Zeroing the BSS and copying data to RAM with regular memset/memcpy may
cause problems when those functions are assuming a fully initialized
system for their optimizations to work e.g. some instructions require
an active MMU, but turning the MMU on needs the .bss section to be
cleared first, etc.
Commit c5b898743a ("aarch64: Fix alignment fault on z_bss_zero()")
provides a detailed explanation of such a case.
Replacing z_bss_zero() with an architecture specific one is problematic
as the former may see new sections added to it that would be missed by
the later. The same reasoning goes for z_data_copy().
Let's make maintenance much easier by providing weak versions of
memset/memcpy that can be overridden by architecture-specific safe
versions when needed.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
33 lines
1.3 KiB
CMake
33 lines
1.3 KiB
CMake
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
# See root CMakeLists.txt for description and expectations of these macros
|
|
|
|
macro(toolchain_ld_relocation)
|
|
set(MEM_RELOCATION_LD "${PROJECT_BINARY_DIR}/include/generated/linker_relocate.ld")
|
|
set(MEM_RELOCATION_SRAM_DATA_LD
|
|
"${PROJECT_BINARY_DIR}/include/generated/linker_sram_data_relocate.ld")
|
|
set(MEM_RELOCATION_SRAM_BSS_LD
|
|
"${PROJECT_BINARY_DIR}/include/generated/linker_sram_bss_relocate.ld")
|
|
set(MEM_RELOCATION_CODE "${PROJECT_BINARY_DIR}/code_relocation.c")
|
|
|
|
add_custom_command(
|
|
OUTPUT ${MEM_RELOCATION_CODE} ${MEM_RELOCATION_LD}
|
|
COMMAND
|
|
${PYTHON_EXECUTABLE}
|
|
${ZEPHYR_BASE}/scripts/gen_relocate_app.py
|
|
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
|
|
-d ${APPLICATION_BINARY_DIR}
|
|
-i \"$<TARGET_PROPERTY:code_data_relocation_target,COMPILE_DEFINITIONS>\"
|
|
-o ${MEM_RELOCATION_LD}
|
|
-s ${MEM_RELOCATION_SRAM_DATA_LD}
|
|
-b ${MEM_RELOCATION_SRAM_BSS_LD}
|
|
-c ${MEM_RELOCATION_CODE}
|
|
DEPENDS app kernel ${ZEPHYR_LIBS_PROPERTY}
|
|
)
|
|
|
|
add_library(code_relocation_source_lib STATIC ${MEM_RELOCATION_CODE})
|
|
target_include_directories(code_relocation_source_lib PRIVATE
|
|
${ZEPHYR_BASE}/kernel/include ${ARCH_DIR}/${ARCH}/include)
|
|
target_link_libraries(code_relocation_source_lib zephyr_interface)
|
|
endmacro()
|