133965Sjdp# This shell script emits a C file. -*- C -*- 233965Sjdp# It does some substitutions. 3130561Sobrienif [ -z "$MACHINE" ]; then 489857Sobrien OUTPUT_ARCH=${ARCH} 589857Sobrienelse 689857Sobrien OUTPUT_ARCH=${ARCH}:${MACHINE} 789857Sobrienfi 833965Sjdpcat >e${EMULATION_NAME}.c <<EOF 933965Sjdp/* This file is is generated by a shell script. DO NOT EDIT! */ 1033965Sjdp 1133965Sjdp/* Linux a.out emulation code for ${EMULATION_NAME} 12218822Sdim Copyright 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 13218822Sdim 2003, 2004, 2005, 2007 Free Software Foundation, Inc. 1433965Sjdp Written by Steve Chamberlain <sac@cygnus.com> 1533965Sjdp Linux support by Eric Youngdale <ericy@cais.cais.com> 1633965Sjdp 1733965SjdpThis file is part of GLD, the Gnu Linker. 1833965Sjdp 1933965SjdpThis program is free software; you can redistribute it and/or modify 2033965Sjdpit under the terms of the GNU General Public License as published by 2133965Sjdpthe Free Software Foundation; either version 2 of the License, or 2233965Sjdp(at your option) any later version. 2333965Sjdp 2433965SjdpThis program is distributed in the hope that it will be useful, 2533965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of 2633965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2733965SjdpGNU General Public License for more details. 2833965Sjdp 2933965SjdpYou should have received a copy of the GNU General Public License 3033965Sjdpalong with this program; if not, write to the Free Software 31218822SdimFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 3233965Sjdp 3333965Sjdp#define TARGET_IS_${EMULATION_NAME} 3433965Sjdp 35218822Sdim#include "sysdep.h" 3633965Sjdp#include "bfd.h" 3733965Sjdp#include "bfdlink.h" 3833965Sjdp 3933965Sjdp#include "ld.h" 4033965Sjdp#include "ldmain.h" 4133965Sjdp#include "ldmisc.h" 4233965Sjdp#include "ldexp.h" 4333965Sjdp#include "ldlang.h" 4477298Sobrien#include "ldfile.h" 4577298Sobrien#include "ldemul.h" 4633965Sjdp 4733965Sjdpstatic void 48130561Sobriengld${EMULATION_NAME}_before_parse (void) 4933965Sjdp{ 50130561Sobrien ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`); 51130561Sobrien config.dynamic_link = TRUE; 52130561Sobrien config.has_shared = TRUE; 5333965Sjdp} 5433965Sjdp 5533965Sjdp/* Try to open a dynamic archive. This is where we know that Linux 5633965Sjdp dynamic libraries have an extension of .sa. */ 5733965Sjdp 58130561Sobrienstatic bfd_boolean 59130561Sobriengld${EMULATION_NAME}_open_dynamic_archive 60130561Sobrien (const char *arch, search_dirs_type *search, lang_input_statement_type *entry) 6133965Sjdp{ 6233965Sjdp char *string; 6333965Sjdp 6433965Sjdp if (! entry->is_archive) 65130561Sobrien return FALSE; 6633965Sjdp 6733965Sjdp string = (char *) xmalloc (strlen (search->name) 6833965Sjdp + strlen (entry->filename) 6933965Sjdp + strlen (arch) 7033965Sjdp + sizeof "/lib.sa"); 7133965Sjdp 7233965Sjdp sprintf (string, "%s/lib%s%s.sa", search->name, entry->filename, arch); 7333965Sjdp 7433965Sjdp if (! ldfile_try_open_bfd (string, entry)) 7533965Sjdp { 7633965Sjdp free (string); 77130561Sobrien return FALSE; 7833965Sjdp } 7933965Sjdp 8033965Sjdp entry->filename = string; 8133965Sjdp 82130561Sobrien return TRUE; 8333965Sjdp} 8433965Sjdp 8533965Sjdp/* This is called by the create_output_section_statements routine via 8633965Sjdp lang_for_each_statement. It locates any address assignment to 8733965Sjdp .text, and modifies it to include the size of the headers. This 8833965Sjdp causes -Ttext to mean the starting address of the header, rather 8933965Sjdp than the starting address of .text, which is compatible with other 9033965Sjdp Linux tools. */ 9133965Sjdp 9233965Sjdpstatic void 93130561Sobriengld${EMULATION_NAME}_find_address_statement (lang_statement_union_type *s) 9433965Sjdp{ 9533965Sjdp if (s->header.type == lang_address_statement_enum 9633965Sjdp && strcmp (s->address_statement.section_name, ".text") == 0) 9733965Sjdp { 9833965Sjdp ASSERT (s->address_statement.address->type.node_class == etree_value); 9933965Sjdp s->address_statement.address->value.value += 0x20; 10033965Sjdp } 10133965Sjdp} 10233965Sjdp 10333965Sjdp/* This is called before opening the input BFD's. */ 10433965Sjdp 10533965Sjdpstatic void 106130561Sobriengld${EMULATION_NAME}_create_output_section_statements (void) 10733965Sjdp{ 10833965Sjdp lang_for_each_statement (gld${EMULATION_NAME}_find_address_statement); 10933965Sjdp} 11033965Sjdp 11133965Sjdp/* This is called after the sections have been attached to output 11233965Sjdp sections, but before any sizes or addresses have been set. */ 11333965Sjdp 11433965Sjdpstatic void 115130561Sobriengld${EMULATION_NAME}_before_allocation (void) 11633965Sjdp{ 117130561Sobrien if (link_info.relocatable) 11833965Sjdp return; 11933965Sjdp 12033965Sjdp /* Let the backend work out the sizes of any sections required by 12133965Sjdp dynamic linking. */ 12233965Sjdp if (! bfd_${EMULATION_NAME}_size_dynamic_sections (output_bfd, &link_info)) 12333965Sjdp einfo ("%P%F: failed to set dynamic section sizes: %E\n"); 124218822Sdim 125218822Sdim before_allocation_default (); 12633965Sjdp} 12733965Sjdp 12833965Sjdpstatic char * 129130561Sobriengld${EMULATION_NAME}_get_script (int *isfile) 13033965SjdpEOF 13133965Sjdp 13233965Sjdpif test -n "$COMPILE_IN" 13333965Sjdpthen 13433965Sjdp# Scripts compiled in. 13533965Sjdp 13633965Sjdp# sed commands to quote an ld script as a C string. 13760484Sobriensc="-f stringify.sed" 13833965Sjdp 13933965Sjdpcat >>e${EMULATION_NAME}.c <<EOF 140130561Sobrien{ 14133965Sjdp *isfile = 0; 14233965Sjdp 143130561Sobrien if (link_info.relocatable && config.build_constructors) 14460484Sobrien return 14533965SjdpEOF 146130561Sobriensed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c 147130561Sobrienecho ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c 148130561Sobriensed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c 149130561Sobrienecho ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c 150130561Sobriensed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c 151130561Sobrienecho ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c 152130561Sobriensed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c 153130561Sobrienecho ' ; else return' >> e${EMULATION_NAME}.c 154130561Sobriensed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c 155130561Sobrienecho '; }' >> e${EMULATION_NAME}.c 15633965Sjdp 15733965Sjdpelse 15833965Sjdp# Scripts read from the filesystem. 15933965Sjdp 16033965Sjdpcat >>e${EMULATION_NAME}.c <<EOF 161130561Sobrien{ 16233965Sjdp *isfile = 1; 16333965Sjdp 164130561Sobrien if (link_info.relocatable && config.build_constructors) 16533965Sjdp return "ldscripts/${EMULATION_NAME}.xu"; 166130561Sobrien else if (link_info.relocatable) 16733965Sjdp return "ldscripts/${EMULATION_NAME}.xr"; 16833965Sjdp else if (!config.text_read_only) 16933965Sjdp return "ldscripts/${EMULATION_NAME}.xbn"; 17033965Sjdp else if (!config.magic_demand_paged) 17133965Sjdp return "ldscripts/${EMULATION_NAME}.xn"; 17233965Sjdp else 17333965Sjdp return "ldscripts/${EMULATION_NAME}.x"; 17433965Sjdp} 17533965SjdpEOF 17633965Sjdp 17733965Sjdpfi 17833965Sjdp 17933965Sjdpcat >>e${EMULATION_NAME}.c <<EOF 18033965Sjdp 181130561Sobrienstruct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 18233965Sjdp{ 18333965Sjdp gld${EMULATION_NAME}_before_parse, 18433965Sjdp syslib_default, 18533965Sjdp hll_default, 18633965Sjdp after_parse_default, 18733965Sjdp after_open_default, 18833965Sjdp after_allocation_default, 18933965Sjdp set_output_arch_default, 19033965Sjdp ldemul_default_target, 19133965Sjdp gld${EMULATION_NAME}_before_allocation, 19233965Sjdp gld${EMULATION_NAME}_get_script, 19333965Sjdp "${EMULATION_NAME}", 19433965Sjdp "${OUTPUT_FORMAT}", 195218822Sdim finish_default, 19633965Sjdp gld${EMULATION_NAME}_create_output_section_statements, 19760484Sobrien gld${EMULATION_NAME}_open_dynamic_archive, 19860484Sobrien NULL, /* place orphan */ 19960484Sobrien NULL, /* set symbols */ 20060484Sobrien NULL, /* parse args */ 201130561Sobrien NULL, /* add_options */ 202130561Sobrien NULL, /* handle_option */ 20360484Sobrien NULL, /* unrecognized file */ 20460484Sobrien NULL, /* list options */ 20560484Sobrien NULL, /* recognized file */ 206104834Sobrien NULL, /* find_potential_libraries */ 207104834Sobrien NULL /* new_vers_pattern */ 20833965Sjdp}; 20933965SjdpEOF 210