rs6000-core.c 20 KB

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