Skip to content

Commit 465f6ba

Browse files
bjorniuppsalakartben
authored andcommitted
userspace: weak defintions for generated k-object lookup functions
Instead of obscure linker-file hacks providing dummy definitions before we have the proper generated k-object lookup functions, provide weak definitions that will be taken out by the real generated implementations when they are available. Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
1 parent aa1f9e2 commit 465f6ba

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

cmake/linker_script/common/kobject-text.cmake

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,4 @@ if(CONFIG_USERSPACE)
2424
EXPR
2525
"(@_kobject_text_area_end@ - @_kobject_text_area_start@)"
2626
)
27-
28-
if(CONFIG_DYNAMIC_OBJECTS)
29-
zephyr_linker_section_configure(
30-
SECTION
31-
_kobject_text_area
32-
SYMBOLS
33-
z_object_gperf_find
34-
z_object_gperf_wordlist_foreach
35-
PASS NOT LINKER_ZEPHYR_FINAL
36-
)
37-
else()
38-
zephyr_linker_section_configure(
39-
SECTION
40-
_kobject_text_area
41-
SYMBOLS
42-
k_object_find
43-
k_object_wordlist_foreach
44-
PASS NOT LINKER_ZEPHYR_FINAL
45-
)
46-
endif()
47-
48-
endif()
27+
endif()

include/zephyr/linker/kobject-text.ld

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
*(".kobject_data.text*")
1515
PLACE_SYMBOL_HERE(_kobject_text_area_end);
1616
_kobject_text_area_used = _kobject_text_area_end - _kobject_text_area_start;
17-
#ifndef LINKER_ZEPHYR_FINAL
18-
#ifdef CONFIG_DYNAMIC_OBJECTS
19-
PROVIDE(z_object_gperf_find = .);
20-
PROVIDE(z_object_gperf_wordlist_foreach = .);
21-
#else
22-
PROVIDE(k_object_find = .);
23-
PROVIDE(k_object_wordlist_foreach = .);
24-
#endif
25-
#endif
2617

2718
/* In a valid build the MAX function will always evaluate to the
2819
second argument below, but to give the user a good error message

kernel/userspace.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,33 @@ void k_object_wordlist_foreach(_wordlist_cb_func_t func, void *context)
521521
}
522522
#endif /* CONFIG_DYNAMIC_OBJECTS */
523523

524+
/* In the earlier linker-passes before we have the real generated
525+
* implementation of the lookup functions, we need some weak dummies.
526+
* Being __weak, they will be replaced by the generated implementations in
527+
* the later linker passes.
528+
*/
529+
#ifdef CONFIG_DYNAMIC_OBJECTS
530+
Z_GENERIC_SECTION(.kobject_data.text.dummies)
531+
__weak struct k_object *z_object_gperf_find(const void *obj)
532+
{
533+
return NULL;
534+
}
535+
Z_GENERIC_SECTION(.kobject_data.text.dummies)
536+
__weak void z_object_gperf_wordlist_foreach(_wordlist_cb_func_t func, void *context)
537+
{
538+
}
539+
#else
540+
Z_GENERIC_SECTION(.kobject_data.text.dummies)
541+
__weak struct k_object *k_object_find(const void *obj)
542+
{
543+
return NULL;
544+
}
545+
Z_GENERIC_SECTION(.kobject_data.text.dummies)
546+
__weak void k_object_wordlist_foreach(_wordlist_cb_func_t func, void *context)
547+
{
548+
}
549+
#endif
550+
524551
static unsigned int thread_index_get(struct k_thread *thread)
525552
{
526553
struct k_object *ko;

0 commit comments

Comments
 (0)