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,23 @@ +## Test llvm-nm for XCOFF object files with --print-size option. +# RUN: llvm-nm --print-size %p/Inputs/test_xlclang.o | FileCheck --check-prefix=NM-SIZE %s + +## test_xlclang.o is generated by the following source compiled with IBM xlclang++ in aix os. +## int value = 0; +## +## __attribute__ ((weak)) int weak_value = 5; +## +## static int func0 () { +## return value; +## } +## +## int func1 (int i) { +## return func0() * i; +## } + +#NM-SIZE: 0000104 00000004 d _Z5func1i +#NM-SIZE-NEXT: 0000010c 0000000c D _Z5func1i +#NM-SIZE-NEXT: 00000100 00000004 d value +#NM-SIZE-NEXT: 00000118 00000004 D value +#NM-SIZE-NEXT: 00000108 00000004 d weak_value +#NM-SIZE-NEXT: 0000011c 00000004 W weak_value +~ 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 @@ -1694,6 +1694,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();