Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2166029rdb; Tue, 3 Oct 2023 12:16:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwt78DC1ZtxLaZeA+QDfIw1gh0sMc+K3JfRAnokujiRP9UK1rP8z6JKcSTiUDssd08aLoP X-Received: by 2002:a17:90a:d18e:b0:26b:698f:dda7 with SMTP id fu14-20020a17090ad18e00b0026b698fdda7mr268958pjb.32.1696360562796; Tue, 03 Oct 2023 12:16:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696360562; cv=none; d=google.com; s=arc-20160816; b=VXM4DkR5OSGsIXEIae5bhXPWJUfpx8McoIVFSBV7nBzbUqPEiXO4oVhaR05HTzGtX1 BGwrQ2VaCqsAc2bdBNqmS0ttKiz8JL0gU2lMazEqLMEQwaeb6pX4R+NwSBn2r7VKZC4O NbebMsgUWyJ7DpYFaXW3r968DYhrXVRPgR6o34dXYkw/6gDGT2h99TYP33RfaZq6wYyg A7rWK5LEnq0OrueTTOdn84Lo1f2gFhlFTZkaNfMfpvRGei/N8o6i6vc2MZ7bjHdbP33D acpPwtHw2iCANmw+e5TW1WQsMrbQd62d0lF41xgTJF89aq7Ez9HlPKcuJsp/Ls1n9fks 2XpA== 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=DJOW1cRndRnD6u1zoIC+jIQu2Yw55MSP06y/ktBFUbM=; fh=sAc8qsB7gN4YPFOWZZIEDQsqTjBkL2wpGwblhGcbyBw=; b=0JiR1M2rKezzLLKAOtbaWhu8WqxhSzs7ZGa0CYPqJ6fOQ8P8J4gWnSObwMNkK6e+T5 pRDYSE6fLqBSuqpw0LWpvxjqCa9BBlQBf4Y6Qk+c7i9+oaiWpxzlnNmu7uwIJwLml/SF X20+cS2HpsFPS1PUVk4CrCSLlRAhhGjYtu0aMSrMqf7Xf1RR+gN3xf2/396Ws4CNvtBy jn2F57H1kR+csCOL6/dBEfBdyBC2X543arZEV6Rsh0uz1zzCL4b5NMwU52w4ShpR6gub fx2OhPxwBFeAMza6XkiX+s/x5r96nUzFikIbWBBAnMJw/dXcNDJNdnf0E4i3SH84RnZR 9fwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yNyvNMbS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id o15-20020a170902d4cf00b001c1e4f9c63esi2289985plg.491.2023.10.03.12.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 12:16:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yNyvNMbS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 8D4D980873AA; Tue, 3 Oct 2023 12:15:24 -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 S240870AbjJCTPL (ORCPT + 99 others); Tue, 3 Oct 2023 15:15:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbjJCTPJ (ORCPT ); Tue, 3 Oct 2023 15:15:09 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E840C8E for ; Tue, 3 Oct 2023 12:15:06 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d816fa2404aso1573907276.0 for ; Tue, 03 Oct 2023 12:15:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696360506; x=1696965306; darn=vger.kernel.org; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=DJOW1cRndRnD6u1zoIC+jIQu2Yw55MSP06y/ktBFUbM=; b=yNyvNMbSL0y5xjTXnhme9KSZR05SSUpDq5O0ghbV21+Fx8LCrsRixX8ODc7jCv9jB8 Y8HZqIhN6GTh87Pzkx/1NC2BA8/fnHBtMTgLM27TdHSJugGQ1GmJZfJHVL9gpnDlM9r3 EFoXWrT3np/HMs4cfDdgfgX+mIBUKgcfJW5WDscfIkp58kRftvJEFVBzM1SexfqWuwyE 5P9ky4qOYNaDb3cLAF8mh4J0haQxXdT4lXXgT2AT3uch/anPsFqv4VzQJ9u3zmC/7g2W 8EwmEUQEsBH2BhqJbDmokvLYTlEbN3TZdI1m8lcmEaQCd/lpNy6fVQwyKI/bF3mw3xPJ 8wow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696360506; x=1696965306; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DJOW1cRndRnD6u1zoIC+jIQu2Yw55MSP06y/ktBFUbM=; b=FcXX5BI90l/xs+chxhZJfL6bEyYEC9USr4dqJTqTPQUFOGPKea57K63a34IlKC/xJo CVH0VE86jQbdPW0rUNy5dBBkND4N8tw4Si9Kb7Zc3i59oB3Oy7vN38dly6tkfhz6iXiR 3CCYguQr/9Afb3LXo6cilNLY/vsllZ7RqtomJLLXcFU0aBzTB0r0J6wILg5RnLZrBksj j3sWwpAcVpXtxhBkv8FGYmMwTPqwGs5C5RR77xB/eGvj39cK1c9QeXQBWIfGUy/INbRf E2fYB5ceF4ij4AfDQLkt3x8rnIImajfBMYOQYI1MYJgZD1Gq8aL8LBPcc4bD38p6pRdl tx/g== X-Gm-Message-State: AOJu0Yxxt2q3o7P11RcmABQrz7cN0pLtUd4X5rtN14+xmHBkH4alGyn0 ovHfLum5OT8rWfomzGGS6INRd3WOG0nN X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:51d:1f25:c2d8:4514]) (user=irogers job=sendgmr) by 2002:a25:db4b:0:b0:d77:bcce:eb11 with SMTP id g72-20020a25db4b000000b00d77bcceeb11mr2196ybf.10.1696360506122; Tue, 03 Oct 2023 12:15:06 -0700 (PDT) Date: Tue, 3 Oct 2023 12:14:11 -0700 Message-Id: <20231003191412.3171385-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Subject: [PATCH v2 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=-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 12:15:24 -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.582.g8ccd20d70d-goog