I'm building the following program in Rust:
fn main() {
println!("Hello, world!\n");
}
on a Devuan Excalibur system (like Debian Trixie but without systemd; rustc version 1.84). After building it (with cargo build --release
), I have:
$ ldd target/release/hello
linux-vdso.so.1 (0x00007fff356f5000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0b073c5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0b071cf000)
/lib64/ld-linux-x86-64.so.2 (0x00007f0b0749c000)
This is a bit weird, as with a hello-world C program:
#include <stdio.h>
int main() {
printf("Hello world\n");
return 0;
}
and GCC 14.2 (gcc -O3
), I get:
$ ldd hello
linux-vdso.so.1 (0x00007fff1d573000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8f1649f000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8f166e5000)
that is, no libgcc_s
dependency. What is the Rust compiler putting in my executable that needs the extra dependency, and why?
Note: I was first wondering about the executable size differences; but that is addressed by this question.
This is presumably a dependency of the Rust standard library. If you build a simple Rust binary crate with the no_std
attribute, it doesn't link against libgcc_s
(on my system, anyway).
$ rustc -lc -Cpanic=abort -o test - <<SRC
#![no_std]
#![no_main]
#[unsafe(no_mangle)]
fn main() {}
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}
SRC
$ ldd test
linux-vdso.so.1 (0x00007f7d61187000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7d60f5b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7d61189000)