Skip to content

Commit 4bf2ab0

Browse files
committed
Make test x86-64-gotpc-relax.s pass
1 parent 338a565 commit 4bf2ab0

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

lld/ELF/Arch/X86_64.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -862,12 +862,13 @@ void X86_64::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
862862

863863
RelExpr X86_64::adjustGotPcExpr(RelType type, int64_t addend,
864864
const uint8_t *loc) const {
865-
// Only R_X86_64_[REX_]GOTPCRELX can be relaxed. GNU as may emit GOTPCRELX
866-
// with addend != -4. Such an instruction does not load the full GOT entry, so
867-
// we cannot relax the relocation. E.g. movl x@GOTPCREL+4(%rip), %rax
868-
// (addend=0) loads the high 32 bits of the GOT entry.
865+
// Only R_X86_64_[REX_]|[REX2_]GOTPCRELX can be relaxed. GNU as may emit
866+
// GOTPCRELX with addend != -4. Such an instruction does not load the full GOT
867+
// entry, so we cannot relax the relocation. E.g. movl x@GOTPCREL+4(%rip),
868+
// %rax (addend=0) loads the high 32 bits of the GOT entry.
869869
if (!ctx.arg.relax || addend != -4 ||
870-
(type != R_X86_64_GOTPCRELX && type != R_X86_64_REX_GOTPCRELX))
870+
(type != R_X86_64_GOTPCRELX && type != R_X86_64_REX_GOTPCRELX &&
871+
type != R_X86_64_REX2_GOTPCRELX))
871872
return R_GOT_PC;
872873
const uint8_t op = loc[-2];
873874
const uint8_t modRm = loc[-1];
@@ -883,7 +884,7 @@ RelExpr X86_64::adjustGotPcExpr(RelType type, int64_t addend,
883884
if (op == 0xff && (modRm == 0x15 || modRm == 0x25))
884885
return R_RELAX_GOT_PC;
885886

886-
// We don't support test/binop instructions without a REX prefix.
887+
// We don't support test/binop instructions without a REX/REX2 prefix.
887888
if (type == R_X86_64_GOTPCRELX)
888889
return R_GOT_PC;
889890

lld/test/ELF/x86-64-gotpc-relax.s

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515

1616
## In our implementation, .got is retained even if all GOT-generating relocations are optimized.
1717
# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
18-
# CHECK: .iplt PROGBITS 0000000000201280 000280 000010 00 AX 0 0 16
19-
# CHECK-NEXT: .got PROGBITS 0000000000202290 000290 000000 00 WA 0 0 8
18+
# CHECK: .iplt PROGBITS 00000000002012e0 0002e0 000010 00 AX 0 0 16
19+
# CHECK-NEXT: .got PROGBITS 00000000002022f0 0002f0 000000 00 WA 0 0 8
2020

2121
## There is one R_X86_64_IRELATIVE relocations.
2222
# RELOC-LABEL: Relocation section '.rela.dyn' at offset {{.*}} contains 1 entry:
2323
# CHECK: Offset Info Type Symbol's Value Symbol's Name + Addend
24-
# CHECK: 0000000000203290 0000000000000025 R_X86_64_IRELATIVE 2011e2
24+
# CHECK: 00000000002032f0 0000000000000025 R_X86_64_IRELATIVE 2011e2
2525
# CHECK-LABEL: Hex dump of section '.got.plt':
26-
# NOAPPLY-NEXT: 0x00203290 00000000 00000000
27-
# APPLY-NEXT: 0x00203290 e2112000 00000000
26+
# NOAPPLY-NEXT: 0x002032f0 00000000 00000000
27+
# APPLY-NEXT: 0x002032f0 e2112000 00000000
2828

2929
# 0x201173 + 7 - 10 = 0x201170
3030
# 0x20117a + 7 - 17 = 0x201170
@@ -43,20 +43,20 @@
4343
# DISASM-NEXT: leaq -17(%rip), %rax
4444
# DISASM-NEXT: leaq -23(%rip), %rax
4545
# DISASM-NEXT: leaq -30(%rip), %rax
46-
# DISASM-NEXT: movq 8330(%rip), %rax
47-
# DISASM-NEXT: movq 8323(%rip), %rax
46+
# DISASM-NEXT: movq 8426(%rip), %rax
47+
# DISASM-NEXT: movq 8419(%rip), %rax
4848
# DISASM-NEXT: leaq -52(%rip), %rax
4949
# DISASM-NEXT: leaq -59(%rip), %rax
5050
# DISASM-NEXT: leaq -65(%rip), %rax
5151
# DISASM-NEXT: leaq -72(%rip), %rax
52-
# DISASM-NEXT: movq 8288(%rip), %rax
53-
# DISASM-NEXT: movq 8281(%rip), %rax
52+
# DISASM-NEXT: movq 8384(%rip), %rax
53+
# DISASM-NEXT: movq 8377(%rip), %rax
5454
# DISASM-NEXT: callq 0x2011e0 <foo>
5555
# DISASM-NEXT: callq 0x2011e0 <foo>
5656
# DISASM-NEXT: callq 0x2011e1 <hid>
5757
# DISASM-NEXT: callq 0x2011e1 <hid>
58-
# DISASM-NEXT: callq *8251(%rip)
59-
# DISASM-NEXT: callq *8245(%rip)
58+
# DISASM-NEXT: callq *8347(%rip)
59+
# DISASM-NEXT: callq *8341(%rip)
6060
# DISASM-NEXT: jmp 0x2011e0 <foo>
6161
# DISASM-NEXT: nop
6262
# DISASM-NEXT: jmp 0x2011e0 <foo>
@@ -65,13 +65,26 @@
6565
# DISASM-NEXT: nop
6666
# DISASM-NEXT: jmp 0x2011e1 <hid>
6767
# DISASM-NEXT: nop
68-
# DISASM-NEXT: jmpq *8215(%rip)
69-
# DISASM-NEXT: jmpq *8209(%rip)
68+
# DISASM-NEXT: jmpq *8311(%rip)
69+
# DISASM-NEXT: jmpq *8305(%rip)
70+
# DISASM-NEXT: leaq -167(%rip), %r16
71+
# DISASM-NEXT: leaq -175(%rip), %r16
72+
# DISASM-NEXT: leaq -182(%rip), %r16
73+
# DISASM-NEXT: leaq -190(%rip), %r16
74+
# DISASM-NEXT: movq 8265(%rip), %r16
75+
# DISASM-NEXT: movq 8257(%rip), %r16
76+
# DISASM-NEXT: leaq -215(%rip), %r16
77+
# DISASM-NEXT: leaq -223(%rip), %r16
78+
# DISASM-NEXT: leaq -230(%rip), %r16
79+
# DISASM-NEXT: leaq -238(%rip), %r16
80+
# DISASM-NEXT: movq 8217(%rip), %r16
81+
# DISASM-NEXT: movq 8209(%rip), %r16
7082

7183
# NORELAX-LABEL: <_start>:
7284
# NORELAX-COUNT-12: movq
7385
# NORELAX-COUNT-6: callq *
7486
# NORELAX-COUNT-6: jmpq *
87+
# NORELAX-COUNT-12: movq
7588

7689
.text
7790
.globl foo

0 commit comments

Comments
 (0)