I'm currently trying to link a Rust executable with a shared library written in C++ and C. The dynamic loading of the shared library works perfectly on amd64 architectures but I am running into segmentation fault errors when the executable tries to load the shared library on an aarch64 linux machine [Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-1033-raspi2 aarch64)].
I am using the Linaro aarch64 toolchain (http://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz) to cross-compile the shared library (combination of C++ and C code).
On inspection using file/readelf, the resultant shared library has the GNU/Linux ABI which seems to be because of the use of g++ to build the C++ code in the library whereas the ABI of the Rust executable is SYSV (cross compiled for aarch64 using the https://github.com/rust-embedded/cross project)
I’ve noticed that manually editing the .so file of the shared library to change the ABI flag from GNU/Linux to SYSV resolves the problem.
Is it possible to make either the executable or the library target a specific ABI? Ideally, I would like to build the Rust executable in a way so that it can link to the shared library irrespective of the library's ABI.
To provide a brief overview, the shared library is an implementation of the this header file: https://github.com/Azure/iotedge/blob/master/edgelet/hsm-sys/azure-iot-hsm-c/inc/hsm_client_data.h I've kept a lot of the C implementation code from the linked repository but have modified the implementation of some of the headers to use C++ instead.
Please let me know if any additional details are required.
I've tried switching back to older versions of g++ (4.9) to build the C and C++ shared library but it always yields an artifact that has an ABI of GNU/Linux.
This question was identified as a duplicate of this one Can I call C or C++ functions from Rust code? but the answers to those questions haven't helped solve my problem as the suggestions/answers on that post state that C++ can be called by passing through a C 'interface' which is exactly what I have. The problem is more of an ABI incompatibility issue for a specific target architecture i.e., aarch64. The problem doesn't reproduce on an amd64 target architecture.
Expected - The Rust executable and the dynamic shared library built using both C and C++ to have compatible ABIs for aarch64.
Actual - Rust executable is targeting the SYSV ABI whereas the dynamic shared library is targeting the GNU/Linux ABI.