Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly inefficient instrumentation of 1-byte accesses: #62

Closed
ramosian-glider opened this issue Aug 31, 2015 · 5 comments
Closed

Slightly inefficient instrumentation of 1-byte accesses: #62

ramosian-glider opened this issue Aug 31, 2015 · 5 comments

Comments

@ramosian-glider
Copy link
Member

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
Copy link
Member Author

FTR,
$ clang++ --version
clang version 3.1 (trunk 154589)

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

@ramosian-glider
Copy link
Member Author

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

  • Labels added: Priority-Low
  • Labels removed: Priority-Medium

@ramosian-glider
Copy link
Member Author

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

  • Status changed: WontFix

@ramosian-glider
Copy link
Member Author

Timur convinced me that this is worth fixing. r155701.

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

  • Status changed: Fixed

@ramosian-glider
Copy link
Member Author

Adding Project:AddressSanitizer as part of GitHub migration.

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

  • Labels added: ProjectAddressSanitizer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant