Repository navigation
fix(elf): keep hidden symbols global in partial links - #3062
Merged
davidlattimore merged 3 commits intoNov 23, 2026
Merged
davidlattimore merged 3 commits into
davidlattimore merged 3 commits into
Conversation
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
marked this pull request as ready for review
November 21, 2026 10:54
davidlattimore
left a comment
Member
There was a problem hiding this comment.
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.
Member
Author
Yes Yes, I noticed this case. I have fixed it now and I'm updating the PR description. Thank you :) |
davidlattimore
approved these changes
Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
-routput in two cases:process_alternatives), e.g. an inline variable, which clang emits as weak and GCC as GNU-uniqueresolve_symbolandapply_visibility_to_definition)In a partial link, these now set a new
HIDDENflag instead ofDOWNGRADE_TO_LOCAL, and the writer writes such symbols asSTV_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