Skip to content

[Runtime] Scribble on metadata allocations. #32408

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

nate-chandler
Copy link
Contributor

Previously, when NDEBUG was not defined, the allocations made for value metadata records were filled with 0xAA bytes. Here, that behavior is both expanded to all metadata records and enabled in release builds when the environment variable SWIFT_DEBUG_ENABLE_MALLOC_SCRIBBLE is set.

@nate-chandler nate-chandler requested a review from mikeash June 16, 2020 18:31
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@mikeash mikeash left a comment

Choose a reason for hiding this comment

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

Just one small change, otherwise looks great. This should help a lot. I wonder if we should set up CI to run with this enabled (aside from performance tests) permanently?

// SWIFT_DEBUG_ENABLE_MALLOC_SCRIBBLE environment variable is set.
static OnceToken_t getenvToken;
SWIFT_ONCE_F(getenvToken, checkMallocScribbleEnvironmentVariable, nullptr);
if (SWIFT_UNLIKELY(_swift_debug_mallocScribbleEnabled)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The SWIFT_DEBUG_ENABLE_MALLOC_SCRIBBLE() call will compile down to a SWIFT_ONCE_F and an access to a global variable, so you can remove your own SWIFT_ONCE_F and global and just check that directly. (You might have seen me doing this with _swift_debug_metadataAllocationIterationEnabled, but that's only because there's additional setup needed when it's enabled.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the explanation! Fixed.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 0ff21a1dbfbca9255e90e0a22eabf27c77ab57f0

@nate-chandler nate-chandler force-pushed the runtime/memset-pattern-metadata-on-flag branch from 0ff21a1 to 4d4d90e Compare June 16, 2020 19:44
Previously, when NDEBUG was not defined, the allocations made for value
metadata records were filled with 0xAA bytes.  Here, that behavior is
both expanded to all metadata records and enabled in release builds when
the environment variable SWIFT_DEBUG_ENABLE_MALLOC_SCRIBBLE is set.
@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 0ff21a1dbfbca9255e90e0a22eabf27c77ab57f0

@nate-chandler nate-chandler force-pushed the runtime/memset-pattern-metadata-on-flag branch from 4d4d90e to 5f67ef4 Compare June 16, 2020 19:47
@nate-chandler
Copy link
Contributor Author

@mikeash

I wonder if we should set up CI to run with this enabled (aside from performance tests) permanently?

Sounds great! I added a commit that does that here: 5f67ef4

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 0ff21a1dbfbca9255e90e0a22eabf27c77ab57f0

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 0ff21a1dbfbca9255e90e0a22eabf27c77ab57f0

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test os x platform

@nate-chandler nate-chandler merged commit d76a8b9 into swiftlang:master Jun 17, 2020
@nate-chandler nate-chandler deleted the runtime/memset-pattern-metadata-on-flag branch June 17, 2020 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants