[llvm] [llvm-objdump] Print out xcoff load section of xcoff object file with option private-headers (PR #121226)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 01:06:17 PST 2025


================
@@ -262,6 +264,45 @@ void XCOFFDumper::printAuxiliaryHeader(
                                    AuxSize, *AuxHeader);
 }
 
+void XCOFFDumper::printLoaderSectionHeader() {
+  Expected<uintptr_t> LoaderSectionAddrOrError =
+      Obj.getSectionFileOffsetToRawData(XCOFF::STYP_LOADER);
+  if (!LoaderSectionAddrOrError) {
+    reportUniqueWarning(LoaderSectionAddrOrError.takeError());
+    return;
+  }
+  uintptr_t LoaderSectionAddr = LoaderSectionAddrOrError.get();
+
+  if (LoaderSectionAddr == 0)
+    return;
+
+  auto PrintLoadSecHeaderCommon = [&](const auto *LDHeader) {
+    printNumber("Version:", LDHeader->Version);
+    printNumber("NumberOfSymbolEntries:", LDHeader->NumberOfSymTabEnt);
+    printNumber("NumberOfRelocationEntries:", LDHeader->NumberOfRelTabEnt);
+    printNumber("LengthOfImportFileIDStringTable:",
+                LDHeader->LengthOfImpidStrTbl);
+    printNumber("NumberOfImportFileIDs:", LDHeader->NumberOfImpid);
+    printHex("OffsetToImportFileIDs:", LDHeader->OffsetToImpid);
+    printNumber("LengthOfStringTable:", LDHeader->LengthOfStrTbl);
+    printHex("OffsetToStringTable:", LDHeader->OffsetToStrTbl);
+  };
+
+  Width = 35;
+  outs() << "\n---Loader Section Header:\n";
+  if (Obj.is64Bit()) {
+    const LoaderSectionHeader64 *LoaderSec64 =
+        reinterpret_cast<const LoaderSectionHeader64 *>(LoaderSectionAddr);
----------------
jh7370 wrote:

Yes, I think you understood the question correctly, but you've missed the fact that this code could be run on non-PowerPC architectures, which is where my concern lies. See issues like https://github.com/llvm/llvm-project/issues/95811 for examples.

In this case, perhaps we should check that `LoaderSectionAddr` is appropriately aligned and emit an error if it isn't. Alternatively, we can simply do a `memcpy` of the raw data into a local copy of `LoaderSectionHeader[64|32]`, so that the data is guaranteed to be aligned. I think either approach is valid, since it's probably a requirement (either explicitly, or indirectly implied by other aspects of the spec) of the XCOFF spec that `LoaderSectionAddr` is aligned.

https://github.com/llvm/llvm-project/pull/121226


More information about the llvm-commits mailing list