Skip to content

Commit 20436cd

Browse files
malt3katexochen
authored andcommitted
envoy: disable "-Werror" in protobuf
1 parent f598632 commit 20436cd

File tree

3 files changed

+162
-2
lines changed

3 files changed

+162
-2
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
From 448e4e14f4f188687580362a861ae4a0dbb5b1fb Mon Sep 17 00:00:00 2001
2+
From: "Krinkin, Mike" <[email protected]>
3+
Date: Sat, 16 Nov 2024 00:40:40 +0000
4+
Subject: [PATCH] [contrib] Disable GCC warnings and broken features (#37131)
5+
6+
Currently contrib does not build with GCC because of various false
7+
positive compiler warnings turned to errors and a GCC compiler bug.
8+
9+
Let's first start with the bug, in GCC apparently
10+
using -gsplit-dwarf (debug fission) and -fdebug-types-section (used to
11+
optimize the size of debug inforamtion), when used together, can result
12+
in a linker failure.
13+
14+
Refer to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110885 for the GCC
15+
bug report of this issue. When it comes to Envoy, optimized builds with
16+
GCC are affected on at least GCC 11 (used by --config=docker-gcc) and
17+
GCC 12 (and I'm pretty sure the bug isn't fixed in any newer versions
18+
either, though I didn't check each version).
19+
20+
Given that we cannot have both debug fission and a debug types section,
21+
we decided to abandon the debug types sections and keep the fission.
22+
23+
That being said, apparently both of those options are unmaintained in
24+
GCC which poses a question of long term viability of using those or GCC.
25+
26+
Other changes in this commit disable GCC compiler errors for various
27+
warnings that happen when building contrib. I checked those warnings and
28+
didn't find any true
29+
positive.
30+
31+
And additionally, for warnings that exists in both Clang and GCC, Clang
32+
warnings don't trigger, so Clang also disagrees with GCC here.
33+
34+
Additionally missing-requires warning is new and does not exist in GCC
35+
11, but exists in later versions of GCC, so to avoid breaking on this
36+
warning for future versions of GCC I disabled it, but also tell GCC to
37+
not complain if it sees a flag related to an unknwon diagnostic.
38+
39+
This is the last change required to make GCC contrib builds work (you
40+
can find more context and discussions in
41+
https://github.com/envoyproxy/envoy/issues/31807)
42+
43+
Risk Level: Low
44+
Testing: building with --config=gcc and --config=docker-gcc
45+
Docs Changes: N/A
46+
Release Notes: N/A
47+
Platform Specific Features: N/A
48+
Fixes #31807
49+
50+
Signed-off-by: Mikhail Krinkin <[email protected]>
51+
---
52+
.bazelrc | 18 +++++++++++++++++-
53+
bazel/envoy_internal.bzl | 16 +++++++++++++++-
54+
2 files changed, 32 insertions(+), 2 deletions(-)
55+
56+
diff --git a/.bazelrc b/.bazelrc
57+
index e0e4899cecf1..7df94c77944c 100644
58+
--- a/.bazelrc
59+
+++ b/.bazelrc
60+
@@ -57,9 +57,9 @@ test --experimental_ui_max_stdouterr_bytes=11712829 #default 1048576
61+
# Allow tags to influence execution requirements
62+
common --experimental_allow_tags_propagation
63+
64+
+build:linux --copt=-fdebug-types-section
65+
# Enable position independent code (this is the default on macOS and Windows)
66+
# (Workaround for https://github.com/bazelbuild/rules_foreign_cc/issues/421)
67+
-build:linux --copt=-fdebug-types-section
68+
build:linux --copt=-fPIC
69+
build:linux --copt=-Wno-deprecated-declarations
70+
build:linux --cxxopt=-std=c++20 --host_cxxopt=-std=c++20
71+
@@ -95,6 +95,21 @@ build:gcc --linkopt=-fuse-ld=gold --host_linkopt=-fuse-ld=gold
72+
build:gcc --test_env=HEAPCHECK=
73+
build:gcc --action_env=BAZEL_COMPILER=gcc
74+
build:gcc --action_env=CC=gcc --action_env=CXX=g++
75+
+# This is to work around a bug in GCC that makes debug-types-section
76+
+# option not play well with fission:
77+
+# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110885
78+
+build:gcc --copt=-fno-debug-types-section
79+
+# These trigger errors in multiple places both in Envoy dependecies
80+
+# and in Envoy code itself when using GCC.
81+
+# And in all cases the reports appear to be clear false positives.
82+
+build:gcc --copt=-Wno-error=restrict
83+
+build:gcc --copt=-Wno-error=uninitialized
84+
+build:gcc --cxxopt=-Wno-missing-requires
85+
+# We need this because -Wno-missing-requires options is rather new
86+
+# in GCC, so flags -Wno-missing-requires exists in GCC 12, but does
87+
+# not in GCC 11 and GCC 11 is what is used in docker-gcc
88+
+# configuration currently
89+
+build:gcc --cxxopt=-Wno-unknown-warning
90+
91+
# Clang-tidy
92+
# TODO(phlax): enable this, its throwing some errors as well as finding more issues
93+
@@ -375,6 +390,7 @@ build:docker-clang-libc++ --config=docker-sandbox
94+
build:docker-clang-libc++ --config=rbe-toolchain-clang-libc++
95+
96+
build:docker-gcc --config=docker-sandbox
97+
+build:docker-gcc --config=gcc
98+
build:docker-gcc --config=rbe-toolchain-gcc
99+
100+
build:docker-asan --config=docker-sandbox
101+
diff --git a/bazel/envoy_internal.bzl b/bazel/envoy_internal.bzl
102+
index 015659851c1b..27ecaa0bbf47 100644
103+
--- a/bazel/envoy_internal.bzl
104+
+++ b/bazel/envoy_internal.bzl
105+
@@ -68,7 +68,21 @@ def envoy_copts(repository, test = False):
106+
"-Wc++2a-extensions",
107+
"-Wrange-loop-analysis",
108+
],
109+
- repository + "//bazel:gcc_build": ["-Wno-maybe-uninitialized"],
110+
+ repository + "//bazel:gcc_build": [
111+
+ "-Wno-maybe-uninitialized",
112+
+ # GCC implementation of this warning is too noisy.
113+
+ #
114+
+ # It generates warnings even in cases where there is no ambiguity
115+
+ # between the overloaded version of a method and the hidden version
116+
+ # from the base class. E.g., when the two have different number of
117+
+ # arguments or incompatible types and therefore a wrong function
118+
+ # cannot be called by mistake without triggering a compiler error.
119+
+ #
120+
+ # As a safeguard, this warning is only disabled for GCC builds, so
121+
+ # if Clang catches a problem in the code we would get a warning
122+
+ # anyways.
123+
+ "-Wno-error=overloaded-virtual",
124+
+ ],
125+
# Allow 'nodiscard' function results values to be discarded for test code only
126+
# TODO(envoyproxy/windows-dev): Replace /Zc:preprocessor with /experimental:preprocessor
127+
# for msvc versions between 15.8 through 16.4.x. see
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff -Naur a/bazel/protobuf.patch b/bazel/protobuf.patch
2+
--- a/bazel/protobuf.patch 2025-01-06 23:00:26.683972526 +0100
3+
+++ b/bazel/protobuf.patch 2025-01-07 00:53:33.997482569 +0100
4+
@@ -149,3 +149,15 @@
5+
#if PROTOBUF_ENABLE_DEBUG_LOGGING_MAY_LEAK_PII
6+
#define PROTOBUF_DEBUG true
7+
#else
8+
+diff -Naur a/build_defs/cpp_opts.bzl b/build_defs/cpp_opts.bzl
9+
+--- a/build_defs/cpp_opts.bzl 2025-01-06 23:02:56.356552216 +0100
10+
++++ b/build_defs/cpp_opts.bzl 2025-01-07 00:23:30.534047300 +0100
11+
+@@ -22,7 +22,7 @@
12+
+ "-Woverloaded-virtual",
13+
+ "-Wno-sign-compare",
14+
+ "-Wno-nonnull",
15+
+- "-Werror",
16+
++ "-Wno-maybe-uninitialized",
17+
+ ],
18+
+ })
19+
+

pkgs/by-name/en/envoy/package.nix

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ let
3838
# these need to be updated for any changes to fetchAttrs
3939
depsHash =
4040
{
41-
x86_64-linux = "sha256-KQ0ZxLC/ZLLcypmb1UlVXvLWErLmxuednjKRFaBgKuQ=";
42-
aarch64-linux = "sha256-DkibjmY1YND9Q2aQ41bhNdch0SKM5ghY2mjYSQfV30M=";
41+
x86_64-linux = "sha256-qny2l+gIoWCVRZIodd/Tzuj88f/+ajNXeZo/b9XEfVE=";
42+
aarch64-linux = "sha256-DkibjmY1YND9Q2aQ41bhNdch0SKM5ghY2mjYSQfV31N=";
4343
}
4444
.${stdenv.system} or (throw "unsupported system ${stdenv.system}");
4545

@@ -73,6 +73,18 @@ buildBazelPackage rec {
7373
# cherry-pick of https://github.com/envoyproxy/envoy/commit/019f589da2cc8da7673edd077478a100b4d99436
7474
# drop with v1.33.x
7575
./0005-deps-Bump-rules_rust-0.54.1-37056.patch
76+
77+
# patch gcc flags to work with GCC 14
78+
# (silences erroneus -Werror=maybe-uninitialized and others)
79+
# cherry-pick of https://github.com/envoyproxy/envoy/commit/448e4e14f4f188687580362a861ae4a0dbb5b1fb
80+
# drop with v1.33.x
81+
./0006-gcc-warnings.patch
82+
83+
# Remove "-Werror" from protobuf build
84+
# This is fixed in protobuf v28 and later:
85+
# https://github.com/protocolbuffers/protobuf/commit/f5a1b178ad52c3e64da40caceaa4ca9e51045cb4
86+
# drop with v1.33.x
87+
./0007-protobuf-remove-Werror.patch
7688
];
7789
postPatch = ''
7890
chmod -R +w .
@@ -206,6 +218,8 @@ buildBazelPackage rec {
206218
"--noexperimental_strict_action_env"
207219
"--cxxopt=-Wno-error"
208220
"--linkopt=-Wl,-z,noexecstack"
221+
"--config=gcc"
222+
"--verbose_failures"
209223

210224
# Force use of system Java.
211225
"--extra_toolchains=@local_jdk//:all"

0 commit comments

Comments
 (0)