pthread: force linking pthread implementation from IDF

Force linking pthread implementation from IDF, instead of the weak
functions provided by gthread library. Previously this would either
work or not depending on the linking order.

Thanks @bpietsch for suggesting the fix.

Closes https://github.com/espressif/esp-idf/issues/3709
This commit is contained in:
Ivan Grokhotkov 2019-07-28 11:22:08 +02:00
parent 1b6010bedf
commit 661769527c
5 changed files with 33 additions and 0 deletions

View File

@ -3,6 +3,16 @@ idf_component_register(SRCS "pthread.c"
"pthread_local_storage.c"
INCLUDE_DIRS include)
if(GCC_NOT_5_2_0)
set(extra_link_flags "-u pthread_include_pthread_impl")
list(APPEND extra_link_flags "-u pthread_include_pthread_cond_impl")
list(APPEND extra_link_flags "-u pthread_include_pthread_local_storage_impl")
endif()
if(CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP)
target_link_libraries(${COMPONENT_LIB} "-Wl,--wrap=vPortCleanUpTCB")
endif()
if(extra_link_flags)
target_link_libraries(${COMPONENT_LIB} INTERFACE "${extra_link_flags}")
endif()

View File

@ -11,3 +11,11 @@ COMPONENT_ADD_LDFLAGS := -lpthread
ifdef CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
COMPONENT_ADD_LDFLAGS += -Wl,--wrap=vPortCleanUpTCB
endif
ifeq ($(GCC_NOT_5_2_0), 1)
# Forces the linker to include pthread implementation from this component,
# instead of the weak implementations provided by libgcc.
COMPONENT_ADD_LDFLAGS += -u pthread_include_pthread_impl
COMPONENT_ADD_LDFLAGS += -u pthread_include_pthread_cond_impl
COMPONENT_ADD_LDFLAGS += -u pthread_include_pthread_local_storage_impl
endif # GCC_NOT_5_2_0

View File

@ -820,3 +820,8 @@ int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
}
return EINVAL;
}
/* Hook function to force linking this file */
void pthread_include_pthread_impl()
{
}

View File

@ -198,3 +198,8 @@ int pthread_cond_destroy(pthread_cond_t *cv)
return ret;
}
/* Hook function to force linking this file */
void pthread_include_pthread_cond_var_impl()
{
}

View File

@ -255,3 +255,8 @@ int pthread_setspecific(pthread_key_t key, const void *value)
return 0;
}
/* Hook function to force linking this file */
void pthread_include_pthread_local_storage_impl()
{
}