[PATCH] [ASan] Fix stack-overflow.cc test on PowerPC64 Linux

Jay Foad jay.foad at gmail.com
Wed Dec 24 07:30:10 PST 2014


Hi kcc, eugenis, samsonov,

On PowerPC64 Linux the stack-overflow.cc test fails intermittently with:

==27505==AddressSanitizer CHECK failed: /home/buildbots/sanitizerslave1/sanitizer-ppc64-1/build/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc:94 "(((uptr)&rl >= start && (uptr)&rl < end)) != (0)" (0x0, 0x0)

I have managed to catch this failure in the debugger, but only
occasionally, and so far only with ASAN_OPTIONS=use_sigaltstack=1
and unlimited stacks ("ulimit -s unlimited").

The problem occurs when GetThreadStackTopAndBottom tries to look up the
address of a local variable in /proc/maps. On Linux, the entry for the
stack in /proc/maps deliberately excludes the first page (the
"stack guard page"):

https://github.com/torvalds/linux/blob/c164e038eee805147e95789dddb88ae3b3aca11c/fs/proc/task_mmu.c#L285

But sometimes when we get to GetThreadStackTopAndBottom, we are already
in the guard page, so the test "(uptr)&rl >= start" fails. The fix is to
tweak the start address before this test, to try to undo the adjustment
that was done in /proc/maps.

http://reviews.llvm.org/D6777

Files:
  lib/sanitizer_common/sanitizer_linux_libcdep.cc

Index: lib/sanitizer_common/sanitizer_linux_libcdep.cc
===================================================================
--- lib/sanitizer_common/sanitizer_linux_libcdep.cc
+++ lib/sanitizer_common/sanitizer_linux_libcdep.cc
@@ -91,6 +91,10 @@
         break;
       prev_end = end;
     }
+    // /proc/maps adjusts the real start address so as not to include the stack
+    // guard page. Undo the adjustment here in case rl is in the guard page.
+    if (start > prev_end)
+      start -= GetPageSizeCached();
     CHECK((uptr)&rl >= start && (uptr)&rl < end);
 
     // Get stacksize from rlimit, but clip it so that it does not overlap

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6777.17626.patch
Type: text/x-patch
Size: 643 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141224/91fc9c60/attachment.bin>


More information about the llvm-commits mailing list