linux.em revision 130561
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} 12130561Sobrien Copyright 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003, 2004 1377298Sobrien 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 3133965SjdpFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 3233965Sjdp 3333965Sjdp#define TARGET_IS_${EMULATION_NAME} 3433965Sjdp 3533965Sjdp#include "bfd.h" 3633965Sjdp#include "sysdep.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"); 12433965Sjdp} 12533965Sjdp 12633965Sjdpstatic char * 127130561Sobriengld${EMULATION_NAME}_get_script (int *isfile) 12833965SjdpEOF 12933965Sjdp 13033965Sjdpif test -n "$COMPILE_IN" 13133965Sjdpthen 13233965Sjdp# Scripts compiled in. 13333965Sjdp 13433965Sjdp# sed commands to quote an ld script as a C string. 13560484Sobriensc="-f stringify.sed" 13633965Sjdp 13733965Sjdpcat >>e${EMULATION_NAME}.c <<EOF 138130561Sobrien{ 13933965Sjdp *isfile = 0; 14033965Sjdp 141130561Sobrien if (link_info.relocatable && config.build_constructors) 14260484Sobrien return 14333965SjdpEOF 144130561Sobriensed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c 145130561Sobrienecho ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c 146130561Sobriensed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c 147130561Sobrienecho ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c 148130561Sobriensed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c 149130561Sobrienecho ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c 150130561Sobriensed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c 151130561Sobrienecho ' ; else return' >> e${EMULATION_NAME}.c 152130561Sobriensed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c 153130561Sobrienecho '; }' >> e${EMULATION_NAME}.c 15433965Sjdp 15533965Sjdpelse 15633965Sjdp# Scripts read from the filesystem. 15733965Sjdp 15833965Sjdpcat >>e${EMULATION_NAME}.c <<EOF 159130561Sobrien{ 16033965Sjdp *isfile = 1; 16133965Sjdp 162130561Sobrien if (link_info.relocatable && config.build_constructors) 16333965Sjdp return "ldscripts/${EMULATION_NAME}.xu"; 164130561Sobrien else if (link_info.relocatable) 16533965Sjdp return "ldscripts/${EMULATION_NAME}.xr"; 16633965Sjdp else if (!config.text_read_only) 16733965Sjdp return "ldscripts/${EMULATION_NAME}.xbn"; 16833965Sjdp else if (!config.magic_demand_paged) 16933965Sjdp return "ldscripts/${EMULATION_NAME}.xn"; 17033965Sjdp else 17133965Sjdp return "ldscripts/${EMULATION_NAME}.x"; 17233965Sjdp} 17333965SjdpEOF 17433965Sjdp 17533965Sjdpfi 17633965Sjdp 17733965Sjdpcat >>e${EMULATION_NAME}.c <<EOF 17833965Sjdp 179130561Sobrienstruct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 18033965Sjdp{ 18133965Sjdp gld${EMULATION_NAME}_before_parse, 18233965Sjdp syslib_default, 18333965Sjdp hll_default, 18433965Sjdp after_parse_default, 18533965Sjdp after_open_default, 18633965Sjdp after_allocation_default, 18733965Sjdp set_output_arch_default, 18833965Sjdp ldemul_default_target, 18933965Sjdp gld${EMULATION_NAME}_before_allocation, 19033965Sjdp gld${EMULATION_NAME}_get_script, 19133965Sjdp "${EMULATION_NAME}", 19233965Sjdp "${OUTPUT_FORMAT}", 19360484Sobrien NULL, /* finish */ 19433965Sjdp gld${EMULATION_NAME}_create_output_section_statements, 19560484Sobrien gld${EMULATION_NAME}_open_dynamic_archive, 19660484Sobrien NULL, /* place orphan */ 19760484Sobrien NULL, /* set symbols */ 19860484Sobrien NULL, /* parse args */ 199130561Sobrien NULL, /* add_options */ 200130561Sobrien NULL, /* handle_option */ 20160484Sobrien NULL, /* unrecognized file */ 20260484Sobrien NULL, /* list options */ 20360484Sobrien NULL, /* recognized file */ 204104834Sobrien NULL, /* find_potential_libraries */ 205104834Sobrien NULL /* new_vers_pattern */ 20633965Sjdp}; 20733965SjdpEOF 208