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

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 30 13:39:50 PST 2022


keith created this revision.
Herald added a subscriber: mgorny.
keith requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118575

Files:
  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/asm.test
  llvm/tools/llvm-libtool-darwin/CMakeLists.txt
  llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp


Index: llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
===================================================================
--- llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -22,6 +22,7 @@
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/LineIterator.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TextAPI/Architecture.h"
@@ -680,6 +681,9 @@
   if (VersionOption)
     cl::PrintVersionMessage();
 
+  llvm::InitializeAllTargets();
+  llvm::InitializeAllAsmParsers();
+
   Config C = *ConfigOrErr;
   switch (LibraryOperation) {
   case Operation::None:
Index: llvm/tools/llvm-libtool-darwin/CMakeLists.txt
===================================================================
--- llvm/tools/llvm-libtool-darwin/CMakeLists.txt
+++ llvm/tools/llvm-libtool-darwin/CMakeLists.txt
@@ -4,6 +4,7 @@
   Object
   Support
   TextAPI
+  ${LLVM_TARGETS_TO_BUILD}
   )
 
 add_llvm_tool(llvm-libtool-darwin
Index: llvm/test/tools/llvm-libtool-darwin/asm.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-libtool-darwin/asm.test
@@ -0,0 +1,12 @@
+## 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
+
+# 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
Index: llvm/test/tools/llvm-libtool-darwin/Inputs/x86_64-asm.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/test/tools/llvm-libtool-darwin/Inputs/arm64-asm.ll
===================================================================
--- /dev/null
+++ 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
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118575.404409.patch
Type: text/x-patch
Size: 2510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220130/be271a6c/attachment.bin>


More information about the llvm-commits mailing list