Dear forum,
I am using ldc,
version 1.28.0-git-5a28329 (DMD v2.098.0, LLVM 10.0.0)
on two different systems:
- Almalinux 8.5
- Fedora 35
ldc itself was compiled on the Almalinux system and then copied over to the Fedora 35 system
I confirmed it is the same ldc executable on both systems by running
md5sum `which ldc2`
I have a simple test case where it seems on the Almalinux system, shared static this() code does not get invoked.
Output on Almalinux:
dsostub : crt_constructor
Output on Fedora:
dsostub : crt_constructor
md_static_import : shared static this
main : shared static this
The code is built using meson, and using meson compile --verbose I can see that the compilation steps are the same, and the linking step looks like this and is identical on both systems:
/usr/bin/cc mwe.p/dsostub.d.o mwe.p/md_static_import.d.o mwe.p/main.d.o -o mwe -Xlinker --allow-shlib-undefined -L/opt/ldc2-1.28.0/lib -lphobos2-ldc-shared -ldruntime-ldc-shared -Wl,-rpath,/opt/ldc2-1.28.0/lib -Wl,--gc-sections -lrt -ldl -lpthread -lm -m64
If I copy over the build directory from the almalinux system to the fedora system and re-execute the link command as above, the resulting executable does work.
- /usr/bin/cc --version on almalinux : cc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)
- /usr/bin/cc --version on fedora : cc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
So it seems there is a difference in how gcc 8.5.0 and gcc 11.2.1 handle something in the linking process, but I assume it requires knowledge of ldc to know what that might be, which is why I am posting here.
The code can be gotten from here: github. It was originally also using using static and dynamic libraries which is why I have the dsostub code that uses pragma(crt_constructor) which is not actually relevant here.
I am hoping there might be a linker option that I can pass to the older gcc that would resolve the issue?