-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[BOLT][AArch64] Fix LDR relocation type in ADRP+LDR sequence #166391
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
`R_AARCH64_ADD_ABS_LO12_NC` is for the `ADD` instruction in the `ADRP+ADD` sequence. For `ADRP+LDR` sequence generated in LDR relaxation, relocation type for `LDR` should be `R_AARCH64_LDST64_ABS_LO12_NC` if it is 64-bit integer load or `R_AARCH64_LDST32_ABS_LO12_NC` if 32-bit.
|
@llvm/pr-subscribers-bolt Author: YongKang Zhu (yozhu) Changes
Sorry should have included this in #165787. Full diff: https://github.com/llvm/llvm-project/pull/166391.diff 1 Files Affected:
diff --git a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
index 8a496c566b06b..43c9d9d3f14bd 100644
--- a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
+++ b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
@@ -640,7 +640,8 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
Insts[1].addOperand(MCOperand::createImm(0));
Insts[1].addOperand(MCOperand::createImm(0));
setOperandToSymbolRef(Insts[1], /* OpNum */ 2, Target, 0, Ctx,
- ELF::R_AARCH64_ADD_ABS_LO12_NC);
+ isLDRXl(LDRInst) ? ELF::R_AARCH64_LDST64_ABS_LO12_NC
+ : ELF::R_AARCH64_LDST32_ABS_LO12_NC);
return Insts;
}
|
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.
Thanks for the update. I believe it wouldn't matter which of the 3 RelTypes we pass, as we'd get the LO12 bits expression regardless.
But ofc, it's better to be accurate. You haven't observed any issues, right?
Some thoughts from the previous patch that might have helped:
- Refactoring to reuse logic from
materializeAddresscould help - We could also make naming consistent between
createAdrpLdrandundoAdrpAddRelaxation?
Thanks for the review and suggestions! Right, I haven't observed any issue, before or after this change. As you said, it is just to make the relocation type name accurately reflect what kind of instruction the relocation is applied on.
I had thought about
I had thought about this when working on the previous patch. |
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 had thought about this when working on the previous patch. undoAdrpAddRelaxation seems to refer to that BOLT will undo the relaxation done by the linker, but LDR (load literal) is not resulted from of any relaxation done by the linker, so I just named it createAdrpLdr.
I was not sure of the context when that function was introduced.
That's fair. Thanks again for the patch!
|
Thanks again for the review and suggestions! |
R_AARCH64_ADD_ABS_LO12_NCis for theADDinstruction in theADRP+ADDsequence. ForADRP+LDRsequence generated in LDR relaxation, relocation type forLDRshould beR_AARCH64_LDST64_ABS_LO12_NCif it is 64-bit integer load orR_AARCH64_LDST32_ABS_LO12_NCif 32-bit.Sorry should have included this in #165787.