Skip to content

Commit 1df1124

Browse files
diggerlinAlexisPerry
authored andcommitted
[llvm-objdump] enable file-headers option of llvm-objdump for XCOFF object files (llvm#96104)
the patch enable file-headers option of llvm-objdump for XCOFF object files
1 parent ce57419 commit 1df1124

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

llvm/include/llvm/Object/XCOFFObjectFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ template <typename T> struct XCOFFAuxiliaryHeader {
7070
}
7171

7272
uint16_t getVersion() const { return static_cast<const T *>(this)->Version; }
73+
uint64_t getEntryPointAddr() const {
74+
return static_cast<const T *>(this)->EntryPointAddr;
75+
}
7376
};
7477

7578
struct XCOFFAuxiliaryHeader32 : XCOFFAuxiliaryHeader<XCOFFAuxiliaryHeader32> {

llvm/lib/Object/XCOFFObjectFile.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,11 @@ bool XCOFFObjectFile::isRelocatableObject() const {
737737
}
738738

739739
Expected<uint64_t> XCOFFObjectFile::getStartAddress() const {
740-
// TODO FIXME Should get from auxiliary_header->o_entry when support for the
741-
// auxiliary_header is added.
742-
return 0;
740+
if (AuxiliaryHeader == nullptr)
741+
return 0;
742+
743+
return is64Bit() ? auxiliaryHeader64()->getEntryPointAddr()
744+
: auxiliaryHeader32()->getEntryPointAddr();
743745
}
744746

745747
StringRef XCOFFObjectFile::mapDebugSectionName(StringRef Name) const {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Test the `--file-headers` option of llvm-objdump for XCOFF object files.
2+
# RUN: yaml2obj %s -o %t1
3+
# RUN: llvm-objdump --file-headers %t1 |\
4+
# RUN: FileCheck %s --check-prefix=CHECK32 --match-full-lines
5+
# RUN: yaml2obj %s -DMAGIC=0x1F7 -o %t2
6+
# RUN: llvm-objdump --file-headers %t2 |\
7+
# RUN: FileCheck %s --check-prefix=CHECK64 --match-full-lines
8+
9+
# CHECK32: {{.*}}file format aixcoff-rs6000
10+
# CHECK32-NEXT: architecture: powerpc
11+
# CHECK32-NEXT: start address: 0x00001111
12+
13+
# CHECK64: {{.*}}file format aix5coff64-rs6000
14+
# CHECK64-NEXT: architecture: powerpc64
15+
# CHECK64-NEXT: start address: 0x0000000000001111
16+
17+
--- !XCOFF
18+
FileHeader:
19+
MagicNumber: [[MAGIC=0x1DF]]
20+
AuxiliaryHeader:
21+
EntryPointAddr: 0x1111

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3151,7 +3151,7 @@ void Dumper::printPrivateHeaders() {
31513151
}
31523152

31533153
static void printFileHeaders(const ObjectFile *O) {
3154-
if (!O->isELF() && !O->isCOFF())
3154+
if (!O->isELF() && !O->isCOFF() && !O->isXCOFF())
31553155
reportError(O->getFileName(), "Invalid/Unsupported object file format");
31563156

31573157
Triple::ArchType AT = O->getArch();

0 commit comments

Comments
 (0)