mksymtab.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env bash
  2. ############################################################################
  3. # apps/tools/mksymtab.sh
  4. #
  5. # Licensed to the Apache Software Foundation (ASF) under one or more
  6. # contributor license agreements. See the NOTICE file distributed with
  7. # this work for additional information regarding copyright ownership. The
  8. # ASF licenses this file to you under the Apache License, Version 2.0 (the
  9. # "License"); you may not use this file except in compliance with the
  10. # License. You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  17. # License for the specific language governing permissions and limitations
  18. # under the License.
  19. #
  20. ############################################################################
  21. export LC_ALL=C
  22. usage="Usage: $0 <imagedirpath> [symtabprefix]"
  23. # Check for the required directory path
  24. dir=$1
  25. if [ -z "$dir" ]; then
  26. echo "ERROR: Missing <imagedirpath>"
  27. echo ""
  28. echo $usage
  29. exit 1
  30. fi
  31. # Get the symbol table prefix
  32. prefix=$2
  33. # Extract all of the undefined symbols from the ELF files and create a
  34. # list of sorted, unique undefined variable names.
  35. varlist=`find $dir -name *-thunk.S 2>/dev/null | xargs grep -h asciz | cut -f3 | sort | uniq`
  36. if [ -z "$varlist" ]; then
  37. execlist=`find $dir -type f -perm -a=x 2>/dev/null`
  38. if [ ! -z "$execlist" ]; then
  39. varlist=`nm $execlist | fgrep ' U ' | sed -e "s/^[ ]*//g" | cut -d' ' -f2 | sort | uniq`
  40. fi
  41. fi
  42. # Now output the symbol table as a structure in a C source file. All
  43. # undefined symbols are declared as void* types. If the toolchain does
  44. # any kind of checking for function vs. data objects, then this could
  45. # failed
  46. echo "#include <nuttx/compiler.h>"
  47. echo "#include <nuttx/symtab.h>"
  48. echo ""
  49. for string in $varlist; do
  50. var=`echo $string | sed -e "s/\"//g"`
  51. echo "extern void *${var};"
  52. done
  53. echo ""
  54. if [ -z "$prefix" ]; then
  55. echo "#if defined(CONFIG_EXECFUNCS_HAVE_SYMTAB)"
  56. echo "const struct symtab_s CONFIG_EXECFUNCS_SYMTAB_ARRAY[] = "
  57. echo "#elif defined(CONFIG_SYSTEM_NSH_SYMTAB)"
  58. echo "const struct symtab_s CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME[] = "
  59. echo "#else"
  60. echo "const struct symtab_s dummy_symtab[] = "
  61. echo "#endif"
  62. else
  63. echo "const struct symtab_s ${prefix}_exports[] = "
  64. fi
  65. echo "{"
  66. for string in $varlist; do
  67. var=`echo $string | sed -e "s/\"//g"`
  68. echo " {\"${var}\", &${var}},"
  69. done
  70. echo "};"
  71. echo ""
  72. if [ -z "$prefix" ]; then
  73. echo "#if defined(CONFIG_EXECFUNCS_HAVE_SYMTAB)"
  74. echo "const int CONFIG_EXECFUNCS_NSYMBOLS_VAR = sizeof(CONFIG_EXECFUNCS_SYMTAB_ARRAY) / sizeof(struct symtab_s);"
  75. echo "#elif defined(CONFIG_SYSTEM_NSH_SYMTAB)"
  76. echo "const int CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME = sizeof(CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME) / sizeof(struct symtab_s);"
  77. echo "#else"
  78. echo "const int dummy_nsymtabs = sizeof(dummy_symtab) / sizeof(struct symtab_s);"
  79. echo "#endif"
  80. else
  81. echo "const int ${prefix}_nexports = sizeof(${prefix}_exports) / sizeof(struct symtab_s);"
  82. fi