From 1134e59bd2463371868c7e7ce023720b9ca4f04d Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Fri, 19 Oct 2018 10:15:19 -0700 Subject: [PATCH] linker: allow SoC to insert linker script fragments This allows the SoC to specify some additional linker script fragments into the bss, data and read-only data sections. For example, the Cypress PSOC6 has a few input sections that must be put into bss and data sections. Without specifying these in the linker script, they are consider orphan sections and the placement is based on linker heuristic which is arbitrary. POSIX is not supported as the main linker script is provided by the host system's binutils and we have no control over it. Also, currently Xtensa SoCs have their own linker scripts so there is no need to this feature. Signed-off-by: Daniel Leung --- include/arch/arc/v2/linker.ld | 12 +++++++ include/arch/arm/cortex_m/scripts/linker.ld | 12 +++++++ include/arch/nios2/linker.ld | 13 ++++++++ include/arch/riscv32/common/linker.ld | 14 ++++++++ include/arch/riscv32/pulpino/linker.ld | 14 ++++++++ include/arch/x86/linker.ld | 12 +++++++ soc/Kconfig | 36 +++++++++++++++++++++ 7 files changed, 113 insertions(+) diff --git a/include/arch/arc/v2/linker.ld b/include/arch/arc/v2/linker.ld index 67f7856d6202..8702c34dbbcd 100644 --- a/include/arch/arc/v2/linker.ld +++ b/include/arch/arc/v2/linker.ld @@ -107,6 +107,10 @@ SECTIONS { *(".rodata.*") *(.gnu.linkonce.r.*) +#ifdef CONFIG_SOC_RODATA_LD +#include +#endif + #ifdef CONFIG_CUSTOM_RODATA_LD /* Located in project source directory */ #include @@ -228,6 +232,10 @@ SECTIONS { KERNEL_INPUT_SECTION(".noinit.*") *(".kernel_noinit.*") +#ifdef CONFIG_SOC_NOINIT_LD +#include +#endif + } GROUP_LINK_IN(RAMABLE_REGION) SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,) { @@ -238,6 +246,10 @@ SECTIONS { KERNEL_INPUT_SECTION(".data.*") *(".kernel.*") +#ifdef CONFIG_SOC_RWDATA_LD +#include +#endif + #ifdef CONFIG_CUSTOM_RWDATA_LD /* Located in project source directory */ #include diff --git a/include/arch/arm/cortex_m/scripts/linker.ld b/include/arch/arm/cortex_m/scripts/linker.ld index 5c6656761934..90d8cca5e0e2 100644 --- a/include/arch/arm/cortex_m/scripts/linker.ld +++ b/include/arch/arm/cortex_m/scripts/linker.ld @@ -163,6 +163,10 @@ SECTIONS *(".rodata.*") *(.gnu.linkonce.r.*) +#ifdef CONFIG_SOC_RODATA_LD +#include +#endif + #ifdef CONFIG_CUSTOM_RODATA_LD /* Located in project source directory */ #include @@ -330,6 +334,10 @@ SECTIONS KERNEL_INPUT_SECTION(".noinit.*") *(".kernel_noinit.*") +#ifdef CONFIG_SOC_NOINIT_LD +#include +#endif + } GROUP_LINK_IN(RAMABLE_REGION) SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,) @@ -339,6 +347,10 @@ SECTIONS KERNEL_INPUT_SECTION(".data.*") *(".kernel.*") +#ifdef CONFIG_SOC_RWDATA_LD +#include +#endif + #ifdef CONFIG_CUSTOM_RWDATA_LD /* Located in project source directory */ #include diff --git a/include/arch/nios2/linker.ld b/include/arch/nios2/linker.ld index 67c3f3239e61..a3918476c930 100644 --- a/include/arch/nios2/linker.ld +++ b/include/arch/nios2/linker.ld @@ -128,6 +128,10 @@ SECTIONS *(".rodata.*") *(.gnu.linkonce.r.*) +#ifdef CONFIG_SOC_RODATA_LD +#include +#endif + #ifdef CONFIG_CUSTOM_RODATA_LD /* Located in project source directory */ #include @@ -174,6 +178,10 @@ SECTIONS *(.data) *(".data.*") +#ifdef CONFIG_SOC_RWDATA_LD +#include +#endif + #ifdef CONFIG_CUSTOM_RWDATA_LD /* Located in project source directory */ #include @@ -231,6 +239,11 @@ SECTIONS */ *(.noinit) *(".noinit.*") + +#ifdef CONFIG_SOC_NOINIT_LD +#include +#endif + } GROUP_LINK_IN(RAMABLE_REGION) /* Define linker symbols */ diff --git a/include/arch/riscv32/common/linker.ld b/include/arch/riscv32/common/linker.ld index 01b6bd2c29f2..ee85d6ef69d6 100644 --- a/include/arch/riscv32/common/linker.ld +++ b/include/arch/riscv32/common/linker.ld @@ -96,6 +96,11 @@ SECTIONS *(.rodata) *(".rodata.*") *(.gnu.linkonce.r.*) + +#ifdef CONFIG_SOC_RODATA_LD +#include +#endif + } GROUP_LINK_IN(ROMABLE_REGION) _image_rom_end = .; @@ -117,6 +122,10 @@ SECTIONS *(.sdata .sdata.* .gnu.linkonce.s.*) *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) +#ifdef CONFIG_SOC_RWDATA_LD +#include +#endif + } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) #include @@ -151,6 +160,11 @@ SECTIONS */ *(.noinit) *(".noinit.*") + +#ifdef CONFIG_SOC_NOINIT_LD +#include +#endif + } GROUP_LINK_IN(RAMABLE_REGION) _image_ram_end = .; diff --git a/include/arch/riscv32/pulpino/linker.ld b/include/arch/riscv32/pulpino/linker.ld index ffd473ca9d68..c4e74a570ab9 100644 --- a/include/arch/riscv32/pulpino/linker.ld +++ b/include/arch/riscv32/pulpino/linker.ld @@ -90,6 +90,11 @@ SECTIONS *(.rodata) *(".rodata.*") *(.gnu.linkonce.r.*) + +#ifdef CONFIG_SOC_RODATA_LD +#include +#endif + } GROUP_LINK_IN(RAMABLE_REGION) _image_ram_start = .; @@ -106,6 +111,10 @@ SECTIONS *(.sdata .sdata.* .gnu.linkonce.s.*) *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) +#ifdef CONFIG_SOC_RWDATA_LD +#include +#endif + } GROUP_LINK_IN(RAMABLE_REGION) SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),) @@ -136,6 +145,11 @@ SECTIONS */ *(.noinit) *(".noinit.*") + +#ifdef CONFIG_SOC_NOINIT_LD +#include +#endif + } GROUP_LINK_IN(RAMABLE_REGION) _image_ram_end = .; diff --git a/include/arch/x86/linker.ld b/include/arch/x86/linker.ld index 184b4e1822a7..f3d0e1973519 100644 --- a/include/arch/x86/linker.ld +++ b/include/arch/x86/linker.ld @@ -132,6 +132,10 @@ SECTIONS #endif #endif +#ifdef CONFIG_SOC_RODATA_LD +#include +#endif + #ifdef CONFIG_CUSTOM_RODATA_LD /* Located in project source directory */ #include @@ -244,6 +248,10 @@ SECTIONS KERNEL_INPUT_SECTION(".noinit.*") *(".kernel_noinit.*") +#ifdef CONFIG_SOC_NOINIT_LD +#include +#endif + MMU_PAGE_ALIGN } GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION) @@ -257,6 +265,10 @@ SECTIONS KERNEL_INPUT_SECTION(".data.*") *(".kernel.*") +#ifdef CONFIG_SOC_RWDATA_LD +#include +#endif + #ifdef CONFIG_CUSTOM_RWDATA_LD /* Located in project source directory */ #include diff --git a/soc/Kconfig b/soc/Kconfig index 69fc7cb3ff89..42ecbefe1c84 100644 --- a/soc/Kconfig +++ b/soc/Kconfig @@ -29,3 +29,39 @@ config SOC_COMPATIBLE_NRF52X config SOC_COMPATIBLE_NRF52832 bool + +# +# SOC_*_LD: SoC specific Linker script additions +# +config SOC_NOINIT_LD + bool + depends on (ARC || ARM || X86 || NIOS2 || RISCV32) + help + Include an SoC specific linker script fragment named soc-noinit.ld + for inserting additional data and linker directives into + the noinit section. + + This only has effect if the SoC uses the common linker script + under include/arch/. + +config SOC_RODATA_LD + bool + depends on (ARC || ARM || X86 || NIOS2 || RISCV32) + help + Include an SoC specific linker script fragment named soc-rodata.ld + for inserting additional data and linker directives into + the rodata section. + + This only has effect if the SoC uses the common linker script + under include/arch/. + +config SOC_RWDATA_LD + bool + depends on (ARC || ARM || X86 || NIOS2 || RISCV32) + help + Include an SoC specific linker script fragment named soc-rwdata.ld + for inserting additional data and linker directives into + the data section. + + This only has effect if the SoC uses the common linker script + under include/arch/.