www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8152] New: Linking C library causes Seg-fault

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8152

           Summary: Linking C library causes Seg-fault
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: stephan.schiffels mac.com


--- Comment #0 from Stephan <stephan.schiffels mac.com> 2012-05-26 14:29:20 PDT
---
The following program tries to trivially run a function from the GSL. It
compiles, but generates a segmentation fault when run.


gsltest.d
--------------------------
import std.stdio;

extern (C) double gsl_sf_hyperg_2F1(double a, double b, double c,
double x);

void main() {
  double f = 0.0025;
  auto ret = f * gsl_sf_hyperg_2F1(1.0, 10.0, 11.0, 1.0 - f /
0.025);
  writeln(ret);
}
---------------------------

The program should return 0.015681, which is the
numerically correct result. Note that the bug can not be in the GSL itself, as
it works correctly when used with C or C++.

To compile and run the code, I used the following command line:

rdmd -L-L/opt/local/lib -L-lgsl -L-lgslcblas gsltest.d
(assuming that gel libraries are in /opt/local/lib)

This seems to be a bug related to how C library functions are called from D.

Stephan

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 26 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8152



--- Comment #1 from Stephan <stephan.schiffels mac.com> 2012-05-26 16:56:44 PDT
---
I ran the executable through the GNU debugger. Here is the output:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x00007fff912a86cd in misaligned_stack_error_entering_dyld_stub_binder ()


And most peculiar by the way: If I drop the variable f, but simply put 0.025
directly in front of the function, the program does NOT crash...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 26 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8152


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au


--- Comment #2 from Don <clugdbug yahoo.com.au> 2012-05-31 05:15:17 PDT ---
Related to bug 5570?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 31 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8152



--- Comment #3 from Stephan <stephan.schiffels mac.com> 2012-07-03 15:35:36 PDT
---
(In reply to comment #2)
 Related to bug 5570?

That may well be. I am unable to check how things compare between 32 and 64 bits, though. Stephan -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 03 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8152


Stephan <stephan.schiffels mac.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #4 from Stephan <stephan.schiffels mac.com> 2013-01-22 14:10:40 PST
---
This issue is resolved. Tested on dmd 2.061.
Thanks for fixing!

Stephan

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2013