Skip to content

Failure to define static const strucs. Left with only declarations. #2322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ephraimfeldblum opened this issue Oct 23, 2022 · 3 comments
Closed

Comments

@ephraimfeldblum
Copy link

ephraimfeldblum commented Oct 23, 2022

I'm trying to use a c header in my rust module, using bindgen to translate it, but bindgen seems to not parse it as well as it could have. It seems to be merely declaring the struct without defining it.

Input C/C++ Header

typedef struct MyLib_Foo {
    uint64_t x;
    uint64_t y;
} MyLib_Foo;

static const MyLib_Foo MyLib_Bar = { 0, 1 }, MyLib_Baz = {...}, ...;

Bindgen Invocation

bindgen::Builder::default()
    .header("mylib.h")
    .allowlist_var("(MYLIB|MyLib).*")
    .allowlist_type("MyLib.*")
    .generate()
    .unwrap()

Actual Results

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct MyLib_Foo {
    pub x: u64,
    pub y: u64,
}

extern "C" {
    pub static MyLib_Bar: MyLib_Foo;
}
...
$ nm -A -C path/to/library.so | grep MyLib_Bar
path/to/library.so:                 U MyLib_Bar

Expected Results

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct MyLib_Foo {
    pub x: u64,
    pub y: u64,
}

const MyLib_Bar: MyLib_Foo = MyLIb_Foo{x: 0, y: 1};
...
$ nm -A -C path/to/library.so | grep MyLib_Bar
path/to/library.so:xxxxxxxxxxxxxxxx r MyLib_Bar
@ephraimfeldblum ephraimfeldblum changed the title Failure to define static consts. Left with only declarations. Failure to define static const strucs. Left with only declarations. Oct 23, 2022
@ephraimfeldblum
Copy link
Author

These seem like they may be relevant. Has nothing been done about this issue since 2018?
#1266
#1524

@pvdrz
Copy link
Contributor

pvdrz commented Oct 24, 2022

I believe that this might still be a upstream issue, see this comment. I'll check if this is still the case or not.

@pvdrz
Copy link
Contributor

pvdrz commented Jan 10, 2023

I'm closing this as it is a duplicate of #1266

PD: There has not been any movement from the LLVM side either https://bugs.llvm.org/show_bug.cgi?id=36576

@pvdrz pvdrz closed this as completed Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants