← All stories
● Covered by 1 source · 1 reportLow impact1 neutral

Indirect Calling of GCC Nested Functions Without Executable Stack for Older Versions

🔄 Updated 2h ago
New to BrevFeed? We gather this story from every outlet covering it into one summary — ranked by real-world impact, not just the latest headline — so you never miss what matters. What is BrevFeed? →

Key points

  • Addresses calling nested functions in older GCC without an executable stack.
  • Method involves extracting code address and static chain from trampolines.
  • Uses `__builtin_call_with_static_chain` for indirect calls.
  • Provides an alternative to future GCC 17 built-ins.

Addressing Executable Stack Requirements

The article discusses a technique for using nested functions in GCC without needing an executable stack, specifically targeting older GCC versions. While an executable stack is sometimes accepted, this method offers an alternative for environments where it is not preferred or allowed. This builds on previous discussions about using nested functions for callbacks without an executable stack in GCC 17 and Clang.

GCC's Nested Function Implementation

When taking the address of a nested function, GCC generates assembly code that places a trampoline on the stack. This trampoline is immediately invoked and loads the static frame register to a structure containing captured variables from the parent function, then jumps to the local function. The trampoline's code includes immediate constants for the static chain and the code address.

Indirect Calling Mechanism

Instead of directly invoking the trampoline, the code address and static chain can be extracted from it. These extracted pointers can then be used with the `__builtin_call_with_static_chain` built-in function to call the local function indirectly. An example using `noplate`'s `peek` and `array_slice` macros demonstrates this extraction for x86_64 architectures.

Comparison to Future GCC Features

The information obtained through this manual extraction process is equivalent to what will be provided by the new built-in functions `__builtin_call_static_chain` and `__builtin_call_code_address` in the upcoming GCC 17. This method therefore serves as a workaround for achieving similar functionality in older GCC versions before these built-ins are widely available.

✨ This summary was generated by AI from the outlets' reporting listed below. It is not independently verified and may contain errors — check the original sources. How BrevFeed works →

The daily brief

One email each morning: the day's tech stories, clustered across outlets and summarized. No account needed.

One email a day. Unsubscribe in one click, any time.

Today's brief

Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.

~8 min · 7 stories · Aug 29

▶ Play today's brief Listen on Spotify

New every morning, and the back catalogue is archived by date.

Reporting from

This article details a method to indirectly call nested functions in older GCC versions without requiring an executable stack, by manually extracting the code address and static chain from the trampoline. This approach provides a workaround for environments where an executable stack is undesirable or unavailable, predating the built-in functions planned for GCC 17.