1919#include < unistd.h>
2020#include < fcntl.h>
2121
22+ struct VTableFieldOffsetDataRaw
23+ {
24+ uint64_t class_name_ptr;
25+ uint64_t member_name_ptr;
26+ uint64_t offset;
27+ };
28+
2229LargeNumber::LargeNumber () : high{}, low{}, isUnsigned{}
2330{
2431
@@ -92,14 +99,14 @@ ProgramInfo process(char *image, std::size_t size)
9299 return programInfo;
93100 }
94101
95- size_t numberOfSections;
102+ size_t numberOfSections = 0 ;
96103 if (elf_getshdrnum (elf, &numberOfSections) != 0 )
97104 {
98105 programInfo.error = " Failed to get number of ELF sections. (" + std::string (elf_errmsg (-1 )) + " )" ;
99106 return programInfo;
100107 }
101108
102- size_t sectionNameStringTableIndex;
109+ size_t sectionNameStringTableIndex = 0 ;
103110 if (elf_getshdrstrndx (elf, §ionNameStringTableIndex) != 0 )
104111 {
105112 programInfo.error = " Failed to get ELF section names. (" + std::string (elf_errmsg (-1 )) + " )" ;
@@ -113,14 +120,14 @@ ProgramInfo process(char *image, std::size_t size)
113120 Elf_Scn *symbolTableScn = nullptr ;
114121
115122 size_t stringTableIndex = SHN_UNDEF ;
116- Elf_Scn *stringTableScn = nullptr ;
123+ const Elf_Scn *stringTableScn = nullptr ;
117124
118125 size_t rodataIndex = SHN_UNDEF ;
119- Elf64_Addr rodataOffset;
126+ Elf64_Addr rodataOffset = 0 ;
120127 Elf_Scn *rodataScn = nullptr ;
121128
122129 size_t relRodataIndex = SHN_UNDEF ;
123- Elf64_Addr relRodataOffset;
130+ Elf64_Addr relRodataOffset = 0 ;
124131 Elf_Scn *relRodataScn = nullptr ;
125132
126133 for (size_t elfSectionIndex = 0 ; elfSectionIndex < numberOfSections; ++elfSectionIndex)
@@ -175,6 +182,26 @@ ProgramInfo process(char *image, std::size_t size)
175182 relRodataOffset = elfSectionHeader.sh_addr ;
176183 relRodataScn = elfScn;
177184 }
185+ else if (elfSectionHeader.sh_type == SHT_PROGBITS && strcmp (name, " .member_offsets" ) == 0 )
186+ {
187+ Elf_Data* data = elf_getdata (elfScn, nullptr );
188+ if (data && data->d_size > 0 )
189+ {
190+ size_t entry_count = data->d_size / sizeof (VTableFieldOffsetDataRaw);
191+ auto entries = static_cast <const VTableFieldOffsetDataRaw*>(data->d_buf );
192+
193+ for (size_t i = 0 ; i < entry_count; ++i)
194+ {
195+ #if 0
196+ std::cout << "VTableFieldOffsetData entry " << i << ":\n";
197+ std::cout << " Class name: " << &image[entries[i].class_name_ptr] << "\n";
198+ std::cout << " Member name: " << &image[entries[i].member_name_ptr] << "\n";
199+ std::cout << " Offset: " << entries[i].offset << " (0x" << std::hex << entries[i].offset << std::dec << ")\n";
200+ #endif
201+ programInfo.vtableFieldDataEntries .emplace_back (&image[entries[i].class_name_ptr ], &image[entries[i].member_name_ptr ], entries[i].offset );
202+ }
203+ }
204+ }
178205
179206 if (relocationTableScn && dynamicSymbolTableScn && symbolTableScn && stringTableScn && rodataScn && relRodataScn)
180207 {
@@ -196,7 +223,7 @@ ProgramInfo process(char *image, std::size_t size)
196223 Elf_Data *relocationData = nullptr ;
197224 while ((relocationData = elf_getdata (relocationTableScn, relocationData)) != nullptr )
198225 {
199- size_t relocationIndex = 0 ;
226+ int relocationIndex = 0 ;
200227 GElf_Rel relocation;
201228 while (gelf_getrel (relocationData, relocationIndex++, &relocation) == &relocation)
202229 {
@@ -210,7 +237,7 @@ ProgramInfo process(char *image, std::size_t size)
210237 while ((symbolData = elf_getdata (dynamicSymbolTableScn, symbolData)) != nullptr )
211238 {
212239 GElf_Sym symbol;
213- size_t symbolIndex = GELF_R_SYM (relocation.r_info );
240+ int symbolIndex = GELF_R_SYM (relocation.r_info );
214241 if (gelf_getsym (symbolData, symbolIndex, &symbol) != &symbol)
215242 {
216243 continue ;
0 commit comments