Skip to content

fix(elf): keep hidden symbols global in partial links - #3062

Merged
davidlattimore merged 3 commits into
wild-linker:mainfrom
deepakshirkem:fix/partial-link-hidden-symbols
Nov 23, 2026
Merged

davidlattimore merged 3 commits into
wild-linker:mainfrom
deepakshirkem:fix/partial-link-hidden-symbols

Conversation

@deepakshirkem

@deepakshirkem deepakshirkem commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Hidden symbols are downgraded to local so they can't leak into dynsym. That's right for executables and shared objects, but a partial link's output is an input to a later link, which still needs to resolve references to them. GNU ld
and lld keep them global, with hidden visibility.

Wild downgraded them in -r output in two cases:

  • a hidden symbol defined in several files (process_alternatives), e.g. an inline variable, which clang emits as weak and GCC as GNU-unique
  • a hidden reference to a definition in another file (resolve_symbol and apply_visibility_to_definition)

In a partial link, these now set a new HIDDEN flag instead of DOWNGRADE_TO_LOCAL, and the writer writes such symbols as STV_HIDDEN. So the symbol stays global, and a hidden reference to a default-visibility definition makes the definition hidden, as GNU ld does.

Fixes #2988

Hidden symbols are made local so that they can't leak into dynsym, but a
partial link's output is an input to a later link, which still needs to
resolve references to them. With definitions in several files (as for
inline variables, weak or GNU-unique), or a hidden reference to a
definition in another file, Wild made the symbol local in -r output, and
the later link failed with an undefined symbol. Don't downgrade in
partial links.
@deepakshirkem
deepakshirkem marked this pull request as ready for review November 21, 2026 10:54

@davidlattimore davidlattimore left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following test fails:

diff --git a/wild/tests/sources/elf/partial-link-hidden/partial-link-hidden.s b/wild/tests/sources/elf/partial-link-hidden/partial-link-hidden.s
index 5403dc8c8d..1fe87867c6 100644
--- a/wild/tests/sources/elf/partial-link-hidden/partial-link-hidden.s
+++ b/wild/tests/sources/elf/partial-link-hidden/partial-link-hidden.s
@@ -6,6 +6,12 @@
 //#Relocatable:dup-one.s,dup-two.s,hidden-ref.s,default-def.s
 //#LinkArgs:-no-pie
 
+//#Config:shared:default
+//#Mode:dynamic
+//#PostLinkArgs:-shared
+//#RunEnabled:false
+//#NoDynSym:referenced_hidden
+
 .text
 .globl _start
 _start:

Keeping hidden symbols global in a partial link wasn't enough: a hidden
reference to a default-visibility definition left the definition default,
so a later shared link exported it. Record the merged visibility with a
new HIDDEN flag instead of downgrading to local, and write it as
STV_HIDDEN, like GNU ld. Adds David's shared-object config to the test.
@deepakshirkem

Copy link
Copy Markdown
Member Author

One remaining difference: for a hidden reference to a default-visibility definition, GNU ld writes the merged definition as hidden, while Wild keeps it default. The binding is now correct, so later links work; the visibility could be a follow-up.

Yes Yes, I noticed this case. I have fixed it now and I'm updating the PR description. Thank you :)

@davidlattimore
davidlattimore added this pull request to the merge queue Nov 23, 2026
Merged via the queue into wild-linker:main with commit ec494e2 Nov 23, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relocatable output localizes hidden GNU-unique symbols

2 participants