Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2887646rdb; Wed, 4 Oct 2023 15:01:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQE9dLWUTmZfCCdaEi9wS034JLZGyRV0u5KkfK/bV2Ls8mC31RQqoAA3yxdI8+1U1Q8y17 X-Received: by 2002:a05:6a20:549f:b0:14d:9bd1:6361 with SMTP id i31-20020a056a20549f00b0014d9bd16361mr4203190pzk.11.1696456873735; Wed, 04 Oct 2023 15:01:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696456873; cv=none; d=google.com; s=arc-20160816; b=KghIguz6U+KfkUM+Gfmh5/wl/2x7jC7H9DhMF12xhln3f5gHM7YprFerIDK98AuVeY 5zV93a287rzBDk+W9pv09toiG41IyOwpG3365aFboWjX0+3Ilvyx2pbnowkd264b5A2+ t8N3Z3dU6bY6uuYufC13ths4aRj/lyqinMYR9/n7ZwmWVn5L9fYE5cly4UIPSes/0GZ3 P7mWJ0giQsas+BhMAp4xrouKlEUdIv+CI67leFPU3iVvmKv86tg1J0fsmQdZ+1WWmHHP NqdbQ271DyYbqqdK7xJ47+DdQw9qdwrVf4jqNBC6ykKXfjJWYc+tGkZbbOgz2GMPHmws /ihw== 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=O/0i1/S5DFSndM3ejN3HqZTrstM7oItSFDz5mhrpE48=; fh=xbxgTV6Qf12z5SMwuWWRxgWwVNScHCbJrt5WfpiFNr4=; b=aioR/p3Ob9+1eMNN0sVvjQ8fXw3p+6MvQH6Q66xc06CvmNUDGKPKEAq+dgoVXvW7RR BJd80/RjYkRAYBLfa0RVjzLDIDKYp62saEikUattJJyUexyrTxzrfUFw5Wj7X6zNdJbi jvAgZ0jxyex0bVGCtvC0dLNVrGasAEuMdEVahFwSc4GQGyfcpezKY7obqI1ZzFxEOihL XKgCZt0+OLtj/nCdjFpyJN/LRTQRpy2x/NW2FDnuJoDMj91YelVTZcuTu7QfR+efmI2k SL8cUjU6D81vH9tBHLqjxII4lEzzllPwZPdJ6djPbjV1Hqg+lwWmaPbsHr2epGC9Sl5H 0wfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=N9LQFIOk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id m1-20020a656a01000000b00573ff14b9e0si35478pgu.763.2023.10.04.15.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 15:01:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=N9LQFIOk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 808E8807CEE5; Wed, 4 Oct 2023 15:00:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233516AbjJDV4i (ORCPT + 99 others); Wed, 4 Oct 2023 17:56:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbjJDV4h (ORCPT ); Wed, 4 Oct 2023 17:56:37 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E9BDC6; Wed, 4 Oct 2023 14:56:34 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-533df112914so453176a12.0; Wed, 04 Oct 2023 14:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696456592; x=1697061392; 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=O/0i1/S5DFSndM3ejN3HqZTrstM7oItSFDz5mhrpE48=; b=N9LQFIOkAz0h1JuV9+/UUkvvvy446tZ1rms3tXaVYk0rCA2tySP+VV/6sHjcAFpeES 7p5/fiQCF2zuq5K+z7M/FlG0Fac58Ej2GTJXPHulvJYj+djU4ro6jKySAz15lpObFAJj B4NH5XGYajwtFqG6esYsWchETh55Zk1dt6BVcGOF7MvbinTZ9gO8vJXDG3a2q22l/pEJ Rc2XOFkbssxX+XIh0fneSoauimsvxqluOXL8xP+uPg7+8FESqpm7vedh82TpcKOe3hZk 8HeNlJe7FCPGNZ6tje5BF+wVuhyhXKIs+et7WF1BV72rcBzdmRCHISsbPSum884rGGql 4D2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696456592; x=1697061392; 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=O/0i1/S5DFSndM3ejN3HqZTrstM7oItSFDz5mhrpE48=; b=TldeKvlpEKxdmY+80O6m0eRHJudFql1HxsJns5JNhDddG0E5rZOkumvgHGE8BNhiXu gVxalpe9f2Ym9UpwxbYx6GJc2oopd1lGyxw/M8700fxb8MA91MdyH3xuonBlLam2J/DK D9ewalkDxZvCZa+Vdy2d2jj8ooXlhl2d+8MGT1k8xQVv/t+W8/VUId2xQ1/7Tup3qtgj 0I7DLhGy4euZ/+XdsDSgei3oO6vuYETbRqC6SVKvT0niLzatoyFPCmDBfrGi42S8fyEo LYTiOUchfE3iQ8jId9Nrkscad/Ogshsz4VMzMLbUYWrKeSyuHpxZEkCTRBAvN+PFh8Wx pY2Q== X-Gm-Message-State: AOJu0YyYjrKD4unpy02pNcidcYIRUirPXMlEvjrGXn0/n8jSIQkUVNfA KpCfPYc1rW4IGcq+FC/WJuHm3dBtFtCvWEA1inY= X-Received: by 2002:aa7:c607:0:b0:530:7abf:3a84 with SMTP id h7-20020aa7c607000000b005307abf3a84mr3026502edq.25.1696456592398; Wed, 04 Oct 2023 14:56:32 -0700 (PDT) MIME-Version: 1.0 References: <20231004204334.3465116-1-irogers@google.com> In-Reply-To: <20231004204334.3465116-1-irogers@google.com> From: Andrii Nakryiko Date: Wed, 4 Oct 2023 14:56:20 -0700 Message-ID: Subject: Re: [PATCH v3 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=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Wed, 04 Oct 2023 15:00:27 -0700 (PDT) On Wed, Oct 4, 2023 at 1:43=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 > Reviewed-by: Alan Maguire > --- > tools/bpf/bpftool/gen.c | 15 +++++++++------ > 1 file changed, 9 insertions(+), 6 deletions(-) > CI is not happy still, see [0] [0] https://github.com/kernel-patches/bpf/actions/runs/6411371996/job/174= 06696212 > 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.609.gbb76f46606-goog >