[lld] r360295 - [lld-link] initialize targets and asmparsers before invoking lib
Bob Haarman via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 15:11:03 PDT 2019
Author: inglorion
Date: Wed May 8 15:11:02 2019
New Revision: 360295
URL: http://llvm.org/viewvc/llvm-project?rev=360295&view=rev
Log:
[lld-link] initialize targets and asmparsers before invoking lib
Summary:
When using lld-link to build static libraries containing object files
with module assembly, the program would crash with "Assertion `T &&
T->hasMCAsmParser()' failed". This change causes the code in lld-link
that initialized Targets, TargetInfos, and AsmParsers (which already
existed) to be run before entering the lib building path (which needs
it). This avoids the error (and is what llvm-lib and llvm-ar do, too).
Fixes PR41803.
Reviewers: ruiu, rnk, hans
Reviewed By: ruiu
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D61699
Added:
lld/trunk/test/COFF/lib-module-asm.ll
Modified:
lld/trunk/COFF/Driver.cpp
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=360295&r1=360294&r2=360295&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Wed May 8 15:11:02 2019
@@ -975,6 +975,13 @@ void LinkerDriver::maybeExportMinGWSymbo
}
void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
+ // Needed for LTO.
+ InitializeAllTargetInfos();
+ InitializeAllTargets();
+ InitializeAllTargetMCs();
+ InitializeAllAsmParsers();
+ InitializeAllAsmPrinters();
+
// If the first command line argument is "/lib", link.exe acts like lib.exe.
// We call our own implementation of lib.exe that understands bitcode files.
if (ArgsArr.size() > 1 && StringRef(ArgsArr[1]).equals_lower("/lib")) {
@@ -983,13 +990,6 @@ void LinkerDriver::link(ArrayRef<const c
return;
}
- // Needed for LTO.
- InitializeAllTargetInfos();
- InitializeAllTargets();
- InitializeAllTargetMCs();
- InitializeAllAsmParsers();
- InitializeAllAsmPrinters();
-
// Parse command line options.
ArgParser Parser;
opt::InputArgList Args = Parser.parseLINK(ArgsArr);
Added: lld/trunk/test/COFF/lib-module-asm.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/lib-module-asm.ll?rev=360295&view=auto
==============================================================================
--- lld/trunk/test/COFF/lib-module-asm.ll (added)
+++ lld/trunk/test/COFF/lib-module-asm.ll Wed May 8 15:11:02 2019
@@ -0,0 +1,21 @@
+; PR41803: llvm-link /lib on object with module asm crashes
+; RUN: rm -f %t.lib
+; RUN: llvm-as -o %t.obj %s
+; RUN: lld-link /lib /out:%t.lib %t.obj
+; RUN: llvm-nm -M %t.lib | FileCheck %s
+
+target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
+target triple = "i386-pc-windows-msvc19.11.0"
+
+module asm ".global global_asm_sym"
+module asm "global_asm_sym:"
+module asm "local_asm_sym:"
+module asm ".long undef_asm_sym"
+
+; CHECK: Archive map
+; CHECK-NEXT: global_asm_sym in {{.*}}lib-module-asm.ll.tmp.obj
+
+; CHECK: lib-module-asm.ll.tmp.obj:{{$}}
+; CHECK-NEXT: T global_asm_sym
+; CHECK-NEXT: t local_asm_sym
+; CHECK-NEXT: U undef_asm_sym
More information about the llvm-commits
mailing list