Skip to contentSkip to conversation

Allow compilation with -ffunction-sections

PATCH In review Matthew Wilcox 2 participants 2 messages Oct 16, 2002

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow compilation with -ffunction-sections

If you compile the kernel with -ffunction-sections, each function gets put in a section .text.function_name. This collides with our current use of .text.init. So here's a patch which converts x86 to use .init.text instead.

I've tested it on x86 and it still frees 120k of ram, so it seems to work. Other architectures will need to change their vmlinux.lds appropriately, and may need other changes (arm, m68k seem to use .text.init verbatim).

arch/i386/vmlinux.lds.S +5 -5
diff -urpNX dontdiff linux-2.5.43/arch/i386/vmlinux.lds.S linux-2.5.43-willy/arch/i386/vmlinux.lds.S
@@ -41,11 +41,11 @@ SECTIONS
 
   . = ALIGN(4096);		/* Init code and data */
   __init_begin = .;
-  .text.init : { *(.text.init) }
-  .data.init : { *(.data.init) }
+  .init.text : { *(.init.text) }
+  .init.data : { *(.init.data) }
   . = ALIGN(16);
   __setup_start = .;
-  .setup.init : { *(.setup.init) }
+  .init.setup : { *(.init.setup) }
   __setup_end = .;
   __initcall_start = .;
   .initcall.init : {
@@ -89,8 +89,8 @@ SECTIONS
 
   /* Sections to be discarded */
   /DISCARD/ : {
-	*(.text.exit)
-	*(.data.exit)
+	*(.exit.text)
+	*(.exit.data)
 	*(.exitcall.exit)
 	}
 
include/linux/init.h +7 -7
diff -urpNX dontdiff linux-2.5.43/include/linux/init.h linux-2.5.43-willy/include/linux/init.h
@@ -93,18 +93,18 @@ extern struct kernel_param __setup_start
  * Mark functions and data as being only used at initialization
  * or exit time.
  */
-#define __init		__attribute__ ((__section__ (".text.init")))
-#define __exit		__attribute__ ((unused, __section__(".text.exit")))
-#define __initdata	__attribute__ ((__section__ (".data.init")))
-#define __exitdata	__attribute__ ((unused, __section__ (".data.exit")))
-#define __initsetup	__attribute__ ((unused,__section__ (".setup.init")))
+#define __init		__attribute__ ((__section__ (".init.text")))
+#define __exit		__attribute__ ((unused, __section__(".exit.text")))
+#define __initdata	__attribute__ ((__section__ (".init.data")))
+#define __exitdata	__attribute__ ((unused, __section__ (".exit.data")))
+#define __initsetup	__attribute__ ((unused,__section__ (".init.setup")))
 #define __init_call(level)  __attribute__ ((unused,__section__ (".initcall" level ".init")))
 #define __exit_call	__attribute__ ((unused,__section__ (".exitcall.exit")))
 
 /* For assembly routines */
-#define __INIT		.section	".text.init","ax"
+#define __INIT		.section	".init.text","ax"
 #define __FINIT		.previous
-#define __INITDATA	.section	".data.init","aw"
+#define __INITDATA	.section	".init.data","aw"
 
 /**
  * module_init() - driver initialization entry point
Signature · 1 line
Revolutions do not require corporate support.
#1 lore raw
Quoted 8 lines · Matthew Wilcox

If you compile the kernel with -ffunction-sections, each function gets put in a section .text.function_name. This collides with our current use of .text.init. So here's a patch which converts x86 to use .init.text instead.

I've tested it on x86 and it still frees 120k of ram, so it seems to work. Other architectures will need to change their vmlinux.lds appropriately, and may need other changes (arm, m68k seem to use .text.init verbatim).

Just in case anybody feels bored, maybe someone wants to come up with a include/asm-generic/vmlinux.lds.S (or a better name) which has the common part of all the arch's vmlinux.lds.S - so we could make such changes like you're proposing at one place in the future.

Since all vmlinux.lds.S get preprocessed by the C preprocessor, putting an "#include <asm-generic/vmlinux.lds.S>" in there should be easy enough instead of all the current duplication.

--Kai