Back to index

cell-binutils  2.17cvs20070401
libnlm.h
Go to the documentation of this file.
00001 /* BFD back-end data structures for NLM (NetWare Loadable Modules) files.
00002    Copyright 1993, 1994, 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
00003    Written by Cygnus Support.
00004 
00005    This file is part of BFD, the Binary File Descriptor library.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00020 
00021 #ifndef _LIBNLM_H_
00022 #define _LIBNLM_H_ 1
00023 
00024 #ifdef ARCH_SIZE
00025 #  define NLM_ARCH_SIZE ARCH_SIZE
00026 #endif
00027 #include "nlm/common.h"
00028 #include "nlm/internal.h"
00029 #include "nlm/external.h"
00030 
00031 /* A reloc for an imported NLM symbol.  Normal relocs are associated
00032    with sections, and include a symbol.  These relocs are associated
00033    with (undefined) symbols, and include a section.  */
00034 
00035 struct nlm_relent
00036 {
00037   /* Section of reloc.  */
00038   asection *section;
00039   /* Reloc info (sym_ptr_ptr field set only when canonicalized).  */
00040   arelent reloc;
00041 };
00042 
00043 /* Information we keep for an NLM symbol.  */
00044 
00045 typedef struct
00046 {
00047   /* BFD symbol.  */
00048   asymbol symbol;
00049   /* Number of reloc entries for imported symbol.  */
00050   bfd_size_type rcnt;
00051   /* Array of reloc information for imported symbol.  */
00052   struct nlm_relent *relocs;
00053 } nlmNAME(symbol_type);
00054 
00055 extern bfd_boolean        nlm_mkobject                    (bfd *);
00056 extern bfd_boolean        nlm_set_arch_mach               (bfd *, enum bfd_architecture, unsigned long);
00057 extern void               nlmNAME (get_symbol_info)       (bfd *, asymbol *, symbol_info *);
00058 extern long               nlmNAME (get_symtab_upper_bound)(bfd *);
00059 extern long               nlmNAME (canonicalize_symtab)   (bfd *, asymbol **);
00060 extern asymbol *          nlmNAME (make_empty_symbol)     (bfd *);
00061 extern void               nlmNAME (print_symbol)          (bfd *, void *, asymbol *, bfd_print_symbol_type);
00062 extern long               nlmNAME (get_reloc_upper_bound) (bfd *, asection *);
00063 extern long               nlmNAME (canonicalize_reloc)    (bfd *, asection *, arelent **, asymbol **);
00064 extern const bfd_target * nlmNAME (object_p)              (bfd *);
00065 extern bfd_boolean        nlmNAME (set_arch_mach)         (bfd *, enum bfd_architecture, unsigned long);
00066 extern bfd_boolean        nlmNAME (set_section_contents)  (bfd *, asection *, const void *, file_ptr, bfd_size_type);
00067 extern bfd_boolean        nlmNAME (write_object_contents) (bfd *);
00068 
00069 /* Some private data is stashed away for future use using the tdata pointer
00070    in the bfd structure.  */
00071 
00072 struct nlm_obj_tdata
00073 {
00074   /* Actual data, but ref like ptr */
00075   Nlm_Internal_Fixed_Header nlm_fixed_hdr[1];
00076   Nlm_Internal_Variable_Header     nlm_variable_hdr[1];
00077   Nlm_Internal_Version_Header      nlm_version_hdr[1];
00078   Nlm_Internal_Copyright_Header    nlm_copyright_hdr[1];
00079   Nlm_Internal_Extended_Header     nlm_extended_hdr[1];
00080   Nlm_Internal_Custom_Header       nlm_custom_hdr[1];
00081   Nlm_Internal_Cygnus_Ext_Header nlm_cygnus_ext_hdr[1];
00082   /* BFD NLM symbols.  */
00083   nlmNAME (symbol_type)     *      nlm_symbols;
00084   /* Lowest text and data VMA values.  */
00085   bfd_vma                   nlm_text_low;
00086   bfd_vma                   nlm_data_low;
00087   /* Caches for data read from object file.  */
00088   arelent *                 nlm_reloc_fixups;
00089   asection **               nlm_reloc_fixup_secs;
00090   /* Backend specific information.  This should probably be a pointer,
00091      but that would require yet another entry point to initialize the
00092      structure.  */
00093   union
00094     {
00095       struct  /* Alpha backend information.  */
00096        {
00097          bfd_vma gp;               /* GP value.  */
00098          bfd_vma lita_address;            /* .lita section address.  */
00099          bfd_size_type lita_size;  /* .lita section size.  */
00100        }
00101       alpha_backend_data;
00102     }
00103   backend_data;
00104 };
00105 
00106 #define nlm_tdata(bfd)                    ((bfd) -> tdata.nlm_obj_data)
00107 #define nlm_fixed_header(bfd)             (nlm_tdata (bfd) -> nlm_fixed_hdr)
00108 #define nlm_variable_header(bfd)   (nlm_tdata (bfd) -> nlm_variable_hdr)
00109 #define nlm_version_header(bfd)           (nlm_tdata (bfd) -> nlm_version_hdr)
00110 #define nlm_copyright_header(bfd)  (nlm_tdata (bfd) -> nlm_copyright_hdr)
00111 #define nlm_extended_header(bfd)   (nlm_tdata (bfd) -> nlm_extended_hdr)
00112 #define nlm_custom_header(bfd)            (nlm_tdata (bfd) -> nlm_custom_hdr)
00113 #define nlm_cygnus_ext_header(bfd) (nlm_tdata (bfd) -> nlm_cygnus_ext_hdr)
00114 #define nlm_get_symbols(bfd)              (nlm_tdata (bfd) -> nlm_symbols)
00115 #define nlm_set_symbols(bfd, p)           (nlm_tdata (bfd) -> nlm_symbols = (p))
00116 #define nlm_set_text_low(bfd, i)   (nlm_tdata (bfd) -> nlm_text_low = (i))
00117 #define nlm_get_text_low(bfd)             (nlm_tdata (bfd) -> nlm_text_low)
00118 #define nlm_set_data_low(bfd, i)   (nlm_tdata (bfd) -> nlm_data_low = (i))
00119 #define nlm_get_data_low(bfd)             (nlm_tdata (bfd) -> nlm_data_low)
00120 #define nlm_relocation_fixups(bfd) (nlm_tdata (bfd) -> nlm_reloc_fixups)
00121 #define nlm_relocation_fixup_secs(bfd)    (nlm_tdata (bfd) -> nlm_reloc_fixup_secs)
00122 #define nlm_alpha_backend_data(bfd)    (&nlm_tdata (bfd) -> backend_data.alpha_backend_data)
00123 
00124 /* This is used when writing out the external relocs. */
00125 
00126 struct reloc_and_sec
00127 {
00128   arelent *rel;
00129   asection *sec;
00130 };
00131 
00132 /* We store some function pointer in the backend structure.  This lets
00133    different NLM targets share most of the same code, while providing
00134    slightly different code where necessary.  */
00135 
00136 struct nlm_backend_data
00137 {
00138   /* Signature for this backend.  */
00139   char signature[NLM_SIGNATURE_SIZE];
00140   /* Size of the fixed header.  */
00141   bfd_size_type fixed_header_size;
00142   /* Size of optional prefix for this backend.  Some backend may
00143      require this to be a function, but so far a constant is OK.  This
00144      is for a prefix which precedes the standard NLM fixed header.  */
00145   bfd_size_type optional_prefix_size;
00146   /* Architecture.  */
00147   enum bfd_architecture arch;
00148   /* Machine.  */
00149   unsigned int mach;
00150   /* Some NLM formats do not use the uninitialized data section, so
00151      all uninitialized data must be put into the regular data section
00152      instead.  */
00153   bfd_boolean no_uninitialized_data;
00154   /* Some NLM formats have a prefix on the file.  If this function is
00155      not NULL, it will be called by nlm_object_p.  It should return
00156      TRUE if this file could match this format, and it should leave
00157      the BFD such that a bfd_bread will pick up the fixed header.  */
00158   bfd_boolean (*nlm_backend_object_p) (bfd *);
00159   /* Write out the prefix.  This function may be NULL.  This must
00160      write out the same number of bytes as is in the field
00161      optional_prefix_size.  */
00162   bfd_boolean (*nlm_write_prefix) (bfd *);
00163   /* Read a relocation fixup from abfd.  The reloc information is
00164      machine specific.  The second argument is the symbol if this is
00165      an import, or NULL if this is a reloc fixup.  This function
00166      should set the third argument to the section which the reloc
00167      belongs in, and the fourth argument to the reloc itself; it does
00168      not need to fill in the sym_ptr_ptr field for a reloc against an
00169      import symbol.  */
00170   bfd_boolean (*nlm_read_reloc) (bfd *, nlmNAME (symbol_type) *, asection **, arelent *);
00171   /* To make objcopy to an i386 NLM work, the i386 backend needs a
00172      chance to work over the relocs.  This is a bit icky.  */
00173   bfd_boolean (*nlm_mangle_relocs) (bfd *, asection *, const void *, bfd_vma,  bfd_size_type);
00174   /* Read an import record from abfd.  It would be nice if this
00175      were in a machine-dependent format, but it doesn't seem to be. */
00176   bfd_boolean (*nlm_read_import) (bfd *, nlmNAME (symbol_type) *);
00177   /* Write an import record to abfd. */
00178   bfd_boolean (*nlm_write_import) (bfd *, asection *, arelent *);
00179   /* Set the section for a public symbol.  This may be NULL, in which
00180      case a default method will be used.  */
00181   bfd_boolean (*nlm_set_public_section) (bfd *, nlmNAME (symbol_type) *);
00182   /* Get the offset to write out for a public symbol.  This may be
00183      NULL, in which case a default method will be used.  */
00184   bfd_vma (*nlm_get_public_offset) (bfd *, asymbol *);
00185   /* Swap the fixed header in and out */
00186   void (*nlm_swap_fhdr_in)  (bfd *, void *, Nlm_Internal_Fixed_Header *);
00187   void (*nlm_swap_fhdr_out) (bfd *, struct nlm_internal_fixed_header *, void *);
00188   /* Write out an external reference.  */
00189   bfd_boolean (*nlm_write_external) (bfd *, bfd_size_type, asymbol *, struct reloc_and_sec *);
00190   bfd_boolean (*nlm_write_export) (bfd *, asymbol *, bfd_vma);
00191 };
00192 
00193 #define nlm_backend(bfd)   ((struct nlm_backend_data *)((bfd) -> xvec -> backend_data))
00194 #define nlm_signature(bfd)                 (nlm_backend (bfd) -> signature)
00195 #define nlm_fixed_header_size(bfd)         (nlm_backend (bfd) -> fixed_header_size)
00196 #define nlm_optional_prefix_size(bfd)      (nlm_backend (bfd) -> optional_prefix_size)
00197 #define nlm_architecture(bfd)              (nlm_backend (bfd) -> arch)
00198 #define nlm_machine(bfd)                   (nlm_backend (bfd) -> mach)
00199 #define nlm_no_uninitialized_data(bfd)     (nlm_backend (bfd) -> no_uninitialized_data)
00200 #define nlm_backend_object_p_func(bfd)     (nlm_backend (bfd) -> nlm_backend_object_p)
00201 #define nlm_write_prefix_func(bfd)         (nlm_backend (bfd) -> nlm_write_prefix)
00202 #define nlm_read_reloc_func(bfd)           (nlm_backend (bfd) -> nlm_read_reloc)
00203 #define nlm_mangle_relocs_func(bfd)        (nlm_backend (bfd) -> nlm_mangle_relocs)
00204 #define nlm_read_import_func(bfd)          (nlm_backend (bfd) -> nlm_read_import)
00205 #define nlm_write_import_func(bfd)         (nlm_backend (bfd) -> nlm_write_import)
00206 #define nlm_set_public_section_func(bfd)   (nlm_backend (bfd) -> nlm_set_public_section)
00207 #define nlm_get_public_offset_func(bfd)    (nlm_backend (bfd) -> nlm_get_public_offset)
00208 #define nlm_swap_fixed_header_in_func(bfd) (nlm_backend (bfd) -> nlm_swap_fhdr_in)
00209 #define nlm_swap_fixed_header_out_func(bfd)(nlm_backend (bfd) -> nlm_swap_fhdr_out)
00210 #define nlm_write_external_func(bfd)       (nlm_backend (bfd) -> nlm_write_external)
00211 #define nlm_write_export_func(bfd)         (nlm_backend (bfd) -> nlm_write_export)
00212 
00213 /* The NLM code, data, and uninitialized sections have no names defined
00214    in the NLM, but bfd wants to give them names, so use the traditional
00215    UNIX names.  */
00216 
00217 #define NLM_CODE_NAME                     ".text"
00218 #define NLM_INITIALIZED_DATA_NAME  ".data"
00219 #define NLM_UNINITIALIZED_DATA_NAME       ".bss"
00220 
00221 #endif /* _LIBNLM_H_ */