Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp619853rdb; Fri, 6 Oct 2023 13:20:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGFH6yorgKqsm95XJ9oMsgidovn9IITpR2mX3UK5FGZnIdr/D62T0ANDNQC6HOMnSkr9yu+ X-Received: by 2002:a05:6a20:7d95:b0:16b:8067:23a7 with SMTP id v21-20020a056a207d9500b0016b806723a7mr3704251pzj.24.1696623642679; Fri, 06 Oct 2023 13:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696623642; cv=none; d=google.com; s=arc-20160816; b=Jh2G13w4lQtIPeRcZnNyTddkZLX9RgWXvfRGRZHFP1xd1EUmPDolH+8JDVRa7ttaJd gBx/GmqgaauOJYr7rprJY1vyakdydKk3V7XhnTuGXjJm1+cIJyPEn5XstG0X858oOjWv xGSlZfWCTJjV3mj/eW0r5sgEsajI8AtBJkpoSJz3OcyLgzToizV3Ogx1NfNqI37+JOhK t/dY0iGkYArsVjmSHd6g193gAnZnBPwGKyAW+4cT4/LNtUjbMxaaa8YLMuLIu70NILCv 3mrekm+Q89im83+cEIvOF0BpWV+izVDsZMpBzu1LdyrW7+k19PTYrFAwUybbfBgYf1Pe Ivtg== 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=cKhoOovJJCN2upy+4Afr69/fh1TMRJWzCU1Zea4v2kE=; fh=xbxgTV6Qf12z5SMwuWWRxgWwVNScHCbJrt5WfpiFNr4=; b=gDLPZpscUB4r4r60Qn5GydTY89Ro8pxp221ujUnEmgB3yk9Y1E9s/H9XlOv0FIf3HQ vNexdSsVHdKi2RWYTlGbbED21gfFQV+YD0q8cIrBoahLXdT5GE0RZkXL8UgtbNvNHxve 4SravKSdwhleGKaVlzHuQ29EBapGapknhovMWtCqQQgt4lS/5KOudHMZ0rDKXCQfq/oh uTHqt6PJJBLpTbmZOOXUyfl4JbZ61RzsiUJK6rGpjbbo88YJI7oUGF+sRlEgEfb2Xges p9oBgBSkYPRLAxvanlkOIndR/hfUmYYUA9qmZULgivYiv88NZxzMN85y7gN3GZjFiQQ8 KWXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PDVVEFv8; 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 kk4-20020a170903070400b001bbd70bdffbsi4128906plb.440.2023.10.06.13.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 13:20:42 -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=PDVVEFv8; 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 EF5F18964163; Fri, 6 Oct 2023 13:20:39 -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 S233465AbjJFUU3 (ORCPT + 99 others); Fri, 6 Oct 2023 16:20:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233452AbjJFUU1 (ORCPT ); Fri, 6 Oct 2023 16:20:27 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD80DC2; Fri, 6 Oct 2023 13:20:24 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-533edb5ac54so4726432a12.0; Fri, 06 Oct 2023 13:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696623623; x=1697228423; 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=cKhoOovJJCN2upy+4Afr69/fh1TMRJWzCU1Zea4v2kE=; b=PDVVEFv8gIqFq3oHh6twa4sOauegXiPp1XL2qFvuk4iVzNTRZ6oq3rZkp7Bka9I+sK PCiZSFtltVr6V+8+7tldooPU/9lFOtNYRvo0v+jZQeFqUJMxMMZGnxet+hejOD1NFukw Lt27bTLn95cP2puvOjEoUVuchnjR3UsTdxt0nuF03uZ8TZOnxT/DFmtj1iYM4juCgOUQ gCcWXwuyMI0m9JDXYFIzX07JlLNxfneB4Ey/SjbV3CcQEZwMFNVwV9LuTkxEFIBzC88P FsAdawsRrHjmV8shCfeBozXd1nP54fBF0xX+NDLmRWC0qims9FPiXWwP+0ea8kEqzufN FmNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696623623; x=1697228423; 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=cKhoOovJJCN2upy+4Afr69/fh1TMRJWzCU1Zea4v2kE=; b=WSUUrYI6F3aMXbVJX+vjmViYDuM1YekvqaOKTQ5rfxlRwnI++CYVjRj9hUDASkpC4T V3Ha0N50xZzzoslRX+/e5ESjknc/092ML1ns2LonCcVJEcsBAPQXpNoAVcVC81ls38ad sHJRs+Csxis2/f4iCrtwWU6pvYeGCpuGjpj2alOWm0eN87UK0N4razyZoJpHj5ERKSN3 DuuYpUjaCDdok95Le31IjjqMbfd17w1UFo0+dCZ/3t/ytTl51A3CfBjfF80vCGQfV9Ot jGc8IGe8ri03fjd8J8OCuIXml1dBAXLGSTrB9QU19FsPDhUywCmbvy/4QMz3Z0Pe70Fw yrRQ== X-Gm-Message-State: AOJu0YzlNbJAQFpAkGjiuEAqRrtDDR9/bnc2yfCPT2eZ71K4EaEMvWih Td5HgBTzQhVT81ORUckAXUeiKyib1eK/PdEfN4TEf1yxNCs= X-Received: by 2002:aa7:d151:0:b0:530:db58:61c8 with SMTP id r17-20020aa7d151000000b00530db5861c8mr8699991edo.23.1696623622922; Fri, 06 Oct 2023 13:20:22 -0700 (PDT) MIME-Version: 1.0 References: <20231005220324.3635499-1-irogers@google.com> In-Reply-To: <20231005220324.3635499-1-irogers@google.com> From: Andrii Nakryiko Date: Fri, 6 Oct 2023 13:20:11 -0700 Message-ID: Subject: Re: [PATCH v5 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=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Fri, 06 Oct 2023 13:20:40 -0700 (PDT) X-Spam-Level: ** On Thu, Oct 5, 2023 at 3:03=E2=80=AFPM Ian Rogers wrot= e: > > 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 > 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! > = \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.609.gbb76f46606-goog >