This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] add SANITIZER_OSX
ClosedPublic

Authored by aralisza on Apr 8 2021, 5:52 PM.

Details

Summary

This will allow us to make osx specific changes easier. Because apple silicon macs also run on aarch64, it was easy to confuse it with iOS.

rdar://75302812

Diff Detail

Event Timeline

aralisza created this revision.Apr 8 2021, 5:52 PM
aralisza requested review of this revision.Apr 8 2021, 5:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2021, 5:52 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
aralisza updated this revision to Diff 336282.Apr 8 2021, 5:54 PM

remove linter changes

aralisza updated this revision to Diff 336283.Apr 8 2021, 5:56 PM

fix whitespace

aralisza updated this revision to Diff 336284.Apr 8 2021, 5:56 PM

remove change that doesn't belong in this diff

Harbormaster completed remote builds in B97858: Diff 336283.

I'm not a big fan of the name but the sensible name (SANTIZER_MAC) is already taken unfortunately.

compiler-rt/lib/sanitizer_common/sanitizer_platform.h
72

How about this instead?

#if TARGET_OS_OSX
#  define SANITIZER_OSX 1
#else
#  define SANITIZER_OSX 0
#endif

It's more inline with the existing defines and doesn't require us to explicitly list platforms that aren't macOS.

yln added a comment.Apr 9 2021, 11:19 AM

From the TargetConditionals.h header:

TARGET_OS_MAC             - Generated code will run under Mac OS X variant
   TARGET_OS_OSX          - Generated code will run under OS X devices
   TARGET_OS_IPHONE          - Generated code for firmware, devices, or simulator
      TARGET_OS_IOS             - Generated code will run under iOS
      TARGET_OS_TV              - Generated code will run under Apple TV OS
      TARGET_OS_WATCH           - Generated code will run under Apple Watch OS
      TARGET_OS_MACCATALYST     - Generated code will run under macOS
   TARGET_OS_SIMULATOR      - Generated code will run under a simulator

 +----------------------------------------------------------+
 |                      TARGET_OS_MAC                       |
 | +---+ +------------------------------------+ +---------+ |
 | |   | |            TARGET_OS_IPHONE        | |         | |
 | |   | | +---------------+ +----+ +-------+ | |         | |
 | |   | | |      IOS      | |    | |       | | |         | |
 | |OSX| | |+-------------+| | TV | | WATCH | | |DRIVERKIT| |
 | |   | | || MACCATALYST || |    | |       | | |         | |
 | |   | | |+-------------+| |    | |       | | |         | |
 | |   | | +---------------+ +----+ +-------+ | |         | |
 | +---+ +------------------------------------+ +---------+ |
 +----------------------------------------------------------+

So adding SANITIZER_OSX would mirror this even though the name is a bad (outdated) one.
Renaming everything to make sense, e.g., SANITIZER_DARWIN for everything and then macOS, iOS, ... as more specific subsets is probably out of the question.

LGTM (with Dan's suggestions)!

Note: in some places we use the order of #if-#elif-#else to make the #else mean maOS. Having an explicit macro should be better.

aralisza updated this revision to Diff 336531.Apr 9 2021, 11:40 AM

use target conditionals

aralisza updated this revision to Diff 336532.Apr 9 2021, 11:41 AM

indentation

Harbormaster completed remote builds in B98045: Diff 336532.

@aralisza You can ignore the lint checks here.

Just floating this as on option. We could call the new define SANITIZER_MACOS.

pro:

  • Name better reflects the current name of macOS

cons:

  • Easily confused with SANITIZER_MAC
  • Doesn't follow the naming conventions in`TargetConditionals.h`

I don't have strong opinions either way, we should just pick one and stick with it. @aralisza @yln Any opinions on this?

yln added a comment.Apr 9 2021, 3:02 PM

I don't have strong opinions either way, we should just pick one and stick with it. @aralisza @yln Any opinions on this?

I would vote for the "extremes", i.e., either

  • keep closely mirroring TargetConditionals.h with all its idiosyncrasies, or
  • newly design/rename things to "make sense" and be consistent. My biggest beef is that TARGET_OS_MAC/SANITIZER_MAC is such a misnomer (but one can easily guess how it evolved and why it means what it means).

The second option would leave us in a better state, but is probably not worth the churn. Renaming everything at once in upstream llvm doesn't sound too bad, but one has to consider the downstream implications.
I would not use the name SANITIZER_MACOS without also "fixing"/renaming SANITIZER_MAC .

aralisza edited the summary of this revision. (Show Details)Apr 9 2021, 3:50 PM

Personally, I would prefer option 1

keep closely mirroring TargetConditionals.h with all its idiosyncrasies

because I don't really want to end up on the git blame for all the lines I rename :(

yln accepted this revision.Apr 12 2021, 11:40 AM
This revision is now accepted and ready to land.Apr 12 2021, 11:40 AM
This revision was landed with ongoing or failed builds.Apr 12 2021, 11:46 AM
This revision was automatically updated to reflect the committed changes.