This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: nonfunctional.


On 10 Apr 2000, Per Lundberg wrote:

> -fomit-frame-pointer in combination with __attribute__ ((section
> (".text.init"))) seems to generate faulty code for this snippet:
> 
> static void __attribute__ ((section (".text.init"))) kernel_entry (void)
> {
>   multiboot_init ();
>   main (((u32 *) arguments_kernel)[0], (char **) arguments_kernel + 1);
>   while (1 == 1);
> }
> 
> The generated code looks like this:
> 
> 000000a4 <kernel_entry>:
>   a4:	83 ec 0c             	sub    $0xc,%esp
>   a7:	e8 fc ff ff ff       	call   a8 <kernel_entry+0x4>
>   ac:	83 c4 f8             	add    $0xfffffff8,%esp
>   af:	68 04 00 00 00       	push   $0x4
>   b4:	ff 35 00 00 00 00    	pushl  0x0
>   ba:	e8 fc ff ff ff       	call   bb <kernel_entry+0x17>
>   bf:	00 eb                	add    %ch,%bl
>   c1:	fe                   	.byte 0xfe
> 
> I have tried this with both gcc 2.95.1 and 2.95.2, and the bug seems
> to be be present in both compilers. Luckily, I found this by the
> "Invalid opcode" exception I got when I tried to boot the kernel. If I
> replace the while (1 == 1) with a function call, it works just
> fine. Also, if I remove -fomit-frame-pointer or let the section be put
> with the rest of the code, the bug disappears.
> 
> Any clues?

Somehow, you've told the assembler that section .text.init is not executable.
Compile your snippet with -S and look at the resulting assembly code, and
you'll see that the first occurence of ".section .text.init" has flags
"aw" rather than "ax".  You'll see a .align before the jmp corresponding
to "while (1 == 1)".  This .align emits a zero byte because the assembler
thinks .text.init is a data section.

-- 
Linuxcare.  Support for the Revolution.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]