Skip to content

Commit de9c0d4

Browse files
nathanchanceRussell King
authored andcommitted
ARM: 8833/1: Ensure that NEON code always compiles with Clang
While building arm32 allyesconfig, I ran into the following errors: arch/arm/lib/xor-neon.c:17:2: error: You should compile this file with '-mfloat-abi=softfp -mfpu=neon' In file included from lib/raid6/neon1.c:27: /home/nathan/cbl/prebuilt/lib/clang/8.0.0/include/arm_neon.h:28:2: error: "NEON support not enabled" Building V=1 showed NEON_FLAGS getting passed along to Clang but __ARM_NEON__ was not getting defined. Ultimately, it boils down to Clang only defining __ARM_NEON__ when targeting armv7, rather than armv6k, which is the '-march' value for allyesconfig. >From lib/Basic/Targets/ARM.cpp in the Clang source: // This only gets set when Neon instructions are actually available, unlike // the VFP define, hence the soft float and arch check. This is subtly // different from gcc, we follow the intent which was that it should be set // when Neon instructions are actually available. if ((FPU & NeonFPU) && !SoftFloat && ArchVersion >= 7) { Builder.defineMacro("__ARM_NEON", "1"); Builder.defineMacro("__ARM_NEON__"); // current AArch32 NEON implementations do not support double-precision // floating-point even when it is present in VFP. Builder.defineMacro("__ARM_NEON_FP", "0x" + Twine::utohexstr(HW_FP & ~HW_FP_DP)); } Ard Biesheuvel recommended explicitly adding '-march=armv7-a' at the beginning of the NEON_FLAGS definitions so that __ARM_NEON__ always gets definined by Clang. This doesn't functionally change anything because that code will only run where NEON is supported, which is implicitly armv7. Link: ClangBuiltLinux#287 Suggested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> Acked-by: Nicolas Pitre <nico@linaro.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Reviewed-by: Stefan Agner <stefan@agner.ch> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
1 parent 5388a5b commit de9c0d4

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

Documentation/arm/kernel_mode_neon.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TL;DR summary
66
* Use only NEON instructions, or VFP instructions that don't rely on support
77
code
88
* Isolate your NEON code in a separate compilation unit, and compile it with
9-
'-mfpu=neon -mfloat-abi=softfp'
9+
'-march=armv7-a -mfpu=neon -mfloat-abi=softfp'
1010
* Put kernel_neon_begin() and kernel_neon_end() calls around the calls into your
1111
NEON code
1212
* Don't sleep in your NEON code, and be aware that it will be executed with
@@ -87,7 +87,7 @@ instructions appearing in unexpected places if no special care is taken.
8787
Therefore, the recommended and only supported way of using NEON/VFP in the
8888
kernel is by adhering to the following rules:
8989
* isolate the NEON code in a separate compilation unit and compile it with
90-
'-mfpu=neon -mfloat-abi=softfp';
90+
'-march=armv7-a -mfpu=neon -mfloat-abi=softfp';
9191
* issue the calls to kernel_neon_begin(), kernel_neon_end() as well as the calls
9292
into the unit containing the NEON code from a compilation unit which is *not*
9393
built with the GCC flag '-mfpu=neon' set.

arch/arm/lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $(obj)/csumpartialcopy.o: $(obj)/csumpartialcopygeneric.S
3939
$(obj)/csumpartialcopyuser.o: $(obj)/csumpartialcopygeneric.S
4040

4141
ifeq ($(CONFIG_KERNEL_MODE_NEON),y)
42-
NEON_FLAGS := -mfloat-abi=softfp -mfpu=neon
42+
NEON_FLAGS := -march=armv7-a -mfloat-abi=softfp -mfpu=neon
4343
CFLAGS_xor-neon.o += $(NEON_FLAGS)
4444
obj-$(CONFIG_XOR_BLOCKS) += xor-neon.o
4545
endif

arch/arm/lib/xor-neon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
MODULE_LICENSE("GPL");
1515

1616
#ifndef __ARM_NEON__
17-
#error You should compile this file with '-mfloat-abi=softfp -mfpu=neon'
17+
#error You should compile this file with '-march=armv7-a -mfloat-abi=softfp -mfpu=neon'
1818
#endif
1919

2020
/*

lib/raid6/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ endif
3939
ifeq ($(CONFIG_KERNEL_MODE_NEON),y)
4040
NEON_FLAGS := -ffreestanding
4141
ifeq ($(ARCH),arm)
42-
NEON_FLAGS += -mfloat-abi=softfp -mfpu=neon
42+
NEON_FLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=neon
4343
endif
4444
CFLAGS_recov_neon_inner.o += $(NEON_FLAGS)
4545
ifeq ($(ARCH),arm64)

0 commit comments

Comments
 (0)