Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent to .spec files for Clang/LLVM and where can I find a reference?

Tags:

c++

c

gcc

clang

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.

like image 882
0xC0000022L Avatar asked Jun 30 '14 13:06

0xC0000022L


2 Answers

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 to clang), then Clang will search for file armv7l.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 for x86_64-cl.cfg and if it is not found, looks for x86_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 file x86_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 file linux.opts is searched for in the directory ~/.llvm/os.

like image 185
0xC0000022L Avatar answered Oct 15 '22 22:10

0xC0000022L


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.

like image 32
Mark Seaborn Avatar answered Oct 15 '22 20:10

Mark Seaborn