1 /* IBM RS/6000 "XCOFF" back-end for BFD.
2 Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007
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 #define core_hdr(abfd) ((struct core_dumpxx *) abfd->tdata.any)
45 #define CHECK_FILE_OFFSET(s, v) \
46 ((bfd_signed_vma)(v) < 0 || (bfd_signed_vma)(v) > (bfd_signed_vma)(s).st_size)
49 xcoff64_core_p (bfd *abfd)
51 struct core_dumpxx core, *new_core_hdr;
54 struct __ld_info64 ldinfo;
57 struct vm_infox vminfo;
58 const bfd_target *return_value = NULL;
62 if (bfd_seek (abfd, 0, SEEK_SET) != 0)
63 goto xcoff64_core_p_error;
65 if (sizeof (struct core_dumpxx)
66 != bfd_bread (&core, sizeof (struct core_dumpxx), abfd))
67 goto xcoff64_core_p_error;
69 if (bfd_stat (abfd, &statbuf) < 0)
70 goto xcoff64_core_p_error;
73 c_flag has CORE_VERSION_1, Aix 4+
74 c_entries = 0 for Aix 4.3+
75 IS_PROC64 is a macro defined in procinfo.h, test for 64 bit process.
77 We will still be confused if a Aix 4.3 64 bit core file is
78 copied over to a Aix 5 machine.
80 Check file header offsets
82 See rs6000-core.c for comment on size of core
83 If there isn't enough of a real core file, bail. */
85 if ((CORE_VERSION_1 != (core.c_flag & CORE_VERSION_1))
86 || (0 != core.c_entries)
87 || (! (IS_PROC64 (&core.c_u.U_proc)))
88 || ((CHECK_FILE_OFFSET (statbuf, core.c_fdsinfox)))
89 || ((CHECK_FILE_OFFSET (statbuf, core.c_loader)))
90 || ((CHECK_FILE_OFFSET (statbuf, core.c_loader + core.c_lsize)))
91 || ((CHECK_FILE_OFFSET (statbuf, core.c_thr)))
92 || ((CHECK_FILE_OFFSET (statbuf, core.c_segregion)))
93 || ((CHECK_FILE_OFFSET (statbuf, core.c_stack)))
94 || ((CHECK_FILE_OFFSET (statbuf, core.c_stack + core.c_size)))
95 || ((CHECK_FILE_OFFSET (statbuf, core.c_data)))
96 || ((CHECK_FILE_OFFSET (statbuf, core.c_data + core.c_datasize)))
97 || (! (core.c_flag & UBLOCK_VALID))
98 || (! (core.c_flag & LE_VALID)))
99 goto xcoff64_core_p_error;
101 /* Check for truncated stack or general truncating. */
102 if ((! (core.c_flag & USTACK_VALID))
103 || (core.c_flag & CORE_TRUNC))
105 bfd_set_error (bfd_error_file_truncated);
110 new_core_hdr = bfd_zalloc (abfd, sizeof (struct core_dumpxx));
111 if (NULL == new_core_hdr)
114 memcpy (new_core_hdr, &core, sizeof (struct core_dumpxx));
115 /* The core_hdr() macro is no longer used here because it would
116 expand to code relying on gcc's cast-as-lvalue extension,
117 which was removed in gcc 4.0. */
118 abfd->tdata.any = new_core_hdr;
120 /* .stack section. */
121 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
122 sec = bfd_make_section_anyway_with_flags (abfd, ".stack", flags);
126 sec->size = core.c_size;
127 sec->vma = core.c_stackorg;
128 sec->filepos = core.c_stack;
130 /* .reg section for all registers. */
131 flags = SEC_HAS_CONTENTS | SEC_IN_MEMORY;
132 sec = bfd_make_section_anyway_with_flags (abfd, ".reg", flags);
136 sec->size = sizeof (struct __context64);
139 sec->contents = (bfd_byte *)&new_core_hdr->c_flt.r64;
142 To actually find out how long this section is in this particular
143 core dump would require going down the whole list of struct
144 ld_info's. See if we can just fake it. */
145 flags = SEC_HAS_CONTENTS;
146 sec = bfd_make_section_anyway_with_flags (abfd, ".ldinfo", flags);
150 sec->size = core.c_lsize;
152 sec->filepos = core.c_loader;
154 /* AIX 4 adds data sections from loaded objects to the core file,
155 which can be found by examining ldinfo, and anonymously mmapped
158 /* .data section from executable. */
159 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
160 sec = bfd_make_section_anyway_with_flags (abfd, ".data", flags);
164 sec->size = core.c_datasize;
165 sec->vma = core.c_dataorg;
166 sec->filepos = core.c_data;
168 /* .data sections from loaded objects. */
169 ld_offset = core.c_loader;
173 if (bfd_seek (abfd, ld_offset, SEEK_SET) != 0)
176 if (sizeof (struct __ld_info64) !=
177 bfd_bread (&ldinfo, sizeof (struct __ld_info64), abfd))
180 if (ldinfo.ldinfo_core)
182 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
183 sec = bfd_make_section_anyway_with_flags (abfd, ".data", flags);
187 sec->size = ldinfo.ldinfo_datasize;
188 sec->vma = ldinfo.ldinfo_dataorg;
189 sec->filepos = ldinfo.ldinfo_core;
192 if (0 == ldinfo.ldinfo_next)
194 ld_offset += ldinfo.ldinfo_next;
197 /* .vmdata sections from anonymously mmapped regions. */
198 if (core.c_vmregions)
200 if (bfd_seek (abfd, core.c_vmm, SEEK_SET) != 0)
203 for (i = 0; i < core.c_vmregions; i++)
204 if (sizeof (struct vm_infox) !=
205 bfd_bread (&vminfo, sizeof (struct vm_infox), abfd))
208 if (vminfo.vminfo_offset)
210 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
211 sec = bfd_make_section_anyway_with_flags (abfd, ".vmdata", flags);
215 sec->size = vminfo.vminfo_size;
216 sec->vma = vminfo.vminfo_addr;
217 sec->filepos = vminfo.vminfo_offset;
221 return_value = (bfd_target *) abfd->xvec; /* This is garbage for now. */
223 xcoff64_core_p_error:
224 if (bfd_get_error () != bfd_error_system_call)
225 bfd_set_error (bfd_error_wrong_format);
230 /* Return `TRUE' if given core is from the given executable. */
233 xcoff64_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
235 struct core_dumpxx core;
238 const char *str1, *str2;
239 bfd_boolean return_value = FALSE;
241 /* Get the header. */
242 if (bfd_seek (core_bfd, 0, SEEK_SET) != 0)
245 if (sizeof (struct core_dumpxx) !=
246 bfd_bread (&core, sizeof (struct core_dumpxx), core_bfd))
249 if (bfd_seek (core_bfd, core.c_loader, SEEK_SET) != 0)
253 path = bfd_malloc (alloc);
261 if (bfd_bread (s, 1, core_bfd) != 1)
262 goto xcoff64_core_file_matches_executable_p_end_1;
267 if (s == path + alloc)
272 n = bfd_realloc (path, alloc);
274 goto xcoff64_core_file_matches_executable_p_end_1;
281 str1 = strrchr (path, '/');
282 str2 = strrchr (exec_bfd->filename, '/');
284 /* Step over character '/'. */
285 str1 = str1 != NULL ? str1 + 1 : path;
286 str2 = str2 != NULL ? str2 + 1 : exec_bfd->filename;
288 if (strcmp (str1, str2) == 0)
291 xcoff64_core_file_matches_executable_p_end_1:
297 xcoff64_core_file_failing_command (bfd *abfd)
299 struct core_dumpxx *c = core_hdr (abfd);
300 char *return_value = 0;
303 return_value = c->c_u.U_proc.pi_comm;
309 xcoff64_core_file_failing_signal (bfd *abfd)
311 struct core_dumpxx *c = core_hdr (abfd);
312 int return_value = 0;
315 return_value = c->c_signo;
320 #else /* AIX_5_CORE */
323 xcoff64_core_p (bfd *abfd ATTRIBUTE_UNUSED)
325 bfd_set_error (bfd_error_wrong_format);
330 xcoff64_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
332 return generic_core_file_matches_executable_p (core_bfd, exec_bfd);
336 xcoff64_core_file_failing_command (bfd *abfd ATTRIBUTE_UNUSED)
342 xcoff64_core_file_failing_signal (bfd *abfd ATTRIBUTE_UNUSED)
347 #endif /* AIX_5_CORE */