Commit 7e196cd1 authored by Emil Velikov's avatar Emil Velikov Committed by Emil Velikov

c11/threads: resolve link issues with -O0

Add weak symbol notation for the pthread_mutexattr* symbols, thus making
the linker happy. When building with -O1 or greater the optimiser will
kick in and remove the said functions as they are dead/unreachable code.

Ideally we'll enable the optimisations locally, yet that does not seem
to work atm.

v2: Add the AX_GCC_FUNC_ATTRIBUTE([weak]) hunk in configure.

Cc: Alejandro Piñeiro <>
Cc: Ben Widawsky <>
Cc: Ilia Mirkin <>
Cc: Rob Herring <>
Signed-off-by: default avatarEmil Velikov <>
Tested-by: Rob Clark's avatarRob Clark <>
Tested-by: Mark Janes's avatarMark Janes <>
parent 0ceed170
......@@ -233,6 +233,7 @@ AX_GCC_FUNC_ATTRIBUTE([pure])
......@@ -169,6 +169,32 @@ mtx_destroy(mtx_t *mtx)
* XXX: Workaround when building with -O0 and without pthreads link.
* In such cases constant folding and dead code elimination won't be
* available, thus the compiler will always add the pthread_mutexattr*
* functions into the binary. As we try to link, we'll fail as the
* symbols are unresolved.
* Ideally we'll enable the optimisations locally, yet that does not
* seem to work.
* So the alternative workaround is to annotate the symbols as weak.
* Thus the linker will be happy and things don't clash when building
* with -O1 or greater.
int pthread_mutexattr_init(pthread_mutexattr_t *attr);
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
static inline int
mtx_init(mtx_t *mtx, int type)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment