From 0a9c6fd77139f4fe095ce997a6fecd33559fdf45 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sat, 23 Jan 2021 15:00:40 +0000 Subject: [PATCH] Revert GNU __malloc_initialize_hook(3) change (re: e8b3274a) This post-Korn AT&T commit from Feburary 2020 broke the build at least on Slackware 14.2 with gcc 5.5.0 and glibc 2.23 if vmalloc was disabled by defining _std_malloc or _AST_ksh_release (see 35672208). So building with vmalloc disabled has always been broken on 93u+m on at least this version of Linux. As usual, AT&T did not document the reason for applying this change. It was also part of a commit that I already have little trust in (I reverted another part of it in 16e4824c). So let's just revert this and see what happens. Hmm. The Linux __malloc_initialize_hook(3) manual page says it's deprecated and was to be removed from glibc as of 2.24, whereas Slackware 14.2 uses glibc 2.23. This would explain why this change didn't break Linux with newer glibc versions, as the feature test won't detect it and it won't be used at all. src/lib/libast/features/vmalloc, src/lib/libast/vmalloc/malloc.c: - Revert change in definition of __malloc_initialize_hook. It now conforms again with the spec in the Linux man page. The build error caused by this change was: | + cc -D_BLD_DLL -fPIC -D_BLD_ast '-D_AST_git_commit="e3f6d2d0"' -Os -g -D_std_malloc -I. -I/usr/local/src/ksh/src/lib/libast -Icomp -I/usr/local/src/ksh/src/lib/libast/comp -Ivmalloc -I/usr/local/src/ksh/src/lib/libast/vmalloc -Iinclude -I/usr/local/src/ksh/src/lib/libast/include -Istd -I/usr/local/src/ksh/src/lib/libast/std -D_PACKAGE_ast -c /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c | /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c: In function '_ast_mallopt': | /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c:1089:58: warning: implicit declaration of function 'mallopt' [-Wimplicit-function-declaration] | extern int F2(_ast_mallopt, int,cmd, int,value) { return mallopt(cmd, value); } | ^ | /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c: At top level: | /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c:1093:22: error: return type is an incomplete type | extern Mallinfo_t F0(_ast_mallinfo, void) { return mallinfo(); } | ^ | /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c:72:19: note: in definition of macro 'F0' | #define F0(f,t0) f(t0) | ^ | /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c: In function '_ast_mallinfo': | /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c:1093:52: warning: implicit declaration of function 'mallinfo' [-Wimplicit-function-declaration] | extern Mallinfo_t F0(_ast_mallinfo, void) { return mallinfo(); } | ^ | /usr/local/src/ksh/src/lib/libast/vmalloc/malloc.c:1093:52: warning: 'return' with a value, in function returning void | mamake [lib/libast]: *** exit code 1 making malloc.o --- src/lib/libast/features/vmalloc | 2 +- src/lib/libast/vmalloc/malloc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/libast/features/vmalloc b/src/lib/libast/features/vmalloc index 5de9fbfc4..284f503f0 100644 --- a/src/lib/libast/features/vmalloc +++ b/src/lib/libast/features/vmalloc @@ -191,7 +191,7 @@ tst malloc_hook note{ gnu malloc hooks work }end execute{ __realloc_hook = test_realloc_hook; } - typeof (__malloc_initialize_hook) __malloc_initialize_hook = test_initialize_hook; + void (*__malloc_initialize_hook)(void) = test_initialize_hook; int main() { diff --git a/src/lib/libast/vmalloc/malloc.c b/src/lib/libast/vmalloc/malloc.c index 90b0336ab..ae77a2212 100644 --- a/src/lib/libast/vmalloc/malloc.c +++ b/src/lib/libast/vmalloc/malloc.c @@ -823,7 +823,7 @@ static void vm_initialize_hook(void) __realloc_hook = vm_realloc_hook; } -typeof (__malloc_initialize_hook) __malloc_initialize_hook = vm_initialize_hook; +void (*__malloc_initialize_hook)(void) = vm_initialize_hook; #if 0 /* 2012-02-29 this may be needed to cover shared libs */