Skip to content

Commit

Permalink
pthread: force linking pthread implementation from IDF
Browse files Browse the repository at this point in the history
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 #3709
  • Loading branch information
igrr committed Jul 29, 2019
1 parent 1b6010b commit 6617695
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions components/pthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 8 additions & 0 deletions components/pthread/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions components/pthread/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
5 changes: 5 additions & 0 deletions components/pthread/pthread_cond_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
5 changes: 5 additions & 0 deletions components/pthread/pthread_local_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}

0 comments on commit 6617695

Please sign in to comment.