Skip to content

Commit 7a26555

Browse files
alvinhochuntstellar
authored andcommitted
[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 #56300. This causes issues with lld-link because it rejects any unknown flags in .drective sections. As dc07867 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 (cherry picked from commit 8fa0cfe)
1 parent 4676274 commit 7a26555

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

lld/COFF/Driver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ void LinkerDriver::parseDirectives(InputFile *file) {
436436
case OPT_editandcontinue:
437437
case OPT_guardsym:
438438
case OPT_throwingnew:
439+
case OPT_inferasanlibs:
440+
case OPT_inferasanlibs_no:
439441
break;
440442
default:
441443
error(arg->getSpelling() + " is not allowed in .drectve (" +
@@ -1924,6 +1926,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
19241926
args.hasFlag(OPT_stdcall_fixup, OPT_stdcall_fixup_no, config->mingw);
19251927
config->warnStdcallFixup = !args.hasArg(OPT_stdcall_fixup);
19261928

1929+
if (args.hasFlag(OPT_inferasanlibs, OPT_inferasanlibs_no, false))
1930+
warn("ignoring '/inferasanlibs', this flag is not supported");
1931+
19271932
// Don't warn about long section names, such as .debug_info, for mingw or
19281933
// when -debug:dwarf is requested.
19291934
if (config->mingw || config->debugDwarf)

lld/COFF/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ defm highentropyva : B<"highentropyva",
194194
defm incremental : B<"incremental",
195195
"Keep original import library if contents are unchanged",
196196
"Overwrite import library even if contents are unchanged">;
197+
defm inferasanlibs : B<"inferasanlibs",
198+
"Unused, generates a warning",
199+
"No effect (default)">;
197200
defm integritycheck : B<"integritycheck",
198201
"Set FORCE_INTEGRITY bit in PE header",
199202
"No effect (default)">;

lld/test/COFF/inferasanlibs-drectve.s

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# REQUIRES: x86
2+
3+
# RUN: llvm-mc -triple=x86_64-windows %s -filetype=obj -o %t.obj
4+
5+
# RUN: lld-link -dll -out:%t.dll -entry:entry %t.obj -subsystem:console 2>&1 | FileCheck --allow-empty --ignore-case %s
6+
7+
# CHECK-NOT: ignoring unknown argument
8+
# CHECK-NOT: inferasanlibs
9+
# CHECK-NOT: is not allowed in .drectve
10+
11+
.global entry
12+
.text
13+
entry:
14+
ret
15+
.section .drectve
16+
.ascii " /INFERASANLIBS "

lld/test/COFF/inferasanlibs.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# RUN: yaml2obj %p/Inputs/ret42.yaml -o %t.obj
2+
3+
# RUN: lld-link /out:%t.exe /entry:main %t.obj /inferasanlibs 2>&1 | FileCheck --check-prefix=POS %s
4+
# RUN: lld-link /out:%t.exe /entry:main %t.obj /inferasanlibs:no 2>&1 | FileCheck --allow-empty --check-prefix=NEG %s
5+
6+
POS: ignoring '/inferasanlibs', this flag is not supported
7+
8+
NEG-NOT: ignoring '/inferasanlibs', this flag is not supported

0 commit comments

Comments
 (0)