Skip to content

shouldn't raw::Library::open be unsafe? #48

Description

@domenpk

I think open should probably be marked unsafe, because it could call a unsafe function, although not directly.

For example, below code demonstrates a constructor function is called on library load (no unsafe code needed):

cargo new dlopen-test
cd dlopen-test/

cat > hello.c << EOF
#include <stdio.h>

void __attribute__ ((constructor)) hello(void)
{
        printf("hello from C\n");
}
EOF

gcc -Wall -shared -fPIC -o hello.so hello.c
cat > src/main.rs << EOF
extern crate dlopen;
use dlopen::raw::Library;

fn main() {
    let lib = Library::open("./hello.so").unwrap();
}
EOF

cargo add dlopen
cargo run

# some cargo outputs, ends with this print from C code
hello from C

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions