From nobody Fri Oct 10 09:14:53 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4379C1D63E6; Sat, 14 Jun 2025 04:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749876222; cv=none; b=HhCvprfM4oVQK5vABZZcZzM9N7nzSHAfeiY6GHXRdPeqAu3xWOUYGrnowouLSR5DnILg0zJhmHs5o4TlIJaqmlsujwP3xZmvwI92ZycpnQehr00tzpxzkKAG5nxKkx795ESqWIbe6N7q4MHp1bhmNgSJKMREItgFqd+1H/ycU8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749876222; c=relaxed/simple; bh=zbn/JoysdxR8uLVh95IpmjoYIROjf0TIXjX/YPElpHc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OZG+6gxzmP1t0Urb/pVG6FtcTW60zFr8Rpro8NRbzf7CEib99osRVigtuf4Z8eUf0kNPubliDrn+3IZz/Fqkz4RiVVdl/k38FSSTLYvH62DU/bXwjBUfLy/3qTUZ1z3acXIJ5nRme5+8pOEvsnTVnqMOmJVjn1PijU7M5qIoAqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Su+TxGM0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Su+TxGM0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54C2BC4CEF2; Sat, 14 Jun 2025 04:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749876221; bh=zbn/JoysdxR8uLVh95IpmjoYIROjf0TIXjX/YPElpHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Su+TxGM0jzJBOvSCiCV1dN0/bW/3ptJlu3FRSKj34h+soSxa+ut96NjR+HyT0qjX+ oKBw4kaCGeOuM+UDRoURQ0hn0Gnv2f5ghYJ9grmhkf+L48K1HzJtDMmGs6HZ6yvGQ4 qBS5SjU0C5zST6rsboOuWDc0wQyWJtbEFKf3yFd06LAkA0ODYE0Z5YcqA0d1qAfi5n EOa8r95tsRLMtxAtKSbVr0EyIc6Ljj8IJSLNJEPuahi0wOHjytD8SMZg8xoY5SJnVu cnOW33WGfH4wyB/CjARqEljUGeDMGYAqzIvLgwUE2CPOXcMh3AH6wzs03MapILf6Zq Xnr9F3DwO4yrA== From: Eric Biggers To: linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Liang Kan , Yuzhuo Jing Subject: [PATCH v2 1/4] perf build: enable -fno-strict-aliasing Date: Fri, 13 Jun 2025 21:41:30 -0700 Message-ID: <20250614044133.660848-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250614044133.660848-1-ebiggers@kernel.org> References: <20250614044133.660848-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Eric Biggers perf pulls in code from kernel headers that assumes it is being built with -fno-strict-aliasing, namely put_unaligned_*() from which write the data using packed structs that lack the may_alias attribute. Enable -fno-strict-aliasing to prevent miscompilations in sha1.c which would otherwise occur due to this issue. Signed-off-by: Eric Biggers --- tools/perf/Makefile.config | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index d1ea7bf449647..1691b47c4694c 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -17,10 +17,14 @@ detected =3D $(shell echo "$(1)=3Dy" >> $(OUT= PUT).config-detected) detected_var =3D $(shell echo "$(1)=3D$($(1))" >> $(OUTPUT).config-detecte= d) =20 CFLAGS :=3D $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS= )) HOSTCFLAGS :=3D $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) =20 +# This is required because the kernel is built with this and some of the c= ode +# borrowed from kernel headers depends on it, e.g. put_unaligned_*(). +CFLAGS +=3D -fno-strict-aliasing + # Enabled Wthread-safety analysis for clang builds. ifeq ($(CC_NO_CLANG), 0) CFLAGS +=3D -Wthread-safety endif =20 --=20 2.49.0 From nobody Fri Oct 10 09:14:53 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE15B1DB34C; Sat, 14 Jun 2025 04:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749876222; cv=none; b=UVsbLgam95nS1jPxEF9ObbGXImv3p5T/YDKTczJ75BcTrYcPSHD2M9x7iHWBYWLsXhMan4ACR2Up3KdvwquzZrsMo3Yu2bDBR2RAd83vyR2KFtp0NzVzgCOtMXe7IiAHdbXajf3aP/NYRTtpjLhqWN6iATJ4y04rqpmNa6D24Io= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749876222; c=relaxed/simple; bh=XWM1WaX+3CfBo6u1run2aG12LlI84dO1mmNRDBD3/yw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G6cqQVVRljehaseHvw6M2WzU+CZcPntxUZVkypvJGduOTRSTqrlsxL/Zcf06Wa1z+kAVoFkxlMvNQFxWfG9h9YrlmkP5CXYLdNc3mqzu11sim0LdUHHnEdJPkt8Wsc0e/jvOSoE4mtO0u2hxUt9arlyBzkAv3wqazjLCTelF9Wg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Uyd1h/VG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Uyd1h/VG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D267CC4CEF5; Sat, 14 Jun 2025 04:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749876222; bh=XWM1WaX+3CfBo6u1run2aG12LlI84dO1mmNRDBD3/yw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uyd1h/VG8nqKfmg02bT6AxH0Sv2nOwGHu3CAXPrZvDvijKmbEyGxxc4arA/LWsyBU io9bNYzfVGKyxk4Zc3E5exaS4nYl7enwAHsLZBACotERySrO2CNQK8hZ6lyWtrGD+m 0Sb9dRj3xm7ges/2HENzTK+wKt/mCeFyeOYf+5og4VybV7MLCirbpGpIwMADmGe3VT Ay1gWgwQ1TqZW9d7Xot+X34D7Qk4k7RECcKSmAxAjQO6gp244W+DHduDJTFGvYDIjq aqofQUUWhyqgIvUV7lQSDy+mghpr9wx99O82KLwa9xSeLKNLoVUCIrzBtz4oD9A1rn ijqH9hthdVACw== From: Eric Biggers To: linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Liang Kan , Yuzhuo Jing Subject: [PATCH v2 2/4] perf util: add a basic SHA-1 implementation Date: Fri, 13 Jun 2025 21:41:31 -0700 Message-ID: <20250614044133.660848-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250614044133.660848-1-ebiggers@kernel.org> References: <20250614044133.660848-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Eric Biggers SHA-1 can be written in fewer than 100 lines of code. Just add a basic SHA-1 implementation so that there's no need to use an external library or try to pull in the kernel's SHA-1 implementation. The kernel's SHA-1 implementation is not really intended to be pulled into userspace programs in the way that it was proposed to do so for perf (https://lore.kernel.org/r/20250521225307.743726-3-yuzhuo@google.com/), and it's also likely to undergo some refactoring in the future. There's no need to tie userspace tools to it. Include a test for sha1() in the util test suite. Signed-off-by: Eric Biggers --- tools/perf/tests/util.c | 45 ++++++++++++++++++- tools/perf/util/Build | 1 + tools/perf/util/sha1.c | 97 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/sha1.h | 6 +++ 4 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 tools/perf/util/sha1.c create mode 100644 tools/perf/util/sha1.h diff --git a/tools/perf/tests/util.c b/tools/perf/tests/util.c index 6366db5cbf8ce..b273d287e1649 100644 --- a/tools/perf/tests/util.c +++ b/tools/perf/tests/util.c @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 #include "tests.h" #include "util/debug.h" +#include "util/sha1.h" =20 #include #include #include =20 @@ -14,18 +15,60 @@ static int test_strreplace(char needle, const char *hay= stack, =20 free(new); return ret =3D=3D 0; } =20 +#define MAX_LEN 512 + +/* Test sha1() for all lengths from 0 to MAX_LEN inclusively. */ +static int test_sha1(void) +{ + u8 data[MAX_LEN]; + size_t digests_size =3D (MAX_LEN + 1) * SHA1_DIGEST_SIZE; + u8 *digests; + u8 digest_of_digests[SHA1_DIGEST_SIZE]; + /* + * The correctness of this value was verified by running this test with + * sha1() replaced by OpenSSL's SHA1(). + */ + static const u8 expected_digest_of_digests[SHA1_DIGEST_SIZE] =3D { + 0x74, 0xcd, 0x4c, 0xb9, 0xd8, 0xa6, 0xd5, 0x95, 0x22, 0x8b, + 0x7e, 0xd6, 0x8b, 0x7e, 0x46, 0x95, 0x31, 0x9b, 0xa2, 0x43, + }; + size_t i; + + digests =3D malloc(digests_size); + TEST_ASSERT_VAL("failed to allocate digests", digests !=3D NULL); + + /* Generate MAX_LEN bytes of data. */ + for (i =3D 0; i < MAX_LEN; i++) + data[i] =3D i; + + /* Calculate a SHA-1 for each length 0 through MAX_LEN inclusively. */ + for (i =3D 0; i <=3D MAX_LEN; i++) + sha1(data, i, &digests[i * SHA1_DIGEST_SIZE]); + + /* Calculate digest of all digests calculated above. */ + sha1(digests, digests_size, digest_of_digests); + + free(digests); + + /* Check for the expected result. */ + TEST_ASSERT_VAL("wrong output from sha1()", + memcmp(digest_of_digests, expected_digest_of_digests, + SHA1_DIGEST_SIZE) =3D=3D 0); + return 0; +} + static int test__util(struct test_suite *t __maybe_unused, int subtest __m= aybe_unused) { TEST_ASSERT_VAL("empty string", test_strreplace(' ', "", "123", "")); TEST_ASSERT_VAL("no match", test_strreplace('5', "123", "4", "123")); TEST_ASSERT_VAL("replace 1", test_strreplace('3', "123", "4", "124")); TEST_ASSERT_VAL("replace 2", test_strreplace('a', "abcabc", "ef", "efbcef= bc")); TEST_ASSERT_VAL("replace long", test_strreplace('a', "abcabc", "longlong", "longlongbclonglongbc")); =20 - return 0; + return test_sha1(); } =20 DEFINE_SUITE("util", util); diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 7910d908c814f..70b6c5f045472 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -39,10 +39,11 @@ perf-util-y +=3D rlimit.o perf-util-y +=3D argv_split.o perf-util-y +=3D rbtree.o perf-util-y +=3D libstring.o perf-util-y +=3D bitmap.o perf-util-y +=3D hweight.o +perf-util-y +=3D sha1.o perf-util-y +=3D smt.o perf-util-y +=3D strbuf.o perf-util-y +=3D string.o perf-util-y +=3D strlist.o perf-util-y +=3D strfilter.o diff --git a/tools/perf/util/sha1.c b/tools/perf/util/sha1.c new file mode 100644 index 0000000000000..ec2411434059f --- /dev/null +++ b/tools/perf/util/sha1.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * SHA-1 message digest algorithm + * + * Copyright 2025 Google LLC + */ +#include +#include +#include +#include + +#include "sha1.h" + +#define SHA1_BLOCK_SIZE 64 + +static const u32 sha1_K[4] =3D { 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA6= 2C1D6 }; + +#define SHA1_ROUND(i, a, b, c, d, e) \ + do { \ + if ((i) >=3D 16) \ + w[i] =3D rol32(w[((i) - 16)] ^ w[((i) - 14)] ^ \ + w[((i) - 8)] ^ w[((i) - 3)], \ + 1); \ + e +=3D w[i] + rol32(a, 5) + sha1_K[(i) / 20]; \ + if ((i) < 20) \ + e +=3D (b & (c ^ d)) ^ d; \ + else if ((i) < 40 || (i) >=3D 60) \ + e +=3D b ^ c ^ d; \ + else \ + e +=3D (c & d) ^ (b & (c ^ d)); \ + b =3D rol32(b, 30); \ + /* The new (a, b, c, d, e) is the old (e, a, b, c, d). */ \ + } while (0) + +#define SHA1_5ROUNDS(i) \ + do { \ + SHA1_ROUND((i) + 0, a, b, c, d, e); \ + SHA1_ROUND((i) + 1, e, a, b, c, d); \ + SHA1_ROUND((i) + 2, d, e, a, b, c); \ + SHA1_ROUND((i) + 3, c, d, e, a, b); \ + SHA1_ROUND((i) + 4, b, c, d, e, a); \ + } while (0) + +#define SHA1_20ROUNDS(i) \ + do { \ + SHA1_5ROUNDS((i) + 0); \ + SHA1_5ROUNDS((i) + 5); \ + SHA1_5ROUNDS((i) + 10); \ + SHA1_5ROUNDS((i) + 15); \ + } while (0) + +static void sha1_blocks(u32 h[5], const u8 *data, size_t nblocks) +{ + while (nblocks--) { + u32 a =3D h[0]; + u32 b =3D h[1]; + u32 c =3D h[2]; + u32 d =3D h[3]; + u32 e =3D h[4]; + u32 w[80]; + + for (int i =3D 0; i < 16; i++) + w[i] =3D get_unaligned_be32(&data[i * 4]); + SHA1_20ROUNDS(0); + SHA1_20ROUNDS(20); + SHA1_20ROUNDS(40); + SHA1_20ROUNDS(60); + + h[0] +=3D a; + h[1] +=3D b; + h[2] +=3D c; + h[3] +=3D d; + h[4] +=3D e; + data +=3D SHA1_BLOCK_SIZE; + } +} + +/* Calculate the SHA-1 message digest of the given data. */ +void sha1(const void *data, size_t len, u8 out[SHA1_DIGEST_SIZE]) +{ + u32 h[5] =3D { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, + 0xC3D2E1F0 }; + u8 final_data[2 * SHA1_BLOCK_SIZE] =3D { 0 }; + size_t final_len =3D len % SHA1_BLOCK_SIZE; + + sha1_blocks(h, data, len / SHA1_BLOCK_SIZE); + + memcpy(final_data, data + len - final_len, final_len); + final_data[final_len] =3D 0x80; + final_len =3D round_up(final_len + 9, SHA1_BLOCK_SIZE); + put_unaligned_be64((u64)len * 8, &final_data[final_len - 8]); + + sha1_blocks(h, final_data, final_len / SHA1_BLOCK_SIZE); + + for (int i =3D 0; i < 5; i++) + put_unaligned_be32(h[i], &out[i * 4]); +} diff --git a/tools/perf/util/sha1.h b/tools/perf/util/sha1.h new file mode 100644 index 0000000000000..e92c9966e1d50 --- /dev/null +++ b/tools/perf/util/sha1.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include + +#define SHA1_DIGEST_SIZE 20 + +void sha1(const void *data, size_t len, u8 out[SHA1_DIGEST_SIZE]); --=20 2.49.0 From nobody Fri Oct 10 09:14:53 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBCB01DBB3A; Sat, 14 Jun 2025 04:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749876222; cv=none; b=TTRn/G7xE5/poNyTtyW4RLeXipB1H6Pr5Hgh44nkVSo9lF5vIImrK7KIhq4xdp+lOjfOyhaULwfSQ8UBZ5PbEZsRPSUeuAel9xXgxJTLO+uOdYXye1ts7OuIsNTLhiwIWACzqyHt+HxFtX79VoPa+6yQUaFpwiADN0fzLCSQqrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749876222; c=relaxed/simple; bh=dzshMKCTThoIISZ/hbu/5/BBKFX5VGz2/btDz3gC8bA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=odlAypuY1EdIQ8VxSTlYMMtz1n69OL5uur//4TdwUnovHINVnMujRnuC6reTRKVT6D7Qdx5ObNgy2tXQQ3MOGJ4BUsExqxCcvvqdd/uGUoKuyC0xc1thfRvCc3u4bM/1YMOdX6ZLfy5AMfpjuW2YLNjQ7WhmCch30+cXJVjN9UI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n9mqhlcg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="n9mqhlcg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CA9FC4CEF8; Sat, 14 Jun 2025 04:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749876222; bh=dzshMKCTThoIISZ/hbu/5/BBKFX5VGz2/btDz3gC8bA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n9mqhlcgqqSJJxw8lyV44X97bY2fgediJIjgbdc8ZgQlIdrI0ar8mCXnB5Yf7k1vZ 6Fp5b92ZjMP7cw9wAKIkhiKj/JqGWUwg6rQ3ZMb8/qjIxLv6FEDRcnFCSInM8Ksnma wfh1+MHISROEmHr/TRLlwTSbWGt2od6jz48i8+M/7C8IRIzks1ywALtwVl4L8smSnD GRje3t8CyuONwyfT6anRVI6ICB78Fq1B7JXfKfaVju5QjgLeRe+rdqfRV37LLkNFIU CKjXkBu+YG13bIYp66ZyVLMquIPhdLvSc92BgLQB2bMJkYTN5gcpuB6JSoGj0a2LPv qW1e4xWMbtOiw== From: Eric Biggers To: linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Liang Kan , Yuzhuo Jing Subject: [PATCH v2 3/4] perf genelf: Remove libcrypto dependency and use built-in sha1() Date: Fri, 13 Jun 2025 21:41:32 -0700 Message-ID: <20250614044133.660848-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250614044133.660848-1-ebiggers@kernel.org> References: <20250614044133.660848-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yuzhuo Jing genelf is the only file in perf that depends on libcrypto (or openssl) which only calculates a Build ID (SHA1, MD5, or URANDOM). SHA1 was expected to be the default option, but MD5 was used by default due to previous issues when linking against Java. This commit switches genelf to use the in-house sha1(), and also removes MD5 and URANDOM options since we have a reliable SHA1 implementation to rely on. It passes the tools/perf/tests/shell/test_java_symbol.sh test. Signed-off-by: Yuzhuo Jing Co-developed-by: Eric Biggers Signed-off-by: Eric Biggers --- tools/perf/util/genelf.c | 85 ++-------------------------------------- 1 file changed, 3 insertions(+), 82 deletions(-) diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c index cdce7f173d00a..fcf86a27f69e1 100644 --- a/tools/perf/util/genelf.c +++ b/tools/perf/util/genelf.c @@ -10,45 +10,25 @@ #include #include #include #include #include -#include #include -#include #include #ifdef HAVE_LIBDW_SUPPORT #include #endif =20 #include "genelf.h" +#include "sha1.h" #include "../util/jitdump.h" #include =20 #ifndef NT_GNU_BUILD_ID #define NT_GNU_BUILD_ID 3 #endif =20 -#define BUILD_ID_URANDOM /* different uuid for each run */ - -#ifdef HAVE_LIBCRYPTO_SUPPORT - -#define BUILD_ID_MD5 -#undef BUILD_ID_SHA /* does not seem to work well when linked with Java */ -#undef BUILD_ID_URANDOM /* different uuid for each run */ - -#ifdef BUILD_ID_SHA -#include -#endif - -#ifdef BUILD_ID_MD5 -#include -#include -#endif -#endif - - typedef struct { unsigned int namesz; /* Size of entry's owner string */ unsigned int descsz; /* Size of the note descriptor */ unsigned int type; /* Interpretation of the descriptor */ char name[0]; /* Start of the name+desc data */ @@ -69,11 +49,11 @@ static char shd_string_table[] =3D { }; =20 static struct buildid_note { Elf_Note desc; /* descsz: size of build-id, must be multiple of 4 */ char name[4]; /* GNU\0 */ - char build_id[20]; + u8 build_id[SHA1_DIGEST_SIZE]; } bnote; =20 static Elf_Sym symtab[]=3D{ /* symbol 0 MUST be the undefined symbol */ { .st_name =3D 0, /* index in sym_string table */ @@ -90,69 +70,10 @@ static Elf_Sym symtab[]=3D{ .st_other =3D ELF_ST_VIS(STV_DEFAULT), .st_size =3D 0, /* for now */ } }; =20 -#ifdef BUILD_ID_URANDOM -static void -gen_build_id(struct buildid_note *note, - unsigned long load_addr __maybe_unused, - const void *code __maybe_unused, - size_t csize __maybe_unused) -{ - int fd; - size_t sz =3D sizeof(note->build_id); - ssize_t sret; - - fd =3D open("/dev/urandom", O_RDONLY); - if (fd =3D=3D -1) - err(1, "cannot access /dev/urandom for buildid"); - - sret =3D read(fd, note->build_id, sz); - - close(fd); - - if (sret !=3D (ssize_t)sz) - memset(note->build_id, 0, sz); -} -#endif - -#ifdef BUILD_ID_SHA -static void -gen_build_id(struct buildid_note *note, - unsigned long load_addr __maybe_unused, - const void *code, - size_t csize) -{ - if (sizeof(note->build_id) < SHA_DIGEST_LENGTH) - errx(1, "build_id too small for SHA1"); - - SHA1(code, csize, (unsigned char *)note->build_id); -} -#endif - -#ifdef BUILD_ID_MD5 -static void -gen_build_id(struct buildid_note *note, unsigned long load_addr, const voi= d *code, size_t csize) -{ - EVP_MD_CTX *mdctx; - - if (sizeof(note->build_id) < 16) - errx(1, "build_id too small for MD5"); - - mdctx =3D EVP_MD_CTX_new(); - if (!mdctx) - errx(2, "failed to create EVP_MD_CTX"); - - EVP_DigestInit_ex(mdctx, EVP_md5(), NULL); - EVP_DigestUpdate(mdctx, &load_addr, sizeof(load_addr)); - EVP_DigestUpdate(mdctx, code, csize); - EVP_DigestFinal_ex(mdctx, (unsigned char *)note->build_id, NULL); - EVP_MD_CTX_free(mdctx); -} -#endif - static int jit_add_eh_frame_info(Elf *e, void* unwinding, uint64_t unwinding_header_s= ize, uint64_t unwinding_size, uint64_t base_offset) { Elf_Data *d; @@ -471,11 +392,11 @@ jit_write_elf(int fd, uint64_t load_addr, const char = *sym, } =20 /* * build-id generation */ - gen_build_id(&bnote, load_addr, code, csize); + sha1(code, csize, bnote.build_id); bnote.desc.namesz =3D sizeof(bnote.name); /* must include 0 termination */ bnote.desc.descsz =3D sizeof(bnote.build_id); bnote.desc.type =3D NT_GNU_BUILD_ID; strcpy(bnote.name, "GNU"); =20 --=20 2.49.0 From nobody Fri Oct 10 09:14:53 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD02D1DED5D; Sat, 14 Jun 2025 04:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749876223; cv=none; b=FbO8m4IFmS1IO/7/HDEs5a90bjZF4SQLPrJ6cVNUO73psxB1wIo2GjaTLanR2kFuTklF8vA3yFayFa4GIXmZTnGx58k49xRd1t8pmsrfbhY5ZTNt9wyNi/wAFrV+mlulGo9P0tL++cxa94d3VM0vJvoTT0aYZPSvyxixO35ixr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749876223; c=relaxed/simple; bh=DFaxT6+s/Nle/3us53Y5IO+wxfnupBIhNM8NsGHK2Ek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=szbycR2Ft8uhJMbuhr9rF1annLnaA0/rp3SIIvRjzLGM6tUUuM+vVA3vaX892FtWehDin69NOcgxNQpXzdjMgQLPoqLUHZg1b6Uyxw8S6q6u18V7/I2wMghi8PvYv3PSmktVfQ4W4cyT4nLb7JNIiZrRQ3p8nsBIYwSBiVvumdY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lZ2/ELd0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lZ2/ELd0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA3C3C4CEF1; Sat, 14 Jun 2025 04:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749876223; bh=DFaxT6+s/Nle/3us53Y5IO+wxfnupBIhNM8NsGHK2Ek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZ2/ELd0OWqTLEr7PsuRVrKG/e/JQKH3vZvMUYOWUzCZfAFX7LluuePQbm/4Bq8N9 jyn4IwN31i066uWSd86e+naJ782oLKITHZJyIKfHwXgCHeiJXldVPAlVbpMjEZxMVv e24mvwW/GECimx52BgLhH2p/UXsOKq6wx7yVHKarn2VT1sLcygSTYUw8dAlbBCK0HF RRNcl6tlrbV0YRjynMPBCDgSyO7pTGDtBa+3yn1K1dwZEyRPZDLDcnx6vaOQFBDkuP AeOi9Ig6w9P4af0LEGUmu+r4clLTUSTuaFgCXJgSrMR1SgW1g9Zxktg6b4bgL5rghO g06jIgsxYYXrQ== From: Eric Biggers To: linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Liang Kan , Yuzhuo Jing Subject: [PATCH v2 4/4] tools: Remove libcrypto dependency Date: Fri, 13 Jun 2025 21:41:33 -0700 Message-ID: <20250614044133.660848-5-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250614044133.660848-1-ebiggers@kernel.org> References: <20250614044133.660848-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yuzhuo Jing Remove all occurrence of libcrypto in the build system. Signed-off-by: Yuzhuo Jing Signed-off-by: Eric Biggers --- tools/build/Makefile.feature | 2 -- tools/build/feature/Makefile | 4 ---- tools/build/feature/test-all.c | 5 ----- tools/build/feature/test-libcrypto.c | 25 ------------------------- tools/perf/Documentation/perf-check.txt | 1 - tools/perf/Makefile.config | 13 ------------- tools/perf/Makefile.perf | 3 --- tools/perf/builtin-check.c | 1 - tools/perf/tests/make | 4 +--- 9 files changed, 1 insertion(+), 57 deletions(-) delete mode 100644 tools/build/feature/test-libcrypto.c diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 57bd995ce6afa..bbadfb5568ebe 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -84,11 +84,10 @@ FEATURE_TESTS_BASIC :=3D \ libpython \ libslang \ libtraceevent \ libtracefs \ libcpupower \ - libcrypto \ pthread-attr-setaffinity-np \ pthread-barrier \ reallocarray \ stackprotector-all \ timerfd \ @@ -150,11 +149,10 @@ FEATURE_DISPLAY ?=3D \ libelf \ libnuma \ numa_num_possible_cpus \ libperl \ libpython \ - libcrypto \ libcapstone \ llvm-perf \ zlib \ lzma \ get_cpuid \ diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index b8b5fb183dd40..04a4aa0341aae 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -36,11 +36,10 @@ FILES=3D \ test-libslang.bin \ test-libslang-include-subdir.bin \ test-libtraceevent.bin \ test-libcpupower.bin \ test-libtracefs.bin \ - test-libcrypto.bin \ test-libunwind.bin \ test-libunwind-debug-frame.bin \ test-libunwind-x86.bin \ test-libunwind-x86_64.bin \ test-libunwind-arm.bin \ @@ -244,13 +243,10 @@ $(OUTPUT)test-libcpupower.bin: $(BUILD) -lcpupower =20 $(OUTPUT)test-libtracefs.bin: $(BUILD) $(shell $(PKG_CONFIG) --cflags libtracefs 2>/dev/null) -ltracefs =20 -$(OUTPUT)test-libcrypto.bin: - $(BUILD) -lcrypto - $(OUTPUT)test-gtk2.bin: $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) -Wno= -deprecated-declarations =20 $(OUTPUT)test-gtk2-infobar.bin: $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c index 03ddaac6f4c4d..ce72e2061ac0a 100644 --- a/tools/build/feature/test-all.c +++ b/tools/build/feature/test-all.c @@ -136,14 +136,10 @@ =20 #define main main_test_bpf # include "test-bpf.c" #undef main =20 -#define main main_test_libcrypto -# include "test-libcrypto.c" -#undef main - #define main main_test_sdt # include "test-sdt.c" #undef main =20 #define main main_test_setns @@ -204,11 +200,10 @@ int main(int argc, char *argv[]) main_test_pthread_attr_setaffinity_np(); main_test_pthread_barrier(); main_test_lzma(); main_test_get_cpuid(); main_test_bpf(); - main_test_libcrypto(); main_test_scandirat(); main_test_sched_getcpu(); main_test_sdt(); main_test_setns(); main_test_libaio(); diff --git a/tools/build/feature/test-libcrypto.c b/tools/build/feature/tes= t-libcrypto.c deleted file mode 100644 index bc34a5bbb5049..0000000000000 --- a/tools/build/feature/test-libcrypto.c +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include -#include -#include - -int main(void) -{ - EVP_MD_CTX *mdctx; - unsigned char md[MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH]; - unsigned char dat[] =3D "12345"; - unsigned int digest_len; - - mdctx =3D EVP_MD_CTX_new(); - if (!mdctx) - return 0; - - EVP_DigestInit_ex(mdctx, EVP_md5(), NULL); - EVP_DigestUpdate(mdctx, &dat[0], sizeof(dat)); - EVP_DigestFinal_ex(mdctx, &md[0], &digest_len); - EVP_MD_CTX_free(mdctx); - - SHA1(&dat[0], sizeof(dat), &md[0]); - - return 0; -} diff --git a/tools/perf/Documentation/perf-check.txt b/tools/perf/Documenta= tion/perf-check.txt index a764a46292206..2b96cb5786581 100644 --- a/tools/perf/Documentation/perf-check.txt +++ b/tools/perf/Documentation/perf-check.txt @@ -51,11 +51,10 @@ feature:: dwarf_getlocations / HAVE_LIBDW_SUPPORT dwarf-unwind / HAVE_DWARF_UNWIND_SUPPORT auxtrace / HAVE_AUXTRACE_SUPPORT libbfd / HAVE_LIBBFD_SUPPORT libcapstone / HAVE_LIBCAPSTONE_SUPPORT - libcrypto / HAVE_LIBCRYPTO_SUPPORT libdw-dwarf-unwind / HAVE_LIBDW_SUPPORT libelf / HAVE_LIBELF_SUPPORT libnuma / HAVE_LIBNUMA_SUPPORT libopencsd / HAVE_CSTRACE_SUPPORT libperl / HAVE_LIBPERL_SUPPORT diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 1691b47c4694c..376929c15b989 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -132,12 +132,10 @@ ifndef NO_LIBUNWIND FEATURE_CHECK_LDFLAGS-libunwind-aarch64 +=3D -lunwind -lunwind-aarch64 FEATURE_CHECK_LDFLAGS-libunwind-x86 +=3D -lunwind -llzma -lunwind-x86 FEATURE_CHECK_LDFLAGS-libunwind-x86_64 +=3D -lunwind -llzma -lunwind-x86= _64 endif =20 -FEATURE_CHECK_LDFLAGS-libcrypto =3D -lcrypto - ifdef CSINCLUDES LIBOPENCSD_CFLAGS :=3D -I$(CSINCLUDES) endif OPENCSDLIBS :=3D -lopencsd_c_api -lopencsd ifeq ($(findstring -static,${LDFLAGS}),-static) @@ -774,21 +772,10 @@ endif =20 ifneq ($(NO_LIBTRACEEVENT),1) $(call detected,CONFIG_TRACE) endif =20 -ifndef NO_LIBCRYPTO - ifneq ($(feature-libcrypto), 1) - $(warning No libcrypto.h found, disables jitted code injection, please= install openssl-devel or libssl-dev) - NO_LIBCRYPTO :=3D 1 - else - CFLAGS +=3D -DHAVE_LIBCRYPTO_SUPPORT - EXTLIBS +=3D -lcrypto - $(call detected,CONFIG_CRYPTO) - endif -endif - ifndef NO_SLANG ifneq ($(feature-libslang), 1) ifneq ($(feature-libslang-include-subdir), 1) $(warning slang not found, disables TUI support. Please install slan= g-devel, libslang-dev or libslang2-dev) NO_SLANG :=3D 1 diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index d4c7031b01a77..9246c94656e03 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -59,13 +59,10 @@ include ../scripts/utilities.mak # # Define NO_LIBNUMA if you do not want numa perf benchmark # # Define NO_LIBBIONIC if you do not want bionic support # -# Define NO_LIBCRYPTO if you do not want libcrypto (openssl) support -# used for generating build-ids for ELFs generated by jitdump. -# # Define NO_LIBDW_DWARF_UNWIND if you do not want libdw support # for dwarf backtrace post unwind. # # Define NO_LIBTRACEEVENT=3D1 if you don't want libtraceevent to be linked, # this will remove multiple features and tools, such as 'perf trace', diff --git a/tools/perf/builtin-check.c b/tools/perf/builtin-check.c index 9a509cb3bb9a0..ad49f2564aae2 100644 --- a/tools/perf/builtin-check.c +++ b/tools/perf/builtin-check.c @@ -42,11 +42,10 @@ struct feature_status supported_features[] =3D { FEATURE_STATUS("dwarf_getlocations", HAVE_LIBDW_SUPPORT), FEATURE_STATUS("dwarf-unwind", HAVE_DWARF_UNWIND_SUPPORT), FEATURE_STATUS("auxtrace", HAVE_AUXTRACE_SUPPORT), FEATURE_STATUS_TIP("libbfd", HAVE_LIBBFD_SUPPORT, "Deprecated, license in= compatibility, use BUILD_NONDISTRO=3D1 and install binutils-dev[el]"), FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT), - FEATURE_STATUS("libcrypto", HAVE_LIBCRYPTO_SUPPORT), FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT), FEATURE_STATUS("libelf", HAVE_LIBELF_SUPPORT), FEATURE_STATUS("libnuma", HAVE_LIBNUMA_SUPPORT), FEATURE_STATUS("libopencsd", HAVE_CSTRACE_SUPPORT), FEATURE_STATUS("libperl", HAVE_LIBPERL_SUPPORT), diff --git a/tools/perf/tests/make b/tools/perf/tests/make index 0ee94caf9ec19..e3651e5b195a4 100644 --- a/tools/perf/tests/make +++ b/tools/perf/tests/make @@ -89,11 +89,10 @@ make_no_libnuma :=3D NO_LIBNUMA=3D1 make_no_libbionic :=3D NO_LIBBIONIC=3D1 make_no_auxtrace :=3D NO_AUXTRACE=3D1 make_no_libbpf :=3D NO_LIBBPF=3D1 make_libbpf_dynamic :=3D LIBBPF_DYNAMIC=3D1 make_no_libbpf_DEBUG :=3D NO_LIBBPF=3D1 DEBUG=3D1 -make_no_libcrypto :=3D NO_LIBCRYPTO=3D1 make_no_libllvm :=3D NO_LIBLLVM=3D1 make_with_babeltrace:=3D LIBBABELTRACE=3D1 make_with_coresight :=3D CORESIGHT=3D1 make_no_sdt :=3D NO_SDT=3D1 make_no_libpfm4 :=3D NO_LIBPFM4=3D1 @@ -120,11 +119,11 @@ make_static :=3D LDFLAGS=3D-static NO_PERF_RE= AD_VDSO32=3D1 NO_PERF_READ_VDSOX3 # all the NO_* variable combined make_minimal :=3D NO_LIBPERL=3D1 NO_LIBPYTHON=3D1 NO_GTK2=3D1 make_minimal +=3D NO_DEMANGLE=3D1 NO_LIBELF=3D1 NO_BACKTRACE=3D1 make_minimal +=3D NO_LIBNUMA=3D1 NO_LIBBIONIC=3D1 make_minimal +=3D NO_LIBDW_DWARF_UNWIND=3D1 NO_AUXTRACE=3D1 NO_LIBB= PF=3D1 -make_minimal +=3D NO_LIBCRYPTO=3D1 NO_SDT=3D1 NO_JVMTI=3D1 NO_LIBZS= TD=3D1 +make_minimal +=3D NO_SDT=3D1 NO_JVMTI=3D1 NO_LIBZSTD=3D1 make_minimal +=3D NO_LIBCAP=3D1 NO_CAPSTONE=3D1 =20 # $(run) contains all available tests run :=3D make_pure # Targets 'clean all' can be run together only through top level @@ -158,11 +157,10 @@ run +=3D make_no_libcapstone run +=3D make_no_libnuma run +=3D make_no_libbionic run +=3D make_no_auxtrace run +=3D make_no_libbpf run +=3D make_no_libbpf_DEBUG -run +=3D make_no_libcrypto run +=3D make_no_libllvm run +=3D make_no_sdt run +=3D make_no_syscall_tbl run +=3D make_with_babeltrace run +=3D make_with_coresight --=20 2.49.0