Skip to content

Commit

Permalink
Update llvm-libunwind to v18 (#102231)
Browse files Browse the repository at this point in the history
* Update llvm-libunwind to v18

* Apply all patches

* Update version file
  • Loading branch information
am11 authored May 30, 2024
1 parent d9d0e38 commit f36a477
Show file tree
Hide file tree
Showing 48 changed files with 1,211 additions and 660 deletions.
7 changes: 3 additions & 4 deletions src/native/external/llvm-libunwind-version.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
v16.0.2
https://github.com/llvm/llvm-project/releases/tag/llvmorg-16.0.2
v18.1.5
https://github.com/llvm/llvm-project/releases/tag/llvmorg-18.1.5

Apply https://github.com/dotnet/runtime/commit/1bafb60792b91747d9c2a9dd38461cf090a987a4
Apply https://github.com/dotnet/runtime/commit/0ee8827547405408b37d1aae2a83629c1632eea8
Apply https://github.com/dotnet/runtime/commit/a53805790a49f5bf52776dc81c1c83ec7f21ebce

7 changes: 0 additions & 7 deletions src/native/external/llvm-libunwind.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ set (LLVM_LIBUNWIND_SOURCES_BASE
src/libunwind.cpp
)

if(CLR_CMAKE_TARGET_APPLE)
set(LLVM_LIBUNWIND_SOURCES_BASE
${LLVM_LIBUNWIND_SOURCES_BASE}
src/Unwind_AppleExtras.cpp
)
endif()

set(LLVM_LIBUNWIND_ASM_SOURCES_BASE
src/UnwindRegistersRestore.S
src/UnwindRegistersSave.S
Expand Down
79 changes: 36 additions & 43 deletions src/native/external/llvm-libunwind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
# Setup Project
#===============================================================================

cmake_minimum_required(VERSION 3.13.4)
cmake_minimum_required(VERSION 3.20.0)

set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")

# Add path for custom modules
list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
"${CMAKE_CURRENT_SOURCE_DIR}/../runtimes/cmake/Modules"
"${LLVM_COMMON_CMAKE_UTILS}"
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
)
Expand All @@ -20,6 +21,7 @@ set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
"Specify path to libc++ source.")

include(GNUInstallDirs)
include(CheckSymbolExists)

#===============================================================================
# Setup CMake Options
Expand Down Expand Up @@ -50,6 +52,7 @@ option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF)
option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF)
option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF)
option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON)
option(LIBUNWIND_ENABLE_FRAME_APIS "Include libgcc-compatible frame apis." OFF)

set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
"Define suffix of library directory name (32/64)")
Expand All @@ -61,12 +64,9 @@ cmake_dependent_option(LIBUNWIND_INSTALL_SHARED_LIBRARY
"Install the shared libunwind library." ON
"LIBUNWIND_ENABLE_SHARED;LIBUNWIND_INSTALL_LIBRARY" OFF)

# TODO: Remove this after branching for LLVM 15
if(LIBUNWIND_SYSROOT OR LIBUNWIND_TARGET_TRIPLE OR LIBUNWIND_GCC_TOOLCHAIN)
message(WARNING "LIBUNWIND_SYSROOT, LIBUNWIND_TARGET_TRIPLE and LIBUNWIND_GCC_TOOLCHAIN are not supported anymore, please use the native CMake equivalents instead")
endif()

if (LIBUNWIND_ENABLE_SHARED)
if(MINGW)
set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-mingw.cfg.in")
elseif (LIBUNWIND_ENABLE_SHARED)
set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared.cfg.in")
else()
set(LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static.cfg.in")
Expand Down Expand Up @@ -97,6 +97,20 @@ endif()
option(LIBUNWIND_HIDE_SYMBOLS
"Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})

# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
# https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
check_symbol_exists(__mips_hard_float "" __MIPSHF)
check_symbol_exists(_ABIO32 "" __MIPS_O32)
if (__MIPSHF AND __MIPS_O32)
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
"#if __mips_fpr != 0\n"
"# error\n"
"#endif\n")
try_compile(MIPS_FPABI_FPXX ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
CMAKE_FLAGS -DCMAKE_C_LINK_EXECUTABLE='echo')
endif()

#===============================================================================
# Configure System
#===============================================================================
Expand All @@ -106,17 +120,17 @@ set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
${CMAKE_MODULE_PATH})

set(LIBUNWIND_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH
set(LIBUNWIND_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE STRING
"Path where built libunwind headers should be installed.")
set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
"Path where built libunwind runtime libraries should be installed.")

set(LIBUNWIND_SHARED_OUTPUT_NAME "unwind" CACHE STRING "Output name for the shared libunwind runtime library.")
set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind" CACHE STRING "Output name for the static libunwind runtime library.")

if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE})
set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH
set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
"Path where built libunwind libraries should be installed.")
if(LIBCXX_LIBDIR_SUBDIR)
string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR})
Expand All @@ -128,7 +142,7 @@ else()
else()
set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX})
endif()
set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH
set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE STRING
"Path where built libunwind libraries should be installed.")
endif()

Expand All @@ -140,6 +154,10 @@ set(LIBUNWIND_C_FLAGS "")
set(LIBUNWIND_CXX_FLAGS "")
set(LIBUNWIND_COMPILE_FLAGS "")
set(LIBUNWIND_LINK_FLAGS "")
set(LIBUNWIND_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
"Additional Compile only flags which can be provided in cache")
set(LIBUNWIND_ADDITIONAL_LIBRARIES "" CACHE STRING
"Additional libraries libunwind is linked to which can be provided in cache")

# Include macros for adding and removing libunwind flags.
include(HandleLibunwindFlags)
Expand Down Expand Up @@ -168,28 +186,6 @@ if (LIBUNWIND_ENABLE_CET)
endif()
endif()

# Get warning flags
add_compile_flags_if_supported(-W)
add_compile_flags_if_supported(-Wall)
add_compile_flags_if_supported(-Wchar-subscripts)
add_compile_flags_if_supported(-Wconversion)
add_compile_flags_if_supported(-Wmismatched-tags)
add_compile_flags_if_supported(-Wmissing-braces)
add_compile_flags_if_supported(-Wnewline-eof)
add_compile_flags_if_supported(-Wno-unused-function)
add_compile_flags_if_supported(-Wshadow)
add_compile_flags_if_supported(-Wshorten-64-to-32)
add_compile_flags_if_supported(-Wsign-compare)
add_compile_flags_if_supported(-Wsign-conversion)
add_compile_flags_if_supported(-Wstrict-aliasing=2)
add_compile_flags_if_supported(-Wstrict-overflow=4)
add_compile_flags_if_supported(-Wunused-parameter)
add_compile_flags_if_supported(-Wunused-variable)
add_compile_flags_if_supported(-Wwrite-strings)
add_compile_flags_if_supported(-Wundef)

add_compile_flags_if_supported(-Wno-suggest-override)

if (WIN32)
# The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
# silence the warning instead of cluttering the headers (which aren't
Expand All @@ -198,16 +194,8 @@ if (WIN32)
add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
endif()

if (LIBUNWIND_ENABLE_WERROR)
add_compile_flags_if_supported(-Werror)
add_compile_flags_if_supported(-WX)
else()
add_compile_flags_if_supported(-Wno-error)
add_compile_flags_if_supported(-WX-)
endif()

if (LIBUNWIND_ENABLE_PEDANTIC)
add_compile_flags_if_supported(-pedantic)
if (MIPS_FPABI_FPXX)
add_compile_flags(-mfp64)
endif()

# Get feature flags.
Expand Down Expand Up @@ -277,6 +265,11 @@ if (NOT LIBUNWIND_ENABLE_CROSS_UNWINDING)
add_compile_flags(-D_LIBUNWIND_IS_NATIVE_ONLY)
endif()

# Include stubs for __register_frame_info_bases and related
if (LIBUNWIND_ENABLE_FRAME_APIS)
add_compile_flags(-D_LIBUNWIND_SUPPORT_FRAME_APIS)
endif()

# Threading-support
if (NOT LIBUNWIND_ENABLE_THREADS)
add_compile_flags(-D_LIBUNWIND_HAS_NO_THREADS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,162 +6,10 @@

include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(HandleFlags)

unset(add_flag_if_supported)

# Mangle the name of a compiler flag into a valid CMake identifier.
# Ex: --std=c++11 -> STD_EQ_CXX11
macro(mangle_name str output)
string(STRIP "${str}" strippedStr)
string(REGEX REPLACE "^/" "" strippedStr "${strippedStr}")
string(REGEX REPLACE "^-+" "" strippedStr "${strippedStr}")
string(REGEX REPLACE "-+$" "" strippedStr "${strippedStr}")
string(REPLACE "-" "_" strippedStr "${strippedStr}")
string(REPLACE "=" "_EQ_" strippedStr "${strippedStr}")
string(REPLACE "+" "X" strippedStr "${strippedStr}")
string(TOUPPER "${strippedStr}" ${output})
endmacro()

# Remove a list of flags from all CMake variables that affect compile flags.
# This can be used to remove unwanted flags specified on the command line
# or added in other parts of LLVM's cmake configuration.
macro(remove_flags)
foreach(var ${ARGN})
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string(REPLACE "${var}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "${var}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REPLACE "${var}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
string(REPLACE "${var}" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
string(REPLACE "${var}" "" CMAKE_SHARED_MODULE_FLAGS "${CMAKE_SHARED_MODULE_FLAGS}")
remove_definitions(${var})
endforeach()
endmacro(remove_flags)

macro(check_flag_supported flag)
mangle_name("${flag}" flagname)
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
endmacro()

macro(append_flags DEST)
foreach(value ${ARGN})
list(APPEND ${DEST} ${value})
list(APPEND ${DEST} ${value})
endforeach()
endmacro()

# If the specified 'condition' is true then append the specified list of flags to DEST
macro(append_flags_if condition DEST)
if (${condition})
list(APPEND ${DEST} ${ARGN})
endif()
endmacro()

# Add each flag in the list specified by DEST if that flag is supported by the current compiler.
macro(append_flags_if_supported DEST)
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
append_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${DEST} ${flag})
endforeach()
endmacro()

# Add a macro definition if condition is true.
macro(define_if condition def)
if (${condition})
add_definitions(${def})
endif()
endmacro()

# Add a macro definition if condition is not true.
macro(define_if_not condition def)
if (NOT ${condition})
add_definitions(${def})
endif()
endmacro()

# Add a macro definition to the __config_site file if the specified condition
# is 'true'. Note that '-D${def}' is not added. Instead it is expected that
# the build include the '__config_site' header.
macro(config_define_if condition def)
if (${condition})
set(${def} ON)
set(LIBUNWIND_NEEDS_SITE_CONFIG ON)
endif()
endmacro()

macro(config_define_if_not condition def)
if (NOT ${condition})
set(${def} ON)
set(LIBUNWIND_NEEDS_SITE_CONFIG ON)
endif()
endmacro()

macro(config_define value def)
set(${def} ${value})
set(LIBUNWIND_NEEDS_SITE_CONFIG ON)
endmacro()

# Add a list of flags to all of 'CMAKE_CXX_FLAGS', 'CMAKE_C_FLAGS',
# 'LIBUNWIND_COMPILE_FLAGS' and 'LIBUNWIND_LINK_FLAGS'.
macro(add_target_flags)
foreach(value ${ARGN})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${value}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${value}")
list(APPEND LIBUNWIND_COMPILE_FLAGS ${value})
list(APPEND LIBUNWIND_LINK_FLAGS ${value})
endforeach()
endmacro()

# If the specified 'condition' is true then add a list of flags to
# all of 'CMAKE_CXX_FLAGS', 'CMAKE_C_FLAGS', 'LIBUNWIND_COMPILE_FLAGS'
# and 'LIBUNWIND_LINK_FLAGS'.
macro(add_target_flags_if condition)
if (${condition})
add_target_flags(${ARGN})
endif()
endmacro()

# Add all the flags supported by the compiler to all of
# 'CMAKE_CXX_FLAGS', 'CMAKE_C_FLAGS', 'LIBUNWIND_COMPILE_FLAGS'
# and 'LIBUNWIND_LINK_FLAGS'.
macro(add_target_flags_if_supported)
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
add_target_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag})
endforeach()
endmacro()

# Add a specified list of flags to both 'LIBUNWIND_COMPILE_FLAGS' and
# 'LIBUNWIND_LINK_FLAGS'.
macro(add_flags)
foreach(value ${ARGN})
list(APPEND LIBUNWIND_COMPILE_FLAGS ${value})
list(APPEND LIBUNWIND_LINK_FLAGS ${value})
endforeach()
endmacro()

# If the specified 'condition' is true then add a list of flags to both
# 'LIBUNWIND_COMPILE_FLAGS' and 'LIBUNWIND_LINK_FLAGS'.
macro(add_flags_if condition)
if (${condition})
add_flags(${ARGN})
endif()
endmacro()

# Add each flag in the list to LIBUNWIND_COMPILE_FLAGS and LIBUNWIND_LINK_FLAGS
# if that flag is supported by the current compiler.
macro(add_flags_if_supported)
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
add_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag})
endforeach()
endmacro()

# Add a list of flags to 'LIBUNWIND_COMPILE_FLAGS'.
macro(add_compile_flags)
foreach(f ${ARGN})
Expand Down Expand Up @@ -202,16 +50,6 @@ macro(add_c_flags_if condition)
endif()
endmacro()

# For each specified flag, add that flag to 'LIBUNWIND_C_FLAGS' if the
# flag is supported by the C compiler.
macro(add_c_compile_flags_if_supported)
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
check_c_compiler_flag("${flag}" "C_SUPPORTS_${flagname}_FLAG")
add_c_flags_if(C_SUPPORTS_${flagname}_FLAG ${flag})
endforeach()
endmacro()

# Add a list of flags to 'LIBUNWIND_CXX_FLAGS'.
macro(add_cxx_flags)
foreach(f ${ARGN})
Expand Down Expand Up @@ -276,20 +114,3 @@ macro(add_library_flags_if condition)
add_library_flags(${ARGN})
endif()
endmacro()

# Turn a comma separated CMake list into a space separated string.
macro(split_list listname)
string(REPLACE ";" " " ${listname} "${${listname}}")
endmacro()

# For each specified flag, add that compile flag to the provided target.
# The flags are added with the given visibility, i.e. PUBLIC|PRIVATE|INTERFACE.
function(target_add_compile_flags_if_supported target visibility)
foreach(flag ${ARGN})
mangle_name("${flag}" flagname)
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
if (CXX_SUPPORTS_${flagname}_FLAG)
target_compile_options(${target} ${visibility} ${flag})
endif()
endforeach()
endfunction()
Loading

0 comments on commit f36a477

Please sign in to comment.