<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">autofs-5.1.6 - make autofs.a a shared library

From: Ian Kent &lt;raven@themaw.net&gt;

When the linker option -Bsymbolic-functions is used the static library
that is linked to each object, automount and the shared lookup, parse
and mount shared libraries becomes unusable because static storage
allocated and initialized in the the library becomes undefined after
certain events, such as forking to become a daemon.

This can be fixed by changing the autofs static library to a shared
library.
---
 CHANGELOG        |    1 +
 Makefile.conf.in |    3 +++
 Makefile.rules   |    5 +++--
 autofs.spec      |    1 +
 daemon/Makefile  |    2 +-
 lib/Makefile     |   13 +++++++------
 modules/Makefile |   12 ++++++------
 7 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index dfffc156..ae8d2d3d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -72,6 +72,7 @@ xx/xx/2020 autofs-5.1.7
 - add helper to construct mount point path.
 - check defaults_read_config() return.
 - move AUTOFS_LIB to end of build rule lines.
+- make autofs.a a shared library.
 
 07/10/2019 autofs-5.1.6
 - support strictexpire mount option.
diff --git a/Makefile.conf.in b/Makefile.conf.in
index cbc3c0d7..df678eec 100644
--- a/Makefile.conf.in
+++ b/Makefile.conf.in
@@ -85,6 +85,9 @@ DMALLOCLIB = @DMALLOCLIB@
 prefix = @prefix@
 exec_prefix = @exec_prefix@
 
+# Shared library directory
+sharedlibdir = @libdir@
+
 # SSS library module directory
 ssslibdir=@sssldir@
 
diff --git a/Makefile.rules b/Makefile.rules
index ba694c83..43cf2963 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -17,7 +17,8 @@ endif
 INSTALLROOT = $(DESTDIR)
 
 # autofs utility library
-AUTOFS_LIB = ../lib/autofs.a
+AUTOFS_LIB      = ../lib/libautofs.so
+AUTOFS_LIB_LINK = -L../lib -lautofs
 
 # Compilers, linkers and flags
 # The STRIP defined here *must not* remove any dynamic-loading symbols
@@ -71,5 +72,5 @@ LIBS += $(LIBCLOCK_GETTIME)
 	$(CC) $(CFLAGS) -S $&lt;
 
 .c.so:
-	$(CC) $(SOLDFLAGS) $(CFLAGS) -o $*.so $&lt; $(LDFLAGS) $(LIBS) $(AUTOFS_LIB)
+	$(CC) $(SOLDFLAGS) $(CFLAGS) -o $*.so $&lt; $(LDFLAGS) $(LIBS) $(AUTOFS_LIB_LINK)
 	$(STRIP) $*.so
diff --git a/autofs.spec b/autofs.spec
index 22e7adf4..e0ab5d84 100644
--- a/autofs.spec
+++ b/autofs.spec
@@ -209,6 +209,7 @@ fi
 %{_sbindir}/mount.fedfs
 %{_sbindir}/fedfs-map-nfs4
 %endif
+%{_libdir}/libautofs.so
 %dir %{_libdir}/autofs
 %{_libdir}/autofs/*
 %{_mandir}/*/*
diff --git a/daemon/Makefile b/daemon/Makefile
index 28b94687..3af38e6f 100644
--- a/daemon/Makefile
+++ b/daemon/Makefile
@@ -38,7 +38,7 @@ endif
 all: automount
 
 automount: $(OBJS) $(AUTOFS_LIB)
-	$(CC) $(DAEMON_LDFLAGS) -o automount $(OBJS) $(LDFLAGS) $(LIBS) $(AUTOFS_LIB)
+	$(CC) $(DAEMON_LDFLAGS) -o automount $(OBJS) $(LDFLAGS) $(LIBS) $(AUTOFS_LIB_LINK)
 	$(STRIP) automount
 
 master_tok.c: master_tok.l
diff --git a/lib/Makefile b/lib/Makefile
index b6f3669f..83a80a1e 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -15,7 +15,7 @@ OBJS = cache.o mount_clnt.o mount_xdr.o cat_path.o rpc_subs.o \
 
 YACCSRC = nss_tok.c nss_parse.tab.c nss_parse.tab.h
 
-LIB = autofs.a
+LIB = libautofs.so
 
 CFLAGS += -I../include -fPIC -D_GNU_SOURCE
 CFLAGS += -DAUTOFS_MAP_DIR=\"$(autofsmapdir)\"
@@ -27,12 +27,11 @@ endif
 
 .PHONY: all install clean
 
-all: autofs.a
+all: libautofs.so
 
-autofs.a: $(OBJS)
-	rm -f $(LIB)
-	$(AR) $(ARFLAGS) $(LIB) $(OBJS)
-	-$(RANLIB) $(LIB)
+libautofs.so: $(OBJS)
+	$(CC) $(SOLDFLAGS) $(CFLAGS) -o $*.so $^ $(LDFLAGS) $(LIBS)
+	$(STRIP) $*.so
 
 mount.h: mount.x
 	$(RPCGEN) -h -o mount.h mount.x
@@ -64,6 +63,8 @@ nss_parse.tab.o: nss_parse.tab.c nss_parse.tab.h
 rpc_subs.o: mount.h
 
 install: all
+	install -d -m 755 $(INSTALLROOT)$(autofslibdir)
+	install -c $(LIB) -m 755 $(INSTALLROOT)$(sharedlibdir)
 
 clean:
 	rm -f $(LIB) $(RPCS) $(OBJS) $(YACCSRC) *.output *~
diff --git a/modules/Makefile b/modules/Makefile
index f97e7cda..91dc20ab 100644
--- a/modules/Makefile
+++ b/modules/Makefile
@@ -110,7 +110,7 @@ amd_parse.tab.o: amd_parse.tab.c amd_parse.tab.h
 
 parse_amd.so: parse_amd.c amd_parse.tab.o amd_tok.o
 	$(CC) $(SOLDFLAGS) $(CFLAGS) -o parse_amd.so \
-		parse_amd.c amd_parse.tab.o amd_tok.o $(LDFLAGS) $(LIBS) $(AUTOFS_LIB)
+		parse_amd.c amd_parse.tab.o amd_tok.o $(LDFLAGS) $(LIBS) $(AUTOFS_LIB_LINK)
 	$(STRIP) parse_amd.so
 
 #
@@ -118,17 +118,17 @@ parse_amd.so: parse_amd.c amd_parse.tab.o amd_tok.o
 #
 lookup_yp.so: lookup_yp.c
 	$(CC) $(SOLDFLAGS) $(CFLAGS) $(NSLCFLAGS) -o lookup_yp.so \
-		lookup_yp.c $(LDFLAGS) $(LIBS) $(NSLLIB) $(AUTOFS_LIB)
+		lookup_yp.c $(LDFLAGS) $(LIBS) $(NSLLIB) $(AUTOFS_LIB_LINK)
 	$(STRIP) lookup_yp.so
 
 lookup_nisplus.so: lookup_nisplus.c
 	$(CC) $(SOLDFLAGS) $(CFLAGS) $(NSLCFLAGS) -o lookup_nisplus.so \
-		lookup_nisplus.c $(LDFLAGS) $(LIBS) $(NSLLIB) $(AUTOFS_LIB)
+		lookup_nisplus.c $(LDFLAGS) $(LIBS) $(NSLLIB) $(AUTOFS_LIB_LINK)
 	$(STRIP) lookup_nisplus.so
 
 lookup_hesiod.so: lookup_hesiod.c
 	$(CC) $(SOLDFLAGS) $(CFLAGS) $(HESIOD_FLAGS) -o lookup_hesiod.so \
-		lookup_hesiod.c $(LDFLAGS) $(LIBHESIOD) $(LIBRESOLV) $(LIBS) $(AUTOFS_LIB)
+		lookup_hesiod.c $(LDFLAGS) $(LIBHESIOD) $(LIBRESOLV) $(LIBS) $(AUTOFS_LIB_LINK)
 	$(STRIP) lookup_hesiod.so
 
 cyrus-sasl.o: cyrus-sasl.c
@@ -140,11 +140,11 @@ cyrus-sasl-extern.o: cyrus-sasl-extern.c
 lookup_ldap.so: lookup_ldap.c dclist.o base64.o $(SASL_OBJ)
 	$(CC) $(SOLDFLAGS) $(CFLAGS) $(LDAP_FLAGS) -o lookup_ldap.so \
 		lookup_ldap.c dclist.o base64.o $(SASL_OBJ) \
-		$(LDFLAGS) $(LIBLDAP) $(LIBRESOLV) $(LIBS) $(AUTOFS_LIB)
+		$(LDFLAGS) $(LIBLDAP) $(LIBRESOLV) $(LIBS) $(AUTOFS_LIB_LINK)
 	$(STRIP) lookup_ldap.so
 
 mount_nfs.so: mount_nfs.c replicated.o
 	$(CC) $(SOLDFLAGS) $(CFLAGS) -o mount_nfs.so \
-		mount_nfs.c replicated.o $(LDFLAGS) $(LIBS) $(AUTOFS_LIB)
+		mount_nfs.c replicated.o $(LDFLAGS) $(LIBS) $(AUTOFS_LIB_LINK)
 	$(STRIP) mount_nfs.so
 
</pre></body></html>