summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Kbuild.src1
-rw-r--r--libbb/appletlib.c2
-rw-r--r--libbb/const_hack.c16
-rw-r--r--libbb/lineedit.c2
4 files changed, 19 insertions, 2 deletions
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src
index 6763008..2fa2398 100644
--- a/libbb/Kbuild.src
+++ b/libbb/Kbuild.src
@@ -24,6 +24,7 @@ lib-y += chomp.o
lib-y += compare_string_array.o
lib-y += concat_path_file.o
lib-y += concat_subpath_file.o
+lib-y += const_hack.o
lib-y += copy_file.o
lib-y += copyfd.o
lib-y += crc32.o
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index bf26c99..e8c3084 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -247,7 +247,7 @@ void lbb_prepare(const char *applet
IF_FEATURE_INDIVIDUAL(, char **argv))
{
#ifdef bb_cached_errno_ptr
- ASSIGN_CONST_PTR(bb_errno, get_perrno());
+ ASSIGN_CONST_PTR(&bb_errno, get_perrno());
#endif
applet_name = applet;
diff --git a/libbb/const_hack.c b/libbb/const_hack.c
new file mode 100644
index 0000000..9575e6d
--- /dev/null
+++ b/libbb/const_hack.c
@@ -0,0 +1,16 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Trick to assign a const ptr with barrier for clang
+ *
+ * Copyright (C) 2021 by YU Jincheng <shana@zju.edu.cn>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+#include "libbb.h"
+
+#if defined(__clang_major__) && __clang_major__ >= 9
+void FAST_FUNC XZALLOC_CONST_PTR(const void *pptr, size_t size)
+{
+ ASSIGN_CONST_PTR(pptr, xzalloc(size));
+}
+#endif
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 3c87abc..9960448 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -214,7 +214,7 @@ extern struct lineedit_statics *BB_GLOBAL_CONST lineedit_ptr_to_statics;
#define delbuf (S.delbuf )
#define INIT_S() do { \
- ASSIGN_CONST_PTR(lineedit_ptr_to_statics, xzalloc(sizeof(S))); \
+ XZALLOC_CONST_PTR(&lineedit_ptr_to_statics, sizeof(S)); \
} while (0)
static void deinit_S(void)