Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions compiler-rt/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -728,16 +728,9 @@ if (MSVC)
set(LLVM_WINSYSROOT "" CACHE STRING
"If set, argument to clang-cl's /winsysroot")

if (LLVM_WINSYSROOT)
set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH
"Path to the DIA SDK")
else()
set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
"Path to the DIA SDK")
endif()

# See if the DIA SDK is available and usable.
if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
find_package(DIASDK)
if (DIASDK_FOUND)
set(CAN_SYMBOLIZE 1)
else()
set(CAN_SYMBOLIZE 0)
Expand Down
27 changes: 3 additions & 24 deletions llvm/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -625,32 +625,11 @@ if( MSVC )
set(LLVM_WINSYSROOT "" CACHE STRING
"If set, argument to clang-cl's /winsysroot")

if (LLVM_WINSYSROOT)
set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH
"Path to the DIA SDK")
else()
set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
"Path to the DIA SDK")
endif()

# See if the DIA SDK is available and usable.
# Due to a bug in MSVC 2013's installation software, it is possible
# for MSVC 2013 to write the DIA SDK into the Visual Studio 2012
# install directory. If this happens, the installation is corrupt
# and there's nothing we can do. It happens with enough frequency
# though that we should handle it. We do so by simply checking that
# the DIA SDK folder exists. Should this happen you will need to
# uninstall VS 2012 and then re-install VS 2013.
if (IS_DIRECTORY "${MSVC_DIA_SDK_DIR}")
set(HAVE_DIA_SDK 1)
else()
set(HAVE_DIA_SDK 0)
endif()

find_package(DIASDK)
option(LLVM_ENABLE_DIA_SDK "Use MSVC DIA SDK for debugging if available."
${HAVE_DIA_SDK})
${DIASDK_FOUND})

if(LLVM_ENABLE_DIA_SDK AND NOT HAVE_DIA_SDK)
if(LLVM_ENABLE_DIA_SDK AND NOT DIASDK_FOUND)
message(FATAL_ERROR "DIA SDK not found. If you have both VS 2012 and 2013 installed, you may need to uninstall the former and re-install the latter afterwards.")
endif()
else()
Expand Down
74 changes: 74 additions & 0 deletions llvm/cmake/modules/FindDIASDK.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Finds the Microsoft DIA SDK and sets DIASDK_FOUND and related variables.
#
# This module is intended to be used both internally by LLVM's build system and
# by consuming projects when loading LLVMConfig.cmake.
#
# LLVM_WINSYSROOT may be set for locating the DIA SDK.
#
# If successful, the following variables will be defined:
# DIASDK_FOUND
# DIASDK_INCLUDE_DIR
# DIASDK_LIBRARIES
#
# Additionally, the following import target will be defined:
# DIASDK::Diaguids

if(NOT WIN32)
set(DIASDK_FOUND FALSE)
return()
endif()
Comment on lines +16 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be restricted to WIN32?

Copy link
Member Author

@ZhongRuoyu ZhongRuoyu Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't have to, because DIA SDK will not be found anyway if we're not building for WIN32 (which, despite its name, covers the entire set of Windows targets). As far as this project is concerned, all find(DIASDK) logic is guarded by LLVM_ENABLE_DIA_SDK (as it should), which in turn is conditioned on MSVC, so I don't really expect this early return to take effect.

Open to remove/update this if you find this unnecessary/inaccurate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that conditional on MSVC is correct, this is not dependent on the MSVC generator nor the MSVC compiler, but rather if we are building for Windows. That said, the guard here is just avoid the unnecessary stats, which is a nice touch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be some old discussion about this back when the relevant part of the code was introduced:

https://reviews.llvm.org/D26255#596333:
Whether or not to use WIN32 or MSC_VER is always a tricky question. I would probably use MSC_VER in this case. Because WIN32 can be defined if you're using GCC / MinGW for example, and DIA won't won't work under those scenarios.

I agree that technically it's only the target platform that's relevant, but having played with it a bit more, it seems that the problem is not with DIA SDK, but rather with LLVM's DIA implementation (see cffff26 and its commit message). It relies on the ATL (<atlbase.h>) which is largely dependent on MS syntax like SEH __try/__except. (Though it could technically work if the non-MSVC-like compiler happens to support it?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I raised this is the cross-compiling scenario—that is building LLVM for Windows on other platforms—which is something we're actively experimenting with. However, based on my experiments WIN32 should be set if CMake is configured correctly so this check shouldn't pose a problem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context and confirmation! Yes, I believe that should be the case, which is suggested by CMake's documentation on this variable 1. I'll keep the WIN32 guard here then.

Footnotes

  1. https://cmake.org/cmake/help/latest/variable/WIN32.html


if(LLVM_WINSYSROOT)
set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH
"Path to the DIA SDK")
else()
set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
"Path to the DIA SDK")
endif()

find_path(DIASDK_INCLUDE_DIR
NAMES dia2.h
PATHS "${MSVC_DIA_SDK_DIR}/include"
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)

if(IS_DIRECTORY "${MSVC_DIA_SDK_DIR}")
set(_DIA_SDK_LIB_DIR "${MSVC_DIA_SDK_DIR}/lib")

if("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "arm64")
set(_DIA_SDK_LIB_DIR "${_DIA_SDK_LIB_DIR}/arm64")
elseif("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "arm")
set(_DIA_SDK_LIB_DIR "${_DIA_SDK_LIB_DIR}/arm")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_DIA_SDK_LIB_DIR "${_DIA_SDK_LIB_DIR}/amd64")
endif()

find_library(DIASDK_LIBRARIES
NAMES diaguids
PATHS "${_DIA_SDK_LIB_DIR}"
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
DIASDK
FOUND_VAR
DIASDK_FOUND
REQUIRED_VARS
DIASDK_INCLUDE_DIR
DIASDK_LIBRARIES
)
mark_as_advanced(DIASDK_INCLUDE_DIR DIASDK_LIBRARIES)

if(DIASDK_FOUND)
if(NOT TARGET DIASDK::Diaguids)
add_library(DIASDK::Diaguids UNKNOWN IMPORTED)
set_target_properties(DIASDK::Diaguids PROPERTIES
IMPORTED_LOCATION "${DIASDK_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${DIASDK_INCLUDE_DIR}"
)
endif()
endif()
3 changes: 3 additions & 0 deletions llvm/cmake/modules/LLVMConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ endif()
set(LLVM_WITH_Z3 @LLVM_WITH_Z3@)

set(LLVM_ENABLE_DIA_SDK @LLVM_ENABLE_DIA_SDK@)
if(LLVM_ENABLE_DIA_SDK)
find_package(DIASDK)
endif()

set(LLVM_NATIVE_ARCH @LLVM_NATIVE_ARCH@)

Expand Down
14 changes: 3 additions & 11 deletions llvm/lib/DebugInfo/PDB/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@ macro(add_pdb_impl_folder group)
endmacro()

if(LLVM_ENABLE_DIA_SDK)
include_directories(SYSTEM ${MSVC_DIA_SDK_DIR}/include)
set(LIBPDB_LINK_FOLDERS "${MSVC_DIA_SDK_DIR}\\lib")

if ("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "arm64")
set(LIBPDB_LINK_FOLDERS "${LIBPDB_LINK_FOLDERS}\\arm64")
elseif ("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "arm")
set(LIBPDB_LINK_FOLDERS "${LIBPDB_LINK_FOLDERS}\\arm")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(LIBPDB_LINK_FOLDERS "${LIBPDB_LINK_FOLDERS}\\amd64")
endif()
file(TO_CMAKE_PATH "${LIBPDB_LINK_FOLDERS}\\diaguids.lib" LIBPDB_ADDITIONAL_LIBRARIES)
find_package(DIASDK REQUIRED)
include_directories(SYSTEM "${DIASDK_INCLUDE_DIR}")
set(LIBPDB_ADDITIONAL_LIBRARIES DIASDK::Diaguids)

add_pdb_impl_folder(DIA
DIA/DIADataStream.cpp
Expand Down
Loading