Created
January 19, 2017 05:58
-
-
Save xc-racer99/865d83f172ec2abd339d5917fefc771d to your computer and use it in GitHub Desktop.
Patches for static busybox replacement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From f742a1d8c388d03060ef23acea6c201e8b02f1f4 Mon Sep 17 00:00:00 2001 | |
From: Adrian DC <[email protected]> | |
Date: Fri, 26 Aug 2016 04:37:24 +0200 | |
Subject: [PATCH] libselinux: Fully libcrypto_static include in static library | |
* Solves external/libselinux/./src/android.c:999: | |
error: undefined reference to 'SHA1' for toybox_static | |
Change-Id: I323d818283110b9ca1ea9cefaa72f4e5320e3a19 | |
--- | |
Android.mk | 3 +-- | |
1 file changed, 1 insertion(+), 2 deletions(-) | |
diff --git a/Android.mk b/Android.mk | |
index 659232e..e25a499 100644 | |
--- a/Android.mk | |
+++ b/Android.mk | |
@@ -45,9 +45,8 @@ include $(CLEAR_VARS) | |
LOCAL_SRC_FILES := $(common_SRC_FILES) $(common_HOST_FILES) src/android.c | |
LOCAL_MODULE:= libselinux | |
LOCAL_MODULE_TAGS := eng | |
-LOCAL_STATIC_LIBRARIES := libcrypto_static | |
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include | |
-LOCAL_WHOLE_STATIC_LIBRARIES := libpcre libpackagelistparser | |
+LOCAL_WHOLE_STATIC_LIBRARIES := libcrypto_static libpcre libpackagelistparser | |
# 1003 corresponds to auditd, from system/core/logd/event.logtags | |
LOCAL_CFLAGS := -DAUDITD_LOG_TAG=1003 | |
# mapping.c has redundant check of array p_in->perms. | |
-- | |
2.7.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 8d36c7aa1e7a09a4678be789f9c74c0efc87215e Mon Sep 17 00:00:00 2001 | |
From: xc-racer99 <[email protected]> | |
Date: Sun, 15 Jan 2017 14:45:04 -0800 | |
Subject: [PATCH] Add a static utility build | |
For use in /tmp/sh - needed for updater.sh | |
--- | |
Android.mk | 104 ++++++++++++++++++++++++++++++++++++++++++++----------------- | |
1 file changed, 76 insertions(+), 28 deletions(-) | |
diff --git a/Android.mk b/Android.mk | |
index 12f3c83..2467b86 100644 | |
--- a/Android.mk | |
+++ b/Android.mk | |
@@ -15,41 +15,15 @@ LOCAL_MODULE_PATH := $(TARGET_OUT)/etc | |
LOCAL_SRC_FILES := $(LOCAL_MODULE) | |
include $(BUILD_PREBUILT) | |
- | |
-# /system/bin/sh | |
- | |
-include $(CLEAR_VARS) | |
- | |
-LOCAL_MODULE := sh | |
-LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk | |
- | |
-# mksh source files | |
-LOCAL_SRC_FILES := \ | |
- src/lalloc.c src/edit.c src/eval.c src/exec.c \ | |
- src/expr.c src/funcs.c src/histrap.c src/jobs.c \ | |
- src/lex.c src/main.c src/misc.c src/shf.c \ | |
- src/syn.c src/tree.c src/var.c | |
- | |
-LOCAL_SYSTEM_SHARED_LIBRARIES := libc | |
- | |
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/src | |
- | |
-# Additional flags first... | |
-LOCAL_CFLAGS += \ | |
- -DMKSH_DEFAULT_PROFILEDIR=\"/system/etc\" \ | |
- -DMKSHRC_PATH=\"/system/etc/mkshrc\" \ | |
- -DMKSH_DEFAULT_EXECSHELL=\"/system/bin/sh\" \ | |
- -DMKSH_DEFAULT_TMPDIR=\"/data/local\" \ | |
- | |
# ...then from Makefrag.inc: CFLAGS... | |
-LOCAL_CFLAGS += \ | |
+mksh_cflags += \ | |
-Wno-deprecated-declarations \ | |
-fno-asynchronous-unwind-tables \ | |
-fno-strict-aliasing \ | |
-fstack-protector -fwrapv \ | |
# ...and CPPFLAGS. | |
-LOCAL_CFLAGS += \ | |
+mksh_cflags += \ | |
-DDEBUG_LEAKS -DMKSH_ASSUME_UTF8 -DMKSH_CONSERVATIVE_FDS \ | |
-DMKSH_DONT_EMIT_IDSTRING -DMKSH_NOPWNAM -DMKSH_BUILDSH \ | |
-D_GNU_SOURCE -DSETUID_CAN_FAIL_WITH_EAGAIN \ | |
@@ -82,4 +56,78 @@ LOCAL_CFLAGS += \ | |
-DHAVE_SYS_ERRLIST_DECL=0 -DHAVE_SYS_SIGLIST_DECL=1 \ | |
-DHAVE_PERSISTENT_HISTORY=0 -DMKSH_BUILD_R=521 | |
+ | |
+# /system/bin/sh | |
+ | |
+include $(CLEAR_VARS) | |
+ | |
+LOCAL_MODULE := sh | |
+LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk | |
+ | |
+# mksh source files | |
+LOCAL_SRC_FILES := \ | |
+ src/lalloc.c src/edit.c src/eval.c src/exec.c \ | |
+ src/expr.c src/funcs.c src/histrap.c src/jobs.c \ | |
+ src/lex.c src/main.c src/misc.c src/shf.c \ | |
+ src/syn.c src/tree.c src/var.c | |
+ | |
+LOCAL_SYSTEM_SHARED_LIBRARIES := libc | |
+ | |
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/src | |
+ | |
+# Additional flags first... | |
+LOCAL_CFLAGS += \ | |
+ -DMKSH_DEFAULT_PROFILEDIR=\"/system/etc\" \ | |
+ -DMKSHRC_PATH=\"/system/etc/mkshrc\" \ | |
+ -DMKSH_DEFAULT_EXECSHELL=\"/system/bin/sh\" \ | |
+ -DMKSH_DEFAULT_TMPDIR=\"/data/local\" \ | |
+ | |
+# Add common flags | |
+LOCAL_CFLAGS += $(mksh_cflags) | |
+ | |
+include $(BUILD_EXECUTABLE) | |
+ | |
+# Common flags for static library and executable | |
+mksh_static_cflags += \ | |
+ -DMKSH_DEFAULT_PROFILEDIR=\"/tmp\" \ | |
+ -DMKSHRC_PATH=\"/tmp/mkshrc\" \ | |
+ -DMKSH_DEFAULT_EXECSHELL=\"/tmp/sh\" \ | |
+ -DMKSH_DEFAULT_TMPDIR=\"/tmp\" \ | |
+ | |
+# Add common flags | |
+mksh_static_cflags += $(mksh_cflags) | |
+ | |
+# static library | |
+include $(CLEAR_VARS) | |
+ | |
+LOCAL_MODULE := libmksh | |
+LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/Android.mk | |
+ | |
+# mksh source files | |
+LOCAL_SRC_FILES := \ | |
+ src/lalloc.c src/edit.c src/eval.c src/exec.c \ | |
+ src/expr.c src/funcs.c src/histrap.c src/jobs.c \ | |
+ src/lex.c src/misc.c src/shf.c \ | |
+ src/syn.c src/tree.c src/var.c | |
+ | |
+LOCAL_STATIC_LIBRARIES := libc | |
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/src | |
+LOCAL_CFLAGS := $(mksh_static_cflags) | |
+ | |
+include $(BUILD_STATIC_LIBRARY) | |
+ | |
+# /tmp/sh - static utility executable | |
+include $(CLEAR_VARS) | |
+LOCAL_SRC_FILES := src/main.c | |
+LOCAL_MODULE := utility_mksh | |
+LOCAL_MODULE_TAGS := optional | |
+LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES | |
+LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities | |
+LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities | |
+LOCAL_MODULE_STEM := sh | |
+LOCAL_STATIC_LIBRARIES := libmksh libc | |
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/src | |
+LOCAL_CFLAGS := $(mksh_static_cflags) | |
+LOCAL_FORCE_STATIC_EXECUTABLE := true | |
+LOCAL_PACK_MODULE_RELOCATIONS := false | |
include $(BUILD_EXECUTABLE) | |
-- | |
2.7.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From acf74b4411cfb28fe7748fe15c31ee06249af3b1 Mon Sep 17 00:00:00 2001 | |
From: Rob Landley <[email protected]> | |
Date: Fri, 8 Apr 2016 18:25:59 -0500 | |
Subject: [PATCH 1/4] Redefining basename_r to mean something random seems | |
popular (bionic and freebsd both did it) so use getbasename instead. | |
--- | |
lib/lib.c | 5 ++++- | |
lib/lib.h | 2 +- | |
lib/portability.h | 10 +--------- | |
toys/pending/modprobe.c | 2 +- | |
toys/pending/netstat.c | 2 +- | |
5 files changed, 8 insertions(+), 13 deletions(-) | |
diff --git a/lib/lib.c b/lib/lib.c | |
index 43db2e3..c6e3d80 100644 | |
--- a/lib/lib.c | |
+++ b/lib/lib.c | |
@@ -906,11 +906,14 @@ void mode_to_string(mode_t mode, char *buf) | |
*buf = c; | |
} | |
-char *basename_r(char *name) | |
+// basename() can modify its argument or return a pointer to a constant string | |
+// This just gives after the last '/' or the whole stirng if no / | |
+char *getbasename(char *name) | |
{ | |
char *s = strrchr(name, '/'); | |
if (s) return s+1; | |
+ | |
return name; | |
} | |
diff --git a/lib/lib.h b/lib/lib.h | |
index dac3b67..cac227f 100644 | |
--- a/lib/lib.h | |
+++ b/lib/lib.h | |
@@ -277,7 +277,7 @@ char *num_to_sig(int sig); | |
mode_t string_to_mode(char *mode_str, mode_t base); | |
void mode_to_string(mode_t mode, char *buf); | |
-char *basename_r(char *name); | |
+char *getbasename(char *name); | |
void names_to_pid(char **names, int (*callback)(pid_t pid, char *name)); | |
pid_t xvforkwrap(pid_t pid); | |
diff --git a/lib/portability.h b/lib/portability.h | |
index d0d0bd9..38230e1 100644 | |
--- a/lib/portability.h | |
+++ b/lib/portability.h | |
@@ -154,19 +154,11 @@ int utimensat(int fd, const char *path, const struct timespec times[2], int flag | |
#endif // glibc in general | |
-#if !defined(__GLIBC__) && !defined(__BIONIC__) | |
+#if !defined(__GLIBC__) | |
// POSIX basename. | |
#include <libgen.h> | |
#endif | |
-// glibc was handled above; for 32-bit bionic we need to avoid a collision | |
-// with toybox's basename_r so we can't include <libgen.h> even though that | |
-// would give us a POSIX basename(3). | |
-#if defined(__BIONIC__) | |
-char *basename(char *path); | |
-char *dirname(char *path); | |
-#endif | |
- | |
// Work out how to do endianness | |
#ifndef __APPLE__ | |
diff --git a/toys/pending/modprobe.c b/toys/pending/modprobe.c | |
index 6813dec..7a35c18 100644 | |
--- a/toys/pending/modprobe.c | |
+++ b/toys/pending/modprobe.c | |
@@ -70,7 +70,7 @@ static char *path2mod(char *file, char *mod) | |
if (!file) return NULL; | |
if (!mod) mod = xmalloc(MODNAME_LEN); | |
- from = basename_r(file); | |
+ from = getbasename(file); | |
for (i = 0; i < (MODNAME_LEN-1) && from[i] && from[i] != '.'; i++) | |
mod[i] = (from[i] == '-') ? '_' : from[i]; | |
diff --git a/toys/pending/netstat.c b/toys/pending/netstat.c | |
index d6acd7a..02ab4fc 100644 | |
--- a/toys/pending/netstat.c | |
+++ b/toys/pending/netstat.c | |
@@ -440,7 +440,7 @@ static void scan_pid(int pid) | |
if ((p = strchr(line, ' '))) *p = 0; // "/bin/netstat -ntp" -> "/bin/netstat" | |
snprintf(TT.current_name, sizeof(TT.current_name), "%d/%s", | |
- pid, basename_r(line)); // "584/netstat" | |
+ pid, getbasename(line)); // "584/netstat" | |
free(line); | |
fd_dir = xmprintf("/proc/%d/fd", pid); | |
-- | |
2.7.4 | |
From e9bee55abae1854a39373ed7fecec4dbb6e56ccd Mon Sep 17 00:00:00 2001 | |
From: xc-racer99 <[email protected]> | |
Date: Sat, 14 Jan 2017 19:05:51 -0800 | |
Subject: [PATCH 2/4] Convert some more basename_r to getbasename | |
--- | |
lib/lib.c | 2 +- | |
main.c | 2 +- | |
2 files changed, 2 insertions(+), 2 deletions(-) | |
diff --git a/lib/lib.c b/lib/lib.c | |
index c6e3d80..b99c2d7 100644 | |
--- a/lib/lib.c | |
+++ b/lib/lib.c | |
@@ -935,7 +935,7 @@ void names_to_pid(char **names, int (*callback)(pid_t pid, char *name)) | |
for (curname = names; *curname; curname++) | |
if (**curname == '/' ? !strcmp(cmd, *curname) | |
- : !strcmp(basename_r(cmd), basename_r(*curname))) | |
+ : !strcmp(getbasename(cmd), getbasename(*curname))) | |
if (callback(u, *curname)) break; | |
if (*curname) break; | |
} | |
diff --git a/main.c b/main.c | |
index cf82872..9c70c96 100644 | |
--- a/main.c | |
+++ b/main.c | |
@@ -202,7 +202,7 @@ int main(int argc, char *argv[]) | |
toys.stacktop = &stack; | |
} | |
- *argv = basename_r(*argv); | |
+ *argv = getbasename(*argv); | |
// If nommu can't fork, special reentry path. | |
// Use !stacktop to signal "vfork happened", both before and after xexec() | |
-- | |
2.7.4 | |
From dccab5aadca1c62b75bb82175c0617907b6be4d1 Mon Sep 17 00:00:00 2001 | |
From: Alistair Strachan <[email protected]> | |
Date: Thu, 5 May 2016 16:11:35 -0700 | |
Subject: [PATCH 3/4] Fix static linkage of toybox binary. | |
If toybox was compiled statically e.g. for use in a recovery ramdisk, | |
it would not build after b66a29a. This is because libselinux already | |
exports a selinux_log_callback() function which getprop.c is trying | |
to override. | |
This change simply makes the second symbol static, since it is only | |
used in a function table so we do not actually need to export it | |
from toybox. | |
Change-Id: I603258877ae2286660df35738bbf4f4285df5b54 | |
Signed-off-by: Alistair Strachan <[email protected]> | |
--- | |
toys/android/getprop.c | 5 +++-- | |
1 file changed, 3 insertions(+), 2 deletions(-) | |
diff --git a/toys/android/getprop.c b/toys/android/getprop.c | |
index efb1e44..9675d9f 100644 | |
--- a/toys/android/getprop.c | |
+++ b/toys/android/getprop.c | |
@@ -54,7 +54,8 @@ static void add_property(char *name, char *value, void *unused) | |
} | |
// Needed to supress extraneous "Loaded property_contexts from" message | |
-int selinux_log_callback(int type, const char *fmt, ...) { | |
+static int selinux_log_callback_local(int type, const char *fmt, ...) | |
+{ | |
va_list ap; | |
if (type == SELINUX_INFO) return 0; | |
@@ -69,7 +70,7 @@ void getprop_main(void) | |
if (toys.optflags & FLAG_Z) { | |
union selinux_callback cb; | |
- cb.func_log = selinux_log_callback; | |
+ cb.func_log = selinux_log_callback_local; | |
selinux_set_callback(SELINUX_CB_LOG, cb); | |
TT.handle = selinux_android_prop_context_handle(); | |
if (!TT.handle) error_exit("unable to get selinux property context handle"); | |
-- | |
2.7.4 | |
From c69b341a7e7fb0a8ee8adb548a851b899b1736e5 Mon Sep 17 00:00:00 2001 | |
From: xc-racer99 <[email protected]> | |
Date: Sat, 14 Jan 2017 19:35:56 -0800 | |
Subject: [PATCH 4/4] Add static toybox build | |
Based off of https://github.com/omnirom/android_external_toybox/commit/6f49c8242e84272a11eb78b8f0eedc30fbea23ec | |
--- | |
Android.mk | 60 ++++++++++++++++++++++++++++++++++++++++++------------------ | |
1 file changed, 42 insertions(+), 18 deletions(-) | |
diff --git a/Android.mk b/Android.mk | |
index 6e8c26f..a31f6ef 100644 | |
--- a/Android.mk | |
+++ b/Android.mk | |
@@ -45,6 +45,24 @@ LOCAL_PATH := $(call my-dir) | |
# # If you just want to use it as "toybox x" rather than "x", you can stop now. | |
# # If you want this toy to have a symbolic link in /system/bin, add the toy to ALL_TOOLS. | |
+toybox_cflags += \ | |
+ -std=c99 \ | |
+ -Os \ | |
+ -Wno-char-subscripts \ | |
+ -Wno-sign-compare \ | |
+ -Wno-string-plus-int \ | |
+ -Wno-uninitialized \ | |
+ -Wno-unused-parameter \ | |
+ -funsigned-char \ | |
+ -ffunction-sections -fdata-sections \ | |
+ -fno-asynchronous-unwind-tables \ | |
+ | |
+toybox_upstream_version := $(shell awk 'match($$0, /TOYBOX_VERSION.*"(.*)"/, ary) {print ary[1]}' $(LOCAL_PATH)/main.c) | |
+toybox_sha := $(shell git -C $(LOCAL_PATH) rev-parse --short=12 HEAD 2>/dev/null) | |
+ | |
+toybox_version := $(toybox_upstream_version)-$(toybox_sha)-android | |
+toybox_cflags += -DTOYBOX_VERSION='"$(toybox_version)"' | |
+ | |
include $(CLEAR_VARS) | |
LOCAL_SRC_FILES := \ | |
@@ -201,24 +219,6 @@ LOCAL_SRC_FILES := \ | |
toys/posix/wc.c \ | |
toys/posix/xargs.c \ | |
-LOCAL_CFLAGS += \ | |
- -std=c99 \ | |
- -Os \ | |
- -Wno-char-subscripts \ | |
- -Wno-sign-compare \ | |
- -Wno-string-plus-int \ | |
- -Wno-uninitialized \ | |
- -Wno-unused-parameter \ | |
- -funsigned-char \ | |
- -ffunction-sections -fdata-sections \ | |
- -fno-asynchronous-unwind-tables \ | |
- | |
-toybox_upstream_version := $(shell awk 'match($$0, /TOYBOX_VERSION.*"(.*)"/, ary) {print ary[1]}' $(LOCAL_PATH)/main.c) | |
-toybox_sha := $(shell git -C $(LOCAL_PATH) rev-parse --short=12 HEAD 2>/dev/null) | |
- | |
-toybox_version := $(toybox_upstream_version)-$(toybox_sha)-android | |
-LOCAL_CFLAGS += -DTOYBOX_VERSION='"$(toybox_version)"' | |
- | |
LOCAL_CLANG := true | |
LOCAL_SHARED_LIBRARIES := libcutils libselinux | |
@@ -227,6 +227,16 @@ LOCAL_SHARED_LIBRARIES := libcutils libselinux | |
# because libnetd_client.so is C++. | |
LOCAL_CXX_STL := none | |
+LOCAL_CFLAGS := $(toybox_cflags) | |
+LOCAL_MODULE := libtoybox | |
+include $(BUILD_STATIC_LIBRARY) | |
+ | |
+include $(CLEAR_VARS) | |
+LOCAL_SRC_FILES := main.c | |
+LOCAL_CFLAGS := $(toybox_cflags) | |
+LOCAL_STATIC_LIBRARIES := libtoybox | |
+LOCAL_SHARED_LIBRARIES := libcutils libselinux | |
+LOCAL_CXX_STL := none | |
LOCAL_MODULE := toybox | |
# dupes: dd | |
@@ -371,3 +381,17 @@ ALL_TOOLS := \ | |
LOCAL_POST_INSTALL_CMD := $(hide) $(foreach t,$(ALL_TOOLS),ln -sf toybox $(TARGET_OUT)/bin/$(t);) | |
include $(BUILD_EXECUTABLE) | |
+ | |
+include $(CLEAR_VARS) | |
+LOCAL_SRC_FILES := main.c | |
+LOCAL_CFLAGS := $(toybox_cflags) | |
+LOCAL_MODULE := toybox_static | |
+LOCAL_MODULE_TAGS := optional | |
+LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES | |
+LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities | |
+LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities | |
+LOCAL_MODULE_STEM := toybox | |
+LOCAL_FORCE_STATIC_EXECUTABLE := true | |
+LOCAL_PACK_MODULE_RELOCATIONS := false | |
+LOCAL_STATIC_LIBRARIES := libtoybox libcutils libselinux liblog | |
+include $(BUILD_EXECUTABLE) | |
-- | |
2.7.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment