1 /* IBM RS/6000 "XCOFF" back-end for BFD.
2 Copyright 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
7 This file is part of BFD, the Binary File Descriptor library.
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
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
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.
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
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 MA 02111-1307, USA. */
31 const bfd_target
*xcoff64_core_p
33 bfd_boolean xcoff64_core_file_matches_executable_p
34 PARAMS ((bfd
*, bfd
*));
35 char *xcoff64_core_file_failing_command
37 int xcoff64_core_file_failing_signal
40 /* Aix 5.1 system include file. */
42 /* Need to define this macro so struct ld_info64 get included. */
43 #define __LDINFO_PTRACE64__
47 #define core_hdr(abfd) ((struct core_dumpxx *) abfd->tdata.any)
49 #define CHECK_FILE_OFFSET(s, v) \
50 ((bfd_signed_vma)(v) < 0 || (bfd_signed_vma)(v) > (bfd_signed_vma)(s).st_size)
56 struct core_dumpxx core
, *new_core_hdr
;
59 struct __ld_info64 ldinfo
;
62 struct vm_infox vminfo
;
63 bfd_target
*return_value
= NULL
;
66 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0)
67 goto xcoff64_core_p_error
;
69 if (sizeof (struct core_dumpxx
)
70 != bfd_bread (&core
, sizeof (struct core_dumpxx
), abfd
))
71 goto xcoff64_core_p_error
;
73 if (bfd_stat (abfd
, &statbuf
) < 0)
74 goto xcoff64_core_p_error
;
77 c_flag has CORE_VERSION_1, Aix 4+
78 c_entries = 0 for Aix 4.3+
79 IS_PROC64 is a macro defined in procinfo.h, test for 64 bit process.
81 We will still be confused if a Aix 4.3 64 bit core file is
82 copied over to a Aix 5 machine.
84 Check file header offsets
86 See rs6000-core.c for comment on size of core
87 If there isn't enough of a real core file, bail. */
89 if ((CORE_VERSION_1
!= (core
.c_flag
& CORE_VERSION_1
))
90 || (0 != core
.c_entries
)
91 || (! (IS_PROC64 (&core
.c_u
.U_proc
)))
92 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_fdsinfox
)))
93 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_loader
)))
94 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_loader
+ core
.c_lsize
)))
95 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_thr
)))
96 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_segregion
)))
97 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_stack
)))
98 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_stack
+ core
.c_size
)))
99 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_data
)))
100 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_data
+ core
.c_datasize
)))
101 || (! (core
.c_flag
& UBLOCK_VALID
))
102 || (! (core
.c_flag
& LE_VALID
)))
103 goto xcoff64_core_p_error
;
105 /* Check for truncated stack or general truncating. */
106 if ((! (core
.c_flag
& USTACK_VALID
))
107 || (core
.c_flag
& CORE_TRUNC
))
109 bfd_set_error (bfd_error_file_truncated
);
114 new_core_hdr
= (struct core_dumpxx
*)
115 bfd_zalloc (abfd
, sizeof (struct core_dumpxx
));
116 if (NULL
== new_core_hdr
)
119 memcpy (new_core_hdr
, &core
, sizeof (struct core_dumpxx
));
120 core_hdr(abfd
) = (char *)new_core_hdr
;
122 /* .stack section. */
123 sec
= bfd_make_section_anyway (abfd
, ".stack");
127 sec
->flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
128 sec
->size
= core
.c_size
;
129 sec
->vma
= core
.c_stackorg
;
130 sec
->filepos
= core
.c_stack
;
132 /* .reg section for all registers. */
133 sec
= bfd_make_section_anyway (abfd
, ".reg");
137 sec
->flags
= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
138 sec
->size
= sizeof (struct __context64
);
141 sec
->contents
= (bfd_byte
*)&new_core_hdr
->c_flt
.r64
;
144 To actually find out how long this section is in this particular
145 core dump would require going down the whole list of struct
146 ld_info's. See if we can just fake it. */
147 sec
= bfd_make_section_anyway (abfd
, ".ldinfo");
151 sec
->flags
= SEC_HAS_CONTENTS
;
152 sec
->size
= core
.c_lsize
;
154 sec
->filepos
= core
.c_loader
;
156 /* AIX 4 adds data sections from loaded objects to the core file,
157 which can be found by examining ldinfo, and anonymously mmapped
160 /* .data section from executable. */
161 sec
= bfd_make_section_anyway (abfd
, ".data");
165 sec
->flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
166 sec
->size
= core
.c_datasize
;
167 sec
->vma
= core
.c_dataorg
;
168 sec
->filepos
= core
.c_data
;
170 /* .data sections from loaded objects. */
171 ld_offset
= core
.c_loader
;
175 if (bfd_seek (abfd
, ld_offset
, SEEK_SET
) != 0)
178 if (sizeof (struct __ld_info64
) !=
179 bfd_bread (&ldinfo
, sizeof (struct __ld_info64
), abfd
))
182 if (ldinfo
.ldinfo_core
)
184 sec
= bfd_make_section_anyway (abfd
, ".data");
188 sec
->flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
189 sec
->size
= ldinfo
.ldinfo_datasize
;
190 sec
->vma
= ldinfo
.ldinfo_dataorg
;
191 sec
->filepos
= ldinfo
.ldinfo_core
;
194 if (0 == ldinfo
.ldinfo_next
)
196 ld_offset
+= ldinfo
.ldinfo_next
;
199 /* .vmdata sections from anonymously mmapped regions. */
200 if (core
.c_vmregions
)
202 if (bfd_seek (abfd
, core
.c_vmm
, SEEK_SET
) != 0)
205 for (i
= 0; i
< core
.c_vmregions
; i
++)
206 if (sizeof (struct vm_infox
) !=
207 bfd_bread (&vminfo
, sizeof (struct vm_infox
), abfd
))
210 if (vminfo
.vminfo_offset
)
212 sec
= bfd_make_section_anyway (abfd
, ".vmdata");
216 sec
->flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
217 sec
->size
= vminfo
.vminfo_size
;
218 sec
->vma
= vminfo
.vminfo_addr
;
219 sec
->filepos
= vminfo
.vminfo_offset
;
223 return_value
= (bfd_target
*) abfd
->xvec
; /* This is garbage for now. */
225 xcoff64_core_p_error
:
226 if (bfd_get_error () != bfd_error_system_call
)
227 bfd_set_error (bfd_error_wrong_format
);
232 /* Return `TRUE' if given core is from the given executable. */
235 xcoff64_core_file_matches_executable_p (core_bfd
, exec_bfd
)
239 struct core_dumpxx core
;
242 const char *str1
, *str2
;
243 bfd_boolean return_value
= FALSE
;
245 /* Get the header. */
246 if (bfd_seek (core_bfd
, 0, SEEK_SET
) != 0)
249 if (sizeof (struct core_dumpxx
) !=
250 bfd_bread (&core
, sizeof (struct core_dumpxx
), core_bfd
))
253 if (bfd_seek (core_bfd
, core
.c_loader
, SEEK_SET
) != 0)
257 path
= bfd_malloc (alloc
);
265 if (bfd_bread (s
, 1, core_bfd
) != 1)
266 goto xcoff64_core_file_matches_executable_p_end_1
;
271 if (s
== path
+ alloc
)
276 n
= bfd_realloc (path
, alloc
);
278 goto xcoff64_core_file_matches_executable_p_end_1
;
285 str1
= strrchr (path
, '/');
286 str2
= strrchr (exec_bfd
->filename
, '/');
288 /* Step over character '/'. */
289 str1
= str1
!= NULL
? str1
+ 1 : path
;
290 str2
= str2
!= NULL
? str2
+ 1 : exec_bfd
->filename
;
292 if (strcmp (str1
, str2
) == 0)
295 xcoff64_core_file_matches_executable_p_end_1
:
301 xcoff64_core_file_failing_command (abfd
)
304 struct core_dumpxx
*c
= core_hdr (abfd
);
305 char *return_value
= 0;
308 return_value
= c
->c_u
.U_proc
.pi_comm
;
314 xcoff64_core_file_failing_signal (abfd
)
317 struct core_dumpxx
*c
= core_hdr (abfd
);
318 int return_value
= 0;
321 return_value
= c
->c_signo
;
326 #else /* AIX_5_CORE */
328 const bfd_target
*xcoff64_core_p
330 bfd_boolean xcoff64_core_file_matches_executable_p
331 PARAMS ((bfd
*, bfd
*));
332 char *xcoff64_core_file_failing_command
334 int xcoff64_core_file_failing_signal
338 xcoff64_core_p (abfd
)
339 bfd
*abfd ATTRIBUTE_UNUSED
;
341 bfd_set_error (bfd_error_wrong_format
);
346 xcoff64_core_file_matches_executable_p (core_bfd
, exec_bfd
)
347 bfd
*core_bfd ATTRIBUTE_UNUSED
;
348 bfd
*exec_bfd ATTRIBUTE_UNUSED
;
354 xcoff64_core_file_failing_command (abfd
)
355 bfd
*abfd ATTRIBUTE_UNUSED
;
361 xcoff64_core_file_failing_signal (abfd
)
362 bfd
*abfd ATTRIBUTE_UNUSED
;
367 #endif /* AIX_5_CORE */