GCC optimizations deleting my code

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
wolframio74
Posts: 2
Joined: Wed May 23, 2012 5:12 pm

GCC optimizations deleting my code

Post by wolframio74 »

Hello!

I have a little problem with gcc and it's aggresive optimizations "-O3".
I have an "idt" variable that I set up with the appropiate offset and limit of my idt table and then pass it's address to lidt like this:

Code: Select all

asm volatile ("lidt (%0)" : : "r"(&idt));
When I compile the code with "O3" optimizations GCC assumes that my "idt" variable is not being used anywhere, deletes the assignments to it, moves it's address into eax and outputs "lidt (%eax)", which is a little weird...
I can workaround the problem using a "noinline" load_idt() function but that's not very elegant.
I thought GCC was aware of the stuff I do with "extended asm" but it doesn't seem to be.

Any suggestions?
Thanks!!
wolframio74
Posts: 2
Joined: Wed May 23, 2012 5:12 pm

Re: GCC optimizations deleting my code

Post by wolframio74 »

That works! thanks! :D

But why does GCC think I'm not using the idt variable when I tell it to pass it's address in a register?

Thanks!
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: GCC optimizations deleting my code

Post by Owen »

I suspect the real reason is the surrounding code. I get a distinct smell of undefined behavior.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: GCC optimizations deleting my code

Post by gravaera »

We have only seen one line of code, and the produced result is consistent with what it is expected to do. I'm not sure how one can now deduce that the surrounding code is shady from having seen only one line of code that produces the expected result...?

--Peace out
gravaera
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Post Reply