[clang] c06e22f - [Driver] Exclude options::LinkerInput for GCC linking

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 31 00:05:08 PDT 2020


Author: Fangrui Song
Date: 2020-07-31T00:04:09-07:00
New Revision: c06e22fe07aa5eb8a9f8ce824cbab1bfe5a96581

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

LOG: [Driver] Exclude options::LinkerInput for GCC linking

options::LinkerInput options may get duplicated after 6a75496836ea14bcfd2f4b59d35a1cad4ac58cee..

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Gnu.cpp
    clang/test/Driver/gcc_forward.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 1806c14c395d..9ca674511dab 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -38,6 +38,9 @@ using tools::addMultilibFlag;
 using tools::addPathIfExists;
 
 static bool forwardToGCC(const Option &O) {
+  // LinkerInput options have been forwarded. Don't duplicate.
+  if (O.hasFlag(options::LinkerInput))
+    return false;
   return O.matches(options::OPT_Link_Group) || O.hasFlag(options::LinkOption);
 }
 

diff  --git a/clang/test/Driver/gcc_forward.c b/clang/test/Driver/gcc_forward.c
index 9579d0d60d1c..a99944f8f533 100644
--- a/clang/test/Driver/gcc_forward.c
+++ b/clang/test/Driver/gcc_forward.c
@@ -1,7 +1,7 @@
 // RUN: %clang -### %s -target aarch64-none-elf \
-// RUN:   --coverage -fuse-ld=lld --ld-path=ld -nostdlib -r -rdynamic -static -static-pie \
+// RUN:   --coverage -e _start -fuse-ld=lld --ld-path=ld -nostdlib -r -rdynamic -static -static-pie \
 // RUN:   2>&1 | FileCheck --check-prefix=FORWARD %s
-// FORWARD: gcc{{[^"]*}}" "--coverage" "-fuse-ld=lld" "--ld-path=ld" "-nostdlib" "-r" "-rdynamic" "-static" "-static-pie"
+// FORWARD: gcc{{[^"]*}}" "--coverage" "-fuse-ld=lld" "--ld-path=ld" "-nostdlib" "-rdynamic" "-static" "-static-pie" "-o" "a.out" "{{.*}}.o" "-e" "_start" "-r"
 
 // Check that we don't try to forward -Xclang or -mlinker-version to GCC.
 // PR12920 -- Check also we may not forward W_Group options to GCC.


        


More information about the cfe-commits mailing list