Circular symlink created when only SHLIB_MAJOR is defined

Jeremie Le Hen <[email protected]>
Newsgroups gmane.os.netbsd.devel.general
Message-ID <[email protected]>
Hi list,

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

I've already sent this e-mail to tech-toolchain@ but got no answer.
I dare to resend it here to reach a larger audience.

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 >
nbsd.shlib_major_only.patch (text/plain, 815 B)
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.