* [PATCH v2 0/4] perf: Remove libcrypto dependency
@ 2025-06-14 4:41 Eric Biggers
2025-06-14 4:41 ` [PATCH v2 1/4] perf build: enable -fno-strict-aliasing Eric Biggers
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Eric Biggers @ 2025-06-14 4:41 UTC (permalink / raw)
To: linux-perf-users
Cc: linux-kernel, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
Liang Kan, Yuzhuo Jing
This is a reworked version of
https://lore.kernel.org/all/20250521225307.743726-1-yuzhuo@google.com/.
I've changed it to add a new minimal SHA-1 implementation, instead of
trying to pull in the kernel's SHA-1 implementation which is not really
designed to be extracted into userspace programs. I also added a test.
Eric Biggers (2):
perf build: enable -fno-strict-aliasing
perf util: add a basic SHA-1 implementation
Yuzhuo Jing (2):
perf genelf: Remove libcrypto dependency and use built-in sha1()
tools: Remove libcrypto dependency
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 | 17 +----
tools/perf/Makefile.perf | 3 -
tools/perf/builtin-check.c | 1 -
tools/perf/tests/make | 4 +-
tools/perf/tests/util.c | 45 +++++++++++-
tools/perf/util/Build | 1 +
tools/perf/util/genelf.c | 85 +---------------------
tools/perf/util/sha1.c | 97 +++++++++++++++++++++++++
tools/perf/util/sha1.h | 6 ++
14 files changed, 156 insertions(+), 140 deletions(-)
delete mode 100644 tools/build/feature/test-libcrypto.c
create mode 100644 tools/perf/util/sha1.c
create mode 100644 tools/perf/util/sha1.h
base-commit: 18531f4d1c8c47c4796289dbbc1ab657ffa063d2
--
2.49.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 1/4] perf build: enable -fno-strict-aliasing
2025-06-14 4:41 [PATCH v2 0/4] perf: Remove libcrypto dependency Eric Biggers
@ 2025-06-14 4:41 ` Eric Biggers
2025-06-15 23:40 ` Ian Rogers
2025-06-14 4:41 ` [PATCH v2 2/4] perf util: add a basic SHA-1 implementation Eric Biggers
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Eric Biggers @ 2025-06-14 4:41 UTC (permalink / raw)
To: linux-perf-users
Cc: linux-kernel, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
Liang Kan, Yuzhuo Jing
From: Eric Biggers <ebiggers@google.com>
perf pulls in code from kernel headers that assumes it is being built
with -fno-strict-aliasing, namely put_unaligned_*() from
<linux/unaligned.h> 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 <ebiggers@google.com>
---
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 = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected)
detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
+# This is required because the kernel is built with this and some of the code
+# borrowed from kernel headers depends on it, e.g. put_unaligned_*().
+CFLAGS += -fno-strict-aliasing
+
# Enabled Wthread-safety analysis for clang builds.
ifeq ($(CC_NO_CLANG), 0)
CFLAGS += -Wthread-safety
endif
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 2/4] perf util: add a basic SHA-1 implementation
2025-06-14 4:41 [PATCH v2 0/4] perf: Remove libcrypto dependency Eric Biggers
2025-06-14 4:41 ` [PATCH v2 1/4] perf build: enable -fno-strict-aliasing Eric Biggers
@ 2025-06-14 4:41 ` Eric Biggers
2025-06-14 4:41 ` [PATCH v2 3/4] perf genelf: Remove libcrypto dependency and use built-in sha1() Eric Biggers
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-06-14 4:41 UTC (permalink / raw)
To: linux-perf-users
Cc: linux-kernel, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
Liang Kan, Yuzhuo Jing
From: Eric Biggers <ebiggers@google.com>
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 <ebiggers@google.com>
---
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"
#include <linux/compiler.h>
#include <stdlib.h>
#include <string2.h>
@@ -14,18 +15,60 @@ static int test_strreplace(char needle, const char *haystack,
free(new);
return ret == 0;
}
+#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 = (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] = {
+ 0x74, 0xcd, 0x4c, 0xb9, 0xd8, 0xa6, 0xd5, 0x95, 0x22, 0x8b,
+ 0x7e, 0xd6, 0x8b, 0x7e, 0x46, 0x95, 0x31, 0x9b, 0xa2, 0x43,
+ };
+ size_t i;
+
+ digests = malloc(digests_size);
+ TEST_ASSERT_VAL("failed to allocate digests", digests != NULL);
+
+ /* Generate MAX_LEN bytes of data. */
+ for (i = 0; i < MAX_LEN; i++)
+ data[i] = i;
+
+ /* Calculate a SHA-1 for each length 0 through MAX_LEN inclusively. */
+ for (i = 0; i <= 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) == 0);
+ return 0;
+}
+
static int test__util(struct test_suite *t __maybe_unused, int subtest __maybe_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", "efbcefbc"));
TEST_ASSERT_VAL("replace long", test_strreplace('a', "abcabc", "longlong",
"longlongbclonglongbc"));
- return 0;
+ return test_sha1();
}
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 += rlimit.o
perf-util-y += argv_split.o
perf-util-y += rbtree.o
perf-util-y += libstring.o
perf-util-y += bitmap.o
perf-util-y += hweight.o
+perf-util-y += sha1.o
perf-util-y += smt.o
perf-util-y += strbuf.o
perf-util-y += string.o
perf-util-y += strlist.o
perf-util-y += 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 <linux/bitops.h>
+#include <linux/kernel.h>
+#include <linux/unaligned.h>
+#include <string.h>
+
+#include "sha1.h"
+
+#define SHA1_BLOCK_SIZE 64
+
+static const u32 sha1_K[4] = { 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6 };
+
+#define SHA1_ROUND(i, a, b, c, d, e) \
+ do { \
+ if ((i) >= 16) \
+ w[i] = rol32(w[((i) - 16)] ^ w[((i) - 14)] ^ \
+ w[((i) - 8)] ^ w[((i) - 3)], \
+ 1); \
+ e += w[i] + rol32(a, 5) + sha1_K[(i) / 20]; \
+ if ((i) < 20) \
+ e += (b & (c ^ d)) ^ d; \
+ else if ((i) < 40 || (i) >= 60) \
+ e += b ^ c ^ d; \
+ else \
+ e += (c & d) ^ (b & (c ^ d)); \
+ b = 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 = h[0];
+ u32 b = h[1];
+ u32 c = h[2];
+ u32 d = h[3];
+ u32 e = h[4];
+ u32 w[80];
+
+ for (int i = 0; i < 16; i++)
+ w[i] = get_unaligned_be32(&data[i * 4]);
+ SHA1_20ROUNDS(0);
+ SHA1_20ROUNDS(20);
+ SHA1_20ROUNDS(40);
+ SHA1_20ROUNDS(60);
+
+ h[0] += a;
+ h[1] += b;
+ h[2] += c;
+ h[3] += d;
+ h[4] += e;
+ data += 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] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476,
+ 0xC3D2E1F0 };
+ u8 final_data[2 * SHA1_BLOCK_SIZE] = { 0 };
+ size_t final_len = 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] = 0x80;
+ final_len = 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 = 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 <linux/types.h>
+
+#define SHA1_DIGEST_SIZE 20
+
+void sha1(const void *data, size_t len, u8 out[SHA1_DIGEST_SIZE]);
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 3/4] perf genelf: Remove libcrypto dependency and use built-in sha1()
2025-06-14 4:41 [PATCH v2 0/4] perf: Remove libcrypto dependency Eric Biggers
2025-06-14 4:41 ` [PATCH v2 1/4] perf build: enable -fno-strict-aliasing Eric Biggers
2025-06-14 4:41 ` [PATCH v2 2/4] perf util: add a basic SHA-1 implementation Eric Biggers
@ 2025-06-14 4:41 ` Eric Biggers
2025-06-14 4:41 ` [PATCH v2 4/4] tools: Remove libcrypto dependency Eric Biggers
2025-06-24 18:03 ` [PATCH v2 0/4] perf: " Namhyung Kim
4 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-06-14 4:41 UTC (permalink / raw)
To: linux-perf-users
Cc: linux-kernel, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
Liang Kan, Yuzhuo Jing
From: Yuzhuo Jing <yuzhuo@google.com>
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 <yuzhuo@google.com>
Co-developed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
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 <sys/types.h>
#include <stddef.h>
#include <libelf.h>
#include <string.h>
#include <stdlib.h>
-#include <unistd.h>
#include <inttypes.h>
-#include <fcntl.h>
#include <err.h>
#ifdef HAVE_LIBDW_SUPPORT
#include <dwarf.h>
#endif
#include "genelf.h"
+#include "sha1.h"
#include "../util/jitdump.h"
#include <linux/compiler.h>
#ifndef NT_GNU_BUILD_ID
#define NT_GNU_BUILD_ID 3
#endif
-#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 <openssl/sha.h>
-#endif
-
-#ifdef BUILD_ID_MD5
-#include <openssl/evp.h>
-#include <openssl/md5.h>
-#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[] = {
};
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;
static Elf_Sym symtab[]={
/* symbol 0 MUST be the undefined symbol */
{ .st_name = 0, /* index in sym_string table */
@@ -90,69 +70,10 @@ static Elf_Sym symtab[]={
.st_other = ELF_ST_VIS(STV_DEFAULT),
.st_size = 0, /* for now */
}
};
-#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 = sizeof(note->build_id);
- ssize_t sret;
-
- fd = open("/dev/urandom", O_RDONLY);
- if (fd == -1)
- err(1, "cannot access /dev/urandom for buildid");
-
- sret = read(fd, note->build_id, sz);
-
- close(fd);
-
- if (sret != (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 void *code, size_t csize)
-{
- EVP_MD_CTX *mdctx;
-
- if (sizeof(note->build_id) < 16)
- errx(1, "build_id too small for MD5");
-
- mdctx = 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_size,
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,
}
/*
* build-id generation
*/
- gen_build_id(&bnote, load_addr, code, csize);
+ sha1(code, csize, bnote.build_id);
bnote.desc.namesz = sizeof(bnote.name); /* must include 0 termination */
bnote.desc.descsz = sizeof(bnote.build_id);
bnote.desc.type = NT_GNU_BUILD_ID;
strcpy(bnote.name, "GNU");
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 4/4] tools: Remove libcrypto dependency
2025-06-14 4:41 [PATCH v2 0/4] perf: Remove libcrypto dependency Eric Biggers
` (2 preceding siblings ...)
2025-06-14 4:41 ` [PATCH v2 3/4] perf genelf: Remove libcrypto dependency and use built-in sha1() Eric Biggers
@ 2025-06-14 4:41 ` Eric Biggers
2025-06-24 18:03 ` [PATCH v2 0/4] perf: " Namhyung Kim
4 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-06-14 4:41 UTC (permalink / raw)
To: linux-perf-users
Cc: linux-kernel, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
Liang Kan, Yuzhuo Jing
From: Yuzhuo Jing <yuzhuo@google.com>
Remove all occurrence of libcrypto in the build system.
Signed-off-by: Yuzhuo Jing <yuzhuo@google.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
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 := \
libpython \
libslang \
libtraceevent \
libtracefs \
libcpupower \
- libcrypto \
pthread-attr-setaffinity-np \
pthread-barrier \
reallocarray \
stackprotector-all \
timerfd \
@@ -150,11 +149,10 @@ FEATURE_DISPLAY ?= \
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= \
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
$(OUTPUT)test-libtracefs.bin:
$(BUILD) $(shell $(PKG_CONFIG) --cflags libtracefs 2>/dev/null) -ltracefs
-$(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
$(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 @@
#define main main_test_bpf
# include "test-bpf.c"
#undef main
-#define main main_test_libcrypto
-# include "test-libcrypto.c"
-#undef main
-
#define main main_test_sdt
# include "test-sdt.c"
#undef main
#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/test-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 <openssl/evp.h>
-#include <openssl/sha.h>
-#include <openssl/md5.h>
-
-int main(void)
-{
- EVP_MD_CTX *mdctx;
- unsigned char md[MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH];
- unsigned char dat[] = "12345";
- unsigned int digest_len;
-
- mdctx = 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/Documentation/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 += -lunwind -lunwind-aarch64
FEATURE_CHECK_LDFLAGS-libunwind-x86 += -lunwind -llzma -lunwind-x86
FEATURE_CHECK_LDFLAGS-libunwind-x86_64 += -lunwind -llzma -lunwind-x86_64
endif
-FEATURE_CHECK_LDFLAGS-libcrypto = -lcrypto
-
ifdef CSINCLUDES
LIBOPENCSD_CFLAGS := -I$(CSINCLUDES)
endif
OPENCSDLIBS := -lopencsd_c_api -lopencsd
ifeq ($(findstring -static,${LDFLAGS}),-static)
@@ -774,21 +772,10 @@ endif
ifneq ($(NO_LIBTRACEEVENT),1)
$(call detected,CONFIG_TRACE)
endif
-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 := 1
- else
- CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
- EXTLIBS += -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 slang-devel, libslang-dev or libslang2-dev)
NO_SLANG := 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=1 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[] = {
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 incompatibility, use BUILD_NONDISTRO=1 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 := NO_LIBNUMA=1
make_no_libbionic := NO_LIBBIONIC=1
make_no_auxtrace := NO_AUXTRACE=1
make_no_libbpf := NO_LIBBPF=1
make_libbpf_dynamic := LIBBPF_DYNAMIC=1
make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
-make_no_libcrypto := NO_LIBCRYPTO=1
make_no_libllvm := NO_LIBLLVM=1
make_with_babeltrace:= LIBBABELTRACE=1
make_with_coresight := CORESIGHT=1
make_no_sdt := NO_SDT=1
make_no_libpfm4 := NO_LIBPFM4=1
@@ -120,11 +119,11 @@ make_static := LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX3
# all the NO_* variable combined
make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_GTK2=1
make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_BACKTRACE=1
make_minimal += NO_LIBNUMA=1 NO_LIBBIONIC=1
make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1
-make_minimal += NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1
+make_minimal += NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1
make_minimal += NO_LIBCAP=1 NO_CAPSTONE=1
# $(run) contains all available tests
run := make_pure
# Targets 'clean all' can be run together only through top level
@@ -158,11 +157,10 @@ run += make_no_libcapstone
run += make_no_libnuma
run += make_no_libbionic
run += make_no_auxtrace
run += make_no_libbpf
run += make_no_libbpf_DEBUG
-run += make_no_libcrypto
run += make_no_libllvm
run += make_no_sdt
run += make_no_syscall_tbl
run += make_with_babeltrace
run += make_with_coresight
--
2.49.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/4] perf build: enable -fno-strict-aliasing
2025-06-14 4:41 ` [PATCH v2 1/4] perf build: enable -fno-strict-aliasing Eric Biggers
@ 2025-06-15 23:40 ` Ian Rogers
2025-06-16 1:13 ` Eric Biggers
0 siblings, 1 reply; 10+ messages in thread
From: Ian Rogers @ 2025-06-15 23:40 UTC (permalink / raw)
To: Eric Biggers
Cc: linux-perf-users, linux-kernel, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Liang Kan,
Yuzhuo Jing
On Fri, Jun 13, 2025 at 9:43 PM Eric Biggers <ebiggers@kernel.org> wrote:
>
> From: Eric Biggers <ebiggers@google.com>
>
> perf pulls in code from kernel headers that assumes it is being built
> with -fno-strict-aliasing, namely put_unaligned_*() from
> <linux/unaligned.h> 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.
Wow, good catch! I wonder if -fsanitize=type could be used to capture
when perf's code is broken like this? Perhaps we should just remove
linux/unaligned.h in tools because of this, the alternative of using
memcpy doesn't look particularly burdensome. Given the memcpys are of
a known/fixed size I'd expect the compiler to be able to optimize
things just as well. Perhaps we should rewrite unaligned.h in tools
but perhaps the kernel too. Something like:
#define __get_unaligned_t(type, ptr) ({
\
const struct { type x; } __packed * __get_pptr =
(typeof(__get_pptr))(ptr); \
__get_pptr->x;
\
})
becomes:
#define __get_unaligned_t(type, ptr) ({
\
type __get_val; memcpy(&__get_val, ptr, sizeof(__get_val)); \
__get_val;
\
})
Thanks,
Ian
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> 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 = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected)
> detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
>
> CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
> HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
>
> +# This is required because the kernel is built with this and some of the code
> +# borrowed from kernel headers depends on it, e.g. put_unaligned_*().
> +CFLAGS += -fno-strict-aliasing
> +
> # Enabled Wthread-safety analysis for clang builds.
> ifeq ($(CC_NO_CLANG), 0)
> CFLAGS += -Wthread-safety
> endif
>
> --
> 2.49.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/4] perf build: enable -fno-strict-aliasing
2025-06-15 23:40 ` Ian Rogers
@ 2025-06-16 1:13 ` Eric Biggers
2025-06-17 1:00 ` Ian Rogers
0 siblings, 1 reply; 10+ messages in thread
From: Eric Biggers @ 2025-06-16 1:13 UTC (permalink / raw)
To: Ian Rogers
Cc: linux-perf-users, linux-kernel, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Liang Kan,
Yuzhuo Jing
On Sun, Jun 15, 2025 at 04:40:45PM -0700, Ian Rogers wrote:
> On Fri, Jun 13, 2025 at 9:43 PM Eric Biggers <ebiggers@kernel.org> wrote:
> >
> > From: Eric Biggers <ebiggers@google.com>
> >
> > perf pulls in code from kernel headers that assumes it is being built
> > with -fno-strict-aliasing, namely put_unaligned_*() from
> > <linux/unaligned.h> 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.
>
> Wow, good catch! I wonder if -fsanitize=type could be used to capture
> when perf's code is broken like this? Perhaps we should just remove
> linux/unaligned.h in tools because of this, the alternative of using
> memcpy doesn't look particularly burdensome. Given the memcpys are of
> a known/fixed size I'd expect the compiler to be able to optimize
> things just as well. Perhaps we should rewrite unaligned.h in tools
> but perhaps the kernel too. Something like:
>
> #define __get_unaligned_t(type, ptr) ({
> \
> const struct { type x; } __packed * __get_pptr =
> (typeof(__get_pptr))(ptr); \
> __get_pptr->x;
> \
> })
>
> becomes:
>
> #define __get_unaligned_t(type, ptr) ({
> \
> type __get_val; memcpy(&__get_val, ptr, sizeof(__get_val)); \
> __get_val;
> \
> })
As far as I know, the packed struct method of doing unaligned memory accesses is
obsolete these days, and memcpy() generates the desired code on all supported
architectures and compilers.
- Eric
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/4] perf build: enable -fno-strict-aliasing
2025-06-16 1:13 ` Eric Biggers
@ 2025-06-17 1:00 ` Ian Rogers
0 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2025-06-17 1:00 UTC (permalink / raw)
To: Eric Biggers
Cc: linux-perf-users, linux-kernel, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Liang Kan,
Yuzhuo Jing
On Sun, Jun 15, 2025 at 6:14 PM Eric Biggers <ebiggers@kernel.org> wrote:
>
> As far as I know, the packed struct method of doing unaligned memory accesses is
> obsolete these days, and memcpy() generates the desired code on all supported
> architectures and compilers.
Thanks Eric, I sent:
https://lore.kernel.org/lkml/20250617005800.1410112-1-irogers@google.com/
let's see how it goes.
Thanks,
Ian
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 0/4] perf: Remove libcrypto dependency
2025-06-14 4:41 [PATCH v2 0/4] perf: Remove libcrypto dependency Eric Biggers
` (3 preceding siblings ...)
2025-06-14 4:41 ` [PATCH v2 4/4] tools: Remove libcrypto dependency Eric Biggers
@ 2025-06-24 18:03 ` Namhyung Kim
2025-06-25 20:26 ` Eric Biggers
4 siblings, 1 reply; 10+ messages in thread
From: Namhyung Kim @ 2025-06-24 18:03 UTC (permalink / raw)
To: Eric Biggers
Cc: linux-perf-users, linux-kernel, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Ian Rogers, Adrian Hunter, Liang Kan, Yuzhuo Jing
Hello,
On Fri, Jun 13, 2025 at 09:41:29PM -0700, Eric Biggers wrote:
> This is a reworked version of
> https://lore.kernel.org/all/20250521225307.743726-1-yuzhuo@google.com/.
> I've changed it to add a new minimal SHA-1 implementation, instead of
> trying to pull in the kernel's SHA-1 implementation which is not really
> designed to be extracted into userspace programs. I also added a test.
>
> Eric Biggers (2):
> perf build: enable -fno-strict-aliasing
> perf util: add a basic SHA-1 implementation
>
> Yuzhuo Jing (2):
> perf genelf: Remove libcrypto dependency and use built-in sha1()
> tools: Remove libcrypto dependency
Thanks for working on this. But can you please rebase it on to the
latest perf-tools-next tree/branch? It doesn't apply cleanly.
Thanks,
Namhyung
>
> 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 | 17 +----
> tools/perf/Makefile.perf | 3 -
> tools/perf/builtin-check.c | 1 -
> tools/perf/tests/make | 4 +-
> tools/perf/tests/util.c | 45 +++++++++++-
> tools/perf/util/Build | 1 +
> tools/perf/util/genelf.c | 85 +---------------------
> tools/perf/util/sha1.c | 97 +++++++++++++++++++++++++
> tools/perf/util/sha1.h | 6 ++
> 14 files changed, 156 insertions(+), 140 deletions(-)
> delete mode 100644 tools/build/feature/test-libcrypto.c
> create mode 100644 tools/perf/util/sha1.c
> create mode 100644 tools/perf/util/sha1.h
>
>
> base-commit: 18531f4d1c8c47c4796289dbbc1ab657ffa063d2
> --
> 2.49.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 0/4] perf: Remove libcrypto dependency
2025-06-24 18:03 ` [PATCH v2 0/4] perf: " Namhyung Kim
@ 2025-06-25 20:26 ` Eric Biggers
0 siblings, 0 replies; 10+ messages in thread
From: Eric Biggers @ 2025-06-25 20:26 UTC (permalink / raw)
To: Namhyung Kim
Cc: linux-perf-users, linux-kernel, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Ian Rogers, Adrian Hunter, Liang Kan, Yuzhuo Jing
On Tue, Jun 24, 2025 at 11:03:00AM -0700, Namhyung Kim wrote:
> Hello,
>
> On Fri, Jun 13, 2025 at 09:41:29PM -0700, Eric Biggers wrote:
> > This is a reworked version of
> > https://lore.kernel.org/all/20250521225307.743726-1-yuzhuo@google.com/.
> > I've changed it to add a new minimal SHA-1 implementation, instead of
> > trying to pull in the kernel's SHA-1 implementation which is not really
> > designed to be extracted into userspace programs. I also added a test.
> >
> > Eric Biggers (2):
> > perf build: enable -fno-strict-aliasing
> > perf util: add a basic SHA-1 implementation
> >
> > Yuzhuo Jing (2):
> > perf genelf: Remove libcrypto dependency and use built-in sha1()
> > tools: Remove libcrypto dependency
>
> Thanks for working on this. But can you please rebase it on to the
> latest perf-tools-next tree/branch? It doesn't apply cleanly.
>
> Thanks,
> Namhyung
>
Done: https://lore.kernel.org/all/20250625202311.23244-1-ebiggers@kernel.org/
- Eric
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-06-25 20:27 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-14 4:41 [PATCH v2 0/4] perf: Remove libcrypto dependency Eric Biggers
2025-06-14 4:41 ` [PATCH v2 1/4] perf build: enable -fno-strict-aliasing Eric Biggers
2025-06-15 23:40 ` Ian Rogers
2025-06-16 1:13 ` Eric Biggers
2025-06-17 1:00 ` Ian Rogers
2025-06-14 4:41 ` [PATCH v2 2/4] perf util: add a basic SHA-1 implementation Eric Biggers
2025-06-14 4:41 ` [PATCH v2 3/4] perf genelf: Remove libcrypto dependency and use built-in sha1() Eric Biggers
2025-06-14 4:41 ` [PATCH v2 4/4] tools: Remove libcrypto dependency Eric Biggers
2025-06-24 18:03 ` [PATCH v2 0/4] perf: " Namhyung Kim
2025-06-25 20:26 ` Eric Biggers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).