Skip to contentSkip to conversation

Linker script cleanup patches for m32r

PATCH In review Tim Abbott 2 participants 8 messages Sep 18, 2009 – Sep 19, 2009

lore
Share & tools
lore

Tim Abbott

author
#0 lore raw

v2 cover Linker script cleanup patches for m32r

This is an updated version of the patch series I sent on September 6 cleaning up the m32r architecture's linker scripts. It differs from V1 in that I moved spi_stack_top and spu_stack_top to .init.data at Hirokazu Takata's request.

This cross-architecture linker script cleanup project is in preparation for adding support for building the kernel with -ffunction-sections -fdata-sections, which is a prerequisite for Ksplice.

-Tim Abbott

Tim Abbott (6):
m32r: make PAGE_SIZE available to assembly.
m32r: Define THREAD_SIZE only once.
m32r: Move GET_THREAD_INFO definition out of asm/thread_info.h.
m32r: Remove unused .altinstructions and .exit.* code from linker
script.
m32r: Move the spi_stack_top and spu_stack_top into .init.data
section.
m32r: Cleanup linker script using new linker script macros.

 arch/m32r/include/asm/page.h        |    4 +-
 arch/m32r/include/asm/processor.h   |    2 -
 arch/m32r/include/asm/thread_info.h |   15 +------
 arch/m32r/kernel/entry.S            |    7 +++
 arch/m32r/kernel/head.S             |    4 +-
 arch/m32r/kernel/vmlinux.lds.S      |   78 ++++-------------------------------
 6 files changed, 23 insertions(+), 87 deletions(-)
author
#1 lore raw

PATCH v2 1/6 m32r: make PAGE_SIZE available to assembly.

page.h includes ifndef __ASSEMBLY__ guards, but PAGE_SIZE is defined using "1UL", which the assembler does not support. Use the _AC macro from const.h to make it available to assembly (and linker scripts).

Cc Hirokazu Takata <[email protected]>
---
 arch/m32r/include/asm/page.h |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
arch/m32r/include/asm/page.h +3 -1
index 11777f7..725ede8 100644
@@ -1,9 +1,11 @@
 #ifndef _ASM_M32R_PAGE_H
 #define _ASM_M32R_PAGE_H
 
+#include <linux/const.h>
+
 /* PAGE_SHIFT determines the page size */
 #define PAGE_SHIFT	12
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
+#define PAGE_SIZE	(_AC(1, UL) << PAGE_SHIFT)
 #define PAGE_MASK	(~(PAGE_SIZE-1))
 
 #ifndef __ASSEMBLY__
Signature · 1 line
1.6.3.3
author
#2 lore raw

PATCH v2 2/6 m32r: Define THREAD_SIZE only once.

In reply to Tim Abbott

Previously, m32r's asm/thread_info.h defined THREAD_SIZE differently for assembly and C code; now that PAGE_SIZE is usable from assembly, these can be combined. Also, m32r's asm/processor.h redefines THREAD_SIZE to the same value; remove this redundant definition.

Cc Hirokazu Takata <[email protected]>
---
 arch/m32r/include/asm/processor.h   |    2 --
 arch/m32r/include/asm/thread_info.h |    6 ++----
 2 files changed, 2 insertions(+), 6 deletions(-)
arch/m32r/include/asm/processor.h +0 -2
index 1a997fc..8397c24 100644
@@ -140,8 +140,6 @@ unsigned long get_wchan(struct task_struct *p);
 #define KSTK_EIP(tsk)  ((tsk)->thread.lr)
 #define KSTK_ESP(tsk)  ((tsk)->thread.sp)
 
-#define THREAD_SIZE (2*PAGE_SIZE)
-
 #define cpu_relax()	barrier()
 
 #endif /* _ASM_M32R_PROCESSOR_H */
arch/m32r/include/asm/thread_info.h +2 -4
index 7157815..4d66169 100644
@@ -55,6 +55,8 @@ struct thread_info {
 
 #define PREEMPT_ACTIVE		0x10000000
 
+#define THREAD_SIZE (PAGE_SIZE << 1)
+
 /*
  * macros/functions for gaining access to the thread information structure
  */
@@ -76,8 +78,6 @@ struct thread_info {
 #define init_thread_info	(init_thread_union.thread_info)
 #define init_stack		(init_thread_union.stack)
 
-#define THREAD_SIZE (2*PAGE_SIZE)
-
 /* how to get the thread information struct from C */
 static inline struct thread_info *current_thread_info(void)
 {
@@ -127,8 +127,6 @@ static inline unsigned int get_thread_fault_code(void)
 
 #else /* !__ASSEMBLY__ */
 
-#define THREAD_SIZE	8192
-
 /* how to get the thread information struct from ASM */
 #define GET_THREAD_INFO(reg)	GET_THREAD_INFO reg
 	.macro GET_THREAD_INFO reg
Signature · 1 line
1.6.3.3
author
#3 lore raw

PATCH v2 3/6 m32r: Move GET_THREAD_INFO definition out of asm/thread_info.h.

In reply to Tim Abbott

Previously, asm/thread_info.h was not usable from linker scripts because it contains a piece of .macro code. Since that code was only used in the m32r entry.S, the right fix is probably to move the macro there.

Cc Hirokazu Takata <[email protected]>
---
 arch/m32r/include/asm/thread_info.h |    9 ---------
 arch/m32r/kernel/entry.S            |    7 +++++++
 2 files changed, 7 insertions(+), 9 deletions(-)
arch/m32r/include/asm/thread_info.h +0 -9
index 4d66169..ed240b6 100644
@@ -125,15 +125,6 @@ static inline unsigned int get_thread_fault_code(void)
 	return ti->flags >> TI_FLAG_FAULT_CODE_SHIFT;
 }
 
-#else /* !__ASSEMBLY__ */
-
-/* how to get the thread information struct from ASM */
-#define GET_THREAD_INFO(reg)	GET_THREAD_INFO reg
-	.macro GET_THREAD_INFO reg
-	ldi	\reg, #-THREAD_SIZE
-	and	\reg, sp
-	.endm
-
 #endif
 
 /*
arch/m32r/kernel/entry.S +7 -0
index 612d35b..4038698 100644
@@ -118,6 +118,13 @@
 #define resume_kernel		restore_all
 #endif
 
+/* how to get the thread information struct from ASM */
+#define GET_THREAD_INFO(reg)	GET_THREAD_INFO reg
+	.macro GET_THREAD_INFO reg
+	ldi	\reg, #-THREAD_SIZE
+	and	\reg, sp
+	.endm
+
 ENTRY(ret_from_fork)
 	pop	r0
 	bl	schedule_tail
Signature · 1 line
1.6.3.3
author
#4 lore raw

PATCH v2 4/6 m32r: Remove unused .altinstructions and .exit.* code from linker script.

In reply to Tim Abbott

It appears that m32r copied the .altinstructions definition from x86 when the architecture was first merged into Linux. m32r doesn't put anything in .altinstructions, so this is just dead code.

The following block affecting .exit.text/.exit.data, which has a comment also copied from x86, should also be deleted; the linker script later discards the .exit.text and .exit.data sections.

Cc Hirokazu Takata <[email protected]>
---
 arch/m32r/kernel/vmlinux.lds.S |    9 ---------
 1 files changed, 0 insertions(+), 9 deletions(-)
arch/m32r/kernel/vmlinux.lds.S +0 -9
index de5e21c..a8aa4a8 100644
@@ -91,15 +91,6 @@ SECTIONS
   .con_initcall.init : { *(.con_initcall.init) }
   __con_initcall_end = .;
   SECURITY_INIT
-  . = ALIGN(4);
-  __alt_instructions = .;
-  .altinstructions : { *(.altinstructions) }
-  __alt_instructions_end = .;
-  .altinstr_replacement : { *(.altinstr_replacement) }
-  /* .exit.text is discard at runtime, not link time, to deal with references
-     from .altinstructions and .eh_frame */
-  .exit.text : { EXIT_TEXT }
-  .exit.data : { EXIT_DATA }
 
 #ifdef CONFIG_BLK_DEV_INITRD
   . = ALIGN(4096);
Signature · 1 line
1.6.3.3
author
#5 lore raw

PATCH v2 5/6 m32r: Move the spi_stack_top and spu_stack_top into .init.data section.

In reply to Tim Abbott

Since these get squashed into the .data output section by the m32r linker script, it seems likely that they don't need their own input sections.

At Hirokazu Takata's suggestion, we place these structures in .init.data rather than just placing them in .data (since they are only used at init time).

This patch is preparation for cleaning up the m32r architecture to use the new macros in vmlinux.lds.h; if these sections are indeed not needed, then we can use the RW_DATA_SECTION macro for m32r and save a bunch of redundant code.

Cc Hirokazu Takata <[email protected]>
---
 arch/m32r/kernel/head.S        |    4 ++--
 arch/m32r/kernel/vmlinux.lds.S |    2 --
 2 files changed, 2 insertions(+), 4 deletions(-)
arch/m32r/kernel/head.S +2 -2
index 0a71944..a46652d 100644
@@ -268,13 +268,13 @@ ENTRY(empty_zero_page)
 /*------------------------------------------------------------------------
  * Stack area
  */
-	.section .spi
+	.section .init.data, "aw"
 	ALIGN
 	.global spi_stack_top
 	.zero	1024
 spi_stack_top:
 
-	.section .spu
+	.section .init.data, "aw"
 	ALIGN
 	.global spu_stack_top
 	.zero	1024
arch/m32r/kernel/vmlinux.lds.S +0 -2
index a8aa4a8..aadb24e 100644
@@ -49,8 +49,6 @@ SECTIONS
 
   /* writeable */
   .data : {			/* Data */
-	*(.spu)
-	*(.spi)
 	DATA_DATA
 	CONSTRUCTORS
 	}
Signature · 1 line
1.6.3.3
author
#6 lore raw

PATCH v2 6/6 m32r: Cleanup linker script using new linker script macros.

In reply to Tim Abbott

This patch is largely a straightforward conversion. One thing to note is that the new macros use fewer separate output sections than the old code; this should have no functional impact but is relevant for people objdumping vmlinux files.

Also note that it moves the .data.init_task output sections inside _edata.

Cc Hirokazu Takata <[email protected]>
---
 arch/m32r/kernel/vmlinux.lds.S |   67 +++++----------------------------------
 1 files changed, 9 insertions(+), 58 deletions(-)
arch/m32r/kernel/vmlinux.lds.S +9 -58
index aadb24e..8ceb618 100644
@@ -4,6 +4,7 @@
 #include <asm-generic/vmlinux.lds.h>
 #include <asm/addrspace.h>
 #include <asm/page.h>
+#include <asm/thread_info.h>
 
 OUTPUT_ARCH(m32r)
 #if defined(__LITTLE_ENDIAN__)
@@ -40,72 +41,22 @@ SECTIONS
 #endif
   _etext = .;			/* End of text section */
 
-  . = ALIGN(16);		/* Exception table */
-  __start___ex_table = .;
-  __ex_table : { *(__ex_table) }
-  __stop___ex_table = .;
-
+  EXCEPTION_TABLE(16)
   RODATA
-
-  /* writeable */
-  .data : {			/* Data */
-	DATA_DATA
-	CONSTRUCTORS
-	}
-
-  . = ALIGN(4096);
-  __nosave_begin = .;
-  .data_nosave : { *(.data.nosave) }
-  . = ALIGN(4096);
-  __nosave_end = .;
-
-  . = ALIGN(32);
-  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
-
+  RW_DATA_SECTION(32, PAGE_SIZE, THREAD_SIZE)
   _edata = .;			/* End of data section */
 
-  . = ALIGN(8192);		/* init_task */
-  .data.init_task : { *(.data.init_task) }
-
   /* will be freed after init */
-  . = ALIGN(4096);		/* Init code and data */
+  . = ALIGN(PAGE_SIZE);		/* Init code and data */
   __init_begin = .;
-  .init.text : {
-	_sinittext = .;
-	INIT_TEXT
-	_einittext = .;
-  }
-  .init.data : { INIT_DATA }
-  . = ALIGN(16);
-  __setup_start = .;
-  .init.setup : { *(.init.setup) }
-  __setup_end = .;
-  __initcall_start = .;
-  .initcall.init : {
-	INITCALLS
-  }
-  __initcall_end = .;
-  __con_initcall_start = .;
-  .con_initcall.init : { *(.con_initcall.init) }
-  __con_initcall_end = .;
-  SECURITY_INIT
-
-#ifdef CONFIG_BLK_DEV_INITRD
-  . = ALIGN(4096);
-  __initramfs_start = .;
-  .init.ramfs : { *(.init.ramfs) }
-  __initramfs_end = .;
-#endif
-
-  PERCPU(4096)
-  . = ALIGN(4096);
+  INIT_TEXT_SECTION(PAGE_SIZE)
+  INIT_DATA_SECTION(16)
+  PERCPU(PAGE_SIZE)
+  . = ALIGN(PAGE_SIZE);
   __init_end = .;
   /* freed after init ends here */
 
-  __bss_start = .;		/* BSS */
-  .bss : { *(.bss) }
-  . = ALIGN(4);
-  __bss_stop = .;
+  BSS_SECTION(0, 0, 4)
 
   _end = . ;
 
Signature · 1 line
1.6.3.3
Acked-by on the v2 series
#7 lore raw
In reply to Tim Abbott
Quoted 12 lines · Tim Abbott

This is an updated version of the patch series I sent on September 6 cleaning up the m32r architecture's linker scripts. It differs from V1 in that I moved spi_stack_top and spu_stack_top to .init.data at Hirokazu Takata's request.

This cross-architecture linker script cleanup project is in preparation for adding support for building the kernel with -ffunction-sections -fdata-sections, which is a prerequisite for Ksplice.

-Tim Abbott

Quoted 9 lines

Tim Abbott (6):
m32r: make PAGE_SIZE available to assembly.
m32r: Define THREAD_SIZE only once.
m32r: Move GET_THREAD_INFO definition out of asm/thread_info.h.
m32r: Remove unused .altinstructions and .exit.* code from linker
script.
m32r: Move the spi_stack_top and spu_stack_top into .init.data
section.
m32r: Cleanup linker script using new linker script macros.

Looked through all of these - looks good.
I like how you take the time to do the additional cleanups that is possible.
Next step would be to introduce the 'normal' style in the linker script but that can come later.

For all 6 patches.

Sam