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