From: Stephen Brennan <stephen.s.brennan@oracle.com>
To: Alan Maguire <alan.maguire@oracle.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org
Subject: Re: [PATCH dwarves 1/4] dutil: return ELF section name when looked up by index
Date: Fri, 13 Sep 2024 10:06:55 -0700 [thread overview]
Message-ID: <87ttejmqj4.fsf@oracle.com> (raw)
In-Reply-To: <004e691b-440d-4594-bdd8-cfc0cae90e2b@oracle.com>
Alan Maguire <alan.maguire@oracle.com> writes:
> On 12/09/2024 20:08, Stephen Brennan wrote:
>
> nit; needs a commit message, e.g. ELF section names will be used in
> DATASEC encoding; as well as getting the section, optionally retrieve
> the name.
>
>> Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
>
> I think one small thing needs fixing below, but
>
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
>> ---
>> dutil.c | 9 ++++++++-
>> dutil.h | 2 +-
>> 2 files changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/dutil.c b/dutil.c
>> index 97c4474..4e83d59 100644
>> --- a/dutil.c
>> +++ b/dutil.c
>> @@ -207,13 +207,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) {
>
> nit; before we were directly returning sec, so if it was NULL that was
> for the caller to deal with; now though we're driving on assuming it was
> non-NULL here. So I'd suggest changing the above to be something like
>
> sec = elf_getscn(elf, idx);
> if (!sec)
> return NULL;
> if (!gelf_getshhdr(sec, shp))
> return NULL;
> if (name_out) {
>
D'oh! You're exactly right. Thanks!
>> + 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 */
next prev parent reply other threads:[~2024-09-13 17:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-12 19:08 [PATCH dwarves 0/4] Emit global variables in BTF Stephen Brennan
2024-09-12 19:08 ` [PATCH dwarves 1/4] dutil: return ELF section name when looked up by index Stephen Brennan
2024-09-13 13:26 ` Alan Maguire
2024-09-13 17:06 ` Stephen Brennan [this message]
2024-09-12 19:08 ` [PATCH dwarves 2/4] dwarf_loader: add "artificial" and "top_level" variable flags Stephen Brennan
2024-09-13 13:35 ` Alan Maguire
2024-09-13 17:16 ` Stephen Brennan
2024-09-12 19:08 ` [PATCH dwarves 3/4] btf_encoder: cache all ELF section info Stephen Brennan
2024-09-13 15:25 ` Alan Maguire
2024-09-13 17:05 ` Stephen Brennan
2024-09-15 11:26 ` Alan Maguire
2024-09-12 19:08 ` [PATCH dwarves 4/4] btf_encoder: add global_var feature to encode globals Stephen Brennan
2024-09-15 11:49 ` Alan Maguire
2024-09-20 8:18 ` 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=87ttejmqj4.fsf@oracle.com \
--to=stephen.s.brennan@oracle.com \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=dwarves@vger.kernel.org \
--cc=linux-debuggers@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.