1 | /* IBM RS/6000 "XCOFF" back-end for BFD.
|
---|
2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
|
---|
3 | 2001, 2002
|
---|
4 | Free Software Foundation, Inc.
|
---|
5 | FIXME: Can someone provide a transliteration of this name into ASCII?
|
---|
6 | Using the following chars caused a compiler warning on HIUX (so I replaced
|
---|
7 | them with octal escapes), and isn't useful without an understanding of what
|
---|
8 | character set it is.
|
---|
9 | Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365,
|
---|
10 | and John Gilmore.
|
---|
11 | Archive support from Damon A. Permezel.
|
---|
12 | Contributed by IBM Corporation and Cygnus Support.
|
---|
13 |
|
---|
14 | This file is part of BFD, the Binary File Descriptor library.
|
---|
15 |
|
---|
16 | This program is free software; you can redistribute it and/or modify
|
---|
17 | it under the terms of the GNU General Public License as published by
|
---|
18 | the Free Software Foundation; either version 2 of the License, or
|
---|
19 | (at your option) any later version.
|
---|
20 |
|
---|
21 | This program is distributed in the hope that it will be useful,
|
---|
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
24 | GNU General Public License for more details.
|
---|
25 |
|
---|
26 | You should have received a copy of the GNU General Public License
|
---|
27 | along with this program; if not, write to the Free Software
|
---|
28 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
---|
29 |
|
---|
30 | /* This port currently only handles reading object files, except when
|
---|
31 | compiled on an RS/6000 host. -- no archive support, no core files.
|
---|
32 | In all cases, it does not support writing.
|
---|
33 |
|
---|
34 | This is in a separate file from coff-rs6000.c, because it includes
|
---|
35 | system include files that conflict with coff/rs6000.h. */
|
---|
36 |
|
---|
37 | /* Internalcoff.h and coffcode.h modify themselves based on this flag. */
|
---|
38 | #define RS6000COFF_C 1
|
---|
39 |
|
---|
40 | /* The AIX 4.1 kernel is obviously compiled with -D_LONG_LONG, so
|
---|
41 | we have to define _LONG_LONG for older versions of gcc to get the
|
---|
42 | proper alignments in the user structure. */
|
---|
43 | #if defined(_AIX41) && !defined(_LONG_LONG)
|
---|
44 | #define _LONG_LONG
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #include "bfd.h"
|
---|
48 | #include "sysdep.h"
|
---|
49 | #include "libbfd.h"
|
---|
50 |
|
---|
51 | #ifdef AIX_CORE
|
---|
52 |
|
---|
53 | /* AOUTHDR is defined by the above. We need another defn of it, from the
|
---|
54 | system include files. Punt the old one and get us a new name for the
|
---|
55 | typedef in the system include files. */
|
---|
56 | #ifdef AOUTHDR
|
---|
57 | #undef AOUTHDR
|
---|
58 | #endif
|
---|
59 | #define AOUTHDR second_AOUTHDR
|
---|
60 |
|
---|
61 | #undef SCNHDR
|
---|
62 |
|
---|
63 | /* ------------------------------------------------------------------------ */
|
---|
64 | /* Support for core file stuff.. */
|
---|
65 | /* ------------------------------------------------------------------------ */
|
---|
66 |
|
---|
67 | #include <sys/user.h>
|
---|
68 | #define __LDINFO_PTRACE32__ /* for __ld_info32 */
|
---|
69 | #define __LDINFO_PTRACE64__ /* for __ld_info64 */
|
---|
70 | #include <sys/ldr.h>
|
---|
71 | #include <sys/core.h>
|
---|
72 | #include <sys/systemcfg.h>
|
---|
73 |
|
---|
74 | #define core_hdr(bfd) ((CoreHdr *) bfd->tdata.any)
|
---|
75 |
|
---|
76 | /* AIX 4.1 changed the names and locations of a few items in the core file.
|
---|
77 | AIX 4.3 defined an entirely new structure, core_dumpx, but kept support for
|
---|
78 | the previous 4.1 structure, core_dump.
|
---|
79 |
|
---|
80 | AIX_CORE_DUMPX_CORE is defined (by configure) on AIX 4.3+, and
|
---|
81 | CORE_VERSION_1 is defined (by AIX core.h) as 2 on AIX 4.3+ and as 1 on AIX
|
---|
82 | 4.1 and 4.2. AIX pre-4.1 (aka 3.x) either doesn't define CORE_VERSION_1
|
---|
83 | or else defines it as 0. */
|
---|
84 |
|
---|
85 | #if defined(CORE_VERSION_1) && !CORE_VERSION_1
|
---|
86 | # undef CORE_VERSION_1
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | /* The following union and macros allow this module to compile on all AIX
|
---|
90 | versions and to handle both core_dumpx and core_dump on 4.3+. CNEW_*()
|
---|
91 | and COLD_*() macros respectively retrieve core_dumpx and core_dump
|
---|
92 | values. */
|
---|
93 |
|
---|
94 | /* Union of 32-bit and 64-bit versions of ld_info. */
|
---|
95 |
|
---|
96 | typedef union {
|
---|
97 | #ifdef __ld_info32
|
---|
98 | struct __ld_info32 l32;
|
---|
99 | struct __ld_info64 l64;
|
---|
100 | #else
|
---|
101 | struct ld_info l32;
|
---|
102 | struct ld_info l64;
|
---|
103 | #endif
|
---|
104 | } LdInfo;
|
---|
105 |
|
---|
106 | /* Union of old and new core dump structures. */
|
---|
107 |
|
---|
108 | typedef union {
|
---|
109 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
110 | struct core_dumpx new; /* new AIX 4.3+ core dump */
|
---|
111 | #else
|
---|
112 | struct core_dump new; /* for simpler coding */
|
---|
113 | #endif
|
---|
114 | struct core_dump old; /* old AIX 4.2- core dump, still used on
|
---|
115 | 4.3+ with appropriate SMIT config */
|
---|
116 | } CoreHdr;
|
---|
117 |
|
---|
118 | /* Union of old and new vm_info structures. */
|
---|
119 |
|
---|
120 | #ifdef CORE_VERSION_1
|
---|
121 | typedef union {
|
---|
122 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
123 | struct vm_infox new;
|
---|
124 | #else
|
---|
125 | struct vm_info new;
|
---|
126 | #endif
|
---|
127 | struct vm_info old;
|
---|
128 | } VmInfo;
|
---|
129 | #endif
|
---|
130 |
|
---|
131 | /* Return whether CoreHdr C is in new or old format. */
|
---|
132 |
|
---|
133 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
134 | # define CORE_NEW(c) (!(c).old.c_entries)
|
---|
135 | #else
|
---|
136 | # define CORE_NEW(c) 0
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | /* Return the c_stackorg field from struct core_dumpx C. */
|
---|
140 |
|
---|
141 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
142 | # define CNEW_STACKORG(c) (c).c_stackorg
|
---|
143 | #else
|
---|
144 | # define CNEW_STACKORG(c) 0
|
---|
145 | #endif
|
---|
146 |
|
---|
147 | /* Return the offset to the loader region from struct core_dump C. */
|
---|
148 |
|
---|
149 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
150 | # define CNEW_LOADER(c) (c).c_loader
|
---|
151 | #else
|
---|
152 | # define CNEW_LOADER(c) 0
|
---|
153 | #endif
|
---|
154 |
|
---|
155 | /* Return the offset to the loader region from struct core_dump C. */
|
---|
156 |
|
---|
157 | #define COLD_LOADER(c) (c).c_tab
|
---|
158 |
|
---|
159 | /* Return the c_lsize field from struct core_dumpx C. */
|
---|
160 |
|
---|
161 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
162 | # define CNEW_LSIZE(c) (c).c_lsize
|
---|
163 | #else
|
---|
164 | # define CNEW_LSIZE(c) 0
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | /* Return the c_dataorg field from struct core_dumpx C. */
|
---|
168 |
|
---|
169 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
170 | # define CNEW_DATAORG(c) (c).c_dataorg
|
---|
171 | #else
|
---|
172 | # define CNEW_DATAORG(c) 0
|
---|
173 | #endif
|
---|
174 |
|
---|
175 | /* Return the c_datasize field from struct core_dumpx C. */
|
---|
176 |
|
---|
177 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
178 | # define CNEW_DATASIZE(c) (c).c_datasize
|
---|
179 | #else
|
---|
180 | # define CNEW_DATASIZE(c) 0
|
---|
181 | #endif
|
---|
182 |
|
---|
183 | /* Return the c_impl field from struct core_dumpx C. */
|
---|
184 |
|
---|
185 | #if defined (HAVE_ST_C_IMPL) || defined (AIX_5_CORE)
|
---|
186 | # define CNEW_IMPL(c) (c).c_impl
|
---|
187 | #else
|
---|
188 | # define CNEW_IMPL(c) 0
|
---|
189 | #endif
|
---|
190 |
|
---|
191 | /* Return the command string from struct core_dumpx C. */
|
---|
192 |
|
---|
193 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
194 | # define CNEW_COMM(c) (c).c_u.U_proc.pi_comm
|
---|
195 | #else
|
---|
196 | # define CNEW_COMM(c) 0
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | /* Return the command string from struct core_dump C. */
|
---|
200 |
|
---|
201 | #ifdef CORE_VERSION_1
|
---|
202 | # define COLD_COMM(c) (c).c_u.U_comm
|
---|
203 | #else
|
---|
204 | # define COLD_COMM(c) (c).c_u.u_comm
|
---|
205 | #endif
|
---|
206 |
|
---|
207 | /* Return the struct __context64 pointer from struct core_dumpx C. */
|
---|
208 |
|
---|
209 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
210 | # define CNEW_CONTEXT64(c) (c).c_flt.hctx.r64
|
---|
211 | #else
|
---|
212 | # define CNEW_CONTEXT64(c) c
|
---|
213 | #endif
|
---|
214 |
|
---|
215 | /* Return the struct mstsave pointer from struct core_dumpx C. */
|
---|
216 |
|
---|
217 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
218 | # define CNEW_MSTSAVE(c) (c).c_flt.hctx.r32
|
---|
219 | #else
|
---|
220 | # define CNEW_MSTSAVE(c) c
|
---|
221 | #endif
|
---|
222 |
|
---|
223 | /* Return the struct mstsave pointer from struct core_dump C. */
|
---|
224 |
|
---|
225 | #ifdef CORE_VERSION_1
|
---|
226 | # define COLD_MSTSAVE(c) (c).c_mst
|
---|
227 | #else
|
---|
228 | # define COLD_MSTSAVE(c) (c).c_u.u_save
|
---|
229 | #endif
|
---|
230 |
|
---|
231 | /* Return whether struct core_dumpx is from a 64-bit process. */
|
---|
232 |
|
---|
233 | #ifdef AIX_CORE_DUMPX_CORE
|
---|
234 | # define CNEW_PROC64(c) IS_PROC64(&(c).c_u.U_proc)
|
---|
235 | #else
|
---|
236 | # define CNEW_PROC64(c) 0
|
---|
237 | #endif
|
---|
238 |
|
---|
239 | /* Magic end-of-stack addresses for old core dumps. This is _very_ fragile,
|
---|
240 | but I don't see any easy way to get that info right now. */
|
---|
241 |
|
---|
242 | #ifdef CORE_VERSION_1
|
---|
243 | # define COLD_STACKEND 0x2ff23000
|
---|
244 | #else
|
---|
245 | # define COLD_STACKEND 0x2ff80000
|
---|
246 | #endif
|
---|
247 |
|
---|
248 | /* Size of the leading portion that old and new core dump structures have in
|
---|
249 | common. */
|
---|
250 | #define CORE_COMMONSZ ((int) &((struct core_dump *) 0)->c_entries \
|
---|
251 | + sizeof (((struct core_dump *) 0)->c_entries))
|
---|
252 |
|
---|
253 | /* Try to read into CORE the header from the core file associated with ABFD.
|
---|
254 | Return success. */
|
---|
255 |
|
---|
256 | static bfd_boolean
|
---|
257 | read_hdr (bfd *abfd, CoreHdr *core)
|
---|
258 | {
|
---|
259 | bfd_size_type size;
|
---|
260 |
|
---|
261 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
|
---|
262 | return FALSE;
|
---|
263 |
|
---|
264 | /* Read the leading portion that old and new core dump structures have in
|
---|
265 | common. */
|
---|
266 | size = CORE_COMMONSZ;
|
---|
267 | if (bfd_bread (core, size, abfd) != size)
|
---|
268 | return FALSE;
|
---|
269 |
|
---|
270 | /* Read the trailing portion of the structure. */
|
---|
271 | if (CORE_NEW (*core))
|
---|
272 | size = sizeof (core->new);
|
---|
273 | else
|
---|
274 | size = sizeof (core->old);
|
---|
275 | size -= CORE_COMMONSZ;
|
---|
276 | return bfd_bread ((char *) core + CORE_COMMONSZ, size, abfd) == size;
|
---|
277 | }
|
---|
278 |
|
---|
279 | static asection *
|
---|
280 | make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
|
---|
281 | bfd *abfd;
|
---|
282 | const char *name;
|
---|
283 | flagword flags;
|
---|
284 | bfd_size_type _raw_size;
|
---|
285 | bfd_vma vma;
|
---|
286 | file_ptr filepos;
|
---|
287 | {
|
---|
288 | asection *asect;
|
---|
289 |
|
---|
290 | asect = bfd_make_section_anyway (abfd, name);
|
---|
291 | if (!asect)
|
---|
292 | return NULL;
|
---|
293 |
|
---|
294 | asect->flags = flags;
|
---|
295 | asect->_raw_size = _raw_size;
|
---|
296 | asect->vma = vma;
|
---|
297 | asect->filepos = filepos;
|
---|
298 | asect->alignment_power = 8;
|
---|
299 |
|
---|
300 | return asect;
|
---|
301 | }
|
---|
302 |
|
---|
303 | /* Decide if a given bfd represents a `core' file or not. There really is no
|
---|
304 | magic number or anything like, in rs6000coff. */
|
---|
305 |
|
---|
306 | const bfd_target *
|
---|
307 | rs6000coff_core_p (abfd)
|
---|
308 | bfd *abfd;
|
---|
309 | {
|
---|
310 | CoreHdr core;
|
---|
311 | struct stat statbuf;
|
---|
312 | bfd_size_type size;
|
---|
313 | char *tmpptr;
|
---|
314 |
|
---|
315 | /* Values from new and old core structures. */
|
---|
316 | int c_flag;
|
---|
317 | file_ptr c_stack, c_regoff, c_loader;
|
---|
318 | bfd_size_type c_size, c_regsize, c_lsize;
|
---|
319 | bfd_vma c_stackend;
|
---|
320 | void *c_regptr;
|
---|
321 | int proc64;
|
---|
322 |
|
---|
323 | if (!read_hdr (abfd, &core))
|
---|
324 | {
|
---|
325 | if (bfd_get_error () != bfd_error_system_call)
|
---|
326 | bfd_set_error (bfd_error_wrong_format);
|
---|
327 | return NULL;
|
---|
328 | }
|
---|
329 |
|
---|
330 | /* Copy fields from new or old core structure. */
|
---|
331 | if (CORE_NEW (core))
|
---|
332 | {
|
---|
333 | c_flag = core.new.c_flag;
|
---|
334 | c_stack = (file_ptr) core.new.c_stack;
|
---|
335 | c_size = core.new.c_size;
|
---|
336 | c_stackend = CNEW_STACKORG (core.new) + c_size;
|
---|
337 | c_lsize = CNEW_LSIZE (core.new);
|
---|
338 | c_loader = CNEW_LOADER (core.new);
|
---|
339 | proc64 = CNEW_PROC64 (core.new);
|
---|
340 | }
|
---|
341 | else
|
---|
342 | {
|
---|
343 | c_flag = core.old.c_flag;
|
---|
344 | c_stack = (file_ptr) core.old.c_stack;
|
---|
345 | c_size = core.old.c_size;
|
---|
346 | c_stackend = COLD_STACKEND;
|
---|
347 | c_lsize = 0x7ffffff;
|
---|
348 | c_loader = (file_ptr) COLD_LOADER (core.old);
|
---|
349 | proc64 = 0;
|
---|
350 | }
|
---|
351 |
|
---|
352 | if (proc64)
|
---|
353 | {
|
---|
354 | c_regsize = sizeof (CNEW_CONTEXT64 (core.new));
|
---|
355 | c_regptr = &CNEW_CONTEXT64 (core.new);
|
---|
356 | }
|
---|
357 | else if (CORE_NEW (core))
|
---|
358 | {
|
---|
359 | c_regsize = sizeof (CNEW_MSTSAVE (core.new));
|
---|
360 | c_regptr = &CNEW_MSTSAVE (core.new);
|
---|
361 | }
|
---|
362 | else
|
---|
363 | {
|
---|
364 | c_regsize = sizeof (COLD_MSTSAVE (core.old));
|
---|
365 | c_regptr = &COLD_MSTSAVE (core.old);
|
---|
366 | }
|
---|
367 | c_regoff = (char *) c_regptr - (char *) &core;
|
---|
368 |
|
---|
369 | if (bfd_stat (abfd, &statbuf) < 0)
|
---|
370 | {
|
---|
371 | bfd_set_error (bfd_error_system_call);
|
---|
372 | return NULL;
|
---|
373 | }
|
---|
374 |
|
---|
375 | /* If the core file ulimit is too small, the system will first
|
---|
376 | omit the data segment, then omit the stack, then decline to
|
---|
377 | dump core altogether (as far as I know UBLOCK_VALID and LE_VALID
|
---|
378 | are always set) (this is based on experimentation on AIX 3.2).
|
---|
379 | Now, the thing is that GDB users will be surprised
|
---|
380 | if segments just silently don't appear (well, maybe they would
|
---|
381 | think to check "info files", I don't know).
|
---|
382 |
|
---|
383 | For the data segment, we have no choice but to keep going if it's
|
---|
384 | not there, since the default behavior is not to dump it (regardless
|
---|
385 | of the ulimit, it's based on SA_FULLDUMP). But for the stack segment,
|
---|
386 | if it's not there, we refuse to have anything to do with this core
|
---|
387 | file. The usefulness of a core dump without a stack segment is pretty
|
---|
388 | limited anyway. */
|
---|
389 |
|
---|
390 | if (!(c_flag & UBLOCK_VALID)
|
---|
391 | || !(c_flag & LE_VALID))
|
---|
392 | {
|
---|
393 | bfd_set_error (bfd_error_wrong_format);
|
---|
394 | return NULL;
|
---|
395 | }
|
---|
396 |
|
---|
397 | if (!(c_flag & USTACK_VALID))
|
---|
398 | {
|
---|
399 | bfd_set_error (bfd_error_file_truncated);
|
---|
400 | return NULL;
|
---|
401 | }
|
---|
402 |
|
---|
403 | /* Don't check the core file size for a full core, AIX 4.1 includes
|
---|
404 | additional shared library sections in a full core. */
|
---|
405 | if (!(c_flag & (FULL_CORE | CORE_TRUNC)))
|
---|
406 | {
|
---|
407 | /* If the size is wrong, it means we're misinterpreting something. */
|
---|
408 | if (c_stack + (file_ptr) c_size != statbuf.st_size)
|
---|
409 | {
|
---|
410 | bfd_set_error (bfd_error_wrong_format);
|
---|
411 | return NULL;
|
---|
412 | }
|
---|
413 | }
|
---|
414 |
|
---|
415 | /* Sanity check on the c_tab field. */
|
---|
416 | if (!CORE_NEW (core) && (c_loader < (file_ptr) sizeof core.old ||
|
---|
417 | c_loader >= statbuf.st_size ||
|
---|
418 | c_loader >= c_stack))
|
---|
419 | {
|
---|
420 | bfd_set_error (bfd_error_wrong_format);
|
---|
421 | return NULL;
|
---|
422 | }
|
---|
423 |
|
---|
424 | /* Issue warning if the core file was truncated during writing. */
|
---|
425 | if (c_flag & CORE_TRUNC)
|
---|
426 | (*_bfd_error_handler) (_("%s: warning core file truncated"),
|
---|
427 | bfd_get_filename (abfd));
|
---|
428 |
|
---|
429 | /* Allocate core file header. */
|
---|
430 | size = CORE_NEW (core) ? sizeof (core.new) : sizeof (core.old);
|
---|
431 | tmpptr = (char *) bfd_zalloc (abfd, (bfd_size_type) size);
|
---|
432 | if (!tmpptr)
|
---|
433 | return NULL;
|
---|
434 |
|
---|
435 | /* Copy core file header. */
|
---|
436 | memcpy (tmpptr, &core, size);
|
---|
437 | set_tdata (abfd, tmpptr);
|
---|
438 |
|
---|
439 | /* Set architecture. */
|
---|
440 | if (CORE_NEW (core))
|
---|
441 | {
|
---|
442 | enum bfd_architecture arch;
|
---|
443 | unsigned long mach;
|
---|
444 |
|
---|
445 | switch (CNEW_IMPL (core.new))
|
---|
446 | {
|
---|
447 | case POWER_RS1:
|
---|
448 | case POWER_RSC:
|
---|
449 | case POWER_RS2:
|
---|
450 | arch = bfd_arch_rs6000;
|
---|
451 | mach = bfd_mach_rs6k;
|
---|
452 | break;
|
---|
453 | default:
|
---|
454 | arch = bfd_arch_powerpc;
|
---|
455 | mach = bfd_mach_ppc;
|
---|
456 | break;
|
---|
457 | }
|
---|
458 | bfd_default_set_arch_mach (abfd, arch, mach);
|
---|
459 | }
|
---|
460 |
|
---|
461 | /* .stack section. */
|
---|
462 | if (!make_bfd_asection (abfd, ".stack",
|
---|
463 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
|
---|
464 | c_size, c_stackend - c_size, c_stack))
|
---|
465 | goto fail;
|
---|
466 |
|
---|
467 | /* .reg section for all registers. */
|
---|
468 | if (!make_bfd_asection (abfd, ".reg",
|
---|
469 | SEC_HAS_CONTENTS,
|
---|
470 | c_regsize, (bfd_vma) 0, c_regoff))
|
---|
471 | goto fail;
|
---|
472 |
|
---|
473 | /* .ldinfo section.
|
---|
474 | To actually find out how long this section is in this particular
|
---|
475 | core dump would require going down the whole list of struct ld_info's.
|
---|
476 | See if we can just fake it. */
|
---|
477 | if (!make_bfd_asection (abfd, ".ldinfo",
|
---|
478 | SEC_HAS_CONTENTS,
|
---|
479 | c_lsize, (bfd_vma) 0, c_loader))
|
---|
480 | goto fail;
|
---|
481 |
|
---|
482 | #ifndef CORE_VERSION_1
|
---|
483 | /* .data section if present.
|
---|
484 | AIX 3 dumps the complete data section and sets FULL_CORE if the
|
---|
485 | ulimit is large enough, otherwise the data section is omitted.
|
---|
486 | AIX 4 sets FULL_CORE even if the core file is truncated, we have
|
---|
487 | to examine core.c_datasize below to find out the actual size of
|
---|
488 | the .data section. */
|
---|
489 | if (c_flag & FULL_CORE)
|
---|
490 | {
|
---|
491 | if (!make_bfd_asection (abfd, ".data",
|
---|
492 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
|
---|
493 | (bfd_size_type) core.old.c_u.u_dsize,
|
---|
494 | (bfd_vma)
|
---|
495 | CDATA_ADDR (core.old.c_u.u_dsize),
|
---|
496 | c_stack + c_size))
|
---|
497 | goto fail;
|
---|
498 | }
|
---|
499 | #endif
|
---|
500 |
|
---|
501 | #ifdef CORE_VERSION_1
|
---|
502 | /* AIX 4 adds data sections from loaded objects to the core file,
|
---|
503 | which can be found by examining ldinfo, and anonymously mmapped
|
---|
504 | regions. */
|
---|
505 | {
|
---|
506 | LdInfo ldinfo;
|
---|
507 | bfd_size_type ldi_datasize;
|
---|
508 | file_ptr ldi_core;
|
---|
509 | uint ldi_next;
|
---|
510 | bfd_vma ldi_dataorg;
|
---|
511 |
|
---|
512 | /* Fields from new and old core structures. */
|
---|
513 | bfd_size_type c_datasize, c_vmregions;
|
---|
514 | file_ptr c_data, c_vmm;
|
---|
515 |
|
---|
516 | if (CORE_NEW (core))
|
---|
517 | {
|
---|
518 | c_datasize = CNEW_DATASIZE (core.new);
|
---|
519 | c_data = (file_ptr) core.new.c_data;
|
---|
520 | c_vmregions = core.new.c_vmregions;
|
---|
521 | c_vmm = (file_ptr) core.new.c_vmm;
|
---|
522 | }
|
---|
523 | else
|
---|
524 | {
|
---|
525 | c_datasize = core.old.c_datasize;
|
---|
526 | c_data = (file_ptr) core.old.c_data;
|
---|
527 | c_vmregions = core.old.c_vmregions;
|
---|
528 | c_vmm = (file_ptr) core.old.c_vmm;
|
---|
529 | }
|
---|
530 |
|
---|
531 | /* .data section from executable. */
|
---|
532 | if (c_datasize)
|
---|
533 | {
|
---|
534 | if (!make_bfd_asection (abfd, ".data",
|
---|
535 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
|
---|
536 | c_datasize,
|
---|
537 | (bfd_vma) CDATA_ADDR (c_datasize),
|
---|
538 | c_data))
|
---|
539 | goto fail;
|
---|
540 | }
|
---|
541 |
|
---|
542 | /* .data sections from loaded objects. */
|
---|
543 | if (proc64)
|
---|
544 | size = (int) ((LdInfo *) 0)->l64.ldinfo_filename;
|
---|
545 | else
|
---|
546 | size = (int) ((LdInfo *) 0)->l32.ldinfo_filename;
|
---|
547 |
|
---|
548 | while (1)
|
---|
549 | {
|
---|
550 | if (bfd_seek (abfd, c_loader, SEEK_SET) != 0)
|
---|
551 | goto fail;
|
---|
552 | if (bfd_bread (&ldinfo, size, abfd) != size)
|
---|
553 | goto fail;
|
---|
554 |
|
---|
555 | if (proc64)
|
---|
556 | {
|
---|
557 | ldi_core = ldinfo.l64.ldinfo_core;
|
---|
558 | ldi_datasize = ldinfo.l64.ldinfo_datasize;
|
---|
559 | ldi_dataorg = (bfd_vma) ldinfo.l64.ldinfo_dataorg;
|
---|
560 | ldi_next = ldinfo.l64.ldinfo_next;
|
---|
561 | }
|
---|
562 | else
|
---|
563 | {
|
---|
564 | ldi_core = ldinfo.l32.ldinfo_core;
|
---|
565 | ldi_datasize = ldinfo.l32.ldinfo_datasize;
|
---|
566 | ldi_dataorg = (bfd_vma) (long) ldinfo.l32.ldinfo_dataorg;
|
---|
567 | ldi_next = ldinfo.l32.ldinfo_next;
|
---|
568 | }
|
---|
569 |
|
---|
570 | if (ldi_core)
|
---|
571 | if (!make_bfd_asection (abfd, ".data",
|
---|
572 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
|
---|
573 | ldi_datasize, ldi_dataorg, ldi_core))
|
---|
574 | goto fail;
|
---|
575 |
|
---|
576 | if (ldi_next == 0)
|
---|
577 | break;
|
---|
578 | c_loader += ldi_next;
|
---|
579 | }
|
---|
580 |
|
---|
581 | /* .vmdata sections from anonymously mmapped regions. */
|
---|
582 | if (c_vmregions)
|
---|
583 | {
|
---|
584 | bfd_size_type i;
|
---|
585 |
|
---|
586 | if (bfd_seek (abfd, c_vmm, SEEK_SET) != 0)
|
---|
587 | goto fail;
|
---|
588 |
|
---|
589 | for (i = 0; i < c_vmregions; i++)
|
---|
590 | {
|
---|
591 | VmInfo vminfo;
|
---|
592 | bfd_size_type vminfo_size;
|
---|
593 | file_ptr vminfo_offset;
|
---|
594 | bfd_vma vminfo_addr;
|
---|
595 |
|
---|
596 | size = CORE_NEW (core) ? sizeof (vminfo.new) : sizeof (vminfo.old);
|
---|
597 | if (bfd_bread (&vminfo, size, abfd) != size)
|
---|
598 | goto fail;
|
---|
599 |
|
---|
600 | if (CORE_NEW (core))
|
---|
601 | {
|
---|
602 | vminfo_addr = (bfd_vma) vminfo.new.vminfo_addr;
|
---|
603 | vminfo_size = vminfo.new.vminfo_size;
|
---|
604 | vminfo_offset = vminfo.new.vminfo_offset;
|
---|
605 | }
|
---|
606 | else
|
---|
607 | {
|
---|
608 | vminfo_addr = (bfd_vma) (long) vminfo.old.vminfo_addr;
|
---|
609 | vminfo_size = vminfo.old.vminfo_size;
|
---|
610 | vminfo_offset = vminfo.old.vminfo_offset;
|
---|
611 | }
|
---|
612 |
|
---|
613 | if (vminfo_offset)
|
---|
614 | if (!make_bfd_asection (abfd, ".vmdata",
|
---|
615 | SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
|
---|
616 | vminfo_size, vminfo_addr,
|
---|
617 | vminfo_offset))
|
---|
618 | goto fail;
|
---|
619 | }
|
---|
620 | }
|
---|
621 | }
|
---|
622 | #endif
|
---|
623 |
|
---|
624 | return abfd->xvec; /* This is garbage for now. */
|
---|
625 |
|
---|
626 | fail:
|
---|
627 | bfd_release (abfd, abfd->tdata.any);
|
---|
628 | abfd->tdata.any = NULL;
|
---|
629 | bfd_section_list_clear (abfd);
|
---|
630 | return NULL;
|
---|
631 | }
|
---|
632 |
|
---|
633 | /* Return `TRUE' if given core is from the given executable. */
|
---|
634 |
|
---|
635 | bfd_boolean
|
---|
636 | rs6000coff_core_file_matches_executable_p (core_bfd, exec_bfd)
|
---|
637 | bfd *core_bfd;
|
---|
638 | bfd *exec_bfd;
|
---|
639 | {
|
---|
640 | CoreHdr core;
|
---|
641 | bfd_size_type size;
|
---|
642 | char *path, *s;
|
---|
643 | size_t alloc;
|
---|
644 | const char *str1, *str2;
|
---|
645 | bfd_boolean ret;
|
---|
646 | file_ptr c_loader;
|
---|
647 |
|
---|
648 | if (!read_hdr (core_bfd, &core))
|
---|
649 | return FALSE;
|
---|
650 |
|
---|
651 | if (CORE_NEW (core))
|
---|
652 | c_loader = CNEW_LOADER (core.new);
|
---|
653 | else
|
---|
654 | c_loader = (file_ptr) COLD_LOADER (core.old);
|
---|
655 |
|
---|
656 | if (CORE_NEW (core) && CNEW_PROC64 (core.new))
|
---|
657 | size = (int) ((LdInfo *) 0)->l64.ldinfo_filename;
|
---|
658 | else
|
---|
659 | size = (int) ((LdInfo *) 0)->l32.ldinfo_filename;
|
---|
660 |
|
---|
661 | if (bfd_seek (core_bfd, c_loader + size, SEEK_SET) != 0)
|
---|
662 | return FALSE;
|
---|
663 |
|
---|
664 | alloc = 100;
|
---|
665 | path = bfd_malloc ((bfd_size_type) alloc);
|
---|
666 | if (path == NULL)
|
---|
667 | return FALSE;
|
---|
668 | s = path;
|
---|
669 |
|
---|
670 | while (1)
|
---|
671 | {
|
---|
672 | if (bfd_bread (s, (bfd_size_type) 1, core_bfd) != 1)
|
---|
673 | {
|
---|
674 | free (path);
|
---|
675 | return FALSE;
|
---|
676 | }
|
---|
677 | if (*s == '\0')
|
---|
678 | break;
|
---|
679 | ++s;
|
---|
680 | if (s == path + alloc)
|
---|
681 | {
|
---|
682 | char *n;
|
---|
683 |
|
---|
684 | alloc *= 2;
|
---|
685 | n = bfd_realloc (path, (bfd_size_type) alloc);
|
---|
686 | if (n == NULL)
|
---|
687 | {
|
---|
688 | free (path);
|
---|
689 | return FALSE;
|
---|
690 | }
|
---|
691 | s = n + (path - s);
|
---|
692 | path = n;
|
---|
693 | }
|
---|
694 | }
|
---|
695 |
|
---|
696 | str1 = strrchr (path, '/');
|
---|
697 | str2 = strrchr (exec_bfd->filename, '/');
|
---|
698 |
|
---|
699 | /* step over character '/' */
|
---|
700 | str1 = str1 != NULL ? str1 + 1 : path;
|
---|
701 | str2 = str2 != NULL ? str2 + 1 : exec_bfd->filename;
|
---|
702 |
|
---|
703 | if (strcmp (str1, str2) == 0)
|
---|
704 | ret = TRUE;
|
---|
705 | else
|
---|
706 | ret = FALSE;
|
---|
707 |
|
---|
708 | free (path);
|
---|
709 |
|
---|
710 | return ret;
|
---|
711 | }
|
---|
712 |
|
---|
713 | char *
|
---|
714 | rs6000coff_core_file_failing_command (abfd)
|
---|
715 | bfd *abfd;
|
---|
716 | {
|
---|
717 | CoreHdr *core = core_hdr (abfd);
|
---|
718 | char *com = CORE_NEW (*core) ?
|
---|
719 | CNEW_COMM (core->new) : COLD_COMM (core->old);
|
---|
720 |
|
---|
721 | if (*com)
|
---|
722 | return com;
|
---|
723 | else
|
---|
724 | return 0;
|
---|
725 | }
|
---|
726 |
|
---|
727 | int
|
---|
728 | rs6000coff_core_file_failing_signal (abfd)
|
---|
729 | bfd *abfd;
|
---|
730 | {
|
---|
731 | CoreHdr *core = core_hdr (abfd);
|
---|
732 | return CORE_NEW (*core) ? core->new.c_signo : core->old.c_signo;
|
---|
733 | }
|
---|
734 |
|
---|
735 | #endif /* AIX_CORE */
|
---|