mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Fortran nested function causes a segfault when linked from a shared library.
@ 2024-06-23 18:33 Nickolai Belakovski
  2024-06-23 21:00 ` Szabolcs Nagy
  0 siblings, 1 reply; 5+ messages in thread
From: Nickolai Belakovski @ 2024-06-23 18:33 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 897 bytes --]

Hello all,

I'm having some trouble running a particular Fortran program I'm working on.
I've reduced it down to just a few lines of code and it seems that this
issue only occurs on musl.

As the title indicates, when a Fortran subroutine has a nested subroutine,
and it passes
that subroutine to another subroutine, that second subroutine will segfault
when it tries
to call the passed nested subroutine. I know, it's quite a mouthful, it's
probably easier
if you look at the code:
https://github.com/nbelakovski/fortran_nested_func_musl

I tried a handful of different compiler flags but I'm mostly just pulling
at straws here.

I'd appreciate any help anyone could provide in terms of either
investigating this issue
further or hopefully fixing it.

I've used mailing lists only once before so if my formatting or etiquette
is off please let
me know so that I may correct it.

Cheers,
Nickolai

[-- Attachment #2: Type: text/html, Size: 1225 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Fortran nested function causes a segfault when linked from a shared library.
  2024-06-23 18:33 [musl] Fortran nested function causes a segfault when linked from a shared library Nickolai Belakovski
@ 2024-06-23 21:00 ` Szabolcs Nagy
  2024-06-23 21:16   ` Szabolcs Nagy
  2024-06-24  3:05   ` Jeffrey Walton
  0 siblings, 2 replies; 5+ messages in thread
From: Szabolcs Nagy @ 2024-06-23 21:00 UTC (permalink / raw)
  To: Nickolai Belakovski; +Cc: musl

* Nickolai Belakovski <nbelakovski@gmail.com> [2024-06-23 14:33:32 -0400]:
> Hello all,
> 
> I'm having some trouble running a particular Fortran program I'm working on.
> I've reduced it down to just a few lines of code and it seems that this
> issue only occurs on musl.
> 
> As the title indicates, when a Fortran subroutine has a nested subroutine,
> and it passes
> that subroutine to another subroutine, that second subroutine will segfault
> when it tries
> to call the passed nested subroutine. I know, it's quite a mouthful, it's
> probably easier
> if you look at the code:
> https://github.com/nbelakovski/fortran_nested_func_musl
> 
> I tried a handful of different compiler flags but I'm mostly just pulling
> at straws here.
> 
> I'd appreciate any help anyone could provide in terms of either
> investigating this issue
> further or hopefully fixing it.


readelf -lW libalgorithm.so
...
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10

musl does not support executable stack, but gcc implements
nested functions via an on-stack trampolines that requires
executable stack.

i don't think there is a compiler flag to fix this, you
have to change the code.

> 
> I've used mailing lists only once before so if my formatting or etiquette
> is off please let
> me know so that I may correct it.
> 
> Cheers,
> Nickolai

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Fortran nested function causes a segfault when linked from a shared library.
  2024-06-23 21:00 ` Szabolcs Nagy
@ 2024-06-23 21:16   ` Szabolcs Nagy
  2024-06-24  3:05   ` Jeffrey Walton
  1 sibling, 0 replies; 5+ messages in thread
From: Szabolcs Nagy @ 2024-06-23 21:16 UTC (permalink / raw)
  To: Nickolai Belakovski, musl

* Szabolcs Nagy <nsz@port70.net> [2024-06-23 23:00:50 +0200]:

> * Nickolai Belakovski <nbelakovski@gmail.com> [2024-06-23 14:33:32 -0400]:
> > Hello all,
> > 
> > I'm having some trouble running a particular Fortran program I'm working on.
> > I've reduced it down to just a few lines of code and it seems that this
> > issue only occurs on musl.
> > 
> > As the title indicates, when a Fortran subroutine has a nested subroutine,
> > and it passes
> > that subroutine to another subroutine, that second subroutine will segfault
> > when it tries
> > to call the passed nested subroutine. I know, it's quite a mouthful, it's
> > probably easier
> > if you look at the code:
> > https://github.com/nbelakovski/fortran_nested_func_musl
> > 
> > I tried a handful of different compiler flags but I'm mostly just pulling
> > at straws here.
> > 
> > I'd appreciate any help anyone could provide in terms of either
> > investigating this issue
> > further or hopefully fixing it.
> 
> 
> readelf -lW libalgorithm.so
> ...
>   GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10
> 
> musl does not support executable stack, but gcc implements
> nested functions via an on-stack trampolines that requires
> executable stack.
> 
> i don't think there is a compiler flag to fix this, you
> have to change the code.
> 

sorry, gcc-14 has -ftrampoline-impl=heap that should fix this.

> > 
> > I've used mailing lists only once before so if my formatting or etiquette
> > is off please let
> > me know so that I may correct it.
> > 
> > Cheers,
> > Nickolai

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Fortran nested function causes a segfault when linked from a shared library.
  2024-06-23 21:00 ` Szabolcs Nagy
  2024-06-23 21:16   ` Szabolcs Nagy
@ 2024-06-24  3:05   ` Jeffrey Walton
  2024-06-24 22:41     ` Nickolai Belakovski
  1 sibling, 1 reply; 5+ messages in thread
From: Jeffrey Walton @ 2024-06-24  3:05 UTC (permalink / raw)
  To: musl, Nickolai Belakovski

On Sun, Jun 23, 2024 at 5:01 PM Szabolcs Nagy <nsz@port70.net> wrote:
>
> * Nickolai Belakovski <nbelakovski@gmail.com> [2024-06-23 14:33:32 -0400]:
> > Hello all,
> >
> > I'm having some trouble running a particular Fortran program I'm working on.
> > I've reduced it down to just a few lines of code and it seems that this
> > issue only occurs on musl.
> >
> > As the title indicates, when a Fortran subroutine has a nested subroutine,
> > and it passes
> > that subroutine to another subroutine, that second subroutine will segfault
> > when it tries
> > to call the passed nested subroutine. I know, it's quite a mouthful, it's
> > probably easier
> > if you look at the code:
> > https://github.com/nbelakovski/fortran_nested_func_musl
> >
> > I tried a handful of different compiler flags but I'm mostly just pulling
> > at straws here.
> >
> > I'd appreciate any help anyone could provide in terms of either
> > investigating this issue
> > further or hopefully fixing it.
>
>
> readelf -lW libalgorithm.so
> ...
>   GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10
>
> musl does not support executable stack, but gcc implements
> nested functions via an on-stack trampolines that requires
> executable stack.
>
> i don't think there is a compiler flag to fix this, you
> have to change the code.

Also see <https://gcc.gnu.org/onlinedocs/gccint/Trampolines.html>, and
the -fno-trampolines option.

Jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Fortran nested function causes a segfault when linked from a shared library.
  2024-06-24  3:05   ` Jeffrey Walton
@ 2024-06-24 22:41     ` Nickolai Belakovski
  0 siblings, 0 replies; 5+ messages in thread
From: Nickolai Belakovski @ 2024-06-24 22:41 UTC (permalink / raw)
  To: noloader; +Cc: musl

I tried -fno-trampolines but it had no effect. Indeed, even when using
it I got the warning about a trampoline being generated.

-ftrampoline-impl looks promising, but do you know a quick way I could
validate it? I see that gcc 14 isn't in the alpine packages yet. I'm
working on compiling it from source, but it's not particularly
straightforward and it's not quick either. Do you know of any musl
distributions that package gcc 14 at this time?

Thanks,
Nickolai

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-06-24 22:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-23 18:33 [musl] Fortran nested function causes a segfault when linked from a shared library Nickolai Belakovski
2024-06-23 21:00 ` Szabolcs Nagy
2024-06-23 21:16   ` Szabolcs Nagy
2024-06-24  3:05   ` Jeffrey Walton
2024-06-24 22:41     ` Nickolai Belakovski

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).