From c3e256e018c25c1d99d11c32d8442745d5bcd795 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 8 Jul 2020 11:19:14 +0800 Subject: [PATCH] libxx: Make __dso_handle weak since sim arch has to use other instance provided by host glibc also initialize __dso_handle to self as glibc: https://github.com/bminor/glibc/blob/master/csu/dso_handle.c#L21 Signed-off-by: Xiang Xiao Change-Id: I7531ae58fc4dbe4600bcb2c2c3a6cac021378bc1 --- include/nuttx/compiler.h | 6 ++++++ libs/libxx/libxx.hxx | 2 +- libs/libxx/libxx_cxa_atexit.cxx | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index a958e635d9..0be441ed62 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -82,11 +82,13 @@ # define CONFIG_HAVE_WEAKFUNCTIONS 1 # define weak_alias(name, aliasname) \ extern __typeof (name) aliasname __attribute__ ((weak, alias (#name))); +# define weak_data __attribute__ ((weak)) # define weak_function __attribute__ ((weak)) # define weak_const_function __attribute__ ((weak, __const__)) # else # undef CONFIG_HAVE_WEAKFUNCTIONS # define weak_alias(name, aliasname) +# define weak_data # define weak_function # define weak_const_function # endif @@ -324,6 +326,7 @@ # undef CONFIG_HAVE_WEAKFUNCTIONS # define weak_alias(name, aliasname) +# define weak_data # define weak_function # define weak_const_function # define restrict /* REVISIT */ @@ -462,6 +465,7 @@ # undef CONFIG_HAVE_WEAKFUNCTIONS # define weak_alias(name, aliasname) +# define weak_data # define weak_function # define weak_const_function # define restrict @@ -565,6 +569,7 @@ # define UNUSED(a) ((void)(a)) # define weak_alias(name, aliasname) +# define weak_data __weak # define weak_function __weak # define weak_const_function # define noreturn_function @@ -618,6 +623,7 @@ # undef CONFIG_HAVE_WEAKFUNCTIONS # undef CONFIG_HAVE_CXX14 # define weak_alias(name, aliasname) +# define weak_data # define weak_function # define weak_const_function # define restrict diff --git a/libs/libxx/libxx.hxx b/libs/libxx/libxx.hxx index ed2d739124..ec76c37893 100644 --- a/libs/libxx/libxx.hxx +++ b/libs/libxx/libxx.hxx @@ -76,7 +76,7 @@ typedef CODE void (*__cxa_exitfunc_t)(void *arg); // Public Data //*************************************************************************** -extern "C" FAR void *__dso_handle; +extern "C" FAR void *__dso_handle weak_data; //*************************************************************************** // Public Function Prototypes diff --git a/libs/libxx/libxx_cxa_atexit.cxx b/libs/libxx/libxx_cxa_atexit.cxx index 46cde2cc96..c94ac265b1 100644 --- a/libs/libxx/libxx_cxa_atexit.cxx +++ b/libs/libxx/libxx_cxa_atexit.cxx @@ -67,7 +67,7 @@ extern "C" // Public Data //************************************************************************* - FAR void *__dso_handle = NULL; + FAR void *__dso_handle = &__dso_handle; //************************************************************************* // Private Functions