aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorYU Jincheng <shana@zju.edu.cn>2021-10-10 02:19:51 +0800
committerDenys Vlasenko <vda.linux@googlemail.com>2021-10-09 22:30:45 +0200
commit5156b245536ce0f07165793f07c63fd9fa5dd3b7 (patch)
tree3b73b7ea8ed1830d9cc13cbce1da6918926553e2 /libbb
parent04ad683bf99333c2a6c6fd6549faa67978ad9a98 (diff)
downloadbusybox-w32-5156b245536ce0f07165793f07c63fd9fa5dd3b7.tar.gz
busybox-w32-5156b245536ce0f07165793f07c63fd9fa5dd3b7.tar.bz2
busybox-w32-5156b245536ce0f07165793f07c63fd9fa5dd3b7.zip
Make const ptr assign as function call in clang
- This can act as memory barrier in clang to avoid read before assign of a const ptr Signed-off-by: LoveSy <shana@zju.edu.cn> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
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 676300801..2fa239857 100644
--- a/libbb/Kbuild.src
+++ b/libbb/Kbuild.src
@@ -24,6 +24,7 @@ lib-y += chomp.o
24lib-y += compare_string_array.o 24lib-y += compare_string_array.o
25lib-y += concat_path_file.o 25lib-y += concat_path_file.o
26lib-y += concat_subpath_file.o 26lib-y += concat_subpath_file.o
27lib-y += const_hack.o
27lib-y += copy_file.o 28lib-y += copy_file.o
28lib-y += copyfd.o 29lib-y += copyfd.o
29lib-y += crc32.o 30lib-y += crc32.o
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index bf26c99e9..e8c308467 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -247,7 +247,7 @@ void lbb_prepare(const char *applet
247 IF_FEATURE_INDIVIDUAL(, char **argv)) 247 IF_FEATURE_INDIVIDUAL(, char **argv))
248{ 248{
249#ifdef bb_cached_errno_ptr 249#ifdef bb_cached_errno_ptr
250 ASSIGN_CONST_PTR(bb_errno, get_perrno()); 250 ASSIGN_CONST_PTR(&bb_errno, get_perrno());
251#endif 251#endif
252 applet_name = applet; 252 applet_name = applet;
253 253
diff --git a/libbb/const_hack.c b/libbb/const_hack.c
new file mode 100644
index 000000000..9575e6d67
--- /dev/null
+++ b/libbb/const_hack.c
@@ -0,0 +1,16 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Trick to assign a const ptr with barrier for clang
4 *
5 * Copyright (C) 2021 by YU Jincheng <shana@zju.edu.cn>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */
9#include "libbb.h"
10
11#if defined(__clang_major__) && __clang_major__ >= 9
12void FAST_FUNC XZALLOC_CONST_PTR(const void *pptr, size_t size)
13{
14 ASSIGN_CONST_PTR(pptr, xzalloc(size));
15}
16#endif
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 3c87abcf9..9960448ec 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -214,7 +214,7 @@ extern struct lineedit_statics *BB_GLOBAL_CONST lineedit_ptr_to_statics;
214#define delbuf (S.delbuf ) 214#define delbuf (S.delbuf )
215 215
216#define INIT_S() do { \ 216#define INIT_S() do { \
217 ASSIGN_CONST_PTR(lineedit_ptr_to_statics, xzalloc(sizeof(S))); \ 217 XZALLOC_CONST_PTR(&lineedit_ptr_to_statics, sizeof(S)); \
218} while (0) 218} while (0)
219 219
220static void deinit_S(void) 220static void deinit_S(void)