Skip to content

[libc++] Fix locale-related compilation errors on NetBSD #143055

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 1 commit into
base: main
Choose a base branch
from

Conversation

alexrp
Copy link
Member

@alexrp alexrp commented Jun 6, 2025

To my knowledge, NetBSD is mostly like other BSDs, but doesn't have xlocale.h. I think c664a7f may have inadvertently broken this.

With this change, I was able to run zig-bootstrap to completion for x86_64-netbsd10.1-none.

@alexrp alexrp requested a review from a team as a code owner June 6, 2025 01:06
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jun 6, 2025
@alexrp
Copy link
Member Author

alexrp commented Jun 6, 2025

cc @ldionne

@llvmbot
Copy link
Member

llvmbot commented Jun 6, 2025

@llvm/pr-subscribers-libcxx

Author: Alex Rønne Petersen (alexrp)

Changes

To my knowledge, NetBSD is mostly like other BSDs, but doesn't have xlocale.h. I think c664a7f may have inadvertently broken this.


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

5 Files Affected:

  • (modified) libcxx/include/__locale_dir/locale_base_api.h (+2)
  • (modified) libcxx/include/__locale_dir/support/apple.h (+2)
  • (modified) libcxx/include/__locale_dir/support/bsd_like.h (-2)
  • (modified) libcxx/include/__locale_dir/support/freebsd.h (+2)
  • (added) libcxx/include/__locale_dir/support/netbsd.h (+20)
diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h
index bbc30b1cfe03f..c0ef6865fdee0 100644
--- a/libcxx/include/__locale_dir/locale_base_api.h
+++ b/libcxx/include/__locale_dir/locale_base_api.h
@@ -117,6 +117,8 @@
 #    include <__locale_dir/support/apple.h>
 #  elif defined(__FreeBSD__)
 #    include <__locale_dir/support/freebsd.h>
+#  elif defined(__NetBSD__)
+#    include <__locale_dir/support/netbsd.h>
 #  elif defined(_LIBCPP_MSVCRT_LIKE)
 #    include <__locale_dir/support/windows.h>
 #  elif defined(__Fuchsia__)
diff --git a/libcxx/include/__locale_dir/support/apple.h b/libcxx/include/__locale_dir/support/apple.h
index 62eb79c30d435..5216ed2ba758a 100644
--- a/libcxx/include/__locale_dir/support/apple.h
+++ b/libcxx/include/__locale_dir/support/apple.h
@@ -15,6 +15,8 @@
 #  pragma GCC system_header
 #endif
 
+#include <xlocale.h>
+
 #include <__locale_dir/support/bsd_like.h>
 
 #endif // _LIBCPP___LOCALE_DIR_SUPPORT_APPLE_H
diff --git a/libcxx/include/__locale_dir/support/bsd_like.h b/libcxx/include/__locale_dir/support/bsd_like.h
index 54eb397358d7a..e9168c91b4fb3 100644
--- a/libcxx/include/__locale_dir/support/bsd_like.h
+++ b/libcxx/include/__locale_dir/support/bsd_like.h
@@ -24,8 +24,6 @@
 #  include <wctype.h>
 #endif
 
-#include <xlocale.h>
-
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
diff --git a/libcxx/include/__locale_dir/support/freebsd.h b/libcxx/include/__locale_dir/support/freebsd.h
index 5c6e21e387271..5e24cbd29bb5a 100644
--- a/libcxx/include/__locale_dir/support/freebsd.h
+++ b/libcxx/include/__locale_dir/support/freebsd.h
@@ -15,6 +15,8 @@
 #  pragma GCC system_header
 #endif
 
+#include <xlocale.h>
+
 #include <__locale_dir/support/bsd_like.h>
 
 #endif // _LIBCPP___LOCALE_DIR_SUPPORT_FREEBSD_H
diff --git a/libcxx/include/__locale_dir/support/netbsd.h b/libcxx/include/__locale_dir/support/netbsd.h
new file mode 100644
index 0000000000000..190857f6f84fe
--- /dev/null
+++ b/libcxx/include/__locale_dir/support/netbsd.h
@@ -0,0 +1,20 @@
+//===-----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_NETBSD_H
+#define _LIBCPP___LOCALE_DIR_SUPPORT_NETBSD_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#include <__locale_dir/support/bsd_like.h>
+
+#endif // _LIBCPP___LOCALE_DIR_SUPPORT_NETBSD_H

@chestnykh
Copy link
Contributor

nit: we don't use trailing period in commit messages :)

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.

Meta comment: the reason this code was removed is that it was seen as dead code. We don't have CI builders for NetBSD and we also don't officially support that platform (https://libcxx.llvm.org/#platform-and-compiler-support). It's not that we don't want to, but we require at least one CI runner to exist in order to officially support a platform so that we can ensure that stuff works.

Is that something that NetBSD would be able to provide?

@alexrp
Copy link
Member Author

alexrp commented Jun 10, 2025

Is that something that NetBSD would be able to provide?

I have no idea; I'm not affiliated with the NetBSD project.

But we should probably still try to keep things working, given that NetBSD is listed here: https://llvm.org/docs/GettingStarted.html#hardware

@philnik777
Copy link
Contributor

Is that something that NetBSD would be able to provide?

I have no idea; I'm not affiliated with the NetBSD project.

But we should probably still try to keep things working, given that NetBSD is listed here: https://llvm.org/docs/GettingStarted.html#hardware

That is unrelated to the platforms libc++ supports. They are listed at https://libcxx.llvm.org/#platform-and-compiler-support.

@alexrp alexrp requested a review from ldionne June 10, 2025 12:09
@alexrp alexrp changed the title [libc++] Fix compilation for NetBSD. [libc++] Fix locale-related compilation errors on NetBSD Jun 10, 2025
@alexrp alexrp force-pushed the libcxx-netbsd branch 2 times, most recently from eb8fa17 to c64b80f Compare June 14, 2025 22:29
@alexrp alexrp force-pushed the libcxx-netbsd branch 3 times, most recently from 27e4d97 to 4fffd93 Compare June 21, 2025 12:10
alexrp added a commit that referenced this pull request Jun 23, 2025
…143549)

Even for EABI, NetBSD uses DWARF EH, not EHABI. This change matches the
Clang frontend behavior, and fixes link errors caused by incorrect
references to `__cxa_end_cleanup` rather than `_Unwind_Resume`.

With this change and #143055, I was able to run
[zig-bootstrap](https://github.com/ziglang/zig-bootstrap) to completion
for `arm-netbsd10.1-eabihf`.
Jaddyen pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 23, 2025
…lvm#143549)

Even for EABI, NetBSD uses DWARF EH, not EHABI. This change matches the
Clang frontend behavior, and fixes link errors caused by incorrect
references to `__cxa_end_cleanup` rather than `_Unwind_Resume`.

With this change and llvm#143055, I was able to run
[zig-bootstrap](https://github.com/ziglang/zig-bootstrap) to completion
for `arm-netbsd10.1-eabihf`.
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…lvm#143549)

Even for EABI, NetBSD uses DWARF EH, not EHABI. This change matches the
Clang frontend behavior, and fixes link errors caused by incorrect
references to `__cxa_end_cleanup` rather than `_Unwind_Resume`.

With this change and llvm#143055, I was able to run
[zig-bootstrap](https://github.com/ziglang/zig-bootstrap) to completion
for `arm-netbsd10.1-eabihf`.
To my knowledge, NetBSD is mostly like other BSDs, but doesn't have xlocale.h. I
think c664a7f may have inadvertently broken this.
@alexrp
Copy link
Member Author

alexrp commented Jul 22, 2025

@ldionne @philnik777 we would like to see this patch upstreamed in time for LLVM 21. Are there any outstanding concerns here?

dasimmet pushed a commit to dasimmet/zig that referenced this pull request Aug 4, 2025
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.

6 participants