linux.em revision 60484
156160Sru# This shell script emits a C file. -*- C -*-
256160Sru# It does some substitutions.
321495Sjmacdcat >e${EMULATION_NAME}.c <<EOF
456160Sru/* This file is is generated by a shell script.  DO NOT EDIT! */
521495Sjmacd
621495Sjmacd/* Linux a.out emulation code for ${EMULATION_NAME}
721495Sjmacd   Copyright (C) 1991, 93, 94, 95, 96, 98, 1999 Free Software Foundation, Inc.
821495Sjmacd   Written by Steve Chamberlain <sac@cygnus.com>
921495Sjmacd   Linux support by Eric Youngdale <ericy@cais.cais.com>
1021495Sjmacd
1121495SjmacdThis file is part of GLD, the Gnu Linker.
1221495Sjmacd
1321495SjmacdThis program is free software; you can redistribute it and/or modify
1421495Sjmacdit under the terms of the GNU General Public License as published by
1521495Sjmacdthe Free Software Foundation; either version 2 of the License, or
1621495Sjmacd(at your option) any later version.
1721495Sjmacd
1821495SjmacdThis program is distributed in the hope that it will be useful,
1921495Sjmacdbut WITHOUT ANY WARRANTY; without even the implied warranty of
2021495SjmacdMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2121495SjmacdGNU General Public License for more details.
2242660Smarkm
2321495SjmacdYou should have received a copy of the GNU General Public License
2421495Sjmacdalong with this program; if not, write to the Free Software
2521495SjmacdFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
2621495Sjmacd
2721495Sjmacd#define TARGET_IS_${EMULATION_NAME}
2821495Sjmacd
2921495Sjmacd#include "bfd.h"
3056160Sru#include "sysdep.h"
3121495Sjmacd#include "bfdlink.h"
3221495Sjmacd
3321495Sjmacd#include "ld.h"
3421495Sjmacd#include "ldmain.h"
3521495Sjmacd#include "ldemul.h"
3621495Sjmacd#include "ldfile.h"
3721495Sjmacd#include "ldmisc.h"
3821495Sjmacd#include "ldexp.h"
3921495Sjmacd#include "ldlang.h"
4021495Sjmacd
4121495Sjmacdstatic void gld${EMULATION_NAME}_before_parse PARAMS ((void));
4221495Sjmacdstatic boolean gld${EMULATION_NAME}_open_dynamic_archive
4321495Sjmacd  PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
4421495Sjmacdstatic void gld${EMULATION_NAME}_find_address_statement
4521495Sjmacd  PARAMS ((lang_statement_union_type *));
4621495Sjmacdstatic void gld${EMULATION_NAME}_create_output_section_statements
4721495Sjmacd  PARAMS ((void));
4821495Sjmacdstatic void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
4921495Sjmacdstatic char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
5021495Sjmacd
5121495Sjmacdstatic void
5221495Sjmacdgld${EMULATION_NAME}_before_parse()
5321495Sjmacd{
5421495Sjmacd  ldfile_output_architecture = bfd_arch_${ARCH};
5521495Sjmacd  config.dynamic_link = true;
5621495Sjmacd  config.has_shared = true;
5721495Sjmacd}
5821495Sjmacd
5921495Sjmacd/* Try to open a dynamic archive.  This is where we know that Linux
6021495Sjmacd   dynamic libraries have an extension of .sa.  */
6121495Sjmacd
6221495Sjmacdstatic boolean
6321495Sjmacdgld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)
6421495Sjmacd     const char *arch;
6521495Sjmacd     search_dirs_type *search;
6621495Sjmacd     lang_input_statement_type *entry;
6721495Sjmacd{
6821495Sjmacd  char *string;
6921495Sjmacd
7021495Sjmacd  if (! entry->is_archive)
7121495Sjmacd    return false;
7221495Sjmacd
7321495Sjmacd  string = (char *) xmalloc (strlen (search->name)
7421495Sjmacd			     + strlen (entry->filename)
7521495Sjmacd			     + strlen (arch)
7621495Sjmacd			     + sizeof "/lib.sa");
7721495Sjmacd
7842660Smarkm  sprintf (string, "%s/lib%s%s.sa", search->name, entry->filename, arch);
7921495Sjmacd
8021495Sjmacd  if (! ldfile_try_open_bfd (string, entry))
8121495Sjmacd    {
8221495Sjmacd      free (string);
8321495Sjmacd      return false;
8421495Sjmacd    }
8521495Sjmacd
8621495Sjmacd  entry->filename = string;
8742660Smarkm
8821495Sjmacd  return true;
8921495Sjmacd}
9021495Sjmacd
9121495Sjmacd/* This is called by the create_output_section_statements routine via
9221495Sjmacd   lang_for_each_statement.  It locates any address assignment to
9321495Sjmacd   .text, and modifies it to include the size of the headers.  This
9421495Sjmacd   causes -Ttext to mean the starting address of the header, rather
9521495Sjmacd   than the starting address of .text, which is compatible with other
9621495Sjmacd   Linux tools.  */
9721495Sjmacd
9821495Sjmacdstatic void
9921495Sjmacdgld${EMULATION_NAME}_find_address_statement (s)
10021495Sjmacd     lang_statement_union_type *s;
10121495Sjmacd{
10221495Sjmacd  if (s->header.type == lang_address_statement_enum
10321495Sjmacd      && strcmp (s->address_statement.section_name, ".text") == 0)
10421495Sjmacd    {
10521495Sjmacd      ASSERT (s->address_statement.address->type.node_class == etree_value);
10621495Sjmacd      s->address_statement.address->value.value += 0x20;
10721495Sjmacd    }
10821495Sjmacd}
10921495Sjmacd
11021495Sjmacd/* This is called before opening the input BFD's.  */
11121495Sjmacd
11221495Sjmacdstatic void
11321495Sjmacdgld${EMULATION_NAME}_create_output_section_statements ()
11421495Sjmacd{
11521495Sjmacd  lang_for_each_statement (gld${EMULATION_NAME}_find_address_statement);
11621495Sjmacd}
11721495Sjmacd
11821495Sjmacd/* This is called after the sections have been attached to output
11921495Sjmacd   sections, but before any sizes or addresses have been set.  */
12021495Sjmacd
12121495Sjmacdstatic void
12221495Sjmacdgld${EMULATION_NAME}_before_allocation ()
12321495Sjmacd{
12421495Sjmacd  if (link_info.relocateable)
12521495Sjmacd    return;
12621495Sjmacd
12721495Sjmacd  /* Let the backend work out the sizes of any sections required by
12821495Sjmacd     dynamic linking.  */
12921495Sjmacd  if (! bfd_${EMULATION_NAME}_size_dynamic_sections (output_bfd, &link_info))
13042660Smarkm    einfo ("%P%F: failed to set dynamic section sizes: %E\n");
13142660Smarkm}
13242660Smarkm
13321495Sjmacdstatic char *
13421495Sjmacdgld${EMULATION_NAME}_get_script(isfile)
13521495Sjmacd     int *isfile;
13621495SjmacdEOF
13721495Sjmacd
13821495Sjmacdif test -n "$COMPILE_IN"
13921495Sjmacdthen
14021495Sjmacd# Scripts compiled in.
14121495Sjmacd
14221495Sjmacd# sed commands to quote an ld script as a C string.
14321495Sjmacdsc="-f stringify.sed"
14421495Sjmacd
14521495Sjmacdcat >>e${EMULATION_NAME}.c <<EOF
14621495Sjmacd{			     
14721495Sjmacd  *isfile = 0;
14821495Sjmacd
14921495Sjmacd  if (link_info.relocateable == true && config.build_constructors == true)
15021495Sjmacd    return
15121495SjmacdEOF
15221495Sjmacdsed $sc ldscripts/${EMULATION_NAME}.xu                     >> e${EMULATION_NAME}.c
15321495Sjmacdecho '  ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
15421495Sjmacdsed $sc ldscripts/${EMULATION_NAME}.xr                     >> e${EMULATION_NAME}.c
15521495Sjmacdecho '  ; else if (!config.text_read_only) return'         >> e${EMULATION_NAME}.c
15621495Sjmacdsed $sc ldscripts/${EMULATION_NAME}.xbn                    >> e${EMULATION_NAME}.c
15721495Sjmacdecho '  ; else if (!config.magic_demand_paged) return'     >> e${EMULATION_NAME}.c
15821495Sjmacdsed $sc ldscripts/${EMULATION_NAME}.xn                     >> e${EMULATION_NAME}.c
15921495Sjmacdecho '  ; else return'                                     >> e${EMULATION_NAME}.c
16021495Sjmacdsed $sc ldscripts/${EMULATION_NAME}.x                      >> e${EMULATION_NAME}.c
16121495Sjmacdecho '; }'                                                 >> e${EMULATION_NAME}.c
16221495Sjmacd
16321495Sjmacdelse
16421495Sjmacd# Scripts read from the filesystem.
16521495Sjmacd
16621495Sjmacdcat >>e${EMULATION_NAME}.c <<EOF
16721495Sjmacd{			     
16821495Sjmacd  *isfile = 1;
16921495Sjmacd
17021495Sjmacd  if (link_info.relocateable == true && config.build_constructors == true)
17121495Sjmacd    return "ldscripts/${EMULATION_NAME}.xu";
17221495Sjmacd  else if (link_info.relocateable == true)
17321495Sjmacd    return "ldscripts/${EMULATION_NAME}.xr";
17421495Sjmacd  else if (!config.text_read_only)
17521495Sjmacd    return "ldscripts/${EMULATION_NAME}.xbn";
17621495Sjmacd  else if (!config.magic_demand_paged)
17721495Sjmacd    return "ldscripts/${EMULATION_NAME}.xn";
17821495Sjmacd  else
17921495Sjmacd    return "ldscripts/${EMULATION_NAME}.x";
18021495Sjmacd}
18121495SjmacdEOF
18221495Sjmacd
18321495Sjmacdfi
18421495Sjmacd
18521495Sjmacdcat >>e${EMULATION_NAME}.c <<EOF
18621495Sjmacd
18721495Sjmacdstruct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 
18821495Sjmacd{
18921495Sjmacd  gld${EMULATION_NAME}_before_parse,
19021495Sjmacd  syslib_default,
19121495Sjmacd  hll_default,
19221495Sjmacd  after_parse_default,
19321495Sjmacd  after_open_default,
19421495Sjmacd  after_allocation_default,
19521495Sjmacd  set_output_arch_default,
19621495Sjmacd  ldemul_default_target,
19721495Sjmacd  gld${EMULATION_NAME}_before_allocation,
19821495Sjmacd  gld${EMULATION_NAME}_get_script,
19921495Sjmacd  "${EMULATION_NAME}",
20021495Sjmacd  "${OUTPUT_FORMAT}",
20121495Sjmacd  NULL,	/* finish */
20221495Sjmacd  gld${EMULATION_NAME}_create_output_section_statements,
20321495Sjmacd  gld${EMULATION_NAME}_open_dynamic_archive,
20421495Sjmacd  NULL,	/* place orphan */
20521495Sjmacd  NULL,	/* set symbols */
20621495Sjmacd  NULL,	/* parse args */
20721495Sjmacd  NULL,	/* unrecognized file */
20821495Sjmacd  NULL,	/* list options */
20921495Sjmacd  NULL,	/* recognized file */
21021495Sjmacd  NULL 	/* find_potential_libraries */
21121495Sjmacd};
21221495SjmacdEOF
21321495Sjmacd