mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] lds: align RO_DATA_SECTION members
@ 2019-12-09  8:00 Lucas Stach
  2019-12-09  9:05 ` Sam Ravnborg
  2019-12-26  9:11 ` Sam Ravnborg
  0 siblings, 2 replies; 4+ messages in thread
From: Lucas Stach @ 2019-12-09  8:00 UTC (permalink / raw)
  To: barebox

When using the RO_DATA_SECTION macro, all the individual components
are put into the rodata section. As they now end up in the same
section there is no alignment enforced between them anymore. This
leads to unaligned start pointers when any of the components have a
unaligned size. Enforce some alignment between them.

Fixes: c5d38e920101 (lds: Add and use RO_DATA_SECTION macro)
Signed-off-by: Lucas Stach <dev@lynxeye.de>
---
 include/asm-generic/barebox.lds.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index b6ca8eb2be27..113392d567fa 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -17,6 +17,7 @@
 #endif
 
 #define BAREBOX_INITCALLS			\
+	. = ALIGN(8);				\
 	__barebox_initcalls_start = .;		\
 	KEEP(*(.initcall.0))			\
 	KEEP(*(.initcall.1))			\
@@ -36,6 +37,7 @@
 	__barebox_initcalls_end = .;
 
 #define BAREBOX_EXITCALLS			\
+	. = ALIGN(8);				\
 	__barebox_exitcalls_start = .;		\
 	KEEP(*(.exitcall.0))			\
 	KEEP(*(.exitcall.1))			\
@@ -47,37 +49,44 @@
 	__barebox_exitcalls_end = .;
 
 #define BAREBOX_CMDS				\
+	. = ALIGN(8);				\
 	__barebox_cmd_start = .;		\
 	KEEP(*(SORT_BY_NAME(.barebox_cmd*)))	\
 	__barebox_cmd_end = .;
 
 #define BAREBOX_RATP_CMDS			\
+	. = ALIGN(8);				\
 	__barebox_ratp_cmd_start = .;		\
 	KEEP(*(SORT_BY_NAME(.barebox_ratp_cmd*)))	\
 	__barebox_ratp_cmd_end = .;
 
 #define BAREBOX_SYMS				\
+	. = ALIGN(8);				\
 	__usymtab_start = .;			\
 	KEEP(*(__usymtab))			\
 	__usymtab_end = .;
 
 #define BAREBOX_MAGICVARS			\
+	. = ALIGN(8);				\
 	__barebox_magicvar_start = .;		\
 	KEEP(*(SORT_BY_NAME(.barebox_magicvar*)))	\
 	__barebox_magicvar_end = .;
 
 #define BAREBOX_CLK_TABLE			\
+	. = ALIGN(8);				\
 	__clk_of_table_start = .;		\
 	KEEP(*(.__clk_of_table));		\
 	KEEP(*(.__clk_of_table_end));		\
 	__clk_of_table_end = .;
 
 #define BAREBOX_DTB				\
+	. = ALIGN(8);				\
 	__dtb_start = .;			\
 	KEEP(*(.dtb.rodata.*));			\
 	__dtb_end = .;
 
 #define BAREBOX_IMD				\
+	. = ALIGN(8);				\
 	KEEP(*(.barebox_imd_start))		\
 	KEEP(*(.barebox_imd_1*))		\
 	*(.barebox_imd_0*)			\
@@ -85,6 +94,7 @@
 
 #ifdef CONFIG_PCI
 #define BAREBOX_PCI_FIXUP			\
+	. = ALIGN(8);				\
 	__start_pci_fixups_early = .;		\
 	KEEP(*(.pci_fixup_early))		\
 	__end_pci_fixups_early = .;		\
@@ -99,6 +109,7 @@
 #endif
 
 #define BAREBOX_RSA_KEYS			\
+	. = ALIGN(8);				\
 	__rsa_keys_start = .;			\
 	KEEP(*(.rsa_keys.rodata.*));		\
 	__rsa_keys_end = .;			\
-- 
2.23.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lds: align RO_DATA_SECTION members
  2019-12-09  8:00 [PATCH] lds: align RO_DATA_SECTION members Lucas Stach
@ 2019-12-09  9:05 ` Sam Ravnborg
  2019-12-09 10:02   ` Lucas Stach
  2019-12-26  9:11 ` Sam Ravnborg
  1 sibling, 1 reply; 4+ messages in thread
From: Sam Ravnborg @ 2019-12-09  9:05 UTC (permalink / raw)
  To: Lucas Stach; +Cc: barebox

Hi Lucas.

On Mon, Dec 09, 2019 at 09:00:29AM +0100, Lucas Stach wrote:
> When using the RO_DATA_SECTION macro, all the individual components
> are put into the rodata section. As they now end up in the same
> section there is no alignment enforced between them anymore. This
> leads to unaligned start pointers when any of the components have a
> unaligned size. Enforce some alignment between them.

In the kernel we have:
#define ALIGN_FUNCTION()  . = ALIGN(8)
#define STRUCT_ALIGNMENT 32
#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)

Could we use something similar here?

	Sam

> 
> Fixes: c5d38e920101 (lds: Add and use RO_DATA_SECTION macro)
> Signed-off-by: Lucas Stach <dev@lynxeye.de>
> ---
>  include/asm-generic/barebox.lds.h | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
> index b6ca8eb2be27..113392d567fa 100644
> --- a/include/asm-generic/barebox.lds.h
> +++ b/include/asm-generic/barebox.lds.h
> @@ -17,6 +17,7 @@
>  #endif
>  
>  #define BAREBOX_INITCALLS			\
> +	. = ALIGN(8);				\
>  	__barebox_initcalls_start = .;		\
>  	KEEP(*(.initcall.0))			\
>  	KEEP(*(.initcall.1))			\
> @@ -36,6 +37,7 @@
>  	__barebox_initcalls_end = .;
>  
>  #define BAREBOX_EXITCALLS			\
> +	. = ALIGN(8);				\
>  	__barebox_exitcalls_start = .;		\
>  	KEEP(*(.exitcall.0))			\
>  	KEEP(*(.exitcall.1))			\
> @@ -47,37 +49,44 @@
>  	__barebox_exitcalls_end = .;
>  
>  #define BAREBOX_CMDS				\
> +	. = ALIGN(8);				\
>  	__barebox_cmd_start = .;		\
>  	KEEP(*(SORT_BY_NAME(.barebox_cmd*)))	\
>  	__barebox_cmd_end = .;
>  
>  #define BAREBOX_RATP_CMDS			\
> +	. = ALIGN(8);				\
>  	__barebox_ratp_cmd_start = .;		\
>  	KEEP(*(SORT_BY_NAME(.barebox_ratp_cmd*)))	\
>  	__barebox_ratp_cmd_end = .;
>  
>  #define BAREBOX_SYMS				\
> +	. = ALIGN(8);				\
>  	__usymtab_start = .;			\
>  	KEEP(*(__usymtab))			\
>  	__usymtab_end = .;
>  
>  #define BAREBOX_MAGICVARS			\
> +	. = ALIGN(8);				\
>  	__barebox_magicvar_start = .;		\
>  	KEEP(*(SORT_BY_NAME(.barebox_magicvar*)))	\
>  	__barebox_magicvar_end = .;
>  
>  #define BAREBOX_CLK_TABLE			\
> +	. = ALIGN(8);				\
>  	__clk_of_table_start = .;		\
>  	KEEP(*(.__clk_of_table));		\
>  	KEEP(*(.__clk_of_table_end));		\
>  	__clk_of_table_end = .;
>  
>  #define BAREBOX_DTB				\
> +	. = ALIGN(8);				\
>  	__dtb_start = .;			\
>  	KEEP(*(.dtb.rodata.*));			\
>  	__dtb_end = .;
>  
>  #define BAREBOX_IMD				\
> +	. = ALIGN(8);				\
>  	KEEP(*(.barebox_imd_start))		\
>  	KEEP(*(.barebox_imd_1*))		\
>  	*(.barebox_imd_0*)			\
> @@ -85,6 +94,7 @@
>  
>  #ifdef CONFIG_PCI
>  #define BAREBOX_PCI_FIXUP			\
> +	. = ALIGN(8);				\
>  	__start_pci_fixups_early = .;		\
>  	KEEP(*(.pci_fixup_early))		\
>  	__end_pci_fixups_early = .;		\
> @@ -99,6 +109,7 @@
>  #endif
>  
>  #define BAREBOX_RSA_KEYS			\
> +	. = ALIGN(8);				\
>  	__rsa_keys_start = .;			\
>  	KEEP(*(.rsa_keys.rodata.*));		\
>  	__rsa_keys_end = .;			\
> -- 
> 2.23.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lds: align RO_DATA_SECTION members
  2019-12-09  9:05 ` Sam Ravnborg
@ 2019-12-09 10:02   ` Lucas Stach
  0 siblings, 0 replies; 4+ messages in thread
From: Lucas Stach @ 2019-12-09 10:02 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: barebox

Hi Sam,

On Mo, 2019-12-09 at 10:05 +0100, Sam Ravnborg wrote:
> Hi Lucas.
> 
> On Mon, Dec 09, 2019 at 09:00:29AM +0100, Lucas Stach wrote:
> > When using the RO_DATA_SECTION macro, all the individual components
> > are put into the rodata section. As they now end up in the same
> > section there is no alignment enforced between them anymore. This
> > leads to unaligned start pointers when any of the components have a
> > unaligned size. Enforce some alignment between them.
> 
> In the kernel we have:
> #define ALIGN_FUNCTION()  . = ALIGN(8)
> #define STRUCT_ALIGNMENT 32
> #define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
> 
> Could we use something similar here?

Actually the STRUCT_ALIGN() define is available in Barebox in the very
same file changed in this commit. However I'm not sure if using those
defines is an improvement. We have some stuff in the RO_DATA_SECTION
like DTB and RSA keys that are neither a struct nor a function, so
using any of those defines is at least misleading.

So if we want to make this more descriptive we would need a new define
with a somewhat fitting name.

Regards,
Lucas


> 	Sam
> 
> > Fixes: c5d38e920101 (lds: Add and use RO_DATA_SECTION macro)
> > Signed-off-by: Lucas Stach <dev@lynxeye.de>
> > ---
> >  include/asm-generic/barebox.lds.h | 11 +++++++++++
> >  1 file changed, 11 insertions(+)
> > 
> > diff --git a/include/asm-generic/barebox.lds.h b/include/asm-
> > generic/barebox.lds.h
> > index b6ca8eb2be27..113392d567fa 100644
> > --- a/include/asm-generic/barebox.lds.h
> > +++ b/include/asm-generic/barebox.lds.h
> > @@ -17,6 +17,7 @@
> >  #endif
> >  
> >  #define BAREBOX_INITCALLS			\
> > +	. = ALIGN(8);				\
> >  	__barebox_initcalls_start = .;		\
> >  	KEEP(*(.initcall.0))			\
> >  	KEEP(*(.initcall.1))			\
> > @@ -36,6 +37,7 @@
> >  	__barebox_initcalls_end = .;
> >  
> >  #define BAREBOX_EXITCALLS			\
> > +	. = ALIGN(8);				\
> >  	__barebox_exitcalls_start = .;		\
> >  	KEEP(*(.exitcall.0))			\
> >  	KEEP(*(.exitcall.1))			\
> > @@ -47,37 +49,44 @@
> >  	__barebox_exitcalls_end = .;
> >  
> >  #define BAREBOX_CMDS				\
> > +	. = ALIGN(8);				\
> >  	__barebox_cmd_start = .;		\
> >  	KEEP(*(SORT_BY_NAME(.barebox_cmd*)))	\
> >  	__barebox_cmd_end = .;
> >  
> >  #define BAREBOX_RATP_CMDS			\
> > +	. = ALIGN(8);				\
> >  	__barebox_ratp_cmd_start = .;		\
> >  	KEEP(*(SORT_BY_NAME(.barebox_ratp_cmd*)))	\
> >  	__barebox_ratp_cmd_end = .;
> >  
> >  #define BAREBOX_SYMS				\
> > +	. = ALIGN(8);				\
> >  	__usymtab_start = .;			\
> >  	KEEP(*(__usymtab))			\
> >  	__usymtab_end = .;
> >  
> >  #define BAREBOX_MAGICVARS			\
> > +	. = ALIGN(8);				\
> >  	__barebox_magicvar_start = .;		\
> >  	KEEP(*(SORT_BY_NAME(.barebox_magicvar*)))	\
> >  	__barebox_magicvar_end = .;
> >  
> >  #define BAREBOX_CLK_TABLE			\
> > +	. = ALIGN(8);				\
> >  	__clk_of_table_start = .;		\
> >  	KEEP(*(.__clk_of_table));		\
> >  	KEEP(*(.__clk_of_table_end));		\
> >  	__clk_of_table_end = .;
> >  
> >  #define BAREBOX_DTB				\
> > +	. = ALIGN(8);				\
> >  	__dtb_start = .;			\
> >  	KEEP(*(.dtb.rodata.*));			\
> >  	__dtb_end = .;
> >  
> >  #define BAREBOX_IMD				\
> > +	. = ALIGN(8);				\
> >  	KEEP(*(.barebox_imd_start))		\
> >  	KEEP(*(.barebox_imd_1*))		\
> >  	*(.barebox_imd_0*)			\
> > @@ -85,6 +94,7 @@
> >  
> >  #ifdef CONFIG_PCI
> >  #define BAREBOX_PCI_FIXUP			\
> > +	. = ALIGN(8);				\
> >  	__start_pci_fixups_early = .;		\
> >  	KEEP(*(.pci_fixup_early))		\
> >  	__end_pci_fixups_early = .;		\
> > @@ -99,6 +109,7 @@
> >  #endif
> >  
> >  #define BAREBOX_RSA_KEYS			\
> > +	. = ALIGN(8);				\
> >  	__rsa_keys_start = .;			\
> >  	KEEP(*(.rsa_keys.rodata.*));		\
> >  	__rsa_keys_end = .;			\
> > -- 
> > 2.23.0
> > 
> > 
> > _______________________________________________
> > barebox mailing list
> > barebox@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lds: align RO_DATA_SECTION members
  2019-12-09  8:00 [PATCH] lds: align RO_DATA_SECTION members Lucas Stach
  2019-12-09  9:05 ` Sam Ravnborg
@ 2019-12-26  9:11 ` Sam Ravnborg
  1 sibling, 0 replies; 4+ messages in thread
From: Sam Ravnborg @ 2019-12-26  9:11 UTC (permalink / raw)
  To: Lucas Stach; +Cc: barebox

Hi Lucas.

On Mon, Dec 09, 2019 at 09:00:29AM +0100, Lucas Stach wrote:
> When using the RO_DATA_SECTION macro, all the individual components
> are put into the rodata section. As they now end up in the same
> section there is no alignment enforced between them anymore. This
> leads to unaligned start pointers when any of the components have a
> unaligned size. Enforce some alignment between them.
> 
> Fixes: c5d38e920101 (lds: Add and use RO_DATA_SECTION macro)
> Signed-off-by: Lucas Stach <dev@lynxeye.de>

After a rather painful bisect I ended up with the commit
c5d38e920101 (lds: Add and use RO_DATA_SECTION macro) as the bad
commit.
So in my case missing the alignment prevented barebox from starting up.

The bisect was painful because this is a proprietary board
where I have too many patches accumulated - and my first attempt
pointed out used a good commit as bad (missing edits after applying
patches).

I saw a v2 of this patch that I already deleted from my mailbox,
but re-did it locally.  That fixed barebox for me.

According to: http://lists.infradead.org/pipermail/barebox/2019-December/040439.html
the patch is applied - but I cannot find it neither in master nor in
next. Seems it has not been pushed out in the xmas rush.

You can add a:
Tested-by: Sam Ravnborg <sam@ravnborg.org>  # fixes barebox startup on at91sam9263
in case it is relevant / doable.

	Sam



> ---
>  include/asm-generic/barebox.lds.h | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
> index b6ca8eb2be27..113392d567fa 100644
> --- a/include/asm-generic/barebox.lds.h
> +++ b/include/asm-generic/barebox.lds.h
> @@ -17,6 +17,7 @@
>  #endif
>  
>  #define BAREBOX_INITCALLS			\
> +	. = ALIGN(8);				\
>  	__barebox_initcalls_start = .;		\
>  	KEEP(*(.initcall.0))			\
>  	KEEP(*(.initcall.1))			\
> @@ -36,6 +37,7 @@
>  	__barebox_initcalls_end = .;
>  
>  #define BAREBOX_EXITCALLS			\
> +	. = ALIGN(8);				\
>  	__barebox_exitcalls_start = .;		\
>  	KEEP(*(.exitcall.0))			\
>  	KEEP(*(.exitcall.1))			\
> @@ -47,37 +49,44 @@
>  	__barebox_exitcalls_end = .;
>  
>  #define BAREBOX_CMDS				\
> +	. = ALIGN(8);				\
>  	__barebox_cmd_start = .;		\
>  	KEEP(*(SORT_BY_NAME(.barebox_cmd*)))	\
>  	__barebox_cmd_end = .;
>  
>  #define BAREBOX_RATP_CMDS			\
> +	. = ALIGN(8);				\
>  	__barebox_ratp_cmd_start = .;		\
>  	KEEP(*(SORT_BY_NAME(.barebox_ratp_cmd*)))	\
>  	__barebox_ratp_cmd_end = .;
>  
>  #define BAREBOX_SYMS				\
> +	. = ALIGN(8);				\
>  	__usymtab_start = .;			\
>  	KEEP(*(__usymtab))			\
>  	__usymtab_end = .;
>  
>  #define BAREBOX_MAGICVARS			\
> +	. = ALIGN(8);				\
>  	__barebox_magicvar_start = .;		\
>  	KEEP(*(SORT_BY_NAME(.barebox_magicvar*)))	\
>  	__barebox_magicvar_end = .;
>  
>  #define BAREBOX_CLK_TABLE			\
> +	. = ALIGN(8);				\
>  	__clk_of_table_start = .;		\
>  	KEEP(*(.__clk_of_table));		\
>  	KEEP(*(.__clk_of_table_end));		\
>  	__clk_of_table_end = .;
>  
>  #define BAREBOX_DTB				\
> +	. = ALIGN(8);				\
>  	__dtb_start = .;			\
>  	KEEP(*(.dtb.rodata.*));			\
>  	__dtb_end = .;
>  
>  #define BAREBOX_IMD				\
> +	. = ALIGN(8);				\
>  	KEEP(*(.barebox_imd_start))		\
>  	KEEP(*(.barebox_imd_1*))		\
>  	*(.barebox_imd_0*)			\
> @@ -85,6 +94,7 @@
>  
>  #ifdef CONFIG_PCI
>  #define BAREBOX_PCI_FIXUP			\
> +	. = ALIGN(8);				\
>  	__start_pci_fixups_early = .;		\
>  	KEEP(*(.pci_fixup_early))		\
>  	__end_pci_fixups_early = .;		\
> @@ -99,6 +109,7 @@
>  #endif
>  
>  #define BAREBOX_RSA_KEYS			\
> +	. = ALIGN(8);				\
>  	__rsa_keys_start = .;			\
>  	KEEP(*(.rsa_keys.rodata.*));		\
>  	__rsa_keys_end = .;			\
> -- 
> 2.23.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-26  9:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-09  8:00 [PATCH] lds: align RO_DATA_SECTION members Lucas Stach
2019-12-09  9:05 ` Sam Ravnborg
2019-12-09 10:02   ` Lucas Stach
2019-12-26  9:11 ` Sam Ravnborg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox