Urgent.News

What's breaking now, across thousands of outlets.

Tech

examining the macOS gcc binary

The macOS gcc binary is not a simple alias to clang, as many people assume. Instead, it is a distinct binary with unique functionalities. While it may appear to simply call clang, there are more complex elements at play, such as special logic for identifying whether it's being run as C++ or LLVM-GCC.

One crucial aspect of this binary is a specific line of code that interacts with the libxcselect.dylib library. This library functions similarly to running xcrun, a binary that essentially calls a function within itself. The question then arises: what does xcrun do? It is a tool that allows developers to access various developer tools installed on macOS through the Xcode command-line interface.

Upon examining the man page, it becomes clear that xcrun functions by calling developer tools from the developer tool directory. These tools, including gcc, g++, clang++, llvm-gcc, and cc, are essentially executed through xcrun. To determine the exact location of the gcc binary being called, one can use the --find command within this directory.

Interestingly, the gcc binary ultimately shells out to xcrun, which then calls clang (or clang++ depending on how it's invoked). This behavior likely stems from System Integrity Protection (SIP) on macOS. SIP prevents the macOS /usr/bin directory from being modified without a restart, allowing Apple to update developer tools without requiring a system reboot.

Additionally, Apple may prefer to have the flexibility to modify the developer tools directory as needed, rather than relying on adding the directory to the system PATH.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at zoey-on-github.github.io →

More in Tech

More from Thursday 22 October →