Newsletter # 1 - Objective-C and Swift Interoperability and Mach-O executables Sep 20 2019
Hello,
Another week has gone by trying to figure out how computers work under the hood, and also enjoying dark mode on iOS. I hope you are enjoying the update too. Everything went smooth on the update, the only problem I had was with my reminders.
I make heavy use of reminders, both on my phone and on my laptop. So you can imagine, I was all excited tapping yes to every new popup on my phone. And I didn't pay attention to the warning for Reminders. If you update to the new reminders, you won't be able to see them in macOS until you upgrade to Catalina. My advice, make sure you won't be needing your reminders on macOS before tapping "upgrade".
Oh well, that serves me right for not paying attention to what I accept.
I posted this week about Objective-C and Swift interoperability. You can read the post here:
https://rderik.com/blog/understanding-objective-c-and-swift-interoperability/
I also did some additional research on executable files entry point. When we load our programs, the executable has to point somewhere to the segment of the object that contains the initial code to run(our program's "entry point").
By looking at the structure of a Mach-O executable, I found that
in the Load Commands section (the section right after the header), exists the LC_MAINcommand which specifies the entry point for my executable.
Success!
Not really... I thought that that would be the real entry point. But in reality, every executable starts with dyld::_main it bootstraps everything and starts linking all libraries needed to load our executable. We think the linking process only occurs during runtime after our program has begun execution, but actually, everything starts before our program has really started. Another interesting aspect of Dynamic linking :).
Also, it has always surprised me how fast everything runs in computers. And trying to follow the execution of a program gives me a greater perspective of everything that needs to happen to execute even a simple program.
Well, I hope you have a good weekend and see you next week.
Derik
PS. I was thinking about doing some work on State Machines. I wanted to explain how Regular Expressions work by using state machines, but maybe it'll be a topic for other time. If you have any topics that you'll want me to write about, send me a message, and I'll see if I can put something together.
Tip of the week:
If you want to check the header file of some of the system files, like:
1
<mach-o/loader.h>
You might try to find it in /usr/include/ but the directory was removed from macOS. You'll need the SDK to see them. You can get the path to the SDK using xcrun:
1
$ xcrun --show-sdk-path
In my case:
1
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
Inside you'll find usr/include/mach-o/loader.h and many more :)