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