Skip to content

Commit 17265b1

Browse files
committed
[Multilib] Add -fmultilib-flag command-line option
This option is passed through to the multilib system. It is then used in conjunction with other options to select the proper library variant. Details about this change can be found in this thread: https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058
1 parent 42c7ca1 commit 17265b1

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5721,6 +5721,8 @@ def print_multi_directory : Flag<["-", "--"], "print-multi-directory">;
57215721
def print_multi_lib : Flag<["-", "--"], "print-multi-lib">;
57225722
def print_multi_flags : Flag<["-", "--"], "print-multi-flags-experimental">,
57235723
HelpText<"Print the flags used for selecting multilibs (experimental)">;
5724+
def fmultilib_flag : Joined<["-", "--"], "fmultilib-flag=">,
5725+
Visibility<[ClangOption]>;
57245726
def print_multi_os_directory : Flag<["-", "--"], "print-multi-os-directory">,
57255727
Flags<[Unsupported]>;
57265728
def print_target_triple : Flag<["-", "--"], "print-target-triple">,

clang/lib/Driver/ToolChain.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ bool ToolChain::defaultToIEEELongDouble() const {
196196
return PPC_LINUX_DEFAULT_IEEELONGDOUBLE && getTriple().isOSLinux();
197197
}
198198

199+
static void processMultilibCustomFlags(Multilib::flags_list &List,
200+
const llvm::opt::ArgList &Args) {
201+
for (const Arg *MultilibFlagArg :
202+
Args.filtered(options::OPT_fmultilib_flag)) {
203+
List.push_back(MultilibFlagArg->getAsString(Args));
204+
MultilibFlagArg->claim();
205+
}
206+
}
207+
199208
static void getAArch64MultilibFlags(const Driver &D,
200209
const llvm::Triple &Triple,
201210
const llvm::opt::ArgList &Args,
@@ -246,6 +255,8 @@ static void getAArch64MultilibFlags(const Driver &D,
246255
if (ABIArg) {
247256
Result.push_back(ABIArg->getAsString(Args));
248257
}
258+
259+
processMultilibCustomFlags(Result, Args);
249260
}
250261

251262
static void getARMMultilibFlags(const Driver &D,
@@ -313,6 +324,7 @@ static void getARMMultilibFlags(const Driver &D,
313324
if (Endian->getOption().matches(options::OPT_mbig_endian))
314325
Result.push_back(Endian->getAsString(Args));
315326
}
327+
processMultilibCustomFlags(Result, Args);
316328
}
317329

318330
static void getRISCVMultilibFlags(const Driver &D, const llvm::Triple &Triple,

clang/test/Driver/print-multi-selection-flags.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,10 @@
9090
// CHECK-RV32E-ORDER: --target=riscv32-unknown-none-elf
9191
// CHECK-RV32E-ORDER: -mabi=ilp32e
9292
// CHECK-RV32E-ORDER: -march=rv32e{{[0-9]+p[0-9]+}}_c{{[0-9]+p[0-9]+}}_zicsr{{[0-9]+p[0-9]+}}
93+
94+
// RUN: %clang -print-multi-flags-experimental --target=armv8m.main-none-eabi -fmultilib-flag=foo -fmultilib-flag=bar | FileCheck --check-prefixes=CHECK-MULTILIB-CUSTOM-FLAG,CHECK-ARM-MULTILIB-CUSTOM-FLAG %s
95+
// RUN: %clang -print-multi-flags-experimental --target=aarch64-none-eabi -fmultilib-flag=foo -fmultilib-flag=bar | FileCheck --check-prefixes=CHECK-MULTILIB-CUSTOM-FLAG,CHECK-AARCH64-MULTILIB-CUSTOM-FLAG %s
96+
// CHECK-ARM-MULTILIB-CUSTOM-FLAG: --target=thumbv8m.main-unknown-none-eabi
97+
// CHECK-AARCH64-MULTILIB-CUSTOM-FLAG: --target=aarch64-unknown-none-eabi
98+
// CHECK-MULTILIB-CUSTOM-FLAG-DAG: -fmultilib-flag=foo
99+
// CHECK-MULTILIB-CUSTOM-FLAG-DAG: -fmultilib-flag=bar

0 commit comments

Comments
 (0)