2010-02-11 00:24:54

by Jan Engelhardt

[permalink] [raw]
Subject: tools/perf: libraries must come after objects

parent b4bdd73ce865213a5653dc424873e8da37e858cc (v2.6.32.7)
commit 588424af1a51fa41ea4811200889d6a03219c6fd
Author: Jan Engelhardt <[email protected]>
Date: Thu Feb 11 01:20:54 2010 +0100

tools/perf: libraries must come after objects

Link order matters, especially now since distributions are
using -Wl,--as-needed.

Signed-off-by: Jan Engelhardt <[email protected]>
---
tools/perf/Makefile | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 7e190d5..9c688cd 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -201,7 +201,7 @@ EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes
EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement

CFLAGS = $(MBITS) -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -fstack-protector-all -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS)
-LDFLAGS = -lpthread -lrt -lelf -lm
+LDLIBS = -lpthread -lrt -lelf -lm
ALL_CFLAGS = $(CFLAGS)
ALL_LDFLAGS = $(LDFLAGS)
STRIP ?= strip
@@ -421,8 +421,8 @@ ifeq ($(uname_S),Darwin)
PTHREAD_LIBS =
endif

-ifeq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o /dev/null $(ALL_LDFLAGS) > /dev/null 2>&1 && echo y"), y)
- ifneq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ_MMAP, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o /dev/null $(ALL_LDFLAGS) > /dev/null 2>&1 && echo y"), y)
+ifeq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o /dev/null $(LDFLAGS) $(LDLIBS) > /dev/null 2>&1 && echo y"), y)
+ ifneq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ_MMAP, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o /dev/null $(LDFLAGS) $(LDLIBS) > /dev/null 2>&1 && echo y"), y)
BASIC_CFLAGS += -DLIBELF_NO_MMAP
endif
else
@@ -432,20 +432,20 @@ endif
ifdef NO_DEMANGLE
BASIC_CFLAGS += -DNO_DEMANGLE
else
- has_bfd := $(shell sh -c "(echo '\#include <bfd.h>'; echo 'int main(void) { bfd_demangle(0, 0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o /dev/null $(ALL_LDFLAGS) -lbfd > /dev/null 2>&1 && echo y")
+ has_bfd := $(shell sh -c "(echo '\#include <bfd.h>'; echo 'int main(void) { bfd_demangle(0, 0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o /dev/null $(LDFLAGS) $(LDLIBS) -lbfd > /dev/null 2>&1 && echo y")

ifeq ($(has_bfd),y)
EXTLIBS += -lbfd
else
- has_bfd_iberty := $(shell sh -c "(echo '\#include <bfd.h>'; echo 'int main(void) { bfd_demangle(0, 0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o /dev/null $(ALL_LDFLAGS) -lbfd -liberty > /dev/null 2>&1 && echo y")
+ has_bfd_iberty := $(shell sh -c "(echo '\#include <bfd.h>'; echo 'int main(void) { bfd_demangle(0, 0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o /dev/null $(LDFLAGS) $(LDLIBS) -lbfd -liberty > /dev/null 2>&1 && echo y")
ifeq ($(has_bfd_iberty),y)
EXTLIBS += -lbfd -liberty
else
- has_bfd_iberty_z := $(shell sh -c "(echo '\#include <bfd.h>'; echo 'int main(void) { bfd_demangle(0, 0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o /dev/null $(ALL_LDFLAGS) -lbfd -liberty -lz > /dev/null 2>&1 && echo y")
+ has_bfd_iberty_z := $(shell sh -c "(echo '\#include <bfd.h>'; echo 'int main(void) { bfd_demangle(0, 0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o /dev/null $(LDFLAGS) $(LDLIBS) -lbfd -liberty -lz > /dev/null 2>&1 && echo y")
ifeq ($(has_bfd_iberty_z),y)
EXTLIBS += -lbfd -liberty -lz
else
- has_cplus_demangle := $(shell sh -c "(echo 'extern char *cplus_demangle(const char *, int);'; echo 'int main(void) { cplus_demangle(0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o /dev/null $(ALL_LDFLAGS) -liberty > /dev/null 2>&1 && echo y")
+ has_cplus_demangle := $(shell sh -c "(echo 'extern char *cplus_demangle(const char *, int);'; echo 'int main(void) { cplus_demangle(0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o /dev/null $(LDFLAGS) $(LDLIBS) -liberty > /dev/null 2>&1 && echo y")
ifeq ($(has_cplus_demangle),y)
EXTLIBS += -liberty
BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
@@ -677,7 +677,7 @@ prefix_SQ = $(subst ','\'',$(prefix))
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))

-LIBS = $(PERFLIBS) $(EXTLIBS)
+LIBS = $(PERFLIBS) $(LDLIBS) $(EXTLIBS)

BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
$(COMPAT_CFLAGS)
--
# Created with git-export-patch


2010-02-22 10:50:34

by Ingo Molnar

[permalink] [raw]
Subject: Re: tools/perf: libraries must come after objects


* Jan Engelhardt <[email protected]> wrote:

> parent b4bdd73ce865213a5653dc424873e8da37e858cc (v2.6.32.7)
> commit 588424af1a51fa41ea4811200889d6a03219c6fd
> Author: Jan Engelhardt <[email protected]>
> Date: Thu Feb 11 01:20:54 2010 +0100
>
> tools/perf: libraries must come after objects
>
> Link order matters, especially now since distributions are
> using -Wl,--as-needed.
>
> Signed-off-by: Jan Engelhardt <[email protected]>
> ---
> tools/perf/Makefile | 16 ++++++++--------
> 1 files changed, 8 insertions(+), 8 deletions(-)

FYI, this patch doesnt apply to the latest version of perf:

patching file tools/perf/Makefile
Hunk #1 FAILED at 201.
Hunk #2 FAILED at 421.
Hunk #3 FAILED at 432.
Hunk #4 succeeded at 770 (offset 93 lines).
3 out of 4 hunks FAILED -- rejects in file tools/perf/Makefile

you can find the devel tree at:

http://people.redhat.com/mingo/tip.git/README

Thanks,

Ingo

2010-02-22 13:31:15

by Jan Engelhardt

[permalink] [raw]
Subject: Re: tools/perf: libraries must come after objects

On Monday 2010-02-22 11:50, Ingo Molnar wrote:
>>
>> tools/perf: libraries must come after objects
>>
>> Link order matters, especially now since distributions are
>> using -Wl,--as-needed.
>>
>> Signed-off-by: Jan Engelhardt <[email protected]>
>> ---
>> tools/perf/Makefile | 16 ++++++++--------
>> 1 files changed, 8 insertions(+), 8 deletions(-)
>
>FYI, this patch doesnt apply to the latest version of perf:
>
> patching file tools/perf/Makefile
> Hunk #1 FAILED at 201.
> Hunk #2 FAILED at 421.
> Hunk #3 FAILED at 432.
> Hunk #4 succeeded at 770 (offset 93 lines).
> 3 out of 4 hunks FAILED -- rejects in file tools/perf/Makefile
>
>you can find the devel tree at:
>
> http://people.redhat.com/mingo/tip.git/README

Do happen to have that as a faster git:// too?

2010-02-22 13:48:11

by Ingo Molnar

[permalink] [raw]
Subject: Re: tools/perf: libraries must come after objects


* Jan Engelhardt <[email protected]> wrote:

> On Monday 2010-02-22 11:50, Ingo Molnar wrote:
> >>
> >> tools/perf: libraries must come after objects
> >>
> >> Link order matters, especially now since distributions are
> >> using -Wl,--as-needed.
> >>
> >> Signed-off-by: Jan Engelhardt <[email protected]>
> >> ---
> >> tools/perf/Makefile | 16 ++++++++--------
> >> 1 files changed, 8 insertions(+), 8 deletions(-)
> >
> >FYI, this patch doesnt apply to the latest version of perf:
> >
> > patching file tools/perf/Makefile
> > Hunk #1 FAILED at 201.
> > Hunk #2 FAILED at 421.
> > Hunk #3 FAILED at 432.
> > Hunk #4 succeeded at 770 (offset 93 lines).
> > 3 out of 4 hunks FAILED -- rejects in file tools/perf/Makefile
> >
> >you can find the devel tree at:
> >
> > http://people.redhat.com/mingo/tip.git/README
>
> Do happen to have that as a faster git:// too?

Yes, the links for the -tip Git tree are in that file.

Thanks,

Ingo

2010-02-22 14:12:40

by Peter Zijlstra

[permalink] [raw]
Subject: Re: tools/perf: libraries must come after objects

On Mon, 2010-02-22 at 14:31 +0100, Jan Engelhardt wrote:
>
> Do happen to have that as a faster git:// too?
>
git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git

2010-02-23 23:54:53

by Jan Engelhardt

[permalink] [raw]
Subject: Re: tools/perf: libraries must come after objects


On Monday 2010-02-22 14:47, Ingo Molnar wrote:
>> >> tools/perf: libraries must come after objects
>> >>
>> >> Link order matters, especially now since distributions are
>> >> using -Wl,--as-needed.

>> >> tools/perf/Makefile | 16 ++++++++--------
>> >> 1 files changed, 8 insertions(+), 8 deletions(-)
>> >
>> >FYI, this patch doesnt apply to the latest version of perf:
>> > http://people.redhat.com/mingo/tip.git/README

Seems like it was already merged - half of it.

There is this perl linking error now remaining, because
libperf.a comes after the perl part, and I am not sure
how to fix cleanly that Makefile without making more
mess of it.

$ make CC=gcc-4.4
touch .perf.dev.null
gcc-4.4 -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wformat-y2k -Wshadow -Winit-self -Wpacked -Wredundant-decls -Wstack-protector -Wstrict-aliasing=3 -Wswitch-default -Wswitch-enum -Wno-system-headers -Wundef -Wvolatile-register-var -Wwrite-strings -Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wstrict-prototypes -Wdeclaration-after-statement -fstack-protector-all -Iutil/include -I/usr/include/libdwarf -DSHA1_HEADER='<openssl/sha.h>' -o perf perf.o \
builtin-annotate.o builtin-bench.o bench/sched-messaging.o bench/sched-pipe.o bench/mem-memcpy.o builtin-diff.o builtin-help.o builtin-sched.o builtin-buildid-list.o builtin-buildid-cache.o builtin-list.o builtin-record.o builtin-report.o builtin-stat.o builtin-timechart.o builtin-top.o builtin-trace.o builtin-probe.o builtin-kmem.o builtin-lock.o `perl -MExtUtils::Embed -e ldopts 2>/dev/null` libperf.a -lpthread -lrt -lelf -lm -lelf -ldwarf -lbfd -liberty -lz
libperf.a(trace-event-perl.o): In function `define_flag_value':
/home/jengelh/code/linux/tools/perf/util/trace-event-perl.c:125: undefined reference to `Perl_push_scope'
[...]
/home/jengelh/code/linux/tools/perf/Context.c:54: undefined reference to `Perl_croak_nocontext'
collect2: ld returned 1 exit status
make: *** [perf] Error 1
rm .perf.dev.null

$ perl -MExtUtils::Embed -e ldopts
-Wl,-E
-Wl,-rpath,/usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/CORE
-L/usr/local/lib64
-L/usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/CORE -lperl -lm
-ldl -lcrypt -lpthread