Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2293413rdb; Tue, 3 Oct 2023 17:20:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsOEzD3CzGrylNH013Hdzz//R8KVqWuXH0oCdLZ8NJI/YjWKNKoNOzG9n2FMoV2MJOJLoe X-Received: by 2002:a81:a0d2:0:b0:577:21ff:4d47 with SMTP id x201-20020a81a0d2000000b0057721ff4d47mr1270045ywg.7.1696378815512; Tue, 03 Oct 2023 17:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696378815; cv=none; d=google.com; s=arc-20160816; b=iotg+jw0m7y+lz16SB9134pBvFgfw+jomyVxvZY5DViT55XADP5RbEdTPf+GttUb5c NR2MJKuaY5wlDapn6RaLG51Mew4NdrWduV0cqV/YUR/SK62nz9fSY0MqFo7TUd2mMEB5 N4CZlU3aAFF5YzZ371Xvs2sPT4XMb9xIxOo/Kj2Rf+h82MKI7SpTtuwuCJ3zqL+wy/r/ kReU0Yjjg1rkl1vQnLMHdpqCVIKR3SkOQvfNUaCpV+tC3FDOPcYWAXBtcKiyVgR7tc68 xppYL6Bj841o+oYsNpu9G9zmty0fK60W+a8zRdjIPejDS8W/JP8yzOVjDI76u8CKkpZH 7/jw== 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=/As1VhnozQGSmkx2UPQKSVlv7yhYS02UudRqOf6rBnQ=; fh=xbxgTV6Qf12z5SMwuWWRxgWwVNScHCbJrt5WfpiFNr4=; b=eMivb1D397jRHPouDMrDWPr8Fm1xbW9N5meI33584ANKAVhYBwnW2CehEo1Hk66ZyH Om58RAsvx+7DJUO0GUZLi0ju93LeuzQl21cmSqEHbnJeKjR3ikiGMVBd8hj6D7OhUCnt nN38nTfLCk8DihfKefcAjdYbZ5GwuV7qjkbjWjuwesXGiSfV93efkV5lfGuqJ2a3tcIn /YO4pQ/OsOjD16QfKGf57A1comlnm80IlRhR14Rx2PGr56TSW7Sg0P7VAx6VnN0DIuzY 5x/rzAL44emHNbOLMuUHcG65S3DD+Vg8nMu/qrLo1O3zjfYT/yCGgu04keZWXb0hUiVb b3ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BS5ybtHf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id b22-20020a639316000000b00577d99bd045si2484890pge.843.2023.10.03.17.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 17:20:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BS5ybtHf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 308ED8317EBF; Tue, 3 Oct 2023 17:20:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238456AbjJDAUN (ORCPT + 99 others); Tue, 3 Oct 2023 20:20:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238406AbjJDAUN (ORCPT ); Tue, 3 Oct 2023 20:20:13 -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 AF00EA7; Tue, 3 Oct 2023 17:20:09 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9b281a2aa94so274277766b.2; Tue, 03 Oct 2023 17:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696378808; x=1696983608; 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=/As1VhnozQGSmkx2UPQKSVlv7yhYS02UudRqOf6rBnQ=; b=BS5ybtHfiGQtBZ0ocmDZWehMwXUrE+q2P0Af2fXQqeTIVwF+gL6QZXxJmm/BKTRdhO AtxfohmCszymb+kkJAq+hFeh1xsKyWeE5fb5Tjcl9SoQAl/24blDeObxF+A8LolAQH2X p5fNWZZvteAg4yHj4OnXoY/S+IM1sdZOClyjM7Vo1gdTWcBHm0gfxRJ1rNA6/Ef8xbwE /yDOity50BSha7GjLFMKcs+0ivnn8hm81NB6cfjHq2/CvRikFOgqD+5+HoXNVESJ4xMA a8umLH4Zwz61py+z8SuIKtNWt2vQw2ubhqSQxNfAmShCl8ljkZ/TYhOoWevFXaQ//lDV JgOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696378808; x=1696983608; 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=/As1VhnozQGSmkx2UPQKSVlv7yhYS02UudRqOf6rBnQ=; b=VNEjXibSr1rQKAeTPriUI0usVQwhpAPLj5rZnneDxqPVtsRlD8gDTJEEh8IpcDLXVO RdLvdBhU0GF58PAqHTP4YizFF9xNWVn9nuRHQA9NR9Iqzdjo6NvXsFLW77Z6J4IHQTl2 UR2dEycAwhSJuRmB7YTEIm3m1L/5rCy5AO7fKhPs+XQzCdeILN8Mwed3aB/Xf2/p+hQq od3OZnDQPl/63521Qz2+jdndttshA5lg1ZO1Zgk+EB6WFWRlJMCbZhr+C9aVD4My9U5b RT6iZiAzDezW5VwEUbawsaqtOKGawOg3oinyRwQk00Hm7bjC0ar4/QHKbFs4TinnfgmZ xt9A== X-Gm-Message-State: AOJu0YzPiUmmXelblYiJV8FSmunpB7ezZcpBKCYlT2wICKHpsc8Fq52C IAOJrZfv6Qt8eW3ZEBbouBdtfLqeoPxSDmltmns= X-Received: by 2002:a17:906:1daa:b0:9b8:b683:5854 with SMTP id u10-20020a1709061daa00b009b8b6835854mr103108ejh.61.1696378807949; Tue, 03 Oct 2023 17:20:07 -0700 (PDT) MIME-Version: 1.0 References: <20231003191412.3171385-1-irogers@google.com> In-Reply-To: <20231003191412.3171385-1-irogers@google.com> From: Andrii Nakryiko Date: Tue, 3 Oct 2023 17:19:56 -0700 Message-ID: Subject: Re: [PATCH v2 1/2] bpftool: Align output skeleton ELF code To: Ian Rogers 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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 03 Oct 2023 17:20:14 -0700 (PDT) On Tue, Oct 3, 2023 at 12:15=E2=80=AFPM Ian Rogers wro= te: > > 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 skel= eton'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/173= 65616392?pr=3D5756 > 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__((__aligned= __(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 >