15using namespace object;
17Error XCOFFReader::readSections(Object &Obj)
const {
18 ArrayRef<XCOFFSectionHeader32> Sections = XCOFFObj.
sections32();
19 for (
const XCOFFSectionHeader32 &Sec : Sections) {
22 ReadSec.SectionHeader = Sec;
23 DataRefImpl SectionDRI;
24 SectionDRI.p =
reinterpret_cast<uintptr_t
>(&Sec);
27 if (Sec.SectionSize) {
28 Expected<ArrayRef<uint8_t>> ContentsRef =
31 return ContentsRef.takeError();
32 ReadSec.Contents = ContentsRef.get();
36 if (Sec.NumberOfRelocations) {
38 XCOFFObj.
relocations<XCOFFSectionHeader32, XCOFFRelocation32>(Sec);
40 return Relocations.takeError();
41 for (
const XCOFFRelocation32 &Rel : Relocations.get())
42 ReadSec.Relocations.push_back(Rel);
45 Obj.Sections.push_back(std::move(ReadSec));
50Error XCOFFReader::readSymbols(Object &Obj)
const {
51 std::vector<Symbol> Symbols;
55 DataRefImpl SymbolDRI =
Sym.getRawDataRefImpl();
56 XCOFFSymbolRef SymbolEntRef = XCOFFObj.
toSymbolRef(SymbolDRI);
59 if (SymbolEntRef.getNumberOfAuxEntries()) {
60 const char *Start =
reinterpret_cast<const char *
>(
62 Expected<StringRef> RawAuxEntriesOrError = XCOFFObj.
getRawData(
66 if (!RawAuxEntriesOrError)
67 return RawAuxEntriesOrError.takeError();
68 ReadSym.AuxSymbolEntries = RawAuxEntriesOrError.get();
70 Obj.Symbols.push_back(std::move(ReadSym));
76 auto Obj = std::make_unique<Object>();
80 "64-bit XCOFF is not supported yet");
88 if (
Error E = readSections(*Obj))
92 if (
Error E = readSymbols(*Obj))
96 return std::move(Obj);
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Expected< std::unique_ptr< Object > > create() const
const XCOFFAuxiliaryHeader32 * auxiliaryHeader32() const
ArrayRef< XCOFFSectionHeader32 > sections32() const
uint32_t getNumberOfSymbolTableEntries() const
const XCOFFFileHeader32 * fileHeader32() const
int32_t getRawNumberOfSymbolTableEntries32() const
uint16_t getOptionalHeaderSize() const
XCOFFSymbolRef toSymbolRef(DataRefImpl Ref) const
uint16_t getNumberOfSections() const
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
bool is64Bit() const override
Expected< StringRef > getRawData(const char *Start, uint64_t Size, StringRef Name) const
Expected< ArrayRef< Reloc > > relocations(const Shdr &Sec) const
xcoff_symbol_iterator_range symbols() const
StringRef getStringTable() const
const XCOFFSymbolEntry32 * getSymbol32() const
constexpr size_t SymbolTableEntrySize
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.