Bug 30709 - nscd fails to build with cleanup handler if built with -fexceptions
Summary: nscd fails to build with cleanup handler if built with -fexceptions
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: nscd (show other bugs)
Version: 2.38
: P2 normal
Target Milestone: 2.39
Assignee: Florian Weimer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-31 22:34 UTC by Frederik Schwan
Modified: 2023-08-11 08:54 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2023-08-01 00:00:00
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frederik Schwan 2023-07-31 22:34:51 UTC
Since a443bd3fb233186038b8b483959ecb7978d1abea, glibc fails to build on Arch Linux. Reverting the commit fixes the issue. Not sure though why the symbol is missing.

```
make[2]: Entering directory '/build/glibc/src/glibc/nscd'
gcc gai.c -c -std=gnu11 -fgnu89-inline  -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -g -ffile-prefix-map=/build/glibc/src=/usr/src/debug/glibc -Wall -Wwrite-strings -Wundef -fmerge-all-constants -frounding-math -fstack-protector-strong -fno-common -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wstrict-prototypes -Wold-style-definition -fmath-errno -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 -DHAVE_EPOLL -DHAVE_INOTIFY -DHAVE_NETLINK  -fPIE   -fcf-protection -DNEED_NETLINK   -fPIE    -I../include -I/build/glibc/src/glibc-build/nscd  -I/build/glibc/src/glibc-build  -I../sysdeps/unix/sysv/linux/x86_64/64  -I../sysdeps/unix/sysv/linux/x86_64  -I../sysdeps/unix/sysv/linux/x86/include -I../sysdeps/unix/sysv/linux/x86  -I../sysdeps/x86/nptl  -I../sysdeps/unix/sysv/linux/wordsize-64  -I../sysdeps/x86_64/nptl  -I../sysdeps/unix/sysv/linux/include -I../sysdeps/unix/sysv/linux  -I../sysdeps/nptl  -I../sysdeps/pthread  -I../sysdeps/gnu  -I../sysdeps/unix/inet  -I../sysdeps/unix/sysv  -I../sysdeps/unix/x86_64  -I../sysdeps/unix  -I../sysdeps/posix  -I../sysdeps/x86_64/64  -I../sysdeps/x86_64/fpu/multiarch  -I../sysdeps/x86_64/fpu  -I../sysdeps/x86/fpu  -I../sysdeps/x86_64/multiarch  -I../sysdeps/x86_64  -I../sysdeps/x86/include -I../sysdeps/x86  -I../sysdeps/ieee754/float128  -I../sysdeps/ieee754/ldbl-96/include -I../sysdeps/ieee754/ldbl-96  -I../sysdeps/ieee754/dbl-64  -I../sysdeps/ieee754/flt-32  -I../sysdeps/wordsize-64  -I../sysdeps/ieee754  -I../sysdeps/generic  -I.. -I../libio -I. -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/include -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/include-fixed -isystem /usr/include -D_LIBC_REENTRANT -include /build/glibc/src/glibc-build/libc-modules.h -DMODULE_NAME=nscd -include ../include/libc-symbols.h  -DPIC     -DTOP_NAMESPACE=glibc -o /build/glibc/src/glibc-build/nscd/gai.o -MD -MP -MF /build/glibc/src/glibc-build/nscd/gai.o.dt -MT /build/glibc/src/glibc-build/nscd/gai.o
make[2]: Leaving directory '/build/glibc/src/glibc/nscd'
make[2]: Entering directory '/build/glibc/src/glibc/nscd'
gcc -Wl,-rpath-link=/build/glibc/src/glibc-build:/build/glibc/src/glibc-build/math:/build/glibc/src/glibc-build/elf:/build/glibc/src/glibc-build/dlfcn:/build/glibc/src/glibc-build/nss:/build/glibc/src/glibc-build/nis:/build/glibc/src/glibc-build/rt:/build/glibc/src/glibc-build/resolv:/build/glibc/src/glibc-build/mathvec:/build/glibc/src/glibc-build/support:/build/glibc/src/glibc-build/nptl -o /build/glibc/src/glibc-build/nscd/nscd -pie -Wl,-z,pack-relative-relocs -Wl,-O1 -nostdlib -nostartfiles  -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -Wl,-z,now -Wl,-z,relro  /build/glibc/src/glibc-build/csu/Scrt1.o /build/glibc/src/glibc-build/csu/crti.o `gcc  --print-file-name=crtbeginS.o` /build/glibc/src/glibc-build/nscd/nscd.o /build/glibc/src/glibc-build/nscd/connections.o /build/glibc/src/glibc-build/nscd/pwdcache.o /build/glibc/src/glibc-build/nscd/getpwnam_r.o /build/glibc/src/glibc-build/nscd/getpwuid_r.o /build/glibc/src/glibc-build/nscd/grpcache.o /build/glibc/src/glibc-build/nscd/getgrnam_r.o /build/glibc/src/glibc-build/nscd/getgrgid_r.o /build/glibc/src/glibc-build/nscd/hstcache.o /build/glibc/src/glibc-build/nscd/gethstbyad_r.o /build/glibc/src/glibc-build/nscd/gethstbynm3_r.o /build/glibc/src/glibc-build/nscd/getsrvbynm_r.o /build/glibc/src/glibc-build/nscd/getsrvbypt_r.o /build/glibc/src/glibc-build/nscd/servicescache.o /build/glibc/src/glibc-build/nscd/dbg_log.o /build/glibc/src/glibc-build/nscd/nscd_conf.o /build/glibc/src/glibc-build/nscd/nscd_stat.o /build/glibc/src/glibc-build/nscd/cache.o /build/glibc/src/glibc-build/nscd/mem.o /build/glibc/src/glibc-build/nscd/nscd_setup_thread.o /build/glibc/src/glibc-build/nscd/xmalloc.o /build/glibc/src/glibc-build/nscd/xstrdup.o /build/glibc/src/glibc-build/nscd/aicache.o /build/glibc/src/glibc-build/nscd/initgrcache.o /build/glibc/src/glibc-build/nscd/gai.o /build/glibc/src/glibc-build/nscd/res_hconf.o /build/glibc/src/glibc-build/nscd/netgroupcache.o /build/glibc/src/glibc-build/nscd/cachedumper.o  -Wl,-dynamic-linker=/usr/lib/ld-linux-x86-64.so.2 -Wl,-z,now /build/glibc/src/glibc-build/libc.so.6 /build/glibc/src/glibc-build/libc_nonshared.a -Wl,--as-needed /build/glibc/src/glibc-build/elf/ld.so -Wl,--no-as-needed -lgcc  `gcc  --print-file-name=crtendS.o` /build/glibc/src/glibc-build/csu/crtn.o
/usr/bin/ld: /build/glibc/src/glibc-build/nscd/gai.o: in function `cancel_handler':
/usr/src/debug/glibc/glibc/nscd/../sysdeps/unix/sysv/linux/check_pf.c:300:(.text.unlikely+0x2e): undefined reference to `_Unwind_Resume'
/usr/bin/ld: /build/glibc/src/glibc-build/nscd/gai.o:(.data.rel.local.DW.ref.__gcc_personality_v0[DW.ref.__gcc_personality_v0]+0x0): undefined reference to `__gcc_personality_v0'
collect2: error: ld returned 1 exit status
make[2]: *** [../Rules:283: /build/glibc/src/glibc-build/nscd/nscd] Error 1
make[2]: Leaving directory '/build/glibc/src/glibc/nscd'
make[1]: *** [Makefile:484: nscd/others] Error 2
make: *** [Makefile:9: all] Error 2
```
Comment 1 Andreas Schwab 2023-08-01 06:39:42 UTC
The symbols are defined in libgcc.  Looks like you have a broken libgcc.  Please report that to the Arch team.
Comment 2 Frederik Schwan 2023-08-01 08:03:32 UTC
libgcc contains
```
    28: 000000000001e480   694 FUNC    GLOBAL DEFAULT   11 __gcc_personality_v0@@GCC_3.3.1
    85: 00000000000040fb     6 FUNC    LOCAL  DEFAULT   11 __gcc_personality_v0.cold
   402: 000000000001e480   694 FUNC    GLOBAL DEFAULT   11 __gcc_personality_v0
```

as well as

```
   406: 000000000001af00   522 FUNC    GLOBAL DEFAULT   11 _Unwind_Resume
```
Comment 3 Florian Weimer 2023-08-01 09:06:37 UTC
(In reply to freswa from comment #2)
> libgcc contains
> ```
>     28: 000000000001e480   694 FUNC    GLOBAL DEFAULT   11
> __gcc_personality_v0@@GCC_3.3.1
>     85: 00000000000040fb     6 FUNC    LOCAL  DEFAULT   11
> __gcc_personality_v0.cold
>    402: 000000000001e480   694 FUNC    GLOBAL DEFAULT   11
> __gcc_personality_v0
> ```
> 
> as well as
> 
> ```
>    406: 000000000001af00   522 FUNC    GLOBAL DEFAULT   11 _Unwind_Resume
> ```

This is from libgcc_s, right? We only link against libgcc.a, so we don't get that definition. (We don't build nscd with -static-libgcc.)

The unwinder is loaded lazily via <unwind-link.h>, but that is currently not available in nscd because nscd is built as !SHARED.
Comment 4 Frederik Schwan 2023-08-01 09:29:56 UTC
(In reply to Florian Weimer from comment #3)
> This is from libgcc_s, right?
Yes indeed. We don't package static gcc-libs as of now.

Thanks for the explanation, didn't see that it was a static link that failed.
Comment 5 Florian Weimer 2023-08-01 14:23:36 UTC
I posted a patch which removes the problematic code from nscd:

[PATCH] nscd: Do not rebuild getaddrinfo (bug 30709)
<https://inbox.sourceware.org/libc-alpha/87sf924zqx.fsf@oldenburg.str.redhat.com/T/>
Comment 6 Frederik Schwan 2023-08-01 15:10:58 UTC
(In reply to Florian Weimer from comment #5)
> I posted a patch which removes the problematic code from nscd:
> 
> [PATCH] nscd: Do not rebuild getaddrinfo (bug 30709)
> <https://inbox.sourceware.org/libc-alpha/87sf924zqx.fsf@oldenburg.str.redhat.
> com/T/>

lgtm
Comment 7 Arsen Arsenović 2023-08-02 19:51:36 UTC
(In reply to Frederik Schwan from comment #4)
> (In reply to Florian Weimer from comment #3)
> > This is from libgcc_s, right?
> Yes indeed. We don't package static gcc-libs as of now.
> 
> Thanks for the explanation, didn't see that it was a static link that failed.

Please don't filter out libgcc.a.

libgcc is a compiler implementation detail, and isn't voluntary like your usual static library in some 'normal' package.  I agree with Andreas in this regard.
Comment 8 Florian Weimer 2023-08-11 08:54:52 UTC
Fixed for 2.39 via:

commit 039ff51ac7e02db1cfc0c23e38ac7bfbb00221d1
Author: Florian Weimer <fweimer@redhat.com>
Date:   Fri Aug 11 10:10:16 2023 +0200

    nscd: Do not rebuild getaddrinfo (bug 30709)
    
    The nscd daemon caches hosts data from NSS modules verbatim, without
    filtering protocol families or sorting them (otherwise separate caches
    would be needed for certain ai_flags combinations).  The cache
    implementation is complete separate from the getaddrinfo code.  This
    means that rebuilding getaddrinfo is not needed.  The only function
    actually used is __bump_nl_timestamp from check_pf.c, and this change
    moves it into nscd/connections.c.
    
    Tested on x86_64-linux-gnu with -fexceptions, built with
    build-many-glibcs.py.  I also backported this patch into a distribution
    that still supports nscd and verified manually that caching still works.
    
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>