2003-01-12 21:59:12

by Sam Ravnborg

[permalink] [raw]
Subject: [RFC] Consolidate vmlinux.lds.S files

Recently we have seen seveal changes to arch/*/vmlinux-lds.S,
mainly introduced by the module support but also other changes.

This is first version, where I have converted i386, s390 and sparc64.
The latter two is not tested, only to make sure it can be used by more
than one platform.

include/asm-generic/vmlinux.lds contains common definitions.
inserted below + three diffs.

i386/vmlinux.lds.S | 148 ++++++++++++++---------------------------------
s390/vmlinux.lds.S | 138 +++++++++++++-------------------------------
sparc64/vmlinux.lds.S | 156 +++++++++++++++++++-------------------------------
3 files changed, 149 insertions(+), 293 deletions(-)

The architecture specific files became smaller.
And adding new stuff is easier.

If this the correct way of doing it - or do you have any better ways
to do it?

Comments appreciated!

Sam

/*
* Generic Linker definitions
*
* Used to share linker definitions across architectures.
*/


/* .text section - default for all code
* start: where .text section starts.
* fill: fill gaps with this value
* extra: additional sections as part of .text
**/
#define TEXT_SECTION_CMD(start, vma, fill, extra) \
TEXT_SECTION_START(start, vma) { \
TEXT_SECTION_CONTENT \
extra \
} = (fill) \
TEXT_SECTION_END

/* start specify where .text starts */
#define TEXT_SECTION_START(start, vma) \
. = (start); \
_text = .; \
.text vma :

#define TEXT_SECTION_CONTENT \
*(.text) \
*(.fixup) \
*(.gnu.warning) \

/* End of TEXT section. Allow architectures to put something in between. */
#define TEXT_SECTION_END \
_etext = .; \
PROVIDE(etext = .);


/* FIXME: Purpose? */
#define RODATA \
.rodata : { *(.rodata) *(.rodata.*) }

/* FIXME: Kernel strings */
#define KSTRTAB \
.kstrtab : { *(.kstrtab) }

/* Exception table */
#define EXCEPTIONTABLE(align) \
. = ALIGN(align); \
__start___ex_table = .; \
__ex_table : { *(__ex_table) } \
__stop___ex_table = .;

/* Kernel symbol table */
#define KERNEL_SYMBOLS \
. = ALIGN(64); \
__start___ksymtab = .; \
__ksymtab : { *(__ksymtab) } \
__stop___ksymtab = .; \
\
/* Symbol table for GPL symbols */ \
__start___gpl_ksymtab = . ; \
__gpl_ksymtab : { *(__gpl_ksymtab) } \
__stop___gpl_ksymtab = . ; \
\
/* All kernel symbols */ \
__start___kallsyms = .; \
__kallsyms : { *(__kallsyms) } \
__stop___kallsyms = .;


/* Start of Data section. Use . if no specific start address */
#define DATA_SECTION_START(start) \
. = (start); \
.data :

/* .data section content */
#define DATA_SECTION \
*(.data) \
CONSTRUCTORS

/* End of DATA section. Allow architectures to put something in between. */
#define DATA_SECTION_END \
_edata = .; \
PROVIDE(edata = .);


#define NOSAVE(nosave_align) \
/* FIXME: Purpose */ \
. = ALIGN(nosave_align); \
__nosave_begin = .; \
.data_nosave : \
{ *(.data.nosave) } \
. = ALIGN(nosave_align); \
__nosave_end = .;

#define DATA_PAGE_ALIGN(page_align) \
. = ALIGN(page_align); \
.data.page_aligned : { *(.data.idt) }

#define DATA_CACHELINE_ALIGN(cache_align) \
. = ALIGN(cache_align); \
.data.cacheline_aligned : \
{ *(.data.cacheline_aligned) }


/* Initial thread structure (init_task) */
#define DATA_INIT_TASK(task_align) \
. = ALIGN(task_align); \
.data.init_task : { *(.data.init_task) }


/* __init_begin mars start of chunk of memory
* that will be freed after init
**/
#define INIT_BEGIN(align) \
. = ALIGN(align); \
__init_begin = .;

/* .init.text and .init.data is used for early initialisation */
#define INIT_TEXTDATA \
.init.text : { *(.init.text) } \
.init.data : { *(.init.data) }

/* Obsolete section used for module parameters */
#define INIT_SETUP(align) \
. = ALIGN (align) ; \
__setup_start = . ; \
.init.setup : { *(.init.setup) } \
__setup_end = . ;

/* Module / boot parameters */
#define MODULE_PARAM \
__start___param = . ; \
__param : { *(__param) } \
__stop___param = . ;

/* Init call tables */
#define INIT_CALLS \
__initcall_start = .; \
.initcall.init : { \
*(.initcall.init) \
*(.initcall1.init) \
*(.initcall2.init) \
*(.initcall3.init) \
*(.initcall4.init) \
*(.initcall5.init) \
*(.initcall6.init) \
*(.initcall7.init) \
} \
__initcall_end = . ;

#define INIT_RAMFS(ramfs_align) \
. = ALIGN(ramfs_align); \
__initramfs_start = .; \
.init.ramfs : { *(.init.ramfs) } \
__initramfs_end = .;

#define PERCPU(align) \
. = ALIGN(align); \
__per_cpu_start = .; \
.data.percpu : { *(.data.percpu) } \
__per_cpu_end = .;

#define INIT_END(end_align) \
. = ALIGN(end_align); \
__init_end = .;

#define BSS(bss_start, bss_align) \
. = bss_start; \
__bss_start = ALIGN(bss_align); \
.bss : { *(.bss) } \
__bss_stop = .;

/* Following list of sections are discarded by the linker.
* Most architectures can use the default.
* To extend the list use the following syntax:
* /DISCARD/ : {
* DISCARD_SECTION
* *(section.exit.text)
* }
**/
#define DISCARD_SECTION_CMD \
/DISCARD/ : { \
DISCARD_SECTION \
}

/* Default sections to be discarded */
#define DISCARD_SECTION \
*(.exit.text) \
*(.exit.data) \
*(.exitcall.exit) \

/* Stabs debugging sections. */
#define STABS_DEBUG \
.stab 0 : { *(.stab) } \
.stabstr 0 : { *(.stabstr) } \
.stab.excl 0 : { *(.stab.excl) } \
.stab.exclstr 0 : { *(.stab.exclstr) } \
.stab.index 0 : { *(.stab.index) } \
.stab.indexstr 0 : { *(.stab.indexstr) } \
.comment 0 : { *(.comment) }

/* Default INIT section.
* All sections within this part are freed after init
* by the kernel.
* Architectures has different alignment requirments,
* reflected in the parameters passed.
**/
#define INIT_SECTION_CMD(align, setup, ramfs, percpu) \
INIT_BEGIN(align) \
INIT_TEXTDATA \
/* Obsolete? init.setup section */ \
INIT_SETUP(setup) \
/* boot / module parameters */ \
MODULE_PARAM \
INIT_CALLS \
INIT_RAMFS(ramfs) \
PERCPU(percpu) \
INIT_END(align)

===== arch/i386/vmlinux.lds.S 1.21 vs edited =====
--- 1.21/arch/i386/vmlinux.lds.S Tue Dec 3 02:03:16 2002
+++ edited/arch/i386/vmlinux.lds.S Sun Jan 12 22:55:49 2003
@@ -1,117 +1,59 @@
/* ld script to make i386 Linux kernel
* Written by Martin Mares <[email protected]>;
*/
+
+#include <asm-generic/vmlinux.lds>
+
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_start)
jiffies = jiffies_64;
+
SECTIONS
{
- . = 0xC0000000 + 0x100000;
- /* read-only */
- _text = .; /* Text and read-only data */
- .text : {
- *(.text)
- *(.fixup)
- *(.gnu.warning)
- } = 0x9090
-
- _etext = .; /* End of text section */
-
- .rodata : { *(.rodata) *(.rodata.*) }
- .kstrtab : { *(.kstrtab) }
-
- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
-
- . = ALIGN(64);
- __start___ksymtab = .; /* Kernel symbol table */
- __ksymtab : { *(__ksymtab) }
- __stop___ksymtab = .;
-
- __start___kallsyms = .; /* All kernel symbols */
- __kallsyms : { *(__kallsyms) }
- __stop___kallsyms = .;
-
- /* writeable */
- .data : { /* Data */
- *(.data)
- CONSTRUCTORS
+ /* Start = 0xC...
+ * vma =
+ * extra =
+ */
+ TEXT_SECTION_CMD(0xC0000000 + 0x100000,, 0x9090, )
+ RODATA
+ KSTRTAB
+ EXCEPTIONTABLE(16)
+ KERNEL_SYMBOLS
+
+ /* start = .
+ * aling = 1
+ */
+ DATA_SECTION_START(.)
+ {
+ DATA_SECTION
}

- . = ALIGN(4096);
- __nosave_begin = .;
- .data_nosave : { *(.data.nosave) }
- . = ALIGN(4096);
- __nosave_end = .;
-
- . = ALIGN(4096);
- .data.page_aligned : { *(.data.idt) }
-
- . = ALIGN(32);
- .data.cacheline_aligned : { *(.data.cacheline_aligned) }
-
- _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 */
- __init_begin = .;
- .init.text : { *(.init.text) }
- .init.data : { *(.init.data) }
- . = ALIGN(16);
- __setup_start = .;
- .init.setup : { *(.init.setup) }
- __setup_end = .;
- __start___param = .;
- __param : { *(__param) }
- __stop___param = .;
- __initcall_start = .;
- .initcall.init : {
- *(.initcall1.init)
- *(.initcall2.init)
- *(.initcall3.init)
- *(.initcall4.init)
- *(.initcall5.init)
- *(.initcall6.init)
- *(.initcall7.init)
- }
- __initcall_end = .;
- . = ALIGN(4096);
- __initramfs_start = .;
- .init.ramfs : { *(.init.ramfs) }
- __initramfs_end = .;
- . = ALIGN(32);
- __per_cpu_start = .;
- .data.percpu : { *(.data.percpu) }
- __per_cpu_end = .;
- . = ALIGN(4096);
- __init_end = .;
- /* freed after init ends here */
+ NOSAVE(4096)
+ DATA_PAGE_ALIGN(4096)
+ DATA_CACHELINE_ALIGN(32)
+ DATA_SECTION_END
+
+ DATA_INIT_TASK(8192)
+
+ /* The following is freed by kernel after init
+ * Alignment 4096
+ * init.setup alignment 12
+ * ramfs alignment 4096
+ * percpu alignment 32
+ **/
+ INIT_SECTION_CMD(4096, 16, 4096, 32)
+
+ /* No specific bss alignment */
+ BSS(., 1)
+
+ /* Global end marker */
+ _end = . ;

- __bss_start = .; /* BSS */
- .bss : { *(.bss) }
- __bss_stop = .;
-
- _end = . ;
-
- /* Sections to be discarded */
- /DISCARD/ : {
- *(.exit.text)
- *(.exit.data)
- *(.exitcall.exit)
- }
+ /* Will be discarded */
+ DISCARD_SECTION_CMD

- /* Stabs debugging sections. */
- .stab 0 : { *(.stab) }
- .stabstr 0 : { *(.stabstr) }
- .stab.excl 0 : { *(.stab.excl) }
- .stab.exclstr 0 : { *(.stab.exclstr) }
- .stab.index 0 : { *(.stab.index) }
- .stab.indexstr 0 : { *(.stab.indexstr) }
- .comment 0 : { *(.comment) }
+ /* Stabs for debugging */
+ STABS_DEBUG
}
+
===== arch/s390/vmlinux.lds.S 1.5 vs edited =====
--- 1.5/arch/s390/vmlinux.lds.S Mon Nov 18 21:11:00 2002
+++ edited/arch/s390/vmlinux.lds.S Sun Jan 12 22:53:54 2003
@@ -7,108 +7,54 @@
jiffies = jiffies_64 + 4;
SECTIONS
{
- . = 0x00000000;
- _text = .; /* Text and read-only data */
- .text : {
- *(.text)
- *(.fixup)
- *(.gnu.warning)
- } = 0x0700
-
- _etext = .; /* End of text section */
-
- .rodata : { *(.rodata) *(.rodata.*) }
- .kstrtab : { *(.kstrtab) }
-
- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
-
- . = ALIGN(64);
- __start___ksymtab = .; /* Kernel symbol table */
- __ksymtab : { *(__ksymtab) }
- __stop___ksymtab = .;
+ /* Start = 0x0
+ * fill = 0x0700
+ TEXT_SECTION_CMD(0x0, , 0x0700,)
+
+ RODATA
+ KSTRTAB
+
+ EXCEPTIONTABLE(16)
+ KERNEL_SYMBOLS

#ifdef CONFIG_SHARED_KERNEL
- . = ALIGN(1048576); /* VM shared segments are 1MB aligned */
+ . = ALIGN(1048576); /* VM shared segments are 1MB aligned */

- _eshared = .; /* End of shareable data */
+ _eshared = .; /* End of shareable data */
#endif

- .data : { /* Data */
- *(.data)
- CONSTRUCTORS
+ /* Data */
+ DATA_SECTION_START(.) {
+ DATA_SECTION
}
+ DATA_SECTION_END

- . = ALIGN(4096);
- __nosave_begin = .;
- .data_nosave : { *(.data.nosave) }
- . = ALIGN(4096);
- __nosave_end = .;
-
- . = ALIGN(4096);
- .data.page_aligned : { *(.data.idt) }
-
- . = ALIGN(32);
- .data.cacheline_aligned : { *(.data.cacheline_aligned) }
-
- _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 */
- __init_begin = .;
- .init.text : { *(.init.text) }
- .init.data : { *(.init.data) }
- . = ALIGN(256);
- __setup_start = .;
- .init.setup : { *(.init.setup) }
- __setup_end = .;
- __initcall_start = .;
- .initcall.init : {
- *(.initcall1.init)
- *(.initcall2.init)
- *(.initcall3.init)
- *(.initcall4.init)
- *(.initcall5.init)
- *(.initcall6.init)
- *(.initcall7.init)
- }
- __initcall_end = .;
- . = ALIGN(256);
- __initramfs_start = .;
- .init.ramfs : { *(.init.initramfs) }
- __initramfs_end = .;
- . = ALIGN(256);
- __per_cpu_start = .;
- .data.percpu : { *(.data.percpu) }
- __per_cpu_end = .;
- . = ALIGN(4096);
- __init_end = .;
- /* freed after init ends here */
-
- __bss_start = .; /* BSS */
- .bss : { *(.bss) }
- __bss_stop = .;
-
- _end = . ;
-
- /* Sections to be discarded */
- /DISCARD/ : {
- *(.exit.text)
- *(.exit.data)
- *(.exitcall.exit)
- }
+ NOSAVE(4096)
+ DATA_PAGE_ALIGN(4096)
+ DATA_CACHE_LINE_ALIGN(32)
+ DATA_SECTION_END
+
+
+ DATA_INIT_TASK(8192);
+
+ /* The following is freed by kernel after init
+ * Alignment 4096
+ * init.setup alignment 256
+ * ramfs alignment 256
+ * percpu alignment 256
+ * Note: includes MODULE_PARAM, which is unused on S390
+ **/
+ INIT_SECTION_CMD(4096, 256, 256, 256)
+
+ /* start = .
+ * align = 1
+ */
+ BSS(., 1)
+
+ _end = . ;
+
+ DISCARD_SECTION_CMD

- /* Stabs debugging sections. */
- .stab 0 : { *(.stab) }
- .stabstr 0 : { *(.stabstr) }
- .stab.excl 0 : { *(.stab.excl) }
- .stab.exclstr 0 : { *(.stab.exclstr) }
- .stab.index 0 : { *(.stab.index) }
- .stab.indexstr 0 : { *(.stab.indexstr) }
- .comment 0 : { *(.comment) }
+ /* Stabs debugging sections. */
+ STABS_DEBUG
}
===== arch/sparc64/vmlinux.lds.S 1.13 vs edited =====
--- 1.13/arch/sparc64/vmlinux.lds.S Tue Dec 3 02:03:16 2002
+++ edited/arch/sparc64/vmlinux.lds.S Sun Jan 12 22:54:07 2003
@@ -1,4 +1,7 @@
/* ld script to make UltraLinux kernel */
+
+#include <asm-generic/vmlinux.lds>
+
OUTPUT_FORMAT("elf64-sparc", "elf64-sparc", "elf64-sparc")
OUTPUT_ARCH(sparc:v9a)
ENTRY(_start)
@@ -6,98 +9,63 @@
jiffies = jiffies_64;
SECTIONS
{
- swapper_pmd_dir = 0x0000000000402000;
- empty_pg_dir = 0x0000000000403000;
- . = 0x4000;
- .text 0x0000000000404000 :
- {
- *(.text)
- *(.gnu.warning)
- } =0
- _etext = .;
- PROVIDE (etext = .);
- .rodata : { *(.rodata) *(.rodata.*) }
- .rodata1 : { *(.rodata1) }
- .data :
- {
- *(.data)
- CONSTRUCTORS
- }
- .data1 : { *(.data1) }
- . = ALIGN(64);
- .data.cacheline_aligned : { *(.data.cacheline_aligned) }
- _edata = .;
- PROVIDE (edata = .);
- .fixup : { *(.fixup) }
-
- . = ALIGN(16);
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
-
- . = ALIGN(64);
- __start___ksymtab = .;
- __ksymtab : { *(__ksymtab) }
- __stop___ksymtab = .;
- __kstrtab : { *(.kstrtab) }
- __start___kallsyms = .; /* All kernel symbols */
- __kallsyms : { *(__kallsyms) }
- __stop___kallsyms = .;
- . = ALIGN(8192);
- __init_begin = .;
- .init.text : { *(.init.text) }
- .init.data : { *(.init.data) }
- . = ALIGN(16);
- __setup_start = .;
- .init.setup : { *(.init.setup) }
- __setup_end = .;
- __start___param = .;
- __param : { *(__param) }
- __stop___param = .;
- __initcall_start = .;
- .initcall.init : {
- *(.initcall1.init)
- *(.initcall2.init)
- *(.initcall3.init)
- *(.initcall4.init)
- *(.initcall5.init)
- *(.initcall6.init)
- *(.initcall7.init)
- }
- __initcall_end = .;
- . = ALIGN(8192);
- __initramfs_start = .;
- .init.ramfs : { *(.init.ramfs) }
- __initramfs_end = .;
- . = ALIGN(32);
- __per_cpu_start = .;
- .data.percpu : { *(.data.percpu) }
- __per_cpu_end = .;
- . = ALIGN(8192);
- __init_end = .;
- __bss_start = .;
- .sbss : { *(.sbss) *(.scommon) }
- .bss :
- {
- *(.dynbss)
- *(.bss)
- *(COMMON)
- }
- _end = . ;
- PROVIDE (end = .);
- /* Stabs debugging sections. */
- .stab 0 : { *(.stab) }
- .stabstr 0 : { *(.stabstr) }
- .stab.excl 0 : { *(.stab.excl) }
- .stab.exclstr 0 : { *(.stab.exclstr) }
- .stab.index 0 : { *(.stab.index) }
- .stab.indexstr 0 : { *(.stab.indexstr) }
- .comment 0 : { *(.comment) }
- .debug 0 : { *(.debug) }
- .debug_srcinfo 0 : { *(.debug_srcinfo) }
- .debug_aranges 0 : { *(.debug_aranges) }
- .debug_pubnames 0 : { *(.debug_pubnames) }
- .debug_sfnames 0 : { *(.debug_sfnames) }
- .line 0 : { *(.line) }
- /DISCARD/ : { *(.exit.text) *(.exit.data) *(.exitcall.exit) }
+ swapper_pmd_dir = 0x0000000000402000;
+ empty_pg_dir = 0x0000000000403000;
+
+ . = 0x4000;
+ .text 0x0000000000404000 : {
+ *(.text)
+ *(.gnu.warning)
+ } =0
+ _etext = .;
+ PROVIDE (etext = .);
+
+ RODATA
+ .rodata1 : { *(.rodata1) }
+
+ DATA_SECTION_START(.)
+ {
+ DATA_SECTION
+ }
+ .data1 : { *(.data1) }
+ DATA_CACHELINE_ALIGN(64)
+ DATA_SECTION_END
+
+ .fixup : { *(.fixup) }
+
+ EXCEPTIONTABLE(16)
+
+ KERNEL_SYMBOLS
+ /* The following is freed by kernel after init
+ * Alignment 8192
+ * init.setup alignment 16
+ * ramfs alignment 8192
+ * percpu alignment 32
+ **/
+ INIT_SECTION_CMD(8192, 16, 8192, 32)
+
+ __bss_start = .;
+ .sbss : {
+ *(.sbss)
+ *(.scommon)
+ }
+ .bss : {
+ *(.dynbss)
+ *(.bss)
+ *(COMMON)
+ }
+ _end = . ;
+ PROVIDE (end = .);
+
+ /* Stabs debugging sections. */
+ STABS_DEBUG
+
+ .debug 0 : { *(.debug) }
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+ .line 0 : { *(.line) }
+
+ DISCARD_SECTION_CMD
}


2003-01-12 23:01:00

by Jeff Garzik

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

I think it looks good, and since we're already pre-processing foo.S
files anyway...

2003-01-13 06:59:51

by Ingo Oeser

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

Hi,

On Sun, Jan 12, 2003 at 11:07:41PM +0100, Sam Ravnborg wrote:
> Recently we have seen seveal changes to arch/*/vmlinux-lds.S,
> mainly introduced by the module support but also other changes.
>
> This is first version, where I have converted i386, s390 and sparc64.
> The latter two is not tested, only to make sure it can be used by more
> than one platform.

Liker scripts are hard enough to read, so I would not like to see
more CPP magic here. Consolidation should stop, where the
readability stops.

These files are not too big, are they?

I'm willing to pay some minutes more of download time[1], if what I
get remains readable ;-)

Regards

Ingo Oeser

[1] 33.6K modem
--
Science is what we can tell a computer. Art is everything else. --- D.E.Knuth

2003-01-13 10:12:05

by Eric Dumazet

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files


> Recently we have seen seveal changes to arch/*/vmlinux-lds.S,
> mainly introduced by the module support but also other changes.
>
> This is first version, where I have converted i386, s390 and sparc64.
> The latter two is not tested, only to make sure it can be used by more
> than one platform.
>

...

> + TEXT_SECTION_CMD(0xC0000000 + 0x100000,, 0x9090, )


Nice job indeed.

Could you change in arch/i386/vmlinux-lds.S the 0xC0000000 by PAGE_OFFSET
(defined in include/asm-i386/page.h)

TEXT_SECTION_CMD(PAGE_OFFSET + 0x100000,, 0x9090, )

This way, one could change PAGE_OFFSET if he needs too, without having to
change vmlinux-lds.S accordingly

Thanks

2003-01-13 11:20:25

by Eric W. Biederman

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

Sam Ravnborg <[email protected]> writes:

> Recently we have seen seveal changes to arch/*/vmlinux-lds.S,
> mainly introduced by the module support but also other changes.
>
> This is first version, where I have converted i386, s390 and sparc64.
> The latter two is not tested, only to make sure it can be used by more
> than one platform.
>
> include/asm-generic/vmlinux.lds contains common definitions.
> inserted below + three diffs.
>
> i386/vmlinux.lds.S | 148 ++++++++++++++---------------------------------
> s390/vmlinux.lds.S | 138 +++++++++++++-------------------------------
> sparc64/vmlinux.lds.S | 156 +++++++++++++++++++-------------------------------
>
> 3 files changed, 149 insertions(+), 293 deletions(-)
>
> The architecture specific files became smaller.
> And adding new stuff is easier.
>
> If this the correct way of doing it - or do you have any better ways
> to do it?


You are changing the Language that vmlinux.lds.S is written in.
It appears to reduce readability by hiding information. I'm not
in favor of it.

Eric

2003-01-13 17:56:03

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

On Mon, Jan 13, 2003 at 12:36:32AM +0100, Ingo Oeser wrote:
> Hi,
>
> > This is first version, where I have converted i386, s390 and sparc64.
> > The latter two is not tested, only to make sure it can be used by more
> > than one platform.
>
> Liker scripts are hard enough to read, so I would not like to see
> more CPP magic here. Consolidation should stop, where the
> readability stops.

Hi Ingo & Eric.

The purpose was to define common stuff in a single place.
Ask Rusty Russell if it is fun to add the same section to > 50
.lds files.

Based on the feedback I will try to come up with a lighter proposal,
that does not hurt readability.
I still want the common stuff separated away.

And I will in the process try to add a bit more descriptive comments,
I agree the linker scripts are hard to read today. It would help if people
cared to spend a few more lines explaning the actual usage.
Having such explanation in a common place would make the chances for
an update of the comments bigger.

Sam

2003-01-13 17:59:58

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

On Mon, Jan 13, 2003 at 11:19:58AM +0100, dada1 wrote:
>
> > + TEXT_SECTION_CMD(0xC0000000 + 0x100000,, 0x9090, )
>
> Could you change in arch/i386/vmlinux-lds.S the 0xC0000000 by PAGE_OFFSET
> (defined in include/asm-i386/page.h)
>
> TEXT_SECTION_CMD(PAGE_OFFSET + 0x100000,, 0x9090, )

Good suggestion, I will do that.

Sam

2003-01-13 19:05:00

by Kai Germaschewski

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

On Mon, 13 Jan 2003, Sam Ravnborg wrote:

> The purpose was to define common stuff in a single place.
> Ask Rusty Russell if it is fun to add the same section to > 50
> .lds files.
>
> Based on the feedback I will try to come up with a lighter proposal,
> that does not hurt readability.
> I still want the common stuff separated away.

I second this, though I also agree that your first cut was hiding away
stuff more than necessary.

I would suggest an approach like the following, of course showing only a
first simple step. A series of steps like this should allow for a serious
reduction in size of arch/*/vmlinux.lds.S already, while being obviously
correct and allowing archs to do their own special thing if necessary (in
particular, IA64 seems to differ from all the other archs).

--Kai


--- /dev/null Thu Apr 11 09:25:15 2002
+++ include/asm-generic/vmlinux.lds.h Mon Jan 13 12:52:56 2003
@@ -0,0 +1,6 @@
+#define EXTABLE \
+ . = ALIGN(16); \
+ __start___ex_table = .; \
+ __ex_table : { *(__ex_table) } \
+ __stop___ex_table = .; \
+
===== arch/alpha/vmlinux.lds.S 1.14 vs edited =====
--- 1.14/arch/alpha/vmlinux.lds.S Sun Jan 12 19:12:21 2003
+++ edited/arch/alpha/vmlinux.lds.S Mon Jan 13 12:53:59 2003
@@ -1,4 +1,5 @@
#include <linux/config.h>
+#include <asm-generic/vmlinux.lds.h>

OUTPUT_FORMAT("elf64-alpha")
ENTRY(__start)
@@ -18,12 +19,7 @@
_etext = .;
} :kernel

- /* Exception table */
- __ex_table ALIGN(16) : {
- __start___ex_table = .;
- *(__ex_table)
- __stop___ex_table = .;
- }
+ EXTABLE

/* Kernel symbol table */
__ksymtab ALIGN(8) : {
===== arch/arm/vmlinux-armo.lds.in 1.11 vs edited =====
--- 1.11/arch/arm/vmlinux-armo.lds.in Sun Jan 12 19:12:21 2003
+++ edited/arch/arm/vmlinux-armo.lds.in Mon Jan 13 12:55:04 2003
@@ -2,6 +2,9 @@
* taken from the i386 version by Russell King
* Written by Martin Mares <[email protected]>
*/
+
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_ARCH(arm)
ENTRY(stext)
jiffies = jiffies_64;
@@ -65,12 +68,7 @@

.kstrtab : { *(.kstrtab) }

- . = ALIGN(16);
- __ex_table : { /* Exception table */
- __start___ex_table = .;
- *(__ex_table)
- __stop___ex_table = .;
- }
+ EXTABLE

__ksymtab : { /* Kernel symbol table */
__start___ksymtab = .;
===== arch/arm/vmlinux-armv.lds.in 1.18 vs edited =====
--- 1.18/arch/arm/vmlinux-armv.lds.in Sun Jan 12 22:21:35 2003
+++ edited/arch/arm/vmlinux-armv.lds.in Mon Jan 13 12:55:31 2003
@@ -2,6 +2,9 @@
* taken from the i386 version by Russell King
* Written by Martin Mares <[email protected]>
*/
+
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_ARCH(arm)
ENTRY(stext)
jiffies = jiffies_64;
@@ -68,12 +71,7 @@

.kstrtab : { *(.kstrtab) }

- . = ALIGN(16);
- __ex_table : { /* Exception table */
- __start___ex_table = .;
- *(__ex_table)
- __stop___ex_table = .;
- }
+ EXTABLE

__gpl_ksymtab : { /* GPL Kernel symbol table */
__start___gpl_ksymtab = .;
===== arch/cris/vmlinux.lds.S 1.13 vs edited =====
--- 1.13/arch/cris/vmlinux.lds.S Sun Jan 12 19:12:21 2003
+++ edited/arch/cris/vmlinux.lds.S Mon Jan 13 12:56:26 2003
@@ -9,7 +9,8 @@
*/

#include <linux/config.h>
-
+#include <asm-generic/vmlinux.lds.h>
+
jiffies = jiffies_64;
SECTIONS
{
@@ -34,10 +35,7 @@
.rodata : { *(.rodata) *(.rodata.__*) }
.kstrtab : { *(.kstrtab) }

- . = ALIGN(4); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

__start___ksymtab = .; /* Kernel symbol table */
__ksymtab : { *(__ksymtab) }
===== arch/i386/vmlinux.lds.S 1.22 vs edited =====
--- 1.22/arch/i386/vmlinux.lds.S Sun Jan 12 19:12:21 2003
+++ edited/arch/i386/vmlinux.lds.S Mon Jan 13 12:54:19 2003
@@ -1,6 +1,9 @@
/* ld script to make i386 Linux kernel
* Written by Martin Mares <[email protected]>;
*/
+
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_start)
@@ -21,10 +24,7 @@
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }

- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

. = ALIGN(64);
__start___ksymtab = .; /* Kernel symbol table */
===== arch/m68k/vmlinux-std.lds 1.12 vs edited =====
--- 1.12/arch/m68k/vmlinux-std.lds Sun Jan 12 19:12:21 2003
+++ edited/arch/m68k/vmlinux-std.lds Mon Jan 13 12:59:13 2003
@@ -1,4 +1,7 @@
/* ld script to make m68k Linux kernel */
+
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_FORMAT("elf32-m68k", "elf32-m68k", "elf32-m68k")
OUTPUT_ARCH(m68k)
ENTRY(_start)
@@ -15,10 +18,7 @@
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }

- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

__start___ksymtab = .; /* Kernel symbol table */
__ksymtab : { *(__ksymtab) }
===== arch/m68k/vmlinux-sun3.lds 1.9 vs edited =====
--- 1.9/arch/m68k/vmlinux-sun3.lds Sun Jan 12 19:12:21 2003
+++ edited/arch/m68k/vmlinux-sun3.lds Mon Jan 13 12:58:44 2003
@@ -1,4 +1,7 @@
/* ld script to make m68k Linux kernel */
+
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_FORMAT("elf32-m68k", "elf32-m68k", "elf32-m68k")
OUTPUT_ARCH(m68k)
ENTRY(_start)
@@ -23,10 +26,7 @@
*(.rodata.*)
*(.data)
CONSTRUCTORS
- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- *(__ex_table)
- __stop___ex_table = .;
+ EXTABLE
__start___ksymtab = .; /* Kernel symbol table */
*(__ksymtab)
__stop___ksymtab = .;
===== arch/mips/vmlinux.lds.S 1.5 vs edited =====
--- 1.5/arch/mips/vmlinux.lds.S Sun Jan 12 19:12:22 2003
+++ edited/arch/mips/vmlinux.lds.S Mon Jan 13 13:08:00 2003
@@ -1,3 +1,5 @@
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_ARCH(mips)
ENTRY(kernel_entry)
SECTIONS
@@ -16,10 +18,7 @@
} =0
.kstrtab : { *(.kstrtab) }

- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

__start___dbe_table = .; /* Exception table for data bus errors */
__dbe_table : { *(__dbe_table) }
===== arch/mips64/vmlinux.lds.S 1.4 vs edited =====
--- 1.4/arch/mips64/vmlinux.lds.S Fri Aug 16 22:08:39 2002
+++ edited/arch/mips64/vmlinux.lds.S Mon Jan 13 13:07:57 2003
@@ -1,3 +1,5 @@
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_ARCH(mips)
ENTRY(kernel_entry)
SECTIONS
@@ -15,10 +17,7 @@
} =0
.kstrtab : { *(.kstrtab) }

- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

__start___dbe_table = .; /* Exception table for data bus errors */
__dbe_table : { *(__dbe_table) }
===== arch/parisc/vmlinux.lds.S 1.8 vs edited =====
--- 1.8/arch/parisc/vmlinux.lds.S Sun Jan 12 19:12:22 2003
+++ edited/arch/parisc/vmlinux.lds.S Mon Jan 13 13:00:53 2003
@@ -1,5 +1,6 @@
#include <linux/config.h>
-
+#include <asm-generic/vmlinux.lds.h>
+
/* ld script to make hppa Linux kernel */
#ifndef CONFIG_PARISC64
OUTPUT_FORMAT("elf32-hppa-linux")
@@ -40,11 +41,8 @@
*(.data)
}

- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
-
+ EXTABLE
+
__start___ksymtab = .; /* Kernel symbol table */
__ksymtab : { *(__ksymtab) }
__stop___ksymtab = .;
===== arch/ppc/vmlinux.lds.S 1.15 vs edited =====
--- 1.15/arch/ppc/vmlinux.lds.S Sun Jan 12 19:12:22 2003
+++ edited/arch/ppc/vmlinux.lds.S Mon Jan 13 13:01:40 2003
@@ -1,3 +1,5 @@
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_ARCH(powerpc)
SEARCH_DIR(/lib); SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/local/lib); SEARCH_DIR(/usr/local/powerpc-any-elf/lib);
/* Do we need any of these for elf?
@@ -53,9 +55,7 @@

.fixup : { *(.fixup) }

- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

__start___ksymtab = .; /* Kernel symbol table */
__ksymtab : { *(__ksymtab) }
===== arch/ppc64/vmlinux.lds.S 1.11 vs edited =====
--- 1.11/arch/ppc64/vmlinux.lds.S Sun Jan 12 19:12:22 2003
+++ edited/arch/ppc64/vmlinux.lds.S Mon Jan 13 13:02:06 2003
@@ -1,3 +1,5 @@
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_ARCH(powerpc:common64)
/* Do we need any of these for elf?
__DYNAMIC = 0; */
@@ -61,9 +63,7 @@
_edata = .;
PROVIDE (edata = .);

- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

__start___ksymtab = .; /* Kernel symbol table */
__ksymtab : { *(__ksymtab) }
===== arch/s390/vmlinux.lds.S 1.6 vs edited =====
--- 1.6/arch/s390/vmlinux.lds.S Sun Jan 12 19:12:22 2003
+++ edited/arch/s390/vmlinux.lds.S Mon Jan 13 13:03:08 2003
@@ -1,6 +1,9 @@
/* ld script to make s390 Linux kernel
* Written by Martin Schwidefsky ([email protected])
*/
+
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_FORMAT("elf32-s390", "elf32-s390", "elf32-s390")
OUTPUT_ARCH(s390)
ENTRY(_start)
@@ -20,10 +23,7 @@
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }

- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

. = ALIGN(64);
__start___ksymtab = .; /* Kernel symbol table */
===== arch/s390x/vmlinux.lds.S 1.6 vs edited =====
--- 1.6/arch/s390x/vmlinux.lds.S Sun Jan 12 19:12:22 2003
+++ edited/arch/s390x/vmlinux.lds.S Mon Jan 13 13:03:27 2003
@@ -1,6 +1,9 @@
/*
* Written by Martin Schwidefsky ([email protected])
*/
+
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_FORMAT("elf64-s390", "elf64-s390", "elf64-s390")
OUTPUT_ARCH(s390:64-bit)
ENTRY(_start)
@@ -20,10 +23,7 @@
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }

- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

. = ALIGN(64);
__start___ksymtab = .; /* Kernel symbol table */
===== arch/sh/vmlinux.lds.S 1.7 vs edited =====
--- 1.7/arch/sh/vmlinux.lds.S Sun Jan 12 19:12:22 2003
+++ edited/arch/sh/vmlinux.lds.S Mon Jan 13 13:03:55 2003
@@ -3,6 +3,8 @@
* Written by Niibe Yutaka
*/
#include <linux/config.h>
+#include <asm-generic/vmlinux.lds.h>
+
#ifdef CONFIG_CPU_LITTLE_ENDIAN
OUTPUT_FORMAT("elf32-sh-linux", "elf32-sh-linux", "elf32-sh-linux")
jiffies = jiffies_64;
@@ -28,10 +30,7 @@
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }

- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

__start___ksymtab = .; /* Kernel symbol table */
__ksymtab : { *(__ksymtab) }
===== arch/sparc/vmlinux.lds.S 1.13 vs edited =====
--- 1.13/arch/sparc/vmlinux.lds.S Sun Jan 12 19:12:22 2003
+++ edited/arch/sparc/vmlinux.lds.S Mon Jan 13 13:04:28 2003
@@ -1,4 +1,7 @@
/* ld script to make SparcLinux kernel */
+
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_FORMAT("elf32-sparc", "elf32-sparc", "elf32-sparc")
OUTPUT_ARCH(sparc)
ENTRY(_start)
@@ -26,9 +29,8 @@
__start___fixup = .;
.fixup : { *(.fixup) }
__stop___fixup = .;
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+
+ EXTABLE

. = ALIGN(64);
__start___ksymtab = .;
===== arch/sparc64/vmlinux.lds.S 1.14 vs edited =====
--- 1.14/arch/sparc64/vmlinux.lds.S Sun Jan 12 19:12:22 2003
+++ edited/arch/sparc64/vmlinux.lds.S Mon Jan 13 13:05:01 2003
@@ -1,4 +1,7 @@
/* ld script to make UltraLinux kernel */
+
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_FORMAT("elf64-sparc", "elf64-sparc", "elf64-sparc")
OUTPUT_ARCH(sparc:v9a)
ENTRY(_start)
@@ -30,10 +33,7 @@
PROVIDE (edata = .);
.fixup : { *(.fixup) }

- . = ALIGN(16);
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

. = ALIGN(64);
__start___ksymtab = .;
===== arch/v850/vmlinux.lds.S 1.4 vs edited =====
--- 1.4/arch/v850/vmlinux.lds.S Thu Jan 9 00:27:41 2003
+++ edited/arch/v850/vmlinux.lds.S Mon Jan 13 13:06:04 2003
@@ -12,6 +12,7 @@
*/

#include <linux/config.h>
+#include <asm-generic/vmlinux.lds.h>


/* The following macros contain the usual definitions for various data areas.
@@ -44,10 +45,7 @@
. = ALIGN (4) ; \
*(.call_table_data) \
*(.call_table_text) \
- . = ALIGN (16) ; /* Exception table. */ \
- ___start___ex_table = . ; \
- *(__ex_table) \
- ___stop___ex_table = . ; \
+ EXTABLE \
___start___ksymtab = . ;/* Kernel symbol table. */ \
*(__ksymtab) \
___stop___ksymtab = . ; \
===== arch/x86_64/vmlinux.lds.S 1.9 vs edited =====
--- 1.9/arch/x86_64/vmlinux.lds.S Sun Jan 12 19:12:22 2003
+++ edited/arch/x86_64/vmlinux.lds.S Mon Jan 13 12:58:00 2003
@@ -1,6 +1,9 @@
/* ld script to make x86-64 Linux kernel
* Written by Martin Mares <[email protected]>;
*/
+
+#include <asm-generic/vmlinux.lds.h>
+
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
ENTRY(_start)
@@ -21,10 +24,7 @@
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }

- . = ALIGN(16); /* Exception table */
- __start___ex_table = .;
- __ex_table : { *(__ex_table) }
- __stop___ex_table = .;
+ EXTABLE

. = ALIGN(64);
__start___ksymtab = .; /* Kernel symbol table */

2003-01-13 19:06:09

by Eric W. Biederman

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

Sam Ravnborg <[email protected]> writes:

> On Mon, Jan 13, 2003 at 12:36:32AM +0100, Ingo Oeser wrote:
> > Hi,
> >
> > > This is first version, where I have converted i386, s390 and sparc64.
> > > The latter two is not tested, only to make sure it can be used by more
> > > than one platform.
> >
> > Liker scripts are hard enough to read, so I would not like to see
> > more CPP magic here. Consolidation should stop, where the
> > readability stops.
>
> Hi Ingo & Eric.
>
> The purpose was to define common stuff in a single place.
> Ask Rusty Russell if it is fun to add the same section to > 50
> .lds files.
>
> Based on the feedback I will try to come up with a lighter proposal,
> that does not hurt readability.
> I still want the common stuff separated away.
>
> And I will in the process try to add a bit more descriptive comments,
> I agree the linker scripts are hard to read today. It would help if people
> cared to spend a few more lines explaning the actual usage.
> Having such explanation in a common place would make the chances for
> an update of the comments bigger.

I consider it a bigger bug that CodingStyle is not followed. If there
was an appropriate amount of whitespace linker scripts would be easier
to read.

Beyond that linker scripts native support include directives. And included
files can have additional SECTIONS attributes. In particular:

SECTIONS {
.section1 {
*(.section1)
}
}
SECTIONS {
.section2 {
*(.section2)
}
}

is legal.

So I would recommend having an arch specific linker script that included
the architecture independent parts. And have each part have it's own
SECTIONS attribute tag.

Something like:

---- arch/i386/vmlinux.lds.S ----
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_start)
vmlinux.lds.S
jiffies = jiffies_64;
SECTIONS
{
. = 0xC0000000 + 0x100000;
/* read-only */
_text = .; /* Text and read-only data */
.text : {
*(.text)
*(.fixup)
*(.gnu.warning)
} = 0x9090

_etext = .; /* End of text section */
.rodata : { *(.rodata) *(.rodata.*) }
.kstrtab : { *(.kstrtab) }
}
INCLUDE ../../kernel/exceptions.lds
INCLUDE ../../init/initramfs.lds

---- kernel/exceptions.lds ----
SECTIONS {
. = ALIGN(16); /* Exception table */
__start___ex_table = .;
__ex_table : { *(__ex_table) }
__stop___ex_table = .;
}

---- init/initramfs.lds ----
SECTIONS {
. = ALIGN(4096);
__initramfs_start = .;
.init.ramfs : { *(.init.ramfs) }
__initramfs_end = .;
}

Eric

2003-01-13 19:29:09

by David Mosberger

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files


Kai> I would suggest an approach like the following, of course
Kai> showing only a first simple step. A series of steps like this
Kai> should allow for a serious reduction in size of
Kai> arch/*/vmlinux.lds.S already, while being obviously correct and
Kai> allowing archs to do their own special thing if necessary (in
Kai> particular, IA64 seems to differ from all the other archs).

The only real difference for the ia64 vmlinux.lds.S is that it
generates correct physical addressess, so that the boot loader doesn't
have to know anything about the virtual layout of the kernel.
Something that might be useful for other arches as well...

--david

2003-01-13 20:21:50

by Kai Germaschewski

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

On Mon, 13 Jan 2003, David Mosberger wrote:

>
> Kai> I would suggest an approach like the following, of course
> Kai> showing only a first simple step. A series of steps like this
> Kai> should allow for a serious reduction in size of
> Kai> arch/*/vmlinux.lds.S already, while being obviously correct and
> Kai> allowing archs to do their own special thing if necessary (in
> Kai> particular, IA64 seems to differ from all the other archs).
>
> The only real difference for the ia64 vmlinux.lds.S is that it
> generates correct physical addressess, so that the boot loader doesn't
> have to know anything about the virtual layout of the kernel.
> Something that might be useful for other arches as well...

Hmmh, you mean that the boot loader can just load the vmlinux sections to
the LMAs, right? Yes, I can see that this makes sense - Most archs don't
actually load the ELF file, so they don't even have the LMA information,
but for them it shouldn't hurt, either.

So it should be possible to have the correct LMA for all archs w/o
breakage. Might be worth a try.

--Kai


2003-01-13 21:08:37

by David Mosberger

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

>>>>> On Mon, 13 Jan 2003 14:30:33 -0600 (CST), Kai Germaschewski <[email protected]> said:

Kai> Hmmh, you mean that the boot loader can just load the vmlinux
Kai> sections to the LMAs, right?

Yup.

--david

2003-01-13 22:03:10

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

On Mon, Jan 13, 2003 at 12:10:11PM -0700, Eric W. Biederman wrote:
>
> I consider it a bigger bug that CodingStyle is not followed. If there
> was an appropriate amount of whitespace linker scripts would be easier
> to read.
I noticed that as well, arm being one of the good guys here.
At least I tried to be consistent with coding style.

> Beyond that linker scripts native support include directives.
But they do not know of standard include paths, and you will see
linker scripts pulling in .h files as well. See ia64 as of today
as a good example.

> And included
> files can have additional SECTIONS attributes. In particular:
>
> SECTIONS {
> .section1 {
> *(.section1)
> }
> }
> SECTIONS {
> .section2 {
> *(.section2)
> }
> }
>
> is legal.
>
> So I would recommend having an arch specific linker script that included
> the architecture independent parts. And have each part have it's own
> SECTIONS attribute tag.
>
> Something like:
>
> ---- arch/i386/vmlinux.lds.S ----
> OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
> OUTPUT_ARCH(i386)
> ENTRY(_start)
> vmlinux.lds.S
> jiffies = jiffies_64;
> SECTIONS
> {
> . = 0xC0000000 + 0x100000;
> /* read-only */
> _text = .; /* Text and read-only data */
> .text : {
> *(.text)
> *(.fixup)
> *(.gnu.warning)
> } = 0x9090
>
> _etext = .; /* End of text section */
> .rodata : { *(.rodata) *(.rodata.*) }
> .kstrtab : { *(.kstrtab) }
> }
> INCLUDE ../../kernel/exceptions.lds
> INCLUDE ../../init/initramfs.lds
>
> ---- kernel/exceptions.lds ----
> SECTIONS {
> . = ALIGN(16); /* Exception table */
> __start___ex_table = .;
> __ex_table : { *(__ex_table) }
> __stop___ex_table = .;
> }
>
> ---- init/initramfs.lds ----
> SECTIONS {
> . = ALIGN(4096);
> __initramfs_start = .;
> .init.ramfs : { *(.init.ramfs) }
> __initramfs_end = .;
> }
Different architectures have different alingments for ramfs for example.
I do not know why, but wanted to support that.

Good point with more sections btw.

Sam

2003-01-13 22:11:06

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

On Mon, Jan 13, 2003 at 01:13:28PM -0600, Kai Germaschewski wrote:
> On Mon, 13 Jan 2003, Sam Ravnborg wrote:
>
> > The purpose was to define common stuff in a single place.
> > Ask Rusty Russell if it is fun to add the same section to > 50
> > .lds files.
> >
> > Based on the feedback I will try to come up with a lighter proposal,
> > that does not hurt readability.
> > I still want the common stuff separated away.
>
> I second this, though I also agree that your first cut was hiding away
> stuff more than necessary.
What I posted was to get feedback, not what I had in mind as first step.
I agree to take small steps - but wanted to find out the direction.

> I would suggest an approach like the following, of course showing only a
> first simple step.

But you do not deal with different alingment of the sections.
I have not yet fully understood all the requirements, but wanted to
keep the original ALIGN settings.
In the patch you posted some architectures use ALIGN(4) {cris},
other nothing, but most of them ALIGN(16).
Is it OK to force them all to ALIGN(16) then?

> A series of steps like this should allow for a serious
> reduction in size of arch/*/vmlinux.lds.S already, while being obviously
> correct and allowing archs to do their own special thing if necessary (in
> particular, IA64 seems to differ from all the other archs).

My main objective was that adding new stuff, like __gpl_ksyms could
be done in one place only.
Or .gnu.linkonce.vermagic, or whatever will be used for that.

Thats why I collected so much in INIT_SECTION_CMD(...).


I will come back with something during the week - as time permits.

Sam

2003-01-13 22:56:53

by Kai Germaschewski

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

On Mon, 13 Jan 2003, Sam Ravnborg wrote:

> > I would suggest an approach like the following, of course showing only a
> > first simple step.
>
> But you do not deal with different alingment of the sections.
> I have not yet fully understood all the requirements, but wanted to
> keep the original ALIGN settings.
> In the patch you posted some architectures use ALIGN(4) {cris},
> other nothing, but most of them ALIGN(16).
> Is it OK to force them all to ALIGN(16) then?

Well, forcing them to a larger alignment surely won't break anything,
except for wasting 12 bytes on cris. But in general, you're right, not of
all of this is trivial to share due to these small differences. In the
cases where it's necessary, we could do something like

(for CRIS)
#define EXTABLE_ALIGN 4

(in generic code)
#ifndef EXTABLE_ALIGN
#define EXTABLE_ALIGN 16
#endif

Of course, one could also do EXTABLE(4) and EXTABLE(16), respectively, but
I think it's less obvious to the occasional reader that these magic
numbers are about alignment.

> > A series of steps like this should allow for a serious
> > reduction in size of arch/*/vmlinux.lds.S already, while being obviously
> > correct and allowing archs to do their own special thing if necessary (in
> > particular, IA64 seems to differ from all the other archs).
>
> My main objective was that adding new stuff, like __gpl_ksyms could
> be done in one place only.
> Or .gnu.linkonce.vermagic, or whatever will be used for that.

Yes, and that's why I think that separating out and sharing these bits is
a very good idea. Actually, separating out the ksymtab etc code should be
really easy, as opposed to other stuff where there's more substantial
differences between the archs.

It'll be a rather long and tedious process to do this work, but I think
it's worth it.

--Kai


2003-01-14 01:47:17

by Eric W. Biederman

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

David Mosberger <[email protected]> writes:

> Kai> I would suggest an approach like the following, of course
> Kai> showing only a first simple step. A series of steps like this
> Kai> should allow for a serious reduction in size of
> Kai> arch/*/vmlinux.lds.S already, while being obviously correct and
> Kai> allowing archs to do their own special thing if necessary (in
> Kai> particular, IA64 seems to differ from all the other archs).
>
> The only real difference for the ia64 vmlinux.lds.S is that it
> generates correct physical addressess, so that the boot loader doesn't
> have to know anything about the virtual layout of the kernel.
> Something that might be useful for other arches as well...

Thank you. I appreciate it.

Having the physical addresses there makes writing a sane bootloader
simpler.

Alpha practically does this except there is a fixed virtual offset added to
everything.

In general anything that gives us correct physical addresses makes
like much simpler on the bootloader..


Eric

2003-01-14 06:20:21

by Mikael Starvik

[permalink] [raw]
Subject: RE: [RFC] Consolidate vmlinux.lds.S files

I see no problem in wasting 12 more bytes on CRIS. We have an
ALIGN(8192) later in the file so the extra 12 bytes kind of
disappears in the noise.

So, you don't have to make any special hacks for us. But
maybe it is still a good idea to keep it controllable
per arch? I don't know, it's up to you.

/Mikael (CRIS maintainer)


-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Kai
Germaschewski
Sent: Tuesday, January 14, 2003 12:06 AM
To: Sam Ravnborg
Cc: Ingo Oeser; [email protected]; [email protected]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files


On Mon, 13 Jan 2003, Sam Ravnborg wrote:

> > I would suggest an approach like the following, of course showing only a
> > first simple step.
>
> But you do not deal with different alingment of the sections.
> I have not yet fully understood all the requirements, but wanted to
> keep the original ALIGN settings.
> In the patch you posted some architectures use ALIGN(4) {cris},
> other nothing, but most of them ALIGN(16).
> Is it OK to force them all to ALIGN(16) then?

Well, forcing them to a larger alignment surely won't break anything,
except for wasting 12 bytes on cris. But in general, you're right, not of
all of this is trivial to share due to these small differences. In the
cases where it's necessary, we could do something like

(for CRIS)
#define EXTABLE_ALIGN 4

(in generic code)
#ifndef EXTABLE_ALIGN
#define EXTABLE_ALIGN 16
#endif

Of course, one could also do EXTABLE(4) and EXTABLE(16), respectively, but
I think it's less obvious to the occasional reader that these magic
numbers are about alignment.

> > A series of steps like this should allow for a serious
> > reduction in size of arch/*/vmlinux.lds.S already, while being obviously
> > correct and allowing archs to do their own special thing if necessary (in
> > particular, IA64 seems to differ from all the other archs).
>
> My main objective was that adding new stuff, like __gpl_ksyms could
> be done in one place only.
> Or .gnu.linkonce.vermagic, or whatever will be used for that.

Yes, and that's why I think that separating out and sharing these bits is
a very good idea. Actually, separating out the ksymtab etc code should be
really easy, as opposed to other stuff where there's more substantial
differences between the archs.

It'll be a rather long and tedious process to do this work, but I think
it's worth it.

--Kai


2003-01-15 22:33:24

by Kai Germaschewski

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

On Mon, 13 Jan 2003, David Mosberger wrote:

>
> Kai> I would suggest an approach like the following, of course
> Kai> showing only a first simple step. A series of steps like this
> Kai> should allow for a serious reduction in size of
> Kai> arch/*/vmlinux.lds.S already, while being obviously correct and
> Kai> allowing archs to do their own special thing if necessary (in
> Kai> particular, IA64 seems to differ from all the other archs).
>
> The only real difference for the ia64 vmlinux.lds.S is that it
> generates correct physical addressess, so that the boot loader doesn't
> have to know anything about the virtual layout of the kernel.
> Something that might be useful for other arches as well...

I just found another way of changing the LMA in vmlinux, which is far
less intrusive than what IA-64 uses. Do you see any reason why something
like the following patch (which changes the LMA for i386) wouldn't work
for IA-64?

--Kai


===== arch/i386/vmlinux.lds.S 1.24 vs edited =====
--- 1.24/arch/i386/vmlinux.lds.S Wed Jan 15 11:48:42 2003
+++ edited/arch/i386/vmlinux.lds.S Wed Jan 15 16:36:04 2003
@@ -7,6 +7,7 @@
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_start)
+PHDRS { kernel PT_LOAD AT(0x100000) ; }
jiffies = jiffies_64;
SECTIONS
{
@@ -17,7 +18,7 @@
*(.text)
*(.fixup)
*(.gnu.warning)
- } = 0x9090
+ } :kernel = 0x9090

_etext = .; /* End of text section */


2003-01-16 00:13:29

by Eric W. Biederman

[permalink] [raw]
Subject: Re: [RFC] Consolidate vmlinux.lds.S files

Kai Germaschewski <[email protected]> writes:

> On Mon, 13 Jan 2003, David Mosberger wrote:
>
> >
> > Kai> I would suggest an approach like the following, of course
> > Kai> showing only a first simple step. A series of steps like this
> > Kai> should allow for a serious reduction in size of
> > Kai> arch/*/vmlinux.lds.S already, while being obviously correct and
> > Kai> allowing archs to do their own special thing if necessary (in
> > Kai> particular, IA64 seems to differ from all the other archs).
> >
> > The only real difference for the ia64 vmlinux.lds.S is that it
> > generates correct physical addressess, so that the boot loader doesn't
> > have to know anything about the virtual layout of the kernel.
> > Something that might be useful for other arches as well...
>
> I just found another way of changing the LMA in vmlinux, which is far
> less intrusive than what IA-64 uses. Do you see any reason why something
> like the following patch (which changes the LMA for i386) wouldn't work
> for IA-64?

Be very careful. There are some versions of ld (I forget which)
that do not behave correctly when PHDRS are used.

Eric