get-needed-libgcc-objects.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_$" | grep -v "_gp_disp" > 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. if [ $EXIT_WITH_ERROR != 0 ]; then
  32. exit $EXIT_WITH_ERROR
  33. fi
  34. else
  35. echo No missing symbols found.
  36. exit 0
  37. fi
  38. rm -rf tmp-gcc
  39. mkdir tmp-gcc
  40. (cd tmp-gcc && $AR -x $LIBGCC)
  41. rm -f libgcc.ldr
  42. echo Extracting referenced libgcc.a objects ...
  43. rm -f obj.need.0
  44. touch obj.need.0
  45. while [ -s obj.need ] && ! cmp -s obj.need obj.need.0 ; do
  46. (cd tmp-gcc && cat ../obj.need | sort | uniq | xargs $LD -r -o ../libgcc.ldr)
  47. cp obj.need obj.need.0
  48. if $NM --undefined-only libgcc.ldr > sym.need ; then
  49. for SYM in `cat sym.need | sed -e 's/ U //g'` ; do
  50. if $NM -s $LIBGCC | grep -q $SYM" in " ; then
  51. $NM -s $LIBGCC | grep $SYM" in " | cut -d' ' -f3 >> obj.need
  52. fi
  53. done
  54. fi
  55. done
  56. cat obj.need | sort | uniq > obj.need.0
  57. (cd tmp-gcc && cp `cat ../obj.need` ..)
  58. if [ -s obj.need.0 ] ; then
  59. echo Objects added from $LIBGCC:
  60. cat obj.need.0
  61. (cd tmp-gcc && cat ../obj.need | sort | uniq | xargs $AR r ../libgcc-need.a)
  62. else
  63. echo No objects added from $LIBGCC.
  64. fi
  65. if [ -s sym.need ] ; then
  66. echo Symbols missing from libgcc.a:
  67. cat sym.need
  68. else
  69. echo Done
  70. fi
  71. exit 0