Skip to content

[🍒][SwiftCore]: Don't always clobber memory #81040

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

Conversation

etcwilde
Copy link
Member

@etcwilde etcwilde commented Apr 23, 2025

6.2 Cherry-Pick of: #81010

The new build system set SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS to 0. Unfortunately, the check in the Swift runtime used #ifdef, so even though it was turned off, it was actually enabled in some cases.

Fixing the issue in the build system as well as switching the check to verify that value of SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS is taken into account in the sources. C/C++ implicitly defines macro values to 1 when set without a value and 0 when it is not set.

Also making the hex a bit more recognizable and grep'able by including it as a comment.

  • Explanation:
    Disables clobbering free'd memory when SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS is set to off. The code inconsistently used #if SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS and #ifdef SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS to enable the clobbering. The flag set SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS to 0, which would partially enable it in the cases where #ifdef was used. this makes the check consistent and fixes the build system to define SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS only if it's enabled.
  • Scope: Affects how the runtime deallocates memory, relaxing so free'd memory isn't overwritten.
  • Risk: Low/Medium: Affects all Swift programs but is a simple fix. This puts the runtime build back to how it was before with the clobbering disabled.
  • Issue: rdar://149210738
  • Testing: Manual verification, and @mikeash verified against the case that identified the issue.
  • Reviewer: @mikeash, @compnerd

Fixes: rdar://149210738
(cherry picked from commit 6f39a52)

The new build system set `SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS` to 0.
Unfortunately, the check in the Swift runtime used `#ifdef`, so even
though it was turned off, it was actually enabled in some cases.

Fixing the issue in the build system as well as switching the check to
verify that value of `SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS` is taken into
account in the sources. C/C++ implicitly defines macro values to 1 when
set without a value and 0 when it is not set.

Also making the hex a bit more recognizable and grep'able by including
it as a comment.

Fixes: rdar://149210738
(cherry picked from commit 6f39a52)
@etcwilde etcwilde added 🍒 release cherry pick Flag: Release branch cherry picks swift 6.2 labels Apr 23, 2025
@etcwilde etcwilde requested a review from a team as a code owner April 23, 2025 19:21
@etcwilde
Copy link
Member Author

@swift-ci please test

@etcwilde etcwilde merged commit 7328081 into swiftlang:release/6.2 Apr 24, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 6.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants