SRI-CSL/gllvm

Pthread linking issue

hongxuchen opened this issue · 8 comments

It's a bit weird but I really don't know why. Building with -pthread may still sometimes fail to link correctly.
For example, when I use gclang simple_race.c -pthread it fails however it works fine with clang simple_race.c -pthread.

simple_race.c
#include <pthread.h>
#include <stdio.h>

int Global;

void *Thread1(void *x) {
    Global++;
    return NULL;
}

void *Thread2(void *x) {
    Global--;
    return NULL;
}

int main() {
    pthread_t t[2];
    pthread_create(&t[0], NULL, Thread1, NULL);
    pthread_create(&t[1], NULL, Thread2, NULL);
    pthread_join(t[0], NULL);
    pthread_join(t[1], NULL);
}

On the other hand, it seems everything is fine when building regular projects involving pthread such as lbzip2.

Indeed I'm using the HEAD and there is a callback for -pthread.

"-pthread": {0, pr.compileUnaryCallback},

Thanks for reporting this. I will look into it.

Maybe it should be both compile and link time option? What platform are you compiling on and I will
check the documentation.

Actually it looks to be just a link time option. Let me commit that and see if it fixes it for you.

By the way, the reason it fails for your example

gclang simple_race.c -pthread

is that that command translates both to a compile then a link, and the whole point of
parsing the cmd flags into compile and link is so that we can do this decomposition correctly,
and most makefiles would never conflate the two steps into one.

df3a1a7 works for me now.
I'm using Ubuntu 18.04.1 LTS x86_64 with LLVM/Clang 7.0.0 (tags/RELEASE_700/final).

BTW, had a quick search and this seems to mention that -pthread is relevant to link as well as preprocessing.

The -pthread link you include is for gcc which is irrelevant. Pretty sure that for clang it is just
a link time flag. I will leave this open for a few more days. Let me know if there are further issues.

Thanks again for helping gllvm improve.

Thank you so much for bringing the community such a fabulous tool 😄