[asan_symbolize] Fix broken pipe handling for python 2.7

I D65322 I added a check for BrokenPipeError. However, python 2.7 doesn't
have BrokenPipeError. To be python 2.7 and 3 compatible we need to catch
IOError instead and check for errno == errno.EPIPE.

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@370025 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/scripts/asan_symbolize.py b/lib/asan/scripts/asan_symbolize.py
index cade927..a196c07 100755
--- a/lib/asan/scripts/asan_symbolize.py
+++ b/lib/asan/scripts/asan_symbolize.py
@@ -21,6 +21,7 @@
 """
 import argparse
 import bisect
+import errno
 import getopt
 import logging
 import os
@@ -202,9 +203,14 @@
           logging.debug("got empty function and file name -> unknown function")
           function_name = '??'
           file_name = '??:0'
-        lines.append((function_name, file_name));
-    except BrokenPipeError:
-      logging.debug("got broken pipe, addr2line returncode=%d" % self.pipe.poll())
+        lines.append((function_name, file_name))
+    except IOError as e:
+      # EPIPE happens if addr2line exits early (which some implementations do
+      # if an invalid file is passed).
+      if e.errno == errno.EPIPE:
+        logging.debug("addr2line exited early (broken pipe), returncode=%d" % self.pipe.poll())
+      else:
+        logging.debug("unexpected I/O exception communicating with addr2line", exc_info=e)
       lines.append(('??', '??:0'))
     except Exception as e:
       logging.debug("got unknown exception communicating with addr2line", exc_info=e)