Hey folks, sorry if this is the wrong place to post this, but I can't really distinguish whether this problem is related to cxx, rustc, rust-lld, or gcc, static linking or something else entirely.
I'm working on a project where I'm writing a plugin for a C++ program in Rust. The program contains some header files which defines a special inline function (call it register), which is automatically called from a class constructor for a global instance instantiated in the plugin source code. For a usual C++ project, when one compiles their shared library, this function is generated (the definition is in the header file), but is marked a "relocation" and the symbol exists in the .got.plt table for the shared library, as can be seen through readelf -r. This symbol is then replaced with the actual one in the "host" program after the library is loaded.
Now, the program I'm writing is a Rust cdylib alongside a C++ shim that pretends to be a plugin as above, which essentially calls the functions I wrote in Rust, with a build.rs script that compiles the C++ through cxxbridge and builds the final shared library. The build in build.rs is more or less as follows:
let mut build = cxx_build::bridge("src/lib.rs");
let build = build
.files(cpp_source_files)
.link_lib_modifier("+whole-archive");
build.compile("plugin-bridge");
The problem is that none of the symbols in this plugin-bridge are exported unless built with +whole-archive, and more relevant for this post, the aforementioned inline function in the header file is generated and placed in .text, and does not show up in .got.plt as is the case with C++ above.
I understand that the root cause for this probably is cc, which only builds static libraries, though I have no idea how I can go about fixing this. It is technically possible to compile the C++ shim separately as a shared library (which I haven't tried yet) and link with the Rust program, but I'd like to obtain a single shared library which also mentions register@plt if possible. I've already tried a few things, notably passing -fPIC to cc::Build and passing relro-level = "off" to .cargo/config.toml to no avail.
Is this even possible to do through Cargo? Any input would be appreciated.