Giter Site home page Giter Site logo

showxu / objc4 Goto Github PK

View Code? Open in Web Editor NEW
533.0 533.0 89.0 1.25 MB

A latest buildable and debuggable Objective-C runtime (objc4-818.2) project.

Home Page: https://opensource.apple.com/tarballs/objc4/

License: MIT License

C++ 13.52% Batchfile 0.06% Assembly 7.53% Objective-C 27.94% Objective-C++ 37.75% C 10.34% DTrace 0.01% Rich Text Format 0.64% Shell 0.03% Perl 1.94% SWIG 0.21% Roff 0.02%
dyld objc objc-723 objc-779 objc-781 objc-787 objc-818 objc-818-2 objc-runtime objc4 objc4-723 objc4-779 objc4-781 objc4-787 objc4-818 objc4-818-2 objc4-runtime runtime xnu

objc4's Introduction

Curious and passionate! ๐Ÿ‘‹

Open Source Projects

Maintainer of swift-library

About me

  • ๐Ÿ”ญ Iโ€™m currently working at Tencent.
  • ๐ŸŽฎ I'm currently working on something cool.
  • ๐Ÿ“ซ How to reach me: [email protected]

showxu's github stats

objc4's People

Contributors

showxdxu avatar showxu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

objc4's Issues

Track of macOS 14.4 + Xcode 15.2 build issue

  1. We need the following patch to make it compile on the latest Xcode.
// objc-os.h
+ #include <utility>
  1. Once we run objc-inspect, we'll get a crash on _objc_init -> _dyld_objc_notify_register.
img_v3_028t_e7d94619-93c1-4999-9abe-fd651232166g

The abort message is "_dyld_objc_notify_register is unsupported"

Checking the latest dyld's source code, the API is still there and suggesting we move to use "_dyld_objc_register_callbacks".

https://github.com/apple-oss-distributions/dyld/blob/d1a0f6869ece370913a3f749617e457f3b4cd7c4/dyld/DyldAPIs.cpp#L876-L877
// FIXME: Remove this once libobjc moves to _dyld_objc_register_callbacks()

The latest SDK's dyld has changed it and make it abort here.

Checking the latest objc code, they did change to use _dyld_objc_register_callbacks here.

https://github.com/apple-oss-distributions/objc4/blob/196363c165b175ed925ef6b9b99f558717923c47/runtime/objc-os.mm#L934

So the final answer is we need to update the objc source to debug it on the latest OS due to the API change in dylb.

Don't comment them out

I figured out how <os/feature_private.h> was, and those dyld magic values.

https://github.com/Torrekie/apple_internal_sdk

I started working on this while compiling latest objc4 for porting it to older iOS. Commenting out featureflag and OS detection codes was really a bad idea since it ACTUALLY affecting how libobjc works. The reason I am doing this is, I can't find any useful information except bunch copies of articles telling me to comment these undefined values out, no, don't do that.

These undefined values and undeclared functions can be easily figured out by simple searching or reversing. For that non-open feature_private.h, I have done that here.

And for those dyld version check constants, they should originally be in <mach-o/dyld_priv.h> but stripped out by Apple. They are simple structs containing two uint32_t values referring to platforms and versions.

typedef uint32_t dyld_platform_t;

typedef struct {
    dyld_platform_t platform;
    uint32_t        version;
} dyld_build_version_t;

These are actual values of those dyld_fall_20*_os_versions stuff

// Sat Mar 26 18:48:53 CST 2022
// reversed from /usr/lib/libobjc.A.dylib and /usr/lib/system/libcommonCrypto.dylib
// Also tested
#define dyld_fall_2017_os_versions		(dyld_build_version_t) { 0xFFFFFFFF, 0x07E10901 }
#define dyld_fall_2018_os_versions		(dyld_build_version_t) { 0xFFFFFFFF, 0x07E20901 }
#define dyld_fall_2019_os_versions		(dyld_build_version_t) { 0xFFFFFFFF, 0x07E30901 }
#define dyld_fall_2020_os_versions		(dyld_build_version_t) { 0xFFFFFFFF, 0x07E40901 }
#define dyld_fall_2021_os_versions		(dyld_build_version_t) { 0xFFFFFFFF, 0x07E50901 }

#define dyld_platform_version_macOS_10_11       (dyld_build_version_t) { PLATFORM_MACOS, 0x000A0B00 }
#define dyld_platform_version_macOS_10_12       (dyld_build_version_t) { PLATFORM_MACOS, 0x000A0C00 }
#define dyld_platform_version_macOS_10_13	(dyld_build_version_t) { PLATFORM_MACOS, 0x000A0D00 }
#define dyld_platform_version_macOS_10_14	(dyld_build_version_t) { PLATFORM_MACOS, 0x000A0E00 }
#define dyld_platform_version_macOS_10_15	(dyld_build_version_t) { PLATFORM_MACOS, 0x000A0F00 }
#define dyld_platform_version_macOS_10_16	(dyld_build_version_t) { PLATFORM_MACOS, 0x000A1000 }
#define dyld_platform_version_macOS_12_00	(dyld_build_version_t) { PLATFORM_MACOS, 0x000C0000 }

#define dyld_platform_version_tvOS_10_0         (dyld_build_version_t) { PLATFORM_TVOS, 0x000A0000 }
#define dyld_platform_version_tvOS_11_0         (dyld_build_version_t) { PLATFORM_TVOS, 0x000B0000 }
#define dyld_platform_version_tvOS_12_0		(dyld_build_version_t) { PLATFORM_TVOS, 0x000C0000 }
#define dyld_platform_version_tvOS_13_0		(dyld_build_version_t) { PLATFORM_TVOS, 0x000D0000 }
#define dyld_platform_version_tvOS_14_0		(dyld_build_version_t) { PLATFORM_TVOS, 0x000E0000 }
#define dyld_platform_version_tvOS_15_0		(dyld_build_version_t) { PLATFORM_TVOS, 0x000F0000 }

#define dyld_platform_version_iOS_10_0          (dyld_build_version_t) { PLATFORM_IOS, 0x000A0000 }
#define dyld_platform_version_iOS_11_0          (dyld_build_version_t) { PLATFORM_IOS, 0x000B0000 }
#define dyld_platform_version_iOS_12_0		(dyld_build_version_t) { PLATFORM_IOS, 0x000C0000 }
#define dyld_platform_version_iOS_13_0		(dyld_build_version_t) { PLATFORM_IOS, 0x000D0000 }
#define dyld_platform_version_iOS_14_0		(dyld_build_version_t) { PLATFORM_IOS, 0x000E0000 }
#define dyld_platform_version_iOS_15_0		(dyld_build_version_t) { PLATFORM_IOS, 0x000F0000 }

#define dyld_platform_version_watchOS_3_0       (dyld_build_version_t) { PLATFORM_WATCHOS, 0x00030000 }
#define dyld_platform_version_watchOS_4_0       (dyld_build_version_t) { PLATFORM_WATCHOS, 0x00040000 }
#define dyld_platform_version_watchOS_5_0	(dyld_build_version_t) { PLATFORM_WATCHOS, 0x00050000 }
#define dyld_platform_version_watchOS_6_0	(dyld_build_version_t) { PLATFORM_WATCHOS, 0x00060000 }
#define dyld_platform_version_watchOS_7_0	(dyld_build_version_t) { PLATFORM_WATCHOS, 0x00070000 }
#define dyld_platform_version_watchOS_8_0	(dyld_build_version_t) { PLATFORM_WATCHOS, 0x00080000 }

#define dyld_platform_version_bridgeOS_2_0      (dyld_build_version_t) { PLATFORM_BRIDGEOS, 0x00020000 }
#define dyld_platform_version_bridgeOS_3_0      (dyld_build_version_t) { PLATFORM_BRIDGEOS, 0x00030000 }
#define dyld_platform_version_bridgeOS_4_0      (dyld_build_version_t) { PLATFORM_BRIDGEOS, 0x00040000 }
#define dyld_platform_version_bridgeOS_5_0      (dyld_build_version_t) { PLATFORM_BRIDGEOS, 0x00050000 }
#define dyld_platform_version_bridgeOS_6_0      (dyld_build_version_t) { PLATFORM_BRIDGEOS, 0x00060000 }

Using that CrashReporterClient.h stub which appears in older Libc was not quite a good idea, since linking libCrashReporterClient would insert a load command section to Mach-O files (that also indicates libCrashReporterClient was a static library)


Section
  sectname __crash_info
   segname __DATA
      addr 0x00000001d97f8ad8
      size 0x0000000000000040
    offset 246296
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0

We can find CrashReporterClient implementation under WTF/wtf/spi/cocoa/CrashReporterClientSPI.h and WTF/wtf/cocoa/CrashReporter.cpp, these codes also appears in many other Apple OSSes.

Now we have <CrashReporterClient.h> and libCrashReporterClient.a

For those Cambria APIs, we can see objc-cache.mm was calling two of them

#if TARGET_OS_OSX
        if (oah_is_current_process_translated()) {
            kern_return_t ret = objc_thread_get_rip(threads[count], (uint64_t*)&pc);
            if (ret != KERN_SUCCESS) {
                pc = PC_SENTINEL;
            }
        } else {
            pc = _get_pc_for_thread (threads[count]);
        }
#else
        pc = _get_pc_for_thread (threads[count]);
#endif

It was really easy to figure out that oah_is_current_process_translated() was returning bool, with no arguments, then we have its prototype

bool oah_is_current_process_translated(void);

objc_thread_get_rip() was kinda tricky but still easy to find out how to correctly call it, the definition of thread was
thread_act_port_array_t threads;, and the actual type of thread_act_port_array_t was

// <arm/_types.h> or <i386/_types.h>
typedef unsigned int            __darwin_natural_t;
// <sys/_types.h>
typedef __darwin_natural_t __darwin_mach_port_name_t; /* Used by mach */
typedef __darwin_mach_port_name_t __darwin_mach_port_t; /* Used by mach */
// <sys/_types/_mach_port_t.h>
typedef __darwin_mach_port_t mach_port_t;
// <mach/mach-types.h>
typedef mach_port_t             thread_act_t;
typedef thread_act_t            *thread_act_array_t;
typedef thread_act_array_t      thread_act_port_array_t;

We can see the 1st arg of objc_thread_get_rip() was a member of thread_act_port_array_t, then the type is thread_act_t but not thread_act_port_array_t, then we get prototype

kern_return_t objc_thread_get_rip(thread_act_t thread, uint64_t** buf);

These codes cannot successfully compile without linking liboah, which was not presenting in MacOSX.sdk, we can extract dyld shared cache, get /usr/lib/liboah.dylib, generate liboah.tbd from it. I have done Cambria headers also

Run debug error on mojave

dyld: Symbol not found: _objc_debug_taggedpointer_obfuscator
Referenced from: /usr/lib/system/libxpc.dylib
Expected in: /Users/xxxx/Library/Developer/Xcode/DerivedData/objc-ccgnoycdykfcdtfetssxtbpuvizg/Build/Products/Debug/libobjc.A.dylib
in /usr/lib/system/libxpc.dylib

Add target IOS_PLATFORM debugging support

Currently, both objc-inspect and objc target only support macOS Catalina, support debugging libobjc.A.dylib on iPhone OS and iOS simulator will be helpful for iOS development.

build crash

hi coder
a.can this demo be build ?
b.i just clone this project and add a new target and config dependencies(objc) and comple sources(libobjc.A.dylib).
c. run
this is come to an crash here is the crash message
Assertion failed: (sel_registerName(sel_getName(meth.name())) == meth.name()), function methodizeClass, file objc-runtime-new.mm, line 1536.
is there any soluation?
thanks

crash at cache_init();

dyld: lazy symbol binding failed: Symbol not found: _task_restartable_ranges_register
Referenced from: /Users/hsz/Library/Developer/Xcode/DerivedData/objc-bcmgrkittkwfkggudysyarbtscjy/Build/Products/Debug/libobjc.A.dylib (which was built for Mac OS X 10.15)
Expected in: /usr/lib/libSystem.B.dylib

dyld: Symbol not found: _task_restartable_ranges_register
Referenced from: /Users/hsz/Library/Developer/Xcode/DerivedData/objc-bcmgrkittkwfkggudysyarbtscjy/Build/Products/Debug/libobjc.A.dylib (which was built for Mac OS X 10.15)
Expected in: /usr/lib/libSystem.B.dylib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.