From dc8559319fe144b800e44c14385a6d3b50384c3a Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Sun, 10 Apr 2022 22:33:42 +0800 Subject: [PATCH] Add -gdwarf-aranges flag for llvm-mingw Clang Clang does not generate DWARF aranges data by default, which makes DrMingw not able to parse the DWARF debug symbols. Add -gdwarf-aranges explicitly. See: https://github.com/jrfonseca/drmingw/issues/42#issuecomment-516614561 --- 3rdparty/CMakeLists.txt | 16 ++++++++++++++++ 3rdparty/ext_qt/CMakeLists.txt | 8 ++++++++ CMakeLists.txt | 11 +++++++++++ 3 files changed, 35 insertions(+) diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 0c73a15e788..af697841351 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -136,6 +136,22 @@ if (MINGW) else () message(WARNING "Linker Security Flags not enabled!") endif () + + # Clang does not generate DWARF aranges data by default, which makes + # DrMingw not able to parse the DWARF debug symbols. Add -gdwarf-aranges + # explicitly. + # See: https://github.com/jrfonseca/drmingw/issues/42#issuecomment-516614561 + if (CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -gdwarf-aranges") + endif () + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -gdwarf-aranges") + endif () + + set(GLOBAL_PROFILE ${GLOBAL_PROFILE} + -DCMAKE_C_FLAGS_RELWITHDEBINFO=${CMAKE_C_FLAGS_RELWITHDEBINFO} + -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO} + ) elseif (MSVC) set(SECURITY_C_FLAGS ${CMAKE_C_FLAGS}) set(SECURITY_CXX_FLAGS ${CMAKE_CXX_FLAGS}) diff --git a/3rdparty/ext_qt/CMakeLists.txt b/3rdparty/ext_qt/CMakeLists.txt index 987a0d6b5c0..c8c02c8e7d0 100644 --- a/3rdparty/ext_qt/CMakeLists.txt +++ b/3rdparty/ext_qt/CMakeLists.txt @@ -64,6 +64,14 @@ if (WIN32) if (QT_ENABLE_DEBUG_INFO) # Set the option to build Qt with debugging info enabled list(APPEND _QT_conf -force-debug-info) + if (MINGW) + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + list(APPEND _QT_conf + QMAKE_CFLAGS+=-gdwarf-aranges + QMAKE_CXXFLAGS+=-gdwarf-aranges + ) + endif () + endif () endif(QT_ENABLE_DEBUG_INFO) if (QT_ENABLE_DYNAMIC_OPENGL) list(APPEND _QT_conf -opengl dynamic -angle) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a0299230ee..c49bd9ce1a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,6 +185,17 @@ add_feature_info("Dr. Mingw" USE_DRMINGW "Enable the Dr. Mingw crash handler") else (USE_MINGW_HARDENING_LINKER) message(WARNING "Linker Security Flags not enabled!") endif (USE_MINGW_HARDENING_LINKER) + + # Clang does not generate DWARF aranges data by default, which makes + # DrMingw not able to parse the DWARF debug symbols. Add -gdwarf-aranges + # explicitly. + # See: https://github.com/jrfonseca/drmingw/issues/42#issuecomment-516614561 + if (CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -gdwarf-aranges") + endif () + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -gdwarf-aranges") + endif () elseif (MSVC) # Increase the stack size to match MinGW's. Prevents crashes with GMic. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:4194304")