Hi Iain,

> On Tue, 29 Jan 2019 at 11:25, Rainer Orth <r...@cebitec.uni-bielefeld.de> 
> wrote:
>>
>> I've successfully been using a late prototype of an implementation of
>> the dlpi_tls_modid field of struct dl_phdr_info on Solaris 11.5 Beta.
>> This allowed me to get pretty reasonable test results using
>> sections_elf_shared.d on Solaris.
>>
>> This pretty straightforward patch implements this.  Only a few points
>> are worth mentioning:
>>
>> * libdruntime/rt/bss_sections.c refers to __bss_start, which only gld
>>   defines.  Unfortunately, it's marked weak, so the absence with Solaris
>>   ld went unnoticed at first.  Lacking an exact equivalent, I'm using
>>   _edata instead, which is pretty close modulo section alignment.
>>
>> * As detailed in the PR, not dlclose()ing the handle in handleForName is
>>   necessary to avoid an assertion failure.
>>
>> * I'm removing sections_solaris.d since it wouldn't even compile and
>>   seems pretty useless.
>>
>> This patch gave me the following testsuite results on Solaris 11.5/x86
>> (a few more minor testsuite fixes were included, too):
>>
>>                 === gdc tests ===
>>
>>
>> Running target unix
>> FAIL: gdc.test/runnable/nulltype.d   execution test
>> FAIL: gdc.test/runnable/nulltype.d -O2   execution test
>> FAIL: gdc.test/runnable/nulltype.d -O2 -shared-libphobos   execution test
>> FAIL: gdc.test/runnable/nulltype.d -g   execution test
>> FAIL: gdc.test/runnable/nulltype.d -g -O2   execution test
>> FAIL: gdc.test/runnable/nulltype.d -g -O2 -shared-libphobos   execution test
>> FAIL: gdc.test/runnable/nulltype.d -g -shared-libphobos   execution test
>> FAIL: gdc.test/runnable/nulltype.d -shared-libphobos   execution test
>>
>>                 === gdc Summary for unix ===
>>
>> # of expected passes            30785
>> # of unexpected failures        8
>>
>> Running target unix/-m64
>>
>>                 === gdc Summary for unix/-m64 ===
>>
>> # of expected passes            30793
>>
>>                 === gdc Summary ===
>>
>> # of expected passes            61578
>> # of unexpected failures        8
>> /var/gcc/gcc-9.0.1-20190128/11.5-gcc-gas-libphobos/gcc/gdc  version 9.0.1 
>> 20190128 (experimental) [trunk revision 268335] (GCC)
>>
>>                 === libphobos tests ===
>>
>>
>> Running target unix
>> FAIL: libphobos.shared/load.d -shared-libphobos -ldl execution test
>> FAIL: libphobos.shared/load_13414.d -shared-libphobos -ldl execution test
>> FAIL: libphobos.shared/finalize.d -shared-libphobos -ldl execution test
>> FAIL: libphobos.shared/linkD.c lib.so -ldl -pthread execution test
>> FAIL: libphobos.unittests/druntime/shared/core.sync.mutex
>> FAIL: libphobos.unittests/druntime/shared/core.time
>>
>>                 === libphobos Summary for unix ===
>>
>> # of expected passes            119
>> # of unexpected failures        6
>>
>> Running target unix/-m64
>> FAIL: libphobos.shared/load.d -shared-libphobos -ldl execution test
>> FAIL: libphobos.shared/load_13414.d -shared-libphobos -ldl execution test
>> FAIL: libphobos.shared/finalize.d -shared-libphobos -ldl execution test
>> FAIL: libphobos.shared/linkD.c lib.so -ldl -pthread execution test
>> FAIL: libphobos.unittests/druntime/shared/ld.so.1:
>> FAIL: libphobos.unittests/druntime/shared/unittest:
>> FAIL: libphobos.unittests/druntime/shared/fatal:
>> FAIL: libphobos.unittests/druntime/shared/libgdruntime_t.so.0:
>> FAIL: libphobos.unittests/druntime/shared/open
>> FAIL: libphobos.unittests/druntime/shared/failed:
>> FAIL: libphobos.unittests/druntime/shared/No
>> FAIL: libphobos.unittests/druntime/shared/such
>> FAIL: libphobos.unittests/druntime/shared/file
>> FAIL: libphobos.unittests/druntime/shared/or
>> FAIL: libphobos.unittests/druntime/shared/directory
>>
>>                 === libphobos Summary for unix/-m64 ===
>>
>> # of expected passes            78
>> # of unexpected failures        15
>>
>>                 === libphobos Summary ===
>>
>> # of expected passes            197
>> # of unexpected failures        21
>>
>> The 32-bit nulltype.d failures occur on Linux, too (PR d/87824), and the
>> 64-bit libphobos.unittests/druntime/shared failures happen because
>> libgdruntime_t.so.0 is only built for the default multilib.  The
>> libphobos.shared failures clearly bear investigating.
>>
>> For the amd64 results, I needed a separate patch to workaround an ld
>> bug, to be submitted shortly.
>>
>> While I did run a sparc-sun-solaris2.11 bootstrap, too, results are
>> pretty useless due to PR d/88462 (the minfo alignment issue).
>>
>
> Hi,
>
> Sorry for the belated response, this has been delayed by myself
> sorting out moving the sections code out of upstream tree.

no worries at all: I've been busy with other things like the sparc side
of things :-)

> bss_sections.c is now gone, and the patch should be rebased to target
> gcc/sections/elf_shared.d.  I think only core/sys/solaris/link.d is
> left to be upstreamed, otherwise this is OK.

Right: I'm keeping the latter local for now.  Given that Solaris 11.5 is
still in beta, the number of people affected should be small.

Here's the rebased version I've commited after testing the whole series
on i386-pc-solaris2.11 (Solaris 11.[345]) and x86_64-pc-linux-gnu.

Thanks a lot.

        Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2018-11-21  Rainer Orth  <r...@cebitec.uni-bielefeld.de>

        PR d/88150
        * libdruntime/gcc/sections/elf_shared.d [Solaris] (SharedELF): Set
        to true.
        Import core.sys.solaris.dlfcn, core.sys.solaris.link,
        core.sys.solaris.sys.elf, core.sys.solaris.sys.link.
        (dummy_ref): Declare.
        (initSections): Initialize dummy_ref.
        (getDependencies): Set strtab.
        (handleForName): Don't dlclose handle.
        (findDSOInfoForAddr): Set IterateManually.
        (getprogname): Declare.
        (progname): Use it.
        * libdruntime/gcc/sections/package.d [Solaris]: Import
        gcc.sections.elf_shared instead of gcc.sections.solaris.
        * libdruntime/gcc/sections/solaris.d: Remove.
        * libdruntime/Makefile.am (DRUNTIME_DSOURCES): Remove
        gcc/sections/solaris.d.
        * libdruntime/Makefile.in: Regenerate.

# HG changeset patch
# Parent  2077bbd9608636259830a7bc7ed06414514fc252
Use sections_elf_shared.d on Solaris 11.5 (PR d/88150)

Fixes for dlpi_tls_modid support.

diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -141,7 +141,7 @@ DRUNTIME_DSOURCES = core/atomic.d core/a
 	core/sync/rwmutex.d core/sync/semaphore.d core/thread.d core/time.d \
 	core/vararg.d gcc/attribute.d gcc/backtrace.d gcc/builtins.d gcc/deh.d \
 	gcc/sections/android.d gcc/sections/elf_shared.d gcc/sections/osx.d \
-	gcc/sections/package.d gcc/sections/solaris.d gcc/sections/win32.d \
+	gcc/sections/package.d gcc/sections/win32.d \
 	gcc/sections/win64.d gcc/unwind/arm.d gcc/unwind/arm_common.d \
 	gcc/unwind/c6x.d gcc/unwind/generic.d gcc/unwind/package.d \
 	gcc/unwind/pe.d object.d rt/aApply.d rt/aApplyR.d rt/aaA.d rt/adi.d \
diff --git a/libphobos/libdruntime/gcc/sections/elf_shared.d b/libphobos/libdruntime/gcc/sections/elf_shared.d
--- a/libphobos/libdruntime/gcc/sections/elf_shared.d
+++ b/libphobos/libdruntime/gcc/sections/elf_shared.d
@@ -28,6 +28,7 @@ else version (FreeBSD) enum SharedELF = 
 else version (NetBSD) enum SharedELF = true;
 else version (DragonFlyBSD) enum SharedELF = true;
 else version (CRuntime_UClibc) enum SharedELF = true;
+else version (Solaris) enum SharedELF = true;
 else enum SharedELF = false;
 static if (SharedELF):
 
@@ -61,6 +62,13 @@ else version (DragonFlyBSD)
     import core.sys.dragonflybsd.sys.elf;
     import core.sys.dragonflybsd.sys.link_elf;
 }
+else version (Solaris)
+{
+    import core.sys.solaris.dlfcn;
+    import core.sys.solaris.link;
+    import core.sys.solaris.sys.elf;
+    import core.sys.solaris.sys.link;
+}
 else
 {
     static assert(0, "unimplemented");
@@ -163,6 +171,7 @@ private:
 version (FreeBSD) private __gshared void* dummy_ref;
 version (DragonFlyBSD) private __gshared void* dummy_ref;
 version (NetBSD) private __gshared void* dummy_ref;
+version (Solaris) private __gshared void* dummy_ref;
 
 /****
  * Gets called on program startup just before GC is initialized.
@@ -174,6 +183,7 @@ void initSections() nothrow @nogc
     version (FreeBSD) dummy_ref = &_d_dso_registry;
     version (DragonFlyBSD) dummy_ref = &_d_dso_registry;
     version (NetBSD) dummy_ref = &_d_dso_registry;
+    version (Solaris) dummy_ref = &_d_dso_registry;
 }
 
 
@@ -719,6 +729,8 @@ version (Shared)
                     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)
+                    strtab = cast(const(char)*)(info.dlpi_addr + dyn.d_un.d_ptr); // relocate
                 else
                     static assert(0, "unimplemented");
                 break;
@@ -745,7 +757,8 @@ version (Shared)
     void* handleForName(const char* name)
     {
         auto handle = .dlopen(name, RTLD_NOLOAD | RTLD_LAZY);
-        if (handle !is null) .dlclose(handle); // drop reference count
+        version (Solaris) { }
+        else if (handle !is null) .dlclose(handle); // drop reference count
         return handle;
     }
 }
@@ -799,9 +812,10 @@ void scanSegments(in ref dl_phdr_info in
  */
 bool findDSOInfoForAddr(in void* addr, dl_phdr_info* result=null) nothrow @nogc
 {
-    version (linux)       enum IterateManually = true;
-    else version (NetBSD) enum IterateManually = true;
-    else                  enum IterateManually = false;
+    version (linux)        enum IterateManually = true;
+    else version (NetBSD)  enum IterateManually = true;
+    else version (Solaris) enum IterateManually = true;
+    else                   enum IterateManually = false;
 
     static if (IterateManually)
     {
@@ -864,6 +878,7 @@ version (linux) import core.sys.linux.er
 version (FreeBSD) extern(C) const(char)* getprogname() nothrow @nogc;
 version (DragonFlyBSD) extern(C) const(char)* getprogname() nothrow @nogc;
 version (NetBSD) extern(C) const(char)* getprogname() nothrow @nogc;
+version (Solaris) extern(C) const(char)* getprogname() nothrow @nogc;
 
 @property const(char)* progname() nothrow @nogc
 {
@@ -871,6 +886,7 @@ version (NetBSD) extern(C) const(char)* 
     version (FreeBSD) return getprogname();
     version (DragonFlyBSD) return getprogname();
     version (NetBSD) return getprogname();
+    version (Solaris) return getprogname();
 }
 
 const(char)[] dsoName(const char* dlpi_name) nothrow @nogc
diff --git a/libphobos/libdruntime/gcc/sections/package.d b/libphobos/libdruntime/gcc/sections/package.d
--- a/libphobos/libdruntime/gcc/sections/package.d
+++ b/libphobos/libdruntime/gcc/sections/package.d
@@ -35,7 +35,7 @@ else version (NetBSD)
 else version (DragonFlyBSD)
     public import gcc.sections.elf_shared;
 else version (Solaris)
-    public import gcc.sections.solaris;
+    public import gcc.sections.elf_shared;
 else version (OSX)
     public import gcc.sections.osx;
 else version (CRuntime_DigitalMars)
diff --git a/libphobos/libdruntime/gcc/sections/solaris.d b/libphobos/libdruntime/gcc/sections/solaris.d
deleted file mode 100644
--- a/libphobos/libdruntime/gcc/sections/solaris.d
+++ /dev/null
@@ -1,126 +0,0 @@
-// Solaris-specific support for sections.
-// Copyright (C) 2019 Free Software Foundation, Inc.
-
-// GCC is free software; you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free
-// Software Foundation; either version 3, or (at your option) any later
-// version.
-
-// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-// WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-// for more details.
-
-// Under Section 7 of GPL version 3, you are granted additional
-// permissions described in the GCC Runtime Library Exception, version
-// 3.1, as published by the Free Software Foundation.
-
-// You should have received a copy of the GNU General Public License and
-// 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/>.
-
-module gcc.sections.solaris;
-
-version (Solaris):
-
-// debug = PRINTF;
-debug(PRINTF) import core.stdc.stdio;
-import core.stdc.stdlib : malloc, free;
-import rt.deh, rt.minfo;
-
-struct SectionGroup
-{
-    static int opApply(scope int delegate(ref SectionGroup) dg)
-    {
-        return dg(_sections);
-    }
-
-    static int opApplyReverse(scope int delegate(ref SectionGroup) dg)
-    {
-        return dg(_sections);
-    }
-
-    @property immutable(ModuleInfo*)[] modules() const nothrow @nogc
-    {
-        return _moduleGroup.modules;
-    }
-
-    @property ref inout(ModuleGroup) moduleGroup() inout nothrow @nogc
-    {
-        return _moduleGroup;
-    }
-
-    @property immutable(FuncTable)[] ehTables() const nothrow @nogc
-    {
-        auto pbeg = cast(immutable(FuncTable)*)&__start_deh;
-        auto pend = cast(immutable(FuncTable)*)&__stop_deh;
-        return pbeg[0 .. pend - pbeg];
-    }
-
-    @property inout(void[])[] gcRanges() inout nothrow @nogc
-    {
-        return _gcRanges[];
-    }
-
-private:
-    ModuleGroup _moduleGroup;
-    void[][1] _gcRanges;
-}
-
-void initSections() nothrow @nogc
-{
-    auto mbeg = cast(immutable ModuleInfo**)&__start_minfo;
-    auto mend = cast(immutable ModuleInfo**)&__stop_minfo;
-    _sections.moduleGroup = ModuleGroup(mbeg[0 .. mend - mbeg]);
-
-    auto pbeg = cast(void*)&__dso_handle;
-    auto pend = cast(void*)&_end;
-    _sections._gcRanges[0] = pbeg[0 .. pend - pbeg];
-}
-
-void finiSections() nothrow @nogc
-{
-}
-
-void[] initTLSRanges() nothrow @nogc
-{
-    auto pbeg = cast(void*)&_tlsstart;
-    auto pend = cast(void*)&_tlsend;
-    return pbeg[0 .. pend - pbeg];
-}
-
-void finiTLSRanges(void[] rng) nothrow @nogc
-{
-}
-
-void scanTLSRanges(void[] rng, scope void delegate(void* pbeg, void* pend) nothrow dg) nothrow
-{
-    dg(rng.ptr, rng.ptr + rng.length);
-}
-
-private:
-
-__gshared SectionGroup _sections;
-
-extern(C)
-{
-    /* Symbols created by the compiler/linker and inserted into the
-     * object file that 'bracket' sections.
-     */
-    extern __gshared
-    {
-        void* __start_deh;
-        void* __stop_deh;
-        void* __start_minfo;
-        void* __stop_minfo;
-        int __dso_handle;
-        int _end;
-    }
-
-    extern
-    {
-        void* _tlsstart;
-        void* _tlsend;
-    }
-}

Reply via email to