libbb: extend "errno pointer" trick to other than __GLIBC__
Savings on musl: function old new delta resume_main 582 614 +32 lbb_prepare - 20 +20 seq_main 432 449 +17 fgetsetversion 74 88 +14 ... script_main 1207 1180 -27 close_silently 28 - -28 shell_builtin_ulimit 655 626 -29 lineedit_read_key 280 247 -33 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 25/123 up/down: 182/-882) Total: -700 bytes text data bss dec hex filename 1005858 551 5676 1012085 f7175 busybox_old 1005136 551 5680 1011367 f6ea7 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
6561e07460
commit
b1c7a66ca6
@ -339,12 +339,13 @@ struct BUG_off_t_size_is_misdetected {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__GLIBC__)
|
#if defined(errno)
|
||||||
/* glibc uses __errno_location() to get a ptr to errno */
|
/* If errno is a define, assume it's "define errno (*__errno_location())"
|
||||||
/* We can just memorize it once - no multithreading in busybox :) */
|
* and we will cache it's result in this variable */
|
||||||
extern int *const bb_errno;
|
extern int *const bb_errno;
|
||||||
#undef errno
|
#undef errno
|
||||||
#define errno (*bb_errno)
|
#define errno (*bb_errno)
|
||||||
|
#define bb_cached_errno_ptr 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !(ULONG_MAX > 0xffffffff)
|
#if !(ULONG_MAX > 0xffffffff)
|
||||||
|
@ -303,7 +303,7 @@ void lbb_prepare(const char *applet
|
|||||||
void lbb_prepare(const char *applet
|
void lbb_prepare(const char *applet
|
||||||
IF_FEATURE_INDIVIDUAL(, char **argv))
|
IF_FEATURE_INDIVIDUAL(, char **argv))
|
||||||
{
|
{
|
||||||
#ifdef __GLIBC__
|
#ifdef bb_cached_errno_ptr
|
||||||
(*(int **)not_const_pp(&bb_errno)) = __errno_location();
|
(*(int **)not_const_pp(&bb_errno)) = __errno_location();
|
||||||
barrier();
|
barrier();
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,7 +14,7 @@ struct globals;
|
|||||||
* but here we make it live in R/W memory */
|
* but here we make it live in R/W memory */
|
||||||
struct globals *ptr_to_globals;
|
struct globals *ptr_to_globals;
|
||||||
|
|
||||||
#ifdef __GLIBC__
|
#ifdef errno
|
||||||
int *bb_errno;
|
int *bb_errno;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ int *bb_errno;
|
|||||||
* on weird architectures, compilers, linkers and so on */
|
* on weird architectures, compilers, linkers and so on */
|
||||||
struct globals *const ptr_to_globals __attribute__ ((section (".data")));
|
struct globals *const ptr_to_globals __attribute__ ((section (".data")));
|
||||||
|
|
||||||
#ifdef __GLIBC__
|
#ifdef errno
|
||||||
int *const bb_errno __attribute__ ((section (".data")));
|
int *const bb_errno __attribute__ ((section (".data")));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user