← Commit list

b1c7a66ca

Denys Vlasenko
Denys Vlasenko
2020-10-01
SUCCESS Duration: 149s

Subject

libbb: extend "errno pointer" trick to other than __GLIBC__

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

include/libbb.h+4 -3
@@ -339,12 +339,13 @@ struct BUG_off_t_size_is_misdetected {
#endif
#endif
-#if defined(__GLIBC__)
-/* glibc uses __errno_location() to get a ptr to errno */
-/* We can just memorize it once - no multithreading in busybox :) */
+#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;
#undef errno
#define errno (*bb_errno)
+#define bb_cached_errno_ptr 1
#endif
#if !(ULONG_MAX > 0xffffffff)
libbb/appletlib.c+1 -1
@@ -303,7 +303,7 @@ void lbb_prepare(const char *applet
void lbb_prepare(const char *applet
IF_FEATURE_INDIVIDUAL(, char **argv))
{
-#ifdef __GLIBC__
+#ifdef bb_cached_errno_ptr
(*(int **)not_const_pp(&bb_errno)) = __errno_location();
barrier();
#endif
libbb/ptr_to_globals.c+2 -2
@@ -14,7 +14,7 @@ struct globals;
* but here we make it live in R/W memory */
struct globals *ptr_to_globals;
-#ifdef __GLIBC__
+#ifdef errno
int *bb_errno;
#endif
@@ -27,7 +27,7 @@ int *bb_errno;
* on weird architectures, compilers, linkers and so on */
struct globals *const ptr_to_globals __attribute__ ((section (".data")));
-#ifdef __GLIBC__
+#ifdef errno
int *const bb_errno __attribute__ ((section (".data")));
#endif