[Mesa-dev] [PATCH] c11/threads: resolve link issues with -O0

Ilia Mirkin imirkin at alum.mit.edu
Tue May 24 13:09:09 UTC 2016


On Tue, May 24, 2016 at 9:06 AM, Rob Herring <robh at kernel.org> wrote:
> On Tue, May 24, 2016 at 4:57 AM, Emil Velikov <emil.l.velikov at gmail.com> wrote:
>> From: Emil Velikov <emil.velikov at collabora.com>
>>
>> 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.
>>
>> Cc: Alejandro PiƱeiro <apinheiro at igalia.com>
>> Cc: Ben Widawsky <ben at bwidawsk.net>
>> Cc: Ilia Mirkin <imirkin at alum.mit.edu>
>> Cc: Mark Janes <mark.a.janes at intel.com>
>> Cc: Rob Clark <robdclark at gmail.com>
>> Cc: Rob Herring <robh at kernel.org>
>> Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
>> ---
>> Building with -Wall -Wextra -pedantic and it does not cause any
>> additional warnings/errors.
>> ---
>>  include/c11/threads_posix.h | 26 ++++++++++++++++++++++++++
>>  1 file changed, 26 insertions(+)
>>
>> diff --git a/include/c11/threads_posix.h b/include/c11/threads_posix.h
>> index 11d36e4..61b7fab 100644
>> --- a/include/c11/threads_posix.h
>> +++ b/include/c11/threads_posix.h
>> @@ -169,6 +169,32 @@ mtx_destroy(mtx_t *mtx)
>>      pthread_mutex_destroy(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.
>> + */
>> +#ifdef HAVE_FUNC_ATTRIBUTE_WEAK
>
> Doesn't this need to get defined somewhere?

See m4/ax_gcc_func_attribute.m4.

>
>> +__attribute__((weak))
>> +int pthread_mutexattr_init(pthread_mutexattr_t *attr);
>> +
>> +__attribute__((weak))
>> +int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
>> +
>> +__attribute__((weak))
>> +int pthread_mutexattr_destroy(pthread_mutexattr_t *attr);
>> +#endif
>> +
>>  // 7.25.4.2
>>  static inline int
>>  mtx_init(mtx_t *mtx, int type)
>> --
>> 2.8.2
>>


More information about the mesa-dev mailing list