Add elf-*.h files.
[deliverable/binutils-gdb.git] / bfd / libaout.h
CommitLineData
69ebee86
JG
1/* BFD back-end data structures for a.out (and similar) files.
2
3 We try to encapsulate the differences in a few routines, and otherwise
4 share large masses of code. This means we only have to fix bugs in
5 one place, most of the time. */
6
4a81b561
DHW
7/* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
8
9This file is part of BFD, the Binary File Diddler.
10
11BFD is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 1, or (at your option)
14any later version.
15
16BFD is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with BFD; see the file COPYING. If not, write to
23the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24
25/* $Id$ */
26
c0e5039e
JG
27#ifdef __STDC__
28#define CAT3(a,b,c) a##b##c
29#else
30#define CAT3(a,b,c) a/**/b/**/c
31#endif
32
33
359f1dee
JG
34/* Parameterize the a.out code based on whether it is being built
35 for a 32-bit architecture or a 64-bit architecture. */
c0e5039e
JG
36#if ARCH_SIZE==64
37#define GET_WORD bfd_h_get_64
38#define GET_SWORD (int64_type)GET_WORD
39#define PUT_WORD bfd_h_put_64
40#define NAME(x,y) CAT3(x,_64_,y)
41#define JNAME(x) CAT(x,_64)
42#define BYTES_IN_WORD 8
43#else
44#define GET_WORD bfd_h_get_32
45#define GET_SWORD (int32_type)GET_WORD
46#define PUT_WORD bfd_h_put_32
47#define NAME(x,y) CAT3(x,_32_,y)
48#define JNAME(x) CAT(x,_32)
49#define BYTES_IN_WORD 4
50#endif
51
69ebee86
JG
52#define adata(bfd) ((struct aoutdata *) ((bfd)->tdata))
53#define exec_hdr(bfd) (adata(bfd)->hdr)
54#define obj_textsec(bfd) (adata(bfd)->textsec)
55#define obj_datasec(bfd) (adata(bfd)->datasec)
56#define obj_bsssec(bfd) (adata(bfd)->bsssec)
57#define obj_sym_filepos(bfd) (adata(bfd)->sym_filepos)
58#define obj_str_filepos(bfd) (adata(bfd)->str_filepos)
4a81b561 59
69ebee86 60#define obj_reloc_entry_size(bfd) (adata(bfd)->reloc_entry_size)
4a81b561 61
69ebee86 62typedef struct aout_symbol {
4a81b561
DHW
63 asymbol symbol;
64 short desc;
69ebee86
JG
65 char other;
66 unsigned char type;
4a81b561
DHW
67} aout_symbol_type;
68
69ebee86 69struct aoutdata {
c0e5039e 70 struct internal_exec *hdr; /* exec file header */
4a81b561
DHW
71 aout_symbol_type *symbols; /* symtab for input bfd */
72
73
74 /* For ease, we do this */
75 asection *textsec;
76 asection *datasec;
77 asection *bsssec;
78
79 /* We remember these offsets so that after check_file_format, we have
80 no dependencies on the particular format of the exec_hdr. */
81 file_ptr sym_filepos;
82 file_ptr str_filepos;
4a81b561 83
69ebee86
JG
84 /* Size of a relocation entry */
85 unsigned reloc_entry_size;
86};
4a81b561 87
4a81b561 88
69ebee86 89#define obj_outsymbols(bfd) ((PTR)(((struct aoutdata *) ((bfd)->tdata))->outsymbols))
4a81b561
DHW
90
91
fc723380
JG
92/* We take the address of the first element of an asymbol to ensure that the
93 * macro is only ever applied to an asymbol */
4a81b561
DHW
94#define aout_symbol(asymbol) ((aout_symbol_type *)(&(asymbol)->the_bfd))
95
69ebee86
JG
96/*#define obj_symbols(bfd) ((((struct aoutdata *) ((bfd)->tdata))->symbols))*/
97#define obj_aout_symbols(bfd) ((((struct aoutdata *) (bfd)->tdata))->symbols)
98#define obj_arch_flags(bfd) ((((struct aoutdata *) (bfd)->tdata))->arch_flags)
99
100#define get_tdata(x) ((struct aoutdata *)((x)->tdata))
101
c0e5039e 102/* Prototype declarations for functions defined in aoutx.h */
69ebee86 103
c0e5039e 104PROTO (boolean, NAME(aout,squirt_out_relocs),(bfd *abfd, asection *section));
69ebee86 105
c0e5039e 106PROTO (bfd_target *, NAME(aout,some_aout_object_p), (bfd *abfd,
69ebee86 107 bfd_target *(*callback)()));
c0e5039e
JG
108PROTO (boolean, NAME(aout,mkobject), (bfd *abfd));
109PROTO (enum machine_type, NAME(aout,machine_type), (enum bfd_architecture arch,
69ebee86 110 unsigned long machine));
c0e5039e 111PROTO (boolean, NAME(aout,set_arch_mach), (bfd *abfd, enum bfd_architecture arch,
69ebee86
JG
112 unsigned long machine));
113
c0e5039e
JG
114PROTO (boolean, NAME(aout,new_section_hook), (bfd *abfd, asection *newsect));
115PROTO (boolean, NAME(aout,set_section_contents), (bfd *abfd, sec_ptr section,
116 PTR location, file_ptr offset, bfd_size_type count));
117
118PROTO (asymbol *,NAME(aout,make_empty_symbol), (bfd *abfd));
119PROTO (boolean, NAME(aout,slurp_symbol_table), (bfd *abfd));
120PROTO (void, NAME(aout,write_syms), (bfd *abfd));
121PROTO (void, NAME(aout,reclaim_symbol_table), (bfd *abfd));
122PROTO (unsigned int, NAME(aout,get_symtab_upper_bound), (bfd *abfd));
123PROTO (unsigned int, NAME(aout,get_symtab), (bfd *abfd, asymbol **location));
124PROTO (boolean, NAME(aout,slurp_reloc_table), (bfd *abfd, sec_ptr asect,
69ebee86 125 asymbol **symbols));
c0e5039e 126PROTO (unsigned int, NAME(aout,canonicalize_reloc), (bfd *abfd, sec_ptr section,
69ebee86 127 arelent **relptr, asymbol **symbols));
c0e5039e
JG
128PROTO (unsigned int, NAME(aout,get_reloc_upper_bound), (bfd *abfd, sec_ptr asect));
129PROTO (void, NAME(aout,reclaim_reloc), (bfd *ignore_abfd, sec_ptr ignore));
130PROTO (alent *, NAME(aout,get_lineno), (bfd *ignore_abfd, asymbol *ignore_symbol));
131PROTO (void, NAME(aout,print_symbol), (bfd *ignore_abfd, PTR file,
69ebee86 132 asymbol *symbol, bfd_print_symbol_enum_type how));
c0e5039e
JG
133PROTO (boolean, NAME(aout,close_and_cleanup), (bfd *abfd));
134PROTO (boolean, NAME(aout,find_nearest_line), (bfd *abfd, asection *section,
69ebee86
JG
135 asymbol **symbols, bfd_vma offset, CONST char **filename_ptr,
136 CONST char **functionname_ptr, unsigned int *line_ptr));
c0e5039e 137PROTO (int, NAME(aout,sizeof_headers), (bfd *ignore_abfd, boolean exec));
69ebee86 138
69ebee86 139
c0e5039e
JG
140PROTO (void, NAME(aout,swap_exec_header_in), (bfd *abfd,
141 struct external_exec *raw_bytes, struct internal_exec *execp));
69ebee86 142
c0e5039e
JG
143PROTO (void, NAME(aout,swap_exec_header_out),(bfd *abfd, struct internal_exec *execp,
144 struct external_exec *raw_bytes));
69ebee86
JG
145
146/* A.out uses the generic versions of these routines... */
147
c0e5039e
JG
148#define aout_32_get_section_contents bfd_generic_get_section_contents
149#define aout_32_close_and_cleanup bfd_generic_close_and_cleanup
150
151#define aout_64_get_section_contents bfd_generic_get_section_contents
152#define aout_64_close_and_cleanup bfd_generic_close_and_cleanup
153
154/* Calculate the file positions of the parts of a newly read aout header */
155#define WORK_OUT_FILE_POSITIONS(abfd, execp) \
156 obj_datasec (abfd)->vma = N_DATADDR(*execp); \
157 obj_bsssec (abfd)->vma = N_BSSADDR(*execp); \
158 obj_textsec (abfd)->vma = N_TXTADDR(*execp); \
159 \
160 /* The file offsets of the sections */ \
161 obj_textsec (abfd)->filepos = N_TXTOFF (*execp); \
162 obj_datasec (abfd)->filepos = N_DATOFF (*execp); \
163 \
164 /* The file offsets of the relocation info */ \
165 obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp); \
166 obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp); \
167 \
168 /* The file offsets of the string table and symbol table. */ \
169 obj_sym_filepos (abfd) = N_SYMOFF (*execp); \
170 obj_str_filepos (abfd) = N_STROFF (*execp); \
171
172
173#define WRITE_HEADERS(abfd, execp) \
174 { \
175 if (abfd->flags & D_PAGED) \
176 { \
177 execp->a_text = obj_textsec (abfd)->size + EXEC_BYTES_SIZE; \
178 N_SET_MAGIC (*execp, ZMAGIC); \
179 } \
180 else if (abfd->flags & WP_TEXT) \
181 { \
182 N_SET_MAGIC (*execp, NMAGIC); \
183 } \
184 else { \
185 N_SET_MAGIC(*execp, OMAGIC); \
186 } \
187 if (abfd->flags & D_PAGED) \
188 { \
189 data_pad = ((obj_datasec(abfd)->size + PAGE_SIZE -1) \
190 & (- PAGE_SIZE)) - obj_datasec(abfd)->size; \
191 \
192 if (data_pad > obj_bsssec(abfd)->size) \
193 execp->a_bss = 0; \
194 else \
195 execp->a_bss = obj_bsssec(abfd)->size - data_pad; \
196 execp->a_data = obj_datasec(abfd)->size + data_pad; \
197 } \
198 else \
199 { \
200 execp->a_data = obj_datasec (abfd)->size; \
201 execp->a_bss = obj_bsssec (abfd)->size; \
202 } \
203 \
204 execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_LIST_SIZE; \
205 execp->a_entry = bfd_get_start_address (abfd); \
206 \
207 execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * \
208 obj_reloc_entry_size (abfd)); \
209 execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * \
210 obj_reloc_entry_size (abfd)); \
211 NAME(aout,swap_exec_header_out) (abfd, execp, &exec_bytes); \
212 \
213 bfd_seek (abfd, 0L, false); \
214 bfd_write ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd); \
215 /* Now write out reloc info, followed by syms and strings */ \
216 \
217 if (bfd_get_symcount (abfd) != 0) \
218 { \
219 bfd_seek (abfd, \
220 (long)(N_SYMOFF(*execp)), false); \
221 \
222 NAME(aout,write_syms)(abfd); \
223 \
224 bfd_seek (abfd, (long)(N_TRELOFF(*execp)), false); \
225 \
226 if (!NAME(aout,squirt_out_relocs) (abfd, obj_textsec (abfd))) return false; \
227 bfd_seek (abfd, (long)(N_DRELOFF(*execp)), false); \
228 \
229 if (!NAME(aout,squirt_out_relocs)(abfd, obj_datasec (abfd))) return false; \
230 } \
231 }
This page took 0.041664 seconds and 4 git commands to generate.