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