rust_libloading
rust_libloading copied to clipboard
Behaviour when importing function (with the same name) from two different shared libraries
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.
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 :)
You are probably right. Tried have a reproducible example and it did not have the problem.
Is this behaviour possible when the share library (that libloading loads) also loads other shared libraries using dlopen?
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.
Yeah, this is unfortunately a platform behaviour that you will need to figure out how to work-around yourself.