[lld] c951edb - [LLD][COFF] Identify /GL object files which are inside libraries

Pengxuan Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 9 12:32:48 PDT 2022


Author: Pengxuan Zheng
Date: 2022-08-09T12:32:35-07:00
New Revision: c951edb7b22e709e50b8ae2ea6bce46f1d7d2741

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

LOG: [LLD][COFF] Identify /GL object files which are inside libraries

With D26647, we can already identify input object files compiled by cl.exe with
/GL. It seems to be helpful to do the same and print an error message for those
object files compiled with /GL but are inside libraries/archives too.

Reviewed By: rnk, thieta

Differential Revision: https://reviews.llvm.org/D131458

Added: 
    lld/test/COFF/Inputs/cl-gl.lib

Modified: 
    lld/COFF/Driver.cpp
    lld/test/COFF/cl-gl.test

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 1e080b190027a..4f7b9e469668a 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -279,6 +279,10 @@ void LinkerDriver::addArchiveBuffer(MemoryBufferRef mb, StringRef symName,
   } else if (magic == file_magic::bitcode) {
     obj =
         make<BitcodeFile>(ctx, mb, parentName, offsetInArchive, /*lazy=*/false);
+  } else if (magic == file_magic::coff_cl_gl_object) {
+    error(mb.getBufferIdentifier() +
+          ": is not a native COFF file. Recompile without /GL?");
+    return;
   } else {
     error("unknown file type: " + mb.getBufferIdentifier());
     return;

diff  --git a/lld/test/COFF/Inputs/cl-gl.lib b/lld/test/COFF/Inputs/cl-gl.lib
new file mode 100755
index 0000000000000..7a6d454cbcc92
Binary files /dev/null and b/lld/test/COFF/Inputs/cl-gl.lib 
diff er

diff  --git a/lld/test/COFF/cl-gl.test b/lld/test/COFF/cl-gl.test
index 306115094771d..2c1e7bdd19482 100644
--- a/lld/test/COFF/cl-gl.test
+++ b/lld/test/COFF/cl-gl.test
@@ -1,4 +1,6 @@
 # RUN: not lld-link /out:%t.exe /entry:main %S/Inputs/cl-gl.obj >& %t.log
 # RUN: FileCheck %s < %t.log
+# RUN: not lld-link /out:%t.exe /entry:main %S/Inputs/cl-gl.lib >& %t1.log
+# RUN: FileCheck %s < %t1.log
 
 # CHECK: is not a native COFF file. Recompile without /GL


        


More information about the llvm-commits mailing list