fix: Don't bail when a linker plugin doesn't claim an IR archive member - #2027
Conversation
|
Adding a regression test for this is a bit tricky because we need to use different compilers (clang and gcc) for archive and other builds 🤔 |
|
Does it work to use gcc as the linker driver, clang as the compiler, then specify -flto only for the one archive? |
davidlattimore
left a comment
There was a problem hiding this comment.
Does this mean that now we'll now, in general, report an undefined symbol error instead of reporting that the archive contains the wrong kind of IR?
9523b64 to
4f48931
Compare
Ah right. There was a simple solution.
While this isn't true in general (it's limited to the archive case), yes. I think users naturally expect an "undefined symbol" error if a symbol was meant to be provided via an archive but the IR member wasn't claimed by the plugin. |
I'm not sure what users expect, but an error telling them that they're trying to link LLVM IR using the GCC plugin would almost certainly be more useful than an undefined symbol error. We have tests for that, but I guess the tests only cover the case of an object, not an archive. I just tried adding the following test: Strangely it passes even with your PR. Perhaps you'd like to add it to your PR to ensure we don't regress that case. Although I'd be interested to learn why it passes. |
I think it's because |
I generally (edit: I mean the general case other than archives) agree, but in the case of archives, the situation differs because archived components may contain members with different IR that aren't referenced. In fact, GNU ld and lld exhibit the same behavior (they pass the mold tests that no longer need to be skipped in this PR). |
Archive members are only selected if their symbols are referenced. If the active LTO plugin refuses to claim one, we used to error unconditionally. Skip it instead and let later symbol resolution fail if the member turns out to be needed.