Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core dump / Segfault #11

Closed
arpie42 opened this issue Oct 22, 2013 · 18 comments
Closed

Core dump / Segfault #11

arpie42 opened this issue Oct 22, 2013 · 18 comments
Labels

Comments

@arpie42
Copy link

arpie42 commented Oct 22, 2013

It's probably my fault - I'm just starting out with D so please be patient. The following is my attempt to compile and run the two examples shipped with DMagick. It's DMagick version 6.8.7. The attempt to run draw.d using rdmd instead of dmd just hung after the strange error message below... hence the ^C. I'm on Arch Linux... I think any other info you might want is below...

$ uname -a
Linux orion 3.11.6-1-ARCH #1 SMP PREEMPT Sat Oct 19 00:29:46 CEST 2013 i686 GNU/Linux

$ pkg-config --cflags --libs DMagick
-version=MagickCore_HDRI -I/usr/local/include/d/ -L-L/usr/local/lib/ -L-lDMagick -L-lMagickCore-6.Q16HDRI 

$ identify -version
Version: ImageMagick 6.8.7-1 2013-10-20 Q16 http://www.imagemagick.org
[snip]

$ dmd `pkg-config --cflags --libs DMagick` draw.d
$ ./draw
draw: malloc.c:2365: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted (core dumped)

$ rdmd `pkg-config --cflags --libs DMagick` draw.d
*** Error in `/tmp/.rdmd-1001/rdmd-draw.d-3DBCB9BFB2127CA5FC9FE08452FBD65A/draw': corrupted double-linked list: 0x087ff2a0 ***
^C

$ dmd sigmoidalContrast.d `pkg-config --cflags --libs DMagick`
$ ./sigmoidalContrast*
Segmentation fault (core dumped)

Any ideas?

@MikeWey
Copy link
Owner

MikeWey commented Oct 23, 2013

$ uname -a
Linux orion 3.11.6-1-ARCH #1 SMP PREEMPT Sat Oct 19 00:29:46 CEST 2013 i686 GNU/Linux

$ pkg-config --cflags --libs DMagick
-version=MagickCore_HDRI -I/usr/local/include/d/ -L-L/usr/local/lib/ -L-lDMagick -L-lMagickCore-6.Q16HDRI 

$ identify -version
Version: ImageMagick 6.8.7-1 2013-10-20 Q16 http://www.imagemagick.org
[snip]

Looks good.

$ dmd `pkg-config --cflags --libs DMagick` draw.d
$ ./draw
draw: malloc.c:2365: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted (core dumped)

Don't know whats going on here.

$ rdmd `pkg-config --cflags --libs DMagick` draw.d
*** Error in `/tmp/.rdmd-1001/rdmd-draw.d-3DBCB9BFB2127CA5FC9FE08452FBD65A/draw': corrupted double-linked list: 0x087ff2a0 ***
^C

Ditto.

$ dmd sigmoidalContrast.d `pkg-config --cflags --libs DMagick`
$ ./sigmoidalContrast*
Segmentation fault (core dumped)

Is the * after the executable name a typo, it will cause problems, i get an exception though.

Any ideas?

Compiler version ?
Are you using the latest git version of DMagick (66c7bc5) ?

No ideas yet, but the demos do have some weird behavior for me.

@arpie42
Copy link
Author

arpie42 commented Oct 23, 2013

On 23/10/13 19:27, Mike Wey wrote:

|$ uname -a
Linux orion 3.11.6-1-ARCH #1 SMP PREEMPT Sat Oct 19 00:29:46 CEST 2013 i686 GNU/Linux

$ pkg-config --cflags --libs DMagick
-version=MagickCore_HDRI -I/usr/local/include/d/ -L-L/usr/local/lib/ -L-lDMagick -L-lMagickCore-6.Q16HDRI

$ identify -version
Version: ImageMagick 6.8.7-1 2013-10-20 Q16 http://www.imagemagick.org
[snip]
|

Looks good.

|$ dmd `pkg-config --cflags --libs DMagick` draw.d
$ ./draw
draw: malloc.c:2365: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted (core dumped)
|

Don't know whats going on here.

That is one mother of an assert there... I presume it is part of the IM
libs, and not actually in your bindings?

|$ rdmd `pkg-config --cflags --libs DMagick` draw.d
*** Error in `/tmp/.rdmd-1001/rdmd-draw.d-3DBCB9BFB2127CA5FC9FE08452FBD65A/draw': corrupted double-linked list: 0x087ff2a0 ***
^C
|

Ditto.

|$ dmd sigmoidalContrast.d `pkg-config --cflags --libs DMagick`
$ ./sigmoidalContrast*
Segmentation fault (core dumped)
|

Is the * after the executable name a typo, it will cause problems, i
get an exception though.

Yeah, sorry the * is a typo. Without it, the output is:
Usage: ./sigmoidalContrast image sigmoidal-image

If I supply a jpeg as a parameter, I get the segfault as above.

Any ideas?

Compiler version ?

DMD32 D Compiler v2.063.2

Are you using the latest git version of DMagick (66c7bc5
66c7bc5)
?

Yes - checked it out yesterday.

No ideas yet, but the demos do have some weird behavior for me.

Could you supply an example of some code that compiles successfully that
I could try? I want to be sure the libs and headers are actually
correctly installed before actually trying to write any real code...

@MikeWey
Copy link
Owner

MikeWey commented Oct 23, 2013

Yeah, sorry the * is a typo. Without it, the output is:
Usage: ./sigmoidalContrast image sigmoidal-image

If I supply a jpeg as a parameter, I get the segfault as above.

What is the command you are using?

Could you supply an example of some code that compiles successfully that
I could try? I want to be sure the libs and headers are actually
correctly installed before actually trying to write any real code...

The sigmoidalContrast example works correctly for me.

I was having some problems but it turns out that because i wasn't using pkgconfig the HDRI version wasn't defined.

@arpie42
Copy link
Author

arpie42 commented Oct 23, 2013

Thanks for taking the time to help me with this - it is very much appreciated.

I'm using

./sigmoidalContrast test.jpg

But lets leave that aside for now... there is something screwed up here and I'm getting more and more convinced that it's my installation using the wrong library or something. This is what I've found so far:

test.d contains :

import dmagick.Image;
void main()
{
  Image image = new Image("test1.jpg");
}

I compile and run :

$ dmd -gc `pkg-config --cflags --libs DMagick` test.d
$ ./test
Segmentation fault (core dumped)

I have managed to narrow down the issue to line 67 of Options.d :

GetDrawInfo(imageInfo, drawInfo);

but I cannot see anything wrong with it. In such a short bit of code, there isn't a lot that can go wrong!

If it is of any help, here is the last few lines of output from gdb :

0xb7b61c29 in malloc () from /usr/lib/libc.so.6
(gdb) step
Single stepping until exit from function malloc,
which has no line number information.
0x08101f89 in gc.gcx.GC.addRange() ()
(gdb) step
Single stepping until exit from function _D2gc3gcx2GC8addRangeMFPvkZv,
which has no line number information.

Program received signal SIGSEGV, Segmentation fault.
0xb7b5e9a0 in malloc_consolidate () from /usr/lib/libc.so.6

This is my first time ever using gdb so it doesn't make much sense to me... but the error seems to not be related to DMagick? Something gc-related?

I have tried writing the equivalent code using Magic++, which seems to have no problem at all despite linking to the same libaries. I am at a loss... and I'm not able to get very excited about the prospect of compiling the IM libaries with debuging symbols.

Finally, I thought I might try a different compiler, but I get this:

$ gdc -gc `pkg-config --cflags --libs DMagick` test.d
gdc: error: unrecognized command line option '-version=MagickCore_HDRI'
$ ldc2 -gc `pkg-config --cflags --libs DMagick` test.d
ldc2: for the -version option: does not allow a value! 'MagickCore_HDRI' specified.

What exactly does that -version flag do? Have you had any success using these alternative compilers?

Any other ideas?

@arpie42
Copy link
Author

arpie42 commented Oct 23, 2013

Okay, so if I compile with ldc2 using all the flags from pkg-config, except the -version flag, it compiles fine, and behaves exactly the same as with dmd. In other words, it segfaults with no other useful output. So perhaps it's not a compiler issue...

ldc2  -I/usr/local/include/d/ -L-L/usr/local/lib/ -L-lDMagick -L-lMagickCore-6.Q16HDRI test.d
./test
Segmentation fault (core dumped)

But what is the significance of the -version flag?

@MikeWey
Copy link
Owner

MikeWey commented Oct 24, 2013

The version defines the amount of bits used for the color information. DMagick an MagickCore need to be in sync in that regard.

With HDRI support floats are used for the Quantums , and without it usually ushorts but bytes, ints or doubles are also possible.

Could you also post the backtrace from gdb. (using the bt command after the segfault)

I'm using

./sigmoidalContrast test.jpg

You should provide both an in and output filename, but the first thing the code checks is if you provided both on line 24.

@arpie42
Copy link
Author

arpie42 commented Oct 24, 2013

The version defines the amount of bits used for the color information.
DMagick an MagickCore need to be in sync in that regard.

With HDRI support floats are used for the Quantums , and without it
usually ushorts but bytes, ints or doubles are also possible.

I thought it must be something like that, but couldn't find any
reference to it in DMagick... but now I've looked a little closer and
learnt a little more about the wonders of D. However, it is odd that
ldc and gdc both reject the -version switch on the command line...?
Just checked ldc2 and it wants a different switch (-d-version). Can't
find an equivalent in gdc though. Can this be 'fixed' in the
pkg-config? Anyway, getting back to something more relevant...

Could you also post the backtrace from gdb. (using the bt command
after the segfault)

(gdb) run
Starting program: /home/arpie/Projects/Umbal/./test
warning: Could not load shared library symbols for linux-gate.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0xb7b5d9a0 in malloc_consolidate () from /usr/lib/libc.so.6
(gdb) bt
#0  0xb7b5d9a0 in malloc_consolidate () from /usr/lib/libc.so.6
#1  0xb7b5eb49 in _int_malloc () from /usr/lib/libc.so.6
#2  0xb7b60c18 in malloc () from /usr/lib/libc.so.6
#3  0xb7e18406 in AcquireMagickMemory () from
/usr/lib/libMagickCore-6.Q16HDRI.so.1
#4  0xb7e027bd in AcquireImageInfo () from
/usr/lib/libMagickCore-6.Q16HDRI.so.1
#5  0xb7e04a6a in CloneImageInfo () from
/usr/lib/libMagickCore-6.Q16HDRI.so.1
#6  0xb7db3a64 in GetDrawInfo () from
/usr/lib/libMagickCore-6.Q16HDRI.so.1
#7  0x080b89d2 in dmagick.Options.Options.__ctor() ()
#8  0x0809c846 in dmagick.Image.Image.__ctor() ()
#9  0x08094439 in _Dmain () at rpdraw.d:5
#10 0x080e0be0 in rt.dmain2._d_run_main() ()
#11 0x080e0880 in rt.dmain2._d_run_main() ()
#12 0x080e0c27 in rt.dmain2._d_run_main() ()
#13 0x080e0880 in rt.dmain2._d_run_main() ()
#14 0x080e0851 in _d_run_main ()
#15 0x080e0724 in main ()
(gdb) quit

That is certainly a more useful output, yet I'm still none the wiser...
I'm hoping it gives you a clue! I presume that warning about
linux-gate.so is irrelevant.

I'm using

./sigmoidalContrast test.jpg

You should provide both an in and output filename, but the first thing
the code checks is if you provided both on line 24.

You're quite right. I tried giving it an output filename and it
segfaulted... same problem as above.

Thanks again for the pointers. I'm really quite keen to get this to work...

@arpie42
Copy link
Author

arpie42 commented Oct 24, 2013

sorry that last post is a bit of a mess - i can't persuade the code block to behave.

@arpie42
Copy link
Author

arpie42 commented Oct 24, 2013

Okay, I have a successful compile and run of sigmoidalContrast... but on a different machine. It seems that DMagick works fine on a 64-bit architecture, but segfaults on 32-bit. Hopefully that will help pinpoint the problem? I have tried now on three machines - two 32-bit machines which both segfault, one 64-bit machine that has no problem. Those segfaults are with the simple program from above : test.d

I would like to get this working on my 32-bit machine if possible...

@MikeWey
Copy link
Owner

MikeWey commented Oct 24, 2013

I'll look into it over the weekend.

@MikeWey
Copy link
Owner

MikeWey commented Oct 24, 2013

Just checked ldc2 and it wants a different switch (-d-version). Can't
find an equivalent in gdc though. Can this be 'fixed' in the
pkg-config?

Fixed in commit 9032d3b the pkg-config files should now contain the proper flags for gdc and ldc if one of them is used to compile the lib.

@arpie42
Copy link
Author

arpie42 commented Oct 25, 2013

Got it!

Don't worry though, I've left you with something to do at the weekend! :)

I've been comparing struct and type sizes between DMagick and Magick++, as I suspected it was a type issue.

Basically, for some reason, on my 32-bit system :

MAGICKCORE_SIZEOF_FLOAT_T == MAGICKCORE_SIZEOF_LONG_DOUBLE == 12

and therefore (using Magick++):

sizeof(MagickRealType) == 12

but in magickType.d, line 107 does this :

  alias float MagickRealType;

so

MagickRealType.sizeof == 4

If I change that line to :

  alias real  MagickRealType;

then I can successfully compile and run draw.d from the examples folder.

Without some sort of inside knowledge about the various version checks going on in magickType.d, I don't think I can go any further. Also, I cannot work out where or how MAGICKCORE_SIZEOF_FLOAT_T gets set. What I have done is effectively a hack - I have no idea how to do it correctly. So over to you... let me know if I can be of any help.

Of course, all of the above is irrelevant on my 64-bit system - both DMagic and Magick++ alias/typedef MagicRealType to be a float (4 bytes).

Thanks again for your help.

@MikeWey
Copy link
Owner

MikeWey commented Oct 25, 2013

Got it!

Don't worry though, I've left you with something to do at the weekend! :)

You got me worried there for a minute ;)

@MikeWey
Copy link
Owner

MikeWey commented Oct 25, 2013

Can you post the output of the following code:

#include <stdio.h>
#include <math.h>

int main(int argc,char **argv)
{
    printf("%i \n", sizeof(float_t));
    printf("%i \n", sizeof(float));
    printf("%i \n", sizeof(double_t));
    printf("%i \n", sizeof(double));
}

@arpie42
Copy link
Author

arpie42 commented Oct 25, 2013

On 25/10/13 22:42, Mike Wey wrote:

Can you post the output of the following code:

#include <stdio.h>
#include <math.h>

int main(int argc,char **argv)
{
printf("%i\n", sizeof(float_t));
printf("%i\n", sizeof(float));
printf("%i\n", sizeof(double_t));
printf("%i\n", sizeof(double));
}
$ c++ -o cpptest cpptest.cpp
$ ./cpptest
12
4
12
8

@arpie42
Copy link
Author

arpie42 commented Oct 25, 2013

Just realised that perhaps you intended that code to be C, not C++... but I can confirm that the output is the same if I compile it as C.

@MikeWey
Copy link
Owner

MikeWey commented Oct 26, 2013

With ImageMagick 6.8.1 the type of MagickRealType changed from float to float_t (and double to double_t for 32bits Quantums).

I still need to find out if a can always alias MagickRealType to real or if float_t can be a different type in some circumstances.

MikeWey added a commit that referenced this issue Oct 26, 2013
@MikeWey
Copy link
Owner

MikeWey commented Oct 26, 2013

On Windows with MinGW float_t also is float with X86_64 and real with i686.

So i changed the definition of MagickRealType to real on 32-bits systems.

@MikeWey MikeWey closed this as completed Sep 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants