Skip to content
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

Pure virtual functions generate bogus link_name. #1197

Closed
jpathy opened this issue Dec 25, 2017 · 4 comments
Closed

Pure virtual functions generate bogus link_name. #1197

jpathy opened this issue Dec 25, 2017 · 4 comments
Assignees

Comments

@jpathy
Copy link

jpathy commented Dec 25, 2017

Hello,
I am using bindgen to generate code from C++ headers and if i disable name mangling the resulting link_name for functions just become function_name, but the library symbols are of form someprefix_classname_function_name. I am assuming it's a bit of namespace issue. Is there any way to achieve this?

@emilio
Copy link
Contributor

emilio commented Dec 25, 2017

Can you put an example? In general disabling name mangling is only supported to workaround old clang bugs in C, like #528.

@jpathy
Copy link
Author

jpathy commented Dec 26, 2017

I am using steamworks sdk. Here is some snippet of a header file.

class ISteamUser
{
public:
	virtual HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) = 0;
}

Here is the relevant generated rust code. It fails to link with test program.

#[repr(C)]
pub struct ISteamUser__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ISteamUser {
    pub vtable_: *const ISteamUser__bindgen_vtable,
}
extern "C" {
    #[link_name = "\u{1}GetAuthSessionTicket"]
    pub fn ISteamUser_GetAuthSessionTicket(
        this: *mut ::std::os::raw::c_void,
        pTicket: *mut ::std::os::raw::c_void,
        cbMaxTicket: ::std::os::raw::c_int,
        pcbTicket: *mut root::uint32,
    ) -> root::HAuthTicket;
}

If i inspect the supplied library with the sdk.

$ nm ~/Downloads/sdk/redistributable_bin/linux64/libsteam_api.so |grep GetAuthSession
0000000000021f70 T SteamAPI_ISteamGameServer_GetAuthSessionTicket
000000000001f810 T SteamAPI_ISteamUser_GetAuthSessionTicket

I had to patch the generated code prefixing link_name with SteamAPI_$CLASS.

@emilio
Copy link
Contributor

emilio commented Dec 29, 2017

Oh ok, so the problem here is two. First of all we generate a link name for a pure virtual method, which is wrong. Then there's the long-standing problem that we don't support generating vtables properly, because of C++ compiler differences.

Let's fix the first one since at least that will fix the linking error.

@emilio emilio changed the title link_name prefix Pure virtual functions generate bogus link_name. Dec 29, 2017
emilio added a commit to emilio/rust-bindgen that referenced this issue Dec 29, 2017
@emilio emilio self-assigned this Dec 29, 2017
@emilio
Copy link
Contributor

emilio commented Dec 29, 2017

#1199

bors-servo pushed a commit that referenced this issue Dec 29, 2017
Don't generate symbols for pure virtual functions.

Fixes #1197.
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