Skip to contentSkip to conversation

Kill CONFIG_BUILD_ELF64 from Kconfig

RFC In review Franck Bui-Huu 4 participants 14 messages Feb 13, 2007 – Feb 15, 2007 MIPS

lore
Share & tools
lore
#0 lore raw

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(-)
#1 lore raw

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
index c68b5d3..4240ca1 100644
@@ -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
#2 lore raw

PATCH 2/3 Automatically set CONFIG_BUILD_ELF64

In reply to Franck Bui-Huu

From: 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
index 54acbf5..89020b6 100644
@@ -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
index 4240ca1..626771c 100644
@@ -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
#3 lore raw

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

#4 lore raw

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 += -msym32

ifeq ($(BUILD_ELF32),y)

is enough, isn't it?

yes it is, I'll change it.

thanks

Signature · 1 line
              Franck
#5 lore raw

Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64

In reply to Franck Bui-Huu
Quoted 1 line · Franck Bui-Huu

+ cflags-y += -DCONFIG_BUILD_ELF64

                   ^^^^^^^^^^^^^^^^^^^^

Preprocessor symbol names starting CONFIG_ are reserved for Kbuild.

Ralf

#6 lore raw

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 for Kbuild.

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
#7 lore raw

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 for Kbuild.

Quoted 6 lines

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 ?

What about KBUILD_64BIT_ELF32 with 'KBUILD' meaning that it comes from Kbuild itself and not from any Kconfig files ?

Signature · 1 line
              Franck
#8 lore raw

Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64

In reply to Franck Bui-Huu
Quoted 3 lines · Franck Bui-Huu

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 ?

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

#9 lore raw

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_ELF64 is renamed into CONFIG_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?

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
#10 lore raw

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 Kbuild itsel ?

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_SYM32 and 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

#11 lore raw

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
#12 lore raw

Re: [PATCH 2/3] Automatically set CONFIG_BUILD_ELF64

In reply to Atsushi Nemoto
Quoted 2 lines · Atsushi Nemoto

How about simple BUILD_SYM32? And replase BUILD_ELF32 with BUILD_SYM32 too?

It sounds reasonable to me.

Maciej

#13 lore raw

PATCH 3/3 Rename CONFIG_BUILD_ELF64 into CONFIG_64BIT_BUILD_ELF32

In reply to Franck Bui-Huu

From: 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
index 626771c..fa08d07 100644
@@ -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
index d3fbd83..d37a24c 100644
@@ -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
index a5b1871..55be7b5 100644
@@ -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
index 1fae5dc..917ffa5 100644
@@ -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