Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2160282imn; Mon, 1 Aug 2022 13:28:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uDYY+SEq2o6dnR2xO7ooZSZvyR5Z6O7q8ZUuhe9YY9bx2hREDjt2h2hqT9RmKbjdORZ7Hz X-Received: by 2002:a17:907:60c6:b0:72f:2e3b:ead6 with SMTP id hv6-20020a17090760c600b0072f2e3bead6mr13943470ejc.664.1659385739323; Mon, 01 Aug 2022 13:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659385739; cv=none; d=google.com; s=arc-20160816; b=lRutzB1sHi32szwEri8KQsWuSI3Xc3k515mTWZC7B4GxZMM5MMqYiJ6WQF5UwXUalJ EyLQ2rsNi0HZC7+kqtuzprEZJoRj03F/yBUWs++mu6O6EcxpKYxdRP0mteklNE/XUlHT Wu19E8mOeRjOldFgLfQKT5+2WFf+3sihGItZFQxAJiDjFjAQpRw8AvvLyzwUaWmszN2n cIfy5MNSosk+RSe4iUS6B1FaXjQVqWdHhrD+Oww/c5OO3BQ+DMSuiShP2F2yIFuMoQ/o q+lCNNJnIi+ysyzyq4rGumS+hRuCTBrgeO9eB7TY5A9LZTh4jjQo2KVrCOz/CQ9mnGsn qGJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=VGHWLnPOuI0iW4HF+EMCDJDCZmTKff3mWYUEzLkNfiw=; b=OSMklsFJmusCDSvWNtq2wLjun9vmAmedTjo529bihv+O/yGLQyV1VQ12yboQenGawz ceultIQwbUwiMlgCUQH5PN7wGVJ/VR/9/b3JAY9aS0wy13UQB2UPQSyEh/mRReLx//tL X6AfcWMO+JuoGNitcUHJXzTQOxzZqsq1LaVoyd875+fZH/NDFG0kHJmCmRL0lT32YJa3 p7GzjxgIeIqws9TBGpVWYCeCwXPC60hVBzUWUbjASW5ehNEJTNWLAdnoLSAAJkNvIbBT eGWWeWBU69JVqJabzzGbqwjxbSctOmRn0hpUWEyTDgZQoyoXRNDhpcQE68nR1mXETFv0 ghig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dAzPq79+; 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 ss10-20020a170907038a00b0072f4b13c68fsi9405373ejb.467.2022.08.01.13.28.30; Mon, 01 Aug 2022 13:28:59 -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=dAzPq79+; 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 S233641AbiHAUYu (ORCPT + 99 others); Mon, 1 Aug 2022 16:24:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232882AbiHAUYr (ORCPT ); Mon, 1 Aug 2022 16:24:47 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83FB93ED4F; Mon, 1 Aug 2022 13:24:45 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id y13so8435835ejp.13; Mon, 01 Aug 2022 13:24:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc; bh=VGHWLnPOuI0iW4HF+EMCDJDCZmTKff3mWYUEzLkNfiw=; b=dAzPq79++vwSq3w9xA+4dohDcZvqi0e0ZQ0sY20qPIv0KLftLe3e63OzidprZpDuoI dUcHn7uiB6ShtYIQEPH3oA23MVDDdQc/IBZUvm+nLbF8YFnVOdvokA/6adhir8ew94VV jDnADahwtP6A6hkTmXRV0krv2F+5BjZ04OB12O1eB8CqKY4ebhE2Kz4CJTajnzEBIQVe QYUcHbGs2Dw2OG8HsnIy7x/e9DC2Z6IVTYVomM5jdVsgUeXjHI/8mcJ+22uYBuQBIQaW cHcpGZp1pKi9mFeyMF1yuAFgwasQMxksaltwAlZc8QXa29StcOgY+ok9GDdvczOC8pej m6fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc; bh=VGHWLnPOuI0iW4HF+EMCDJDCZmTKff3mWYUEzLkNfiw=; b=DPcbn64dLvy3IhLUDK59FIUKJMC3rM1umU6ElIeGrdNdsNhUfoo4KK9au73+D8ArrH nAUqwWZiDqS7HrNDncCa19Vwm7vB6S/G/i0ZqLJlLpSvlOPr4FKuPDErPdvFXmLKunnJ +iHv8tx429P5JWnb8cav9rM+/AgHngvB2x1mLuK8XuuBQ+C70RwIUmHvIf6NQw/EN7N/ Sy/LL9R8OHls4PyKLxo4rZBw7puC7uyhvFUJLhqybUMFigvcaTM1Xtf21XIcIb1wDGPj 1ByMe6Pe2ew7SerCtSmAJbhyix2agnE/S8UMGH57OCRO6peREy+bKZ/7epdx50Rqip29 2wRA== X-Gm-Message-State: AJIora/yzCshTgfDxIozmIOFZAqRXJ3WU8aNBGVCMigZONxRWoEuLg1D h20QmlHZ/sNqHrFmq4sRY5U= X-Received: by 2002:a17:907:2d90:b0:72f:5bb:1f32 with SMTP id gt16-20020a1709072d9000b0072f05bb1f32mr14043465ejc.758.1659385483943; Mon, 01 Aug 2022 13:24:43 -0700 (PDT) Received: from krava ([83.240.62.89]) by smtp.gmail.com with ESMTPSA id 19-20020a170906301300b006fef0c7072esm5579555ejz.144.2022.08.01.13.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 13:24:43 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Mon, 1 Aug 2022 22:24:41 +0200 To: James Hilliard Cc: bpf@vger.kernel.org, "Jose E . Marchesi" , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, David Faust Subject: Re: [PATCH] libbpf: skip empty sections in bpf_object__init_global_data_maps Message-ID: References: <20220731232649.4668-1-james.hilliard1@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220731232649.4668-1-james.hilliard1@gmail.com> 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 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 Sun, Jul 31, 2022 at 05:26:49PM -0600, James Hilliard wrote: > The GNU assembler generates an empty .bss section. This is a well > established behavior in GAS that happens in all supported targets. > > The LLVM assembler doesn't generate an empty .bss section. > > bpftool chokes on the empty .bss section. > > Additionally in bpf_object__elf_collect the sec_desc->data is not > initialized when a section is not recognized. In this case, this > happens with .comment. > > So we must check that sec_desc->data is initialized before checking > if the size is 0. oops David send same change but I asked him to move the check to bpf_object__elf_collect [1] .. but with your explanation this fix actualy looks fine to me jirka [1] https://lore.kernel.org/bpf/YuKaFiZ+ksB5f0Ye@krava/ > > Signed-off-by: James Hilliard > Cc: Jose E. Marchesi > --- > tools/lib/bpf/libbpf.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 50d41815f431..77e3797cf75a 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -1642,6 +1642,10 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj) > for (sec_idx = 1; sec_idx < obj->efile.sec_cnt; sec_idx++) { > sec_desc = &obj->efile.secs[sec_idx]; > > + /* Skip recognized sections with size 0. */ > + if (sec_desc->data && sec_desc->data->d_size == 0) > + continue; > + > switch (sec_desc->sec_type) { > case SEC_DATA: > sec_name = elf_sec_name(obj, elf_sec_by_idx(obj, sec_idx)); > -- > 2.34.1 >