GCC doesnt work with -O0
GCC doesnt work with -O0
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
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
-
- Member
- Posts: 5560
- Joined: Mon Mar 25, 2013 7:01 pm
Re: GCC doesnt work with -O0
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?
I see you're also using the large code model instead of the kernel code model. Why is that?
Re: GCC doesnt work with -O0
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
I will try the red zone flag, thank you
Re: GCC doesnt work with -O0
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.
Re: GCC doesnt work with -O0
Probably from the clock interrupt.
-
- Member
- Posts: 5560
- Joined: Mon Mar 25, 2013 7:01 pm
Re: GCC doesnt work with -O0
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.Xeno wrote:for some reason ld doesnt work with kernel
Re: GCC doesnt work with -O0
My kernel is loaded at 0xffffFA0000000000
-
- Member
- Posts: 5560
- Joined: Mon Mar 25, 2013 7:01 pm
Re: GCC doesnt work with -O0
Why? If you load it at 0xFFFFFFFF80000000 you can use the kernel code model, which will make your kernel smaller and faster.
Re: GCC doesnt work with -O0
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
This is also for a method of memory allocation I designed, it uses a different design for virtual memory, then the typical idea
-
- Member
- Posts: 5560
- Joined: Mon Mar 25, 2013 7:01 pm
Re: GCC doesnt work with -O0
Why can't you allocate those kernel data structures at 0xFFFFFA0000000000 and link your kernel at (or above) 0xFFFFFFFF80000000?
Re: GCC doesnt work with -O0
I might but i think it would conflict with my goals...I'll look into it