2018-06-27 06:20:04 +08:00
|
|
|
// REQUIRES: x86,aarch64
|
2015-08-05 20:03:34 +08:00
|
|
|
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %ta.o
|
|
|
|
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %tb.o
|
2015-11-18 14:11:01 +08:00
|
|
|
// RUN: ld.lld -shared %tb.o -o %ti686.so
|
2015-10-14 00:03:39 +08:00
|
|
|
// RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-linux %s -o %tc.o
|
2015-08-05 20:03:34 +08:00
|
|
|
|
2020-02-13 13:48:45 +08:00
|
|
|
// RUN: not ld.lld %ta.o %tb.o -o /dev/null 2>&1 | \
|
2015-08-05 20:03:34 +08:00
|
|
|
// RUN: FileCheck --check-prefix=A-AND-B %s
|
2015-10-07 17:13:03 +08:00
|
|
|
// A-AND-B: b.o is incompatible with {{.*}}a.o
|
2015-08-05 20:03:34 +08:00
|
|
|
|
2020-02-13 13:48:45 +08:00
|
|
|
// RUN: not ld.lld %tb.o %tc.o -o /dev/null 2>&1 | \
|
2015-08-05 20:03:34 +08:00
|
|
|
// RUN: FileCheck --check-prefix=B-AND-C %s
|
2015-10-07 17:13:03 +08:00
|
|
|
// B-AND-C: c.o is incompatible with {{.*}}b.o
|
2015-08-05 20:03:34 +08:00
|
|
|
|
2020-02-13 13:48:45 +08:00
|
|
|
// RUN: not ld.lld %ta.o %ti686.so -o /dev/null 2>&1 | \
|
2015-09-04 04:03:54 +08:00
|
|
|
// RUN: FileCheck --check-prefix=A-AND-SO %s
|
2015-10-07 17:13:03 +08:00
|
|
|
// A-AND-SO: i686.so is incompatible with {{.*}}a.o
|
2015-09-04 04:03:54 +08:00
|
|
|
|
2020-02-13 13:48:45 +08:00
|
|
|
// RUN: not ld.lld %tc.o %ti686.so -o /dev/null 2>&1 | \
|
2015-09-04 04:03:54 +08:00
|
|
|
// RUN: FileCheck --check-prefix=C-AND-SO %s
|
2015-10-07 17:13:03 +08:00
|
|
|
// C-AND-SO: i686.so is incompatible with {{.*}}c.o
|
2015-09-04 04:03:54 +08:00
|
|
|
|
2020-02-13 13:48:45 +08:00
|
|
|
// RUN: not ld.lld %ti686.so %tc.o -o /dev/null 2>&1 | \
|
2015-09-04 04:03:54 +08:00
|
|
|
// RUN: FileCheck --check-prefix=SO-AND-C %s
|
2015-10-07 17:13:03 +08:00
|
|
|
// SO-AND-C: c.o is incompatible with {{.*}}i686.so
|
|
|
|
|
2020-02-13 13:48:45 +08:00
|
|
|
// RUN: not ld.lld -m elf64ppc %ta.o -o /dev/null 2>&1 | \
|
2015-10-07 17:13:03 +08:00
|
|
|
// RUN: FileCheck --check-prefix=A-ONLY %s
|
2015-10-10 05:07:25 +08:00
|
|
|
// A-ONLY: a.o is incompatible with elf64ppc
|
2015-10-07 17:13:03 +08:00
|
|
|
|
2020-02-13 13:48:45 +08:00
|
|
|
// RUN: not ld.lld -m elf64ppc %tb.o -o /dev/null 2>&1 | \
|
2015-10-07 17:13:03 +08:00
|
|
|
// RUN: FileCheck --check-prefix=B-ONLY %s
|
2015-10-10 05:07:25 +08:00
|
|
|
// B-ONLY: b.o is incompatible with elf64ppc
|
2015-10-07 17:13:03 +08:00
|
|
|
|
2020-02-13 13:48:45 +08:00
|
|
|
// RUN: not ld.lld -m elf64ppc %tc.o -o /dev/null 2>&1 | \
|
2015-10-07 17:13:03 +08:00
|
|
|
// RUN: FileCheck --check-prefix=C-ONLY %s
|
2015-10-10 05:07:25 +08:00
|
|
|
// C-ONLY: c.o is incompatible with elf64ppc
|
2015-10-07 17:13:03 +08:00
|
|
|
|
2020-02-13 13:48:45 +08:00
|
|
|
// RUN: not ld.lld -m elf_i386 %tc.o %ti686.so -o /dev/null 2>&1 | \
|
2015-10-07 17:13:03 +08:00
|
|
|
// RUN: FileCheck --check-prefix=C-AND-SO-I386 %s
|
2015-10-10 05:07:25 +08:00
|
|
|
// C-AND-SO-I386: c.o is incompatible with elf_i386
|
2015-10-07 17:13:03 +08:00
|
|
|
|
2020-02-13 13:48:45 +08:00
|
|
|
// RUN: not ld.lld -m elf_i386 %ti686.so %tc.o -o /dev/null 2>&1 | \
|
2015-10-07 17:13:03 +08:00
|
|
|
// RUN: FileCheck --check-prefix=SO-AND-C-I386 %s
|
2015-10-10 05:07:25 +08:00
|
|
|
// SO-AND-C-I386: c.o is incompatible with elf_i386
|
2015-09-04 04:03:54 +08:00
|
|
|
|
[ELF] Correct error message when OUTPUT_FORMAT is used
Any OUTPUT_FORMAT in a linker script overrides the emulation passed on
the command line, so record the passed bfdname and use that in the error
message about incompatible input files.
This prevents confusing error messages. For example, if you explicitly
pass `-m elf_x86_64` to LLD but accidentally include a linker script
which sets `OUTPUT_FORMAT(elf32-i386)`, LLD would previously complain
about your input files being compatible with elf_x86_64, which isn't the
actual issue, and is confusing because the input files are in fact
x86-64 ELF files.
Interestingly enough, this also prevents a segfault! When we don't pass
`-m` and we have an object file which is incompatible with the
`OUTPUT_FORMAT` set by a linker script, the object file is checked for
compatibility before it's added to the objectFiles vector.
config->emulation, objectFiles, and sharedFiles will all be empty, so
we'll attempt to access bitcodeFiles[0], but bitcodeFiles is also empty,
so we'll segfault. This commit prevents the segfault by adding
OUTPUT_FORMAT as a possible source of machine configuration, and it also
adds an llvm_unreachable to diagnose similar issues in the future.
Differential Revision: https://reviews.llvm.org/D76109
2020-03-13 06:25:36 +08:00
|
|
|
// RUN: echo 'OUTPUT_FORMAT(elf32-i386)' > %t.script
|
|
|
|
// RUN: not ld.lld %t.script %ta.o -o /dev/null 2>&1 | \
|
|
|
|
// RUN: FileCheck --check-prefix=A-AND-SCRIPT %s
|
|
|
|
// RUN: not ld.lld %ta.o %t.script -o /dev/null 2>&1 | \
|
|
|
|
// RUN: FileCheck --check-prefix=A-AND-SCRIPT %s
|
|
|
|
// RUN: not ld.lld -m elf_x86_64 %ta.o %t.script -o /dev/null 2>&1 | \
|
|
|
|
// RUN: FileCheck --check-prefix=A-AND-SCRIPT %s
|
|
|
|
// A-AND-SCRIPT: a.o is incompatible with elf32-i386
|
2015-10-11 11:36:49 +08:00
|
|
|
|
2020-03-14 05:15:58 +08:00
|
|
|
// RUN: echo 'OUTPUT_FORMAT(elf32-i386-freebsd)' > %t-freebsd.script
|
|
|
|
// RUN: not ld.lld %t-freebsd.script %ta.o -o /dev/null 2>&1 | \
|
|
|
|
// RUN: FileCheck --check-prefix=A-AND-FREEBSD-SCRIPT %s
|
|
|
|
// A-AND-FREEBSD-SCRIPT: a.o is incompatible with elf32-i386-freebsd
|
|
|
|
|
2015-10-11 11:36:49 +08:00
|
|
|
// We used to fail to identify this incompatibility and crash trying to
|
|
|
|
// read a 64 bit file as a 32 bit one.
|
|
|
|
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/archive2.s -o %ta.o
|
2018-08-02 19:33:54 +08:00
|
|
|
// RUN: rm -f %t.a
|
2015-10-11 11:36:49 +08:00
|
|
|
// RUN: llvm-ar rc %t.a %ta.o
|
|
|
|
// RUN: llvm-mc -filetype=obj -triple=i686-linux %s -o %tb.o
|
2020-02-13 13:48:45 +08:00
|
|
|
// RUN: not ld.lld %t.a %tb.o 2>&1 -o /dev/null | FileCheck --check-prefix=ARCHIVE %s
|
2016-11-25 04:59:44 +08:00
|
|
|
// ARCHIVE: .a({{.*}}a.o) is incompatible with {{.*}}b.o
|
2015-10-11 11:36:49 +08:00
|
|
|
.global _start
|
|
|
|
_start:
|
2016-04-30 08:49:10 +08:00
|
|
|
.data
|
2015-10-11 11:36:49 +08:00
|
|
|
.long foo
|
|
|
|
|