diff --git a/llvm/test/tools/obj2yaml/XCOFF/Inputs/aix_xcoff.o b/llvm/test/tools/obj2yaml/XCOFF/Inputs/aix_xcoff.o deleted file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ Error dumpSections(ArrayRef Sections); public: XCOFFDumper(const object::XCOFFObjectFile &obj) : Obj(obj) {} - std::error_code dump(); + Error dump(); XCOFFYAML::Object &getYAMLObj() { return YAMLObj; } }; } // namespace -std::error_code XCOFFDumper::dump() { +Error XCOFFDumper::dump() { dumpHeader(); + if (Error E = dumpSections()) + return E; return dumpSymbols(); } @@ -50,7 +55,59 @@ YAMLObj.Header.Flags = Obj.getFlags(); } -std::error_code XCOFFDumper::dumpSymbols() { +Error XCOFFDumper::dumpSections() { + if (Obj.is64Bit()) + return createStringError(object_error::invalid_file_type, + "64-bit XCOFF not supported yet"); + return dumpSections(Obj.sections32()); +} + +template Error XCOFFDumper::dumpSections(ArrayRef Sections) { + std::vector &YamlSections = YAMLObj.Sections; + for (const T &S : Sections) { + XCOFFYAML::Section YamlSec; + YamlSec.SectionName = S.getName(); + YamlSec.Address = S.PhysicalAddress; + YamlSec.Size = S.SectionSize; + YamlSec.NumberOfRelocations = S.NumberOfRelocations; + YamlSec.NumberOfLineNumbers = S.NumberOfLineNumbers; + YamlSec.FileOffsetToData = S.FileOffsetToRawData; + YamlSec.FileOffsetToRelocations = S.FileOffsetToRelocationInfo; + YamlSec.FileOffsetToLineNumbers = S.FileOffsetToLineNumberInfo; + YamlSec.Flags = S.Flags; + + // Dump section data. + if (S.FileOffsetToRawData) { + DataRefImpl SectionDRI; + SectionDRI.p = reinterpret_cast(&S); + Expected> SecDataRefOrErr = + Obj.getSectionContents(SectionDRI); + if (!SecDataRefOrErr) + return SecDataRefOrErr.takeError(); + YamlSec.SectionData = SecDataRefOrErr.get(); + } + + // Dump relocations. + if (S.NumberOfRelocations) { + auto RelRefOrErr = + Obj.relocations(S); + if (!RelRefOrErr) + return RelRefOrErr.takeError(); + for (XCOFFRelocation32 Rel : RelRefOrErr.get()) { + XCOFFYAML::Relocation YamlRel; + YamlRel.Type = Rel.Type; + YamlRel.Info = Rel.Info; + YamlRel.SymbolIndex = Rel.SymbolIndex; + YamlRel.VirtualAddress = Rel.VirtualAddress; + YamlSec.Relocations.push_back(YamlRel); + } + } + YamlSections.push_back(YamlSec); + } + return Error::success(); +} + +Error XCOFFDumper::dumpSymbols() { std::vector &Symbols = YAMLObj.Symbols; for (const SymbolRef &S : Obj.symbols()) { @@ -60,7 +117,7 @@ Expected SymNameRefOrErr = Obj.getSymbolName(SymbolDRI); if (!SymNameRefOrErr) { - return errorToErrorCode(SymNameRefOrErr.takeError()); + return SymNameRefOrErr.takeError(); } Sym.SymbolName = SymNameRefOrErr.get(); @@ -69,7 +126,7 @@ Expected SectionNameRefOrErr = Obj.getSymbolSectionName(SymbolEntRef); if (!SectionNameRefOrErr) - return errorToErrorCode(SectionNameRefOrErr.takeError()); + return SectionNameRefOrErr.takeError(); Sym.SectionName = SectionNameRefOrErr.get(); @@ -79,15 +136,15 @@ Symbols.push_back(Sym); } - return std::error_code(); + return Error::success(); } std::error_code xcoff2yaml(raw_ostream &Out, const object::XCOFFObjectFile &Obj) { XCOFFDumper Dumper(Obj); - if (std::error_code EC = Dumper.dump()) - return EC; + if (Error E = Dumper.dump()) + return errorToErrorCode(std::move(E)); yaml::Output Yout(Out); Yout << Dumper.getYAMLObj();