public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: linux-kernel@vger.kernel.org,  srikar@linux.vnet.ibm.com,
	 peterz@infradead.org,  oleg@redhat.com,
	 hegdevasant@linux.vnet.ibm.com,  mingo@redhat.com,
	 anton@redhat.com,  systemtap@sourceware.org,
	 masami.hiramatsu.pt@hitachi.com,  aravinda@linux.vnet.ibm.com,
	 penberg@iki.fi
Subject: Re: [PATCH v3 1/5] perf/sdt: ELF support for SDT
Date: Wed, 22 Oct 2014 02:39:00 -0000	[thread overview]
Message-ID: <87a94og74b.fsf@sejong.aot.lge.com> (raw)
In-Reply-To: <20141010105727.15506.99362.stgit@hemant-fedora> (Hemant Kumar's	message of "Fri, 10 Oct 2014 16:27:53 +0530")

Hi Hemant,

On Fri, 10 Oct 2014 16:27:53 +0530, Hemant Kumar wrote:
> This patch serves the initial support to identify and list SDT events in binaries.
> When programs containing SDT markers are compiled, gcc with the help of assembler
> directives identifies them and places them in the section ".note.stapsdt". To find
> these markers from the binaries, one needs to traverse through this section and
> parse the relevant details like the name, type and location of the marker. Also,
> the original location could be skewed due to the effect of prelinking. If that is
> the case, the locations need to be adjusted.
>
> The functions in this patch open a given ELF, find out the SDT section, parse the
> relevant details, adjust the location (if necessary) and populate them in a list.
>
> Signed-off-by: Hemant Kumar <hemant@linux.vnet.ibm.com>

Acked-by: Namhyung Kim <namhyung@kernel.org>

Just a nitpick below..


> +static int construct_sdt_notes_list(Elf *elf, struct list_head *sdt_notes)
> +{
> +	GElf_Ehdr ehdr;
> +	Elf_Scn *scn = NULL;
> +	Elf_Data *data;
> +	GElf_Shdr shdr;
> +	size_t shstrndx, next;
> +	GElf_Nhdr nhdr;
> +	size_t name_off, desc_off, offset;
> +	int ret = 0;
> +
> +	if (gelf_getehdr(elf, &ehdr) == NULL) {
> +		ret = -EBADF;
> +		goto out_ret;
> +	}
> +	if (elf_getshdrstrndx(elf, &shstrndx) != 0) {
> +		ret = -EBADF;
> +		goto out_ret;
> +	}
> +
> +	/* Look for the required section */
> +	scn = elf_section_by_name(elf, &ehdr, &shdr, SDT_NOTE_SCN, NULL);
> +	if (!scn) {
> +		ret = -ENOENT;
> +		goto out_ret;
> +	}
> +
> +	if (!(shdr.sh_type == SHT_NOTE) || (shdr.sh_flags & SHF_ALLOC)) {

I think the below is more readable:

	if ((shdr.sh_type != SHT_NOTE) || (shdr.sh_flags & SHF_ALLOC)) {

Other than that, looks good to me!

Thanks,
Namhyung


> +		ret = -ENOENT;
> +		goto out_ret;
> +	}
> +
> +	data = elf_getdata(scn, NULL);
> +
> +	/* Get the SDT notes */
> +	for (offset = 0; (next = gelf_getnote(data, offset, &nhdr, &name_off,
> +					      &desc_off)) > 0; offset = next) {
> +		if (nhdr.n_namesz == sizeof(SDT_NOTE_NAME) &&
> +		    !memcmp(data->d_buf + name_off, SDT_NOTE_NAME,
> +			    sizeof(SDT_NOTE_NAME))) {
> +			ret = populate_sdt_note(&elf, ((data->d_buf) + desc_off),
> +						nhdr.n_descsz, nhdr.n_type,
> +						sdt_notes);
> +			if (ret < 0)
> +				goto out_ret;
> +		}
> +	}
> +	if (list_empty(sdt_notes))
> +		ret = -ENOENT;
> +
> +out_ret:
> +	return ret;
> +}

  reply	other threads:[~2014-10-22  2:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-10 10:58 [PATCH v3 0/5] perf/sdt: SDT events listing/probing Hemant Kumar
2014-10-10 10:58 ` [PATCH v3 1/5] perf/sdt: ELF support for SDT Hemant Kumar
2014-10-22  2:39   ` Namhyung Kim [this message]
2014-10-22 10:26     ` Hemant Kumar
2014-10-10 10:59 ` [PATCH v3 4/5] perf/sdt: Delete SDT events from cache Hemant Kumar
2014-10-10 10:59 ` [PATCH v3 3/5] perf/sdt: Show SDT cache contents Hemant Kumar
2014-10-22  4:48   ` Namhyung Kim
2014-10-10 10:59 ` [PATCH v3 2/5] perf/sdt: Add SDT events into a cache Hemant Kumar
2014-10-22  4:41   ` Namhyung Kim
2014-10-24 11:28     ` Hemant Kumar
2014-10-23 11:51   ` Masami Hiramatsu
2014-10-10 11:00 ` [PATCH v3 5/5] perf/sdt: Add support to perf record to trace SDT events Hemant Kumar
2014-10-22  6:45   ` Masami Hiramatsu
2014-10-22  8:20     ` Hemant Kumar
2014-10-22  9:42       ` Masami Hiramatsu
2014-10-23  5:31         ` Hemant Kumar
2014-10-23  5:54         ` Srikar Dronamraju
2014-10-23  6:33           ` Masami Hiramatsu
2014-10-23  8:21             ` Namhyung Kim
2014-10-23  8:57               ` Masami Hiramatsu

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=87a94og74b.fsf@sejong.aot.lge.com \
    --to=namhyung@kernel.org \
    --cc=anton@redhat.com \
    --cc=aravinda@linux.vnet.ibm.com \
    --cc=hegdevasant@linux.vnet.ibm.com \
    --cc=hemant@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=penberg@iki.fi \
    --cc=peterz@infradead.org \
    --cc=srikar@linux.vnet.ibm.com \
    --cc=systemtap@sourceware.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).