From 3370d0c0f21a43223efe9ae0f76e67f04a332781 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 9 Sep 2013 15:03:53 -0700 Subject: [PATCH] Finish new build environment, relocatable objects. --- Mach/Inject.cpp | 8 ++++- Makefile.am | 4 ++- Makefile.in | 57 +++++++++++++++-------------- Select.cpp | 18 ++++------ cycript.in | 2 ++ make.sh | 7 +--- xcode.mk | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ xcode.sh | 7 ++-- 8 files changed, 148 insertions(+), 51 deletions(-) create mode 100644 cycript.in create mode 100644 xcode.mk diff --git a/Mach/Inject.cpp b/Mach/Inject.cpp index 74e5b30..feb2c3c 100644 --- a/Mach/Inject.cpp +++ b/Mach/Inject.cpp @@ -53,7 +53,13 @@ extern "C" void CYHandleServer(pid_t); void InjectLibrary(pid_t pid) { Dl_info addr; _assert(dladdr(reinterpret_cast(&CYHandleServer), &addr) != 0); - const char *library(addr.dli_fname); + + size_t flength(strlen(addr.dli_fname)); + char library[flength + 4 + 1]; + memcpy(library, addr.dli_fname, flength); + library[flength] = '\0'; + _assert(strcmp(library + flength - 6, ".dylib") == 0); + strcpy(library + flength - 6, "-any.dylib"); mach_port_t self(mach_task_self()), task; _krncall(task_for_pid(self, pid, &task)); diff --git a/Makefile.am b/Makefile.am index a92bb74..2c13663 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,10 +32,12 @@ CY_LDFLAGS = -no-undefined -avoid-version -export-dynamic lib_LTLIBRARIES = +if CY_MACH lib_LTLIBRARIES += libcycript-any.la libcycript_any_la_SOURCES = Select.cpp libcycript_any_la_LDFLAGS = $(CY_LDFLAGS) libcycript_any_la_LIBADD = -ldl +endif lib_LTLIBRARIES += libcycript.la libcycript_la_LDFLAGS = $(CY_LDFLAGS) @@ -117,7 +119,7 @@ CLEANFILES += lex.cy.cpp lex.cy.cpp: Cycript.l $(FLEX) -t $< | $(SED) -e 's/int yyl;/yy_size_t yyl;/;s/int yyleng_r;/yy_size_t yyleng_r;/' >$@ -Console.$(OBJEXT) Execute.lo Handler.lo Highlight.lo Library.lo Parser.lo lex.cy.lo: Cycript.tab.hh +Console.$(OBJEXT) Execute.lo Handler.lo Highlight.lo Library.lo Output.lo Parser.lo lex.cy.lo: Cycript.tab.hh CLEANFILES += Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh Cycript.output Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh Cycript.output: Cycript.yy diff --git a/Makefile.in b/Makefile.in index 1f74967..8036ab1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -98,21 +98,22 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ +@CY_MACH_TRUE@am__append_1 = libcycript-any.la @CY_CONSOLE_TRUE@bin_PROGRAMS = cycript$(EXEEXT) -@CY_EXECUTE_TRUE@am__append_1 = sig/ffi_type.cpp sig/parse.cpp \ +@CY_EXECUTE_TRUE@am__append_2 = sig/ffi_type.cpp sig/parse.cpp \ @CY_EXECUTE_TRUE@ sig/copy.cpp Bridge.cpp Execute.cpp \ @CY_EXECUTE_TRUE@ JavaScriptCore.cpp Library.cpp -@CY_EXECUTE_TRUE@am__append_2 = $(LTJAVASCRIPTCORE) -@CY_EXECUTE_TRUE@am__append_3 = -DCY_EXECUTE -@CY_EXECUTE_TRUE@am__append_4 = C -@CY_EXECUTE_TRUE@am__append_5 = Bridge.gperf Bridge.hpp -@CY_OBJECTIVEC_TRUE@am__append_6 = ObjectiveC -@CY_OBJECTIVEC_TRUE@am__append_7 = ObjectiveC/Output.cpp ObjectiveC/Replace.cpp ObjectiveC/Library.mm -@CY_OBJECTIVEC_TRUE@am__append_8 = $(LTOBJECTIVEC) -@CY_MACH_TRUE@am__append_9 = Handler.mm -@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_10 = Mach/Inject.cpp -@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_11 = -DCY_ATTACH -@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_12 = Trampoline.t.lo \ +@CY_EXECUTE_TRUE@am__append_3 = $(LTJAVASCRIPTCORE) +@CY_EXECUTE_TRUE@am__append_4 = -DCY_EXECUTE +@CY_EXECUTE_TRUE@am__append_5 = C +@CY_EXECUTE_TRUE@am__append_6 = Bridge.gperf Bridge.hpp +@CY_OBJECTIVEC_TRUE@am__append_7 = ObjectiveC +@CY_OBJECTIVEC_TRUE@am__append_8 = ObjectiveC/Output.cpp ObjectiveC/Replace.cpp ObjectiveC/Library.mm +@CY_OBJECTIVEC_TRUE@am__append_9 = $(LTOBJECTIVEC) +@CY_MACH_TRUE@am__append_10 = Handler.mm +@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_11 = Mach/Inject.cpp +@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_12 = -DCY_ATTACH +@CY_CONSOLE_TRUE@@CY_MACH_TRUE@am__append_13 = Trampoline.t.lo \ @CY_CONSOLE_TRUE@@CY_MACH_TRUE@ libTrampoline.t.la \ @CY_CONSOLE_TRUE@@CY_MACH_TRUE@ Trampoline.t.hpp subdir = . @@ -165,7 +166,8 @@ am__uninstall_files_from_dir = { \ am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" LTLIBRARIES = $(lib_LTLIBRARIES) libcycript_any_la_DEPENDENCIES = -am_libcycript_any_la_OBJECTS = Select.lo +am__libcycript_any_la_SOURCES_DIST = Select.cpp +@CY_MACH_TRUE@am_libcycript_any_la_OBJECTS = Select.lo libcycript_any_la_OBJECTS = $(am_libcycript_any_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -175,6 +177,7 @@ libcycript_any_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ $(AM_CXXFLAGS) $(CXXFLAGS) $(libcycript_any_la_LDFLAGS) \ $(LDFLAGS) -o $@ +@CY_MACH_TRUE@am_libcycript_any_la_rpath = -rpath $(libdir) am__DEPENDENCIES_1 = @CY_EXECUTE_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) @CY_OBJECTIVEC_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1) @@ -282,7 +285,7 @@ am__v_OBJCXXLD_0 = @echo " OBJCXXLD" $@; am__v_OBJCXXLD_1 = SOURCES = $(libcycript_any_la_SOURCES) $(libcycript_la_SOURCES) \ $(cycript_SOURCES) -DIST_SOURCES = $(libcycript_any_la_SOURCES) \ +DIST_SOURCES = $(am__libcycript_any_la_SOURCES_DIST) \ $(am__libcycript_la_SOURCES_DIST) $(am__cycript_SOURCES_DIST) RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ @@ -527,27 +530,27 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = subdir-objects -CLEANFILES = $(am__append_5) $(am__append_12) Cycript.yy Cycript.l \ +CLEANFILES = $(am__append_6) $(am__append_13) Cycript.yy Cycript.l \ lex.cy.cpp Cycript.tab.cc Cycript.tab.hh location.hh \ position.hh stack.hh Cycript.output SUBDIRS = ACLOCAL_AMFLAGS = -I m4 AM_CPPFLAGS = -I$(srcdir)/include -DYYDEBUG=1 -include config.h \ - -include $(srcdir)/unconfig.h $(am__append_3) $(am__append_11) + -include $(srcdir)/unconfig.h $(am__append_4) $(am__append_12) CY_LDFLAGS = -no-undefined -avoid-version -export-dynamic -lib_LTLIBRARIES = libcycript-any.la libcycript.la -libcycript_any_la_SOURCES = Select.cpp -libcycript_any_la_LDFLAGS = $(CY_LDFLAGS) -libcycript_any_la_LIBADD = -ldl +lib_LTLIBRARIES = $(am__append_1) libcycript.la +@CY_MACH_TRUE@libcycript_any_la_SOURCES = Select.cpp +@CY_MACH_TRUE@libcycript_any_la_LDFLAGS = $(CY_LDFLAGS) +@CY_MACH_TRUE@libcycript_any_la_LIBADD = -ldl libcycript_la_LDFLAGS = $(CY_LDFLAGS) -libcycript_la_LIBADD = $(LTLIBFFI) -ldl $(am__append_2) \ - $(am__append_8) +libcycript_la_LIBADD = $(LTLIBFFI) -ldl $(am__append_3) \ + $(am__append_9) libcycript_la_SOURCES = ConvertUTF.c Highlight.cpp Network.cpp \ Output.cpp Parser.cpp Replace.cpp Cycript.tab.cc lex.cy.cpp \ - $(am__append_1) $(am__append_7) $(am__append_9) -filters = $(CY_FILTERS) $(am__append_4) $(am__append_6) + $(am__append_2) $(am__append_8) $(am__append_10) +filters = $(CY_FILTERS) $(am__append_5) $(am__append_7) @CY_CONSOLE_TRUE@cycript_SOURCES = Console.cpp Display.cpp \ -@CY_CONSOLE_TRUE@ $(am__append_10) +@CY_CONSOLE_TRUE@ $(am__append_11) @CY_CONSOLE_TRUE@cycript_LDADD = libcycript.la $(LTLIBAPR) $(LTLIBREADLINE) $(LTLIBTERMCAP) -ldl @CY_CONSOLE_TRUE@ldid = true @CY_CONSOLE_TRUE@entitle = $(ldid) -S$(srcdir)/cycript.xml @@ -642,7 +645,7 @@ clean-libLTLIBRARIES: } libcycript-any.la: $(libcycript_any_la_OBJECTS) $(libcycript_any_la_DEPENDENCIES) $(EXTRA_libcycript_any_la_DEPENDENCIES) - $(AM_V_CXXLD)$(libcycript_any_la_LINK) -rpath $(libdir) $(libcycript_any_la_OBJECTS) $(libcycript_any_la_LIBADD) $(LIBS) + $(AM_V_CXXLD)$(libcycript_any_la_LINK) $(am_libcycript_any_la_rpath) $(libcycript_any_la_OBJECTS) $(libcycript_any_la_LIBADD) $(LIBS) sig/$(am__dirstamp): @$(MKDIR_P) sig @: > sig/$(am__dirstamp) @@ -1330,7 +1333,7 @@ Cycript.l: Cycript.l.in lex.cy.cpp: Cycript.l $(FLEX) -t $< | $(SED) -e 's/int yyl;/yy_size_t yyl;/;s/int yyleng_r;/yy_size_t yyleng_r;/' >$@ -Console.o Execute.lo Handler.lo Highlight.lo Library.lo Parser.lo lex.cy.lo: Cycript.tab.hh +Console.$(OBJEXT) Execute.lo Handler.lo Highlight.lo Library.lo Output.lo Parser.lo lex.cy.lo: Cycript.tab.hh Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh Cycript.output: Cycript.yy $(BISON) -v --report=state $< ! grep -n '^ *$$default reduce using rule [0-9]* (Lex[A-Z][^)]*)$$' Cycript.output -B 2 | grep 'shift, and go to state [0-9]*$$' diff --git a/Select.cpp b/Select.cpp index 3143be2..f15ab06 100644 --- a/Select.cpp +++ b/Select.cpp @@ -37,10 +37,7 @@ extern "C" void CYHandleServer(pid_t pid) { const char *fname(addr.dli_fname); size_t length(strlen(fname)); - const char *ext(strrchr(fname, '.')); - size_t prefix(ext - fname); - - const char *addition; + const char *target; #ifdef __APPLE__ // XXX: THIS IS HORRIBLE OMG I NEED TO FIX THIS ASAP bool simulator(false); @@ -49,18 +46,17 @@ extern "C" void CYHandleServer(pid_t pid) { simulator = true; } if (simulator) - addition = "-sim"; + target = "sim"; else #endif // someone threw a fit about dangling #endif + else // the idea that this bothers someone gives me glee - addition = "-sys"; + target = "sys"; - char library[length + 5]; - memcpy(library, fname, prefix); - memcpy(library + prefix, addition, 4); - memcpy(library + prefix + 4, fname + prefix, length - prefix); - library[length + 4] = '\0'; + char library[length + 1]; + memcpy(library, fname, length); + memcpy(library + length - 6 - 3, target, 3); + library[length] = '\0'; void *handle(dlopen(library, RTLD_LOCAL | RTLD_LAZY)); if (handle == NULL) { diff --git a/cycript.in b/cycript.in new file mode 100644 index 0000000..979c0c6 --- /dev/null +++ b/cycript.in @@ -0,0 +1,2 @@ +#!/bin/bash +DYLD_LIBRARY_PATH=.libs exec .libs/cycript "$@" diff --git a/make.sh b/make.sh index cae4027..ff2c5d2 100755 --- a/make.sh +++ b/make.sh @@ -1,7 +1,2 @@ #!/bin/bash -set -e -for build in build.*; do - cd "${build}" - make - cd .. -done +exec make -f xcode.mk "$@" diff --git a/xcode.mk b/xcode.mk new file mode 100644 index 0000000..2271652 --- /dev/null +++ b/xcode.mk @@ -0,0 +1,96 @@ +# Cycript - Optimizing JavaScript Compiler/Runtime +# Copyright (C) 2009-2013 Jay Freeman (saurik) + +# GNU General Public License, Version 3 {{{ +# +# Cycript is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# by the Free Software Foundation, either version 3 of the License, +# or (at your option) any later version. +# +# Cycript 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Cycript. If not, see . +# }}} + +.DELETE_ON_ERROR: +SHELL := /bin/bash + +libs := +libs += .libs/cycript +libs += .libs/libcycript.dylib +libs += .libs/libcycript-any.dylib +libs += .libs/libcycript-sys.dylib +libs += .libs/libcycript-sim.dylib +libs += .libs/libcycript.o + +all: cycript $(libs) + +clean: + rm -rf cycript .libs + +build-mac: + $(MAKE) -C build.mac + +build-ios: + $(MAKE) -C build.ios + +build-sim: + $(MAKE) -C build.sim + +# make stubbornly refuses to believe that these @'s are bugs +# http://osdir.com/ml/help-make-gnu/2012-04/msg00008.html + +build.mac/.libs/cycript: build-mac + @ +build.mac/.libs/libcycript.dylib: build-mac + @ +build.mac/.libs/libcycript-any.dylib: build-mac + @ + +build.ios/.libs/cycript: build-ios + @ +build.ios/.libs/libcycript.dylib: build-ios + @ +build.ios/.libs/libcycript-any.dylib: build-ios + @ +build.ios/.libs/libcycript.a: build-ios + @ + +build.sim/.libs/libcycript.dylib: build-sim + @ +build.sim/.libs/libcycript.a: build-sim + @ + +.libs/%: build.mac/.libs/% build.ios/.libs/% + @mkdir -p .libs + lipo -create -output $@ $^ + +.libs/%-ios.a: build.ios/.libs/%.a build.sim/.libs/%.a + @mkdir -p .libs + lipo -create -output $@ $^ + +.libs/libcycript-sys.dylib: + @mkdir -p .libs + ln -sf libcycript.dylib $@ + +.libs/libcycript-sim.dylib: build.sim/.libs/libcycript.dylib + @mkdir -p .libs + cp -af $< $@ + +.libs/libcycript-%.o: build.%/.libs/libcycript.a + @mkdir -p .libs + ld -r -arch $$(lipo -detailed_info $< | sed -e '/^Non-fat file: / ! d; s/.*: //') -o $@ -all_load $< libffi.a + +.libs/libcycript.o: .libs/libcycript-ios.o .libs/libcycript-sim.o + lipo -create -output $@ $^ + +cycript: cycript.in + cp -af $< $@ + chmod 755 $@ + +.PHONY: all clean build-mac build-ios build-sim diff --git a/xcode.sh b/xcode.sh index 8646162..de4e5ab 100755 --- a/xcode.sh +++ b/xcode.sh @@ -59,7 +59,7 @@ function configure() { rm -rf build."${dir}" mkdir build."${dir}" cd build."${dir}" - CPP="${cc} -E" CC="${cc} ${flg}" CXXCPP="${cxx} -E" CXX="${cxx} ${flg}" OBJCXX="${cxx} ${flg}" ../configure "${flags[@]}" "$@" + CPP="${cc} -E" CC="${cc} ${flg}" CXXCPP="${cxx} -E" CXX="${cxx} ${flg}" OBJCXX="${cxx} ${flg}" ../configure "${flags[@]}" --prefix="/usr" "$@" cd .. } @@ -74,8 +74,5 @@ function build() { configure "${dir}" "${sdk}" "${flg}" "$@" --enable-static --with-pic #CPPFLAGS="-idirafter ${mac}/usr/include" } -sim="-mios-simulator-version-min=2.0" -sim="" # gcc does not support this - -build sim iphonesimulator "-arch i386 ${sim}" OBJCXXFLAGS="-fobjc-abi-version=2 -fobjc-legacy-dispatch" CPPFLAGS="-I../libffi.i386/include" LDFLAGS="-L.." --disable-console +build sim iphonesimulator "-arch i386 -mios-simulator-version-min=2.0" OBJCXXFLAGS="-fobjc-abi-version=2 -fobjc-legacy-dispatch" CPPFLAGS="-I../libffi.i386/include" LDFLAGS="-L.." --disable-console build ios iphoneos5.1 "-arch armv6 -miphoneos-version-min=2.0" --host=arm-apple-darwin10 CPPFLAGS="-I../libffi.armv6/include -I../sysroot.ios/usr/include -I../sysroot.ios/usr/include/apr-1" LTLIBAPR="../sysroot.ios/usr/lib/libapr-1.dylib" LDFLAGS="-L.. -L../sysroot.ios/usr/lib" -- 2.45.2