From a17fe86de2be667d60abc0b904db81e320645bea Mon Sep 17 00:00:00 2001 From: Patryk Duda Date: Fri, 1 Sep 2023 15:57:18 +0200 Subject: [PATCH] arch: common: Force linker to fill empty spaces in rom_start with 0x00 LLVM LLD fills empty spaces (created using ALIGN() or moving the location counter) in executable segments with TrapInstr pattern, e.g. for ARM the TrapInstr pattern is 0xd4d4d4d4. GNU LD fills empty spaces with 0x00 pattern. We may want to have some section (e.g. rom_start) filled with 0x00, e.g. because MCU can interpret the pattern as a configuration data. Signed-off-by: Patryk Duda --- arch/common/CMakeLists.txt | 4 ++++ arch/common/fill_with_zeros.ld | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 arch/common/fill_with_zeros.ld diff --git a/arch/common/CMakeLists.txt b/arch/common/CMakeLists.txt index 80102d7033..f9c6f8a72b 100644 --- a/arch/common/CMakeLists.txt +++ b/arch/common/CMakeLists.txt @@ -56,6 +56,10 @@ if (DEFINED CONFIG_ARM OR DEFINED CONFIG_X86 OR DEFINED CONFIG_ARM64 # Exclamation mark is printable character with lowest number in ASCII table. # We are sure that this file will be included as a first. zephyr_linker_sources(ROM_START SORT_KEY ! rom_start_address.ld) + # Some linkers fill unspecified region with pattern other than 0x00. Include + # fill_with_zeros.ld file which forces the linker to use 0x00 pattern. Please + # note that the pattern will affect empty spaces created after FILL(0x00). + zephyr_linker_sources(ROM_START SORT_KEY $ fill_with_zeros.ld) zephyr_linker_sources(ROM_START SORT_KEY 0x0 rom_start_offset.ld) # Handled in ld.cmake endif() diff --git a/arch/common/fill_with_zeros.ld b/arch/common/fill_with_zeros.ld new file mode 100644 index 0000000000..b93a5ffead --- /dev/null +++ b/arch/common/fill_with_zeros.ld @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023, Google, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * LLVM LLD fills empty spaces (created using ALIGN() or moving the location + * counter) in executable segments with TrapInstr pattern, e.g. for ARM the + * TrapInstr pattern is 0xd4d4d4d4. GNU LD fills empty spaces with 0x00 + * pattern. + * + * We may want to have some section (e.g. rom_start) filled with 0x00, + * e.g. because MCU can interpret the pattern as a configuration data. + */ +FILL(0x00);