linker: align _image_rodata and _image_rom start/end/size linker symbols

Cleanup and preparation commit for linker script generator.

Zephyr linker scripts provides start and end symbols for each larger
areas in the linker script.

The symbols _image_rom_start and _image_rom_end corresponds to the group
ROMABLE_REGION defined in the ld linker scripts.

The symbols _image_rodata_start and _image_rodata_end is not placed as
independent group but covers common-rom.ld, thread-local-storage.ld,
kobject-rom.ld and snippets-rodata.ld.

This commit align those names and prepares for generation of groups in
linker scripts.

The symbols describing the ROMABLE_REGION will be renamed to:
_image_rom_start -> __rom_region_start
_image_rom_end   -> __rom_region_end

The rodata will also use the group symbol notation as:
_image_rodata_start -> __rodata_region_start
_image_rodata_end   -> __rodata_region_end

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2021-08-09 18:16:51 +02:00 committed by Anas Nashif
commit c6aded2dcb
23 changed files with 86 additions and 86 deletions

View file

@ -651,8 +651,8 @@ static const struct arm_mmu_flat_range mmu_zephyr_ranges[] = {
/* Mark rodata segment cacheable, read only and execute-never */
{ .name = "zephyr_rodata",
.start = _image_rodata_start,
.end = _image_rodata_end,
.start = __rodata_region_start,
.end = __rodata_region_end,
.attrs = MT_NORMAL | MT_P_RO_U_RO | MT_DEFAULT_SECURE_STATE },
};

View file

@ -229,11 +229,11 @@ void z_riscv_init_user_accesses(struct k_thread *thread)
{
unsigned char index;
unsigned char *uchar_pmpcfg;
ulong_t rom_start = (ulong_t) _image_rom_start;
ulong_t rom_start = (ulong_t) __rom_region_start;
#if defined(CONFIG_PMP_POWER_OF_TWO_ALIGNMENT)
ulong_t rom_size = (ulong_t) _image_rom_size;
ulong_t rom_size = (ulong_t) __rom_region_size;
#else /* CONFIG_PMP_POWER_OF_TWO_ALIGNMENT */
ulong_t rom_end = (ulong_t) _image_rom_end;
ulong_t rom_end = (ulong_t) __rom_region_end;
#endif /* CONFIG_PMP_POWER_OF_TWO_ALIGNMENT */
index = 0U;
uchar_pmpcfg = (unsigned char *) thread->arch.u_pmpcfg;

View file

@ -14,7 +14,7 @@ struct x86_memmap_exclusion x86_memmap_exclusions[] = {
{ "locore", _locore_start, _locore_end },
#endif
#ifdef CONFIG_XIP
{ "rom", _image_rom_start, _image_rom_end },
{ "rom", __rom_region_start, __rom_region_end },
#endif
{ "ram", _image_ram_start, _image_ram_end },
#ifdef CONFIG_USERSPACE

View file

@ -23,7 +23,7 @@ vary:
- By default, the Present, Write, and Execute Disable bits are
set.
- The _image_text region will have Present and User bits set
- The _image_rodata region will have Present, User, and Execute
- The __rodata_region region will have Present, User, and Execute
Disable bits set
- On x86_64, the _locore region will have Present set and
the _lorodata region will have Present and Execute Disable set.
@ -878,7 +878,7 @@ def main():
if is_generic_section_present:
flags = flags | FLAG_P
pt.set_region_perms("_image_rodata", flags)
pt.set_region_perms("__rodata_region", flags)
if isdef("CONFIG_LINKER_USE_BOOT_SECTION"):
pt.set_region_perms("lnkr_boot_rodata", flags | FLAG_P)

View file

@ -590,7 +590,7 @@ SECTIONS
_image_text_end = .;
_image_text_size = _image_text_end - _image_text_start;
_image_rodata_start = .;
__rodata_region_start = .;
#ifndef CONFIG_LINKER_USE_PINNED_SECTION
#include <linker/common-rom.ld>
@ -623,8 +623,8 @@ SECTIONS
MMU_PAGE_ALIGN_PERM
/* ROM ends here, position counter will now be in RAM areas */
_image_rodata_end = .;
_image_rodata_size = _image_rodata_end - _image_rodata_start;
__rodata_region_end = .;
__rodata_region_size = __rodata_region_end - __rodata_region_start;
GROUP_END(ROMABLE_REGION)
/*
* Needed for dynamic linking which we do not have, do discard

View file

@ -74,7 +74,7 @@ SECTIONS {
GROUP_START(ROMABLE_REGION)
SECTION_PROLOGUE(_TEXT_SECTION_NAME,,ALIGN(1024)) {
_image_rom_start = .;
__rom_region_start = .;
_image_text_start = .;
/* Located in generated directory. This file is populated by the
@ -96,7 +96,7 @@ SECTIONS {
#endif /* CONFIG_CPLUSPLUS && !CONFIG_CPP_STATIC_INIT_GNU && __MWDT_LINKER_CMD__ */
_image_text_end = .;
_image_rodata_start = .;
__rodata_region_start = .;
#include <linker/common-rom.ld>
#include <linker/thread-local-storage.ld>
@ -127,10 +127,10 @@ SECTIONS {
#include <linker/cplusplus-rom.ld>
#endif /* __MWDT_LINKER_CMD__ */
_image_rodata_end = .;
MPU_ALIGN(_image_rodata_end - _image_rom_start);
_image_rom_end = .;
_image_rom_size = _image_rom_end - _image_rom_start;
__rodata_region_end = .;
MPU_ALIGN(__rodata_region_end - __rom_region_start);
__rom_region_end = .;
__rom_region_size = __rom_region_end - __rom_region_start;
GROUP_END(ROMABLE_REGION)

View file

@ -103,9 +103,9 @@ SECTIONS
GROUP_START(ROMABLE_REGION)
#if defined(CONFIG_XIP)
_image_rom_start = ROM_ADDR;
__rom_region_start = ROM_ADDR;
#else
_image_rom_start = RAM_ADDR;
__rom_region_start = RAM_ADDR;
#endif
SECTION_PROLOGUE(rom_start,,)
@ -170,7 +170,7 @@ SECTIONS
__exidx_end = .;
} GROUP_LINK_IN(ROMABLE_REGION)
_image_rodata_start = .;
__rodata_region_start = .;
#include <linker/common-rom.ld>
#include <linker/thread-local-storage.ld>
@ -208,7 +208,7 @@ SECTIONS
MPU_ALIGN(ABSOLUTE(.) - _image_rom_start);
} GROUP_LINK_IN(ROMABLE_REGION)
_image_rodata_end = .;
__rodata_region_end = .;
_image_rom_end = .;
_image_rom_end_order = (LOG2CEIL(_image_rom_end) - 1) << 1;
@ -345,6 +345,6 @@ SECTIONS
/* To provide the image size as a const expression,
* calculate this value here. */
_flash_used = LOADADDR(.last_section) - _image_rom_start;
_flash_used = LOADADDR(.last_section) - __rom_region_start;
}

View file

@ -124,7 +124,7 @@ SECTIONS
GROUP_START(ROMABLE_REGION)
_image_rom_start = ROM_ADDR;
__rom_region_start = ROM_ADDR;
SECTION_PROLOGUE(rom_start,,)
{
@ -189,7 +189,7 @@ SECTIONS
__exidx_end = .;
} GROUP_LINK_IN(ROMABLE_REGION)
_image_rodata_start = .;
__rodata_region_start = .;
#include <linker/common-rom.ld>
#include <linker/thread-local-storage.ld>
@ -222,9 +222,9 @@ SECTIONS
#include <linker/cplusplus-rom.ld>
_image_rodata_end = .;
MPU_ALIGN(_image_rodata_end -_image_rom_start);
_image_rom_end = .;
__rodata_region_end = .;
MPU_ALIGN(__rodata_region_end -__rom_region_start);
__rom_region_end = .;
GROUP_END(ROMABLE_REGION)
@ -460,6 +460,6 @@ SECTION_PROLOGUE(.last_section,(NOLOAD),)
/* To provide the image size as a const expression,
* calculate this value here. */
_flash_used = LOADADDR(.last_section) - _image_rom_start;
_flash_used = LOADADDR(.last_section) - __rom_region_start;
}

View file

@ -89,7 +89,7 @@ SECTIONS
GROUP_START(ROMABLE_REGION)
_image_rom_start = ROM_ADDR;
__rom_region_start = ROM_ADDR;
SECTION_PROLOGUE(_TEXT_SECTION_NAME,,)
{
@ -154,7 +154,7 @@ SECTIONS
__exidx_end = .;
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
_image_rodata_start = .;
__rodata_region_start = .;
#include <linker/common-rom.ld>
#include <linker/thread-local-storage.ld>
@ -179,9 +179,9 @@ SECTIONS
#include <linker/cplusplus-rom.ld>
MMU_ALIGN;
_image_rodata_end = .;
_image_rodata_size = _image_rodata_end - _image_rodata_start;
_image_rom_end = .;
__rodata_region_end = .;
__rodata_region_size = __rodata_region_end - __rodata_region_start;
__rom_region_end = .;
/*
* These are here according to 'arm-zephyr-elf-ld --verbose',
@ -317,6 +317,6 @@ SECTIONS
/* To provide the image size as a const expression,
* calculate this value here. */
_flash_used = LOADADDR(.last_section) - _image_rom_start;
_flash_used = LOADADDR(.last_section) - __rom_region_start;
}

View file

@ -155,10 +155,10 @@ SECTIONS
#include <linker/cplusplus-rom.ld>
_image_rodata_end = .;
_image_rodata_size = _image_rodata_end - _image_rodata_start;
__rodata_region_end = .;
__rodata_region_size = __rodata_region_end - __rodata_region_start;
_image_rom_end = .;
__rom_region_end = .;
__data_region_load_start = ALIGN(4); /* XIP imaged DATA ROM start addr */
GROUP_END(ROMABLE_REGION)

View file

@ -111,7 +111,7 @@ SECTIONS
}
GROUP_START(ROMABLE_REGION)
_image_rom_start = ROM_BASE;
__rom_region_start = ROM_BASE;
SECTION_PROLOGUE(_VECTOR_SECTION_NAME,,)
{
@ -163,7 +163,7 @@ SECTIONS
_image_text_end = .;
_image_rodata_start = .;
__rodata_region_start = .;
#include <linker/common-rom.ld>
#include <linker/thread-local-storage.ld>
@ -186,8 +186,8 @@ SECTIONS
} GROUP_LINK_IN(ROMABLE_REGION)
#include <linker/cplusplus-rom.ld>
_image_rodata_end = .;
MPU_ALIGN(_image_rodata_end - _image_rom_start);
__rodata_region_end = .;
MPU_ALIGN(__rodata_region_end - __rom_region_start);
GROUP_END(ROMABLE_REGION)
GROUP_START(RAMABLE_REGION)
@ -369,7 +369,7 @@ SECTION_PROLOGUE(.last_section,(NOLOAD),)
/* To provide the image size as a const expression,
* calculate this value here. */
_image_rom_end = LOADADDR(.last_section);
_image_rom_size = _image_rom_end - _image_rom_start;
__rom_region_end = LOADADDR(.last_section);
__rom_region_size = __rom_region_end - __rom_region_start;
}

View file

@ -24,7 +24,7 @@ SECTIONS
#include <linker/rel-sections.ld>
_image_rom_start = .;
__rom_region_start = .;
SECTION_PROLOGUE(_TEXT_SECTION_NAME,,)
{
@ -40,7 +40,7 @@ SECTIONS
} GROUP_LINK_IN(REGION_TEXT)
_image_text_end = .;
_image_rodata_start = .;
__rodata_region_start = .;
#include <linker/common-rom.ld>
#include <linker/thread-local-storage.ld>
@ -62,10 +62,10 @@ SECTIONS
#include <linker/cplusplus-rom.ld>
_image_rodata_end = .;
_image_rodata_size = _image_rodata_end - _image_rodata_start;
__rodata_region_end = .;
__rodata_region_size = __rodata_region_end - __rodata_region_start;
_image_rom_end = .;
__rom_region_end = .;
__data_region_load_start = .;
__data_region_start = .;

View file

@ -289,7 +289,7 @@ SECTIONS
. = ALIGN(8);
#ifdef CONFIG_XIP
_image_rom_start = PHYS_LOAD_ADDR;
__rom_region_start = PHYS_LOAD_ADDR;
#endif
SECTION_PROLOGUE(_TEXT_SECTION_NAME,,)
{
@ -329,7 +329,7 @@ SECTIONS
_image_text_end = .;
_image_text_size = _image_text_end - _image_text_start;
_image_rodata_start = .;
__rodata_region_start = .;
#ifndef CONFIG_LINKER_USE_PINNED_SECTION
#include <linker/common-rom.ld>
@ -363,11 +363,11 @@ SECTIONS
MMU_PAGE_ALIGN_PERM
/* ROM ends here, position counter will now be in RAM areas */
#ifdef CONFIG_XIP
_image_rom_end = .;
_image_rom_size = _image_rom_end - _image_rom_start;
__rom_region_end = .;
__rom_region_size = __rom_region_end - __rom_region_start;
#endif
_image_rodata_end = .;
_image_rodata_size = _image_rodata_end - _image_rodata_start;
__rodata_region_end = .;
__rodata_region_size = __rodata_region_end - __rodata_region_start;
GROUP_END(ROMABLE_REGION)
/*
* Needed for dynamic linking which we do not have, do discard

View file

@ -88,7 +88,7 @@ SECTIONS
SECTION_PROLOGUE(_TEXT_SECTION_NAME,,)
{
. = ALIGN(16);
_image_rom_start = .;
__rom_region_start = .;
_image_text_start = .;
z_mapped_start = .;
*(.text)
@ -101,7 +101,7 @@ SECTIONS
_image_text_end = .;
_image_text_size = _image_text_end - _image_text_start;
_image_rodata_start = .;
__rodata_region_start = .;
#include <linker/common-rom.ld>
#include <linker/thread-local-storage.ld>
@ -128,9 +128,9 @@ SECTIONS
#include <linker/cplusplus-rom.ld>
MMU_PAGE_ALIGN_PERM
_image_rodata_end = .;
_image_rodata_size = _image_rodata_end - _image_rodata_start;
_image_rom_end = .;
__rodata_region_end = .;
__rodata_region_size = __rodata_region_end - __rodata_region_start;
__rom_region_end = .;
#ifdef CONFIG_USERSPACE
/* APP SHARED MEMORY REGION */

View file

@ -236,9 +236,9 @@ extern char z_mapped_end[];
#endif /* CONFIG_MMU */
/* Includes text and rodata */
extern char _image_rom_start[];
extern char _image_rom_end[];
extern char _image_rom_size[];
extern char __rom_region_start[];
extern char __rom_region_end[];
extern char __rom_region_size[];
/* Includes all ROMable data, i.e. the size of the output image file. */
extern char _flash_used[];
@ -251,9 +251,9 @@ extern char _image_text_start[];
extern char _image_text_end[];
extern char _image_text_size[];
extern char _image_rodata_start[];
extern char _image_rodata_end[];
extern char _image_rodata_size[];
extern char __rodata_region_start[];
extern char __rodata_region_end[];
extern char __rodata_region_size[];
extern char _vector_start[];
extern char _vector_end[];

View file

@ -32,10 +32,10 @@ static inline bool ptr_in_rodata(const char *addr)
#elif defined(CONFIG_ARC) || defined(CONFIG_ARM) || defined(CONFIG_X86) \
|| defined(CONFIG_RISCV) || defined(CONFIG_ARM64) \
|| defined(CONFIG_NIOS2)
extern char _image_rodata_start[];
extern char _image_rodata_end[];
#define RO_START _image_rodata_start
#define RO_END _image_rodata_end
extern char __rodata_region_start[];
extern char __rodata_region_end[];
#define RO_START __rodata_region_start
#define RO_END __rodata_region_end
#elif defined(CONFIG_XTENSA)
extern char _rodata_start[];
extern char _rodata_end[];

View file

@ -27,8 +27,8 @@ static const struct arm_mpu_region mpu_regions[] = {
/* Region 2 zephyr rodata */
MPU_REGION_ENTRY("SRAM_1",
(uintptr_t)_image_rodata_start,
(uintptr_t)_image_rodata_end,
(uintptr_t)__rodata_region_start,
(uintptr_t)__rodata_region_end,
REGION_RAM_RO_ATTR),
/* Region 3 zephyr data */

View file

@ -238,7 +238,7 @@ SECTIONS
.flash.rodata : ALIGN(0x10)
{
_rodata_start = ABSOLUTE(.);
_image_rodata_start = .;
__rodata_region_start = .;
__esp_shell_root_cmds_start = .;
KEEP(*(SORT(.shell_root_cmd_*)));
__esp_shell_root_cmds_end = .;
@ -285,7 +285,7 @@ SECTIONS
*(.xt_except_desc_end)
*(.dynamic)
*(.gnu.version_d)
_image_rodata_end = .;
__rodata_region_end = .;
_rodata_end = ABSOLUTE(.);
/* Literals are also RO data. */
_lit4_start = ABSOLUTE(.);

View file

@ -99,7 +99,7 @@ SECTIONS
}
GROUP_START(ROM)
_image_rom_start = ROM_BASE;
__rom_region_start = ROM_BASE;
SECTION_PROLOGUE(_TEXT_SECTION_NAME,,)
{
@ -119,7 +119,7 @@ SECTIONS
_image_text_end = .;
_image_rodata_start = .;
__rodata_region_start = .;
#include <linker/common-rom.ld>
#include <linker/thread-local-storage.ld>
@ -142,8 +142,8 @@ SECTIONS
#include <linker/cplusplus-rom.ld>
_image_rodata_end = .;
_image_rom_end = .;
__rodata_region_end = .;
__rom_region_end = .;
#ifndef CONFIG_BOOTLOADER_MCUBOOT
/* The vector table goes into core-dependent flash locations. */

View file

@ -402,7 +402,7 @@ SECTIONS
.ResetVector.text : ALIGN(4)
{
_image_rom_start = ABSOLUTE(.);
__rom_region_start = ABSOLUTE(.);
_ResetVector_text_start = ABSOLUTE(.);
KEEP (*(.ResetVector.text))
_ResetVector_text_end = ABSOLUTE(.);
@ -422,7 +422,7 @@ SECTIONS
*(.srom.literal .srom.text)
_srom_text_end = ABSOLUTE(.);
_memmap_seg_srom1_end = ALIGN(0x8);
_image_rom_end = ABSOLUTE(.);
__rom_region_end = ABSOLUTE(.);
} >srom1_seg :srom1_phdr
.sram.rodata : ALIGN(4)

View file

@ -156,10 +156,10 @@ static bool is_rodata(const void *addr)
#if defined(CONFIG_ARM) || defined(CONFIG_ARC) || defined(CONFIG_X86) || \
defined(CONFIG_ARM64) || defined(CONFIG_NIOS2) || \
defined(CONFIG_RISCV) || defined(CONFIG_SPARC)
extern const char *_image_rodata_start[];
extern const char *_image_rodata_end[];
#define RO_START _image_rodata_start
#define RO_END _image_rodata_end
extern const char *__rodata_region_start[];
extern const char *__rodata_region_end[];
#define RO_START __rodata_region_start
#define RO_END __rodata_region_end
#elif defined(CONFIG_XTENSA)
extern const char *_rodata_start[];
extern const char *_rodata_end[];

View file

@ -99,7 +99,7 @@ void test_ram_perms(void)
expected = MMU_P | MMU_RW;
} else if (IN_REGION(_image_text, pos)) {
expected = MMU_P | MMU_US;
} else if (IN_REGION(_image_rodata, pos)) {
} else if (IN_REGION(__rodata_region, pos)) {
expected = MMU_P | MMU_US | MMU_XD;
#ifdef CONFIG_COVERAGE_GCOV
} else if (IN_REGION(__gcov_bss, pos)) {

View file

@ -293,8 +293,8 @@ static void test_write_kernro(void)
/* Try to write to kernel RO. */
const char *const ptr = (const char *const)&_k_neg_eagain;
in_rodata = ptr < _image_rodata_end &&
ptr >= _image_rodata_start;
in_rodata = ptr < __rodata_region_end &&
ptr >= __rodata_region_start;
#ifdef CONFIG_LINKER_USE_PINNED_SECTION
if (!in_rodata) {