From 18bed2c174362f76ddedf68bb700e8b2c817fcb5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 18 Jun 2020 14:09:59 +0200 Subject: Complete NetBSD compatibility --- libbutl/backtrace.cxx | 11 ++++++----- libbutl/backtrace.mxx | 6 +++--- libbutl/buildfile | 4 ++-- libbutl/fdstream.cxx | 6 +++--- libbutl/process.cxx | 5 ++++- libbutl/sha256c.c | 2 +- libbutl/target-triplet.cxx | 15 +++------------ libbutl/target-triplet.mxx | 1 + libbutl/uuid-freebsd.cxx | 10 +++++++++- tests/backtrace/testscript | 5 ++++- tests/target-triplet/driver.cxx | 8 ++++++++ 11 files changed, 44 insertions(+), 29 deletions(-) diff --git a/libbutl/backtrace.cxx b/libbutl/backtrace.cxx index 119f4d1..8c9c6ae 100644 --- a/libbutl/backtrace.cxx +++ b/libbutl/backtrace.cxx @@ -9,15 +9,16 @@ // complications of the build scripts/makefiles. // // With glibc linking with -rdynamic gives (non-static) function names. -// FreeBSD requires explicitly linking -lexecinfo. +// FreeBSD/NetBSD requires explicitly linking -lexecinfo. // // Note that some libc implementation on Linux (most notably, musl), don't // support this, at least not out of the box. // #ifndef BUILD2_BOOTSTRAP -# if defined(__GLIBC__) || \ - defined(__APPLE__) || \ - defined(__FreeBSD__) +# if defined(__GLIBC__) || \ + defined(__APPLE__) || \ + defined(__FreeBSD__) || \ + defined(__NetBSD__) # define LIBBUTL_BACKTRACE # endif #else @@ -71,7 +72,7 @@ namespace butl #ifdef LIBBUTL_BACKTRACE - // Note: backtrace() returns int on Linux and MacOS and size_t on FreeBSD. + // Note: backtrace() returns int on Linux and MacOS and size_t on *BSD. // void* buf[1024]; auto n (::backtrace (buf, 1024)); diff --git a/libbutl/backtrace.mxx b/libbutl/backtrace.mxx index 6cde022..f5a63d5 100644 --- a/libbutl/backtrace.mxx +++ b/libbutl/backtrace.mxx @@ -31,9 +31,9 @@ LIBBUTL_MODEXPORT namespace butl // function name for each stack frame. // // Currently this functionality is only available on Linux (with glibc), - // FreeBSD, and Mac OS. On the first two platforms the address can be mapped - // to the function name and, if built with debug info, to source location - // using the addr2line(1) utility: + // FreeBSD/NetBSD, and Mac OS. On the first two platforms the address + // can be mapped to the function name and, if built with debug info, to + // source location using the addr2line(1) utility: // // $ addr2line -f -C -e // diff --git a/libbutl/buildfile b/libbutl/buildfile index 2d40031..6526900 100644 --- a/libbutl/buildfile +++ b/libbutl/buildfile @@ -38,7 +38,7 @@ lib{butl}: file{*.c *.h} lib{butl}: cxx{uuid-linux}: include = ($tclass == 'linux') lib{butl}: cxx{uuid-macos}: include = ($tclass == 'macos') lib{butl}: cxx{uuid-windows}: include = $windows -lib{butl}: cxx{uuid-freebsd}: include = ($tsys == 'freebsd') +lib{butl}: cxx{uuid-freebsd}: include = ($tsys == 'freebsd' || $tsys == 'netbsd') # Additional system libraries. # @@ -56,7 +56,7 @@ switch $tclass, $tsys case 'windows' cxx.libs += rpcrt4.lib imagehlp.lib - case 'bsd', 'freebsd' + case 'bsd', 'freebsd' | 'netbsd' cxx.libs += -lexecinfo } diff --git a/libbutl/fdstream.cxx b/libbutl/fdstream.cxx index e108df5..7fdb08b 100644 --- a/libbutl/fdstream.cxx +++ b/libbutl/fdstream.cxx @@ -1043,9 +1043,9 @@ namespace butl of |= O_LARGEFILE; #endif - // Unlike other platforms, FreeBSD allows opening a directory as a file - // which will cause all kinds of problems upstream (e.g., cpfile()). So we - // detect and diagnose this. + // Unlike other platforms, *BSD allows opening a directory as a file which + // will cause all kinds of problems upstream (e.g., cpfile()). So we detect + // and diagnose this. // #if defined(__FreeBSD__) || defined(__NetBSD__) { diff --git a/libbutl/process.cxx b/libbutl/process.cxx index 2dc3809..0695493 100644 --- a/libbutl/process.cxx +++ b/libbutl/process.cxx @@ -43,7 +43,10 @@ // # elif defined(__FreeBSD__) && __FreeBSD__ >= 8 # define LIBBUTL_POSIX_SPAWN -# elif defined(__NetBSD__) +// +// On NetBSD posix_spawn() appeared in 6.0 (see the man page for details). +// +# elif defined(__NetBSD__) && __NetBSD__ >= 6 # define LIBBUTL_POSIX_SPAWN // // posix_spawn() appeared in Version 3 of the Single UNIX Specification that diff --git a/libbutl/sha256c.c b/libbutl/sha256c.c index c98dd10..348fb44 100644 --- a/libbutl/sha256c.c +++ b/libbutl/sha256c.c @@ -123,7 +123,7 @@ be64enc(void *pp, uint64_t u) p[6] = (u >> 8) & 0xff; p[7] = u & 0xff; } -#endif /* __FreeBSD__ */ +#endif /* __FreeBSD__ || __NetBSD__ */ /* The rest is the unmodified (except for a few explicit casts to make compilable in C++) latest implementation from FreeBSD sys/crypto/sha2/. */ diff --git a/libbutl/target-triplet.cxx b/libbutl/target-triplet.cxx index 8eb6de6..c2535b1 100644 --- a/libbutl/target-triplet.cxx +++ b/libbutl/target-triplet.cxx @@ -54,16 +54,14 @@ namespace butl // VENDOR. Unless it is a first component of two-component system, as in // i686-linux-gnu. // - if (f != l) + // There are also cases like x86_64--netbsd. + // + if (l - f > 1) { // [f, p) is VENDOR. // string::size_type p (s.find ('-', ++f)), n (p - f); - if (n == 0) { - goto netbsd_empty_vendor; - } - // Do we have all four components? If so, then we don't need to do any // special recognition of two-component systems. // @@ -103,8 +101,6 @@ namespace butl } } -netbsd_empty_vendor: - // (l, npos) is SYSTEM // system.assign (s, ++l, string::npos); @@ -112,11 +108,6 @@ netbsd_empty_vendor: if (system.empty ()) bad ("missing os/kernel/abi"); - if (system.compare(0, 6, "netbsd") == 0) - vendor.assign("unknown"); - else - bad("empty vendor"); - if (system.front () == '-' || system.back () == '-') bad ("invalid os/kernel/abi"); diff --git a/libbutl/target-triplet.mxx b/libbutl/target-triplet.mxx index 5f98195..e68bc68 100644 --- a/libbutl/target-triplet.mxx +++ b/libbutl/target-triplet.mxx @@ -80,6 +80,7 @@ LIBBUTL_MODEXPORT namespace butl // // x86_64-apple-darwin14.5.0 x86_64 apple darwin 14.5.0 // x86_64-unknown-freebsd10.2 x86_64 freebsd 10.2 + // x86_64-unknown-netbsd9.0 x86_64 netbsd 9.0 // i686-elf i686 elf // arm-eabi arm eabi // arm-none-eabi arm eabi diff --git a/libbutl/uuid-freebsd.cxx b/libbutl/uuid-freebsd.cxx index 567c241..daf680b 100644 --- a/libbutl/uuid-freebsd.cxx +++ b/libbutl/uuid-freebsd.cxx @@ -31,7 +31,7 @@ namespace butl // // Specifically (and as of FreeBSD 11.2), we get a version 1 (MAC/time- // based) UUID and it seems there is provision for getting the time in a - // collision-safe: + // collision-safe manner: // // "According to the algorithm of generating time-based UUIDs, this will // also force a new random clock sequence, thereby increasing the @@ -43,6 +43,14 @@ namespace butl // smart enough not to start return random UUIDs without a good source of // randomness, at least not by default. // + // When it comes to NetBSD, there is this HISTORY note in the uuidgen(2) + // man page: + // + // "It was changed to use version 4 UUIDs, i.e. randomly generated UUIDs, + // in NetBSD 8.0." + // + // And we will assume random NetBSD UUIDs are strong. + // struct ::uuid d; if (uuidgen (&d, 1) != 0) diff --git a/tests/backtrace/testscript b/tests/backtrace/testscript index 206e1a5..fe4cb37 100644 --- a/tests/backtrace/testscript +++ b/tests/backtrace/testscript @@ -6,7 +6,10 @@ tsys = $cxx.target.system : basic : -if ($tclass == 'linux' || $tclass == 'macos' || $tsys == 'freebsd') +if ($tclass == 'linux' || \ + $tclass == 'macos' || \ + $tsys == 'freebsd' || \ + $tsys == 'netbsd') { # The stack frame line format varies among OSes. The only common thing is # the '0x' function address prefix. diff --git a/tests/target-triplet/driver.cxx b/tests/target-triplet/driver.cxx index 62e6503..0bb305e 100644 --- a/tests/target-triplet/driver.cxx +++ b/tests/target-triplet/driver.cxx @@ -89,6 +89,10 @@ main () "x86_64-linux-gnux32", "x86_64", "", "linux-gnux32", "", "linux")); + assert (test ("x86_64--netbsd", + "x86_64-netbsd", + "x86_64", "", "netbsd", "", "bsd")); + // Removal of none-. // assert (test ("arm-none", @@ -109,6 +113,10 @@ main () "x86_64-freebsd10.2", "x86_64", "", "freebsd", "10.2", "bsd")); + assert (test ("x86_64-unknown-netbsd9.0", + "x86_64-netbsd9.0", + "x86_64", "", "netbsd", "9.0", "bsd")); + assert (test ("x86_64-pc-openbsd5.6", "x86_64-openbsd5.6", "x86_64", "", "openbsd", "5.6", "bsd")); -- cgit v1.1