Merge pull request #536 from PaulGrandperrin/master

Makefile: allow using BUILD_DIR for outputs
diff --git a/linux/bfd.c b/linux/bfd.c
index 1ad3ec3..b18c8bb 100644
--- a/linux/bfd.c
+++ b/linux/bfd.c
@@ -58,15 +58,6 @@
     asymbol** dsyms;
 } bfd_t;
 
-/* INFO: binutils (libbfd, libopcode) has an unstable public interface. */
-/*
- * This is probably the only define which was added with binutils 2.29, so we use
- * it, do decide which disassembler() prototype from dis-asm.h to use.
- */
-#if defined(FOR_EACH_DISASSEMBLER_OPTION)
-#define _HF_BFD_GE_2_29
-#endif /* defined(FOR_EACH_DISASSEMBLER_OPTION) */
-
 static pthread_mutex_t arch_bfd_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static bool arch_bfdInit(pid_t pid, bfd_t* bfdParams) {
@@ -834,9 +825,9 @@
         }
 
         uint8_t* buf = util_Malloc(sz);
-	defer {
-		free(buf);
-	};
+        defer {
+            free(buf);
+        };
         if (!bfd_get_section_contents(bfdh, sec, buf, 0, sz)) {
             LOG_W("bfd_get_section_contents('%s') failed", name);
             continue;
diff --git a/linux/pt.c b/linux/pt.c
index dc7a94a..1d7b410 100644
--- a/linux/pt.c
+++ b/linux/pt.c
@@ -30,6 +30,7 @@
 #include "libhfcommon/common.h"
 #include "libhfcommon/log.h"
 #include "libhfcommon/util.h"
+#include "linux/perf.h"
 
 #ifdef _HF_LINUX_INTEL_PT_LIB
 
diff --git a/sanitizers.c b/sanitizers.c
index 58efeb8..a3cc7e1 100644
--- a/sanitizers.c
+++ b/sanitizers.c
@@ -173,13 +173,30 @@
                 break;
             }
             headerFound = true;
-            sscanf(lineptr,
+
+            /* Extract the error description */
+            sscanf(lineptr, "==%*d==ERROR: %" HF_XSTR(HF_STR_LEN_MINUS_1) "[^\n]", description);
+
+            /* Extract the crash address and PC. First try the standard "on address" format
+             */
+            int mathchCount = sscanf(lineptr,
                 "==%*d==ERROR: %*[^:]: %*[^ ] on address 0x%" PRIx64 " at pc 0x%" PRIx64, crashAddr,
                 pc);
-            sscanf(lineptr,
-                "==%*d==ERROR: %*[^:]: %*[^ ] on %*s address 0x%" PRIx64 " (pc 0x%" PRIx64,
-                crashAddr, pc);
-            sscanf(lineptr, "==%*d==ERROR: %" HF_XSTR(HF_STR_LEN_MINUS_1) "[^\n]", description);
+
+            if (mathchCount != 2) {
+                /* If we cannot match report headers with "on address", try the format with a descriptor before "address" */
+                char addressDetail[HF_STR_LEN] = {0};
+                if (sscanf(lineptr,
+                        "==%*d==ERROR: %*[^:]: %*[^ ] on %" HF_XSTR(
+                            HF_STR_LEN_MINUS_1) "s address 0x%" PRIx64 " (pc 0x%" PRIx64,
+                        addressDetail, crashAddr, pc) == 3) {
+                    /* If the address descriptor is "unknown", set crashAddr to 0 as this would
+                     * break error deduplication*/
+                    if (strncmp(addressDetail, "unknown", 7) == 0) {
+                        *crashAddr = 0;
+                    }
+                }
+            }
         } else {
             char* pLineLC = lineptr;
             /* Trim leading spaces */