Potential GCC bug?

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.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Potential GCC bug?

Post 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
darkstart
Posts: 8
Joined: Fri Jul 18, 2008 8:50 am

Re: Potential GCC bug?

Post 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
:oops: 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

Code: Select all

add %esp, 16
from the cross compiler...
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Potential GCC bug?

Post 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

Code: Select all

add %esp, 16
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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Potential GCC bug?

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Potential GCC bug?

Post 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
darkstart
Posts: 8
Joined: Fri Jul 18, 2008 8:50 am

Re: Potential GCC bug?

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Potential GCC bug?

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Potential GCC bug?

Post 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.
darkstart
Posts: 8
Joined: Fri Jul 18, 2008 8:50 am

Re: Potential GCC bug?

Post 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??
froggey
Member
Member
Posts: 38
Joined: Tue Oct 17, 2006 10:21 pm
Location: Hampshire, UK

Re: Potential GCC bug?

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