2013-03-05 22:45:59 +08:00
|
|
|
//===- lib/ReaderWriter/ELF/DynamicLibraryWriter.h ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLD_READER_WRITER_ELF_DYNAMIC_LIBRARY_WRITER_H
|
|
|
|
#define LLD_READER_WRITER_ELF_DYNAMIC_LIBRARY_WRITER_H
|
|
|
|
|
2013-03-09 05:42:51 +08:00
|
|
|
#include "OutputELFWriter.h"
|
2013-03-05 22:45:59 +08:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf {
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
|
|
|
|
|
|
|
template<class ELFT>
|
|
|
|
class DynamicLibraryWriter;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DynamicLibraryWriter Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
template<class ELFT>
|
2013-03-09 05:42:51 +08:00
|
|
|
class DynamicLibraryWriter : public OutputELFWriter<ELFT> {
|
2013-03-05 22:45:59 +08:00
|
|
|
public:
|
2013-08-07 06:31:59 +08:00
|
|
|
DynamicLibraryWriter(const ELFLinkingContext &context)
|
|
|
|
: OutputELFWriter<ELFT>(context) {}
|
2013-03-05 22:45:59 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void buildDynamicSymbolTable(const File &file);
|
|
|
|
void addDefaultAtoms();
|
|
|
|
void finalizeDefaultAtomValues();
|
|
|
|
|
|
|
|
llvm::BumpPtrAllocator _alloc;
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DynamicLibraryWriter
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
template <class ELFT>
|
|
|
|
void DynamicLibraryWriter<ELFT>::buildDynamicSymbolTable(const File &file) {
|
|
|
|
// Add all the defined symbols to the dynamic symbol table
|
2013-03-15 00:09:49 +08:00
|
|
|
// we need hooks into the Atom to find out which atoms need
|
|
|
|
// to be exported
|
2013-03-09 05:42:51 +08:00
|
|
|
for (auto sec : this->_layout->sections())
|
2013-03-05 22:45:59 +08:00
|
|
|
if (auto section = dyn_cast<AtomSection<ELFT>>(sec))
|
|
|
|
for (const auto &atom : section->atoms()) {
|
|
|
|
const DefinedAtom *da = dyn_cast<const DefinedAtom>(atom->_atom);
|
2013-03-15 00:09:49 +08:00
|
|
|
if (da && (da->scope() != DefinedAtom::scopeTranslationUnit))
|
2013-03-09 05:42:51 +08:00
|
|
|
this->_dynamicSymbolTable->addSymbol(atom->_atom, section->ordinal(),
|
|
|
|
atom->_virtualAddr, atom);
|
2013-03-05 22:45:59 +08:00
|
|
|
}
|
|
|
|
|
2013-04-01 23:14:34 +08:00
|
|
|
for (const UndefinedAtom *a : file.undefined())
|
|
|
|
this->_dynamicSymbolTable->addSymbol(a, ELF::SHN_UNDEF);
|
|
|
|
|
2013-03-09 05:42:51 +08:00
|
|
|
OutputELFWriter<ELFT>::buildDynamicSymbolTable(file);
|
2013-03-05 22:45:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class ELFT>
|
2013-03-09 05:42:51 +08:00
|
|
|
void DynamicLibraryWriter<ELFT>::addDefaultAtoms() { }
|
2013-03-05 22:45:59 +08:00
|
|
|
|
|
|
|
template<class ELFT>
|
|
|
|
void DynamicLibraryWriter<ELFT>::finalizeDefaultAtomValues() {
|
2013-03-09 05:42:51 +08:00
|
|
|
this->_targetHandler.finalizeSymbolValues();
|
2013-03-05 22:45:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace elf
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif // LLD_READER_WRITER_ELF_DYNAMIC_LIBRARY_WRITER_H
|