From cb7b4fadaaa220075603c9c63860e22ff7ebcac1 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 4 Jan 2016 13:09:19 -0800 Subject: [PATCH] Drop to android-9 platform using -fno-PIE wrapper. --- Makefile.am | 25 +++++++++-- Makefile.in | 114 ++++++++++++++++++++++++++++++--------------------- android.sh | 2 - build.mk | 7 ++++ configure | 37 +++++++++++++++++ configure.ac | 12 ++++++ pie.c | 56 +++++++++++++++++++++++++ 7 files changed, 201 insertions(+), 52 deletions(-) create mode 100644 pie.c diff --git a/Makefile.am b/Makefile.am index d61a4d8..b80bb1e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -28,10 +28,21 @@ ACLOCAL_AMFLAGS = -I m4 AM_CPPFLAGS = -DYYDEBUG=1 -DCY_SYSTEM="\"$(CY_SYSTEM)\"" AM_CPPFLAGS += -include config.h -include $(srcdir)/unconfig.h -AM_CFLAGS = -fvisibility=hidden -AM_CXXFLAGS = -fvisibility=hidden -AM_OBJCXXFLAGS = -fvisibility=hidden -AM_LDFLAGS = -fvisibility=hidden +CY_FLAGS = +CY_FLAGS += -fvisibility=hidden + +if CY_ANDROID +CY_FLAGS += -fPIE +endif + +AM_CFLAGS = $(CY_FLAGS) +AM_CXXFLAGS = $(CY_FLAGS) +AM_OBJCXXFLAGS = $(CY_FLAGS) +AM_LDFLAGS = $(CY_FLAGS) + +if CY_ANDROID +AM_LDFLAGS += -rdynamic -fPIE -pie +endif AM_OBJCXXFLAGS += -fobjc-exceptions @@ -56,6 +67,12 @@ bin_PROGRAMS = cycript cycript_SOURCES = Console.cpp cycript_LDADD = libcycript.la $(LTLIBREADLINE) $(LTLIBTERMCAP) $(LTLIBGCC) $(PTHREAD_CFLAGS) -ldl libcycript_la_SOURCES += Complete.cpp + +if CY_ANDROID +bin_PROGRAMS += cycript-pie +cycript_pie_SOURCES = pie.c +cycript_pie_LDFLAGS = -fno-PIE +endif endif if CY_EXECUTE diff --git a/Makefile.in b/Makefile.in index 1464d04..d9892a2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -109,17 +109,20 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -@CY_CONSOLE_TRUE@bin_PROGRAMS = cycript$(EXEEXT) -@CY_CONSOLE_TRUE@am__append_1 = Complete.cpp -@CY_EXECUTE_TRUE@am__append_2 = sig/ffi_type.cpp sig/parse.cpp \ +@CY_ANDROID_TRUE@am__append_1 = -fPIE +@CY_ANDROID_TRUE@am__append_2 = -rdynamic -fPIE -pie +@CY_CONSOLE_TRUE@bin_PROGRAMS = cycript$(EXEEXT) $(am__EXEEXT_1) +@CY_CONSOLE_TRUE@am__append_3 = Complete.cpp +@CY_ANDROID_TRUE@@CY_CONSOLE_TRUE@am__append_4 = cycript-pie +@CY_EXECUTE_TRUE@am__append_5 = sig/ffi_type.cpp sig/parse.cpp \ @CY_EXECUTE_TRUE@ sig/copy.cpp Execute.cpp JavaScriptCore.cpp -@CY_EXECUTE_TRUE@am__append_3 = $(LTJAVASCRIPTCORE) -@CY_EXECUTE_TRUE@am__append_4 = libcycript.db -@CY_EXECUTE_TRUE@am__append_5 = -DCY_EXECUTE -@CY_EXECUTE_TRUE@am__append_6 = C +@CY_EXECUTE_TRUE@am__append_6 = $(LTJAVASCRIPTCORE) @CY_EXECUTE_TRUE@am__append_7 = libcycript.db -@CY_EXECUTE_TRUE@@CY_PRELINK_TRUE@am__append_8 = Analyze Bridge.def -@CY_EXECUTE_TRUE@@CY_PRELINK_FALSE@am__append_9 = Bridge.def +@CY_EXECUTE_TRUE@am__append_8 = -DCY_EXECUTE +@CY_EXECUTE_TRUE@am__append_9 = C +@CY_EXECUTE_TRUE@am__append_10 = libcycript.db +@CY_EXECUTE_TRUE@@CY_PRELINK_TRUE@am__append_11 = Analyze Bridge.def +@CY_EXECUTE_TRUE@@CY_PRELINK_FALSE@am__append_12 = Bridge.def #CLEANFILES += Hasher.gperf #Hasher.gperf: Hasher.def Hasher.sh @@ -128,24 +131,24 @@ host_triplet = @host@ #CLEANFILES += Hasher.hpp #Hasher.hpp: Hasher.gperf # $(GPERF) $< >$@ -@CY_JAVA_TRUE@am__append_10 = Java -@CY_JAVA_TRUE@am__append_11 = Java/Execute.cpp -@CY_JAVA_TRUE@am__append_12 = $(LTJAVA) -@CY_JAVA_TRUE@am__append_13 = libcycript.jar -@CY_JAVA_TRUE@am__append_14 = Class libcycript.jar -@CY_RUBY_TRUE@am__append_15 = Ruby -@CY_RUBY_TRUE@am__append_16 = Ruby/Execute.cpp -@CY_RUBY_TRUE@am__append_17 = $(LTRUBY) -@CY_PYTHON_TRUE@am__append_18 = Python -@CY_PYTHON_TRUE@am__append_19 = Python/Execute.cpp -@CY_PYTHON_TRUE@am__append_20 = $(LTPYTHON) -@CY_OBJECTIVEC_TRUE@am__append_21 = -DCY_OBJECTIVEC -@CY_OBJECTIVEC_TRUE@am__append_22 = ObjectiveC -@CY_OBJECTIVEC_TRUE@am__append_23 = ObjectiveC/Output.cpp ObjectiveC/Replace.cpp ObjectiveC/Library.mm -@CY_OBJECTIVEC_TRUE@am__append_24 = $(LTOBJECTIVEC) -@CY_ATTACH_TRUE@am__append_25 = Handler.cpp -@CY_ATTACH_TRUE@@CY_CONSOLE_TRUE@am__append_26 = Inject.cpp -@CY_ATTACH_TRUE@@CY_CONSOLE_TRUE@am__append_27 = -DCY_ATTACH +@CY_JAVA_TRUE@am__append_13 = Java +@CY_JAVA_TRUE@am__append_14 = Java/Execute.cpp +@CY_JAVA_TRUE@am__append_15 = $(LTJAVA) +@CY_JAVA_TRUE@am__append_16 = libcycript.jar +@CY_JAVA_TRUE@am__append_17 = Class libcycript.jar +@CY_RUBY_TRUE@am__append_18 = Ruby +@CY_RUBY_TRUE@am__append_19 = Ruby/Execute.cpp +@CY_RUBY_TRUE@am__append_20 = $(LTRUBY) +@CY_PYTHON_TRUE@am__append_21 = Python +@CY_PYTHON_TRUE@am__append_22 = Python/Execute.cpp +@CY_PYTHON_TRUE@am__append_23 = $(LTPYTHON) +@CY_OBJECTIVEC_TRUE@am__append_24 = -DCY_OBJECTIVEC +@CY_OBJECTIVEC_TRUE@am__append_25 = ObjectiveC +@CY_OBJECTIVEC_TRUE@am__append_26 = ObjectiveC/Output.cpp ObjectiveC/Replace.cpp ObjectiveC/Library.mm +@CY_OBJECTIVEC_TRUE@am__append_27 = $(LTOBJECTIVEC) +@CY_ATTACH_TRUE@am__append_28 = Handler.cpp +@CY_ATTACH_TRUE@@CY_CONSOLE_TRUE@am__append_29 = Inject.cpp +@CY_ATTACH_TRUE@@CY_CONSOLE_TRUE@am__append_30 = -DCY_ATTACH subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_cxx_compile_stdcxx_11.m4 \ @@ -236,6 +239,7 @@ am__v_lt_1 = libcycript_la_LINK = $(LIBTOOL) $(AM_V_lt) $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(OBJCXXLD) $(AM_OBJCXXFLAGS) \ $(OBJCXXFLAGS) $(libcycript_la_LDFLAGS) $(LDFLAGS) -o $@ +@CY_ANDROID_TRUE@@CY_CONSOLE_TRUE@am__EXEEXT_1 = cycript-pie$(EXEEXT) PROGRAMS = $(bin_PROGRAMS) am__cycript_SOURCES_DIST = Console.cpp Inject.cpp @CY_ATTACH_TRUE@@CY_CONSOLE_TRUE@am__objects_8 = Inject.$(OBJEXT) @@ -245,6 +249,14 @@ cycript_OBJECTS = $(am_cycript_OBJECTS) @CY_CONSOLE_TRUE@cycript_DEPENDENCIES = libcycript.la \ @CY_CONSOLE_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ @CY_CONSOLE_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am__cycript_pie_SOURCES_DIST = pie.c +@CY_ANDROID_TRUE@@CY_CONSOLE_TRUE@am_cycript_pie_OBJECTS = \ +@CY_ANDROID_TRUE@@CY_CONSOLE_TRUE@ pie.$(OBJEXT) +cycript_pie_OBJECTS = $(am_cycript_pie_OBJECTS) +cycript_pie_LDADD = $(LDADD) +cycript_pie_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(cycript_pie_LDFLAGS) $(LDFLAGS) -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -315,9 +327,10 @@ AM_V_OBJCXXLD = $(am__v_OBJCXXLD_@AM_V@) am__v_OBJCXXLD_ = $(am__v_OBJCXXLD_@AM_DEFAULT_V@) am__v_OBJCXXLD_0 = @echo " OBJCXXLD" $@; am__v_OBJCXXLD_1 = -SOURCES = $(libcycript_la_SOURCES) $(cycript_SOURCES) +SOURCES = $(libcycript_la_SOURCES) $(cycript_SOURCES) \ + $(cycript_pie_SOURCES) DIST_SOURCES = $(am__libcycript_la_SOURCES_DIST) \ - $(am__cycript_SOURCES_DIST) + $(am__cycript_SOURCES_DIST) $(am__cycript_pie_SOURCES_DIST) RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ @@ -436,6 +449,7 @@ CXXFLAGS = @CXXFLAGS@ CXXFLAGS_FOR_BUILD = @CXXFLAGS_FOR_BUILD@ CXX_FOR_BUILD = @CXX_FOR_BUILD@ CYGPATH_W = @CYGPATH_W@ +CY_ANDROID = @CY_ANDROID@ CY_EXECUTE = @CY_EXECUTE@ CY_JAVA = @CY_JAVA@ CY_LIBCLANG = @CY_LIBCLANG@ @@ -588,36 +602,39 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = subdir-objects -CLEANFILES = $(am__append_7) $(am__append_8) $(am__append_9) \ - $(am__append_14) Parser.ypp Scanner.lpp Scanner.cpp \ +CLEANFILES = $(am__append_10) $(am__append_11) $(am__append_12) \ + $(am__append_17) Parser.ypp Scanner.lpp Scanner.cpp \ Scanner.output lex.backup Parser.cpp Parser.hpp stack.hh \ Parser.output SUBDIRS = ACLOCAL_AMFLAGS = -I m4 AM_CPPFLAGS = -DYYDEBUG=1 -DCY_SYSTEM="\"$(CY_SYSTEM)\"" -include \ - config.h -include $(srcdir)/unconfig.h $(am__append_5) \ - $(am__append_21) $(am__append_27) -AM_CFLAGS = -fvisibility=hidden -AM_CXXFLAGS = -fvisibility=hidden -AM_OBJCXXFLAGS = -fvisibility=hidden -fobjc-exceptions -AM_LDFLAGS = -fvisibility=hidden + config.h -include $(srcdir)/unconfig.h $(am__append_8) \ + $(am__append_24) $(am__append_30) +CY_FLAGS = -fvisibility=hidden $(am__append_1) +AM_CFLAGS = $(CY_FLAGS) +AM_CXXFLAGS = $(CY_FLAGS) +AM_OBJCXXFLAGS = $(CY_FLAGS) -fobjc-exceptions +AM_LDFLAGS = $(CY_FLAGS) $(am__append_2) CY_LDFLAGS = -no-undefined -avoid-version -export-dynamic datdir = $(libdir) -dat_DATA = $(am__append_4) $(am__append_13) +dat_DATA = $(am__append_7) $(am__append_16) lib_LTLIBRARIES = libcycript.la libcycript_la_LDFLAGS = $(CY_LDFLAGS) libcycript_la_LIBADD = $(LTLIBUV) $(LTLIBFFI) $(LTLIBSQLITE3) \ - $(LTLIBGCC) -ldl $(am__append_3) $(am__append_12) \ - $(am__append_17) $(am__append_20) $(am__append_24) + $(LTLIBGCC) -ldl $(am__append_6) $(am__append_15) \ + $(am__append_20) $(am__append_23) $(am__append_27) libcycript_la_SOURCES = ConvertUTF.c Decode.cpp Driver.cpp Error.cpp \ Highlight.cpp Library.cpp Network.cpp Output.cpp Replace.cpp \ - Syntax.cpp Parser.cpp Scanner.cpp $(am__append_1) \ - $(am__append_2) $(am__append_11) $(am__append_16) \ - $(am__append_19) $(am__append_23) $(am__append_25) -filters = $(am__append_6) $(am__append_10) $(am__append_15) \ - $(am__append_18) $(am__append_22) -@CY_CONSOLE_TRUE@cycript_SOURCES = Console.cpp $(am__append_26) + Syntax.cpp Parser.cpp Scanner.cpp $(am__append_3) \ + $(am__append_5) $(am__append_14) $(am__append_19) \ + $(am__append_22) $(am__append_26) $(am__append_28) +filters = $(am__append_9) $(am__append_13) $(am__append_18) \ + $(am__append_21) $(am__append_25) +@CY_CONSOLE_TRUE@cycript_SOURCES = Console.cpp $(am__append_29) @CY_CONSOLE_TRUE@cycript_LDADD = libcycript.la $(LTLIBREADLINE) $(LTLIBTERMCAP) $(LTLIBGCC) $(PTHREAD_CFLAGS) -ldl +@CY_ANDROID_TRUE@@CY_CONSOLE_TRUE@cycript_pie_SOURCES = pie.c +@CY_ANDROID_TRUE@@CY_CONSOLE_TRUE@cycript_pie_LDFLAGS = -fno-PIE @CY_EXECUTE_TRUE@@CY_PRELINK_TRUE@CY_LANGFLAGS = -DCY_JAVA=$(CY_JAVA) -DCY_PYTHON=$(CY_PYTHON) -DCY_OBJECTIVEC=$(CY_OBJECTIVEC) all: config.h $(MAKE) $(AM_MAKEFLAGS) all-recursive @@ -807,6 +824,10 @@ cycript$(EXEEXT): $(cycript_OBJECTS) $(cycript_DEPENDENCIES) $(EXTRA_cycript_DEP @rm -f cycript$(EXEEXT) $(AM_V_CXXLD)$(CXXLINK) $(cycript_OBJECTS) $(cycript_LDADD) $(LIBS) +cycript-pie$(EXEEXT): $(cycript_pie_OBJECTS) $(cycript_pie_DEPENDENCIES) $(EXTRA_cycript_pie_DEPENDENCIES) + @rm -f cycript-pie$(EXEEXT) + $(AM_V_CCLD)$(cycript_pie_LINK) $(cycript_pie_OBJECTS) $(cycript_pie_LDADD) $(LIBS) + mostlyclean-compile: -rm -f *.$(OBJEXT) -rm -f Java/*.$(OBJEXT) @@ -841,6 +862,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Replace.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Scanner.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Syntax.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pie.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@Java/$(DEPDIR)/Execute.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ObjectiveC/$(DEPDIR)/Library.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@ObjectiveC/$(DEPDIR)/Output.Plo@am__quote@ diff --git a/android.sh b/android.sh index 3e8708e..da2bd6a 100755 --- a/android.sh +++ b/android.sh @@ -17,8 +17,6 @@ tgt=arm-linux-androideabi cc=${bin}/${tgt}-gcc cxx=${bin}/${tgt}-g++ cpp=() -cpp+=(-fPIE) -ldf+=(-rdynamic -fPIE -pie) ccf=() ccf+=(-g0 -O3) function cfg() { diff --git a/build.mk b/build.mk index 4190112..d415459 100644 --- a/build.mk +++ b/build.mk @@ -70,6 +70,7 @@ local += Cycript.lib/libcycript-sim.dylib android := $(data) android += Cycript.lib/cycript-a32 +android += Cycript.lib/cycript-pie android += Cycript.lib/libcycript.so android += Cycript.lib/libJavaScriptCore.so android += Cycript.lib/l/linux @@ -187,6 +188,8 @@ clean += clean-and-$(1) db += build.and-$(1)/libcycript.db build.and-$(1)/.libs/cycript: build-and-$(1) @ +build.and-$(1)/cycript-pie: build-and-$(1) + @ build.and-$(1)/.libs/libcycript.so: build-and-$(1) @ build.and-$(1)/libcycript.db: build-and-$(1) @@ -220,6 +223,10 @@ Cycript.lib/%: terminfo/% @mkdir -p $(dir $@) cp -af $< $@ +Cycript.lib/cycript-pie: build.and-armeabi/cycript-pie + @mkdir -p $(dir $@) + cp -af $< $@ + %_: % @cp -af $< $@ install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@ diff --git a/configure b/configure index 154012d..a48336f 100755 --- a/configure +++ b/configure @@ -644,6 +644,9 @@ LTLIBGCC LTLIBTERMCAP LTLIBREADLINE CY_LIBCLANG +CY_ANDROID_FALSE +CY_ANDROID_TRUE +CY_ANDROID CY_OBJECTIVEC_FALSE CY_OBJECTIVEC_TRUE CY_PYTHON_FALSE @@ -23966,6 +23969,36 @@ else fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#ifndef __ANDROID__ +#error +#endif + +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + + CY_ANDROID=1 + + +else + + CY_ANDROID=0 + + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + + if test "x$CY_ANDROID" = x1; then + CY_ANDROID_TRUE= + CY_ANDROID_FALSE='#' +else + CY_ANDROID_TRUE='#' + CY_ANDROID_FALSE= +fi + + # Check whether --with-libclang was given. if test "${with_libclang+set}" = set; then : @@ -24388,6 +24421,10 @@ if test -z "${CY_OBJECTIVEC_TRUE}" && test -z "${CY_OBJECTIVEC_FALSE}"; then as_fn_error $? "conditional \"CY_OBJECTIVEC\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${CY_ANDROID_TRUE}" && test -z "${CY_ANDROID_FALSE}"; then + as_fn_error $? "conditional \"CY_ANDROID\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi if test -z "${CY_PRELINK_TRUE}" && test -z "${CY_PRELINK_FALSE}"; then as_fn_error $? "conditional \"CY_PRELINK\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 diff --git a/configure.ac b/configure.ac index 5ae7a76..84756bc 100644 --- a/configure.ac +++ b/configure.ac @@ -298,6 +298,18 @@ AM_CONDITIONAL([CY_RUBY], [test "x$CY_RUBY" = x1]) AM_CONDITIONAL([CY_PYTHON], [test "x$CY_PYTHON" = x1]) AM_CONDITIONAL([CY_OBJECTIVEC], [test "x$CY_OBJECTIVEC" = x1]) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([ +#ifndef __ANDROID__ +#error +#endif +])], [ + AC_SUBST([CY_ANDROID], [1]) +], [ + AC_SUBST([CY_ANDROID], [0]) +]) + +AM_CONDITIONAL([CY_ANDROID], [test "x$CY_ANDROID" = x1]) + AC_ARG_WITH([libclang], AS_HELP_STRING([--with-libclang], [build bridge definitions using this libclang]), [], [with_libclang=no]) AS_IF([test "x$with_libclang" != "xno"], [ diff --git a/pie.c b/pie.c new file mode 100644 index 0000000..53192c1 --- /dev/null +++ b/pie.c @@ -0,0 +1,56 @@ +/* Cycript - The Truly Universal Scripting Language + * Copyright (C) 2009-2016 Jay Freeman (saurik) +*/ + +/* GNU Affero General Public License, Version 3 {{{ */ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +**/ +/* }}} */ + +#include +#include +#include + +#include +#include + +static void fail(const char *error) { + perror(error); + exit(1); +} + +int main(int argc, const char *argv[]) { + char buffer[1024]; + if (readlink("/proc/self/exe", buffer, sizeof(buffer)) == -1) + fail("cannot read from /proc/self/exe"); + + char *slash = strrchr(buffer, '/'); + if (slash == NULL) + fail("could not find executable folder"); + + strcpy(slash + 1, "cycript-a32"); + void *handle = dlopen(buffer, RTLD_LAZY); + if (handle == NULL) { + fprintf(stderr, "%s\n", dlerror()); + fail("could not load actual executable"); + } + + int (*$main)(int argc, const char *argv[]); + $main = (int (*)(int, const char *[])) dlsym(handle, "main"); + if ($main == NULL) + fail("could not locale main symbol"); + + return $main(argc, argv); +} -- 2.45.2