[PATCH] D71632: [lld][WebAssembly] Fail if bitcode objects are pulled in after LTO
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 17 14:51:12 PST 2019
sbc100 updated this revision to Diff 234396.
sbc100 added a comment.
- spelling
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71632/new/
https://reviews.llvm.org/D71632
Files:
lld/test/wasm/lto/Inputs/builtins.ll
lld/test/wasm/lto/builtins.ll
lld/wasm/InputFiles.cpp
lld/wasm/InputFiles.h
lld/wasm/SymbolTable.cpp
Index: lld/wasm/SymbolTable.cpp
===================================================================
--- lld/wasm/SymbolTable.cpp
+++ lld/wasm/SymbolTable.cpp
@@ -65,6 +65,9 @@
// Because all bitcode files that the program consists of are passed
// to the compiler at once, it can do whole-program optimization.
void SymbolTable::addCombinedLTOObject() {
+ // Prevent further LTO objects being included
+ BitcodeFile::doneLTO = true;
+
if (bitcodeFiles.empty())
return;
Index: lld/wasm/InputFiles.h
===================================================================
--- lld/wasm/InputFiles.h
+++ lld/wasm/InputFiles.h
@@ -160,6 +160,10 @@
void parse();
std::unique_ptr<llvm::lto::InputFile> obj;
+
+ // Set to true once LTO is complete in order prevent further bitcode objects
+ // being added.
+ static bool doneLTO;
};
// Will report a fatal() error if the input buffer is not a valid bitcode
Index: lld/wasm/InputFiles.cpp
===================================================================
--- lld/wasm/InputFiles.cpp
+++ lld/wasm/InputFiles.cpp
@@ -537,7 +537,16 @@
return symtab->addDefinedData(name, flags, &f, nullptr, 0, 0);
}
+bool BitcodeFile::doneLTO = false;
+
void BitcodeFile::parse() {
+ if (doneLTO) {
+ error(toString(mb.getBufferIdentifier()) +
+ ": attempt to add bitcode file after LTO.");
+ error("This is most often caused by builtin functions into LTO objects.");
+ return;
+ }
+
obj = check(lto::InputFile::create(MemoryBufferRef(
mb.getBuffer(), saver.save(archiveName + mb.getBufferIdentifier()))));
Triple t(obj->getTargetTriple());
Index: lld/test/wasm/lto/builtins.ll
===================================================================
--- /dev/null
+++ lld/test/wasm/lto/builtins.ll
@@ -0,0 +1,26 @@
+; References to builtin symbols can be created for the first time during LTO.
+; If those builtins are themselved implemented in lazy LTO objects that are
+; otherwise not referenced in the link, this can result in bitcode being added
+; to the link *after* LTO, which will not work.
+; Verify that we detect this and report a meaningful error.
+
+; RUN: llvm-as %s -o %t.o
+; RUN: llvm-as %p/Inputs/builtins.ll -o %t.truncsfhf2.o
+; RUN: rm -f %t.a
+; RUN: llvm-ar rcs %t.a %t.truncsfhf2.o
+; RUN: not wasm-ld --export-all %t.o %t.a -o %t.wasm 2>&1 | FileCheck %s
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+ at g_float = global float 0.0
+ at g_half = global half 0.0
+
+define void @_start() {
+ %val1 = load float, float* @g_float
+ %v0 = fptrunc float %val1 to half
+ store half %v0, half* @g_half
+ ret void
+}
+
+; CHECK: wasm-ld: error: {{.*}}truncsfhf2.o: attempt to add bitcode file after LTO.
Index: lld/test/wasm/lto/Inputs/builtins.ll
===================================================================
--- /dev/null
+++ lld/test/wasm/lto/Inputs/builtins.ll
@@ -0,0 +1,6 @@
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+define half @__truncsfhf2(float) {
+ ret half 0.0
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71632.234396.patch
Type: text/x-patch
Size: 3101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191217/8075cddf/attachment.bin>
More information about the llvm-commits
mailing list