[patch] hide libsmbclient's private symbols

James Peach jpeach at samba.org
Mon Jun 18 16:38:06 GMT 2007


On Jun 18, 2007, at 3:52 AM, Julien Cristau wrote:

> Hi,
>
> the following patch (against samba 3.0.25a) makes the build system  
> use a
> version script if it detects a recent enough gnu ld.  This makes
> libsmbclient export about 50 symbols instead of about 4000, which
> reduces the risk of symbols clashes due to private symbols which  
> aren't
> part of the API and have no business being exported.  The detection is
> probably not optimal, but I think it's safe (support for version  
> scripts
> seems to have been added in 2002, before gnu ld 2.12).  Feedback
> welcome.

This seems like a generally useful idea. I'd be pretty keen to see  
this make a bit more generic, so that we can have a single build rule  
that will build all the shared libraries.

The rules might look like this for a gcc-based toolchain. The only  
problem remaining is how to express the DSO version number in a  
generic way.

DSO_EXPORTS = -Wl,--version-script,exports/`basename $@ | sed -e/ 
@SHLIBEXT@/syms/`
SHLD_DSO = $(SHLD) $(LDSHFLAGS) $(DSO_EXPORTS) \
	@SONAMEFLAG@`basename $@`.$(XXXXXX_MAJOR)

bin/libsmbclient. at SHLIBEXT@: $(BINARY_PREREQS) $(LIBSMBCLIENT_OBJ)
	@echo Linking libsmbclient shared library $@
	@$(SHLD_DSO) $(LIBSMBCLIENT_OBJ) $(LIBS) $(KRB5LIBS) $(LDAP_LIBS) $ 
(NSCD_LIBS)

Actually, thinking about this a bit more, it might be better for the  
exports files to be a simple list of symbols (though I think most  
toolchains support wildcard matching). It's easier to generate the GNU/ 
Sun syntax from a simple list, than it is to go the other way round.

>
>
> Cheers,
> Julien
>
> Index: samba-3.0.25a/source/Makefile.in
> ===================================================================
> --- samba-3.0.25a.orig/source/Makefile.in	2007-06-08  
> 23:36:12.000000000 +0200
> +++ samba-3.0.25a/source/Makefile.in	2007-06-08 23:36:12.000000000  
> +0200
> @@ -1163,6 +1163,7 @@
> 	@echo Linking libsmbclient shared library $@
> 	@$(SHLD) $(LDSHFLAGS) -Wl,-z,defs -o $@ $(LIBSMBCLIENT_OBJ) $(LIBS) \
> 		$(KRB5LIBS) $(LDAP_LIBS) $(NSCD_LIBS) \
> +		@VERSIONLDFLAGS@ \
> 		@SONAMEFLAG@`basename $@`.$(LIBSMBCLIENT_MAJOR)
>
> bin/libsmbclient.a: proto_exists $(LIBSMBCLIENT_OBJ)
> Index: samba-3.0.25a/source/configure.in
> ===================================================================
> --- samba-3.0.25a.orig/source/configure.in	2007-06-08  
> 23:36:12.000000000 +0200
> +++ samba-3.0.25a/source/configure.in	2007-06-08 23:36:36.000000000  
> +0200
> @@ -267,6 +267,7 @@
> AC_SUBST(SHELL)
> AC_SUBST(LDSHFLAGS)
> AC_SUBST(SONAMEFLAG)
> +AC_SUBST(VERSIONLDFLAGS)
> AC_SUBST(SHLD)
> AC_SUBST(HOST_OS)
> AC_SUBST(PICFLAG)
> @@ -456,6 +457,9 @@
>  	if test "$ac_cv_gnu_ld_date" -lt 20030217; then
>  		ac_cv_gnu_ld_no_default_allow_shlib_undefined=yes
>  	fi
> +	if test "$ac_cv_gnu_ld_date" -gt 20030101; then
> +		ac_cv_gnu_ld_version_script=yes
> +	fi
>         else
>            AC_MSG_CHECKING(GNU ld release version)
>            changequote(,)dnl
> @@ -471,6 +475,9 @@
>            if test "$ac_cv_gnu_ld_vernr_major" -lt 2 || test  
> "$ac_cv_gnu_ld_vernr_minor" -lt 14; then
>              ac_cv_gnu_ld_no_default_allow_shlib_undefined=yes
>            fi
> +           if test "$ac_cv_gnu_ld_vernr_major" -gt 2 || test  
> "$ac_cv_gnu_ld_vernr_major" = 2 && test "$ac_cv_gnu_ld_vernr_minor" - 
> ge 12; then
> +             ac_cv_gnu_ld_version_script=yes
> +           fi
>         fi
> fi
>
> @@ -1703,6 +1710,9 @@
> 			DYNEXP="-Wl,--export-dynamic"
> 			PICFLAG="-fPIC"
> 			SONAMEFLAG="-Wl,-soname="
> +			if test "${ac_cv_gnu_ld_version_script}" = yes; then
> +				VERSIONLDFLAGS="-Wl,--version-script,libsmb/libsmbclient.syms"
> +			fi
> 			AC_DEFINE(STAT_ST_BLOCKSIZE,512)
> 			;;
> 		*solaris*) AC_DEFINE(SUNOS5,1,[Whether the host os is solaris])
> Index: samba-3.0.25a/source/libsmb/libsmbclient.syms
> ===================================================================
> --- /dev/null	1970-01-01 00:00:00.000000000 +0000
> +++ samba-3.0.25a/source/libsmb/libsmbclient.syms	2007-06-08  
> 23:36:12.000000000 +0200
> @@ -0,0 +1,4 @@
> +{
> +	global: smbc_*;
> +	local: *;
> +};

--
James Peach | jpeach at samba.org



More information about the samba-technical mailing list