Fixtypos in ChangeLogs, fix copyright dates in files
[external/binutils.git] / ld / emultempl / armelf.em
1 # This shell script emits a C file. -*- C -*-
2 #   Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000
3 #   Free Software Foundation, Inc.
4 #
5 # This file is part of GLD, the Gnu Linker.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #
21
22 # This file is sourced from elf32.em, and defines extra arm-elf
23 # specific routines.
24 #
25 cat >>e${EMULATION_NAME}.c <<EOF
26
27 static int no_pipeline_knowledge = 0;
28 static char *thumb_entry_symbol = NULL;
29
30
31 static void
32 gld${EMULATION_NAME}_before_parse ()
33 {
34 #ifndef TARGET_                 /* I.e., if not generic.  */
35   ldfile_set_output_arch ("`echo ${ARCH}`");
36 #endif /* not TARGET_ */
37   config.dynamic_link = ${DYNAMIC_LINK-true};
38   config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`;
39 }
40
41
42 static void arm_elf_after_open PARAMS((void));
43
44 static void
45 arm_elf_after_open ()
46 {
47   if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
48     {
49       /* The arm backend needs special fields in the output hash structure.
50          These will only be created if the output format is an arm format,
51          hence we do not support linking and changing output formats at the
52          same time.  Use a link followed by objcopy to change output formats.  */
53       einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
54       return;
55     }
56
57   {
58     LANG_FOR_EACH_INPUT_STATEMENT (is)
59       {
60         /* The interworking bfd must be the last one to be processed */
61         if (!is->next)
62           bfd_elf32_arm_get_bfd_for_interworking (is->the_bfd, & link_info);
63       }
64   }
65
66   /* Call the standard elf routine.  */
67   gld${EMULATION_NAME}_after_open ();
68 }
69
70
71 static void arm_elf_before_allocation PARAMS ((void));
72
73 static void
74 arm_elf_before_allocation ()
75 {
76   /* Call the standard elf routine.  */
77   gld${EMULATION_NAME}_before_allocation ();
78
79   /* We should be able to set the size of the interworking stub section */
80
81   /* Here we rummage through the found bfds to collect glue information */
82   /* FIXME: should this be based on a command line option? krk@cygnus.com */
83   {
84     LANG_FOR_EACH_INPUT_STATEMENT (is)
85       {
86         if (!bfd_elf32_arm_process_before_allocation (is->the_bfd, & link_info,
87                                                       no_pipeline_knowledge))
88           {
89             /* xgettext:c-format */
90             einfo (_("Errors encountered processing file %s"), is->filename);
91           }
92       }
93   }
94
95   /* We have seen it all. Allocate it, and carry on */
96   bfd_elf32_arm_allocate_interworking_sections (& link_info);
97 }
98
99
100 static void gld${EMULATION_NAME}_finish PARAMS ((void));
101
102 static void
103 gld${EMULATION_NAME}_finish PARAMS((void))
104 {
105   struct bfd_link_hash_entry * h;
106
107   if (thumb_entry_symbol == NULL)
108     return;
109   
110   h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
111                             false, false, true);
112
113   if (h != (struct bfd_link_hash_entry *) NULL
114       && (h->type == bfd_link_hash_defined
115           || h->type == bfd_link_hash_defweak)
116       && h->u.def.section->output_section != NULL)
117     {
118       static char buffer[32];
119       bfd_vma val;
120       
121       /* Special procesing is required for a Thumb entry symbol.  The
122          bottom bit of its address must be set.  */
123       val = (h->u.def.value
124              + bfd_get_section_vma (output_bfd,
125                                     h->u.def.section->output_section)
126              + h->u.def.section->output_offset);
127       
128       val |= 1;
129
130       /* Now convert this value into a string and store it in entry_symbol
131          where the lang_finish() function will pick it up.  */
132       buffer[0] = '0';
133       buffer[1] = 'x';
134       
135       sprintf_vma (buffer + 2, val);
136
137       if (entry_symbol != NULL && entry_from_cmdline)
138         einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
139                thumb_entry_symbol, entry_symbol);
140       entry_symbol = buffer;
141     }
142   else
143     einfo (_("%P: warning: connot find thumb start symbol %s\n"),
144            thumb_entry_symbol);
145 }
146
147 EOF
148
149 # Define some shell vars to insert bits of code into the standard elf
150 # parse_args and list_options functions.
151 #
152 PARSE_AND_LIST_PROLOGUE='
153 #define OPTION_THUMB_ENTRY              301
154 '
155
156 PARSE_AND_LIST_SHORTOPTS=p
157
158 PARSE_AND_LIST_LONGOPTS='
159   { "no-pipeline-knowledge", no_argument, NULL, '\'p\''},
160   { "thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
161 '
162
163 PARSE_AND_LIST_OPTIONS='
164   fprintf (file, _("  -p --no-pipeline-knowledge  Stop the linker knowing about the pipeline length\n"));
165   fprintf (file, _("     --thumb-entry=<sym>      Set the entry point to be Thumb symbol <sym>\n"));
166 '
167
168 PARSE_AND_LIST_ARGS_CASES='
169     case '\'p\'':
170       no_pipeline_knowledge = 1;
171       break;
172
173     case OPTION_THUMB_ENTRY:
174       thumb_entry_symbol = optarg;
175       break;
176 '
177
178 # We have our own after_open and before_allocation functions, but they call
179 # the standard routines, so give them a different name.
180 LDEMUL_AFTER_OPEN=arm_elf_after_open
181 LDEMUL_BEFORE_ALLOCATION=arm_elf_before_allocation
182
183 # Replace the elf before_parse function with our own.
184 LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse
185
186 # Call the extra arm-elf function
187 LDEMUL_FINISH=gld${EMULATION_NAME}_finish