# HG changeset patch # Parent 3b397b651aecb48e300966e0d709ac6e5cf0c3b8 Work around lack of dlpi_tls_modid before Solaris 11.5 diff --git a/libphobos/configure.ac b/libphobos/configure.ac --- a/libphobos/configure.ac +++ b/libphobos/configure.ac @@ -32,6 +32,7 @@ AC_CONFIG_HEADERS(config.h) AM_ENABLE_MULTILIB(, ..) AC_CANONICAL_SYSTEM +AC_USE_SYSTEM_EXTENSIONS target_alias=${target_alias-$target} AC_SUBST(target_alias) @@ -126,6 +127,7 @@ DRUNTIME_OS_SOURCES DRUNTIME_OS_THREAD_MODEL DRUNTIME_OS_ARM_EABI_UNWINDER DRUNTIME_OS_MINFO_BRACKETING +DRUNTIME_OS_DLPI_TLS_MODID DRUNTIME_OS_LINK_SPEC DRUNTIME_LIBRARIES_CLIB diff --git a/libphobos/libdruntime/gcc/config.d.in b/libphobos/libdruntime/gcc/config.d.in --- a/libphobos/libdruntime/gcc/config.d.in +++ b/libphobos/libdruntime/gcc/config.d.in @@ -35,6 +35,9 @@ enum ThreadModel enum ThreadModel GNU_Thread_Model = ThreadModel.@DCFG_THREAD_MODEL@; +// Whether struct dl_phdr_info has dlpi_tls_modid member. +enum OS_Have_Dlpi_Tls_Modid = @DCFG_DLPI_TLS_MODID@; + // Whether target has support for builtin atomics. enum GNU_Have_Atomics = @DCFG_HAVE_ATOMIC_BUILTINS@; diff --git a/libphobos/libdruntime/rt/sections_elf_shared.d b/libphobos/libdruntime/rt/sections_elf_shared.d --- a/libphobos/libdruntime/rt/sections_elf_shared.d +++ b/libphobos/libdruntime/rt/sections_elf_shared.d @@ -750,8 +750,40 @@ void scanSegments(in ref dl_phdr_info in case PT_TLS: // TLS segment assert(!pdso._tlsSize); // is unique per DSO - pdso._tlsMod = info.dlpi_tls_modid; - pdso._tlsSize = phdr.p_memsz; + static if (OS_Have_Dlpi_Tls_Modid) + { + pdso._tlsMod = info.dlpi_tls_modid; + pdso._tlsSize = phdr.p_memsz; + } + else version (Solaris) + { + struct Rt_map + { + Link_map rt_public; + const char* rt_pathname; + c_ulong rt_padstart; + c_ulong rt_padimlen; + c_ulong rt_msize; + uint rt_flags; + uint rt_flags1; + c_ulong rt_tlsmodid; + } + + Rt_map* map; + version (Shared) + dlinfo(handleForName(info.dlpi_name), RTLD_DI_LINKMAP, &map); + else + dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map); + // Until Solaris 11.4, tlsmodid for the executable is 0. + // Let it start at 1 as the rest of the code expects. + pdso._tlsMod = map.rt_tlsmodid + 1; + pdso._tlsSize = phdr.p_memsz; + } + else + { + pdso._tlsMod = 0; + pdso._tlsSize = 0; + } break; default: @@ -1055,6 +1087,12 @@ void[] getTLSRange(size_t mod, size_t sz if (mod == 0) return null; + version (Solaris) + { + static if (!OS_Have_Dlpi_Tls_Modid) + mod -= 1; + } + // base offset auto ti = tls_index(mod, 0); return (__tls_get_addr(&ti)-TLS_DTV_OFFSET)[0 .. sz]; diff --git a/libphobos/m4/druntime/os.m4 b/libphobos/m4/druntime/os.m4 --- a/libphobos/m4/druntime/os.m4 +++ b/libphobos/m4/druntime/os.m4 @@ -184,6 +184,20 @@ AC_DEFUN([DRUNTIME_OS_MINFO_BRACKETING], AC_LANG_POP([C]) ]) +# DRUNTIME_OS_DLPI_TLS_MODID +# ---------------------------- +# Check if struct dl_phdr_info includes the dlpi_tls_modid member and +# substitute DCFG_DLPI_TLS_MODID. +AC_DEFUN([DRUNTIME_OS_DLPI_TLS_MODID], +[ + AC_LANG_PUSH([C]) + AC_CHECK_MEMBER([struct dl_phdr_info.dlpi_tls_modid], + [DCFG_DLPI_TLS_MODID=true], [DCFG_DLPI_TLS_MODID=false], + [[#include ]]) + AC_SUBST(DCFG_DLPI_TLS_MODID) + AC_LANG_POP([C]) +]) + # DRUNTIME_OS_LINK_SPEC # --------------------- # Add target-specific link options to link_spec.