Skip to content

[llvm-nm][WebAssembly] Print function symbol sizes #81315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 9, 2024

Conversation

dschuff
Copy link
Member

@dschuff dschuff commented Feb 9, 2024

nm already prints sizes for data symbols. Do that for function symbols too,
and update objdump to also print size information.

Implements item 3 from #76107

nm already prints sizes for data symbols. Do that for function symbols too.
@llvmbot
Copy link
Member

llvmbot commented Feb 9, 2024

@llvm/pr-subscribers-mc
@llvm/pr-subscribers-backend-webassembly

@llvm/pr-subscribers-llvm-binary-utilities

Author: Derek Schuff (dschuff)

Changes

nm already prints sizes for data symbols. Do that for function symbols too.


Full diff: https://github.com/llvm/llvm-project/pull/81315.diff

3 Files Affected:

  • (modified) llvm/test/tools/llvm-nm/wasm/linked.yaml (+5)
  • (modified) llvm/test/tools/llvm-nm/wasm/print-size.test (+1-1)
  • (modified) llvm/tools/llvm-nm/llvm-nm.cpp (+5)
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)) {

@dschuff
Copy link
Member Author

dschuff commented Feb 9, 2024

Actually WDYT of printing the symbol size in llvm-objdump -t too? It is a change to the output format for that flag (we weren't printing it at all before) but now our format matches ELF, and in any case the info could be useful and it makes sense for objdump to mirror nm.

Copy link

github-actions bot commented Feb 9, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@llvmbot llvmbot added the mc Machine (object) code label Feb 9, 2024
@dschuff dschuff merged commit 01706e7 into llvm:main Feb 9, 2024
@dschuff
Copy link
Member Author

dschuff commented Feb 9, 2024

This seems to have broken some buildbots in a way that didn't reproduce for me locally. I'm investigating and will revert if I don't figure it out soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants