elf_symtab: Handle SHN_XINDEX index in elf_section_by_name()
Use elf_getshdrstrndx() to cover the case where the ELF header 'e_shstrndx' field contains the special value SHN_XINDEX so that we get the proper string table index. This is necessary to handle files with over 65536 sections, such as when building the kernel with -f[function|data]-sections. Other cases may include when using FG-ASLR, LTO. With so many sections, ELF is using extended section index table, which is used to hold values for some of the indexes and extra code is needed to retrieve them. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Hao Luo <haoluo@google.com> Cc: Joe Lawrence <joe.lawrence@redhat.com> Cc: John Fastabend <john.fastabend@gmail.com> Cc: KP Singh <kpsingh@chromium.org> Cc: Mark Wieelard <mjw@redhat.com> Cc: Martin KaFai Lau <kafai@fb.com> Cc: Song Liu <songliubraving@fb.com> Cc: Yonghong Song <yhs@fb.com> Cc: bpf@vger.kernel.org Cc: dwarves@vger.kernel.org Cc: netdev@vger.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
e32b9800e6
commit
3f8aad340b
8
dutil.c
8
dutil.c
|
@ -179,12 +179,18 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
|
|||
{
|
||||
Elf_Scn *sec = NULL;
|
||||
size_t cnt = 1;
|
||||
size_t str_idx;
|
||||
|
||||
if (elf_getshdrstrndx(elf, &str_idx))
|
||||
return NULL;
|
||||
|
||||
while ((sec = elf_nextscn(elf, sec)) != NULL) {
|
||||
char *str;
|
||||
|
||||
gelf_getshdr(sec, shp);
|
||||
str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
|
||||
str = elf_strptr(elf, str_idx, shp->sh_name);
|
||||
if (!str)
|
||||
return NULL;
|
||||
if (!strcmp(name, str)) {
|
||||
if (index)
|
||||
*index = cnt;
|
||||
|
|
Loading…
Reference in New Issue