Skip to content

[clang-repl] Add CLANG_ENABLE_EMUTLS_GET_ADDRESS cmake option - #217700

Open
pranavk wants to merge 1 commit into
llvm:mainfrom
pranavk:emutls1
Open

[clang-repl] Add CLANG_ENABLE_EMUTLS_GET_ADDRESS cmake option#217700
pranavk wants to merge 1 commit into
llvm:mainfrom
pranavk:emutls1

Conversation

@pranavk

@pranavk pranavk commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Guard the extern "C" declaration and reference to __emutls_get_address in IncrementalExecutor.cpp behind a new CMake option CLANG_ENABLE_EMUTLS_GET_ADDRESS, which is OFF by default.

This prevents link errors in environments/runtimes where __emutls_get_address is not available.

Replace all other guards with the new cmake option.

@pranavk
pranavk requested a review from brooksdavis August 20, 2026 17:15
@llvmorg-github-actions llvmorg-github-actions Bot added clang:frontend Language frontend issues, e.g. anything involving "Sema" bazel "Peripheral" support tier build system: utils/bazel labels Aug 20, 2026
Comment thread clang/CMakeLists.txt Outdated
option(CLANG_USE_EXPERIMENTAL_CONST_INTERP
"Use the new experimental constant interpreter for compile-time evaluation." OFF)

option(CLANG_ENABLE_EMUTLS_GET_ADDRESS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was wondering if we can detect that during configure time instead of having a separate option?

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

@vgvassilev vgvassilev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lgtm!

@pranavk
pranavk enabled auto-merge (squash) August 20, 2026 19:00
@pranavk

pranavk commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

looking at windows PR checks, for reasons i don't understand, the cmake check passes on Windows but then fails to find __emutls_get_address during link time. any ideas?

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
@vgvassilev

Copy link
Copy Markdown
Contributor

looking at windows PR checks, for reasons i don't understand, the cmake check passes on Windows but then fails to find __emutls_get_address during link time. any ideas?

@mstorsjo or @compnerd may be able to help us out.

@pranavk

pranavk commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

I changed the cmake check a bit to call the function. i don't have a windows machine but maybe it was getting optimized away? i will wait for the PR CI checks.

Comment thread clang/CMakeLists.txt
int main() {
return __emutls_get_address((void *)0) != (void *)0;
}
" CLANG_HAVE_EMUTLS_GET_ADDRESS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not understand this check. This basically attempts to determine it by means of a magically linked library rather than some condition. We should simply hoist the CPP condition into CMake and require an alternative answer to be explicit opt-in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For context, this is trying to fix #209717 which requires __emutls_get_address to be available at link time.

This PR is trying to move all that logic into cmake configure time.

There was another version of this PR that didn't have this check and just required explicitly setting -DCLANG_HAVE_EMUTLS_GET_ADDRESS= but @vgvassilev wanted to see if we could get that auto set during configure time

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The windows checks are now passing with the new version of this cmake check. Too bad I didn't preserve the commit history. The earlier check looked like this:

extern "C" void *__emutls_get_address(void *);
int main() {
    void *p = (void *)&__emutls_get_address;
    return p == (void *)0;
  }

So it seems like during the PR check on Windows, it was getting optimized away and we don't have any unresolved symbol in the end. Changing the check to call the function forces the linker to look for the definition at link time which is what the original PR is doing as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@compnerd let me know if there's anything I can do here. It's currently blocking our internal processes. So I would like to get this fixed sooner.

The current check takes care of @vgvassilev concerns without forcing downstream platforms to provide __emutls_get_address during link time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@compnerd ping

@compnerd

Copy link
Copy Markdown
Member

looking at windows PR checks, for reasons i don't understand, the cmake check passes on Windows but then fails to find __emutls_get_address during link time. any ideas?

@mstorsjo or @compnerd may be able to help us out.

I don't see the logs because they have been removed by the new run. What is "Windows" here (i.e. what environment)? MinGW? MSVC? Cygwin? Something else?

At least on MSVC, it shouldn't do that as weak resolution is not supported. MinGW does have a custom mechanism for weak symbols IIRC.

@pranavk

pranavk commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

I don't see the logs because they have been removed by the new run. What is "Windows" here (i.e. what environment)? MinGW? MSVC? Cygwin? Something else?

It's MSVC afaics that we are using in PR checkers.

@boomanaiden154

boomanaiden154 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Windows CI is an MSVC environment, minus the fact we build with clang-cl and lld-link.

@pranavk
pranavk disabled auto-merge August 21, 2026 16:11
pranavk added a commit that referenced this pull request Aug 21, 2026
This is needed to fix #209717.
#217700 tries to fix it cleanly
but it's blocked on review. Get this in while we wait for review.
llvm-upstreamsync Bot pushed a commit to qualcomm/cpullvm-toolchain that referenced this pull request Aug 21, 2026
This is needed to fix #209717.
llvm/llvm-project#217700 tries to fix it cleanly
but it's blocked on review. Get this in while we wait for review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bazel "Peripheral" support tier build system: utils/bazel clang:frontend Language frontend issues, e.g. anything involving "Sema"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants