Skip to content

Conversation

ysbaddaden
Copy link

Adds a couple functions to LLVM-C to expose the Thread Local Storage options that are only available though the C++ API for now:

  • LLVMTargetMachineOptionsSetEmulatedTLS
  • LLVMTargetMachineOptionsSetEnableTLSDESC

We plan to use these options in @crystal-lang to reliably compile and cross compile to some targets regardless of downstream patches in OpenBSD or MingGW for example.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@nikic
Copy link
Contributor

nikic commented Sep 29, 2025

Can you please add a release note entry under https://github.com/llvm/llvm-project/blob/main/llvm/docs/ReleaseNotes.md#changes-to-the-c-api?

@ysbaddaden ysbaddaden force-pushed the feature/llvm-c-target-machine-options-set-emulated-tls branch from f052645 to 13b625f Compare September 29, 2025 10:10
@ysbaddaden
Copy link
Author

@nikic Of course. I just did. I'm not so sure about the phrasing, though.

Comment on lines +43 to +44
bool EmulatedTLS;
bool EnableTLSDESC;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm... I think these need to be std::optional and only used if the corresponding functions are called? Otherwise we're not going to respect hasDefaultEmulatedTLS and hasDefaultTLSDESC anymore, right?

Copy link
Author

Choose a reason for hiding this comment

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

I investigated a bit: LLVMCreateTargetMachineWithOptions uses the default llvm::TargetOptions constructor that explicitly initializes both options to false already. Setting them again to false again is a NOOP.

I understand that the frontend is responsible to call hasDefaultEmulatedTLS or hasDefaultTLSDESC as a fallback value when unspecified. Clang appears to do that.

Now, I could change both options to be std::optional and have LLVMCreateTargetMachineWithOptions set the options when they have been explicit set, and fallback to hasDefaultEmulatedTLS and hasDefaultTLSDESC otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants