Published at LXer:
In a short thread on thelkml, Linux creator Linus Torvalds discussedrecentlyadded hacks to prevent gcc from overwriting the argument stack inasmlinkage functions on the x86 platform. The existing fix involves usingprevent_tail_call() to prevent the gcc tail call optimization, though Linus notes, "the problem isn't even really fundamentally tailcalls, that just is the detail that happens to trigger the problem (but I could imagine other situations triggering it _too_". Tail calls are when the last line of one function returns a call to another function, somethingcommonly optimized by compilers.Linus acknowledged that the current hack in the kernel code is ugly, suggesting that the proper fix is for the gcc team to add an attribute allowing code to tell gcc it doesn't own the argument stack, "I'd much rather have 'asmlinkage' tell gcc directly that it doesn't own the stack, but no such attribute exists, so we're stuck with our hacky manual 'prevent_tail_call()' macro once more (we've had the same issue before with sys_waitpid() and sys_wait4())." He then went on to propose a cleaner hack to solve the same problem in a more generic way, not specific to the tail call optimization.