This is an archive of the discontinued LLVM Phabricator instance.

[Darwin] Add and adopt a way to query for the Darwin kernel version
ClosedPublic

Authored by yln on May 14 2020, 1:57 PM.

Details

Summary

This applies the learnings from [1]. What I intended as a simple
cleanup made me realize that the compiler-rt version checks have two
separate issues:

  1. In some places (e.g., mmap flag setting) what matters is the kernel version, not the OS version.
  2. OS version checks are implemented by querying the kernel version. This is not necessarily correct inside the simulators if the simulator runtime isn't aligned the host macOS.

This commit tackles 1) by adopting a separate query function for the
Darwin kernel version. 2) (and cleanups) will be dealt with in
follow-ups.

[1] https://reviews.llvm.org/D78942

rdar://63031937

Diff Detail

Event Timeline

yln created this revision.May 14 2020, 1:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 14 2020, 1:57 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
yln added a comment.May 14 2020, 7:03 PM

Issue 2) is addressed by D79979

yln marked an inline comment as done.May 15 2020, 9:23 AM
yln added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
671

Any suggestions on how to improve this parsing code? compiler-rt shouldn't use sscanf() and there is no internal_sscanf().

delcypher requested changes to this revision.May 20 2020, 6:05 PM

The overall idea looks good but I think the current patch has a few bugs.

compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
663

Are you sure that's the correct syctl?

On my system

$ sysctl -a | grep kern.osproductversion
kern.osproductversion: 10.15.5

That looks like the OS version rather than the kernel version.

Perhaps you meant

$ sysctl -a | grep kern.osrelease
kern.osrelease: 19.5.0

?

671

Do you need to advance p by 1 before the second call to internal_simple_strtoll? At that point it still points at '.' which isn't an integer.

This revision now requires changes to proceed.May 20 2020, 6:05 PM

Suggestion: You could write a Darwin only unit test that calls GetDarwinKernelVersion() and checks the result matches the kernel reported by the host.

Suggestion: You could also write a small Darwin only unit test that tests DarwinKernelVersion operators.

compiler-rt/lib/sanitizer_common/sanitizer_mac.h
57

Suggestion. You could instead implement operator> and then implement operator>= as

bool operator>=(const DarwinKernelVersion &other) const {
  return *this == other || *this > other;
}
yln marked 4 inline comments as done.May 20 2020, 8:19 PM

Suggestion: You could write a Darwin only unit test that calls GetDarwinKernelVersion() and checks the result matches the kernel reported by the host.

I will add a test for GetDarwinKernelVersion() and the existing GetMacosVersion() in a follow-up patch.

compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
663

Ahh, of course! That's the whole point of the patch. :facepalm:

671

Thanks, fixed!

compiler-rt/lib/sanitizer_common/sanitizer_mac.h
57

In the distant future, all of this can just be auto operator<=>(const Version&) const = default;
https://en.cppreference.com/w/cpp/language/default_comparisons

yln updated this revision to Diff 265412.May 20 2020, 8:22 PM
yln marked an inline comment as done.

Use appropriate sysctl key kern.osrelease. Fix bug in parsing code.

This revision is now accepted and ready to land.May 30 2020, 2:54 PM
This revision was automatically updated to reflect the committed changes.