https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106949

--- Comment #4 from Anton Fedorov <iam at datacompboy dot ru> ---
> You can't just add a stack segment without changing the stack pointer.

I can -- since we are on the initial stack at this point, no return into
__morestack will happen so no attempt to release it, thus there is no problem
and it won't affect subsequent allocations of frames would it be necessary.

But that's the catch: the allocated blocks won't be released no matter is we on
the initial stack or deep inside, until we try to release the frame, which may
never happen no matter are we on the initial stack or not.

the easiest way may be change gcc generate the code like:

```
struct __morestack_blocks {
  struct __morestack_blocks * next;
  void * block;
};

void __morestack_free_blocks(struct __morestack_blocks ** blocks) {
  struct __morestack_blocks * cur = *blocks;
  while(cur) {
    free(cur->block);
    cur = cur->next;
  }
}

void* __morestack_allocate_stack_space(int size, struct __morestack_blocks **
blocks){ ... }

somefunction(someargs) {
  struct __morestack_blocks __attribute__((cleanup(__morestack_free_blocks))) =
nullptr;

  // void * a = alloca(x);
  a = __morestack_allocate_stack_space(x, &__morestack_blocks);

}
```

But that local variable to be used as a reference, but makes it trivial
(although, I don't know how to generate local variable with assigned destructor
from the gcc code, will look for it)...

Reply via email to