-
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
[Runtime] Define GOT equivalents for Linux for BuiltinProtocolConformances #34457
Conversation
@swift-ci Please test Edit: Seems CI access hasn't kicked in yet. |
@swift-ci Please test |
Build failed |
@swift-ci Please test OS X platform |
@lhames what are your thoughts on this? |
ELF assemblers do support GOT relative references, but the syntax may be different. |
Maybe it would be more portable to write the assembly as a |
#define P2ALIGN_FOR_GOT " .p2align 3\n" | ||
#else | ||
#define POINTER_FOR_GOT(SYMBOL) \ | ||
" .long (" SYMBOl ")\n" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: lowercase l
at the end of SYMBOl
.
So with this patch applied, and the fix for the lowercase
(the usage of I will try AArch64 next to see if the same error is generated. The fix seems to at least avoid the compilation problem. Thanks a lot for it. I would not have been able to figure out the changes necessary. Update: same problem in AArch64, but I just realized that it is failing in the Linux x86_64 runtime, not the Android one. Update 2: checking in AArch64, but without this patch. I changed the |
Can we even use LLVM IR though? From a quick search it seems that we don't always build with clang, sometimes we build with msvc and I don't believe it can compile ll files (maybe that's just for when building clang? I'm not sure). Yeah I've been looking at LLVM source and found the assert when its checking the relocation for aarch64 ELF, and it seems to only support an absolute symbol or a |
The Windows build prefers MSVC for compiling (it's faster on Windows), but builds large parts of LLVM. I don't see
I don't think
Yes. That's what I wanted to say with that disclaimer. I only run half of the tests. I would expect |
The runtime can only be built with the just-built Clang, because upstream clang and msvc do not support the Swift calling convention. It should be fine to use LLVM IR. |
@jckarter - it can also be built with a host compiler as long as the host compiler supports the SwiftCC. |
#define INDIRECT_RELREF_GOTPCREL(SYMBOL) ".Lgot." SYMBOL " - . + 1" | ||
|
||
// Helper for defining the .type on linux. | ||
#if defined(__arm__) && !defined(__aarch64__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PPC uses the %
sigil as well
#if defined(__x86_64__) || defined(__aarch64__) | ||
#define POINTER_FOR_GOT(SYMBOL) \ | ||
" .quad (" SYMBOL ")\n" \ | ||
" .size .Lgot." SYMBOL ", 8\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might want to have a level of indirection here. The .L
not guaranteed to the assembler local prefix.
#endif | ||
|
||
// Helper to get the pointer sized pointer to symbol and the right alignment. | ||
#if defined(__x86_64__) || defined(__aarch64__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PPC64?
#else | ||
#define POINTER_FOR_GOT(SYMBOL) \ | ||
" .long (" SYMBOl ")\n" \ | ||
" .size .Lgot." SYMBOL ", 4\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar here to the 8-byte case.
// equivalent variables for linux. | ||
#define GOT_EQUIVALENT(SYMBOL) \ | ||
__asm( \ | ||
" .type .Lgot." SYMBOL ", " TYPE_OBJECT "\n" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you should create another macro to generate the name rather than use the .Lgot." SYMBOL"
in multiple locations.
The copy relocation against a protected symbol has had issues in the past. Dropping the visibility to default should work, or alternatively, I think that looking into R_*_GOTPCRELX might be useful. Depending on the context in which it is used, we should be able to use the GOTPCREL variant of the symbol. |
@compnerd We should never copy Swift symbols, and we really do want them to be |
AFAIK that still implies some variation of Clang. If we tweak the swiftcc lowering, or the way the swiftcc maps into runtime C++, we're going to want to make the change to swift-clang in lockstep with swift itself, so using any other compiler is going to be brittle. However, we could use |
Oh, assuming that the compiler that is used for building the runtime supports the correct thing is reasonable. I don't think that we should be relying on |
I thought so too, but it looks like the correct assembly syntax for emitting the kinds of relocations we want is pretty tempermental and varies between platforms quite a bit. As far as portable options, C can't express relative references, but LLVM IR can. If we don't want to ship a .ll file, or rely on llc or clang being part of the build toolchain, another kinda-gross option might be to just add code to IRGen that generates the necessary LLVM IR while building the standard library. |
I was just about to mention moving this back to IRGen to solve lots of these issues. Is there any particular reason you consider that solution kinda-gross? IIRC IRGen does something similar with Builtin reflection information where it emits it for the standard library vs. being in the runtime. |
I guess it just seems kind of unfortunate for the compiler to have code in it that's only ever used to build the standard library to me. |
Some Linux archs+platforms don't support relocations like
@GOTPCREL
which is what we defaulted to using on ELF platforms. Create a GOT equivalent for indirect symbols we reference for ELF (mirroring what the Swift compiler currently does). This should fix external CI testing platforms. Joe, I remember we mentioned that we shouldn't need to have to do this, but it seems beneficial to go ahead and create these for Linux because of the wide support range of arch requirements when it comes to relocations.