forked from OSchip/llvm-project
[ARM] Add needed symbols during dynamic executable linking
These include _GLOBAL_OFFSET_TABLE_ and _DYNAMIC. llvm-svn: 237791
This commit is contained in:
parent
196390e8af
commit
56b12d75bf
|
@ -17,6 +17,7 @@
|
|||
|
||||
namespace {
|
||||
const char *gotSymbol = "_GLOBAL_OFFSET_TABLE_";
|
||||
const char *dynamicSymbol = "_DYNAMIC";
|
||||
}
|
||||
|
||||
namespace lld {
|
||||
|
@ -53,6 +54,13 @@ ARMExecutableWriter::ARMExecutableWriter(ARMLinkingContext &ctx,
|
|||
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::finalizeDefaultAtomValues() {
|
|||
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();
|
||||
|
|
|
@ -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
|
||||
...
|
Loading…
Reference in New Issue