-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[bolt][aarch64] Add R_AARCH64_P32_ABS16/32 relocations #143773
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
Conversation
@llvm/pr-subscribers-bolt Author: Alexey Moksyakov (yavtuk) ChangesAdded few relocations for quick checking Full diff: https://github.com/llvm/llvm-project/pull/143773.diff 2 Files Affected:
diff --git a/bolt/lib/Core/Relocation.cpp b/bolt/lib/Core/Relocation.cpp
index f099dfa46f3d4..c189dbe8f49fd 100644
--- a/bolt/lib/Core/Relocation.cpp
+++ b/bolt/lib/Core/Relocation.cpp
@@ -87,7 +87,9 @@ static bool isSupportedAArch64(uint32_t Type) {
case ELF::R_AARCH64_PREL32:
case ELF::R_AARCH64_PREL64:
case ELF::R_AARCH64_ABS16:
+ case ELF::R_AARCH64_P32_ABS16:
case ELF::R_AARCH64_ABS32:
+ case ELF::R_AARCH64_P32_ABS32:
case ELF::R_AARCH64_ABS64:
case ELF::R_AARCH64_MOVW_UABS_G0:
case ELF::R_AARCH64_MOVW_UABS_G0_NC:
@@ -167,6 +169,7 @@ static size_t getSizeForTypeAArch64(uint32_t Type) {
errs() << object::getELFRelocationTypeName(ELF::EM_AARCH64, Type) << '\n';
llvm_unreachable("unsupported relocation type");
case ELF::R_AARCH64_ABS16:
+ case ELF::R_AARCH64_P32_ABS16:
case ELF::R_AARCH64_PREL16:
return 2;
case ELF::R_AARCH64_CALL26:
@@ -204,6 +207,7 @@ static size_t getSizeForTypeAArch64(uint32_t Type) {
case ELF::R_AARCH64_MOVW_UABS_G2_NC:
case ELF::R_AARCH64_MOVW_UABS_G3:
case ELF::R_AARCH64_ABS32:
+ case ELF::R_AARCH64_P32_ABS32:
case ELF::R_AARCH64_PLT32:
return 4;
case ELF::R_AARCH64_ABS64:
@@ -290,7 +294,9 @@ static uint64_t encodeValueAArch64(uint32_t Type, uint64_t Value, uint64_t PC) {
default:
llvm_unreachable("unsupported relocation");
case ELF::R_AARCH64_ABS16:
+ case ELF::R_AARCH64_P32_ABS16:
case ELF::R_AARCH64_ABS32:
+ case ELF::R_AARCH64_P32_ABS32:
case ELF::R_AARCH64_ABS64:
break;
case ELF::R_AARCH64_PREL16:
@@ -352,7 +358,9 @@ static uint64_t extractValueAArch64(uint32_t Type, uint64_t Contents,
errs() << object::getELFRelocationTypeName(ELF::EM_AARCH64, Type) << '\n';
llvm_unreachable("unsupported relocation type");
case ELF::R_AARCH64_ABS16:
+ case ELF::R_AARCH64_P32_ABS16:
case ELF::R_AARCH64_ABS32:
+ case ELF::R_AARCH64_P32_ABS32:
case ELF::R_AARCH64_ABS64:
return Contents;
case ELF::R_AARCH64_PREL16:
@@ -643,7 +651,9 @@ static bool isPCRelativeAArch64(uint32_t Type) {
default:
llvm_unreachable("Unknown relocation type");
case ELF::R_AARCH64_ABS16:
+ case ELF::R_AARCH64_P32_ABS16:
case ELF::R_AARCH64_ABS32:
+ case ELF::R_AARCH64_P32_ABS32:
case ELF::R_AARCH64_ABS64:
case ELF::R_AARCH64_LDST64_ABS_LO12_NC:
case ELF::R_AARCH64_ADD_ABS_LO12_NC:
diff --git a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
index eb1d9d8a19514..f12ff033ca3ff 100644
--- a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
+++ b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
@@ -2244,7 +2244,9 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
switch (RelType) {
case ELF::R_AARCH64_ABS64:
case ELF::R_AARCH64_ABS32:
+ case ELF::R_AARCH64_P32_ABS32:
case ELF::R_AARCH64_ABS16:
+ case ELF::R_AARCH64_P32_ABS16:
case ELF::R_AARCH64_ADD_ABS_LO12_NC:
case ELF::R_AARCH64_ADR_GOT_PAGE:
case ELF::R_AARCH64_ADR_PREL_LO21:
|
Related Issue #143709 |
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.
Hey Alexei,
Thanks for the patch! The code itself looks okay. When trying @aaupov patch #132114 (currently marked as draft), I do get a failure on AArch64/jump-table-info.s
as @whubeibei reports on issue #143709.
After cherry-picking this PR on top of Amir's draft PR I get an assertion:
BinarySection.cpp:136: void llvm::bolt::BinarySection::emitAsData(MCStreamer &, const Twine &) const
: Assertion `SectionOffset <= SectionContents.size() && "overflow error"' failed.
Not sure if I missed something.
Regarding the relocations themselves, they appear to be part of the ILP32 which is Beta. @yavtuk , @whubeibei could you share more details on how you get to generate those relocations in the input binary?
cc @smithp35 who can provide additional context around the status of ILP32.
This assert is not related to the type of relocations, I added the link to source code where I think the problem is. There emit Jump Table function where you can find updateOriginal entry and there we should add relocation for aarch64 platform |
I think this relocations are generated by mistake, the one for x86 type in emitJumpTables function. I had the one before I added abs64 relocation correctly for aarch64 |
Yes, I agree. The patch itself looks good; it only needs tests. Maybe that is what you meant here.
Yeap, and that is my concern for supporting these beta relocations in BOLT. |
Thanks for the update! I only applied PR #132114 along with its prerequisite patch (#131997), and I haven't encountered the That said, I'm still learning the internals of BOLT and AArch64 relocation handling, and I'm trying to understand the cause of this issue. I'll keep digging and follow up if I find anything useful.
Thanks for the update! I only applied PR #132114 along with its prerequisite patch , and I haven't encountered the That said, I'm still learning the internals of BOLT and AArch64 relocation handling, and I'm trying to understand the cause of this issue. I'll keep digging and follow up if I find anything useful. As for the relocations, I also believe—like @yavtuk mentioned—that they were generated by mistake. It seems Thanks again for all the insights and help! |
The ILP32 relocation codes are only legal in ELFCLASS32 files https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#5731relocation-names-and-class I recommend that you add these only if you are intending to support 32-bit ILP32 files in BOLT (presumably from a GCC ILP32 toolchain). An ELFCLASS64 file containing these relocations is not well defined as there are different codes for the same relocation in AArch64. Is it possible that someone used the ILP32 value for the relocation code (< 256) rather than the usual one https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#575static-data-relocations |
@smithp35 we are not going to merge this code to main branch because this relocations are generated by mistake, I will close this MR soon, just to show that we made mistake in another place |
@yavtuk, @whubeibei okay, just to clarify, these relocations aren't present in the input binary, but generated by mistake as the below code is not guarded for AArch64? llvm-project/bolt/lib/Core/JumpTable.cpp Lines 86 to 91 in d49a2b5
And this happens only because the encoding of X86:
happens to map on these on AArch64 relocations? llvm-project/llvm/include/llvm/BinaryFormat/ELFRelocs/AArch64.def Lines 170 to 171 in a9ad9e2
If that is the case then maybe we don't need to proceed with this patch, at least not at this point. |
yes,i think it's a mistake |
I'd say it's more that this PR is still unfinished :) Mystery solved then. Τhanks for being keen and trying it out! Would you mind if I go ahead and close #143709 ? BTW, @aaupov is the diff rendering properly here? When I pull that PR locally I see changes on 17 files, including JumpTable.cpp, but online I only see 7 changed files. |
I agree with closing about #143709 |
Thanks! Sure, feel free to close #143709 — it was mainly for debugging purposes to surface the issue. I'd be happy to help test or contribute toward #132114 for a complete fix for jump table handling. |
thanks for your earlier comment! based on the jump table support introduced in PR #132114. As we noted, BOLT attempts to generate relocations for jump table entries, but currently there is no suitable relocation type for these entries on AArch64. Since I’m still not very familiar with BOLT internals and ARM architecture specifics, I would like to seek more detailed guidance on how to properly improve or extend the implementation to handle this case. Specifically:
I’m eager to learn and contribute to the fix once I better understand the recommended path forward. Thank you very much for your advice and help! |
No, we just need to emit entry as symbol which should be encoded according to JT pattern
I implemented JT for aarch64 but for GCC, I will help you here, we have a holidaynow but on the next week I will try to resolve this complicated moment |
Thanks a lot for your quick reply and explanation! I get that we don’t need new relocation types, and the jump table entries should just be emitted as symbols following the JT pattern. Really appreciate that you’re willing to help with the AArch64 jump table stuff based on your GCC work. Enjoy your holiday, and I’m looking forward to working with you when you’re back. If you have any docs or example code about the JT pattern or symbol encoding, could you please share? I’d like to start getting familiar with it while waiting. Thanks again for your help! |
Added few relocations for quick checking