collect-ld 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #! /bin/sh
  2. # Copyright (C) 2007-2015 Free Software Foundation, Inc.
  3. # This file is part of GCC.
  4. # GCC is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3, or (at your option)
  7. # any later version.
  8. # GCC is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with GCC; see the file COPYING3. If not see
  14. # <http://www.gnu.org/licenses/>.
  15. # Invoke as, ld or nm from the build tree.
  16. ORIGINAL_AS_FOR_TARGET=""
  17. ORIGINAL_LD_FOR_TARGET=""
  18. ORIGINAL_LD_BFD_FOR_TARGET="/.bfd"
  19. ORIGINAL_LD_GOLD_FOR_TARGET="/.gold"
  20. ORIGINAL_PLUGIN_LD_FOR_TARGET=""
  21. ORIGINAL_NM_FOR_TARGET=""
  22. exeext=
  23. fast_install=yes
  24. objdir=.libs
  25. invoked=`basename "$0"`
  26. id=$invoked
  27. case "$invoked" in
  28. as)
  29. original=$ORIGINAL_AS_FOR_TARGET
  30. prog=as-new$exeext
  31. dir=gas
  32. ;;
  33. collect-ld)
  34. # Check -fuse-ld=bfd and -fuse-ld=gold
  35. case " $* " in
  36. *\ -fuse-ld=bfd\ *)
  37. original=$ORIGINAL_LD_BFD_FOR_TARGET
  38. ;;
  39. *\ -fuse-ld=gold\ *)
  40. original=$ORIGINAL_LD_GOLD_FOR_TARGET
  41. ;;
  42. *)
  43. # when using a linker plugin, gcc will always pass '-plugin' as the
  44. # first or second option to the linker.
  45. if test x"$1" = "x-plugin" || test x"$2" = "x-plugin"; then
  46. original=$ORIGINAL_PLUGIN_LD_FOR_TARGET
  47. else
  48. original=$ORIGINAL_LD_FOR_TARGET
  49. fi
  50. ;;
  51. esac
  52. prog=ld-new$exeext
  53. if test "$original" = ../gold/ld-new$exeext; then
  54. dir=gold
  55. # No need to handle relink since gold doesn't use libtool.
  56. fast_install=yes
  57. else
  58. dir=ld
  59. fi
  60. id=ld
  61. ;;
  62. nm)
  63. original=$ORIGINAL_NM_FOR_TARGET
  64. prog=nm-new$exeext
  65. dir=binutils
  66. ;;
  67. esac
  68. case "$original" in
  69. ../*)
  70. # compute absolute path of the location of this script
  71. tdir=`dirname "$0"`
  72. scriptdir=`cd "$tdir" && pwd`
  73. if test -x $scriptdir/../$dir/$prog; then
  74. test "$fast_install" = yes || exec $scriptdir/../$dir/$prog ${1+"$@"}
  75. # if libtool did everything it needs to do, there's a fast path
  76. lt_prog=$scriptdir/../$dir/$objdir/lt-$prog
  77. test -x $lt_prog && exec $lt_prog ${1+"$@"}
  78. # libtool has not relinked ld-new yet, but we cannot just use the
  79. # previous stage (because then the relinking would just never happen!).
  80. # So we take extra care to use prev-ld/ld-new *on recursive calls*.
  81. eval LT_RCU="\${LT_RCU_$id}"
  82. test x"$LT_RCU" = x"1" && exec $scriptdir/../prev-$dir/$prog ${1+"$@"}
  83. eval LT_RCU_$id=1
  84. export LT_RCU_$id
  85. $scriptdir/../$dir/$prog ${1+"$@"}
  86. result=$?
  87. exit $result
  88. else
  89. exec $scriptdir/../prev-$dir/$prog ${1+"$@"}
  90. fi
  91. ;;
  92. *)
  93. exec $original ${1+"$@"}
  94. ;;
  95. esac