Skip to content

Commit

Permalink
[ELF] Fix crash when an input is incompatible with a lazy object file
Browse files Browse the repository at this point in the history
The diagnostic is concise. It is ok because the case is rare.
  • Loading branch information
MaskRay committed Feb 6, 2022
1 parent b4626f2 commit bad1b7f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lld/ELF/InputFiles.cpp
Expand Up @@ -152,18 +152,17 @@ static bool isCompatible(InputFile *file) {
return false;
}

InputFile *existing;
InputFile *existing = nullptr;
if (!objectFiles.empty())
existing = objectFiles[0];
else if (!sharedFiles.empty())
existing = sharedFiles[0];
else if (!bitcodeFiles.empty())
existing = bitcodeFiles[0];
else
llvm_unreachable("Must have -m, OUTPUT_FORMAT or existing input file to "
"determine target emulation");

error(toString(file) + " is incompatible with " + toString(existing));
std::string with;
if (existing)
with = " with " + toString(existing);
error(toString(file) + " is incompatible" + with);
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions lld/test/ELF/incompatible-ar-first.s
Expand Up @@ -10,3 +10,6 @@
// * -m was not used.
// CHECK: .a({{.*}}a.o) is incompatible with {{.*}}b.o

// RUN: not ld.lld --start-lib %ta.o --end-lib %tb.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK2

// CHECK2: {{.*}}b.o is incompatible{{$}}

0 comments on commit bad1b7f

Please sign in to comment.