MacOS Resolution of localhost
It seem like this is, in fact, hardcoded in mDNSResponder.
╰─ grep -A5 -B5 "Register localhost" ./mDNSResponder-1096.40.7/mDNSMacOSX/mDNSMacOSX.c
const domainname *const localHostName = (const domainname *) "\x9" "localhost";
const domainname *const broadcastHostName = (const domainname *) "\xd" "broadcasthost";
const mDNSv4Addr localHostV4 = { { 127, 0, 0, 1 } };
mDNSv6Addr localHostV6;
// Register localhost 127.0.0.1 A record.
RegisterLocalOnlyARecord(localHostName, &localHostV4);
// Register broadcasthost 255.255.255.255 A record.
--
--
// Register broadcasthost 255.255.255.255 A record.
RegisterLocalOnlyARecord(broadcastHostName, &onesIPv4Addr);
// Register localhost ::1 AAAA record.
mDNSPlatformMemZero(&localHostV6, sizeof(localHostV6));
localHostV6.b[15] = 1;
RegisterLocalOnlyAAAARecord(localHostName, &localHostV6);
}