From 65271ffe84165b935cefc9a7d468cb6f46a96a91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Markus=20B=C3=B6ck?= <markus.boeck02@gmail.com>
Date: Mon, 17 May 2021 22:12:22 +0200
Subject: [PATCH] [lld][MinGW] Introduce aliases for -Bdynamic and -Bstatic

Besides -Bdynamic and -Bstatic, ld documents additional aliases for both of these options. Instead of -Bstatic, one may write -dn, -non_shared or -static. Instead of -Bdynamic one may write -dy or -call_shared. Source: https://sourceware.org/binutils/docs-2.36/ld/Options.html

This patch adds those aliases to the MinGW driver of lld for the sake of ld compatibility.

Encountered this case while compiling a static Qt 6.1 distribution and got build failures as -static was passed directly to the linker, instead of through the compiler driver.

Differential Revision: https://reviews.llvm.org/D102637
---
 MinGW/Options.td    | 5 +++++
 test/MinGW/lib.test | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/MinGW/Options.td b/MinGW/Options.td
index 3a4a40bbe11f..e27c1365ab1f 100644
--- a/MinGW/Options.td
+++ b/MinGW/Options.td
@@ -113,6 +113,11 @@ def Xlink : J<"Xlink=">, MetaVarName<"<arg>">,
     HelpText<"Pass <arg> to the COFF linker">;
 
 // Alias
+def alias_Bdynamic_call_shared: Flag<["-"], "call_shared">, Alias<Bdynamic>;
+def alias_Bdynamic_dy: Flag<["-"], "dy">, Alias<Bdynamic>;
+def alias_Bstatic_dn: Flag<["-"], "dn">, Alias<Bstatic>;
+def alias_Bstatic_non_shared: Flag<["-"], "non_shared">, Alias<Bstatic>;
+def alias_Bstatic_static: Flag<["-"], "static">, Alias<Bstatic>;
 def alias_entry_e: JoinedOrSeparate<["-"], "e">, Alias<entry>;
 def alias_strip_s: Flag<["-"], "s">, Alias<strip_all>;
 def alias_strip_S: Flag<["-"], "S">, Alias<strip_debug>;
diff --git a/test/MinGW/lib.test b/test/MinGW/lib.test
index a2bd091bc691..09bff012b237 100644
--- a/test/MinGW/lib.test
+++ b/test/MinGW/lib.test
@@ -15,6 +15,9 @@ RUN: ld.lld -### -m i386pep -l:barefilename -L%t/lib 2>&1 | FileCheck -check-pre
 LIB-LITERAL: barefilename
 
 RUN: not ld.lld -### -m i386pep -Bstatic -lfoo -L%t/lib 2>&1 | FileCheck -check-prefix=LIB3 %s
+RUN: not ld.lld -### -m i386pep -dn -lfoo -L%t/lib 2>&1 | FileCheck -check-prefix=LIB3 %s
+RUN: not ld.lld -### -m i386pep -static -lfoo -L%t/lib 2>&1 | FileCheck -check-prefix=LIB3 %s
+RUN: not ld.lld -### -m i386pep -non_shared -lfoo -L%t/lib 2>&1 | FileCheck -check-prefix=LIB3 %s
 LIB3: unable to find library -lfoo
 
 RUN: echo > %t/lib/libfoo.a
@@ -24,6 +27,8 @@ LIB4: libfoo.a
 RUN: echo > %t/lib/libbar.dll.a
 RUN: echo > %t/lib/libbar.a
 RUN: ld.lld -### -m i386pep -Bstatic -lfoo -Bdynamic -lbar -L%t/lib | FileCheck -check-prefix=LIB5 %s
+RUN: ld.lld -### -m i386pep -Bstatic -lfoo -dy -lbar -L%t/lib | FileCheck -check-prefix=LIB5 %s
+RUN: ld.lld -### -m i386pep -Bstatic -lfoo -call_shared -lbar -L%t/lib | FileCheck -check-prefix=LIB5 %s
 LIB5:      libfoo.a
 LIB5-SAME: libbar.dll.a
 
-- 
2.31.1.windows.1

