This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 97096bed832fa83b6f6e18f07a07fda29c716020 Author: yinshengkai <[email protected]> AuthorDate: Mon Nov 27 20:04:46 2023 +0800 libs: fix the problem that the address obtained in thumb mode cannot be executed. The lowest bit of the thumb instruction is 1 by default, which is used to distinguish arm instructions and thumb instructions. Fixed the problem of misalignment of symbol table when performing binary search In arm, the lowest bit of the instruction is 1, which is a thumb instruction, and 0, which is an arm instruction. The nm command was used in mkallsym.sh before, and the result it will return will set the lowest bit of the thumb instruction to 0. There will be a one-byte deviation during binary search, so mkallsyms.py will also set the lowest bit to 0 according to the previous format. ```sh arm-none-eabi-nm -Cn nuttx | grep hello 0801c384 T hello_main arm-none-eabi-objdump nuttx -t |grep hello 0801c384 g F .text 0000004c hello_main arm-none-eabi-readelf nuttx -s |grep hello 4558: 0801c385 76 FUNC GLOBAL DEFAULT 1 hello_main ``` However, in the following case, when you need to find the function address according to the symbol name and execute the corresponding function, the lowest address obtained is 0. It will follow the arm instruction, causing an exception. ```c void sym_test(void) { printf("call sym_test\n"); } int main(int argc, FAR char *argv[]) { FAR void *addr = sym_test; printf("sym_test:%p %pS\n",addr, addr); printf("sym_test - 1: %pS\n", (char *)addr - 1); printf("sym_test + 1: %pS\n", (char *)addr + 1); size_t size; void (*func)(void); const struct symtab_s *sym = allsyms_findbyname("sym_test", &size); printf("sym_test:%p %pS\n",sym, sym); func = sym->sym_value; func(); return 0; } ``` Therefore, you need to change mkallsyms.py back to the correct result and correct the binary search. Signed-off-by: yinshengkai <[email protected]> --- libs/libc/symtab/symtab_findbyvalue.c | 2 +- tools/mkallsyms.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/libc/symtab/symtab_findbyvalue.c b/libs/libc/symtab/symtab_findbyvalue.c index 86ac081932..eaed5a0bb7 100644 --- a/libs/libc/symtab/symtab_findbyvalue.c +++ b/libs/libc/symtab/symtab_findbyvalue.c @@ -92,7 +92,7 @@ symtab_findbyvalue(FAR const struct symtab_s *symtab, } else if (symtab[mid].sym_value < value) { - if (symtab[mid + 1].sym_value >= value) + if (symtab[mid + 1].sym_value > value) { break; } diff --git a/tools/mkallsyms.py b/tools/mkallsyms.py index 75488991d5..bfe217efa3 100755 --- a/tools/mkallsyms.py +++ b/tools/mkallsyms.py @@ -110,7 +110,7 @@ class SymbolTables(object): func_name = re.sub(r"\(.*$", "", symbol_name) except cxxfilt.InvalidName: symbol_name = symbol.name - self.symbol_list.append((symbol["st_value"] & ~0x01, func_name)) + self.symbol_list.append((symbol["st_value"], func_name)) if orderbyname: self.symbol_list = sorted(self.symbol_list, key=lambda item: item[1]) else:
