*** empty log message ***
[deliverable/binutils-gdb.git] / bfd / libaout.h
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
7 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
8
9 This file is part of BFD, the Binary File Diddler.
10
11 BFD is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 1, or (at your option)
14 any later version.
15
16 BFD is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with BFD; see the file COPYING. If not, write to
23 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24
25 /* $Id$ */
26
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
34 /* Parameterize the a.out code based on whether it is being built
35 for a 32-bit architecture or a 64-bit architecture. */
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
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)
59
60 #define obj_reloc_entry_size(bfd) (adata(bfd)->reloc_entry_size)
61
62 typedef struct aout_symbol {
63 asymbol symbol;
64 short desc;
65 char other;
66 unsigned char type;
67 } aout_symbol_type;
68
69 struct aoutdata {
70 struct internal_exec *hdr; /* exec file header */
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;
83
84 /* Size of a relocation entry */
85 unsigned reloc_entry_size;
86 };
87
88
89 #define obj_outsymbols(bfd) ((PTR)(((struct aoutdata *) ((bfd)->tdata))->outsymbols))
90
91
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 */
94 #define aout_symbol(asymbol) ((aout_symbol_type *)(&(asymbol)->the_bfd))
95
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
102 /* Prototype declarations for functions defined in aoutx.h */
103
104 PROTO (boolean, NAME(aout,squirt_out_relocs),(bfd *abfd, asection *section));
105
106 PROTO (bfd_target *, NAME(aout,some_aout_object_p), (bfd *abfd,
107 bfd_target *(*callback)()));
108 PROTO (boolean, NAME(aout,mkobject), (bfd *abfd));
109 PROTO (enum machine_type, NAME(aout,machine_type), (enum bfd_architecture arch,
110 unsigned long machine));
111 PROTO (boolean, NAME(aout,set_arch_mach), (bfd *abfd, enum bfd_architecture arch,
112 unsigned long machine));
113
114 PROTO (boolean, NAME(aout,new_section_hook), (bfd *abfd, asection *newsect));
115 PROTO (boolean, NAME(aout,set_section_contents), (bfd *abfd, sec_ptr section,
116 PTR location, file_ptr offset, bfd_size_type count));
117
118 PROTO (asymbol *,NAME(aout,make_empty_symbol), (bfd *abfd));
119 PROTO (boolean, NAME(aout,slurp_symbol_table), (bfd *abfd));
120 PROTO (void, NAME(aout,write_syms), (bfd *abfd));
121 PROTO (void, NAME(aout,reclaim_symbol_table), (bfd *abfd));
122 PROTO (unsigned int, NAME(aout,get_symtab_upper_bound), (bfd *abfd));
123 PROTO (unsigned int, NAME(aout,get_symtab), (bfd *abfd, asymbol **location));
124 PROTO (boolean, NAME(aout,slurp_reloc_table), (bfd *abfd, sec_ptr asect,
125 asymbol **symbols));
126 PROTO (unsigned int, NAME(aout,canonicalize_reloc), (bfd *abfd, sec_ptr section,
127 arelent **relptr, asymbol **symbols));
128 PROTO (unsigned int, NAME(aout,get_reloc_upper_bound), (bfd *abfd, sec_ptr asect));
129 PROTO (void, NAME(aout,reclaim_reloc), (bfd *ignore_abfd, sec_ptr ignore));
130 PROTO (alent *, NAME(aout,get_lineno), (bfd *ignore_abfd, asymbol *ignore_symbol));
131 PROTO (void, NAME(aout,print_symbol), (bfd *ignore_abfd, PTR file,
132 asymbol *symbol, bfd_print_symbol_enum_type how));
133 PROTO (boolean, NAME(aout,close_and_cleanup), (bfd *abfd));
134 PROTO (boolean, NAME(aout,find_nearest_line), (bfd *abfd, asection *section,
135 asymbol **symbols, bfd_vma offset, CONST char **filename_ptr,
136 CONST char **functionname_ptr, unsigned int *line_ptr));
137 PROTO (int, NAME(aout,sizeof_headers), (bfd *ignore_abfd, boolean exec));
138
139
140 PROTO (void, NAME(aout,swap_exec_header_in), (bfd *abfd,
141 struct external_exec *raw_bytes, struct internal_exec *execp));
142
143 PROTO (void, NAME(aout,swap_exec_header_out),(bfd *abfd, struct internal_exec *execp,
144 struct external_exec *raw_bytes));
145
146 /* A.out uses the generic versions of these routines... */
147
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.052494 seconds and 4 git commands to generate.