[compiler-rt] r292630 - [scudo] Replacing std::atomic with Sanitizer's atomics
Kostya Kortchinsky via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 10:32:19 PST 2017
Author: cryptoad
Date: Fri Jan 20 12:32:18 2017
New Revision: 292630
URL: http://llvm.org/viewvc/llvm-project?rev=292630&view=rev
Log:
[scudo] Replacing std::atomic with Sanitizer's atomics
Summary:
In an effort to getting rid of dependencies to external libraries, we are
replacing atomic PackedHeader use of std::atomic with Sanitizer's
atomic_uint64_t, which allows us to avoid -latomic.
Reviewers: kcc, phosek, alekseyshl
Reviewed By: alekseyshl
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D28864
Modified:
compiler-rt/trunk/lib/scudo/scudo_allocator.cpp
compiler-rt/trunk/lib/scudo/scudo_allocator.h
compiler-rt/trunk/test/scudo/interface.cpp
compiler-rt/trunk/test/scudo/lit.cfg
compiler-rt/trunk/test/scudo/malloc.cpp
compiler-rt/trunk/test/scudo/realloc.cpp
Modified: compiler-rt/trunk/lib/scudo/scudo_allocator.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_allocator.cpp?rev=292630&r1=292629&r2=292630&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_allocator.cpp (original)
+++ compiler-rt/trunk/lib/scudo/scudo_allocator.cpp Fri Jan 20 12:32:18 2017
@@ -125,8 +125,7 @@ struct ScudoChunk : UnpackedHeader {
UnpackedHeader NewUnpackedHeader;
const AtomicPackedHeader *AtomicHeader =
reinterpret_cast<const AtomicPackedHeader *>(this);
- PackedHeader NewPackedHeader =
- AtomicHeader->load(std::memory_order_relaxed);
+ PackedHeader NewPackedHeader = atomic_load_relaxed(AtomicHeader);
NewUnpackedHeader = bit_cast<UnpackedHeader>(NewPackedHeader);
return (NewUnpackedHeader.Checksum == computeChecksum(&NewUnpackedHeader));
}
@@ -135,8 +134,7 @@ struct ScudoChunk : UnpackedHeader {
void loadHeader(UnpackedHeader *NewUnpackedHeader) const {
const AtomicPackedHeader *AtomicHeader =
reinterpret_cast<const AtomicPackedHeader *>(this);
- PackedHeader NewPackedHeader =
- AtomicHeader->load(std::memory_order_relaxed);
+ PackedHeader NewPackedHeader = atomic_load_relaxed(AtomicHeader);
*NewUnpackedHeader = bit_cast<UnpackedHeader>(NewPackedHeader);
if (NewUnpackedHeader->Checksum != computeChecksum(NewUnpackedHeader)) {
dieWithMessage("ERROR: corrupted chunk header at address %p\n", this);
@@ -149,7 +147,7 @@ struct ScudoChunk : UnpackedHeader {
PackedHeader NewPackedHeader = bit_cast<PackedHeader>(*NewUnpackedHeader);
AtomicPackedHeader *AtomicHeader =
reinterpret_cast<AtomicPackedHeader *>(this);
- AtomicHeader->store(NewPackedHeader, std::memory_order_relaxed);
+ atomic_store_relaxed(AtomicHeader, NewPackedHeader);
}
// Packs and stores the header, computing the checksum in the process. We
@@ -162,10 +160,10 @@ struct ScudoChunk : UnpackedHeader {
PackedHeader OldPackedHeader = bit_cast<PackedHeader>(*OldUnpackedHeader);
AtomicPackedHeader *AtomicHeader =
reinterpret_cast<AtomicPackedHeader *>(this);
- if (!AtomicHeader->compare_exchange_strong(OldPackedHeader,
- NewPackedHeader,
- std::memory_order_relaxed,
- std::memory_order_relaxed)) {
+ if (!atomic_compare_exchange_strong(AtomicHeader,
+ &OldPackedHeader,
+ NewPackedHeader,
+ memory_order_relaxed)) {
dieWithMessage("ERROR: race on chunk header at address %p\n", this);
}
}
Modified: compiler-rt/trunk/lib/scudo/scudo_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_allocator.h?rev=292630&r1=292629&r2=292630&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_allocator.h (original)
+++ compiler-rt/trunk/lib/scudo/scudo_allocator.h Fri Jan 20 12:32:18 2017
@@ -22,8 +22,6 @@
# error "The Scudo hardened allocator is currently only supported on Linux."
#endif
-#include <atomic>
-
namespace __scudo {
enum AllocType : u8 {
@@ -58,7 +56,7 @@ struct UnpackedHeader {
u64 Salt : 8;
};
-typedef std::atomic<PackedHeader> AtomicPackedHeader;
+typedef atomic_uint64_t AtomicPackedHeader;
COMPILER_CHECK(sizeof(UnpackedHeader) == sizeof(PackedHeader));
// Minimum alignment of 8 bytes for 32-bit, 16 for 64-bit
Modified: compiler-rt/trunk/test/scudo/interface.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/scudo/interface.cpp?rev=292630&r1=292629&r2=292630&view=diff
==============================================================================
--- compiler-rt/trunk/test/scudo/interface.cpp (original)
+++ compiler-rt/trunk/test/scudo/interface.cpp Fri Jan 20 12:32:18 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo %s -o %t
+// RUN: %clang_scudo %s -lstdc++ -o %t
// RUN: %run %t 2>&1
// Tests that the sanitizer interface functions behave appropriately.
Modified: compiler-rt/trunk/test/scudo/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/scudo/lit.cfg?rev=292630&r1=292629&r2=292630&view=diff
==============================================================================
--- compiler-rt/trunk/test/scudo/lit.cfg (original)
+++ compiler-rt/trunk/test/scudo/lit.cfg Fri Jan 20 12:32:18 2017
@@ -19,9 +19,7 @@ config.suffixes = ['.c', '.cc', '.cpp']
# C flags.
c_flags = ([config.target_cflags] +
["-std=c++11",
- "-lstdc++",
"-lrt",
- "-latomic",
"-ldl",
"-pthread",
"-fPIE",
Modified: compiler-rt/trunk/test/scudo/malloc.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/scudo/malloc.cpp?rev=292630&r1=292629&r2=292630&view=diff
==============================================================================
--- compiler-rt/trunk/test/scudo/malloc.cpp (original)
+++ compiler-rt/trunk/test/scudo/malloc.cpp Fri Jan 20 12:32:18 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo %s -o %t
+// RUN: %clang_scudo %s -lstdc++ -o %t
// RUN: %run %t 2>&1
// Tests that a regular workflow of allocation, memory fill and free works as
Modified: compiler-rt/trunk/test/scudo/realloc.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/scudo/realloc.cpp?rev=292630&r1=292629&r2=292630&view=diff
==============================================================================
--- compiler-rt/trunk/test/scudo/realloc.cpp (original)
+++ compiler-rt/trunk/test/scudo/realloc.cpp Fri Jan 20 12:32:18 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo %s -o %t
+// RUN: %clang_scudo %s -lstdc++ -o %t
// RUN: %run %t pointers 2>&1
// RUN: %run %t contents 2>&1
// RUN: not %run %t memalign 2>&1 | FileCheck %s
More information about the llvm-commits
mailing list