Skip to content

[libcxx] Recognize __UEFI__ predefine #139327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Prabhuk
Copy link
Contributor

@Prabhuk Prabhuk commented May 9, 2025

The new target triple x86_64-uefi does not set _WIN32 macro. It sets a
new predefine __UEFI__. Update platform.h to recognize if the target
object format is COFF based on __UEFI__ as well.

The new target triple x86_64-uefi does not set _WIN32 macro. It sets a
new predefine __UEFI__. Update platform to recognize if the target
object format is COFF based on __UEFI__ as well.
@Prabhuk Prabhuk requested a review from a team as a code owner May 9, 2025 21:34
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label May 9, 2025
@llvmbot
Copy link
Member

llvmbot commented May 9, 2025

@llvm/pr-subscribers-libcxx

Author: Prabhu Rajasekaran (Prabhuk)

Changes

The new target triple x86_64-uefi does not set _WIN32 macro. It sets a
new predefine UEFI. Update platform to recognize if the target
object format is COFF based on UEFI as well.


Full diff: https://github.com/llvm/llvm-project/pull/139327.diff

1 Files Affected:

  • (modified) libcxx/include/__configuration/platform.h (+1-1)
diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h
index f3c199dee172b..4a414d00e2208 100644
--- a/libcxx/include/__configuration/platform.h
+++ b/libcxx/include/__configuration/platform.h
@@ -20,7 +20,7 @@
 #  define _LIBCPP_OBJECT_FORMAT_ELF 1
 #elif defined(__MACH__)
 #  define _LIBCPP_OBJECT_FORMAT_MACHO 1
-#elif defined(_WIN32)
+#elif defined(_WIN32) || defined(__UEFI__)
 #  define _LIBCPP_OBJECT_FORMAT_COFF 1
 #elif defined(__wasm__)
 #  define _LIBCPP_OBJECT_FORMAT_WASM 1

@Prabhuk Prabhuk requested review from petrhosek and frobtech May 9, 2025 21:38
@ldionne
Copy link
Member

ldionne commented May 12, 2025

Is this introducing a new target? Are there going to be other changes for that target?

libc++ requires pre-commit CI to be set up for any newly supported target/platform, so I'd like to understand whether this falls into that category.

@Prabhuk
Copy link
Contributor Author

Prabhuk commented May 12, 2025

Is this introducing a new target? Are there going to be other changes for that target?

libc++ requires pre-commit CI to be set up for any newly supported target/platform, so I'd like to understand whether this falls into that category.

I introduced a new target triple "x86_64-uefi" in Clang and been incrementally landing changes to support this triple. The __UEFI__ predefine is set when x86_64-uefi triple is used. This triple does not set _WIN32 and other windows specific predefines. At this point, this triple is in developmental stage. It will be good to have a pre-commit CI set up when the support is mature. I do not know if we are quite there yet at this point. Thank you.

@Prabhuk
Copy link
Contributor Author

Prabhuk commented May 13, 2025

Is this introducing a new target? Are there going to be other changes for that target?
libc++ requires pre-commit CI to be set up for any newly supported target/platform, so I'd like to understand whether this falls into that category.

I introduced a new target triple "x86_64-uefi" in Clang and been incrementally landing changes to support this triple. The __UEFI__ predefine is set when x86_64-uefi triple is used. This triple does not set _WIN32 and other windows specific predefines. At this point, this triple is in developmental stage. It will be good to have a pre-commit CI set up when the support is mature. I do not know if we are quite there yet at this point. Thank you.

Adding a little bit more context. The way libcxx is used in the UEFI context I am experimenting with is header-only. We do not rely on the libcxx ABI and the changes I am expecting in the future will be limited to header files only. I would like to add precommit libcxx CI builders for UEFI when the support is mature but the builders will be limited to cover the header only scenarios which will presumably cover the changes I am expecting to land in libcxx.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

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

There is no such thing as using libc++ "header only". Even using basic functionality like std::sort requires libc++.so or libc++.a to be available, because we externally instantiate some specializations of std::sort into the built library. Failing to have a built library available will yield to linker errors when you do perfectly normal things like calling std::sort(int*, int*).

From your comment, this target is still experimental. I would rather add support in libc++ once you have a good understanding of the changes required to libc++ to support the target, and it looks like this might be a bit early for that. Otherwise, as far as the project is concerned, this patch is introducing dead code and our policy is to reject such patches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants