OSDev.org

The Place to Start for Operating System Developers
It is currently Mon May 20, 2024 7:54 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: GCC doesnt work with -O0
PostPosted: Fri Nov 17, 2023 5:19 pm 
Offline
Member
Member

Joined: Tue Oct 10, 2023 7:40 pm
Posts: 52
When i compile my Kernel with no optimization flags or with -O0 (same thing), it randomly works/doesn't work or causes faults or print doesn't work or i get weird results from kmemcpy. it also causes the output to grow to 332k from 44k in size. I am clueless to what is going on... I'v tried "fixing" functions but nothing works, and all works fine with -O1, -O2, -O3, -Ofast and -Os.

Compile line from script:
~/opt/cross/bin/x86_64-elf-gcc -I./kheaders -c -s $1 -o $2 -mgeneral-regs-only -ffreestanding -O0 -mcmodel=large


Top
 Profile  
 
 Post subject: Re: GCC doesnt work with -O0
PostPosted: Fri Nov 17, 2023 6:17 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5173
I see you're not passing "-mno-red-zone" to your cross-compiler. If you have interrupts enabled, they'll corrupt the red zone (unless you use the IST for all interrupts, which is a questionable design choice). Optimizations tend to reduce usage of the red zone, so that might be why you haven't seen problems when optimizations are enabled.

I see you're also using the large code model instead of the kernel code model. Why is that?


Top
 Profile  
 
 Post subject: Re: GCC doesnt work with -O0
PostPosted: Fri Nov 17, 2023 6:22 pm 
Offline
Member
Member

Joined: Tue Oct 10, 2023 7:40 pm
Posts: 52
Funny thing it just kinda randomly does it... for some reason ld doesnt work with kernel
I will try the red zone flag, thank you


Top
 Profile  
 
 Post subject: Re: GCC doesnt work with -O0
PostPosted: Fri Nov 17, 2023 6:24 pm 
Offline
Member
Member

Joined: Tue Oct 10, 2023 7:40 pm
Posts: 52
Ok thank you, that seems to be the problem...but it was weird if i ran it several times it would fail once in a while even with no code changes.


Top
 Profile  
 
 Post subject: Re: GCC doesnt work with -O0
PostPosted: Fri Nov 17, 2023 6:26 pm 
Offline
Member
Member

Joined: Tue Oct 10, 2023 7:40 pm
Posts: 52
Probably from the clock interrupt.


Top
 Profile  
 
 Post subject: Re: GCC doesnt work with -O0
PostPosted: Fri Nov 17, 2023 6:31 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5173
Xeno wrote:
for some reason ld doesnt work with kernel

The reason is usually that the kernel code model requires your linker script to place your kernel between 0xFFFFFFFF80000000 and 0xFFFFFFFFFFFFFFFF, and your linker script probably doesn't do that.


Top
 Profile  
 
 Post subject: Re: GCC doesnt work with -O0
PostPosted: Fri Nov 17, 2023 6:31 pm 
Offline
Member
Member

Joined: Tue Oct 10, 2023 7:40 pm
Posts: 52
My kernel is loaded at 0xffffFA0000000000


Top
 Profile  
 
 Post subject: Re: GCC doesnt work with -O0
PostPosted: Fri Nov 17, 2023 6:32 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5173
Why? If you load it at 0xFFFFFFFF80000000 you can use the kernel code model, which will make your kernel smaller and faster.


Top
 Profile  
 
 Post subject: Re: GCC doesnt work with -O0
PostPosted: Fri Nov 17, 2023 6:35 pm 
Offline
Member
Member

Joined: Tue Oct 10, 2023 7:40 pm
Posts: 52
I have it maped there so that i can allocate the virtual memory above it for kernel data structures (page maps/memory bitmap etc) with all user data below
This is also for a method of memory allocation I designed, it uses a different design for virtual memory, then the typical idea


Top
 Profile  
 
 Post subject: Re: GCC doesnt work with -O0
PostPosted: Fri Nov 17, 2023 6:45 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5173
Why can't you allocate those kernel data structures at 0xFFFFFA0000000000 and link your kernel at (or above) 0xFFFFFFFF80000000?


Top
 Profile  
 
 Post subject: Re: GCC doesnt work with -O0
PostPosted: Fri Nov 17, 2023 9:43 pm 
Offline
Member
Member

Joined: Tue Oct 10, 2023 7:40 pm
Posts: 52
I might but i think it would conflict with my goals...I'll look into it


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 16 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