aboutsummaryrefslogtreecommitdiff
path: root/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h')
-rw-r--r--lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h83
1 files changed, 59 insertions, 24 deletions
diff --git a/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h b/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
index 57da7bca01e6..6e3e58f8aed6 100644
--- a/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
+++ b/lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.h
@@ -10,57 +10,92 @@
#ifndef LLD_READER_WRITER_ELF_X86_64_X86_64_TARGET_HANDLER_H
#define LLD_READER_WRITER_ELF_X86_64_X86_64_TARGET_HANDLER_H
-#include "DefaultTargetHandler.h"
+#include "ELFReader.h"
#include "TargetLayout.h"
-#include "X86_64ELFFile.h"
-#include "X86_64ELFReader.h"
#include "X86_64LinkingContext.h"
#include "X86_64RelocationHandler.h"
+#include "X86_64SectionChunks.h"
#include "lld/Core/Simple.h"
namespace lld {
namespace elf {
-class X86_64TargetLayout : public TargetLayout<X86_64ELFType> {
+
+
+class X86_64TargetLayout : public TargetLayout<ELF64LE> {
public:
- X86_64TargetLayout(X86_64LinkingContext &context)
- : TargetLayout(context) {}
+ X86_64TargetLayout(X86_64LinkingContext &ctx) : TargetLayout(ctx),
+ _gotSection(new (this->_allocator) X86_64GOTSection(ctx)) {}
+
+ AtomSection<ELF64LE> *
+ createSection(StringRef name, int32_t type,
+ DefinedAtom::ContentPermissions permissions,
+ TargetLayout<ELF64LE>::SectionOrder order) override {
+ if (type == DefinedAtom::typeGOT && name == ".got")
+ return _gotSection;
+ return TargetLayout<ELF64LE>::createSection(name, type, permissions, order);
+ }
void finalizeOutputSectionLayout() override {
- sortOutputSectionByPriority(".init_array", ".init_array");
- sortOutputSectionByPriority(".fini_array", ".fini_array");
+ sortOutputSectionByPriority<ELF64LE>(".init_array");
+ sortOutputSectionByPriority<ELF64LE>(".fini_array");
}
-};
-class X86_64TargetHandler
- : public DefaultTargetHandler<X86_64ELFType> {
-public:
- X86_64TargetHandler(X86_64LinkingContext &context);
+ const X86_64GOTSection &getGOTSection() const { return *_gotSection; }
- X86_64TargetLayout &getTargetLayout() override {
- return *(_x86_64TargetLayout.get());
+private:
+ uint32_t getPriority(StringRef sectionName) const {
+ StringRef priority = sectionName.drop_front().rsplit('.').second;
+ uint32_t prio;
+ if (priority.getAsInteger(10, prio))
+ return std::numeric_limits<uint32_t>::max();
+ return prio;
}
- void registerRelocationNames(Registry &registry) override;
+ template <typename T> void sortOutputSectionByPriority(StringRef prefix) {
+ OutputSection<T> *section = findOutputSection(prefix);
+ if (!section)
+ return;
+ auto sections = section->sections();
+ std::sort(sections.begin(), sections.end(),
+ [&](Chunk<T> *lhs, Chunk<T> *rhs) {
+ Section<T> *lhsSection = dyn_cast<Section<T>>(lhs);
+ Section<T> *rhsSection = dyn_cast<Section<T>>(rhs);
+ if (!lhsSection || !rhsSection)
+ return false;
+ StringRef lhsName = lhsSection->inputSectionName();
+ StringRef rhsName = rhsSection->inputSectionName();
+ if (!lhsName.startswith(prefix) || !rhsName.startswith(prefix))
+ return false;
+ return getPriority(lhsName) < getPriority(rhsName);
+ });
+ }
+
+private:
+ X86_64GOTSection *_gotSection;
+};
+
+class X86_64TargetHandler : public TargetHandler {
+public:
+ X86_64TargetHandler(X86_64LinkingContext &ctx);
- const X86_64TargetRelocationHandler &getRelocationHandler() const override {
- return *(_x86_64RelocationHandler.get());
+ const TargetRelocationHandler &getRelocationHandler() const override {
+ return *_relocationHandler;
}
std::unique_ptr<Reader> getObjReader() override {
- return std::unique_ptr<Reader>(new X86_64ELFObjectReader(_context));
+ return llvm::make_unique<ELFReader<ELFFile<ELF64LE>>>(_ctx);
}
std::unique_ptr<Reader> getDSOReader() override {
- return std::unique_ptr<Reader>(new X86_64ELFDSOReader(_context));
+ return llvm::make_unique<ELFReader<DynamicFile<ELF64LE>>>(_ctx);
}
std::unique_ptr<Writer> getWriter() override;
protected:
- static const Registry::KindStrings kindStrings[];
- X86_64LinkingContext &_context;
- std::unique_ptr<X86_64TargetLayout> _x86_64TargetLayout;
- std::unique_ptr<X86_64TargetRelocationHandler> _x86_64RelocationHandler;
+ X86_64LinkingContext &_ctx;
+ std::unique_ptr<X86_64TargetLayout> _targetLayout;
+ std::unique_ptr<X86_64TargetRelocationHandler> _relocationHandler;
};
} // end namespace elf