https://sourceware.org/bugzilla/show_bug.cgi?id=33300

            Bug ID: 33300
           Summary: strip --strip-unneeded "breaks" libc.a (causing
                    segfault in Rust programs linked libc statically)
           Product: binutils
           Version: 2.45
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: binutils
          Assignee: unassigned at sourceware dot org
          Reporter: xry111 at xry111 dot site
  Target Milestone: ---

With the latest Glibc and Binutils release, we found stripping libc.a
with --strip-unneeded will cause any Rust programs compiled with -C
target-feature=+crc-static (i.e. linking against the static libc) to
segfault on startup.  To reproduce:

$ cat hw.rs
pub fn main() {
    println!("Hello, world.");
}
$ unshare -mr env PS1="(unshared ns)# " LC_ALL=C bash --norc
(unshared ns)# cp /usr/lib/libc.a /tmp
(unshared ns)# strip --strip-unneeded /tmp/libc.a
(unshared ns)# mount --bind /tmp/libc.a /usr/lib/libc.a
(unshared ns)# rustc hw.rs -C target-feature=+crt-static
(unshared ns)# ./hw
Segmentation fault         (core dumped) ./hw
(unshared ns)# gdb hw
(gdb) r
Starting program: /home/xry111/hw

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x00007ffff7f507a3 in _IO_doallocbuf ()
#2  0x00007ffff7f4d756 in _IO_new_file_underflow ()
#3  0x00007ffff7f4b313 in getdelim ()
#4  0x00007ffff7f169da in pthread_getattr_np ()
#5  0x00007ffff7ef28f6 in std::rt::lang_start_internal ()
#6  0x00007ffff7ed8911 in std::rt::lang_start ()
#7  0x00007ffff7ed8a45 in main ()

This can also be reproduced on Fedora Rawhide (where "/usr/lib" in the above
instructions needs to be change to "/usr/lib64").

We are currently working the issue around by using --strip-debug instead
of --strip-unneeded, but shouldn't --strip-
unneeded just keep anything that the linker may "need" to create a
correct executable?

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to