I heard of a scheme by Henry Baker a year or so ago that and I thought then that the scheme did not apply to this problem. Perhaps it does however.
Baker’s scheme, by word of mouth, would be a collection of C routines linked together but of these sorts:
An alternative is to find a compiler that is guaranteed to do tail call optimization and insure that all special routines finish by calling another special routine only just before returning itself. This causes the special routine to undo its frame as it finishes.
In either case both special and ordinary routines can call ordinary routines. This means that faults in the stack segment cannot be taken as a signal to clean the stack. There is in general and often a few vital frames at the recent end of the stack.
gcc -O3 a.c -S -Wallproduces this:
.file "a.c" .text .p2align 4,,15 .globl b .type b, @function b: .LFB0: .cfi_startproc movq %rsi, %rax movq 8(%rsi), %rsi addl 16(%rax), %edi movq (%rax), %rax jmp *%rax .cfi_endproc .LFE0: .size b, .-b .ident "GCC: (GNU) 4.6.4" .section .note.GNU-stack,"",@progbitsThis stream function adds a constant to each character. You can’t write much better code in assembler.