1 # This shell script emits a C file. -*- C -*-
2 # Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000
3 # Free Software Foundation, Inc.
5 # This file is part of GLD, the Gnu Linker.
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.
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.
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.
22 # This file is sourced from elf32.em, and defines extra arm-elf
25 cat >>e${EMULATION_NAME}.c <<EOF
27 static int no_pipeline_knowledge = 0;
28 static char *thumb_entry_symbol = NULL;
32 gld${EMULATION_NAME}_before_parse ()
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`;
42 static void arm_elf_after_open PARAMS((void));
47 if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
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");
58 LANG_FOR_EACH_INPUT_STATEMENT (is)
60 /* The interworking bfd must be the last one to be processed */
62 bfd_elf32_arm_get_bfd_for_interworking (is->the_bfd, & link_info);
66 /* Call the standard elf routine. */
67 gld${EMULATION_NAME}_after_open ();
71 static void arm_elf_before_allocation PARAMS ((void));
74 arm_elf_before_allocation ()
76 /* Call the standard elf routine. */
77 gld${EMULATION_NAME}_before_allocation ();
79 /* We should be able to set the size of the interworking stub section */
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 */
84 LANG_FOR_EACH_INPUT_STATEMENT (is)
86 if (!bfd_elf32_arm_process_before_allocation (is->the_bfd, & link_info,
87 no_pipeline_knowledge))
89 /* xgettext:c-format */
90 einfo (_("Errors encountered processing file %s"), is->filename);
95 /* We have seen it all. Allocate it, and carry on */
96 bfd_elf32_arm_allocate_interworking_sections (& link_info);
100 static void gld${EMULATION_NAME}_finish PARAMS ((void));
103 gld${EMULATION_NAME}_finish PARAMS((void))
105 struct bfd_link_hash_entry * h;
107 if (thumb_entry_symbol == NULL)
110 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
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)
118 static char buffer[32];
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);
130 /* Now convert this value into a string and store it in entry_symbol
131 where the lang_finish() function will pick it up. */
135 sprintf_vma (buffer + 2, val);
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;
143 einfo (_("%P: warning: connot find thumb start symbol %s\n"),
149 # Define some shell vars to insert bits of code into the standard elf
150 # parse_args and list_options functions.
152 PARSE_AND_LIST_PROLOGUE='
153 #define OPTION_THUMB_ENTRY 301
156 PARSE_AND_LIST_SHORTOPTS=p
158 PARSE_AND_LIST_LONGOPTS='
159 { "no-pipeline-knowledge", no_argument, NULL, '\'p\''},
160 { "thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
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"));
168 PARSE_AND_LIST_ARGS_CASES='
170 no_pipeline_knowledge = 1;
173 case OPTION_THUMB_ENTRY:
174 thumb_entry_symbol = optarg;
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
183 # Replace the elf before_parse function with our own.
184 LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse
186 # Call the extra arm-elf function
187 LDEMUL_FINISH=gld${EMULATION_NAME}_finish