Author: Fangrui Song Date: 2023-10-15T19:12:35-07:00 New Revision: 993e839480449de63aefb1a1ae9142eefed5e7a6
URL: https://github.com/llvm/llvm-project/commit/993e839480449de63aefb1a1ae9142eefed5e7a6 DIFF: https://github.com/llvm/llvm-project/commit/993e839480449de63aefb1a1ae9142eefed5e7a6.diff LOG: [Driver] Don't pass -Z to ld for ELF platforms (#69120) -Z is an Apple ld64 option. ELF linkers don't recognize -Z, except OpenBSD which patched GNU ld to add -Z for zmagic (seems unused) > -Z Produce 'Standard' executables, disables Writable XOR Executable features in resulting binaries. Some `ToolChain`s have -Z due to copy-and-paste mistakes. Added: Modified: clang/lib/Driver/ToolChains/BareMetal.cpp clang/lib/Driver/ToolChains/CSKYToolChain.cpp clang/lib/Driver/ToolChains/FreeBSD.cpp clang/lib/Driver/ToolChains/Haiku.cpp clang/lib/Driver/ToolChains/MinGW.cpp clang/lib/Driver/ToolChains/NetBSD.cpp clang/lib/Driver/ToolChains/OpenBSD.cpp clang/lib/Driver/ToolChains/RISCVToolchain.cpp clang/test/Driver/openbsd.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index f363d277a7b71d3..842061c1e1488b0 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -452,9 +452,8 @@ void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL"); } - Args.addAllArgs(CmdArgs, - {options::OPT_L, options::OPT_T_Group, options::OPT_s, - options::OPT_t, options::OPT_Z_Flag, options::OPT_r}); + Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group, + options::OPT_s, options::OPT_t, options::OPT_r}); TC.AddFilePathLibArgs(Args, CmdArgs); diff --git a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp index 2bd91e63fdd5a42..0c280347b2af6a1 100644 --- a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp +++ b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp @@ -169,9 +169,8 @@ void CSKY::Linker::ConstructJob(Compilation &C, const JobAction &JA, Args.AddAllArgs(CmdArgs, options::OPT_L); ToolChain.AddFilePathLibArgs(Args, CmdArgs); - Args.addAllArgs(CmdArgs, - {options::OPT_T_Group, options::OPT_s, options::OPT_t, - options::OPT_Z_Flag, options::OPT_r}); + Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s, + options::OPT_t, options::OPT_r}); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp index c936fb88d18ccd9..7a61159ba4a7308 100644 --- a/clang/lib/Driver/ToolChains/FreeBSD.cpp +++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp @@ -262,9 +262,8 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, Args.AddAllArgs(CmdArgs, options::OPT_L); ToolChain.AddFilePathLibArgs(Args, CmdArgs); - Args.addAllArgs(CmdArgs, - {options::OPT_T_Group, options::OPT_s, options::OPT_t, - options::OPT_Z_Flag, options::OPT_r}); + Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s, + options::OPT_t, options::OPT_r}); if (D.isUsingLTO()) { assert(!Inputs.empty() && "Must have at least one input."); diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp b/clang/lib/Driver/ToolChains/Haiku.cpp index c2653a4a2022edf..9f56a0ea5d612d0 100644 --- a/clang/lib/Driver/ToolChains/Haiku.cpp +++ b/clang/lib/Driver/ToolChains/Haiku.cpp @@ -80,9 +80,8 @@ void haiku::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("init_term_dyn.o"))); } - Args.addAllArgs(CmdArgs, - {options::OPT_L, options::OPT_T_Group, options::OPT_s, - options::OPT_t, options::OPT_Z_Flag, options::OPT_r}); + Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group, + options::OPT_s, options::OPT_t, options::OPT_r}); ToolChain.AddFilePathLibArgs(Args, CmdArgs); addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs); diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp index d3d829a8ddbdb95..39d767795445dbe 100644 --- a/clang/lib/Driver/ToolChains/MinGW.cpp +++ b/clang/lib/Driver/ToolChains/MinGW.cpp @@ -201,7 +201,6 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_s); Args.AddLastArg(CmdArgs, options::OPT_t); Args.AddAllArgs(CmdArgs, options::OPT_u_Group); - Args.AddLastArg(CmdArgs, options::OPT_Z_Flag); // Add asan_dynamic as the first import lib before other libs. This allows // asan to be initialized as early as possible to increase its instrumentation diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp b/clang/lib/Driver/ToolChains/NetBSD.cpp index 316e4d56c242acc..1c901f70f72ca2e 100644 --- a/clang/lib/Driver/ToolChains/NetBSD.cpp +++ b/clang/lib/Driver/ToolChains/NetBSD.cpp @@ -266,9 +266,8 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, } } - Args.addAllArgs(CmdArgs, - {options::OPT_L, options::OPT_T_Group, options::OPT_s, - options::OPT_t, options::OPT_Z_Flag, options::OPT_r}); + Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group, + options::OPT_s, options::OPT_t, options::OPT_r}); bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs); bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs); diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp index 5a9a8584cccb278..2508ef57f827ccf 100644 --- a/clang/lib/Driver/ToolChains/OpenBSD.cpp +++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -195,9 +195,8 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, Args.AddAllArgs(CmdArgs, options::OPT_L); ToolChain.AddFilePathLibArgs(Args, CmdArgs); - Args.addAllArgs(CmdArgs, - {options::OPT_T_Group, options::OPT_s, options::OPT_t, - options::OPT_Z_Flag, options::OPT_r}); + Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s, + options::OPT_t, options::OPT_r}); bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs); bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs); diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp index c98f43f6e05eb4b..7e6abd144428783 100644 --- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp +++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp @@ -193,9 +193,8 @@ void RISCV::Linker::ConstructJob(Compilation &C, const JobAction &JA, Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u}); ToolChain.AddFilePathLibArgs(Args, CmdArgs); - Args.addAllArgs(CmdArgs, - {options::OPT_T_Group, options::OPT_s, options::OPT_t, - options::OPT_Z_Flag, options::OPT_r}); + Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s, + options::OPT_t, options::OPT_r}); // TODO: add C++ includes and libs if compiling C++. diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c index 05d290a309c40c0..c84b54f24fdc24c 100644 --- a/clang/test/Driver/openbsd.c +++ b/clang/test/Driver/openbsd.c @@ -30,8 +30,6 @@ // RUN: | FileCheck --check-prefix=CHECK-LD-S %s // RUN: %clang --target=i686-pc-openbsd -t -### %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-LD-T %s -// RUN: %clang --target=i686-pc-openbsd -Z -### %s 2>&1 \ -// RUN: | FileCheck --check-prefix=CHECK-LD-Z %s // RUN: %clang --target=mips64-unknown-openbsd -### %s 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-MIPS64-LD %s // RUN: %clang --target=mips64el-unknown-openbsd -### %s 2>&1 \ @@ -44,8 +42,6 @@ // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o" // CHECK-LD-T: "-cc1" "-triple" "i686-pc-openbsd" // CHECK-LD-T: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-t" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o" -// CHECK-LD-Z: "-cc1" "-triple" "i686-pc-openbsd" -// CHECK-LD-Z: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-Z" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o" // CHECK-MIPS64-LD: "-cc1" "-triple" "mips64-unknown-openbsd" // CHECK-MIPS64-LD: ld{{.*}}" "-EB" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o" // CHECK-MIPS64EL-LD: "-cc1" "-triple" "mips64el-unknown-openbsd" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits