[clang] 719c87e - remove gold linker
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 24 13:50:28 PDT 2020
"Remove gold linker support from the PS4 toolchain" might've been a
more precise commit message - "Remove gold linker" seems a bit too
vague.
On Tue, Jun 16, 2020 at 1:03 PM Yuanfang Chen via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
>
>
> Author: Yuanfang Chen
> Date: 2020-06-16T13:03:31-07:00
> New Revision: 719c87edc58018a0e9f3ee04305e081d4b582c2b
>
> URL: https://github.com/llvm/llvm-project/commit/719c87edc58018a0e9f3ee04305e081d4b582c2b
> DIFF: https://github.com/llvm/llvm-project/commit/719c87edc58018a0e9f3ee04305e081d4b582c2b.diff
>
> LOG: remove gold linker
>
> Added:
>
>
> Modified:
> clang/lib/Driver/ToolChains/PS4CPU.cpp
> clang/test/Driver/ps4-linker-non-win.c
> clang/test/Driver/ps4-linker-win.c
>
> Removed:
>
>
>
> ################################################################################
> diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp
> index ebeed3803e06..379b88017b0e 100644
> --- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
> +++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
> @@ -88,13 +88,13 @@ void tools::PS4cpu::addSanitizerArgs(const ToolChain &TC,
> CmdArgs.push_back("--dependent-lib=libSceDbgAddressSanitizer_stub_weak.a");
> }
>
> -static void ConstructPS4LinkJob(const Tool &T, Compilation &C,
> - const JobAction &JA, const InputInfo &Output,
> - const InputInfoList &Inputs,
> - const ArgList &Args,
> - const char *LinkingOutput) {
> +void tools::PS4cpu::Link::ConstructJob(Compilation &C, const JobAction &JA,
> + const InputInfo &Output,
> + const InputInfoList &Inputs,
> + const ArgList &Args,
> + const char *LinkingOutput) const {
> const toolchains::FreeBSD &ToolChain =
> - static_cast<const toolchains::FreeBSD &>(T.getToolChain());
> + static_cast<const toolchains::FreeBSD &>(getToolChain());
> const Driver &D = ToolChain.getDriver();
> ArgStringList CmdArgs;
>
> @@ -143,216 +143,17 @@ static void ConstructPS4LinkJob(const Tool &T, Compilation &C,
> CmdArgs.push_back("-lpthread");
> }
>
> - const char *Exec = Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld"));
> -
> - C.addCommand(std::make_unique<Command>(JA, T, Exec, CmdArgs, Inputs));
> -}
> -
> -static void ConstructGoldLinkJob(const Tool &T, Compilation &C,
> - const JobAction &JA, const InputInfo &Output,
> - const InputInfoList &Inputs,
> - const ArgList &Args,
> - const char *LinkingOutput) {
> - const toolchains::FreeBSD &ToolChain =
> - static_cast<const toolchains::FreeBSD &>(T.getToolChain());
> - const Driver &D = ToolChain.getDriver();
> - ArgStringList CmdArgs;
> -
> - // Silence warning for "clang -g foo.o -o foo"
> - Args.ClaimAllArgs(options::OPT_g_Group);
> - // and "clang -emit-llvm foo.o -o foo"
> - Args.ClaimAllArgs(options::OPT_emit_llvm);
> - // and for "clang -w foo.o -o foo". Other warning options are already
> - // handled somewhere else.
> - Args.ClaimAllArgs(options::OPT_w);
> -
> - if (!D.SysRoot.empty())
> - CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
> -
> - if (Args.hasArg(options::OPT_pie))
> - CmdArgs.push_back("-pie");
> -
> - if (Args.hasArg(options::OPT_static)) {
> - CmdArgs.push_back("-Bstatic");
> - } else {
> - if (Args.hasArg(options::OPT_rdynamic))
> - CmdArgs.push_back("-export-dynamic");
> - CmdArgs.push_back("--eh-frame-hdr");
> - if (Args.hasArg(options::OPT_shared)) {
> - CmdArgs.push_back("-Bshareable");
> - } else {
> - CmdArgs.push_back("-dynamic-linker");
> - CmdArgs.push_back("/libexec/ld-elf.so.1");
> - }
> - CmdArgs.push_back("--enable-new-dtags");
> - }
> -
> - if (Output.isFilename()) {
> - CmdArgs.push_back("-o");
> - CmdArgs.push_back(Output.getFilename());
> - } else {
> - assert(Output.isNothing() && "Invalid output.");
> - }
> -
> - if(!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
> - AddPS4SanitizerArgs(ToolChain, CmdArgs);
> -
> - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
> - const char *crt1 = nullptr;
> - if (!Args.hasArg(options::OPT_shared)) {
> - if (Args.hasArg(options::OPT_pg))
> - crt1 = "gcrt1.o";
> - else if (Args.hasArg(options::OPT_pie))
> - crt1 = "Scrt1.o";
> - else
> - crt1 = "crt1.o";
> - }
> - if (crt1)
> - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1)));
> -
> - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
> -
> - const char *crtbegin = nullptr;
> - if (Args.hasArg(options::OPT_static))
> - crtbegin = "crtbeginT.o";
> - else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
> - crtbegin = "crtbeginS.o";
> - else
> - crtbegin = "crtbegin.o";
> -
> - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
> - }
> -
> - Args.AddAllArgs(CmdArgs, options::OPT_L);
> - ToolChain.AddFilePathLibArgs(Args, CmdArgs);
> - Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
> - Args.AddAllArgs(CmdArgs, options::OPT_e);
> - Args.AddAllArgs(CmdArgs, options::OPT_s);
> - Args.AddAllArgs(CmdArgs, options::OPT_t);
> - Args.AddAllArgs(CmdArgs, options::OPT_r);
> -
> - if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
> - CmdArgs.push_back("--no-demangle");
> -
> - AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
> -
> - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
> - // For PS4, we always want to pass libm, libstdc++ and libkernel
> - // libraries for both C and C++ compilations.
> - CmdArgs.push_back("-lkernel");
> - if (D.CCCIsCXX()) {
> - if (ToolChain.ShouldLinkCXXStdlib(Args))
> - ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
> - if (Args.hasArg(options::OPT_pg))
> - CmdArgs.push_back("-lm_p");
> - else
> - CmdArgs.push_back("-lm");
> - }
> - // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
> - // the default system libraries. Just mimic this for now.
> - if (Args.hasArg(options::OPT_pg))
> - CmdArgs.push_back("-lgcc_p");
> - else
> - CmdArgs.push_back("-lcompiler_rt");
> - if (Args.hasArg(options::OPT_static)) {
> - CmdArgs.push_back("-lstdc++");
> - } else if (Args.hasArg(options::OPT_pg)) {
> - CmdArgs.push_back("-lgcc_eh_p");
> - } else {
> - CmdArgs.push_back("--as-needed");
> - CmdArgs.push_back("-lstdc++");
> - CmdArgs.push_back("--no-as-needed");
> - }
> -
> - if (Args.hasArg(options::OPT_pthread)) {
> - if (Args.hasArg(options::OPT_pg))
> - CmdArgs.push_back("-lpthread_p");
> - else
> - CmdArgs.push_back("-lpthread");
> - }
> -
> - if (Args.hasArg(options::OPT_pg)) {
> - if (Args.hasArg(options::OPT_shared))
> - CmdArgs.push_back("-lc");
> - else {
> - if (Args.hasArg(options::OPT_static)) {
> - CmdArgs.push_back("--start-group");
> - CmdArgs.push_back("-lc_p");
> - CmdArgs.push_back("-lpthread_p");
> - CmdArgs.push_back("--end-group");
> - } else {
> - CmdArgs.push_back("-lc_p");
> - }
> - }
> - CmdArgs.push_back("-lgcc_p");
> - } else {
> - if (Args.hasArg(options::OPT_static)) {
> - CmdArgs.push_back("--start-group");
> - CmdArgs.push_back("-lc");
> - CmdArgs.push_back("-lpthread");
> - CmdArgs.push_back("--end-group");
> - } else {
> - CmdArgs.push_back("-lc");
> - }
> - CmdArgs.push_back("-lcompiler_rt");
> - }
> -
> - if (Args.hasArg(options::OPT_static)) {
> - CmdArgs.push_back("-lstdc++");
> - } else if (Args.hasArg(options::OPT_pg)) {
> - CmdArgs.push_back("-lgcc_eh_p");
> - } else {
> - CmdArgs.push_back("--as-needed");
> - CmdArgs.push_back("-lstdc++");
> - CmdArgs.push_back("--no-as-needed");
> - }
> + if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
> + D.Diag(diag::err_drv_unsupported_opt_for_target)
> + << "-fuse-ld" << getToolChain().getTriple().str();
> }
>
> - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
> - if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
> - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o")));
> - else
> - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o")));
> - CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
> - }
> + std::string LdName = std::string("orbis-ld");
>
> const char *Exec =
> -#ifdef _WIN32
> - Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld.gold"));
> -#else
> - Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld"));
> -#endif
> + Args.MakeArgString(ToolChain.GetProgramPath(LdName.c_str()));
>
> - C.addCommand(std::make_unique<Command>(JA, T, Exec, CmdArgs, Inputs));
> -}
> -
> -void tools::PS4cpu::Link::ConstructJob(Compilation &C, const JobAction &JA,
> - const InputInfo &Output,
> - const InputInfoList &Inputs,
> - const ArgList &Args,
> - const char *LinkingOutput) const {
> - const toolchains::FreeBSD &ToolChain =
> - static_cast<const toolchains::FreeBSD &>(getToolChain());
> - const Driver &D = ToolChain.getDriver();
> - bool PS4Linker;
> - StringRef LinkerOptName;
> - if (const Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
> - LinkerOptName = A->getValue();
> - if (LinkerOptName != "ps4" && LinkerOptName != "gold")
> - D.Diag(diag::err_drv_unsupported_linker) << LinkerOptName;
> - }
> -
> - if (LinkerOptName == "gold")
> - PS4Linker = false;
> - else if (LinkerOptName == "ps4")
> - PS4Linker = true;
> - else
> - PS4Linker = !Args.hasArg(options::OPT_shared);
> -
> - if (PS4Linker)
> - ConstructPS4LinkJob(*this, C, JA, Output, Inputs, Args, LinkingOutput);
> - else
> - ConstructGoldLinkJob(*this, C, JA, Output, Inputs, Args, LinkingOutput);
> + C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
> }
>
> toolchains::PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple,
>
> diff --git a/clang/test/Driver/ps4-linker-non-win.c b/clang/test/Driver/ps4-linker-non-win.c
> index 3197292176c4..955cb5abb4c0 100644
> --- a/clang/test/Driver/ps4-linker-non-win.c
> +++ b/clang/test/Driver/ps4-linker-non-win.c
> @@ -6,16 +6,14 @@
> // RUN: touch %t/orbis-ld
> // RUN: chmod +x %t/orbis-ld
>
> -// RUN: env "PATH=%t:%PATH%" %clang -### -target x86_64-scei-ps4 %s -fuse-ld=gold 2>&1 \
> -// RUN: | FileCheck --check-prefix=CHECK-PS4-LINKER %s
> -// RUN: env "PATH=%t:%PATH%" %clang -### -target x86_64-scei-ps4 %s -shared 2>&1 \
> -// RUN: | FileCheck --check-prefix=CHECK-PS4-LINKER %s
> -
> // RUN: env "PATH=%t:%PATH%" %clang -### -target x86_64-scei-ps4 %s 2>&1 \
> // RUN: | FileCheck --check-prefix=CHECK-PS4-LINKER %s
> -// RUN: env "PATH=%t:%PATH%" %clang -### -target x86_64-scei-ps4 %s -fuse-ld=ps4 2>&1 \
> +// RUN: env "PATH=%t:%PATH%" %clang -### -target x86_64-scei-ps4 %s -shared 2>&1 \
> // RUN: | FileCheck --check-prefix=CHECK-PS4-LINKER %s
> -// RUN: env "PATH=%t:%PATH%" %clang -### -target x86_64-scei-ps4 %s -shared \
> -// RUN: -fuse-ld=ps4 2>&1 | FileCheck --check-prefix=CHECK-PS4-LINKER %s
>
> // CHECK-PS4-LINKER: /orbis-ld
> +
> +// RUN: env "PATH=%t:%PATH%" %clang -### -target x86_64-scei-ps4 %s -fuse-ld=gold 2>&1 \
> +// RUN: | FileCheck --check-prefix=ERROR %s
> +
> +// ERROR: error: unsupported option '-fuse-ld' for target 'x86_64-scei-ps4'
> \ No newline at end of file
>
> diff --git a/clang/test/Driver/ps4-linker-win.c b/clang/test/Driver/ps4-linker-win.c
> index fafa579a0743..688aec8c0ce1 100644
> --- a/clang/test/Driver/ps4-linker-win.c
> +++ b/clang/test/Driver/ps4-linker-win.c
> @@ -1,27 +1,31 @@
> -// The full path to the gold linker was not found on Windows because the
> -// driver fails to add an .exe extension to the name.
> -// We check that gold linker's full name (with an extension) is specified
> -// on the command line if -fuse-ld=gold, or -shared with no -fuse-ld option
> -// are passed. Otherwise, we check that the PS4's linker's full name is
> -// specified.
> +// This test check that orbis-ld is used for linker all the time. Specifying
> +// linker using -fuse-ld causes a error message emitted and compilation fail.
>
> // REQUIRES: system-windows, x86-registered-target
>
> // RUN: mkdir -p %t
> // RUN: touch %t/orbis-ld.exe
> -// RUN: touch %t/orbis-ld.gold.exe
> -
> -// RUN: env "PATH=%t;%PATH%;" %clang -target x86_64-scei-ps4 %s -fuse-ld=gold -### 2>&1 \
> -// RUN: | FileCheck --check-prefix=CHECK-PS4-GOLD %s
> -// RUN: env "PATH=%t;%PATH%;" %clang -target x86_64-scei-ps4 %s -shared -### 2>&1 \
> -// RUN: | FileCheck --check-prefix=CHECK-PS4-GOLD %s
>
> // RUN: env "PATH=%t;%PATH%;" %clang -target x86_64-scei-ps4 %s -### 2>&1 \
> // RUN: | FileCheck --check-prefix=CHECK-PS4-LINKER %s
> -// RUN: env "PATH=%t;%PATH%;" %clang -target x86_64-scei-ps4 %s -fuse-ld=ps4 -### 2>&1 \
> +// RUN: env "PATH=%t;%PATH%;" %clang -target x86_64-scei-ps4 %s -shared -### 2>&1 \
> // RUN: | FileCheck --check-prefix=CHECK-PS4-LINKER %s
> -// RUN: env "PATH=%t;%PATH%;" %clang -target x86_64-scei-ps4 %s -shared \
> -// RUN: -fuse-ld=ps4 -### 2>&1 | FileCheck --check-prefix=CHECK-PS4-LINKER %s
>
> -// CHECK-PS4-GOLD: \\orbis-ld.gold
> // CHECK-PS4-LINKER: \\orbis-ld
> +
> +// RUN: env "PATH=%t;%PATH%;" %clang -### -target x86_64-scei-ps4 -flto=thin %s 2>&1 \
> +// RUN: | FileCheck --check-prefix=CHECK-PS4-LTO-THIN %s
> +// RUN: env "PATH=%t;%PATH%;" %clang -### -target x86_64-scei-ps4 -flto=full %s 2>&1 \
> +// RUN: | FileCheck --check-prefix=CHECK-PS4-LTO-FULL %s
> +// RUN: env "PATH=%t;%PATH%;" %clang -### -target x86_64-scei-ps4 %s 2>&1 \
> +// RUN: | FileCheck --check-prefix=CHECK-PS4-NO-LTO-THIN --check-prefix=CHECK-PS4-NO-LTO-FULL %s
> +
> +// CHECK-PS4-LTO-THIN: --lto=thin
> +// CHECK-PS4-LTO-FULL: --lto=full
> +// CHECK-PS4-NO-LTO-THIN-NOT: --lto=thin
> +// CHECK-PS4-NO-LTO-FULL-NOT: --lto=full
> +
> +// RUN: env "PATH=%t;%PATH%;" %clang -target x86_64-scei-ps4 %s -fuse-ld=gold -### 2>&1 \
> +// RUN: | FileCheck --check-prefix=ERROR %s
> +
> +// ERROR: error: unsupported option '-fuse-ld' for target 'x86_64-scei-ps4'
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list