Memory Corruption Issue??
Bottled Gin via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jan 20 01:12:57 PST 2016
Greetings
I am struggling with strange memory corruption issues with
dmd-2.069.2 release.
The issue shows up only when I load a shared library created from
D code from C and call some D functions from the C side. But
since the program control is completely with the D code, and data
structures in D get corrupted, I believe C has no role to play in
the corruption. It is just that the memory layout of the
executable, when the compiled D code is loaded from C, is helping
in replicating the issue.
I have spent almost a week in reducing this issue to less than
100 lines of code. Now I need the developers' love and help to
get this issue fixed. There is some bleak chance that I am doing
something wrong while loading the D library from C code. But
otherwise it looks like a DMD memory corruption issue.
Since two C, and one D files are involved in recreating the
issue, I have put all the files on a github repository along with
a makefile. I have been able to recreate the issue on two Ubuntu
14.04 64-bit machines.
Generally the issue seems to be with static (thread local)
variables that get allocated on heap. If I create many such
variables, I get data corruption in some of these variables and
sometimes I get segmentation fault. In this testcase that I have
reduced, contents of a dynamic array are getting corrupted. Since
all the data is being accessed from only one thread, there is no
chance of a multicore race condition.
To reproduce the issue, kindly clone my git repo
(https://github.com/puneet/memerr.git). Change the path of the
DMD installation (I have tested only with dmd-2.069.2) in the
makefile and run make.
$ git clone https://github.com/puneet/memerr.git
# change DMD install path in memerr/makefile
$ make
I get an output like:
$ make
/home/puneet/local/dmd-2.069.2/linux/bin64/rdmd foo.d
Start frop from D
Successfully completed loop....
./main
Start frop from C
0 -> @�+----------------
The last line is the content of an array which is actually filled
with only dashes in the code.
Kindly help. I want to make sure that I am not making a mistake
before I file a bug on dlang bugzilla.
Regards
- Puneet
More information about the Digitalmars-d
mailing list