[compiler-rt] r299604 - [cfi] Fix symbol lookup hack in cross-dso cfi to handle LLD binaries.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 5 17:34:45 PDT 2017


Author: eugenis
Date: Wed Apr  5 19:34:45 2017
New Revision: 299604

URL: http://llvm.org/viewvc/llvm-project?rev=299604&view=rev
Log:
[cfi] Fix symbol lookup hack in cross-dso cfi to handle LLD binaries.

Modified:
    compiler-rt/trunk/lib/cfi/cfi.cc

Modified: compiler-rt/trunk/lib/cfi/cfi.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/cfi/cfi.cc?rev=299604&r1=299603&r2=299604&view=diff
==============================================================================
--- compiler-rt/trunk/lib/cfi/cfi.cc (original)
+++ compiler-rt/trunk/lib/cfi/cfi.cc Wed Apr  5 19:34:45 2017
@@ -188,12 +188,14 @@ uptr find_cfi_check_in_dso(dl_phdr_info
     }
   }
   if (!dynamic) return 0;
-  uptr strtab = 0, symtab = 0;
+  uptr strtab = 0, symtab = 0, strsz = 0;
   for (const ElfW(Dyn) *p = dynamic; p->d_tag != PT_NULL; ++p) {
     if (p->d_tag == DT_SYMTAB)
       symtab = p->d_un.d_ptr;
     else if (p->d_tag == DT_STRTAB)
       strtab = p->d_un.d_ptr;
+    else if (p->d_tag == DT_STRSZ)
+      strsz = p->d_un.d_ptr;
   }
 
   if (symtab > strtab) {
@@ -209,7 +211,8 @@ uptr find_cfi_check_in_dso(dl_phdr_info
     if (phdr->p_type == PT_LOAD) {
       uptr beg = info->dlpi_addr + phdr->p_vaddr;
       uptr end = beg + phdr->p_memsz;
-      if (strtab >= beg && strtab < end && symtab >= beg && symtab < end)
+      if (strtab >= beg && strtab + strsz < end && symtab >= beg &&
+          symtab < end)
         break;
     }
   }
@@ -222,6 +225,10 @@ uptr find_cfi_check_in_dso(dl_phdr_info
 
   for (const ElfW(Sym) *p = (const ElfW(Sym) *)symtab; (ElfW(Addr))p < strtab;
        ++p) {
+    // There is no reliable way to find the end of the symbol table. In
+    // lld-produces files, there are other sections between symtab and strtab.
+    // Stop looking when the symbol name is not inside strtab.
+    if (p->st_name >= strsz) break;
     char *name = (char*)(strtab + p->st_name);
     if (strcmp(name, "__cfi_check") == 0) {
       assert(p->st_info == ELF32_ST_INFO(STB_GLOBAL, STT_FUNC));




More information about the llvm-commits mailing list