Skip to content

Exported cxxbuild symbols in cdylib #1500

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

Open
waldemarKunkel opened this issue Apr 8, 2025 · 1 comment
Open

Exported cxxbuild symbols in cdylib #1500

waldemarKunkel opened this issue Apr 8, 2025 · 1 comment

Comments

@waldemarKunkel
Copy link

I've build a cdylib with cargo with the following cxx bridge:

#[cxx::bridge]
mod ffi {
    unsafe extern "C++" {
        include!("helper.h");
        fn SendKey(key: c_char) -> u32;
    }
}

Now if I check the exported symbols with

nm -gD --defined-only libmylib.so

the output is:

0012abb5 T cxxbridge1$exception
0012aeed T cxxbridge1$rust_vec$bool$capacity
0012aef1 T cxxbridge1$rust_vec$bool$data
0012aed9 T cxxbridge1$rust_vec$bool$drop
0012aee9 T cxxbridge1$rust_vec$bool$len
0012aecd T cxxbridge1$rust_vec$bool$new
0012aef5 T cxxbridge1$rust_vec$bool$reserve_total
0012af1d T cxxbridge1$rust_vec$bool$set_len
0012af21 T cxxbridge1$rust_vec$bool$truncate
0012aeed T cxxbridge1$rust_vec$char$capacity
0012aef1 T cxxbridge1$rust_vec$char$data
0012aed9 T cxxbridge1$rust_vec$char$drop
0012aee9 T cxxbridge1$rust_vec$char$len
0012aecd T cxxbridge1$rust_vec$char$new
0012aef5 T cxxbridge1$rust_vec$char$reserve_total
0012af1d T cxxbridge1$rust_vec$char$set_len
0012af21 T cxxbridge1$rust_vec$char$truncate
0012aeed T cxxbridge1$rust_vec$f32$capacity
0012aef1 T cxxbridge1$rust_vec$f32$data
0012af81 T cxxbridge1$rust_vec$f32$drop
0012af93 T cxxbridge1$rust_vec$f32$len
0012af75 T cxxbridge1$rust_vec$f32$new
0012af97 T cxxbridge1$rust_vec$f32$reserve_total
0012af1d T cxxbridge1$rust_vec$f32$set_len
0012af21 T cxxbridge1$rust_vec$f32$truncate
0012aeed T cxxbridge1$rust_vec$f64$capacity
0012aef1 T cxxbridge1$rust_vec$f64$data
0012afcb T cxxbridge1$rust_vec$f64$drop
0012afdd T cxxbridge1$rust_vec$f64$len
0012afbf T cxxbridge1$rust_vec$f64$new
0012afe1 T cxxbridge1$rust_vec$f64$reserve_total
0012af1d T cxxbridge1$rust_vec$f64$set_len
0012af21 T cxxbridge1$rust_vec$f64$truncate
0012aeed T cxxbridge1$rust_vec$i16$capacity
0012aef1 T cxxbridge1$rust_vec$i16$data
0012af37 T cxxbridge1$rust_vec$i16$drop
0012af49 T cxxbridge1$rust_vec$i16$len
0012af2b T cxxbridge1$rust_vec$i16$new
0012af4d T cxxbridge1$rust_vec$i16$reserve_total
0012af1d T cxxbridge1$rust_vec$i16$set_len
0012af21 T cxxbridge1$rust_vec$i16$truncate
0012aeed T cxxbridge1$rust_vec$i32$capacity
0012aef1 T cxxbridge1$rust_vec$i32$data
0012af81 T cxxbridge1$rust_vec$i32$drop
0012af93 T cxxbridge1$rust_vec$i32$len
0012af75 T cxxbridge1$rust_vec$i32$new
0012af97 T cxxbridge1$rust_vec$i32$reserve_total
0012af1d T cxxbridge1$rust_vec$i32$set_len
0012af21 T cxxbridge1$rust_vec$i32$truncate
0012aeed T cxxbridge1$rust_vec$i64$capacity
0012aef1 T cxxbridge1$rust_vec$i64$data
0012afcb T cxxbridge1$rust_vec$i64$drop
0012afdd T cxxbridge1$rust_vec$i64$len
0012afbf T cxxbridge1$rust_vec$i64$new
0012afe1 T cxxbridge1$rust_vec$i64$reserve_total
0012af1d T cxxbridge1$rust_vec$i64$set_len
0012af21 T cxxbridge1$rust_vec$i64$truncate
0012aeed T cxxbridge1$rust_vec$i8$capacity
0012aef1 T cxxbridge1$rust_vec$i8$data
0012aed9 T cxxbridge1$rust_vec$i8$drop
0012aee9 T cxxbridge1$rust_vec$i8$len
0012aecd T cxxbridge1$rust_vec$i8$new
0012aef5 T cxxbridge1$rust_vec$i8$reserve_total
0012af1d T cxxbridge1$rust_vec$i8$set_len
0012af21 T cxxbridge1$rust_vec$i8$truncate
0012aeed T cxxbridge1$rust_vec$isize$capacity
0012aef1 T cxxbridge1$rust_vec$isize$data
0012af81 T cxxbridge1$rust_vec$isize$drop
0012af93 T cxxbridge1$rust_vec$isize$len
0012af75 T cxxbridge1$rust_vec$isize$new
0012af97 T cxxbridge1$rust_vec$isize$reserve_total
0012af1d T cxxbridge1$rust_vec$isize$set_len
0012af21 T cxxbridge1$rust_vec$isize$truncate
0012aeed T cxxbridge1$rust_vec$str$capacity
0012aef1 T cxxbridge1$rust_vec$str$data
0012b0a9 T cxxbridge1$rust_vec$str$drop
0012afdd T cxxbridge1$rust_vec$str$len
0012af75 T cxxbridge1$rust_vec$str$new
0012b0bb T cxxbridge1$rust_vec$str$reserve_total
0012af1d T cxxbridge1$rust_vec$str$set_len
0012af21 T cxxbridge1$rust_vec$str$truncate
0012aeed T cxxbridge1$rust_vec$string$capacity
0012aef1 T cxxbridge1$rust_vec$string$data
0012b009 T cxxbridge1$rust_vec$string$drop
0012b043 T cxxbridge1$rust_vec$string$len
0012af75 T cxxbridge1$rust_vec$string$new
0012b047 T cxxbridge1$rust_vec$string$reserve_total
0012af1d T cxxbridge1$rust_vec$string$set_len
0012b071 T cxxbridge1$rust_vec$string$truncate
0012aeed T cxxbridge1$rust_vec$u16$capacity
0012aef1 T cxxbridge1$rust_vec$u16$data
0012af37 T cxxbridge1$rust_vec$u16$drop
0012af49 T cxxbridge1$rust_vec$u16$len
0012af2b T cxxbridge1$rust_vec$u16$new
0012af4d T cxxbridge1$rust_vec$u16$reserve_total
0012af1d T cxxbridge1$rust_vec$u16$set_len
0012af21 T cxxbridge1$rust_vec$u16$truncate
0012aeed T cxxbridge1$rust_vec$u32$capacity
0012aef1 T cxxbridge1$rust_vec$u32$data
0012af81 T cxxbridge1$rust_vec$u32$drop
0012af93 T cxxbridge1$rust_vec$u32$len
0012af75 T cxxbridge1$rust_vec$u32$new
0012af97 T cxxbridge1$rust_vec$u32$reserve_total
0012af1d T cxxbridge1$rust_vec$u32$set_len
0012af21 T cxxbridge1$rust_vec$u32$truncate
0012aeed T cxxbridge1$rust_vec$u64$capacity
0012aef1 T cxxbridge1$rust_vec$u64$data
0012afcb T cxxbridge1$rust_vec$u64$drop
0012afdd T cxxbridge1$rust_vec$u64$len
0012afbf T cxxbridge1$rust_vec$u64$new
0012afe1 T cxxbridge1$rust_vec$u64$reserve_total
0012af1d T cxxbridge1$rust_vec$u64$set_len
0012af21 T cxxbridge1$rust_vec$u64$truncate
0012aeed T cxxbridge1$rust_vec$u8$capacity
0012aef1 T cxxbridge1$rust_vec$u8$data
0012aed9 T cxxbridge1$rust_vec$u8$drop
0012aee9 T cxxbridge1$rust_vec$u8$len
0012aecd T cxxbridge1$rust_vec$u8$new
0012aef5 T cxxbridge1$rust_vec$u8$reserve_total
0012af1d T cxxbridge1$rust_vec$u8$set_len
0012af21 T cxxbridge1$rust_vec$u8$truncate
0012aeed T cxxbridge1$rust_vec$usize$capacity
0012aef1 T cxxbridge1$rust_vec$usize$data
0012af81 T cxxbridge1$rust_vec$usize$drop
0012af93 T cxxbridge1$rust_vec$usize$len
0012af75 T cxxbridge1$rust_vec$usize$new
0012af97 T cxxbridge1$rust_vec$usize$reserve_total
0012af1d T cxxbridge1$rust_vec$usize$set_len
0012af21 T cxxbridge1$rust_vec$usize$truncate
0012ac8f T cxxbridge1$slice$len
0012ac85 T cxxbridge1$slice$new
0012ac8b T cxxbridge1$slice$ptr
0012aca7 T cxxbridge1$str$from
0012acd1 T cxxbridge1$str$len
0012ac93 T cxxbridge1$str$new
0012accd T cxxbridge1$str$ptr
0012ac9d T cxxbridge1$str$ref
0012ae7f T cxxbridge1$string$capacity
0012ace1 T cxxbridge1$string$clone
0012aba3 T cxxbridge1$string$drop
0012adf5 T cxxbridge1$string$from_utf16
0012ae1f T cxxbridge1$string$from_utf16_lossy
0012acfd T cxxbridge1$string$from_utf8
0012ad71 T cxxbridge1$string$from_utf8_lossy
0012ae7b T cxxbridge1$string$len
0012acd5 T cxxbridge1$string$new
0012ae77 T cxxbridge1$string$ptr
0012ae83 T cxxbridge1$string$reserve_additional
0012aea5 T cxxbridge1$string$reserve_total
000961a9 T explicit_init
0008059d T function1
00095ea9 T function2

How could I achieve that the cxxbridge symbols are not exported but only these three at the bottom:

000961a9 T explicit_init
0008059d T function1
00095ea9 T function2

@dtolnay
Copy link
Owner

dtolnay commented May 18, 2025

Rustc always treats all #[no_mangle] symbols as exported. See rust-lang/rust#73958.

You can intercept rustc's linker invocation and replace it with your own version script by following the approach in #1520.

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