Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pthread linking issue #25

Closed
hongxuchen opened this issue Jan 1, 2019 · 8 comments
Closed

Pthread linking issue #25

hongxuchen opened this issue Jan 1, 2019 · 8 comments

Comments

@hongxuchen
Copy link

hongxuchen commented Jan 1, 2019

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},

@ianamason
Copy link
Member

Thanks for reporting this. I will look into it.

@ianamason
Copy link
Member

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

ianamason added a commit that referenced this issue Jan 2, 2019
@ianamason
Copy link
Member

ianamason commented Jan 2, 2019

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.

@hongxuchen
Copy link
Author

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).

@hongxuchen
Copy link
Author

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

@ianamason
Copy link
Member

ianamason commented Jan 3, 2019

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.

@ianamason
Copy link
Member

Thanks again for helping gllvm improve.

@hongxuchen
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants