Append pthread to platform libs if cmake supplied Threads is not good enough #897
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
original PR created from a fork branch: 895
aws-c-common has an explicit dependency on pthread's pthread_mutexattr_settype here in mutex.c .
However, aws-c-common cmake script does not instruct cmake to explicitly link with pthread.
Appending fsanitize=address to CMAKE_CXX_FLAGS results in GLIBC library to provide some pthread API but not all. Therefore,
find_package(Threads REQUIRED)
starts to "find" fake pthread APIs in GLIBC and stops to setCMAKE_THREAD_LIBS_INIT
(which is typically expected to contain Threads lib implementation (which is typically pthread)). In addition, if user sets OpenSSL as a crypto lib implementation, aws-lc is not being built too (aws-lc has a hard set lining dependency on pthread, aws-lc hides the issue being described/fixed in this pull request).The end result is that aws-c-common fails to link (in case of fsanitize= and OpenSSL crypto) because pthread_mutexattr_settype symbol is not found.
Description of changes:
Link explicitly with pthread unless cmake found Threads library provides necessary symbol (i.e. still provide user with a theoretical ability to use custom Threads lib).
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.