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