aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-01-03 14:29:11 +0000
committerRon Yorston <rmy@pobox.com>2024-01-03 14:29:11 +0000
commit306601c86fa1cc6c210b7f18d597b8c0821ab19a (patch)
tree94177968ffcce05238e97847a5f4ae6481a73fb6
parentcca8c8e806db11810e25c8fa9446e86431aa2a53 (diff)
downloadbusybox-w32-306601c86fa1cc6c210b7f18d597b8c0821ab19a.tar.gz
busybox-w32-306601c86fa1cc6c210b7f18d597b8c0821ab19a.tar.bz2
busybox-w32-306601c86fa1cc6c210b7f18d597b8c0821ab19a.zip
win32: make the clang build less crashy
busybox-w32 binaries built using clang crashed so frequently that they were pretty much unusable. The main issue seems to be with assignments to the structures containing global variables which are used in most applets. Upstream commit 5156b2455 (Make const ptr assign as function call in clang) addresses this, but is insufficient for the build on Windows. Extend the idea to the ASSIGN_CONST_PTR() macro too. Costs 32-80 bytes in the gcc build.
-rw-r--r--Makefile.flags5
-rw-r--r--include/libbb.h5
-rw-r--r--libbb/const_hack.c10
-rw-r--r--shell/ash.c8
4 files changed, 22 insertions, 6 deletions
diff --git a/Makefile.flags b/Makefile.flags
index 1a2923854..bf22cec04 100644
--- a/Makefile.flags
+++ b/Makefile.flags
@@ -149,6 +149,11 @@ endif
149 149
150ifeq ($(CONFIG_PLATFORM_MINGW32),y) 150ifeq ($(CONFIG_PLATFORM_MINGW32),y)
151CFLAGS += -Iwin32 -DHAVE_STRING_H=1 -DHAVE_CONFIG_H=0 -fno-builtin-stpcpy -fno-builtin-stpncpy -fno-ident -fno-builtin-strndup 151CFLAGS += -Iwin32 -DHAVE_STRING_H=1 -DHAVE_CONFIG_H=0 -fno-builtin-stpcpy -fno-builtin-stpncpy -fno-ident -fno-builtin-strndup
152# this seems to be necessary for setjmp/longjmp to work with clang
153ifeq ($(lastword $(subst -, ,$(CC))),clang)
154CFLAGS += $(call cc-option,-fexceptions,)
155endif
156
152EXEEXT = .exe 157EXEEXT = .exe
153LDLIBS += ws2_32 158LDLIBS += ws2_32
154endif 159endif
diff --git a/include/libbb.h b/include/libbb.h
index a7b19b1c9..a469bfe03 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -2439,10 +2439,15 @@ static ALWAYS_INLINE void* not_const_pp(const void *p)
2439 ); 2439 );
2440 return pp; 2440 return pp;
2441} 2441}
2442# if !ENABLE_PLATFORM_MINGW32
2442# define ASSIGN_CONST_PTR(pptr, v) do { \ 2443# define ASSIGN_CONST_PTR(pptr, v) do { \
2443 *(void**)not_const_pp(pptr) = (void*)(v); \ 2444 *(void**)not_const_pp(pptr) = (void*)(v); \
2444 barrier(); \ 2445 barrier(); \
2445} while (0) 2446} while (0)
2447#else
2448/* On Windows it seems necessary for this to be a function too. */
2449void ASSIGN_CONST_PTR(const void *pptr, const void *ptr) FAST_FUNC;
2450#endif
2446/* XZALLOC_CONST_PTR() is an out-of-line function to prevent 2451/* XZALLOC_CONST_PTR() is an out-of-line function to prevent
2447 * clang from reading pointer before it is assigned. 2452 * clang from reading pointer before it is assigned.
2448 */ 2453 */
diff --git a/libbb/const_hack.c b/libbb/const_hack.c
index 9575e6d67..75163fede 100644
--- a/libbb/const_hack.c
+++ b/libbb/const_hack.c
@@ -13,4 +13,14 @@ void FAST_FUNC XZALLOC_CONST_PTR(const void *pptr, size_t size)
13{ 13{
14 ASSIGN_CONST_PTR(pptr, xzalloc(size)); 14 ASSIGN_CONST_PTR(pptr, xzalloc(size));
15} 15}
16
17# if ENABLE_PLATFORM_MINGW32
18void FAST_FUNC ASSIGN_CONST_PTR(const void *pptr, const void *v)
19{
20 do {
21 *(void**)not_const_pp(pptr) = (void*)(v);
22 barrier();
23 } while (0);
24}
25# endif
16#endif 26#endif
diff --git a/shell/ash.c b/shell/ash.c
index 8b7c6c627..adab63fa7 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -17279,8 +17279,6 @@ forkshell_init(const char *idstr)
17279 struct forkshell *fs; 17279 struct forkshell *fs;
17280 void *map_handle; 17280 void *map_handle;
17281 HANDLE h; 17281 HANDLE h;
17282 struct globals_var **gvpp;
17283 struct globals_misc **gmpp;
17284 int i; 17282 int i;
17285 char **ptr; 17283 char **ptr;
17286 char *lrelocate; 17284 char *lrelocate;
@@ -17323,10 +17321,8 @@ forkshell_init(const char *idstr)
17323 fs->gmp->trap_ptr = fs->gmp->trap; 17321 fs->gmp->trap_ptr = fs->gmp->trap;
17324 17322
17325 /* Set global variables */ 17323 /* Set global variables */
17326 gvpp = (struct globals_var **)&ash_ptr_to_globals_var; 17324 ASSIGN_CONST_PTR(&ash_ptr_to_globals_var, fs->gvp);
17327 *gvpp = fs->gvp; 17325 ASSIGN_CONST_PTR(&ash_ptr_to_globals_misc, fs->gmp);
17328 gmpp = (struct globals_misc **)&ash_ptr_to_globals_misc;
17329 *gmpp = fs->gmp;
17330 cmdtable = fs->cmdtable; 17326 cmdtable = fs->cmdtable;
17331#if ENABLE_ASH_ALIAS 17327#if ENABLE_ASH_ALIAS
17332 atab = fs->atab; /* will be NULL for FS_SHELLEXEC */ 17328 atab = fs->atab; /* will be NULL for FS_SHELLEXEC */