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

-Werror by default can break downstream Bazel builds #14714

Closed
coryan opened this issue Nov 9, 2023 · 6 comments · Fixed by #17921
Closed

-Werror by default can break downstream Bazel builds #14714

coryan opened this issue Nov 9, 2023 · 6 comments · Fixed by #17921
Assignees
Labels
bug c++ inactive Denotes the issue/PR has not seen activity in the last 90 days.

Comments

@coryan
Copy link
Contributor

coryan commented Nov 9, 2023

What version of protobuf and what language are you using?

Version: main and v24.x
Language: C++

What operating system (Linux, Windows, ...) and version?

Linux, but probably all of them.

What runtime / compiler are you using (e.g., python version or gcc version)

In this case GCC 13.2:

gcc (Debian 13.2.0-4) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

What did you do?

  1. I was compiling Protobuf with GCC 13 and Address Sanitizer, as part of a different project (googleapis/google-cloud-cpp)
  2. This project uses slightly different options in its asan configuration, and the build breaks.
  3. To reproduce, you can apply this patch to the Protobuf source:
diff --git a/.bazelrc b/.bazelrc
index fb29fe10d..39e7120e0 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -4,7 +4,7 @@ build:dbg --compilation_mode=dbg
 
 build:opt --compilation_mode=opt
 
-build:san-common --config=dbg --strip=never --copt=-O0 --copt=-fno-omit-frame-pointer
+build:san-common --config=dbg --strip=never --copt=-Og --copt=-fno-omit-frame-pointer
 
 build:asan --config=san-common --copt=-fsanitize=address --linkopt=-fsanitize=address
 build:asan --copt=-DADDRESS_SANITIZER=1
  1. And then compile using
bazel build --config asan //:protobuf

What did you expect to see

A successful build.

What did you see instead?

The build fails with:

ERROR: /usr/local/google/home/coryan/protobuf/src/google/protobuf/io/BUILD.bazel:11:11: Compiling src/google/protobuf/io/coded_stream.cc failed: (Exit 1): gcc failed: error executing command (from target //src/google/protobuf/io:io) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g '-std=c++14' -MD -MF ... (remaining 40 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
src/google/protobuf/io/coded_stream.cc: In member function 'int64_t google::protobuf::io::CodedInputStream::ReadVarint32Fallback(uint32_t)':
src/google/protobuf/io/coded_stream.cc:525:12: error: 'temp' may be used uninitialized [-Werror=maybe-uninitialized]
  525 |     return temp;
      |            ^~~~
src/google/protobuf/io/coded_stream.cc:520:14: note: 'temp' was declared here
  520 |     uint32_t temp;
      |              ^~~~
cc1plus: all warnings being treated as errors

Anything else we should know about your project / environment

You know where to find me if needed.

An opinion

Someday I will write "-Werror by default considered harmful". It is a good idea to turn this flag on development builds, I thank you for doing so, but it is not a good idea to turn it on for downstream builds too. The downstream builds may have slightly different compilers, or compiler flags, and the build would break.

https://github.com/protocolbuffers/protobuf/blob/24.x/build_defs/cpp_opts.bzl#L24

@coryan coryan added the untriaged auto added to all issues by default when created. label Nov 9, 2023
@traversaro
Copy link
Contributor

An opinion

Someday I will write "-Werror by default considered harmful". It is a good idea to turn this flag on development builds, I thank you for doing so, but it is not a good idea to turn it on for downstream builds too. The downstream builds may have slightly different compilers, or compiler flags, and the build would break.

I think this point is explained with a lot of detail in the "Don't create spurious errors" section of Robert Schumacher's Talk from CppCon2019 “Don't Package Your Libraries, Write Packagable Libraries! (Part 2)”: https://youtu.be/_5weX5mx8hc?si=boacaiOG-pw_yG23&t=322 .

@mkruskal-google mkruskal-google self-assigned this Nov 13, 2023
@mkruskal-google mkruskal-google added bug c++ and removed untriaged auto added to all issues by default when created. labels Nov 13, 2023
copybara-service bot pushed a commit that referenced this issue Nov 14, 2023
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Closed #14714

PiperOrigin-RevId: 582400675
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 Feb 12, 2024
@coryan
Copy link
Contributor Author

coryan commented Feb 12, 2024

I think this was fixed in #14752 ? @mkruskal-google thoughts?

@github-actions github-actions bot removed the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Feb 13, 2024
@vvviktor
Copy link

vvviktor commented Mar 3, 2024

@coryan No, -Werror flag still exists in build_defs/cpp_opts.bzl

@hgminh95
Copy link

I got the same issue too. Can confirm that merging #14752 should fix it.

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. This issue will be closed and archived after 14 additional days without activity.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Aug 11, 2024
copybara-service bot pushed a commit that referenced this issue Aug 22, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 22, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 22, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 22, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 22, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 22, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 22, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 22, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 22, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 22, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 22, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 23, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing.

Closed #14714

PiperOrigin-RevId: 582400675
copybara-service bot pushed a commit that referenced this issue Aug 23, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing.

Closed #14714

PiperOrigin-RevId: 582400675
mkruskal-google added a commit that referenced this issue Aug 23, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing.

Closed #14714

PiperOrigin-RevId: 666903224
mkruskal-google added a commit that referenced this issue Aug 23, 2024
Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing.

Closed #14714

PiperOrigin-RevId: 666903224
mkruskal-google added a commit that referenced this issue Aug 23, 2024
* Move -Werror to our test/dev bazelrc files.

Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing.

Closed #14714

PiperOrigin-RevId: 666903224

* Fix extra warnings on 27.x

* Fix zlib issues on macos

* Fix spurious upb warnings in 27.x

* Second try at zlib/macos issues

* Only disable deprecated-non-prototype on macos-14
mkruskal-google added a commit that referenced this issue Aug 23, 2024
* Move -Werror to our test/dev bazelrc files.

Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing.

Closed #14714

PiperOrigin-RevId: 666903224

* Fix extra warnings on 28.x

* Fix zlib issues on macos

* Second try at zlib/macos issues

* Only disable deprecated-non-prototype on macos-14
zhangskz added a commit that referenced this issue Sep 18, 2024
    * Move -Werror to our test/dev bazelrc files.

    Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

    Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing.

    Closed #14714

    PiperOrigin-RevId: 666903224

    * Fix extra warnings on 28.x

    * Fix zlib issues on macos

    * Second try at zlib/macos issues

    * Only disable deprecated-non-prototype on macos-14
mkruskal-google added a commit that referenced this issue Sep 18, 2024
* Fix cord handling in DynamicMessage and oneofs.

This fixes a memory corruption vulnerability for anyone using cord with dynamically built descriptor pools.

* Move -Werror to our test/dev bazelrc files. (#17938)

    * Move -Werror to our test/dev bazelrc files.

    Putting it into BUILD files unintentionally forces it on all our downstream users.  Instead, we just want to enable this during testing and let them choose for themselves in their builds.

    Note, that this expands the scope of -Werror to our entire repo for CI, so a bunch of fixes and opt-outs had to be applied to get this change passing.

    Closed #14714

    PiperOrigin-RevId: 666903224

    * Fix extra warnings on 28.x

    * Fix zlib issues on macos

    * Second try at zlib/macos issues

    * Only disable deprecated-non-prototype on macos-14

* Silence expected ubsan failures from absl::Cord

* Fix test dependency

* Fix python/upb warnings

* Fix last upb warning

---------

Co-authored-by: Mike Kruskal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug c++ inactive Denotes the issue/PR has not seen activity in the last 90 days.
Projects
None yet
5 participants