aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2024-02-09 14:22:47 -0800
committerGitHub <noreply@github.com>2024-02-09 14:22:47 -0800
commit01706e767777aeac9d5a22617d522826b64fce3e (patch)
treec07dad2bb08ec18c31adfdedcf7138b968e5f9e8 /llvm/lib/Object/WasmObjectFile.cpp
parent0b77b19292457b9f2020e290980f1803a16eea34 (diff)
downloadllvm-01706e767777aeac9d5a22617d522826b64fce3e.zip
llvm-01706e767777aeac9d5a22617d522826b64fce3e.tar.gz
llvm-01706e767777aeac9d5a22617d522826b64fce3e.tar.bz2
[llvm-nm][WebAssembly] Print function symbol sizes (#81315)
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 https://github.com/llvm/llvm-project/issues/76107
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 1d68687..04e2b80 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -1932,6 +1932,20 @@ uint32_t WasmObjectFile::getSymbolSectionIdImpl(const WasmSymbol &Sym) const {
}
}
+uint32_t WasmObjectFile::getSymbolSize(SymbolRef Symb) const {
+ const WasmSymbol &Sym = getWasmSymbol(Symb);
+ if (!Sym.isDefined())
+ return 0;
+ if (Sym.isTypeData())
+ return Sym.Info.DataRef.Size;
+ if (Sym.isTypeFunction())
+ return functions()[Sym.Info.ElementIndex - getNumImportedFunctions()].Size;
+ // Currently symbol size is only tracked for data segments and functions. In
+ // principle we could also track size (e.g. binary size) for tables, globals
+ // and element segments etc too.
+ return 0;
+}
+
void WasmObjectFile::moveSectionNext(DataRefImpl &Sec) const { Sec.d.a++; }
Expected<StringRef> WasmObjectFile::getSectionName(DataRefImpl Sec) const {