-
Notifications
You must be signed in to change notification settings - Fork 423
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
Optimization flag and stripping are not enabled for Release build type #2270
Comments
Sorry, it's not very clear to me. This repo relies on the CMake default optimization flags for each configuration ( $labhas@DESKTOP-D0BLHPQ:~/obs/ot/opentelemetry-cpp/build$ cmake .. -DCMAKE_BUILD_TYPE=Release && make VERBOSE=1
....
[ 0%] Building CXX object api/test/core/CMakeFiles/version_test.dir/version_test.cc.o
cd /home/labhas/obs/ot/opentelemetry-cpp/build/api/test/core && /usr/bin/c++ -DENABLE_TEST -I/home/labhas/obs/ot/opentelemetry-cpp/api/include -O3 -DNDEBUG -Wno-error=deprecated-declarations -std=gnu++11 -o CMakeFiles/version_test.dir/version_test.cc.o -c /home/labhas/obs/ot/opentelemetry-cpp/api/test/core/version_test.cc
And the optimization can be overridden using So, to set the O2 optimization for Release configuration: $labhas@DESKTOP-D0BLHPQ:~/obs/ot/opentelemetry-cpp/build$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE="-O2" && make VERBOSE=1
...
[ 0%] Building CXX object api/test/core/CMakeFiles/version_test.dir/version_test.cc.o
cd /home/labhas/obs/ot/opentelemetry-cpp/build/api/test/core && /usr/bin/c++ -DENABLE_TEST -I/home/labhas/obs/ot/opentelemetry-cpp/api/include -O2 -Wno-error=deprecated-declarations -std=gnu++11 -o CMakeFiles/version_test.dir/version_test.cc.o -c /home/labhas/obs/ot/opentelemetry-cpp/api/test/core/version_test.cc Let me know if I didn't understand the issue properly. |
Maybe I misunderstood the approach. As far as I understand from your comment above, by default any optimization flags not set and if someone needs such thing, corresponding FLAGS must be overwritten. Is it correct? I was trying to create Debian package from the library and I realized that there is a room for optimization in Release mode. That's why I created a bug for it because with optimization flag, package is decreased 30% almost. |
The default optimization selected by CMake for gcc release build is |
CMake will add |
Maybe you are focusing on too optimization flags as compiler flag. I mentioned also linker flags too like strip-all, gc-sections etc. With setting CMake Release build type does not bring them by default. |
@cngzhnp - would this work? CMAKE_EXE_LINKER_FLAGS_<CONFIG> - To set the configuration-specific linker flags. The otel build should just rely on the default flags for each configuration, and let the users modify it for their needs using the above cmake variables. |
Of course, it is going to be worked. Here what I want to hear :
So, no need to change any flags regarding this. Thanks a lot, so no need to implement something. |
Describe your environment
Steps to reproduce
When makefile verbose is ON, I do not see any optimization flag enabled (-O1, -O2) for even Release build type.
What is the expected behavior?
At least for Release type, I'd like to see some optimization flags are enabled like (-fdata-sections, -ffunction-sections, -O2 etc.) In my opinion, it should contain also "stripping".
What is the actual behavior?
There is no optimization at all, one only case for MSVC compiler with STL enabled.
Additional context
After I played around with optimization flag like I mentioned above here is the difference:
Before -O2 flag enabled and not stripped for shared libraries(example for proto and grpc):
After -O2 flag enabled and stripped for shared libraries(example for proto and grpc):
After enabling this "
-O2 -flto -fdata-sections -ffunction-sections -fmerge-all-constants -fno-exceptions -fno-rtti
" as compiler flags and do "-Wl,-flto -Wl,--as-needed -Wl,--gc-sections -Wl,--strip-all
" linker flags:Note: I know that some part of flags are not available for every compiler, so needs to be handled in a different way.
The text was updated successfully, but these errors were encountered: