[PATCH] perf build: Fix LTO build of libperf-jvmti.so

From: Trevor Allison

Date: Wed Jul 01 2026 - 00:24:28 EST


Linking libperf-jvmti.so through jvmti-in.o (ld -r) breaks LTO when
-flto is passed via LDFLAGS. Link the JVMTI object files directly
instead, and pass any LTO flags from LDFLAGS to the JVMTI compile step

Signed-off-by: Trevor Allison <tallison@xxxxxxxxxx>
---
tools/perf/Makefile.perf | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 3f0544d37a7f..bc66d711fa39 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -686,10 +686,12 @@ ifndef NO_JVMTI
LIBJVMTI_IN := $(OUTPUT)jvmti/jvmti-in.o

$(LIBJVMTI_IN): prepare FORCE
- $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=jvmti obj=jvmti
+ $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=jvmti obj=jvmti \
+ CFLAGS="$(CFLAGS) $(filter -flto% -ffat-lto-objects,$(LDFLAGS))"

$(OUTPUT)$(LIBJVMTI): $(LIBJVMTI_IN)
- $(QUIET_LINK)$(CC) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIBJVMTI) -o $@ $<
+ $(QUIET_LINK)$(CC) $(LDFLAGS) -shared -Wl,-soname -Wl,$(LIBJVMTI) -o $@ \
+ $(addprefix $(OUTPUT)jvmti/,libjvmti.o jvmti_agent.o libstring.o libctype.o)
endif

$(patsubst perf-%,%.o,$(PROGRAMS)): $(wildcard */*.h)
--
2.50.1 (Apple Git-155)