(tc_gen_reloc): Handle the case where the reloc is the difference of two
[binutils.git] / ld / emultempl / gld960c.em
blobb99cb5959adf8ceee3b6d71a913688f88b001652
1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 cat >e${EMULATION_NAME}.c <<EOF
4 /* Copyright 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2003, 2004,
5    2005 Free Software Foundation, Inc.
7 This file is part of GLD, the Gnu Linker.
9 GLD is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 1, or (at your option)
12 any later version.
14 GLD is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GLD; see the file COPYING.  If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 02111-1307, USA.  */
25  * emulate the Intels port of  gld
26  */
29 #include "bfd.h"
30 #include "sysdep.h"
31 #include "libiberty.h"
32 #include "safe-ctype.h"
33 #include "bfdlink.h"
35 #include "ld.h"
36 #include "ldmisc.h"
37 #include "ldmain.h"
39 #include "ldexp.h"
40 #include "ldlang.h"
41 #include "ldfile.h"
42 #include "ldemul.h"
44 static void gld960_before_parse (void)
46   char *env ;
47   env =  getenv("G960LIB");
48   if (env) {
49     ldfile_add_library_path(env, FALSE);
50   }
51   env = getenv("G960BASE");
52   if (env)
53     ldfile_add_library_path (concat (env, "/lib", (const char *) NULL),
54                              FALSE);
55   ldfile_output_architecture = bfd_arch_i960;
58 static void
59 gld960_set_output_arch (void)
61   if (ldfile_output_machine_name != NULL
62       && *ldfile_output_machine_name != '\0')
63     {
64       char *s, *s1;
66       s = concat ("i960:", ldfile_output_machine_name, (char *) NULL);
67       for (s1 = s; *s1 != '\0'; s1++)
68         *s1 = TOLOWER (*s1);
69       ldfile_set_output_arch (s, bfd_arch_unknown);
70       free (s);
71     }
73   set_output_arch_default ();
76 static char *
77 gld960_choose_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
79   char *from_outside = getenv(TARGET_ENVIRON);
80   output_filename = "b.out";
82   if (from_outside != (char *)NULL)
83     return from_outside;
85   return "coff-Intel-little";
88 static char *
89 gld960_get_script (int *isfile)
90 EOF
92 if test -n "$COMPILE_IN"
93 then
94 # Scripts compiled in.
96 # sed commands to quote an ld script as a C string.
97 sc="-f stringify.sed"
99 cat >>e${EMULATION_NAME}.c <<EOF
101   *isfile = 0;
103   if (link_info.relocatable && config.build_constructors)
104     return
106 sed $sc ldscripts/${EMULATION_NAME}.xu                 >> e${EMULATION_NAME}.c
107 echo '  ; else if (link_info.relocatable) return'     >> e${EMULATION_NAME}.c
108 sed $sc ldscripts/${EMULATION_NAME}.xr                 >> e${EMULATION_NAME}.c
109 echo '  ; else if (!config.text_read_only) return'     >> e${EMULATION_NAME}.c
110 sed $sc ldscripts/${EMULATION_NAME}.xbn                >> e${EMULATION_NAME}.c
111 echo '  ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
112 sed $sc ldscripts/${EMULATION_NAME}.xn                 >> e${EMULATION_NAME}.c
113 echo '  ; else return'                                 >> e${EMULATION_NAME}.c
114 sed $sc ldscripts/${EMULATION_NAME}.x                  >> e${EMULATION_NAME}.c
115 echo '; }'                                             >> e${EMULATION_NAME}.c
117 else
118 # Scripts read from the filesystem.
120 cat >>e${EMULATION_NAME}.c <<EOF
122   *isfile = 1;
124   if (link_info.relocatable && config.build_constructors)
125     return "ldscripts/${EMULATION_NAME}.xu";
126   else if (link_info.relocatable)
127     return "ldscripts/${EMULATION_NAME}.xr";
128   else if (!config.text_read_only)
129     return "ldscripts/${EMULATION_NAME}.xbn";
130   else if (!config.magic_demand_paged)
131     return "ldscripts/${EMULATION_NAME}.xn";
132   else
133     return "ldscripts/${EMULATION_NAME}.x";
139 cat >>e${EMULATION_NAME}.c <<EOF
141 struct ld_emulation_xfer_struct ld_gld960coff_emulation =
143   gld960_before_parse,
144   syslib_default,
145   hll_default,
146   after_parse_default,
147   after_open_default,
148   after_allocation_default,
149   gld960_set_output_arch,
150   gld960_choose_target,
151   before_allocation_default,
152   gld960_get_script,
153   "960coff",
154   "",
155   NULL, /* finish */
156   NULL, /* create output section statements */
157   NULL, /* open dynamic archive */
158   NULL, /* place orphan */
159   NULL, /* set symbols */
160   NULL, /* parse args */
161   NULL, /* add_options */
162   NULL, /* handle_option */
163   NULL, /* unrecognized file */
164   NULL, /* list options */
165   NULL, /* recognized file */
166   NULL, /* find_potential_libraries */
167   NULL  /* new_vers_pattern */