diff options
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 40665d6..94cd969 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -1351,6 +1351,7 @@ Error WasmObjectFile::parseExportSection(ReadContext &Ctx) { break; case wasm::WASM_EXTERNAL_TABLE: Info.Kind = wasm::WASM_SYMBOL_TYPE_TABLE; + Info.ElementIndex = Ex.Index; break; default: return make_error<GenericBinaryError>("unexpected export kind", @@ -1667,10 +1668,18 @@ Expected<StringRef> WasmObjectFile::getSymbolName(DataRefImpl Symb) const { Expected<uint64_t> WasmObjectFile::getSymbolAddress(DataRefImpl Symb) const { auto &Sym = getWasmSymbol(Symb); if (Sym.Info.Kind == wasm::WASM_SYMBOL_TYPE_FUNCTION && - isDefinedFunctionIndex(Sym.Info.ElementIndex)) - return getDefinedFunction(Sym.Info.ElementIndex).CodeSectionOffset; - else - return getSymbolValue(Symb); + isDefinedFunctionIndex(Sym.Info.ElementIndex)) { + // For object files, use the section offset. The linker relies on this. + // For linked files, use the file offset. This behavior matches the way + // browsers print stack traces and is useful for binary size analysis. + // (see https://webassembly.github.io/spec/web-api/index.html#conventions) + uint32_t Adjustment = isRelocatableObject() || isSharedObject() + ? 0 + : Sections[CodeSection].Offset; + return getDefinedFunction(Sym.Info.ElementIndex).CodeSectionOffset + + Adjustment; + } + return getSymbolValue(Symb); } uint64_t WasmObjectFile::getWasmSymbolValue(const WasmSymbol &Sym) const { |