diff --git a/llvm/test/tools/llvm-nm/XCOFF/basic.test b/llvm/test/tools/llvm-nm/XCOFF/basic.test --- a/llvm/test/tools/llvm-nm/XCOFF/basic.test +++ b/llvm/test/tools/llvm-nm/XCOFF/basic.test @@ -45,8 +45,8 @@ # NM-SYM-NEXT: 00000138 t ._Z41__static_initialization_and_destruction_0ii # NM-SYM-NEXT: 00000050 T ._Z5func1i # NM-SYM-NEXT: 00000000 t ._ZL5func0v -# NM-SYM-NEXT: 00000294 t ._ZN1CC1Ei # NM-SYM-NEXT: 00000294 W ._ZN1CC1Ei +# NM-SYM-NEXT: 00000294 t ._ZN1CC1Ei # NM-SYM-NEXT: 000002f0 d .data # NM-SYM-NEXT: 00000000 f .file # NM-SYM-NEXT: 00000000 t .text @@ -57,8 +57,8 @@ # NM-SYM-NEXT: 0000033c W _Z3fwhv # NM-SYM-NEXT: 00000348 W _Z3fwpv # NM-SYM-NEXT: 00000354 d _Z41__static_initialization_and_destruction_0ii -# NM-SYM-NEXT: 00000330 d _Z5func1i # NM-SYM-NEXT: 00000330 D _Z5func1i +# NM-SYM-NEXT: 00000330 d _Z5func1i # NM-SYM-NEXT: 0000037c d _ZL2si # NM-SYM-NEXT: 00000324 d _ZL5func0v # NM-SYM-NEXT: 00000310 W _ZN1CC1Ei 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,50 @@ +## Test llvm-nm for XCOFF object files with --print-size option. +# RUN: llvm-nm --print-size %p/Inputs/test_gcc.o | FileCheck --check-prefix=NM-SIZE %s + +## test_gcc.o is generated by the following source compiled with g++ in aix os. +## int v = 0; +## +## __attribute__((visibility ("protected"))) int vp = 1; +## __attribute__((visibility ("hidden"))) int vh = 2; +## __attribute__((visibility ("default"))) int vd = 3; +## __attribute__ ((weak)) __attribute__((visibility ("hidden"))) int vwh = 4; +## __attribute__ ((weak)) __attribute__((visibility ("protected"))) int vwp = 5; +## +## class C { +## public: +## int c; +## C(int v):c(v) {} +## }; +## +## C cc(2); +## +## static int si = 6; +## +## static int func0 () { +## return vp+si; +## } +## +## int func1 (int i) { +## return func0() * i; +## } +## +## __attribute__ ((weak)) __attribute__((visibility ("hidden"))) +## int fwh() { +## return si+1; +## } +## +## __attribute__ ((weak)) __attribute__((visibility ("protected"))) +## int fwp() { +## return si+2; +## } + +# NM-SIZE: 00000294 00000050 t ._ZN1CC1Ei +# NM-SIZE-NEXT: 000002f0 00000020 d .data +# NM-SIZE-NEXT: 00000000 00000000 f .file +# NM-SIZE-NEXT: 00000000 00000294 t .text + +# NM-SIZE: 00000330 00000000 D _Z5func1i +# NM-SIZE-NEXT: 00000330 0000000c d _Z5func1i + +# NM-SIZE: 000002f4 00000000 D vp +# NM-SIZE-NEXT: 00000378 00000004 d vp 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 @@ -1693,6 +1693,10 @@ 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();