cmake: Add the TEXT_START location to zephyr_linker_sources()

Places linker code at or near the beginning of the text section.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
This commit is contained in:
Øyvind Rønningstad 2019-11-28 12:01:53 +01:00 committed by Anas Nashif
commit d1c2a4edbf
8 changed files with 45 additions and 3 deletions

View file

@ -873,15 +873,17 @@ endfunction(zephyr_check_compiler_flag_hardcoded)
# NOINIT Inside the noinit output section. # NOINIT Inside the noinit output section.
# RWDATA Inside the data output section. # RWDATA Inside the data output section.
# RODATA Inside the rodata 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. # RAM_SECTIONS Inside the RAMABLE_REGION GROUP.
# SECTIONS Near the end of the file. Don't use this when linking into # SECTIONS Near the end of the file. Don't use this when linking into
# RAMABLE_REGION, use RAM_SECTIONS instead. # RAMABLE_REGION, use RAM_SECTIONS instead.
# #
# Use NOINIT, RWDATA, and RODATA unless they don't work for your use case. # 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 # When placing into NOINIT, RWDATA, RODATA, or TEXT_START the contents of the files
# placed inside an output section, so assume the section definition is already # will be placed inside an output section, so assume the section definition is
# present, e.g.: # already present, e.g.:
# _mysection_start = .; # _mysection_start = .;
# KEEP(*(.mysection)); # KEEP(*(.mysection));
# _mysection_end = .; # _mysection_end = .;
@ -909,6 +911,7 @@ function(zephyr_linker_sources location)
set(snippet_base "${__build_dir}/include/generated") set(snippet_base "${__build_dir}/include/generated")
set(sections_path "${snippet_base}/snippets-sections.ld") set(sections_path "${snippet_base}/snippets-sections.ld")
set(ram_sections_path "${snippet_base}/snippets-ram-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(noinit_path "${snippet_base}/snippets-noinit.ld")
set(rwdata_path "${snippet_base}/snippets-rwdata.ld") set(rwdata_path "${snippet_base}/snippets-rwdata.ld")
set(rodata_path "${snippet_base}/snippets-rodata.ld") set(rodata_path "${snippet_base}/snippets-rodata.ld")
@ -918,6 +921,7 @@ function(zephyr_linker_sources location)
if (NOT DEFINED cleared) if (NOT DEFINED cleared)
file(WRITE ${sections_path} "") file(WRITE ${sections_path} "")
file(WRITE ${ram_sections_path} "") file(WRITE ${ram_sections_path} "")
file(WRITE ${text_start_path} "")
file(WRITE ${noinit_path} "") file(WRITE ${noinit_path} "")
file(WRITE ${rwdata_path} "") file(WRITE ${rwdata_path} "")
file(WRITE ${rodata_path} "") file(WRITE ${rodata_path} "")
@ -929,6 +933,8 @@ function(zephyr_linker_sources location)
set(snippet_path "${sections_path}") set(snippet_path "${sections_path}")
elseif("${location}" STREQUAL "RAM_SECTIONS") elseif("${location}" STREQUAL "RAM_SECTIONS")
set(snippet_path "${ram_sections_path}") set(snippet_path "${ram_sections_path}")
elseif("${location}" STREQUAL "TEXT_START")
set(snippet_path "${text_start_path}")
elseif("${location}" STREQUAL "NOINIT") elseif("${location}" STREQUAL "NOINIT")
set(snippet_path "${noinit_path}") set(snippet_path "${noinit_path}")
elseif("${location}" STREQUAL "RWDATA") elseif("${location}" STREQUAL "RWDATA")

View file

@ -87,6 +87,10 @@ SECTIONS {
_image_rom_start = .; _image_rom_start = .;
_image_text_start = .; _image_text_start = .;
/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function.
*/
#include <snippets-text-start.ld>
/* when !XIP, .text is in RAM, and vector table must be at its very start */ /* when !XIP, .text is in RAM, and vector table must be at its very start */
KEEP(*(.exc_vector_table)) KEEP(*(.exc_vector_table))

View file

@ -156,6 +156,10 @@ SECTIONS
. = CONFIG_TEXT_SECTION_OFFSET; . = CONFIG_TEXT_SECTION_OFFSET;
/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function.
*/
#include <snippets-text-start.ld>
#if defined(CONFIG_SW_VECTOR_RELAY) #if defined(CONFIG_SW_VECTOR_RELAY)
KEEP(*(.vector_relay_table)) KEEP(*(.vector_relay_table))
KEEP(*(".vector_relay_table.*")) KEEP(*(".vector_relay_table.*"))

View file

@ -153,6 +153,10 @@ SECTIONS
. = CONFIG_TEXT_SECTION_OFFSET; . = CONFIG_TEXT_SECTION_OFFSET;
/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function.
*/
#include <snippets-text-start.ld>
#if defined(CONFIG_SW_VECTOR_RELAY) #if defined(CONFIG_SW_VECTOR_RELAY)
KEEP(*(.vector_relay_table)) KEEP(*(.vector_relay_table))
KEEP(*(".vector_relay_table.*")) KEEP(*(".vector_relay_table.*"))

View file

@ -120,6 +120,12 @@ SECTIONS
. = ALT_CPU_RESET_ADDR; . = ALT_CPU_RESET_ADDR;
_image_text_start = .; _image_text_start = .;
/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function.
*/
#include <snippets-text-start.ld>
*(.text) *(.text)
*(".text.*") *(".text.*")
*(.gnu.linkonce.t.*) *(.gnu.linkonce.t.*)

View file

@ -88,6 +88,12 @@ SECTIONS
KEEP(*(".openocd_debug.*")) KEEP(*(".openocd_debug.*"))
_image_text_start = .; _image_text_start = .;
/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function.
*/
#include <snippets-text-start.ld>
*(.text) *(.text)
*(".text.*") *(".text.*")
*(.gnu.linkonce.t.*) *(.gnu.linkonce.t.*)

View file

@ -86,6 +86,12 @@ SECTIONS
SECTION_PROLOGUE(_TEXT_SECTION_NAME,,) SECTION_PROLOGUE(_TEXT_SECTION_NAME,,)
{ {
. = CONFIG_TEXT_SECTION_OFFSET; . = CONFIG_TEXT_SECTION_OFFSET;
/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function.
*/
#include <snippets-text-start.ld>
*(.text_start) *(.text_start)
*(".text_start.*") *(".text_start.*")
*(.text) *(.text)

View file

@ -133,6 +133,12 @@ SECTIONS
KEEP(*(".openocd_debug.*")) KEEP(*(".openocd_debug.*"))
_image_text_start = .; _image_text_start = .;
/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function.
*/
#include <snippets-text-start.ld>
*(.text .text.*) *(.text .text.*)
*(.gnu.linkonce.t.*) *(.gnu.linkonce.t.*)
*(.eh_frame) *(.eh_frame)