_vcomp_fork stack frame puzzle

Dan Kegel dank at kegel.com
Thu Aug 9 00:49:14 CDT 2012


Having fun trying to figure out what's in the black box of _vcomp_fork(),
the helper function that spawns threads in Visual C's OpenMP
support library.

The C source code

#include <stdio.h>
#include <omp.h>
int main(int argc, char **argv)
{
    double d;
    double e;
    int i;
    printf("&d is %p, &e is %p\n", &d, &e);
#pragma omp parallel for
    for (i=0; i<3; i++) {
        printf("&d is %p\n", &d);
    }
#pragma omp parallel for
    for (i=0; i<3; i++) {
        printf("&d is %p, &e is %p\n", &d, &e);
    }
    return 0;
}

when compiled with
  cl /MD /openmp /FAs odd.c

generates an .exe and a mixed assembly / source .asm listing.
The compiler puts the loop into a helper function, and invokes
the helper using _vcomp_fork(), which is called with
a flag saying whether to parallelize,
a pointer to the helper function, a count,
and then a pointer to each variable referenced
by the loop from the outer scope.
The code in the helper function knows to
get the addresses of the variables from the stack.

When run with native vcomp.dll, this prints out
the right addresses inside the loop.
When run with my slightly less stubby builtin vcomp patch attached to
http://bugs.winehq.org/show_bug.cgi?id=26688
(based on Andre's earlier patch),
it prints out garbage.

It seems like Andre's varargs code should be right,
but something's not connecting.  I even tried beer,
and it still didn't work.

I guess I should fire up a debugger and see what's going
on, but I don't want to accidentally see too much about
what native's doing.

Suggestions, anyone?
- Dan



More information about the wine-devel mailing list