www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10711] New: shared phobos library should not depend on _Dmain

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10711

           Summary: shared phobos library should not depend on _Dmain
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody puremagic.com
        ReportedBy: code dawg.eu



When building shared D libraries the function _Dmain remains unresolved.
This is because a C main function is part of druntime.
To fix this we should generate the C main function in the glue layer of the
compiler and only do that if a D main function is present.

This needs some refactoring in druntime first so that the function becomes
reasonably simple, e.g. something along this line.

extern(C) int main(int argc, char*[] argv)
{
    auto rc = rt_init(argv[0 .. argc]);
    if (rc == 0)
    {
        runMain();
        rc = rt_term();
    }
    return rc;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 24 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10711


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com



00:23:21 PDT ---
To reproduce:

main.c:

    #include <stdio.h>
    #include <stdlib.h>
    #include <dlfcn.h>

    int main()
    {
        printf("+main()\n");

        void *lh = dlopen("/home/walter/tmp/libdll.so", RTLD_LAZY);
        if (!lh)
        {
            fprintf(stderr, "dlopen error: %s\n", dlerror());
            exit(1);
        }
        printf("libdll.so is loaded\n");

        int (*fn)() = dlsym(lh, "dll");
        char *error = dlerror();
        if (error)
        {
            fprintf(stderr, "dlsym error: %s\n", error);
            exit(1);
        }
        printf("dll() function is found\n");

        (*fn)();

        printf("unloading libdll.so\n");
        dlclose(lh);

        printf("-main()\n");
        return 0;
    }

dll.d:

    import core.stdc.stdio;

    extern (C) int dll()
    {
        printf("dll()\n");
        return 0;
    }

    static this()
    {
        printf("libdll.so construction\n");
    }

    static ~this()
    {
        printf("libdll.so destruction\n");
    }

Build:

    dmd -c dll.d -fPIC
    dmd -oflibdll.so dll.o -shared -defaultlib=libphobos2.so
-L-rpath=/home/walter/cbx/mars/phobos/generated/linux/release/64

    gcc -c main.c
    gcc -rdynamic main.o -o main -ldl

    ./main

Results:

    +main()
    dlopen error:
/home/walter/cbx/mars/phobos/generated/linux/release/64/libphobos2.so.0.64:
undefined symbol: _Dmain

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10711




01:10:30 PDT ---
https://github.com/D-Programming-Language/druntime/pull/563

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 10 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10711




Commits pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/5373575c109cf997f4c9cfa09af7802b4ce8b7c4
fix Issue 10711 - shared phobos library should not depend on _Dmain

https://github.com/D-Programming-Language/druntime/commit/f6692feb43904bf231ebde76317190084796b63a


fix Issue 10711 - shared phobos library should not depend on _Dmain

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 11 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10711




23:07:10 PDT ---
2nd try at fixing this:

https://github.com/D-Programming-Language/dmd/pull/2476

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 14 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10711




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/0082669292b0a4e535420ea9aabcd57fd7844923
fix Issue 10711 - shared phobos library should not depend on _Dmain

https://github.com/D-Programming-Language/dmd/commit/ab3a4030977d369b33f4d42b6964a134c7a800b5


fix Issue 10711 - shared phobos library should not depend on _Dmain

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 15 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10711


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 15 2013