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

[Bug]: segmentation fault due to constexpr constructor of absl::flags_internal::Flag #1821

Open
daizhirui opened this issue Feb 4, 2025 · 2 comments

Comments

@daizhirui
Copy link

Describe the issue

When I used abseil-cpp with other libraries like libtorch, I got segmentation fault at FlagRegistry::RegisterFlag. I solved this issue by removing the constexpr keyword from the constructor of absl::flags_internal::Flag.

Steps to reproduce the problem

  • create a main.cpp with a blank main function.
  • compile main.cpp into an executable and link libtorch and abseil-cpp to it.
  • run the executable, a segmentation fault will occur.

What version of Abseil are you using?

20240722.1

What operating system and version are you using?

ArchLinux, kernel version: Linux 6.13.1

What compiler and version are you using?

I tried both GCC13 and GCC14 with C++17.

What build system are you using?

cmake 3.30

Additional context

No response

@derekmauro
Copy link
Member

Please provide more details on how to reproduce the problem. We need exact commands.

@daizhirui
Copy link
Author

Here is the CMakeLists.txt:

cmake_minimum_required(VERSION 3.30)

project(test_abseil_flags_commandline_flag
    LANGUAGES CXX
)
set(CMAKE_VERBOSE_MAKEFILE ON)
find_package(absl REQUIRED)
set(Torch_DIR /opt/libtorch-cuda/share/cmake/Torch)
find_package(Torch REQUIRED)

find_package(Eigen3 REQUIRED)

# grab all absl libraries
get_target_property(absl_INCLUDE_DIRS absl::core_headers INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(absl_raw_hash_set_path absl::raw_hash_set LOCATION)
get_filename_component(absl_LIB_DIR ${absl_raw_hash_set_path} DIRECTORY)
unset(absl_raw_hash_set_path)
file(GLOB absl_LIBRARIES ${absl_LIB_DIR}/libabsl_*.so.*)
file(GLOB exclude_absl_LIBRARIES ${absl_LIB_DIR}/libabsl_*test*.so.*)

foreach (exclude_absl_LIBRARY ${exclude_absl_LIBRARIES})
    list(REMOVE_ITEM absl_LIBRARIES ${exclude_absl_LIBRARY})
endforeach ()


add_executable(main main.cpp)

# THIS WILL CAUSE SEGMENTATION FAULT
target_link_libraries(main
    PUBLIC ${TORCH_LIBRARIES}
    PUBLIC ${absl_LIBRARIES}
    PUBLIC CUDA::cupti
)


# # THIS WILL NOT CAUSE SEGMENTATION FAULT
# target_link_libraries(main
#     PUBLIC ${absl_LIBRARIES}
#     PUBLIC ${TORCH_LIBRARIES}
#     PUBLIC CUDA::cupti
# )

Then the main.cpp:

#include <cuda_runtime_api.h>
#include <torch/torch.h>
#include <iostream>

int main() {
    std::cout << "hello!" << std::endl;
    return 0;
}

Then execute the commands:

mkdir build
cd build
cmake ..
make
./main   <=== segmentation fault!

Interestingly, if you switch the order of TORCH_LIBRARIES and absl_LIBRARIES, the segmentation fault disappears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants