diff --git a/CMakeLists.txt b/CMakeLists.txt index 568c1638e..ff6777d90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,7 @@ endif(NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64") add_subdirectory(src/util) add_subdirectory(src/libmach-o) +add_subdirectory(src/libdyld) add_subdirectory(src/dyld) add_subdirectory(src/libSystem) add_subdirectory(src/Cocoa) @@ -110,6 +111,7 @@ add_subdirectory(src/OpenGL) add_subdirectory(src/thin) add_subdirectory(src/libstdc++darwin) -add_dependencies(dyld${SUFFIX} mach-o) +add_dependencies(dyld mach-o) +add_dependencies(dyld-bin dyld) add_dependencies(Cocoa crashhandler) diff --git a/etc/dylib.conf b/etc/dylib.conf index b63ccb609..16c2a14f5 100644 --- a/etc/dylib.conf +++ b/etc/dylib.conf @@ -18,6 +18,8 @@ /usr/lib/libmx.A.dylib=libc.so.6 /usr/lib/libpcap.A.dylib=libpcap.so.1 /usr/lib/libssl.0.9.8.dylib=libssl.so.0.9.8 +/usr/lib/libxml2.2.dylib=libxml2.so.2 +/usr/lib/libicucore.A.dylib=libicuc.so @rpath/libclang.dylib=libclang.so @rpath/libobjc.A.dylib=libobjc.A.dylib.so diff --git a/src/AudioToolbox/AudioConverter.cpp b/src/AudioToolbox/AudioConverter.cpp index 49f8460e8..3945422ec 100644 --- a/src/AudioToolbox/AudioConverter.cpp +++ b/src/AudioToolbox/AudioConverter.cpp @@ -2,6 +2,10 @@ #include #include +extern "C" { +#include +} + // http://blinkingblip.wordpress.com/ __attribute__((constructor)) static void init_avcodec() @@ -184,9 +188,9 @@ OSStatus AudioConverter::create(const AudioStreamBasicDescription* inSourceForma AudioConverter::~AudioConverter() { if (m_decoder) - av_free(m_decoder); + avcodec_close(m_decoder); if (m_encoder) - av_free(m_encoder); + avcodec_close(m_encoder); //if (m_resampler) // avresample_free(&m_resampler); } diff --git a/src/Foundation/NSDarwinBundle.mm b/src/Foundation/NSDarwinBundle.mm index eae6b3c49..cb929017b 100644 --- a/src/Foundation/NSDarwinBundle.mm +++ b/src/Foundation/NSDarwinBundle.mm @@ -5,9 +5,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include extern int g_argc asm("NXArgc"); extern char** g_argv asm("NXArgv"); diff --git a/src/dyld/CMakeLists.txt b/src/dyld/CMakeLists.txt index d4d07a8c4..79f7d2c40 100644 --- a/src/dyld/CMakeLists.txt +++ b/src/dyld/CMakeLists.txt @@ -1,4 +1,4 @@ -project(dyld) +project(dyld-bin) cmake_minimum_required(VERSION 2.4.0) @@ -7,28 +7,7 @@ if(COMMAND cmake_policy) endif(COMMAND cmake_policy) set(dyld_SRCS - eh/BufReWriter.cpp - eh/CFIWalker.cpp - eh/DwarfPointer.cpp - eh/BufWriter.cpp - eh/BufReader.cpp - eh/EHSection.cpp - Trampoline.cpp - trampoline_helper.nasm - dyld_stub_binder.nasm - tls_helper.nasm dyld.cpp - dyld_public.cpp - dl_public.cpp - binfmt_misc.cpp - TLS.cpp - - MachOObject.cpp - LoadableObject.cpp - NativeObject.cpp - MachOMgr.cpp - DylibSearch.cpp - UndefinedFunction.cpp ) SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX}/darling") @@ -36,13 +15,21 @@ SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX}/darling") SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -add_executable(dyld${SUFFIX} ${dyld_SRCS}) -target_link_libraries(dyld${SUFFIX} -ldl -lpthread mach-o util) +add_executable(dyld-bin ${dyld_SRCS}) +set_target_properties(dyld-bin PROPERTIES OUTPUT_NAME dyld${SUFFIX}) +target_link_libraries(dyld-bin -l:../libdyld/libdyld.so util) -install(TARGETS dyld${SUFFIX} DESTINATION bin) +if (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64") + add_executable(dyldd dyldd.cpp) + target_link_libraries(dyldd -l:../libdyld/libdyld.so util) + install(TARGETS dyldd DESTINATION bin) +endif (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64") + +install(TARGETS dyld-bin DESTINATION bin) if (SUFFIX STREQUAL "64") - add_executable(dyld dyld-multilib.c) - install(TARGETS dyld DESTINATION bin) + add_executable(dyld-multilib dyld-multilib.c) + set_target_properties(dyld-multilib PROPERTIES OUTPUT_NAME dyld) + install(TARGETS dyld-multilib DESTINATION bin) endif (SUFFIX STREQUAL "64") diff --git a/src/dyld/dyld.cpp b/src/dyld/dyld.cpp index 40cdc9ad7..fa08e6079 100644 --- a/src/dyld/dyld.cpp +++ b/src/dyld/dyld.cpp @@ -1,5 +1,5 @@ -#include "MachOMgr.h" -#include "MachOObject.h" +#include +#include #include #include #include @@ -7,7 +7,7 @@ #include #include #include -#include "arch.h" +#include static void printHelp(const char* argv0); static std::string locateBundleExecutable(const std::string& bundlePath); diff --git a/src/dyld/dyldd.cpp b/src/dyld/dyldd.cpp new file mode 100644 index 000000000..51276df90 --- /dev/null +++ b/src/dyld/dyldd.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ANSI_COLOR_RED "\x1b[31m" +#define ANSI_COLOR_GREEN "\x1b[32m" +#define ANSI_COLOR_YELLOW "\x1b[33m" +#define ANSI_COLOR_BLUE "\x1b[34m" +#define ANSI_COLOR_MAGENTA "\x1b[35m" +#define ANSI_COLOR_CYAN "\x1b[36m" +#define ANSI_COLOR_GRAY "\x1b[1m\x1b[30m" +#define ANSI_COLOR_RESET "\x1b[0m" + +using namespace Darling; + +static void resolve(MachOObject* obj, std::set& deps); +static const char* c(const char* color); + +int main(int argc, char** argv, char** envp) +{ + try + { + MachOObject* obj; + std::set deps; + + obj = new MachOObject(argv[1]); + + MachOMgr::instance()->add(obj, true); + + std::cout << c(ANSI_COLOR_GRAY) << "Resolving dependencies of " << obj->path() << "\n\n" << c(ANSI_COLOR_RESET); + + resolve(obj, deps); + + MachOMgr::instance()->remove(obj); + } + catch (const std::exception& e) + { + std::cerr << c(ANSI_COLOR_RED) << e.what() << c(ANSI_COLOR_RESET) << std::endl; + return 1; + } +} + +void resolve(MachOObject* obj, std::set& deps) +{ + for (std::string dylib : obj->declaredDependencies()) + { + LoadableObject* dep; + + if (dylib.empty()) + continue; + + std::string path = DylibSearch::instance()->resolve(dylib, obj); + if (path.empty()) + { + if (deps.find(dylib) == deps.end()) + { + deps.insert(dylib); + + std::cout << dylib << " => " << c(ANSI_COLOR_RED) << "not found" << c(ANSI_COLOR_RESET) << std::endl; + } + + continue; + } + + dep = LoadableObject::instantiateForPath(path, obj); + + if (deps.find(dep->path()) != deps.end()) + { + dep->delRef(); + continue; + } + + deps.insert(dep->path()); + + if (MachOObject* mach = dynamic_cast(dep)) + { + std::cout << dylib << " => " << c(ANSI_COLOR_BLUE) << dep->path() << c(ANSI_COLOR_RESET) << std::endl; + + resolve(mach, deps); + } + else + std::cout << dylib << " => " << c(ANSI_COLOR_GREEN) << dep->path() << c(ANSI_COLOR_RESET) << std::endl; + } +} + +const char* c(const char* color) +{ + static bool tty = isatty(1); + return tty ? color : ""; +} diff --git a/src/libSystem/kernel-bsd/fopsmisc.cpp b/src/libSystem/kernel-bsd/fopsmisc.cpp index fa6859537..9ec4f9c44 100644 --- a/src/libSystem/kernel-bsd/fopsmisc.cpp +++ b/src/libSystem/kernel-bsd/fopsmisc.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include int __darwin_access(const char *pathname, int mode) { diff --git a/src/libSystem/kernel-bsd/io.cpp b/src/libSystem/kernel-bsd/io.cpp index 7f90eb98c..0bee69afb 100644 --- a/src/libSystem/kernel-bsd/io.cpp +++ b/src/libSystem/kernel-bsd/io.cpp @@ -8,7 +8,7 @@ #include "common/auto.h" #include #include -#include +#include static const Darling::MappedFlag g_openflags[] = { { DARWIN_O_ASYNC, O_ASYNC}, { DARWIN_O_SYNC, O_SYNC }, { DARWIN_O_NOFOLLOW, O_NOFOLLOW}, diff --git a/src/libSystem/kernel-bsd/stat.cpp b/src/libSystem/kernel-bsd/stat.cpp index 4ce5c66c4..59b7ff40d 100644 --- a/src/libSystem/kernel-bsd/stat.cpp +++ b/src/libSystem/kernel-bsd/stat.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include static void convertStat64(struct stat64* linux_buf, struct __darwin_stat64* mac) { diff --git a/src/libSystem/libc/dir.cpp b/src/libSystem/libc/dir.cpp index 1b45c1bce..8a199b6a2 100644 --- a/src/libSystem/libc/dir.cpp +++ b/src/libSystem/libc/dir.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include static darwin_dirent* convertDirent(const struct dirent* ent); static darwin_dirent64* convertDirent64(const struct dirent* ent); diff --git a/src/libSystem/libc/nextstep.cpp b/src/libSystem/libc/nextstep.cpp index b1c424c18..1487afb41 100644 --- a/src/libSystem/libc/nextstep.cpp +++ b/src/libSystem/libc/nextstep.cpp @@ -2,8 +2,8 @@ #include "nextstep.h" #include #include -#include -#include +#include +#include using namespace Darling; diff --git a/src/libSystem/libc/progname.cpp b/src/libSystem/libc/progname.cpp index 53e860638..1569e788b 100644 --- a/src/libSystem/libc/progname.cpp +++ b/src/libSystem/libc/progname.cpp @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include using namespace Darling; diff --git a/src/libSystem/libc/stdio.cpp b/src/libSystem/libc/stdio.cpp index 616ef331d..b51f30dd6 100644 --- a/src/libSystem/libc/stdio.cpp +++ b/src/libSystem/libc/stdio.cpp @@ -18,7 +18,7 @@ #include #include "log.h" #include -#include +#include #include #include diff --git a/src/libdyld/CMakeLists.txt b/src/libdyld/CMakeLists.txt new file mode 100644 index 000000000..6abafb082 --- /dev/null +++ b/src/libdyld/CMakeLists.txt @@ -0,0 +1,43 @@ +project(libdyld) + +cmake_minimum_required(VERSION 2.4.0) + +if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +set(dyld_SRCS + eh/BufReWriter.cpp + eh/CFIWalker.cpp + eh/DwarfPointer.cpp + eh/BufWriter.cpp + eh/BufReader.cpp + eh/EHSection.cpp + Trampoline.cpp + trampoline_helper.nasm + dyld_stub_binder.nasm + tls_helper.nasm + dyld_public.cpp + dl_public.cpp + binfmt_misc.cpp + TLS.cpp + + MachOObject.cpp + LoadableObject.cpp + NativeObject.cpp + MachOMgr.cpp + DylibSearch.cpp + UndefinedFunction.cpp +) + +SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX}/darling") +#SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags") +SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + +add_library(dyld SHARED ${dyld_SRCS}) +target_link_libraries(dyld -ldl -lpthread mach-o util) + +install(TARGETS dyld DESTINATION lib${SUFFIX}/darling) + + diff --git a/src/dyld/DylibSearch.cpp b/src/libdyld/DylibSearch.cpp similarity index 100% rename from src/dyld/DylibSearch.cpp rename to src/libdyld/DylibSearch.cpp diff --git a/src/dyld/DylibSearch.h b/src/libdyld/DylibSearch.h similarity index 100% rename from src/dyld/DylibSearch.h rename to src/libdyld/DylibSearch.h diff --git a/src/dyld/LoadableObject.cpp b/src/libdyld/LoadableObject.cpp similarity index 95% rename from src/dyld/LoadableObject.cpp rename to src/libdyld/LoadableObject.cpp index ada6d9cb4..3a4e3215a 100644 --- a/src/dyld/LoadableObject.cpp +++ b/src/libdyld/LoadableObject.cpp @@ -21,7 +21,8 @@ int LoadableObject::delRef() int refs = --m_refs; if (!refs && !m_noDelete) { - unload(); + if (isLoaded()) + unload(); delete this; } diff --git a/src/dyld/LoadableObject.h b/src/libdyld/LoadableObject.h similarity index 99% rename from src/dyld/LoadableObject.h rename to src/libdyld/LoadableObject.h index 913ced733..42ae14375 100644 --- a/src/dyld/LoadableObject.h +++ b/src/libdyld/LoadableObject.h @@ -41,8 +41,9 @@ public: inline void setNoDelete(bool noDelete) { m_noDelete = noDelete; } inline bool noDelete() const { return m_noDelete; } -protected: + static LoadableObject* instantiateForPath(const std::string& path, MachOObject* requester); + protected: std::atomic m_refs; bool m_globalExports = true; diff --git a/src/dyld/MachOMgr.cpp b/src/libdyld/MachOMgr.cpp similarity index 100% rename from src/dyld/MachOMgr.cpp rename to src/libdyld/MachOMgr.cpp diff --git a/src/dyld/MachOMgr.h b/src/libdyld/MachOMgr.h similarity index 100% rename from src/dyld/MachOMgr.h rename to src/libdyld/MachOMgr.h diff --git a/src/dyld/MachOObject.cpp b/src/libdyld/MachOObject.cpp similarity index 99% rename from src/dyld/MachOObject.cpp rename to src/libdyld/MachOObject.cpp index 490a69ff2..8a2ec2cb0 100644 --- a/src/dyld/MachOObject.cpp +++ b/src/libdyld/MachOObject.cpp @@ -63,6 +63,7 @@ void MachOObject::postConstruct() { detectAbsolutePath(); m_header = m_file->header(); + m_rpaths.insert(m_rpaths.begin(), m_file->rpaths().begin(), m_file->rpaths().end()); m_bindAllAtLoad = MachOMgr::instance()->bindAtLaunch(); } diff --git a/src/dyld/MachOObject.h b/src/libdyld/MachOObject.h similarity index 95% rename from src/dyld/MachOObject.h rename to src/libdyld/MachOObject.h index 12d8b844c..fb79a840d 100644 --- a/src/dyld/MachOObject.h +++ b/src/libdyld/MachOObject.h @@ -92,12 +92,14 @@ public: inline void setNoRecursion(bool noRecursion) { m_noRecursion = noRecursion; } inline bool noRecursion() const { return m_noRecursion; } + std::vector declaredDependencies() const { return m_file->dylibs(); } + protected: friend class DylibSearch; friend class LoadableObject; - void setRequesterRunpaths(const std::vector& rpaths) { m_parentRpaths = rpaths; } - const std::vector& runPaths() const { return m_file->rpaths(); } + void setRequesterRunpaths(const std::vector& rpaths) { m_rpaths.insert(m_rpaths.begin(), rpaths.begin(), rpaths.end()); } + const std::vector& runPaths() const { return m_rpaths; } ProgramVars* getProgramVars(); private: @@ -163,7 +165,7 @@ private: int initprot, maxprot; }; std::vector m_mappings; - std::vector m_parentRpaths; + std::vector m_rpaths; void* m_reworkedEHData = nullptr; std::string m_absolutePath, m_absolutePathDir, m_name; diff --git a/src/dyld/NativeObject.cpp b/src/libdyld/NativeObject.cpp similarity index 100% rename from src/dyld/NativeObject.cpp rename to src/libdyld/NativeObject.cpp diff --git a/src/dyld/NativeObject.h b/src/libdyld/NativeObject.h similarity index 100% rename from src/dyld/NativeObject.h rename to src/libdyld/NativeObject.h diff --git a/src/dyld/TLS.cpp b/src/libdyld/TLS.cpp similarity index 100% rename from src/dyld/TLS.cpp rename to src/libdyld/TLS.cpp diff --git a/src/dyld/TLS.h b/src/libdyld/TLS.h similarity index 100% rename from src/dyld/TLS.h rename to src/libdyld/TLS.h diff --git a/src/dyld/Trampoline.cpp b/src/libdyld/Trampoline.cpp similarity index 100% rename from src/dyld/Trampoline.cpp rename to src/libdyld/Trampoline.cpp diff --git a/src/dyld/Trampoline.h b/src/libdyld/Trampoline.h similarity index 100% rename from src/dyld/Trampoline.h rename to src/libdyld/Trampoline.h diff --git a/src/dyld/UndefinedFunction.cpp b/src/libdyld/UndefinedFunction.cpp similarity index 100% rename from src/dyld/UndefinedFunction.cpp rename to src/libdyld/UndefinedFunction.cpp diff --git a/src/dyld/UndefinedFunction.h b/src/libdyld/UndefinedFunction.h similarity index 100% rename from src/dyld/UndefinedFunction.h rename to src/libdyld/UndefinedFunction.h diff --git a/src/dyld/arch.h b/src/libdyld/arch.h similarity index 100% rename from src/dyld/arch.h rename to src/libdyld/arch.h diff --git a/src/dyld/binfmt_misc.cpp b/src/libdyld/binfmt_misc.cpp similarity index 100% rename from src/dyld/binfmt_misc.cpp rename to src/libdyld/binfmt_misc.cpp diff --git a/src/dyld/binfmt_misc.h b/src/libdyld/binfmt_misc.h similarity index 100% rename from src/dyld/binfmt_misc.h rename to src/libdyld/binfmt_misc.h diff --git a/src/dyld/dl_public.cpp b/src/libdyld/dl_public.cpp similarity index 100% rename from src/dyld/dl_public.cpp rename to src/libdyld/dl_public.cpp diff --git a/src/dyld/dl_public.h b/src/libdyld/dl_public.h similarity index 100% rename from src/dyld/dl_public.h rename to src/libdyld/dl_public.h diff --git a/src/dyld/dyld_public.cpp b/src/libdyld/dyld_public.cpp similarity index 100% rename from src/dyld/dyld_public.cpp rename to src/libdyld/dyld_public.cpp diff --git a/src/dyld/dyld_public.h b/src/libdyld/dyld_public.h similarity index 100% rename from src/dyld/dyld_public.h rename to src/libdyld/dyld_public.h diff --git a/src/dyld/dyld_stub_binder.nasm b/src/libdyld/dyld_stub_binder.nasm similarity index 57% rename from src/dyld/dyld_stub_binder.nasm rename to src/libdyld/dyld_stub_binder.nasm index 16fef2fd9..4884a154e 100644 --- a/src/dyld/dyld_stub_binder.nasm +++ b/src/libdyld/dyld_stub_binder.nasm @@ -3,6 +3,7 @@ section .note.GNU-stack noalloc noexec nowrite progbits extern reg_saveall extern reg_restoreall extern dyld_stub_binder_fixup ; void* dyld_stub_binder_fixup(void* cache, uintptr_t index) +extern _GLOBAL_OFFSET_TABLE_ global dyld_stub_binder ; Stub identifier is pushed first @@ -15,15 +16,16 @@ section text dyld_stub_binder: - call reg_saveall ; 224 bytes + call reg_saveall WRT ..plt ; 224 bytes mov rdi, [rsp+224] ; cache mov rsi, [rsp+224+8] ; offset - call dyld_stub_binder_fixup + call dyld_stub_binder_fixup WRT ..plt - mov r11, rax - call reg_restoreall + mov [rsp+224], rax + call reg_restoreall WRT ..plt + mov r11, [rsp] add rsp, 16 ; remove arguments to dyld_stub_binder jmp r11 @@ -34,21 +36,31 @@ section text dyld_stub_binder: + push ebx + + call .get_GOT +.get_GOT: + pop ebx + add ebx, _GLOBAL_OFFSET_TABLE_+$$-.get_GOT wrt ..gotpc + push eax - call reg_saveall ; 32 bytes - mov eax, [esp+32] ; cache - mov ecx, [esp+32+4] ; offset + call reg_saveall WRT ..plt ; 32 bytes + mov eax, [esp+32+4] ; cache + mov ecx, [esp+32+4+4] ; offset push ecx push eax - call dyld_stub_binder_fixup + call dyld_stub_binder_fixup WRT ..plt add esp, 8 - mov [esp-12], eax ; save the real addr somewhere - call reg_restoreall + mov [esp+32+4], eax ; save the real addr somewhere + call reg_restoreall WRT ..plt - mov eax, [esp-0x2c] ; restore the real addr + mov eax, [esp+4] ; restore the real addr + + pop ebx add esp, 8 ; remove arguments to dyld_stub_binder THIS SHOULDN'T WORK! + jmp eax %else diff --git a/src/dyld/eh/BufReWriter.cpp b/src/libdyld/eh/BufReWriter.cpp similarity index 100% rename from src/dyld/eh/BufReWriter.cpp rename to src/libdyld/eh/BufReWriter.cpp diff --git a/src/dyld/eh/BufReWriter.h b/src/libdyld/eh/BufReWriter.h similarity index 100% rename from src/dyld/eh/BufReWriter.h rename to src/libdyld/eh/BufReWriter.h diff --git a/src/dyld/eh/BufReader.cpp b/src/libdyld/eh/BufReader.cpp similarity index 100% rename from src/dyld/eh/BufReader.cpp rename to src/libdyld/eh/BufReader.cpp diff --git a/src/dyld/eh/BufReader.h b/src/libdyld/eh/BufReader.h similarity index 100% rename from src/dyld/eh/BufReader.h rename to src/libdyld/eh/BufReader.h diff --git a/src/dyld/eh/BufWriter.cpp b/src/libdyld/eh/BufWriter.cpp similarity index 100% rename from src/dyld/eh/BufWriter.cpp rename to src/libdyld/eh/BufWriter.cpp diff --git a/src/dyld/eh/BufWriter.h b/src/libdyld/eh/BufWriter.h similarity index 100% rename from src/dyld/eh/BufWriter.h rename to src/libdyld/eh/BufWriter.h diff --git a/src/dyld/eh/CFIWalker.cpp b/src/libdyld/eh/CFIWalker.cpp similarity index 100% rename from src/dyld/eh/CFIWalker.cpp rename to src/libdyld/eh/CFIWalker.cpp diff --git a/src/dyld/eh/CFIWalker.h b/src/libdyld/eh/CFIWalker.h similarity index 100% rename from src/dyld/eh/CFIWalker.h rename to src/libdyld/eh/CFIWalker.h diff --git a/src/dyld/eh/DwarfPointer.cpp b/src/libdyld/eh/DwarfPointer.cpp similarity index 100% rename from src/dyld/eh/DwarfPointer.cpp rename to src/libdyld/eh/DwarfPointer.cpp diff --git a/src/dyld/eh/DwarfPointer.h b/src/libdyld/eh/DwarfPointer.h similarity index 100% rename from src/dyld/eh/DwarfPointer.h rename to src/libdyld/eh/DwarfPointer.h diff --git a/src/dyld/eh/EHSection.cpp b/src/libdyld/eh/EHSection.cpp similarity index 100% rename from src/dyld/eh/EHSection.cpp rename to src/libdyld/eh/EHSection.cpp diff --git a/src/dyld/eh/EHSection.h b/src/libdyld/eh/EHSection.h similarity index 100% rename from src/dyld/eh/EHSection.h rename to src/libdyld/eh/EHSection.h diff --git a/src/dyld/tls_helper.nasm b/src/libdyld/tls_helper.nasm similarity index 83% rename from src/dyld/tls_helper.nasm rename to src/libdyld/tls_helper.nasm index dbf3705cf..71ffe9086 100644 --- a/src/dyld/tls_helper.nasm +++ b/src/libdyld/tls_helper.nasm @@ -22,6 +22,7 @@ section .note.GNU-stack noalloc noexec nowrite progbits extern darling_tls_get_native extern darling_tls_allocate +extern _GLOBAL_OFFSET_TABLE_ global darling_tls_get_addr @@ -31,9 +32,10 @@ BITS 64 section text darling_tls_get_addr: - call darling_tls_get_native ; fast three-instruction function - push rdi + call darling_tls_get_native WRT ..plt ; fast three-instruction function + + mov rdi, [rsp] mov rdi, [rdi+8] mov rax, [rax+rdi*8] pop rdi @@ -60,7 +62,7 @@ slow_path: fxsave [rbp-592] mov rdi, [rdi+8] ; pass the pthread_key - call darling_tls_allocate + call darling_tls_allocate WRT ..plt fxrstor [rbp-592] mov r11, [rbp-64] @@ -82,10 +84,18 @@ BITS 32 section text darling_tls_get_addr: + + push ebx + call .get_GOT +.get_GOT: + pop ebx + add ebx, _GLOBAL_OFFSET_TABLE_+$$-.get_GOT wrt ..gotpc + mov ecx, eax ; eax will get destroyed - call darling_tls_get_native ; fast three-instruction function push ecx + call darling_tls_get_native WRT ..plt ; fast three-instruction function + mov ecx, [esp] mov ecx, [ecx+4] ; add the pthread key mov eax, [eax+ecx*4] ; read the value at the key @@ -94,16 +104,20 @@ darling_tls_get_addr: pop ecx add eax, [ecx+8] ; add the offset + + pop ebx ret slow_path: mov ecx, [esp] push dword [ecx+4] ; pass the pthread_key - call darling_tls_allocate + call darling_tls_allocate WRT ..plt pop ecx pop ecx add eax, [ecx+8] ; add the offset + + pop ebx ret %else diff --git a/src/dyld/trampoline_helper.nasm b/src/libdyld/trampoline_helper.nasm similarity index 100% rename from src/dyld/trampoline_helper.nasm rename to src/libdyld/trampoline_helper.nasm diff --git a/src/libobjcdarwin/ClassRegister.cpp b/src/libobjcdarwin/ClassRegister.cpp index 8213943cb..90ea171fa 100644 --- a/src/libobjcdarwin/ClassRegister.cpp +++ b/src/libobjcdarwin/ClassRegister.cpp @@ -1,5 +1,5 @@ #include "ClassRegister.h" -#include +#include #include #ifndef OBJC_ABI_2 diff --git a/src/libobjcdarwin/common/cfstring.cpp b/src/libobjcdarwin/common/cfstring.cpp index 8a8b16797..d7e8ca595 100644 --- a/src/libobjcdarwin/common/cfstring.cpp +++ b/src/libobjcdarwin/common/cfstring.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/libobjcdarwin/common/method.h b/src/libobjcdarwin/common/method.h index dd2279f43..e619425fc 100644 --- a/src/libobjcdarwin/common/method.h +++ b/src/libobjcdarwin/common/method.h @@ -2,6 +2,11 @@ #define COMMON_METHOD_H #include #include +#include +#include +#include +#include +#include "selector.h" extern std::queue> g_pendingInitClasses; @@ -18,8 +23,14 @@ template void ConvertMethodListGen(Class c, const ListType* l LOG << "Method: selName: " << m->selName << "; types: " << m->types << "; impl: " << m->impl << std::endl; - SEL sel = sel_registerTypedName_np(m->selName, m->types); - class_addMethod(c, sel, imp, m->types); + SEL sel; + std::string selType = m->types; + + ConvertSelectorType(selType); + + sel = sel_registerTypedName_np(m->selName, selType.c_str()); + + class_addMethod(c, sel, imp, selType.c_str()); if (isMeta && strcmp(m->selName, "load") == 0) g_pendingInitClasses.push(std::make_pair((Class)c, *imp)); diff --git a/src/libobjcdarwin/common/selector.cpp b/src/libobjcdarwin/common/selector.cpp index a40ef3e36..7967ced52 100644 --- a/src/libobjcdarwin/common/selector.cpp +++ b/src/libobjcdarwin/common/selector.cpp @@ -1,8 +1,10 @@ #include "selector.h" #include "../new/AppleLayout.h" #include "../old/AppleLayout.h" -#include +#include #include +#include +#include void UpdateSelectors(const struct mach_header* mh, intptr_t slide) { @@ -48,3 +50,30 @@ void UpdateSelectors(const struct mach_header* mh, intptr_t slide) } #endif } + + +static const std::pair equivalentTypes[] = { + std::make_pair("CGRect", "_NSRect"), + std::make_pair("CGPoint", "_NSPoint"), + std::make_pair("CGSize", "_NSSize") +}; + +void ConvertSelectorType(std::string& selType) +{ + bool changed = false; + for (auto p : equivalentTypes) + { + size_t pos; + + while ((pos = selType.find(p.first)) != std::string::npos) + { + selType.replace(pos, strlen(p.first), p.second); + changed = true; + } + } + + if (changed) + LOG << "convertSelectorType: new type info is " << selType << std::endl; +} + + diff --git a/src/libobjcdarwin/common/selector.h b/src/libobjcdarwin/common/selector.h index 08d228f86..f34657d4a 100644 --- a/src/libobjcdarwin/common/selector.h +++ b/src/libobjcdarwin/common/selector.h @@ -2,7 +2,9 @@ #define COMMON_SELECTOR_H #include #include +#include void UpdateSelectors(const struct mach_header* mh, intptr_t slide); +void ConvertSelectorType(std::string& selType); #endif diff --git a/src/libobjcdarwin/new/category.h b/src/libobjcdarwin/new/category.h index 76ceb83c6..fc9c781de 100644 --- a/src/libobjcdarwin/new/category.h +++ b/src/libobjcdarwin/new/category.h @@ -3,7 +3,7 @@ #include "./AppleLayout.h" #include #include -#include +#include void ProcessCategoriesNew(const struct mach_header* mh, intptr_t slide); diff --git a/src/libobjcdarwin/new/class.cpp b/src/libobjcdarwin/new/class.cpp index fe6dfe201..cb8754999 100644 --- a/src/libobjcdarwin/new/class.cpp +++ b/src/libobjcdarwin/new/class.cpp @@ -48,6 +48,7 @@ Class RegisterClass(const class_t* cls, intptr_t slide) // conv->isa->instance_size = roMeta->instSize; objc_registerClassPair(conv); + LOG << "ObjC class " << cls->data()->className << " now @" << conv << std::endl; g_classPointers[cls] = conv; g_classPointers[cls->isa] = object_getClass(id(conv)); diff --git a/src/libobjcdarwin/new/class.h b/src/libobjcdarwin/new/class.h index aeed8f2a8..f6667bbea 100644 --- a/src/libobjcdarwin/new/class.h +++ b/src/libobjcdarwin/new/class.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include Class RegisterClass(const class_t* cls, intptr_t slide); std::vector ProcessClassesNew(const struct mach_header* mh, intptr_t slide, const class_t** classes, unsigned long size); diff --git a/src/libobjcdarwin/new/protocol.cpp b/src/libobjcdarwin/new/protocol.cpp index 57e7fba99..164d14815 100644 --- a/src/libobjcdarwin/new/protocol.cpp +++ b/src/libobjcdarwin/new/protocol.cpp @@ -1,7 +1,7 @@ #include "./protocol.h" #include #include -#include +#include #include "../common/ref.h" #include "../common/property.h" #include "../TopologySort.h" diff --git a/src/libobjcdarwin/old/category.h b/src/libobjcdarwin/old/category.h index 8b87e9d74..aaaedd6a2 100644 --- a/src/libobjcdarwin/old/category.h +++ b/src/libobjcdarwin/old/category.h @@ -4,7 +4,7 @@ #include "./AppleLayout.h" #include #include -#include +#include void ProcessCategoriesOld(const struct mach_header* mh, intptr_t slide, module_info* modinfo); diff --git a/src/libobjcdarwin/old/class.h b/src/libobjcdarwin/old/class.h index 195f85664..91ede5fd6 100644 --- a/src/libobjcdarwin/old/class.h +++ b/src/libobjcdarwin/old/class.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include Class RegisterClass(old_class* cls, bool hasExt); std::vector ProcessClassesOld(const struct mach_header* mh, intptr_t slide, module_info* info); diff --git a/src/libobjcdarwin/old/protocol.h b/src/libobjcdarwin/old/protocol.h index b46db4b17..e0e1761b5 100644 --- a/src/libobjcdarwin/old/protocol.h +++ b/src/libobjcdarwin/old/protocol.h @@ -3,7 +3,7 @@ #include "./AppleLayout.h" #include #include -#include +#include void RegisterProtocolMethods(Protocol* p, const old_method_decl_list* list, bool required, bool instance); Protocol* RegisterProtocol(old_protocol* prot, uintptr_t extStart, unsigned long extLen);