ramosian-glider / sanitizers

0 stars 0 forks source link

Slightly inefficient instrumentation of 1-byte accesses: #63

Closed ramosian-glider closed 9 years ago

ramosian-glider commented 9 years ago

Originally reported on Google Code with ID 62

Repro:
=======================================
#include <stdio.h>
int main() {
  volatile char array[1] = {42};
  if (array[0] == 0x42)
    printf("Boo!\n");
}
=======================================

$ clang++ -faddress-sanitizer test.cpp  # on x64
$ objdump -D ./a.out
0000000000404850 <main>:
...
  4049d1:       48 8b 54 24 50          mov    0x50(%rsp),%rdx
  4049d6:       48 c1 ea 03             shr    $0x3,%rdx
  4049da:       48 be 00 00 00 00 00    mov    $0x100000000000,%rsi
  4049e1:       10 00 00 
  4049e4:       48 09 f2                or     %rsi,%rdx
  4049e7:       8a 02                   mov    (%rdx),%al
  4049e9:       3c 00                   cmp    $0x0,%al
  4049eb:       88 44 24 14             mov    %al,0x14(%rsp)
  4049ef:       0f 85 57 01 00 00       jne    404b4c <main+0x2fc>
  4049f5:       48 8b 44 24 50          mov    0x50(%rsp),%rax
  4049fa:       8a 08                   mov    (%rax),%cl
  4049fc:       0f be d1                movsbl %cl,%edx
  4049ff:       81 fa 42 00 00 00       cmp    $0x42,%edx
...
  404b4c:       48 8b 44 24 50          mov    0x50(%rsp),%rax
  404b51:       48 25 07 00 00 00       and    $0x7,%rax
  404b57:       48 05 00 00 00 00       add    $0x0,%rax    ###########
  404b5d:       88 c1                   mov    %al,%cl
  404b5f:       8a 54 24 14             mov    0x14(%rsp),%dl
  404b63:       38 d1                   cmp    %dl,%cl
  404b65:       0f 8d 05 00 00 00       jge    404b70 <main+0x320> ####
  404b6b:       e9 85 fe ff ff          jmpq   4049f5 <main+0x1a5> ####
  404b70:       48 8b 7c 24 50          mov    0x50(%rsp),%rdi
  404b75:       e8 66 22 00 00          callq  406de0 <__asan_report_load1>

I believe
a) `add 0,%rax` is a redundant no-op
b) jge/jmpq should be replaced by jlt

Reported by timurrrr on 2012-04-13 10:11:17

ramosian-glider commented 9 years ago
FTR,
$ clang++ --version
clang version 3.1 (trunk 154589)

Reported by timurrrr on 2012-04-13 10:18:12

ramosian-glider commented 9 years ago
Ooops, this is -O0.

I'd rather not emit `add 0,%rax` for 1-byte accesses anyways though.

Reported by timurrrr on 2012-04-13 10:25:43

ramosian-glider commented 9 years ago
Do we need to keep it (given that this is an LLVM issue, if at all)?

Reported by konstantin.s.serebryany on 2012-04-25 13:57:23

ramosian-glider commented 9 years ago
Timur convinced me that this is worth fixing. r155701.

Reported by konstantin.s.serebryany on 2012-04-27 10:06:18

ramosian-glider commented 9 years ago
Adding Project:AddressSanitizer as part of GitHub migration.

Reported by ramosian.glider on 2015-07-30 09:12:59