Skip to content

compilers/gnu: set level 0 optimization to '-O0'#9287

Merged
jpakkane merged 1 commit intomesonbuild:masterfrom
dcbaker:submit/gcc-opt-0
Mar 2, 2022
Merged

compilers/gnu: set level 0 optimization to '-O0'#9287
jpakkane merged 1 commit intomesonbuild:masterfrom
dcbaker:submit/gcc-opt-0

Conversation

@dcbaker
Copy link
Member

@dcbaker dcbaker commented Sep 21, 2021

GCC with optimization set to 0 does not actually result in no
optimizations, which can be annoying when trying to use a debugger like
gdb, and finding that your variable has been optimized out. We already
do this with clang, so gcc is a bit of an outlier here.

GCC with optimization set to 0 does not actually result in no
optimizations, which can be annoying when trying to use a debugger like
gdb, and finding that your variable has been optimized out. We already
do this with clang, so gcc is a bit of an outlier here.
@codecov
Copy link

codecov bot commented Sep 21, 2021

Codecov Report

Merging #9287 (926dac8) into master (68eca11) will increase coverage by 3.12%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9287      +/-   ##
==========================================
+ Coverage   66.85%   69.97%   +3.12%     
==========================================
  Files         386      193     -193     
  Lines       85062    42593   -42469     
  Branches    17551     8788    -8763     
==========================================
- Hits        56869    29806   -27063     
+ Misses      23401    10348   -13053     
+ Partials     4792     2439    -2353     
Impacted Files Coverage Δ
mesonbuild/compilers/mixins/gnu.py 82.93% <ø> (ø)
mesonbuild/scripts/vcstagger.py 87.50% <0.00%> (-4.17%) ⬇️
templates/cudatemplates.py
modules/hotdoc.py
munstable_coredata.py
templates/objcpptemplates.py
compilers/objc.py
compilers/mixins/arm.py
interpreterbase/helpers.py
compilers/mixins/compcert.py
... and 186 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 68eca11...926dac8. Read the comment docs.

@eli-schwartz
Copy link
Member

eli-schwartz commented Sep 23, 2021

So which optimization level is the "don't do anything" option now? (Thinking of e.g. --buildtype=plain here....)

From the GCC manpage:

-O0 Reduce compilation time and make debugging produce the expected results.  This is the default.

Is the manpage lying?

@dcbaker
Copy link
Member Author

dcbaker commented Sep 23, 2021

I see a difference with gcc 10.3 on nixos, possibly they're patching things?

Which seems likely since they're also setting -D_FORTIFY_SOURCE, which requires at least some optimizations

@dcbaker
Copy link
Member Author

dcbaker commented Sep 24, 2021

Still, it seems better to explicitly set the value than depend on it being implicitly set, especially when in (at least one case) not setting results in not -O0

@jpakkane
Copy link
Member

If memory serves we did use to use -O0 but then we stopped doing that because it caused some problems.

@dcbaker
Copy link
Member Author

dcbaker commented Sep 29, 2021

I can't find that, all I could find is that when we split the buildtypes into debug and optimization this silently disapeared. The combined options had ['-O0', '-g'], and the split options only put -g in the debug options. There's no comments saying that there were problems with '-O0'. At one point we set '-Og', which did have problems because it was new in gcc 4.8.

#3489

@dcbaker dcbaker added this to the 0.60.0 milestone Sep 30, 2021
@eli-schwartz eli-schwartz removed this from the 0.60.0 milestone Oct 27, 2021
@dcbaker dcbaker added this to the 0.61.0 milestone Nov 23, 2021
@nirbheek nirbheek modified the milestones: 0.61.0, 0.62.0 Jan 10, 2022
@jpakkane jpakkane merged commit f9bfeb2 into mesonbuild:master Mar 2, 2022
@dcbaker dcbaker deleted the submit/gcc-opt-0 branch March 2, 2022 18:03
@ajs124 ajs124 mentioned this pull request Jul 11, 2022
13 tasks
jtojnar added a commit to jtojnar/meson that referenced this pull request Jul 12, 2022
mesonbuild#9287 changed the `optimization=0`
to pass `-O0` to the compiler. This change is reasonable by itself
but unfortunately, it breaks `buildtype=plain`, which promises
that “no extra build flags are used”.

`buildtype=plain` is important for distros like NixOS,
which manage compiler flags for optimization and hardening
themselves.

Let’s introduce a new optimization level that does nothing
and set it as the default for `buildtype=plain`.
jtojnar added a commit to jtojnar/meson that referenced this pull request Jul 12, 2022
mesonbuild#9287 changed the `optimization=0`
to pass `-O0` to the compiler. This change is reasonable by itself
but unfortunately, it breaks `buildtype=plain`, which promises
that “no extra build flags are used”.

`buildtype=plain` is important for distros like NixOS,
which manage compiler flags for optimization and hardening
themselves.

Let’s introduce a new optimization level that does nothing
and set it as the default for `buildtype=plain`.
jtojnar added a commit to jtojnar/meson that referenced this pull request Jul 12, 2022
mesonbuild#9287 changed the `optimization=0`
to pass `-O0` to the compiler. This change is reasonable by itself
but unfortunately, it breaks `buildtype=plain`, which promises
that “no extra build flags are used”.

`buildtype=plain` is important for distros like NixOS,
which manage compiler flags for optimization and hardening
themselves.

Let’s introduce a new optimization level that does nothing
and set it as the default for `buildtype=plain`.
jtojnar added a commit to jtojnar/meson that referenced this pull request Jul 12, 2022
mesonbuild#9287 changed the `optimization=0`
to pass `-O0` to the compiler. This change is reasonable by itself
but unfortunately, it breaks `buildtype=plain`, which promises
that “no extra build flags are used”.

`buildtype=plain` is important for distros like NixOS,
which manage compiler flags for optimization and hardening
themselves.

Let’s introduce a new optimization level that does nothing
and set it as the default for `buildtype=plain`.
jtojnar added a commit to jtojnar/meson that referenced this pull request Jul 18, 2022
mesonbuild#9287 changed the `optimization=0`
to pass `-O0` to the compiler. This change is reasonable by itself
but unfortunately, it breaks `buildtype=plain`, which promises
that “no extra build flags are used”.

`buildtype=plain` is important for distros like NixOS,
which manage compiler flags for optimization and hardening
themselves.

Let’s introduce a new optimization level that does nothing
and set it as the default for `buildtype=plain`.
jtojnar added a commit to jtojnar/meson that referenced this pull request Aug 15, 2022
mesonbuild#9287 changed the `optimization=0`
to pass `-O0` to the compiler. This change is reasonable by itself
but unfortunately, it breaks `buildtype=plain`, which promises
that “no extra build flags are used”.

`buildtype=plain` is important for distros like NixOS,
which manage compiler flags for optimization and hardening
themselves.

Let’s introduce a new optimization level that does nothing
and set it as the default for `buildtype=plain`.
jpakkane pushed a commit that referenced this pull request Oct 9, 2022
#9287 changed the `optimization=0`
to pass `-O0` to the compiler. This change is reasonable by itself
but unfortunately, it breaks `buildtype=plain`, which promises
that “no extra build flags are used”.

`buildtype=plain` is important for distros like NixOS,
which manage compiler flags for optimization and hardening
themselves.

Let’s introduce a new optimization level that does nothing
and set it as the default for `buildtype=plain`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants