OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 12:22 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Multitasking Bugs
PostPosted: Sat Aug 26, 2017 12:39 pm 
Offline
Member
Member

Joined: Fri Aug 19, 2016 10:28 pm
Posts: 360
Octocontrabass wrote:
simeonz wrote:
What do you mean by "free to optimize"? If you mean that "__attribute__((optimize("-fno-omit-frame-pointer")))" is not ANSI C, then you are obviously correct. But neither is "stack pointer". You couldn't busy loop without going outside the canonical C.

I mean that GCC is free to generate ESP-relative addresses regardless of optimization parameters, and there is no specific guarantee that -fno-omit-frame-pointer will prevent it from doing so.
What do you mean by "no specific guarantee"? Doesn't gcc currently guarantee the exact semantics of those options, even if the disabling flags are not always described explicitly. But take "fno-defer-pop" for example, which is documented. It has strict meaning. Not like say, using "inline" specifier to a function definition. I am not questioning that these options may not be reliable for future use, but even the linux kernel uses "-fno-omit-frame-pointer" to get proper traces, and may be a few other things.

Octocontrabass wrote:
simeonz wrote:
You relax the constraint and it happens to work. How could remark about behavior volatility and offer this suggestion? I agree that using the operand constraints is a better fix per se. "=r" would be a stricter constraint, and could/should work.

Relaxing the constraint is an optimization. The bug fix is ensuring that ESP-relative addresses will be calculated correctly if GCC chooses to use them. Intel specifies that POP with a memory operand using ESP as a base register will increment ESP before calculating the effective address. Combined with the previous decrement from PUSH, the result is that an effective address with ESP will be calculated the way GCC expects.
The subtle change didn't capture my attention. Yes, this will work better. Again, undeniably better solution then mine.


Top
 Profile  
 
 Post subject: Re: Multitasking Bugs
PostPosted: Sat Aug 26, 2017 12:50 pm 
Offline
Member
Member

Joined: Thu Jul 05, 2007 8:58 am
Posts: 223
simeonz wrote:
Octocontrabass wrote:
simeonz wrote:
What do you mean by "free to optimize"? If you mean that "__attribute__((optimize("-fno-omit-frame-pointer")))" is not ANSI C, then you are obviously correct. But neither is "stack pointer". You couldn't busy loop without going outside the canonical C.

I mean that GCC is free to generate ESP-relative addresses regardless of optimization parameters, and there is no specific guarantee that -fno-omit-frame-pointer will prevent it from doing so.
What do you mean by "no specific guarantee"? Doesn't gcc currently guarantee the exact semantics of those options, even if the disabling flags are not always described explicitly. But take "fno-defer-pop" for example, which is documented. It has strict meaning. Not like say, using "inline" specifier to a function definition. I am not questioning that these options may not be reliable for future use, but even the linux kernel uses "-fno-omit-frame-pointer" to get proper traces, and may be a few other things.

GCC does guarantee semantics of those options, at least for the current version. The problem is that the option you currently use does not guarantee what it thinks you guarantees. It only guarantees that ebp functions as the frame pointer. IT DOES NOT guarantee that gcc will actually use ebp to access local variables. If it thinks the resulting code might be more efficient using esp-relative accesses, it will use that as it wants. Hence, you are still not sure it will work correctly.


Top
 Profile  
 
 Post subject: Re: Multitasking Bugs
PostPosted: Sat Aug 26, 2017 1:45 pm 
Offline
Member
Member

Joined: Fri Aug 19, 2016 10:28 pm
Posts: 360
davidv1992 wrote:
simeonz wrote:
Octocontrabass wrote:
I mean that GCC is free to generate ESP-relative addresses regardless of optimization parameters, and there is no specific guarantee that -fno-omit-frame-pointer will prevent it from doing so.
What do you mean by "no specific guarantee"? Doesn't gcc currently guarantee the exact semantics of those options, even if the disabling flags are not always described explicitly. But take "fno-defer-pop" for example, which is documented. It has strict meaning. Not like say, using "inline" specifier to a function definition. I am not questioning that these options may not be reliable for future use, but even the linux kernel uses "-fno-omit-frame-pointer" to get proper traces, and may be a few other things.

GCC does guarantee semantics of those options, at least for the current version. The problem is that the option you currently use does not guarantee what it thinks you guarantees. It only guarantees that ebp functions as the frame pointer. IT DOES NOT guarantee that gcc will actually use ebp to access local variables. If it thinks the resulting code might be more efficient using esp-relative accesses, it will use that as it wants. Hence, you are still not sure it will work correctly.
I cannot coerce it to fail at the moment, but your statement sounds correct. In other words, there is no way to perform alloca style adjustment to esp midway a C frame. Well, that is unfortunate. There are certain cases where this is convenient (such as dynamically performing stack realignment from C), and I was under the impression that it works, but apparently I got lucky. Looking at the glibc headers, I see that alloca is declared as __builtin_alloca, which explains how it manages to coerce the compiler to do what my use of this option is apparently not able to do. Thanks for the clarification to both of you.

P.S. To the OP if you are reading this. To keep the behavior stable, do remove the function attribute and use some of the other proposed solutions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], SemrushBot [Bot] and 130 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group