[lld] r238014 - [ARM] Implement R_ARM_GLOB_DAT for GOT entries
Denis Protivensky
dprotivensky at accesssoftek.com
Fri May 22 04:00:32 PDT 2015
Author: denis-protivensky
Date: Fri May 22 06:00:31 2015
New Revision: 238014
URL: http://llvm.org/viewvc/llvm-project?rev=238014&view=rev
Log:
[ARM] Implement R_ARM_GLOB_DAT for GOT entries
This is used when referencing global or static data in shared
objects. This is also used when function's address is taken and
function call is made indirectly.
Added:
lld/trunk/test/elf/ARM/rel-glob-dat.test
lld/trunk/test/elf/ARM/rel-jump-slot.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/ARM/ARMLinkingContext.h
lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/ARM/ARMLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ARM/ARMLinkingContext.h?rev=238014&r1=238013&r2=238014&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMLinkingContext.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMLinkingContext.h Fri May 22 06:00:31 2015
@@ -38,6 +38,7 @@ public:
return false;
assert(r.kindArch() == Reference::KindArch::ARM);
switch (r.kindValue()) {
+ case llvm::ELF::R_ARM_GLOB_DAT:
case llvm::ELF::R_ARM_TLS_TPOFF32:
case llvm::ELF::R_ARM_COPY:
return true;
Modified: lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp?rev=238014&r1=238013&r2=238014&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationHandler.cpp Fri May 22 06:00:31 2015
@@ -665,6 +665,7 @@ std::error_code ARMTargetRelocationHandl
case R_ARM_LDR_PC_G2:
return relocR_ARM_LDR_PC_G2(loc, reloc, target, addend);
case R_ARM_JUMP_SLOT:
+ case R_ARM_GLOB_DAT:
case R_ARM_IRELATIVE:
// Runtime only relocations. Ignore here.
return std::error_code();
Modified: lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp?rev=238014&r1=238013&r2=238014&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp Fri May 22 06:00:31 2015
@@ -945,9 +945,15 @@ public:
return _plt0;
}
+ const GOTAtom *getSharedGOTEntry(const SharedLibraryAtom *sla) {
+ return getGOT<R_ARM_GLOB_DAT>(sla);
+ }
+
std::error_code handleGOT(const Reference &ref) {
- assert(!isa<const SharedLibraryAtom>(ref.target()) &&
- "Shared GOT entries aren't handled yet");
+ if (const auto sla = dyn_cast<const SharedLibraryAtom>(ref.target())) {
+ const_cast<Reference &>(ref).setTarget(getSharedGOTEntry(sla));
+ return std::error_code();
+ }
return ARMRelocationPass::handleGOT(ref);
}
};
Added: lld/trunk/test/elf/ARM/rel-glob-dat.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/ARM/rel-glob-dat.test?rev=238014&view=auto
==============================================================================
--- lld/trunk/test/elf/ARM/rel-glob-dat.test (added)
+++ lld/trunk/test/elf/ARM/rel-glob-dat.test Fri May 22 06:00:31 2015
@@ -0,0 +1,58 @@
+# Check handling of R_ARM_GLOB_DAT relocation.
+
+# RUN: yaml2obj -format=elf %s > %t-o.o
+# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -shared \
+# RUN: --noinhibit-exec %t-o.o -lfn -L%p/Inputs -o %t
+# RUN: llvm-readobj -relocations %t | FileCheck %s
+
+# CHECK: 0x401000 R_ARM_GLOB_DAT fn
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_ARM
+ Flags: [ EF_ARM_EABI_VER5 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x0000000000000004
+ Content: 00482DE904B08DE208D04DE224209FE502208FE020309FE5033092E708300BE508301BE533FF2FE10030A0E10300A0E104D04BE20088BDE82000000000000000
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x0000000000000004
+ Info: .text
+ Relocations:
+ - Offset: 0x0000000000000038
+ Symbol: _GLOBAL_OFFSET_TABLE_
+ Type: R_ARM_BASE_PREL
+ - Offset: 0x000000000000003C
+ Symbol: fn
+ Type: R_ARM_GOT_BREL
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000001
+ Content: ''
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000001
+ Content: ''
+Symbols:
+ Local:
+ - Name: '$a'
+ Section: .text
+ - Name: '$d'
+ Section: .text
+ Value: 0x0000000000000038
+ Global:
+ - Name: f
+ Type: STT_FUNC
+ Section: .text
+ - Name: _GLOBAL_OFFSET_TABLE_
+ - Name: fn
+...
Added: lld/trunk/test/elf/ARM/rel-jump-slot.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/ARM/rel-jump-slot.test?rev=238014&view=auto
==============================================================================
--- lld/trunk/test/elf/ARM/rel-jump-slot.test (added)
+++ lld/trunk/test/elf/ARM/rel-jump-slot.test Fri May 22 06:00:31 2015
@@ -0,0 +1,51 @@
+# Check handling of R_ARM_JUMP_SLOT relocation.
+
+# RUN: yaml2obj -format=elf %s > %t-o.o
+# RUN: lld -flavor gnu -target arm -m armelf_linux_eabi -shared \
+# RUN: --noinhibit-exec %t-o.o -lfn -L%p/Inputs -o %t
+# RUN: llvm-readobj -relocations %t | FileCheck %s
+
+# CHECK: 0x40100C R_ARM_JUMP_SLOT fn 0x0
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_ARM
+ Flags: [ EF_ARM_EABI_VER5 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x0000000000000004
+ Content: 00482DE904B08DE2FEFFFFEB0030A0E10300A0E10088BDE8
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x0000000000000004
+ Info: .text
+ Relocations:
+ - Offset: 0x0000000000000008
+ Symbol: fn
+ Type: R_ARM_CALL
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000001
+ Content: ''
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000001
+ Content: ''
+Symbols:
+ Local:
+ - Name: '$a'
+ Section: .text
+ Global:
+ - Name: f
+ Type: STT_FUNC
+ Section: .text
+ - Name: fn
+...
More information about the llvm-commits
mailing list