[llvm] r208296 - [asan] Preserve flags in asm instrumentation.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Thu May 8 02:55:24 PDT 2014
Author: eugenis
Date: Thu May 8 04:55:24 2014
New Revision: 208296
URL: http://llvm.org/viewvc/llvm-project?rev=208296&view=rev
Log:
[asan] Preserve flags in asm instrumentation.
Patch by Yuri Gorshenin.
Modified:
llvm/trunk/lib/Target/X86/AsmParser/X86AsmInstrumentation.cpp
llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_mov.ll
llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_mov.s
llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_swap_intel.s
Modified: llvm/trunk/lib/Target/X86/AsmParser/X86AsmInstrumentation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmParser/X86AsmInstrumentation.cpp?rev=208296&r1=208295&r2=208296&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmParser/X86AsmInstrumentation.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmParser/X86AsmInstrumentation.cpp Thu May 8 04:55:24 2014
@@ -177,13 +177,26 @@ public:
MCStreamer &Out) override;
};
-void X86AddressSanitizer64::InstrumentMemOperandImpl(
- X86Operand *Op, unsigned AccessSize, bool IsWrite, MCContext &Ctx,
- MCStreamer &Out) {
+void X86AddressSanitizer64::InstrumentMemOperandImpl(X86Operand *Op,
+ unsigned AccessSize,
+ bool IsWrite,
+ MCContext &Ctx,
+ MCStreamer &Out) {
// FIXME: emit .cfi directives for correct stack unwinding.
- // Set %rsp below current red zone (128 bytes wide)
- EmitInstruction(Out, MCInstBuilder(X86::SUB64ri32).addReg(X86::RSP)
- .addReg(X86::RSP).addImm(128));
+
+ // Set %rsp below current red zone (128 bytes wide) using LEA instruction to
+ // preserve flags.
+ {
+ MCInst Inst;
+ Inst.setOpcode(X86::LEA64r);
+ Inst.addOperand(MCOperand::CreateReg(X86::RSP));
+
+ const MCExpr *Disp = MCConstantExpr::Create(-128, Ctx);
+ X86Operand *Op =
+ X86Operand::CreateMem(0, Disp, X86::RSP, 0, 1, SMLoc(), SMLoc());
+ Op->addMemOperands(Inst, 5);
+ EmitInstruction(Out, Inst);
+ }
EmitInstruction(Out, MCInstBuilder(X86::PUSH64r).addReg(X86::RDI));
{
MCInst Inst;
@@ -200,8 +213,19 @@ void X86AddressSanitizer64::InstrumentMe
EmitInstruction(Out, MCInstBuilder(X86::CALL64pcrel32).addExpr(FuncExpr));
}
EmitInstruction(Out, MCInstBuilder(X86::POP64r).addReg(X86::RDI));
- EmitInstruction(Out, MCInstBuilder(X86::ADD64ri32).addReg(X86::RSP)
- .addReg(X86::RSP).addImm(128));
+
+ // Restore old %rsp value.
+ {
+ MCInst Inst;
+ Inst.setOpcode(X86::LEA64r);
+ Inst.addOperand(MCOperand::CreateReg(X86::RSP));
+
+ const MCExpr *Disp = MCConstantExpr::Create(128, Ctx);
+ X86Operand *Op =
+ X86Operand::CreateMem(0, Disp, X86::RSP, 0, 1, SMLoc(), SMLoc());
+ Op->addMemOperands(Inst, 5);
+ EmitInstruction(Out, Inst);
+ }
}
} // End anonymous namespace
Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_mov.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_mov.ll?rev=208296&r1=208295&r2=208296&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_mov.ll (original)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_mov.ll Thu May 8 04:55:24 2014
@@ -4,19 +4,19 @@ target datalayout = "e-p:64:64:64-i1:8:8
target triple = "x86_64-unknown-linux-gnu"
; CHECK-LABEL: mov1b
-; CHECK: subq $128, %rsp
+; CHECK: leaq -128(%rsp), %rsp
; CHECK-NEXT: pushq %rdi
; CHECK-NEXT: leaq {{.*}}, %rdi
; CHECK-NEXT: callq __sanitizer_sanitize_load1 at PLT
; CHECK-NEXT: popq %rdi
-; CHECK-NEXT: addq $128, %rsp
+; CHECK-NEXT: leaq 128(%rsp), %rsp
-; CHECK: subq $128, %rsp
+; CHECK: leaq -128(%rsp), %rsp
; CHECK-NEXT: pushq %rdi
; CHECK-NEXT: leaq {{.*}}, %rdi
; CHECK-NEXT: callq __sanitizer_sanitize_store1 at PLT
; CHECK-NEXT: popq %rdi
-; CHECK-NEXT: addq $128, %rsp
+; CHECK-NEXT: leaq 128(%rsp), %rsp
; CHECK: movb {{.*}}, {{.*}}
define void @mov1b(i8* %dst, i8* %src) #0 {
@@ -26,19 +26,19 @@ entry:
}
; CHECK-LABEL: mov2b
-; CHECK: subq $128, %rsp
+; CHECK: leaq -128(%rsp), %rsp
; CHECK-NEXT: pushq %rdi
; CHECK-NEXT: leaq {{.*}}, %rdi
; CHECK-NEXT: callq __sanitizer_sanitize_load2 at PLT
; CHECK-NEXT: popq %rdi
-; CHECK-NEXT: addq $128, %rsp
+; CHECK-NEXT: leaq 128(%rsp), %rsp
-; CHECK: subq $128, %rsp
+; CHECK: leaq -128(%rsp), %rsp
; CHECK-NEXT: pushq %rdi
; CHECK-NEXT: leaq {{.*}}, %rdi
; CHECK-NEXT: callq __sanitizer_sanitize_store2 at PLT
; CHECK-NEXT: popq %rdi
-; CHECK-NEXT: addq $128, %rsp
+; CHECK-NEXT: leaq 128(%rsp), %rsp
; CHECK: movw {{.*}}, {{.*}}
define void @mov2b(i16* %dst, i16* %src) #0 {
@@ -48,19 +48,19 @@ entry:
}
; CHECK-LABEL: mov4b
-; CHECK: subq $128, %rsp
+; CHECK: leaq -128(%rsp), %rsp
; CHECK-NEXT: pushq %rdi
; CHECK-NEXT: leaq {{.*}}, %rdi
; CHECK-NEXT: callq __sanitizer_sanitize_load4 at PLT
; CHECK-NEXT: popq %rdi
-; CHECK-NEXT: addq $128, %rsp
+; CHECK-NEXT: leaq 128(%rsp), %rsp
-; CHECK: subq $128, %rsp
+; CHECK: leaq -128(%rsp), %rsp
; CHECK-NEXT: pushq %rdi
; CHECK-NEXT: leaq {{.*}}, %rdi
; CHECK-NEXT: callq __sanitizer_sanitize_store4 at PLT
; CHECK-NEXT: popq %rdi
-; CHECK-NEXT: addq $128, %rsp
+; CHECK-NEXT: leaq 128(%rsp), %rsp
; CHECK: movl {{.*}}, {{.*}}
define void @mov4b(i32* %dst, i32* %src) #0 {
@@ -70,19 +70,19 @@ entry:
}
; CHECK-LABEL: mov8b
-; CHECK: subq $128, %rsp
+; CHECK: leaq -128(%rsp), %rsp
; CHECK-NEXT: pushq %rdi
; CHECK-NEXT: leaq {{.*}}, %rdi
; CHECK-NEXT: callq __sanitizer_sanitize_load8 at PLT
; CHECK-NEXT: popq %rdi
-; CHECK-NEXT: addq $128, %rsp
+; CHECK-NEXT: leaq 128(%rsp), %rsp
-; CHECK: subq $128, %rsp
+; CHECK: leaq -128(%rsp), %rsp
; CHECK-NEXT: pushq %rdi
; CHECK-NEXT: leaq {{.*}}, %rdi
; CHECK-NEXT: callq __sanitizer_sanitize_store8 at PLT
; CHECK-NEXT: popq %rdi
-; CHECK-NEXT: addq $128, %rsp
+; CHECK-NEXT: leaq 128(%rsp), %rsp
; CHECK: movq {{.*}}, {{.*}}
define void @mov8b(i64* %dst, i64* %src) #0 {
@@ -92,19 +92,19 @@ entry:
}
; CHECK-LABEL: mov16b
-; CHECK: subq $128, %rsp
+; CHECK: leaq -128(%rsp), %rsp
; CHECK-NEXT: pushq %rdi
; CHECK-NEXT: leaq {{.*}}, %rdi
; CHECK-NEXT: callq __sanitizer_sanitize_load16 at PLT
; CHECK-NEXT: popq %rdi
-; CHECK-NEXT: addq $128, %rsp
+; CHECK-NEXT: leaq 128(%rsp), %rsp
-; CHECK: subq $128, %rsp
+; CHECK: leaq -128(%rsp), %rsp
; CHECK-NEXT: pushq %rdi
; CHECK-NEXT: leaq {{.*}}, %rdi
; CHECK-NEXT: callq __sanitizer_sanitize_store16 at PLT
; CHECK-NEXT: popq %rdi
-; CHECK-NEXT: addq $128, %rsp
+; CHECK-NEXT: leaq 128(%rsp), %rsp
; CHECK: movaps {{.*}}, {{.*}}
define void @mov16b(<2 x i64>* %dst, <2 x i64>* %src) #0 {
Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_mov.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_mov.s?rev=208296&r1=208295&r2=208296&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_mov.s (original)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_mov.s Thu May 8 04:55:24 2014
@@ -6,21 +6,21 @@
.type mov1b, at function
# CHECK-LABEL: mov1b:
#
-# CHECK: subq $128, %rsp
+# CHECK: leaq -128(%rsp), %rsp
# CHECK-NEXT: pushq %rdi
# CHECK-NEXT: leaq (%rsi), %rdi
# CHECK-NEXT: callq __sanitizer_sanitize_load1 at PLT
# CHECK-NEXT: popq %rdi
-# CHECK-NEXT: addq $128, %rsp
+# CHECK-NEXT: leaq 128(%rsp), %rsp
#
# CHECK-NEXT: movb (%rsi), %al
#
-# CHECK-NEXT: subq $128, %rsp
+# CHECK-NEXT: leaq -128(%rsp), %rsp
# CHECK-NEXT: pushq %rdi
# CHECK-NEXT: leaq (%rdi), %rdi
# CHECK-NEXT: callq __sanitizer_sanitize_store1 at PLT
# CHECK-NEXT: popq %rdi
-# CHECK-NEXT: addq $128, %rsp
+# CHECK-NEXT: leaq 128(%rsp), %rsp
#
# CHECK-NEXT: movb %al, (%rdi)
mov1b: # @mov1b
@@ -41,21 +41,21 @@ mov1b:
.type mov16b, at function
# CHECK-LABEL: mov16b:
#
-# CHECK: subq $128, %rsp
+# CHECK: leaq -128(%rsp), %rsp
# CHECK-NEXT: pushq %rdi
# CHECK-NEXT: leaq (%rsi), %rdi
# CHECK-NEXT: callq __sanitizer_sanitize_load16 at PLT
# CHECK-NEXT: popq %rdi
-# CHECK-NEXT: addq $128, %rsp
+# CHECK-NEXT: leaq 128(%rsp), %rsp
#
# CHECK-NEXT: movaps (%rsi), %xmm0
#
-# CHECK-NEXT: subq $128, %rsp
+# CHECK-NEXT: leaq -128(%rsp), %rsp
# CHECK-NEXT: pushq %rdi
# CHECK-NEXT: leaq (%rdi), %rdi
# CHECK-NEXT: callq __sanitizer_sanitize_store16 at PLT
# CHECK-NEXT: popq %rdi
-# CHECK-NEXT: addq $128, %rsp
+# CHECK-NEXT: leaq 128(%rsp), %rsp
#
# CHECK-NEXT: movaps %xmm0, (%rdi)
mov16b: # @mov16b
Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_swap_intel.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_swap_intel.s?rev=208296&r1=208295&r2=208296&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_swap_intel.s (original)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/X86/asm_swap_intel.s Thu May 8 04:55:24 2014
@@ -6,39 +6,39 @@
.type swap, at function
# CHECK-LABEL: swap:
#
-# CHECK: subq $128, %rsp
+# CHECK: leaq -128(%rsp), %rsp
# CHECK-NEXT: pushq %rdi
# CHECK-NEXT: leaq (%rcx), %rdi
# CHECK-NEXT: callq __sanitizer_sanitize_load8 at PLT
# CHECK-NEXT: popq %rdi
-# CHECK-NEXT: addq $128, %rsp
+# CHECK-NEXT: leaq 128(%rsp), %rsp
#
# CHECK-NEXT: movq (%rcx), %rax
#
-# CHECK-NEXT: subq $128, %rsp
+# CHECK-NEXT: leaq -128(%rsp), %rsp
# CHECK-NEXT: pushq %rdi
# CHECK-NEXT: leaq (%rdx), %rdi
# CHECK-NEXT: callq __sanitizer_sanitize_load8 at PLT
# CHECK-NEXT: popq %rdi
-# CHECK-NEXT: addq $128, %rsp
+# CHECK-NEXT: leaq 128(%rsp), %rsp
#
# CHECK-NEXT: movq (%rdx), %rbx
#
-# CHECK: subq $128, %rsp
+# CHECK: leaq -128(%rsp), %rsp
# CHECK-NEXT: pushq %rdi
# CHECK-NEXT: leaq (%rcx), %rdi
# CHECK-NEXT: callq __sanitizer_sanitize_store8 at PLT
# CHECK-NEXT: popq %rdi
-# CHECK-NEXT: addq $128, %rsp
+# CHECK-NEXT: leaq 128(%rsp), %rsp
#
# CHECK-NEXT: movq %rbx, (%rcx)
#
-# CHECK-NEXT: subq $128, %rsp
+# CHECK-NEXT: leaq -128(%rsp), %rsp
# CHECK-NEXT: pushq %rdi
# CHECK-NEXT: leaq (%rdx), %rdi
# CHECK-NEXT: callq __sanitizer_sanitize_store8 at PLT
# CHECK-NEXT: popq %rdi
-# CHECK-NEXT: addq $128, %rsp
+# CHECK-NEXT: leaq 128(%rsp), %rsp
#
# CHECK-NEXT: movq %rax, (%rdx)
swap: # @swap
More information about the llvm-commits
mailing list