diff --git a/common/hooks/pre-pkg/07-shlib-symbols.sh b/common/hooks/pre-pkg/07-shlib-symbols.sh new file mode 100644 index 00000000000000..dcedd8c5bf60e3 --- /dev/null +++ b/common/hooks/pre-pkg/07-shlib-symbols.sh @@ -0,0 +1,60 @@ +# This hook executes the following tasks: +# - generates shlib-provides file for xbps-create(8) + +get_symbols() { + local _destdir="$1" _fname="$2" _soname="$3" + local _addr _type _sym + local _path="${_fname#$_destdir}" + _path=${_path%/*} + $NM -Dg --defined-only $_fname | while read _addr _type _sym; do + echo "${_path}/$_soname $_sym ${pkgname}-${version}" + echo "${_path}/$_soname $_sym ${pkgname}-${version}" >&2 + done +} + +get_old_symbols() { + local _destdir="$1" _fname="$2" + $XBPS_QUERY_CMD -R --cat "/usr/lib/symbols/${pkgname}" "$pkgname" || : +} + +merge_symbols() { + awk ' + {x[$1][$2]=$3} + END{ + for (k in x) for (k1 in x[k]) printf "%s %s %s\n",k,k1,x[k][k1] + }' +} + +collect_symbols() { + local _destdir="$1" + local _soname + + if [ ! -d ${_destdir} ]; then + return 0 + fi + mkdir -p "${_destdir}/usr/lib/symbols" + + find ${_destdir} -type f -name "*.so*" | while read f; do + _fname="${f##*/}" + case "$(file -bi "$f")" in + application/x-sharedlib*|application/x-pie-executable*) + _soname=$(${OBJDUMP} -p "$f"|grep SONAME|awk '{print $2}') + get_symbols "$_destdir" "$f" "$_soname" + get_old_symbols "$_destdir" "$f" "$_soname" + ;; + esac + done | merge_symbols >"${_destdir}/usr/lib/symbols/${pkgname}" +} + +hook() { + local _destdir32=${XBPS_DESTDIR}/${pkgname}-32bit-${version} + + if [ -z "$shlib_provides" -a "${archs// /}" = "noarch" -o -n "$noshlibprovides" ]; then + return 0 + fi + + # native pkg + collect_symbols ${PKGDESTDIR} + # 32bit pkg + collect_symbols ${_destdir32} +} diff --git a/common/shlibs b/common/shlibs index 8b1c87a98aa4c3..71dad5747000c3 100644 --- a/common/shlibs +++ b/common/shlibs @@ -3709,3 +3709,4 @@ libnvpair.so.1 zfs-0.8.2_1 libjsonnet.so.0 jsonnet-0.14.0_2 libjsonnet++.so.0 jsonnet-0.14.0_2 libigdgmm.so.12 intel-gmmlib-19.3.4_1 +libtestlib.so.0 testlib-0.1_1 diff --git a/srcpkgs/testbin/template b/srcpkgs/testbin/template new file mode 100644 index 00000000000000..5a0af38d801045 --- /dev/null +++ b/srcpkgs/testbin/template @@ -0,0 +1,30 @@ +# Template file for 'testbin' +pkgname=testbin +version=0.2 +revision=1 +hostmakedepends="" +makedepends="testlib-devel" +depends="" +short_desc="symbol package version test" +maintainer="Duncaen " +license="BSD-2-clause" +homepage="https://voidlinux.org" + +do_build() { + echo "#include " >main.c + echo "#include " >>main.c + case "${version}" in + 0.1) + echo 'int main(void) { printf("%d\n", foo()); return 0; }' >>main.c + ;; + 0.2) + echo 'int main(void) { printf("%d %d\n", foo(), bar()); return 0; }' >>main.c + ;; + esac + $CC $CFLAGS -c -o main.o main.c + $CC $LDFLAGS -o testbin main.c -ltestlib +} + +do_install() { + vbin testbin +} diff --git a/srcpkgs/testlib-devel b/srcpkgs/testlib-devel new file mode 120000 index 00000000000000..ffcc5e380808e5 --- /dev/null +++ b/srcpkgs/testlib-devel @@ -0,0 +1 @@ +testlib \ No newline at end of file diff --git a/srcpkgs/testlib/template b/srcpkgs/testlib/template new file mode 100644 index 00000000000000..478e7fbe3b0738 --- /dev/null +++ b/srcpkgs/testlib/template @@ -0,0 +1,50 @@ +# Template file for 'testlib' +pkgname=testlib +version=0.2 +revision=1 +hostmakedepends="" +makedepends="" +depends="" +short_desc="symbol package version test" +maintainer="Duncaen " +license="BSD-2-clause" +homepage="https://voidlinux.org" + +do_build() { + case "$version" in + 0.1) + echo "int foo(void);" >testlib.h + echo "int foo(void) { return 1; }" >testlib.c + $CC $CFLAGS -c -o testlib.o testlib.c + $CC -shared $LDFLAGS -Wl,-soname,libtestlib.so.0 testlib.o -o libtestlib.so.${version} + ln -sf libtestlib.so.${version} libtestlib.so.0 + ln -sf libtestlib.so.${version} libtestlib.so + ;; + 0.2) + echo "int foo(void);" >testlib.h + echo "int bar(void);" >>testlib.h + echo "int foo(void) { return 1; }" >testlib.c + echo "int bar(void) { return 1; }" >>testlib.c + $CC $CFLAGS -c -o testlib.o testlib.c + $CC -shared $LDFLAGS -Wl,-soname,libtestlib.so.0 testlib.o -o libtestlib.so.${version} + ln -sf libtestlib.so.${version} libtestlib.so.0 + ln -sf libtestlib.so.${version} libtestlib.so + ;; + esac +} + +do_install() { + vmkdir usr/lib + vinstall libtestlib.so.${version} 755 usr/lib + vcopy libtestlib.so* usr/lib + vinstall testlib.h 644 usr/include +} + +testlib-devel_package() { + short_desc+=" - development files" + depends="${sourcepkg}>=${version}_${revision}" + pkg_install() { + vmove usr/include + vmove "usr/lib/*.so" + } +} diff --git a/test.sh b/test.sh new file mode 100755 index 00000000000000..16b78a310ea8cb --- /dev/null +++ b/test.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +mktestlib() { + local version="$1" + sed -i "s/version=.*/version=$version/" srcpkgs/testlib/template + ./xbps-src -f pkg testlib >/dev/null || exit 1 + echo "symbols for $version:" + xbps-query \ + --repository=hostdir/binpkgs/ \ + --repository=hostdir/binpkgs/symbol-map \ + --cat /usr/lib/symbols/testlib testlib || exit 1 +} + +mktestbin() { + local version="$1" + sed -i "s/version=.*/version=$version/" srcpkgs/testbin/template + ./xbps-src -f pkg testbin >/dev/null || exit 1 + echo "deps for testbin-$version:" + xbps-query \ + --repository=hostdir/binpkgs/ \ + --repository=hostdir/binpkgs/symbol-map \ + -x testbin || exit 1 +} + +rm -rf hostdir/binpkgs/symbol-map +mktestlib "0.1" +mktestbin "0.1" +mktestlib "0.2" +mktestbin "0.2"