public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH 0/1] Check for errors in scanelf
@ 2021-10-02 20:13 Sam James
  2021-10-02 20:13 ` [gentoo-portage-dev] [PATCH 1/1] bin/misc-function.sh: check scanelf return code Sam James
  0 siblings, 1 reply; 2+ messages in thread
From: Sam James @ 2021-10-02 20:13 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Sam James

Posted at https://github.com/gentoo/portage/pull/750 originally
and merged in 3.0.24, but posting here for posterity.

Related to the general preserve-libs issues I've been working on.

Sam James (1):
  bin/misc-function.sh: check scanelf return code

 bin/misc-functions.sh | 64 +++++++++++++++++++++++++++++++++----------
 1 file changed, 50 insertions(+), 14 deletions(-)

-- 
2.33.0



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gentoo-portage-dev] [PATCH 1/1] bin/misc-function.sh: check scanelf return code
  2021-10-02 20:13 [gentoo-portage-dev] [PATCH 0/1] Check for errors in scanelf Sam James
@ 2021-10-02 20:13 ` Sam James
  0 siblings, 0 replies; 2+ messages in thread
From: Sam James @ 2021-10-02 20:13 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Sam James

This is part of a series of fixes for the linked bug (failure
to preserve libraries in some situations).

We need to check if scanelf failed when calling it in the
installed-files QA check as we later use it to populate the VDB.

Silently continuing results in either blank e.g. PROVIDES,
NEEDED{,.ELF.2} or those files may be missing entirely,
resulting in a corrupt state both on the system and in
any generated binpkgs.

Adds an escape variable (PORTAGE_NO_SCANELF_CHECK) to allow
re-emerging pax-utils if it's broken.

Bug: https://bugs.gentoo.org/811462
Signed-off-by: Sam James <sam@gentoo.org>
---
 bin/misc-functions.sh | 64 +++++++++++++++++++++++++++++++++----------
 1 file changed, 50 insertions(+), 14 deletions(-)

diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh
index bd1fb7553..e4defa550 100755
--- a/bin/misc-functions.sh
+++ b/bin/misc-functions.sh
@@ -177,25 +177,61 @@ install_qa_check() {
 	if type -P scanelf > /dev/null ; then
 		# Save NEEDED information after removing self-contained providers
 		rm -f "$PORTAGE_BUILDDIR"/build-info/NEEDED{,.ELF.2}
+
 		# We don't use scanelf -q, since that would omit libraries like
 		# musl's /usr/lib/libc.so which do not have any DT_NEEDED or
 		# DT_SONAME settings. Since we don't use scanelf -q, we have to
 		# handle the special rpath value "  -  " below.
-		scanelf -yRBF '%a;%p;%S;%r;%n' "${D%/}/" | { while IFS= read -r l; do
-			arch=${l%%;*}; l=${l#*;}
-			obj="/${l%%;*}"; l=${l#*;}
-			soname=${l%%;*}; l=${l#*;}
-			rpath=${l%%;*}; l=${l#*;}; [ "${rpath}" = "  -  " ] && rpath=""
-			needed=${l%%;*}; l=${l#*;}
-
-			# Infer implicit soname from basename (bug 715162).
-			if [[ -z ${soname} && $(file "${D%/}${obj}") == *"SB shared object"* ]]; then
-				soname=${obj##*/}
-			fi
+		scanelf_output=$(scanelf -yRBF '%a;%p;%S;%r;%n' "${D%/}/")
+
+		case $? in
+			0)
+				# Proceed
+				;;
+			159)
+				# Unknown syscall
+				eerror "Failed to run scanelf (unknown syscall)"
+
+				if [[ -z ${PORTAGE_NO_SCANELF_CHECK} ]]; then
+					# Abort only if the special recovery variable isn't set
+					eerror "Please upgrade pax-utils with:"
+					eerror " PORTAGE_NO_SCANELF_CHECK=1 emerge -v1 app-misc/pax-utils"
+					eerror "Aborting to avoid corrupting metadata"
+					die "${0##*/}: Failed to run scanelf! Update pax-utils?"
+				fi
+				;;
+			*)
+				# Failed in another way
+				eerror "Failed to run scanelf (returned: $?)!"
+
+				if [[ -z ${PORTAGE_NO_SCANELF_CHECK} ]]; then
+					# Abort only if the special recovery variable isn't set
+					eerror "Please report this bug at https://bugs.gentoo.org/!"
+					eerror "It may be possible to re-emerge pax-utils with:"
+					eerror " PORTAGE_NO_SCANELF_CHECK=1 emerge -v1 app-misc/pax-utils"
+					eerror "Aborting to avoid corrupting metadata"
+					die "${0##*/}: Failed to run scanelf!"
+				fi
+				;;
+		esac
+
+		if [[ -n ${scanelf_output} ]]; then
+			while IFS= read -r l; do
+				arch=${l%%;*}; l=${l#*;}
+				obj="/${l%%;*}"; l=${l#*;}
+				soname=${l%%;*}; l=${l#*;}
+				rpath=${l%%;*}; l=${l#*;}; [ "${rpath}" = "  -  " ] && rpath=""
+				needed=${l%%;*}; l=${l#*;}
+
+				# Infer implicit soname from basename (bug 715162).
+				if [[ -z ${soname} && $(file "${D%/}${obj}") == *"SB shared object"* ]]; then
+					soname=${obj##*/}
+				fi
 
-			echo "${obj} ${needed}"	>> "${PORTAGE_BUILDDIR}"/build-info/NEEDED
-			echo "${arch#EM_};${obj};${soname};${rpath};${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
-		done }
+				echo "${obj} ${needed}"	>> "${PORTAGE_BUILDDIR}"/build-info/NEEDED
+				echo "${arch#EM_};${obj};${soname};${rpath};${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
+			done <<< ${scanelf_output}
+		fi
 
 		[ -n "${QA_SONAME_NO_SYMLINK}" ] && \
 			echo "${QA_SONAME_NO_SYMLINK}" > \
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-02 20:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-02 20:13 [gentoo-portage-dev] [PATCH 0/1] Check for errors in scanelf Sam James
2021-10-02 20:13 ` [gentoo-portage-dev] [PATCH 1/1] bin/misc-function.sh: check scanelf return code Sam James

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox