Skip to content

Commit ef01f78

Browse files
brenns10acmel
authored andcommittedOct 1, 2024
dutil: Return ELF section name when looked up by index
Reviewed-by: Alan Maguire <[email protected]> Signed-off-by: Stephen Brennan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 135b37a commit ef01f78

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed
 

‎dutil.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,21 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Shdr *shp, const char *name, size_t
207207
return sec;
208208
}
209209

210-
Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx)
210+
Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx, const char **name_out)
211211
{
212212
Elf_Scn *sec;
213+
size_t str_idx;
213214

214215
sec = elf_getscn(elf, idx);
215-
if (sec)
216-
gelf_getshdr(sec, shp);
216+
if (!sec)
217+
return NULL;
218+
if (!gelf_getshdr(sec, shp))
219+
return NULL;
220+
if (name_out) {
221+
if (elf_getshdrstrndx(elf, &str_idx))
222+
return NULL;
223+
*name_out = elf_strptr(elf, str_idx, shp->sh_name);
224+
}
217225
return sec;
218226
}
219227

‎dutil.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void *zalloc(const size_t size);
328328

329329
Elf_Scn *elf_section_by_name(Elf *elf, GElf_Shdr *shp, const char *name, size_t *index);
330330

331-
Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx);
331+
Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx, const char **name_out);
332332

333333
#ifndef SHT_GNU_ATTRIBUTES
334334
/* Just a way to check if we're using an old elfutils version */

0 commit comments

Comments
 (0)
Please sign in to comment.