Skip to content
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

[libc] Support configurable errno modes #98287

Merged
merged 10 commits into from
Jul 13, 2024
Merged

Conversation

petrhosek
Copy link
Member

Rather than selecting the errno implementation based on the platform which doesn't provide the necessary flexibility, make it configurable.

The errno value location is returned by __errno_location() which is a solution used by glibc.

Rather than selecting the errno implementation based on the platform
which doesn't provide the necessary flexibility, make it configurable.

The errno value location is returned by __errno_location() which is a
solution used by glibc.
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 10, 2024

@llvm/pr-subscribers-libc

Author: Petr Hosek (petrhosek)

Changes

Rather than selecting the errno implementation based on the platform which doesn't provide the necessary flexibility, make it configurable.

The errno value location is returned by __errno_location() which is a solution used by glibc.


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

8 Files Affected:

  • (modified) libc/config/baremetal/config.json (+5)
  • (modified) libc/config/config.json (+6)
  • (modified) libc/config/gpu/config.json (+5)
  • (modified) libc/docs/configure.rst (+2)
  • (modified) libc/include/errno.h.def (+6-12)
  • (modified) libc/src/errno/CMakeLists.txt (+12)
  • (modified) libc/src/errno/libc_errno.cpp (+81-25)
  • (modified) libc/src/errno/libc_errno.h (+1)
diff --git a/libc/config/baremetal/config.json b/libc/config/baremetal/config.json
index dda4c42425755..9e66b682039f7 100644
--- a/libc/config/baremetal/config.json
+++ b/libc/config/baremetal/config.json
@@ -1,4 +1,9 @@
 {
+  "errno": {
+    "LIBC_CONF_ERRNO_MODE": {
+      "value": "LIBC_ERRNO_MODE_LOCATION"
+    }
+  },
   "printf": {
     "LIBC_CONF_PRINTF_DISABLE_FLOAT": {
       "value": true
diff --git a/libc/config/config.json b/libc/config/config.json
index e8feab20175f4..6c59ce95fdcc4 100644
--- a/libc/config/config.json
+++ b/libc/config/config.json
@@ -1,4 +1,10 @@
 {
+  "errno": {
+    "LIBC_CONF_ERRNO_MODE": {
+      "value": "",
+      "doc": "The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_NONE, LIBC_ERRNO_MODE_INTERNAL, LIBC_ERRNO_MODE_EXTERNAL, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_GLOBAL, and LIBC_ERRNO_MODE_LOCATION."
+    }
+  },
   "printf": {
     "LIBC_CONF_PRINTF_DISABLE_FLOAT": {
       "value": false,
diff --git a/libc/config/gpu/config.json b/libc/config/gpu/config.json
index 71107d26ea7ab..390aafad92b95 100644
--- a/libc/config/gpu/config.json
+++ b/libc/config/gpu/config.json
@@ -1,4 +1,9 @@
 {
+  "errno": {
+    "LIBC_CONF_ERRNO_MODE": {
+      "value": "LIBC_ERRNO_MODE_GLOBAL"
+    }
+  },
   "printf": {
     "LIBC_CONF_PRINTF_DISABLE_FLOAT": {
       "value": true
diff --git a/libc/docs/configure.rst b/libc/docs/configure.rst
index 9c641ef94570f..e1aaa28ee9b91 100644
--- a/libc/docs/configure.rst
+++ b/libc/docs/configure.rst
@@ -28,6 +28,8 @@ to learn about the defaults for your platform and target.
 * **"codegen" options**
     - ``LIBC_CONF_ENABLE_STRONG_STACK_PROTECTOR``: Enable -fstack-protector-strong to defend against stack smashing attack.
     - ``LIBC_CONF_KEEP_FRAME_POINTER``: Keep frame pointer in functions for better debugging experience.
+* **"errno" options**
+    - ``LIBC_CONF_ERRNO_MODE``: The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_NONE, LIBC_ERRNO_MODE_INTERNAL, LIBC_ERRNO_MODE_EXTERNAL, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_GLOBAL, and LIBC_ERRNO_MODE_LOCATION.
 * **"malloc" options**
     - ``LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE``: Default size for the constinit freelist buffer used for the freelist malloc implementation (default 1o 1GB).
 * **"math" options**
diff --git a/libc/include/errno.h.def b/libc/include/errno.h.def
index 1f7120e63bfc9..298f02116a25f 100644
--- a/libc/include/errno.h.def
+++ b/libc/include/errno.h.def
@@ -25,18 +25,12 @@
 #include "llvm-libc-macros/generic-error-number-macros.h"
 #endif
 
-#if defined(__AMDGPU__) || defined(__NVPTX__)
-extern int __llvmlibc_errno; // Not thread_local!
-#else
-#ifdef __cplusplus
-extern "C" {
-extern thread_local int __llvmlibc_errno;
-}
-#else
-extern _Thread_local int __llvmlibc_errno;
-#endif // __cplusplus
-#endif
+__BEGIN_C_DECLS
+
+int *__errno_location(void) __NOEXCEPT;
+
+__END_C_DECLS
 
-#define errno __llvmlibc_errno
+#define errno (*__errno_location())
 
 #endif // LLVM_LIBC_ERRNO_H
diff --git a/libc/src/errno/CMakeLists.txt b/libc/src/errno/CMakeLists.txt
index 2622e51261cc3..ca049143874ac 100644
--- a/libc/src/errno/CMakeLists.txt
+++ b/libc/src/errno/CMakeLists.txt
@@ -9,6 +9,17 @@ if(LLVM_LIBC_FULL_BUILD)
   set(full_build_flag "-DLIBC_FULL_BUILD")
 endif()
 
+if(LIBC_CONF_ERRNO_MODE)
+  set(errno_config_copts "-DLIBC_ERRNO_MODE=${LIBC_CONF_ERRNO_MODE}")
+else()
+  if(LLVM_LIBC_FULL_BUILD)
+    set(errno_mode "LIBC_ERRNO_MODE_THREAD_LOCAL")
+  else()
+    set(errno_mode "LIBC_ERRNO_MODE_EXTERNAL")
+  endif()
+  set(errno_config_copts "-DLIBC_ERRNO_MODE=${errno_mode}")
+endif()
+
 add_entrypoint_object(
   errno
   SRCS
@@ -17,6 +28,7 @@ add_entrypoint_object(
     libc_errno.h     # Include this
   COMPILE_OPTIONS
     ${full_build_flag}
+    ${errno_config_copts}
   DEPENDS
     libc.hdr.errno_macros
     libc.src.__support.common
diff --git a/libc/src/errno/libc_errno.cpp b/libc/src/errno/libc_errno.cpp
index bd1438c226143..ccc7467ed22ff 100644
--- a/libc/src/errno/libc_errno.cpp
+++ b/libc/src/errno/libc_errno.cpp
@@ -9,44 +9,100 @@
 #include "libc_errno.h"
 #include "src/__support/CPP/atomic.h"
 
-#ifdef LIBC_TARGET_ARCH_IS_GPU
-// LIBC_THREAD_LOCAL on GPU currently does nothing. So essentially this is just
-// a global errno for gpu to use for now.
+#define LIBC_ERRNO_MODE_NONE 0x01
+#define LIBC_ERRNO_MODE_INTERNAL 0x02
+#define LIBC_ERRNO_MODE_EXTERNAL 0x04
+#define LIBC_ERRNO_MODE_THREAD_LOCAL 0x08
+#define LIBC_ERRNO_MODE_GLOBAL 0x10
+#define LIBC_ERRNO_MODE_LOCATION 0x20
+
+#ifndef LIBC_ERRNO_MODE
+#error LIBC_ERRNO_MODE is not defined
+#endif
+
+#if LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_NONE && \
+    LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_INTERNAL && \
+    LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_EXTERNAL && \
+    LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_THREAD_LOCAL && \
+    LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_GLOBAL && \
+    LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_LOCATION
+#error LIBC_ERRNO_MODE must be one of the following values: \
+LIBC_ERRNO_MODE_NONE, \
+LIBC_ERRNO_MODE_INTERNAL, \
+LIBC_ERRNO_MODE_EXTERNAL, \
+LIBC_ERRNO_MODE_THREAD_LOCAL, \
+LIBC_ERRNO_MODE_GLOBAL, \
+LIBC_ERRNO_MODE_LOCATION
+#endif
+
+namespace LIBC_NAMESPACE {
+
+// Define the global `libc_errno` instance.
+Errno libc_errno;
+
+#if LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_NONE
+
 extern "C" {
-LIBC_THREAD_LOCAL LIBC_NAMESPACE::cpp::Atomic<int> __llvmlibc_errno;
+const int __llvmlibc_errno = 0;
+int *__errno_location(void) { return &__llvmlibc_errno; }
 }
 
-void LIBC_NAMESPACE::Errno::operator=(int a) {
-  __llvmlibc_errno.store(a, cpp::MemoryOrder::RELAXED);
+void Errno::operator=(int) {}
+Errno::operator int() { return 0; }
+
+#elif LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_INTERNAL
+
+LIBC_THREAD_LOCAL int __llvmlibc_internal_errno;
+
+extern "C" {
+int *__errno_location(void) { return &__llvmlibc_internal_errno; }
 }
-LIBC_NAMESPACE::Errno::operator int() {
-  return __llvmlibc_errno.load(cpp::MemoryOrder::RELAXED);
+
+void Errno::operator=(int a) { __llvmlibc_internal_errno = a; }
+Errno::operator int() { return __llvmlibc_internal_errno; }
+
+#elif LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_EXTERNAL
+
+extern "C" {
+int *__errno_location(void) { return &errno; }
 }
 
-#elif !defined(LIBC_COPT_PUBLIC_PACKAGING)
-// This mode is for unit testing.  We just use our internal errno.
-LIBC_THREAD_LOCAL int __llvmlibc_internal_errno;
+void Errno::operator=(int a) { errno = a; }
+Errno::operator int() { return errno; }
 
-void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_internal_errno = a; }
-LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_internal_errno; }
+#elif LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_THREAD_LOCAL
 
-#elif defined(LIBC_FULL_BUILD)
-// This mode is for public libc archive, hermetic, and integration tests.
-// In full build mode, we provide the errno storage ourselves.
 extern "C" {
 LIBC_THREAD_LOCAL int __llvmlibc_errno;
+int *__errno_location(void) { return &__llvmlibc_errno; }
 }
 
-void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_errno = a; }
-LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_errno; }
+void Errno::operator=(int a) { __llvmlibc_errno = a; }
+Errno::operator int() { return __llvmlibc_errno; }
 
-#else
-void LIBC_NAMESPACE::Errno::operator=(int a) { errno = a; }
-LIBC_NAMESPACE::Errno::operator int() { return errno; }
+#elif LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_GLOBAL
 
-#endif // LIBC_FULL_BUILD
+extern "C" {
+LIBC_NAMESPACE::cpp::Atomic<int> __llvmlibc_errno;
+int *__errno_location(void) { return &__llvmlibc_errno; }
+}
+
+void Errno::operator=(int a) {
+  __llvmlibc_errno.store(a, cpp::MemoryOrder::RELAXED);
+}
+Errno::operator int() {
+  return __llvmlibc_errno.load(cpp::MemoryOrder::RELAXED);
+}
+
+#elif LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_LOCATION
+
+extern "C" {
+int *__errno_location(void);
+}
+
+void Errno::operator=(int a) { *__errno_location() = a; }
+Errno::operator int() { return *__errno_location(); }
+
+#endif
 
-namespace LIBC_NAMESPACE {
-// Define the global `libc_errno` instance.
-Errno libc_errno;
 } // namespace LIBC_NAMESPACE
diff --git a/libc/src/errno/libc_errno.h b/libc/src/errno/libc_errno.h
index df67ea3b42faa..a5c1e3e485407 100644
--- a/libc/src/errno/libc_errno.h
+++ b/libc/src/errno/libc_errno.h
@@ -31,6 +31,7 @@
 // - Still depend on libc.src.errno.errno
 
 namespace LIBC_NAMESPACE {
+
 struct Errno {
   void operator=(int);
   operator int();

@petrhosek
Copy link
Member Author

This is an alternative to #98130 which was suggested by @frobtech.

Copy link

github-actions bot commented Jul 10, 2024

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 062844615db5e141da118c1ad780bf102537f40a 1ff0acc44a2443ff87ae2decad282b0a604ca5f6 --extensions cpp,h -- libc/src/errno/errno.h libc/src/errno/libc_errno.cpp libc/src/errno/libc_errno.h
View the diff from clang-format here.
diff --git a/libc/src/errno/libc_errno.cpp b/libc/src/errno/libc_errno.cpp
index f7bd3a3b9e..12e5637ed1 100644
--- a/libc/src/errno/libc_errno.cpp
+++ b/libc/src/errno/libc_errno.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "libc_errno.h"
-#include "src/errno/errno.h"
 #include "src/__support/macros/config.h"
+#include "src/errno/errno.h"
 
 // libc never stores a value; `errno` macro uses get link-time failure.
 #define LIBC_ERRNO_MODE_UNDEFINED 1

#define LIBC_ERRNO_MODE_LOCATION 0x20

#ifndef LIBC_ERRNO_MODE
#error LIBC_ERRNO_MODE is not defined
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a new flag, so I think we should provide the default value for LIBC_ERRNO_MODE which matches the current behavior instead of errors to not break downstream users.

#ifndef LIBC_ERRNO_MODE
#ifndef LIBC_COPT_PUBLIC_PACKAGING
// This mode is for unit testing. We just use our internal errno.
#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_INTERNAL
#elif defined(LIBC_FULL_BUILD)
// In full build mode, we provide the errno storage ourselves.
#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_THREAD_LOCAL
#else
#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_EXTERNAL
#endif
#endif // LIBC_ERRNO_MODE

Then you can remove the default setting in the CMakeLists.txt.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@jhuber6 jhuber6 left a comment

Choose a reason for hiding this comment

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

I like the concept, we mostly provide a global errno just to make things like libc++ happy. Though maybe it would be better to disable it there as well...

libc/config/baremetal/config.json Show resolved Hide resolved
"errno": {
"LIBC_CONF_ERRNO_MODE": {
"value": "",
"doc": "The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_NONE, LIBC_ERRNO_MODE_INTERNAL, LIBC_ERRNO_MODE_EXTERNAL, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_GLOBAL, and LIBC_ERRNO_MODE_SYSTEM."
Copy link
Contributor

Choose a reason for hiding this comment

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

I really think this needs to not only enumerate the modes but document what each one means. That would make this spot the right place to bikeshed the names, none of which I really like so far.

Perhaps:

  • UNDEFINED: libc never stores a value; errno macro uses get link-time failure
  • EXTERNAL_ABI: embedder must define int *__llvm_libc_errno(void); C function
  • THREAD_LOCAL: libc maintains per-thread state (requires C++ thread_local support for libc implementation code)
  • SHARED_ATOMIC: libc maintains an atomic_int used by all threads, contrary to standard C semantics (requires use of atomics in libc implementation code, may produce libcalls an embedder must supply)
  • SHARED_THREAD_UNSAFE: libc maintains a plain int used by all threads, contrary to standard C semantics unless always single-threaded; nothing prevents data races
  • SYSTEM_HEADER: In overlay mode, system <errno.h> errno macro is used directly by libc. In fullbuild mode, effectively the same as EXTERNAL_ABI (or perhaps we make it an error to choose this in fullbuild mode).

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you think it makes sense to distinguish the "shared atomic" and "shared thread unsafe" modes? Right now these are only used by the GPU port which uses the atomic version. Specifically the only reason for the "shared thread unsafe" mode seems to be avoiding the use of atomics, but we already use those elsewhere so I'm not sure how useful that is.

Copy link
Contributor

Choose a reason for hiding this comment

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

Today's "baremetal" is a very specific set of choices about an embedded-style use case. I'm confident that there will in the long run be embedded-style use cases that are purely single-threaded and want to avoid the overhead (or need for useless libcall stubs that do nothing) of atomics. I think it will certainly be the right thing for all libc code that might ever be useful in some minimal embedded context to be configurable to avoid atomics at the cost of any kind of thread safety. I don't think it will ever be wise enough to be acceptable to "achieve" that via hacks like -DLIBC_THREAD_LOCAL= or making cpp::Atomic configurable to itself not actually be atomic. Instead, I think each and every case (so far, rand and errno) merits its own intentional and explicit configuration choice so in each context someone has to decide what semantics, and tradeoffs between formally standards-compliant and/or de facto norm semantics and other context-specific factors, are right for them.

For today, it doesn't matter if we support everything that we should in principle support in terms of configuration options. The taxonomy above I think covers all the options for errno in particular that I anticipate we will support long term. The subset of THREAD_LOCAL, SHARED_ATOMIC, and SHARED_THREAD_UNSAFE is probably a common vocabulary that makes sense for the broader general class of cases that includes rand, while the other options here are idiosyncratic to errno.

libc/src/errno/libc_errno.cpp Outdated Show resolved Hide resolved
LIBC_ERRNO_MODE_SYSTEM
#endif

namespace LIBC_NAMESPACE {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget to update to LIBC_NAMESPACE_DECL when that stuff lands. (I'm not sure it technically matters as long as it was done in libc_errno.h, but I think uniformity it what we're going for regardless.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack, I expect this change is going to land after that one.

libc/src/errno/libc_errno.cpp Show resolved Hide resolved
libc/src/errno/libc_errno.cpp Outdated Show resolved Hide resolved
libc/src/errno/libc_errno.cpp Outdated Show resolved Hide resolved
void Errno::operator=(int a) { __libc_errno = a; }
Errno::operator int() { return __libc_errno; }

#elif LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_GLOBAL
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this mode should be called "SHARED_ATOMIC" or something like that. ISTM there should be another "SHARED_THREAD_UNSAFE" or the like that's just a plain variable.

Again, these variables should have names appropriate for a local linkage implementation detail, and it doesn't hurt to use different names specific to each different implementation here.

libc/src/errno/libc_errno.cpp Outdated Show resolved Hide resolved
extern "C" {
LIBC_THREAD_LOCAL int __llvmlibc_errno;
int *__llvm_libc_errno(void);
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need a declaration here. It's already in <errno.h>.

Copy link
Member Author

@petrhosek petrhosek Jul 11, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's a policy about using a hdr/errno_macros.h wrapper instead of doing it directly, but yeah. In some fashion, the authoritative header file declaration of any public ABI function you're defining really ought to be in scope in the implementation file.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there may be a case to be made that there should be an __llvm_libc_errno.h in this directory to declare the function like we have for other public (ABI) functions. But then that would go with the __llvm_libc_errno.cpp implementation file for just that function, which isn't what we want to do since we want it and the Errno internal class implemented together.

I'm not sure what the precedent is (or if there is any yet) for other non-functions in the API, i.e. having an errno.h that's responsible for errno inside the libc implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what the precedent is (or if there is any yet) for other non-functions in the API, i.e. having an errno.h that's responsible for errno inside the libc implementation.

We use https://github.com/llvm/llvm-project/blob/0b15f89182a4b2a4c46ad207fa2e282ad35f12ee/libc/src/errno/libc_errno.h for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

That header has that name because it's implementing LIBC_NAMESPACE::libc_errno. It's true that today it does include hdr/errno_macros.h, but that only defines the E* constants (necessarily, i.e. in all build modes).

That's a different issue from whether when there is a variable (or variable-like API, such as errno) in the public API, we have a symbol_name.h header for it in src/something/ like we do for functions in the public API.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I introduced src/errno/errno.h in the latest revision.

return __llvmlibc_errno.load(cpp::MemoryOrder::RELAXED);

extern "C" {
int *__llvm_libc_errno() { return &global_errno; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this is kind of a problem. You can't really make the user access via the function call (i.e. the errno macro--the only API) be atomic. The errno macro has to be a "modifiable lvalue" (equivalent to C++ lvalue reference) of type int. If cpp::Atomic<T> lets you convert its address to T* implicitly somehow that's highly questionable.

So in reality I don't think SHARED_ATOMIC is actually an option here, unlike the general case a la rand. There is no way in the C API/ABI to force the user to use an accessor other than normal pointer dereference. (A C++-only definition of errno could be like libc_errno and turn loads and stores into library calls, but there's no way to do that in C.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was just looking at that. cpp::Atomic<T> lets you access the underlying value but accessing the value that way won't be atomic so I don't think this is really viable.

Copy link
Member Author

Choose a reason for hiding this comment

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

I switched to using just regular global.

@@ -1,4 +1,10 @@
{
"errno": {
"LIBC_CONF_ERRNO_MODE": {
"value": "",
Copy link
Contributor

Choose a reason for hiding this comment

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

it would probably be best to make the default value LIBC_ERRNO_MODE_THREAD_LOCAL

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree but the problem is that we currently don't have any mechanism to distinguish the overlay from the full build mode, and in the overlay mode we want to default to LIBC_ERRNO_MODE_SYSTEM.

@@ -28,6 +28,13 @@ to learn about the defaults for your platform and target.
* **"codegen" options**
- ``LIBC_CONF_ENABLE_STRONG_STACK_PROTECTOR``: Enable -fstack-protector-strong to defend against stack smashing attack.
- ``LIBC_CONF_KEEP_FRAME_POINTER``: Keep frame pointer in functions for better debugging experience.
* **"errno" options**
- ``LIBC_CONF_ERRNO_MODE``: The implementation used for errno, acceptable values are:
Copy link
Contributor

Choose a reason for hiding this comment

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

this file gets auto-generated, so the docs here need to be also in the json file

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think JSON is particularly suited for multiline strings so I moved the explanation of different modes as comments to the implementation file.

libc/src/errno/libc_errno.cpp Show resolved Hide resolved
Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

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

LGTM

libc/src/errno/libc_errno.cpp Show resolved Hide resolved
Copy link
Contributor

@frobtech frobtech left a comment

Choose a reason for hiding this comment

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

LGTM now. I think we could refine a little how we make the overlay vs full mode setting interact with the option, but it's a little hairy to decide what we want and it doesn't seem crucial. Likewise I think we should clarify and fully specify the plan about per-function/symbol headers and how that relates to errno/__llvm_libc_errno inside the tree. But that too is not urgent. When we do that we should start using -Wprototypes or whatever it is that complains if we define __llvm_libc_errno without a prior header declaration being in scope.

@petrhosek petrhosek merged commit 6925849 into llvm:main Jul 13, 2024
4 of 7 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 13, 2024

LLVM Buildbot has detected a new failure on builder libc-aarch64-ubuntu-dbg running on libc-aarch64-ubuntu while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/104/builds/2085

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile
-- Configuring done
-- Generating done
-- Build files have been written to: /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/build
@@@BUILD_STEP build libc@@@
Running: ninja libc
[1/390] Building CXX object projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o
FAILED: projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_18_0_0_git -D_DEBUG -Iprojects/libc/src/errno -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/errno -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc -isystem projects/libc/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fpie -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=c++17 -MD -MT projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -MF projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o.d -o projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/errno/libc_errno.cpp
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/errno/libc_errno.cpp:91:32: error: use of undeclared identifier 'errno'
void Errno::operator=(int a) { errno = a; }
                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-project/libc/src/errno/libc_errno.cpp:92:32: error: use of undeclared identifier 'errno'
Errno::operator int() { return errno; }
                               ^
2 errors generated.
[2/390] Building CXX object projects/libc/src/__support/OSUtil/linux/CMakeFiles/libc.src.__support.OSUtil.linux.linux_util.dir/fcntl.cpp.o
[3/390] Building CXX object projects/libc/src/__support/File/linux/CMakeFiles/libc.src.__support.File.linux.file.dir/file.cpp.o
[4/390] Building CXX object projects/libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o
[5/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetround.dir/fesetround.cpp.o
[6/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetexceptflag.dir/fesetexceptflag.cpp.o
[7/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetround.dir/fegetround.cpp.o
[8/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fetestexceptflag.dir/fetestexceptflag.cpp.o
[9/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetenv.dir/fesetenv.cpp.o
[10/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetenv.dir/fegetenv.cpp.o
[11/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fedisableexcept.dir/fedisableexcept.cpp.o
[12/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feclearexcept.dir/feclearexcept.cpp.o
[13/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetexcept.dir/fesetexcept.cpp.o
[14/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feupdateenv.dir/feupdateenv.cpp.o
[15/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feholdexcept.dir/feholdexcept.cpp.o
[16/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fetestexcept.dir/fetestexcept.cpp.o
[17/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetexceptflag.dir/fegetexceptflag.cpp.o
[18/390] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feraiseexcept.dir/feraiseexcept.cpp.o
ninja: build stopped: subcommand failed.
['ninja', 'libc'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 164, in step
    yield
  File "../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 121, in main
    run_command(['ninja', 'libc'])
  File "../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 179, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu/llvm-zorg/zorg/buildbot/builders/annotated/util.py", line 49, in report_run_cmd
    subprocess.check_call(cmd, shell=shell, *args, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 190, in check_call

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 13, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian running on libc-x86_64-debian while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/43/builds/2045

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Performing Test HAVE_PTHREAD_AFFINITY -- success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build
@@@BUILD_STEP build libc@@@
Running: ninja libc
[1/363] Building CXX object projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o
FAILED: projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/src/errno -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/llvm-project/libc/src/errno -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/build/projects/libc/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -fpie -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=c++17 -MD -MT projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -MF projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o.d -o projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/llvm-project/libc/src/errno/libc_errno.cpp
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/llvm-project/libc/src/errno/libc_errno.cpp:91:32: error: use of undeclared identifier 'errno'
void Errno::operator=(int a) { errno = a; }
                               ^
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian/llvm-project/libc/src/errno/libc_errno.cpp:92:32: error: use of undeclared identifier 'errno'
Errno::operator int() { return errno; }
                               ^
2 errors generated.
[2/363] Building CXX object projects/libc/src/__support/OSUtil/linux/CMakeFiles/libc.src.__support.OSUtil.linux.linux_util.dir/fcntl.cpp.o
[3/363] Building CXX object projects/libc/src/inttypes/CMakeFiles/libc.src.inttypes.strtoimax.dir/strtoimax.cpp.o
[4/363] Building CXX object projects/libc/src/inttypes/CMakeFiles/libc.src.inttypes.strtoumax.dir/strtoumax.cpp.o
[5/363] Building CXX object projects/libc/src/__support/File/linux/CMakeFiles/libc.src.__support.File.linux.file.dir/file.cpp.o
[6/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetexceptflag.dir/fesetexceptflag.cpp.o
[7/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feclearexcept.dir/feclearexcept.cpp.o
[8/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fedisableexcept.dir/fedisableexcept.cpp.o
[9/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetexcept.dir/fesetexcept.cpp.o
[10/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetround.dir/fesetround.cpp.o
[11/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetexceptflag.dir/fegetexceptflag.cpp.o
[12/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feupdateenv.dir/feupdateenv.cpp.o
[13/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feholdexcept.dir/feholdexcept.cpp.o
[14/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fetestexceptflag.dir/fetestexceptflag.cpp.o
[15/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fetestexcept.dir/fetestexcept.cpp.o
[16/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetexcept.dir/fegetexcept.cpp.o
[17/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetenv.dir/fegetenv.cpp.o
[18/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feenableexcept.dir/feenableexcept.cpp.o
[19/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetround.dir/fegetround.cpp.o
[20/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feraiseexcept.dir/feraiseexcept.cpp.o
[21/363] Building CXX object projects/libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o
[22/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetenv.dir/fesetenv.cpp.o
[23/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.ceilf128.dir/ceilf128.cpp.o
[24/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.ceil.dir/ceil.cpp.o
[25/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.canonicalize.dir/canonicalize.cpp.o
[26/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.canonicalizef128.dir/canonicalizef128.cpp.o
[27/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.canonicalizef.dir/canonicalizef.cpp.o
[28/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.ceilf.dir/ceilf.cpp.o
[29/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.ceill.dir/ceill.cpp.o
[30/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.canonicalizel.dir/canonicalizel.cpp.o
[31/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.cospif.dir/cospif.cpp.o

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 13, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-dbg running on libc-x86_64-debian while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/93/builds/2001

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Performing Test HAVE_PTHREAD_AFFINITY -- success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg/build
@@@BUILD_STEP build libc@@@
Running: ninja libc
[1/363] Building CXX object projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o
FAILED: projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -D_DEBUG -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg/build/projects/libc/src/errno -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg/llvm-project/libc/src/errno -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg/build/projects/libc/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fpie -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=c++17 -MD -MT projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -MF projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o.d -o projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp:91:32: error: use of undeclared identifier 'errno'
void Errno::operator=(int a) { errno = a; }
                               ^
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp:92:32: error: use of undeclared identifier 'errno'
Errno::operator int() { return errno; }
                               ^
2 errors generated.
[2/363] Building CXX object projects/libc/src/__support/OSUtil/linux/CMakeFiles/libc.src.__support.OSUtil.linux.linux_util.dir/fcntl.cpp.o
[3/363] Building CXX object projects/libc/src/inttypes/CMakeFiles/libc.src.inttypes.strtoumax.dir/strtoumax.cpp.o
[4/363] Building CXX object projects/libc/src/inttypes/CMakeFiles/libc.src.inttypes.strtoimax.dir/strtoimax.cpp.o
[5/363] Building CXX object projects/libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o
[6/363] Building CXX object projects/libc/src/__support/File/linux/CMakeFiles/libc.src.__support.File.linux.file.dir/file.cpp.o
[7/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fetestexceptflag.dir/fetestexceptflag.cpp.o
[8/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetexcept.dir/fegetexcept.cpp.o
[9/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetround.dir/fegetround.cpp.o
[10/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetenv.dir/fegetenv.cpp.o
[11/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feclearexcept.dir/feclearexcept.cpp.o
[12/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetexceptflag.dir/fesetexceptflag.cpp.o
[13/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetenv.dir/fesetenv.cpp.o
[14/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fetestexcept.dir/fetestexcept.cpp.o
[15/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feraiseexcept.dir/feraiseexcept.cpp.o
[16/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetexceptflag.dir/fegetexceptflag.cpp.o
[17/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetround.dir/fesetround.cpp.o
[18/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fedisableexcept.dir/fedisableexcept.cpp.o
[19/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feholdexcept.dir/feholdexcept.cpp.o
[20/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feenableexcept.dir/feenableexcept.cpp.o
[21/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.ceil.dir/ceil.cpp.o
[22/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.feupdateenv.dir/feupdateenv.cpp.o
[23/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.canonicalize.dir/canonicalize.cpp.o
[24/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.canonicalizef.dir/canonicalizef.cpp.o
[25/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.canonicalizef128.dir/canonicalizef128.cpp.o
[26/363] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetexcept.dir/fesetexcept.cpp.o
[27/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.ceill.dir/ceill.cpp.o
[28/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.ceilf128.dir/ceilf128.cpp.o
[29/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.ceilf.dir/ceilf.cpp.o
[30/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.canonicalizel.dir/canonicalizel.cpp.o
[31/363] Building CXX object projects/libc/src/math/generic/CMakeFiles/libc.src.math.generic.cospif.dir/cospif.cpp.o

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 13, 2024

LLVM Buildbot has detected a new failure on builder libc-riscv64-debian-dbg running on libc-riscv64-debian while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/188/builds/1439

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile
-- Configuring done
-- Generating done
-- Build files have been written to: /home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build
@@@BUILD_STEP build libc@@@
Running: ninja libc
[1/342] Building CXX object projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o
FAILED: projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_18_0_0_git -D_DEBUG -I/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build/projects/libc/src/errno -I/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/src/errno -I/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc -isystem /home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build/projects/libc/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fpie -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=c++17 -MD -MT projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -MF projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o.d -o projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -c /home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp
/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp:91:32: error: use of undeclared identifier 'errno'
void Errno::operator=(int a) { errno = a; }
                               ^
/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp:92:32: error: use of undeclared identifier 'errno'
Errno::operator int() { return errno; }
                               ^
2 errors generated.
[2/342] Building CXX object projects/libc/src/__support/OSUtil/linux/CMakeFiles/libc.src.__support.OSUtil.linux.linux_util.dir/fcntl.cpp.o
[3/342] Building CXX object projects/libc/src/__support/File/linux/CMakeFiles/libc.src.__support.File.linux.file.dir/file.cpp.o
[4/342] Building CXX object projects/libc/src/__support/File/CMakeFiles/libc.src.__support.File.file.dir/file.cpp.o
[5/342] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fesetround.dir/fesetround.cpp.o
[6/342] Building CXX object projects/libc/src/fenv/CMakeFiles/libc.src.fenv.fegetround.dir/fegetround.cpp.o
ninja: build stopped: subcommand failed.
['ninja', 'libc'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 164, in step
    yield
  File "/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 121, in main
    run_command(['ninja', 'libc'])
  File "/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 179, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/home/libc_worker/libc-riscv64-debian/libc-riscv64-debian-dbg/llvm-zorg/zorg/buildbot/builders/annotated/util.py", line 49, in report_run_cmd
    subprocess.check_call(cmd, shell=shell, *args, **kwargs)
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ninja', 'libc']' returned non-zero exit status 1.
@@@STEP_FAILURE@@@
@@@BUILD_STEP libc-unit-tests@@@
Running: ninja libc-unit-tests

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 13, 2024

LLVM Buildbot has detected a new failure on builder libc-arm32-debian-dbg running on libc-arm32-debian while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/182/builds/1011

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Performing Test HAVE_PTHREAD_AFFINITY -- success
-- Configuring done
-- Generating done
-- Build files have been written to: /llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build
@@@BUILD_STEP build libc@@@
Running: ninja libc
[1/205] Building CXX object projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o
FAILED: projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -D_DEBUG -I/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/projects/libc/src/errno -I/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/src/errno -I/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc -isystem /llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/projects/libc/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fpie -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=c++17 -MD -MT projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -MF projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o.d -o projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -c /llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp:91:32: error: use of undeclared identifier 'errno'
void Errno::operator=(int a) { errno = a; }
                               ^
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp:92:32: error: use of undeclared identifier 'errno'
Errno::operator int() { return errno; }
                               ^
2 errors generated.
[2/205] Building CXX object projects/libc/src/__support/OSUtil/linux/CMakeFiles/libc.src.__support.OSUtil.linux.linux_util.dir/fcntl.cpp.o
ninja: build stopped: subcommand failed.
['ninja', 'libc'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 164, in step
    yield
  File "/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 121, in main
    run_command(['ninja', 'libc'])
  File "/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 179, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-zorg/zorg/buildbot/builders/annotated/util.py", line 49, in report_run_cmd
    subprocess.check_call(cmd, shell=shell, *args, **kwargs)
  File "/usr/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ninja', 'libc']' returned non-zero exit status 1.
@@@STEP_FAILURE@@@
@@@BUILD_STEP libc-unit-tests@@@
Running: ninja libc-unit-tests
Step 6 (build libc) failure: build libc (failure)
@@@BUILD_STEP build libc@@@
Running: ninja libc
[1/205] Building CXX object projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o
FAILED: projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -D_DEBUG -I/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/projects/libc/src/errno -I/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/src/errno -I/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc -isystem /llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/projects/libc/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fpie -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=c++17 -MD -MT projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -MF projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o.d -o projects/libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o -c /llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp:91:32: error: use of undeclared identifier 'errno'
void Errno::operator=(int a) { errno = a; }
                               ^
/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-project/libc/src/errno/libc_errno.cpp:92:32: error: use of undeclared identifier 'errno'
Errno::operator int() { return errno; }
                               ^
2 errors generated.
[2/205] Building CXX object projects/libc/src/__support/OSUtil/linux/CMakeFiles/libc.src.__support.OSUtil.linux.linux_util.dir/fcntl.cpp.o
ninja: build stopped: subcommand failed.
['ninja', 'libc'] exited with return code 1.
The build step threw an exception...
Traceback (most recent call last):
  File "/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 164, in step
    yield
  File "/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 121, in main
    run_command(['ninja', 'libc'])
  File "/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 179, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/llvm/libc_worker/worker/libc-arm32-debian/libc-arm32-debian-dbg/llvm-zorg/zorg/buildbot/builders/annotated/util.py", line 49, in report_run_cmd
    subprocess.check_call(cmd, shell=shell, *args, **kwargs)
  File "/usr/lib/python3.11/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ninja', 'libc']' returned non-zero exit status 1.

petrhosek added a commit to petrhosek/llvm-project that referenced this pull request Jul 13, 2024
This addresses the build error introduced in llvm#98287 where
src/errno/errno.h is included instead of the system errno.h.

We instead move the declaration to libc_errno.h.
petrhosek added a commit that referenced this pull request Jul 13, 2024
This addresses the build error introduced in #98287 where
src/errno/errno.h is included instead of the system errno.h.

We instead move the declaration to libc_errno.h.
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
Rather than selecting the errno implementation based on the platform
which doesn't provide the necessary flexibility, make it configurable.

The errno value location is returned by `int *__llvm_libc_errno()` which
is a common design used by other C libraries.
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
This addresses the build error introduced in llvm#98287 where
src/errno/errno.h is included instead of the system errno.h.

We instead move the declaration to libc_errno.h.
akshaykumars614 pushed a commit to akshaykumars614/llvm-project that referenced this pull request Jul 15, 2024
This addresses the build error introduced in llvm#98287 where
src/errno/errno.h is included instead of the system errno.h.

We instead move the declaration to libc_errno.h.
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 16, 2024
Rather than selecting the errno implementation based on the platform
which doesn't provide the necessary flexibility, make it configurable.

The errno value location is returned by `int *__llvm_libc_errno()` which
is a common design used by other C libraries.
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 16, 2024
This addresses the build error introduced in llvm#98287 where
src/errno/errno.h is included instead of the system errno.h.

We instead move the declaration to libc_errno.h.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants