https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/83216
>From 6c68cdaef71eacbad4fc2f6b81d2845c08b124fd Mon Sep 17 00:00:00 2001 From: Brad Smith <b...@comstyle.com> Date: Tue, 27 Feb 2024 21:07:09 -0500 Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BSD, Fuchsia and Haiku Based on https://github.com/llvm/llvm-project/pull/76432 --- clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ++++++++--- clang/lib/Driver/ToolChains/Fuchsia.cpp | 5 ++++- clang/lib/Driver/ToolChains/Haiku.cpp | 7 +++++-- clang/lib/Driver/ToolChains/NetBSD.cpp | 5 ++++- clang/lib/Driver/ToolChains/OpenBSD.cpp | 6 +++++- clang/test/Driver/freebsd.c | 3 +++ clang/test/Driver/fuchsia.c | 4 ++++ clang/test/Driver/haiku.c | 4 ++++ clang/test/Driver/netbsd.c | 6 ++++++ clang/test/Driver/openbsd.c | 5 ++--- 10 files changed, 45 insertions(+), 11 deletions(-) diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp index 9d698f77583950..c5757ddebb0f3e 100644 --- a/clang/lib/Driver/ToolChains/FreeBSD.cpp +++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp @@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, const char *LinkingOutput) const { const auto &ToolChain = static_cast<const FreeBSD &>(getToolChain()); const Driver &D = ToolChain.getDriver(); + const llvm::Triple &Triple = ToolChain.getTriple(); const llvm::Triple::ArchType Arch = ToolChain.getArch(); const bool IsPIE = !Args.hasArg(options::OPT_shared) && @@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-dynamic-linker"); CmdArgs.push_back("/libexec/ld-elf.so.1"); } - const llvm::Triple &T = ToolChain.getTriple(); - if (Arch == llvm::Triple::arm || T.isX86()) + if (Arch == llvm::Triple::arm || Triple.isX86()) CmdArgs.push_back("--hash-style=both"); CmdArgs.push_back("--enable-new-dtags"); } @@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, case llvm::Triple::riscv64: CmdArgs.push_back("-m"); CmdArgs.push_back("elf64lriscv"); - CmdArgs.push_back("-X"); break; default: break; } + if (Triple.isRISCV64()) { + CmdArgs.push_back("-X"); + if (Args.hasArg(options::OPT_mno_relax)) + CmdArgs.push_back("--no-relax"); + } + if (Arg *A = Args.getLastArg(options::OPT_G)) { if (ToolChain.getTriple().isMIPS()) { StringRef v = A->getValue(); diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp index 14b838500becce..237d1554d4970d 100644 --- a/clang/lib/Driver/ToolChains/Fuchsia.cpp +++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp @@ -119,8 +119,11 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString(Dyld)); } - if (ToolChain.getArch() == llvm::Triple::riscv64) + if (Triple.isRISCV64()) { CmdArgs.push_back("-X"); + if (Args.hasArg(options::OPT_mno_relax)) + CmdArgs.push_back("--no-relax"); + } CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp b/clang/lib/Driver/ToolChains/Haiku.cpp index ca7faa68765abf..30464e2229e65b 100644 --- a/clang/lib/Driver/ToolChains/Haiku.cpp +++ b/clang/lib/Driver/ToolChains/Haiku.cpp @@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const JobAction &JA, const char *LinkingOutput) const { const auto &ToolChain = static_cast<const Haiku &>(getToolChain()); const Driver &D = ToolChain.getDriver(); - const llvm::Triple::ArchType Arch = ToolChain.getArch(); + const llvm::Triple &Triple = ToolChain.getTriple(); const bool Static = Args.hasArg(options::OPT_static); const bool Shared = Args.hasArg(options::OPT_shared); ArgStringList CmdArgs; @@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (!Shared) CmdArgs.push_back("--no-undefined"); - if (Arch == llvm::Triple::riscv64) + if (Triple.isRISCV64()) { CmdArgs.push_back("-X"); + if (Args.hasArg(options::OPT_mno_relax)) + CmdArgs.push_back("--no-relax"); + } assert((Output.isFilename() || Output.isNothing()) && "Invalid output."); if (Output.isFilename()) { diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp b/clang/lib/Driver/ToolChains/NetBSD.cpp index 645d0311641f34..0eec8fddabd5db 100644 --- a/clang/lib/Driver/ToolChains/NetBSD.cpp +++ b/clang/lib/Driver/ToolChains/NetBSD.cpp @@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, break; } - if (Triple.isRISCV()) + if (Triple.isRISCV()) { CmdArgs.push_back("-X"); + if (Args.hasArg(options::OPT_mno_relax)) + CmdArgs.push_back("--no-relax"); + } assert((Output.isFilename() || Output.isNothing()) && "Invalid output."); if (Output.isFilename()) { diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp index 97f88b7b79dfbe..6da6728585df93 100644 --- a/clang/lib/Driver/ToolChains/OpenBSD.cpp +++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -111,6 +111,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, const char *LinkingOutput) const { const auto &ToolChain = static_cast<const OpenBSD &>(getToolChain()); const Driver &D = ToolChain.getDriver(); + const llvm::Triple &Triple = ToolChain.getTriple(); const llvm::Triple::ArchType Arch = ToolChain.getArch(); const bool Static = Args.hasArg(options::OPT_static); const bool Shared = Args.hasArg(options::OPT_shared); @@ -160,8 +161,11 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (Nopie || Profiling) CmdArgs.push_back("-nopie"); - if (Arch == llvm::Triple::riscv64) + if (Triple.isRISCV64()) { CmdArgs.push_back("-X"); + if (Args.hasArg(options::OPT_mno_relax)) + CmdArgs.push_back("--no-relax"); + } assert((Output.isFilename() || Output.isNothing()) && "Invalid output."); if (Output.isFilename()) { diff --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c index e1ce8889459f97..62df9b024b30d6 100644 --- a/clang/test/Driver/freebsd.c +++ b/clang/test/Driver/freebsd.c @@ -203,3 +203,6 @@ // RELOCATABLE-NOT: "-l // RELOCATABLE-NOT: crt{{[^./\\]+}}.o +// RUN: %clang --target=riscv64-unknown-freebsd -mno-relax -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-RISCV64-FLAGS %s +// CHECK-RISCV64-FLAGS: "-X" "--no-relax" diff --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c index ca53f0d107a005..1900ccaa625e31 100644 --- a/clang/test/Driver/fuchsia.c +++ b/clang/test/Driver/fuchsia.c @@ -292,3 +292,7 @@ // RUN: | FileCheck %s -check-prefix=CHECK-PROFRT-X86_64 // CHECK-PROFRT-X86_64: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" // CHECK-PROFRT-X86_64: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}x86_64-unknown-fuchsia{{/|\\\\}}libclang_rt.profile.a" + +// RUN: %clang --target=riscv64-unknown-fuchsia -mno-relax -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-RISCV64-FLAGS %s +// CHECK-RISCV64-FLAGS: "-X" "--no-relax" diff --git a/clang/test/Driver/haiku.c b/clang/test/Driver/haiku.c index e907c34b29b995..1ea28cd699cc1c 100644 --- a/clang/test/Driver/haiku.c +++ b/clang/test/Driver/haiku.c @@ -76,6 +76,10 @@ // RUN: | FileCheck --check-prefix=CHECK-ARM-CPU %s // CHECK-ARM-CPU: "-target-cpu" "arm1176jzf-s" +// RUN: %clang --target=riscv64-unknown-haiku -mno-relax -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-RISCV64-FLAGS %s +// CHECK-RISCV64-FLAGS: "-X" "--no-relax" + // Check passing LTO flags to the linker // RUN: %clang --target=x86_64-unknown-haiku -flto -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-LTO-FLAGS %s diff --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c index 73777e7a3e38fa..8b7b69e3cd8701 100644 --- a/clang/test/Driver/netbsd.c +++ b/clang/test/Driver/netbsd.c @@ -342,3 +342,9 @@ // DRIVER-PASS-INCLUDES: "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]" // DRIVER-PASS-INCLUDES-SAME: "-internal-isystem" "[[RESOURCE]]{{/|\\\\}}include" // DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-externc-isystem" "{{.*}}/usr/include" + +// RUN: %clang --target=riscv32-unknown-netbsd -mno-relax -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-RISCV-FLAGS %s +// RUN: %clang --target=riscv64-unknown-netbsd -mno-relax -### %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-RISCV-FLAGS %s +// CHECK-RISCV-FLAGS: "-X" "--no-relax" diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c index 68d33c5dd01e22..9ef79cc36c9357 100644 --- a/clang/test/Driver/openbsd.c +++ b/clang/test/Driver/openbsd.c @@ -127,10 +127,9 @@ // UNWIND-TABLES: "-funwind-tables=2" // NO-UNWIND-TABLES-NOT: "-funwind-tables=2" -// Check that the -X flag is passed to the linker on riscv64 -// RUN: %clang --target=riscv64-unknown-openbsd -### %s 2>&1 \ +// RUN: %clang --target=riscv64-unknown-openbsd -mno-relax -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-RISCV64-FLAGS %s -// CHECK-RISCV64-FLAGS: "-X" +// CHECK-RISCV64-FLAGS: "-X" "--no-relax" // Check passing LTO flags to the linker // RUN: %clang --target=amd64-unknown-openbsd -flto -### %s 2>&1 \ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits