This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Enable -zexecstack on Solaris
On Sat, May 2, 2009 at 8:10 PM, Alan Modra <amodra@bigpond.net.au> 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
diff -uraN binutils-2.19.51.orig/ChangeLog binutils-2.19.51/ChangeLog
--- binutils-2.19.51.orig/ChangeLog 2009-04-25 08:24:57.000000000 -0400
+++ binutils-2.19.51/ChangeLog 2009-05-03 01:48:12.812863280 -0400
@@ -1,3 +1,7 @@
+2009-05-02 David Bartley <dtbartle@csclub.uwaterloo.ca>
+
+ * ld/emultempl/elf32.em: Fix -zexecstack on Solaris.
+
2009-04-25 Eric Botcazou <ebotcazou@adacore.com>
* Makefile.tpl (POSTSTAGE1_HOST_EXPORTS): Add GNATBIND.
diff -uraN binutils-2.19.51.orig/ld/emultempl/elf32.em binutils-2.19.51/ld/emultempl/elf32.em
--- binutils-2.19.51.orig/ld/emultempl/elf32.em 2008-10-21 18:55:04.000000000 -0400
+++ binutils-2.19.51/ld/emultempl/elf32.em 2009-05-03 01:50:33.525760453 -0400
@@ -1037,6 +1037,39 @@
{
struct bfd_link_needed_list *needed, *l;
struct elf_link_hash_table *htab;
+EOF
+ # Solaris enables executable stacks by setting the final PT_LOAD section to
+ # be executable. We set .bss to be executable, since it will end up being in
+ # the final PT_LOAD section.
+ case ${target} in
+ *-*-solaris2* | *-*-kopensolaris*-gnu*)
+ fragment <<EOF
+
+ if (link_info.execstack)
+ {
+ LANG_FOR_EACH_INPUT_STATEMENT (is)
+ {
+ asection *s;
+
+ s = bfd_get_section_by_name (is->the_bfd, ".bss");
+ if (s)
+ s->flags |= SEC_CODE;
+ }
+ }
+EOF
+ ;;
+ esac
+
+ # 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
+ ;;
+ esac
+fragment <<EOF
htab = elf_hash_table (&link_info);
if (!is_elf_hash_table (htab))