This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH to bfd: embedded relocs for m68k COFF as discussed with Ian


This patch and the next one to ld implement --embedded-relocs for m68k COFF
along the lines I discussed earlier today with Ian Lance Taylor. See that
discussion for justification.

This patch is a prerequisite for the next one to ld.

Nick, please comment on this patch. If you approve it, I will make the next one
doing the same for ELF. I will also make my post-linker tools grok the relocs
in the format generated here, and John can easily do the same with his. If you
reject my patch on the basis of accepting John's instead, that's fine with me
too. If you reject it on some other basis, let's work on getting it into
acceptable shape. I want --embedded-relocs.

--
Michael Sokolov		Harhan Engineering Laboratory
Public Service Agent	International Free Computing Task Force
			International Engineering and Science Task Force
			615 N GOOD LATIMER EXPY STE #4
			DALLAS TX 75204-5852 USA

Phone: +1-214-824-7693 (Harhan Eng Lab office)
E-mail: msokolov@ivan.Harhan.ORG (ARPA TCP/SMTP) (UUCP coming soon)

2000-06-08  Michael Sokolov  <msokolov@ivan.Harhan.ORG>

	* coff-m68k.c (bfd_m68k_coff_create_embedded_relocs): New function.
	* bfd-in.h (bfd_m68k_coff_create_embedded_relocs): Add declaration.
	* bfd-in2.h: Regenerate.

Index: bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.11
diff -c -3 -p -r1.11 bfd-in.h
*** bfd-in.h	2000/05/05 18:12:53	1.11
--- bfd-in.h	2000/06/09 01:56:32
*************** extern boolean bfd_coff_get_auxent
*** 721,726 ****
--- 721,730 ----
  extern boolean bfd_coff_set_symbol_class
    PARAMS ((bfd *, struct symbol_cache_entry *, unsigned int));
  
+ extern boolean bfd_m68k_coff_create_embedded_relocs
+   PARAMS ((bfd *, struct bfd_link_info *, struct sec *, struct sec *,
+ 	   char **));
+ 
  /* ARM Interworking support.  Called from linker.  */
  extern boolean bfd_arm_allocate_interworking_sections
    PARAMS ((struct bfd_link_info *));
Index: coff-m68k.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-m68k.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 coff-m68k.c
*** coff-m68k.c	1999/07/19 14:55:15	1.3
--- coff-m68k.c	2000/06/09 01:56:33
***************
*** 1,5 ****
  /* BFD back-end for Motorola 68000 COFF binaries.
!    Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 1999
     Free Software Foundation, Inc.
     Written by Cygnus Support.
  
--- 1,5 ----
  /* BFD back-end for Motorola 68000 COFF binaries.
!    Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 1999, 2000
     Free Software Foundation, Inc.
     Written by Cygnus Support.
  
*************** m68kcoff_common_addend_rtype_to_howto (a
*** 419,424 ****
--- 419,513 ----
  #endif /* ! defined (coff_rtype_to_howto) */
  
  #endif /* COFF_COMMON_ADDEND */
+ 
+ /* Given a .data section and a .emreloc in-memory section, store
+    relocation information into the .emreloc section which can be
+    used at runtime to relocate the 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_m68k_coff_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
+      bfd *abfd;
+      struct bfd_link_info *info;
+      asection *datasec;
+      asection *relsec;
+      char **errmsg;
+ {
+   char *extsyms;
+   bfd_size_type symesz;
+   struct internal_reloc *irel, *irelend;
+   bfd_byte *p;
+ 
+   BFD_ASSERT (! info->relocateable);
+ 
+   *errmsg = NULL;
+ 
+   if (datasec->reloc_count == 0)
+     return true;
+ 
+   extsyms = obj_coff_external_syms (abfd);
+   symesz = bfd_coff_symesz (abfd);
+ 
+   irel = _bfd_coff_read_internal_relocs (abfd, datasec, true, NULL, false,
+ 					 NULL);
+   irelend = irel + datasec->reloc_count;
+ 
+   relsec->contents = (bfd_byte *) bfd_alloc (abfd, datasec->reloc_count * 12);
+   if (relsec->contents == NULL)
+     return false;
+ 
+   p = relsec->contents;
+ 
+   for (; 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 (irel->r_type != R_RELLONG)
+ 	{
+ 	  *errmsg = _("unsupported reloc type");
+ 	  bfd_set_error (bfd_error_bad_value);
+ 	  return false;
+ 	}
+ 
+       if (irel->r_symndx == -1)
+ 	targetsec = bfd_abs_section_ptr;
+       else
+ 	{
+ 	  struct coff_link_hash_entry *h;
+ 
+ 	  h = obj_coff_sym_hashes (abfd)[irel->r_symndx];
+ 	  if (h == NULL)
+ 	    {
+ 	      struct internal_syment isym;
+ 
+ 	      bfd_coff_swap_sym_in (abfd, extsyms + symesz * irel->r_symndx,
+ 				    &isym);
+ 	      targetsec = coff_section_from_bfd_index (abfd, isym.n_scnum);
+ 	    }
+ 	  else if (h->root.type == bfd_link_hash_defined
+ 		   || h->root.type == bfd_link_hash_defweak)
+ 	    targetsec = h->root.u.def.section;
+ 	  else
+ 	    targetsec = NULL;
+ 	}
+ 
+       bfd_put_32 (abfd,
+ 		  (irel->r_vaddr - datasec->vma + datasec->output_offset), p);
+       memset (p + 4, 0, 8);
+       strncpy (p + 4, targetsec->output_section->name, 8);
+     }
+ 
+   return true;
+ }
  
  #define coff_bfd_is_local_label_name m68k_coff_is_local_label_name
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]