-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
$ cat Cargo.toml
[package]
name = "foo"
version = "0.1.0"
authors = ["Mike Hommey <[email protected]>"]
[lib]
crate-type = ["cdylib"]
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
$ cat src/lib.rs
#![no_std]
use core::alloc::Layout;
use core::ffi::c_void;
use core::ptr;
const CHUNK_SIZE: usize = 1 << 20;
#[panic_handler]
#[no_mangle]
pub fn panic_impl(_: &core::panic::PanicInfo) -> ! {
loop {}
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct ChunkLayout(Layout);
#[derive(Debug)]
pub(crate) struct ChunkLayoutErr;
impl ChunkLayout {
fn from_size_align(size: usize, align: usize) -> Result<Self, ChunkLayoutErr> {
if align < CHUNK_SIZE || (size & (CHUNK_SIZE - 1) != 0) {
return Err(ChunkLayoutErr);
}
Layout::from_size_align(size, align).map(ChunkLayout).map_err(|_| ChunkLayoutErr)
}
}
#[no_mangle]
pub unsafe extern "C" fn chunk_alloc_mmap(size: usize, align: usize) -> *mut c_void {
if let Ok(_layout) = ChunkLayout::from_size_align(size, align) {
ptr::null_mut()
} else {
ptr::null_mut()
}
}
$ cargo build
Compiling foo v0.1.0 (/tmp/foo)
Finished dev [unoptimized + debuginfo] target(s) in 0.24s
$ objdump -T target/debug/libfoo.so | grep rust_eh_personality
0000000000000000 D *UND* 0000000000000000 rust_eh_personality
Practically speaking, this means the resulting library (cdylib) can't be loaded because the symbol can't be resolved.
This doesn't happen with --release
(there is no undefined reference to rust_eh_personality
). And this doesn't happen when the body of chunk_alloc_mmap
is further reduced to only ptr::null_mut()
.
If I add -Wl,-Map,map to the linker arguments, the output map
file says the symbol reference comes from:
.data.DW.ref.rust_eh_personality
0x0000000000004008 0x8 /tmp/foo/target/debug/deps/foo.3sp59mzlmyqssn40.rcgu.o
0x0000000000004008 DW.ref.rust_eh_personality
So rust actively creates a pointer to rust_eh_personality
in .data
. DW suggests this would have something to do with DWARF, so I tried enabling debug info on the release profile, but that still didn't make it happen with --release
.
Cc: @japaric, @alexcrichton
jplatte
Metadata
Metadata
Assignees
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.