mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/7] Cleanup linker scripts
@ 2019-10-02 14:44 Sascha Hauer
  2019-10-02 14:44 ` [PATCH 1/7] barebox.lds: Remove unnecessary braces Sascha Hauer
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Sascha Hauer @ 2019-10-02 14:44 UTC (permalink / raw)
  To: Barebox List

We use many arrays created by the linker. Each time a new one is added
we have to add it to the linker script of all architectures. This series
adds a common RO_DATA_SECTION to collect the arrays which is then used
in all linker scripts.

I don't like fiddling with linker scripts. It's dangerous and asking for
regressions. Some testing feedback especially for the !ARM architectures
is greatly appreciated.

Sascha

Sascha Hauer (7):
  barebox.lds: Remove unnecessary braces
  ppc: remove unused variables from linker scripts
  lds: Move start/end address variables into defines
  lds: create and use BAREBOX_PCI_FIXUP macro
  X86: lds: remove unnecessary alignments
  lds: remove more unnecessary alignments
  lds: Add and use RO_DATA_SECTION macro

 arch/arm/lib32/barebox.lds.S           | 44 ++--------------
 arch/arm/lib64/barebox.lds.S           | 46 ++---------------
 arch/mips/lib/barebox.lds.S            | 45 ++---------------
 arch/nios2/cpu/barebox.lds.S           | 29 ++---------
 arch/openrisc/cpu/barebox.lds.S        | 29 +----------
 arch/ppc/boards/pcm030/barebox.lds.S   | 28 +----------
 arch/ppc/mach-mpc85xx/barebox.lds.S    | 24 +--------
 arch/riscv/lib/barebox.lds.S           | 30 +++--------
 arch/sandbox/board/barebox.lds.S       | 26 ++--------
 arch/x86/lib/barebox.lds.S             | 43 +---------------
 arch/x86/mach-efi/elf_ia32_efi.lds.S   | 26 +---------
 arch/x86/mach-efi/elf_x86_64_efi.lds.S | 26 +---------
 include/asm-generic/barebox.lds.h      | 70 +++++++++++++++++++++-----
 13 files changed, 89 insertions(+), 377 deletions(-)

-- 
2.23.0


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

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

* [PATCH 1/7] barebox.lds: Remove unnecessary braces
  2019-10-02 14:44 [PATCH 0/7] Cleanup linker scripts Sascha Hauer
@ 2019-10-02 14:44 ` Sascha Hauer
  2019-10-02 14:44 ` [PATCH 2/7] ppc: remove unused variables from linker scripts Sascha Hauer
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2019-10-02 14:44 UTC (permalink / raw)
  To: Barebox List

The BAREBOX_CLK_TABLE and BAREBOX_DTB macros are defines that do not
take a parameter, so we can remove the braces.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib32/barebox.lds.S      | 4 ++--
 arch/arm/lib64/barebox.lds.S      | 4 ++--
 arch/mips/lib/barebox.lds.S       | 4 ++--
 arch/openrisc/cpu/barebox.lds.S   | 2 +-
 arch/riscv/lib/barebox.lds.S      | 4 ++--
 include/asm-generic/barebox.lds.h | 4 ++--
 6 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/arm/lib32/barebox.lds.S b/arch/arm/lib32/barebox.lds.S
index 7230e5f31f..05a50afaad 100644
--- a/arch/arm/lib32/barebox.lds.S
+++ b/arch/arm/lib32/barebox.lds.S
@@ -118,9 +118,9 @@ SECTIONS
 	__end_pci_fixups_enable = .;
 #endif
 
-	.oftables : { BAREBOX_CLK_TABLE() }
+	.oftables : { BAREBOX_CLK_TABLE }
 
-	.dtb : { BAREBOX_DTB() }
+	.dtb : { BAREBOX_DTB }
 
 	.rel_dyn_start : { *(.__rel_dyn_start) }
 	.rel.dyn : { *(.rel*) }
diff --git a/arch/arm/lib64/barebox.lds.S b/arch/arm/lib64/barebox.lds.S
index 694bbcaaf1..5e9d94bee9 100644
--- a/arch/arm/lib64/barebox.lds.S
+++ b/arch/arm/lib64/barebox.lds.S
@@ -100,9 +100,9 @@ SECTIONS
 	__end_pci_fixups_enable = .;
 #endif
 
-	.oftables : { BAREBOX_CLK_TABLE() }
+	.oftables : { BAREBOX_CLK_TABLE }
 
-	.dtb : { BAREBOX_DTB() }
+	.dtb : { BAREBOX_DTB }
 
 	.rel_dyn_start : { *(.__rel_dyn_start) }
 	.rela.dyn : { *(.rela*) }
diff --git a/arch/mips/lib/barebox.lds.S b/arch/mips/lib/barebox.lds.S
index 58b0c5919d..7109d73372 100644
--- a/arch/mips/lib/barebox.lds.S
+++ b/arch/mips/lib/barebox.lds.S
@@ -76,9 +76,9 @@ SECTIONS
 	.pci_fixup_enable : { KEEP(*(.pci_fixup_enable)) }
 	__end_pci_fixups_enable = .;
 #endif
-	.oftables : { BAREBOX_CLK_TABLE() }
+	.oftables : { BAREBOX_CLK_TABLE }
 
-	.dtb : { BAREBOX_DTB() }
+	.dtb : { BAREBOX_DTB }
 
 	_edata = .;
 	.image_end : { *(.__image_end) }
diff --git a/arch/openrisc/cpu/barebox.lds.S b/arch/openrisc/cpu/barebox.lds.S
index c6807aec3a..ed9b90ed70 100644
--- a/arch/openrisc/cpu/barebox.lds.S
+++ b/arch/openrisc/cpu/barebox.lds.S
@@ -77,7 +77,7 @@ SECTIONS
 	__usymtab : { BAREBOX_SYMS } > ram
 	___usymtab_end = .;
 
-	.dtb : { BAREBOX_DTB() } > ram
+	.dtb : { BAREBOX_DTB } > ram
 
 	__etext = .; /* End of text and rodata section */
 
diff --git a/arch/riscv/lib/barebox.lds.S b/arch/riscv/lib/barebox.lds.S
index ffb97f40e8..10c19f15de 100644
--- a/arch/riscv/lib/barebox.lds.S
+++ b/arch/riscv/lib/barebox.lds.S
@@ -66,9 +66,9 @@ SECTIONS
 
 	.rela.dyn : { *(.rela*) }
 
-	.oftables : { BAREBOX_CLK_TABLE() }
+	.oftables : { BAREBOX_CLK_TABLE }
 
-	.dtb : { BAREBOX_DTB() }
+	.dtb : { BAREBOX_DTB }
 
 	_edata = .;
 	. = ALIGN(8);
diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index 74d3ca4a96..c9fb8f47ae 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -50,14 +50,14 @@
 
 #define BAREBOX_MAGICVARS	KEEP(*(SORT_BY_NAME(.barebox_magicvar*)))
 
-#define BAREBOX_CLK_TABLE()			\
+#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()				\
+#define BAREBOX_DTB				\
 	. = ALIGN(8);				\
 	__dtb_start = .;			\
 	KEEP(*(.dtb.rodata.*));			\
-- 
2.23.0


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

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

* [PATCH 2/7] ppc: remove unused variables from linker scripts
  2019-10-02 14:44 [PATCH 0/7] Cleanup linker scripts Sascha Hauer
  2019-10-02 14:44 ` [PATCH 1/7] barebox.lds: Remove unnecessary braces Sascha Hauer
@ 2019-10-02 14:44 ` Sascha Hauer
  2019-10-02 14:44 ` [PATCH 3/7] lds: Move start/end address variables into defines Sascha Hauer
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2019-10-02 14:44 UTC (permalink / raw)
  To: Barebox List

__initcall_entries and __exitcall_entries are unused. Remove them.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/ppc/boards/pcm030/barebox.lds.S | 2 --
 arch/ppc/mach-mpc85xx/barebox.lds.S  | 2 --
 2 files changed, 4 deletions(-)

diff --git a/arch/ppc/boards/pcm030/barebox.lds.S b/arch/ppc/boards/pcm030/barebox.lds.S
index 3b8bf3c0d0..12b551e685 100644
--- a/arch/ppc/boards/pcm030/barebox.lds.S
+++ b/arch/ppc/boards/pcm030/barebox.lds.S
@@ -115,12 +115,10 @@ SECTIONS
   __barebox_initcalls_start = .;
   .barebox_initcalls : { INITCALLS }
   __barebox_initcalls_end = .;
-  __initcall_entries = (__barebox_initcalls_end - __barebox_initcalls_start) >> 2;
 
   __barebox_exitcalls_start = .;
   .barebox_exitcalls : { EXITCALLS }
   __barebox_exitcalls_end = .;
-  __exitcall_entries = (__barebox_exitcalls_end - __barebox_exitcalls_start) >> 2;
 
   __usymtab_start = .;
   __usymtab : { BAREBOX_SYMS }
diff --git a/arch/ppc/mach-mpc85xx/barebox.lds.S b/arch/ppc/mach-mpc85xx/barebox.lds.S
index 0001972831..30a1c571d7 100644
--- a/arch/ppc/mach-mpc85xx/barebox.lds.S
+++ b/arch/ppc/mach-mpc85xx/barebox.lds.S
@@ -112,12 +112,10 @@ SECTIONS
   __barebox_initcalls_start = .;
   .barebox_initcalls : { INITCALLS }
   __barebox_initcalls_end = .;
-  __initcall_entries = (__barebox_initcalls_end - __barebox_initcalls_start)>>2;
 
   __barebox_exitcalls_start = .;
   .barebox_exitcalls : { EXITCALLS }
   __barebox_exitcalls_end = .;
-  __exitcall_entries = (__barebox_exitcalls_end - __barebox_exitcalls_start) >> 2;
 
   __usymtab_start = .;
   __usymtab : { BAREBOX_SYMS }
-- 
2.23.0


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

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

* [PATCH 3/7] lds: Move start/end address variables into defines
  2019-10-02 14:44 [PATCH 0/7] Cleanup linker scripts Sascha Hauer
  2019-10-02 14:44 ` [PATCH 1/7] barebox.lds: Remove unnecessary braces Sascha Hauer
  2019-10-02 14:44 ` [PATCH 2/7] ppc: remove unused variables from linker scripts Sascha Hauer
@ 2019-10-02 14:44 ` Sascha Hauer
  2019-10-02 18:46   ` Sam Ravnborg
  2019-10-02 14:44 ` [PATCH 4/7] lds: create and use BAREBOX_PCI_FIXUP macro Sascha Hauer
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Sascha Hauer @ 2019-10-02 14:44 UTC (permalink / raw)
  To: Barebox List

For the older section defines we specify the start and end addresses
outside the macro which means we have to repeat them in each linker
script. Make the start/end addresses part of the define to simplify
things. While at it, add a BAREBOX_ prefix to the INITCALLS and EXITCALLS
macros for consistency to the other defines.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib32/barebox.lds.S           | 21 ++------------
 arch/arm/lib64/barebox.lds.S           | 21 ++------------
 arch/mips/lib/barebox.lds.S            | 21 ++------------
 arch/nios2/cpu/barebox.lds.S           | 21 ++------------
 arch/openrisc/cpu/barebox.lds.S        | 22 ++------------
 arch/ppc/boards/pcm030/barebox.lds.S   | 21 ++------------
 arch/ppc/mach-mpc85xx/barebox.lds.S    | 18 ++----------
 arch/riscv/lib/barebox.lds.S           | 18 ++----------
 arch/sandbox/board/barebox.lds.S       | 14 ++-------
 arch/x86/lib/barebox.lds.S             | 16 ++---------
 arch/x86/mach-efi/elf_ia32_efi.lds.S   | 15 ++--------
 arch/x86/mach-efi/elf_x86_64_efi.lds.S | 15 ++--------
 include/asm-generic/barebox.lds.h      | 40 ++++++++++++++++++--------
 13 files changed, 52 insertions(+), 211 deletions(-)

diff --git a/arch/arm/lib32/barebox.lds.S b/arch/arm/lib32/barebox.lds.S
index 05a50afaad..9ffcffd66d 100644
--- a/arch/arm/lib32/barebox.lds.S
+++ b/arch/arm/lib32/barebox.lds.S
@@ -82,29 +82,12 @@ SECTIONS
 	.barebox_imd : { BAREBOX_IMD }
 
 	. = .;
-	__barebox_cmd_start = .;
 	.barebox_cmd : { BAREBOX_CMDS }
-	__barebox_cmd_end = .;
-
-	__barebox_ratp_cmd_start = .;
 	.barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-	__barebox_ratp_cmd_end = .;
-
-	__barebox_magicvar_start = .;
 	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	__barebox_magicvar_end = .;
-
-	__barebox_initcalls_start = .;
-	.barebox_initcalls : { INITCALLS }
-	__barebox_initcalls_end = .;
-
-	__barebox_exitcalls_start = .;
-	.barebox_exitcalls : { EXITCALLS }
-	__barebox_exitcalls_end = .;
-
-	__usymtab_start = .;
+	.barebox_initcalls : { BAREBOX_INITCALLS }
+	.barebox_exitcalls : { BAREBOX_EXITCALLS }
 	__usymtab : { BAREBOX_SYMS }
-	__usymtab_end = .;
 
 #ifdef CONFIG_PCI
 	__start_pci_fixups_early = .;
diff --git a/arch/arm/lib64/barebox.lds.S b/arch/arm/lib64/barebox.lds.S
index 5e9d94bee9..1cc00eca11 100644
--- a/arch/arm/lib64/barebox.lds.S
+++ b/arch/arm/lib64/barebox.lds.S
@@ -64,29 +64,12 @@ SECTIONS
 	.barebox_imd : { BAREBOX_IMD }
 
 	. = .;
-	__barebox_cmd_start = .;
 	.barebox_cmd : { BAREBOX_CMDS }
-	__barebox_cmd_end = .;
-
-	__barebox_ratp_cmd_start = .;
 	.barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-	__barebox_ratp_cmd_end = .;
-
-	__barebox_magicvar_start = .;
 	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	__barebox_magicvar_end = .;
-
-	__barebox_initcalls_start = .;
-	.barebox_initcalls : { INITCALLS }
-	__barebox_initcalls_end = .;
-
-	__barebox_exitcalls_start = .;
-	.barebox_exitcalls : { EXITCALLS }
-	__barebox_exitcalls_end = .;
-
-	__usymtab_start = .;
+	.barebox_initcalls : { BAREBOX_INITCALLS }
+	.barebox_exitcalls : { BAREBOX_EXITCALLS }
 	__usymtab : { BAREBOX_SYMS }
-	__usymtab_end = .;
 
 #ifdef CONFIG_PCI
 	__start_pci_fixups_early = .;
diff --git a/arch/mips/lib/barebox.lds.S b/arch/mips/lib/barebox.lds.S
index 7109d73372..86a469a042 100644
--- a/arch/mips/lib/barebox.lds.S
+++ b/arch/mips/lib/barebox.lds.S
@@ -41,29 +41,12 @@ SECTIONS
 	.barebox_imd : { BAREBOX_IMD }
 
 	. = .;
-	__barebox_cmd_start = .;
 	.barebox_cmd : { BAREBOX_CMDS }
-	__barebox_cmd_end = .;
-
-	__barebox_ratp_cmd_start = .;
 	.barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-	__barebox_ratp_cmd_end = .;
-
-	__barebox_magicvar_start = .;
 	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	__barebox_magicvar_end = .;
-
-	__barebox_initcalls_start = .;
-	.barebox_initcalls : { INITCALLS }
-	__barebox_initcalls_end = .;
-
-	__barebox_exitcalls_start = .;
-	.barebox_exitcalls : { EXITCALLS }
-	__barebox_exitcalls_end = .;
-
-	__usymtab_start = .;
+	.barebox_initcalls : { BAREBOX_INITCALLS }
+	.barebox_exitcalls : { BAREBOX_EXITCALLS }
 	__usymtab : { BAREBOX_SYMS }
-	__usymtab_end = .;
 
 #ifdef CONFIG_PCI
 	__start_pci_fixups_early = .;
diff --git a/arch/nios2/cpu/barebox.lds.S b/arch/nios2/cpu/barebox.lds.S
index fbcd1cd3f7..efe8e106a1 100644
--- a/arch/nios2/cpu/barebox.lds.S
+++ b/arch/nios2/cpu/barebox.lds.S
@@ -51,29 +51,12 @@ SECTIONS
 	.rodata : { *(.rodata) }
 
 	. = .;
-	__barebox_cmd_start = .;
 	.barebox_cmd : { BAREBOX_CMDS }
-	__barebox_cmd_end = .;
-
-	__barebox_ratp_cmd_start = .;
 	.barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-	__barebox_ratp_cmd_end = .;
-
-	__barebox_magicvar_start = .;
 	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	__barebox_magicvar_end = .;
-
-	__barebox_initcalls_start = .;
-	.barebox_initcalls : { INITCALLS }
-	__barebox_initcalls_end = .;
-
-	__barebox_exitcalls_start = .;
-	.barebox_exitcalls : { EXITCALLS }
-	__barebox_exitcalls_end = .;
-
-	___usymtab_start = .;
+	.barebox_initcalls : { BAREBOX_INITCALLS }
+	.barebox_exitcalls : { BAREBOX_EXITCALLS }
 	__usymtab : { BAREBOX_SYMS }
-	___usymtab_end = .;
 
 	_etext = .; /* End of text and rodata section */
 
diff --git a/arch/openrisc/cpu/barebox.lds.S b/arch/openrisc/cpu/barebox.lds.S
index ed9b90ed70..37242f9c5e 100644
--- a/arch/openrisc/cpu/barebox.lds.S
+++ b/arch/openrisc/cpu/barebox.lds.S
@@ -53,30 +53,12 @@ SECTIONS
 
 	. = ALIGN(4);
 	. = .;
-	__barebox_cmd_start = .;
 	.barebox_cmd : { BAREBOX_CMDS } > ram
-	__barebox_cmd_end = .;
-
-	__barebox_ratp_cmd_start = .;
 	.barebox_ratp_cmd : { BAREBOX_RATP_CMDS } > ram
-	__barebox_ratp_cmd_end = .;
-
-	__barebox_magicvar_start = .;
 	.barebox_magicvar : { BAREBOX_MAGICVARS } > ram
-	__barebox_magicvar_end = .;
-
-	__barebox_initcalls_start = .;
-	.barebox_initcalls : { INITCALLS } > ram
-	__barebox_initcalls_end = .;
-
-	__barebox_exitcalls_start = .;
-	.barebox_exitcalls : { EXITCALLS } > ram
-	__barebox_exitcalls_end = .;
-
-	___usymtab_start = .;
+	.barebox_initcalls : { BAREBOX_INITCALLS } > ram
+	.barebox_exitcalls : { BAREBOX_EXITCALLS } > ram
 	__usymtab : { BAREBOX_SYMS } > ram
-	___usymtab_end = .;
-
 	.dtb : { BAREBOX_DTB } > ram
 
 	__etext = .; /* End of text and rodata section */
diff --git a/arch/ppc/boards/pcm030/barebox.lds.S b/arch/ppc/boards/pcm030/barebox.lds.S
index 12b551e685..73e4bde434 100644
--- a/arch/ppc/boards/pcm030/barebox.lds.S
+++ b/arch/ppc/boards/pcm030/barebox.lds.S
@@ -100,29 +100,12 @@ SECTIONS
   PROVIDE (edata = .);
 
   . = .;
-  __barebox_cmd_start = .;
   .barebox_cmd : { BAREBOX_CMDS }
-  __barebox_cmd_end = .;
-
-  __barebox_ratp_cmd_start = .;
   .barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-  __barebox_ratp_cmd_end = .;
-
-  __barebox_magicvar_start = .;
   .barebox_magicvar : { BAREBOX_MAGICVARS }
-  __barebox_magicvar_end = .;
-
-  __barebox_initcalls_start = .;
-  .barebox_initcalls : { INITCALLS }
-  __barebox_initcalls_end = .;
-
-  __barebox_exitcalls_start = .;
-  .barebox_exitcalls : { EXITCALLS }
-  __barebox_exitcalls_end = .;
-
-  __usymtab_start = .;
+  .barebox_initcalls : { BAREBOX_INITCALLS }
+  .barebox_exitcalls : { BAREBOX_EXITCALLS }
   __usymtab : { BAREBOX_SYMS }
-  __usymtab_end = .;
 
   __start___ex_table = .;
   __ex_table : { *(__ex_table) }
diff --git a/arch/ppc/mach-mpc85xx/barebox.lds.S b/arch/ppc/mach-mpc85xx/barebox.lds.S
index 30a1c571d7..1874319e71 100644
--- a/arch/ppc/mach-mpc85xx/barebox.lds.S
+++ b/arch/ppc/mach-mpc85xx/barebox.lds.S
@@ -101,25 +101,11 @@ SECTIONS
   }
 
   . = .;
-  __barebox_cmd_start = .;
   .barebox_cmd : { BAREBOX_CMDS }
-  __barebox_cmd_end = .;
-
-  __barebox_ratp_cmd_start = .;
   .barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-  __barebox_ratp_cmd_end = .;
-
-  __barebox_initcalls_start = .;
-  .barebox_initcalls : { INITCALLS }
-  __barebox_initcalls_end = .;
-
-  __barebox_exitcalls_start = .;
-  .barebox_exitcalls : { EXITCALLS }
-  __barebox_exitcalls_end = .;
-
-  __usymtab_start = .;
+  .barebox_initcalls : { BAREBOX_INITCALLS }
+  .barebox_exitcalls : { BAREBOX_EXITCALLS }
   __usymtab : { BAREBOX_SYMS }
-  __usymtab_end = .;
 
   . = .;
   __start___ex_table = .;
diff --git a/arch/riscv/lib/barebox.lds.S b/arch/riscv/lib/barebox.lds.S
index 10c19f15de..23e4468e2f 100644
--- a/arch/riscv/lib/barebox.lds.S
+++ b/arch/riscv/lib/barebox.lds.S
@@ -44,25 +44,11 @@ SECTIONS
 	.got : { *(.got*) }
 
 	. = .;
-	__barebox_cmd_start = .;
 	.barebox_cmd : { BAREBOX_CMDS }
-	__barebox_cmd_end = .;
-
-	__barebox_magicvar_start = .;
 	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	__barebox_magicvar_end = .;
-
-	__barebox_initcalls_start = .;
-	.barebox_initcalls : { INITCALLS }
-	__barebox_initcalls_end = .;
-
-	__barebox_exitcalls_start = .;
-	.barebox_exitcalls : { EXITCALLS }
-	__barebox_exitcalls_end = .;
-
-	__usymtab_start = .;
+	.barebox_initcalls : { BAREBOX_INITCALLS }
+	.barebox_exitcalls : { BAREBOX_EXITCALLS }
 	__usymtab : { BAREBOX_SYMS }
-	__usymtab_end = .;
 
 	.rela.dyn : { *(.rela*) }
 
diff --git a/arch/sandbox/board/barebox.lds.S b/arch/sandbox/board/barebox.lds.S
index 80e27fe87d..bdce8ecbd6 100644
--- a/arch/sandbox/board/barebox.lds.S
+++ b/arch/sandbox/board/barebox.lds.S
@@ -3,29 +3,19 @@
 SECTIONS
 {
 	. = ALIGN(64);
-	__barebox_initcalls_start = .;
-	__barebox_initcalls : { INITCALLS }
-	__barebox_initcalls_end = .;
+	.barebox_initcalls : { BAREBOX_INITCALLS }
 
 	. = ALIGN(64);
-	__barebox_exitcalls_start = .;
-	__barebox_exitcalls : { EXITCALLS }
-	__barebox_exitcalls_end = .;
+	.barebox_exitcalls : { BAREBOX_EXITCALLS }
 
 	. = ALIGN(64);
-	__barebox_magicvar_start = .;
 	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	__barebox_magicvar_end = .;
 
 	. = ALIGN(64);
-	__barebox_cmd_start = .;
 	__barebox_cmd : { BAREBOX_CMDS }
-	__barebox_cmd_end = .;
 
 	. = ALIGN(64);
-	__barebox_ratp_cmd_start = .;
 	__barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-	__barebox_ratp_cmd_end = .;
 }
 
 INSERT BEFORE .rodata;
diff --git a/arch/x86/lib/barebox.lds.S b/arch/x86/lib/barebox.lds.S
index 6ee9342f47..d26f060a3e 100644
--- a/arch/x86/lib/barebox.lds.S
+++ b/arch/x86/lib/barebox.lds.S
@@ -165,44 +165,32 @@ SECTIONS
 	} > barebox
 
 	.barebox_cmd : AT ( LOADADDR(.got) + SIZEOF (.got) ) {
-		__barebox_cmd_start = .;
 		BAREBOX_CMDS
-		__barebox_cmd_end = .;
 		. = ALIGN(4);
 	} > barebox
 
 	.barebox_ratp_cmd : AT ( LOADADDR(.got) + SIZEOF (.got) ) {
-		__barebox_ratp_cmd_start = .;
 		BAREBOX_RATP_CMDS
-		__barebox_ratp_cmd_end = .;
 		. = ALIGN(4);
 	} > barebox
 
 	.barebox_magicvars : AT ( LOADADDR(.barebox_cmd) + SIZEOF (.barebox_cmd) ) {
-		__barebox_magicvar_start = .;
 		BAREBOX_MAGICVARS
-		__barebox_magicvar_end = .;
 		. = ALIGN(4);
 	} > barebox
 
 	.barebox_initcalls : AT ( LOADADDR(.barebox_magicvars) + SIZEOF (.barebox_magicvars) ) {
-		__barebox_initcalls_start = .;
-		INITCALLS
-		__barebox_initcalls_end = .;
+		BAREBOX_INITCALLS
 		. = ALIGN(4);
 	} > barebox
 
 	.barebox_exitcalls : AT ( LOADADDR(.barebox_initcalls) + SIZEOF (.barebox_initcalls) ) {
-		__barebox_exitcalls_start = .;
-		EXITCALLS
-		__barebox_exitcalls_end = .;
+		BAREBOX_EXITCALLS
 		. = ALIGN(4);
 	} > barebox
 
 	.__usymtab : AT ( LOADADDR(.barebox_exitcalls) + SIZEOF (.barebox_exitcalls) ) {
-		__usymtab_start = .;
 		BAREBOX_SYMS
-		__usymtab_end = .;
 		. = ALIGN(4);
 	} > barebox
 
diff --git a/arch/x86/mach-efi/elf_ia32_efi.lds.S b/arch/x86/mach-efi/elf_ia32_efi.lds.S
index 9477aa7d73..a5874c448b 100644
--- a/arch/x86/mach-efi/elf_ia32_efi.lds.S
+++ b/arch/x86/mach-efi/elf_ia32_efi.lds.S
@@ -52,28 +52,17 @@ SECTIONS
 
 	. = ALIGN(64);
 
-	__barebox_initcalls_start = .;
-	__barebox_initcalls : { INITCALLS }
-	__barebox_initcalls_end = .;
-
-	__barebox_exitcalls_start = .;
-	__barebox_exitcalls : { EXITCALLS }
-	__barebox_exitcalls_end = .;
+	.barebox_initcalls : { BAREBOX_INITCALLS }
+	.barebox_exitcalls : { BAREBOX_EXITCALLS }
 
 	. = ALIGN(64);
-	__barebox_magicvar_start = .;
 	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	__barebox_magicvar_end = .;
 
 	. = ALIGN(64);
-	__barebox_cmd_start = .;
 	__barebox_cmd : { BAREBOX_CMDS }
-	__barebox_cmd_end = .;
 
 	. = ALIGN(64);
-	__barebox_ratp_cmd_start = .;
 	__barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-	__barebox_ratp_cmd_end = .;
 
 	. = ALIGN(4096);
 	.dynamic : { *(.dynamic) }
diff --git a/arch/x86/mach-efi/elf_x86_64_efi.lds.S b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
index 90b6b9f3f1..b00cb98c97 100644
--- a/arch/x86/mach-efi/elf_x86_64_efi.lds.S
+++ b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
@@ -54,28 +54,17 @@ SECTIONS
 
 	. = ALIGN(64);
 
-	__barebox_initcalls_start = .;
-	__barebox_initcalls : { INITCALLS }
-	__barebox_initcalls_end = .;
-
-	__barebox_exitcalls_start = .;
-	__barebox_exitcalls : { EXITCALLS }
-	__barebox_exitcalls_end = .;
+	.barebox_initcalls : { BAREBOX_INITCALLS }
+	.barebox_exitcalls : { BAREBOX_EXITCALLS }
 
 	. = ALIGN(64);
-	__barebox_magicvar_start = .;
 	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	__barebox_magicvar_end = .;
 
 	. = ALIGN(64);
-	__barebox_cmd_start = .;
 	__barebox_cmd : { BAREBOX_CMDS }
-	__barebox_cmd_end = .;
 
 	. = ALIGN(64);
-	__barebox_ratp_cmd_start = .;
 	__barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-	__barebox_ratp_cmd_end = .;
 
 	. = ALIGN(4096);
 	.dynamic : { *(.dynamic) }
diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index c9fb8f47ae..0784048eb6 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -16,7 +16,8 @@
 #define PRE_IMAGE
 #endif
 
-#define INITCALLS			\
+#define BAREBOX_INITCALLS			\
+	__barebox_initcalls_start = .;		\
 	KEEP(*(.initcall.0))			\
 	KEEP(*(.initcall.1))			\
 	KEEP(*(.initcall.2))			\
@@ -31,24 +32,39 @@
 	KEEP(*(.initcall.11))			\
 	KEEP(*(.initcall.12))			\
 	KEEP(*(.initcall.13))			\
-	KEEP(*(.initcall.14))
+	KEEP(*(.initcall.14))			\
+	__barebox_initcalls_end = .;
 
-#define EXITCALLS			\
+#define BAREBOX_EXITCALLS			\
+	__barebox_exitcalls_start = .;		\
 	KEEP(*(.exitcall.0))			\
 	KEEP(*(.exitcall.1))			\
 	KEEP(*(.exitcall.2))			\
 	KEEP(*(.exitcall.3))			\
 	KEEP(*(.exitcall.4))			\
 	KEEP(*(.exitcall.5))			\
-	KEEP(*(.exitcall.6))
-
-#define BAREBOX_CMDS	KEEP(*(SORT_BY_NAME(.barebox_cmd*)))
-
-#define BAREBOX_RATP_CMDS	KEEP(*(SORT_BY_NAME(.barebox_ratp_cmd*)))
-
-#define BAREBOX_SYMS	KEEP(*(__usymtab))
-
-#define BAREBOX_MAGICVARS	KEEP(*(SORT_BY_NAME(.barebox_magicvar*)))
+	KEEP(*(.exitcall.6))			\
+	__barebox_exitcalls_end = .;
+
+#define BAREBOX_CMDS				\
+	__barebox_cmd_start = .;		\
+	KEEP(*(SORT_BY_NAME(.barebox_cmd*)))	\
+	__barebox_cmd_end = .;
+
+#define BAREBOX_RATP_CMDS			\
+	__barebox_ratp_cmd_start = .;		\
+	KEEP(*(SORT_BY_NAME(.barebox_ratp_cmd*)))	\
+	__barebox_ratp_cmd_end = .;
+
+#define BAREBOX_SYMS				\
+	__usymtab_start = .;			\
+	KEEP(*(__usymtab))			\
+	__usymtab_end = .;
+
+#define BAREBOX_MAGICVARS			\
+	__barebox_magicvar_start = .;		\
+	KEEP(*(SORT_BY_NAME(.barebox_magicvar*)))	\
+	__barebox_magicvar_end = .;
 
 #define BAREBOX_CLK_TABLE			\
 	. = ALIGN(8);				\
-- 
2.23.0


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

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

* [PATCH 4/7] lds: create and use BAREBOX_PCI_FIXUP macro
  2019-10-02 14:44 [PATCH 0/7] Cleanup linker scripts Sascha Hauer
                   ` (2 preceding siblings ...)
  2019-10-02 14:44 ` [PATCH 3/7] lds: Move start/end address variables into defines Sascha Hauer
@ 2019-10-02 14:44 ` Sascha Hauer
  2019-10-02 14:44 ` [PATCH 5/7] X86: lds: remove unnecessary alignments Sascha Hauer
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2019-10-02 14:44 UTC (permalink / raw)
  To: Barebox List

No need to repeat the pci fixup sections in each linker script. Add a
define for it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib32/barebox.lds.S      | 15 +--------------
 arch/arm/lib64/barebox.lds.S      | 15 +--------------
 arch/mips/lib/barebox.lds.S       | 14 +-------------
 include/asm-generic/barebox.lds.h | 15 +++++++++++++++
 4 files changed, 18 insertions(+), 41 deletions(-)

diff --git a/arch/arm/lib32/barebox.lds.S b/arch/arm/lib32/barebox.lds.S
index 9ffcffd66d..3a19d8faab 100644
--- a/arch/arm/lib32/barebox.lds.S
+++ b/arch/arm/lib32/barebox.lds.S
@@ -88,21 +88,8 @@ SECTIONS
 	.barebox_initcalls : { BAREBOX_INITCALLS }
 	.barebox_exitcalls : { BAREBOX_EXITCALLS }
 	__usymtab : { BAREBOX_SYMS }
-
-#ifdef CONFIG_PCI
-	__start_pci_fixups_early = .;
-	.pci_fixup_early : { KEEP(*(.pci_fixup_early)) }
-	__end_pci_fixups_early = .;
-	__start_pci_fixups_header = .;
-	.pci_fixup_header : { KEEP(*(.pci_fixup_header)) }
-	__end_pci_fixups_header = .;
-	__start_pci_fixups_enable = .;
-	.pci_fixup_enable : { KEEP(*(.pci_fixup_enable)) }
-	__end_pci_fixups_enable = .;
-#endif
-
+	.pci_fixup : { BAREBOX_PCI_FIXUP }
 	.oftables : { BAREBOX_CLK_TABLE }
-
 	.dtb : { BAREBOX_DTB }
 
 	.rel_dyn_start : { *(.__rel_dyn_start) }
diff --git a/arch/arm/lib64/barebox.lds.S b/arch/arm/lib64/barebox.lds.S
index 1cc00eca11..3ad9d5f132 100644
--- a/arch/arm/lib64/barebox.lds.S
+++ b/arch/arm/lib64/barebox.lds.S
@@ -70,21 +70,8 @@ SECTIONS
 	.barebox_initcalls : { BAREBOX_INITCALLS }
 	.barebox_exitcalls : { BAREBOX_EXITCALLS }
 	__usymtab : { BAREBOX_SYMS }
-
-#ifdef CONFIG_PCI
-	__start_pci_fixups_early = .;
-	.pci_fixup_early : { KEEP(*(.pci_fixup_early)) }
-	__end_pci_fixups_early = .;
-	__start_pci_fixups_header = .;
-	.pci_fixup_header : { KEEP(*(.pci_fixup_header)) }
-	__end_pci_fixups_header = .;
-	__start_pci_fixups_enable = .;
-	.pci_fixup_enable : { KEEP(*(.pci_fixup_enable)) }
-	__end_pci_fixups_enable = .;
-#endif
-
+	.pci_fixup : { BAREBOX_PCI_FIXUP }
 	.oftables : { BAREBOX_CLK_TABLE }
-
 	.dtb : { BAREBOX_DTB }
 
 	.rel_dyn_start : { *(.__rel_dyn_start) }
diff --git a/arch/mips/lib/barebox.lds.S b/arch/mips/lib/barebox.lds.S
index 86a469a042..f9a0b44937 100644
--- a/arch/mips/lib/barebox.lds.S
+++ b/arch/mips/lib/barebox.lds.S
@@ -47,20 +47,8 @@ SECTIONS
 	.barebox_initcalls : { BAREBOX_INITCALLS }
 	.barebox_exitcalls : { BAREBOX_EXITCALLS }
 	__usymtab : { BAREBOX_SYMS }
-
-#ifdef CONFIG_PCI
-	__start_pci_fixups_early = .;
-	.pci_fixup_early : { KEEP(*(.pci_fixup_early)) }
-	__end_pci_fixups_early = .;
-	__start_pci_fixups_header = .;
-	.pci_fixup_header : { KEEP(*(.pci_fixup_header)) }
-	__end_pci_fixups_header = .;
-	__start_pci_fixups_enable = .;
-	.pci_fixup_enable : { KEEP(*(.pci_fixup_enable)) }
-	__end_pci_fixups_enable = .;
-#endif
+	.pci_fixup : { BAREBOX_PCI_FIXUP }
 	.oftables : { BAREBOX_CLK_TABLE }
-
 	.dtb : { BAREBOX_DTB }
 
 	_edata = .;
diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index 0784048eb6..2f8786356e 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -85,6 +85,21 @@
 	*(.barebox_imd_0*)			\
 	KEEP(*(.barebox_imd_end))
 
+#ifdef CONFIG_PCI
+#define BAREBOX_PCI_FIXUP			\
+	__start_pci_fixups_early = .;		\
+	KEEP(*(.pci_fixup_early))		\
+	__end_pci_fixups_early = .;		\
+	__start_pci_fixups_header = .;		\
+	KEEP(*(.pci_fixup_header))		\
+	__end_pci_fixups_header = .;		\
+	__start_pci_fixups_enable = .;		\
+	KEEP(*(.pci_fixup_enable))		\
+	__end_pci_fixups_enable = .;
+#else
+#define BAREBOX_PCI_FIXUP
+#endif
+
 #if defined(CONFIG_ARCH_BAREBOX_MAX_BARE_INIT_SIZE) && \
 CONFIG_ARCH_BAREBOX_MAX_BARE_INIT_SIZE < CONFIG_BAREBOX_MAX_BARE_INIT_SIZE
 #define MAX_BARE_INIT_SIZE CONFIG_ARCH_BAREBOX_MAX_BARE_INIT_SIZE
-- 
2.23.0


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

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

* [PATCH 5/7] X86: lds: remove unnecessary alignments
  2019-10-02 14:44 [PATCH 0/7] Cleanup linker scripts Sascha Hauer
                   ` (3 preceding siblings ...)
  2019-10-02 14:44 ` [PATCH 4/7] lds: create and use BAREBOX_PCI_FIXUP macro Sascha Hauer
@ 2019-10-02 14:44 ` Sascha Hauer
  2019-10-02 18:53   ` Sam Ravnborg
  2019-10-02 14:44 ` [PATCH 6/7] lds: remove more " Sascha Hauer
  2019-10-02 14:44 ` [PATCH 7/7] lds: Add and use RO_DATA_SECTION macro Sascha Hauer
  6 siblings, 1 reply; 13+ messages in thread
From: Sascha Hauer @ 2019-10-02 14:44 UTC (permalink / raw)
  To: Barebox List

We do not seem to need all these alignments in the rodata sections
except the one for the command array. Remove them and put the alignment
for the command array into the BAREBOX_CMDS define.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/sandbox/board/barebox.lds.S       | 8 --------
 arch/x86/mach-efi/elf_ia32_efi.lds.S   | 6 ------
 arch/x86/mach-efi/elf_x86_64_efi.lds.S | 6 ------
 include/asm-generic/barebox.lds.h      | 6 ++++++
 4 files changed, 6 insertions(+), 20 deletions(-)

diff --git a/arch/sandbox/board/barebox.lds.S b/arch/sandbox/board/barebox.lds.S
index bdce8ecbd6..862376dd0e 100644
--- a/arch/sandbox/board/barebox.lds.S
+++ b/arch/sandbox/board/barebox.lds.S
@@ -4,17 +4,9 @@ SECTIONS
 {
 	. = ALIGN(64);
 	.barebox_initcalls : { BAREBOX_INITCALLS }
-
-	. = ALIGN(64);
 	.barebox_exitcalls : { BAREBOX_EXITCALLS }
-
-	. = ALIGN(64);
 	.barebox_magicvar : { BAREBOX_MAGICVARS }
-
-	. = ALIGN(64);
 	__barebox_cmd : { BAREBOX_CMDS }
-
-	. = ALIGN(64);
 	__barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
 }
 
diff --git a/arch/x86/mach-efi/elf_ia32_efi.lds.S b/arch/x86/mach-efi/elf_ia32_efi.lds.S
index a5874c448b..70d34f4871 100644
--- a/arch/x86/mach-efi/elf_ia32_efi.lds.S
+++ b/arch/x86/mach-efi/elf_ia32_efi.lds.S
@@ -54,14 +54,8 @@ SECTIONS
 
 	.barebox_initcalls : { BAREBOX_INITCALLS }
 	.barebox_exitcalls : { BAREBOX_EXITCALLS }
-
-	. = ALIGN(64);
 	.barebox_magicvar : { BAREBOX_MAGICVARS }
-
-	. = ALIGN(64);
 	__barebox_cmd : { BAREBOX_CMDS }
-
-	. = ALIGN(64);
 	__barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
 
 	. = ALIGN(4096);
diff --git a/arch/x86/mach-efi/elf_x86_64_efi.lds.S b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
index b00cb98c97..53de22d75c 100644
--- a/arch/x86/mach-efi/elf_x86_64_efi.lds.S
+++ b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
@@ -56,14 +56,8 @@ SECTIONS
 
 	.barebox_initcalls : { BAREBOX_INITCALLS }
 	.barebox_exitcalls : { BAREBOX_EXITCALLS }
-
-	. = ALIGN(64);
 	.barebox_magicvar : { BAREBOX_MAGICVARS }
-
-	. = ALIGN(64);
 	__barebox_cmd : { BAREBOX_CMDS }
-
-	. = ALIGN(64);
 	__barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
 
 	. = ALIGN(4096);
diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index 2f8786356e..acf838e85f 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -46,7 +46,13 @@
 	KEEP(*(.exitcall.6))			\
 	__barebox_exitcalls_end = .;
 
+/* For some obscure reason X86_64 needs these 64bit aligned */
+#ifdef __x86_64__
+#define X86_64_ALIGN . = ALIGN(64);
+#endif
+
 #define BAREBOX_CMDS				\
+	X86_64_ALIGN				\
 	__barebox_cmd_start = .;		\
 	KEEP(*(SORT_BY_NAME(.barebox_cmd*)))	\
 	__barebox_cmd_end = .;
-- 
2.23.0


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

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

* [PATCH 6/7] lds: remove more unnecessary alignments
  2019-10-02 14:44 [PATCH 0/7] Cleanup linker scripts Sascha Hauer
                   ` (4 preceding siblings ...)
  2019-10-02 14:44 ` [PATCH 5/7] X86: lds: remove unnecessary alignments Sascha Hauer
@ 2019-10-02 14:44 ` Sascha Hauer
  2019-10-02 18:55   ` Sam Ravnborg
  2019-10-02 14:44 ` [PATCH 7/7] lds: Add and use RO_DATA_SECTION macro Sascha Hauer
  6 siblings, 1 reply; 13+ messages in thread
From: Sascha Hauer @ 2019-10-02 14:44 UTC (permalink / raw)
  To: Barebox List

The alignemnt in the DTB and clk_of_table shouldn't be needed. Remove
them.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/asm-generic/barebox.lds.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index acf838e85f..a3e367c9ed 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -73,14 +73,12 @@
 	__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 = .;
-- 
2.23.0


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

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

* [PATCH 7/7] lds: Add and use RO_DATA_SECTION macro
  2019-10-02 14:44 [PATCH 0/7] Cleanup linker scripts Sascha Hauer
                   ` (5 preceding siblings ...)
  2019-10-02 14:44 ` [PATCH 6/7] lds: remove more " Sascha Hauer
@ 2019-10-02 14:44 ` Sascha Hauer
  6 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2019-10-02 14:44 UTC (permalink / raw)
  To: Barebox List

We have many different pointer arrays which we put into linker sections
and each time there's one added we have to adjust all linker scripts.
This adds a common RO_DATA_SECTION define and uses it for all
architectures. This makes it easier to add a new linker array.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib32/barebox.lds.S           | 14 ++++--------
 arch/arm/lib64/barebox.lds.S           | 16 ++++---------
 arch/mips/lib/barebox.lds.S            | 16 ++++---------
 arch/nios2/cpu/barebox.lds.S           | 12 ++++------
 arch/openrisc/cpu/barebox.lds.S        | 11 +--------
 arch/ppc/boards/pcm030/barebox.lds.S   |  9 +-------
 arch/ppc/mach-mpc85xx/barebox.lds.S    |  8 +------
 arch/riscv/lib/barebox.lds.S           | 12 ++++------
 arch/sandbox/board/barebox.lds.S       |  8 +++----
 arch/x86/lib/barebox.lds.S             | 31 +-------------------------
 arch/x86/mach-efi/elf_ia32_efi.lds.S   |  9 +-------
 arch/x86/mach-efi/elf_x86_64_efi.lds.S |  9 +-------
 include/asm-generic/barebox.lds.h      | 11 +++++++++
 13 files changed, 40 insertions(+), 126 deletions(-)

diff --git a/arch/arm/lib32/barebox.lds.S b/arch/arm/lib32/barebox.lds.S
index 3a19d8faab..c479e02e91 100644
--- a/arch/arm/lib32/barebox.lds.S
+++ b/arch/arm/lib32/barebox.lds.S
@@ -55,7 +55,10 @@ SECTIONS
 	BAREBOX_BARE_INIT_SIZE
 
 	. = ALIGN(4);
-	.rodata : { *(.rodata*) }
+	.rodata : {
+		*(.rodata*)
+		RO_DATA_SECTION
+	}
 
 #ifdef CONFIG_ARM_UNWIND
 	/*
@@ -82,15 +85,6 @@ SECTIONS
 	.barebox_imd : { BAREBOX_IMD }
 
 	. = .;
-	.barebox_cmd : { BAREBOX_CMDS }
-	.barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	.barebox_initcalls : { BAREBOX_INITCALLS }
-	.barebox_exitcalls : { BAREBOX_EXITCALLS }
-	__usymtab : { BAREBOX_SYMS }
-	.pci_fixup : { BAREBOX_PCI_FIXUP }
-	.oftables : { BAREBOX_CLK_TABLE }
-	.dtb : { BAREBOX_DTB }
 
 	.rel_dyn_start : { *(.__rel_dyn_start) }
 	.rel.dyn : { *(.rel*) }
diff --git a/arch/arm/lib64/barebox.lds.S b/arch/arm/lib64/barebox.lds.S
index 3ad9d5f132..cf6ef18895 100644
--- a/arch/arm/lib64/barebox.lds.S
+++ b/arch/arm/lib64/barebox.lds.S
@@ -53,7 +53,10 @@ SECTIONS
 	BAREBOX_BARE_INIT_SIZE
 
 	. = ALIGN(4);
-	.rodata : { *(.rodata*) }
+	.rodata : {
+		*(.rodata*)
+		RO_DATA_SECTION
+	}
 
 	_etext = .;			/* End of text and rodata section */
 	_sdata = .;
@@ -63,17 +66,6 @@ SECTIONS
 
 	.barebox_imd : { BAREBOX_IMD }
 
-	. = .;
-	.barebox_cmd : { BAREBOX_CMDS }
-	.barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	.barebox_initcalls : { BAREBOX_INITCALLS }
-	.barebox_exitcalls : { BAREBOX_EXITCALLS }
-	__usymtab : { BAREBOX_SYMS }
-	.pci_fixup : { BAREBOX_PCI_FIXUP }
-	.oftables : { BAREBOX_CLK_TABLE }
-	.dtb : { BAREBOX_DTB }
-
 	.rel_dyn_start : { *(.__rel_dyn_start) }
 	.rela.dyn : { *(.rela*) }
 	.rel_dyn_end : { *(.__rel_dyn_end) }
diff --git a/arch/mips/lib/barebox.lds.S b/arch/mips/lib/barebox.lds.S
index f9a0b44937..e96c3bf6e2 100644
--- a/arch/mips/lib/barebox.lds.S
+++ b/arch/mips/lib/barebox.lds.S
@@ -30,7 +30,10 @@ SECTIONS
 	PRE_IMAGE
 
 	. = ALIGN(4);
-	.rodata : { *(.rodata*) }
+	.rodata : {
+		*(.rodata*)
+		RO_DATA_SECTION
+	}
 
 	_etext = .;			/* End of text and rodata section */
 	_sdata = .;
@@ -40,17 +43,6 @@ SECTIONS
 
 	.barebox_imd : { BAREBOX_IMD }
 
-	. = .;
-	.barebox_cmd : { BAREBOX_CMDS }
-	.barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	.barebox_initcalls : { BAREBOX_INITCALLS }
-	.barebox_exitcalls : { BAREBOX_EXITCALLS }
-	__usymtab : { BAREBOX_SYMS }
-	.pci_fixup : { BAREBOX_PCI_FIXUP }
-	.oftables : { BAREBOX_CLK_TABLE }
-	.dtb : { BAREBOX_DTB }
-
 	_edata = .;
 	.image_end : { *(.__image_end) }
 
diff --git a/arch/nios2/cpu/barebox.lds.S b/arch/nios2/cpu/barebox.lds.S
index efe8e106a1..8d82aa59e7 100644
--- a/arch/nios2/cpu/barebox.lds.S
+++ b/arch/nios2/cpu/barebox.lds.S
@@ -48,15 +48,11 @@ SECTIONS
 	BAREBOX_BARE_INIT_SIZE
 
 	. = ALIGN(4);
-	.rodata : { *(.rodata) }
 
-	. = .;
-	.barebox_cmd : { BAREBOX_CMDS }
-	.barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	.barebox_initcalls : { BAREBOX_INITCALLS }
-	.barebox_exitcalls : { BAREBOX_EXITCALLS }
-	__usymtab : { BAREBOX_SYMS }
+	.rodata : {
+		*(.rodata*)
+		RO_DATA_SECTION
+	}
 
 	_etext = .; /* End of text and rodata section */
 
diff --git a/arch/openrisc/cpu/barebox.lds.S b/arch/openrisc/cpu/barebox.lds.S
index 37242f9c5e..adb0c22f85 100644
--- a/arch/openrisc/cpu/barebox.lds.S
+++ b/arch/openrisc/cpu/barebox.lds.S
@@ -49,18 +49,9 @@ SECTIONS
 		*(.rodata);
 		*(.rodata.*)
 		*(.bbenv.rodata.*)
+		RO_DATA_SECTION
 	} > ram
 
-	. = ALIGN(4);
-	. = .;
-	.barebox_cmd : { BAREBOX_CMDS } > ram
-	.barebox_ratp_cmd : { BAREBOX_RATP_CMDS } > ram
-	.barebox_magicvar : { BAREBOX_MAGICVARS } > ram
-	.barebox_initcalls : { BAREBOX_INITCALLS } > ram
-	.barebox_exitcalls : { BAREBOX_EXITCALLS } > ram
-	__usymtab : { BAREBOX_SYMS } > ram
-	.dtb : { BAREBOX_DTB } > ram
-
 	__etext = .; /* End of text and rodata section */
 
 	. = ALIGN(4);
diff --git a/arch/ppc/boards/pcm030/barebox.lds.S b/arch/ppc/boards/pcm030/barebox.lds.S
index 73e4bde434..6c91ed6256 100644
--- a/arch/ppc/boards/pcm030/barebox.lds.S
+++ b/arch/ppc/boards/pcm030/barebox.lds.S
@@ -38,6 +38,7 @@ SECTIONS
     *(.rodata*)
     *(.rodata1*)
     *(.rodata.str1.4)
+    RO_DATA_SECTION
   }
 
   /* Read-only sections, merged into text segment: */
@@ -99,14 +100,6 @@ SECTIONS
   _edata  =  .;
   PROVIDE (edata = .);
 
-  . = .;
-  .barebox_cmd : { BAREBOX_CMDS }
-  .barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-  .barebox_magicvar : { BAREBOX_MAGICVARS }
-  .barebox_initcalls : { BAREBOX_INITCALLS }
-  .barebox_exitcalls : { BAREBOX_EXITCALLS }
-  __usymtab : { BAREBOX_SYMS }
-
   __start___ex_table = .;
   __ex_table : { *(__ex_table) }
   __stop___ex_table = .;
diff --git a/arch/ppc/mach-mpc85xx/barebox.lds.S b/arch/ppc/mach-mpc85xx/barebox.lds.S
index 1874319e71..a09a01eba1 100644
--- a/arch/ppc/mach-mpc85xx/barebox.lds.S
+++ b/arch/ppc/mach-mpc85xx/barebox.lds.S
@@ -71,6 +71,7 @@ SECTIONS
    .rodata    :
    {
     *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*)))
+    RO_DATA_SECTION
   } :text
 
   /* Read-write section, merged into data segment: */
@@ -100,13 +101,6 @@ SECTIONS
     CONSTRUCTORS
   }
 
-  . = .;
-  .barebox_cmd : { BAREBOX_CMDS }
-  .barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-  .barebox_initcalls : { BAREBOX_INITCALLS }
-  .barebox_exitcalls : { BAREBOX_EXITCALLS }
-  __usymtab : { BAREBOX_SYMS }
-
   . = .;
   __start___ex_table = .;
   __ex_table : { *(__ex_table) }
diff --git a/arch/riscv/lib/barebox.lds.S b/arch/riscv/lib/barebox.lds.S
index 23e4468e2f..5149f8ce28 100644
--- a/arch/riscv/lib/barebox.lds.S
+++ b/arch/riscv/lib/barebox.lds.S
@@ -30,7 +30,10 @@ SECTIONS
 	}
 
 	. = ALIGN(8);
-	.rodata : { *(.rodata*) }
+	.rodata : {
+		*(.rodata*)
+		RO_DATA_SECTION
+	}
 
 	_etext = .;			/* End of text and rodata section */
 	_sdata = .;
@@ -43,13 +46,6 @@ SECTIONS
 	. = ALIGN(8);
 	.got : { *(.got*) }
 
-	. = .;
-	.barebox_cmd : { BAREBOX_CMDS }
-	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	.barebox_initcalls : { BAREBOX_INITCALLS }
-	.barebox_exitcalls : { BAREBOX_EXITCALLS }
-	__usymtab : { BAREBOX_SYMS }
-
 	.rela.dyn : { *(.rela*) }
 
 	.oftables : { BAREBOX_CLK_TABLE }
diff --git a/arch/sandbox/board/barebox.lds.S b/arch/sandbox/board/barebox.lds.S
index 862376dd0e..7a5a8eb1e7 100644
--- a/arch/sandbox/board/barebox.lds.S
+++ b/arch/sandbox/board/barebox.lds.S
@@ -3,11 +3,9 @@
 SECTIONS
 {
 	. = ALIGN(64);
-	.barebox_initcalls : { BAREBOX_INITCALLS }
-	.barebox_exitcalls : { BAREBOX_EXITCALLS }
-	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	__barebox_cmd : { BAREBOX_CMDS }
-	__barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
+	.barebox_rodata : {
+		RO_DATA_SECTION
+	}
 }
 
 INSERT BEFORE .rodata;
diff --git a/arch/x86/lib/barebox.lds.S b/arch/x86/lib/barebox.lds.S
index d26f060a3e..71251642dc 100644
--- a/arch/x86/lib/barebox.lds.S
+++ b/arch/x86/lib/barebox.lds.S
@@ -133,6 +133,7 @@ SECTIONS
 		*(.boot.rodata*)
 		*(.boot.data*)
 		. = ALIGN(4);
+		RO_DATA_SECTION
 	} > barebox
 #endif
 
@@ -164,36 +165,6 @@ SECTIONS
 		. = ALIGN(4);
 	} > barebox
 
-	.barebox_cmd : AT ( LOADADDR(.got) + SIZEOF (.got) ) {
-		BAREBOX_CMDS
-		. = ALIGN(4);
-	} > barebox
-
-	.barebox_ratp_cmd : AT ( LOADADDR(.got) + SIZEOF (.got) ) {
-		BAREBOX_RATP_CMDS
-		. = ALIGN(4);
-	} > barebox
-
-	.barebox_magicvars : AT ( LOADADDR(.barebox_cmd) + SIZEOF (.barebox_cmd) ) {
-		BAREBOX_MAGICVARS
-		. = ALIGN(4);
-	} > barebox
-
-	.barebox_initcalls : AT ( LOADADDR(.barebox_magicvars) + SIZEOF (.barebox_magicvars) ) {
-		BAREBOX_INITCALLS
-		. = ALIGN(4);
-	} > barebox
-
-	.barebox_exitcalls : AT ( LOADADDR(.barebox_initcalls) + SIZEOF (.barebox_initcalls) ) {
-		BAREBOX_EXITCALLS
-		. = ALIGN(4);
-	} > barebox
-
-	.__usymtab : AT ( LOADADDR(.barebox_exitcalls) + SIZEOF (.barebox_exitcalls) ) {
-		BAREBOX_SYMS
-		. = ALIGN(4);
-	} > barebox
-
 	_edata = .;
 	.bss : {
 		__bss_start = .;
diff --git a/arch/x86/mach-efi/elf_ia32_efi.lds.S b/arch/x86/mach-efi/elf_ia32_efi.lds.S
index 70d34f4871..18ddf17802 100644
--- a/arch/x86/mach-efi/elf_ia32_efi.lds.S
+++ b/arch/x86/mach-efi/elf_ia32_efi.lds.S
@@ -35,6 +35,7 @@ SECTIONS
 
 	.data : {
 		*(.rodata*)
+		RO_DATA_SECTION
 		*(.data)
 		*(.data1)
 		*(.data.*)
@@ -50,14 +51,6 @@ SECTIONS
 		*(COMMON)
 	}
 
-	. = ALIGN(64);
-
-	.barebox_initcalls : { BAREBOX_INITCALLS }
-	.barebox_exitcalls : { BAREBOX_EXITCALLS }
-	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	__barebox_cmd : { BAREBOX_CMDS }
-	__barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-
 	. = ALIGN(4096);
 	.dynamic : { *(.dynamic) }
 	. = ALIGN(4096);
diff --git a/arch/x86/mach-efi/elf_x86_64_efi.lds.S b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
index 53de22d75c..40a9425034 100644
--- a/arch/x86/mach-efi/elf_x86_64_efi.lds.S
+++ b/arch/x86/mach-efi/elf_x86_64_efi.lds.S
@@ -38,6 +38,7 @@ SECTIONS
 
 	.data : {
 		*(.rodata*)
+		RO_DATA_SECTION
 		*(.got.plt)
 		*(.got)
 		*(.data*)
@@ -52,14 +53,6 @@ SECTIONS
 		*(.rel.local)
 	}
 
-	. = ALIGN(64);
-
-	.barebox_initcalls : { BAREBOX_INITCALLS }
-	.barebox_exitcalls : { BAREBOX_EXITCALLS }
-	.barebox_magicvar : { BAREBOX_MAGICVARS }
-	__barebox_cmd : { BAREBOX_CMDS }
-	__barebox_ratp_cmd : { BAREBOX_RATP_CMDS }
-
 	. = ALIGN(4096);
 	.dynamic : { *(.dynamic) }
 	. = ALIGN(4096);
diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index a3e367c9ed..491f879c8d 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -104,6 +104,17 @@
 #define BAREBOX_PCI_FIXUP
 #endif
 
+#define RO_DATA_SECTION				\
+	BAREBOX_INITCALLS			\
+	BAREBOX_EXITCALLS			\
+	BAREBOX_CMDS				\
+	BAREBOX_RATP_CMDS			\
+	BAREBOX_SYMS				\
+	BAREBOX_MAGICVARS			\
+	BAREBOX_CLK_TABLE			\
+	BAREBOX_DTB				\
+	BAREBOX_PCI_FIXUP
+
 #if defined(CONFIG_ARCH_BAREBOX_MAX_BARE_INIT_SIZE) && \
 CONFIG_ARCH_BAREBOX_MAX_BARE_INIT_SIZE < CONFIG_BAREBOX_MAX_BARE_INIT_SIZE
 #define MAX_BARE_INIT_SIZE CONFIG_ARCH_BAREBOX_MAX_BARE_INIT_SIZE
-- 
2.23.0


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

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

* Re: [PATCH 3/7] lds: Move start/end address variables into defines
  2019-10-02 14:44 ` [PATCH 3/7] lds: Move start/end address variables into defines Sascha Hauer
@ 2019-10-02 18:46   ` Sam Ravnborg
  0 siblings, 0 replies; 13+ messages in thread
From: Sam Ravnborg @ 2019-10-02 18:46 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

Hi Sascha.

On Wed, Oct 02, 2019 at 04:44:26PM +0200, Sascha Hauer wrote:
> For the older section defines we specify the start and end addresses
> outside the macro which means we have to repeat them in each linker
> script. Make the start/end addresses part of the define to simplify
> things.

A positive side effect is that if the linker insert some alignment
then the variable will have the correct value.
I recall that I in the kernel was hit by a variable that was off by a
few bytes due to extra alignment added by the linker.
And ofc only in some configurations.

Looked through the patch but no testing.

	Sam

Acked-by: Sam Ravnborg <sam@ravnborg.org>

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

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

* Re: [PATCH 5/7] X86: lds: remove unnecessary alignments
  2019-10-02 14:44 ` [PATCH 5/7] X86: lds: remove unnecessary alignments Sascha Hauer
@ 2019-10-02 18:53   ` Sam Ravnborg
  2019-10-14 10:05     ` [PATCH] command: Use array of pointers to commands Sascha Hauer
  2019-10-14 10:08     ` [PATCH 5/7] X86: lds: remove unnecessary alignments Sascha Hauer
  0 siblings, 2 replies; 13+ messages in thread
From: Sam Ravnborg @ 2019-10-02 18:53 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

Hi Sascha.

On Wed, Oct 02, 2019 at 04:44:28PM +0200, Sascha Hauer wrote:
> We do not seem to need all these alignments in the rodata sections
> except the one for the command array. Remove them and put the alignment
> for the command array into the BAREBOX_CMDS define.

The changelog does not match the code.
The alignment is only for x86_64.

> --- a/include/asm-generic/barebox.lds.h
> +++ b/include/asm-generic/barebox.lds.h
> @@ -46,7 +46,13 @@
>  	KEEP(*(.exitcall.6))			\
>  	__barebox_exitcalls_end = .;
>  
> +/* For some obscure reason X86_64 needs these 64bit aligned */

The obscure reason looks like this (from include/command.h):
#ifdef __x86_64__
/* This is required because the linker will put symbols on a 64 bit alignment */
__attribute__((aligned(64)))
#endif

I did not try it. But I would assume removing the alignment from the .h
file and the .lds file would sort it out.


	Sam


> +#ifdef __x86_64__
> +#define X86_64_ALIGN . = ALIGN(64);
> +#endif
> +
>  #define BAREBOX_CMDS				\
> +	X86_64_ALIGN				\
>  	__barebox_cmd_start = .;		\
>  	KEEP(*(SORT_BY_NAME(.barebox_cmd*)))	\
>  	__barebox_cmd_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] 13+ messages in thread

* Re: [PATCH 6/7] lds: remove more unnecessary alignments
  2019-10-02 14:44 ` [PATCH 6/7] lds: remove more " Sascha Hauer
@ 2019-10-02 18:55   ` Sam Ravnborg
  0 siblings, 0 replies; 13+ messages in thread
From: Sam Ravnborg @ 2019-10-02 18:55 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

Hi Sascha.

On Wed, Oct 02, 2019 at 04:44:29PM +0200, Sascha Hauer wrote:
> The alignemnt in the DTB and clk_of_table shouldn't be needed. Remove
s/alignemnt/alignment/g

I do this type of spelling error all the time :-(

	Sam

Acked-by: Sam Ravnborg <sam@ravnborg.org>

> them.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  include/asm-generic/barebox.lds.h | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
> index acf838e85f..a3e367c9ed 100644
> --- a/include/asm-generic/barebox.lds.h
> +++ b/include/asm-generic/barebox.lds.h
> @@ -73,14 +73,12 @@
>  	__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 = .;
> -- 
> 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] 13+ messages in thread

* [PATCH] command: Use array of pointers to commands
  2019-10-02 18:53   ` Sam Ravnborg
@ 2019-10-14 10:05     ` Sascha Hauer
  2019-10-14 10:08     ` [PATCH 5/7] X86: lds: remove unnecessary alignments Sascha Hauer
  1 sibling, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2019-10-14 10:05 UTC (permalink / raw)
  To: Barebox List

We used to store the commands as a linker array. One problem with this
is that on X86_64 for unknown reasons the linker uses a different struct
alignment than the compiler, so when we use the linker to compose the
array and the compiler to iterate over it we have to play tricks with
manually adjusting the alignment. The other problem is that we declare
the commands as const (and also put it in .rodata), but in fact we do
not treat it as const: we put the commands onto a list which modifies
the struct list_head list member of struct command.

With this patch we no longer put the command themselves into an array,
but instead create an array of pointers to the commands. This inherently
solves the second issue as well.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/command.c  |  8 ++++----
 include/command.h | 21 +++++++++------------
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/common/command.c b/common/command.c
index d9cc4a6d48..49845938ae 100644
--- a/common/command.c
+++ b/common/command.c
@@ -149,12 +149,12 @@ EXPORT_SYMBOL(find_cmd);
  */
 static int init_command_list(void)
 {
-	struct command *cmdtp;
+	struct command * const *cmdtp;
 
-	for (cmdtp = &__barebox_cmd_start;
-			cmdtp != &__barebox_cmd_end;
+	for (cmdtp = __barebox_cmd_start;
+			cmdtp != __barebox_cmd_end;
 			cmdtp++)
-		register_command(cmdtp);
+		register_command(*cmdtp);
 
 	return 0;
 }
diff --git a/include/command.h b/include/command.h
index 0afc5c7550..7555d0053c 100644
--- a/include/command.h
+++ b/include/command.h
@@ -53,15 +53,10 @@ struct command {
 	const char	*help;		/* Help  message	(long)	*/
 	void		(*usage)(void);
 #endif
-}
-#ifdef __x86_64__
-/* This is required because the linker will put symbols on a 64 bit alignment */
-__attribute__((aligned(64)))
-#endif
-;
+};
 
-extern struct command __barebox_cmd_start;
-extern struct command __barebox_cmd_end;
+extern struct command * const __barebox_cmd_start[];
+extern struct command * const __barebox_cmd_end[];
 
 
 /* common/command.c */
@@ -89,10 +84,12 @@ int run_command(const char *cmd);
 
 #endif	/* __ASSEMBLY__ */
 
-#define BAREBOX_CMD_START(_name)							\
-extern const struct command __barebox_cmd_##_name;					\
-const struct command __barebox_cmd_##_name						\
-	__attribute__ ((unused,section (".barebox_cmd_" __stringify(_name)))) = {	\
+#define BAREBOX_CMD_START(_name)						\
+static struct command __barebox_cmd_##_name;					\
+const struct command *barebox_cmd_##_name 					\
+	__attribute__ ((unused,section (".barebox_cmd_" __stringify(_name))))	\
+			= &__barebox_cmd_##_name;				\
+static struct command __barebox_cmd_##_name = {					\
 	.name		= #_name,
 
 #define BAREBOX_CMD_END					\
-- 
2.23.0


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

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

* Re: [PATCH 5/7] X86: lds: remove unnecessary alignments
  2019-10-02 18:53   ` Sam Ravnborg
  2019-10-14 10:05     ` [PATCH] command: Use array of pointers to commands Sascha Hauer
@ 2019-10-14 10:08     ` Sascha Hauer
  1 sibling, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2019-10-14 10:08 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: Barebox List

Hi Sam,

On Wed, Oct 02, 2019 at 08:53:37PM +0200, Sam Ravnborg wrote:
> Hi Sascha.
> 
> On Wed, Oct 02, 2019 at 04:44:28PM +0200, Sascha Hauer wrote:
> > We do not seem to need all these alignments in the rodata sections
> > except the one for the command array. Remove them and put the alignment
> > for the command array into the BAREBOX_CMDS define.
> 
> The changelog does not match the code.
> The alignment is only for x86_64.
> 
> > --- a/include/asm-generic/barebox.lds.h
> > +++ b/include/asm-generic/barebox.lds.h
> > @@ -46,7 +46,13 @@
> >  	KEEP(*(.exitcall.6))			\
> >  	__barebox_exitcalls_end = .;
> >  
> > +/* For some obscure reason X86_64 needs these 64bit aligned */
> 
> The obscure reason looks like this (from include/command.h):
> #ifdef __x86_64__
> /* This is required because the linker will put symbols on a 64 bit alignment */
> __attribute__((aligned(64)))
> #endif
> 
> I did not try it. But I would assume removing the alignment from the .h
> file and the .lds file would sort it out.

Unfortunately it doesn't. I still don't fully understand this, but the
linker uses a different alignment for the array as the compiler does.

I chose to go a different way and have created an array of pointers to
the commands rather than putting the commands directly into an array.
This seems to solve it without playing aligmnent tricks.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

end of thread, other threads:[~2019-10-14 10:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-02 14:44 [PATCH 0/7] Cleanup linker scripts Sascha Hauer
2019-10-02 14:44 ` [PATCH 1/7] barebox.lds: Remove unnecessary braces Sascha Hauer
2019-10-02 14:44 ` [PATCH 2/7] ppc: remove unused variables from linker scripts Sascha Hauer
2019-10-02 14:44 ` [PATCH 3/7] lds: Move start/end address variables into defines Sascha Hauer
2019-10-02 18:46   ` Sam Ravnborg
2019-10-02 14:44 ` [PATCH 4/7] lds: create and use BAREBOX_PCI_FIXUP macro Sascha Hauer
2019-10-02 14:44 ` [PATCH 5/7] X86: lds: remove unnecessary alignments Sascha Hauer
2019-10-02 18:53   ` Sam Ravnborg
2019-10-14 10:05     ` [PATCH] command: Use array of pointers to commands Sascha Hauer
2019-10-14 10:08     ` [PATCH 5/7] X86: lds: remove unnecessary alignments Sascha Hauer
2019-10-02 14:44 ` [PATCH 6/7] lds: remove more " Sascha Hauer
2019-10-02 18:55   ` Sam Ravnborg
2019-10-02 14:44 ` [PATCH 7/7] lds: Add and use RO_DATA_SECTION macro Sascha Hauer

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