InstrProf: Do a better job of reading coverage mapping data.
authorJustin Bogner <mail@justinbogner.com>
Mon, 16 Mar 2015 06:55:45 +0000 (06:55 +0000)
committerJustin Bogner <mail@justinbogner.com>
Mon, 16 Mar 2015 06:55:45 +0000 (06:55 +0000)
commit5e4931b4893b5d3fe1da777d548cbfe9f68ef433
tree2101b344e091c6fcfb17a914ecf900106e2b5874
parent991f3ead4eca9baef1ce1f9d1a313e0aa7247c9c
InstrProf: Do a better job of reading coverage mapping data.

This code was casting regions of a memory buffer to a couple of
different structs. This is wrong in a few ways:

1. It breaks aliasing rules.
2. If the buffer isn't aligned, it hits undefined behaviour.
3. It completely ignores endianness differences.
4. The structs being defined for this aren't specifying their padding
   properly, so this doesn't even represent the data properly on some
   platforms.

This commit is mostly NFC, except that it fixes reading coverage for
32 bit binaries as a side effect of getting rid of the mispadded
structs. I've included a test for that.

I've also baked in that we only handle little endian more explicitly,
since that was true in practice already. I'll fix this to handle
endianness properly in a followup commit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232346 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Support/Endian.h
lib/ProfileData/CoverageMappingReader.cpp
test/tools/llvm-cov/Inputs/binary-formats.macho32l [new file with mode: 0755]
test/tools/llvm-cov/Inputs/binary-formats.macho64l [new file with mode: 0755]
test/tools/llvm-cov/Inputs/binary-formats.proftext [new file with mode: 0644]
test/tools/llvm-cov/binary-formats.c [new file with mode: 0644]
test/tools/llvm-cov/lit.local.cfg