1247779Sbapt/* BFD back-end data structures for NLM (NetWare Loadable Modules) files. 2247779Sbapt Copyright (C) 1993-2017 Free Software Foundation, Inc. 3247779Sbapt Written by Cygnus Support. 4247779Sbapt 5247779Sbapt This file is part of BFD, the Binary File Descriptor library. 6247779Sbapt 7247779Sbapt This program is free software; you can redistribute it and/or modify 8247779Sbapt it under the terms of the GNU General Public License as published by 9247779Sbapt the Free Software Foundation; either version 3 of the License, or 10247779Sbapt (at your option) any later version. 11247779Sbapt 12247779Sbapt This program is distributed in the hope that it will be useful, 13247779Sbapt but WITHOUT ANY WARRANTY; without even the implied warranty of 14247779Sbapt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15247779Sbapt GNU General Public License for more details. 16247779Sbapt 17247779Sbapt You should have received a copy of the GNU General Public License 18247779Sbapt along with this program; if not, write to the Free Software 19247779Sbapt Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 20247779Sbapt MA 02110-1301, USA. */ 21247779Sbapt 22247779Sbapt#ifndef _LIBNLM_H_ 23247779Sbapt#define _LIBNLM_H_ 1 24247779Sbapt 25247779Sbapt#ifdef ARCH_SIZE 26247779Sbapt# define NLM_ARCH_SIZE ARCH_SIZE 27247779Sbapt#endif 28247779Sbapt#include "nlm/common.h" 29247779Sbapt#include "nlm/internal.h" 30247779Sbapt#include "nlm/external.h" 31247779Sbapt 32247779Sbapt/* A reloc for an imported NLM symbol. Normal relocs are associated 33247779Sbapt with sections, and include a symbol. These relocs are associated 34247779Sbapt with (undefined) symbols, and include a section. */ 35247779Sbapt 36247779Sbaptstruct nlm_relent 37247779Sbapt{ 38247779Sbapt /* Section of reloc. */ 39247779Sbapt asection *section; 40247779Sbapt /* Reloc info (sym_ptr_ptr field set only when canonicalized). */ 41247779Sbapt arelent reloc; 42247779Sbapt}; 43247779Sbapt 44247779Sbapt/* Information we keep for an NLM symbol. */ 45247779Sbapt 46247779Sbapttypedef struct 47247779Sbapt{ 48247779Sbapt /* BFD symbol. */ 49247779Sbapt asymbol symbol; 50247779Sbapt /* Number of reloc entries for imported symbol. */ 51247779Sbapt bfd_size_type rcnt; 52247779Sbapt /* Array of reloc information for imported symbol. */ 53247779Sbapt struct nlm_relent *relocs; 54247779Sbapt} nlmNAME(symbol_type); 55247779Sbapt 56247779Sbaptextern bfd_boolean nlm_mkobject (bfd *); 57247779Sbaptextern bfd_boolean nlm_set_arch_mach (bfd *, enum bfd_architecture, unsigned long); 58247779Sbaptextern void nlmNAME (get_symbol_info) (bfd *, asymbol *, symbol_info *); 59247779Sbaptextern long nlmNAME (get_symtab_upper_bound)(bfd *); 60247779Sbaptextern long nlmNAME (canonicalize_symtab) (bfd *, asymbol **); 61247779Sbaptextern asymbol * nlmNAME (make_empty_symbol) (bfd *); 62247779Sbaptextern void nlmNAME (print_symbol) (bfd *, void *, asymbol *, bfd_print_symbol_type); 63247779Sbaptextern long nlmNAME (get_reloc_upper_bound) (bfd *, asection *); 64247779Sbaptextern long nlmNAME (canonicalize_reloc) (bfd *, asection *, arelent **, asymbol **); 65247779Sbaptextern const bfd_target * nlmNAME (object_p) (bfd *); 66247779Sbaptextern bfd_boolean nlmNAME (set_arch_mach) (bfd *, enum bfd_architecture, unsigned long); 67247779Sbaptextern bfd_boolean nlmNAME (set_section_contents) (bfd *, asection *, const void *, file_ptr, bfd_size_type); 68247779Sbaptextern bfd_boolean nlmNAME (write_object_contents) (bfd *); 69247779Sbapt 70247779Sbapt/* Some private data is stashed away for future use using the tdata pointer 71247779Sbapt in the bfd structure. */ 72247779Sbapt 73247779Sbaptstruct nlm_obj_tdata 74247779Sbapt{ 75247779Sbapt /* Actual data, but ref like ptr */ 76247779Sbapt Nlm_Internal_Fixed_Header nlm_fixed_hdr[1]; 77247779Sbapt Nlm_Internal_Variable_Header nlm_variable_hdr[1]; 78247779Sbapt Nlm_Internal_Version_Header nlm_version_hdr[1]; 79247779Sbapt Nlm_Internal_Copyright_Header nlm_copyright_hdr[1]; 80247779Sbapt Nlm_Internal_Extended_Header nlm_extended_hdr[1]; 81247779Sbapt Nlm_Internal_Custom_Header nlm_custom_hdr[1]; 82247779Sbapt Nlm_Internal_Cygnus_Ext_Header nlm_cygnus_ext_hdr[1]; 83247779Sbapt /* BFD NLM symbols. */ 84 nlmNAME (symbol_type) * nlm_symbols; 85 /* Lowest text and data VMA values. */ 86 bfd_vma nlm_text_low; 87 bfd_vma nlm_data_low; 88 /* Caches for data read from object file. */ 89 arelent * nlm_reloc_fixups; 90 asection ** nlm_reloc_fixup_secs; 91 /* Backend specific information. This should probably be a pointer, 92 but that would require yet another entry point to initialize the 93 structure. */ 94 union 95 { 96 struct /* Alpha backend information. */ 97 { 98 bfd_vma gp; /* GP value. */ 99 bfd_vma lita_address; /* .lita section address. */ 100 bfd_size_type lita_size; /* .lita section size. */ 101 } 102 alpha_backend_data; 103 } 104 backend_data; 105}; 106 107#define nlm_tdata(bfd) ((bfd) -> tdata.nlm_obj_data) 108#define nlm_fixed_header(bfd) (nlm_tdata (bfd) -> nlm_fixed_hdr) 109#define nlm_variable_header(bfd) (nlm_tdata (bfd) -> nlm_variable_hdr) 110#define nlm_version_header(bfd) (nlm_tdata (bfd) -> nlm_version_hdr) 111#define nlm_copyright_header(bfd) (nlm_tdata (bfd) -> nlm_copyright_hdr) 112#define nlm_extended_header(bfd) (nlm_tdata (bfd) -> nlm_extended_hdr) 113#define nlm_custom_header(bfd) (nlm_tdata (bfd) -> nlm_custom_hdr) 114#define nlm_cygnus_ext_header(bfd) (nlm_tdata (bfd) -> nlm_cygnus_ext_hdr) 115#define nlm_get_symbols(bfd) (nlm_tdata (bfd) -> nlm_symbols) 116#define nlm_set_symbols(bfd, p) (nlm_tdata (bfd) -> nlm_symbols = (p)) 117#define nlm_set_text_low(bfd, i) (nlm_tdata (bfd) -> nlm_text_low = (i)) 118#define nlm_get_text_low(bfd) (nlm_tdata (bfd) -> nlm_text_low) 119#define nlm_set_data_low(bfd, i) (nlm_tdata (bfd) -> nlm_data_low = (i)) 120#define nlm_get_data_low(bfd) (nlm_tdata (bfd) -> nlm_data_low) 121#define nlm_relocation_fixups(bfd) (nlm_tdata (bfd) -> nlm_reloc_fixups) 122#define nlm_relocation_fixup_secs(bfd) (nlm_tdata (bfd) -> nlm_reloc_fixup_secs) 123#define nlm_alpha_backend_data(bfd) (&nlm_tdata (bfd) -> backend_data.alpha_backend_data) 124 125/* This is used when writing out the external relocs. */ 126 127struct reloc_and_sec 128{ 129 arelent *rel; 130 asection *sec; 131}; 132 133/* We store some function pointer in the backend structure. This lets 134 different NLM targets share most of the same code, while providing 135 slightly different code where necessary. */ 136 137struct nlm_backend_data 138{ 139 /* Signature for this backend. */ 140 char signature[NLM_SIGNATURE_SIZE]; 141 /* Size of the fixed header. */ 142 bfd_size_type fixed_header_size; 143 /* Size of optional prefix for this backend. Some backend may 144 require this to be a function, but so far a constant is OK. This 145 is for a prefix which precedes the standard NLM fixed header. */ 146 bfd_size_type optional_prefix_size; 147 /* Architecture. */ 148 enum bfd_architecture arch; 149 /* Machine. */ 150 unsigned int mach; 151 /* Some NLM formats do not use the uninitialized data section, so 152 all uninitialized data must be put into the regular data section 153 instead. */ 154 bfd_boolean no_uninitialized_data; 155 /* Some NLM formats have a prefix on the file. If this function is 156 not NULL, it will be called by nlm_object_p. It should return 157 TRUE if this file could match this format, and it should leave 158 the BFD such that a bfd_bread will pick up the fixed header. */ 159 bfd_boolean (*nlm_backend_object_p) (bfd *); 160 /* Write out the prefix. This function may be NULL. This must 161 write out the same number of bytes as is in the field 162 optional_prefix_size. */ 163 bfd_boolean (*nlm_write_prefix) (bfd *); 164 /* Read a relocation fixup from abfd. The reloc information is 165 machine specific. The second argument is the symbol if this is 166 an import, or NULL if this is a reloc fixup. This function 167 should set the third argument to the section which the reloc 168 belongs in, and the fourth argument to the reloc itself; it does 169 not need to fill in the sym_ptr_ptr field for a reloc against an 170 import symbol. */ 171 bfd_boolean (*nlm_read_reloc) (bfd *, nlmNAME (symbol_type) *, asection **, arelent *); 172 /* To make objcopy to an i386 NLM work, the i386 backend needs a 173 chance to work over the relocs. This is a bit icky. */ 174 bfd_boolean (*nlm_mangle_relocs) (bfd *, asection *, const void *, bfd_vma, bfd_size_type); 175 /* Read an import record from abfd. It would be nice if this 176 were in a machine-dependent format, but it doesn't seem to be. */ 177 bfd_boolean (*nlm_read_import) (bfd *, nlmNAME (symbol_type) *); 178 /* Write an import record to abfd. */ 179 bfd_boolean (*nlm_write_import) (bfd *, asection *, arelent *); 180 /* Set the section for a public symbol. This may be NULL, in which 181 case a default method will be used. */ 182 bfd_boolean (*nlm_set_public_section) (bfd *, nlmNAME (symbol_type) *); 183 /* Get the offset to write out for a public symbol. This may be 184 NULL, in which case a default method will be used. */ 185 bfd_vma (*nlm_get_public_offset) (bfd *, asymbol *); 186 /* Swap the fixed header in and out */ 187 void (*nlm_swap_fhdr_in) (bfd *, void *, Nlm_Internal_Fixed_Header *); 188 void (*nlm_swap_fhdr_out) (bfd *, struct nlm_internal_fixed_header *, void *); 189 /* Write out an external reference. */ 190 bfd_boolean (*nlm_write_external) (bfd *, bfd_size_type, asymbol *, struct reloc_and_sec *); 191 bfd_boolean (*nlm_write_export) (bfd *, asymbol *, bfd_vma); 192}; 193 194#define nlm_backend(bfd) ((struct nlm_backend_data *)((bfd) -> xvec -> backend_data)) 195#define nlm_signature(bfd) (nlm_backend (bfd) -> signature) 196#define nlm_fixed_header_size(bfd) (nlm_backend (bfd) -> fixed_header_size) 197#define nlm_optional_prefix_size(bfd) (nlm_backend (bfd) -> optional_prefix_size) 198#define nlm_architecture(bfd) (nlm_backend (bfd) -> arch) 199#define nlm_machine(bfd) (nlm_backend (bfd) -> mach) 200#define nlm_no_uninitialized_data(bfd) (nlm_backend (bfd) -> no_uninitialized_data) 201#define nlm_backend_object_p_func(bfd) (nlm_backend (bfd) -> nlm_backend_object_p) 202#define nlm_write_prefix_func(bfd) (nlm_backend (bfd) -> nlm_write_prefix) 203#define nlm_read_reloc_func(bfd) (nlm_backend (bfd) -> nlm_read_reloc) 204#define nlm_mangle_relocs_func(bfd) (nlm_backend (bfd) -> nlm_mangle_relocs) 205#define nlm_read_import_func(bfd) (nlm_backend (bfd) -> nlm_read_import) 206#define nlm_write_import_func(bfd) (nlm_backend (bfd) -> nlm_write_import) 207#define nlm_set_public_section_func(bfd) (nlm_backend (bfd) -> nlm_set_public_section) 208#define nlm_get_public_offset_func(bfd) (nlm_backend (bfd) -> nlm_get_public_offset) 209#define nlm_swap_fixed_header_in_func(bfd) (nlm_backend (bfd) -> nlm_swap_fhdr_in) 210#define nlm_swap_fixed_header_out_func(bfd)(nlm_backend (bfd) -> nlm_swap_fhdr_out) 211#define nlm_write_external_func(bfd) (nlm_backend (bfd) -> nlm_write_external) 212#define nlm_write_export_func(bfd) (nlm_backend (bfd) -> nlm_write_export) 213 214/* The NLM code, data, and uninitialized sections have no names defined 215 in the NLM, but bfd wants to give them names, so use the traditional 216 UNIX names. */ 217 218#define NLM_CODE_NAME ".text" 219#define NLM_INITIALIZED_DATA_NAME ".data" 220#define NLM_UNINITIALIZED_DATA_NAME ".bss" 221 222#endif /* _LIBNLM_H_ */ 223