test: Add test for weak ref to as-needed shared library#1672
test: Add test for weak ref to as-needed shared library#1672davidlattimore merged 3 commits intowild-linker:mainfrom
Conversation
libwild/src/resolution.rs
Outdated
| // 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 |
There was a problem hiding this comment.
It might not be an archive. It could also be a regular object file right?
There was a problem hiding this comment.
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
|
Do the tests pass for you locally? If they do, then you might want to look at your |
|
I think I understand why my earlier fix was breaking the tests. When try_request_file_id activates a --as-needed DSO for a weak ref, the file becomes loaded. Then in canonicalise_undefined_symbols, the ignore_if_loaded check treats the symbol as defined and skips the ValueFlags::DYNAMIC path. This causes the symbol to keep the DSO’s version metadata (e.g. gmon_start@unversioned) instead of being emitted as a plain undefined dynamic symbol like GNU ld does |
|
Hi @davidlattimore, I'm working on fixing the But this introduces a regression I tried guarding with Not sure if |
|
Usually in cases like this, it's necessary to do some experiments. I'd suggest writing a test using our own testing framework. We probably want to do that anyway, since we want our test suite to be reasonably complete when run without the external test suites. That'll make it easier to run with GNU ld and / or LLD so that you can confirm if they have the same behaviour. You could also try running the mold test with GNU ld to see if it passes. |
|
@davidlattimore sure I will experiment with all the edge scenario which are possible and let you know where i land with it |
|
I re-ran the test with GNU ld and lld to double check. Both of them fail the mold test as well, so it seems this behaviour is mold-specific, Wild might already be behaving correctly here I will add a small Wild test to confirm the expected behaviour. |
|
Thanks for investigating. It'd be useful to also update |
17e7b8d to
b1e4071
Compare
davidlattimore
left a comment
There was a problem hiding this comment.
Thanks. Always good to see our test coverage improve :)
davidlattimore
left a comment
There was a problem hiding this comment.
Looks like there's a compilation error with the merge
wild/tests/sources/as-needed-weak.c
Outdated
| //#Object:runtime.c | ||
| //#Mode:unspecified | ||
| //#Shared:template(--push-state --as-needed $O --pop-state):as-needed-weak-lib.c | ||
| // GNU ld drops PT_INTERP when no shared libs are needed, producing a static |
There was a problem hiding this comment.
If you wanted, you could add the following instead:
//#Shared:force-dynamic-linking.c
//#DiffIgnore:.dynamic.DT_NEEDED
|
Also, could you update the PR's description? This would be useful for others to review later. |
I already changed the PR title. Unless there's further issues with the title? |
|
I don't see any issues with the title itself, but having the title and description content significantly differ would only cause confusion, which is why I'd like Pritam to update the content. |
|
Oh, right. Sorry, you did say description. I often just delete the description from the commit message when I merge, so I didn't pay any attention to that. |
|
@davidlattimore @lapla-cogito Thanks for the review and feedback. I will update the PR description so that it matches the changes and conclusions made. |
…NU ld/lld behaviour
a2dea4e to
c91a302
Compare
|
Sorry, you possibly need |
|
@davidlattimore yeah, I figured it out. I'm testing it locally first before pushing the update. |
4cbed0f to
4eb63b0
Compare
|
For the error: It's fine to just diffignore it. Wild doesn't emit the GOT if it isn't needed, so differences like this are currently pretty common. |
e25958a to
a7a8eb7
Compare
35bf737 to
0b07001
Compare
|
@lapla-cogito I have updated the PR description, can you review it once |
|
Thanks! Looks good. |
The original intent of this PR was to fix an issue where
--as-neededshared libraries were not being activated when only a weak symbol referenced them.Initially, this seemed like a divergence from GNU ld and lld, so the change attempted to activate the shared library in that case.
After further investigation and testing with GNU ld and lld, it turned out that both of them do not activate
--as-neededshared libraries for weak references. The behavior expected by the mold test (as-needed-weak.sh) is therefore mold-specific. Wild already behaves the same as GNU ld and lld.Changes in this PR
as-needed-weak.shas mold-specific inmold_skip_tests.toml.as-needed-weak.c) to verify the expected behavior: a weak reference should not activate a--as-neededshared library.DT_NEEDED, matching GNU ld and lld behavior.Result
Wild’s behavior now has explicit test coverage confirming that weak references do not activate
--as-neededshared libraries, consistent with GNU ld and lld.