Hi!

I've stumbled across the following problem: when I raise an exception from a (statically linked) library that was compiled with -fPIC, I get a segmentation fault. Example:

-- libfoo/dub.json
{
        "name" : "foo",
        "description" : "Exception raising lib",
        "dflags" : [ "-fPIC" ]
}
--
-- libfoo/source/foo.d
module foo;

public void throwIt() {
        throw new Exception("This is an exception!");
}
--
-- bar/dub.json
{
        "name" : "bar",
        "description" : "uses libfoo",
        "dependencies" : { "foo" : "*" },
}
-- bar/source/app.d
import foo;

void main() {
        throwIt();
}
--

If I run "bar" (after libfoo is added through "dub add-local", of course), I get a segmentation fault (the exception cannot even be caught). If I remove "-fPIC" I get the usual stack trace and I can catch the exception as well.

Is this a compiler bug or is there a reason for that? I'm using "DMD64 D Compiler v2.071.1", I haven't tried yet with ldc or gdc.

P.S.: This is simplified test case, the reason why I'm trying -fPIC is because I want to link a dependency statically in a .so file which in turn will be dynamically loaded as a plugin.

Reply via email to