[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
This commit is contained in:
Sam Clegg 2020-04-23 17:57:00 -07:00
parent 6fb80d9383
commit 4b8e2d8e81
2 changed files with 44 additions and 2 deletions

View file

@ -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

View file

@ -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;
}