[lld] r250584 - [ELF2] - Implemented R_X86_64_PLT32 relocation.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 16 16:52:25 PDT 2015
Author: grimar
Date: Fri Oct 16 18:52:24 2015
New Revision: 250584
URL: http://llvm.org/viewvc/llvm-project?rev=250584&view=rev
Log:
[ELF2] - Implemented R_X86_64_PLT32 relocation.
There is sometimes no need to generate relocation via PLT.
Example - when symbol is not undefined and we are not creating shared library. Then we can create relative relocation instead of referencing and creating PLT records.
Differential Revision: http://reviews.llvm.org/D13835
Modified:
lld/trunk/ELF/Target.cpp
lld/trunk/test/elf2/plt.s
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=250584&r1=250583&r2=250584&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Fri Oct 16 18:52:24 2015
@@ -256,7 +256,7 @@ bool X86_64TargetInfo::relocNeedsPlt(uin
// R_386_JMP_SLOT, etc).
return S.isShared();
case R_X86_64_PLT32:
- return true;
+ return canBePreempted(&S, true);
}
}
@@ -297,6 +297,9 @@ void X86_64TargetInfo::relocateOne(uint8
write32le(Loc, SA);
break;
}
+ case R_X86_64_PLT32:
+ write32le(Loc, SA - BaseAddr - Offset);
+ break;
default:
error("unrecognized reloc " + Twine(Type));
}
Modified: lld/trunk/test/elf2/plt.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/plt.s?rev=250584&r1=250583&r2=250584&view=diff
==============================================================================
--- lld/trunk/test/elf2/plt.s (original)
+++ lld/trunk/test/elf2/plt.s Fri Oct 16 18:52:24 2015
@@ -2,8 +2,12 @@
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/shared.s -o %t2.o
// RUN: ld.lld2 -shared %t2.o -o %t2.so
// RUN: ld.lld2 -shared %t.o %t2.so -o %t
+// RUN: ld.lld2 %t.o %t2.so -o %t3
// RUN: llvm-readobj -s -r %t | FileCheck %s
// RUN: llvm-objdump -d %t | FileCheck --check-prefix=DISASM %s
+// RUN: llvm-readobj -s -r %t3 | FileCheck --check-prefix=CHECK2 %s
+// RUN: llvm-objdump -d %t3 | FileCheck --check-prefix=DISASM2 %s
+
// REQUIRES: x86
// CHECK: Name: .plt
@@ -27,20 +31,43 @@
// CHECK-NEXT: }
// CHECK-NEXT: ]
+// CHECK2: Name: .plt
+// CHECK2-NEXT: Type: SHT_PROGBITS
+// CHECK2-NEXT: Flags [
+// CHECK2-NEXT: SHF_ALLOC
+// CHECK2-NEXT: SHF_EXECINSTR
+// CHECK2-NEXT: ]
+// CHECK2-NEXT: Address: 0x11020
+// CHECK2-NEXT: Offset:
+// CHECK2-NEXT: Size: 16
+// CHECK2-NEXT: Link: 0
+// CHECK2-NEXT: Info: 0
+// CHECK2-NEXT: AddressAlignment: 16
+
+// CHECK2: Relocations [
+// CHECK2-NEXT: Section ({{.*}}) .rela.dyn {
+// CHECK2-NEXT: 0x120A0 R_X86_64_GLOB_DAT bar 0x0
+// CHECK2-NEXT: 0x120A8 R_X86_64_GLOB_DAT zed 0x0
+// CHECK2-NEXT: }
+// CHECK2-NEXT: ]
+
// Unfortunately FileCheck can't do math, so we have to check for explicit
// values:
-// 0x11020 - (0x11000 + 1) - 4 = 27
-// 0x11020 - (0x11005 + 1) - 4 = 22
-// 0x11028 - (0x1100a + 1) - 4 = 25
+// 0x1020 - (0x1000 + 1) - 4 = 27
+// 0x1020 - (0x1005 + 1) - 4 = 22
+// 0x1028 - (0x100a + 1) - 4 = 25
+// 0x1030 - (0x100f + 1) - 4 = 28
// DISASM: _start:
// DISASM-NEXT: 1000: e9 {{.*}} jmp 27
// DISASM-NEXT: 1005: e9 {{.*}} jmp 22
// DISASM-NEXT: 100a: e9 {{.*}} jmp 25
+// DISASM-NEXT: 100f: e9 {{.*}} jmp 28
-// 0x120A0 - 0x11026 = 4218
-// 0x120A8 - 0x1102e = 4218
+// 0x20A0 - 0x1026 = 4218
+// 0x20A8 - 0x102e = 4218
+// 0x20B0 - 0x1036 = 4218
// DISASM: Disassembly of section .plt:
// DISASM-NEXT: .plt:
@@ -50,6 +77,30 @@
// DISASM-NEXT: 1028: ff 25 {{.*}} jmpq *4218(%rip)
// DISASM-NEXT: 102e: 90 nop
// DISASM-NEXT: 102f: 90 nop
+// DISASM-NEXT: 1030: ff 25 {{.*}} jmpq *4218(%rip)
+// DISASM-NEXT: 1036: 90 nop
+// DISASM-NEXT: 1037: 90 nop
+
+// 0x11020 - (0x11000 + 1) - 4 = 27
+// 0x11020 - (0x11005 + 1) - 4 = 22
+// 0x11028 - (0x1100a + 1) - 4 = 25
+// 0x11000 - (0x1100f + 1) - 4 = -20
+
+// DISASM2: _start:
+// DISASM2-NEXT: 11000: e9 {{.*}} jmp 27
+// DISASM2-NEXT: 11005: e9 {{.*}} jmp 22
+// DISASM2-NEXT: 1100a: e9 {{.*}} jmp 25
+// DISASM2-NEXT: 1100f: e9 {{.*}} jmp -20
+
+// DISASM2: Disassembly of section .plt:
+// DISASM2-NEXT: .plt:
+// DISASM2-NEXT: 11020: ff 25 7a 10 00 00 jmpq *4218(%rip)
+// DISASM2-NEXT: 11026: 90 nop
+// DISASM2-NEXT: 11027: 90 nop
+// DISASM2-NEXT: 11028: ff 25 7a 10 00 00 jmpq *4218(%rip)
+// DISASM2-NEXT: 1102e: 90 nop
+// DISASM2-NEXT: 1102f: 90 nop
+// DISASM2-NEXT-NOT: 110C0
.global _start
_start:
More information about the llvm-commits
mailing list