All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yann E. MORIN via buildroot" <buildroot@buildroot.org>
To: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: buildroot@buildroot.org,
	"Arnout Vandecappelle (Essensium/Mind)" <arnout@mind.be>,
	David Laight <David.Laight@aculab.com>
Subject: Re: [Buildroot] [PATCH v2] support/scripts/check-host-libs: add new check on host binaries/libs
Date: Tue, 25 Aug 2026 09:31:58 +0200	[thread overview]
Message-ID: <ao1E7m-2c4BbHUt9@landeda> (raw)
In-Reply-To: <20260824213435.3324692-1-thomas.petazzoni@bootlin.com>

Thomas, All,

On 2026-08-24 23:34 +0200, Thomas Petazzoni spake thusly:
[--SNIP--]
> What it does is that at the end of the build, it verifies that all
> binaries and libraries in $(HOST_DIR) only have shared library
> dependencies on libraries that are in Buildroot $(HOST_DIR), to the
> exception of the C library, for which we of course use the system C
> library.
[--SNIP--]

I was wondering why you would not extend check-host-rpath, see my
tentative, totally untested patch at the end...

Also, check-host-rpath is run after each package install, so it will
catch executables installed without their dependent libraries, should
they later be installed.

Otherwise, some comments below...

> diff --git a/support/scripts/check-host-libs b/support/scripts/check-host-libs
> new file mode 100755
> index 0000000000..79f60024c4
> --- /dev/null
> +++ b/support/scripts/check-host-libs
> @@ -0,0 +1,37 @@
> +#!/bin/bash
> +
> +HOST_DIR=$1

Double-quote variable expansion (shellcheck should have reported that
one, I think).

[--SNIP--]
> +bailout="no"

There is a construct that I tend to use nowadas, which is to use
true/false, rather than 0/1 or yes/no, because that can be reused
without a test;

    success=true
    for loop; do
        if [ conditiion ]; then
            success=false
        fi
    done
    ${success}

[--SNIP--]
> +        case ${lib} in

Ditto, double-quote around variable expansion.

And here's a tentative, totally untested patch to introduce that in
check-host-rpath (indented so that patchwork does not see it):

    diff --git a/support/scripts/check-host-rpath b/support/scripts/check-host-rpath
    index 41aa0aa1ed..e1fdf16829 100755
    --- a/support/scripts/check-host-rpath
    +++ b/support/scripts/check-host-rpath
    @@ -21,6 +21,14 @@ main() {
         while read file; do
             is_elf "${file}" || continue
             elf_needs_rpath "${file}" "${hostdir}" || continue
    +        missing_libs="$(get_missing_libs "${file}" "${hostdir}")"
    +        if [ "${missing_libs}" ]; then
    +            ret=1
    +            printf "***\n"
    +            printf "*** ERROR: package %s uses libs not in HOST_DIR:\n" "${pkg}"
    +            # shellcheck disable=SC2086 # we need the word splitting
    +            printf '  - %s\n' ${missing_libs}
    +        fi
             check_elf_has_rpath "${file}" "${hostdir}" "${perpackagedir}" && continue
             if [ ${ret} -eq 0 ]; then
                 ret=1
    @@ -57,16 +65,44 @@ is_elf() {
     elf_needs_rpath() {
         local file="${1}"
         local hostdir="${2}"
    +
    +    [ -n "$(get_libs "${file}" "${hostdir}")" ]
    +}
    +
    +# This function returns all non-toolchain libs tha tare not in HOST_DIR
    +get_missing_libs() {
    +    local file="${1}"
    +    local hostdir="${2}"
    +    local lib
    +
    +    get_libs "${file}" "${hostdir}" \
    +    | while read lib; do
    +        if [ -not -e "${hostdir}/lib/${lib}" ]; then
    +            printf '%s\n' "${lib}"
    +        fi
    +    done
    +}
    +
    +# This function returns the list of non-toolchain libraries that an ELF
    +# file has as DT_NEEDED
    +get_libs() {
    +    local file="${1}"
    +    local hostdir="${2}"
         local lib

         while read lib; do
    -        [ -e "${hostdir}/lib/${lib}" ] && return 0
    +        case "${lib}" in
    +            libc.so*|libm.so*|libstdc++.so*|libpthread.so*|libgcc_s.so*|libdl.so*|ld-*|libgomp.so*|libcrypt.so*|libcrypto.so*|libatomic.so*|librt.so*|libutil.so*|libresolv.so*)
    +                continue
    +                ;;
    +            *)
    +                printf '%s\n' "${lib}"
    +                ;;
    +        esac
         done < <( readelf -d "${file}" 2>/dev/null                             \
                   |sed -r -e '/^.* \(NEEDED\) .*Shared library: \[(.+)\]$/!d;' \
                          -e 's//\1/;'                                          \
                 )
    -
    -    return 1
     }

     # This function checks whether at least one of the RPATH of the given

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  parent reply	other threads:[~2026-08-25  7:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 21:34 [Buildroot] [PATCH v2] support/scripts/check-host-libs: add new check on host binaries/libs Thomas Petazzoni via buildroot
2026-08-25  7:22 ` Alexis Lothoré via buildroot
2026-08-25  7:31 ` Yann E. MORIN via buildroot [this message]
2026-08-25  8:19   ` Thomas Petazzoni via buildroot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ao1E7m-2c4BbHUt9@landeda \
    --to=buildroot@buildroot.org \
    --cc=David.Laight@aculab.com \
    --cc=arnout@mind.be \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=yann.morin.1998@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.