Skip to content

[libc] Implement barriers for pthreads #148948

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

Merged
merged 16 commits into from
Jul 28, 2025
Merged

Conversation

uzairnawaz
Copy link
Contributor

Implemented barrier synchronization for pthreads

  • Uses condition variables internally for platform independence (platform-specific work is handled by the condition variable implementation)
  • Does NOT currently handle barrierattr pshared, this is a goal for a future patch

@llvmbot
Copy link
Member

llvmbot commented Jul 15, 2025

@llvm/pr-subscribers-libc

Author: Uzair Nawaz (uzairnawaz)

Changes

Implemented barrier synchronization for pthreads

  • Uses condition variables internally for platform independence (platform-specific work is handled by the condition variable implementation)
  • Does NOT currently handle barrierattr pshared, this is a goal for a future patch

Patch is 21.59 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/148948.diff

19 Files Affected:

  • (modified) libc/config/linux/x86_64/entrypoints.txt (+3)
  • (modified) libc/include/CMakeLists.txt (+2)
  • (modified) libc/include/llvm-libc-macros/pthread-macros.h (+2)
  • (modified) libc/include/llvm-libc-types/CMakeLists.txt (+2)
  • (added) libc/include/llvm-libc-types/pthread_barrier_t.h (+16)
  • (added) libc/include/llvm-libc-types/pthread_barrierattr_t.h (+16)
  • (modified) libc/include/pthread.yaml (+22)
  • (modified) libc/src/__support/threads/CMakeLists.txt (+11)
  • (added) libc/src/__support/threads/barrier.cpp (+82)
  • (added) libc/src/__support/threads/barrier.h (+44)
  • (modified) libc/src/pthread/CMakeLists.txt (+34)
  • (added) libc/src/pthread/pthread_barrier_destroy.cpp (+23)
  • (added) libc/src/pthread/pthread_barrier_destroy.h (+21)
  • (added) libc/src/pthread/pthread_barrier_init.cpp (+31)
  • (added) libc/src/pthread/pthread_barrier_init.h (+23)
  • (added) libc/src/pthread/pthread_barrier_wait.cpp (+27)
  • (added) libc/src/pthread/pthread_barrier_wait.h (+21)
  • (modified) libc/test/integration/src/pthread/CMakeLists.txt (+17)
  • (added) libc/test/integration/src/pthread/pthread_barrier_test.cpp (+117)
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 59c248871f83a..3a631c9056163 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1039,6 +1039,9 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.pthread.pthread_join
     libc.src.pthread.pthread_key_create
     libc.src.pthread.pthread_key_delete
+    libc.src.pthread.pthread_barrier_init
+    libc.src.pthread.pthread_barrier_wait
+    libc.src.pthread.pthread_barrier_destroy
     libc.src.pthread.pthread_mutex_destroy
     libc.src.pthread.pthread_mutex_init
     libc.src.pthread.pthread_mutex_lock
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 55268d19529c7..3c16468b8110e 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -390,6 +390,8 @@ add_header_macro(
     .llvm-libc-types.pthread_attr_t
     .llvm-libc-types.pthread_condattr_t
     .llvm-libc-types.pthread_key_t
+    .llvm-libc-types.pthread_barrier_t
+    .llvm-libc-types.pthread_barrierattr_t
     .llvm-libc-types.pthread_mutex_t
     .llvm-libc-types.pthread_mutexattr_t
     .llvm-libc-types.pthread_once_t
diff --git a/libc/include/llvm-libc-macros/pthread-macros.h b/libc/include/llvm-libc-macros/pthread-macros.h
index fcc6ef925e3f4..ce467b7cc4d07 100644
--- a/libc/include/llvm-libc-macros/pthread-macros.h
+++ b/libc/include/llvm-libc-macros/pthread-macros.h
@@ -22,6 +22,8 @@
 #define PTHREAD_MUTEX_STALLED 0
 #define PTHREAD_MUTEX_ROBUST 1
 
+#define PTHREAD_BARRIER_SERIAL_THREAD -1
+
 #define PTHREAD_ONCE_INIT {0}
 
 #define PTHREAD_PROCESS_PRIVATE 0
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index b24c97301668a..405c2cd26b863 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -53,6 +53,8 @@ add_header(pthread_condattr_t HDR pthread_condattr_t.h DEPENDS .clockid_t)
 add_header(pthread_key_t HDR pthread_key_t.h)
 add_header(pthread_mutex_t HDR pthread_mutex_t.h DEPENDS .__futex_word .__mutex_type)
 add_header(pthread_mutexattr_t HDR pthread_mutexattr_t.h)
+add_header(pthread_barrier_t HDR pthread_barrier_t.h)
+add_header(pthread_barrierattr_t HDR pthread_barrierattr_t.h)
 add_header(pthread_once_t HDR pthread_once_t.h DEPENDS .__futex_word)
 add_header(pthread_rwlock_t HDR pthread_rwlock_t.h DEPENDS .__futex_word .pid_t)
 add_header(pthread_rwlockattr_t HDR pthread_rwlockattr_t.h)
diff --git a/libc/include/llvm-libc-types/pthread_barrier_t.h b/libc/include/llvm-libc-types/pthread_barrier_t.h
new file mode 100644
index 0000000000000..d95477afb226c
--- /dev/null
+++ b/libc/include/llvm-libc-types/pthread_barrier_t.h
@@ -0,0 +1,16 @@
+//===-- Definition of pthread_barrier_t type ------------------------------===//
+//
+// 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 LLVM_LIBC_TYPES_PTHREAD_BARRIER_T_H
+#define LLVM_LIBC_TYPES_PTHREAD_BARRIER_T_H
+
+typedef struct {
+  char padding[88];
+} pthread_barrier_t;
+
+#endif // LLVM_LIBC_TYPES_PTHREAD_BARRIER_T_H
diff --git a/libc/include/llvm-libc-types/pthread_barrierattr_t.h b/libc/include/llvm-libc-types/pthread_barrierattr_t.h
new file mode 100644
index 0000000000000..064be5bfb6721
--- /dev/null
+++ b/libc/include/llvm-libc-types/pthread_barrierattr_t.h
@@ -0,0 +1,16 @@
+//===-- Definition of pthread_barrierattr_t type --------------------------===//
+//
+// 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 LLVM_LIBC_TYPES_PTHREAD_BARRIERATTR_T_H
+#define LLVM_LIBC_TYPES_PTHREAD_BARRIERATTR_T_H
+
+typedef struct {
+  bool pshared;
+} pthread_barrierattr_t;
+
+#endif // LLVM_LIBC_TYPES_PTHREAD_BARRIERATTR_T_H
diff --git a/libc/include/pthread.yaml b/libc/include/pthread.yaml
index 5b27e68d2f2d8..8afce2098adde 100644
--- a/libc/include/pthread.yaml
+++ b/libc/include/pthread.yaml
@@ -6,6 +6,8 @@ types:
   - type_name: pthread_once_t
   - type_name: pthread_mutex_t
   - type_name: pthread_mutexattr_t
+  - type_name: pthread_barrier_t
+  - type_name: pthread_barrierattr_t
   - type_name: pthread_key_t
   - type_name: pthread_condattr_t
   - type_name: __pthread_tss_dtor_t
@@ -277,6 +279,26 @@ functions:
     arguments:
       - type: pthread_mutexattr_t *__restrict
       - type: int
+  - name: pthread_barrier_init
+    standards:
+      - POSIX
+    return_type: int
+    arguments:
+      - type: pthread_barrier_t *__restrict
+      - type: const pthread_barrierattr_t *__restrict
+      - type: int
+  - name: pthread_barrier_wait
+    standards:
+      - POSIX
+    return_type: int
+    arguments:
+      - type: pthread_barrier_t *
+  - name: pthread_barrier_destroy
+    standards:
+      - POSIX
+    return_type: int
+    arguments:
+      - type: pthread_barrier_t *
   - name: pthread_once
     standards:
       - POSIX
diff --git a/libc/src/__support/threads/CMakeLists.txt b/libc/src/__support/threads/CMakeLists.txt
index bd49bbb5ad2fe..3cf50b6d3f8a9 100644
--- a/libc/src/__support/threads/CMakeLists.txt
+++ b/libc/src/__support/threads/CMakeLists.txt
@@ -90,6 +90,17 @@ if(TARGET libc.src.__support.threads.${LIBC_TARGET_OS}.CndVar)
   )
 endif()
 
+add_object_library(
+  barrier
+  HDRS
+    barrier.h
+  SRCS
+    barrier.cpp
+  DEPENDS
+    .CndVar
+    .mutex
+)
+
 if (LLVM_LIBC_FULL_BUILD)
   set(identifier_dependency_on_thread libc.src.__support.threads.thread)
 endif()
diff --git a/libc/src/__support/threads/barrier.cpp b/libc/src/__support/threads/barrier.cpp
new file mode 100644
index 0000000000000..298cb17cb8d00
--- /dev/null
+++ b/libc/src/__support/threads/barrier.cpp
@@ -0,0 +1,82 @@
+//===-- Linux implementation of the callonce function ---------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/threads/barrier.h"
+#include "barrier.h"
+#include "hdr/errno_macros.h"
+#include "src/__support/threads/mutex.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+const int BARRIER_FIRST_EXITED = -1;
+
+int Barrier::init(Barrier *b, const pthread_barrierattr_t *attr,
+                  unsigned count) {
+  LIBC_ASSERT(attr == nullptr); // TODO implement barrierattr
+  if (count == 0)
+    return EINVAL;
+
+  b->expected = count;
+  b->waiting = 0;
+  b->blocking = true;
+
+  int err;
+  err = CndVar::init(&b->entering);
+  if (err != 0)
+    return err;
+
+  err = CndVar::init(&b->exiting);
+  if (err != 0)
+    return err;
+
+  Mutex::init(&b->m, false, false, false, false);
+  return 0;
+}
+
+int Barrier::wait() {
+  m.lock();
+
+  // if the barrier is emptying out threads, wait until it finishes
+  while (!blocking) {
+    entering.wait(&m);
+  }
+  waiting++;
+
+  if (waiting == expected) {
+    // this is the last thread to call wait(), so lets wake everyone up
+    blocking = false;
+    exiting.broadcast();
+  } else {
+    // block threads until waiting = expected
+    while (blocking) {
+      exiting.wait(&m);
+    }
+  }
+  waiting--;
+
+  // all threads have exited the barrier, lets let the ones waiting to enter
+  // continue
+  if (waiting == 0) {
+    blocking = true;
+    entering.broadcast();
+    m.unlock();
+    return BARRIER_FIRST_EXITED;
+  }
+  m.unlock();
+
+  return 0;
+}
+
+int Barrier::destroy(Barrier *b) {
+  CndVar::destroy(&b->entering);
+  CndVar::destroy(&b->exiting);
+  Mutex::destroy(&b->m);
+  return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/threads/barrier.h b/libc/src/__support/threads/barrier.h
new file mode 100644
index 0000000000000..b8b410ec1b35e
--- /dev/null
+++ b/libc/src/__support/threads/barrier.h
@@ -0,0 +1,44 @@
+//===-- A platform independent abstraction layer for barriers --*- C++ -*-===//
+//
+// 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 LLVM_LIBC___SUPPORT_SRC_THREADS_LINUX_BARRIER_H
+#define LLVM_LIBC___SUPPORT_SRC_THREADS_LINUX_BARRIER_H
+
+#include "include/llvm-libc-types/pthread_barrier_t.h"
+#include "include/llvm-libc-types/pthread_barrierattr_t.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/threads/CndVar.h"
+#include "src/__support/threads/mutex.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+// NOTE: if the size of this class changes, you must ensure that the size of
+// pthread_barrier_t (found in include/llvm-libc/types/pthread_barrier_t.h) is
+// the same size
+
+extern const int BARRIER_FIRST_EXITED;
+
+class Barrier {
+private:
+  unsigned expected;
+  unsigned waiting;
+  bool blocking;
+  CndVar entering;
+  CndVar exiting;
+  Mutex m;
+
+public:
+  static int init(Barrier *b, const pthread_barrierattr_t *attr,
+                  unsigned count);
+  static int destroy(Barrier *b);
+  int wait();
+};
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC___SUPPORT_SRC_THREADS_LINUX_BARRIER_H
diff --git a/libc/src/pthread/CMakeLists.txt b/libc/src/pthread/CMakeLists.txt
index c8c66805667fa..e5a0a34cf46a6 100644
--- a/libc/src/pthread/CMakeLists.txt
+++ b/libc/src/pthread/CMakeLists.txt
@@ -271,6 +271,40 @@ add_entrypoint_object(
     libc.src.errno.errno
 )
 
+add_entrypoint_object(
+  pthread_barrier_init
+  SRCS
+    pthread_barrier_init.cpp
+  HDRS
+    pthread_barrier_init.h
+  DEPENDS
+    libc.src.errno.errno
+    libc.include.pthread
+    libc.src.__support.threads.barrier
+)
+
+add_entrypoint_object(
+  pthread_barrier_destroy
+  SRCS
+    pthread_barrier_destroy.cpp
+  HDRS
+    pthread_barrier_destroy.h
+  DEPENDS
+    libc.include.pthread
+    libc.src.__support.threads.barrier
+)
+
+add_entrypoint_object(
+  pthread_barrier_wait
+  SRCS
+    pthread_barrier_wait.cpp
+  HDRS
+    pthread_barrier_wait.h
+  DEPENDS
+    libc.include.pthread
+    libc.src.__support.threads.barrier
+)
+
 add_entrypoint_object(
   pthread_mutex_init
   SRCS
diff --git a/libc/src/pthread/pthread_barrier_destroy.cpp b/libc/src/pthread/pthread_barrier_destroy.cpp
new file mode 100644
index 0000000000000..389e1751ed3ee
--- /dev/null
+++ b/libc/src/pthread/pthread_barrier_destroy.cpp
@@ -0,0 +1,23 @@
+//===-- Linux implementation of the pthread_barrier_init function ---------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "pthread_barrier_destroy.h"
+
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/threads/barrier.h"
+
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, pthread_barrier_destroy, (pthread_barrier_t * b)) {
+  return Barrier::destroy(reinterpret_cast<Barrier *>(b));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/pthread/pthread_barrier_destroy.h b/libc/src/pthread/pthread_barrier_destroy.h
new file mode 100644
index 0000000000000..0b1d0f090ec26
--- /dev/null
+++ b/libc/src/pthread/pthread_barrier_destroy.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for pthread_barrier_destroy ----------*- C++ -*-===//
+//
+// 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 LLVM_LIBC_SRC_PTHREAD_PTHREAD_BARRIER_DESTROY_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_BARRIER_DESTROY_H
+
+#include "src/__support/macros/config.h"
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+int pthread_barrier_destroy(pthread_barrier_t *b);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_BARRIER_DESTROY_H
diff --git a/libc/src/pthread/pthread_barrier_init.cpp b/libc/src/pthread/pthread_barrier_init.cpp
new file mode 100644
index 0000000000000..1d0d87342d823
--- /dev/null
+++ b/libc/src/pthread/pthread_barrier_init.cpp
@@ -0,0 +1,31 @@
+//===-- Linux implementation of the pthread_barrier_init function ---------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "pthread_barrier_init.h"
+
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/threads/barrier.h"
+
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+static_assert(
+    sizeof(Barrier) <= sizeof(pthread_barrier_t),
+    "The public pthread_barrier_t type cannot accommodate the internal "
+    "barrier type.");
+
+LLVM_LIBC_FUNCTION(int, pthread_barrier_init,
+                   (pthread_barrier_t * b,
+                    const pthread_barrierattr_t *__restrict attr,
+                    unsigned count)) {
+  return Barrier::init(reinterpret_cast<Barrier *>(b), attr, count);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/pthread/pthread_barrier_init.h b/libc/src/pthread/pthread_barrier_init.h
new file mode 100644
index 0000000000000..ea79df6da7ea9
--- /dev/null
+++ b/libc/src/pthread/pthread_barrier_init.h
@@ -0,0 +1,23 @@
+//===-- Implementation header for pthread_barrier_init ----------*- C++ -*-===//
+//
+// 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 LLVM_LIBC_SRC_PTHREAD_PTHREAD_BARRIER_INIT_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_BARRIER_INIT_H
+
+#include "src/__support/macros/config.h"
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+int pthread_barrier_init(pthread_barrier_t *b,
+                         const pthread_barrierattr_t *__restrict attr,
+                         unsigned count);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_BARRIER_INIT_H
diff --git a/libc/src/pthread/pthread_barrier_wait.cpp b/libc/src/pthread/pthread_barrier_wait.cpp
new file mode 100644
index 0000000000000..617d91dd16f77
--- /dev/null
+++ b/libc/src/pthread/pthread_barrier_wait.cpp
@@ -0,0 +1,27 @@
+//===-- Linux implementation of the pthread_barrier_init function ---------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "pthread_barrier_wait.h"
+
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/threads/barrier.h"
+
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, pthread_barrier_wait, (pthread_barrier_t * b)) {
+  int out = reinterpret_cast<Barrier *>(b)->wait();
+  if (out == BARRIER_FIRST_EXITED)
+    return PTHREAD_BARRIER_SERIAL_THREAD;
+  
+  return out;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/pthread/pthread_barrier_wait.h b/libc/src/pthread/pthread_barrier_wait.h
new file mode 100644
index 0000000000000..738ca56bd53e4
--- /dev/null
+++ b/libc/src/pthread/pthread_barrier_wait.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for pthread_barrier_wait ----------*- C++ -*-===//
+//
+// 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 LLVM_LIBC_SRC_PTHREAD_PTHREAD_BARRIER_WAIT_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_BARRIER_WAIT_H
+
+#include "src/__support/macros/config.h"
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+int pthread_barrier_wait(pthread_barrier_t *b);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_BARRIER_WAIT_H
diff --git a/libc/test/integration/src/pthread/CMakeLists.txt b/libc/test/integration/src/pthread/CMakeLists.txt
index 208ba3fd43507..ce3bb9da9d58e 100644
--- a/libc/test/integration/src/pthread/CMakeLists.txt
+++ b/libc/test/integration/src/pthread/CMakeLists.txt
@@ -17,6 +17,23 @@ add_integration_test(
     libc.src.pthread.pthread_join
 )
 
+add_integration_test(
+  pthread_barrier_test
+  SUITE
+    libc-pthread-integration-tests
+  SRCS
+    pthread_barrier_test.cpp
+  DEPENDS
+    libc.include.pthread
+    libc.src.errno.errno
+    libc.src.pthread.pthread_barrier_destroy
+    libc.src.pthread.pthread_barrier_wait
+    libc.src.pthread.pthread_barrier_init
+    libc.src.pthread.pthread_create
+    libc.src.pthread.pthread_join
+    libc.src.stdio.printf
+)
+
 add_integration_test(
   pthread_rwlock_test
   SUITE
diff --git a/libc/test/integration/src/pthread/pthread_barrier_test.cpp b/libc/test/integration/src/pthread/pthread_barrier_test.cpp
new file mode 100644
index 0000000000000..d4d696ec82507
--- /dev/null
+++ b/libc/test/integration/src/pthread/pthread_barrier_test.cpp
@@ -0,0 +1,117 @@
+//===-- Tests for pthread_barrier_t ---------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/pthread/pthread_barrier_destroy.h"
+#include "src/pthread/pthread_barrier_init.h"
+#include "src/pthread/pthread_barrier_wait.h"
+
+#include "src/__support/CPP/atomic.h"
+#include "src/pthread/pthread_create.h"
+#include "src/pthread/pthread_join.h"
+#include "src/pthread/pthread_mutex_destroy.h"
+#include "src/pthread/pthread_mutex_init.h"
+#include "src/pthread/pthread_mutex_lock.h"
+#include "src/pthread/pthread_mutex_unlock.h"
+#include "src/stdio/printf.h"
+
+#include "test/IntegrationTest/test.h"
+
+#include <pthread.h>
+
+pthread_barrier_t barrier;
+
+void smoke_test() {
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_barrier_init(&barrier, nullptr, 1), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_barrier_wait(&barrier),
+            PTHREAD_BARRIER_SERIAL_THREAD);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_barrier_destroy(&barrier), 0);
+}
+
+LIBC_NAMESPACE::cpp::Atomic<int> counter;
+void *increment_counter_and_wait(void *args) {
+  counter.fetch_add(1);
+  LIBC_NAMESPACE::pthread_barrier_wait(&barrier);
+  return 0;
+}
+
+void single_use_barrier() {
+  counter.set(0);
+  const int NUM_THREADS = 30;
+  pthread_t threads[NUM_THREADS];
+  ASSERT_EQ(
+      LIBC_NAMESPACE::pthread_barrier_init(&barrier, nullptr, NUM_THREADS + 1),
+      0);
+
+  for (int i = 0; i < NUM_THREADS; ++i)
+    LIBC_NAMESPACE::pthread_create(&threads[i], nullptr,
+                                   increment_counter_and_wait, nullptr);
+
+  LIBC_NAMESPACE::pthread_barrier_wait(&barrier);
+  ASSERT_EQ(counter.load(), NUM_THREADS);
+
+  for (int i = 0; i < NUM_THREADS; ++i)
+    LIBC_NAMESPACE::pthread_join(threads[i], nullptr);
+
+  LIBC_NAMESPACE::pthread_barrier_destroy(&barrier);
+}
+
+void reusable_barrier() {
+  counter.set(0);
+  const int NUM_THREADS = 30;
+  const int REPEAT = 20;
+  pthread_t threads[NUM_THREADS...
[truncated]

Copy link

github-actions bot commented Jul 15, 2025

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

@SchrodingerZhu
Copy link
Contributor

Thanks for the patch. I am reviewing it right now.

Copy link

@brooksmoses brooksmoses left a comment

Choose a reason for hiding this comment

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

This generally looks good to me, but I do have several cleanup comments.

int err;
err = CndVar::init(&b->entering);
if (err != 0)
return err;

Choose a reason for hiding this comment

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

The answer might be "no", but: Isn't there a macro for this "check error and return it if it's nonzero" construct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe there is something for this specific pattern, or at least I haven't encountered one yet (also skimmed through the __support/macros folder and I don't see anything like this unfortunately).

Copy link
Contributor

@SchrodingerZhu SchrodingerZhu left a comment

Choose a reason for hiding this comment

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

This overall looks good to me.

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.

Overall LGTM, a few minor comments. Good to land after fixing. @SchrodingerZhu thanks for reviewing!


#include "test/IntegrationTest/test.h"

#include <pthread.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

is this necessary or can you include the proxy headers for pthread macros/types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are many pthread types defined in include/llvm-libc-types that don't have corresponding proxy headers in hdr/types yet. I created proxy headers for the barrier structs in this patch, but I think it may make sense to have a separate patch for creating all of those additional proxy headers.

@uzairnawaz uzairnawaz merged commit 7ca2375 into llvm:main Jul 28, 2025
15 of 19 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 28, 2025

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

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

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)
...
[59/70] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_equal.dir/pthread_equal.cpp.o
[60/70] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_clockrdlock.dir/pthread_rwlock_clockrdlock.cpp.o
[61/70] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_setname_np.dir/pthread_setname_np.cpp.o
[62/70] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_exit.dir/pthread_exit.cpp.o
[63/70] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_getname_np.dir/pthread_getname_np.cpp.o
[64/70] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_mutex_lock.dir/pthread_mutex_lock.cpp.o
[65/70] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_mutex_unlock.dir/pthread_mutex_unlock.cpp.o
[66/70] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_key_create.dir/pthread_key_create.cpp.o
[67/70] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_destroy.dir/pthread_rwlock_destroy.cpp.o
[68/70] Building CXX object compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.aarch64.dir/wrappers_c.cpp.o
FAILED: compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.aarch64.dir/wrappers_c.cpp.o 
/usr/bin/clang++ -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/../.. -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/include -Icompiler-rt/../libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -Wall -g -march=armv8-a -Werror=conversion -Wall -Wextra -pedantic -g -nostdinc++ -fvisibility=hidden -fno-exceptions -Wno-pedantic -fno-lto -O3 -ffreestanding -std=c++17 -MD -MT compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.aarch64.dir/wrappers_c.cpp.o -MF compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.aarch64.dir/wrappers_c.cpp.o.d -o compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.aarch64.dir/wrappers_c.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c.cpp:14:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/allocator_config.h:12:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/combined.h:28:
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/tsd.h:18:
In file included from compiler-rt/../libc/include/pthread.h:21:
compiler-rt/../libc/include/llvm-libc-types/pthread_barrier_t.h:12:10: fatal error: 'include/llvm-libc-types/__barrier_type.h' file not found
#include "include/llvm-libc-types/__barrier_type.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[69/70] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_timedrdlock.dir/pthread_rwlock_timedrdlock.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 181, in step
    yield
  File "../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 143, in main
    run_command(['ninja', 'libc'])
  File "../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 196, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-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/python2.7/subprocess.py", line 190, in check_call
    raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '['ninja', 'libc']' returned non-zero exit status 1
@@@STEP_FAILURE@@@
@@@BUILD_STEP build libc-startup@@@
Running: ninja libc-startup
ninja: no work to do.
@@@BUILD_STEP libc-unit-tests@@@
Running: ninja libc-unit-tests
[1/956] Running unit test libc.test.src.math.smoke.fromfpf16_test.__unit__
[==========] Running 16 tests from 1 test suite.
[ RUN      ] LlvmLibcFromfpTest.SpecialNumbersNonzeroWidth
[       OK ] LlvmLibcFromfpTest.SpecialNumbersNonzeroWidth (14 us)
[ RUN      ] LlvmLibcFromfpTest.SpecialNumbersZeroWidth
[       OK ] LlvmLibcFromfpTest.SpecialNumbersZeroWidth (14 us)

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 28, 2025

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

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

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)
...
[107/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_getname_np.dir/pthread_getname_np.cpp.o
[108/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_key_create.dir/pthread_key_create.cpp.o
[109/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_key_delete.dir/pthread_key_delete.cpp.o
[110/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_getspecific.dir/pthread_getspecific.cpp.o
[111/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_setspecific.dir/pthread_setspecific.cpp.o
[112/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlockattr_setkind_np.dir/pthread_rwlockattr_setkind_np.cpp.o
[113/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlockattr_setpshared.dir/pthread_rwlockattr_setpshared.cpp.o
[114/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_init.dir/pthread_spin_init.cpp.o
[115/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_destroy.dir/pthread_spin_destroy.cpp.o
[116/133] Building CXX object compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o
FAILED: compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o 
/usr/bin/g++ -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/../.. -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/include -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/compiler-rt/../libc/include -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Wall -Wno-unused-parameter -g -m64 -Werror=conversion -Wall -Wextra -pedantic -g -nostdinc++ -fvisibility=hidden -fno-exceptions -Wno-pedantic -fno-lto -O3 -ffreestanding -std=c++17 -MD -MT compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o -MF compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o.d -o compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c.cpp
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/compiler-rt/../libc/include/pthread.h:21,
                 from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/tsd.h:18,
                 from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/combined.h:28,
                 from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/allocator_config.h:12,
                 from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c.cpp:14:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/compiler-rt/../libc/include/llvm-libc-types/pthread_barrier_t.h:12:10: fatal error: include/llvm-libc-types/__barrier_type.h: No such file or directory
   12 | #include "include/llvm-libc-types/__barrier_type.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
[117/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_atfork.dir/pthread_atfork.cpp.o
[118/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_init.dir/pthread_rwlock_init.cpp.o
[119/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_tryrdlock.dir/pthread_rwlock_tryrdlock.cpp.o
[120/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_once.dir/pthread_once.cpp.o
[121/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_trywrlock.dir/pthread_rwlock_trywrlock.cpp.o
[122/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_destroy.dir/pthread_rwlock_destroy.cpp.o
[123/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_unlock.dir/pthread_spin_unlock.cpp.o
[124/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_timedrdlock.dir/pthread_rwlock_timedrdlock.cpp.o
[125/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_lock.dir/pthread_spin_lock.cpp.o
[126/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_clockrdlock.dir/pthread_rwlock_clockrdlock.cpp.o
[127/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_rdlock.dir/pthread_rwlock_rdlock.cpp.o
[128/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_trylock.dir/pthread_spin_trylock.cpp.o
[129/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_wrlock.dir/pthread_rwlock_wrlock.cpp.o
[130/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_unlock.dir/pthread_rwlock_unlock.cpp.o
[131/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_timedwrlock.dir/pthread_rwlock_timedwrlock.cpp.o
[132/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_clockwrlock.dir/pthread_rwlock_clockwrlock.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/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 181, in step
    yield
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 143, in main
    run_command(['ninja', 'libc'])
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 196, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-zorg/zorg/buildbot/builders/annotated/util.py", line 49, in report_run_cmd
    subprocess.check_call(cmd, shell=shell, *args, **kwargs)
Step 6 (build libc) failure: build libc (failure)
...
[107/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_getname_np.dir/pthread_getname_np.cpp.o
[108/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_key_create.dir/pthread_key_create.cpp.o
[109/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_key_delete.dir/pthread_key_delete.cpp.o
[110/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_getspecific.dir/pthread_getspecific.cpp.o
[111/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_setspecific.dir/pthread_setspecific.cpp.o
[112/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlockattr_setkind_np.dir/pthread_rwlockattr_setkind_np.cpp.o
[113/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlockattr_setpshared.dir/pthread_rwlockattr_setpshared.cpp.o
[114/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_init.dir/pthread_spin_init.cpp.o
[115/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_destroy.dir/pthread_spin_destroy.cpp.o
[116/133] Building CXX object compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o
FAILED: compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o 
/usr/bin/g++ -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/../.. -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/include -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/compiler-rt/../libc/include -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Wall -Wno-unused-parameter -g -m64 -Werror=conversion -Wall -Wextra -pedantic -g -nostdinc++ -fvisibility=hidden -fno-exceptions -Wno-pedantic -fno-lto -O3 -ffreestanding -std=c++17 -MD -MT compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o -MF compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o.d -o compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c.cpp
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/compiler-rt/../libc/include/pthread.h:21,
                 from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/tsd.h:18,
                 from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/combined.h:28,
                 from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/allocator_config.h:12,
                 from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c.cpp:14:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/compiler-rt/../libc/include/llvm-libc-types/pthread_barrier_t.h:12:10: fatal error: include/llvm-libc-types/__barrier_type.h: No such file or directory
   12 | #include "include/llvm-libc-types/__barrier_type.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
[117/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_atfork.dir/pthread_atfork.cpp.o
[118/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_init.dir/pthread_rwlock_init.cpp.o
[119/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_tryrdlock.dir/pthread_rwlock_tryrdlock.cpp.o
[120/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_once.dir/pthread_once.cpp.o
[121/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_trywrlock.dir/pthread_rwlock_trywrlock.cpp.o
[122/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_destroy.dir/pthread_rwlock_destroy.cpp.o
[123/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_unlock.dir/pthread_spin_unlock.cpp.o
[124/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_timedrdlock.dir/pthread_rwlock_timedrdlock.cpp.o
[125/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_lock.dir/pthread_spin_lock.cpp.o
[126/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_clockrdlock.dir/pthread_rwlock_clockrdlock.cpp.o
[127/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_rdlock.dir/pthread_rwlock_rdlock.cpp.o
[128/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_trylock.dir/pthread_spin_trylock.cpp.o
[129/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_wrlock.dir/pthread_rwlock_wrlock.cpp.o
[130/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_unlock.dir/pthread_rwlock_unlock.cpp.o
[131/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_timedwrlock.dir/pthread_rwlock_timedwrlock.cpp.o
[132/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_clockwrlock.dir/pthread_rwlock_clockwrlock.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/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 181, in step
    yield
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 143, in main
    run_command(['ninja', 'libc'])
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 196, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-zorg/zorg/buildbot/builders/annotated/util.py", line 49, in report_run_cmd
    subprocess.check_call(cmd, shell=shell, *args, **kwargs)

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 28, 2025

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

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

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)
...
[120/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_once.dir/pthread_once.cpp.o
[121/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_trylock.dir/pthread_spin_trylock.cpp.o
[122/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_destroy.dir/pthread_rwlock_destroy.cpp.o
[123/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_timedwrlock.dir/pthread_rwlock_timedwrlock.cpp.o
[124/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_unlock.dir/pthread_spin_unlock.cpp.o
[125/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_unlock.dir/pthread_rwlock_unlock.cpp.o
[126/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_wrlock.dir/pthread_rwlock_wrlock.cpp.o
[127/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_spin_lock.dir/pthread_spin_lock.cpp.o
[128/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_rdlock.dir/pthread_rwlock_rdlock.cpp.o
[129/133] Building CXX object compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o
FAILED: compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o 
/usr/bin/clang++ -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/../.. -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/include -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/compiler-rt/../libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Wall -Wno-unused-parameter -g -m64 -Werror=conversion -Wall -Wextra -pedantic -g -nostdinc++ -fvisibility=hidden -fno-exceptions -Wno-pedantic -fno-lto -O3 -Werror=thread-safety -ffreestanding -std=c++17 -MD -MT compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o -MF compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o.d -o compiler-rt/lib/scudo/standalone/CMakeFiles/RTScudoStandaloneCWrappers.x86_64.dir/wrappers_c.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c.cpp
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_c.cpp:14:
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/allocator_config.h:12:
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/combined.h:28:
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/compiler-rt/lib/scudo/standalone/tsd.h:18:
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/compiler-rt/../libc/include/pthread.h:21:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/compiler-rt/../libc/include/llvm-libc-types/pthread_barrier_t.h:12:10: fatal error: 'include/llvm-libc-types/__barrier_type.h' file not found
#include "include/llvm-libc-types/__barrier_type.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[130/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_clockrdlock.dir/pthread_rwlock_clockrdlock.cpp.o
[131/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_timedrdlock.dir/pthread_rwlock_timedrdlock.cpp.o
[132/133] Building CXX object libc/src/pthread/CMakeFiles/libc.src.pthread.pthread_rwlock_clockwrlock.dir/pthread_rwlock_clockwrlock.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/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 181, in step
    yield
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 143, in main
    run_command(['ninja', 'libc'])
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py", line 196, in run_command
    util.report_run_cmd(cmd, cwd=directory)
  File "/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-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 build libc-startup@@@
Running: ninja libc-startup
ninja: no work to do.
@@@BUILD_STEP libc-unit-tests@@@
Running: ninja libc-unit-tests
[1/1255] Running unit test libc.test.src.__support.block_test.__unit__
[==========] Running 23 tests from 1 test suite.
[ RUN      ] LlvmLibcBlockTest.CanCreateSingleAlignedBlock
[       OK ] LlvmLibcBlockTest.CanCreateSingleAlignedBlock (8 us)

uzairnawaz added a commit that referenced this pull request Jul 28, 2025
uzairnawaz added a commit that referenced this pull request Jul 28, 2025
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 28, 2025
uzairnawaz added a commit that referenced this pull request Jul 29, 2025
Fixed build dependencies for pthread_barrier_t (add __barrier_type to
cmake dependencies)
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