[PATCH] D113104: add the xcoff symbol size for the llvm-nm.
Digger Lin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 4 11:17:09 PDT 2021
DiggerLin updated this revision to Diff 384819.
DiggerLin added a comment.
reduce test case
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113104/new/
https://reviews.llvm.org/D113104
Files:
llvm/test/tools/llvm-nm/XCOFF/basic.test
llvm/test/tools/llvm-nm/XCOFF/size.test
llvm/tools/llvm-nm/llvm-nm.cpp
Index: llvm/tools/llvm-nm/llvm-nm.cpp
===================================================================
--- llvm/tools/llvm-nm/llvm-nm.cpp
+++ llvm/tools/llvm-nm/llvm-nm.cpp
@@ -1693,6 +1693,10 @@
if (isa<ELFObjectFileBase>(&Obj))
S.Size = ELFSymbolRef(Sym).getSize();
+ if (const XCOFFObjectFile *XCOFFObj =
+ dyn_cast<const XCOFFObjectFile>(&Obj))
+ S.Size = XCOFFObj->getSymbolSize(Sym.getRawDataRefImpl());
+
if (PrintAddress && isa<ObjectFile>(Obj)) {
SymbolRef SymRef(Sym);
Expected<uint64_t> AddressOrErr = SymRef.getAddress();
Index: llvm/test/tools/llvm-nm/XCOFF/size.test
===================================================================
--- /dev/null
+++ 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
Index: llvm/test/tools/llvm-nm/XCOFF/basic.test
===================================================================
--- llvm/test/tools/llvm-nm/XCOFF/basic.test
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113104.384819.patch
Type: text/x-patch
Size: 3183 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211104/6c5d39a2/attachment.bin>
More information about the llvm-commits
mailing list