diff --git a/CHANGES b/CHANGES index cc6c165..257253c 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,8 @@ Next version - GPR#164: Recognize `-mwindows` and `-mconsole` for greater compatibility (with `pkg-config` in particular). (Nicolás Ojeda Bär, review by David Allsopp) +- GRP#169: Drop the .llvm_addrsig section from rewritten objects. + (Antonin Décimo, review by David Allsopp) Version 0.44 - GPR#127: Recognise hyphens in option names in the COFF .drectve section. diff --git a/reloc.ml b/reloc.ml index 9fcf05a..070fe17 100644 --- a/reloc.ml +++ b/reloc.ml @@ -926,6 +926,23 @@ let build_dll link_exe output_file files exts extra_args = List.iter (fun s -> exported := StrSet.add (usym s) !exported) !defexports; + (* Drop the .llvm_addrsig section (an optional hint for the linker's + identical-code-folding pass, emitted by clang) from rewritten objects: + its payload consists of symbol table indices which become stale when + the symbol table is rewritten, and lld-link rejects objects with an + invalid address-significance table. *) + let drop_addrsig obj = + let addrsig s = s.sec_name = ".llvm_addrsig" in + obj.sections <- List.filter (fun s -> not (addrsig s)) obj.sections; + obj.symbols <- + List.filter + (fun s -> + match s.section with + | `Section sec -> not (addrsig sec) + | `Num _ -> true) + obj.symbols + in + let record_obj obj = if !builtin_linker then "" else begin @@ -959,6 +976,7 @@ let build_dll link_exe output_file files exts extra_args = let close_obj name imps obj = error_imports name imps; add_reloc name obj imps; + drop_addrsig obj; record_obj obj in