Using asm labels in function declaration produces unexpected bindings

Open
#3,534 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

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

Research direction

Start by reading bindgen's handling of C function declarations and asm labels, then reproduce the provided syslog example with the stated bindgen version and compare the generated declarations. The issue does not name a source file or test; trace the parsing and code generation paths involved and add a regression test for the example. Done means the renamed function produces one binding instead of two.

Written by the indexing model from the issue text.

Description

gcc (and clang which I guess inherited the extension) allows a function to be declared with one name, but redirect calls to a function of a different name [1]. glibc makes heavy use of the feature to support multiple versions of long double on multiple targets. Some powerpc64le distros have switched the long double format, which turns on these awkward redirections.

A simplified and preprocessed example of syslog from syslog.h on powerpc64le on fedora 44 looks like:

extern void syslog (int __pri, const char *__fmt, ...);
extern __typeof (syslog) syslog __asm ("__syslogieee128");

Which produces the following from bindgen:

/* automatically generated by rust-bindgen 0.72.1 */

unsafe extern "C" {
    pub fn syslog(__pri: ::std::os::raw::c_int, __fmt: *const ::std::os::raw::c_char, ...);
}
unsafe extern "C" {
    #[link_name = "\u{1}__syslogieee128"]
    pub fn syslog1(arg1: ::std::os::raw::c_int, arg2: *const ::std::os::raw::c_char, ...);
}

Ideally, there should be one binding to the renamed function. In this case, it's harmless as long as Rust does not support long double.

[1] https://gcc.gnu.org/onlinedocs/gcc/Asm-Labels.html

Dominant language
Rust
Stars
5.3k
Forks
846
Avg merge
2d 6h
Merged PRs (30d)
11

Getting set up

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.

More from rust-lang/rust-bindgen

All issues in rust-lang/rust-bindgen

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.