[PATCH] Fix linker errors caused bv passing "-Og" to gold plugin
Joey Pabalinas via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 10 05:54:37 PST 2018
[Driver] Pass -O0 to gold plugin when -Og is specified on the command-line
The gold plugin understands -O0..-O3, so when -Og is passed to it, the link
fails with:
> /bin/ld.gold: fatal error: Optimization level must be between 0 and 3
>
> clang-5.0: error: linker command failed with exit code 1 (use -v to see
> invocation)
Pass -O0 instead of -Og to the gold plugin when that optimization level
is specified as a command-line argument.
--
Joey Pabalinas
-------------- next part --------------
Index: lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- lib/Driver/ToolChains/CommonArgs.cpp (revision 324803)
+++ lib/Driver/ToolChains/CommonArgs.cpp (working copy)
@@ -405,7 +405,9 @@
A->getOption().matches(options::OPT_Ofast))
OOpt = "3";
else if (A->getOption().matches(options::OPT_O))
- OOpt = A->getValue();
+ // The ld.gold linker needs an optimization level between 0 and 3.
+ // If optimization level is`-Og`, pass `-O0` to avoid linker errors.
+ OOpt = A->getValue()[0] == 'g' ? "0" : A->getValue();
else if (A->getOption().matches(options::OPT_O0))
OOpt = "0";
if (!OOpt.empty())
Index: test/Driver/gold-lto.c
===================================================================
--- test/Driver/gold-lto.c (revision 324803)
+++ test/Driver/gold-lto.c (working copy)
@@ -8,6 +8,14 @@
// CHECK-X86-64-BASIC: "-plugin-opt=foo"
//
// RUN: %clang -target x86_64-unknown-linux -### %t.o -flto 2>&1 \
+// RUN: -Wl,-plugin-opt=foo -Og \
+// RUN: | FileCheck %s --check-prefix=CHECK-X86-64-CORE2
+// CHECK-X86-64-BASIC: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
+// CHECK-X86-64-CORE2: "-plugin-opt=mcpu=core2"
+// CHECK-X86-64-BASIC: "-plugin-opt=Og"
+// CHECK-X86-64-BASIC: "-plugin-opt=foo"
+//
+// RUN: %clang -target x86_64-unknown-linux -### %t.o -flto 2>&1 \
// RUN: -march=corei7 -Wl,-plugin-opt=foo -Ofast \
// RUN: | FileCheck %s --check-prefix=CHECK-X86-64-COREI7
// CHECK-X86-64-COREI7: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180210/6f7d20f0/attachment.sig>
More information about the cfe-commits
mailing list