elf-generic.em 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # This shell script emits a C file. -*- C -*-
  2. # Copyright (C) 2006-2015 Free Software Foundation, Inc.
  3. #
  4. # This file is part of the GNU Binutils.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  19. # MA 02110-1301, USA.
  20. #
  21. # This file is sourced from elf32.em and from ELF targets that use
  22. # generic.em.
  23. #
  24. fragment <<EOF
  25. static void
  26. gld${EMULATION_NAME}_map_segments (bfd_boolean need_layout)
  27. {
  28. int tries = 10;
  29. do
  30. {
  31. lang_relax_sections (need_layout);
  32. need_layout = FALSE;
  33. if (link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour
  34. && !bfd_link_relocatable (&link_info))
  35. {
  36. bfd_size_type phdr_size;
  37. phdr_size = elf_program_header_size (link_info.output_bfd);
  38. /* If we don't have user supplied phdrs, throw away any
  39. previous linker generated program headers. */
  40. if (lang_phdr_list == NULL)
  41. elf_seg_map (link_info.output_bfd) = NULL;
  42. if (!_bfd_elf_map_sections_to_segments (link_info.output_bfd,
  43. &link_info))
  44. einfo ("%F%P: map sections to segments failed: %E\n");
  45. if (phdr_size != elf_program_header_size (link_info.output_bfd))
  46. {
  47. if (tries > 6)
  48. /* The first few times we allow any change to
  49. phdr_size . */
  50. need_layout = TRUE;
  51. else if (phdr_size
  52. < elf_program_header_size (link_info.output_bfd))
  53. /* After that we only allow the size to grow. */
  54. need_layout = TRUE;
  55. else
  56. elf_program_header_size (link_info.output_bfd) = phdr_size;
  57. }
  58. }
  59. }
  60. while (need_layout && --tries);
  61. if (tries == 0)
  62. einfo (_("%P%F: looping in map_segments"));
  63. }
  64. EOF