[PATCH] D56947: [WebAssembly] Fix crash with LTO + relocatable + undefined symbols
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 18 16:46:09 PST 2019
sbc100 created this revision.
Herald added subscribers: llvm-commits, dexonsmith, steven_wu, sunfish, aheejin, jgravelle-google, inglorion, mehdi_amini, dschuff.
sbc100 edited the summary of this revision.
sbc100 added reviewers: kripken, ruiu.
sbc100 updated this revision to Diff 182643.
sbc100 added a comment.
Revert debugging
Fixes PR40204
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D56947
Files:
test/wasm/lto/relocatable-undefined.ll
wasm/Writer.cpp
Index: wasm/Writer.cpp
===================================================================
--- wasm/Writer.cpp
+++ wasm/Writer.cpp
@@ -935,6 +935,25 @@
}
}
+ // Undefined symbols from bitcode input files can still exist in the final
+ // output. For defined symbols these get replaces with the symbols in the LTO
+ // object itself.
+ for (BitcodeFile *File : Symtab->BitcodeFiles) {
+ LLVM_DEBUG(dbgs() << "Symtab entries: " << File->getName() << "\n");
+ for (Symbol *Sym : File->getSymbols()) {
+ if (Sym->getFile() != File)
+ continue;
+
+ assert(Sym->isUndefined());
+
+ // (Since this is relocatable output, GC is not performed so symbols must
+ // be live.)
+ assert(Sym->isLive());
+ Sym->setOutputSymbolIndex(SymbolIndex++);
+ SymtabEntries.emplace_back(Sym);
+ }
+ }
+
// For the moment, relocatable output doesn't contain any synthetic functions,
// so no need to look through the Symtab for symbols not referenced by
// Symtab->ObjectFiles.
Index: test/wasm/lto/relocatable-undefined.ll
===================================================================
--- /dev/null
+++ test/wasm/lto/relocatable-undefined.ll
@@ -0,0 +1,36 @@
+; RUN: llvm-as %s -o %t.o
+; RUN: wasm-ld -r -o %t.wasm %t.o
+; RUN: obj2yaml %t.wasm | FileCheck %s
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+ at missing_data = external global i32
+declare i32 @missing_func() local_unnamed_addr
+
+define i32 @foo() {
+entry:
+ %0 = call i32 @missing_func()
+ %1 = load i32, i32* @missing_data, align 4
+ ret i32 %1
+}
+
+
+; CHECK: - Type: CUSTOM
+; CHECK-NEXT: Name: linking
+; CHECK-NEXT: Version: 2
+; CHECK-NEXT: SymbolTable:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Name: foo
+; CHECK-NEXT: Flags: [ ]
+; CHECK-NEXT: Function: 1
+; CHECK-NEXT: - Index: 1
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Name: missing_func
+; CHECK-NEXT: Flags: [ UNDEFINED ]
+; CHECK-NEXT: Function: 0
+; CHECK-NEXT: - Index: 2
+; CHECK-NEXT: Kind: DATA
+; CHECK-NEXT: Name: missing_data
+; CHECK-NEXT: Flags: [ UNDEFINED ]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56947.182643.patch
Type: text/x-patch
Size: 2455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190119/3f552753/attachment.bin>
More information about the llvm-commits
mailing list