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

    From Sergei Vyshenski@svysh.fbsd@gmail.com to muc.lists.freebsd.ports on Thu Apr 23 20:13:55 2026
    From Newsgroup: muc.lists.freebsd.ports

    --0000000000009bd2cc065023c6e0
    Content-Type: text/plain; charset="UTF-8"

    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

    --0000000000009bd2cc065023c6e0
    Content-Type: text/html; charset="UTF-8"
    Content-Transfer-Encoding: quoted-printable

    <div dir=3D"ltr">HI,<div><br>PR: 294732<br><a href=3D"https://bugs.freebsd=
    .org/bugzilla/show_bug.cgi?id=3D294732">https://bugs.freebsd.org/bugzilla/s= how_bug.cgi?id=3D294732</a><br><br>Mk/Scripts/qa.sh script in FreeBSD-15.0 =
    is broken. <br>&quot;make stage-qa&quot; silently ignores non-stripped so o= bjects.<br><br>FreeBSD-15.0 has in base a new llvm variant of /usr/bin/read= elf. It differs from the old GNU variant of /usr/bin/readelf in FreeBSD-14.=
    4 or 13.5 at least with these:<br><br>1) Argument separator &quot;--&quot; =
    is not allowed for new readelf and triggers an error;<br>2) When given a li=
    st 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 procee=
    d with the rest of files. This behavior can not be altered with hacks like = &quot;|| :&quot; or &quot;2&gt;/dev/null&quot;.<br><br>This violates work o=
    f stripped() function in Mk/Scripts/qa.sh script in FreeBSD-15 so that &quo= t;make stage-qa&quot; silently ignores non-stripped ELF objects. Silence is=
    caused by suppressing of ALL error messages from readelf within this funct= ion.<br><br>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&#39;s works has been tested with both llvm-readelf (from base 15.0 syst=
    em or from port devel/llvm*) and with GNU-readelf (from base 14.4 system, b= ase 13.5 system, or from port devel/binutils).<br><br>Tested with poudriere=
    jails as follows:<br><br>1)<br>cd /usr/ports/security/p5-Crypt-Argon2<br>m= ake &amp;&amp; make stage-qa<br><br>Should report no issues with non-stripp=
    ed objects.<br><br>2) Repeate step 1 with lines commented out in Makefile:<= br>#post-install:<br># =C2=A0 =C2=A0 =C2=A0 ${STRIP_CMD} ${STAGEDIR}${PREFI= X}/${SITE_ARCH_REL}/auto/Crypt/Argon2/Argon2.so<br><br>Should report an iss=
    ue with a non-stripped object.<br><br>3) Repeate steps 1 and 2 for readelf = from base in poudriere jails <br> with FreeBSD 15.0, 14.4, 13.5.<br>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:<br>RE=3D&quot;/u= sr/local/bin/readelf&quot;<br>Repeate steps 1 and 2 for readelf from ports =
    in poudriere jails <br> with FreeBSD 15.0, 14.4, 13.5.<br>5) Repeate step 4=
    with devel/llvm19 (which includes its own readelf) instead of devel/binuti=
    ls (need to remove it). This last step was not perfomed.</div><div><br></di= v><div>A new version of the function:</div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</div><di= v>stripped() {<br> RE=3D&quot;/usr/bin/readelf&quot;<br> CRY=3D&quot;is not=
    stripped, consider trying INSTALL_TARGET=3Dinstall-strip or using \${STRIP= _CMD}&quot;<br> [ -n &quot;${STRIP}&quot; ] || return 0<br> [ -x ${RE} ] ||=
    return 1 # Allow readelf (llvm or GNU) from base<br> find &quot;${STAGEDIR= }&quot; -type f ! -name &#39;*.a&#39; ! -name &#39;*.o&#39; -print | \<br> =
    while IFS=3D read -r f; do # Allow filenames with spaces or leading minus<b=
    if ${RE} -h &quot;${f}&quot; &gt;/dev/null 2&gt;&amp;1; then # Consider=
    only ELFs<br> SECTIONS=3D&quot;$(${RE} -S &quot;${f}&quot; 2&gt;/dev/nul=
    l)&quot; # Read all sections data from ELF<br> LINE=3D&quot;$(echo &quot;=
    ${SECTIONS}&quot; | grep &#39;[[:space:]]\.debug_info[[:space:]]*PROGBITS&#= 39;)&quot;<br> # Test for exit code of grep in a pipe is fragile when sw=
    itching<br> # of readelf variants and of FreeBSD releases.<br> # Inst=
    ead, test for output of grep is robust.<br> # LINE may have debug flag a=
    s found by grep and<br> # is empty for stripped ELF object<br> LENGTH=
    =3D${#LINE} # Would be zero for stripped ELF object<br> if [ ${LENGTH} -g=
    e 50 ]; then # Found non-stripped ELF object<br> warn &quot;&#39;${f#${S=
    TAGEDIR}${PREFIX}/}&#39; ${CRY}&quot;<br> fi<br> fi<br> done<br>}<br>=3D=
    =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D</div><div>it works with a new readelf (which is=
    a llvm variant) from 15.0 base, and with an old readelf (which is a GNU va= riant) from 14.4 or 13.5 base.</div><div><br></div><div>Regards, Sergei</di= v><div><br></div></div>

    --0000000000009bd2cc065023c6e0--


    --
    Posted automagically by a mail2news gateway at muc.de e.V.
    Please direct questions, flames, donations, etc. to news-admin@muc.de
    --- Synchronet 3.21f-Linux NewsLink 1.2