about summary refs log tree commit diff
path: root/absl/debugging/symbolize_elf.inc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/debugging/symbolize_elf.inc')
-rw-r--r--absl/debugging/symbolize_elf.inc48
1 files changed, 19 insertions, 29 deletions
diff --git a/absl/debugging/symbolize_elf.inc b/absl/debugging/symbolize_elf.inc
index 5ac7ff5de427..e73052135c98 100644
--- a/absl/debugging/symbolize_elf.inc
+++ b/absl/debugging/symbolize_elf.inc
@@ -762,37 +762,27 @@ FindSymbolResult Symbolizer::GetSymbolFromObjectFile(
     }
   }
 
-  // Consult a regular symbol table first.
-  if (!GetSectionHeaderByType(obj.fd, obj.elf_header.e_shnum,
-                              obj.elf_header.e_shoff, SHT_SYMTAB, &symtab,
-                              tmp_buf, tmp_buf_size)) {
-    return SYMBOL_NOT_FOUND;
-  }
-  if (!ReadFromOffsetExact(
-          obj.fd, &strtab, sizeof(strtab),
-          obj.elf_header.e_shoff + symtab.sh_link * sizeof(symtab))) {
-    return SYMBOL_NOT_FOUND;
-  }
-  const FindSymbolResult rc =
-      FindSymbol(pc, obj.fd, out, out_size, relocation, &strtab, &symtab,
-                 opd_ptr, tmp_buf, tmp_buf_size);
-  if (rc != SYMBOL_NOT_FOUND) {
-    return rc;  // Found the symbol in a regular symbol table.
+  // Consult a regular symbol table, then fall back to the dynamic symbol table.
+  for (const auto symbol_table_type : {SHT_SYMTAB, SHT_DYNSYM}) {
+    if (!GetSectionHeaderByType(obj.fd, obj.elf_header.e_shnum,
+                                obj.elf_header.e_shoff, symbol_table_type,
+                                &symtab, tmp_buf, tmp_buf_size)) {
+      continue;
+    }
+    if (!ReadFromOffsetExact(
+            obj.fd, &strtab, sizeof(strtab),
+            obj.elf_header.e_shoff + symtab.sh_link * sizeof(symtab))) {
+      continue;
+    }
+    const FindSymbolResult rc =
+        FindSymbol(pc, obj.fd, out, out_size, relocation, &strtab, &symtab,
+                   opd_ptr, tmp_buf, tmp_buf_size);
+    if (rc != SYMBOL_NOT_FOUND) {
+      return rc;
+    }
   }
 
-  // If the symbol is not found, then consult a dynamic symbol table.
-  if (!GetSectionHeaderByType(obj.fd, obj.elf_header.e_shnum,
-                              obj.elf_header.e_shoff, SHT_DYNSYM, &symtab,
-                              tmp_buf, tmp_buf_size)) {
-    return SYMBOL_NOT_FOUND;
-  }
-  if (!ReadFromOffsetExact(
-          obj.fd, &strtab, sizeof(strtab),
-          obj.elf_header.e_shoff + symtab.sh_link * sizeof(symtab))) {
-    return SYMBOL_NOT_FOUND;
-  }
-  return FindSymbol(pc, obj.fd, out, out_size, relocation, &strtab, &symtab,
-                    opd_ptr, tmp_buf, tmp_buf_size);
+  return SYMBOL_NOT_FOUND;
 }
 
 namespace {