Skip to content

Commit 0f20c48

Browse files
committed
Reflection: prevent address truncation on ELF64
Ensure that we use the address type as specified by ELF rather than truncate to a 32-bit value.
1 parent 1a949ea commit 0f20c48

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/swift/Reflection/ReflectionContext.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ template <> struct ELFTraits<llvm::ELF::ELFCLASS32> {
6060
using Section = const struct llvm::ELF::Elf32_Shdr;
6161
using Offset = llvm::ELF::Elf32_Off;
6262
using Size = llvm::ELF::Elf32_Word;
63+
using Address = llvm::ELF::Elf32_Addr;
6364
static constexpr unsigned char ELFClass = llvm::ELF::ELFCLASS32;
6465
};
6566

@@ -68,6 +69,7 @@ template <> struct ELFTraits<llvm::ELF::ELFCLASS64> {
6869
using Section = const struct llvm::ELF::Elf64_Shdr;
6970
using Offset = llvm::ELF::Elf64_Off;
7071
using Size = llvm::ELF::Elf64_Xword;
72+
using Address = llvm::ELF::Elf64_Addr;
7173
static constexpr unsigned char ELFClass = llvm::ELF::ELFCLASS64;
7274
};
7375

@@ -330,7 +332,7 @@ class ReflectionContext
330332
auto StrTab = reinterpret_cast<const char *>(StrTabBuf.get());
331333

332334
auto findELFSectionByName = [&](std::string Name)
333-
-> std::pair<std::pair<const char *, const char *>, uint32_t> {
335+
-> std::pair<std::pair<const char *, const char *>, typename T::Address> {
334336
// Now for all the sections, find their name.
335337
for (const typename T::Section *Hdr : SecHdrVec) {
336338
uint32_t Offset = Hdr->sh_name;

0 commit comments

Comments
 (0)