All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option
@ 2017-03-19 13:07 Thomas Petazzoni
  2017-03-19 13:07 ` [Buildroot] [PATCH v4 2/2] Makefile: add check of binaries architecture Thomas Petazzoni
  2017-03-20 21:26 ` [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option Thomas Petazzoni
  0 siblings, 2 replies; 10+ messages in thread
From: Thomas Petazzoni @ 2017-03-19 13:07 UTC (permalink / raw)
  To: buildroot

This config option corresponds to the string returned by readelf for
the "Machine" field of the ELF header. It will be used to check if the
architecture of binaries built by Buildroot match the target
architecture.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
Changes since v3:
 - None

Changes since v2:
 - Improve comment above BR2_READELF_ARCH_NAME to explain that it is the
   value of the "Machine:" field in readelf output, and point to the
   readelf source code for the list of possible values.

Changes since v1:
 - None
---
 arch/Config.in            | 6 ++++++
 arch/Config.in.arc        | 3 +++
 arch/Config.in.arm        | 4 ++++
 arch/Config.in.bfin       | 3 +++
 arch/Config.in.csky       | 2 ++
 arch/Config.in.m68k       | 3 +++
 arch/Config.in.microblaze | 3 +++
 arch/Config.in.mips       | 3 +++
 arch/Config.in.nios2      | 3 +++
 arch/Config.in.or1k       | 3 +++
 arch/Config.in.powerpc    | 4 ++++
 arch/Config.in.sh         | 3 +++
 arch/Config.in.sparc      | 4 ++++
 arch/Config.in.x86        | 4 ++++
 arch/Config.in.xtensa     | 3 +++
 15 files changed, 51 insertions(+)

diff --git a/arch/Config.in b/arch/Config.in
index 65a33fb..50377a9 100644
--- a/arch/Config.in
+++ b/arch/Config.in
@@ -292,6 +292,12 @@ config BR2_GCC_TARGET_MODE
 config BR2_BINFMT_SUPPORTS_SHARED
 	bool
 
+# Must match the name of the architecture from readelf point of view,
+# i.e the "Machine:" field of readelf output. See get_machine_name()
+# in binutils/readelf.c for the list of possible values.
+config BR2_READELF_ARCH_NAME
+	string
+
 # Set up target binary format
 choice
 	prompt "Target Binary Format"
diff --git a/arch/Config.in.arc b/arch/Config.in.arc
index 7d341f3..dcdba68 100644
--- a/arch/Config.in.arc
+++ b/arch/Config.in.arc
@@ -38,6 +38,9 @@ config BR2_GCC_TARGET_CPU
 	default "arc700" if BR2_arc770d
 	default "archs"	 if BR2_archs38
 
+config BR2_READELF_ARCH_NAME
+	default "ARCv2"
+
 choice
 	prompt "MMU Page Size"
 	default BR2_ARC_PAGE_SIZE_8K
diff --git a/arch/Config.in.arm b/arch/Config.in.arm
index 2617976..f910364 100644
--- a/arch/Config.in.arm
+++ b/arch/Config.in.arm
@@ -568,3 +568,7 @@ config BR2_GCC_TARGET_FLOAT_ABI
 config BR2_GCC_TARGET_MODE
 	default "arm"		if BR2_ARM_INSTRUCTIONS_ARM
 	default "thumb"		if BR2_ARM_INSTRUCTIONS_THUMB || BR2_ARM_INSTRUCTIONS_THUMB2
+
+config BR2_READELF_ARCH_NAME
+	default "ARM"		if BR2_arm || BR2_armeb
+	default "AArch64"	if BR2_aarch64 || BR2_aarch64_be
diff --git a/arch/Config.in.bfin b/arch/Config.in.bfin
index 9f7056a..90e4ab9 100644
--- a/arch/Config.in.bfin
+++ b/arch/Config.in.bfin
@@ -105,3 +105,6 @@ config BR2_GCC_TARGET_CPU_REVISION
 	  value of the -mcpu option. For example, if the selected CPU is
 	  bf609, and then selected CPU revision is "0.0", then gcc will
 	  receive the -mcpu=bf609-0.0 option.
+
+config BR2_READELF_ARCH_NAME
+	default "Analog Devices Blackfin"
diff --git a/arch/Config.in.csky b/arch/Config.in.csky
index 7029c60..e88e4e2 100644
--- a/arch/Config.in.csky
+++ b/arch/Config.in.csky
@@ -44,3 +44,5 @@ config BR2_GCC_TARGET_CPU
 	default "ck810f"	if (BR2_ck810 &&  BR2_CSKY_FPU && !BR2_CSKY_DSP)
 	default "ck810ef"	if (BR2_ck810 &&  BR2_CSKY_FPU &&  BR2_CSKY_DSP)
 
+config BR2_READELF_ARCH_NAME
+	default "CSKY"
diff --git a/arch/Config.in.m68k b/arch/Config.in.m68k
index ced871f..c56031c 100644
--- a/arch/Config.in.m68k
+++ b/arch/Config.in.m68k
@@ -35,3 +35,6 @@ endchoice
 config BR2_GCC_TARGET_CPU
 	default "68040"		if BR2_m68k_68040
 	default "5208"		if BR2_m68k_cf5208
+
+config BR2_READELF_ARCH_NAME
+	default "MC68000"
diff --git a/arch/Config.in.microblaze b/arch/Config.in.microblaze
index 2d4c1fe..042712a 100644
--- a/arch/Config.in.microblaze
+++ b/arch/Config.in.microblaze
@@ -6,6 +6,9 @@ config BR2_ENDIAN
 	default "LITTLE" if BR2_microblazeel
 	default "BIG"	 if BR2_microblazebe
 
+config BR2_READELF_ARCH_NAME
+	default "Xilinx MicroBlaze"
+
 config BR2_microblaze
 	bool
 	default y if BR2_microblazeel || BR2_microblazebe
diff --git a/arch/Config.in.mips b/arch/Config.in.mips
index ce41e9e..22819d0 100644
--- a/arch/Config.in.mips
+++ b/arch/Config.in.mips
@@ -161,3 +161,6 @@ config BR2_GCC_TARGET_ABI
 	default "32"		if BR2_MIPS_OABI32
 	default "n32"		if BR2_MIPS_NABI32
 	default "64"		if BR2_MIPS_NABI64
+
+config BR2_READELF_ARCH_NAME
+	default "MIPS R3000"
diff --git a/arch/Config.in.nios2 b/arch/Config.in.nios2
index ed63898..7466331 100644
--- a/arch/Config.in.nios2
+++ b/arch/Config.in.nios2
@@ -3,3 +3,6 @@ config BR2_ARCH
 
 config BR2_ENDIAN
 	default "LITTLE"
+
+config BR2_READELF_ARCH_NAME
+	default "Altera Nios II"
diff --git a/arch/Config.in.or1k b/arch/Config.in.or1k
index dba64a6..b31ab3e 100644
--- a/arch/Config.in.or1k
+++ b/arch/Config.in.or1k
@@ -3,3 +3,6 @@ config BR2_ARCH
 
 config BR2_ENDIAN
 	default "BIG"
+
+config BR2_READELF_ARCH_NAME
+	default "OpenRISC 1000"
diff --git a/arch/Config.in.powerpc b/arch/Config.in.powerpc
index 09ac794..0968412 100644
--- a/arch/Config.in.powerpc
+++ b/arch/Config.in.powerpc
@@ -212,3 +212,7 @@ config BR2_GCC_TARGET_ABI
 	default "no-spe"		if BR2_PPC_ABI_no-spe
 	default "ibmlongdouble"		if BR2_PPC_ABI_ibmlongdouble
 	default "ieeelongdouble"	if BR2_PPC_ABI_ieeelongdouble
+
+config BR2_READELF_ARCH_NAME
+	default "PowerPC"	if BR2_powerpc
+	default "PowerPC64"	if BR2_powerpc64 || BR2_powerpc64le
diff --git a/arch/Config.in.sh b/arch/Config.in.sh
index 4705212..deb7244 100644
--- a/arch/Config.in.sh
+++ b/arch/Config.in.sh
@@ -27,3 +27,6 @@ config BR2_ARCH
 config BR2_ENDIAN
 	default "LITTLE"	if BR2_sh4 || BR2_sh4a
 	default "BIG"		if BR2_sh2a || BR2_sh4eb || BR2_sh4aeb
+
+config BR2_READELF_ARCH_NAME
+	default "Renesas / SuperH SH"
diff --git a/arch/Config.in.sparc b/arch/Config.in.sparc
index 307540f..9b6a6aa 100644
--- a/arch/Config.in.sparc
+++ b/arch/Config.in.sparc
@@ -28,3 +28,7 @@ config BR2_GCC_TARGET_CPU
 	default "leon3"		if BR2_sparc_leon3
 	default "v8"		if BR2_sparc_v8
 	default "ultrasparc"	if BR2_sparc_v9
+
+config BR2_READELF_ARCH_NAME
+	default "Sparc"		if BR2_sparc
+	default "Sparc v9"	if BR2_sparc64
diff --git a/arch/Config.in.x86 b/arch/Config.in.x86
index efa9567..0d9e93b 100644
--- a/arch/Config.in.x86
+++ b/arch/Config.in.x86
@@ -275,3 +275,7 @@ config BR2_GCC_TARGET_ARCH
 	default "c3"		if BR2_x86_c3
 	default "c3-2"		if BR2_x86_c32
 	default "geode"		if BR2_x86_geode
+
+config BR2_READELF_ARCH_NAME
+	default "Intel 80386"			if BR2_i386
+	default "Advanced Micro Devices X86-64" if BR2_x86_64
diff --git a/arch/Config.in.xtensa b/arch/Config.in.xtensa
index fcb3dc9..88dbe18 100644
--- a/arch/Config.in.xtensa
+++ b/arch/Config.in.xtensa
@@ -54,3 +54,6 @@ config BR2_ENDIAN
 
 config BR2_ARCH
 	default "xtensa"	if BR2_xtensa
+
+config BR2_READELF_ARCH_NAME
+	default "Tensilica Xtensa Processor"
-- 
2.7.4

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

* [Buildroot] [PATCH v4 2/2] Makefile: add check of binaries architecture
  2017-03-19 13:07 [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option Thomas Petazzoni
@ 2017-03-19 13:07 ` Thomas Petazzoni
  2017-03-20 21:26 ` [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option Thomas Petazzoni
  1 sibling, 0 replies; 10+ messages in thread
From: Thomas Petazzoni @ 2017-03-19 13:07 UTC (permalink / raw)
  To: buildroot

As shown recently by the firejail example, it is easy to miss that a
package builds and installs binaries without actually cross-compiling
them: they are built for the host architecture instead of the target
architecture.

This commit adds a small helper script, check-bin-arch, called as a
GLOBAL_INSTRUMENTATION_HOOKS at the end of the target installation of
each package, to verify that the files installed by this package have
been built for the correct architecture.

Being called as a GLOBAL_INSTRUMENTATION_HOOKS allows the build to error
out right after the installation of the faulty package, and therefore
get autobuilder error detection properly assigned to this specific
package.

Example output with the firejail package enabled, when building for an
ARM target:

ERROR: architecture for ./usr/lib/firejail/libconnect.so is Advanced Micro Devices X86-64, should be ARM
ERROR: architecture for ./usr/bin/firejail is Advanced Micro Devices X86-64, should be ARM
ERROR: architecture for ./usr/lib/firejail/libtrace.so is Advanced Micro Devices X86-64, should be ARM
ERROR: architecture for ./usr/lib/firejail/libtracelog.so is Advanced Micro Devices X86-64, should be ARM
ERROR: architecture for ./usr/lib/firejail/ftee is Advanced Micro Devices X86-64, should be ARM
ERROR: architecture for ./usr/lib/firejail/faudit is Advanced Micro Devices X86-64, should be ARM
ERROR: architecture for ./usr/bin/firemon is Advanced Micro Devices X86-64, should be ARM
ERROR: architecture for ./usr/bin/firecfg is Advanced Micro Devices X86-64, should be ARM

Many thanks to Yann E. Morin and Arnout Vandecappelle for their reviews
and suggestions.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
Changes since v4:
 - Use arguments with flags in the script, as suggested by Arnout.
 - Pipe the readelf output to head -1, so that with static libs we only
   take into account the architecture of the first object file (assuming
   all object files in a static library will have the same
   architecture). Suggested by Arnout.
 - Change error message to not mention the name of the package, since we
   know abort the build during the package installation step. Suggested
   by Arnout.

Changes since v3:
 - Pass TARGET_READELF instead of TARGET_CROSS, suggested by Arnout
 - Pass BR2_READELF_ARCH_NAME to the script, instead of parsing the BR
   config file. Suggested by Yann.
 - Use LC_ALL=C when calling readelf, to avoid surprises. Suggested by
   Yann.
 - Reword the error message, according to Yann suggestion.

Changes since v2:
 - Moved as a per-package check, so that we detect the faulty package
   earlier, and get correct autobuilder notifications.
 - Use TARGET_DIR from the environment and use BR2_CONFIG to retrieve
   the value of BR2_READELF_ARCH_NAME.
 - Skip firmware files in /lib/firmware and /usr/lib/firmware.
 - Simply ignore files for which readelf returned an empty Machine
   field, as a way to quickly detect non-ELF files.

Changes since v1:
 - Following Yann E. Morin's comment, restrict the check to bin, lib,
   sbin, usr/bin, usr/lib and usr/sbin, in order to avoid matching
   firmware files that could use the ELF format but be targeted for
   other architectures.
---
 package/pkg-generic.mk         | 11 +++++++++
 support/scripts/check-bin-arch | 52 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100755 support/scripts/check-bin-arch

diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
index e8a8021..dd8a1e2 100644
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -87,6 +87,17 @@ define step_pkg_size
 endef
 GLOBAL_INSTRUMENTATION_HOOKS += step_pkg_size
 
+# Relies on step_pkg_size, so must be after
+define check_bin_arch
+	$(if $(filter end-install-target,$(1)-$(2)),\
+		support/scripts/check-bin-arch -p $(3) \
+			-l $(BUILD_DIR)/packages-file-list.txt \
+			-r $(TARGET_READELF) \
+			-a $(BR2_READELF_ARCH_NAME))
+endef
+
+GLOBAL_INSTRUMENTATION_HOOKS += check_bin_arch
+
 # This hook checks that host packages that need libraries that we build
 # have a proper DT_RPATH or DT_RUNPATH tag
 define check_host_rpath
diff --git a/support/scripts/check-bin-arch b/support/scripts/check-bin-arch
new file mode 100755
index 0000000..2c619ad
--- /dev/null
+++ b/support/scripts/check-bin-arch
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+while getopts p:l:r:a: OPT ; do
+	case "${OPT}" in
+	p) package="${OPTARG}";;
+	l) pkg_list="${OPTARG}";;
+	r) readelf="${OPTARG}";;
+	a) arch_name="${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>"
+	exit 1
+fi
+
+exitcode=0
+
+pkg_files=$(sed -r -e "/^${package},(.+)$/!d; s//\1/;" ${pkg_list})
+
+for f in ${pkg_files} ; do
+	# Skip firmware files, they could be ELF files for other
+	# architectures
+	if [[ "${f}" =~ ^\./(usr/)?lib/firmware/.* ]]; then
+		continue
+	fi
+
+	# 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.
+	arch=$(LC_ALL=C ${readelf} -h "${TARGET_DIR}/${f}" 2>&1 | \
+		       sed -r -e '/^  Machine: +(.+)/!d; s//\1/;' | head -1)
+
+	# If no architecture found, assume it was not an ELF file
+	if test "${arch}" = "" ; then
+		continue
+	fi
+
+	# Architecture is correct
+	if test "${arch}" = "${arch_name}" ; then
+		continue
+	fi
+
+	printf 'ERROR: architecture for %s is %s, should be %s\n' \
+	       "${f}" "${arch}" "${arch_name}"
+
+	exitcode=1
+done
+
+exit ${exitcode}
-- 
2.7.4

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

* [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option
  2017-03-19 13:07 [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option Thomas Petazzoni
  2017-03-19 13:07 ` [Buildroot] [PATCH v4 2/2] Makefile: add check of binaries architecture Thomas Petazzoni
@ 2017-03-20 21:26 ` Thomas Petazzoni
  2017-04-02 10:38   ` Bernd Kuhls
  1 sibling, 1 reply; 10+ messages in thread
From: Thomas Petazzoni @ 2017-03-20 21:26 UTC (permalink / raw)
  To: buildroot

Hello,

On Sun, 19 Mar 2017 14:07:51 +0100, Thomas Petazzoni wrote:
> This config option corresponds to the string returned by readelf for
> the "Machine" field of the ELF header. It will be used to check if the
> architecture of binaries built by Buildroot match the target
> architecture.
> 
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> ---
> Changes since v3:
>  - None

I've applied both patches to master. Let's see if the autobuilders blow
up now :)

Best regards,

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

* [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option
  2017-03-20 21:26 ` [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option Thomas Petazzoni
@ 2017-04-02 10:38   ` Bernd Kuhls
  2017-04-02 12:30     ` Thomas Petazzoni
  0 siblings, 1 reply; 10+ messages in thread
From: Bernd Kuhls @ 2017-04-02 10:38 UTC (permalink / raw)
  To: buildroot

Am Mon, 20 Mar 2017 22:26:56 +0100 schrieb Thomas Petazzoni:

> Hello,
> 
> On Sun, 19 Mar 2017 14:07:51 +0100, Thomas Petazzoni wrote:
>> This config option corresponds to the string returned by readelf for
>> the "Machine" field of the ELF header. It will be used to check if the
>> architecture of binaries built by Buildroot match the target
>> architecture.
>> 
>> Signed-off-by: Thomas Petazzoni
>> <thomas.petazzoni@free-electrons.com>
>> ---
>> Changes since v3:
>>  - None
> 
> I've applied both patches to master. Let's see if the autobuilders blow
> up now :)
> 
> Best regards,
> 
> Thomas

Hi Thomas,

Sparc v8 sees some build errors:

http://autobuild.buildroot.net/results/de7/
de7079b89fda1dd47e52619a644f23c4f4986b2c//

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"

http://autobuild.buildroot.net/results/f96/
f96c30c5c398db1ba561740ae64e922cd4f8a524//

ERROR: architecture for "/usr/lib/libopenblas_sparcp-r0.2.19.dev.so" is 
"Sparc v8+", should be "Sparc"

Patching arch/Config.in.sparc like this

@@ -30,5 +30,6 @@ config BR2_GCC_TARGET_CPU
        default "ultrasparc"    if BR2_sparc_v9
 
 config BR2_READELF_ARCH_NAME
+       default "Sparc v8+"     if BR2_sparc_v8
        default "Sparc"         if BR2_sparc
        default "Sparc v9"      if BR2_sparc64

does not fix the problem however:

>>> toolchain-external-custom  Copying external toolchain libraries to 
target...
ERROR: architecture for "/lib/libgcc_s.so.1" is "Sparc", should be "Sparc 
v8+"
ERROR: architecture for "/lib/libuClibc-1.0.22.so" is "Sparc", should be 
"Sparc v8+"
ERROR: architecture for "/lib/ld-uClibc-1.0.22.so" is "Sparc", should be 
"Sparc v8+"
ERROR: architecture for "/usr/lib/libstdc++.so.6.0.21" is "Sparc", should 
be "Sparc v8+"
ERROR: architecture for "/lib/libatomic.so.1.1.0" is "Sparc", should be 
"Sparc v8+"

Tested with http://autobuild.buildroot.net/results/de7/
de7079b89fda1dd47e52619a644f23c4f4986b2c/defconfig

Regards, Bernd

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

* [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option
  2017-04-02 10:38   ` Bernd Kuhls
@ 2017-04-02 12:30     ` Thomas Petazzoni
  2017-04-03 14:24       ` Arnout Vandecappelle
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Petazzoni @ 2017-04-02 12:30 UTC (permalink / raw)
  To: buildroot

Hello,

On Sun, 02 Apr 2017 12:38:24 +0200, Bernd Kuhls wrote:

> http://autobuild.buildroot.net/results/de7/
> de7079b89fda1dd47e52619a644f23c4f4986b2c//
> 
> 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"
> 
> http://autobuild.buildroot.net/results/f96/
> f96c30c5c398db1ba561740ae64e922cd4f8a524//
> 
> ERROR: architecture for "/usr/lib/libopenblas_sparcp-r0.2.19.dev.so" is 
> "Sparc v8+", should be "Sparc"
> 
> Patching arch/Config.in.sparc like this
> 
> @@ -30,5 +30,6 @@ config BR2_GCC_TARGET_CPU
>         default "ultrasparc"    if BR2_sparc_v9
>  
>  config BR2_READELF_ARCH_NAME
> +       default "Sparc v8+"     if BR2_sparc_v8
>         default "Sparc"         if BR2_sparc
>         default "Sparc v9"      if BR2_sparc64

No, that's not the proper fix.

I had a look at the libmpeg2 problem yesterday. The issue is that the
configure.ac script forces -mcpu=ultrasparc -mvis, which generates
Sparcv8+ code. However, simply removing those flags doesn't work, as it
then tries to build some code that really needs the Sparc VIS
instructions.

Apparently, the libmpeg2 code is smart enough to decide at runtime if
the VIS instructions are supported or not, so even though the code is
for Sparc v8+, it's safe to run it on older Sparc machines. That's
clearly a case where the check we make on the file architecture is a
bit annoying.

I don't yet have a good solution for this case. Suggestions welcome.

Best regards,

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option
  2017-04-02 12:30     ` Thomas Petazzoni
@ 2017-04-03 14:24       ` Arnout Vandecappelle
  2017-04-03 15:08         ` Thomas Petazzoni
  0 siblings, 1 reply; 10+ messages in thread
From: Arnout Vandecappelle @ 2017-04-03 14:24 UTC (permalink / raw)
  To: buildroot



On 02-04-17 14:30, Thomas Petazzoni wrote:
> Hello,
> 
> On Sun, 02 Apr 2017 12:38:24 +0200, Bernd Kuhls wrote:
> 
>> http://autobuild.buildroot.net/results/de7/
>> de7079b89fda1dd47e52619a644f23c4f4986b2c//
>>
>> 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"
>>
>> http://autobuild.buildroot.net/results/f96/
>> f96c30c5c398db1ba561740ae64e922cd4f8a524//
>>
>> ERROR: architecture for "/usr/lib/libopenblas_sparcp-r0.2.19.dev.so" is 
>> "Sparc v8+", should be "Sparc"
>>
>> Patching arch/Config.in.sparc like this
>>
>> @@ -30,5 +30,6 @@ config BR2_GCC_TARGET_CPU
>>         default "ultrasparc"    if BR2_sparc_v9
>>  
>>  config BR2_READELF_ARCH_NAME
>> +       default "Sparc v8+"     if BR2_sparc_v8
>>         default "Sparc"         if BR2_sparc
>>         default "Sparc v9"      if BR2_sparc64
> 
> No, that's not the proper fix.
> 
> I had a look at the libmpeg2 problem yesterday. The issue is that the
> configure.ac script forces -mcpu=ultrasparc -mvis, which generates
> Sparcv8+ code. However, simply removing those flags doesn't work, as it
> then tries to build some code that really needs the Sparc VIS
> instructions.
> 
> Apparently, the libmpeg2 code is smart enough to decide at runtime if
> the VIS instructions are supported or not, so even though the code is
> for Sparc v8+, it's safe to run it on older Sparc machines. That's
> clearly a case where the check we make on the file architecture is a
> bit annoying.

 So, let me get this clear: libmpeg2 actually does the right thing, and it is in
fact possible to link the Sparc v8+ library with Sparc libraries?


 In that case, I guess we should extend check-bin-arch to support regexes for
the expected arch, and set the BR2_sparc arch to "Sparc( v8+)?".


 Regards,
 Arnout

> 
> I don't yet have a good solution for this case. Suggestions welcome.
> 
> Best regards,
> 
> Thomas
> 

-- 
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF

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

* [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option
  2017-04-03 14:24       ` Arnout Vandecappelle
@ 2017-04-03 15:08         ` Thomas Petazzoni
  2017-04-10 15:49           ` Arnout Vandecappelle
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Petazzoni @ 2017-04-03 15:08 UTC (permalink / raw)
  To: buildroot

Hello,

On Mon, 3 Apr 2017 16:24:55 +0200, Arnout Vandecappelle wrote:

>  So, let me get this clear: libmpeg2 actually does the right thing, and it is in
> fact possible to link the Sparc v8+ library with Sparc libraries?

It's not so much that you can link Sparc v8+ code with Sparc code that
is important:  you can link ARMv5 and ARMv7 code together, but running
ARMv7 code on ARMv5 still doesn't make sense.

And "Sparc v8+" on regular Sparc like we support is not going to work.
However, what is important here is that libmpeg is smart enough to not
call into the Sparc v8+ code if we're not on Sparc v8+.

It's exactly like having SSE3 code built-in, and testing at runtime if
SSE3 is enabled before calling the SSE3 specific code. In a Buildroot
context where we normally build for specifically the target system,
this shouldn't be necessary, but some software packages do this anyway.

>  In that case, I guess we should extend check-bin-arch to support regexes for
> the expected arch, and set the BR2_sparc arch to "Sparc( v8+)?".

Not as simple: another package may generate Sparc v8+ code, and this
would be bogus.

So, in the context of Buildroot, I believe we should rather patch
libmpeg to not generate the Sparc v8+ code if we are not on Sparc v8+.

Best regards,

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option
  2017-04-03 15:08         ` Thomas Petazzoni
@ 2017-04-10 15:49           ` Arnout Vandecappelle
  0 siblings, 0 replies; 10+ messages in thread
From: Arnout Vandecappelle @ 2017-04-10 15:49 UTC (permalink / raw)
  To: buildroot



On 03-04-17 17:08, Thomas Petazzoni wrote:
> Hello,
> 
> On Mon, 3 Apr 2017 16:24:55 +0200, Arnout Vandecappelle wrote:
> 
>>  So, let me get this clear: libmpeg2 actually does the right thing, and it is in
>> fact possible to link the Sparc v8+ library with Sparc libraries?
> 
> It's not so much that you can link Sparc v8+ code with Sparc code that
> is important:  you can link ARMv5 and ARMv7 code together, but running
> ARMv7 code on ARMv5 still doesn't make sense.
> 
> And "Sparc v8+" on regular Sparc like we support is not going to work.
> However, what is important here is that libmpeg is smart enough to not
> call into the Sparc v8+ code if we're not on Sparc v8+.
> 
> It's exactly like having SSE3 code built-in, and testing at runtime if
> SSE3 is enabled before calling the SSE3 specific code. In a Buildroot
> context where we normally build for specifically the target system,
> this shouldn't be necessary, but some software packages do this anyway.
> 
>>  In that case, I guess we should extend check-bin-arch to support regexes for
>> the expected arch, and set the BR2_sparc arch to "Sparc( v8+)?".
> 
> Not as simple: another package may generate Sparc v8+ code, and this
> would be bogus.
> 
> So, in the context of Buildroot, I believe we should rather patch
> libmpeg to not generate the Sparc v8+ code if we are not on Sparc v8+.

 That is an option. But perhaps it's better to add a possibility for a
per-package exclusion of a file that is checked manually. I'll see if I can cook
something up.

 Regards,
 Arnout

-- 
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF

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

* [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option
  2017-03-12 22:17 Thomas Petazzoni
@ 2017-03-13 22:15 ` Arnout Vandecappelle
  0 siblings, 0 replies; 10+ messages in thread
From: Arnout Vandecappelle @ 2017-03-13 22:15 UTC (permalink / raw)
  To: buildroot



On 12-03-17 23:17, Thomas Petazzoni wrote:
> This config option corresponds to the string returned by readelf for
> the "Machine" field of the ELF header. It will be used to check if the
> architecture of binaries built by Buildroot match the target
> architecture.

 I'm a bit uncomfortable with encoding these names, since there is no real
guarantee that the binutils developers won't decide to change the name at some
point. Ideally we should just use the hex value, but it seems readelf (nor any
other tool) has an option to get it. Compiling our own ELF interpreter (or
patching patchelf) is a bit too much.

 Therefore:

Reviewed-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>


 Regards,
 Arnout

> 
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> ---
> Changes since v2:
>  - Improve comment above BR2_READELF_ARCH_NAME to explain that it is the
>    value of the "Machine:" field in readelf output, and point to the
>    readelf source code for the list of possible values.
> 
> Changes since v1:
>  - None
[snip]

-- 
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF

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

* [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option
@ 2017-03-12 22:17 Thomas Petazzoni
  2017-03-13 22:15 ` Arnout Vandecappelle
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Petazzoni @ 2017-03-12 22:17 UTC (permalink / raw)
  To: buildroot

This config option corresponds to the string returned by readelf for
the "Machine" field of the ELF header. It will be used to check if the
architecture of binaries built by Buildroot match the target
architecture.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
Changes since v2:
 - Improve comment above BR2_READELF_ARCH_NAME to explain that it is the
   value of the "Machine:" field in readelf output, and point to the
   readelf source code for the list of possible values.

Changes since v1:
 - None
---
 arch/Config.in            | 6 ++++++
 arch/Config.in.arc        | 3 +++
 arch/Config.in.arm        | 4 ++++
 arch/Config.in.bfin       | 3 +++
 arch/Config.in.csky       | 2 ++
 arch/Config.in.m68k       | 3 +++
 arch/Config.in.microblaze | 3 +++
 arch/Config.in.mips       | 3 +++
 arch/Config.in.nios2      | 3 +++
 arch/Config.in.or1k       | 3 +++
 arch/Config.in.powerpc    | 4 ++++
 arch/Config.in.sh         | 3 +++
 arch/Config.in.sparc      | 4 ++++
 arch/Config.in.x86        | 4 ++++
 arch/Config.in.xtensa     | 3 +++
 15 files changed, 51 insertions(+)

diff --git a/arch/Config.in b/arch/Config.in
index 65a33fb..50377a9 100644
--- a/arch/Config.in
+++ b/arch/Config.in
@@ -292,6 +292,12 @@ config BR2_GCC_TARGET_MODE
 config BR2_BINFMT_SUPPORTS_SHARED
 	bool
 
+# Must match the name of the architecture from readelf point of view,
+# i.e the "Machine:" field of readelf output. See get_machine_name()
+# in binutils/readelf.c for the list of possible values.
+config BR2_READELF_ARCH_NAME
+	string
+
 # Set up target binary format
 choice
 	prompt "Target Binary Format"
diff --git a/arch/Config.in.arc b/arch/Config.in.arc
index 7d341f3..dcdba68 100644
--- a/arch/Config.in.arc
+++ b/arch/Config.in.arc
@@ -38,6 +38,9 @@ config BR2_GCC_TARGET_CPU
 	default "arc700" if BR2_arc770d
 	default "archs"	 if BR2_archs38
 
+config BR2_READELF_ARCH_NAME
+	default "ARCv2"
+
 choice
 	prompt "MMU Page Size"
 	default BR2_ARC_PAGE_SIZE_8K
diff --git a/arch/Config.in.arm b/arch/Config.in.arm
index 2617976..f910364 100644
--- a/arch/Config.in.arm
+++ b/arch/Config.in.arm
@@ -568,3 +568,7 @@ config BR2_GCC_TARGET_FLOAT_ABI
 config BR2_GCC_TARGET_MODE
 	default "arm"		if BR2_ARM_INSTRUCTIONS_ARM
 	default "thumb"		if BR2_ARM_INSTRUCTIONS_THUMB || BR2_ARM_INSTRUCTIONS_THUMB2
+
+config BR2_READELF_ARCH_NAME
+	default "ARM"		if BR2_arm || BR2_armeb
+	default "AArch64"	if BR2_aarch64 || BR2_aarch64_be
diff --git a/arch/Config.in.bfin b/arch/Config.in.bfin
index 9f7056a..90e4ab9 100644
--- a/arch/Config.in.bfin
+++ b/arch/Config.in.bfin
@@ -105,3 +105,6 @@ config BR2_GCC_TARGET_CPU_REVISION
 	  value of the -mcpu option. For example, if the selected CPU is
 	  bf609, and then selected CPU revision is "0.0", then gcc will
 	  receive the -mcpu=bf609-0.0 option.
+
+config BR2_READELF_ARCH_NAME
+	default "Analog Devices Blackfin"
diff --git a/arch/Config.in.csky b/arch/Config.in.csky
index 7029c60..e88e4e2 100644
--- a/arch/Config.in.csky
+++ b/arch/Config.in.csky
@@ -44,3 +44,5 @@ config BR2_GCC_TARGET_CPU
 	default "ck810f"	if (BR2_ck810 &&  BR2_CSKY_FPU && !BR2_CSKY_DSP)
 	default "ck810ef"	if (BR2_ck810 &&  BR2_CSKY_FPU &&  BR2_CSKY_DSP)
 
+config BR2_READELF_ARCH_NAME
+	default "CSKY"
diff --git a/arch/Config.in.m68k b/arch/Config.in.m68k
index ced871f..c56031c 100644
--- a/arch/Config.in.m68k
+++ b/arch/Config.in.m68k
@@ -35,3 +35,6 @@ endchoice
 config BR2_GCC_TARGET_CPU
 	default "68040"		if BR2_m68k_68040
 	default "5208"		if BR2_m68k_cf5208
+
+config BR2_READELF_ARCH_NAME
+	default "MC68000"
diff --git a/arch/Config.in.microblaze b/arch/Config.in.microblaze
index 2d4c1fe..042712a 100644
--- a/arch/Config.in.microblaze
+++ b/arch/Config.in.microblaze
@@ -6,6 +6,9 @@ config BR2_ENDIAN
 	default "LITTLE" if BR2_microblazeel
 	default "BIG"	 if BR2_microblazebe
 
+config BR2_READELF_ARCH_NAME
+	default "Xilinx MicroBlaze"
+
 config BR2_microblaze
 	bool
 	default y if BR2_microblazeel || BR2_microblazebe
diff --git a/arch/Config.in.mips b/arch/Config.in.mips
index ce41e9e..22819d0 100644
--- a/arch/Config.in.mips
+++ b/arch/Config.in.mips
@@ -161,3 +161,6 @@ config BR2_GCC_TARGET_ABI
 	default "32"		if BR2_MIPS_OABI32
 	default "n32"		if BR2_MIPS_NABI32
 	default "64"		if BR2_MIPS_NABI64
+
+config BR2_READELF_ARCH_NAME
+	default "MIPS R3000"
diff --git a/arch/Config.in.nios2 b/arch/Config.in.nios2
index ed63898..7466331 100644
--- a/arch/Config.in.nios2
+++ b/arch/Config.in.nios2
@@ -3,3 +3,6 @@ config BR2_ARCH
 
 config BR2_ENDIAN
 	default "LITTLE"
+
+config BR2_READELF_ARCH_NAME
+	default "Altera Nios II"
diff --git a/arch/Config.in.or1k b/arch/Config.in.or1k
index dba64a6..b31ab3e 100644
--- a/arch/Config.in.or1k
+++ b/arch/Config.in.or1k
@@ -3,3 +3,6 @@ config BR2_ARCH
 
 config BR2_ENDIAN
 	default "BIG"
+
+config BR2_READELF_ARCH_NAME
+	default "OpenRISC 1000"
diff --git a/arch/Config.in.powerpc b/arch/Config.in.powerpc
index 09ac794..0968412 100644
--- a/arch/Config.in.powerpc
+++ b/arch/Config.in.powerpc
@@ -212,3 +212,7 @@ config BR2_GCC_TARGET_ABI
 	default "no-spe"		if BR2_PPC_ABI_no-spe
 	default "ibmlongdouble"		if BR2_PPC_ABI_ibmlongdouble
 	default "ieeelongdouble"	if BR2_PPC_ABI_ieeelongdouble
+
+config BR2_READELF_ARCH_NAME
+	default "PowerPC"	if BR2_powerpc
+	default "PowerPC64"	if BR2_powerpc64 || BR2_powerpc64le
diff --git a/arch/Config.in.sh b/arch/Config.in.sh
index 4705212..deb7244 100644
--- a/arch/Config.in.sh
+++ b/arch/Config.in.sh
@@ -27,3 +27,6 @@ config BR2_ARCH
 config BR2_ENDIAN
 	default "LITTLE"	if BR2_sh4 || BR2_sh4a
 	default "BIG"		if BR2_sh2a || BR2_sh4eb || BR2_sh4aeb
+
+config BR2_READELF_ARCH_NAME
+	default "Renesas / SuperH SH"
diff --git a/arch/Config.in.sparc b/arch/Config.in.sparc
index 307540f..9b6a6aa 100644
--- a/arch/Config.in.sparc
+++ b/arch/Config.in.sparc
@@ -28,3 +28,7 @@ config BR2_GCC_TARGET_CPU
 	default "leon3"		if BR2_sparc_leon3
 	default "v8"		if BR2_sparc_v8
 	default "ultrasparc"	if BR2_sparc_v9
+
+config BR2_READELF_ARCH_NAME
+	default "Sparc"		if BR2_sparc
+	default "Sparc v9"	if BR2_sparc64
diff --git a/arch/Config.in.x86 b/arch/Config.in.x86
index efa9567..0d9e93b 100644
--- a/arch/Config.in.x86
+++ b/arch/Config.in.x86
@@ -275,3 +275,7 @@ config BR2_GCC_TARGET_ARCH
 	default "c3"		if BR2_x86_c3
 	default "c3-2"		if BR2_x86_c32
 	default "geode"		if BR2_x86_geode
+
+config BR2_READELF_ARCH_NAME
+	default "Intel 80386"			if BR2_i386
+	default "Advanced Micro Devices X86-64" if BR2_x86_64
diff --git a/arch/Config.in.xtensa b/arch/Config.in.xtensa
index fcb3dc9..88dbe18 100644
--- a/arch/Config.in.xtensa
+++ b/arch/Config.in.xtensa
@@ -54,3 +54,6 @@ config BR2_ENDIAN
 
 config BR2_ARCH
 	default "xtensa"	if BR2_xtensa
+
+config BR2_READELF_ARCH_NAME
+	default "Tensilica Xtensa Processor"
-- 
2.7.4

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

end of thread, other threads:[~2017-04-10 15:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-19 13:07 [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option Thomas Petazzoni
2017-03-19 13:07 ` [Buildroot] [PATCH v4 2/2] Makefile: add check of binaries architecture Thomas Petazzoni
2017-03-20 21:26 ` [Buildroot] [PATCH v4 1/2] arch: add BR2_READELF_ARCH_NAME hidden config option Thomas Petazzoni
2017-04-02 10:38   ` Bernd Kuhls
2017-04-02 12:30     ` Thomas Petazzoni
2017-04-03 14:24       ` Arnout Vandecappelle
2017-04-03 15:08         ` Thomas Petazzoni
2017-04-10 15:49           ` Arnout Vandecappelle
  -- strict thread matches above, loose matches on Subject: below --
2017-03-12 22:17 Thomas Petazzoni
2017-03-13 22:15 ` Arnout Vandecappelle

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.