This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Nested functions
- From: Ian Lance Taylor <ian at airs dot com>
- To: Marco Gerards <mgerards at xs4all dot nl>
- Cc: gcc-help at gnu dot org
- Date: 28 Dec 2005 08:13:29 -0800
- Subject: Re: Nested functions
- References: <87bqz1idwc.fsf@xs4all.nl>
Marco Gerards <mgerards@xs4all.nl> writes:
> There have been quite some "bug reports" for a project I work on
> lately related to nested functions. Although I don't know the
> internals of gcc, it seems that sometimes trampolines are used when a
> function pointer to the nested function is passed to another function.
>
> Two "bugs" have been reported:
>
> 1) It doesn't build under Mac OSX.
> 2) The program does not execute when the stack is not executable.
>
> The first problem is caused by apple, regardless of whether
> trampolines are required or not, the program, AFAIK, does not build.
>
> The second problem is caused because some OS'es have no executable
> stack. Redhat even removes the nested functions from our code so it
> builds for them. But of course it would be better for all of our
> users if it just works.
The implementation of nested functions requires using a trampoline
when you pass the address of a nested function to another function.
That is not a bug.
For most if not all targets these trampolines are created on the
stack, and thus require the stack to be executable. On GNU/Linux, the
program will normally be annotated to indicate that it requires an
executable stack (I'm not sure what you mean when you say that Red Hat
removes the nested functions). On NetBSD and other operating systems,
the compiler will insert a call to a system call to make the stack
executable. There may be other strategies used on other systems. I
don't know the status of trampolines on Mac OS/X. Note that Apple
ships a patched version of gcc.
> 1) Is there a fix for this or has this been fixed?
I don't know what the bug is, so I don't know whether it has been
fixed.
> 2) What is the official stance of the GCC maintainers regarding this
> issue? It's a documented feature we like and we rely on.
Nested functions are supposed to work.
Please check for existing bug reports at http://gcc.gnu.org/bugzilla/,
and file a new bug report if you don't find one. See
http://gcc.gnu.org/bugs.html. Thanks.
Ian