get-needed-libgcc-objects.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. #
  3. # Manuel Novoa III Jan 2001
  4. #
  5. # The purpose of this script is to extract the object files from libgcc.a
  6. # that are needed by the shared uClibc so that they won't be linked with
  7. # each application.
  8. #
  9. # I'm sure people with better shell programming skills can improve this.
  10. # Feel free! ;-) At this point though, it gets the job done for me.
  11. #
  12. # Possible problems (paranioa mode): Are any of the objects in libgcc.a
  13. # needed to actually load the shared library on any archs?
  14. #Enable this when debugging
  15. #set -x
  16. echo Finding missing symbols in libc.a ...
  17. echo " partial linking..."
  18. rm -f libc.ldr
  19. $LD $LDFLAGS -r -o libc.ldr $CRTOBJS --whole-archive ../libc.a
  20. if $NM --undefined-only libc.ldr 2>&1 | sed -e 's/ *$//' | sed -e 's/^.*U *//' | grep -v "main$" | grep -v "_GLOBAL_OFFSET_TABLE_$" | grep -v "_gp_disp" | grep -v "^etext$" | grep -v "^__gmon_start__$" > sym.need ; then
  21. EXIT_WITH_ERROR=0
  22. rm -f obj.need
  23. touch obj.need
  24. for SYM in `cat sym.need | sed -e 's/ U //g'` ; do
  25. if $NM -s $LIBGCC 2>&1 | grep -q $SYM" in " ; then
  26. $NM -s $LIBGCC 2>&1 | grep $SYM" in " | cut -d' ' -f3 >> obj.need
  27. else
  28. echo Symbol $SYM needed by libc.a but not found in libgcc.a
  29. EXIT_WITH_ERROR=1
  30. fi
  31. done
  32. if [ $EXIT_WITH_ERROR != 0 ]; then
  33. exit $EXIT_WITH_ERROR
  34. fi
  35. else
  36. echo No missing symbols found.
  37. exit 0
  38. fi
  39. rm -rf tmp-gcc
  40. mkdir tmp-gcc
  41. (cd tmp-gcc && $AR -x $LIBGCC)
  42. rm -f libgcc.ldr
  43. echo Extracting referenced libgcc.a objects ...
  44. rm -f obj.need.0
  45. touch obj.need.0
  46. cmp -s obj.need obj.need.0 ; state=$?
  47. while [ -s obj.need ] && [ $state -ne 0 ] ; do
  48. (cd tmp-gcc && cat ../obj.need | sort | uniq | xargs $LD $LDFLAGS -r -o ../libgcc.ldr)
  49. cp obj.need obj.need.0
  50. if $NM --undefined-only libgcc.ldr | grep -v "^_GLOBAL_OFFSET_TABLE_$" > sym.need 2>&1 ; then
  51. for SYM in `cat sym.need | sed -e 's/ U //g'` ; do
  52. if $NM -s $LIBGCC 2>&1 | grep -q $SYM" in " ; then
  53. $NM -s $LIBGCC 2>&1 | grep $SYM" in " | cut -d' ' -f3 >> obj.need
  54. fi
  55. done
  56. fi
  57. cmp -s obj.need obj.need.0 ; state=$?
  58. done
  59. cat obj.need | sort | uniq > obj.need.0
  60. (cd tmp-gcc && cp `cat ../obj.need` ..)
  61. if [ -s obj.need.0 ] ; then
  62. echo Objects added from $LIBGCC:
  63. cat obj.need.0
  64. (cd tmp-gcc && cat ../obj.need | sort | uniq | xargs $AR r ../libgcc-need.a)
  65. else
  66. echo No objects added from $LIBGCC.
  67. fi
  68. if [ -s sym.need ] ; then
  69. echo Symbols missing from libgcc.a:
  70. cat sym.need
  71. else
  72. echo Done
  73. fi
  74. exit 0