Skip to content

Asan with Windows EH generates __asan_xxx runtime calls without required funclet tokens #64990

@sylvain-audi

Description

@sylvain-audi

This issue has been discussed in #39667 as well as google/sanitizers#749

As mentionned by @rnk in a comment: "ASan instrumentation isn't inserting calls into EH pads with the right funclet token bundle, so any attempts to do ASan checks inside funclets will be removed by WinEHPrepare. "

It seems that not only WinEHPrepare will remove the calls themselves but it also discards the entire Basic Block around it, replacing the content with unreachable statement.

Here is a repro:

char buff1[6] = "hello";
char buff2[6] = "hello";

int main(int argc, char **argv) {
  int result = 1;
  try {
    throw 1;
  } catch (...) {
    // make asan generate call to __asan_memcpy that should report an error due to memory overflow.
    __builtin_memcpy(buff1, buff2 + 3, 6);
    result = 0;
  }
  return result;
}

See in Compiler Explorer: https://godbolt.org/z/Tacdhsz4T
Notice, in the LLVM Opt Pipeline Viewer, the WinEHPrepare pass of main: the entire catch Basic block and successors get transformed into a single unreachable statement.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions