Skip to content

Commit

Permalink
[llvm-libtool-darwin] Fix crash with bitcode asm module
Browse files Browse the repository at this point in the history
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
  • Loading branch information
keith committed Feb 4, 2022
1 parent e55ace6 commit dbed14d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 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
}
7 changes: 7 additions & 0 deletions 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
}
9 changes: 9 additions & 0 deletions 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
9 changes: 9 additions & 0 deletions 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
1 change: 1 addition & 0 deletions llvm/tools/llvm-libtool-darwin/CMakeLists.txt
Expand Up @@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
Object
Support
TextAPI
${LLVM_TARGETS_TO_BUILD}
)

add_llvm_tool(llvm-libtool-darwin
Expand Down
5 changes: 5 additions & 0 deletions llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit dbed14d

Please sign in to comment.