[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 Dec 16 13:30:00 PST 2021
DiggerLin updated this revision to Diff 394979.
DiggerLin added a comment.
using yaml2obj for test cases
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/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
@@ -1695,6 +1695,11 @@
S.Address = 0;
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,52 @@
+## Test llvm-nm for XCOFF object files with --print-size option.
+## Test size of label symbol
+## Test size of SD symbol
+## Test size of common symbol
+
+# RUN: yaml2obj --docnum=1 %s -o %t.o
+# RUN: llvm-nm --print-size %t.o | FileCheck --check-prefix=NM-SIZE --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
+
+# NM-SIZE: 00000000 00000000 T ._ZL5func0v
+# NM-SIZE-NEXT: 0000013c 00000004 C comval
+# NM-SIZE-NEXT: 00000200 00000008 D val
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113104.394979.patch
Type: text/x-patch
Size: 2503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211216/87218f1b/attachment.bin>
More information about the llvm-commits
mailing list