From 1ba327bd1c3e895675e7ab504af1064635fdf282 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 27 Oct 2012 00:04:47 +0000 Subject: The ELF loader is basically functional (needs more testing) git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5265 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/elf/tests/mksymtab.sh | 50 +++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'apps/examples/elf/tests/mksymtab.sh') diff --git a/apps/examples/elf/tests/mksymtab.sh b/apps/examples/elf/tests/mksymtab.sh index fa1a2d030..56be10f73 100755 --- a/apps/examples/elf/tests/mksymtab.sh +++ b/apps/examples/elf/tests/mksymtab.sh @@ -1,6 +1,24 @@ #!/bin/bash -usage="Usage: %0 " +usage="Usage: $0 [-t ] " + +# Check for the optional tempory file name + +tmpfile=varlist.tmp +if [ "X${1}" = "X-t" ]; then + shift + tmpfile=$1 + shift + + if [ -z "$tmpfile" ]; then + echo "ERROR: Missing " + echo "" + echo $usage + exit 1 + fi +fi + +# Check for the required ROMFS directory path dir=$1 if [ -z "$dir" ]; then @@ -17,23 +35,33 @@ if [ ! -d "$dir" ]; then exit 1 fi -varlist=`find $dir -name "*-thunk.S"| xargs grep -h asciz | cut -f3 | sort | uniq` +# Extract all of the undefined symbols from the ELF files and create a +# list of sorted, unique undefined variable names. -echo "#ifndef __EXAMPLES_ELF_TESTS_SYMTAB_H" -echo "#define __EXAMPLES_ELF_TESTS_SYMTAB_H" -echo "" +varlist=`find ${dir} -executable -type f | 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 +# faile + +echo "#include " echo "#include " echo "" -echo "static const struct symtab_s exports[] = " + +for var in $varlist; do + echo "extern void *${var};" +done + +echo "" +echo "const struct symtab_s exports[] = " echo "{" -for string in $varlist; do - var=`echo $string | sed -e "s/\"//g"` - echo " {$string, $var}," +for var in $varlist; do + echo " {\"${var}\", &${var}}," done echo "};" -echo "#define NEXPORTS (sizeof(exports)/sizeof(struct symtab_s))" echo "" -echo "#endif /* __EXAMPLES_ELF_TESTS_SYMTAB_H */" +echo "const int nexports = sizeof(exports) / sizeof(struct symtab_s);" -- cgit v1.2.3