From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753195AbbE1BxN (ORCPT ); Wed, 27 May 2015 21:53:13 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:35480 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751398AbbE1BxK (ORCPT ); Wed, 27 May 2015 21:53:10 -0400 Date: Wed, 27 May 2015 18:53:08 -0700 From: Alexei Starovoitov To: Wang Nan Cc: paulus@samba.org, a.p.zijlstra@chello.nl, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, jolsa@kernel.org, dsahern@gmail.com, daniel@iogearbox.net, brendan.d.gregg@gmail.com, masami.hiramatsu.pt@hitachi.com, lizefan@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com Subject: Re: [RFC PATCH v4 10/29] bpf tools: Collect map definitions from 'maps' section Message-ID: <20150528015307.GE20764@Alexeis-MacBook-Pro.local> References: <1432704004-171454-1-git-send-email-wangnan0@huawei.com> <1432704004-171454-11-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1432704004-171454-11-git-send-email-wangnan0@huawei.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 27, 2015 at 05:19:45AM +0000, Wang Nan wrote: > If maps are used by eBPF programs, corresponding object file(s) should > contain a section named 'map'. Which contains map definitions. This > patch copies the data of the whole section. Map data parsing should be > acted just before map loading. > > Signed-off-by: Wang Nan > --- ... > +static int > +bpf_object__init_maps(struct bpf_object *obj, void *data, > + size_t size) > +{ > + if (size == 0) { > + pr_debug("%s doesn't need map definition\n", > + obj->path); > + return 0; > + } > + > + obj->maps_buf = malloc(size); > + if (!obj->maps_buf) { > + pr_warning("malloc maps failed: %s\n", obj->path); > + return -ENOMEM; > + } > + > + obj->maps_buf_sz = size; > + memcpy(obj->maps_buf, data, size); why copy it? To create maps and apply fixups to instructions relo sections are needed anyway, so elf has to be open while this section is being processed. So why copy?