gcc 如何查找 as、ld 和其他 binutils 可执行文件?

发布于 2024-12-09 00:50:25 字数 286 浏览 0 评论 0原文

它们的位置是否硬编码到 gcc 代码中,还是 gcc 只是调用 as 而我们的 PATH 变量中必须有 as 位置?

在后一种情况下,我们如何创建两个完全独立的 gcc 工具链?我的意思是,我们怎样才能让 gcc-A 调用 as-Agcc-B 调用 as-B如果 as-Aas-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

Bonjour°[大白 2024-12-16 00:50:25

一些路径(例如,到 cc1)被编译。其他路径(例如,as)在 $PATH 中使用正常查找。这可能会根据 GCC 配置的选项而有所不同。

您可以通过使用 strace 运行并 grep 查找 exec|stat 来相当轻松地判断。

$ strace -f gcc foo.c -o foo |& grep exec
⋮
[pid 24943] execve("/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/cc1", …

这是通过编译路径调用 cc1,正如您可以从
缺乏寻找它。它也不在 $PATH 中。

[pid 24944] execve("/home/anthony/bin/as", ["as", "--64", "-o", "/tmp/ccCIrcGi.o", "/tmp/ccbw3PkL.s"], [/* 51 vars */]) = -1 ENOENT (No such file or directory)
[pid 24944] execve("/usr/local/bin/as", ["as", "--64", "-o", "/tmp/ccCIrcGi.o", "/tmp/ccbw3PkL.s"], [/* 51 vars */]) = -1 ENOENT (No such file or directory)
[pid 24944] execve("/usr/bin/as", ["as", "--64", "-o", "/tmp/ccCIrcGi.o", "/tmp/ccbw3PkL.s"], [/* 51 vars */]) = 0

即在 $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 for exec|stat.

$ strace -f gcc foo.c -o foo |& grep exec
⋮
[pid 24943] execve("/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/cc1", …

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.

[pid 24944] execve("/home/anthony/bin/as", ["as", "--64", "-o", "/tmp/ccCIrcGi.o", "/tmp/ccbw3PkL.s"], [/* 51 vars */]) = -1 ENOENT (No such file or directory)
[pid 24944] execve("/usr/local/bin/as", ["as", "--64", "-o", "/tmp/ccCIrcGi.o", "/tmp/ccbw3PkL.s"], [/* 51 vars */]) = -1 ENOENT (No such file or directory)
[pid 24944] execve("/usr/bin/as", ["as", "--64", "-o", "/tmp/ccCIrcGi.o", "/tmp/ccbw3PkL.s"], [/* 51 vars */]) = 0

That is looking for as in $PATH. You can tell because its trying each
location 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).

冰葑 2024-12-16 00:50:25

我们如何创建两个完全独立的 gcc 工具链?

从源代码编译 GCC 两次,详细说明位于:单个主机上的多个 glibc 库

尽我所能,所有内容都是硬编码和高度耦合的瞧,我认为没有其他像样的解决方案。

查询 GCC 搜索路径

您还可以使用以下方式查询 GCC 搜索路径:

gcc -print-search-dirs | grep -E '^programs' | tr ':' '\n'

示例输出:

programs
 =/usr/lib/gcc/x86_64-linux-gnu/6/
/usr/lib/gcc/x86_64-linux-gnu/6/
/usr/lib/gcc/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/6/
/usr/lib/gcc/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/6/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/6/
/usr/lib/gcc/x86_64-linux-gnu/6/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/6/../../../../x86_64-linux-gnu/bin/

和特定程序:

gcc -print-prog-name=cc1

示例输出:

/usr/lib/gcc/x86_64-linux-gnu/6/cc1

GCC 规范文件

值得一提的是,什么实际上决定了最终的cppldas是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:

gcc -print-search-dirs | grep -E '^programs' | tr ':' '\n'

sample output:

programs
 =/usr/lib/gcc/x86_64-linux-gnu/6/
/usr/lib/gcc/x86_64-linux-gnu/6/
/usr/lib/gcc/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/6/
/usr/lib/gcc/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/6/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/6/
/usr/lib/gcc/x86_64-linux-gnu/6/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/6/../../../../x86_64-linux-gnu/bin/

and a specific program with:

gcc -print-prog-name=cc1

sample output:

/usr/lib/gcc/x86_64-linux-gnu/6/cc1

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?

べ映画 2024-12-16 00:50:25

有一个临时选项:-B*prefix*,引用 gcc 文档:

对于要运行的每个子程序,编译器驱动程序首先尝试 -B 前缀(如果有)。如果
找不到该名称,或者如果未指定 -B,则驱动程序会尝试两个标准前缀,
分别是 /usr/lib/gcc/ 和 /usr/local/lib/gcc/。 [...]

There's an ad-hoc option for that: -B*prefix*, quoting gcc docs:

For each subprogram to be run, the compiler driver first tries the -B prefix, if any. If
that name is not found, or if -B was not specified, the driver tries two standard prefixes,
which are /usr/lib/gcc/ and /usr/local/lib/gcc/. [...]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文