[v2] configure: define TARGET_LIBC_GNUSTACK on musl

Message ID 20211116051323.4900-1-ilya.lipnitskiy@gmail.com
State New
Headers
Series [v2] configure: define TARGET_LIBC_GNUSTACK on musl |

Commit Message

Ilya Lipnitskiy Nov. 16, 2021, 5:13 a.m. UTC
  musl only uses PT_GNU_STACK to set default thread stack size and has no
executable stack support[0], so there is no reason not to emit the
.note.GNU-stack section on musl builds.

[0]: https://lore.kernel.org/all/20190423192534.GN23599@brightrain.aerifal.cx/T/#u

gcc/ChangeLog:

	* configure: Regenerate.
	* configure.ac: define TARGET_LIBC_GNUSTACK on musl

Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
---
 gcc/configure    | 3 +++
 gcc/configure.ac | 3 +++
 2 files changed, 6 insertions(+)
  

Comments

Dragan Mladjenovic Nov. 16, 2021, 2:40 p.m. UTC | #1
Hi,

Looks fine to me. If possible, maybe it should even be back-ported to 
stable branches.

Not sure if MIPS assembly sources (if any) in musl would need explicit 
.note.GNU-stack

to complement this?

Best regards,

Dragan

On 16-Nov-21 06:13, Ilya Lipnitskiy wrote:
> musl only uses PT_GNU_STACK to set default thread stack size and has no
> executable stack support[0], so there is no reason not to emit the
> .note.GNU-stack section on musl builds.
>
> [0]: https://lore.kernel.org/all/20190423192534.GN23599@brightrain.aerifal.cx/T/#u
>
> gcc/ChangeLog:
>
> 	* configure: Regenerate.
> 	* configure.ac: define TARGET_LIBC_GNUSTACK on musl
>
> Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
> ---
>   gcc/configure    | 3 +++
>   gcc/configure.ac | 3 +++
>   2 files changed, 6 insertions(+)
>
> diff --git a/gcc/configure b/gcc/configure
> index 74b9d9be4c85..7091a838aefa 100755
> --- a/gcc/configure
> +++ b/gcc/configure
> @@ -31275,6 +31275,9 @@ fi
>   # Check if the target LIBC handles PT_GNU_STACK.
>   gcc_cv_libc_gnustack=unknown
>   case "$target" in
> +  mips*-*-linux-musl*)
> +    gcc_cv_libc_gnustack=yes
> +    ;;
>     mips*-*-linux*)
>   
>   if test $glibc_version_major -gt 2 \
> diff --git a/gcc/configure.ac b/gcc/configure.ac
> index c9ee1fb8919e..8a2d34179a75 100644
> --- a/gcc/configure.ac
> +++ b/gcc/configure.ac
> @@ -6961,6 +6961,9 @@ fi
>   # Check if the target LIBC handles PT_GNU_STACK.
>   gcc_cv_libc_gnustack=unknown
>   case "$target" in
> +  mips*-*-linux-musl*)
> +    gcc_cv_libc_gnustack=yes
> +    ;;
>     mips*-*-linux*)
>       GCC_GLIBC_VERSION_GTE_IFELSE([2], [31], [gcc_cv_libc_gnustack=yes], )
>       ;;
  
Rich Felker Nov. 16, 2021, 4:25 p.m. UTC | #2
On Tue, Nov 16, 2021 at 03:40:00PM +0100, Dragan Mladjenovic wrote:
> Hi,
> 
> Looks fine to me. If possible, maybe it should even be back-ported
> to stable branches.
> 
> Not sure if MIPS assembly sources (if any) in musl would need
> explicit ..note.GNU-stack
> 
> to complement this?

What are the actual consequences of making this change, and what is
the goal? I'm concerned that it might produce object files which don't
include annotation that they don't need executable stack, in which
case the final executable file will be marked as executable-stack and
the kernel will load it as such. That would be very bad.

Rich


> On 16-Nov-21 06:13, Ilya Lipnitskiy wrote:
> >musl only uses PT_GNU_STACK to set default thread stack size and has no
> >executable stack support[0], so there is no reason not to emit the
> >.note.GNU-stack section on musl builds.
> >
> >[0]: https://lore.kernel.org/all/20190423192534.GN23599@brightrain.aerifal.cx/T/#u
> >
> >gcc/ChangeLog:
> >
> >	* configure: Regenerate.
> >	* configure.ac: define TARGET_LIBC_GNUSTACK on musl
> >
> >Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
> >---
> >  gcc/configure    | 3 +++
> >  gcc/configure.ac | 3 +++
> >  2 files changed, 6 insertions(+)
> >
> >diff --git a/gcc/configure b/gcc/configure
> >index 74b9d9be4c85..7091a838aefa 100755
> >--- a/gcc/configure
> >+++ b/gcc/configure
> >@@ -31275,6 +31275,9 @@ fi
> >  # Check if the target LIBC handles PT_GNU_STACK.
> >  gcc_cv_libc_gnustack=unknown
> >  case "$target" in
> >+  mips*-*-linux-musl*)
> >+    gcc_cv_libc_gnustack=yes
> >+    ;;
> >    mips*-*-linux*)
> >  if test $glibc_version_major -gt 2 \
> >diff --git a/gcc/configure.ac b/gcc/configure.ac
> >index c9ee1fb8919e..8a2d34179a75 100644
> >--- a/gcc/configure.ac
> >+++ b/gcc/configure.ac
> >@@ -6961,6 +6961,9 @@ fi
> >  # Check if the target LIBC handles PT_GNU_STACK.
> >  gcc_cv_libc_gnustack=unknown
> >  case "$target" in
> >+  mips*-*-linux-musl*)
> >+    gcc_cv_libc_gnustack=yes
> >+    ;;
> >    mips*-*-linux*)
> >      GCC_GLIBC_VERSION_GTE_IFELSE([2], [31], [gcc_cv_libc_gnustack=yes], )
> >      ;;
  
Ilya Lipnitskiy Nov. 16, 2021, 5:49 p.m. UTC | #3
On Tue, Nov 16, 2021 at 8:41 AM Rich Felker <dalias@libc.org> wrote:
>
> On Tue, Nov 16, 2021 at 03:40:00PM +0100, Dragan Mladjenovic wrote:
> > Hi,
> >
> > Looks fine to me. If possible, maybe it should even be back-ported
> > to stable branches.
The change cherry-picks fine onto 10.x and 11.x branches. Should I
send out separate patches or can the committer of this patch apply it
to 10.x and 11.x?
> >
> > Not sure if MIPS assembly sources (if any) in musl would need
> > explicit ..note.GNU-stack
> >
> > to complement this?
>
> What are the actual consequences of making this change, and what is
> the goal? I'm concerned that it might produce object files which don't
> include annotation that they don't need executable stack, in which
> case the final executable file will be marked as executable-stack and
> the kernel will load it as such. That would be very bad.
It is actually the other way around - for MIPS hard-float targets on
non-glibc (or glibc < 2.31) without this change the .note.GNU-stack
annotation is not emitted by GCC.

Ilya
>
> Rich
>
>
> > On 16-Nov-21 06:13, Ilya Lipnitskiy wrote:
> > >musl only uses PT_GNU_STACK to set default thread stack size and has no
> > >executable stack support[0], so there is no reason not to emit the
> > >.note.GNU-stack section on musl builds.
> > >
> > >[0]: https://lore.kernel.org/all/20190423192534.GN23599@brightrain.aerifal.cx/T/#u
> > >
> > >gcc/ChangeLog:
> > >
> > >     * configure: Regenerate.
> > >     * configure.ac: define TARGET_LIBC_GNUSTACK on musl
> > >
> > >Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
> > >---
> > >  gcc/configure    | 3 +++
> > >  gcc/configure.ac | 3 +++
> > >  2 files changed, 6 insertions(+)
> > >
> > >diff --git a/gcc/configure b/gcc/configure
> > >index 74b9d9be4c85..7091a838aefa 100755
> > >--- a/gcc/configure
> > >+++ b/gcc/configure
> > >@@ -31275,6 +31275,9 @@ fi
> > >  # Check if the target LIBC handles PT_GNU_STACK.
> > >  gcc_cv_libc_gnustack=unknown
> > >  case "$target" in
> > >+  mips*-*-linux-musl*)
> > >+    gcc_cv_libc_gnustack=yes
> > >+    ;;
> > >    mips*-*-linux*)
> > >  if test $glibc_version_major -gt 2 \
> > >diff --git a/gcc/configure.ac b/gcc/configure.ac
> > >index c9ee1fb8919e..8a2d34179a75 100644
> > >--- a/gcc/configure.ac
> > >+++ b/gcc/configure.ac
> > >@@ -6961,6 +6961,9 @@ fi
> > >  # Check if the target LIBC handles PT_GNU_STACK.
> > >  gcc_cv_libc_gnustack=unknown
> > >  case "$target" in
> > >+  mips*-*-linux-musl*)
> > >+    gcc_cv_libc_gnustack=yes
> > >+    ;;
> > >    mips*-*-linux*)
> > >      GCC_GLIBC_VERSION_GTE_IFELSE([2], [31], [gcc_cv_libc_gnustack=yes], )
> > >      ;;
  
Jeff Law Dec. 2, 2021, 8:48 p.m. UTC | #4
On 11/15/2021 10:13 PM, Ilya Lipnitskiy wrote:
> musl only uses PT_GNU_STACK to set default thread stack size and has no
> executable stack support[0], so there is no reason not to emit the
> .note.GNU-stack section on musl builds.
>
> [0]: https://lore.kernel.org/all/20190423192534.GN23599@brightrain.aerifal.cx/T/#u
>
> gcc/ChangeLog:
>
> 	* configure: Regenerate.
> 	* configure.ac: define TARGET_LIBC_GNUSTACK on musl
Thanks.  I've pushed this to the trunk.  Sorry for the long wait.

Jeff
  
Ilya Lipnitskiy Dec. 2, 2021, 8:59 p.m. UTC | #5
On Thu, Dec 2, 2021 at 12:48 PM Jeff Law <jeffreyalaw@gmail.com> wrote:
>
>
>
> On 11/15/2021 10:13 PM, Ilya Lipnitskiy wrote:
> > musl only uses PT_GNU_STACK to set default thread stack size and has no
> > executable stack support[0], so there is no reason not to emit the
> > .note.GNU-stack section on musl builds.
> >
> > [0]: https://lore.kernel.org/all/20190423192534.GN23599@brightrain.aerifal.cx/T/#u
> >
> > gcc/ChangeLog:
> >
> >       * configure: Regenerate.
> >       * configure.ac: define TARGET_LIBC_GNUSTACK on musl
> Thanks.  I've pushed this to the trunk.  Sorry for the long wait.
No worries, and thank you! How about 10.x and 11.x branches, do you
think it should get picked into those since this change is effectively
a follow-up to https://gcc.gnu.org/g:54b3d52c3 ? Please also update
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103470 I created to track
this fix.

Ilya
  
Jeff Law Dec. 2, 2021, 9:12 p.m. UTC | #6
On 12/2/2021 1:59 PM, Ilya Lipnitskiy wrote:
> On Thu, Dec 2, 2021 at 12:48 PM Jeff Law <jeffreyalaw@gmail.com> wrote:
>>
>>
>> On 11/15/2021 10:13 PM, Ilya Lipnitskiy wrote:
>>> musl only uses PT_GNU_STACK to set default thread stack size and has no
>>> executable stack support[0], so there is no reason not to emit the
>>> .note.GNU-stack section on musl builds.
>>>
>>> [0]: https://lore.kernel.org/all/20190423192534.GN23599@brightrain.aerifal.cx/T/#u
>>>
>>> gcc/ChangeLog:
>>>
>>>        * configure: Regenerate.
>>>        * configure.ac: define TARGET_LIBC_GNUSTACK on musl
>> Thanks.  I've pushed this to the trunk.  Sorry for the long wait.
> No worries, and thank you! How about 10.x and 11.x branches, do you
> think it should get picked into those since this change is effectively
> a follow-up to https://gcc.gnu.org/g:54b3d52c3 ? Please also update
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103470 I created to track
> this fix.
I wasn't planning to backport it.  I'd leave that decision up to the 
release managers.

jeff
  

Patch

diff --git a/gcc/configure b/gcc/configure
index 74b9d9be4c85..7091a838aefa 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -31275,6 +31275,9 @@  fi
 # Check if the target LIBC handles PT_GNU_STACK.
 gcc_cv_libc_gnustack=unknown
 case "$target" in
+  mips*-*-linux-musl*)
+    gcc_cv_libc_gnustack=yes
+    ;;
   mips*-*-linux*)
 
 if test $glibc_version_major -gt 2 \
diff --git a/gcc/configure.ac b/gcc/configure.ac
index c9ee1fb8919e..8a2d34179a75 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -6961,6 +6961,9 @@  fi
 # Check if the target LIBC handles PT_GNU_STACK.
 gcc_cv_libc_gnustack=unknown
 case "$target" in
+  mips*-*-linux-musl*)
+    gcc_cv_libc_gnustack=yes
+    ;;
   mips*-*-linux*)
     GCC_GLIBC_VERSION_GTE_IFELSE([2], [31], [gcc_cv_libc_gnustack=yes], )
     ;;