2006年5月1日星期一

Linux: Who Owns The Stack?

In a short thread on the lkml, Linux creator Linus Torvalds discussed recently added hacks to prevent gcc from overwriting the argument stack in asmlinkage functions on the x86 platform. The existing fix involves using prevent_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, something commonly 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.

没有评论:

发表评论