www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Problems with -fPIC, libraries and exceptions (in linux?)

reply Arafel <er.krali gmail.com> writes:
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.
Jul 14 2016
parent reply Arafel <er.krali gmail.com> writes:
Just as a follow-up, I think it's looking more and more like a 
compiler bug. It works properly both with gdc and ldmd2. Should I 
make a bug report about that?
Jul 15 2016
parent reply Seb <seb wilzba.ch> writes:
On Friday, 15 July 2016 at 08:40:02 UTC, Arafel wrote:
 Just as a follow-up, I think it's looking more and more like a 
 compiler bug. It works properly both with gdc and ldmd2. Should 
 I make a bug report about that?
Yes please.
Jul 16 2016
parent reply Basile B. <b2.temp everywhere.net> writes:
On Saturday, 16 July 2016 at 20:13:00 UTC, Seb wrote:
 On Friday, 15 July 2016 at 08:40:02 UTC, Arafel wrote:
 Just as a follow-up, I think it's looking more and more like a 
 compiler bug. It works properly both with gdc and ldmd2. 
 Should I make a bug report about that?
Yes please.
Hi, you wanted to talk ? I'm on D IRC channel today, whole day, european time.
Jul 16 2016
parent Basile B. <b2.temp everywhere.net> writes:
On Sunday, 17 July 2016 at 05:07:00 UTC, Basile B. wrote:
 On Saturday, 16 July 2016 at 20:13:00 UTC, Seb wrote:
 On Friday, 15 July 2016 at 08:40:02 UTC, Arafel wrote:
 Just as a follow-up, I think it's looking more and more like 
 a compiler bug. It works properly both with gdc and ldmd2. 
 Should I make a bug report about that?
Yes please.
Hi, you wanted to talk ? I'm on D IRC channel today, whole day, european time.
BBaz.
Jul 16 2016