Hi all,
This is a proposal to extend the current multilib system to support the selection of library variants which do not correspond to existing command-line options.
Thanks in advance for the review and your suggestions.
The current 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. We thus propose that the multilib system should be extended to support these use cases.
This proposal introduces a way to instruct the multilib system to consider these features in library selection. The proposed solution comprises two changes:
- A new section in
multilib.yaml
to declare flags for which no option exists. Henceforth this sort of flag will be called custom flag for clarity. - A new command-line option in the Clang driver to use these custom flags.
Multilib flags declarations
The multilib.yaml
file will have a new section called Flags which contains the declarations of the targetâs custom flags:
Flags:
- Name: multithreaded
Values:
- no-multithreaded
- multithreaded
Default: no-multithreaded
- Name: io
Values:
- io-none
- io-semihosting
- io-linux-syscalls
Default: io-none
- Name: the name to categorize a flag.
- Values: a list of possible values.
- Default: it specifies which value this flag should take if not specified in the command-line invocation. It must be one value from the Values field.
A Default value is useful to save users from specifying custom flags that have a most commonly used value.
The namespace of flag values is common across all flags. This means that flag values must be unique.
The reasoning for n-ary flags is expanded in the Appendix.
New command-line option to use multilib flags
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.
List supported custom flags
Another command-line option to list all flags declarations is proposed:
-fmultilib-flag-list
Output:
multithreaded:
multithreaded
semihosted
io:
io-none
io-semihosting
io-linux-syscalls
Usage of custom flags by the Variants specifications
Library variants should list their requirement on one or more custom flags like they do for any other flag. The new command-line option is passed as-is to the multilib system, therefore it should be listed in the same format as described in Section New command-line option to use multilib flags.
Moreover, a variant that does not specify a requirement on any particular flag can be matched against any value of that flag. For instance, letâs introduce a new custom flag called heap-opt that governs the selection of optimized memory allocation functions as a multilib layer. In the example below, the use of -fmultilib-flag=heap-opt-size
enables the selection of the multilib layer heap_optsize, while at the same time enabling the match to the most suitable base C library (as the latter does not list any requirement on the heap-opt dimension).
Variants:
- Dir: libc
Group: stdlibs
Flags:
- -march=armv8-a
- -mfpu=none
- -fmultilib-flag=no-multithreaded
- -fmultilib-flag=io-semihosting
- Dir: libc_multithreaded
Group: stdlibs
Flags:
- -march=armv8-a
- -mfpu=none
- -fmultilib-flag=multithreaded
- -fmultilib-flag=io-semihosting
- Dir: libc_nosemihosting_multithreaded
Group: stdlibs
Flags:
- -march=armv8-a
- -mfpu=none
- -fmultilib-flag=no-multithreaded
- -fmultilib-flag=io-none
- Dir: libc_nosemihosting
Group: stdlibs
Flags:
- -march=armv8-a
- -mfpu=none
- -fmultilib-flag=no-multithreaded
- -fmultilib-flag=io-none
- Dir: heap_optsize
Flags:
- -march=armv8-a
- -fmultilib-flag=heap-opt-size
Flags:
- Name: multithreaded
Values:
- no-multithreaded
- multithreaded
Default: no-multithreaded
- Name: io
Values:
- io-none
- io-semihosting
- io-linux-syscalls
Default: io-none
- Name: heap-opt
Values:
- heap-opt-size
- heap-opt-security
- heap-opt-fast
Default: heap-opt-size
Semantic check of multilib flags
The use of unsupported flags should emit a warning such as:
warning: unsupport multilib flag âfooâ
Appendix: design decisions
N-ary flags
The choice for n-ary flags over binary flags is motivated by some features for which the choice is more than a simple on/off. Examples include:
- I/O:
- stubs for IO functions;
- semihosting-aware;
- implemented using Linux syscalls;
- Heap optimised for:
- size;
- performance;
- security.