From ba2cb65a9197b0517ace1eada3347d25b10e5d73 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Tue, 8 Mar 2022 22:33:50 +0800 Subject: [PATCH] arch/sim: add all symbols support Signed-off-by: chao.an --- arch/sim/src/Makefile | 22 ++++++++++++ arch/sim/src/sim/up_head.c | 45 ++++++++++++++++++++++++ boards/sim/sim/sim/configs/nsh/defconfig | 2 ++ 3 files changed, 69 insertions(+) diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index e9bed7e1f3..4c0a0740b0 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -31,6 +31,8 @@ CFLAGS += $(INCLUDES) CXXFLAGS += $(INCLUDES) AFLAGS += $(INCLUDES) +NUTTX = $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx$(EXEEXT)) + # Determine which objects are required in the link.The # up_head object normally draws in all that is needed, but # there are a fews that must be included because they @@ -294,6 +296,17 @@ board/libboard$(LIBEXT): nuttx-names.dat: nuttx-names.in $(call PREPROCESS, nuttx-names.in, nuttx-names.dat) +define LINK_ALLSYMS + $(Q) $(TOPDIR)/tools/mkallsyms.sh noconst $(NUTTX) $(CROSSDEV) > allsyms.tmp + $(Q) $(call COMPILE, -x c allsyms.tmp, allsyms$(OBJEXT)) + $(if $(CONFIG_HAVE_CXX),\ + $(Q) "$(CXX)" $(CFLAGS) $(LDFLAGS) -o $(NUTTX) \ + $(HEADOBJ) nuttx.rel $(HOSTOBJS) $(STDLIBS) allsyms$(OBJEXT),\ + $(Q) "$(CC)" $(CFLAGS) $(LDFLAGS) -o $(NUTTX) \ + $(HEADOBJ) nuttx.rel $(HOSTOBJS) $(STDLIBS) allsyms$(OBJEXT)) + $(Q) $(call DELFILE, allsyms.tmp allsyms$(OBJEXT)) +endef + # Note: Use objcopy for Linux because for some reasons visibility=hidden # stuff doesn't work there as we expect. # Note: _stext stuff is for CONFIG_CXX_INITIALIZE_SINIT, which in not @@ -309,9 +322,18 @@ ifneq ($(CONFIG_HOST_MACOS),y) -e 's/__init_array_end/_einit/g' -e 's/__fini_array_start/_sfini/g' -e 's/__fini_array_end/_efini/g' >nuttx.ld $(Q) echo "__init_array_start = .; __init_array_end = .; __fini_array_start = .; __fini_array_end = .;" >>nuttx.ld endif +ifneq ($(CONFIG_ALLSYMS),y) $(if $(CONFIG_HAVE_CXX),\ $(Q) "$(CXX)" $(CFLAGS) $(LDFLAGS) -o $(TOPDIR)/$@ $(HEADOBJ) nuttx.rel $(HOSTOBJS) $(STDLIBS),\ $(Q) "$(CC)" $(CFLAGS) $(LDFLAGS) -o $(TOPDIR)/$@ $(HEADOBJ) nuttx.rel $(HOSTOBJS) $(STDLIBS)) +else + $(Q) # Link and generate default table + $(Q) $(if $(wildcard $(shell echo $(NUTTX))),,$(call LINK_ALLSYMS, $@)) + $(Q) # Extract all symbols + $(Q) $(call LINK_ALLSYMS, $^) + $(Q) # Extract again since the table offset may changed + $(Q) $(call LINK_ALLSYMS, $^) +endif $(Q) $(NM) $(TOPDIR)/$@ | \ grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \ sort > $(TOPDIR)/System.map diff --git a/arch/sim/src/sim/up_head.c b/arch/sim/src/sim/up_head.c index 16f82e4a93..ecccb77d43 100644 --- a/arch/sim/src/sim/up_head.c +++ b/arch/sim/src/sim/up_head.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include "up_internal.h" @@ -52,6 +53,46 @@ char **g_argv; static char g_logbuffer[4096]; #endif +#ifdef CONFIG_ALLSYMS +extern struct symtab_s g_allsyms[]; +extern int g_nallsyms; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: allsyms_relocate + * + * Description: + * Simple relocate to redirect the address from symbol table. + * + ****************************************************************************/ + +#ifdef CONFIG_ALLSYMS +static void allsyms_relocate(void) +{ + uintptr_t offset; + int i; + + for (i = 0; i < g_nallsyms; i++) + { + if (strcmp("allsyms_relocate", g_allsyms[i].sym_name) == 0) + { + offset = (uintptr_t)allsyms_relocate - + (uintptr_t)g_allsyms[i].sym_value; + for (i = 0; i < g_nallsyms; i++) + { + g_allsyms[i].sym_value = + (void *)((uintptr_t)g_allsyms[i].sym_value + offset); + } + break; + } + } +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -70,6 +111,10 @@ int main(int argc, char **argv, char **envp) g_argc = argc; g_argv = argv; +#ifdef CONFIG_ALLSYMS + allsyms_relocate(); +#endif + #ifdef CONFIG_SYSLOG_RPMSG syslog_rpmsg_init_early(g_logbuffer, sizeof(g_logbuffer)); #endif diff --git a/boards/sim/sim/sim/configs/nsh/defconfig b/boards/sim/sim/sim/configs/nsh/defconfig index 85dc828026..a59ef3b581 100644 --- a/boards/sim/sim/sim/configs/nsh/defconfig +++ b/boards/sim/sim/sim/configs/nsh/defconfig @@ -6,6 +6,7 @@ # modifications. # # CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ALLSYMS=y CONFIG_ARCH="sim" CONFIG_ARCH_BOARD="sim" CONFIG_ARCH_BOARD_SIM=y @@ -65,4 +66,5 @@ CONFIG_SCHED_ONEXIT=y CONFIG_SCHED_WAITPID=y CONFIG_START_MONTH=6 CONFIG_START_YEAR=2008 +CONFIG_SYSTEM_DUMPSTACK=y CONFIG_SYSTEM_NSH=y