From 01706e767777aeac9d5a22617d522826b64fce3e Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 9 Feb 2024 14:22:47 -0800 Subject: [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 --- llvm/lib/Object/WasmObjectFile.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'llvm/lib/Object/WasmObjectFile.cpp') 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 WasmObjectFile::getSectionName(DataRefImpl Sec) const { -- cgit v1.1