libnlm.h 10 KB

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