[llvm] [llvm-nm][WebAssembly] Print function symbol sizes (PR #81315)
Derek Schuff via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 9 12:41:42 PST 2024
https://github.com/dschuff updated https://github.com/llvm/llvm-project/pull/81315
>From 9aa841ab8ddb8f5808f8ce2924fdf925f43ed266 Mon Sep 17 00:00:00 2001
From: Derek Schuff <dschuff at chromium.org>
Date: Fri, 9 Feb 2024 12:38:29 -0800
Subject: [PATCH 1/2] [llvm-nm][WebAssembly] Print function symbol sizes
nm already prints sizes for data symbols. Do that for function symbols too.
---
llvm/test/tools/llvm-nm/wasm/linked.yaml | 5 +++++
llvm/test/tools/llvm-nm/wasm/print-size.test | 2 +-
llvm/tools/llvm-nm/llvm-nm.cpp | 5 +++++
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/llvm/test/tools/llvm-nm/wasm/linked.yaml b/llvm/test/tools/llvm-nm/wasm/linked.yaml
index 992c1811743b7a..6aee4b9fc184c4 100644
--- a/llvm/test/tools/llvm-nm/wasm/linked.yaml
+++ b/llvm/test/tools/llvm-nm/wasm/linked.yaml
@@ -1,10 +1,15 @@
# RUN: yaml2obj %s -o %t.wasm
# RUN: llvm-nm %t.wasm | FileCheck %s
+# RUN: llvm-nm -P %t.wasm | FileCheck %s --check-prefix=POSIX
# CHECK: 0000009f T my_func_export
# CHECK-NEXT: 0000002a D my_global_export
# CHECK-NEXT: 00000000 D my_table_export
+# POSIX: my_func_export T 9f 3
+# POSIX-NEXT: my_global_export D 2a 0
+# POSIX-NEXT: my_table_export D 0 0
+
--- !WASM
FileHeader:
Version: 0x1
diff --git a/llvm/test/tools/llvm-nm/wasm/print-size.test b/llvm/test/tools/llvm-nm/wasm/print-size.test
index c166edb4641c4b..610929b959b5f1 100644
--- a/llvm/test/tools/llvm-nm/wasm/print-size.test
+++ b/llvm/test/tools/llvm-nm/wasm/print-size.test
@@ -43,4 +43,4 @@ Sections:
Size: 32
# CHECK: 00000000 00000020 D a_data_symbol
-# CHECK: 00000001 00000000 T a_func
+# CHECK: 00000001 0000000d T a_func
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index da5998b70ea3f3..51f7e417306cf6 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -1858,6 +1858,11 @@ static bool getSymbolNamesFromObject(SymbolicFile &Obj,
const WasmSymbol &WasmSym = WasmObj->getWasmSymbol(Sym);
if (WasmSym.isTypeData() && !WasmSym.isUndefined())
S.Size = WasmSym.Info.DataRef.Size;
+ if (WasmSym.isTypeFunction() && !WasmSym.isUndefined())
+ S.Size = WasmObj
+ ->functions()[WasmSym.Info.ElementIndex -
+ WasmObj->getNumImportedFunctions()]
+ .Size;
}
if (PrintAddress && isa<ObjectFile>(Obj)) {
>From d57e2693fecfcaecf61a481e6305583f11bc0dc4 Mon Sep 17 00:00:00 2001
From: Derek Schuff <dschuff at chromium.org>
Date: Fri, 9 Feb 2024 12:41:28 -0800
Subject: [PATCH 2/2] use else
---
llvm/tools/llvm-nm/llvm-nm.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index 51f7e417306cf6..1e69adc72ce310 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -1858,7 +1858,7 @@ static bool getSymbolNamesFromObject(SymbolicFile &Obj,
const WasmSymbol &WasmSym = WasmObj->getWasmSymbol(Sym);
if (WasmSym.isTypeData() && !WasmSym.isUndefined())
S.Size = WasmSym.Info.DataRef.Size;
- if (WasmSym.isTypeFunction() && !WasmSym.isUndefined())
+ else if (WasmSym.isTypeFunction() && !WasmSym.isUndefined())
S.Size = WasmObj
->functions()[WasmSym.Info.ElementIndex -
WasmObj->getNumImportedFunctions()]
More information about the llvm-commits
mailing list