From 8770fe03d34dd0871862f8c362eec9aa4a5abe13 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 27 Jul 2026 01:35:20 -0500 Subject: [PATCH] Move one more global variable into rodata. --- main.c | 7 ++++++- toys.h | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 1bd4b0d2..41728ae1 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,10 @@ #define NEWTOY(name, opts, flags) {#name, name##_main, OPTSTR_##name, flags}, #define OLDTOY(name, oldname, flags) \ {#name, oldname##_main, OPTSTR_##oldname, flags}, +// sticking "const" on this doesn't help because it's got function pointers +// in its initializer. In theory static binaries should still be able to put +// it in rodata, but neither gcc nor llvm is smart enough to do so, and +// neither static PIE nor fdpic would benefit. struct toy_list toy_list[] = { #include "generated/newtoys.h" }; @@ -20,7 +24,8 @@ struct toy_list toy_list[] = { struct toy_context toys; union global_union this; -char *toybox_version = TOYBOX_VERSION, toybuf[4096], libbuf[4096]; +char toybuf[4096], libbuf[4096]; +const char *toybox_version = TOYBOX_VERSION; struct toy_list *toy_find(char *name) { diff --git a/toys.h b/toys.h index f7de91ba..c313d2ed 100644 --- a/toys.h +++ b/toys.h @@ -129,7 +129,8 @@ extern struct toy_context { // Two big temporary buffers: one for use by commands, one for library functions -extern char **environ, *toybox_version, toybuf[4096], libbuf[4096]; +extern char **environ, toybuf[4096], libbuf[4096]; +extern const char *toybox_version; #define FLAG(x) (!!(toys.optflags&FLAG_##x)) // Return 1 if flag set, 0 if not -- 2.39.5