From patchwork Thu Apr 5 15:16:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 895440 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40H62Q6Sycz9s0p for ; Fri, 6 Apr 2018 01:19:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751516AbeDEPQ4 (ORCPT ); Thu, 5 Apr 2018 11:16:56 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34424 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751179AbeDEPQy (ORCPT ); Thu, 5 Apr 2018 11:16:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF13A406E97C; Thu, 5 Apr 2018 15:16:53 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 888AAAB400; Thu, 5 Apr 2018 15:16:51 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: lkml , netdev@vger.kernel.org, linux-kbuild@vger.kernel.org, Quentin Monnet , Eugene Syromiatnikov , Jiri Benc , Stanislav Kozina , Jerome Marchand , Arnaldo Carvalho de Melo , Masahiro Yamada , Michal Marek , Jiri Kosina Subject: [PATCH 1/9] perf tools: Make read_build_id function public Date: Thu, 5 Apr 2018 17:16:37 +0200 Message-Id: <20180405151645.19130-2-jolsa@kernel.org> In-Reply-To: <20180405151645.19130-1-jolsa@kernel.org> References: <20180405151645.19130-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Apr 2018 15:16:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 05 Apr 2018 15:16:53 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jolsa@kernel.org' RCPT:'' Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.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 --- 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)