From d80945a9683fc0feb129fce7ea45e8ceeafd07b7 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Tue, 12 Mar 2024 14:19:58 +0100 Subject: [PATCH] tests: llext: add relative jump test ext.c Validate the new relocations for BL and BLX instructions by creating a new test extension which contains a chain of global functions in a pseudo random order to (hopefully) generate relative jumps in both positive and negative directions. Signed-off-by: Bjarki Arge Andreasen --- tests/subsys/llext/simple/CMakeLists.txt | 2 +- .../llext/simple/src/relative_jump_ext.c | 59 +++++++++++++++++++ .../llext/simple/src/test_llext_simple.c | 5 ++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/subsys/llext/simple/src/relative_jump_ext.c diff --git a/tests/subsys/llext/simple/CMakeLists.txt b/tests/subsys/llext/simple/CMakeLists.txt index 03a781fb74d..e39f4f89008 100644 --- a/tests/subsys/llext/simple/CMakeLists.txt +++ b/tests/subsys/llext/simple/CMakeLists.txt @@ -16,7 +16,7 @@ target_include_directories(app PRIVATE ) # generate extension targets foreach extension given by name -foreach(ext_name hello_world logging) +foreach(ext_name hello_world logging relative_jump) set(ext_src ${PROJECT_SOURCE_DIR}/src/${ext_name}_ext.c) set(ext_bin ${ZEPHYR_BINARY_DIR}/${ext_name}.llext) set(ext_inc ${ZEPHYR_BINARY_DIR}/include/generated/${ext_name}.inc) diff --git a/tests/subsys/llext/simple/src/relative_jump_ext.c b/tests/subsys/llext/simple/src/relative_jump_ext.c new file mode 100644 index 00000000000..0619f201cef --- /dev/null +++ b/tests/subsys/llext/simple/src/relative_jump_ext.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 Trackunit Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * This test is designed to test linking global symbols, which for some architectures + * like ARM generate relative jumps rather than jumping to absolute addresses. Multiple + * global functions are created to hopefully generate both positive and negative relative + * jumps. + */ + +#include +#include +#include + +void test_relative_jump_1(void); +void test_relative_jump_2(void); +void test_relative_jump_3(void); +void test_relative_jump_4(void); +void test_relative_jump_5(void); + +void test_relative_jump_5(void) +{ + printk("relative jump 5\n"); +} + +void test_relative_jump_4(void) +{ + printk("relative jump 4\n"); + test_relative_jump_5(); +} + +void test_relative_jump_2(void) +{ + printk("relative jump 2\n"); + test_relative_jump_3(); +} + +void test_relative_jump_1(void) +{ + printk("relative jump 1\n"); + test_relative_jump_2(); +} + +void test_relative_jump_3(void) +{ + printk("relative jump 3\n"); + test_relative_jump_4(); +} + +void test_entry(void) +{ + printk("enter\n"); + test_relative_jump_1(); + printk("exit\n"); +} +LL_EXTENSION_SYMBOL(test_entry); diff --git a/tests/subsys/llext/simple/src/test_llext_simple.c b/tests/subsys/llext/simple/src/test_llext_simple.c index d3d38a2a3ab..14d224f4779 100644 --- a/tests/subsys/llext/simple/src/test_llext_simple.c +++ b/tests/subsys/llext/simple/src/test_llext_simple.c @@ -147,6 +147,11 @@ static LLEXT_CONST uint8_t logging_ext[] __aligned(4) = { }; LLEXT_LOAD_UNLOAD(logging, true) +static LLEXT_CONST uint8_t relative_jump_ext[] __aligned(4) = { + #include "relative_jump.inc" +}; +LLEXT_LOAD_UNLOAD(relative_jump, true) + /* * Ensure that EXPORT_SYMBOL does indeed provide a symbol and a valid address * to it.