From 6b979fc6dd8c03ed8332bdef2915b9d6d3ecfd6a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 24 Oct 2022 10:53:40 -0400 Subject: [PATCH] Build fix: rpath of test libraries results in non-reproducible build MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Yocto has trouble making LTTng-tools builds reproducibile since abs_builddir is used as the rpath of the test libraries under tests/regression/ust/ust-dl/. From their commit message: Specifing abs_builddir as an RPATH is plain wrong when cross compiling. Sadly, removing the rpath makes libtool/automake do weird things and breaks the build as shared libs are no longer generated. We already try and delete the RPATH at do_install with chrpath however that does leave the path in the string table so it doesn't help us with reproducibility. Their fix consists in hardcoding /usr/lib as the rpath of those libraries. As mentionned, the rpath doesn't matter; it's used to workaround libtool's behaviour. This fix uses `$libdir`, which takes the user's specified prefix into account to generate an rpath that is consistent with the one inserted in the other artifacts. Note that the change in the notification tests is a bit more involved since we have to bypass libtool to instrument a test application with uprobes. Fixes #1361 Change-Id: I7739956f8bc8571ef90802c3b37a4e1f21352385 Reported-by: Alexander Kanavin Signed-off-by: Jérémie Galarneau --- tests/regression/kernel/test_userspace_probe | 19 ++++++++++--------- .../notification/util_event_generator.sh | 14 +++++++++++++- tests/regression/ust/ust-dl/Makefile.am | 8 ++++---- .../userspace-probe-elf-binary/Makefile.am | 2 +- .../userspace-probe-sdt-binary/Makefile.am | 6 +++--- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/tests/regression/kernel/test_userspace_probe b/tests/regression/kernel/test_userspace_probe index 31b11e98d..1091ee65e 100755 --- a/tests/regression/kernel/test_userspace_probe +++ b/tests/regression/kernel/test_userspace_probe @@ -289,7 +289,7 @@ function test_userspace_probe_elf () lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME start_lttng_tracing_ok $SESSION_NAME - eval "$ELF_TEST_BIN" > /dev/null + LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-elf-binary/.libs" "$ELF_TEST_BIN" > /dev/null stop_lttng_tracing_ok $SESSION_NAME validate_trace $PROBE_EVENT_NAME "$TRACE_PATH" @@ -313,7 +313,7 @@ function test_userspace_probe_elf_dynamic_symbol () lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME start_lttng_tracing_ok $SESSION_NAME - eval "$ELF_TEST_BIN" > /dev/null + LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-elf-binary/.libs" "$ELF_TEST_BIN" > /dev/null stop_lttng_tracing_ok $SESSION_NAME validate_trace $PROBE_EVENT_NAME "$TRACE_PATH" @@ -545,6 +545,7 @@ function test_userspace_probe_sdt () PROVIDER="foobar" PROBE="tp1" ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE" + SESSION_NAME="${FUNCNAME[0]}" diag "Userspace probe on SDT tracepoint enabled and traced" @@ -553,7 +554,7 @@ function test_userspace_probe_sdt () lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME start_lttng_tracing_ok $SESSION_NAME - eval "$SDT_TEST_BIN" > /dev/null + LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null stop_lttng_tracing_ok $SESSION_NAME validate_trace $PROBE_EVENT_NAME "$TRACE_PATH" @@ -661,7 +662,7 @@ function test_userspace_probe_sdt_one_probe () lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME start_lttng_tracing_ok $SESSION_NAME - eval "$SDT_TEST_BIN" > /dev/null + LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null stop_lttng_tracing_ok $SESSION_NAME validate_trace $PROBE_EVENT_NAME "$TRACE_PATH" @@ -686,7 +687,7 @@ function test_userspace_probe_sdt_two_probes () lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME start_lttng_tracing_ok $SESSION_NAME - eval "$SDT_TEST_BIN" > /dev/null + LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null stop_lttng_tracing_ok $SESSION_NAME validate_trace $PROBE_EVENT_NAME "$TRACE_PATH" @@ -711,7 +712,7 @@ function test_userspace_probe_sdt_in_shared_object () lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME start_lttng_tracing_ok $SESSION_NAME - eval "$SDT_TEST_BIN" > /dev/null + LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null stop_lttng_tracing_ok $SESSION_NAME validate_trace $PROBE_EVENT_NAME "$TRACE_PATH" @@ -736,7 +737,7 @@ function test_userspace_probe_sdt_in_shared_object_dlopen () lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME start_lttng_tracing_ok $SESSION_NAME - eval "$SDT_TEST_BIN" > /dev/null + LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null stop_lttng_tracing_ok $SESSION_NAME validate_trace $PROBE_EVENT_NAME "$TRACE_PATH" @@ -761,7 +762,7 @@ function test_userspace_probe_sdt_in_shared_object_ldpreload () lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME start_lttng_tracing_ok $SESSION_NAME - LD_PRELOAD="$SDT_TEST_BIN_DIR/libzzz.so" eval "$SDT_TEST_BIN" > /dev/null + LD_PRELOAD="$SDT_TEST_BIN_DIR/libzzz.so" LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null stop_lttng_tracing_ok $SESSION_NAME validate_trace $PROBE_EVENT_NAME "$TRACE_PATH" @@ -786,7 +787,7 @@ function test_userspace_probe_sdt_with_arg () lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME start_lttng_tracing_ok $SESSION_NAME - eval "$SDT_TEST_BIN" > /dev/null + LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null stop_lttng_tracing_ok $SESSION_NAME validate_trace $PROBE_EVENT_NAME "$TRACE_PATH" diff --git a/tests/regression/tools/notification/util_event_generator.sh b/tests/regression/tools/notification/util_event_generator.sh index 5eef0deea..55189cf7c 100644 --- a/tests/regression/tools/notification/util_event_generator.sh +++ b/tests/regression/tools/notification/util_event_generator.sh @@ -37,7 +37,19 @@ function userspace_probe_testapp shift for i in $(seq 1 "$nr"); do - $USERSPACE_PROBE_ELF_TESTAPP_BIN "$@" + # This userspace probe test has to instrument the actual elf + # binary and not the generated libtool wrapper. However, we + # can't invoke the wrapper either since it will re-link the test + # application binary on its first invocation, resulting in a new + # binary with an 'lt-*' prefix under the .libs folder. The + # relinking stage adds the .libs folder to the 'lt-*' binary's + # rpath. + # + # To ensure the binary (inode) that instrumented is the same as + # what is running, set LD_LIBRARY_PATH to find the .libs folder + # that contains the libfoo.so library and invoke the binary + # directly. + LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-elf-binary/.libs" $USERSPACE_PROBE_ELF_TESTAPP_BIN "$@" done } diff --git a/tests/regression/ust/ust-dl/Makefile.am b/tests/regression/ust/ust-dl/Makefile.am index 366b02bb0..322a2c65f 100644 --- a/tests/regression/ust/ust-dl/Makefile.am +++ b/tests/regression/ust/ust-dl/Makefile.am @@ -31,16 +31,16 @@ noinst_LTLIBRARIES = libzzz.la libbar.la libfoo.la libtp.la libzzz_la_SOURCES = libzzz.c libzzz.h libzzz_la_LDFLAGS = -module -shared -avoid-version \ - -rpath $(abs_builddir) + -rpath $(libdir) libbar_la_SOURCES = libbar.c libbar.h libbar_la_LDFLAGS = -module -shared -avoid-version \ - -rpath $(abs_builddir) + -rpath $(libdir) libbar_la_LIBADD = libzzz.la libfoo_la_SOURCES = libfoo.c libfoo.h libfoo_la_LDFLAGS = -module -shared -avoid-version \ - -rpath $(abs_builddir) + -rpath $(libdir) libfoo_la_LIBADD = libbar.la CLEANFILES = libfoo.so libfoo.so.debug libbar.so libbar.so.debug \ @@ -48,7 +48,7 @@ CLEANFILES = libfoo.so libfoo.so.debug libbar.so libbar.so.debug \ libtp_la_SOURCES = libbar-tp.h libbar-tp.c libfoo-tp.h libfoo-tp.c \ libzzz-tp.h libzzz-tp.c -libtp_la_LDFLAGS = -module -shared -rpath $(abs_builddir) +libtp_la_LDFLAGS = -module -shared -rpath $(libdir) # Extract debug symbols libfoo.so.debug: libfoo.la diff --git a/tests/utils/testapp/userspace-probe-elf-binary/Makefile.am b/tests/utils/testapp/userspace-probe-elf-binary/Makefile.am index af76ae7fc..836f13e95 100644 --- a/tests/utils/testapp/userspace-probe-elf-binary/Makefile.am +++ b/tests/utils/testapp/userspace-probe-elf-binary/Makefile.am @@ -5,7 +5,7 @@ AM_CFLAGS += -O0 noinst_LTLIBRARIES = libfoo.la libfoo_la_SOURCES = foo.c foo.h -libfoo_la_LDFLAGS = -shared -module -avoid-version -rpath $(abs_builddir)/.libs/ +libfoo_la_LDFLAGS = -shared -module -avoid-version -rpath $(libdir) noinst_PROGRAMS = userspace-probe-elf-binary userspace_probe_elf_binary_SOURCES = userspace-probe-elf-binary.c diff --git a/tests/utils/testapp/userspace-probe-sdt-binary/Makefile.am b/tests/utils/testapp/userspace-probe-sdt-binary/Makefile.am index f12ced228..77567f2fc 100644 --- a/tests/utils/testapp/userspace-probe-sdt-binary/Makefile.am +++ b/tests/utils/testapp/userspace-probe-sdt-binary/Makefile.am @@ -22,19 +22,19 @@ noinst_LTLIBRARIES = libfoo.la libbar.la libzzz.la libfoo_la_SOURCES = libfoo.h libfoo.c libfoo_la_LIBADD = foobar_provider.o libfoo_la_CFLAGS = -I$(abs_builddir) -libfoo_la_LDFLAGS = -module -shared -avoid-version -rpath $(abs_builddir)/.libs/ +libfoo_la_LDFLAGS = -module -shared -avoid-version -rpath $(libdir) nodist_libfoo_la_SOURCES = $(abs_builddir)/foobar_provider.h libbar_la_SOURCES = libbar.h libbar.c libbar_la_LIBADD = foobar_provider.o libbar_la_CFLAGS = -I$(abs_builddir) -libbar_la_LDFLAGS = -module -shared -avoid-version -rpath $(abs_builddir)/.libs/ +libbar_la_LDFLAGS = -module -shared -avoid-version -rpath $(libdir) nodist_libbar_la_SOURCES = $(abs_builddir)/foobar_provider.h libzzz_la_SOURCES = libzzz.h libzzz.c libzzz_la_LIBADD = foobar_provider.o libzzz_la_CFLAGS = -I$(abs_builddir) -libzzz_la_LDFLAGS = -module -shared -avoid-version -rpath $(abs_builddir)/.libs/ +libzzz_la_LDFLAGS = -module -shared -avoid-version -rpath $(libdir) nodist_libzzz_la_SOURCES = $(abs_builddir)/foobar_provider.h dtrace_verbose = $(dtrace_verbose_@AM_V@) -- 2.34.1