<div dir="ltr">Sorry, ignore that last one.  It fired off incomplete.<br><br>On Wed, Dec 21, 2016 at 10:35 PM, David T. Lewis <<a href="mailto:lewis@mail.msen.com">lewis@mail.msen.com</a>> wrote:<br>><br>> On Wed, Dec 21, 2016 at 10:11:39AM +0000, Jan Vrany wrote:<br>>><br>>> On Tue, 2016-12-20 at 21:54 -0500, David T. Lewis wrote:<br>>> > ??<br>>> > On Wed, Dec 21, 2016 at 10:40:32AM +0800, Ben Coman wrote:<br>>> > > ??<br>>> > > I'd be interested to know the reason sends get slower (if known).<br>>> > > cheers -ben<br>>> ><br>>> > No clue, I was just sanity checking to make sure that -O2 was not<br>>> > horribly<br>>> > worse. It was not. But I suspect all of this is likely to vary<br>>> > depending on<br>>> > gcc compiler version and phase of the moon.<br>>><br>>> This post:<br>>><br>>> <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html">http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html</a><br>>><br>>> explains the dependency on moon phases (and compiler versions) :-)<br>>><br>><br>> Thanks. Indeed there is probably some undefined C behavior in there, although<br>> I was not able to spot it. If anyone is interested in lending their eyes to<br>> the problem, I was able to localize the crash to intermittent segfaults that<br>> occurred in OSProcessPlugin>>fixPointersInArrayOfStrings: which is generated<br>> in C (for a V3 image, not Spur) as:<br>><br>> /*      Use the address offsets in offsetArray to fix up the pointers in cStringArray.<br>>         The result is a C array of pointers to char, used for argv and env vectors. */<br>><br>> static sqInt fixPointersInArrayOfStringswithOffsetscount(char *flattenedArrayOfStrings, sqInt *offsetArray, sqInt count) {<br>>     sqInt idx;<br>>     char **ptr;<br>><br>>         ptr = ((char **) flattenedArrayOfStrings);<br>>         idx = 0;<br>>         while (idx < count) {<br>>                 ptr[idx] = (flattenedArrayOfStrings + (((offsetArray[idx]) >> 1)));<br>>                 idx += 1;<br>>         }<br>>         return null;<br>> }<br>><br>><br><br><br>I've taken a guess at its usage and turned it into an executable test case.<br>Could you confirm this...<br><br>#include <stdio.h><br>typedef int sqInt;<br>int null = 0;<br>static sqInt fixPointersInArrayOfStringswithOffsetscount(char *flattenedArrayOfStrings, sqInt *offsetArray, sqInt count) {<br>    sqInt idx;<br>    char **ptr;<br>        ptr = ((char **) flattenedArrayOfStrings);<br>        idx = 0;<br>        while (idx < count) {<br>                ptr[idx] = (flattenedArrayOfStrings + (((offsetArray[idx]) >> 1)));<br>                idx += 1;<br>        }<br>        return null;<br>}<br>int main()<br>{<br>        char *flattenedArrayOfStrings = "abcd\0efgh\0ijkl\0";<br>        sqInt offsetArray[] = {0, 5, 10};<br>        printf("%s\n", flattenedArrayOfStrings);<br>        printf("%d %d %d\n", offsetArray[0], offsetArray[1], offsetArray[2]);<br>        fixPointersInArrayOfStringswithOffsetscount( flattenedArrayOfStrings, offsetArray, 2 );<div>        printf("%s\n", flattenedArrayOfStrings);<br>}<br><br>$ cc test.c ; ./a.out<br>abcd<br>0 5 10<br>Segmentation fault<br><br>ptr is being defined as a pointer to "one" string, but its being<br>accessed as a consecutive list of strings.<br>Even the first assignment to ptr seems wrong.  flattenedArrayOfStrings<br>is a string. The first dereference is a char, and then when it assigns<br>to ptr[idx], it tries to dereferenced the char and boom!<br><div><br></div><div>If the first ptr assignment is changed as follows, it doesn't crash...</div><div><div>       ptr = &flattenedArrayOfStrings;</div><div> </div></div><div>But I'm not sure it does what its supposed to ??</div><div>$ cc test.c ; ./a.out </div><div>abcd</div><div>0 5 10</div><div>abcd</div><div>cd</div><div>abcd</div><div><br></div><div><br></div></div><div>Now if I do this...</div><div><div>static sqInt fixPointersInArrayOfStringswithOffsetscount(char *flattenedArrayOfStrings, sqInt offsetArray[], sqInt count) {</div><div>    sqInt idx;</div><div>    char *ptr[count+1];</div><div>        idx = 0;</div><div>        while (idx < count) {</div><div>                ptr[idx] = flattenedArrayOfStrings + offsetArray[idx];</div><div>                idx += 1;</div><div>        }</div><div>    idx = 0;</div><div>    while (idx < count) {</div><div>            printf("%s\n", ptr[idx]);</div><div>            idx += 1;</div><div>    }</div><div>    return null;</div><div>}</div></div><div><br></div><div>I can call it with count=3 and get this...</div><div>$ cc test.c ; ./a.out </div><div>abcd</div><div>0 5 10</div><div>abcd</div><div>efgh</div><div>ijkl</div><div>abcd</div><div><br></div><div>but the original flattenedArrayOfStrings is unmodified, so I'm not sure if that is how its meant to behave?</div><div><br></div><div>cheers -ben </div><div><br></div></div>