tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Nested functions


From: Antti-Juhani Kaijanaho
Subject: Re: [Tinycc-devel] Nested functions
Date: Fri, 14 Sep 2007 12:23:51 +0300
User-agent: Mutt/1.5.16 (2007-06-11)

On Fri, Sep 14, 2007 at 10:59:59AM +0200, Zdenek Pavlas wrote:
> 1. Portability issues.  Your code now requires compliant compiler and 
> runtime.

True.  If the feature were in the standard, this would not be a problem.
In the real world, it unfortunately is.  Of course, if more compilers
provided nested function as an extension, the standards committee would
be more likely to include it in C1x.  (It's not impossible that they
will in any case; the C++ committee was, when I last looked, thinking of
adding function-object-generating lambdas in C++0x.)

> 2. Security.  There was a strong rationale to make stack not executable.  
> Nested functions make it even worse than before: not only is stack 
> executable, but if there is a buffer overflow when the nested function is 
> in scope, the attacker knows that a fixed `esp + const` is getting to be 
> called, and very easily exploit that.

True.  Of course, an executable stack is only necessary if you are
constrained to a preexisting ABI that doesn't allow for fat function
pointers.

In other words, the con side of the feature is a matter of historical
wart.  If we could start with a clean slate, there would be no problem
(beside the small additional work for the compiler writer).

> Speed is not an issue.  The GCC implementation is pretty fast.  Actually I 
> think it's a well designed feature.  Very intuitive and sometimes usefull.  
> But IMHO just not worth the pain.

Yep; the trampoline adds a couple of instructions and an unconditional
direct jump.  The fat pointer approach would shave off that jump.

-- 
Antti-Juhani Kaijanaho, Jyväskylä
http://antti-juhani.kaijanaho.fi/newblog/
http://www.flickr.com/photos/antti-juhani/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]