This is an archive of the discontinued LLVM Phabricator instance.

[Darwin][compiler-rt] Test TARGET_OS_* conditionals using preprocessor directives
Needs ReviewPublic

Authored by veprbl on Jun 3 2021, 1:50 AM.

Details

Summary

This helps to avoid compilation errors like

lib/sanitizer_common/sanitizer_mac.cpp:617:7: error: use of undeclared identifier 'TARGET_OS_IOS'
  if (TARGET_OS_IOS || TARGET_OS_TV) return 6;
      ^

Diff Detail

Event Timeline

veprbl created this revision.Jun 3 2021, 1:50 AM
veprbl requested review of this revision.Jun 3 2021, 1:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 3 2021, 1:50 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
veprbl updated this revision to Diff 349504.Jun 3 2021, 2:54 AM
yln added a comment.Jun 16 2021, 5:32 PM

Hi Dmitry, I am happy with the quality of this patch, but I don't understand why it is required.

These constant are defined in TargetConditionals.h (included via sanitizer_common/sanitizer_platform.h) which is part of the Apple SDK and should always be available.
Maybe the SDK paths weren't correctly configured or are you using manual -isysroot overrides?

I can give some clarifications. The environment which I'm using is based on Nix/Nixpkgs where we are packaging our own SDK based on what is available from the open source releases that were done by Apple. Originally I googled the issue with the defines and saw that people outside of LLVM and Nix had similar issues, so I assumed it was a common issue with perhaps a slightly outdated SDK (we are using 10.12). Your response had prompted me to investigate this a little bit more, and by running the compiler with a nice -H option I learned that the particular instance of TargetConditionals.h that was using in compiler-rt's compilation wasn't coming from the SDK or the Swift CF framework. Instead it was coming from a hardcoded file [1] that may have been based on some SDK at the time, but definitely have not been updated in 6 years and is missing some of the definitions that are currently needed to build the compiler-rt.

I'm not really sure about all the moving parts involved, but, I think, I could try to fix the issue by updating TargetConditionals.h on our end.

[1] https://github.com/NixOS/nixpkgs/blame/5c770035c8fa1e84b1362dc2fe6da30be0eef363/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix#L63-L90

veprbl added a comment.EditedJun 17 2021, 7:51 AM

Looking at the TargetConditionals.h from our 10.12 SDK, I see that there are actually branches that lead to some of the TARGET_OS_ definitions staying undefined for non-apple compilers, so it seems like this patch has some merit to it.