2010-08-21 00:41:03

by Kirill A. Shutemov

[permalink] [raw]
Subject: [PATCH 1/2] perf: add test for strlcpy()

Some Linux distributions like ALT Linux provides patched glibc with
contains strlcpy(). It's confilcts with strlcpy() from perf.

Let's add check for strlcpy().

Signed-off-by: Kirill A. Shutemov <[email protected]>
---
tools/perf/Makefile | 8 ++++++++
tools/perf/feature-tests.mak | 11 +++++++++++
tools/perf/util/cache.h | 2 ++
tools/perf/util/path.c | 3 ++-
4 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 4f1fa77..496a0d6 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -653,6 +653,14 @@ else
endif
endif

+ifdef NO_STRLCPY
+ BASIC_CFLAGS += -DNO_STRLCPY
+else
+ ifneq ($(call try-cc,$(SOURCE_STRLCPY),),y)
+ BASIC_CFLAGS += -DNO_STRLCPY
+ endif
+endif
+
ifndef CC_LD_DYNPATH
ifdef NO_R_TO_GCC_LINKER
# Some gcc does not accept and pass -R to the linker to specify
diff --git a/tools/perf/feature-tests.mak b/tools/perf/feature-tests.mak
index 7a7b608..b253db6 100644
--- a/tools/perf/feature-tests.mak
+++ b/tools/perf/feature-tests.mak
@@ -110,6 +110,17 @@ int main(void)
}
endef

+define SOURCE_STRLCPY
+#include <stdlib.h>
+extern size_t strlcpy(char *dest, const char *src, size_t size);
+
+int main(void)
+{
+ strlcpy(NULL, NULL, 0);
+ return 0;
+}
+endef
+
# try-cc
# Usage: option = $(call try-cc, source-to-build, cc-options)
try-cc = $(shell sh -c \
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 27e9ebe..a772979 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -82,6 +82,8 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2
extern char *perf_pathdup(const char *fmt, ...)
__attribute__((format (printf, 1, 2)));

+#ifdef NO_STRLCPY
extern size_t strlcpy(char *dest, const char *src, size_t size);
+#endif

#endif /* __PERF_CACHE_H */
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index 58a470d..029661c 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -22,6 +22,7 @@ static const char *get_perf_dir(void)
return ".";
}

+#ifdef STRLCPY
size_t strlcpy(char *dest, const char *src, size_t size)
{
size_t ret = strlen(src);
@@ -33,7 +34,7 @@ size_t strlcpy(char *dest, const char *src, size_t size)
}
return ret;
}
-
+#endif

static char *get_pathname(void)
{
--
1.7.2.1


2010-08-21 00:41:29

by Kirill A. Shutemov

[permalink] [raw]
Subject: [PATCH 2/2] perf: fix build with -Wl,--as-needed

We need to put all libraries at the end of linking command to be able to
use -Wl,--as-needed (default in some distributions).

python-config --ldconfig also prints -lpython*, but we need to put it
to EXTLIBS, not to ALL_LDFLAGS.

Let's add call of python-config --libs and put its output to EXTLIBS.

Signed-off-by: Kirill A. Shutemov <[email protected]>
---
tools/perf/Makefile | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 496a0d6..a5972f6 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -605,12 +605,14 @@ ifdef NO_LIBPYTHON
BASIC_CFLAGS += -DNO_LIBPYTHON
else
PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null`
+ PYTHON_EMBED_LIBS = `python-config --libs 2>/dev/null`
PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null`
- FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
+ FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS) $(PYTHON_EMBED_LIBS)
ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y)
BASIC_CFLAGS += -DNO_LIBPYTHON
else
ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
+ EXTLIBS += $(PYTHON_EMBED_LIBS)
LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
endif
--
1.7.2.1

2010-08-21 17:15:59

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 1/2] perf: add test for strlcpy()

Em Sat, Aug 21, 2010 at 03:38:20AM +0300, Kirill A. Shutemov escreveu:
> Some Linux distributions like ALT Linux provides patched glibc with
> contains strlcpy(). It's confilcts with strlcpy() from perf.
>
> Let's add check for strlcpy().

It doesn't work on !ALT Linux ;-\

LINK /home/acme/git/build/perf//perf
/home/acme/git/build/perf//libperf.a(path.o): In function `perf_vsnpath':
/home/acme/git/linux/tools/perf/util/path.c:74: undefined reference to `strlcpy'
/home/acme/git/build/perf//libperf.a(abspath.o): In function `get_pwd_cwd':
/home/acme/git/linux/tools/perf/util/abspath.c:16: undefined reference to `strlcpy'
/home/acme/git/build/perf//libperf.a(abspath.o): In function `make_nonrelative_path':
/home/acme/git/linux/tools/perf/util/abspath.c:27: undefined reference to `strlcpy'
collect2: ld returned 1 exit status
make: *** [/home/acme/git/build/perf//perf] Error 1
make: Leaving directory `/home/acme/git/linux/tools/perf'
[acme@emilia linux]$

See below why:

> Signed-off-by: Kirill A. Shutemov <[email protected]>
> ---
> tools/perf/Makefile | 8 ++++++++
> tools/perf/feature-tests.mak | 11 +++++++++++
> tools/perf/util/cache.h | 2 ++
> tools/perf/util/path.c | 3 ++-
> 4 files changed, 23 insertions(+), 1 deletions(-)
>
> diff --git a/tools/perf/Makefile b/tools/perf/Makefile
> index 4f1fa77..496a0d6 100644
> --- a/tools/perf/Makefile
> +++ b/tools/perf/Makefile
> @@ -653,6 +653,14 @@ else
> diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
> index 58a470d..029661c 100644
> --- a/tools/perf/util/path.c
> +++ b/tools/perf/util/path.c
> @@ -22,6 +22,7 @@ static const char *get_perf_dir(void)
> return ".";
> }
>
> +#ifdef STRLCPY

Should be:

+#ifdef NO_STRLCPY

I'm fixing it up.

> size_t strlcpy(char *dest, const char *src, size_t size)
> {
> size_t ret = strlen(src);
> @@ -33,7 +34,7 @@ size_t strlcpy(char *dest, const char *src, size_t size)
> }
> return ret;
> }

2010-08-21 17:24:17

by Kirill A. Shutemov

[permalink] [raw]
Subject: Re: [PATCH 1/2] perf: add test for strlcpy()

On Sat, Aug 21, 2010 at 02:15:37PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Sat, Aug 21, 2010 at 03:38:20AM +0300, Kirill A. Shutemov escreveu:
> > Some Linux distributions like ALT Linux provides patched glibc with
> > contains strlcpy(). It's confilcts with strlcpy() from perf.
> >
> > Let's add check for strlcpy().
>
> It doesn't work on !ALT Linux ;-\
>
> LINK /home/acme/git/build/perf//perf
> /home/acme/git/build/perf//libperf.a(path.o): In function `perf_vsnpath':
> /home/acme/git/linux/tools/perf/util/path.c:74: undefined reference to `strlcpy'
> /home/acme/git/build/perf//libperf.a(abspath.o): In function `get_pwd_cwd':
> /home/acme/git/linux/tools/perf/util/abspath.c:16: undefined reference to `strlcpy'
> /home/acme/git/build/perf//libperf.a(abspath.o): In function `make_nonrelative_path':
> /home/acme/git/linux/tools/perf/util/abspath.c:27: undefined reference to `strlcpy'
> collect2: ld returned 1 exit status
> make: *** [/home/acme/git/build/perf//perf] Error 1
> make: Leaving directory `/home/acme/git/linux/tools/perf'
> [acme@emilia linux]$
>
> See below why:
>
> > Signed-off-by: Kirill A. Shutemov <[email protected]>
> > ---
> > tools/perf/Makefile | 8 ++++++++
> > tools/perf/feature-tests.mak | 11 +++++++++++
> > tools/perf/util/cache.h | 2 ++
> > tools/perf/util/path.c | 3 ++-
> > 4 files changed, 23 insertions(+), 1 deletions(-)
> >
> > diff --git a/tools/perf/Makefile b/tools/perf/Makefile
> > index 4f1fa77..496a0d6 100644
> > --- a/tools/perf/Makefile
> > +++ b/tools/perf/Makefile
> > @@ -653,6 +653,14 @@ else
> > diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
> > index 58a470d..029661c 100644
> > --- a/tools/perf/util/path.c
> > +++ b/tools/perf/util/path.c
> > @@ -22,6 +22,7 @@ static const char *get_perf_dir(void)
> > return ".";
> > }
> >
> > +#ifdef STRLCPY
>
> Should be:
>
> +#ifdef NO_STRLCPY
>

Oops. Sorry.

> I'm fixing it up.
>
> > size_t strlcpy(char *dest, const char *src, size_t size)
> > {
> > size_t ret = strlen(src);
> > @@ -33,7 +34,7 @@ size_t strlcpy(char *dest, const char *src, size_t size)
> > }
> > return ret;
> > }

--
Kirill A. Shutemov

2010-08-21 17:25:40

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 2/2] perf: fix build with -Wl,--as-needed

Tom,
Here it is.

- Arnaldo

Em Sat, Aug 21, 2010 at 03:38:21AM +0300, Kirill A. Shutemov escreveu:
> We need to put all libraries at the end of linking command to be able to
> use -Wl,--as-needed (default in some distributions).
>
> python-config --ldconfig also prints -lpython*, but we need to put it
> to EXTLIBS, not to ALL_LDFLAGS.
>
> Let's add call of python-config --libs and put its output to EXTLIBS.
>
> Signed-off-by: Kirill A. Shutemov <[email protected]>
> ---
> tools/perf/Makefile | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/tools/perf/Makefile b/tools/perf/Makefile
> index 496a0d6..a5972f6 100644
> --- a/tools/perf/Makefile
> +++ b/tools/perf/Makefile
> @@ -605,12 +605,14 @@ ifdef NO_LIBPYTHON
> BASIC_CFLAGS += -DNO_LIBPYTHON
> else
> PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null`
> + PYTHON_EMBED_LIBS = `python-config --libs 2>/dev/null`
> PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null`
> - FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
> + FLAGS_PYTHON_EMBED=$(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS) $(PYTHON_EMBED_LIBS)
> ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y)
> BASIC_CFLAGS += -DNO_LIBPYTHON
> else
> ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
> + EXTLIBS += $(PYTHON_EMBED_LIBS)
> LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
> LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
> endif
> --
> 1.7.2.1

2010-08-21 20:19:44

by Kirill A. Shutemov

[permalink] [raw]
Subject: [tip:perf/core] perf tools: add test for strlcpy()

Commit-ID: f4e7ac0a233a4dc9b51345546ab69c64bb43e2c1
Gitweb: http://git.kernel.org/tip/f4e7ac0a233a4dc9b51345546ab69c64bb43e2c1
Author: Kirill A. Shutemov <[email protected]>
AuthorDate: Sat, 21 Aug 2010 03:38:20 +0300
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sat, 21 Aug 2010 11:22:47 -0300

perf tools: add test for strlcpy()

Some Linux distributions like ALT Linux provides patched glibc with
contains strlcpy(). It's confilcts with strlcpy() from perf.

Let's add check for strlcpy().

Cc: Peter Zijlstra <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Ingo Molnar <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Kirill A. Shutemov <[email protected]>
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/Makefile | 9 +++++++++
tools/perf/feature-tests.mak | 11 +++++++++++
tools/perf/util/cache.h | 2 ++
tools/perf/util/path.c | 3 ++-
4 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index dcb9700..7473de0 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -647,6 +647,15 @@ else
endif
endif

+
+ifdef NO_STRLCPY
+ BASIC_CFLAGS += -DNO_STRLCPY
+else
+ ifneq ($(call try-cc,$(SOURCE_STRLCPY),),y)
+ BASIC_CFLAGS += -DNO_STRLCPY
+ endif
+endif
+
ifndef CC_LD_DYNPATH
ifdef NO_R_TO_GCC_LINKER
# Some gcc does not accept and pass -R to the linker to specify
diff --git a/tools/perf/feature-tests.mak b/tools/perf/feature-tests.mak
index ddb68e6..ef3d0d6 100644
--- a/tools/perf/feature-tests.mak
+++ b/tools/perf/feature-tests.mak
@@ -110,6 +110,17 @@ int main(void)
}
endef

+define SOURCE_STRLCPY
+#include <stdlib.h>
+extern size_t strlcpy(char *dest, const char *src, size_t size);
+
+int main(void)
+{
+ strlcpy(NULL, NULL, 0);
+ return 0;
+}
+endef
+
# try-cc
# Usage: option = $(call try-cc, source-to-build, cc-options)
try-cc = $(shell sh -c \
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index 27e9ebe..a772979 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -82,6 +82,8 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2
extern char *perf_pathdup(const char *fmt, ...)
__attribute__((format (printf, 1, 2)));

+#ifdef NO_STRLCPY
extern size_t strlcpy(char *dest, const char *src, size_t size);
+#endif

#endif /* __PERF_CACHE_H */
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index 58a470d..bd74977 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -22,6 +22,7 @@ static const char *get_perf_dir(void)
return ".";
}

+#ifdef NO_STRLCPY
size_t strlcpy(char *dest, const char *src, size_t size)
{
size_t ret = strlen(src);
@@ -33,7 +34,7 @@ size_t strlcpy(char *dest, const char *src, size_t size)
}
return ret;
}
-
+#endif

static char *get_pathname(void)
{