Skip to content

Commit e26d140

Browse files
semariefingolfinoscardssmith
authored
add initial support for OpenBSD (#53633)
These commits add initial support of OpenBSD in julia. It isn't strictly enough to make julia runable on OpenBSD (see #53632), but it covers the larger part. --------- Co-authored-by: Max Horn <[email protected]> Co-authored-by: Oscar Smith <[email protected]>
1 parent 09b356f commit e26d140

27 files changed

+194
-30
lines changed

Make.inc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ JL_MAJOR_SHLIB_EXT := $(SHLIB_EXT).$(SOMAJOR)
670670
endif
671671
endif
672672

673-
ifeq ($(OS), FreeBSD)
673+
ifneq ($(findstring $(OS),FreeBSD OpenBSD),)
674674
LOCALBASE ?= /usr/local
675675
else
676676
LOCALBASE ?= /usr
@@ -726,7 +726,7 @@ SANITIZE_LDFLAGS :=
726726
ifeq ($(SANITIZE_MEMORY),1)
727727
SANITIZE_OPTS += -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer
728728
SANITIZE_LDFLAGS += $(SANITIZE_OPTS)
729-
ifneq ($(findstring $(OS),Linux FreeBSD),)
729+
ifneq ($(findstring $(OS),Linux FreeBSD OpenBSD),)
730730
SANITIZE_LDFLAGS += -Wl,--warn-unresolved-symbols
731731
endif # OS Linux or FreeBSD
732732
endif # SANITIZE_MEMORY=1
@@ -1069,7 +1069,7 @@ JCFLAGS+=-DSYSTEM_LIBUNWIND
10691069
JCPPFLAGS+=-DSYSTEM_LIBUNWIND
10701070
endif
10711071
else
1072-
ifeq ($(OS),Darwin)
1072+
ifneq ($(findstring $(OS),Darwin OpenBSD),)
10731073
LIBUNWIND:=-lunwind
10741074
JCPPFLAGS+=-DLLVMLIBUNWIND
10751075
else
@@ -1380,6 +1380,19 @@ OSLIBS += -Wl,--export-dynamic -Wl,--version-script=$(BUILDROOT)/src/julia.expma
13801380
$(NO_WHOLE_ARCHIVE)
13811381
endif
13821382

1383+
ifeq ($(OS), OpenBSD)
1384+
JLDFLAGS += -Wl,--Bdynamic
1385+
ifneq ($(SANITIZE),1)
1386+
JLDFLAGS += -Wl,-no-undefined
1387+
endif
1388+
1389+
JLIBLDFLAGS += -Wl,-Bsymbolic-functions
1390+
1391+
OSLIBS += -Wl,--no-as-needed -lpthread -lm -lc++abi -lc
1392+
OSLIBS += -Wl,--whole-archive -lcompiler_rt -Wl,--no-whole-archive
1393+
OSLIBS += -Wl,--export-dynamic,--as-needed,--version-script=$(BUILDROOT)/src/julia.expmap
1394+
endif
1395+
13831396
ifeq ($(OS), Darwin)
13841397
SHLIB_EXT := dylib
13851398
OSLIBS += -framework CoreFoundation

base/binaryplatforms.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function validate_tags(tags::Dict)
198198
throw_invalid_key("arch")
199199
end
200200
# Validate `os`
201-
if tags["os"] ("linux", "macos", "freebsd", "windows")
201+
if tags["os"] ("linux", "macos", "freebsd", "openbsd", "windows")
202202
throw_invalid_key("os")
203203
end
204204
# Validate `os`/`arch` combination
@@ -375,8 +375,10 @@ function os()
375375
return "windows"
376376
elseif Sys.isapple()
377377
return "macos"
378-
elseif Sys.isbsd()
378+
elseif Sys.isfreebsd()
379379
return "freebsd"
380+
elseif Sys.isopenbsd()
381+
return "openbsd"
380382
else
381383
return "linux"
382384
end
@@ -422,6 +424,7 @@ const platform_names = Dict(
422424
"macos" => "macOS",
423425
"windows" => "Windows",
424426
"freebsd" => "FreeBSD",
427+
"openbsd" => "OpenBSD",
425428
nothing => "Unknown",
426429
)
427430

@@ -556,6 +559,8 @@ function os_str(p::AbstractPlatform)
556559
else
557560
return "-unknown-freebsd"
558561
end
562+
elseif os(p) == "openbsd"
563+
return "-unknown-openbsd"
559564
else
560565
return "-unknown"
561566
end
@@ -581,7 +586,8 @@ Sys.isapple(p::AbstractPlatform) = os(p) == "macos"
581586
Sys.islinux(p::AbstractPlatform) = os(p) == "linux"
582587
Sys.iswindows(p::AbstractPlatform) = os(p) == "windows"
583588
Sys.isfreebsd(p::AbstractPlatform) = os(p) == "freebsd"
584-
Sys.isbsd(p::AbstractPlatform) = os(p) ("freebsd", "macos")
589+
Sys.isopenbsd(p::AbstractPlatform) = os(p) == "openbsd"
590+
Sys.isbsd(p::AbstractPlatform) = os(p) ("freebsd", "openbsd", "macos")
585591
Sys.isunix(p::AbstractPlatform) = Sys.isbsd(p) || Sys.islinux(p)
586592

587593
const arch_mapping = Dict(
@@ -632,6 +638,7 @@ end
632638
const os_mapping = Dict(
633639
"macos" => "-apple-darwin[\\d\\.]*",
634640
"freebsd" => "-(.*-)?freebsd[\\d\\.]*",
641+
"openbsd" => "-(.*-)?openbsd[\\d\\.]*",
635642
"windows" => "-w64-mingw32",
636643
"linux" => "-(.*-)?linux",
637644
)
@@ -745,6 +752,9 @@ function Base.parse(::Type{Platform}, triplet::String; validate_strict::Bool = f
745752
if os == "freebsd"
746753
os_version = extract_os_version("freebsd", r".*freebsd([\d.]+)"sa)
747754
end
755+
if os == "openbsd"
756+
os_version = extract_os_version("openbsd", r".*openbsd([\d.]+)"sa)
757+
end
748758
tags["os_version"] = os_version
749759

750760
return Platform(arch, os, tags; validate_strict)
@@ -802,7 +812,7 @@ function parse_dl_name_version(path::String, os::String)
802812
# On OSX, libraries look like `libnettle.6.3.dylib`
803813
dlregex = r"^(.*?)((?:\.[\d]+)*)\.dylib$"sa
804814
else
805-
# On Linux and FreeBSD, libraries look like `libnettle.so.6.3.0`
815+
# On Linux and others BSD, libraries look like `libnettle.so.6.3.0`
806816
dlregex = r"^(.*?)\.so((?:\.[\d]+)*)$"sa
807817
end
808818

base/sysinfo.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ end
399399
400400
Get the maximum resident set size utilized in bytes.
401401
See also:
402-
- man page of `getrusage`(2) on Linux and FreeBSD.
402+
- man page of `getrusage`(2) on Linux and BSD.
403403
- Windows API `GetProcessMemoryInfo`.
404404
"""
405405
maxrss() = ccall(:jl_maxrss, Csize_t, ())

cli/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ else ifeq ($(OS),Linux)
2424
LOADER_LDFLAGS += -Wl,--no-as-needed -ldl -lpthread -rdynamic -lc -Wl,--as-needed -Wl,-z,notext
2525
else ifeq ($(OS),FreeBSD)
2626
LOADER_LDFLAGS += -Wl,--no-as-needed -ldl -lpthread -rdynamic -lc -Wl,--as-needed
27+
else ifeq ($(OS),OpenBSD)
28+
LOADER_LDFLAGS += -Wl,--no-as-needed -lpthread -rdynamic -lc -Wl,--as-needed
2729
else ifeq ($(OS),Darwin)
2830
LOADER_LDFLAGS += -lSystem
2931
endif
@@ -107,7 +109,7 @@ julia-debug: $(build_bindir)/julia-debug$(EXE)
107109
libjulia-release: $(build_shlibdir)/libjulia.$(SHLIB_EXT)
108110
libjulia-debug: $(build_shlibdir)/libjulia-debug.$(SHLIB_EXT)
109111

110-
ifneq (,$(filter $(OS), Linux FreeBSD))
112+
ifneq (,$(filter $(OS), Linux FreeBSD OpenBSD))
111113
VERSIONSCRIPT := -Wl,--version-script=$(BUILDDIR)/julia.expmap
112114
endif
113115

cli/loader_lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ __attribute__((constructor)) void jl_load_libjulia_internal(void) {
520520
(*jl_codegen_exported_func_addrs[symbol_idx]) = addr;
521521
}
522522
// Next, if we're on Linux/FreeBSD, set up fast TLS.
523-
#if !defined(_OS_WINDOWS_) && !defined(_OS_DARWIN_)
523+
#if !defined(_OS_WINDOWS_) && !defined(_OS_DARWIN_) && !defined(_OS_OPENBSD_)
524524
void (*jl_pgcstack_setkey)(void*, void*(*)(void)) = lookup_symbol(libjulia_internal, "jl_pgcstack_setkey");
525525
if (jl_pgcstack_setkey == NULL) {
526526
jl_loader_print_stderr("ERROR: Cannot find jl_pgcstack_setkey() function within libjulia-internal!\n");

contrib/normalize_triplet.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
platform_mapping = {
2020
'darwin': "-apple-darwin[\\d\\.]*",
2121
'freebsd': "-(.*-)?freebsd[\\d\\.]*",
22+
'openbsd': "-(.*-)?openbsd[\\d\\.]*",
2223
'windows': "-w64-mingw32",
2324
'linux': "-(.*-)?linux",
2425
}
@@ -96,6 +97,7 @@ def p(x):
9697
'darwin': 'apple-darwin',
9798
'windows': 'w64-mingw32',
9899
'freebsd': 'unknown-freebsd',
100+
'openbsd': 'unknown-openbsd',
99101
}
100102
x = r(x)
101103
if x:

deps/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ ifeq ($(OS), Linux)
6464
DEP_LIBS += unwind
6565
else ifeq ($(OS), FreeBSD)
6666
DEP_LIBS += unwind
67+
else ifeq ($(OS), OpenBSD)
68+
DEP_LIBS += llvmunwind
6769
else ifeq ($(OS), Darwin)
6870
DEP_LIBS += llvmunwind
6971
endif
7072
endif
7173
endif
7274

73-
ifneq (,$(findstring $(OS),Linux FreeBSD))
75+
ifneq (,$(findstring $(OS),Linux FreeBSD OpenBSD))
7476
ifeq ($(USE_SYSTEM_PATCHELF), 0)
7577
DEP_LIBS += patchelf
7678
PATCHELF:=$(build_depsbindir)/patchelf

deps/libgit2.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ LIBGIT2_OPTS += -DBUILD_TESTS=OFF -DDLLTOOL=`which $(CROSS_COMPILE)dlltool`
3333
LIBGIT2_OPTS += -DCMAKE_FIND_ROOT_PATH=/usr/$(XC_HOST) -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
3434
endif
3535
endif
36+
ifeq ($(OS),OpenBSD)
37+
# iconv.h is third-party
38+
LIBGIT2_OPTS += -DCMAKE_C_FLAGS="-I/usr/local/include"
39+
endif
3640

37-
ifneq (,$(findstring $(OS),Linux FreeBSD))
41+
ifneq (,$(findstring $(OS),Linux FreeBSD OpenBSD))
3842
LIBGIT2_OPTS += -DUSE_HTTPS="mbedTLS" -DUSE_SHA1="CollisionDetection" -DCMAKE_INSTALL_RPATH="\$$ORIGIN"
3943
endif
4044

deps/libssh2.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ endif
1111
LIBSSH2_OPTS := $(CMAKE_COMMON) -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF \
1212
-DCMAKE_BUILD_TYPE=Release
1313

14+
ifneq ($(fPIC),)
15+
LIBSSH2_OPTS += -DCMAKE_C_FLAGS="-fPIC"
16+
endif
17+
1418
ifeq ($(OS),WINNT)
1519
LIBSSH2_OPTS += -DCRYPTO_BACKEND=WinCNG -DENABLE_ZLIB_COMPRESSION=OFF
1620
ifeq ($(BUILD_OS),WINNT)
@@ -20,7 +24,7 @@ else
2024
LIBSSH2_OPTS += -DCRYPTO_BACKEND=mbedTLS -DENABLE_ZLIB_COMPRESSION=OFF
2125
endif
2226

23-
ifneq (,$(findstring $(OS),Linux FreeBSD))
27+
ifneq (,$(findstring $(OS),Linux FreeBSD OpenBSD))
2428
LIBSSH2_OPTS += -DCMAKE_INSTALL_RPATH="\$$ORIGIN"
2529
endif
2630

deps/libsuitesparse.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ else
3636
LIBSUITESPARSE_CMAKE_FLAGS += -DSUITESPARSE_USE_64BIT_BLAS=NO
3737
endif
3838

39-
ifneq (,$(findstring $(OS),Linux FreeBSD))
39+
ifneq (,$(findstring $(OS),Linux FreeBSD OpenBSD))
4040
LIBSUITESPARSE_CMAKE_FLAGS += -DCMAKE_INSTALL_RPATH="\$$ORIGIN"
4141
endif
4242

@@ -59,8 +59,8 @@ $(BUILDDIR)/SuiteSparse-$(LIBSUITESPARSE_VER)/build-compiled: | $(build_prefix)/
5959

6060
$(BUILDDIR)/SuiteSparse-$(LIBSUITESPARSE_VER)/build-compiled: $(BUILDDIR)/SuiteSparse-$(LIBSUITESPARSE_VER)/source-patched
6161
cd $(dir $<) && $(CMAKE) . $(LIBSUITESPARSE_CMAKE_FLAGS)
62-
make -C $(dir $<)
63-
make -C $(dir $<) install
62+
$(MAKE) -C $(dir $<)
63+
$(MAKE) -C $(dir $<) install
6464
echo 1 > $@
6565

6666
ifeq ($(OS),WINNT)

0 commit comments

Comments
 (0)