Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2856326rdb; Wed, 4 Oct 2023 13:44:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKRbkRm9RGIEp9sVHOzHsvCDQ2lB81Uljl2h+Eh5N1enRvf+wkQm8MeSzETjC9z2jO2OH3 X-Received: by 2002:a05:6a00:8c7:b0:68b:e710:ee9c with SMTP id s7-20020a056a0008c700b0068be710ee9cmr4004390pfu.19.1696452246563; Wed, 04 Oct 2023 13:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696452246; cv=none; d=google.com; s=arc-20160816; b=yJ7GZwcfSGMoZ7XLqgbo7rnGmtOq4q+sxoHb7FTwKOCuNe6hS+/g26ryykGEya1IDv 5W/nuXh5b0J6MewKlpGZknJMycDY6bJL2FhmZpa4PnJ1Fgp9TavmAgkSlrIKRshr0Xr/ KkQTqTVVw3ndUZQqYxZSv2ndVSiDCCEDicdKKygQrj1bQ+IDPDHEYPJafW3ycPh2mbzD ziefoM5qk5ZokqXxyJjo1zmoTxy9NL9Fp4U+dF1m+b4uKfRveXB3Lxbju0idXgmsBs9y rX1wKZIVjXU2+7peHGfbJXQBtP82Yg8bgVE1kUbpeQ8nzuWHeiy+gvGd7OvgTE8Su0fJ sTkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=raoMQ3SQ/7ZFelkz0l8EiT5sUCvEdkA2km5MKOLJhzo=; fh=sAc8qsB7gN4YPFOWZZIEDQsqTjBkL2wpGwblhGcbyBw=; b=Ni8pGZ9/O4aI4eXSVRdPOeQ2bQPDtorhXzjA9AhlPFHtYSJhDHNflsxi8havBOESA1 xk3THQGkFwxNngN5nJoG5bPf6o7yoHPJAspPxXA5XQadG3S3KHTlj9NSQiD+qRETsSb3 42Of1cUMn6dBN3GkEwGFPN9KTtHHJ7ffWHrrhNGZbszqFkWFFMNlJZCGoLMTN86TfdHU Gl27z4JBSjNqE9b+6GnknRNz6jzvatXyhGoHKDziYhlvt2OBouoam2uFtxt/fjpty8Rm k0UORdWUrcCBVLS0rQfX4bx62j8gsInpmlfGY/x3TeJxMYiO7TGjRxyx0yPAhcExXzpN Suuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZruWNVAf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id fb34-20020a056a002da200b0068fe12b361dsi4506024pfb.249.2023.10.04.13.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 13:44:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZruWNVAf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id A42A08213F28; Wed, 4 Oct 2023 13:44:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233557AbjJDUoE (ORCPT + 99 others); Wed, 4 Oct 2023 16:44:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243721AbjJDUn6 (ORCPT ); Wed, 4 Oct 2023 16:43:58 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D6B3D7 for ; Wed, 4 Oct 2023 13:43:55 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59f53027158so2739737b3.0 for ; Wed, 04 Oct 2023 13:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696452234; x=1697057034; darn=vger.kernel.org; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=raoMQ3SQ/7ZFelkz0l8EiT5sUCvEdkA2km5MKOLJhzo=; b=ZruWNVAfzd3QgvkZtWTdyvtnZEJ/B7pM4jN0z0HZxlWk+mwvz7456s9KFrrQPQRHOk LTa6ERqV72R5E/BXJd9g5pz14+Gc1jJWyG4+7MALIHuECmS5Bj/Hxr56ANyfylSrtbvF HIGw0U0HgxCYVKMufVSRhcadxW9hix1r3dcJvgEJQIfSRGQMbXp2UD2/Fdy5wNgarMMJ ozKLY9bQ7+GkT0uZGY9Ev62GIFzhcbVEIK8gFo6UQdgKGdplu3o2HFIOEui4gKPNOzGS yzY07PMQpHMRRB4hTi4xRSQr76P7N32kUaR9XM5pQkHa3j2SoqQzB1gPDGg64+HTspM1 Dgiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696452234; x=1697057034; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=raoMQ3SQ/7ZFelkz0l8EiT5sUCvEdkA2km5MKOLJhzo=; b=RWmEc/nmOJ9eiWPki3VOSGws4MdpCuBbnwnf5Y4KXwvP/LfBcZjbnNGSxJ1HiIc7mD 349Gy3hcHQMh4fyGfT8eMTHYgd/5CkbtlnE+rYuaereqXgtsnbQt8n50esC3aBOgYdyH gDJDNET3fPW0D38DzeZzEapYfk4l0n3KY/KX61UtcN7KpVh+5AQF2Sk+VaV74ZLpg0TE Ytq0QQh2B1sDYarT/OkXqZYS75VI9GCqYeCJmHIk3rMqAdDet7JtypIzq7MtFCyGt8jp ZHjNl08idbu4OqRnu83weH/4YNvIgRNbXzw7j+v088HxOUeF0YiGyaojYKQiQdZ/6Efb GlWQ== X-Gm-Message-State: AOJu0YzRv55S5FXiuOc7jNQqoNvDSKPaEwy5fQdPy4qPxdJWlHAyxI01 T9GUfVoR92Zl6SmI5jAhQrA68jQYdGjC X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:f42:a09e:8ee2:1491]) (user=irogers job=sendgmr) by 2002:a81:b3c3:0:b0:59b:f863:6f60 with SMTP id r186-20020a81b3c3000000b0059bf8636f60mr58579ywh.4.1696452234270; Wed, 04 Oct 2023 13:43:54 -0700 (PDT) Date: Wed, 4 Oct 2023 13:43:33 -0700 Message-Id: <20231004204334.3465116-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Subject: [PATCH v3 1/2] bpftool: Align output skeleton ELF code From: Ian Rogers To: 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 Cc: Ian Rogers , Alan Maguire Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 (snail.vger.email [0.0.0.0]); Wed, 04 Oct 2023 13:44:05 -0700 (PDT) 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 skeleton'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(-) 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 = (void *)%2$s__elf_bytes(&s->data_sz); \n\ + s->data = (void *)%1$s__elf_bytes(&s->data_sz); \n\ \n\ obj->skeleton = 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 = %1$d; \n\ - return (const void *)\"\\ \n\ - " - , file_sz, obj_name); + static const char data[] __attribute__((__aligned__(8))) = \"\\\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 = sizeof(data) - 1; \n\ + return (const void *)data; \n\ } \n\ \n\ #ifdef __cplusplus \n\ -- 2.42.0.609.gbb76f46606-goog