1 /* IBM RS/6000 "XCOFF" back-end for BFD.
2 Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
5 Contributed by Red Hat 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 3 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., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
27 const bfd_target
*xcoff64_core_p (bfd
*);
28 bfd_boolean
xcoff64_core_file_matches_executable_p (bfd
*, bfd
*);
29 char *xcoff64_core_file_failing_command (bfd
*);
30 int xcoff64_core_file_failing_signal (bfd
*);
36 /* Aix 5.1 system include file. */
38 /* Need to define this macro so struct ld_info64 get included. */
39 #define __LDINFO_PTRACE64__
43 /* The default architecture and machine for matching core files. */
44 #define DEFAULT_ARCHITECTURE bfd_arch_powerpc
45 #define DEFAULT_MACHINE bfd_mach_ppc_620
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)
53 xcoff64_core_p (bfd
*abfd
)
55 enum bfd_architecture arch
;
57 struct core_dumpxx core
, *new_core_hdr
;
60 struct __ld_info64 ldinfo
;
63 struct vm_infox vminfo
;
64 const bfd_target
*return_value
= NULL
;
68 if (bfd_seek (abfd
, 0, SEEK_SET
) != 0)
69 goto xcoff64_core_p_error
;
71 if (sizeof (struct core_dumpxx
)
72 != bfd_bread (&core
, sizeof (struct core_dumpxx
), abfd
))
73 goto xcoff64_core_p_error
;
75 if (bfd_stat (abfd
, &statbuf
) < 0)
76 goto xcoff64_core_p_error
;
79 c_flag has CORE_VERSION_1, Aix 4+
80 c_entries = 0 for Aix 4.3+
81 IS_PROC64 is a macro defined in procinfo.h, test for 64 bit process.
83 We will still be confused if a Aix 4.3 64 bit core file is
84 copied over to a Aix 5 machine.
86 Check file header offsets
88 See rs6000-core.c for comment on size of core
89 If there isn't enough of a real core file, bail. */
91 if ((CORE_VERSION_1
!= (core
.c_flag
& CORE_VERSION_1
))
92 || (0 != core
.c_entries
)
93 || (! (IS_PROC64 (&core
.c_u
.U_proc
)))
94 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_fdsinfox
)))
95 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_loader
)))
96 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_loader
+ core
.c_lsize
)))
97 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_thr
)))
98 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_segregion
)))
99 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_stack
)))
100 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_stack
+ core
.c_size
)))
101 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_data
)))
102 || ((CHECK_FILE_OFFSET (statbuf
, core
.c_data
+ core
.c_datasize
)))
103 || (! (core
.c_flag
& UBLOCK_VALID
))
104 || (! (core
.c_flag
& LE_VALID
)))
105 goto xcoff64_core_p_error
;
107 /* Check for truncated stack or general truncating. */
108 if ((! (core
.c_flag
& USTACK_VALID
))
109 || (core
.c_flag
& CORE_TRUNC
))
111 bfd_set_error (bfd_error_file_truncated
);
116 new_core_hdr
= bfd_zalloc (abfd
, sizeof (struct core_dumpxx
));
117 if (NULL
== new_core_hdr
)
120 memcpy (new_core_hdr
, &core
, sizeof (struct core_dumpxx
));
121 /* The core_hdr() macro is no longer used here because it would
122 expand to code relying on gcc's cast-as-lvalue extension,
123 which was removed in gcc 4.0. */
124 abfd
->tdata
.any
= new_core_hdr
;
126 /* .stack section. */
127 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
128 sec
= bfd_make_section_anyway_with_flags (abfd
, ".stack", flags
);
132 sec
->size
= core
.c_size
;
133 sec
->vma
= core
.c_stackorg
;
134 sec
->filepos
= core
.c_stack
;
136 /* .reg section for all registers. */
137 flags
= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
138 sec
= bfd_make_section_anyway_with_flags (abfd
, ".reg", flags
);
142 sec
->size
= sizeof (struct __context64
);
145 sec
->contents
= (bfd_byte
*)&new_core_hdr
->c_flt
.r64
;
148 To actually find out how long this section is in this particular
149 core dump would require going down the whole list of struct
150 ld_info's. See if we can just fake it. */
151 flags
= SEC_HAS_CONTENTS
;
152 sec
= bfd_make_section_anyway_with_flags (abfd
, ".ldinfo", flags
);
156 sec
->size
= core
.c_lsize
;
158 sec
->filepos
= core
.c_loader
;
160 /* AIX 4 adds data sections from loaded objects to the core file,
161 which can be found by examining ldinfo, and anonymously mmapped
164 /* .data section from executable. */
165 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
166 sec
= bfd_make_section_anyway_with_flags (abfd
, ".data", flags
);
170 sec
->size
= core
.c_datasize
;
171 sec
->vma
= core
.c_dataorg
;
172 sec
->filepos
= core
.c_data
;
174 /* .data sections from loaded objects. */
175 ld_offset
= core
.c_loader
;
179 if (bfd_seek (abfd
, ld_offset
, SEEK_SET
) != 0)
182 if (sizeof (struct __ld_info64
) !=
183 bfd_bread (&ldinfo
, sizeof (struct __ld_info64
), abfd
))
186 if (ldinfo
.ldinfo_core
)
188 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
189 sec
= bfd_make_section_anyway_with_flags (abfd
, ".data", flags
);
193 sec
->size
= ldinfo
.ldinfo_datasize
;
194 sec
->vma
= ldinfo
.ldinfo_dataorg
;
195 sec
->filepos
= ldinfo
.ldinfo_core
;
198 if (0 == ldinfo
.ldinfo_next
)
200 ld_offset
+= ldinfo
.ldinfo_next
;
203 /* .vmdata sections from anonymously mmapped regions. */
204 if (core
.c_vmregions
)
206 if (bfd_seek (abfd
, core
.c_vmm
, SEEK_SET
) != 0)
209 for (i
= 0; i
< core
.c_vmregions
; i
++)
210 if (sizeof (struct vm_infox
) !=
211 bfd_bread (&vminfo
, sizeof (struct vm_infox
), abfd
))
214 if (vminfo
.vminfo_offset
)
216 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
217 sec
= bfd_make_section_anyway_with_flags (abfd
, ".vmdata", flags
);
221 sec
->size
= vminfo
.vminfo_size
;
222 sec
->vma
= vminfo
.vminfo_addr
;
223 sec
->filepos
= vminfo
.vminfo_offset
;
227 /* Set the architecture and machine. */
228 arch
= DEFAULT_ARCHITECTURE
;
229 mach
= DEFAULT_MACHINE
;
230 bfd_default_set_arch_mach (abfd
, arch
, mach
);
232 return_value
= (bfd_target
*) abfd
->xvec
; /* This is garbage for now. */
234 xcoff64_core_p_error
:
235 if (bfd_get_error () != bfd_error_system_call
)
236 bfd_set_error (bfd_error_wrong_format
);
241 /* Return `TRUE' if given core is from the given executable. */
244 xcoff64_core_file_matches_executable_p (bfd
*core_bfd
, bfd
*exec_bfd
)
246 struct core_dumpxx core
;
249 const char *str1
, *str2
;
250 bfd_boolean return_value
= FALSE
;
252 /* Get the header. */
253 if (bfd_seek (core_bfd
, 0, SEEK_SET
) != 0)
256 if (sizeof (struct core_dumpxx
) !=
257 bfd_bread (&core
, sizeof (struct core_dumpxx
), core_bfd
))
260 if (bfd_seek (core_bfd
, core
.c_loader
, SEEK_SET
) != 0)
264 path
= bfd_malloc (alloc
);
272 if (bfd_bread (s
, 1, core_bfd
) != 1)
273 goto xcoff64_core_file_matches_executable_p_end_1
;
278 if (s
== path
+ alloc
)
283 n
= bfd_realloc (path
, alloc
);
285 goto xcoff64_core_file_matches_executable_p_end_1
;
292 str1
= strrchr (path
, '/');
293 str2
= strrchr (exec_bfd
->filename
, '/');
295 /* Step over character '/'. */
296 str1
= str1
!= NULL
? str1
+ 1 : path
;
297 str2
= str2
!= NULL
? str2
+ 1 : exec_bfd
->filename
;
299 if (strcmp (str1
, str2
) == 0)
302 xcoff64_core_file_matches_executable_p_end_1
:
308 xcoff64_core_file_failing_command (bfd
*abfd
)
310 struct core_dumpxx
*c
= core_hdr (abfd
);
311 char *return_value
= 0;
314 return_value
= c
->c_u
.U_proc
.pi_comm
;
320 xcoff64_core_file_failing_signal (bfd
*abfd
)
322 struct core_dumpxx
*c
= core_hdr (abfd
);
323 int return_value
= 0;
326 return_value
= c
->c_signo
;
331 #else /* AIX_5_CORE */
334 xcoff64_core_p (bfd
*abfd ATTRIBUTE_UNUSED
)
336 bfd_set_error (bfd_error_wrong_format
);
341 xcoff64_core_file_matches_executable_p (bfd
*core_bfd
, bfd
*exec_bfd
)
343 return generic_core_file_matches_executable_p (core_bfd
, exec_bfd
);
347 xcoff64_core_file_failing_command (bfd
*abfd ATTRIBUTE_UNUSED
)
353 xcoff64_core_file_failing_signal (bfd
*abfd ATTRIBUTE_UNUSED
)
358 #endif /* AIX_5_CORE */