[llvm] [XCOFF][obj2yaml] support parsing auxiliary symbols for XCOFF (PR #70642)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 20 08:08:55 PST 2023
================
@@ -106,6 +126,181 @@ Error XCOFFDumper::dumpSections(ArrayRef<Shdr> Sections) {
return Error::success();
}
+Error XCOFFDumper::dumpFileAuxSym(XCOFFYAML::Symbol &Sym,
+ const XCOFFSymbolRef &SymbolEntRef) {
+ for (uint8_t I = 1; I <= Sym.NumberOfAuxEntries; ++I) {
+ uintptr_t AuxAddress = XCOFFObjectFile::getAdvancedSymbolEntryAddress(
+ SymbolEntRef.getEntryAddress(), I);
+ const XCOFFFileAuxEnt *FileAuxEntPtr =
+ getAuxEntPtr<XCOFFFileAuxEnt>(AuxAddress);
+ auto FileNameOrError = Obj.getCFileName(FileAuxEntPtr);
+ if (!FileNameOrError)
+ return FileNameOrError.takeError();
+
+ XCOFFYAML::FileAuxEnt FileAuxSym;
+ FileAuxSym.FileNameOrString = FileNameOrError.get();
+ FileAuxSym.FileStringType = FileAuxEntPtr->Type;
+ Sym.AuxEntries.push_back(
+ std::make_unique<XCOFFYAML::FileAuxEnt>(FileAuxSym));
+ }
+ return Error::success();
+}
+
+void XCOFFDumper::dumpStatAuxSym(XCOFFYAML::Symbol &Sym,
+ const XCOFFSymbolRef &SymbolEntRef) {
+ assert(Sym.NumberOfAuxEntries == 1 &&
+ "expected a single aux symbol for C_STAT!");
+
+ const XCOFFSectAuxEntForStat *AuxEntPtr =
+ getAuxEntPtr<XCOFFSectAuxEntForStat>(
+ XCOFFObjectFile::getAdvancedSymbolEntryAddress(
+ SymbolEntRef.getEntryAddress(), 1));
+ XCOFFYAML::SectAuxEntForStat StatAuxSym;
+ StatAuxSym.SectionLength = AuxEntPtr->SectionLength;
+ StatAuxSym.NumberOfLineNum = AuxEntPtr->NumberOfLineNum;
+ StatAuxSym.NumberOfRelocEnt = AuxEntPtr->NumberOfRelocEnt;
+ Sym.AuxEntries.push_back(
+ std::make_unique<XCOFFYAML::SectAuxEntForStat>(StatAuxSym));
+}
+
+void XCOFFDumper::dumpFuncAuxSym(XCOFFYAML::Symbol &Sym,
+ const uintptr_t AuxAddress) {
+ XCOFFYAML::FunctionAuxEnt FunAuxSym;
+
+ if (Obj.is64Bit()) {
+ const XCOFFFunctionAuxEnt64 *AuxEntPtr =
+ getAuxEntPtr<XCOFFFunctionAuxEnt64>(AuxAddress);
+ FunAuxSym.PtrToLineNum = AuxEntPtr->PtrToLineNum;
+ FunAuxSym.SizeOfFunction = AuxEntPtr->SizeOfFunction;
+ FunAuxSym.SymIdxOfNextBeyond = AuxEntPtr->SymIdxOfNextBeyond;
+ } else {
+ const XCOFFFunctionAuxEnt32 *AuxEntPtr =
+ getAuxEntPtr<XCOFFFunctionAuxEnt32>(AuxAddress);
+ FunAuxSym.OffsetToExceptionTbl = AuxEntPtr->OffsetToExceptionTbl;
+ FunAuxSym.PtrToLineNum = AuxEntPtr->PtrToLineNum;
+ FunAuxSym.SizeOfFunction = AuxEntPtr->SizeOfFunction;
+ FunAuxSym.SymIdxOfNextBeyond = AuxEntPtr->SymIdxOfNextBeyond;
+ }
+
+ Sym.AuxEntries.push_back(
+ std::make_unique<XCOFFYAML::FunctionAuxEnt>(FunAuxSym));
+}
+
+void XCOFFDumper::dumpExpAuxSym(XCOFFYAML::Symbol &Sym,
+ const uintptr_t AuxAddress) {
+ const XCOFFExceptionAuxEnt *AuxEntPtr =
+ getAuxEntPtr<XCOFFExceptionAuxEnt>(AuxAddress);
+ XCOFFYAML::ExcpetionAuxEnt ExceptAuxSym;
+ ExceptAuxSym.OffsetToExceptionTbl = AuxEntPtr->OffsetToExceptionTbl;
+ ExceptAuxSym.SizeOfFunction = AuxEntPtr->SizeOfFunction;
+ ExceptAuxSym.SymIdxOfNextBeyond = AuxEntPtr->SymIdxOfNextBeyond;
+ Sym.AuxEntries.push_back(
+ std::make_unique<XCOFFYAML::ExcpetionAuxEnt>(ExceptAuxSym));
+}
+
+void XCOFFDumper::dumpCscetAuxSym(XCOFFYAML::Symbol &Sym,
+ const object::XCOFFCsectAuxRef &AuxEntPtr) {
+ XCOFFYAML::CsectAuxEnt CsectAuxSym;
+ CsectAuxSym.ParameterHashIndex = AuxEntPtr.getParameterHashIndex();
+ CsectAuxSym.TypeChkSectNum = AuxEntPtr.getTypeChkSectNum();
+ CsectAuxSym.SymbolAlignmentAndType = AuxEntPtr.getSymbolAlignmentAndType();
+ CsectAuxSym.StorageMappingClass = AuxEntPtr.getStorageMappingClass();
+
+ if (Obj.is64Bit()) {
+ CsectAuxSym.SectionOrLengthLo =
+ static_cast<uint32_t>(AuxEntPtr.getSectionOrLength64());
+ CsectAuxSym.SectionOrLengthHi =
+ static_cast<uint32_t>(AuxEntPtr.getSectionOrLength64() >> 32);
+ } else {
+ CsectAuxSym.SectionOrLength = AuxEntPtr.getSectionOrLength32();
+ CsectAuxSym.StabInfoIndex = AuxEntPtr.getStabInfoIndex32();
+ CsectAuxSym.StabSectNum = AuxEntPtr.getStabSectNum32();
+ }
+
+ Sym.AuxEntries.push_back(
+ std::make_unique<XCOFFYAML::CsectAuxEnt>(CsectAuxSym));
+}
+
+Error XCOFFDumper::dumpAuxSyms(XCOFFYAML::Symbol &Sym,
+ const XCOFFSymbolRef &SymbolEntRef) {
+ for (uint8_t I = 1; I <= Sym.NumberOfAuxEntries; ++I) {
+ if (I == Sym.NumberOfAuxEntries && !Obj.is64Bit())
+ break;
+
+ uintptr_t AuxAddress = XCOFFObjectFile::getAdvancedSymbolEntryAddress(
+ SymbolEntRef.getEntryAddress(), I);
+
+ if (Obj.is64Bit()) {
+ XCOFF::SymbolAuxType Type = *Obj.getSymbolAuxType(AuxAddress);
+ if (Type == XCOFF::SymbolAuxType::AUX_CSECT)
----------------
diggerlin wrote:
it looks you change the auxiliary entry of the CSECT, you always print the CSECT entry in the end of the all auxiliary entries for 64 bits, I think we need to keep the same order of the binary object file.
https://github.com/llvm/llvm-project/pull/70642
More information about the llvm-commits
mailing list