gld960c.em 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # This shell script emits a C file. -*- C -*-
  2. # It does some substitutions.
  3. fragment <<EOF
  4. /* Copyright (C) 1991-2015 Free Software Foundation, Inc.
  5. This file is part of the GNU Binutils.
  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. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  17. MA 02110-1301, USA. */
  18. /* Emulate the Intel's port of gld. */
  19. #include "sysdep.h"
  20. #include "bfd.h"
  21. #include "libiberty.h"
  22. #include "safe-ctype.h"
  23. #include "bfdlink.h"
  24. #include "ld.h"
  25. #include "ldmisc.h"
  26. #include "ldmain.h"
  27. #include "ldexp.h"
  28. #include "ldlang.h"
  29. #include "ldfile.h"
  30. #include "ldemul.h"
  31. static void gld960_before_parse (void)
  32. {
  33. char *env ;
  34. env = getenv("G960LIB");
  35. if (env) {
  36. ldfile_add_library_path(env, FALSE);
  37. }
  38. env = getenv("G960BASE");
  39. if (env)
  40. ldfile_add_library_path (concat (env, "/lib", (const char *) NULL),
  41. FALSE);
  42. ldfile_output_architecture = bfd_arch_i960;
  43. }
  44. static void
  45. gld960_set_output_arch (void)
  46. {
  47. if (ldfile_output_machine_name != NULL
  48. && *ldfile_output_machine_name != '\0')
  49. {
  50. char *s, *s1;
  51. s = concat ("i960:", ldfile_output_machine_name, (char *) NULL);
  52. for (s1 = s; *s1 != '\0'; s1++)
  53. *s1 = TOLOWER (*s1);
  54. ldfile_set_output_arch (s, bfd_arch_unknown);
  55. free (s);
  56. }
  57. set_output_arch_default ();
  58. }
  59. static char *
  60. gld960_choose_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
  61. {
  62. char *from_outside = getenv(TARGET_ENVIRON);
  63. output_filename = "b.out";
  64. if (from_outside != (char *)NULL)
  65. return from_outside;
  66. return "coff-Intel-little";
  67. }
  68. static char *
  69. gld960_get_script (int *isfile)
  70. EOF
  71. if test x"$COMPILE_IN" = xyes
  72. then
  73. # Scripts compiled in.
  74. # sed commands to quote an ld script as a C string.
  75. sc="-f stringify.sed"
  76. fragment <<EOF
  77. {
  78. *isfile = 0;
  79. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  80. return
  81. EOF
  82. sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
  83. echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
  84. sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
  85. echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
  86. sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
  87. echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
  88. sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
  89. echo ' ; else return' >> e${EMULATION_NAME}.c
  90. sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
  91. echo '; }' >> e${EMULATION_NAME}.c
  92. else
  93. # Scripts read from the filesystem.
  94. fragment <<EOF
  95. {
  96. *isfile = 1;
  97. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  98. return "ldscripts/${EMULATION_NAME}.xu";
  99. else if (bfd_link_relocatable (&link_info))
  100. return "ldscripts/${EMULATION_NAME}.xr";
  101. else if (!config.text_read_only)
  102. return "ldscripts/${EMULATION_NAME}.xbn";
  103. else if (!config.magic_demand_paged)
  104. return "ldscripts/${EMULATION_NAME}.xn";
  105. else
  106. return "ldscripts/${EMULATION_NAME}.x";
  107. }
  108. EOF
  109. fi
  110. fragment <<EOF
  111. struct ld_emulation_xfer_struct ld_gld960coff_emulation =
  112. {
  113. gld960_before_parse,
  114. syslib_default,
  115. hll_default,
  116. after_parse_default,
  117. after_open_default,
  118. after_allocation_default,
  119. gld960_set_output_arch,
  120. gld960_choose_target,
  121. before_allocation_default,
  122. gld960_get_script,
  123. "960coff",
  124. "",
  125. finish_default,
  126. NULL, /* create output section statements */
  127. NULL, /* open dynamic archive */
  128. NULL, /* place orphan */
  129. NULL, /* set symbols */
  130. NULL, /* parse args */
  131. NULL, /* add_options */
  132. NULL, /* handle_option */
  133. NULL, /* unrecognized file */
  134. NULL, /* list options */
  135. NULL, /* recognized file */
  136. NULL, /* find_potential_libraries */
  137. NULL, /* new_vers_pattern */
  138. NULL /* extra_map_file_text */
  139. };
  140. EOF