- About the compilation of objc4 source code, there will be a new version in the future. If you want to be the first to be fresh, you need to play it by yourself, and you will learn it by yourself in the future.
- "The content is not important, the angle of analytical thinking exploration" is very important!!! Circle!
1. On the source code of objc4
Can be in Download and compile at Cooci Completed source code
2. Manually experience the source code compilation process
Apple original source download Address
Objc4-824 under macOS 11.3 system is not downloaded, and objc4-824 under 11.2 system is not obtained objc4-818.2 edition
3. Some system files required by the source code
After the source code is obtained, it will face a series of error reporting problems of missing header files obtained by various system libraries. The problems of compiling according to versions such as 750 and 781 can be summarized together. The missing files can be public parts, and the specific differences can be compared by themselves. It is mainly obtained from the following source files. You can try to find it from 0 to 1: you don't want to toss like this after playing for several times.
libpthread
xnu
Libc
dyld
libdispatch
libplatform
libclosure
- The most convenient way is to directly obtain the header file of the corresponding version found on the opening github. Hahaha, each version is slightly different. It's better to find the latest one
4. After obtaining the 818.2 source code, add the header file to the project and configure the search path as shown in the figure
- TARGETS - objc - Build Settings - Search Path add ${SRCROOT}/include path
5. Next, start the journey of solving error reporting
1.Common system errors: unable to find sdk 'macosx.internal'
resolvent:
- Select the current system
- At this moment, when you select TARGETS - objc, you can easily rearrange the binary libobjc Change the Order File path of order to the project path. Otherwise, an error will be reported later. Because Other is a virtual folder, libobjc Order is in the root directory of the project
- The most hidden place is where the script is executed. When we can't find an execution symbol, we should consider whether the script contains. Because of the perspective of God, I know that there will be errors in the script.
- Add macosx Change internal to macosx
2.'os/feature_private.h' file not found
- Comment out the header file
- At the same time, obj runtime OS in mm file_ feature_ enabled_ Comment out the simple call
// if (!os_feature_enabled_simple(objc4, preoptimizedCaches, true)) { // DisablePreoptCaches = true; // }
- The header file references that cannot be found are commented out. Private is generally a private file.
- Use of undeclared identifier 'dyld_fall_2020_os_versions'
//if (!dyld_program_sdk_at_least(dyld_fall_2020_os_versions)) // DisableAutoreleaseCoalescingLRU = true;
4.'objc-bp-assist.h' file not found
Comment out
5.Use of undeclared identifier 'dyld_platform_version_macOS_10_13'
// if (!dyld_program_sdk_at_least(dyld_platform_version_macOS_10_13)) { // DisableInitializeForkSafety = true; // if (PrintInitializing) { // _objc_inform("INITIALIZE: disabling +initialize fork " // "safety enforcement because the app is " // "too old.)"); // } // }
6.Use of undeclared identifier 'dyld_platform_version_macOS_10_11'
// if (!dyld_program_sdk_at_least(dyld_platform_version_macOS_10_11)) { // DisableNonpointerIsa = true; // if (PrintRawIsa) { // _objc_inform("RAW ISA: disabling non-pointer isa because " // "the app is too old."); // } // }
7.Use of undeclared identifier 'dyld_fall_2018_os_versions'
- Delete & & dyld_ program_ sdk_ at_ Least (dyld_fall_2018_os_versions) judgment
8. Common and familiar error use of unclared identifier 'CRGetCrashLogMessage'
The source is crashreporterclient H file.
- If libc is defined according to the previous step of the macro definition_ NO_ Librashreporterclient will be the next macro definition symbol
Go to the Preprocessor Macros precompiler to define this variable
9.'os/linker_set.h' file not found
Comment out the header file reference
//#if !TARGET_OS_WIN32 //#include <os/linker_set.h> //#endif
Comment out the calling code
// LINKER_SET_FOREACH(_dupi, const objc_duplicate_class **, "__objc_dupclass") { // const objc_duplicate_class *dupi = *_dupi; // // if (strcmp(dupi->name, name) == 0) { // return; // } // }
10,'Cambria/Traps.h' file not found
#if TARGET_OS_OSX //#include <Cambria/Traps.h> //#include <Cambria/Cambria.h> #endif
Correspondingly, comment out the calling code and oah_is_current_process_translated, thread execution place of reserved call
// Find out where thread is executing //#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
11.LINKER_SET_FOREACH
12.Use of undeclared identifier 'dyld_platform_version_bridgeOS_2_0'
Compatibility code of old SDK
- Comment out
// if (DebugPoolAllocation || sdkIsAtLeast(10_12, 10_0, 10_0, 3_0, 2_0)) { // // OBJC_DEBUG_POOL_ALLOCATION or new SDK. Bad pop is fatal. // _objc_fatal // ("Invalid or prematurely-freed autorelease pool %p.", token); // }
13. Finally, the familiar library not found did not find the symbol. What symbol?
- -lCrashReporterClient
- Come to our Build Settings – Other Linker Flags and kill it
14. Library not found for - load similarly, you know what I mean? See the previous step: delete - load.
6. After solving the above problems, Build Success!!! Familiar?
-
In fact, what I want to say is that we want objc dynamic link library
-
We can see that the other library that Build Phases relies on is objc trampolines, so other irrelevant libraries that cannot run can be killed.
-
Objc simulator can also be retained because it depends on objc.
-
After deletion, don't forget to delete the files in Edit Scheme
-
Edit Scheme – Manage Schemes
-
At this time, think about whether the compressed storage of the project is a little small...
7. Create a debug Target at this time
- Select this Target – add objc dependency in Build Phases.
8. Commissioning and operation
- Create an HSPerson class in main The breakpoint is called in M.
- Step into and you will find a new world~~~
- Run into the small breakpoint of the source code.
9. Hide file
- I compiled successfully, hide the file, you know?
10. The fourth exploration means LLDB debugging. Do you want to play it?
- For regular expression breakpoints under alloc related functions
- Method 1: do not specify the library file and debug after downloading
`(lldb) breakpoint set --func-regex (.*)[a|A]llo[c|C](.*) Breakpoint 2: 82902 locations.`
- Method 2: specify the library file, open the God perspective, and know that the library file corresponding to objc is libobjc A.dylib
- First clear the previous breakpoints, br list, and of course, br delete
(lldb) breakpoint set --func-regex (.*)[a|A]llo[c|C](.*) -s libobjc.A.dylib Breakpoint 3: 515 locations. libobjc.A.dylib was compiled with optimization - stepping may behave oddly; variables may not be available.
Specifically, simplify the breakpoint, summarize the regular expression according to the specific method, and be interested in playing by yourself. Have you learned it?