From d1c2a4edbfcea1c1eb57bf7dc021ba4f911f1d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Thu, 28 Nov 2019 12:01:53 +0100 Subject: [PATCH] cmake: Add the TEXT_START location to zephyr_linker_sources() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Places linker code at or near the beginning of the text section. Signed-off-by: Øyvind Rønningstad --- cmake/extensions.cmake | 12 +++++++++--- include/arch/arc/v2/linker.ld | 4 ++++ include/arch/arm/cortex_m/scripts/linker.ld | 4 ++++ include/arch/arm/cortex_r/scripts/linker.ld | 4 ++++ include/arch/nios2/linker.ld | 6 ++++++ include/arch/riscv/common/linker.ld | 6 ++++++ include/arch/x86/ia32/linker.ld | 6 ++++++ soc/riscv/openisa_rv32m1/linker.ld | 6 ++++++ 8 files changed, 45 insertions(+), 3 deletions(-) diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake index 6657b352db8..8fa8792df22 100644 --- a/cmake/extensions.cmake +++ b/cmake/extensions.cmake @@ -873,15 +873,17 @@ endfunction(zephyr_check_compiler_flag_hardcoded) # NOINIT Inside the noinit output section. # RWDATA Inside the data output section. # RODATA Inside the rodata output section. +# TEXT_START At the beginning of the text section, i.e. the beginning of +# the image. # RAM_SECTIONS Inside the RAMABLE_REGION GROUP. # SECTIONS Near the end of the file. Don't use this when linking into # RAMABLE_REGION, use RAM_SECTIONS instead. # # Use NOINIT, RWDATA, and RODATA unless they don't work for your use case. # -# When placing into NOINIT, RWDATA, or RODATA, the contents of the files will be -# placed inside an output section, so assume the section definition is already -# present, e.g.: +# When placing into NOINIT, RWDATA, RODATA, or TEXT_START the contents of the files +# will be placed inside an output section, so assume the section definition is +# already present, e.g.: # _mysection_start = .; # KEEP(*(.mysection)); # _mysection_end = .; @@ -909,6 +911,7 @@ function(zephyr_linker_sources location) set(snippet_base "${__build_dir}/include/generated") set(sections_path "${snippet_base}/snippets-sections.ld") set(ram_sections_path "${snippet_base}/snippets-ram-sections.ld") + set(text_start_path "${snippet_base}/snippets-text-start.ld") set(noinit_path "${snippet_base}/snippets-noinit.ld") set(rwdata_path "${snippet_base}/snippets-rwdata.ld") set(rodata_path "${snippet_base}/snippets-rodata.ld") @@ -918,6 +921,7 @@ function(zephyr_linker_sources location) if (NOT DEFINED cleared) file(WRITE ${sections_path} "") file(WRITE ${ram_sections_path} "") + file(WRITE ${text_start_path} "") file(WRITE ${noinit_path} "") file(WRITE ${rwdata_path} "") file(WRITE ${rodata_path} "") @@ -929,6 +933,8 @@ function(zephyr_linker_sources location) set(snippet_path "${sections_path}") elseif("${location}" STREQUAL "RAM_SECTIONS") set(snippet_path "${ram_sections_path}") + elseif("${location}" STREQUAL "TEXT_START") + set(snippet_path "${text_start_path}") elseif("${location}" STREQUAL "NOINIT") set(snippet_path "${noinit_path}") elseif("${location}" STREQUAL "RWDATA") diff --git a/include/arch/arc/v2/linker.ld b/include/arch/arc/v2/linker.ld index 69458f62e45..92f084e60b8 100644 --- a/include/arch/arc/v2/linker.ld +++ b/include/arch/arc/v2/linker.ld @@ -87,6 +87,10 @@ SECTIONS { _image_rom_start = .; _image_text_start = .; +/* Located in generated directory. This file is populated by the + * zephyr_linker_sources() Cmake function. + */ +#include /* when !XIP, .text is in RAM, and vector table must be at its very start */ KEEP(*(.exc_vector_table)) diff --git a/include/arch/arm/cortex_m/scripts/linker.ld b/include/arch/arm/cortex_m/scripts/linker.ld index f4294a0473c..f6b83946112 100644 --- a/include/arch/arm/cortex_m/scripts/linker.ld +++ b/include/arch/arm/cortex_m/scripts/linker.ld @@ -156,6 +156,10 @@ SECTIONS . = CONFIG_TEXT_SECTION_OFFSET; +/* Located in generated directory. This file is populated by the + * zephyr_linker_sources() Cmake function. + */ +#include #if defined(CONFIG_SW_VECTOR_RELAY) KEEP(*(.vector_relay_table)) KEEP(*(".vector_relay_table.*")) diff --git a/include/arch/arm/cortex_r/scripts/linker.ld b/include/arch/arm/cortex_r/scripts/linker.ld index dc08d6c3bf1..ca9adcf3b0e 100644 --- a/include/arch/arm/cortex_r/scripts/linker.ld +++ b/include/arch/arm/cortex_r/scripts/linker.ld @@ -153,6 +153,10 @@ SECTIONS . = CONFIG_TEXT_SECTION_OFFSET; +/* Located in generated directory. This file is populated by the + * zephyr_linker_sources() Cmake function. + */ +#include #if defined(CONFIG_SW_VECTOR_RELAY) KEEP(*(.vector_relay_table)) KEEP(*(".vector_relay_table.*")) diff --git a/include/arch/nios2/linker.ld b/include/arch/nios2/linker.ld index f72f1cd4b76..e3eeb7920b2 100644 --- a/include/arch/nios2/linker.ld +++ b/include/arch/nios2/linker.ld @@ -120,6 +120,12 @@ SECTIONS . = ALT_CPU_RESET_ADDR; _image_text_start = .; + +/* Located in generated directory. This file is populated by the + * zephyr_linker_sources() Cmake function. + */ +#include + *(.text) *(".text.*") *(.gnu.linkonce.t.*) diff --git a/include/arch/riscv/common/linker.ld b/include/arch/riscv/common/linker.ld index a0edb0a0381..19bd463dc0c 100644 --- a/include/arch/riscv/common/linker.ld +++ b/include/arch/riscv/common/linker.ld @@ -88,6 +88,12 @@ SECTIONS KEEP(*(".openocd_debug.*")) _image_text_start = .; + +/* Located in generated directory. This file is populated by the + * zephyr_linker_sources() Cmake function. + */ +#include + *(.text) *(".text.*") *(.gnu.linkonce.t.*) diff --git a/include/arch/x86/ia32/linker.ld b/include/arch/x86/ia32/linker.ld index e6df4475de4..6306dd25111 100644 --- a/include/arch/x86/ia32/linker.ld +++ b/include/arch/x86/ia32/linker.ld @@ -86,6 +86,12 @@ SECTIONS SECTION_PROLOGUE(_TEXT_SECTION_NAME,,) { . = CONFIG_TEXT_SECTION_OFFSET; + +/* Located in generated directory. This file is populated by the + * zephyr_linker_sources() Cmake function. + */ +#include + *(.text_start) *(".text_start.*") *(.text) diff --git a/soc/riscv/openisa_rv32m1/linker.ld b/soc/riscv/openisa_rv32m1/linker.ld index 0e900afd511..ff69f81f397 100644 --- a/soc/riscv/openisa_rv32m1/linker.ld +++ b/soc/riscv/openisa_rv32m1/linker.ld @@ -133,6 +133,12 @@ SECTIONS KEEP(*(".openocd_debug.*")) _image_text_start = .; + +/* Located in generated directory. This file is populated by the + * zephyr_linker_sources() Cmake function. + */ +#include + *(.text .text.*) *(.gnu.linkonce.t.*) *(.eh_frame)