[libphobos] Work around lack of dlpi_tls_modid before Solaris 11.5
Tue Apr 9 19:31:00 GMT 2019
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:
> Before Solaris 11.5, struct dl_phdr_info lacked the dlpi_tls_modid
> member. While the support might be backported to Solaris 11.4, it
> certainly won't to previous Solaris releases. To work around this, I've
> used the following patch. Again, it's pretty straightforward.
> Point of note:
> * On Solaris, FreeBSD and NetBSD, dl_phdr_info is always visible in
> <link.h>, while on Linux one needs to define _GNU_SOURCE.
> AC_USE_SYSTEM_EXTENSION takes care of this, but needs to be called
> early (i.e. not in DRUNTIME_OS_DLPI_TLS_MODID) to avoid an autoconf
> configure.ac:129: warning: AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS
> m4/druntime/os.m4:190: DRUNTIME_OS_DLPI_TLS_MODID is expanded from...
> configure.ac:129: the top level
> Tested on i386-pc-solaris2.11 (Solaris 11.4) and x86_64-pc-linux-gnu.
> Not unexpectedly, there are a couple of regressions compared to the
> Solaris 11.5/x86 results:
> +FAIL: gdc.test/runnable/testaa.d execution test
> +FAIL: gdc.test/runnable/testaa.d -fPIC execution test
> +FAIL: gdc.test/runnable/testaa.d -fPIC -shared-libphobos execution test
> +FAIL: gdc.test/runnable/testaa.d -shared-libphobos execution test
> 32 and 64-bit
> +FAIL: gdc.test/runnable/xtest55.d execution test
> +FAIL: gdc.test/runnable/xtest55.d -shared-libphobos execution test
> 64-bit only
> +FAIL: libphobos.shared/link_linkdep.d -I/vol/gcc/src/hg/trunk/local/libphobos/t
> estsuite/libphobos.shared liblinkdep.so lib.so -shared-libphobos execution test
> +FAIL: libphobos.shared/load_linkdep.d -shared-libphobos -ldl execution test
> +FAIL: libphobos.shared/load_loaddep.d -shared-libphobos -ldl execution test
> +FAIL: libphobos.shared/linkDR.c -shared-libphobos -ldl -pthread execution test
> +FAIL: libphobos.shared/host.c -ldl -pthread execution test
> +FAIL: libphobos.shared/loadDR.c -ldl -pthread -g execution test
> 32 and 64-bit
> +FAIL: libphobos.shared/link.d -I/vol/gcc/src/hg/trunk/local/libphobos/testsuite/libphobos.shared lib.so -shared-libphobos execution test
> 64-bit only
> I haven't looked much closer yet, just posting this to see if anything
> along those lines could be acceptable at all.
Fortunately, Iain just discovered a way better way to work around the
lack of dlpi_tls_modid: dlinfo(RTLD_DI_LINKMAP) returns not only a
pointer to a Link_map * as documented in the man page, but rather a
pointer to a struct Rt_map which also includes a rt_tlsmodid member.
It has been this way since at least Solaris 9 and the Solaris/Illumos
sources ($SRC/cmd/sgs/include/rtld.h) explicitly have a comment around
the start of the structure stateing
Exposed to rtld_db - don't move, don't delete
which pretty much guarantees that this can be relied on.
The only other quirk of note is that before dlpi_tls_modid got added,
tlsmodid started at 0 for the main executable, not 1 as the glibc spec
required and libdruntime assumes. I account for this by adjusting
_tlsMod on dlinfo and undoing the adjustment before passing it to
__tls_get_adddr, the only consumer.
With the revised patch below, I get clean gdc testresults on Solaris
11.3 and 11.4 (and still on 11.5 which uses the dlpi_tls_modid path),
and almost identical libphobos testresults on all three versions.
I hope this is good to go in (the sections_elf_shared.d part via
upstream, the rest directly) now?
Thanks a lot to Iain for discovering this.
Rainer Orth, Center for Biotechnology, Bielefeld University
2019-01-22 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Iain Buclaw <email@example.com>
* m4/druntime/os.m4 (DRUNTIME_OS_DLPI_TLS_MODID): New macro.
* configure.ac: Use it.
* configure: Regenerate.
* Makefile.in, libdruntime/Makefile.in, src/Makefile.in,
* libdruntime/gcc/config.d.in (OS_Have_Dlpi_Tls_Modid): Define.
* libdruntime/rt/sections_elf_shared.d (scanSegments) <PT_TLS>:
[OS_Have_Dlpi_Tls_Modid]: Use dlpi_tls_modid.
[Solaris]: Use dlinfo(RTLD_DI_LINKMAP) to get rt_tlsmodid.
Otherwise clear pdso._tlsMod, pdso._tlsSize.
(getTLSRange) [Solaris && !OS_Have_Dlpi_Tls_Modid]: Readjust mod.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 3984 bytes
Desc: not available
More information about the Gcc-patches