[lld] r237791 - [ARM] Add needed symbols during dynamic executable linking
Denis Protivensky
dprotivensky at accesssoftek.com
Wed May 20 06:39:33 PDT 2015
Author: denis-protivensky
Date: Wed May 20 08:39:33 2015
New Revision: 237791
URL: http://llvm.org/viewvc/llvm-project?rev=237791&view=rev
Log:
[ARM] Add needed symbols during dynamic executable linking
These include _GLOBAL_OFFSET_TABLE_ and _DYNAMIC.
Added:
lld/trunk/test/elf/ARM/dynamic-symbols.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h
Modified: lld/trunk/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h?rev=237791&r1=237790&r2=237791&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h Wed May 20 08:39:33 2015
@@ -17,6 +17,7 @@
namespace {
const char *gotSymbol = "_GLOBAL_OFFSET_TABLE_";
+const char *dynamicSymbol = "_DYNAMIC";
}
namespace lld {
@@ -53,6 +54,13 @@ ARMExecutableWriter::ARMExecutableWriter
void ARMExecutableWriter::createImplicitFiles(
std::vector<std::unique_ptr<File>> &result) {
ExecutableWriter::createImplicitFiles(result);
+ // Add default atoms for ARM.
+ if (_ctx.isDynamic()) {
+ auto file = llvm::make_unique<RuntimeFile<ELF32LE>>(_ctx, "ARM exec file");
+ file->addAbsoluteAtom(gotSymbol);
+ file->addAbsoluteAtom(dynamicSymbol);
+ result.push_back(std::move(file));
+ }
}
void ARMExecutableWriter::finalizeDefaultAtomValues() {
@@ -68,6 +76,13 @@ void ARMExecutableWriter::finalizeDefaul
gotAtom->_virtualAddr = 0;
}
+ if (auto *dynamicAtom = _armLayout.findAbsoluteAtom(dynamicSymbol)) {
+ if (auto dynamicSection = _armLayout.findOutputSection(".dynamic"))
+ dynamicAtom->_virtualAddr = dynamicSection->virtualAddr();
+ else
+ dynamicAtom->_virtualAddr = 0;
+ }
+
// Set required by gcc libc __ehdr_start symbol with pointer to ELF header
if (auto ehdr = _armLayout.findAbsoluteAtom("__ehdr_start"))
ehdr->_virtualAddr = _elfHeader->virtualAddr();
Added: lld/trunk/test/elf/ARM/dynamic-symbols.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/ARM/dynamic-symbols.test?rev=237791&view=auto
==============================================================================
--- lld/trunk/test/elf/ARM/dynamic-symbols.test (added)
+++ lld/trunk/test/elf/ARM/dynamic-symbols.test Wed May 20 08:39:33 2015
@@ -0,0 +1,59 @@
+# Check that proper dynamic symbols are present in the generated executable
+
+# RUN: yaml2obj -format=elf %s > %t-o.o
+# RUN: lld -flavor gnu -target arm-linux-gnu \
+# RUN: -Bstatic --noinhibit-exec %t-o.o -o %t
+# RUN: llvm-readobj -symbols %t | FileCheck -check-prefix=STATIC %s
+
+# STATIC-NOT: Name: _GLOBAL_OFFSET_TABLE_
+# STATIC-NOT: Name: _DYNAMIC
+
+# RUN: yaml2obj -format=elf %s > %t-o.o
+# RUN: lld -flavor gnu -target arm-linux-gnu \
+# RUN: --noinhibit-exec %t-o.o -o %t
+# RUN: llvm-readobj -symbols %t | FileCheck -check-prefix=EXEC-DYN %s
+
+# EXEC-DYN: Name: _GLOBAL_OFFSET_TABLE_
+# EXEC-DYN-NEXT: Value: {{[0-9]+}}
+# EXEC-DYN-NEXT: Size: 0
+# EXEC-DYN-NEXT: Binding: Global (0x1)
+# EXEC-DYN-NEXT: Type: Object (0x1)
+# EXEC-DYN-NEXT: Other: 0
+# EXEC-DYN-NEXT: Section: Absolute (0xFFF1)
+# EXEC-DYN: Name: _DYNAMIC
+# EXEC-DYN-NEXT: Value: {{[0-9]+}}
+# EXEC-DYN-NEXT: Size: 0
+# EXEC-DYN-NEXT: Binding: Global (0x1)
+# EXEC-DYN-NEXT: Type: Object (0x1)
+# EXEC-DYN-NEXT: Other: 0
+# EXEC-DYN-NEXT: Section: Absolute (0xFFF1)
+
+---
+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: 04B02DE500B08DE20030A0E30300A0E100D04BE204B09DE41EFF2FE1
+ - 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:
+ Global:
+ - Name: main
+ Type: STT_FUNC
+ Section: .text
+...
More information about the llvm-commits
mailing list