this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Objective-C exceptions support, new unit tests Complete ObjC ABI 1/2 compilation split

+380 -40
+7 -1
CMakeLists.txt
··· 8 8 if (SUFFIX) 9 9 set(MULTILIB TRUE) 10 10 endif (SUFFIX) 11 + if(CMAKE_SIZEOF_VOID_P EQUAL 4 OR SUFFIX STREQUAL "32") 12 + set(BITS 32) 13 + else(CMAKE_SIZEOF_VOID_P EQUAL 4 OR SUFFIX STREQUAL "32") 14 + set(BITS 64) 15 + endif(CMAKE_SIZEOF_VOID_P EQUAL 4 OR SUFFIX STREQUAL "32") 16 + 17 + message(STATUS "This is a ${BITS}-bit build") 11 18 12 19 if (SUFFIX STREQUAL "32") 13 - message(STATUS "This is a 32bit build") 14 20 set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -m32") 15 21 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") 16 22 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
+8
src/dyld/arch.h
··· 17 17 18 18 typedef uint32_t intptr; 19 19 20 + #elif defined(__arm__) 21 + # define ARCH_NAME "arm" 22 + # define ARCH_CROSS_NAME "" 23 + # define DYLD_FULL_NAME "dyld" 24 + # define DYLD_CROSS_NAME "dyld" 25 + 26 + typedef uint32_t intptr; 27 + 20 28 #else 21 29 # error Unsupported platform 22 30 #endif
+4 -1
src/dyld/dyld.cpp
··· 52 52 { 53 53 if (argc == 1) 54 54 { 55 - std::cerr << "This is Darwin dyld for " ARCH_NAME ". "; 55 + std::cerr << "This is Darling dyld for " ARCH_NAME ".\n"; 56 + std::cerr << "Copyright (C) 2012 Lubos Dolezel\n" 57 + "Copyright (C) 2011 Shinichiro Hamaji\n\n"; 58 + 56 59 std::cerr << "Usage: " << argv[0] << " program-path [arguments...]\n\n"; 57 60 std::cerr << "Environment variables:\n" 58 61 "\tDYLD_DEBUG=1 - enable debug info (lots of output)\n"
+30 -12
src/libobjcdarwin/CMakeLists.txt
··· 11 11 # message(FATAL_ERROR "Clang is the only supported compiler.") 12 12 #endif (NOT "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang") 13 13 14 - #configure_file(config.h.in config.h) 14 + configure_file(config.h.in config.h) 15 15 16 16 add_definitions(-D__STDC_LIMIT_MACROS) 17 + 18 + if (BITS EQUAL 64) # Would need to be extended for ARM 19 + set(OBJC_ABI_2 TRUE) 20 + endif(BITS EQUAL 64) 17 21 18 22 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -fPIC -fvisibility=hidden -ggdb") 19 23 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fPIC -fvisibility=hidden -ggdb") ··· 23 27 objc_msgSend_fixup.nasm 24 28 objc_msgSendSuper.nasm 25 29 objc_msgSend.nasm 30 + 26 31 NameTranslate.cpp 27 32 ClassRegister.cpp 28 33 TrampolineHelper.mm ··· 32 37 common/selector.cpp 33 38 common/cfstring.cpp 34 39 35 - old/category.cpp 36 - old/class.cpp 37 - old/ivar.mm 38 - old/protocol.cpp 39 - 40 - new/category.cpp 41 - new/class.cpp 42 - new/ivar.cpp 43 - new/protocol.cpp 44 - 45 40 NSBundle_dyld.mm 46 - #NSCFString.mm 47 41 misc.mm 48 42 zero.c 49 43 ) 44 + 45 + if(NOT OBJC_ABI_2) 46 + set(objcdarwin_SRCS 47 + ${objcdarwin_SRCS} 48 + 49 + old/exceptions.cpp 50 + old/category.cpp 51 + old/class.cpp 52 + old/ivar.mm 53 + old/protocol.cpp 54 + ) 55 + else(NOT OBJC_ABI_2) 56 + set(objcdarwin_SRCS 57 + ${objcdarwin_SRCS} 58 + 59 + new/exceptions.cpp 60 + new/category.cpp 61 + new/class.cpp 62 + new/ivar.cpp 63 + new/protocol.cpp 64 + 65 + new/return.nasm 66 + ) 67 + endif(NOT OBJC_ABI_2) 50 68 51 69 add_library(objc.A.dylib SHARED ${objcdarwin_SRCS}) 52 70 target_link_libraries(objc.A.dylib -l:libobjc.so.4 -lgnustep-base -l:../../libutil.a)
+26 -24
src/libobjcdarwin/ClassRegister.cpp
··· 1 + #include "config.h" 1 2 #include "ClassRegister.h" 2 3 #include "../dyld/public.h" 3 4 #include "../util/trace.h" 4 5 #include "../util/log.h" 5 - #include "old/protocol.h" 6 - #include "new/protocol.h" 7 - #include "old/class.h" 8 - #include "new/class.h" 9 - #include "old/category.h" 10 - #include "new/category.h" 6 + 7 + #ifndef OBJC_ABI_2 8 + # include "old/protocol.h" 9 + # include "old/class.h" 10 + # include "old/category.h" 11 + #else 12 + # include "new/protocol.h" 13 + # include "new/class.h" 14 + # include "new/category.h" 15 + #endif 11 16 #include "common/selector.h" 12 17 #include "common/cfstring.h" 13 18 #include <map> ··· 37 42 void ProcessImageLoad(const struct mach_header* mh, intptr_t slide) 38 43 { 39 44 unsigned long size; 40 - const class_t** classes; 41 45 46 + #ifdef OBJC_ABI_2 47 + const class_t** classes; 42 48 ProcessProtocolsNew(mh, slide); 43 - ProcessProtocolsOld(mh, slide); 44 49 45 50 classes = reinterpret_cast<const class_t**>( 46 51 getsectdata(mh, SEG_OBJC_CLASSLIST_NEW, SECT_OBJC_CLASSLIST_NEW, &size) 47 52 ); 53 + if (classes) 54 + ProcessClassesNew(mh, slide, classes, size); 48 55 49 - if (!classes) 50 - { 51 - // Try the old runtime 52 - module_info* modinfo; 56 + ProcessCategoriesNew(mh, slide); 57 + #else 58 + module_info* modinfo; 59 + ProcessProtocolsOld(mh, slide); 53 60 54 - modinfo = reinterpret_cast<module_info*>( 55 - getsectdata(mh, SEG_OBJC_MODINFO_OLD, SECT_OBJC_MODINFO_OLD, &size) 56 - ); 61 + modinfo = reinterpret_cast<module_info*>( 62 + getsectdata(mh, SEG_OBJC_MODINFO_OLD, SECT_OBJC_MODINFO_OLD, &size) 63 + ); 57 64 58 - if (modinfo) 59 - { 60 - ProcessClassesOld(mh, slide, modinfo); 61 - ProcessCategoriesOld(mh, slide, modinfo); 62 - } 63 - } 64 - else 65 + if (modinfo) 65 66 { 66 - ProcessClassesNew(mh, slide, classes, size); 67 + ProcessClassesOld(mh, slide, modinfo); 68 + ProcessCategoriesOld(mh, slide, modinfo); 67 69 } 70 + #endif 68 71 69 - ProcessCategoriesNew(mh, slide); 70 72 UpdateSelectors(mh, slide); 71 73 UpdateCFStrings(mh); 72 74 }
+25 -2
src/libobjcdarwin/NameTranslate.cpp
··· 1 1 #include <cstring> 2 2 #include <memory> 3 3 #include <dlfcn.h> 4 + #include <cstdio> 5 + #include "visibility.h" 4 6 5 - __attribute__((visibility ("default"))) extern "C" void* _objc_empty_cache = 0; 6 - __attribute__((visibility ("default"))) extern "C" void* _objc_empty_vtable = 0; 7 + DARLING_VISIBLE extern "C" void* _objc_empty_cache = 0; 8 + DARLING_VISIBLE extern "C" void* _objc_empty_vtable = 0; 9 + 10 + #ifdef __x86_64__ 11 + DARLING_VISIBLE extern "C" void* _objc_dummy_ehtype = 0; 12 + #endif 7 13 8 14 namespace Darling 9 15 { ··· 28 34 29 35 static bool ClassTranslator(char* name) 30 36 { 37 + #ifdef __x86_64__ 38 + if (strncmp(name, "OBJC_EHTYPE_$_", 14) == 0) 39 + { 40 + strcpy(name, "_objc_dummy_ehtype"); 41 + return true; 42 + } 43 + else 44 + #endif 45 + 31 46 if (char* off = strstr(name, "_$_")) 32 47 { 33 48 size_t offset = off - name; ··· 40 55 41 56 return true; 42 57 } 58 + // Or we could create a variable like this and memcpy the objc_class 43 59 else if (strcmp(name, "__CFConstantStringClassReference") == 0) 44 60 { 45 61 strcpy(name, "_OBJC_CLASS_NSCFString"); 46 62 return true; 47 63 } 64 + #ifdef __x86_64__ 65 + else if (strcmp(name, "__objc_personality_v0") == 0) 66 + { 67 + strcpy(name, "__gnu_objc_personality_v0"); 68 + return true; 69 + } 70 + #endif 48 71 49 72 return false; 50 73 }
+27
src/libobjcdarwin/new/exceptions.cpp
··· 1 + #include "exceptions.h" 2 + #include "return.h" 3 + 4 + extern "C" void __cxa_rethrow(); 5 + extern "C" void* __cxa_begin_catch(void*); 6 + extern "C" void __cxa_end_catch(); 7 + 8 + void objc_exception_rethrow() 9 + { 10 + __cxa_rethrow(); 11 + } 12 + 13 + void* objc_begin_catch(void* p) 14 + { 15 + void *rv = returnReturn(); 16 + void* cpp = __cxa_begin_catch(p); 17 + if (cpp) 18 + return cpp; 19 + else 20 + return rv; 21 + } 22 + 23 + void objc_end_catch() 24 + { 25 + __cxa_end_catch(); 26 + } 27 +
+14
src/libobjcdarwin/new/exceptions.h
··· 1 + #ifndef OBJC_EXCEPTIONS_H 2 + #define OBJC_EXCEPTIONS_H 3 + #include "../visibility.h" 4 + 5 + extern "C" { 6 + 7 + DARLING_VISIBLE void objc_exception_rethrow(); 8 + DARLING_VISIBLE void* objc_begin_catch(void*); 9 + DARLING_VISIBLE void objc_end_catch(); 10 + 11 + } 12 + 13 + #endif 14 +
+9
src/libobjcdarwin/new/return.h
··· 1 + #ifndef OBJC_RETURN_H 2 + #define OBJC_RETURN_H 3 + 4 + // Does nothing, but given it's signature, it will actually return 5 + // the last return value (contents of eax/rax on x86) 6 + extern "C" void* returnReturn(); 7 + 8 + #endif 9 +
+8
src/libobjcdarwin/new/return.nasm
··· 1 + section .note.GNU-stack noalloc noexec nowrite progbits 2 + section text 3 + 4 + global returnReturn 5 + 6 + returnReturn: 7 + ret 8 +
+2
src/libobjcdarwin/objc_msgSend.nasm
··· 2 2 3 3 extern objc_msgSend 4 4 5 + section .note.GNU-stack noalloc noexec nowrite progbits 6 + 5 7 %ifidn __OUTPUT_FORMAT__, elf64 6 8 7 9 BITS 64
+2
src/libobjcdarwin/objc_msgSendSuper.nasm
··· 3 3 global __darwin_objc_msgSendSuper2_stret 4 4 extern objc_msg_lookup_super 5 5 6 + section .note.GNU-stack noalloc noexec nowrite progbits 7 + 6 8 %ifidn __OUTPUT_FORMAT__, elf64 7 9 8 10 BITS 64
+2
src/libobjcdarwin/objc_msgSend_fixup.nasm
··· 1 1 global __darwin_objc_msgSend_fixup 2 2 extern objc_msgSend 3 3 4 + section .note.GNU-stack noalloc noexec nowrite progbits 5 + 4 6 %ifidn __OUTPUT_FORMAT__, elf64 5 7 6 8 BITS 64
+64
src/libobjcdarwin/old/exceptions.cpp
··· 1 + #include "exceptions.h" 2 + #include <cstdlib> 3 + #include <iostream> 4 + #include "../util/trace.h" 5 + 6 + static __thread TryBlock* m_lastBlock = nullptr; 7 + 8 + void __darwin_objc_exception_throw(objc_object* object) 9 + { 10 + TRACE1(object); 11 + 12 + if (!object) 13 + { 14 + std::cerr << "NULL Objective-C exception thrown!\n"; 15 + abort(); 16 + } 17 + 18 + if (!m_lastBlock) 19 + { 20 + std::cerr << "Unhandled Objective-C exception: " << class_getName(object_getClass(object)) << '(' << object << ")\n"; 21 + abort(); 22 + } 23 + else 24 + { 25 + m_lastBlock->exceptionObject = object; 26 + longjmp(m_lastBlock->buffer, true); 27 + } 28 + } 29 + 30 + void objc_exception_try_enter(TryBlock* state) 31 + { 32 + TRACE1(state); 33 + state->previousBlock = m_lastBlock; 34 + m_lastBlock = state; 35 + } 36 + 37 + void objc_exception_try_exit(TryBlock* state) 38 + { 39 + TRACE1(state); 40 + m_lastBlock = state->previousBlock; 41 + } 42 + 43 + void* objc_exception_extract(TryBlock* state) 44 + { 45 + TRACE1(state); 46 + return m_lastBlock->exceptionObject; 47 + } 48 + 49 + int objc_exception_match(objc_class* cls, objc_object* object) 50 + { 51 + TRACE2(cls, object); 52 + objc_class* objClass = object_getClass(object); 53 + 54 + while (objClass) 55 + { 56 + if (objClass == cls) 57 + return true; 58 + else 59 + objClass = class_getSuperclass(objClass); 60 + } 61 + 62 + return false; 63 + } 64 +
+49
src/libobjcdarwin/old/exceptions.h
··· 1 + #ifndef OBJC_EXCEPTIONS_H 2 + #define OBJC_EXCEPTIONS_H 3 + #include <objc/runtime.h> 4 + #include <setjmp.h> 5 + #include "../visibility.h" 6 + 7 + // Apple 32-bit ObjC ABI doesn't use Itanium ABI zero-cost exceptions. 8 + // Instead, every try block is registered and deregistered, every catch 9 + // block is tested for usability with a runtime function call and if no 10 + // match is found, the exception is thrown again to traverse the try 11 + // block chain. 12 + 13 + struct TryBlock 14 + { 15 + jmp_buf buffer; 16 + 17 + union 18 + { 19 + void* fourPointers[4]; 20 + 21 + struct 22 + { 23 + objc_object* exceptionObject; 24 + TryBlock* previousBlock; 25 + }; 26 + }; 27 + }; 28 + 29 + extern "C" { 30 + 31 + // This function is called repeatedly until a handler is found 32 + DARLING_VISIBLE void __darwin_objc_exception_throw(objc_object* object); 33 + 34 + // Called on every @try { 35 + DARLING_VISIBLE void objc_exception_try_enter(TryBlock* state); 36 + 37 + // Called on every } of a @try block 38 + DARLING_VISIBLE void objc_exception_try_exit(TryBlock* state); 39 + 40 + // Called to get the exception object 41 + DARLING_VISIBLE void* objc_exception_extract(TryBlock* state); 42 + 43 + // Called to check if the handler's type is appropriate for the exception object 44 + DARLING_VISIBLE int objc_exception_match(objc_class* cls, objc_object* object); 45 + 46 + } 47 + 48 + #endif 49 +
+31
tests/src/fstream.cpp
··· 1 + #include <fstream> 2 + #include <iostream> 3 + #include <unistd.h> 4 + #include <cstring> 5 + #include <cstdio> 6 + #include <ext/stdio_filebuf.h> 7 + 8 + int main() 9 + { 10 + //__gnu_cxx::stdio_filebuf<char> out; 11 + std::ifstream in; 12 + const char* text = "Hello world"; 13 + const char* file = "/tmp/__test123"; 14 + char buf[100]; 15 + 16 + //out.open(file, std::ios_base::out | std::ios_base::binary); 17 + __gnu_cxx::stdio_filebuf<char> out(fopen(file, "w+b"), std::ios_base::out|std::ios_base::binary); 18 + out.sputn(text, strlen(text)); 19 + out.close(); 20 + 21 + in.open(file); 22 + in.getline(buf, 100); 23 + in.close(); 24 + 25 + std::cout << "sizeof: " << sizeof(out) << std::endl; 26 + std::cout << buf << std::endl; 27 + unlink(file); 28 + 29 + return 0; 30 + } 31 +
+48
tests/src/maclocales.m
··· 1 + // -framework foundation -framework corefoundation -framework coreservices 2 + // http://www.cocoabuilder.com/archive/cocoa/144537-human-readable-locale-names.html 3 + 4 + #import <Foundation/Foundation.h> 5 + #import <CoreServices/CoreServices.h> 6 + #include <stdio.h> 7 + 8 + int main (int argc, const char * argv[]) { 9 + 10 + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 11 + 12 + //NSString *identifier = [[NSLocale currentLocale] localeIdentifier]; 13 + //char localeString[12]; 14 + //BOOL ok = [identifier getCString:localeString maxLength:12 encoding:NSASCIIStringEncoding]; 15 + 16 + OSStatus status; 17 + LocaleRef locale; 18 + // status = LocaleRefFromLocaleString (localeString, &locale); 19 + status = LocaleRefFromLocaleString ("es_ES", &locale); 20 + 21 + LocaleRef displayLocale; 22 + // status = LocaleRefFromLocaleString(localeString, &displayLocale); 23 + status = LocaleRefFromLocaleString("es_ES", &displayLocale); 24 + 25 + UniCharCount maxNameLen = 256; 26 + UniCharCount actualNameLen; 27 + UniChar displayName[256]; 28 + 29 + status = LocaleGetName (locale, 30 + 0, // LocaleOperationVariant opVariant 31 + kLocaleAndVariantNameMask, // LocaleNameMask nameMask 32 + displayLocale, 33 + maxNameLen, // UniCharCount maxNameLen 34 + &actualNameLen, // UniCharCount * actualNameLen 35 + displayName); // UniChar displayName[] 36 + 37 + NSString *displayString = 38 + [NSString stringWithCharacters:displayName 39 + length:actualNameLen]; 40 + //NSLog(@"identifier: %@", identifier); 41 + //NSLog(@"localeString: %s", localeString); 42 + //NSLog(@"displayString: %@", displayString); 43 + puts([displayString UTF8String]); 44 + 45 + [pool release]; 46 + return 0; 47 + } 48 +
+24
tests/src/objc_exception.m
··· 1 + // CFLAGS: -framework foundation 2 + #include <stdio.h> 3 + #import <Foundation/NSException.h> 4 + #import <Foundation/NSAutoreleasePool.h> 5 + 6 + int main() 7 + { 8 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 9 + @try 10 + { 11 + @throw([NSException exceptionWithName: @"MyException" reason:@"Test" userInfo:nil]); 12 + } 13 + @catch(NSException* e) 14 + { 15 + puts([[e name] UTF8String]); 16 + } 17 + @finally 18 + { 19 + puts("Finally"); 20 + } 21 + [pool release]; 22 + return 0; 23 + } 24 +