From 596dae5fc2d926325c7dfb5bc4192c027059310a Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Mon, 6 Apr 2015 15:15:01 +0000 Subject: [PATCH] [LinkerScript] Handle symbols defined in linker scripts in case of shared lib This patch is a follow-up to the rL232409 and allows define symbols in a linker script in case of linking shared library. llvm-svn: 234163 --- .../ReaderWriter/ELF/DynamicLibraryWriter.h | 2 ++ .../elf/linkerscript/Inputs/simple-pic.o.yaml | 32 +++++++++++++++++++ .../linkerscript/symbol-definition-so.test | 32 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 lld/test/elf/linkerscript/Inputs/simple-pic.o.yaml create mode 100644 lld/test/elf/linkerscript/symbol-definition-so.test diff --git a/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h index ebc03f9c889f..6cfa14ca7cc9 100644 --- a/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h @@ -60,6 +60,7 @@ void DynamicLibraryWriter::buildDynamicSymbolTable(const File &file) { } template void DynamicLibraryWriter::addDefaultAtoms() { + OutputELFWriter::addDefaultAtoms(); _runtimeFile->addAbsoluteAtom("_end"); } @@ -76,6 +77,7 @@ bool DynamicLibraryWriter::createImplicitFiles( template void DynamicLibraryWriter::finalizeDefaultAtomValues() { + OutputELFWriter::finalizeDefaultAtomValues(); lld::AtomLayout *underScoreEndAtom = this->_layout.findAbsoluteAtom("_end"); assert(underScoreEndAtom); diff --git a/lld/test/elf/linkerscript/Inputs/simple-pic.o.yaml b/lld/test/elf/linkerscript/Inputs/simple-pic.o.yaml new file mode 100644 index 000000000000..f826034053c3 --- /dev/null +++ b/lld/test/elf/linkerscript/Inputs/simple-pic.o.yaml @@ -0,0 +1,32 @@ +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 4 + Size: 16 + + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + AddressAlign: 4 + Size: 16 + +Symbols: + Local: + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .text + Type: STT_SECTION + Section: .text + Global: + - Name: foo + Type: STT_FUNC + Section: .text + Size: 16 diff --git a/lld/test/elf/linkerscript/symbol-definition-so.test b/lld/test/elf/linkerscript/symbol-definition-so.test new file mode 100644 index 000000000000..7f4004761f88 --- /dev/null +++ b/lld/test/elf/linkerscript/symbol-definition-so.test @@ -0,0 +1,32 @@ +/* +We test whether we can define symbols in a linker script and have them exported +to the output file symbol table. This test is the same as symbol-definition.test +but make checking in case of shared library linking. + +We use the following linker script for this test: +*/ + +SECTIONS +{ + .text : { *(.text) } + MYSTRING = .; + .data : { *(.data) } +} + +/* +RUN: yaml2obj -format=elf %p/Inputs/simple-pic.o.yaml -o=%t.o + +RUN: lld -flavor gnu -target x86_64 -shared -T %s %t.o -o %t.so +RUN: llvm-readobj -s -symbols %t.so | FileCheck -check-prefix CHECKSYMS %s + +CHECKSYMS: Name: .data +CHECKSYMS-NEXT: Type: SHT_PROGBITS +CHECKSYMS-NEXT: Flags [ +CHECKSYMS-NEXT: SHF_ALLOC +CHECKSYMS-NEXT: SHF_WRITE +CHECKSYMS-NEXT: ] +CHECKSYMS-NEXT: Address: 0x401060 + +CHECKSYMS: Name: MYSTRING +CHECKSYMS-NEXT: Value: 0x401060 +*/ -- 2.34.1