Index: lib/asan/asan_asm_instrumentation.S =================================================================== --- lib/asan/asan_asm_instrumentation.S +++ lib/asan/asan_asm_instrumentation.S @@ -324,7 +324,7 @@ .globl __sanitizer_sanitize_store1 .type __sanitizer_sanitize_store1, @function __sanitizer_sanitize_store1: - subq $128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushq %rcx pushfq @@ -347,14 +347,14 @@ popfq popq %rcx popq %rax - addq $128, %rsp + leaq 128(%rsp), %rsp ret // Sanitize 1-byte load. Takes one 8-byte address as an argument in %rdi, // nothing is returned. .globl __sanitizer_sanitize_load1 .type __sanitizer_sanitize_load1, @function __sanitizer_sanitize_load1: - subq $128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushq %rcx pushfq @@ -377,14 +377,14 @@ popfq popq %rcx popq %rax - addq $128, %rsp + leaq 128(%rsp), %rsp ret // Sanitize 2-byte store. Takes one 8-byte address as an argument in %rdi, // nothing is returned. .globl __sanitizer_sanitize_store2 .type __sanitizer_sanitize_store2, @function __sanitizer_sanitize_store2: - subq $128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushq %rcx pushfq @@ -408,14 +408,14 @@ popfq popq %rcx popq %rax - addq $128, %rsp + leaq 128(%rsp), %rsp ret // Sanitize 2-byte load. Takes one 8-byte address as an argument in %rdi, // nothing is returned. .globl __sanitizer_sanitize_load2 .type __sanitizer_sanitize_load2, @function __sanitizer_sanitize_load2: - subq $128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushq %rcx pushfq @@ -439,14 +439,14 @@ popfq popq %rcx popq %rax - addq $128, %rsp + leaq 128(%rsp), %rsp ret // Sanitize 4-byte store. Takes one 8-byte address as an argument in %rdi, // nothing is returned. .globl __sanitizer_sanitize_store4 .type __sanitizer_sanitize_store4, @function __sanitizer_sanitize_store4: - subq $128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushq %rcx pushfq @@ -470,14 +470,14 @@ popfq popq %rcx popq %rax - addq $128, %rsp + leaq 128(%rsp), %rsp ret // Sanitize 4-byte load. Takes one 8-byte address as an argument in %rdi, // nothing is returned. .globl __sanitizer_sanitize_load4 .type __sanitizer_sanitize_load4, @function __sanitizer_sanitize_load4: - subq $128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushq %rcx pushfq @@ -501,14 +501,14 @@ popfq popq %rcx popq %rax - addq $128, %rsp + leaq 128(%rsp), %rsp ret // Sanitize 8-byte store. Takes one 8-byte address as an argument in %rdi, // nothing is returned. .globl __sanitizer_sanitize_store8 .type __sanitizer_sanitize_store8, @function __sanitizer_sanitize_store8: - subq $128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushfq movq %rdi, %rax @@ -523,14 +523,14 @@ .sanitize_store8_done: popfq popq %rax - addq $128, %rsp + leaq 128(%rsp), %rsp ret // Sanitize 8-byte load. Takes one 8-byte address as an argument in %rdi, // nothing is returned. .globl __sanitizer_sanitize_load8 .type __sanitizer_sanitize_load8, @function __sanitizer_sanitize_load8: - subq $128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushfq movq %rdi, %rax @@ -545,14 +545,14 @@ .sanitize_load8_done: popfq popq %rax - addq $128, %rsp + leaq 128(%rsp), %rsp ret // Sanitize 16-byte store. Takes one 8-byte address as an argument in %rdi, // nothing is returned. .globl __sanitizer_sanitize_store16 .type __sanitizer_sanitize_store16, @function __sanitizer_sanitize_store16: - subq $128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushfq movq %rdi, %rax @@ -567,14 +567,14 @@ .sanitize_store16_done: popfq popq %rax - addq $128, %rsp + leaq 128(%rsp), %rsp ret // Sanitize 16-byte load. Takes one 8-byte address as an argument in %rdi, // nothing is returned. .globl __sanitizer_sanitize_load16 .type __sanitizer_sanitize_load16, @function __sanitizer_sanitize_load16: - subq $128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushfq movq %rdi, %rax @@ -589,7 +589,7 @@ .sanitize_load16_done: popfq popq %rax - addq $128, %rsp + leaq 128(%rsp), %rsp ret #endif // defined(__x86_64__) /* We do not need executable stack. */ Index: lib/asan/scripts/gen_asm_instrumentation.sh =================================================================== --- lib/asan/scripts/gen_asm_instrumentation.sh +++ lib/asan/scripts/gen_asm_instrumentation.sh @@ -181,7 +181,7 @@ .globl $(func_name $at $as) .type $(func_name $at $as), @function $(func_name $at $as): - subq \$128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushq %rcx pushfq @@ -211,7 +211,7 @@ popfq popq %rcx popq %rax - addq \$128, %rsp + leaq 128(%rsp), %rsp ret EOF done @@ -228,7 +228,7 @@ .globl $(func_name $at $as) .type $(func_name $at $as), @function $(func_name $at $as): - subq \$128, %rsp + leaq -128(%rsp), %rsp pushq %rax pushfq movq %rdi, %rax @@ -248,7 +248,7 @@ $(func_label $at $as): popfq popq %rax - addq \$128, %rsp + leaq 128(%rsp), %rsp ret EOF done Index: lib/asan/tests/CMakeLists.txt =================================================================== --- lib/asan/tests/CMakeLists.txt +++ lib/asan/tests/CMakeLists.txt @@ -60,6 +60,7 @@ ${ASAN_UNITTEST_COMMON_CFLAGS} -fsanitize=address "-fsanitize-blacklist=${ASAN_BLACKLIST_FILE}" + -mllvm -asan-instrument-assembly ) if(NOT MSVC) Index: lib/asan/tests/asan_asm_test.cc =================================================================== --- lib/asan/tests/asan_asm_test.cc +++ lib/asan/tests/asan_asm_test.cc @@ -197,6 +197,40 @@ delete [] buf; } +#if defined(__x86_64__) + +void TestFlags() { + long magic = 0x1234; + long r = 0x0; + __asm__("xorq %%rax, %%rax \n\t" + "movq (%[p]), %%rax \n\t" + "sete %%al \n\t" + "movzbq %%al, %[r] \n\t" + : [r] "=r"(r) + : [p] "r"(&magic) + : "rax", "memory"); + ASSERT_EQ(0x1, r); +} + +#endif // defined(__x86_64__) + +#if defined(__i386__) + +void TestFlags() { + long magic = 0x1234; + long r = 0x0; + __asm__("xorl %%eax, %%eax \n\t" + "movl (%[p]), %%eax \n\t" + "sete %%al \n\t" + "movzbl %%al, %[r] \n\t" + : [r] "=r"(r) + : [p] "r"(&magic) + : "eax", "memory"); + ASSERT_EQ(0x1, r); +} + +#endif // defined(__i386__) + } // End of anonymous namespace TEST(AddressSanitizer, asm_rw) { @@ -211,6 +245,8 @@ TestAsmRead("READ of size 4"); TestAsmRead("READ of size 8"); TestAsmRead<__m128i>("READ of size 16"); + + TestFlags(); } #endif // defined(__x86_64__) || (defined(__i386__) && defined(__SSE2__))