[WebAssembly] Ensure BasicSymbolRef.getRawDataRefImpl().p is non-null
authorSam Clegg <sbc@chromium.org>
Tue, 29 Jan 2019 22:22:32 +0000 (22:22 +0000)
committerSam Clegg <sbc@chromium.org>
Tue, 29 Jan 2019 22:22:32 +0000 (22:22 +0000)
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

llvm/lib/Object/WasmObjectFile.cpp
llvm/test/tools/llvm-nm/lit.local.cfg
llvm/test/tools/llvm-nm/wasm/extern-only.ll [new file with mode: 0644]

index ce77ad9..6f0a5a4 100644 (file)
@@ -1181,7 +1181,7 @@ const wasm::WasmObjectHeader &WasmObjectFile::getHeader() const {
   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 @@ uint32_t WasmObjectFile::getSymbolFlags(DataRefImpl Symb) const {
 
 basic_symbol_iterator WasmObjectFile::symbol_begin() const {
   DataRefImpl Ref;
-  Ref.d.a = 0;
+  Ref.d.a = 1; // Arbitrary non-zero value 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 value 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 447a737..1fc0bea 100644 (file)
@@ -1,4 +1,4 @@
 if not 'X86' in config.root.targets:
     config.unsupported = True
 
-config.suffixes = ['.s', '.test', '.yaml']
+config.suffixes = ['.ll', '.s', '.test', '.yaml']
diff --git a/llvm/test/tools/llvm-nm/wasm/extern-only.ll b/llvm/test/tools/llvm-nm/wasm/extern-only.ll
new file mode 100644 (file)
index 0000000..46fecba
--- /dev/null
@@ -0,0 +1,23 @@
+; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown -o %t.o %s
+; RUN: llvm-nm --extern-only %t.o | FileCheck %s
+
+; Verity that hidden symbols are listed even when --extern-only is passed
+
+define hidden i32 @foo() {
+entry:
+  ret i32 42
+}
+
+define i32 @bar() {
+entry:
+  ret i32 43
+}
+
+define internal i32 @baz() {
+entry:
+  ret i32 44
+}
+
+; CHECK: 00000006 T bar
+; CHECK-NOT: baz
+; CHECK: 00000001 T foo