Skip to contentSkip to conversation

configs: raspberrypi3: fix mismatch cpu arch

RFC New Gaël PORTAY 5 participants 9 messages Apr 16, 2017 – Jul 15, 2017 Broadcom BCM2711/BCM2835 Arm architecture

lore
Share & tools
lore
#0 lore raw

cover configs: raspberrypi3: fix mismatch cpu arch

Hi all,

The RaspberryPi 3 is powered by a Broadcom BCM2837 which is a 64bits Cortex-A53 ARM processor (armv8).

Currently, BR defines the RPI3 as a simple Cortex-A7 (armv7), which is fair enough.

The first patch updates the ARM architecture to Cortex-A53 (BR2_cortex_a53=y) but leave the same 32 bit-length architecture (BR2_arm=y).

BR was compiling and the RPI3 was running fine until I decided to compile qt5base.

At this stage, GCC (6.3) complains about an unknown attribute:

	tools/qhash.cpp:148:54: error: attribute(target("+crc")) is unknown
	 static uint crc32(const Char *ptr, size_t len, uint h)

According to GCC, the +crc attribute is specific to armv8/AArch64 [1].

Also, according to the ARM (R) C Language Extensions Release 2.0 pdf [2].

6.5.8 CRC32 Extension
__ARM_FEATURE_CRC32 is defined to 1 if the CRC32 instructions are supported and the intrinsics defined in 9.7 are available. These instructions include CRC32B, CRC32H etc. This is only available when __ARM_ARCH >= 8

9.7 CRC32 intrinsics
CRC32 intrinsics provide direct access to CRC32 instructions CRC32{C}{B, H, W, X} in both ARMv8 AArch32 and AArch64 execution states. These intrinsics are available when __ARM_FEATURE_CRC32 is defined.

Here is the list of the ARM defines generated by the BR toolchain (w/ BR2_arm=y and BR2_cortex_a53=y).

	#define __arm__ 1
	#define __ARM_32BIT_STATE 1
	#define __ARM_ARCH 8
	#define __ARM_ARCH_8A__ 1
	#define __ARM_ARCH_EXT_IDIV__ 1
	#define __ARM_ARCH_ISA_ARM 1
	#define __ARM_ARCH_ISA_THUMB 2
	#define __ARM_ARCH_PROFILE 65
	#define __ARM_EABI__ 1
	#define __ARMEL__ 1
	#define __ARM_FEATURE_CLZ 1
	#define __ARM_FEATURE_CRC32 1
	#define __ARM_FEATURE_DSP 1
	#define __ARM_FEATURE_IDIV 1
	#define __ARM_FEATURE_LDREX 15
	#define __ARM_FEATURE_QBIT 1
	#define __ARM_FEATURE_SAT 1
	#define __ARM_FEATURE_SIMD32 1
	#define __ARM_FEATURE_UNALIGNED 1
	#define __ARM_PCS 1
	#define __ARM_SIZEOF_MINIMAL_ENUM 4
	#define __ARM_SIZEOF_WCHAR_T 4

Toolchain seems to be a 32bits (presence of __ARM_32BIT_STATE) and for armv8-a target (__ARM_ARCH 8, __ARM_ARCH_8A__...).

Because of #define __ARM_FEATURE_CRC32 1, qt5base does not compile (due to the attribute target=+crc) [3].

Note: If I remove the attribute(target=+crc), the compilation fails at linkage saying crc32 instructions are bad.

When I force architecture to armv7 (ie. -march=armv7), __ARM_FEATURE_CRC32 is unset. I assume it compiles.

My understanding is that the crc32 instructions are not available in 32bits mode.

In this RFC, the second patch tries to fix qt5base. It checks for both defines

        #if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)

Instead of checking the single define __ARM_FEATURE_CRC32.

I guess my fix is not appropriate. Anyone can tell me what exactly is wrong in there?
- Maybe I make a confusion between __ARM_32BIT_STATE and AArch32.
- Maybe the toolchain is not properly set using arm/cortex_a53.
- Maybe the points 6.5.8 and 9.7 from [2] are not true.

[1] https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#g_t-march-and--mcpu-Feature-Modifiers
[2] http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053c/IHI0053C_acle_2_0.pdf
[3] https://github.com/qt/qtbase/blob/5.8/src/corelib/tools/qhash.cpp#L140

Regards,
Ga?l PORTAY (2):
configs: raspberrypi3: fix mismatch cpu arch
qt5base: fix build failure with a 32bit armv8

 configs/raspberrypi3_defconfig                     |  2 +-
 ...01-Fix-ARM32-CRC-build-issue-on-armv8-cpu.patch | 90 ++++++++++++++++++++++
 ...01-Fix-ARM32-CRC-build-issue-on-armv8-cpu.patch |  1 +
 3 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 package/qt5/qt5base/5.6.2/0001-Fix-ARM32-CRC-build-issue-on-armv8-cpu.patch
 create mode 120000 package/qt5/qt5base/5.8.0/0001-Fix-ARM32-CRC-build-issue-on-armv8-cpu.patch

PS: Here is the list of the ARM defines if I force -march=armv7.

	#define __arm__ 1
	#define __ARM_32BIT_STATE 1
	#define __ARM_ARCH 7
	#define __ARM_ARCH_7A__ 1
	#define __ARM_ARCH_ISA_ARM 1
	#define __ARM_ARCH_ISA_THUMB 2
	#define __ARM_ARCH_PROFILE 65
	#define __ARM_EABI__ 1
	#define __ARMEL__ 1
	#define __ARM_FEATURE_CLZ 1
	#define __ARM_FEATURE_DSP 1
	#define __ARM_FEATURE_LDREX 15
	#define __ARM_FEATURE_QBIT 1
	#define __ARM_FEATURE_SAT 1
	#define __ARM_FEATURE_SIMD32 1
	#define __ARM_FEATURE_UNALIGNED 1
	#define __ARM_PCS 1
	#define __ARM_SIZEOF_MINIMAL_ENUM 4
	#define __ARM_SIZEOF_WCHAR_T 4
Signature · 1 line
2.12.1
#1 lore raw

RFC 1/2 configs: raspberrypi3: fix mismatch cpu arch

The raspberrypi3 is powered by a Broadcom BCM2837 which is a Cortex-A53.

---
 configs/raspberrypi3_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configs/raspberrypi3_defconfig +1 -1
index 1b2134e0b..3d8949765 100644
@@ -1,5 +1,5 @@
 BR2_arm=y
-BR2_cortex_a7=y
+BR2_cortex_a53=y
 BR2_ARM_EABIHF=y
 BR2_ARM_FPU_NEON_VFPV4=y
 
Signature · 1 line
2.12.1
#2 lore raw

RFC 1/2 configs: raspberrypi3: fix mismatch cpu arch

Quoted 3 lines · Ga?l PORTAY

The raspberrypi3 is powered by a Broadcom BCM2837 which is a Cortex-A53.

Just to be sure: have you boot-tested the new defconfig?

Regards,
Arnout

Quoted 16 lines
---
 configs/raspberrypi3_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
configs/raspberrypi3_defconfig +1 -1
index 1b2134e0b..3d8949765 100644
@@ -1,5 +1,5 @@
 BR2_arm=y
-BR2_cortex_a7=y
+BR2_cortex_a53=y
 BR2_ARM_EABIHF=y
 BR2_ARM_FPU_NEON_VFPV4=y
 
Signature · 6 lines
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
#3 lore raw

RFC 1/2 configs: raspberrypi3: fix mismatch cpu arch

Arnout,

Quoted 10 lines · Arnout Vandecappelle
Quoted 3 lines · Ga?l PORTAY

The raspberrypi3 is powered by a Broadcom BCM2837 which is a Cortex-A53.

Just to be sure: have you boot-tested the new defconfig?

Yes, I have tested this new configuration.

As you can see in the second patch, this new configuration has broken the compilation of qtbase.

Quoted 3 lines

Regards,
Arnout

Regards,
Ga?l

#5 lore raw

RFC 1/2 configs: raspberrypi3: fix mismatch cpu arch

In reply to Gaël PORTAY

Hello,

Quoted 6 lines · Ga?l PORTAY

The raspberrypi3 is powered by a Broadcom BCM2837 which is a Cortex-A53.

---
 configs/raspberrypi3_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks, I have applied https://patchwork.ozlabs.org/patch/757022/
instead, which was a little bit more complete, but essentially does the same thing.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#6 lore raw

RFC 2/2 qt5base: fix build issue on 32bits armv8 target

In reply to Gaël PORTAY

__ARM_FEATURE_CRC32 macro is set for armv8 cpus.

In case of a 32bits armv8 target, gcc complains about an unknown attribute +crc.

	tools/qhash.cpp:148:54: error: attribute(target("+crc")) is unknown
	 static uint crc32(const Char *ptr, size_t len, uint h)

This attribute looks to not be available in 32bits mode. If the attribute is bypassed (commented), the build breaks at linkage saying crc32x instructions are bad.

To solve this build issue, this patch checks for both __aarch64__ and __ARM_FEATURE_CRC32.

---
 ...ix-CRC-build-issue-on-32bits-armv8-target.patch | 95 ++++++++++++++++++++++
 ...ix-CRC-build-issue-on-32bits-armv8-target.patch |  1 +
 2 files changed, 96 insertions(+)
 create mode 100644 package/qt5/qt5base/5.6.2/0003-Fix-CRC-build-issue-on-32bits-armv8-target.patch
 create mode 120000 package/qt5/qt5base/5.8.0/0005-Fix-CRC-build-issue-on-32bits-armv8-target.patch
package/qt5/qt5base/5.6.2/0003-Fix-CRC-build-issue-on-32bits-armv8-target.patch new file +95 -0
new file mode 100644
index 000000000..a648ea04d
@@ -0,0 +1,95 @@
+From 0382127e9f39f83e313ea279bc407d4eb6bd5e73 Mon Sep 17 00:00:00 2001
+From: =?utf-8?q?Ga=C3=ABl=20PORTAY?= <[email protected]>
+Date: Tue, 11 Apr 2017 17:28:48 -0400
+Subject: [PATCH] Fix CRC build issue on 32bits armv8 target
+MIME-Version: 1.0
+Content-Type: text/plain; charset=utf-8
+Content-Transfer-Encoding: 8bit
+
+__ARM_FEATURE_CRC32 macro is set for armv8 cpus.
+
+In case of a 32bits armv8 target, gcc complains about an unknown
+attribute +crc.
+
+	tools/qhash.cpp:148:54: error: attribute(target("+crc")) is unknown
+	 static uint crc32(const Char *ptr, size_t len, uint h)
+
+This attribute looks to not be available in 32bits mode. If the
+attribute is bypassed (commented), the build breaks at linkage saying
+crc32x instructions are bad.
+
+To solve this build issue, this patch checks for both __aarch64__ and
+__ARM_FEATURE_CRC32.
+
+Signed-off-by: Ga?l PORTAY <[email protected]>
+---
+ config.tests/arch/arch.cpp  | 2 +-
+ src/corelib/tools/qhash.cpp | 2 +-
+ src/corelib/tools/qsimd.cpp | 2 +-
+ src/corelib/tools/qsimd_p.h | 4 ++--
+ 4 files changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/config.tests/arch/arch.cpp b/config.tests/arch/arch.cpp
+index f99c5ca118..72f4af39fe 100644
+--- a/config.tests/arch/arch.cpp
++++ b/config.tests/arch/arch.cpp
+@@ -249,7 +249,7 @@ const char msg2[] = "==Qt=magic=Qt== Sub-architecture:"
+ #ifdef __IWMMXT__
+ " iwmmxt"
+ #endif
+-#ifdef __ARM_FEATURE_CRC32
++#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+ " crc32"
+ #endif
+ 
+diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
+index abec9ebb79..84cbe51731 100644
+--- a/src/corelib/tools/qhash.cpp
++++ b/src/corelib/tools/qhash.cpp
+@@ -137,7 +137,7 @@ static uint crc32(const Char *ptr, size_t len, uint h)
+         h = _mm_crc32_u8(h, *p);
+     return h;
+ }
+-#elif defined(__ARM_FEATURE_CRC32)
++#elif defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+ static inline bool hasFastCrc32()
+ {
+     return qCpuHasFeature(CRC32);
+diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
+index d4edf459de..f07cb2914a 100644
+--- a/src/corelib/tools/qsimd.cpp
++++ b/src/corelib/tools/qsimd.cpp
+@@ -136,7 +136,7 @@ static inline quint64 detectProcessorFeatures()
+ #if defined(__ARM_NEON__)
+     features |= Q_UINT64_C(1) << CpuFeatureNEON;
+ #endif
+-#if defined(__ARM_FEATURE_CRC32)
++#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+     features |= Q_UINT64_C(1) << CpuFeatureCRC32;
+ #endif
+ 
+diff --git a/src/corelib/tools/qsimd_p.h b/src/corelib/tools/qsimd_p.h
+index d5d887598e..92c93ea2e7 100644
+--- a/src/corelib/tools/qsimd_p.h
++++ b/src/corelib/tools/qsimd_p.h
+@@ -324,7 +324,7 @@
+ #endif
+ #endif
+ // AArch64/ARM64
+-#if defined(Q_PROCESSOR_ARM_V8) && defined(__ARM_FEATURE_CRC32)
++#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+ #define QT_FUNCTION_TARGET_STRING_CRC32      "+crc"
+ #  include <arm_acle.h>
+ #endif
+@@ -466,7 +466,7 @@ static const quint64 qCompilerCpuFeatures = 0
+ #if defined __ARM_NEON__
+         | (Q_UINT64_C(1) << CpuFeatureNEON)
+ #endif
+-#if defined __ARM_FEATURE_CRC32
++#if defined __aarch64__ && defined __ARM_FEATURE_CRC32
+         | (Q_UINT64_C(1) << CpuFeatureCRC32)
+ #endif
+ #if defined __mips_dsp
+-- 
+2.12.1
+
package/qt5/qt5base/5.8.0/0005-Fix-CRC-build-issue-on-32bits-armv8-target.patch new file +1 -0
new file mode 120000
index 000000000..fce78e496
@@ -0,0 +1 @@
+../5.6.2/0003-Fix-CRC-build-issue-on-32bits-armv8-target.patch
\ No newline@end of file
Signature · 1 line
2.12.1
#7 lore raw

RFC 2/2 qt5base: fix build issue on 32bits armv8 target

Quoted 9 lines · Ga?l PORTAY

__ARM_FEATURE_CRC32 macro is set for armv8 cpus.

In case of a 32bits armv8 target, gcc complains about an unknown attribute +crc.

	tools/qhash.cpp:148:54: error: attribute(target("+crc")) is unknown
	 static uint crc32(const Char *ptr, size_t len, uint h)

This attribute looks to not be available in 32bits mode.

That looks like a compiler bug, so I'm not sure this is the right fix.

Also, I haven't been able to reproduce with a small test program (see below)
with various compilers I tried. Instead I get

/tmp/crc.c:7:1: warning: target attribute is not supported on this machine

I do get the link error in the end because of the missing __crc32w intrinsic. Or when crc32 really is available (i.e. with -mcpu=cortex-a53), I get an assembler error "selected processor does not support ARM mode `crc32w r3,r3,r2'". This error I *don't* have when I use binutils 2.28, but I *do* have it with binutils 2.24. So my error sounds like a binutils issue.

With which compiler did you have this issue?

crc.c:
------
#include <stdint.h>
#include <arm_acle.h>

__attribute__((__target__("+crc")))
int main(int argc, char *argv[])
{
return __crc32w(0, *(uint32_t *)argv[0]);
}
------

Note by the way that all cortex-aXX armv8-a processors seem to support the
optional CRC instruction, at least according to gcc. A processor that doesn't have it is xgene1, but we don't support that one. So for Buildroot, the target("+crc32") is pretty much redundant, since we always have -mcpu=cortex-aXX for any processor that has __ARM_FEATURE_CRC32 set.

Which makes me realize: the code in qhash.cpp is in fact rubbish... After
expanding a few macros, it basically has:

#if defined(__ARM_FEATURE_CRC32) __attribute__((target("+crc32")))
static uint crc32(const Char *ptr, size_t len, uint h)

but __ARM_FEATURE_CRC32 is only defined if the compilation flags already contain the equivalent of +crc32...

So that makes me think that the proper (upstreamable) fix could be:

* Remove the bogus QT_FUNCTION_TARGET(CRC32) from qhash.cpp.

* Add a config.test that checks for broken assemblers that don't support the crc32x instructions, and disable fast crc32 on those.

Regards,
Arnout

Regards,
Arnout

Quoted 125 lines

If the
attribute is bypassed (commented), the build breaks at linkage saying crc32x instructions are bad.

To solve this build issue, this patch checks for both __aarch64__ and __ARM_FEATURE_CRC32.

---
 ...ix-CRC-build-issue-on-32bits-armv8-target.patch | 95 ++++++++++++++++++++++
 ...ix-CRC-build-issue-on-32bits-armv8-target.patch |  1 +
 2 files changed, 96 insertions(+)
 create mode 100644 package/qt5/qt5base/5.6.2/0003-Fix-CRC-build-issue-on-32bits-armv8-target.patch
 create mode 120000 package/qt5/qt5base/5.8.0/0005-Fix-CRC-build-issue-on-32bits-armv8-target.patch
package/qt5/qt5base/5.6.2/0003-Fix-CRC-build-issue-on-32bits-armv8-target.patch new file +95 -0
new file mode 100644
index 000000000..a648ea04d
@@ -0,0 +1,95 @@
+From 0382127e9f39f83e313ea279bc407d4eb6bd5e73 Mon Sep 17 00:00:00 2001
+From: =?utf-8?q?Ga=C3=ABl=20PORTAY?= <[email protected]>
+Date: Tue, 11 Apr 2017 17:28:48 -0400
+Subject: [PATCH] Fix CRC build issue on 32bits armv8 target
+MIME-Version: 1.0
+Content-Type: text/plain; charset=utf-8
+Content-Transfer-Encoding: 8bit
+
+__ARM_FEATURE_CRC32 macro is set for armv8 cpus.
+
+In case of a 32bits armv8 target, gcc complains about an unknown
+attribute +crc.
+
+	tools/qhash.cpp:148:54: error: attribute(target("+crc")) is unknown
+	 static uint crc32(const Char *ptr, size_t len, uint h)
+
+This attribute looks to not be available in 32bits mode. If the
+attribute is bypassed (commented), the build breaks at linkage saying
+crc32x instructions are bad.
+
+To solve this build issue, this patch checks for both __aarch64__ and
+__ARM_FEATURE_CRC32.
+
+Signed-off-by: Ga?l PORTAY <[email protected]>
+---
+ config.tests/arch/arch.cpp  | 2 +-
+ src/corelib/tools/qhash.cpp | 2 +-
+ src/corelib/tools/qsimd.cpp | 2 +-
+ src/corelib/tools/qsimd_p.h | 4 ++--
+ 4 files changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/config.tests/arch/arch.cpp b/config.tests/arch/arch.cpp
+index f99c5ca118..72f4af39fe 100644
+--- a/config.tests/arch/arch.cpp
++++ b/config.tests/arch/arch.cpp
+@@ -249,7 +249,7 @@ const char msg2[] = "==Qt=magic=Qt== Sub-architecture:"
+ #ifdef __IWMMXT__
+ " iwmmxt"
+ #endif
+-#ifdef __ARM_FEATURE_CRC32
++#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+ " crc32"
+ #endif
+ 
+diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
+index abec9ebb79..84cbe51731 100644
+--- a/src/corelib/tools/qhash.cpp
++++ b/src/corelib/tools/qhash.cpp
+@@ -137,7 +137,7 @@ static uint crc32(const Char *ptr, size_t len, uint h)
+         h = _mm_crc32_u8(h, *p);
+     return h;
+ }
+-#elif defined(__ARM_FEATURE_CRC32)
++#elif defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+ static inline bool hasFastCrc32()
+ {
+     return qCpuHasFeature(CRC32);
+diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
+index d4edf459de..f07cb2914a 100644
+--- a/src/corelib/tools/qsimd.cpp
++++ b/src/corelib/tools/qsimd.cpp
+@@ -136,7 +136,7 @@ static inline quint64 detectProcessorFeatures()
+ #if defined(__ARM_NEON__)
+     features |= Q_UINT64_C(1) << CpuFeatureNEON;
+ #endif
+-#if defined(__ARM_FEATURE_CRC32)
++#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+     features |= Q_UINT64_C(1) << CpuFeatureCRC32;
+ #endif
+ 
+diff --git a/src/corelib/tools/qsimd_p.h b/src/corelib/tools/qsimd_p.h
+index d5d887598e..92c93ea2e7 100644
+--- a/src/corelib/tools/qsimd_p.h
++++ b/src/corelib/tools/qsimd_p.h
+@@ -324,7 +324,7 @@
+ #endif
+ #endif
+ // AArch64/ARM64
+-#if defined(Q_PROCESSOR_ARM_V8) && defined(__ARM_FEATURE_CRC32)
++#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+ #define QT_FUNCTION_TARGET_STRING_CRC32      "+crc"
+ #  include <arm_acle.h>
+ #endif
+@@ -466,7 +466,7 @@ static const quint64 qCompilerCpuFeatures = 0
+ #if defined __ARM_NEON__
+         | (Q_UINT64_C(1) << CpuFeatureNEON)
+ #endif
+-#if defined __ARM_FEATURE_CRC32
++#if defined __aarch64__ && defined __ARM_FEATURE_CRC32
+         | (Q_UINT64_C(1) << CpuFeatureCRC32)
+ #endif
+ #if defined __mips_dsp
+-- 
+2.12.1
+
package/qt5/qt5base/5.8.0/0005-Fix-CRC-build-issue-on-32bits-armv8-target.patch new file +1 -0
new file mode 120000
index 000000000..fce78e496
@@ -0,0 +1 @@
+../5.6.2/0003-Fix-CRC-build-issue-on-32bits-armv8-target.patch
\ No newline at end of file
Signature · 6 lines
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
#8 lore raw

RFC 2/2 qt5base: fix build issue on 32bits armv8 target

Hello Ga?l, Arnout,

Quoted 58 lines · Arnout Vandecappelle
Quoted 9 lines · Ga?l PORTAY

__ARM_FEATURE_CRC32 macro is set for armv8 cpus.

In case of a 32bits armv8 target, gcc complains about an unknown attribute +crc.

	tools/qhash.cpp:148:54: error: attribute(target("+crc")) is unknown
	 static uint crc32(const Char *ptr, size_t len, uint h)

This attribute looks to not be available in 32bits mode.

That looks like a compiler bug, so I'm not sure this is the right fix.

Also, I haven't been able to reproduce with a small test program (see below)
with various compilers I tried. Instead I get

/tmp/crc.c:7:1: warning: target attribute is not supported on this machine

I do get the link error in the end because of the missing __crc32w intrinsic. Or when crc32 really is available (i.e. with -mcpu=cortex-a53), I get an assembler error "selected processor does not support ARM mode `crc32w r3,r3,r2'". This error I *don't* have when I use binutils 2.28, but I *do* have it with binutils 2.24. So my error sounds like a binutils issue.

With which compiler did you have this issue?

crc.c:
------
#include <stdint.h>
#include <arm_acle.h>

__attribute__((__target__("+crc")))
int main(int argc, char *argv[])
{
return __crc32w(0, *(uint32_t *)argv[0]);
}
------

Note by the way that all cortex-aXX armv8-a processors seem to support the
optional CRC instruction, at least according to gcc. A processor that doesn't have it is xgene1, but we don't support that one. So for Buildroot, the target("+crc32") is pretty much redundant, since we always have -mcpu=cortex-aXX for any processor that has __ARM_FEATURE_CRC32 set.

Which makes me realize: the code in qhash.cpp is in fact rubbish... After
expanding a few macros, it basically has:

#if defined(__ARM_FEATURE_CRC32) __attribute__((target("+crc32")))
static uint crc32(const Char *ptr, size_t len, uint h)

but __ARM_FEATURE_CRC32 is only defined if the compilation flags already contain the equivalent of +crc32...

Quoted 7 lines

So that makes me think that the proper (upstreamable) fix could be:

* Remove the bogus QT_FUNCTION_TARGET(CRC32) from qhash.cpp.

* Add a config.test that checks for broken assemblers that don't support the crc32x instructions, and disable fast crc32 on those.

Suggested an alternative patch upstream [1],[2] and tested the qt5base compile with binutils-2.28 and binutils-2.27+patch suggested in Bug 9916 [3] and posted as two buildroot patches...

Regards,
Peter

[1] https://bugreports.qt.io/browse/QTBUG-61975
[2] https://codereview.qt-project.org/200171
[3] https://bugs.busybox.net/show_bug.cgi?id=9916
[4] http://lists.busybox.net/pipermail/buildroot/2017-July/198027.html
[5] http://lists.busybox.net/pipermail/buildroot/2017-July/198026.html

Quoted 136 lines

Regards,
Arnout

Regards,
Arnout

Quoted 125 lines

If the
attribute is bypassed (commented), the build breaks at linkage saying crc32x instructions are bad.

To solve this build issue, this patch checks for both __aarch64__ and __ARM_FEATURE_CRC32.

---
 ...ix-CRC-build-issue-on-32bits-armv8-target.patch | 95 ++++++++++++++++++++++
 ...ix-CRC-build-issue-on-32bits-armv8-target.patch |  1 +
 2 files changed, 96 insertions(+)
 create mode 100644 package/qt5/qt5base/5.6.2/0003-Fix-CRC-build-issue-on-32bits-armv8-target.patch
 create mode 120000 package/qt5/qt5base/5.8.0/0005-Fix-CRC-build-issue-on-32bits-armv8-target.patch
package/qt5/qt5base/5.6.2/0003-Fix-CRC-build-issue-on-32bits-armv8-target.patch new file +95 -0
new file mode 100644
index 000000000..a648ea04d
@@ -0,0 +1,95 @@
+From 0382127e9f39f83e313ea279bc407d4eb6bd5e73 Mon Sep 17 00:00:00 2001
+From: =?utf-8?q?Ga=C3=ABl=20PORTAY?= <[email protected]>
+Date: Tue, 11 Apr 2017 17:28:48 -0400
+Subject: [PATCH] Fix CRC build issue on 32bits armv8 target
+MIME-Version: 1.0
+Content-Type: text/plain; charset=utf-8
+Content-Transfer-Encoding: 8bit
+
+__ARM_FEATURE_CRC32 macro is set for armv8 cpus.
+
+In case of a 32bits armv8 target, gcc complains about an unknown
+attribute +crc.
+
+	tools/qhash.cpp:148:54: error: attribute(target("+crc")) is unknown
+	 static uint crc32(const Char *ptr, size_t len, uint h)
+
+This attribute looks to not be available in 32bits mode. If the
+attribute is bypassed (commented), the build breaks at linkage saying
+crc32x instructions are bad.
+
+To solve this build issue, this patch checks for both __aarch64__ and
+__ARM_FEATURE_CRC32.
+
+Signed-off-by: Ga?l PORTAY <[email protected]>
+---
+ config.tests/arch/arch.cpp  | 2 +-
+ src/corelib/tools/qhash.cpp | 2 +-
+ src/corelib/tools/qsimd.cpp | 2 +-
+ src/corelib/tools/qsimd_p.h | 4 ++--
+ 4 files changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/config.tests/arch/arch.cpp b/config.tests/arch/arch.cpp
+index f99c5ca118..72f4af39fe 100644
+--- a/config.tests/arch/arch.cpp
++++ b/config.tests/arch/arch.cpp
+@@ -249,7 +249,7 @@ const char msg2[] = "==Qt=magic=Qt== Sub-architecture:"
+ #ifdef __IWMMXT__
+ " iwmmxt"
+ #endif
+-#ifdef __ARM_FEATURE_CRC32
++#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+ " crc32"
+ #endif
+ 
+diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
+index abec9ebb79..84cbe51731 100644
+--- a/src/corelib/tools/qhash.cpp
++++ b/src/corelib/tools/qhash.cpp
+@@ -137,7 +137,7 @@ static uint crc32(const Char *ptr, size_t len, uint h)
+         h = _mm_crc32_u8(h, *p);
+     return h;
+ }
+-#elif defined(__ARM_FEATURE_CRC32)
++#elif defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+ static inline bool hasFastCrc32()
+ {
+     return qCpuHasFeature(CRC32);
+diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
+index d4edf459de..f07cb2914a 100644
+--- a/src/corelib/tools/qsimd.cpp
++++ b/src/corelib/tools/qsimd.cpp
+@@ -136,7 +136,7 @@ static inline quint64 detectProcessorFeatures()
+ #if defined(__ARM_NEON__)
+     features |= Q_UINT64_C(1) << CpuFeatureNEON;
+ #endif
+-#if defined(__ARM_FEATURE_CRC32)
++#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+     features |= Q_UINT64_C(1) << CpuFeatureCRC32;
+ #endif
+ 
+diff --git a/src/corelib/tools/qsimd_p.h b/src/corelib/tools/qsimd_p.h
+index d5d887598e..92c93ea2e7 100644
+--- a/src/corelib/tools/qsimd_p.h
++++ b/src/corelib/tools/qsimd_p.h
+@@ -324,7 +324,7 @@
+ #endif
+ #endif
+ // AArch64/ARM64
+-#if defined(Q_PROCESSOR_ARM_V8) && defined(__ARM_FEATURE_CRC32)
++#if defined(__aarch64__) && defined(__ARM_FEATURE_CRC32)
+ #define QT_FUNCTION_TARGET_STRING_CRC32      "+crc"
+ #  include <arm_acle.h>
+ #endif
+@@ -466,7 +466,7 @@ static const quint64 qCompilerCpuFeatures = 0
+ #if defined __ARM_NEON__
+         | (Q_UINT64_C(1) << CpuFeatureNEON)
+ #endif
+-#if defined __ARM_FEATURE_CRC32
++#if defined __aarch64__ && defined __ARM_FEATURE_CRC32
+         | (Q_UINT64_C(1) << CpuFeatureCRC32)
+ #endif
+ #if defined __mips_dsp
+-- 
+2.12.1
+
package/qt5/qt5base/5.8.0/0005-Fix-CRC-build-issue-on-32bits-armv8-target.patch new file +1 -0
new file mode 120000
index 000000000..fce78e496
@@ -0,0 +1 @@
+../5.6.2/0003-Fix-CRC-build-issue-on-32bits-armv8-target.patch
\ No newline at end of file