Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2992444AbbHHIQG (ORCPT ); Sat, 8 Aug 2015 04:16:06 -0400 Received: from terminus.zytor.com ([198.137.202.10]:53867 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1946729AbbHHIPz (ORCPT ); Sat, 8 Aug 2015 04:15:55 -0400 Date: Sat, 8 Aug 2015 01:12:54 -0700 From: tip-bot for Wang Nan Message-ID: Cc: lizefan@huawei.com, masami.hiramatsu.pt@hitachi.com, mingo@kernel.org, daniel@iogearbox.net, ast@plumgrid.com, linux-kernel@vger.kernel.org, jolsa@kernel.org, wangnan0@huawei.com, a.p.zijlstra@chello.nl, acme@redhat.com, hpa@zytor.com, brendan.d.gregg@gmail.com, xiakaixu@huawei.com, tglx@linutronix.de, dsahern@gmail.com, namhyung@kernel.org, hekuang@huawei.com Reply-To: xiakaixu@huawei.com, tglx@linutronix.de, dsahern@gmail.com, hekuang@huawei.com, namhyung@kernel.org, a.p.zijlstra@chello.nl, acme@redhat.com, hpa@zytor.com, brendan.d.gregg@gmail.com, linux-kernel@vger.kernel.org, wangnan0@huawei.com, jolsa@kernel.org, lizefan@huawei.com, mingo@kernel.org, masami.hiramatsu.pt@hitachi.com, ast@plumgrid.com, daniel@iogearbox.net In-Reply-To: <1435716878-189507-14-git-send-email-wangnan0@huawei.com> References: <1435716878-189507-14-git-send-email-wangnan0@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] bpf tools: Collect relocation sections from SHT_REL sections Git-Commit-ID: b62f06e81bcf28d47fe736fe2beae40f15f496be X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3312 Lines: 99 Commit-ID: b62f06e81bcf28d47fe736fe2beae40f15f496be Gitweb: http://git.kernel.org/tip/b62f06e81bcf28d47fe736fe2beae40f15f496be Author: Wang Nan AuthorDate: Wed, 1 Jul 2015 02:14:01 +0000 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 7 Aug 2015 10:16:57 -0300 bpf tools: Collect relocation sections from SHT_REL sections This patch collects relocation sections into 'struct object'. Such sections are used for connecting maps to bpf programs. 'reloc' field in 'struct bpf_object' is introduced for storing such information. This patch simply store the data into 'reloc' field. Following patch will parse them to know the exact instructions which are needed to be relocated. Note that the collected data will be invalid after ELF object file is closed. This is the second patch related to map relocation. The first one is 'bpf tools: Collect symbol table from SHT_SYMTAB section'. The principle of map relocation is described in its commit message. Signed-off-by: Wang Nan Acked-by: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1435716878-189507-14-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/libbpf.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 102156f..e8088f8 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -110,6 +110,11 @@ struct bpf_object { Elf *elf; GElf_Ehdr ehdr; Elf_Data *symbols; + struct { + GElf_Shdr shdr; + Elf_Data *data; + } *reloc; + int nr_reloc; } efile; char path[]; }; @@ -231,6 +236,9 @@ static void bpf_object__elf_finish(struct bpf_object *obj) obj->efile.elf = NULL; } obj->efile.symbols = NULL; + + zfree(&obj->efile.reloc); + obj->efile.nr_reloc = 0; zclose(obj->efile.fd); obj->efile.obj_buf = NULL; obj->efile.obj_buf_sz = 0; @@ -447,6 +455,24 @@ static int bpf_object__elf_collect(struct bpf_object *obj) pr_warning("failed to alloc program %s (%s): %s", name, obj->path, errmsg); } + } else if (sh.sh_type == SHT_REL) { + void *reloc = obj->efile.reloc; + int nr_reloc = obj->efile.nr_reloc + 1; + + reloc = realloc(reloc, + sizeof(*obj->efile.reloc) * nr_reloc); + if (!reloc) { + pr_warning("realloc failed\n"); + err = -ENOMEM; + } else { + int n = nr_reloc - 1; + + obj->efile.reloc = reloc; + obj->efile.nr_reloc = nr_reloc; + + obj->efile.reloc[n].shdr = sh; + obj->efile.reloc[n].data = data; + } } if (err) goto out; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/