23 Aug, 2007, Guest wrote in the 1st comment:
Votes: 0
Tyche said:
* Function tail_chain removed.


Quoted from Tyche's log for Murk++. The function is called in several places in Merc and derived code. Is this something that's no longer required or does Murk++ just not need it anymore?
23 Aug, 2007, Dorian wrote in the 2nd comment:
Votes: 0
Samson said:
Tyche said:
* Function tail_chain removed.


Quoted from Tyche's log for Murk++. The function is called in several places in Merc and derived code. Is this something that's no longer required or does Murk++ just not need it anymore?


It was never needed. AFAIU, it was to make sure the gcc compiler produced a certain instruction. I think it was done because debugging was getting messed up somehow otherwise. At least this is what I remember from the comments around the function. Hopefully debuggers and compilers have improved since then. Tyche?
23 Aug, 2007, Guest wrote in the 3rd comment:
Votes: 0
That's basically what I'm trying to find out too. If it was never needed, then why keep it around? The Merc team seemed to think it was important enough to leave behind a dire warning about removing it. But that was 14 years ago. It's not a huge thorn in anyone's side but if it's not needed then I'd like to get rid of it. I'm somewhat fanatical that way :)
23 Aug, 2007, Tyche wrote in the 4th comment:
Votes: 0
If the last line in a function is a call to another function a tail recursion optimization may occur where a jmp instruction is generated or the function is inlined rather than a new stack frame being created with a call. This causes gdb to not have the frame in the backtrace.

$ cat tail.c
#include <stdio.h>
void foo() {
rand(9);
}
int main() {
foo();
}

$ gcc -S -O3 tail.c; cat tail.s
.file "tail.c"
.text
.p2align 4,,15
.globl _foo
.def _foo; .scl 2; .type 32; .endef
_foo:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl $9, (%esp)
call _rand
leave
ret
.def ___main; .scl 2; .type 32; .endef
.p2align 4,,15
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl $16, %eax
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
call __alloca
call ___main
movl $9, (%esp) <—- foo inlined no stack frame created for call
call _rand <—-
leave
ret
.def _rand; .scl 3; .type 32; .endef

$ gcc -S -O2 tail.c; cat tail.s
.file "tail.c"
.text
.p2align 4,,15
.globl _foo
.def _foo; .scl 2; .type 32; .endef
_foo:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl $9, (%esp)
call _rand
leave
ret
.def ___main; .scl 2; .type 32; .endef
.p2align 4,,15
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl $16, %eax
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
call __alloca
call ___main
call _foo <—- foo not inlined
leave
ret
.def _rand; .scl 3; .type 32; .en


No it's not needed. And if you do compile and attempt to debug a program at O3 level, tail recursion optimization is the least of the odd things you'll see in gdb.
0.0/4