[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1430391165-30267-14-git-send-email-wangnan0@huawei.com>
Date: Thu, 30 Apr 2015 10:52:36 +0000
From: Wang Nan <wangnan0@...wei.com>
To: <ast@...mgrid.com>, <davem@...emloft.net>, <acme@...nel.org>,
<mingo@...hat.com>, <a.p.zijlstra@...llo.nl>,
<masami.hiramatsu.pt@...achi.com>, <jolsa@...nel.org>
CC: <lizefan@...nel.org>, <linux-kernel@...r.kernel.org>,
<pi3orama@....com>, <hekuang@...wei.com>
Subject: [RFC PATCH 13/22] perf bpf: collects relocation sections from object file.
This patch collects relocation sections into 'struct obj'. Such
sections are used for associating maps with bpf programs.
Signed-off-by: Wang Nan <wangnan0@...wei.com>
---
tools/perf/util/bpf-loader.c | 17 +++++++++++++++++
tools/perf/util/bpf-loader.h | 5 +++++
2 files changed, 22 insertions(+)
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index bbebaf1..66fbca2 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -46,6 +46,10 @@ static void bpf_obj_clear_elf(struct bpf_obj *obj)
if (!obj_elf_valid(obj))
return;
+ if (obj->elf.reloc) {
+ free(obj->elf.reloc);
+ obj->elf.reloc = NULL;
+ }
if (obj->elf.elf) {
elf_end(obj->elf.elf);
obj->elf.elf = NULL;
@@ -413,6 +417,19 @@ static int bpf_obj_elf_collect(struct bpf_obj *obj)
prog->name);
list_add(&prog->list, &obj->progs_list);
}
+ } else if (sh.sh_type == SHT_REL) {
+ obj->elf.reloc = realloc(obj->elf.reloc,
+ sizeof(*obj->elf.reloc) *
+ (++obj->elf.nr_reloc));
+ if (!obj->elf.reloc) {
+ pr_err("bpf: realloc reloc record failed\n");
+ err = -ENOMEM;
+ } else {
+ int n = obj->elf.nr_reloc - 1;
+
+ obj->elf.reloc[n].shdr = sh;
+ obj->elf.reloc[n].data = data;
+ }
}
if (err)
goto out;
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index f9cb46b..1417c0d 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h
@@ -53,6 +53,11 @@ struct bpf_obj {
Elf *elf;
GElf_Ehdr ehdr;
Elf_Data *symbols;
+ struct {
+ GElf_Shdr shdr;
+ Elf_Data *data;
+ } *reloc;
+ int nr_reloc;
} elf;
};
#define obj_elf_valid(o) ((o)->elf.fd >= 0)
--
1.8.3.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists