#include "libnlm.h"
#include "nlmconv.h"
-/* Needed for Alpha support. */
+#ifdef NLMCONV_ALPHA
#include "coff/sym.h"
#include "coff/ecoff.h"
+#endif
/* If strerror is just a macro, we want to use the one from libiberty
since it will handle undefined values. */
static void mangle_relocs PARAMS ((bfd *, asection *, arelent ***,
long *, char *,
bfd_size_type));
+static void default_mangle_relocs PARAMS ((bfd *, asection *, arelent ***,
+ long *, char *,
+ bfd_size_type));
+static char *link_inputs PARAMS ((struct string_list *, char *));
+static const char *choose_temp_base_try PARAMS ((const char *,
+ const char *));
+static void choose_temp_base PARAMS ((void));
+static int pexecute PARAMS ((char *, char *[]));
+
+#ifdef NLMCONV_I386
static void i386_mangle_relocs PARAMS ((bfd *, asection *, arelent ***,
long *, char *,
bfd_size_type));
+#endif
+
+#ifdef NLMCONV_ALPHA
static void alpha_mangle_relocs PARAMS ((bfd *, asection *, arelent ***,
long *, char *,
bfd_size_type));
-/* start-sanitize-powerpc-netware */
+#endif
+
+#ifdef NLMCONV_POWERPC
static void powerpc_build_stubs PARAMS ((bfd *, bfd *, asymbol ***, long *));
static void powerpc_resolve_stubs PARAMS ((bfd *, bfd *));
static void powerpc_mangle_relocs PARAMS ((bfd *, asection *, arelent ***,
long *, char *,
bfd_size_type));
-/* end-sanitize-powerpc-netware */
-static void default_mangle_relocs PARAMS ((bfd *, asection *, arelent ***,
- long *, char *,
- bfd_size_type));
-static char *link_inputs PARAMS ((struct string_list *, char *));
-static const char *choose_temp_base_try PARAMS ((const char *,
- const char *));
-static void choose_temp_base PARAMS ((void));
-static int pexecute PARAMS ((char *, char *[]));
+#endif
\f
/* The main routine. */
bfd_fatal ("make .nlmsections section");
if (! bfd_set_section_flags (outbfd, secsec, SEC_HAS_CONTENTS))
bfd_fatal ("set .nlmsections flags");
-/* start-sanitize-powerpc-netware */
+#ifdef NLMCONV_POWERPC
/* For PowerPC NetWare we need to build stubs for calls to undefined
symbols. Because each stub requires an entry in the TOC section
which must be at the same location as other entries in the TOC
goes in setup_sections. */
if (bfd_get_arch (inbfd) == bfd_arch_powerpc)
powerpc_build_stubs (inbfd, outbfd, &symbols, &symcount);
-/* end-sanitize-powerpc-netware */
+#endif
/* Set up the sections. */
bfd_map_over_sections (inbfd, setup_sections, (PTR) outbfd);
symbols will confuse it. */
if ((sym->flags & BSF_DEBUGGING) == 0
&& bfd_asymbol_name (sym)[0] == '_'
- && bfd_get_section (sym) == &bfd_und_section)
+ && bfd_is_und_section (bfd_get_section (sym)))
{
if (strcmp (bfd_asymbol_name (sym), "_edata") == 0)
{
sym->section = bss_sec;
endsym = sym;
}
-/* start-sanitize-powerpc-netware */
+
+#ifdef NLMCONV_POWERPC
/* For PowerPC NetWare, we define __GOT0. This is the start
of the .got section. */
if (bfd_get_arch (inbfd) == bfd_arch_powerpc
sym->value = got_sec->output_offset;
sym->section = got_sec->output_section;
}
-/* end-sanitize-powerpc-netware */
+#endif
}
/* If this is a global symbol, check the export list. */
/* If it's an undefined symbol, see if it's on the import list.
Change the prefix if necessary. */
- if (bfd_get_section (sym) == &bfd_und_section)
+ if (bfd_is_und_section (bfd_get_section (sym)))
{
register struct string_list *l;
nlm_version_header (outbfd)->year = ptm->tm_year + 1900;
strncpy (version_hdr->stamp, "VeRsIoN#", 8);
}
-/* start-sanitize-powerpc-netware */
+#ifdef NLMCONV_POWERPC
/* Resolve the stubs we build for PowerPC NetWare. */
if (bfd_get_arch (inbfd) == bfd_arch_powerpc)
powerpc_resolve_stubs (inbfd, outbfd);
-/* end-sanitize-powerpc-netware */
+#endif
/* Copy over the sections. */
bfd_map_over_sections (inbfd, copy_sections, (PTR) outbfd);
{
switch (arch)
{
+#ifdef NLMCONV_I386
case bfd_arch_i386:
return "nlm32-i386";
+#endif
+#ifdef NLMCONV_SPARC
case bfd_arch_sparc:
return "nlm32-sparc";
+#endif
+#ifdef NLMCONV_ALPHA
case bfd_arch_alpha:
return "nlm32-alpha";
-/* start-sanitize-powerpc-netware */
+#endif
+#ifdef NLMCONV_POWERPC
case bfd_arch_powerpc:
return "nlm32-powerpc";
-/* end-sanitize-powerpc-netware */
+#endif
default:
- fprintf (stderr, "%s: no default NLM format for %s\n",
+ fprintf (stderr, "%s: support not compiled in for %s\n",
program_name, bfd_printable_arch_mach (arch, mach));
exit (1);
/* Avoid warning. */
arelent **combined;
total_count = reloc_count + outsec->reloc_count;
- combined = (arelent **) xmalloc (total_count * sizeof (arelent));
+ combined = (arelent **) xmalloc (total_count * sizeof (arelent *));
memcpy (combined, outsec->orelocation,
- outsec->reloc_count * sizeof (arelent));
+ outsec->reloc_count * sizeof (arelent *));
memcpy (combined + outsec->reloc_count, relocs,
- (size_t) (reloc_count * sizeof (arelent)));
+ (size_t) (reloc_count * sizeof (arelent *)));
free (outsec->orelocation);
reloc_count = total_count;
relocs = combined;
{
switch (bfd_get_arch (outbfd))
{
+#ifdef NLMCONV_I386
case bfd_arch_i386:
i386_mangle_relocs (outbfd, insec, relocs_ptr, reloc_count_ptr,
contents, contents_size);
break;
+#endif
+#ifdef NLMCONV_ALPHA
case bfd_arch_alpha:
alpha_mangle_relocs (outbfd, insec, relocs_ptr, reloc_count_ptr,
contents, contents_size);
break;
-/* start-sanitize-powerpc-netware */
+#endif
+#ifdef NLMCONV_POWERPC
case bfd_arch_powerpc:
powerpc_mangle_relocs (outbfd, insec, relocs_ptr, reloc_count_ptr,
contents, contents_size);
break;
-/* end-sanitize-powerpc-netware */
+#endif
default:
default_mangle_relocs (outbfd, insec, relocs_ptr, reloc_count_ptr,
contents, contents_size);
(*relocs)->address += insec->output_offset;
}
}
+\f
+#ifdef NLMCONV_I386
/* NetWare on the i386 supports a restricted set of relocs, which are
different from those used on other i386 targets. This routine
/* Adjust the reloc for the changes we just made. */
rel->addend = 0;
- if (bfd_get_section (sym) != &bfd_und_section)
+ if (! bfd_is_und_section (bfd_get_section (sym)))
rel->sym_ptr_ptr = bfd_get_section (sym)->symbol_ptr_ptr;
}
}
}
+#endif /* NLMCONV_I386 */
+\f
+#ifdef NLMCONV_ALPHA
+
/* On the Alpha the first reloc for every section must be a special
relocs which hold the GP address. Also, the first reloc in the
file must be a special reloc which holds the address of the .lita
}
*relocs = (arelent *) xmalloc (sizeof (arelent));
- (*relocs)->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
+ (*relocs)->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
(*relocs)->address = nlm_alpha_backend_data (outbfd)->lita_address;
(*relocs)->addend = nlm_alpha_backend_data (outbfd)->lita_size + 1;
(*relocs)->howto = &nlm32_alpha_nw_howto;
bfd_ecoff_get_gp_value (insec->owner);
*relocs = (arelent *) xmalloc (sizeof (arelent));
- (*relocs)->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
+ (*relocs)->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
(*relocs)->address = nlm_alpha_backend_data (outbfd)->gp;
(*relocs)->addend = 0;
(*relocs)->howto = &nlm32_alpha_nw_howto;
(*relocs)->address += insec->output_offset;
}
}
-/* start-sanitize-powerpc-netware */
+
+#endif /* NLMCONV_ALPHA */
+\f
+#ifdef NLMCONV_POWERPC
/* We keep a linked list of stubs which we must build. Because BFD
requires us to know the sizes of all sections before we can set the
/* We must make a stub for every undefined symbol whose name
starts with '.'. */
if (bfd_asymbol_name (sym)[0] != '.'
- || bfd_get_section (sym) != &bfd_und_section)
+ || ! bfd_is_und_section (bfd_get_section (sym)))
continue;
/* Make a new undefined symbol with the same name but without
/* PowerPC NetWare requires a custom header. We create it here.
The first word is the header version number, currently 1. The
- second word is the timestamp of the input file. */
+ second word is the timestamp of the input file. Unfortunately,
+ they do not conform to the emergent standard for custom headers.
+ We must fake the version number and timestamp in the offset and
+ length fields. */
memcpy (nlm_custom_header (outbfd)->stamp, "CuStHeAd", 8);
- nlm_custom_header (outbfd)->dataLength = 8;
- nlm_custom_header (outbfd)->data = xmalloc (8);
- bfd_h_put_32 (outbfd, (bfd_vma) 1,
- (bfd_byte *) nlm_custom_header (outbfd)->data);
+ nlm_custom_header (outbfd)->hdrLength = 0;
+ /* Put version number in dataOffset field. */
+ nlm_custom_header (outbfd)->dataOffset = 1;
+ /* Put timestamp in length field. */
{
struct stat s;
if (stat (bfd_get_filename (inbfd), &s) < 0)
s.st_mtime = 0;
- bfd_h_put_32 (outbfd, (bfd_vma) s.st_mtime,
- (bfd_byte *) nlm_custom_header (outbfd)->data + 4);
+ nlm_custom_header (outbfd)->dataLength = s.st_mtime;
}
+ /* No data stamp. */
+ memset (nlm_custom_header (outbfd)->dataStamp, 0,
+ sizeof (nlm_custom_header (outbfd)->dataStamp));
}
/* Resolve all the stubs for PowerPC NetWare. We fill in the contents
rel->address += insec->output_offset;
}
}
-/* end-sanitize-powerpc-netware */
+
+#endif /* NLMCONV_POWERPC */
\f
/* Name of linker. */
#ifndef LD_NAME