Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/4] support/scripts/check-host-bins: check shared libraries
@ 2026-09-09 12:39 Matthew Weber
  2026-09-09 12:39 ` [Buildroot] [PATCH 2/4] support/scripts/check-host-bins: report RPATH errors after library errors Matthew Weber
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Matthew Weber @ 2026-09-09 12:39 UTC (permalink / raw)
  To: buildroot; +Cc: thomas.petazzoni, yann.morin.1998, Matthew Weber

Shared libraries installed in HOST_DIR/lib do not have a program interpreter,
so they were skipped by the existing ELF check. Detect ET_DYN ELF files as
well as executables and scan HOST_DIR/lib.

Accept $ORIGIN as a valid RPATH for shared libraries in HOST_DIR/lib, where
it resolves to the directory containing the library.

Assisted-by: GitHub Copilot [VS Code]
Signed-off-by: Matthew Weber <matt@thewebers.ws>
---
Depends on v3 of the check-host-bins series:
https://patchwork.ozlabs.org/project/buildroot/list/?series=520240

The test script is available at:
https://gist.github.com/matthew-l-weber/34fae15a4319a81462961eadf0e31164

Review of v3 found that its new host-library check scanned only
HOST_DIR/bin and HOST_DIR/sbin. Its ELF test also required a program
interpreter, which excludes ET_DYN shared libraries in HOST_DIR/lib.

Test 3g builds a shared library in a synthetic HOST_DIR/lib with a
DT_NEEDED entry for a second library that is deliberately not installed in
HOST_DIR/lib. It verifies that check-host-bins scans the shared object and
reports the missing dependency.

Test 3j builds a shared library whose dependency is installed in the same
synthetic HOST_DIR/lib and whose RPATH is $ORIGIN. It verifies that this
valid RPATH does not produce an RPATH diagnostic.

 support/scripts/check-host-bins | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/support/scripts/check-host-bins b/support/scripts/check-host-bins
index 098e35e592..cddf6a08b2 100755
--- a/support/scripts/check-host-bins
+++ b/support/scripts/check-host-bins
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 
-# This script scans $(HOST_DIR)/{bin,sbin} for all ELF files, and checks
+# This script scans $(HOST_DIR)/{bin,sbin,lib} for all ELF files, and checks
 # they have an RPATH to $(HOST_DIR)/lib if they need libraries from
 # there.
 
@@ -36,16 +36,20 @@ main() {
             printf "*** ERROR: package %s installs executables without proper RPATH:\n" "${pkg}"
         fi
         printf "***   %s\n" "${file}"
-    done < <( find "${hostdir}"/{bin,sbin} -type f 2>/dev/null )
+    done < <( find "${hostdir}"/{bin,sbin,lib} -type f 2>/dev/null )
 
     return ${ret}
 }
 
 is_elf() {
     local f="${1}"
+    local magic
 
-    readelf -l "${f}" 2>/dev/null \
-    |grep -E 'Requesting program interpreter:' >/dev/null 2>&1
+    { read -r -N 4 magic < "${f}"; } 2>/dev/null \
+        && [ "${magic}" = $'\x7fELF' ] || return 1
+
+    readelf -h "${f}" 2>/dev/null \
+        | grep -qE 'Type:[[:space:]]+(EXEC|DYN)'
 }
 
 # This function tells whether a given ELF executable (first argument)
@@ -129,6 +133,7 @@ check_elf_has_rpath() {
             dir="$( sed -r -e 's:/+:/:g; s:/$::;' <<<"${dir}" )"
             [ "${dir}" = "${hostdir}/lib" ] && return 0
             [ "${dir}" = "\$ORIGIN/../lib" ] && return 0
+            [ "${dir}" = "\$ORIGIN" ] && [[ "${file}" == "${hostdir}/lib/"* ]] && return 0
             # This check is done even for builds where
             # BR2_PER_PACKAGE_DIRECTORIES is disabled. In this case,
             # PER_PACKAGE_DIR and therefore ${perpackagedir} points to
-- 
2.39.5

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-09-09 13:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-09 12:39 [Buildroot] [PATCH 1/4] support/scripts/check-host-bins: check shared libraries Matthew Weber
2026-09-09 12:39 ` [Buildroot] [PATCH 2/4] support/scripts/check-host-bins: report RPATH errors after library errors Matthew Weber
2026-09-09 13:23   ` Thomas Petazzoni via buildroot
2026-09-09 12:39 ` [Buildroot] [PATCH 3/4] support/scripts/check-host-bins: skip RPATH check for missing libraries Matthew Weber
2026-09-09 13:33   ` Thomas Petazzoni via buildroot
2026-09-09 12:39 ` [Buildroot] [PATCH 4/4] support/scripts/check-host-bins: allow musl libc names Matthew Weber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox