More prefixing of error_code.

llvm-svn: 210831
This commit is contained in:
Rafael Espindola
2014-06-12 21:35:33 +00:00
parent d31b63e6ae
commit f743031b8b
21 changed files with 84 additions and 82 deletions

View File

@@ -31,10 +31,10 @@ protected:
virtual void finalizeDefaultAtomValues(); virtual void finalizeDefaultAtomValues();
virtual error_code setELFHeader() { virtual std::error_code setELFHeader() {
DynamicLibraryWriter<ELFT>::setELFHeader(); DynamicLibraryWriter<ELFT>::setELFHeader();
HexagonELFWriter<ELFT>::setELFHeader(*this->_elfHeader); HexagonELFWriter<ELFT>::setELFHeader(*this->_elfHeader);
return error_code(); return std::error_code();
} }
private: private:

View File

@@ -118,12 +118,12 @@ public:
: ELFFile<ELFT>(name, atomizeStrings) {} : ELFFile<ELFT>(name, atomizeStrings) {}
HexagonELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings, HexagonELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings,
error_code &ec) std::error_code &ec)
: ELFFile<ELFT>(std::move(mb), atomizeStrings, ec) {} : ELFFile<ELFT>(std::move(mb), atomizeStrings, ec) {}
static ErrorOr<std::unique_ptr<HexagonELFFile>> static ErrorOr<std::unique_ptr<HexagonELFFile>>
create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) { create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) {
error_code ec; std::error_code ec;
std::unique_ptr<HexagonELFFile<ELFT>> file( std::unique_ptr<HexagonELFFile<ELFT>> file(
new HexagonELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings)); new HexagonELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings));

View File

@@ -43,7 +43,7 @@ public:
HexagonELFObjectReader(bool atomizeStrings) HexagonELFObjectReader(bool atomizeStrings)
: ELFObjectReader(atomizeStrings) {} : ELFObjectReader(atomizeStrings) {}
error_code std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const override { std::vector<std::unique_ptr<File>> &result) const override {
std::size_t maxAlignment = std::size_t maxAlignment =
@@ -51,10 +51,10 @@ public:
auto f = createELF<HexagonELFFileCreateELFTraits>( auto f = createELF<HexagonELFFileCreateELFTraits>(
llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb), llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb),
_atomizeStrings); _atomizeStrings);
if (error_code ec = f.getError()) if (std::error_code ec = f.getError())
return ec; return ec;
result.push_back(std::move(*f)); result.push_back(std::move(*f));
return error_code(); return std::error_code();
} }
}; };
@@ -62,7 +62,7 @@ class HexagonELFDSOReader : public ELFDSOReader {
public: public:
HexagonELFDSOReader(bool useUndefines) : ELFDSOReader(useUndefines) {} HexagonELFDSOReader(bool useUndefines) : ELFDSOReader(useUndefines) {}
error_code std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const override { std::vector<std::unique_ptr<File>> &result) const override {
std::size_t maxAlignment = std::size_t maxAlignment =
@@ -70,10 +70,10 @@ public:
auto f = createELF<HexagonDynamicFileCreateELFTraits>( auto f = createELF<HexagonDynamicFileCreateELFTraits>(
llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb), llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb),
_useUndefines); _useUndefines);
if (error_code ec = f.getError()) if (std::error_code ec = f.getError())
return ec; return ec;
result.push_back(std::move(*f)); result.push_back(std::move(*f));
return error_code(); return std::error_code();
} }
}; };

View File

@@ -32,10 +32,10 @@ protected:
virtual void finalizeDefaultAtomValues(); virtual void finalizeDefaultAtomValues();
virtual error_code setELFHeader() { virtual std::error_code setELFHeader() {
ExecutableWriter<ELFT>::setELFHeader(); ExecutableWriter<ELFT>::setELFHeader();
HexagonELFWriter<ELFT>::setELFHeader(*this->_elfHeader); HexagonELFWriter<ELFT>::setELFHeader(*this->_elfHeader);
return error_code(); return std::error_code();
} }
private: private:

View File

@@ -211,7 +211,7 @@ static int relocHexGOTREL_32(uint8_t *location, uint64_t P, uint64_t S,
return 0; return 0;
} }
error_code HexagonTargetRelocationHandler::applyRelocation( std::error_code HexagonTargetRelocationHandler::applyRelocation(
ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom, ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom,
const Reference &ref) const { const Reference &ref) const {
uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset; uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset;
@@ -220,7 +220,7 @@ error_code HexagonTargetRelocationHandler::applyRelocation(
uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom(); uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom();
if (ref.kindNamespace() != Reference::KindNamespace::ELF) if (ref.kindNamespace() != Reference::KindNamespace::ELF)
return error_code(); return std::error_code();
assert(ref.kindArch() == Reference::KindArch::Hexagon); assert(ref.kindArch() == Reference::KindArch::Hexagon);
switch (ref.kindValue()) { switch (ref.kindValue()) {
case R_HEX_B22_PCREL: case R_HEX_B22_PCREL:
@@ -353,7 +353,7 @@ error_code HexagonTargetRelocationHandler::applyRelocation(
} }
} }
return error_code(); return std::error_code();
} }

View File

@@ -24,9 +24,9 @@ public:
HexagonTargetRelocationHandler(HexagonTargetLayout<HexagonELFType> &layout) HexagonTargetRelocationHandler(HexagonTargetLayout<HexagonELFType> &layout)
: _hexagonTargetLayout(layout) {} : _hexagonTargetLayout(layout) {}
error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
const lld::AtomLayout &, const lld::AtomLayout &,
const Reference &) const override; const Reference &) const override;
private: private:
HexagonTargetLayout<HexagonELFType> &_hexagonTargetLayout; HexagonTargetLayout<HexagonELFType> &_hexagonTargetLayout;

View File

@@ -301,19 +301,19 @@ public:
return ga; return ga;
} }
error_code handleGOTREL(const Reference &ref) { std::error_code handleGOTREL(const Reference &ref) {
// Turn this so that the target is set to the GOT entry // Turn this so that the target is set to the GOT entry
const_cast<Reference &>(ref).setTarget(getGOTEntry(ref.target())); const_cast<Reference &>(ref).setTarget(getGOTEntry(ref.target()));
return error_code(); return std::error_code();
} }
error_code handlePLT32(const Reference &ref) { std::error_code handlePLT32(const Reference &ref) {
// Turn this into a PC32 to the PLT entry. // Turn this into a PC32 to the PLT entry.
assert(ref.kindNamespace() == Reference::KindNamespace::ELF); assert(ref.kindNamespace() == Reference::KindNamespace::ELF);
assert(ref.kindArch() == Reference::KindArch::Hexagon); assert(ref.kindArch() == Reference::KindArch::Hexagon);
const_cast<Reference &>(ref).setKindValue(R_HEX_B22_PCREL); const_cast<Reference &>(ref).setKindValue(R_HEX_B22_PCREL);
const_cast<Reference &>(ref).setTarget(getPLTEntry(ref.target())); const_cast<Reference &>(ref).setTarget(getPLTEntry(ref.target()));
return error_code(); return std::error_code();
} }
}; };

View File

@@ -31,10 +31,10 @@ protected:
void finalizeDefaultAtomValues() override; void finalizeDefaultAtomValues() override;
error_code setELFHeader() override { std::error_code setELFHeader() override {
DynamicLibraryWriter<ELFT>::setELFHeader(); DynamicLibraryWriter<ELFT>::setELFHeader();
_writeHelper.setELFHeader(*this->_elfHeader); _writeHelper.setELFHeader(*this->_elfHeader);
return error_code(); return std::error_code();
} }
LLD_UNIQUE_BUMP_PTR(DynamicTable<ELFT>) createDynamicTable(); LLD_UNIQUE_BUMP_PTR(DynamicTable<ELFT>) createDynamicTable();

View File

@@ -29,7 +29,7 @@ class MipsELFObjectReader : public ELFObjectReader {
public: public:
MipsELFObjectReader(bool atomizeStrings) : ELFObjectReader(atomizeStrings) {} MipsELFObjectReader(bool atomizeStrings) : ELFObjectReader(atomizeStrings) {}
error_code std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &, parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const override { std::vector<std::unique_ptr<File>> &result) const override {
std::size_t maxAlignment = std::size_t maxAlignment =
@@ -37,10 +37,10 @@ public:
auto f = createELF<MipsELFFileCreateTraits>( auto f = createELF<MipsELFFileCreateTraits>(
llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb), llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb),
_atomizeStrings); _atomizeStrings);
if (error_code ec = f.getError()) if (std::error_code ec = f.getError())
return ec; return ec;
result.push_back(std::move(*f)); result.push_back(std::move(*f));
return error_code(); return std::error_code();
} }
}; };

View File

@@ -33,10 +33,10 @@ protected:
void finalizeDefaultAtomValues() override; void finalizeDefaultAtomValues() override;
error_code setELFHeader() override { std::error_code setELFHeader() override {
ExecutableWriter<ELFT>::setELFHeader(); ExecutableWriter<ELFT>::setELFHeader();
_writeHelper.setELFHeader(*this->_elfHeader); _writeHelper.setELFHeader(*this->_elfHeader);
return error_code(); return std::error_code();
} }
LLD_UNIQUE_BUMP_PTR(DynamicTable<ELFT>) createDynamicTable(); LLD_UNIQUE_BUMP_PTR(DynamicTable<ELFT>) createDynamicTable();

View File

@@ -119,11 +119,11 @@ static void reloc32hi16(uint8_t *location, uint64_t S, int64_t A) {
applyReloc(location, (S + A + 0x8000) & 0xffff0000, 0xffffffff); applyReloc(location, (S + A + 0x8000) & 0xffff0000, 0xffffffff);
} }
error_code MipsTargetRelocationHandler::applyRelocation( std::error_code MipsTargetRelocationHandler::applyRelocation(
ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom, ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom,
const Reference &ref) const { const Reference &ref) const {
if (ref.kindNamespace() != lld::Reference::KindNamespace::ELF) if (ref.kindNamespace() != lld::Reference::KindNamespace::ELF)
return error_code(); return std::error_code();
assert(ref.kindArch() == Reference::KindArch::Mips); assert(ref.kindArch() == Reference::KindArch::Mips);
AtomLayout *gpAtom = _mipsTargetLayout.getGP(); AtomLayout *gpAtom = _mipsTargetLayout.getGP();
@@ -216,5 +216,5 @@ error_code MipsTargetRelocationHandler::applyRelocation(
} }
} }
return error_code(); return std::error_code();
} }

View File

@@ -22,9 +22,9 @@ public:
MipsTargetRelocationHandler(MipsTargetLayout<Mips32ElELFType> &layout) MipsTargetRelocationHandler(MipsTargetLayout<Mips32ElELFType> &layout)
: _mipsTargetLayout(layout) {} : _mipsTargetLayout(layout) {}
error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
const lld::AtomLayout &, const lld::AtomLayout &,
const Reference &) const override; const Reference &) const override;
private: private:
MipsTargetLayout<Mips32ElELFType> &_mipsTargetLayout; MipsTargetLayout<Mips32ElELFType> &_mipsTargetLayout;

View File

@@ -52,16 +52,16 @@ protected:
void buildChunks(const File &file) override; void buildChunks(const File &file) override;
// Build the output file // Build the output file
virtual error_code buildOutput(const File &file); virtual std::error_code buildOutput(const File &file);
// Setup the ELF header. // Setup the ELF header.
virtual error_code setELFHeader(); virtual std::error_code setELFHeader();
// Write the file to the path specified // Write the file to the path specified
error_code writeFile(const File &File, StringRef path) override; std::error_code writeFile(const File &File, StringRef path) override;
// Write to the output file. // Write to the output file.
virtual error_code writeOutput(const File &file, StringRef path); virtual std::error_code writeOutput(const File &file, StringRef path);
// Get the size of the output file that the linker would emit. // Get the size of the output file that the linker would emit.
virtual uint64_t outputFileSize() const; virtual uint64_t outputFileSize() const;
@@ -348,7 +348,7 @@ LLD_UNIQUE_BUMP_PTR(DynamicSymbolTable<ELFT>)
} }
template <class ELFT> template <class ELFT>
error_code OutputELFWriter<ELFT>::buildOutput(const File &file) { std::error_code OutputELFWriter<ELFT>::buildOutput(const File &file) {
ScopedTask buildTask(getDefaultDomain(), "ELF Writer buildOutput"); ScopedTask buildTask(getDefaultDomain(), "ELF Writer buildOutput");
buildChunks(file); buildChunks(file);
@@ -394,10 +394,10 @@ error_code OutputELFWriter<ELFT>::buildOutput(const File &file) {
if (_context.isDynamic()) if (_context.isDynamic())
_dynamicTable->updateDynamicTable(); _dynamicTable->updateDynamicTable();
return error_code(); return std::error_code();
} }
template <class ELFT> error_code OutputELFWriter<ELFT>::setELFHeader() { template <class ELFT> std::error_code OutputELFWriter<ELFT>::setELFHeader() {
_elfHeader->e_ident(ELF::EI_CLASS, _elfHeader->e_ident(ELF::EI_CLASS,
_context.is64Bits() ? ELF::ELFCLASS64 : ELF::ELFCLASS32); _context.is64Bits() ? ELF::ELFCLASS64 : ELF::ELFCLASS32);
_elfHeader->e_ident(ELF::EI_DATA, _context.isLittleEndian() _elfHeader->e_ident(ELF::EI_DATA, _context.isLittleEndian()
@@ -419,7 +419,7 @@ template <class ELFT> error_code OutputELFWriter<ELFT>::setELFHeader() {
_layout.findAtomAddrByName(_context.entrySymbolName(), virtualAddr); _layout.findAtomAddrByName(_context.entrySymbolName(), virtualAddr);
_elfHeader->e_entry(virtualAddr); _elfHeader->e_entry(virtualAddr);
return error_code(); return std::error_code();
} }
template <class ELFT> uint64_t OutputELFWriter<ELFT>::outputFileSize() const { template <class ELFT> uint64_t OutputELFWriter<ELFT>::outputFileSize() const {
@@ -427,12 +427,12 @@ template <class ELFT> uint64_t OutputELFWriter<ELFT>::outputFileSize() const {
} }
template <class ELFT> template <class ELFT>
error_code OutputELFWriter<ELFT>::writeOutput(const File &file, std::error_code OutputELFWriter<ELFT>::writeOutput(const File &file,
StringRef path) { StringRef path) {
std::unique_ptr<FileOutputBuffer> buffer; std::unique_ptr<FileOutputBuffer> buffer;
ScopedTask createOutputTask(getDefaultDomain(), "ELF Writer Create Output"); ScopedTask createOutputTask(getDefaultDomain(), "ELF Writer Create Output");
error_code ec = FileOutputBuffer::create(path, outputFileSize(), buffer, std::error_code ec = FileOutputBuffer::create(path, outputFileSize(), buffer,
FileOutputBuffer::F_executable); FileOutputBuffer::F_executable);
createOutputTask.end(); createOutputTask.end();
if (ec) if (ec)
@@ -455,8 +455,9 @@ error_code OutputELFWriter<ELFT>::writeOutput(const File &file,
} }
template <class ELFT> template <class ELFT>
error_code OutputELFWriter<ELFT>::writeFile(const File &file, StringRef path) { std::error_code OutputELFWriter<ELFT>::writeFile(const File &file,
error_code ec = buildOutput(file); StringRef path) {
std::error_code ec = buildOutput(file);
if (ec) if (ec)
return ec; return ec;

View File

@@ -35,7 +35,7 @@ static int relocB24PCREL(uint8_t *location, uint64_t P, uint64_t S,
return 1; return 1;
} }
error_code PPCTargetRelocationHandler::applyRelocation( std::error_code PPCTargetRelocationHandler::applyRelocation(
ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom, ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom,
const Reference &ref) const { const Reference &ref) const {
uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset; uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset;
@@ -44,7 +44,7 @@ error_code PPCTargetRelocationHandler::applyRelocation(
uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom(); uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom();
if (ref.kindNamespace() != Reference::KindNamespace::ELF) if (ref.kindNamespace() != Reference::KindNamespace::ELF)
return error_code(); return std::error_code();
assert(ref.kindArch() == Reference::KindArch::PowerPC); assert(ref.kindArch() == Reference::KindArch::PowerPC);
switch (ref.kindValue()) { switch (ref.kindValue()) {
case R_PPC_REL24: case R_PPC_REL24:
@@ -60,7 +60,7 @@ error_code PPCTargetRelocationHandler::applyRelocation(
} }
} }
return error_code(); return std::error_code();
} }
PPCTargetHandler::PPCTargetHandler(PPCLinkingContext &context) PPCTargetHandler::PPCTargetHandler(PPCLinkingContext &context)

View File

@@ -30,9 +30,9 @@ public:
PPCTargetLayout<PPCELFType> &layout) PPCTargetLayout<PPCELFType> &layout)
: _ppcContext(context), _ppcTargetLayout(layout) {} : _ppcContext(context), _ppcTargetLayout(layout) {}
virtual error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, virtual std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
const lld::AtomLayout &, const lld::AtomLayout &,
const Reference &) const override; const Reference &) const override;
protected: protected:
PPCLinkingContext &_ppcContext; PPCLinkingContext &_ppcContext;

View File

@@ -96,7 +96,7 @@ void X86TargetHandler::registerRelocationNames(Registry &registry) {
kindStrings); kindStrings);
} }
error_code X86TargetRelocationHandler::applyRelocation( std::error_code X86TargetRelocationHandler::applyRelocation(
ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom, ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom,
const Reference &ref) const { const Reference &ref) const {
uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset; uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset;
@@ -105,7 +105,7 @@ error_code X86TargetRelocationHandler::applyRelocation(
uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom(); uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom();
if (ref.kindNamespace() != Reference::KindNamespace::ELF) if (ref.kindNamespace() != Reference::KindNamespace::ELF)
return error_code(); return std::error_code();
assert(ref.kindArch() == Reference::KindArch::x86); assert(ref.kindArch() == Reference::KindArch::x86);
switch (ref.kindValue()) { switch (ref.kindValue()) {
case R_386_32: case R_386_32:
@@ -123,7 +123,7 @@ error_code X86TargetRelocationHandler::applyRelocation(
} }
} }
return error_code(); return std::error_code();
} }
X86TargetHandler::X86TargetHandler(X86LinkingContext &context) X86TargetHandler::X86TargetHandler(X86LinkingContext &context)

View File

@@ -33,9 +33,9 @@ public:
X86TargetLayout<X86ELFType> &layout) X86TargetLayout<X86ELFType> &layout)
: _x86Context(context), _x86TargetLayout(layout) {} : _x86Context(context), _x86TargetLayout(layout) {}
error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
const lld::AtomLayout &, const lld::AtomLayout &,
const Reference &) const override; const Reference &) const override;
static const Registry::KindStrings kindStrings[]; static const Registry::KindStrings kindStrings[];

View File

@@ -60,7 +60,7 @@ int64_t X86_64TargetRelocationHandler::relocAddend(const Reference &ref) const {
return 0; return 0;
} }
error_code X86_64TargetRelocationHandler::applyRelocation( std::error_code X86_64TargetRelocationHandler::applyRelocation(
ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom, ELFWriter &writer, llvm::FileOutputBuffer &buf, const lld::AtomLayout &atom,
const Reference &ref) const { const Reference &ref) const {
uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset; uint8_t *atomContent = buf.getBufferStart() + atom._fileOffset;
@@ -69,7 +69,7 @@ error_code X86_64TargetRelocationHandler::applyRelocation(
uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom(); uint64_t relocVAddress = atom._virtualAddr + ref.offsetInAtom();
if (ref.kindNamespace() != Reference::KindNamespace::ELF) if (ref.kindNamespace() != Reference::KindNamespace::ELF)
return error_code(); return std::error_code();
assert(ref.kindArch() == Reference::KindArch::x86_64); assert(ref.kindArch() == Reference::KindArch::x86_64);
switch (ref.kindValue()) { switch (ref.kindValue()) {
case R_X86_64_NONE: case R_X86_64_NONE:
@@ -140,5 +140,5 @@ error_code X86_64TargetRelocationHandler::applyRelocation(
} }
} }
return error_code(); return std::error_code();
} }

View File

@@ -24,9 +24,9 @@ public:
X86_64TargetRelocationHandler(X86_64TargetLayout<X86_64ELFType> &layout) X86_64TargetRelocationHandler(X86_64TargetLayout<X86_64ELFType> &layout)
: _tlsSize(0), _x86_64Layout(layout) {} : _tlsSize(0), _x86_64Layout(layout) {}
error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
const lld::AtomLayout &, const lld::AtomLayout &,
const Reference &) const override; const Reference &) const override;
virtual int64_t relocAddend(const Reference &) const; virtual int64_t relocAddend(const Reference &) const;

View File

@@ -149,11 +149,11 @@ protected:
/// ///
/// This create a PLT and GOT entry for the IFUNC if one does not exist. The /// This create a PLT and GOT entry for the IFUNC if one does not exist. The
/// GOT entry and a IRELATIVE relocation to the original target resolver. /// GOT entry and a IRELATIVE relocation to the original target resolver.
error_code handleIFUNC(const Reference &ref) { std::error_code handleIFUNC(const Reference &ref) {
auto target = dyn_cast_or_null<const DefinedAtom>(ref.target()); auto target = dyn_cast_or_null<const DefinedAtom>(ref.target());
if (target && target->contentType() == DefinedAtom::typeResolver) if (target && target->contentType() == DefinedAtom::typeResolver)
const_cast<Reference &>(ref).setTarget(getIFUNCPLTEntry(target)); const_cast<Reference &>(ref).setTarget(getIFUNCPLTEntry(target));
return error_code(); return std::error_code();
} }
/// \brief Create a GOT entry for the TP offset of a TLS atom. /// \brief Create a GOT entry for the TP offset of a TLS atom.
@@ -300,13 +300,13 @@ public:
StaticRelocationPass(const elf::X86_64LinkingContext &ctx) StaticRelocationPass(const elf::X86_64LinkingContext &ctx)
: RelocationPass(ctx) {} : RelocationPass(ctx) {}
error_code handlePlain(const Reference &ref) { return handleIFUNC(ref); } std::error_code handlePlain(const Reference &ref) { return handleIFUNC(ref); }
error_code handlePLT32(const Reference &ref) { std::error_code handlePLT32(const Reference &ref) {
// __tls_get_addr is handled elsewhere. // __tls_get_addr is handled elsewhere.
if (ref.target() && ref.target()->name() == "__tls_get_addr") { if (ref.target() && ref.target()->name() == "__tls_get_addr") {
const_cast<Reference &>(ref).setKindValue(R_X86_64_NONE); const_cast<Reference &>(ref).setKindValue(R_X86_64_NONE);
return error_code(); return std::error_code();
} }
// Static code doesn't need PLTs. // Static code doesn't need PLTs.
const_cast<Reference &>(ref).setKindValue(R_X86_64_PC32); const_cast<Reference &>(ref).setKindValue(R_X86_64_PC32);
@@ -315,15 +315,15 @@ public:
dyn_cast_or_null<const DefinedAtom>(ref.target())) dyn_cast_or_null<const DefinedAtom>(ref.target()))
if (da->contentType() == DefinedAtom::typeResolver) if (da->contentType() == DefinedAtom::typeResolver)
return handleIFUNC(ref); return handleIFUNC(ref);
return error_code(); return std::error_code();
} }
error_code handleGOT(const Reference &ref) { std::error_code handleGOT(const Reference &ref) {
if (isa<UndefinedAtom>(ref.target())) if (isa<UndefinedAtom>(ref.target()))
const_cast<Reference &>(ref).setTarget(getNullGOT()); const_cast<Reference &>(ref).setTarget(getNullGOT());
else if (const DefinedAtom *da = dyn_cast<const DefinedAtom>(ref.target())) else if (const DefinedAtom *da = dyn_cast<const DefinedAtom>(ref.target()))
const_cast<Reference &>(ref).setTarget(getGOT(da)); const_cast<Reference &>(ref).setTarget(getGOT(da));
return error_code(); return std::error_code();
} }
}; };
@@ -393,9 +393,9 @@ public:
return oa; return oa;
} }
error_code handlePlain(const Reference &ref) { std::error_code handlePlain(const Reference &ref) {
if (!ref.target()) if (!ref.target())
return error_code(); return std::error_code();
if (auto sla = dyn_cast<SharedLibraryAtom>(ref.target())) { if (auto sla = dyn_cast<SharedLibraryAtom>(ref.target())) {
if (sla->type() == SharedLibraryAtom::Type::Data) if (sla->type() == SharedLibraryAtom::Type::Data)
const_cast<Reference &>(ref).setTarget(getObjectEntry(sla)); const_cast<Reference &>(ref).setTarget(getObjectEntry(sla));
@@ -403,10 +403,10 @@ public:
const_cast<Reference &>(ref).setTarget(getPLTEntry(sla)); const_cast<Reference &>(ref).setTarget(getPLTEntry(sla));
} else } else
return handleIFUNC(ref); return handleIFUNC(ref);
return error_code(); return std::error_code();
} }
error_code handlePLT32(const Reference &ref) { std::error_code handlePLT32(const Reference &ref) {
// Turn this into a PC32 to the PLT entry. // Turn this into a PC32 to the PLT entry.
const_cast<Reference &>(ref).setKindValue(R_X86_64_PC32); const_cast<Reference &>(ref).setKindValue(R_X86_64_PC32);
// Handle IFUNC. // Handle IFUNC.
@@ -416,7 +416,7 @@ public:
return handleIFUNC(ref); return handleIFUNC(ref);
if (isa<const SharedLibraryAtom>(ref.target())) if (isa<const SharedLibraryAtom>(ref.target()))
const_cast<Reference &>(ref).setTarget(getPLTEntry(ref.target())); const_cast<Reference &>(ref).setTarget(getPLTEntry(ref.target()));
return error_code(); return std::error_code();
} }
const GOTAtom *getSharedGOT(const SharedLibraryAtom *sla) { const GOTAtom *getSharedGOT(const SharedLibraryAtom *sla) {
@@ -435,14 +435,14 @@ public:
return got->second; return got->second;
} }
error_code handleGOT(const Reference &ref) { std::error_code handleGOT(const Reference &ref) {
if (isa<UndefinedAtom>(ref.target())) if (isa<UndefinedAtom>(ref.target()))
const_cast<Reference &>(ref).setTarget(getNullGOT()); const_cast<Reference &>(ref).setTarget(getNullGOT());
else if (const DefinedAtom *da = dyn_cast<const DefinedAtom>(ref.target())) else if (const DefinedAtom *da = dyn_cast<const DefinedAtom>(ref.target()))
const_cast<Reference &>(ref).setTarget(getGOT(da)); const_cast<Reference &>(ref).setTarget(getGOT(da));
else if (const auto sla = dyn_cast<const SharedLibraryAtom>(ref.target())) else if (const auto sla = dyn_cast<const SharedLibraryAtom>(ref.target()))
const_cast<Reference &>(ref).setTarget(getSharedGOT(sla)); const_cast<Reference &>(ref).setTarget(getSharedGOT(sla));
return error_code(); return std::error_code();
} }
}; };
} // end anon namespace } // end anon namespace

View File

@@ -141,6 +141,7 @@
using namespace lld; using namespace lld;
using namespace lld::pecoff; using namespace lld::pecoff;
using namespace llvm; using namespace llvm;
using std::error_code;
#define DEBUG_TYPE "ReaderImportHeader" #define DEBUG_TYPE "ReaderImportHeader"