* emultempl/elf32.em (gld${EMULATION_NAME}_finish): Only emit this
[deliverable/binutils-gdb.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 arm_elf_finish PARAMS ((void));
101
102 static void
103 arm_elf_finish ()
104 {
105 struct bfd_link_hash_entry * h;
106
107 /* Call the elf32.em routine. */
108 gld${EMULATION_NAME}_finish ();
109
110 if (thumb_entry_symbol == NULL)
111 return;
112
113 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
114 false, false, true);
115
116 if (h != (struct bfd_link_hash_entry *) NULL
117 && (h->type == bfd_link_hash_defined
118 || h->type == bfd_link_hash_defweak)
119 && h->u.def.section->output_section != NULL)
120 {
121 static char buffer[32];
122 bfd_vma val;
123
124 /* Special procesing is required for a Thumb entry symbol. The
125 bottom bit of its address must be set. */
126 val = (h->u.def.value
127 + bfd_get_section_vma (output_bfd,
128 h->u.def.section->output_section)
129 + h->u.def.section->output_offset);
130
131 val |= 1;
132
133 /* Now convert this value into a string and store it in entry_symbol
134 where the lang_finish() function will pick it up. */
135 buffer[0] = '0';
136 buffer[1] = 'x';
137
138 sprintf_vma (buffer + 2, val);
139
140 if (entry_symbol != NULL && entry_from_cmdline)
141 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
142 thumb_entry_symbol, entry_symbol);
143 entry_symbol = buffer;
144 }
145 else
146 einfo (_("%P: warning: connot find thumb start symbol %s\n"),
147 thumb_entry_symbol);
148 }
149
150 EOF
151
152 # Define some shell vars to insert bits of code into the standard elf
153 # parse_args and list_options functions.
154 #
155 PARSE_AND_LIST_PROLOGUE='
156 #define OPTION_THUMB_ENTRY 301
157 '
158
159 PARSE_AND_LIST_SHORTOPTS=p
160
161 PARSE_AND_LIST_LONGOPTS='
162 { "no-pipeline-knowledge", no_argument, NULL, '\'p\''},
163 { "thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
164 '
165
166 PARSE_AND_LIST_OPTIONS='
167 fprintf (file, _(" -p --no-pipeline-knowledge Stop the linker knowing about the pipeline length\n"));
168 fprintf (file, _(" --thumb-entry=<sym> Set the entry point to be Thumb symbol <sym>\n"));
169 '
170
171 PARSE_AND_LIST_ARGS_CASES='
172 case '\'p\'':
173 no_pipeline_knowledge = 1;
174 break;
175
176 case OPTION_THUMB_ENTRY:
177 thumb_entry_symbol = optarg;
178 break;
179 '
180
181 # We have our own after_open and before_allocation functions, but they call
182 # the standard routines, so give them a different name.
183 LDEMUL_AFTER_OPEN=arm_elf_after_open
184 LDEMUL_BEFORE_ALLOCATION=arm_elf_before_allocation
185
186 # Replace the elf before_parse function with our own.
187 LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse
188
189 # Call the extra arm-elf function
190 LDEMUL_FINISH=arm_elf_finish
This page took 0.041859 seconds and 5 git commands to generate.