summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/scripts
diff options
context:
space:
mode:
authorSagar Thakur <sagar.thakur@imgtec.com>2016-04-22 09:20:22 +0000
committerSagar Thakur <sagar.thakur@imgtec.com>2016-04-22 09:20:22 +0000
commit6ccdfdfc84e3c2c656136dc359b9ec098000f3c1 (patch)
treea7ae4d30da47a13e1ef108494c6a8f566383ba1b /lib/sanitizer_common/scripts
parent6b7dd03a7b30bb2c8f42a337cf5dc492a3171187 (diff)
[ASAN] Use struct instead of array in sancov.py
Summary: When using 32-bit python with 64-bit asan the pc array in sancov.py cannot fit in 64-bit pc's because the type-code 'L' for arrays in python corresponds to the C type long which is only of 4 bytes. Because of this some of the coverage tool tests fail on mips. To fix these test possible solutions are to use 64-bit python or use struct.unpack with the 'Q' type-code. We have used struct.unpack with 'Q' type code since it is not appropriate to have a 64-bit python on all hosts. Reviewed by kcc, aizatsky Differential: http://reviews.llvm.org/D18817 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267126 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/scripts')
-rwxr-xr-xlib/sanitizer_common/scripts/sancov.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/sanitizer_common/scripts/sancov.py b/lib/sanitizer_common/scripts/sancov.py
index a5ae9574a..e19afdb71 100755
--- a/lib/sanitizer_common/scripts/sancov.py
+++ b/lib/sanitizer_common/scripts/sancov.py
@@ -30,6 +30,10 @@ def TypeCodeForBits(bits):
CheckBits(bits)
return 'L' if bits == 64 else 'I'
+def TypeCodeForStruct(bits):
+ CheckBits(bits)
+ return 'Q' if bits == 64 else 'I'
+
kMagic32SecondHalf = 0xFFFFFF32;
kMagic64SecondHalf = 0xFFFFFF64;
kMagicFirstHalf = 0xC0BFFFFF;
@@ -64,7 +68,7 @@ def ReadOneFile(path):
raise Exception('File %s is short (< 8 bytes)' % path)
bits = ReadMagicAndReturnBitness(f, path)
size -= 8
- s = array.array(TypeCodeForBits(bits), f.read(size))
+ s = struct.unpack_from(TypeCodeForStruct(bits) * (size * 8 / bits), f.read(size))
print >>sys.stderr, "%s: read %d %d-bit PCs from %s" % (prog_name, size * 8 / bits, bits, path)
return s
@@ -94,8 +98,8 @@ def MergeAndPrint(files):
if max(s) > 0xFFFFFFFF:
bits = 64
array.array('I', MagicForBits(bits)).tofile(sys.stdout)
- a = array.array(TypeCodeForBits(bits), s)
- a.tofile(sys.stdout)
+ a = struct.pack(TypeCodeForStruct(bits) * len(s), *s)
+ sys.stdout.write(a)
def UnpackOneFile(path):
@@ -148,7 +152,7 @@ def UnpackOneRawFile(path, map_path):
f.seek(0, 2)
size = f.tell()
f.seek(0, 0)
- pcs = array.array(TypeCodeForBits(bits), f.read(size))
+ pcs = struct.unpack_from(TypeCodeForStruct(bits) * (size * 8 / bits), f.read(size))
mem_map_pcs = [[] for i in range(0, len(mem_map))]
for pc in pcs:
@@ -166,11 +170,12 @@ def UnpackOneRawFile(path, map_path):
assert path.endswith('.sancov.raw')
dst_path = module_path + '.' + os.path.basename(path)[:-4]
print >> sys.stderr, "%s: writing %d PCs to %s" % (prog_name, len(pc_list), dst_path)
- arr = array.array(TypeCodeForBits(bits))
- arr.fromlist(sorted(pc_list))
- with open(dst_path, 'ab') as f2:
+ sorted_pc_list = sorted(pc_list)
+ pc_buffer = struct.pack(TypeCodeForStruct(bits) * len(pc_list), *sorted_pc_list)
+ with open(dst_path, 'ab+') as f2:
array.array('I', MagicForBits(bits)).tofile(f2)
- arr.tofile(f2)
+ f2.seek(0, 2)
+ f2.write(pc_buffer)
def RawUnpack(files):
for f in files: