Discussion:
ppc64 exec stack
Alan Modra
2007-02-19 13:02:06 UTC
Permalink
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
Andreas Schwab
2007-02-19 14:29:15 UTC
Permalink
Post by Alan Modra
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.
IMHO that would also make sense on ia64, which is non-exec stack by
default as well.

Andreas.
--
Andreas Schwab, SuSE Labs, ***@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Andreas Schwab
2007-02-19 18:07:06 UTC
Permalink
Post by Andreas Schwab
Post by Alan Modra
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.
IMHO that would also make sense on ia64, which is non-exec stack by
default as well.
This has been tested on ia64-suse-linux.

Andreas.

2007-02-19 Andreas Schwab <***@suse.de>

* elfxx-ia64.c (elf_backend_default_execstack): Define to 0.

--- bfd/elfxx-ia64.c.~1.193.~ 2006-11-03 11:13:00.000000000 +0100
+++ bfd/elfxx-ia64.c 2007-02-19 15:42:51.000000000 +0100
@@ -5801,6 +5801,7 @@ elfNN_hpux_backend_symbol_processing (bf
#define elf_backend_reloc_type_class elfNN_ia64_reloc_type_class
#define elf_backend_rela_normal 1
#define elf_backend_special_sections elfNN_ia64_special_sections
+#define elf_backend_default_execstack 0

/* FIXME: PR 290: The Intel C compiler generates SHT_IA_64_UNWIND with
SHF_LINK_ORDER. But it doesn't set the sh_link or sh_info fields.
--
Andreas Schwab, SuSE Labs, ***@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Jim Wilson
2007-03-26 23:20:53 UTC
Permalink
Post by Andreas Schwab
Post by Andreas Schwab
IMHO that would also make sense on ia64, which is non-exec stack by
default as well.
True, but the patch doesn't seem to gain us anything, since Alan was
fixing a ppc64 specific problem that won't occur on IA-64. But, on the
other hand, it certainly doesn't hurt to do this, and may help in the
future, so we may as well do it, if only for documentation.
Post by Andreas Schwab
* elfxx-ia64.c (elf_backend_default_execstack): Define to 0.
OK.
--
Jim Wilson, GNU Tools Support, http://www.specifix.com
Andreas Schwab
2007-03-26 23:42:28 UTC
Permalink
Post by Jim Wilson
Post by Andreas Schwab
IMHO that would also make sense on ia64, which is non-exec stack by
default as well.
True, but the patch doesn't seem to gain us anything, since Alan was
fixing a ppc64 specific problem that won't occur on IA-64.
The same problem exists on ia64 as well. There are software packages that
explicitly compile with -Wa,--noexecstack, causing the same kind of mixing
stack notes with absense of notes (from the compiler-supplied object
files). Instead of requiring to remember when --noexecstack should not be
used it is easier to make this case work as intented.

Andreas.
--
Andreas Schwab, SuSE Labs, ***@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Loading...