Gentoo Archives: gentoo-portage-dev

From: Sam James <sam@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Sam James <sam@g.o>
Subject: [gentoo-portage-dev] [PATCH 1/1] bin/misc-function.sh: check scanelf return code
Date: Sat, 02 Oct 2021 20:13:45
Message-Id: 20211002201335.347542-2-sam@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 0/1] Check for errors in scanelf by Sam James
1 This is part of a series of fixes for the linked bug (failure
2 to preserve libraries in some situations).
3
4 We need to check if scanelf failed when calling it in the
5 installed-files QA check as we later use it to populate the VDB.
6
7 Silently continuing results in either blank e.g. PROVIDES,
8 NEEDED{,.ELF.2} or those files may be missing entirely,
9 resulting in a corrupt state both on the system and in
10 any generated binpkgs.
11
12 Adds an escape variable (PORTAGE_NO_SCANELF_CHECK) to allow
13 re-emerging pax-utils if it's broken.
14
15 Bug: https://bugs.gentoo.org/811462
16 Signed-off-by: Sam James <sam@g.o>
17 ---
18 bin/misc-functions.sh | 64 +++++++++++++++++++++++++++++++++----------
19 1 file changed, 50 insertions(+), 14 deletions(-)
20
21 diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh
22 index bd1fb7553..e4defa550 100755
23 --- a/bin/misc-functions.sh
24 +++ b/bin/misc-functions.sh
25 @@ -177,25 +177,61 @@ install_qa_check() {
26 if type -P scanelf > /dev/null ; then
27 # Save NEEDED information after removing self-contained providers
28 rm -f "$PORTAGE_BUILDDIR"/build-info/NEEDED{,.ELF.2}
29 +
30 # We don't use scanelf -q, since that would omit libraries like
31 # musl's /usr/lib/libc.so which do not have any DT_NEEDED or
32 # DT_SONAME settings. Since we don't use scanelf -q, we have to
33 # handle the special rpath value " - " below.
34 - scanelf -yRBF '%a;%p;%S;%r;%n' "${D%/}/" | { while IFS= read -r l; do
35 - arch=${l%%;*}; l=${l#*;}
36 - obj="/${l%%;*}"; l=${l#*;}
37 - soname=${l%%;*}; l=${l#*;}
38 - rpath=${l%%;*}; l=${l#*;}; [ "${rpath}" = " - " ] && rpath=""
39 - needed=${l%%;*}; l=${l#*;}
40 -
41 - # Infer implicit soname from basename (bug 715162).
42 - if [[ -z ${soname} && $(file "${D%/}${obj}") == *"SB shared object"* ]]; then
43 - soname=${obj##*/}
44 - fi
45 + scanelf_output=$(scanelf -yRBF '%a;%p;%S;%r;%n' "${D%/}/")
46 +
47 + case $? in
48 + 0)
49 + # Proceed
50 + ;;
51 + 159)
52 + # Unknown syscall
53 + eerror "Failed to run scanelf (unknown syscall)"
54 +
55 + if [[ -z ${PORTAGE_NO_SCANELF_CHECK} ]]; then
56 + # Abort only if the special recovery variable isn't set
57 + eerror "Please upgrade pax-utils with:"
58 + eerror " PORTAGE_NO_SCANELF_CHECK=1 emerge -v1 app-misc/pax-utils"
59 + eerror "Aborting to avoid corrupting metadata"
60 + die "${0##*/}: Failed to run scanelf! Update pax-utils?"
61 + fi
62 + ;;
63 + *)
64 + # Failed in another way
65 + eerror "Failed to run scanelf (returned: $?)!"
66 +
67 + if [[ -z ${PORTAGE_NO_SCANELF_CHECK} ]]; then
68 + # Abort only if the special recovery variable isn't set
69 + eerror "Please report this bug at https://bugs.gentoo.org/!"
70 + eerror "It may be possible to re-emerge pax-utils with:"
71 + eerror " PORTAGE_NO_SCANELF_CHECK=1 emerge -v1 app-misc/pax-utils"
72 + eerror "Aborting to avoid corrupting metadata"
73 + die "${0##*/}: Failed to run scanelf!"
74 + fi
75 + ;;
76 + esac
77 +
78 + if [[ -n ${scanelf_output} ]]; then
79 + while IFS= read -r l; do
80 + arch=${l%%;*}; l=${l#*;}
81 + obj="/${l%%;*}"; l=${l#*;}
82 + soname=${l%%;*}; l=${l#*;}
83 + rpath=${l%%;*}; l=${l#*;}; [ "${rpath}" = " - " ] && rpath=""
84 + needed=${l%%;*}; l=${l#*;}
85 +
86 + # Infer implicit soname from basename (bug 715162).
87 + if [[ -z ${soname} && $(file "${D%/}${obj}") == *"SB shared object"* ]]; then
88 + soname=${obj##*/}
89 + fi
90
91 - echo "${obj} ${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED
92 - echo "${arch#EM_};${obj};${soname};${rpath};${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
93 - done }
94 + echo "${obj} ${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED
95 + echo "${arch#EM_};${obj};${soname};${rpath};${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
96 + done <<< ${scanelf_output}
97 + fi
98
99 [ -n "${QA_SONAME_NO_SYMLINK}" ] && \
100 echo "${QA_SONAME_NO_SYMLINK}" > \
101 --
102 2.33.0