Skip to content
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

Behaviour when importing function (with the same name) from two different shared libraries #165

Open
mert-kurttutan opened this issue Nov 28, 2024 · 4 comments

Comments

@mert-kurttutan
Copy link

mert-kurttutan commented Nov 28, 2024

What is the expected behaviour when we important a function with the same name from two different shared libraries.

In coding, this translates to:

    unsafe {
        let lib1 = libloading::Library::new("/path/to/liblibrary_one.so")?;
        let func1: libloading::Symbol<unsafe extern fn()> = lib.get(b"my_func").unwrap();

        let lib2 = libloading::Library::new("/path/to/liblibrary_two.so")?;
        let func2: libloading::Symbol<unsafe extern fn()> = lib.get(b"my_func").unwrap();

       func1();
       func2();

    }

In my debugging, when func1 is called before func2, function from library_two is called twice.

But, when func2 is called before func1, function from library_two is only called once, then function from library_one is called, so no double calling of function from 1st imported library.
Is this behaviour expected ?

I aware this is info is a limited, not enough for repro but I can elaborate later on, giving actual info about the content if shared libraries.

@nagisa
Copy link
Owner

nagisa commented Nov 28, 2024

The behaviour doesn't sound expected, but at the same time this likely doesn't have anything to do with the implementation of libloading and more so with the specifics of your dynamic libraries and/or their interaction with the interpreter/loader that is used on your system.

A minimal reproducer would help here :)

@mert-kurttutan
Copy link
Author

You are probably right. Tried have a reproducible example and it did not have the problem.

@mert-kurttutan
Copy link
Author

Is this behaviour possible when the share library (that libloading loads) also loads other shared libraries using dlopen?

@mert-kurttutan
Copy link
Author

It turns out they both had an inner functions (which is the main body) to which they make a call. This inner function has the same name on both shared libraries and exported.

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