ssrg-vt / popcorn-compiler

Popcorn Linux compiler toolchain for heterogeneous-ISA execution
41 stars 22 forks source link

Wrong value when passing "struct stat" as a parameter to a function #37

Open xjtuwxg opened 6 years ago

xjtuwxg commented 6 years ago

Problem description

Hi I got this simple test file when debugging the issue 36:

#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>       // struct stat
#include <fcntl.h>          // O_RDONLY

void print_stat(struct stat sbuf)
//void print_stat(struct stat *sbuf)
{
    printf(">> stat sbuf.st_mode: 0x%x\n", sbuf.st_mode);
    //printf("stat sbuf.st_mode: 0x%x\n", sbuf->st_mode);
}

int main(int argc, char *argv[])
{
    struct stat sbuf;
    int fd = open("fstat.c", O_RDONLY, 0);
    if (fd < 0) {
        printf("error");
        return 1;
    }
    fstat(fd, &sbuf);
    printf("stat sbuf.st_mode: 0x%x\n", sbuf.st_mode);
    printf("sizeof(struct stat): %lu, %lu\n", sizeof(sbuf), sizeof(struct stat));
    print_stat(sbuf);
    //print_stat(&sbuf);
    close(fd);
    return 0;
}

For some reason, it has the following results (the value of st_mode is changed):

$ ./2_x86-64
stat sbuf.st_mode: 0x81a4
sizeof(struct stat): 128, 128
>> stat sbuf.st_mode: 0x3a297461

Environment

popcorn-compiler: from commit 4ffd16e00d70a40b4cdde9507f6eddadffef62b8, patched with the code from issue 36.