google / bloaty

Bloaty: a size profiler for binaries
Apache License 2.0
4.66k stars 337 forks source link

Build broken on Arch Linux with ABSL_ASSUME errors from protobuf headers #353

Open colatkinson opened 1 year ago

colatkinson commented 1 year ago

The issue appears to be coming from an incompatibility between the system-provided version of protobuf and the vendored version of abseil.

Modifying the CMake file to use the system abseil instead seems to fix the issue. I have attached a hacky proof-of-concept patch below.

For reference, the system-provided version of protobuf is 23.4, and the system-provided abseil-cpp is 20230125.3. The bloaty commit I'm building is 2757d3ec0fec07f4ac7f2f96fe8f0b020c2d84fb (latest main as of this writing).

Patch that fixes the build: ```diff diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a843b9..d90a548 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,7 +157,6 @@ endif() include_directories(.) include_directories(src) -include_directories(third_party/abseil-cpp) include_directories("${CMAKE_CURRENT_BINARY_DIR}/src") # Baseline build flags. @@ -244,27 +243,6 @@ add_library(libbloaty STATIC src/util.cc src/util.h src/webassembly.cc - # Until Abseil has a proper CMake build system - third_party/abseil-cpp/absl/base/internal/raw_logging.cc # Grrrr... - third_party/abseil-cpp/absl/base/internal/throw_delegate.cc - third_party/abseil-cpp/absl/debugging/internal/demangle.cc - third_party/abseil-cpp/absl/numeric/int128.cc - third_party/abseil-cpp/absl/strings/ascii.cc - third_party/abseil-cpp/absl/strings/charconv.cc - third_party/abseil-cpp/absl/strings/escaping.cc - third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc - third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc - third_party/abseil-cpp/absl/strings/internal/escaping.cc - third_party/abseil-cpp/absl/strings/internal/memutil.cc - third_party/abseil-cpp/absl/strings/internal/utf8.cc - third_party/abseil-cpp/absl/strings/match.cc - third_party/abseil-cpp/absl/strings/numbers.cc - third_party/abseil-cpp/absl/strings/str_cat.cc - third_party/abseil-cpp/absl/strings/string_view.cc - third_party/abseil-cpp/absl/strings/str_split.cc - third_party/abseil-cpp/absl/strings/substitute.cc - third_party/abseil-cpp/absl/types/bad_optional_access.cc - # One source file, no special build system needed. third_party/demumble/third_party/libcxxabi/cxa_demangle.cpp ) set_property(TARGET libbloaty PROPERTY FOLDER "bloaty") ```

The errors are generally of the form

FAILED: CMakeFiles/libbloaty.dir/src/macho.cc.o 
/usr/bin/c++ -DUSE_RE2 -D_LIBCXXABI_FUNC_VIS="" -I/usr/include/capstone -I/tmp/bloaty/. -I/tmp/bloaty/src -I/tmp/bloaty/third_party/abseil-cpp -I/tmp/bloaty/build/src -I/tmp/bloaty/third_party/googletest/googletest/include -I/tmp/bloaty/third_party/googletest/googlemock/include -W -Wall -Wno-sign-compare -fdiagnostics-color=always -O2 -g1 -std=gnu++17 -MD -MT CMakeFiles/libbloaty.dir/src/macho.cc.o -MF CMakeFiles/libbloaty.dir/src/macho.cc.o.d -o CMakeFiles/libbloaty.dir/src/macho.cc.o -c /tmp/bloaty/src/macho.cc
In file included from /usr/include/google/protobuf/implicit_weak_message.h:39,
                 from /usr/include/google/protobuf/generated_message_util.h:55,
                 from /tmp/bloaty/build/src/bloaty.pb.h:27,
                 from /tmp/bloaty/src/bloaty.h:39,
                 from /tmp/bloaty/src/macho.cc:17:
/usr/include/google/protobuf/repeated_field.h: In member function ‘void google::protobuf::RepeatedField< <template-parameter-1-1> >::Add(Element)’:
/usr/include/google/protobuf/repeated_field.h:674:3: error: there are no arguments to ‘ABSL_ASSUME’ that depend on a template parameter, so a declaration of ‘ABSL_ASSUME’ must be available [-fpermissive]
  674 |   ABSL_ASSUME(new_size == current_size_);
      |   ^~~~~~~~~~~

A complete build log is provided here: err-log.txt

For my 2¢ on a more complete fix: Arch does provide pkg-config files for abseil, so it should be possible to check for its presence as a system library that way. Alternatively, could just add a BLOATY_PREFER_SYSTEM_ABSL flag, like in #352.

Please let me know if any additional info would be helpful, or if this is a downstream bug of some kind.

jmaselbas commented 11 months ago

hi, i am having the same issue, also on arch with protobuf 23.4 and abseil-cpp 20230125.3

cschramm commented 11 months ago

The underlying issue seems to be that bloaty ships its own abseil LTS 20211102 while it happily accepts any system-provided protobuf. That means that such a protobuf has to be compatible with that abseil version so that anything newer than 21.12 does not work.

cjdb commented 6 months ago

The AUR package for bloaty-git provides a patch that might be useful.