Skip to contentSkip to conversation

perf tools: Fix static building

PATCH In review Alexey Brodkin 3 participants 6 messages Aug 22, 2016 – Sep 14, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf tools: Fix static building

With commit e3d09ec8126f ("tools lib traceevent: Export dynamic symbols used by traceevent plugins") we started to add "--dynamic-list" in LDFLAGS. One side-effect of that was inability to build really statically-linked perf.

I.e. even if "LDFLAGS=-static" were passed on perf building command-line it had no effect and perf was built dynamically.

This change disables setup of "--dynamic-list" if LDFLAGS contains "-static" option.

Signed-off-by Alexey Brodkin <abrodkin at synopsys.com>
Cc Arnaldo Carvalho de Melo <acme at redhat.com>
Cc Vineet Gupta <vgupta at synopsys.com>
Cc Wang Nan <wangnan0 at huawei.com>
Cc Jiri Olsa <jolsa at kernel.org>
Cc He Kuang <hekuang at huawei.com>
Cc Masami Hiramatsu <masami.hiramatsu.pt at hitachi.com>
Cc Namhyung Kim <namhyung at kernel.org>
Cc Peter Zijlstra <a.p.zijlstra at chello.nl>
Cc Zefan Li <lizefan at huawei.com>
Cc pi3orama at 163.com
---
 tools/perf/Makefile.perf | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/Makefile.perf +2 -0
index 2d908750..e9acc7c 100644
@@ -236,7 +236,9 @@ LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
 export LIBTRACEEVENT
 
 LIBTRACEEVENT_DYNAMIC_LIST = $(TE_PATH)libtraceevent-dynamic-list
+ifeq ($(filter -static,$(LDFLAGS)),)
 LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST)
+endif
 
 LIBAPI = $(API_PATH)libapi.a
 export LIBAPI
Signature · 1 line
2.7.4
#1 lore raw
Quoted 31 lines · Alexey Brodkin

With commit e3d09ec8126f ("tools lib traceevent: Export dynamic symbols used by traceevent plugins") we started to add "--dynamic-list" in LDFLAGS. One side-effect of that was inability to build really statically-linked perf.

I.e. even if "LDFLAGS=-static" were passed on perf building command-line it had no effect and perf was built dynamically.

This change disables setup of "--dynamic-list" if LDFLAGS contains "-static" option.

Signed-off-by Alexey Brodkin <abrodkin at synopsys.com>
Cc Arnaldo Carvalho de Melo <acme at redhat.com>
Cc Vineet Gupta <vgupta at synopsys.com>
Cc Wang Nan <wangnan0 at huawei.com>
Cc Jiri Olsa <jolsa at kernel.org>
Cc He Kuang <hekuang at huawei.com>
Cc Masami Hiramatsu <masami.hiramatsu.pt at hitachi.com>
Cc Namhyung Kim <namhyung at kernel.org>
Cc Peter Zijlstra <a.p.zijlstra at chello.nl>
Cc Zefan Li <lizefan at huawei.com>
Cc pi3orama at 163.com
---
 tools/perf/Makefile.perf | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/Makefile.perf +0 -0
index 2d908750..e9acc7c 100644

tools/perf/Makefile.perf LIBTRACEEVENT = $(TE_PATH)libtraceevent.a · line 244

Quoted 9 lines
tools/perf/Makefile.perf +2 -0
@@ -236,7 +236,9 @@ LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
 export LIBTRACEEVENT
 
 LIBTRACEEVENT_DYNAMIC_LIST = $(TE_PATH)libtraceevent-dynamic-list
+ifeq ($(filter -static,$(LDFLAGS)),)
 LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST)
+endif
 
 LIBAPI = $(API_PATH)libapi.a
 export LIBAPI

Gentle Ping while Alexey is away on vacation !
Arnaldo are you ok with this patch.

Thx,
-Vineet

#2 lore raw
In reply to Alexey Brodkin
Quoted 4 lines · Alexey Brodkin

With commit e3d09ec8126f ("tools lib traceevent: Export dynamic symbols used by traceevent plugins") we started to add "--dynamic-list" in LDFLAGS. One side-effect of that was inability to build really statically-linked perf.

IIRC --dynamic-list forces perf to exports some symbols to be used by plugins.. don't see this breaking static build

also it's working properly for me:

[jolsa at krava perf]$ make LDFLAGS=-static
...
[jolsa at krava perf]$ ldd ./perf
not a dynamic executable

unless I miss what you mean by 'really statically-linked' ;-)

Maybe different features enabled/build environment could you please send the .config-detected along with the build error?

thanks,
jirka

#3 lore raw
Quoted 9 lines · Jiri Olsa
Quoted 4 lines · Alexey Brodkin

With commit e3d09ec8126f ("tools lib traceevent: Export dynamic symbols used by traceevent plugins") we started to add "--dynamic-list" in LDFLAGS. One side-effect of that was inability to build really statically-linked perf.

IIRC --dynamic-list forces perf to exports some symbols to be used by plugins.. don't see this breaking static build

Quoted 8 lines

also it's working properly for me:

[jolsa at krava perf]$ make LDFLAGS=-static
...
[jolsa at krava perf]$ ldd ./perf
not a dynamic executable

unless I miss what you mean by 'really statically-linked' ;-)

Right - so I tried this as well and indeed I can confirm that it builds for me as static. Atleast the build system doesn;t need changing as -sattic being propagated to fianl link cmd.

There seems to be some weirdness with ARC tools: file reports

| ELF 32-bit LSB executable, *unknown arch 0xc3* version 1 (SYSV), | dynamically linked, interpreter *empty*, for GNU/Linux 3.9.0, not stripped

That is clearly wrong !

And the static binary as expected doesn't seem to run on target - exits with -EACCESS.

-Vineet

#4 lore raw

Hi Vineet, Jiri,

Quoted 28 lines · Vineet Gupta
Quoted 11 lines · Jiri Olsa
Quoted 5 lines · Alexey Brodkin

With commit e3d09ec8126f ("tools lib traceevent: Export dynamic symbols used by traceevent plugins") we started to add "--dynamic-list" in LDFLAGS. One side-effect of that was inability to build really statically-linked perf.

IIRC --dynamic-list forces perf to exports some symbols to be used by plugins.. don't see this breaking static build

Quoted 8 lines

also it's working properly for me:

[jolsa at krava perf]$ make LDFLAGS=-static
...
[jolsa at krava perf]$ ldd ./perf
????????not a dynamic executable

unless I miss what you mean by 'really statically-linked' ;-)

Right - so I tried this as well and indeed I can confirm that it builds for me as static. Atleast the build system doesn;t need changing as -sattic being propagated to fianl link cmd.

There seems to be some weirdness with ARC tools: file reports

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

ELF 32-bit LSB executable, *unknown arch 0xc3* version 1 (SYSV), dynamically linked, interpreter *empty*, for GNU/Linux 3.9.0, not stripped

That is clearly wrong !

And the static binary as expected doesn't seem to run on target - exits with -EACCESS.

I may confirm what Vineet said already adding just that funny ldd output on target:
-------------------->8-----------------

# ldd /home/perf?
	 =>??(0x00000000)
-------------------->8-----------------

Just for comparison that's ldd output for dynamically built perf:
-------------------->8-----------------

# ldd /usr/bin/perf?
checking sub-depends for '/lib/libpthread.so.0'
checking sub-depends for '/lib/librt.so.0'
checking sub-depends for '/lib/libm.so.0'
checking sub-depends for '/lib/libdl.so.0'
checking sub-depends for '/lib/libc.so.0'
	libpthread.so.0 => /lib/libpthread.so.0 (0x00000000)
	librt.so.0 => /lib/librt.so.0 (0x00000000)
	libm.so.0 => /lib/libm.so.0 (0x00000000)
	libdl.so.0 => /lib/libdl.so.0 (0x00000000)
	libc.so.0 => /lib/libc.so.0 (0x00000000)
	/lib/ld-uClibc.so.1 => /lib/ld-uClibc.so.1 (0x00000000)
-------------------->8-----------------

And most probably the reason for me to think perf built with LDFLAGS=-static
was not static is indeed "file" output:
-------------------->8-----------------
file tools/perf/perf
tools/perf/perf: ELF 32-bit LSB executable, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.9.0, not stripped
-------------------->8-----------------

Sorry for the noise.

-Alexey

#5 lore raw
In reply to Alexey Brodkin
Quoted 31 lines · Alexey Brodkin

With commit e3d09ec8126f ("tools lib traceevent: Export dynamic symbols used by traceevent plugins") we started to add "--dynamic-list" in LDFLAGS. One side-effect of that was inability to build really statically-linked perf.

I.e. even if "LDFLAGS=-static" were passed on perf building command-line it had no effect and perf was built dynamically.

This change disables setup of "--dynamic-list" if LDFLAGS contains "-static" option.

Signed-off-by Alexey Brodkin <abrodkin at synopsys.com>
Cc Arnaldo Carvalho de Melo <acme at redhat.com>
Cc Vineet Gupta <vgupta at synopsys.com>
Cc Wang Nan <wangnan0 at huawei.com>
Cc Jiri Olsa <jolsa at kernel.org>
Cc He Kuang <hekuang at huawei.com>
Cc Masami Hiramatsu <masami.hiramatsu.pt at hitachi.com>
Cc Namhyung Kim <namhyung at kernel.org>
Cc Peter Zijlstra <a.p.zijlstra at chello.nl>
Cc Zefan Li <lizefan at huawei.com>
Cc pi3orama at 163.com
---
 tools/perf/Makefile.perf | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/Makefile.perf +0 -0
index 2d908750..e9acc7c 100644

tools/perf/Makefile.perf LIBTRACEEVENT = $(TE_PATH)libtraceevent.a · line 241

Quoted 6 lines
tools/perf/Makefile.perf +2 -0
@@ -236,7 +236,9 @@ LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
 export LIBTRACEEVENT
 
 LIBTRACEEVENT_DYNAMIC_LIST = $(TE_PATH)libtraceevent-dynamic-list
+ifeq ($(filter -static,$(LDFLAGS)),)
 LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYNAMIC_LIST)
+endif

hum, e3d09ec8126f changelog mentioned python feature adding this by default

but not sure python could be added within static build

jirka

Quoted 6 lines
tools/perf/Makefile.perf +0 -0
 LIBAPI = $(API_PATH)libapi.a
 export LIBAPI
Signature · 1 line
2.7.4