[lld] 8fa0cfe - [LLD][COFF] Add /inferasanlibs to lld-link as ignored flag

Alvin Wong via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 24 07:07:00 PDT 2023


Author: Alvin Wong
Date: 2023-04-24T22:06:34+08:00
New Revision: 8fa0cfeb61a12ad5ca7830a8228155de32aa7ab2

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

LOG: [LLD][COFF] Add /inferasanlibs to lld-link as ignored flag

MSVC link.exe added this flag and MS STL started using this flag in
.drectve [1] when compiling with Clang with asan enabled, as reported
on https://github.com/llvm/llvm-project/issues/56300. This causes issues
with lld-link because it rejects any unknown flags in .drective sections.

As dc07867dc9991c982bd3441da19d6fcc16ea54d6 noted that, when using Clang
as the driver it explicitly passes the proper asan libraries. Therefore
it should be acceptable to ignore this flag in lld-link to at least
unbreak building with clang-cl and linking with lld-link.

[1]: https://github.com/microsoft/STL/blob/faaf094ee16bcbfb2c8d612fdb9334bcdef2fd0a/stl/inc/__msvc_sanitizer_annotate_container.hpp#L35

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

Added: 
    lld/test/COFF/inferasanlibs-drectve.s
    lld/test/COFF/inferasanlibs.test

Modified: 
    lld/COFF/Driver.cpp
    lld/COFF/Options.td

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index d326296b1b608..6326e466930a4 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -445,6 +445,8 @@ void LinkerDriver::parseDirectives(InputFile *file) {
     case OPT_editandcontinue:
     case OPT_guardsym:
     case OPT_throwingnew:
+    case OPT_inferasanlibs:
+    case OPT_inferasanlibs_no:
       break;
     default:
       error(arg->getSpelling() + " is not allowed in .drectve (" +
@@ -1933,6 +1935,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
       args.hasFlag(OPT_stdcall_fixup, OPT_stdcall_fixup_no, config->mingw);
   config->warnStdcallFixup = !args.hasArg(OPT_stdcall_fixup);
 
+  if (args.hasFlag(OPT_inferasanlibs, OPT_inferasanlibs_no, false))
+    warn("ignoring '/inferasanlibs', this flag is not supported");
+
   // Don't warn about long section names, such as .debug_info, for mingw or
   // when -debug:dwarf is requested.
   if (config->mingw || config->debugDwarf)

diff  --git a/lld/COFF/Options.td b/lld/COFF/Options.td
index df527bb48ae72..2a89509be5fe0 100644
--- a/lld/COFF/Options.td
+++ b/lld/COFF/Options.td
@@ -194,6 +194,9 @@ defm highentropyva : B<"highentropyva",
 defm incremental : B<"incremental",
                      "Keep original import library if contents are unchanged",
                      "Overwrite import library even if contents are unchanged">;
+defm inferasanlibs : B<"inferasanlibs",
+                       "Unused, generates a warning",
+                       "No effect (default)">;
 defm integritycheck : B<"integritycheck",
                         "Set FORCE_INTEGRITY bit in PE header",
                         "No effect (default)">;

diff  --git a/lld/test/COFF/inferasanlibs-drectve.s b/lld/test/COFF/inferasanlibs-drectve.s
new file mode 100644
index 0000000000000..8406658cea389
--- /dev/null
+++ b/lld/test/COFF/inferasanlibs-drectve.s
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -triple=x86_64-windows %s -filetype=obj -o %t.obj
+
+# RUN: lld-link -dll -out:%t.dll -entry:entry %t.obj -subsystem:console 2>&1 | FileCheck --allow-empty --ignore-case %s
+
+# CHECK-NOT: ignoring unknown argument
+# CHECK-NOT: inferasanlibs
+# CHECK-NOT: is not allowed in .drectve
+
+  .global entry
+  .text
+entry:
+  ret
+  .section .drectve
+  .ascii " /INFERASANLIBS "

diff  --git a/lld/test/COFF/inferasanlibs.test b/lld/test/COFF/inferasanlibs.test
new file mode 100644
index 0000000000000..e8f36602b5f6b
--- /dev/null
+++ b/lld/test/COFF/inferasanlibs.test
@@ -0,0 +1,8 @@
+# RUN: yaml2obj %p/Inputs/ret42.yaml -o %t.obj
+
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /inferasanlibs 2>&1 | FileCheck --check-prefix=POS %s
+# RUN: lld-link /out:%t.exe /entry:main %t.obj /inferasanlibs:no 2>&1 | FileCheck --allow-empty --check-prefix=NEG %s
+
+POS: ignoring '/inferasanlibs', this flag is not supported
+
+NEG-NOT: ignoring '/inferasanlibs', this flag is not supported


        


More information about the llvm-commits mailing list