Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document example failure of glibc static linking with NSS somewhere #17

Open
nh2 opened this issue May 7, 2019 · 3 comments
Open

Document example failure of glibc static linking with NSS somewhere #17

nh2 opened this issue May 7, 2019 · 3 comments

Comments

@nh2
Copy link
Owner

nh2 commented May 7, 2019

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.

@nh2
Copy link
Owner Author

nh2 commented Nov 9, 2019

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

@cstrahan
Copy link

cstrahan commented Mar 10, 2020

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.

@nh2
Copy link
Owner Author

nh2 commented Jul 5, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants