2009-09-16 16:47:05

by Tim Abbott

[permalink] [raw]
Subject: [PATCH v2] Linker script cleanup for sparc

This is an updated version of the patch series I sent in late July
cleaning up the sparc architecture's linker scripts. The only change is
that it is rebased on top of Linus's current master.

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

-Tim Abbott

Geoffrey Thomas (1):
sparc: Clean up linker script using new linker script macros.

arch/sparc/kernel/vmlinux.lds.S | 75 ++++-----------------------------------
1 files changed, 7 insertions(+), 68 deletions(-)


2009-09-16 16:46:55

by Tim Abbott

[permalink] [raw]
Subject: [PATCH v2] sparc: Clean up linker script using new linker script macros.

From: Geoffrey Thomas <[email protected]>

Signed-off-by: Geoffrey Thomas <[email protected]>
Signed-off-by: Tim Abbott <[email protected]>
Cc: Sam Ravnborg <[email protected]>
Cc: David S. Miller <[email protected]>
---
arch/sparc/kernel/vmlinux.lds.S | 75 ++++-----------------------------------
1 files changed, 7 insertions(+), 68 deletions(-)

diff --git a/arch/sparc/kernel/vmlinux.lds.S b/arch/sparc/kernel/vmlinux.lds.S
index 866390f..4e59925 100644
--- a/arch/sparc/kernel/vmlinux.lds.S
+++ b/arch/sparc/kernel/vmlinux.lds.S
@@ -51,70 +51,27 @@ SECTIONS
_etext = .;

RO_DATA(PAGE_SIZE)
- .data : {
- DATA_DATA
- CONSTRUCTORS
- }
.data1 : {
*(.data1)
}
- . = ALIGN(SMP_CACHE_BYTES);
- .data.cacheline_aligned : {
- *(.data.cacheline_aligned)
- }
- . = ALIGN(SMP_CACHE_BYTES);
- .data.read_mostly : {
- *(.data.read_mostly)
- }
+ RW_DATA_SECTION(SMP_CACHE_BYTES, 0, THREAD_SIZE)
+
/* End of data section */
_edata = .;

- /* init_task */
- . = ALIGN(THREAD_SIZE);
- .data.init_task : {
- *(.data.init_task)
- }
.fixup : {
__start___fixup = .;
*(.fixup)
__stop___fixup = .;
}
- . = ALIGN(16);
- __ex_table : {
- __start___ex_table = .;
- *(__ex_table)
- __stop___ex_table = .;
- }
+ EXCEPTION_TABLE(16)
NOTES

. = ALIGN(PAGE_SIZE);
- .init.text : {
- __init_begin = .;
- _sinittext = .;
- INIT_TEXT
- _einittext = .;
- }
+ __init_begin = ALIGN(PAGE_SIZE);
+ INIT_TEXT_SECTION(PAGE_SIZE)
__init_text_end = .;
- .init.data : {
- INIT_DATA
- }
- . = ALIGN(16);
- .init.setup : {
- __setup_start = .;
- *(.init.setup)
- __setup_end = .;
- }
- .initcall.init : {
- __initcall_start = .;
- INITCALLS
- __initcall_end = .;
- }
- .con_initcall.init : {
- __con_initcall_start = .;
- *(.con_initcall.init)
- __con_initcall_end = .;
- }
- SECURITY_INIT
+ INIT_DATA_SECTION(16)

. = ALIGN(4);
.tsb_ldquad_phys_patch : {
@@ -146,29 +103,11 @@ SECTIONS
__sun4v_2insn_patch_end = .;
}

-#ifdef CONFIG_BLK_DEV_INITRD
- . = ALIGN(PAGE_SIZE);
- .init.ramfs : {
- __initramfs_start = .;
- *(.init.ramfs)
- __initramfs_end = .;
- }
-#endif
-
PERCPU(PAGE_SIZE)

. = ALIGN(PAGE_SIZE);
__init_end = .;
- __bss_start = .;
- .sbss : {
- *(.sbss)
- *(.scommon)
- }
- .bss : {
- *(.dynbss)
- *(.bss)
- *(COMMON)
- }
+ BSS_SECTION(0, 0, 0)
_end = . ;

STABS_DEBUG
--
1.6.3.3

2009-09-16 17:19:10

by David Miller

[permalink] [raw]
Subject: Re: [PATCH v2] sparc: Clean up linker script using new linker script macros.

From: Tim Abbott <[email protected]>
Date: Wed, 16 Sep 2009 12:46:32 -0400

> @@ -51,70 +51,27 @@ SECTIONS
> _etext = .;
>
> RO_DATA(PAGE_SIZE)
> - .data : {
> - DATA_DATA
> - CONSTRUCTORS
> - }
> .data1 : {
> *(.data1)
> }
> - . = ALIGN(SMP_CACHE_BYTES);
> - .data.cacheline_aligned : {
> - *(.data.cacheline_aligned)
> - }
> - . = ALIGN(SMP_CACHE_BYTES);
> - .data.read_mostly : {
> - *(.data.read_mostly)
> - }
> + RW_DATA_SECTION(SMP_CACHE_BYTES, 0, THREAD_SIZE)
> +

Can you do this cleanup without moving the relative locations of .data
and .data1 sections?

2009-09-16 17:27:56

by Tim Abbott

[permalink] [raw]
Subject: Re: [PATCH v2] sparc: Clean up linker script using new linker script macros.

On Wed, 16 Sep 2009, David Miller wrote:

> Can you do this cleanup without moving the relative locations of .data
> and .data1 sections?

Yes, if you just swap RW_DATA_SECTION and .data1 so it looks like

RW_DATA_SECTION(SMP_CACHE_BYTES, 0, THREAD_SIZE)
.data1 : {
*(.data1)
}

instead, that would preserve their relative locations.

Currently, switching to RW_DATA_SECTION would still result in a change in
their relative position that .data.page_aligned and .data.nosave would be
between .data and .data1 (not sure if that is relevant on sparc). (this
will change when <http://lkml.org/lkml/2009/9/16/396> is merged).

-Tim Abbott

2009-09-16 17:30:08

by David Miller

[permalink] [raw]
Subject: Re: [PATCH v2] sparc: Clean up linker script using new linker script macros.

From: Tim Abbott <[email protected]>
Date: Wed, 16 Sep 2009 13:27:43 -0400 (EDT)

> On Wed, 16 Sep 2009, David Miller wrote:
>
>> Can you do this cleanup without moving the relative locations of .data
>> and .data1 sections?
>
> Yes, if you just swap RW_DATA_SECTION and .data1 so it looks like
>
> RW_DATA_SECTION(SMP_CACHE_BYTES, 0, THREAD_SIZE)
> .data1 : {
> *(.data1)
> }
>
> instead, that would preserve their relative locations.
>
> Currently, switching to RW_DATA_SECTION would still result in a change in
> their relative position that .data.page_aligned and .data.nosave would be
> between .data and .data1 (not sure if that is relevant on sparc). (this
> will change when <http://lkml.org/lkml/2009/9/16/396> is merged).

I don't know which, if any, are relevant or could cause problems.

It's hard for me to ACK this because it's not a straight nop
transformation, which we could at least presume would function
properly if the macros were implemented correctly.

2009-09-16 18:05:49

by Tim Abbott

[permalink] [raw]
Subject: Re: [PATCH v2] sparc: Clean up linker script using new linker script macros.

On Wed, 16 Sep 2009, David Miller wrote:

> From: Tim Abbott <[email protected]>
> Date: Wed, 16 Sep 2009 13:27:43 -0400 (EDT)
>
> > On Wed, 16 Sep 2009, David Miller wrote:
> >
> >> Can you do this cleanup without moving the relative locations of .data
> >> and .data1 sections?
> >
> > Yes, if you just swap RW_DATA_SECTION and .data1 so it looks like
> >
> > RW_DATA_SECTION(SMP_CACHE_BYTES, 0, THREAD_SIZE)
> > .data1 : {
> > *(.data1)
> > }
> >
> > instead, that would preserve their relative locations.
> >
> > Currently, switching to RW_DATA_SECTION would still result in a change in
> > their relative position that .data.page_aligned and .data.nosave would be
> > between .data and .data1 (not sure if that is relevant on sparc). (this
> > will change when <http://lkml.org/lkml/2009/9/16/396> is merged).
>
> I don't know which, if any, are relevant or could cause problems.

The kind of problem I've seen on other architectures is if there are
short-range (e.g. 2-byte) relative relocations between two sections, and
you insert a new section between them, they end up too far apart and the
kernel fails to link. I don't know whether the sparc architecture has
that kind of short relocation issue, but that's what I'd be worried about
with section order changes.

The other potential issue is sections moving past linker script defined
symbols such as __init_end, so that the section might be allocated
differently. The only change of that form in this patch is that it moves
.data.init_task before _edata, which on sparc is only used to print how
memory is used by different data types.

The other thing I should mention is that I've not boot-tested this; I've
only build-tested it with a sparc64 cross-compiler. So that should be
done before merging this.

> It's hard for me to ACK this because it's not a straight nop
> transformation, which we could at least presume would function
> properly if the macros were implemented correctly.

Would it help if I were to split the patch into first rearranging the code
to look like the macros and then applying the macros, so that you can see
more easily exactly what is changing?

-Tim Abbott

2009-09-16 20:31:42

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [PATCH v2] sparc: Clean up linker script using new linker script macros.

On Wed, Sep 16, 2009 at 10:30:19AM -0700, David Miller wrote:
> From: Tim Abbott <[email protected]>
> Date: Wed, 16 Sep 2009 13:27:43 -0400 (EDT)
>
> > On Wed, 16 Sep 2009, David Miller wrote:
> >
> >> Can you do this cleanup without moving the relative locations of .data
> >> and .data1 sections?
> >
> > Yes, if you just swap RW_DATA_SECTION and .data1 so it looks like
> >
> > RW_DATA_SECTION(SMP_CACHE_BYTES, 0, THREAD_SIZE)
> > .data1 : {
> > *(.data1)
> > }
> >
> > instead, that would preserve their relative locations.
> >
> > Currently, switching to RW_DATA_SECTION would still result in a change in
> > their relative position that .data.page_aligned and .data.nosave would be
> > between .data and .data1 (not sure if that is relevant on sparc). (this
> > will change when <http://lkml.org/lkml/2009/9/16/396> is merged).
>
> I don't know which, if any, are relevant or could cause problems.
>
> It's hard for me to ACK this because it's not a straight nop
> transformation, which we could at least presume would function
> properly if the macros were implemented correctly.

As you most likely are aware the linker scripts has diverged a lot
over time between different architectures.
So whatever fits the ordering of one architecture fails on another
architecture.

Tim is doing a huge effort to bring some sanity into this
area which I appreciate a lot!

Sam

2009-09-16 22:32:08

by David Miller

[permalink] [raw]
Subject: Re: [PATCH v2] sparc: Clean up linker script using new linker script macros.

From: Tim Abbott <[email protected]>
Date: Wed, 16 Sep 2009 14:03:48 -0400 (EDT)

> On Wed, 16 Sep 2009, David Miller wrote:
>
>> It's hard for me to ACK this because it's not a straight nop
>> transformation, which we could at least presume would function
>> properly if the macros were implemented correctly.
>
> Would it help if I were to split the patch into first rearranging the code
> to look like the macros and then applying the macros, so that you can see
> more easily exactly what is changing?

No, it wouldn't :-) The issue is that I can't just say from
reading the patch that it will absolutely work.

But I'm willing to take the risk and we can revert if testing
shows it breaks things, so:

Acked-by: David S. Miller <[email protected]>