static-haskell-nix
static-haskell-nix copied to clipboard
Document example failure of glibc static linking with NSS somewhere
I got this example segfault of somebody trying to use an executable statically linked with glibc and using the network.
The stacktrace is of the program crashing in gdb
; stack build ... --no-strip
was used to obtain a sensible stack trace, otherwise it would show just in ?? ()
in the entire trace.
Thread 11 "myprogram:w" received signal SIGSEGV, Segmentation fault.
[Switching to LWP 494]
0x00007ffff43857a0 in internal_getent (stream=stream@entry=0x7ffff4059680, result=result@entry=0x368b1a0 <resbuf.11135>, buffer=buffer@entry=0x36e7a20 "# Internet (IP) protocols\n", buflen=buflen@entry=1024, errnop=errnop@entry=0x7fffe67fc6a0)
at nss_files/files-XXX.c:216
216 nss_files/files-XXX.c: No such file or directory.
(gdb) bt
#0 0x00007ffff43857a0 in internal_getent (stream=stream@entry=0x7ffff4059680, result=result@entry=0x368b1a0 <resbuf.11135>, buffer=buffer@entry=0x36e7a20 "# Internet (IP) protocols\n", buflen=buflen@entry=1024, errnop=errnop@entry=0x7fffe67fc6a0)
at nss_files/files-XXX.c:216
#1 0x00007ffff4385a32 in _nss_files_getprotobyname_r (name=0x420021c800 "tcp", result=0x368b1a0 <resbuf.11135>, buffer=0x36e7a20 "# Internet (IP) protocols\n", buflen=1024, errnop=0x7fffe67fc6a0) at nss_files/files-proto.c:38
#2 0x0000000003026f47 in getprotobyname_r ()
#3 0x0000000003026d18 in getprotobyname ()
#4 0x0000000002208aee in ?? ()
#5 0x0000000000000000 in ?? ()
Should probably document that somewhere as an example for why you may want to use musl here.
The glibc warning:
Hello.hs
:
main = putStrLn "hello world"
% ghc --make Hello.hs -optl-static
[1 of 1] Compiling Main ( Hello.hs, Hello.o )
Linking Hello ...
rts/Linker.c:601:0: error:
warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
|
601 | hdl = dlopen(dll_name, RTLD_LAZY|RTLD_LOCAL); /* see Note [RTLD_LOCAL] */
| ^
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libnuma.a(affinity.o):function affinity_ip: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
See https://stackoverflow.com/questions/57476533/why-is-statically-linking-glibc-discouraged/57478728#57478728
Two options:
- Use
musl
, but then lose out on Name Service Switch - Keep using
glibc
, but then only statically link everything other than libc.
Another example of static glibc breakage: https://old.reddit.com/r/haskell/comments/vqqq7x/trying_to_build_a_statically_linked_binary/