Skip to content

Commit

Permalink
[llvm-libtool-darwin] Add support for LLVM bitcode files
Browse files Browse the repository at this point in the history
This diff adds support for LLVM bitcode objects to llvm-libtool-darwin.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D88722
  • Loading branch information
Paul-Antoine Arras authored and Alexander Shaposhnikov committed Oct 29, 2020
1 parent 7df80a1 commit 05f7b68
Show file tree
Hide file tree
Showing 15 changed files with 310 additions and 26 deletions.
6 changes: 6 additions & 0 deletions llvm/test/tools/llvm-libtool-darwin/Inputs/arm64-ios.ll
@@ -0,0 +1,6 @@
target triple = "arm64-apple-ios8.0.0"

define void @_arm64(){
entry:
ret void
}
6 changes: 6 additions & 0 deletions llvm/test/tools/llvm-libtool-darwin/Inputs/arm64e-ios.ll
@@ -0,0 +1,6 @@
target triple = "arm64e-apple-ios8.0.0"

define void @_arm64e(){
entry:
ret void
}
6 changes: 6 additions & 0 deletions llvm/test/tools/llvm-libtool-darwin/Inputs/armv7-ios.ll
@@ -0,0 +1,6 @@
target triple = "thumbv7-apple-ios8.0.0"

define void @_armv7() {
entry:
ret void
}
6 changes: 6 additions & 0 deletions llvm/test/tools/llvm-libtool-darwin/Inputs/x86_64-osx-2.ll
@@ -0,0 +1,6 @@
target triple = "x86_64-apple-macosx10.15.0"

define void @_x86_64_2() {
entry:
ret void
}
6 changes: 6 additions & 0 deletions llvm/test/tools/llvm-libtool-darwin/Inputs/x86_64-osx.ll
@@ -0,0 +1,6 @@
target triple = "x86_64-apple-macosx10.15.0"

define void @_x86_64() {
entry:
ret void
}
6 changes: 6 additions & 0 deletions llvm/test/tools/llvm-libtool-darwin/Inputs/x86_64h-osx.ll
@@ -0,0 +1,6 @@
target triple = "x86_64h-apple-macosx10.15.0"

define void @_x86_64_h() {
entry:
ret void
}
18 changes: 12 additions & 6 deletions llvm/test/tools/llvm-libtool-darwin/archive-flattening.test
Expand Up @@ -2,24 +2,27 @@

# RUN: yaml2obj %S/Inputs/input1.yaml -o %t-input1.o
# RUN: yaml2obj %S/Inputs/input2.yaml -o %t-input2.o
# RUN: llvm-as %S/Inputs/x86_64-osx.ll -o %t-x86_64.bc

## Input a correct archive:
# RUN: rm -f %t.correct.ar
# RUN: llvm-ar cr %t.correct.ar %t-input1.o %t-input2.o
# RUN: llvm-ar cr %t.correct.ar %t-x86_64.bc %t-input1.o %t-input2.o
# RUN: llvm-libtool-darwin -static -o %t.lib %t.correct.ar

## Check that binaries are present:
# RUN: llvm-ar t %t.lib | \
# RUN: FileCheck %s --check-prefix=CHECK-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp

# CHECK-NAMES: [[PREFIX]]-input1.o
# CHECK-NAMES: [[PREFIX]]-x86_64.bc
# CHECK-NAMES-NEXT: [[PREFIX]]-input1.o
# CHECK-NAMES-NEXT: [[PREFIX]]-input2.o

## Check that symbols are present:
# RUN: llvm-nm --print-armap %t.lib | \
# RUN: FileCheck %s --check-prefix=CHECK-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines

# CHECK-SYMBOLS: Archive map
# CHECK-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.bc
# CHECK-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
# CHECK-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
# CHECK-SYMBOLS-EMPTY:
Expand All @@ -30,24 +33,27 @@

# FORMAT: Archive : [[ARCHIVE]]
# FORMAT-NEXT: __.SYMDEF
# FORMAT-NEXT: [[PREFIX]]-x86_64.bc
# FORMAT-NEXT: [[PREFIX]]-input1.o
# FORMAT-NEXT: [[PREFIX]]-input2.o
# FORMAT-NOT: {{.}}

## Passing both archive and object file:
# RUN: llvm-libtool-darwin -static -o %t.lib %t-input2.o %t.correct.ar %t-input1.o
## Passing both archive, bitcode and object file:
# RUN: llvm-libtool-darwin -static -o %t.lib %t-x86_64.bc %t.correct.ar %t-input1.o
# RUN: llvm-ar t %t.lib | \
# RUN: FileCheck %s --check-prefix=BOTH-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
# RUN: llvm-nm --print-armap %t.lib | \
# RUN: FileCheck %s --check-prefix=BOTH-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines

# BOTH-NAMES: [[PREFIX]]-input2.o
# BOTH-NAMES: [[PREFIX]]-x86_64.bc
# BOTH-NAMES-NEXT: [[PREFIX]]-x86_64.bc
# BOTH-NAMES-NEXT: [[PREFIX]]-input1.o
# BOTH-NAMES-NEXT: [[PREFIX]]-input2.o
# BOTH-NAMES-NEXT: [[PREFIX]]-input1.o

# BOTH-SYMBOLS: Archive map
# BOTH-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
# BOTH-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.bc
# BOTH-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.bc
# BOTH-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
# BOTH-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
# BOTH-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
Expand Down
28 changes: 18 additions & 10 deletions llvm/test/tools/llvm-libtool-darwin/cpu-subtype-matching.test
@@ -1,22 +1,26 @@
## This test checks that the CPU subtype matching logic is handled correctly.

# RUN: yaml2obj %s --docnum=1 -o %t.armv6
# RUN: yaml2obj %s --docnum=2 -o %t.armv7
# RUN: yaml2obj %s --docnum=1 -o %t-armv6.obj
# RUN: yaml2obj %s --docnum=2 -o %t-armv7.obj
# RUN: llvm-as %p/Inputs/arm64-ios.ll -o %t-arm64.bc
# RUN: llvm-as %p/Inputs/armv7-ios.ll -o %t-armv7.bc

# RUN: llvm-libtool-darwin -static -o %t.lib %t.armv6 %t.armv7 -arch_only armv7
# RUN: llvm-libtool-darwin -static -o %t.lib %t-armv6.obj %t-armv7.obj %t-arm64.bc %t-armv7.bc -arch_only armv7

## Check that only armv7 binary is present:
# RUN: llvm-ar t %t.lib | \
# RUN: FileCheck %s --check-prefix=ARM-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp

# ARM-NAMES: [[PREFIX]].armv7
# ARM-NAMES: [[PREFIX]]-armv7.obj
# ARM-NAMES-NEXT: [[PREFIX]]-armv7.bc

## Check that only armv7 symbol is present:
# RUN: llvm-nm --print-armap %t.lib | \
# RUN: FileCheck %s --check-prefix=ARM-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines

# ARM-SYMBOLS: Archive map
# ARM-SYMBOLS-NEXT: _armv7 in [[PREFIX]].armv7
# ARM-SYMBOLS-NEXT: _armv7 in [[PREFIX]]-armv7.obj
# ARM-SYMBOLS-NEXT: _armv7 in [[PREFIX]]-armv7.bc
# ARM-SYMBOLS-EMPTY:

## armv6.yaml
Expand Down Expand Up @@ -133,23 +137,27 @@ LinkEditData:
- ''
...

# RUN: yaml2obj %s --docnum=3 -o %t.x86_64
# RUN: yaml2obj %s --docnum=4 -o %t.x86_64_h
# RUN: yaml2obj %s --docnum=3 -o %t-x86_64.obj
# RUN: yaml2obj %s --docnum=4 -o %t-x86_64_h.obj
# RUN: llvm-as %p/Inputs/x86_64-osx.ll -o %t-x86_64.bc
# RUN: llvm-as %p/Inputs/x86_64h-osx.ll -o %t-x86_64_h.bc

# RUN: llvm-libtool-darwin -static -o %t.lib %t.x86_64 %t.x86_64_h -arch_only x86_64
# RUN: llvm-libtool-darwin -static -o %t.lib %t-x86_64.obj %t-x86_64_h.obj %t-x86_64.bc %t-x86_64_h.bc -arch_only x86_64

## Check that only x86_64 binary is present:
# RUN: llvm-ar t %t.lib | \
# RUN: FileCheck %s --check-prefix=X86-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp

# X86-NAMES: [[PREFIX]].x86_64
# X86-NAMES: [[PREFIX]]-x86_64.obj
# X86-NAMES-NEXT: [[PREFIX]]-x86_64.bc

## Check that only x86_64 symbol is present:
# RUN: llvm-nm --print-armap %t.lib | \
# RUN: FileCheck %s --check-prefix=X86-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines

# X86-SYMBOLS: Archive map
# X86-SYMBOLS-NEXT: _x86_64 in [[PREFIX]].x86_64
# X86-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.obj
# X86-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.bc
# X86-SYMBOLS-EMPTY:

## x86_64.yaml
Expand Down
6 changes: 5 additions & 1 deletion llvm/test/tools/llvm-libtool-darwin/create-static-lib.test
Expand Up @@ -2,16 +2,18 @@

# RUN: yaml2obj %S/Inputs/input1.yaml -o %t-input1.o
# RUN: yaml2obj %S/Inputs/input2.yaml -o %t-input2.o
# RUN: llvm-as %S/Inputs/x86_64-osx.ll -o %t-x86_64.bc

# RUN: rm -rf %t.lib
# RUN: llvm-libtool-darwin -static -o %t.lib %t-input1.o %t-input2.o
# RUN: llvm-libtool-darwin -static -o %t.lib %t-input1.o %t-input2.o %t-x86_64.bc

## Check that binaries are present:
# RUN: llvm-ar t %t.lib | \
# RUN: FileCheck %s --check-prefix=CHECK-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp

# CHECK-NAMES: [[PREFIX]]-input1.o
# CHECK-NAMES-NEXT: [[PREFIX]]-input2.o
# CHECK-NAMES-NEXT: [[PREFIX]]-x86_64.bc

## Check that symbols are present:
# RUN: llvm-nm --print-armap %t.lib | \
Expand All @@ -20,6 +22,7 @@
# CHECK-SYMBOLS: Archive map
# CHECK-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
# CHECK-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
# CHECK-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.bc
# CHECK-SYMBOLS-EMPTY:

## Check that output archive is in Darwin format:
Expand All @@ -30,6 +33,7 @@
# FORMAT-NEXT: __.SYMDEF
# FORMAT-NEXT: [[PREFIX]]-input1.o
# FORMAT-NEXT: [[PREFIX]]-input2.o
# FORMAT-NEXT: [[PREFIX]]-x86_64.bc
# FORMAT-NOT: {{.}}

## Check that the output file is overwritten:
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/tools/llvm-libtool-darwin/filelist.test
Expand Up @@ -2,10 +2,12 @@

# RUN: yaml2obj %S/Inputs/input1.yaml -o %t-input1.o
# RUN: yaml2obj %S/Inputs/input2.yaml -o %t-input2.o
# RUN: llvm-as %S/Inputs/x86_64-osx.ll -o %t-x86_64.bc

## Passing files in a listfile:
# RUN: echo %t-input1.o > %t.files.txt
# RUN: echo %t-input2.o >> %t.files.txt
# RUN: echo %t-x86_64.bc >> %t.files.txt
# RUN: llvm-libtool-darwin -static -o %t.lib -filelist %t.files.txt

## Check that binaries are present:
Expand All @@ -14,6 +16,7 @@

# CHECK-NAMES: [[PREFIX]]-input1.o
# CHECK-NAMES-NEXT: [[PREFIX]]-input2.o
# CHECK-NAMES-NEXT: [[PREFIX]]-x86_64.bc

## Check that symbols are present:
# RUN: llvm-nm --print-armap %t.lib | \
Expand All @@ -22,6 +25,7 @@
# CHECK-SYMBOLS: Archive map
# CHECK-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
# CHECK-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
# CHECK-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.bc
# CHECK-SYMBOLS-EMPTY:

# RUN: rm -rf %t/dirname && mkdir -p %t/dirname
Expand Down
@@ -0,0 +1,86 @@
## This test checks that a universal bitcode file is flattened correctly.

# RUN: llvm-as %S/Inputs/arm64-ios.ll -o %t-arm64.bc
# RUN: llvm-as %S/Inputs/x86_64-osx.ll -o %t-x86_64.bc
# RUN: llvm-as %S/Inputs/x86_64-osx-2.ll -o %t-x86_64-2.bc
# RUN: llvm-lipo %t-arm64.bc %t-x86_64.bc -create -output %t-universal.o

# RUN: llvm-libtool-darwin -static -o %t.lib %t-universal.o -arch_only arm64

## Check that the binary is present:
# RUN: llvm-ar t %t.lib | \
# RUN: FileCheck %s --check-prefix=CHECK-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp

# CHECK-NAMES: [[PREFIX]]-universal.o

## Check that symbols are present:
# RUN: llvm-nm --print-armap %t.lib | \
# RUN: FileCheck %s --check-prefix=CHECK-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines

# CHECK-SYMBOLS: Archive map
# CHECK-SYMBOLS-NEXT: _arm64 in [[PREFIX]]-universal.o
# CHECK-SYMBOLS-EMPTY:

## Check that the output archive is in Darwin format:
# RUN: llvm-objdump --macho --archive-headers %t.lib | \
# RUN: FileCheck %s --check-prefix=FORMAT -DPREFIX=%basename_t.tmp -DARCHIVE=%t.lib

# FORMAT: Archive : [[ARCHIVE]]
# FORMAT-NEXT: __.SYMDEF
# FORMAT-NEXT: [[PREFIX]]-universal.o
# FORMAT-NOT: {{.}}

## Passing both a universal file and a bitcode file:
# RUN: llvm-libtool-darwin -static -o %t.lib %t-universal.o %t-x86_64-2.bc -arch_only x86_64
# RUN: llvm-ar t %t.lib | \
# RUN: FileCheck %s --check-prefix=BOTH-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
# RUN: llvm-nm --print-armap %t.lib | \
# RUN: FileCheck %s --check-prefix=BOTH-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines

# BOTH-NAMES: [[PREFIX]]-universal.o
# BOTH-NAMES-NEXT: [[PREFIX]]-x86_64-2.bc

# BOTH-SYMBOLS: Archive map
# BOTH-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-universal.o
# BOTH-SYMBOLS-NEXT: _x86_64_2 in [[PREFIX]]-x86_64-2.bc
# BOTH-SYMBOLS-EMPTY:

## Passing both a universal file and a bitcode file but filtering out the object file:
# RUN: llvm-libtool-darwin -static -o %t.lib %t-universal.o %t-x86_64.bc -arch_only arm64
# RUN: llvm-ar t %t.lib | \
# RUN: FileCheck %s --check-prefix=CHECK-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
# RUN: llvm-nm --print-armap %t.lib | \
# RUN: FileCheck %s --check-prefix=CHECK-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines

## Universal file containing an archive:
# RUN: rm -f %t.ar
# RUN: llvm-ar cr %t.ar %t-x86_64.bc %t-x86_64-2.bc
# RUN: llvm-lipo %t.ar -create -output %t-fat-with-archive.o
# RUN: llvm-libtool-darwin -static -o %t.lib %t-fat-with-archive.o
# RUN: llvm-ar t %t.lib | \
# RUN: FileCheck %s --check-prefix=ARCHIVE-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
# RUN: llvm-nm --print-armap %t.lib | \
# RUN: FileCheck %s --check-prefix=ARCHIVE-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines

# ARCHIVE-NAMES: [[PREFIX]]-x86_64.bc
# ARCHIVE-NAMES-NEXT: [[PREFIX]]-x86_64-2.bc

# ARCHIVE-SYMBOLS: Archive map
# ARCHIVE-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.bc
# ARCHIVE-SYMBOLS-NEXT: _x86_64_2 in [[PREFIX]]-x86_64-2.bc
# ARCHIVE-SYMBOLS-EMPTY:

## Allow arch_only to be specified more than once (pick the last one):
# RUN: llvm-libtool-darwin -static -o %t.lib %t-universal.o -arch_only arm64 -arch_only x86_64
# RUN: llvm-ar t %t.lib | \
# RUN: FileCheck %s --check-prefix=DOUBLE-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
# RUN: llvm-nm --print-armap %t.lib | \
# RUN: FileCheck %s --check-prefix=DOUBLE-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines

# DOUBLE-NAMES: [[PREFIX]]-universal.o

# DOUBLE-SYMBOLS: Archive map
# DOUBLE-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-universal.o
# DOUBLE-SYMBOLS-EMPTY:


0 comments on commit 05f7b68

Please sign in to comment.