diff --git a/examples/nsh/Kconfig b/examples/nsh/Kconfig index 0e9cd312e..ddaf4e680 100644 --- a/examples/nsh/Kconfig +++ b/examples/nsh/Kconfig @@ -13,6 +13,23 @@ config EXAMPLES_NSH if EXAMPLES_NSH +config EXAMPLES_NSH_SYMTAB + bool "Register symbol table" + default n + depends on LIBC_EXECFUNCS && LIB_BOARDCTL && !EXECFUNCS_HAVE_SYMTAB + select BOARDCTL_APP_SYMTAB + ---help--- + Enable logic to automatically register an application symbol table + as part of NSH initialization. If enabled, then application logic + must provide the following: + + const struct symtab_s g_exports[]; + const int g_nexports; + + Where g_exports is the name of the exported application symbol table + and g_nexports holds the number of entries in the application symbol + table. + config EXAMPLES_NSH_PROGNAME string "Program name" default "nsh" diff --git a/examples/nsh/nsh_main.c b/examples/nsh/nsh_main.c index 074083786..508938891 100644 --- a/examples/nsh/nsh_main.c +++ b/examples/nsh/nsh_main.c @@ -79,8 +79,17 @@ # undef HAVE_DUMMY_SYMTAB #endif -#if defined(CONFIG_FS_BINFS) && !defined(HAVE_DUMMY_SYMTAB) -# warning "Prequisites not met for BINFS dummy symbol table" +/* If we are going to use the application symbol table, then suppress + * the dummy symbol table. + */ + +#ifdef CONFIG_EXAMPLES_NSH_SYMTAB +# undef HAVE_DUMMY_SYMTAB +#endif + +#if defined(CONFIG_FS_BINFS) && !defined(HAVE_DUMMY_SYMTAB) && \ + !defined(CONFIG_EXAMPLES_NSH_SYMTAB) +# warning "Prequisites not met for BINFS symbol table" #endif /* C++ initialization requires CXX initializer support */ @@ -109,7 +118,7 @@ * Private Data ****************************************************************************/ -#ifdef HAVE_DUMMY_SYMTAB +#if defined(HAVE_DUMMY_SYMTAB) /* If posix_spawn() is enabled as required for CONFIG_NSH_FILE_APPS, then * a symbol table is needed by the internals of posix_spawn(). The symbol * table is needed to support ELF and NXFLAT binaries to dynamically link to @@ -120,7 +129,13 @@ * you want to support ELF or NXFLAT binaries! */ -static const struct symtab_s CONFIG_EXECFUNCS_SYMTAB[1]; /* Wasted memory! */ +static const struct symtab_s g_dummy_symtab[1]; /* Wasted memory! */ + +#elif defined(CONFIG_EXAMPLES_NSH_SYMTAB) + +extern const struct symtab_s g_exports[]; +extern const int g_nexports; + #endif /**************************************************************************** @@ -137,7 +152,7 @@ int main(int argc, FAR char *argv[]) int nsh_main(int argc, char *argv[]) #endif { -#ifdef HAVE_DUMMY_SYMTAB +#if defined(HAVE_DUMMY_SYMTAB) || defined (CONFIG_EXAMPLES_NSH_SYMTAB) struct boardioc_symtab_s symdesc; #endif int exitval = 0; @@ -149,11 +164,18 @@ int nsh_main(int argc, char *argv[]) up_cxxinitialize(); #endif -#ifdef HAVE_DUMMY_SYMTAB +#if defined(HAVE_DUMMY_SYMTAB) || defined (CONFIG_EXAMPLES_NSH_SYMTAB) +#if defined(HAVE_DUMMY_SYMTAB) /* Make sure that we are using our symbol table */ symdesc.symtab = (FAR struct symtab_s *)g_dummy_symtab; /* Discard 'const' */ symdesc.nsymbols = 0; + +#else /* if defined(CONFIG_EXAMPLES_NSH_SYMTAB) */ + symdesc.symtab = (FAR struct symtab_s *)g_exports; /* Discard 'const' */ + symdesc.nsymbols = g_nexports; +#endif + (void)boardctl(BOARDIOC_APP_SYMTAB, (uintptr_t)&symdesc); #endif