UBSan detects misaligned memory accesses in llvm-profdata and llvm-cov

Hi!

UBSan bootstrap bot fails with error report on 5 llvm-cov and llvm-profdata lit-tests:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/4526/steps/check-llvm%20ubsan/logs/stdio
Also see http://llvm.org/bugs/show_bug.cgi?id=20815.

The error reports look vaild: in general it’s incorrect to load uint64_t, or even structures like “RawHeader” or “CoverageMappingTURecord” from a random address. Also, if you parse files stored on disk, it would certainly help to know endianness of data in these files and, e.g., use routines from Support/Endian.h. Can you take a look at this?

Alexey Samsonov <vonosmas@gmail.com> writes:

Hi!

UBSan bootstrap bot fails with error report on 5 llvm-cov and llvm-profdata
lit-tests:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/4526
/steps/check-llvm%20ubsan/logs/stdio
Also see http://llvm.org/bugs/show_bug.cgi?id=20815.

Thanks for pointing these out!

The error reports look vaild: in general it's incorrect to load uint64_t, or
even structures like "RawHeader" or "CoverageMappingTURecord" from a random
address. Also, if you parse files stored on disk, it would certainly help to
know endianness of data in these files and, e.g., use routines from Support/
Endian.h. Can you take a look at this?

I've fixed the llvm-profdata failure in r217708. The file format has a
known endianness and is always padded to a proper alignment, so this is
just a matter of rejecting files that are malformed.

I'm a bit less familiar with the llvm-cov format, so I'll look into that
one and get it fixed in the next day or two.

Thanks!