Skip to content

Commit 2a193e0

Browse files
committed
[WebAssembly] Ensure BasicSymbolRef.getRawDataRefImpl().p is non-null
Store a non-zero value to ref.d.a and use ref.d.b to store the symbol index. This means that ref.p is never null, which was confusing llvm-nm. Fixes PR40497 Differential Revision: https://reviews.llvm.org/D57373 llvm-svn: 352551
1 parent ed2ebf8 commit 2a193e0

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

llvm/lib/Object/WasmObjectFile.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ const wasm::WasmObjectHeader &WasmObjectFile::getHeader() const {
11811181
return Header;
11821182
}
11831183

1184-
void WasmObjectFile::moveSymbolNext(DataRefImpl &Symb) const { Symb.d.a++; }
1184+
void WasmObjectFile::moveSymbolNext(DataRefImpl &Symb) const { Symb.d.b++; }
11851185

11861186
uint32_t WasmObjectFile::getSymbolFlags(DataRefImpl Symb) const {
11871187
uint32_t Result = SymbolRef::SF_None;
@@ -1203,18 +1203,20 @@ uint32_t WasmObjectFile::getSymbolFlags(DataRefImpl Symb) const {
12031203

12041204
basic_symbol_iterator WasmObjectFile::symbol_begin() const {
12051205
DataRefImpl Ref;
1206-
Ref.d.a = 0;
1206+
Ref.d.a = 1; // Arbitrary non-zero value so that Ref.p is non-null
1207+
Ref.d.b = 0; // Symbol index
12071208
return BasicSymbolRef(Ref, this);
12081209
}
12091210

12101211
basic_symbol_iterator WasmObjectFile::symbol_end() const {
12111212
DataRefImpl Ref;
1212-
Ref.d.a = Symbols.size();
1213+
Ref.d.a = 1; // Arbitrary non-zero value so that Ref.p is non-null
1214+
Ref.d.b = Symbols.size(); // Symbol index
12131215
return BasicSymbolRef(Ref, this);
12141216
}
12151217

12161218
const WasmSymbol &WasmObjectFile::getWasmSymbol(const DataRefImpl &Symb) const {
1217-
return Symbols[Symb.d.a];
1219+
return Symbols[Symb.d.b];
12181220
}
12191221

12201222
const WasmSymbol &WasmObjectFile::getWasmSymbol(const SymbolRef &Symb) const {

llvm/test/tools/llvm-nm/lit.local.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
if not 'X86' in config.root.targets:
22
config.unsupported = True
33

4-
config.suffixes = ['.s', '.test', '.yaml']
4+
config.suffixes = ['.ll', '.s', '.test', '.yaml']
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown -o %t.o %s
2+
; RUN: llvm-nm --extern-only %t.o | FileCheck %s
3+
4+
; Verity that hidden symbols are listed even when --extern-only is passed
5+
6+
define hidden i32 @foo() {
7+
entry:
8+
ret i32 42
9+
}
10+
11+
define i32 @bar() {
12+
entry:
13+
ret i32 43
14+
}
15+
16+
define internal i32 @baz() {
17+
entry:
18+
ret i32 44
19+
}
20+
21+
; CHECK: 00000006 T bar
22+
; CHECK-NOT: baz
23+
; CHECK: 00000001 T foo

0 commit comments

Comments
 (0)