https://github.com/pranavk updated https://github.com/llvm/llvm-project/pull/217700
>From ed5c5f299c1939f00c0c20cd2bd843f5bf161817 Mon Sep 17 00:00:00 2001 From: Pranav Kant <[email protected]> Date: Thu, 20 Aug 2026 10:03:36 -0700 Subject: [PATCH 1/2] [clang-repl] Detect __emutls_get_address availability at configure time Detect if __emutls_get_address is available in the compiler runtime at configure time via check_cxx_source_compiles (CLANG_HAVE_EMUTLS_GET_ADDRESS) and guard its extern "C" declaration and reference in IncrementalExecutor.cpp. This prevents link errors in environments/runtimes where __emutls_get_address is not available. TAG=agy CONV=dd895981-3d14-4e98-a942-6aedc8fbfd77 --- clang/CMakeLists.txt | 9 +++++++++ clang/include/clang/Config/config.h.cmake | 3 +++ clang/lib/Interpreter/IncrementalExecutor.cpp | 11 ++++------- .../gn/secondary/clang/include/clang/Config/BUILD.gn | 1 + .../clang/include/clang/Config/config.h | 3 +++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index 89f584c5dceaa..e44748d6db5b6 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -220,6 +220,15 @@ if( CLANG_HAVE_DLFCN_H ) cmake_pop_check_state() endif() +include(CheckCXXSourceCompiles) +check_cxx_source_compiles(" + extern \"C\" void *__emutls_get_address(void *); + int main() { + void *p = (void *)&__emutls_get_address; + return p == (void *)0; + } +" CLANG_HAVE_EMUTLS_GET_ADDRESS) + set(CLANG_RESOURCE_DIR "" CACHE STRING "Relative directory from the Clang binary to its resource files.") diff --git a/clang/include/clang/Config/config.h.cmake b/clang/include/clang/Config/config.h.cmake index 11b4096726f67..064d588a62030 100644 --- a/clang/include/clang/Config/config.h.cmake +++ b/clang/include/clang/Config/config.h.cmake @@ -95,4 +95,7 @@ /* Enable the experimental new constant interpreter by default */ #cmakedefine01 CLANG_USE_EXPERIMENTAL_CONST_INTERP +/* Define if __emutls_get_address is available in the compiler runtime */ +#cmakedefine01 CLANG_HAVE_EMUTLS_GET_ADDRESS + #endif diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp index 6d337e7848699..4563425756235 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.cpp +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -17,6 +17,7 @@ #endif // __EMSCRIPTEN__ #include "clang/Basic/TargetInfo.h" +#include "clang/Config/config.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/ToolChain.h" @@ -70,13 +71,9 @@ // in a static archive and nothing else references it, it is never linked in and // ORC's process-symbol lookup cannot resolve it. Referencing it here // force-links the archive member so it is present regardless of how the host -// provides it. Excluded where an emulated-TLS runtime is not guaranteed on the -// link line, so the reference would fail to link: non-Unix (MSVC has no such -// runtime), Emscripten (the wasm executor below does not use this JIT path), -// and AIX / z/OS (whose runtimes may not provide the symbol). On those hosts -// thread_locals instead rely on process-symbol lookup, unchanged from before. -#if defined(LLVM_ON_UNIX) && !defined(__EMSCRIPTEN__) && !defined(_AIX) && \ - !defined(__MVS__) && !defined(__FreeBSD__) +// provides it. Defined if available at configure time (CLANG_HAVE_EMUTLS_GET_ADDRESS). +// When unavailable, thread_locals instead rely on process-symbol lookup. +#if CLANG_HAVE_EMUTLS_GET_ADDRESS extern "C" void *__emutls_get_address(void *); static void *getEmuTLSGetAddressPtr() { return reinterpret_cast<void *>(&__emutls_get_address); diff --git a/llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn b/llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn index f8196d1b248e5..2ab6c603325fe 100644 --- a/llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn +++ b/llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn @@ -32,6 +32,7 @@ write_cmake_config("Config") { "CLANG_SYSTEMZ_DEFAULT_ARCH=z10", "PPC_LINUX_DEFAULT_IEEELONGDOUBLE=", "CLANG_USE_EXPERIMENTAL_CONST_INTERP=", + "CLANG_HAVE_EMUTLS_GET_ADDRESS=", ] if (clang_enable_static_analyzer) { diff --git a/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h b/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h index 7f7308f338966..be31546f93fe9 100644 --- a/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h +++ b/utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h @@ -105,6 +105,9 @@ /* Enable the experimental new constant interpreter by default */ #define CLANG_USE_EXPERIMENTAL_CONST_INTERP 0 +/* Define if __emutls_get_address is available in the compiler runtime */ +#define CLANG_HAVE_EMUTLS_GET_ADDRESS 0 + /* Directly provide definitions here behind platform preprocessor definitions. * The preprocessor conditions are sufficient to handle all of the configuration * on platforms targeted by Bazel, and defining these here more faithfully >From 99098fa7c3678fefebffef234fe966d88d49ae8c Mon Sep 17 00:00:00 2001 From: Pranav Kant <[email protected]> Date: Thu, 20 Aug 2026 11:55:51 -0700 Subject: [PATCH 2/2] clang-format --- clang/lib/Interpreter/IncrementalExecutor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp index 4563425756235..387ab57216498 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.cpp +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -71,8 +71,9 @@ // in a static archive and nothing else references it, it is never linked in and // ORC's process-symbol lookup cannot resolve it. Referencing it here // force-links the archive member so it is present regardless of how the host -// provides it. Defined if available at configure time (CLANG_HAVE_EMUTLS_GET_ADDRESS). -// When unavailable, thread_locals instead rely on process-symbol lookup. +// provides it. Defined if available at configure time +// (CLANG_HAVE_EMUTLS_GET_ADDRESS). When unavailable, thread_locals instead rely +// on process-symbol lookup. #if CLANG_HAVE_EMUTLS_GET_ADDRESS extern "C" void *__emutls_get_address(void *); static void *getEmuTLSGetAddressPtr() { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
