This is an archive of the discontinued LLVM Phabricator instance.

Implement `sys::getHostCPUName()` for Darwin ARM
ClosedPublic

Authored by beanz on Oct 29 2019, 6:13 PM.

Details

Summary

Currently there is no implementation of sys::getHostCPUName() for Darwin ARM targets. This patch makes it so that LLVM running on ARM makes reasonable guesses about the CPU features of the host CPU.

Diff Detail

Event Timeline

beanz created this revision.Oct 29 2019, 6:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2019, 6:13 PM
beanz edited the summary of this revision. (Show Details)Oct 29 2019, 6:15 PM
efriedma added inline comments.
llvm/lib/Support/Host.cpp
1236

What do 64-bit devices return here? (I assume the call returns CPU_TYPE_ARM for 32-bit code regardless of the CPU?)

1243

Can we skip the syscall on __aarch64__ targets, since you don't really check the result?

beanz marked 2 inline comments as done.Oct 29 2019, 6:45 PM
beanz added a subscriber: rjmccall.
beanz added inline comments.
llvm/lib/Support/Host.cpp
1236

Modern Apple 64-bit devices can't execute 32bit code, so that really should never happen. If it does, returning a value that matches the binary's CPU type/subtype is probably reasonable.

I could break the arm 32/64-bit implementations up into separate ifdef blocks if that seems more sane to you. In that case we could return cyclone for arm 32 in the arm 64 implementation, but we would still likely want the sys call to determine if the cpu type is 64 or 32 bit.

1243

Sure... Until arm64e pointer authentication lands in upstream (see @rjmccall's RFC). At which point this changes. I tried to structure the code to take that into account.

efriedma added inline comments.Oct 30 2019, 1:08 PM
llvm/lib/Support/Host.cpp
1236

If you're not sure what cpu_type the kernel returns for a 32-bit userspace on top of a 64-bit kernel, you could check on x86. That said, I don't want to add codepaths you can't reasonably test.

Splitting the ifdef blocks probably makes sense.

1243

Okay.

beanz updated this revision to Diff 227897.Nov 5 2019, 9:12 AM

Rebasing and updating to separate arm32 and arm64.

I beleive this is the simplest correct implementation based on the state of the in-tree Aarch64 support.

efriedma accepted this revision.Nov 5 2019, 2:22 PM

LGTM

This revision is now accepted and ready to land.Nov 5 2019, 2:22 PM
This revision was automatically updated to reflect the committed changes.