1 /*
2 * Copyright (c) 2024 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /*
8 * This code demonstrates multi-file object and function linking support.
9 */
10
11 #include <stdint.h>
12 #include <zephyr/llext/symbol.h>
13 #include <zephyr/kernel.h>
14 #include <zephyr/ztest_assert.h>
15
16 /* Test non-static global object relocation */
17 int number = 0x42;
18 extern int ext_number;
19 int ext_sum_fn(int arg);
20
21 int run_id = 41;
22
test_entry(void)23 void test_entry(void)
24 {
25 switch (run_id) {
26 case 41:
27 /* initial run: test variable initialization */
28 break;
29 case 42:
30 /* user-mode run: reinit number */
31 number = 0x42;
32 break;
33 default:
34 /* possible llext loader issue */
35 zassert_unreachable("unexpected run_id %d", run_id);
36 return;
37 }
38
39 printk("initial: local %d plus external %d equals %d\n",
40 number, ext_number, ext_sum_fn(ext_number));
41 zassert_equal(number, 0x42);
42 zassert_equal(ext_number, 0x18);
43 number ^= ext_number;
44 ext_number ^= number;
45 number ^= ext_number;
46 zassert_equal(number, 0x18);
47 zassert_equal(ext_number, 0x42);
48 printk("updated: local %d plus external %d equals %d\n",
49 number, ext_number, ext_sum_fn(ext_number));
50
51 run_id += 1;
52 }
53 EXPORT_SYMBOL(test_entry);
54