Gentoo Archives: gentoo-commits

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