Skip to content

Commit 25949c2

Browse files
[Sanitizer] Don't depend on symbolication in asan_recover.swift. (swiftlang#28290)
Relying on symbolication via `atos` unfortunately does not seem to be a good idea because there are several testing scenarios where this doesn't work and we fallback to `dladdr()` for Darwin platforms. To workaround this, the `asan_recover.swift` test has been changed to just test for the function name which covers the fully-symbolicated and partially symbolicated case (`dladdr()` fallback). To make sure that the two errors come from different locations (the original intention of examining source locations) the second error has been moved into a different function called `foo`. Unfortunately in some testing scenarios `foo` isn't always demangled correctly so we have to make the FileCheck pattern quite liberal. rdar://problem/57198494
1 parent 8bfe519 commit 25949c2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

test/Sanitizers/asan_recover.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ fflush(stdout)
4242

4343
let size:Int = 128;
4444

45+
func foo(_ rawptr:UnsafeMutablePointer<UInt8>) {
46+
print("Read second element:\(rawptr.advanced(by: 1).pointee)")
47+
fflush(stdout)
48+
}
49+
4550
// In this test we need multiple issues to occur that ASan can detect.
4651
// Allocating a buffer and artificially poisoning it seems like the best way to
4752
// test this because there's no undefined behavior happening. Hopefully this
@@ -77,18 +82,18 @@ __asan_poison_memory_region(UnsafeMutableRawPointer(x), size)
7782
// NOTE: Testing for stackframe `#0` should ensure that the poison read
7883
// happened in instrumentation and not in an interceptor.
7984
// CHECK-COMMON-STDERR: AddressSanitizer: use-after-poison
80-
// CHECK-COMMON-STDERR: #0 0x{{.+}} in main {{.*}}asan_recover.swift:[[@LINE+1]]
85+
// CHECK-COMMON-STDERR: #0 0x{{.+}} in main{{.*}}
8186
print("Read first element:\(x.advanced(by: 0).pointee)")
8287
fflush(stdout)
8388
// CHECK-RECOVER-STDOUT: Read first element:0
8489

8590
// Second error
91+
// NOTE: Very loose regex is to accomodate if name demangling
92+
// fails. rdar://problem/57235673
8693
// CHECK-RECOVER-STDERR: AddressSanitizer: use-after-poison
87-
// CHECK-RECOVER-STDERR: #0 0x{{.+}} in main {{.*}}asan_recover.swift:[[@LINE+1]]
88-
print("Read second element:\(x.advanced(by: 1).pointee)")
89-
fflush(stdout)
94+
// CHECK-RECOVER-STDERR: #0 0x{{.+}} in {{.*}}foo{{.*}}
9095
// CHECK-RECOVER-STDOUT: Read second element:0
91-
96+
foo(x)
9297
__asan_unpoison_memory_region(UnsafeMutableRawPointer(x), size)
9398

9499
x.deallocate();

0 commit comments

Comments
 (0)