[lld] r249254 - [ELF2/AArch64] Add support for AARCH64_ABS{16, 32, 64} relocations.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 3 17:59:17 PDT 2015
Author: davide
Date: Sat Oct 3 19:59:16 2015
New Revision: 249254
URL: http://llvm.org/viewvc/llvm-project?rev=249254&view=rev
Log:
[ELF2/AArch64] Add support for AARCH64_ABS{16,32,64} relocations.
I saw these in the wild while trying to link shared libraries.
Added:
lld/trunk/test/elf2/aarch64-data-relocs.s
Modified:
lld/trunk/ELF/Target.cpp
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=249254&r1=249253&r2=249254&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Sat Oct 3 19:59:16 2015
@@ -267,6 +267,26 @@ static uint64_t AArch64GetPage(uint64_t
return Expr & (~static_cast<uint64_t>(0xFFF));
}
+static void handle_ABS16(uint8_t *Location, uint64_t S, int64_t A) {
+ uint64_t X = S + A;
+ if (!isInt<16>(X)) // -2^15 <= X < 2^16
+ error("Relocation R_AARCH64_ABS16 out of range");
+ write16le(Location, read32le(Location) | X);
+}
+
+static void handle_ABS32(uint8_t *Location, uint64_t S, int64_t A) {
+ uint64_t X = S + A;
+ if (!isInt<32>(X)) // -2^31 <= X < 2^32
+ error("Relocation R_AARCH64_ABS32 out of range");
+ write32le(Location, read32le(Location) | X);
+}
+
+static void handle_ABS64(uint8_t *Location, uint64_t S, int64_t A) {
+ uint64_t X = S + A;
+ // No overflow check.
+ write64le(Location, read32le(Location) | X);
+}
+
static void handle_ADD_ABS_LO12_NC(uint8_t *Location, uint64_t S, int64_t A) {
// No overflow check.
uint64_t X = ((S + A) & 0xFFF) << 10;
@@ -300,6 +320,15 @@ void AArch64TargetInfo::relocateOne(uint
int64_t A = Rel.r_addend;
uint64_t P = BaseAddr + Rel.r_offset;
switch (Type) {
+ case R_AARCH64_ABS16:
+ handle_ABS16(Location, S, A);
+ break;
+ case R_AARCH64_ABS32:
+ handle_ABS32(Location, S, A);
+ break;
+ case R_AARCH64_ABS64:
+ handle_ABS64(Location, S, A);
+ break;
case R_AARCH64_ADD_ABS_LO12_NC:
handle_ADD_ABS_LO12_NC(Location, S, A);
break;
Added: lld/trunk/test/elf2/aarch64-data-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/aarch64-data-relocs.s?rev=249254&view=auto
==============================================================================
--- lld/trunk/test/elf2/aarch64-data-relocs.s (added)
+++ lld/trunk/test/elf2/aarch64-data-relocs.s Sat Oct 3 19:59:16 2015
@@ -0,0 +1,29 @@
+// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t
+// RUN: lld -flavor gnu2 -shared %t -o %t2
+// RUN: llvm-objdump -d %t2 | FileCheck %s
+// REQUIRES: aarch64
+
+.section .R_AARCH64_ABS16, "ax", at progbits
+ .hword sym+12
+
+.section .R_AARCH64_ABS32, "ax", at progbits
+ .word sym+24
+
+.section .R_AARCH64_ABS64, "ax", at progbits
+ .xword sym+36
+
+// CHECK: Disassembly of section .R_AARCH64_ABS16:
+// CHECK-NEXT: $d.0:
+// CHECK-NEXT: 2000: 0c 00 .short
+// ^-- A = 0xc
+
+// CHECK-NEXT: Disassembly of section .R_AARCH64_ABS32:
+// CHECK-NEXT: $d.1:
+// CHECK-NEXT: 2002: 18 00 00 00 .word
+// ^-- A = 0x18
+
+// CHECK-NEXT: Disassembly of section .R_AARCH64_ABS64:
+// CHECK-NEXT: $d.2:
+// CHECK-NEXT: 2006: 24 00 00 00 .word
+// ^-- A = 0x24
+// CHECK-NEXT: 200a: 00 00 00 00 .word
More information about the llvm-commits
mailing list