aboutsummaryrefslogtreecommitdiff
path: root/test/CodeGen
diff options
context:
space:
mode:
authorJim Stichnoth <stichnot@chromium.org>2013-07-17 12:13:48 -0700
committerJim Stichnoth <stichnot@chromium.org>2013-07-17 12:13:48 -0700
commitcc8deaf49f79eb22c4edc8c0f44ef64668b3be4a (patch)
tree24e2b88702daa994195a1531d790510207589766 /test/CodeGen
parent5a4bc23e85f58fecbc4e0a6d6fec3c1193bbc350 (diff)
Disallow a global address in the x86-64 displacement field.
This applies only to %r15 sandboxed memory references. The problem is that if the index register is negative, the sandboxing operation will cause the index to become a large positive 32-bit value, which combined with the displacement, will overflow and try to reference memory outside the sandbox. This situation may legitimately occur if the compiler happens to construct a (constant) interior pointer to the middle of the global struct/array, and then dereferences it with a variable offset. After this fix, pnacl/scripts/testsuite_known_failures_pnacl.txt can be updated to remove the "aha x86-64" known failure. BUG= https://code.google.com/p/nativeclient/issues/detail?id=3517 R=eliben@chromium.org Review URL: https://codereview.chromium.org/17987002
Diffstat (limited to 'test/CodeGen')
-rw-r--r--test/CodeGen/X86/no-global-in-disp-x86-64.ll50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/CodeGen/X86/no-global-in-disp-x86-64.ll b/test/CodeGen/X86/no-global-in-disp-x86-64.ll
new file mode 100644
index 0000000000..db911ccff9
--- /dev/null
+++ b/test/CodeGen/X86/no-global-in-disp-x86-64.ll
@@ -0,0 +1,50 @@
+; RUN: pnacl-llc -O2 -mtriple=x86_64-none-nacl < %s | \
+; RUN: FileCheck %s --check-prefix=NACLON
+; RUN: pnacl-llc -O2 -mtriple=x86_64-linux < %s | \
+; RUN: FileCheck %s --check-prefix=NACLOFF
+
+; This test is derived from the following C code:
+;
+; int myglobal[100];
+; void test(int arg)
+; {
+; myglobal[arg] = arg;
+; myglobal[arg+1] = arg;
+; }
+; int main(int argc, char **argv)
+; {
+; test(argc);
+; }
+;
+; The goal is NOT to produce an instruction with "myglobal" as the
+; displacement value in any addressing mode, e.g. this (bad) instruction:
+;
+; movl %eax, %nacl:myglobal(%r15,%rax,4)
+;
+; The NACLOFF test is a canary that tries to ensure that the NACLON test is
+; testing the right thing. If the NACLOFF test starts failing, it's likely
+; that the LLVM -O2 optimizations are no longer generating the problematic
+; pattern that NACLON tests for. In that case, the test should be modified.
+
+
+@myglobal = global [100 x i32] zeroinitializer, align 4
+
+define void @test(i32 %arg) #0 {
+entry:
+; NACLON: test:
+; NACLON-NOT: mov{{.*}}nacl:myglobal(
+; NACLOFF: test:
+; NACLOFF: mov{{.*}}myglobal(
+ %arg.addr = alloca i32, align 4
+ store i32 %arg, i32* %arg.addr, align 4
+ %0 = load i32* %arg.addr, align 4
+ %1 = load i32* %arg.addr, align 4
+ %arrayidx = getelementptr inbounds [100 x i32]* @myglobal, i32 0, i32 %1
+ store i32 %0, i32* %arrayidx, align 4
+ %2 = load i32* %arg.addr, align 4
+ %3 = load i32* %arg.addr, align 4
+ %add = add nsw i32 %3, 1
+ %arrayidx1 = getelementptr inbounds [100 x i32]* @myglobal, i32 0, i32 %add
+ store i32 %2, i32* %arrayidx1, align 4
+ ret void
+}