[compiler-rt] [HWASan] Fix symbol indexing (PR #135967)

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 17 17:41:25 PDT 2025


================
@@ -76,19 +82,29 @@ def handle_elf(mv):
   # have to extend the parsing code.
   if mv[:6] != b'\x7fELF\x02\x01':
     return None
+  found_symbols = False
+  bid = None
   e_shnum, = struct.unpack_from('<H', buffer=mv, offset=e_shnum_offset)
   e_shoff, = struct.unpack_from('<Q', buffer=mv, offset=e_shoff_offset)
   for i in range(0, e_shnum):
     start = e_shoff + i * Shdr_size
-    sh_offset, sh_size = handle_Shdr(mv[start: start + Shdr_size])
-    if sh_offset is None:
-      continue
-    note_hdr = mv[sh_offset: sh_offset + sh_size]
-    result = handle_Nhdr(note_hdr, sh_size)
-    if result is not None:
-      return result
+    sh = mv[start: start + Shdr_size]
+    sh_type = unpack_sh_type(sh)
+
+    if sh_type == SHT_SYMTAB:
+      found_symbols = True
+    elif sh_type == SHT_NOTE:
+      sh_offset, sh_size = handle_Shdr(sh)
+      if sh_offset is None:
+        continue
+      note_hdr = mv[sh_offset: sh_offset + sh_size]
+      result = handle_Nhdr(note_hdr, sh_size)
+      if result is not None:
+        bid = result
+
+  return (found_symbols, bid)
 
-def get_buildid(filename):
+def read_elf(filename):
   with open(filename, "r") as fd:
     if os.fstat(fd.fileno()).st_size < Ehdr_size:
       return None
----------------
fmayer wrote:

sure, i would be happy to review that

https://github.com/llvm/llvm-project/pull/135967


More information about the llvm-commits mailing list