Skip to content

Commit bad1b7f

Browse files
committed
[ELF] Fix crash when an input is incompatible with a lazy object file
The diagnostic is concise. It is ok because the case is rare.
1 parent b4626f2 commit bad1b7f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,17 @@ static bool isCompatible(InputFile *file) {
152152
return false;
153153
}
154154

155-
InputFile *existing;
155+
InputFile *existing = nullptr;
156156
if (!objectFiles.empty())
157157
existing = objectFiles[0];
158158
else if (!sharedFiles.empty())
159159
existing = sharedFiles[0];
160160
else if (!bitcodeFiles.empty())
161161
existing = bitcodeFiles[0];
162-
else
163-
llvm_unreachable("Must have -m, OUTPUT_FORMAT or existing input file to "
164-
"determine target emulation");
165-
166-
error(toString(file) + " is incompatible with " + toString(existing));
162+
std::string with;
163+
if (existing)
164+
with = " with " + toString(existing);
165+
error(toString(file) + " is incompatible" + with);
167166
return false;
168167
}
169168

lld/test/ELF/incompatible-ar-first.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
// * -m was not used.
1111
// CHECK: .a({{.*}}a.o) is incompatible with {{.*}}b.o
1212

13+
// RUN: not ld.lld --start-lib %ta.o --end-lib %tb.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK2
14+
15+
// CHECK2: {{.*}}b.o is incompatible{{$}}

0 commit comments

Comments
 (0)