From 429cbac0390654f90bba18a41799464adf31a5ec Mon Sep 17 00:00:00 2001 From: luxufan Date: Tue, 8 Mar 2022 19:28:10 +0800 Subject: [PATCH] [RISCV] Pass -mno-relax to assembler when -fno-integrated-as specified In the past, `clang --target=riscv64-unknown-linux-gnu -mno-relax -c hello.s` will assemble hello.s without relaxation, but `clang --target=riscv64-unknown-linux-gnu -mno-relax -fno-integrated-as -c hello.s` doesn't pass the `-mno-relax` option to assembler, and assemble with relaxation This patch pass the -mno-relax option to assembler when -fno-integrated-as is specified. Differential Revision: https://reviews.llvm.org/D120639 --- clang/lib/Driver/ToolChains/Gnu.cpp | 2 ++ clang/test/Driver/riscv-gnutools.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index ae848cf..5816b91 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -764,6 +764,8 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C, StringRef MArchName = riscv::getRISCVArch(Args, getToolChain().getTriple()); CmdArgs.push_back("-march"); CmdArgs.push_back(MArchName.data()); + if (!Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true)) + Args.addOptOutFlag(CmdArgs, options::OPT_mrelax, options::OPT_mno_relax); break; } case llvm::Triple::sparc: diff --git a/clang/test/Driver/riscv-gnutools.c b/clang/test/Driver/riscv-gnutools.c index 2b44494..685b320 100644 --- a/clang/test/Driver/riscv-gnutools.c +++ b/clang/test/Driver/riscv-gnutools.c @@ -16,9 +16,14 @@ // RUN: %clang --target=riscv32-unknown-elf --gcc-toolchain=%S/Inputs/basic_riscv32_tree -fno-integrated-as %s -### -c -march=rv32g \ // RUN: 2>&1 | FileCheck -check-prefix=CHECK-RV32G-ILP32D %s +// Check -mno-relax is passed when -fno-integrated-as specified +// RUN: %clang -target riscv32-unknown-elf --gcc-toolchain=%S/Inputs/basic_riscv32_tree -mno-relax -fno-integrated-as %s -### -c \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-RV32-NO-RELAX %s + // CHECK-RV32IMAC-ILP32: "{{.*}}as{{(.exe)?}}" "-mabi" "ilp32" "-march" "rv32imac" // CHECK-RV32IMAFDC-ILP32D: "{{.*}}as{{(.exe)?}}" "-mabi" "ilp32d" "-march" "rv32imafdc" // CHECK-RV32G-ILP32D: "{{.*}}as{{(.exe)?}}" "-mabi" "ilp32d" "-march" "rv32g" +// CHECK-RV32-NO-RELAX: "{{.*}}as{{(.exe)?}}" "{{.*}}" "-mno-relax" // 64-bit checks @@ -35,6 +40,12 @@ // RUN: %clang --target=riscv64-unknown-elf --gcc-toolchain=%S/Inputs/basic_riscv64_tree -fno-integrated-as %s -### -c -march=rv64g \ // RUN: 2>&1 | FileCheck -check-prefix=CHECK-RV64G-LP64D %s +// Check -mno-relax is not passed when -fno-integrated-as specified +// RUN: %clang -target riscv64-unknown-elf --gcc-toolchain=%S/Inputs/basic_riscv64_tree -mno-relax -mrelax -fno-integrated-as %s -### -c \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK-RV64-RELAX %s + // CHECK-RV64IMAC-LP64: "{{.*}}as{{(.exe)?}}" "-mabi" "lp64" "-march" "rv64imac" // CHECK-RV64IMAFDC-LP64D: "{{.*}}as{{(.exe)?}}" "-mabi" "lp64d" "-march" "rv64imafdc" // CHECK-RV64G-LP64D: "{{.*}}as{{(.exe)?}}" "-mabi" "lp64d" "-march" "rv64g" +// CHECK-RV64-RELAX: "{{.*}}as{{(.exe)?}}" +// CHECK-RV64-RELAX-NOT: "-mno-relax" -- 2.7.4