This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Improve pthread_[gs]etname_np detection code
ClosedPublic

Authored by labath on Apr 6 2018, 2:51 AM.

Details

Summary

Due to some android peculiarities, in some build configurations
(statically linked executables targeting older release) we could detect
the presence of these functions (because they are present in libc.a,
where check_library_exists searches), but then fail to build because the
headers did not include the definition.

This attempts to remedy that by upgrading the check_library_exists to
check_symbol_exists, which will check that the function is declared too.

I am hoping that a more thorough check will make the messy #ifdef we
have accumulated in the code obsolete, so I optimistically try to remove
it.

Diff Detail

Event Timeline

labath created this revision.Apr 6 2018, 2:51 AM

Just a note that FreeBSD calls its function pthread_set_name_np.

NetBSD has pthread_getname_np() and pthread_setname_np() like Linux, but the setname variant has a different prototype:

int
pthread_setname_np(pthread_t thread, const char *name, void *arg);

FreeBSD also uses pthread_np.h header.

labath added a comment.Apr 6 2018, 7:04 AM

Yeah, so far these checks are only actually used on linux. Do you need them on Free/NetBSD or can we just assume they will always be there?

This patch looks fine, not sure if we can improve it.

This revision was not accepted when it landed; it landed in state Needs Review.Apr 18 2018, 6:16 AM
This revision was automatically updated to reflect the committed changes.