Mk/Scripts/qa.sh script in FreeBSD-15.0 is broken

Sergei Vyshenski <[email protected]>
Newsgroups gmane.os.freebsd.devel.ports
Message-ID <CAHU0Y-7SHb9gbY--fRQy4J7wA6x8nAWyqLLcTPcMBkXDHT5JNA@mail.gmail.com>
HI,

PR: 294732
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=294732

Mk/Scripts/qa.sh script in FreeBSD-15.0 is broken.
"make stage-qa" silently ignores non-stripped so objects.

FreeBSD-15.0 has in base a new llvm variant of /usr/bin/readelf. It differs
from the old GNU variant of /usr/bin/readelf in FreeBSD-14.4 or 13.5 at
least with these:

1) Argument separator "--" is not allowed for new readelf and triggers an
error;
2) When given a list of files to read, and some file triggers an error
(e.g. the file is not an ELF object), new readelf immediately terminates
work and does not proceed with the rest of files. This behavior can not be
altered with hacks like "|| :" or "2>/dev/null".

This violates work of stripped() function in Mk/Scripts/qa.sh script in
FreeBSD-15 so that "make stage-qa" silently ignores non-stripped ELF
objects. Silence is caused by suppressing of ALL error messages from
readelf within this function.

Proposed here is a working version of stripped() function which is easy
both to understand and maintain. It handles filenames with spaces or with
leading minus. To be on a safe side with possible future evolution, it's
works has been tested with both llvm-readelf (from base 15.0 system or from
port devel/llvm*) and with GNU-readelf (from base 14.4 system, base 13.5
system, or from port devel/binutils).

Tested with poudriere jails as follows:

1)
cd /usr/ports/security/p5-Crypt-Argon2
make && make stage-qa

Should report no issues with non-stripped objects.

2) Repeate step 1 with lines commented out in Makefile:
#post-install:
#       ${STRIP_CMD}
${STAGEDIR}${PREFIX}/${SITE_ARCH_REL}/auto/Crypt/Argon2/Argon2.so

Should report an issue with a non-stripped object.

3) Repeate steps 1 and 2 for readelf from base in poudriere jails
with FreeBSD 15.0, 14.4, 13.5.
4) Add devel/binutils (which includes its own readelf) to DEPENDS of
Makefile, and edit Mk/Scripts/qa.sh so that it uses readelf from ports:
RE="/usr/local/bin/readelf"
Repeate steps 1 and 2 for readelf from ports in poudriere jails
with FreeBSD 15.0, 14.4, 13.5.
5) Repeate step 4 with devel/llvm19 (which includes its own readelf)
instead of devel/binutils (need to remove it). This last step was not
perfomed.

A new version of the function:
===============================
stripped() {
RE="/usr/bin/readelf"
CRY="is not stripped, consider trying INSTALL_TARGET=install-strip or using
\${STRIP_CMD}"
[ -n "${STRIP}" ] || return 0
[ -x ${RE} ] || return 1 # Allow readelf (llvm or GNU) from base
find "${STAGEDIR}" -type f ! -name '*.a' ! -name '*.o' -print | \
while IFS= read -r f; do # Allow filenames with spaces or leading minus
if ${RE} -h "${f}" >/dev/null 2>&1; then # Consider only ELFs
SECTIONS="$(${RE} -S "${f}" 2>/dev/null)" # Read all sections data from ELF
LINE="$(echo "${SECTIONS}" | grep
'[[:space:]]\.debug_info[[:space:]]*PROGBITS')"
# Test for exit code of grep in a pipe is fragile when switching
# of readelf variants and of FreeBSD releases.
# Instead, test for output of grep is robust.
# LINE may have debug flag as found by grep and
# is empty for stripped ELF object
LENGTH=${#LINE} # Would be zero for stripped ELF object
if [ ${LENGTH} -ge 50 ]; then # Found non-stripped ELF object
warn "'${f#${STAGEDIR}${PREFIX}/}' ${CRY}"
fi
fi
done
}
===================================
it works with a new readelf (which is a llvm variant) from 15.0 base, and
with an old readelf (which is a GNU variant) from 14.4 or 13.5 base.

Regards, Sergei
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.