Hi, This patch fixes the section support code for libphobos on OpenBSD, this is enough to get the library built, and most tests will pass now.
Testsuite hasn't been confirmed to pass cleanly just yet, so support for libphobos on OpenBSD is still considered experimental. Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, as well as x86_64-openbsd6.8 for testing the initial port, and committed to mainline. Regards, Iain. --- libphobos/ChangeLog: PR d/99691 * configure: Regenerate. * libdruntime/config/common/threadasm.S: Add __OpenBSD__. * libdruntime/gcc/backtrace.d: Import core.sys.openbsd.dlfcn on OpenBSD platforms. * libdruntime/gcc/sections/elf.d (SharedElf): Define on OpenBSD. (linkMapForHandle): Implement for OpenBSD. (exeLinkMap): Remove. (getDependencies): Adjust dlpi_addr on OpenBSD. (handleForName): Implement for OpenBSD. (IterateManually): Define on OpenBSD. * libdruntime/gcc/sections/package.d (SectionsElf): Define on OpenBSD. * m4/druntime/libraries.m4 (DRUNTIME_LIBRARIES_ATOMIC): Test for enable_libatomic. (DRUNTIME_LIBRARIES_BACKTRACE): Test for enable_libbacktrace. --- libphobos/configure | 4 +- .../libdruntime/config/common/threadasm.S | 2 +- libphobos/libdruntime/gcc/backtrace.d | 4 +- libphobos/libdruntime/gcc/sections/elf.d | 54 +++++++++++++------ libphobos/libdruntime/gcc/sections/package.d | 1 + libphobos/m4/druntime/libraries.m4 | 4 +- 6 files changed, 48 insertions(+), 21 deletions(-) diff --git a/libphobos/configure b/libphobos/configure index fe7cd9c11ff..2c0f57cef03 100755 --- a/libphobos/configure +++ b/libphobos/configure @@ -14917,7 +14917,7 @@ fi DCFG_HAVE_LIBATOMIC=false LIBATOMIC= - if test "x$with_libatomic" != "xno"; then : + if test "x$enable_libatomic" != "xno" && test "x$with_libatomic" != "xno"; then : DCFG_HAVE_LIBATOMIC=true LIBATOMIC=../../libatomic/libatomic_convenience.la @@ -14953,7 +14953,7 @@ if test "${with_libbacktrace+set}" = set; then : fi - if test "x$with_libbacktrace" != "xno"; then : + if test "x$enable_libbacktrace" != "xno" && test "x$with_libbacktrace" != "xno"; then : LIBBACKTRACE=../../libbacktrace/libbacktrace.la diff --git a/libphobos/libdruntime/config/common/threadasm.S b/libphobos/libdruntime/config/common/threadasm.S index 1e9bc760527..35462170e58 100644 --- a/libphobos/libdruntime/config/common/threadasm.S +++ b/libphobos/libdruntime/config/common/threadasm.S @@ -22,7 +22,7 @@ a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see <http://www.gnu.org/licenses/>. */ -#if (__linux__ || __FreeBSD__ || __NetBSD__ || __DragonFly__) && __ELF__ +#if (__linux__ || __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __DragonFly__) && __ELF__ /* * Mark the resulting object file as not requiring execution permissions on * stack memory. The absence of this section would mark the whole resulting diff --git a/libphobos/libdruntime/gcc/backtrace.d b/libphobos/libdruntime/gcc/backtrace.d index 45dd011dc63..8f5582d7469 100644 --- a/libphobos/libdruntime/gcc/backtrace.d +++ b/libphobos/libdruntime/gcc/backtrace.d @@ -424,8 +424,10 @@ private: import core.sys.freebsd.dlfcn; else version (NetBSD) import core.sys.netbsd.dlfcn; + else version (OpenBSD) + import core.sys.openbsd.dlfcn; else version (Solaris) - import core.sys.netbsd.dlfcn; + import core.sys.solaris.dlfcn; else version (Posix) import core.sys.posix.dlfcn; diff --git a/libphobos/libdruntime/gcc/sections/elf.d b/libphobos/libdruntime/gcc/sections/elf.d index 8450aecb239..3480fb9474c 100644 --- a/libphobos/libdruntime/gcc/sections/elf.d +++ b/libphobos/libdruntime/gcc/sections/elf.d @@ -33,6 +33,7 @@ version (CRuntime_Glibc) enum SharedELF = true; else version (CRuntime_Musl) enum SharedELF = true; else version (FreeBSD) enum SharedELF = true; else version (NetBSD) enum SharedELF = true; +else version (OpenBSD) enum SharedELF = true; else version (DragonFlyBSD) enum SharedELF = true; else version (CRuntime_UClibc) enum SharedELF = true; else version (Solaris) enum SharedELF = true; @@ -62,6 +63,12 @@ else version (NetBSD) import core.sys.netbsd.sys.elf; import core.sys.netbsd.sys.link_elf; } +else version (OpenBSD) +{ + import core.sys.openbsd.dlfcn; + import core.sys.openbsd.sys.elf; + import core.sys.openbsd.sys.link_elf; +} else version (DragonFlyBSD) { import core.sys.dragonflybsd.dlfcn; @@ -688,20 +695,22 @@ version (Shared) @nogc nothrow: link_map* linkMapForHandle(void* handle) { - link_map* map; - const success = dlinfo(handle, RTLD_DI_LINKMAP, &map) == 0; - safeAssert(success, "Failed to get DSO info."); - return map; + static if (__traits(compiles, RTLD_DI_LINKMAP)) + { + link_map* map; + const success = dlinfo(handle, RTLD_DI_LINKMAP, &map) == 0; + safeAssert(success, "Failed to get DSO info."); + return map; + } + else version (OpenBSD) + { + safeAssert(handle !is null, "Failed to get DSO info."); + return cast(link_map*)handle; + } + else + static assert(0, "unimplemented"); } - link_map* exeLinkMap(link_map* map) - { - safeAssert(map !is null, "Invalid link_map."); - while (map.l_prev !is null) - map = map.l_prev; - return map; - } - DSO* dsoForHandle(void* handle) { DSO* pdso; @@ -766,6 +775,8 @@ version (Shared) strtab = cast(const(char)*)(info.dlpi_addr + dyn.d_un.d_ptr); // relocate else version (NetBSD) strtab = cast(const(char)*)(info.dlpi_addr + dyn.d_un.d_ptr); // relocate + else version (OpenBSD) + strtab = cast(const(char)*)(info.dlpi_addr + dyn.d_un.d_ptr); // relocate else version (DragonFlyBSD) strtab = cast(const(char)*)(info.dlpi_addr + dyn.d_un.d_ptr); // relocate else version (Solaris) @@ -795,9 +806,21 @@ version (Shared) void* handleForName(const char* name) { - auto handle = .dlopen(name, RTLD_NOLOAD | RTLD_LAZY); - version (Solaris) { } - else if (handle !is null) .dlclose(handle); // drop reference count + version (Solaris) enum refCounted = false; + else version (OpenBSD) enum refCounted = false; + else enum refCounted = true; + + static if (__traits(compiles, RTLD_NOLOAD)) + enum flags = (RTLD_NOLOAD | RTLD_LAZY); + else + enum flags = RTLD_LAZY; + + auto handle = .dlopen(name, flags); + static if (refCounted) + { + if (handle !is null) + .dlclose(handle); // drop reference count + } return handle; } } @@ -891,6 +914,7 @@ bool findDSOInfoForAddr(in void* addr, dl_phdr_info* result=null) nothrow @nogc { version (linux) enum IterateManually = true; else version (NetBSD) enum IterateManually = true; + else version (OpenBSD) enum IterateManually = true; else version (Solaris) enum IterateManually = true; else enum IterateManually = false; diff --git a/libphobos/libdruntime/gcc/sections/package.d b/libphobos/libdruntime/gcc/sections/package.d index 4c2b542df23..1e887cdcb8f 100644 --- a/libphobos/libdruntime/gcc/sections/package.d +++ b/libphobos/libdruntime/gcc/sections/package.d @@ -27,6 +27,7 @@ version (CRuntime_Musl) version = SectionsElf; version (CRuntime_UClibc) version = SectionsElf; version (FreeBSD) version = SectionsElf; version (NetBSD) version = SectionsElf; +version (OpenBSD) version = SectionsElf; version (DragonFlyBSD) version = SectionsElf; version (Solaris) version = SectionsElf; version (OSX) version = SectionsMacho; diff --git a/libphobos/m4/druntime/libraries.m4 b/libphobos/m4/druntime/libraries.m4 index 743d3e3e17c..45a56f6f76a 100644 --- a/libphobos/m4/druntime/libraries.m4 +++ b/libphobos/m4/druntime/libraries.m4 @@ -116,7 +116,7 @@ AC_DEFUN([DRUNTIME_LIBRARIES_ATOMIC], DCFG_HAVE_LIBATOMIC=false LIBATOMIC= - AS_IF([test "x$with_libatomic" != "xno"], [ + AS_IF([test "x$enable_libatomic" != "xno" && test "x$with_libatomic" != "xno"], [ DCFG_HAVE_LIBATOMIC=true LIBATOMIC=../../libatomic/libatomic_convenience.la ], [ @@ -145,7 +145,7 @@ AC_DEFUN([DRUNTIME_LIBRARIES_BACKTRACE], AS_HELP_STRING([--without-libbacktrace], [Do not use libbacktrace in core.runtime (default: auto)])) - AS_IF([test "x$with_libbacktrace" != "xno"], [ + AS_IF([test "x$enable_libbacktrace" != "xno" && test "x$with_libbacktrace" != "xno"], [ LIBBACKTRACE=../../libbacktrace/libbacktrace.la gdc_save_CPPFLAGS=$CPPFLAGS -- 2.27.0