www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16290] New: Problems with -fPIC, libraries and exceptions


          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 puremagic.com
          Reporter: er.krali gmail.com


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() {

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.

Jul 18 2016