alphaelf.em 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # This shell script emits a C file. -*- C -*-
  2. # Copyright (C) 2003-2022 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 elf.em, and defines extra alpha
  22. # specific routines.
  23. #
  24. fragment <<EOF
  25. #include "elf/internal.h"
  26. #include "elf/alpha.h"
  27. #include "elf-bfd.h"
  28. static bool limit_32bit;
  29. extern bool elf64_alpha_use_secureplt;
  30. /* Set the start address as in the Tru64 ld. */
  31. #define ALPHA_TEXT_START_32BIT 0x12000000
  32. static void
  33. alpha_after_open (void)
  34. {
  35. if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
  36. && elf_object_id (link_info.output_bfd) == ALPHA_ELF_DATA)
  37. {
  38. unsigned int num_plt;
  39. lang_output_section_statement_type *os;
  40. lang_output_section_statement_type *plt_os[2];
  41. num_plt = 0;
  42. for (os = (void *) lang_os_list.head;
  43. os != NULL;
  44. os = os->next)
  45. {
  46. if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
  47. {
  48. if (num_plt < 2)
  49. plt_os[num_plt] = os;
  50. ++num_plt;
  51. }
  52. }
  53. if (num_plt == 2)
  54. {
  55. plt_os[0]->constraint = elf64_alpha_use_secureplt ? 0 : -1;
  56. plt_os[1]->constraint = elf64_alpha_use_secureplt ? -1 : 0;
  57. }
  58. }
  59. gld${EMULATION_NAME}_after_open ();
  60. }
  61. static void
  62. alpha_after_parse (void)
  63. {
  64. link_info.relax_pass = 2;
  65. if (limit_32bit
  66. && !bfd_link_pic (&link_info)
  67. && !bfd_link_relocatable (&link_info))
  68. lang_section_start (".interp",
  69. exp_binop ('+',
  70. exp_intop (ALPHA_TEXT_START_32BIT),
  71. exp_nameop (SIZEOF_HEADERS, NULL)),
  72. NULL);
  73. ldelf_after_parse ();
  74. }
  75. static void
  76. alpha_before_allocation (void)
  77. {
  78. /* Call main function; we're just extending it. */
  79. gld${EMULATION_NAME}_before_allocation ();
  80. /* Add -relax if -O, not -r, and not explicitly disabled. */
  81. if (link_info.optimize
  82. && !bfd_link_relocatable (&link_info)
  83. && ! RELAXATION_DISABLED_BY_USER)
  84. ENABLE_RELAXATION;
  85. }
  86. static void
  87. alpha_finish (void)
  88. {
  89. if (limit_32bit)
  90. elf_elfheader (link_info.output_bfd)->e_flags |= EF_ALPHA_32BIT;
  91. finish_default ();
  92. }
  93. EOF
  94. # Define some shell vars to insert bits of code into the standard elf
  95. # parse_args and list_options functions.
  96. #
  97. PARSE_AND_LIST_PROLOGUE='
  98. #define OPTION_TASO 300
  99. #define OPTION_SECUREPLT (OPTION_TASO + 1)
  100. #define OPTION_NO_SECUREPLT (OPTION_SECUREPLT + 1)
  101. '
  102. PARSE_AND_LIST_LONGOPTS='
  103. { "taso", no_argument, NULL, OPTION_TASO },
  104. { "secureplt", no_argument, NULL, OPTION_SECUREPLT },
  105. { "no-secureplt", no_argument, NULL, OPTION_NO_SECUREPLT },
  106. '
  107. PARSE_AND_LIST_OPTIONS='
  108. fprintf (file, _("\
  109. --taso Load executable in the lower 31-bit addressable\n\
  110. virtual address range\n"));
  111. fprintf (file, _("\
  112. --secureplt Force PLT in text segment\n"));
  113. fprintf (file, _("\
  114. --no-secureplt Force PLT in data segment\n"));
  115. '
  116. PARSE_AND_LIST_ARGS_CASES='
  117. case OPTION_TASO:
  118. limit_32bit = 1;
  119. break;
  120. case OPTION_SECUREPLT:
  121. elf64_alpha_use_secureplt = true;
  122. break;
  123. case OPTION_NO_SECUREPLT:
  124. elf64_alpha_use_secureplt = false;
  125. break;
  126. '
  127. # Put these extra alpha routines in ld_${EMULATION_NAME}_emulation
  128. #
  129. LDEMUL_AFTER_OPEN=alpha_after_open
  130. LDEMUL_AFTER_PARSE=alpha_after_parse
  131. LDEMUL_BEFORE_ALLOCATION=alpha_before_allocation
  132. LDEMUL_FINISH=alpha_finish