Skip to content

fix: activate --as-needed shared libraries for weak symbol references#1672

Open
PritamP20 wants to merge 2 commits intowild-linker:mainfrom
PritamP20:fix/as-needed-weak-shared-lib
Open

fix: activate --as-needed shared libraries for weak symbol references#1672
PritamP20 wants to merge 2 commits intowild-linker:mainfrom
PritamP20:fix/as-needed-weak-shared-lib

Conversation

@PritamP20
Copy link
Contributor

When --as-needed is active, Wild was dropping shared libraries from DT_NEEDED if the only reference to one of their symbols was weak. This diverges from GNU ld and lld, which both include the library in this case.

The fix is in resolve_symbol in libwild/src/resolution.rs. Previously, try_request_file_id (which marks a library as needed) was only called for strong references. The condition now also activates shared libraries for weak references, while preserving the existing behaviour for archives weak references to archive members should still not force them to be pulled in.

Fixes #1665

Tests

Mold test as-needed-weak.sh now passes removed from misc skip group:

running 2 tests
test external_tests::mold_tests::verify_skipped_mold_tests_still_fail::mold_test_101__UP_external_test_suites_mold_test_as_needed_weak_sh ... ok
test external_tests::mold_tests::check_mold_tests_regression::mold_test_101__UP_external_test_suites_mold_test_as_needed_weak_sh ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 1045 filtered out; finished in 0.14s

// file got loaded. TODO: If the file is a non-archived object, or possibly even if
// it's an archived object that we've already decided to load, then we could skip
// this.
// The symbol is weak and the target is an archive (not a shared library). We
Copy link
Member

Choose a reason for hiding this comment

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

It might not be an archive. It could also be a regular object file right?

Copy link
Contributor Author

@PritamP20 PritamP20 Mar 9, 2026

Choose a reason for hiding this comment

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

Yeah, it can be a regular object file too I'll fix the comment. The main thing this block handles is the case where a weak reference to a shared library wasn't activating it for --as-needed, so it was getting dropped from DT_NEEDED

@davidlattimore
Copy link
Member

Do the tests pass for you locally? If they do, then you might want to look at your test-config.toml or copy test-config-ci.toml if you don't have one.

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.

Weak symbol references don't activate , --as-needed shared libraries

2 participants