The gcc
driver can be configured to use a particular linker, particular options and other details (e.g. overriding system headers) using .specs
files.
The current (as of this writing) manual for version of GCC (4.9.0) describes the Spec Files here.
Is there a similar mechanism for Clang/LLVM. Apparently Clang has the notion of a driver as well, but I was unable to come up with any documentation on whether Spec Files or a similar mechanism exist for Clang and how to use them.
I am interested in this for both C and C++, but probably a pointer to either of them will get me started.
Goal is to override the system header and library paths as well as the linker as briefly mentioned before.
Turns out there is something pretty close to the specs files by now: configuration files.
Relevant excerpt from the LLVM 12.x documentation (see link above):
Another way to specify a configuration file is to encode it in executable name. For example, if the Clang executable is named
armv7l-clang
(it may be a symbolic link toclang
), then Clang will search for filearmv7l.cfg
in the directory where Clang resides.If a driver mode is specified in invocation, Clang tries to find a file specific for the specified mode. For example, if the executable file is named
x86_64-clang-cl
, Clang first looks forx86_64-cl.cfg
and if it is not found, looks forx86_64.cfg
.If the command line contains options that effectively change target architecture (these are
-m32
,-EL
, and some others) and the configuration file starts with an architecture name, Clang tries to load the configuration file for the effective architecture. For example, invocation:x86_64-clang -m32 abc.c
causes Clang search for a file
i368.cfg
first, and if no such file is found, Clang looks for the filex86_64.cfg
.The configuration file consists of command-line options specified on one or more lines. Lines composed of whitespace characters only are ignored as well as lines in which the first non-blank character is
#
. Long options may be split between several lines by a trailing backslash. Here is example of a configuration file:# Several options on line -c --target=x86_64-unknown-linux-gnu # Long option split between lines -I/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../\ include/c++/5.4.0 # other config files may be included @linux.options
Files included by
@file
directives in configuration files are resolved relative to the including file. For example, if a configuration file~/.llvm/target.cfg
contains the directive@os/linux.opts
, the filelinux.opts
is searched for in the directory~/.llvm/os
.
According to the docs, the Clang driver doesn't have a direct equivalent to GCC spec files:
The clang driver has no direct correspondent for “specs”. The majority of the functionality that is embedded in specs is in the Tool specific argument translation routines. The parts of specs which control the compilation pipeline are generally part of the Pipeline stage.
The #include search path can be overridden using -nostdinc
and -isystem
.
However, I don't know how to override the linker or fully override the library search path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With