Skip to content

Commit 8fce018

Browse files
committed
openbsd: init at 7.5
1 parent a8067e7 commit 8fce018

File tree

22 files changed

+621
-9
lines changed

22 files changed

+621
-9
lines changed

lib/systems/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ let
9393
else if final.isAndroid then "bionic"
9494
else if final.isLinux /* default */ then "glibc"
9595
else if final.isFreeBSD then "fblibc"
96+
else if final.isOpenBSD then "oblibc"
9697
else if final.isNetBSD then "nblibc"
9798
else if final.isAvr then "avrlibc"
9899
else if final.isGhcjs then null

lib/systems/examples.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ rec {
342342
useLLVM = true;
343343
};
344344

345+
x86_64-openbsd = {
346+
config = "x86_64-unknown-openbsd";
347+
useLLVM = true;
348+
};
349+
345350
#
346351
# WASM
347352
#

lib/systems/parse.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ rec {
469469
elem (elemAt l 2) [ "wasi" "redox" "mmixware" "ghcjs" "mingw32" ] ||
470470
hasPrefix "freebsd" (elemAt l 2) ||
471471
hasPrefix "netbsd" (elemAt l 2) ||
472+
hasPrefix "openbsd" (elemAt l 2) ||
472473
hasPrefix "genode" (elemAt l 2)
473474
then {
474475
cpu = elemAt l 0;

pkgs/development/compilers/llvm/common/compiler-rt/default.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
, linuxHeaders
1616
, libxcrypt
1717
, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD
18+
, forceLinkCompilerRt ? stdenv.hostPlatform.isOpenBSD
1819
}:
1920

2021
let
@@ -149,7 +150,9 @@ stdenv.mkDerivation ({
149150
ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o
150151
ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o
151152
'' + lib.optionalString doFakeLibgcc ''
152-
ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a
153+
ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libgcc.a
154+
'' + lib.optionalString forceLinkCompilerRt ''
155+
ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libcompiler_rt.a
153156
'';
154157

155158
meta = llvm_meta // {
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
commit ca923e69ae630b33393da2b0eaceee76f27609e4
2+
Author: John Ericson <[email protected]>
3+
Date: Fri May 10 13:16:40 2024 -0400
4+
5+
[libc++] Fix build on OpenBSD
6+
7+
- No indirect syscalls on OpenBSD
8+
9+
- Clock:
10+
11+
See https://lists.boost.org/boost-bugs/2015/07/41690.php and
12+
https://github.com/boostorg/log/commit/c98b1f459add14d5ce3e9e63e2469064601d7f71
13+
for a description of an analogous problem an fix for Boost.
14+
15+
diff --git a/libcxx/src/atomic.cpp b/libcxx/src/atomic.cpp
16+
index a55249a15c21..10cf6dc0ffcf 100644
17+
--- a/libcxx/src/atomic.cpp
18+
+++ b/libcxx/src/atomic.cpp
19+
@@ -19,25 +19,35 @@
20+
21+
#ifdef __linux__
22+
23+
-#include <unistd.h>
24+
-#include <linux/futex.h>
25+
-#include <sys/syscall.h>
26+
+# include <unistd.h>
27+
+# include <linux/futex.h>
28+
+# include <sys/syscall.h>
29+
30+
// libc++ uses SYS_futex as a universal syscall name. However, on 32 bit architectures
31+
// with a 64 bit time_t, we need to specify SYS_futex_time64.
32+
-#if !defined(SYS_futex) && defined(SYS_futex_time64)
33+
-# define SYS_futex SYS_futex_time64
34+
-#endif
35+
+# if !defined(SYS_futex) && defined(SYS_futex_time64)
36+
+# define SYS_futex SYS_futex_time64
37+
+# endif
38+
+# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__)
39+
40+
#elif defined(__FreeBSD__)
41+
42+
-#include <sys/types.h>
43+
-#include <sys/umtx.h>
44+
+# include <sys/types.h>
45+
+# include <sys/umtx.h>
46+
+
47+
+# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__)
48+
+
49+
+#elif defined(__OpenBSD__)
50+
+
51+
+// OpenBSD has no indirect syscalls
52+
+# define _LIBCPP_FUTEX(...) futex(__VA_ARGS__)
53+
54+
#else // <- Add other operating systems here
55+
56+
// Baseline needs no new headers
57+
58+
+# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__)
59+
+
60+
#endif
61+
62+
_LIBCPP_BEGIN_NAMESPACE_STD
63+
@@ -48,13 +58,13 @@ static void __libcpp_platform_wait_on_address(__cxx_atomic_contention_t const vo
64+
__cxx_contention_t __val)
65+
{
66+
static constexpr timespec __timeout = { 2, 0 };
67+
- syscall(SYS_futex, __ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0);
68+
+ _LIBCPP_FUTEX(__ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0);
69+
}
70+
71+
static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr,
72+
bool __notify_one)
73+
{
74+
- syscall(SYS_futex, __ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0);
75+
+ _LIBCPP_FUTEX(__ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0);
76+
}
77+
78+
#elif defined(__APPLE__) && defined(_LIBCPP_USE_ULOCK)
79+
diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
80+
index f1596132024c..ba3fca0ab9b1 100644
81+
--- a/libcxx/src/chrono.cpp
82+
+++ b/libcxx/src/chrono.cpp
83+
@@ -31,7 +31,9 @@
84+
# include <sys/time.h> // for gettimeofday and timeval
85+
#endif
86+
87+
-#if defined(__APPLE__) || defined (__gnu_hurd__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
88+
+// OpenBSD does not have a fully conforment suite of POSIX timers, but
89+
+// it does have clock_gettime and CLOCK_MONOTONIC which is all we need.
90+
+#if defined(__APPLE__) || defined (__gnu_hurd__) || defined (__OpenBSD__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
91+
# define _LIBCPP_HAS_CLOCK_GETTIME
92+
#endif
93+
94+
diff --git a/libcxxabi/src/cxa_guard_impl.h b/libcxxabi/src/cxa_guard_impl.h
95+
index e00d54b3a731..90d589be4d77 100644
96+
--- a/libcxxabi/src/cxa_guard_impl.h
97+
+++ b/libcxxabi/src/cxa_guard_impl.h
98+
@@ -47,6 +47,9 @@
99+
#include "__cxxabi_config.h"
100+
#include "include/atomic_support.h" // from libc++
101+
#if defined(__has_include)
102+
+# if __has_include(<sys/futex.h>)
103+
+# include <sys/futex.h>
104+
+# endif
105+
# if __has_include(<sys/syscall.h>)
106+
# include <sys/syscall.h>
107+
# endif
108+
@@ -411,7 +414,18 @@ private:
109+
// Futex Implementation
110+
//===----------------------------------------------------------------------===//
111+
112+
-#if defined(SYS_futex)
113+
+#if defined(__OpenBSD__)
114+
+void PlatformFutexWait(int* addr, int expect) {
115+
+ constexpr int WAIT = 0;
116+
+ futex(reinterpret_cast<volatile uint32_t*>(addr), WAIT, expect, NULL, NULL);
117+
+ __tsan_acquire(addr);
118+
+}
119+
+void PlatformFutexWake(int* addr) {
120+
+ constexpr int WAKE = 1;
121+
+ __tsan_release(addr);
122+
+ futex(reinterpret_cast<volatile uint32_t*>(addr), WAKE, INT_MAX, NULL, NULL);
123+
+}
124+
+#elif defined(SYS_futex)
125+
void PlatformFutexWait(int* addr, int expect) {
126+
constexpr int WAIT = 0;
127+
syscall(SYS_futex, addr, WAIT, expect, 0);

pkgs/os-specific/bsd/freebsd/lib/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
}
1515
.${stdenv'.hostPlatform.parsed.cpu.name} or stdenv'.hostPlatform.parsed.cpu.name;
1616

17-
install-wrapper = builtins.readFile ./install-wrapper.sh;
17+
install-wrapper = builtins.readFile ../../lib/install-wrapper.sh;
1818
}

pkgs/os-specific/bsd/netbsd/pkgs/install/package.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
# HACK: to ensure parent directories exist. This emulates GNU
1818
# install’s -D option. No alternative seems to exist in BSD install.
1919
let
20-
binstall = writeShellScript "binstall" ''
21-
set -eu
22-
for last in "$@"; do true; done
23-
mkdir -p $(dirname $last)
24-
@out@/bin/xinstall "$@"
25-
'';
20+
binstall = writeShellScript "binstall" (
21+
builtins.readFile ../../../lib/install-wrapper.sh
22+
+ ''
23+
@out@/bin/xinstall "''${args[@]}"
24+
''
25+
);
2626
in
2727
mkDerivation {
2828
path = "usr.bin/xinstall";

pkgs/os-specific/bsd/netbsd/pkgs/make.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mkDerivation {
1515
make-rules.postPatch
1616
+ ''
1717
# make needs this to pick up our sys make files
18-
export NIX_CFLAGS_COMPILE+=" -D_PATH_DEFSYSPATH=\"$out/share/mk\""
18+
appendToVar NIX_CFLAGS_COMPILE -D_PATH_DEFSYSPATH="$out/share/mk"
1919
'';
2020

2121
postInstall = ''
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
stdenv,
3+
lib,
4+
stdenvNoCC,
5+
makeScopeWithSplicing',
6+
generateSplicesForMkScope,
7+
pkgs,
8+
buildPackages,
9+
netbsd,
10+
}:
11+
12+
makeScopeWithSplicing' {
13+
otherSplices = generateSplicesForMkScope "openbsd";
14+
f = (
15+
self:
16+
lib.packagesFromDirectoryRecursive {
17+
callPackage = self.callPackage;
18+
directory = ./pkgs;
19+
}
20+
// {
21+
libc = self.callPackage ./pkgs/libc/package.nix {
22+
inherit (self) csu include lorder;
23+
inherit (buildPackages.openbsd) makeMinimal;
24+
inherit (buildPackages.netbsd)
25+
install
26+
gencat
27+
rpcgen
28+
tsort
29+
;
30+
};
31+
makeMinimal = buildPackages.netbsd.makeMinimal.override { inherit (self) make-rules; };
32+
mkDerivation = self.callPackage ./pkgs/mkDerivation.nix {
33+
inherit stdenv;
34+
inherit (buildPackages.netbsd) install;
35+
};
36+
include = self.callPackage ./pkgs/include/package.nix {
37+
inherit (buildPackages.openbsd) makeMinimal;
38+
inherit (buildPackages.netbsd) install rpcgen mtree;
39+
};
40+
csu = self.callPackage ./pkgs/csu.nix {
41+
inherit (self) include;
42+
inherit (buildPackages.openbsd) makeMinimal;
43+
inherit (buildPackages.netbsd) install;
44+
};
45+
make-rules = self.callPackage ./pkgs/make-rules/package.nix { };
46+
lorder = self.callPackage ./pkgs/lorder.nix { inherit (buildPackages.netbsd) install; };
47+
}
48+
);
49+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
lib,
3+
mkDerivation,
4+
bsdSetupHook,
5+
openbsdSetupHook,
6+
makeMinimal,
7+
install,
8+
include,
9+
}:
10+
11+
mkDerivation {
12+
path = "lib/csu";
13+
nativeBuildInputs = [
14+
bsdSetupHook
15+
openbsdSetupHook
16+
makeMinimal
17+
install
18+
];
19+
buildInputs = [ include ];
20+
meta.platforms = lib.platforms.openbsd;
21+
extraPaths = [ "libexec/ld.so" ];
22+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
lib,
3+
mkDerivation,
4+
makeMinimal,
5+
bsdSetupHook,
6+
openbsdSetupHook,
7+
install,
8+
rpcgen,
9+
mtree,
10+
pax,
11+
buildPackages,
12+
}:
13+
mkDerivation {
14+
path = "include";
15+
noCC = true;
16+
17+
extraPaths = [
18+
"lib"
19+
#"sys"
20+
"sys/arch"
21+
# LDIRS from the mmakefile
22+
"sys/crypto"
23+
"sys/ddb"
24+
"sys/dev"
25+
"sys/isofs"
26+
"sys/miscfs"
27+
"sys/msdosfs"
28+
"sys/net"
29+
"sys/netinet"
30+
"sys/netinet6"
31+
"sys/netmpls"
32+
"sys/net80211"
33+
"sys/nfs"
34+
"sys/ntfs"
35+
"sys/scsi"
36+
"sys/sys"
37+
"sys/ufs"
38+
"sys/uvm"
39+
];
40+
41+
nativeBuildInputs = [
42+
bsdSetupHook
43+
install
44+
makeMinimal
45+
mtree
46+
openbsdSetupHook
47+
pax
48+
rpcgen
49+
];
50+
51+
makeFlags = [
52+
"RPCGEN_CPP=${buildPackages.stdenv.cc.cc}/bin/cpp"
53+
"-B"
54+
];
55+
56+
headersOnly = true;
57+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
2+
index 4bb4b67fcbb..1c8a8e08e60 100644
3+
--- a/lib/libc/Makefile
4+
+++ b/lib/libc/Makefile
5+
@@ -6,7 +6,6 @@
6+
.include <bsd.own.mk>
7+
8+
LIB=c
9+
-LIBREBUILD=y
10+
CLEANFILES+=tags Symbols.map
11+
CFLAGS+=-Wimplicit
12+
#CFLAGS+=-Werror
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
NetBSD's make uses `${variable:tl}` not `${variable:L}`.
2+
3+
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
4+
index 4bb4b67fcbb..ffb35c196ea 100644
5+
--- a/lib/libc/Makefile
6+
+++ b/lib/libc/Makefile
7+
@@ -11,8 +11,8 @@ CLEANFILES+=tags Symbols.map
8+
CFLAGS+=-Wimplicit
9+
#CFLAGS+=-Werror
10+
LDADD=-nostdlib
11+
-.if ${COMPILER_VERSION:L} == "clang"
12+
+.if ${COMPILER_VERSION:tl} == "clang"
13+
LDADD+=-lcompiler_rt
14+
.else
15+
LDADD+=-lgcc
16+
.endif

0 commit comments

Comments
 (0)