summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h
diff options
context:
space:
mode:
authorJoerg Sonnenberger <joerg@bec.de>2013-09-14 13:45:29 +0000
committerJoerg Sonnenberger <joerg@bec.de>2013-09-14 13:45:29 +0000
commit4263d8b35dd927b3cd939d08a285e79fe0dd7f18 (patch)
treee83d8c820216e55d877ad672af2b70557daaf4c2 /lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h
parentd5489074e69ce6f66b4f714491f5a2c70fdce422 (diff)
downloadbcm5719-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/lib/ReaderWriter/ELF/DynamicLibraryWriter.h')
-rw-r--r--lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h33
1 files changed, 29 insertions, 4 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();
}
OpenPOWER on IntegriCloud