[libc-commits] [libc] [libc] Implement `execle` (PR #217213)

Bhavesh M via libc-commits libc-commits at lists.llvm.org
Wed Aug 19 15:48:01 PDT 2026


https://github.com/beamandala updated https://github.com/llvm/llvm-project/pull/217213

>From 90d6b9f07ec8b4c9fcdddd61d147af90d0fec9a3 Mon Sep 17 00:00:00 2001
From: Bhavesh Mandalapu <bmandalapu at google.com>
Date: Tue, 18 Aug 2026 22:10:01 -0700
Subject: [PATCH 1/4] execle

---
 libc/config/linux/aarch64/entrypoints.txt     |  1 +
 libc/config/linux/riscv/entrypoints.txt       |  1 +
 libc/config/linux/x86_64/entrypoints.txt      |  1 +
 libc/include/unistd.yaml                      |  8 +++
 libc/src/unistd/CMakeLists.txt                |  7 +++
 libc/src/unistd/execle.h                      | 20 +++++++
 libc/src/unistd/linux/CMakeLists.txt          | 13 +++++
 libc/src/unistd/linux/execle.cpp              | 51 +++++++++++++++++
 .../integration/src/unistd/CMakeLists.txt     | 41 +++++++++++++
 .../integration/src/unistd/execle_test.cpp    | 57 +++++++++++++++++++
 .../src/unistd/execle_test_normal_exit.cpp    | 21 +++++++
 .../src/unistd/execle_test_signal_exit.cpp    | 10 ++++
 12 files changed, 231 insertions(+)
 create mode 100644 libc/src/unistd/execle.h
 create mode 100644 libc/src/unistd/linux/execle.cpp
 create mode 100644 libc/test/integration/src/unistd/execle_test.cpp
 create mode 100644 libc/test/integration/src/unistd/execle_test_normal_exit.cpp
 create mode 100644 libc/test/integration/src/unistd/execle_test_signal_exit.cpp

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 3af5943717e84..1676e69b5e02d 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -393,6 +393,7 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.unistd.dup
     libc.src.unistd.dup2
     libc.src.unistd.dup3
+    libc.src.unistd.execle
     libc.src.unistd.execve
     libc.src.unistd.faccessat
     libc.src.unistd.fchdir
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 2a40f55076178..70bf1e4a38304 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -422,6 +422,7 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.unistd.dup
     libc.src.unistd.dup2
     libc.src.unistd.dup3
+    libc.src.unistd.execle
     libc.src.unistd.execve
     libc.src.unistd.faccessat
     libc.src.unistd.fchdir
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index cef595fc67465..89886f0f04734 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -432,6 +432,7 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.unistd.dup
     libc.src.unistd.dup2
     libc.src.unistd.dup3
+    libc.src.unistd.execle
     libc.src.unistd.execve
     libc.src.unistd.faccessat
     libc.src.unistd.fchdir
diff --git a/libc/include/unistd.yaml b/libc/include/unistd.yaml
index 4b3703af7798e..bc76587866f8f 100644
--- a/libc/include/unistd.yaml
+++ b/libc/include/unistd.yaml
@@ -128,6 +128,14 @@ functions:
       - type: int
       - type: int
       - type: int
+  - name: execle
+    standards:
+      - posix
+    return_type: int
+    arguments:
+      - type: const char *
+      - type: const char *
+      - type: '...'
   - name: execv
     standards:
       - posix
diff --git a/libc/src/unistd/CMakeLists.txt b/libc/src/unistd/CMakeLists.txt
index 646c5881532de..c10ea20681059 100644
--- a/libc/src/unistd/CMakeLists.txt
+++ b/libc/src/unistd/CMakeLists.txt
@@ -110,6 +110,13 @@ add_entrypoint_object(
     .${LIBC_TARGET_OS}.fpathconf
 )
 
+add_entrypoint_object(
+  execle
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.execle
+)
+
 add_entrypoint_object(
   execv
   ALIAS
diff --git a/libc/src/unistd/execle.h b/libc/src/unistd/execle.h
new file mode 100644
index 0000000000000..118ef9f9ed70f
--- /dev/null
+++ b/libc/src/unistd/execle.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for execle ------------------------*- 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_UNISTD_EXECLE_H
+#define LLVM_LIBC_SRC_UNISTD_EXECLE_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int execle(const char *path, const char *arg0, ...);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_UNISTD_EXECLE_H
diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 7a8b51e9514aa..57708808f43d0 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -162,6 +162,19 @@ add_entrypoint_object(
     libc.src.unistd.linux.pathconf_utils
 )
 
+add_entrypoint_object(
+  execle
+  SRCS
+    execle.cpp
+  HDRS
+    ../execle.h
+  DEPENDS
+    libc.hdr.types.size_t
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.errno.errno
+)
+
 add_entrypoint_object(
   execv
   SRCS
diff --git a/libc/src/unistd/linux/execle.cpp b/libc/src/unistd/linux/execle.cpp
new file mode 100644
index 0000000000000..fb8bdf57a517c
--- /dev/null
+++ b/libc/src/unistd/linux/execle.cpp
@@ -0,0 +1,51 @@
+//===-- Linux implementation of execle ------------------------------------===//
+//
+// 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/unistd/execle.h"
+#include "src/__support/macros/config.h"
+
+#include "hdr/types/size_t.h"
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include <stdarg.h>
+#include <sys/syscall.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, execle, (const char *path, const char *arg0, ...)) {
+  va_list varargs;
+  va_start(varargs, arg0);
+
+  size_t argc = 1;
+  while (va_arg(varargs, const char *) != nullptr)
+    ++argc;
+  va_end(varargs);
+
+  char **argv =
+      static_cast<char **>(__builtin_alloca((argc + 1) * sizeof(char *)));
+  argv[0] = const_cast<char *>(arg0);
+
+  va_start(varargs, arg0);
+  for (size_t i = 1; i <= argc; ++i)
+    argv[i] = va_arg(varargs, char *);
+  char **envp = va_arg(varargs, char **);
+  va_end(varargs);
+
+  int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_execve, path, argv, envp);
+  if (ret < 0) {
+    libc_errno = -ret;
+    return -1;
+  }
+
+  // Control will not reach here on success but have a return statement will
+  // keep the compilers happy.
+  return ret;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/integration/src/unistd/CMakeLists.txt b/libc/test/integration/src/unistd/CMakeLists.txt
index 3c09ae43b4dd7..6eac86217383e 100644
--- a/libc/test/integration/src/unistd/CMakeLists.txt
+++ b/libc/test/integration/src/unistd/CMakeLists.txt
@@ -85,6 +85,47 @@ set_target_properties(
     RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 )
 
+add_executable(
+  libc_execle_test_normal_exit
+  EXCLUDE_FROM_ALL
+  execle_test_normal_exit.cpp
+)
+set_target_properties(
+  libc_execle_test_normal_exit
+  PROPERTIES
+    OUTPUT_NAME libc_execle_test_normal_exit
+    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+add_executable(
+  libc_execle_test_signal_exit
+  EXCLUDE_FROM_ALL
+  execle_test_signal_exit.cpp
+)
+set_target_properties(
+  libc_execle_test_signal_exit
+  PROPERTIES
+    OUTPUT_NAME libc_execle_test_signal_exit
+    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+add_integration_test(
+  execle_test
+  SUITE
+    unistd-integration-tests
+  SRCS
+    execle_test.cpp
+  DEPENDS
+    libc_execle_test_normal_exit
+    libc_execle_test_signal_exit
+    libc.src.errno.errno
+    libc.src.sys.wait.waitpid
+    libc.src.unistd.execle
+    libc.src.unistd.fork
+  ENV
+    EXECLE_TEST=PASS
+)
+
 add_integration_test(
   execv_test
   SUITE
diff --git a/libc/test/integration/src/unistd/execle_test.cpp b/libc/test/integration/src/unistd/execle_test.cpp
new file mode 100644
index 0000000000000..e53c51b4ef90a
--- /dev/null
+++ b/libc/test/integration/src/unistd/execle_test.cpp
@@ -0,0 +1,57 @@
+//===-- Unittests for execle ----------------------------------------------===//
+//
+// 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/sys/wait/waitpid.h"
+#include "src/unistd/execle.h"
+#include "src/unistd/fork.h"
+
+#include "test/IntegrationTest/test.h"
+
+#include <signal.h>
+#include <sys/wait.h>
+
+void fork_and_execle_normal_exit(char **envp) {
+  pid_t pid = LIBC_NAMESPACE::fork();
+  if (pid == 0) {
+    const char *path = "libc_execle_test_normal_exit";
+    LIBC_NAMESPACE::execle(path, const_cast<char *>("execle_test_normal_exit"),
+                           const_cast<char *>("first"),
+                           const_cast<char *>("second"),
+                           static_cast<char *>(nullptr), envp);
+  }
+
+  ASSERT_TRUE(pid > 0);
+  int status;
+  pid_t cpid = LIBC_NAMESPACE::waitpid(pid, &status, 0);
+  ASSERT_TRUE(cpid > 0);
+  ASSERT_EQ(cpid, pid);
+  ASSERT_TRUE(WIFEXITED(status));
+}
+
+void fork_and_execle_signal_exit(char **envp) {
+  pid_t pid = LIBC_NAMESPACE::fork();
+  if (pid == 0) {
+    const char *path = "libc_execle_test_signal_exit";
+    LIBC_NAMESPACE::execle(path, const_cast<char *>("execle_test_signal_exit"),
+                           static_cast<char *>(nullptr), envp);
+  }
+  ASSERT_TRUE(pid > 0);
+  int status;
+  pid_t cpid = LIBC_NAMESPACE::waitpid(pid, &status, 0);
+  ASSERT_TRUE(cpid > 0);
+  ASSERT_EQ(cpid, pid);
+  ASSERT_FALSE(WIFEXITED(status));
+  ASSERT_TRUE(WTERMSIG(status) == SIGUSR1);
+}
+
+TEST_MAIN([[maybe_unused]] int argc, [[maybe_unused]] char **argv,
+          char **envp) {
+  fork_and_execle_normal_exit(envp);
+  fork_and_execle_signal_exit(envp);
+  return 0;
+}
diff --git a/libc/test/integration/src/unistd/execle_test_normal_exit.cpp b/libc/test/integration/src/unistd/execle_test_normal_exit.cpp
new file mode 100644
index 0000000000000..76936b2bff6a8
--- /dev/null
+++ b/libc/test/integration/src/unistd/execle_test_normal_exit.cpp
@@ -0,0 +1,21 @@
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+  if (argc != 3)
+    raise(SIGUSR1);
+  if (strcmp(argv[0], "execle_test_normal_exit") != 0)
+    raise(SIGUSR1);
+  if (strcmp(argv[1], "first") != 0)
+    raise(SIGUSR1);
+  if (strcmp(argv[2], "second") != 0)
+    raise(SIGUSR1);
+
+  char *env = getenv("EXECLE_TEST");
+  if (env == nullptr || strcmp(env, "PASS") != 0)
+    raise(SIGUSR1);
+
+  return 0;
+}
diff --git a/libc/test/integration/src/unistd/execle_test_signal_exit.cpp b/libc/test/integration/src/unistd/execle_test_signal_exit.cpp
new file mode 100644
index 0000000000000..e266b5c07490f
--- /dev/null
+++ b/libc/test/integration/src/unistd/execle_test_signal_exit.cpp
@@ -0,0 +1,10 @@
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int main() {
+  char *env = getenv("__MISSING_ENV_VAR__");
+  if (env == nullptr)
+    raise(SIGUSR1);
+  return 0;
+}

>From 1d29e79809f11f2c33d1c239f7c473746aadb859 Mon Sep 17 00:00:00 2001
From: Bhavesh Mandalapu <bmandalapu at google.com>
Date: Wed, 19 Aug 2026 14:34:10 -0700
Subject: [PATCH 2/4] Update file headers, create execve syscall wrapper, copy
 original varargs instead of creating a new one

---
 .../linux/syscall_wrappers/CMakeLists.txt     | 14 ++++++
 .../OSUtil/linux/syscall_wrappers/execve.h    | 44 +++++++++++++++++++
 libc/src/unistd/linux/CMakeLists.txt          |  3 +-
 libc/src/unistd/linux/execle.cpp              | 34 +++++++-------
 .../integration/src/unistd/execle_test.cpp    |  6 ++-
 .../src/unistd/execle_test_normal_exit.cpp    |  8 ++++
 .../src/unistd/execle_test_signal_exit.cpp    |  8 ++++
 7 files changed, 99 insertions(+), 18 deletions(-)
 create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/execve.h

diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 997e199460ab7..ba4254eab0de6 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -993,3 +993,17 @@ add_header_library(
     libc.include.sys_syscall
 )
 
+add_header_library(
+  execve
+  HDRS
+    execve.h
+  DEPENDS
+    libc.hdr.fcntl_macros
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+    libc.include.sys_syscall
+)
+
+
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/execve.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/execve.h
new file mode 100644
index 0000000000000..9c88b7603e808
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/execve.h
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Syscall wrapper for execve.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EXECVE_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EXECVE_H
+
+#include "hdr/fcntl_macros.h"
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> execve(const char *path, char *const argv[],
+                                char *const envp[]) {
+#if defined(SYS_execve)
+  int ret = syscall_impl<int>(SYS_execve, path, argv, envp);
+#elif defined(SYS_execveat)
+  int ret = syscall_impl<int>(SYS_execveat, AT_FDCWD, path, argv, envp, 0);
+#else
+#error "execve and execveat syscalls not available."
+#endif
+  if (ret < 0)
+    return Error(-ret);
+  return ret;
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EXECVE_H
diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 57708808f43d0..d710f84742d59 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -170,8 +170,7 @@ add_entrypoint_object(
     ../execle.h
   DEPENDS
     libc.hdr.types.size_t
-    libc.include.sys_syscall
-    libc.src.__support.OSUtil.osutil
+    libc.src.__support.OSUtil.linux.syscall_wrappers.execve
     libc.src.errno.errno
 )
 
diff --git a/libc/src/unistd/linux/execle.cpp b/libc/src/unistd/linux/execle.cpp
index fb8bdf57a517c..fae705abd98a2 100644
--- a/libc/src/unistd/linux/execle.cpp
+++ b/libc/src/unistd/linux/execle.cpp
@@ -1,51 +1,55 @@
-//===-- Linux implementation of execle ------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Linux implementation of execle
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/unistd/execle.h"
-#include "src/__support/macros/config.h"
 
 #include "hdr/types/size_t.h"
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/OSUtil/linux/syscall_wrappers/execve.h"
 #include "src/__support/common.h"
 #include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
 #include <stdarg.h>
-#include <sys/syscall.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, execle, (const char *path, const char *arg0, ...)) {
-  va_list varargs;
+  va_list varargs, varargs_copy;
   va_start(varargs, arg0);
+  va_copy(varargs_copy, varargs);
 
   size_t argc = 1;
   while (va_arg(varargs, const char *) != nullptr)
     ++argc;
   va_end(varargs);
 
-  char **argv =
-      static_cast<char **>(__builtin_alloca((argc + 1) * sizeof(char *)));
+  char *argv[argc + 1];
   argv[0] = const_cast<char *>(arg0);
 
-  va_start(varargs, arg0);
   for (size_t i = 1; i <= argc; ++i)
-    argv[i] = va_arg(varargs, char *);
-  char **envp = va_arg(varargs, char **);
-  va_end(varargs);
+    argv[i] = va_arg(varargs_copy, char *);
+  char **envp = va_arg(varargs_copy, char **);
+  va_end(varargs_copy);
 
-  int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_execve, path, argv, envp);
-  if (ret < 0) {
-    libc_errno = -ret;
+  auto ret = linux_syscalls::execve(path, argv, envp);
+  if (!ret) {
+    libc_errno = ret.error();
     return -1;
   }
 
   // Control will not reach here on success but have a return statement will
   // keep the compilers happy.
-  return ret;
+  return *ret;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/integration/src/unistd/execle_test.cpp b/libc/test/integration/src/unistd/execle_test.cpp
index e53c51b4ef90a..eb31ed2048b41 100644
--- a/libc/test/integration/src/unistd/execle_test.cpp
+++ b/libc/test/integration/src/unistd/execle_test.cpp
@@ -1,10 +1,14 @@
-//===-- Unittests for execle ----------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // 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
 //
 //===----------------------------------------------------------------------===//
+/// 
+/// Unittests for execle
+///
+//===----------------------------------------------------------------------===//
 
 #include "src/sys/wait/waitpid.h"
 #include "src/unistd/execle.h"
diff --git a/libc/test/integration/src/unistd/execle_test_normal_exit.cpp b/libc/test/integration/src/unistd/execle_test_normal_exit.cpp
index 76936b2bff6a8..b2648704a7fae 100644
--- a/libc/test/integration/src/unistd/execle_test_normal_exit.cpp
+++ b/libc/test/integration/src/unistd/execle_test_normal_exit.cpp
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <signal.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/libc/test/integration/src/unistd/execle_test_signal_exit.cpp b/libc/test/integration/src/unistd/execle_test_signal_exit.cpp
index e266b5c07490f..fae0f1538f9ac 100644
--- a/libc/test/integration/src/unistd/execle_test_signal_exit.cpp
+++ b/libc/test/integration/src/unistd/execle_test_signal_exit.cpp
@@ -1,3 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <signal.h>
 #include <stdlib.h>
 #include <unistd.h>

>From 8a1b9960ebf6b35b632894e82771feb033082011 Mon Sep 17 00:00:00 2001
From: Bhavesh Mandalapu <bmandalapu at google.com>
Date: Wed, 19 Aug 2026 14:47:27 -0700
Subject: [PATCH 3/4] Refactor tests

---
 .../integration/src/unistd/CMakeLists.txt     | 34 ++++++-------------
 ...nal_exit.cpp => exec_test_signal_exit.cpp} |  0
 .../integration/src/unistd/execle_test.cpp    |  4 +--
 .../integration/src/unistd/execv_test.cpp     |  4 +--
 .../src/unistd/execv_test_signal_exit.cpp     | 10 ------
 .../integration/src/unistd/execve_test.cpp    |  4 +--
 6 files changed, 17 insertions(+), 39 deletions(-)
 rename libc/test/integration/src/unistd/{execle_test_signal_exit.cpp => exec_test_signal_exit.cpp} (100%)
 delete mode 100644 libc/test/integration/src/unistd/execv_test_signal_exit.cpp

diff --git a/libc/test/integration/src/unistd/CMakeLists.txt b/libc/test/integration/src/unistd/CMakeLists.txt
index 6eac86217383e..4091082486b96 100644
--- a/libc/test/integration/src/unistd/CMakeLists.txt
+++ b/libc/test/integration/src/unistd/CMakeLists.txt
@@ -62,26 +62,26 @@ if((${LIBC_TARGET_OS} STREQUAL "linux") AND (${LIBC_TARGET_ARCHITECTURE_IS_X86})
 endif()
 
 add_executable(
-  libc_execv_test_normal_exit
+  libc_exec_test_signal_exit
   EXCLUDE_FROM_ALL
-  execv_test_normal_exit.cpp
+  exec_test_signal_exit.cpp
 )
 set_target_properties(
-  libc_execv_test_normal_exit
+  libc_exec_test_signal_exit
   PROPERTIES
-    OUTPUT_NAME libc_execv_test_normal_exit
+    OUTPUT_NAME libc_exec_test_signal_exit
     RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 )
 
 add_executable(
-  libc_execv_test_signal_exit
+  libc_execv_test_normal_exit
   EXCLUDE_FROM_ALL
-  execv_test_signal_exit.cpp
+  execv_test_normal_exit.cpp
 )
 set_target_properties(
-  libc_execv_test_signal_exit
+  libc_execv_test_normal_exit
   PROPERTIES
-    OUTPUT_NAME libc_execv_test_signal_exit
+    OUTPUT_NAME libc_execv_test_normal_exit
     RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 )
 
@@ -97,18 +97,6 @@ set_target_properties(
     RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 )
 
-add_executable(
-  libc_execle_test_signal_exit
-  EXCLUDE_FROM_ALL
-  execle_test_signal_exit.cpp
-)
-set_target_properties(
-  libc_execle_test_signal_exit
-  PROPERTIES
-    OUTPUT_NAME libc_execle_test_signal_exit
-    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-)
-
 add_integration_test(
   execle_test
   SUITE
@@ -117,7 +105,7 @@ add_integration_test(
     execle_test.cpp
   DEPENDS
     libc_execle_test_normal_exit
-    libc_execle_test_signal_exit
+    libc_exec_test_signal_exit
     libc.src.errno.errno
     libc.src.sys.wait.waitpid
     libc.src.unistd.execle
@@ -134,7 +122,7 @@ add_integration_test(
     execv_test.cpp
   DEPENDS
     libc_execv_test_normal_exit
-    libc_execv_test_signal_exit
+    libc_exec_test_signal_exit
     libc.src.errno.errno
     libc.src.sys.wait.waitpid
     libc.src.unistd.execv
@@ -151,7 +139,7 @@ add_integration_test(
     execve_test.cpp
   DEPENDS
     libc_execv_test_normal_exit
-    libc_execv_test_signal_exit
+    libc_exec_test_signal_exit
     libc.src.errno.errno
     libc.src.sys.wait.waitpid
     libc.src.unistd.execve
diff --git a/libc/test/integration/src/unistd/execle_test_signal_exit.cpp b/libc/test/integration/src/unistd/exec_test_signal_exit.cpp
similarity index 100%
rename from libc/test/integration/src/unistd/execle_test_signal_exit.cpp
rename to libc/test/integration/src/unistd/exec_test_signal_exit.cpp
diff --git a/libc/test/integration/src/unistd/execle_test.cpp b/libc/test/integration/src/unistd/execle_test.cpp
index eb31ed2048b41..a943a2805c752 100644
--- a/libc/test/integration/src/unistd/execle_test.cpp
+++ b/libc/test/integration/src/unistd/execle_test.cpp
@@ -40,8 +40,8 @@ void fork_and_execle_normal_exit(char **envp) {
 void fork_and_execle_signal_exit(char **envp) {
   pid_t pid = LIBC_NAMESPACE::fork();
   if (pid == 0) {
-    const char *path = "libc_execle_test_signal_exit";
-    LIBC_NAMESPACE::execle(path, const_cast<char *>("execle_test_signal_exit"),
+    const char *path = "libc_exec_test_signal_exit";
+    LIBC_NAMESPACE::execle(path, const_cast<char *>("exec_test_signal_exit"),
                            static_cast<char *>(nullptr), envp);
   }
   ASSERT_TRUE(pid > 0);
diff --git a/libc/test/integration/src/unistd/execv_test.cpp b/libc/test/integration/src/unistd/execv_test.cpp
index bdd54d420760c..ffffd89af091f 100644
--- a/libc/test/integration/src/unistd/execv_test.cpp
+++ b/libc/test/integration/src/unistd/execv_test.cpp
@@ -36,9 +36,9 @@ void fork_and_execv_normal_exit() {
 void fork_and_execv_signal_exit() {
   pid_t pid = LIBC_NAMESPACE::fork();
   if (pid == 0) {
-    const char *path = "libc_execv_test_signal_exit";
+    const char *path = "libc_exec_test_signal_exit";
     char *const argv[] = {
-        const_cast<char *>("execv_test_normal_exit"),
+        const_cast<char *>("exec_test_signal_exit"),
         nullptr,
     };
     LIBC_NAMESPACE::execv(path, argv);
diff --git a/libc/test/integration/src/unistd/execv_test_signal_exit.cpp b/libc/test/integration/src/unistd/execv_test_signal_exit.cpp
deleted file mode 100644
index e266b5c07490f..0000000000000
--- a/libc/test/integration/src/unistd/execv_test_signal_exit.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-int main() {
-  char *env = getenv("__MISSING_ENV_VAR__");
-  if (env == nullptr)
-    raise(SIGUSR1);
-  return 0;
-}
diff --git a/libc/test/integration/src/unistd/execve_test.cpp b/libc/test/integration/src/unistd/execve_test.cpp
index 1204de3984c7e..e4ddf6f1879dd 100644
--- a/libc/test/integration/src/unistd/execve_test.cpp
+++ b/libc/test/integration/src/unistd/execve_test.cpp
@@ -36,9 +36,9 @@ void fork_and_execv_normal_exit(char **envp) {
 void fork_and_execv_signal_exit(char **envp) {
   pid_t pid = LIBC_NAMESPACE::fork();
   if (pid == 0) {
-    const char *path = "libc_execv_test_signal_exit";
+    const char *path = "libc_exec_test_signal_exit";
     char *const argv[] = {
-        const_cast<char *>("execv_test_normal_exit"),
+        const_cast<char *>("exec_test_signal_exit"),
         nullptr,
     };
     LIBC_NAMESPACE::execve(path, argv, envp);

>From cdd0979e1295adf2f7d212c796510395b5625594 Mon Sep 17 00:00:00 2001
From: Bhavesh Mandalapu <bmandalapu at google.com>
Date: Wed, 19 Aug 2026 15:47:41 -0700
Subject: [PATCH 4/4] Address comments

---
 .../__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt | 2 --
 libc/src/unistd/execle.h                                   | 7 ++++++-
 libc/test/integration/src/unistd/exec_test_signal_exit.cpp | 5 +++++
 libc/test/integration/src/unistd/execle_test.cpp           | 2 +-
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index ba4254eab0de6..0041db9a24cbd 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1005,5 +1005,3 @@ add_header_library(
     libc.src.__support.macros.config
     libc.include.sys_syscall
 )
-
-
diff --git a/libc/src/unistd/execle.h b/libc/src/unistd/execle.h
index 118ef9f9ed70f..a2ec59cca454d 100644
--- a/libc/src/unistd/execle.h
+++ b/libc/src/unistd/execle.h
@@ -1,10 +1,15 @@
-//===-- Implementation header for execle ------------------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for execle
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_UNISTD_EXECLE_H
 #define LLVM_LIBC_SRC_UNISTD_EXECLE_H
diff --git a/libc/test/integration/src/unistd/exec_test_signal_exit.cpp b/libc/test/integration/src/unistd/exec_test_signal_exit.cpp
index fae0f1538f9ac..bfcd25baa827b 100644
--- a/libc/test/integration/src/unistd/exec_test_signal_exit.cpp
+++ b/libc/test/integration/src/unistd/exec_test_signal_exit.cpp
@@ -5,6 +5,11 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Helper that terminates via signal (SIGUSR1) to test exec*
+///
+//===----------------------------------------------------------------------===//
 
 #include <signal.h>
 #include <stdlib.h>
diff --git a/libc/test/integration/src/unistd/execle_test.cpp b/libc/test/integration/src/unistd/execle_test.cpp
index a943a2805c752..100c556dcb0f9 100644
--- a/libc/test/integration/src/unistd/execle_test.cpp
+++ b/libc/test/integration/src/unistd/execle_test.cpp
@@ -5,7 +5,7 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-/// 
+///
 /// Unittests for execle
 ///
 //===----------------------------------------------------------------------===//



More information about the libc-commits mailing list