feat(build): check that .text section starts at page boundary

Linker may decide to put new unspecified sections before .text
section. That will cause non-working image, because entry point isn't
at __BLXX_START__. Device just not booted with such image.

This happened for example with .note.gnu.build-id section generated
for LTO build in some cases. Now linker will report this situation as
an error.

```
/usr/lib/gcc-cross/aarch64-linux-gnu/13/../../../../aarch64-linux-gnu/bin/ld: .text is not aligned on a page boundary.
collect2: error: ld returned 1 exit status
```

Signed-off-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
Change-Id: I5ae46ddd1e6e431e1df1715d1d301f6dd7181cc7
This commit is contained in:
Andrey Skvortsov 2023-09-05 22:09:25 +03:00
parent 5a4c3f0baa
commit 3d6edc325c
7 changed files with 42 additions and 0 deletions

View File

@ -36,6 +36,9 @@ SECTIONS {
#if SEPARATE_CODE_AND_RODATA
.text . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".text address is not aligned on a page boundary.");
__TEXT_START__ = .;
*bl1_entrypoint.o(.text*)
@ -80,6 +83,9 @@ SECTIONS {
} >ROM
#else /* SEPARATE_CODE_AND_RODATA */
.ro . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".ro address is not aligned on a page boundary.");
__RO_START__ = .;
*bl1_entrypoint.o(.text*)

View File

@ -25,6 +25,9 @@ SECTIONS {
#if SEPARATE_CODE_AND_RODATA
.text . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".text address is not aligned on a page boundary.");
__TEXT_START__ = .;
#if ENABLE_RME
@ -65,6 +68,9 @@ SECTIONS {
} >RAM
#else /* SEPARATE_CODE_AND_RODATA */
.ro . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".ro address is not aligned on a page boundary.");
__RO_START__ = .;
*bl2_entrypoint.o(.text*)

View File

@ -55,6 +55,9 @@ SECTIONS {
#if SEPARATE_CODE_AND_RODATA
.text . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".text address is not aligned on a page boundary.");
__TEXT_START__ = .;
__TEXT_RESIDENT_START__ = .;
@ -89,6 +92,9 @@ SECTIONS {
"Resident part of BL2 has exceeded its limit.")
#else /* SEPARATE_CODE_AND_RODATA */
.ro . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".ro address is not aligned on a page boundary.");
__RO_START__ = .;
__TEXT_RESIDENT_START__ = .;

View File

@ -27,6 +27,9 @@ SECTIONS {
#if SEPARATE_CODE_AND_RODATA
.text . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".text address is not aligned on a page boundary.");
__TEXT_START__ = .;
*bl2u_entrypoint.o(.text*)
@ -60,6 +63,9 @@ SECTIONS {
} >RAM
#else /* SEPARATE_CODE_AND_RODATA */
.ro . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".ro address is not aligned on a page boundary.");
__RO_START__ = .;
*bl2u_entrypoint.o(.text*)

View File

@ -37,6 +37,9 @@ SECTIONS {
#if SEPARATE_CODE_AND_RODATA
.text . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".text is not aligned on a page boundary.");
__TEXT_START__ = .;
*bl31_entrypoint.o(.text*)
@ -71,6 +74,9 @@ SECTIONS {
} >RAM
#else /* SEPARATE_CODE_AND_RODATA */
.ro . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".ro is not aligned on a page boundary.");
__RO_START__ = .;
*bl31_entrypoint.o(.text*)

View File

@ -29,6 +29,9 @@ SECTIONS {
#if SEPARATE_CODE_AND_RODATA
.text . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".text address is not aligned on a page boundary.");
__TEXT_START__ = .;
*entrypoint.o(.text*)
@ -67,6 +70,9 @@ SECTIONS {
} >RAM
#else /* SEPARATE_CODE_AND_RODATA */
.ro . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".ro address is not aligned on a page boundary.");
__RO_START__ = .;
*entrypoint.o(.text*)

View File

@ -25,6 +25,9 @@ SECTIONS {
#if SEPARATE_CODE_AND_RODATA
.text . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".text address is not aligned on a page boundary.");
__TEXT_START__ = .;
*tsp_entrypoint.o(.text*)
@ -51,6 +54,9 @@ SECTIONS {
} >RAM
#else /* SEPARATE_CODE_AND_RODATA */
.ro . : {
ASSERT(. == ALIGN(PAGE_SIZE),
".ro address is not aligned on a page boundary.");
__RO_START__ = .;
*tsp_entrypoint.o(.text*)