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

runtime loaded shared library on osx: partially worked in 2.062, fails since 2.063 #18774

Open
dlangBugzillaToGithub opened this issue Feb 18, 2014 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

Timothee Cour (@timotheecour) reported this on 2014-02-18T00:44:37Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=12190

CC List

Description

Now that issue 11478 is partially fixed (linktime shared libraries), on to runtime loaded shared libraries:

----
module foo;
import std.stdio;

extern(C) void foo1(){
  printf("ok1
");
  import core.runtime;
  bool ret=Runtime.initialize(); //is it necessary?
  printf("ret=%d
",ret);
  printf("ok2
");
  writeln("ok3");
  int[]a;
  a.length=2; //ok
  writeln(a.length); //dmd2.062 only crashes at this point
}
----
module main2;
import std.stdio, core.sys.posix.dlfcn;
void main(){
  string file="libfoo.dylib";
  auto handle = dlopen(file.ptr, RTLD_LAZY | RTLD_GLOBAL);
  auto funptr = cast(void function()) dlsym(handle, "foo1");
  funptr();
}
----
dmd -oflibfoo.dylib -shared foo.d;
dmd main.d
./main

--output:
2.062:
crashes at writeln(a.length)  (lldb shows it crashes inside LockingTextWriter), which can still be useful for writing plugins.

git head: crashes upon loading


Also, note that dlopen() of a D shared library works when called from a C++ file, and that a C++ file can call multiple D shared libraries simultaneously when using RTLD_LAZY option. 

Before waiting for a full solution with an integrated druntime, is there at least a way to have a separate runtime in each shared library, so that dlopen() can be called from a D file?
@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2014-06-20T20:52:41Z

It appears from the text here that this is not a regression since it never did work. Reclassified.

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

1 participant