Skip to contentSkip to conversation

kbuild: disable Android-specific compiler features

PATCH In review Kees Cook 2 participants 4 messages Feb 6, 2016 – Feb 18, 2016 Kbuild

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 kbuild: disable Android-specific compiler features

The Android compilers enable some non-standard features by default. While most Android build systems inject the needed "-mno-android" option via KCFLAGS, it happens too late (at least on x86_64), since KBUILD_CFLAGS gains KCFLAGS after running (and failing) many cc-option tests. (For example, the stack-protector tests happen after arch-specific KBUILD_CFLAGS are added but before the external KCFLAGS are added.) As such, we should notice this option and immediately turn it on as the first cc-option test we run.

---
 Makefile | 4 ++++
 1 file changed, 4 insertions(+)
Makefile +4 -0
index 6c1a3c247988..126c98b582bb 100644
@@ -393,6 +393,10 @@ KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
 		   -Wno-format-security \
 		   -std=gnu89
 
+# We must turn off the Android-specific compiler options as early as possible
+# otherwise cc-option calls below may erroneously fail.
+KBUILD_CFLAGS	+= $(call cc-option,-mno-android,)
+
 KBUILD_AFLAGS_KERNEL :=
 KBUILD_CFLAGS_KERNEL :=
 KBUILD_AFLAGS   := -D__ASSEMBLY__
Signature · 6 lines
2.6.3


-- 
Kees Cook
Chrome OS & Brillo Security
author
#1 lore raw
Quoted 10 lines · Kees Cook

The Android compilers enable some non-standard features by default. While most Android build systems inject the needed "-mno-android" option via KCFLAGS, it happens too late (at least on x86_64), since KBUILD_CFLAGS gains KCFLAGS after running (and failing) many cc-option tests. (For example, the stack-protector tests happen after arch-specific KBUILD_CFLAGS are added but before the external KCFLAGS are added.) As such, we should notice this option and immediately turn it on as the first cc-option test we run.

Michal, is this okay? I'd like to get it into -next soon if possible.

Thanks!

-Kees

Quoted 26 lines
---
 Makefile | 4 ++++
 1 file changed, 4 insertions(+)
Makefile +4 -1
index 6c1a3c247988..126c98b582bb 100644
@@ -393,6 +393,10 @@ KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                   -Wno-format-security \
                   -std=gnu89
 
+# We must turn off the Android-specific compiler options as early as possible
+# otherwise cc-option calls below may erroneously fail.
+KBUILD_CFLAGS  += $(call cc-option,-mno-android,)
+
 KBUILD_AFLAGS_KERNEL :=
 KBUILD_CFLAGS_KERNEL :=
 KBUILD_AFLAGS   := -D__ASSEMBLY__
--

2.6.3

--
Kees Cook
Chrome OS & Brillo Security

Signature · 2 lines
Kees Cook
Chrome OS & Brillo Security
#2 lore raw

Dne 18.2.2016 v 00:03 Kees Cook napsal(a):

Quoted 10 lines · Kees Cook
Quoted 9 lines

The Android compilers enable some non-standard features by default. While most Android build systems inject the needed "-mno-android" option via KCFLAGS, it happens too late (at least on x86_64), since KBUILD_CFLAGS gains KCFLAGS after running (and failing) many cc-option tests. (For example, the stack-protector tests happen after arch-specific KBUILD_CFLAGS are added but before the external KCFLAGS are added.) As such, we should notice this option and immediately turn it on as the first cc-option test we run.

Quoted 3 lines
Quoted 1 line

Michal, is this okay? I'd like to get it into -next soon if possible.

Is there a way to detect these compilers and are there some canonical versions of these? I do not think it's a good idea to add workaround for each random gcc fork.

Michal

author
#3 lore raw
Quoted 11 lines · Michal Marek

Dne 18.2.2016 v 00:03 Kees Cook napsal(a):

Quoted 10 lines · Kees Cook
Quoted 9 lines

The Android compilers enable some non-standard features by default. While most Android build systems inject the needed "-mno-android" option via KCFLAGS, it happens too late (at least on x86_64), since KBUILD_CFLAGS gains KCFLAGS after running (and failing) many cc-option tests. (For example, the stack-protector tests happen after arch-specific KBUILD_CFLAGS are added but before the external KCFLAGS are added.) As such, we should notice this option and immediately turn it on as the first cc-option test we run.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Michal, is this okay? I'd like to get it into -next soon if possible.

Is there a way to detect these compilers and are there some canonical versions of these? I do not think it's a good idea to add workaround for each random gcc fork.

It's detectable by -mno-android being a valid option. It's not a random gcc fork, as it's part of the Android SDK gcc prebuilts that all Android vendors and hobbiests use to build their kernels.

-Kees

Signature · 2 lines
Kees Cook
Chrome OS & Brillo Security