[lld] r190752 - Add _end symbol for dynamic libraries. At least brk/sbrk in libc on
Joerg Sonnenberger
joerg at bec.de
Sat Sep 14 06:45:29 PDT 2013
Author: joerg
Date: Sat Sep 14 08:45:29 2013
New Revision: 190752
URL: http://llvm.org/viewvc/llvm-project?rev=190752&view=rev
Log:
Add _end symbol for dynamic libraries. At least brk/sbrk in libc on
NetBSD need it.
Modified:
lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h
lld/trunk/test/elf/symbols.test
Modified: lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h?rev=190752&r1=190751&r2=190752&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DynamicLibraryWriter.h Sat Sep 14 08:45:29 2013
@@ -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>::buildDy
OutputELFWriter<ELFT>::buildDynamicSymbolTable(file);
}
-template<class ELFT>
-void DynamicLibraryWriter<ELFT>::addDefaultAtoms() { }
+template <class ELFT> void DynamicLibraryWriter<ELFT>::addDefaultAtoms() {
+ _runtimeFile.addAbsoluteAtom("_end");
+}
+
+/// \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>
+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();
}
Modified: lld/trunk/test/elf/symbols.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/symbols.test?rev=190752&r1=190751&r2=190752&view=diff
==============================================================================
--- lld/trunk/test/elf/symbols.test (original)
+++ lld/trunk/test/elf/symbols.test Sat Sep 14 08:45:29 2013
@@ -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
More information about the llvm-commits
mailing list