[llvm] dbed14d - [llvm-libtool-darwin] Fix crash with bitcode asm module

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 4 10:55:41 PST 2022


Author: Keith Smiley
Date: 2022-02-04T10:54:27-08:00
New Revision: dbed14d215fed740e0e26784e7b8b00b68f5e680

URL: https://github.com/llvm/llvm-project/commit/dbed14d215fed740e0e26784e7b8b00b68f5e680
DIFF: https://github.com/llvm/llvm-project/commit/dbed14d215fed740e0e26784e7b8b00b68f5e680.diff

LOG: [llvm-libtool-darwin] Fix crash with bitcode asm module

When using llvm-libtool-darwin with LTO building llvm itself, it crashed
on a file with an asm module in the bitcode. This fixes that by
correctly registering the targets for this.

Differential Revision: https://reviews.llvm.org/D118575

Added: 
    llvm/test/tools/llvm-libtool-darwin/Inputs/arm64-asm.ll
    llvm/test/tools/llvm-libtool-darwin/Inputs/x86_64-asm.ll
    llvm/test/tools/llvm-libtool-darwin/arm64-asm.test
    llvm/test/tools/llvm-libtool-darwin/x86_64-asm.test

Modified: 
    llvm/tools/llvm-libtool-darwin/CMakeLists.txt
    llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-libtool-darwin/Inputs/arm64-asm.ll b/llvm/test/tools/llvm-libtool-darwin/Inputs/arm64-asm.ll
new file mode 100644
index 0000000000000..41385f6950844
--- /dev/null
+++ b/llvm/test/tools/llvm-libtool-darwin/Inputs/arm64-asm.ll
@@ -0,0 +1,7 @@
+target triple = "arm64-apple-macosx11.0.0"
+
+module asm ".desc ___crashreporter_info__, 0x10"
+
+define void @somesymbol() {
+  ret void
+}

diff  --git a/llvm/test/tools/llvm-libtool-darwin/Inputs/x86_64-asm.ll b/llvm/test/tools/llvm-libtool-darwin/Inputs/x86_64-asm.ll
new file mode 100644
index 0000000000000..5e8b6c61d7783
--- /dev/null
+++ b/llvm/test/tools/llvm-libtool-darwin/Inputs/x86_64-asm.ll
@@ -0,0 +1,7 @@
+target triple = "x86_64-apple-macosx11.0.0"
+
+module asm ".desc ___crashreporter_info__, 0x10"
+
+define void @somesymbol() {
+  ret void
+}

diff  --git a/llvm/test/tools/llvm-libtool-darwin/arm64-asm.test b/llvm/test/tools/llvm-libtool-darwin/arm64-asm.test
new file mode 100644
index 0000000000000..6a50451dd5efe
--- /dev/null
+++ b/llvm/test/tools/llvm-libtool-darwin/arm64-asm.test
@@ -0,0 +1,9 @@
+# REQUIRES: aarch64-registered-target
+## This tests that archives are correctly created when the llvm
+## has native assembly info
+
+# RUN: llvm-as %p/Inputs/arm64-asm.ll -o %t-arm64-asm.bc
+# RUN: llvm-libtool-darwin -static -o %t-arm64.lib %t-arm64-asm.bc
+# RUN: llvm-nm %t-arm64.lib | FileCheck %s
+
+# CHECK: T somesymbol

diff  --git a/llvm/test/tools/llvm-libtool-darwin/x86_64-asm.test b/llvm/test/tools/llvm-libtool-darwin/x86_64-asm.test
new file mode 100644
index 0000000000000..2b364ba741e5c
--- /dev/null
+++ b/llvm/test/tools/llvm-libtool-darwin/x86_64-asm.test
@@ -0,0 +1,9 @@
+# REQUIRES: x86-registered-target
+## This tests that archives are correctly created when the llvm
+## has native assembly info
+
+# RUN: llvm-as %p/Inputs/x86_64-asm.ll -o %t-x86_64-asm.bc
+# RUN: llvm-libtool-darwin -static -o %t-x86_64.lib %t-x86_64-asm.bc
+# RUN: llvm-nm %t-x86_64.lib | FileCheck %s
+
+# CHECK: T somesymbol

diff  --git a/llvm/tools/llvm-libtool-darwin/CMakeLists.txt b/llvm/tools/llvm-libtool-darwin/CMakeLists.txt
index 65495ce9d5334..a06d107e1557b 100644
--- a/llvm/tools/llvm-libtool-darwin/CMakeLists.txt
+++ b/llvm/tools/llvm-libtool-darwin/CMakeLists.txt
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
   Object
   Support
   TextAPI
+  ${LLVM_TARGETS_TO_BUILD}
   )
 
 add_llvm_tool(llvm-libtool-darwin

diff  --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
index 8b6b2645d1f81..cd56e10a30af5 100644
--- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -21,6 +21,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/LineIterator.h"
+#include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
@@ -682,6 +683,10 @@ int main(int Argc, char **Argv) {
   if (VersionOption)
     cl::PrintVersionMessage();
 
+  llvm::InitializeAllTargetInfos();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmParsers();
+
   Config C = *ConfigOrErr;
   switch (LibraryOperation) {
   case Operation::None:


        


More information about the llvm-commits mailing list