1 |
684 |
jeremybenn |
/* AIX cross support for collect2.
|
2 |
|
|
Copyright (C) 2009 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GCC.
|
5 |
|
|
|
6 |
|
|
GCC is free software; you can redistribute it and/or modify it under
|
7 |
|
|
the terms of the GNU General Public License as published by the Free
|
8 |
|
|
Software Foundation; either version 3, or (at your option) any later
|
9 |
|
|
version.
|
10 |
|
|
|
11 |
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
12 |
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13 |
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
14 |
|
|
for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with GCC; see the file COPYING3. If not see
|
18 |
|
|
<http://www.gnu.org/licenses/>. */
|
19 |
|
|
|
20 |
|
|
/* collect2-aix.c requires mmap support. It should otherwise be
|
21 |
|
|
fairly portable. */
|
22 |
|
|
#if defined(CROSS_DIRECTORY_STRUCTURE) \
|
23 |
|
|
&& defined(TARGET_AIX_VERSION) \
|
24 |
|
|
&& HAVE_MMAP
|
25 |
|
|
|
26 |
|
|
#define CROSS_AIX_SUPPORT 1
|
27 |
|
|
|
28 |
|
|
/* -------------------------------------------------------------------------
|
29 |
|
|
Definitions adapted from bfd. (Fairly heavily adapted in some cases.)
|
30 |
|
|
------------------------------------------------------------------------- */
|
31 |
|
|
|
32 |
|
|
/* Compatiblity types for bfd. */
|
33 |
|
|
typedef unsigned HOST_WIDE_INT bfd_vma;
|
34 |
|
|
|
35 |
|
|
/* The size of an archive's fl_magic field. */
|
36 |
|
|
#define FL_MAGIC_SIZE 8
|
37 |
|
|
|
38 |
|
|
/* The expected contents of fl_magic for big archives. */
|
39 |
|
|
#define FL_MAGIC_BIG_AR "<bigaf>\012"
|
40 |
|
|
|
41 |
|
|
/* The size of each offset string in the header of a big archive. */
|
42 |
|
|
#define AR_BIG_OFFSET_SIZE 20
|
43 |
|
|
|
44 |
|
|
/* The format of the file header in a "big" XCOFF archive. */
|
45 |
|
|
struct external_big_ar_filehdr
|
46 |
|
|
{
|
47 |
|
|
/* Magic string. */
|
48 |
|
|
char fl_magic[FL_MAGIC_SIZE];
|
49 |
|
|
|
50 |
|
|
/* Offset of the member table (decimal ASCII string). */
|
51 |
|
|
char fl_memoff[AR_BIG_OFFSET_SIZE];
|
52 |
|
|
|
53 |
|
|
/* Offset of the global symbol table for 32-bit objects (decimal ASCII
|
54 |
|
|
string). */
|
55 |
|
|
char fl_symoff[AR_BIG_OFFSET_SIZE];
|
56 |
|
|
|
57 |
|
|
/* Offset of the global symbol table for 64-bit objects (decimal ASCII
|
58 |
|
|
string). */
|
59 |
|
|
char fl_symoff64[AR_BIG_OFFSET_SIZE];
|
60 |
|
|
|
61 |
|
|
/* Offset of the first member in the archive (decimal ASCII string). */
|
62 |
|
|
char fl_firstmemoff[AR_BIG_OFFSET_SIZE];
|
63 |
|
|
|
64 |
|
|
/* Offset of the last member in the archive (decimal ASCII string). */
|
65 |
|
|
char fl_lastmemoff[AR_BIG_OFFSET_SIZE];
|
66 |
|
|
|
67 |
|
|
/* Offset of the first member on the free list (decimal ASCII
|
68 |
|
|
string). */
|
69 |
|
|
char fl_freeoff[AR_BIG_OFFSET_SIZE];
|
70 |
|
|
};
|
71 |
|
|
|
72 |
|
|
/* Each archive name is followed by this many bytes of magic string. */
|
73 |
|
|
#define SXCOFFARFMAG 2
|
74 |
|
|
|
75 |
|
|
/* The format of a member header in a "big" XCOFF archive. */
|
76 |
|
|
struct external_big_ar_member
|
77 |
|
|
{
|
78 |
|
|
/* File size not including the header (decimal ASCII string). */
|
79 |
|
|
char ar_size[AR_BIG_OFFSET_SIZE];
|
80 |
|
|
|
81 |
|
|
/* File offset of next archive member (decimal ASCII string). */
|
82 |
|
|
char ar_nextoff[AR_BIG_OFFSET_SIZE];
|
83 |
|
|
|
84 |
|
|
/* File offset of previous archive member (decimal ASCII string). */
|
85 |
|
|
char ar_prevoff[AR_BIG_OFFSET_SIZE];
|
86 |
|
|
|
87 |
|
|
/* File mtime (decimal ASCII string). */
|
88 |
|
|
char ar_date[12];
|
89 |
|
|
|
90 |
|
|
/* File UID (decimal ASCII string). */
|
91 |
|
|
char ar_uid[12];
|
92 |
|
|
|
93 |
|
|
/* File GID (decimal ASCII string). */
|
94 |
|
|
char ar_gid[12];
|
95 |
|
|
|
96 |
|
|
/* File mode (octal ASCII string). */
|
97 |
|
|
char ar_mode[12];
|
98 |
|
|
|
99 |
|
|
/* Length of file name (decimal ASCII string). */
|
100 |
|
|
char ar_namlen[4];
|
101 |
|
|
|
102 |
|
|
/* This structure is followed by the file name. The length of the
|
103 |
|
|
name is given in the namlen field. If the length of the name is
|
104 |
|
|
odd, the name is followed by a null byte. The name and optional
|
105 |
|
|
null byte are followed by XCOFFARFMAG, which is not included in
|
106 |
|
|
namlen. The contents of the archive member follow; the number of
|
107 |
|
|
bytes is given in the size field. */
|
108 |
|
|
};
|
109 |
|
|
|
110 |
|
|
/* The known values of f_magic in an XCOFF file header. */
|
111 |
|
|
#define U802WRMAGIC 0730 /* Writeable text segments. */
|
112 |
|
|
#define U802ROMAGIC 0735 /* Readonly sharable text segments. */
|
113 |
|
|
#define U802TOCMAGIC 0737 /* Readonly text segments and TOC. */
|
114 |
|
|
#define U803XTOCMAGIC 0757 /* Aix 4.3 64-bit XCOFF. */
|
115 |
|
|
#define U64_TOCMAGIC 0767 /* AIX 5+ 64-bit XCOFF. */
|
116 |
|
|
|
117 |
|
|
/* The number of bytes in an XCOFF file's f_magic field. */
|
118 |
|
|
#define F_MAGIC_SIZE 2
|
119 |
|
|
|
120 |
|
|
/* The format of a 32-bit XCOFF file header. */
|
121 |
|
|
struct external_filehdr_32
|
122 |
|
|
{
|
123 |
|
|
/* The magic number. */
|
124 |
|
|
char f_magic[F_MAGIC_SIZE];
|
125 |
|
|
|
126 |
|
|
/* The number of sections. */
|
127 |
|
|
char f_nscns[2];
|
128 |
|
|
|
129 |
|
|
/* Time & date stamp. */
|
130 |
|
|
char f_timdat[4];
|
131 |
|
|
|
132 |
|
|
/* The offset of the symbol table from the start of the file. */
|
133 |
|
|
char f_symptr[4];
|
134 |
|
|
|
135 |
|
|
/* The number of entries in the symbol table. */
|
136 |
|
|
char f_nsyms[4];
|
137 |
|
|
|
138 |
|
|
/* The size of the auxillary header. */
|
139 |
|
|
char f_opthdr[2];
|
140 |
|
|
|
141 |
|
|
/* Flags. */
|
142 |
|
|
char f_flags[2];
|
143 |
|
|
};
|
144 |
|
|
|
145 |
|
|
/* The format of a 64-bit XCOFF file header. */
|
146 |
|
|
struct external_filehdr_64
|
147 |
|
|
{
|
148 |
|
|
/* The magic number. */
|
149 |
|
|
char f_magic[F_MAGIC_SIZE];
|
150 |
|
|
|
151 |
|
|
/* The number of sections. */
|
152 |
|
|
char f_nscns[2];
|
153 |
|
|
|
154 |
|
|
/* Time & date stamp. */
|
155 |
|
|
char f_timdat[4];
|
156 |
|
|
|
157 |
|
|
/* The offset of the symbol table from the start of the file. */
|
158 |
|
|
char f_symptr[8];
|
159 |
|
|
|
160 |
|
|
/* The size of the auxillary header. */
|
161 |
|
|
char f_opthdr[2];
|
162 |
|
|
|
163 |
|
|
/* Flags. */
|
164 |
|
|
char f_flags[2];
|
165 |
|
|
|
166 |
|
|
/* The number of entries in the symbol table. */
|
167 |
|
|
char f_nsyms[4];
|
168 |
|
|
};
|
169 |
|
|
|
170 |
|
|
/* An internal representation of the XCOFF file header. */
|
171 |
|
|
struct internal_filehdr
|
172 |
|
|
{
|
173 |
|
|
unsigned short f_magic;
|
174 |
|
|
unsigned short f_nscns;
|
175 |
|
|
long f_timdat;
|
176 |
|
|
bfd_vma f_symptr;
|
177 |
|
|
long f_nsyms;
|
178 |
|
|
unsigned short f_opthdr;
|
179 |
|
|
unsigned short f_flags;
|
180 |
|
|
};
|
181 |
|
|
|
182 |
|
|
/* Symbol classes have their names in the debug section if this flag
|
183 |
|
|
is set. */
|
184 |
|
|
#define DBXMASK 0x80
|
185 |
|
|
|
186 |
|
|
/* The format of an XCOFF symbol-table entry. */
|
187 |
|
|
struct external_syment
|
188 |
|
|
{
|
189 |
|
|
union {
|
190 |
|
|
struct {
|
191 |
|
|
union {
|
192 |
|
|
/* The name of the symbol. There is an implicit null character
|
193 |
|
|
after the end of the array. */
|
194 |
|
|
char n_name[8];
|
195 |
|
|
struct {
|
196 |
|
|
/* If n_zeroes is zero, n_offset is the offset the name from
|
197 |
|
|
the start of the string table. */
|
198 |
|
|
char n_zeroes[4];
|
199 |
|
|
char n_offset[4];
|
200 |
|
|
} u;
|
201 |
|
|
} u;
|
202 |
|
|
|
203 |
|
|
/* The symbol's value. */
|
204 |
|
|
char n_value[4];
|
205 |
|
|
} xcoff32;
|
206 |
|
|
struct {
|
207 |
|
|
/* The symbol's value. */
|
208 |
|
|
char n_value[8];
|
209 |
|
|
|
210 |
|
|
/* The offset of the symbol from the start of the string table. */
|
211 |
|
|
char n_offset[4];
|
212 |
|
|
} xcoff64;
|
213 |
|
|
} u;
|
214 |
|
|
|
215 |
|
|
/* The number of the section to which this symbol belongs. */
|
216 |
|
|
char n_scnum[2];
|
217 |
|
|
|
218 |
|
|
/* The type of symbol. (It can be interpreted as an n_lang
|
219 |
|
|
and an n_cpu byte, but we don't care about that here.) */
|
220 |
|
|
char n_type[2];
|
221 |
|
|
|
222 |
|
|
/* The class of symbol (a C_* value). */
|
223 |
|
|
char n_sclass[1];
|
224 |
|
|
|
225 |
|
|
/* The number of auxillary symbols attached to this entry. */
|
226 |
|
|
char n_numaux[1];
|
227 |
|
|
};
|
228 |
|
|
|
229 |
|
|
/* Definitions required by collect2. */
|
230 |
|
|
#define C_EXT 2
|
231 |
|
|
|
232 |
|
|
#define F_SHROBJ 0x2000
|
233 |
|
|
|
234 |
|
|
#define N_UNDEF ((short) 0)
|
235 |
|
|
#define N_TMASK 060
|
236 |
|
|
#define N_BTSHFT 4
|
237 |
|
|
|
238 |
|
|
#define DT_NON 0
|
239 |
|
|
#define DT_FCN 2
|
240 |
|
|
|
241 |
|
|
/* -------------------------------------------------------------------------
|
242 |
|
|
Local code.
|
243 |
|
|
------------------------------------------------------------------------- */
|
244 |
|
|
|
245 |
|
|
/* An internal representation of an XCOFF symbol-table entry,
|
246 |
|
|
which is associated with the API-defined SYMENT type. */
|
247 |
|
|
struct internal_syment
|
248 |
|
|
{
|
249 |
|
|
char n_name[9];
|
250 |
|
|
unsigned int n_zeroes;
|
251 |
|
|
bfd_vma n_offset;
|
252 |
|
|
bfd_vma n_value;
|
253 |
|
|
short n_scnum;
|
254 |
|
|
unsigned short n_flags;
|
255 |
|
|
unsigned short n_type;
|
256 |
|
|
unsigned char n_sclass;
|
257 |
|
|
unsigned char n_numaux;
|
258 |
|
|
};
|
259 |
|
|
typedef struct internal_syment SYMENT;
|
260 |
|
|
|
261 |
|
|
/* The internal representation of the API-defined LDFILE type. */
|
262 |
|
|
struct internal_ldfile
|
263 |
|
|
{
|
264 |
|
|
/* The file handle for the associated file, or -1 if it hasn't been
|
265 |
|
|
opened yet. */
|
266 |
|
|
int fd;
|
267 |
|
|
|
268 |
|
|
/* The start of the current XCOFF object, if one has been mapped
|
269 |
|
|
into memory. Null otherwise. */
|
270 |
|
|
char *object;
|
271 |
|
|
|
272 |
|
|
/* The offset of OBJECT from the start of the containing page. */
|
273 |
|
|
size_t page_offset;
|
274 |
|
|
|
275 |
|
|
/* The size of the file pointed to by OBJECT. Valid iff OFFSET
|
276 |
|
|
is nonnull. */
|
277 |
|
|
size_t object_size;
|
278 |
|
|
|
279 |
|
|
/* The offset of the next member in an archive after OBJECT,
|
280 |
|
|
or -1 if this isn't an archive. Valid iff OFFSET is nonnull. */
|
281 |
|
|
off_t next_member;
|
282 |
|
|
|
283 |
|
|
/* The parsed version of the XCOFF file header. */
|
284 |
|
|
struct internal_filehdr filehdr;
|
285 |
|
|
};
|
286 |
|
|
typedef struct internal_ldfile LDFILE;
|
287 |
|
|
|
288 |
|
|
/* The API allows the file header to be directly accessed via this macro. */
|
289 |
|
|
#define HEADER(FILE) ((FILE)->filehdr)
|
290 |
|
|
|
291 |
|
|
/* API-defined return codes. SUCCESS must be > 0 and FAILURE must be <= 0. */
|
292 |
|
|
#define SUCCESS 1
|
293 |
|
|
#define FAILURE 0
|
294 |
|
|
|
295 |
|
|
/* API-defined functions. */
|
296 |
|
|
extern LDFILE *ldopen (char *, LDFILE *);
|
297 |
|
|
extern char *ldgetname (LDFILE *, SYMENT *);
|
298 |
|
|
extern int ldtbread (LDFILE *, long, SYMENT *);
|
299 |
|
|
extern int ldclose (LDFILE *);
|
300 |
|
|
|
301 |
|
|
#endif
|