[PATCH] D103562: [NFC][compiler-rt][hwasan] Refactor hwasan functions

Alexey Baturo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 6 01:18:53 PDT 2022


smd added inline comments.


================
Comment at: compiler-rt/lib/hwasan/hwasan.cpp:205
+  if (registers_frame && stack->trace && stack->size > 0) {
+    stack->trace++;
+    stack->size--;
----------------
fmayer wrote:
> fmayer wrote:
> > fmayer wrote:
> > > vitalybuka wrote:
> > > > maybe we should pop everything up to "pc" to avoid issues with nested calls?
> > > > 
> > > > For most users hwasan frames are not very useful. However if you work on sanitizer, some frames can be a useful info. So I don't mind we just relax test cases to accommodate this nesting.
> > > > 
> > > > cc @smd 
> > > This is probably for another patch though, right? This is already like this on the LHS.
> > nevermind. i accidentally had this left, sent https://reviews.llvm.org/D131279 for that.
> Sorry, please disregard everything I said here (incl the link). I confused myself where this was posted, and this is all nonsense.
@vitalybuka thanks for the reply.

>However if you work on sanitizer, some frames can be a useful info
>From my experience most of the time while I'm working on sanitizers I spend in gdb, so I don't actually care about what backtrace is being printed. So it might be a good idea to avoid confusing regular hwasan user and skip printing service hwasan frames.

Maybe we just could keep the current scheme, but get return address and frame pointer in __hwasan_tag_mismatch4 like it was before? Something like:
```
void HwasanTagMismatch(uptr addr, uptr pc, uptr frame, uptr access_info, uptr *registers_frame, size_t outsize) {
  __hwasan::AccessInfo ai;
  ai.is_store = access_info & 0x10;
  ai.is_load = !ai.is_store;
  ai.recover = access_info & 0x20;
  ai.addr = addr;
  if ((access_info & 0xf) == 0xf)
    ai.size = outsize;
  else
    ai.size = 1 << (access_info & 0xf);

  HandleTagMismatch(ai, pc, frame, nullptr, registers_frame);
}
...
void __hwasan_tag_mismat(uptr)__builtin_frame_address(0)ch4(uptr addr, uptr access_info, uptr *registers_frame,
                            size_t outsize) {
  uptr ra = (uptr)__builtin_return_address(0);
  uptr fp = (uptr)__builtin_frame_address(0);
  __hwasan::HwasanTagMismatch(addr, ra, fp, access_info, registers_frame, outsize);
}
```

@fmayer 
>LTO could conceivably inline this – in which case it would be one, right?
Yes, you're totally right.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103562/new/

https://reviews.llvm.org/D103562



More information about the cfe-commits mailing list