diff --git a/llvm/include/llvm/Object/XCOFFObjectFile.h b/llvm/include/llvm/Object/XCOFFObjectFile.h --- a/llvm/include/llvm/Object/XCOFFObjectFile.h +++ b/llvm/include/llvm/Object/XCOFFObjectFile.h @@ -294,6 +294,7 @@ bool isSectionText(DataRefImpl Sec) const override; bool isSectionData(DataRefImpl Sec) const override; bool isSectionBSS(DataRefImpl Sec) const override; + bool isDebugSection(DataRefImpl Sec) const override; bool isSectionVirtual(DataRefImpl Sec) const override; relocation_iterator section_rel_begin(DataRefImpl Sec) const override; diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp --- a/llvm/lib/Object/XCOFFObjectFile.cpp +++ b/llvm/lib/Object/XCOFFObjectFile.cpp @@ -314,6 +314,11 @@ return Flags & (XCOFF::STYP_BSS | XCOFF::STYP_TBSS); } +bool XCOFFObjectFile::isDebugSection(DataRefImpl Sec) const { + uint32_t Flags = getSectionFlags(Sec); + return Flags & (XCOFF::STYP_DEBUG | XCOFF::STYP_DWARF); +} + bool XCOFFObjectFile::isSectionVirtual(DataRefImpl Sec) const { return is64Bit() ? toSection64(Sec)->FileOffsetToRawData == 0 : toSection32(Sec)->FileOffsetToRawData == 0; diff --git a/llvm/test/tools/llvm-objdump/XCOFF/Inputs/xcoff-long-sec-names.o b/llvm/test/tools/llvm-objdump/XCOFF/Inputs/xcoff-long-sec-names.o deleted file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@&1 \ +# RUN: | FileCheck --check-prefix=ERROR %s + +# ERROR: The end of the file was unexpectedly encountered + +--- !XCOFF +FileHeader: + MagicNumber: 0x1DF +Sections: + - Name: .text + Size: 0x8 + Flags: [ STYP_TEXT ] diff --git a/llvm/test/tools/llvm-objdump/XCOFF/section-headers.test b/llvm/test/tools/llvm-objdump/XCOFF/section-headers.test --- a/llvm/test/tools/llvm-objdump/XCOFF/section-headers.test +++ b/llvm/test/tools/llvm-objdump/XCOFF/section-headers.test @@ -1,43 +1,71 @@ -# RUN: llvm-objdump --section-headers %p/Inputs/xcoff-section-headers.o | \ -# RUN: FileCheck %s - -# RUN: llvm-objdump --section-headers %p/Inputs/xcoff-long-sec-names.o | \ -# RUN: FileCheck --check-prefix=LONG %s - -# RUN: not llvm-objdump --section-headers 2>&1 \ -# RUN: %p/Inputs/xcoff-section-headers-truncate.o | FileCheck \ -# RUN: --check-prefix=ERROR %s - -# ERROR: The end of the file was unexpectedly encountered - -# CHECK: xcoff-section-headers.o: file format aixcoff-rs6000 -# CHECK: Sections: -# CHECK: Idx Name Size VMA Type -# CHECK: 0 .text 00000080 00000000 TEXT -# CHECK: 1 .data 00000024 00000080 DATA -# CHECK: 2 .bss 00000004 000000a4 BSS -# CHECK: 3 .tdata 00000008 00000000 DATA -# CHECK: 4 .tbss 00000004 00000008 BSS - -# xcoff-section-headers.o Compiled with IBM XL C/C++ for AIX, V16.1.0 -# test.c: -# int a; -# int b = 12345; -# __thread int c; -# __thread double d = 3.14159; -# -# int func(void) { -# return a; -# } - -# LONG: xcoff-long-sec-names.o: file format aixcoff-rs6000 -# LONG: Sections: -# LONG: Idx Name Size VMA Type -# LONG: 0 .dwarnge 00000004 00000000 -# LONG: 1 .dwpbnms 00000004 00000000 -# LONG: 2 .dwpbtyp 00000004 00000000 - -# xcoff-long-sec-names.o was generated by assembling the following .s file: -# .dwsect 0x30000 # .dwpbnms section -# .dwsect 0x40000 # .dwpbtyp section -# .dwsect 0x50000 # .dwarnge section +## Test various details of llvm-objdump -h/--section-headers for XCOFF. + +## Check the `--section-headers/-h` prints the type of sections correctly. + +# RUN: yaml2obj %s --docnum=1 -o %t-type.o +# RUN: llvm-objdump --section-headers %t-type.o | FileCheck %s + +# CHECK: Sections: +# CHECK-NEXT: Idx Name Size VMA Type +# CHECK-NEXT: 0 .text 00000008 00000008 TEXT +# CHECK-NEXT: 1 .data 00000004 00000000 DATA +# CHECK-NEXT: 2 .bss 00000000 00000010 BSS +# CHECK-NEXT: 3 .tdata 00000004 00000000 DATA +# CHECK-NEXT: 4 .tbss 00000000 00000000 BSS +# CHECK-NEXT: 5 .dwline 00000046 00000000 DEBUG +# CHECK-NEXT: 6 .dwinfo 00000046 00000000 DEBUG + +--- !XCOFF +FileHeader: + MagicNumber: 0x1DF +Sections: + - Name: .text + Address: 0x8 + Size: 0x8 + Flags: [ STYP_TEXT ] + - Name: .data + Size: 0x4 + Flags: [ STYP_DATA ] + - Name: .bss + Address: 0x20 + Size: 0x0 + Address: 0x10 + Flags: [ STYP_BSS ] + - Name: .tdata + Size: 0x4 + Flags: [ STYP_TDATA ] + - Name: .tbss + Size: 0x0 + Flags: [ STYP_TBSS ] + - Name: .dwline + Size: 0x46 + Flags: [ STYP_DWARF ] + - Name: .dwinfo + Size: 0x46 + Flags: [ STYP_DEBUG ] + +## Check the `--section-headers/-h` option prints long section names. + +# RUN: yaml2obj %s --docnum=2 -o %t-longname.o +# RUN: llvm-objdump --section-headers %t-longname.o \ +# RUN: | FileCheck %s --check-prefix=LONG + +# LONG: Sections: +# LONG-NEXT: Idx Name Size VMA Type +# LONG-NEXT: 0 .dwarnge 00000004 00000000 +# LONG-NEXT: 1 .dwpbnms 00000004 00000000 +# LONG-NEXT: 2 .dwpbtyp 00000004 00000000 + +--- !XCOFF +FileHeader: + MagicNumber: 0x1DF +Sections: + - Name: .dwarnge + Size: 0x4 + Flags: [ STYP_PAD ] + - Name: .dwpbnms + Size: 0x4 + Flags: [ STYP_PAD ] + - Name: .dwpbtyp + Size: 0x4 + Flags: [ STYP_PAD ]