linux.em 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. # This shell script emits a C file. -*- C -*-
  2. # It does some substitutions.
  3. if [ -z "$MACHINE" ]; then
  4. OUTPUT_ARCH=${ARCH}
  5. else
  6. OUTPUT_ARCH=${ARCH}:${MACHINE}
  7. fi
  8. fragment <<EOF
  9. /* This file is is generated by a shell script. DO NOT EDIT! */
  10. /* Linux a.out emulation code for ${EMULATION_NAME}
  11. Copyright (C) 1991-2015 Free Software Foundation, Inc.
  12. Written by Steve Chamberlain <sac@cygnus.com>
  13. Linux support by Eric Youngdale <ericy@cais.cais.com>
  14. This file is part of the GNU Binutils.
  15. This program is free software; you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License as published by
  17. the Free Software Foundation; either version 3 of the License, or
  18. (at your option) any later version.
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. GNU General Public License for more details.
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software
  25. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  26. MA 02110-1301, USA. */
  27. #define TARGET_IS_${EMULATION_NAME}
  28. #include "sysdep.h"
  29. #include "bfd.h"
  30. #include "bfdlink.h"
  31. #include "ld.h"
  32. #include "ldmain.h"
  33. #include "ldmisc.h"
  34. #include "ldexp.h"
  35. #include "ldlang.h"
  36. #include "ldfile.h"
  37. #include "ldemul.h"
  38. static void
  39. gld${EMULATION_NAME}_before_parse (void)
  40. {
  41. ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
  42. input_flags.dynamic = TRUE;
  43. config.has_shared = TRUE;
  44. }
  45. /* Try to open a dynamic archive. This is where we know that Linux
  46. dynamic libraries have an extension of .sa. */
  47. static bfd_boolean
  48. gld${EMULATION_NAME}_open_dynamic_archive
  49. (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
  50. {
  51. char *string;
  52. if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
  53. return FALSE;
  54. string = (char *) xmalloc (strlen (search->name)
  55. + strlen (entry->filename)
  56. + strlen (arch)
  57. + sizeof "/lib.sa");
  58. sprintf (string, "%s/lib%s%s.sa", search->name, entry->filename, arch);
  59. if (! ldfile_try_open_bfd (string, entry))
  60. {
  61. free (string);
  62. return FALSE;
  63. }
  64. entry->filename = string;
  65. return TRUE;
  66. }
  67. /* This is called by the create_output_section_statements routine via
  68. lang_for_each_statement. It locates any address assignment to
  69. .text, and modifies it to include the size of the headers. This
  70. causes -Ttext to mean the starting address of the header, rather
  71. than the starting address of .text, which is compatible with other
  72. Linux tools. */
  73. static void
  74. gld${EMULATION_NAME}_find_address_statement (lang_statement_union_type *s)
  75. {
  76. if (s->header.type == lang_address_statement_enum
  77. && strcmp (s->address_statement.section_name, ".text") == 0)
  78. {
  79. ASSERT (s->address_statement.address->type.node_class == etree_value);
  80. s->address_statement.address->value.value += 0x20;
  81. }
  82. }
  83. /* This is called before opening the input BFD's. */
  84. static void
  85. gld${EMULATION_NAME}_create_output_section_statements (void)
  86. {
  87. lang_for_each_statement (gld${EMULATION_NAME}_find_address_statement);
  88. }
  89. /* This is called after the sections have been attached to output
  90. sections, but before any sizes or addresses have been set. */
  91. static void
  92. gld${EMULATION_NAME}_before_allocation (void)
  93. {
  94. if (bfd_link_relocatable (&link_info))
  95. return;
  96. /* Let the backend work out the sizes of any sections required by
  97. dynamic linking. */
  98. if (! bfd_${EMULATION_NAME}_size_dynamic_sections (link_info.output_bfd,
  99. &link_info))
  100. einfo ("%P%F: failed to set dynamic section sizes: %E\n");
  101. before_allocation_default ();
  102. }
  103. static char *
  104. gld${EMULATION_NAME}_get_script (int *isfile)
  105. EOF
  106. if test x"$COMPILE_IN" = xyes
  107. then
  108. # Scripts compiled in.
  109. # sed commands to quote an ld script as a C string.
  110. sc="-f stringify.sed"
  111. fragment <<EOF
  112. {
  113. *isfile = 0;
  114. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  115. return
  116. EOF
  117. sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
  118. echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
  119. sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
  120. echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
  121. sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
  122. echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
  123. sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
  124. echo ' ; else return' >> e${EMULATION_NAME}.c
  125. sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
  126. echo '; }' >> e${EMULATION_NAME}.c
  127. else
  128. # Scripts read from the filesystem.
  129. fragment <<EOF
  130. {
  131. *isfile = 1;
  132. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  133. return "ldscripts/${EMULATION_NAME}.xu";
  134. else if (bfd_link_relocatable (&link_info))
  135. return "ldscripts/${EMULATION_NAME}.xr";
  136. else if (!config.text_read_only)
  137. return "ldscripts/${EMULATION_NAME}.xbn";
  138. else if (!config.magic_demand_paged)
  139. return "ldscripts/${EMULATION_NAME}.xn";
  140. else
  141. return "ldscripts/${EMULATION_NAME}.x";
  142. }
  143. EOF
  144. fi
  145. fragment <<EOF
  146. struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
  147. {
  148. gld${EMULATION_NAME}_before_parse,
  149. syslib_default,
  150. hll_default,
  151. after_parse_default,
  152. after_open_default,
  153. after_allocation_default,
  154. set_output_arch_default,
  155. ldemul_default_target,
  156. gld${EMULATION_NAME}_before_allocation,
  157. gld${EMULATION_NAME}_get_script,
  158. "${EMULATION_NAME}",
  159. "${OUTPUT_FORMAT}",
  160. finish_default,
  161. gld${EMULATION_NAME}_create_output_section_statements,
  162. gld${EMULATION_NAME}_open_dynamic_archive,
  163. NULL, /* place orphan */
  164. NULL, /* set symbols */
  165. NULL, /* parse args */
  166. NULL, /* add_options */
  167. NULL, /* handle_option */
  168. NULL, /* unrecognized file */
  169. NULL, /* list options */
  170. NULL, /* recognized file */
  171. NULL, /* find_potential_libraries */
  172. NULL, /* new_vers_pattern */
  173. NULL /* extra_map_file_text */
  174. };
  175. EOF