dynamic sized arrays crash

dynamic sized arrays crash

Portrait de prohaskatokutek.com

using cilk++ 8503 on cents 5.4 found that a cilk function that sizes a local array dynamically crashes. the problem is avoided when using an explicit malloc and free. the code is attached. run "make check" to reproduce. #include #include #include extern "C" { int n = 0; int foo(void) { return n; } } void testit(void) { int n = foo(); printf("n=%d\\n", n); int a[n] ; // int *a = (int *) malloc(n * sizeof (int)); for (int i = 0; i < n; i++) a[i] = i; // free(a); } int cilk_main(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { n = atoi(argv[i]); testit(); } return 0; } the crash is: Program received signal SIGSEGV, Segmentation fault. 0x00002aaf37e8e915 in __cilkrts_allocate_dynamic () from /usr/local/cilk_8503/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../lib64/libcilkrts.so Current language: auto; currently asm (gdb) disass Dump of assembler code for function __cilkrts_allocate_dynamic: 0x00002aaf37e8e912 <__cilkrts_allocate_dynamic+0>: mov %rsp,%rax 0x00002aaf37e8e915 <__cilkrts_allocate_dynamic+3>: mov 0x48(%r10),%rsp 0x00002aaf37e8e919 <__cilkrts_allocate_dynamic+7>: push %rax 0x00002aaf37e8e91a <__cilkrts_allocate_dynamic+8>: callq 0x2aaf37e8add0 <__cilkrts_c_allocate_dynamic> 0x00002aaf37e8e91f <__cilkrts_allocate_dynamic+13>: mov (%rsp),%rsp 0x00002aaf37e8e923 <__cilkrts_allocate_dynamic+17>: retq End of assembler dump. (gdb) info registers rax 0x1ec95c28 516512808 rbx 0x1ec95c30 516512816 rcx 0x3dcbb51780 265410647936 rdx 0x7fffb2904fc0 140736189190080 rsi 0x4 4 rdi 0x1ec95c68 516512872 rbp 0x1ec95c60 0x1ec95c60 rsp 0x1ec95c28 0x1ec95c28 r8 0xffffffff 4294967295 r9 0x3dcb919840 265408321600 r10 0x22 34 r11 0x206 518 r12 0x7fffb2905490 140736189191312 r13 0x909090909090cc02 -8029759185026495486 r14 0x909090909090cc03 -8029759185026495485 r15 0x909090909090cc04 -8029759185026495484 rip 0x2aaf37e8e915 0x2aaf37e8e915 <__cilkrts_allocate_dynamic+3>

Program received signal SIGSEGV, Segmentation fault.0x00002aaf37e8e915 in __cilkrts_allocate_dynamic () from /usr/local/cilk_8503/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.2.4/../../../../lib64/libcilkrts.soCurrent language: auto; currently asm(gdb) disassDump of assembler code for function __cilkrts_allocate_dynamic:0x00002aaf37e8e912 <__cilkrts_allocate_dynamic+0>: mov %rsp,%rax0x00002aaf37e8e915 <__cilkrts_allocate_dynamic+3>: mov 0x48(%r10),%rsp0x00002aaf37e8e919 <__cilkrts_allocate_dynamic+7>: push %rax0x00002aaf37e8e91a <__cilkrts_allocate_dynamic+8>: callq 0x2aaf37e8add0 <__cilkrts_c_allocate_dynamic>0x00002aaf37e8e91f <__cilkrts_allocate_dynamic+13>: mov (%rsp),%rsp0x00002aaf37e8e923 <__cilkrts_allocate_dynamic+17>: retq End of assembler dump.(gdb) info registersrax 0x1ec95c28 516512808rbx 0x1ec95c30 516512816rcx 0x3dcbb51780 265410647936rdx 0x7fffb2904fc0 140736189190080rsi 0x4 4rdi 0x1ec95c68 516512872rbp 0x1ec95c60 0x1ec95c60rsp 0x1ec95c28 0x1ec95c28r8 0xffffffff 4294967295r9 0x3dcb919840 265408321600r10 0x22 34r11 0x206 518r12 0x7fffb2905490 140736189191312r13 0x909090909090cc02 -8029759185026495486r14 0x909090909090cc03 -8029759185026495485r15 0x909090909090cc04 -8029759185026495484rip 0x2aaf37e8e915 0x2aaf37e8e915 <__cilkrts_allocate_dynamic+3>

Fichier attachéTaille
Téléchargement dynarraycrash.cilk444 octets
Téléchargement Makefile735 octets
5 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.
Portrait de John Carr (Intel)

This looks like a bug that has been fixed but not posted to the web site.

Here is a source patch for the runtime. I'm typing this on Windows so the whitespace will probably be hopelessly garbled but you should be able to edit manually to match.

Index: /home/jfc/svn/eng/prod/common/runtime/x86_32-linux.asm

===================================================================

--- /home/jfc/svn/eng/prod/common/runtime/x86_32-linux.asm (revision 8756)

+++ /home/jfc/svn/eng/prod/common/runtime/x86_32-linux.asm (revision 8757)

@@ -153,6 +153,9 @@

FUNCTION(__cilkrts_c_free_dynamic)

.p2align 6,0xcc,8

EXTERN(__cilkrts_free_dynamic):

+ .if ifdef(`worker_in_frame',1,0)

+ movl offset_rbp_descriptor+offset_sf_worker(%ebp), %wreg

+ .endif

movl offset_w_stack(%wreg), %eax

xchg %eax, %esp

pushl %eax

Index: /home/jfc/svn/eng/prod/common/runtime/x86_64-linux.asm

===================================================================

--- /home/jfc/svn/eng/prod/common/runtime/x86_64-linux.asm (revision 8756)

+++ /home/jfc/svn/eng/prod/common/runtime/x86_64-linux.asm (revision 8757)

@@ -1199,6 +1199,10 @@

#Avoid crossing a 64 byte (cache line) boundary.

ifelse(pic, `static', `.p2align 6,,17', pic, `dynamic', `.p2align 6,,25')

EXTERN(__cilkrts_$1):

+ # These functions are called with %rbp valid

+ .if ifelse(wreg,`r10',1,0)

+ movq offset_rbp_descriptor+offset_sf_worker(%rbp), %wreg

+ .endif

movq %rsp, %rax

movq offset_w_stack(%wreg), %rsp

pushq %rax

Portrait de prohaskatokutek.com

thanks we will try the patch. is there a schedule for the next release? also, we would like to use cilk on windows for 64 bit apps. what is going on with it?

Portrait de Kittur Ganesh (Intel)

Hi,

We do have a beta for Cilk for Windows* and I'll send you an invite to participate and help give us feedback. Appreciate much for your interest and look forwad to your participation in the beta.

-regards,
Kittur

Portrait de liyun

Sorry. I do not get where should this patch goes to.

Which directory or file should I add these lines?

Connectez-vous pour laisser un commentaire.