@@ -50,8 +50,6 @@ extern bool option_debug;
5050 } \
5151 while (false )
5252
53- typedef std::map<intptr_t , intptr_t > RelaInfo;
54-
5553/*
5654 * Insert target information.
5755 */
@@ -251,7 +249,7 @@ static void CFGCodeAnalysis(const ELF *elf, bool pic, const Instr *Is,
251249 * Section analysis pass: find potential code pointers in data.
252250 */
253251static void CFGSectionAnalysis (const ELF *elf, bool pic, const char *name,
254- const Elf64_Shdr *shdr, const Instr *Is, size_t size, const RelaInfo relas,
252+ const Elf64_Shdr *shdr, const Instr *Is, size_t size,
255253 const std::set<intptr_t > &tables, Targets &targets)
256254{
257255 if ((shdr->sh_flags & SHF_EXECINSTR) != 0 || shdr->sh_addr == 0x0 )
@@ -262,8 +260,13 @@ static void CFGSectionAnalysis(const ELF *elf, bool pic, const char *name,
262260
263261 if (!pic)
264262 {
265- if (shdr->sh_type != SHT_PROGBITS)
266- return ;
263+ switch (shdr->sh_type )
264+ {
265+ case SHT_PROGBITS: case SHT_INIT_ARRAY: case SHT_FINI_ARRAY:
266+ break ;
267+ default :
268+ return ;
269+ }
267270
268271 // Scan the data for absolute addresses.
269272 auto bounds = getBounds<intptr_t >(sh_data, sh_data + sh_size);
@@ -317,26 +320,6 @@ static void CFGSectionAnalysis(const ELF *elf, bool pic, const char *name,
317320 }
318321 }
319322 }
320-
321- if (pic && shdr->sh_type == SHT_PROGBITS)
322- {
323- // Scan for code pointers using relocation information.
324- auto bounds = getBounds<int64_t >(sh_data, sh_data + sh_size);
325- for (const int64_t *p = bounds.first ; p < bounds.second ; p++)
326- {
327- intptr_t offset = (intptr_t )shdr->sh_addr +
328- ((intptr_t )p - (intptr_t )sh_data);
329- auto i = relas.find (offset);
330- if (i == relas.end ())
331- continue ;
332-
333- intptr_t target = *p + i->second ;
334- if (findInstr (Is, size, target) < 0 )
335- continue ;
336- DEBUG (targets, target, " Reloc : %p (F)" , (void *)target);
337- addTarget (target, TARGET_INDIRECT | TARGET_FUNCTION, targets);
338- }
339- }
340323}
341324
342325/*
@@ -347,7 +330,6 @@ static void CFGDataAnalysis(const ELF *elf, bool pic, const Instr *Is,
347330{
348331 // Gather relocation information:
349332 const SectionInfo §ions = getELFSectionInfo (elf);
350- RelaInfo relas;
351333 for (const auto &entry: sections)
352334 {
353335 const Elf64_Shdr *shdr = entry.second ;
@@ -360,14 +342,18 @@ static void CFGDataAnalysis(const ELF *elf, bool pic, const Instr *Is,
360342 for (; rela < rela_end; rela++)
361343 {
362344 if (ELF64_R_TYPE (rela->r_info ) == R_X86_64_RELATIVE)
363- relas.insert ({rela->r_offset , rela->r_addend });
345+ {
346+ intptr_t target = (intptr_t )rela->r_addend ;
347+ DEBUG (targets, target, " Reloc : %p (F)" , (void *)target);
348+ addTarget (target, TARGET_INDIRECT | TARGET_FUNCTION, targets);
349+ }
364350 }
365351 }
366352
367353 // Analyze each data section:
368354 for (const auto &entry: sections)
369355 CFGSectionAnalysis (elf, pic, entry.first , entry.second , Is, size,
370- relas, tables, targets);
356+ tables, targets);
371357}
372358
373359/*
0 commit comments