[PATCH] D18817: [ASAN] Use struct instead of array in sancov.py
Sagar Thakur via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 6 02:05:17 PDT 2016
sagar created this revision.
sagar added reviewers: dsanders, kcc, samsonov.
sagar added subscribers: mohit.bhakkad, jaydeep, llvm-commits.
sagar set the repository for this revision to rL LLVM.
Herald added a reviewer: vkalintiris.
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.
Repository:
rL LLVM
http://reviews.llvm.org/D18817
Files:
lib/sanitizer_common/scripts/sancov.py
Index: lib/sanitizer_common/scripts/sancov.py
===================================================================
--- lib/sanitizer_common/scripts/sancov.py
+++ lib/sanitizer_common/scripts/sancov.py
@@ -30,6 +30,10 @@
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;
@@ -148,7 +152,7 @@
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), f.read(size))
mem_map_pcs = [[] for i in range(0, len(mem_map))]
for pc in pcs:
@@ -166,11 +170,12 @@
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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18817.52770.patch
Type: text/x-patch
Size: 1460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160406/288e8a10/attachment.bin>
More information about the llvm-commits
mailing list