[llvm-branch-commits] [lld] c7bca45 - [ELF] Fix crash when an input is incompatible with a lazy object file

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Feb 5 23:42:04 PST 2022


Author: Fangrui Song
Date: 2022-02-05T23:40:36-08:00
New Revision: c7bca45103e360ed9cb695d3db519f0639c898d3

URL: https://github.com/llvm/llvm-project/commit/c7bca45103e360ed9cb695d3db519f0639c898d3
DIFF: https://github.com/llvm/llvm-project/commit/c7bca45103e360ed9cb695d3db519f0639c898d3.diff

LOG: [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.

(cherry picked from commit bad1b7fbb0fec532f097ac59805562020f895962)

Added: 
    

Modified: 
    lld/ELF/InputFiles.cpp
    lld/test/ELF/incompatible-ar-first.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index b5510b3b27362..775999a5f534c 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -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;
 }
 

diff  --git a/lld/test/ELF/incompatible-ar-first.s b/lld/test/ELF/incompatible-ar-first.s
index e49171939513c..a82a55a39ed80 100644
--- a/lld/test/ELF/incompatible-ar-first.s
+++ b/lld/test/ELF/incompatible-ar-first.s
@@ -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{{$}}


        


More information about the llvm-branch-commits mailing list