[Driver] Exclude options::LinkerInput for GCC linking
authorFangrui Song <maskray@google.com>
Fri, 31 Jul 2020 07:04:09 +0000 (00:04 -0700)
committerFangrui Song <maskray@google.com>
Fri, 31 Jul 2020 07:04:09 +0000 (00:04 -0700)
options::LinkerInput options may get duplicated after 6a75496836ea14bcfd2f4b59d35a1cad4ac58cee..

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

index 1806c14..9ca6745 100644 (file)
@@ -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);
 }
 
index 9579d0d..a99944f 100644 (file)
@@ -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.