build 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. distdir=/var/tmp/dist/binutils
  4. [% IF c("var/linux") %]
  5. # Config options for hardening-wrapper
  6. export DEB_BUILD_HARDENING=1
  7. export DEB_BUILD_HARDENING_STACKPROTECTOR=1
  8. export DEB_BUILD_HARDENING_FORTIFY=1
  9. export DEB_BUILD_HARDENING_FORMAT=1
  10. export DEB_BUILD_HARDENING_PIE=1
  11. [% END -%]
  12. [% IF c("var/linux-x86_64") || c("var/linux-arm") %]
  13. # The libstdc++ shipped by default is non-PIC which breaks the binutils build
  14. # if we build with DEB_BUILD_HARDENING_PIE=1. We need to install a PIC one AND
  15. # make sure it gets used before the non-PIC one would.
  16. ln -s /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++_pic.a libstdc++.a
  17. export LDFLAGS="-L$rootdir -lstdc++"
  18. [% END %]
  19. tar xf [% project %]-[% c("version") %].tar.bz2
  20. cd [% project %]-[% c("version") %]
  21. [% IF c('var/windows') -%]
  22. # XXX: This is needed due to bug 10102.
  23. sed 's/= extern_rt_rel_d;/= extern_rt_rel_d;\n memset (extern_rt_rel_d, 0, PE_IDATA5_SIZE);/' -i ld/pe-dll.c
  24. # Zeroing timestamps in PE headers reliably, see bug 12753.
  25. patch -p1 < ../peXXigen.patch
  26. # Needed for the hardening...
  27. patch -p1 < ../enable-reloc-section-ld.patch
  28. # fix "right-hand operand of comma expression has no effect" warning
  29. patch -p1 < ../fix-warning-bfd.patch
  30. [% END -%]
  31. [% IF c('var/windows-x86_64') -%]
  32. patch -p1 < ../64bit-fixups.patch
  33. [% END -%]
  34. [% IF c("var/linux") && ! c("var/release") -%]
  35. # We need to work around a gold linker bug in 2.24 to get selfrando working,
  36. # see bug 20683.
  37. patch -p1 < $rootdir/binutils-224-gold.patch
  38. [% END -%]
  39. ./configure --prefix=$distdir [% c('var/configure_opt') %]
  40. make -j[% c("buildconf/num_procs") %]
  41. make install
  42. [% IF c("var/linux") && ! c("var/linux-arm") %]
  43. # Make sure gold is used with the hardening wrapper for full RELRO, see #13031.
  44. cd $distdir/bin
  45. rm ld
  46. cp /usr/bin/hardened-ld ./
  47. mv ld.gold ld.gold.real
  48. ln -sf hardened-ld ld.gold
  49. ln -sf ld.gold ld
  50. [% END %]
  51. [% IF c("var/linux-arm") && 0 %]
  52. # gold is disabled for cross-compiles, because of
  53. # https://sourceware.org/bugzilla/show_bug.cgi?id=14995
  54. # Once we upgrade to glibc 2.26 and binutils 2.28, we should be able to
  55. # re-introduce gold for cross-compiles.
  56. # Make sure gold is used with the hardening wrapper for full RELRO, see #13031.
  57. # First do the filename-prefixed ones...
  58. cd $distdir/bin
  59. rm [% c('var/crosstarget') %]-ld
  60. cp /usr/bin/hardened-ld ./
  61. mv [% c('var/crosstarget') %]-ld.gold [% c('var/crosstarget') %]-ld.gold.real
  62. ln -sf hardened-ld [% c('var/crosstarget') %]-ld.gold
  63. ln -sf [% c('var/crosstarget') %]-ld.gold [% c('var/crosstarget') %]-ld
  64. # Then do the directory-prefixed ones...
  65. cd $distdir/[% c('var/crosstarget') %]/bin
  66. rm ld
  67. cp /usr/bin/hardened-ld ./
  68. mv ld.gold ld.gold.real
  69. ln -sf hardened-ld ld.gold
  70. ln -sf ld.gold ld
  71. [% END %]
  72. cd /var/tmp/dist
  73. [% c('tar', {
  74. tar_src => [ project ],
  75. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  76. }) %]