[llvm] r268724 - [asan] add option to set shadow mapping offset

Ryan Govostes via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 03:25:22 PDT 2016


Author: rgov
Date: Fri May  6 05:25:22 2016
New Revision: 268724

URL: http://llvm.org/viewvc/llvm-project?rev=268724&view=rev
Log:
[asan] add option to set shadow mapping offset

Allowing overriding the default ASAN shadow mapping offset with the
-asan-shadow-offset option, and allow zero to be specified for both offset and
scale.

Patch by Aaron Carroll <aaronc at apple.com>.

Added:
    llvm/trunk/test/Instrumentation/AddressSanitizer/scale-offset.ll
Modified:
    llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=268724&r1=268723&r2=268724&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Fri May  6 05:25:22 2016
@@ -204,10 +204,13 @@ static cl::opt<bool> ClSkipPromotableAll
 
 // These flags allow to change the shadow mapping.
 // The shadow mapping looks like
-//    Shadow = (Mem >> scale) + (1 << offset_log)
+//    Shadow = (Mem >> scale) + offset
 static cl::opt<int> ClMappingScale("asan-mapping-scale",
                                    cl::desc("scale of asan shadow mapping"),
                                    cl::Hidden, cl::init(0));
+static cl::opt<unsigned long long> ClMappingOffset("asan-mapping-offset",
+                                   cl::desc("offset of asan shadow mapping [EXPERIMENTAL]"),
+                                   cl::Hidden, cl::init(0));
 
 // Optimization flags. Not user visible, used mostly for testing
 // and benchmarking the tool.
@@ -404,10 +407,14 @@ static ShadowMapping getShadowMapping(Tr
   }
 
   Mapping.Scale = kDefaultShadowScale;
-  if (ClMappingScale) {
+  if (ClMappingScale.getNumOccurrences() > 0) {
     Mapping.Scale = ClMappingScale;
   }
 
+  if (ClMappingOffset.getNumOccurrences() > 0) {
+    Mapping.Offset = ClMappingOffset;
+  }
+
   // OR-ing shadow offset if more efficient (at least on x86) if the offset
   // is a power of two, but on ppc64 we have to use add since the shadow
   // offset is not necessary 1/8-th of the address space.  On SystemZ,

Added: llvm/trunk/test/Instrumentation/AddressSanitizer/scale-offset.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/scale-offset.ll?rev=268724&view=auto
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/scale-offset.ll (added)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/scale-offset.ll Fri May  6 05:25:22 2016
@@ -0,0 +1,39 @@
+; Test that the scale (-asan-mapping-scale) and offset (-asan-mapping-offset) command-line options work as expected
+;
+; RUN: opt < %s -asan -asan-module -asan-mapping-offset 0xdeadbeef -S | FileCheck --check-prefix=CHECK-OFFSET %s
+; RUN: opt < %s -asan -asan-module -asan-mapping-scale 1 -S | FileCheck --check-prefix=CHECK-SCALE %s
+; RUN: opt < %s -asan -asan-module -asan-mapping-offset 0xc0ffee -asan-mapping-scale 0 -S | FileCheck --check-prefix=CHECK-BOTH %s
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @read_offset(i32* %a) sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  ret i32 %tmp1
+}
+; CHECK-OFFSET-LABEL: @read_offset
+; CHECK-OFFSET-NOT: ret
+; CHECK-OFFSET: lshr {{.*}} 3
+; CHECK-OFFSET-NEXT: add{{.*}}3735928559
+; CHECK-OFFSET: ret
+
+define i32 @read_scale(i32* %a) sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  ret i32 %tmp1
+}
+; CHECK-SCALE-LABEL: @read_scale
+; CHECK-SCALE-NOT: ret
+; CHECK-SCALE: lshr {{.*}} 1
+; CHECK-SCALE-NEXT: add{{.*}}
+; CHECK-SCALE: ret
+
+define i32 @read_both(i32* %a) sanitize_address {
+entry:
+  %tmp1 = load i32, i32* %a, align 4
+  ret i32 %tmp1
+}
+; CHECK-BOTH-LABEL: @read_both
+; CHECK-BOTH-NOT: ret
+; CHECK-BOTH: lshr {{.*}} 0
+; CHECK-BOTH-NEXT: add{{.*}}12648430
+; CHECK-BOTH: ret




More information about the llvm-commits mailing list