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