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 <bjarki@arge-andreasen.me>
This commit is contained in:
Bjarki Arge Andreasen 2024-03-12 14:19:58 +01:00 committed by Fabio Baltieri
parent 9b583cc539
commit d80945a968
3 changed files with 65 additions and 1 deletions

View File

@ -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)

View File

@ -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 <stdint.h>
#include <zephyr/llext/symbol.h>
#include <zephyr/sys/printk.h>
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);

View File

@ -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.