aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm12/tools/llvm-objcopy/ELF
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:30 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:30 +0300
commit2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch)
tree012bb94d777798f1f56ac1cec429509766d05181 /contrib/libs/llvm12/tools/llvm-objcopy/ELF
parent6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff)
downloadydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/tools/llvm-objcopy/ELF')
-rw-r--r--contrib/libs/llvm12/tools/llvm-objcopy/ELF/ELFObjcopy.cpp184
-rw-r--r--contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.cpp1192
-rw-r--r--contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.h276
3 files changed, 826 insertions, 826 deletions
diff --git a/contrib/libs/llvm12/tools/llvm-objcopy/ELF/ELFObjcopy.cpp b/contrib/libs/llvm12/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
index c53a34bc46..ee808a2d9d 100644
--- a/contrib/libs/llvm12/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ b/contrib/libs/llvm12/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -184,28 +184,28 @@ findBuildID(const CopyConfig &Config, const object::ELFFile<ELFT> &In) {
return createFileError(Config.InputFilename, std::move(Err));
}
- return createFileError(Config.InputFilename,
- createStringError(llvm::errc::invalid_argument,
- "could not find build ID"));
+ return createFileError(Config.InputFilename,
+ createStringError(llvm::errc::invalid_argument,
+ "could not find build ID"));
}
static Expected<ArrayRef<uint8_t>>
findBuildID(const CopyConfig &Config, const object::ELFObjectFileBase &In) {
if (auto *O = dyn_cast<ELFObjectFile<ELF32LE>>(&In))
- return findBuildID(Config, O->getELFFile());
+ return findBuildID(Config, O->getELFFile());
else if (auto *O = dyn_cast<ELFObjectFile<ELF64LE>>(&In))
- return findBuildID(Config, O->getELFFile());
+ return findBuildID(Config, O->getELFFile());
else if (auto *O = dyn_cast<ELFObjectFile<ELF32BE>>(&In))
- return findBuildID(Config, O->getELFFile());
+ return findBuildID(Config, O->getELFFile());
else if (auto *O = dyn_cast<ELFObjectFile<ELF64BE>>(&In))
- return findBuildID(Config, O->getELFFile());
+ return findBuildID(Config, O->getELFFile());
llvm_unreachable("Bad file format");
}
template <class... Ts>
-static Error makeStringError(std::error_code EC, const Twine &Msg,
- Ts &&... Args) {
+static Error makeStringError(std::error_code EC, const Twine &Msg,
+ Ts &&... Args) {
std::string FullMsg = (EC.message() + ": " + Msg).str();
return createStringError(EC, FullMsg.c_str(), std::forward<Ts>(Args)...);
}
@@ -265,23 +265,23 @@ static Error linkToBuildIdDir(const CopyConfig &Config, StringRef ToLink,
static Error splitDWOToFile(const CopyConfig &Config, const Reader &Reader,
StringRef File, ElfType OutputElfType) {
- Expected<std::unique_ptr<Object>> DWOFile = Reader.create(false);
- if (!DWOFile)
- return DWOFile.takeError();
-
+ Expected<std::unique_ptr<Object>> DWOFile = Reader.create(false);
+ if (!DWOFile)
+ return DWOFile.takeError();
+
auto OnlyKeepDWOPred = [&DWOFile](const SectionBase &Sec) {
- return onlyKeepDWOPred(**DWOFile, Sec);
+ return onlyKeepDWOPred(**DWOFile, Sec);
};
- if (Error E =
- (*DWOFile)->removeSections(Config.AllowBrokenLinks, OnlyKeepDWOPred))
+ if (Error E =
+ (*DWOFile)->removeSections(Config.AllowBrokenLinks, OnlyKeepDWOPred))
return E;
if (Config.OutputArch) {
- (*DWOFile)->Machine = Config.OutputArch.getValue().EMachine;
- (*DWOFile)->OSABI = Config.OutputArch.getValue().OSABI;
+ (*DWOFile)->Machine = Config.OutputArch.getValue().EMachine;
+ (*DWOFile)->OSABI = Config.OutputArch.getValue().OSABI;
}
FileBuffer FB(File);
- std::unique_ptr<Writer> Writer =
- createWriter(Config, **DWOFile, FB, OutputElfType);
+ std::unique_ptr<Writer> Writer =
+ createWriter(Config, **DWOFile, FB, OutputElfType);
if (Error E = Writer->finalize())
return E;
return Writer->write();
@@ -316,39 +316,39 @@ static bool isCompressable(const SectionBase &Sec) {
StringRef(Sec.Name).startswith(".debug");
}
-static Error replaceDebugSections(
+static Error replaceDebugSections(
Object &Obj, SectionPred &RemovePred,
- function_ref<bool(const SectionBase &)> ShouldReplace,
- function_ref<Expected<SectionBase *>(const SectionBase *)> AddSection) {
+ function_ref<bool(const SectionBase &)> ShouldReplace,
+ function_ref<Expected<SectionBase *>(const SectionBase *)> AddSection) {
// Build a list of the debug sections we are going to replace.
- // We can't call `AddSection` while iterating over sections,
+ // We can't call `AddSection` while iterating over sections,
// because it would mutate the sections array.
SmallVector<SectionBase *, 13> ToReplace;
for (auto &Sec : Obj.sections())
- if (ShouldReplace(Sec))
+ if (ShouldReplace(Sec))
ToReplace.push_back(&Sec);
// Build a mapping from original section to a new one.
DenseMap<SectionBase *, SectionBase *> FromTo;
- for (SectionBase *S : ToReplace) {
- Expected<SectionBase *> NewSection = AddSection(S);
- if (!NewSection)
- return NewSection.takeError();
-
- FromTo[S] = *NewSection;
- }
-
+ for (SectionBase *S : ToReplace) {
+ Expected<SectionBase *> NewSection = AddSection(S);
+ if (!NewSection)
+ return NewSection.takeError();
+
+ FromTo[S] = *NewSection;
+ }
+
// Now we want to update the target sections of relocation
// sections. Also we will update the relocations themselves
// to update the symbol references.
for (auto &Sec : Obj.sections())
Sec.replaceSectionReferences(FromTo);
- RemovePred = [ShouldReplace, RemovePred](const SectionBase &Sec) {
- return ShouldReplace(Sec) || RemovePred(Sec);
+ RemovePred = [ShouldReplace, RemovePred](const SectionBase &Sec) {
+ return ShouldReplace(Sec) || RemovePred(Sec);
};
-
- return Error::success();
+
+ return Error::success();
}
static bool isUnneededSymbol(const Symbol &Sym) {
@@ -587,29 +587,29 @@ static Error replaceAndRemoveSections(const CopyConfig &Config, Object &Obj) {
};
}
- if (Config.CompressionType != DebugCompressionType::None) {
- if (Error Err = replaceDebugSections(
- Obj, RemovePred, isCompressable,
- [&Config, &Obj](const SectionBase *S) -> Expected<SectionBase *> {
- Expected<CompressedSection> NewSection =
- CompressedSection::create(*S, Config.CompressionType);
- if (!NewSection)
- return NewSection.takeError();
-
- return &Obj.addSection<CompressedSection>(std::move(*NewSection));
- }))
- return Err;
- } else if (Config.DecompressDebugSections) {
- if (Error Err = replaceDebugSections(
- Obj, RemovePred,
- [](const SectionBase &S) { return isa<CompressedSection>(&S); },
- [&Obj](const SectionBase *S) {
- const CompressedSection *CS = cast<CompressedSection>(S);
- return &Obj.addSection<DecompressedSection>(*CS);
- }))
- return Err;
- }
-
+ if (Config.CompressionType != DebugCompressionType::None) {
+ if (Error Err = replaceDebugSections(
+ Obj, RemovePred, isCompressable,
+ [&Config, &Obj](const SectionBase *S) -> Expected<SectionBase *> {
+ Expected<CompressedSection> NewSection =
+ CompressedSection::create(*S, Config.CompressionType);
+ if (!NewSection)
+ return NewSection.takeError();
+
+ return &Obj.addSection<CompressedSection>(std::move(*NewSection));
+ }))
+ return Err;
+ } else if (Config.DecompressDebugSections) {
+ if (Error Err = replaceDebugSections(
+ Obj, RemovePred,
+ [](const SectionBase &S) { return isa<CompressedSection>(&S); },
+ [&Obj](const SectionBase *S) {
+ const CompressedSection *CS = cast<CompressedSection>(S);
+ return &Obj.addSection<DecompressedSection>(*CS);
+ }))
+ return Err;
+ }
+
return Obj.removeSections(Config.AllowBrokenLinks, RemovePred);
}
@@ -748,9 +748,9 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj,
// If the symbol table was previously removed, we need to create a new one
// before adding new symbols.
- if (!Obj.SymbolTable && !Config.ELF->SymbolsToAdd.empty())
- if (Error E = Obj.addNewSymbolTable())
- return E;
+ if (!Obj.SymbolTable && !Config.ELF->SymbolsToAdd.empty())
+ if (Error E = Obj.addNewSymbolTable())
+ return E;
for (const NewSymbolInfo &SI : Config.ELF->SymbolsToAdd) {
SectionBase *Sec = Obj.findSection(SI.SectionName);
@@ -760,17 +760,17 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj,
Sec ? (uint16_t)SYMBOL_SIMPLE_INDEX : (uint16_t)SHN_ABS, 0);
}
- // --set-section-flags works with sections added by --add-section.
- if (!Config.SetSectionFlags.empty()) {
- for (auto &Sec : Obj.sections()) {
- const auto Iter = Config.SetSectionFlags.find(Sec.Name);
- if (Iter != Config.SetSectionFlags.end()) {
- const SectionFlagsUpdate &SFU = Iter->second;
- setSectionFlagsAndType(Sec, SFU.NewFlags);
- }
- }
- }
-
+ // --set-section-flags works with sections added by --add-section.
+ if (!Config.SetSectionFlags.empty()) {
+ for (auto &Sec : Obj.sections()) {
+ const auto Iter = Config.SetSectionFlags.find(Sec.Name);
+ if (Iter != Config.SetSectionFlags.end()) {
+ const SectionFlagsUpdate &SFU = Iter->second;
+ setSectionFlagsAndType(Sec, SFU.NewFlags);
+ }
+ }
+ }
+
if (Config.EntryExpr)
Obj.Entry = Config.EntryExpr(Obj.Entry);
return Error::success();
@@ -788,15 +788,15 @@ static Error writeOutput(const CopyConfig &Config, Object &Obj, Buffer &Out,
Error executeObjcopyOnIHex(const CopyConfig &Config, MemoryBuffer &In,
Buffer &Out) {
IHexReader Reader(&In);
- Expected<std::unique_ptr<Object>> Obj = Reader.create(true);
- if (!Obj)
- return Obj.takeError();
-
+ Expected<std::unique_ptr<Object>> Obj = Reader.create(true);
+ if (!Obj)
+ return Obj.takeError();
+
const ElfType OutputElfType =
- getOutputElfType(Config.OutputArch.getValueOr(MachineInfo()));
- if (Error E = handleArgs(Config, **Obj, Reader, OutputElfType))
+ getOutputElfType(Config.OutputArch.getValueOr(MachineInfo()));
+ if (Error E = handleArgs(Config, **Obj, Reader, OutputElfType))
return E;
- return writeOutput(Config, **Obj, Out, OutputElfType);
+ return writeOutput(Config, **Obj, Out, OutputElfType);
}
Error executeObjcopyOnRawBinary(const CopyConfig &Config, MemoryBuffer &In,
@@ -804,26 +804,26 @@ Error executeObjcopyOnRawBinary(const CopyConfig &Config, MemoryBuffer &In,
uint8_t NewSymbolVisibility =
Config.ELF->NewSymbolVisibility.getValueOr((uint8_t)ELF::STV_DEFAULT);
BinaryReader Reader(&In, NewSymbolVisibility);
- Expected<std::unique_ptr<Object>> Obj = Reader.create(true);
- if (!Obj)
- return Obj.takeError();
+ Expected<std::unique_ptr<Object>> Obj = Reader.create(true);
+ if (!Obj)
+ return Obj.takeError();
// Prefer OutputArch (-O<format>) if set, otherwise fallback to BinaryArch
// (-B<arch>).
const ElfType OutputElfType =
getOutputElfType(Config.OutputArch.getValueOr(MachineInfo()));
- if (Error E = handleArgs(Config, **Obj, Reader, OutputElfType))
+ if (Error E = handleArgs(Config, **Obj, Reader, OutputElfType))
return E;
- return writeOutput(Config, **Obj, Out, OutputElfType);
+ return writeOutput(Config, **Obj, Out, OutputElfType);
}
Error executeObjcopyOnBinary(const CopyConfig &Config,
object::ELFObjectFileBase &In, Buffer &Out) {
ELFReader Reader(&In, Config.ExtractPartition);
- Expected<std::unique_ptr<Object>> Obj =
- Reader.create(!Config.SymbolsToAdd.empty());
- if (!Obj)
- return Obj.takeError();
+ Expected<std::unique_ptr<Object>> Obj =
+ Reader.create(!Config.SymbolsToAdd.empty());
+ if (!Obj)
+ return Obj.takeError();
// Prefer OutputArch (-O<format>) if set, otherwise infer it from the input.
const ElfType OutputElfType =
Config.OutputArch ? getOutputElfType(Config.OutputArch.getValue())
@@ -849,10 +849,10 @@ Error executeObjcopyOnBinary(const CopyConfig &Config,
Config.BuildIdLinkInput.getValue(), BuildIdBytes))
return E;
- if (Error E = handleArgs(Config, **Obj, Reader, OutputElfType))
+ if (Error E = handleArgs(Config, **Obj, Reader, OutputElfType))
return createFileError(Config.InputFilename, std::move(E));
- if (Error E = writeOutput(Config, **Obj, Out, OutputElfType))
+ if (Error E = writeOutput(Config, **Obj, Out, OutputElfType))
return createFileError(Config.InputFilename, std::move(E));
if (!Config.BuildIdLinkDir.empty() && Config.BuildIdLinkOutput)
if (Error E =
diff --git a/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.cpp b/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.cpp
index 0ff82f951b..4aea09fb50 100644
--- a/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.cpp
+++ b/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.cpp
@@ -14,7 +14,7 @@
#include "llvm/ADT/iterator_range.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCTargetOptions.h"
-#include "llvm/Object/ELF.h"
+#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Endian.h"
@@ -51,15 +51,15 @@ template <class ELFT> void ELFWriter<ELFT>::writePhdr(const Segment &Seg) {
}
Error SectionBase::removeSectionReferences(
- bool, function_ref<bool(const SectionBase *)>) {
+ bool, function_ref<bool(const SectionBase *)>) {
return Error::success();
}
-Error SectionBase::removeSymbols(function_ref<bool(const Symbol &)>) {
+Error SectionBase::removeSymbols(function_ref<bool(const Symbol &)>) {
return Error::success();
}
-Error SectionBase::initialize(SectionTableRef) { return Error::success(); }
+Error SectionBase::initialize(SectionTableRef) { return Error::success(); }
void SectionBase::finalize() {}
void SectionBase::markSymbols() {}
void SectionBase::replaceSectionReferences(
@@ -81,98 +81,98 @@ template <class ELFT> void ELFWriter<ELFT>::writeShdr(const SectionBase &Sec) {
Shdr.sh_entsize = Sec.EntrySize;
}
-template <class ELFT> Error ELFSectionSizer<ELFT>::visit(Section &) {
- return Error::success();
-}
+template <class ELFT> Error ELFSectionSizer<ELFT>::visit(Section &) {
+ return Error::success();
+}
-template <class ELFT> Error ELFSectionSizer<ELFT>::visit(OwnedDataSection &) {
- return Error::success();
-}
+template <class ELFT> Error ELFSectionSizer<ELFT>::visit(OwnedDataSection &) {
+ return Error::success();
+}
-template <class ELFT> Error ELFSectionSizer<ELFT>::visit(StringTableSection &) {
- return Error::success();
-}
+template <class ELFT> Error ELFSectionSizer<ELFT>::visit(StringTableSection &) {
+ return Error::success();
+}
template <class ELFT>
-Error ELFSectionSizer<ELFT>::visit(DynamicRelocationSection &) {
- return Error::success();
-}
+Error ELFSectionSizer<ELFT>::visit(DynamicRelocationSection &) {
+ return Error::success();
+}
template <class ELFT>
-Error ELFSectionSizer<ELFT>::visit(SymbolTableSection &Sec) {
+Error ELFSectionSizer<ELFT>::visit(SymbolTableSection &Sec) {
Sec.EntrySize = sizeof(Elf_Sym);
Sec.Size = Sec.Symbols.size() * Sec.EntrySize;
// Align to the largest field in Elf_Sym.
Sec.Align = ELFT::Is64Bits ? sizeof(Elf_Xword) : sizeof(Elf_Word);
- return Error::success();
+ return Error::success();
}
template <class ELFT>
-Error ELFSectionSizer<ELFT>::visit(RelocationSection &Sec) {
+Error ELFSectionSizer<ELFT>::visit(RelocationSection &Sec) {
Sec.EntrySize = Sec.Type == SHT_REL ? sizeof(Elf_Rel) : sizeof(Elf_Rela);
Sec.Size = Sec.Relocations.size() * Sec.EntrySize;
// Align to the largest field in Elf_Rel(a).
Sec.Align = ELFT::Is64Bits ? sizeof(Elf_Xword) : sizeof(Elf_Word);
- return Error::success();
+ return Error::success();
}
template <class ELFT>
-Error ELFSectionSizer<ELFT>::visit(GnuDebugLinkSection &) {
- return Error::success();
-}
+Error ELFSectionSizer<ELFT>::visit(GnuDebugLinkSection &) {
+ return Error::success();
+}
-template <class ELFT> Error ELFSectionSizer<ELFT>::visit(GroupSection &Sec) {
+template <class ELFT> Error ELFSectionSizer<ELFT>::visit(GroupSection &Sec) {
Sec.Size = sizeof(Elf_Word) + Sec.GroupMembers.size() * sizeof(Elf_Word);
- return Error::success();
+ return Error::success();
}
template <class ELFT>
-Error ELFSectionSizer<ELFT>::visit(SectionIndexSection &) {
- return Error::success();
-}
+Error ELFSectionSizer<ELFT>::visit(SectionIndexSection &) {
+ return Error::success();
+}
-template <class ELFT> Error ELFSectionSizer<ELFT>::visit(CompressedSection &) {
- return Error::success();
-}
+template <class ELFT> Error ELFSectionSizer<ELFT>::visit(CompressedSection &) {
+ return Error::success();
+}
template <class ELFT>
-Error ELFSectionSizer<ELFT>::visit(DecompressedSection &) {
- return Error::success();
-}
+Error ELFSectionSizer<ELFT>::visit(DecompressedSection &) {
+ return Error::success();
+}
-Error BinarySectionWriter::visit(const SectionIndexSection &Sec) {
- return createStringError(errc::operation_not_permitted,
- "cannot write symbol section index table '" +
- Sec.Name + "' ");
+Error BinarySectionWriter::visit(const SectionIndexSection &Sec) {
+ return createStringError(errc::operation_not_permitted,
+ "cannot write symbol section index table '" +
+ Sec.Name + "' ");
}
-Error BinarySectionWriter::visit(const SymbolTableSection &Sec) {
- return createStringError(errc::operation_not_permitted,
- "cannot write symbol table '" + Sec.Name +
- "' out to binary");
+Error BinarySectionWriter::visit(const SymbolTableSection &Sec) {
+ return createStringError(errc::operation_not_permitted,
+ "cannot write symbol table '" + Sec.Name +
+ "' out to binary");
}
-Error BinarySectionWriter::visit(const RelocationSection &Sec) {
- return createStringError(errc::operation_not_permitted,
- "cannot write relocation section '" + Sec.Name +
- "' out to binary");
+Error BinarySectionWriter::visit(const RelocationSection &Sec) {
+ return createStringError(errc::operation_not_permitted,
+ "cannot write relocation section '" + Sec.Name +
+ "' out to binary");
}
-Error BinarySectionWriter::visit(const GnuDebugLinkSection &Sec) {
- return createStringError(errc::operation_not_permitted,
- "cannot write '" + Sec.Name + "' out to binary");
+Error BinarySectionWriter::visit(const GnuDebugLinkSection &Sec) {
+ return createStringError(errc::operation_not_permitted,
+ "cannot write '" + Sec.Name + "' out to binary");
}
-Error BinarySectionWriter::visit(const GroupSection &Sec) {
- return createStringError(errc::operation_not_permitted,
- "cannot write '" + Sec.Name + "' out to binary");
+Error BinarySectionWriter::visit(const GroupSection &Sec) {
+ return createStringError(errc::operation_not_permitted,
+ "cannot write '" + Sec.Name + "' out to binary");
}
-Error SectionWriter::visit(const Section &Sec) {
+Error SectionWriter::visit(const Section &Sec) {
if (Sec.Type != SHT_NOBITS)
llvm::copy(Sec.Contents, Out.getBufferStart() + Sec.Offset);
-
- return Error::success();
+
+ return Error::success();
}
static bool addressOverflows32bit(uint64_t Addr) {
@@ -377,34 +377,34 @@ uint64_t IHexSectionWriterBase::writeBaseAddr(uint64_t Addr) {
return Base;
}
-void IHexSectionWriterBase::writeData(uint8_t, uint16_t,
+void IHexSectionWriterBase::writeData(uint8_t, uint16_t,
ArrayRef<uint8_t> Data) {
Offset += IHexRecord::getLineLength(Data.size());
}
-Error IHexSectionWriterBase::visit(const Section &Sec) {
+Error IHexSectionWriterBase::visit(const Section &Sec) {
writeSection(&Sec, Sec.Contents);
- return Error::success();
+ return Error::success();
}
-Error IHexSectionWriterBase::visit(const OwnedDataSection &Sec) {
+Error IHexSectionWriterBase::visit(const OwnedDataSection &Sec) {
writeSection(&Sec, Sec.Data);
- return Error::success();
+ return Error::success();
}
-Error IHexSectionWriterBase::visit(const StringTableSection &Sec) {
+Error IHexSectionWriterBase::visit(const StringTableSection &Sec) {
// Check that sizer has already done its work
assert(Sec.Size == Sec.StrTabBuilder.getSize());
// We are free to pass an invalid pointer to writeSection as long
// as we don't actually write any data. The real writer class has
// to override this method .
writeSection(&Sec, {nullptr, static_cast<size_t>(Sec.Size)});
- return Error::success();
+ return Error::success();
}
-Error IHexSectionWriterBase::visit(const DynamicRelocationSection &Sec) {
+Error IHexSectionWriterBase::visit(const DynamicRelocationSection &Sec) {
writeSection(&Sec, Sec.Contents);
- return Error::success();
+ return Error::success();
}
void IHexSectionWriter::writeData(uint8_t Type, uint16_t Addr,
@@ -414,25 +414,25 @@ void IHexSectionWriter::writeData(uint8_t Type, uint16_t Addr,
Offset += HexData.size();
}
-Error IHexSectionWriter::visit(const StringTableSection &Sec) {
+Error IHexSectionWriter::visit(const StringTableSection &Sec) {
assert(Sec.Size == Sec.StrTabBuilder.getSize());
std::vector<uint8_t> Data(Sec.Size);
Sec.StrTabBuilder.write(Data.data());
writeSection(&Sec, Data);
- return Error::success();
+ return Error::success();
}
-Error Section::accept(SectionVisitor &Visitor) const {
- return Visitor.visit(*this);
-}
+Error Section::accept(SectionVisitor &Visitor) const {
+ return Visitor.visit(*this);
+}
-Error Section::accept(MutableSectionVisitor &Visitor) {
- return Visitor.visit(*this);
-}
+Error Section::accept(MutableSectionVisitor &Visitor) {
+ return Visitor.visit(*this);
+}
-Error SectionWriter::visit(const OwnedDataSection &Sec) {
+Error SectionWriter::visit(const OwnedDataSection &Sec) {
llvm::copy(Sec.Data, Out.getBufferStart() + Sec.Offset);
- return Error::success();
+ return Error::success();
}
static constexpr std::array<uint8_t, 4> ZlibGnuMagic = {{'Z', 'L', 'I', 'B'}};
@@ -459,7 +459,7 @@ getDecompressedSizeAndAlignment(ArrayRef<uint8_t> Data) {
}
template <class ELFT>
-Error ELFSectionWriter<ELFT>::visit(const DecompressedSection &Sec) {
+Error ELFSectionWriter<ELFT>::visit(const DecompressedSection &Sec) {
const size_t DataOffset = isDataGnuCompressed(Sec.OriginalData)
? (ZlibGnuMagic.size() + sizeof(Sec.Size))
: sizeof(Elf_Chdr_Impl<ELFT>);
@@ -469,37 +469,37 @@ Error ELFSectionWriter<ELFT>::visit(const DecompressedSection &Sec) {
Sec.OriginalData.size() - DataOffset);
SmallVector<char, 128> DecompressedContent;
- if (Error Err = zlib::uncompress(CompressedContent, DecompressedContent,
- static_cast<size_t>(Sec.Size)))
- return createStringError(errc::invalid_argument,
- "'" + Sec.Name + "': " + toString(std::move(Err)));
+ if (Error Err = zlib::uncompress(CompressedContent, DecompressedContent,
+ static_cast<size_t>(Sec.Size)))
+ return createStringError(errc::invalid_argument,
+ "'" + Sec.Name + "': " + toString(std::move(Err)));
uint8_t *Buf = Out.getBufferStart() + Sec.Offset;
std::copy(DecompressedContent.begin(), DecompressedContent.end(), Buf);
-
- return Error::success();
+
+ return Error::success();
}
-Error BinarySectionWriter::visit(const DecompressedSection &Sec) {
- return createStringError(errc::operation_not_permitted,
- "cannot write compressed section '" + Sec.Name +
- "' ");
+Error BinarySectionWriter::visit(const DecompressedSection &Sec) {
+ return createStringError(errc::operation_not_permitted,
+ "cannot write compressed section '" + Sec.Name +
+ "' ");
}
-Error DecompressedSection::accept(SectionVisitor &Visitor) const {
- return Visitor.visit(*this);
+Error DecompressedSection::accept(SectionVisitor &Visitor) const {
+ return Visitor.visit(*this);
}
-Error DecompressedSection::accept(MutableSectionVisitor &Visitor) {
- return Visitor.visit(*this);
+Error DecompressedSection::accept(MutableSectionVisitor &Visitor) {
+ return Visitor.visit(*this);
}
-Error OwnedDataSection::accept(SectionVisitor &Visitor) const {
- return Visitor.visit(*this);
+Error OwnedDataSection::accept(SectionVisitor &Visitor) const {
+ return Visitor.visit(*this);
}
-Error OwnedDataSection::accept(MutableSectionVisitor &Visitor) {
- return Visitor.visit(*this);
+Error OwnedDataSection::accept(MutableSectionVisitor &Visitor) {
+ return Visitor.visit(*this);
}
void OwnedDataSection::appendHexData(StringRef HexData) {
@@ -511,18 +511,18 @@ void OwnedDataSection::appendHexData(StringRef HexData) {
Size = Data.size();
}
-Error BinarySectionWriter::visit(const CompressedSection &Sec) {
- return createStringError(errc::operation_not_permitted,
- "cannot write compressed section '" + Sec.Name +
- "' ");
+Error BinarySectionWriter::visit(const CompressedSection &Sec) {
+ return createStringError(errc::operation_not_permitted,
+ "cannot write compressed section '" + Sec.Name +
+ "' ");
}
template <class ELFT>
-Error ELFSectionWriter<ELFT>::visit(const CompressedSection &Sec) {
+Error ELFSectionWriter<ELFT>::visit(const CompressedSection &Sec) {
uint8_t *Buf = Out.getBufferStart() + Sec.Offset;
if (Sec.CompressionType == DebugCompressionType::None) {
std::copy(Sec.OriginalData.begin(), Sec.OriginalData.end(), Buf);
- return Error::success();
+ return Error::success();
}
if (Sec.CompressionType == DebugCompressionType::GNU) {
@@ -543,42 +543,42 @@ Error ELFSectionWriter<ELFT>::visit(const CompressedSection &Sec) {
}
std::copy(Sec.CompressedData.begin(), Sec.CompressedData.end(), Buf);
- return Error::success();
-}
-
-Expected<CompressedSection>
-CompressedSection::create(const SectionBase &Sec,
- DebugCompressionType CompressionType) {
- Error Err = Error::success();
- CompressedSection Section(Sec, CompressionType, Err);
-
- if (Err)
- return std::move(Err);
-
- return Section;
-}
-Expected<CompressedSection>
-CompressedSection::create(ArrayRef<uint8_t> CompressedData,
- uint64_t DecompressedSize,
- uint64_t DecompressedAlign) {
- return CompressedSection(CompressedData, DecompressedSize, DecompressedAlign);
-}
-
+ return Error::success();
+}
+
+Expected<CompressedSection>
+CompressedSection::create(const SectionBase &Sec,
+ DebugCompressionType CompressionType) {
+ Error Err = Error::success();
+ CompressedSection Section(Sec, CompressionType, Err);
+
+ if (Err)
+ return std::move(Err);
+
+ return Section;
+}
+Expected<CompressedSection>
+CompressedSection::create(ArrayRef<uint8_t> CompressedData,
+ uint64_t DecompressedSize,
+ uint64_t DecompressedAlign) {
+ return CompressedSection(CompressedData, DecompressedSize, DecompressedAlign);
+}
+
CompressedSection::CompressedSection(const SectionBase &Sec,
- DebugCompressionType CompressionType,
- Error &OutErr)
+ DebugCompressionType CompressionType,
+ Error &OutErr)
: SectionBase(Sec), CompressionType(CompressionType),
DecompressedSize(Sec.OriginalData.size()), DecompressedAlign(Sec.Align) {
- ErrorAsOutParameter EAO(&OutErr);
-
- if (Error Err = zlib::compress(
+ ErrorAsOutParameter EAO(&OutErr);
+
+ if (Error Err = zlib::compress(
StringRef(reinterpret_cast<const char *>(OriginalData.data()),
OriginalData.size()),
- CompressedData)) {
- OutErr = createStringError(llvm::errc::invalid_argument,
- "'" + Name + "': " + toString(std::move(Err)));
- return;
- }
+ CompressedData)) {
+ OutErr = createStringError(llvm::errc::invalid_argument,
+ "'" + Name + "': " + toString(std::move(Err)));
+ return;
+ }
size_t ChdrSize;
if (CompressionType == DebugCompressionType::GNU) {
@@ -604,12 +604,12 @@ CompressedSection::CompressedSection(ArrayRef<uint8_t> CompressedData,
OriginalData = CompressedData;
}
-Error CompressedSection::accept(SectionVisitor &Visitor) const {
- return Visitor.visit(*this);
+Error CompressedSection::accept(SectionVisitor &Visitor) const {
+ return Visitor.visit(*this);
}
-Error CompressedSection::accept(MutableSectionVisitor &Visitor) {
- return Visitor.visit(*this);
+Error CompressedSection::accept(MutableSectionVisitor &Visitor) {
+ return Visitor.visit(*this);
}
void StringTableSection::addString(StringRef Name) { StrTabBuilder.add(Name); }
@@ -623,51 +623,51 @@ void StringTableSection::prepareForLayout() {
Size = StrTabBuilder.getSize();
}
-Error SectionWriter::visit(const StringTableSection &Sec) {
+Error SectionWriter::visit(const StringTableSection &Sec) {
Sec.StrTabBuilder.write(Out.getBufferStart() + Sec.Offset);
- return Error::success();
+ return Error::success();
}
-Error StringTableSection::accept(SectionVisitor &Visitor) const {
- return Visitor.visit(*this);
+Error StringTableSection::accept(SectionVisitor &Visitor) const {
+ return Visitor.visit(*this);
}
-Error StringTableSection::accept(MutableSectionVisitor &Visitor) {
- return Visitor.visit(*this);
+Error StringTableSection::accept(MutableSectionVisitor &Visitor) {
+ return Visitor.visit(*this);
}
template <class ELFT>
-Error ELFSectionWriter<ELFT>::visit(const SectionIndexSection &Sec) {
+Error ELFSectionWriter<ELFT>::visit(const SectionIndexSection &Sec) {
uint8_t *Buf = Out.getBufferStart() + Sec.Offset;
llvm::copy(Sec.Indexes, reinterpret_cast<Elf_Word *>(Buf));
- return Error::success();
+ return Error::success();
}
-Error SectionIndexSection::initialize(SectionTableRef SecTable) {
+Error SectionIndexSection::initialize(SectionTableRef SecTable) {
Size = 0;
- Expected<SymbolTableSection *> Sec =
- SecTable.getSectionOfType<SymbolTableSection>(
- Link,
- "Link field value " + Twine(Link) + " in section " + Name +
- " is invalid",
- "Link field value " + Twine(Link) + " in section " + Name +
- " is not a symbol table");
- if (!Sec)
- return Sec.takeError();
-
- setSymTab(*Sec);
+ Expected<SymbolTableSection *> Sec =
+ SecTable.getSectionOfType<SymbolTableSection>(
+ Link,
+ "Link field value " + Twine(Link) + " in section " + Name +
+ " is invalid",
+ "Link field value " + Twine(Link) + " in section " + Name +
+ " is not a symbol table");
+ if (!Sec)
+ return Sec.takeError();
+
+ setSymTab(*Sec);
Symbols->setShndxTable(this);
- return Error::success();
+ return Error::success();
}
void SectionIndexSection::finalize() { Link = Symbols->Index; }
-Error SectionIndexSection::accept(SectionVisitor &Visitor) const {
- return Visitor.visit(*this);
+Error SectionIndexSection::accept(SectionVisitor &Visitor) const {
+ return Visitor.visit(*this);
}
-Error SectionIndexSection::accept(MutableSectionVisitor &Visitor) {
- return Visitor.visit(*this);
+Error SectionIndexSection::accept(MutableSectionVisitor &Visitor) {
+ return Visitor.visit(*this);
}
static bool isValidReservedSectionIndex(uint16_t Index, uint16_t Machine) {
@@ -750,7 +750,7 @@ void SymbolTableSection::addSymbol(Twine Name, uint8_t Bind, uint8_t Type,
}
Error SymbolTableSection::removeSectionReferences(
- bool AllowBrokenLinks, function_ref<bool(const SectionBase *)> ToRemove) {
+ bool AllowBrokenLinks, function_ref<bool(const SectionBase *)> ToRemove) {
if (ToRemove(SectionIndexTable))
SectionIndexTable = nullptr;
if (ToRemove(SymbolNames)) {
@@ -793,20 +793,20 @@ void SymbolTableSection::replaceSectionReferences(
Sym->DefinedIn = To;
}
-Error SymbolTableSection::initialize(SectionTableRef SecTable) {
+Error SymbolTableSection::initialize(SectionTableRef SecTable) {
Size = 0;
- Expected<StringTableSection *> Sec =
- SecTable.getSectionOfType<StringTableSection>(
- Link,
- "Symbol table has link index of " + Twine(Link) +
- " which is not a valid index",
- "Symbol table has link index of " + Twine(Link) +
- " which is not a string table");
- if (!Sec)
- return Sec.takeError();
-
- setStrTab(*Sec);
- return Error::success();
+ Expected<StringTableSection *> Sec =
+ SecTable.getSectionOfType<StringTableSection>(
+ Link,
+ "Symbol table has link index of " + Twine(Link) +
+ " which is not a valid index",
+ "Symbol table has link index of " + Twine(Link) +
+ " which is not a string table");
+ if (!Sec)
+ return Sec.takeError();
+
+ setStrTab(*Sec);
+ return Error::success();
}
void SymbolTableSection::finalize() {
@@ -851,25 +851,25 @@ void SymbolTableSection::fillShndxTable() {
}
}
-Expected<const Symbol *>
-SymbolTableSection::getSymbolByIndex(uint32_t Index) const {
+Expected<const Symbol *>
+SymbolTableSection::getSymbolByIndex(uint32_t Index) const {
if (Symbols.size() <= Index)
- return createStringError(errc::invalid_argument,
- "invalid symbol index: " + Twine(Index));
+ return createStringError(errc::invalid_argument,
+ "invalid symbol index: " + Twine(Index));
return Symbols[Index].get();
}
-Expected<Symbol *> SymbolTableSection::getSymbolByIndex(uint32_t Index) {
- Expected<const Symbol *> Sym =
- static_cast<const SymbolTableSection *>(this)->getSymbolByIndex(Index);
- if (!Sym)
- return Sym.takeError();
-
- return const_cast<Symbol *>(*Sym);
+Expected<Symbol *> SymbolTableSection::getSymbolByIndex(uint32_t Index) {
+ Expected<const Symbol *> Sym =
+ static_cast<const SymbolTableSection *>(this)->getSymbolByIndex(Index);
+ if (!Sym)
+ return Sym.takeError();
+
+ return const_cast<Symbol *>(*Sym);
}
template <class ELFT>
-Error ELFSectionWriter<ELFT>::visit(const SymbolTableSection &Sec) {
+Error ELFSectionWriter<ELFT>::visit(const SymbolTableSection &Sec) {
Elf_Sym *Sym = reinterpret_cast<Elf_Sym *>(Out.getBufferStart() + Sec.Offset);
// Loop though symbols setting each entry of the symbol table.
for (const std::unique_ptr<Symbol> &Symbol : Sec.Symbols) {
@@ -882,19 +882,19 @@ Error ELFSectionWriter<ELFT>::visit(const SymbolTableSection &Sec) {
Sym->st_shndx = Symbol->getShndx();
++Sym;
}
- return Error::success();
+ return Error::success();
}
-Error SymbolTableSection::accept(SectionVisitor &Visitor) const {
- return Visitor.visit(*this);
+Error SymbolTableSection::accept(SectionVisitor &Visitor) const {
+ return Visitor.visit(*this);
}
-Error SymbolTableSection::accept(MutableSectionVisitor &Visitor) {
- return Visitor.visit(*this);
+Error SymbolTableSection::accept(MutableSectionVisitor &Visitor) {
+ return Visitor.visit(*this);
}
Error RelocationSection::removeSectionReferences(
- bool AllowBrokenLinks, function_ref<bool(const SectionBase *)> ToRemove) {
+ bool AllowBrokenLinks, function_ref<bool(const SectionBase *)> ToRemove) {
if (ToRemove(Symbols)) {
if (!AllowBrokenLinks)
return createStringError(
@@ -921,33 +921,33 @@ Error RelocationSection::removeSectionReferences(
}
template <class SymTabType>
-Error RelocSectionWithSymtabBase<SymTabType>::initialize(
+Error RelocSectionWithSymtabBase<SymTabType>::initialize(
SectionTableRef SecTable) {
- if (Link != SHN_UNDEF) {
- Expected<SymTabType *> Sec = SecTable.getSectionOfType<SymTabType>(
+ if (Link != SHN_UNDEF) {
+ Expected<SymTabType *> Sec = SecTable.getSectionOfType<SymTabType>(
Link,
"Link field value " + Twine(Link) + " in section " + Name +
" is invalid",
"Link field value " + Twine(Link) + " in section " + Name +
- " is not a symbol table");
- if (!Sec)
- return Sec.takeError();
-
- setSymTab(*Sec);
- }
-
- if (Info != SHN_UNDEF) {
- Expected<SectionBase *> Sec =
- SecTable.getSection(Info, "Info field value " + Twine(Info) +
- " in section " + Name + " is invalid");
- if (!Sec)
- return Sec.takeError();
-
- setSection(*Sec);
- } else
+ " is not a symbol table");
+ if (!Sec)
+ return Sec.takeError();
+
+ setSymTab(*Sec);
+ }
+
+ if (Info != SHN_UNDEF) {
+ Expected<SectionBase *> Sec =
+ SecTable.getSection(Info, "Info field value " + Twine(Info) +
+ " in section " + Name + " is invalid");
+ if (!Sec)
+ return Sec.takeError();
+
+ setSection(*Sec);
+ } else
setSection(nullptr);
-
- return Error::success();
+
+ return Error::success();
}
template <class SymTabType>
@@ -959,7 +959,7 @@ void RelocSectionWithSymtabBase<SymTabType>::finalize() {
}
template <class ELFT>
-static void setAddend(Elf_Rel_Impl<ELFT, false> &, uint64_t) {}
+static void setAddend(Elf_Rel_Impl<ELFT, false> &, uint64_t) {}
template <class ELFT>
static void setAddend(Elf_Rel_Impl<ELFT, true> &Rela, uint64_t Addend) {
@@ -978,21 +978,21 @@ static void writeRel(const RelRange &Relocations, T *Buf) {
}
template <class ELFT>
-Error ELFSectionWriter<ELFT>::visit(const RelocationSection &Sec) {
+Error ELFSectionWriter<ELFT>::visit(const RelocationSection &Sec) {
uint8_t *Buf = Out.getBufferStart() + Sec.Offset;
if (Sec.Type == SHT_REL)
writeRel(Sec.Relocations, reinterpret_cast<Elf_Rel *>(Buf));
else
writeRel(Sec.Relocations, reinterpret_cast<Elf_Rela *>(Buf));
- return Error::success();
+ return Error::success();
}
-Error RelocationSection::accept(SectionVisitor &Visitor) const {
- return Visitor.visit(*this);
+Error RelocationSection::accept(SectionVisitor &Visitor) const {
+ return Visitor.visit(*this);
}
-Error RelocationSection::accept(MutableSectionVisitor &Visitor) {
- return Visitor.visit(*this);
+Error RelocationSection::accept(MutableSectionVisitor &Visitor) {
+ return Visitor.visit(*this);
}
Error RelocationSection::removeSymbols(
@@ -1019,17 +1019,17 @@ void RelocationSection::replaceSectionReferences(
SecToApplyRel = To;
}
-Error SectionWriter::visit(const DynamicRelocationSection &Sec) {
+Error SectionWriter::visit(const DynamicRelocationSection &Sec) {
llvm::copy(Sec.Contents, Out.getBufferStart() + Sec.Offset);
- return Error::success();
+ return Error::success();
}
-Error DynamicRelocationSection::accept(SectionVisitor &Visitor) const {
- return Visitor.visit(*this);
+Error DynamicRelocationSection::accept(SectionVisitor &Visitor) const {
+ return Visitor.visit(*this);
}
-Error DynamicRelocationSection::accept(MutableSectionVisitor &Visitor) {
- return Visitor.visit(*this);
+Error DynamicRelocationSection::accept(MutableSectionVisitor &Visitor) {
+ return Visitor.visit(*this);
}
Error DynamicRelocationSection::removeSectionReferences(
@@ -1115,22 +1115,22 @@ void GroupSection::onRemove() {
Sec->Flags &= ~SHF_GROUP;
}
-Error Section::initialize(SectionTableRef SecTable) {
+Error Section::initialize(SectionTableRef SecTable) {
if (Link == ELF::SHN_UNDEF)
- return Error::success();
-
- Expected<SectionBase *> Sec =
+ return Error::success();
+
+ Expected<SectionBase *> Sec =
SecTable.getSection(Link, "Link field value " + Twine(Link) +
" in section " + Name + " is invalid");
- if (!Sec)
- return Sec.takeError();
-
- LinkSection = *Sec;
-
+ if (!Sec)
+ return Sec.takeError();
+
+ LinkSection = *Sec;
+
if (LinkSection->Type == ELF::SHT_SYMTAB)
LinkSection = nullptr;
-
- return Error::success();
+
+ return Error::success();
}
void Section::finalize() { this->Link = LinkSection ? LinkSection->Index : 0; }
@@ -1159,39 +1159,39 @@ GnuDebugLinkSection::GnuDebugLinkSection(StringRef File,
}
template <class ELFT>
-Error ELFSectionWriter<ELFT>::visit(const GnuDebugLinkSection &Sec) {
+Error ELFSectionWriter<ELFT>::visit(const GnuDebugLinkSection &Sec) {
unsigned char *Buf = Out.getBufferStart() + Sec.Offset;
Elf_Word *CRC =
reinterpret_cast<Elf_Word *>(Buf + Sec.Size - sizeof(Elf_Word));
*CRC = Sec.CRC32;
llvm::copy(Sec.FileName, Buf);
- return Error::success();
+ return Error::success();
}
-Error GnuDebugLinkSection::accept(SectionVisitor &Visitor) const {
- return Visitor.visit(*this);
+Error GnuDebugLinkSection::accept(SectionVisitor &Visitor) const {
+ return Visitor.visit(*this);
}
-Error GnuDebugLinkSection::accept(MutableSectionVisitor &Visitor) {
- return Visitor.visit(*this);
+Error GnuDebugLinkSection::accept(MutableSectionVisitor &Visitor) {
+ return Visitor.visit(*this);
}
template <class ELFT>
-Error ELFSectionWriter<ELFT>::visit(const GroupSection &Sec) {
+Error ELFSectionWriter<ELFT>::visit(const GroupSection &Sec) {
ELF::Elf32_Word *Buf =
reinterpret_cast<ELF::Elf32_Word *>(Out.getBufferStart() + Sec.Offset);
*Buf++ = Sec.FlagWord;
for (SectionBase *S : Sec.GroupMembers)
support::endian::write32<ELFT::TargetEndianness>(Buf++, S->Index);
- return Error::success();
+ return Error::success();
}
-Error GroupSection::accept(SectionVisitor &Visitor) const {
- return Visitor.visit(*this);
+Error GroupSection::accept(SectionVisitor &Visitor) const {
+ return Visitor.visit(*this);
}
-Error GroupSection::accept(MutableSectionVisitor &Visitor) {
- return Visitor.visit(*this);
+Error GroupSection::accept(MutableSectionVisitor &Visitor) {
+ return Visitor.visit(*this);
}
// Returns true IFF a section is wholly inside the range of a segment
@@ -1271,12 +1271,12 @@ SymbolTableSection *BasicELFBuilder::addSymTab(StringTableSection *StrTab) {
return &SymTab;
}
-Error BasicELFBuilder::initSections() {
+Error BasicELFBuilder::initSections() {
for (SectionBase &Sec : Obj->sections())
- if (Error Err = Sec.initialize(Obj->sections()))
- return Err;
-
- return Error::success();
+ if (Error Err = Sec.initialize(Obj->sections()))
+ return Err;
+
+ return Error::success();
}
void BinaryELFBuilder::addData(SymbolTableSection *SymTab) {
@@ -1303,13 +1303,13 @@ void BinaryELFBuilder::addData(SymbolTableSection *SymTab) {
0);
}
-Expected<std::unique_ptr<Object>> BinaryELFBuilder::build() {
+Expected<std::unique_ptr<Object>> BinaryELFBuilder::build() {
initFileHeader();
initHeaderSegment();
SymbolTableSection *SymTab = addSymTab(addStrTab());
- if (Error Err = initSections())
- return std::move(Err);
+ if (Error Err = initSections())
+ return std::move(Err);
addData(SymTab);
return std::move(Obj);
@@ -1360,13 +1360,13 @@ void IHexELFBuilder::addDataSections() {
}
}
-Expected<std::unique_ptr<Object>> IHexELFBuilder::build() {
+Expected<std::unique_ptr<Object>> IHexELFBuilder::build() {
initFileHeader();
initHeaderSegment();
StringTableSection *StrTab = addStrTab();
addSymTab(StrTab);
- if (Error Err = initSections())
- return std::move(Err);
+ if (Error Err = initSections())
+ return std::move(Err);
addDataSections();
return std::move(Obj);
@@ -1388,37 +1388,37 @@ template <class ELFT> void ELFBuilder<ELFT>::setParentSegment(Segment &Child) {
}
}
-template <class ELFT> Error ELFBuilder<ELFT>::findEhdrOffset() {
+template <class ELFT> Error ELFBuilder<ELFT>::findEhdrOffset() {
if (!ExtractPartition)
- return Error::success();
+ return Error::success();
for (const SectionBase &Sec : Obj.sections()) {
if (Sec.Type == SHT_LLVM_PART_EHDR && Sec.Name == *ExtractPartition) {
EhdrOffset = Sec.Offset;
- return Error::success();
+ return Error::success();
}
}
- return createStringError(errc::invalid_argument,
- "could not find partition named '" +
- *ExtractPartition + "'");
+ return createStringError(errc::invalid_argument,
+ "could not find partition named '" +
+ *ExtractPartition + "'");
}
template <class ELFT>
-Error ELFBuilder<ELFT>::readProgramHeaders(const ELFFile<ELFT> &HeadersFile) {
+Error ELFBuilder<ELFT>::readProgramHeaders(const ELFFile<ELFT> &HeadersFile) {
uint32_t Index = 0;
-
- Expected<typename ELFFile<ELFT>::Elf_Phdr_Range> Headers =
- HeadersFile.program_headers();
- if (!Headers)
- return Headers.takeError();
-
- for (const typename ELFFile<ELFT>::Elf_Phdr &Phdr : *Headers) {
+
+ Expected<typename ELFFile<ELFT>::Elf_Phdr_Range> Headers =
+ HeadersFile.program_headers();
+ if (!Headers)
+ return Headers.takeError();
+
+ for (const typename ELFFile<ELFT>::Elf_Phdr &Phdr : *Headers) {
if (Phdr.p_offset + Phdr.p_filesz > HeadersFile.getBufSize())
- return createStringError(
- errc::invalid_argument,
- "program header with offset 0x" + Twine::utohexstr(Phdr.p_offset) +
- " and file size 0x" + Twine::utohexstr(Phdr.p_filesz) +
- " goes past the end of the file");
+ return createStringError(
+ errc::invalid_argument,
+ "program header with offset 0x" + Twine::utohexstr(Phdr.p_offset) +
+ " and file size 0x" + Twine::utohexstr(Phdr.p_filesz) +
+ " goes past the end of the file");
ArrayRef<uint8_t> Data{HeadersFile.base() + Phdr.p_offset,
(size_t)Phdr.p_filesz};
@@ -1445,7 +1445,7 @@ Error ELFBuilder<ELFT>::readProgramHeaders(const ELFFile<ELFT> &HeadersFile) {
ElfHdr.Index = Index++;
ElfHdr.OriginalOffset = ElfHdr.Offset = EhdrOffset;
- const typename ELFT::Ehdr &Ehdr = HeadersFile.getHeader();
+ const typename ELFT::Ehdr &Ehdr = HeadersFile.getHeader();
auto &PrHdr = Obj.ProgramHdrSegment;
PrHdr.Type = PT_PHDR;
PrHdr.Flags = 0;
@@ -1466,16 +1466,16 @@ Error ELFBuilder<ELFT>::readProgramHeaders(const ELFFile<ELFT> &HeadersFile) {
setParentSegment(Child);
setParentSegment(ElfHdr);
setParentSegment(PrHdr);
-
- return Error::success();
+
+ return Error::success();
}
template <class ELFT>
-Error ELFBuilder<ELFT>::initGroupSection(GroupSection *GroupSec) {
+Error ELFBuilder<ELFT>::initGroupSection(GroupSection *GroupSec) {
if (GroupSec->Align % sizeof(ELF::Elf32_Word) != 0)
- return createStringError(errc::invalid_argument,
- "invalid alignment " + Twine(GroupSec->Align) +
- " of group section '" + GroupSec->Name + "'");
+ return createStringError(errc::invalid_argument,
+ "invalid alignment " + Twine(GroupSec->Align) +
+ " of group section '" + GroupSec->Name + "'");
SectionTableRef SecTable = Obj.sections();
if (GroupSec->Link != SHN_UNDEF) {
auto SymTab = SecTable.template getSectionOfType<SymbolTableSection>(
@@ -1484,23 +1484,23 @@ Error ELFBuilder<ELFT>::initGroupSection(GroupSection *GroupSec) {
GroupSec->Name + "' is invalid",
"link field value '" + Twine(GroupSec->Link) + "' in section '" +
GroupSec->Name + "' is not a symbol table");
- if (!SymTab)
- return SymTab.takeError();
-
- Expected<Symbol *> Sym = (*SymTab)->getSymbolByIndex(GroupSec->Info);
+ if (!SymTab)
+ return SymTab.takeError();
+
+ Expected<Symbol *> Sym = (*SymTab)->getSymbolByIndex(GroupSec->Info);
if (!Sym)
- return createStringError(errc::invalid_argument,
- "info field value '" + Twine(GroupSec->Info) +
- "' in section '" + GroupSec->Name +
- "' is not a valid symbol index");
- GroupSec->setSymTab(*SymTab);
- GroupSec->setSymbol(*Sym);
+ return createStringError(errc::invalid_argument,
+ "info field value '" + Twine(GroupSec->Info) +
+ "' in section '" + GroupSec->Name +
+ "' is not a valid symbol index");
+ GroupSec->setSymTab(*SymTab);
+ GroupSec->setSymbol(*Sym);
}
if (GroupSec->Contents.size() % sizeof(ELF::Elf32_Word) ||
GroupSec->Contents.empty())
- return createStringError(errc::invalid_argument,
- "the content of the section " + GroupSec->Name +
- " is malformed");
+ return createStringError(errc::invalid_argument,
+ "the content of the section " + GroupSec->Name +
+ " is malformed");
const ELF::Elf32_Word *Word =
reinterpret_cast<const ELF::Elf32_Word *>(GroupSec->Contents.data());
const ELF::Elf32_Word *End =
@@ -1508,103 +1508,103 @@ Error ELFBuilder<ELFT>::initGroupSection(GroupSection *GroupSec) {
GroupSec->setFlagWord(*Word++);
for (; Word != End; ++Word) {
uint32_t Index = support::endian::read32<ELFT::TargetEndianness>(Word);
- Expected<SectionBase *> Sec = SecTable.getSection(
+ Expected<SectionBase *> Sec = SecTable.getSection(
Index, "group member index " + Twine(Index) + " in section '" +
- GroupSec->Name + "' is invalid");
- if (!Sec)
- return Sec.takeError();
-
- GroupSec->addMember(*Sec);
+ GroupSec->Name + "' is invalid");
+ if (!Sec)
+ return Sec.takeError();
+
+ GroupSec->addMember(*Sec);
}
-
- return Error::success();
+
+ return Error::success();
}
template <class ELFT>
-Error ELFBuilder<ELFT>::initSymbolTable(SymbolTableSection *SymTab) {
- Expected<const Elf_Shdr *> Shdr = ElfFile.getSection(SymTab->Index);
- if (!Shdr)
- return Shdr.takeError();
-
- Expected<StringRef> StrTabData = ElfFile.getStringTableForSymtab(**Shdr);
- if (!StrTabData)
- return StrTabData.takeError();
-
+Error ELFBuilder<ELFT>::initSymbolTable(SymbolTableSection *SymTab) {
+ Expected<const Elf_Shdr *> Shdr = ElfFile.getSection(SymTab->Index);
+ if (!Shdr)
+ return Shdr.takeError();
+
+ Expected<StringRef> StrTabData = ElfFile.getStringTableForSymtab(**Shdr);
+ if (!StrTabData)
+ return StrTabData.takeError();
+
ArrayRef<Elf_Word> ShndxData;
- Expected<typename ELFFile<ELFT>::Elf_Sym_Range> Symbols =
- ElfFile.symbols(*Shdr);
- if (!Symbols)
- return Symbols.takeError();
-
- for (const typename ELFFile<ELFT>::Elf_Sym &Sym : *Symbols) {
+ Expected<typename ELFFile<ELFT>::Elf_Sym_Range> Symbols =
+ ElfFile.symbols(*Shdr);
+ if (!Symbols)
+ return Symbols.takeError();
+
+ for (const typename ELFFile<ELFT>::Elf_Sym &Sym : *Symbols) {
SectionBase *DefSection = nullptr;
- Expected<StringRef> Name = Sym.getName(*StrTabData);
- if (!Name)
- return Name.takeError();
-
+ Expected<StringRef> Name = Sym.getName(*StrTabData);
+ if (!Name)
+ return Name.takeError();
+
if (Sym.st_shndx == SHN_XINDEX) {
if (SymTab->getShndxTable() == nullptr)
- return createStringError(errc::invalid_argument,
- "symbol '" + *Name +
- "' has index SHN_XINDEX but no "
- "SHT_SYMTAB_SHNDX section exists");
+ return createStringError(errc::invalid_argument,
+ "symbol '" + *Name +
+ "' has index SHN_XINDEX but no "
+ "SHT_SYMTAB_SHNDX section exists");
if (ShndxData.data() == nullptr) {
- Expected<const Elf_Shdr *> ShndxSec =
- ElfFile.getSection(SymTab->getShndxTable()->Index);
- if (!ShndxSec)
- return ShndxSec.takeError();
-
- Expected<ArrayRef<Elf_Word>> Data =
- ElfFile.template getSectionContentsAsArray<Elf_Word>(**ShndxSec);
- if (!Data)
- return Data.takeError();
-
- ShndxData = *Data;
- if (ShndxData.size() != Symbols->size())
- return createStringError(
- errc::invalid_argument,
- "symbol section index table does not have the same number of "
- "entries as the symbol table");
+ Expected<const Elf_Shdr *> ShndxSec =
+ ElfFile.getSection(SymTab->getShndxTable()->Index);
+ if (!ShndxSec)
+ return ShndxSec.takeError();
+
+ Expected<ArrayRef<Elf_Word>> Data =
+ ElfFile.template getSectionContentsAsArray<Elf_Word>(**ShndxSec);
+ if (!Data)
+ return Data.takeError();
+
+ ShndxData = *Data;
+ if (ShndxData.size() != Symbols->size())
+ return createStringError(
+ errc::invalid_argument,
+ "symbol section index table does not have the same number of "
+ "entries as the symbol table");
}
- Elf_Word Index = ShndxData[&Sym - Symbols->begin()];
- Expected<SectionBase *> Sec = Obj.sections().getSection(
+ Elf_Word Index = ShndxData[&Sym - Symbols->begin()];
+ Expected<SectionBase *> Sec = Obj.sections().getSection(
Index,
- "symbol '" + *Name + "' has invalid section index " + Twine(Index));
- if (!Sec)
- return Sec.takeError();
-
- DefSection = *Sec;
+ "symbol '" + *Name + "' has invalid section index " + Twine(Index));
+ if (!Sec)
+ return Sec.takeError();
+
+ DefSection = *Sec;
} else if (Sym.st_shndx >= SHN_LORESERVE) {
if (!isValidReservedSectionIndex(Sym.st_shndx, Obj.Machine)) {
- return createStringError(
- errc::invalid_argument,
- "symbol '" + *Name +
- "' has unsupported value greater than or equal "
- "to SHN_LORESERVE: " +
- Twine(Sym.st_shndx));
+ return createStringError(
+ errc::invalid_argument,
+ "symbol '" + *Name +
+ "' has unsupported value greater than or equal "
+ "to SHN_LORESERVE: " +
+ Twine(Sym.st_shndx));
}
} else if (Sym.st_shndx != SHN_UNDEF) {
- Expected<SectionBase *> Sec = Obj.sections().getSection(
- Sym.st_shndx, "symbol '" + *Name +
+ Expected<SectionBase *> Sec = Obj.sections().getSection(
+ Sym.st_shndx, "symbol '" + *Name +
"' is defined has invalid section index " +
Twine(Sym.st_shndx));
- if (!Sec)
- return Sec.takeError();
-
- DefSection = *Sec;
+ if (!Sec)
+ return Sec.takeError();
+
+ DefSection = *Sec;
}
- SymTab->addSymbol(*Name, Sym.getBinding(), Sym.getType(), DefSection,
+ SymTab->addSymbol(*Name, Sym.getBinding(), Sym.getType(), DefSection,
Sym.getValue(), Sym.st_other, Sym.st_shndx, Sym.st_size);
}
-
- return Error::success();
+
+ return Error::success();
}
template <class ELFT>
-static void getAddend(uint64_t &, const Elf_Rel_Impl<ELFT, false> &) {}
+static void getAddend(uint64_t &, const Elf_Rel_Impl<ELFT, false> &) {}
template <class ELFT>
static void getAddend(uint64_t &ToSet, const Elf_Rel_Impl<ELFT, true> &Rela) {
@@ -1612,8 +1612,8 @@ static void getAddend(uint64_t &ToSet, const Elf_Rel_Impl<ELFT, true> &Rela) {
}
template <class T>
-static Error initRelocations(RelocationSection *Relocs,
- SymbolTableSection *SymbolTable, T RelRange) {
+static Error initRelocations(RelocationSection *Relocs,
+ SymbolTableSection *SymbolTable, T RelRange) {
for (const auto &Rel : RelRange) {
Relocation ToAdd;
ToAdd.Offset = Rel.r_offset;
@@ -1622,54 +1622,54 @@ static Error initRelocations(RelocationSection *Relocs,
if (uint32_t Sym = Rel.getSymbol(false)) {
if (!SymbolTable)
- return createStringError(
- errc::invalid_argument,
- "'" + Relocs->Name + "': relocation references symbol with index " +
- Twine(Sym) + ", but there is no symbol table");
- Expected<Symbol *> SymByIndex = SymbolTable->getSymbolByIndex(Sym);
- if (!SymByIndex)
- return SymByIndex.takeError();
-
- ToAdd.RelocSymbol = *SymByIndex;
+ return createStringError(
+ errc::invalid_argument,
+ "'" + Relocs->Name + "': relocation references symbol with index " +
+ Twine(Sym) + ", but there is no symbol table");
+ Expected<Symbol *> SymByIndex = SymbolTable->getSymbolByIndex(Sym);
+ if (!SymByIndex)
+ return SymByIndex.takeError();
+
+ ToAdd.RelocSymbol = *SymByIndex;
}
Relocs->addRelocation(ToAdd);
}
-
- return Error::success();
+
+ return Error::success();
}
-Expected<SectionBase *> SectionTableRef::getSection(uint32_t Index,
- Twine ErrMsg) {
+Expected<SectionBase *> SectionTableRef::getSection(uint32_t Index,
+ Twine ErrMsg) {
if (Index == SHN_UNDEF || Index > Sections.size())
- return createStringError(errc::invalid_argument, ErrMsg);
+ return createStringError(errc::invalid_argument, ErrMsg);
return Sections[Index - 1].get();
}
template <class T>
-Expected<T *> SectionTableRef::getSectionOfType(uint32_t Index,
- Twine IndexErrMsg,
- Twine TypeErrMsg) {
- Expected<SectionBase *> BaseSec = getSection(Index, IndexErrMsg);
- if (!BaseSec)
- return BaseSec.takeError();
-
- if (T *Sec = dyn_cast<T>(*BaseSec))
+Expected<T *> SectionTableRef::getSectionOfType(uint32_t Index,
+ Twine IndexErrMsg,
+ Twine TypeErrMsg) {
+ Expected<SectionBase *> BaseSec = getSection(Index, IndexErrMsg);
+ if (!BaseSec)
+ return BaseSec.takeError();
+
+ if (T *Sec = dyn_cast<T>(*BaseSec))
return Sec;
-
- return createStringError(errc::invalid_argument, TypeErrMsg);
+
+ return createStringError(errc::invalid_argument, TypeErrMsg);
}
template <class ELFT>
-Expected<SectionBase &> ELFBuilder<ELFT>::makeSection(const Elf_Shdr &Shdr) {
+Expected<SectionBase &> ELFBuilder<ELFT>::makeSection(const Elf_Shdr &Shdr) {
switch (Shdr.sh_type) {
case SHT_REL:
case SHT_RELA:
if (Shdr.sh_flags & SHF_ALLOC) {
- if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
- return Obj.addSection<DynamicRelocationSection>(*Data);
- else
- return Data.takeError();
+ if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
+ return Obj.addSection<DynamicRelocationSection>(*Data);
+ else
+ return Data.takeError();
}
return Obj.addSection<RelocationSection>();
case SHT_STRTAB:
@@ -1677,35 +1677,35 @@ Expected<SectionBase &> ELFBuilder<ELFT>::makeSection(const Elf_Shdr &Shdr) {
// mean altering the memory image. There are no special link types or
// anything so we can just use a Section.
if (Shdr.sh_flags & SHF_ALLOC) {
- if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
- return Obj.addSection<Section>(*Data);
- else
- return Data.takeError();
+ if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
+ return Obj.addSection<Section>(*Data);
+ else
+ return Data.takeError();
}
return Obj.addSection<StringTableSection>();
case SHT_HASH:
case SHT_GNU_HASH:
// Hash tables should refer to SHT_DYNSYM which we're not going to change.
// Because of this we don't need to mess with the hash tables either.
- if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
- return Obj.addSection<Section>(*Data);
- else
- return Data.takeError();
+ if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
+ return Obj.addSection<Section>(*Data);
+ else
+ return Data.takeError();
case SHT_GROUP:
- if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
- return Obj.addSection<GroupSection>(*Data);
- else
- return Data.takeError();
+ if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
+ return Obj.addSection<GroupSection>(*Data);
+ else
+ return Data.takeError();
case SHT_DYNSYM:
- if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
- return Obj.addSection<DynamicSymbolTableSection>(*Data);
- else
- return Data.takeError();
+ if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
+ return Obj.addSection<DynamicSymbolTableSection>(*Data);
+ else
+ return Data.takeError();
case SHT_DYNAMIC:
- if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
- return Obj.addSection<DynamicSection>(*Data);
- else
- return Data.takeError();
+ if (Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr))
+ return Obj.addSection<DynamicSection>(*Data);
+ else
+ return Data.takeError();
case SHT_SYMTAB: {
auto &SymTab = Obj.addSection<SymbolTableSection>();
Obj.SymbolTable = &SymTab;
@@ -1717,176 +1717,176 @@ Expected<SectionBase &> ELFBuilder<ELFT>::makeSection(const Elf_Shdr &Shdr) {
return ShndxSection;
}
case SHT_NOBITS:
- return Obj.addSection<Section>(ArrayRef<uint8_t>());
+ return Obj.addSection<Section>(ArrayRef<uint8_t>());
default: {
- Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr);
- if (!Data)
- return Data.takeError();
-
- Expected<StringRef> Name = ElfFile.getSectionName(Shdr);
- if (!Name)
- return Name.takeError();
-
- if (Name->startswith(".zdebug") || (Shdr.sh_flags & ELF::SHF_COMPRESSED)) {
+ Expected<ArrayRef<uint8_t>> Data = ElfFile.getSectionContents(Shdr);
+ if (!Data)
+ return Data.takeError();
+
+ Expected<StringRef> Name = ElfFile.getSectionName(Shdr);
+ if (!Name)
+ return Name.takeError();
+
+ if (Name->startswith(".zdebug") || (Shdr.sh_flags & ELF::SHF_COMPRESSED)) {
uint64_t DecompressedSize, DecompressedAlign;
std::tie(DecompressedSize, DecompressedAlign) =
- getDecompressedSizeAndAlignment<ELFT>(*Data);
- Expected<CompressedSection> NewSection =
- CompressedSection::create(*Data, DecompressedSize, DecompressedAlign);
- if (!NewSection)
- return NewSection.takeError();
-
- return Obj.addSection<CompressedSection>(std::move(*NewSection));
+ getDecompressedSizeAndAlignment<ELFT>(*Data);
+ Expected<CompressedSection> NewSection =
+ CompressedSection::create(*Data, DecompressedSize, DecompressedAlign);
+ if (!NewSection)
+ return NewSection.takeError();
+
+ return Obj.addSection<CompressedSection>(std::move(*NewSection));
}
- return Obj.addSection<Section>(*Data);
+ return Obj.addSection<Section>(*Data);
}
}
}
-template <class ELFT> Error ELFBuilder<ELFT>::readSectionHeaders() {
+template <class ELFT> Error ELFBuilder<ELFT>::readSectionHeaders() {
uint32_t Index = 0;
- Expected<typename ELFFile<ELFT>::Elf_Shdr_Range> Sections =
- ElfFile.sections();
- if (!Sections)
- return Sections.takeError();
-
- for (const typename ELFFile<ELFT>::Elf_Shdr &Shdr : *Sections) {
+ Expected<typename ELFFile<ELFT>::Elf_Shdr_Range> Sections =
+ ElfFile.sections();
+ if (!Sections)
+ return Sections.takeError();
+
+ for (const typename ELFFile<ELFT>::Elf_Shdr &Shdr : *Sections) {
if (Index == 0) {
++Index;
continue;
}
- Expected<SectionBase &> Sec = makeSection(Shdr);
- if (!Sec)
- return Sec.takeError();
-
- Expected<StringRef> SecName = ElfFile.getSectionName(Shdr);
- if (!SecName)
- return SecName.takeError();
- Sec->Name = SecName->str();
- Sec->Type = Sec->OriginalType = Shdr.sh_type;
- Sec->Flags = Sec->OriginalFlags = Shdr.sh_flags;
- Sec->Addr = Shdr.sh_addr;
- Sec->Offset = Shdr.sh_offset;
- Sec->OriginalOffset = Shdr.sh_offset;
- Sec->Size = Shdr.sh_size;
- Sec->Link = Shdr.sh_link;
- Sec->Info = Shdr.sh_info;
- Sec->Align = Shdr.sh_addralign;
- Sec->EntrySize = Shdr.sh_entsize;
- Sec->Index = Index++;
- Sec->OriginalIndex = Sec->Index;
- Sec->OriginalData =
+ Expected<SectionBase &> Sec = makeSection(Shdr);
+ if (!Sec)
+ return Sec.takeError();
+
+ Expected<StringRef> SecName = ElfFile.getSectionName(Shdr);
+ if (!SecName)
+ return SecName.takeError();
+ Sec->Name = SecName->str();
+ Sec->Type = Sec->OriginalType = Shdr.sh_type;
+ Sec->Flags = Sec->OriginalFlags = Shdr.sh_flags;
+ Sec->Addr = Shdr.sh_addr;
+ Sec->Offset = Shdr.sh_offset;
+ Sec->OriginalOffset = Shdr.sh_offset;
+ Sec->Size = Shdr.sh_size;
+ Sec->Link = Shdr.sh_link;
+ Sec->Info = Shdr.sh_info;
+ Sec->Align = Shdr.sh_addralign;
+ Sec->EntrySize = Shdr.sh_entsize;
+ Sec->Index = Index++;
+ Sec->OriginalIndex = Sec->Index;
+ Sec->OriginalData =
ArrayRef<uint8_t>(ElfFile.base() + Shdr.sh_offset,
(Shdr.sh_type == SHT_NOBITS) ? 0 : Shdr.sh_size);
}
-
- return Error::success();
+
+ return Error::success();
}
-template <class ELFT> Error ELFBuilder<ELFT>::readSections(bool EnsureSymtab) {
- uint32_t ShstrIndex = ElfFile.getHeader().e_shstrndx;
- if (ShstrIndex == SHN_XINDEX) {
- Expected<const Elf_Shdr *> Sec = ElfFile.getSection(0);
- if (!Sec)
- return Sec.takeError();
-
- ShstrIndex = (*Sec)->sh_link;
- }
+template <class ELFT> Error ELFBuilder<ELFT>::readSections(bool EnsureSymtab) {
+ uint32_t ShstrIndex = ElfFile.getHeader().e_shstrndx;
+ if (ShstrIndex == SHN_XINDEX) {
+ Expected<const Elf_Shdr *> Sec = ElfFile.getSection(0);
+ if (!Sec)
+ return Sec.takeError();
+ ShstrIndex = (*Sec)->sh_link;
+ }
+
if (ShstrIndex == SHN_UNDEF)
Obj.HadShdrs = false;
- else {
- Expected<StringTableSection *> Sec =
+ else {
+ Expected<StringTableSection *> Sec =
Obj.sections().template getSectionOfType<StringTableSection>(
ShstrIndex,
"e_shstrndx field value " + Twine(ShstrIndex) + " in elf header " +
" is invalid",
"e_shstrndx field value " + Twine(ShstrIndex) + " in elf header " +
" does not reference a string table");
- if (!Sec)
- return Sec.takeError();
-
- Obj.SectionNames = *Sec;
- }
+ if (!Sec)
+ return Sec.takeError();
+ Obj.SectionNames = *Sec;
+ }
+
// If a section index table exists we'll need to initialize it before we
// initialize the symbol table because the symbol table might need to
// reference it.
if (Obj.SectionIndexTable)
- if (Error Err = Obj.SectionIndexTable->initialize(Obj.sections()))
- return Err;
+ if (Error Err = Obj.SectionIndexTable->initialize(Obj.sections()))
+ return Err;
// Now that all of the sections have been added we can fill out some extra
// details about symbol tables. We need the symbol table filled out before
// any relocations.
if (Obj.SymbolTable) {
- if (Error Err = Obj.SymbolTable->initialize(Obj.sections()))
- return Err;
- if (Error Err = initSymbolTable(Obj.SymbolTable))
- return Err;
+ if (Error Err = Obj.SymbolTable->initialize(Obj.sections()))
+ return Err;
+ if (Error Err = initSymbolTable(Obj.SymbolTable))
+ return Err;
} else if (EnsureSymtab) {
- if (Error Err = Obj.addNewSymbolTable())
- return Err;
+ if (Error Err = Obj.addNewSymbolTable())
+ return Err;
}
// Now that all sections and symbols have been added we can add
// relocations that reference symbols and set the link and info fields for
// relocation sections.
- for (SectionBase &Sec : Obj.sections()) {
+ for (SectionBase &Sec : Obj.sections()) {
if (&Sec == Obj.SymbolTable)
continue;
- if (Error Err = Sec.initialize(Obj.sections()))
- return Err;
+ if (Error Err = Sec.initialize(Obj.sections()))
+ return Err;
if (auto RelSec = dyn_cast<RelocationSection>(&Sec)) {
- Expected<typename ELFFile<ELFT>::Elf_Shdr_Range> Sections =
- ElfFile.sections();
- if (!Sections)
- return Sections.takeError();
-
- const typename ELFFile<ELFT>::Elf_Shdr *Shdr =
- Sections->begin() + RelSec->Index;
- if (RelSec->Type == SHT_REL) {
- Expected<typename ELFFile<ELFT>::Elf_Rel_Range> Rels =
- ElfFile.rels(*Shdr);
- if (!Rels)
- return Rels.takeError();
-
- if (Error Err = initRelocations(RelSec, Obj.SymbolTable, *Rels))
- return Err;
- } else {
- Expected<typename ELFFile<ELFT>::Elf_Rela_Range> Relas =
- ElfFile.relas(*Shdr);
- if (!Relas)
- return Relas.takeError();
-
- if (Error Err = initRelocations(RelSec, Obj.SymbolTable, *Relas))
- return Err;
- }
+ Expected<typename ELFFile<ELFT>::Elf_Shdr_Range> Sections =
+ ElfFile.sections();
+ if (!Sections)
+ return Sections.takeError();
+
+ const typename ELFFile<ELFT>::Elf_Shdr *Shdr =
+ Sections->begin() + RelSec->Index;
+ if (RelSec->Type == SHT_REL) {
+ Expected<typename ELFFile<ELFT>::Elf_Rel_Range> Rels =
+ ElfFile.rels(*Shdr);
+ if (!Rels)
+ return Rels.takeError();
+
+ if (Error Err = initRelocations(RelSec, Obj.SymbolTable, *Rels))
+ return Err;
+ } else {
+ Expected<typename ELFFile<ELFT>::Elf_Rela_Range> Relas =
+ ElfFile.relas(*Shdr);
+ if (!Relas)
+ return Relas.takeError();
+
+ if (Error Err = initRelocations(RelSec, Obj.SymbolTable, *Relas))
+ return Err;
+ }
} else if (auto GroupSec = dyn_cast<GroupSection>(&Sec)) {
- if (Error Err = initGroupSection(GroupSec))
- return Err;
+ if (Error Err = initGroupSection(GroupSec))
+ return Err;
}
}
-
- return Error::success();
+
+ return Error::success();
}
-template <class ELFT> Error ELFBuilder<ELFT>::build(bool EnsureSymtab) {
- if (Error E = readSectionHeaders())
- return E;
- if (Error E = findEhdrOffset())
- return E;
+template <class ELFT> Error ELFBuilder<ELFT>::build(bool EnsureSymtab) {
+ if (Error E = readSectionHeaders())
+ return E;
+ if (Error E = findEhdrOffset())
+ return E;
// The ELFFile whose ELF headers and program headers are copied into the
// output file. Normally the same as ElfFile, but if we're extracting a
// loadable partition it will point to the partition's headers.
- Expected<ELFFile<ELFT>> HeadersFile = ELFFile<ELFT>::create(toStringRef(
- {ElfFile.base() + EhdrOffset, ElfFile.getBufSize() - EhdrOffset}));
- if (!HeadersFile)
- return HeadersFile.takeError();
+ Expected<ELFFile<ELFT>> HeadersFile = ELFFile<ELFT>::create(toStringRef(
+ {ElfFile.base() + EhdrOffset, ElfFile.getBufSize() - EhdrOffset}));
+ if (!HeadersFile)
+ return HeadersFile.takeError();
- const typename ELFFile<ELFT>::Elf_Ehdr &Ehdr = HeadersFile->getHeader();
+ const typename ELFFile<ELFT>::Elf_Ehdr &Ehdr = HeadersFile->getHeader();
Obj.OSABI = Ehdr.e_ident[EI_OSABI];
Obj.ABIVersion = Ehdr.e_ident[EI_ABIVERSION];
Obj.Type = Ehdr.e_type;
@@ -1895,17 +1895,17 @@ template <class ELFT> Error ELFBuilder<ELFT>::build(bool EnsureSymtab) {
Obj.Entry = Ehdr.e_entry;
Obj.Flags = Ehdr.e_flags;
- if (Error E = readSections(EnsureSymtab))
- return E;
- return readProgramHeaders(*HeadersFile);
+ if (Error E = readSections(EnsureSymtab))
+ return E;
+ return readProgramHeaders(*HeadersFile);
}
Writer::~Writer() {}
Reader::~Reader() {}
-Expected<std::unique_ptr<Object>>
-BinaryReader::create(bool /*EnsureSymtab*/) const {
+Expected<std::unique_ptr<Object>>
+BinaryReader::create(bool /*EnsureSymtab*/) const {
return BinaryELFBuilder(MemBuf, NewSymbolVisibility).build();
}
@@ -1935,39 +1935,39 @@ Expected<std::vector<IHexRecord>> IHexReader::parse() const {
return std::move(Records);
}
-Expected<std::unique_ptr<Object>>
-IHexReader::create(bool /*EnsureSymtab*/) const {
- Expected<std::vector<IHexRecord>> Records = parse();
- if (!Records)
- return Records.takeError();
-
- return IHexELFBuilder(*Records).build();
+Expected<std::unique_ptr<Object>>
+IHexReader::create(bool /*EnsureSymtab*/) const {
+ Expected<std::vector<IHexRecord>> Records = parse();
+ if (!Records)
+ return Records.takeError();
+
+ return IHexELFBuilder(*Records).build();
}
-Expected<std::unique_ptr<Object>> ELFReader::create(bool EnsureSymtab) const {
+Expected<std::unique_ptr<Object>> ELFReader::create(bool EnsureSymtab) const {
auto Obj = std::make_unique<Object>();
if (auto *O = dyn_cast<ELFObjectFile<ELF32LE>>(Bin)) {
ELFBuilder<ELF32LE> Builder(*O, *Obj, ExtractPartition);
- if (Error Err = Builder.build(EnsureSymtab))
- return std::move(Err);
- return std::move(Obj);
+ if (Error Err = Builder.build(EnsureSymtab))
+ return std::move(Err);
+ return std::move(Obj);
} else if (auto *O = dyn_cast<ELFObjectFile<ELF64LE>>(Bin)) {
ELFBuilder<ELF64LE> Builder(*O, *Obj, ExtractPartition);
- if (Error Err = Builder.build(EnsureSymtab))
- return std::move(Err);
- return std::move(Obj);
+ if (Error Err = Builder.build(EnsureSymtab))
+ return std::move(Err);
+ return std::move(Obj);
} else if (auto *O = dyn_cast<ELFObjectFile<ELF32BE>>(Bin)) {
ELFBuilder<ELF32BE> Builder(*O, *Obj, ExtractPartition);
- if (Error Err = Builder.build(EnsureSymtab))
- return std::move(Err);
- return std::move(Obj);
+ if (Error Err = Builder.build(EnsureSymtab))
+ return std::move(Err);
+ return std::move(Obj);
} else if (auto *O = dyn_cast<ELFObjectFile<ELF64BE>>(Bin)) {
ELFBuilder<ELF64BE> Builder(*O, *Obj, ExtractPartition);
- if (Error Err = Builder.build(EnsureSymtab))
- return std::move(Err);
- return std::move(Obj);
+ if (Error Err = Builder.build(EnsureSymtab))
+ return std::move(Err);
+ return std::move(Obj);
}
- return createStringError(errc::invalid_argument, "invalid file type");
+ return createStringError(errc::invalid_argument, "invalid file type");
}
template <class ELFT> void ELFWriter<ELFT>::writeEhdr() {
@@ -2061,16 +2061,16 @@ template <class ELFT> void ELFWriter<ELFT>::writeShdrs() {
writeShdr(Sec);
}
-template <class ELFT> Error ELFWriter<ELFT>::writeSectionData() {
+template <class ELFT> Error ELFWriter<ELFT>::writeSectionData() {
for (SectionBase &Sec : Obj.sections())
// Segments are responsible for writing their contents, so only write the
// section data if the section is not in a segment. Note that this renders
// sections in segments effectively immutable.
if (Sec.ParentSegment == nullptr)
- if (Error Err = Sec.accept(*SecWriter))
- return Err;
-
- return Error::success();
+ if (Error Err = Sec.accept(*SecWriter))
+ return Err;
+
+ return Error::success();
}
template <class ELFT> void ELFWriter<ELFT>::writeSegmentData() {
@@ -2097,8 +2097,8 @@ ELFWriter<ELFT>::ELFWriter(Object &Obj, Buffer &Buf, bool WSH,
: Writer(Obj, Buf), WriteSectionHeaders(WSH && Obj.HadShdrs),
OnlyKeepDebug(OnlyKeepDebug) {}
-Error Object::removeSections(
- bool AllowBrokenLinks, std::function<bool(const SectionBase &)> ToRemove) {
+Error Object::removeSections(
+ bool AllowBrokenLinks, std::function<bool(const SectionBase &)> ToRemove) {
auto Iter = std::stable_partition(
std::begin(Sections), std::end(Sections), [=](const SecPtr &Sec) {
@@ -2134,8 +2134,8 @@ Error Object::removeSections(
// a live section critically depends on a section being removed somehow
// (e.g. the removed section is referenced by a relocation).
for (auto &KeepSec : make_range(std::begin(Sections), Iter)) {
- if (Error E = KeepSec->removeSectionReferences(
- AllowBrokenLinks, [&RemoveSections](const SectionBase *Sec) {
+ if (Error E = KeepSec->removeSectionReferences(
+ AllowBrokenLinks, [&RemoveSections](const SectionBase *Sec) {
return RemoveSections.find(Sec) != RemoveSections.end();
}))
return E;
@@ -2157,7 +2157,7 @@ Error Object::removeSymbols(function_ref<bool(const Symbol &)> ToRemove) {
return Error::success();
}
-Error Object::addNewSymbolTable() {
+Error Object::addNewSymbolTable() {
assert(!SymbolTable && "Object must not has a SymbolTable.");
// Reuse an existing SHT_STRTAB section if it exists.
@@ -2178,13 +2178,13 @@ Error Object::addNewSymbolTable() {
SymbolTableSection &SymTab = addSection<SymbolTableSection>();
SymTab.Name = ".symtab";
SymTab.Link = StrTab->Index;
- if (Error Err = SymTab.initialize(sections()))
- return Err;
+ if (Error Err = SymTab.initialize(sections()))
+ return Err;
SymTab.addSymbol("", 0, 0, nullptr, 0, 0, 0, 0);
SymbolTable = &SymTab;
-
- return Error::success();
+
+ return Error::success();
}
void Object::sortSections() {
@@ -2305,19 +2305,19 @@ static uint64_t layoutSectionsForOnlyKeepDebug(Object &Obj, uint64_t Off) {
return Off;
}
-// Rewrite p_offset and p_filesz of non-PT_PHDR segments after sh_offset values
-// have been updated.
+// Rewrite p_offset and p_filesz of non-PT_PHDR segments after sh_offset values
+// have been updated.
static uint64_t layoutSegmentsForOnlyKeepDebug(std::vector<Segment *> &Segments,
uint64_t HdrEnd) {
uint64_t MaxOffset = 0;
for (Segment *Seg : Segments) {
- // An empty segment contains no section (see sectionWithinSegment). If it
- // has a parent segment, copy the parent segment's offset field. This works
- // for empty PT_TLS. We don't handle empty segments without a parent for
- // now.
- if (Seg->ParentSegment != nullptr && Seg->MemSize == 0)
- Seg->Offset = Seg->ParentSegment->Offset;
-
+ // An empty segment contains no section (see sectionWithinSegment). If it
+ // has a parent segment, copy the parent segment's offset field. This works
+ // for empty PT_TLS. We don't handle empty segments without a parent for
+ // now.
+ if (Seg->ParentSegment != nullptr && Seg->MemSize == 0)
+ Seg->Offset = Seg->ParentSegment->Offset;
+
const SectionBase *FirstSec = Seg->firstSection();
if (Seg->Type == PT_PHDR || !FirstSec)
continue;
@@ -2405,8 +2405,8 @@ template <class ELFT> Error ELFWriter<ELFT>::write() {
writeSegmentData();
writeEhdr();
writePhdrs();
- if (Error E = writeSectionData())
- return E;
+ if (Error E = writeSectionData())
+ return E;
if (WriteSectionHeaders)
writeShdrs();
return Buf.commit();
@@ -2451,8 +2451,8 @@ template <class ELFT> Error ELFWriter<ELFT>::finalize() {
if (Obj.sections().size() >= SHN_LORESERVE) {
SectionTableRef Sections = Obj.sections();
NeedsLargeIndexes =
- any_of(drop_begin(Sections, SHN_LORESERVE),
- [](const SectionBase &Sec) { return Sec.HasSymbol; });
+ any_of(drop_begin(Sections, SHN_LORESERVE),
+ [](const SectionBase &Sec) { return Sec.HasSymbol; });
// TODO: handle case where only one section needs the large index table but
// only needs it because the large index table hasn't been removed yet.
}
@@ -2495,8 +2495,8 @@ template <class ELFT> Error ELFWriter<ELFT>::finalize() {
auto SecSizer = std::make_unique<ELFSectionSizer<ELFT>>();
for (SectionBase &Sec : Obj.sections()) {
Sec.Index = Index++;
- if (Error Err = Sec.accept(*SecSizer))
- return Err;
+ if (Error Err = Sec.accept(*SecSizer))
+ return Err;
}
// The symbol table does not update all other sections on update. For
@@ -2537,9 +2537,9 @@ template <class ELFT> Error ELFWriter<ELFT>::finalize() {
Error BinaryWriter::write() {
for (const SectionBase &Sec : Obj.allocSections())
- if (Error Err = Sec.accept(*SecWriter))
- return Err;
-
+ if (Error Err = Sec.accept(*SecWriter))
+ return Err;
+
return Buf.commit();
}
@@ -2611,8 +2611,8 @@ Error IHexWriter::write() {
IHexSectionWriter Writer(Buf);
// Write sections.
for (const SectionBase *Sec : Sections)
- if (Error Err = Sec->accept(Writer))
- return Err;
+ if (Error Err = Sec->accept(Writer))
+ return Err;
uint64_t Offset = Writer.getBufferOffset();
// Write entry point address.
@@ -2628,8 +2628,8 @@ Error IHexWriter::checkSection(const SectionBase &Sec) {
if (addressOverflows32bit(Addr) || addressOverflows32bit(Addr + Sec.Size - 1))
return createStringError(
errc::invalid_argument,
- "Section '%s' address range [0x%llx, 0x%llx] is not 32 bit",
- Sec.Name.c_str(), Addr, Addr + Sec.Size - 1);
+ "Section '%s' address range [0x%llx, 0x%llx] is not 32 bit",
+ Sec.Name.c_str(), Addr, Addr + Sec.Size - 1);
return Error::success();
}
@@ -2666,8 +2666,8 @@ Error IHexWriter::finalize() {
IHexSectionWriterBase LengthCalc(Buf);
for (const SectionBase *Sec : Sections)
- if (Error Err = Sec->accept(LengthCalc))
- return Err;
+ if (Error Err = Sec->accept(LengthCalc))
+ return Err;
// We need space to write section records + StartAddress record
// (if start adress is not zero) + EndOfFile record.
diff --git a/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.h b/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.h
index 0205c2d4f3..01caa5d42a 100644
--- a/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.h
+++ b/contrib/libs/llvm12/tools/llvm-objcopy/ELF/Object.h
@@ -61,11 +61,11 @@ public:
iterator end() const { return iterator(Sections.data() + Sections.size()); }
size_t size() const { return Sections.size(); }
- Expected<SectionBase *> getSection(uint32_t Index, Twine ErrMsg);
+ Expected<SectionBase *> getSection(uint32_t Index, Twine ErrMsg);
template <class T>
- Expected<T *> getSectionOfType(uint32_t Index, Twine IndexErrMsg,
- Twine TypeErrMsg);
+ Expected<T *> getSectionOfType(uint32_t Index, Twine IndexErrMsg,
+ Twine TypeErrMsg);
};
enum ElfType { ELFT_ELF32LE, ELFT_ELF64LE, ELFT_ELF32BE, ELFT_ELF64BE };
@@ -74,34 +74,34 @@ class SectionVisitor {
public:
virtual ~SectionVisitor() = default;
- virtual Error visit(const Section &Sec) = 0;
- virtual Error visit(const OwnedDataSection &Sec) = 0;
- virtual Error visit(const StringTableSection &Sec) = 0;
- virtual Error visit(const SymbolTableSection &Sec) = 0;
- virtual Error visit(const RelocationSection &Sec) = 0;
- virtual Error visit(const DynamicRelocationSection &Sec) = 0;
- virtual Error visit(const GnuDebugLinkSection &Sec) = 0;
- virtual Error visit(const GroupSection &Sec) = 0;
- virtual Error visit(const SectionIndexSection &Sec) = 0;
- virtual Error visit(const CompressedSection &Sec) = 0;
- virtual Error visit(const DecompressedSection &Sec) = 0;
+ virtual Error visit(const Section &Sec) = 0;
+ virtual Error visit(const OwnedDataSection &Sec) = 0;
+ virtual Error visit(const StringTableSection &Sec) = 0;
+ virtual Error visit(const SymbolTableSection &Sec) = 0;
+ virtual Error visit(const RelocationSection &Sec) = 0;
+ virtual Error visit(const DynamicRelocationSection &Sec) = 0;
+ virtual Error visit(const GnuDebugLinkSection &Sec) = 0;
+ virtual Error visit(const GroupSection &Sec) = 0;
+ virtual Error visit(const SectionIndexSection &Sec) = 0;
+ virtual Error visit(const CompressedSection &Sec) = 0;
+ virtual Error visit(const DecompressedSection &Sec) = 0;
};
class MutableSectionVisitor {
public:
virtual ~MutableSectionVisitor() = default;
- virtual Error visit(Section &Sec) = 0;
- virtual Error visit(OwnedDataSection &Sec) = 0;
- virtual Error visit(StringTableSection &Sec) = 0;
- virtual Error visit(SymbolTableSection &Sec) = 0;
- virtual Error visit(RelocationSection &Sec) = 0;
- virtual Error visit(DynamicRelocationSection &Sec) = 0;
- virtual Error visit(GnuDebugLinkSection &Sec) = 0;
- virtual Error visit(GroupSection &Sec) = 0;
- virtual Error visit(SectionIndexSection &Sec) = 0;
- virtual Error visit(CompressedSection &Sec) = 0;
- virtual Error visit(DecompressedSection &Sec) = 0;
+ virtual Error visit(Section &Sec) = 0;
+ virtual Error visit(OwnedDataSection &Sec) = 0;
+ virtual Error visit(StringTableSection &Sec) = 0;
+ virtual Error visit(SymbolTableSection &Sec) = 0;
+ virtual Error visit(RelocationSection &Sec) = 0;
+ virtual Error visit(DynamicRelocationSection &Sec) = 0;
+ virtual Error visit(GnuDebugLinkSection &Sec) = 0;
+ virtual Error visit(GroupSection &Sec) = 0;
+ virtual Error visit(SectionIndexSection &Sec) = 0;
+ virtual Error visit(CompressedSection &Sec) = 0;
+ virtual Error visit(DecompressedSection &Sec) = 0;
};
class SectionWriter : public SectionVisitor {
@@ -111,17 +111,17 @@ protected:
public:
virtual ~SectionWriter() = default;
- Error visit(const Section &Sec) override;
- Error visit(const OwnedDataSection &Sec) override;
- Error visit(const StringTableSection &Sec) override;
- Error visit(const DynamicRelocationSection &Sec) override;
- virtual Error visit(const SymbolTableSection &Sec) override = 0;
- virtual Error visit(const RelocationSection &Sec) override = 0;
- virtual Error visit(const GnuDebugLinkSection &Sec) override = 0;
- virtual Error visit(const GroupSection &Sec) override = 0;
- virtual Error visit(const SectionIndexSection &Sec) override = 0;
- virtual Error visit(const CompressedSection &Sec) override = 0;
- virtual Error visit(const DecompressedSection &Sec) override = 0;
+ Error visit(const Section &Sec) override;
+ Error visit(const OwnedDataSection &Sec) override;
+ Error visit(const StringTableSection &Sec) override;
+ Error visit(const DynamicRelocationSection &Sec) override;
+ virtual Error visit(const SymbolTableSection &Sec) override = 0;
+ virtual Error visit(const RelocationSection &Sec) override = 0;
+ virtual Error visit(const GnuDebugLinkSection &Sec) override = 0;
+ virtual Error visit(const GroupSection &Sec) override = 0;
+ virtual Error visit(const SectionIndexSection &Sec) override = 0;
+ virtual Error visit(const CompressedSection &Sec) override = 0;
+ virtual Error visit(const DecompressedSection &Sec) override = 0;
explicit SectionWriter(Buffer &Buf) : Out(Buf) {}
};
@@ -135,13 +135,13 @@ private:
public:
virtual ~ELFSectionWriter() {}
- Error visit(const SymbolTableSection &Sec) override;
- Error visit(const RelocationSection &Sec) override;
- Error visit(const GnuDebugLinkSection &Sec) override;
- Error visit(const GroupSection &Sec) override;
- Error visit(const SectionIndexSection &Sec) override;
- Error visit(const CompressedSection &Sec) override;
- Error visit(const DecompressedSection &Sec) override;
+ Error visit(const SymbolTableSection &Sec) override;
+ Error visit(const RelocationSection &Sec) override;
+ Error visit(const GnuDebugLinkSection &Sec) override;
+ Error visit(const GroupSection &Sec) override;
+ Error visit(const SectionIndexSection &Sec) override;
+ Error visit(const CompressedSection &Sec) override;
+ Error visit(const DecompressedSection &Sec) override;
explicit ELFSectionWriter(Buffer &Buf) : SectionWriter(Buf) {}
};
@@ -155,17 +155,17 @@ private:
using Elf_Xword = typename ELFT::Xword;
public:
- Error visit(Section &Sec) override;
- Error visit(OwnedDataSection &Sec) override;
- Error visit(StringTableSection &Sec) override;
- Error visit(DynamicRelocationSection &Sec) override;
- Error visit(SymbolTableSection &Sec) override;
- Error visit(RelocationSection &Sec) override;
- Error visit(GnuDebugLinkSection &Sec) override;
- Error visit(GroupSection &Sec) override;
- Error visit(SectionIndexSection &Sec) override;
- Error visit(CompressedSection &Sec) override;
- Error visit(DecompressedSection &Sec) override;
+ Error visit(Section &Sec) override;
+ Error visit(OwnedDataSection &Sec) override;
+ Error visit(StringTableSection &Sec) override;
+ Error visit(DynamicRelocationSection &Sec) override;
+ Error visit(SymbolTableSection &Sec) override;
+ Error visit(RelocationSection &Sec) override;
+ Error visit(GnuDebugLinkSection &Sec) override;
+ Error visit(GroupSection &Sec) override;
+ Error visit(SectionIndexSection &Sec) override;
+ Error visit(CompressedSection &Sec) override;
+ Error visit(DecompressedSection &Sec) override;
};
#define MAKE_SEC_WRITER_FRIEND \
@@ -179,13 +179,13 @@ class BinarySectionWriter : public SectionWriter {
public:
virtual ~BinarySectionWriter() {}
- Error visit(const SymbolTableSection &Sec) override;
- Error visit(const RelocationSection &Sec) override;
- Error visit(const GnuDebugLinkSection &Sec) override;
- Error visit(const GroupSection &Sec) override;
- Error visit(const SectionIndexSection &Sec) override;
- Error visit(const CompressedSection &Sec) override;
- Error visit(const DecompressedSection &Sec) override;
+ Error visit(const SymbolTableSection &Sec) override;
+ Error visit(const RelocationSection &Sec) override;
+ Error visit(const GnuDebugLinkSection &Sec) override;
+ Error visit(const GroupSection &Sec) override;
+ Error visit(const SectionIndexSection &Sec) override;
+ Error visit(const CompressedSection &Sec) override;
+ Error visit(const DecompressedSection &Sec) override;
explicit BinarySectionWriter(Buffer &Buf) : SectionWriter(Buf) {}
};
@@ -286,10 +286,10 @@ public:
explicit IHexSectionWriterBase(Buffer &Buf) : BinarySectionWriter(Buf) {}
uint64_t getBufferOffset() const { return Offset; }
- Error visit(const Section &Sec) final;
- Error visit(const OwnedDataSection &Sec) final;
- Error visit(const StringTableSection &Sec) override;
- Error visit(const DynamicRelocationSection &Sec) final;
+ Error visit(const Section &Sec) final;
+ Error visit(const OwnedDataSection &Sec) final;
+ Error visit(const StringTableSection &Sec) override;
+ Error visit(const DynamicRelocationSection &Sec) final;
using BinarySectionWriter::visit;
};
@@ -299,7 +299,7 @@ public:
IHexSectionWriter(Buffer &Buf) : IHexSectionWriterBase(Buf) {}
void writeData(uint8_t Type, uint16_t Addr, ArrayRef<uint8_t> Data) override;
- Error visit(const StringTableSection &Sec) override;
+ Error visit(const StringTableSection &Sec) override;
};
class Writer {
@@ -330,7 +330,7 @@ private:
void writePhdrs();
void writeShdrs();
- Error writeSectionData();
+ Error writeSectionData();
void writeSegmentData();
void assignOffsets();
@@ -391,7 +391,7 @@ public:
uint64_t HeaderOffset = 0;
uint32_t Index = 0;
- uint32_t OriginalIndex = 0;
+ uint32_t OriginalIndex = 0;
uint64_t OriginalFlags = 0;
uint64_t OriginalType = ELF::SHT_NULL;
uint64_t OriginalOffset = std::numeric_limits<uint64_t>::max();
@@ -407,22 +407,22 @@ public:
uint64_t Size = 0;
uint64_t Type = ELF::SHT_NULL;
ArrayRef<uint8_t> OriginalData;
- bool HasSymbol = false;
+ bool HasSymbol = false;
SectionBase() = default;
SectionBase(const SectionBase &) = default;
virtual ~SectionBase() = default;
- virtual Error initialize(SectionTableRef SecTable);
+ virtual Error initialize(SectionTableRef SecTable);
virtual void finalize();
// Remove references to these sections. The list of sections must be sorted.
virtual Error
removeSectionReferences(bool AllowBrokenLinks,
function_ref<bool(const SectionBase *)> ToRemove);
virtual Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove);
- virtual Error accept(SectionVisitor &Visitor) const = 0;
- virtual Error accept(MutableSectionVisitor &Visitor) = 0;
+ virtual Error accept(SectionVisitor &Visitor) const = 0;
+ virtual Error accept(MutableSectionVisitor &Visitor) = 0;
virtual void markSymbols();
virtual void
replaceSectionReferences(const DenseMap<SectionBase *, SectionBase *> &);
@@ -436,9 +436,9 @@ private:
bool operator()(const SectionBase *Lhs, const SectionBase *Rhs) const {
// Some sections might have the same address if one of them is empty. To
// fix this we can use the lexicographic ordering on ->Addr and the
- // original index.
+ // original index.
if (Lhs->OriginalOffset == Rhs->OriginalOffset)
- return Lhs->OriginalIndex < Rhs->OriginalIndex;
+ return Lhs->OriginalIndex < Rhs->OriginalIndex;
return Lhs->OriginalOffset < Rhs->OriginalOffset;
}
};
@@ -483,12 +483,12 @@ class Section : public SectionBase {
public:
explicit Section(ArrayRef<uint8_t> Data) : Contents(Data) {}
- Error accept(SectionVisitor &Visitor) const override;
- Error accept(MutableSectionVisitor &Visitor) override;
- Error removeSectionReferences(
- bool AllowBrokenLinks,
+ Error accept(SectionVisitor &Visitor) const override;
+ Error accept(MutableSectionVisitor &Visitor) override;
+ Error removeSectionReferences(
+ bool AllowBrokenLinks,
function_ref<bool(const SectionBase *)> ToRemove) override;
- Error initialize(SectionTableRef SecTable) override;
+ Error initialize(SectionTableRef SecTable) override;
void finalize() override;
};
@@ -516,8 +516,8 @@ public:
}
void appendHexData(StringRef HexData);
- Error accept(SectionVisitor &Sec) const override;
- Error accept(MutableSectionVisitor &Visitor) override;
+ Error accept(SectionVisitor &Sec) const override;
+ Error accept(MutableSectionVisitor &Visitor) override;
};
class CompressedSection : public SectionBase {
@@ -529,28 +529,28 @@ class CompressedSection : public SectionBase {
SmallVector<char, 128> CompressedData;
public:
- static Expected<CompressedSection>
- create(const SectionBase &Sec, DebugCompressionType CompressionType);
- static Expected<CompressedSection> create(ArrayRef<uint8_t> CompressedData,
- uint64_t DecompressedSize,
- uint64_t DecompressedAlign);
+ static Expected<CompressedSection>
+ create(const SectionBase &Sec, DebugCompressionType CompressionType);
+ static Expected<CompressedSection> create(ArrayRef<uint8_t> CompressedData,
+ uint64_t DecompressedSize,
+ uint64_t DecompressedAlign);
uint64_t getDecompressedSize() const { return DecompressedSize; }
uint64_t getDecompressedAlign() const { return DecompressedAlign; }
- Error accept(SectionVisitor &Visitor) const override;
- Error accept(MutableSectionVisitor &Visitor) override;
+ Error accept(SectionVisitor &Visitor) const override;
+ Error accept(MutableSectionVisitor &Visitor) override;
static bool classof(const SectionBase *S) {
return (S->OriginalFlags & ELF::SHF_COMPRESSED) ||
(StringRef(S->Name).startswith(".zdebug"));
}
-
-private:
- CompressedSection(const SectionBase &Sec,
- DebugCompressionType CompressionType, Error &Err);
- CompressedSection(ArrayRef<uint8_t> CompressedData, uint64_t DecompressedSize,
- uint64_t DecompressedAlign);
+
+private:
+ CompressedSection(const SectionBase &Sec,
+ DebugCompressionType CompressionType, Error &Err);
+ CompressedSection(ArrayRef<uint8_t> CompressedData, uint64_t DecompressedSize,
+ uint64_t DecompressedAlign);
};
class DecompressedSection : public SectionBase {
@@ -566,8 +566,8 @@ public:
Name = "." + Name.substr(2);
}
- Error accept(SectionVisitor &Visitor) const override;
- Error accept(MutableSectionVisitor &Visitor) override;
+ Error accept(SectionVisitor &Visitor) const override;
+ Error accept(MutableSectionVisitor &Visitor) override;
};
// There are two types of string tables that can exist, dynamic and not dynamic.
@@ -591,8 +591,8 @@ public:
void addString(StringRef Name);
uint32_t findIndex(StringRef Name) const;
void prepareForLayout();
- Error accept(SectionVisitor &Visitor) const override;
- Error accept(MutableSectionVisitor &Visitor) override;
+ Error accept(SectionVisitor &Visitor) const override;
+ Error accept(MutableSectionVisitor &Visitor) override;
static bool classof(const SectionBase *S) {
if (S->OriginalFlags & ELF::SHF_ALLOC)
@@ -649,18 +649,18 @@ public:
virtual ~SectionIndexSection() {}
void addIndex(uint32_t Index) {
assert(Size > 0);
- Indexes.push_back(Index);
+ Indexes.push_back(Index);
}
void reserve(size_t NumSymbols) {
Indexes.reserve(NumSymbols);
Size = NumSymbols * 4;
- }
+ }
void setSymTab(SymbolTableSection *SymTab) { Symbols = SymTab; }
- Error initialize(SectionTableRef SecTable) override;
+ Error initialize(SectionTableRef SecTable) override;
void finalize() override;
- Error accept(SectionVisitor &Visitor) const override;
- Error accept(MutableSectionVisitor &Visitor) override;
+ Error accept(SectionVisitor &Visitor) const override;
+ Error accept(MutableSectionVisitor &Visitor) override;
SectionIndexSection() {
Name = ".symtab_shndx";
@@ -698,17 +698,17 @@ public:
const SectionIndexSection *getShndxTable() const { return SectionIndexTable; }
void fillShndxTable();
const SectionBase *getStrTab() const { return SymbolNames; }
- Expected<const Symbol *> getSymbolByIndex(uint32_t Index) const;
- Expected<Symbol *> getSymbolByIndex(uint32_t Index);
+ Expected<const Symbol *> getSymbolByIndex(uint32_t Index) const;
+ Expected<Symbol *> getSymbolByIndex(uint32_t Index);
void updateSymbols(function_ref<void(Symbol &)> Callable);
- Error removeSectionReferences(
- bool AllowBrokenLinks,
+ Error removeSectionReferences(
+ bool AllowBrokenLinks,
function_ref<bool(const SectionBase *)> ToRemove) override;
- Error initialize(SectionTableRef SecTable) override;
+ Error initialize(SectionTableRef SecTable) override;
void finalize() override;
- Error accept(SectionVisitor &Visitor) const override;
- Error accept(MutableSectionVisitor &Visitor) override;
+ Error accept(SectionVisitor &Visitor) const override;
+ Error accept(MutableSectionVisitor &Visitor) override;
Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove) override;
void replaceSectionReferences(
const DenseMap<SectionBase *, SectionBase *> &FromTo) override;
@@ -759,7 +759,7 @@ protected:
SymTabType *Symbols = nullptr;
public:
- Error initialize(SectionTableRef SecTable) override;
+ Error initialize(SectionTableRef SecTable) override;
void finalize() override;
};
@@ -771,10 +771,10 @@ class RelocationSection
public:
void addRelocation(Relocation Rel) { Relocations.push_back(Rel); }
- Error accept(SectionVisitor &Visitor) const override;
- Error accept(MutableSectionVisitor &Visitor) override;
- Error removeSectionReferences(
- bool AllowBrokenLinks,
+ Error accept(SectionVisitor &Visitor) const override;
+ Error accept(MutableSectionVisitor &Visitor) override;
+ Error removeSectionReferences(
+ bool AllowBrokenLinks,
function_ref<bool(const SectionBase *)> ToRemove) override;
Error removeSymbols(function_ref<bool(const Symbol &)> ToRemove) override;
void markSymbols() override;
@@ -810,8 +810,8 @@ public:
void setFlagWord(ELF::Elf32_Word W) { FlagWord = W; }
void addMember(SectionBase *Sec) { GroupMembers.push_back(Sec); }
- Error accept(SectionVisitor &) const override;
- Error accept(MutableSectionVisitor &Visitor) override;
+ Error accept(SectionVisitor &) const override;
+ Error accept(MutableSectionVisitor &Visitor) override;
void finalize() override;
Error removeSectionReferences(
bool AllowBrokenLinks,
@@ -855,8 +855,8 @@ private:
public:
explicit DynamicRelocationSection(ArrayRef<uint8_t> Data) : Contents(Data) {}
- Error accept(SectionVisitor &) const override;
- Error accept(MutableSectionVisitor &Visitor) override;
+ Error accept(SectionVisitor &) const override;
+ Error accept(MutableSectionVisitor &Visitor) override;
Error removeSectionReferences(
bool AllowBrokenLinks,
function_ref<bool(const SectionBase *)> ToRemove) override;
@@ -880,14 +880,14 @@ private:
public:
// If we add this section from an external source we can use this ctor.
explicit GnuDebugLinkSection(StringRef File, uint32_t PrecomputedCRC);
- Error accept(SectionVisitor &Visitor) const override;
- Error accept(MutableSectionVisitor &Visitor) override;
+ Error accept(SectionVisitor &Visitor) const override;
+ Error accept(MutableSectionVisitor &Visitor) override;
};
class Reader {
public:
virtual ~Reader();
- virtual Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const = 0;
+ virtual Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const = 0;
};
using object::Binary;
@@ -903,7 +903,7 @@ protected:
void initHeaderSegment();
StringTableSection *addStrTab();
SymbolTableSection *addSymTab(StringTableSection *StrTab);
- Error initSections();
+ Error initSections();
public:
BasicELFBuilder() : Obj(std::make_unique<Object>()) {}
@@ -919,7 +919,7 @@ public:
: BasicELFBuilder(), MemBuf(MB),
NewSymbolVisibility(NewSymbolVisibility) {}
- Expected<std::unique_ptr<Object>> build();
+ Expected<std::unique_ptr<Object>> build();
};
class IHexELFBuilder : public BasicELFBuilder {
@@ -931,7 +931,7 @@ public:
IHexELFBuilder(const std::vector<IHexRecord> &Records)
: BasicELFBuilder(), Records(Records) {}
- Expected<std::unique_ptr<Object>> build();
+ Expected<std::unique_ptr<Object>> build();
};
template <class ELFT> class ELFBuilder {
@@ -946,21 +946,21 @@ private:
Optional<StringRef> ExtractPartition;
void setParentSegment(Segment &Child);
- Error readProgramHeaders(const ELFFile<ELFT> &HeadersFile);
- Error initGroupSection(GroupSection *GroupSec);
- Error initSymbolTable(SymbolTableSection *SymTab);
- Error readSectionHeaders();
- Error readSections(bool EnsureSymtab);
- Error findEhdrOffset();
- Expected<SectionBase &> makeSection(const Elf_Shdr &Shdr);
+ Error readProgramHeaders(const ELFFile<ELFT> &HeadersFile);
+ Error initGroupSection(GroupSection *GroupSec);
+ Error initSymbolTable(SymbolTableSection *SymTab);
+ Error readSectionHeaders();
+ Error readSections(bool EnsureSymtab);
+ Error findEhdrOffset();
+ Expected<SectionBase &> makeSection(const Elf_Shdr &Shdr);
public:
ELFBuilder(const ELFObjectFile<ELFT> &ElfObj, Object &Obj,
Optional<StringRef> ExtractPartition)
- : ElfFile(ElfObj.getELFFile()), Obj(Obj),
+ : ElfFile(ElfObj.getELFFile()), Obj(Obj),
ExtractPartition(ExtractPartition) {}
- Error build(bool EnsureSymtab);
+ Error build(bool EnsureSymtab);
};
class BinaryReader : public Reader {
@@ -970,7 +970,7 @@ class BinaryReader : public Reader {
public:
BinaryReader(MemoryBuffer *MB, const uint8_t NewSymbolVisibility)
: MemBuf(MB), NewSymbolVisibility(NewSymbolVisibility) {}
- Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
+ Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
};
class IHexReader : public Reader {
@@ -992,7 +992,7 @@ class IHexReader : public Reader {
public:
IHexReader(MemoryBuffer *MB) : MemBuf(MB) {}
- Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
+ Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
};
class ELFReader : public Reader {
@@ -1000,7 +1000,7 @@ class ELFReader : public Reader {
Optional<StringRef> ExtractPartition;
public:
- Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
+ Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
explicit ELFReader(Binary *B, Optional<StringRef> ExtractPartition)
: Bin(B), ExtractPartition(ExtractPartition) {}
};
@@ -1084,7 +1084,7 @@ public:
Ptr->Index = Sections.size();
return *Ptr;
}
- Error addNewSymbolTable();
+ Error addNewSymbolTable();
Segment &addSegment(ArrayRef<uint8_t> Data) {
Segments.emplace_back(std::make_unique<Segment>(Data));
return *Segments.back();