diff --git a/tests/subsys/llext/CMakeLists.txt b/tests/subsys/llext/CMakeLists.txt index 31730e2a2c7e..6d402c585475 100644 --- a/tests/subsys/llext/CMakeLists.txt +++ b/tests/subsys/llext/CMakeLists.txt @@ -25,6 +25,7 @@ set(ext_names threads_kernel_objects export_dependent export_dependency + align ) if(CONFIG_ARM) diff --git a/tests/subsys/llext/src/align_ext.c b/tests/subsys/llext/src/align_ext.c new file mode 100644 index 000000000000..52bd36fe4937 --- /dev/null +++ b/tests/subsys/llext/src/align_ext.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 Arduino SA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * Define symbols with different alignment requirements and verify that LLEXT + * correctly handles them by testing the runtime address and the contents of + * each defined symbol. + */ + +#include +#include +#include +#include + +/* + * Create constants requesting a specific alignment in memory and with a value + * that is related but not equal to their alignment requirement. + */ +#define ALIGNED_ENTRY(name, n) \ + const int name ## _ ## n __aligned(n) = n / 2 + 1 + +ALIGNED_ENTRY(common, 8); +ALIGNED_ENTRY(common, 16); +ALIGNED_ENTRY(common, 32); +ALIGNED_ENTRY(common, 64); +ALIGNED_ENTRY(common, 128); +ALIGNED_ENTRY(common, 256); +ALIGNED_ENTRY(common, 512); + +/* + * Create similar constants in a set of independent sections to test merging. + */ +#define ALIGNED_SECT_ENTRY(name, n) \ + Z_GENERIC_SECTION(name ## _sect_ ## n) ALIGNED_ENTRY(name, n) + +ALIGNED_SECT_ENTRY(independent, 8); +ALIGNED_SECT_ENTRY(independent, 16); +ALIGNED_SECT_ENTRY(independent, 32); +ALIGNED_SECT_ENTRY(independent, 64); +ALIGNED_SECT_ENTRY(independent, 128); +ALIGNED_SECT_ENTRY(independent, 256); +ALIGNED_SECT_ENTRY(independent, 512); + +/* + * Test that each symbol matches its expected value and alignment. + */ +#define ASSERT_ENTRY(name, n) \ + zassert_equal(name ## _ ## n, n / 2 + 1); \ + zassert_true(IS_ALIGNED(&name ## _ ## n, n)) + +void test_entry(void) +{ + ASSERT_ENTRY(common, 8); + ASSERT_ENTRY(common, 16); + ASSERT_ENTRY(common, 32); + ASSERT_ENTRY(common, 64); + ASSERT_ENTRY(common, 128); + ASSERT_ENTRY(common, 256); + ASSERT_ENTRY(common, 512); + + ASSERT_ENTRY(independent, 8); + ASSERT_ENTRY(independent, 16); + ASSERT_ENTRY(independent, 32); + ASSERT_ENTRY(independent, 64); + ASSERT_ENTRY(independent, 128); + ASSERT_ENTRY(independent, 256); + ASSERT_ENTRY(independent, 512); +} +EXPORT_SYMBOL(test_entry); diff --git a/tests/subsys/llext/src/detached_fn_ext.c b/tests/subsys/llext/src/detached_fn_ext.c index a1cbaa62d805..a112046e8cd4 100644 --- a/tests/subsys/llext/src/detached_fn_ext.c +++ b/tests/subsys/llext/src/detached_fn_ext.c @@ -9,7 +9,7 @@ #include #include -__section(".detach") void detached_entry(void) +Z_GENERIC_SECTION(.detach) void detached_entry(void) { static int data_cnt = -3; static unsigned int bss_cnt; diff --git a/tests/subsys/llext/src/test_llext.c b/tests/subsys/llext/src/test_llext.c index d9bf11ce4334..528ab37a730f 100644 --- a/tests/subsys/llext/src/test_llext.c +++ b/tests/subsys/llext/src/test_llext.c @@ -317,6 +317,11 @@ LLEXT_LOAD_UNLOAD(threads_kernel_objects, .test_setup = threads_objects_test_setup, ) +static LLEXT_CONST uint8_t align_ext[] ELF_ALIGN = { + #include "align.inc" +}; +LLEXT_LOAD_UNLOAD(align) + static LLEXT_CONST uint8_t inspect_ext[] ELF_ALIGN = { #include "inspect.inc" };