Add _end symbol for dynamic libraries. At least brk/sbrk in libc on

NetBSD need it.

llvm-svn: 190752
This commit is contained in:
Joerg Sonnenberger 2013-09-14 13:45:29 +00:00
parent d5489074e6
commit 4263d8b35d
2 changed files with 37 additions and 5 deletions

View File

@ -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();
}

View File

@ -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