Skip to content

Commit 6f39a52

Browse files
committed
[SwiftCore]: Don't always clobber memory
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
1 parent b76047a commit 6f39a52

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Runtimes/Core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ add_compile_definitions(
159159
$<$<BOOL:${SwiftCore_HAS_DARWIN_LIBMALLOC}>:-DSWIFT_STDLIB_HAS_DARWIN_LIBMALLOC> # Anything that includes include/swift/Runtime/Config.h
160160
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_THREADING_${SwiftCore_THREADING_PACKAGE}>
161161
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_ENABLE_LEAK_CHECKER=$<BOOL:${SwiftCore_ENABLE_RUNTIME_LEAK_CHECKER}>>
162-
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS=$<BOOL:${SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS}>>)
162+
$<$<BOOL:${SwiftCore_ENABLE_CLOBBER_FREED_OBJECTS}>:-DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS>)
163163

164164
add_compile_options(
165165
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>

stdlib/public/runtime/HeapObject.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ void swift::swift_deallocPartialClassInstance(HeapObject *object,
875875
swift_deallocClassInstance(object, allocatedSize, allocatedAlignMask);
876876
}
877877

878-
#if !defined(__APPLE__) && defined(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS)
878+
#if !defined(__APPLE__) && SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS
879879
static inline void memset_pattern8(void *b, const void *pattern8, size_t len) {
880880
char *ptr = static_cast<char *>(b);
881881
while (len >= 8) {
@@ -898,9 +898,9 @@ static inline void swift_deallocObjectImpl(HeapObject *object,
898898
}
899899
assert(object->refCounts.isDeiniting());
900900
SWIFT_RT_TRACK_INVOCATION(object, swift_deallocObject);
901-
#ifdef SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS
901+
#if SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS
902902
memset_pattern8((uint8_t *)object + sizeof(HeapObject),
903-
"\xAB\xAD\x1D\xEA\xF4\xEE\xD0\bB9",
903+
"\xF0\xEF\xBE\xAD\xDE\xED\xFE\x0F", // 0x0ffeeddeadbeeff0
904904
allocatedSize - sizeof(HeapObject));
905905
#endif
906906

0 commit comments

Comments
 (0)