[PATCH] D78779: [lld][WebAssembly] Fix crash on function signature mismatch with --relocatable

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 18:30:15 PDT 2020


sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff.
Herald added a project: LLVM.
sbc100 added a reviewer: ruiu.
sbc100 added a reviewer: aheejin.

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.

Fixes: PR45645


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78779

Files:
  lld/test/wasm/signature-mismatch.ll
  lld/wasm/SymbolTable.cpp


Index: lld/wasm/SymbolTable.cpp
===================================================================
--- lld/wasm/SymbolTable.cpp
+++ lld/wasm/SymbolTable.cpp
@@ -642,8 +642,10 @@
   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;
 }
 
Index: lld/test/wasm/signature-mismatch.ll
===================================================================
--- lld/test/wasm/signature-mismatch.ll
+++ 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 @@
 ; 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78779.259768.patch
Type: text/x-patch
Size: 3346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200424/4fd3e2b4/attachment.bin>


More information about the llvm-commits mailing list