Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Wrong ABI used for small C++ classes on Linux. #778

Open
@vadimcn

Description

@vadimcn

Input C/C++ Header

#include<cstdint>structFoo {size_t data;};structBar {size_t data;~Bar() { data =0; }};FooMakeFoo();// { return Foo(); }BarMakeBar();// { return Bar(); }

Bindgen Invocation

bindgen::Builder::default().clang_args(&["-x","c++","-std=c++11"]).header("input.h").generate().unwrap()

Actual Results

#[repr(C)]#[derive(Debug,Copy)]pubstructFoo{pubdata:usize,}implCloneforFoo{fnclone(&self) ->Self{*self}}#[repr(C)]#[derive(Debug)]pubstructBar{pubdata:usize,}extern"C"{#[link_name ="_ZN3BarD1Ev"]pubfnBar_Bar_destructor(this:*mutBar);}implBar{#[inline]pubunsafefndestruct(&mutself){Bar_Bar_destructor(self)}}extern"C"{#[link_name ="_Z7MakeFoov"]pubfnMakeFoo() ->Foo;}extern"C"{#[link_name ="_Z7MakeBarv"]pubfnMakeBar() ->Bar;}

Expected Results

Not sure...

Discussion

MakeFoo andMakeBar look very similar, however in C++ they use different ABIs, at least on Linux.
Here's a quote fromSystem V AMD64 ABI spec (page 20):

If a C++ object has either a non-trivial copy constructor or a non-trivial
destructor11, it is passed by invisible reference (the object is replaced in the
parameter list by a pointer that has class POINTER)12

This means that whileFoo get returned by-value in therax register,Bar must be returned by-pointer to a caller allocated memory. To Rust compiler, however, these look identical, so it expects both to be returned inrax.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp