optimization causing invalid opcode exception
Posted: Sun Jul 10, 2016 4:15 pm
Link to code: https://github.com/io12/OS
My OS works fine when compiling with clang on -O0 and -O1, and also -O2 on gcc. All optimization levels above that cause an invalid opcode exception.
Register dump (clang):
eax=0x10000 ebx=0x0 ecx=0x8 edx=0x109000
esp=0x1088E0 ebp=0x8946 esi=0x10 edi=0x109000
cs=0x8 ds=0x10 ss=0x8946 es=0x10 fs=0x10 gs=0x10
eip=0x101803
0x101803 in malloc (from liballoc) in kernel.elf (clang):
0f 57 c0 xorps %xmm0,%xmm0
Register dump (gcc):
eax=0x1000 ebx=0x10B000 ecx=0x11B edx=0x11B
esp=0x10A934 ebp=0x10000 esi=0x8946 edi=0x10
cs=0x8 ds=0x10 ss=0x0 es=0x10 fs=0x10 gs=0x10
eip=0x101BFD
0x101bfd in malloc (from liballoc) in kernel.elf (gcc):
66 0f ef c0 pxor %xmm0,%xmm0
Xorps and pxor are not in the resulting kernel.elf with lower optimization levels. The area that the code fails on (I checked with gdb) is a line where a value is set to NULL. The problem fixed when I changed it to a memset call, but that caused the exception somewhere else.
Can someone give me a hint what the issue is?
My OS works fine when compiling with clang on -O0 and -O1, and also -O2 on gcc. All optimization levels above that cause an invalid opcode exception.
Register dump (clang):
eax=0x10000 ebx=0x0 ecx=0x8 edx=0x109000
esp=0x1088E0 ebp=0x8946 esi=0x10 edi=0x109000
cs=0x8 ds=0x10 ss=0x8946 es=0x10 fs=0x10 gs=0x10
eip=0x101803
0x101803 in malloc (from liballoc) in kernel.elf (clang):
0f 57 c0 xorps %xmm0,%xmm0
Register dump (gcc):
eax=0x1000 ebx=0x10B000 ecx=0x11B edx=0x11B
esp=0x10A934 ebp=0x10000 esi=0x8946 edi=0x10
cs=0x8 ds=0x10 ss=0x0 es=0x10 fs=0x10 gs=0x10
eip=0x101BFD
0x101bfd in malloc (from liballoc) in kernel.elf (gcc):
66 0f ef c0 pxor %xmm0,%xmm0
Xorps and pxor are not in the resulting kernel.elf with lower optimization levels. The area that the code fails on (I checked with gdb) is a line where a value is set to NULL. The problem fixed when I changed it to a memset call, but that caused the exception somewhere else.
Can someone give me a hint what the issue is?