Thread overview
Static executable (ldc, linux)
Oct 25, 2022
Anonymouse
Oct 25, 2022
Kagamin
Oct 25, 2022
Anonymouse
October 25, 2022

I'm having problems compiling my thing into an executable that doesn't require ldc's phobos/druntime .so's. I want to distribute it in a form where it's okay if /usr/lib/libphobos2-ldc-shared.so.100 and friends don't exist.

--static seems to do the trick in that the compiled file is no longer a dynamic executable, but then it doesn't work and just segfaults upon trying to use OpenSSL (via arsd.http2). The only other flag I specifically pass to ldc is -linkonce-templates.

Linking...
/usr/bin/ld: ../../.dub/packages/arsd-official-10.9.2/arsd-official/.dub/build/with_openssl-debug-linux.posix-x86_64-ldc_v1.30.0-328F22C7CA122C28C3639482CB724003/libarsd-official_http.a(arsd.http2.o): in function `_D4arsd5http211loadOpenSslFZv':
/home/wob/src/kameloso/../../.dub/packages/arsd-official-10.9.2/arsd-official/http2.d:3679: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(path.o): in function `_D3std4path11expandTildeFNbNfAyaZ18expandFromDatabaseFNbNfQBdZQBh':
path.d:(.text._D3std4path11expandTildeFNbNfAyaZ18expandFromDatabaseFNbNfQBdZQBh+0x147): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function `_D3std6socket25_sharedStaticCtor_L282_C1FZv':
socket.d:(.text._D3std6socket25_sharedStaticCtor_L282_C1FZv+0x14): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function `_D3std6socket12InternetHost__T7getHostVAyaa118_0a2020202020202020202020206175746f2078203d2068746f6e6c28706172616d293b0a2020202020202020202020206175746f206865203d20676574686f73746279616464722826782c20342c206361737428696e7429204164647265737346616d696c792e494e4554293b0a2020202020202020TkZQJwMFkZb':
socket.d:(.text._D3std6socket12InternetHost__T7getHostVAyaa118_0a2020202020202020202020206175746f2078203d2068746f6e6c28706172616d293b0a2020202020202020202020206175746f206865203d20676574686f73746279616464722826782c20342c206361737428696e7429204164647265737346616d696c792e494e4554293b0a2020202020202020TkZQJwMFkZb+0x37): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function `_D3std6socket12InternetHost__T7getHostVAyaa75_0a202020202020202020202020202020206175746f206865203d20676574686f737462796e616d6528706172616d2e74656d7043537472696e672829293b0a202020202020202020202020TAxaZQGpMFQjZb':
socket.d:(.text._D3std6socket12InternetHost__T7getHostVAyaa75_0a202020202020202020202020202020206175746f206865203d20676574686f737462796e616d6528706172616d2e74656d7043537472696e672829293b0a202020202020202020202020TAxaZQGpMFQjZb+0x43): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function `_D3std6socket8Protocol17getProtocolByTypeMFNbNeEQBuQBt12ProtocolTypeZb':
socket.d:(.text._D3std6socket8Protocol17getProtocolByTypeMFNbNeEQBuQBt12ProtocolTypeZb+0xa): warning: Using 'getprotobynumber' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function `_D3std6socket8Protocol17getProtocolByNameMFNbNeMAxaZb':
socket.d:(.text._D3std6socket8Protocol17getProtocolByNameMFNbNeMAxaZb+0x26): warning: Using 'getprotobyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function `_D3std6socket7Service16getServiceByNameMFNbNeMAxaMQeZb':
socket.d:(.text._D3std6socket7Service16getServiceByNameMFNbNeMAxaMQeZb+0x57): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/libphobos2-ldc.a(socket.o): in function `_D3std6socket7Service16getServiceByPortMFNbNetMAxaZb':
socket.d:(.text._D3std6socket7Service16getServiceByPortMFNbNetMAxaZb+0x30): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
Thread 10 "twitchworker" received signal SIGSEGV, Segmentation fault.
[Switching to LWP 965536]
0x00007ffff7bd7ec0 in CONF_parse_list () from /opt/dell/dcc/libcrypto.so.3
(gdb) bt
#0  0x00007ffff7bd7ec0 in CONF_parse_list () from /opt/dell/dcc/libcrypto.so.3
#1  0x00007ffff7f3f152 in SSL_CTX_set_ciphersuites () from /opt/dell/dcc/libssl.so.3
#2  0x00007ffff7f4c9df in SSL_CTX_new_ex () from /opt/dell/dcc/libssl.so.3
#3  0x0000000000826fc3 in _D4arsd5http27OpenSSL__T10opDispatchVAyaa11_53534c5f4354585f6e6577Z__TQBuTPSQCwQCu10SSL_METHODZQCtFQzZPSQDyQDw7SSL_CTX (_param_0=0x7ffff7fb4620) at ../../.du
b/packages/arsd-official-10.9.2/arsd-official/http2.d:3592
#4  0x0000000000826de1 in _D4arsd5http213OpenSslSocket7initSslMFbAyaZv (this=0x7fffd603c060, verifyPeer=true, hostname="id.twitch.tv") at ../../.dub/packages/arsd-official-10.9.2/arsd
-official/http2.d:3806
#5  0x000000000082035d in _D4arsd5http213OpenSslSocket6__ctorMFE3std6socket13AddressFamilyEQBbQBa10SocketTypeAyabZCQDjQDhQDe (this=0x7fffd603c060, af=std.socket.INET, type=std.socket.
STREAM, hostname="id.twitch.tv", verifyPeer=true) at ../../.dub/packages/arsd-official-10.9.2/arsd-official/http2.d:3961
[...]

dmd seems to do this by default (ldd doesn't list any phobos or druntime .so files and program doesn't segfault), but I'm not sure how I can get ldc to behave the same. I looked over the --help listing but I could only find --static (and --lib, which I assume doesn't apply here).

October 25, 2022
ldc2 -link-defaultlib-shared=false or something like that
October 25, 2022
On Tuesday, 25 October 2022 at 10:55:33 UTC, Kagamin wrote:
> ldc2 -link-defaultlib-shared=false or something like that

Thanks.