Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp620565rdb; Fri, 6 Oct 2023 13:22:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0CCGdOHnGOq8c7F+47pNiVXRrgglvbEmFTtuw+G/6P8ioHTDTlh7vbHkUkqUlp3QEYOBw X-Received: by 2002:a17:902:cec2:b0:1c8:910b:3753 with SMTP id d2-20020a170902cec200b001c8910b3753mr2711983plg.34.1696623752744; Fri, 06 Oct 2023 13:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696623752; cv=none; d=google.com; s=arc-20160816; b=zs7Qmc7E+pj74630OwB9fQIDP9ZPO4vMoshjcIjLUTjXFgTc2JLMA/Yue52Jnh1g8Q 0lQZX9fDvPHPmb8svbhB5RJ0949pU9RjY1rTDt04DfGBZzmkwwBQjbA7dv2MPhvFfTnv eN7Ojs+aJx9t4gwit7jm+8mVUMvRY6nQAeBlOQ6w5Wt2IN58/1XrYpDoJSMnu9/aMeFf 3lgbp9j2ZlITYDfAO9jE2x4mS2mPat9G1pBCU05fPNrbBpcSO412aJyUHrFCm0pQMrXH Ta+KYMPR0JU4pNDMzy55rKI6MCDIBp1WI6IyspL87puWUWBI3t0DzD1DrvV1TauOkvtf s+Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=d/4hSoCDyaBEYy7aXsgoLzXeIlCi3RJAlrp96XY1SLQ=; fh=ucMdsYwPLQiIPXwccFwCFrGcM+nDdmgXKb8Y9F0BDF0=; b=suDR3CdDijyeDlGWAlodhPNCgggecNR0FKznUthGEwi2SpFp8hawno2rVHDkNEg2CF 5TjRrU3GwX+sSpLvMy46p1iGSgZDqO1sC2s73B7sczSU03JyKacwuk37JZ3DpeVlILsQ kvvz+izZgLZFUOlGZLAh+z8yRwU4jJU1ZnxyptPchgRA0rLOq7cXMgbqgewqQpZKHLdZ dcd7RtrmHq0YeYifUEKKdVhcW/gEZFDwqnnjSV/POI8EcIjivj1jivKWwJTBgPzVUnH3 /wyXV1e9hOcHZibAe5gwaaQ2sdWGQ/l5XbhPWtUHwX9ax5BQ2wfACq/96OGloarEjPbO ufRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KgF1nKu0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id kf4-20020a17090305c400b001c3e9b0bae1si4194316plb.443.2023.10.06.13.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:22:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KgF1nKu0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8123280B19CB; Fri, 6 Oct 2023 13:22:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233423AbjJFUWV (ORCPT + 99 others); Fri, 6 Oct 2023 16:22:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233318AbjJFUWU (ORCPT ); Fri, 6 Oct 2023 16:22:20 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFBFEBD for ; Fri, 6 Oct 2023 13:22:18 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5032a508e74so213e87.1 for ; Fri, 06 Oct 2023 13:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696623737; x=1697228537; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=d/4hSoCDyaBEYy7aXsgoLzXeIlCi3RJAlrp96XY1SLQ=; b=KgF1nKu0lGe2xmMn80uRxeexdo4SSk/JFsTSn2t7igSpS4bbQFKblxTmezmIDGwq6F uA9rXTEDr5yGBHDa6mgn3cXF6sm43SpaMfyIRkgO84r6L57j/g4vegE2nyDtgC+VoLcs OZrcFb3cPw8xsMdJigFXI0x9UK52LSpEC/T41Fq5LIViviq8BoCiqIlX4U5k9H+YQCRR AJOw+dzbch+8mQBvFrxb/AJxv8pAzCpJ4E+8bmg2n3CeGhx903NEyQsmr+S0pzZKsaV1 wNQE5cqK41/EcguwkOfi5we7zDHjO0X4SMc+Pj6POyNZ94iFU1wk+CPQD9X4hv7/3QMA VpYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696623737; x=1697228537; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d/4hSoCDyaBEYy7aXsgoLzXeIlCi3RJAlrp96XY1SLQ=; b=Xf98q5lSvXnObL2LIGKgqRiLfyZt2fODIeZIGzzDjecC7i6FwLq4a7tOjoNUC1M3Jl NXcUIa2cb22Xed/6SiR1Fl8i1/qKo7Z6SjbtfH3UZ8Uq7oxIUJ8CTADFs3HmDUFpUZHr rP3SRGVjoGZP2/T1Pa5utp05x8lMsDHobPorbj8NgQmxV2d6f0b8AqZ5+edLDqRfKUl5 KBuquPsqVdYI8xl6I8LETM4pciQdOibfd/sBdyeYqWodT4qGmnxyhUtMQztFKrohmK49 y/NrQGUiEXDVkxiS0QyPGEZl0XFjGQZvJGSxbiPwDbkI2p4yOt0br4FS9Nj8fPDojxjG VGNQ== X-Gm-Message-State: AOJu0YwBAsYlIEGvjNVGM6fLdRLjzEBmIGkUPEdM5vBW2g7tlk47WnnC w8OZUJP2dxYwl08T89FeiDv47Fy/lzPmC1AGTuJNIQ== X-Received: by 2002:a05:6512:4801:b0:502:a55e:fec0 with SMTP id eo1-20020a056512480100b00502a55efec0mr146330lfb.6.1696623736764; Fri, 06 Oct 2023 13:22:16 -0700 (PDT) MIME-Version: 1.0 References: <20231005220324.3635499-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Fri, 6 Oct 2023 13:22:05 -0700 Message-ID: Subject: Re: [PATCH v5 1/2] bpftool: Align output skeleton ELF code To: Andrii Nakryiko Cc: Quentin Monnet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alan Maguire Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 06 Oct 2023 13:22:30 -0700 (PDT) On Fri, Oct 6, 2023 at 1:20=E2=80=AFPM Andrii Nakryiko wrote: > > On Thu, Oct 5, 2023 at 3:03=E2=80=AFPM Ian Rogers wr= ote: > > > > libbpf accesses the ELF data requiring at least 8 byte alignment, > > however, the data is generated into a C string that doesn't guarantee > > alignment. Fix this by assigning to an aligned char array. Use sizeof > > on the array, less one for the \0 terminator, rather than generating a > > constant. > > > > Fixes: a6cc6b34b93e ("bpftool: Provide a helper method for accessing sk= eleton's embedded ELF data") > > Signed-off-by: Ian Rogers > > Acked-by: Quentin Monnet > > Reviewed-by: Alan Maguire > > --- > > tools/bpf/bpftool/gen.c | 15 +++++++++------ > > 1 file changed, 9 insertions(+), 6 deletions(-) > > > > diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c > > index 2883660d6b67..b8ebcee9bc56 100644 > > --- a/tools/bpf/bpftool/gen.c > > +++ b/tools/bpf/bpftool/gen.c > > @@ -1209,7 +1209,7 @@ static int do_skeleton(int argc, char **argv) > > codegen("\ > > \n\ > > = \n\ > > - s->data =3D (void *)%2$s__elf_bytes(&s->data_sz= ); \n\ > > + s->data =3D (void *)%1$s__elf_bytes(&s->data_sz= ); \n\ > > Seems like you based this on top of bpf tree, can you please rebase > onto bpf-next, it has a small change here and I can't apply it cleanly > anymore. Other than that it looks good. Thanks! Sure thing, sorry for so many V-s, we'll get there in the end. Thanks, Ian > > = \n\ > > obj->skeleton =3D s; = \n\ > > return 0; = \n\ > > @@ -1218,12 +1218,12 @@ static int do_skeleton(int argc, char **argv) > > return err; = \n\ > > } = \n\ > > = \n\ > > - static inline const void *%2$s__elf_bytes(size_t *sz) = \n\ > > + static inline const void *%1$s__elf_bytes(size_t *sz) = \n\ > > { = \n\ > > - *sz =3D %1$d; = \n\ > > - return (const void *)\"\\ = \n\ > > - " > > - , file_sz, obj_name); > > + static const char data[] __attribute__((__align= ed__(8))) =3D \"\\\n\ > > + ", > > + obj_name > > + ); > > > > /* embed contents of BPF object file */ > > print_hex(obj_data, file_sz); > > @@ -1231,6 +1231,9 @@ static int do_skeleton(int argc, char **argv) > > codegen("\ > > \n\ > > \"; = \n\ > > + = \n\ > > + *sz =3D sizeof(data) - 1; = \n\ > > + return (const void *)data; = \n\ > > } = \n\ > > = \n\ > > #ifdef __cplusplus = \n\ > > -- > > 2.42.0.609.gbb76f46606-goog > >