Skip to content

Basic protobuf usage segfaults #221740

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

Closed
2 of 4 tasks
mortie opened this issue Apr 28, 2025 · 6 comments
Closed
2 of 4 tasks

Basic protobuf usage segfaults #221740

mortie opened this issue Apr 28, 2025 · 6 comments
Labels
stale No recent activity

Comments

@mortie
Copy link
Contributor

mortie commented Apr 28, 2025

brew gist-logs <formula> link OR brew config AND brew doctor output

$ brew gist-logs protobuf
Error: No logs.

$ brew config
HOMEBREW_VERSION: 4.4.32-75-g50b70e3
ORIGIN: https://github.com/Homebrew/brew
HEAD: 50b70e3cb72e994cd7f530960dfb47255fdf2a34
Last commit: 6 hours ago
Branch: master
Core tap HEAD: 6c2620ecb4d741efbff32295f0c2ef01ebd5dfca
Core tap last commit: 5 hours ago
Core tap JSON: 28 Apr 10:02 UTC
Core cask tap HEAD: ba3da943abc861c24d078b63560419d6981c4f32
Core cask tap last commit: 5 hours ago
Core cask tap JSON: 28 Apr 10:02 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_EDITOR: nvim
HOMEBREW_MAKE_JOBS: 10
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 3.4.3 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.3/bin/ruby
CPU: deca-core 64-bit arm_firestorm_icestorm
Clang: 17.0.0 build 1700
Git: 2.49.0 => /opt/homebrew/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 15.4.1-arm64
CLT: 16.3.0.0.1.1742442376
Xcode: 16.3
Rosetta 2: false

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  icu4c@76

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae and may need to be deleted.

Unexpected dylibs:
  /usr/local/lib/libMoltenVK.dylib
  /usr/local/lib/libSPIRV-Tools-shared.dylib
  /usr/local/lib/libVkLayer_api_dump.dylib
  /usr/local/lib/libVkLayer_khronos_profiles.dylib
  /usr/local/lib/libVkLayer_khronos_synchronization2.dylib
  /usr/local/lib/libVkLayer_khronos_validation.dylib
  /usr/local/lib/libcorrect.dylib
  /usr/local/lib/libdxcompiler.3.7.dylib
  /usr/local/lib/libsdrpp_core.dylib
  /usr/local/lib/libshaderc_shared.1.dylib
  /usr/local/lib/libspirv-cross-c-shared.0.49.0.dylib
  /usr/local/lib/libvulkan.1.3.211.dylib

Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae and may need to be deleted.

Unexpected header files:
  /usr/local/include/correct-sse.h
  /usr/local/include/correct.h
  /usr/local/include/dxc/*
  /usr/local/include/glslang/*
  /usr/local/include/shaderc/*
  /usr/local/include/spirv-tools/*
  /usr/local/include/spirv_cross/*
  /usr/local/include/vk_video/*
  /usr/local/include/vulkan/*

Warning: Unbrewed '.pc' files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae and may need to be deleted.

Unexpected '.pc' files:
  /usr/local/lib/pkgconfig/SPIRV-Tools-shared.pc
  /usr/local/lib/pkgconfig/SPIRV-Tools.pc
  /usr/local/lib/pkgconfig/shaderc.pc
  /usr/local/lib/pkgconfig/spirv-cross-c-shared.pc
  /usr/local/lib/pkgconfig/vulkan.pc

Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae and may need to be deleted.

Unexpected static libraries:
  /usr/local/lib/libGenericCodeGen.a
  /usr/local/lib/libHLSL.a
  /usr/local/lib/libMachineIndependent.a
  /usr/local/lib/libOGLCompiler.a
  /usr/local/lib/libOSDependent.a
  /usr/local/lib/libSPIRV-Tools-diff.a
  /usr/local/lib/libSPIRV-Tools-link.a
  /usr/local/lib/libSPIRV-Tools-lint.a
  /usr/local/lib/libSPIRV-Tools-opt.a
  /usr/local/lib/libSPIRV-Tools-reduce.a
  /usr/local/lib/libSPIRV-Tools.a
  /usr/local/lib/libSPIRV.a
  /usr/local/lib/libSPVRemapper.a
  /usr/local/lib/libcorrect.a
  /usr/local/lib/libglslang-default-resource-limits.a
  /usr/local/lib/libglslang.a
  /usr/local/lib/libshaderc.a
  /usr/local/lib/libshaderc_combined.a
  /usr/local/lib/libshaderc_util.a
  /usr/local/lib/libspirv-cross-c.a
  /usr/local/lib/libspirv-cross-core.a
  /usr/local/lib/libspirv-cross-cpp.a
  /usr/local/lib/libspirv-cross-glsl.a
  /usr/local/lib/libspirv-cross-hlsl.a
  /usr/local/lib/libspirv-cross-msl.a
  /usr/local/lib/libspirv-cross-reflect.a
  /usr/local/lib/libspirv-cross-util.a

Verification

As you can see from by brew doctor output, I have the Vulkan SDK installed, and I have icu4c@76 installed because it's a dependency of a ton of packages. These things seem unrelated to the issue I'm describing here, so I will not uninstall the Vulkan SDK or icu4c@76 (+ dependents) just to make the output of brew doctor clean, unless someone specifically asks for it.

What were you trying to do (and why)?

I tried to use the Homebrew-packaged protobuf library to deserialize a serialized string.

What happened (include all command output)?

It caused a segmentation fault.

What did you expect to happen?

It to not cause a segmentation fault.

Step-by-step reproduction instructions (by running brew commands)

  1. brew install protobuf
  2. Write the following content to testmessage.proto:
syntax = "proto3";

message TestMessage {
    repeated Foo foos = 1;
}

message Foo {
  int32 x = 1;
}
  1. Write the following to main.cc:
#include "testmessage.pb.h"
#include <iostream>

int main() {
    TestMessage a;
    a.add_foos()->set_x(10);

    std::string serialized;
    if (!a.SerializeToString(&serialized)) {
        std::cerr << "Oh no, serialize failed\n";
        return 1;
    }

    std::cout << "Parsing...\n";
    TestMessage b;
    if (!b.ParseFromString(serialized)) {
        std::cerr << "Oh no, parse failed\n";
        return 1;
    }

    return 0;
}
  1. protoc --cpp_out=. testmessage.proto
  2. clang++ -std=c++20 -o main main.cc testmessage.pb.cc $(pkg-config --libs --cflags protobuf)
  3. ./main

You should see a segmentation fault error.

@mortie
Copy link
Contributor Author

mortie commented Apr 28, 2025

Now that I'm out of the extremely restrictive issue template, I can finally describe what the issue actually is.

The protobuf package, since a couple weeks ago, has an issue where it causes a segmentation fault even for trivial applications. It seems relevant to this bug on their issue tracker: protocolbuffers/protobuf#21447

I suspect that something about the way which Homebrew builds protobuf might trigger the issue, since if it was universal, they would otherwise have caught the issue in their tests in CI. Though I want to investigate further.

@mortie
Copy link
Contributor Author

mortie commented Apr 28, 2025

I just checked out protobuf commit b407e8416e3893036aee5af9a12bd9b6a0e2b2e6 (the one tagged v29.3) and built it with the same cmake parameters as is used by the formula:

cmake -DCMAKE_CXX_STANDARD=17 -DBUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_LIBPROTOC=ON -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_INSTALL_EXAMPLES=ON -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_ABSL_PROVIDER=package -Dprotobuf_JSONCPP_PROVIDER=package -DCMAKE_INSTALL_PREFIX=`pwd`/../pfx .. ..
make -j10
make install

And when I link against the resulting libprotobuf.dylib, my dummy application is able to parse the protobuf file without issues. I wonder if it's just a compiler version thing? I'm using "Apple clang version 17.0.0 (clang-1700.0.13.3)", the protobuf package might have been built with an older clang?

@Bo98
Copy link
Member

Bo98 commented Apr 28, 2025

29.3 is old enough that it would have been built with Apple Clang 16. The protobuf package has not been updated since January so if it only happened in the last couple weeks you say, the new compiler may be a possible cause.

With that said, there usually isn't binary compatibility issues between compiler versions without there being an underlying bug somewhere (potentially even in the compiler), unless an Xcode release note states a breaking change otherwise.

@mortie
Copy link
Contributor Author

mortie commented Apr 28, 2025

I just reinstalled protobuf from source with brew reinstall --build-from-source protobuf, and now it works. So yeah, this is probably an issue caused by having compiled protobuf and the application code with different compiler versions.

Why would this cause a problem? 🤷. But at least building from source is a workaround, and this issue will probably just fix itself whenever a protobuf package version compiled with Clang 17 is released.

@fxcoudert
Copy link
Member

I've dispatched a build for new bottles: https://github.com/Homebrew/homebrew-core/actions/runs/14772098332

Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label May 22, 2025
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale No recent activity
Projects
None yet
Development

No branches or pull requests

3 participants