Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2824449ioo; Tue, 24 May 2022 06:51:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhgj6DoeEEin6ZswqUNfOiUL4Zdc9lLgZuXi+GjIibX4D+YjfHR1Mz6mgKHOfUhxfq2+se X-Received: by 2002:a17:907:168e:b0:6fe:b705:7e65 with SMTP id hc14-20020a170907168e00b006feb7057e65mr17178036ejc.490.1653400281528; Tue, 24 May 2022 06:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653400281; cv=none; d=google.com; s=arc-20160816; b=heemXC+Lk80JE/TOO3iBvzQqAt8f8Ja4uaypoNI3KHWMA/lQd/j+rv/JPd76wRIe02 HKVyb0jxJlO/7y80zpf1qP74BJlXOCBBSLViTR3EBlHeYGpJn3ZlUmJfvEzd6xJF5Jcx LvG4OcOno4mjP1CiR6AJyNm5Px+iZf/MlnPfdvZ5EO2bCSwK8Ki/JS/iDKB5ZDokvG4U /2/0tvk9URbQEOqRgGE2C6CIAIe7apPaspMbAdHQMoKqzNO/y/6tGu0pBvxmY9df3YSb foLJ44zeLEjKQDpKdV7looszfxxKdHrpzcQVrkECESJ3vKF+lf6qYIkBDYJiQaGyipbC cXCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WgfA+bj8h/yfvLtv8TQjcWpJiGYbRoi7JEJT7KRe+10=; b=yzA8fHFVirIQAWw/0ytqlfUYpc6RxR8fYIwL0jZggjTv+1YRLr3pRUDd+rkSd5VQu1 FwweaEpfHu9q5XdG4/luX/duiWCbsvc/mHgKWHtTt/Ta/TijmmFSudS0iHTDXmXzfrwD pLXLJ+PTzcYENM4vK8lFy89E0FHysC7o8Kaonmc42iHst//Y6Ikuisp1FQ1RfiXKiwS/ 4rhwTtNwmucx2O/RwyPytnKlDCeOb6lpEoiVMtoi8n7kKWUrvty0ueeZu3q5NXxLkRLi Ak8VTZmwGGZ4D5sU916bFNfBZva7olzF0X/jcGSQNeu6ucpoOgP854URGAKrafsGg7oB vF2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gacDjAeQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd9-20020a1709069b8900b006ff0a118422si739910ejc.522.2022.05.24.06.50.32; Tue, 24 May 2022 06:51:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gacDjAeQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231562AbiEWWiX (ORCPT + 99 others); Mon, 23 May 2022 18:38:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbiEWWiQ (ORCPT ); Mon, 23 May 2022 18:38:16 -0400 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3951C9CF7D; Mon, 23 May 2022 15:38:15 -0700 (PDT) Received: by mail-io1-xd2e.google.com with SMTP id 2so6945363iou.5; Mon, 23 May 2022 15:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WgfA+bj8h/yfvLtv8TQjcWpJiGYbRoi7JEJT7KRe+10=; b=gacDjAeQh6oI7YHuiwPSGFwsV3CF57PtZWR9POoh7jzgX+t+opWpA1dnvhnh8pNHt2 irTzfrFP+T58xwnWZzI7TMGr6ltUwxZ9thY7wOyeuOcTOQpzRMq3MTANn75hiEDLvimx 2LkqFw4ADDzhUsVpIZyDjKYyZSPZSIqMkri+sbt1OKBNBeAdinFdn7AY9pdDMZSD8sHi G5JatAMH8vpk/KZeY5Qwgf8r56MtS1EVs0BZNwGWWwY4hLtQIXoTXUoIaJ5qJWBZyI1B iNk4ijFLQOKSQaFKKvC/oprDbb35shx17I8AfsGhLdhterZbPeqERz2MGVRwn/McDNYK mGxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WgfA+bj8h/yfvLtv8TQjcWpJiGYbRoi7JEJT7KRe+10=; b=CnA2r/a6PWiLvBQJKY6D/tc41jMpkT1+gwFbFn+m2urwO7wgw88b2F15PZkTTJ4q6K 95OYVmHygvIheS9fwLHx6i+yXPL7W98b9qOmPgHZmypvDPrDY3kCi+EXgMqSg/8L874l 5JjrTxxy33vF5g0fqjpSkS/89OWBfR4QJ4nEwDsSYhJGF8tA/dQRaD2/gWng78qfZr8R Os+i1ktplZE8AfGQjsz+o7k8k52cLxy/kM+lANswkhd9svqeAjiwpfNfuzitq68NJHf6 VchyG1MNSjliHZtTpwhpXR6rlZBI6tDio/paI48RZbYC3o6N9dZdkr4QcleKBuk4LBfQ RuoQ== X-Gm-Message-State: AOAM533ykuOzL5zEqTdwML1A5nYtoU2a+au5jYq1NqfObu4fKJC0bt62 JsxMVeSTN/2A41vGjzhPFvmK/4NHMCueopXR41M= X-Received: by 2002:a02:9f87:0:b0:32e:69ae:23df with SMTP id a7-20020a029f87000000b0032e69ae23dfmr12443446jam.237.1653345494552; Mon, 23 May 2022 15:38:14 -0700 (PDT) MIME-Version: 1.0 References: <20220523202649.6iiz4h2wf5ryx3w2@jup> <20220523221954.dsqvy55ron4cfdqq@jup> In-Reply-To: <20220523221954.dsqvy55ron4cfdqq@jup> From: Andrii Nakryiko Date: Mon, 23 May 2022 15:38:03 -0700 Message-ID: Subject: Re: [PATCH] bpftool: mmaped fields missing map structure in generated skeletons To: Michael Mullin Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Networking , bpf , open list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 23, 2022 at 3:19 PM Michael Mullin wrote: > > On Mon, May 23, 2022 at 03:02:31PM -0700, Andrii Nakryiko wrote: > > On Mon, May 23, 2022 at 1:26 PM Michael Mullin wrote: > > > > > > When generating a skeleton which has an mmaped map field, bpftool's > > > output is missing the map structure. This causes a compile break when > > > the generated skeleton is compiled as the field belongs to the internal > > > struct maps, not directly to the obj. > > > > > > Signed-off-by: Michael Mullin > > > --- > > > tools/bpf/bpftool/gen.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c > > > index f158dc1c2149..b49293795ba0 100644 > > > --- a/tools/bpf/bpftool/gen.c > > > +++ b/tools/bpf/bpftool/gen.c > > > @@ -853,7 +853,7 @@ codegen_maps_skeleton(struct bpf_object *obj, size_t map_cnt, bool mmaped) > > > i, bpf_map__name(map), i, ident); > > > /* memory-mapped internal maps */ > > > if (mmaped && is_internal_mmapable_map(map, ident, sizeof(ident))) { > > > - printf("\ts->maps[%zu].mmaped = (void **)&obj->%s;\n", > > > + printf("\ts->maps[%zu].mmaped = (void **)&obj->maps.%s;\n", > > > > That's not right. maps.my_map is struct bpf_map *, but mmaped is > > supposed to be a blob of memory that is memory-mapped into map. > > > > Can you elaborate on how you trigger that compilation error with a > > small example? > > I have an a very small example on github. I have added some sed fixes to > my Makefile make my sample program compile. > https://github.com/masmullin2000/libbpf-sample/tree/main/c/simple > > https://github.com/masmullin2000/libbpf-sample/tree/02c7f945bf9027daedec04f485a320ba2df28204/c/simple > contains broken code. You are missing -g when calling clang to generate debug info (DWARF and subsequently BTF). When BPF object file doesn't have BTF, we don't generate those bss/data/rodata/etc sections of the skeleton. You should be good just by adding -g. > > I apologize if this is an incorrect way to share external code. I > haven't found the proper way to share example code from > kernelnewbies.org > > > > > > i, ident); > > > } > > > i++; > > > -- > > > 2.36.1 > > >