From 2ca8434c0dbbc698823ff74e96739c7164112c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Sun, 20 Mar 2022 16:29:53 +0700 Subject: [PATCH 1/2] hooks/gen-runtime-deps: convert element check to case...esac This change was made in the hope of finding a needle in a haystack could be faster than tokenizing and loop with for. However, the ultimate goal is easier to integrate a later change to add implicit sh-requires on libgcc_s.so.1 when libpthread.so.0 is required since libpthread.so.0 always dlopen(2) libgcc_s.so.1, and libpthread.so.0 will go ahead to crash the program, should it fail to do so. --- common/hooks/pre-pkg/04-generate-runtime-deps.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh index c8f8c04d4884..da0ac7754902 100644 --- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh +++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh @@ -75,12 +75,13 @@ hook() { read -n4 elfmagic < "$f" if [ "$elfmagic" = $'\177ELF' ]; then for nlib in $($OBJDUMP -p "$f"|awk '/NEEDED/{print $2}'); do - [ -z "$verify_deps" ] && verify_deps="$nlib" && continue - found=0 - for j in ${verify_deps}; do - [[ $j == $nlib ]] && found=1 && break - done - [[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib" + case " $verify_deps " in + *" $nlib "*) + ;; + *) + verify_deps="$verify_deps $nlib" + ;; + esac done fi done From 71478956740ba94d02a7ea4b98417f0d7ce81376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Sun, 20 Mar 2022 16:38:00 +0700 Subject: [PATCH 2/2] hooks/gen-runtime-deps: require libgcc_s.so.1 for libpthread.so.0 libpthread.so.0 dlopen(2) libgcc_s.so.1 on startup. Should the former fails to dlopen(2) the latter, it will proceed to crash the program. Let's add libgcc_s.so.1 to sh-requires list whenever libpthread.so.0 is required. While doing so, don't add it to sh-requires list when $sourcepkg is glibc, in order to prevent circular dependencies between glibc and libgcc. Fix: #36004 --- common/hooks/pre-pkg/04-generate-runtime-deps.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh index da0ac7754902..2fb9dc34b9e3 100644 --- a/common/hooks/pre-pkg/04-generate-runtime-deps.sh +++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh @@ -48,6 +48,7 @@ store_pkgdestdir_rundeps() { hook() { local depsftmp f lf j mapshlibs sorequires _curdep elfmagic + local needpthread= # Disable trap on ERR, xbps-uhelper cmd might return error... but not something # to be worried about because if there are broken shlibs this hook returns @@ -80,6 +81,9 @@ hook() { ;; *) verify_deps="$verify_deps $nlib" + if [ "$nlib" = libpthread.so.0 ]; then + needpthread=y + fi ;; esac done @@ -88,6 +92,12 @@ hook() { exec 0<&3 # restore stdin rm -f $depsftmp + # libpthread.so.0 dlopen(2) libgcc_s.so.1 and will abort if fail to do so + # Don't make glibc depends on libgcc to prevent circular dependencies. + if [ "$needpthread" ] && [ "$sourcepkg" != glibc ] ; then + verify_deps="$verify_deps libgcc_s.so.1" + fi + # # Add required run time packages by using required shlibs resolved # above, the mapping is done thru the common/shlibs file.