什么链接器用于构建 Rust 二进制文件?
What linker was used to build a Rust binary?
如果我只有二进制可执行文件,我怎么知道它是用什么链接器构建的?
感谢 rodrigo 的评论,这是一个似乎可以解决问题的解决方案:
$ objdump -j .comment -s some_app
我在 Linux 上的一个简单的 hello-world 应用程序上对其进行了测试,这是输出:
一个。使用默认链接器:
$ objdump -j .comment -s target/release/my_hello_world_app
target/release/my_hello_world_app: file format elf64-x86-64
Contents of section .comment:
0000 4743433a 20285562 756e7475 20392e33 GCC: (Ubuntu 9.3
0010 2e302d31 37756275 6e747531 7e32302e .0-17ubuntu1~20.
0020 30342920 392e332e 3000 04) 9.3.0.
乙。使用 LLD 链接器:
$ objdump -j .comment -s target/release/my_hello_world_app
target/release/my_hello_world_app: file format elf64-x86-64
Contents of section .comment:
0000 4c696e6b 65723a20 4c4c4420 31302e30 Linker: LLD 10.0
0010 2e300047 43433a20 28556275 6e747520 .0.GCC: (Ubuntu
0020 392e332e 302d3137 7562756e 7475317e 9.3.0-17ubuntu1~
0030 32302e30 34292039 2e332e30 0000 20.04) 9.3.0..
顺便说一句,我使用以下全局配置文件 ~/.cargo/config
来激活 LLD 链接器:
[build]
rustflags = [
"-C", "link-arg=-fuse-ld=lld",
]
此设置只能在项目级别。我相信这并不重要,但我正在写这些细节,因为有些人可能会发现它们很有用。
如果我只有二进制可执行文件,我怎么知道它是用什么链接器构建的?
感谢 rodrigo 的评论,这是一个似乎可以解决问题的解决方案:
$ objdump -j .comment -s some_app
我在 Linux 上的一个简单的 hello-world 应用程序上对其进行了测试,这是输出:
一个。使用默认链接器:
$ objdump -j .comment -s target/release/my_hello_world_app
target/release/my_hello_world_app: file format elf64-x86-64
Contents of section .comment:
0000 4743433a 20285562 756e7475 20392e33 GCC: (Ubuntu 9.3
0010 2e302d31 37756275 6e747531 7e32302e .0-17ubuntu1~20.
0020 30342920 392e332e 3000 04) 9.3.0.
乙。使用 LLD 链接器:
$ objdump -j .comment -s target/release/my_hello_world_app
target/release/my_hello_world_app: file format elf64-x86-64
Contents of section .comment:
0000 4c696e6b 65723a20 4c4c4420 31302e30 Linker: LLD 10.0
0010 2e300047 43433a20 28556275 6e747520 .0.GCC: (Ubuntu
0020 392e332e 302d3137 7562756e 7475317e 9.3.0-17ubuntu1~
0030 32302e30 34292039 2e332e30 0000 20.04) 9.3.0..
顺便说一句,我使用以下全局配置文件 ~/.cargo/config
来激活 LLD 链接器:
[build]
rustflags = [
"-C", "link-arg=-fuse-ld=lld",
]
此设置只能在项目级别。我相信这并不重要,但我正在写这些细节,因为有些人可能会发现它们很有用。