Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 9f4261c

Browse files
committed
[cfi] Fix symbol lookup hack in cross-dso cfi to handle LLD binaries.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299604 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent bd4e3b4 commit 9f4261c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/cfi/cfi.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,14 @@ uptr find_cfi_check_in_dso(dl_phdr_info *info) {
188188
}
189189
}
190190
if (!dynamic) return 0;
191-
uptr strtab = 0, symtab = 0;
191+
uptr strtab = 0, symtab = 0, strsz = 0;
192192
for (const ElfW(Dyn) *p = dynamic; p->d_tag != PT_NULL; ++p) {
193193
if (p->d_tag == DT_SYMTAB)
194194
symtab = p->d_un.d_ptr;
195195
else if (p->d_tag == DT_STRTAB)
196196
strtab = p->d_un.d_ptr;
197+
else if (p->d_tag == DT_STRSZ)
198+
strsz = p->d_un.d_ptr;
197199
}
198200

199201
if (symtab > strtab) {
@@ -209,7 +211,8 @@ uptr find_cfi_check_in_dso(dl_phdr_info *info) {
209211
if (phdr->p_type == PT_LOAD) {
210212
uptr beg = info->dlpi_addr + phdr->p_vaddr;
211213
uptr end = beg + phdr->p_memsz;
212-
if (strtab >= beg && strtab < end && symtab >= beg && symtab < end)
214+
if (strtab >= beg && strtab + strsz < end && symtab >= beg &&
215+
symtab < end)
213216
break;
214217
}
215218
}
@@ -222,6 +225,10 @@ uptr find_cfi_check_in_dso(dl_phdr_info *info) {
222225

223226
for (const ElfW(Sym) *p = (const ElfW(Sym) *)symtab; (ElfW(Addr))p < strtab;
224227
++p) {
228+
// There is no reliable way to find the end of the symbol table. In
229+
// lld-produces files, there are other sections between symtab and strtab.
230+
// Stop looking when the symbol name is not inside strtab.
231+
if (p->st_name >= strsz) break;
225232
char *name = (char*)(strtab + p->st_name);
226233
if (strcmp(name, "__cfi_check") == 0) {
227234
assert(p->st_info == ELF32_ST_INFO(STB_GLOBAL, STT_FUNC));

0 commit comments

Comments
 (0)