Ops, 3k x 3k = 9M, not 3M ________________________________ From: gem5-dev <[email protected]> on behalf of Giacomo Travaglini <[email protected]> Sent: 17 October 2019 14:52 To: [email protected] <[email protected]>; Gabe Black <[email protected]> Subject: [gem5-dev] Elf loading problem
Hi Gabe, I am sending this email since I am having some elf loading problems after the patch you recently merged: https://gem5-review.googlesource.com/c/public/gem5/+/21467 I have an elf binary whose load takes a lot of time (I have set a timeout, so I can say it takes at least 30 seconds) I have debugged it and apparently we now spend a lot of time looping here. // Name segments after the sections they contain. Elf_Scn *section = elf_getscn(elf, 1); for (int sec_idx = 1; section; section = elf_getscn(elf, ++sec_idx)) { GElf_Shdr shdr; gelf_getshdr(section, &shdr); char *sec_name = elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name); if (!sec_name) { Elf_Error errorNum = (Elf_Error)elf_errno(); if (errorNum != ELF_E_NONE) { const char *errorMessage = elf_errmsg(errorNum); fatal("Error from libelf: %s.\n", errorMessage); } } if (shdr.sh_addr >= mem_start && shdr.sh_addr < mem_end) { if (name != "") name += ","; name += sec_name; } } This code loops for EVERY section in the elf, and it does that for EVERY segment. Consider that the specific example binary I have (there are more) has ~3k sections and ~3k headers, so the loader iterates 3 million times. Machine: AArch64 Version: 0x1 Entry point address: 0x0 Start of program headers: 1613144 (bytes into file) Start of section headers: 1774928 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 2889 Size of section headers: 64 (bytes) Number of section headers: 2907 Section header string table index: 2905 I think this is not necessary. We should loop over sections once, annotate their address, and then start the handleLoadableSegment. I am not an elf expert, but I think part of the problems comes with the fact that we are not able to extract from the elf which sections a segment contains without looping over the entire section table. I am also wondering if it is really needed that we do all of this. As far as I can see we just do that to name the segment after the sections it contains. Is there a reason for it other than maybe debugging? Previous version of the code was avoiding it (it was doing it wrong, and this is why we never encountered that problem maybe) Please let me know your thoughts Giacomo IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. _______________________________________________ gem5-dev mailing list [email protected] http://m5sim.org/mailman/listinfo/gem5-dev IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. _______________________________________________ gem5-dev mailing list [email protected] http://m5sim.org/mailman/listinfo/gem5-dev
