fix: align output kind with LD in more cases#1279
Conversation
This seems more sensible to me
|
These CI errors surely will be fun. |
60e6a9c to
1fe0ac1
Compare
1fe0ac1 to
8203a25
Compare
The failures I was talking about: https://github.com/davidlattimore/wild/actions/runs/19172217881/job/54807556902?pr=1279 Some context:I have noticed that adding DSO with This worked on Arch and openSUSE but failed on Ubuntu. As it turns out, GCC on Ubuntu prepends The dubious fix:I tried to fix it with Looks like the logic from #879 wasn't too far off, and upon getting DSO as an argument, we should try to produce a dynamic executable. However, if no DSO ends up being used after symbol_db build and resolution (both these parts behave differently depending on resulting binary type) phases, we have to go back to static executable format. |
|
Looking through the callers of I guess the ideal would be to make the decision at one specific point in the link and have nothing prior to that point in linking depend on the output kind. Possibly we should even remove It's a shame that GNU ld has such vague semantics with regard to determining the output type. Does lld do the same thing? So eyra when it builds passes --as-needed shared objects to the linker, then doesn't use any of them and expects to get a statically linked executable? |
To answer my own question, I just tried and if I enable lld for the test config |
|
IIRC for eyra the problem was related to Wild creating static PIE when given The test case for that should be
Yeah, hence my "I wish I'm wrong somewhere, and it's not as complicated as I made it, so I could use some help with this maze."
Yes, that's my goal too, but I didn't want to cram too much into a single PR, thanks to LD decisions it's complicated enough already. *unless we want to match LD's auto revert to static executable if no DSO is loaded... |
|
I agree that this is a case where we should probably match lld's behaviour rather than GNU ld's. I imagine that GNU ld isn't so much reverting to static, but rather its behaviour is a result of where in the link process it decides to output a shared object. Presumably it's making that decision after I'd be happy with bugfix then refactoring or refactoring then bugfix - whatever is easiest. Let me know if you'd like any help. |
2168b36 to
a8bc7dc
Compare
Sure, everything is so much easier now.
I didn't word it properly, my bad. I meant that upon noticing DSO, LD would try to resolve symbols as it was creating the dynamic executable. If no DSO ends up loaded, it'd revert to static executable output and then proceed to figure out symbols details (considering how slow it is, it might as well resolve the symbols again).
Yeah, the decision whether to try proceeding as dynamic executable really needs to happen before parsing. Current version passes almost all the tests with Eyra (ctor ordering doesn't work yet, so there is a single failure) but shows a rather confusing diff: Not that it matters at all. I'll clean up the comments and tests tomorrow. |
|
Thank you, @davidlattimore, for the insights! |
When testing eyra I've once more encountered a problem similar to #879 and decided to solve it properly this time.
FYI, this time the problem was caused by Wild outputting static PIE even though dynamic linker was set.
Spending countless hours on reverse engineering the output kind based on dozens of scenarios probably wasn't the best way to spend that time, but hopefully this is now robust enough that we won't have to deal with all this mess again.
Wild will now turn static PIE into dynamic one even if no DSO is linked (
pie-over-shared).