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