[Issue 16290] New: Problems with -fPIC, libraries and exceptions

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jul 18 06:22:43 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16290

          Issue ID: 16290
           Summary: Problems with -fPIC, libraries and exceptions
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: er.krali at gmail.com

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", and it works properly both with gdc and ldmd2.

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.

--


More information about the Digitalmars-d-bugs mailing list