[lld] r234747 - ELF/AArch64: Add tests for ADR_PREL_LO21
Adhemerval Zanella
azanella at linux.vnet.ibm.com
Mon Apr 13 05:11:23 PDT 2015
Author: azanella
Date: Mon Apr 13 07:11:23 2015
New Revision: 234747
URL: http://llvm.org/viewvc/llvm-project?rev=234747&view=rev
Log:
ELF/AArch64: Add tests for ADR_PREL_LO21
Add default and overflow checking when processing
R_AARCH64_ADR_PREL_LO21 relocations.
Added:
lld/trunk/test/elf/AArch64/rel-adr_prel_lo21-overflow.test
lld/trunk/test/elf/AArch64/rel-adr_prel_lo21.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp?rev=234747&r1=234746&r2=234747&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationHandler.cpp Mon Apr 13 07:11:23 2015
@@ -137,9 +137,11 @@ static std::error_code relocR_AARCH64_AD
}
/// \brief R_AARCH64_ADR_PREL_LO21 - S + A - P
-static void relocR_AARCH64_ADR_PREL_LO21(uint8_t *location, uint64_t P,
- uint64_t S, int64_t A) {
- uint64_t result = S + A - P;
+static std::error_code relocR_AARCH64_ADR_PREL_LO21(uint8_t *location, uint64_t P,
+ uint64_t S, int64_t A) {
+ uint64_t result = (S + A) - P;
+ if (!isInt<20>(result))
+ return make_out_of_range_reloc_error();
uint32_t immlo = result & 0x3;
uint32_t immhi = result & 0x1FFFFC;
immlo = immlo << 29;
@@ -152,7 +154,7 @@ static void relocR_AARCH64_ADR_PREL_LO21
llvm::dbgs() << " immlo: " << Twine::utohexstr(immlo);
llvm::dbgs() << " result: " << Twine::utohexstr(result) << "\n");
write32le(location, immlo | immhi | read32le(location));
- // TODO: Make sure this is correct!
+ return std::error_code();
}
/// \brief R_AARCH64_ADD_ABS_LO12_NC
@@ -416,8 +418,7 @@ std::error_code AArch64TargetRelocationH
case R_AARCH64_ADR_PREL_PG_HI21:
return relocR_AARCH64_ADR_PREL_PG_HI21(loc, reloc, target, addend);
case R_AARCH64_ADR_PREL_LO21:
- relocR_AARCH64_ADR_PREL_LO21(loc, reloc, target, addend);
- break;
+ return relocR_AARCH64_ADR_PREL_LO21(loc, reloc, target, addend);
case R_AARCH64_ADD_ABS_LO12_NC:
relocR_AARCH64_ADD_ABS_LO12_NC(loc, reloc, target, addend);
break;
Added: lld/trunk/test/elf/AArch64/rel-adr_prel_lo21-overflow.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/AArch64/rel-adr_prel_lo21-overflow.test?rev=234747&view=auto
==============================================================================
--- lld/trunk/test/elf/AArch64/rel-adr_prel_lo21-overflow.test (added)
+++ lld/trunk/test/elf/AArch64/rel-adr_prel_lo21-overflow.test Mon Apr 13 07:11:23 2015
@@ -0,0 +1,45 @@
+# Check handling of R_AARCH64_ADR_PREL_PG_HI21 relocation.
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: not lld -flavor gnu -target arm64 -o %t-exe %t-obj
+
+# CHECK: Relocation out of range in file {{.*}}: reference from _start+0 to data1+1048577 of type 274 (R_AARCH64_ADR_PREL_LO21)
+
+!ELF
+FileHeader: !FileHeader
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_AARCH64
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "00000090"
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Content: "00000000"
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_WRITE]
+
+- Name: .rela.text
+ Type: SHT_RELA
+ Info: .text
+ AddressAlign: 8
+ Relocations:
+ - Offset: 0x0
+ Symbol: data1
+ Type: R_AARCH64_ADR_PREL_LO21
+ Addend: 0x100001
+
+Symbols:
+ Global:
+ - Name: _start
+ Section: .text
+ Value: 0x0
+ Size: 4
+ - Name: data1
+ Section: .data
+ Size: 8
Added: lld/trunk/test/elf/AArch64/rel-adr_prel_lo21.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/AArch64/rel-adr_prel_lo21.test?rev=234747&view=auto
==============================================================================
--- lld/trunk/test/elf/AArch64/rel-adr_prel_lo21.test (added)
+++ lld/trunk/test/elf/AArch64/rel-adr_prel_lo21.test Mon Apr 13 07:11:23 2015
@@ -0,0 +1,49 @@
+# Check handling of R_AARCH64_ADR_PREL_PG_HI21 relocation.
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor gnu -target arm64 -o %t-exe %t-obj
+# RUN: llvm-objdump -d -t %t-exe | FileCheck %s
+
+# CHECK: Disassembly of section .text:
+# CHECK-NEXT: _start:
+# CHECK-NEXT: 4001b0: 80 75 00 90 adrp x0, #15400960
+# 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: "00000090"
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+- Name: .data
+ Type: SHT_PROGBITS
+ Content: "00000000"
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_WRITE]
+
+- Name: .rela.text
+ Type: SHT_RELA
+ Info: .text
+ AddressAlign: 8
+ Relocations:
+ - Offset: 0x0
+ Symbol: data1
+ Type: R_AARCH64_ADR_PREL_LO21
+ Addend: 0
+
+Symbols:
+ Global:
+ - Name: _start
+ Section: .text
+ Value: 0x0
+ Size: 4
+ - Name: data1
+ Section: .data
+ Size: 8
More information about the llvm-commits
mailing list