* [PATCH] perf build: Specify libtraceevent dir to rpath for asan/msan build
@ 2024-05-06 8:16 Yang Jihong
2024-05-08 23:18 ` Ian Rogers
0 siblings, 1 reply; 4+ messages in thread
From: Yang Jihong @ 2024-05-06 8:16 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, irogers, adrian.hunter, kan.liang, james.clark,
linux-perf-users, linux-kernel
Cc: yangjihong
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@bytedance.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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] perf build: Specify libtraceevent dir to rpath for asan/msan build
2024-05-06 8:16 [PATCH] perf build: Specify libtraceevent dir to rpath for asan/msan build Yang Jihong
@ 2024-05-08 23:18 ` Ian Rogers
2024-05-13 7:53 ` Yang Jihong
0 siblings, 1 reply; 4+ messages in thread
From: Ian Rogers @ 2024-05-08 23:18 UTC (permalink / raw)
To: Yang Jihong
Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, adrian.hunter, kan.liang, james.clark, linux-perf-users,
linux-kernel
On Mon, May 6, 2024 at 1:17 AM Yang Jihong <yangjihong@bytedance.com> wrote:
>
> 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@bytedance.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
Thanks for this! I found I need the following to make it work:
```
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index a9a923358604..bcf4ab292462 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -190,7 +190,11 @@ ifdef LIBTRACEEVENT_DIR
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
+ ifeq (${IS_64_BIT}, 1)
+ LIBTRACEEVENT_LDFLAGS += -Wl,-rpath,$(LIBTRACEEVENT_DIR)/lib64
+ else
+ LIBTRACEEVENT_LDFLAGS += -Wl,-rpath,$(LIBTRACEEVENT_DIR)/lib
+ endif
endif
endif
FEATURE_CHECK_CFLAGS-libtraceevent := $(LIBTRACEEVENT_CFLAGS)
```
My libtraceevent build command is:
$ make EXTRA_CFLAGS="-O0 -g -fsanitize=address" DESTDIR=~/libtrace install
and I build perf with:
$ make -C tools/perf O=/tmp/perf DEBUG=1 EXTRA_CFLAGS="-O0 -g
-fno-omit-frame-pointer -fsanitize=address -Wno-error=unused-function"
LIBTRACEEVENT_DIR=~/libtrace/usr/local
I'm checking which library is used with ldd.
Thanks,
Ian
> endif
> FEATURE_CHECK_CFLAGS-libtraceevent := $(LIBTRACEEVENT_CFLAGS)
> FEATURE_CHECK_LDFLAGS-libtraceevent := $(LIBTRACEEVENT_LDFLAGS) $(TRACEEVENTLIBS)
> --
> 2.25.1
>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] perf build: Specify libtraceevent dir to rpath for asan/msan build
2024-05-08 23:18 ` Ian Rogers
@ 2024-05-13 7:53 ` Yang Jihong
2024-05-13 17:57 ` Ian Rogers
0 siblings, 1 reply; 4+ messages in thread
From: Yang Jihong @ 2024-05-13 7:53 UTC (permalink / raw)
To: Ian Rogers
Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, adrian.hunter, kan.liang, james.clark, linux-perf-users,
linux-kernel
Hello,
On 5/9/24 07:18, Ian Rogers wrote:
> On Mon, May 6, 2024 at 1:17 AM Yang Jihong <yangjihong@bytedance.com> wrote:
>>
>> 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@bytedance.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
>
> Thanks for this! I found I need the following to make it work:
> ```
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index a9a923358604..bcf4ab292462 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -190,7 +190,11 @@ ifdef LIBTRACEEVENT_DIR
> 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
> + ifeq (${IS_64_BIT}, 1)
> + LIBTRACEEVENT_LDFLAGS += -Wl,-rpath,$(LIBTRACEEVENT_DIR)/lib64
> + else
> + LIBTRACEEVENT_LDFLAGS += -Wl,-rpath,$(LIBTRACEEVENT_DIR)/lib
> + endif
> endif
> endif
> FEATURE_CHECK_CFLAGS-libtraceevent := $(LIBTRACEEVENT_CFLAGS)
> ```
>
> My libtraceevent build command is:
> $ make EXTRA_CFLAGS="-O0 -g -fsanitize=address" DESTDIR=~/libtrace install
My build environment only uses make, not make install, so the library
path is lib, not lib64, which leads to this difference.
# cd /opt/libtraceevent
# CROSS_COMPILE=aarch64-linux-gnu- make
In order to be compatible with both situations, would it be better for
us to also add the lib64 path to -L and rpath?
I have sent the v2 version and added it to path2. Please help me see if
this solution is OK:
https://lore.kernel.org/all/20240513074910.1660373-1-yangjihong@bytedance.com/
Thanks,
Yang
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf build: Specify libtraceevent dir to rpath for asan/msan build
2024-05-13 7:53 ` Yang Jihong
@ 2024-05-13 17:57 ` Ian Rogers
0 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2024-05-13 17:57 UTC (permalink / raw)
To: Yang Jihong
Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, adrian.hunter, kan.liang, james.clark, linux-perf-users,
linux-kernel
On Mon, May 13, 2024 at 12:53 AM Yang Jihong <yangjihong@bytedance.com> wrote:
>
> Hello,
>
> On 5/9/24 07:18, Ian Rogers wrote:
> > On Mon, May 6, 2024 at 1:17 AM Yang Jihong <yangjihong@bytedance.com> wrote:
> >>
> >> 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@bytedance.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
> >
> > Thanks for this! I found I need the following to make it work:
> > ```
> > diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> > index a9a923358604..bcf4ab292462 100644
> > --- a/tools/perf/Makefile.config
> > +++ b/tools/perf/Makefile.config
> > @@ -190,7 +190,11 @@ ifdef LIBTRACEEVENT_DIR
> > 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
> > + ifeq (${IS_64_BIT}, 1)
> > + LIBTRACEEVENT_LDFLAGS += -Wl,-rpath,$(LIBTRACEEVENT_DIR)/lib64
> > + else
> > + LIBTRACEEVENT_LDFLAGS += -Wl,-rpath,$(LIBTRACEEVENT_DIR)/lib
> > + endif
> > endif
> > endif
> > FEATURE_CHECK_CFLAGS-libtraceevent := $(LIBTRACEEVENT_CFLAGS)
> > ```
> >
> > My libtraceevent build command is:
> > $ make EXTRA_CFLAGS="-O0 -g -fsanitize=address" DESTDIR=~/libtrace install
> My build environment only uses make, not make install, so the library
> path is lib, not lib64, which leads to this difference.
>
> # cd /opt/libtraceevent
> # CROSS_COMPILE=aarch64-linux-gnu- make
>
> In order to be compatible with both situations, would it be better for
> us to also add the lib64 path to -L and rpath?
>
> I have sent the v2 version and added it to path2. Please help me see if
> this solution is OK:
> https://lore.kernel.org/all/20240513074910.1660373-1-yangjihong@bytedance.com/
That fixed the issue for me. Thanks!
Ian
>
> Thanks,
> Yang
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-13 17:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-06 8:16 [PATCH] perf build: Specify libtraceevent dir to rpath for asan/msan build Yang Jihong
2024-05-08 23:18 ` Ian Rogers
2024-05-13 7:53 ` Yang Jihong
2024-05-13 17:57 ` Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).