From: Jiri Olsa <jolsa@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Cc: lkml <linux-kernel@vger.kernel.org>,
netdev@vger.kernel.org, linux-kbuild@vger.kernel.org,
Quentin Monnet <quentin.monnet@netronome.com>,
Eugene Syromiatnikov <esyr@redhat.com>,
Jiri Benc <jbenc@redhat.com>,
Stanislav Kozina <skozina@redhat.com>,
Jerome Marchand <jmarchan@redhat.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Masahiro Yamada <yamada.masahiro@socionext.com>,
Michal Marek <michal.lkml@markovi.net>,
Jiri Kosina <jkosina@suse.cz>
Subject: [PATCH 1/9] perf tools: Make read_build_id function public
Date: Thu, 5 Apr 2018 17:16:37 +0200 [thread overview]
Message-ID: <20180405151645.19130-2-jolsa@kernel.org> (raw)
In-Reply-To: <20180405151645.19130-1-jolsa@kernel.org>
And renaming it into parse_notes_buildid to be more
precise and usable in following patches.
Link: http://lkml.kernel.org/n/tip-v1mz76rkdxfnbfz2v05fumn6@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/util/symbol-minimal.c | 50 ++--------------------------------------
tools/perf/util/util.c | 48 ++++++++++++++++++++++++++++++++++++++
tools/perf/util/util.h | 4 ++++
3 files changed, 54 insertions(+), 48 deletions(-)
diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-minimal.c
index ff48d0d49584..bd281d3dc508 100644
--- a/tools/perf/util/symbol-minimal.c
+++ b/tools/perf/util/symbol-minimal.c
@@ -24,53 +24,6 @@ static bool check_need_swap(int file_endian)
return host_endian != file_endian;
}
-#define NOTE_ALIGN(sz) (((sz) + 3) & ~3)
-
-#define NT_GNU_BUILD_ID 3
-
-static int read_build_id(void *note_data, size_t note_len, void *bf,
- size_t size, bool need_swap)
-{
- struct {
- u32 n_namesz;
- u32 n_descsz;
- u32 n_type;
- } *nhdr;
- void *ptr;
-
- ptr = note_data;
- while (ptr < (note_data + note_len)) {
- const char *name;
- size_t namesz, descsz;
-
- nhdr = ptr;
- if (need_swap) {
- nhdr->n_namesz = bswap_32(nhdr->n_namesz);
- nhdr->n_descsz = bswap_32(nhdr->n_descsz);
- nhdr->n_type = bswap_32(nhdr->n_type);
- }
-
- namesz = NOTE_ALIGN(nhdr->n_namesz);
- descsz = NOTE_ALIGN(nhdr->n_descsz);
-
- ptr += sizeof(*nhdr);
- name = ptr;
- ptr += namesz;
- if (nhdr->n_type == NT_GNU_BUILD_ID &&
- nhdr->n_namesz == sizeof("GNU")) {
- if (memcmp(name, "GNU", sizeof("GNU")) == 0) {
- size_t sz = min(size, descsz);
- memcpy(bf, ptr, sz);
- memset(bf + sz, 0, size - sz);
- return 0;
- }
- }
- ptr += descsz;
- }
-
- return -1;
-}
-
int filename__read_debuglink(const char *filename __maybe_unused,
char *debuglink __maybe_unused,
size_t size __maybe_unused)
@@ -153,7 +106,8 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)
if (fread(buf, buf_size, 1, fp) != 1)
goto out_free;
- ret = read_build_id(buf, buf_size, bf, size, need_swap);
+ ret = parse_notes_buildid(buf, buf_size, bf, size,
+ need_swap);
if (ret == 0)
ret = size;
break;
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 1019bbc5dbd8..41fc61d941ef 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -447,6 +447,54 @@ fetch_kernel_version(unsigned int *puint, char *str,
return 0;
}
+#define NOTE_ALIGN(sz) (((sz) + 3) & ~3)
+
+#define NT_GNU_BUILD_ID 3
+
+int parse_notes_buildid(void *note_data, size_t note_len, void *bf,
+ size_t size, bool need_swap)
+{
+ struct {
+ u32 n_namesz;
+ u32 n_descsz;
+ u32 n_type;
+ } *nhdr;
+ void *ptr;
+
+ ptr = note_data;
+ while (ptr < (note_data + note_len)) {
+ const char *name;
+ size_t namesz, descsz;
+
+ nhdr = ptr;
+ if (need_swap) {
+ nhdr->n_namesz = bswap_32(nhdr->n_namesz);
+ nhdr->n_descsz = bswap_32(nhdr->n_descsz);
+ nhdr->n_type = bswap_32(nhdr->n_type);
+ }
+
+ namesz = NOTE_ALIGN(nhdr->n_namesz);
+ descsz = NOTE_ALIGN(nhdr->n_descsz);
+
+ ptr += sizeof(*nhdr);
+ name = ptr;
+ ptr += namesz;
+ if (nhdr->n_type == NT_GNU_BUILD_ID &&
+ nhdr->n_namesz == sizeof("GNU")) {
+ if (memcmp(name, "GNU", sizeof("GNU")) == 0) {
+ size_t sz = min(size, descsz);
+
+ memcpy(bf, ptr, sz);
+ memset(bf + sz, 0, size - sz);
+ return 0;
+ }
+ }
+ ptr += descsz;
+ }
+
+ return -1;
+}
+
const char *perf_tip(const char *dirpath)
{
struct strlist *tips;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 9496365da3d7..27106548396b 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -47,6 +47,10 @@ extern int cacheline_size;
int fetch_kernel_version(unsigned int *puint,
char *str, size_t str_sz);
+
+int parse_notes_buildid(void *note_data, size_t note_len, void *bf,
+ size_t size, bool need_swap);
+
#define KVER_VERSION(x) (((x) >> 16) & 0xff)
#define KVER_PATCHLEVEL(x) (((x) >> 8) & 0xff)
#define KVER_SUBLEVEL(x) ((x) & 0xff)
--
2.13.6
next prev parent reply other threads:[~2018-04-05 15:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-05 15:16 [RFC 0/9] bpf: Add buildid check support Jiri Olsa
2018-04-05 15:16 ` Jiri Olsa [this message]
2018-04-05 15:16 ` [PATCH 2/9] perf tools: Add fetch_kernel_buildid function Jiri Olsa
2018-04-05 15:16 ` [PATCH 3/9] kbuild: Do not pass arguments to link-vmlinux.sh Jiri Olsa
2018-04-05 15:50 ` Masahiro Yamada
2018-04-05 18:59 ` Jiri Olsa
2018-04-06 0:59 ` Masahiro Yamada
2018-04-06 16:54 ` Jiri Olsa
2018-04-05 15:16 ` [PATCH 4/9] kbuild: Add filechk2 function Jiri Olsa
2018-04-05 15:16 ` [PATCH 5/9] bpf: Add CONFIG_BUILDID_H option Jiri Olsa
2018-04-05 15:16 ` [PATCH 6/9] bpf: Add CONFIG_BPF_BUILDID_CHECK option Jiri Olsa
2018-04-05 15:16 ` [PATCH 7/9] libbpf: Synchronize uapi bpf.h header Jiri Olsa
2018-04-05 15:16 ` [PATCH 8/9] libbpf: Add support to attach buildid to program load Jiri Olsa
2018-04-05 15:16 ` [PATCH 9/9] perf tools: The buildid usage in example eBPF program Jiri Olsa
2018-04-06 1:37 ` [RFC 0/9] bpf: Add buildid check support Alexei Starovoitov
2018-04-06 15:07 ` Jiri Olsa
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=20180405151645.19130-2-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=acme@redhat.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=esyr@redhat.com \
--cc=jbenc@redhat.com \
--cc=jkosina@suse.cz \
--cc=jmarchan@redhat.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.lkml@markovi.net \
--cc=netdev@vger.kernel.org \
--cc=quentin.monnet@netronome.com \
--cc=skozina@redhat.com \
--cc=yamada.masahiro@socionext.com \
/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 NNTP newsgroup(s).