Hello,
This is a bug report regarding llvm ports.
This has been confirmed for versions 19-22.

When compiling with -fexperimental-library on OpenBSD,
 clang tries to link -lc++experimental,
 but OpenBSD's libcxx is named libec++experimental.a,
 causing a linker error.
The library is built as libec++experimental.a due to OpenBSD's "ec++"
 naming convention, but clang's OpenBSD toolchain is hardcoded
 to request -lc++experimental, causing the linker error.

The following section likely needs to be fixed.
Related code:

https://github.com/llvm/llvm-project/blob/llvmorg-22.1.8/clang/lib/Driver/ToolChains/OpenBSD.cpp#L353C1-L362C2
void OpenBSD::AddCXXStdlibLibArgs(const ArgList &Args,
                                  ArgStringList &CmdArgs) const {
  bool Profiling = Args.hasArg(options::OPT_pg);

  CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
  if (Args.hasArg(options::OPT_fexperimental_library))
    CmdArgs.push_back("-lc++experimental");
  CmdArgs.push_back(Profiling ? "-lc++abi_p" : "-lc++abi");
  CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
}

Steps to reproduce:
$ doas pkg_add llvm%22 libcxx%22
$ echo "#include <syncstream>\nint main(){}" > test.cpp
$ clang++-22 -v -std=c++20 -fexperimental-library test.cpp
clang version 22.1.8
Target: amd64-unknown-openbsd7.9
Thread model: posix
InstalledDir: /usr/local/llvm22/bin
 "/usr/local/llvm22/bin/clang-22" -cc1 -triple amd64-unknown-openbsd7.9
 -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend
 -disable-llvm-verifier -discard-value-names -main-file-name test.cpp
 -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all
 -relaxed-aliasing -ffp-contract=on -fno-rounding-math
 -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64
 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/tmp
 -v -fcoverage-compilation-dir=/tmp
 -resource-dir /usr/local/llvm22/lib/clang/22
 -internal-isystem /usr/include/c++/v1
 -internal-isystem /usr/local/llvm22/lib/clang/22/include
 -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro
 -fexperimental-library -ferror-limit 19 -fmessage-length=132
 -femulated-tls -fwrapv -D_RET_PROTECTOR -ret-protector
 -fcf-protection=branch -fno-jump-tables -fgnuc-version=4.2.1
 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions
 -fexceptions -fno-builtin-malloc -fno-builtin-calloc
 -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free
 -fno-builtin-strdup -fno-builtin-strndup -faddrsig -fdwarf2-cfi-asm
 -o /tmp/test-480167.o -x c++ test.cpp
clang -cc1 version 22.1.8 based upon LLVM 22.1.8 default target 
amd64-unknown-openbsd7.9
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/v1
 /usr/local/llvm22/lib/clang/22/include
 /usr/include
End of search list.
 "/usr/bin/ld" -e __start --eh-frame-hdr
 -dynamic-linker /usr/libexec/ld.so
 -o a.out /usr/lib/crt0.o /usr/lib/crtbegin.o
 -L/usr/lib /tmp/test-480167.o -lc++ -lc++experimental -lc++abi
 -lpthread -lm -lcompiler_rt -lc -lcompiler_rt /usr/lib/crtend.o
ld: error: unable to find library -lc++experimental
clang++: error: linker command failed with exit code 1
(use -v to see invocation)

System Info:
$ sysctl -n kern.version
OpenBSD 7.9-current (GENERIC.MP) #2: Fri Jun 12 12:08:26 MDT 2026
    [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP

$ cat /var/db/installed.BUILDINFO
Build date: 1781288383 - Fri Jun 12 18:19:43 UTC 2026

ports tree version: current

Note:
I previously contacted the maintainers about this issue
 without receiving a response, so I'm posting to the public list.

-c2qd

diff --git 
a/devel/llvm/19/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp 
b/devel/llvm/19/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
index 55dc701f8f8..5a046c1cb92 100644
--- a/devel/llvm/19/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
+++ b/devel/llvm/19/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
@@ -21,3 +21,12 @@ Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
    ToolChain.addProfileRTLibs(Args, CmdArgs);

    const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
+@@ -365,7 +378,7 @@ void OpenBSD::AddCXXStdlibLibArgs(const ArgList &Args,
+
+   CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
+   if (Args.hasArg(options::OPT_fexperimental_library))
+-    CmdArgs.push_back("-lc++experimental");
++    CmdArgs.push_back("-lec++experimental");
+   CmdArgs.push_back(Profiling ? "-lc++abi_p" : "-lc++abi");
+   CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
+ }
diff --git 
a/devel/llvm/20/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp 
b/devel/llvm/20/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
index 9ec59adf692..0f201dbcd84 100644
--- a/devel/llvm/20/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
+++ b/devel/llvm/20/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
@@ -21,3 +21,12 @@ Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
    ToolChain.addProfileRTLibs(Args, CmdArgs);

    const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
+@@ -366,7 +379,7 @@ void OpenBSD::AddCXXStdlibLibArgs(const ArgList &Args,
+
+   CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
+   if (Args.hasArg(options::OPT_fexperimental_library))
+-    CmdArgs.push_back("-lc++experimental");
++    CmdArgs.push_back("-lec++experimental");
+   CmdArgs.push_back(Profiling ? "-lc++abi_p" : "-lc++abi");
+   CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
+ }
diff --git 
a/devel/llvm/21/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp 
b/devel/llvm/21/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
index b7aa7dae11d..451c411dc09 100644
--- a/devel/llvm/21/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
+++ b/devel/llvm/21/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
@@ -21,3 +21,12 @@ Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
    ToolChain.addProfileRTLibs(Args, CmdArgs);

    const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
+@@ -356,7 +369,7 @@ void OpenBSD::AddCXXStdlibLibArgs(const ArgList &Args,
+
+   CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
+   if (Args.hasArg(options::OPT_fexperimental_library))
+-    CmdArgs.push_back("-lc++experimental");
++    CmdArgs.push_back("-lec++experimental");
+   CmdArgs.push_back(Profiling ? "-lc++abi_p" : "-lc++abi");
+   CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
+ }
diff --git 
a/devel/llvm/22/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp 
b/devel/llvm/22/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
index b7aa7dae11d..451c411dc09 100644
--- a/devel/llvm/22/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
+++ b/devel/llvm/22/patches/patch-clang_lib_Driver_ToolChains_OpenBSD_cpp
@@ -21,3 +21,12 @@ Index: clang/lib/Driver/ToolChains/OpenBSD.cpp
    ToolChain.addProfileRTLibs(Args, CmdArgs);

    const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
+@@ -356,7 +369,7 @@ void OpenBSD::AddCXXStdlibLibArgs(const ArgList &Args,
+
+   CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
+   if (Args.hasArg(options::OPT_fexperimental_library))
+-    CmdArgs.push_back("-lc++experimental");
++    CmdArgs.push_back("-lec++experimental");
+   CmdArgs.push_back(Profiling ? "-lc++abi_p" : "-lc++abi");
+   CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
+ }

Reply via email to