Index: lib/Object/WasmObjectFile.cpp =================================================================== --- lib/Object/WasmObjectFile.cpp +++ lib/Object/WasmObjectFile.cpp @@ -1181,7 +1181,7 @@ return Header; } -void WasmObjectFile::moveSymbolNext(DataRefImpl &Symb) const { Symb.d.a++; } +void WasmObjectFile::moveSymbolNext(DataRefImpl &Symb) const { Symb.d.b++; } uint32_t WasmObjectFile::getSymbolFlags(DataRefImpl Symb) const { uint32_t Result = SymbolRef::SF_None; @@ -1203,18 +1203,20 @@ basic_symbol_iterator WasmObjectFile::symbol_begin() const { DataRefImpl Ref; - Ref.d.a = 0; + Ref.d.a = 1; // Arbitrary non-zero index so that Ref.p is non-null + Ref.d.b = 0; // Symbol index return BasicSymbolRef(Ref, this); } basic_symbol_iterator WasmObjectFile::symbol_end() const { DataRefImpl Ref; - Ref.d.a = Symbols.size(); + Ref.d.a = 1; // Arbitrary non-zero index so that Ref.p is non-null + Ref.d.b = Symbols.size(); // Symbol index return BasicSymbolRef(Ref, this); } const WasmSymbol &WasmObjectFile::getWasmSymbol(const DataRefImpl &Symb) const { - return Symbols[Symb.d.a]; + return Symbols[Symb.d.b]; } const WasmSymbol &WasmObjectFile::getWasmSymbol(const SymbolRef &Symb) const { Index: test/tools/llvm-nm/wasm/extern-only.ll =================================================================== --- /dev/null +++ test/tools/llvm-nm/wasm/extern-only.ll @@ -0,0 +1,9 @@ +; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown -o %t.o %s +; RUN: llvm-nm --extern-only %t.o | FileCheck %s + +define hidden i32 @foo() { +entry: + ret i32 42 +} + +; CHECK: 00000001 T foo