vms.em 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. # This shell script emits a C file. -*- C -*-
  2. # Copyright (C) 2010-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 generic.em.
  22. fragment <<EOF
  23. #include "getopt.h"
  24. static void
  25. gld${EMULATION_NAME}_before_parse (void)
  26. {
  27. ldfile_set_output_arch ("${ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
  28. input_flags.dynamic = true;
  29. config.has_shared = false; /* Not yet. */
  30. /* For ia64, harmless for alpha. */
  31. link_info.emit_hash = false;
  32. link_info.spare_dynamic_tags = 0;
  33. }
  34. /* This is called before the input files are opened. We add the
  35. standard library. */
  36. static void
  37. gld${EMULATION_NAME}_create_output_section_statements (void)
  38. {
  39. lang_add_input_file ("imagelib", lang_input_file_is_l_enum, NULL);
  40. lang_add_input_file ("starlet", lang_input_file_is_l_enum, NULL);
  41. lang_add_input_file ("sys\$public_vectors", lang_input_file_is_l_enum, NULL);
  42. }
  43. /* Try to open a dynamic archive. This is where we know that VMS
  44. shared images (dynamic libraries) have an extension of .exe. */
  45. static bool
  46. gld${EMULATION_NAME}_open_dynamic_archive (const char *arch ATTRIBUTE_UNUSED,
  47. search_dirs_type *search,
  48. lang_input_statement_type *entry)
  49. {
  50. char *string;
  51. if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
  52. return false;
  53. string = (char *) xmalloc (strlen (search->name)
  54. + strlen (entry->filename)
  55. + sizeof "/.exe");
  56. sprintf (string, "%s/%s.exe", search->name, entry->filename);
  57. if (! ldfile_try_open_bfd (string, entry))
  58. {
  59. free (string);
  60. return false;
  61. }
  62. entry->filename = string;
  63. return true;
  64. }
  65. static int
  66. gld${EMULATION_NAME}_find_potential_libraries
  67. (char *name, lang_input_statement_type *entry)
  68. {
  69. return ldfile_open_file_search (name, entry, "", ".olb");
  70. }
  71. /* Place an orphan section. We use this to put random OVR sections.
  72. Much borrowed from elf.em. */
  73. static lang_output_section_statement_type *
  74. vms_place_orphan (asection *s,
  75. const char *secname ATTRIBUTE_UNUSED,
  76. int constraint ATTRIBUTE_UNUSED)
  77. {
  78. static struct orphan_save hold_data =
  79. {
  80. "\$DATA\$",
  81. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
  82. 0, 0, 0, 0
  83. };
  84. /* We have nothing to say for anything other than a final link or an excluded
  85. section. */
  86. if (bfd_link_relocatable (&link_info)
  87. || (s->flags & (SEC_EXCLUDE | SEC_LOAD)) != SEC_LOAD)
  88. return NULL;
  89. /* FIXME: we should place sections by VMS program section flags. */
  90. /* Only handle data sections. */
  91. if ((s->flags & SEC_DATA) == 0)
  92. return NULL;
  93. if (hold_data.os == NULL)
  94. hold_data.os = lang_output_section_find (hold_data.name);
  95. if (hold_data.os != NULL)
  96. {
  97. lang_add_section (&hold_data.os->children, s, NULL, NULL, hold_data.os);
  98. return hold_data.os;
  99. }
  100. else
  101. return NULL;
  102. }
  103. /* VMS specific options. */
  104. #define OPTION_IDENTIFICATION (300 + 1)
  105. static void
  106. gld${EMULATION_NAME}_add_options
  107. (int ns ATTRIBUTE_UNUSED,
  108. char **shortopts ATTRIBUTE_UNUSED,
  109. int nl,
  110. struct option **longopts,
  111. int nrl ATTRIBUTE_UNUSED,
  112. struct option **really_longopts ATTRIBUTE_UNUSED)
  113. {
  114. static const struct option xtra_long[] =
  115. {
  116. {"identification", required_argument, NULL, OPTION_IDENTIFICATION},
  117. {NULL, no_argument, NULL, 0}
  118. };
  119. *longopts
  120. = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
  121. memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
  122. }
  123. static void
  124. gld${EMULATION_NAME}_list_options (FILE *file)
  125. {
  126. fprintf (file, _(" --identification <string> Set the identification of the output\n"));
  127. }
  128. static bool
  129. gld${EMULATION_NAME}_handle_option (int optc)
  130. {
  131. switch (optc)
  132. {
  133. default:
  134. return false;
  135. case OPTION_IDENTIFICATION:
  136. /* Currently ignored. */
  137. break;
  138. }
  139. return true;
  140. }
  141. EOF
  142. if test "$OUTPUT_FORMAT" = "elf64-ia64-vms"; then
  143. fragment <<EOF
  144. #include "elf-bfd.h"
  145. #include "ldelfgen.h"
  146. EOF
  147. source_em ${srcdir}/emultempl/elf-generic.em
  148. fragment <<EOF
  149. /* This is called after the sections have been attached to output
  150. sections, but before any sizes or addresses have been set. */
  151. static void
  152. gld${EMULATION_NAME}_before_allocation (void)
  153. {
  154. const struct elf_backend_data *bed;
  155. if (!is_elf_hash_table (link_info.hash))
  156. return;
  157. bed = get_elf_backend_data (link_info.output_bfd);
  158. /* The backend must work out the sizes of all the other dynamic
  159. sections. */
  160. if (elf_hash_table (&link_info)->dynamic_sections_created
  161. && bed->elf_backend_size_dynamic_sections
  162. && ! (*bed->elf_backend_size_dynamic_sections) (link_info.output_bfd,
  163. &link_info))
  164. einfo (_("%F%P: failed to set dynamic section sizes: %E\n"));
  165. before_allocation_default ();
  166. }
  167. static void
  168. gld${EMULATION_NAME}_after_allocation (void)
  169. {
  170. int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
  171. if (need_layout < 0)
  172. einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
  173. else
  174. ldelf_map_segments (need_layout);
  175. }
  176. static void
  177. gld${EMULATION_NAME}_after_parse (void)
  178. {
  179. link_info.relax_pass = 2;
  180. after_parse_default ();
  181. }
  182. EOF
  183. LDEMUL_BEFORE_ALLOCATION=gld"$EMULATION_NAME"_before_allocation
  184. LDEMUL_AFTER_ALLOCATION=gld"$EMULATION_NAME"_after_allocation
  185. LDEMUL_AFTER_PARSE=gld${EMULATION_NAME}_after_parse
  186. source_em ${srcdir}/emultempl/needrelax.em
  187. fi
  188. LDEMUL_PLACE_ORPHAN=vms_place_orphan
  189. LDEMUL_BEFORE_PARSE=gld"$EMULATION_NAME"_before_parse
  190. LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=gld"$EMULATION_NAME"_create_output_section_statements
  191. LDEMUL_FIND_POTENTIAL_LIBRARIES=gld"$EMULATION_NAME"_find_potential_libraries
  192. LDEMUL_OPEN_DYNAMIC_ARCHIVE=gld"$EMULATION_NAME"_open_dynamic_archive
  193. LDEMUL_ADD_OPTIONS=gld"$EMULATION_NAME"_add_options
  194. LDEMUL_HANDLE_OPTION=gld"$EMULATION_NAME"_handle_option
  195. LDEMUL_LIST_OPTIONS=gld"$EMULATION_NAME"_list_options