From 0cf3c437c18ed27d9663d87804a9a15ff6874af2 Mon Sep 17 00:00:00 2001 From: Stefan Bossbaly Date: Fri, 23 May 2025 12:43:04 -0400 Subject: [PATCH] [HWASan] Improve symbol indexing (#135967) Previously we would add any ELF that contained a build id regardless whether the ELF contained symbols or not. This works for Android since soong will strip the symbols into a new directory. However other build systems, like BUCK, will write the stripped file in the same directory as the unstripped file. This would cause the hwasan_symbolize script sometimes add then stripped ELF to its index and ignore the symbolized ELF. The logic has now been changed to only add ELFs that contain symbols to the index. If two symbolized ELFs are encountered with the same build id, we now exit out with an error. Fixes #135966 --------- Co-authored-by: Stefan Bossbaly --- .../lib/hwasan/scripts/hwasan_symbolize | 88 +++++++++++++++---- 1 file changed, 72 insertions(+), 16 deletions(-) diff --git a/compiler-rt/lib/hwasan/scripts/hwasan_symbolize b/compiler-rt/lib/hwasan/scripts/hwasan_symbolize index efca6b82809b..19d948d1f0aa 100755 --- a/compiler-rt/lib/hwasan/scripts/hwasan_symbolize +++ b/compiler-rt/lib/hwasan/scripts/hwasan_symbolize @@ -16,6 +16,7 @@ from __future__ import unicode_literals import argparse import glob +import hashlib import html import json import mmap @@ -37,8 +38,9 @@ if sys.version_info.major < 3: Ehdr_size = 64 e_shnum_offset = 60 e_shoff_offset = 40 - +e_shstrndx_offset = 62 Shdr_size = 64 +sh_name_offset = 0 sh_type_offset = 4 sh_offset_offset = 24 sh_size_offset = 32 @@ -62,13 +64,32 @@ def handle_Nhdr(mv, sh_size): offset += Nhdr_size + align_up(n_namesz, 4) + align_up(n_descsz, 4) return None -def handle_Shdr(mv): +def handle_shstrtab(mv, e_shoff): + e_shstrndx, = struct.unpack_from('