ticoff.em 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # This shell script emits a C file. -*- C -*-
  2. # It does some substitutions.
  3. (echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
  4. fragment <<EOF
  5. /* This file is part of GLD, the Gnu Linker.
  6. Copyright (C) 1999-2015 Free Software Foundation, Inc.
  7. This file is part of the GNU Binutils.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 3 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  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. /* For TI COFF */
  21. /* Need to determine load and run pages for output sections */
  22. #define TARGET_IS_${EMULATION_NAME}
  23. #include "sysdep.h"
  24. #include "bfd.h"
  25. #include "bfdlink.h"
  26. #include "getopt.h"
  27. #include "ld.h"
  28. #include "ldmain.h"
  29. #include "ldmisc.h"
  30. #include "ldexp.h"
  31. #include "ldlang.h"
  32. #include "ldfile.h"
  33. #include "ldemul.h"
  34. static int coff_version;
  35. /* TI COFF extra command line options */
  36. #define OPTION_COFF_FORMAT (300 + 1)
  37. static void
  38. gld${EMULATION_NAME}_add_options
  39. (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl,
  40. struct option **longopts, int nrl ATTRIBUTE_UNUSED,
  41. struct option **really_longopts ATTRIBUTE_UNUSED)
  42. {
  43. static const struct option xtra_long[] = {
  44. /* TI COFF options */
  45. {"format", required_argument, NULL, OPTION_COFF_FORMAT },
  46. {NULL, no_argument, NULL, 0}
  47. };
  48. *longopts = (struct option *)
  49. xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
  50. memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
  51. }
  52. static void
  53. gld_${EMULATION_NAME}_list_options (FILE * file)
  54. {
  55. fprintf (file, _(" --format 0|1|2 Specify which COFF version to use\n"));
  56. }
  57. static bfd_boolean
  58. gld${EMULATION_NAME}_handle_option (int optc)
  59. {
  60. switch (optc)
  61. {
  62. default:
  63. return FALSE;
  64. case OPTION_COFF_FORMAT:
  65. if ((*optarg == '0' || *optarg == '1' || *optarg == '2')
  66. && optarg[1] == '\0')
  67. {
  68. static char buf[] = "coffX-${OUTPUT_FORMAT_TEMPLATE}";
  69. coff_version = *optarg - '0';
  70. buf[4] = *optarg;
  71. lang_add_output_format (buf, NULL, NULL, 0);
  72. }
  73. else
  74. {
  75. einfo (_("%P%F: invalid COFF format version %s\n"), optarg);
  76. }
  77. break;
  78. }
  79. return FALSE;
  80. }
  81. static void
  82. gld_${EMULATION_NAME}_before_parse(void)
  83. {
  84. #ifndef TARGET_ /* I.e., if not generic. */
  85. ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
  86. #endif /* not TARGET_ */
  87. }
  88. static char *
  89. gld_${EMULATION_NAME}_get_script (int *isfile)
  90. EOF
  91. if test x"$COMPILE_IN" = xyes
  92. then
  93. # Scripts compiled in.
  94. # sed commands to quote an ld script as a C string.
  95. sc='s/["\\]/\\&/g
  96. s/$/\\n\\/
  97. 1s/^/"/
  98. $s/$/n"/
  99. '
  100. fragment <<EOF
  101. {
  102. *isfile = 0;
  103. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  104. return `sed "$sc" ldscripts/${EMULATION_NAME}.xu`;
  105. else if (bfd_link_relocatable (&link_info))
  106. return `sed "$sc" ldscripts/${EMULATION_NAME}.xr`;
  107. else if (!config.text_read_only)
  108. return `sed "$sc" ldscripts/${EMULATION_NAME}.xbn`;
  109. else if (!config.magic_demand_paged)
  110. return `sed "$sc" ldscripts/${EMULATION_NAME}.xn`;
  111. else
  112. return `sed "$sc" ldscripts/${EMULATION_NAME}.x`;
  113. }
  114. EOF
  115. else
  116. # Scripts read from the filesystem.
  117. fragment <<EOF
  118. {
  119. *isfile = 1;
  120. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  121. return "ldscripts/${EMULATION_NAME}.xu";
  122. else if (bfd_link_relocatable (&link_info))
  123. return "ldscripts/${EMULATION_NAME}.xr";
  124. else if (!config.text_read_only)
  125. return "ldscripts/${EMULATION_NAME}.xbn";
  126. else if (!config.magic_demand_paged)
  127. return "ldscripts/${EMULATION_NAME}.xn";
  128. else
  129. return "ldscripts/${EMULATION_NAME}.x";
  130. }
  131. EOF
  132. fi
  133. fragment <<EOF
  134. struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
  135. {
  136. gld_${EMULATION_NAME}_before_parse,
  137. syslib_default,
  138. hll_default,
  139. after_parse_default,
  140. after_open_default,
  141. after_allocation_default,
  142. set_output_arch_default,
  143. ldemul_default_target,
  144. before_allocation_default,
  145. gld_${EMULATION_NAME}_get_script,
  146. "${EMULATION_NAME}",
  147. "${OUTPUT_FORMAT}",
  148. finish_default,
  149. NULL, /* create output section statements */
  150. NULL, /* open dynamic archive */
  151. NULL, /* place orphan */
  152. NULL, /* set_symbols */
  153. NULL, /* parse_args */
  154. gld${EMULATION_NAME}_add_options,
  155. gld${EMULATION_NAME}_handle_option,
  156. NULL, /* unrecognized_file */
  157. gld_${EMULATION_NAME}_list_options,
  158. NULL, /* recognized file */
  159. NULL, /* find_potential_libraries */
  160. NULL, /* new_vers_pattern */
  161. NULL /* extra_map_file_text */
  162. };
  163. EOF