[patch] Cleaning up amd64 kernel optimization options

Alexander Best arundel at freebsd.org
Thu Dec 22 19:25:49 UTC 2011


On Thu Dec 22 11, Dimitry Andric wrote:
> Hi,
> 
> I would like to ask some feedback on the attached patch, which cleans up
> the kernel optimization options for amd64.  This was touched upon
> earlier by Alexander Best in freebsd-toolchain, here:

i've been using such settings for a few months now and haven't noticed any
problems.

however bruce evans raised a good point (in a private mail). when you compile a
kernel without debugging enabled, -O2 is the default. if you experience issues,
and enable debugging, -O0 now becomes the default. in case the problems with
the kernel were caused by the -O2 option and aren't present with the -O0
option, the newly built kernel with debugging enabled will not help you fix the
problems. in that case you would need to set -O2 explicitly in CFLAGS. his
exact words were:

"
I don't like -O2 for anything.  However, if it is only a default, it is
not a problem provided it can be canceled easily.  And for debugging, you
want the default to be the same as without debugging, so that (by default)
you debug the same code that caused the problem.
"

however i don't think this is fixable. using -O0 for debuggable and
non-debuggable kernels will cause too much of a slowdown.

having -O2 as the default flag for non-debuggable kernels and -O2 -g for
debuggable kernels might cause situations, where debugging isn't possible,
where with -O0 -g it would have been.

so i guess although bruces concerns are valid, they are impossible to solve.

cheers.
alex

> 
> http://lists.freebsd.org/pipermail/freebsd-toolchain/2011-October/000270.html
> 
> What this patch attempts to fix is the following:
> - When you compile amd64 kernels for debug, they still get optimized
>   with "-O2 -frename-registers", which is almost certain to make
>   debugging miserable.  Optimizing at higher levels makes variables and
>   code move around, or disappear altogether.  About -frename-registers
>   the gcc documentation even says: "Depending on the debug information
>   format adopted by the target, however, it can make debugging
>   impossible, since variables will no longer stay in a ?home register?."
> - Clang doesn't support the -frename-registers option, so you get
>   harmless but annoying "warning: argument unused during compilation:
>   '-frename-registers'" messages during buildkernel.
> 
> The patch makes it so that:
> - For normal amd64 kernel builds, it uses "-O2 -frename-registers",
>   unless Clang is used, then it uses plain "-O2".
> - For debug amd64 kernel builds, it uses "-O", just like all the other
>   arches.




More information about the freebsd-current mailing list