osf-core.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* BFD back-end for OSF/1 core files.
  2. Copyright (C) 1993-2022 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. /* This file can only be compiled on systems which use OSF/1 style
  17. core files. */
  18. #include "sysdep.h"
  19. #include "bfd.h"
  20. #include "libbfd.h"
  21. #include <sys/user.h>
  22. #ifdef OSF_CORE
  23. #include <sys/core.h>
  24. #endif
  25. /* forward declarations */
  26. #define osf_core_core_file_matches_executable_p generic_core_file_matches_executable_p
  27. #define osf_core_core_file_pid _bfd_nocore_core_file_pid
  28. /* These are stored in the bfd's tdata */
  29. struct osf_core_struct
  30. {
  31. int sig;
  32. char cmd[MAXCOMLEN + 1];
  33. };
  34. #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
  35. #define core_signal(bfd) (core_hdr(bfd)->sig)
  36. #define core_command(bfd) (core_hdr(bfd)->cmd)
  37. static asection *
  38. make_bfd_asection (bfd *abfd,
  39. const char *name,
  40. flagword flags,
  41. bfd_size_type size,
  42. bfd_vma vma,
  43. file_ptr filepos)
  44. {
  45. asection *asect;
  46. asect = bfd_make_section_anyway_with_flags (abfd, name, flags);
  47. if (!asect)
  48. return NULL;
  49. asect->size = size;
  50. asect->vma = vma;
  51. asect->filepos = filepos;
  52. asect->alignment_power = 8;
  53. return asect;
  54. }
  55. static bfd_cleanup
  56. osf_core_core_file_p (bfd *abfd)
  57. {
  58. int val;
  59. int i;
  60. char *secname;
  61. struct core_filehdr core_header;
  62. size_t amt;
  63. amt = sizeof core_header;
  64. val = bfd_bread (& core_header, amt, abfd);
  65. if (val != sizeof core_header)
  66. return NULL;
  67. if (! startswith (core_header.magic, "Core"))
  68. return NULL;
  69. core_hdr (abfd) = (struct osf_core_struct *)
  70. bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
  71. if (!core_hdr (abfd))
  72. return NULL;
  73. strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
  74. core_signal (abfd) = core_header.signo;
  75. for (i = 0; i < core_header.nscns; i++)
  76. {
  77. struct core_scnhdr core_scnhdr;
  78. flagword flags;
  79. amt = sizeof core_scnhdr;
  80. val = bfd_bread (& core_scnhdr, amt, abfd);
  81. if (val != sizeof core_scnhdr)
  82. break;
  83. /* Skip empty sections. */
  84. if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
  85. continue;
  86. switch (core_scnhdr.scntype)
  87. {
  88. case SCNRGN:
  89. secname = ".data";
  90. flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  91. break;
  92. case SCNSTACK:
  93. secname = ".stack";
  94. flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  95. break;
  96. case SCNREGS:
  97. secname = ".reg";
  98. flags = SEC_HAS_CONTENTS;
  99. break;
  100. default:
  101. _bfd_error_handler (_("unhandled OSF/1 core file section type %d"),
  102. core_scnhdr.scntype);
  103. continue;
  104. }
  105. if (!make_bfd_asection (abfd, secname, flags,
  106. (bfd_size_type) core_scnhdr.size,
  107. (bfd_vma) core_scnhdr.vaddr,
  108. (file_ptr) core_scnhdr.scnptr))
  109. goto fail;
  110. }
  111. /* OK, we believe you. You're a core file (sure, sure). */
  112. return _bfd_no_cleanup;
  113. fail:
  114. bfd_release (abfd, core_hdr (abfd));
  115. core_hdr (abfd) = NULL;
  116. bfd_section_list_clear (abfd);
  117. return NULL;
  118. }
  119. static char *
  120. osf_core_core_file_failing_command (bfd *abfd)
  121. {
  122. return core_command (abfd);
  123. }
  124. static int
  125. osf_core_core_file_failing_signal (bfd *abfd)
  126. {
  127. return core_signal (abfd);
  128. }
  129. /* If somebody calls any byte-swapping routines, shoot them. */
  130. static void
  131. swap_abort (void)
  132. {
  133. abort (); /* This way doesn't require any declaration for ANSI to fuck up */
  134. }
  135. #define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
  136. #define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
  137. #define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
  138. #define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
  139. #define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
  140. #define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
  141. const bfd_target core_osf_vec =
  142. {
  143. "osf-core",
  144. bfd_target_unknown_flavour,
  145. BFD_ENDIAN_LITTLE, /* target byte order */
  146. BFD_ENDIAN_LITTLE, /* target headers byte order */
  147. (HAS_RELOC | EXEC_P | /* object flags */
  148. HAS_LINENO | HAS_DEBUG |
  149. HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
  150. (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  151. 0, /* symbol prefix */
  152. ' ', /* ar_pad_char */
  153. 16, /* ar_max_namelen */
  154. 0, /* match priority. */
  155. TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */
  156. NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
  157. NO_GET, NO_GETS, NO_PUT, /* 32 bit data */
  158. NO_GET, NO_GETS, NO_PUT, /* 16 bit data */
  159. NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
  160. NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */
  161. NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */
  162. { /* bfd_check_format */
  163. _bfd_dummy_target, /* unknown format */
  164. _bfd_dummy_target, /* object file */
  165. _bfd_dummy_target, /* archive */
  166. osf_core_core_file_p /* a core file */
  167. },
  168. { /* bfd_set_format */
  169. _bfd_bool_bfd_false_error,
  170. _bfd_bool_bfd_false_error,
  171. _bfd_bool_bfd_false_error,
  172. _bfd_bool_bfd_false_error
  173. },
  174. { /* bfd_write_contents */
  175. _bfd_bool_bfd_false_error,
  176. _bfd_bool_bfd_false_error,
  177. _bfd_bool_bfd_false_error,
  178. _bfd_bool_bfd_false_error
  179. },
  180. BFD_JUMP_TABLE_GENERIC (_bfd_generic),
  181. BFD_JUMP_TABLE_COPY (_bfd_generic),
  182. BFD_JUMP_TABLE_CORE (osf_core),
  183. BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
  184. BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
  185. BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
  186. BFD_JUMP_TABLE_WRITE (_bfd_generic),
  187. BFD_JUMP_TABLE_LINK (_bfd_nolink),
  188. BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  189. NULL,
  190. NULL /* backend_data */
  191. };