Linking zlib before cudart = segfault

Here is the code:

[codebox]#include <cuda_runtime.h>

int main(void)

{

cudaSetDevice(0);

return 0;

}[/codebox]

Here is the compilation:

[codebox]gcc -o test main.c -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lz -lcudart[/codebox]

And here is the crash:

[codebox]$ ./test

Segmentation fault[/codebox]

The backtrace in gdb only shows me this:

[codebox]

#0 0x00007ffff5f34d50 in ?? ()

#1 0x00007ffff7983973 in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#2 0x00007ffff7987b1d in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#3 0x00007ffff79bd169 in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#4 0x00007ffff799e470 in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#5 0x00007ffff796f5df in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#6 0x000000000000000d in ?? ()

#7 0x0000000000000000 in ?? ()

[/codebox]

Passing -lz after -lcudart makes the crash go away, but who knows what else might be silently going wrong.

My environment:

Mandriva Linux 2010.1, kernel 2.6.33.7-desktop-mnb, x86_64

zlib 1.2.3-15mdv2010.1

gcc 4.4.3-2mnb2

nvidia driver 260.24

Cuda compilation tools, release 3.2, V0.2.1221 (the RHEL5.5 binaries)

Can anyone tell me if they can reproduce the crash with the code above by passing -lz before -lcudart?

Here is the code:

[codebox]#include <cuda_runtime.h>

int main(void)

{

cudaSetDevice(0);

return 0;

}[/codebox]

Here is the compilation:

[codebox]gcc -o test main.c -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lz -lcudart[/codebox]

And here is the crash:

[codebox]$ ./test

Segmentation fault[/codebox]

The backtrace in gdb only shows me this:

[codebox]

#0 0x00007ffff5f34d50 in ?? ()

#1 0x00007ffff7983973 in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#2 0x00007ffff7987b1d in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#3 0x00007ffff79bd169 in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#4 0x00007ffff799e470 in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#5 0x00007ffff796f5df in ?? () from /usr/local/cuda/lib64/libcudart.so.3

#6 0x000000000000000d in ?? ()

#7 0x0000000000000000 in ?? ()

[/codebox]

Passing -lz after -lcudart makes the crash go away, but who knows what else might be silently going wrong.

My environment:

Mandriva Linux 2010.1, kernel 2.6.33.7-desktop-mnb, x86_64

zlib 1.2.3-15mdv2010.1

gcc 4.4.3-2mnb2

nvidia driver 260.24

Cuda compilation tools, release 3.2, V0.2.1221 (the RHEL5.5 binaries)

Can anyone tell me if they can reproduce the crash with the code above by passing -lz before -lcudart?

Ah, so it isn’t just me?! Thanks for the tip – I’ve spent the morning trying to figure out the SEGFAULT.

FWIW, I’m running on openSuSE 11.2 x86_64 with CUDA 3.1.

Anyone have an insight?

Thanks,

Matt

Ah, so it isn’t just me?! Thanks for the tip – I’ve spent the morning trying to figure out the SEGFAULT.

FWIW, I’m running on openSuSE 11.2 x86_64 with CUDA 3.1.

Anyone have an insight?

Thanks,

Matt

This might actually be the bug I found in zlib something like two years ago… I’ll need to look and see if that ever actually got fixed.

This might actually be the bug I found in zlib something like two years ago… I’ll need to look and see if that ever actually got fixed.

Have you resolved this bug? I am getting a similar error with a library I have built, libfoo.so.

I created a test case, and I link my test.c with libcudart.so and my libfoo.so. When I use “g++ foo.c -lgpublast -lcudart” everything is fine. When I link with “g++ foo.c -lcudart -lgpublast” I get a segmentation fault before main is hit.

Moreover, if I link with a static version of my library everything works fine.

The main problem is that I need to link libfoo.so and libcudart.so with some other libraries. Although with my test program changing the order of libfoo.so and libcudart.so fixes the problem, with that other set of libraries that doesn’t work. I get the segmentation fault regardless of the order of these two libraries. Again, when I link with a static version of libfoo everything is fine.

Is there a way around it?

Thanks.

It was my bad. I was linking with g++ instead of nvcc. However, I still don’t understand why by changing the order of libcudart and libfoo makes a difference.