From: Simon Glass <simon.glass@canonical.com> When running sandbox, U-Boot's malloc symbols can be hooked into the GOT before U-Boot code runs. This causes issues because the dynamic linker may call malloc/free before gd is initialized. Use hidden visibility for malloc symbols to prevent them from being hooked into the GOT, so only code in the U-Boot binary itself calls them; any other code calls the standard C library malloc(). Changes from original commit: - Use DLMALLOC_EXPORT mechanism instead of #pragma in malloc.h Cc: Rabin Vincent <rabin@rab.in> Signed-off-by: Stephen Warren <swarren@wwwdotorg.org> Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Glass <sjg@chromium.org> Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> (cherry picked from commit 2f0bcd4de1a5b990e58d12cd0c7f9d7e9248fec4) --- common/dlmalloc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 5a8e463671c..d53cbf2f2e1 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -538,6 +538,15 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP #define DLMALLOC_VERSION 20806 #endif /* DLMALLOC_VERSION */ +/* + * For U-Boot, use hidden visibility to prevent malloc symbols from being + * hooked into the GOT, avoiding issues during early initialization before + * gd is set up. + */ +#ifdef __UBOOT__ +#define DLMALLOC_EXPORT extern __attribute__((visibility("hidden"))) +#endif + #ifndef DLMALLOC_EXPORT #define DLMALLOC_EXPORT extern #endif -- 2.43.0