Skip to content

protobuf 34 upb compile and test failures with gcc #26385

@zifeitong

Description

@zifeitong

I ran into compilation error when I was building upb with gcc, and only in opt mode.

$ bazel test upb/test:all -c opt
INFO: Analyzed 47 targets (0 packages loaded, 0 targets configured).
ERROR: /tmp/protobuf/upb/test/BUILD:68:14: Compiling upb/test/test.upb_minitable.c failed: (Exit 1): gcc failed: error executing CppCompile command (from target //upb/test:test_proto) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 26 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
bazel-out/k8-opt/bin/upb/test/test.upb_minitable.c:582:30: warning: 'upb_test_ModelExtension2_model_ext_5_ext' without 'retain' attribute and 'UPB_linkarr_internal_empty_upb_AllExts' with 'retain' attribute are placed in a section with the same name [-Wattributes]
  582 | const upb_MiniTableExtension upb_test_ModelExtension2_model_ext_5_ext = {
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from bazel-out/k8-opt/bin/upb/test/test.upb_minitable.c:14:
./upb/port/def.inc:578:29: note: 'UPB_linkarr_internal_empty_upb_AllExts' was declared here
  578 |   UPB_LINKARR_SENTINEL type UPB_linkarr_internal_empty_##name[1]
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
bazel-out/k8-opt/bin/upb/test/test.upb_minitable.c:619:1: note: in expansion of macro 'UPB_LINKARR_DECLARE'
  619 | UPB_LINKARR_DECLARE(upb_AllExts, const upb_MiniTableExtension);
      | ^~~~~~~~~~~~~~~~~~~
bazel-out/k8-opt/bin/upb/test/test.upb_minitable.c:575:30: error: 'upb_test_ModelExtension2_model_ext_4_ext' causes a section type conflict with 'UPB_linkarr_internal_empty_upb_AllExts' in section 'linkarr_upb_AllExts'
  575 | const upb_MiniTableExtension upb_test_ModelExtension2_model_ext_4_ext = {
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./upb/port/def.inc:578:29: note: 'UPB_linkarr_internal_empty_upb_AllExts' was declared here
  578 |   UPB_LINKARR_SENTINEL type UPB_linkarr_internal_empty_##name[1]
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
bazel-out/k8-opt/bin/upb/test/test.upb_minitable.c:619:1: note: in expansion of macro 'UPB_LINKARR_DECLARE'
  619 | UPB_LINKARR_DECLARE(upb_AllExts, const upb_MiniTableExtension);
      | ^~~~~~~~~~~~~~~~~~~
Use --verbose_failures to see the command lines of failed build steps.

I can get it compile with this patch:

diff --git a/upb_generator/minitable/generator.cc b/upb_generator/minitable/generator.cc
index 77b1175ef..9badc228b 100644
--- a/upb_generator/minitable/generator.cc
+++ b/upb_generator/minitable/generator.cc
@@ -295,7 +295,7 @@ void WriteEnum(upb::EnumDefPtr e, Output& output) {
 void WriteExtension(const DefPoolPair& pools, upb::FieldDefPtr ext,
                     const MiniTableOptions& options, Output& output) {
   output("UPB_LINKARR_APPEND(upb_AllExts)\n");
-  output("const upb_MiniTableExtension $0 = {\n  ", ExtensionVarName(ext));
+  output("const UPB_RETAIN upb_MiniTableExtension $0 = {\n  ", ExtensionVarName(ext));
   output("$0,\n", FieldInitializer(pools, ext));
   output("  $0,\n", GetSub(ext, true, options));
   output("  &$0,\n", MessageVarName(ext.containing_type()));

But the tests will fail:

$ bazel test upb/test:all -c opt
INFO: Analyzed 47 targets (0 packages loaded, 0 targets configured).
INFO: Found 40 targets and 7 test targets...
INFO: Elapsed time: 0.347s, Critical Path: 0.08s
INFO: 2 processes: 6 action cache hit, 1 internal, 1 linux-sandbox.
INFO: Build completed, 1 test FAILED, 2 total actions
//upb/test:length_prefixed_test                                 (cached) PASSED in 0.1s
//upb/test:proto3_test                                          (cached) PASSED in 0.0s
//upb/test:test_cpp                                             (cached) PASSED in 0.0s
//upb/test:test_generated_code                                  (cached) PASSED in 0.0s
//upb/test:test_import_empty_srcs                               (cached) PASSED in 0.1s
//upb/test:test_mini_table_oneof                                (cached) PASSED in 0.0s
//upb/test:editions_test                                                 FAILED in 0.1s

Executed 1 out of 7 tests: 6 tests pass and 1 fails locally.
There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command line option to see which ones these are.

Executing tests from //upb/test:editions_test
-----------------------------------------------------------------------------
Running main() from gmock_main.cc
[==========] Running 9 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 9 tests from EditionsTest
[ RUN      ] EditionsTest.PlainField
[       OK ] EditionsTest.PlainField (0 ms)
[ RUN      ] EditionsTest.ImplicitPresenceField
[       OK ] EditionsTest.ImplicitPresenceField (0 ms)
[ RUN      ] EditionsTest.DelimitedField
[       OK ] EditionsTest.DelimitedField (0 ms)
[ RUN      ] EditionsTest.RequiredField
[       OK ] EditionsTest.RequiredField (0 ms)
[ RUN      ] EditionsTest.ClosedEnum
[       OK ] EditionsTest.ClosedEnum (0 ms)
[ RUN      ] EditionsTest.PackedField
[       OK ] EditionsTest.PackedField (0 ms)
[ RUN      ] EditionsTest.ImportOptionUnlinked
[       OK ] EditionsTest.ImportOptionUnlinked (0 ms)
[ RUN      ] EditionsTest.ImportOptionLinked
upb/test/editions_test.cc:94: Failure
Expected equality of these values:
  upb_message_opt(options)
    Which is: 0
  87

[  FAILED  ] EditionsTest.ImportOptionLinked (0 ms)
[ RUN      ] EditionsTest.ConstructProto
[       OK ] EditionsTest.ConstructProto (0 ms)
[----------] 9 tests from EditionsTest (2 ms total)

[----------] Global test environment tear-down
[==========] 9 tests from 1 test suite ran. (2 ms total)
[  PASSED  ] 8 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] EditionsTest.ImportOptionLinked

 1 FAILED TEST

I am using gcc 15.2 that comes with the to-be-released ubuntu 26.04. You should be able to easily reproduce it with ubuntu 26.04 docker image.

$ gcc --version
gcc (Ubuntu 15.2.0-12ubuntu1) 15.2.0

I also tested gcc-12 to gcc-14 and got the same error.

Metadata

Metadata

Assignees

Labels

platform relatedAny issue releated to specific platform or OSupb

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions