Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure does not set optimization flag in CXXFLAGS #406

Open
ulmus-scott opened this issue Nov 1, 2021 · 11 comments
Open

configure does not set optimization flag in CXXFLAGS #406

ulmus-scott opened this issue Nov 1, 2021 · 11 comments
Assignees

Comments

@ulmus-scott
Copy link
Contributor

  • Platform: Xubuntu 21.04
    Linux htpc 5.11.0-38-generic #42-Ubuntu SMP Fri Sep 24 14:03:54 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

  • MythTV version: master, fixes/31

  • Package version: mythbuntu ppa for fixes/31

  • Component: configure

What steps will reproduce the bug?

in mythtv/ run:

./configure
make

or look at config.mak instead of running make

for ppa: look at DWARF debugging info, note no -O flag
readelf -wi <binary> | grep DW_AT_producer

How often does it reproduce? Is there a required condition? always

What is the expected behaviour?

Optimization flag is set for c++ compilation.
Without any options, -O2, maybe -O3, definitely at least -O1.

NB: CFLAGS includes -O3

What do you see instead?

No -O flag is set, so gcc uses its default of -O0, no optimizations are performed.

Additional information

with ./configure --extra-cxxflags=-O1 note -O1 now in CXXFLAGS

@linuxdude42
Copy link
Contributor

You can add "--toolchain=hardened" to the configure command to get " -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" added to the c++ flags.

@kmdewaal
Copy link
Contributor

I think that this bug report really refers to how the packages are built, as it refers to mythbuntu ppa for fixes/31. I do agree that packages should be built optimized and if that is not done, it should be fixed.

However, this proposal changes the compilation behavior for all interactive builds (./configure; make) and not (only) for package builds.
My expected behavior for interactive builds is that the default --compile-type=profile has the default optimization -O0. It can be an omission that this is not set in CXXFLAGS but then it should be set to -O0 if it is to be set and not to -O2.

@kmdewaal kmdewaal reopened this Dec 13, 2021
@garybuhrmaster
Copy link
Contributor

I think that this bug report really refers to how the packages are built, as it refers to mythbuntu ppa for fixes/31. I do agree that packages should be built optimized and if that is not done, it should be fixed.

Every distro has their own set of standards for CFLAGS/CXXFLAGS for building (some set/export the variables, some have config/build macros, some use the -specs option to gcc, whatever). It is up to the packagers for that distro to make sure that those standards are implemented, and if there are mistakes in the distros packaging, there should be tickets opened with that distro against the package.

@ulmus-scott
Copy link
Contributor Author

@kmdewaal

I think that this bug report really refers to how the packages are built, as it refers to mythbuntu ppa for fixes/31. I do agree that packages should be built optimized and if that is not done, it should be fixed.

OK, the packaging optimization should be a separate bug. Ignore that part.

However, this proposal changes the compilation behavior for all interactive builds (./configure; make) and not (only) for package builds.
My expected behavior for interactive builds is that the default --compile-type=profile has the default optimization -O0. It can be an omission that this is not set in CXXFLAGS but then it should be set to -O0 if it is to be set and not to -O2.

I disagree. If you build from source, I would expect some level of optimization (at least -O1, probably -O2) just from ./configure.

Klaas, it really sounds like you want to compile with --compile-type=debug.

Profile is supposed to be for, well, profiling. Does anyone actually profile the code? For profiling to give useful results, optimization must be enabled.

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
Recommends -Og for debugging, not -O0.

@mspieth
Copy link
Contributor

mspieth commented Dec 13, 2021 via email

@kmdewaal
Copy link
Contributor

>  https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
>  Recommends |-Og| for debugging, not |-O0|.

Profiling is so that you can debug with many optimizations. -Og is
advisable. -O2 makes things more difficult. This is what I use for my
master production system as it gives good backtraces when problems occur.

Summing this up, I think that should make the "./configure; make" use compilation flag -Og so that we do have both fast compilation time and good debug capability.

@ulmus-scott
Copy link
Contributor Author

ulmus-scott commented Dec 30, 2021

@mspieth

Profiling is so that you can debug with many optimizations. -Og is advisable. -O2 makes things more difficult. This is what I use for my master production system as it gives good backtraces when problems occur.

Profiling is so you don't waste your time optimizing code that doesn't matter.

@kmdewaal

Summing this up, I think that should make the "./configure; make" use compilation flag -Og so that we do have both fast compilation time and good debug capability.

I disagree. I think -O2 is a better default. If you want to run it in a debugger, it makes sense to me that you would have to specify what optimization level you want (-Og, -O1, -O0, etc.).

On that note, the now trimmed pull request #430 would enable setting the optimization flag with
./configure --cxxoptflags=OPTFLAGS

@garybuhrmaster
Copy link
Contributor

I disagree. I think -O2 is a better default.

According to the available usage statistics, only developers and a few advanced users compile/run from source. The vast majority use packages built by others for production, and every distro packager (to first approximation) uses the distros default compile flags (whatever they are).

So, the only remaining issue is what do developers doing development/debugging need/want. The default should most likely be set for developers to do their debugging, as when developers compile for production, they are presumably capable of knowing how to set their compiler flags (or build their own packages for their own production). Those that run development codes in production likely are doing do knowingly for purposes of, well, development/debugging.

@ulmus-scott
Copy link
Contributor Author

@garybuhrmaster

According to the available usage statistics, only developers and a few advanced users compile/run from source. The vast majority use packages built by others for production, and every distro packager (to first approximation) uses the distros default compile flags (whatever they are).

My main concern is that some warning options only work at -O2 or higher, or work better at higher optimization levels.

So, the only remaining issue is what do developers doing development/debugging need/want. The default should most likely be set for developers to do their debugging, as when developers compile for production, they are presumably capable of knowing how to set their compiler flags (or build their own packages for their own production). Those that run development codes in production likely are doing do knowingly for purposes of, well, development/debugging.

That is fair enough. Perhaps the default compile type should be renamed to "development" and use -Og for C++ code.

@ulmus-scott
Copy link
Contributor Author

Unless I misread the clang and Intel compiler documentation, -Og is specific to GCC. What should the default be for the other compilers?

@ulmus-scott
Copy link
Contributor Author

@kmdewaal Would adding a new compile type named devel with -Og for gcc or -O1 for other compilers be acceptable?

This could be made the new default if the other developers agree. Thoughts, everyone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants