redboltz / async_mqtt

Asynchronous MQTT communication library based on Boost.Asio
Boost Software License 1.0
77 stars 10 forks source link

Internal Compiler Error on compilation #317

Open notzain opened 1 week ago

notzain commented 1 week ago

I'm trying out this library, and am getting stuck on the seperate compilation. To clarify, I'm using Conan to repackage your library. This is on Ubuntu 22, GCC11 with C++20.

[build] /home/zaah/.conan/data/AsyncMqtt/7.0.0/demo/testing/package/1eb27d28a68692f43a797fbcb7ebf6231c8f210f/include/async_mqtt/impl/endpoint_send.ipp:133:1: internal compiler error: in dwarf2out_finish, at dwarf2out.c:31686
[build]   133 | BOOST_PP_SEQ_FOR_EACH_PRODUCT(ASYNC_MQTT_PP_GENERATE_BASIC, (ASYNC_MQTT_PP_ROLE)(ASYNC_MQTT_PP_SIZE)(ASYNC_MQTT_PP_PROTOCOL)(ASYNC_MQTT_PP_BASIC_PACKET))
[build]       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build] 0x70b758c29d8f __libc_start_call_main
[build]     ../sysdeps/nptl/libc_start_call_main.h:58
[build] 0x70b758c29e3f __libc_start_main_impl
[build]     ../csu/libc-start.c:392
[build] Please submit a full bug report,
[build] with preprocessed source if appropriate.
[build] Please include the complete backtrace with any bug report.
[build] See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.
redboltz commented 1 week ago

I am not sure what is the root issue. It seems that the error message indicate that the compiler bug. I think that the following approach could help you.

  1. Update async_mqtt to 8.0.0
  2. Update g++ to newer version
  3. Use clang++ instead of g++
  4. Create minimal reproduce code (it is not easy) using Boost.Preprosessor and report the issue to gcc bugzilla
redboltz commented 1 week ago

FYI:

I tried the separate compilation mode using the following g++:

g++ (GCC) 14.1.1 20240522
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

no error is occurred.

notzain commented 1 week ago

i upgraded to 8.0.0, and tried with GCC12. This is the latests GCC available to me, and it has the same issue. I'm also using Boost 1.85, if that makes a difference

redboltz commented 1 week ago

Unfortunately I can't fix it internal compiler error that is solved in newer g++ version. Because I don't have much knowledge the internal implementation of g++. But according to the outpug message, the error is related to dwarf2out.c. Perhaps remove debug -g , -gdb3 etc option could something different if you set it.

redboltz commented 1 week ago

I come up with other approach but it is very hard way.

Disable the following part using #if 0 and observe the result. The error would disappear. The separated compiled library is incomplete. But if the error is disappeared, we might be able to narrow down the scope of the investigation.

https://github.com/redboltz/async_mqtt/blob/b859411b2d6ec153fa2736641ee9f238c02ede77/include/async_mqtt/impl/endpoint_send.ipp#L83-L140

redboltz commented 1 week ago

I created g++-12 environment using docker ubuntu.

Then I got the following result. It seems that no errors are reported.

root@e50c20bf7c03:/var/work/clb_ubu# BOOST_ROOT=../tmp_boost/boost_1_85_0/stage/  cmake -DASYNC_MQTT_BUILD_EXAMPLES=ON -DCMAKE_CXX_COMPILER="g++-12" ..
-- Setting minimum C++ standard to C++17
-- Dynamically linking with Boost
-- Dynamically linking with Openssl
-- TLS disabled
-- WS disabled
-- Logging disabled
-- Print payload disabled
-- Found Boost: /var/work/tmp_boost/boost_1_85_0/stage/lib/cmake/Boost-1.85.0/BoostConfig.cmake (found suitable version "1.85.0", minimum required is "1.81.0")
-- Examples enabled
-- C++20 examples added
-- Tools disabled
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Configuring done
-- Generating done
-- Build files have been written to: /var/work/clb_ubu

root@e50c20bf7c03:/var/work/clb_ubu# cd example/
root@e50c20bf7c03:/var/work/clb_ubu/example# ls
CMakeFiles  Makefile  cacert.pem  client.crt.pem  client.key.pem  cmake_install.cmake  mosquitto.org.crt  separate_client  separate_endpoint

root@e50c20bf7c03:/var/work/clb_ubu/example# cd separate_client/

root@e50c20bf7c03:/var/work/clb_ubu/example/separate_client# make VERBOSE=1
cd /var/work/clb_ubu && /usr/bin/cmake -S/var/work -B/var/work/clb_ubu --check-build-system CMakeFiles/Makefile.cmake 0
cd /var/work/clb_ubu && /usr/bin/cmake -E cmake_progress_start /var/work/clb_ubu/CMakeFiles /var/work/clb_ubu/example/separate_client//CMakeFiles/progress.marks
cd /var/work/clb_ubu && make  -f CMakeFiles/Makefile2 example/separate_client/all
make[1]: Entering directory '/var/work/clb_ubu'
make  -f example/separate_client/CMakeFiles/separate_client.dir/build.make example/separate_client/CMakeFiles/separate_client.dir/depend
make[2]: Entering directory '/var/work/clb_ubu'
cd /var/work/clb_ubu && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /var/work /var/work/example/separate_client /var/work/clb_ubu /var/work/clb_ubu/example/separate_client /var/work/clb_ubu/example/separate_client/CMakeFiles/separate_client.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/var/work/clb_ubu'
make  -f example/separate_client/CMakeFiles/separate_client.dir/build.make example/separate_client/CMakeFiles/separate_client.dir/build
make[2]: Entering directory '/var/work/clb_ubu'
[ 33%] Building CXX object example/separate_client/CMakeFiles/separate_client.dir/async_mqtt.cpp.o
cd /var/work/clb_ubu/example/separate_client && /usr/bin/g++-12 -DASYNC_MQTT_SEPARATE_COMPILATION -DBOOST_PROGRAM_OPTIONS_DYN_LINK -I/var/work/include -isystem /var/work/tmp_boost/boost_1_85_0 -std=c++20 -MD -MT example/separate_client/CMakeFiles/separate_client.dir/async_mqtt.cpp.o -MF CMakeFiles/separate_client.dir/async_mqtt.cpp.o.d -o CMakeFiles/separate_client.dir/async_mqtt.cpp.o -c /var/work/example/separate_client/async_mqtt.cpp
[ 66%] Building CXX object example/separate_client/CMakeFiles/separate_client.dir/main.cpp.o
cd /var/work/clb_ubu/example/separate_client && /usr/bin/g++-12 -DASYNC_MQTT_SEPARATE_COMPILATION -DBOOST_PROGRAM_OPTIONS_DYN_LINK -I/var/work/include -isystem /var/work/tmp_boost/boost_1_85_0 -std=c++20 -MD -MT example/separate_client/CMakeFiles/separate_client.dir/main.cpp.o -MF CMakeFiles/separate_client.dir/main.cpp.o.d -o CMakeFiles/separate_client.dir/main.cpp.o -c /var/work/example/separate_client/main.cpp
[100%] Linking CXX executable separate_client
cd /var/work/clb_ubu/example/separate_client && /usr/bin/cmake -E cmake_link_script CMakeFiles/separate_client.dir/link.txt --verbose=1
/usr/bin/g++-12 CMakeFiles/separate_client.dir/async_mqtt.cpp.o CMakeFiles/separate_client.dir/main.cpp.o -o separate_client
make[2]: Leaving directory '/var/work/clb_ubu'
[100%] Built target separate_client
make[1]: Leaving directory '/var/work/clb_ubu'
/usr/bin/cmake -E cmake_progress_start /var/work/clb_ubu/CMakeFiles 0
root@e50c20bf7c03:/var/work/clb_ubu/example/separate_client# g++ --version
g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root@e50c20bf7c03:/var/work/clb_ubu/example/separate_client#
root@e50c20bf7c03:/var/work/clb_ubu/example/separate_client# g++-12 --version
g++-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
root@e50c20bf7c03:/var/work/clb_ubu/example/separate_client# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.4 LTS"
redboltz commented 1 week ago

I just merged 3d4cdd6decf0ef62ed9a421a29a62e448d014229.

I'm not sure if this commit will help you, but it provides another way to build a separately compiled library.

cmake -DASYNC_MQTT_BUILD_LIB=ON ..
make async_mqtt_separate

See https://redboltz.github.io/async_mqtt/doc/latest/separate.html for more details.

If the internal error is caused by memory consumption (separate compilation requires instantiating many templates), this approach might help. It allows you to compile each .ipp file step by step.