[PATCH] Enable -zexecstack on Solaris

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Enable -zexecstack on Solaris

dtbartle
Hi,

The attached patch enabled executable stacks on Solaris (via
-zexecstack). On Solaris, this is achieved by setting the final
PT_LOAD section to be executable.

-- David

binutils-solaris-execstack.diff (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Enable -zexecstack on Solaris

Alan Modra
On Sat, May 02, 2009 at 04:11:28PM -0700, David Bartley wrote:
> The attached patch enabled executable stacks on Solaris (via
> -zexecstack). On Solaris, this is achieved by setting the final
> PT_LOAD section to be executable.
[snip]
> + * bfd/elf.c: Enable -zexecstack on Solaris.
> + * bfd/configure.in: Likewise.
> + * bfd/configure: Regenerate.
> + * bfd/config.in: Likewise.

I think bfd is the wrong place to implement this feature.  Instead,
you should arrange for ld to set SEC_CODE on .bss, which I think will
result in PF_X on the PT_LOAD header covering .bss.  Do this in a new
.em file for solaris (grep for EXTRA_EM_FILE examples), probably best
done in ldemul_before_allocation so that you have the option of
turning off link_info.execstack and noexecstack to not emit
PT_GNU_STACK, which I imagine isn't much use to you.

--
Alan Modra
Australia Development Lab, IBM
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Enable -zexecstack on Solaris

dtbartle
On Sat, May 2, 2009 at 8:10 PM, Alan Modra <[hidden email]> wrote:

> On Sat, May 02, 2009 at 04:11:28PM -0700, David Bartley wrote:
>> The attached patch enabled executable stacks on Solaris (via
>> -zexecstack). On Solaris, this is achieved by setting the final
>> PT_LOAD section to be executable.
> [snip]
>> +     * bfd/elf.c: Enable -zexecstack on Solaris.
>> +     * bfd/configure.in: Likewise.
>> +     * bfd/configure: Regenerate.
>> +     * bfd/config.in: Likewise.
>
> I think bfd is the wrong place to implement this feature.  Instead,
> you should arrange for ld to set SEC_CODE on .bss, which I think will
> result in PF_X on the PT_LOAD header covering .bss.  Do this in a new
> .em file for solaris (grep for EXTRA_EM_FILE examples), probably best
> done in ldemul_before_allocation so that you have the option of
> turning off link_info.execstack and noexecstack to not emit
> PT_GNU_STACK, which I imagine isn't much use to you.
Thanks for the suggestion. How does this patch look?

-- David

binutils-solaris-execstack.diff (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Enable -zexecstack on Solaris

dtbartle
Ping?

-- David

On Sat, May 2, 2009 at 10:55 PM, David Bartley
<[hidden email]> wrote:

> On Sat, May 2, 2009 at 8:10 PM, Alan Modra <[hidden email]> wrote:
>> On Sat, May 02, 2009 at 04:11:28PM -0700, David Bartley wrote:
>>> The attached patch enabled executable stacks on Solaris (via
>>> -zexecstack). On Solaris, this is achieved by setting the final
>>> PT_LOAD section to be executable.
>> [snip]
>>> +     * bfd/elf.c: Enable -zexecstack on Solaris.
>>> +     * bfd/configure.in: Likewise.
>>> +     * bfd/configure: Regenerate.
>>> +     * bfd/config.in: Likewise.
>>
>> I think bfd is the wrong place to implement this feature.  Instead,
>> you should arrange for ld to set SEC_CODE on .bss, which I think will
>> result in PF_X on the PT_LOAD header covering .bss.  Do this in a new
>> .em file for solaris (grep for EXTRA_EM_FILE examples), probably best
>> done in ldemul_before_allocation so that you have the option of
>> turning off link_info.execstack and noexecstack to not emit
>> PT_GNU_STACK, which I imagine isn't much use to you.
>
> Thanks for the suggestion. How does this patch look?
>
> -- David
>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Enable -zexecstack on Solaris

Alan Modra
On Thu, May 07, 2009 at 01:36:18AM -0700, David Bartley wrote:

> Ping?
>
> On Sat, May 2, 2009 at 10:55 PM, David Bartley
> <[hidden email]> wrote:
> > On Sat, May 2, 2009 at 8:10 PM, Alan Modra <[hidden email]> wrote:
> >> On Sat, May 02, 2009 at 04:11:28PM -0700, David Bartley wrote:
> >>> The attached patch enabled executable stacks on Solaris (via
> >>> -zexecstack). On Solaris, this is achieved by setting the final
> >>> PT_LOAD section to be executable.
> >> [snip]
> >>> +     * bfd/elf.c: Enable -zexecstack on Solaris.
> >>> +     * bfd/configure.in: Likewise.
> >>> +     * bfd/configure: Regenerate.
> >>> +     * bfd/config.in: Likewise.
> >>
> >> I think bfd is the wrong place to implement this feature.  Instead,
> >> you should arrange for ld to set SEC_CODE on .bss, which I think will
> >> result in PF_X on the PT_LOAD header covering .bss.  Do this in a new
> >> .em file for solaris (grep for EXTRA_EM_FILE examples), probably best

Adding target hacks to elf32.em isn't quite as tidy as a new solaris
.em file, but I guess is acceptable.  Hmm, especially given that
powerpc already uses EXTRA_EM_FILE.

> >> done in ldemul_before_allocation so that you have the option of
> >> turning off link_info.execstack and noexecstack to not emit
> >> PT_GNU_STACK, which I imagine isn't much use to you.
> >
> > Thanks for the suggestion. How does this patch look?

Was there a reason why you patched after_open rather than
before_allocation?  If you make the change in the latter function then
you can set flags on the output .bss section rather than looping over
input files.  Also, I forgot one corner case:  You need to set
SEC_KEEP on the output .bss, otherwise ld will remove an empty .bss
section and the SEC_CODE flag be ignored.

> +  # GNU/kOpenSolaris uses glibc, which uses PT_GNU_STACK, but we don't need to
> +  # emit PT_GNU_STACK for Solaris proper.
> +  case ${target} in
> +    *-*-solaris2*)
> +  fragment <<EOF
> +  link_info.execstack = 0;
> +EOF

Clear noexecstack too.

--
Alan Modra
Australia Development Lab, IBM