This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH RFA] implement "ld --embedded-relocs" for 32-bit MIPSELF.
- To: binutils at sources dot redhat dot com
- Subject: [PATCH RFA] implement "ld --embedded-relocs" for 32-bit MIPSELF.
- From: cgd at broadcom dot com
- Date: 31 Oct 2001 17:53:29 -0800
hey folks,
This patch implements and adds a test case for "ld --embedded-relocs"
for 32-bit MIPS ELF. (Actually, it adds a good generic place to put
MIPS ELF ld tests, and drops a test in there. 8-)
The code was written/modified by Mitch Lichtenberg (he's got an
assignment on file too) and then substantially cleaned up by me. I
added the test case. (I'm the right contact for all of the patch,
tho.)
The current version of this code has gotten some use internally, and
the pre-cleanup version of the code has been in heavy use here for the
last 9 months or so. (Some significant software we've written depends
on it, and on -membedded-pic working in binutils and the compiler.)
We've most recently been using it in binutils from 2001-10-10 sources.
I've taken this patch and used it to build the following set of
targets:
mips-elf mipsel-elf
mips64-elf mips64el-elf
mips-linux mipsel-linux
mips64-linux mips64el-linux
mips-ecoff mipsel-ecoff
All continue to build and, with the exception of the newly-added
testcases (which pass where they're run 8-) cause identical log files
when 'make check' over the binutils compared to the a pre-patch source
tree.
There are no documentation changes, etc., because the manual already
seems to document --embedded-relocs for MIPS...
chris
====
[ bfd/Changelog ]
2001-10-31 Chris Demetriou <cgd@broadcom.com>
Mitch Lichtenberg <mpl@broadcom.com>
* bfd-in.h (bfd_mips_elf32_create_embedded_relocs): New prototype.
* bfd-in2.h (bfd_mips_elf32_create_embedded_relocs): Likewise.
* elf32-mips.c (bfd_mips_elf32_create_embedded_relocs): New function
to handle 32-bit ELF embedded reloc (ld --embedded-relocs)
generation.
[ ld/ChangeLog ]
2001-10-31 Chris Demetriou <cgd@broadcom.com>
Mitch Lichtenberg <mpl@broadcom.com>
* emulparams/elf32bmip.sh (EXTRA_EM_FILE): Define to be mipself.
* emulparams/elf32bmipn32.sh (EXTRA_EM_FILE): Likewise.
* emulparams/elf32bsmip.sh (EXTRA_EM_FILE): Likewise.
* emulparams/elf32btsmip.sh (EXTRA_EM_FILE): Likewise.
* emulparams/elf32ebmip.sh (EXTRA_EM_FILE): Likewise.
* emulparams/elf32elmip.sh (EXTRA_EM_FILE): Likewise.
* emulparams/elf32lmip.sh (EXTRA_EM_FILE): Likewise.
* emulparams/elf32lsmip.sh (EXTRA_EM_FILE): Likewise.
* emultempl/mipself.sh: New file to handle MIPS ELF embedded
reloc creation (ld --embedded-relocs).
[ ld/testsuite/ChangeLog ]
2001-10-31 Chris Demetriou <cgd@broadcom.com>
* ld-mips-elf/mips-elf.exp: New file to drive MIPS ELF ld tests.
* ld-mips-elf/emrelocs-eb.d: New file to test --embedded-relocs.
* ld-mips-elf/emrelocs-el.d: Likewise.
* ld-mips-elf/emrelocs1.s: Likewise.
* ld-mips-elf/emrelocs2.s: Likewise.
* ld-mips-elf/emrelocs.ld: Likewise.
diff -ru -x CVS -P ../src.CLEAN/bfd/bfd-in.h ./bfd/bfd-in.h
--- ../src.CLEAN/bfd/bfd-in.h Mon Oct 1 22:58:37 2001
+++ ./bfd/bfd-in.h Wed Oct 31 14:12:10 2001
@@ -659,6 +659,9 @@
extern boolean bfd_m68k_elf32_create_embedded_relocs
PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *,
char **));
+extern boolean bfd_mips_elf32_create_embedded_relocs
+ PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *,
+ char **));
/* SunOS shared library support routines for the linker. */
diff -ru -x CVS -P ../src.CLEAN/bfd/bfd-in2.h ./bfd/bfd-in2.h
--- ../src.CLEAN/bfd/bfd-in2.h Tue Oct 30 07:20:02 2001
+++ ./bfd/bfd-in2.h Wed Oct 31 14:12:10 2001
@@ -665,6 +665,9 @@
extern boolean bfd_m68k_elf32_create_embedded_relocs
PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *,
char **));
+extern boolean bfd_mips_elf32_create_embedded_relocs
+ PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *,
+ char **));
/* SunOS shared library support routines for the linker. */
diff -ru -x CVS -P ../src.CLEAN/bfd/elf32-mips.c ./bfd/elf32-mips.c
--- ../src.CLEAN/bfd/elf32-mips.c Tue Oct 23 13:24:23 2001
+++ ./bfd/elf32-mips.c Wed Oct 31 14:12:10 2001
@@ -9221,6 +9221,161 @@
return true;
}
+/* Given a data section and an in-memory embedded reloc section, store
+ relocation information into the embedded reloc section which can be
+ used at runtime to relocate the data section. This is called by the
+ linker when the --embedded-relocs switch is used. This is called
+ after the add_symbols entry point has been called for all the
+ objects, and before the final_link entry point is called. */
+
+boolean
+bfd_mips_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ asection *datasec;
+ asection *relsec;
+ char **errmsg;
+{
+ Elf_Internal_Shdr *symtab_hdr;
+ Elf32_External_Sym *extsyms;
+ Elf32_External_Sym *free_extsyms = NULL;
+ Elf_Internal_Rela *internal_relocs;
+ Elf_Internal_Rela *free_relocs = NULL;
+ Elf_Internal_Rela *irel, *irelend;
+ bfd_byte *p;
+
+ BFD_ASSERT (! info->relocateable);
+
+ *errmsg = NULL;
+
+ if (datasec->reloc_count == 0)
+ return true;
+
+ symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+ /* Read this BFD's symbols if we haven't done so already, or get the cached
+ copy if it exists. */
+ if (symtab_hdr->contents != NULL)
+ extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
+ else
+ {
+ /* Go get them off disk. */
+ if (info->keep_memory)
+ extsyms = ((Elf32_External_Sym *)
+ bfd_alloc (abfd, symtab_hdr->sh_size));
+ else
+ extsyms = ((Elf32_External_Sym *)
+ bfd_malloc (symtab_hdr->sh_size));
+ if (extsyms == NULL)
+ goto error_return;
+ if (! info->keep_memory)
+ free_extsyms = extsyms;
+ if (bfd_seek (abfd, symtab_hdr->sh_offset, SEEK_SET) != 0
+ || (bfd_bread (extsyms, symtab_hdr->sh_size, abfd)
+ != symtab_hdr->sh_size))
+ goto error_return;
+ if (info->keep_memory)
+ symtab_hdr->contents = extsyms;
+ }
+
+ /* Get a copy of the native relocations. */
+ internal_relocs = (_bfd_elf32_link_read_relocs
+ (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
+ info->keep_memory));
+ if (internal_relocs == NULL)
+ goto error_return;
+ if (! info->keep_memory)
+ free_relocs = internal_relocs;
+
+ relsec->contents = (bfd_byte *) bfd_alloc (abfd, datasec->reloc_count * 12);
+ if (relsec->contents == NULL)
+ goto error_return;
+
+ p = relsec->contents;
+
+ irelend = internal_relocs + datasec->reloc_count;
+
+ for (irel = internal_relocs; irel < irelend; irel++, p += 12)
+ {
+ asection *targetsec;
+
+ /* We are going to write a four byte longword into the runtime
+ reloc section. The longword will be the address in the data
+ section which must be relocated. It is followed by the name
+ of the target section NUL-padded or truncated to 8
+ characters. */
+
+ /* We can only relocate absolute longword relocs at run time. */
+ if ((ELF32_R_TYPE (irel->r_info) != (int) R_MIPS_32) &&
+ (ELF32_R_TYPE (irel->r_info) != (int) R_MIPS_64))
+ {
+ *errmsg = _("unsupported reloc type");
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+ /* Get the target section referred to by the reloc. */
+ if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
+ {
+ Elf_Internal_Sym isym;
+
+ /* A local symbol. */
+ bfd_elf32_swap_symbol_in (abfd,
+ extsyms + ELF32_R_SYM (irel->r_info),
+ &isym);
+
+ targetsec = bfd_section_from_elf_index (abfd, isym.st_shndx);
+ }
+ else
+ {
+ unsigned long indx;
+ struct elf_link_hash_entry *h;
+
+ /* An external symbol. */
+ indx = ELF32_R_SYM (irel->r_info);
+ h = elf_sym_hashes (abfd)[indx];
+ targetsec = NULL;
+ /*
+ * For some reason, in certain programs, the symbol will
+ * not be in the hash table. It seems to happen when you
+ * declare a static table of pointers to const external structures.
+ * In this case, the relocs are relative to data, not
+ * text, so just treating it like an undefined link
+ * should be sufficient.
+ */
+ BFD_ASSERT(h != NULL);
+ if (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ targetsec = h->root.u.def.section;
+ }
+
+
+ /*
+ * Set the low bit of the relocation offset if it's a MIPS64 reloc.
+ * Relocations will always be on (at least) 32-bit boundaries.
+ */
+
+ bfd_put_32 (abfd, ((irel->r_offset + datasec->output_offset) +
+ ((ELF32_R_TYPE (irel->r_info) == (int) R_MIPS_64) ? 1 : 0)),
+ p);
+ memset (p + 4, 0, 8);
+ if (targetsec != NULL)
+ strncpy (p + 4, targetsec->output_section->name, 8);
+ }
+
+ if (free_extsyms != NULL)
+ free (free_extsyms);
+ if (free_relocs != NULL)
+ free (free_relocs);
+ return true;
+
+ error_return:
+ if (free_extsyms != NULL)
+ free (free_extsyms);
+ if (free_relocs != NULL)
+ free (free_relocs);
+ return false;
+}
+
+
/* This is almost identical to bfd_generic_get_... except that some
MIPS relocations need to be handled specially. Sigh. */
diff -ru -x CVS -P ../src.CLEAN/ld/emulparams/elf32bmip.sh ./ld/emulparams/elf32bmip.sh
--- ../src.CLEAN/ld/emulparams/elf32bmip.sh Thu Aug 9 07:25:59 2001
+++ ./ld/emulparams/elf32bmip.sh Wed Oct 31 14:12:10 2001
@@ -27,4 +27,5 @@
ARCH=mips
MACHINE=
TEMPLATE_NAME=elf32
+EXTRA_EM_FILE=mipself
GENERATE_SHLIB_SCRIPT=yes
diff -ru -x CVS -P ../src.CLEAN/ld/emulparams/elf32bmipn32.sh ./ld/emulparams/elf32bmipn32.sh
--- ../src.CLEAN/ld/emulparams/elf32bmipn32.sh Thu Aug 9 07:25:59 2001
+++ ./ld/emulparams/elf32bmipn32.sh Wed Oct 31 14:12:10 2001
@@ -8,6 +8,7 @@
LITTLE_OUTPUT_FORMAT="elf32-littlemips"
TEMPLATE_NAME=elf32
+EXTRA_EM_FILE=mipself
TEXT_START_ADDR=0x10000000
MAXPAGESIZE=0x100000
diff -ru -x CVS -P ../src.CLEAN/ld/emulparams/elf32bsmip.sh ./ld/emulparams/elf32bsmip.sh
--- ../src.CLEAN/ld/emulparams/elf32bsmip.sh Thu Aug 9 07:25:59 2001
+++ ./ld/emulparams/elf32bsmip.sh Wed Oct 31 14:12:10 2001
@@ -27,5 +27,6 @@
ARCH=mips
MACHINE=
TEMPLATE_NAME=elf32
+EXTRA_EM_FILE=mipself
GENERATE_SHLIB_SCRIPT=yes
ENTRY=__start
diff -ru -x CVS -P ../src.CLEAN/ld/emulparams/elf32btsmip.sh ./ld/emulparams/elf32btsmip.sh
--- ../src.CLEAN/ld/emulparams/elf32btsmip.sh Thu Aug 9 07:25:59 2001
+++ ./ld/emulparams/elf32btsmip.sh Wed Oct 31 14:12:10 2001
@@ -27,5 +27,6 @@
ARCH=mips
MACHINE=
TEMPLATE_NAME=elf32
+EXTRA_EM_FILE=mipself
GENERATE_SHLIB_SCRIPT=yes
ENTRY=__start
diff -ru -x CVS -P ../src.CLEAN/ld/emulparams/elf32ebmip.sh ./ld/emulparams/elf32ebmip.sh
--- ../src.CLEAN/ld/emulparams/elf32ebmip.sh Thu Aug 9 07:25:59 2001
+++ ./ld/emulparams/elf32ebmip.sh Wed Oct 31 14:12:11 2001
@@ -24,5 +24,6 @@
ARCH=mips
MACHINE=
TEMPLATE_NAME=elf32
+EXTRA_EM_FILE=mipself
GENERATE_SHLIB_SCRIPT=yes
EMBEDDED=yes
diff -ru -x CVS -P ../src.CLEAN/ld/emulparams/elf32elmip.sh ./ld/emulparams/elf32elmip.sh
--- ../src.CLEAN/ld/emulparams/elf32elmip.sh Thu Aug 9 07:25:59 2001
+++ ./ld/emulparams/elf32elmip.sh Wed Oct 31 14:12:11 2001
@@ -24,5 +24,6 @@
ARCH=mips
MACHINE=
TEMPLATE_NAME=elf32
+EXTRA_EM_FILE=mipself
GENERATE_SHLIB_SCRIPT=yes
EMBEDDED=yes
diff -ru -x CVS -P ../src.CLEAN/ld/emulparams/elf32lmip.sh ./ld/emulparams/elf32lmip.sh
--- ../src.CLEAN/ld/emulparams/elf32lmip.sh Thu Aug 9 07:25:59 2001
+++ ./ld/emulparams/elf32lmip.sh Wed Oct 31 14:12:11 2001
@@ -27,4 +27,5 @@
ARCH=mips
MACHINE=
TEMPLATE_NAME=elf32
+EXTRA_EM_FILE=mipself
GENERATE_SHLIB_SCRIPT=yes
diff -ru -x CVS -P ../src.CLEAN/ld/emulparams/elf32lsmip.sh ./ld/emulparams/elf32lsmip.sh
--- ../src.CLEAN/ld/emulparams/elf32lsmip.sh Thu Aug 9 07:25:59 2001
+++ ./ld/emulparams/elf32lsmip.sh Wed Oct 31 14:12:11 2001
@@ -27,5 +27,6 @@
ARCH=mips
MACHINE=
TEMPLATE_NAME=elf32
+EXTRA_EM_FILE=mipself
GENERATE_SHLIB_SCRIPT=yes
ENTRY=__start
diff -ru -x CVS -P ../src.CLEAN/ld/emultempl/mipself.em ./ld/emultempl/mipself.em
--- ../src.CLEAN/ld/emultempl/mipself.em Wed Dec 31 16:00:00 1969
+++ ./ld/emultempl/mipself.em Wed Oct 31 15:32:00 2001
@@ -0,0 +1,183 @@
+# Copyright 2001 Free Software Foundation, Inc.
+# Written by Mitch Lichtenberg <mpl@broadcom.com> and
+# Chris Demetriou <cgd@broadcom.com> based on m68kelf.em and mipsecoff.em.
+#
+# This file is part of GLD, the Gnu Linker.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# This shell script emits a C file. -*- C -*-
+
+
+# This file is sourced from elf32.em, and defines some extra routines for m68k
+# embedded systems using ELF and for some other systems using m68k ELF. While
+# it is sourced from elf32.em for all m68k ELF configurations, here we include
+# only the features we want depending on the configuration.
+
+case ${target} in
+ mips*-*-elf)
+ echo "#define SUPPORT_EMBEDDED_RELOCS" >>e${EMULATION_NAME}.c
+ ;;
+esac
+
+cat >>e${EMULATION_NAME}.c <<EOF
+
+static void mips_elf${ELFSIZE}_after_open PARAMS ((void));
+#ifdef SUPPORT_EMBEDDED_RELOCS
+static void mips_elf${ELFSIZE}_check_sections PARAMS ((bfd *, asection *,
+ PTR));
+#endif
+static void mips_elf${ELFSIZE}_after_allocation PARAMS ((void));
+
+/* This function is run after all the input files have been opened. */
+
+static void
+mips_elf${ELFSIZE}_after_open()
+{
+ /* Call the standard elf routine. */
+ gld${EMULATION_NAME}_after_open ();
+
+#ifdef SUPPORT_EMBEDDED_RELOCS
+ if (command_line.embedded_relocs && (! link_info.relocateable))
+ {
+ bfd *abfd;
+
+ /* In the embedded relocs mode we create a .emreloc section for
+ each input file with a .sdata section which has has
+ relocations. The BFD backend will fill in these sections
+ with magic numbers which can be used to relocate the data
+ section at run time. */
+ for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
+ {
+ asection *datasec;
+
+ /* As first-order business, make sure that each input BFD is
+ ELF. We need to call a special BFD backend function to
+ generate the embedded relocs, and we have that function
+ only for ELF */
+
+ if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+ einfo ("%F%B: all input objects must be ELF for --embedded-relocs\n");
+
+ if (bfd_get_arch_size (abfd) != ${ELFSIZE})
+ einfo ("%F%B: all input objects must be ${ELFSIZE}-bit ELF for --embedded-relocs\n");
+
+ datasec = bfd_get_section_by_name (abfd, ".sdata");
+
+ /* Note that we assume that the reloc_count field has already
+ been set up. We could call bfd_get_reloc_upper_bound, but
+ that returns the size of a memory buffer rather than a reloc
+ count. We do not want to call bfd_canonicalize_reloc,
+ because although it would always work it would force us to
+ read in the relocs into BFD canonical form, which would waste
+ a significant amount of time and memory. */
+
+ if (datasec != NULL && datasec->reloc_count > 0)
+ {
+ asection *relsec;
+
+ relsec = bfd_make_section (abfd, ".emreloc");
+ if (relsec == NULL
+ || ! bfd_set_section_flags (abfd, relsec,
+ (SEC_ALLOC
+ | SEC_LOAD
+ | SEC_HAS_CONTENTS
+ | SEC_IN_MEMORY))
+ || ! bfd_set_section_alignment (abfd, relsec,
+ (${ELFSIZE} == 32) ? 2 : 3)
+ || ! bfd_set_section_size (abfd, relsec,
+ datasec->reloc_count
+ * ((${ELFSIZE} / 8) + 8)))
+ einfo ("%F%B: cannot create .emreloc section: %E\n");
+ }
+
+ /* Double check that all other data sections have no relocs,
+ as is required for embedded PIC code. */
+ bfd_map_over_sections (abfd, mips_elf${ELFSIZE}_check_sections,
+ (PTR) datasec);
+ }
+ }
+#endif /* SUPPORT_EMBEDDED_RELOCS */
+}
+
+#ifdef SUPPORT_EMBEDDED_RELOCS
+/* Check that of the data sections, only the .sdata section has
+ relocs. This is called via bfd_map_over_sections. */
+
+static void
+mips_elf${ELFSIZE}_check_sections (abfd, sec, sdatasec)
+ bfd *abfd;
+ asection *sec;
+ PTR sdatasec;
+{
+ if ((bfd_get_section_flags (abfd, sec) & SEC_CODE) == 0
+ && sec != (asection *) sdatasec
+ && sec->reloc_count != 0)
+ einfo ("%F%X: section %s has relocs; cannot use --embedded-relocs\n",
+ abfd, bfd_get_section_name (abfd, sec));
+}
+#endif /* SUPPORT_EMBEDDED_RELOCS */
+
+/* This function is called after the section sizes and offsets have
+ been set. If we are generating embedded relocs, it calls a special
+ BFD backend routine to do the work. */
+
+static void
+mips_elf${ELFSIZE}_after_allocation ()
+{
+ /* Call the standard elf routine. */
+ after_allocation_default ();
+
+#ifdef SUPPORT_EMBEDDED_RELOCS
+ if (command_line.embedded_relocs && (! link_info.relocateable))
+ {
+ bfd *abfd;
+
+ for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link_next)
+ {
+ asection *datasec, *relsec;
+ char *errmsg;
+
+ datasec = bfd_get_section_by_name (abfd, ".sdata");
+
+ if (datasec == NULL || datasec->reloc_count == 0)
+ continue;
+
+ relsec = bfd_get_section_by_name (abfd, ".emreloc");
+ ASSERT (relsec != NULL);
+
+ if (! bfd_mips_elf${ELFSIZE}_create_embedded_relocs (abfd,
+ &link_info,
+ datasec,
+ relsec,
+ &errmsg))
+ {
+ if (errmsg == NULL)
+ einfo ("%B%X: can not create runtime reloc information: %E\n",
+ abfd);
+ else
+ einfo ("%X%B: can not create runtime reloc information: %s\n",
+ abfd, errmsg);
+ }
+ }
+ }
+#endif /* SUPPORT_EMBEDDED_RELOCS */
+}
+
+EOF
+
+# We have our own after_open and after_allocation functions, but they call
+# the standard routines, so give them a different name.
+LDEMUL_AFTER_OPEN=mips_elf${ELFSIZE}_after_open
+LDEMUL_AFTER_ALLOCATION=mips_elf${ELFSIZE}_after_allocation
diff -ru -x CVS -P ../src.CLEAN/ld/testsuite/ld-mips-elf/emrelocs-eb.d ./ld/testsuite/ld-mips-elf/emrelocs-eb.d
--- ../src.CLEAN/ld/testsuite/ld-mips-elf/emrelocs-eb.d Wed Dec 31 16:00:00 1969
+++ ./ld/testsuite/ld-mips-elf/emrelocs-eb.d Wed Oct 31 14:21:46 2001
@@ -0,0 +1,25 @@
+#name: MIPS 32-bit ELF embedded relocs (big endian)
+#source: emrelocs1.s -EB
+#source: emrelocs2.s -EB
+#ld: -EB --embedded-relocs -T $srcdir/$subdir/emrelocs.ld
+#objdump: -s
+
+.*: file format elf.*mips.*
+
+Contents of section \.text:
+ 100000 00000000 00000001 00000000 00000000 .*
+ 100010 00000000 00000000 00000003 00000000 .*
+Contents of section \.data:
+ 200000 00000000 00000002 00000000 00000000 .*
+ 200010 00000000 00000000 00000004 00000000 .*
+ 200020 00100004 00200004 00100018 00200018 .*
+ 200030 00000000 00100004 00000000 00200004 .*
+ 200040 00000000 00100018 00000000 00200018 .*
+Contents of section \.emreloc:
+ 300000 00000020 2e746578 74000000 00000024 .*
+ 300010 2e646174 61000000 00000028 2e746578 .*
+ 300020 74000000 0000002c 2e646174 61000000 .*
+ 300030 00000031 2e746578 74000000 00000039 .*
+ 300040 2e646174 61000000 00000041 2e746578 .*
+ 300050 74000000 00000049 2e646174 61000000 .*
+#pass
diff -ru -x CVS -P ../src.CLEAN/ld/testsuite/ld-mips-elf/emrelocs-el.d ./ld/testsuite/ld-mips-elf/emrelocs-el.d
--- ../src.CLEAN/ld/testsuite/ld-mips-elf/emrelocs-el.d Wed Dec 31 16:00:00 1969
+++ ./ld/testsuite/ld-mips-elf/emrelocs-el.d Wed Oct 31 14:21:46 2001
@@ -0,0 +1,25 @@
+#name: MIPS 32-bit ELF embedded relocs (little endian)
+#source: emrelocs1.s -EL
+#source: emrelocs2.s -EL
+#ld: -EL --embedded-relocs -T $srcdir/$subdir/emrelocs.ld
+#objdump: -s
+
+.*: file format elf.*mips.*
+
+Contents of section \.text:
+ 100000 00000000 01000000 00000000 00000000 .*
+ 100010 00000000 00000000 03000000 00000000 .*
+Contents of section \.data:
+ 200000 00000000 02000000 00000000 00000000 .*
+ 200010 00000000 00000000 04000000 00000000 .*
+ 200020 04001000 04002000 18001000 18002000 .*
+ 200030 04001000 00000000 04002000 00000000 .*
+ 200040 18001000 00000000 18002000 00000000 .*
+Contents of section \.emreloc:
+ 300000 20000000 2e746578 74000000 24000000 .*
+ 300010 2e646174 61000000 28000000 2e746578 .*
+ 300020 74000000 2c000000 2e646174 61000000 .*
+ 300030 31000000 2e746578 74000000 39000000 .*
+ 300040 2e646174 61000000 41000000 2e746578 .*
+ 300050 74000000 49000000 2e646174 61000000 .*
+#pass
diff -ru -x CVS -P ../src.CLEAN/ld/testsuite/ld-mips-elf/emrelocs.ld ./ld/testsuite/ld-mips-elf/emrelocs.ld
--- ../src.CLEAN/ld/testsuite/ld-mips-elf/emrelocs.ld Wed Dec 31 16:00:00 1969
+++ ./ld/testsuite/ld-mips-elf/emrelocs.ld Wed Oct 31 14:21:46 2001
@@ -0,0 +1,16 @@
+ENTRY(ext_fun)
+SECTIONS
+{
+ .text 0x00100000:
+ {
+ *(.text)
+ }
+ .data 0x00200000:
+ {
+ *(.sdata)
+ }
+ .emreloc 0x00300000:
+ {
+ *(.emreloc)
+ }
+}
diff -ru -x CVS -P ../src.CLEAN/ld/testsuite/ld-mips-elf/emrelocs1.s ./ld/testsuite/ld-mips-elf/emrelocs1.s
--- ../src.CLEAN/ld/testsuite/ld-mips-elf/emrelocs1.s Wed Dec 31 16:00:00 1969
+++ ./ld/testsuite/ld-mips-elf/emrelocs1.s Wed Oct 31 14:21:46 2001
@@ -0,0 +1,23 @@
+# emrelocs1.s: some external symbols to be used in relocations.
+
+ .text
+ .p2align 4
+
+ # Pad things so addresses which are used for relocations
+ # are non-zero. Zero simply isn't as much fun.
+ .word 0
+
+ .globl ext_fun
+ .ent ext_fun
+ext_fun: .word 1
+ .end ext_fun
+
+
+ .sdata
+ .p2align 4
+
+ # Padding here, for same reason.
+ .word 0
+
+ .globl ext_var
+ext_var: .word 2
diff -ru -x CVS -P ../src.CLEAN/ld/testsuite/ld-mips-elf/emrelocs2.s ./ld/testsuite/ld-mips-elf/emrelocs2.s
--- ../src.CLEAN/ld/testsuite/ld-mips-elf/emrelocs2.s Wed Dec 31 16:00:00 1969
+++ ./ld/testsuite/ld-mips-elf/emrelocs2.s Wed Oct 31 14:21:47 2001
@@ -0,0 +1,30 @@
+# emrelocs2.s: local symbols and data which causes relocations.
+
+ .text
+ .p2align 4
+
+ .word 0, 0
+
+ .ent lcl_fun
+lcl_fun: .word 3
+ .end lcl_fun
+
+
+ .sdata
+ .p2align 4
+
+ .word 0, 0
+
+lcl_var: .word 4
+
+ .p2align 4
+
+ .word ext_fun
+ .word ext_var
+ .word lcl_fun
+ .word lcl_var
+
+ .dword ext_fun
+ .dword ext_var
+ .dword lcl_fun
+ .dword lcl_var
diff -ru -x CVS -P ../src.CLEAN/ld/testsuite/ld-mips-elf/mips-elf.exp ./ld/testsuite/ld-mips-elf/mips-elf.exp
--- ../src.CLEAN/ld/testsuite/ld-mips-elf/mips-elf.exp Wed Dec 31 16:00:00 1969
+++ ./ld/testsuite/ld-mips-elf/mips-elf.exp Wed Oct 31 14:21:47 2001
@@ -0,0 +1,26 @@
+# Expect script for MIPS ELF linker tests
+# Copyright 2001 Free Software Foundation, Inc.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+if { [istarget mips*-*-*] } then {
+
+ if { [istarget mips*-*-elf] } {
+ run_dump_test "emrelocs-eb"
+ run_dump_test "emrelocs-el"
+ }
+
+}