perf build: Fix LTO build of libperf-jvmti.so
PATCH 1/1 perf build: Fix LTO build of libperf-jvmti.so
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
--- tools/perf/Makefile.perf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/Makefile.perf +4 -2
@@ -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)
Signature · 1 line
2.50.1 (Apple Git-155)
Namhyung Kim
maintainerHello,
Quoted 3 lines · Trevor Allison
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
Can you share the error message and put it in the commit message?
I think my build is fine with LDFLAGS=-flto.
Thanks,
Namhyung
Quoted 28 lines
Signed-off-by Trevor Allison <[email protected]>--- tools/perf/Makefile.perf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)tools/perf/Makefile.perf +4
-2@@ -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)Signature · 1 line
2.50.1 (Apple Git-155)
Ian Rogers
reviewerQuoted 11 lines · Namhyung Kim
Hello,
Quoted 3 lines · Trevor Allison
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
Can you share the error message and put it in the commit message?
I think my build is fine with LDFLAGS=-flto.
I had to do many manual steps to make LTO work in the past (IIRC, using clang and lld). We do have an LTO option in the Makefiles:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/Makefile.config?h=perf-tools-next#n266
If LTO is ready, maybe we can add it to the build tests:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/make?h=perf-tools-next
Thanks,
Ian
Quoted 31 lines
Thanks,
NamhyungQuoted 28 lines
Signed-off-by Trevor Allison <[email protected]>--- tools/perf/Makefile.perf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)tools/perf/Makefile.perf +4
-3@@ -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)