busybox: fix segfaults with clang. Closes #278

This commit is contained in:
Dylan Araps 2021-07-12 20:24:39 +03:00
parent 6494390713
commit 13e25e48ac
No known key found for this signature in database
GPG Key ID: 13295DAC2CF13B5C
4 changed files with 74 additions and 3 deletions

View File

@ -9,9 +9,13 @@ sed -e "s#= g[c+][c+]#= ${CC:=cc}#g" \
-e "s#\(\$(CROSS_COMPILE)\)gcc#\1${CC}#g" Makefile > _
mv -f _ Makefile
# Ensure that busybox's build system is aware that 'cc' may point
# to clang rather than GCC. This is the case in non-GCC systems.
case $("$CC" --version) in (*clang*)
case $("$CC" --version) in *clang*)
# Disable UB based optimizations which are optimized out by
# clang and become null pointer dereferences(?).
patch -p1 < patch-clang/fix-UB.patch
# Ensure that busybox's build system is aware that 'cc' may point
# to clang rather than GCC. This is the case in non-GCC systems.
sed "s&\(\$(CC),\)clang&\1${CC}&g" Makefile.flags > _
mv -f _ Makefile.flags
esac

View File

@ -6,6 +6,7 @@
f0e17fefc0af6b10205d72b242b6ef7481a58ff07726c62890ebc5893b96a396
73be7b16dcff44e88eb48696522794f529beddf9d5a139b8a76cc8685a9f6fc8
d70c4cd6381baeb3836c0387f53553021b48bdc851de49f1c86d836f7d0355fc
c8a6fc95a75fa355d570c14e214d68a618e060a486b824b83b5140b9c6a894a7
c599d1590da233d4926c65c411ea32409c445c7e244e1d3aa10b4c2fd60b1dd4
f6141447a68127cd4997689687bd8c0f8b7e63e0a17d6eb09d4178b4947c0ce3
ebd61afac770d3d9cae5c411f44002496fb18b28cf7b77520072a3909852246e

View File

@ -0,0 +1,65 @@
diff --git a/coreutils/test.c b/coreutils/test.c
index 7c65743..ac0ac4e 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -435,7 +435,7 @@ struct test_statics {
};
/* See test_ptr_hack.c */
-extern struct test_statics *const test_ptr_to_statics;
+extern struct test_statics *test_ptr_to_statics;
#define S (*test_ptr_to_statics)
#define args (S.args )
diff --git a/include/libbb.h b/include/libbb.h
index cae5465..adbf4b8 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -342,7 +342,7 @@ struct BUG_off_t_size_is_misdetected {
#if defined(errno)
/* If errno is a define, assume it's "define errno (*__errno_location())"
* and we will cache it's result in this variable */
-extern int *const bb_errno;
+extern int *bb_errno;
#undef errno
#define errno (*bb_errno)
#define bb_cached_errno_ptr 1
@@ -2228,7 +2228,7 @@ struct globals;
/* '*const' ptr makes gcc optimize code much better.
* Magic prevents ptr_to_globals from going into rodata.
* If you want to assign a value, use SET_PTR_TO_GLOBALS(x) */
-extern struct globals *const ptr_to_globals;
+extern struct globals *ptr_to_globals;
#if defined(__clang_major__) && __clang_major__ >= 9
/* Clang/llvm drops assignment to "constant" storage. Silently.
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 75de88e..78ad893 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -192,7 +192,7 @@ struct lineedit_statics {
};
/* See lineedit_ptr_hack.c */
-extern struct lineedit_statics *const lineedit_ptr_to_statics;
+extern struct lineedit_statics * lineedit_ptr_to_statics;
#define S (*lineedit_ptr_to_statics)
#define state (S.state )
diff --git a/shell/ash.c b/shell/ash.c
index f16d7fb..0eff957 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -300,10 +300,9 @@ typedef long arith_t;
* set "-DBB_GLOBAL_CONST=''" in CONFIG_EXTRA_CFLAGS to disable
* this optimization.
*/
-#ifndef BB_GLOBAL_CONST
-# define BB_GLOBAL_CONST const
-#endif
+#undef BB_GLOBAL_CONST
+#define BB_GLOBAL_CONST
/* ============ Hash table sizes. Configurable. */

View File

@ -6,6 +6,7 @@ patches/print-unicode.patch patch
patches/install-fix-chown.patch patch
patches/lsusb-vendor-product.patch patch
patches/unzip-usage-no-error.patch patch
patches/fix-UB.patch patch-clang
files/.config
files/.config-suid
files/acpid.run