Bug 16290 – Problems with -fPIC, libraries and exceptions
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-07-18T13:22:00Z
Last change time
2017-07-19T15:01:38Z
Assigned to
nobody
Creator
er.krali
Comments
Comment #0 by er.krali — 2016-07-18T13:22:43Z
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.
Comment #1 by dlang-bugzilla — 2017-07-19T15:01:38Z
Fixed in https://github.com/dlang/dmd/pull/6129 - seems to be a duplicate of issue 16031.
*** This issue has been marked as a duplicate of issue 16031 ***