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