r194328 - Add support for -fuse-ld=.
Chandler Carruth
chandlerc at google.com
Sat Nov 9 16:31:15 PST 2013
On Sat, Nov 9, 2013 at 6:16 AM, David Chisnall <csdavec at swan.ac.uk> wrote:
> Author: theraven
> Date: Sat Nov 9 08:16:52 2013
> New Revision: 194328
>
> URL: http://llvm.org/viewvc/llvm-project?rev=194328&view=rev
> Log:
> Add support for -fuse-ld=.
>
>
> Added:
> cfe/trunk/test/Driver/Inputs/basic_freebsd_tree/usr/bin/
> cfe/trunk/test/Driver/Inputs/basic_freebsd_tree/usr/bin/ld.bfd
> cfe/trunk/test/Driver/Inputs/basic_freebsd_tree/usr/bin/ld.gold
> cfe/trunk/test/Driver/fuse_ld.c
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/include/clang/Driver/ToolChain.h
> cfe/trunk/lib/Driver/ToolChain.cpp
> cfe/trunk/lib/Driver/Tools.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=194328&r1=194327&r2=194328&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Sat Nov 9
> 08:16:52 2013
> @@ -20,6 +20,8 @@ def err_drv_unknown_stdin_type : Error<
> def err_drv_unknown_language : Error<"language not recognized: '%0'">;
> def err_drv_invalid_arch_name : Error<
> "invalid arch name '%0'">;
> +def err_drv_invalid_linker_name : Error<
> + "invalid linker name in argument '%0'">;
> def err_drv_invalid_rtlib_name : Error<
> "invalid runtime library name in argument '%0'">;
> def err_drv_unsupported_rtlib_for_platform : Error<
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=194328&r1=194327&r2=194328&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Sat Nov 9 08:16:52 2013
> @@ -1434,7 +1434,8 @@ def fprofile_dir : Joined<["-"], "fprofi
>
> defm profile_use : BooleanFFlag<"profile-use">,
> Group<clang_ignored_f_Group>;
> def fprofile_use_EQ : Joined<["-"], "fprofile-use=">,
> Group<clang_ignored_f_Group>;
> -def fuse_ld_EQ : Joined<["-"], "fuse-ld=">, Group<clang_ignored_f_Group>;
> +def fuse_ld_EQ : Joined<["-", "--"], "fuse-ld=">, Group<f_Group>,
>
Why add a '--' prefix? No other f-group flags use '--'? I don't think this
is right.
> + HelpText<"The suffix of the linker to use (e.g. bfd for ld.bfd).">;
>
> defm align_functions : BooleanFFlag<"align-functions">,
> Group<clang_ignored_f_Group>;
> def falign_functions_EQ : Joined<["-"], "falign-functions=">,
> Group<clang_ignored_f_Group>;
>
> Modified: cfe/trunk/include/clang/Driver/ToolChain.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=194328&r1=194327&r2=194328&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/ToolChain.h (original)
> +++ cfe/trunk/include/clang/Driver/ToolChain.h Sat Nov 9 08:16:52 2013
> @@ -126,6 +126,9 @@ public:
>
> path_list &getProgramPaths() { return ProgramPaths; }
> const path_list &getProgramPaths() const { return ProgramPaths; }
> + /// Returns the linker path, respecting the -fuse-ld= argument to
> determine
> + /// the linker suffix or name.
> + std::string GetLinkerPath() const;
>
Please put this down next to GetProgramPath. That makes a lot more sense
than here.
>
> const SanitizerArgs& getSanitizerArgs() const;
>
>
> Modified: cfe/trunk/lib/Driver/ToolChain.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=194328&r1=194327&r2=194328&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/ToolChain.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChain.cpp Sat Nov 9 08:16:52 2013
> @@ -146,6 +146,28 @@ std::string ToolChain::GetProgramPath(co
> return D.GetProgramPath(Name, *this);
> }
>
> +std::string ToolChain::GetLinkerPath() const {
> + if (Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
> + StringRef Value = A->getValue();
> + // If we're passed -fuse-ld= with no argument, or with the argument
> ld,
> + // then use whatever the default system linker is.
> + if (Value.empty() || Value == "ld")
> + return GetProgramPath("ld");
> + std::string LinkerName = Value.str();
> + std::string LD("ld.");
> + LD += LinkerName;
> + std::string LinkerPath = GetProgramPath(LD.c_str());
>
This is kinda horrible string hacking.
Why don't you make GetProgramPath use a Twine argument? Then most of this
vanishes.
> + bool Exists;
> + if (!llvm::sys::fs::exists(LinkerPath, Exists) && Exists)
> + return LinkerPath;
> + getDriver().Diag(diag::err_drv_invalid_linker_name)
> + << A->getAsString(Args);
> + return "";
>
Why do we need to diagnose this? Surely either GetProgramPath will, or if
not, the caller why might have gotten something bogus and undiagnosed from
GetProgramPath will? While yes, you print out the argument if it fails, you
don't test that it would have succeeded without the argument, and so this
is just as likely to diagnose the wrong thing as it stands.
> + }
> + return GetProgramPath("ld");
> +}
> +
> +
> types::ID ToolChain::LookupTypeForExtension(const char *Ext) const {
> return types::lookupTypeForExtension(Ext);
> }
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=194328&r1=194327&r2=194328&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Sat Nov 9 08:16:52 2013
> @@ -5184,7 +5184,7 @@ void solaris::Link::ConstructJob(Compila
> addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
>
> const char *Exec =
> - Args.MakeArgString(getToolChain().GetProgramPath("ld"));
> + Args.MakeArgString(getToolChain().GetLinkerPath());
> C.addCommand(new Command(JA, *this, Exec, CmdArgs));
> }
>
> @@ -5296,7 +5296,7 @@ void auroraux::Link::ConstructJob(Compil
> addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
>
> const char *Exec =
> - Args.MakeArgString(getToolChain().GetProgramPath("ld"));
> + Args.MakeArgString(getToolChain().GetLinkerPath());
> C.addCommand(new Command(JA, *this, Exec, CmdArgs));
> }
>
> @@ -5447,7 +5447,7 @@ void openbsd::Link::ConstructJob(Compila
> }
>
> const char *Exec =
> - Args.MakeArgString(getToolChain().GetProgramPath("ld"));
> + Args.MakeArgString(getToolChain().GetLinkerPath());
> C.addCommand(new Command(JA, *this, Exec, CmdArgs));
> }
>
> @@ -5587,7 +5587,7 @@ void bitrig::Link::ConstructJob(Compilat
> }
>
> const char *Exec =
> - Args.MakeArgString(getToolChain().GetProgramPath("ld"));
> + Args.MakeArgString(getToolChain().GetLinkerPath());
> C.addCommand(new Command(JA, *this, Exec, CmdArgs));
> }
>
> @@ -5838,7 +5838,7 @@ void freebsd::Link::ConstructJob(Compila
> addProfileRT(ToolChain, Args, CmdArgs, ToolChain.getTriple());
>
> const char *Exec =
> - Args.MakeArgString(ToolChain.GetProgramPath("ld"));
> + Args.MakeArgString(getToolChain().GetLinkerPath());
> C.addCommand(new Command(JA, *this, Exec, CmdArgs));
> }
>
> @@ -5992,7 +5992,7 @@ void netbsd::Link::ConstructJob(Compilat
>
> addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
>
> - const char *Exec =
> Args.MakeArgString(getToolChain().GetProgramPath("ld"));
> + const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
> C.addCommand(new Command(JA, *this, Exec, CmdArgs));
> }
>
> @@ -6503,7 +6503,7 @@ void minix::Link::ConstructJob(Compilati
> Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
> }
>
> - const char *Exec =
> Args.MakeArgString(getToolChain().GetProgramPath("ld"));
> + const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
> C.addCommand(new Command(JA, *this, Exec, CmdArgs));
> }
>
> @@ -6687,7 +6687,7 @@ void dragonfly::Link::ConstructJob(Compi
> addProfileRT(getToolChain(), Args, CmdArgs, getToolChain().getTriple());
>
> const char *Exec =
> - Args.MakeArgString(getToolChain().GetProgramPath("ld"));
> + Args.MakeArgString(getToolChain().GetLinkerPath());
> C.addCommand(new Command(JA, *this, Exec, CmdArgs));
> }
>
>
> Added: cfe/trunk/test/Driver/Inputs/basic_freebsd_tree/usr/bin/ld.bfd
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_freebsd_tree/usr/bin/ld.bfd?rev=194328&view=auto
>
> ==============================================================================
> (empty)
>
> Added: cfe/trunk/test/Driver/Inputs/basic_freebsd_tree/usr/bin/ld.gold
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/basic_freebsd_tree/usr/bin/ld.gold?rev=194328&view=auto
>
> ==============================================================================
> (empty)
>
> Added: cfe/trunk/test/Driver/fuse_ld.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fuse_ld.c?rev=194328&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Driver/fuse_ld.c (added)
> +++ cfe/trunk/test/Driver/fuse_ld.c Sat Nov 9 08:16:52 2013
> @@ -0,0 +1,14 @@
> +// RUN: %clang %s -### 2>&1 | FileCheck %s
> +// CHECK: ld
> +// RUN: %clang -fuse-ld=bfd --sysroot=%S/Inputs/basic_freebsd_tree \
> +// RUN: -B%S/Inputs/basic_freebsd_tree %s -### 2>&1 | \
> +// RUN: FileCheck -check-prefix=CHECK-BFD %s
> +// CHECK-BFD: ld.bfd
> +// RUN: %clang -fuse-ld=gold --sysroot=%S/Inputs/basic_freebsd_tree \
> +// RUN: -B%S/Inputs/basic_freebsd_tree %s -### 2>&1 | \
> +// RUN: FileCheck -check-prefix=CHECK-GOLD %s
> +// CHECK-GOLD: ld.gold
> +// RUN: %clang -fuse-ld=plib --sysroot=%S/Inputs/basic_freebsd_tree \
> +// RUN: -B%S/Inputs/basic_freebsd_tree %s -### 2>&1 | \
> +// RUN: FileCheck -check-prefix=CHECK-PLIB %s
> +// CHECK-PLIB: error: invalid linker name
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131109/915b574c/attachment.html>
More information about the cfe-commits
mailing list