From 1f925038ab9c6bd8f6b3cd40ed7aab0ef10d898e Mon Sep 17 00:00:00 2001 From: YU Jincheng Date: Wed, 29 Sep 2021 17:37:26 +0800 Subject: *: generalize "const trick" While at it, change all "__asm__" to "asm" Co-authored-by: canyie <31466456+canyie@users.noreply.github.com> Signed-off-by: YU Jincheng Signed-off-by: Denys Vlasenko --- coreutils/test.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'coreutils') diff --git a/coreutils/test.c b/coreutils/test.c index 7c6574334..fc956724b 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 *BB_GLOBAL_CONST test_ptr_to_statics; #define S (*test_ptr_to_statics) #define args (S.args ) @@ -446,8 +446,7 @@ extern struct test_statics *const test_ptr_to_statics; #define leaving (S.leaving ) #define INIT_S() do { \ - (*(struct test_statics**)not_const_pp(&test_ptr_to_statics)) = xzalloc(sizeof(S)); \ - barrier(); \ + ASSIGN_CONST_PTR(test_ptr_to_statics, xzalloc(sizeof(S))); \ } while (0) #define DEINIT_S() do { \ free(group_array); \ -- cgit v1.2.3-55-g6feb From ecac9853f29dcb2e5e0d70c0effaae2cabeefabf Mon Sep 17 00:00:00 2001 From: Andrej Valek Date: Fri, 25 Jun 2021 07:45:35 +0200 Subject: mktemp: add --tmpdir option Make mktemp more compatible with coreutils. - add "--tmpdir" option - add long variants for "d,q,u" options Note: Upstream ca-certificate update script started using this option. function old new delta .rodata 104179 104219 +40 mktemp_main 186 194 +8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 48/0) Total: 48 bytes Signed-off-by: Andrej Valek Signed-off-by: Peter Marko Signed-off-by: Denys Vlasenko --- coreutils/mktemp.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'coreutils') diff --git a/coreutils/mktemp.c b/coreutils/mktemp.c index 5393320a5..33e2720de 100644 --- a/coreutils/mktemp.c +++ b/coreutils/mktemp.c @@ -72,13 +72,27 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) OPT_t = 1 << 2, OPT_p = 1 << 3, OPT_u = 1 << 4, + OPT_tmpdir = (1 << 5) * ENABLE_LONG_OPTS, }; path = getenv("TMPDIR"); if (!path || path[0] == '\0') path = "/tmp"; +#if ENABLE_LONG_OPTS + opts = getopt32long(argv, "^" + "dqtp:u" + "\0" + "?1" /* 1 arg max */, + "directory\0" No_argument "d" + "quiet\0" No_argument "q" + "dry-run\0" No_argument "u" + "tmpdir\0" Optional_argument "\xff" + , &path, &path + ); +#else opts = getopt32(argv, "^" "dqtp:u" "\0" "?1"/*1 arg max*/, &path); +#endif chp = argv[optind]; if (!chp) { @@ -95,7 +109,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) goto error; } #endif - if (opts & (OPT_t|OPT_p)) + if (opts & (OPT_t|OPT_p|OPT_tmpdir)) chp = concat_path_file(path, chp); if (opts & OPT_u) { -- cgit v1.2.3-55-g6feb From 5156b245536ce0f07165793f07c63fd9fa5dd3b7 Mon Sep 17 00:00:00 2001 From: YU Jincheng Date: Sun, 10 Oct 2021 02:19:51 +0800 Subject: 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 Signed-off-by: Denys Vlasenko --- coreutils/test.c | 2 +- include/libbb.h | 21 +++++++++++++++------ libbb/Kbuild.src | 1 + libbb/appletlib.c | 2 +- libbb/const_hack.c | 16 ++++++++++++++++ libbb/lineedit.c | 2 +- shell/ash.c | 6 +++--- 7 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 libbb/const_hack.c (limited to 'coreutils') diff --git a/coreutils/test.c b/coreutils/test.c index fc956724b..a914c7490 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -446,7 +446,7 @@ extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics; #define leaving (S.leaving ) #define INIT_S() do { \ - ASSIGN_CONST_PTR(test_ptr_to_statics, xzalloc(sizeof(S))); \ + XZALLOC_CONST_PTR(&test_ptr_to_statics, sizeof(S)); \ } while (0) #define DEINIT_S() do { \ free(group_array); \ diff --git a/include/libbb.h b/include/libbb.h index 296417dae..a340f27d2 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -2280,6 +2280,7 @@ extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ extern const int const_int_0; //extern const int const_int_1; + /* This struct is deliberately not defined. */ /* See docs/keep_data_small.txt */ struct globals; @@ -2304,23 +2305,31 @@ static ALWAYS_INLINE void* not_const_pp(const void *p) ); return pp; } +# define ASSIGN_CONST_PTR(pptr, v) do { \ + *(void**)not_const_pp(pptr) = (void*)(v); \ + barrier(); \ +} while (0) +/* XZALLOC_CONST_PTR() is an out-of-line function to prevent + * clang from reading pointer before it is assigned. + */ +void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC; #else -static ALWAYS_INLINE void* not_const_pp(const void *p) { return (void*)p; } -#endif - -#define ASSIGN_CONST_PTR(p, v) do { \ - *(void**)not_const_pp(&p) = (void*)(v); \ +# define ASSIGN_CONST_PTR(pptr, v) do { \ + *(void**)(pptr) = (void*)(v); \ /* At least gcc 3.4.6 on mipsel needs optimization barrier */ \ barrier(); \ } while (0) +# define XZALLOC_CONST_PTR(pptr, size) ASSIGN_CONST_PTR(pptr, xzalloc(size)) +#endif -#define SET_PTR_TO_GLOBALS(x) ASSIGN_CONST_PTR(ptr_to_globals, x) +#define SET_PTR_TO_GLOBALS(x) ASSIGN_CONST_PTR(&ptr_to_globals, x) #define FREE_PTR_TO_GLOBALS() do { \ if (ENABLE_FEATURE_CLEAN_UP) { \ free(ptr_to_globals); \ } \ } while (0) + /* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it, * use bb_default_login_shell and following defines. * If you change LIBBB_DEFAULT_LOGIN_SHELL, 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 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 bf26c99e9..e8c308467 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 000000000..9575e6d67 --- /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 + * + * 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 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; #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) diff --git a/shell/ash.c b/shell/ash.c index 199975191..2d3cc8a61 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -504,7 +504,7 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc; #define random_gen (G_misc.random_gen ) #define backgndpid (G_misc.backgndpid ) #define INIT_G_misc() do { \ - ASSIGN_CONST_PTR(ash_ptr_to_globals_misc, xzalloc(sizeof(G_misc))); \ + XZALLOC_CONST_PTR(&ash_ptr_to_globals_misc, sizeof(G_misc)); \ savestatus = -1; \ curdir = nullstr; \ physdir = nullstr; \ @@ -1582,7 +1582,7 @@ extern struct globals_memstack *BB_GLOBAL_CONST ash_ptr_to_globals_memstack; #define g_stacknleft (G_memstack.g_stacknleft) #define stackbase (G_memstack.stackbase ) #define INIT_G_memstack() do { \ - ASSIGN_CONST_PTR(ash_ptr_to_globals_memstack, xzalloc(sizeof(G_memstack))); \ + XZALLOC_CONST_PTR(&ash_ptr_to_globals_memstack, sizeof(G_memstack)); \ g_stackp = &stackbase; \ g_stacknxt = stackbase.space; \ g_stacknleft = MINSIZE; \ @@ -2213,7 +2213,7 @@ extern struct globals_var *BB_GLOBAL_CONST ash_ptr_to_globals_var; #endif #define INIT_G_var() do { \ unsigned i; \ - ASSIGN_CONST_PTR(ash_ptr_to_globals_var, xzalloc(sizeof(G_var))); \ + XZALLOC_CONST_PTR(&ash_ptr_to_globals_var, sizeof(G_var)); \ for (i = 0; i < ARRAY_SIZE(varinit_data); i++) { \ varinit[i].flags = varinit_data[i].flags; \ varinit[i].var_text = varinit_data[i].var_text; \ -- cgit v1.2.3-55-g6feb From 94c78aa0b91f2150bd038866addf3d0ee69474a8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 12 Oct 2021 13:23:29 +0200 Subject: config system: move some options closer to relevalnt tool subdirectories Signed-off-by: Denys Vlasenko --- coreutils/Config.src | 19 ++++-- coreutils/df.c | 20 ++++++ libbb/Config.src | 185 +++++++++++++++++--------------------------------- mailutils/Config.src | 4 +- networking/Config.src | 26 +++++++ procps/Config.src | 9 ++- 6 files changed, 132 insertions(+), 131 deletions(-) (limited to 'coreutils') diff --git a/coreutils/Config.src b/coreutils/Config.src index 1bded03a6..6c9e47551 100644 --- a/coreutils/Config.src +++ b/coreutils/Config.src @@ -5,10 +5,6 @@ menu "Coreutils" -INSERT - -comment "Common options" - config FEATURE_VERBOSE bool "Support verbose options (usually -v) for various applets" default y @@ -17,6 +13,19 @@ config FEATURE_VERBOSE Also enables long option (--verbose) if it exists. Without this option, -v is accepted but ignored. +comment "Common options for date and touch" + +config FEATURE_TIMEZONE + bool "Allow timezone in dates" + default y + depends on DESKTOP + help + Permit the use of timezones when parsing user-provided data + strings, e.g. '1996-04-09 12:45:00 -0500'. + + This requires support for the '%z' extension to strptime() which + may not be available in all implementations. + comment "Common options for cp and mv" depends on CP || MV @@ -37,4 +46,6 @@ config FEATURE_HUMAN_READABLE help Allow df, du, and ls to have human readable output. +INSERT + endmenu diff --git a/coreutils/df.c b/coreutils/df.c index 9f8b3a71e..176aa079f 100644 --- a/coreutils/df.c +++ b/coreutils/df.c @@ -32,6 +32,26 @@ //config: -a Show all filesystems //config: -i Inodes //config: -B Blocksize +//config: +//config:config FEATURE_SKIP_ROOTFS +//config: bool "Skip rootfs in mount table" +//config: default y +//config: depends on DF +//config: help +//config: Ignore rootfs entry in mount table. +//config: +//config: In Linux, kernel has a special filesystem, rootfs, which is initially +//config: mounted on /. It contains initramfs data, if kernel is configured +//config: to have one. Usually, another file system is mounted over / early +//config: in boot process, and therefore most tools which manipulate +//config: mount table, such as df, will skip rootfs entry. +//config: +//config: However, some systems do not mount anything on /. +//config: If you need to configure busybox for one of these systems, +//config: you may find it useful to turn this option off to make df show +//config: initramfs statistics. +//config: +//config: Otherwise, choose Y. //applet:IF_DF(APPLET_NOEXEC(df, df, BB_DIR_BIN, BB_SUID_DROP, df)) diff --git a/libbb/Config.src b/libbb/Config.src index 58c5fad50..24b31fad9 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -61,32 +61,73 @@ config SHA3_SMALL 64-bit x86: +270 bytes of code, 45% faster 32-bit x86: +450 bytes of code, 75% faster -config FEATURE_FAST_TOP - bool "Faster /proc scanning code (+100 bytes)" - default n # all "fast or small" options default to small +config FEATURE_NON_POSIX_CP + bool "Non-POSIX, but safer, copying to special nodes" + default y help - This option makes top and ps ~20% faster (or 20% less CPU hungry), - but code size is slightly bigger. + With this option, "cp file symlink" will delete symlink + and create a regular file. This does not conform to POSIX, + but prevents a symlink attack. + Similarly, "cp file device" will not send file's data + to the device. (To do that, use "cat file >device") -config FEATURE_ETC_NETWORKS - bool "Support /etc/networks" +config FEATURE_VERBOSE_CP_MESSAGE + bool "Give more precise messages when copy fails (cp, mv etc)" default n help - Enable support for network names in /etc/networks. This is - a rarely used feature which allows you to use names - instead of IP/mask pairs in route command. + Error messages with this feature enabled: -config FEATURE_ETC_SERVICES - bool "Consult /etc/services even for well-known ports" - default n + $ cp file /does_not_exist/file + cp: cannot create '/does_not_exist/file': Path does not exist + $ cp file /vmlinuz/file + cp: cannot stat '/vmlinuz/file': Path has non-directory component + + If this feature is not enabled, they will be, respectively: + + cp: cannot create '/does_not_exist/file': No such file or directory + cp: cannot stat '/vmlinuz/file': Not a directory + + This will cost you ~60 bytes. + +config FEATURE_USE_SENDFILE + bool "Use sendfile system call" + default y + help + When enabled, busybox will use the kernel sendfile() function + instead of read/write loops to copy data between file descriptors + (for example, cp command does this a lot). + If sendfile() doesn't work, copying code falls back to read/write + loop. sendfile() was originally implemented for faster I/O + from files to sockets, but since Linux 2.6.33 it was extended + to work for many more file types. + +config FEATURE_COPYBUF_KB + int "Copy buffer size, in kilobytes" + range 1 1024 + default 4 + help + Size of buffer used by cp, mv, install, wget etc. + Buffers which are 4 kb or less will be allocated on stack. + Bigger buffers will be allocated with mmap, with fallback to 4 kb + stack buffer if mmap fails. + +config MONOTONIC_SYSCALL + bool "Use clock_gettime(CLOCK_MONOTONIC) syscall" + default y + help + Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring + time intervals (time, ping, traceroute etc need this). + Probably requires Linux 2.6+. If not selected, gettimeofday + will be used instead (which gives wrong results if date/time + is reset). + +config IOCTL_HEX2STR_ERROR + bool "Use ioctl names rather than hex values in error messages" + default y help - Look up e.g. "telnet" and "http" in /etc/services file - instead of assuming ports 23 and 80. - This is almost never necessary (everybody uses standard ports), - and it makes sense to avoid reading this file. - If you disable this option, in the cases where port is explicitly - specified as a service name (e.g. "telnet HOST PORTNAME"), - it will still be looked up in /etc/services. + Use ioctl names rather than hex values in error messages + (e.g. VT_DISALLOCATE rather than 0x5608). If disabled this + saves about 1400 bytes. config FEATURE_EDITING bool "Command line editing" @@ -302,107 +343,3 @@ config UNICODE_PRESERVE_BROKEN For example, this means that entering 'l', 's', ' ', 0xff, [Enter] at shell prompt will list file named 0xff (single char name with char value 255), not file named '?'. - -config FEATURE_NON_POSIX_CP - bool "Non-POSIX, but safer, copying to special nodes" - default y - help - With this option, "cp file symlink" will delete symlink - and create a regular file. This does not conform to POSIX, - but prevents a symlink attack. - Similarly, "cp file device" will not send file's data - to the device. (To do that, use "cat file >device") - -config FEATURE_VERBOSE_CP_MESSAGE - bool "Give more precise messages when copy fails (cp, mv etc)" - default n - help - Error messages with this feature enabled: - - $ cp file /does_not_exist/file - cp: cannot create '/does_not_exist/file': Path does not exist - $ cp file /vmlinuz/file - cp: cannot stat '/vmlinuz/file': Path has non-directory component - - If this feature is not enabled, they will be, respectively: - - cp: cannot create '/does_not_exist/file': No such file or directory - cp: cannot stat '/vmlinuz/file': Not a directory - - This will cost you ~60 bytes. - -config FEATURE_USE_SENDFILE - bool "Use sendfile system call" - default y - help - When enabled, busybox will use the kernel sendfile() function - instead of read/write loops to copy data between file descriptors - (for example, cp command does this a lot). - If sendfile() doesn't work, copying code falls back to read/write - loop. sendfile() was originally implemented for faster I/O - from files to sockets, but since Linux 2.6.33 it was extended - to work for many more file types. - -config FEATURE_COPYBUF_KB - int "Copy buffer size, in kilobytes" - range 1 1024 - default 4 - help - Size of buffer used by cp, mv, install, wget etc. - Buffers which are 4 kb or less will be allocated on stack. - Bigger buffers will be allocated with mmap, with fallback to 4 kb - stack buffer if mmap fails. - -config FEATURE_SKIP_ROOTFS - bool "Skip rootfs in mount table" - default y - help - Ignore rootfs entry in mount table. - - In Linux, kernel has a special filesystem, rootfs, which is initially - mounted on /. It contains initramfs data, if kernel is configured - to have one. Usually, another file system is mounted over / early - in boot process, and therefore most tools which manipulate - mount table, such as df, will skip rootfs entry. - - However, some systems do not mount anything on /. - If you need to configure busybox for one of these systems, - you may find it useful to turn this option off to make df show - initramfs statistics. - - Otherwise, choose Y. - -config MONOTONIC_SYSCALL - bool "Use clock_gettime(CLOCK_MONOTONIC) syscall" - default y - help - Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring - time intervals (time, ping, traceroute etc need this). - Probably requires Linux 2.6+. If not selected, gettimeofday - will be used instead (which gives wrong results if date/time - is reset). - -config IOCTL_HEX2STR_ERROR - bool "Use ioctl names rather than hex values in error messages" - default y - help - Use ioctl names rather than hex values in error messages - (e.g. VT_DISALLOCATE rather than 0x5608). If disabled this - saves about 1400 bytes. - -config FEATURE_HWIB - bool "Support infiniband HW" - default y - help - Support for printing infiniband addresses in network applets. - -config FEATURE_TIMEZONE - bool "Allow timezone in dates" - default y - depends on DESKTOP - help - Permit the use of timezones when parsing user-provided data - strings, e.g. '1996-04-09 12:45:00 -0500'. - - This requires support for the '%z' extension to strptime() which - may not be available in all implementations. diff --git a/mailutils/Config.src b/mailutils/Config.src index 6d47163e4..b3a3e506d 100644 --- a/mailutils/Config.src +++ b/mailutils/Config.src @@ -1,7 +1,5 @@ menu "Mail Utilities" -INSERT - config FEATURE_MIME_CHARSET string "Default charset" default "us-ascii" @@ -9,4 +7,6 @@ config FEATURE_MIME_CHARSET help Default charset of the message. +INSERT + endmenu diff --git a/networking/Config.src b/networking/Config.src index 04d644bc9..0942645c3 100644 --- a/networking/Config.src +++ b/networking/Config.src @@ -46,6 +46,32 @@ config VERBOSE_RESOLUTION_ERRORS "can't resolve 'hostname.com'" and want to know more. This may increase size of your executable a bit. +config FEATURE_ETC_NETWORKS + bool "Support /etc/networks" + default n + help + Enable support for network names in /etc/networks. This is + a rarely used feature which allows you to use names + instead of IP/mask pairs in route command. + +config FEATURE_ETC_SERVICES + bool "Consult /etc/services even for well-known ports" + default n + help + Look up e.g. "telnet" and "http" in /etc/services file + instead of assuming ports 23 and 80. + This is almost never necessary (everybody uses standard ports), + and it makes sense to avoid reading this file. + If you disable this option, in the cases where port is explicitly + specified as a service name (e.g. "telnet HOST PORTNAME"), + it will still be looked up in /etc/services. + +config FEATURE_HWIB + bool "Support infiniband HW" + default y + help + Support for printing infiniband addresses in network applets. + config FEATURE_TLS_SHA1 bool "In TLS code, support ciphers which use deprecated SHA1" depends on TLS diff --git a/procps/Config.src b/procps/Config.src index 2b1b8ab11..7fcce98c5 100644 --- a/procps/Config.src +++ b/procps/Config.src @@ -5,7 +5,12 @@ menu "Process Utilities" -INSERT +config FEATURE_FAST_TOP + bool "Faster /proc scanning code (+100 bytes)" + default n # all "fast or small" options default to small + help + This option makes top and ps ~20% faster (or 20% less CPU hungry), + but code size is slightly bigger. config FEATURE_SHOW_THREADS bool "Support thread display in ps/pstree/top" @@ -15,4 +20,6 @@ config FEATURE_SHOW_THREADS Enables the ps -T option, showing of threads in pstree, and 'h' command in top. +INSERT + endmenu -- cgit v1.2.3-55-g6feb