gcc 如何查找 as、ld 和其他 binutils 可执行文件?
它们的位置是否硬编码到 gcc 代码中,还是 gcc 只是调用 as
而我们的 PATH 变量中必须有 as
位置?
在后一种情况下,我们如何创建两个完全独立的 gcc 工具链?我的意思是,我们怎样才能让 gcc-A
调用 as-A
和 gcc-B
调用 as-B
如果 as-A
和 as-B
都称为 as
?
Is their location hardcoded into gcc code or does gcc just call as
and we must have as
location in our PATH variable?
And in the latter case, how could we create two completely separate gcc toolchains? I mean, how can we make gcc-A
invoke as-A
and gcc-B
invoke as-B
if as-A
and as-B
are both called as
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一些路径(例如,到
cc1
)被编译。其他路径(例如,as
)在 $PATH 中使用正常查找。这可能会根据 GCC 配置的选项而有所不同。您可以通过使用
strace
运行并 grep 查找exec|stat
来相当轻松地判断。这是通过编译路径调用 cc1,正如您可以从
缺乏寻找它。它也不在 $PATH 中。
即在 $PATH 中查找
as
。你可以看出,因为它正在尝试每一个按顺序在 $PATH 中的位置。
我省略了很多 strace 输出——即使只有 stat 和 exec,它的
好几页长。
运行 gcc -v 将显示一些编译路径(作为配置行的一部分)。
Some of the paths (e.g., to
cc1
) are compiled in. Others (e.g.,as
) use normal lookup in $PATH. This can vary depending on the options GCC is configured with.You can tell fairly easily by running with
strace
, and grepping forexec|stat
.That is a call to cc1 by a compiled-in path, as you can see from the
lack of looking for it. Its also not in $PATH.
That is looking for
as
in $PATH. You can tell because its trying eachlocation in $PATH in order.
I've omitted a lot of strace output—even with just stat and exec, its
several pages long.
Running
gcc -v
will show you some of the compiled-in paths (as part of the configure line).我们如何创建两个完全独立的 gcc 工具链?
从源代码编译 GCC 两次,详细说明位于:单个主机上的多个 glibc 库
尽我所能,所有内容都是硬编码和高度耦合的瞧,我认为没有其他像样的解决方案。
查询 GCC 搜索路径
您还可以使用以下方式查询 GCC 搜索路径:
示例输出:
和特定程序:
示例输出:
GCC 规范文件
值得一提的是,什么实际上决定了最终的
cpp
、ld
、as
是GCC源代码中的“spec”文件,另见:GCC 的通行证和调用程序是什么?How could we create two completely separate gcc toolchains?
Compile GCC from source twice, detailed instructions at: Multiple glibc libraries on a single host
Everything is hardcoded and highly coupled as far as I can see, I don't think there is any other decent solution.
Query the GCC search path
You can also query the GCC search path with:
sample output:
and a specific program with:
sample output:
GCC spec files
It is wort mentioning that what actually determines the final
cpp
,ld
,as
are the "spec" files in the GCC source code, see also: What are GCC's passes and invoked programs?有一个临时选项:-B*prefix*,引用 gcc 文档:
There's an ad-hoc option for that: -B*prefix*, quoting gcc docs: