If I only have the binary executable file, how can I tell what linker was it built with?
Asked
Active
Viewed 426 times
1
-
Why do you need to know? Commonly you cannot tell this. – the busybee Jul 12 '21 at 07:55
-
Well, I think that might be useful in different situations. In my case, I am building from a machine where I _think_ I had previously setup the LLD linker to be used for all projects, but the slow build times got me suspicious (even though LLD is faster than the default linker, it still [isn't very fast](https://stackoverflow.com/questions/67042345/why-isnt-rust-linker-faster-with-incremental-builds), so I can't judge solely by the build speed). Obviously, in my case I could check that on the build machine, but I thought it would be nice if there were a way to somehow check the binary itself. – at54321 Jul 12 '21 at 08:29
-
Just from the work a linker does, if it does not insert some identifying stuff, I have no idea how to differentiate linkers. (Given that the same linker script is used.) The binary is mostly (if not completely) a concatenation of object modules, with all references resolved. But I'm no expert in ELF. – the busybee Jul 12 '21 at 08:40
-
1In linux executables there is this section `.comment` that may be useful: `objdump -j .comment -s program`. – rodrigo Jul 12 '21 at 09:32
-
See this https://github.com/rust-lang/rust/issues/39915, seems LLD is not fully supported yet. – prehistoricpenguin Jul 13 '21 at 02:48
1 Answers
1
Thanks to rodrigo's comment, here is a solution that seems to do the trick:
$ objdump -j .comment -s some_app
I tested it on a simple hello-world app on Linux and here is the output:
A. With the default linker:
$ 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.
B. With the LLD linker:
$ 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..
BTW I used the following global config file ~/.cargo/config
to activate the LLD linker:
[build]
rustflags = [
"-C", "link-arg=-fuse-ld=lld",
]
This setting could be at a project-level only. That shouldn't really matter, I believe, but I am writing those details, since some people might find them useful.

at54321
- 8,726
- 26
- 46