From: Stephen Brennan <stephen.s.brennan@oracle.com>
To: Stephen Brennan <stephen.s.brennan@oracle.com>
Cc: dwarves@vger.kernel.org, bpf@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
alan.maguire@oracle.com, Andrii Nakryiko <andrii@kernel.org>
Subject: [PATCH v2 dwarves 1/9] dutil: return ELF section name when looked up by index
Date: Fri, 4 Nov 2022 16:10:55 -0700 [thread overview]
Message-ID: <20221104231103.752040-2-stephen.s.brennan@oracle.com> (raw)
In-Reply-To: <20221104231103.752040-1-stephen.s.brennan@oracle.com>
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
---
dutil.c | 10 +++++++++-
dutil.h | 2 +-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/dutil.c b/dutil.c
index 97c4474..a4d55e6 100644
--- a/dutil.c
+++ b/dutil.c
@@ -2,6 +2,7 @@
SPDX-License-Identifier: GPL-2.0-only
Copyright (C) 2007 Arnaldo Carvalho de Melo <acme@redhat.com>
+ Copyright (c) 2022, Oracle and/or its affiliates.
*/
@@ -207,13 +208,20 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Shdr *shp, const char *name, size_t
return sec;
}
-Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx)
+Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx, const char **name_out)
{
Elf_Scn *sec;
+ size_t str_idx;
sec = elf_getscn(elf, idx);
if (sec)
gelf_getshdr(sec, shp);
+
+ if (name_out) {
+ if (elf_getshdrstrndx(elf, &str_idx))
+ return NULL;
+ *name_out = elf_strptr(elf, str_idx, shp->sh_name);
+ }
return sec;
}
diff --git a/dutil.h b/dutil.h
index 335a17c..ff78aa6 100644
--- a/dutil.h
+++ b/dutil.h
@@ -328,7 +328,7 @@ void *zalloc(const size_t size);
Elf_Scn *elf_section_by_name(Elf *elf, GElf_Shdr *shp, const char *name, size_t *index);
-Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx);
+Elf_Scn *elf_section_by_idx(Elf *elf, GElf_Shdr *shp, int idx, const char **name_out);
#ifndef SHT_GNU_ATTRIBUTES
/* Just a way to check if we're using an old elfutils version */
--
2.31.1
next prev parent reply other threads:[~2022-11-04 23:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-04 23:10 [PATCH v2 dwarves, kernel, libbpf 0/9] Add support for generating BTF for all variables Stephen Brennan
2022-11-04 23:10 ` Stephen Brennan [this message]
2022-11-04 23:10 ` [PATCH v2 dwarves 2/9] btf_encoder: Rename percpu structures to variables Stephen Brennan
2022-11-04 23:10 ` [PATCH v2 dwarves 3/9] btf_encoder: cache all ELF section info Stephen Brennan
2022-11-04 23:10 ` [PATCH v2 dwarves 4/9] btf_encoder: make the variable array dynamic Stephen Brennan
2022-11-04 23:10 ` [PATCH v2 dwarves 5/9] btf_encoder: record ELF section for collected variables Stephen Brennan
2022-11-04 23:11 ` [PATCH v2 dwarves 6/9] btf_encoder: collect all variables Stephen Brennan
2022-11-04 23:11 ` [PATCH v2 dwarves 7/9] btf_encoder: allow encoding " Stephen Brennan
2022-11-04 23:11 ` [PATCH v2 bpf 8/9] libbpf: btf dedup identical struct test needs check for nested structs/arrays Stephen Brennan
2022-11-04 23:11 ` [PATCH v2 kernel 9/9] bpf: add support for CONFIG_DEBUG_INFO_BTF_VARS Stephen Brennan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221104231103.752040-2-stephen.s.brennan@oracle.com \
--to=stephen.s.brennan@oracle.com \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).