macros for section name cleanup
Subsystems (5)
v2 cover macros for section name cleanup
(this patch series differs from v1 only in the CC list; some of the architecture lists I sent the previous one to are moderated against non-members; all replies should go to this version).
Here are the architecture-independent macro definitions needed for to clean up the kernel's section names. The overall diffstat from this section name cleanup project is:
96 files changed, 261 insertions(+), 503 deletions(-)
The decrease results from removing a lot of redundancy in the linker scripts.
The long-term goal here is to add support for building the kernel with -ffunction-sections -fdata-sections. This requires renaming all the magic section names in the kernel of the form .text.foo, .data.foo, .bss.foo, and .rodata.foo to not have collisions with sections generated for code like:
static int nosave = 0; /* -fdata-sections places in .data.nosave */ static void head(); /* -ffunction-sections places in .text.head */
Sam Ravnborg proposed that rather than just renaming all the sections outright, we should start by first getting more control over the section names used in the kernel so that we can later rename sections without touching too many files. These patch series implement that cleanup. Later, there will be another patch series to actually rename the sections.
I'm hoping we can get just these macro definitions into 2.6.30 so that the arch maintainers don't have to grab the macro definitions for their trees while reviewing the patches for 2.6.31.
Shortly, I'm going to send one patch series for each of the architectures updating those architectures to use these new macros (and otherwise cleaning up section names on those architectures).
-Tim Abbott
Tim Abbott (6):
Add new macros for page-aligned data and bss sections. Add new NOSAVE_DATA linker script macro.
Add new CACHELINE_ALIGNED_DATA linker script macro. Add new INIT_TASK_DATA() linker script macro. Add new READ_MOSTLY_DATA(align) linker script macro. Add support for __read_mostly to linux/cache.h
include/asm-generic/vmlinux.lds.h | 27 +++++++++++++++++++++++++++ include/linux/cache.h | 6 ++++++ include/linux/init_task.h | 3 +++ include/linux/linkage.h | 9 +++++++++ 4 files changed, 45 insertions(+), 0 deletions(-)
A message that is not in the archive (sent off-list or not yet received): 1241121253-32341-1-git-send-email-tabbott-3s7WtUTddSA@public.gmane.org
PATCH v2 1/6 Add new macros for page-aligned data and bss sections.
This patch is preparation for replacing most uses of ".bss.page_aligned" and ".data.page_aligned" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
--- include/asm-generic/vmlinux.lds.h | 8 ++++++++ include/linux/linkage.h | 9 +++++++++ 2 files changed, 17 insertions(+), 0 deletions(-)
include/asm-generic/vmlinux.lds.h +8 -0
@@ -116,6 +116,14 @@ FTRACE_EVENTS() \ TRACE_SYSCALLS() +#define PAGE_ALIGNED_DATA \ + . = ALIGN(PAGE_SIZE); \ + *(.data.page_aligned) + +#define PAGE_ALIGNED_BSS \ + . = ALIGN(PAGE_SIZE); \ + *(.bss.page_aligned) +#define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
include/linux/linkage.h +9 -0
@@ -22,6 +22,15 @@#define __page_aligned_bss __section(.bss.page_aligned) __aligned(PAGE_SIZE)/* +* For assembly routines. +* +* Note when using these that you must specify the appropriate +* alignment directives yourself +*/ +#define __PAGE_ALIGNED_DATA .section ".data.page_aligned", "aw", @progbits +#define __PAGE_ALIGNED_BSS .section ".bss.page_aligned", "aw", @nobits + +/* * This is used by architectures to keep arguments on the stack * untouched by the compiler by keeping them live until the end. * The argument stack may be owned by the assembly-language
Signature · 1 line
1.6.2.1
A message that is not in the archive (sent off-list or not yet received): 1241121253-32341-2-git-send-email-tabbott-3s7WtUTddSA@public.gmane.org
PATCH v2 2/6 Add new NOSAVE_DATA linker script macro.
This patch is preparation for replacing most ".data.nosave" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
--- include/asm-generic/vmlinux.lds.h | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
include/asm-generic/vmlinux.lds.h +7 -0
@@ -124,6 +124,13 @@ . = ALIGN(PAGE_SIZE); \ *(.bss.page_aligned) +#define NOSAVE_DATA \ + . = ALIGN(PAGE_SIZE); \ + __nosave_begin = .; \ + *(.data.nosave) \ + . = ALIGN(PAGE_SIZE); \ + __nosave_end = .; +#define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
Signature · 1 line
1.6.2.1
PATCH v2 3/6 Add new CACHELINE_ALIGNED_DATA linker script macro.
This patch is preparation for replacing most ".data.cacheline_aligned" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
--- include/asm-generic/vmlinux.lds.h | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
include/asm-generic/vmlinux.lds.h +4 -0
@@ -131,6 +131,10 @@ . = ALIGN(PAGE_SIZE); \ __nosave_end = .; +#define CACHELINE_ALIGNED_DATA (alignment) \ + . = ALIGN(alignment); \ + *(.data.cacheline_aligned) +#define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
Signature · 1 line
1.6.2.1
PATCH v2 4/6 Add new INIT_TASK_DATA() linker script macro.
This patch is preparation for replacing most ".data.init_task" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
--- include/asm-generic/vmlinux.lds.h | 4 ++++ include/linux/init_task.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
include/asm-generic/vmlinux.lds.h +4 -0
@@ -135,6 +135,10 @@ . = ALIGN(alignment); \ *(.data.cacheline_aligned) +#define INIT_TASK_DATA (alignment) \ + . = ALIGN(alignment); \ + *(.data.init_task) +#define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
include/linux/init_task.h +3 -0
@@ -184,5 +184,8 @@ extern struct cred init_cred; LIST_HEAD_INIT(cpu_timers[2]), \ } +/* Attach to the init_task data structure for proper alignment */ +#define __init_task_data __attribute__((__section__(".data.init_task"))) +#endif
Signature · 1 line
1.6.2.1
PATCH v2 5/6 Add new READ_MOSTLY_DATA(align) linker script macro.
This patch is preparation for replacing most ".data.read_mostly" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
--- include/asm-generic/vmlinux.lds.h | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
include/asm-generic/vmlinux.lds.h +4 -0
@@ -139,6 +139,10 @@ . = ALIGN(alignment); \ *(.data.init_task) +#define READ_MOSTLY_DATA (alignment) \ + . = ALIGN(alignment); \ + *(.data.read_mostly) +#define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
Signature · 1 line
1.6.2.1
PATCH v2 6/6 Add support for __read_mostly to linux/cache.h
--- include/linux/cache.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
include/linux/cache.h +6 -0
@@ -13,7 +13,13 @@#endif #ifndef __read_mostly +#ifdef CONFIG_HAVE_READ_MOSTLY_DATA +#define __read_mostly __attribute__((__section__(".data.read_mostly"))) +#define __READ_MOSTLY .section ".data.read_mostly", "aw" +#else #define __read_mostly +#define __READ_MOSTLY +#endif /* CONFIG_HAVE_READ_MOSTLY_DATA */ #endif #ifndef ____cacheline_aligned
Signature · 1 line
1.6.2.1
Re: [PATCH v2 2/6] Add new NOSAVE_DATA linker script macro.
In reply to Tim AbbottQuoted 20 lines · Tim Abbott
This patch is preparation for replacing most ".data.nosave" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
Signed-off-by Tim Abbott <[email protected]>Cc Sam Ravnborg <[email protected]>--- include/asm-generic/vmlinux.lds.h | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)include/asm-generic/vmlinux.lds.h +0
-0
include/asm-generic/vmlinux.lds.h line 133
Quoted 10 lines
include/asm-generic/vmlinux.lds.h +7
-0@@ -124,6 +124,13 @@ . = ALIGN(PAGE_SIZE); \ *(.bss.page_aligned) +#define NOSAVE_DATA \ + . = ALIGN(PAGE_SIZE); \ + __nosave_begin = .; \ + *(.data.nosave) \ + . = ALIGN(PAGE_SIZE); \ + __nosave_end = .; +
You need to use:
VMLINUX_SYMBOL(__nosave_begin) = .;
Otherwise architectures such as m68k wil break as they add a leading underscore.
See other symbols that is defined inside vmlinux.lds.h
Sam
Re: [PATCH v2 1/6] Add new macros for page-aligned data and bss sections.
In reply to Tim AbbottQuoted 42 lines · Tim Abbott
This patch is preparation for replacing most uses of ".bss.page_aligned" and ".data.page_aligned" in the kernel with macros, so that the section name can later be changed without having to touch a lot of the kernel.
The long-term goal here is to be able to change the kernel's magic section names to those that are compatible with -ffunction-sections -fdata-sections. This requires renaming all magic sections with names of the form ".data.foo".
Signed-off-by Tim Abbott <[email protected]>Cc Sam Ravnborg <[email protected]>Acked-by David Howells <[email protected]>--- include/asm-generic/vmlinux.lds.h | 8 ++++++++ include/linux/linkage.h | 9 +++++++++ 2 files changed, 17 insertions(+), 0 deletions(-)include/asm-generic/vmlinux.lds.h +8
-0@@ -116,6 +116,14 @@ FTRACE_EVENTS() \ TRACE_SYSCALLS() +#define PAGE_ALIGNED_DATA \ + . = ALIGN(PAGE_SIZE); \ + *(.data.page_aligned) + +#define PAGE_ALIGNED_BSS \ + . = ALIGN(PAGE_SIZE); \ + *(.bss.page_aligned) +#define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \include/linux/linkage.h +0
-0
include/linux/linkage.h line 31
Quoted 10 lines
include/linux/linkage.h +7
-0@@ -22,6 +22,15 @@#define __page_aligned_bss __section(.bss.page_aligned) __aligned(PAGE_SIZE)/* +* For assembly routines. +* +* Note when using these that you must specify the appropriate +* alignment directives yourself +*/ +#define __PAGE_ALIGNED_DATA .section ".data.page_aligned", "aw", @progbits +#define __PAGE_ALIGNED_BSS .section ".bss.page_aligned", "aw", @nobits
The above will work on most architectures but fails (silently?) on arm. arm uses %{progbits,nobits} where all other uses @{nobits,progbits}.
I know we do not use page_aligned in arm assembler code for now, but if we do then it should work.
It is my understanding that the linker will automatically assume nobits for section names starting with .bss and likewise progbits for section names starting with .data - so we can leave them out?
Sam
Re: [PATCH v2 1/6] Add new macros for page-aligned data and bss sections.
Quoted 7 lines · Sam Ravnborg
include/linux/linkage.h line 31
Quoted 2 lines · Tim Abbott
include/linux/linkage.h +2
-0+#define __PAGE_ALIGNED_DATA .section ".data.page_aligned", "aw", @progbits +#define __PAGE_ALIGNED_BSS .section ".bss.page_aligned", "aw", @nobitsIt is my understanding that the linker will automatically assume nobits for section names starting with .bss and likewise progbits for section names starting with .data - so we can leave them out?
I believe that is correct.
-Tim Abbott
A message that is not in the archive (sent off-list or not yet received): alpine.DEB.1.10.0905010951100.3955-KERi1O17UK+7LhyUQnA0IJVzexx5G7lz@public.gmane.org
Re: [PATCH v2 1/6] Add new macros for page-aligned data and bss sections.
Quoted 11 lines · Tim Abbott
Quoted 6 lines · Sam Ravnborg
include/linux/linkage.h line 31
Quoted 2 lines · Tim Abbott
include/linux/linkage.h +2
-0+#define __PAGE_ALIGNED_DATA .section ".data.page_aligned", "aw", @progbits +#define __PAGE_ALIGNED_BSS .section ".bss.page_aligned", "aw", @nobitsIt is my understanding that the linker will automatically assume nobits for section names starting with .bss and likewise progbits for section names starting with .data - so we can leave them out?
I believe that is correct.
... but that doesn't mean it's the right thing to do.
It's better to be fully explicit when macroizing this kind of stuff. This is part of why macroizing it is good: it means we end up with *one* place that determines this stuff, not some magic heuristics in the linker.
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Re: [PATCH v2 1/6] Add new macros for page-aligned data and bss sections.
Quoted 10 lines · H. Peter Anvin
Quoted 9 lines · Tim Abbott
Quoted 6 lines · Sam Ravnborg
include/linux/linkage.h line 31
Quoted 2 lines · Tim Abbott
include/linux/linkage.h +2
-0+#define __PAGE_ALIGNED_DATA .section ".data.page_aligned", "aw", @progbits +#define __PAGE_ALIGNED_BSS .section ".bss.page_aligned", "aw", @nobitsIt is my understanding that the linker will automatically assume nobits for section names starting with .bss and likewise progbits for section names starting with .data - so we can leave them out?
Quoted 8 lines
Quoted 2 lines
I believe that is correct.
... but that doesn't mean it's the right thing to do.
It's better to be fully explicit when macroizing this kind of stuff. This is part of why macroizing it is good: it means we end up with *one* place that determines this stuff, not some magic heuristics in the linker.
Do you know if we can use % in place of @?
I could see that gas supports both - at least in trunk in cvs.
Sam
A message that is not in the archive (sent off-list or not yet received): 20090501171717.GA26401-QabhHTsIXMSnlFQ6Q1D1Y0B+6BGkLq7r@public.gmane.org
Re: [PATCH v2 1/6] Add new macros for page-aligned data and bss sections.
Quoted 12 lines · Sam Ravnborg
Quoted 11 lines · H. Peter Anvin
Quoted 10 lines · Tim Abbott
Quoted 6 lines · Sam Ravnborg
Review
Quoted 2 lines · Tim Abbott
(quoted diff) +2
-0+#define __PAGE_ALIGNED_DATA .section ".data.page_aligned", "aw", @progbits +#define __PAGE_ALIGNED_BSS .section ".bss.page_aligned", "aw", @nobitsIt is my understanding that the linker will automatically assume nobits for section names starting with .bss and likewise progbits for section names starting with .data - so we can leave them out?
I believe that is correct.
Quoted 9 lines
Quoted 5 lines
... but that doesn't mean it's the right thing to do.
It's better to be fully explicit when macroizing this kind of stuff. This is part of why macroizing it is good: it means we end up with *one* place that determines this stuff, not some magic heuristics in the linker.
Do you know if we can use % in place of @?
I could see that gas supports both - at least in trunk in cvs.
I think it might depend on the architecture(!)... but it would definitely have to be an issue with testing a bunch of different versions.
What's wrong with @?
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Re: [PATCH v2 1/6] Add new macros for page-aligned data and bss sections.
Quoted 19 lines · H. Peter Anvin
Quoted 18 lines · Sam Ravnborg
Quoted 16 lines · H. Peter Anvin
Quoted 10 lines · Tim Abbott
Quoted 6 lines · Sam Ravnborg
Review
Quoted 2 lines · Tim Abbott
(quoted diff) +2
-0+#define __PAGE_ALIGNED_DATA .section ".data.page_aligned", "aw", @progbits +#define __PAGE_ALIGNED_BSS .section ".bss.page_aligned", "aw", @nobitsIt is my understanding that the linker will automatically assume nobits for section names starting with .bss and likewise progbits for section names starting with .data - so we can leave them out?
I believe that is correct.
... but that doesn't mean it's the right thing to do.
It's better to be fully explicit when macroizing this kind of stuff. This is part of why macroizing it is good: it means we end up with *one* place that determines this stuff, not some magic heuristics in the linker.
Quoted 8 lines
Quoted 3 lines
Do you know if we can use % in place of @?
I could see that gas supports both - at least in trunk in cvs.I think it might depend on the architecture(!)... but it would definitely have to be an issue with testing a bunch of different versions.
What's wrong with @?
arm does not support it :-(
I recall it denote a comment in arm assembler.
I could do some magic to detect the ARM case but I'm reluctant to do so. I could also ignore the arm issue for now as it is not used by arm, but that strikes me as the wrong approach.
Sam
A message that is not in the archive (sent off-list or not yet received): 20090501174457.GA26559-QabhHTsIXMSnlFQ6Q1D1Y0B+6BGkLq7r@public.gmane.org
Re: [PATCH v2 1/6] Add new macros for page-aligned data and bss sections.
Quoted 9 lines · Sam Ravnborg
Quoted 2 lines
What's wrong with @?
arm does not support it :-(
I recall it denote a comment in arm assembler.I could do some magic to detect the ARM case but I'm reluctant to do so. I could also ignore the arm issue for now as it is not used by arm, but that strikes me as the wrong approach.
If we really have to use different tokens, I would say:
#ifdef __ARM__
# define _PROGBITS %progbits /* or whatever */ # define _NOBITS %nobits #else # define _PROGBITS @progbits # define _NOBITS @nobits #endif
Otherwise we probably need to ask the binutils people...
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Re: [PATCH v2 1/6] Add new macros for page-aligned data and bss sections.
Quoted 13 lines · H. Peter Anvin
Quoted 9 lines · Sam Ravnborg
Quoted 2 lines
What's wrong with @?
arm does not support it :-(
I recall it denote a comment in arm assembler.I could do some magic to detect the ARM case but I'm reluctant to do so. I could also ignore the arm issue for now as it is not used by arm, but that strikes me as the wrong approach.
If we really have to use different tokens, I would say:
Quoted 7 lines
#ifdef
__ARM__# define _PROGBITS %progbits /* or whatever */ # define _NOBITS %nobits #else # define _PROGBITS @progbits # define _NOBITS @nobits #endif
GAS has always supported both '@' and '%', so '%' can be used everywhere.
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Quoted 29 lines · Tim Abbott
(this patch series differs from v1 only in the CC list; some of the architecture lists I sent the previous one to are moderated against non-members; all replies should go to this version).
Here are the architecture-independent macro definitions needed for to clean up the kernel's section names. The overall diffstat from this section name cleanup project is:
96 files changed, 261 insertions(+), 503 deletions(-)The decrease results from removing a lot of redundancy in the linker scripts.
The long-term goal here is to add support for building the kernel with -ffunction-sections -fdata-sections. This requires renaming all the magic section names in the kernel of the form .text.foo, .data.foo, .bss.foo, and .rodata.foo to not have collisions with sections generated for code like:
static int nosave = 0; /* -fdata-sections places in .data.nosave */ static void
head(); /* -ffunction-sections places in .text.head */Sam Ravnborg proposed that rather than just renaming all the sections outright, we should start by first getting more control over the section names used in the kernel so that we can later rename sections without touching too many files. These patch series implement that cleanup. Later, there will be another patch series to actually rename the sections.
Quoted 7 lines
I'm hoping we can get just these macro definitions into 2.6.30 so that the arch maintainers don't have to grab the macro definitions for their trees while reviewing the patches for 2.6.31.
Shortly, I'm going to send one patch series for each of the architectures updating those architectures to use these new macros (and otherwise cleaning up section names on those architectures).
Hi Tim.
We agreed to get the common stuff and one architecture done before proceeding with the rest.
Please stick to that plan so we avoid patch-bombing lkml + maintainers.
When we have this ready it will be a simple one-patch-per-arch to cover the rest.
I will comment on your common patches for now.
Sam
Quoted 37 lines · Tim Abbott
(this patch series differs from v1 only in the CC list; some of the architecture lists I sent the previous one to are moderated against non-members; all replies should go to this version).
Here are the architecture-independent macro definitions needed for to clean up the kernel's section names. The overall diffstat from this section name cleanup project is:
96 files changed, 261 insertions(+), 503 deletions(-)The decrease results from removing a lot of redundancy in the linker scripts.
The long-term goal here is to add support for building the kernel with -ffunction-sections -fdata-sections. This requires renaming all the magic section names in the kernel of the form .text.foo, .data.foo, .bss.foo, and .rodata.foo to not have collisions with sections generated for code like:
static int nosave = 0; /* -fdata-sections places in .data.nosave */ static void
head(); /* -ffunction-sections places in .text.head */Sam Ravnborg proposed that rather than just renaming all the sections outright, we should start by first getting more control over the section names used in the kernel so that we can later rename sections without touching too many files. These patch series implement that cleanup. Later, there will be another patch series to actually rename the sections.
I'm hoping we can get just these macro definitions into 2.6.30 so that the arch maintainers don't have to grab the macro definitions for their trees while reviewing the patches for 2.6.31.
Shortly, I'm going to send one patch series for each of the architectures updating those architectures to use these new macros (and otherwise cleaning up section names on those architectures).
Quoted 8 lines
-Tim Abbott
Tim Abbott (6):
Add new macros for page-aligned data and bss sections. Add newNOSAVE_DATAlinker script macro.
Add newCACHELINE_ALIGNED_DATAlinker script macro. Add newINIT_TASK_DATA()linker script macro. Add newREAD_MOSTLY_DATA(align)linker script macro.
I am about to apply this part of your patches.
I am doing some additional modifications and
will most likely apply them as one patch.
Will post to linux-arch for review when it is ready.
Sam
Hi Tim.
[cc trimmed so this hits lkml]
I've tried to make the patch to vmlinux.lds.h more complete. With this patch I managed to achive the following diffstat:
arch/mips/kernel/vmlinux.lds.S | 70 ++---------------- arch/mn10300/kernel/vmlinux.lds.S | 82 +++------------------- arch/sparc/kernel/vmlinux.lds.S | 82 +++------------------- include/asm-generic/vmlinux.lds.h | 139 ++++++++++++++++++++++++++++++++++++- 4 files changed, 165 insertions(+), 208 deletions(-)
So with 3 architecture I have more lines deleted than added. None of these has been build tested but this shows the potential.
Below you will find the *untested* patch for vmlinux.lds.h. This is the way I want to go where we have more complete definitions in the shared file and we try to keep the arch linker scripts to the arch specifc stuff.
This is not a 1:1 replacement for your patches as they touches files outside vmlinux.lds.h but I concentrated on this single file for now.
Comments welcome!
Sam
include/asm-generic/vmlinux.lds.h +136 -3
@@ -116,6 +116,43 @@ FTRACE_EVENTS() \TRACE_SYSCALLS () +/* +* Data section helpers + */ +#define NOSAVE_DATA \ + . = ALIGN(PAGE_SIZE); \ + VMLINUX_SYMBOL(__nosave_begin) = .; \ + *(.data.nosave) \ + . = ALIGN(PAGE_SIZE); \ + VMLINUX_SYMBOL(__nosave_end) = .; + +#define PAGE_ALIGNED_DATA (page_align) \ + . = ALIGN((page_align)); \ + *(.data.page_aligned) + +#define READ_MOSTLY_DATA (align) \ + . = ALIGN((align)); \ + *(.data.read_mostly) + +#define CACHELINE_ALIGNED_DATA (align) \ + . = ALIGN((align)); \ + *(.data.cacheline_aligned) + +/* use 0 as page_align if page_aligned data is not used */ +#define RW_DATA (page_align, readmostly_align, cache_align) \ + . = ALIGN(PAGE_SIZE); \ + .data : AT(ADDR(.data) - LOAD_OFFSET) { \ + DATA_DATA \ + CONSTRUCTORS \ + NOSAVE_DATA \ + PAGE_ALIGNED_DATA(page_align) \ + READMOSTLY_DATA((readmostly_align)) \ + CACHELINE_ALIGNED_DATA((cache_align)) \ + } + +/* +* Read only Data +*/ #define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
@@ -274,6 +311,18 @@* All archs are supposed to use RO_DATA() */ #define RODATA RO_DATA(4096) +#ifdef CONFIG_BLK_DEV_INITRD +#define INITRAMFS \ + . = ALIGN(PAGE_SIZE); \ + .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) { \ + VMLINUX_SYMBOL(__initramfs_start) = .; \ + *(.init.ramfs) \ + VMLINUX_SYMBOL(__initramfs_end) = .; \ + } +#else +#define INITRAMFS +#endif +#define SECURITY_INIT \ .security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \ VMLINUX_SYMBOL(__security_initcall_start) = .; \
@@ -281,6 +330,24 @@ VMLINUX_SYMBOL(__security_initcall_end) = .; \ } +#define INITDATA (initsetup_align) \ + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \ + INIT_DATA \ + . = ALIGN(initsetup_align); \ + VMLINUX_SYMBOL(__setup_start) = .; \ + *(.init.setup) \ + VMLINUX_SYMBOL(__setup_end) = .; \ + VMLINUX_SYMBOL(__initcall_start) = .; \ + INITCALLS \ + VMLINUX_SYMBOL(__initcall_end) = .; \ + VMLINUX_SYMBOL(__con_initcall_start) = .; \ + *(.con_initcall.init) \ + VMLINUX_SYMBOL(__con_initcall_end) = .; + VMLINUX_SYMBOL(__security_initcall_start) = .; \ + *(.security_initcall.init) \ + VMLINUX_SYMBOL(__security_initcall_end) = .; \ + } +/* .text section. Map to function alignment to avoid address changes * during second ld run in second ld pass when generating System.map */ #define TEXT_TEXT \
@@ -332,6 +399,29 @@/* Section used for early init (in .S files) */ #define HEAD_TEXT *(HEAD_TEXT_SECTION) +/* +* Exception table +*/ +#define EXCEPTION_TABLE (align) \ + . = ALIGN((align)); \ + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \ + VMLINUX_SYMBOL(__start___ex_table) = .; \ + *(__ex_table) \ + VMLINUX_SYMBOL(__stop___ex_table) = .; \ + } + +/* +* Init task +*/ +#define INIT_TASK \ + *(.data.init_task) + +#define INIT_TASK_DATA (align) \ + . = ALIGN((align)); \ + .data.init_task : { \ + INIT_TASK \ + } +/* init and exit section handling */ #define INIT_DATA \ *(.init.data) \
@@ -363,9 +453,52 @@ CPU_DISCARD(exit.text) \ MEM_DISCARD(exit.text) -/* DWARF debug sections. -Symbols in the DWARF debugging sections are relative to - the beginning of the section so we begin them at 0. */ +#define INITTEXT (inittext_align) \ + . = ALIGN((inittext_align)); \ + .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { \ + VMLINUX_SYMBOL(__init_begin) = .; \ + VMLINUX_SYMBOL(_sinittext) = .; \ + INIT_TEXT \ + VMLINUX_SYMBOL(_einittext) = .; \ + } + +#define INITDATA (initdata_align) \ + . = ALIGN((initdata_align)); \ + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \ + INIT_DATA \ + } + +/* +* bss +*/ +#define SBSS (sbss_align) \ + . = ALIGN((sbss_align)); \ + .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) { \ + *(.sbss) \ + *(.scommon) \ + } + +#define BSS (bss_align) \ + . = ALIGN((bss_align)); \ + .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \ + *(.bss.page_aligned) \ + *(.dynbss) \ + *(.bss) \ + *(COMMON) \ + } + +#define SBSS_BSS (sbss_align, bss_align) \ + VMLINUX_SYMBOL(__bss_start) = .; \ + SBSS(sbss_align) \ + BSS(bss_align) \ + ALIGN_FUNCTION(); \ + VMLINUX_SYMBOL(__bss_stop) = .; + +/* +* DWARF debug sections. +* Symbols in the DWARF debugging sections are relative to +* the beginning of the section so we begin them at 0. +*/ #define DWARF_DEBUG \/* DWARF 1 */ \ .debug 0 : { *(.debug) } \
Quoted 3 lines · Sam Ravnborg
This is the way I want to go where we have more complete definitions in the shared file and we try to keep the arch linker scripts to the arch specifc stuff.
I like the general look of this. Indeed, I was planning to work on something like this as a follow-on to the linker script cleanup work I've done so far.
Some comments on the details are below.
include/asm-generic/vmlinux.lds.h line 131
Quoted 3 lines
include/asm-generic/vmlinux.lds.h +3
-0+#define PAGE_ALIGNED_DATA (page_align) \ + . = ALIGN((page_align)); \ + *(.data.page_aligned)
Why does this need an argument? You should be able to just align to PAGE_SIZE.
Also, I'm not sure what you're trying to do with the double parentheses here (it also appears inconsistently in several other places in this patch).
include/asm-generic/vmlinux.lds.h line 151
Quoted 11 lines
include/asm-generic/vmlinux.lds.h +11
-0+/* use 0 as page_align if page_aligned data is not used */ +#define RW_DATA (page_align, readmostly_align, cache_align) \ + . = ALIGN(PAGE_SIZE); \ + .data : AT(ADDR(.data) - LOAD_OFFSET) { \ + DATA_DATA \ + CONSTRUCTORS \ + NOSAVE_DATA \ + PAGE_ALIGNED_DATA(page_align) \ + READMOSTLY_DATA((readmostly_align)) \ + CACHELINE_ALIGNED_DATA((cache_align)) \ + }
I think there are several architectures that have some other stuff in their .data output section (e.g. powerpc, frv, ia64), so we won't be able to use this on all architectures.
Perhaps we want an intermediate macro between DATA_DATA and RW_DATA that is just the contents of .data here that those architectuere can use?
Quoted 6 lines
include/asm-generic/vmlinux.lds.h +6
-0+#define INITDATA (initsetup_align) \ + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \ + INIT_DATA \ + . = ALIGN(initsetup_align); \ + VMLINUX_SYMBOL(__setup_start) = .; \ + *(.init.setup) \
[...]
include/asm-generic/vmlinux.lds.h line 469
Quoted 5 lines
include/asm-generic/vmlinux.lds.h +5
-0+#define INITDATA (initdata_align) \ + . = ALIGN((initdata_align)); \ + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \ + INIT_DATA \ + }
You define two different macros called INITDATA; I'm not sure what the intention is here.
include/asm-generic/vmlinux.lds.h line 424
Quoted 9 lines
include/asm-generic/vmlinux.lds.h +9
-0+#define INIT_TASK \ + *(.data.init_task) + +#define INIT_TASK_DATA (align) + . = ALIGN((align)); \ + .data.init_task : { \ + INIT_TASK \ + } +
You mentioned elsewhere you thought .data.init_task needs to be its own output section rather than part of the .data output section; why is that? There are several architectures on which it is part of the .data output section (e.g. sh, um, avr32).
Also, I think it is possible that INIT_TASK_DATA could just align to THREAD_SIZE rather than taking an argument. While working on my patches for this I noticed there were only a couple of architectures where the alignment wasn't THREAD_SIZE (or a value equal to THREAD_SIZE was used). One exception was parisc, where the aligment is 16384 and THREAD_SIZE is always at least that but could be bigger in some configs where PAGE_SIZE is bigger. I'm not sure whether this one exception is a bug.
-Tim Abbott
Quoted 9 lines · Tim Abbott
Quoted 3 lines · Sam Ravnborg
This is the way I want to go where we have more complete definitions in the shared file and we try to keep the arch linker scripts to the arch specifc stuff.
I like the general look of this. Indeed, I was planning to work on something like this as a follow-on to the linker script cleanup work I've done so far.
Keep in mind that my primary goal here is to clean up the linker scripts. Support for -ffunction-sections is only a spin-off of that. This is why I try to take a broader look at it.
Quoted 9 lines
Some comments on the details are below.
include/asm-generic/vmlinux.lds.h line 131
Quoted 3 lines
include/asm-generic/vmlinux.lds.h +3
-0+#define PAGE_ALIGNED_DATA (page_align) \ + . = ALIGN((page_align)); \ + *(.data.page_aligned)Why does this need an argument? You should be able to just align to
PAGE_SIZE.
Only a few archs supports .data.page_aligned so those that does not pass a 0 as alignmnet thus they do not waste any memory.
Quoted 4 lines
Also, I'm not sure what you're trying to do with the double parentheses here (it also appears inconsistently in several other places in this patch).
Old habbit - dropped now.
Quoted 16 lines
include/asm-generic/vmlinux.lds.h line 151
Quoted 12 lines
include/asm-generic/vmlinux.lds.h +11
-0+/* use 0 as page_align if page_aligned data is not used */ +#define RW_DATA (page_align, readmostly_align, cache_align) \ + . = ALIGN(PAGE_SIZE); \ + .data : AT(ADDR(.data) - LOAD_OFFSET) { \ + DATA_DATA \ + CONSTRUCTORS \ + NOSAVE_DATA \ + PAGE_ALIGNED_DATA(page_align) \ + READMOSTLY_DATA((readmostly_align)) \ + CACHELINE_ALIGNED_DATA((cache_align)) \ + }I think there are several architectures that have some other stuff in their .data output section (e.g. powerpc, frv, ia64), so we won't be able to use this on all architectures.
We have at least two situations to deal with:
1) archs that define more in .data
They can either define another output section named '.data' or they can name it differently.
frv should be able to do:
RW_DATA(...)
.data : {
*(.data.*)
EXIT_DATA
}ld allow us to define identical named output sections and it will append to the first when it encounter the name for the second time.
2) archs that do something special.
x86 is an example with has:
.data : AT(ADDR(.data) - LOAD_OFFSET) {
DATA_DATA
} :data
.data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
*(.data.nosave)
} :data.init2See that it add the data section to two different PHDRS. In this case they cannot use RW_DATA and need to fall back to the individual defines.
Quoted 11 lines
Perhaps we want an intermediate macro between
DATA_DATAandRW_DATAthat is just the contents of .data here that those architectuere can use?Quoted 6 lines
include/asm-generic/vmlinux.lds.h +6
-0+#define INITDATA (initsetup_align) \ + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \ + INIT_DATA \ + . = ALIGN(initsetup_align); \ + VMLINUX_SYMBOL(__setup_start) = .; \ + *(.init.setup) \[...]
Quoted 8 lines
include/asm-generic/vmlinux.lds.h line 469
Quoted 5 lines
include/asm-generic/vmlinux.lds.h +5
-0+#define INITDATA (initdata_align) \ + . = ALIGN((initdata_align)); \ + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \ + INIT_DATA \ + }You define two different macros called INITDATA; I'm not sure what the intention is here.
Bug - fixed.
Quoted 15 lines
include/asm-generic/vmlinux.lds.h line 424
Quoted 10 lines
include/asm-generic/vmlinux.lds.h +9
-0+#define INIT_TASK \ + *(.data.init_task) + +#define INIT_TASK_DATA (align) + . = ALIGN((align)); \ + .data.init_task : { \ + INIT_TASK \ + } +You mentioned elsewhere you thought .data.init_task needs to be its own output section rather than part of the .data output section; why is that? There are several architectures on which it is part of the .data output section (e.g. sh, um, avr32).
I had noticed it was not part of the .data output section in some cases. But it occur to me not to make any big difference now I have loked closer so I have moved it inside RW_DATA() for now.
Quoted 8 lines
Also, I think it is possible that
INIT_TASK_DATAcould just align toTHREAD_SIZErather than taking an argument. While working on my patches for this I noticed there were only a couple of architectures where the alignment wasn'tTHREAD_SIZE(or a value equal toTHREAD_SIZEwas used). One exception was parisc, where the aligment is 16384 andTHREAD_SIZEis always at least that but could be bigger in some configs wherePAGE_SIZEis bigger. I'm not sure whether this one exception is a bug.
That triggered some discussions - I will read and see the conclusions.
Sam
Quoted 7 lines · Sam Ravnborg
Quoted 6 lines · Tim Abbott
Quoted 3 lines · Sam Ravnborg
This is the way I want to go where we have more complete definitions in the shared file and we try to keep the arch linker scripts to the arch specifc stuff.
Quoted 7 lines
Quoted 3 lines
I like the general look of this. Indeed, I was planning to work on something like this as a follow-on to the linker script cleanup work I've done so far.
Keep in mind that my primary goal here is to clean up the linker scripts. Support for -ffunction-sections is only a spin-off of that. This is why I try to take a broader look at it.
Here comes the reworked version.
I have addressed your comments (thanks!), and also added a lot more stuff.
I'm especially found of the "minimal" linker script contained in the beginning of the file.
This helped me to gain better understanding of the general sturcture - And I then also quickly spotted when an architecture does not follow the normal flow.
I have converted powerpc to the new scheme - which I have done a test build of.
If/when we get this in I will help all architectures to convert to use these new defines killing a lot of duplication in the process.
But we need to get this stuff agreed on first.
Comments appreciated!
Sam
include/asm-generic/vmlinux.lds.h +209 -4
@@ -1,4 +1,60 @@ -#include <linux/section-names.h> +/* +* Helper macros to support writing architecture specific +* linker scripts. +* +* A minimal linker scripts has following content: +* +* OUTPUT_FORMAT(...) +* OUTPUT_ARCH(...) +* ENTRY(...) +* SECTIONS +* { +* . = START; +* _stext = .; +* .text : { +* HEAD_TEXT +* TEXT_TEXT +* SCHED_TEXT +* LOCK_TEXT +* KPROBES_TEXT +* IRQENTRY_TEXT +* } = 0 +* _etext = .; +* +* RO_DATA_SECTION(PAGE_SIZE) +* RW_DATA_SECTION(...) +* _edata = .; +* +* EXCEPTION_TABLE(...) +* NOTES +* +* __init_begin = .; +* INIT_TEXT_SECTION(PAGE_SIZE) +* INIT_DATA_SECTION(...) +* PERCPU(PAGE_SIZE) +* __init_end = .; +* +* BSS_SECTION(0, 0) +* _end = .; +* +* /DISCARD/ : { +* EXIT_TEXT +* EXIT_DATA +* *(.exitcall.exit) +* } +* STABS_DEBUG +* DWARF_DEBUG +* } +* +* [_stext, _etext] is the text section +* [_etext, _edata] is the data section +* [__init_begin, __init_end] is the init section that may be freed after init +* +* Some of the included output section include their own set of constants. +* Examples are: [__initramfs_start, __initramfs_end] for initramfs and +* [__nosave_begin, __nosave_end] for the nosave data +*/ +#include <linux/section-names.h> #ifndef LOAD_OFFSET #define LOAD_OFFSET 0
@@ -116,6 +172,35 @@ FTRACE_EVENTS() \TRACE_SYSCALLS () +/* +* Data section helpers + */ +#define NOSAVE_DATA \ + . = ALIGN(PAGE_SIZE); \ + VMLINUX_SYMBOL(__nosave_begin) = .; \ + *(.data.nosave) \ + . = ALIGN(PAGE_SIZE); \ + VMLINUX_SYMBOL(__nosave_end) = .; + +#define PAGE_ALIGNED_DATA (page_align) \ + . = ALIGN(page_align); \ + *(.data.page_aligned) + +#define READ_MOSTLY_DATA (align) \ + . = ALIGN(align); \ + *(.data.read_mostly) + +#define CACHELINE_ALIGNED_DATA (align) \ + . = ALIGN(align); \ + *(.data.cacheline_aligned) + +#define INIT_TASK (align) \ + . = ALIGN(align); \ + *(.data.init_task) + +/* +* Read only Data +*/ #define RO_DATA (align) \ . = ALIGN((align)); \ .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
@@ -332,6 +417,26 @@/* Section used for early init (in .S files) */ #define HEAD_TEXT *(HEAD_TEXT_SECTION) +/* +* Exception table +*/ +#define EXCEPTION_TABLE (align) \ + . = ALIGN(align); \ + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \ + VMLINUX_SYMBOL(__start___ex_table) = .; \ + *(__ex_table) \ + VMLINUX_SYMBOL(__stop___ex_table) = .; \ + } + +/* +* Init task +*/ +#define INIT_TASK_DATA (align) \ + . = ALIGN(align); \ + .data.init_task : { \ + INIT_TASK \ + } +/* init and exit section handling */ #define INIT_DATA \ *(.init.data) \
@@ -363,9 +468,32 @@ CPU_DISCARD(exit.text) \MEM_DISCARD (exit.text) -/* DWARF debug sections. -Symbols in the DWARF debugging sections are relative to - the beginning of the section so we begin them at 0. */ +/* +* bss (Block started by Symbol) - uninitialized data +* zeroed during startup + */ +#define SBSS \ + .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) { \ + *(.sbss) \ + *(.scommon) \ + } + +#define BSS (bss_align) \ + . = ALIGN(bss_align); \ + .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \ + VMLINUX_SYMBOL(__bss_start) = .; \ + *(.bss.page_aligned) \ + *(.dynbss) \ + *(.bss) \ + *(COMMON) \ + VMLINUX_SYMBOL(__bss_stop) = .; \ + } + +/* +* DWARF debug sections. +* Symbols in the DWARF debugging sections are relative to +* the beginning of the section so we begin them at 0. +*/ #define DWARF_DEBUG \/* DWARF 1 */ \ .debug 0 : { *(.debug) } \
@@ -432,6 +560,12 @@ VMLINUX_SYMBOL(__stop_notes) = .; \ } +#define INIT_SETUP (initsetup_align) \ + . = ALIGN(initsetup_align); \ + VMLINUX_SYMBOL(__setup_start) = .; \ + *(.init.setup) \ + VMLINUX_SYMBOL(__setup_end) = .; +#define INITCALLS \ *(.initcallearly.init) \ VMLINUX_SYMBOL(__early_initcall_end) = .; \
@@ -453,6 +587,31 @@ *(.initcall7.init) \ *(.initcall7s.init) +#define INIT_CALLS \ + VMLINUX_SYMBOL(__initcall_start) = .; \ + INITCALLS \ + VMLINUX_SYMBOL(__initcall_end) = .; + +#define CON_INITCALL \ + VMLINUX_SYMBOL(__con_initcall_start) = .; \ + *(.con_initcall.init) \ + VMLINUX_SYMBOL(__con_initcall_end) = .; + +#define SECURITY_INITCALL \ + VMLINUX_SYMBOL(__security_initcall_start) = .; \ + *(.security_initcall.init) \ + VMLINUX_SYMBOL(__security_initcall_end) = .; + +#ifdef CONFIG_BLK_DEV_INITRD +#define INIT_RAM_FS \ + . = ALIGN(PAGE_SIZE); \ + VMLINUX_SYMBOL(__initramfs_start) = .; \ + *(.init.ramfs) \ + VMLINUX_SYMBOL(__initramfs_end) = .; +#else +#define INITRAMFS +#endif +/** * PERCPU_VADDR - define output section for percpu area * @vaddr: explicit base address (optional)
@@ -509,3 +668,49 @@ *(.data.percpu.shared_aligned) \ VMLINUX_SYMBOL(__per_cpu_end) = .; \ } + + +/* +* Definition of the high level *_SECTION macros +* They will fit only a subset of the architectures +*/ + +#define RO_DATA_SECTION (align) RO_DATA(align) + +/* use 0 as page_align if page_aligned data is not used */ +#define RW_DATA_SECTION (page_align, readmostly_align, cache_align, inittask_align) \ + . = ALIGN(PAGE_SIZE); \ + .data : AT(ADDR(.data) - LOAD_OFFSET) { \ + DATA_DATA \ + CONSTRUCTORS \ + NOSAVE_DATA \ + PAGE_ALIGNED_DATA(page_align) \ + READMOSTLY_DATA(readmostly_align) \ + CACHELINE_ALIGNED_DATA(cache_align) \ + INIT_TASK(inittask_align) \ + } + +#define INIT_TEXT_SECTION (inittext_align) \ + . = ALIGN(inittext_align); \ + .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { \ + VMLINUX_SYMBOL(_sinittext) = .; \ + INIT_TEXT \ + VMLINUX_SYMBOL(_einittext) = .; \ + } + +#define INIT_DATA_SECTION (initsetup_align) \ + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \ + INIT_DATA \ + INIT_SETUP(initsetup_align) \ + INIT_CALLS \ + CON_INITCALL \ + SECURITY_INITCALL \ + INIT_RAM_FS \ + } + +#define BSS_SECTION (sbss_align, bss_align) \ + SBSS \ + VMLINUX_SYMBOL(__bss_start) = .; \ + BSS(bss_align) \ + . = ALIGN(4); \ + VMLINUX_SYMBOL(__bss_stop) = .;
[PATCH/RFC] Sample conversion of powerpc
This is the patch to convert powerpc to the
new linker script setup.
Note that powerpc does not take benefit of all the consolidations.
Sam
arch/powerpc/kernel/vmlinux.lds.S | 53 +++++-------------------------------- 1 files changed, 7 insertions(+), 46 deletions(-)
arch/powerpc/kernel/vmlinux.lds.S +7 -46
@@ -75,14 +75,8 @@ SECTIONS PROVIDE32 (etext = .); /* Read-only data */ - RODATA - - /* Exception & bug tables */ - __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { - __start___ex_table = .; - *(__ex_table) - __stop___ex_table = .; - } + RO_DATA_SECTION(PAGE_SIZE) + EXCEPTION_TABLE(1) NOTES :kernel :notes
@@ -100,11 +94,7 @@ SECTIONS . = ALIGN(PAGE_SIZE); __init_begin = .; - .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { - _sinittext = .; - INIT_TEXT - _einittext = .; - } :kernel + INIT_TEXT_SECTION(PAGE_SIZE) :kernel /* .exit.text is discarded at runtime, not link time, * to deal with references from __bug_table
@@ -113,8 +103,10 @@ SECTIONS EXIT_TEXT } - .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { - INIT_DATA + INIT_DATA_SECTION(16) + PERCPU(PAGE_SIZE) + + .init.data : { __vtop_table_begin = .; *(.vtop_fixup); __vtop_table_end = .;
@@ -128,27 +120,6 @@ SECTIONS #endif } - . = ALIGN(16); - .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) { - __setup_start = .; - *(.init.setup) - __setup_end = .; - } - - .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) { - __initcall_start = .; - INITCALLS - __initcall_end = .; - } - - .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) { - __con_initcall_start = .; - *(.con_initcall.init) - __con_initcall_end = .; - } - - SECURITY_INIT - . = ALIGN(8); __ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) { __start___ftr_fixup = .;
@@ -175,15 +146,6 @@ SECTIONS __stop___fw_ftr_fixup = .; } #endif -#ifdef CONFIG_BLK_DEV_INITRD - . = ALIGN(PAGE_SIZE); - .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) { - __initramfs_start = .; - *(.init.ramfs) - __initramfs_end = .; - } -#endif - PERCPU(PAGE_SIZE) . = ALIGN(8); .machine.desc : AT(ADDR(.machine.desc) - LOAD_OFFSET) {
@@ -247,7 +209,6 @@ SECTIONS . = ALIGN(PAGE_SIZE); _edata = .; - PROVIDE32 (edata = .); /* The initial task and kernel stack */ #ifdef CONFIG_PPC32
Quoted 2 lines · Sam Ravnborg
I'm especially fond of the "minimal" linker script contained in the beginning of the file.
I like this a lot too.
Quoted 5 lines
+ * /DISCARD/ : {
+ * EXIT_TEXT + * EXIT_DATA + * *(.exitcall.exit)+ * }
You may want to create an EXIT_CALL macro, to remove the explicit mention of .exitcall.exit, which is the only input section referenced directly in the example script.
include/asm-generic/vmlinux.lds.h line 191
Quoted 3 lines
include/asm-generic/vmlinux.lds.h +3
-0+#define READ_MOSTLY_DATA (align) \ + . = ALIGN(align); \ + *(.data.read_mostly)
Should READ_MOSTLY_DATA have an ALIGN(align) at the end as well? If the goal is to isolate READ_MOSTLY_DATA from other data at the given alignment level, this would seem appropriate. Something similar may apply to CACHELINE_ALIGNED_DATA as well.
include/asm-generic/vmlinux.lds.h line 479
Quoted 9 lines
include/asm-generic/vmlinux.lds.h +9
-0+/* +* bss (Block started by Symbol) - uninitialized data +* zeroed during startup +*/ +#define SBSS \ + .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) { \ + *(.sbss) \ + *(.scommon) \ + }
I notice that s390 and powerpc reference a ".dynsbss"; does that belong here?
include/asm-generic/vmlinux.lds.h line 613
Quoted 9 lines
include/asm-generic/vmlinux.lds.h +9
-0+#ifdef CONFIG_BLK_DEV_INITRD +#define INIT_RAM_FS \ + . = ALIGN(PAGE_SIZE); \ + VMLINUX_SYMBOL(__initramfs_start) = .; \ + *(.init.ramfs) \ + VMLINUX_SYMBOL(__initramfs_end) = .; +#else +#define INITRAMFS +#endif
I think you want the #else clause to be INIT_RAM_FS here.
Quoted 4 lines
+/*
+ * Definition of the high level*_SECTIONmacros
+ * They will fit only a subset of the architectures
+ */
Do we want a TEXT_SECTION macro here as well that looks like what appears above in the example script?
Quoted 1 line
+#define RW_DATA_SECTION(page_align,
readmostly_align,cache_align,
inittask_align) \
include/asm-generic/vmlinux.lds.h line 691
Quoted 10 lines
include/asm-generic/vmlinux.lds.h +10
-0+ . = ALIGN(PAGE_SIZE); \ + .data : AT(ADDR(.data) - LOAD_OFFSET) { \ +DATA_DATA \ + CONSTRUCTORS \ + NOSAVE_DATA \ + PAGE_ALIGNED_DATA(page_align) \ + READMOSTLY_DATA(readmostly_align) \ + CACHELINE_ALIGNED_DATA(cache_align) \ + INIT_TASK(inittask_align) \ + }
How did you pick the order of the sections here? I would think that to pack the .data section efficiently, you'd want to sort by alignment requirements so that e.g. all the at-least-page aligned sections are adjacent (INIT_TASK and the page-aligned sections are separated by some much smaller aligments here). So it would like either the following or the following reversed:
. = ALIGN(PAGE_SIZE); \
.data : AT(ADDR(.data) - LOAD_OFFSET) { \
INIT_TASK(inittask_align) \
NOSAVE_DATA \
PAGE_ALIGNED_DATA(page_align) \
READMOSTLY_DATA(readmostly_align) \
CACHELINE_ALIGNED_DATA(cache_align) \
DATA_DATA \
CONSTRUCTORS \
}
-Tim AbbottQuoted 14 lines · Tim Abbott
Quoted 4 lines · Sam Ravnborg
+#define RW_DATA_SECTION(page_align,
readmostly_align,cache_align,
inittask_align) \
+ . =ALIGN(PAGE_SIZE); \
+ .data :AT(ADDR(.data) - LOAD_OFFSET){ \Quoted 8 lines
+
DATA_DATA\
+ CONSTRUCTORS \
+NOSAVE_DATA\
+PAGE_ALIGNED_DATA(page_align)\
+READMOSTLY_DATA(readmostly_align)\
+CACHELINE_ALIGNED_DATA(cache_align)\
+INIT_TASK(inittask_align)\
+ }
Quoted 5 lines
How did you pick the order of the sections here? I would think that to pack the .data section efficiently, you'd want to sort by alignment requirements so that e.g. all the at-least-page aligned sections are adjacent (
INIT_TASKand the page-aligned sections are separated by some much smaller aligments here).
if this were actually the case, there should of course be some /* comments */ above the define explaining that the order wasnt arbitrarily pulled like a rabbit from an orifice. if you're scratching your head, then there's going to be plenty more people who never ask but treat it like untouchable voodoo.
-mike
Quoted 21 lines · Mike Frysinger
Quoted 14 lines · Tim Abbott
Quoted 4 lines · Sam Ravnborg
+#define RW_DATA_SECTION(page_align,
readmostly_align,cache_align,
inittask_align) \
+ . =ALIGN(PAGE_SIZE); \
+ .data :AT(ADDR(.data) - LOAD_OFFSET){ \Quoted 8 lines
+
DATA_DATA\
+ CONSTRUCTORS \
+NOSAVE_DATA\
+PAGE_ALIGNED_DATA(page_align)\
+READMOSTLY_DATA(readmostly_align)\
+CACHELINE_ALIGNED_DATA(cache_align)\
+INIT_TASK(inittask_align)\
+ }Quoted 5 lines
How did you pick the order of the sections here? I would think that to pack the .data section efficiently, you'd want to sort by alignment requirements so that e.g. all the at-least-page aligned sections are adjacent (
INIT_TASKand the page-aligned sections are separated by some much smaller aligments here).
Quoted 5 lines
if this were actually the case, there should of course be some /* comments */ above the define explaining that the order wasnt arbitrarily pulled like a rabbit from an orifice. if you're scratching your head, then there's going to be plenty more people who never ask but treat it like untouchable voodoo.
Point taken (from both of you).
I will try to document the order in next version.
In reality I just picked the order used for 32 bit x86 IIRC.
Sam