xref: /openbsd/gnu/usr.bin/binutils/bfd/libnlm.h (revision 007c2a45)
12159047fSniklas /* BFD back-end data structures for NLM (NetWare Loadable Modules) files.
2*007c2a45Smiod    Copyright 1993, 1994, 2001, 2002, 2003 Free Software Foundation, Inc.
32159047fSniklas    Written by Cygnus Support.
42159047fSniklas 
52159047fSniklas This file is part of BFD, the Binary File Descriptor library.
62159047fSniklas 
72159047fSniklas This program is free software; you can redistribute it and/or modify
82159047fSniklas it under the terms of the GNU General Public License as published by
92159047fSniklas the Free Software Foundation; either version 2 of the License, or
102159047fSniklas (at your option) any later version.
112159047fSniklas 
122159047fSniklas This program is distributed in the hope that it will be useful,
132159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
142159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
152159047fSniklas GNU General Public License for more details.
162159047fSniklas 
172159047fSniklas You should have received a copy of the GNU General Public License
182159047fSniklas along with this program; if not, write to the Free Software
192159047fSniklas Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
202159047fSniklas 
212159047fSniklas #ifndef _LIBNLM_H_
222159047fSniklas #define _LIBNLM_H_ 1
232159047fSniklas 
242159047fSniklas #ifdef ARCH_SIZE
252159047fSniklas #  define NLM_ARCH_SIZE ARCH_SIZE
262159047fSniklas #endif
272159047fSniklas #include "nlm/common.h"
282159047fSniklas #include "nlm/internal.h"
292159047fSniklas #include "nlm/external.h"
302159047fSniklas 
312159047fSniklas /* A reloc for an imported NLM symbol.  Normal relocs are associated
322159047fSniklas    with sections, and include a symbol.  These relocs are associated
332159047fSniklas    with (undefined) symbols, and include a section.  */
342159047fSniklas 
352159047fSniklas struct nlm_relent
362159047fSniklas {
372159047fSniklas   /* Section of reloc.  */
382159047fSniklas   asection *section;
392159047fSniklas   /* Reloc info (sym_ptr_ptr field set only when canonicalized).  */
402159047fSniklas   arelent reloc;
412159047fSniklas };
422159047fSniklas 
432159047fSniklas /* Information we keep for an NLM symbol.  */
442159047fSniklas 
452159047fSniklas typedef struct
462159047fSniklas {
472159047fSniklas   /* BFD symbol.  */
482159047fSniklas   asymbol symbol;
492159047fSniklas   /* Number of reloc entries for imported symbol.  */
502159047fSniklas   bfd_size_type rcnt;
512159047fSniklas   /* Array of reloc information for imported symbol.  */
522159047fSniklas   struct nlm_relent *relocs;
532159047fSniklas } nlmNAME(symbol_type);
542159047fSniklas 
55c074d1c9Sdrahn extern bfd_boolean nlm_mkobject
56c074d1c9Sdrahn   PARAMS ((bfd *));
57c074d1c9Sdrahn extern bfd_boolean nlm_set_arch_mach
58c074d1c9Sdrahn   PARAMS ((bfd *, enum bfd_architecture, unsigned long));
592159047fSniklas 
602159047fSniklas extern void nlmNAME(get_symbol_info)
612159047fSniklas   PARAMS ((bfd *, asymbol *, symbol_info *));
622159047fSniklas extern long nlmNAME(get_symtab_upper_bound)
632159047fSniklas   PARAMS ((bfd *));
64*007c2a45Smiod extern long nlmNAME(canonicalize_symtab)
652159047fSniklas   PARAMS ((bfd *, asymbol **));
662159047fSniklas extern asymbol *nlmNAME(make_empty_symbol)
672159047fSniklas   PARAMS ((bfd *));
682159047fSniklas extern void nlmNAME(print_symbol)
692159047fSniklas   PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type));
702159047fSniklas extern long nlmNAME(get_reloc_upper_bound)
712159047fSniklas   PARAMS ((bfd *, asection *));
722159047fSniklas extern long nlmNAME(canonicalize_reloc)
732159047fSniklas   PARAMS ((bfd *, asection *, arelent **, asymbol **));
742159047fSniklas extern const bfd_target *nlmNAME(object_p)
752159047fSniklas   PARAMS ((bfd *));
76c074d1c9Sdrahn extern bfd_boolean nlmNAME(set_arch_mach)
772159047fSniklas   PARAMS ((bfd *, enum bfd_architecture, unsigned long));
78c074d1c9Sdrahn extern bfd_boolean nlmNAME(set_section_contents)
79*007c2a45Smiod   PARAMS ((bfd *, asection *, const PTR, file_ptr, bfd_size_type));
80c074d1c9Sdrahn extern bfd_boolean nlmNAME(write_object_contents)
812159047fSniklas   PARAMS ((bfd *));
822159047fSniklas 
832159047fSniklas /* Some private data is stashed away for future use using the tdata pointer
842159047fSniklas    in the bfd structure.  */
852159047fSniklas 
862159047fSniklas struct nlm_obj_tdata
872159047fSniklas {
882159047fSniklas   /* Actual data, but ref like ptr */
892159047fSniklas   Nlm_Internal_Fixed_Header	nlm_fixed_hdr[1];
902159047fSniklas   Nlm_Internal_Variable_Header	nlm_variable_hdr[1];
912159047fSniklas   Nlm_Internal_Version_Header	nlm_version_hdr[1];
922159047fSniklas   Nlm_Internal_Copyright_Header	nlm_copyright_hdr[1];
932159047fSniklas   Nlm_Internal_Extended_Header	nlm_extended_hdr[1];
942159047fSniklas   Nlm_Internal_Custom_Header	nlm_custom_hdr[1];
952159047fSniklas   Nlm_Internal_Cygnus_Ext_Header nlm_cygnus_ext_hdr[1];
962159047fSniklas   /* BFD NLM symbols.  */
972159047fSniklas   nlmNAME(symbol_type)		*nlm_symbols;
982159047fSniklas   /* Lowest text and data VMA values.  */
992159047fSniklas   bfd_vma			nlm_text_low;
1002159047fSniklas   bfd_vma			nlm_data_low;
1012159047fSniklas   /* Caches for data read from object file.  */
1022159047fSniklas   arelent *			nlm_reloc_fixups;
1032159047fSniklas   asection **			nlm_reloc_fixup_secs;
1042159047fSniklas   /* Backend specific information.  This should probably be a pointer,
1052159047fSniklas      but that would require yet another entry point to initialize the
1062159047fSniklas      structure.  */
1072159047fSniklas   union
1082159047fSniklas     {
1092159047fSniklas       struct	/* Alpha backend information.  */
1102159047fSniklas 	{
1112159047fSniklas 	  bfd_vma gp;			/* GP value.  */
1122159047fSniklas 	  bfd_vma lita_address;		/* .lita section address.  */
1132159047fSniklas 	  bfd_size_type lita_size;	/* .lita section size.  */
1142159047fSniklas 	}
1152159047fSniklas       alpha_backend_data;
1162159047fSniklas     }
1172159047fSniklas   backend_data;
1182159047fSniklas };
1192159047fSniklas 
1202159047fSniklas #define nlm_tdata(bfd)			((bfd) -> tdata.nlm_obj_data)
1212159047fSniklas #define nlm_fixed_header(bfd)		(nlm_tdata(bfd) -> nlm_fixed_hdr)
1222159047fSniklas #define nlm_variable_header(bfd)	(nlm_tdata(bfd) -> nlm_variable_hdr)
1232159047fSniklas #define nlm_version_header(bfd)		(nlm_tdata(bfd) -> nlm_version_hdr)
1242159047fSniklas #define nlm_copyright_header(bfd)	(nlm_tdata(bfd) -> nlm_copyright_hdr)
1252159047fSniklas #define nlm_extended_header(bfd)	(nlm_tdata(bfd) -> nlm_extended_hdr)
1262159047fSniklas #define nlm_custom_header(bfd)		(nlm_tdata(bfd) -> nlm_custom_hdr)
1272159047fSniklas #define nlm_cygnus_ext_header(bfd)	(nlm_tdata(bfd) -> nlm_cygnus_ext_hdr)
1282159047fSniklas #define nlm_get_symbols(bfd)		(nlm_tdata(bfd) -> nlm_symbols)
1292159047fSniklas #define nlm_set_symbols(bfd, p)		(nlm_tdata(bfd) -> nlm_symbols = (p))
1302159047fSniklas #define nlm_set_text_low(bfd, i)	(nlm_tdata(bfd) -> nlm_text_low = (i))
1312159047fSniklas #define nlm_get_text_low(bfd)		(nlm_tdata(bfd) -> nlm_text_low)
1322159047fSniklas #define nlm_set_data_low(bfd, i)	(nlm_tdata(bfd) -> nlm_data_low = (i))
1332159047fSniklas #define nlm_get_data_low(bfd)		(nlm_tdata(bfd) -> nlm_data_low)
1342159047fSniklas #define nlm_relocation_fixups(bfd)	(nlm_tdata(bfd) -> nlm_reloc_fixups)
1352159047fSniklas #define nlm_relocation_fixup_secs(bfd)	(nlm_tdata(bfd)->nlm_reloc_fixup_secs)
1362159047fSniklas 
1372159047fSniklas #define nlm_alpha_backend_data(bfd) \
1382159047fSniklas   (&nlm_tdata (bfd)->backend_data.alpha_backend_data)
1392159047fSniklas 
1402159047fSniklas /* This is used when writing out the external relocs. */
1412159047fSniklas 
1422159047fSniklas struct reloc_and_sec
1432159047fSniklas {
1442159047fSniklas   arelent *rel;
1452159047fSniklas   asection *sec;
1462159047fSniklas };
1472159047fSniklas 
1482159047fSniklas /* We store some function pointer in the backend structure.  This lets
1492159047fSniklas    different NLM targets share most of the same code, while providing
1502159047fSniklas    slightly different code where necessary.  */
1512159047fSniklas 
1522159047fSniklas struct nlm_backend_data
1532159047fSniklas {
1542159047fSniklas   /* Signature for this backend.  */
1552159047fSniklas   char signature[NLM_SIGNATURE_SIZE];
1562159047fSniklas   /* Size of the fixed header.  */
1572159047fSniklas   bfd_size_type fixed_header_size;
1582159047fSniklas   /* Size of optional prefix for this backend.  Some backend may
1592159047fSniklas      require this to be a function, but so far a constant is OK.  This
1602159047fSniklas      is for a prefix which precedes the standard NLM fixed header.  */
1612159047fSniklas   bfd_size_type optional_prefix_size;
1622159047fSniklas   /* Architecture.  */
1632159047fSniklas   enum bfd_architecture arch;
1642159047fSniklas   /* Machine.  */
165c074d1c9Sdrahn   unsigned int mach;
1662159047fSniklas   /* Some NLM formats do not use the uninitialized data section, so
1672159047fSniklas      all uninitialized data must be put into the regular data section
1682159047fSniklas      instead.  */
169c074d1c9Sdrahn   bfd_boolean no_uninitialized_data;
1702159047fSniklas   /* Some NLM formats have a prefix on the file.  If this function is
1712159047fSniklas      not NULL, it will be called by nlm_object_p.  It should return
172c074d1c9Sdrahn      TRUE if this file could match this format, and it should leave
173c074d1c9Sdrahn      the BFD such that a bfd_bread will pick up the fixed header.  */
174c074d1c9Sdrahn   bfd_boolean (*nlm_backend_object_p) PARAMS ((bfd *));
1752159047fSniklas   /* Write out the prefix.  This function may be NULL.  This must
1762159047fSniklas      write out the same number of bytes as is in the field
1772159047fSniklas      optional_prefix_size.  */
178c074d1c9Sdrahn   bfd_boolean (*nlm_write_prefix) PARAMS ((bfd *));
1792159047fSniklas   /* Read a relocation fixup from abfd.  The reloc information is
1802159047fSniklas      machine specific.  The second argument is the symbol if this is
1812159047fSniklas      an import, or NULL if this is a reloc fixup.  This function
1822159047fSniklas      should set the third argument to the section which the reloc
1832159047fSniklas      belongs in, and the fourth argument to the reloc itself; it does
1842159047fSniklas      not need to fill in the sym_ptr_ptr field for a reloc against an
1852159047fSniklas      import symbol.  */
186c074d1c9Sdrahn   bfd_boolean (*nlm_read_reloc)
187c074d1c9Sdrahn     PARAMS ((bfd *, nlmNAME(symbol_type) *, asection **, arelent *));
1882159047fSniklas   /* To make objcopy to an i386 NLM work, the i386 backend needs a
1892159047fSniklas      chance to work over the relocs.  This is a bit icky.  */
190c074d1c9Sdrahn   bfd_boolean (*nlm_mangle_relocs)
191*007c2a45Smiod     PARAMS ((bfd *, asection *, const PTR data, bfd_vma offset,
192*007c2a45Smiod 	     bfd_size_type count));
1932159047fSniklas   /* Read an import record from abfd.  It would be nice if this
1942159047fSniklas      were in a machine-dependent format, but it doesn't seem to be. */
195c074d1c9Sdrahn   bfd_boolean (*nlm_read_import) PARAMS ((bfd *, nlmNAME(symbol_type) *));
1962159047fSniklas   /* Write an import record to abfd. */
197c074d1c9Sdrahn   bfd_boolean (*nlm_write_import) PARAMS ((bfd *, asection *, arelent *));
1982159047fSniklas   /* Set the section for a public symbol.  This may be NULL, in which
1992159047fSniklas      case a default method will be used.  */
200c074d1c9Sdrahn   bfd_boolean (*nlm_set_public_section)
201c074d1c9Sdrahn     PARAMS ((bfd *, nlmNAME(symbol_type) *));
2022159047fSniklas   /* Get the offset to write out for a public symbol.  This may be
2032159047fSniklas      NULL, in which case a default method will be used.  */
2042159047fSniklas   bfd_vma (*nlm_get_public_offset) PARAMS ((bfd *, asymbol *));
2052159047fSniklas   /* Swap the fixed header in and out */
206c074d1c9Sdrahn   void (*nlm_swap_fhdr_in)
207c074d1c9Sdrahn     PARAMS ((bfd *, PTR, Nlm_Internal_Fixed_Header *));
208c074d1c9Sdrahn   void (*nlm_swap_fhdr_out)
209c074d1c9Sdrahn     PARAMS ((bfd *, struct nlm_internal_fixed_header *, PTR));
2102159047fSniklas   /* Write out an external reference.  */
211c074d1c9Sdrahn   bfd_boolean (*nlm_write_external)
212c074d1c9Sdrahn     PARAMS ((bfd *, bfd_size_type, asymbol *, struct reloc_and_sec *));
213c074d1c9Sdrahn   bfd_boolean (*nlm_write_export) PARAMS ((bfd *, asymbol *, bfd_vma));
2142159047fSniklas };
2152159047fSniklas 
2162159047fSniklas #define nlm_backend(bfd) \
2172159047fSniklas   ((struct nlm_backend_data *)((bfd) -> xvec -> backend_data))
2182159047fSniklas #define nlm_signature(bfd) \
2192159047fSniklas   (nlm_backend(bfd) -> signature)
2202159047fSniklas #define nlm_fixed_header_size(bfd) \
2212159047fSniklas   (nlm_backend(bfd) -> fixed_header_size)
2222159047fSniklas #define nlm_optional_prefix_size(bfd) \
2232159047fSniklas   (nlm_backend(bfd) -> optional_prefix_size)
2242159047fSniklas #define nlm_architecture(bfd) \
2252159047fSniklas   (nlm_backend(bfd) -> arch)
2262159047fSniklas #define nlm_machine(bfd) \
2272159047fSniklas   (nlm_backend(bfd) -> mach)
2282159047fSniklas #define nlm_no_uninitialized_data(bfd) \
2292159047fSniklas   (nlm_backend(bfd) -> no_uninitialized_data)
2302159047fSniklas #define nlm_backend_object_p_func(bfd) \
2312159047fSniklas   (nlm_backend(bfd) -> nlm_backend_object_p)
2322159047fSniklas #define nlm_write_prefix_func(bfd) \
2332159047fSniklas   (nlm_backend(bfd) -> nlm_write_prefix)
2342159047fSniklas #define nlm_read_reloc_func(bfd) \
2352159047fSniklas   (nlm_backend(bfd) -> nlm_read_reloc)
2362159047fSniklas #define nlm_mangle_relocs_func(bfd) \
2372159047fSniklas   (nlm_backend(bfd) -> nlm_mangle_relocs)
2382159047fSniklas #define nlm_read_import_func(bfd) \
2392159047fSniklas   (nlm_backend(bfd) -> nlm_read_import)
2402159047fSniklas #define nlm_write_import_func(bfd) \
2412159047fSniklas   (nlm_backend(bfd) -> nlm_write_import)
2422159047fSniklas #define nlm_set_public_section_func(bfd) \
2432159047fSniklas   (nlm_backend(bfd) -> nlm_set_public_section)
2442159047fSniklas #define nlm_get_public_offset_func(bfd) \
2452159047fSniklas   (nlm_backend(bfd) -> nlm_get_public_offset)
2462159047fSniklas #define nlm_swap_fixed_header_in_func(bfd) \
2472159047fSniklas   (nlm_backend(bfd) -> nlm_swap_fhdr_in)
2482159047fSniklas #define nlm_swap_fixed_header_out_func(bfd) \
2492159047fSniklas   (nlm_backend(bfd) -> nlm_swap_fhdr_out)
2502159047fSniklas #define nlm_write_external_func(bfd) \
2512159047fSniklas   (nlm_backend(bfd) -> nlm_write_external)
2522159047fSniklas #define nlm_write_export_func(bfd) \
2532159047fSniklas   (nlm_backend(bfd) -> nlm_write_export)
2542159047fSniklas 
2552159047fSniklas /* The NLM code, data, and uninitialized sections have no names defined
2562159047fSniklas    in the NLM, but bfd wants to give them names, so use the traditional
2572159047fSniklas    UNIX names.  */
2582159047fSniklas 
2592159047fSniklas #define NLM_CODE_NAME			".text"
2602159047fSniklas #define NLM_INITIALIZED_DATA_NAME	".data"
2612159047fSniklas #define NLM_UNINITIALIZED_DATA_NAME	".bss"
2622159047fSniklas 
2632159047fSniklas #endif /* _LIBNLM_H_ */
264