Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp16972rdb; Thu, 5 Oct 2023 15:03:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwEGq5CidRxZnjVLMurIgWLLB0b5daWJnRqnw2AxPY4dkiKci1K3V/Xqo1d7EMc5PPQgct X-Received: by 2002:a17:902:744b:b0:1c3:d9ed:a410 with SMTP id e11-20020a170902744b00b001c3d9eda410mr6321173plt.59.1696543428464; Thu, 05 Oct 2023 15:03:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696543428; cv=none; d=google.com; s=arc-20160816; b=NIzutE0eA1rrjIPzb+AkO31v/VLGNDySbUCkjWwu3EyKjw6rOO6plI37d85YknEZ3I sjVixV6nRzzxFTBXGkhHAabVmEGyq4DqhJRofnCrVzIETG03GGqWkDOSQzEuNoKkLl2J Sv+ew4AbyY9xOBKTA5OvtgERO+NKhr+UiLUKbZpsotmNIQgPB3L5YsQmGeFAce7cZxlx eXjGfoEgp1eLaE/xzdKXk4gOAdQSXeFLStxIOmFRJTaKXoLE7zqe2+s74wV6AwYcQiaE XWiMhysZUjB8OsvxG7WnkIFZ/fbSCq6h3PplOiQJk0mBfmEtlLvJJyBx+2tYRQAfIuZJ zqAw== 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=l3o6wyBSROZp99HOssTXqpXKVsTtNmt9jgf0aZMxwy0=; fh=sAc8qsB7gN4YPFOWZZIEDQsqTjBkL2wpGwblhGcbyBw=; b=jUMfHy5Kh3D8AbEeMWnsOpOEWzGD7OVR8AjNaqoUxQGxWnwFIIyC78VnY9sxoEbw0T 4UVjCphapCXndjS4Fyx0EWm+e3m4S1lgk5BwQ7xMJJYd+akd3WuH9qfr1ZoFpYs7nMVs h8ia0J5L4fFyUcGmz3RciTngE4ohmFhUCFnEK3ufEgaDL84w/EASaZQbvObmv0W+cQL7 WuyuSN0Q37I2M0hKS4H9m2GtcmWpfp+UNIhTcDfXhvT+dyOyHh44czD2ewsEWyrRtpMx aqnLzSLvgwglRcpYvo5+7MRQ7y4959wAHIXT2dhwJdGIAtMuxwSJtVy0rNXBNTmPrdaW WOwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="hbw1RH/r"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id z2-20020a1709027e8200b001bbcddd6e82si2372996pla.91.2023.10.05.15.03.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 15:03:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="hbw1RH/r"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 4A6258082932; Thu, 5 Oct 2023 15:03:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231890AbjJEWDb (ORCPT + 99 others); Thu, 5 Oct 2023 18:03:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbjJEWDa (ORCPT ); Thu, 5 Oct 2023 18:03:30 -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 5318FD8 for ; Thu, 5 Oct 2023 15:03:29 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d816fa2404aso2060727276.0 for ; Thu, 05 Oct 2023 15:03:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696543408; x=1697148208; darn=vger.kernel.org; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=l3o6wyBSROZp99HOssTXqpXKVsTtNmt9jgf0aZMxwy0=; b=hbw1RH/rDSDbT8w7/RCxWggqTGsq2S5bgAEQ27PmhmbHFtuQ+/zb3EtJB9p6sIbf/o K6XKaIHZ6lksGCZnnuuPIc47XUl2jZBmuLFqmoaJAkEGy2OtlSmInG/OiVAfoWyAzFs/ B6b4LktvD+4Msv8u0ij8yqEcgHJpvr5SOr20Yz2xaDQHIPsHoF9MyDpAfmFzUJMWiMqz jnbSeLm0AmsyTB9037GyffjDy9Fu4wAfTi0zW/VjBs4FlD4fmuKbi5rgrywINne650oO 6ePP8B823zkmdiNmtCZCmAUEG3tooHIgb2SveK6GaiJaJFveY1ju0XQnuE2C+YlVfJnb oaTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696543408; x=1697148208; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=l3o6wyBSROZp99HOssTXqpXKVsTtNmt9jgf0aZMxwy0=; b=JtaShxpUb22AzVZW8uIxRlGzHQMPsNNtmtXCY7hDMUQnDWzix81r8ygmrsSLLBcoly 0PjSN6+nSwfbUpoZWELceygtxuOmkHNhKZpiozpXyCYsZyo4K3MoRZMrLmdU+D2T1TLB 0srCBkGmu4w7Ex2cDxjQsAMzfVGeslHTbk580fgt25PhssJeeGoEFxcGAw00dcQH4q8I VMg9GMurDBNLEd4yfCskYfERw16y35uPSJRwLqydrYj0bHrrQfRD/O/Hw0YacO8vbjXF rO+pu6PeeGKaJXClPhfcraNGoFj8flR4I7fJadz9PXzTP/ivl7/LVUne2tMD2/Cx0ROW DrnQ== X-Gm-Message-State: AOJu0Yw6/JJvn3DPcOIgEij7dpOCnQt6pZG2OQiWrxxY/Mxy2gunDE7F YeD6vXgJeYdNoVEJs8uC8rAo5Q9/Nele X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7449:56a1:2b14:305b]) (user=irogers job=sendgmr) by 2002:a05:6902:1603:b0:d7a:bfcf:2d7 with SMTP id bw3-20020a056902160300b00d7abfcf02d7mr100869ybb.6.1696543408563; Thu, 05 Oct 2023 15:03:28 -0700 (PDT) Date: Thu, 5 Oct 2023 15:03:23 -0700 Message-Id: <20231005220324.3635499-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Subject: [PATCH v5 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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 05 Oct 2023 15:03:45 -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 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 = (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