diff --git a/components/pthread/CMakeLists.txt b/components/pthread/CMakeLists.txt index d488c92a9..136bf9cf1 100644 --- a/components/pthread/CMakeLists.txt +++ b/components/pthread/CMakeLists.txt @@ -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() diff --git a/components/pthread/component.mk b/components/pthread/component.mk index 9c3eececf..c5793fded 100644 --- a/components/pthread/component.mk +++ b/components/pthread/component.mk @@ -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 diff --git a/components/pthread/pthread.c b/components/pthread/pthread.c index 84997c9aa..f4fe4ded7 100644 --- a/components/pthread/pthread.c +++ b/components/pthread/pthread.c @@ -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() +{ +} diff --git a/components/pthread/pthread_cond_var.c b/components/pthread/pthread_cond_var.c index fe3144512..8db28ae5e 100644 --- a/components/pthread/pthread_cond_var.c +++ b/components/pthread/pthread_cond_var.c @@ -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() +{ +} diff --git a/components/pthread/pthread_local_storage.c b/components/pthread/pthread_local_storage.c index 5e2dbafd2..ecf252e4c 100644 --- a/components/pthread/pthread_local_storage.c +++ b/components/pthread/pthread_local_storage.c @@ -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() +{ +}