#988465 ldc: using std.stdio causes static link to fail

Package:
ldc
Source:
ldc
Description:
LLVM D Compiler
Submitter:
Witold Baryluk
Date:
2025-11-28 20:03:01 UTC
Severity:
normal
Tags:
#988465#5
Date:
2021-05-13 14:58:33 UTC
From:
To:
```
import std.stdio;
void main() {}
```

$ ldc2 -Os -static hello.d
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o):function _D3std6socket25_sharedStaticCtor_L282_C1FZv: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o):function _D3std6socket8Protocol17getProtocolByNameMFNbNeMAxaZb: warning: Using 'getprotobyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o):function _D3std6socket8Protocol17getProtocolByTypeMFNbNeEQBuQBt12ProtocolTypeZb: warning: Using 'getprotobynumber' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o):function _D3std6socket7Service16getServiceByNameMFNbNeMAxaMQeZb: warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o):function _D3std6socket7Service16getServiceByPortMFNbNetMAxaZb: warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o):function _D3std6socket12InternetHost__T7getHostVAyaa75_0a202020202020202020202020202020206175746f206865203d20676574686f737462796e616d6528706172616d2e74656d7043537472696e672829293b0a202020202020202020202020TAxaZQGpMFQjZb: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o):function _D3std6socket12InternetHost__T7getHostVAyaa118_0a2020202020202020202020206175746f2078203d2068746f6e6c28706172616d293b0a2020202020202020202020206175746f206865203d20676574686f73746279616464722826782c20342c206361737428696e7429204164647265737346616d696c792e494e4554293b0a2020202020202020TkZQJwMFkZb: warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o):function _D3std6socket12InternetHost__T13getHostNoSyncVAyaa245_0a2020202020202020202020206175746f2078203d20696e65745f6164647228706172616d2e74656d7043537472696e672829293b0a202020202020202020202020656e666f726365287820213d20494e414444525f4e4f4e452c0a202020202020202020202020202020206e657720536f636b6574506172616d65746572457863657074696f6e2822496e76616c6964204950763420616464726573732229293b0a2020202020202020202020206175746f206865203d20676574686f73746279616464722826782c20342c206361737428696e7429204164647265737346616d696c792e494e4554293b0a2020202020202020TAxaZQTzMFQjZb: warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function _D3std4zlib8Compress5errorMFiZv: error: undefined reference to 'deflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function _D3std4zlib8Compress6__dtorMFZv: error: undefined reference to 'deflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function _D3std4zlib8Compress8compressMFAxvZQe: error: undefined reference to 'deflate'
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function _D3std4zlib8Compress5flushMFiZAv: error: undefined reference to 'deflate'
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function _D3std4zlib8Compress5flushMFiZAv: error: undefined reference to 'deflate'
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function _D3std4zlib8Compress5flushMFiZAv: error: undefined reference to 'deflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function _D3std4zlib10UnCompress5errorMFiZv: error: undefined reference to 'inflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function _D3std4zlib10UnCompress6__dtorMFZv: error: undefined reference to 'inflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function _D3std4zlib10UnCompress10uncompressMFAxvZQe: error: undefined reference to 'inflate'
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function deflateInit2: error: undefined reference to 'deflateInit2_'
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function inflateInit2: error: undefined reference to 'inflateInit2_'
collect2: error: ld returned 1 exit status
Error: /usr/bin/cc failed with status: 1
$


That is very unfortunate.

Similar problem occur when using few other phobos modules:

  std.file
  std.datetime
  std.encoding
  std.signals
  std.process

most likely because they do import transitively std.strio or std.file.

Importing other modules, like std.math, std.format, and many others does not
cause the issue.

log when executed with -v in attachement.

#988465#10
Date:
2021-11-19 18:38:10 UTC
From:
To:
Still same issue in 1.28, but example now actually need to use something from stdio:

```
import std.stdio;
void main() {
  writefln("Hello");
}
```

#988465#19
Date:
2025-11-28 20:00:36 UTC
From:
To:
Still the same essentially as in 1.24:

In ldc2 1.41:


/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(curl.o): in function `std.net.curl.CurlAPI.loadAPI()':
(.text._D3std3net4curl7CurlAPI7loadAPIFZPv+0xd): 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/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(curl.o): note: the message above does not take linker garbage collection into account
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): in function `std.socket._sharedStaticCtor_L291_C1()':
(.text._D3std6socket25_sharedStaticCtor_L291_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/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): note: the message above does not take linker garbage collection into account
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): in function `std.socket.InternetHost.getHost!("\n            auto x = htonl(param);\n            auto he = gethostbyaddr(&x, 4, cast(int) AddressFamily.INET);\n        ", uint).getHost(uint)':
(.text._D3std6socket12InternetHost__T7getHostVAyaa118_0a2020202020202020202020206175746f2078203d2068746f6e6c28706172616d293b0a2020202020202020202020206175746f206865203d20676574686f73746279616464722826782c20342c206361737428696e7429204164647265737346616d696c792e494e4554293b0a2020202020202020TkZQJwMFkZb[_D3std6socket12InternetHost__T7getHostVAyaa118_0a2020202020202020202020206175746f2078203d2068746f6e6c28706172616d293b0a2020202020202020202020206175746f206865203d20676574686f73746279616464722826782c20342c206361737428696e7429204164647265737346616d696c792e494e4554293b0a2020202020202020TkZQJwMFkZb]+0x3a): 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/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): note: the message above does not take linker garbage collection into account
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): in function `std.socket.InternetHost.getHost!("\n                auto he = gethostbyname(param.tempCString());\n            ", const(char)[]).getHost(const(char)[])':
(.text._D3std6socket12InternetHost__T7getHostVAyaa75_0a202020202020202020202020202020206175746f206865203d20676574686f737462796e616d6528706172616d2e74656d7043537472696e672829293b0a202020202020202020202020TAxaZQGpMFQjZb[_D3std6socket12InternetHost__T7getHostVAyaa75_0a202020202020202020202020202020206175746f206865203d20676574686f737462796e616d6528706172616d2e74656d7043537472696e672829293b0a202020202020202020202020TAxaZQGpMFQjZb]+0x40): 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/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): note: the message above does not take linker garbage collection into account
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): in function `std.socket.Protocol.getProtocolByType(std.socket.ProtocolType)':
(.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/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): note: the message above does not take linker garbage collection into account
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): in function `std.socket.Protocol.getProtocolByName(scope const(char)[])':
(.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/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): note: the message above does not take linker garbage collection into account
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(path.o): in function `_D3std4path11expandTildeFNbNfNkMxAyaZ18expandFromDatabaseFNbNfAyaZQe':
(.text._D3std4path11expandTildeFNbNfNkMxAyaZ18expandFromDatabaseFNbNfAyaZQe+0x139): 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/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(path.o): note: the message above does not take linker garbage collection into account
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): in function `std.socket.Service.getServiceByName(scope const(char)[], scope const(char)[])':
(.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/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): note: the message above does not take linker garbage collection into account
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): in function `std.socket.Service.getServiceByPort(ushort, scope const(char)[])':
(.text._D3std6socket7Service16getServiceByPortMFNbNetMAxaZb+0x33): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/15/../../../x86_64-linux-gnu/libphobos2-ldc.a(socket.o): note: the message above does not take linker garbage collection into account