[llvm-branch-commits] [llvm] release/23.x: [flang-rt] Fix runtime/environment.cpp compilation on FreeBSD (#219705) (PR #220839)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Sep 3 01:07:05 PDT 2026


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/220839

Backport 20102748a3548a1006e32056868cb3df8ce83565

Requested by: @brad0

>From 6dec807b0e25bb55e524077cf14b4d676597f456 Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Thu, 3 Sep 2026 09:57:45 +0200
Subject: [PATCH] [flang-rt] Fix runtime/environment.cpp compilation on FreeBSD
 (#219705)

`runtime/environment.cpp` doesn't compile on FreeBSD:

```
runtime/environment.cpp:115:47: error: use of undeclared identifier 'RTLD_DEFAULT'
  115 |   auto envpp{reinterpret_cast<char ***>(dlsym(RTLD_DEFAULT, "environ"))};
      |                                               ^~~~~~~~~~~~
```

`<dlfcn.h>` needs to be included.

Tested on `x86_64-pc-freebsd15.1` and `x86_64-pc-linux-gnu`.

(cherry picked from commit 20102748a3548a1006e32056868cb3df8ce83565)
---
 flang-rt/lib/runtime/environment.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/flang-rt/lib/runtime/environment.cpp b/flang-rt/lib/runtime/environment.cpp
index 4f3f0e46bb87d..ea98eb4634293 100644
--- a/flang-rt/lib/runtime/environment.cpp
+++ b/flang-rt/lib/runtime/environment.cpp
@@ -17,10 +17,12 @@
 
 #ifdef _WIN32
 #include <stdlib.h>
-#elif defined(__FreeBSD__) || RT_GPU_TARGET
+#elif defined(__FreeBSD__)
 // FreeBSD has environ in crt rather than libc. Using "extern char** environ"
 // in the code of a shared library makes it fail to link with -Wl,--no-undefined
 // See https://reviews.freebsd.org/D30842#840642
+#include <dlfcn.h>
+#elif RT_GPU_TARGET
 // GPU targets do not provide environ.
 #else
 extern char **environ;



More information about the llvm-branch-commits mailing list