get-needed-libgcc-objects.sh 2.2 KB

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