Author: Victor Campos Date: 2025-01-13T13:53:53Z New Revision: 2a551ab3002897ba52a27961b766f3741695c816
URL: https://github.com/llvm/llvm-project/commit/2a551ab3002897ba52a27961b766f3741695c816 DIFF: https://github.com/llvm/llvm-project/commit/2a551ab3002897ba52a27961b766f3741695c816.diff LOG: [Multilib] Add -fmultilib-flag command-line option (#110658) This patch is the second step to extend the current multilib system to support the selection of library variants which do not correspond to existing command-line options. Proposal can be found in https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058 The multilib mechanism supports libraries that target code generation or language options such as --target, -mcpu, -mfpu, -mbranch-protection. However, some library variants are particular to features that do not correspond to any command-line options. Examples include variants for multithreading and semihosting. This work introduces a way to instruct the multilib system to consider these features in library selection. The driver must be informed about the multilib custom flags with a new command-line option. ``` -fmultilib-flag=C ``` Where the grammar for C is: ``` C -> option option -> multithreaded | no-multithreaded | io-none | io-semihosting | io-linux-syscalls | ... ``` There must be one option instance for each flag specified: ``` -fmultilib-flag=multithreaded -fmultilib-flag=io-semihosting ``` Contradictory options are untied by *last one wins*. These options are to be used exclusively by the multilib mechanism in the Clang driver. Hence they are not forwarded to the compiler frontend. Added: Modified: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChain.cpp clang/test/Driver/print-multi-selection-flags.c Removed: ################################################################################ diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 80360216c9503a..bbf5c0e7e7fd1a 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5756,6 +5756,8 @@ def print_multi_directory : Flag<["-", "--"], "print-multi-directory">; def print_multi_lib : Flag<["-", "--"], "print-multi-lib">; def print_multi_flags : Flag<["-", "--"], "print-multi-flags-experimental">, HelpText<"Print the flags used for selecting multilibs (experimental)">; +def fmultilib_flag : Joined<["-", "--"], "fmultilib-flag=">, + Visibility<[ClangOption]>; def print_multi_os_directory : Flag<["-", "--"], "print-multi-os-directory">, Flags<[Unsupported]>; def print_target_triple : Flag<["-", "--"], "print-target-triple">, diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 2b4df64f2789de..acf9d264d631b3 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -196,6 +196,15 @@ bool ToolChain::defaultToIEEELongDouble() const { return PPC_LINUX_DEFAULT_IEEELONGDOUBLE && getTriple().isOSLinux(); } +static void processMultilibCustomFlags(Multilib::flags_list &List, + const llvm::opt::ArgList &Args) { + for (const Arg *MultilibFlagArg : + Args.filtered(options::OPT_fmultilib_flag)) { + List.push_back(MultilibFlagArg->getAsString(Args)); + MultilibFlagArg->claim(); + } +} + static void getAArch64MultilibFlags(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, @@ -246,6 +255,8 @@ static void getAArch64MultilibFlags(const Driver &D, if (ABIArg) { Result.push_back(ABIArg->getAsString(Args)); } + + processMultilibCustomFlags(Result, Args); } static void getARMMultilibFlags(const Driver &D, @@ -313,6 +324,7 @@ static void getARMMultilibFlags(const Driver &D, if (Endian->getOption().matches(options::OPT_mbig_endian)) Result.push_back(Endian->getAsString(Args)); } + processMultilibCustomFlags(Result, Args); } static void getRISCVMultilibFlags(const Driver &D, const llvm::Triple &Triple, diff --git a/clang/test/Driver/print-multi-selection-flags.c b/clang/test/Driver/print-multi-selection-flags.c index 5bf6dca5096a73..cf9522aa068524 100644 --- a/clang/test/Driver/print-multi-selection-flags.c +++ b/clang/test/Driver/print-multi-selection-flags.c @@ -90,3 +90,10 @@ // CHECK-RV32E-ORDER: --target=riscv32-unknown-none-elf // CHECK-RV32E-ORDER: -mabi=ilp32e // CHECK-RV32E-ORDER: -march=rv32e{{[0-9]+p[0-9]+}}_c{{[0-9]+p[0-9]+}}_zicsr{{[0-9]+p[0-9]+}} + +// 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 +// 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 +// CHECK-ARM-MULTILIB-CUSTOM-FLAG: --target=thumbv8m.main-unknown-none-eabi +// CHECK-AARCH64-MULTILIB-CUSTOM-FLAG: --target=aarch64-unknown-none-eabi +// CHECK-MULTILIB-CUSTOM-FLAG-DAG: -fmultilib-flag=foo +// CHECK-MULTILIB-CUSTOM-FLAG-DAG: -fmultilib-flag=bar _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits