Add COFF_SWAP_TABLE to it (oops)
[deliverable/binutils-gdb.git] / bfd / coffcode.h
CommitLineData
6d7c88c3 1/* Support for the generic parts of most COFF variants, for BFD.
7a8b18b6
SC
2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
3 Written by Cygnus Support.
0f268757 4
7a8b18b6 5This file is part of BFD, the Binary File Descriptor library.
0f268757 6
7a8b18b6
SC
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
0f268757 11
7a8b18b6
SC
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
0f268757 16
7a8b18b6
SC
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6f715d66
SC
20
21/*doc*
22@section coff backends
23
24BFD supports a number of different flavours of coff format. The major
25difference between formats are the sizes and alignments of fields in
26structures on disk, and the occasional extra field.
27
28Coff in all its varieties is implimented with a few common files and a
29number of implementation specific files. For example, The 88k bcs coff
3b4f1a5d
SC
30format is implemented in the file @code{coff-m88k.c}. This file
31@code{#include}s @code{coff-m88k.h} which defines the external
6f715d66 32structure of the coff format for the 88k, and @code{internalcoff.h}
3b4f1a5d 33which defines the internal structure. @code{coff-m88k.c} also defines
6f715d66
SC
34the relocations used by the 88k format @xref{Relocations}. Then the
35major portion of coff code is included (@code{coffcode.h}) which
36defines the methods used to act upon the types defined in
3b4f1a5d 37@code{coff-m88k.h} and @code{internalcoff.h}.
6f715d66
SC
38
39The Intel i960 processor version of coff is implemented in
3b4f1a5d
SC
40@code{coff-i960.c}. This file has the same structure as
41@code{coff-m88k.c}, except that it includes @code{coff-i960.h} rather
42than @code{coff-m88k.h}.
6f715d66
SC
43
44@subsection Porting To A New Version of Coff
45
46The recommended method is to select from the existing implimentations
47the version of coff which is most like the one you want to use, for
48our purposes, we'll say that i386 coff is the one you select, and that
49your coff flavour is called foo. Copy the @code{i386coff.c} to @code{foocoff.c},
50copy @code{../include/i386coff.h} to @code{../include/foocoff.h} and
51add the lines to @code{targets.c} and @code{Makefile.in} so that your
cbdc7909 52new back end is used.
6f715d66
SC
53
54Alter the shapes of the structures in @code{../include/foocoff.h} so
55that they match what you need. You will probably also have to add
56@code{#ifdef}s to the code in @code{internalcoff.h} and
57@code{coffcode.h} if your version of coff is too wild.
58
6724ff46 59You can verify that your new BFD backend works quite simply by
6f715d66
SC
60building @code{objdump} from the @code{binutils} directory, and
61making sure that its version of what's going on at your host systems
62idea (assuming it has the pretty standard coff dump utility (usually
63called @code{att-dump} or just @code{dump})) are the same.
64
65Then clean up your code, and send what you've done to Cygnus. Then your stuff
66will be in the next release, and you won't have to keep integrating
67it.
68
69@subsection How The Coff Backend Works
70
71@subsubsection Bit Twiddling
6724ff46 72Each flavour of coff supported in BFD has its own header file
6f715d66
SC
73descibing the external layout of the structures. There is also an
74internal description of the coff layout (in @code{internalcoff.h})
75file (@code{}). A major function of the coff backend is swapping the
76bytes and twiddling the bits to translate the external form of the
77structures into the normal internal form. This is all performed in the
78@code{bfd_swap}_@i{thing}_@i{direction} routines. Some elements are
79different sizes between different versions of coff, it is the duty of
80the coff version specific include file to override the definitions of
81various packing routines in @code{coffcode.h}. Eg the size of line
82number entry in coff is sometimes 16 bits, and sometimes 32 bits.
83@code{#define}ing @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will
84select the correct one. No doubt, some day someone will find a version
85of coff which has a varying field size not catered for at the moment.
6724ff46 86To port BFD, that person will have to add more @code{#defines}.
6f715d66
SC
87
88Three of the bit twiddling routines are exported to @code{gdb};
89@code{coff_swap_aux_in}, @code{coff_swap_sym_in} and
90@code{coff_swap_linno_in}. @code{GDB} reads the symbol table on its
6724ff46 91own, but uses BFD to fix things up.
6f715d66 92
0d740984
SC
93More of the bit twiddlers are exported for @code{gas};
94@code{coff_swap_aux_out}, @code{coff_swap_sym_out},
95@code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
96@code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
97@code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track of all
98the symbol table and reloc drudgery itself, thereby saving the
99internal BFD overhead, but uses BFD to swap things on the way out,
100making cross ports much safer. This also allows BFD (and thus the
101linker) to use the same header files as @code{gas}, which makes one
102avenue to disaster disappear.
103
6f715d66 104@subsubsection Symbol Reading
6724ff46 105The simple canonical form for symbols used by BFD is not rich enough
6f715d66
SC
106to keep all the information available in a coff symbol table. The back
107end gets around this by keeping the original symbol table around,
cbdc7909 108"behind the scenes".
6f715d66
SC
109
110When a symbol table is requested (through a call to
111@code{bfd_canonicalize_symtab}, a request gets through to
112@code{get_normalized_symtab}. This reads the symbol table from the
113coff file and swaps all the structures inside into the internal form.
114It also fixes up all the pointers in the table (represented in the file
115by offsets from the first symbol in the table) into physical pointers
116to elements in the new internal table. This involves some work since
117the meanings of fields changes depending upon context; a field that is a
118pointer to another structure in the symbol table at one moment may be
119the size in bytes of a structure in the next.
120
121Another pass is made over the table. All symbols which mark file names
122(@code{C_FILE} symbols) are modified so that the internal string
123points to the value in the auxent (the real filename) rather than the
124normal text associated with the symbol (@code{".file"}).
125
126At this time the symbol names are moved around. Coff stores all
127symbols less than nine characters long physically within the symbol
128table, longer strings are kept at the end of the file in the string
129table. This pass moves all strings into memory, and replaces them with
130pointers to the strings.
131
132The symbol table is massaged once again, this time to create the
6724ff46 133canonical table used by the BFD application. Each symbol is inspected
6f715d66
SC
134in turn, and a decision made (using the @code{sclass} field) about the
135various flags to set in the @code{asymbol} @xref{Symbols}. The
136generated canonical table shares strings with the hidden internal
137symbol table.
138
7d003262 139Any linenumbers are read from the coff file too, and attached to the
6f715d66
SC
140symbols which own the functions the linenumbers belong to.
141
142@subsubsection Symbol Writing
143Writing a symbol to a coff file which didn't come from a coff file
144will lose any debugging information. The @code{asymbol} structure
6724ff46 145remembers the BFD from which was born, and on output the back end
6f715d66
SC
146makes sure that the same destination target as source target is
147present.
148
149When the symbols have come from a coff file then all the debugging
cbdc7909 150information is preserved.
6f715d66
SC
151
152Symbol tables are provided for writing to the back end in a vector of
153pointers to pointers. This allows applications like the linker to
154accumulate and output large symbol tables without having to do too
155much byte copying.
156
cbdc7909 157The symbol table is not output to a writable BFD until it is closed.
6f715d66
SC
158The order of operations on the canonical symbol table at that point
159are:
160@table @code
161@item coff_renumber_symbols
162This function runs through the provided symbol table and patches each
163symbol marked as a file place holder (@code{C_FILE}) to point to the
164next file place holder in the list. It also marks each @code{offset}
165field in the list with the offset from the first symbol of the current
cbdc7909 166symbol.
6f715d66
SC
167
168Another function of this procedure is to turn the canonical value form
6724ff46 169of BFD into the form used by coff. Internally, BFD expects symbol
6f715d66
SC
170values to be offsets from a section base; so a symbol physically at
1710x120, but in a section starting at 0x100, would have the value 0x20.
172Coff expects symbols to contain their final value, so symbols have
173their values changed at this point to reflect their sum with their
174owning section. Note that this transformation uses the
175@code{output_section} field of the @code{asymbol}'s @code{asection}
176@xref{Sections}.
177@item coff_mangle_symbols
178This routine runs though the provided symbol table and uses the
179offsets generated by the previous pass and the pointers generated when
180the symbol table was read in to create the structured hierachy
181required by coff. It changes each pointer to a symbol to an index into
182the symbol table of the symbol being referenced.
183@item coff_write_symbols
184This routine runs through the symbol table and patches up the symbols
185from their internal form into the coff way, calls the bit twiddlers
186and writes out the tabel to the file.
187@end table
188*/
189
190/*proto*
191
192The hidden information for an asymbol is:
193
194*+++
195
196$ typedef struct coff_ptr_struct
197$ {
198
199Remembers the offset from the first symbol in the file for this
200symbol. Generated by @code{coff_renumber_symbols}.
201
202$ unsigned int offset;
203
204Should the tag field of this symbol be renumbered.
205Created by @code{coff_pointerize_aux}.
206
207$ char fix_tag;
208
209Should the endidx field of this symbol be renumbered.
210Created by @code{coff_pointerize_aux}.
211
212$ char fix_end;
213
214The container for the symbol structure as read and translated from the file.
215
216$ union {
217$ union internal_auxent auxent;
218$ struct internal_syment syment;
219$ } u;
220$ } combined_entry_type;
221$
222
223*---
224
225Each canonical asymbol really looks like this:
226
227*+++
228
229$ typedef struct coff_symbol_struct
230$ {
231
6724ff46 232The actual symbol which the rest of BFD works with
6f715d66
SC
233
234$ asymbol symbol;
235
236A pointer to the hidden information for this symbol
237
238$ combined_entry_type *native;
239
240A pointer to the linenumber information for this symbol
241
242$ struct lineno_cache_entry *lineno;
243$ } coff_symbol_type;
244
245*---
246
0f268757
SC
247*/
248
0f268757
SC
249/* Most of this hacked by Steve Chamberlain, steve@cygnus.com */
250
0f268757
SC
251
252#define PUTWORD bfd_h_put_32
253#define PUTHALF bfd_h_put_16
6d7c88c3 254#define PUTBYTE bfd_h_put_8
6f715d66
SC
255
256#ifndef GET_FCN_LNNOPTR
41f50af0 257#define GET_FCN_LNNOPTR(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
6f715d66
SC
258#endif
259
260#ifndef GET_FCN_ENDNDX
41f50af0 261#define GET_FCN_ENDNDX(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
6f715d66
SC
262#endif
263
264#ifndef PUT_FCN_LNNOPTR
41f50af0 265#define PUT_FCN_LNNOPTR(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
6f715d66
SC
266#endif
267#ifndef PUT_FCN_ENDNDX
41f50af0 268#define PUT_FCN_ENDNDX(abfd, in, ext) PUTWORD(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
6f715d66
SC
269#endif
270#ifndef GET_LNSZ_LNNO
41f50af0 271#define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
6f715d66
SC
272#endif
273#ifndef GET_LNSZ_SIZE
41f50af0 274#define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
6f715d66
SC
275#endif
276#ifndef PUT_LNSZ_LNNO
41f50af0 277#define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
6f715d66
SC
278#endif
279#ifndef PUT_LNSZ_SIZE
41f50af0 280#define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
6f715d66 281#endif
cbdc7909 282#ifndef GET_SCN_SCNLEN
41f50af0 283#define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
6f715d66
SC
284#endif
285#ifndef GET_SCN_NRELOC
41f50af0 286#define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
6f715d66
SC
287#endif
288#ifndef GET_SCN_NLINNO
41f50af0 289#define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
6f715d66 290#endif
cbdc7909 291#ifndef PUT_SCN_SCNLEN
41f50af0 292#define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
6f715d66
SC
293#endif
294#ifndef PUT_SCN_NRELOC
41f50af0 295#define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
6f715d66
SC
296#endif
297#ifndef PUT_SCN_NLINNO
85e0c721
SC
298#define PUT_SCN_NLINNO(abfd,in, ext) bfd_h_put_16(abfd,in, (bfd_byte *) ext->x_scn.x_nlinno)
299#endif
300#ifndef GET_LINENO_LNNO
301#define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
302#endif
8c4a1ace 303#ifndef PUT_LINENO_LNNO
85e0c721 304#define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
0f268757 305#endif
0f268757
SC
306
307\f
308/* void warning(); */
6f715d66 309
cbdc7909
JG
310/*
311 * Return a word with STYP_* (scnhdr.s_flags) flags set to represent the
41f50af0
SC
312 * incoming SEC_* flags. The inverse of this function is styp_to_sec_flags().
313 * NOTE: If you add to/change this routine, you should mirror the changes
314 * in styp_to_sec_flags().
315 */
cbdc7909 316static long
41f50af0
SC
317DEFUN(sec_to_styp_flags, (sec_name, sec_flags),
318 CONST char * sec_name AND
319 flagword sec_flags)
320{
321 long styp_flags = 0;
322
323 if (!strcmp(sec_name, _TEXT)) {
324 return((long)STYP_TEXT);
325 } else if (!strcmp(sec_name, _DATA)) {
326 return((long)STYP_DATA);
327 } else if (!strcmp(sec_name, _BSS)) {
328 return((long)STYP_BSS);
8c4a1ace
JG
329#ifdef _COMMENT
330 } else if (!strcmp(sec_name, _COMMENT)) {
331 return((long)STYP_INFO);
332#endif /* _COMMENT */
cbdc7909 333 }
41f50af0
SC
334
335/* Try and figure out what it should be */
cbdc7909
JG
336 if (sec_flags & SEC_CODE) styp_flags = STYP_TEXT;
337 if (sec_flags & SEC_DATA) styp_flags = STYP_DATA;
338 else if (sec_flags & SEC_READONLY)
41f50af0 339#ifdef STYP_LIT /* 29k readonly text/data section */
cbdc7909 340 styp_flags = STYP_LIT;
41f50af0 341#else
cbdc7909 342 styp_flags = STYP_TEXT;
41f50af0
SC
343#endif /* STYP_LIT */
344 else if (sec_flags & SEC_LOAD) styp_flags = STYP_TEXT;
345
346 if (styp_flags == 0) styp_flags = STYP_BSS;
347
348 return(styp_flags);
349}
cbdc7909 350/*
41f50af0 351 * Return a word with SEC_* flags set to represent the incoming
cbdc7909
JG
352 * STYP_* flags (from scnhdr.s_flags). The inverse of this
353 * function is sec_to_styp_flags().
41f50af0
SC
354 * NOTE: If you add to/change this routine, you should mirror the changes
355 * in sec_to_styp_flags().
356 */
cbdc7909 357static flagword
41f50af0
SC
358DEFUN(styp_to_sec_flags, (styp_flags),
359 long styp_flags)
360{
361 flagword sec_flags=0;
362
363 if ((styp_flags & STYP_TEXT) || (styp_flags & STYP_DATA))
364 sec_flags = (SEC_LOAD | SEC_ALLOC);
365 else if (styp_flags & STYP_BSS)
366 sec_flags = SEC_ALLOC;
367
368#ifdef STYP_LIT /* A29k readonly text/data section type */
369 if ((styp_flags & STYP_LIT) == STYP_LIT)
370 sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
371#endif /* STYP_LIT */
853f0a70
JG
372#ifdef STYP_OTHER_LOAD /* Other loaded sections */
373 if (styp_flags & STYP_OTHER_LOAD)
374 sec_flags = (SEC_LOAD | SEC_ALLOC);
375#endif /* STYP_SDATA */
41f50af0
SC
376
377 return(sec_flags);
378}
0f268757 379
fb3be09b
JG
380#define get_index(symbol) ((int) (symbol)->value)
381#define set_index(symbol, idx) ((symbol)->value = (idx))
0f268757 382
6f715d66
SC
383/* **********************************************************************
384Here are all the routines for swapping the structures seen in the
cbdc7909 385outside world into the internal forms.
0f268757
SC
386*/
387
388
2700c3c7 389static void
0f268757
SC
390DEFUN(bfd_swap_reloc_in,(abfd, reloc_src, reloc_dst),
391 bfd *abfd AND
392 RELOC *reloc_src AND
393 struct internal_reloc *reloc_dst)
394{
41f50af0
SC
395 reloc_dst->r_vaddr = bfd_h_get_32(abfd, (bfd_byte *)reloc_src->r_vaddr);
396 reloc_dst->r_symndx = bfd_h_get_32(abfd, (bfd_byte *) reloc_src->r_symndx);
cbdc7909
JG
397
398#ifdef RS6000COFF_C
399 reloc_dst->r_type = bfd_h_get_8(abfd, reloc_src->r_type);
400 reloc_dst->r_size = bfd_h_get_8(abfd, reloc_src->r_size);
401#else
41f50af0 402 reloc_dst->r_type = bfd_h_get_16(abfd, (bfd_byte *) reloc_src->r_type);
cbdc7909
JG
403#endif
404
3b4f1a5d
SC
405#ifdef SWAP_IN_RELOC_OFFSET
406 reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET(abfd, reloc_src->r_offset);
0f268757
SC
407#endif
408}
409
2700c3c7 410
0d740984
SC
411static unsigned int
412DEFUN(coff_swap_reloc_out,(abfd, src, dst),
413 bfd *abfd AND
414 PTR src AND
415 PTR dst)
0f268757 416{
0d740984
SC
417 struct internal_reloc *reloc_src = (struct internal_reloc *)src;
418 struct external_reloc *reloc_dst = (struct external_reloc *)dst;
41f50af0
SC
419 bfd_h_put_32(abfd, reloc_src->r_vaddr, (bfd_byte *) reloc_dst->r_vaddr);
420 bfd_h_put_32(abfd, reloc_src->r_symndx, (bfd_byte *) reloc_dst->r_symndx);
3b4f1a5d
SC
421 bfd_h_put_16(abfd, reloc_src->r_type, (bfd_byte *)
422 reloc_dst->r_type);
423
424#ifdef SWAP_OUT_RELOC_OFFSET
425 SWAP_OUT_RELOC_OFFSET(abfd,
426 reloc_src->r_offset,
427 (bfd_byte *) reloc_dst->r_offset);
428#endif
429#ifdef SWAP_OUT_RELOC_EXTRA
430 SWAP_OUT_RELOC_EXTRA(abfd,reloc_src, reloc_dst);
0f268757 431#endif
3b4f1a5d 432
0d740984 433 return sizeof(struct external_reloc);
0f268757
SC
434}
435
2700c3c7 436static void
0f268757
SC
437DEFUN(bfd_swap_filehdr_in,(abfd, filehdr_src, filehdr_dst),
438 bfd *abfd AND
439 FILHDR *filehdr_src AND
440 struct internal_filehdr *filehdr_dst)
441{
41f50af0
SC
442 filehdr_dst->f_magic = bfd_h_get_16(abfd, (bfd_byte *) filehdr_src->f_magic);
443 filehdr_dst->f_nscns = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_nscns);
444 filehdr_dst->f_timdat = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_timdat);
445 filehdr_dst->f_symptr = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_symptr);
446 filehdr_dst->f_nsyms = bfd_h_get_32(abfd, (bfd_byte *)filehdr_src-> f_nsyms);
447 filehdr_dst->f_opthdr = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_opthdr);
448 filehdr_dst->f_flags = bfd_h_get_16(abfd, (bfd_byte *)filehdr_src-> f_flags);
0f268757
SC
449}
450
0d740984
SC
451static unsigned int
452DEFUN(coff_swap_filehdr_out,(abfd, in, out),
453 bfd *abfd AND
454 PTR in AND
455 PTR out)
0f268757 456{
0d740984
SC
457 struct internal_filehdr *filehdr_in = (struct internal_filehdr *)in;
458 FILHDR *filehdr_out = (FILHDR *)out;
41f50af0
SC
459 bfd_h_put_16(abfd, filehdr_in->f_magic, (bfd_byte *) filehdr_out->f_magic);
460 bfd_h_put_16(abfd, filehdr_in->f_nscns, (bfd_byte *) filehdr_out->f_nscns);
461 bfd_h_put_32(abfd, filehdr_in->f_timdat, (bfd_byte *) filehdr_out->f_timdat);
462 bfd_h_put_32(abfd, filehdr_in->f_symptr, (bfd_byte *) filehdr_out->f_symptr);
463 bfd_h_put_32(abfd, filehdr_in->f_nsyms, (bfd_byte *) filehdr_out->f_nsyms);
464 bfd_h_put_16(abfd, filehdr_in->f_opthdr, (bfd_byte *) filehdr_out->f_opthdr);
465 bfd_h_put_16(abfd, filehdr_in->f_flags, (bfd_byte *) filehdr_out->f_flags);
0d740984 466 return sizeof(FILHDR);
0f268757
SC
467}
468
469
7a8b18b6 470#ifndef NO_COFF_SYMBOLS
2700c3c7 471
cbdc7909 472static void
6f715d66 473DEFUN(coff_swap_sym_in,(abfd, ext1, in1),
0f268757 474 bfd *abfd AND
6f715d66
SC
475 PTR ext1 AND
476 PTR in1)
0f268757 477{
6f715d66
SC
478 SYMENT *ext = (SYMENT *)ext1;
479 struct internal_syment *in = (struct internal_syment *)in1;
480
0f268757
SC
481 if( ext->e.e_name[0] == 0) {
482 in->_n._n_n._n_zeroes = 0;
41f50af0 483 in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
0f268757
SC
484 }
485 else {
fb3be09b
JG
486#if SYMNMLEN != E_SYMNMLEN
487 -> Error, we need to cope with truncating or extending SYMNMLEN!;
488#else
0f268757 489 memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
fb3be09b 490#endif
0f268757 491 }
41f50af0
SC
492 in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
493 in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
0f268757 494 if (sizeof(ext->e_type) == 2){
41f50af0 495 in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
0f268757
SC
496 }
497 else {
41f50af0 498 in->n_type = bfd_h_get_32(abfd, (bfd_byte *) ext->e_type);
0f268757
SC
499 }
500 in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
501 in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
502}
503
0d740984
SC
504static unsigned int
505DEFUN(coff_swap_sym_out,(abfd, inp, extp),
506 bfd *abfd AND
507 PTR inp AND
508 PTR extp)
0f268757 509{
0d740984
SC
510 struct internal_syment *in = (struct internal_syment *)inp;
511 SYMENT *ext =(SYMENT *)extp;
0f268757 512 if(in->_n._n_name[0] == 0) {
41f50af0
SC
513 bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
514 bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *) ext->e.e.e_offset);
0f268757
SC
515 }
516 else {
fb3be09b 517#if SYMNMLEN != E_SYMNMLEN
0d740984 518 -> Error, we need to cope with truncating or extending SYMNMLEN!;
fb3be09b 519#else
0f268757 520 memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
fb3be09b 521#endif
0f268757 522 }
41f50af0
SC
523 bfd_h_put_32(abfd, in->n_value , (bfd_byte *) ext->e_value);
524 bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
cbdc7909 525 if (sizeof(ext->e_type) == 2)
0f268757 526 {
41f50af0 527 bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
0f268757
SC
528 }
529 else
530 {
41f50af0 531 bfd_h_put_32(abfd, in->n_type , (bfd_byte *) ext->e_type);
0f268757
SC
532 }
533 bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
534 bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
0d740984 535 return sizeof(SYMENT);
0f268757
SC
536}
537
2700c3c7 538static void
6f715d66 539DEFUN(coff_swap_aux_in,(abfd, ext1, type, class, in1),
0f268757 540 bfd *abfd AND
fb3be09b 541 PTR ext1 AND
0f268757
SC
542 int type AND
543 int class AND
fb3be09b 544 PTR in1)
0f268757 545{
6f715d66
SC
546 AUXENT *ext = (AUXENT *)ext1;
547 union internal_auxent *in = (union internal_auxent *)in1;
0f268757
SC
548 switch (class) {
549 case C_FILE:
550 if (ext->x_file.x_fname[0] == 0) {
551 in->x_file.x_n.x_zeroes = 0;
6d7c88c3
JG
552 in->x_file.x_n.x_offset =
553 bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
2099685b 554 } else {
fb3be09b
JG
555#if FILNMLEN != E_FILNMLEN
556 -> Error, we need to cope with truncating or extending FILNMLEN!;
557#else
558 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
559#endif
0f268757 560 }
6d7c88c3 561 break;
0f268757 562
6d7c88c3
JG
563 /* RS/6000 "csect" auxents */
564#ifdef RS6000COFF_C
565 case C_EXT:
566 case C_HIDEXT:
567 in->x_csect.x_scnlen = bfd_h_get_32 (abfd, (bfd_byte *) ext->x_csect.x_scnlen);
568 in->x_csect.x_parmhash = bfd_h_get_32 (abfd, (bfd_byte *) ext->x_csect.x_parmhash);
569 in->x_csect.x_snhash = bfd_h_get_16 (abfd, (bfd_byte *) ext->x_csect.x_snhash);
570 /* We don't have to hack bitfields in x_smtyp because it's defined by
571 shifts-and-ands, which are equivalent on all byte orders. */
572 in->x_csect.x_smtyp = bfd_h_get_8 (abfd, (bfd_byte *) ext->x_csect.x_smtyp);
573 in->x_csect.x_smclas = bfd_h_get_8 (abfd, (bfd_byte *) ext->x_csect.x_smclas);
574 in->x_csect.x_stab = bfd_h_get_32 (abfd, (bfd_byte *) ext->x_csect.x_stab);
575 in->x_csect.x_snstab = bfd_h_get_16 (abfd, (bfd_byte *) ext->x_csect.x_snstab);
0f268757 576 break;
6d7c88c3
JG
577#endif
578
0f268757
SC
579 case C_STAT:
580#ifdef C_LEAFSTAT
581 case C_LEAFSTAT:
582#endif
583 case C_HIDDEN:
584 if (type == T_NULL) {
6f715d66
SC
585 in->x_scn.x_scnlen = GET_SCN_SCNLEN(abfd, ext);
586 in->x_scn.x_nreloc = GET_SCN_NRELOC(abfd, ext);
587 in->x_scn.x_nlinno = GET_SCN_NLINNO(abfd, ext);
0f268757
SC
588 break;
589 }
590 default:
41f50af0 591 in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
6f715d66 592#ifndef NO_TVNDX
41f50af0 593 in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
6f715d66 594#endif
0f268757
SC
595
596 if (ISARY(type) || class == C_BLOCK) {
fb3be09b
JG
597#if DIMNUM != E_DIMNUM
598 -> Error, we need to cope with truncating or extending DIMNUM!;
599#else
41f50af0
SC
600 in->x_sym.x_fcnary.x_ary.x_dimen[0] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
601 in->x_sym.x_fcnary.x_ary.x_dimen[1] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
602 in->x_sym.x_fcnary.x_ary.x_dimen[2] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
603 in->x_sym.x_fcnary.x_ary.x_dimen[3] = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
fb3be09b 604#endif
0f268757 605 }
6f715d66
SC
606 in->x_sym.x_fcnary.x_fcn.x_lnnoptr = GET_FCN_LNNOPTR(abfd, ext);
607 in->x_sym.x_fcnary.x_fcn.x_endndx.l = GET_FCN_ENDNDX(abfd, ext);
608
0f268757 609 if (ISFCN(type)) {
41f50af0 610 in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
0f268757
SC
611 }
612 else {
6f715d66
SC
613 in->x_sym.x_misc.x_lnsz.x_lnno = GET_LNSZ_LNNO(abfd, ext);
614 in->x_sym.x_misc.x_lnsz.x_size = GET_LNSZ_SIZE(abfd, ext);
0f268757
SC
615 }
616 }
617}
618
0d740984
SC
619static unsigned int
620DEFUN(coff_swap_aux_out,(abfd, inp, type, class, extp),
0f268757 621 bfd *abfd AND
0d740984
SC
622 PTR inp AND
623 int type AND
624 int class AND
625 PTR extp)
0f268757 626{
0d740984
SC
627 union internal_auxent *in = (union internal_auxent *)inp;
628 AUXENT *ext = (AUXENT *)extp;
0f268757
SC
629 switch (class) {
630 case C_FILE:
631 if (in->x_file.x_fname[0] == 0) {
cbdc7909 632 PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
0d740984
SC
633 PUTWORD(abfd,
634 in->x_file.x_n.x_offset,
635 (bfd_byte *) ext->x_file.x_n.x_offset);
0f268757 636 }
6f715d66 637 else {
fb3be09b 638#if FILNMLEN != E_FILNMLEN
0d740984 639 -> Error, we need to cope with truncating or extending FILNMLEN!;
fb3be09b
JG
640#else
641 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
642#endif
cbdc7909 643 }
0f268757 644 break;
6d7c88c3
JG
645
646#ifdef RS6000COFF_C
647 /* RS/6000 "csect" auxents */
648 case C_EXT:
649 case C_HIDEXT:
650 PUTWORD (abfd, in->x_csect.x_scnlen, ext->x_csect.x_scnlen);
651 PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
652 PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
653 /* We don't have to hack bitfields in x_smtyp because it's defined by
654 shifts-and-ands, which are equivalent on all byte orders. */
655 PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
656 PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
657 PUTWORD (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
658 PUTHALF (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
659 break;
660#endif
661
0f268757
SC
662 case C_STAT:
663#ifdef C_LEAFSTAT
664 case C_LEAFSTAT:
665#endif
666 case C_HIDDEN:
667 if (type == T_NULL) {
6f715d66
SC
668 PUT_SCN_SCNLEN(abfd, in->x_scn.x_scnlen, ext);
669 PUT_SCN_NRELOC(abfd, in->x_scn.x_nreloc, ext);
670 PUT_SCN_NLINNO(abfd, in->x_scn.x_nlinno, ext);
0f268757
SC
671 break;
672 }
673 default:
41f50af0 674 PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
6f715d66 675#ifndef NO_TVNDX
41f50af0 676 PUTWORD(abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
6f715d66 677#endif
0f268757 678
0f268757 679 if (ISFCN(type)) {
41f50af0 680 PUTWORD(abfd, in->x_sym.x_misc.x_fsize, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
6f715d66
SC
681 PUT_FCN_LNNOPTR(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
682 PUT_FCN_ENDNDX(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
0f268757
SC
683 }
684 else {
6f715d66
SC
685
686 if (ISARY(type) || class == C_BLOCK) {
fb3be09b 687#if DIMNUM != E_DIMNUM
0d740984 688 -> Error, we need to cope with truncating or extending DIMNUM!;
fb3be09b 689#else
41f50af0
SC
690 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
691 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
692 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
693 bfd_h_put_16(abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3], (bfd_byte *)ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
fb3be09b 694#endif
6f715d66 695 }
0d740984
SC
696 PUT_LNSZ_LNNO(abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext);
697 PUT_LNSZ_SIZE(abfd, in->x_sym.x_misc.x_lnsz.x_size, ext);
6f715d66
SC
698
699 PUT_FCN_LNNOPTR(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, ext);
700 PUT_FCN_ENDNDX(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, ext);
701
702
0f268757
SC
703 }
704 }
0d740984 705return sizeof(AUXENT);
0f268757
SC
706}
707
7a8b18b6
SC
708#endif /* NO_COFF_SYMBOLS */
709
710#ifndef NO_COFF_LINENOS
711
6f715d66
SC
712static void
713DEFUN(coff_swap_lineno_in,(abfd, ext1, in1),
0f268757 714 bfd *abfd AND
6f715d66
SC
715 PTR ext1 AND
716 PTR in1)
0f268757 717{
6f715d66
SC
718 LINENO *ext = (LINENO *)ext1;
719 struct internal_lineno *in = (struct internal_lineno *)in1;
720
41f50af0 721 in->l_addr.l_symndx = bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
85e0c721 722 in->l_lnno = GET_LINENO_LNNO(abfd, ext);
0f268757
SC
723}
724
0d740984
SC
725static unsigned int
726DEFUN(coff_swap_lineno_out,(abfd, inp, outp),
727 bfd *abfd AND
728 PTR inp AND
729 PTR outp)
0f268757 730{
0d740984
SC
731 struct internal_lineno *in = (struct internal_lineno *)inp;
732 struct external_lineno *ext = (struct external_lineno *)outp;
85e0c721
SC
733 PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
734 ext->l_addr.l_symndx);
735
736 PUT_LINENO_LNNO (abfd, in->l_lnno, ext);
0d740984 737 return sizeof(struct external_lineno);
0f268757
SC
738}
739
7a8b18b6 740#endif /* NO_COFF_LINENOS */
0f268757
SC
741
742
cbdc7909 743static void
6f715d66 744DEFUN(bfd_swap_aouthdr_in,(abfd, aouthdr_ext1, aouthdr_int1),
0f268757 745 bfd *abfd AND
6f715d66
SC
746 PTR aouthdr_ext1 AND
747 PTR aouthdr_int1)
0f268757 748{
6f715d66
SC
749 AOUTHDR *aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
750 struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
751
41f50af0
SC
752 aouthdr_int->magic = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->magic);
753 aouthdr_int->vstamp = bfd_h_get_16(abfd, (bfd_byte *) aouthdr_ext->vstamp);
754 aouthdr_int->tsize = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->tsize);
755 aouthdr_int->dsize = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->dsize);
756 aouthdr_int->bsize = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->bsize);
757 aouthdr_int->entry = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->entry);
758 aouthdr_int->text_start = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->text_start);
759 aouthdr_int->data_start = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->data_start);
0f268757 760#ifdef I960
41f50af0 761 aouthdr_int->tagentries = bfd_h_get_32(abfd, (bfd_byte *) aouthdr_ext->tagentries);
0f268757 762#endif
cbdc7909
JG
763
764#ifdef RS6000COFF_C
765 aouthdr_int->o_toc = bfd_h_get_32(abfd, aouthdr_ext->o_toc);
766 aouthdr_int->o_snentry = bfd_h_get_16(abfd, aouthdr_ext->o_snentry);
767 aouthdr_int->o_sntext = bfd_h_get_16(abfd, aouthdr_ext->o_sntext);
768 aouthdr_int->o_sndata = bfd_h_get_16(abfd, aouthdr_ext->o_sndata);
769 aouthdr_int->o_sntoc = bfd_h_get_16(abfd, aouthdr_ext->o_sntoc);
770 aouthdr_int->o_snloader = bfd_h_get_16(abfd, aouthdr_ext->o_snloader);
771 aouthdr_int->o_snbss = bfd_h_get_16(abfd, aouthdr_ext->o_snbss);
772 aouthdr_int->o_algntext = bfd_h_get_16(abfd, aouthdr_ext->o_algntext);
773 aouthdr_int->o_algndata = bfd_h_get_16(abfd, aouthdr_ext->o_algndata);
774 aouthdr_int->o_modtype = bfd_h_get_16(abfd, aouthdr_ext->o_modtype);
775 aouthdr_int->o_maxstack = bfd_h_get_32(abfd, aouthdr_ext->o_maxstack);
776#endif
0f268757
SC
777}
778
0d740984
SC
779static unsigned int
780DEFUN(coff_swap_aouthdr_out,(abfd, in, out),
781 bfd *abfd AND
782 PTR in AND
783 PTR out)
0f268757 784{
0d740984
SC
785 struct internal_aouthdr *aouthdr_in = (struct internal_aouthdr *)in;
786 AOUTHDR *aouthdr_out = (AOUTHDR *)out;
41f50af0
SC
787 bfd_h_put_16(abfd, aouthdr_in->magic, (bfd_byte *) aouthdr_out->magic);
788 bfd_h_put_16(abfd, aouthdr_in->vstamp, (bfd_byte *) aouthdr_out->vstamp);
789 bfd_h_put_32(abfd, aouthdr_in->tsize, (bfd_byte *) aouthdr_out->tsize);
790 bfd_h_put_32(abfd, aouthdr_in->dsize, (bfd_byte *) aouthdr_out->dsize);
791 bfd_h_put_32(abfd, aouthdr_in->bsize, (bfd_byte *) aouthdr_out->bsize);
792 bfd_h_put_32(abfd, aouthdr_in->entry, (bfd_byte *) aouthdr_out->entry);
0d740984
SC
793 bfd_h_put_32(abfd, aouthdr_in->text_start,
794 (bfd_byte *) aouthdr_out->text_start);
41f50af0 795 bfd_h_put_32(abfd, aouthdr_in->data_start, (bfd_byte *) aouthdr_out->data_start);
0f268757 796#ifdef I960
41f50af0 797 bfd_h_put_32(abfd, aouthdr_in->tagentries, (bfd_byte *) aouthdr_out->tagentries);
0f268757 798#endif
0d740984 799 return sizeof(AOUTHDR);
0f268757
SC
800}
801
cbdc7909 802static void
2700c3c7 803DEFUN(coff_swap_scnhdr_in,(abfd, scnhdr_ext, scnhdr_int),
0f268757
SC
804 bfd *abfd AND
805 SCNHDR *scnhdr_ext AND
806 struct internal_scnhdr *scnhdr_int)
807{
808 memcpy(scnhdr_int->s_name, scnhdr_ext->s_name, sizeof(scnhdr_int->s_name));
41f50af0
SC
809 scnhdr_int->s_vaddr = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_vaddr);
810 scnhdr_int->s_paddr = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_paddr);
811 scnhdr_int->s_size = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_size);
812 scnhdr_int->s_scnptr = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_scnptr);
813 scnhdr_int->s_relptr = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_relptr);
814 scnhdr_int->s_lnnoptr = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_lnnoptr);
815 scnhdr_int->s_flags = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_flags);
6f715d66 816#if defined(M88)
41f50af0
SC
817 scnhdr_int->s_nreloc = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
818 scnhdr_int->s_nlnno = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
6f715d66 819#else
41f50af0
SC
820 scnhdr_int->s_nreloc = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nreloc);
821 scnhdr_int->s_nlnno = bfd_h_get_16(abfd, (bfd_byte *) scnhdr_ext->s_nlnno);
6f715d66 822#endif
0f268757 823#ifdef I960
41f50af0 824 scnhdr_int->s_align = bfd_h_get_32(abfd, (bfd_byte *) scnhdr_ext->s_align);
0f268757
SC
825#endif
826}
827
cbdc7909 828static unsigned int
0d740984
SC
829DEFUN(coff_swap_scnhdr_out,(abfd, in, out),
830 bfd *abfd AND
831 PTR in AND
832 PTR out)
0f268757 833{
0d740984
SC
834 struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *)in;
835 SCNHDR *scnhdr_ext = (SCNHDR *)out;
0f268757 836 memcpy(scnhdr_ext->s_name, scnhdr_int->s_name, sizeof(scnhdr_int->s_name));
41f50af0
SC
837 PUTWORD(abfd, scnhdr_int->s_vaddr, (bfd_byte *) scnhdr_ext->s_vaddr);
838 PUTWORD(abfd, scnhdr_int->s_paddr, (bfd_byte *) scnhdr_ext->s_paddr);
839 PUTWORD(abfd, scnhdr_int->s_size, (bfd_byte *) scnhdr_ext->s_size);
840 PUTWORD(abfd, scnhdr_int->s_scnptr, (bfd_byte *) scnhdr_ext->s_scnptr);
841 PUTWORD(abfd, scnhdr_int->s_relptr, (bfd_byte *) scnhdr_ext->s_relptr);
842 PUTWORD(abfd, scnhdr_int->s_lnnoptr, (bfd_byte *) scnhdr_ext->s_lnnoptr);
2f8d9c1c 843 PUTWORD(abfd, scnhdr_int->s_flags, (bfd_byte *) scnhdr_ext->s_flags);
6f715d66 844#if defined(M88)
41f50af0 845 PUTWORD(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
41f50af0 846 PUTWORD(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
6f715d66 847#else
41f50af0 848 PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);
41f50af0 849 PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);
6f715d66
SC
850#endif
851
cbdc7909 852#if defined(I960)
41f50af0 853 PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);
0f268757 854#endif
0d740984 855 return sizeof(SCNHDR);
0f268757
SC
856}
857
6f715d66 858
0f268757
SC
859/*
860 initialize a section structure with information peculiar to this
861 particular implementation of coff
862*/
863
864static boolean
865DEFUN(coff_new_section_hook,(abfd_ignore, section_ignore),
866 bfd *abfd_ignore AND
867 asection *section_ignore)
868{
6f715d66 869 section_ignore->alignment_power = abfd_ignore->xvec->align_power_min;
0f268757
SC
870 return true;
871}
872
873/* Take a section header read from a coff file (in HOST byte order),
874 and make a BFD "section" out of it. */
875static boolean
876DEFUN(make_a_section_from_file,(abfd, hdr),
877 bfd *abfd AND
878 struct internal_scnhdr *hdr)
879{
880 asection *return_section;
881
882 {
883 /* Assorted wastage to null-terminate the name, thanks AT&T! */
884 char *name = bfd_alloc(abfd, sizeof (hdr->s_name)+1);
885 if (name == NULL) {
886 bfd_error = no_memory;
887 return false;
888 }
889 strncpy(name, (char *) &hdr->s_name[0], sizeof (hdr->s_name));
890 name[sizeof (hdr->s_name)] = 0;
891
892 return_section = bfd_make_section(abfd, name);
cbdc7909
JG
893 if (return_section == NULL)
894 return false;
0f268757
SC
895 }
896
897 /* s_paddr is presumed to be = to s_vaddr */
898#define assign(to, from) return_section->to = hdr->from
899 assign(vma, s_vaddr);
900 /* assign (vma, s_vaddr); */
901 assign(size, s_size);
902 assign(filepos, s_scnptr);
903 assign(rel_filepos, s_relptr);
904 assign(reloc_count, s_nreloc);
905#ifdef I960
906 {
907 /* FIXME, use a temp var rather than alignment_power */
908 assign(alignment_power, s_align);
909 {
910 unsigned int i;
911 for (i = 0; i < 32; i++) {
912 if ((1 << i) >= (int) (return_section->alignment_power)) {
913 return_section->alignment_power = i;
914 break;
915 }
916 }
917 }
918 }
919#endif
920 assign(line_filepos, s_lnnoptr);
921 /*
922 return_section->linesize = hdr->s_nlnno * sizeof (struct lineno);
923 */
924
0f268757
SC
925 return_section->lineno_count = hdr->s_nlnno;
926 return_section->userdata = NULL;
927 return_section->next = (asection *) NULL;
41f50af0
SC
928 return_section->flags = styp_to_sec_flags(hdr->s_flags);
929
0f268757
SC
930
931 if (hdr->s_nreloc != 0)
932 return_section->flags |= SEC_RELOC;
41f50af0 933 /* FIXME: should this check 'hdr->s_size > 0' */
0f268757
SC
934 if (hdr->s_scnptr != 0)
935 return_section->flags |= SEC_HAS_CONTENTS;
936 return true;
937}
938static boolean
939DEFUN(coff_mkobject,(abfd),
940 bfd *abfd)
941{
942 set_tdata (abfd, bfd_zalloc (abfd,sizeof(coff_data_type)));
943 if (coff_data(abfd) == 0) {
944 bfd_error = no_memory;
945 return false;
946 }
947 coff_data(abfd)->relocbase = 0;
948 return true;
949}
950
951static
952bfd_target *
953DEFUN(coff_real_object_p,(abfd, nscns, internal_f, internal_a),
954 bfd *abfd AND
955 unsigned nscns AND
956 struct internal_filehdr *internal_f AND
957 struct internal_aouthdr *internal_a)
958{
959 coff_data_type *coff;
0d740984
SC
960 enum bfd_architecture arch;
961 long machine;
0f268757
SC
962 size_t readsize; /* length of file_info */
963 SCNHDR *external_sections;
cbdc7909 964
0f268757
SC
965 /* Build a play area */
966 if (coff_mkobject(abfd) != true)
967 return 0;
968 coff = coff_data(abfd);
cbdc7909
JG
969
970
0f268757 971 external_sections = (SCNHDR *)bfd_alloc(abfd, readsize = (nscns * SCNHSZ));
cbdc7909 972
0f268757
SC
973 if (bfd_read((PTR)external_sections, 1, readsize, abfd) != readsize) {
974 goto fail;
975 }
cbdc7909
JG
976
977
0f268757
SC
978 /* Now copy data as required; construct all asections etc */
979 coff->symbol_index_slew = 0;
980 coff->relocbase =0;
981 coff->raw_syment_count = 0;
982 coff->raw_linenos = 0;
983 coff->raw_syments = 0;
984 coff->sym_filepos =0;
985 coff->flags = internal_f->f_flags;
986 if (nscns != 0) {
987 unsigned int i;
988 for (i = 0; i < nscns; i++) {
989 struct internal_scnhdr tmp;
2700c3c7 990 coff_swap_scnhdr_in(abfd, external_sections + i, &tmp);
0f268757
SC
991 make_a_section_from_file(abfd,&tmp);
992 }
993 }
994 /* Determine the machine architecture and type. */
0d740984 995machine = 0;
0f268757 996 switch (internal_f->f_magic) {
20fdc627
SC
997#ifdef I386MAGIC
998 case I386MAGIC:
0d740984
SC
999 arch = bfd_arch_i386;
1000 machine = 0;
20fdc627
SC
1001 break;
1002#endif
cbdc7909
JG
1003
1004#ifdef A29K_MAGIC_BIG
41f50af0
SC
1005 case A29K_MAGIC_BIG:
1006 case A29K_MAGIC_LITTLE:
0d740984
SC
1007 arch = bfd_arch_a29k;
1008 machine = 0;
41f50af0
SC
1009 break;
1010#endif
cbdc7909 1011
0f268757 1012#ifdef MIPS
20fdc627
SC
1013 case MIPS_MAGIC_1:
1014 case MIPS_MAGIC_2:
1015 case MIPS_MAGIC_3:
0d740984
SC
1016 arch = bfd_arch_mips;
1017 machine = 0;
0f268757
SC
1018 break;
1019#endif
cbdc7909 1020
0f268757
SC
1021#ifdef MC68MAGIC
1022 case MC68MAGIC:
1023 case M68MAGIC:
0d740984
SC
1024 arch = bfd_arch_m68k;
1025 machine = 68020;
0f268757
SC
1026 break;
1027#endif
1028#ifdef MC88MAGIC
1029 case MC88MAGIC:
1030 case MC88DMAGIC:
1031 case MC88OMAGIC:
0d740984
SC
1032 arch = bfd_arch_m88k;
1033 machine = 88100;
0f268757
SC
1034 break;
1035#endif
1036#ifdef I960
1037#ifdef I960ROMAGIC
1038 case I960ROMAGIC:
1039 case I960RWMAGIC:
0d740984 1040 arch = bfd_arch_i960;
cbdc7909 1041 switch (F_I960TYPE & internal_f->f_flags)
0f268757
SC
1042 {
1043 default:
1044 case F_I960CORE:
0d740984 1045 machine = bfd_mach_i960_core;
0f268757
SC
1046 break;
1047 case F_I960KB:
0d740984 1048 machine = bfd_mach_i960_kb_sb;
0f268757 1049 break;
0d740984
SC
1050 case F_I960MC:
1051 machine = bfd_mach_i960_mc;
0f268757
SC
1052 break;
1053 case F_I960XA:
0d740984 1054 machine = bfd_mach_i960_xa;
0f268757
SC
1055 break;
1056 case F_I960CA:
0d740984 1057 machine = bfd_mach_i960_ca;
0f268757
SC
1058 break;
1059 case F_I960KA:
0d740984 1060 machine = bfd_mach_i960_ka_sa;
0f268757 1061 break;
0f268757
SC
1062 }
1063 break;
1064#endif
1065#endif
cbdc7909
JG
1066
1067#ifdef U802ROMAGIC
1068 case U802ROMAGIC:
1069 case U802WRMAGIC:
1070 case U802TOCMAGIC:
1071 arch = bfd_arch_rs6000;
1072 machine = 6000;
1073 break;
1074#endif
1075
3b4f1a5d
SC
1076#ifdef H8300MAGIC
1077 case H8300MAGIC:
1078 arch = bfd_arch_h8300;
1079 machine = 0;
1080 break;
1081#endif
cbdc7909 1082
0f268757 1083 default: /* Unreadable input file type */
0d740984 1084 arch = bfd_arch_obscure;
0f268757
SC
1085 break;
1086 }
cbdc7909 1087
0d740984 1088 bfd_default_set_arch_mach(abfd, arch, machine);
0f268757
SC
1089 if (!(internal_f->f_flags & F_RELFLG))
1090 abfd->flags |= HAS_RELOC;
1091 if ((internal_f->f_flags & F_EXEC))
1092 abfd->flags |= EXEC_P;
1093 if (!(internal_f->f_flags & F_LNNO))
1094 abfd->flags |= HAS_LINENO;
1095 if (!(internal_f->f_flags & F_LSYMS))
1096 abfd->flags |= HAS_LOCALS;
cbdc7909
JG
1097
1098
0f268757
SC
1099 bfd_get_symcount(abfd) = internal_f->f_nsyms;
1100 if (internal_f->f_nsyms)
1101 abfd->flags |= HAS_SYMS;
cbdc7909 1102
0f268757 1103 coff->sym_filepos = internal_f->f_symptr;
cbdc7909 1104
fb3be09b 1105 /* These members communicate important constants about the symbol table
0d740984
SC
1106 to GDB's symbol-reading code. These `constants' unfortunately vary
1107 from coff implementation to implementation... */
fb3be09b
JG
1108#ifndef NO_COFF_SYMBOLS
1109 coff->local_n_btmask = N_BTMASK;
1110 coff->local_n_btshft = N_BTSHFT;
1111 coff->local_n_tmask = N_TMASK;
1112 coff->local_n_tshift = N_TSHIFT;
1113 coff->local_symesz = SYMESZ;
1114 coff->local_auxesz = AUXESZ;
1115 coff->local_linesz = LINESZ;
1116#endif
cbdc7909 1117
0f268757
SC
1118 coff->symbols = (coff_symbol_type *) NULL;
1119 bfd_get_start_address(abfd) = internal_f->f_opthdr ? internal_a->entry : 0;
cbdc7909 1120
0f268757
SC
1121 return abfd->xvec;
1122 fail:
1123 bfd_release(abfd, coff);
1124 return (bfd_target *)NULL;
1125}
1126
1127static bfd_target *
1128DEFUN(coff_object_p,(abfd),
1129 bfd *abfd)
6f715d66
SC
1130{
1131 int nscns;
1132 FILHDR filehdr;
1133 AOUTHDR opthdr;
1134 struct internal_filehdr internal_f;
1135 struct internal_aouthdr internal_a;
cbdc7909 1136
6f715d66 1137 bfd_error = system_call_error;
cbdc7909 1138
6f715d66
SC
1139 /* figure out how much to read */
1140 if (bfd_read((PTR) &filehdr, 1, FILHSZ, abfd) != FILHSZ)
1141 return 0;
cbdc7909 1142
6f715d66 1143 bfd_swap_filehdr_in(abfd, &filehdr, &internal_f);
cbdc7909 1144
6f715d66
SC
1145 if (BADMAG(internal_f)) {
1146 bfd_error = wrong_format;
1147 return 0;
1148 }
1149 nscns =internal_f.f_nscns;
cbdc7909 1150
6f715d66
SC
1151 if (internal_f.f_opthdr) {
1152 if (bfd_read((PTR) &opthdr, 1,AOUTSZ, abfd) != AOUTSZ) {
1153 return 0;
0f268757 1154 }
7d003262 1155 bfd_swap_aouthdr_in(abfd, (char *)&opthdr, (char *)&internal_a);
6f715d66 1156 }
cbdc7909 1157
6f715d66
SC
1158 /* Seek past the opt hdr stuff */
1159 bfd_seek(abfd, internal_f.f_opthdr + FILHSZ, SEEK_SET);
cbdc7909 1160
6f715d66
SC
1161 /* if the optional header is NULL or not the correct size then
1162 quit; the only difference I can see between m88k dgux headers (MC88DMAGIC)
1163 and Intel 960 readwrite headers (I960WRMAGIC) is that the
1164 optional header is of a different size.
cbdc7909 1165
6f715d66
SC
1166 But the mips keeps extra stuff in it's opthdr, so dont check
1167 when doing that
1168 */
cbdc7909 1169
0d740984 1170#if defined(M88) || defined(I960)
6f715d66
SC
1171 if (internal_f.f_opthdr != 0 && AOUTSZ != internal_f.f_opthdr)
1172 return (bfd_target *)NULL;
0f268757 1173#endif
cbdc7909 1174
6f715d66
SC
1175 return coff_real_object_p(abfd, nscns, &internal_f, &internal_a);
1176}
0f268757
SC
1177
1178
1179
7a8b18b6 1180#ifndef NO_COFF_LINENOS
0f268757 1181
cbdc7909 1182static void
0f268757
SC
1183DEFUN(coff_count_linenumbers,(abfd),
1184 bfd *abfd)
6f715d66
SC
1185{
1186 unsigned int limit = bfd_get_symcount(abfd);
1187 unsigned int i;
1188 asymbol **p;
1189 {
1190 asection *s = abfd->sections->output_section;
1191 while (s) {
1192 BFD_ASSERT(s->lineno_count == 0);
1193 s = s->next;
20fdc627 1194 }
6f715d66 1195 }
cbdc7909
JG
1196
1197
6f715d66
SC
1198 for (p = abfd->outsymbols, i = 0; i < limit; i++, p++) {
1199 asymbol *q_maybe = *p;
0d740984 1200 if (q_maybe->the_bfd->xvec->flavour == bfd_target_coff_flavour) {
6f715d66
SC
1201 coff_symbol_type *q = coffsymbol(q_maybe);
1202 if (q->lineno) {
1203 /*
1204 This symbol has a linenumber, increment the owning
1205 section's linenumber count
1206 */
1207 alent *l = q->lineno;
1208 q->symbol.section->output_section->lineno_count++;
1209 l++;
1210 while (l->line_number) {
20fdc627
SC
1211 q->symbol.section->output_section->lineno_count++;
1212 l++;
0f268757 1213 }
20fdc627 1214 }
0f268757 1215 }
20fdc627 1216 }
6f715d66 1217}
0f268757 1218
7a8b18b6
SC
1219#endif /* NO_COFF_LINENOS */
1220
1221#ifndef NO_COFF_SYMBOLS
1222
cbdc7909 1223/*
0d740984
SC
1224 Takes a bfd and a symbol, returns a pointer to the coff specific area
1225 of the symbol if there is one.
1226 */
7a8b18b6 1227static coff_symbol_type *
fb3be09b
JG
1228DEFUN(coff_symbol_from,(ignore_abfd, symbol),
1229 bfd *ignore_abfd AND
7a8b18b6
SC
1230 asymbol *symbol)
1231{
cbdc7909 1232 if (symbol->the_bfd->xvec->flavour != bfd_target_coff_flavour)
7a8b18b6 1233 return (coff_symbol_type *)NULL;
cbdc7909 1234
7a8b18b6
SC
1235 if (symbol->the_bfd->tdata == (PTR)NULL)
1236 return (coff_symbol_type *)NULL;
cbdc7909 1237
7a8b18b6
SC
1238 return (coff_symbol_type *) symbol;
1239}
1240
0f268757 1241
0f268757 1242
6f715d66
SC
1243static void
1244DEFUN(fixup_symbol_value,(coff_symbol_ptr, syment),
1245coff_symbol_type *coff_symbol_ptr AND
1246struct internal_syment *syment)
1247{
0f268757 1248
6f715d66
SC
1249 /* Normalize the symbol flags */
1250 if (coff_symbol_ptr->symbol.flags & BSF_FORT_COMM) {
1251 /* a common symbol is undefined with a value */
1252 syment->n_scnum = N_UNDEF;
1253 syment->n_value = coff_symbol_ptr->symbol.value;
1254 }
1255 else if (coff_symbol_ptr->symbol.flags & BSF_DEBUGGING) {
1256 syment->n_value = coff_symbol_ptr->symbol.value;
1257 }
1258 else if (coff_symbol_ptr->symbol.flags & BSF_UNDEFINED) {
1259 syment->n_scnum = N_UNDEF;
1260 syment->n_value = 0;
cbdc7909 1261 }
6f715d66
SC
1262 else if (coff_symbol_ptr->symbol.flags & BSF_ABSOLUTE) {
1263 syment->n_scnum = N_ABS;
1264 syment->n_value = coff_symbol_ptr->symbol.value;
cbdc7909 1265 }
6f715d66 1266 else {
f58809fd 1267 if (coff_symbol_ptr->symbol.section) {
cbdc7909 1268 syment->n_scnum =
f58809fd 1269 coff_symbol_ptr->symbol.section->output_section->index+1;
cbdc7909
JG
1270
1271 syment->n_value =
f58809fd 1272 coff_symbol_ptr->symbol.value +
6f715d66 1273 coff_symbol_ptr->symbol.section->output_offset +
f58809fd
SC
1274 coff_symbol_ptr->symbol.section->output_section->vma;
1275 }
1276 else {
1277 /* This can happen, but I don't know why yet (steve@cygnus.com) */
1278 syment->n_scnum = N_ABS;
cbdc7909 1279 syment->n_value = coff_symbol_ptr->symbol.value;
f58809fd 1280 }
6f715d66
SC
1281 }
1282}
0f268757 1283
6f715d66 1284/* run through all the symbols in the symbol table and work out what
cbdc7909 1285 their indexes into the symbol table will be when output
0f268757 1286
6f715d66
SC
1287 Coff requires that each C_FILE symbol points to the next one in the
1288 chain, and that the last one points to the first external symbol. We
1289 do that here too.
0f268757 1290
6f715d66
SC
1291*/
1292static void
1293DEFUN(coff_renumber_symbols,(bfd_ptr),
1294 bfd *bfd_ptr)
1295{
1296 unsigned int symbol_count = bfd_get_symcount(bfd_ptr);
1297 asymbol **symbol_ptr_ptr = bfd_ptr->outsymbols;
1298 unsigned int native_index = 0;
1299 struct internal_syment *last_file = (struct internal_syment *)NULL;
1300 unsigned int symbol_index;
cbdc7909 1301 for (symbol_index = 0; symbol_index < symbol_count; symbol_index++)
6f715d66
SC
1302 {
1303 coff_symbol_type *coff_symbol_ptr = coff_symbol_from(bfd_ptr, symbol_ptr_ptr[symbol_index]);
1304 if (coff_symbol_ptr && coff_symbol_ptr->native) {
1305 combined_entry_type *s = coff_symbol_ptr->native;
1306 int i;
0f268757 1307
cbdc7909 1308 if (s->u.syment.n_sclass == C_FILE)
6f715d66
SC
1309 {
1310 if (last_file != (struct internal_syment *)NULL) {
1311 last_file->n_value = native_index;
1312 }
1313 last_file = &(s->u.syment);
1314 }
1315 else {
0f268757 1316
6f715d66
SC
1317 /* Modify the symbol values according to their section and
1318 type */
0f268757 1319
6f715d66
SC
1320 fixup_symbol_value(coff_symbol_ptr, &(s->u.syment));
1321 }
1322 for (i = 0; i < s->u.syment.n_numaux + 1; i++) {
1323 s[i].offset = native_index ++;
1324 }
1325 }
1326 else {
1327 native_index++;
1328 }
1329 }
1330}
0f268757 1331
0f268757 1332
41f50af0 1333/*
6f715d66
SC
1334 Run thorough the symbol table again, and fix it so that all pointers to
1335 entries are changed to the entries' index in the output symbol table.
0f268757 1336
6f715d66 1337*/
cbdc7909 1338static void
0f268757
SC
1339DEFUN(coff_mangle_symbols,(bfd_ptr),
1340 bfd *bfd_ptr)
6f715d66
SC
1341{
1342 unsigned int symbol_count = bfd_get_symcount(bfd_ptr);
1343 asymbol **symbol_ptr_ptr = bfd_ptr->outsymbols;
6f715d66
SC
1344 unsigned int symbol_index;
1345
cbdc7909 1346 for (symbol_index = 0; symbol_index < symbol_count; symbol_index++)
6f715d66 1347 {
cbdc7909
JG
1348 coff_symbol_type *coff_symbol_ptr =
1349 coff_symbol_from(bfd_ptr, symbol_ptr_ptr[symbol_index]);
1350
1351 if (coff_symbol_ptr && coff_symbol_ptr->native) {
6f715d66
SC
1352 int i;
1353 combined_entry_type *s = coff_symbol_ptr->native;
1354
6f715d66
SC
1355 for (i = 0; i < s->u.syment.n_numaux ; i++) {
1356 combined_entry_type *a = s + i + 1;
1357 if (a->fix_tag) {
cbdc7909
JG
1358 a->u.auxent.x_sym.x_tagndx.l =
1359 a->u.auxent.x_sym.x_tagndx.p->offset;
6f715d66
SC
1360 }
1361 if (a->fix_end) {
1362 a->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.l =
1363 a->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p->offset;
1364 }
1365
1366 }
1367 }
1368 }
1369}
1370
cbdc7909 1371static int string_size;
6f715d66 1372static void
fb3be09b
JG
1373DEFUN(coff_fix_symbol_name,(ignore_abfd, symbol, native),
1374 bfd *ignore_abfd AND
6f715d66
SC
1375 asymbol *symbol AND
1376 combined_entry_type *native)
1377{
1378 unsigned int name_length;
1379 union internal_auxent *auxent;
41f50af0 1380 char * name = ( char *)(symbol->name);
6f715d66
SC
1381
1382 if (name == (char *) NULL) {
fb3be09b
JG
1383 /* coff symbols always have names, so we'll make one up */
1384 symbol->name = "strange";
41f50af0 1385 name = (char *)symbol->name;
6f715d66
SC
1386 }
1387 name_length = strlen(name);
cbdc7909 1388
6f715d66
SC
1389 if (native->u.syment.n_sclass == C_FILE) {
1390 strncpy(native->u.syment._n._n_name, ".file", SYMNMLEN);
1391 auxent = &(native+1)->u.auxent;
cbdc7909 1392
6f715d66
SC
1393#ifdef COFF_LONG_FILENAMES
1394 if (name_length <= FILNMLEN) {
1395 strncpy(auxent->x_file.x_fname, name, FILNMLEN);
1396 }
1397 else {
1398 auxent->x_file.x_n.x_offset = string_size + 4;
1399 auxent->x_file.x_n.x_zeroes = 0;
1400 string_size += name_length + 1;
1401 }
1402#else
1403 strncpy(auxent->x_file.x_fname, name, FILNMLEN);
1404 if (name_length > FILNMLEN) {
1405 name[FILNMLEN] = '\0';
1406 }
1407#endif
1408 }
1409 else
1410 { /* NOT A C_FILE SYMBOL */
1411 if (name_length <= SYMNMLEN) {
1412 /* This name will fit into the symbol neatly */
1413 strncpy(native->u.syment._n._n_name, symbol->name, SYMNMLEN);
1414 }
1415 else {
1416 native->u.syment._n._n_n._n_offset = string_size + 4;
1417 native->u.syment._n._n_n._n_zeroes = 0;
1418 string_size += name_length + 1;
1419 }
1420 }
1421}
1422
1423
1424
cbdc7909 1425static unsigned int
6f715d66
SC
1426DEFUN(coff_write_symbol,(abfd, symbol, native, written),
1427bfd *abfd AND
1428asymbol *symbol AND
1429combined_entry_type *native AND
1430unsigned int written)
1431{
1432 unsigned int numaux = native->u.syment.n_numaux;
1433 int type = native->u.syment.n_type;
1434 int class = native->u.syment.n_sclass;
1435 SYMENT buf;
1436 unsigned int j;
1437
1438 coff_fix_symbol_name(abfd, symbol, native);
1439 coff_swap_sym_out(abfd, &native->u.syment, &buf);
1440 bfd_write((PTR)& buf, 1, SYMESZ, abfd);
cbdc7909 1441 for (j = 0; j != native->u.syment.n_numaux; j++)
6f715d66
SC
1442 {
1443 AUXENT buf1;
f58809fd 1444 bzero((PTR)&buf, AUXESZ);
6f715d66
SC
1445 coff_swap_aux_out(abfd,
1446 &( (native + j + 1)->u.auxent), type, class, &buf1);
1447 bfd_write((PTR) (&buf1), 1, AUXESZ, abfd);
1448 }
1449 /*
1450 Reuse somewhere in the symbol to keep the index
1451 */
1452 set_index(symbol, written);
1453 return written + 1 + numaux;
1454}
1455
1456
1457static unsigned int
1458DEFUN(coff_write_alien_symbol,(abfd, symbol, written),
1459 bfd *abfd AND
1460 asymbol *symbol AND
1461 unsigned int written)
1462{
1463 /*
1464 This symbol has been created by the loader, or come from a non
1465 coff format. It has no native element to inherit, make our
1466 own
1467 */
1468 combined_entry_type *native;
1469 combined_entry_type dummy;
1470 native = &dummy;
1471 native->u.syment.n_type = T_NULL;
1472#ifdef I960
1473 native->u.syment.n_flags = 0;
1474#endif
1475 if (symbol->flags & BSF_ABSOLUTE) {
1476 native->u.syment.n_scnum = N_ABS;
1477 native->u.syment.n_value = symbol->value;
1478 }
1479 else if (symbol->flags & (BSF_UNDEFINED | BSF_FORT_COMM)) {
1480 native->u.syment.n_scnum = N_UNDEF;
1481 native->u.syment.n_value = symbol->value;
1482 }
1483 else if (symbol->flags & BSF_DEBUGGING) {
1484 /*
1485 remove name so it doesn't take up any space
1486 */
1487 symbol->name = "";
1488 }
1489 else {
1490 native->u.syment.n_scnum = symbol->section->output_section->index +
1491 1;
1492 native->u.syment.n_value = symbol->value +
1493 symbol->section->output_section->vma +
1494 symbol->section->output_offset;
1495#ifdef I960
1496 /* Copy the any flags from the the file hdr into the symbol */
1497 {
1498 coff_symbol_type *c = coff_symbol_from(abfd, symbol);
1499 if (c != (coff_symbol_type *)NULL) {
1500 native->u.syment.n_flags = c->symbol.the_bfd->flags;
1501 }
1502 }
1503#endif
1504 }
cbdc7909 1505
6f715d66
SC
1506#ifdef HASPAD1
1507 native->u.syment.pad1[0] = 0;
1508 native->u.syment.pad1[0] = 0;
1509#endif
cbdc7909 1510
6f715d66
SC
1511 native->u.syment.n_type = 0;
1512 if (symbol->flags & BSF_LOCAL)
1513 native->u.syment.n_sclass = C_STAT;
cbdc7909 1514 else
6f715d66
SC
1515 native->u.syment.n_sclass = C_EXT;
1516 native->u.syment.n_numaux = 0;
1517
1518 return coff_write_symbol(abfd, symbol, native, written);
1519}
1520
cbdc7909 1521static unsigned int
6f715d66
SC
1522DEFUN(coff_write_native_symbol,(abfd, symbol, written),
1523bfd *abfd AND
1524coff_symbol_type *symbol AND
1525unsigned int written)
1526{
1527 /*
1528 Does this symbol have an ascociated line number - if so then
1529 make it remember this symbol index. Also tag the auxent of
1530 this symbol to point to the right place in the lineno table
1531 */
1532 combined_entry_type *native = symbol->native;
1533
1534 alent *lineno = symbol->lineno;
1535
1536 if (lineno) {
1537 unsigned int count = 0;
1538 lineno[count].u.offset = written;
1539 if (native->u.syment.n_numaux) {
1540 union internal_auxent *a = &((native+1)->u.auxent);
cbdc7909
JG
1541
1542 a->x_sym.x_fcnary.x_fcn.x_lnnoptr =
6f715d66
SC
1543 symbol->symbol.section->output_section->moving_line_filepos;
1544 }
1545 /*
1546 And count and relocate all other linenumbers
1547 */
1548 count++;
1549 while (lineno[count].line_number) {
1550 lineno[count].u.offset +=
1551 symbol->symbol.section->output_section->vma +
1552 symbol->symbol.section->output_offset;
1553 count++;
1554 }
1555 symbol->symbol.section->output_section->moving_line_filepos +=
1556 count * LINESZ;
6f715d66
SC
1557 }
1558 return coff_write_symbol(abfd, &( symbol->symbol), native,written);
1559}
1560
cbdc7909 1561static void
0f268757 1562DEFUN(coff_write_symbols,(abfd),
6f715d66 1563 bfd *abfd)
0f268757
SC
1564{
1565 unsigned int i;
1566 unsigned int limit = bfd_get_symcount(abfd);
1567 unsigned int written = 0;
6f715d66 1568
0f268757 1569 asymbol **p;
6f715d66
SC
1570
1571 string_size = 0;
cbdc7909
JG
1572
1573
0f268757
SC
1574 /* Seek to the right place */
1575 bfd_seek(abfd, obj_sym_filepos(abfd), SEEK_SET);
cbdc7909 1576
0f268757 1577 /* Output all the symbols we have */
cbdc7909 1578
0f268757 1579 written = 0;
cbdc7909 1580 for (p = abfd->outsymbols, i = 0; i < limit; i++, p++)
0f268757 1581 {
6f715d66
SC
1582 asymbol *symbol = *p;
1583 coff_symbol_type *c_symbol = coff_symbol_from(abfd, symbol);
6f715d66
SC
1584
1585 if (c_symbol == (coff_symbol_type *) NULL ||
1586 c_symbol->native == (combined_entry_type *)NULL)
1587 {
1588 written = coff_write_alien_symbol(abfd, symbol, written);
0f268757 1589 }
6f715d66
SC
1590 else
1591 {
1592 written = coff_write_native_symbol(abfd, c_symbol, written);
1593 }
1594
0f268757 1595 }
6f715d66 1596
0f268757 1597 bfd_get_symcount(abfd) = written;
6f715d66 1598
0f268757 1599 /* Now write out strings */
cbdc7909
JG
1600
1601 if (string_size != 0)
6f715d66
SC
1602 {
1603 unsigned int size = string_size + 4;
fb3be09b
JG
1604 bfd_byte buffer[4];
1605
7a8b18b6
SC
1606 bfd_h_put_32(abfd, size, buffer);
1607 bfd_write((PTR) buffer, 1, sizeof(buffer), abfd);
cbdc7909
JG
1608 for (p = abfd->outsymbols, i = 0;
1609 i < limit;
1610 i++, p++)
6f715d66
SC
1611 {
1612 asymbol *q = *p;
1613 size_t name_length = strlen(q->name);
1614 int maxlen;
1615 coff_symbol_type* c_symbol = coff_symbol_from(abfd, q);
7a8b18b6
SC
1616 maxlen = ((c_symbol != NULL && c_symbol->native != NULL) &&
1617 (c_symbol->native->u.syment.n_sclass == C_FILE)) ?
6f715d66 1618 FILNMLEN : SYMNMLEN;
cbdc7909 1619
6f715d66
SC
1620 if (name_length > maxlen) {
1621 bfd_write((PTR) (q->name), 1, name_length + 1, abfd);
1622 }
1623 }
1624 }
0f268757
SC
1625 else {
1626 /* We would normally not write anything here, but we'll write
1627 out 4 so that any stupid coff reader which tries to read
1628 the string table even when there isn't one won't croak.
1629 */
cbdc7909 1630
0f268757
SC
1631 uint32e_type size = 4;
1632 size = size;
1633 bfd_write((PTR)&size, 1, sizeof(size), abfd);
cbdc7909 1634
0f268757 1635 }
0f268757 1636}
7a8b18b6 1637
6f715d66
SC
1638/*doc*
1639@subsubsection Writing Relocations
1640To write a relocations, all the back end does is step though the
1641canonical relocation table, and create an @code{internal_reloc}. The
1642symbol index to use is removed from the @code{offset} field in the
1643symbol table supplied, the address comes directly from the sum of the
1644section base address and the relocation offset and the type is dug
1645directly from the howto field.
1646
1647Then the @code{internal_reloc} is swapped into the shape of an
1648@code{external_reloc} and written out to disk.
1649*/
0f268757 1650
cbdc7909 1651static void
6f715d66
SC
1652DEFUN(coff_write_relocs,(abfd),
1653 bfd *abfd)
1654{
1655 asection *s;
1656 for (s = abfd->sections; s != (asection *) NULL; s = s->next) {
1657 unsigned int i;
1658 struct external_reloc dst;
cbdc7909 1659
6f715d66
SC
1660 arelent **p = s->orelocation;
1661 bfd_seek(abfd, s->rel_filepos, SEEK_SET);
1662 for (i = 0; i < s->reloc_count; i++) {
1663 struct internal_reloc n;
1664 arelent *q = p[i];
1665 memset((PTR)&n, 0, sizeof(n));
1666 n.r_vaddr = q->address + s->vma;
1667 if (q->sym_ptr_ptr) {
1668 n.r_symndx = get_index((*(q->sym_ptr_ptr)));
1669 }
0f268757 1670#ifdef SELECT_RELOC
6f715d66
SC
1671 /* Work out reloc type from what is required */
1672 SELECT_RELOC(n.r_type, q->howto);
0f268757 1673#else
6f715d66 1674 n.r_type = q->howto->type;
0f268757 1675#endif
0d740984 1676 coff_swap_reloc_out(abfd, &n, &dst);
6f715d66 1677 bfd_write((PTR) &n, 1, RELSZ, abfd);
0f268757
SC
1678 }
1679 }
6f715d66 1680}
fb3be09b 1681#endif /* NO_COFF_SYMBOLS */
0f268757 1682
7a8b18b6
SC
1683#ifndef NO_COFF_LINENOS
1684
cbdc7909 1685static void
0f268757
SC
1686DEFUN(coff_write_linenumbers,(abfd),
1687 bfd *abfd)
6f715d66
SC
1688{
1689 asection *s;
1690 for (s = abfd->sections; s != (asection *) NULL; s = s->next) {
1691 if (s->lineno_count) {
1692 asymbol **q = abfd->outsymbols;
1693 bfd_seek(abfd, s->line_filepos, SEEK_SET);
1694 /* Find all the linenumbers in this section */
1695 while (*q) {
1696 asymbol *p = *q;
1697 alent *l = BFD_SEND(p->the_bfd, _get_lineno, (p->the_bfd, p));
1698 if (l) {
1699 /* Found a linenumber entry, output */
1700 struct internal_lineno out;
1701 LINENO buff;
1702 memset( (PTR)&out, 0, sizeof(out));
1703 out.l_lnno = 0;
1704 out.l_addr.l_symndx = l->u.offset;
1705 coff_swap_lineno_out(abfd, &out, &buff);
1706 bfd_write((PTR) &buff, 1, LINESZ, abfd);
1707 l++;
1708 while (l->line_number) {
1709 out.l_lnno = l->line_number;
0f268757 1710 out.l_addr.l_symndx = l->u.offset;
2700c3c7 1711 coff_swap_lineno_out(abfd, &out, &buff);
0f268757
SC
1712 bfd_write((PTR) &buff, 1, LINESZ, abfd);
1713 l++;
0f268757 1714 }
0f268757 1715 }
6f715d66 1716 q++;
0f268757
SC
1717 }
1718 }
1719 }
6f715d66 1720}
0f268757 1721
7a8b18b6
SC
1722static alent *
1723DEFUN(coff_get_lineno,(ignore_abfd, symbol),
1724 bfd *ignore_abfd AND
1725 asymbol *symbol)
1726{
1727 return coffsymbol(symbol)->lineno;
1728}
1729
1730#endif /* NO_COFF_LINENOS */
0f268757
SC
1731
1732static asymbol *
1733coff_make_empty_symbol(abfd)
1734bfd *abfd;
6f715d66
SC
1735{
1736 coff_symbol_type *new = (coff_symbol_type *) bfd_alloc(abfd, sizeof(coff_symbol_type));
1737 if (new == NULL) {
1738 bfd_error = no_memory;
1739 return (NULL);
1740 } /* on error */
1741 new->native = 0;
1742 new->lineno = (alent *) NULL;
1743 new->symbol.the_bfd = abfd;
1744 return &new->symbol;
1745}
0f268757 1746
7a8b18b6
SC
1747#ifndef NO_COFF_SYMBOLS
1748
cbdc7909 1749static void
ee32cba6 1750DEFUN(coff_print_symbol,(ignore_abfd, filep, symbol, how),
6f715d66 1751 bfd *ignore_abfd AND
41f50af0 1752 PTR filep AND
6f715d66 1753 asymbol *symbol AND
0d740984 1754 bfd_print_symbol_type how)
6f715d66 1755{
41f50af0 1756 FILE *file = (FILE *)filep;
6f715d66 1757 switch (how) {
3b4f1a5d
SC
1758 case bfd_print_symbol_name:
1759 fprintf(file, "%s", symbol->name);
1760 break;
1761 case bfd_print_symbol_more:
1762 fprintf(file, "coff %lx %lx", (unsigned long) coffsymbol(symbol)->native,
1763 (unsigned long) coffsymbol(symbol)->lineno);
1764 break;
1765 case bfd_print_symbol_nm:
1766
1767 {
1768 CONST char *section_name = symbol->section == (asection *) NULL ?
1769 "*abs" : symbol->section->name;
1770 bfd_print_symbol_vandf((PTR) file, symbol);
1771
1772
1773 fprintf(file, " %-5s %s %s %s",
1774 section_name,
1775 coffsymbol(symbol)->native ? "n" : "g",
1776 coffsymbol(symbol)->lineno ? "l" : " ",
1777 symbol->name);
1778 }
1779
1780
1781 break;
1782 case bfd_print_symbol_all:
1783 /* Print out the symbols in a reasonable way */
1784 {
1785 CONST char *section_name = symbol->section == (asection *) NULL ?
1786 "*abs" : symbol->section->name;
1787
1788
1789 if (coffsymbol(symbol)->native)
6f715d66 1790 {
3b4f1a5d
SC
1791 unsigned int aux;
1792 combined_entry_type *combined = coffsymbol(symbol)->native;
1793 combined_entry_type *root = obj_raw_syments(ignore_abfd);
1794
1795fprintf(file,"[%3d]",
1796 combined - root);
1797
cbdc7909 1798
3b4f1a5d
SC
1799 fprintf(file, "(sc %2d)(fl%4x)(ty%3x)(sc%3d) nx(%d) %08x %s",
1800 combined->u.syment.n_scnum,
1801 combined->u.syment.n_flags,
1802 combined->u.syment.n_type,
1803 combined->u.syment.n_sclass,
1804 combined->u.syment.n_numaux,
1805 combined->u.syment.n_value,
1806 symbol->name
1807 );
1808 for (aux = 0; aux < combined->u.syment.n_numaux; aux++)
1809 {
1810 fprintf(file,"\n");
1811 switch (combined->u.syment.n_sclass) {
1812 case C_FILE:
1813 fprintf(file, "File ");
1814 break;
1815 default:
1816 fprintf(file, "AUX tv %x lnno %x size %x",
1817 combined[aux+1].u.auxent.x_sym.x_misc.x_lnsz.x_lnno,
1818 combined[aux+1].u.auxent.x_sym.x_misc.x_lnsz.x_size);
1819 break;
1820
1821 }
cbdc7909 1822
3b4f1a5d
SC
1823 }
1824
1825
1826
1827
1828 }
1829
1830 else {
1831 bfd_print_symbol_vandf((PTR) file, symbol);
1832 fprintf(file, " %-5s %s %s %s",
1833 section_name,
1834 coffsymbol(symbol)->native ? "n" : "g",
1835 coffsymbol(symbol)->lineno ? "l" : " ",
1836 symbol->name);
1837 }
1838
1839 }
1840
1841 }
6f715d66 1842}
0f268757 1843
7a8b18b6
SC
1844#endif /* NO_COFF_SYMBOLS */
1845
1846/* Set flags and magic number of a coff file from architecture and machine
1847 type. Result is true if we can represent the arch&type, false if not. */
0f268757 1848
0f268757 1849static boolean
6f715d66
SC
1850DEFUN(coff_set_flags,(abfd, magicp, flagsp),
1851 bfd *abfd AND
1852 unsigned *magicp AND
1853 unsigned short *flagsp)
1854{
0d740984 1855 switch (bfd_get_arch(abfd)) {
cbdc7909 1856
0f268757 1857#ifdef I960ROMAGIC
cbdc7909 1858
3b4f1a5d 1859 case bfd_arch_i960:
cbdc7909 1860
6f715d66
SC
1861 {
1862 unsigned flags;
1863 *magicp = I960ROMAGIC;
1864 /*
1865 ((bfd_get_file_flags(abfd) & WP_TEXT) ? I960ROMAGIC :
1866 I960RWMAGIC); FIXME???
1867 */
0d740984 1868 switch (bfd_get_mach(abfd)) {
6f715d66
SC
1869 case bfd_mach_i960_core:
1870 flags = F_I960CORE;
1871 break;
1872 case bfd_mach_i960_kb_sb:
1873 flags = F_I960KB;
1874 break;
1875 case bfd_mach_i960_mc:
1876 flags = F_I960MC;
1877 break;
1878 case bfd_mach_i960_xa:
1879 flags = F_I960XA;
1880 break;
1881 case bfd_mach_i960_ca:
1882 flags = F_I960CA;
1883 break;
1884 case bfd_mach_i960_ka_sa:
1885 flags = F_I960KA;
1886 break;
1887 default:
1888 return false;
0f268757 1889 }
6f715d66
SC
1890 *flagsp = flags;
1891 return true;
1892 }
1893 break;
0f268757
SC
1894#endif
1895#ifdef MIPS
6f715d66
SC
1896 case bfd_arch_mips:
1897 *magicp = MIPS_MAGIC_2;
1898 return true;
1899 break;
0f268757 1900#endif
20fdc627 1901#ifdef I386MAGIC
6f715d66
SC
1902 case bfd_arch_i386:
1903 *magicp = I386MAGIC;
1904 return true;
20fdc627 1905#endif
0f268757 1906#ifdef MC68MAGIC
6f715d66
SC
1907 case bfd_arch_m68k:
1908 *magicp = MC68MAGIC;
1909 return true;
0f268757 1910#endif
cbdc7909 1911
0f268757 1912#ifdef MC88MAGIC
3b4f1a5d
SC
1913 case bfd_arch_m88k:
1914 *magicp = MC88OMAGIC;
1915 return true;
1916 break;
1917#endif
1918#ifdef H8300MAGIC
1919 case bfd_arch_h8300:
1920 *magicp = H8300MAGIC;
1921 return true;
1922 break;
0f268757 1923#endif
41f50af0 1924#ifdef A29K_MAGIC_BIG
3b4f1a5d
SC
1925 case bfd_arch_a29k:
1926 if (abfd->xvec->byteorder_big_p)
1927 *magicp = A29K_MAGIC_BIG;
1928 else
1929 *magicp = A29K_MAGIC_LITTLE;
1930 return true;
1931 break;
41f50af0 1932#endif
cbdc7909
JG
1933
1934#ifdef U802TOCMAGIC
1935 case bfd_arch_rs6000:
1936 *magicp = U802TOCMAGIC;
1937 break;
1938#endif
1939
6f715d66 1940 default: /* Unknown architecture */
8acc9e05 1941 /* return false; -- fall through to "return false" below, to avoid
cbdc7909 1942 "statement never reached" errors on the one below. */
8acc9e05 1943 break;
0f268757 1944 }
cbdc7909 1945
6f715d66
SC
1946 return false;
1947}
0f268757
SC
1948
1949
1950static boolean
6f715d66
SC
1951DEFUN(coff_set_arch_mach,(abfd, arch, machine),
1952 bfd *abfd AND
1953 enum bfd_architecture arch AND
1954 unsigned long machine)
1955{
0d740984
SC
1956 unsigned dummy1;
1957 unsigned short dummy2;
1958 bfd_default_set_arch_mach(abfd, arch, machine);
1959
1960 if (arch != bfd_arch_unknown &&
1961 coff_set_flags(abfd, &dummy1, &dummy2) != true)
1962 return false; /* We can't represent this type */
1963 return true; /* We're easy ... */
1964}
0f268757
SC
1965
1966
1967/* Calculate the file position for each section. */
1968
cbdc7909 1969static void
6f715d66
SC
1970DEFUN(coff_compute_section_file_positions,(abfd),
1971 bfd *abfd)
1972{
85e0c721
SC
1973 asection *current;
1974 asection *previous = (asection *)NULL;
1975 file_ptr sofar = FILHSZ;
1976 file_ptr old_sofar;
1977 if (bfd_get_start_address(abfd))
1978 {
1979 /* A start address may have been added to the original file. In this
1980 case it will need an optional header to record it. */
1981 abfd->flags |= EXEC_P;
1982 }
1983
1984 if (abfd->flags & EXEC_P)
1985 sofar += AOUTSZ;
cbdc7909 1986
85e0c721
SC
1987 sofar += abfd->section_count * SCNHSZ;
1988 for (current = abfd->sections;
1989 current != (asection *)NULL;
1990 current = current->next) {
cbdc7909 1991
85e0c721
SC
1992 /* Only deal with sections which have contents */
1993 if (!(current->flags & SEC_HAS_CONTENTS))
1994 continue;
cbdc7909 1995
85e0c721
SC
1996 /* Align the sections in the file to the same boundary on
1997 which they are aligned in virtual memory. I960 doesn't
1998 do this (FIXME) so we can stay in sync with Intel. 960
1999 doesn't yet page from files... */
0f268757 2000#ifndef I960
85e0c721
SC
2001 {
2002 /* make sure this section is aligned on the right boundary - by
2003 padding the previous section up if necessary */
2004
2005 old_sofar= sofar;
8c4a1ace 2006 sofar = BFD_ALIGN(sofar, 1 << current->alignment_power);
85e0c721
SC
2007 if (previous != (asection *)NULL) {
2008 previous->size += sofar - old_sofar;
2009 }
2010 }
2011
0f268757 2012#endif
85e0c721
SC
2013 /* FIXME, in demand paged files, the low order bits of the file
2014 offset must match the low order bits of the virtual address.
2015 "Low order" is apparently implementation defined. Add code
2016 here to round sofar up to match the virtual address. */
cbdc7909 2017
85e0c721
SC
2018 current->filepos = sofar;
2019
2020 /* make sure that this section is of the right size too */
2021 old_sofar = sofar += current->size;
8c4a1ace 2022 sofar = BFD_ALIGN(sofar, 1 << current->alignment_power);
85e0c721
SC
2023 current->size += sofar - old_sofar ;
2024
2025 previous = current;
2026 }
2027 obj_relocbase(abfd) = sofar;
6f715d66 2028}
0f268757
SC
2029
2030
2031
2032
2033/* SUPPRESS 558 */
2034/* SUPPRESS 529 */
2035static boolean
2036DEFUN(coff_write_object_contents,(abfd),
6f715d66
SC
2037 bfd *abfd)
2038 {
2039 asection *current;
2040 boolean hasrelocs = false;
2041 boolean haslinno = false;
2042 file_ptr reloc_base;
2043 file_ptr lineno_base;
2044 file_ptr sym_base;
2045 file_ptr scn_base;
2046 file_ptr data_base;
2047 unsigned long reloc_size = 0;
2048 unsigned long lnno_size = 0;
2049 asection *text_sec = NULL;
2050 asection *data_sec = NULL;
2051 asection *bss_sec = NULL;
cbdc7909 2052
6f715d66
SC
2053 struct internal_filehdr internal_f;
2054 struct internal_aouthdr internal_a;
cbdc7909
JG
2055
2056
6f715d66 2057 bfd_error = system_call_error;
cbdc7909
JG
2058
2059
6f715d66
SC
2060 if(abfd->output_has_begun == false) {
2061 coff_compute_section_file_positions(abfd);
2062 }
cbdc7909 2063
6f715d66
SC
2064 if (abfd->sections != (asection *)NULL) {
2065 scn_base = abfd->sections->filepos;
0f268757
SC
2066 }
2067 else {
2068 scn_base = 0;
2069 }
2070 if (bfd_seek(abfd, scn_base, SEEK_SET) != 0)
2071 return false;
2072 reloc_base = obj_relocbase(abfd);
cbdc7909 2073
0f268757
SC
2074 /* Make a pass through the symbol table to count line number entries and
2075 put them into the correct asections */
cbdc7909 2076
7a8b18b6 2077#ifndef NO_COFF_LINENOS
0f268757 2078 coff_count_linenumbers(abfd);
7a8b18b6 2079#endif
0f268757 2080 data_base = scn_base;
cbdc7909 2081
0f268757 2082 /* Work out the size of the reloc and linno areas */
cbdc7909 2083
0f268757
SC
2084 for (current = abfd->sections; current != NULL; current = current->next) {
2085 reloc_size += current->reloc_count * RELSZ;
7a8b18b6 2086#ifndef NO_COFF_LINENOS
0f268757 2087 lnno_size += current->lineno_count * LINESZ;
7a8b18b6 2088#endif
0f268757
SC
2089 data_base += SCNHSZ;
2090 }
cbdc7909 2091
0f268757
SC
2092 lineno_base = reloc_base + reloc_size;
2093 sym_base = lineno_base + lnno_size;
cbdc7909 2094
0f268757
SC
2095 /* Indicate in each section->line_filepos its actual file address */
2096 for (current = abfd->sections; current != NULL; current = current->next) {
2097 if (current->lineno_count) {
2098 current->line_filepos = lineno_base;
2099 current->moving_line_filepos = lineno_base;
7a8b18b6 2100#ifndef NO_COFF_LINENOS
0f268757 2101 lineno_base += current->lineno_count * LINESZ;
7a8b18b6 2102#endif
0f268757
SC
2103 }
2104 else {
2105 current->line_filepos = 0;
2106 }
2107 if (current->reloc_count) {
2108 current->rel_filepos = reloc_base;
2109 reloc_base += current->reloc_count * sizeof(struct internal_reloc);
2110 }
2111 else {
2112 current->rel_filepos = 0;
2113 }
2114 }
cbdc7909 2115
0f268757 2116 /* Write section headers to the file. */
cbdc7909 2117
0f268757
SC
2118 bfd_seek(abfd,
2119 (file_ptr) ((abfd->flags & EXEC_P) ?
2120 (FILHSZ + AOUTSZ) : FILHSZ),
2121 SEEK_SET);
cbdc7909 2122
0f268757
SC
2123 {
2124#if 0
2125 unsigned int pad = abfd->flags & D_PAGED ? data_base : 0;
2126#endif
2127 unsigned int pad = 0;
cbdc7909 2128
0f268757
SC
2129 for (current = abfd->sections; current != NULL; current = current->next) {
2130 struct internal_scnhdr section;
2131 strncpy(&(section.s_name[0]), current->name, 8);
2132 section.s_vaddr = current->vma + pad;
2133 section.s_paddr = current->vma + pad;
2134 section.s_size = current->size - pad;
2135 /*
2136 If this section has no size or is unloadable then the scnptr
2137 will be 0 too
2138 */
2139 if (current->size - pad == 0 ||
2140 (current->flags & SEC_LOAD) == 0) {
2141 section.s_scnptr = 0;
0f268757
SC
2142 }
2143 else {
2144 section.s_scnptr = current->filepos;
2145 }
2146 section.s_relptr = current->rel_filepos;
2147 section.s_lnnoptr = current->line_filepos;
2148 section.s_nreloc = current->reloc_count;
2149 section.s_nlnno = current->lineno_count;
2150 if (current->reloc_count != 0)
2151 hasrelocs = true;
2152 if (current->lineno_count != 0)
2153 haslinno = true;
cbdc7909 2154
41f50af0
SC
2155 section.s_flags = sec_to_styp_flags(current->name,current->flags);
2156
0f268757
SC
2157 if (!strcmp(current->name, _TEXT)) {
2158 text_sec = current;
41f50af0 2159 } else if (!strcmp(current->name, _DATA)) {
0f268757 2160 data_sec = current;
41f50af0 2161 } else if (!strcmp(current->name, _BSS)) {
0f268757 2162 bss_sec = current;
cbdc7909
JG
2163 }
2164
0f268757
SC
2165#ifdef I960
2166 section.s_align = (current->alignment_power
2167 ? 1 << current->alignment_power
2168 : 0);
2169
2170#endif
2171 {
2172 SCNHDR buff;
2173
0d740984 2174 coff_swap_scnhdr_out(abfd, &section, &buff);
0f268757
SC
2175 bfd_write((PTR) (&buff), 1, SCNHSZ, abfd);
2176
2177 }
2178 pad = 0;
2179 }
2180 }
2181
2182 /* OK, now set up the filehdr... */
2183 internal_f.f_nscns = abfd->section_count;
2184 /*
2185 We will NOT put a fucking timestamp in the header here. Every time you
2186 put it back, I will come in and take it out again. I'm sorry. This
2187 field does not belong here. We fill it with a 0 so it compares the
2188 same but is not a reasonable time. -- gnu@cygnus.com
2189 */
2190 /*
2191 Well, I like it, so I'm conditionally compiling it in.
2192 steve@cygnus.com
2193 */
2194#ifdef COFF_TIMESTAMP
2195 internal_f.f_timdat = time(0);
2196#else
2197 internal_f.f_timdat = 0;
2198#endif
2199
2200 if (bfd_get_symcount(abfd) != 0)
2201 internal_f.f_symptr = sym_base;
2202 else
2203 internal_f.f_symptr = 0;
2204
2205 internal_f.f_flags = 0;
2206
2207 if (abfd->flags & EXEC_P)
2208 internal_f.f_opthdr = AOUTSZ;
2209 else
2210 internal_f.f_opthdr = 0;
2211
2212 if (!hasrelocs)
2213 internal_f.f_flags |= F_RELFLG;
2214 if (!haslinno)
2215 internal_f.f_flags |= F_LNNO;
2216 if (0 == bfd_get_symcount(abfd))
2217 internal_f.f_flags |= F_LSYMS;
2218 if (abfd->flags & EXEC_P)
2219 internal_f.f_flags |= F_EXEC;
2220#if M88
2221 internal_f.f_flags |= F_AR32W;
2222#else
2223 if (!abfd->xvec->byteorder_big_p)
2224 internal_f.f_flags |= F_AR32WR;
2225#endif
2226 /*
2227 FIXME, should do something about the other byte orders and
2228 architectures.
2229 */
2230
2231 /* Set up architecture-dependent stuff */
2232
41f50af0
SC
2233 { unsigned int magic = 0;
2234 unsigned short flags = 0;
2235 coff_set_flags(abfd, &magic, &flags);
0f268757 2236 internal_f.f_magic = magic;
2f8d9c1c 2237 internal_f.f_flags |= flags;
0f268757
SC
2238 /* ...and the "opt"hdr... */
2239
cbdc7909 2240#ifdef A29K
41f50af0
SC
2241# ifdef ULTRA3 /* NYU's machine */
2242 /* FIXME: This is a bogus check. I really want to see if there
2243 * is a .shbss or a .shdata section, if so then set the magic
2244 * number to indicate a shared data executable.
cbdc7909 2245 */
41f50af0
SC
2246 if (internal_f.f_nscns >= 7)
2247 internal_a.magic = SHMAGIC; /* Shared magic */
2248 else
2249# endif /* ULTRA3 */
2250 internal_a.magic = NMAGIC; /* Assume separate i/d */
2251#define __A_MAGIC_SET__
2252#endif /* A29K */
0f268757 2253#ifdef I960
cbdc7909 2254 internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC);
41f50af0
SC
2255#define __A_MAGIC_SET__
2256#endif /* I960 */
0f268757 2257#if M88
41f50af0 2258#define __A_MAGIC_SET__
0f268757 2259 internal_a.magic = PAGEMAGICBCS;
41f50af0
SC
2260#endif /* M88 */
2261
2262#if M68 || I386 || MIPS
2263#define __A_MAGIC_SET__
cbdc7909 2264 /* Never was anything here for the 68k */
41f50af0
SC
2265#endif /* M88 */
2266
cbdc7909
JG
2267#if RS6000COFF_C
2268#define __A_MAGIC_SET__
2269 internal_a.magic = (abfd->flags & D_PAGED)? RS6K_AOUTHDR_ZMAGIC:
2270 (abfd->flags & WP_TEXT)? RS6K_AOUTHDR_NMAGIC:
2271 RS6K_AOUTHDR_OMAGIC;
2272#endif
2273
41f50af0
SC
2274#ifndef __A_MAGIC_SET__
2275# include "Your aouthdr magic number is not being set!"
2276#else
2277# undef __A_MAGIC_SET__
0f268757
SC
2278#endif
2279 }
2280 /* Now should write relocs, strings, syms */
2281 obj_sym_filepos(abfd) = sym_base;
2282
7a8b18b6 2283#ifndef NO_COFF_SYMBOLS
0f268757 2284 if (bfd_get_symcount(abfd) != 0) {
6f715d66 2285 coff_renumber_symbols(abfd);
0f268757
SC
2286 coff_mangle_symbols(abfd);
2287 coff_write_symbols(abfd);
2288 coff_write_linenumbers(abfd);
2289 coff_write_relocs(abfd);
2290 }
7a8b18b6 2291#endif /* NO_COFF_SYMBOLS */
0f268757
SC
2292 if (text_sec) {
2293 internal_a.tsize = text_sec->size;
2294 internal_a.text_start =text_sec->size ? text_sec->vma : 0;
2295 }
2296 if (data_sec) {
2297 internal_a.dsize = data_sec->size;
2298 internal_a.data_start = data_sec->size ? data_sec->vma : 0;
2299 }
2300 if (bss_sec) {
2301 internal_a.bsize = bss_sec->size;
2302 }
2303
2304 internal_a.entry = bfd_get_start_address(abfd);
2305 internal_f.f_nsyms = bfd_get_symcount(abfd);
2306
2307 /* now write them */
2308 if (bfd_seek(abfd, 0L, SEEK_SET) != 0)
2309 return false;
2310 {
2311 FILHDR buff;
0d740984 2312 coff_swap_filehdr_out(abfd, &internal_f, &buff);
0f268757
SC
2313 bfd_write((PTR) &buff, 1, FILHSZ, abfd);
2314 }
2315 if (abfd->flags & EXEC_P) {
2316 AOUTHDR buff;
0d740984 2317 coff_swap_aouthdr_out(abfd, &internal_a, &buff);
0f268757
SC
2318 bfd_write((PTR) &buff, 1, AOUTSZ, abfd);
2319 }
2320 return true;
6f715d66
SC
2321}
2322
7a8b18b6
SC
2323#ifndef NO_COFF_SYMBOLS
2324
6f715d66
SC
2325/*
2326this function transforms the offsets into the symbol table into
2327pointers to syments.
2328*/
2329
2330
2331static void
fb3be09b
JG
2332DEFUN(coff_pointerize_aux,(ignore_abfd, table_base, type, class, auxent),
2333bfd *ignore_abfd AND
6f715d66
SC
2334combined_entry_type *table_base AND
2335int type AND
2336int class AND
2337combined_entry_type *auxent)
2338{
2339 /* Don't bother if this is a file or a section */
2340 if (class == C_STAT && type == T_NULL) return;
2341 if (class == C_FILE) return;
2342
2343 /* Otherwise patch up */
2344 if (ISFCN(type) || ISTAG(class) || class == C_BLOCK) {
2345 auxent->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p = table_base +
2346 auxent->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.l;
2347 auxent->fix_end = 1;
2348 }
7a8b18b6
SC
2349 if (auxent->u.auxent.x_sym.x_tagndx.l != 0) {
2350 auxent->u.auxent.x_sym.x_tagndx.p = table_base + auxent->u.auxent.x_sym.x_tagndx.l;
2351 auxent->fix_tag = 1;
2352 }
6f715d66
SC
2353}
2354
7a8b18b6 2355#endif /* NO_COFF_SYMBOLS */
0f268757
SC
2356
2357static boolean
6f715d66
SC
2358DEFUN(coff_set_section_contents,(abfd, section, location, offset, count),
2359 bfd *abfd AND
2360 sec_ptr section AND
2361 PTR location AND
2362 file_ptr offset AND
41f50af0 2363 bfd_size_type count)
0f268757
SC
2364{
2365 if (abfd->output_has_begun == false) /* set by bfd.c handler */
2366 coff_compute_section_file_positions(abfd);
2367
2368 bfd_seek(abfd, (file_ptr) (section->filepos + offset), SEEK_SET);
2369
2370 if (count != 0) {
2371 return (bfd_write(location, 1, count, abfd) == count) ? true : false;
2372 }
2373 return true;
2374}
2375#if 0
2376static boolean
2377coff_close_and_cleanup(abfd)
2378 bfd *abfd;
2379{
2380 if (!bfd_read_p(abfd))
2381 switch (abfd->format) {
2382 case bfd_archive:
2383 if (!_bfd_write_archive_contents(abfd))
2384 return false;
2385 break;
2386 case bfd_object:
2387 if (!coff_write_object_contents(abfd))
2388 return false;
2389 break;
2390 default:
2391 bfd_error = invalid_operation;
2392 return false;
2393 }
2394
2395 /* We depend on bfd_close to free all the memory on the obstack. */
2396 /* FIXME if bfd_release is not using obstacks! */
2397 return true;
2398}
2399
2400#endif
cbdc7909 2401static PTR
0f268757
SC
2402buy_and_read(abfd, where, seek_direction, size)
2403 bfd *abfd;
2404 file_ptr where;
2405 int seek_direction;
2406 size_t size;
2407{
2408 PTR area = (PTR) bfd_alloc(abfd, size);
2409 if (!area) {
2410 bfd_error = no_memory;
2411 return (NULL);
2412 }
2413 bfd_seek(abfd, where, seek_direction);
2414 if (bfd_read(area, 1, size, abfd) != size) {
2415 bfd_error = system_call_error;
2416 return (NULL);
2417 } /* on error */
2418 return (area);
2419} /* buy_and_read() */
2420
6f715d66 2421
7a8b18b6 2422#ifndef NO_COFF_SYMBOLS
6f715d66
SC
2423
2424static char *
2425DEFUN(build_string_table,(abfd),
2426bfd *abfd)
0f268757 2427{
6f715d66
SC
2428 char string_table_size_buffer[4];
2429 unsigned int string_table_size;
2430 char *string_table;
cbdc7909
JG
2431
2432 /* At this point we should be "seek"'d to the end of the
2433 symbols === the symbol table size. */
6f715d66
SC
2434 if (bfd_read((char *) string_table_size_buffer,
2435 sizeof(string_table_size_buffer),
2436 1, abfd) != sizeof(string_table_size)) {
2437 bfd_error = system_call_error;
2438 return (NULL);
2439 } /* on error */
cbdc7909 2440
41f50af0 2441 string_table_size = bfd_h_get_32(abfd, (bfd_byte *) string_table_size_buffer);
cbdc7909 2442
6f715d66
SC
2443 if ((string_table = (PTR) bfd_alloc(abfd, string_table_size -= 4)) == NULL) {
2444 bfd_error = no_memory;
2445 return (NULL);
2446 } /* on mallocation error */
2447 if (bfd_read(string_table, string_table_size, 1, abfd) != string_table_size) {
2448 bfd_error = system_call_error;
2449 return (NULL);
cbdc7909 2450 }
6f715d66
SC
2451 return string_table;
2452}
0f268757 2453
cbdc7909
JG
2454/* Allocate space for the ".debug" section, and read it.
2455 We did not read the debug section until now, because
2456 we didn't want to go to the trouble until someone needed it. */
2457
2458static char *
2459DEFUN(build_debug_section,(abfd),
2460 bfd *abfd)
2461{
2462 char *debug_section;
2463 long position;
2464
2465 asection *sect = bfd_get_section_by_name (abfd, ".debug");
2466
2467 if (!sect) {
2468 bfd_error = no_debug_section;
2469 return NULL;
2470 }
2471
2472 debug_section = (PTR) bfd_alloc (abfd, bfd_section_size (abfd, sect));
2473 if (debug_section == NULL) {
2474 bfd_error = no_memory;
2475 return NULL;
2476 }
2477
2478 /* Seek to the beginning of the `.debug' section and read it.
2479 Save the current position first; it is needed by our caller.
2480 Then read debug section and reset the file pointer. */
2481
2482 position = bfd_tell (abfd);
2483 bfd_seek (abfd, sect->filepos, SEEK_SET);
2484 if (bfd_read (debug_section, bfd_section_size (abfd, sect), 1, abfd)
2485 != bfd_section_size (abfd, sect)) {
2486 bfd_error = system_call_error;
2487 return NULL;
2488 }
2489 bfd_seek (abfd, position, SEEK_SET);
2490 return debug_section;
2491}
2492
2493
fb3be09b
JG
2494/* Return a pointer to a malloc'd copy of 'name'. 'name' may not be
2495 \0-terminated, but will not exceed 'maxlen' characters. The copy *will*
2496 be \0-terminated. */
2497static char *
2498DEFUN(copy_name,(abfd, name, maxlen),
2499 bfd *abfd AND
2500 char *name AND
2501 int maxlen)
2502{
2503 int len;
2504 char *newname;
cbdc7909 2505
fb3be09b
JG
2506 for (len = 0; len < maxlen; ++len) {
2507 if (name[len] == '\0') {
2508 break;
2509 }
2510 }
cbdc7909 2511
fb3be09b
JG
2512 if ((newname = (PTR) bfd_alloc(abfd, len+1)) == NULL) {
2513 bfd_error = no_memory;
2514 return (NULL);
2515 }
2516 strncpy(newname, name, len);
2517 newname[len] = '\0';
2518 return newname;
2519}
2520
2521
cbdc7909
JG
2522/* Read a symbol table into freshly bfd_allocated memory, swap it, and
2523 knit the symbol names into a normalized form. By normalized here I
2524 mean that all symbols have an n_offset pointer that points to a null-
2525 terminated string. */
2526
2527#ifndef SYMNAME_IN_DEBUG
2528#define SYMNAME_IN_DEBUG(x) 0
2529#endif
0f268757 2530
6f715d66 2531static combined_entry_type *
0f268757
SC
2532DEFUN(get_normalized_symtab,(abfd),
2533bfd *abfd)
2534{
6f715d66
SC
2535 combined_entry_type *internal;
2536 combined_entry_type *internal_ptr;
2537 combined_entry_type *internal_end;
0f268757
SC
2538 SYMENT *raw;
2539 SYMENT *raw_src;
2540 SYMENT *raw_end;
2541 char *string_table = NULL;
cbdc7909 2542 char *debug_section = NULL;
0f268757 2543 unsigned long size;
6f715d66 2544
0f268757 2545 unsigned int raw_size;
6f715d66 2546 if (obj_raw_syments(abfd) != (combined_entry_type *)NULL) {
0f268757
SC
2547 return obj_raw_syments(abfd);
2548 }
6f715d66 2549 if ((size = bfd_get_symcount(abfd) * sizeof(combined_entry_type)) == 0) {
0f268757
SC
2550 bfd_error = no_symbols;
2551 return (NULL);
2552 }
2553
6f715d66 2554 internal = (combined_entry_type *)bfd_alloc(abfd, size);
0f268757
SC
2555 internal_end = internal + bfd_get_symcount(abfd);
2556
2557 raw_size = bfd_get_symcount(abfd) * SYMESZ;
2558 raw = (SYMENT *)bfd_alloc(abfd,raw_size);
2559
2560 if (bfd_seek(abfd, obj_sym_filepos(abfd), SEEK_SET) == -1
2561 || bfd_read((PTR)raw, raw_size, 1, abfd) != raw_size) {
2562 bfd_error = system_call_error;
2563 return (NULL);
2564 }
2565 /* mark the end of the symbols */
2566 raw_end = raw + bfd_get_symcount(abfd);
2567 /*
2568 FIXME SOMEDAY. A string table size of zero is very weird, but
2569 probably possible. If one shows up, it will probably kill us.
2570 */
2571
2572 /* Swap all the raw entries */
cbdc7909
JG
2573 for (raw_src = raw, internal_ptr = internal;
2574 raw_src < raw_end;
2575 raw_src++, internal_ptr++) {
2576
0f268757 2577 unsigned int i;
cbdc7909 2578 coff_swap_sym_in(abfd, (char *)raw_src, (char *)&internal_ptr->u.syment);
6f715d66
SC
2579 internal_ptr->fix_tag = 0;
2580 internal_ptr->fix_end = 0;
2581
cbdc7909
JG
2582 for (i = internal_ptr->u.syment.n_numaux;
2583 i;
2584 --i, raw_src++, internal_ptr++) {
2585
6f715d66
SC
2586 (internal_ptr+1)->fix_tag = 0;
2587 (internal_ptr+1)->fix_end = 0;
2588
cbdc7909
JG
2589 coff_swap_aux_in(abfd, (char *)(raw_src +1),
2590 internal_ptr->u.syment.n_type,
2591 internal_ptr->u.syment.n_sclass,
2592 &(internal_ptr+1)->u.auxent);
6f715d66 2593
cbdc7909 2594 coff_pointerize_aux(abfd,
6f715d66
SC
2595 internal,
2596 internal_ptr->u.syment.n_type,
2597 internal_ptr->u.syment.n_sclass,
2598 internal_ptr +1);
0f268757
SC
2599 }
2600 }
cbdc7909 2601
0f268757 2602 /* Free all the raw stuff */
0d740984 2603 bfd_release(abfd, raw);
0f268757 2604
6f715d66 2605 for (internal_ptr = internal; internal_ptr < internal_end;
cbdc7909 2606 internal_ptr ++)
6f715d66
SC
2607 {
2608 if (internal_ptr->u.syment.n_sclass == C_FILE) {
2609 /* make a file symbol point to the name in the auxent, since
2610 the text ".file" is redundant */
2611 if ((internal_ptr+1)->u.auxent.x_file.x_n.x_zeroes == 0) {
cbdc7909 2612 /* the filename is a long one, point into the string table */
6f715d66
SC
2613 if (string_table == NULL) {
2614 string_table = build_string_table(abfd);
2615 }
0f268757 2616
6f715d66
SC
2617 internal_ptr->u.syment._n._n_n._n_offset =
2618 (int) (string_table - 4 +
2619 (internal_ptr+1)->u.auxent.x_file.x_n.x_offset);
2620 }
2621 else {
2622 /* ordinary short filename, put into memory anyway */
2623 internal_ptr->u.syment._n._n_n._n_offset = (int)
cbdc7909
JG
2624 copy_name(abfd, (internal_ptr+1)->u.auxent.x_file.x_fname,
2625 FILNMLEN);
6f715d66
SC
2626 }
2627 }
2628 else {
2629 if (internal_ptr->u.syment._n._n_n._n_zeroes != 0) {
cbdc7909 2630 /* This is a "short" name. Make it long. */
6f715d66
SC
2631 unsigned long i = 0;
2632 char *newstring = NULL;
cbdc7909
JG
2633
2634 /* find the length of this string without walking into memory
2635 that isn't ours. */
6f715d66
SC
2636 for (i = 0; i < 8; ++i) {
2637 if (internal_ptr->u.syment._n._n_name[i] == '\0') {
2638 break;
2639 } /* if end of string */
2640 } /* possible lengths of this string. */
cbdc7909 2641
6f715d66
SC
2642 if ((newstring = (PTR) bfd_alloc(abfd, ++i)) == NULL) {
2643 bfd_error = no_memory;
2644 return (NULL);
2645 } /* on error */
2646 bzero(newstring, i);
2647 strncpy(newstring, internal_ptr->u.syment._n._n_name, i-1);
2648 internal_ptr->u.syment._n._n_n._n_offset = (int) newstring;
2649 internal_ptr->u.syment._n._n_n._n_zeroes = 0;
6f715d66 2650 }
cbdc7909
JG
2651 else if (!SYMNAME_IN_DEBUG(&internal_ptr->u.syment)) {
2652 /* Long name already. Point symbol at the string in the table. */
6f715d66
SC
2653 if (string_table == NULL) {
2654 string_table = build_string_table(abfd);
2655 }
cbdc7909
JG
2656 internal_ptr->u.syment._n._n_n._n_offset = (int)
2657 (string_table - 4 + internal_ptr->u.syment._n._n_n._n_offset);
2658 }
2659 else {
2660 /* Long name in debug section. Very similar. */
2661 if (debug_section == NULL) {
2662 debug_section = build_debug_section(abfd);
2663 }
2664 internal_ptr->u.syment._n._n_n._n_offset = (int)
2665 (debug_section + internal_ptr->u.syment._n._n_n._n_offset);
2666 }
6f715d66
SC
2667 }
2668 internal_ptr += internal_ptr->u.syment.n_numaux;
cbdc7909 2669 }
0f268757 2670
0f268757 2671 obj_raw_syments(abfd) = internal;
cbdc7909 2672
0f268757
SC
2673 return (internal);
2674} /* get_normalized_symtab() */
2675
7a8b18b6
SC
2676#endif /* NO_COFF_SYMBOLS */
2677
0f268757
SC
2678static
2679struct sec *
2680DEFUN(section_from_bfd_index,(abfd, index),
2681 bfd *abfd AND
2682 int index)
2683{
2684 if (index > 0) {
2685 struct sec *answer = abfd->sections;
2686 while (--index) {
2687 answer = answer->next;
2688 }
2689 return answer;
2690 }
2691 return 0;
2692}
2693
7a8b18b6 2694#ifndef NO_COFF_LINENOS
0f268757 2695
6f715d66
SC
2696/*doc*
2697@subsubsection Reading Linenumbers
2698Createing the linenumber table is done by reading in the entire coff
2699linenumber table, and creating another table for internal use.
2700
2701A coff line number table is structured so that each
2702function is marked as having a line number of 0. Each line within the
2703function is an offset from the first line in the function. The base of
2704the line number information for the table is stored in the symbol
2705associated with the function.
2706
2707The information is copied from the external to the internal table, and
2708each symbol which marks a function is marked by pointing its...
2709
2710**How does this work ?**
2711
2712*/
0f268757
SC
2713
2714static boolean
2715coff_slurp_line_table(abfd, asect)
2716bfd *abfd;
2717asection *asect;
2718 {
2719 LINENO *native_lineno;
2720 alent *lineno_cache;
cbdc7909 2721
0f268757 2722 BFD_ASSERT(asect->lineno == (alent *) NULL);
cbdc7909 2723
0f268757
SC
2724 native_lineno = (LINENO *) buy_and_read(abfd,
2725 asect->line_filepos,
2726 SEEK_SET,
2727 (size_t) (LINESZ *
2728 asect->lineno_count));
2729 lineno_cache =
2730 (alent *) bfd_alloc(abfd, (size_t) ((asect->lineno_count + 1) * sizeof(alent)));
2731 if (lineno_cache == NULL) {
2732 bfd_error = no_memory;
2733 return false;
cbdc7909 2734 } else {
0f268757
SC
2735 unsigned int counter = 0;
2736 alent *cache_ptr = lineno_cache;
2737 LINENO *src = native_lineno;
cbdc7909 2738
0f268757
SC
2739 while (counter < asect->lineno_count) {
2740 struct internal_lineno dst;
2700c3c7 2741 coff_swap_lineno_in(abfd, src, &dst);
0f268757 2742 cache_ptr->line_number = dst.l_lnno;
cbdc7909 2743
0f268757
SC
2744 if (cache_ptr->line_number == 0) {
2745 coff_symbol_type *sym =
2746 (coff_symbol_type *) (dst.l_addr.l_symndx
6f715d66 2747 + obj_raw_syments(abfd))->u.syment._n._n_n._n_zeroes;
0f268757
SC
2748 cache_ptr->u.sym = (asymbol *) sym;
2749 sym->lineno = cache_ptr;
2750 }
2751 else {
2752 cache_ptr->u.offset = dst.l_addr.l_paddr
2753 - bfd_section_vma(abfd, asect);
2754 } /* If no linenumber expect a symbol index */
cbdc7909 2755
0f268757
SC
2756 cache_ptr++;
2757 src++;
2758 counter++;
2759 }
2760 cache_ptr->line_number = 0;
cbdc7909 2761
0f268757
SC
2762 }
2763 asect->lineno = lineno_cache;
2764 /* FIXME, free native_lineno here, or use alloca or something. */
2765 return true;
2766 } /* coff_slurp_line_table() */
2767
7a8b18b6
SC
2768#endif /* NO_COFF_LINENOS */
2769
2770#ifndef NO_COFF_LINENOS
2771
0f268757
SC
2772static boolean
2773DEFUN(coff_slurp_symbol_table,(abfd),
2774 bfd *abfd)
6f715d66
SC
2775{
2776 combined_entry_type *native_symbols;
2777 coff_symbol_type *cached_area;
2778 unsigned int *table_ptr;
cbdc7909 2779
6f715d66
SC
2780 unsigned int number_of_symbols = 0;
2781 if (obj_symbols(abfd))
2782 return true;
2783 bfd_seek(abfd, obj_sym_filepos(abfd), SEEK_SET);
cbdc7909 2784
6f715d66
SC
2785 /* Read in the symbol table */
2786 if ((native_symbols = get_normalized_symtab(abfd)) == NULL) {
2787 return (false);
2788 } /* on error */
cbdc7909 2789
6f715d66
SC
2790 /* Allocate enough room for all the symbols in cached form */
2791 cached_area =
2792 (coff_symbol_type *)
2793 bfd_alloc(abfd, (size_t) (bfd_get_symcount(abfd) * sizeof(coff_symbol_type)));
cbdc7909 2794
6f715d66
SC
2795 if (cached_area == NULL) {
2796 bfd_error = no_memory;
2797 return false;
2798 } /* on error */
2799 table_ptr =
2800 (unsigned int *)
2801 bfd_alloc(abfd, (size_t) (bfd_get_symcount(abfd) * sizeof(unsigned int)));
cbdc7909 2802
6f715d66
SC
2803 if (table_ptr == NULL) {
2804 bfd_error = no_memory;
2805 return false;
85e0c721
SC
2806 }
2807 else
2808 {
6f715d66
SC
2809 coff_symbol_type *dst = cached_area;
2810 unsigned int last_native_index = bfd_get_symcount(abfd);
2811 unsigned int this_index = 0;
2812 while (this_index < last_native_index) {
2813 combined_entry_type *src = native_symbols + this_index;
2814 table_ptr[this_index] = number_of_symbols;
2815 dst->symbol.the_bfd = abfd;
cbdc7909 2816
6f715d66
SC
2817 dst->symbol.name = (char *)(src->u.syment._n._n_n._n_offset);
2818 /*
2819 We use the native name field to point to the cached field
2820 */
2821 src->u.syment._n._n_n._n_zeroes = (int) dst;
2822 dst->symbol.section = section_from_bfd_index(abfd,
2823 src->u.syment.n_scnum);
2824 switch (src->u.syment.n_sclass) {
0f268757 2825#ifdef I960
6f715d66 2826 case C_LEAFEXT:
0f268757 2827#if 0
6f715d66
SC
2828 dst->symbol.value = src->u.syment.n_value - dst->symbol.section->vma;
2829 dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
2830 dst->symbol.flags |= BSF_NOT_AT_END;
0f268757 2831#endif
6f715d66 2832 /* Fall through to next case */
cbdc7909 2833
0f268757 2834#endif
cbdc7909 2835
6f715d66 2836 case C_EXT:
cbdc7909
JG
2837#ifdef RS6000COFF_C
2838 case C_HIDEXT:
2839#endif
6f715d66
SC
2840 if ((src->u.syment.n_scnum) == 0) {
2841 if ((src->u.syment.n_value) == 0) {
2842 dst->symbol.flags = BSF_UNDEFINED;
2843 dst->symbol.value= 0;
2844 }
2845 else {
2846 dst->symbol.flags = BSF_FORT_COMM;
2847 dst->symbol.value = (src->u.syment.n_value);
2848 }
2849 }
2850 else {
2851 /*
2852 Base the value as an index from the base of the
2853 section
2854 */
2855 if (dst->symbol.section == (asection *) NULL) {
2856 dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL | BSF_ABSOLUTE;
2857 dst->symbol.value = src->u.syment.n_value;
0f268757
SC
2858 }
2859 else {
6f715d66
SC
2860 dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
2861 dst->symbol.value = src->u.syment.n_value - dst->symbol.section->vma;
2862 }
2863 if (ISFCN((src->u.syment.n_type))) {
0f268757 2864 /*
6f715d66
SC
2865 A function ext does not go at the end of a file
2866 */
2867 dst->symbol.flags |= BSF_NOT_AT_END;
0f268757 2868 }
6f715d66 2869 }
85e0c721
SC
2870
2871
6f715d66 2872 break;
cbdc7909 2873
6f715d66 2874 case C_STAT: /* static */
0f268757 2875#ifdef I960
6f715d66 2876 case C_LEAFSTAT: /* static leaf procedure */
0f268757 2877#endif
6f715d66 2878 case C_LABEL: /* label */
0d740984
SC
2879 if (src->u.syment.n_scnum == -2)
2880 dst->symbol.flags = BSF_DEBUGGING;
2881 else
2882 dst->symbol.flags = BSF_LOCAL;
6f715d66 2883 /*
0d740984
SC
2884 Base the value as an index from the base of the section, if
2885 there is one
6f715d66 2886 */
0d740984
SC
2887 if (dst->symbol.section)
2888 dst->symbol.value = (src->u.syment.n_value) -
2889 dst->symbol.section->vma;
2890 else
2891 dst->symbol.value = (src->u.syment.n_value) ;
6f715d66 2892 break;
cbdc7909 2893
6f715d66
SC
2894 case C_MOS: /* member of structure */
2895 case C_EOS: /* end of structure */
41f50af0
SC
2896#ifdef NOTDEF /* C_AUTOARG has the same value */
2897#ifdef C_GLBLREG
2898 case C_GLBLREG: /* A29k-specific storage class */
2899#endif
2900#endif
6f715d66
SC
2901 case C_REGPARM: /* register parameter */
2902 case C_REG: /* register variable */
0f268757 2903#ifdef C_AUTOARG
6f715d66 2904 case C_AUTOARG: /* 960-specific storage class */
0f268757 2905#endif
6f715d66 2906 case C_TPDEF: /* type definition */
6f715d66
SC
2907 case C_ARG:
2908 case C_AUTO: /* automatic variable */
2909 case C_FIELD: /* bit field */
2910 case C_ENTAG: /* enumeration tag */
2911 case C_MOE: /* member of enumeration */
2912 case C_MOU: /* member of union */
2913 case C_UNTAG: /* union tag */
6f715d66
SC
2914 dst->symbol.flags = BSF_DEBUGGING;
2915 dst->symbol.value = (src->u.syment.n_value);
2916 break;
cbdc7909 2917
6f715d66
SC
2918 case C_FILE: /* file name */
2919 case C_STRTAG: /* structure tag */
cbdc7909
JG
2920#ifdef RS6000COFF_C
2921 case C_BINCL: /* beginning of include file */
2922 case C_EINCL: /* ending of include file */
2923 case C_GSYM:
2924 case C_LSYM:
2925 case C_PSYM:
2926 case C_RSYM:
2927 case C_RPSYM:
2928 case C_STSYM:
2929 case C_DECL:
2930 case C_ENTRY:
2931 case C_FUN:
2932 case C_BSTAT:
2933 case C_ESTAT:
2934#endif
6f715d66
SC
2935 dst->symbol.flags = BSF_DEBUGGING;
2936 dst->symbol.value = (src->u.syment.n_value);
6f715d66 2937 break;
cbdc7909 2938
6f715d66
SC
2939 case C_BLOCK: /* ".bb" or ".eb" */
2940 case C_FCN: /* ".bf" or ".ef" */
41f50af0 2941 case C_EFCN: /* physical end of function */
6f715d66
SC
2942 dst->symbol.flags = BSF_LOCAL;
2943 /*
2944 Base the value as an index from the base of the section
2945 */
2946 dst->symbol.value = (src->u.syment.n_value) - dst->symbol.section->vma;
6f715d66 2947 break;
cbdc7909 2948
6f715d66
SC
2949 case C_NULL:
2950 case C_EXTDEF: /* external definition */
2951 case C_ULABEL: /* undefined label */
2952 case C_USTATIC: /* undefined static */
2953 case C_LINE: /* line # reformatted as symbol table entry */
2954 case C_ALIAS: /* duplicate tag */
2955 case C_HIDDEN: /* ext symbol in dmert public lib */
6f715d66 2956 default:
cbdc7909
JG
2957
2958 fprintf(stderr,"Unrecognized storage class %d\n",
41f50af0 2959 src->u.syment.n_sclass);
6f715d66
SC
2960 abort();
2961 dst->symbol.flags = BSF_DEBUGGING;
2962 dst->symbol.value = (src->u.syment.n_value);
6f715d66
SC
2963 break;
2964 }
cbdc7909 2965
6f715d66 2966 BFD_ASSERT(dst->symbol.flags != 0);
cbdc7909 2967
6f715d66 2968 dst->native = src;
cbdc7909 2969
6f715d66
SC
2970 dst->symbol.udata = 0;
2971 dst->lineno = (alent *) NULL;
2972 this_index += (src->u.syment.n_numaux) + 1;
2973 dst++;
2974 number_of_symbols++;
2975 } /* walk the native symtab */
2976 } /* bfdize the native symtab */
cbdc7909 2977
6f715d66
SC
2978 obj_symbols(abfd) = cached_area;
2979 obj_raw_syments(abfd) = native_symbols;
cbdc7909 2980
6f715d66
SC
2981 bfd_get_symcount(abfd) = number_of_symbols;
2982 obj_convert(abfd) = table_ptr;
2983 /* Slurp the line tables for each section too */
2984 {
2985 asection *p;
2986 p = abfd->sections;
2987 while (p) {
2988 coff_slurp_line_table(abfd, p);
2989 p = p->next;
0f268757 2990 }
6f715d66
SC
2991 }
2992 return true;
2993} /* coff_slurp_symbol_table() */
0f268757
SC
2994
2995static unsigned int
2996coff_get_symtab_upper_bound(abfd)
2997bfd *abfd;
2998 {
2999 if (!coff_slurp_symbol_table(abfd))
3000 return 0;
cbdc7909 3001
0f268757
SC
3002 return (bfd_get_symcount(abfd) + 1) * (sizeof(coff_symbol_type *));
3003 }
3004
3005
3006static unsigned int
85e0c721
SC
3007DEFUN(coff_get_symtab, (abfd, alocation),
3008 bfd *abfd AND
3009 asymbol **alocation)
3010{
0f268757
SC
3011 unsigned int counter = 0;
3012 coff_symbol_type *symbase;
3013 coff_symbol_type **location = (coff_symbol_type **) (alocation);
3014 if (!coff_slurp_symbol_table(abfd))
85e0c721
SC
3015 return 0;
3016
3017 symbase = obj_symbols(abfd);
3018 while (counter < bfd_get_symcount(abfd))
3019 {
3020 /* This nasty code looks at the symbol to decide whether or
3021 not it is descibes a constructor/destructor entry point. It
3022 is structured this way to (hopefully) speed non matches */
3b4f1a5d
SC
3023#if 0
3024 if (0 && symbase->symbol.name[9] == '$')
85e0c721
SC
3025 {
3026 bfd_constructor_entry(abfd,
3027 (asymbol **)location,
3028 symbase->symbol.name[10] == 'I' ?
3029 "CTOR" : "DTOR");
3030 }
3b4f1a5d 3031#endif
85e0c721
SC
3032 *(location++) = symbase++;
3033 counter++;
3034 }
0f268757
SC
3035 *location++ = 0;
3036 return bfd_get_symcount(abfd);
85e0c721 3037}
0f268757 3038
7a8b18b6
SC
3039#endif /* NO_COFF_SYMBOLS */
3040
0f268757
SC
3041static unsigned int
3042coff_get_reloc_upper_bound(abfd, asect)
3043bfd *abfd;
3044sec_ptr asect;
3045 {
3046 if (bfd_get_format(abfd) != bfd_object) {
3047 bfd_error = invalid_operation;
3048 return 0;
3049 }
3050 return (asect->reloc_count + 1) * sizeof(arelent *);
3051 }
3052
6f715d66
SC
3053/*doc*
3054@subsubsection Reading Relocations
6724ff46 3055Coff relocations are easily transformed into the internal BFD form
cbdc7909 3056(@code{arelent}).
6f715d66
SC
3057
3058Reading a coff relocation table is done in the following stages:
3059@itemize @bullet
cbdc7909 3060@item
6f715d66
SC
3061The entire coff relocation table is read into memory.
3062@item
3063Each relocation is processed in turn, first it is swapped from the
3064external to the internal form.
3065@item
3066The symbol referenced in the relocation's symbol index is turned into
3067a pointer into the canonical symbol table. Note that this table is the
3068same as the one returned by a call to @code{bfd_canonicalize_symtab}.
3069The back end will call the routine and save the result if a
3070canonicalization hasn't been done.
3071@item
3072The reloc index is turned into a pointer to a howto structure, in a
3073back end specific way. For instance, the 386 and 960 use the
3074@code{r_type} to directly produce an index into a howto table vector;
3075the 88k subtracts a number from the @code{r_type} field and creates an
3076addend field.
3077@end itemize
3078*/
3079
3b4f1a5d
SC
3080#ifndef CALC_ADDEND
3081#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
3082 if (ptr && ptr->the_bfd == abfd \
3083 && ptr->section != (asection *) NULL \
3084 && ((ptr->flags & BSF_OLD_COMMON)== 0)) \
3085 { \
3086 cache_ptr->addend = -(ptr->section->vma + ptr->value); \
3087 } \
3088 else { \
3089 cache_ptr->addend = 0; \
3090 }
3091#endif
3092
0f268757
SC
3093static boolean
3094DEFUN(coff_slurp_reloc_table,(abfd, asect, symbols),
3095 bfd *abfd AND
3096 sec_ptr asect AND
3097 asymbol **symbols)
85e0c721 3098{
3b4f1a5d
SC
3099 RELOC *native_relocs;
3100 arelent *reloc_cache;
3101 arelent *cache_ptr;
3102
3103 unsigned int idx;
3104
3105 if (asect->relocation)
3106 return true;
3107 if (asect->reloc_count == 0)
3108 return true;
3109 if (asect->flags & SEC_CONSTRUCTOR)
3110 return true;
7a8b18b6 3111#ifndef NO_COFF_SYMBOLS
3b4f1a5d
SC
3112 if (!coff_slurp_symbol_table(abfd))
3113 return false;
3114#endif
3115 native_relocs =
3116 (RELOC *) buy_and_read(abfd,
3117 asect->rel_filepos,
3118 SEEK_SET,
3119 (size_t) (RELSZ *
3120 asect->reloc_count));
3121 reloc_cache = (arelent *)
3122 bfd_alloc(abfd, (size_t) (asect->reloc_count * sizeof(arelent)));
3123
3124 if (reloc_cache == NULL) {
3125 bfd_error = no_memory;
3126 return false;
3127 }
3128
3129
3130 for (idx = 0; idx < asect->reloc_count; idx ++)
3131 {
3132 struct internal_reloc dst;
3133 asymbol *ptr;
3134 struct external_reloc *src;
3135
3136 cache_ptr = reloc_cache + idx;
3137 src = native_relocs + idx;
3138
3139 bfd_swap_reloc_in(abfd, src, &dst);
3140
3141
3142 if (dst.r_symndx != -1)
3143 {
3144 cache_ptr->sym_ptr_ptr = symbols + obj_convert(abfd)[dst.r_symndx];
3145 }
3146 else
3147 {
3148 cache_ptr->sym_ptr_ptr = 0;
3149 ptr = 0;
3150 goto puke_logic;
3151
3152 }
3153
cbdc7909 3154#ifdef A29K
3b4f1a5d
SC
3155 /* AMD has two relocation entries for the 'consth' instruction.
3156 * The first is R_IHIHALF (part 1), the second is R_IHCONST
3157 * (part 2). The second entry's r_symndx does not contain
3158 * an index to a symbol but rather a value (apparently).
3159 * Also, see the ifdef below for saving the r_symndx value in addend.
3160 */
3161 if (dst.r_type == R_IHCONST) {
3162 ptr = NULL;
3163 }
3164 else
41f50af0 3165#endif
85e0c721
SC
3166 ptr = *(cache_ptr->sym_ptr_ptr);
3167 cache_ptr->address = dst.r_vaddr;
3168 /*
3169 The symbols definitions that we have read in have been
3170 relocated as if their sections started at 0. But the offsets
3171 refering to the symbols in the raw data have not been
3172 modified, so we have to have a negative addend to compensate.
3173
3174 Note that symbols which used to be common must be left alone */
3175
3b4f1a5d
SC
3176 puke_logic:
3177 cache_ptr->address = dst.r_vaddr;
3178 /*
3179 The symbols definitions that we have read in have been
3180 relocated as if their sections started at 0. But the offsets
3181 refering to the symbols in the raw data have not been
3182 modified, so we have to have a negative addend to compensate.
3183
3184 Note that symbols which used to be common must be left alone */
cbdc7909 3185
3b4f1a5d
SC
3186 /* Calculate any reloc addend by looking at the symbol */
3187 CALC_ADDEND(abfd, ptr, dst, cache_ptr);
cbdc7909 3188
3b4f1a5d
SC
3189 cache_ptr->address -= asect->vma;
3190 cache_ptr->section = (asection *) NULL;
20fdc627 3191
3b4f1a5d
SC
3192 /* Fill in the cache_ptr->howto field from dst.r_type */
3193 RTYPE2HOWTO(cache_ptr, dst);
0f268757 3194 }
cbdc7909 3195
3b4f1a5d
SC
3196 asect->relocation = reloc_cache;
3197 return true;
85e0c721 3198}
0f268757
SC
3199
3200
3201/* This is stupid. This function should be a boolean predicate */
3202static unsigned int
85e0c721
SC
3203DEFUN(coff_canonicalize_reloc, (abfd, section, relptr, symbols),
3204bfd *abfd AND
3205sec_ptr section AND
3206arelent **relptr AND
3207asymbol **symbols)
3208{
0f268757
SC
3209 arelent *tblptr = section->relocation;
3210 unsigned int count = 0;
cbdc7909 3211
cbdc7909 3212
85e0c721
SC
3213 if (section->flags & SEC_CONSTRUCTOR)
3214 {
3215 /* this section has relocs made up by us, they are not in the
3216 file, so take them out of their chain and place them into
3217 the data area provided */
3218 arelent_chain *chain = section->constructor_chain;
3219 for (count = 0; count < section->reloc_count; count ++)
3220 {
3221 *relptr ++ = &chain->relent;
3222 chain = chain->next;
3223 }
3224
3225 }
3226 else
3227 {
3228 coff_slurp_reloc_table(abfd, section, symbols);
3229
3230
3231 tblptr = section->relocation;
3232 if (!tblptr)
3233 return 0;
3234
3235 for (; count++ < section->reloc_count;)
3236 *relptr++ = tblptr++;
cbdc7909 3237
85e0c721
SC
3238
3239 }
3240 *relptr = 0;
0f268757 3241 return section->reloc_count;
85e0c721 3242}
0f268757 3243
7a8b18b6 3244#ifndef NO_COFF_SYMBOLS
0f268757
SC
3245
3246/*
6724ff46 3247provided a BFD, a section and an offset into the section, calculate and
0f268757
SC
3248return the name of the source file and the line nearest to the wanted
3249location.
3250*/
3251
3252static boolean
3253DEFUN(coff_find_nearest_line,(abfd,
3254 section,
fb3be09b 3255 ignore_symbols,
0f268757
SC
3256 offset,
3257 filename_ptr,
3258 functionname_ptr,
3259 line_ptr),
3260 bfd *abfd AND
3261 asection *section AND
fb3be09b 3262 asymbol **ignore_symbols AND
0f268757
SC
3263 bfd_vma offset AND
3264 CONST char **filename_ptr AND
3265 CONST char **functionname_ptr AND
3266 unsigned int *line_ptr)
3267{
3268 static bfd *cache_abfd;
3269 static asection *cache_section;
3270 static bfd_vma cache_offset;
3271 static unsigned int cache_i;
3272 static alent *cache_l;
cbdc7909 3273
0f268757 3274 unsigned int i = 0;
fb3be09b 3275 coff_data_type *cof = coff_data(abfd);
0f268757 3276 /* Run through the raw syments if available */
6f715d66 3277 combined_entry_type *p;
0f268757
SC
3278 alent *l;
3279 unsigned int line_base = 0;
cbdc7909
JG
3280
3281
0f268757
SC
3282 *filename_ptr = 0;
3283 *functionname_ptr = 0;
3284 *line_ptr = 0;
cbdc7909 3285
0f268757 3286 /* Don't try and find line numbers in a non coff file */
0d740984 3287 if (abfd->xvec->flavour != bfd_target_coff_flavour)
0f268757 3288 return false;
cbdc7909 3289
fb3be09b 3290 if (cof == NULL)
0f268757 3291 return false;
6f715d66 3292
0f268757 3293 p = cof->raw_syments;
cbdc7909 3294
0f268757 3295 for (i = 0; i < cof->raw_syment_count; i++) {
6f715d66
SC
3296 if (p->u.syment.n_sclass == C_FILE) {
3297 /* File name has been moved into symbol */
3298 *filename_ptr = (char *) p->u.syment._n._n_n._n_offset;
0f268757
SC
3299 break;
3300 }
6f715d66 3301 p += 1 + p->u.syment.n_numaux;
0f268757
SC
3302 }
3303 /* Now wander though the raw linenumbers of the section */
3304 /*
6724ff46 3305 If this is the same BFD as we were previously called with and this is
0f268757
SC
3306 the same section, and the offset we want is further down then we can
3307 prime the lookup loop
3308 */
3309 if (abfd == cache_abfd &&
3310 section == cache_section &&
3311 offset >= cache_offset) {
3312 i = cache_i;
3313 l = cache_l;
3314 }
3315 else {
3316 i = 0;
3317 l = section->lineno;
3318 }
cbdc7909 3319
0f268757
SC
3320 for (; i < section->lineno_count; i++) {
3321 if (l->line_number == 0) {
3322 /* Get the symbol this line number points at */
3323 coff_symbol_type *coff = (coff_symbol_type *) (l->u.sym);
3324 *functionname_ptr = coff->symbol.name;
3325 if (coff->native) {
6f715d66
SC
3326 combined_entry_type *s = coff->native;
3327 s = s + 1 + s->u.syment.n_numaux;
0f268757
SC
3328 /*
3329 S should now point to the .bf of the function
3330 */
6f715d66 3331 if (s->u.syment.n_numaux) {
0f268757
SC
3332 /*
3333 The linenumber is stored in the auxent
3334 */
6f715d66 3335 union internal_auxent *a = &((s + 1)->u.auxent);
0f268757
SC
3336 line_base = a->x_sym.x_misc.x_lnsz.x_lnno;
3337 }
3338 }
3339 }
3340 else {
3341 if (l->u.offset > offset)
3342 break;
3343 *line_ptr = l->line_number + line_base + 1;
3344 }
3345 l++;
3346 }
cbdc7909 3347
0f268757
SC
3348 cache_abfd = abfd;
3349 cache_section = section;
3350 cache_offset = offset;
3351 cache_i = i;
3352 cache_l = l;
6f715d66 3353
0f268757
SC
3354 return true;
3355}
3356
3357#ifdef GNU960
3358file_ptr
3359coff_sym_filepos(abfd)
3360bfd *abfd;
3361 {
3362 return obj_sym_filepos(abfd);
3363 }
3364#endif
3365
7a8b18b6
SC
3366#endif /* NO_COFF_SYMBOLS */
3367
0f268757 3368
cbdc7909 3369static int
0f268757
SC
3370DEFUN(coff_sizeof_headers,(abfd, reloc),
3371 bfd *abfd AND
3372 boolean reloc)
85e0c721 3373{
0f268757 3374 size_t size;
cbdc7909 3375
0f268757 3376 if (reloc == false) {
85e0c721 3377 size = FILHSZ + AOUTSZ;
0f268757
SC
3378 }
3379 else {
85e0c721 3380 size = FILHSZ;
0f268757 3381 }
cbdc7909 3382
0f268757
SC
3383 size += abfd->section_count * SCNHSZ;
3384 return size;
85e0c721 3385}
0f268757
SC
3386
3387
3388#define coff_core_file_failing_command _bfd_dummy_core_file_failing_command
3389#define coff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
3390#define coff_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
3391#define coff_slurp_armap bfd_slurp_coff_armap
3392#define coff_slurp_extended_name_table _bfd_slurp_extended_name_table
3393#define coff_truncate_arname bfd_dont_truncate_arname
3394#define coff_openr_next_archived_file bfd_generic_openr_next_archived_file
3395#define coff_generic_stat_arch_elt bfd_generic_stat_arch_elt
3396#define coff_get_section_contents bfd_generic_get_section_contents
3397#define coff_close_and_cleanup bfd_generic_close_and_cleanup
6f715d66
SC
3398
3399#define coff_bfd_debug_info_start bfd_void
3400#define coff_bfd_debug_info_end bfd_void
41f50af0 3401#define coff_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
This page took 0.191837 seconds and 4 git commands to generate.