diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-04-19 14:23:00 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-04-19 19:26:43 +0200 |
commit | d86e60855f05a0e493f8362c12bfd40d5432d337 (patch) | |
tree | edf1a0c62961d7b8be8d26e09172b88a74f63912 /libphobos/libdruntime | |
parent | 3bffc4b37e85c7f6092dfb0fbe4067d268e97b46 (diff) | |
download | gcc-d86e60855f05a0e493f8362c12bfd40d5432d337.zip gcc-d86e60855f05a0e493f8362c12bfd40d5432d337.tar.gz gcc-d86e60855f05a0e493f8362c12bfd40d5432d337.tar.bz2 |
libphobos: Add section support code for OpenBSD (PR99691)
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.
Diffstat (limited to 'libphobos/libdruntime')
-rw-r--r-- | libphobos/libdruntime/config/common/threadasm.S | 2 | ||||
-rw-r--r-- | libphobos/libdruntime/gcc/backtrace.d | 4 | ||||
-rw-r--r-- | libphobos/libdruntime/gcc/sections/elf.d | 54 | ||||
-rw-r--r-- | libphobos/libdruntime/gcc/sections/package.d | 1 |
4 files changed, 44 insertions, 17 deletions
diff --git a/libphobos/libdruntime/config/common/threadasm.S b/libphobos/libdruntime/config/common/threadasm.S index 1e9bc76..3546217 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 45dd011..8f5582d 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 8450aec..3480fb9 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 4c2b542..1e887cd 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; |