[compiler-rt] [sanitizer_common] posix_spawn test should forward DYLD_LIBRARY_PATH (PR #168795)

Andrew Haberlandt via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 19 15:51:13 PST 2025


https://github.com/ndrewh created https://github.com/llvm/llvm-project/pull/168795

This test explicitly sets the environment for a spawned process. Since the compiler-rt lit config sets the library path variable [here](https://github.com/llvm/llvm-project/blob/main/compiler-rt/test/lit.common.cfg.py#L84) (i.e. to ensure that just-built runtimes are used for tests), we should also forward it to the spawned process.

My change only forwards the variable for Darwin (DYLD_LIBRARY_PATH), but we **_ought_** to also forward the variable for other platforms. However, it's not clear that there's any good way to plumb this into the test, since some platforms actually have multiple library path variables which would need to be forwarded (see: SunOS [here](https://github.com/llvm/llvm-project/blob/main/compiler-rt/test/lit.common.cfg.py#L102)). I considered adding a substitution variable for the library path variable, but that doesn't really work if there's multiple such variables.

>From 1f251c3c3d362e8e341571bb3e07900a71ac4901 Mon Sep 17 00:00:00 2001
From: Andrew Haberlandt <ahaberlandt at apple.com>
Date: Wed, 19 Nov 2025 15:34:45 -0800
Subject: [PATCH] posix_spawn test should forward DYLD_LIBRARY_PATH

---
 .../test/sanitizer_common/TestCases/Posix/posix_spawn.c  | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c b/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c
index ea58b92af6097..e570a61f9ac9a 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c
@@ -7,6 +7,8 @@
 #include <spawn.h>
 #include <stdio.h>
 #include <sys/wait.h>
+#include <string.h>
+#include <stdlib.h>
 
 int main(int argc, char **argv) {
   if (argc > 1) {
@@ -23,11 +25,16 @@ int main(int argc, char **argv) {
       argv[0], "2", "3", "4", "2", "3", "4", "2", "3", "4",
       "2",     "3", "4", "2", "3", "4", "2", "3", "4", NULL,
   };
-  char *const env[] = {
+  const char *env[] = {
       "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B",
       "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", NULL,
   };
 
+  char *lib_path = getenv("DYLD_LIRARY_PATH");
+  if (lib_path) {
+    env[0] = strdup(lib_path);
+  }
+
   pid_t pid;
   int s = posix_spawn(&pid, argv[0], &file_actions, &attr, args, env);
   assert(!s);



More information about the llvm-commits mailing list