OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Nov 24, 2020 8:27 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Crashes without -O3
PostPosted: Sun Oct 11, 2020 7:55 am 
Offline
Member
Member
User avatar

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 431
Hello,
In my kernel, at one point, I would get occasional #PFs and hangs. I compiled with -O3, and it works now. Why would -O3 fix this problem?
Thanks,
nexos

_________________
Working on NexBoot, a simple and lightweight GRUB replacement. and NexKe, a stable and fast microkernel. Part of the Nexware Project.


Top
 Profile  
 
 Post subject: Re: Crashes without -O3
PostPosted: Sun Oct 11, 2020 8:55 am 
Offline
Member
Member
User avatar

Joined: Sun Jan 17, 2016 7:57 am
Posts: 42
Are you on x86_64, and if so, have you setup the compiler to not use the red zone? https://wiki.osdev.org/Libgcc_without_red_zone


Top
 Profile  
 
 Post subject: Re: Crashes without -O3
PostPosted: Sun Oct 11, 2020 11:01 am 
Offline
Member
Member

Joined: Tue Aug 11, 2020 12:14 pm
Posts: 71
It's possible you have a buggy section of code somewhere that -O3 is optimizing into nothing, but that is triggering #PF when it's there.

This isn't a good example, because it's a useless function, but as an illustration:

Code:
void func(int *x) {
        int y;

        y = *x;
}

That would cause #PF if x is an invalid pointer, but if you use -O3, the entire function becomes a NOP. The optimizer decides since you didn't use y, there's no reason to set it.

What'd you have to do is 1) track whether your #PFs are happening in the same place(s), and 2) analyze that section of code with and without -O3 to see if you can tell what's going wrong. (if the #PFs are in random places, obviously that makes it harder to find)


Top
 Profile  
 
 Post subject: Re: Crashes without -O3
PostPosted: Sun Oct 11, 2020 11:26 am 
Offline
Member
Member
User avatar

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 431
What is strange is that it only does it occasionaly. I don't think libgcc was compiled with -mno-red-zone. The code probably got interrupted and it corrupted the stack.

_________________
Working on NexBoot, a simple and lightweight GRUB replacement. and NexKe, a stable and fast microkernel. Part of the Nexware Project.


Top
 Profile  
 
 Post subject: Re: Crashes without -O3
PostPosted: Mon Oct 12, 2020 1:09 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1014
nexos wrote:
What is strange is that it only does it occasionaly. I don't think libgcc was compiled with -mno-red-zone. The code probably got interrupted and it corrupted the stack.
I'm certain you have an UB somewhere. Things like "it works with -O0 but not with -O3 (or vice versa)" almost all the time caused by an UB somewhere. The optimizer generating code that occasionaly doesn't work also a good indicator for an UB.

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: Crashes without -O3
PostPosted: Mon Oct 12, 2020 3:10 pm 
Offline
Member
Member
User avatar

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 431
I meant it does it occasionaly with -O0, amd never with -O3. I probably had to do with the red zone. I realized today I wasn't passing -mno-red-zone to the compiler :shock: .

_________________
Working on NexBoot, a simple and lightweight GRUB replacement. and NexKe, a stable and fast microkernel. Part of the Nexware Project.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: foliagecanine, kzinti and 12 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