This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

ppc64 exec stack


PowerPC64 does not require an executable stack for many of the usual
reasons other common targets need one, eg. nested function call
trampolines just put a function descriptor on the stack rather than
a small code sequence.  Also, shortly after the linux kernel
implemented non-exec stacks for ppc64, the default was changed to
non-exec unless a PT_GNU_STACK header with PF_X was present.  See
http://ozlabs.org/pipermail/linuxppc64-dev/2005-April/003891.html.
So there is really no need for .note.GNU-stack or PT_GNU_STACK on
ppc64 unless you want to mark an object file or executable as needing
exec stack.  For that reason, I changed gcc-4.x to omit
.note.GNU-stack on ppc64.  See
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21098.  However, for some
reason Redhat changed their version of gcc to mark all ppc64 object
files with .note.GNU-stack.  This presents a problem when mixing
objects created by different compilers, because the linker requires
that if some object file has .note.GNU-stack, then they all must, and
if one file is missing .note.GNU-stack it is assumed to be exec stack.

I think that for ppc64 it would make more sense to assume that a file
without the .note.GNU-stack marker is non-exec stack.  This will allow
mixing of Redhat object files with mainline gcc, and is in fact the
correct default for ppc64.

	* elf-bfd.h (struct elf_backend_data): Add default_execstack.
	* elflink.c (bfd_elf_size_dynamic_sections): Heed default_execstack.
	* elfxx-target.h (elf_backend_default_execstack): Define to 1.
	(elfNN_bed): Init new field.
	* elf64-ppc.c (elf_backend_default_execstack): Define to 0.

Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.226
diff -u -p -r1.226 elf-bfd.h
--- bfd/elf-bfd.h	5 Feb 2007 19:50:12 -0000	1.226
+++ bfd/elf-bfd.h	19 Feb 2007 00:17:23 -0000
@@ -1106,10 +1106,17 @@ struct elf_backend_data
   unsigned can_refcount : 1;
   unsigned want_got_sym : 1;
   unsigned want_dynbss : 1;
-    /* Targets which do not support physical addressing often require
-       that the p_paddr field in the section header to be set to zero.
-       This field indicates whether this behavior is required.  */
+
+  /* Targets which do not support physical addressing often require
+     that the p_paddr field in the section header to be set to zero.
+     This field indicates whether this behavior is required.  */
   unsigned want_p_paddr_set_to_zero : 1;
+
+  /* True if an object file lacking a .note.GNU-stack section
+     should be assumed to be requesting exec stack.  At least one
+     other file in the link needs to have a .note.GNU-stack section
+     for a PT_GNU_STACK segment to be created.  */
+  unsigned default_execstack : 1;
 };
 
 /* Information stored for each BFD section in an ELF file.  This
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.250
diff -u -p -r1.250 elflink.c
--- bfd/elflink.c	14 Feb 2007 14:15:52 -0000	1.250
+++ bfd/elflink.c	19 Feb 2007 00:18:44 -0000
@@ -5237,6 +5237,7 @@ bfd_elf_size_dynamic_sections (bfd *outp
   if (!is_elf_hash_table (info->hash))
     return TRUE;
 
+  bed = get_elf_backend_data (output_bfd);
   elf_tdata (output_bfd)->relro = info->relro;
   if (info->execstack)
     elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X;
@@ -5263,7 +5264,7 @@ bfd_elf_size_dynamic_sections (bfd *outp
 		exec = PF_X;
 	      notesec = s;
 	    }
-	  else
+	  else if (bed->default_execstack)
 	    exec = PF_X;
 	}
       if (notesec)
@@ -5284,7 +5285,6 @@ bfd_elf_size_dynamic_sections (bfd *outp
 
   /* The backend may have to create some sections regardless of whether
      we're dynamic or not.  */
-  bed = get_elf_backend_data (output_bfd);
   if (bed->elf_backend_always_size_sections
       && ! (*bed->elf_backend_always_size_sections) (output_bfd, info))
     return FALSE;
Index: bfd/elfxx-target.h
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-target.h,v
retrieving revision 1.102
diff -u -p -r1.102 elfxx-target.h
--- bfd/elfxx-target.h	1 Feb 2007 05:35:58 -0000	1.102
+++ bfd/elfxx-target.h	19 Feb 2007 00:18:53 -0000
@@ -103,6 +103,9 @@
 #ifndef elf_backend_want_p_paddr_set_to_zero
 #define elf_backend_want_p_paddr_set_to_zero 0
 #endif
+#ifndef elf_backend_default_execstack
+#define elf_backend_default_execstack 1
+#endif
 
 #define bfd_elfNN_bfd_debug_info_start	bfd_void
 #define bfd_elfNN_bfd_debug_info_end	bfd_void
@@ -683,7 +686,8 @@ static struct elf_backend_data elfNN_bed
   elf_backend_can_refcount,
   elf_backend_want_got_sym,
   elf_backend_want_dynbss,
-  elf_backend_want_p_paddr_set_to_zero
+  elf_backend_want_p_paddr_set_to_zero,
+  elf_backend_default_execstack
 };
 
 /* Forward declaration for use when initialising alternative_target field.  */
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.257
diff -u -p -r1.257 elf64-ppc.c
--- bfd/elf64-ppc.c	13 Feb 2007 01:53:02 -0000	1.257
+++ bfd/elf64-ppc.c	19 Feb 2007 00:35:35 -0000
@@ -73,6 +73,7 @@ static bfd_vma opd_entry_value
 #define elf_backend_can_gc_sections 1
 #define elf_backend_can_refcount 1
 #define elf_backend_rela_normal 1
+#define elf_backend_default_execstack 0
 
 #define bfd_elf64_mkobject		      ppc64_elf_mkobject
 #define bfd_elf64_bfd_reloc_type_lookup	      ppc64_elf_reloc_type_lookup
@@ -1197,7 +1198,7 @@ static reloc_howto_type ppc64_elf_howto_
 
   /* Like R_PPC64_PLTGOT16, but for instructions with a DS field.  */
   /* FIXME: R_PPC64_PLTGOT16_DS not implemented.  */
-    HOWTO (R_PPC64_PLTGOT16_DS,	/* type */
+  HOWTO (R_PPC64_PLTGOT16_DS,	/* type */
 	 0,			/* rightshift */
 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
 	 16,			/* bitsize */

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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