aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-05-17 09:53:25 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-05-17 09:53:25 +0200
commitccb9aa7f2db7f5e867c8025d7da00cf147222854 (patch)
tree5def62d5fbb7a2d80c973831b4641156dd062e83
parentf719647b45953bf3a1996fbc62976571d7cb9112 (diff)
Handle backtrace()/libexecinfo for OpenBSD
This functionality is available as built-in from OpenBSD 7.0.
-rw-r--r--libbutl/backtrace.cxx8
-rw-r--r--libbutl/buildfile8
2 files changed, 15 insertions, 1 deletions
diff --git a/libbutl/backtrace.cxx b/libbutl/backtrace.cxx
index c0cf472..347e231 100644
--- a/libbutl/backtrace.cxx
+++ b/libbutl/backtrace.cxx
@@ -7,7 +7,8 @@
// complications of the build scripts/makefiles.
//
// With glibc linking with -rdynamic gives (non-static) function names.
-// FreeBSD/NetBSD requires explicitly linking -lexecinfo.
+// FreeBSD/NetBSD requires explicitly linking -lexecinfo. OpenBSD only has
+// this functionality built-in from 7.0 and requires -lexecinfo.
//
// Note that some libc implementation on Linux (most notably, musl), don't
// support this, at least not out of the box.
@@ -18,6 +19,11 @@
defined(__FreeBSD__) || \
defined(__NetBSD__)
# define LIBBUTL_BACKTRACE
+# elif defined (__OpenBSD__)
+# include <sys/param.h> // OpenBSD (yyyymm)
+# if OpenBSD >= 202110 // 7.0 was released in October 2021.
+# define LIBBUTL_BACKTRACE
+# endif
# endif
#else
# if defined(__GLIBC__) || \
diff --git a/libbutl/buildfile b/libbutl/buildfile
index 4dd952c..6c490af 100644
--- a/libbutl/buildfile
+++ b/libbutl/buildfile
@@ -65,6 +65,14 @@ switch $tclass, $tsys
case 'bsd', 'freebsd' | 'netbsd'
cxx.libs += -lexecinfo
+
+ case 'bsd', 'openbsd'
+ {
+ # Built-in libexecinfo is only available since OpenBSD 7.0.
+ #
+ if (([uint64] $regex.replace($cxx.target.version, '(\d+)\..+', '\1')) >= 7)
+ cxx.libs += -lexecinfo
+ }
}
if! $windows