summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/ELF
diff options
context:
space:
mode:
Diffstat (limited to 'lld/lib/ReaderWriter/ELF')
-rw-r--r--lld/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h4
-rw-r--r--lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h4
-rw-r--r--lld/lib/ReaderWriter/ELF/ELFFile.h8
-rw-r--r--lld/lib/ReaderWriter/ELF/ExecutableWriter.h6
-rw-r--r--lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableAtoms.h4
-rw-r--r--lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h4
-rw-r--r--lld/lib/ReaderWriter/ELF/OutputELFWriter.h49
7 files changed, 52 insertions, 27 deletions
diff --git a/lld/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h b/lld/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h
index 7f1d37e3d5b..b53a8fee76b 100644
--- a/lld/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h
+++ b/lld/lib/ReaderWriter/ELF/ARM/ARMExecutableWriter.h
@@ -37,7 +37,7 @@ protected:
unique_bump_ptr<SymbolTable<ELFT>> createSymbolTable() override;
void processUndefinedSymbol(StringRef symName,
- CRuntimeFile<ELFT> &file) const override;
+ RuntimeFile<ELFT> &file) const override;
private:
ARMLinkingContext &_context;
ARMTargetLayout<ELFT> &_armLayout;
@@ -83,7 +83,7 @@ unique_bump_ptr<SymbolTable<ELFT>>
template <class ELFT>
void ARMExecutableWriter<ELFT>::processUndefinedSymbol(
- StringRef symName, CRuntimeFile<ELFT> &file) const {
+ StringRef symName, RuntimeFile<ELFT> &file) const {
if (symName == _gotSymbol) {
file.addAbsoluteAtom(_gotSymbol);
} else if (symName.startswith("__exidx")) {
diff --git a/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h b/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h
index 62fa6a767fa..3ca4aac129b 100644
--- a/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h
+++ b/lld/lib/ReaderWriter/ELF/DynamicLibraryWriter.h
@@ -27,7 +27,7 @@ class DynamicLibraryWriter : public OutputELFWriter<ELFT> {
public:
DynamicLibraryWriter(ELFLinkingContext &context, TargetLayout<ELFT> &layout)
: OutputELFWriter<ELFT>(context, layout),
- _runtimeFile(new CRuntimeFile<ELFT>(context)) {}
+ _runtimeFile(new RuntimeFile<ELFT>(context, "C runtime")) {}
protected:
virtual void buildDynamicSymbolTable(const File &file);
@@ -36,7 +36,7 @@ protected:
virtual void finalizeDefaultAtomValues();
protected:
- std::unique_ptr<CRuntimeFile<ELFT> > _runtimeFile;
+ std::unique_ptr<RuntimeFile<ELFT> > _runtimeFile;
};
//===----------------------------------------------------------------------===//
diff --git a/lld/lib/ReaderWriter/ELF/ELFFile.h b/lld/lib/ReaderWriter/ELF/ELFFile.h
index fb7c0213247..bd4fa832261 100644
--- a/lld/lib/ReaderWriter/ELF/ELFFile.h
+++ b/lld/lib/ReaderWriter/ELF/ELFFile.h
@@ -430,14 +430,14 @@ protected:
};
/// \brief All atoms are owned by a File. To add linker specific atoms
-/// the atoms need to be inserted to a file called (CRuntimeFile) which
+/// the atoms need to be inserted to a file called (RuntimeFile) which
/// are basically additional symbols required by libc and other runtime
/// libraries part of executing a program. This class provides support
/// for adding absolute symbols and undefined symbols
-template <class ELFT> class CRuntimeFile : public ELFFile<ELFT> {
+template <class ELFT> class RuntimeFile : public ELFFile<ELFT> {
public:
typedef llvm::object::Elf_Sym_Impl<ELFT> Elf_Sym;
- CRuntimeFile(ELFLinkingContext &context, StringRef name = "C runtime")
+ RuntimeFile(ELFLinkingContext &context, StringRef name)
: ELFFile<ELFT>(name, context) {}
/// \brief add a global absolute atom
@@ -470,7 +470,7 @@ public:
return *newAtom;
}
- // cannot add atoms to C Runtime file
+ // cannot add atoms to Runtime file
virtual void addAtom(const Atom &) {
llvm_unreachable("cannot add atoms to Runtime files");
}
diff --git a/lld/lib/ReaderWriter/ELF/ExecutableWriter.h b/lld/lib/ReaderWriter/ELF/ExecutableWriter.h
index 92a8ea9ff57..477e3920aba 100644
--- a/lld/lib/ReaderWriter/ELF/ExecutableWriter.h
+++ b/lld/lib/ReaderWriter/ELF/ExecutableWriter.h
@@ -27,7 +27,7 @@ class ExecutableWriter : public OutputELFWriter<ELFT> {
public:
ExecutableWriter(ELFLinkingContext &context, TargetLayout<ELFT> &layout)
: OutputELFWriter<ELFT>(context, layout),
- _runtimeFile(new CRuntimeFile<ELFT>(context)) {}
+ _runtimeFile(new RuntimeFile<ELFT>(context, "C runtime")) {}
protected:
virtual void buildDynamicSymbolTable(const File &file);
@@ -41,7 +41,7 @@ protected:
}
unique_bump_ptr<InterpSection<ELFT>> _interpSection;
- std::unique_ptr<CRuntimeFile<ELFT> > _runtimeFile;
+ std::unique_ptr<RuntimeFile<ELFT> > _runtimeFile;
};
//===----------------------------------------------------------------------===//
@@ -80,6 +80,7 @@ void ExecutableWriter<ELFT>::buildDynamicSymbolTable(const File &file) {
/// absolute symbols
template<class ELFT>
void ExecutableWriter<ELFT>::addDefaultAtoms() {
+ OutputELFWriter<ELFT>::addDefaultAtoms();
_runtimeFile->addUndefinedAtom(this->_context.entrySymbolName());
_runtimeFile->addAbsoluteAtom("__bss_start");
_runtimeFile->addAbsoluteAtom("__bss_end");
@@ -124,6 +125,7 @@ template <class ELFT> void ExecutableWriter<ELFT>::createDefaultSections() {
/// Finalize the value of all the absolute symbols that we
/// created
template <class ELFT> void ExecutableWriter<ELFT>::finalizeDefaultAtomValues() {
+ OutputELFWriter<ELFT>::finalizeDefaultAtomValues();
auto bssStartAtomIter = this->_layout.findAbsoluteAtom("__bss_start");
auto bssEndAtomIter = this->_layout.findAbsoluteAtom("__bss_end");
auto underScoreEndAtomIter = this->_layout.findAbsoluteAtom("_end");
diff --git a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableAtoms.h b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableAtoms.h
index 47a0996fcfd..a2505aa460c 100644
--- a/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableAtoms.h
+++ b/lld/lib/ReaderWriter/ELF/Hexagon/HexagonExecutableAtoms.h
@@ -18,10 +18,10 @@ typedef llvm::object::ELFType<llvm::support::little, 2, false> HexagonELFType;
class HexagonLinkingContext;
template <class HexagonELFType> class HexagonRuntimeFile
- : public CRuntimeFile<HexagonELFType> {
+ : public RuntimeFile<HexagonELFType> {
public:
HexagonRuntimeFile(HexagonLinkingContext &context)
- : CRuntimeFile<HexagonELFType>(context, "Hexagon runtime file") {}
+ : RuntimeFile<HexagonELFType>(context, "Hexagon runtime file") {}
};
} // elf
} // lld
diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
index 023c7a8ec8c..49affe6589f 100644
--- a/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
+++ b/lld/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
@@ -87,10 +87,10 @@ private:
/// \brief Mips Runtime file.
template <class ELFType>
-class MipsRuntimeFile final : public CRuntimeFile<ELFType> {
+class MipsRuntimeFile final : public RuntimeFile<ELFType> {
public:
MipsRuntimeFile(MipsLinkingContext &ctx)
- : CRuntimeFile<ELFType>(ctx, "Mips runtime file") {}
+ : RuntimeFile<ELFType>(ctx, "Mips runtime file") {}
};
/// \brief Auxiliary class holds relocation's names table.
diff --git a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h
index b44da49402f..e26bb685c1e 100644
--- a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h
+++ b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h
@@ -33,14 +33,14 @@ template <class ELFT> class TargetLayout;
namespace {
template<class ELFT>
-class SymbolFile : public CRuntimeFile<ELFT> {
+class SymbolFile : public RuntimeFile<ELFT> {
public:
SymbolFile(ELFLinkingContext &context)
- : CRuntimeFile<ELFT>(context, "Dynamic absolute symbols"),
+ : RuntimeFile<ELFT>(context, "Dynamic absolute symbols"),
_atomsAdded(false) {}
Atom *addAbsoluteAtom(StringRef symbolName) override {
- auto *a = CRuntimeFile<ELFT>::addAbsoluteAtom(symbolName);
+ auto *a = RuntimeFile<ELFT>::addAbsoluteAtom(symbolName);
if (a) _atomsAdded = true;
return a;
}
@@ -57,7 +57,7 @@ private:
template<class ELFT>
class DynamicSymbolFile : public SimpleArchiveLibraryFile {
- typedef std::function<void(StringRef, CRuntimeFile<ELFT> &)> Resolver;
+ typedef std::function<void(StringRef, RuntimeFile<ELFT> &)> Resolver;
public:
DynamicSymbolFile(ELFLinkingContext &context, Resolver resolver)
: SimpleArchiveLibraryFile("Dynamically added runtime symbols"),
@@ -99,7 +99,7 @@ public:
typedef Elf_Sym_Impl<ELFT> Elf_Sym;
typedef Elf_Dyn_Impl<ELFT> Elf_Dyn;
- OutputELFWriter(const ELFLinkingContext &context, TargetLayout<ELFT> &layout);
+ OutputELFWriter(ELFLinkingContext &context, TargetLayout<ELFT> &layout);
protected:
// build the sections that need to be created
@@ -141,13 +141,13 @@ protected:
virtual void assignSectionsWithNoSegments();
// Add default atoms that need to be present in the output file
- virtual void addDefaultAtoms() = 0;
+ virtual void addDefaultAtoms();
// Add any runtime files and their atoms to the output
bool createImplicitFiles(std::vector<std::unique_ptr<File>> &) override;
// Finalize the default atom values
- virtual void finalizeDefaultAtomValues() = 0;
+ virtual void finalizeDefaultAtomValues();
// This is called by the write section to apply relocations
uint64_t addressOfAtom(const Atom *atom) override {
@@ -180,11 +180,11 @@ protected:
/// \brief Process undefined symbols that left after resolution step.
virtual void processUndefinedSymbol(StringRef symName,
- CRuntimeFile<ELFT> &file) const {}
+ RuntimeFile<ELFT> &file) const {}
llvm::BumpPtrAllocator _alloc;
- const ELFLinkingContext &_context;
+ ELFLinkingContext &_context;
TargetHandler<ELFT> &_targetHandler;
typedef llvm::DenseMap<const Atom *, uint64_t> AtomToAddress;
@@ -205,6 +205,7 @@ protected:
unique_bump_ptr<HashSection<ELFT>> _hashTable;
llvm::StringSet<> _soNeeded;
/// @}
+ std::unique_ptr<RuntimeFile<ELFT>> _scriptFile;
private:
static StringRef maybeGetSOName(Node *node);
@@ -214,10 +215,11 @@ private:
// OutputELFWriter
//===----------------------------------------------------------------------===//
template <class ELFT>
-OutputELFWriter<ELFT>::OutputELFWriter(const ELFLinkingContext &context,
+OutputELFWriter<ELFT>::OutputELFWriter(ELFLinkingContext &context,
TargetLayout<ELFT> &layout)
: _context(context), _targetHandler(context.getTargetHandler<ELFT>()),
- _layout(layout) {}
+ _layout(layout),
+ _scriptFile(new RuntimeFile<ELFT>(context, "Linker script runtime")) {}
template <class ELFT>
void OutputELFWriter<ELFT>::buildChunks(const File &file) {
@@ -363,20 +365,41 @@ void OutputELFWriter<ELFT>::assignSectionsWithNoSegments() {
_shdrtab->updateSection(section);
}
+template <class ELFT> void OutputELFWriter<ELFT>::addDefaultAtoms() {
+ const llvm::StringSet<> &symbols =
+ _context.linkerScriptSema().getScriptDefinedSymbols();
+ for (auto &sym : symbols)
+ _scriptFile->addAbsoluteAtom(sym.getKey());
+}
+
template <class ELFT>
bool OutputELFWriter<ELFT>::createImplicitFiles(
- std::vector<std::unique_ptr<File>> &) {
+ std::vector<std::unique_ptr<File>> &result) {
// Add the virtual archive to resolve undefined symbols.
// The file will be added later in the linking context.
- auto callback = [this](StringRef sym, CRuntimeFile<ELFT> &file) {
+ auto callback = [this](StringRef sym, RuntimeFile<ELFT> &file) {
processUndefinedSymbol(sym, file);
};
auto &ctx = const_cast<ELFLinkingContext &>(_context);
ctx.setUndefinesResolver(
llvm::make_unique<DynamicSymbolFile<ELFT>>(ctx, std::move(callback)));
+ // Add script defined symbols
+ result.push_back(std::move(_scriptFile));
return true;
}
+template <class ELFT>
+void OutputELFWriter<ELFT>::finalizeDefaultAtomValues() {
+ const llvm::StringSet<> &symbols =
+ _context.linkerScriptSema().getScriptDefinedSymbols();
+ for (auto &sym : symbols) {
+ uint64_t res =
+ _context.linkerScriptSema().getLinkerScriptExprValue(sym.getKey());
+ auto a = _layout.findAbsoluteAtom(sym.getKey());
+ (*a)->_virtualAddr = res;
+ }
+}
+
template <class ELFT> void OutputELFWriter<ELFT>::createDefaultSections() {
_elfHeader.reset(new (_alloc) ELFHeader<ELFT>(_context));
_programHeader.reset(new (_alloc) ProgramHeader<ELFT>(_context));
OpenPOWER on IntegriCloud