ELF: Define ELF{32,64}{LE,BE} types and use them everywhere.
llvm-svn: 234823
This commit is contained in:
parent
47260c23ca
commit
ad87e54f1a
|
@ -46,6 +46,11 @@ std::unique_ptr<ELFLinkingContext> createMipsLinkingContext(llvm::Triple);
|
|||
std::unique_ptr<ELFLinkingContext> createX86LinkingContext(llvm::Triple);
|
||||
std::unique_ptr<ELFLinkingContext> createX86_64LinkingContext(llvm::Triple);
|
||||
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, false> ELF32LE;
|
||||
typedef llvm::object::ELFType<llvm::support::big, 2, false> ELF32BE;
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, true> ELF64LE;
|
||||
typedef llvm::object::ELFType<llvm::support::big, 2, true> ELF64BE;
|
||||
|
||||
class TargetRelocationHandler {
|
||||
public:
|
||||
virtual ~TargetRelocationHandler() {}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, true> AArch64ELFType;
|
||||
|
||||
class AArch64TargetRelocationHandler final : public TargetRelocationHandler {
|
||||
public:
|
||||
|
|
|
@ -17,16 +17,16 @@ using namespace lld;
|
|||
using namespace elf;
|
||||
|
||||
AArch64TargetHandler::AArch64TargetHandler(AArch64LinkingContext &ctx)
|
||||
: _ctx(ctx), _targetLayout(new TargetLayout<AArch64ELFType>(ctx)),
|
||||
: _ctx(ctx), _targetLayout(new TargetLayout<ELF64LE>(ctx)),
|
||||
_relocationHandler(new AArch64TargetRelocationHandler()) {}
|
||||
|
||||
std::unique_ptr<Writer> AArch64TargetHandler::getWriter() {
|
||||
switch (this->_ctx.getOutputELFType()) {
|
||||
case llvm::ELF::ET_EXEC:
|
||||
return llvm::make_unique<AArch64ExecutableWriter<AArch64ELFType>>(
|
||||
_ctx, *_targetLayout);
|
||||
return llvm::make_unique<AArch64ExecutableWriter<ELF64LE>>(_ctx,
|
||||
*_targetLayout);
|
||||
case llvm::ELF::ET_DYN:
|
||||
return llvm::make_unique<AArch64DynamicLibraryWriter<AArch64ELFType>>(
|
||||
return llvm::make_unique<AArch64DynamicLibraryWriter<ELF64LE>>(
|
||||
_ctx, *_targetLayout);
|
||||
case llvm::ELF::ET_REL:
|
||||
llvm_unreachable("TODO: support -r mode");
|
||||
|
|
|
@ -20,9 +20,8 @@ namespace elf {
|
|||
class AArch64LinkingContext;
|
||||
|
||||
class AArch64TargetHandler final : public TargetHandler {
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, true> ELFT;
|
||||
typedef ELFReader<ELFT, AArch64LinkingContext, ELFFile> ObjReader;
|
||||
typedef ELFReader<ELFT, AArch64LinkingContext, DynamicFile> DSOReader;
|
||||
typedef ELFReader<ELF64LE, AArch64LinkingContext, ELFFile> ObjReader;
|
||||
typedef ELFReader<ELF64LE, AArch64LinkingContext, DynamicFile> DSOReader;
|
||||
|
||||
public:
|
||||
AArch64TargetHandler(AArch64LinkingContext &ctx);
|
||||
|
@ -43,7 +42,7 @@ public:
|
|||
|
||||
private:
|
||||
AArch64LinkingContext &_ctx;
|
||||
std::unique_ptr<TargetLayout<ELFT>> _targetLayout;
|
||||
std::unique_ptr<TargetLayout<ELF64LE>> _targetLayout;
|
||||
std::unique_ptr<AArch64TargetRelocationHandler> _relocationHandler;
|
||||
};
|
||||
|
||||
|
|
|
@ -15,13 +15,11 @@
|
|||
namespace lld {
|
||||
namespace elf {
|
||||
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, false> ARMELFType;
|
||||
|
||||
template <class ELFT> class ARMTargetLayout;
|
||||
|
||||
class ARMTargetRelocationHandler final : public TargetRelocationHandler {
|
||||
public:
|
||||
ARMTargetRelocationHandler(ARMTargetLayout<ARMELFType> &layout)
|
||||
ARMTargetRelocationHandler(ARMTargetLayout<ELF32LE> &layout)
|
||||
: _armLayout(layout) {}
|
||||
|
||||
std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
|
||||
|
@ -29,7 +27,7 @@ public:
|
|||
const Reference &) const override;
|
||||
|
||||
private:
|
||||
ARMTargetLayout<ARMELFType> &_armLayout;
|
||||
ARMTargetLayout<ELF32LE> &_armLayout;
|
||||
};
|
||||
|
||||
} // end namespace elf
|
||||
|
|
|
@ -16,14 +16,14 @@ using namespace lld;
|
|||
using namespace elf;
|
||||
|
||||
ARMTargetHandler::ARMTargetHandler(ARMLinkingContext &ctx)
|
||||
: _ctx(ctx), _targetLayout(new ARMTargetLayout<ARMELFType>(ctx)),
|
||||
: _ctx(ctx), _targetLayout(new ARMTargetLayout<ELF32LE>(ctx)),
|
||||
_relocationHandler(new ARMTargetRelocationHandler(*_targetLayout)) {}
|
||||
|
||||
std::unique_ptr<Writer> ARMTargetHandler::getWriter() {
|
||||
switch (this->_ctx.getOutputELFType()) {
|
||||
case llvm::ELF::ET_EXEC:
|
||||
return llvm::make_unique<ARMExecutableWriter<ARMELFType>>(_ctx,
|
||||
*_targetLayout);
|
||||
return llvm::make_unique<ARMExecutableWriter<ELF32LE>>(_ctx,
|
||||
*_targetLayout);
|
||||
default:
|
||||
llvm_unreachable("unsupported output type");
|
||||
}
|
||||
|
|
|
@ -58,9 +58,8 @@ private:
|
|||
};
|
||||
|
||||
class ARMTargetHandler final : public TargetHandler {
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, false> ELFT;
|
||||
typedef ELFReader<ELFT, ARMLinkingContext, ARMELFFile> ObjReader;
|
||||
typedef ELFReader<ELFT, ARMLinkingContext, DynamicFile> DSOReader;
|
||||
typedef ELFReader<ELF32LE, ARMLinkingContext, ARMELFFile> ObjReader;
|
||||
typedef ELFReader<ELF32LE, ARMLinkingContext, DynamicFile> DSOReader;
|
||||
|
||||
public:
|
||||
ARMTargetHandler(ARMLinkingContext &ctx);
|
||||
|
@ -81,7 +80,7 @@ public:
|
|||
|
||||
private:
|
||||
ARMLinkingContext &_ctx;
|
||||
std::unique_ptr<ARMTargetLayout<ELFT>> _targetLayout;
|
||||
std::unique_ptr<ARMTargetLayout<ELF32LE>> _targetLayout;
|
||||
std::unique_ptr<ARMTargetRelocationHandler> _relocationHandler;
|
||||
};
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
#include "llvm/Object/ELF.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
|
||||
using llvm::object::ELFType;
|
||||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
|
||||
|
@ -100,10 +98,10 @@ template <class ELFT> std::error_code DynamicFile<ELFT>::doParse() {
|
|||
return std::error_code();
|
||||
}
|
||||
|
||||
template class DynamicFile<ELFType<llvm::support::little, 2, false>>;
|
||||
template class DynamicFile<ELFType<llvm::support::big, 2, false>>;
|
||||
template class DynamicFile<ELFType<llvm::support::little, 2, true>>;
|
||||
template class DynamicFile<ELFType<llvm::support::big, 2, true>>;
|
||||
template class DynamicFile<ELF32LE>;
|
||||
template class DynamicFile<ELF32BE>;
|
||||
template class DynamicFile<ELF64LE>;
|
||||
template class DynamicFile<ELF64BE>;
|
||||
|
||||
} // end namespace elf
|
||||
} // end namespace lld
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
#include "ELFFile.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
|
||||
using llvm::object::ELFType;
|
||||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
|
||||
|
@ -758,15 +756,15 @@ void RuntimeFile<ELFT>::addUndefinedAtom(StringRef symbolName) {
|
|||
this->addAtom(*atom);
|
||||
}
|
||||
|
||||
template class ELFFile<ELFType<llvm::support::little, 2, false>>;
|
||||
template class ELFFile<ELFType<llvm::support::big, 2, false>>;
|
||||
template class ELFFile<ELFType<llvm::support::little, 2, true>>;
|
||||
template class ELFFile<ELFType<llvm::support::big, 2, true>>;
|
||||
template class ELFFile<ELF32LE>;
|
||||
template class ELFFile<ELF32BE>;
|
||||
template class ELFFile<ELF64LE>;
|
||||
template class ELFFile<ELF64BE>;
|
||||
|
||||
template class RuntimeFile<ELFType<llvm::support::little, 2, false>>;
|
||||
template class RuntimeFile<ELFType<llvm::support::big, 2, false>>;
|
||||
template class RuntimeFile<ELFType<llvm::support::little, 2, true>>;
|
||||
template class RuntimeFile<ELFType<llvm::support::big, 2, true>>;
|
||||
template class RuntimeFile<ELF32LE>;
|
||||
template class RuntimeFile<ELF32BE>;
|
||||
template class RuntimeFile<ELF64LE>;
|
||||
template class RuntimeFile<ELF64BE>;
|
||||
|
||||
} // end namespace elf
|
||||
} // end namespace lld
|
||||
|
|
|
@ -48,7 +48,6 @@ private:
|
|||
std::unique_ptr<File> createELF(std::unique_ptr<MemoryBuffer> mb) const {
|
||||
using namespace llvm::ELF;
|
||||
using namespace llvm::support;
|
||||
using llvm::object::ELFType;
|
||||
|
||||
if (uintptr_t(mb->getBufferStart()) & 1)
|
||||
llvm_unreachable("Invalid alignment for ELF file!");
|
||||
|
@ -57,13 +56,13 @@ private:
|
|||
std::tie(size, endian) = llvm::object::getElfArchType(mb->getBuffer());
|
||||
File *file = nullptr;
|
||||
if (size == ELFCLASS32 && endian == ELFDATA2LSB) {
|
||||
file = new FileT<ELFType<little, 2, false>>(std::move(mb), _ctx);
|
||||
file = new FileT<ELF32LE>(std::move(mb), _ctx);
|
||||
} else if (size == ELFCLASS32 && endian == ELFDATA2MSB) {
|
||||
file = new FileT<ELFType<big, 2, false>>(std::move(mb), _ctx);
|
||||
file = new FileT<ELF32BE>(std::move(mb), _ctx);
|
||||
} else if (size == ELFCLASS64 && endian == ELFDATA2LSB) {
|
||||
file = new FileT<ELFType<little, 2, true>>(std::move(mb), _ctx);
|
||||
file = new FileT<ELF64LE>(std::move(mb), _ctx);
|
||||
} else if (size == ELFCLASS64 && endian == ELFDATA2MSB) {
|
||||
file = new FileT<ELFType<big, 2, true>>(std::move(mb), _ctx);
|
||||
file = new FileT<ELF64BE>(std::move(mb), _ctx);
|
||||
}
|
||||
if (!file)
|
||||
llvm_unreachable("Invalid ELF type!");
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace elf {
|
|||
|
||||
class HexagonTargetLayout;
|
||||
|
||||
class HexagonDynamicLibraryWriter : public DynamicLibraryWriter<ELFT> {
|
||||
class HexagonDynamicLibraryWriter : public DynamicLibraryWriter<ELF32LE> {
|
||||
public:
|
||||
HexagonDynamicLibraryWriter(HexagonLinkingContext &ctx,
|
||||
HexagonTargetLayout &layout);
|
||||
|
@ -30,7 +30,7 @@ protected:
|
|||
void finalizeDefaultAtomValues() override;
|
||||
|
||||
std::error_code setELFHeader() override {
|
||||
DynamicLibraryWriter<ELFT>::setELFHeader();
|
||||
DynamicLibraryWriter<ELF32LE>::setELFHeader();
|
||||
setHexagonELFHeader(*this->_elfHeader);
|
||||
return std::error_code();
|
||||
}
|
||||
|
@ -42,12 +42,12 @@ private:
|
|||
|
||||
HexagonDynamicLibraryWriter::HexagonDynamicLibraryWriter(
|
||||
HexagonLinkingContext &ctx, HexagonTargetLayout &layout)
|
||||
: DynamicLibraryWriter<ELFT>(ctx, layout), _ctx(ctx),
|
||||
: DynamicLibraryWriter<ELF32LE>(ctx, layout), _ctx(ctx),
|
||||
_targetLayout(layout) {}
|
||||
|
||||
void HexagonDynamicLibraryWriter::createImplicitFiles(
|
||||
std::vector<std::unique_ptr<File>> &result) {
|
||||
DynamicLibraryWriter<ELFT>::createImplicitFiles(result);
|
||||
DynamicLibraryWriter<ELF32LE>::createImplicitFiles(result);
|
||||
// Add the default atoms as defined for hexagon
|
||||
auto file = llvm::make_unique<HexagonRuntimeFile>(_ctx);
|
||||
file->addAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
|
||||
|
@ -57,7 +57,7 @@ void HexagonDynamicLibraryWriter::createImplicitFiles(
|
|||
|
||||
void HexagonDynamicLibraryWriter::finalizeDefaultAtomValues() {
|
||||
// Finalize the atom values that are part of the parent.
|
||||
DynamicLibraryWriter<ELFT>::finalizeDefaultAtomValues();
|
||||
DynamicLibraryWriter<ELF32LE>::finalizeDefaultAtomValues();
|
||||
if (_ctx.isDynamic())
|
||||
finalizeHexagonRuntimeAtomValues(_targetLayout);
|
||||
}
|
||||
|
|
|
@ -16,12 +16,10 @@ namespace lld {
|
|||
class ELFLinkingContext;
|
||||
|
||||
namespace elf {
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, false> ELFT;
|
||||
|
||||
class HexagonRuntimeFile : public RuntimeFile<ELFT> {
|
||||
class HexagonRuntimeFile : public RuntimeFile<ELF32LE> {
|
||||
public:
|
||||
HexagonRuntimeFile(ELFLinkingContext &ctx)
|
||||
: RuntimeFile<ELFT>(ctx, "Hexagon runtime file") {}
|
||||
: RuntimeFile<ELF32LE>(ctx, "Hexagon runtime file") {}
|
||||
};
|
||||
} // elf
|
||||
} // lld
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace elf {
|
|||
|
||||
class HexagonTargetLayout;
|
||||
|
||||
class HexagonExecutableWriter : public ExecutableWriter<ELFT> {
|
||||
class HexagonExecutableWriter : public ExecutableWriter<ELF32LE> {
|
||||
public:
|
||||
HexagonExecutableWriter(HexagonLinkingContext &ctx,
|
||||
HexagonTargetLayout &layout);
|
||||
|
@ -31,7 +31,7 @@ protected:
|
|||
void finalizeDefaultAtomValues() override;
|
||||
|
||||
std::error_code setELFHeader() override {
|
||||
ExecutableWriter<ELFT>::setELFHeader();
|
||||
ExecutableWriter<ELF32LE>::setELFHeader();
|
||||
setHexagonELFHeader(*this->_elfHeader);
|
||||
return std::error_code();
|
||||
}
|
||||
|
@ -43,11 +43,12 @@ private:
|
|||
|
||||
HexagonExecutableWriter::HexagonExecutableWriter(HexagonLinkingContext &ctx,
|
||||
HexagonTargetLayout &layout)
|
||||
: ExecutableWriter<ELFT>(ctx, layout), _ctx(ctx), _targetLayout(layout) {}
|
||||
: ExecutableWriter<ELF32LE>(ctx, layout), _ctx(ctx), _targetLayout(layout) {
|
||||
}
|
||||
|
||||
void HexagonExecutableWriter::createImplicitFiles(
|
||||
std::vector<std::unique_ptr<File>> &result) {
|
||||
ExecutableWriter<ELFT>::createImplicitFiles(result);
|
||||
ExecutableWriter<ELF32LE>::createImplicitFiles(result);
|
||||
// Add the default atoms as defined for hexagon
|
||||
auto file = llvm::make_unique<HexagonRuntimeFile>(_ctx);
|
||||
file->addAbsoluteAtom("_SDA_BASE_");
|
||||
|
@ -60,7 +61,7 @@ void HexagonExecutableWriter::createImplicitFiles(
|
|||
|
||||
void HexagonExecutableWriter::finalizeDefaultAtomValues() {
|
||||
// Finalize the atom values that are part of the parent.
|
||||
ExecutableWriter<ELFT>::finalizeDefaultAtomValues();
|
||||
ExecutableWriter<ELF32LE>::finalizeDefaultAtomValues();
|
||||
AtomLayout *sdabaseAtom = _targetLayout.findAbsoluteAtom("_SDA_BASE_");
|
||||
sdabaseAtom->_virtualAddr = _targetLayout.getSDataSection()->virtualAddr();
|
||||
if (_ctx.isDynamic())
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
namespace lld {
|
||||
namespace elf {
|
||||
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, false> HexagonELFType;
|
||||
|
||||
class HexagonLinkingContext final : public ELFLinkingContext {
|
||||
public:
|
||||
static const int machine = llvm::ELF::EM_HEXAGON;
|
||||
|
|
|
@ -16,8 +16,6 @@ namespace elf {
|
|||
class HexagonTargetHandler;
|
||||
class HexagonTargetLayout;
|
||||
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, false> HexagonELFType;
|
||||
|
||||
class HexagonTargetRelocationHandler final : public TargetRelocationHandler {
|
||||
public:
|
||||
HexagonTargetRelocationHandler(HexagonTargetLayout &layout)
|
||||
|
|
|
@ -20,8 +20,6 @@ namespace lld {
|
|||
namespace elf {
|
||||
class HexagonLinkingContext;
|
||||
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, false> ELFT;
|
||||
|
||||
/// \brief Handle Hexagon SData section
|
||||
template <class ELFT> class SDataSection : public AtomSection<ELFT> {
|
||||
public:
|
||||
|
@ -37,27 +35,27 @@ public:
|
|||
};
|
||||
|
||||
/// \brief TargetLayout for Hexagon
|
||||
class HexagonTargetLayout final : public TargetLayout<ELFT> {
|
||||
class HexagonTargetLayout final : public TargetLayout<ELF32LE> {
|
||||
public:
|
||||
enum HexagonSectionOrder {
|
||||
ORDER_SDATA = 205
|
||||
};
|
||||
|
||||
HexagonTargetLayout(HexagonLinkingContext &hti)
|
||||
: TargetLayout<ELFT>(hti), _sdataSection() {
|
||||
_sdataSection = new (_alloc) SDataSection<ELFT>(hti);
|
||||
: TargetLayout<ELF32LE>(hti), _sdataSection() {
|
||||
_sdataSection = new (_alloc) SDataSection<ELF32LE>(hti);
|
||||
}
|
||||
|
||||
/// \brief Return the section order for a input section
|
||||
TargetLayout<ELFT>::SectionOrder
|
||||
TargetLayout<ELF32LE>::SectionOrder
|
||||
getSectionOrder(StringRef name, int32_t contentType,
|
||||
int32_t contentPermissions) override {
|
||||
if ((contentType == DefinedAtom::typeDataFast) ||
|
||||
(contentType == DefinedAtom::typeZeroFillFast))
|
||||
return ORDER_SDATA;
|
||||
|
||||
return TargetLayout<ELFT>::getSectionOrder(name, contentType,
|
||||
contentPermissions);
|
||||
return TargetLayout<ELF32LE>::getSectionOrder(name, contentType,
|
||||
contentPermissions);
|
||||
}
|
||||
|
||||
/// \brief Return the appropriate input section name.
|
||||
|
@ -69,31 +67,31 @@ public:
|
|||
default:
|
||||
break;
|
||||
}
|
||||
return TargetLayout<ELFT>::getInputSectionName(da);
|
||||
return TargetLayout<ELF32LE>::getInputSectionName(da);
|
||||
}
|
||||
|
||||
/// \brief Gets or creates a section.
|
||||
AtomSection<ELFT> *
|
||||
AtomSection<ELF32LE> *
|
||||
createSection(StringRef name, int32_t contentType,
|
||||
DefinedAtom::ContentPermissions contentPermissions,
|
||||
TargetLayout<ELFT>::SectionOrder sectionOrder) override {
|
||||
TargetLayout<ELF32LE>::SectionOrder sectionOrder) override {
|
||||
if ((contentType == DefinedAtom::typeDataFast) ||
|
||||
(contentType == DefinedAtom::typeZeroFillFast))
|
||||
return _sdataSection;
|
||||
return TargetLayout<ELFT>::createSection(name, contentType,
|
||||
contentPermissions, sectionOrder);
|
||||
return TargetLayout<ELF32LE>::createSection(
|
||||
name, contentType, contentPermissions, sectionOrder);
|
||||
}
|
||||
|
||||
/// \brief get the segment type for the section thats defined by the target
|
||||
TargetLayout<ELFT>::SegmentType
|
||||
getSegmentType(Section<ELFT> *section) const override {
|
||||
TargetLayout<ELF32LE>::SegmentType
|
||||
getSegmentType(Section<ELF32LE> *section) const override {
|
||||
if (section->order() == ORDER_SDATA)
|
||||
return PT_LOAD;
|
||||
|
||||
return TargetLayout<ELFT>::getSegmentType(section);
|
||||
return TargetLayout<ELF32LE>::getSegmentType(section);
|
||||
}
|
||||
|
||||
Section<ELFT> *getSDataSection() const { return _sdataSection; }
|
||||
Section<ELF32LE> *getSDataSection() const { return _sdataSection; }
|
||||
|
||||
uint64_t getGOTSymAddr() {
|
||||
std::call_once(_gotOnce, [this]() {
|
||||
|
@ -105,16 +103,15 @@ public:
|
|||
|
||||
private:
|
||||
llvm::BumpPtrAllocator _alloc;
|
||||
SDataSection<ELFT> *_sdataSection = nullptr;
|
||||
SDataSection<ELF32LE> *_sdataSection = nullptr;
|
||||
uint64_t _gotAddr = 0;
|
||||
std::once_flag _gotOnce;
|
||||
};
|
||||
|
||||
/// \brief TargetHandler for Hexagon
|
||||
class HexagonTargetHandler final : public TargetHandler {
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, false> ELFT;
|
||||
typedef ELFReader<ELFT, HexagonLinkingContext, HexagonELFFile> ObjReader;
|
||||
typedef ELFReader<ELFT, HexagonLinkingContext, DynamicFile> ELFDSOReader;
|
||||
typedef ELFReader<ELF32LE, HexagonLinkingContext, HexagonELFFile> ObjReader;
|
||||
typedef ELFReader<ELF32LE, HexagonLinkingContext, DynamicFile> ELFDSOReader;
|
||||
|
||||
public:
|
||||
HexagonTargetHandler(HexagonLinkingContext &targetInfo);
|
||||
|
@ -194,13 +191,13 @@ const lld::AtomLayout *SDataSection<ELFT>::appendAtom(const Atom *atom) {
|
|||
|
||||
inline void finalizeHexagonRuntimeAtomValues(HexagonTargetLayout &layout) {
|
||||
AtomLayout *gotAtom = layout.findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
|
||||
OutputSection<ELFT> *gotpltSection = layout.findOutputSection(".got.plt");
|
||||
OutputSection<ELF32LE> *gotpltSection = layout.findOutputSection(".got.plt");
|
||||
if (gotpltSection)
|
||||
gotAtom->_virtualAddr = gotpltSection->virtualAddr();
|
||||
else
|
||||
gotAtom->_virtualAddr = 0;
|
||||
AtomLayout *dynamicAtom = layout.findAbsoluteAtom("_DYNAMIC");
|
||||
OutputSection<ELFT> *dynamicSection = layout.findOutputSection(".dynamic");
|
||||
OutputSection<ELF32LE> *dynamicSection = layout.findOutputSection(".dynamic");
|
||||
if (dynamicSection)
|
||||
dynamicAtom->_virtualAddr = dynamicSection->virtualAddr();
|
||||
else
|
||||
|
|
|
@ -37,11 +37,6 @@ enum {
|
|||
LLD_R_MIPS_64_HI16 = 1031,
|
||||
};
|
||||
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, false> Mips32ELType;
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, true> Mips64ELType;
|
||||
typedef llvm::object::ELFType<llvm::support::big, 2, false> Mips32BEType;
|
||||
typedef llvm::object::ELFType<llvm::support::big, 2, true> Mips64BEType;
|
||||
|
||||
class MipsLinkingContext final : public ELFLinkingContext {
|
||||
public:
|
||||
static const int machine = llvm::ELF::EM_MIPS;
|
||||
|
|
|
@ -617,16 +617,16 @@ namespace elf {
|
|||
|
||||
template <>
|
||||
std::unique_ptr<TargetRelocationHandler>
|
||||
createMipsRelocationHandler<Mips32ELType>(MipsLinkingContext &ctx,
|
||||
MipsTargetLayout<Mips32ELType> &layout) {
|
||||
return llvm::make_unique<RelocationHandler<Mips32ELType>>(ctx, layout);
|
||||
createMipsRelocationHandler<ELF32LE>(MipsLinkingContext &ctx,
|
||||
MipsTargetLayout<ELF32LE> &layout) {
|
||||
return llvm::make_unique<RelocationHandler<ELF32LE>>(ctx, layout);
|
||||
}
|
||||
|
||||
template <>
|
||||
std::unique_ptr<TargetRelocationHandler>
|
||||
createMipsRelocationHandler<Mips64ELType>(MipsLinkingContext &ctx,
|
||||
MipsTargetLayout<Mips64ELType> &layout) {
|
||||
return llvm::make_unique<RelocationHandler<Mips64ELType>>(ctx, layout);
|
||||
createMipsRelocationHandler<ELF64LE>(MipsLinkingContext &ctx,
|
||||
MipsTargetLayout<ELF64LE> &layout) {
|
||||
return llvm::make_unique<RelocationHandler<ELF64LE>>(ctx, layout);
|
||||
}
|
||||
|
||||
Reference::Addend readMipsRelocAddend(Reference::KindValue kind,
|
||||
|
|
|
@ -119,10 +119,10 @@ public:
|
|||
ArrayRef<uint8_t> rawContent() const override;
|
||||
};
|
||||
|
||||
template <> ArrayRef<uint8_t> GOT0Atom<Mips32ELType>::rawContent() const {
|
||||
template <> ArrayRef<uint8_t> GOT0Atom<ELF32LE>::rawContent() const {
|
||||
return llvm::makeArrayRef(mipsGot0AtomContent).slice(4);
|
||||
}
|
||||
template <> ArrayRef<uint8_t> GOT0Atom<Mips64ELType>::rawContent() const {
|
||||
template <> ArrayRef<uint8_t> GOT0Atom<ELF64LE>::rawContent() const {
|
||||
return llvm::makeArrayRef(mipsGot0AtomContent);
|
||||
}
|
||||
|
||||
|
@ -135,11 +135,11 @@ public:
|
|||
};
|
||||
|
||||
template <>
|
||||
ArrayRef<uint8_t> GOTModulePointerAtom<Mips32ELType>::rawContent() const {
|
||||
ArrayRef<uint8_t> GOTModulePointerAtom<ELF32LE>::rawContent() const {
|
||||
return llvm::makeArrayRef(mipsGotModulePointerAtomContent).slice(4);
|
||||
}
|
||||
template <>
|
||||
ArrayRef<uint8_t> GOTModulePointerAtom<Mips64ELType>::rawContent() const {
|
||||
ArrayRef<uint8_t> GOTModulePointerAtom<ELF64LE>::rawContent() const {
|
||||
return llvm::makeArrayRef(mipsGotModulePointerAtomContent);
|
||||
}
|
||||
|
||||
|
@ -151,11 +151,11 @@ public:
|
|||
ArrayRef<uint8_t> rawContent() const override;
|
||||
};
|
||||
|
||||
template <> ArrayRef<uint8_t> GOTTLSGdAtom<Mips32ELType>::rawContent() const {
|
||||
template <> ArrayRef<uint8_t> GOTTLSGdAtom<ELF32LE>::rawContent() const {
|
||||
return llvm::makeArrayRef(mipsGotTlsGdAtomContent).slice(8);
|
||||
}
|
||||
|
||||
template <> ArrayRef<uint8_t> GOTTLSGdAtom<Mips64ELType>::rawContent() const {
|
||||
template <> ArrayRef<uint8_t> GOTTLSGdAtom<ELF64LE>::rawContent() const {
|
||||
return llvm::makeArrayRef(mipsGotTlsGdAtomContent);
|
||||
}
|
||||
|
||||
|
@ -1077,9 +1077,9 @@ RelocationPass<ELFT>::getObjectEntry(const SharedLibraryAtom *a) {
|
|||
static std::unique_ptr<Pass> createPass(MipsLinkingContext &ctx) {
|
||||
switch (ctx.getTriple().getArch()) {
|
||||
case llvm::Triple::mipsel:
|
||||
return llvm::make_unique<RelocationPass<Mips32ELType>>(ctx);
|
||||
return llvm::make_unique<RelocationPass<ELF32LE>>(ctx);
|
||||
case llvm::Triple::mips64el:
|
||||
return llvm::make_unique<RelocationPass<Mips64ELType>>(ctx);
|
||||
return llvm::make_unique<RelocationPass<ELF64LE>>(ctx);
|
||||
default:
|
||||
llvm_unreachable("Unhandled arch");
|
||||
}
|
||||
|
|
|
@ -14,5 +14,5 @@ using namespace lld::elf;
|
|||
|
||||
std::unique_ptr<TargetHandler>
|
||||
lld::elf::createMips32ELTargetHandler(MipsLinkingContext &ctx) {
|
||||
return llvm::make_unique<MipsTargetHandler<Mips32ELType>>(ctx);
|
||||
return llvm::make_unique<MipsTargetHandler<ELF32LE>>(ctx);
|
||||
}
|
||||
|
|
|
@ -14,5 +14,5 @@ using namespace lld::elf;
|
|||
|
||||
std::unique_ptr<TargetHandler>
|
||||
lld::elf::createMips64ELTargetHandler(MipsLinkingContext &ctx) {
|
||||
return llvm::make_unique<MipsTargetHandler<Mips64ELType>>(ctx);
|
||||
return llvm::make_unique<MipsTargetHandler<ELF64LE>>(ctx);
|
||||
}
|
||||
|
|
|
@ -15,25 +15,23 @@
|
|||
namespace lld {
|
||||
namespace elf {
|
||||
|
||||
template <class ELFT>
|
||||
class X86DynamicLibraryWriter : public DynamicLibraryWriter<ELFT> {
|
||||
class X86DynamicLibraryWriter : public DynamicLibraryWriter<ELF32LE> {
|
||||
public:
|
||||
X86DynamicLibraryWriter(X86LinkingContext &ctx, TargetLayout<ELFT> &layout);
|
||||
X86DynamicLibraryWriter(X86LinkingContext &ctx,
|
||||
TargetLayout<ELF32LE> &layout);
|
||||
|
||||
protected:
|
||||
// Add any runtime files and their atoms to the output
|
||||
void createImplicitFiles(std::vector<std::unique_ptr<File>> &) override;
|
||||
};
|
||||
|
||||
template <class ELFT>
|
||||
X86DynamicLibraryWriter<ELFT>::X86DynamicLibraryWriter(
|
||||
X86LinkingContext &ctx, TargetLayout<ELFT> &layout)
|
||||
: DynamicLibraryWriter<ELFT>(ctx, layout) {}
|
||||
X86DynamicLibraryWriter::X86DynamicLibraryWriter(X86LinkingContext &ctx,
|
||||
TargetLayout<ELF32LE> &layout)
|
||||
: DynamicLibraryWriter<ELF32LE>(ctx, layout) {}
|
||||
|
||||
template <class ELFT>
|
||||
void X86DynamicLibraryWriter<ELFT>::createImplicitFiles(
|
||||
void X86DynamicLibraryWriter::createImplicitFiles(
|
||||
std::vector<std::unique_ptr<File>> &result) {
|
||||
DynamicLibraryWriter<ELFT>::createImplicitFiles(result);
|
||||
DynamicLibraryWriter<ELF32LE>::createImplicitFiles(result);
|
||||
auto gotFile = llvm::make_unique<SimpleFile>("GOTFile");
|
||||
gotFile->addAtom(*new (gotFile->allocator()) GlobalOffsetTableAtom(*gotFile));
|
||||
gotFile->addAtom(*new (gotFile->allocator()) DynamicAtom(*gotFile));
|
||||
|
|
|
@ -15,25 +15,22 @@
|
|||
namespace lld {
|
||||
namespace elf {
|
||||
|
||||
template <class ELFT>
|
||||
class X86ExecutableWriter : public ExecutableWriter<ELFT> {
|
||||
class X86ExecutableWriter : public ExecutableWriter<ELF32LE> {
|
||||
public:
|
||||
X86ExecutableWriter(X86LinkingContext &ctx, TargetLayout<ELFT> &layout);
|
||||
X86ExecutableWriter(X86LinkingContext &ctx, TargetLayout<ELF32LE> &layout);
|
||||
|
||||
protected:
|
||||
// Add any runtime files and their atoms to the output
|
||||
void createImplicitFiles(std::vector<std::unique_ptr<File>> &) override;
|
||||
};
|
||||
|
||||
template <class ELFT>
|
||||
X86ExecutableWriter<ELFT>::X86ExecutableWriter(X86LinkingContext &ctx,
|
||||
TargetLayout<ELFT> &layout)
|
||||
: ExecutableWriter<ELFT>(ctx, layout) {}
|
||||
X86ExecutableWriter::X86ExecutableWriter(X86LinkingContext &ctx,
|
||||
TargetLayout<ELF32LE> &layout)
|
||||
: ExecutableWriter<ELF32LE>(ctx, layout) {}
|
||||
|
||||
template <class ELFT>
|
||||
void X86ExecutableWriter<ELFT>::createImplicitFiles(
|
||||
void X86ExecutableWriter::createImplicitFiles(
|
||||
std::vector<std::unique_ptr<File>> &result) {
|
||||
ExecutableWriter<ELFT>::createImplicitFiles(result);
|
||||
ExecutableWriter<ELF32LE>::createImplicitFiles(result);
|
||||
}
|
||||
|
||||
} // namespace elf
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, false> X86ELFType;
|
||||
|
||||
class X86TargetRelocationHandler final : public TargetRelocationHandler {
|
||||
public:
|
||||
|
|
|
@ -21,11 +21,9 @@ using namespace llvm::ELF;
|
|||
std::unique_ptr<Writer> X86TargetHandler::getWriter() {
|
||||
switch (_ctx.getOutputELFType()) {
|
||||
case llvm::ELF::ET_EXEC:
|
||||
return llvm::make_unique<X86ExecutableWriter<X86ELFType>>(_ctx,
|
||||
*_targetLayout);
|
||||
return llvm::make_unique<X86ExecutableWriter>(_ctx, *_targetLayout);
|
||||
case llvm::ELF::ET_DYN:
|
||||
return llvm::make_unique<X86DynamicLibraryWriter<X86ELFType>>(
|
||||
_ctx, *_targetLayout);
|
||||
return llvm::make_unique<X86DynamicLibraryWriter>(_ctx, *_targetLayout);
|
||||
case llvm::ELF::ET_REL:
|
||||
llvm_unreachable("TODO: support -r mode");
|
||||
default:
|
||||
|
@ -34,5 +32,5 @@ std::unique_ptr<Writer> X86TargetHandler::getWriter() {
|
|||
}
|
||||
|
||||
X86TargetHandler::X86TargetHandler(X86LinkingContext &ctx)
|
||||
: _ctx(ctx), _targetLayout(new TargetLayout<X86ELFType>(ctx)),
|
||||
: _ctx(ctx), _targetLayout(new TargetLayout<ELF32LE>(ctx)),
|
||||
_relocationHandler(new X86TargetRelocationHandler()) {}
|
||||
|
|
|
@ -20,9 +20,8 @@ namespace elf {
|
|||
class X86LinkingContext;
|
||||
|
||||
class X86TargetHandler final : public TargetHandler {
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, false> ELFT;
|
||||
typedef ELFReader<ELFT, X86LinkingContext, ELFFile> ObjReader;
|
||||
typedef ELFReader<ELFT, X86LinkingContext, DynamicFile> DSOReader;
|
||||
typedef ELFReader<ELF32LE, X86LinkingContext, ELFFile> ObjReader;
|
||||
typedef ELFReader<ELF32LE, X86LinkingContext, DynamicFile> DSOReader;
|
||||
|
||||
public:
|
||||
X86TargetHandler(X86LinkingContext &ctx);
|
||||
|
@ -43,7 +42,7 @@ public:
|
|||
|
||||
protected:
|
||||
X86LinkingContext &_ctx;
|
||||
std::unique_ptr<TargetLayout<ELFT>> _targetLayout;
|
||||
std::unique_ptr<TargetLayout<ELF32LE>> _targetLayout;
|
||||
std::unique_ptr<X86TargetRelocationHandler> _relocationHandler;
|
||||
};
|
||||
} // end namespace elf
|
||||
|
|
|
@ -10,14 +10,13 @@
|
|||
#define X86_64_DYNAMIC_LIBRARY_WRITER_H
|
||||
|
||||
#include "DynamicLibraryWriter.h"
|
||||
#include "X86_64ElfType.h"
|
||||
#include "X86_64LinkingContext.h"
|
||||
#include "X86_64TargetHandler.h"
|
||||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
|
||||
class X86_64DynamicLibraryWriter : public DynamicLibraryWriter<X86_64ELFType> {
|
||||
class X86_64DynamicLibraryWriter : public DynamicLibraryWriter<ELF64LE> {
|
||||
public:
|
||||
X86_64DynamicLibraryWriter(X86_64LinkingContext &ctx,
|
||||
X86_64TargetLayout &layout);
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
//===- lib/ReaderWriter/ELF/X86_64/X86_64ElfType.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_X86_64_X86_64_ELF_TYPE_H
|
||||
#define LLD_READER_WRITER_ELF_X86_64_X86_64_ELF_TYPE_H
|
||||
|
||||
#include "llvm/Object/ELF.h"
|
||||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, true> X86_64ELFType;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -10,13 +10,12 @@
|
|||
#define X86_64_EXECUTABLE_WRITER_H
|
||||
|
||||
#include "ExecutableWriter.h"
|
||||
#include "X86_64ElfType.h"
|
||||
#include "X86_64LinkingContext.h"
|
||||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
|
||||
class X86_64ExecutableWriter : public ExecutableWriter<X86_64ELFType> {
|
||||
class X86_64ExecutableWriter : public ExecutableWriter<ELF64LE> {
|
||||
public:
|
||||
X86_64ExecutableWriter(X86_64LinkingContext &ctx, X86_64TargetLayout &layout)
|
||||
: ExecutableWriter(ctx, layout) {}
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
typedef llvm::object::ELFType<llvm::support::little, 2, true> X86_64ELFType;
|
||||
|
||||
class X86_64TargetLayout;
|
||||
|
||||
class X86_64TargetRelocationHandler final : public TargetRelocationHandler {
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
namespace lld {
|
||||
namespace elf {
|
||||
|
||||
class X86_64TargetLayout : public TargetLayout<X86_64ELFType> {
|
||||
class X86_64TargetLayout : public TargetLayout<ELF64LE> {
|
||||
public:
|
||||
X86_64TargetLayout(X86_64LinkingContext &ctx) : TargetLayout(ctx) {}
|
||||
|
||||
void finalizeOutputSectionLayout() override {
|
||||
sortOutputSectionByPriority<X86_64ELFType>(".init_array");
|
||||
sortOutputSectionByPriority<X86_64ELFType>(".fini_array");
|
||||
sortOutputSectionByPriority<ELF64LE>(".init_array");
|
||||
sortOutputSectionByPriority<ELF64LE>(".fini_array");
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue