From 0ce9af9c619a289168ff14cceca588957d1e5186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Thu, 18 Jun 2026 09:46:03 +0200 Subject: [PATCH] Drop the `.llvm_addrsig` section from rewritten objects The address-significance table emitted by clang holds symbol table indices, which become stale when flexlink rewrites an object's symbol table to add the relocation table. lld-link rejects objects with an invalid `.llvm_addrsig` section. The section is an optional hint for the linker's identical-code-folding pass and can safely be dropped. --- CHANGES | 2 ++ reloc.ml | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) 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