是否有类似于.spec文件的东西适用于Clang/LLVM?在哪里可以找到参考资料?

10
gcc驱动程序可以使用.specs文件配置特定的链接器、选项和其他细节(例如覆盖系统头文件)。

当前(截至本文撰写时)GCC版本(4.9.0)的手册在此处描述了Spec文件

对于Clang / LLVM是否有类似的机制。 显然,Clang也有一个driver概念,但我找不到任何关于Clang是否存在Spec Files或类似机制以及如何使用它们的文档。

我对C和C ++都很感兴趣,但可能指向其中任何一个都会让我开始。

目标是简要介绍覆盖系统头文件和库路径以及链接器。

2个回答

5
根据文档,Clang驱动程序没有直接对应于GCC规范文件的功能:

Clang驱动程序没有直接对应“规范(specs)”的功能。大多数嵌入在规范中的功能都在工具特定的参数转换例程中。控制编译流水线的规范部分通常是流水线阶段的一部分。

可以使用-nostdinc-isystem来覆盖#include搜索路径。
但我不知道如何覆盖链接器或完全覆盖库搜索路径。

2
要覆盖链接器搜索路径,请查看ld的手册以确定您需要的标志(例如-syslibroot),并告诉clang通过-Wl将它们传递给链接器。例如,此命令使我能够使用自定义版本的libstdc ++clang++ -std=c++11 -stdlib=libstdc++ -nostdinc++ -isystem/path/to/alt-stdlib/include/c++ -isystem/path/to/alt-stdlib/include/c++/x86_64-apple-darwin14.4.0 -L/path/to/alt-stdlib/lib -lstdc++ -Wl,-syslibroot,/usr/lib -Wl,-syslibroot,/path/to/alt-stdlib/lib test.cpp - Stuart Berg

4

事实证明,现在有一些非常接近规范文件的内容:配置文件

LLVM 12.x文档的相关摘录(请参见上面的链接):

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.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接