Build fix: rpath of test libraries results in non-reproducible build
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 24 Oct 2022 14:53:40 +0000 (10:53 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 26 Oct 2022 19:42:08 +0000 (15:42 -0400)
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 <alex.kanavin@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/regression/kernel/test_userspace_probe
tests/regression/tools/notification/util_event_generator.sh
tests/regression/ust/ust-dl/Makefile.am
tests/utils/testapp/userspace-probe-elf-binary/Makefile.am
tests/utils/testapp/userspace-probe-sdt-binary/Makefile.am

index 31b11e98da99777b25e3f4079c1edeab12e636bc..1091ee65e461d6a3f53064d78817d3d06260bfe9 100755 (executable)
@@ -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"
index 5eef0deea82f0a775e88f04d7144816d4e6bd3b1..55189cf7cec217e88b7f2d3d5c364a79666aaff9 100644 (file)
@@ -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
 }
 
index 366b02bb0eb9daf13e10847a77e00bd8cee653cc..322a2c65f7fdcee12e6e8c1df51e8bd760d65a09 100644 (file)
@@ -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
index af76ae7fc909c60d8cb682dc30ec18dca521ed57..836f13e9543874af8db5814d80a8cb5c165b9384 100644 (file)
@@ -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
index f12ced228e4611ee6b48361fafe28454b4621b47..77567f2fc6913d15004bf0f65915407e668eea79 100644 (file)
@@ -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@)
This page took 0.029121 seconds and 4 git commands to generate.