Skip to content

[RemoteInspection] Handle special case of large amount of ELF sections. #83582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions include/swift/RemoteInspection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,26 @@ class ReflectionContext

if (sizeof(typename T::Section) > SectionEntrySize)
return {};

// Special handling for large amount of sections.
// From the elf man page, describing e_shnum:
//
// If the number of entries in the section header table is
// larger than or equal to SHN_LORESERVE (0xff00), e_shnum
// holds the value zero and the real number of entries in the
// section header table is held in the sh_size member of the
// initial entry in section header table. Otherwise, the
// sh_size member of the initial entry in the section header
// table holds the value zero.
if (SectionHdrNumEntries == 0 && SectionEntrySize > 0) {
auto SecBuf = readData(SectionHdrAddress, sizeof(typename T::Section));
if (!SecBuf)
return {};
const typename T::Section *FirstSectHdr =
reinterpret_cast<const typename T::Section *>(SecBuf);
SectionHdrNumEntries = FirstSectHdr->sh_size;
}

if (SectionHdrNumEntries == 0)
return {};

Expand Down