Page 2 of 2
Re: Potential GCC bug?
Posted: Tue Oct 28, 2008 4:55 am
by jal
darkstart wrote:I've heard of it, just never actually used it before.
That's a mildly ignorant remark, since
everyone using a computer has used two's complement (and don't start getting smart on me about only using floats or 60 year old computers...).
I think the DWORD PTR [%esp+12] is a pointer to the cr0 register.
Err... I'm not sure whether this is another display of total ignorance of the machine you are working with, or just plain stupidity (or both). Really, a memory pointer pointing to a register???
JAL
Re: Potential GCC bug?
Posted: Tue Oct 28, 2008 4:10 pm
by darkstart
jal wrote:darkstart wrote:I've heard of it, just never actually used it before.
That's a mildly ignorant remark, since
everyone using a computer has used two's complement (and don't start getting smart on me about only using floats or 60 year old computers...).
I meant I haven't used it in day to day applications programming.
jal wrote:darkstart wrote:I think the DWORD PTR [%esp+12] is a pointer to the cr0 register.
Err... I'm not sure whether this is another display of total ignorance of the machine you are working with, or just plain stupidity (or both). Really, a memory pointer pointing to a register???
JAL

My bad, my thinking sounds retarded looking at it that way. I'm just going to paste the whole function from GAS, it might help:
Code: Select all
switch_page_dir:
sub %esp, 16
mov %eax, DWORD PTR [%esp+20]
mov DWORD PTR current_dir, %eax
mov %eax, DWORD PTR [%esp+20]
add %eax, 4096
/APP
mov %eax, %cr3
mov %cr0, %eax
/NO_APP
mov DWORD PTR [%esp+12], %eax
or DWORD PTR [%esp+12], -2147483648
mov %eax, DWORD PTR [%esp+12]
/APP
mov %eax, %cr0
/NO_APP
add %esp, 16
ret
.size switch_page_dir, .-switch_page_dir
I'm going to assume that the
/APP and
/NOAPP are what gcc uses to enclose inline assembly?
EDIT: bochs dies on
from the cross compiler...
Re: Potential GCC bug?
Posted: Thu Oct 30, 2008 10:16 am
by jal
darkstart wrote:[I'm going to assume that the /APP and /NOAPP are what gcc uses to enclose inline assembly?
That's indeed what a quick Google tells me.
EDIT: bochs dies on
from the cross compiler...
I'd say that is impossible. No doubt it is chocking on the ret, as you do something with page dirs, the new page dir will not have a valid page for the return address?
JAL
Re: Potential GCC bug?
Posted: Fri Oct 31, 2008 3:58 am
by Combuster
It will choke on the instruction after the cr0 load if paging got turned on and the tables are broken (or turned off and things aren't identity mapped) - both give undefined results on real hardware. In this case I expect it to pagefault on the page holding the code.
Re: Potential GCC bug?
Posted: Fri Oct 31, 2008 4:50 am
by jal
Combuster wrote:It will choke on the instruction after the cr0 load if paging got turned on and the tables are broken (or turned off and things aren't identity mapped) - both give undefined results on real hardware. In this case I expect it to pagefault on the page holding the code.
Yes of course, stupid me, the code itself will not be reachable anymore...
JAL
Re: Potential GCC bug?
Posted: Fri Oct 31, 2008 2:49 pm
by darkstart
Combuster wrote:It will choke on the instruction after the cr0 load if paging got turned on and the tables are broken (or turned off and things aren't identity mapped) - both give undefined results on real hardware. In this case I expect it to pagefault on the page holding the code.
So then, would this mean that however the cross-compiler is compiling the code is doing something wrong? I'm going to try a different GCC and binutils version and see how that changes things.
Re: Potential GCC bug?
Posted: Sat Nov 01, 2008 5:47 am
by Combuster
One lesson you'll apparently need to know
The compiler is *never* wrong. All the GBs of source that is linux and its apps compiles and runs off that compiler without problems. And you really expect that you do something that causes the compiler to mess up on you?
Blaming the compiler is a way of saying "My code is wrong but I stubbornly refuse to admit that I made a mistake"
In other words: your paging code is wrong.
Re: Potential GCC bug?
Posted: Sat Nov 01, 2008 5:47 am
by JamesM
darkstart wrote:Combuster wrote:It will choke on the instruction after the cr0 load if paging got turned on and the tables are broken (or turned off and things aren't identity mapped) - both give undefined results on real hardware. In this case I expect it to pagefault on the page holding the code.
So then, would this mean that however the cross-compiler is compiling the code is doing something wrong? I'm going to try a different GCC and binutils version and see how that changes things.
No. Stop blaming the toolkit and blame your own code. All
my code works fine on the toolchain you mentioned.
Re: Potential GCC bug?
Posted: Sun Nov 02, 2008 1:29 pm
by darkstart
Then how does that explain the fact that my distro's compiler's code works fine and when I use the cross-compiler, it dies??
Re: Potential GCC bug?
Posted: Sun Nov 02, 2008 4:00 pm
by froggey
darkstart wrote:Then how does that explain the fact that my distro's compiler's code works fine and when I use the cross-compiler, it dies??
Your code relies on the behaviour of your distro's compiler. It has a bug that happens to be unmasked by whatever the cross-compiler is doing differently. For example the code could be accidentally overflowing a buffer, but because of the way compiler A orders the code it doesn't matter, but compiler B is orders the code in such a way that the overflow does matter and causes a crash.
But if you really are still convinced that it's a gcc bug (99% chance is isn't) then you should find out what the cross-compiler is doing differently, reduce it down to a simple test case and submit a bug report. Superficial changes in the way the assembly is output (like what you mentioned in the first post) won't have an effect on the problem and can be disregarded.