This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Re: [patch ping] libffi/boehm-gc/crt files executable stack (missing .note.GNU-stack on .o files)


On Thu, Jul 12, 2007 at 12:58:15PM +0100, Andrew Haley wrote:
> Jakub Jelinek writes:
>  > On Thu, Jul 05, 2007 at 12:51:51PM +0200, Matthias Klose wrote:
>  > > The following patch (taken from the redhat/gcc-4_1-branch) adds .note.GNU-stack
>  > > sections for gcc's crt files, libffi and boehm-gc.
>  > > 
>  > > sent first here: http://gcc.gnu.org/ml/gcc-patches/2006-12/msg00948.html
>  > > 
>  > > Updated in the patch is:
>  > > 
>  > > 2007-05-11  Daniel Jacobowitz  <dan@debian.org>
>  > > 
>  > >         * src/arm/sysv.S: Fix ARM comment marker.
>  > > 
>  > > Jakub, is this patch necessary/wanted in the FSF sources?
>  > 
>  > Yes, except perhaps the ppc64 and ia64 bits.  There it is ambiguous whether
>  > PT_GNU_STACK segments are desirable or not (varries between upstream and
>  > distros) and recent changes in binutils on ia64 and ppc64 assume by
>  > default non-executable stack whe .note.GNU-stack section is not present,
>  > so explicit .note.GNU-stack with "x" needs to be used to force
>  > executable PT_GNU_STACK.
> 
> But why?  libffi doesn't need an executable stack, and libgcj
> definitely doesn't want it.

The gcc/as/ld behavior on linux non-ppc64/non-ia64 is:
- compiler generated assembly always contains .note.GNU-stack note,
  either with "", or with "x" flags - the former if it doesn't need
  trampolines, the latter if it does
- if -Wa,--execstack or -Wa,--noexecstack options are used,
  .note.GNU-stack section is generated, with "x" resp. "" flags
- during linking, if none of the input objects for some DSO or
  executable contain .note.GNU-stack note, no PT_GNU_STACK
  is created (very rare these days, as crtfiles e.g. will have
  the notes), otherwise if .note.GNU-stack notes are present
  in all object files and are all "" (non-executable), PT_GNU_STACK
  without PF_X is created, otherwise PT_GNU_STACK with PF_X is
  created.  This can be overridden with -Wl,-z,execstack or
  -Wl,-z,noexecstack
So, C/C++/Java code by default is assumed not to need executable
stack unless it needs trampolines (e.g. when taking address of
a nested function, or for Ada), while assembly sources must be
marked in one of the above ways, otherwise they are pessimistally
assumed to need executable stack.
As libffi assembly is known not to need executable stack, it
should be either marked, or assembled with -Wa,--noexecstack,
otherwise libgcj.so will require executable stack.

	Jakub


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