Tech News
← Home  ·  All topics

Nested Functions

2 GoKawiil briefs on this topic

GCC's Nested Functions: How They Differ From C++ Lambdas Internally

Martin Uecker details how GCC compiles nested functions that access variables from an enclosing function, explaining that such functions are lowered early in the middle-end. Variables referenced by the nested function are gathered into a single synthetic struct, with a pointer to that struct passed to the nested function instead of using older stack-frame-pointer techniques like those in Pascal.

Martin Uecker details GCC hack for nested-function callbacks without executable stack

A technical blog post by Martin Uecker examines how GCC compiles nested functions using trampolines placed on the stack, which normally require the stack to be executable. He shows that by extracting the code address and static chain values embedded in the trampoline and passing them to the __builtin_call_with_static_chain built-in, developers can indirectly call nested functions on older GCC versions without needing an executable stack.