[PATCH] ELF/AArch64: Add support for R_AARCH64_ABS16

Will Newton will.newton at linaro.org
Thu Feb 12 22:53:26 PST 2015


Add support for the R_AARCH64_ABS16 relocation type and add tests.
---
 .../ELF/AArch64/AArch64RelocationHandler.cpp       | 21 +++++++++
 test/elf/AArch64/rel-abs16-overflow.test           | 44 ++++++++++++++++++
 test/elf/AArch64/rel-abs16.test                    | 53 ++++++++++++++++++++++
 3 files changed, 118 insertions(+)
 create mode 100644 test/elf/AArch64/rel-abs16-overflow.test
 create mode 100644 test/elf/AArch64/rel-abs16.test

diff --git a/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp b/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
index 878b2ad..7be9ee9 100644
--- a/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
+++ b/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
@@ -64,6 +64,24 @@ static std::error_code relocR_AARCH64_ABS32(uint8_t *location, uint64_t P,
   return std::error_code();
 }
 
+/// \brief R_AARCH64_ABS16 - word16:  S + A
+static std::error_code relocR_AARCH64_ABS16(uint8_t *location, uint64_t P,
+                                            uint64_t S, int64_t A) {
+  int64_t result = S + A;
+  if (!withinSignedUnsignedRange(result, 16))
+    return make_out_of_range_reloc_error();
+  DEBUG_WITH_TYPE(
+      "AArch64", llvm::dbgs() << "\t\tHandle " << LLVM_FUNCTION_NAME << " -";
+      llvm::dbgs() << " S: 0x" << Twine::utohexstr(S);
+      llvm::dbgs() << " A: 0x" << Twine::utohexstr(A);
+      llvm::dbgs() << " P: 0x" << Twine::utohexstr(P);
+      llvm::dbgs() << " result: 0x" << Twine::utohexstr(result) << "\n");
+  *reinterpret_cast<llvm::support::ulittle16_t *>(location) =
+      result |
+      (int16_t) * reinterpret_cast<llvm::support::little16_t *>(location);
+  return std::error_code();
+}
+
 /// \brief R_AARCH64_ADR_PREL_PG_HI21 - Page(S+A) - Page(P)
 static void relocR_AARCH64_ADR_PREL_PG_HI21(uint8_t *location, uint64_t P,
                                             uint64_t S, int64_t A) {
@@ -396,6 +414,9 @@ std::error_code AArch64TargetRelocationHandler::applyRelocation(
   case R_AARCH64_ABS32:
     return relocR_AARCH64_ABS32(location, relocVAddress, targetVAddress,
                                 ref.addend());
+  case R_AARCH64_ABS16:
+    return relocR_AARCH64_ABS16(location, relocVAddress, targetVAddress,
+                                ref.addend());
   // Runtime only relocations. Ignore here.
   case R_AARCH64_RELATIVE:
   case R_AARCH64_IRELATIVE:
diff --git a/test/elf/AArch64/rel-abs16-overflow.test b/test/elf/AArch64/rel-abs16-overflow.test
new file mode 100644
index 0000000..f9907ac
--- /dev/null
+++ b/test/elf/AArch64/rel-abs16-overflow.test
@@ -0,0 +1,44 @@
+# Check handling of R_AARCH64_ABS16 relocation overflow.
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: not lld -flavor gnu -target arm64 -o %t-exe %t-obj 2>&1 | FileCheck %s
+
+# CHECK: Relocation out of range in file {{.*}}: reference from data1+0 to data1+0 of type 259 (R_AARCH64_ABS16)
+
+!ELF
+FileHeader: !FileHeader
+  Class: ELFCLASS64
+  Data: ELFDATA2LSB
+  Type: ET_REL
+  Machine: EM_AARCH64
+
+Sections:
+- Name: .text
+  Type: SHT_PROGBITS
+  Content: "00000000"
+  AddressAlign: 16
+  Flags: [SHF_ALLOC, SHF_EXECINSTR]
+- Name: .data
+  Type: SHT_PROGBITS
+  Content: "0000000000000000"
+  AddressAlign: 16
+  Flags: [SHF_ALLOC, SHF_WRITE]
+
+- Name: .rela.data
+  Type: SHT_RELA
+  Info: .data
+  AddressAlign: 8
+  Relocations:
+    - Offset: 0
+      Symbol: data1
+      Type: R_AARCH64_ABS16
+      Addend: 0
+
+Symbols:
+  Global:
+    - Name: _start
+      Section: .text
+      Value: 0x0
+      Size: 4
+    - Name: data1
+      Section: .data
+      Size: 4
diff --git a/test/elf/AArch64/rel-abs16.test b/test/elf/AArch64/rel-abs16.test
new file mode 100644
index 0000000..1b7a67d
--- /dev/null
+++ b/test/elf/AArch64/rel-abs16.test
@@ -0,0 +1,53 @@
+# Check handling of R_AARCH64_ABS16 relocation.
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor gnu -target arm64 -o %t-exe %t-obj
+# RUN: llvm-objdump -s -t %t-exe | FileCheck %s
+
+# CHECK: Contents of section .data:
+# CHECK-NEXT: 401060 60100000 00000000 `.......
+#                    ^^ data1 - 0x400000 = 0x1060
+# CHECK: SYMBOL TABLE:
+# CHECK: 00401060 g  .data  00000004 data1
+
+!ELF
+FileHeader: !FileHeader
+  Class: ELFCLASS64
+  Data: ELFDATA2LSB
+  Type: ET_REL
+  Machine: EM_AARCH64
+
+Sections:
+- Name: .text
+  Type: SHT_PROGBITS
+  Content: "00000000"
+  AddressAlign: 16
+  Flags: [SHF_ALLOC, SHF_EXECINSTR]
+- Name: .data
+  Type: SHT_PROGBITS
+  Content: "0000000000000000"
+  AddressAlign: 16
+  Flags: [SHF_ALLOC, SHF_WRITE]
+
+- Name: .rela.data
+  Type: SHT_RELA
+  Info: .data
+  AddressAlign: 8
+  Relocations:
+    - Offset: 0x0
+      Symbol: data1
+      Type: R_AARCH64_ABS16
+      Addend: -4194304
+
+Symbols:
+  Global:
+    - Name: _start
+      Section: .text
+      Value: 0x0
+      Size: 4
+    - Name: data1
+      Section: .data
+      Size: 4
+    - Name: data2
+      Section: .data
+      Value: 0x4
+      Size: 4
-- 
2.1.0




More information about the llvm-commits mailing list