Skip to content

Commit 4f85ea5

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 78a8c8a commit 4f85ea5

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5684,6 +5684,8 @@ def print_multi_directory : Flag<["-", "--"], "print-multi-directory">;
56845684
def print_multi_lib : Flag<["-", "--"], "print-multi-lib">;
56855685
def print_multi_flags : Flag<["-", "--"], "print-multi-flags-experimental">,
56865686
HelpText<"Print the flags used for selecting multilibs (experimental)">;
5687+
def fmultilib_flag : Joined<["-", "--"], "fmultilib-flag=">,
5688+
Visibility<[ClangOption]>;
56875689
def print_multi_os_directory : Flag<["-", "--"], "print-multi-os-directory">,
56885690
Flags<[Unsupported]>;
56895691
def print_target_triple : Flag<["-", "--"], "print-target-triple">,

clang/lib/Driver/ToolChain.cpp

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

199+
static void
200+
processARMAArch64MultilibCustomFlags(Multilib::flags_list &List,
201+
const llvm::opt::ArgList &Args) {
202+
for (const Arg *MultilibFlagArg :
203+
Args.filtered(options::OPT_fmultilib_flag)) {
204+
List.push_back(MultilibFlagArg->getAsString(Args));
205+
MultilibFlagArg->claim();
206+
}
207+
}
208+
199209
static void getAArch64MultilibFlags(const Driver &D,
200210
const llvm::Triple &Triple,
201211
const llvm::opt::ArgList &Args,
@@ -232,6 +242,8 @@ static void getAArch64MultilibFlags(const Driver &D,
232242
if (ABIArg) {
233243
Result.push_back(ABIArg->getAsString(Args));
234244
}
245+
246+
processARMAArch64MultilibCustomFlags(Result, Args);
235247
}
236248

237249
static void getARMMultilibFlags(const Driver &D,
@@ -285,6 +297,8 @@ static void getARMMultilibFlags(const Driver &D,
285297
if (BranchProtectionArg) {
286298
Result.push_back(BranchProtectionArg->getAsString(Args));
287299
}
300+
301+
processARMAArch64MultilibCustomFlags(Result, Args);
288302
}
289303

290304
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
@@ -82,3 +82,10 @@
8282
// CHECK-RV32E-ORDER: --target=riscv32-unknown-none-elf
8383
// CHECK-RV32E-ORDER: -mabi=ilp32e
8484
// CHECK-RV32E-ORDER: -march=rv32e{{[0-9]+p[0-9]+}}_c{{[0-9]+p[0-9]+}}_zicsr{{[0-9]+p[0-9]+}}
85+
86+
// 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
87+
// 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
88+
// CHECK-ARM-MULTILIB-CUSTOM-FLAG: --target=thumbv8m.main-unknown-none-eabi
89+
// CHECK-AARCH64-MULTILIB-CUSTOM-FLAG: --target=aarch64-unknown-none-eabi
90+
// CHECK-MULTILIB-CUSTOM-FLAG-DAG: -fmultilib-flag=foo
91+
// CHECK-MULTILIB-CUSTOM-FLAG-DAG: -fmultilib-flag=bar

0 commit comments

Comments
 (0)