-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DNM] Revert "IRGen: Use llvm.compiler.used instead of llvm.used on ELF" #71373
[DNM] Revert "IRGen: Use llvm.compiler.used instead of llvm.used on ELF" #71373
Conversation
This reverts commit 2bbea54.
@swift-ci Please test |
The problem is/was that you end up with multiple section of the same name. The runtime (CC @mikeash) and tools look for said section and (presumably) can't deal with the presence of multiple same named sections in one binary on linux and therefore you see failures. Speculating ..., to address this, maybe the runtime could be modified? I am assuming that this means something like: if you have seen one section of (e.g) |
The section data should be coalesced, so it seems like we might be missing something. |
The fact that they are not coalesced seems to be intentional feature of SHF_GNU_RETAIN. https://reviews.llvm.org/D97448
|
IIUC, multiple same-name sections are OK in object files, but the problem here is linker does not coalesce those same-name sections appearing in a single object file, but just pick a first one. I will have a closer look again. |
Okay, the problem was that:
The 1. behavior is inconsistent between gold and lld (lld merges those sections into one), so it was not a problem with lld. I applied 0e410da to add I tested stdlib test suites with the following env var and it works on my end.
|
@swift-ci Please test Linux platform |
To have consistent section flags between compiler emitted object files and swiftrt.o.
I saw some of the reflection tests failed because some of reflection sections like However, some of reflection sections like This conditional section flag decision makes it difficult to have consistent section flags between object files, and it results in multiple reflection sections in the final image. I think one of the solutions would be adding retained versions of those conditionally retained sections What do you think about this solution? and do you have any other good ideas? @compnerd @aschwaighofer |
Could we initialize the section appropriately so that the attributes are applied to that section into which we emit the symbols? We can change the behaviour conditionally based on the object file format that we are emitting into as well if that is necessary. |
@compnerd Do you mean not to have |
I was thinking more the latter. We can emit them if reflection is enabled and not strip them. |
There are a couple of different problems here. The first is that for ELF images it's impossible to locate sections at runtime by looking through the ELF data structures (the section headers are not mapped into the process's address space and indeed can be stripped from the executable image). The upshot of that is that we're using the linker-generated Unfortunately those symbols aren't regarded as GC roots, so when section GC is enabled, the linker will drop some of the metadata sections as there are no pointers into them. This is then compounded by the fact that (To clarify, because the sections are not coalesced, and because there can be only one Even if we were to get a fix into |
I think this is probably the way forward in the short term. WDYT @aschwaighofer @mikeash? Also, I guess @kubamracek might have some opinions on this? |
(I could do with having this resolved for my static Linux SDK work — see #71841, which is one of the changes I had on my branch, and which, of course, doesn't work in CI because of this problem.) |
FWIW, I just filed a bug against That'll fix the issue in the longer term, but doesn't help us now, of course. |
My assumption was that we could make it so the flags never differ for these sections. Presumably by making a similar change to #71841 wherever that is in the code, is that not the case? |
There is the issue @kateinoigakukun mentions above, where the reflection metadata is marked either used or not used depending on a flag, which complicates matters slightly. One other option that nobody has mentioned so far is for the runtime to support two sections (with different names, hence different |
I'm okay if we for now declare that reflection metadata stripping on ELF won't work. It's only needed for the -experimental-hermetic-seal-at-link / WME / VFE features, which don't (sadly) work properly on ELF today anyway. |
Is the section not being there the important part? I guess I assumed that if the section was there, but empty, that would be "good enough" for that disabling as well (even if it's not ideal) |
Not sure which exact part you're asking about. The -experimental-hermetic-seal-at-link feature can work with reflection metadata being completely off, but that regresses debugging because without reflection metadata, LLDB doesn't know how to inspect variables and understand their types. Runtime execution will still work, though. |
Sorry I was just talking about the section presence part. If the section is there, but empty, I assume that would be ok? |
I've been looking at this some more. The runtime only cares about the section if it's retained, so The reflection code is where we might care about the unretained sections, so That should fix everything I think. I've got a changeset for all of this and I'm currently trying the test suite with
as @kateinoigakukun did previously to make sure I haven't broken anything. |
I have a new PR that deals with all of this: #72061. |
Great! |
This reverts commit 2bbea54 to see what multiple sections for each global broke.
The use of
llvm.compiler.used
as a replacement forllvm.used
changes the semantics of symbol requirements at link time, and it losesSHF_GNU_RETAIN
for generatedswift5
metadata sections.I'm not sure why multiple same name sections were problem here 🤔