update generated files
[binutils.git] / ld / emultempl / linux.em
blob888a3ddc61c6c9e796673522e299e1dc7a0fbb34
1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 cat >e${EMULATION_NAME}.c <<EOF
4 /* This file is is generated by a shell script.  DO NOT EDIT! */
6 /* Linux a.out emulation code for ${EMULATION_NAME}
7    Copyright 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000
8    Free Software Foundation, Inc.
9    Written by Steve Chamberlain <sac@cygnus.com>
10    Linux support by Eric Youngdale <ericy@cais.cais.com>
12 This file is part of GLD, the Gnu Linker.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (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.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
28 #define TARGET_IS_${EMULATION_NAME}
30 #include "bfd.h"
31 #include "sysdep.h"
32 #include "bfdlink.h"
34 #include "ld.h"
35 #include "ldmain.h"
36 #include "ldmisc.h"
37 #include "ldexp.h"
38 #include "ldlang.h"
39 #include "ldfile.h"
40 #include "ldemul.h"
42 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
43 static boolean gld${EMULATION_NAME}_open_dynamic_archive
44   PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
45 static void gld${EMULATION_NAME}_find_address_statement
46   PARAMS ((lang_statement_union_type *));
47 static void gld${EMULATION_NAME}_create_output_section_statements
48   PARAMS ((void));
49 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
50 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
52 static void
53 gld${EMULATION_NAME}_before_parse()
55   ldfile_output_architecture = bfd_arch_${ARCH};
56   config.dynamic_link = true;
57   config.has_shared = true;
60 /* Try to open a dynamic archive.  This is where we know that Linux
61    dynamic libraries have an extension of .sa.  */
63 static boolean
64 gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)
65      const char *arch;
66      search_dirs_type *search;
67      lang_input_statement_type *entry;
69   char *string;
71   if (! entry->is_archive)
72     return false;
74   string = (char *) xmalloc (strlen (search->name)
75                              + strlen (entry->filename)
76                              + strlen (arch)
77                              + sizeof "/lib.sa");
79   sprintf (string, "%s/lib%s%s.sa", search->name, entry->filename, arch);
81   if (! ldfile_try_open_bfd (string, entry))
82     {
83       free (string);
84       return false;
85     }
87   entry->filename = string;
89   return true;
92 /* This is called by the create_output_section_statements routine via
93    lang_for_each_statement.  It locates any address assignment to
94    .text, and modifies it to include the size of the headers.  This
95    causes -Ttext to mean the starting address of the header, rather
96    than the starting address of .text, which is compatible with other
97    Linux tools.  */
99 static void
100 gld${EMULATION_NAME}_find_address_statement (s)
101      lang_statement_union_type *s;
103   if (s->header.type == lang_address_statement_enum
104       && strcmp (s->address_statement.section_name, ".text") == 0)
105     {
106       ASSERT (s->address_statement.address->type.node_class == etree_value);
107       s->address_statement.address->value.value += 0x20;
108     }
111 /* This is called before opening the input BFD's.  */
113 static void
114 gld${EMULATION_NAME}_create_output_section_statements ()
116   lang_for_each_statement (gld${EMULATION_NAME}_find_address_statement);
119 /* This is called after the sections have been attached to output
120    sections, but before any sizes or addresses have been set.  */
122 static void
123 gld${EMULATION_NAME}_before_allocation ()
125   if (link_info.relocateable)
126     return;
128   /* Let the backend work out the sizes of any sections required by
129      dynamic linking.  */
130   if (! bfd_${EMULATION_NAME}_size_dynamic_sections (output_bfd, &link_info))
131     einfo ("%P%F: failed to set dynamic section sizes: %E\n");
134 static char *
135 gld${EMULATION_NAME}_get_script(isfile)
136      int *isfile;
139 if test -n "$COMPILE_IN"
140 then
141 # Scripts compiled in.
143 # sed commands to quote an ld script as a C string.
144 sc="-f stringify.sed"
146 cat >>e${EMULATION_NAME}.c <<EOF
147 {                            
148   *isfile = 0;
150   if (link_info.relocateable == true && config.build_constructors == true)
151     return
153 sed $sc ldscripts/${EMULATION_NAME}.xu                     >> e${EMULATION_NAME}.c
154 echo '  ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
155 sed $sc ldscripts/${EMULATION_NAME}.xr                     >> e${EMULATION_NAME}.c
156 echo '  ; else if (!config.text_read_only) return'         >> e${EMULATION_NAME}.c
157 sed $sc ldscripts/${EMULATION_NAME}.xbn                    >> e${EMULATION_NAME}.c
158 echo '  ; else if (!config.magic_demand_paged) return'     >> e${EMULATION_NAME}.c
159 sed $sc ldscripts/${EMULATION_NAME}.xn                     >> e${EMULATION_NAME}.c
160 echo '  ; else return'                                     >> e${EMULATION_NAME}.c
161 sed $sc ldscripts/${EMULATION_NAME}.x                      >> e${EMULATION_NAME}.c
162 echo '; }'                                                 >> e${EMULATION_NAME}.c
164 else
165 # Scripts read from the filesystem.
167 cat >>e${EMULATION_NAME}.c <<EOF
168 {                            
169   *isfile = 1;
171   if (link_info.relocateable == true && config.build_constructors == true)
172     return "ldscripts/${EMULATION_NAME}.xu";
173   else if (link_info.relocateable == true)
174     return "ldscripts/${EMULATION_NAME}.xr";
175   else if (!config.text_read_only)
176     return "ldscripts/${EMULATION_NAME}.xbn";
177   else if (!config.magic_demand_paged)
178     return "ldscripts/${EMULATION_NAME}.xn";
179   else
180     return "ldscripts/${EMULATION_NAME}.x";
186 cat >>e${EMULATION_NAME}.c <<EOF
188 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 
190   gld${EMULATION_NAME}_before_parse,
191   syslib_default,
192   hll_default,
193   after_parse_default,
194   after_open_default,
195   after_allocation_default,
196   set_output_arch_default,
197   ldemul_default_target,
198   gld${EMULATION_NAME}_before_allocation,
199   gld${EMULATION_NAME}_get_script,
200   "${EMULATION_NAME}",
201   "${OUTPUT_FORMAT}",
202   NULL, /* finish */
203   gld${EMULATION_NAME}_create_output_section_statements,
204   gld${EMULATION_NAME}_open_dynamic_archive,
205   NULL, /* place orphan */
206   NULL, /* set symbols */
207   NULL, /* parse args */
208   NULL, /* unrecognized file */
209   NULL, /* list options */
210   NULL, /* recognized file */
211   NULL  /* find_potential_libraries */