All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tools: Fix linking errors with --as-needed flag
@ 2010-07-18 10:45 Ozan Çağlayan
  2010-07-18 11:04 ` Ozan Çağlayan
  0 siblings, 1 reply; 11+ messages in thread
From: Ozan Çağlayan @ 2010-07-18 10:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: acme, mst, mingo

External shared libraries should never be appended to the LDFLAGS as
this messes the linking order. As EXTLIBS collects those libraries,
it seems that perl and python libraries  should also be appended
to EXTLIBS.

Also fix the broken linking order.

See:
  http://www.gentoo.org/proj/en/qa/asneeded.xml

Signed-off-by: Ozan Çağlayan <ozan@pardus.org.tr>
---
 tools/perf/Makefile |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 3d8f31e..98c537f 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -580,7 +580,7 @@ endif
 ifneq ($(shell sh -c "(echo '\#include <EXTERN.h>'; echo '\#include <perl.h>'; echo 'int main(void) { perl_alloc(); return 0; }') | $(CC) -x c - $(PERL_EMBED_CCOPTS) -o $(BITBUCKET) $(PERL_EMBED_LDOPTS) > /dev/null 2>&1 && echo y"), y)
 	BASIC_CFLAGS += -DNO_LIBPERL
 else
-	ALL_LDFLAGS += $(PERL_EMBED_LDOPTS)
+	EXTLIBS += $(PERL_EMBED_LDOPTS)
 	LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
 	LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
 endif
@@ -593,7 +593,7 @@ endif
 ifneq ($(shell sh -c "(echo '\#include <Python.h>'; echo 'int main(void) { Py_Initialize(); return 0; }') | $(CC) -x c - $(PYTHON_EMBED_CCOPTS) -o $(BITBUCKET) $(PYTHON_EMBED_LDOPTS) > /dev/null 2>&1 && echo y"), y)
 	BASIC_CFLAGS += -DNO_LIBPYTHON
 else
-	ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
+	EXTLIBS += $(PYTHON_EMBED_LDOPTS)
 	LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
 	LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
 endif
@@ -886,8 +886,8 @@ $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
 		$(ALL_CFLAGS) -c $(filter %.c,$^) -o $@
 
 $(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(OUTPUT)perf.o \
-		$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
+	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \
+		$(BUILTIN_OBJS) $(LIBS) -o $@
 
 $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
-- 
1.7.1


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

* Re: [PATCH] perf tools: Fix linking errors with --as-needed flag
  2010-07-18 10:45 [PATCH] perf tools: Fix linking errors with --as-needed flag Ozan Çağlayan
@ 2010-07-18 11:04 ` Ozan Çağlayan
  2010-08-21 17:24   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 11+ messages in thread
From: Ozan Çağlayan @ 2010-07-18 11:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: acme, mst, mingo

On 18.07.2010 13:45, Ozan Çağlayan wrote:
> External shared libraries should never be appended to the LDFLAGS as
> this messes the linking order. As EXTLIBS collects those libraries,
> it seems that perl and python libraries  should also be appended
> to EXTLIBS.
> 
> Also fix the broken linking order.

Hm actually the PERL_EMBED_LDOPTS may contain LDFLAGS and LIBADD according
to distribution's perl package configuration's goodness/badness. On my system
the return value is crap which bloats the linking process:

 -rdynamic -Wl,-rpath,/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE -lperl -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc

PYTHON_EMBED_LDOPTS evaluates python-config --ldflags and adds these to 
ALL_LDFLAGS. (--libs and --ldflags are synonyms for python-config). According
to python-config this code *never* returns LDFLAGS so it's safe to put them in
EXTLIBS.

So the cure may be more than this patch for perl stuff, but at least it fixes my
linking problems with -Wl, --as-needed.


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

* Re: [PATCH] perf tools: Fix linking errors with --as-needed flag
  2010-07-18 11:04 ` Ozan Çağlayan
@ 2010-08-21 17:24   ` Arnaldo Carvalho de Melo
  2010-08-22  6:43     ` Tom Zanussi
  0 siblings, 1 reply; 11+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-08-21 17:24 UTC (permalink / raw)
  To: Ozan Çağlayan
  Cc: Kirill A. Shutemov, Tom Zanussi, linux-kernel, mingo

Em Sun, Jul 18, 2010 at 02:04:32PM +0300, Ozan Çağlayan escreveu:
> On 18.07.2010 13:45, Ozan Çağlayan wrote:
> > External shared libraries should never be appended to the LDFLAGS as
> > this messes the linking order. As EXTLIBS collects those libraries,
> > it seems that perl and python libraries  should also be appended
> > to EXTLIBS.
> > 
> > Also fix the broken linking order.
> 
> Hm actually the PERL_EMBED_LDOPTS may contain LDFLAGS and LIBADD according
> to distribution's perl package configuration's goodness/badness. On my system
> the return value is crap which bloats the linking process:
> 
>  -rdynamic -Wl,-rpath,/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE -lperl -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
> 
> PYTHON_EMBED_LDOPTS evaluates python-config --ldflags and adds these to 
> ALL_LDFLAGS. (--libs and --ldflags are synonyms for python-config). According
> to python-config this code *never* returns LDFLAGS so it's safe to put them in
> EXTLIBS.
> 
> So the cure may be more than this patch for perl stuff, but at least it fixes my
> linking problems with -Wl, --as-needed.

Can you refresh this patch? I had it in the back of my mind, remembered
it when considering a similar patch by Kirill, but his covers just the
python case.

Tom, can you please check Ozan's and Kirill's patches and tell me if I
can stick your Acked-by to them?

I'll CC you on the Kirill patch on private cover.

- Arnaldo

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

* Re: [PATCH] perf tools: Fix linking errors with --as-needed flag
  2010-08-21 17:24   ` Arnaldo Carvalho de Melo
@ 2010-08-22  6:43     ` Tom Zanussi
  2010-08-23  2:44       ` Tom Zanussi
  0 siblings, 1 reply; 11+ messages in thread
From: Tom Zanussi @ 2010-08-22  6:43 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ozan Çağlayan, Kirill A. Shutemov, linux-kernel, mingo

Hi,

On Sat, 2010-08-21 at 14:24 -0300, Arnaldo Carvalho de Melo wrote:
> Em Sun, Jul 18, 2010 at 02:04:32PM +0300, Ozan Çağlayan escreveu:
> > On 18.07.2010 13:45, Ozan Çağlayan wrote:
> > > External shared libraries should never be appended to the LDFLAGS as
> > > this messes the linking order. As EXTLIBS collects those libraries,
> > > it seems that perl and python libraries  should also be appended
> > > to EXTLIBS.
> > > 
> > > Also fix the broken linking order.
> > 
> > Hm actually the PERL_EMBED_LDOPTS may contain LDFLAGS and LIBADD according
> > to distribution's perl package configuration's goodness/badness. On my system
> > the return value is crap which bloats the linking process:
> > 
> >  -rdynamic -Wl,-rpath,/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE -lperl -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
> > 
> > PYTHON_EMBED_LDOPTS evaluates python-config --ldflags and adds these to 
> > ALL_LDFLAGS. (--libs and --ldflags are synonyms for python-config). According
> > to python-config this code *never* returns LDFLAGS so it's safe to put them in
> > EXTLIBS.
> > 
> > So the cure may be more than this patch for perl stuff, but at least it fixes my
> > linking problems with -Wl, --as-needed.
> 
> Can you refresh this patch? I had it in the back of my mind, remembered
> it when considering a similar patch by Kirill, but his covers just the
> python case.
> 
> Tom, can you please check Ozan's and Kirill's patches and tell me if I
> can stick your Acked-by to them?
> 

I refreshed Ozan's patch against tip and tried both with and without
-Wl,--as-needed and it worked fine for both Perl and Python, on my
Ubuntu 9.10 system.  The refreshed patch I used is included below.

It wasn't clear to me whether Ozan's PERL_EMBED_LDOPTS output still
caused link errors; here's mine, which didn't:

trz@tropicana:~$ perl -MExtUtils::Embed -e ldopts
-Wl,-E  -L/usr/local/lib  -L/usr/lib/perl/5.10/CORE -lperl -ldl -lm
-lpthread -lc -lcrypt

In any case, since neither ExtUtils::Embed nor python-config seem to
have a way to get the LDFLAGS and LIBADD components separately, we'll
have to find some other way to do that if necessary.

trz@tropicana:~$ python-config --libs
-lpthread -ldl -lutil -lm -lpython2.6
trz@tropicana:~$ python-config --ldflags
-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm -lpython2.6


Acked-by: Tom Zanussi <tzanussi@gmail.com>

---
 tools/perf/Makefile |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 4f1fa77..f35e784 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -595,7 +595,7 @@ else
 	ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED)),y)
 		BASIC_CFLAGS += -DNO_LIBPERL
 	else
-		ALL_LDFLAGS += $(PERL_EMBED_LDOPTS)
+		EXTLIBS += $(PERL_EMBED_LDOPTS)
 		LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
 		LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
 	endif
@@ -610,7 +610,7 @@ else
 	ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y)
 		BASIC_CFLAGS += -DNO_LIBPYTHON
 	else
-		ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
+		EXTLIBS += $(PYTHON_EMBED_LDOPTS)
 		LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
 		LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
 	endif
@@ -910,8 +910,8 @@ $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
 		$(ALL_CFLAGS) -c $(filter %.c,$^) -o $@
 
 $(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(OUTPUT)perf.o \
-		$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
+	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \
+		$(BUILTIN_OBJS) $(LIBS) -o $@
 
 $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
-- 
1.6.4.GIT




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

* Re: [PATCH] perf tools: Fix linking errors with --as-needed flag
  2010-08-22  6:43     ` Tom Zanussi
@ 2010-08-23  2:44       ` Tom Zanussi
  2010-08-23 14:38         ` Arnaldo Carvalho de Melo
  2010-08-23 16:53         ` Kirill A. Shutemov
  0 siblings, 2 replies; 11+ messages in thread
From: Tom Zanussi @ 2010-08-23  2:44 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Ozan Çağlayan, Kirill A. Shutemov, linux-kernel, mingo

On Sun, 2010-08-22 at 01:43 -0500, Tom Zanussi wrote:
> Hi,
> 
> On Sat, 2010-08-21 at 14:24 -0300, Arnaldo Carvalho de Melo wrote:
> > Em Sun, Jul 18, 2010 at 02:04:32PM +0300, Ozan Çağlayan escreveu:
> > > On 18.07.2010 13:45, Ozan Çağlayan wrote:
> > > > External shared libraries should never be appended to the LDFLAGS as
> > > > this messes the linking order. As EXTLIBS collects those libraries,
> > > > it seems that perl and python libraries  should also be appended
> > > > to EXTLIBS.
> > > > 
> > > > Also fix the broken linking order.
> > > 
> > > Hm actually the PERL_EMBED_LDOPTS may contain LDFLAGS and LIBADD according
> > > to distribution's perl package configuration's goodness/badness. On my system
> > > the return value is crap which bloats the linking process:
> > > 
> > >  -rdynamic -Wl,-rpath,/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE -lperl -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
> > > 
> > > PYTHON_EMBED_LDOPTS evaluates python-config --ldflags and adds these to 
> > > ALL_LDFLAGS. (--libs and --ldflags are synonyms for python-config). According
> > > to python-config this code *never* returns LDFLAGS so it's safe to put them in
> > > EXTLIBS.
> > > 
> > > So the cure may be more than this patch for perl stuff, but at least it fixes my
> > > linking problems with -Wl, --as-needed.
> > 
> > Can you refresh this patch? I had it in the back of my mind, remembered
> > it when considering a similar patch by Kirill, but his covers just the
> > python case.
> > 
> > Tom, can you please check Ozan's and Kirill's patches and tell me if I
> > can stick your Acked-by to them?
> > 
> 
> I refreshed Ozan's patch against tip and tried both with and without
> -Wl,--as-needed and it worked fine for both Perl and Python, on my
> Ubuntu 9.10 system.  The refreshed patch I used is included below.
> 
> It wasn't clear to me whether Ozan's PERL_EMBED_LDOPTS output still
> caused link errors; here's mine, which didn't:
> 
> trz@tropicana:~$ perl -MExtUtils::Embed -e ldopts
> -Wl,-E  -L/usr/local/lib  -L/usr/lib/perl/5.10/CORE -lperl -ldl -lm
> -lpthread -lc -lcrypt
> 
> In any case, since neither ExtUtils::Embed nor python-config seem to
> have a way to get the LDFLAGS and LIBADD components separately, we'll
> have to find some other way to do that if necessary.
> 

Looking into it a bit further, both ExtUtils::Embed -e ldopts and
python-config --ldflags put the libs at the end, so we should be able to
parse the output of those and take only the parts we need for each
component.  How about something like this instead?

Tom 

---

[PATCH] Refresh of Ozan Çağlayan's patch: perf tools: Fix linking errors
with --as-needed flag:

External shared libraries should never be appended to the LDFLAGS as
this messes the linking order. As EXTLIBS collects those libraries,
it seems that perl and python libraries  should also be appended
to EXTLIBS.

Also fix the broken linking order.

v2: add commands to separate out LDFLAGS and libs from both Perl and
Python LDOPTS (Tom Zanussi)

Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
---
 tools/perf/Makefile |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 26a3f2e..59f5b10 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -589,13 +589,16 @@ ifdef NO_LIBPERL
 	BASIC_CFLAGS += -DNO_LIBPERL
 else
 	PERL_EMBED_LDOPTS = `perl -MExtUtils::Embed -e ldopts 2>/dev/null`
+	PERL_EMBED_LDFLAGS = $(shell echo $(PERL_EMBED_LDOPTS) | sed 's/-l.*//' )
+	PERL_EMBED_LIBADD = $(shell echo $(PERL_EMBED_LDOPTS) | grep -o '\-l.*' )
 	PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
 	FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
 
 	ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED)),y)
 		BASIC_CFLAGS += -DNO_LIBPERL
 	else
-		ALL_LDFLAGS += $(PERL_EMBED_LDOPTS)
+		ALL_LDFLAGS += $(PERL_EMBED_LDFLAGS)
+		EXTLIBS += $(PERL_EMBED_LIBADD)
 		LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
 		LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
 	endif
@@ -605,12 +608,15 @@ ifdef NO_LIBPYTHON
 	BASIC_CFLAGS += -DNO_LIBPYTHON
 else
 	PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null`
+	PYTHON_EMBED_LDFLAGS = $(shell echo $(PYTHON_EMBED_LDOPTS) | sed 's/-l.*//' )
+	PYTHON_EMBED_LIBADD = $(shell echo $(PYTHON_EMBED_LDOPTS) | grep -o '\-l.*' )
 	PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null`
 	FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
 	ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y)
 		BASIC_CFLAGS += -DNO_LIBPYTHON
 	else
-		ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
+		ALL_LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
+		EXTLIBS += $(PYTHON_EMBED_LIBADD)
 		LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
 		LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
 	endif
@@ -919,8 +925,8 @@ $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
 		$(ALL_CFLAGS) -c $(filter %.c,$^) -o $@
 
 $(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(OUTPUT)perf.o \
-		$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
+	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \
+		$(BUILTIN_OBJS) $(LIBS) -o $@
 
 $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
-- 
1.6.4.GIT




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

* Re: [PATCH] perf tools: Fix linking errors with --as-needed flag
  2010-08-23  2:44       ` Tom Zanussi
@ 2010-08-23 14:38         ` Arnaldo Carvalho de Melo
  2010-08-23 21:22           ` Ozan Çağlayan
  2010-08-23 16:53         ` Kirill A. Shutemov
  1 sibling, 1 reply; 11+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-08-23 14:38 UTC (permalink / raw)
  To: Ozan Çağlayan, Kirill A. Shutemov
  Cc: Tom Zanussi, linux-kernel, mingo

Em Sun, Aug 22, 2010 at 09:44:13PM -0500, Tom Zanussi escreveu:
> Looking into it a bit further, both ExtUtils::Embed -e ldopts and
> python-config --ldflags put the libs at the end, so we should be able to
> parse the output of those and take only the parts we need for each
> component.  How about something like this instead?

Ozan, Kirill, can you please test Tom's patch and see if it fixes the
problems you noticed so that I can add Tested-by tags and apply this
patch?

Thanks,

- Arnaldo

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

* Re: [PATCH] perf tools: Fix linking errors with --as-needed flag
  2010-08-23  2:44       ` Tom Zanussi
  2010-08-23 14:38         ` Arnaldo Carvalho de Melo
@ 2010-08-23 16:53         ` Kirill A. Shutemov
  2010-08-24  5:23           ` Tom Zanussi
  1 sibling, 1 reply; 11+ messages in thread
From: Kirill A. Shutemov @ 2010-08-23 16:53 UTC (permalink / raw)
  To: Tom Zanussi
  Cc: Arnaldo Carvalho de Melo, Ozan Çağlayan, linux-kernel, mingo

On Sun, Aug 22, 2010 at 09:44:13PM -0500, Tom Zanussi wrote:
> On Sun, 2010-08-22 at 01:43 -0500, Tom Zanussi wrote:
> > Hi,
> > 
> > On Sat, 2010-08-21 at 14:24 -0300, Arnaldo Carvalho de Melo wrote:
> > > Em Sun, Jul 18, 2010 at 02:04:32PM +0300, Ozan Çağlayan escreveu:
> > > > On 18.07.2010 13:45, Ozan Çağlayan wrote:
> > > > > External shared libraries should never be appended to the LDFLAGS as
> > > > > this messes the linking order. As EXTLIBS collects those libraries,
> > > > > it seems that perl and python libraries  should also be appended
> > > > > to EXTLIBS.
> > > > > 
> > > > > Also fix the broken linking order.
> > > > 
> > > > Hm actually the PERL_EMBED_LDOPTS may contain LDFLAGS and LIBADD according
> > > > to distribution's perl package configuration's goodness/badness. On my system
> > > > the return value is crap which bloats the linking process:
> > > > 
> > > >  -rdynamic -Wl,-rpath,/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE -lperl -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
> > > > 
> > > > PYTHON_EMBED_LDOPTS evaluates python-config --ldflags and adds these to 
> > > > ALL_LDFLAGS. (--libs and --ldflags are synonyms for python-config). According
> > > > to python-config this code *never* returns LDFLAGS so it's safe to put them in
> > > > EXTLIBS.
> > > > 
> > > > So the cure may be more than this patch for perl stuff, but at least it fixes my
> > > > linking problems with -Wl, --as-needed.
> > > 
> > > Can you refresh this patch? I had it in the back of my mind, remembered
> > > it when considering a similar patch by Kirill, but his covers just the
> > > python case.
> > > 
> > > Tom, can you please check Ozan's and Kirill's patches and tell me if I
> > > can stick your Acked-by to them?
> > > 
> > 
> > I refreshed Ozan's patch against tip and tried both with and without
> > -Wl,--as-needed and it worked fine for both Perl and Python, on my
> > Ubuntu 9.10 system.  The refreshed patch I used is included below.
> > 
> > It wasn't clear to me whether Ozan's PERL_EMBED_LDOPTS output still
> > caused link errors; here's mine, which didn't:
> > 
> > trz@tropicana:~$ perl -MExtUtils::Embed -e ldopts
> > -Wl,-E  -L/usr/local/lib  -L/usr/lib/perl/5.10/CORE -lperl -ldl -lm
> > -lpthread -lc -lcrypt
> > 
> > In any case, since neither ExtUtils::Embed nor python-config seem to
> > have a way to get the LDFLAGS and LIBADD components separately, we'll
> > have to find some other way to do that if necessary.
> > 
> 
> Looking into it a bit further, both ExtUtils::Embed -e ldopts and
> python-config --ldflags put the libs at the end, so we should be able to
> parse the output of those and take only the parts we need for each
> component.  How about something like this instead?
> 
> Tom 
> 
> ---
> 
> [PATCH] Refresh of Ozan Çağlayan's patch: perf tools: Fix linking errors
> with --as-needed flag:
> 
> External shared libraries should never be appended to the LDFLAGS as
> this messes the linking order. As EXTLIBS collects those libraries,
> it seems that perl and python libraries  should also be appended
> to EXTLIBS.
> 
> Also fix the broken linking order.
> 
> v2: add commands to separate out LDFLAGS and libs from both Perl and
> Python LDOPTS (Tom Zanussi)
> 
> Signed-off-by: Tom Zanussi <tzanussi@gmail.com>

Tested-by: Kirill A. Shutemov <kirill@shutemov.name>

But, probably better to do it with make:

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 4f1fa77..03a53a9 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -313,6 +313,9 @@ TEST_PROGRAMS =
 
 SCRIPT_SH += perf-archive.sh
 
+grep-libs = $(filter -l%,$(1))
+strip-libs = $(filter-out -l%,$(1))
+
 #
 # No Perl scripts right now:
 #
@@ -588,14 +591,17 @@ endif
 ifdef NO_LIBPERL
        BASIC_CFLAGS += -DNO_LIBPERL
 else
-       PERL_EMBED_LDOPTS = `perl -MExtUtils::Embed -e ldopts 2>/dev/null`
+       PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
+       PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
+       PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
        PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
        FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
 
        ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED)),y)
                BASIC_CFLAGS += -DNO_LIBPERL
        else
-               ALL_LDFLAGS += $(PERL_EMBED_LDOPTS)
+               ALL_LDFLAGS += $(PERL_EMBED_LDFLAGS)
+               EXTLIBS += $(PERL_EMBED_LIBADD)
                LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
                LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
        endif
@@ -604,13 +610,16 @@ endif
 ifdef NO_LIBPYTHON
        BASIC_CFLAGS += -DNO_LIBPYTHON
 else
-       PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null`
+       PYTHON_EMBED_LDOPTS = $(shell python-config --ldflags 2>/dev/null)
+       PYTHON_EMBED_LDFLAGS = $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
+       PYTHON_EMBED_LIBADD = $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
        PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null`
        FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
        ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y)
                BASIC_CFLAGS += -DNO_LIBPYTHON
        else
-               ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
+               ALL_LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
+               EXTLIBS += $(PYTHON_EMBED_LIBADD)
                LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
                LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
        endif
@@ -910,8 +919,8 @@ $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
                $(ALL_CFLAGS) -c $(filter %.c,$^) -o $@
 
 $(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
-       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(OUTPUT)perf.o \
-               $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
+       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \
+               $(BUILTIN_OBJS) $(LIBS) -o $@
 
 $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
        $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
-- 
 Kirill A. Shutemov

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

* Re: [PATCH] perf tools: Fix linking errors with --as-needed flag
  2010-08-23 14:38         ` Arnaldo Carvalho de Melo
@ 2010-08-23 21:22           ` Ozan Çağlayan
  2010-08-23 23:23             ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 11+ messages in thread
From: Ozan Çağlayan @ 2010-08-23 21:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Kirill A. Shutemov, Tom Zanussi, linux-kernel, mingo

On 23.08.2010 17:38, Arnaldo Carvalho de Melo wrote:
> Em Sun, Aug 22, 2010 at 09:44:13PM -0500, Tom Zanussi escreveu:
>> Looking into it a bit further, both ExtUtils::Embed -e ldopts and
>> python-config --ldflags put the libs at the end, so we should be able to
>> parse the output of those and take only the parts we need for each
>> component.  How about something like this instead?
> 
> Ozan, Kirill, can you please test Tom's patch and see if it fixes the
> problems you noticed so that I can add Tested-by tags and apply this
> patch?

Hi,

I won't be able to test anything for at least 1 week, sorry.

Regards,

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

* Re: [PATCH] perf tools: Fix linking errors with --as-needed flag
  2010-08-23 21:22           ` Ozan Çağlayan
@ 2010-08-23 23:23             ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 11+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-08-23 23:23 UTC (permalink / raw)
  To: Ozan Çağlayan
  Cc: Kirill A. Shutemov, Tom Zanussi, linux-kernel, mingo

Em Tue, Aug 24, 2010 at 12:22:55AM +0300, Ozan Çağlayan escreveu:
> On 23.08.2010 17:38, Arnaldo Carvalho de Melo wrote:
> > Em Sun, Aug 22, 2010 at 09:44:13PM -0500, Tom Zanussi escreveu:
> >> Looking into it a bit further, both ExtUtils::Embed -e ldopts and
> >> python-config --ldflags put the libs at the end, so we should be able to
> >> parse the output of those and take only the parts we need for each
> >> component.  How about something like this instead?
> > 
> > Ozan, Kirill, can you please test Tom's patch and see if it fixes the
> > problems you noticed so that I can add Tested-by tags and apply this
> > patch?
> 
> Hi,
> 
> I won't be able to test anything for at least 1 week, sorry.

np, take your time.

- Arnaldo

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

* Re: [PATCH] perf tools: Fix linking errors with --as-needed flag
  2010-08-23 16:53         ` Kirill A. Shutemov
@ 2010-08-24  5:23           ` Tom Zanussi
       [not found]             ` <tip-f2481f3df4521e731da36afe7f0fe19a5c93e46d@git.kernel.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Tom Zanussi @ 2010-08-24  5:23 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Arnaldo Carvalho de Melo, Ozan Çağlayan, linux-kernel, mingo

On Mon, 2010-08-23 at 19:53 +0300, Kirill A. Shutemov wrote:
> On Sun, Aug 22, 2010 at 09:44:13PM -0500, Tom Zanussi wrote:
> > On Sun, 2010-08-22 at 01:43 -0500, Tom Zanussi wrote:
> > > Hi,
> > > 
> > > On Sat, 2010-08-21 at 14:24 -0300, Arnaldo Carvalho de Melo wrote:
> > > > Em Sun, Jul 18, 2010 at 02:04:32PM +0300, Ozan Çağlayan escreveu:
> > > > > On 18.07.2010 13:45, Ozan Çağlayan wrote:
> > > > > > External shared libraries should never be appended to the LDFLAGS as
> > > > > > this messes the linking order. As EXTLIBS collects those libraries,
> > > > > > it seems that perl and python libraries  should also be appended
> > > > > > to EXTLIBS.
> > > > > > 
> > > > > > Also fix the broken linking order.
> > > > > 
> > > > > Hm actually the PERL_EMBED_LDOPTS may contain LDFLAGS and LIBADD according
> > > > > to distribution's perl package configuration's goodness/badness. On my system
> > > > > the return value is crap which bloats the linking process:
> > > > > 
> > > > >  -rdynamic -Wl,-rpath,/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl5/5.10.1/i686-linux-thread-multi/CORE -lperl -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
> > > > > 
> > > > > PYTHON_EMBED_LDOPTS evaluates python-config --ldflags and adds these to 
> > > > > ALL_LDFLAGS. (--libs and --ldflags are synonyms for python-config). According
> > > > > to python-config this code *never* returns LDFLAGS so it's safe to put them in
> > > > > EXTLIBS.
> > > > > 
> > > > > So the cure may be more than this patch for perl stuff, but at least it fixes my
> > > > > linking problems with -Wl, --as-needed.
> > > > 
> > > > Can you refresh this patch? I had it in the back of my mind, remembered
> > > > it when considering a similar patch by Kirill, but his covers just the
> > > > python case.
> > > > 
> > > > Tom, can you please check Ozan's and Kirill's patches and tell me if I
> > > > can stick your Acked-by to them?
> > > > 
> > > 
> > > I refreshed Ozan's patch against tip and tried both with and without
> > > -Wl,--as-needed and it worked fine for both Perl and Python, on my
> > > Ubuntu 9.10 system.  The refreshed patch I used is included below.
> > > 
> > > It wasn't clear to me whether Ozan's PERL_EMBED_LDOPTS output still
> > > caused link errors; here's mine, which didn't:
> > > 
> > > trz@tropicana:~$ perl -MExtUtils::Embed -e ldopts
> > > -Wl,-E  -L/usr/local/lib  -L/usr/lib/perl/5.10/CORE -lperl -ldl -lm
> > > -lpthread -lc -lcrypt
> > > 
> > > In any case, since neither ExtUtils::Embed nor python-config seem to
> > > have a way to get the LDFLAGS and LIBADD components separately, we'll
> > > have to find some other way to do that if necessary.
> > > 
> > 
> > Looking into it a bit further, both ExtUtils::Embed -e ldopts and
> > python-config --ldflags put the libs at the end, so we should be able to
> > parse the output of those and take only the parts we need for each
> > component.  How about something like this instead?
> > 
> > Tom 
> > 
> > ---
> > 
> > [PATCH] Refresh of Ozan Çağlayan's patch: perf tools: Fix linking errors
> > with --as-needed flag:
> > 
> > External shared libraries should never be appended to the LDFLAGS as
> > this messes the linking order. As EXTLIBS collects those libraries,
> > it seems that perl and python libraries  should also be appended
> > to EXTLIBS.
> > 
> > Also fix the broken linking order.
> > 
> > v2: add commands to separate out LDFLAGS and libs from both Perl and
> > Python LDOPTS (Tom Zanussi)
> > 
> > Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
> 
> Tested-by: Kirill A. Shutemov <kirill@shutemov.name>
> 
> But, probably better to do it with make:
> 
> diff --git a/tools/perf/Makefile b/tools/perf/Makefile
> index 4f1fa77..03a53a9 100644
> --- a/tools/perf/Makefile
> +++ b/tools/perf/Makefile
> @@ -313,6 +313,9 @@ TEST_PROGRAMS =
>  
>  SCRIPT_SH += perf-archive.sh
>  
> +grep-libs = $(filter -l%,$(1))
> +strip-libs = $(filter-out -l%,$(1))
> +
>  #
>  # No Perl scripts right now:
>  #
> @@ -588,14 +591,17 @@ endif
>  ifdef NO_LIBPERL
>         BASIC_CFLAGS += -DNO_LIBPERL
>  else
> -       PERL_EMBED_LDOPTS = `perl -MExtUtils::Embed -e ldopts 2>/dev/null`
> +       PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
> +       PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
> +       PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
>         PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
>         FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
>  
>         ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED)),y)
>                 BASIC_CFLAGS += -DNO_LIBPERL
>         else
> -               ALL_LDFLAGS += $(PERL_EMBED_LDOPTS)
> +               ALL_LDFLAGS += $(PERL_EMBED_LDFLAGS)
> +               EXTLIBS += $(PERL_EMBED_LIBADD)
>                 LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
>                 LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
>         endif
> @@ -604,13 +610,16 @@ endif
>  ifdef NO_LIBPYTHON
>         BASIC_CFLAGS += -DNO_LIBPYTHON
>  else
> -       PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null`
> +       PYTHON_EMBED_LDOPTS = $(shell python-config --ldflags 2>/dev/null)
> +       PYTHON_EMBED_LDFLAGS = $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
> +       PYTHON_EMBED_LIBADD = $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
>         PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null`
>         FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
>         ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y)
>                 BASIC_CFLAGS += -DNO_LIBPYTHON
>         else
> -               ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
> +               ALL_LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
> +               EXTLIBS += $(PYTHON_EMBED_LIBADD)
>                 LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
>                 LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
>         endif
> @@ -910,8 +919,8 @@ $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
>                 $(ALL_CFLAGS) -c $(filter %.c,$^) -o $@
>  
>  $(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
> -       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(OUTPUT)perf.o \
> -               $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
> +       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \
> +               $(BUILTIN_OBJS) $(LIBS) -o $@
>  
>  $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
>         $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \

Yes, much better, thanks!

Tested-by: Tom Zanussi <tzanussi@gmail.com>

BTW, I had some problems applying that patch, had to use -l and fix up a missing tab:

---
 tools/perf/Makefile |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 26a3f2e..fe1e307 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -313,6 +313,9 @@ TEST_PROGRAMS =
 
 SCRIPT_SH += perf-archive.sh
 
+grep-libs = $(filter -l%,$(1))
+strip-libs = $(filter-out -l%,$(1))
+
 #
 # No Perl scripts right now:
 #
@@ -588,14 +591,17 @@ endif
 ifdef NO_LIBPERL
 	BASIC_CFLAGS += -DNO_LIBPERL
 else
-	PERL_EMBED_LDOPTS = `perl -MExtUtils::Embed -e ldopts 2>/dev/null`
+       PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
+       PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
+       PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
 	PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
 	FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
 
 	ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED)),y)
 		BASIC_CFLAGS += -DNO_LIBPERL
 	else
-		ALL_LDFLAGS += $(PERL_EMBED_LDOPTS)
+               ALL_LDFLAGS += $(PERL_EMBED_LDFLAGS)
+               EXTLIBS += $(PERL_EMBED_LIBADD)
 		LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
 		LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
 	endif
@@ -604,13 +610,16 @@ endif
 ifdef NO_LIBPYTHON
 	BASIC_CFLAGS += -DNO_LIBPYTHON
 else
-	PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null`
+       PYTHON_EMBED_LDOPTS = $(shell python-config --ldflags 2>/dev/null)
+       PYTHON_EMBED_LDFLAGS = $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
+       PYTHON_EMBED_LIBADD = $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
 	PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null`
 	FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
 	ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y)
 		BASIC_CFLAGS += -DNO_LIBPYTHON
 	else
-		ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
+               ALL_LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
+               EXTLIBS += $(PYTHON_EMBED_LIBADD)
 		LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
 		LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
 	endif
@@ -919,8 +928,8 @@ $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
 		$(ALL_CFLAGS) -c $(filter %.c,$^) -o $@
 
 $(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
-	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(OUTPUT)perf.o \
-		$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
+	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \
+               $(BUILTIN_OBJS) $(LIBS) -o $@
 
 $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
 	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
-- 
1.6.4.GIT





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

* Re: [tip:perf/core] perf tools: Fix linking errors with --as-needed flag
       [not found]             ` <tip-f2481f3df4521e731da36afe7f0fe19a5c93e46d@git.kernel.org>
@ 2010-08-30  8:38               ` Kirill A. Shutemov
  0 siblings, 0 replies; 11+ messages in thread
From: Kirill A. Shutemov @ 2010-08-30  8:38 UTC (permalink / raw)
  To: mingo, hpa, linux-kernel, acme, tzanussi, ozan, tglx; +Cc: linux-tip-commits

On Mon, Aug 30, 2010 at 08:35:40AM +0000, tip-bot for Tom Zanussi wrote:
> Commit-ID:  f2481f3df4521e731da36afe7f0fe19a5c93e46d
> Gitweb:     http://git.kernel.org/tip/f2481f3df4521e731da36afe7f0fe19a5c93e46d
> Author:     Tom Zanussi <tzanussi@gmail.com>
> AuthorDate: Tue, 24 Aug 2010 00:23:50 -0500
> Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
> CommitDate: Wed, 25 Aug 2010 17:35:21 -0300
> 
> perf tools: Fix linking errors with --as-needed flag
> 
> External shared libraries should never be appended to the LDFLAGS as this
> messes the linking order. As EXTLIBS collects those libraries, it seems that
> perl and python libraries  should also be appended to EXTLIBS.
> 
> Also fix the broken linking order.
> 
> This is a refresh of a patch by Ozan Çağlayan and improved by both Tom Zanussi
> and Kirill A. Shutemov.
> 
> Cc: Ozan Çağlayan <ozan@pardus.org.tr>
> Tested-by: Kirill A. Shutemov <kirill@shutemov.name>

I guess Signed-off-by is more appropriate here.

> Tested-by: Tom Zanussi <tzanussi@gmail.com>
> LKML-Reference: <1282627430.28324.8.camel@tropicana>
> Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/perf/Makefile |   21 +++++++++++++++------
>  1 files changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/perf/Makefile b/tools/perf/Makefile
> index 26a3f2e..fe1e307 100644
> --- a/tools/perf/Makefile
> +++ b/tools/perf/Makefile
> @@ -313,6 +313,9 @@ TEST_PROGRAMS =
>  
>  SCRIPT_SH += perf-archive.sh
>  
> +grep-libs = $(filter -l%,$(1))
> +strip-libs = $(filter-out -l%,$(1))
> +
>  #
>  # No Perl scripts right now:
>  #
> @@ -588,14 +591,17 @@ endif
>  ifdef NO_LIBPERL
>  	BASIC_CFLAGS += -DNO_LIBPERL
>  else
> -	PERL_EMBED_LDOPTS = `perl -MExtUtils::Embed -e ldopts 2>/dev/null`
> +       PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
> +       PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
> +       PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
>  	PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
>  	FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
>  
>  	ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED)),y)
>  		BASIC_CFLAGS += -DNO_LIBPERL
>  	else
> -		ALL_LDFLAGS += $(PERL_EMBED_LDOPTS)
> +               ALL_LDFLAGS += $(PERL_EMBED_LDFLAGS)
> +               EXTLIBS += $(PERL_EMBED_LIBADD)
>  		LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
>  		LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
>  	endif
> @@ -604,13 +610,16 @@ endif
>  ifdef NO_LIBPYTHON
>  	BASIC_CFLAGS += -DNO_LIBPYTHON
>  else
> -	PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null`
> +       PYTHON_EMBED_LDOPTS = $(shell python-config --ldflags 2>/dev/null)
> +       PYTHON_EMBED_LDFLAGS = $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
> +       PYTHON_EMBED_LIBADD = $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
>  	PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null`
>  	FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
>  	ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y)
>  		BASIC_CFLAGS += -DNO_LIBPYTHON
>  	else
> -		ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
> +               ALL_LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
> +               EXTLIBS += $(PYTHON_EMBED_LIBADD)
>  		LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
>  		LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
>  	endif
> @@ -919,8 +928,8 @@ $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
>  		$(ALL_CFLAGS) -c $(filter %.c,$^) -o $@
>  
>  $(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
> -	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(OUTPUT)perf.o \
> -		$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
> +	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \
> +               $(BUILTIN_OBJS) $(LIBS) -o $@
>  
>  $(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
>  	$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \

-- 
 Kirill A. Shutemov

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

end of thread, other threads:[~2010-08-30  8:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-18 10:45 [PATCH] perf tools: Fix linking errors with --as-needed flag Ozan Çağlayan
2010-07-18 11:04 ` Ozan Çağlayan
2010-08-21 17:24   ` Arnaldo Carvalho de Melo
2010-08-22  6:43     ` Tom Zanussi
2010-08-23  2:44       ` Tom Zanussi
2010-08-23 14:38         ` Arnaldo Carvalho de Melo
2010-08-23 21:22           ` Ozan Çağlayan
2010-08-23 23:23             ` Arnaldo Carvalho de Melo
2010-08-23 16:53         ` Kirill A. Shutemov
2010-08-24  5:23           ` Tom Zanussi
     [not found]             ` <tip-f2481f3df4521e731da36afe7f0fe19a5c93e46d@git.kernel.org>
2010-08-30  8:38               ` [tip:perf/core] " Kirill A. Shutemov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.