Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2308660rdb; Tue, 3 Oct 2023 18:04:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGFveFkTv8BUeVhB3vjZOBpqlZ8J7HuXF350+THxavRum+fY4FmTZ+QAOl6Ecqse4R78MxJ X-Received: by 2002:a17:90a:cc7:b0:274:9121:382 with SMTP id 7-20020a17090a0cc700b0027491210382mr6410648pjt.22.1696381495447; Tue, 03 Oct 2023 18:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696381495; cv=none; d=google.com; s=arc-20160816; b=RX3GWaxNS6oz5pL46hCNSqhfo5PT0tXC8SmfC2Tt9N19D53UoUyhGT5ZCNXHyYwv5C D8FHxN7A/rnCD2+CYg0a9sJ5WsshPiBEZZf8Xnua9r6el1mzPxNQwQVcGU/jwi1y8VQk KWLtQtuQ/poCd3Z1kuMg/S1hyutpZJ1CGvlR3rc9hvy3T2U9i4Dgm9MH3I32X7xIVnxG xrQa+0rRNOTat/rjpKdUnsHHD+IZ/4my42h3JIAmsBmQBqo3Fssyt013yQcJLG3N/sfa GJCk00W8XnY/loU524PsK3xkieZLLPEBUFwi+PTje/qtay5Lh5e73mqjDNhM0q7Wga3U RSYA== 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=WDROeYS7kKQ9JBkO/Lcgw1FtJFr3f8I5Bb8UdoQeU9E=; fh=ucMdsYwPLQiIPXwccFwCFrGcM+nDdmgXKb8Y9F0BDF0=; b=Df8Hhisge4PhiXnieeDVf9fVqUFpoNOWteq9UYHuD0pXFKgWeoiI+HnlOlhrA2FW+7 TBaSXCqJXYSjA680U3LqtyrGuS+dgpl0/pxHzRVXC3izHvY8dUpjzseOuoywJS1QgEHo u/2p6BEAd/EbZYnx7uAYqrEBXnPiDegtiTHWksn/64L+986n6emf/fXPJlMdGQFCpjaN y5VIllw1oaABkS0RY/TxG2CCZ2eGt5/O7bu6A1vGMv4nFxFLTrzAW+K4aDwzMdhG0nDi wQaSPnWOMGPTTii5auSNBGhT0lcvCnRqc4zJ2e4ieLFi0oLXy87zl6jvCJ8yePEeU85D OLPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4iNDhCJX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id ls6-20020a17090b350600b0027763b64ea1si496424pjb.44.2023.10.03.18.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 18:04:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4iNDhCJX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 1034F819BB7E; Tue, 3 Oct 2023 18:04:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232300AbjJDBEj (ORCPT + 99 others); Tue, 3 Oct 2023 21:04:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbjJDBEi (ORCPT ); Tue, 3 Oct 2023 21:04:38 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7250CA9 for ; Tue, 3 Oct 2023 18:04:35 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-50348c54439so1424e87.1 for ; Tue, 03 Oct 2023 18:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696381474; x=1696986274; 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=WDROeYS7kKQ9JBkO/Lcgw1FtJFr3f8I5Bb8UdoQeU9E=; b=4iNDhCJXerx0tDlyemthkgWRxboelcftjUXqifWJEw9a11Kix612e7SkmzKpFylv6e x6EUvAZGrP/FjAAwtU0FKXeVHP5i+FZVDgt5SURini50IC/rFwcI5v2y4FS0TrO6DJSm Ebbp4FlFbdg05hOtmkLd4M49lpr2snvpi59ABpAkJt/JoSQu+KhcGXzff8PqRv3mO/oj MCbgP36uIozbZzsjnf1L1LHH0TpRrrklRkSmNw/yTAaoocIQZrnb78fePsKtzRggln+/ Pk/D/laQF2+LkGQuY84ObuLU5skAbneRS7gDtIis8A927kKVFlG+g2ULz5EKlxCLFvxR z6Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696381474; x=1696986274; 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=WDROeYS7kKQ9JBkO/Lcgw1FtJFr3f8I5Bb8UdoQeU9E=; b=BBZGbQR2IHszZ5X2vie/pI0ewpfmKcyYmeXYI0Ws0yfhXaWNRW3upysKDYgWRRBkZz qkxtsu5tLY0CVecVZKRYoMKVfXWcZ+F44G3wBjgdKzKqVhnrYzEj7O7uZ/fpKsfLeYNU aAlfFCo2ZPhdoUSK0P1noKPAAPDgZ4vbiD+AHkIt6glAhGC9hBvlvFIbrO670ExPbaHZ qTmjU+8d0DlkDl2IkCIbuG+oSxIEV+CFE6zpvsbTEjsaK6ArVrDWnaCcklfCH/Z0964j GKzqbdTTkuzEfbUHqGsR8kimw+e2/Yujr0PwonakMKNsa/BNByW3gDt+vaC7HB/jThq5 O2EA== X-Gm-Message-State: AOJu0Yw3+EoO6N8pNobS/goMv5m9H8pfWEK+fKokVMu1G2w6uAM9sMre kKV8c4tp7MfRf335fJf52FLMqYin8+OJ4nzop40g+A== X-Received: by 2002:ac2:44d1:0:b0:505:6e12:9e70 with SMTP id d17-20020ac244d1000000b005056e129e70mr32852lfm.6.1696381473439; Tue, 03 Oct 2023 18:04:33 -0700 (PDT) MIME-Version: 1.0 References: <20231003191412.3171385-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Tue, 3 Oct 2023 18:04:22 -0700 Message-ID: Subject: Re: [PATCH v2 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=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 03 Oct 2023 18:04:53 -0700 (PDT) On Tue, Oct 3, 2023 at 5:20=E2=80=AFPM Andrii Nakryiko wrote: > > On Tue, Oct 3, 2023 at 12:15=E2=80=AFPM Ian Rogers w= rote: > > > > 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 > > Reviewed-by: Alan Maguire > > --- > > See CI failures ([0]). You messed up tabs somewhere. > > [0] https://github.com/kernel-patches/bpf/actions/runs/6397510833/job/1= 7365616392?pr=3D5756 Thanks, I messed up (also) somewhere else in patch 2/2 as I broke some Google code. Working on a v3. Ian > > > 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\ > > = \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.582.g8ccd20d70d-goog > >