Page 1 of 1

GCC optimization removing my function call

Posted: Fri Nov 18, 2022 3:20 pm
by Cyao
Hello, somehow gcc removes my puts function from my code when optimizing, anyone knows why?

main.c: https://github.com/cheyao/AsmOS/blob/master/lib/main.c

You can also see from the elf file disasembly that the third call (puts) is gone
With -O0 https://github.com/cheyao/AsmOS/blob/master/O0.dis
With -O1 https://github.com/cheyao/AsmOS/blob/master/O1.dis

The only thing i changed that may effect this is changed "" to <> include brackets (and changed the file's directories but that shouldn't effect it)

Re: GCC optimization removing my function call

Posted: Fri Nov 18, 2022 3:35 pm
by Octocontrabass
GCC is performing tail call optimization. Notice how the optimized main function ends with a JMP instead of a RET.

If your code isn't working, the problem is unrelated to this optimization.

Re: GCC optimization removing my function call

Posted: Sat Nov 19, 2022 1:13 am
by Cyao
Octocontrabass wrote:GCC is performing tail call optimization. Notice how the optimized main function ends with a JMP instead of a RET.

If your code isn't working, the problem is unrelated to this optimization.
Ahhh ok, I thought the jump stuff had to do with other stuff