Skip to content

Commit d1fdd48

Browse files
committed
Updated test, added comments and removed symbols unneeded.
1 parent ea53c43 commit d1fdd48

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

lld/ELF/Arch/X86_64.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ void X86_64::relaxTlsIeToLe(uint8_t *loc, const Relocation &rel,
584584
memcpy(inst, "\x48\xc7", 2);
585585
*regSlot = 0xc0 | reg;
586586
} else {
587-
ErrAlways(ctx)
587+
Err(ctx)
588588
<< getErrorLoc(ctx, loc - 3)
589589
<< "R_X86_64_GOTTPOFF must be used in MOVQ or ADDQ instructions only";
590590
}
@@ -596,10 +596,18 @@ void X86_64::relaxTlsIeToLe(uint8_t *loc, const Relocation &rel,
596596
const uint8_t rex = loc[-3];
597597
loc[-3] = (rex & ~0x44) | (rex & 0x44) >> 2;
598598
*regSlot = 0xc0 | reg;
599+
600+
// "movq foo@gottpoff(%rip),%r[16-31]" -> "movq $foo,%r[16-31]"
599601
if (loc[-2] == 0x8b)
600602
loc[-2] = 0xc7;
601-
else
603+
else {
604+
// "addq foo@gottpoff(%rip),%r[16-31]" -> "addq $foo,%r[16-31]"
605+
if (loc[-2] != 0x03)
606+
Err(ctx) << getErrorLoc(ctx, loc - 3)
607+
<< "R_X86_64_CODE_4_GOTTPOFF must be used in MOVQ or ADDQ "
608+
"instructions only";
602609
loc[-2] = 0x81;
610+
}
603611
}
604612

605613
// The original code used a PC relative relocation.

lld/test/ELF/x86-64-tls-ie-local.s

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,32 @@
55
# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=REL %s
66
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t.so | FileCheck %s
77

8-
# SEC: .got PROGBITS 0000000000002378 000378 000020 00 WA 0 0 8
8+
# SEC: .got PROGBITS 0000000000002348 000348 000010 00 WA 0 0 8
99

1010
## Dynamic relocations for non-preemptable symbols in a shared object have section index 0.
1111
# REL: .rela.dyn {
12-
# REL-NEXT: 0x2378 R_X86_64_TPOFF64 - 0x0
13-
# REL-NEXT: 0x2380 R_X86_64_TPOFF64 - 0x8
14-
# REL-NEXT: 0x2388 R_X86_64_TPOFF64 - 0x4
15-
# REL-NEXT: 0x2390 R_X86_64_TPOFF64 - 0xC
12+
# REL-NEXT: 0x2348 R_X86_64_TPOFF64 - 0x0
13+
# REL-NEXT: 0x2350 R_X86_64_TPOFF64 - 0x4
1614
# REL-NEXT: }
1715

18-
## &.got[0] - 0x12af = 0x2378 - 0x12af = 4297
19-
## &.got[1] - 0x12b6 = 0x2380 - 0x12b6 = 4298
20-
## &.got[2] - 0x12be = 0x2388 - 0x12be = 4298
21-
## &.got[3] - 0x12c6 = 0x2390 - 0x12c6 = 4298
16+
## &.got[0] - 0x127f = 0x2348 - 0x127f = 4297
17+
## &.got[1] - 0x1286 = 0x2350 - 0x1286 = 4298
18+
## &.got[2] - 0x128e = 0x2348 - 0x128e = 4282
19+
## &.got[3] - 0x1296 = 0x2350 - 0x1296 = 4282
2220

23-
# CHECK: 12a8: addq 4297(%rip), %rax
24-
# CHECK-NEXT: 12af: addq 4298(%rip), %rax
25-
# CHECK-NEXT: 12b6: addq 4298(%rip), %r16
26-
# CHECK-NEXT: 12be: addq 4298(%rip), %r16
21+
# CHECK: 1278: addq 4297(%rip), %rax
22+
# CHECK-NEXT: 127f: addq 4298(%rip), %rax
23+
# CHECK-NEXT: 1286: addq 4282(%rip), %r16
24+
# CHECK-NEXT: 128e: addq 4282(%rip), %r16
2725

2826
addq foo@GOTTPOFF(%rip), %rax
2927
addq bar@GOTTPOFF(%rip), %rax
30-
addq foo2@GOTTPOFF(%rip), %r16
31-
addq bar2@GOTTPOFF(%rip), %r16
28+
addq foo@GOTTPOFF(%rip), %r16
29+
addq bar@GOTTPOFF(%rip), %r16
3230

3331

3432
.section .tbss,"awT",@nobits
3533
foo:
3634
.long 0
37-
foo2:
38-
.long 0
3935
bar:
4036
.long 0
41-
bar2:
42-
.long 0

0 commit comments

Comments
 (0)