Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SANITIZER_MIN_OSX_VERSION a cache variable #74394

Merged
merged 4 commits into from Jan 10, 2024

Conversation

cjappl
Copy link
Contributor

@cjappl cjappl commented Dec 5, 2023

It is desirable to be able to configure the -mmacosx-version-min flag for the sanitizers, but this flag was never made a CACHE variable in cmake.

By doing this, it will allow developers to select different minimum versions, which results in different interceptors being enabled or disabled on their platforms. This version can now persist between cmake runs, so it can be remembered by cmake, and edited in the cache file.

@cjappl
Copy link
Contributor Author

cjappl commented Dec 5, 2023

@vitalybuka @ramosian-glider @kcc

Kindly requesting a review on this patch. Thanks in advance

@cjappl
Copy link
Contributor Author

cjappl commented Dec 11, 2023

@vitalybuka @ramosian-glider @kcc

Ping

@cjappl
Copy link
Contributor Author

cjappl commented Dec 18, 2023

Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but please wait a few days for others feedback

@petrhosek For CMAKE expertise

@yln @sundahl as it impacts OSX

Copy link
Collaborator

@yln yln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me summarize my understanding: the intention here is to promote SANITIZER_MIN_OSX_VERSION to a CMAKE cache variable. We don't change any behavior or default.

LGTM, thanks!

@rsundahl @thetruestblue
At some point we should think about bumping the minimal sanitizer target enabling some cleanups.

@cjappl
Copy link
Contributor Author

cjappl commented Dec 21, 2023

Let me summarize my understanding: the intention here is to promote SANITIZER_MIN_OSX_VERSION to a CMAKE cache variable. We don't change any behavior or default.

Your understanding is correct! No changes in behavior, just allowing people to tweak it easier.

At some point we should think about bumping the minimal sanitizer target enabling some cleanups.

One of the main reasons behind me putting up this review is I found a handful of things that would be cleaned up (allowing sanitizers to hook into calls introduced in newer MacOS versions). Once this is merged, I'm going to put up a few more in this series based on what I found! I'll make sure to add you to those reviews to get your thoughts @yln .

Thanks for the review.

@cjappl
Copy link
Contributor Author

cjappl commented Jan 2, 2024

Pinging either:

@rsundahl for a review

Or one of my previous reviewers with write access for a merge, if appropriate.

@petrhosek @yln @vitalybuka

Thanks!

@cjappl
Copy link
Contributor Author

cjappl commented Jan 9, 2024

Pinging either:

@rsundahl for a review

Or one of my previous reviewers with write access for a merge, if appropriate.

@petrhosek @yln @vitalybuka

@yln yln merged commit ab82b06 into llvm:main Jan 10, 2024
4 checks passed
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
It is desirable to be able to configure the `-mmacosx-version-min` flag
for the sanitizers, but this flag was never made a CACHE variable in
cmake.

By doing this, it will allow developers to select different minimum
versions, which results in different interceptors being enabled or
disabled on their platforms. This version can now persist between cmake
runs, so it can be remembered by cmake, and edited in the cache file.
@cjappl cjappl deleted the AddConfigurableSanitizer branch March 13, 2024 00:39
@jfgoog
Copy link
Contributor

jfgoog commented Apr 3, 2024

This does actually change behavior. If -mmacosx-version-min is set, cmake will behave differently between the first and subsequent runs. More info at rust-lang/rust#122504 (comment)

@cjappl
Copy link
Contributor Author

cjappl commented Apr 3, 2024

Agreed on your analysis @jfgoog . I see that on subsequent runs, MACOSX_VERSION_MIN_FLAG will be unset. This was an unintended side effect of this change (bug).

I think this patch would fix the problem, while maintaining the flexibility of this PR? Essentially hoisting the regex match out of the if statement. WDYT?

diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index d5dc4a40c097..b2cae81d5032 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -463,9 +463,10 @@ if(APPLE)

   set(DEFAULT_SANITIZER_MIN_OSX_VERSION 10.10)
   set(DARWIN_osx_MIN_VER_FLAG "-mmacosx-version-min")
+  string(REGEX MATCH "${DARWIN_osx_MIN_VER_FLAG}=([.0-9]+)"
+         MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}")
+
   if(SANITIZER_MIN_OSX_VERSION STREQUAL "")
-    string(REGEX MATCH "${DARWIN_osx_MIN_VER_FLAG}=([.0-9]+)"
-           MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}")
     if(MACOSX_VERSION_MIN_FLAG)
       set(MIN_OSX_VERSION "${CMAKE_MATCH_1}")
     elseif(CMAKE_OSX_DEPLOYMENT_TARGET)

@jfgoog
Copy link
Contributor

jfgoog commented Apr 3, 2024

That seems reasonable, but I am hardly an expert here.

The underlying issue for me, though, which pre-dates your change, is that it seems like if the -mmacosx-version-min flag is set, we will never detect any architectures for compiler-rt, essentially making it impossible to build anything. Is that intended behavior?

@cjappl
Copy link
Contributor Author

cjappl commented Apr 3, 2024

Pinging a couple experts to weigh in (as I am hardly an expert either)

@yln @vitalybuka @petrhosek

Pending on when they get back to us, if this is a blocking issue for rust you should file a bug report for this. I wouldn't want this "buried" in this PR with just us two talking about it

@jfgoog
Copy link
Contributor

jfgoog commented Apr 3, 2024

It's not blocking. It only happens with newer versions of the cc crate, and the rustc bootstrap code has an old version pinned that doesn't have this problem.

@cjappl
Copy link
Contributor Author

cjappl commented Apr 3, 2024

I put up a review to at least revert this to the previous way of doing things:

#87580

I understand this doesn't fix your "bigger" issue, but I agree that something about that smells fishy.

vitalybuka pushed a commit that referenced this pull request Apr 8, 2024
…s of CMake in compiler-rt (#87580)

As discussed here:

#74394 (comment)

An unintentional change of behavior was introduced in #74394 

This code introduced in #74394 :

The first time through
* SANITIZER_MIN_OSX_VERSION is not set
* parse -mmacosx-version-min and set MACOSX_VERSION_MIN_FLAG
* Set and cache SANITIZER_MIN_OSX_VERSION

Subsequent times through:
* SANITIZER_MIN_OSX_VERSION is cached 
* (BUG!!) you don't parse -mmacosx-version-min, and don't set
MACOSX_VERSION_MIN_FLAG


MACOSX_VERSION_MIN_FLAG is used later in the file on this line:

https://github.com/llvm/llvm-project/blob/63c925ca808f216f805b76873743450456e350f2/compiler-rt/cmake/config-ix.cmake#L517


Hoisting this assignment outside the if block returns us to the previous
behavior before this commit, while maintaining the flexibility
introduced with the cache variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants