Skip to content

thread_local!s with destructors segfault in non-PIE executables #24445

Closed
@huonw

Description

@huonw
void foo();
int main()
{
    foo();
    return 0;
}
#![crate_type = "staticlib"]

struct Destroy;
impl Drop for Destroy { fn drop(&mut self) {} }

thread_local! {
    static X: Destroy = Destroy
}

#[no_mangle]
pub extern "C" fn foo() {
    X.with(|_| ());
}
rustc staticlib2.rs
gcc staticlib2.c libstaticlib2.a -ldl -lpthread -lrt -lgcc_s -lpthread -lc -lm -o staticlib2
gcc staticlib2.c -pie libstaticlib2.a -ldl -lpthread -lrt -lgcc_s -lpthread -lc -lm -o staticlib2-pie

staticlib2 segfaults, staticlib2-pie doesn't.

This is possibly/probably the expected behaviour, but it would be quite nice to not cause a segfault or at least find some way to help the user get it right. (cc http://stackoverflow.com/q/29632715/1256624)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions