examining the macOS gcc binary

39 points by juliethefoxcoon 8 hours ago on lobsters | 5 comments

ema-pe | 5 hours ago

Wow! So, if I understand correctly the binary is actually clang, but it disguises itself as gcc for compatibility purposes?

athas | an hour ago

Yes, and it is terrible, because it is not actually compatible. I teach a basic course on systems programming, and every year my poor macOS-using students have issues because I give them some gcc-specific code or command and then they get weird errors. When they then try to install GCC (the actual one) with Homebrew or whatnot, they have to learn about PATH shenanigans to ensure that the gcc they get is actually the real one. I also remember some issue about linking against the wrong libc. Even the Windows users have a better experience because they just install WSL.

The macOS gcc binary is basically a liar. I think humans that lie are bad, and I also think programs that lie are bad.

gignico | 5 hours ago

Yes, lots of old makefiles out there just calling gcc assuming it’s the only one. Or even simply people following C programming tutorials that assume gcc is there

citizen428 | 15 minutes ago

Sure. But a better way to deal with this would be a shim pointing the user in the right direction, not clang pretending to be gcc.

madsmtm | an hour ago

Having trampoline binaries like this is a surprisingly common pattern actually! Both Nix and Rustup do something similar.

as for why they dont just add the developer tools directory to path

My guess would be that this method supports easily overriding the path with env vars? You can use DEVELOPER_DIR=/my/path/to/Xcode.app/Contents/Developer, and invoking clang will now use the Clang from the given Xcode (and use the SDKs from that Xcode too).

But then again, I very much agree that things would be so much more understandable if they'd just used PATH.