From ecfa524ee3397bb96e74974576726db6fcc1cb41 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Wed, 27 Jan 2016 19:33:00 +0000 Subject: [PATCH] [cfi] Fix gcc build. llvm-svn: 258977 --- compiler-rt/lib/cfi/cfi.cc | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/compiler-rt/lib/cfi/cfi.cc b/compiler-rt/lib/cfi/cfi.cc index fd9b548..2d22d06 100644 --- a/compiler-rt/lib/cfi/cfi.cc +++ b/compiler-rt/lib/cfi/cfi.cc @@ -32,16 +32,18 @@ typedef ElfW(Ehdr) Elf_Ehdr; namespace __cfi { -static constexpr uptr kCfiShadowLimitsStorageSize = 4096; // 1 page +#define kCfiShadowLimitsStorageSize 4096 // 1 page // Lets hope that the data segment is mapped with 4K pages. // The pointer to the cfi shadow region is stored at the start of this page. // The rest of the page is unused and re-mapped read-only. -static char cfi_shadow_pointer_storage[kCfiShadowLimitsStorageSize] +static union { + char space[kCfiShadowLimitsStorageSize]; + struct { + uptr start; + uptr size; + } limits; +} cfi_shadow_limits_storage __attribute__((aligned(kCfiShadowLimitsStorageSize))); -struct ShadowLimits { - uptr start; - uptr size; -}; static constexpr uptr kShadowGranularity = 12; static constexpr uptr kShadowAlign = 1UL << kShadowGranularity; // 4096 @@ -50,16 +52,16 @@ static constexpr uint16_t kUncheckedShadow = 0xFFFFU; // Get the start address of the CFI shadow region. uptr GetShadow() { - return reinterpret_cast(&cfi_shadow_pointer_storage)->start; + return cfi_shadow_limits_storage.limits.start; } uptr GetShadowSize() { - return reinterpret_cast(&cfi_shadow_pointer_storage)->size; + return cfi_shadow_limits_storage.limits.size; } // This will only work while the shadow is not allocated. void SetShadowSize(uptr size) { - reinterpret_cast(&cfi_shadow_pointer_storage)->size = size; + cfi_shadow_limits_storage.limits.size = size; } uptr MemToShadowOffset(uptr x) { @@ -159,9 +161,9 @@ void ShadowBuilder::Install() { // Initial setup. CHECK_EQ(kCfiShadowLimitsStorageSize, GetPageSizeCached()); CHECK_EQ(0, GetShadow()); - *reinterpret_cast(&cfi_shadow_pointer_storage) = shadow_; - MprotectReadOnly((uptr)&cfi_shadow_pointer_storage, - kCfiShadowLimitsStorageSize); + cfi_shadow_limits_storage.limits.start = shadow_; + MprotectReadOnly((uptr)&cfi_shadow_limits_storage, + sizeof(cfi_shadow_limits_storage)); CHECK_EQ(shadow_, GetShadow()); } } -- 2.7.4