Hi everyone,
I’m observing a strange behaviour when I try to call a function located in a shared library compiled with g++ from another program compiled with nvc++. The parameters passed to a called function seem to get corrupted during the function call.
Here you can find a minimal example showing off this behaviour. The example code uses g++-9 to compile a shared library and nvc++ to compile the main.
test.zip (2.4 KB)
compile commands
mkdir build
cd build
cmake ..
make -j
./src/main
The expected output is ###### pid 42 kid 0
but I actually get ###### pid <some_random_number> kid 42
with changing results on every run.
Here is a short explanation of what the code does:
The class myclass is compiled with g++ to create a shared library providing the static method myclass::foo.
myclass.hpp
[...]
class myclass {
public:
struct {
uint64_t a : 24;
uint64_t b : 32;
uint64_t c : 8;
} fields;
static myclass foo(uint8_t pid, uint32_t key_id);
};
myclass.cpp
[...]
myclass myclass::foo(uint8_t pid, uint32_t key_id)
{
std::cout << "###### pid " << int(pid) << " kid " << int(key_id) << std::endl;
myclass result;
return result;
}
The main function is compiled with nvc++ and calls foo.
main.cpp
int main(int argc, char* argv[]) {
auto var = 42;
auto tmp = myclass::foo(var, 0);
return 0;
}
As far as I can tell, the problem occurs only if the static function is not void and is located behind a bitfield with specific bit widths. When I compile both, the library and the main, with the same compiler (no matter if g++ or nvc++) everything works as expected. Unfortunately for the project in which I ran into those problems, we are not able change the library toolchain to nvc++ due to other requirements.
Is anyone able to reproduce this behaviour with the given example project?
Are there known bugs that could be related to this?
Or am I just missing some obvious undefined behaviour causing stuff here?
Thank you and best regards
Josh
Edit:
nvc++ version : 23.1-0
g++ version : 9.4.0