[llvm] df86fb0 - [llvm-objdump] enable file-headers option of llvm-objdump for XCOFF object files (#96104)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 21 06:17:08 PDT 2024


Author: zhijian lin
Date: 2024-06-21T09:17:04-04:00
New Revision: df86fb069e130f405ca2e6124c725e6dd1d629c6

URL: https://github.com/llvm/llvm-project/commit/df86fb069e130f405ca2e6124c725e6dd1d629c6
DIFF: https://github.com/llvm/llvm-project/commit/df86fb069e130f405ca2e6124c725e6dd1d629c6.diff

LOG: [llvm-objdump] enable file-headers option of llvm-objdump for XCOFF object files (#96104)

the patch enable file-headers option of llvm-objdump for XCOFF object
files

Added: 
    llvm/test/tools/llvm-objdump/XCOFF/file-headers.test

Modified: 
    llvm/include/llvm/Object/XCOFFObjectFile.h
    llvm/lib/Object/XCOFFObjectFile.cpp
    llvm/tools/llvm-objdump/llvm-objdump.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Object/XCOFFObjectFile.h b/llvm/include/llvm/Object/XCOFFObjectFile.h
index fa23aa9c5d3f4..5a7cd8e38f2b7 100644
--- a/llvm/include/llvm/Object/XCOFFObjectFile.h
+++ b/llvm/include/llvm/Object/XCOFFObjectFile.h
@@ -70,6 +70,9 @@ template <typename T> struct XCOFFAuxiliaryHeader {
   }
 
   uint16_t getVersion() const { return static_cast<const T *>(this)->Version; }
+  uint64_t getEntryPointAddr() const {
+    return static_cast<const T *>(this)->EntryPointAddr;
+  }
 };
 
 struct XCOFFAuxiliaryHeader32 : XCOFFAuxiliaryHeader<XCOFFAuxiliaryHeader32> {

diff  --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp
index d09e7b0698ca0..25a60f379fc22 100644
--- a/llvm/lib/Object/XCOFFObjectFile.cpp
+++ b/llvm/lib/Object/XCOFFObjectFile.cpp
@@ -737,9 +737,11 @@ bool XCOFFObjectFile::isRelocatableObject() const {
 }
 
 Expected<uint64_t> XCOFFObjectFile::getStartAddress() const {
-  // TODO FIXME Should get from auxiliary_header->o_entry when support for the
-  // auxiliary_header is added.
-  return 0;
+  if (AuxiliaryHeader == nullptr)
+    return 0;
+
+  return is64Bit() ? auxiliaryHeader64()->getEntryPointAddr()
+                   : auxiliaryHeader32()->getEntryPointAddr();
 }
 
 StringRef XCOFFObjectFile::mapDebugSectionName(StringRef Name) const {

diff  --git a/llvm/test/tools/llvm-objdump/XCOFF/file-headers.test b/llvm/test/tools/llvm-objdump/XCOFF/file-headers.test
new file mode 100644
index 0000000000000..89218ac6852f2
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/XCOFF/file-headers.test
@@ -0,0 +1,21 @@
+## Test the `--file-headers` option of llvm-objdump for XCOFF object files.
+# RUN: yaml2obj %s -o %t1
+# RUN: llvm-objdump --file-headers %t1 |\
+# RUN:   FileCheck %s --check-prefix=CHECK32 --match-full-lines
+# RUN: yaml2obj %s -DMAGIC=0x1F7 -o %t2
+# RUN: llvm-objdump --file-headers %t2 |\
+# RUN:   FileCheck %s --check-prefix=CHECK64 --match-full-lines
+
+# CHECK32:      {{.*}}file format aixcoff-rs6000 
+# CHECK32-NEXT: architecture: powerpc
+# CHECK32-NEXT: start address: 0x00001111
+
+# CHECK64:      {{.*}}file format aix5coff64-rs6000
+# CHECK64-NEXT: architecture: powerpc64
+# CHECK64-NEXT: start address: 0x0000000000001111
+
+--- !XCOFF
+FileHeader:
+  MagicNumber: [[MAGIC=0x1DF]]
+AuxiliaryHeader:
+  EntryPointAddr:        0x1111

diff  --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 8265ab9d7fe6b..6249be4f332b7 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -3151,7 +3151,7 @@ void Dumper::printPrivateHeaders() {
 }
 
 static void printFileHeaders(const ObjectFile *O) {
-  if (!O->isELF() && !O->isCOFF())
+  if (!O->isELF() && !O->isCOFF() && !O->isXCOFF())
     reportError(O->getFileName(), "Invalid/Unsupported object file format");
 
   Triple::ArchType AT = O->getArch();


        


More information about the llvm-commits mailing list