This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Statically linked binary & NSS
- To: egcs at cygnus dot com, bug-glibc at gnu dot org
- Subject: Statically linked binary & NSS
- From: Lionel Cons <Lionel dot Cons at cern dot ch>
- Date: Wed, 2 Dec 1998 10:30:33 +0100 (MET)
- CC: Philippe Defert <philippe dot defert at cern dot ch>
I would like to create a statically linked binary but it seems that
the -static flag is not enough. The problem seems to come from glibc
dynamically loading some libnss_* libraries, depending on the contents
of /etc/nsswitch.conf.
Here is my test program:
#include <stdio.h>
#include <pwd.h>
main()
{
struct passwd *p;
p = getpwnam("root");
if (p == NULL) {
printf("no root!\n");
} else {
printf("root is %d\n", p->pw_uid);
}
}
# gcc -v
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
# gcc -static -o test test.c
# ./test
root is 0
# ldd ./test
not a dynamic executable
So far so good but this still loads dynamic libraries:
# strace ./test
...
open("/etc/nsswitch.conf", O_RDONLY) = 3
...
open("/lib/libnss_files.so.1", O_RDONLY) = 3
And this fails in a chroot jail:
# mkdir -p /tmp/jail/etc
# cp /etc/passwd /tmp/jail/etc
# cp /etc/nsswitch.conf /tmp/jail/etc
# cp test /tmp/jail
# chroot /tmp/jail /test
no root!
# strace chroot /tmp/jail /test
...
open("/etc/nsswitch.conf", O_RDONLY) = 3
...
open("/lib/libnss_files.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
...
So, how can I create a really static binary? Are there some other
libraries dynamically loading files like this?
If this matters, I'm using Red Hat 5.1, glibc 2.0.7 and egcs 1.1.
Thanks in advance for any help...
________________________________________________________
Lionel Cons http://wwwinfo.cern.ch/~cons
CERN http://www.cern.ch
Boren's Laws:
When in charge, ponder.
When in trouble, delegate.
When in doubt, mumble.