linker_script: move .data section to bl_common.ld.h

Move the data section to the common header.

I slightly tweaked some scripts as follows:

[1] bl1.ld.S has ALIGN(16). I added DATA_ALIGN macro, which is 1
    by default, but overridden by bl1.ld.S. Currently, ALIGN(16)
    of the .data section is redundant because commit 4128659076
    ("Fix boot failures on some builds linked with ld.lld.") padded
    out the previous section to work around the issue of LLD version
    <= 10.0. This will be fixed in the future release of LLVM, so
    I am keeping the proper way to align LMA.

[2] bl1.ld.S and bl2_el3.ld.S define __DATA_RAM_{START,END}__ instead
    of __DATA_{START,END}__. I put them out of the .data section.

[3] SORT_BY_ALIGNMENT() is missing tsp.ld.S, sp_min.ld.S, and
    mediatek/mt6795/bl31.ld.S. This commit adds SORT_BY_ALIGNMENT()
    for all images, so the symbol order in those three will change,
    but I do not think it is a big deal.

Change-Id: I215bb23c319f045cd88e6f4e8ee2518c67f03692
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
Masahiro Yamada 2020-04-22 10:50:12 +09:00
parent a926a9f60a
commit caa3e7e0a4
9 changed files with 36 additions and 77 deletions

View File

@ -4,6 +4,14 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
/*
* The .data section gets copied from ROM to RAM at runtime.
* Its LMA should be 16-byte aligned to allow efficient copying of 16-bytes
* aligned regions in it.
* Its VMA must be page-aligned as it marks the first read/write page.
*/
#define DATA_ALIGN 16
#include <common/bl_common.ld.h> #include <common/bl_common.ld.h>
#include <lib/xlat_tables/xlat_tables_defs.h> #include <lib/xlat_tables/xlat_tables_defs.h>
@ -87,21 +95,9 @@ SECTIONS
ASSERT(BL1_RW_BASE == ALIGN(PAGE_SIZE), ASSERT(BL1_RW_BASE == ALIGN(PAGE_SIZE),
"BL1_RW_BASE address is not aligned on a page boundary.") "BL1_RW_BASE address is not aligned on a page boundary.")
/* DATA_SECTION >RAM AT>ROM
* The .data section gets copied from ROM to RAM at runtime. __DATA_RAM_START__ = __DATA_START__;
* Its LMA should be 16-byte aligned to allow efficient copying of 16-bytes __DATA_RAM_END__ = __DATA_END__;
* aligned regions in it.
* Its VMA must be page-aligned as it marks the first read/write page.
*
* It must be placed at a lower address than the stacks if the stack
* protector is enabled. Alternatively, the .data.stack_protector_canary
* section can be placed independently of the main .data section.
*/
.data . : ALIGN(16) {
__DATA_RAM_START__ = .;
*(SORT_BY_ALIGNMENT(.data*))
__DATA_RAM_END__ = .;
} >RAM AT>ROM
STACK_SECTION >RAM STACK_SECTION >RAM
BSS_SECTION >RAM BSS_SECTION >RAM

View File

@ -77,17 +77,7 @@ SECTIONS
*/ */
__RW_START__ = . ; __RW_START__ = . ;
/* DATA_SECTION >RAM
* .data must be placed at a lower address than the stacks if the stack
* protector is enabled. Alternatively, the .data.stack_protector_canary
* section can be placed independently of the main .data section.
*/
.data . : {
__DATA_START__ = .;
*(SORT_BY_ALIGNMENT(.data*))
__DATA_END__ = .;
} >RAM
STACK_SECTION >RAM STACK_SECTION >RAM
BSS_SECTION >RAM BSS_SECTION >RAM
XLAT_TABLE_SECTION >RAM XLAT_TABLE_SECTION >RAM

View File

@ -101,16 +101,9 @@ SECTIONS
*/ */
__RW_START__ = . ; __RW_START__ = . ;
/* DATA_SECTION >RAM AT>ROM
* .data must be placed at a lower address than the stacks if the stack __DATA_RAM_START__ = __DATA_START__;
* protector is enabled. Alternatively, the .data.stack_protector_canary __DATA_RAM_END__ = __DATA_END__;
* section can be placed independently of the main .data section.
*/
.data . : {
__DATA_RAM_START__ = .;
*(SORT_BY_ALIGNMENT(.data*))
__DATA_RAM_END__ = .;
} >RAM AT>ROM
/* /*
* .rela.dyn needs to come after .data for the read-elf utility to parse * .rela.dyn needs to come after .data for the read-elf utility to parse

View File

@ -79,17 +79,7 @@ SECTIONS
*/ */
__RW_START__ = . ; __RW_START__ = . ;
/* DATA_SECTION >RAM
* .data must be placed at a lower address than the stacks if the stack
* protector is enabled. Alternatively, the .data.stack_protector_canary
* section can be placed independently of the main .data section.
*/
.data . : {
__DATA_START__ = .;
*(SORT_BY_ALIGNMENT(.data*))
__DATA_END__ = .;
} >RAM
STACK_SECTION >RAM STACK_SECTION >RAM
BSS_SECTION >RAM BSS_SECTION >RAM
XLAT_TABLE_SECTION >RAM XLAT_TABLE_SECTION >RAM

View File

@ -114,16 +114,7 @@ SECTIONS
*/ */
__RW_START__ = . ; __RW_START__ = . ;
/* DATA_SECTION >RAM
* .data must be placed at a lower address than the stacks if the stack
* protector is enabled. Alternatively, the .data.stack_protector_canary
* section can be placed independently of the main .data section.
*/
.data . : {
__DATA_START__ = .;
*(SORT_BY_ALIGNMENT(.data*))
__DATA_END__ = .;
} >RAM
/* /*
* .rela.dyn needs to come after .data for the read-elf utility to parse * .rela.dyn needs to come after .data for the read-elf utility to parse

View File

@ -91,11 +91,7 @@ SECTIONS
*/ */
__RW_START__ = . ; __RW_START__ = . ;
.data . : { DATA_SECTION >RAM
__DATA_START__ = .;
*(.data*)
__DATA_END__ = .;
} >RAM
#ifdef BL32_PROGBITS_LIMIT #ifdef BL32_PROGBITS_LIMIT
ASSERT(. <= BL32_PROGBITS_LIMIT, "BL32 progbits has exceeded its limit.") ASSERT(. <= BL32_PROGBITS_LIMIT, "BL32 progbits has exceeded its limit.")

View File

@ -70,11 +70,7 @@ SECTIONS
*/ */
__RW_START__ = . ; __RW_START__ = . ;
.data . : { DATA_SECTION >RAM
__DATA_START__ = .;
*(.data*)
__DATA_END__ = .;
} >RAM
/* /*
* .rela.dyn needs to come after .data for the read-elf utility to parse * .rela.dyn needs to come after .data for the read-elf utility to parse

View File

@ -17,6 +17,10 @@
#define BSS_ALIGN 8 #define BSS_ALIGN 8
#endif #endif
#ifndef DATA_ALIGN
#define DATA_ALIGN 1
#endif
#define CPU_OPS \ #define CPU_OPS \
. = ALIGN(STRUCT_ALIGN); \ . = ALIGN(STRUCT_ALIGN); \
__CPU_OPS_START__ = .; \ __CPU_OPS_START__ = .; \
@ -85,6 +89,18 @@
GOT \ GOT \
BASE_XLAT_TABLE_RO BASE_XLAT_TABLE_RO
/*
* .data must be placed at a lower address than the stacks if the stack
* protector is enabled. Alternatively, the .data.stack_protector_canary
* section can be placed independently of the main .data section.
*/
#define DATA_SECTION \
.data . : ALIGN(DATA_ALIGN) { \
__DATA_START__ = .; \
*(SORT_BY_ALIGNMENT(.data*)) \
__DATA_END__ = .; \
}
#define STACK_SECTION \ #define STACK_SECTION \
stacks (NOLOAD) : { \ stacks (NOLOAD) : { \
__STACKS_START__ = .; \ __STACKS_START__ = .; \

View File

@ -59,16 +59,7 @@ SECTIONS
*/ */
__RW_START__ = . ; __RW_START__ = . ;
/* DATA_SECTION >RAM
* .data must be placed at a lower address than the stacks if the stack
* protector is enabled. Alternatively, the .data.stack_protector_canary
* section can be placed independently of the main .data section.
*/
.data . : {
__DATA_START__ = .;
*(.data*)
__DATA_END__ = .;
} >RAM
#ifdef BL31_PROGBITS_LIMIT #ifdef BL31_PROGBITS_LIMIT
ASSERT(. <= BL31_PROGBITS_LIMIT, "BL3-1 progbits has exceeded its limit.") ASSERT(. <= BL31_PROGBITS_LIMIT, "BL3-1 progbits has exceeded its limit.")