Kill CONFIG_BUILD_ELF64 from Kconfig
Hi,
This patchset results from the following thread we had a couple weeks ago:
http://marc.theaimsgroup.com/?l=linux-mips&m=117000798317188&w=2
Once this patchset is applied, we do not need to configure CONFIG_BUILD_ELF64 manually. Instead, the makefile should do the right thing for us:
- It passes '-msym32' switch to gcc according to the platform's load address.
- We can still force Kbuild to not use '-msym32' whatever the value of the load address by passing "BUILD_ELF32=no" when invoking make.
Patch #3 renames CONFIG_BUILD_ELF64 into CONFIG_64BIT_BUILD_ELF32. It simplifies the places where it's used.
This patchset assumes that the compiler will fail if it doesn't support '-msym32' switch. Therefore we needn't to test gcc's version when testing CONFIG_64BIT_BUILD_ELF32 value.
Please, consider.
Franck
--- arch/mips/Kconfig | 15 --------------- arch/mips/Makefile | 23 ++++++++++++++++++----- include/asm-mips/page.h | 2 +- include/asm-mips/pgtable-64.h | 2 +- include/asm-mips/stackframe.h | 12 ++++++------ 5 files changed, 26 insertions(+), 28 deletions(-)
PATCH 1/3 Remove '-mno-explicit-relocs' option when CONFIG_BUILD_ELF64
From: Franck Bui-Huu <[email protected]>
This patch removes '-mno-explicit-relocs' usage when CONFIG_BUILD_ELF64 is set since this option was only required with the old hack to truncate addresses at the assembly level where "-mabi=64 -Wa,-mabi=32" was used.
This should yield a small code size improvement for inline assembly, where the R constraint is used.
The idea is coming from Maciej <[email protected]>.
--- arch/mips/Makefile | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
arch/mips/Makefile +1 -3
@@ -60,9 +60,7 @@ vmlinux-32 = vmlinux.32 vmlinux-64 = vmlinux cflags-y += -mabi=64 -ifdef CONFIG_BUILD_ELF64 -cflags-y += $(call cc-option,-mno-explicit-relocs) -else +ifndef CONFIG_BUILD_ELF64 cflags-y += $(call cc-option,-msym32) endif endif
Signature · 1 line
1.4.4.3.ge6d4
PATCH 2/3 Automatically set CONFIG_BUILD_ELF64
In reply to Franck Bui-HuuFrom: Franck Bui-Huu <[email protected]>
We do not rely on user anymore to setup this config correctly. Instead we make our choice depending on the load address.
If we want to force Kbuild to use ELF64 format whatever the load address we can still do:
$ make BUILD_ELF32=no
--- arch/mips/Kconfig | 15 --------------- arch/mips/Makefile | 23 ++++++++++++++++++++--- 2 files changed, 20 insertions(+), 18 deletions(-)
arch/mips/Kconfig +0 -15
@@ -2009,21 +2009,6 @@ source "fs/Kconfig.binfmt" config TRAD_SIGNALS bool -config BUILD_ELF64 - bool "Use 64-bit ELF format for building" - depends on 64BIT - help - A 64-bit kernel is usually built using the 64-bit ELF binary object - format as it's one that allows arbitrary 64-bit constructs. For - kernels that are loaded within the KSEG compatibility segments the - 32-bit ELF format can optionally be used resulting in a somewhat - smaller binary, but this option is not explicitly supported by the - toolchain and since binutils 2.14 it does not even work at all. - - Say Y to use the 64-bit format or N to use the 32-bit one. - - If unsure say Y. - config BINFMT_IRIX bool "Include IRIX binary compatibility" depends on CPU_BIG_ENDIAN && 32BIT && BROKEN
arch/mips/Makefile +20 -3
@@ -60,9 +60,6 @@ vmlinux-32 = vmlinux.32 vmlinux-64 = vmlinux cflags-y += -mabi=64 -ifndef CONFIG_BUILD_ELF64 -cflags-y += $(call cc-option,-msym32) -endif endif
@@ -614,6 +611,26 @@ else JIFFIES = jiffies_64 endif +# +# Automatically detect the build format. By default we choose +# the elf format according to the load address. +# We can always force a build with a 64-bits symbol format by +# passing 'BUILD_ELF32=no' option to the make's command line. +# +ifdef CONFIG_64BIT + ifndef BUILD_ELF32 + ifeq ($(shell expr $(load-y) \< 0xffffffff80000000), 0) + BUILD_ELF32 = y + endif + endif + + ifeq ("$(BUILD_ELF32)", "y") + cflags-y += -msym32 + else + cflags-y += -DCONFIG_BUILD_ELF64 + endif +endif # CONFIG_64BIT + AFLAGS += $(cflags-y) CFLAGS += $(cflags-y)
Signature · 1 line
1.4.4.3.ge6d4
Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64
arch/mips/Makefile else · line 628
Quoted 2 lines · Franck Bui-Huu
arch/mips/Makefile +2
-0+ ifeq ("$(BUILD_ELF32)", "y") + cflags-y += -msym32
ifeq ($(BUILD_ELF32),y)
is enough, isn't it?
---
Atsushi Nemoto
Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64
Quoted 7 lines · Atsushi Nemoto
arch/mips/Makefile else · line 628
Quoted 2 lines · Franck Bui-Huu
arch/mips/Makefile +2
-0+ ifeq ("$(BUILD_ELF32)", "y") + cflags-y += -msym32ifeq ($(BUILD_ELF32),y)
is enough, isn't it?
yes it is, I'll change it.
thanks
Signature · 1 line
Franck
Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64
In reply to Franck Bui-HuuQuoted 1 line · Franck Bui-Huu
+ cflags-y += -DCONFIG_BUILD_ELF64
^^^^^^^^^^^^^^^^^^^^
Preprocessor symbol names starting CONFIG_ are reserved for Kbuild.
Ralf
Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64
Quoted 7 lines · Ralf Baechle
Quoted 1 line · Franck Bui-Huu
+ cflags-y += -DCONFIG_BUILD_ELF64
^^^^^^^^^^^^^^^^^^^^Preprocessor symbol names starting
CONFIG_are reserved forKbuild.
Ok but keeping this name avoid to change all places where CONFIG_BUILD_ELF64 is used.
It should be done by patch #3 instead where CONFIG_BUILD_ELF64 is renamed into CONFIG_64BIT_BUILD_ELF32. Any suggestions for a better name ?
Signature · 1 line
Franck
Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64
Quoted 9 lines · Franck Bui-Huu
Quoted 7 lines · Ralf Baechle
Quoted 1 line · Franck Bui-Huu
+ cflags-y += -DCONFIG_BUILD_ELF64
^^^^^^^^^^^^^^^^^^^^Preprocessor symbol names starting
CONFIG_are reserved forKbuild.
Quoted 6 lines
Ok but keeping this name avoid to change all places where
CONFIG_BUILD_ELF64is used.It should be done by patch #3 instead where
CONFIG_BUILD_ELF64is renamed intoCONFIG_64BIT_BUILD_ELF32. Any suggestions for a better name ?
What about KBUILD_64BIT_ELF32 with 'KBUILD' meaning that it comes from Kbuild itself and not from any Kconfig files ?
Signature · 1 line
Franck
Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64
In reply to Franck Bui-HuuQuoted 3 lines · Franck Bui-Huu
It should be done by patch #3 instead where
CONFIG_BUILD_ELF64is renamed intoCONFIG_64BIT_BUILD_ELF32. Any suggestions for a better name ?
I think "ELF32" or "ELF64" word is improper while this is irrelevant to ELF format. This makes confusion with CONFIG_BOOT_ELF32.
How about simple BUILD_SYM32? And replase BUILD_ELF32 with BUILD_SYM32 too?
---
Atsushi Nemoto
Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64
Quoted 11 lines · Atsushi Nemoto
Quoted 3 lines · Franck Bui-Huu
It should be done by patch #3 instead where
CONFIG_BUILD_ELF64is renamed intoCONFIG_64BIT_BUILD_ELF32. Any suggestions for a better name ?I think "ELF32" or "ELF64" word is improper while this is irrelevant to ELF format. This makes confusion with
CONFIG_BOOT_ELF32.How about simple
BUILD_SYM32? And replaseBUILD_ELF32withBUILD_SYM32too?
That's a good point. What about replacing BUILD by KBUILD meaning this macro is coming from Kbuild itsel ?
And maybe it would be interesting to make obvious that this macro implies 64-bits kernel. What about something like KBUILD_64BIT_SYM32 and replace 'BUILD_ELF32=no' by 'KBUILD_SYM32=no' ?
Signature · 1 line
Franck
Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64
Quoted 2 lines · Franck Bui-Huu
That's a good point. What about replacing BUILD by KBUILD meaning this macro is coming from
Kbuilditsel ?
No objections.
Quoted 3 lines
And maybe it would be interesting to make obvious that this macro implies 64-bits kernel. What about something like
KBUILD_64BIT_SYM32and replace 'BUILD_ELF32=no' by 'KBUILD_SYM32=no' ?
Same here. I just think introducing one name is better than two name. I also feel "make KBUILD_SYM32=0" is more consistent.
---
Atsushi Nemoto
Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64
Quoted 3 lines · Atsushi Nemoto
Same here. I just think introducing one name is better than two name. I also feel "make KBUILD_SYM32=0" is more consistent.
Yes I agree KBUILD_SYM32 seems better for command line usage but I think it won't be used widely unlike in code usage where KBUILD_64BIT_SYM32 is better because it's really self explaned and not
ambigous: "build a 64 bits kernel with 32 bits symbols".
And I think it's more important.
Signature · 1 line
Franck
Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64
In reply to Atsushi NemotoQuoted 2 lines · Atsushi Nemoto
How about simple
BUILD_SYM32? And replaseBUILD_ELF32withBUILD_SYM32too?
It sounds reasonable to me.
Maciej
PATCH 3/3 Rename CONFIG_BUILD_ELF64 into CONFIG_64BIT_BUILD_ELF32
In reply to Franck Bui-HuuFrom: Franck Bui-Huu <[email protected]>
--- arch/mips/Makefile | 6 ++---- include/asm-mips/page.h | 2 +- include/asm-mips/pgtable-64.h | 2 +- include/asm-mips/stackframe.h | 12 ++++++------ 4 files changed, 10 insertions(+), 12 deletions(-)
arch/mips/Makefile +2 -4
@@ -625,11 +625,9 @@ ifdef CONFIG_64BIT endif ifeq ("$(BUILD_ELF32)", "y") - cflags-y += -msym32 - else - cflags-y += -DCONFIG_BUILD_ELF64 + cflags-y += -msym32 -DCONFIG_64BIT_BUILD_ELF32 endif -endif # CONFIG_64BIT +endif AFLAGS += $(cflags-y) CFLAGS += $(cflags-y)
include/asm-mips/page.h +1 -1
@@ -149,7 +149,7 @@ typedef struct { unsigned long pgprot; } pgprot_t;/* * __pa()/__va() should be used only during mem init. */ -#if defined(CONFIG_64BIT ) && !defined(CONFIG_BUILD_ELF64 ) +#ifdef CONFIG_64BIT_BUILD_ELF32 #define __pa_page_offset (x) ((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)#else #define __pa_page_offset (x) PAGE_OFFSET
include/asm-mips/pgtable-64.h +1 -1
@@ -104,7 +104,7 @@#define VMALLOC_START MAP_BASE#define VMALLOC_END \ (VMALLOC_START + PTRS_PER_PGD * PTRS_PER_PMD * PTRS_PER_PTE * PAGE_SIZE) -#if defined(CONFIG_MODULES ) && !defined(CONFIG_BUILD_ELF64 ) && \ +#if defined(CONFIG_MODULES ) && defined(CONFIG_64BIT_BUILD_ELF32 ) && \VMALLOC_START !=CKSSEG /* Load modules into 32bit-compatible segment. */ #define MODULE_START CKSSEG
include/asm-mips/stackframe.h +6 -6
@@ -70,14 +70,14 @@#else MFC0 k0, CP0_CONTEXT#endif -#if defined(CONFIG_BUILD_ELF64 ) || (defined(CONFIG_64BIT ) && __GNUC__ <4 ) +#if defined(CONFIG_32BIT ) || defined(CONFIG_64BIT_BUILD_ELF32 ) + lui k1, %hi(kernelsp) +#else lui k1, %highest(kernelsp) daddiu k1, %higher(kernelsp) dsll k1, 16 daddiu k1, %hi(kernelsp) dsll k1, 16 -#else - lui k1, %hi(kernelsp) #endif LONG_SRL k0, PTEBASE_SHIFT LONG_ADDU k1, k0
@@ -95,14 +95,14 @@ .endm #else .macro get_saved_sp /* Uniprocessor variation */ -#if defined(CONFIG_BUILD_ELF64 ) || (defined(CONFIG_64BIT ) && __GNUC__ <4 ) +#if defined(CONFIG_32BIT ) || defined(CONFIG_64BIT_BUILD_ELF32 ) + lui k1, %hi(kernelsp) +#else lui k1, %highest(kernelsp) daddiu k1, %higher(kernelsp) dsll k1, k1, 16 daddiu k1, %hi(kernelsp) dsll k1, k1, 16 -#else - lui k1, %hi(kernelsp) #endif LONG_L k1, %lo(kernelsp)(k1) .endm
Signature · 1 line
1.4.4.3.ge6d4