[lld] [X86][LLD] Handle R_X86_64_CODE_6_GOTTPOFF relocation type (PR #117675)
Feng Zou via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 29 19:37:07 PST 2024
================
@@ -623,6 +625,41 @@ void X86_64::relaxTlsIeToLe(uint8_t *loc, const Relocation &rel,
<< "R_X86_64_CODE_4_GOTTPOFF must be used in MOVQ or ADDQ "
"instructions only";
}
+ } else if (rel.type == R_X86_64_CODE_6_GOTTPOFF) {
+ if (loc[-6] != 0x62) {
+ Err(ctx) << getErrorLoc(ctx, loc - 6)
+ << "Invalid prefix with R_X86_64_CODE_6_GOTTPOFF!";
+ return;
+ }
+ // Check bits are satisfied:
+ // loc[-5]: X==1 (inverted polarity), (loc[-5] & 0x7) == 0x4
+ // loc[-4]: W==1, X2==1 (inverted polarity), pp==0b00(NP)
+ // loc[-3]: NF==1 or ND==1
+ // loc[-2]: opcode==0x1 or opcode==0x3
+ // loc[-1]: Mod==0b00, RM==0b101
+ if (((loc[-5] & 0x47) == 0x44) && ((loc[-4] & 0x87) == 0x84) &&
+ ((loc[-3] & 0x14) != 0) && (loc[-2] == 0x1 || loc[-2] == 0x3) &&
+ ((loc[-1] & 0xc7) == 0x5)) {
+ // "addq %reg1, foo at GOTTPOFF(%rip), %reg2" -> "addq $foo, %reg1, %reg2"
+ // "addq foo at GOTTPOFF(%rip), %reg1, %reg2" -> "addq $foo, %reg1, %reg2"
+ // "{nf} addq %reg1, foo at GOTTPOFF(%rip), %reg2"
+ // -> "{nf} addq $foo, %reg1, %reg2"
+ // "{nf} addq name at GOTTPOFF(%rip), %reg1, %reg2"
+ // -> "{nf} addq $foo, %reg1, %reg2"
+ // "{nf} addq name at GOTTPOFF(%rip), %reg" -> "{nf} addq $foo, %reg"
+ loc[-2] = 0x81;
+ // Move R bits to B bits in EVEX payloads and ModRM byte.
+ const uint8_t evexPayload0 = loc[-5];
+ if ((evexPayload0 & (1 << 7)) == 0)
+ loc[-5] = (evexPayload0 | (1 << 7)) & ~(1 << 5);
+ if ((evexPayload0 & (1 << 4)) == 0)
+ loc[-5] = evexPayload0 | (1 << 4) | (1 << 3);
+ *regSlot = 0xc0 | reg;
+ } else {
+ Err(ctx) << getErrorLoc(ctx, loc - 6)
----------------
fzou1 wrote:
Done.
https://github.com/llvm/llvm-project/pull/117675
More information about the llvm-commits
mailing list