Skip to content

Commit b1acbb1

Browse files
author
Andreu Carminati
committed
Include -mno-relax forwarding for GNU environment (ld)
According reviewer's suggestion.
1 parent 13648ea commit b1acbb1

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,12 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
423423
D.Diag(diag::err_target_unknown_triple) << Triple.str();
424424
return;
425425
}
426-
if (Triple.isRISCV())
426+
427+
if (Triple.isRISCV()) {
427428
CmdArgs.push_back("-X");
429+
if (Args.hasArg(options::OPT_mno_relax))
430+
CmdArgs.push_back("--no-relax");
431+
}
428432

429433
const bool IsShared = Args.hasArg(options::OPT_shared);
430434
if (IsShared)

clang/test/Driver/riscv32-toolchain.c

+16
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,22 @@
231231
// RUN: | FileCheck --check-prefix=CHECK-RV32-RELAX %s
232232
// CHECK-RV32-RELAX-NOT: "--no-relax"
233233

234+
// Check that "--no-relax" is forwarded to the linker for RISC-V (Gnu.cpp).
235+
// RUN: env "PATH=" %clang -### %s -fuse-ld=ld -no-pie -mno-relax \
236+
// RUN: --target=riscv32-unknown-linux-gnu --rtlib=platform --unwindlib=platform -mabi=ilp32 \
237+
// RUN: --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
238+
// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
239+
// RUN: | FileCheck -check-prefix=CHECK-RV32-GNU-NORELAX %s
240+
// CHECK-RV32-GNU-NORELAX: "--no-relax"
241+
242+
// Check that "--no-relax" is not forwarded to the linker for RISC-V (Gnu.cpp).
243+
// RUN: env "PATH=" %clang -### %s -fuse-ld=ld -no-pie \
244+
// RUN: --target=riscv32-unknown-linux-gnu --rtlib=platform --unwindlib=platform -mabi=ilp32 \
245+
// RUN: --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
246+
// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
247+
// RUN: | FileCheck -check-prefix=CHECK-RV32-GNU-RELAX %s
248+
// CHECK-RV32-GNU-RELAX-NOT: "--no-relax"
249+
234250
typedef __builtin_va_list va_list;
235251
typedef __SIZE_TYPE__ size_t;
236252
typedef __PTRDIFF_TYPE__ ptrdiff_t;

clang/test/Driver/riscv64-toolchain.c

+16
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@
187187
// RUN: | FileCheck --check-prefix=CHECK-RV64-RELAX %s
188188
// CHECK-RV64-RELAX-NOT: "--no-relax"
189189

190+
// Check that "--no-relax" is forwarded to the linker for RISC-V (Gnu.cpp).
191+
// RUN: env "PATH=" %clang -### %s -fuse-ld=ld -no-pie -mno-relax \
192+
// RUN: --target=riscv64-unknown-linux-gnu --rtlib=platform --unwindlib=platform -mabi=lp64 \
193+
// RUN: --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
194+
// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
195+
// RUN: | FileCheck -check-prefix=CHECK-RV64-GNU-NORELAX %s
196+
// CHECK-RV64-GNU-NORELAX: "--no-relax"
197+
198+
// Check that "--no-relax" is not forwarded to the linker for RISC-V (Gnu.cpp).
199+
// RUN: env "PATH=" %clang -### %s -fuse-ld=ld -no-pie \
200+
// RUN: --target=riscv64-unknown-linux-gnu --rtlib=platform --unwindlib=platform -mabi=lp64 \
201+
// RUN: --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
202+
// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
203+
// RUN: | FileCheck -check-prefix=CHECK-RV64-GNU-RELAX %s
204+
// CHECK-RV64-GNU-RELAX-NOT: "--no-relax"
205+
190206
typedef __builtin_va_list va_list;
191207
typedef __SIZE_TYPE__ size_t;
192208
typedef __PTRDIFF_TYPE__ ptrdiff_t;

0 commit comments

Comments
 (0)