Skip to content
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
32 changes: 16 additions & 16 deletions include/swift/RemoteInspection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ template <> struct MachOTraits<8> {
template <unsigned char ELFClass> struct ELFTraits;

template <> struct ELFTraits<llvm::ELF::ELFCLASS32> {
using Header = const struct llvm::ELF::Elf32_Ehdr;
using Section = const struct llvm::ELF::Elf32_Shdr;
using ELFHeader = const struct llvm::ELF::Elf32_Ehdr;
using SectionHeader = const struct llvm::ELF::Elf32_Shdr;
using Offset = llvm::ELF::Elf32_Off;
using Size = llvm::ELF::Elf32_Word;
static constexpr unsigned char ELFClass = llvm::ELF::ELFCLASS32;
};

template <> struct ELFTraits<llvm::ELF::ELFCLASS64> {
using Header = const struct llvm::ELF::Elf64_Ehdr;
using Section = const struct llvm::ELF::Elf64_Shdr;
using ELFHeader = const struct llvm::ELF::Elf64_Ehdr;
using SectionHeader = const struct llvm::ELF::Elf64_Shdr;
using Offset = llvm::ELF::Elf64_Off;
using Size = llvm::ELF::Elf64_Xword;
static constexpr unsigned char ELFClass = llvm::ELF::ELFCLASS64;
Expand Down Expand Up @@ -552,18 +552,18 @@ class ReflectionContext
}
};

const void *Buf = readData(0, sizeof(typename T::Header));
const void *Buf = readData(0, sizeof(typename T::ELFHeader));
if (!Buf)
return {};
auto Hdr = reinterpret_cast<const typename T::Header *>(Buf);
auto Hdr = reinterpret_cast<const typename T::ELFHeader *>(Buf);
assert(Hdr->getFileClass() == T::ELFClass && "invalid ELF file class");

// From the header, grab information about the section header table.
uint64_t SectionHdrAddress = Hdr->e_shoff;
uint16_t SectionHdrNumEntries = Hdr->e_shnum;
uint16_t SectionEntrySize = Hdr->e_shentsize;

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

// Special handling for large amount of sections.
Expand All @@ -577,11 +577,11 @@ class ReflectionContext
// 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));
auto SecBuf = readData(SectionHdrAddress, sizeof(typename T::SectionHeader));
if (!SecBuf)
return {};
const typename T::Section *FirstSectHdr =
reinterpret_cast<const typename T::Section *>(SecBuf);
const typename T::SectionHeader *FirstSectHdr =
reinterpret_cast<const typename T::SectionHeader *>(SecBuf);
SectionHdrNumEntries = FirstSectHdr->sh_size;
}

Expand All @@ -592,14 +592,14 @@ class ReflectionContext
// reflection sections (by name) and the string table.
// We read the section headers from the FileBuffer, since they are
// not mapped in the child process.
std::vector<const typename T::Section *> SecHdrVec;
std::vector<const typename T::SectionHeader *> SecHdrVec;
for (unsigned I = 0; I < SectionHdrNumEntries; ++I) {
uint64_t Offset = SectionHdrAddress + (I * SectionEntrySize);
auto SecBuf = readData(Offset, sizeof(typename T::Section));
auto SecBuf = readData(Offset, sizeof(typename T::SectionHeader));
if (!SecBuf)
return {};
const typename T::Section *SecHdr =
reinterpret_cast<const typename T::Section *>(SecBuf);
const typename T::SectionHeader *SecHdr =
reinterpret_cast<const typename T::SectionHeader *>(SecBuf);

SecHdrVec.push_back(SecHdr);
}
Expand All @@ -615,7 +615,7 @@ class ReflectionContext

assert(SecIdx < SecHdrVec.size() && "malformed ELF object");

const typename T::Section *SecHdrStrTab = SecHdrVec[SecIdx];
const typename T::SectionHeader *SecHdrStrTab = SecHdrVec[SecIdx];
typename T::Offset StrTabOffset = SecHdrStrTab->sh_offset;
typename T::Size StrTabSize = SecHdrStrTab->sh_size;

Expand Down Expand Up @@ -652,7 +652,7 @@ class ReflectionContext
if (Error)
return {nullptr, 0};
// Now for all the sections, find their name.
for (const typename T::Section *Hdr : SecHdrVec) {
for (const typename T::SectionHeader *Hdr : SecHdrVec) {
// Skip unused headers
if (Hdr->sh_type == llvm::ELF::SHT_NULL)
continue;
Expand Down