Subject: Circular symlink created when only SHLIB_MAJOR is defined
To: None <tech-toolchain@NetBSD.org>
From: Jeremie Le Hen <jeremie@le-hen.org>
List: tech-toolchain
Date: 01/23/2007 17:31:34
--R3G7APHDIzY6R/pk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi list,

(Please Cc: in your reply, I'm not subscribed.)

bsd.lib.mk supports multiple levels of precision for shared libraries
version numbering as the following code snippet shows:

% .if defined(SHLIB_MAJOR) && !empty(SHLIB_MAJOR)                         # {
% .if defined(SHLIB_MINOR) && !empty(SHLIB_MINOR)
% .if defined(SHLIB_TEENY) && !empty(SHLIB_TEENY)
% SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}.${SHLIB_TEENY}
% .else
% SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
% .endif
% .else
% SHLIB_FULLVERSION=${SHLIB_MAJOR}
% .endif
% .endif                                                                  # }

The problem I've been faced occurs in the later case when you only
define SHLIB_MAJOR.  Here is what happens during the linkage of my
shared library:

% #     build  poolexecutor/libzthreadstub.so.1
% rm -f libzthreadstub.so.1
% cc -Wl,-x -shared -Wl,-soname,libzthreadstub.so.1   -o libzthreadstub.so.1   -Wl,-rpath-link,/lib:/usr/lib  -L/lib  -Wl,--whole-archive libzthreadstub_pic.a -Wl,--no-whole-archive -lpthread
% ln -sf libzthreadstub.so.1 libzthreadstub.so.1.tmp
% mv -f libzthreadstub.so.1.tmp libzthreadstub.so.1
% ln -sf libzthreadstub.so.1 libzthreadstub.so.tmp
% mv -f libzthreadstub.so.tmp libzthreadstub.so

This results in a circular symlink for libzthreadstub.so.1:

% octobrebsd:poolexecutor$ stat -f "%N -> %Y" libzthreadstub.so.1
% libzthreadstub.so.1 -> libzthreadstub.so.1


According to the CVS repository, this ln(1)/mv(1) dance is used to
prevent small races during parallel builds where libc.so could no
longer exist for a small time (see rev. 1.177).  The proposed fix
is attached.

This works for me, at least.
Best regards,
-- 
Jeremie Le Hen
< jeremie at le-hen dot org >< ttz at chchile dot org >

--R3G7APHDIzY6R/pk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="nbsd.shlib_major_only.patch"

Index: bsd.lib.mk
===================================================================
RCS file: /pub/NetBSD-CVS/src/share/mk/bsd.lib.mk,v
retrieving revision 1.270
diff -u -r1.270 bsd.lib.mk
--- bsd.lib.mk  23 Nov 2006 12:05:26 -0000      1.270
+++ bsd.lib.mk  23 Jan 2007 16:20:41 -0000
@@ -469,8 +469,10 @@
 #  We don't use INSTALL_SYMLINK here because this is just
 #  happening inside the build directory/objdir. XXX Why does
 #  this spend so much effort on libraries that aren't live??? XXX
+.if ${SHLIB_FULLVERSION} != ${SHLIB_MAJOR}
 	${HOST_LN} -sf lib${LIB}.so.${SHLIB_FULLVERSION} lib${LIB}.so.${SHLIB_MAJOR}.tmp
 	mv -f lib${LIB}.so.${SHLIB_MAJOR}.tmp lib${LIB}.so.${SHLIB_MAJOR}
+.endif
 	${HOST_LN} -sf lib${LIB}.so.${SHLIB_FULLVERSION} lib${LIB}.so.tmp
 	mv -f lib${LIB}.so.tmp lib${LIB}.so
 .endif


--R3G7APHDIzY6R/pk--