Skip to contentSkip to conversation

x86: Use -mno-avx when available

PATCH In review Andi Kleen 5 participants 17 messages Mar 28, 2012 – May 12, 2012

Subsystems (4)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/2 x86: Use -mno-avx when available

From: Andi Kleen <[email protected]>

On gccs that support AVX it's a good idea to disable that too, similar to how SSE2, SSE1 etc. are already disabled. This prevents the compiler from generating AVX ever implicitely.

No failure observed, just from review.

---
 arch/x86/Makefile |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/Makefile +1 -0
index 209ba12..2c8aefd 100644
@@ -113,6 +113,7 @@ KBUILD_CFLAGS += -Wno-sign-compare
 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
 # prevent gcc from generating any FP code by mistake
 KBUILD_CFLAGS += $(call cc-option,-mno-sse -mno-mmx -mno-sse2 -mno-3dnow,)
+KBUILD_CFLAGS += $(call cc-option,-mno-avx,)
 
 KBUILD_CFLAGS += $(mflags-y)
 KBUILD_AFLAGS += $(mflags-y)
Signature · 1 line
1.7.7.6
author
#1 lore raw

PATCH 2/2 Add CONFIG_READABLE_ASM

From: Andi Kleen <[email protected]>

Add a config option to disable various gcc compiler optimizations that make assembler listings much harder to read. This is everything that reorders code significantly or creates partial functions.

This is mainly to keep kernel hackers sane.

---
 Makefile          |   10 ++++++++++
 lib/Kconfig.debug |    9 +++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
Makefile +10 -0
index 1932984..6f7328b 100644
@@ -564,6 +564,16 @@ else
 KBUILD_CFLAGS	+= -O2
 endif
 
+ifdef CONFIG_READABLE_ASM
+# Disable optimizations that make assembler listings hard to read.
+# reorder blocks reorders the control in the function
+# ipa clone creates specialized cloned functions
+# partial inlining inlines only parts of functions
+KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
+                 $(call cc-option,-fno-ipa-cp-clone,) \
+                 $(call cc-option,-fno-partial-inlining)
+endif
+
 include $(srctree)/arch/$(SRCARCH)/Makefile
 
 ifneq ($(CONFIG_FRAME_WARN),0)
lib/Kconfig.debug +9 -0
index f7af95d..d6102f3 100644
@@ -70,6 +70,15 @@ config STRIP_ASM_SYMS
 	  that look like '.Lxxx') so they don't pollute the output of
 	  get_wchan() and suchlike.
 
+config READABLE_ASM
+        bool "Generate readable assembler code"
+        depends on DEBUG_KERNEL
+        help
+          Disable some compiler optimizations that tend to generate human unreadable
+          assembler output. This may make the kernel slightly slower, but it helps
+          to keep kernel developers who have to stare a lot at assembler listings
+          sane.
+
 config UNUSED_SYMBOLS
 	bool "Enable unused/obsolete exported symbols"
 	default y if X86
Signature · 1 line
1.7.7.6
#2 lore raw

[tip:x86/cleanups] debug: Add CONFIG_READABLE_ASM

Commit-ID:  1873e870fd63ee4b87dbe0125ca373e420fb4987
Gitweb:     http://git.kernel.org/tip/1873e870fd63ee4b87dbe0125ca373e420fb4987
Author:     Andi Kleen <[email protected]>
AuthorDate: Wed, 28 Mar 2012 11:51:18 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Fri, 30 Mar 2012 10:15:21 -0700

debug: Add CONFIG_READABLE_ASM

Add a config option to disable various gcc compiler optimizations that make assembler listings much harder to read. This is everything that reorders code significantly or creates partial functions.

This is mainly to keep kernel hackers sane.

---
 Makefile          |   10 ++++++++++
 lib/Kconfig.debug |    9 +++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
Makefile +10 -0
index 1932984..6f7328b 100644
@@ -564,6 +564,16 @@ else
 KBUILD_CFLAGS	+= -O2
 endif
 
+ifdef CONFIG_READABLE_ASM
+# Disable optimizations that make assembler listings hard to read.
+# reorder blocks reorders the control in the function
+# ipa clone creates specialized cloned functions
+# partial inlining inlines only parts of functions
+KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
+                 $(call cc-option,-fno-ipa-cp-clone,) \
+                 $(call cc-option,-fno-partial-inlining)
+endif
+
 include $(srctree)/arch/$(SRCARCH)/Makefile
 
 ifneq ($(CONFIG_FRAME_WARN),0)
lib/Kconfig.debug +9 -0
index 6777153..4d3cbbb 100644
@@ -70,6 +70,15 @@ config STRIP_ASM_SYMS
 	  that look like '.Lxxx') so they don't pollute the output of
 	  get_wchan() and suchlike.
 
+config READABLE_ASM
+        bool "Generate readable assembler code"
+        depends on DEBUG_KERNEL
+        help
+          Disable some compiler optimizations that tend to generate human unreadable
+          assembler output. This may make the kernel slightly slower, but it helps
+          to keep kernel developers who have to stare a lot at assembler listings
+          sane.
+
 config UNUSED_SYMBOLS
 	bool "Enable unused/obsolete exported symbols"
 	default y if X86
#3 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

In reply to Andi Kleen

Hi Andi,

Makefile else · line 575

Quoted 9 lines · Andi Kleen
Makefile +9 -0
+ifdef CONFIG_READABLE_ASM
+# Disable optimizations that make assembler listings hard to read.
+# reorder blocks reorders the control in the function
+# ipa clone creates specialized cloned functions
+# partial inlining inlines only parts of functions
+KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
+                 $(call cc-option,-fno-ipa-cp-clone,) \
+                 $(call cc-option,-fno-partial-inlining)
+endif

This (now in linux-next) causes m68k/allmodconfig to fail for me:

  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
  CC      kernel/bounds.s

cc1: error: unrecognized command line option "-fno-ipa-cp-clone"

Somehow, "$(call cc-option,-fno-ipa-cp-clone,)" doesn't detect that my toolchain (gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)) doesn't support this option.

I tried playing with the trailing comma (why do the first 2 tests have it, and the 3rd one doesn't?), but that didn't make a difference.

linux-next builds (using a newer toolchain) don't show this.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds

#4 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

Quoted 20 lines · Geert Uytterhoeven

Hi Andi,

Makefile else · line 575

Quoted 9 lines · Andi Kleen
Makefile +9 -0
+ifdef CONFIG_READABLE_ASM
+# Disable optimizations that make assembler listings hard to read.
+# reorder blocks reorders the control in the function
+# ipa clone creates specialized cloned functions
+# partial inlining inlines only parts of functions
+KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
+                 $(call cc-option,-fno-ipa-cp-clone,) \
+                 $(call cc-option,-fno-partial-inlining)
+endif

This (now in linux-next) causes m68k/allmodconfig to fail for me:

  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
  CC      kernel/bounds.s

cc1: error: unrecognized command line option "-fno-ipa-cp-clone"

Quoted 9 lines

Somehow, "$(call cc-option,-fno-ipa-cp-clone,)" doesn't detect that my toolchain (gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)) doesn't support this option.

I tried playing with the trailing comma (why do the first 2 tests have it, and the 3rd one doesn't?), but that didn't make a difference.

linux-next builds (using a newer toolchain) don't show this.

Sounds like the fundamental action item is to find out what makes cc-option not work.

-hpa

#5 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

Quoted 23 lines · H. Peter Anvin
Quoted 22 lines · Geert Uytterhoeven

Makefile else · line 575

Quoted 9 lines · Andi Kleen
Makefile +9 -0
+ifdef CONFIG_READABLE_ASM
+# Disable optimizations that make assembler listings hard to read.
+# reorder blocks reorders the control in the function
+# ipa clone creates specialized cloned functions
+# partial inlining inlines only parts of functions
+KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
+                 $(call cc-option,-fno-ipa-cp-clone,) \
+                 $(call cc-option,-fno-partial-inlining)
+endif

This (now in linux-next) causes m68k/allmodconfig to fail for me:

  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
  CC      kernel/bounds.s
cc1: error: unrecognized command line option "-fno-ipa-cp-clone"

Somehow, "$(call cc-option,-fno-ipa-cp-clone,)" doesn't detect that my toolchain (gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)) doesn't support this option.

Quoted 8 lines
Quoted 5 lines

I tried playing with the trailing comma (why do the first 2 tests have it, and the 3rd one doesn't?), but that didn't make a difference.

linux-next builds (using a newer toolchain) don't show this.

Sounds like the fundamental action item is to find out what makes cc-option not work.

FWIW, it did detect that:
- -fno-reorder-blocks is supported,
- -fno-partial-inlining is not supported.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds

#6 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

In reply to Geert Uytterhoeven
Quoted 12 lines · Geert Uytterhoeven

Hi Andi,

Makefile else · line 575

Quoted 9 lines · Andi Kleen
Makefile +9 -0
+ifdef CONFIG_READABLE_ASM
+# Disable optimizations that make assembler listings hard to read.
+# reorder blocks reorders the control in the function
+# ipa clone creates specialized cloned functions
+# partial inlining inlines only parts of functions
+KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
+                 $(call cc-option,-fno-ipa-cp-clone,) \
+                 $(call cc-option,-fno-partial-inlining)
+endif

Could people move to this century and drop these ugly "\" line-continuations please... People seems to get along in C without but think they should be used in Makefiles..

Quoted 5 lines

This (now in linux-next) causes m68k/allmodconfig to fail for me:

  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
  CC      kernel/bounds.s
Quoted 8 lines

cc1: error: unrecognized command line option "-fno-ipa-cp-clone"

Somehow, "$(call cc-option,-fno-ipa-cp-clone,)" doesn't detect that my toolchain (gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)) doesn't support this option.

I tried playing with the trailing comma (why do the first 2 tests have it, and the 3rd one doesn't?), but that didn't make a difference.

The trailing comma does not have any affect - it is only ugly and should be dropped. You should try cc-diasable-warning like this:

KBUILD_CFLAGS += $(call cc-disable-warning, ipa-cp-clone)

from Documentation/kbuild/makefiles.txt:

cc-disable-warning
cc-disable-warning checks if gcc supports a given warning and returns the commandline switch to disable it. This special function is needed, because gcc 4.4 and later accept any unknown -Wno-* option and only warn about it if there is another warning in the source file.

Example:
KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)

In the above example, -Wno-unused-but-set-variable will be added to KBUILD_CFLAGS only if gcc really accepts it.

The documentation refer to gcc 4.4 - but maybe the older gcc you have has the same behaviour.

Sam

#7 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

Hi Sam,

Quoted 14 lines · Sam Ravnborg
Quoted 10 lines · Geert Uytterhoeven

Makefile else · line 575

Quoted 9 lines · Andi Kleen
Makefile +9 -0
+ifdef CONFIG_READABLE_ASM
+# Disable optimizations that make assembler listings hard to read.
+# reorder blocks reorders the control in the function
+# ipa clone creates specialized cloned functions
+# partial inlining inlines only parts of functions
+KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
+                 $(call cc-option,-fno-ipa-cp-clone,) \
+                 $(call cc-option,-fno-partial-inlining)
+endif

Could people move to this century and drop these ugly "\" line-continuations please... People seems to get along in C without but think they should be used in Makefiles..

Not without an additional patch for make:

Makefile:575: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.

Quoted 9 lines
Quoted 5 lines

cc1: error: unrecognized command line option "-fno-ipa-cp-clone"

Somehow, "$(call cc-option,-fno-ipa-cp-clone,)" doesn't detect that my toolchain (gcc version 4.1.2 20061115 (prerelease) (Ubuntu 4.1.1-21)) doesn't support this option.

You should try cc-diasable-warning like this:

KBUILD_CFLAGS += $(call cc-disable-warning, ipa-cp-clone)

That works, thanks!
Andi, does it still work as expected for you?

Quoted 11 lines

from Documentation/kbuild/makefiles.txt:

   cc-disable-warning
       cc-disable-warning checks if gcc supports a given warning and returns the commandline switch to disable it. This special function is needed, because gcc 4.4 and later accept any unknown -Wno-* option and only warn about it if there is another warning in the source file.

       Example:
               KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)

Quoted 6 lines

       In the above example, -Wno-unused-but-set-variable will be added to KBUILD_CFLAGS only if gcc really accepts it.

The documentation refer to gcc 4.4 - but maybe the older gcc you have has the same behaviour.

Seems to be that case. Thx!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds

#8 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

Quoted 18 lines · Geert Uytterhoeven

Hi Sam,

Quoted 14 lines · Sam Ravnborg
Quoted 10 lines · Geert Uytterhoeven

Makefile else · line 575

Quoted 9 lines · Andi Kleen
Makefile +9 -0
+ifdef CONFIG_READABLE_ASM
+# Disable optimizations that make assembler listings hard to read.
+# reorder blocks reorders the control in the function
+# ipa clone creates specialized cloned functions
+# partial inlining inlines only parts of functions
+KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
+                 $(call cc-option,-fno-ipa-cp-clone,) \
+                 $(call cc-option,-fno-partial-inlining)
+endif

Could people move to this century and drop these ugly "\" line-continuations please... People seems to get along in C without but think they should be used in Makefiles..

Quoted 4 lines

Not without an additional patch for make:

Makefile:575: *** missing separator (did you mean TAB instead of 8 spaces?). Stop.

I meant like this:

KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks) KBUILD_CFLAGS += $(call cc-disable-warning,-fno-ipa-cp-clone) KBUILD_CFLAGS += $(call cc-option,-fno-partial-inlining)

Sam

#9 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

In reply to Geert Uytterhoeven
Quoted 6 lines
Quoted 4 lines

You should try cc-diasable-warning like this:

KBUILD_CFLAGS += $(call cc-disable-warning, ipa-cp-clone)

That works, thanks!
Andi, does it still work as expected for you?

No, unfortunately it doesn't enable the flag with my compiler. Also BTW ipa-cp-clone is not a warning, it's an optimization pass.

Sam any other ideas?

-Andi

#10 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

Quoted 9 lines · Andi Kleen
Quoted 6 lines
Quoted 4 lines

You should try cc-diasable-warning like this:

KBUILD_CFLAGS += $(call cc-disable-warning, ipa-cp-clone)

That works, thanks!
Andi, does it still work as expected for you?

No, unfortunately it doesn't enable the flag with my compiler. Also BTW ipa-cp-clone is not a warning, it's an optimization pass.

Yeah I see now.
cc-disable-warning only works on warnings - which starts with -W

Could you try this:

cc-disable-opt = $(call try-run,\
        $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -f$(strip $(1)) -c -xc /dev/null -o "$$TMP",-fno-$(strip $(1)))

KBUILD_CFLAGS += $(call cc-disable-opt, ipa-cp-clone)

It will try if "gcc -fipa-cp-clone" is supported,
and add -fno-ipa-cp-clone in that case.

Sam

#11 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

Hi Sam,

Quoted 10 lines · Sam Ravnborg

Could you try this:

cc-disable-opt = $(call try-run,\
       $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -f$(strip $(1)) -c -xc /dev/null -o "$TMP",-fno-$(strip $(1)))

KBUILD_CFLAGS += $(call cc-disable-opt, ipa-cp-clone)

It will try if "gcc -fipa-cp-clone" is supported,
and add -fno-ipa-cp-clone in that case.

Unfortunately not:

m68k-linux-gnu-gcc -Wp,-MD,kernel/.bounds.s.d -nostdinc -isystem /usr/lib/gcc/m68k-linux-gnu/4.1.2/include -I/scratch/geert/linux/linux-next/arch/m68k/include Iarch/m68k/include/generated -Iinclude -include /scratch/geert/linux/linux-next/include/linux/kconfig.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -Os -fno-reorder-blocks -fno-ipa-cp-clone -pipe -fno-strength-reduce -ffixed-a2 -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(bounds)" -D"KBUILD_MODNAME=KBUILD_STR(bounds)" -fverbose-asm -S -o kernel/bounds.s kernel/bounds.c
cc1: error: unrecognized command line option "-fno-ipa-cp-clone" make[1]: *** [kernel/bounds.s] Error 1
make: *** [prepare0] Error 2

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds

#12 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

Quoted 28 lines · Geert Uytterhoeven

Hi Sam,

Quoted 10 lines · Sam Ravnborg

Could you try this:

cc-disable-opt = $(call try-run,\
       $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -f$(strip $(1)) -c -xc /dev/null -o "$TMP",-fno-$(strip $(1)))

KBUILD_CFLAGS += $(call cc-disable-opt, ipa-cp-clone)

It will try if "gcc -fipa-cp-clone" is supported,
and add -fno-ipa-cp-clone in that case.

Unfortunately not:

m68k-linux-gnu-gcc -Wp,-MD,kernel/.bounds.s.d -nostdinc -isystem /usr/lib/gcc/m68k-linux-gnu/4.1.2/include -I/scratch/geert/linux/linux-next/arch/m68k/include Iarch/m68k/include/generated -Iinclude -include /scratch/geert/linux/linux-next/include/linux/kconfig.h -D__KERNEL__

(quoted diff) +0 -7
-Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
-fno-common -Werror-implicit-function-declaration -Wno-format-security
-fno-delete-null-pointer-checks -Os -fno-reorder-blocks
-fno-ipa-cp-clone -pipe -fno-strength-reduce -ffixed-a2
-fno-omit-frame-pointer -fno-optimize-sibling-calls -g
-D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(bounds)"
-D"KBUILD_MODNAME=KBUILD_STR(bounds)" -fverbose-asm -S -o
Quoted 4 lines

kernel/bounds.s kernel/bounds.c
cc1: error: unrecognized command line option "-fno-ipa-cp-clone" make[1]: *** [kernel/bounds.s] Error 1
make: *** [prepare0] Error 2

So with the above command-line gcc fails with an exit code for -fno-ipa-cp-clone. But with cc-option it does not.

Can you dig out the command-line used for cc-option? We may be able to analyze why it fails in the above case, but not with cc-option.

I wonder if we hit something strange due to the fact that we are assigning to KBUILD_CFLAGS and we reference the same variable.

But that does not explain why the others work.

Sam

#13 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

Quoted 35 lines · Sam Ravnborg
Quoted 26 lines · Geert Uytterhoeven
Quoted 10 lines · Sam Ravnborg

Could you try this:

cc-disable-opt = $(call try-run,\
       $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -f$(strip $(1)) -c -xc /dev/null -o "$TMP",-fno-$(strip $(1)))

KBUILD_CFLAGS += $(call cc-disable-opt, ipa-cp-clone)

It will try if "gcc -fipa-cp-clone" is supported,
and add -fno-ipa-cp-clone in that case.

Unfortunately not:

m68k-linux-gnu-gcc -Wp,-MD,kernel/.bounds.s.d  -nostdinc -isystem /usr/lib/gcc/m68k-linux-gnu/4.1.2/include -I/scratch/geert/linux/linux-next/arch/m68k/include Iarch/m68k/include/generated -Iinclude  -include /scratch/geert/linux/linux-next/include/linux/kconfig.h -D__KERNEL__

(quoted diff) +0 -7
-Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
-fno-common -Werror-implicit-function-declaration -Wno-format-security
-fno-delete-null-pointer-checks -Os -fno-reorder-blocks
-fno-ipa-cp-clone -pipe -fno-strength-reduce -ffixed-a2
-fno-omit-frame-pointer -fno-optimize-sibling-calls -g
-D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(bounds)"
-D"KBUILD_MODNAME=KBUILD_STR(bounds)" -fverbose-asm -S -o
Quoted 4 lines

kernel/bounds.s kernel/bounds.c
cc1: error: unrecognized command line option "-fno-ipa-cp-clone" make[1]: *** [kernel/bounds.s] Error 1
make: *** [prepare0] Error 2

So with the above command-line gcc fails with an exit code for -fno-ipa-cp-clone. But with cc-option it does not.

Quoted 3 lines

Can you dig out the command-line used for cc-option? We may be able to analyze why it fails in the above case, but not with cc-option.

gcc -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -Os -fno-ipa-cp-clone -c -xc /dev/null -o .6376.tmp

So it's running "gcc" instead of "m68k-linux-gnu-gcc".

I used the gmail-damaged patch below to get the command in /tmp/x.

Makefile +1 -1
index d17a616..0e0cbb9 100644
@@ -567,7 +567,7 @@ ifdef CONFIG_READABLE_ASM
 # ipa clone creates specialized cloned functions
 # partial inlining inlines only parts of functions
 KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
-                 $(call cc-option,-fno-ipa-cp-clone,) \
+                 $(call cc-option2,-fno-ipa-cp-clone,) \
                  $(call cc-option,-fno-partial-inlining)
 endif
 
scripts/Kbuild.include +10 -0
index 6a3ee98..41c80bf 100644
@@ -94,6 +94,16 @@ try-run = $(shell set -e;            \
        fi;                             \
        rm -f "$$TMP" "$$TMPO")
 
+try-run2 = $(shell set -e;             \
+       TMP="$(TMPOUT).$$$$.tmp";       \
+       TMPO="$(TMPOUT).$$$$.o";        \
+       echo "$(1)" > /tmp/x;           \
+       if ($(1)) >/dev/null 2>&1;      \
+       then echo "$(2)";               \
+       else echo "$(3)";               \
+       fi;                             \
+       rm -f "$$TMP" "$$TMPO")
+
 # as-option
 # Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
 
@@ -112,6 +122,9 @@ as-instr = $(call try-run,\
 cc-option = $(call try-run,\
        $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc

/dev/null -o "$$TMP",$(1),$(2))

+cc-option2 = $(call try-run2,\
+ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -xc
/dev/null -o "$$TMP",$(1),$(2))
+

 # cc-option-yn
 # Usage: flag := $(call cc-option-yn,-march=winchip-c6)
 cc-option-yn = $(call try-run,\

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds

#14 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

Quoted 45 lines · Geert Uytterhoeven
Quoted 35 lines · Sam Ravnborg
Quoted 26 lines · Geert Uytterhoeven
Quoted 10 lines · Sam Ravnborg

Could you try this:

cc-disable-opt = $(call try-run,\
       $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -f$(strip $(1)) -c -xc /dev/null -o "$TMP",-fno-$(strip $(1)))

KBUILD_CFLAGS += $(call cc-disable-opt, ipa-cp-clone)

It will try if "gcc -fipa-cp-clone" is supported,
and add -fno-ipa-cp-clone in that case.

Unfortunately not:

m68k-linux-gnu-gcc -Wp,-MD,kernel/.bounds.s.d  -nostdinc -isystem /usr/lib/gcc/m68k-linux-gnu/4.1.2/include -I/scratch/geert/linux/linux-next/arch/m68k/include Iarch/m68k/include/generated -Iinclude  -include /scratch/geert/linux/linux-next/include/linux/kconfig.h -D__KERNEL__

(quoted diff) +0 -7
-Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
-fno-common -Werror-implicit-function-declaration -Wno-format-security
-fno-delete-null-pointer-checks -Os -fno-reorder-blocks
-fno-ipa-cp-clone -pipe -fno-strength-reduce -ffixed-a2
-fno-omit-frame-pointer -fno-optimize-sibling-calls -g
-D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(bounds)"
-D"KBUILD_MODNAME=KBUILD_STR(bounds)" -fverbose-asm -S -o
Quoted 4 lines

kernel/bounds.s kernel/bounds.c
cc1: error: unrecognized command line option "-fno-ipa-cp-clone" make[1]: *** [kernel/bounds.s] Error 1
make: *** [prepare0] Error 2

So with the above command-line gcc fails with an exit code for -fno-ipa-cp-clone. But with cc-option it does not.

Quoted 3 lines

Can you dig out the command-line used for cc-option? We may be able to analyze why it fails in the above case, but not with cc-option.

gcc -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs

(quoted diff) +0 -3
-fno-strict-aliasing -fno-common -Werror-implicit-function-declaration
-Wno-format-security -fno-delete-null-pointer-checks -Os
-fno-ipa-cp-clone -c -xc /dev/null -o .6376.tmp
Quoted 1 line

So it's running "gcc" instead of "m68k-linux-gnu-gcc".

Found it using the patch below to log all try-run invocations:

scripts/Kbuild.include +0 -0
index 6a3ee98..12eb839 100644
@@ -88,6 +88,7 @@ TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword

$(KBUILD_EXTMOD))/)

 try-run = $(shell set -e;              \
        TMP="$(TMPOUT).$$$$.tmp";       \
        TMPO="$(TMPOUT).$$$$.o";        \
+       echo "$(1)" >> /tmp/x;          \
        if ($(1)) >/dev/null 2>&1;      \
        then echo "$(2)";               \
        else echo "$(3)";               \
| --- a/Makefile
| +++ b/Makefile
| @@ -564,6 +564,16 @@ else
|  KBUILD_CFLAGS  += -O2
|  endif
|
| +ifdef CONFIG_READABLE_ASM
| +# Disable optimizations that make assembler listings hard to read.
| +# reorder blocks reorders the control in the function
| +# ipa clone creates specialized cloned functions
| +# partial inlining inlines only parts of functions
| +KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
| +                 $(call cc-option,-fno-ipa-cp-clone,) \
| +                 $(call cc-option,-fno-partial-inlining)
| +endif
| +

The above calls cc-option using CC = gcc, as my cross compiler is only setup in the next line:

| include $(srctree)/arch/$(SRCARCH)/Makefile

This affects all architectures that setup CROSS_COMPILE in their arch/*/Makefile (blackfin, h8300, m68k, mips, parisc, score, sh, tile, unicore32, xtensa).

Worse, m68k, sh, and xtensa call cc-option in their arch/*/Makefile before CROSS_COMPILE is setup, causing those checks to be done against the host compiler when cross-compiling.

Sending out patches, as soon as the (automatic) "git gc" completes...

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds

#15 lore raw

Re: [PATCH 2/2] Add CONFIG_READABLE_ASM

Quoted 86 lines · Geert Uytterhoeven
Quoted 45 lines · Geert Uytterhoeven
Quoted 35 lines · Sam Ravnborg
Quoted 26 lines · Geert Uytterhoeven
Quoted 10 lines · Sam Ravnborg

Could you try this:

cc-disable-opt = $(call try-run,\
       $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -f$(strip $(1)) -c -xc /dev/null -o "$TMP",-fno-$(strip $(1)))

KBUILD_CFLAGS += $(call cc-disable-opt, ipa-cp-clone)

It will try if "gcc -fipa-cp-clone" is supported,
and add -fno-ipa-cp-clone in that case.

Unfortunately not:

m68k-linux-gnu-gcc -Wp,-MD,kernel/.bounds.s.d  -nostdinc -isystem /usr/lib/gcc/m68k-linux-gnu/4.1.2/include -I/scratch/geert/linux/linux-next/arch/m68k/include Iarch/m68k/include/generated -Iinclude  -include /scratch/geert/linux/linux-next/include/linux/kconfig.h -D__KERNEL__

(quoted diff) +0 -7
-Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing
-fno-common -Werror-implicit-function-declaration -Wno-format-security
-fno-delete-null-pointer-checks -Os -fno-reorder-blocks
-fno-ipa-cp-clone -pipe -fno-strength-reduce -ffixed-a2
-fno-omit-frame-pointer -fno-optimize-sibling-calls -g
-D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(bounds)"
-D"KBUILD_MODNAME=KBUILD_STR(bounds)" -fverbose-asm -S -o
Quoted 4 lines

kernel/bounds.s kernel/bounds.c
cc1: error: unrecognized command line option "-fno-ipa-cp-clone" make[1]: *** [kernel/bounds.s] Error 1
make: *** [prepare0] Error 2

So with the above command-line gcc fails with an exit code for -fno-ipa-cp-clone. But with cc-option it does not.

Quoted 3 lines

Can you dig out the command-line used for cc-option? We may be able to analyze why it fails in the above case, but not with cc-option.

gcc -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs

(quoted diff) +0 -3
-fno-strict-aliasing -fno-common -Werror-implicit-function-declaration
-Wno-format-security -fno-delete-null-pointer-checks -Os
-fno-ipa-cp-clone -c -xc /dev/null -o .6376.tmp
Quoted 1 line

So it's running "gcc" instead of "m68k-linux-gnu-gcc".

Found it using the patch below to log all try-run invocations:

scripts/Kbuild.include +1 -0
index 6a3ee98..12eb839 100644
@@ -88,6 +88,7 @@ TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword
 $(KBUILD_EXTMOD))/)
 try-run = $(shell set -e;              \
        TMP="$(TMPOUT).$$$$.tmp";       \
        TMPO="$(TMPOUT).$$$$.o";        \
+       echo "$(1)" >> /tmp/x;          \
        if ($(1)) >/dev/null 2>&1;      \
        then echo "$(2)";               \
        else echo "$(3)";               \
| --- a/Makefile
| +++ b/Makefile
| @@ -564,6 +564,16 @@ else
|  KBUILD_CFLAGS  += -O2
|  endif
|
| +ifdef CONFIG_READABLE_ASM
| +# Disable optimizations that make assembler listings hard to read.
| +# reorder blocks reorders the control in the function
| +# ipa clone creates specialized cloned functions
| +# partial inlining inlines only parts of functions
| +KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
| +                 $(call cc-option,-fno-ipa-cp-clone,) \
| +                 $(call cc-option,-fno-partial-inlining)
| +endif
| +

The above calls cc-option using CC = gcc, as my cross compiler is only setup in the next line:

| include $(srctree)/arch/$(SRCARCH)/Makefile

Quoted 8 lines

This affects all architectures that setup CROSS_COMPILE in their arch/*/Makefile (blackfin, h8300, m68k, mips, parisc, score, sh, tile, unicore32, xtensa).

Worse, m68k, sh, and xtensa call cc-option in their arch/*/Makefile before CROSS_COMPILE is setup, causing those checks to be done against the host compiler when cross-compiling.

Sending out patches, as soon as the (automatic) "git gc" completes...

I expected something like this - but I got distraced by some sparc32 work and forgot to return to you.

Great that you found it so we can get this fixed!

Sam

#16 lore raw
In reply to Andi Kleen
Commit-ID:  c0e9afc0da6cb0f11497e5ea83377b3c451450e0
Gitweb:     http://git.kernel.org/tip/c0e9afc0da6cb0f11497e5ea83377b3c451450e0
Author:     Andi Kleen <[email protected]>
AuthorDate: Wed, 28 Mar 2012 11:51:17 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Fri, 30 Mar 2012 10:06:39 -0700

x86: Use -mno-avx when available

On gccs that support AVX it's a good idea to disable that too, similar to how SSE2, SSE1 etc. are already disabled. This prevents the compiler from generating AVX ever implicitely.

No failure observed, just from review.

[ hpa: Marking this for urgent and stable, simply because the patch
will either have absolutely no effect *or* it will avoid potentially very hard to debug failures. ]

---
 arch/x86/Makefile |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/Makefile +1 -0
index 968dbe2..41a7237 100644
@@ -129,6 +129,7 @@ KBUILD_CFLAGS += -Wno-sign-compare
 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
 # prevent gcc from generating any FP code by mistake
 KBUILD_CFLAGS += $(call cc-option,-mno-sse -mno-mmx -mno-sse2 -mno-3dnow,)
+KBUILD_CFLAGS += $(call cc-option,-mno-avx,)
 
 KBUILD_CFLAGS += $(mflags-y)
 KBUILD_AFLAGS += $(mflags-y)