get-needed-libgcc-objects.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. LIBGCC=`$CC -print-libgcc-file-name`
  15. echo Finding missing symbols in libc.a ...
  16. echo " partial linking..."
  17. rm -f libc.ldr
  18. $LD -r -o libc.ldr ../crt0.o --whole-archive ../libc.a
  19. if $NM --undefined-only libc.ldr | grep -v "^main$" > sym.need ; then
  20. rm -f obj.need
  21. touch obj.need
  22. for SYM in `cat sym.need | sed -e 's/ U //g'` ; do
  23. if $NM -s $LIBGCC | grep -q $SYM" in " ; then
  24. $NM -s $LIBGCC | grep $SYM" in " | cut -d' ' -f3 >> obj.need
  25. else
  26. echo Symbol $SYM needed by libc.a but not found in libgcc.a
  27. fi
  28. done
  29. else
  30. echo No missing symbols found.
  31. exit 0
  32. fi
  33. rm -rf tmp-gcc
  34. mkdir tmp-gcc
  35. (cd tmp-gcc ; $AR -x $LIBGCC)
  36. rm -f libgcc.ldr
  37. echo Extracting referenced libgcc.a objects ...
  38. rm -f obj.need.0
  39. touch obj.need.0
  40. while [ -s obj.need ] && ! cmp -s obj.need obj.need.0 ; do
  41. (cd tmp-gcc ; cat ../obj.need | uniq | xargs $LD -r -o ../libgcc.ldr)
  42. cp obj.need obj.need.0
  43. if $NM --undefined-only libgcc.ldr > sym.need ; then
  44. for SYM in `cat sym.need | sed -e 's/ U //g'` ; do
  45. if $NM -s $LIBGCC | grep -q $SYM" in " ; then
  46. $NM -s $LIBGCC | grep $SYM" in " | cut -d' ' -f3 >> obj.need
  47. fi
  48. done
  49. fi
  50. done
  51. cat obj.need | sort | uniq > obj.need.0
  52. (cd tmp-gcc ; cp `cat ../obj.need` ..)
  53. if [ -s obj.need.0 ] ; then
  54. echo Objects added from $LIBGCC:
  55. cat obj.need.0
  56. (cd tmp-gcc ; cat ../obj.need | uniq | xargs $AR r ../libgcc-need.a)
  57. else
  58. echo No objects added from $LIBGCC.
  59. fi
  60. if [ -s sym.need ] ; then
  61. echo Symbols missing from libgcc.a:
  62. cat sym.need
  63. else
  64. echo Done
  65. fi
  66. exit 0