]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* Support for the generic parts of most COFF variants, for BFD. |
5f771d47 | 2 | Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999 |
252b5132 RH |
3 | Free Software Foundation, Inc. |
4 | Written by Cygnus Support. | |
5 | ||
6 | This file is part of BFD, the Binary File Descriptor library. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | /* | |
23 | Most of this hacked by Steve Chamberlain, | |
24 | [email protected] | |
25 | */ | |
26 | /* | |
27 | ||
28 | SECTION | |
29 | coff backends | |
30 | ||
31 | BFD supports a number of different flavours of coff format. | |
32 | The major differences between formats are the sizes and | |
33 | alignments of fields in structures on disk, and the occasional | |
34 | extra field. | |
35 | ||
36 | Coff in all its varieties is implemented with a few common | |
37 | files and a number of implementation specific files. For | |
38 | example, The 88k bcs coff format is implemented in the file | |
39 | @file{coff-m88k.c}. This file @code{#include}s | |
40 | @file{coff/m88k.h} which defines the external structure of the | |
41 | coff format for the 88k, and @file{coff/internal.h} which | |
42 | defines the internal structure. @file{coff-m88k.c} also | |
43 | defines the relocations used by the 88k format | |
44 | @xref{Relocations}. | |
45 | ||
46 | The Intel i960 processor version of coff is implemented in | |
47 | @file{coff-i960.c}. This file has the same structure as | |
48 | @file{coff-m88k.c}, except that it includes @file{coff/i960.h} | |
49 | rather than @file{coff-m88k.h}. | |
50 | ||
51 | SUBSECTION | |
52 | Porting to a new version of coff | |
53 | ||
54 | The recommended method is to select from the existing | |
55 | implementations the version of coff which is most like the one | |
56 | you want to use. For example, we'll say that i386 coff is | |
57 | the one you select, and that your coff flavour is called foo. | |
58 | Copy @file{i386coff.c} to @file{foocoff.c}, copy | |
59 | @file{../include/coff/i386.h} to @file{../include/coff/foo.h}, | |
60 | and add the lines to @file{targets.c} and @file{Makefile.in} | |
61 | so that your new back end is used. Alter the shapes of the | |
62 | structures in @file{../include/coff/foo.h} so that they match | |
63 | what you need. You will probably also have to add | |
64 | @code{#ifdef}s to the code in @file{coff/internal.h} and | |
65 | @file{coffcode.h} if your version of coff is too wild. | |
66 | ||
67 | You can verify that your new BFD backend works quite simply by | |
68 | building @file{objdump} from the @file{binutils} directory, | |
69 | and making sure that its version of what's going on and your | |
70 | host system's idea (assuming it has the pretty standard coff | |
71 | dump utility, usually called @code{att-dump} or just | |
72 | @code{dump}) are the same. Then clean up your code, and send | |
73 | what you've done to Cygnus. Then your stuff will be in the | |
74 | next release, and you won't have to keep integrating it. | |
75 | ||
76 | SUBSECTION | |
77 | How the coff backend works | |
78 | ||
79 | SUBSUBSECTION | |
80 | File layout | |
81 | ||
82 | The Coff backend is split into generic routines that are | |
83 | applicable to any Coff target and routines that are specific | |
84 | to a particular target. The target-specific routines are | |
85 | further split into ones which are basically the same for all | |
86 | Coff targets except that they use the external symbol format | |
87 | or use different values for certain constants. | |
88 | ||
89 | The generic routines are in @file{coffgen.c}. These routines | |
90 | work for any Coff target. They use some hooks into the target | |
91 | specific code; the hooks are in a @code{bfd_coff_backend_data} | |
92 | structure, one of which exists for each target. | |
93 | ||
94 | The essentially similar target-specific routines are in | |
95 | @file{coffcode.h}. This header file includes executable C code. | |
96 | The various Coff targets first include the appropriate Coff | |
97 | header file, make any special defines that are needed, and | |
98 | then include @file{coffcode.h}. | |
99 | ||
100 | Some of the Coff targets then also have additional routines in | |
101 | the target source file itself. | |
102 | ||
103 | For example, @file{coff-i960.c} includes | |
104 | @file{coff/internal.h} and @file{coff/i960.h}. It then | |
105 | defines a few constants, such as @code{I960}, and includes | |
106 | @file{coffcode.h}. Since the i960 has complex relocation | |
107 | types, @file{coff-i960.c} also includes some code to | |
108 | manipulate the i960 relocs. This code is not in | |
109 | @file{coffcode.h} because it would not be used by any other | |
110 | target. | |
111 | ||
112 | SUBSUBSECTION | |
113 | Bit twiddling | |
114 | ||
115 | Each flavour of coff supported in BFD has its own header file | |
116 | describing the external layout of the structures. There is also | |
117 | an internal description of the coff layout, in | |
118 | @file{coff/internal.h}. A major function of the | |
119 | coff backend is swapping the bytes and twiddling the bits to | |
120 | translate the external form of the structures into the normal | |
121 | internal form. This is all performed in the | |
122 | @code{bfd_swap}_@i{thing}_@i{direction} routines. Some | |
123 | elements are different sizes between different versions of | |
124 | coff; it is the duty of the coff version specific include file | |
125 | to override the definitions of various packing routines in | |
126 | @file{coffcode.h}. E.g., the size of line number entry in coff is | |
127 | sometimes 16 bits, and sometimes 32 bits. @code{#define}ing | |
128 | @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the | |
129 | correct one. No doubt, some day someone will find a version of | |
130 | coff which has a varying field size not catered to at the | |
131 | moment. To port BFD, that person will have to add more @code{#defines}. | |
132 | Three of the bit twiddling routines are exported to | |
133 | @code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in} | |
00692651 | 134 | and @code{coff_swap_lineno_in}. @code{GDB} reads the symbol |
252b5132 RH |
135 | table on its own, but uses BFD to fix things up. More of the |
136 | bit twiddlers are exported for @code{gas}; | |
137 | @code{coff_swap_aux_out}, @code{coff_swap_sym_out}, | |
138 | @code{coff_swap_lineno_out}, @code{coff_swap_reloc_out}, | |
139 | @code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out}, | |
140 | @code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track | |
141 | of all the symbol table and reloc drudgery itself, thereby | |
142 | saving the internal BFD overhead, but uses BFD to swap things | |
143 | on the way out, making cross ports much safer. Doing so also | |
144 | allows BFD (and thus the linker) to use the same header files | |
145 | as @code{gas}, which makes one avenue to disaster disappear. | |
146 | ||
147 | SUBSUBSECTION | |
148 | Symbol reading | |
149 | ||
150 | The simple canonical form for symbols used by BFD is not rich | |
151 | enough to keep all the information available in a coff symbol | |
152 | table. The back end gets around this problem by keeping the original | |
153 | symbol table around, "behind the scenes". | |
154 | ||
155 | When a symbol table is requested (through a call to | |
156 | @code{bfd_canonicalize_symtab}), a request gets through to | |
157 | @code{coff_get_normalized_symtab}. This reads the symbol table from | |
158 | the coff file and swaps all the structures inside into the | |
159 | internal form. It also fixes up all the pointers in the table | |
160 | (represented in the file by offsets from the first symbol in | |
161 | the table) into physical pointers to elements in the new | |
162 | internal table. This involves some work since the meanings of | |
163 | fields change depending upon context: a field that is a | |
164 | pointer to another structure in the symbol table at one moment | |
165 | may be the size in bytes of a structure at the next. Another | |
166 | pass is made over the table. All symbols which mark file names | |
167 | (<<C_FILE>> symbols) are modified so that the internal | |
168 | string points to the value in the auxent (the real filename) | |
169 | rather than the normal text associated with the symbol | |
170 | (@code{".file"}). | |
171 | ||
172 | At this time the symbol names are moved around. Coff stores | |
173 | all symbols less than nine characters long physically | |
174 | within the symbol table; longer strings are kept at the end of | |
175 | the file in the string table. This pass moves all strings | |
176 | into memory and replaces them with pointers to the strings. | |
177 | ||
178 | ||
179 | The symbol table is massaged once again, this time to create | |
180 | the canonical table used by the BFD application. Each symbol | |
181 | is inspected in turn, and a decision made (using the | |
182 | @code{sclass} field) about the various flags to set in the | |
183 | @code{asymbol}. @xref{Symbols}. The generated canonical table | |
184 | shares strings with the hidden internal symbol table. | |
185 | ||
186 | Any linenumbers are read from the coff file too, and attached | |
187 | to the symbols which own the functions the linenumbers belong to. | |
188 | ||
189 | SUBSUBSECTION | |
190 | Symbol writing | |
191 | ||
192 | Writing a symbol to a coff file which didn't come from a coff | |
193 | file will lose any debugging information. The @code{asymbol} | |
194 | structure remembers the BFD from which the symbol was taken, and on | |
195 | output the back end makes sure that the same destination target as | |
196 | source target is present. | |
197 | ||
198 | When the symbols have come from a coff file then all the | |
199 | debugging information is preserved. | |
200 | ||
201 | Symbol tables are provided for writing to the back end in a | |
202 | vector of pointers to pointers. This allows applications like | |
203 | the linker to accumulate and output large symbol tables | |
204 | without having to do too much byte copying. | |
205 | ||
206 | This function runs through the provided symbol table and | |
207 | patches each symbol marked as a file place holder | |
208 | (@code{C_FILE}) to point to the next file place holder in the | |
209 | list. It also marks each @code{offset} field in the list with | |
210 | the offset from the first symbol of the current symbol. | |
211 | ||
212 | Another function of this procedure is to turn the canonical | |
213 | value form of BFD into the form used by coff. Internally, BFD | |
214 | expects symbol values to be offsets from a section base; so a | |
215 | symbol physically at 0x120, but in a section starting at | |
216 | 0x100, would have the value 0x20. Coff expects symbols to | |
217 | contain their final value, so symbols have their values | |
218 | changed at this point to reflect their sum with their owning | |
219 | section. This transformation uses the | |
220 | <<output_section>> field of the @code{asymbol}'s | |
221 | @code{asection} @xref{Sections}. | |
222 | ||
223 | o <<coff_mangle_symbols>> | |
224 | ||
225 | This routine runs though the provided symbol table and uses | |
226 | the offsets generated by the previous pass and the pointers | |
227 | generated when the symbol table was read in to create the | |
228 | structured hierachy required by coff. It changes each pointer | |
229 | to a symbol into the index into the symbol table of the asymbol. | |
230 | ||
231 | o <<coff_write_symbols>> | |
232 | ||
233 | This routine runs through the symbol table and patches up the | |
234 | symbols from their internal form into the coff way, calls the | |
235 | bit twiddlers, and writes out the table to the file. | |
236 | ||
237 | */ | |
238 | ||
239 | /* | |
240 | INTERNAL_DEFINITION | |
241 | coff_symbol_type | |
242 | ||
243 | DESCRIPTION | |
244 | The hidden information for an <<asymbol>> is described in a | |
245 | <<combined_entry_type>>: | |
246 | ||
247 | CODE_FRAGMENT | |
248 | . | |
249 | .typedef struct coff_ptr_struct | |
250 | .{ | |
251 | . | |
252 | . {* Remembers the offset from the first symbol in the file for | |
253 | . this symbol. Generated by coff_renumber_symbols. *} | |
254 | .unsigned int offset; | |
255 | . | |
256 | . {* Should the value of this symbol be renumbered. Used for | |
257 | . XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. *} | |
258 | .unsigned int fix_value : 1; | |
259 | . | |
260 | . {* Should the tag field of this symbol be renumbered. | |
261 | . Created by coff_pointerize_aux. *} | |
262 | .unsigned int fix_tag : 1; | |
263 | . | |
264 | . {* Should the endidx field of this symbol be renumbered. | |
265 | . Created by coff_pointerize_aux. *} | |
266 | .unsigned int fix_end : 1; | |
267 | . | |
268 | . {* Should the x_csect.x_scnlen field be renumbered. | |
269 | . Created by coff_pointerize_aux. *} | |
270 | .unsigned int fix_scnlen : 1; | |
271 | . | |
272 | . {* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the | |
273 | . index into the line number entries. Set by | |
274 | . coff_slurp_symbol_table. *} | |
275 | .unsigned int fix_line : 1; | |
276 | . | |
277 | . {* The container for the symbol structure as read and translated | |
278 | . from the file. *} | |
279 | . | |
280 | .union { | |
281 | . union internal_auxent auxent; | |
282 | . struct internal_syment syment; | |
283 | . } u; | |
284 | .} combined_entry_type; | |
285 | . | |
286 | . | |
287 | .{* Each canonical asymbol really looks like this: *} | |
288 | . | |
289 | .typedef struct coff_symbol_struct | |
290 | .{ | |
291 | . {* The actual symbol which the rest of BFD works with *} | |
292 | .asymbol symbol; | |
293 | . | |
294 | . {* A pointer to the hidden information for this symbol *} | |
295 | .combined_entry_type *native; | |
296 | . | |
297 | . {* A pointer to the linenumber information for this symbol *} | |
298 | .struct lineno_cache_entry *lineno; | |
299 | . | |
300 | . {* Have the line numbers been relocated yet ? *} | |
301 | .boolean done_lineno; | |
302 | .} coff_symbol_type; | |
303 | ||
304 | ||
305 | */ | |
306 | ||
307 | #ifdef COFF_WITH_PE | |
308 | #include "peicode.h" | |
309 | #else | |
310 | #include "coffswap.h" | |
311 | #endif | |
312 | ||
313 | #define STRING_SIZE_SIZE (4) | |
314 | ||
315 | static long sec_to_styp_flags PARAMS ((const char *, flagword)); | |
316 | static flagword styp_to_sec_flags PARAMS ((bfd *, PTR, const char *)); | |
317 | static boolean coff_bad_format_hook PARAMS ((bfd *, PTR)); | |
5dccc1dd ILT |
318 | static void coff_set_custom_section_alignment |
319 | PARAMS ((bfd *, asection *, const struct coff_section_alignment_entry *, | |
320 | unsigned int)); | |
252b5132 RH |
321 | static boolean coff_new_section_hook PARAMS ((bfd *, asection *)); |
322 | static boolean coff_set_arch_mach_hook PARAMS ((bfd *, PTR)); | |
323 | static boolean coff_write_relocs PARAMS ((bfd *, int)); | |
324 | static boolean coff_set_flags | |
325 | PARAMS ((bfd *, unsigned int *, unsigned short *)); | |
326 | static boolean coff_set_arch_mach | |
327 | PARAMS ((bfd *, enum bfd_architecture, unsigned long)); | |
328 | static boolean coff_compute_section_file_positions PARAMS ((bfd *)); | |
329 | static boolean coff_write_object_contents PARAMS ((bfd *)); | |
330 | static boolean coff_set_section_contents | |
331 | PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type)); | |
332 | static PTR buy_and_read PARAMS ((bfd *, file_ptr, int, size_t)); | |
333 | static boolean coff_slurp_line_table PARAMS ((bfd *, asection *)); | |
334 | static boolean coff_slurp_symbol_table PARAMS ((bfd *)); | |
5d54c628 ILT |
335 | static enum coff_symbol_classification coff_classify_symbol |
336 | PARAMS ((bfd *, struct internal_syment *)); | |
252b5132 RH |
337 | static boolean coff_slurp_reloc_table PARAMS ((bfd *, asection *, asymbol **)); |
338 | static long coff_canonicalize_reloc | |
339 | PARAMS ((bfd *, asection *, arelent **, asymbol **)); | |
340 | #ifndef coff_mkobject_hook | |
341 | static PTR coff_mkobject_hook PARAMS ((bfd *, PTR, PTR)); | |
342 | #endif | |
343 | \f | |
344 | /* void warning(); */ | |
345 | ||
346 | /* | |
347 | * Return a word with STYP_* (scnhdr.s_flags) flags set to represent the | |
348 | * incoming SEC_* flags. The inverse of this function is styp_to_sec_flags(). | |
349 | * NOTE: If you add to/change this routine, you should mirror the changes | |
350 | * in styp_to_sec_flags(). | |
351 | */ | |
352 | static long | |
353 | sec_to_styp_flags (sec_name, sec_flags) | |
354 | CONST char *sec_name; | |
355 | flagword sec_flags; | |
356 | { | |
357 | long styp_flags = 0; | |
358 | ||
359 | if (!strcmp (sec_name, _TEXT)) | |
360 | { | |
361 | styp_flags = STYP_TEXT; | |
362 | } | |
363 | else if (!strcmp (sec_name, _DATA)) | |
364 | { | |
365 | styp_flags = STYP_DATA; | |
366 | } | |
367 | else if (!strcmp (sec_name, _BSS)) | |
368 | { | |
369 | styp_flags = STYP_BSS; | |
370 | #ifdef _COMMENT | |
371 | } | |
372 | else if (!strcmp (sec_name, _COMMENT)) | |
373 | { | |
374 | styp_flags = STYP_INFO; | |
375 | #endif /* _COMMENT */ | |
376 | #ifdef _LIB | |
377 | } | |
378 | else if (!strcmp (sec_name, _LIB)) | |
379 | { | |
380 | styp_flags = STYP_LIB; | |
381 | #endif /* _LIB */ | |
382 | #ifdef _LIT | |
383 | } | |
384 | else if (!strcmp (sec_name, _LIT)) | |
385 | { | |
386 | styp_flags = STYP_LIT; | |
387 | #endif /* _LIT */ | |
388 | } | |
389 | else if (!strcmp (sec_name, ".debug")) | |
390 | { | |
391 | #ifdef STYP_DEBUG | |
392 | styp_flags = STYP_DEBUG; | |
393 | #else | |
394 | styp_flags = STYP_INFO; | |
395 | #endif | |
396 | } | |
397 | else if (!strncmp (sec_name, ".stab", 5)) | |
398 | { | |
399 | styp_flags = STYP_INFO; | |
400 | } | |
401 | #ifdef COFF_WITH_PE | |
402 | else if (!strcmp (sec_name, ".edata")) | |
403 | { | |
404 | styp_flags = STYP_DATA; | |
405 | } | |
406 | #endif | |
407 | #ifdef RS6000COFF_C | |
408 | else if (!strcmp (sec_name, _PAD)) | |
409 | { | |
410 | styp_flags = STYP_PAD; | |
411 | } | |
412 | else if (!strcmp (sec_name, _LOADER)) | |
413 | { | |
414 | styp_flags = STYP_LOADER; | |
415 | } | |
416 | #endif | |
417 | /* Try and figure out what it should be */ | |
418 | else if (sec_flags & SEC_CODE) | |
419 | { | |
420 | styp_flags = STYP_TEXT; | |
421 | } | |
422 | else if (sec_flags & SEC_DATA) | |
423 | { | |
424 | styp_flags = STYP_DATA; | |
425 | } | |
426 | else if (sec_flags & SEC_READONLY) | |
427 | { | |
428 | #ifdef STYP_LIT /* 29k readonly text/data section */ | |
429 | styp_flags = STYP_LIT; | |
430 | #else | |
431 | styp_flags = STYP_TEXT; | |
432 | #endif /* STYP_LIT */ | |
433 | } | |
434 | else if (sec_flags & SEC_LOAD) | |
435 | { | |
436 | styp_flags = STYP_TEXT; | |
437 | } | |
438 | else if (sec_flags & SEC_ALLOC) | |
439 | { | |
440 | styp_flags = STYP_BSS; | |
441 | } | |
442 | ||
443 | #ifdef STYP_NOLOAD | |
444 | if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0) | |
445 | styp_flags |= STYP_NOLOAD; | |
446 | #endif | |
447 | ||
448 | #ifdef COFF_WITH_PE | |
449 | if (sec_flags & SEC_LINK_ONCE) | |
450 | styp_flags |= IMAGE_SCN_LNK_COMDAT; | |
bd826630 ILT |
451 | if (sec_flags & SEC_SHARED) |
452 | styp_flags |= IMAGE_SCN_MEM_SHARED; | |
252b5132 RH |
453 | #endif |
454 | ||
455 | return (styp_flags); | |
456 | } | |
457 | /* | |
458 | * Return a word with SEC_* flags set to represent the incoming | |
459 | * STYP_* flags (from scnhdr.s_flags). The inverse of this | |
460 | * function is sec_to_styp_flags(). | |
461 | * NOTE: If you add to/change this routine, you should mirror the changes | |
462 | * in sec_to_styp_flags(). | |
463 | */ | |
464 | static flagword | |
465 | styp_to_sec_flags (abfd, hdr, name) | |
5f771d47 | 466 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
467 | PTR hdr; |
468 | const char *name; | |
469 | { | |
470 | struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr; | |
471 | long styp_flags = internal_s->s_flags; | |
472 | flagword sec_flags = 0; | |
473 | ||
474 | #ifdef STYP_NOLOAD | |
475 | if (styp_flags & STYP_NOLOAD) | |
476 | { | |
477 | sec_flags |= SEC_NEVER_LOAD; | |
478 | } | |
479 | #endif /* STYP_NOLOAD */ | |
480 | ||
481 | /* For 386 COFF, at least, an unloadable text or data section is | |
482 | actually a shared library section. */ | |
483 | if (styp_flags & STYP_TEXT) | |
484 | { | |
485 | if (sec_flags & SEC_NEVER_LOAD) | |
486 | sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY; | |
487 | else | |
488 | sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC; | |
489 | } | |
490 | else if (styp_flags & STYP_DATA) | |
491 | { | |
492 | if (sec_flags & SEC_NEVER_LOAD) | |
493 | sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY; | |
494 | else | |
495 | sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC; | |
496 | } | |
497 | else if (styp_flags & STYP_BSS) | |
498 | { | |
499 | #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY | |
500 | if (sec_flags & SEC_NEVER_LOAD) | |
501 | sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY; | |
502 | else | |
503 | #endif | |
504 | sec_flags |= SEC_ALLOC; | |
505 | } | |
506 | else if (styp_flags & STYP_INFO) | |
507 | { | |
508 | /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is | |
509 | defined. coff_compute_section_file_positions uses | |
510 | COFF_PAGE_SIZE to ensure that the low order bits of the | |
511 | section VMA and the file offset match. If we don't know | |
512 | COFF_PAGE_SIZE, we can't ensure the correct correspondence, | |
513 | and demand page loading of the file will fail. */ | |
514 | #if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS) | |
515 | sec_flags |= SEC_DEBUGGING; | |
516 | #endif | |
517 | } | |
518 | else if (styp_flags & STYP_PAD) | |
519 | { | |
520 | sec_flags = 0; | |
521 | } | |
522 | else if (strcmp (name, _TEXT) == 0) | |
523 | { | |
524 | if (sec_flags & SEC_NEVER_LOAD) | |
525 | sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY; | |
526 | else | |
527 | sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC; | |
528 | } | |
529 | else if (strcmp (name, _DATA) == 0) | |
530 | { | |
531 | if (sec_flags & SEC_NEVER_LOAD) | |
532 | sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY; | |
533 | else | |
534 | sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC; | |
535 | } | |
536 | else if (strcmp (name, _BSS) == 0) | |
537 | { | |
538 | #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY | |
539 | if (sec_flags & SEC_NEVER_LOAD) | |
540 | sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY; | |
541 | else | |
542 | #endif | |
543 | sec_flags |= SEC_ALLOC; | |
544 | } | |
545 | else if (strcmp (name, ".debug") == 0 | |
546 | #ifdef _COMMENT | |
547 | || strcmp (name, _COMMENT) == 0 | |
548 | #endif | |
549 | || strncmp (name, ".stab", 5) == 0) | |
550 | { | |
551 | #ifdef COFF_PAGE_SIZE | |
552 | sec_flags |= SEC_DEBUGGING; | |
553 | #endif | |
554 | } | |
555 | #ifdef _LIB | |
556 | else if (strcmp (name, _LIB) == 0) | |
557 | ; | |
558 | #endif | |
559 | #ifdef _LIT | |
560 | else if (strcmp (name, _LIT) == 0) | |
561 | { | |
562 | sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY; | |
563 | } | |
564 | #endif | |
565 | else | |
566 | { | |
567 | sec_flags |= SEC_ALLOC | SEC_LOAD; | |
568 | } | |
569 | ||
570 | #ifdef STYP_LIT /* A29k readonly text/data section type */ | |
571 | if ((styp_flags & STYP_LIT) == STYP_LIT) | |
572 | { | |
573 | sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY); | |
574 | } | |
575 | #endif /* STYP_LIT */ | |
576 | #ifdef STYP_OTHER_LOAD /* Other loaded sections */ | |
577 | if (styp_flags & STYP_OTHER_LOAD) | |
578 | { | |
579 | sec_flags = (SEC_LOAD | SEC_ALLOC); | |
580 | } | |
581 | #endif /* STYP_SDATA */ | |
582 | ||
583 | #ifdef COFF_WITH_PE | |
584 | if (styp_flags & IMAGE_SCN_LNK_REMOVE) | |
585 | sec_flags |= SEC_EXCLUDE; | |
586 | ||
bd826630 ILT |
587 | if (styp_flags & IMAGE_SCN_MEM_SHARED) |
588 | sec_flags |= SEC_SHARED; | |
589 | ||
252b5132 RH |
590 | if (styp_flags & IMAGE_SCN_LNK_COMDAT) |
591 | { | |
592 | sec_flags |= SEC_LINK_ONCE; | |
593 | ||
594 | /* Unfortunately, the PE format stores essential information in | |
595 | the symbol table, of all places. We need to extract that | |
596 | information now, so that objdump and the linker will know how | |
597 | to handle the section without worrying about the symbols. We | |
598 | can't call slurp_symtab, because the linker doesn't want the | |
599 | swapped symbols. */ | |
600 | ||
ec0ef80e DD |
601 | /* COMDAT sections are special. The first symbol is the section |
602 | symbol, which tells what kind of COMDAT section it is. The | |
603 | *second* symbol is the "comdat symbol" - the one with the | |
604 | unique name. GNU uses the section symbol for the unique | |
605 | name; MS uses ".text" for every comdat section. Sigh. - DJ */ | |
606 | ||
252b5132 RH |
607 | if (_bfd_coff_get_external_symbols (abfd)) |
608 | { | |
609 | bfd_byte *esym, *esymend; | |
610 | ||
611 | esym = (bfd_byte *) obj_coff_external_syms (abfd); | |
612 | esymend = esym + obj_raw_syment_count (abfd) * SYMESZ; | |
613 | ||
614 | while (esym < esymend) | |
615 | { | |
616 | struct internal_syment isym; | |
617 | ||
618 | bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &isym); | |
619 | ||
620 | if (sizeof (internal_s->s_name) > SYMNMLEN) | |
621 | { | |
622 | /* This case implies that the matching symbol name | |
623 | will be in the string table. */ | |
624 | abort (); | |
625 | } | |
626 | ||
627 | if (isym.n_sclass == C_STAT | |
628 | && isym.n_type == T_NULL | |
629 | && isym.n_numaux == 1) | |
630 | { | |
631 | char buf[SYMNMLEN + 1]; | |
632 | const char *symname; | |
633 | ||
634 | symname = _bfd_coff_internal_syment_name (abfd, &isym, buf); | |
635 | if (symname == NULL) | |
636 | abort (); | |
637 | ||
638 | if (strcmp (name, symname) == 0) | |
639 | { | |
640 | union internal_auxent aux; | |
641 | ||
642 | /* This is the section symbol. */ | |
643 | ||
644 | bfd_coff_swap_aux_in (abfd, (PTR) (esym + SYMESZ), | |
645 | isym.n_type, isym.n_sclass, | |
646 | 0, isym.n_numaux, (PTR) &aux); | |
647 | ||
ec0ef80e DD |
648 | /* FIXME: Microsoft uses NODUPLICATES and |
649 | ASSOCIATIVE, but gnu uses ANY and SAME_SIZE. | |
650 | Unfortunately, gnu doesn't do the comdat | |
651 | symbols right. So, until we can fix it to do | |
652 | the right thing, we are temporarily disabling | |
653 | comdats for the MS types (they're used in | |
654 | DLLs and C++, but we don't support *their* | |
655 | C++ libraries anyway - DJ */ | |
656 | ||
252b5132 RH |
657 | switch (aux.x_scn.x_comdat) |
658 | { | |
659 | case IMAGE_COMDAT_SELECT_NODUPLICATES: | |
ec0ef80e | 660 | #if 0 |
252b5132 | 661 | sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY; |
ec0ef80e DD |
662 | #else |
663 | sec_flags &= ~SEC_LINK_ONCE; | |
664 | #endif | |
252b5132 RH |
665 | break; |
666 | ||
667 | default: | |
668 | case IMAGE_COMDAT_SELECT_ANY: | |
669 | sec_flags |= SEC_LINK_DUPLICATES_DISCARD; | |
670 | break; | |
671 | ||
672 | case IMAGE_COMDAT_SELECT_SAME_SIZE: | |
673 | sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE; | |
674 | break; | |
675 | ||
676 | case IMAGE_COMDAT_SELECT_EXACT_MATCH: | |
677 | sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS; | |
678 | break; | |
679 | ||
680 | case IMAGE_COMDAT_SELECT_ASSOCIATIVE: | |
ec0ef80e | 681 | #if 0 |
252b5132 RH |
682 | /* FIXME: This is not currently implemented. */ |
683 | sec_flags |= SEC_LINK_DUPLICATES_DISCARD; | |
ec0ef80e DD |
684 | #else |
685 | sec_flags &= ~SEC_LINK_ONCE; | |
686 | #endif | |
252b5132 RH |
687 | break; |
688 | } | |
689 | ||
690 | break; | |
691 | } | |
692 | } | |
693 | ||
694 | esym += (isym.n_numaux + 1) * SYMESZ; | |
695 | } | |
696 | } | |
697 | } | |
698 | #endif | |
699 | ||
242eabea ILT |
700 | #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE) |
701 | /* As a GNU extension, if the name begins with .gnu.linkonce, we | |
702 | only link a single copy of the section. This is used to support | |
703 | g++. g++ will emit each template expansion in its own section. | |
704 | The symbols will be defined as weak, so that multiple definitions | |
705 | are permitted. The GNU linker extension is to actually discard | |
706 | all but one of the sections. */ | |
707 | if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0) | |
708 | sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD; | |
709 | #endif | |
710 | ||
252b5132 RH |
711 | return (sec_flags); |
712 | } | |
713 | ||
714 | #define get_index(symbol) ((symbol)->udata.i) | |
715 | ||
716 | /* | |
717 | INTERNAL_DEFINITION | |
718 | bfd_coff_backend_data | |
719 | ||
720 | CODE_FRAGMENT | |
721 | ||
5d54c628 ILT |
722 | .{* COFF symbol classifications. *} |
723 | . | |
724 | .enum coff_symbol_classification | |
725 | .{ | |
726 | . {* Global symbol. *} | |
727 | . COFF_SYMBOL_GLOBAL, | |
728 | . {* Common symbol. *} | |
729 | . COFF_SYMBOL_COMMON, | |
730 | . {* Undefined symbol. *} | |
731 | . COFF_SYMBOL_UNDEFINED, | |
732 | . {* Local symbol. *} | |
733 | . COFF_SYMBOL_LOCAL, | |
734 | . {* PE section symbol. *} | |
735 | . COFF_SYMBOL_PE_SECTION | |
736 | .}; | |
737 | . | |
252b5132 RH |
738 | Special entry points for gdb to swap in coff symbol table parts: |
739 | .typedef struct | |
740 | .{ | |
741 | . void (*_bfd_coff_swap_aux_in) PARAMS (( | |
742 | . bfd *abfd, | |
743 | . PTR ext, | |
744 | . int type, | |
745 | . int class, | |
746 | . int indaux, | |
747 | . int numaux, | |
748 | . PTR in)); | |
749 | . | |
750 | . void (*_bfd_coff_swap_sym_in) PARAMS (( | |
751 | . bfd *abfd , | |
752 | . PTR ext, | |
753 | . PTR in)); | |
754 | . | |
755 | . void (*_bfd_coff_swap_lineno_in) PARAMS (( | |
756 | . bfd *abfd, | |
757 | . PTR ext, | |
758 | . PTR in)); | |
759 | . | |
760 | ||
761 | Special entry points for gas to swap out coff parts: | |
762 | ||
763 | . unsigned int (*_bfd_coff_swap_aux_out) PARAMS (( | |
764 | . bfd *abfd, | |
765 | . PTR in, | |
766 | . int type, | |
767 | . int class, | |
768 | . int indaux, | |
769 | . int numaux, | |
770 | . PTR ext)); | |
771 | . | |
772 | . unsigned int (*_bfd_coff_swap_sym_out) PARAMS (( | |
773 | . bfd *abfd, | |
774 | . PTR in, | |
775 | . PTR ext)); | |
776 | . | |
777 | . unsigned int (*_bfd_coff_swap_lineno_out) PARAMS (( | |
778 | . bfd *abfd, | |
779 | . PTR in, | |
780 | . PTR ext)); | |
781 | . | |
782 | . unsigned int (*_bfd_coff_swap_reloc_out) PARAMS (( | |
783 | . bfd *abfd, | |
784 | . PTR src, | |
785 | . PTR dst)); | |
786 | . | |
787 | . unsigned int (*_bfd_coff_swap_filehdr_out) PARAMS (( | |
788 | . bfd *abfd, | |
789 | . PTR in, | |
790 | . PTR out)); | |
791 | . | |
792 | . unsigned int (*_bfd_coff_swap_aouthdr_out) PARAMS (( | |
793 | . bfd *abfd, | |
794 | . PTR in, | |
795 | . PTR out)); | |
796 | . | |
797 | . unsigned int (*_bfd_coff_swap_scnhdr_out) PARAMS (( | |
798 | . bfd *abfd, | |
799 | . PTR in, | |
800 | . PTR out)); | |
801 | . | |
802 | ||
803 | Special entry points for generic COFF routines to call target | |
804 | dependent COFF routines: | |
805 | ||
806 | . unsigned int _bfd_filhsz; | |
807 | . unsigned int _bfd_aoutsz; | |
808 | . unsigned int _bfd_scnhsz; | |
809 | . unsigned int _bfd_symesz; | |
810 | . unsigned int _bfd_auxesz; | |
811 | . unsigned int _bfd_relsz; | |
812 | . unsigned int _bfd_linesz; | |
813 | . boolean _bfd_coff_long_filenames; | |
814 | . boolean _bfd_coff_long_section_names; | |
815 | . unsigned int _bfd_coff_default_section_alignment_power; | |
816 | . void (*_bfd_coff_swap_filehdr_in) PARAMS (( | |
817 | . bfd *abfd, | |
818 | . PTR ext, | |
819 | . PTR in)); | |
820 | . void (*_bfd_coff_swap_aouthdr_in) PARAMS (( | |
821 | . bfd *abfd, | |
822 | . PTR ext, | |
823 | . PTR in)); | |
824 | . void (*_bfd_coff_swap_scnhdr_in) PARAMS (( | |
825 | . bfd *abfd, | |
826 | . PTR ext, | |
827 | . PTR in)); | |
828 | . void (*_bfd_coff_swap_reloc_in) PARAMS (( | |
829 | . bfd *abfd, | |
830 | . PTR ext, | |
831 | . PTR in)); | |
832 | . boolean (*_bfd_coff_bad_format_hook) PARAMS (( | |
833 | . bfd *abfd, | |
834 | . PTR internal_filehdr)); | |
835 | . boolean (*_bfd_coff_set_arch_mach_hook) PARAMS (( | |
836 | . bfd *abfd, | |
837 | . PTR internal_filehdr)); | |
838 | . PTR (*_bfd_coff_mkobject_hook) PARAMS (( | |
839 | . bfd *abfd, | |
840 | . PTR internal_filehdr, | |
841 | . PTR internal_aouthdr)); | |
842 | . flagword (*_bfd_styp_to_sec_flags_hook) PARAMS (( | |
843 | . bfd *abfd, | |
844 | . PTR internal_scnhdr, | |
845 | . const char *name)); | |
846 | . void (*_bfd_set_alignment_hook) PARAMS (( | |
847 | . bfd *abfd, | |
848 | . asection *sec, | |
849 | . PTR internal_scnhdr)); | |
850 | . boolean (*_bfd_coff_slurp_symbol_table) PARAMS (( | |
851 | . bfd *abfd)); | |
852 | . boolean (*_bfd_coff_symname_in_debug) PARAMS (( | |
853 | . bfd *abfd, | |
854 | . struct internal_syment *sym)); | |
855 | . boolean (*_bfd_coff_pointerize_aux_hook) PARAMS (( | |
856 | . bfd *abfd, | |
857 | . combined_entry_type *table_base, | |
858 | . combined_entry_type *symbol, | |
859 | . unsigned int indaux, | |
860 | . combined_entry_type *aux)); | |
861 | . boolean (*_bfd_coff_print_aux) PARAMS (( | |
862 | . bfd *abfd, | |
863 | . FILE *file, | |
864 | . combined_entry_type *table_base, | |
865 | . combined_entry_type *symbol, | |
866 | . combined_entry_type *aux, | |
867 | . unsigned int indaux)); | |
868 | . void (*_bfd_coff_reloc16_extra_cases) PARAMS (( | |
869 | . bfd *abfd, | |
870 | . struct bfd_link_info *link_info, | |
871 | . struct bfd_link_order *link_order, | |
872 | . arelent *reloc, | |
873 | . bfd_byte *data, | |
874 | . unsigned int *src_ptr, | |
875 | . unsigned int *dst_ptr)); | |
876 | . int (*_bfd_coff_reloc16_estimate) PARAMS (( | |
877 | . bfd *abfd, | |
878 | . asection *input_section, | |
879 | . arelent *r, | |
880 | . unsigned int shrink, | |
881 | . struct bfd_link_info *link_info)); | |
5d54c628 | 882 | . enum coff_symbol_classification (*_bfd_coff_classify_symbol) PARAMS (( |
252b5132 RH |
883 | . bfd *abfd, |
884 | . struct internal_syment *)); | |
885 | . boolean (*_bfd_coff_compute_section_file_positions) PARAMS (( | |
886 | . bfd *abfd)); | |
887 | . boolean (*_bfd_coff_start_final_link) PARAMS (( | |
888 | . bfd *output_bfd, | |
889 | . struct bfd_link_info *info)); | |
890 | . boolean (*_bfd_coff_relocate_section) PARAMS (( | |
891 | . bfd *output_bfd, | |
892 | . struct bfd_link_info *info, | |
893 | . bfd *input_bfd, | |
894 | . asection *input_section, | |
895 | . bfd_byte *contents, | |
896 | . struct internal_reloc *relocs, | |
897 | . struct internal_syment *syms, | |
898 | . asection **sections)); | |
899 | . reloc_howto_type *(*_bfd_coff_rtype_to_howto) PARAMS (( | |
900 | . bfd *abfd, | |
901 | . asection *sec, | |
902 | . struct internal_reloc *rel, | |
903 | . struct coff_link_hash_entry *h, | |
904 | . struct internal_syment *sym, | |
905 | . bfd_vma *addendp)); | |
906 | . boolean (*_bfd_coff_adjust_symndx) PARAMS (( | |
907 | . bfd *obfd, | |
908 | . struct bfd_link_info *info, | |
909 | . bfd *ibfd, | |
910 | . asection *sec, | |
911 | . struct internal_reloc *reloc, | |
912 | . boolean *adjustedp)); | |
913 | . boolean (*_bfd_coff_link_add_one_symbol) PARAMS (( | |
914 | . struct bfd_link_info *info, | |
915 | . bfd *abfd, | |
916 | . const char *name, | |
917 | . flagword flags, | |
918 | . asection *section, | |
919 | . bfd_vma value, | |
920 | . const char *string, | |
921 | . boolean copy, | |
922 | . boolean collect, | |
923 | . struct bfd_link_hash_entry **hashp)); | |
924 | . | |
925 | . boolean (*_bfd_coff_link_output_has_begun) PARAMS (( | |
926 | . bfd * abfd, | |
927 | . struct coff_final_link_info * pfinfo)); | |
928 | . boolean (*_bfd_coff_final_link_postscript) PARAMS (( | |
929 | . bfd * abfd, | |
930 | . struct coff_final_link_info * pfinfo)); | |
931 | . | |
932 | .} bfd_coff_backend_data; | |
933 | . | |
934 | .#define coff_backend_info(abfd) ((bfd_coff_backend_data *) (abfd)->xvec->backend_data) | |
935 | . | |
936 | .#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \ | |
937 | . ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i)) | |
938 | . | |
939 | .#define bfd_coff_swap_sym_in(a,e,i) \ | |
940 | . ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i)) | |
941 | . | |
942 | .#define bfd_coff_swap_lineno_in(a,e,i) \ | |
943 | . ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i)) | |
944 | . | |
945 | .#define bfd_coff_swap_reloc_out(abfd, i, o) \ | |
946 | . ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o)) | |
947 | . | |
948 | .#define bfd_coff_swap_lineno_out(abfd, i, o) \ | |
949 | . ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o)) | |
950 | . | |
951 | .#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \ | |
952 | . ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o)) | |
953 | . | |
954 | .#define bfd_coff_swap_sym_out(abfd, i,o) \ | |
955 | . ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o)) | |
956 | . | |
957 | .#define bfd_coff_swap_scnhdr_out(abfd, i,o) \ | |
958 | . ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o)) | |
959 | . | |
960 | .#define bfd_coff_swap_filehdr_out(abfd, i,o) \ | |
961 | . ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o)) | |
962 | . | |
963 | .#define bfd_coff_swap_aouthdr_out(abfd, i,o) \ | |
964 | . ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o)) | |
965 | . | |
966 | .#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz) | |
967 | .#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz) | |
968 | .#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz) | |
969 | .#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz) | |
970 | .#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz) | |
971 | .#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz) | |
972 | .#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz) | |
973 | .#define bfd_coff_long_filenames(abfd) (coff_backend_info (abfd)->_bfd_coff_long_filenames) | |
974 | .#define bfd_coff_long_section_names(abfd) \ | |
975 | . (coff_backend_info (abfd)->_bfd_coff_long_section_names) | |
976 | .#define bfd_coff_default_section_alignment_power(abfd) \ | |
977 | . (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power) | |
978 | .#define bfd_coff_swap_filehdr_in(abfd, i,o) \ | |
979 | . ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o)) | |
980 | . | |
981 | .#define bfd_coff_swap_aouthdr_in(abfd, i,o) \ | |
982 | . ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o)) | |
983 | . | |
984 | .#define bfd_coff_swap_scnhdr_in(abfd, i,o) \ | |
985 | . ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o)) | |
986 | . | |
987 | .#define bfd_coff_swap_reloc_in(abfd, i, o) \ | |
988 | . ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o)) | |
989 | . | |
990 | .#define bfd_coff_bad_format_hook(abfd, filehdr) \ | |
991 | . ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr)) | |
992 | . | |
993 | .#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\ | |
994 | . ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr)) | |
995 | .#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\ | |
996 | . ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook) (abfd, filehdr, aouthdr)) | |
997 | . | |
998 | .#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name)\ | |
999 | . ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook) (abfd, scnhdr, name)) | |
1000 | . | |
1001 | .#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\ | |
1002 | . ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr)) | |
1003 | . | |
1004 | .#define bfd_coff_slurp_symbol_table(abfd)\ | |
1005 | . ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd)) | |
1006 | . | |
1007 | .#define bfd_coff_symname_in_debug(abfd, sym)\ | |
1008 | . ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym)) | |
1009 | . | |
1010 | .#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\ | |
1011 | . ((coff_backend_info (abfd)->_bfd_coff_print_aux)\ | |
1012 | . (abfd, file, base, symbol, aux, indaux)) | |
1013 | . | |
1014 | .#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)\ | |
1015 | . ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\ | |
1016 | . (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr)) | |
1017 | . | |
1018 | .#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\ | |
1019 | . ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\ | |
1020 | . (abfd, section, reloc, shrink, link_info)) | |
1021 | . | |
5d54c628 ILT |
1022 | .#define bfd_coff_classify_symbol(abfd, sym)\ |
1023 | . ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\ | |
252b5132 RH |
1024 | . (abfd, sym)) |
1025 | . | |
1026 | .#define bfd_coff_compute_section_file_positions(abfd)\ | |
1027 | . ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\ | |
1028 | . (abfd)) | |
1029 | . | |
1030 | .#define bfd_coff_start_final_link(obfd, info)\ | |
1031 | . ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\ | |
1032 | . (obfd, info)) | |
1033 | .#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\ | |
1034 | . ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\ | |
1035 | . (obfd, info, ibfd, o, con, rel, isyms, secs)) | |
1036 | .#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\ | |
1037 | . ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\ | |
1038 | . (abfd, sec, rel, h, sym, addendp)) | |
1039 | .#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\ | |
1040 | . ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\ | |
1041 | . (obfd, info, ibfd, sec, rel, adjustedp)) | |
1042 | .#define bfd_coff_link_add_one_symbol(info,abfd,name,flags,section,value,string,cp,coll,hashp)\ | |
1043 | . ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\ | |
1044 | . (info, abfd, name, flags, section, value, string, cp, coll, hashp)) | |
1045 | . | |
1046 | .#define bfd_coff_link_output_has_begun(a,p) \ | |
1047 | . ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a,p)) | |
1048 | .#define bfd_coff_final_link_postscript(a,p) \ | |
1049 | . ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a,p)) | |
1050 | . | |
1051 | */ | |
1052 | ||
1053 | /* See whether the magic number matches. */ | |
1054 | ||
1055 | static boolean | |
1056 | coff_bad_format_hook (abfd, filehdr) | |
5f771d47 | 1057 | bfd * abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1058 | PTR filehdr; |
1059 | { | |
1060 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
1061 | ||
1062 | if (BADMAG (*internal_f)) | |
1063 | return false; | |
1064 | ||
1065 | /* if the optional header is NULL or not the correct size then | |
1066 | quit; the only difference I can see between m88k dgux headers (MC88DMAGIC) | |
1067 | and Intel 960 readwrite headers (I960WRMAGIC) is that the | |
1068 | optional header is of a different size. | |
1069 | ||
1070 | But the mips keeps extra stuff in it's opthdr, so dont check | |
1071 | when doing that | |
1072 | */ | |
1073 | ||
1074 | #if defined(M88) || defined(I960) | |
1075 | if (internal_f->f_opthdr != 0 && AOUTSZ != internal_f->f_opthdr) | |
1076 | return false; | |
1077 | #endif | |
1078 | ||
1079 | return true; | |
1080 | } | |
1081 | ||
5dccc1dd ILT |
1082 | /* Check whether this section uses an alignment other than the |
1083 | default. */ | |
1084 | ||
1085 | static void | |
1086 | coff_set_custom_section_alignment (abfd, section, alignment_table, table_size) | |
1087 | bfd *abfd ATTRIBUTE_UNUSED; | |
1088 | asection *section; | |
1089 | const struct coff_section_alignment_entry *alignment_table; | |
1090 | const unsigned int table_size; | |
1091 | { | |
1092 | const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER; | |
1093 | unsigned int i; | |
1094 | ||
1095 | for (i = 0; i < table_size; ++i) | |
1096 | { | |
1097 | const char *secname = bfd_get_section_name (abfd, section); | |
1098 | if (alignment_table[i].comparison_length == (unsigned int) -1 | |
1099 | ? strcmp (alignment_table[i].name, secname) == 0 | |
1100 | : strncmp (alignment_table[i].name, secname, | |
1101 | alignment_table[i].comparison_length) == 0) | |
1102 | break; | |
1103 | } | |
1104 | if (i >= table_size) | |
1105 | return; | |
1106 | ||
1107 | if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY | |
1108 | && default_alignment < alignment_table[i].default_alignment_min) | |
1109 | return; | |
1110 | ||
1111 | if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY | |
1112 | && default_alignment > alignment_table[i].default_alignment_max) | |
1113 | return; | |
1114 | ||
1115 | section->alignment_power = alignment_table[i].alignment_power; | |
1116 | } | |
1117 | ||
1118 | /* Custom section alignment records. */ | |
1119 | ||
1120 | static const struct coff_section_alignment_entry | |
1121 | coff_section_alignment_table[] = | |
1122 | { | |
1123 | #ifdef COFF_SECTION_ALIGNMENT_ENTRIES | |
1124 | COFF_SECTION_ALIGNMENT_ENTRIES, | |
1125 | #endif | |
1126 | /* There must not be any gaps between .stabstr sections. */ | |
1127 | { COFF_SECTION_NAME_PARTIAL_MATCH (".stabstr"), | |
1128 | 1, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, | |
1129 | /* The .stab section must be aligned to 2**2 at most, to avoid gaps. */ | |
1130 | { COFF_SECTION_NAME_PARTIAL_MATCH (".stab"), | |
1131 | 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, | |
1132 | /* Similarly for the .ctors and .dtors sections. */ | |
1133 | { COFF_SECTION_NAME_EXACT_MATCH (".ctors"), | |
1134 | 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, | |
1135 | { COFF_SECTION_NAME_EXACT_MATCH (".dtors"), | |
1136 | 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 } | |
1137 | }; | |
1138 | ||
1139 | static const unsigned int coff_section_alignment_table_size = | |
1140 | sizeof coff_section_alignment_table / sizeof coff_section_alignment_table[0]; | |
1141 | ||
1142 | /* Initialize a section structure with information peculiar to this | |
1143 | particular implementation of COFF. */ | |
252b5132 RH |
1144 | |
1145 | static boolean | |
1146 | coff_new_section_hook (abfd, section) | |
5dccc1dd ILT |
1147 | bfd *abfd; |
1148 | asection *section; | |
252b5132 RH |
1149 | { |
1150 | combined_entry_type *native; | |
1151 | ||
1152 | section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER; | |
1153 | ||
1154 | #ifdef RS6000COFF_C | |
1155 | if (xcoff_data (abfd)->text_align_power != 0 | |
1156 | && strcmp (bfd_get_section_name (abfd, section), ".text") == 0) | |
1157 | section->alignment_power = xcoff_data (abfd)->text_align_power; | |
1158 | if (xcoff_data (abfd)->data_align_power != 0 | |
1159 | && strcmp (bfd_get_section_name (abfd, section), ".data") == 0) | |
1160 | section->alignment_power = xcoff_data (abfd)->data_align_power; | |
1161 | #endif | |
1162 | ||
1163 | /* Allocate aux records for section symbols, to store size and | |
1164 | related info. | |
1165 | ||
1166 | @@ The 10 is a guess at a plausible maximum number of aux entries | |
1167 | (but shouldn't be a constant). */ | |
1168 | native = ((combined_entry_type *) | |
1169 | bfd_zalloc (abfd, sizeof (combined_entry_type) * 10)); | |
1170 | if (native == NULL) | |
1171 | return false; | |
1172 | ||
1173 | /* We don't need to set up n_name, n_value, or n_scnum in the native | |
1174 | symbol information, since they'll be overriden by the BFD symbol | |
1175 | anyhow. However, we do need to set the type and storage class, | |
1176 | in case this symbol winds up getting written out. The value 0 | |
1177 | for n_numaux is already correct. */ | |
1178 | ||
1179 | native->u.syment.n_type = T_NULL; | |
1180 | native->u.syment.n_sclass = C_STAT; | |
1181 | ||
1182 | coffsymbol (section->symbol)->native = native; | |
1183 | ||
5dccc1dd ILT |
1184 | coff_set_custom_section_alignment (abfd, section, |
1185 | coff_section_alignment_table, | |
1186 | coff_section_alignment_table_size); | |
252b5132 RH |
1187 | |
1188 | return true; | |
1189 | } | |
1190 | ||
1191 | #ifdef COFF_ALIGN_IN_SECTION_HEADER | |
1192 | ||
1193 | /* Set the alignment of a BFD section. */ | |
1194 | ||
1195 | static void coff_set_alignment_hook PARAMS ((bfd *, asection *, PTR)); | |
1196 | ||
1197 | static void | |
1198 | coff_set_alignment_hook (abfd, section, scnhdr) | |
5f771d47 | 1199 | bfd * abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1200 | asection * section; |
1201 | PTR scnhdr; | |
1202 | { | |
1203 | struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr; | |
1204 | unsigned int i; | |
1205 | ||
1206 | #ifdef I960 | |
1207 | /* Extract ALIGN from 2**ALIGN stored in section header */ | |
1208 | for (i = 0; i < 32; i++) | |
1209 | if ((1 << i) >= hdr->s_align) | |
1210 | break; | |
1211 | #endif | |
1212 | #ifdef TIC80COFF | |
1213 | /* TI tools hijack bits 8-11 for the alignment */ | |
1214 | i = (hdr->s_flags >> 8) & 0xF ; | |
1215 | #endif | |
1216 | section->alignment_power = i; | |
1217 | } | |
1218 | ||
1219 | #else /* ! COFF_ALIGN_IN_SECTION_HEADER */ | |
1220 | #ifdef COFF_WITH_PE | |
1221 | ||
1222 | /* a couple of macros to help setting the alignment power field */ | |
1223 | #define ALIGN_SET(field,x,y) \ | |
1224 | if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x )\ | |
1225 | {\ | |
1226 | section->alignment_power = y;\ | |
1227 | } | |
1228 | ||
1229 | #define ELIFALIGN_SET(field,x,y) \ | |
1230 | else if (( (field) & IMAGE_SCN_ALIGN_64BYTES) == x ) \ | |
1231 | {\ | |
1232 | section->alignment_power = y;\ | |
1233 | } | |
1234 | ||
1235 | static void coff_set_alignment_hook PARAMS ((bfd *, asection *, PTR)); | |
1236 | ||
1237 | static void | |
1238 | coff_set_alignment_hook (abfd, section, scnhdr) | |
5f771d47 | 1239 | bfd * abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1240 | asection * section; |
1241 | PTR scnhdr; | |
1242 | { | |
1243 | struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr; | |
1244 | ||
1245 | ALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_64BYTES, 6) | |
1246 | ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_32BYTES, 5) | |
1247 | ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_16BYTES, 4) | |
1248 | ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_8BYTES, 3) | |
1249 | ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_4BYTES, 2) | |
1250 | ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_2BYTES, 1) | |
1251 | ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_1BYTES, 0) | |
1252 | ||
1253 | #ifdef POWERPC_LE_PE | |
1254 | if (strcmp (section->name, ".idata$2") == 0) | |
1255 | { | |
1256 | section->alignment_power = 0; | |
1257 | } | |
1258 | else if (strcmp (section->name, ".idata$3") == 0) | |
1259 | { | |
1260 | section->alignment_power = 0; | |
1261 | } | |
1262 | else if (strcmp (section->name, ".idata$4") == 0) | |
1263 | { | |
1264 | section->alignment_power = 2; | |
1265 | } | |
1266 | else if (strcmp (section->name, ".idata$5") == 0) | |
1267 | { | |
1268 | section->alignment_power = 2; | |
1269 | } | |
1270 | else if (strcmp (section->name, ".idata$6") == 0) | |
1271 | { | |
1272 | section->alignment_power = 1; | |
1273 | } | |
1274 | else if (strcmp (section->name, ".reloc") == 0) | |
1275 | { | |
1276 | section->alignment_power = 1; | |
1277 | } | |
1278 | else if (strncmp (section->name, ".stab", 5) == 0) | |
1279 | { | |
1280 | section->alignment_power = 2; | |
1281 | } | |
1282 | #endif | |
1283 | ||
1284 | #ifdef COFF_IMAGE_WITH_PE | |
1285 | /* In a PE image file, the s_paddr field holds the virtual size of a | |
1286 | section, while the s_size field holds the raw size. */ | |
1287 | if (hdr->s_paddr != 0) | |
1288 | { | |
1289 | if (coff_section_data (abfd, section) == NULL) | |
1290 | { | |
1291 | section->used_by_bfd = | |
1292 | (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata)); | |
1293 | if (section->used_by_bfd == NULL) | |
1294 | { | |
1295 | /* FIXME: Return error. */ | |
1296 | abort (); | |
1297 | } | |
1298 | } | |
1299 | if (pei_section_data (abfd, section) == NULL) | |
1300 | { | |
1301 | coff_section_data (abfd, section)->tdata = | |
1302 | (PTR) bfd_zalloc (abfd, sizeof (struct pei_section_tdata)); | |
1303 | if (coff_section_data (abfd, section)->tdata == NULL) | |
1304 | { | |
1305 | /* FIXME: Return error. */ | |
1306 | abort (); | |
1307 | } | |
1308 | } | |
1309 | pei_section_data (abfd, section)->virt_size = hdr->s_paddr; | |
1310 | } | |
1311 | #endif | |
1312 | ||
9d8cefa9 RH |
1313 | #ifdef COFF_WITH_PE |
1314 | section->lma = hdr->s_vaddr; | |
1315 | #endif | |
252b5132 RH |
1316 | } |
1317 | #undef ALIGN_SET | |
1318 | #undef ELIFALIGN_SET | |
1319 | ||
1320 | #else /* ! COFF_WITH_PE */ | |
1321 | #ifdef RS6000COFF_C | |
1322 | ||
1323 | /* We grossly abuse this function to handle XCOFF overflow headers. | |
1324 | When we see one, we correct the reloc and line number counts in the | |
1325 | real header, and remove the section we just created. */ | |
1326 | ||
1327 | static void coff_set_alignment_hook PARAMS ((bfd *, asection *, PTR)); | |
1328 | ||
1329 | static void | |
1330 | coff_set_alignment_hook (abfd, section, scnhdr) | |
1331 | bfd *abfd; | |
1332 | asection *section; | |
1333 | PTR scnhdr; | |
1334 | { | |
1335 | struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr; | |
1336 | asection *real_sec; | |
1337 | asection **ps; | |
1338 | ||
1339 | if ((hdr->s_flags & STYP_OVRFLO) == 0) | |
1340 | return; | |
1341 | ||
1342 | real_sec = coff_section_from_bfd_index (abfd, hdr->s_nreloc); | |
1343 | if (real_sec == NULL) | |
1344 | return; | |
1345 | ||
1346 | real_sec->reloc_count = hdr->s_paddr; | |
1347 | real_sec->lineno_count = hdr->s_vaddr; | |
1348 | ||
1349 | for (ps = &abfd->sections; *ps != NULL; ps = &(*ps)->next) | |
1350 | { | |
1351 | if (*ps == section) | |
1352 | { | |
1353 | *ps = (*ps)->next; | |
1354 | --abfd->section_count; | |
1355 | break; | |
1356 | } | |
1357 | } | |
1358 | } | |
1359 | ||
1360 | #else /* ! RS6000COFF_C */ | |
1361 | ||
1362 | #define coff_set_alignment_hook \ | |
1363 | ((void (*) PARAMS ((bfd *, asection *, PTR))) bfd_void) | |
1364 | ||
1365 | #endif /* ! RS6000COFF_C */ | |
1366 | #endif /* ! COFF_WITH_PE */ | |
1367 | #endif /* ! COFF_ALIGN_IN_SECTION_HEADER */ | |
1368 | ||
1369 | #ifndef coff_mkobject | |
1370 | ||
1371 | static boolean coff_mkobject PARAMS ((bfd *)); | |
1372 | ||
1373 | static boolean | |
1374 | coff_mkobject (abfd) | |
1375 | bfd * abfd; | |
1376 | { | |
1377 | coff_data_type *coff; | |
1378 | ||
1379 | abfd->tdata.coff_obj_data = (struct coff_tdata *) bfd_zalloc (abfd, sizeof (coff_data_type)); | |
1380 | if (abfd->tdata.coff_obj_data == 0) | |
1381 | return false; | |
1382 | coff = coff_data (abfd); | |
1383 | coff->symbols = (coff_symbol_type *) NULL; | |
1384 | coff->conversion_table = (unsigned int *) NULL; | |
1385 | coff->raw_syments = (struct coff_ptr_struct *) NULL; | |
1386 | coff->relocbase = 0; | |
1387 | coff->local_toc_sym_map = 0; | |
1388 | ||
1389 | /* make_abs_section(abfd);*/ | |
1390 | ||
1391 | return true; | |
1392 | } | |
1393 | #endif | |
1394 | ||
1395 | /* Create the COFF backend specific information. */ | |
1396 | #ifndef coff_mkobject_hook | |
1397 | static PTR | |
1398 | coff_mkobject_hook (abfd, filehdr, aouthdr) | |
1399 | bfd * abfd; | |
1400 | PTR filehdr; | |
5f771d47 | 1401 | PTR aouthdr ATTRIBUTE_UNUSED; |
252b5132 RH |
1402 | { |
1403 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
1404 | coff_data_type *coff; | |
1405 | ||
1406 | if (coff_mkobject (abfd) == false) | |
1407 | return NULL; | |
1408 | ||
1409 | coff = coff_data (abfd); | |
1410 | ||
1411 | coff->sym_filepos = internal_f->f_symptr; | |
1412 | ||
1413 | /* These members communicate important constants about the symbol | |
1414 | table to GDB's symbol-reading code. These `constants' | |
1415 | unfortunately vary among coff implementations... */ | |
1416 | coff->local_n_btmask = N_BTMASK; | |
1417 | coff->local_n_btshft = N_BTSHFT; | |
1418 | coff->local_n_tmask = N_TMASK; | |
1419 | coff->local_n_tshift = N_TSHIFT; | |
1420 | coff->local_symesz = SYMESZ; | |
1421 | coff->local_auxesz = AUXESZ; | |
1422 | coff->local_linesz = LINESZ; | |
1423 | ||
1424 | obj_raw_syment_count (abfd) = | |
1425 | obj_conv_table_size (abfd) = | |
1426 | internal_f->f_nsyms; | |
1427 | ||
1428 | #ifdef RS6000COFF_C | |
1429 | if ((internal_f->f_flags & F_SHROBJ) != 0) | |
1430 | abfd->flags |= DYNAMIC; | |
1431 | if (aouthdr != NULL && internal_f->f_opthdr >= AOUTSZ) | |
1432 | { | |
1433 | struct internal_aouthdr *internal_a = | |
1434 | (struct internal_aouthdr *) aouthdr; | |
1435 | struct xcoff_tdata *xcoff; | |
1436 | ||
1437 | xcoff = xcoff_data (abfd); | |
1438 | xcoff->full_aouthdr = true; | |
1439 | xcoff->toc = internal_a->o_toc; | |
1440 | xcoff->sntoc = internal_a->o_sntoc; | |
1441 | xcoff->snentry = internal_a->o_snentry; | |
1442 | xcoff->text_align_power = internal_a->o_algntext; | |
1443 | xcoff->data_align_power = internal_a->o_algndata; | |
1444 | xcoff->modtype = internal_a->o_modtype; | |
1445 | xcoff->cputype = internal_a->o_cputype; | |
1446 | xcoff->maxdata = internal_a->o_maxdata; | |
1447 | xcoff->maxstack = internal_a->o_maxstack; | |
1448 | } | |
1449 | #endif | |
1450 | ||
1451 | #ifdef ARM | |
1452 | /* Set the flags field from the COFF header read in */ | |
1453 | if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags)) | |
1454 | coff->flags = 0; | |
1455 | #endif | |
1456 | ||
1457 | return (PTR) coff; | |
1458 | } | |
1459 | #endif | |
1460 | ||
1461 | /* Determine the machine architecture and type. FIXME: This is target | |
1462 | dependent because the magic numbers are defined in the target | |
1463 | dependent header files. But there is no particular need for this. | |
1464 | If the magic numbers were moved to a separate file, this function | |
1465 | would be target independent and would also be much more successful | |
1466 | at linking together COFF files for different architectures. */ | |
1467 | ||
1468 | static boolean | |
1469 | coff_set_arch_mach_hook (abfd, filehdr) | |
1470 | bfd *abfd; | |
1471 | PTR filehdr; | |
1472 | { | |
1473 | long machine; | |
1474 | enum bfd_architecture arch; | |
1475 | struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr; | |
1476 | ||
1477 | machine = 0; | |
1478 | switch (internal_f->f_magic) | |
1479 | { | |
1480 | #ifdef PPCMAGIC | |
1481 | case PPCMAGIC: | |
1482 | arch = bfd_arch_powerpc; | |
1483 | machine = 0; /* what does this mean? (krk) */ | |
1484 | break; | |
1485 | #endif | |
1486 | #ifdef I386MAGIC | |
1487 | case I386MAGIC: | |
1488 | case I386PTXMAGIC: | |
1489 | case I386AIXMAGIC: /* Danbury PS/2 AIX C Compiler */ | |
1490 | case LYNXCOFFMAGIC: /* shadows the m68k Lynx number below, sigh */ | |
1491 | arch = bfd_arch_i386; | |
1492 | machine = 0; | |
1493 | break; | |
1494 | #endif | |
1495 | #ifdef A29K_MAGIC_BIG | |
1496 | case A29K_MAGIC_BIG: | |
1497 | case A29K_MAGIC_LITTLE: | |
1498 | arch = bfd_arch_a29k; | |
1499 | machine = 0; | |
1500 | break; | |
1501 | #endif | |
1502 | #ifdef ARMMAGIC | |
1503 | case ARMMAGIC: | |
1504 | arch = bfd_arch_arm; | |
1505 | switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK) | |
1506 | { | |
948221a8 NC |
1507 | case F_ARM_2: machine = bfd_mach_arm_2; break; |
1508 | case F_ARM_2a: machine = bfd_mach_arm_2a; break; | |
1509 | case F_ARM_3: machine = bfd_mach_arm_3; break; | |
1510 | default: | |
1511 | case F_ARM_3M: machine = bfd_mach_arm_3M; break; | |
1512 | case F_ARM_4: machine = bfd_mach_arm_4; break; | |
1513 | case F_ARM_4T: machine = bfd_mach_arm_4T; break; | |
478d07d6 | 1514 | case F_ARM_5: machine = bfd_mach_arm_5; break; |
252b5132 RH |
1515 | } |
1516 | break; | |
1517 | #endif | |
1518 | #ifdef MC68MAGIC | |
1519 | case MC68MAGIC: | |
1520 | case M68MAGIC: | |
1521 | #ifdef MC68KBCSMAGIC | |
1522 | case MC68KBCSMAGIC: | |
1523 | #endif | |
1524 | #ifdef APOLLOM68KMAGIC | |
1525 | case APOLLOM68KMAGIC: | |
1526 | #endif | |
1527 | #ifdef LYNXCOFFMAGIC | |
1528 | case LYNXCOFFMAGIC: | |
1529 | #endif | |
1530 | arch = bfd_arch_m68k; | |
1531 | machine = bfd_mach_m68020; | |
1532 | break; | |
1533 | #endif | |
1534 | #ifdef MC88MAGIC | |
1535 | case MC88MAGIC: | |
1536 | case MC88DMAGIC: | |
1537 | case MC88OMAGIC: | |
1538 | arch = bfd_arch_m88k; | |
1539 | machine = 88100; | |
1540 | break; | |
1541 | #endif | |
1542 | #ifdef Z8KMAGIC | |
1543 | case Z8KMAGIC: | |
1544 | arch = bfd_arch_z8k; | |
1545 | switch (internal_f->f_flags & F_MACHMASK) | |
1546 | { | |
1547 | case F_Z8001: | |
1548 | machine = bfd_mach_z8001; | |
1549 | break; | |
1550 | case F_Z8002: | |
1551 | machine = bfd_mach_z8002; | |
1552 | break; | |
1553 | default: | |
1554 | return false; | |
1555 | } | |
1556 | break; | |
1557 | #endif | |
1558 | #ifdef I860 | |
1559 | case I860MAGIC: | |
1560 | arch = bfd_arch_i860; | |
1561 | break; | |
1562 | #endif | |
1563 | #ifdef I960 | |
1564 | #ifdef I960ROMAGIC | |
1565 | case I960ROMAGIC: | |
1566 | case I960RWMAGIC: | |
1567 | arch = bfd_arch_i960; | |
1568 | switch (F_I960TYPE & internal_f->f_flags) | |
1569 | { | |
1570 | default: | |
1571 | case F_I960CORE: | |
1572 | machine = bfd_mach_i960_core; | |
1573 | break; | |
1574 | case F_I960KB: | |
1575 | machine = bfd_mach_i960_kb_sb; | |
1576 | break; | |
1577 | case F_I960MC: | |
1578 | machine = bfd_mach_i960_mc; | |
1579 | break; | |
1580 | case F_I960XA: | |
1581 | machine = bfd_mach_i960_xa; | |
1582 | break; | |
1583 | case F_I960CA: | |
1584 | machine = bfd_mach_i960_ca; | |
1585 | break; | |
1586 | case F_I960KA: | |
1587 | machine = bfd_mach_i960_ka_sa; | |
1588 | break; | |
1589 | case F_I960JX: | |
1590 | machine = bfd_mach_i960_jx; | |
1591 | break; | |
1592 | case F_I960HX: | |
1593 | machine = bfd_mach_i960_hx; | |
1594 | break; | |
1595 | } | |
1596 | break; | |
1597 | #endif | |
1598 | #endif | |
1599 | ||
1600 | #ifdef RS6000COFF_C | |
1601 | case U802ROMAGIC: | |
1602 | case U802WRMAGIC: | |
1603 | case U802TOCMAGIC: | |
1604 | { | |
1605 | int cputype; | |
1606 | ||
1607 | if (xcoff_data (abfd)->cputype != -1) | |
1608 | cputype = xcoff_data (abfd)->cputype & 0xff; | |
1609 | else | |
1610 | { | |
1611 | /* We did not get a value from the a.out header. If the | |
1612 | file has not been stripped, we may be able to get the | |
1613 | architecture information from the first symbol, if it | |
1614 | is a .file symbol. */ | |
1615 | if (obj_raw_syment_count (abfd) == 0) | |
1616 | cputype = 0; | |
1617 | else | |
1618 | { | |
1619 | bfd_byte buf[SYMESZ]; | |
1620 | struct internal_syment sym; | |
1621 | ||
1622 | if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0 | |
1623 | || bfd_read (buf, 1, SYMESZ, abfd) != SYMESZ) | |
1624 | return false; | |
1625 | coff_swap_sym_in (abfd, (PTR) buf, (PTR) &sym); | |
1626 | if (sym.n_sclass == C_FILE) | |
1627 | cputype = sym.n_type & 0xff; | |
1628 | else | |
1629 | cputype = 0; | |
1630 | } | |
1631 | } | |
1632 | ||
1633 | /* FIXME: We don't handle all cases here. */ | |
1634 | switch (cputype) | |
1635 | { | |
1636 | default: | |
1637 | case 0: | |
1638 | #ifdef POWERMAC | |
1639 | /* PowerPC Macs use the same magic numbers as RS/6000 | |
1640 | (because that's how they were bootstrapped originally), | |
1641 | but they are always PowerPC architecture. */ | |
1642 | arch = bfd_arch_powerpc; | |
1643 | machine = 0; | |
1644 | #else | |
1645 | arch = bfd_arch_rs6000; | |
1646 | machine = 6000; | |
1647 | #endif /* POWERMAC */ | |
1648 | break; | |
1649 | ||
1650 | case 1: | |
1651 | arch = bfd_arch_powerpc; | |
1652 | machine = 601; | |
1653 | break; | |
1654 | case 2: /* 64 bit PowerPC */ | |
1655 | arch = bfd_arch_powerpc; | |
1656 | machine = 620; | |
1657 | break; | |
1658 | case 3: | |
1659 | arch = bfd_arch_powerpc; | |
1660 | machine = 0; | |
1661 | break; | |
1662 | case 4: | |
1663 | arch = bfd_arch_rs6000; | |
1664 | machine = 6000; | |
1665 | break; | |
1666 | } | |
1667 | } | |
1668 | break; | |
1669 | #endif | |
1670 | ||
1671 | #ifdef WE32KMAGIC | |
1672 | case WE32KMAGIC: | |
1673 | arch = bfd_arch_we32k; | |
1674 | machine = 0; | |
1675 | break; | |
1676 | #endif | |
1677 | ||
1678 | #ifdef H8300MAGIC | |
1679 | case H8300MAGIC: | |
1680 | arch = bfd_arch_h8300; | |
1681 | machine = bfd_mach_h8300; | |
1682 | /* !! FIXME this probably isn't the right place for this */ | |
1683 | abfd->flags |= BFD_IS_RELAXABLE; | |
1684 | break; | |
1685 | #endif | |
1686 | ||
1687 | #ifdef H8300HMAGIC | |
1688 | case H8300HMAGIC: | |
1689 | arch = bfd_arch_h8300; | |
1690 | machine = bfd_mach_h8300h; | |
1691 | /* !! FIXME this probably isn't the right place for this */ | |
1692 | abfd->flags |= BFD_IS_RELAXABLE; | |
1693 | break; | |
1694 | #endif | |
1695 | ||
1696 | #ifdef H8300SMAGIC | |
1697 | case H8300SMAGIC: | |
1698 | arch = bfd_arch_h8300; | |
1699 | machine = bfd_mach_h8300s; | |
1700 | /* !! FIXME this probably isn't the right place for this */ | |
1701 | abfd->flags |= BFD_IS_RELAXABLE; | |
1702 | break; | |
1703 | #endif | |
1704 | ||
1705 | #ifdef SH_ARCH_MAGIC_BIG | |
1706 | case SH_ARCH_MAGIC_BIG: | |
1707 | case SH_ARCH_MAGIC_LITTLE: | |
1708 | arch = bfd_arch_sh; | |
1709 | machine = 0; | |
1710 | break; | |
1711 | #endif | |
1712 | ||
1713 | #ifdef H8500MAGIC | |
1714 | case H8500MAGIC: | |
1715 | arch = bfd_arch_h8500; | |
1716 | machine = 0; | |
1717 | break; | |
1718 | #endif | |
1719 | ||
1720 | #ifdef SPARCMAGIC | |
1721 | case SPARCMAGIC: | |
1722 | #ifdef LYNXCOFFMAGIC | |
1723 | case LYNXCOFFMAGIC: | |
1724 | #endif | |
1725 | arch = bfd_arch_sparc; | |
1726 | machine = 0; | |
1727 | break; | |
1728 | #endif | |
1729 | ||
1730 | #ifdef TIC30MAGIC | |
1731 | case TIC30MAGIC: | |
1732 | arch = bfd_arch_tic30; | |
1733 | break; | |
1734 | #endif | |
1735 | ||
1736 | #ifdef TIC80_ARCH_MAGIC | |
1737 | case TIC80_ARCH_MAGIC: | |
1738 | arch = bfd_arch_tic80; | |
1739 | break; | |
1740 | #endif | |
1741 | ||
1742 | #ifdef MCOREMAGIC | |
1743 | case MCOREMAGIC: | |
1744 | arch = bfd_arch_mcore; | |
1745 | break; | |
1746 | #endif | |
1747 | default: /* Unreadable input file type */ | |
1748 | arch = bfd_arch_obscure; | |
1749 | break; | |
1750 | } | |
1751 | ||
1752 | bfd_default_set_arch_mach (abfd, arch, machine); | |
1753 | return true; | |
1754 | } | |
1755 | ||
1756 | #ifdef SYMNAME_IN_DEBUG | |
1757 | ||
1758 | static boolean symname_in_debug_hook | |
1759 | PARAMS ((bfd *, struct internal_syment *)); | |
1760 | ||
1761 | static boolean | |
1762 | symname_in_debug_hook (abfd, sym) | |
5f771d47 | 1763 | bfd * abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1764 | struct internal_syment *sym; |
1765 | { | |
1766 | return SYMNAME_IN_DEBUG (sym) ? true : false; | |
1767 | } | |
1768 | ||
1769 | #else | |
1770 | ||
1771 | #define symname_in_debug_hook \ | |
1772 | (boolean (*) PARAMS ((bfd *, struct internal_syment *))) bfd_false | |
1773 | ||
1774 | #endif | |
1775 | ||
1776 | #ifdef RS6000COFF_C | |
1777 | ||
1778 | /* Handle the csect auxent of a C_EXT or C_HIDEXT symbol. */ | |
1779 | ||
1780 | static boolean coff_pointerize_aux_hook | |
1781 | PARAMS ((bfd *, combined_entry_type *, combined_entry_type *, | |
1782 | unsigned int, combined_entry_type *)); | |
1783 | ||
1784 | /*ARGSUSED*/ | |
1785 | static boolean | |
1786 | coff_pointerize_aux_hook (abfd, table_base, symbol, indaux, aux) | |
5f771d47 | 1787 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1788 | combined_entry_type *table_base; |
1789 | combined_entry_type *symbol; | |
1790 | unsigned int indaux; | |
1791 | combined_entry_type *aux; | |
1792 | { | |
1793 | int class = symbol->u.syment.n_sclass; | |
1794 | ||
1795 | if ((class == C_EXT || class == C_HIDEXT) | |
1796 | && indaux + 1 == symbol->u.syment.n_numaux) | |
1797 | { | |
1798 | if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD) | |
1799 | { | |
1800 | aux->u.auxent.x_csect.x_scnlen.p = | |
1801 | table_base + aux->u.auxent.x_csect.x_scnlen.l; | |
1802 | aux->fix_scnlen = 1; | |
1803 | } | |
1804 | ||
1805 | /* Return true to indicate that the caller should not do any | |
1806 | further work on this auxent. */ | |
1807 | return true; | |
1808 | } | |
1809 | ||
1810 | /* Return false to indicate that this auxent should be handled by | |
1811 | the caller. */ | |
1812 | return false; | |
1813 | } | |
1814 | ||
1815 | #else | |
1816 | #ifdef I960 | |
1817 | ||
1818 | /* We don't want to pointerize bal entries. */ | |
1819 | ||
1820 | static boolean coff_pointerize_aux_hook | |
1821 | PARAMS ((bfd *, combined_entry_type *, combined_entry_type *, | |
1822 | unsigned int, combined_entry_type *)); | |
1823 | ||
1824 | /*ARGSUSED*/ | |
1825 | static boolean | |
1826 | coff_pointerize_aux_hook (abfd, table_base, symbol, indaux, aux) | |
5f771d47 ILT |
1827 | bfd *abfd ATTRIBUTE_UNUSED; |
1828 | combined_entry_type *table_base ATTRIBUTE_UNUSED; | |
252b5132 RH |
1829 | combined_entry_type *symbol; |
1830 | unsigned int indaux; | |
5f771d47 | 1831 | combined_entry_type *aux ATTRIBUTE_UNUSED; |
252b5132 RH |
1832 | { |
1833 | /* Return true if we don't want to pointerize this aux entry, which | |
1834 | is the case for the lastfirst aux entry for a C_LEAFPROC symbol. */ | |
1835 | return (indaux == 1 | |
1836 | && (symbol->u.syment.n_sclass == C_LEAFPROC | |
1837 | || symbol->u.syment.n_sclass == C_LEAFSTAT | |
1838 | || symbol->u.syment.n_sclass == C_LEAFEXT)); | |
1839 | } | |
1840 | ||
1841 | #else /* ! I960 */ | |
1842 | ||
1843 | #define coff_pointerize_aux_hook 0 | |
1844 | ||
1845 | #endif /* ! I960 */ | |
1846 | #endif /* ! RS6000COFF_C */ | |
1847 | ||
1848 | /* Print an aux entry. This returns true if it has printed it. */ | |
1849 | ||
1850 | static boolean coff_print_aux | |
1851 | PARAMS ((bfd *, FILE *, combined_entry_type *, combined_entry_type *, | |
1852 | combined_entry_type *, unsigned int)); | |
1853 | ||
1854 | static boolean | |
1855 | coff_print_aux (abfd, file, table_base, symbol, aux, indaux) | |
5f771d47 ILT |
1856 | bfd *abfd ATTRIBUTE_UNUSED; |
1857 | FILE *file ATTRIBUTE_UNUSED; | |
1858 | combined_entry_type *table_base ATTRIBUTE_UNUSED; | |
1859 | combined_entry_type *symbol ATTRIBUTE_UNUSED; | |
1860 | combined_entry_type *aux ATTRIBUTE_UNUSED; | |
1861 | unsigned int indaux ATTRIBUTE_UNUSED; | |
252b5132 RH |
1862 | { |
1863 | #ifdef RS6000COFF_C | |
1864 | if ((symbol->u.syment.n_sclass == C_EXT | |
1865 | || symbol->u.syment.n_sclass == C_HIDEXT) | |
1866 | && indaux + 1 == symbol->u.syment.n_numaux) | |
1867 | { | |
1868 | /* This is a csect entry. */ | |
1869 | fprintf (file, "AUX "); | |
1870 | if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD) | |
1871 | { | |
1872 | BFD_ASSERT (! aux->fix_scnlen); | |
1873 | fprintf (file, "val %5ld", aux->u.auxent.x_csect.x_scnlen.l); | |
1874 | } | |
1875 | else | |
1876 | { | |
1877 | fprintf (file, "indx "); | |
1878 | if (! aux->fix_scnlen) | |
1879 | fprintf (file, "%4ld", aux->u.auxent.x_csect.x_scnlen.l); | |
1880 | else | |
1881 | fprintf (file, "%4ld", | |
1882 | (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base)); | |
1883 | } | |
1884 | fprintf (file, | |
1885 | " prmhsh %ld snhsh %u typ %d algn %d clss %u stb %ld snstb %u", | |
1886 | aux->u.auxent.x_csect.x_parmhash, | |
1887 | (unsigned int) aux->u.auxent.x_csect.x_snhash, | |
1888 | SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp), | |
1889 | SMTYP_ALIGN (aux->u.auxent.x_csect.x_smtyp), | |
1890 | (unsigned int) aux->u.auxent.x_csect.x_smclas, | |
1891 | aux->u.auxent.x_csect.x_stab, | |
1892 | (unsigned int) aux->u.auxent.x_csect.x_snstab); | |
1893 | return true; | |
1894 | } | |
1895 | #endif | |
1896 | ||
1897 | /* Return false to indicate that no special action was taken. */ | |
1898 | return false; | |
1899 | } | |
1900 | ||
1901 | /* | |
1902 | SUBSUBSECTION | |
1903 | Writing relocations | |
1904 | ||
1905 | To write relocations, the back end steps though the | |
1906 | canonical relocation table and create an | |
1907 | @code{internal_reloc}. The symbol index to use is removed from | |
1908 | the @code{offset} field in the symbol table supplied. The | |
1909 | address comes directly from the sum of the section base | |
1910 | address and the relocation offset; the type is dug directly | |
1911 | from the howto field. Then the @code{internal_reloc} is | |
1912 | swapped into the shape of an @code{external_reloc} and written | |
1913 | out to disk. | |
1914 | ||
1915 | */ | |
1916 | ||
1917 | #ifdef TARG_AUX | |
1918 | ||
1919 | static int compare_arelent_ptr PARAMS ((const PTR, const PTR)); | |
1920 | ||
1921 | /* AUX's ld wants relocations to be sorted */ | |
1922 | static int | |
1923 | compare_arelent_ptr (x, y) | |
1924 | const PTR x; | |
1925 | const PTR y; | |
1926 | { | |
1927 | const arelent **a = (const arelent **) x; | |
1928 | const arelent **b = (const arelent **) y; | |
1929 | bfd_size_type aadr = (*a)->address; | |
1930 | bfd_size_type badr = (*b)->address; | |
1931 | ||
1932 | return (aadr < badr ? -1 : badr < aadr ? 1 : 0); | |
1933 | } | |
1934 | ||
1935 | #endif /* TARG_AUX */ | |
1936 | ||
1937 | static boolean | |
1938 | coff_write_relocs (abfd, first_undef) | |
1939 | bfd * abfd; | |
1940 | int first_undef; | |
1941 | { | |
1942 | asection *s; | |
1943 | ||
1944 | for (s = abfd->sections; s != (asection *) NULL; s = s->next) | |
1945 | { | |
1946 | unsigned int i; | |
1947 | struct external_reloc dst; | |
1948 | arelent **p; | |
1949 | ||
1950 | #ifndef TARG_AUX | |
1951 | p = s->orelocation; | |
1952 | #else | |
1953 | /* sort relocations before we write them out */ | |
1954 | p = (arelent **) bfd_malloc (s->reloc_count * sizeof (arelent *)); | |
1955 | if (p == NULL && s->reloc_count > 0) | |
1956 | return false; | |
1957 | memcpy (p, s->orelocation, s->reloc_count * sizeof (arelent *)); | |
1958 | qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr); | |
1959 | #endif | |
1960 | ||
1961 | if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0) | |
1962 | return false; | |
1963 | for (i = 0; i < s->reloc_count; i++) | |
1964 | { | |
1965 | struct internal_reloc n; | |
1966 | arelent *q = p[i]; | |
1967 | memset ((PTR) & n, 0, sizeof (n)); | |
1968 | ||
1969 | /* Now we've renumbered the symbols we know where the | |
1970 | undefined symbols live in the table. Check the reloc | |
1971 | entries for symbols who's output bfd isn't the right one. | |
1972 | This is because the symbol was undefined (which means | |
1973 | that all the pointers are never made to point to the same | |
1974 | place). This is a bad thing,'cause the symbols attached | |
1975 | to the output bfd are indexed, so that the relocation | |
1976 | entries know which symbol index they point to. So we | |
1977 | have to look up the output symbol here. */ | |
1978 | ||
1979 | if (q->sym_ptr_ptr[0]->the_bfd != abfd) | |
1980 | { | |
1981 | int i; | |
1982 | const char *sname = q->sym_ptr_ptr[0]->name; | |
1983 | asymbol **outsyms = abfd->outsymbols; | |
1984 | for (i = first_undef; outsyms[i]; i++) | |
1985 | { | |
1986 | const char *intable = outsyms[i]->name; | |
1987 | if (strcmp (intable, sname) == 0) { | |
1988 | /* got a hit, so repoint the reloc */ | |
1989 | q->sym_ptr_ptr = outsyms + i; | |
1990 | break; | |
1991 | } | |
1992 | } | |
1993 | } | |
1994 | ||
1995 | n.r_vaddr = q->address + s->vma; | |
1996 | ||
1997 | #ifdef R_IHCONST | |
1998 | /* The 29k const/consth reloc pair is a real kludge. The consth | |
1999 | part doesn't have a symbol; it has an offset. So rebuilt | |
2000 | that here. */ | |
2001 | if (q->howto->type == R_IHCONST) | |
2002 | n.r_symndx = q->addend; | |
2003 | else | |
2004 | #endif | |
2005 | if (q->sym_ptr_ptr) | |
2006 | { | |
2007 | if (q->sym_ptr_ptr == bfd_abs_section_ptr->symbol_ptr_ptr) | |
2008 | /* This is a relocation relative to the absolute symbol. */ | |
2009 | n.r_symndx = -1; | |
2010 | else | |
2011 | { | |
2012 | n.r_symndx = get_index ((*(q->sym_ptr_ptr))); | |
2013 | /* Take notice if the symbol reloc points to a symbol | |
2014 | we don't have in our symbol table. What should we | |
2015 | do for this?? */ | |
2016 | if (n.r_symndx > obj_conv_table_size (abfd)) | |
2017 | abort (); | |
2018 | } | |
2019 | } | |
2020 | ||
2021 | #ifdef SWAP_OUT_RELOC_OFFSET | |
2022 | n.r_offset = q->addend; | |
2023 | #endif | |
2024 | ||
2025 | #ifdef SELECT_RELOC | |
2026 | /* Work out reloc type from what is required */ | |
2027 | SELECT_RELOC (n, q->howto); | |
2028 | #else | |
2029 | n.r_type = q->howto->type; | |
2030 | #endif | |
2031 | coff_swap_reloc_out (abfd, &n, &dst); | |
2032 | if (bfd_write ((PTR) & dst, 1, RELSZ, abfd) != RELSZ) | |
2033 | return false; | |
2034 | } | |
2035 | ||
2036 | #ifdef TARG_AUX | |
2037 | if (p != NULL) | |
2038 | free (p); | |
2039 | #endif | |
2040 | } | |
2041 | ||
2042 | return true; | |
2043 | } | |
2044 | ||
2045 | /* Set flags and magic number of a coff file from architecture and machine | |
2046 | type. Result is true if we can represent the arch&type, false if not. */ | |
2047 | ||
2048 | static boolean | |
2049 | coff_set_flags (abfd, magicp, flagsp) | |
2050 | bfd * abfd; | |
5f771d47 ILT |
2051 | unsigned int *magicp ATTRIBUTE_UNUSED; |
2052 | unsigned short *flagsp ATTRIBUTE_UNUSED; | |
252b5132 RH |
2053 | { |
2054 | switch (bfd_get_arch (abfd)) | |
2055 | { | |
2056 | #ifdef Z8KMAGIC | |
2057 | case bfd_arch_z8k: | |
2058 | *magicp = Z8KMAGIC; | |
2059 | switch (bfd_get_mach (abfd)) | |
2060 | { | |
2061 | case bfd_mach_z8001: | |
2062 | *flagsp = F_Z8001; | |
2063 | break; | |
2064 | case bfd_mach_z8002: | |
2065 | *flagsp = F_Z8002; | |
2066 | break; | |
2067 | default: | |
2068 | return false; | |
2069 | } | |
2070 | return true; | |
2071 | #endif | |
2072 | #ifdef I960ROMAGIC | |
2073 | ||
2074 | case bfd_arch_i960: | |
2075 | ||
2076 | { | |
2077 | unsigned flags; | |
2078 | *magicp = I960ROMAGIC; | |
2079 | /* | |
2080 | ((bfd_get_file_flags(abfd) & WP_TEXT) ? I960ROMAGIC : | |
2081 | I960RWMAGIC); FIXME??? | |
2082 | */ | |
2083 | switch (bfd_get_mach (abfd)) | |
2084 | { | |
2085 | case bfd_mach_i960_core: | |
2086 | flags = F_I960CORE; | |
2087 | break; | |
2088 | case bfd_mach_i960_kb_sb: | |
2089 | flags = F_I960KB; | |
2090 | break; | |
2091 | case bfd_mach_i960_mc: | |
2092 | flags = F_I960MC; | |
2093 | break; | |
2094 | case bfd_mach_i960_xa: | |
2095 | flags = F_I960XA; | |
2096 | break; | |
2097 | case bfd_mach_i960_ca: | |
2098 | flags = F_I960CA; | |
2099 | break; | |
2100 | case bfd_mach_i960_ka_sa: | |
2101 | flags = F_I960KA; | |
2102 | break; | |
2103 | case bfd_mach_i960_jx: | |
2104 | flags = F_I960JX; | |
2105 | break; | |
2106 | case bfd_mach_i960_hx: | |
2107 | flags = F_I960HX; | |
2108 | break; | |
2109 | default: | |
2110 | return false; | |
2111 | } | |
2112 | *flagsp = flags; | |
2113 | return true; | |
2114 | } | |
2115 | break; | |
2116 | #endif | |
2117 | ||
2118 | #ifdef TIC30MAGIC | |
2119 | case bfd_arch_tic30: | |
2120 | *magicp = TIC30MAGIC; | |
2121 | return true; | |
2122 | #endif | |
2123 | #ifdef TIC80_ARCH_MAGIC | |
2124 | case bfd_arch_tic80: | |
2125 | *magicp = TIC80_ARCH_MAGIC; | |
2126 | return true; | |
2127 | #endif | |
2128 | #ifdef ARMMAGIC | |
2129 | case bfd_arch_arm: | |
2130 | * magicp = ARMMAGIC; | |
2131 | * flagsp = 0; | |
2132 | if (APCS_SET (abfd)) | |
2133 | { | |
2134 | if (APCS_26_FLAG (abfd)) | |
2135 | * flagsp |= F_APCS26; | |
2136 | ||
2137 | if (APCS_FLOAT_FLAG (abfd)) | |
2138 | * flagsp |= F_APCS_FLOAT; | |
2139 | ||
2140 | if (PIC_FLAG (abfd)) | |
948221a8 | 2141 | * flagsp |= F_PIC; |
252b5132 RH |
2142 | } |
2143 | if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd)) | |
2144 | * flagsp |= F_INTERWORK; | |
2145 | switch (bfd_get_mach (abfd)) | |
2146 | { | |
2147 | case bfd_mach_arm_2: * flagsp |= F_ARM_2; break; | |
2148 | case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break; | |
2149 | case bfd_mach_arm_3: * flagsp |= F_ARM_3; break; | |
2150 | case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break; | |
2151 | case bfd_mach_arm_4: * flagsp |= F_ARM_4; break; | |
2152 | case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break; | |
478d07d6 NC |
2153 | case bfd_mach_arm_5: * flagsp |= F_ARM_5; break; |
2154 | case bfd_mach_arm_5T: * flagsp |= F_ARM_5; break; /* XXX - we do not have an F_ARM_5T */ | |
252b5132 RH |
2155 | } |
2156 | return true; | |
2157 | #endif | |
2158 | #ifdef PPCMAGIC | |
2159 | case bfd_arch_powerpc: | |
2160 | *magicp = PPCMAGIC; | |
2161 | return true; | |
2162 | break; | |
2163 | #endif | |
2164 | #ifdef I386MAGIC | |
2165 | case bfd_arch_i386: | |
2166 | *magicp = I386MAGIC; | |
2167 | #ifdef LYNXOS | |
2168 | /* Just overwrite the usual value if we're doing Lynx. */ | |
2169 | *magicp = LYNXCOFFMAGIC; | |
2170 | #endif | |
2171 | return true; | |
2172 | break; | |
2173 | #endif | |
2174 | #ifdef I860MAGIC | |
2175 | case bfd_arch_i860: | |
2176 | *magicp = I860MAGIC; | |
2177 | return true; | |
2178 | break; | |
2179 | #endif | |
2180 | #ifdef MC68MAGIC | |
2181 | case bfd_arch_m68k: | |
2182 | #ifdef APOLLOM68KMAGIC | |
2183 | *magicp = APOLLO_COFF_VERSION_NUMBER; | |
2184 | #else | |
2185 | /* NAMES_HAVE_UNDERSCORE may be defined by coff-u68k.c. */ | |
2186 | #ifdef NAMES_HAVE_UNDERSCORE | |
2187 | *magicp = MC68KBCSMAGIC; | |
2188 | #else | |
2189 | *magicp = MC68MAGIC; | |
2190 | #endif | |
2191 | #endif | |
2192 | #ifdef LYNXOS | |
2193 | /* Just overwrite the usual value if we're doing Lynx. */ | |
2194 | *magicp = LYNXCOFFMAGIC; | |
2195 | #endif | |
2196 | return true; | |
2197 | break; | |
2198 | #endif | |
2199 | ||
2200 | #ifdef MC88MAGIC | |
2201 | case bfd_arch_m88k: | |
2202 | *magicp = MC88OMAGIC; | |
2203 | return true; | |
2204 | break; | |
2205 | #endif | |
2206 | #ifdef H8300MAGIC | |
2207 | case bfd_arch_h8300: | |
2208 | switch (bfd_get_mach (abfd)) | |
2209 | { | |
2210 | case bfd_mach_h8300: | |
2211 | *magicp = H8300MAGIC; | |
2212 | return true; | |
2213 | case bfd_mach_h8300h: | |
2214 | *magicp = H8300HMAGIC; | |
2215 | return true; | |
2216 | case bfd_mach_h8300s: | |
2217 | *magicp = H8300SMAGIC; | |
2218 | return true; | |
2219 | } | |
2220 | break; | |
2221 | #endif | |
2222 | ||
2223 | #ifdef SH_ARCH_MAGIC_BIG | |
2224 | case bfd_arch_sh: | |
2225 | if (bfd_big_endian (abfd)) | |
2226 | *magicp = SH_ARCH_MAGIC_BIG; | |
2227 | else | |
2228 | *magicp = SH_ARCH_MAGIC_LITTLE; | |
2229 | return true; | |
2230 | break; | |
2231 | #endif | |
2232 | ||
2233 | #ifdef SPARCMAGIC | |
2234 | case bfd_arch_sparc: | |
2235 | *magicp = SPARCMAGIC; | |
2236 | #ifdef LYNXOS | |
2237 | /* Just overwrite the usual value if we're doing Lynx. */ | |
2238 | *magicp = LYNXCOFFMAGIC; | |
2239 | #endif | |
2240 | return true; | |
2241 | break; | |
2242 | #endif | |
2243 | ||
2244 | #ifdef H8500MAGIC | |
2245 | case bfd_arch_h8500: | |
2246 | *magicp = H8500MAGIC; | |
2247 | return true; | |
2248 | break; | |
2249 | #endif | |
2250 | #ifdef A29K_MAGIC_BIG | |
2251 | case bfd_arch_a29k: | |
2252 | if (bfd_big_endian (abfd)) | |
2253 | *magicp = A29K_MAGIC_BIG; | |
2254 | else | |
2255 | *magicp = A29K_MAGIC_LITTLE; | |
2256 | return true; | |
2257 | break; | |
2258 | #endif | |
2259 | ||
2260 | #ifdef WE32KMAGIC | |
2261 | case bfd_arch_we32k: | |
2262 | *magicp = WE32KMAGIC; | |
2263 | return true; | |
2264 | break; | |
2265 | #endif | |
2266 | ||
2267 | #ifdef U802TOCMAGIC | |
2268 | case bfd_arch_rs6000: | |
2269 | #ifndef PPCMAGIC | |
2270 | case bfd_arch_powerpc: | |
2271 | #endif | |
2272 | *magicp = U802TOCMAGIC; | |
2273 | return true; | |
2274 | break; | |
2275 | #endif | |
2276 | ||
2277 | #ifdef MCOREMAGIC | |
2278 | case bfd_arch_mcore: | |
2279 | * magicp = MCOREMAGIC; | |
2280 | return true; | |
2281 | #endif | |
2282 | ||
2283 | default: /* Unknown architecture */ | |
2284 | /* return false; -- fall through to "return false" below, to avoid | |
2285 | "statement never reached" errors on the one below. */ | |
2286 | break; | |
2287 | } | |
2288 | ||
2289 | return false; | |
2290 | } | |
2291 | ||
2292 | ||
2293 | static boolean | |
2294 | coff_set_arch_mach (abfd, arch, machine) | |
2295 | bfd * abfd; | |
2296 | enum bfd_architecture arch; | |
2297 | unsigned long machine; | |
2298 | { | |
2299 | unsigned dummy1; | |
2300 | unsigned short dummy2; | |
2301 | ||
2302 | if (! bfd_default_set_arch_mach (abfd, arch, machine)) | |
2303 | return false; | |
2304 | ||
2305 | if (arch != bfd_arch_unknown && | |
2306 | coff_set_flags (abfd, &dummy1, &dummy2) != true) | |
2307 | return false; /* We can't represent this type */ | |
2308 | ||
2309 | return true; /* We're easy ... */ | |
2310 | } | |
2311 | ||
2312 | ||
2313 | /* Calculate the file position for each section. */ | |
2314 | ||
2315 | #ifndef I960 | |
2316 | #define ALIGN_SECTIONS_IN_FILE | |
2317 | #endif | |
2318 | #ifdef TIC80COFF | |
2319 | #undef ALIGN_SECTIONS_IN_FILE | |
2320 | #endif | |
2321 | ||
2322 | static boolean | |
2323 | coff_compute_section_file_positions (abfd) | |
2324 | bfd * abfd; | |
2325 | { | |
2326 | asection *current; | |
2327 | asection *previous = (asection *) NULL; | |
2328 | file_ptr sofar = FILHSZ; | |
2329 | boolean align_adjust; | |
2330 | unsigned int count; | |
2331 | #ifdef ALIGN_SECTIONS_IN_FILE | |
2332 | file_ptr old_sofar; | |
2333 | #endif | |
2334 | ||
2335 | #ifdef RS6000COFF_C | |
2336 | /* On XCOFF, if we have symbols, set up the .debug section. */ | |
2337 | if (bfd_get_symcount (abfd) > 0) | |
2338 | { | |
2339 | bfd_size_type sz; | |
2340 | bfd_size_type i, symcount; | |
2341 | asymbol **symp; | |
2342 | ||
2343 | sz = 0; | |
2344 | symcount = bfd_get_symcount (abfd); | |
2345 | for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++) | |
2346 | { | |
2347 | coff_symbol_type *cf; | |
2348 | ||
2349 | cf = coff_symbol_from (abfd, *symp); | |
2350 | if (cf != NULL | |
2351 | && cf->native != NULL | |
2352 | && SYMNAME_IN_DEBUG (&cf->native->u.syment)) | |
2353 | { | |
2354 | size_t len; | |
2355 | ||
2356 | len = strlen (bfd_asymbol_name (*symp)); | |
2357 | if (len > SYMNMLEN) | |
2358 | sz += len + 3; | |
2359 | } | |
2360 | } | |
2361 | if (sz > 0) | |
2362 | { | |
2363 | asection *dsec; | |
2364 | ||
2365 | dsec = bfd_make_section_old_way (abfd, ".debug"); | |
2366 | if (dsec == NULL) | |
2367 | abort (); | |
2368 | dsec->_raw_size = sz; | |
2369 | dsec->flags |= SEC_HAS_CONTENTS; | |
2370 | } | |
2371 | } | |
2372 | #endif | |
2373 | ||
2374 | #ifdef COFF_IMAGE_WITH_PE | |
2375 | int page_size; | |
2376 | if (coff_data (abfd)->link_info) | |
2377 | { | |
2378 | page_size = pe_data (abfd)->pe_opthdr.FileAlignment; | |
2379 | } | |
2380 | else | |
2381 | page_size = PE_DEF_FILE_ALIGNMENT; | |
2382 | #else | |
2383 | #ifdef COFF_PAGE_SIZE | |
2384 | int page_size = COFF_PAGE_SIZE; | |
2385 | #endif | |
2386 | #endif | |
2387 | ||
2388 | if (bfd_get_start_address (abfd)) | |
2389 | { | |
2390 | /* A start address may have been added to the original file. In this | |
2391 | case it will need an optional header to record it. */ | |
2392 | abfd->flags |= EXEC_P; | |
2393 | } | |
2394 | ||
2395 | if (abfd->flags & EXEC_P) | |
2396 | sofar += AOUTSZ; | |
2397 | #ifdef RS6000COFF_C | |
2398 | else if (xcoff_data (abfd)->full_aouthdr) | |
2399 | sofar += AOUTSZ; | |
2400 | else | |
2401 | sofar += SMALL_AOUTSZ; | |
2402 | #endif | |
2403 | ||
2404 | sofar += abfd->section_count * SCNHSZ; | |
2405 | ||
2406 | #ifdef RS6000COFF_C | |
2407 | /* XCOFF handles overflows in the reloc and line number count fields | |
2408 | by allocating a new section header to hold the correct counts. */ | |
2409 | for (current = abfd->sections; current != NULL; current = current->next) | |
2410 | if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff) | |
2411 | sofar += SCNHSZ; | |
2412 | #endif | |
2413 | ||
2414 | align_adjust = false; | |
2415 | for (current = abfd->sections, count = 1; | |
2416 | current != (asection *) NULL; | |
2417 | current = current->next, ++count) | |
2418 | { | |
2419 | #ifdef COFF_IMAGE_WITH_PE | |
2420 | /* The NT loader does not want empty section headers, so we omit | |
2421 | them. We don't actually remove the section from the BFD, | |
2422 | although we probably should. This matches code in | |
2423 | coff_write_object_contents. */ | |
2424 | if (current->_raw_size == 0) | |
2425 | { | |
2426 | current->target_index = -1; | |
2427 | --count; | |
2428 | continue; | |
2429 | } | |
2430 | #endif | |
2431 | ||
2432 | current->target_index = count; | |
2433 | ||
2434 | /* Only deal with sections which have contents */ | |
2435 | if (!(current->flags & SEC_HAS_CONTENTS)) | |
2436 | continue; | |
2437 | ||
2438 | /* Align the sections in the file to the same boundary on | |
2439 | which they are aligned in virtual memory. I960 doesn't | |
2440 | do this (FIXME) so we can stay in sync with Intel. 960 | |
2441 | doesn't yet page from files... */ | |
2442 | #ifdef ALIGN_SECTIONS_IN_FILE | |
2443 | if ((abfd->flags & EXEC_P) != 0) | |
2444 | { | |
2445 | /* make sure this section is aligned on the right boundary - by | |
2446 | padding the previous section up if necessary */ | |
2447 | ||
2448 | old_sofar = sofar; | |
2449 | sofar = BFD_ALIGN (sofar, 1 << current->alignment_power); | |
2450 | if (previous != (asection *) NULL) | |
2451 | { | |
2452 | previous->_raw_size += sofar - old_sofar; | |
2453 | } | |
2454 | } | |
2455 | ||
2456 | #endif | |
2457 | ||
2458 | /* In demand paged files the low order bits of the file offset | |
2459 | must match the low order bits of the virtual address. */ | |
2460 | #ifdef COFF_PAGE_SIZE | |
2461 | if ((abfd->flags & D_PAGED) != 0 | |
2462 | && (current->flags & SEC_ALLOC) != 0) | |
2463 | sofar += (current->vma - sofar) % page_size; | |
2464 | #endif | |
2465 | current->filepos = sofar; | |
2466 | ||
2467 | #ifdef COFF_IMAGE_WITH_PE | |
2468 | /* With PE we have to pad each section to be a multiple of its | |
2469 | page size too, and remember both sizes. */ | |
2470 | ||
2471 | if (coff_section_data (abfd, current) == NULL) | |
2472 | { | |
2473 | current->used_by_bfd = | |
2474 | (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata)); | |
2475 | if (current->used_by_bfd == NULL) | |
2476 | return false; | |
2477 | } | |
2478 | if (pei_section_data (abfd, current) == NULL) | |
2479 | { | |
2480 | coff_section_data (abfd, current)->tdata = | |
2481 | (PTR) bfd_zalloc (abfd, sizeof (struct pei_section_tdata)); | |
2482 | if (coff_section_data (abfd, current)->tdata == NULL) | |
2483 | return false; | |
2484 | } | |
2485 | if (pei_section_data (abfd, current)->virt_size == 0) | |
2486 | pei_section_data (abfd, current)->virt_size = current->_raw_size; | |
2487 | ||
2488 | current->_raw_size = (current->_raw_size + page_size -1) & -page_size; | |
2489 | #endif | |
2490 | ||
2491 | sofar += current->_raw_size; | |
2492 | ||
2493 | #ifdef ALIGN_SECTIONS_IN_FILE | |
2494 | /* make sure that this section is of the right size too */ | |
2495 | if ((abfd->flags & EXEC_P) == 0) | |
2496 | { | |
2497 | bfd_size_type old_size; | |
2498 | ||
2499 | old_size = current->_raw_size; | |
2500 | current->_raw_size = BFD_ALIGN (current->_raw_size, | |
2501 | 1 << current->alignment_power); | |
2502 | align_adjust = current->_raw_size != old_size; | |
2503 | sofar += current->_raw_size - old_size; | |
2504 | } | |
2505 | else | |
2506 | { | |
2507 | old_sofar = sofar; | |
2508 | sofar = BFD_ALIGN (sofar, 1 << current->alignment_power); | |
2509 | align_adjust = sofar != old_sofar; | |
2510 | current->_raw_size += sofar - old_sofar; | |
2511 | } | |
2512 | #endif | |
2513 | ||
2514 | #ifdef COFF_IMAGE_WITH_PE | |
2515 | /* For PE we need to make sure we pad out to the aligned | |
2516 | _raw_size, in case the caller only writes out data to the | |
2517 | unaligned _raw_size. */ | |
2518 | if (pei_section_data (abfd, current)->virt_size < current->_raw_size) | |
2519 | align_adjust = true; | |
2520 | #endif | |
2521 | ||
2522 | #ifdef _LIB | |
2523 | /* Force .lib sections to start at zero. The vma is then | |
2524 | incremented in coff_set_section_contents. This is right for | |
2525 | SVR3.2. */ | |
2526 | if (strcmp (current->name, _LIB) == 0) | |
2527 | bfd_set_section_vma (abfd, current, 0); | |
2528 | #endif | |
2529 | ||
2530 | previous = current; | |
2531 | } | |
2532 | ||
2533 | /* It is now safe to write to the output file. If we needed an | |
2534 | alignment adjustment for the last section, then make sure that | |
2535 | there is a byte at offset sofar. If there are no symbols and no | |
2536 | relocs, then nothing follows the last section. If we don't force | |
2537 | the last byte out, then the file may appear to be truncated. */ | |
2538 | if (align_adjust) | |
2539 | { | |
2540 | bfd_byte b; | |
2541 | ||
2542 | b = 0; | |
2543 | if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0 | |
2544 | || bfd_write (&b, 1, 1, abfd) != 1) | |
2545 | return false; | |
2546 | } | |
2547 | ||
2548 | /* Make sure the relocations are aligned. We don't need to make | |
2549 | sure that this byte exists, because it will only matter if there | |
2550 | really are relocs. */ | |
2551 | sofar = BFD_ALIGN (sofar, 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER); | |
2552 | ||
2553 | obj_relocbase (abfd) = sofar; | |
2554 | abfd->output_has_begun = true; | |
2555 | ||
2556 | return true; | |
2557 | } | |
2558 | ||
2559 | #if 0 | |
2560 | ||
2561 | /* This can never work, because it is called too late--after the | |
2562 | section positions have been set. I can't figure out what it is | |
2563 | for, so I am going to disable it--Ian Taylor 20 March 1996. */ | |
2564 | ||
2565 | /* If .file, .text, .data, .bss symbols are missing, add them. */ | |
2566 | /* @@ Should we only be adding missing symbols, or overriding the aux | |
2567 | values for existing section symbols? */ | |
2568 | static boolean | |
2569 | coff_add_missing_symbols (abfd) | |
2570 | bfd *abfd; | |
2571 | { | |
2572 | unsigned int nsyms = bfd_get_symcount (abfd); | |
2573 | asymbol **sympp = abfd->outsymbols; | |
2574 | asymbol **sympp2; | |
2575 | unsigned int i; | |
2576 | int need_text = 1, need_data = 1, need_bss = 1, need_file = 1; | |
2577 | ||
2578 | for (i = 0; i < nsyms; i++) | |
2579 | { | |
2580 | coff_symbol_type *csym = coff_symbol_from (abfd, sympp[i]); | |
2581 | CONST char *name; | |
2582 | if (csym) | |
2583 | { | |
2584 | /* only do this if there is a coff representation of the input | |
2585 | symbol */ | |
2586 | if (csym->native && csym->native->u.syment.n_sclass == C_FILE) | |
2587 | { | |
2588 | need_file = 0; | |
2589 | continue; | |
2590 | } | |
2591 | name = csym->symbol.name; | |
2592 | if (!name) | |
2593 | continue; | |
2594 | if (!strcmp (name, _TEXT)) | |
2595 | need_text = 0; | |
2596 | #ifdef APOLLO_M68 | |
2597 | else if (!strcmp (name, ".wtext")) | |
2598 | need_text = 0; | |
2599 | #endif | |
2600 | else if (!strcmp (name, _DATA)) | |
2601 | need_data = 0; | |
2602 | else if (!strcmp (name, _BSS)) | |
2603 | need_bss = 0; | |
2604 | } | |
2605 | } | |
2606 | /* Now i == bfd_get_symcount (abfd). */ | |
2607 | /* @@ For now, don't deal with .file symbol. */ | |
2608 | need_file = 0; | |
2609 | ||
2610 | if (!need_text && !need_data && !need_bss && !need_file) | |
2611 | return true; | |
2612 | nsyms += need_text + need_data + need_bss + need_file; | |
2613 | sympp2 = (asymbol **) bfd_alloc (abfd, nsyms * sizeof (asymbol *)); | |
2614 | if (!sympp2) | |
2615 | return false; | |
2616 | memcpy (sympp2, sympp, i * sizeof (asymbol *)); | |
2617 | if (need_file) | |
2618 | { | |
2619 | /* @@ Generate fake .file symbol, in sympp2[i], and increment i. */ | |
2620 | abort (); | |
2621 | } | |
2622 | if (need_text) | |
2623 | sympp2[i++] = coff_section_symbol (abfd, _TEXT); | |
2624 | if (need_data) | |
2625 | sympp2[i++] = coff_section_symbol (abfd, _DATA); | |
2626 | if (need_bss) | |
2627 | sympp2[i++] = coff_section_symbol (abfd, _BSS); | |
2628 | BFD_ASSERT (i == nsyms); | |
2629 | bfd_set_symtab (abfd, sympp2, nsyms); | |
2630 | return true; | |
2631 | } | |
2632 | ||
2633 | #endif /* 0 */ | |
2634 | ||
2635 | /* SUPPRESS 558 */ | |
2636 | /* SUPPRESS 529 */ | |
2637 | static boolean | |
2638 | coff_write_object_contents (abfd) | |
2639 | bfd * abfd; | |
2640 | { | |
2641 | asection *current; | |
2642 | boolean hasrelocs = false; | |
2643 | boolean haslinno = false; | |
2644 | file_ptr scn_base; | |
2645 | file_ptr reloc_base; | |
2646 | file_ptr lineno_base; | |
2647 | file_ptr sym_base; | |
2648 | unsigned long reloc_size = 0; | |
2649 | unsigned long lnno_size = 0; | |
2650 | boolean long_section_names; | |
2651 | asection *text_sec = NULL; | |
2652 | asection *data_sec = NULL; | |
2653 | asection *bss_sec = NULL; | |
2654 | struct internal_filehdr internal_f; | |
2655 | struct internal_aouthdr internal_a; | |
2656 | #ifdef COFF_LONG_SECTION_NAMES | |
2657 | size_t string_size = STRING_SIZE_SIZE; | |
2658 | #endif | |
2659 | ||
2660 | bfd_set_error (bfd_error_system_call); | |
2661 | ||
2662 | /* Make a pass through the symbol table to count line number entries and | |
2663 | put them into the correct asections */ | |
2664 | ||
2665 | lnno_size = coff_count_linenumbers (abfd) * LINESZ; | |
2666 | ||
2667 | if (abfd->output_has_begun == false) | |
2668 | { | |
2669 | if (! coff_compute_section_file_positions (abfd)) | |
2670 | return false; | |
2671 | } | |
2672 | ||
2673 | reloc_base = obj_relocbase (abfd); | |
2674 | ||
2675 | /* Work out the size of the reloc and linno areas */ | |
2676 | ||
2677 | for (current = abfd->sections; current != NULL; current = | |
2678 | current->next) | |
2679 | reloc_size += current->reloc_count * RELSZ; | |
2680 | ||
2681 | lineno_base = reloc_base + reloc_size; | |
2682 | sym_base = lineno_base + lnno_size; | |
2683 | ||
2684 | /* Indicate in each section->line_filepos its actual file address */ | |
2685 | for (current = abfd->sections; current != NULL; current = | |
2686 | current->next) | |
2687 | { | |
2688 | if (current->lineno_count) | |
2689 | { | |
2690 | current->line_filepos = lineno_base; | |
2691 | current->moving_line_filepos = lineno_base; | |
2692 | lineno_base += current->lineno_count * LINESZ; | |
2693 | } | |
2694 | else | |
2695 | { | |
2696 | current->line_filepos = 0; | |
2697 | } | |
2698 | if (current->reloc_count) | |
2699 | { | |
2700 | current->rel_filepos = reloc_base; | |
2701 | reloc_base += current->reloc_count * RELSZ; | |
2702 | } | |
2703 | else | |
2704 | { | |
2705 | current->rel_filepos = 0; | |
2706 | } | |
2707 | } | |
2708 | ||
2709 | /* Write section headers to the file. */ | |
2710 | internal_f.f_nscns = 0; | |
2711 | ||
2712 | if ((abfd->flags & EXEC_P) != 0) | |
2713 | scn_base = FILHSZ + AOUTSZ; | |
2714 | else | |
2715 | { | |
2716 | scn_base = FILHSZ; | |
2717 | #ifdef RS6000COFF_C | |
2718 | if (xcoff_data (abfd)->full_aouthdr) | |
2719 | scn_base += AOUTSZ; | |
2720 | else | |
2721 | scn_base += SMALL_AOUTSZ; | |
2722 | #endif | |
2723 | } | |
2724 | ||
2725 | if (bfd_seek (abfd, scn_base, SEEK_SET) != 0) | |
2726 | return false; | |
2727 | ||
2728 | long_section_names = false; | |
2729 | for (current = abfd->sections; | |
2730 | current != NULL; | |
2731 | current = current->next) | |
2732 | { | |
2733 | struct internal_scnhdr section; | |
2734 | ||
2735 | #ifdef COFF_WITH_PE | |
2736 | /* If we've got a .reloc section, remember. */ | |
2737 | ||
2738 | #ifdef COFF_IMAGE_WITH_PE | |
2739 | if (strcmp (current->name, ".reloc") == 0) | |
2740 | { | |
2741 | pe_data (abfd)->has_reloc_section = 1; | |
2742 | } | |
2743 | #endif | |
2744 | ||
2745 | #endif | |
2746 | internal_f.f_nscns++; | |
2747 | ||
2748 | strncpy (section.s_name, current->name, SCNNMLEN); | |
2749 | ||
2750 | #ifdef COFF_LONG_SECTION_NAMES | |
2751 | /* Handle long section names as in PE. This must be compatible | |
00692651 | 2752 | with the code in coff_write_symbols and _bfd_coff_final_link. */ |
252b5132 RH |
2753 | { |
2754 | size_t len; | |
2755 | ||
2756 | len = strlen (current->name); | |
2757 | if (len > SCNNMLEN) | |
2758 | { | |
2759 | memset (section.s_name, 0, SCNNMLEN); | |
2760 | sprintf (section.s_name, "/%lu", (unsigned long) string_size); | |
2761 | string_size += len + 1; | |
2762 | long_section_names = true; | |
2763 | } | |
2764 | } | |
2765 | #endif | |
2766 | ||
2767 | #ifdef _LIB | |
2768 | /* Always set s_vaddr of .lib to 0. This is right for SVR3.2 | |
2769 | Ian Taylor <[email protected]>. */ | |
2770 | if (strcmp (current->name, _LIB) == 0) | |
2771 | section.s_vaddr = 0; | |
2772 | else | |
2773 | #endif | |
2774 | section.s_vaddr = current->vma; | |
2775 | section.s_paddr = current->lma; | |
2776 | section.s_size = current->_raw_size; | |
2777 | ||
2778 | #ifdef COFF_WITH_PE | |
2779 | section.s_paddr = 0; | |
2780 | #endif | |
2781 | #ifdef COFF_IMAGE_WITH_PE | |
2782 | /* Reminder: s_paddr holds the virtual size of the section. */ | |
2783 | if (coff_section_data (abfd, current) != NULL | |
2784 | && pei_section_data (abfd, current) != NULL) | |
2785 | section.s_paddr = pei_section_data (abfd, current)->virt_size; | |
2786 | else | |
2787 | section.s_paddr = 0; | |
2788 | #endif | |
2789 | ||
2790 | /* | |
2791 | If this section has no size or is unloadable then the scnptr | |
2792 | will be 0 too | |
2793 | */ | |
2794 | if (current->_raw_size == 0 || | |
2795 | (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0) | |
2796 | { | |
2797 | section.s_scnptr = 0; | |
2798 | } | |
2799 | else | |
2800 | { | |
2801 | section.s_scnptr = current->filepos; | |
2802 | } | |
2803 | section.s_relptr = current->rel_filepos; | |
2804 | section.s_lnnoptr = current->line_filepos; | |
2805 | section.s_nreloc = current->reloc_count; | |
2806 | section.s_nlnno = current->lineno_count; | |
2807 | if (current->reloc_count != 0) | |
2808 | hasrelocs = true; | |
2809 | if (current->lineno_count != 0) | |
2810 | haslinno = true; | |
2811 | ||
2812 | #ifdef RS6000COFF_C | |
2813 | /* Indicate the use of an XCOFF overflow section header. */ | |
2814 | if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff) | |
2815 | { | |
2816 | section.s_nreloc = 0xffff; | |
2817 | section.s_nlnno = 0xffff; | |
2818 | } | |
2819 | #endif | |
2820 | ||
2821 | section.s_flags = sec_to_styp_flags (current->name, current->flags); | |
2822 | ||
2823 | if (!strcmp (current->name, _TEXT)) | |
2824 | { | |
2825 | text_sec = current; | |
2826 | } | |
2827 | else if (!strcmp (current->name, _DATA)) | |
2828 | { | |
2829 | data_sec = current; | |
2830 | } | |
2831 | else if (!strcmp (current->name, _BSS)) | |
2832 | { | |
2833 | bss_sec = current; | |
2834 | } | |
2835 | ||
2836 | #ifdef I960 | |
2837 | section.s_align = (current->alignment_power | |
2838 | ? 1 << current->alignment_power | |
2839 | : 0); | |
2840 | #else | |
2841 | #ifdef TIC80COFF | |
2842 | section.s_flags |= (current->alignment_power & 0xF) << 8; | |
2843 | #endif | |
2844 | #endif | |
2845 | ||
2846 | #ifdef COFF_IMAGE_WITH_PE | |
00692651 ILT |
2847 | /* Suppress output of the sections if they are null. ld |
2848 | includes the bss and data sections even if there is no size | |
2849 | assigned to them. NT loader doesn't like it if these section | |
2850 | headers are included if the sections themselves are not | |
2851 | needed. See also coff_compute_section_file_positions. */ | |
252b5132 RH |
2852 | if (section.s_size == 0) |
2853 | internal_f.f_nscns--; | |
2854 | else | |
2855 | #endif | |
2856 | { | |
2857 | SCNHDR buff; | |
2858 | if (coff_swap_scnhdr_out (abfd, §ion, &buff) == 0 | |
2859 | || bfd_write ((PTR) (&buff), 1, SCNHSZ, abfd) != SCNHSZ) | |
2860 | return false; | |
2861 | } | |
2862 | ||
2863 | #ifdef COFF_WITH_PE | |
2864 | /* PE stores COMDAT section information in the symbol table. If | |
2865 | this section is supposed to have some COMDAT info, track down | |
2866 | the symbol in the symbol table and modify it. */ | |
2867 | if ((current->flags & SEC_LINK_ONCE) != 0) | |
2868 | { | |
2869 | unsigned int i, count; | |
2870 | asymbol **psym; | |
2871 | coff_symbol_type *csym = NULL; | |
2872 | asymbol **psymsec; | |
2873 | ||
2874 | psymsec = NULL; | |
2875 | count = bfd_get_symcount (abfd); | |
2876 | for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++) | |
2877 | { | |
2878 | if ((*psym)->section != current) | |
2879 | continue; | |
2880 | ||
2881 | /* Remember the location of the first symbol in this | |
2882 | section. */ | |
2883 | if (psymsec == NULL) | |
2884 | psymsec = psym; | |
2885 | ||
2886 | /* See if this is the section symbol. */ | |
2887 | if (strcmp ((*psym)->name, current->name) == 0) | |
2888 | { | |
2889 | csym = coff_symbol_from (abfd, *psym); | |
2890 | if (csym == NULL | |
2891 | || csym->native == NULL | |
2892 | || csym->native->u.syment.n_numaux < 1 | |
2893 | || csym->native->u.syment.n_sclass != C_STAT | |
2894 | || csym->native->u.syment.n_type != T_NULL) | |
2895 | continue; | |
2896 | ||
2897 | /* Here *PSYM is the section symbol for CURRENT. */ | |
2898 | ||
2899 | break; | |
2900 | } | |
2901 | } | |
2902 | ||
2903 | /* Did we find it? | |
2904 | Note that we might not if we're converting the file from | |
2905 | some other object file format. */ | |
2906 | if (i < count) | |
2907 | { | |
2908 | combined_entry_type *aux; | |
2909 | ||
2910 | /* We don't touch the x_checksum field. The | |
2911 | x_associated field is not currently supported. */ | |
2912 | ||
2913 | aux = csym->native + 1; | |
2914 | switch (current->flags & SEC_LINK_DUPLICATES) | |
2915 | { | |
2916 | case SEC_LINK_DUPLICATES_DISCARD: | |
2917 | aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY; | |
2918 | break; | |
2919 | ||
2920 | case SEC_LINK_DUPLICATES_ONE_ONLY: | |
2921 | aux->u.auxent.x_scn.x_comdat = | |
2922 | IMAGE_COMDAT_SELECT_NODUPLICATES; | |
2923 | break; | |
2924 | ||
2925 | case SEC_LINK_DUPLICATES_SAME_SIZE: | |
2926 | aux->u.auxent.x_scn.x_comdat = | |
2927 | IMAGE_COMDAT_SELECT_SAME_SIZE; | |
2928 | break; | |
2929 | ||
2930 | case SEC_LINK_DUPLICATES_SAME_CONTENTS: | |
2931 | aux->u.auxent.x_scn.x_comdat = | |
2932 | IMAGE_COMDAT_SELECT_EXACT_MATCH; | |
2933 | break; | |
2934 | } | |
2935 | ||
2936 | /* The COMDAT symbol must be the first symbol from this | |
2937 | section in the symbol table. In order to make this | |
2938 | work, we move the COMDAT symbol before the first | |
2939 | symbol we found in the search above. It's OK to | |
2940 | rearrange the symbol table at this point, because | |
2941 | coff_renumber_symbols is going to rearrange it | |
2942 | further and fix up all the aux entries. */ | |
2943 | if (psym != psymsec) | |
2944 | { | |
2945 | asymbol *hold; | |
2946 | asymbol **pcopy; | |
2947 | ||
2948 | hold = *psym; | |
2949 | for (pcopy = psym; pcopy > psymsec; pcopy--) | |
2950 | pcopy[0] = pcopy[-1]; | |
2951 | *psymsec = hold; | |
2952 | } | |
2953 | } | |
2954 | } | |
2955 | #endif /* COFF_WITH_PE */ | |
2956 | } | |
2957 | ||
2958 | #ifdef RS6000COFF_C | |
2959 | /* XCOFF handles overflows in the reloc and line number count fields | |
2960 | by creating a new section header to hold the correct values. */ | |
2961 | for (current = abfd->sections; current != NULL; current = current->next) | |
2962 | { | |
2963 | if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff) | |
2964 | { | |
2965 | struct internal_scnhdr scnhdr; | |
2966 | SCNHDR buff; | |
2967 | ||
2968 | internal_f.f_nscns++; | |
2969 | strncpy (&(scnhdr.s_name[0]), current->name, 8); | |
2970 | scnhdr.s_paddr = current->reloc_count; | |
2971 | scnhdr.s_vaddr = current->lineno_count; | |
2972 | scnhdr.s_size = 0; | |
2973 | scnhdr.s_scnptr = 0; | |
2974 | scnhdr.s_relptr = current->rel_filepos; | |
2975 | scnhdr.s_lnnoptr = current->line_filepos; | |
2976 | scnhdr.s_nreloc = current->target_index; | |
2977 | scnhdr.s_nlnno = current->target_index; | |
2978 | scnhdr.s_flags = STYP_OVRFLO; | |
2979 | if (coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0 | |
2980 | || bfd_write ((PTR) &buff, 1, SCNHSZ, abfd) != SCNHSZ) | |
2981 | return false; | |
2982 | } | |
2983 | } | |
2984 | #endif | |
2985 | ||
2986 | /* OK, now set up the filehdr... */ | |
2987 | ||
2988 | /* Don't include the internal abs section in the section count */ | |
2989 | ||
2990 | /* | |
2991 | We will NOT put a fucking timestamp in the header here. Every time you | |
2992 | put it back, I will come in and take it out again. I'm sorry. This | |
2993 | field does not belong here. We fill it with a 0 so it compares the | |
2994 | same but is not a reasonable time. -- [email protected] | |
2995 | */ | |
2996 | internal_f.f_timdat = 0; | |
2997 | ||
2998 | internal_f.f_flags = 0; | |
2999 | ||
3000 | if (abfd->flags & EXEC_P) | |
3001 | internal_f.f_opthdr = AOUTSZ; | |
3002 | else | |
3003 | { | |
3004 | internal_f.f_opthdr = 0; | |
3005 | #ifdef RS6000COFF_C | |
3006 | if (xcoff_data (abfd)->full_aouthdr) | |
3007 | internal_f.f_opthdr = AOUTSZ; | |
3008 | else | |
3009 | internal_f.f_opthdr = SMALL_AOUTSZ; | |
3010 | #endif | |
3011 | } | |
3012 | ||
3013 | if (!hasrelocs) | |
3014 | internal_f.f_flags |= F_RELFLG; | |
3015 | if (!haslinno) | |
3016 | internal_f.f_flags |= F_LNNO; | |
3017 | if (abfd->flags & EXEC_P) | |
3018 | internal_f.f_flags |= F_EXEC; | |
3019 | ||
3020 | /* FIXME: this is wrong for PPC_PE! */ | |
3021 | if (bfd_little_endian (abfd)) | |
3022 | internal_f.f_flags |= F_AR32WR; | |
3023 | else | |
3024 | internal_f.f_flags |= F_AR32W; | |
3025 | ||
3026 | #ifdef TIC80_TARGET_ID | |
3027 | internal_f.f_target_id = TIC80_TARGET_ID; | |
3028 | #endif | |
3029 | ||
3030 | /* | |
3031 | FIXME, should do something about the other byte orders and | |
3032 | architectures. | |
3033 | */ | |
3034 | ||
3035 | #ifdef RS6000COFF_C | |
3036 | if ((abfd->flags & DYNAMIC) != 0) | |
3037 | internal_f.f_flags |= F_SHROBJ; | |
3038 | if (bfd_get_section_by_name (abfd, _LOADER) != NULL) | |
3039 | internal_f.f_flags |= F_DYNLOAD; | |
3040 | #endif | |
3041 | ||
3042 | memset (&internal_a, 0, sizeof internal_a); | |
3043 | ||
3044 | /* Set up architecture-dependent stuff */ | |
3045 | ||
3046 | { | |
3047 | unsigned int magic = 0; | |
3048 | unsigned short flags = 0; | |
3049 | coff_set_flags (abfd, &magic, &flags); | |
3050 | internal_f.f_magic = magic; | |
3051 | internal_f.f_flags |= flags; | |
3052 | /* ...and the "opt"hdr... */ | |
3053 | ||
3054 | #ifdef A29K | |
3055 | #ifdef ULTRA3 /* NYU's machine */ | |
3056 | /* FIXME: This is a bogus check. I really want to see if there | |
3057 | * is a .shbss or a .shdata section, if so then set the magic | |
3058 | * number to indicate a shared data executable. | |
3059 | */ | |
3060 | if (internal_f.f_nscns >= 7) | |
3061 | internal_a.magic = SHMAGIC; /* Shared magic */ | |
3062 | else | |
3063 | #endif /* ULTRA3 */ | |
3064 | internal_a.magic = NMAGIC; /* Assume separate i/d */ | |
3065 | #define __A_MAGIC_SET__ | |
3066 | #endif /* A29K */ | |
3067 | #ifdef TIC80COFF | |
3068 | internal_a.magic = TIC80_ARCH_MAGIC; | |
3069 | #define __A_MAGIC_SET__ | |
3070 | #endif /* TIC80 */ | |
3071 | #ifdef I860 | |
3072 | /* FIXME: What are the a.out magic numbers for the i860? */ | |
3073 | internal_a.magic = 0; | |
3074 | #define __A_MAGIC_SET__ | |
3075 | #endif /* I860 */ | |
3076 | #ifdef I960 | |
3077 | internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC); | |
3078 | #define __A_MAGIC_SET__ | |
3079 | #endif /* I960 */ | |
3080 | #if M88 | |
3081 | #define __A_MAGIC_SET__ | |
3082 | internal_a.magic = PAGEMAGICBCS; | |
3083 | #endif /* M88 */ | |
3084 | ||
3085 | #if APOLLO_M68 | |
3086 | #define __A_MAGIC_SET__ | |
3087 | internal_a.magic = APOLLO_COFF_VERSION_NUMBER; | |
3088 | #endif | |
3089 | ||
3090 | #if defined(M68) || defined(WE32K) || defined(M68K) | |
3091 | #define __A_MAGIC_SET__ | |
3092 | #if defined(LYNXOS) | |
3093 | internal_a.magic = LYNXCOFFMAGIC; | |
3094 | #else | |
3095 | #if defined(TARG_AUX) | |
3096 | internal_a.magic = (abfd->flags & D_PAGED ? PAGEMAGICPEXECPAGED : | |
3097 | abfd->flags & WP_TEXT ? PAGEMAGICPEXECSWAPPED : | |
3098 | PAGEMAGICEXECSWAPPED); | |
3099 | #else | |
3100 | #if defined (PAGEMAGICPEXECPAGED) | |
3101 | internal_a.magic = PAGEMAGICPEXECPAGED; | |
3102 | #endif | |
3103 | #endif /* TARG_AUX */ | |
3104 | #endif /* LYNXOS */ | |
3105 | #endif /* M68 || WE32K || M68K */ | |
3106 | ||
3107 | #if defined(ARM) | |
3108 | #define __A_MAGIC_SET__ | |
3109 | internal_a.magic = ZMAGIC; | |
3110 | #endif | |
3111 | ||
3112 | #if defined(PPC_PE) | |
3113 | #define __A_MAGIC_SET__ | |
3114 | internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC; | |
3115 | #endif | |
3116 | ||
3117 | #if defined MCORE_PE | |
3118 | #define __A_MAGIC_SET__ | |
3119 | internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC; | |
3120 | #endif | |
3121 | ||
3122 | #if defined(I386) | |
3123 | #define __A_MAGIC_SET__ | |
3124 | #if defined(LYNXOS) | |
3125 | internal_a.magic = LYNXCOFFMAGIC; | |
3126 | #else /* LYNXOS */ | |
3127 | internal_a.magic = ZMAGIC; | |
3128 | #endif /* LYNXOS */ | |
3129 | #endif /* I386 */ | |
3130 | ||
3131 | #if defined(SPARC) | |
3132 | #define __A_MAGIC_SET__ | |
3133 | #if defined(LYNXOS) | |
3134 | internal_a.magic = LYNXCOFFMAGIC; | |
3135 | #endif /* LYNXOS */ | |
3136 | #endif /* SPARC */ | |
3137 | ||
3138 | #ifdef RS6000COFF_C | |
3139 | #define __A_MAGIC_SET__ | |
3140 | internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC : | |
3141 | (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC : | |
3142 | RS6K_AOUTHDR_OMAGIC; | |
3143 | #endif | |
3144 | ||
3145 | #ifndef __A_MAGIC_SET__ | |
3146 | #include "Your aouthdr magic number is not being set!" | |
3147 | #else | |
3148 | #undef __A_MAGIC_SET__ | |
3149 | #endif | |
3150 | } | |
3151 | ||
3152 | /* FIXME: Does anybody ever set this to another value? */ | |
3153 | internal_a.vstamp = 0; | |
3154 | ||
3155 | /* Now should write relocs, strings, syms */ | |
3156 | obj_sym_filepos (abfd) = sym_base; | |
3157 | ||
3158 | if (bfd_get_symcount (abfd) != 0) | |
3159 | { | |
3160 | int firstundef; | |
3161 | #if 0 | |
3162 | if (!coff_add_missing_symbols (abfd)) | |
3163 | return false; | |
3164 | #endif | |
3165 | if (!coff_renumber_symbols (abfd, &firstundef)) | |
3166 | return false; | |
3167 | coff_mangle_symbols (abfd); | |
3168 | if (! coff_write_symbols (abfd)) | |
3169 | return false; | |
3170 | if (! coff_write_linenumbers (abfd)) | |
3171 | return false; | |
3172 | if (! coff_write_relocs (abfd, firstundef)) | |
3173 | return false; | |
3174 | } | |
3175 | #ifdef COFF_LONG_SECTION_NAMES | |
3176 | else if (long_section_names) | |
3177 | { | |
3178 | /* If we have long section names we have to write out the string | |
3179 | table even if there are no symbols. */ | |
3180 | if (! coff_write_symbols (abfd)) | |
3181 | return false; | |
3182 | } | |
3183 | #endif | |
3184 | #ifdef COFF_IMAGE_WITH_PE | |
3185 | #ifdef PPC_PE | |
3186 | else if ((abfd->flags & EXEC_P) != 0) | |
3187 | { | |
3188 | bfd_byte b; | |
3189 | ||
3190 | /* PowerPC PE appears to require that all executable files be | |
3191 | rounded up to the page size. */ | |
3192 | b = 0; | |
3193 | if (bfd_seek (abfd, | |
3194 | BFD_ALIGN (sym_base, COFF_PAGE_SIZE) - 1, | |
3195 | SEEK_SET) != 0 | |
3196 | || bfd_write (&b, 1, 1, abfd) != 1) | |
3197 | return false; | |
3198 | } | |
3199 | #endif | |
3200 | #endif | |
3201 | ||
3202 | /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF | |
3203 | backend linker, and obj_raw_syment_count is not valid until after | |
3204 | coff_write_symbols is called. */ | |
3205 | if (obj_raw_syment_count (abfd) != 0) | |
3206 | { | |
3207 | internal_f.f_symptr = sym_base; | |
3208 | #ifdef RS6000COFF_C | |
3209 | /* AIX appears to require that F_RELFLG not be set if there are | |
3210 | local symbols but no relocations. */ | |
3211 | internal_f.f_flags &=~ F_RELFLG; | |
3212 | #endif | |
3213 | } | |
3214 | else | |
3215 | { | |
3216 | if (long_section_names) | |
3217 | internal_f.f_symptr = sym_base; | |
3218 | else | |
3219 | internal_f.f_symptr = 0; | |
3220 | internal_f.f_flags |= F_LSYMS; | |
3221 | } | |
3222 | ||
3223 | if (text_sec) | |
3224 | { | |
3225 | internal_a.tsize = bfd_get_section_size_before_reloc (text_sec); | |
3226 | internal_a.text_start = internal_a.tsize ? text_sec->vma : 0; | |
3227 | } | |
3228 | if (data_sec) | |
3229 | { | |
3230 | internal_a.dsize = bfd_get_section_size_before_reloc (data_sec); | |
3231 | internal_a.data_start = internal_a.dsize ? data_sec->vma : 0; | |
3232 | } | |
3233 | if (bss_sec) | |
3234 | { | |
3235 | internal_a.bsize = bfd_get_section_size_before_reloc (bss_sec); | |
3236 | if (internal_a.bsize && bss_sec->vma < internal_a.data_start) | |
3237 | internal_a.data_start = bss_sec->vma; | |
3238 | } | |
3239 | ||
3240 | internal_a.entry = bfd_get_start_address (abfd); | |
3241 | internal_f.f_nsyms = obj_raw_syment_count (abfd); | |
3242 | ||
3243 | #ifdef RS6000COFF_C | |
3244 | if (xcoff_data (abfd)->full_aouthdr) | |
3245 | { | |
3246 | bfd_vma toc; | |
3247 | asection *loader_sec; | |
3248 | ||
3249 | internal_a.vstamp = 1; | |
3250 | ||
3251 | internal_a.o_snentry = xcoff_data (abfd)->snentry; | |
3252 | if (internal_a.o_snentry == 0) | |
3253 | internal_a.entry = (bfd_vma) -1; | |
3254 | ||
3255 | if (text_sec != NULL) | |
3256 | { | |
3257 | internal_a.o_sntext = text_sec->target_index; | |
3258 | internal_a.o_algntext = bfd_get_section_alignment (abfd, text_sec); | |
3259 | } | |
3260 | else | |
3261 | { | |
3262 | internal_a.o_sntext = 0; | |
3263 | internal_a.o_algntext = 0; | |
3264 | } | |
3265 | if (data_sec != NULL) | |
3266 | { | |
3267 | internal_a.o_sndata = data_sec->target_index; | |
3268 | internal_a.o_algndata = bfd_get_section_alignment (abfd, data_sec); | |
3269 | } | |
3270 | else | |
3271 | { | |
3272 | internal_a.o_sndata = 0; | |
3273 | internal_a.o_algndata = 0; | |
3274 | } | |
3275 | loader_sec = bfd_get_section_by_name (abfd, ".loader"); | |
3276 | if (loader_sec != NULL) | |
3277 | internal_a.o_snloader = loader_sec->target_index; | |
3278 | else | |
3279 | internal_a.o_snloader = 0; | |
3280 | if (bss_sec != NULL) | |
3281 | internal_a.o_snbss = bss_sec->target_index; | |
3282 | else | |
3283 | internal_a.o_snbss = 0; | |
3284 | ||
3285 | toc = xcoff_data (abfd)->toc; | |
3286 | internal_a.o_toc = toc; | |
3287 | internal_a.o_sntoc = xcoff_data (abfd)->sntoc; | |
3288 | ||
3289 | internal_a.o_modtype = xcoff_data (abfd)->modtype; | |
3290 | if (xcoff_data (abfd)->cputype != -1) | |
3291 | internal_a.o_cputype = xcoff_data (abfd)->cputype; | |
3292 | else | |
3293 | { | |
3294 | switch (bfd_get_arch (abfd)) | |
3295 | { | |
3296 | case bfd_arch_rs6000: | |
3297 | internal_a.o_cputype = 4; | |
3298 | break; | |
3299 | case bfd_arch_powerpc: | |
3300 | if (bfd_get_mach (abfd) == 0) | |
3301 | internal_a.o_cputype = 3; | |
3302 | else | |
3303 | internal_a.o_cputype = 1; | |
3304 | break; | |
3305 | default: | |
3306 | abort (); | |
3307 | } | |
3308 | } | |
3309 | internal_a.o_maxstack = xcoff_data (abfd)->maxstack; | |
3310 | internal_a.o_maxdata = xcoff_data (abfd)->maxdata; | |
3311 | } | |
3312 | #endif | |
3313 | ||
3314 | /* now write them */ | |
3315 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) | |
3316 | return false; | |
3317 | { | |
3318 | char buff[FILHSZ]; | |
3319 | coff_swap_filehdr_out (abfd, (PTR) & internal_f, (PTR) buff); | |
3320 | if (bfd_write ((PTR) buff, 1, FILHSZ, abfd) != FILHSZ) | |
3321 | return false; | |
3322 | } | |
3323 | if (abfd->flags & EXEC_P) | |
3324 | { | |
3325 | /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR. | |
3326 | include/coff/pe.h sets AOUTSZ == sizeof(PEAOUTHDR)) */ | |
3327 | char buff[AOUTSZ]; | |
3328 | coff_swap_aouthdr_out (abfd, (PTR) & internal_a, (PTR) buff); | |
3329 | if (bfd_write ((PTR) buff, 1, AOUTSZ, abfd) != AOUTSZ) | |
3330 | return false; | |
3331 | } | |
3332 | #ifdef RS6000COFF_C | |
3333 | else | |
3334 | { | |
3335 | AOUTHDR buff; | |
3336 | size_t size; | |
3337 | ||
3338 | /* XCOFF seems to always write at least a small a.out header. */ | |
3339 | coff_swap_aouthdr_out (abfd, (PTR) &internal_a, (PTR) &buff); | |
3340 | if (xcoff_data (abfd)->full_aouthdr) | |
3341 | size = AOUTSZ; | |
3342 | else | |
3343 | size = SMALL_AOUTSZ; | |
3344 | if (bfd_write ((PTR) &buff, 1, size, abfd) != size) | |
3345 | return false; | |
3346 | } | |
3347 | #endif | |
3348 | ||
3349 | return true; | |
3350 | } | |
3351 | ||
3352 | static boolean | |
3353 | coff_set_section_contents (abfd, section, location, offset, count) | |
3354 | bfd * abfd; | |
3355 | sec_ptr section; | |
3356 | PTR location; | |
3357 | file_ptr offset; | |
3358 | bfd_size_type count; | |
3359 | { | |
3360 | if (abfd->output_has_begun == false) /* set by bfd.c handler */ | |
3361 | { | |
3362 | if (! coff_compute_section_file_positions (abfd)) | |
3363 | return false; | |
3364 | } | |
3365 | ||
3366 | #if defined(_LIB) && !defined(TARG_AUX) | |
3367 | ||
3368 | /* The physical address field of a .lib section is used to hold the | |
3369 | number of shared libraries in the section. This code counts the | |
3370 | number of sections being written, and increments the lma field | |
3371 | with the number. | |
3372 | ||
3373 | I have found no documentation on the contents of this section. | |
3374 | Experimentation indicates that the section contains zero or more | |
3375 | records, each of which has the following structure: | |
3376 | ||
3377 | - a (four byte) word holding the length of this record, in words, | |
3378 | - a word that always seems to be set to "2", | |
3379 | - the path to a shared library, null-terminated and then padded | |
3380 | to a whole word boundary. | |
3381 | ||
3382 | bfd_assert calls have been added to alert if an attempt is made | |
3383 | to write a section which doesn't follow these assumptions. The | |
3384 | code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe | |
3385 | <[email protected]> (Thanks!). | |
3386 | ||
3387 | Gvran Uddeborg <[email protected]> */ | |
3388 | ||
3389 | if (strcmp (section->name, _LIB) == 0) | |
3390 | { | |
3391 | bfd_byte *rec, *recend; | |
3392 | ||
3393 | rec = (bfd_byte *) location; | |
3394 | recend = rec + count; | |
3395 | while (rec < recend) | |
3396 | { | |
3397 | ++section->lma; | |
3398 | rec += bfd_get_32 (abfd, rec) * 4; | |
3399 | } | |
3400 | ||
3401 | BFD_ASSERT (rec == recend); | |
3402 | } | |
3403 | ||
3404 | #endif | |
3405 | ||
3406 | /* Don't write out bss sections - one way to do this is to | |
3407 | see if the filepos has not been set. */ | |
3408 | if (section->filepos == 0) | |
3409 | return true; | |
3410 | ||
3411 | if (bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET) != 0) | |
3412 | return false; | |
3413 | ||
3414 | if (count != 0) | |
3415 | { | |
3416 | return (bfd_write (location, 1, count, abfd) == count) ? true : false; | |
3417 | } | |
3418 | return true; | |
3419 | } | |
3420 | #if 0 | |
3421 | static boolean | |
3422 | coff_close_and_cleanup (abfd) | |
3423 | bfd *abfd; | |
3424 | { | |
3425 | if (!bfd_read_p (abfd)) | |
3426 | switch (abfd->format) | |
3427 | { | |
3428 | case bfd_archive: | |
3429 | if (!_bfd_write_archive_contents (abfd)) | |
3430 | return false; | |
3431 | break; | |
3432 | case bfd_object: | |
3433 | if (!coff_write_object_contents (abfd)) | |
3434 | return false; | |
3435 | break; | |
3436 | default: | |
3437 | bfd_set_error (bfd_error_invalid_operation); | |
3438 | return false; | |
3439 | } | |
3440 | ||
3441 | /* We depend on bfd_close to free all the memory on the objalloc. */ | |
3442 | return true; | |
3443 | } | |
3444 | ||
3445 | #endif | |
3446 | ||
3447 | static PTR | |
3448 | buy_and_read (abfd, where, seek_direction, size) | |
3449 | bfd *abfd; | |
3450 | file_ptr where; | |
3451 | int seek_direction; | |
3452 | size_t size; | |
3453 | { | |
3454 | PTR area = (PTR) bfd_alloc (abfd, size); | |
3455 | if (!area) | |
3456 | return (NULL); | |
3457 | if (bfd_seek (abfd, where, seek_direction) != 0 | |
3458 | || bfd_read (area, 1, size, abfd) != size) | |
3459 | return (NULL); | |
3460 | return (area); | |
3461 | } /* buy_and_read() */ | |
3462 | ||
3463 | /* | |
3464 | SUBSUBSECTION | |
3465 | Reading linenumbers | |
3466 | ||
3467 | Creating the linenumber table is done by reading in the entire | |
3468 | coff linenumber table, and creating another table for internal use. | |
3469 | ||
3470 | A coff linenumber table is structured so that each function | |
3471 | is marked as having a line number of 0. Each line within the | |
3472 | function is an offset from the first line in the function. The | |
3473 | base of the line number information for the table is stored in | |
3474 | the symbol associated with the function. | |
3475 | ||
00692651 ILT |
3476 | Note: The PE format uses line number 0 for a flag indicating a |
3477 | new source file. | |
3478 | ||
252b5132 RH |
3479 | The information is copied from the external to the internal |
3480 | table, and each symbol which marks a function is marked by | |
3481 | pointing its... | |
3482 | ||
3483 | How does this work ? | |
3484 | ||
3485 | */ | |
3486 | ||
3487 | static boolean | |
3488 | coff_slurp_line_table (abfd, asect) | |
3489 | bfd *abfd; | |
3490 | asection *asect; | |
3491 | { | |
3492 | LINENO *native_lineno; | |
3493 | alent *lineno_cache; | |
3494 | ||
3495 | BFD_ASSERT (asect->lineno == (alent *) NULL); | |
3496 | ||
3497 | native_lineno = (LINENO *) buy_and_read (abfd, | |
3498 | asect->line_filepos, | |
3499 | SEEK_SET, | |
3500 | (size_t) (LINESZ * | |
3501 | asect->lineno_count)); | |
3502 | lineno_cache = | |
3503 | (alent *) bfd_alloc (abfd, (size_t) ((asect->lineno_count + 1) * sizeof (alent))); | |
3504 | if (lineno_cache == NULL) | |
3505 | return false; | |
3506 | else | |
3507 | { | |
3508 | unsigned int counter = 0; | |
3509 | alent *cache_ptr = lineno_cache; | |
3510 | LINENO *src = native_lineno; | |
3511 | ||
3512 | while (counter < asect->lineno_count) | |
3513 | { | |
3514 | struct internal_lineno dst; | |
3515 | coff_swap_lineno_in (abfd, src, &dst); | |
3516 | cache_ptr->line_number = dst.l_lnno; | |
3517 | ||
3518 | if (cache_ptr->line_number == 0) | |
3519 | { | |
3520 | boolean warned; | |
3521 | long symndx; | |
3522 | coff_symbol_type *sym; | |
3523 | ||
3524 | warned = false; | |
3525 | symndx = dst.l_addr.l_symndx; | |
3526 | if (symndx < 0 | |
3527 | || (unsigned long) symndx >= obj_raw_syment_count (abfd)) | |
3528 | { | |
3529 | (*_bfd_error_handler) | |
3530 | (_("%s: warning: illegal symbol index %ld in line numbers"), | |
3531 | bfd_get_filename (abfd), dst.l_addr.l_symndx); | |
3532 | symndx = 0; | |
3533 | warned = true; | |
3534 | } | |
3535 | /* FIXME: We should not be casting between ints and | |
3536 | pointers like this. */ | |
3537 | sym = ((coff_symbol_type *) | |
3538 | ((symndx + obj_raw_syments (abfd)) | |
3539 | ->u.syment._n._n_n._n_zeroes)); | |
3540 | cache_ptr->u.sym = (asymbol *) sym; | |
3541 | if (sym->lineno != NULL && ! warned) | |
3542 | { | |
3543 | (*_bfd_error_handler) | |
3544 | (_("%s: warning: duplicate line number information for `%s'"), | |
3545 | bfd_get_filename (abfd), | |
3546 | bfd_asymbol_name (&sym->symbol)); | |
3547 | } | |
3548 | sym->lineno = cache_ptr; | |
3549 | } | |
3550 | else | |
3551 | { | |
3552 | cache_ptr->u.offset = dst.l_addr.l_paddr | |
3553 | - bfd_section_vma (abfd, asect); | |
3554 | } /* If no linenumber expect a symbol index */ | |
3555 | ||
3556 | cache_ptr++; | |
3557 | src++; | |
3558 | counter++; | |
3559 | } | |
3560 | cache_ptr->line_number = 0; | |
3561 | ||
3562 | } | |
3563 | asect->lineno = lineno_cache; | |
3564 | /* FIXME, free native_lineno here, or use alloca or something. */ | |
3565 | return true; | |
3566 | } | |
3567 | ||
00692651 ILT |
3568 | /* Slurp in the symbol table, converting it to generic form. Note |
3569 | that if coff_relocate_section is defined, the linker will read | |
3570 | symbols via coff_link_add_symbols, rather than via this routine. */ | |
3571 | ||
252b5132 RH |
3572 | static boolean |
3573 | coff_slurp_symbol_table (abfd) | |
3574 | bfd * abfd; | |
3575 | { | |
3576 | combined_entry_type *native_symbols; | |
3577 | coff_symbol_type *cached_area; | |
3578 | unsigned int *table_ptr; | |
3579 | ||
3580 | unsigned int number_of_symbols = 0; | |
3581 | ||
3582 | if (obj_symbols (abfd)) | |
3583 | return true; | |
3584 | ||
3585 | /* Read in the symbol table */ | |
3586 | if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL) | |
3587 | { | |
3588 | return (false); | |
3589 | } /* on error */ | |
3590 | ||
3591 | /* Allocate enough room for all the symbols in cached form */ | |
3592 | cached_area = ((coff_symbol_type *) | |
3593 | bfd_alloc (abfd, | |
3594 | (obj_raw_syment_count (abfd) | |
3595 | * sizeof (coff_symbol_type)))); | |
3596 | ||
3597 | if (cached_area == NULL) | |
3598 | return false; | |
3599 | table_ptr = ((unsigned int *) | |
3600 | bfd_alloc (abfd, | |
3601 | (obj_raw_syment_count (abfd) | |
3602 | * sizeof (unsigned int)))); | |
3603 | ||
3604 | if (table_ptr == NULL) | |
3605 | return false; | |
3606 | else | |
3607 | { | |
3608 | coff_symbol_type *dst = cached_area; | |
3609 | unsigned int last_native_index = obj_raw_syment_count (abfd); | |
3610 | unsigned int this_index = 0; | |
3611 | while (this_index < last_native_index) | |
3612 | { | |
3613 | combined_entry_type *src = native_symbols + this_index; | |
3614 | table_ptr[this_index] = number_of_symbols; | |
3615 | dst->symbol.the_bfd = abfd; | |
3616 | ||
3617 | dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset); | |
3618 | /* We use the native name field to point to the cached field. */ | |
3619 | src->u.syment._n._n_n._n_zeroes = (long) dst; | |
3620 | dst->symbol.section = coff_section_from_bfd_index (abfd, | |
3621 | src->u.syment.n_scnum); | |
3622 | dst->symbol.flags = 0; | |
3623 | dst->done_lineno = false; | |
3624 | ||
3625 | switch (src->u.syment.n_sclass) | |
3626 | { | |
3627 | #ifdef I960 | |
3628 | case C_LEAFEXT: | |
3629 | #if 0 | |
3630 | dst->symbol.value = src->u.syment.n_value - dst->symbol.section->vma; | |
3631 | dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL; | |
3632 | dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION; | |
3633 | #endif | |
3634 | /* Fall through to next case */ | |
3635 | ||
3636 | #endif | |
3637 | ||
3638 | case C_EXT: | |
3639 | case C_WEAKEXT: | |
3640 | #if defined ARM | |
3641 | case C_THUMBEXT: | |
3642 | case C_THUMBEXTFUNC: | |
3643 | #endif | |
3644 | #ifdef RS6000COFF_C | |
3645 | case C_HIDEXT: | |
3646 | #endif | |
3647 | #ifdef C_SYSTEM | |
3648 | case C_SYSTEM: /* System Wide variable */ | |
3649 | #endif | |
3650 | #ifdef COFF_WITH_PE | |
5d54c628 | 3651 | /* In PE, 0x68 (104) denotes a section symbol */ |
252b5132 | 3652 | case C_SECTION: |
5d54c628 | 3653 | /* In PE, 0x69 (105) denotes a weak external symbol. */ |
252b5132 RH |
3654 | case C_NT_WEAK: |
3655 | #endif | |
5d54c628 | 3656 | switch (coff_classify_symbol (abfd, &src->u.syment)) |
252b5132 | 3657 | { |
5d54c628 | 3658 | case COFF_SYMBOL_GLOBAL: |
252b5132 | 3659 | dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL; |
252b5132 RH |
3660 | #if defined COFF_WITH_PE |
3661 | /* PE sets the symbol to a value relative to the | |
3662 | start of the section. */ | |
3663 | dst->symbol.value = src->u.syment.n_value; | |
3664 | #else | |
3665 | dst->symbol.value = (src->u.syment.n_value | |
3666 | - dst->symbol.section->vma); | |
3667 | #endif | |
252b5132 RH |
3668 | if (ISFCN ((src->u.syment.n_type))) |
3669 | { | |
3670 | /* A function ext does not go at the end of a | |
3671 | file. */ | |
3672 | dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION; | |
3673 | } | |
5d54c628 ILT |
3674 | break; |
3675 | ||
3676 | case COFF_SYMBOL_COMMON: | |
3677 | dst->symbol.section = bfd_com_section_ptr; | |
3678 | dst->symbol.value = src->u.syment.n_value; | |
3679 | break; | |
3680 | ||
3681 | case COFF_SYMBOL_UNDEFINED: | |
3682 | dst->symbol.section = bfd_und_section_ptr; | |
3683 | dst->symbol.value = 0; | |
3684 | break; | |
3685 | ||
3686 | case COFF_SYMBOL_PE_SECTION: | |
3687 | dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM; | |
3688 | dst->symbol.value = 0; | |
3689 | break; | |
3690 | ||
3691 | case COFF_SYMBOL_LOCAL: | |
3692 | dst->symbol.flags = BSF_LOCAL; | |
3693 | #if defined COFF_WITH_PE | |
3694 | /* PE sets the symbol to a value relative to the | |
3695 | start of the section. */ | |
3696 | dst->symbol.value = src->u.syment.n_value; | |
3697 | #else | |
3698 | dst->symbol.value = (src->u.syment.n_value | |
3699 | - dst->symbol.section->vma); | |
3700 | #endif | |
3701 | if (ISFCN ((src->u.syment.n_type))) | |
3702 | dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION; | |
3703 | break; | |
252b5132 RH |
3704 | } |
3705 | ||
3706 | #ifdef RS6000COFF_C | |
252b5132 RH |
3707 | /* A symbol with a csect entry should not go at the end. */ |
3708 | if (src->u.syment.n_numaux > 0) | |
3709 | dst->symbol.flags |= BSF_NOT_AT_END; | |
3710 | #endif | |
3711 | ||
3712 | #ifdef COFF_WITH_PE | |
3713 | if (src->u.syment.n_sclass == C_NT_WEAK) | |
3714 | dst->symbol.flags = BSF_WEAK; | |
ec0ef80e DD |
3715 | if (src->u.syment.n_sclass == C_SECTION |
3716 | && src->u.syment.n_scnum > 0) | |
3717 | { | |
3718 | dst->symbol.flags = BSF_LOCAL; | |
3719 | } | |
252b5132 RH |
3720 | #endif |
3721 | ||
3722 | if (src->u.syment.n_sclass == C_WEAKEXT) | |
3723 | dst->symbol.flags = BSF_WEAK; | |
3724 | ||
3725 | break; | |
3726 | ||
3727 | case C_STAT: /* static */ | |
3728 | #ifdef I960 | |
3729 | case C_LEAFSTAT: /* static leaf procedure */ | |
3730 | #endif | |
3731 | #if defined ARM | |
3732 | case C_THUMBSTAT: /* Thumb static */ | |
3733 | case C_THUMBLABEL: /* Thumb label */ | |
3734 | case C_THUMBSTATFUNC:/* Thumb static function */ | |
3735 | #endif | |
3736 | case C_LABEL: /* label */ | |
00692651 | 3737 | if (src->u.syment.n_scnum == N_DEBUG) |
252b5132 RH |
3738 | dst->symbol.flags = BSF_DEBUGGING; |
3739 | else | |
3740 | dst->symbol.flags = BSF_LOCAL; | |
3741 | ||
3742 | /* Base the value as an index from the base of the | |
3743 | section, if there is one. */ | |
3744 | if (dst->symbol.section) | |
3745 | { | |
3746 | #if defined COFF_WITH_PE | |
3747 | /* PE sets the symbol to a value relative to the | |
3748 | start of the section. */ | |
3749 | dst->symbol.value = src->u.syment.n_value; | |
3750 | #else | |
3751 | dst->symbol.value = (src->u.syment.n_value | |
3752 | - dst->symbol.section->vma); | |
3753 | #endif | |
3754 | } | |
3755 | else | |
3756 | dst->symbol.value = src->u.syment.n_value; | |
3757 | break; | |
3758 | ||
3759 | case C_MOS: /* member of structure */ | |
3760 | case C_EOS: /* end of structure */ | |
3761 | #ifdef NOTDEF /* C_AUTOARG has the same value */ | |
3762 | #ifdef C_GLBLREG | |
3763 | case C_GLBLREG: /* A29k-specific storage class */ | |
3764 | #endif | |
3765 | #endif | |
3766 | case C_REGPARM: /* register parameter */ | |
3767 | case C_REG: /* register variable */ | |
3768 | #ifndef TIC80COFF | |
3769 | #ifdef C_AUTOARG | |
3770 | case C_AUTOARG: /* 960-specific storage class */ | |
3771 | #endif | |
3772 | #endif | |
3773 | case C_TPDEF: /* type definition */ | |
3774 | case C_ARG: | |
3775 | case C_AUTO: /* automatic variable */ | |
3776 | case C_FIELD: /* bit field */ | |
3777 | case C_ENTAG: /* enumeration tag */ | |
3778 | case C_MOE: /* member of enumeration */ | |
3779 | case C_MOU: /* member of union */ | |
3780 | case C_UNTAG: /* union tag */ | |
3781 | dst->symbol.flags = BSF_DEBUGGING; | |
3782 | dst->symbol.value = (src->u.syment.n_value); | |
3783 | break; | |
3784 | ||
3785 | case C_FILE: /* file name */ | |
3786 | case C_STRTAG: /* structure tag */ | |
3787 | #ifdef RS6000COFF_C | |
3788 | case C_GSYM: | |
3789 | case C_LSYM: | |
3790 | case C_PSYM: | |
3791 | case C_RSYM: | |
3792 | case C_RPSYM: | |
3793 | case C_STSYM: | |
3794 | case C_BCOMM: | |
3795 | case C_ECOMM: | |
3796 | case C_DECL: | |
3797 | case C_ENTRY: | |
3798 | case C_FUN: | |
3799 | case C_ESTAT: | |
3800 | #endif | |
3801 | dst->symbol.flags = BSF_DEBUGGING; | |
3802 | dst->symbol.value = (src->u.syment.n_value); | |
3803 | break; | |
3804 | ||
3805 | #ifdef RS6000COFF_C | |
3806 | case C_BINCL: /* beginning of include file */ | |
3807 | case C_EINCL: /* ending of include file */ | |
3808 | /* The value is actually a pointer into the line numbers | |
3809 | of the file. We locate the line number entry, and | |
3810 | set the section to the section which contains it, and | |
3811 | the value to the index in that section. */ | |
3812 | { | |
3813 | asection *sec; | |
3814 | ||
3815 | dst->symbol.flags = BSF_DEBUGGING; | |
3816 | for (sec = abfd->sections; sec != NULL; sec = sec->next) | |
3817 | if (sec->line_filepos <= (file_ptr) src->u.syment.n_value | |
3818 | && ((file_ptr) (sec->line_filepos | |
3819 | + sec->lineno_count * LINESZ) | |
3820 | > (file_ptr) src->u.syment.n_value)) | |
3821 | break; | |
3822 | if (sec == NULL) | |
3823 | dst->symbol.value = 0; | |
3824 | else | |
3825 | { | |
3826 | dst->symbol.section = sec; | |
3827 | dst->symbol.value = ((src->u.syment.n_value | |
3828 | - sec->line_filepos) | |
3829 | / LINESZ); | |
3830 | src->fix_line = 1; | |
3831 | } | |
3832 | } | |
3833 | break; | |
3834 | ||
3835 | case C_BSTAT: | |
3836 | dst->symbol.flags = BSF_DEBUGGING; | |
3837 | ||
3838 | /* The value is actually a symbol index. Save a pointer | |
3839 | to the symbol instead of the index. FIXME: This | |
3840 | should use a union. */ | |
3841 | src->u.syment.n_value = | |
3842 | (long) (native_symbols + src->u.syment.n_value); | |
3843 | dst->symbol.value = src->u.syment.n_value; | |
3844 | src->fix_value = 1; | |
3845 | break; | |
3846 | #endif | |
3847 | ||
3848 | case C_BLOCK: /* ".bb" or ".eb" */ | |
3849 | case C_FCN: /* ".bf" or ".ef" */ | |
3850 | case C_EFCN: /* physical end of function */ | |
3851 | dst->symbol.flags = BSF_LOCAL; | |
3852 | #if defined COFF_WITH_PE | |
3853 | /* PE sets the symbol to a value relative to the start | |
3854 | of the section. */ | |
3855 | dst->symbol.value = src->u.syment.n_value; | |
3856 | #else | |
3857 | /* Base the value as an index from the base of the | |
3858 | section. */ | |
3859 | dst->symbol.value = (src->u.syment.n_value | |
3860 | - dst->symbol.section->vma); | |
3861 | #endif | |
3862 | break; | |
3863 | ||
3864 | case C_NULL: | |
00692651 ILT |
3865 | /* PE DLLs sometimes have zeroed out symbols for some |
3866 | reason. Just ignore them without a warning. */ | |
3867 | if (src->u.syment.n_type == 0 | |
3868 | && src->u.syment.n_value == 0 | |
3869 | && src->u.syment.n_scnum == 0) | |
3870 | break; | |
3871 | /* Fall through. */ | |
252b5132 RH |
3872 | case C_EXTDEF: /* external definition */ |
3873 | case C_ULABEL: /* undefined label */ | |
3874 | case C_USTATIC: /* undefined static */ | |
3875 | #ifndef COFF_WITH_PE | |
3876 | /* C_LINE in regular coff is 0x68. NT has taken over this storage | |
3877 | class to represent a section symbol */ | |
3878 | case C_LINE: /* line # reformatted as symbol table entry */ | |
3879 | /* NT uses 0x67 for a weak symbol, not C_ALIAS. */ | |
3880 | case C_ALIAS: /* duplicate tag */ | |
3881 | #endif | |
3882 | /* New storage classes for TIc80 */ | |
3883 | #ifdef TIC80COFF | |
3884 | case C_UEXT: /* Tentative external definition */ | |
3885 | #endif | |
3886 | case C_STATLAB: /* Static load time label */ | |
3887 | case C_EXTLAB: /* External load time label */ | |
3888 | case C_HIDDEN: /* ext symbol in dmert public lib */ | |
3889 | default: | |
3890 | (*_bfd_error_handler) | |
3891 | (_("%s: Unrecognized storage class %d for %s symbol `%s'"), | |
3892 | bfd_get_filename (abfd), src->u.syment.n_sclass, | |
3893 | dst->symbol.section->name, dst->symbol.name); | |
3894 | dst->symbol.flags = BSF_DEBUGGING; | |
3895 | dst->symbol.value = (src->u.syment.n_value); | |
3896 | break; | |
3897 | } | |
3898 | ||
3899 | /* BFD_ASSERT(dst->symbol.flags != 0);*/ | |
3900 | ||
3901 | dst->native = src; | |
3902 | ||
3903 | dst->symbol.udata.i = 0; | |
3904 | dst->lineno = (alent *) NULL; | |
3905 | this_index += (src->u.syment.n_numaux) + 1; | |
3906 | dst++; | |
3907 | number_of_symbols++; | |
3908 | } /* walk the native symtab */ | |
3909 | } /* bfdize the native symtab */ | |
3910 | ||
3911 | obj_symbols (abfd) = cached_area; | |
3912 | obj_raw_syments (abfd) = native_symbols; | |
3913 | ||
3914 | bfd_get_symcount (abfd) = number_of_symbols; | |
3915 | obj_convert (abfd) = table_ptr; | |
3916 | /* Slurp the line tables for each section too */ | |
3917 | { | |
3918 | asection *p; | |
3919 | p = abfd->sections; | |
3920 | while (p) | |
3921 | { | |
3922 | coff_slurp_line_table (abfd, p); | |
3923 | p = p->next; | |
3924 | } | |
3925 | } | |
3926 | return true; | |
3927 | } /* coff_slurp_symbol_table() */ | |
3928 | ||
5d54c628 ILT |
3929 | /* Classify a COFF symbol. A couple of targets have globally visible |
3930 | symbols which are not class C_EXT, and this handles those. It also | |
3931 | recognizes some special PE cases. */ | |
252b5132 | 3932 | |
5d54c628 ILT |
3933 | static enum coff_symbol_classification |
3934 | coff_classify_symbol (abfd, syment) | |
3935 | bfd *abfd; | |
3936 | struct internal_syment *syment; | |
3937 | { | |
3938 | /* FIXME: This partially duplicates the switch in | |
3939 | coff_slurp_symbol_table. */ | |
3940 | switch (syment->n_sclass) | |
3941 | { | |
3942 | case C_EXT: | |
3943 | case C_WEAKEXT: | |
252b5132 | 3944 | #ifdef I960 |
5d54c628 | 3945 | case C_LEAFEXT: |
252b5132 | 3946 | #endif |
5d54c628 ILT |
3947 | #ifdef ARM |
3948 | case C_THUMBEXT: | |
3949 | case C_THUMBEXTFUNC: | |
252b5132 | 3950 | #endif |
5d54c628 ILT |
3951 | #ifdef C_SYSTEM |
3952 | case C_SYSTEM: | |
252b5132 | 3953 | #endif |
5d54c628 ILT |
3954 | #ifdef COFF_WITH_PE |
3955 | case C_NT_WEAK: | |
3956 | #endif | |
3957 | if (syment->n_scnum == 0) | |
3958 | { | |
3959 | if (syment->n_value == 0) | |
3960 | return COFF_SYMBOL_UNDEFINED; | |
3961 | else | |
3962 | return COFF_SYMBOL_COMMON; | |
3963 | } | |
3964 | return COFF_SYMBOL_GLOBAL; | |
3965 | ||
3966 | default: | |
3967 | break; | |
3968 | } | |
252b5132 | 3969 | |
5d54c628 ILT |
3970 | #ifdef COFF_WITH_PE |
3971 | if (syment->n_sclass == C_STAT) | |
3972 | { | |
3973 | if (syment->n_scnum == 0) | |
3974 | { | |
3975 | /* The Microsoft compiler sometimes generates these if a | |
3976 | small static function is inlined every time it is used. | |
3977 | The function is discarded, but the symbol table entry | |
3978 | remains. */ | |
3979 | return COFF_SYMBOL_LOCAL; | |
3980 | } | |
252b5132 | 3981 | |
bd826630 ILT |
3982 | #if 0 |
3983 | /* This is correct for Microsoft generated objects, but it | |
3984 | breaks gas generated objects. */ | |
3985 | ||
5d54c628 ILT |
3986 | if (syment->n_value == 0) |
3987 | { | |
3988 | asection *sec; | |
3989 | char buf[SYMNMLEN + 1]; | |
3990 | ||
3991 | sec = coff_section_from_bfd_index (abfd, syment->n_scnum); | |
3992 | if (sec != NULL | |
3993 | && (strcmp (bfd_get_section_name (abfd, sec), | |
3994 | _bfd_coff_internal_syment_name (abfd, syment, buf)) | |
3995 | == 0)) | |
3996 | return COFF_SYMBOL_PE_SECTION; | |
3997 | } | |
bd826630 | 3998 | #endif |
252b5132 | 3999 | |
5d54c628 ILT |
4000 | return COFF_SYMBOL_LOCAL; |
4001 | } | |
252b5132 | 4002 | |
5d54c628 ILT |
4003 | if (syment->n_sclass == C_SECTION) |
4004 | { | |
4005 | /* In some cases in a DLL generated by the Microsoft linker, the | |
4006 | n_value field will contain garbage. FIXME: This should | |
4007 | probably be handled by the swapping function instead. */ | |
4008 | syment->n_value = 0; | |
4009 | if (syment->n_scnum == 0) | |
4010 | return COFF_SYMBOL_UNDEFINED; | |
4011 | return COFF_SYMBOL_PE_SECTION; | |
4012 | } | |
4013 | #endif /* COFF_WITH_PE */ | |
252b5132 | 4014 | |
5d54c628 | 4015 | /* If it is not a global symbol, we presume it is a local symbol. */ |
252b5132 | 4016 | |
5d54c628 ILT |
4017 | if (syment->n_scnum == 0) |
4018 | { | |
4019 | char buf[SYMNMLEN + 1]; | |
252b5132 | 4020 | |
5d54c628 ILT |
4021 | (*_bfd_error_handler) |
4022 | (_("warning: %s: local symbol `%s' has no section"), | |
4023 | bfd_get_filename (abfd), | |
4024 | _bfd_coff_internal_syment_name (abfd, syment, buf)); | |
4025 | } | |
252b5132 | 4026 | |
5d54c628 ILT |
4027 | return COFF_SYMBOL_LOCAL; |
4028 | } | |
252b5132 RH |
4029 | |
4030 | /* | |
4031 | SUBSUBSECTION | |
4032 | Reading relocations | |
4033 | ||
4034 | Coff relocations are easily transformed into the internal BFD form | |
4035 | (@code{arelent}). | |
4036 | ||
4037 | Reading a coff relocation table is done in the following stages: | |
4038 | ||
4039 | o Read the entire coff relocation table into memory. | |
4040 | ||
4041 | o Process each relocation in turn; first swap it from the | |
4042 | external to the internal form. | |
4043 | ||
4044 | o Turn the symbol referenced in the relocation's symbol index | |
4045 | into a pointer into the canonical symbol table. | |
4046 | This table is the same as the one returned by a call to | |
4047 | @code{bfd_canonicalize_symtab}. The back end will call that | |
4048 | routine and save the result if a canonicalization hasn't been done. | |
4049 | ||
4050 | o The reloc index is turned into a pointer to a howto | |
4051 | structure, in a back end specific way. For instance, the 386 | |
4052 | and 960 use the @code{r_type} to directly produce an index | |
4053 | into a howto table vector; the 88k subtracts a number from the | |
4054 | @code{r_type} field and creates an addend field. | |
4055 | ||
4056 | ||
4057 | */ | |
4058 | ||
4059 | #ifndef CALC_ADDEND | |
4060 | #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \ | |
4061 | { \ | |
4062 | coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \ | |
4063 | if (ptr && bfd_asymbol_bfd (ptr) != abfd) \ | |
4064 | coffsym = (obj_symbols (abfd) \ | |
4065 | + (cache_ptr->sym_ptr_ptr - symbols)); \ | |
4066 | else if (ptr) \ | |
4067 | coffsym = coff_symbol_from (abfd, ptr); \ | |
4068 | if (coffsym != (coff_symbol_type *) NULL \ | |
4069 | && coffsym->native->u.syment.n_scnum == 0) \ | |
4070 | cache_ptr->addend = 0; \ | |
4071 | else if (ptr && bfd_asymbol_bfd (ptr) == abfd \ | |
4072 | && ptr->section != (asection *) NULL) \ | |
4073 | cache_ptr->addend = - (ptr->section->vma + ptr->value); \ | |
4074 | else \ | |
4075 | cache_ptr->addend = 0; \ | |
4076 | } | |
4077 | #endif | |
4078 | ||
4079 | static boolean | |
4080 | coff_slurp_reloc_table (abfd, asect, symbols) | |
4081 | bfd * abfd; | |
4082 | sec_ptr asect; | |
4083 | asymbol ** symbols; | |
4084 | { | |
4085 | RELOC *native_relocs; | |
4086 | arelent *reloc_cache; | |
4087 | arelent *cache_ptr; | |
4088 | ||
4089 | unsigned int idx; | |
4090 | ||
4091 | if (asect->relocation) | |
4092 | return true; | |
4093 | if (asect->reloc_count == 0) | |
4094 | return true; | |
4095 | if (asect->flags & SEC_CONSTRUCTOR) | |
4096 | return true; | |
4097 | if (!coff_slurp_symbol_table (abfd)) | |
4098 | return false; | |
4099 | native_relocs = | |
4100 | (RELOC *) buy_and_read (abfd, | |
4101 | asect->rel_filepos, | |
4102 | SEEK_SET, | |
4103 | (size_t) (RELSZ * | |
4104 | asect->reloc_count)); | |
4105 | reloc_cache = (arelent *) | |
4106 | bfd_alloc (abfd, (size_t) (asect->reloc_count * sizeof (arelent))); | |
4107 | ||
4108 | if (reloc_cache == NULL) | |
4109 | return false; | |
4110 | ||
4111 | ||
4112 | for (idx = 0; idx < asect->reloc_count; idx++) | |
4113 | { | |
4114 | struct internal_reloc dst; | |
4115 | struct external_reloc *src; | |
4116 | #ifndef RELOC_PROCESSING | |
4117 | asymbol *ptr; | |
4118 | #endif | |
4119 | ||
4120 | cache_ptr = reloc_cache + idx; | |
4121 | src = native_relocs + idx; | |
4122 | ||
4123 | coff_swap_reloc_in (abfd, src, &dst); | |
4124 | ||
4125 | #ifdef RELOC_PROCESSING | |
4126 | RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect); | |
4127 | #else | |
4128 | cache_ptr->address = dst.r_vaddr; | |
4129 | ||
4130 | if (dst.r_symndx != -1) | |
4131 | { | |
4132 | if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd)) | |
4133 | { | |
4134 | (*_bfd_error_handler) | |
4135 | (_("%s: warning: illegal symbol index %ld in relocs"), | |
4136 | bfd_get_filename (abfd), dst.r_symndx); | |
4137 | cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | |
4138 | ptr = NULL; | |
4139 | } | |
4140 | else | |
4141 | { | |
4142 | cache_ptr->sym_ptr_ptr = (symbols | |
4143 | + obj_convert (abfd)[dst.r_symndx]); | |
4144 | ptr = *(cache_ptr->sym_ptr_ptr); | |
4145 | } | |
4146 | } | |
4147 | else | |
4148 | { | |
4149 | cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; | |
4150 | ptr = NULL; | |
4151 | } | |
4152 | ||
4153 | /* The symbols definitions that we have read in have been | |
4154 | relocated as if their sections started at 0. But the offsets | |
4155 | refering to the symbols in the raw data have not been | |
4156 | modified, so we have to have a negative addend to compensate. | |
4157 | ||
4158 | Note that symbols which used to be common must be left alone */ | |
4159 | ||
4160 | /* Calculate any reloc addend by looking at the symbol */ | |
4161 | CALC_ADDEND (abfd, ptr, dst, cache_ptr); | |
4162 | ||
4163 | cache_ptr->address -= asect->vma; | |
4164 | /* !! cache_ptr->section = (asection *) NULL;*/ | |
4165 | ||
4166 | /* Fill in the cache_ptr->howto field from dst.r_type */ | |
4167 | RTYPE2HOWTO (cache_ptr, &dst); | |
4168 | #endif /* RELOC_PROCESSING */ | |
4169 | ||
4170 | if (cache_ptr->howto == NULL) | |
4171 | { | |
4172 | (*_bfd_error_handler) | |
4173 | (_("%s: illegal relocation type %d at address 0x%lx"), | |
4174 | bfd_get_filename (abfd), dst.r_type, (long) dst.r_vaddr); | |
4175 | bfd_set_error (bfd_error_bad_value); | |
4176 | return false; | |
4177 | } | |
4178 | } | |
4179 | ||
4180 | asect->relocation = reloc_cache; | |
4181 | return true; | |
4182 | } | |
4183 | ||
4184 | #ifndef coff_rtype_to_howto | |
4185 | #ifdef RTYPE2HOWTO | |
4186 | ||
4187 | /* Get the howto structure for a reloc. This is only used if the file | |
4188 | including this one defines coff_relocate_section to be | |
4189 | _bfd_coff_generic_relocate_section, so it is OK if it does not | |
4190 | always work. It is the responsibility of the including file to | |
4191 | make sure it is reasonable if it is needed. */ | |
4192 | ||
4193 | static reloc_howto_type *coff_rtype_to_howto | |
4194 | PARAMS ((bfd *, asection *, struct internal_reloc *, | |
4195 | struct coff_link_hash_entry *, struct internal_syment *, | |
4196 | bfd_vma *)); | |
4197 | ||
4198 | /*ARGSUSED*/ | |
4199 | static reloc_howto_type * | |
4200 | coff_rtype_to_howto (abfd, sec, rel, h, sym, addendp) | |
5f771d47 ILT |
4201 | bfd *abfd ATTRIBUTE_UNUSED; |
4202 | asection *sec ATTRIBUTE_UNUSED; | |
252b5132 | 4203 | struct internal_reloc *rel; |
5f771d47 ILT |
4204 | struct coff_link_hash_entry *h ATTRIBUTE_UNUSED; |
4205 | struct internal_syment *sym ATTRIBUTE_UNUSED; | |
4206 | bfd_vma *addendp ATTRIBUTE_UNUSED; | |
252b5132 RH |
4207 | { |
4208 | arelent genrel; | |
4209 | ||
4210 | RTYPE2HOWTO (&genrel, rel); | |
4211 | return genrel.howto; | |
4212 | } | |
4213 | ||
4214 | #else /* ! defined (RTYPE2HOWTO) */ | |
4215 | ||
4216 | #define coff_rtype_to_howto NULL | |
4217 | ||
4218 | #endif /* ! defined (RTYPE2HOWTO) */ | |
4219 | #endif /* ! defined (coff_rtype_to_howto) */ | |
4220 | ||
4221 | /* This is stupid. This function should be a boolean predicate. */ | |
4222 | static long | |
4223 | coff_canonicalize_reloc (abfd, section, relptr, symbols) | |
4224 | bfd * abfd; | |
4225 | sec_ptr section; | |
4226 | arelent ** relptr; | |
4227 | asymbol ** symbols; | |
4228 | { | |
4229 | arelent *tblptr = section->relocation; | |
4230 | unsigned int count = 0; | |
4231 | ||
4232 | ||
4233 | if (section->flags & SEC_CONSTRUCTOR) | |
4234 | { | |
4235 | /* this section has relocs made up by us, they are not in the | |
4236 | file, so take them out of their chain and place them into | |
4237 | the data area provided */ | |
4238 | arelent_chain *chain = section->constructor_chain; | |
4239 | for (count = 0; count < section->reloc_count; count++) | |
4240 | { | |
4241 | *relptr++ = &chain->relent; | |
4242 | chain = chain->next; | |
4243 | } | |
4244 | ||
4245 | } | |
4246 | else | |
4247 | { | |
4248 | if (! coff_slurp_reloc_table (abfd, section, symbols)) | |
4249 | return -1; | |
4250 | ||
4251 | tblptr = section->relocation; | |
4252 | ||
4253 | for (; count++ < section->reloc_count;) | |
4254 | *relptr++ = tblptr++; | |
4255 | ||
4256 | ||
4257 | } | |
4258 | *relptr = 0; | |
4259 | return section->reloc_count; | |
4260 | } | |
4261 | ||
4262 | #ifdef GNU960 | |
4263 | file_ptr | |
4264 | coff_sym_filepos (abfd) | |
4265 | bfd *abfd; | |
4266 | { | |
4267 | return obj_sym_filepos (abfd); | |
4268 | } | |
4269 | #endif | |
4270 | ||
4271 | #ifndef coff_reloc16_estimate | |
4272 | #define coff_reloc16_estimate dummy_reloc16_estimate | |
4273 | ||
4274 | static int dummy_reloc16_estimate | |
4275 | PARAMS ((bfd *, asection *, arelent *, unsigned int, | |
4276 | struct bfd_link_info *)); | |
4277 | ||
4278 | static int | |
4279 | dummy_reloc16_estimate (abfd, input_section, reloc, shrink, link_info) | |
5f771d47 ILT |
4280 | bfd *abfd ATTRIBUTE_UNUSED; |
4281 | asection *input_section ATTRIBUTE_UNUSED; | |
4282 | arelent *reloc ATTRIBUTE_UNUSED; | |
4283 | unsigned int shrink ATTRIBUTE_UNUSED; | |
4284 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED; | |
252b5132 RH |
4285 | { |
4286 | abort (); | |
00692651 | 4287 | return 0; |
252b5132 RH |
4288 | } |
4289 | ||
4290 | #endif | |
4291 | ||
4292 | #ifndef coff_reloc16_extra_cases | |
4293 | ||
4294 | #define coff_reloc16_extra_cases dummy_reloc16_extra_cases | |
4295 | ||
4296 | /* This works even if abort is not declared in any header file. */ | |
4297 | ||
4298 | static void dummy_reloc16_extra_cases | |
4299 | PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *, | |
4300 | bfd_byte *, unsigned int *, unsigned int *)); | |
4301 | ||
4302 | static void | |
4303 | dummy_reloc16_extra_cases (abfd, link_info, link_order, reloc, data, src_ptr, | |
4304 | dst_ptr) | |
5f771d47 ILT |
4305 | bfd *abfd ATTRIBUTE_UNUSED; |
4306 | struct bfd_link_info *link_info ATTRIBUTE_UNUSED; | |
4307 | struct bfd_link_order *link_order ATTRIBUTE_UNUSED; | |
4308 | arelent *reloc ATTRIBUTE_UNUSED; | |
4309 | bfd_byte *data ATTRIBUTE_UNUSED; | |
4310 | unsigned int *src_ptr ATTRIBUTE_UNUSED; | |
4311 | unsigned int *dst_ptr ATTRIBUTE_UNUSED; | |
252b5132 RH |
4312 | { |
4313 | abort (); | |
4314 | } | |
4315 | #endif | |
4316 | ||
4317 | /* If coff_relocate_section is defined, we can use the optimized COFF | |
4318 | backend linker. Otherwise we must continue to use the old linker. */ | |
4319 | #ifdef coff_relocate_section | |
4320 | #ifndef coff_bfd_link_hash_table_create | |
4321 | #define coff_bfd_link_hash_table_create _bfd_coff_link_hash_table_create | |
4322 | #endif | |
4323 | #ifndef coff_bfd_link_add_symbols | |
4324 | #define coff_bfd_link_add_symbols _bfd_coff_link_add_symbols | |
4325 | #endif | |
4326 | #ifndef coff_bfd_final_link | |
4327 | #define coff_bfd_final_link _bfd_coff_final_link | |
4328 | #endif | |
4329 | #else /* ! defined (coff_relocate_section) */ | |
4330 | #define coff_relocate_section NULL | |
4331 | #ifndef coff_bfd_link_hash_table_create | |
4332 | #define coff_bfd_link_hash_table_create _bfd_generic_link_hash_table_create | |
4333 | #endif | |
4334 | #ifndef coff_bfd_link_add_symbols | |
4335 | #define coff_bfd_link_add_symbols _bfd_generic_link_add_symbols | |
4336 | #endif | |
4337 | #define coff_bfd_final_link _bfd_generic_final_link | |
4338 | #endif /* ! defined (coff_relocate_section) */ | |
4339 | ||
4340 | #define coff_bfd_link_split_section _bfd_generic_link_split_section | |
4341 | ||
4342 | #ifndef coff_start_final_link | |
4343 | #define coff_start_final_link NULL | |
4344 | #endif | |
4345 | ||
4346 | #ifndef coff_adjust_symndx | |
4347 | #define coff_adjust_symndx NULL | |
4348 | #endif | |
4349 | ||
4350 | #ifndef coff_link_add_one_symbol | |
4351 | #define coff_link_add_one_symbol _bfd_generic_link_add_one_symbol | |
4352 | #endif | |
4353 | ||
4354 | #ifndef coff_link_output_has_begun | |
4355 | ||
4356 | static boolean coff_link_output_has_begun | |
4357 | PARAMS ((bfd *, struct coff_final_link_info *)); | |
4358 | ||
4359 | static boolean | |
4360 | coff_link_output_has_begun (abfd, info) | |
4361 | bfd * abfd; | |
5f771d47 | 4362 | struct coff_final_link_info * info ATTRIBUTE_UNUSED; |
252b5132 RH |
4363 | { |
4364 | return abfd->output_has_begun; | |
4365 | } | |
4366 | #endif | |
4367 | ||
4368 | #ifndef coff_final_link_postscript | |
4369 | ||
4370 | static boolean coff_final_link_postscript | |
4371 | PARAMS ((bfd *, struct coff_final_link_info *)); | |
4372 | ||
4373 | static boolean | |
4374 | coff_final_link_postscript (abfd, pfinfo) | |
5f771d47 ILT |
4375 | bfd * abfd ATTRIBUTE_UNUSED; |
4376 | struct coff_final_link_info * pfinfo ATTRIBUTE_UNUSED; | |
252b5132 RH |
4377 | { |
4378 | return true; | |
4379 | } | |
4380 | #endif | |
4381 | ||
4382 | #ifndef coff_SWAP_aux_in | |
4383 | #define coff_SWAP_aux_in coff_swap_aux_in | |
4384 | #endif | |
4385 | #ifndef coff_SWAP_sym_in | |
4386 | #define coff_SWAP_sym_in coff_swap_sym_in | |
4387 | #endif | |
4388 | #ifndef coff_SWAP_lineno_in | |
4389 | #define coff_SWAP_lineno_in coff_swap_lineno_in | |
4390 | #endif | |
4391 | #ifndef coff_SWAP_aux_out | |
4392 | #define coff_SWAP_aux_out coff_swap_aux_out | |
4393 | #endif | |
4394 | #ifndef coff_SWAP_sym_out | |
4395 | #define coff_SWAP_sym_out coff_swap_sym_out | |
4396 | #endif | |
4397 | #ifndef coff_SWAP_lineno_out | |
4398 | #define coff_SWAP_lineno_out coff_swap_lineno_out | |
4399 | #endif | |
4400 | #ifndef coff_SWAP_reloc_out | |
4401 | #define coff_SWAP_reloc_out coff_swap_reloc_out | |
4402 | #endif | |
4403 | #ifndef coff_SWAP_filehdr_out | |
4404 | #define coff_SWAP_filehdr_out coff_swap_filehdr_out | |
4405 | #endif | |
4406 | #ifndef coff_SWAP_aouthdr_out | |
4407 | #define coff_SWAP_aouthdr_out coff_swap_aouthdr_out | |
4408 | #endif | |
4409 | #ifndef coff_SWAP_scnhdr_out | |
4410 | #define coff_SWAP_scnhdr_out coff_swap_scnhdr_out | |
4411 | #endif | |
4412 | #ifndef coff_SWAP_reloc_in | |
4413 | #define coff_SWAP_reloc_in coff_swap_reloc_in | |
4414 | #endif | |
4415 | #ifndef coff_SWAP_filehdr_in | |
4416 | #define coff_SWAP_filehdr_in coff_swap_filehdr_in | |
4417 | #endif | |
4418 | #ifndef coff_SWAP_aouthdr_in | |
4419 | #define coff_SWAP_aouthdr_in coff_swap_aouthdr_in | |
4420 | #endif | |
4421 | #ifndef coff_SWAP_scnhdr_in | |
4422 | #define coff_SWAP_scnhdr_in coff_swap_scnhdr_in | |
4423 | #endif | |
4424 | ||
4425 | ||
4426 | ||
4427 | static CONST bfd_coff_backend_data bfd_coff_std_swap_table = | |
4428 | { | |
4429 | coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in, | |
4430 | coff_SWAP_aux_out, coff_SWAP_sym_out, | |
4431 | coff_SWAP_lineno_out, coff_SWAP_reloc_out, | |
4432 | coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out, | |
4433 | coff_SWAP_scnhdr_out, | |
4434 | FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, | |
4435 | #ifdef COFF_LONG_FILENAMES | |
4436 | true, | |
4437 | #else | |
4438 | false, | |
4439 | #endif | |
4440 | #ifdef COFF_LONG_SECTION_NAMES | |
4441 | true, | |
4442 | #else | |
4443 | false, | |
4444 | #endif | |
4445 | COFF_DEFAULT_SECTION_ALIGNMENT_POWER, | |
4446 | coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in, | |
4447 | coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook, | |
4448 | coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook, | |
4449 | coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook, | |
4450 | coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate, | |
5d54c628 | 4451 | coff_classify_symbol, coff_compute_section_file_positions, |
252b5132 RH |
4452 | coff_start_final_link, coff_relocate_section, coff_rtype_to_howto, |
4453 | coff_adjust_symndx, coff_link_add_one_symbol, | |
4454 | coff_link_output_has_begun, coff_final_link_postscript | |
4455 | }; | |
4456 | ||
4457 | #ifndef coff_close_and_cleanup | |
4458 | #define coff_close_and_cleanup _bfd_generic_close_and_cleanup | |
4459 | #endif | |
4460 | ||
4461 | #ifndef coff_bfd_free_cached_info | |
4462 | #define coff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info | |
4463 | #endif | |
4464 | ||
4465 | #ifndef coff_get_section_contents | |
4466 | #define coff_get_section_contents _bfd_generic_get_section_contents | |
4467 | #endif | |
4468 | ||
4469 | #ifndef coff_bfd_copy_private_symbol_data | |
4470 | #define coff_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data | |
4471 | #endif | |
4472 | ||
4473 | #ifndef coff_bfd_copy_private_section_data | |
4474 | #define coff_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data | |
4475 | #endif | |
4476 | ||
4477 | #ifndef coff_bfd_copy_private_bfd_data | |
4478 | #define coff_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data | |
4479 | #endif | |
4480 | ||
4481 | #ifndef coff_bfd_merge_private_bfd_data | |
4482 | #define coff_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data | |
4483 | #endif | |
4484 | ||
4485 | #ifndef coff_bfd_set_private_flags | |
4486 | #define coff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags | |
4487 | #endif | |
4488 | ||
4489 | #ifndef coff_bfd_print_private_bfd_data | |
4490 | #define coff_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data | |
4491 | #endif | |
4492 | ||
4493 | #ifndef coff_bfd_is_local_label_name | |
4494 | #define coff_bfd_is_local_label_name _bfd_coff_is_local_label_name | |
4495 | #endif | |
4496 | ||
4497 | #ifndef coff_read_minisymbols | |
4498 | #define coff_read_minisymbols _bfd_generic_read_minisymbols | |
4499 | #endif | |
4500 | ||
4501 | #ifndef coff_minisymbol_to_symbol | |
4502 | #define coff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol | |
4503 | #endif | |
4504 | ||
4505 | /* The reloc lookup routine must be supplied by each individual COFF | |
4506 | backend. */ | |
4507 | #ifndef coff_bfd_reloc_type_lookup | |
4508 | #define coff_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup | |
4509 | #endif | |
4510 | ||
4511 | #ifndef coff_bfd_get_relocated_section_contents | |
4512 | #define coff_bfd_get_relocated_section_contents \ | |
4513 | bfd_generic_get_relocated_section_contents | |
4514 | #endif | |
4515 | ||
4516 | #ifndef coff_bfd_relax_section | |
4517 | #define coff_bfd_relax_section bfd_generic_relax_section | |
4518 | #endif | |
4519 | ||
4520 | #ifndef coff_bfd_gc_sections | |
4521 | #define coff_bfd_gc_sections bfd_generic_gc_sections | |
4522 | #endif | |
c3c89269 NC |
4523 | |
4524 | #define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE) \ | |
4525 | const bfd_target VAR = \ | |
4526 | { \ | |
4527 | NAME , \ | |
4528 | bfd_target_coff_flavour, \ | |
4529 | BFD_ENDIAN_BIG, /* data byte order is big */ \ | |
4530 | BFD_ENDIAN_BIG, /* header byte order is big */ \ | |
4531 | /* object flags */ \ | |
4532 | (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \ | |
4533 | HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \ | |
4534 | /* section flags */ \ | |
4535 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS), \ | |
4536 | UNDER, /* leading symbol underscore */ \ | |
4537 | '/', /* ar_pad_char */ \ | |
4538 | 15, /* ar_max_namelen */ \ | |
4539 | \ | |
4540 | /* Data conversion functions. */ \ | |
4541 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, \ | |
4542 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, \ | |
4543 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, \ | |
4544 | \ | |
4545 | /* Header conversion functions. */ \ | |
4546 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, \ | |
4547 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, \ | |
4548 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, \ | |
4549 | \ | |
4550 | /* bfd_check_format */ \ | |
4551 | { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, _bfd_dummy_target }, \ | |
4552 | /* bfd_set_format */ \ | |
4553 | { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \ | |
4554 | /* bfd_write_contents */ \ | |
4555 | { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, bfd_false }, \ | |
4556 | \ | |
4557 | BFD_JUMP_TABLE_GENERIC (coff), \ | |
4558 | BFD_JUMP_TABLE_COPY (coff), \ | |
4559 | BFD_JUMP_TABLE_CORE (_bfd_nocore), \ | |
4560 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \ | |
4561 | BFD_JUMP_TABLE_SYMBOLS (coff), \ | |
4562 | BFD_JUMP_TABLE_RELOCS (coff), \ | |
4563 | BFD_JUMP_TABLE_WRITE (coff), \ | |
4564 | BFD_JUMP_TABLE_LINK (coff), \ | |
4565 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \ | |
4566 | \ | |
4567 | ALTERNATIVE, \ | |
4568 | \ | |
4569 | COFF_SWAP_TABLE \ | |
4570 | }; | |
4571 | ||
4572 | #define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE) \ | |
4573 | const bfd_target VAR = \ | |
4574 | { \ | |
4575 | NAME , \ | |
4576 | bfd_target_coff_flavour, \ | |
4577 | BFD_ENDIAN_LITTLE, /* data byte order is little */ \ | |
4578 | BFD_ENDIAN_LITTLE, /* header byte order is little */ \ | |
4579 | /* object flags */ \ | |
4580 | (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \ | |
4581 | HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \ | |
4582 | /* section flags */ \ | |
4583 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS), \ | |
4584 | UNDER, /* leading symbol underscore */ \ | |
4585 | '/', /* ar_pad_char */ \ | |
4586 | 15, /* ar_max_namelen */ \ | |
4587 | \ | |
4588 | /* Data conversion functions. */ \ | |
4589 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, \ | |
4590 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, \ | |
4591 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, \ | |
4592 | /* Header conversion functions. */ \ | |
4593 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, \ | |
4594 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, \ | |
4595 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, \ | |
4596 | /* bfd_check_format */ \ | |
4597 | { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, _bfd_dummy_target }, \ | |
4598 | /* bfd_set_format */ \ | |
4599 | { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \ | |
4600 | /* bfd_write_contents */ \ | |
4601 | { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, bfd_false }, \ | |
4602 | \ | |
4603 | BFD_JUMP_TABLE_GENERIC (coff), \ | |
4604 | BFD_JUMP_TABLE_COPY (coff), \ | |
4605 | BFD_JUMP_TABLE_CORE (_bfd_nocore), \ | |
4606 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \ | |
4607 | BFD_JUMP_TABLE_SYMBOLS (coff), \ | |
4608 | BFD_JUMP_TABLE_RELOCS (coff), \ | |
4609 | BFD_JUMP_TABLE_WRITE (coff), \ | |
4610 | BFD_JUMP_TABLE_LINK (coff), \ | |
4611 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \ | |
4612 | \ | |
4613 | ALTERNATIVE, \ | |
4614 | \ | |
4615 | COFF_SWAP_TABLE \ | |
4616 | }; |