From 04594feee5b3f4ac161e9091b3e403ce29c9f424 Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Wed, 16 Aug 2017 05:02:31 +0000 Subject: [PATCH] Use -S for library installations except for -DNO_ROOT builds. Also disable this if NO_SAFE_LIBINSTALL is defined. There is little harm in always using -S and it fixes several issues: - A race during 'make libraries' where, for example, libgcc_s is being installed while another library is trying to link against it. This is possible because libgcc_s is connected in both _prereq_libs and _startup_libs. The first build (_prereq_libs) sets MK_PROFILE=no while the 2nd pass (_startup_libs) enables MK_PROFILE. Thus the libgcc_s library *is* present in WORLDTMP for other libraries to link to, so serializing further items in _startup_libs is not required. Just ensuring that libgcc_s is installed atomically (via rename(2)) is enough. [1] - Installation to a running system where some library that cannot be detected, copied and used from the temporary INSTALLTMP with LD_LIBRARY_PATH that the build itself uses for installation. Such an example is having the install an NSS module for user lookups that install(1) uses while concurrently installing the module in another process. This is not a problem for the FreeBSD base build but can be for downstream vendors. While this is a very specific case, installation to a running system with non-atomic library installation is prone to many problems. A further step still is to install in proper dependency ordering. Reported by: dhw many times [1] Sponsored by: Dell EMC Isilon MFC after: 2 weeks --- share/mk/bsd.lib.mk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk index d3ad574f7295..3c6fb3812a00 100644 --- a/share/mk/bsd.lib.mk +++ b/share/mk/bsd.lib.mk @@ -326,6 +326,11 @@ _EXTRADEPEND: .if !defined(NO_FSCHG) SHLINSTALLFLAGS+= -fschg .endif +.endif +# Install libraries with -S to avoid linker races with WORLDTMP and risk +# of modifying in-use libraries when installing to a running system. +# It is safe to avoid this for NO_ROOT builds that are only creating an image. +.if !defined(NO_SAFE_LIBINSTALL) && !defined(NO_ROOT) SHLINSTALLFLAGS+= -S .endif