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