[compiler-rt] 0e4b214 - [sanitizer_common] Don't try to unmap unaligned memory

Rainer Orth via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 9 00:16:17 PST 2022


Author: Rainer Orth
Date: 2022-02-09T09:15:41+01:00
New Revision: 0e4b214b8c404d7e2f67301858ea05c209a27433

URL: https://github.com/llvm/llvm-project/commit/0e4b214b8c404d7e2f67301858ea05c209a27433
DIFF: https://github.com/llvm/llvm-project/commit/0e4b214b8c404d7e2f67301858ea05c209a27433.diff

LOG: [sanitizer_common] Don't try to unmap unaligned memory

Enabling `sanitizer_common` tests on Solaris (D91606
<https://reviews.llvm.org/D91606>) and SPARC (D91608
<https://reviews.llvm.org/D91608>) uncovered a sparcv9 failure

  SanitizerCommon-Unit :: ./Sanitizer-sparcv9-Test/CompactRingBuffer.int64

like this:

  [ RUN      ] CompactRingBuffer.int64
  ==24576==ERROR: SanitizerTool failed to deallocate 0x2000 (8192) bytes at address 0xffffffff7f59b000
  ==24576==Sanitizer CHECK failed: /vol/llvm/src/llvm-project/local/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp:61 (("unable to unmap" && 0)) != (0) (0, 0)

The problem is that the original allocation via
`MmapAlignedOrDieOnFatalError` is for 4 kB, but the Solaris/sparcv9
pagesize is 8 kB.  So the initial allocation is for 12 kB, rounded to a
multiple of the pagesize.  Afterwards, the unneeded rest is unmapped again,
but this fails since the address is not pagesize-aligned.

This patch avoids this by aligning the end of the mapping to the pagesize.

With D91827 <https://reviews.llvm.org/D91827> added, the test `PASS`es on
`sparcv9-sun-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D91615

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
index f8457a6aac41..3b330a3705e2 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
@@ -95,6 +95,7 @@ void *MmapAlignedOrDieOnFatalError(uptr size, uptr alignment,
     UnmapOrDie((void*)map_res, res - map_res);
   }
   uptr end = res + size;
+  end = RoundUpTo(end, GetPageSizeCached());
   if (end != map_end)
     UnmapOrDie((void*)end, map_end - end);
   return (void*)res;


        


More information about the llvm-commits mailing list