This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [patch] Fix linking ldconfig when --enable-static-nss (with ChangeLog)
On Sat, Feb 25, 2012 at 10:21 AM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> Could you give the URL to what you are pinging?
http://cygwin.com/ml/libc-alpha/2010-01/msg00026.html
> Or, better yet, a self-contained submission with a patch against current git master and an
> explanation of what the failure is, the approach the patch takes to fix it
> and why that approach is the right one.
The failure is: when configured with --enable-static-nss, link of
ldconfig fails like so:
gcc -nostdlib -nostartfiles -static -o /build-static-nss/elf/ldconfig
/build-static-nss/csu/crt1.o /build-static-nss/csu/crti.o `gcc
--print-file-name=crtbegin.o` /build-static-nss/elf/ldconfig.o
/build-static-nss/elf/cache.o /build-static-nss/elf/readlib.o
/build-static-nss/elf/xmalloc.o /build-static-nss/elf/xstrdup.o
/build-static-nss/elf/chroot_canon.o -Wl,--start-group
/build-static-nss/libc.a -lgcc -lgcc_eh -Wl,--end-group `gcc
--print-file-name=crtend.o` /build-static-nss/csu/crtn.o
/build-static-nss/libc.a(nsswitch.o):(.data+0x8): undefined reference
to `_nss_files_getaliasent_r'
/build-static-nss/libc.a(nsswitch.o):(.data+0x18): undefined reference
to `_nss_files_endaliasent'
...
/build-static-nss/libc.a(nsswitch.o):(.data+0x148): undefined
reference to `_nss_dns_gethostbyaddr_r'
/build-static-nss/libc.a(nsswitch.o):(.data+0x158): undefined
reference to `_nss_dns_gethostbyname_r'
...
/build-static-nss/libc.a(nsswitch.o):(.data+0x388): undefined
reference to `_nss_files_getspnam_r'
The patch fixes the problem by conditionally adding the libraries
required to link ldconfig.
The patch is much simpler than the one attached to
http://sourceware.org/bugzilla/show_bug.cgi?id=6528, but requires that
a statically-linked binary explicitly list "-lnss_files -lnss_dns
-lresolv" on the link line.
I *think* Daniel's patch from PR 6528 would not require clients to do
that, so perhaps that's better?
Thanks,
--
Paul Pluzhnikov
2012-02-25 Paul Pluzhnikov <ppluzhnikov@google.com>
[BZ #6528]
* elf/Makefile: Fix static NSS linkage.
diff --git a/elf/Makefile b/elf/Makefile
index 8234ba7..c265cf0 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -168,6 +168,13 @@ extra-objs += $(ldconfig-modules:=.o)
pldd-modules := xmalloc
+ifeq (yes,$(build-static-nss))
+nssobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)nss)
+resolvobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)resolv)
+static-gnulib += $(nssobjdir)/libnss_files.a $(resolvobjdir)/libnss_dns.a \
+ $(resolvobjdir)/libresolv.a
+endif
+
# To find xmalloc.c and xstrdup.c
vpath %.c ../locale/programs