All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] kbuild and powerpc patches for new Kconfig language
@ 2018-05-10  5:16 Nicholas Piggin
  2018-05-10  5:16 ` [PATCH v2 1/5] powerpc/kbuild: set default generic machine type for 32-bit compile Nicholas Piggin
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Nicholas Piggin @ 2018-05-10  5:16 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Nicholas Piggin, Masahiro Yamada, linuxppc-dev

I came back to these patches and I think I have solved the remaining
problems -- it now builds with 64-bit big and little endian (using a
le toolchain), and also 32-bit big using 64le toolchain. There might
be some build failures still left, but it seems to be in much better
shape now.

Reviews would be welcome. I don't quite know how it should be merged,
maybe via the kbuild tree after acks from powerpc maintainer. We can
decide that after it gets more testing and review.

Thanks,
Nick

Nicholas Piggin (5):
  powerpc/kbuild: set default generic machine type for 32-bit compile
  powerpc/kbuild: remove CROSS32 defines from top level powerpc Makefile
  kbuild: call cc-option with the current set of KBUILD_CFLAGS
  powerpc/kbuild: Use flags variables rather than overriding LD/CC/AS
  powerpc/kbuild: move -mprofile-kernel check to Kconfig

 arch/powerpc/Kconfig                          | 16 +------
 arch/powerpc/Makefile                         | 46 +++++++------------
 arch/powerpc/boot/Makefile                    | 16 +++++--
 arch/powerpc/kernel/vdso32/Makefile           | 15 ++++--
 .../tools/gcc-check-mprofile-kernel.sh        |  4 +-
 scripts/Kbuild.include                        |  8 ++--
 scripts/recordmcount.pl                       |  8 ++++
 7 files changed, 54 insertions(+), 59 deletions(-)

-- 
2.17.0


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

* [PATCH v2 1/5] powerpc/kbuild: set default generic machine type for 32-bit compile
  2018-05-10  5:16 [PATCH v2 0/5] kbuild and powerpc patches for new Kconfig language Nicholas Piggin
@ 2018-05-10  5:16 ` Nicholas Piggin
  2018-05-10 13:10   ` Segher Boessenkool
  2018-05-10 14:52   ` Segher Boessenkool
  2018-05-10  5:16 ` [PATCH v2 2/5] powerpc/kbuild: remove CROSS32 defines from top level powerpc Makefile Nicholas Piggin
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 15+ messages in thread
From: Nicholas Piggin @ 2018-05-10  5:16 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Nicholas Piggin, Masahiro Yamada, linuxppc-dev

The 64-bit toolchain uses the wrong ISA variant for compiling 32-bit
kernels, eve with -m32. Set -mcpu=powerpc which is the generic 32-bit
powerpc machine type and scheduling model. 32-bit platforms and CPUs
can override this with -mcpu= options that come later on the command
line.

This fixes a lot of build failures due to incompatible assembly when
compiling 32-bit kernel with 64-bit toolchain.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/Makefile | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 95813df90801..7034b1ad50e0 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -27,6 +27,14 @@ KBUILD_ARFLAGS	+= --target=elf32-powerpc
 endif
 endif
 
+ifdef CONFIG_PPC32
+# These options will be overridden by any -mcpu option that comes
+# later on the command line, but they are needed to set a sane
+# 32-bit cpu target for the 64-bit cross compiler.
+KBUILD_CFLAGS		+= -mcpu=powerpc
+KBUILD_AFLAGS		+= -mcpu=powerpc
+endif
+
 export CROSS32CC CROSS32AR
 
 ifeq ($(CROSS_COMPILE),)
-- 
2.17.0


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

* [PATCH v2 2/5] powerpc/kbuild: remove CROSS32 defines from top level powerpc Makefile
  2018-05-10  5:16 [PATCH v2 0/5] kbuild and powerpc patches for new Kconfig language Nicholas Piggin
  2018-05-10  5:16 ` [PATCH v2 1/5] powerpc/kbuild: set default generic machine type for 32-bit compile Nicholas Piggin
@ 2018-05-10  5:16 ` Nicholas Piggin
  2018-05-10  5:16 ` [PATCH v2 3/5] kbuild: call cc-option with the current set of KBUILD_CFLAGS Nicholas Piggin
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Nicholas Piggin @ 2018-05-10  5:16 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Nicholas Piggin, Masahiro Yamada, linuxppc-dev

Switch VDSO32 build over to use CROSS32_COMPILE directly, and have
it pass in -m32 after the standard c_flags. This allows endianness
overrides to be removed and the endian and bitness flags moved into
standard flags variables.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/Makefile               | 12 ------------
 arch/powerpc/boot/Makefile          | 16 +++++++++++-----
 arch/powerpc/kernel/vdso32/Makefile | 15 +++++++++++----
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 7034b1ad50e0..a40f59ca2afe 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -17,16 +17,6 @@ HAS_BIARCH	:= $(call cc-option-yn, -m32)
 # Set default 32 bits cross compilers for vdso and boot wrapper
 CROSS32_COMPILE ?=
 
-CROSS32CC		:= $(CROSS32_COMPILE)gcc
-CROSS32AR		:= $(CROSS32_COMPILE)ar
-
-ifeq ($(HAS_BIARCH),y)
-ifeq ($(CROSS32_COMPILE),)
-CROSS32CC	:= $(CC) -m32
-KBUILD_ARFLAGS	+= --target=elf32-powerpc
-endif
-endif
-
 ifdef CONFIG_PPC32
 # These options will be overridden by any -mcpu option that comes
 # later on the command line, but they are needed to set a sane
@@ -35,8 +25,6 @@ KBUILD_CFLAGS		+= -mcpu=powerpc
 KBUILD_AFLAGS		+= -mcpu=powerpc
 endif
 
-export CROSS32CC CROSS32AR
-
 ifeq ($(CROSS_COMPILE),)
 KBUILD_DEFCONFIG := $(shell uname -m)_defconfig
 else
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 26d5d2a5b8e9..49767e06202c 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -23,19 +23,23 @@ all: $(obj)/zImage
 compress-$(CONFIG_KERNEL_GZIP) := CONFIG_KERNEL_GZIP
 compress-$(CONFIG_KERNEL_XZ)   := CONFIG_KERNEL_XZ
 
+ifdef CROSS32_COMPILE
+    BOOTCC := $(CROSS32_COMPILE)gcc
+    BOOTAR := $(CROSS32_COMPILE)ar
+else
+    BOOTCC := $(CC)
+    BOOTAR := $(AR)
+endif
+
 BOOTCFLAGS    := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
 		 -fno-strict-aliasing -Os -msoft-float -pipe \
 		 -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
 		 -D$(compress-y)
 
-BOOTCC := $(CC)
 ifdef CONFIG_PPC64_BOOT_WRAPPER
 BOOTCFLAGS	+= -m64
 else
 BOOTCFLAGS	+= -m32
-ifdef CROSS32_COMPILE
-    BOOTCC := $(CROSS32_COMPILE)gcc
-endif
 endif
 
 BOOTCFLAGS	+= -isystem $(shell $(BOOTCC) -print-file-name=include)
@@ -49,6 +53,8 @@ endif
 
 BOOTAFLAGS	:= -D__ASSEMBLY__ $(BOOTCFLAGS) -traditional -nostdinc
 
+BOOTARFLAGS	:= -cr$(KBUILD_ARFLAGS)
+
 ifdef CONFIG_DEBUG_INFO
 BOOTCFLAGS	+= -g
 endif
@@ -202,7 +208,7 @@ quiet_cmd_bootas = BOOTAS  $@
       cmd_bootas = $(BOOTCC) -Wp,-MD,$(depfile) $(BOOTAFLAGS) -c -o $@ $<
 
 quiet_cmd_bootar = BOOTAR  $@
-      cmd_bootar = $(CROSS32AR) -cr$(KBUILD_ARFLAGS) $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@
+      cmd_bootar = $(BOOTAR) $(BOOTARFLAGS) $@.$$$$ $(filter-out FORCE,$^); mv $@.$$$$ $@
 
 $(obj-libfdt): $(obj)/%.o: $(srctree)/scripts/dtc/libfdt/%.c FORCE
 	$(call if_changed_dep,bootcc)
diff --git a/arch/powerpc/kernel/vdso32/Makefile b/arch/powerpc/kernel/vdso32/Makefile
index b8c434d1d459..50112d4473bb 100644
--- a/arch/powerpc/kernel/vdso32/Makefile
+++ b/arch/powerpc/kernel/vdso32/Makefile
@@ -8,8 +8,15 @@ obj-vdso32 = sigtramp.o gettimeofday.o datapage.o cacheflush.o note.o \
 
 # Build rules
 
-ifeq ($(CONFIG_PPC32),y)
-CROSS32CC := $(CC)
+ifdef CROSS32_COMPILE
+    VDSOCC := $(CROSS32_COMPILE)gcc
+else
+    VDSOCC := $(CC)
+endif
+
+CC32FLAGS :=
+ifdef CONFIG_PPC64
+CC32FLAGS += -m32
 endif
 
 targets := $(obj-vdso32) vdso32.so vdso32.so.dbg
@@ -45,9 +52,9 @@ $(obj-vdso32): %.o: %.S FORCE
 
 # actual build commands
 quiet_cmd_vdso32ld = VDSO32L $@
-      cmd_vdso32ld = $(CROSS32CC) $(c_flags) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^)
+      cmd_vdso32ld = $(VDSOCC) $(c_flags) $(CC32FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^)
 quiet_cmd_vdso32as = VDSO32A $@
-      cmd_vdso32as = $(CROSS32CC) $(a_flags) -c -o $@ $<
+      cmd_vdso32as = $(VDSOCC) $(a_flags) $(CC32FLAGS) -c -o $@ $<
 
 # install commands for the unstripped file
 quiet_cmd_vdso_install = INSTALL $@
-- 
2.17.0


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

* [PATCH v2 3/5] kbuild: call cc-option with the current set of KBUILD_CFLAGS
  2018-05-10  5:16 [PATCH v2 0/5] kbuild and powerpc patches for new Kconfig language Nicholas Piggin
  2018-05-10  5:16 ` [PATCH v2 1/5] powerpc/kbuild: set default generic machine type for 32-bit compile Nicholas Piggin
  2018-05-10  5:16 ` [PATCH v2 2/5] powerpc/kbuild: remove CROSS32 defines from top level powerpc Makefile Nicholas Piggin
@ 2018-05-10  5:16 ` Nicholas Piggin
  2018-05-10  5:29   ` Masahiro Yamada
  2018-05-10  5:16 ` [PATCH v2 4/5] powerpc/kbuild: Use flags variables rather than overriding LD/CC/AS Nicholas Piggin
  2018-05-10  5:16 ` [PATCH v2 5/5] powerpc/kbuild: move -mprofile-kernel check to Kconfig Nicholas Piggin
  4 siblings, 1 reply; 15+ messages in thread
From: Nicholas Piggin @ 2018-05-10  5:16 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Nicholas Piggin, Masahiro Yamada, linuxppc-dev

In some cases, the options that gcc will accept depend on options it
has already been given. For example -m32 / -m64 and -mbig-endian /
-mlittle-endian can have this affect.

Passing in KBUILD_CFLAGS to cc-option allows an architecture to
set such basic machine types at the beginning, rather than override
CC itself.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 scripts/Kbuild.include | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 9f7eb10079cc..66869bb815d2 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -121,7 +121,7 @@ CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
 # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
 
 cc-option = $(call __cc-option, $(CC),\
-	$(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2))
+	$(KBUILD_CFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2))
 
 # hostcc-option
 # Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586)
@@ -131,12 +131,12 @@ hostcc-option = $(call __cc-option, $(HOSTCC),\
 # cc-option-yn
 # Usage: flag := $(call cc-option-yn,-march=winchip-c6)
 cc-option-yn = $(call try-run,\
-	$(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
+	$(CC) -Werror $(KBUILD_CFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
 
 # cc-disable-warning
 # Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
 cc-disable-warning = $(call try-run,\
-	$(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
+	$(CC) -Werror $(KBUILD_CFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
 
 # cc-name
 # Expands to either gcc or clang
@@ -160,7 +160,7 @@ cc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo
 # cc-ldoption
 # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
 cc-ldoption = $(call try-run,\
-	$(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
+	$(CC) $(1) $(KBUILD_CFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
 
 # ld-option
 # Usage: LDFLAGS += $(call ld-option, -X)
-- 
2.17.0


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

* [PATCH v2 4/5] powerpc/kbuild: Use flags variables rather than overriding LD/CC/AS
  2018-05-10  5:16 [PATCH v2 0/5] kbuild and powerpc patches for new Kconfig language Nicholas Piggin
                   ` (2 preceding siblings ...)
  2018-05-10  5:16 ` [PATCH v2 3/5] kbuild: call cc-option with the current set of KBUILD_CFLAGS Nicholas Piggin
@ 2018-05-10  5:16 ` Nicholas Piggin
  2018-05-10 13:03     ` Michael Ellerman
  2018-05-10  5:16 ` [PATCH v2 5/5] powerpc/kbuild: move -mprofile-kernel check to Kconfig Nicholas Piggin
  4 siblings, 1 reply; 15+ messages in thread
From: Nicholas Piggin @ 2018-05-10  5:16 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Nicholas Piggin, Masahiro Yamada, linuxppc-dev

The powerpc toolchain can compile combinations of 32/64 bit and
big/little endian, so it's convenient to consider, e.g.,

  `CC -m64 -mbig-endian`

To be the C compiler for the purpose of invoking it to build target
artifacts. So overriding the the CC variable to include thse flags
works for this purpose.

Unfortunately that is not compatible with the way the proposed new
Kconfig macro language will work.

After previous patches in this series, these flags can be carefully
passed in using flags instead.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/Makefile   | 16 +++++++++-------
 scripts/recordmcount.pl |  8 ++++++++
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index a40f59ca2afe..5f3ec8029e50 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -70,13 +70,15 @@ endif
 endif
 
 ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
-override LD	+= -EL
+KBUILD_CFLAGS	+= -mlittle-endian
+LDFLAGS		+= -EL
 LDEMULATION	:= lppc
 GNUTARGET	:= powerpcle
 MULTIPLEWORD	:= -mno-multiple
 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect)
 else
-override LD	+= -EB
+KBUILD_CFLAGS += $(call cc-option,-mbig-endian)
+LDFLAGS		+= -EB
 LDEMULATION	:= ppc
 GNUTARGET	:= powerpc
 MULTIPLEWORD	:= -mmultiple
@@ -89,19 +91,19 @@ aflags-$(CONFIG_CPU_BIG_ENDIAN)		+= $(call cc-option,-mabi=elfv1)
 aflags-$(CONFIG_CPU_LITTLE_ENDIAN)	+= -mabi=elfv2
 endif
 
-cflags-$(CONFIG_CPU_LITTLE_ENDIAN)	+= -mlittle-endian
-cflags-$(CONFIG_CPU_BIG_ENDIAN)		+= $(call cc-option,-mbig-endian)
 ifneq ($(cc-name),clang)
   cflags-$(CONFIG_CPU_LITTLE_ENDIAN)	+= -mno-strict-align
 endif
 
+cflags-$(CONFIG_CPU_BIG_ENDIAN)		+= $(call cc-option,-mbig-endian)
+cflags-$(CONFIG_CPU_LITTLE_ENDIAN)	+= -mlittle-endian
 aflags-$(CONFIG_CPU_BIG_ENDIAN)		+= $(call cc-option,-mbig-endian)
 aflags-$(CONFIG_CPU_LITTLE_ENDIAN)	+= -mlittle-endian
 
 ifeq ($(HAS_BIARCH),y)
-override AS	+= -a$(BITS)
-override LD	+= -m elf$(BITS)$(LDEMULATION)
-override CC	+= -m$(BITS)
+KBUILD_CFLAGS	+= -m$(BITS)
+KBUILD_AFLAGS	+= -m$(BITS) -Wl,-a$(BITS)
+LDFLAGS		+= -m elf$(BITS)$(LDEMULATION)
 KBUILD_ARFLAGS	+= --target=elf$(BITS)-$(GNUTARGET)
 endif
 
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
index 191eb949d52c..919711dd9d6c 100755
--- a/scripts/recordmcount.pl
+++ b/scripts/recordmcount.pl
@@ -274,6 +274,14 @@ if ($arch eq "x86_64") {
     if ($bits == 64) {
 	$type = ".quad";
     }
+    $ld .= " -EB ";
+    if ($endian eq "big") {
+	    $cc .= " -mbig-endian ";
+	    $ld .= " -EB ";
+    } else {
+	    $cc .= " -mlittle-endian ";
+	    $ld .= " -EL ";
+    }
 
 } elsif ($arch eq "arm") {
     $alignment = 2;
-- 
2.17.0


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

* [PATCH v2 5/5] powerpc/kbuild: move -mprofile-kernel check to Kconfig
  2018-05-10  5:16 [PATCH v2 0/5] kbuild and powerpc patches for new Kconfig language Nicholas Piggin
                   ` (3 preceding siblings ...)
  2018-05-10  5:16 ` [PATCH v2 4/5] powerpc/kbuild: Use flags variables rather than overriding LD/CC/AS Nicholas Piggin
@ 2018-05-10  5:16 ` Nicholas Piggin
  4 siblings, 0 replies; 15+ messages in thread
From: Nicholas Piggin @ 2018-05-10  5:16 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Nicholas Piggin, Masahiro Yamada, linuxppc-dev

This eliminates the workaround that requires disabling
-mprofile-kernel by default in Kconfig.

[ Note: this depends on https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git kconfig-shell-v3 ]

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/Kconfig                            | 16 +---------------
 arch/powerpc/Makefile                           | 14 ++------------
 arch/powerpc/tools/gcc-check-mprofile-kernel.sh |  4 ++--
 3 files changed, 5 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 512fcc177c87..af527f894f9b 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -460,23 +460,9 @@ config LD_HEAD_STUB_CATCH
 
 	  If unsure, say "N".
 
-config DISABLE_MPROFILE_KERNEL
-	bool "Disable use of mprofile-kernel for kernel tracing"
-	depends on PPC64 && CPU_LITTLE_ENDIAN
-	default y
-	help
-	  Selecting this options disables use of the mprofile-kernel ABI for
-	  kernel tracing. That will cause options such as live patching
-	  (CONFIG_LIVEPATCH) which depend on CONFIG_DYNAMIC_FTRACE_WITH_REGS to
-	  be disabled also.
-
-	  If you have a toolchain which supports mprofile-kernel, then you can
-	  disable this. Otherwise leave it enabled. If you're not sure, say
-	  "Y".
-
 config MPROFILE_KERNEL
 	depends on PPC64 && CPU_LITTLE_ENDIAN
-	def_bool !DISABLE_MPROFILE_KERNEL
+	def_bool $(success $(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -I$(srctree)/include -D__KERNEL__)
 
 config IOMMU_HELPER
 	def_bool PPC64
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 5f3ec8029e50..9f69b1599c61 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -156,18 +156,8 @@ CFLAGS-$(CONFIG_GENERIC_CPU) += -mcpu=powerpc64
 endif
 
 ifdef CONFIG_MPROFILE_KERNEL
-    ifeq ($(shell $(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -I$(srctree)/include -D__KERNEL__),OK)
-        CC_FLAGS_FTRACE := -pg -mprofile-kernel
-        KBUILD_CPPFLAGS += -DCC_USING_MPROFILE_KERNEL
-    else
-        # If the user asked for mprofile-kernel but the toolchain doesn't
-        # support it, emit a warning and deliberately break the build later
-        # with mprofile-kernel-not-supported. We would prefer to make this an
-        # error right here, but then the user would never be able to run
-        # oldconfig to change their configuration.
-        $(warning Compiler does not support mprofile-kernel, set CONFIG_DISABLE_MPROFILE_KERNEL)
-        CC_FLAGS_FTRACE := -mprofile-kernel-not-supported
-    endif
+	CC_FLAGS_FTRACE := -pg -mprofile-kernel
+	KBUILD_CPPFLAGS += -DCC_USING_MPROFILE_KERNEL
 endif
 
 CFLAGS-$(CONFIG_CELL_CPU) += $(call cc-option,-mcpu=cell)
diff --git a/arch/powerpc/tools/gcc-check-mprofile-kernel.sh b/arch/powerpc/tools/gcc-check-mprofile-kernel.sh
index 061f8035bdbe..ec4486a9c4a3 100755
--- a/arch/powerpc/tools/gcc-check-mprofile-kernel.sh
+++ b/arch/powerpc/tools/gcc-check-mprofile-kernel.sh
@@ -10,13 +10,13 @@ set -o pipefail
 # Test whether the compile option -mprofile-kernel exists and generates
 # profiling code (ie. a call to _mcount()).
 echo "int func() { return 0; }" | \
-    $* -S -x c -O2 -p -mprofile-kernel - -o - 2> /dev/null | \
+    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - 2> /dev/null | \
     grep -q "_mcount"
 
 # Test whether the notrace attribute correctly suppresses calls to _mcount().
 
 echo -e "#include <linux/compiler.h>\nnotrace int func() { return 0; }" | \
-    $* -S -x c -O2 -p -mprofile-kernel - -o - 2> /dev/null | \
+    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - 2> /dev/null | \
     grep -q "_mcount" && \
     exit 1
 
-- 
2.17.0


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

* Re: [PATCH v2 3/5] kbuild: call cc-option with the current set of KBUILD_CFLAGS
  2018-05-10  5:16 ` [PATCH v2 3/5] kbuild: call cc-option with the current set of KBUILD_CFLAGS Nicholas Piggin
@ 2018-05-10  5:29   ` Masahiro Yamada
  2018-05-10  6:09     ` Nicholas Piggin
  0 siblings, 1 reply; 15+ messages in thread
From: Masahiro Yamada @ 2018-05-10  5:29 UTC (permalink / raw)
  To: Nicholas Piggin; +Cc: Linux Kbuild mailing list, linuxppc-dev

2018-05-10 14:16 GMT+09:00 Nicholas Piggin <npiggin@gmail.com>:
> In some cases, the options that gcc will accept depend on options it
> has already been given. For example -m32 / -m64 and -mbig-endian /
> -mlittle-endian can have this affect.

Is cc-option not working for you?


> Passing in KBUILD_CFLAGS to cc-option allows an architecture to
> set such basic machine types at the beginning, rather than override
> CC itself.

KBUILD_CFLAGS is passed to cc-option already
because CC_OPTION_CFLAGS includes it:

CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))



This patch drops KBUILD_CPPFLAGS,
and adds KBUILD_CFLAGS twice, doesn't it?



> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  scripts/Kbuild.include | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> index 9f7eb10079cc..66869bb815d2 100644
> --- a/scripts/Kbuild.include
> +++ b/scripts/Kbuild.include
> @@ -121,7 +121,7 @@ CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
>  # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
>
>  cc-option = $(call __cc-option, $(CC),\
> -       $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2))
> +       $(KBUILD_CFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2))
>
>  # hostcc-option
>  # Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586)
> @@ -131,12 +131,12 @@ hostcc-option = $(call __cc-option, $(HOSTCC),\
>  # cc-option-yn
>  # Usage: flag := $(call cc-option-yn,-march=winchip-c6)
>  cc-option-yn = $(call try-run,\
> -       $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
> +       $(CC) -Werror $(KBUILD_CFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
>
>  # cc-disable-warning
>  # Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
>  cc-disable-warning = $(call try-run,\
> -       $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
> +       $(CC) -Werror $(KBUILD_CFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
>
>  # cc-name
>  # Expands to either gcc or clang
> @@ -160,7 +160,7 @@ cc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo
>  # cc-ldoption
>  # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
>  cc-ldoption = $(call try-run,\
> -       $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
> +       $(CC) $(1) $(KBUILD_CFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
>
>  # ld-option
>  # Usage: LDFLAGS += $(call ld-option, -X)
> --
> 2.17.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Best Regards
Masahiro Yamada

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

* Re: [PATCH v2 3/5] kbuild: call cc-option with the current set of KBUILD_CFLAGS
  2018-05-10  5:29   ` Masahiro Yamada
@ 2018-05-10  6:09     ` Nicholas Piggin
  0 siblings, 0 replies; 15+ messages in thread
From: Nicholas Piggin @ 2018-05-10  6:09 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: Linux Kbuild mailing list, linuxppc-dev

On Thu, 10 May 2018 14:29:49 +0900
Masahiro Yamada <yamada.masahiro@socionext.com> wrote:

> 2018-05-10 14:16 GMT+09:00 Nicholas Piggin <npiggin@gmail.com>:
> > In some cases, the options that gcc will accept depend on options it
> > has already been given. For example -m32 / -m64 and -mbig-endian /
> > -mlittle-endian can have this affect.  
> 
> Is cc-option not working for you?

I thought it wasn't, but now I try again and it does work, sorry for
the noise. The bug must have been something in my previous series.
This series seems to work just as well after I remove this patch.

Thanks,
Nick

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

* Re: [PATCH v2 4/5] powerpc/kbuild: Use flags variables rather than overriding LD/CC/AS
  2018-05-10  5:16 ` [PATCH v2 4/5] powerpc/kbuild: Use flags variables rather than overriding LD/CC/AS Nicholas Piggin
@ 2018-05-10 13:03     ` Michael Ellerman
  0 siblings, 0 replies; 15+ messages in thread
From: Michael Ellerman @ 2018-05-10 13:03 UTC (permalink / raw)
  To: Nicholas Piggin, linux-kbuild; +Cc: Masahiro Yamada, linuxppc-dev

Nicholas Piggin <npiggin@gmail.com> writes:

> The powerpc toolchain can compile combinations of 32/64 bit and
> big/little endian, so it's convenient to consider, e.g.,
>
>   `CC -m64 -mbig-endian`
>
> To be the C compiler for the purpose of invoking it to build target
> artifacts. So overriding the the CC variable to include thse flags
> works for this purpose.
>
> Unfortunately that is not compatible with the way the proposed new
> Kconfig macro language will work.
>
> After previous patches in this series, these flags can be carefully
> passed in using flags instead.
>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  arch/powerpc/Makefile   | 16 +++++++++-------
>  scripts/recordmcount.pl |  8 ++++++++

We should probably at least Cc Rostedt on the recordmcount.pl change.

> diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
> index 191eb949d52c..919711dd9d6c 100755
> --- a/scripts/recordmcount.pl
> +++ b/scripts/recordmcount.pl
> @@ -274,6 +274,14 @@ if ($arch eq "x86_64") {

Despite what the above says you're patching the powerpc entry AFAICS, so
I guess that's pretty harmless.

>      if ($bits == 64) {
>  	$type = ".quad";
>      }
> +    $ld .= " -EB ";
> +    if ($endian eq "big") {
> +	    $cc .= " -mbig-endian ";
> +	    $ld .= " -EB ";

Don't we end up with two "-EB"s for the big endian case?

Or do I understand perl even less than I thought I did?

> +    } else {
> +	    $cc .= " -mlittle-endian ";
> +	    $ld .= " -EL ";
> +    }
>  
>  } elsif ($arch eq "arm") {
>      $alignment = 2;

cheers

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

* Re: [PATCH v2 4/5] powerpc/kbuild: Use flags variables rather than overriding LD/CC/AS
@ 2018-05-10 13:03     ` Michael Ellerman
  0 siblings, 0 replies; 15+ messages in thread
From: Michael Ellerman @ 2018-05-10 13:03 UTC (permalink / raw)
  To: Nicholas Piggin, linux-kbuild
  Cc: Masahiro Yamada, linuxppc-dev, Nicholas Piggin

Nicholas Piggin <npiggin@gmail.com> writes:

> The powerpc toolchain can compile combinations of 32/64 bit and
> big/little endian, so it's convenient to consider, e.g.,
>
>   `CC -m64 -mbig-endian`
>
> To be the C compiler for the purpose of invoking it to build target
> artifacts. So overriding the the CC variable to include thse flags
> works for this purpose.
>
> Unfortunately that is not compatible with the way the proposed new
> Kconfig macro language will work.
>
> After previous patches in this series, these flags can be carefully
> passed in using flags instead.
>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  arch/powerpc/Makefile   | 16 +++++++++-------
>  scripts/recordmcount.pl |  8 ++++++++

We should probably at least Cc Rostedt on the recordmcount.pl change.

> diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
> index 191eb949d52c..919711dd9d6c 100755
> --- a/scripts/recordmcount.pl
> +++ b/scripts/recordmcount.pl
> @@ -274,6 +274,14 @@ if ($arch eq "x86_64") {

Despite what the above says you're patching the powerpc entry AFAICS, so
I guess that's pretty harmless.

>      if ($bits == 64) {
>  	$type = ".quad";
>      }
> +    $ld .= " -EB ";
> +    if ($endian eq "big") {
> +	    $cc .= " -mbig-endian ";
> +	    $ld .= " -EB ";

Don't we end up with two "-EB"s for the big endian case?

Or do I understand perl even less than I thought I did?

> +    } else {
> +	    $cc .= " -mlittle-endian ";
> +	    $ld .= " -EL ";
> +    }
>  
>  } elsif ($arch eq "arm") {
>      $alignment = 2;

cheers

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

* Re: [PATCH v2 1/5] powerpc/kbuild: set default generic machine type for 32-bit compile
  2018-05-10  5:16 ` [PATCH v2 1/5] powerpc/kbuild: set default generic machine type for 32-bit compile Nicholas Piggin
@ 2018-05-10 13:10   ` Segher Boessenkool
  2018-05-10 13:24     ` Nicholas Piggin
  2018-05-10 14:52   ` Segher Boessenkool
  1 sibling, 1 reply; 15+ messages in thread
From: Segher Boessenkool @ 2018-05-10 13:10 UTC (permalink / raw)
  To: Nicholas Piggin; +Cc: linux-kbuild, Masahiro Yamada, linuxppc-dev

On Thu, May 10, 2018 at 03:16:55PM +1000, Nicholas Piggin wrote:
> The 64-bit toolchain uses the wrong ISA variant for compiling 32-bit
> kernels, eve with -m32. Set -mcpu=powerpc which is the generic 32-bit
> powerpc machine type and scheduling model. 32-bit platforms and CPUs
> can override this with -mcpu= options that come later on the command
> line.
> 
> This fixes a lot of build failures due to incompatible assembly when
> compiling 32-bit kernel with 64-bit toolchain.

So what ISA is set for gas without this patch?  With what GCC version?
And, why is that wrong?


Segher


> +ifdef CONFIG_PPC32
> +# These options will be overridden by any -mcpu option that comes
> +# later on the command line, but they are needed to set a sane
> +# 32-bit cpu target for the 64-bit cross compiler.
> +KBUILD_CFLAGS		+= -mcpu=powerpc
> +KBUILD_AFLAGS		+= -mcpu=powerpc
> +endif

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

* Re: [PATCH v2 4/5] powerpc/kbuild: Use flags variables rather than overriding LD/CC/AS
  2018-05-10 13:03     ` Michael Ellerman
  (?)
@ 2018-05-10 13:11     ` Nicholas Piggin
  -1 siblings, 0 replies; 15+ messages in thread
From: Nicholas Piggin @ 2018-05-10 13:11 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linux-kbuild, Masahiro Yamada, linuxppc-dev

On Thu, 10 May 2018 23:03:08 +1000
Michael Ellerman <mpe@ellerman.id.au> wrote:

> Nicholas Piggin <npiggin@gmail.com> writes:
> 
> > The powerpc toolchain can compile combinations of 32/64 bit and
> > big/little endian, so it's convenient to consider, e.g.,
> >
> >   `CC -m64 -mbig-endian`
> >
> > To be the C compiler for the purpose of invoking it to build target
> > artifacts. So overriding the the CC variable to include thse flags
> > works for this purpose.
> >
> > Unfortunately that is not compatible with the way the proposed new
> > Kconfig macro language will work.
> >
> > After previous patches in this series, these flags can be carefully
> > passed in using flags instead.
> >
> > Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> > ---
> >  arch/powerpc/Makefile   | 16 +++++++++-------
> >  scripts/recordmcount.pl |  8 ++++++++  
> 
> We should probably at least Cc Rostedt on the recordmcount.pl change.

Sure I'll send another iteration after some more time for reviews and
cc him on it.

> 
> > diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
> > index 191eb949d52c..919711dd9d6c 100755
> > --- a/scripts/recordmcount.pl
> > +++ b/scripts/recordmcount.pl
> > @@ -274,6 +274,14 @@ if ($arch eq "x86_64") {  
> 
> Despite what the above says you're patching the powerpc entry AFAICS, so
> I guess that's pretty harmless.

Yeah I didn't think it was worth a separate patch.

> 
> >      if ($bits == 64) {
> >  	$type = ".quad";
> >      }
> > +    $ld .= " -EB ";
> > +    if ($endian eq "big") {
> > +	    $cc .= " -mbig-endian ";
> > +	    $ld .= " -EB ";  
> 
> Don't we end up with two "-EB"s for the big endian case?
> 
> Or do I understand perl even less than I thought I did?

No I was testing things and that's leaked into the commit. Good eye. I
think it worked for le because the next -EL will override the first -EB,
but I'll take that out.

Thanks,
Nick

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

* Re: [PATCH v2 1/5] powerpc/kbuild: set default generic machine type for 32-bit compile
  2018-05-10 13:10   ` Segher Boessenkool
@ 2018-05-10 13:24     ` Nicholas Piggin
  2018-05-10 14:29       ` Segher Boessenkool
  0 siblings, 1 reply; 15+ messages in thread
From: Nicholas Piggin @ 2018-05-10 13:24 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linux-kbuild, Masahiro Yamada, linuxppc-dev

On Thu, 10 May 2018 08:10:03 -0500
Segher Boessenkool <segher@kernel.crashing.org> wrote:

> On Thu, May 10, 2018 at 03:16:55PM +1000, Nicholas Piggin wrote:
> > The 64-bit toolchain uses the wrong ISA variant for compiling 32-bit
> > kernels, eve with -m32. Set -mcpu=powerpc which is the generic 32-bit
> > powerpc machine type and scheduling model. 32-bit platforms and CPUs
> > can override this with -mcpu= options that come later on the command
> > line.
> > 
> > This fixes a lot of build failures due to incompatible assembly when
> > compiling 32-bit kernel with 64-bit toolchain.  
> 
> So what ISA is set for gas without this patch?  With what GCC version?

I'm not sure, how do I find that out?

> And, why is that wrong?

Some 32-bit platforms and CPU types do not provide -mcpu, so I assume
for 32-bit toolchains that must result in the "powerpc" machine. With
64-bit toolchains 

arch/powerpc/mm/hash_low_32.S:353: Error: missing operand

Which is,

        tlbie   r4

Is that v2.06?

Thanks,
Nick

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

* Re: [PATCH v2 1/5] powerpc/kbuild: set default generic machine type for 32-bit compile
  2018-05-10 13:24     ` Nicholas Piggin
@ 2018-05-10 14:29       ` Segher Boessenkool
  0 siblings, 0 replies; 15+ messages in thread
From: Segher Boessenkool @ 2018-05-10 14:29 UTC (permalink / raw)
  To: Nicholas Piggin; +Cc: linux-kbuild, Masahiro Yamada, linuxppc-dev

On Thu, May 10, 2018 at 11:24:40PM +1000, Nicholas Piggin wrote:
> On Thu, 10 May 2018 08:10:03 -0500
> Segher Boessenkool <segher@kernel.crashing.org> wrote:
> > On Thu, May 10, 2018 at 03:16:55PM +1000, Nicholas Piggin wrote:
> > > The 64-bit toolchain uses the wrong ISA variant for compiling 32-bit
> > > kernels, eve with -m32. Set -mcpu=powerpc which is the generic 32-bit
> > > powerpc machine type and scheduling model. 32-bit platforms and CPUs
> > > can override this with -mcpu= options that come later on the command
> > > line.
> > > 
> > > This fixes a lot of build failures due to incompatible assembly when
> > > compiling 32-bit kernel with 64-bit toolchain.  
> > 
> > So what ISA is set for gas without this patch?  With what GCC version?
> 
> I'm not sure, how do I find that out?

gcc --version
gcc -v <rest of command>, look at the command line options passed to as
make something.s, look at what .machine is set (if any).


> > And, why is that wrong?
> 
> Some 32-bit platforms and CPU types do not provide -mcpu, so I assume
> for 32-bit toolchains that must result in the "powerpc" machine. With

It results in whatever is the default for that toolchain.  Depends on
many things.

> 64-bit toolchains 
> 
> arch/powerpc/mm/hash_low_32.S:353: Error: missing operand
> 
> Which is,
> 
>         tlbie   r4
> 
> Is that v2.06?

The original ISA did not have the L field, 2.xx does, for any xx even I think.


Segher

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

* Re: [PATCH v2 1/5] powerpc/kbuild: set default generic machine type for 32-bit compile
  2018-05-10  5:16 ` [PATCH v2 1/5] powerpc/kbuild: set default generic machine type for 32-bit compile Nicholas Piggin
  2018-05-10 13:10   ` Segher Boessenkool
@ 2018-05-10 14:52   ` Segher Boessenkool
  1 sibling, 0 replies; 15+ messages in thread
From: Segher Boessenkool @ 2018-05-10 14:52 UTC (permalink / raw)
  To: Nicholas Piggin; +Cc: linux-kbuild, Masahiro Yamada, linuxppc-dev

On Thu, May 10, 2018 at 03:16:55PM +1000, Nicholas Piggin wrote:
> The 64-bit toolchain uses the wrong ISA variant for compiling 32-bit
> kernels, eve with -m32. Set -mcpu=powerpc which is the generic 32-bit
> powerpc machine type and scheduling model. 32-bit platforms and CPUs
> can override this with -mcpu= options that come later on the command
> line.

So it turns out your compiler was configured with --with-cpu=power8;
it's not that GCC defaults are bad, but who built your compiler
overrode the defaults.

If the problem only happens in .S files, it might be better to put
.machine directives in those.  But your patch should work too, yes.


Segher

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

end of thread, other threads:[~2018-05-10 14:52 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-10  5:16 [PATCH v2 0/5] kbuild and powerpc patches for new Kconfig language Nicholas Piggin
2018-05-10  5:16 ` [PATCH v2 1/5] powerpc/kbuild: set default generic machine type for 32-bit compile Nicholas Piggin
2018-05-10 13:10   ` Segher Boessenkool
2018-05-10 13:24     ` Nicholas Piggin
2018-05-10 14:29       ` Segher Boessenkool
2018-05-10 14:52   ` Segher Boessenkool
2018-05-10  5:16 ` [PATCH v2 2/5] powerpc/kbuild: remove CROSS32 defines from top level powerpc Makefile Nicholas Piggin
2018-05-10  5:16 ` [PATCH v2 3/5] kbuild: call cc-option with the current set of KBUILD_CFLAGS Nicholas Piggin
2018-05-10  5:29   ` Masahiro Yamada
2018-05-10  6:09     ` Nicholas Piggin
2018-05-10  5:16 ` [PATCH v2 4/5] powerpc/kbuild: Use flags variables rather than overriding LD/CC/AS Nicholas Piggin
2018-05-10 13:03   ` Michael Ellerman
2018-05-10 13:03     ` Michael Ellerman
2018-05-10 13:11     ` Nicholas Piggin
2018-05-10  5:16 ` [PATCH v2 5/5] powerpc/kbuild: move -mprofile-kernel check to Kconfig Nicholas Piggin

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.