build 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # The libstdc++ shipped by default is non-PIC which breaks the binutils build
  12. # if we build with DEB_BUILD_HARDENING_PIE=1. We need to install a PIC one AND
  13. # make sure it gets used before the non-PIC one would.
  14. ln -s /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++_pic.a libstdc++.a
  15. export LDFLAGS="-L$rootdir -lstdc++"
  16. [% END %]
  17. tar xf [% project %]-[% c("version") %].tar.xz
  18. cd [% project %]-[% c("version") %]
  19. [% IF c('var/windows') -%]
  20. # Needed for the hardening... The upstream ticket is:
  21. # https://sourceware.org/bugzilla/show_bug.cgi?id=17321
  22. patch -p1 < ../enable-reloc-section-ld.patch
  23. [% END -%]
  24. [% IF c('var/windows-x86_64') -%]
  25. patch -p1 < ../64bit-fixups.patch
  26. [% END -%]
  27. ./configure --prefix=$distdir [% c('var/configure_opt') %]
  28. make -j[% c("buildconf/num_procs") %]
  29. make install
  30. [% IF c("var/linux") && ! c("var/linux-cross") %]
  31. # Make sure gold is used with the hardening wrapper for full RELRO, see #13031.
  32. cd $distdir/bin
  33. rm ld
  34. cp /usr/bin/hardened-ld ./
  35. mv ld.gold ld.gold.real
  36. ln -sf hardened-ld ld.gold
  37. ln -sf ld.gold ld
  38. [% END %]
  39. [% IF c("var/linux-cross") && 0 %]
  40. # gold is disabled for cross-compiles, because of
  41. # https://sourceware.org/bugzilla/show_bug.cgi?id=14995
  42. # Once we upgrade to glibc 2.26 and binutils 2.28, we should be able to
  43. # re-introduce gold for cross-compiles.
  44. # Make sure gold is used with the hardening wrapper for full RELRO, see #13031.
  45. # First do the filename-prefixed ones...
  46. cd $distdir/bin
  47. rm [% c('var/crosstarget') %]-ld
  48. cp /usr/bin/hardened-ld ./
  49. mv [% c('var/crosstarget') %]-ld.gold [% c('var/crosstarget') %]-ld.gold.real
  50. ln -sf hardened-ld [% c('var/crosstarget') %]-ld.gold
  51. ln -sf [% c('var/crosstarget') %]-ld.gold [% c('var/crosstarget') %]-ld
  52. # Then do the directory-prefixed ones...
  53. cd $distdir/[% c('var/crosstarget') %]/bin
  54. rm ld
  55. cp /usr/bin/hardened-ld ./
  56. mv ld.gold ld.gold.real
  57. ln -sf hardened-ld ld.gold
  58. ln -sf ld.gold ld
  59. [% END %]
  60. cd /var/tmp/dist
  61. [% c('tar', {
  62. tar_src => [ project ],
  63. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  64. }) %]