1 From ecc9767fd8c3a1ecbfca5df18714df34995a38a3 Mon Sep 17 00:00:00 2001
2 From: Khem Raj <raj.khem@gmail.com>
3 Date: Tue, 26 Aug 2025 22:45:54 -0700
4 Subject: [PATCH] make: Make _nss_nis_getsecretkey export conditional on xdecrypt()
6 The function _nss_nis_getsecretkey in nis-publickey.c is only
7 compiled when xdecrypt() is available. This is controlled by the
8 configure check AC_CHECK_FUNCS([xdecrypt]) which defines
9 HAVE_XDECRYPT in config.h.
11 However, the symbol was always listed in src/libnss_nis.map,
12 regardless of whether the function was actually built. On systems
13 without xdecrypt() (for example musl or certain embedded toolchains),
14 this leads to a link failure:
16 ld: error: version script assignment of 'NSS_NIS_1.0' to symbol
17 '_nss_nis_getsecretkey' failed: symbol not defined
19 To fix this mismatch, rename libnss_nis.map to
20 libnss_nis.map.in and generate libnss_nis.map at build time:
22 - If HAVE_XDECRYPT is defined, the symbol map is copied unchanged.
23 - Otherwise, the _nss_nis_getsecretkey line is stripped out
26 Automake rules are added to src/Makefile.am so the correct
27 libnss_nis.map is produced, and the linker always sees a version
28 script consistent with the compiled objects.
30 This ensures _nss_nis_getsecretkey is exported only when it exists
31 in the object code, preventing build failures on platforms where
32 xdecrypt() is missing.
34 This fixes build with LLD linker which defaults to not accepting
37 Upstream-Status: Submitted [https://github.com/thkukuk/libnss_nis/pull/12]
38 Signed-off-by: Khem Raj <raj.khem@gmail.com>
40 src/Makefile.am | 18 +++++++++++++++++-
41 src/{libnss_nis.map => libnss_nis.map.in} | 0
42 2 files changed, 17 insertions(+), 1 deletion(-)
43 rename src/{libnss_nis.map => libnss_nis.map.in} (100%)
45 diff --git a/src/Makefile.am b/src/Makefile.am
46 index e1a9bb2..cc32ea9 100644
49 @@ -22,8 +22,24 @@ nss_loader_test_LDADD = -ldl
51 TESTS = $(check_PROGRAMS)
53 +# Build the version script from a template, pruning _nss_nis_getsecretkey
54 +# when xdecrypt() was not detected by configure (i.e., HAVE_XDECRYPT is unset).
55 +BUILT_SOURCES = libnss_nis.map
56 +EXTRA_DIST += libnss_nis.map.in
57 +CLEANFILES += libnss_nis.map
59 +libnss_nis.map: $(srcdir)/libnss_nis.map.in $(top_builddir)/config.h
61 + if grep -q '^[[:space:]]*#define[[:space:]]\+HAVE_XDECRYPT[[:space:]]\+1' $(top_builddir)/config.h ; then \
62 + cp $(srcdir)/libnss_nis.map.in $@ ; \
64 + sed 's/ _nss_nis_getsecretkey;//g' \
65 + $(srcdir)/libnss_nis.map.in > $@ ; \
69 libnss_nis_la_LDFLAGS = -version-info 2:0:0 \
70 - -Wl,--version-script=$(srcdir)/libnss_nis.map
71 + -Wl,--version-script=$(builddir)/libnss_nis.map
72 libnss_nis_la_LIBADD = @LIBNSL_LIBS@
73 libnss_nis_la_SOURCES = nis-alias.c nis-ethers.c nis-grp.c nis-hosts.c \
74 nis-initgroups.c nis-netgrp.c nis-network.c \
75 diff --git a/src/libnss_nis.map b/src/libnss_nis.map.in
77 rename from src/libnss_nis.map
78 rename to src/libnss_nis.map.in