Skip to contentSkip to conversation

check-bin-arch: add option to exclude files

PATCH New Arnout Vandecappelle (Essensium/Mind) 1 participant 2 messages Apr 10, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 check-bin-arch: add option to exclude files

Some packages will validly install files with a different architecture than the target. We already exclude firmware and /usr/share, but we have at least one case where a shared library is installed for a different arch and it is not wrong. libmpeg2 has code that detects at runtime whether some SPARC instructions are available, which leads to an ELF machine ID of "Sparc v8+" instead of "Sparc".

Therefore, add a new -x option to check-bin-arch to give a list of files to exclude from the check. Note that it is necessary to put spaces around the option argument, otherwise the case statement doesn't match. So "-x ' <exclusions> '", not "-x '<exclusions>'". If called with "-x ' '", nothing will match. This weird syntax doesn't hurt because the script is anyway only meant to be called from within Buildroot (cfr. the fact that it relies on TARGET_DIR to be set in the environment).

In addition, add a per-package variable LIBFOO_CHECK_BIN_ARCH_EXCLUSIONS that is passed to the -x option, and add documentation for this option.

---
I didn't think it was appropriate to split into two patches: in a patch that just adds the -x option to the script, it wouldn't be clear what the purpose is or how it's supposed to be used.

---
 docs/manual/adding-packages-generic.txt | 17 +++++++++++++++++
 package/pkg-generic.mk                  |  3 ++-
 support/scripts/check-bin-arch          | 10 ++++++++--
 3 files changed, 27 insertions(+), 3 deletions(-)
docs/manual/adding-packages-generic.txt +17 -0
index 71e27b6722..c3dbd48c4b 100644
@@ -450,6 +450,23 @@ information is (assuming the package name is +libfoo+) :
   FLAT binary format is only 4k bytes. If the application consumes more stack,
   append the required number here.
 
+* +LIBFOO_CHECK_BIN_ARCH_EXCLUSIONS+ defines a list of files that should be
+  excluded from the target architecture check. Since some packages accidentally
+  installs files that are built for the host into the target directory,
+  Buildroot adds a check that all files in the target directory are really
+  built for the target architecture. However, in rare cases, a package will
+  validly install files for a different (sub)architecture. For example, some
+  libraries have code to dynamically detect the available instructions.
+  Buildroot will then complain with an error like:
++
+---------------------
+ERROR: architecture for "/usr/lib/libfoo.so" is "Sparc v8+", should be "Sparc"
+---------------------
++
+If this is really correct, it is possible to override the check by setting
++LIBFOO_CHECK_BIN_ARCH_EXCLUSIONS+ to a space-separated list of files
+(relative to the target directory) that should not be checked.
+
 The recommended way to define these variables is to use the following
 syntax:
 
package/pkg-generic.mk +2 -1
index 31dbc54557..a6654c8327 100644
@@ -93,7 +93,8 @@ define check_bin_arch
 		support/scripts/check-bin-arch -p $(3) \
 			-l $(BUILD_DIR)/packages-file-list.txt \
 			-r $(TARGET_READELF) \
-			-a $(BR2_READELF_ARCH_NAME))
+			-a $(BR2_READELF_ARCH_NAME) \
+			-x ' $($(call UPPERCASE,$(3))_CHECK_BIN_ARCH_EXCLUSIONS) ')
 endef
 
 GLOBAL_INSTRUMENTATION_HOOKS += check_bin_arch
support/scripts/check-bin-arch +8 -2
index ff974a71bc..72d7436b5a 100755
@@ -1,18 +1,19 @@
 #!/bin/bash
 
-while getopts p:l:r:a: OPT ; do
+while getopts p:l:r:a:x: OPT ; do
 	case "${OPT}" in
 	p) package="${OPTARG}";;
 	l) pkg_list="${OPTARG}";;
 	r) readelf="${OPTARG}";;
 	a) arch_name="${OPTARG}";;
+	x) exclusions="${OPTARG}";;
 	:) error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
 	\?) error "unknown option '%s'\n" "${OPTARG}";;
 	esac
 done
 
 if test -z "${package}" -o -z "${pkg_list}" -o -z "${readelf}" -o -z "${arch_name}" ; then
-	echo "Usage: $0 -p <pkg> -l <pkg-file-list> -r <readelf> -a <arch name>"
+	echo "Usage: $0 -p <pkg> -l <pkg-file-list> -r <readelf> -a <arch name> -x ' <exclusions> '"
 	exit 1
 fi
 
@@ -36,6 +37,11 @@ while read f; do
 		continue
 	fi
 
+	# Skip files that have been excluded explicitly
+	case "${exclusions}" in
+	*\ ${f}\ *) continue;;
+	esac
+
 	# Get architecture using readelf. We pipe through 'head -1' so
 	# that when the file is a static library (.a), we only take
 	# into account the architecture of the first object file.
Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/2 libmpeg2: add check-bin-arch exclusion for Sparc

libmpeg2's configure forces -mcpu=ultrasparc -mvis, which generates Sparcv8+ code. At runtime, however, the library detects if the VIS instructions really are supported or not, so in fact this does work even on < v8 machines.

Our check-bin-arch step will complain about the architecture mismatch with

ERROR: architecture for "/usr/lib/libmpeg2convert.so.0.0.0" is "Sparc v8+", should be "Sparc"
ERROR: architecture for "/usr/lib/libmpeg2.so.0.1.0" is "Sparc v8+", should be "Sparc"

Therefore, explicitly disable the binary arch check for these two libraries when building for Sparc.

Fixes:
http://autobuild.buildroot.net/results/690/690b07b2de0b5f2d2d6e37bcfa7223ee7cc53fe2
http://autobuild.buildroot.net/results/318/318dd1a396b10e7655e0e9b290721fa7bf7a7194
etc.

---
 package/libmpeg2/libmpeg2.mk | 13 +++++++++++++
 1 file changed, 13 insertions(+)
package/libmpeg2/libmpeg2.mk +13 -0
index db9b2f8bbb..d5ce980c99 100644
@@ -20,6 +20,19 @@ else
 LIBMPEG2_CONF_OPTS += --disable-sdl
 endif
 
+ifeq ($(BR2_sparc),y)
+# configure forces -mcpu=ultrasparc -mvis, which generates Sparcv8+ code.
+# This conflicts with the Sparc code that we expect. At runtime, the
+# library detects if the VIS instructions really are supported or not, so
+# in fact this does work even on < v8 machines. Therefore, explicitly
+# disable the binary arch check in that case.
+# When bumping/changing this package, please double-check if it still works
+# correctly for Sparc.
+LIBMPEG2_CHECK_BIN_ARCH_EXCLUSIONS = \
+	/usr/lib/libmpeg2convert.so.0.0.0 \
+	/usr/lib/libmpeg2.so.0.1.0
+endif
+
 ifneq ($(BR2_PACKAGE_LIBMPEG2_BINS),y)
 define LIBMPEG2_REMOVE_BINS
 	rm -f $(addprefix $(TARGET_DIR)/usr/bin/,\
Signature · 1 line
2.11.0