diff --git a/Makefile b/Makefile index dbcc4b63c..fdca28598 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,7 @@ else $(SYMTABSRC): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) $(Q) $(MAKE) install TOPDIR="$(TOPDIR)" - $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) $@.tmp + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) >$@.tmp $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) $(SYMTABOBJ): %$(OBJEXT): %.c diff --git a/examples/elf/tests/Makefile b/examples/elf/tests/Makefile index 20230d8dd..620b83c28 100644 --- a/examples/elf/tests/Makefile +++ b/examples/elf/tests/Makefile @@ -124,7 +124,7 @@ $(DIRLIST_SRC): install # Create the exported symbol table $(SYMTAB_SRC): install - $(Q) $(TESTS_DIR)/mksymtab.sh $(FSIMG_DIR) >$@.tmp + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(FSIMG_DIR) g_elf >$@.tmp $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) # Clean each subdirectory diff --git a/examples/elf/tests/mksymtab.sh b/examples/elf/tests/mksymtab.sh deleted file mode 100755 index f422c11cc..000000000 --- a/examples/elf/tests/mksymtab.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash - -usage="Usage: $0 " - -# Check for the required ROMFS directory path - -dir=$1 -if [ -z "$dir" ]; then - echo "ERROR: Missing " - echo "" - echo $usage - exit 1 -fi - -if [ ! -d "$dir" ]; then - echo "ERROR: Directory $dir does not exist" - echo "" - echo $usage - exit 1 -fi - -# Extract all of the undefined symbols from the ELF files and create a -# list of sorted, unique undefined variable names. - -varlist=`find ${dir} -type f -perm -a=x | xargs nm | fgrep ' U ' | sed -e "s/^[ ]*//g" | cut -d' ' -f2 | sort | uniq` - -# 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 -# failed - -echo "#include " -echo "#include " -echo "" - -for var in $varlist; do - echo "extern void *${var};" -done - -echo "" -echo "const struct symtab_s g_elf_exports[] = " -echo "{" - -for var in $varlist; do - echo " {\"${var}\", &${var}}," -done - -echo "};" -echo "" -echo "const int g_elf_nexports = sizeof(g_elf_exports) / sizeof(struct symtab_s);" diff --git a/examples/module/drivers/Makefile b/examples/module/drivers/Makefile index 5e20eafd7..756eabafc 100644 --- a/examples/module/drivers/Makefile +++ b/examples/module/drivers/Makefile @@ -107,7 +107,7 @@ endif # Create the exported symbol table $(SYMTAB_SRC): install - $(Q) $(DRIVER_DIR)/mksymtab.sh $(FSROOT_DIR) >$@.tmp + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(FSROOT_DIR) g_mod >$@.tmp $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) # Copy the symbol table into the kernel pass1/ build directory diff --git a/examples/module/drivers/mksymtab.sh b/examples/module/drivers/mksymtab.sh deleted file mode 100755 index 77ef4dd7a..000000000 --- a/examples/module/drivers/mksymtab.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash - -usage="Usage: $0 " - -# Check for the required ROMFS directory path - -dir=$1 -if [ -z "$dir" ]; then - echo "ERROR: Missing " - echo "" - echo $usage - exit 1 -fi - -if [ ! -d "$dir" ]; then - echo "ERROR: Directory $dir does not exist" - echo "" - echo $usage - exit 1 -fi - -# Extract all of the undefined symbols from the MODULE files and create a -# list of sorted, unique undefined variable names. - -varlist=`find ${dir} -type f -perm -a=x | xargs nm | fgrep ' U ' | sed -e "s/^[ ]*//g" | cut -d' ' -f2 | sort | uniq` - -# 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 -# failed - -echo "#include " -echo "#include " -echo "" - -for var in $varlist; do - echo "extern void *${var};" -done - -echo "" -echo "const struct symtab_s g_mod_exports[] = " -echo "{" - -for var in $varlist; do - echo " {\"${var}\", &${var}}," -done - -echo "};" -echo "" -echo "const int g_mod_nexports = sizeof(g_mod_exports) / sizeof(struct symtab_s);" diff --git a/examples/nxflat/tests/Makefile b/examples/nxflat/tests/Makefile index 2c79cb793..0d125aa7a 100644 --- a/examples/nxflat/tests/Makefile +++ b/examples/nxflat/tests/Makefile @@ -88,7 +88,7 @@ $(DIRLIST_SRC): install # Create the exported symbol table list from the derived *-thunk.S files $(SYMTAB_SRC): install - $(Q) $(TESTS_DIR)/mksymtab.sh $(ROMFS_DIR) >$@.tmp + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(ROMFS_DIR) g_nxflat >$@.tmp $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) # Clean each subdirectory diff --git a/examples/nxflat/tests/mksymtab.sh b/examples/nxflat/tests/mksymtab.sh deleted file mode 100755 index 0f6ab877c..000000000 --- a/examples/nxflat/tests/mksymtab.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env bash - -usage="Usage: $0 " - -dir=$1 -if [ -z "$dir" ]; then - echo "ERROR: Missing " - echo "" - echo $usage - exit 1 -fi - -if [ ! -d "$dir" ]; then - echo "ERROR: Directory $dir does not exist" - echo "" - echo $usage - exit 1 -fi - -varlist=`find $dir -name "*-thunk.S"| xargs grep -h asciz | cut -f3 | sort | uniq` - -# 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 -# failed - -echo "#include " -echo "#include " -echo "" - -for var in $varlist; do - echo "extern void *${var};" -done - -echo "" -echo "const struct symtab_s g_nxflat_exports[] = " -echo "{" - -for string in $varlist; do - var=`echo $string | sed -e "s/\"//g"` - echo " {$string, $var}," -done - -echo "};" -echo "" -echo "const int g_nxflat_nexports = sizeof(g_nxflat_exports) / sizeof(struct symtab_s);" diff --git a/examples/posix_spawn/filesystem/Makefile b/examples/posix_spawn/filesystem/Makefile index ae13c9640..088b373a9 100644 --- a/examples/posix_spawn/filesystem/Makefile +++ b/examples/posix_spawn/filesystem/Makefile @@ -73,7 +73,7 @@ $(ROMFS_SRC): $(ROMFS_IMG) # Create the exported symbol table $(SYMTAB_SRC): $(ROMFS_IMG) - $(Q) $(FILESYSTEM_DIR)$(DELIM)mksymtab.sh $(ROMFS_DIR) >$@.tmp + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(ROMFS_DIR) g_spawn >$@.tmp $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) # Clean each subdirectory diff --git a/examples/posix_spawn/filesystem/mksymtab.sh b/examples/posix_spawn/filesystem/mksymtab.sh deleted file mode 100755 index 05384be86..000000000 --- a/examples/posix_spawn/filesystem/mksymtab.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash - -usage="Usage: $0 " - -# Check for the required ROMFS directory path - -dir=$1 -if [ -z "$dir" ]; then - echo "ERROR: Missing " - echo "" - echo $usage - exit 1 -fi - -if [ ! -d "$dir" ]; then - echo "ERROR: Directory $dir does not exist" - echo "" - echo $usage - exit 1 -fi - -# Extract all of the undefined symbols from the ELF files and create a -# list of sorted, unique undefined variable names. - -varlist=`find ${dir} -type f -perm -a=x | xargs nm | fgrep ' U ' | sed -e "s/^[ ]*//g" | cut -d' ' -f2 | sort | uniq` - -# 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 -# failed - -echo "#include " -echo "#include " -echo "" - -for var in $varlist; do - echo "extern void *${var};" -done - -echo "" -echo "const struct symtab_s g_spawn_exports[] = " -echo "{" - -for var in $varlist; do - echo " {\"${var}\", &${var}}," -done - -echo "};" -echo "" -echo "const int g_spawn_nexports = sizeof(g_spawn_exports) / sizeof(struct symtab_s);" diff --git a/examples/sotest/lib/Makefile b/examples/sotest/lib/Makefile index 795a95ee9..8a0117c9c 100644 --- a/examples/sotest/lib/Makefile +++ b/examples/sotest/lib/Makefile @@ -84,7 +84,7 @@ endif # Create the exported symbol table $(SYMTAB_SRC): install - $(Q) $(LIB_DIR)/mksymtab.sh $(FSROOT_DIR) >$@.tmp + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(FSROOT_DIR) g_sot | sed "/modprint/d" >$@.tmp $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) # Clean each subdirectory diff --git a/examples/sotest/lib/mksymtab.sh b/examples/sotest/lib/mksymtab.sh deleted file mode 100755 index 28db68f97..000000000 --- a/examples/sotest/lib/mksymtab.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash -# set -x - -usage="Usage: $0 " - -# Check for the required ROMFS directory path - -dir=$1 -if [ -z "$dir" ]; then - echo "ERROR: Missing " - echo "" - echo $usage - exit 1 -fi - -if [ ! -d "$dir" ]; then - echo "ERROR: Directory $dir does not exist" - echo "" - echo $usage - exit 1 -fi - -# Extract all of the undefined symbols from the SOTEST files and create a -# list of sorted, unique undefined variable names. - -tmplist=`find ${dir} -type f -perm -a=x | xargs nm | fgrep ' U ' | sed -e "s/^[ ]*//g" | cut -d' ' -f2 | sort | uniq` - -# Remove the special symbol 'modprint'. It it is not exported by the -# base firmware, but rather in this test from one shared library to another. - -varlist=`echo $tmplist | sed -e "s/modprint//g"` - -# 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 -# fail - -echo "#include " -echo "#include " -echo "" - -for var in $varlist; do - echo "extern void *${var};" -done - -echo "" -echo "const struct symtab_s g_sot_exports[] = " -echo "{" - -for var in $varlist; do - echo " {\"${var}\", &${var}}," -done - -echo "};" -echo "" -echo "const int g_sot_nexports = sizeof(g_sot_exports) / sizeof(struct symtab_s);" diff --git a/examples/thttpd/content/Makefile.nxflat b/examples/thttpd/content/Makefile.nxflat index 9350da7d2..738424220 100644 --- a/examples/thttpd/content/Makefile.nxflat +++ b/examples/thttpd/content/Makefile.nxflat @@ -76,7 +76,7 @@ $(ROMFS_SRC): $(ROMFS_IMG) # Create the exported symbol table list from the derived *-thunk.S files $(SYMTAB_SRC): install - $(Q) $(CONTENT_DIR)/mksymtab.sh $(CONTENT_DIR) >$@.tmp + $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(CONTENT_DIR) g_thttpd >$@.tmp $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) # Nothing special needs to be done during the context phase diff --git a/examples/thttpd/content/mksymtab.sh b/examples/thttpd/content/mksymtab.sh deleted file mode 100755 index f9bb735d3..000000000 --- a/examples/thttpd/content/mksymtab.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash - -usage="Usage: %0 " - -dir=$1 -if [ -z "$dir" ]; then - echo "ERROR: Missing " - echo "" - echo $usage - exit 1 -fi - -if [ ! -d "$dir" ]; then - echo "ERROR: Directory $dir does not exist" - echo "" - echo $usage - exit 1 -fi - -varlist=`find $dir -name "*-thunk.S"| xargs grep -h asciz | cut -f3 | sort | uniq` - -# 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 -# failed - -echo "#include " -echo "#include " -echo "" - -for var in $varlist; do - echo "extern void *${var};" -done - -echo "" -echo "const struct symtab_s g_thttpd_exports[] = " -echo "{" - -for string in $varlist; do - var=`echo $string | sed -e "s/\"//g"` - echo " {$string, $var}," -done - -echo "};" -echo "const int g_thttpd_nexports = sizeof(g_thttpd_exports) / sizeof(struct symtab_s);" diff --git a/tools/mksymtab.sh b/tools/mksymtab.sh index c78fdea2f..811a886c5 100755 --- a/tools/mksymtab.sh +++ b/tools/mksymtab.sh @@ -36,7 +36,7 @@ export LC_ALL=C -usage="Usage: $0 " +usage="Usage: $0 [symtabprefix]" # Check for the required directory path @@ -48,29 +48,19 @@ if [ -z "$dir" ]; then exit 1 fi -# Get the output file name +# Get the symbol table prefix -outfile=$2 -if [ -z "$outfile" ]; then - echo "ERROR: Missing " - echo "" - echo $usage - exit 1 -fi - -rm -f $outfile +prefix=$2 # Extract all of the undefined symbols from the ELF files and create a # list of sorted, unique undefined variable names. -execlist=`find ${dir} -type f 2>/dev/null` -if [ ! -z "${execlist}" ]; then - for exec in ${execlist}; do - nm $exec | fgrep ' U ' | sed -e "s/^[ ]*//g" | cut -d' ' -f2 >>_tmplist - done - - varlist=`cat _tmplist | sort - | uniq -` - rm -f _tmplist +varlist=`find $dir -name *-thunk.S 2>/dev/null | xargs grep -h asciz | cut -f3 | sort | uniq` +if [ -z "$varlist" ]; then + execlist=`find $dir -type f -perm -a=x 2>/dev/null` + if [ ! -z "$execlist" ]; then + varlist=`nm $execlist | fgrep ' U ' | sed -e "s/^[ ]*//g" | cut -d' ' -f2 | sort | uniq` + fi fi # Now output the symbol table as a structure in a C source file. All @@ -78,34 +68,42 @@ fi # any kind of checking for function vs. data objects, then this could # failed -echo "#include " >$outfile -echo "#include " >>$outfile -echo "" >>$outfile +echo "#include " +echo "#include " +echo "" for var in $varlist; do - echo "extern void *${var};" >>$outfile + echo "extern void *${var};" done -echo "" >>$outfile -echo "#if defined(CONFIG_EXECFUNCS_HAVE_SYMTAB)" >>$outfile -echo "const struct symtab_s CONFIG_EXECFUNCS_SYMTAB_ARRAY[] = " >>$outfile -echo "#elif defined(CONFIG_SYSTEM_NSH_SYMTAB)" >>$outfile -echo "const struct symtab_s CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME[] = " >>$outfile -echo "#else" >>$outfile -echo "const struct symtab_s dummy_symtab[] = " >>$outfile -echo "#endif" >>$outfile -echo "{" >>$outfile +echo "" +if [ -z "$prefix" ]; then + echo "#if defined(CONFIG_EXECFUNCS_HAVE_SYMTAB)" + echo "const struct symtab_s CONFIG_EXECFUNCS_SYMTAB_ARRAY[] = " + echo "#elif defined(CONFIG_SYSTEM_NSH_SYMTAB)" + echo "const struct symtab_s CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME[] = " + echo "#else" + echo "const struct symtab_s dummy_symtab[] = " + echo "#endif" +else + echo "const struct symtab_s ${prefix}_exports[] = " +fi +echo "{" for var in $varlist; do - echo " {\"${var}\", &${var}}," >>$outfile + echo " {\"${var}\", &${var}}," done -echo "};" >>$outfile -echo "" >>$outfile -echo "#if defined(CONFIG_EXECFUNCS_HAVE_SYMTAB)" >>$outfile -echo "const int CONFIG_EXECFUNCS_NSYMBOLS_VAR = sizeof(CONFIG_EXECFUNCS_SYMTAB_ARRAY) / sizeof(struct symtab_s);" >>$outfile -echo "#elif defined(CONFIG_SYSTEM_NSH_SYMTAB)" >>$outfile -echo "const int CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME = sizeof(CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME) / sizeof(struct symtab_s);" >>$outfile -echo "#else" >>$outfile -echo "const int dummy_nsymtabs = sizeof(dummy_symtab) / sizeof(struct symtab_s);" >>$outfile -echo "#endif" >>$outfile +echo "};" +echo "" +if [ -z "$prefix" ]; then + echo "#if defined(CONFIG_EXECFUNCS_HAVE_SYMTAB)" + echo "const int CONFIG_EXECFUNCS_NSYMBOLS_VAR = sizeof(CONFIG_EXECFUNCS_SYMTAB_ARRAY) / sizeof(struct symtab_s);" + echo "#elif defined(CONFIG_SYSTEM_NSH_SYMTAB)" + echo "const int CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME = sizeof(CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME) / sizeof(struct symtab_s);" + echo "#else" + echo "const int dummy_nsymtabs = sizeof(dummy_symtab) / sizeof(struct symtab_s);" + echo "#endif" +else + echo "const int ${prefix}_nexports = sizeof(${prefix}_exports) / sizeof(struct symtab_s);" +fi