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

Protobuf is compiled with -g -O2 despite what configure.ac claims #6941

Closed
neongreen opened this issue Nov 25, 2019 · 3 comments
Closed

Protobuf is compiled with -g -O2 despite what configure.ac claims #6941

neongreen opened this issue Nov 25, 2019 · 3 comments
Labels
bug inactive Denotes the issue/PR has not seen activity in the last 90 days.

Comments

@neongreen
Copy link

neongreen commented Nov 25, 2019

By default, protobuf is compiled with -O2 -g, even though configure.ac claims it shouldn't be:

protobuf/configure.ac

Lines 39 to 44 in a9f390f

# autoconf's default CXXFLAGS are usually "-g -O2". These aren't necessarily
# the best choice for libprotobuf.
AS_IF([test "x${ac_cv_env_CFLAGS_set}" = "x"],
[CFLAGS=""])
AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],
[CXXFLAGS=""])

I'm building latest master as follows:

./autogen.sh
./configure
make

Here's a sample compiler invocation during the build:

/Library/Developer/CommandLineTools/usr/bin/clang++ -DHAVE_CONFIG_H -I. -I..
  -pthread -DHAVE_PTHREAD=1 -DHAVE_ZLIB=1 -Wall -Wno-sign-compare
  -O2 -g -std=c++11 -DNDEBUG -MT google/protobuf/generated_enum_util.lo -MD -MP
  -MF google/protobuf/.deps/generated_enum_util.Tpo 
  -c google/protobuf/generated_enum_util.cc 
  -fno-common -DPIC -o google/protobuf/.libs/generated_enum_util.o

What would be the best way to compile protobuf without -g? This would help a lot with NixOS/nixpkgs#73919.

@veprbl
Copy link

veprbl commented Apr 9, 2020

Turns out there is some bit of code which has an opposite intention:

protobuf/configure.ac

Lines 85 to 101 in 3be9322

# test_util.cc takes forever to compile with GCC and optimization turned on.
AC_MSG_CHECKING([C++ compiler flags...])
AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[
AS_IF([test "$GCC" = "yes"],[
PROTOBUF_OPT_FLAG="-O2"
CXXFLAGS="${CXXFLAGS} -g"
])
# Protocol Buffers contains several checks that are intended to be used only
# for debugging and which might hurt performance. Most users are probably
# end users who don't want these checks, so add -DNDEBUG by default.
CXXFLAGS="$CXXFLAGS -std=c++11 -DNDEBUG"
AC_MSG_RESULT([use default: $PROTOBUF_OPT_FLAG $CXXFLAGS])
],[
AC_MSG_RESULT([use user-supplied: $CXXFLAGS])
])

I'm not aware of what is considered the best practice for handling debug/release builds in autotools, but it seems like, in the case of protobuf, downstream needs to explicitly set CXXFLAGS to achieve a full release build without "-g" option everywhere and with "-O2" on clang.

Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Mar 31, 2024
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug inactive Denotes the issue/PR has not seen activity in the last 90 days.
Projects
None yet
Development

No branches or pull requests

3 participants