[compiler-rt] 89031cf - Fix sancov.py when objdump is llvm-objdump

Alex Richardson via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 27 05:17:50 PDT 2020


Author: Alex Richardson
Date: 2020-10-27T12:16:46Z
New Revision: 89031cffd1de0ce70106cda1bf5188f7a11726a2

URL: https://github.com/llvm/llvm-project/commit/89031cffd1de0ce70106cda1bf5188f7a11726a2
DIFF: https://github.com/llvm/llvm-project/commit/89031cffd1de0ce70106cda1bf5188f7a11726a2.diff

LOG: Fix sancov.py when objdump is llvm-objdump

The sanitizer-coverage.cpp test case was always failing for me. It turns
out the reason for this is that I was building with
-DLLVM_INSTALL_BINUTILS_SYMLINKS=ON and sancov.py's grep regex does not
handle llvm-objdump's disassembly format (hex immediates have a leading "0x").
While touching those lines also change them to use raw string literals since
invalid escape sequnces will become an error in future python versions.
Also simplify the code by using subprocess.check_output() instead of Popen().
This also works with python2.

Fixes https://bugs.llvm.org/show_bug.cgi?id=44504

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D89648

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/scripts/sancov.py

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/scripts/sancov.py b/compiler-rt/lib/sanitizer_common/scripts/sancov.py
index 35606396b78e..759eb0cb8bd5 100755
--- a/compiler-rt/lib/sanitizer_common/scripts/sancov.py
+++ b/compiler-rt/lib/sanitizer_common/scripts/sancov.py
@@ -193,16 +193,14 @@ def GetInstrumentedPCs(binary):
   # - __sanitizer_cov() or __sanitizer_cov_with_check(),
   # - with call or callq,
   # - directly or via PLT.
-  cmd = "objdump -d %s | " \
-        "grep '^\s\+[0-9a-f]\+:.*\scall\(q\|\)\s\+[0-9a-f]\+ <__sanitizer_cov\(_with_check\|\|_trace_pc_guard\)\(@plt\|\)>' | " \
-        "grep '^\s\+[0-9a-f]\+' -o" % binary
-  proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-                          shell=True)
-  proc.stdin.close()
+  cmd = r"objdump --no-show-raw-insn -d %s | " \
+        r"grep '^\s\+[0-9a-f]\+:\s\+call\(q\|\)\s\+\(0x\|\)[0-9a-f]\+ <__sanitizer_cov\(_with_check\|\|_trace_pc_guard\)\(@plt\|\)>' | " \
+        r"grep -o '^\s\+[0-9a-f]\+'" % binary
+  lines = subprocess.check_output(cmd, stdin=subprocess.PIPE, shell=True).splitlines()
   # The PCs we get from objdump are off by 4 bytes, as they point to the
   # beginning of the callq instruction. Empirically this is true on x86 and
   # x86_64.
-  return set(int(line.strip(), 16) + 4 for line in proc.stdout)
+  return set(int(line.strip(), 16) + 4 for line in lines)
 
 def PrintMissing(binary):
   if not os.path.isfile(binary):


        


More information about the llvm-commits mailing list