dependencies - Why does my hello-world rust executable depend on libgcc_s? - Stack Overflow

I'm building the following program in Rust:fn main() {println!("Hello, world!n");}on

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.

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.

Share Improve this question edited Mar 22 at 18:37 einpoklum asked Mar 22 at 11:37 einpoklumeinpoklum 133k80 gold badges420 silver badges864 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 2

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)

Rusts standard library links to gcc_s for unwinding in certain configurations:

#[cfg(target_env = "musl")]
cfg_if::cfg_if! {
    if #[cfg(all(feature = "llvm-libunwind", feature = "system-llvm-libunwind"))] {
    // …
    } else {
        #[link(name = "unwind", kind = "static", modifiers = "-bundle", cfg(target_feature = "crt-static"))]
        #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
        unsafe extern "C" {}
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744316690a4568218.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信