* libnlm.h (struct nlm_backend_data): New fields
[external/binutils.git] / bfd / libnlm.h
1 /* BFD back-end data structures for NLM (NetWare Loadable Modules) files.
2    Copyright (C) 1993 Free Software Foundation, Inc.
3    Written by Cygnus Support.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
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 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21 #ifndef _LIBNLM_H_
22 #define _LIBNLM_H_ 1
23
24 #ifdef ARCH_SIZE
25 #  define NLM_ARCH_SIZE ARCH_SIZE
26 #endif
27 #include "nlm/common.h"
28 #include "nlm/internal.h"
29 #include "nlm/external.h"
30
31 /* A reloc for an imported NLM symbol.  Normal relocs are associated
32    with sections, and include a symbol.  These relocs are associated
33    with (undefined) symbols, and include a section.  */
34
35 struct nlm_relent
36 {
37   /* Section of reloc.  */
38   asection *section;
39   /* Reloc info (sym_ptr_ptr field set only when canonicalized).  */
40   arelent reloc;
41 };
42
43 /* Information we keep for an NLM symbol.  */
44
45 typedef struct
46 {
47   /* BFD symbol.  */
48   asymbol symbol;
49   /* Number of reloc entries for imported symbol.  */
50   bfd_size_type rcnt;
51   /* Array of reloc information for imported symbol.  */
52   struct nlm_relent *relocs;
53 } nlmNAME(symbol_type);
54
55 extern boolean nlm_mkobject PARAMS ((bfd *));
56 extern boolean nlm_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
57                                           unsigned long));
58
59 extern void nlmNAME(get_symbol_info)
60      PARAMS ((bfd *, asymbol *, symbol_info *));
61 extern unsigned int nlmNAME(get_symtab_upper_bound)
62      PARAMS ((bfd *));
63 extern unsigned int nlmNAME(get_symtab)
64      PARAMS ((bfd *, asymbol **));
65 extern asymbol *nlmNAME(make_empty_symbol)
66      PARAMS ((bfd *));
67 extern void nlmNAME(print_symbol)
68      PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type));
69 extern unsigned int nlmNAME(get_reloc_upper_bound)
70      PARAMS ((bfd *, asection *));
71 extern unsigned int nlmNAME(canonicalize_reloc)
72      PARAMS ((bfd *, asection *, arelent **, asymbol **));
73 extern bfd_target *nlmNAME(object_p)
74      PARAMS ((bfd *));
75 extern boolean nlmNAME(set_arch_mach)
76      PARAMS ((bfd *, enum bfd_architecture, unsigned long));
77 extern boolean nlmNAME(set_section_contents)
78      PARAMS ((bfd *, asection *, PTR, file_ptr, bfd_size_type));
79 extern boolean nlmNAME(write_object_contents)
80      PARAMS ((bfd *));
81
82 /* Some private data is stashed away for future use using the tdata pointer
83    in the bfd structure.  */
84
85 struct nlm_obj_tdata
86 {
87   /* Actual data, but ref like ptr */
88   Nlm_Internal_Fixed_Header     nlm_fixed_hdr[1];
89   Nlm_Internal_Variable_Header  nlm_variable_hdr[1];
90   Nlm_Internal_Version_Header   nlm_version_hdr[1];
91   Nlm_Internal_Copyright_Header nlm_copyright_hdr[1];
92   Nlm_Internal_Extended_Header  nlm_extended_hdr[1];
93   Nlm_Internal_Custom_Header    nlm_custom_hdr[1];
94   /* BFD NLM symbols.  */
95   nlmNAME(symbol_type)          *nlm_symbols;
96   /* Lowest text and data VMA values.  */
97   bfd_vma                       nlm_text_low;
98   bfd_vma                       nlm_data_low;
99   /* Caches for data read from object file.  */
100   arelent *                     nlm_reloc_fixups;
101   asection **                   nlm_reloc_fixup_secs;
102 };
103
104 #define nlm_tdata(bfd)                  ((bfd) -> tdata.nlm_obj_data)
105 #define nlm_fixed_header(bfd)           (nlm_tdata(bfd) -> nlm_fixed_hdr)
106 #define nlm_variable_header(bfd)        (nlm_tdata(bfd) -> nlm_variable_hdr)
107 #define nlm_version_header(bfd)         (nlm_tdata(bfd) -> nlm_version_hdr)
108 #define nlm_copyright_header(bfd)       (nlm_tdata(bfd) -> nlm_copyright_hdr)
109 #define nlm_extended_header(bfd)        (nlm_tdata(bfd) -> nlm_extended_hdr)
110 #define nlm_custom_header(bfd)          (nlm_tdata(bfd) -> nlm_custom_hdr)
111 #define nlm_get_symbols(bfd)            (nlm_tdata(bfd) -> nlm_symbols)
112 #define nlm_set_symbols(bfd, p)         (nlm_tdata(bfd) -> nlm_symbols = (p))
113 #define nlm_set_text_low(bfd, i)        (nlm_tdata(bfd) -> nlm_text_low = (i))
114 #define nlm_get_text_low(bfd)           (nlm_tdata(bfd) -> nlm_text_low)
115 #define nlm_set_data_low(bfd, i)        (nlm_tdata(bfd) -> nlm_data_low = (i))
116 #define nlm_get_data_low(bfd)           (nlm_tdata(bfd) -> nlm_data_low)
117 #define nlm_relocation_fixups(bfd)      (nlm_tdata(bfd) -> nlm_reloc_fixups)
118 #define nlm_relocation_fixup_secs(bfd)  (nlm_tdata(bfd)->nlm_reloc_fixup_secs)
119
120 /* This is used when writing out the external relocs. */
121
122 struct reloc_and_sec
123 {
124   arelent *rel;
125   asection *sec;
126 };
127
128 /* We store some function pointer in the backend structure.  This lets
129    different NLM targets share most of the same code, while providing
130    slightly different code where necessary.  */
131
132 struct nlm_backend_data
133 {
134   /* Signature for this backend.  */
135   char signature[NLM_SIGNATURE_SIZE];
136   /* Size of the fixed header.  */
137   bfd_size_type fixed_header_size;
138   /* Size of optional prefix for this backend.  Some backend may
139      require this to be a function, but so far a constant is OK.  This
140      is for a prefix which precedes the standard NLM fixed header.  */
141   bfd_size_type optional_prefix_size;
142   /* Architecture.  */
143   enum bfd_architecture arch;
144   /* Machine.  */
145   long mach;
146   /* Some NLM formats have a prefix on the file.  If this function is
147      not NULL, it will be called by nlm_object_p.  It should return
148      true if this file could match this format, and it should leave
149      the BFD such that a bfd_read will pick up the fixed header.  */
150   boolean (*nlm_backend_object_p) PARAMS ((bfd *));
151   /* Write out the prefix.  This function may be NULL.  This must
152      write out the same number of bytes as is in the field
153      optional_prefix_size.  */
154   boolean (*nlm_write_prefix) PARAMS ((bfd *));
155   /* Read a relocation fixup from abfd.  The reloc information is
156      machine specific.  The second argument is the symbol if this is
157      an import, or NULL if this is a reloc fixup.  This function
158      should set the third argument to the section which the reloc
159      belongs in, and the fourth argument to the reloc itself; it does
160      not need to fill in the sym_ptr_ptr field for a reloc against an
161      import symbol.  */
162   boolean (*nlm_read_reloc) PARAMS ((bfd *, nlmNAME(symbol_type) *,
163                                      asection **, arelent *));
164   /* To make objcopy to an i386 NLM work, the i386 backend needs a
165      chance to work over the relocs.  This is a bit icky.  */
166   boolean (*nlm_mangle_relocs) PARAMS ((bfd *, asection *, PTR data,
167                                         bfd_vma offset,
168                                         bfd_size_type count));
169   /* Read an import record from abfd.  It would be nice if this
170      were in a machine-dependent format, but it doesn't seem to be. */
171   boolean (*nlm_read_import) PARAMS ((bfd *, nlmNAME(symbol_type) *));
172   /* Write an import record to abfd. */
173   boolean (*nlm_write_import) PARAMS ((bfd *, asection *, arelent *));
174   /* Set the section for a public symbol.  This may be NULL, in which
175      case a default method will be used.  */
176   boolean (*nlm_set_public_section) PARAMS ((bfd *, nlmNAME(symbol_type) *));
177   /* Get the offset to write out for a public symbol.  This may be
178      NULL, in which case a default method will be used.  */
179   bfd_vma (*nlm_get_public_offset) PARAMS ((bfd *, asymbol *));
180   /* Swap the fixed header in and out */
181   void (*nlm_swap_fhdr_in) PARAMS ((bfd *,
182                                     PTR,
183                                     Nlm_Internal_Fixed_Header *));
184   void (*nlm_swap_fhdr_out) PARAMS ((bfd *,
185                                      struct nlm_internal_fixed_header *,
186                                      PTR));
187   /* Write out an external reference.  */
188   boolean (*nlm_write_external) PARAMS ((bfd *, bfd_size_type,
189                                          asymbol *,
190                                          struct reloc_and_sec *));
191 };
192
193 #define nlm_backend(bfd) \
194   ((struct nlm_backend_data *)((bfd) -> xvec -> backend_data))
195 #define nlm_signature(bfd) \
196   (nlm_backend(bfd) ? nlm_backend(bfd) -> signature : "")
197 #define nlm_fixed_header_size(bfd) \
198   (nlm_backend(bfd) ? nlm_backend(bfd) -> fixed_header_size : 0)
199 #define nlm_optional_prefix_size(bfd) \
200   (nlm_backend(bfd) ? nlm_backend(bfd) -> optional_prefix_size : 0)
201 #define nlm_architecture(bfd) \
202   (nlm_backend(bfd) ? nlm_backend(bfd) -> arch : bfd_arch_unknown)
203 #define nlm_machine(bfd) \
204   (nlm_backend(bfd) ? nlm_backend(bfd) -> mach : 0)
205 #define nlm_backend_object_p_func(bfd) \
206   (nlm_backend(bfd) ? nlm_backend(bfd) -> nlm_backend_object_p : 0)
207 #define nlm_write_prefix_func(bfd) \
208   (nlm_backend(bfd) ? nlm_backend(bfd) -> nlm_write_prefix : 0)
209 #define nlm_read_reloc_func(bfd) \
210   (nlm_backend(bfd) ? nlm_backend(bfd) -> nlm_read_reloc : 0)
211 #define nlm_mangle_relocs_func(bfd) \
212   (nlm_backend(bfd) ? nlm_backend(bfd) -> nlm_mangle_relocs : 0)
213 #define nlm_read_import_func(bfd) \
214   (nlm_backend(bfd) ? nlm_backend(bfd) -> nlm_read_import : 0)
215 #define nlm_write_import_func(bfd) \
216   (nlm_backend(bfd) ? nlm_backend(bfd) -> nlm_write_import : 0)
217 #define nlm_set_public_section_func(bfd) \
218   (nlm_backend(bfd) ? nlm_backend(bfd) -> nlm_set_public_section : 0)
219 #define nlm_get_public_offset_func(bfd) \
220   (nlm_backend(bfd) ? nlm_backend(bfd) -> nlm_get_public_offset : 0)
221 #define nlm_swap_fixed_header_in_func(bfd) \
222   (nlm_backend(bfd) ? nlm_backend(bfd) -> nlm_swap_fhdr_in : 0)
223 #define nlm_swap_fixed_header_out_func(bfd) \
224   (nlm_backend(bfd) ? nlm_backend(bfd) -> nlm_swap_fhdr_out : 0)
225 #define nlm_write_external_func(bfd) \
226   (nlm_backend(bfd) ? nlm_backend(bfd) -> nlm_write_external : 0)
227
228 /* The NLM code, data, and uninitialized sections have no names defined
229    in the NLM, but bfd wants to give them names, so use the traditional
230    UNIX names.  */
231
232 #define NLM_CODE_NAME                   ".text"
233 #define NLM_INITIALIZED_DATA_NAME       ".data"
234 #define NLM_UNINITIALIZED_DATA_NAME     ".bss"
235
236 #endif /* _LIBNLM_H_ */