Skip to content

Commit

Permalink
[llvm-libtool-darwin] Print a warning if object file names are repeated
Browse files Browse the repository at this point in the history
Print a warning if `llvm-libtool-darwin` if any of the object
files provided by the user have the same file name.

The tool will now print a warning if there is a name collision across:

* Two object files
* An object file and an object file from within a static library
* Two object files from different static libraries

Here is an example of the error:

```
$ llvm-libtool-darwin -static -o archive.a out.o out.o
error: file 'out.o' was specified multiple times.
in: out.o
in: out.o

$ llvm-libtool-darwin -static -o archive.a out.o
$ llvm-libtool-darwin -static -o combined.a archive.a out.o
error: file 'out.o' was specified multiple times.
in: archive.a
in: out.o
```

This change mimics apple's cctools libtool's behavior which always shows a warning in such cases.

Reviewed By: smeenai

Differential Revision: https://reviews.llvm.org/D113130
  • Loading branch information
Roger Kim authored and smeenai committed Jan 11, 2022
1 parent e9b5b81 commit 4993eff
Show file tree
Hide file tree
Showing 4 changed files with 346 additions and 238 deletions.
45 changes: 30 additions & 15 deletions llvm/test/tools/llvm-libtool-darwin/L-and-l.test
Expand Up @@ -62,29 +62,44 @@
# RUN: llvm-nm --print-armap %t.lib | \
# RUN: FileCheck %s --check-prefix=SINGLE-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines

## Check that if two different files with the same names are explicitly
## specified, the command gives a warning.
# RUN: cp %t-input2.o %t/dirname
# RUN: llvm-libtool-darwin -static -o %t.lib \
# RUN: %t/dirname/%basename_t.tmp-input2.o %t-input2.o 2>&1 | \
# RUN: FileCheck %s --check-prefix=DUPLICATE-INPUT \
# RUN: -DFILE=%basename_t.tmp-input2.o \
# RUN: -DINPUTA=%t/dirname/%basename_t.tmp-input2.o \
# RUN: -DINPUTB=%t-input2.o

# DUPLICATE-INPUT: warning: file '[[FILE]]' was specified multiple times.
# DUPLICATE-INPUT-DAG: [[INPUTA]]
# DUPLICATE-INPUT-DAG: [[INPUTB]]

## -l option combined with an input file:
# RUN: llvm-libtool-darwin -static -o %t.lib %t-input1.o -linput2 -L%t/dirname
# 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

## Specify same -l option twice:
## cctools' libtool raises a warning in this case.
## The warning is not yet implemented for llvm-libtool-darwin.
# RUN: llvm-libtool-darwin -static -o %t.lib -l%basename_t.tmp-input2.o -l%basename_t.tmp-input2.o -L%T
# 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]]-input2.o
# DOUBLE-NAMES-NEXT: [[PREFIX]]-input2.o
## Specify the same file with a -l option and an input file:
# RUN: rm -rf %t/copy
# RUN: mkdir -p %t/copy
# RUN: cp %t-input1.o %t/copy
# RUN: llvm-libtool-darwin -static -o %t.lib \
# RUN: %t/copy/%basename_t.tmp-input1.o -l%basename_t.tmp-input1.o -L%t/copy 2>&1 | \
# RUN: FileCheck %s --check-prefix=DUPLICATE-INPUT -DFILE=%basename_t.tmp-input1.o \
# RUN: -DINPUTA=%t/copy/%basename_t.tmp-input1.o \
# RUN: -DINPUTB=%t/copy/%basename_t.tmp-input1.o

# DOUBLE-SYMBOLS: Archive map
# DOUBLE-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
# DOUBLE-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
# DOUBLE-SYMBOLS-EMPTY:
## Specify same -l option twice:
# RUN: llvm-libtool-darwin -static -o %t.lib -l%basename_t.tmp-input1.o \
# RUN: -l%basename_t.tmp-input1.o -L%t/copy 2>&1 | \
# RUN: FileCheck %s --check-prefix=DUPLICATE-INPUT \
# RUN: -DFILE=%basename_t.tmp-input1.o \
# RUN: -DINPUTA=%t/copy/%basename_t.tmp-input1.o \
# RUN: -DINPUTB=%t/copy/%basename_t.tmp-input1.o

## Check that an error is thrown when the input library cannot be found:
# RUN: not llvm-libtool-darwin -static -o %t.lib -lfile-will-not-exist.o 2>&1 | \
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/tools/llvm-libtool-darwin/archive-flattening.test
Expand Up @@ -59,6 +59,17 @@
# BOTH-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
# BOTH-SYMBOLS-EMPTY:

# RUN: llvm-libtool-darwin -static -o %t.lib %t-x86_64.bc %t.correct.ar %t-input1.o 2>&1 | \
# RUN: FileCheck %s --check-prefix=DUPLICATE-INPUT -DFILEA=%basename_t.tmp-input1.o \
# RUN: -DPATHA=%t-input1.o -DFILEB=%basename_t.tmp-x86_64.bc -DPATHB=%t-x86_64.bc -DPATHCORRECT=%t.correct.ar

# DUPLICATE-INPUT: warning: file '[[FILEA]]' was specified multiple times.
# DUPLICATE-INPUT-DAG: [[PATHA]]
# DUPLICATE-INPUT-DAG: [[PATHCORRECT]]
# DUPLICATE-INPUT: file '[[FILEB]]' was specified multiple times.
# DUPLICATE-INPUT-DAG: [[PATHB]]
# DUPLICATE-INPUT-DAG: [[PATHCORRECT]]

## Cannot read archive:
# RUN: echo '!<arch>' > %t-invalid-archive.lib
# RUN: echo 'invalid' >> %t-invalid-archive.lib
Expand Down
28 changes: 13 additions & 15 deletions llvm/test/tools/llvm-libtool-darwin/create-static-lib.test
Expand Up @@ -50,21 +50,19 @@
# OVERWRITE-SYMBOLS-EMPTY:

## Duplicate a binary:
## cctools' libtool raises a warning in this case.
## The warning is not yet implemented for llvm-libtool-darwin.
# RUN: llvm-libtool-darwin -static -o %t.lib %t-input1.o %t-input2.o %t-input1.o 2>&1 | \
# RUN: FileCheck %s --allow-empty --implicit-check-not={{.}}
# RUN: llvm-ar t %t.lib | \
# RUN: FileCheck %s --check-prefix=DUPLICATE-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
# RUN: llvm-nm --print-armap %t.lib | \
# RUN: FileCheck %s --check-prefix=DUPLICATE-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
# RUN: FileCheck %s --check-prefix=DUPLICATE-INPUT -DFILE=%basename_t.tmp-input1.o \
# RUN: -DINPUTA=%t-input1.o -DINPUTB=%t-input1.o

# DUPLICATE-NAMES: [[PREFIX]]-input1.o
# DUPLICATE-NAMES-NEXT: [[PREFIX]]-input2.o
# DUPLICATE-NAMES-NEXT: [[PREFIX]]-input1.o
# DUPLICATE-INPUT: warning: file '[[FILE]]' was specified multiple times.
# DUPLICATE-INPUT-DAG: [[INPUTA]]
# DUPLICATE-INPUT-DAG: [[INPUTB]]

# DUPLICATE-SYMBOLS: Archive map
# DUPLICATE-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
# DUPLICATE-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
# DUPLICATE-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
# DUPLICATE-SYMBOLS-EMPTY:
## Make sure we can combine object files with the same name if
## they are for different architectures.
# RUN: mkdir -p %t/arm64 %t/armv7
# RUN: llvm-as %S/Inputs/arm64-ios.ll -o %t/arm64/out.bc
# RUN: llvm-as %S/Inputs/armv7-ios.ll -o %t/armv7/out.bc
## Command output should be empty.
# RUN: llvm-libtool-darwin -static %t/arm64/out.bc %t/armv7/out.bc -o %t.lib 2>&1 | \
# RUN: FileCheck %s --implicit-check-not=warning: --allow-empty

0 comments on commit 4993eff

Please sign in to comment.