diff options
| author | Joerg Sonnenberger <joerg@bec.de> | 2013-09-14 13:45:29 +0000 |
|---|---|---|
| committer | Joerg Sonnenberger <joerg@bec.de> | 2013-09-14 13:45:29 +0000 |
| commit | 4263d8b35dd927b3cd939d08a285e79fe0dd7f18 (patch) | |
| tree | e83d8c820216e55d877ad672af2b70557daaf4c2 /lld | |
| parent | d5489074e69ce6f66b4f714491f5a2c70fdce422 (diff) | |
| download | bcm5719-llvm-4263d8b35dd927b3cd939d08a285e79fe0dd7f18.tar.gz bcm5719-llvm-4263d8b35dd927b3cd939d08a285e79fe0dd7f18.zip | |
Add _end symbol for dynamic libraries. At least brk/sbrk in libc on
NetBSD need it.
llvm-svn: 190752
Diffstat (limited to 'lld')
| -rw-r--r-- | lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h | 33 | ||||
| -rw-r--r-- | lld/test/elf/symbols.test | 9 |
2 files changed, 37 insertions, 5 deletions
diff --git a/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h index 1c8b12ffcb3..9d057becbeb 100644 --- a/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h +++ b/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h @@ -26,14 +26,16 @@ template<class ELFT> class DynamicLibraryWriter : public OutputELFWriter<ELFT> { public: DynamicLibraryWriter(const ELFLinkingContext &context) - : OutputELFWriter<ELFT>(context) {} + : OutputELFWriter<ELFT>(context), _runtimeFile(context) {} private: void buildDynamicSymbolTable(const File &file); void addDefaultAtoms(); + virtual void addFiles(InputFiles &); void finalizeDefaultAtomValues(); llvm::BumpPtrAllocator _alloc; + CRuntimeFile<ELFT> _runtimeFile; }; //===----------------------------------------------------------------------===// @@ -59,11 +61,34 @@ void DynamicLibraryWriter<ELFT>::buildDynamicSymbolTable(const File &file) { OutputELFWriter<ELFT>::buildDynamicSymbolTable(file); } -template<class ELFT> -void DynamicLibraryWriter<ELFT>::addDefaultAtoms() { } +template <class ELFT> void DynamicLibraryWriter<ELFT>::addDefaultAtoms() { + _runtimeFile.addAbsoluteAtom("_end"); +} -template<class ELFT> +/// \brief Hook in lld to add CRuntime file +template <class ELFT> +void DynamicLibraryWriter<ELFT>::addFiles(InputFiles &inputFiles) { + // Add the default atoms as defined by executables + addDefaultAtoms(); + // Add the runtime file + inputFiles.prependFile(_runtimeFile); + // Add the Linker internal file for symbols that are defined by + // command line options + OutputELFWriter<ELFT>::addFiles(inputFiles); +} + +template <class ELFT> void DynamicLibraryWriter<ELFT>::finalizeDefaultAtomValues() { + auto underScoreEndAtomIter = this->_layout->findAbsoluteAtom("_end"); + + if (auto bssSection = this->_layout->findOutputSection(".bss")) { + (*underScoreEndAtomIter)->_virtualAddr = + bssSection->virtualAddr() + bssSection->memSize(); + } else if (auto dataSection = this->_layout->findOutputSection(".data")) { + (*underScoreEndAtomIter)->_virtualAddr = + dataSection->virtualAddr() + dataSection->memSize(); + } + this->_targetHandler.finalizeSymbolValues(); } diff --git a/lld/test/elf/symbols.test b/lld/test/elf/symbols.test index 3fcc7841160..8e3dc25032b 100644 --- a/lld/test/elf/symbols.test +++ b/lld/test/elf/symbols.test @@ -14,8 +14,10 @@ #} # -RUN: lld -flavor gnu -target i386 -e main %p/Inputs/writersyms.o -o %t1 +RUN: lld -flavor gnu -target i386 -e main %p/Inputs/writersyms.o -o %t1 RUN: llvm-nm -n %t1 | FileCheck -check-prefix CHECKSYMS %s +RUN: lld -flavor gnu -shared -target i386 -e main %p/Inputs/writersyms.o -o %t1 +RUN: llvm-nm -n %t1 | FileCheck -check-prefix CHECKSHAREDSYMS %s CHECKSYMS: 00000000 a 1.c CHECKSYMS: 00000114 T main @@ -24,3 +26,8 @@ CHECKSYMS: 00001000 B a CHECKSYMS: 00001004 A __bss_end CHECKSYMS: 00001004 A _end CHECKSYMS: 00001004 A end + +CHECKSHAREDSYMS: 00000000 a 1.c +CHECKSHAREDSYMS: 0000010c T main +CHECKSHAREDSYMS: 00001000 B a +CHECKSHAREDSYMS: 00001004 A _end |

