Skip to content

Commit 77db003

Browse files
authored
Merge pull request #83582 from augusto2112/fix-elf-shnum
[RemoteInspection] Handle special case of large amount of ELF sections.
2 parents eb23d3b + e9cb50e commit 77db003

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

include/swift/RemoteInspection/ReflectionContext.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,26 @@ class ReflectionContext
565565

566566
if (sizeof(typename T::Section) > SectionEntrySize)
567567
return {};
568+
569+
// Special handling for large amount of sections.
570+
// From the elf man page, describing e_shnum:
571+
//
572+
// If the number of entries in the section header table is
573+
// larger than or equal to SHN_LORESERVE (0xff00), e_shnum
574+
// holds the value zero and the real number of entries in the
575+
// section header table is held in the sh_size member of the
576+
// initial entry in section header table. Otherwise, the
577+
// sh_size member of the initial entry in the section header
578+
// table holds the value zero.
579+
if (SectionHdrNumEntries == 0 && SectionEntrySize > 0) {
580+
auto SecBuf = readData(SectionHdrAddress, sizeof(typename T::Section));
581+
if (!SecBuf)
582+
return {};
583+
const typename T::Section *FirstSectHdr =
584+
reinterpret_cast<const typename T::Section *>(SecBuf);
585+
SectionHdrNumEntries = FirstSectHdr->sh_size;
586+
}
587+
568588
if (SectionHdrNumEntries == 0)
569589
return {};
570590

0 commit comments

Comments
 (0)