LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] perf build: Specify libtraceevent dir to rpath for asan/msan build on 64-bit
@ 2024-05-13  7:49 Yang Jihong
  2024-05-13  7:49 ` [PATCH v2 1/2] perf build: Specify libtraceevent dir to rpath for asan/msan build Yang Jihong
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yang Jihong @ 2024-05-13  7:49 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

This patchset is for asan build issues. For detailed discussion, see:
https://lore.kernel.org/all/CAP-5=fXJAu8OO_Gaw45Hx3uq6N8VQBNFhqcUy3Zm2vKT-TDSOQ@mail.gmail.com/
https://lore.kernel.org/all/CAP-5=fXYH4JnfQH98vPRttViBfYAWGA-aoGXO7q+R_Wt8AqFSw@mail.gmail.com/

Yang Jihong (2):
  perf build: Specify libtraceevent dir to rpath for asan/msan build
  perf build: Add libtraceevent lib64 to -L directory & rpath on 64-bit

 tools/perf/Makefile.config | 12 ++++++++++++
 1 file changed, 12 insertions(+)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] perf build: Specify libtraceevent dir to rpath for asan/msan build
  2024-05-13  7:49 [PATCH v2 0/2] perf build: Specify libtraceevent dir to rpath for asan/msan build on 64-bit Yang Jihong
@ 2024-05-13  7:49 ` Yang Jihong
  2024-05-13  7:49 ` [PATCH v2 2/2] perf build: Add libtraceevent lib64 to -L directory & rpath on 64-bit Yang Jihong
  2024-05-13 17:56 ` [PATCH v2 0/2] perf build: Specify libtraceevent dir to rpath for asan/msan build " Ian Rogers
  2 siblings, 0 replies; 4+ messages in thread
From: Yang Jihong @ 2024-05-13  7:49 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

* [PATCH v2 2/2] perf build: Add libtraceevent lib64 to -L directory & rpath on 64-bit
  2024-05-13  7:49 [PATCH v2 0/2] perf build: Specify libtraceevent dir to rpath for asan/msan build on 64-bit Yang Jihong
  2024-05-13  7:49 ` [PATCH v2 1/2] perf build: Specify libtraceevent dir to rpath for asan/msan build Yang Jihong
@ 2024-05-13  7:49 ` Yang Jihong
  2024-05-13 17:56 ` [PATCH v2 0/2] perf build: Specify libtraceevent dir to rpath for asan/msan build " Ian Rogers
  2 siblings, 0 replies; 4+ messages in thread
From: Yang Jihong @ 2024-05-13  7:49 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

For 64-bit system, libtraceevent will install these libraries into
lib64 directory, so add it to the -L directory and rpath as well.

build libtraceevent:
  $ make EXTRA_CFLAGS="-O0 -g -fsanitize=address" DESTDIR=~/libtrace install

Before:
  $ rm -rf /tmp/perf; mkdir /tmp/perf; 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 1>/dev/null
  Makefile.config:1146: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
  Makefile.config:1196: *** ERROR: libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel and/or set LIBTRACEEVENT_DIR or build with NO_LIBTRACEEVENT=1.  Stop.
  make[1]: *** [Makefile.perf:264: sub-make] Error 2
  make: *** [Makefile:70: all] Error 2

After:
  $ rm -rf /tmp/perf; mkdir /tmp/perf; 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 1>/dev/null
  Makefile.config:1154: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
    PERF_VERSION = 6.9.0-rc5
  $ echo $?
  0
  $ ldd /tmp/perf/perf
  <SINP>
  	libtraceevent.so.1 => /home/yangjihong/libtrace/usr/local/lib64/libtraceevent.so.1 (0x00007f08983d5000)
  <SINP>

Signed-off-by: Yang Jihong <yangjihong@bytedance.com>
---
 tools/perf/Makefile.config | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index a9a923358604..d632c85e6c4d 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -188,9 +188,17 @@ TRACEEVENTLIBS := -ltraceevent
 ifdef LIBTRACEEVENT_DIR
   LIBTRACEEVENT_CFLAGS  := -I$(LIBTRACEEVENT_DIR)/include
   LIBTRACEEVENT_LDFLAGS := -L$(LIBTRACEEVENT_DIR)/lib
+  # libtraceevent install libraries into lib64 on 64-bit, so add it to -L directory as well
+  ifeq (${IS_64_BIT}, 1)
+    LIBTRACEEVENT_LDFLAGS += -L$(LIBTRACEEVENT_DIR)/lib64
+  endif
   # 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
+    # libtraceevent install libraries into lib64 on 64-bit, so add it to rpath as well
+    ifeq (${IS_64_BIT}, 1)
+      LIBTRACEEVENT_LDFLAGS += -Wl,-rpath,$(LIBTRACEEVENT_DIR)/lib64
+    endif
   endif
 endif
 FEATURE_CHECK_CFLAGS-libtraceevent := $(LIBTRACEEVENT_CFLAGS)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] perf build: Specify libtraceevent dir to rpath for asan/msan build on 64-bit
  2024-05-13  7:49 [PATCH v2 0/2] perf build: Specify libtraceevent dir to rpath for asan/msan build on 64-bit Yang Jihong
  2024-05-13  7:49 ` [PATCH v2 1/2] perf build: Specify libtraceevent dir to rpath for asan/msan build Yang Jihong
  2024-05-13  7:49 ` [PATCH v2 2/2] perf build: Add libtraceevent lib64 to -L directory & rpath on 64-bit Yang Jihong
@ 2024-05-13 17:56 ` Ian Rogers
  2 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2024-05-13 17:56 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:49 AM Yang Jihong <yangjihong@bytedance.com> wrote:
>
> This patchset is for asan build issues. For detailed discussion, see:
> https://lore.kernel.org/all/CAP-5=fXJAu8OO_Gaw45Hx3uq6N8VQBNFhqcUy3Zm2vKT-TDSOQ@mail.gmail.com/
> https://lore.kernel.org/all/CAP-5=fXYH4JnfQH98vPRttViBfYAWGA-aoGXO7q+R_Wt8AqFSw@mail.gmail.com/
>
> Yang Jihong (2):
>   perf build: Specify libtraceevent dir to rpath for asan/msan build
>   perf build: Add libtraceevent lib64 to -L directory & rpath on 64-bit

Great, thanks!
Tested-by: Ian Rogers <irogers@google.com>

>  tools/perf/Makefile.config | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-13 17:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-13  7:49 [PATCH v2 0/2] perf build: Specify libtraceevent dir to rpath for asan/msan build on 64-bit Yang Jihong
2024-05-13  7:49 ` [PATCH v2 1/2] perf build: Specify libtraceevent dir to rpath for asan/msan build Yang Jihong
2024-05-13  7:49 ` [PATCH v2 2/2] perf build: Add libtraceevent lib64 to -L directory & rpath on 64-bit Yang Jihong
2024-05-13 17:56 ` [PATCH v2 0/2] perf build: Specify libtraceevent dir to rpath for asan/msan build " 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 read-only IMAP folder(s) and NNTP newsgroup(s).