From 7f7ff8c7d450abdf28b27acfc20ea43b1c848e59 Mon Sep 17 00:00:00 2001 From: wangjianyu3 Date: Wed, 27 Mar 2024 11:04:45 +0800 Subject: [PATCH] tools/mksymtab.sh: Support adding additional symbols that are not in undefined list e.g. For CHRE dynamic nanoapps, pre-saving symbols that may be used later, no need recompiling. Test: (unique & sorted) $ nm ./hello_world.o | grep " U " U __aeabi_unwind_cpp_pr1 U chreGetTime U chreGetVersion U chreLog U __stack_chk_fail U __stack_chk_guard $ cat additional.txt -n 1 test_symbol 2 test_symbol $ /PATH/TO/APPS/tools/mksymtab.sh ./hello_world.o MY_PREFIX -a additional.txt #include #include extern void *__aeabi_unwind_cpp_pr1; extern void *__stack_chk_fail; extern void *__stack_chk_guard; extern void *chreGetTime; extern void *chreGetVersion; extern void *chreLog; extern void *test_symbol; const struct symtab_s MY_PREFIX_exports[] = { {"__aeabi_unwind_cpp_pr1", &__aeabi_unwind_cpp_pr1}, {"__stack_chk_fail", &__stack_chk_fail}, {"__stack_chk_guard", &__stack_chk_guard}, {"chreGetTime", &chreGetTime}, {"chreGetVersion", &chreGetVersion}, {"chreLog", &chreLog}, {"test_symbol", &test_symbol}, }; const int MY_PREFIX_nexports = sizeof(MY_PREFIX_exports) / sizeof(struct symtab_s); Signed-off-by: wangjianyu3 --- tools/mksymtab.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/mksymtab.sh b/tools/mksymtab.sh index e72196791..4f1d7f481 100755 --- a/tools/mksymtab.sh +++ b/tools/mksymtab.sh @@ -21,7 +21,7 @@ export LC_ALL=C -usage="Usage: $0 [symtabprefix]" +usage="Usage: $0 [symtabprefix [additionalsymbolspath]]" # Check for the required directory path @@ -36,6 +36,7 @@ fi # Get the symbol table prefix prefix=$2 +add_sym=$3 # Extract all of the undefined symbols from the ELF files and create a # list of sorted, unique undefined variable names. @@ -59,6 +60,18 @@ if [ -z "$varlist" ]; then fi fi +if [ "x$add_sym" != "x" ]; then + if [ -f $add_sym ]; then + varlist="${varlist}\n$(cat $add_sym)" + elif [ -d $add_sym ]; then + varlist="${varlist}\n$(find $add_sym -type f | xargs cat)" + else + echo $usage + exit 1 + fi + varlist=$(echo -e "${varlist}" | sort -u) +fi + # Now output the symbol table as a structure in a C source file. All # undefined symbols are declared as void* types. If the toolchain does # any kind of checking for function vs. data objects, then this could