variables optimized out
NGie Cooper
yaneurabeya at gmail.com
Sun Jan 3 18:24:46 UTC 2016
> On Jan 3, 2016, at 10:11, Joerg Sonnenberger <joerg at britannica.bec.de> wrote:
>
> On Sun, Jan 03, 2016 at 03:59:23PM +0100, Bertram Scharpf wrote:
>> Hi,
>>
>> On Sunday, 03. Jan 2016, 14:38:33 +0100, robbinson defau wrote:
>>> Im debugging some issues in the kernel and as the kernel is compiled by
>>> default with -O2, a lot of variables are optimized out. So i made changes
>>> to make.conf (CFLAGS and COPTFLAGS).\
>>>
>>> All builds fine, but I get the weirdest of panics that most certainly not
>>> happen with -O2. [...]
>>
>> I just had a look at "man make.conf" and that says:
>>
>> CFLAGS (str) Controls the compiler setting when compiling C code.
>> Optimization levels other than -O and -O2 are not sup‐
>> ported.
>>
>> At least to me this is a surprise. I'm really disappointed
>> about what programming style has become common.
>
> There are two strong historical reasons from GCC behavior:
> - a lot of the -O3 optimisations has been known to break questionable
> code
> - a lot of the warnings significantly change behavior depending on the
> optmizer.
>
> While the former is not a big problem for disabling optimisation, the
> latter certainly is. Note that with clang there is no difference between
> -O and -O2.
Hi Joerg,
We had some discussion on this a while ago internally at $work. clang optimizes a lot of variables away and doesn’t track them like later versions of gcc does (unfortunately 4.2.1 in base also lacks this capability): https://llvm.org/bugs/show_bug.cgi?id=23636 (clang lacks -ftracking[-assignments]). The only way you can reliably debug a program today is to compile code with `DEBUG_FLAGS="-g -O0”`, but that might change behavior of the code due to how it was optimized (and it might make things less efficient), so caveat emptor. You will definitely need to increase your stack space with the kernel for instance.
Hope this helps!
-NGie
More information about the freebsd-hackers
mailing list