Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert(handle !in _handleToDSO) in setDSOForHandle fails on OSX #64

Closed
timotheecour opened this issue Jan 6, 2018 · 2 comments
Closed

Comments

@timotheecour
Copy link
Collaborator

timotheecour commented Jan 6, 2018

@Syniurge @klickverbot @ MartinNowak (since this seem to touch on druntime shared library initialization issues)

to reproduce: same test case as in #63

$calypso_D/lib/libcalypso-ldc-shared.dylib is being registered twice; depending on program, it could be another file that is registered twice;
workaround: just return from _d_dso_registry (in Calypso/runtime/druntime/src/rt/sections_elf_shared.d) when input corresponds to a so already registered.

Here is where it would fail:

#in void setDSOForHandle(DSO* pdso, void* handle):
assert(handle !in _handleToDSO); // fails

not sure if the fix is good enough though, doesn't seem so based on other bug i have after that

@timotheecour
Copy link
Collaborator Author

TODO:do a PR

Calypso/runtime/druntime/src/rt/sections_elf_shared.d:

 extern(C) void _d_dso_registry(void* arg)
 {
+    static int counter=0;
+    counter++;
+    {
+        auto data2 = cast(CompilerDSOData*)arg;
+        Dl_info info = void;
+        if(dladdr(data2._slot, &info) == 0){
+            assert(0);
+        }
+        assert(dladdr(data2._slot, &info) != 0);
+        printf("c:%d arg:%p name:%s\n", counter, arg, info.dli_fname);
+        auto name2=info.dli_fname;
+
+        // IMPROVE
+        alias string2=char[256];
+        __gshared string2[10] names;
+
+        __gshared size_t names_length=0;
+        __gshared is_first=true;
+        if(is_first){
+            foreach(ai;names){
+                ai="";
+            }
+            is_first=false;
+        }
+        import core.stdc.string:strlen;
+        import core.stdc.string:strcmp;
+        foreach(namei; names){
+            const(char*)namei2=namei.ptr;
+            auto tmp=strcmp(namei2, name2);
+            if(tmp==0){
+                printf("WORKAROUND:RETURN\n");
+                return;
+            }
+        }
+        assert(names_length<names.length);
+        names[names_length][0..strlen(name2)][]=name2[0..strlen(name2)];
+        names[names_length][strlen(name2)]=0;
+        names_length++;
+    }
+
     auto data = cast(CompilerDSOData*)arg;

@Syniurge
Copy link
Owner

This assert was the cause of #60.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants