Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751728AbbEXIaw (ORCPT ); Sun, 24 May 2015 04:30:52 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:1947 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751700AbbEXIar (ORCPT ); Sun, 24 May 2015 04:30:47 -0400 Subject: Re: [PATCH v3 1/2] tools lib traceevent: Export dynamic symbols used by traceevent plugins To: , , , References: <1431676879-19724-1-git-send-email-hekuang@huawei.com> CC: , From: He Kuang Message-ID: <55618C1A.7010208@huawei.com> Date: Sun, 24 May 2015 16:30:18 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.0 MIME-Version: 1.0 In-Reply-To: <1431676879-19724-1-git-send-email-hekuang@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.110.54.65] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5616 Lines: 152 hi, jirka ping.. Thanks. On 2015/5/15 16:01, He Kuang wrote: > Traceevent plugins need dynamic symbols exported from libtraceevent.a, > otherwise a dlopen error will occur during plugins loading. > > This patch uses dynamic-list-file to export dynamic symbols which will > be used in plugins to perf executable. > > The problem is covered up if feature-libpython is enabled, because > PYTHON_EMBED_LDOPTS contains '-Xlinker --export-dynamic' which adds all > symbols to the dynamic symbol table. So we should reproduce the problem > by setting NO_LIBPYTHON=1. > > Before this patch: > > (Prepare plugins) > $ ls /root/.traceevent/plugins/ > plugin_sched_switch.so > plugin_function.so > ... > > $ perf record -e 'ftrace:function' ls > > $ perf script > Warning: could not load plugin '/mnt/data/root/.traceevent/plugins/plugin_sched_switch.so' > /root/.traceevent/plugins/plugin_sched_switch.so: undefined symbol: pevent_unregister_event_handler > > Warning: could not load plugin '/root/.traceevent/plugins/plugin_function.so' > /root/.traceevent/plugins/plugin_function.so: undefined symbol: warning > ... > :1049 1049 [000] 9666.754487: ftrace:function: ffffffff8118bc50 <-- ffffffff8118c5b3 > :1049 1049 [000] 9666.754487: ftrace:function: ffffffff818e2440 <-- ffffffff8118bc75 > :1049 1049 [000] 9666.754487: ftrace:function: ffffffff8106eee0 <-- ffffffff811212e2 > > After this patch: > > $ perf record -e 'ftrace:function' ls > $ perf script > :1049 1049 [000] 9666.754487: ftrace:function: __set_task_comm > :1049 1049 [000] 9666.754487: ftrace:function: _raw_spin_lock > :1049 1049 [000] 9666.754487: ftrace:function: task_tgid_nr_ns > ... > > Signed-off-by: He Kuang > --- > tools/lib/traceevent/Makefile | 14 +++++++++++++- > tools/perf/Makefile.perf | 14 ++++++++++++-- > 2 files changed, 25 insertions(+), 3 deletions(-) > > diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile > index d410da3..2cbac13 100644 > --- a/tools/lib/traceevent/Makefile > +++ b/tools/lib/traceevent/Makefile > @@ -23,6 +23,7 @@ endef > # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. > $(call allow-override,CC,$(CROSS_COMPILE)gcc) > $(call allow-override,AR,$(CROSS_COMPILE)ar) > +$(call allow-override,NM,$(CROSS_COMPILE)nm) > > EXT = -std=gnu99 > INSTALL = install > @@ -151,8 +152,9 @@ PLUGINS_IN := $(PLUGINS:.so=-in.o) > > TE_IN := $(OUTPUT)libtraceevent-in.o > LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE)) > +DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list > > -CMD_TARGETS = $(LIB_FILE) $(PLUGINS) > +CMD_TARGETS = $(LIB_FILE) $(PLUGINS) $(DYNAMIC_LIST_FILE) > > TARGETS = $(CMD_TARGETS) > > @@ -169,6 +171,9 @@ $(OUTPUT)libtraceevent.so: $(TE_IN) > $(OUTPUT)libtraceevent.a: $(TE_IN) > $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ > > +$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS) > + $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@) > + > plugins: $(PLUGINS) > > __plugin_obj = $(notdir $@) > @@ -238,6 +243,13 @@ define do_install_plugins > done > endef > > +define do_generate_dynamic_list_file > + (echo '{'; \ > + $(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u; \ > + echo '};'; \ > + ) > $2 > +endef > + > install_lib: all_cmd install_plugins > $(call QUIET_INSTALL, $(LIB_FILE)) \ > $(call do_install,$(LIB_FILE),$(bindir_SQ)) > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf > index 03409cc..1e6e038 100644 > --- a/tools/perf/Makefile.perf > +++ b/tools/perf/Makefile.perf > @@ -173,6 +173,9 @@ endif > LIBTRACEEVENT = $(TE_PATH)libtraceevent.a > export LIBTRACEEVENT > > +LIBTRACEEVENT_DYNAMIC_LIST = $(TE_PATH)libtraceevent-dynamic-list > +LDFLAGS += -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST) > + > LIBAPI = $(LIB_PATH)libapi.a > export LIBAPI > > @@ -278,7 +281,7 @@ build := -f $(srctree)/tools/build/Makefile.build dir=. obj > $(PERF_IN): $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h FORCE > $(Q)$(MAKE) $(build)=perf > > -$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) > +$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(LIBTRACEEVENT_DYNAMIC_LIST) > $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(PERF_IN) $(LIBS) -o $@ > > $(GTK_IN): FORCE > @@ -373,7 +376,13 @@ $(LIB_FILE): $(LIBPERF_IN) > LIBTRACEEVENT_FLAGS += plugin_dir=$(plugindir_SQ) > > $(LIBTRACEEVENT): FORCE > - $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) $(OUTPUT)libtraceevent.a plugins > + $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) $(OUTPUT)libtraceevent.a > + > +libtraceevent_plugins: FORCE > + $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) plugins > + > +$(LIBTRACEEVENT_DYNAMIC_LIST): libtraceevent_plugins > + $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) $(OUTPUT)libtraceevent-dynamic-list > > $(LIBTRACEEVENT)-clean: > $(call QUIET_CLEAN, libtraceevent) > @@ -551,4 +560,5 @@ FORCE: > .PHONY: all install clean config-clean strip install-gtk > .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell > .PHONY: $(GIT-HEAD-PHONY) TAGS tags cscope FORCE single_dep > +.PHONY: libtraceevent_plugins > > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/