From: Peter Collingbourne Date: Thu, 22 Apr 2021 02:13:36 +0000 (-0700) Subject: scudo: Obtain tag from pointer instead of loading it from memory. NFCI. X-Git-Tag: llvmorg-14-init~8842 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e4fa0b307f7fe2c3db7442c719f643287f08eed4;p=platform%2Fupstream%2Fllvm.git scudo: Obtain tag from pointer instead of loading it from memory. NFCI. Since we already have a tagged pointer available to us, we can just extract the tag from it and avoid an LDG instruction. Differential Revision: https://reviews.llvm.org/D101014 --- diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h index e778181..e621c87 100644 --- a/compiler-rt/lib/scudo/standalone/combined.h +++ b/compiler-rt/lib/scudo/standalone/combined.h @@ -518,6 +518,7 @@ public: if (UNLIKELY(!isAligned(reinterpret_cast(Ptr), MinAlignment))) reportMisalignedPointer(AllocatorAction::Deallocating, Ptr); + void *TaggedPtr = Ptr; Ptr = getHeaderTaggedPointer(Ptr); Chunk::UnpackedHeader Header; @@ -543,7 +544,7 @@ public: reportDeleteSizeMismatch(Ptr, DeleteSize, Size); } - quarantineOrDeallocateChunk(Options, Ptr, &Header, Size); + quarantineOrDeallocateChunk(Options, TaggedPtr, &Header, Size); } void *reallocate(void *OldPtr, uptr NewSize, uptr Alignment = MinAlignment) { @@ -639,7 +640,7 @@ public: void *NewPtr = allocate(NewSize, Chunk::Origin::Malloc, Alignment); if (LIKELY(NewPtr)) { memcpy(NewPtr, OldTaggedPtr, Min(NewSize, OldSize)); - quarantineOrDeallocateChunk(Options, OldPtr, &OldHeader, OldSize); + quarantineOrDeallocateChunk(Options, OldTaggedPtr, &OldHeader, OldSize); } return NewPtr; } @@ -1031,13 +1032,13 @@ private: reinterpret_cast(Ptr) - SizeOrUnusedBytes; } - void quarantineOrDeallocateChunk(Options Options, void *Ptr, + void quarantineOrDeallocateChunk(Options Options, void *TaggedPtr, Chunk::UnpackedHeader *Header, uptr Size) { + void *Ptr = getHeaderTaggedPointer(TaggedPtr); Chunk::UnpackedHeader NewHeader = *Header; if (UNLIKELY(useMemoryTagging(Options))) { - u8 PrevTag = 0; + u8 PrevTag = extractTag(reinterpret_cast(TaggedPtr)); if (NewHeader.ClassId) { - PrevTag = extractTag(loadTag(reinterpret_cast(Ptr))); if (!TSDRegistry.getDisableMemInit()) { uptr TaggedBegin, TaggedEnd; const uptr OddEvenMask = computeOddEvenMaskForPointerMaybe(