2010-11-29 08:48:30

by Hui Zhu

[permalink] [raw]
Subject: Re: [hellogcc] Re: [PATCH] Built kernel without -O2 option

In this way, you will got a lot of error.

Hui

On Mon, Nov 29, 2010 at 16:41, ?dz? <[email protected]> wrote:
> does not need change kernel,just write a shell mycc as bellow:
>
> #!/bin/sh
> gcc "$@" -O0
>
> then
>
> make CC=./mycc vmlinux
>
> Hui Zhu said
>
> On Mon, Nov 29, 2010 at 16:16, Am??rico Wang <[email protected]>
> wrote:
>
>
> On Mon, Nov 29, 2010 at 11:56:15AM +0800, Hui Zhu wrote:
>
>
> Hi,
>
> Now, there are a lot of ways to debug the Linux kernel with GDB, like
> qemu, kgtp or kgdb and so on.
> But the developer more like add a printk. It have a lot of reason, a big one
> is:
> (gdb) p ret
> $3 = <value optimized out>
> And the code execution order is not right.
>
> This is becuase the Kernel is bult with gcc -O2. Gcc will not
> generate enough debug message with file with -O2.
> So GDB cannot work very well with Linux kernel.
>
> So I make a patch that add a option in "Kernel hacking" called "Close
> GCC optimization". It will make kernel be built without -O2.
>
> I built and use it in i386 and x86_64. I will try to make it OK in other
> arch.
>
>
>
> The problem is that some functions _have to_ be inlined and gcc without -O2
> doesn't inline them. Have check all the cases? I doubt.
>
>
> If they really need O2, I set them to O2.
> Actually, this is the main work, find out the file that need the O2. :)
>
> For example:
> ifdef CONFIG_CC_CLOSE_OPTIMIZATION
> CFLAGS_fpu.o += -O2
> CFLAGS_aesni-intel_glue.o += -O2
> CFLAGS_ghash-clmulni-intel_glue.o += -O2
> endif
>
> And I will try to find more of these type files.
>
>
>
> Also, what is size of vmlinux before applying your patch and after that?
> Does it increase too much?
>
>
>
> Before the patch:
> ls -alh vmlinuz-2.6.37-rc3+
> -rw-r--r-- 1 root root 4.1M 2010-11-25 12:02 vmlinuz-2.6.37-rc3+
> ls -alh b26no/vmlinux
> -rwxr-xr-x 1 teawater teawater 135M 2010-11-25 13:31 b26no/vmlinux
>
> After the patch:
> ls -alh vmlinuz-2.6.37-rc3debug+
> -rw-r--r-- 1 root root 4.6M 2010-11-25 14:02 vmlinuz-2.6.37-rc3debug+
> ls -alh b26/vmlinux
> -rwxr-xr-x 1 teawater teawater 140M 2010-11-25 11:14 b26/vmlinux
>
> Thanks,
> Hui
>
>
>
>
> --
>
> ?dz? [email protected]
>
> 2010?? 11?? 29?? ????һ 16:35:38 CST


2010-11-29 08:55:36

by Steven

[permalink] [raw]
Subject: Re: [hellogcc] Re: [PATCH] Built kernel without -O2 option

I replace -O2 with -O0 in Makefile of kernel source code root directory?
I just do it and my gdb works well with this method.

You mean it is not enough?

Steven

On Mon, 2010-11-29 at 16:47 +0800, Hui Zhu wrote:
> In this way, you will got a lot of error.
>
> Hui
>
> On Mon, Nov 29, 2010 at 16:41, 乔崇 <[email protected]> wrote:
> > does not need change kernel,just write a shell mycc as bellow:
> >
> > #!/bin/sh
> > gcc "$@" -O0
> >
> > then
> >
> > make CC=./mycc vmlinux
> >
> > Hui Zhu said
> >
> > On Mon, Nov 29, 2010 at 16:16, Américo Wang <[email protected]>
> > wrote:
> >
> >
> > On Mon, Nov 29, 2010 at 11:56:15AM +0800, Hui Zhu wrote:
> >
> >
> > Hi,
> >
> > Now, there are a lot of ways to debug the Linux kernel with GDB, like
> > qemu, kgtp or kgdb and so on.
> > But the developer more like add a printk. It have a lot of reason, a big one
> > is:
> > (gdb) p ret
> > $3 = <value optimized out>
> > And the code execution order is not right.
> >
> > This is becuase the Kernel is bult with gcc -O2. Gcc will not
> > generate enough debug message with file with -O2.
> > So GDB cannot work very well with Linux kernel.
> >
> > So I make a patch that add a option in "Kernel hacking" called "Close
> > GCC optimization". It will make kernel be built without -O2.
> >
> > I built and use it in i386 and x86_64. I will try to make it OK in other
> > arch.
> >
> >
> >
> > The problem is that some functions _have to_ be inlined and gcc without -O2
> > doesn't inline them. Have check all the cases? I doubt.
> >
> >
> > If they really need O2, I set them to O2.
> > Actually, this is the main work, find out the file that need the O2. :)
> >
> > For example:
> > ifdef CONFIG_CC_CLOSE_OPTIMIZATION
> > CFLAGS_fpu.o += -O2
> > CFLAGS_aesni-intel_glue.o += -O2
> > CFLAGS_ghash-clmulni-intel_glue.o += -O2
> > endif
> >
> > And I will try to find more of these type files.
> >
> >
> >
> > Also, what is size of vmlinux before applying your patch and after that?
> > Does it increase too much?
> >
> >
> >
> > Before the patch:
> > ls -alh vmlinuz-2.6.37-rc3+
> > -rw-r--r-- 1 root root 4.1M 2010-11-25 12:02 vmlinuz-2.6.37-rc3+
> > ls -alh b26no/vmlinux
> > -rwxr-xr-x 1 teawater teawater 135M 2010-11-25 13:31 b26no/vmlinux
> >
> > After the patch:
> > ls -alh vmlinuz-2.6.37-rc3debug+
> > -rw-r--r-- 1 root root 4.6M 2010-11-25 14:02 vmlinuz-2.6.37-rc3debug+
> > ls -alh b26/vmlinux
> > -rwxr-xr-x 1 teawater teawater 140M 2010-11-25 11:14 b26/vmlinux
> >
> > Thanks,
> > Hui
> >
> >
> >
> >
> > --
> >
> > 乔崇 [email protected]
> >
> > 2010年 11月 29日 星期一 16:35:38 CST

2010-11-29 08:58:21

by Hui Zhu

[permalink] [raw]
Subject: Re: [hellogcc] Re: [PATCH] Built kernel without -O2 option

On Mon, Nov 29, 2010 at 16:55, Steven <[email protected]> wrote:
> I replace -O2 with -O0 in Makefile of kernel source code root directory?
> I just do it and my gdb works well with this method.
>
> You mean it is not enough?
>
> Steven

Yes.

>
> On Mon, 2010-11-29 at 16:47 +0800, Hui Zhu wrote:
>> In this way, you will got a lot of error.
>>
>> Hui
>>
>> On Mon, Nov 29, 2010 at 16:41, ?dz? <[email protected]> wrote:
>> > does not need change kernel,just write a shell mycc as bellow:
>> >
>> > #!/bin/sh
>> > gcc "$@" -O0
>> >
>> > then
>> >
>> > make CC=./mycc vmlinux
>> >
>> > Hui Zhu said
>> >
>> > On Mon, Nov 29, 2010 at 16:16, Am??rico Wang <[email protected]>
>> > wrote:
>> >
>> >
>> > On Mon, Nov 29, 2010 at 11:56:15AM +0800, Hui Zhu wrote:
>> >
>> >
>> > Hi,
>> >
>> > Now, there are a lot of ways to debug the Linux kernel with GDB, like
>> > qemu, kgtp or kgdb and so on.
>> > But the developer more like add a printk. It have a lot of reason, a big one
>> > is:
>> > (gdb) p ret
>> > $3 = <value optimized out>
>> > And the code execution order is not right.
>> >
>> > This is becuase the Kernel is bult with gcc -O2. Gcc will not
>> > generate enough debug message with file with -O2.
>> > So GDB cannot work very well with Linux kernel.
>> >
>> > So I make a patch that add a option in "Kernel hacking" called "Close
>> > GCC optimization". It will make kernel be built without -O2.
>> >
>> > I built and use it in i386 and x86_64. I will try to make it OK in other
>> > arch.
>> >
>> >
>> >
>> > The problem is that some functions _have to_ be inlined and gcc without -O2
>> > doesn't inline them. Have check all the cases? I doubt.
>> >
>> >
>> > If they really need O2, I set them to O2.
>> > Actually, this is the main work, find out the file that need the O2. :)
>> >
>> > For example:
>> > ifdef CONFIG_CC_CLOSE_OPTIMIZATION
>> > CFLAGS_fpu.o += -O2
>> > CFLAGS_aesni-intel_glue.o += -O2
>> > CFLAGS_ghash-clmulni-intel_glue.o += -O2
>> > endif
>> >
>> > And I will try to find more of these type files.
>> >
>> >
>> >
>> > Also, what is size of vmlinux before applying your patch and after that?
>> > Does it increase too much?
>> >
>> >
>> >
>> > Before the patch:
>> > ls -alh vmlinuz-2.6.37-rc3+
>> > -rw-r--r-- 1 root root 4.1M 2010-11-25 12:02 vmlinuz-2.6.37-rc3+
>> > ls -alh b26no/vmlinux
>> > -rwxr-xr-x 1 teawater teawater 135M 2010-11-25 13:31 b26no/vmlinux
>> >
>> > After the patch:
>> > ls -alh vmlinuz-2.6.37-rc3debug+
>> > -rw-r--r-- 1 root root 4.6M 2010-11-25 14:02 vmlinuz-2.6.37-rc3debug+
>> > ls -alh b26/vmlinux
>> > -rwxr-xr-x 1 teawater teawater 140M 2010-11-25 11:14 b26/vmlinux
>> >
>> > Thanks,
>> > Hui
>> >
>> >
>> >
>> >
>> > --
>> >
>> > ?dz? [email protected]
>> >
>> > 2010?? 11?? 29?? ????һ 16:35:38 CST
>
>

2010-11-29 09:45:26

by 乔崇

[permalink] [raw]
Subject: Re: [hellogcc] Re: [PATCH] Built kernel without -O2 option

Hui Zhu д??:
> In this way, you will got a lot of error.
>
> Hui
>
> On Mon, Nov 29, 2010 at 16:41, ?dz? <[email protected]> wrote:
>
>> does not need change kernel,just write a shell mycc as bellow:
>>
>> #!/bin/sh
>> gcc "$@" -O0
>>
>>
change mycc to this will work,:)

#!/bin/sh
gcc "$@" -O0 ||
gcc "$@" -O1 ||
gcc "$@"


>> then
>>
>> make CC=./mycc vmlinux
>>
>> Hui Zhu said
>>
>> On Mon, Nov 29, 2010 at 16:16, Am??rico Wang <[email protected]>
>> wrote:
>>
>>
>> On Mon, Nov 29, 2010 at 11:56:15AM +0800, Hui Zhu wrote:
>>
>>
>> Hi,
>>
>> Now, there are a lot of ways to debug the Linux kernel with GDB, like
>> qemu, kgtp or kgdb and so on.
>> But the developer more like add a printk. It have a lot of reason, a big one
>> is:
>> (gdb) p ret
>> $3 = <value optimized out>
>> And the code execution order is not right.
>>
>> This is becuase the Kernel is bult with gcc -O2. Gcc will not
>> generate enough debug message with file with -O2.
>> So GDB cannot work very well with Linux kernel.
>>
>> So I make a patch that add a option in "Kernel hacking" called "Close
>> GCC optimization". It will make kernel be built without -O2.
>>
>> I built and use it in i386 and x86_64. I will try to make it OK in other
>> arch.
>>
>>
>>
>> The problem is that some functions _have to_ be inlined and gcc without -O2
>> doesn't inline them. Have check all the cases? I doubt.
>>
>>
>> If they really need O2, I set them to O2.
>> Actually, this is the main work, find out the file that need the O2. :)
>>
>> For example:
>> ifdef CONFIG_CC_CLOSE_OPTIMIZATION
>> CFLAGS_fpu.o += -O2
>> CFLAGS_aesni-intel_glue.o += -O2
>> CFLAGS_ghash-clmulni-intel_glue.o += -O2
>> endif
>>
>> And I will try to find more of these type files.
>>
>>
>>
>> Also, what is size of vmlinux before applying your patch and after that?
>> Does it increase too much?
>>
>>
>>
>> Before the patch:
>> ls -alh vmlinuz-2.6.37-rc3+
>> -rw-r--r-- 1 root root 4.1M 2010-11-25 12:02 vmlinuz-2.6.37-rc3+
>> ls -alh b26no/vmlinux
>> -rwxr-xr-x 1 teawater teawater 135M 2010-11-25 13:31 b26no/vmlinux
>>
>> After the patch:
>> ls -alh vmlinuz-2.6.37-rc3debug+
>> -rw-r--r-- 1 root root 4.6M 2010-11-25 14:02 vmlinuz-2.6.37-rc3debug+
>> ls -alh b26/vmlinux
>> -rwxr-xr-x 1 teawater teawater 140M 2010-11-25 11:14 b26/vmlinux
>>
>> Thanks,
>> Hui
>>
>>
>>
>>
>> --
>>
>> ?dz? [email protected]
>>
>> 2010?? 11?? 29?? ????һ 16:35:38 CST
>>
>
>
>


--

?dz? [email protected]
??о?пƼ??????????????޹?˾
office:010-62600855-615
mobile:13521990614

2010?? 11?? 29?? ????һ 17:38:14 CST

2010-11-29 18:11:12

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: [hellogcc] Re: [PATCH] Built kernel without -O2 option

On Mon, 29 Nov 2010 17:45:15 +0800, 乔崇 said:

> change mycc to this will work,:)
>
> #!/bin/sh
> gcc "$@" -O0 ||
> gcc "$@" -O1 ||
> gcc "$@"

That may result in issues - the problem is that there are places in the kernel
where 'gcc -O0' will *compile* cleanly, but not actually *run* correctly.


Attachments:
(No filename) (227.00 B)

2010-11-29 18:34:57

by Steven J. Magnani

[permalink] [raw]
Subject: Re: [hellogcc] Re: [PATCH] Built kernel without -O2 option

On Mon, 2010-11-29 at 13:10 -0500, [email protected] wrote:
> On Mon, 29 Nov 2010 17:45:15 +0800, 乔崇 said:
>
> > change mycc to this will work,:)
> >
> > #!/bin/sh
> > gcc "$@" -O0 ||
> > gcc "$@" -O1 ||
> > gcc "$@"
>
> That may result in issues - the problem is that there are places in the kernel
> where 'gcc -O0' will *compile* cleanly, but not actually *run* correctly.
>

There may be arch-specific places that cannot be made to run -O0.
See this thread from a few years ago:

http://www.spinics.net/lists/arm-kernel/msg24836.html

------------------------------------------------------------------------
Steven J. Magnani "I claim this network for MARS!
http://www.digidescorp.com Earthling, return my space modulator!"

#include <standard.disclaimer>

2010-11-29 22:03:57

by Alexey Dobriyan

[permalink] [raw]
Subject: Re: [hellogcc] Re: [PATCH] Built kernel without -O2 option

On Mon, Nov 29, 2010 at 01:10:29PM -0500, [email protected] wrote:
> That may result in issues - the problem is that there are places in the kernel
> where 'gcc -O0' will *compile* cleanly, but not actually *run* correctly.

Since nobody (no-bo-dy) runs kernel with -O0, I'd suggest original
poster to learn how to debug kernel with constrained information.

I'll be most certainly faster. :^)

2010-12-01 13:22:09

by Hui Zhu

[permalink] [raw]
Subject: Re: [hellogcc] Re: [PATCH] Built kernel without -O2 option

On Tue, Nov 30, 2010 at 06:03, Alexey Dobriyan <[email protected]> wrote:
> On Mon, Nov 29, 2010 at 01:10:29PM -0500, [email protected] wrote:
>> That may result in issues - the problem is that there are places in the kernel
>> where 'gcc -O0' will *compile* cleanly, but not actually *run* correctly.
>
> Since nobody (no-bo-dy) runs kernel with -O0, I'd suggest original
> poster to learn how to debug kernel with constrained information.
>
> I'll be most certainly faster. :^)
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at ?http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at ?http://www.tux.org/lkml/
>

Do you know Linux kernel cannot be built with "gcc -O0" now?
I think you should said "Since nobody (no-bo-dy) don't want built
kernel with -O0".

But how you know all the people's idea? :)

Thanks,
Hui

2010-12-01 15:42:45

by Jovi Zhang

[permalink] [raw]
Subject: Re: [hellogcc] Re: [PATCH] Built kernel without -O2 option

Please don't use Chinese word in this mailing list, maybe somebody
need to read LKML guideline firstly.

Does this patch have many use case upon it? if there have many use
case, maybe we can worth to do it, otherwise it maybe need to
consider..., as we known, there have many person debug kernel just
using -O2 or kdb, etc...
we need to think once bring this config option, there will have so
many maintain work on it, every maintainer need to care for their
commit file to make sure the file can work with this -O0 mode.

If there have some files missed to support with the -O0 mode, the
kernel will not stable(also it have a little hard to find which
file/function cause unstable), and the unstable kernel is not
everybody want to see.

>> +ifdef CONFIG_CC_CLOSE_OPTIMIZATION
>> +CFLAGS_process_$(BITS).o       += -O2
>> +CFLAGS_entry_$(BITS).o         += -O2
>> +CFLAGS_traps.o                 += -O2
>> +CFLAGS_i387.o                  += -O2
>> +CFLAGS_xsave.o                 += -O2
>> +CFLAGS_hpet.o                  += -O2

CONFIG_CC_CLOSE_OPTIMIZATION really misunderstand user in here with adding -O2.

   Thanks.