Skip to content

Commit 3e06d0b

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 0944b25 commit 3e06d0b

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
@@ -5658,6 +5658,8 @@ def print_multi_directory : Flag<["-", "--"], "print-multi-directory">;
56585658
def print_multi_lib : Flag<["-", "--"], "print-multi-lib">;
56595659
def print_multi_flags : Flag<["-", "--"], "print-multi-flags-experimental">,
56605660
HelpText<"Print the flags used for selecting multilibs (experimental)">;
5661+
def fmultilib_flag : Joined<["-", "--"], "fmultilib-flag=">,
5662+
Visibility<[ClangOption]>;
56615663
def print_multi_os_directory : Flag<["-", "--"], "print-multi-os-directory">,
56625664
Flags<[Unsupported]>;
56635665
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,
@@ -227,6 +237,8 @@ static void getAArch64MultilibFlags(const Driver &D,
227237
if (BranchProtectionArg) {
228238
Result.push_back(BranchProtectionArg->getAsString(Args));
229239
}
240+
241+
processARMAArch64MultilibCustomFlags(Result, Args);
230242
}
231243

232244
static void getARMMultilibFlags(const Driver &D,
@@ -280,6 +292,8 @@ static void getARMMultilibFlags(const Driver &D,
280292
if (BranchProtectionArg) {
281293
Result.push_back(BranchProtectionArg->getAsString(Args));
282294
}
295+
296+
processARMAArch64MultilibCustomFlags(Result, Args);
283297
}
284298

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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,8 @@
7777
// CHECK-RV32E-ORDER: --target=riscv32-unknown-none-elf
7878
// CHECK-RV32E-ORDER: -mabi=ilp32e
7979
// CHECK-RV32E-ORDER: -march=rv32e{{[0-9]+p[0-9]+}}_c{{[0-9]+p[0-9]+}}_zicsr{{[0-9]+p[0-9]+}}
80+
81+
// RUN: %clang -print-multi-flags-experimental --target=armv8m.main-none-eabi -fmultilib-flag=foo -fmultilib-flag=bar | FileCheck --check-prefix=CHECK-MULTILIB-CUSTOM-FLAG %s
82+
// CHECK-MULTILIB-CUSTOM-FLAG: --target=thumbv8m.main-unknown-none-eabi
83+
// CHECK-MULTILIB-CUSTOM-FLAG-DAG: -fmultilib-flag=foo
84+
// CHECK-MULTILIB-CUSTOM-FLAG-DAG: -fmultilib-flag=bar

0 commit comments

Comments
 (0)