As stated in the question, is it possible to create a structure within a function, and then return that structure when the function exits? Since the structure is not created until the function is called, I don't know what to put in the prototype for the return value. Any advice/help would be great, thanks.
static void section_to_segment_map(Elf *elf, GElf_Ehdr *ehdr) {
struct memory_data {
int phdr_addrs[ehdr->e_phnum][2];
int section_bounds[ehdr->e_shnum][2];
} memData;
for(int phead_cnt = 0; phead_cnt < ehdr->e_phnum; phead_cnt++) {
GElf_Phdr mem;
GElf_Phdr *phdr = gelf_getphdr(elf, phead_cnt, &mem);
memData.phdr_addrs[phead_cnt][1] = phdr->p_vaddr;
memData.phdr_addrs[phead_cnt][2] = phdr->p_vaddr + phdr->p_memsz;
}
printf("Starting and Ending Address Values for Program Segments:\n");
for(int i = 0; i < ehdr->e_phnum; i++)
printf("%x --> %x\n", memData.phdr_addrs[i][1], memData.phdr_addrs[i][2]);
Elf_Scn *scn = NULL;
for(int shead_cnt = 0; shead_cnt < ehdr->e_shnum; shead_cnt++) {
scn = elf_getscn(elf, shead_cnt);
GElf_Shdr shdr_mem;
GElf_Shdr *shdr = gelf_getshdr(scn, &shdr_mem);
memData.section_bounds[shead_cnt][1] = shdr->sh_addr;
memData.section_bounds[shead_cnt][2] = shdr->sh_addr + shdr->sh_size;
}
printf("\n");
printf("Starting and Ending Addresses for Program Sections:\n");
for(int j = 0; j < ehdr->e_shnum; j++)
printf("%x --> %x\n", memData.section_bounds[j][1], memData.section_bounds[j][2]);
return memData;
}