commit 2a6afc8ceb4f54bc6ddf805a9482f915c15f4dee
parent 33e9e2f47ca3ed15da08672d7e956420f1773988
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 20 Jan 2025 16:05:46 +0100
libmach/elf64: Set name to the undefined section
A value of 0 means undefined section, but the elf file still has
a section in the index 0 that holds information for some cases.
As this section number 0 does not have a name is better to assign
*UND* to make explicit the meaning of this section.
Diffstat:
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/libmach/elf64/elf64getsec.c b/src/libmach/elf64/elf64getsec.c
@@ -55,7 +55,11 @@ elf64getsec(Obj *obj, int *idx, Section *sec)
* with the sh_link pointing to this section. Maybe,
* we should just remove the nrelloc field.
*/
- sec->name = elf64str(obj, SEC_STRTBL, shdr->sh_name);
+ if (n == SHN_UNDEF)
+ sec->name = "*UND*";
+ else
+ sec->name = elf64str(obj, SEC_STRTBL, shdr->sh_name);
+
sec->index = n;
sec->size = shdr->sh_size;
sec->base = shdr->sh_addr;