public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* combreloc patches for s390, s390x, ppc
@ 2001-08-24 11:53 Andreas Jaeger
  2001-08-24 12:15 ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Jaeger @ 2001-08-24 11:53 UTC (permalink / raw)
  To: binutils; +Cc: Martin Schwidefsky, Geoff Keating

Here's a patch to change the textrel sections and add reloc_type_class
for three more architectures.

Note I'm not convinced that my patches for reloc_type_class are
correct.  Jakub, can you document a bit for which relocations
reloc_class_relative has to be returned?  I think it would be helpfull
if you could document the enum elf_reloc_type_class.

I currently test the s390 and ppc changes but won't see the results
before tomorrow and therefore decided to mail this already.

Ok to commit if make check passes with combreloc set to true?

Thanks,
Andreas

2001-08-24  Andreas Jaeger  <aj@suse.de>

	* elf64-s390.c (elf_s390_check_relocs): Set DF_TEXTREL if the
	reloc is against read-only section.
	(elf_s390_size_dynamic_sections): Use DF_TEXTREL flag instead of
	looking up section names for DT_TEXTREL.
	(elf_s390_reloc_type_class): New.
	(elf_backend_reloc_type_class): Define.

	* elf32-s390.c (elf_s390_check_relocs): Set DF_TEXTREL if the
	reloc is against read-only section.
	(elf_s390_size_dynamic_sections): Use DF_TEXTREL flag instead of
	looking up section names for DT_TEXTREL.
	(elf_s390_reloc_type_class): New.
	(elf_backend_reloc_type_class): Define.

	* elf32-ppc.c (ppc_elf_check_relocs): Set DF_TEXTREL if the reloc
	is against read-only section.
	(ppc_elf_size_dynamic_sections): Use DF_TEXTREL flag instead of
	looking up section names for DT_TEXTREL.
	(ppc_elf_reloc_type_class): New.
	(elf_backend_reloc_type_class): Define.


============================================================
Index: bfd/elf32-ppc.c
--- bfd/elf32-ppc.c	2001/08/17 15:56:58	1.24
+++ bfd/elf32-ppc.c	2001/08/24 18:07:36
@@ -108,6 +108,7 @@
 						      Elf_Internal_Sym *));
 
 static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
+static enum elf_reloc_type_class ppc_elf_reloc_type_class PARAMS ((int));
 
 #define BRANCH_PREDICT_BIT 0x200000		/* branch prediction bit for branch taken relocs */
 #define RA_REGISTER_MASK 0x001f0000		/* mask to set RA in memory instructions */
@@ -1885,7 +1886,6 @@
   asection *s;
   boolean plt;
   boolean relocs;
-  boolean reltext;
 
 #ifdef DEBUG
   fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
@@ -1930,7 +1930,6 @@
      memory for them.  */
   plt = false;
   relocs = false;
-  reltext = false;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char *name;
@@ -1976,22 +1975,9 @@
 	    }
 	  else
 	    {
-	      asection *target;
-	      const char *outname;
-
 	      /* Remember whether there are any relocation sections.  */
 	      relocs = true;
 
-	      /* If this relocation section applies to a read only
-		 section, then we probably need a DT_TEXTREL entry.  */
-	      outname = bfd_get_section_name (output_bfd,
-					      s->output_section);
-	      target = bfd_get_section_by_name (output_bfd, outname + 5);
-	      if (target != NULL
-		  && (target->flags & SEC_READONLY) != 0
-		  && (target->flags & SEC_ALLOC) != 0)
-		reltext = true;
-
 	      /* We use the reloc_count field as a counter if we need
 		 to copy relocs into the output file.  */
 	      s->reloc_count = 0;
@@ -2048,7 +2034,7 @@
 	    return false;
 	}
 
-      if (reltext)
+      if ((info->flags & DF_TEXTREL) != 0)
 	{
 	  if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
 	    return false;
@@ -2433,6 +2419,8 @@
 			  || ! bfd_set_section_alignment (dynobj, sreloc, 2))
 			return false;
 		    }
+		  if (sec->flags & SEC_READONLY)
+		    info->flags |= DF_TEXTREL;
 		}
 
 	      sreloc->_raw_size += sizeof (Elf32_External_Rela);
@@ -3712,6 +3700,28 @@
 
   return ret;
 }
+
+static enum elf_reloc_type_class
+ppc_elf_reloc_type_class (type)
+     int type;
+{
+  switch (type)
+    {
+    case R_PPC_REL24:
+    case R_PPC_REL14:
+    case R_PPC_REL14_BRTAKEN:
+    case R_PPC_REL14_BRNTAKEN:
+    case R_PPC_REL32:
+    case R_PPC_RELATIVE:
+      return reloc_class_relative;
+    case R_PPC_JMP_SLOT:
+      return reloc_class_plt;
+    case R_PPC_COPY:
+      return reloc_class_copy;
+    default:
+      return reloc_class_normal;
+    }
+}
 \f
 #define TARGET_LITTLE_SYM	bfd_elf32_powerpcle_vec
 #define TARGET_LITTLE_NAME	"elf32-powerpcle"
@@ -3757,5 +3767,6 @@
 #define elf_backend_fake_sections		ppc_elf_fake_sections
 #define elf_backend_additional_program_headers	ppc_elf_additional_program_headers
 #define elf_backend_modify_segment_map		ppc_elf_modify_segment_map
+#define elf_backend_reloc_type_class		ppc_elf_reloc_type_class
 
 #include "elf32-target.h"
============================================================
Index: bfd/elf32-s390.c
--- bfd/elf32-s390.c	2001/08/21 08:40:23	1.3
+++ bfd/elf32-s390.c	2001/08/24 18:07:38
@@ -56,6 +56,7 @@
 static boolean elf_s390_finish_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 static boolean elf_s390_object_p PARAMS ((bfd *));
+static enum elf_reloc_type_class elf_s390_reloc_type_class PARAMS ((int));
 
 #define USE_RELA 1		/* We want RELA relocations, not REL.  */
 
@@ -712,6 +713,8 @@
 			  || ! bfd_set_section_alignment (dynobj, sreloc, 2))
 			return false;
 		    }
+		  if (sec->flags & SEC_READONLY)
+		    info->flags |= DF_TEXTREL;
 		}
 
 	      sreloc->_raw_size += sizeof (Elf32_External_Rela);
@@ -1094,7 +1097,6 @@
 {
   bfd *dynobj;
   asection *s;
-  boolean reltext;
   boolean relocs;
   boolean plt;
 
@@ -1137,7 +1139,6 @@
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
   plt = false;
-  reltext = false;
   relocs = false;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
@@ -1184,30 +1185,11 @@
 	    }
 	  else
 	    {
-	      asection *target;
-
 	      /* Remember whether there are any reloc sections other
                  than .rela.plt.  */
 	      if (strcmp (name, ".rela.plt") != 0)
-		{
-		  const char *outname;
-
-		  relocs = true;
+		relocs = true;
 
-		  /* If this relocation section applies to a read only
-		     section, then we probably need a DT_TEXTREL
-		     entry.  The entries in the .rela.plt section
-		     really apply to the .got section, which we
-		     created ourselves and so know is not readonly.  */
-		  outname = bfd_get_section_name (output_bfd,
-						  s->output_section);
-		  target = bfd_get_section_by_name (output_bfd, outname + 5);
-		  if (target != NULL
-		      && (target->flags & SEC_READONLY) != 0
-		      && (target->flags & SEC_ALLOC) != 0)
-		    reltext = true;
-		}
-
 	      /* We use the reloc_count field as a counter if we need
 		 to copy relocs into the output file.  */
 	      s->reloc_count = 0;
@@ -1262,7 +1244,7 @@
 	    return false;
          }
 
-      if (reltext)
+      if ((info->flags & DF_TEXTREL) != 0)
 	{
 	  if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
 	    return false;
@@ -2150,6 +2132,26 @@
   return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_esa);
 }
 
+static enum elf_reloc_type_class
+elf_s390_reloc_type_class (type)
+     int type;
+{
+  switch (type)
+    {
+    case R_390_PC16:
+    case R_390_PC16DBL:
+    case R_390_PC32:
+    case R_390_RELATIVE:
+      return reloc_class_relative;
+    case R_390_JMP_SLOT:
+      return reloc_class_plt;
+    case R_390_COPY:
+      return reloc_class_copy;
+    default:
+      return reloc_class_normal;
+    }
+}
+
 #define TARGET_BIG_SYM	bfd_elf32_s390_vec
 #define TARGET_BIG_NAME	"elf32-s390"
 #define ELF_ARCH	bfd_arch_s390
@@ -2180,6 +2182,7 @@
 #define elf_backend_gc_sweep_hook             elf_s390_gc_sweep_hook
 #define elf_backend_relocate_section          elf_s390_relocate_section
 #define elf_backend_size_dynamic_sections     elf_s390_size_dynamic_sections
+#define elf_backend_reloc_type_class	      elf_s390_reloc_type_class
 
 #define elf_backend_object_p            elf_s390_object_p
 
============================================================
Index: bfd/elf64-s390.c
--- bfd/elf64-s390.c	2001/08/11 07:59:54	1.3
+++ bfd/elf64-s390.c	2001/08/24 18:07:40
@@ -684,6 +684,8 @@
 			  || ! bfd_set_section_alignment (dynobj, sreloc, 2))
 			return false;
 		    }
+		  if (sec->flags & SEC_READONLY)
+		    info->flags |= DF_TEXTREL;
 		}
 
 	      sreloc->_raw_size += sizeof (Elf64_External_Rela);
@@ -1074,7 +1076,6 @@
 {
   bfd *dynobj;
   asection *s;
-  boolean reltext;
   boolean relocs;
   boolean plt;
 
@@ -1117,7 +1118,6 @@
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
   plt = false;
-  reltext = false;
   relocs = false;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
@@ -1164,30 +1164,11 @@
 	    }
 	  else
 	    {
-	      asection *target;
-
 	      /* Remember whether there are any reloc sections other
                  than .rela.plt.  */
 	      if (strcmp (name, ".rela.plt") != 0)
-		{
-		  const char *outname;
-
-		  relocs = true;
+		relocs = true;
 
-		  /* If this relocation section applies to a read only
-		     section, then we probably need a DT_TEXTREL
-		     entry.  The entries in the .rela.plt section
-		     really apply to the .got section, which we
-		     created ourselves and so know is not readonly.  */
-		  outname = bfd_get_section_name (output_bfd,
-						  s->output_section);
-		  target = bfd_get_section_by_name (output_bfd, outname + 5);
-		  if (target != NULL
-		      && (target->flags & SEC_READONLY) != 0
-		      && (target->flags & SEC_ALLOC) != 0)
-		    reltext = true;
-		}
-
 	      /* We use the reloc_count field as a counter if we need
 		 to copy relocs into the output file.  */
 	      s->reloc_count = 0;
@@ -1242,7 +1223,7 @@
 	    return false;
          }
 
-      if (reltext)
+      if ((info->flags & DF_TEXTREL) != 0)
 	{
 	  if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
 	    return false;
@@ -2112,6 +2093,29 @@
   return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_esame);
 }
 
+
+static enum elf_reloc_type_class
+elf_s390_reloc_type_class (type)
+     int type;
+{
+  switch (type)
+    {
+    case R_390_PC16:
+    case R_390_PC16DBL:
+    case R_390_PC32:
+    case R_390_PC32DBL:
+    case R_390_PC64:
+    case R_390_RELATIVE:
+      return reloc_class_relative;
+    case R_390_JMP_SLOT:
+      return reloc_class_plt;
+    case R_390_COPY:
+      return reloc_class_copy;
+    default:
+      return reloc_class_normal;
+    }
+}
+
 /*
  * Why was the hash table entry size definition changed from
  * ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and
@@ -2179,6 +2183,7 @@
 #define elf_backend_gc_sweep_hook	      elf_s390_gc_sweep_hook
 #define elf_backend_relocate_section	      elf_s390_relocate_section
 #define elf_backend_size_dynamic_sections     elf_s390_size_dynamic_sections
+#define elf_backend_reloc_type_class	      elf_s390_reloc_type_class
 
 #define elf_backend_object_p                  elf_s390_object_p
 

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: combreloc patches for s390, s390x, ppc
  2001-08-24 11:53 combreloc patches for s390, s390x, ppc Andreas Jaeger
@ 2001-08-24 12:15 ` Jakub Jelinek
  2001-08-24 13:58   ` Andreas Jaeger
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2001-08-24 12:15 UTC (permalink / raw)
  To: Andreas Jaeger; +Cc: binutils, Martin Schwidefsky, Geoff Keating

On Fri, Aug 24, 2001 at 08:19:29PM +0200, Andreas Jaeger wrote:
> +    case R_PPC_REL24:
> +    case R_PPC_REL14:
> +    case R_PPC_REL14_BRTAKEN:
> +    case R_PPC_REL14_BRNTAKEN:
> +    case R_PPC_REL32:

I think these are wrong.
reloc_class_relative are the ones that count into DT_REL*COUNT.
Looking at powerpc/dl-machine.h:
  if (rinfo == R_PPC_RELATIVE
      || (sym->st_shndx != SHN_UNDEF
          && ELF32_ST_BIND (sym->st_info) == STB_LOCAL))
    {
      /* Has already been relocated.  */
      loadbase = map->l_addr;
      finaladdr = loadbase + reloc->r_addend;
    }
  else
    {
      loadbase = (Elf32_Word) (char *) (RESOLVE (&sym, version,
which shows that IMHO only R_PPC_RELATIVE should be here.

reloc_class_plt are those for which glibc elf_machine_lookup_noplt_p
returns 1, ie. I think R_PPC_REL24 and R_PPC_ADDR24 too.
The thing is that PLT relocs have different lookup rules, likewise with
copy relocs, and thus mixing them together with other relocs means lookup
cache will be less effective.
reloc_class_copy should be obvious (R_*_COPY only, in other words
elf_machine_lookup_noexec_p in glibc).

> +    case R_PPC_RELATIVE:
> +      return reloc_class_relative;
> +    case R_PPC_JMP_SLOT:
> +      return reloc_class_plt;
> +    case R_PPC_COPY:
> +      return reloc_class_copy;
> +    default:
> +      return reloc_class_normal;
...
> +    case R_390_PC16:
> +    case R_390_PC16DBL:
> +    case R_390_PC32:

Again, only R_390_RELATIVE.

> +    case R_390_RELATIVE:
> +      return reloc_class_relative;
> +    case R_390_JMP_SLOT:
> +      return reloc_class_plt;
> +    case R_390_COPY:
> +      return reloc_class_copy;
> +    default:
> +      return reloc_class_normal;
...
> +    case R_390_PC16:
> +    case R_390_PC16DBL:
> +    case R_390_PC32:
> +    case R_390_PC32DBL:
> +    case R_390_PC64:

Likewise.

> +    case R_390_RELATIVE:
> +      return reloc_class_relative;
> +    case R_390_JMP_SLOT:
> +      return reloc_class_plt;
> +    case R_390_COPY:
> +      return reloc_class_copy;
> +    default:
> +      return reloc_class_normal;

	Jakub

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: combreloc patches for s390, s390x, ppc
  2001-08-24 12:15 ` Jakub Jelinek
@ 2001-08-24 13:58   ` Andreas Jaeger
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Jaeger @ 2001-08-24 13:58 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: binutils, Martin Schwidefsky, Geoff Keating

Jakub Jelinek <jakub@redhat.com> writes:

> On Fri, Aug 24, 2001 at 08:19:29PM +0200, Andreas Jaeger wrote:
> > +    case R_PPC_REL24:
>> +    case R_PPC_REL14:
>> +    case R_PPC_REL14_BRTAKEN:
>> +    case R_PPC_REL14_BRNTAKEN:
>> +    case R_PPC_REL32:
>
> I think these are wrong.

That's what I feared - but wasn't sure what really needs to be done.
Can you document this please in the bintuils sources (I guess in
bfd.h)?

> reloc_class_relative are the ones that count into DT_REL*COUNT.
> Looking at powerpc/dl-machine.h:
>   if (rinfo == R_PPC_RELATIVE
>       || (sym->st_shndx != SHN_UNDEF
>           && ELF32_ST_BIND (sym->st_info) == STB_LOCAL))
>     {
>       /* Has already been relocated.  */
>       loadbase = map->l_addr;
>       finaladdr = loadbase + reloc->r_addend;
>     }
>   else
>     {
>       loadbase = (Elf32_Word) (char *) (RESOLVE (&sym, version,
> which shows that IMHO only R_PPC_RELATIVE should be here.
> reloc_class_plt are those for which glibc elf_machine_lookup_noplt_p
> returns 1, ie. I think R_PPC_REL24 and R_PPC_ADDR24 too.

Thanks Jakub, I've incorporated all your changes and also fixed some
warning I noted.

Here's a new patch.  Ok to commit?

Andreas

2001-08-24  Andreas Jaeger  <aj@suse.de>

	* elf64-s390.c (elf_s390_check_relocs): Set DF_TEXTREL if the
	reloc is against read-only section.
	(elf_s390_size_dynamic_sections): Use DF_TEXTREL flag instead of
	looking up section names for DT_TEXTREL.
	(elf_s390_reloc_type_class): New.
	(elf_backend_reloc_type_class): Define.

	* elf32-s390.c (elf_s390_check_relocs): Set DF_TEXTREL if the
	reloc is against read-only section.
	(elf_s390_size_dynamic_sections): Use DF_TEXTREL flag instead of
	looking up section names for DT_TEXTREL.
	(elf_s390_reloc_type_class): New.
	(elf_backend_reloc_type_class): Define.

	* elf32-ppc.c (ppc_elf_check_relocs): Set DF_TEXTREL if the reloc
	is against read-only section.
	(ppc_elf_size_dynamic_sections): Use DF_TEXTREL flag instead of
	looking up section names for DT_TEXTREL.
	(ppc_elf_reloc_type_class): New.
	(elf_backend_reloc_type_class): Define.

============================================================
Index: bfd/elf32-ppc.c
--- bfd/elf32-ppc.c	2001/08/17 15:56:58	1.24
+++ bfd/elf32-ppc.c	2001/08/24 19:28:07
@@ -108,6 +108,7 @@
 						      Elf_Internal_Sym *));
 
 static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
+static enum elf_reloc_type_class ppc_elf_reloc_type_class PARAMS ((int));
 
 #define BRANCH_PREDICT_BIT 0x200000		/* branch prediction bit for branch taken relocs */
 #define RA_REGISTER_MASK 0x001f0000		/* mask to set RA in memory instructions */
@@ -1878,14 +1879,13 @@
 
 static boolean
 ppc_elf_size_dynamic_sections (output_bfd, info)
-     bfd *output_bfd;
+     bfd *output_bfd ATTRIBUTE_UNUSED;
      struct bfd_link_info *info;
 {
   bfd *dynobj;
   asection *s;
   boolean plt;
   boolean relocs;
-  boolean reltext;
 
 #ifdef DEBUG
   fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
@@ -1930,7 +1930,6 @@
      memory for them.  */
   plt = false;
   relocs = false;
-  reltext = false;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char *name;
@@ -1976,22 +1975,9 @@
 	    }
 	  else
 	    {
-	      asection *target;
-	      const char *outname;
-
 	      /* Remember whether there are any relocation sections.  */
 	      relocs = true;
 
-	      /* If this relocation section applies to a read only
-		 section, then we probably need a DT_TEXTREL entry.  */
-	      outname = bfd_get_section_name (output_bfd,
-					      s->output_section);
-	      target = bfd_get_section_by_name (output_bfd, outname + 5);
-	      if (target != NULL
-		  && (target->flags & SEC_READONLY) != 0
-		  && (target->flags & SEC_ALLOC) != 0)
-		reltext = true;
-
 	      /* We use the reloc_count field as a counter if we need
 		 to copy relocs into the output file.  */
 	      s->reloc_count = 0;
@@ -2048,7 +2034,7 @@
 	    return false;
 	}
 
-      if (reltext)
+      if ((info->flags & DF_TEXTREL) != 0)
 	{
 	  if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
 	    return false;
@@ -2433,6 +2419,8 @@
 			  || ! bfd_set_section_alignment (dynobj, sreloc, 2))
 			return false;
 		    }
+		  if (sec->flags & SEC_READONLY)
+		    info->flags |= DF_TEXTREL;
 		}
 
 	      sreloc->_raw_size += sizeof (Elf32_External_Rela);
@@ -3712,6 +3700,25 @@
 
   return ret;
 }
+
+static enum elf_reloc_type_class
+ppc_elf_reloc_type_class (type)
+     int type;
+{
+  switch (type)
+    {
+    case R_PPC_RELATIVE:
+      return reloc_class_relative;
+    case R_PPC_REL24:
+    case R_PPC_ADDR24:
+    case R_PPC_JMP_SLOT:
+      return reloc_class_plt;
+    case R_PPC_COPY:
+      return reloc_class_copy;
+    default:
+      return reloc_class_normal;
+    }
+}
 \f
 #define TARGET_LITTLE_SYM	bfd_elf32_powerpcle_vec
 #define TARGET_LITTLE_NAME	"elf32-powerpcle"
@@ -3757,5 +3764,6 @@
 #define elf_backend_fake_sections		ppc_elf_fake_sections
 #define elf_backend_additional_program_headers	ppc_elf_additional_program_headers
 #define elf_backend_modify_segment_map		ppc_elf_modify_segment_map
+#define elf_backend_reloc_type_class		ppc_elf_reloc_type_class
 
 #include "elf32-target.h"
============================================================
Index: bfd/elf32-s390.c
--- bfd/elf32-s390.c	2001/08/21 08:40:23	1.3
+++ bfd/elf32-s390.c	2001/08/24 19:28:09
@@ -56,6 +56,7 @@
 static boolean elf_s390_finish_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 static boolean elf_s390_object_p PARAMS ((bfd *));
+static enum elf_reloc_type_class elf_s390_reloc_type_class PARAMS ((int));
 
 #define USE_RELA 1		/* We want RELA relocations, not REL.  */
 
@@ -712,6 +713,8 @@
 			  || ! bfd_set_section_alignment (dynobj, sreloc, 2))
 			return false;
 		    }
+		  if (sec->flags & SEC_READONLY)
+		    info->flags |= DF_TEXTREL;
 		}
 
 	      sreloc->_raw_size += sizeof (Elf32_External_Rela);
@@ -1089,12 +1092,11 @@
 
 static boolean
 elf_s390_size_dynamic_sections (output_bfd, info)
-     bfd *output_bfd;
+     bfd *output_bfd ATTRIBUTE_UNUSED;
      struct bfd_link_info *info;
 {
   bfd *dynobj;
   asection *s;
-  boolean reltext;
   boolean relocs;
   boolean plt;
 
@@ -1137,7 +1139,6 @@
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
   plt = false;
-  reltext = false;
   relocs = false;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
@@ -1184,29 +1185,10 @@
 	    }
 	  else
 	    {
-	      asection *target;
-
 	      /* Remember whether there are any reloc sections other
                  than .rela.plt.  */
 	      if (strcmp (name, ".rela.plt") != 0)
-		{
-		  const char *outname;
-
-		  relocs = true;
-
-		  /* If this relocation section applies to a read only
-		     section, then we probably need a DT_TEXTREL
-		     entry.  The entries in the .rela.plt section
-		     really apply to the .got section, which we
-		     created ourselves and so know is not readonly.  */
-		  outname = bfd_get_section_name (output_bfd,
-						  s->output_section);
-		  target = bfd_get_section_by_name (output_bfd, outname + 5);
-		  if (target != NULL
-		      && (target->flags & SEC_READONLY) != 0
-		      && (target->flags & SEC_ALLOC) != 0)
-		    reltext = true;
-		}
+		relocs = true;
 
 	      /* We use the reloc_count field as a counter if we need
 		 to copy relocs into the output file.  */
@@ -1262,7 +1244,7 @@
 	    return false;
          }
 
-      if (reltext)
+      if ((info->flags & DF_TEXTREL) != 0)
 	{
 	  if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
 	    return false;
@@ -2150,6 +2132,23 @@
   return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_esa);
 }
 
+static enum elf_reloc_type_class
+elf_s390_reloc_type_class (type)
+     int type;
+{
+  switch (type)
+    {
+    case R_390_RELATIVE:
+      return reloc_class_relative;
+    case R_390_JMP_SLOT:
+      return reloc_class_plt;
+    case R_390_COPY:
+      return reloc_class_copy;
+    default:
+      return reloc_class_normal;
+    }
+}
+
 #define TARGET_BIG_SYM	bfd_elf32_s390_vec
 #define TARGET_BIG_NAME	"elf32-s390"
 #define ELF_ARCH	bfd_arch_s390
@@ -2180,6 +2179,7 @@
 #define elf_backend_gc_sweep_hook             elf_s390_gc_sweep_hook
 #define elf_backend_relocate_section          elf_s390_relocate_section
 #define elf_backend_size_dynamic_sections     elf_s390_size_dynamic_sections
+#define elf_backend_reloc_type_class	      elf_s390_reloc_type_class
 
 #define elf_backend_object_p            elf_s390_object_p
 
============================================================
Index: bfd/elf64-s390.c
--- bfd/elf64-s390.c	2001/08/11 07:59:54	1.3
+++ bfd/elf64-s390.c	2001/08/24 19:28:11
@@ -56,6 +56,7 @@
 static boolean elf_s390_finish_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 static boolean elf_s390_object_p PARAMS ((bfd *));
+static enum elf_reloc_type_class elf_s390_reloc_type_class PARAMS ((int));
 
 #define USE_RELA 1		/* We want RELA relocations, not REL.  */
 
@@ -684,6 +685,8 @@
 			  || ! bfd_set_section_alignment (dynobj, sreloc, 2))
 			return false;
 		    }
+		  if (sec->flags & SEC_READONLY)
+		    info->flags |= DF_TEXTREL;
 		}
 
 	      sreloc->_raw_size += sizeof (Elf64_External_Rela);
@@ -1069,12 +1072,11 @@
 
 static boolean
 elf_s390_size_dynamic_sections (output_bfd, info)
-     bfd *output_bfd;
+     bfd *output_bfd ATTRIBUTE_UNUSED;
      struct bfd_link_info *info;
 {
   bfd *dynobj;
   asection *s;
-  boolean reltext;
   boolean relocs;
   boolean plt;
 
@@ -1117,7 +1119,6 @@
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
   plt = false;
-  reltext = false;
   relocs = false;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
@@ -1164,30 +1165,11 @@
 	    }
 	  else
 	    {
-	      asection *target;
-
 	      /* Remember whether there are any reloc sections other
                  than .rela.plt.  */
 	      if (strcmp (name, ".rela.plt") != 0)
-		{
-		  const char *outname;
-
-		  relocs = true;
+		relocs = true;
 
-		  /* If this relocation section applies to a read only
-		     section, then we probably need a DT_TEXTREL
-		     entry.  The entries in the .rela.plt section
-		     really apply to the .got section, which we
-		     created ourselves and so know is not readonly.  */
-		  outname = bfd_get_section_name (output_bfd,
-						  s->output_section);
-		  target = bfd_get_section_by_name (output_bfd, outname + 5);
-		  if (target != NULL
-		      && (target->flags & SEC_READONLY) != 0
-		      && (target->flags & SEC_ALLOC) != 0)
-		    reltext = true;
-		}
-
 	      /* We use the reloc_count field as a counter if we need
 		 to copy relocs into the output file.  */
 	      s->reloc_count = 0;
@@ -1242,7 +1224,7 @@
 	    return false;
          }
 
-      if (reltext)
+      if ((info->flags & DF_TEXTREL) != 0)
 	{
 	  if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
 	    return false;
@@ -2112,6 +2094,24 @@
   return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_esame);
 }
 
+
+static enum elf_reloc_type_class
+elf_s390_reloc_type_class (type)
+     int type;
+{
+  switch (type)
+    {
+    case R_390_RELATIVE:
+      return reloc_class_relative;
+    case R_390_JMP_SLOT:
+      return reloc_class_plt;
+    case R_390_COPY:
+      return reloc_class_copy;
+    default:
+      return reloc_class_normal;
+    }
+}
+
 /*
  * Why was the hash table entry size definition changed from
  * ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and
@@ -2179,6 +2179,7 @@
 #define elf_backend_gc_sweep_hook	      elf_s390_gc_sweep_hook
 #define elf_backend_relocate_section	      elf_s390_relocate_section
 #define elf_backend_size_dynamic_sections     elf_s390_size_dynamic_sections
+#define elf_backend_reloc_type_class	      elf_s390_reloc_type_class
 
 #define elf_backend_object_p                  elf_s390_object_p
 

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: combreloc patches for s390, s390x, ppc
@ 2001-08-27  1:34 Nick Clifton
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Clifton @ 2001-08-27  1:34 UTC (permalink / raw)
  To: aj; +Cc: binutils

Hi Andreas,

> 2001-08-24  Andreas Jaeger  <aj@suse.de>
> 
> * elf64-s390.c (elf_s390_check_relocs): Set DF_TEXTREL if the
> 	reloc is against read-only section.
> 	(elf_s390_size_dynamic_sections): Use DF_TEXTREL flag instead of
> 	looking up section names for DT_TEXTREL.
> 	(elf_s390_reloc_type_class): New.
> 	(elf_backend_reloc_type_class): Define.
> 
> 	* elf32-s390.c (elf_s390_check_relocs): Set DF_TEXTREL if the
> 	reloc is against read-only section.
> 	(elf_s390_size_dynamic_sections): Use DF_TEXTREL flag instead of
> 	looking up section names for DT_TEXTREL.
> 	(elf_s390_reloc_type_class): New.
> 	(elf_backend_reloc_type_class): Define.
> 
> 	* elf32-ppc.c (ppc_elf_check_relocs): Set DF_TEXTREL if the reloc
> 	is against read-only section.
> 	(ppc_elf_size_dynamic_sections): Use DF_TEXTREL flag instead of
> 	looking up section names for DT_TEXTREL.
> 	(ppc_elf_reloc_type_class): New.
> 	(elf_backend_reloc_type_class): Define.

Approved.

Cheers
        Nick

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-08-27  1:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-24 11:53 combreloc patches for s390, s390x, ppc Andreas Jaeger
2001-08-24 12:15 ` Jakub Jelinek
2001-08-24 13:58   ` Andreas Jaeger
2001-08-27  1:34 Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).