som.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* HP PA-RISC SOM object file format: definitions internal to BFD.
  2. Copyright (C) 1990-2022 Free Software Foundation, Inc.
  3. Contributed by the Center for Software Science at the
  4. University of Utah (pa-gdb-bugs@cs.utah.edu).
  5. This file is part of BFD, the Binary File Descriptor library.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  17. 02110-1301, USA. */
  18. #ifndef _SOM_H
  19. #define _SOM_H
  20. #include "libhppa.h"
  21. /* We want reloc.h to provide PA 2.0 defines. */
  22. #define PA_2_0
  23. #include "som/aout.h"
  24. #include "som/lst.h"
  25. #include "som/internal.h"
  26. /* The SOM BFD backend doesn't currently use anything from these
  27. two include files, but it's likely to need them in the future. */
  28. #ifdef R_DLT_REL
  29. #include <shl.h>
  30. #include <dl.h>
  31. #endif
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. #if defined (HOST_HPPABSD) || defined (HOST_HPPAOSF)
  36. /* BSD uses a completely different scheme for object file identification.
  37. so for now, define _PA_RISC_ID to accept any random value for a model
  38. number. */
  39. #undef _PA_RISC_ID
  40. #define _PA_RISC_ID(__m_num) 1
  41. #endif /* HOST_HPPABSD */
  42. typedef struct som_symbol
  43. {
  44. asymbol symbol;
  45. unsigned int som_type;
  46. /* Structured like the ELF tc_data union. Allows more code sharing
  47. in GAS this way. */
  48. union
  49. {
  50. struct
  51. {
  52. unsigned int hppa_arg_reloc;
  53. unsigned int hppa_priv_level;
  54. } ap;
  55. void * any;
  56. }
  57. tc_data;
  58. /* Index of this symbol in the symbol table. Only used when
  59. building relocation streams for incomplete objects. */
  60. int index;
  61. /* How many times this symbol is used in a relocation. By sorting
  62. the symbols from most used to least used we can significantly
  63. reduce the size of the relocation stream for incomplete objects. */
  64. int reloc_count;
  65. /* During object file writing, the offset of the name of this symbol
  66. in the SOM string table. */
  67. int stringtab_offset;
  68. }
  69. som_symbol_type;
  70. /* A structure containing all the magic information stored in a BFD's
  71. private data which needs to be copied during an objcopy/strip run. */
  72. struct som_exec_data
  73. {
  74. /* Sort-of a magic number. BSD uses it to distinguish between
  75. native executables and hpux executables. */
  76. short system_id;
  77. /* Magic exec flags. These control things like whether or not
  78. null pointer dereferencing is allowed and the like. */
  79. long exec_flags;
  80. /* We must preserve the version identifier too. Some versions
  81. of the HP linker do not grok NEW_VERSION_ID for reasons unknown. */
  82. unsigned int version_id;
  83. /* Add more stuff here as needed. Good examples of information
  84. we might want to pass would be presumed_dp, entry_* and maybe
  85. others from the file header. */
  86. };
  87. struct somdata
  88. {
  89. /* All the magic information about an executable which lives
  90. in the private BFD structure and needs to be copied from
  91. the input bfd to the output bfd during an objcopy/strip. */
  92. struct som_exec_data *exec_data;
  93. /* These three fields are only used when writing files and are
  94. generated from scratch. They need not be copied for objcopy
  95. or strip to work. */
  96. struct som_header *file_hdr;
  97. struct som_string_auxhdr *copyright_aux_hdr;
  98. struct som_string_auxhdr *version_aux_hdr;
  99. struct som_exec_auxhdr *exec_hdr;
  100. struct som_compilation_unit *comp_unit;
  101. /* Pointers to a saved copy of the symbol and string tables. These
  102. need not be copied for objcopy or strip to work. */
  103. som_symbol_type *symtab;
  104. char *stringtab;
  105. asymbol **sorted_syms;
  106. /* We remember these offsets so that after check_file_format, we have
  107. no dependencies on the particular format of the exec_hdr.
  108. These offsets need not be copied for objcopy or strip to work. */
  109. file_ptr sym_filepos;
  110. file_ptr str_filepos;
  111. file_ptr reloc_filepos;
  112. unsigned stringtab_size;
  113. void * line_info;
  114. };
  115. struct som_data_struct
  116. {
  117. struct somdata a;
  118. };
  119. /* Substructure of som_section_data_struct used to hold information
  120. which can't be represented by the generic BFD section structure,
  121. but which must be copied during objcopy or strip. */
  122. struct som_copyable_section_data_struct
  123. {
  124. /* Various fields in space and subspace headers that we need
  125. to pass around. */
  126. unsigned int sort_key : 8;
  127. unsigned int access_control_bits : 7;
  128. unsigned int is_defined : 1;
  129. unsigned int is_private : 1;
  130. unsigned int quadrant : 2;
  131. unsigned int is_comdat : 1;
  132. unsigned int is_common : 1;
  133. unsigned int dup_common : 1;
  134. /* For subspaces, this points to the section which represents the
  135. space in which the subspace is contained. For spaces it points
  136. back to the section for this space. */
  137. asection *container;
  138. /* The user-specified space number. It is wrong to use this as
  139. an index since duplicates and holes are allowed. */
  140. int space_number;
  141. /* Add more stuff here as needed. Good examples of information
  142. we might want to pass would be initialization pointers,
  143. and the many subspace flags we do not represent yet. */
  144. };
  145. /* Used to keep extra SOM specific information for a given section.
  146. reloc_size holds the size of the relocation stream, note this
  147. is very different from the number of relocations as SOM relocations
  148. are variable length.
  149. reloc_stream is the actual stream of relocation entries. */
  150. struct som_section_data_struct
  151. {
  152. struct som_copyable_section_data_struct *copy_data;
  153. unsigned int reloc_size;
  154. unsigned char *reloc_stream;
  155. struct som_space_dictionary_record *space_dict;
  156. struct som_subspace_dictionary_record *subspace_dict;
  157. };
  158. #define somdata(bfd) ((bfd)->tdata.som_data->a)
  159. #define obj_som_exec_data(bfd) (somdata (bfd).exec_data)
  160. #define obj_som_file_hdr(bfd) (somdata (bfd).file_hdr)
  161. #define obj_som_exec_hdr(bfd) (somdata (bfd).exec_hdr)
  162. #define obj_som_copyright_hdr(bfd) (somdata (bfd).copyright_aux_hdr)
  163. #define obj_som_version_hdr(bfd) (somdata (bfd).version_aux_hdr)
  164. #define obj_som_compilation_unit(bfd) (somdata (bfd).comp_unit)
  165. #define obj_som_symtab(bfd) (somdata (bfd).symtab)
  166. #define obj_som_stringtab(bfd) (somdata (bfd).stringtab)
  167. #define obj_som_sym_filepos(bfd) (somdata (bfd).sym_filepos)
  168. #define obj_som_str_filepos(bfd) (somdata (bfd).str_filepos)
  169. #define obj_som_stringtab_size(bfd) (somdata (bfd).stringtab_size)
  170. #define obj_som_reloc_filepos(bfd) (somdata (bfd).reloc_filepos)
  171. #define obj_som_sorted_syms(bfd) (somdata (bfd).sorted_syms)
  172. #define som_section_data(sec) ((struct som_section_data_struct *) sec->used_by_bfd)
  173. #define som_symbol_data(symbol) ((som_symbol_type *) symbol)
  174. /* Defines groups of basic relocations. FIXME: These should
  175. be the only basic relocations created by GAS. The rest
  176. should be internal to the BFD backend.
  177. The idea is both SOM and ELF define these basic relocation
  178. types so they map into a SOM or ELF specific relocation as
  179. appropriate. This allows GAS to share much more code
  180. between the two object formats. */
  181. #define R_HPPA_NONE R_NO_RELOCATION
  182. #define R_HPPA R_CODE_ONE_SYMBOL
  183. #define R_HPPA_PCREL_CALL R_PCREL_CALL
  184. #define R_HPPA_ABS_CALL R_ABS_CALL
  185. #define R_HPPA_GOTOFF R_DP_RELATIVE
  186. #define R_HPPA_ENTRY R_ENTRY
  187. #define R_HPPA_EXIT R_EXIT
  188. #define R_HPPA_COMPLEX R_COMP1
  189. #define R_HPPA_BEGIN_BRTAB R_BEGIN_BRTAB
  190. #define R_HPPA_END_BRTAB R_END_BRTAB
  191. #define R_HPPA_BEGIN_TRY R_BEGIN_TRY
  192. #define R_HPPA_END_TRY R_END_TRY
  193. /* Exported functions, mostly for use by GAS. */
  194. bool bfd_som_set_section_attributes
  195. (asection *, int, int, unsigned int, int);
  196. bool bfd_som_set_subsection_attributes
  197. (asection *, asection *, int, unsigned int, int, int, int, int);
  198. void bfd_som_set_symbol_type
  199. (asymbol *, unsigned int);
  200. bool bfd_som_attach_aux_hdr
  201. (bfd *, int, char *);
  202. int **hppa_som_gen_reloc_type
  203. (bfd *, int, int, enum hppa_reloc_field_selector_type_alt, int, asymbol *);
  204. bool bfd_som_attach_compilation_unit
  205. (bfd *, const char *, const char *, const char *, const char *);
  206. asection *bfd_section_from_som_symbol
  207. (bfd *abfd, struct som_external_symbol_dictionary_record *symbol);
  208. #ifdef __cplusplus
  209. }
  210. #endif
  211. #endif /* _SOM_H */