diff --git a/llvm/test/tools/llvm-nm/XCOFF/size.test b/llvm/test/tools/llvm-nm/XCOFF/size.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-nm/XCOFF/size.test @@ -0,0 +1,52 @@ +## Test llvm-nm for XCOFF object files with --print-size option. + +# RUN: yaml2obj %s -o %t.o +# RUN: llvm-nm --print-size %t.o | FileCheck --match-full-lines %s + +--- !XCOFF +FileHeader: + MagicNumber: 0x1DF +Sections: + - Name: .text + Address: 0x0 + Flags: [ STYP_TEXT ] + - Name: .data + Flags: [ STYP_DATA ] + - Name: .bss + Flags: [ STYP_BSS ] +Symbols: + - Name: ._ZL5func0v + Section: .text + StorageClass: C_EXT + Type: 0x20 + AuxEntries: + - Type: AUX_CSECT + SymbolAlignmentAndType: 0x02 + StorageMappingClass: XMC_PR + - Name: val + Value: 0x200 + Section: .data + StorageClass: C_EXT + Type: 0x20 + AuxEntries: + - Type: AUX_CSECT + SymbolAlignmentAndType: 0x01 + StorageMappingClass: XMC_RW + SectionOrLength: 0x8 + - Name: comval + Section: .bss + Value: 0x13C + StorageClass: C_EXT + Type: 0x00 + AuxEntries: + - Type: AUX_CSECT + SymbolAlignmentAndType: 0x03 + StorageMappingClass: XMC_RW + SectionOrLength: 0x4 + +## Size of a label symbol. +# CHECK: 00000000 00000000 T ._ZL5func0v +## Size of a common symbol. +# CHECK-NEXT: 0000013c 00000004 C comval +## Size of an SD symbol. +# CHECK-NEXT: 00000200 00000008 D val diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -1695,6 +1695,11 @@ S.Address = 0; if (isa(&Obj)) S.Size = ELFSymbolRef(Sym).getSize(); + + if (const XCOFFObjectFile *XCOFFObj = + dyn_cast(&Obj)) + S.Size = XCOFFObj->getSymbolSize(Sym.getRawDataRefImpl()); + if (PrintAddress && isa(Obj)) { SymbolRef SymRef(Sym); Expected AddressOrErr = SymRef.getAddress();