GCC optimization removing my function call

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Cyao
Member
Member
Posts: 78
Joined: Tue Jun 07, 2022 11:23 am
Libera.chat IRC: Cyao
Location: France
Contact:

GCC optimization removing my function call

Post 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)
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: GCC optimization removing my function call

Post 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.
Cyao
Member
Member
Posts: 78
Joined: Tue Jun 07, 2022 11:23 am
Libera.chat IRC: Cyao
Location: France
Contact:

Re: GCC optimization removing my function call

Post 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
Post Reply