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/section-headers-truncate.test b/llvm/test/tools/llvm-objdump/XCOFF/section-headers-truncate.test --- a/llvm/test/tools/llvm-objdump/XCOFF/section-headers-truncate.test +++ b/llvm/test/tools/llvm-objdump/XCOFF/section-headers-truncate.test @@ -0,0 +1,5 @@ +# 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 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,69 @@ -# 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 \ +# RUN: | FileCheck %s --check-prefix=TYPE + +#TYPE: Sections: +#TYPE-NEXT: Idx Name Size VMA Type +#TYPE-NEXT: 0 .text 00000008 00000000 TEXT +#TYPE-NEXT: 1 .data 00000004 00000000 DATA +#TYPE-NEXT: 2 .bss 00000000 00000000 BSS +#TYPE-NEXT: 3 .tdata 00000004 00000000 DATA +#TYPE-NEXT: 4 .tbss 00000000 00000000 BSS +#TYPE-NEXT: 5 .dwline 00000046 00000000 DEBUG +#TYPE-NEXT: 6 .dwinfo 00000046 00000000 DEBUG + +--- !XCOFF +FileHeader: + MagicNumber: 0x1DF +Sections: + - Name: .text + Size: 0x8 + Flags: [ STYP_TEXT ] + - Name: .data + Size: 0x4 + Flags: [ STYP_DATA ] + - Name: .bss + Size: 0x0 + 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 ] diff --git a/llvm/test/tools/llvm-objdump/section-headers.test b/llvm/test/tools/llvm-objdump/section-headers.test --- a/llvm/test/tools/llvm-objdump/section-headers.test +++ b/llvm/test/tools/llvm-objdump/section-headers.test @@ -141,3 +141,47 @@ Type: SHT_PROGBITS Flags: [SHF_ALLOC, SHF_EXECINSTR] Address: 0x400 + +## Check that the `--section-headers/-h` option prints the types of +## section headers correctly. + +# RUN: yaml2obj %s --docnum=5 -o %t-sectiontypes.o +# RUN: llvm-objdump --section-headers %t-sectiontypes.o \ +# RUN: | FileCheck %s --check-prefix=TYPE + +# TYPE: Sections: +# TYPE-NEXT: Idx Name Size VMA Type +# TYPE-NEXT: 0 00000000 0000000000000000 +# TYPE-NEXT: 1 .text 00000026 0000000000000000 TEXT +# TYPE-NEXT: 2 .data 00000010 0000000000000026 DATA +# TYPE-NEXT: 3 .bss 00000000 0000000000000036 BSS +# TYPE-NEXT: 4 .debug_abbrev 0000000a 0000000000000000 DEBUG +# TYPE-NEXT: 5 .debug_info 0000000a 0000000000000040 DATA, DEBUG +# TYPE-NEXT: 6 .strtab 00000001 0000000000000000 +# TYPE-NEXT: 7 .shstrtab 0000003e 0000000000000000 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_PPC64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Size: 0x26 + - Name: .data + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Size: 0x10 + - Name: .bss + Type: SHT_NOBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + - Name: .debug_abbrev + Type: SHT_PROGBITS + Size: 0xa + - Name: .debug_info + Type: SHT_PROGBITS + Flags: [ SHF_WRITE, SHF_ALLOC ] + Size: 0xa diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -2185,9 +2185,11 @@ std::string Type = Section.isText() ? "TEXT" : ""; if (Section.isData()) - Type += Type.empty() ? "DATA" : " DATA"; + Type += Type.empty() ? "DATA" : ", DATA"; if (Section.isBSS()) - Type += Type.empty() ? "BSS" : " BSS"; + Type += Type.empty() ? "BSS" : ", BSS"; + if (Section.isDebugSection()) + Type += Type.empty() ? "DEBUG" : ", DEBUG"; if (HasLMAColumn) outs() << format("%3" PRIu64 " %-*s %08" PRIx64 " ", Idx, NameWidth,