← Commit list

43982ed49

Denys Vlasenko
Denys Vlasenko
2026-01-24
SUCCESS Duration: 142s

Subject

httpd: code shrink via "split-globals" trick

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
gcc -Wp,-MD,applets/.usage.d -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer      -Iinclude -Iinclude -o applets/usage applets/usage.c

Build Log

(log yok)

Commit Diff GitHub →

include/libbb.h+15 -0
@@ -457,6 +457,11 @@ void *xmmap_anon(size_t size) FAST_FUNC;
//sparc64,alpha,openrisc: fixed 8k pages
#endif
+#if defined(__x86_64__) || defined(i386)
+/* 0x7f would be better, but it causes alignment problems */
+# define ARCH_GLOBAL_PTR_OFF 0x80
+#endif
+
#if defined BB_ARCH_FIXED_PAGESIZE
# define IF_VARIABLE_ARCH_PAGESIZE(...) /*nothing*/
# define bb_getpagesize() BB_ARCH_FIXED_PAGESIZE
@@ -2423,6 +2428,16 @@ void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC;
} \
} while (0)
+#if defined(ARCH_GLOBAL_PTR_OFF)
+# define SET_OFFSET_PTR_TO_GLOBALS(x) \
+ ASSIGN_CONST_PTR(&ptr_to_globals, (char*)(x) + ARCH_GLOBAL_PTR_OFF)
+# define OFFSET_PTR_TO_GLOBALS \
+ ((struct globals*)((char*)ptr_to_globals - ARCH_GLOBAL_PTR_OFF))
+#else
+# define SET_OFFSET_PTR_TO_GLOBALS(x) SET_PTR_TO_GLOBALS(x)
+# define OFFSET_PTR_TO_GLOBALS ptr_to_globals
+#endif
+
/* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it,
* use bb_default_login_shell and following defines.
networking/httpd.c+3 -3
@@ -484,7 +484,6 @@ static const struct {
};
struct globals {
- int verbose; /* must be int (used by getopt32) */
smallint flg_deny_all;
#if ENABLE_FEATURE_HTTPD_GZIP
/* client can handle gzip / we are going to send gzip */
@@ -494,6 +493,7 @@ struct globals {
#if ENABLE_FEATURE_HTTPD_CGI
smallint cgi_output;
#endif
+ int verbose; /* must be int (used by getopt32) */
time_t last_mod;
#if ENABLE_FEATURE_HTTPD_ETAG
char *if_none_match;
@@ -555,7 +555,7 @@ struct globals {
#endif
char iobuf[IOBUF_SIZE] ALIGN8;
};
-#define G (*ptr_to_globals)
+#define G (*OFFSET_PTR_TO_GLOBALS)
#define verbose (G.verbose )
#define flg_deny_all (G.flg_deny_all )
#if ENABLE_FEATURE_HTTPD_GZIP
@@ -598,7 +598,7 @@ enum {
#define iobuf (G.iobuf )
#define INIT_G() do { \
setup_common_bufsiz(); \
- SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
+ SET_OFFSET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \
IF_FEATURE_HTTPD_RANGES(range_start = -1;) \
bind_addr_or_port = STR(CONFIG_FEATURE_HTTPD_PORT_DEFAULT); \