[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240506081648.3890067-1-yangjihong@bytedance.com>
Date: Mon, 6 May 2024 16:16:48 +0800
From: Yang Jihong <yangjihong@...edance.com>
To: peterz@...radead.org,
mingo@...hat.com,
acme@...nel.org,
namhyung@...nel.org,
mark.rutland@....com,
alexander.shishkin@...ux.intel.com,
jolsa@...nel.org,
irogers@...gle.com,
adrian.hunter@...el.com,
kan.liang@...ux.intel.com,
james.clark@....com,
linux-perf-users@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: yangjihong@...edance.com
Subject: [PATCH] perf build: Specify libtraceevent dir to rpath for asan/msan build
perf built by asan/msan will not search for shared libraries in the
-L directory. For cross-compilation, we assume that sanitizers is
generally not enabled and add libtraceevent dir to rpath in a simple way.
1. msan build
Before:
$ make -C tools/perf O=/tmp/perf DEBUG=1 EXTRA_CFLAGS="-O0 -g -fno-omit-frame-pointer -fsanitize=memory -fsanitize-memory-track-origins" CC=clang CXX=clang++ HOSTCC=clang NO_LIBELF=1 BUILD_BPF_SKEL=0 NO_LIBPFM=1 LIBTRACEEVENT_DIR=/opt/libtraceevent
...
$ /tmp/perf/perf
/tmp/perf/perf: error while loading shared libraries: libtraceevent.so.1: cannot open shared object file: No such file or directory
After:
$ make -C tools/perf O=/tmp/perf DEBUG=1 EXTRA_CFLAGS="-O0 -g -fno-omit-frame-pointer -fsanitize=memory -fsanitize-memory-track-origins" CC=clang CXX=clang++ HOSTCC=clang NO_LIBELF=1 BUILD_BPF_SKEL=0 NO_LIBPFM=1 LIBTRACEEVENT_DIR=/opt/libtraceevent
...
$ /tmp/perf/perf --build-options
perf version 6.9.0-rc5
<SNIP>
libtraceevent: [ on ] # HAVE_LIBTRACEEVENT
<SNIP>
2. asan build
Before:
$ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=address' LIBTRACEEVENT_DIR=/opt/libtraceevent
...
$ ./perf
./perf: error while loading shared libraries: libtraceevent.so.1: cannot open shared object file: No such file or directory
After:
$ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=address' LIBTRACEEVENT_DIR=/opt/libtraceevent
...
$ ./perf --build-options
perf version 6.9.0-rc5
<SNIP>
libtraceevent: [ on ] # HAVE_LIBTRACEEVENT
<SNIP>
Signed-off-by: Yang Jihong <yangjihong@...edance.com>
---
tools/perf/Makefile.config | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 7f1e016a9253..a9a923358604 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -188,6 +188,10 @@ TRACEEVENTLIBS := -ltraceevent
ifdef LIBTRACEEVENT_DIR
LIBTRACEEVENT_CFLAGS := -I$(LIBTRACEEVENT_DIR)/include
LIBTRACEEVENT_LDFLAGS := -L$(LIBTRACEEVENT_DIR)/lib
+ # Specify rpath for asan/msan build. Generally, cross-compilation will not enable sanitizers.
+ ifeq ($(findstring -fsanitize=,${EXTRA_CFLAGS}),-fsanitize=)
+ LIBTRACEEVENT_LDFLAGS += -Wl,-rpath,$(LIBTRACEEVENT_DIR)/lib
+ endif
endif
FEATURE_CHECK_CFLAGS-libtraceevent := $(LIBTRACEEVENT_CFLAGS)
FEATURE_CHECK_LDFLAGS-libtraceevent := $(LIBTRACEEVENT_LDFLAGS) $(TRACEEVENTLIBS)
--
2.25.1
Powered by blists - more mailing lists