[lld] 4b8e2d8 - [lld][WebAssembly] Fix crash on function signature mismatch with --relocatable
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 25 10:27:24 PDT 2020
Author: Sam Clegg
Date: 2020-04-25T10:26:11-07:00
New Revision: 4b8e2d8e81adf3aa1ea79fe0b908100c4ea69f65
URL: https://github.com/llvm/llvm-project/commit/4b8e2d8e81adf3aa1ea79fe0b908100c4ea69f65
DIFF: https://github.com/llvm/llvm-project/commit/4b8e2d8e81adf3aa1ea79fe0b908100c4ea69f65.diff
LOG: [lld][WebAssembly] Fix crash on function signature mismatch with --relocatable
These stub new function were not being added to the symbol table
which in turn meant that we were crashing when trying to output
relocations against them.
Differential Revision: https://reviews.llvm.org/D78779
Added:
Modified:
lld/test/wasm/signature-mismatch.ll
lld/wasm/SymbolTable.cpp
Removed:
################################################################################
diff --git a/lld/test/wasm/signature-mismatch.ll b/lld/test/wasm/signature-mismatch.ll
index 116d81823ab0..bb9204ea7e45 100644
--- a/lld/test/wasm/signature-mismatch.ll
+++ b/lld/test/wasm/signature-mismatch.ll
@@ -1,8 +1,13 @@
; RUN: llc -filetype=obj %p/Inputs/ret32.ll -o %t.ret32.o
; RUN: llc -filetype=obj %p/Inputs/call-ret32.ll -o %t.call.o
; RUN: llc -filetype=obj %s -o %t.main.o
+
; RUN: wasm-ld --export=call_ret32 --export=ret32 -o %t.wasm %t.main.o %t.ret32.o %t.call.o 2>&1 | FileCheck %s -check-prefix=WARN
; RUN: obj2yaml %t.wasm | FileCheck %s -check-prefix=YAML
+
+; RUN: wasm-ld -r -o %t.reloc.o %t.main.o %t.ret32.o %t.call.o 2>&1 | FileCheck %s -check-prefix=WARN
+; RUN: obj2yaml %t.reloc.o | FileCheck %s -check-prefix=RELOC
+
; RUN: not wasm-ld --fatal-warnings -o %t.wasm %t.main.o %t.ret32.o %t.call.o 2>&1 | FileCheck %s -check-prefix=ERROR
target triple = "wasm32-unknown-unknown"
@@ -49,3 +54,38 @@ declare i32 @ret32(i32, i64, i32) local_unnamed_addr
; YAML-NEXT: Name: call_ret32
; YAML-NEXT: ...
+; RELOC: Name: linking
+; RELOC-NEXT: Version: 2
+; RELOC-NEXT: SymbolTable:
+; RELOC-NEXT: - Index: 0
+; RELOC-NEXT: Kind: FUNCTION
+; RELOC-NEXT: Name: _start
+; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
+; RELOC-NEXT: Function: 1
+; RELOC-NEXT: - Index: 1
+; RELOC-NEXT: Kind: FUNCTION
+; RELOC-NEXT: Name: ret32
+; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
+; RELOC-NEXT: Function: 2
+; RELOC-NEXT: - Index: 2
+; RELOC-NEXT: Kind: DATA
+; RELOC-NEXT: Name: ret32_address_main
+; RELOC-NEXT: Flags: [ ]
+; RELOC-NEXT: Segment: 0
+; RELOC-NEXT: Size: 4
+; RELOC-NEXT: - Index: 3
+; RELOC-NEXT: Kind: FUNCTION
+; RELOC-NEXT: Name: call_ret32
+; RELOC-NEXT: Flags: [ VISIBILITY_HIDDEN ]
+; RELOC-NEXT: Function: 3
+; RELOC-NEXT: - Index: 4
+; RELOC-NEXT: Kind: DATA
+; RELOC-NEXT: Name: ret32_address
+; RELOC-NEXT: Flags: [ ]
+; RELOC-NEXT: Segment: 1
+; RELOC-NEXT: Size: 4
+; RELOC-NEXT: - Index: 5
+; RELOC-NEXT: Kind: FUNCTION
+; RELOC-NEXT: Name: 'signature_mismatch:ret32'
+; RELOC-NEXT: Flags: [ BINDING_LOCAL ]
+; RELOC-NEXT: Function: 0
diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index 99d18178eeac..6f6706e36aab 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -642,8 +642,10 @@ InputFunction *SymbolTable::replaceWithUnreachable(Symbol *sym,
auto *func = make<SyntheticFunction>(sig, sym->getName(), debugName);
func->setBody(unreachableFn);
syntheticFunctions.emplace_back(func);
- replaceSymbol<DefinedFunction>(sym, sym->getName(), sym->flags, nullptr,
- func);
+ // Mark new symbols as local. For relocatable output we don't want them
+ // to be exported outside the object file.
+ replaceSymbol<DefinedFunction>(sym, debugName, WASM_SYMBOL_BINDING_LOCAL,
+ nullptr, func);
return func;
}
More information about the llvm-commits
mailing list