rust-lang / rust-lang/rust-bindgen

segfault on powerpc

Open
#1,746 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

(see also https://bugs.debian.org/953648, on bindgen 0.51.1)

Input C/C++ Header
void i_am_looking_at_the(void);
Bindgen Invocation
$ RUST_BACKTRACE=1 bindgen void.h
Actual Results
(sid_powerpc-dchroot)dkg@perotto:~/src/bindgen-test$ RUST_BACKTRACE=1 bindgen void.h 
Segmentation fault
(sid_powerpc-dchroot)dkg@perotto:~/src/bindgen-test$ 
Expected Results

no segfault 😛

(sid_powerpc-dchroot)dkg@perotto:~/src/bindgen-test$ echo 'void i_am_looking_at_the(void);' > void.h
(sid_powerpc-dchroot)dkg@perotto:~/src/bindgen-test$ ulimit -c 10000000
(sid_powerpc-dchroot)dkg@perotto:~/src/bindgen-test$ bindgen void.h
Segmentation fault (core dumped)
(sid_powerpc-dchroot)dkg@perotto:~/src/bindgen-test$ gdb -c core $(which bindgen)
GNU gdb (Debian 9.1-2) 9.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "powerpc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/bindgen...
Reading symbols from /usr/lib/debug/.build-id/de/e00c8c6783edceb776638570fde91cededf1ba.debug...
[New LWP 41431]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/powerpc-linux-gnu/libthread_db.so.1".
bt
Core was generated by `bindgen void.h'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  strlen () at ../sysdeps/powerpc/powerpc32/strlen.S:98
98	../sysdeps/powerpc/powerpc32/strlen.S: No such file or directory.
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /usr/bin/bindgen.
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) bt
#0  strlen () at ../sysdeps/powerpc/powerpc32/strlen.S:98
#1  0x00d337fc in std::ffi::c_str::CStr::from_ptr ()
#2  0x00b641a0 in bindgen::clang::cxstring_to_string_leaky (s=...) at src/clang.rs:1476
#3  bindgen::clang::cxstring_into_string (s=...) at src/clang.rs:1481
#4  bindgen::clang::extract_clang_version () at src/clang.rs:1925
#5  0x00ba14bc in bindgen::clang_version () at src/lib.rs:2121
#6  0x00aa2554 in bindgen::main () at src/main.rs:26
(gdb) up
#1  0x00d337fc in std::ffi::c_str::CStr::from_ptr ()
(gdb) up
#2  0x00b641a0 in bindgen::clang::cxstring_to_string_leaky (s=...) at src/clang.rs:1476
1476	    let c_str = unsafe { CStr::from_ptr(clang_getCString(s) as *const _) };
(gdb) print s
$1 = clang_sys::CXString {data: 0x143bef0, private_flags: 1}
(gdb) printf "%s\n", s.data
clang version 9.0.1-9 
(gdb) quit
(sid_powerpc-dchroot)dkg@perotto:~/src/bindgen-test$

Weirdly, i note that i see no arguments for strlen at all in the backtrace here :/

I don't know where to get the debug symbols for
std::ffi::c_str::CStr::from_ptr either.

I haven't tried this on the latest version of bindgen because debian hasn't moved to clang_sys 0.29 yet.

I recognize that not a lot of people have access to this platform, but I'm game to try any kind of debugging that you recommend, or to help an interested person get an account on the debian porterbox so you can experiment for yourself.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the powerpc crash with the void.h input and bindgen invocation, then start at src/clang.rs:1476 in cxstring_to_string_leaky and follow extract_clang_version at line 1925. Compare the CXString and clang_getCString behavior on powerpc; done means the command no longer segfaults and the relevant regression is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.