Commit fb1c9185 authored by Ingo Molnar's avatar Ingo Molnar

tools/perf: Turn strlcpy() into a __weak function

The strlcpy() feature check slows every build unnecessarily - so make it
a __weak function so it does not have to be auto-detected.

If the libc (or any other library) has an strlcpy() implementation it will
be used - otherwise our fallback is active.

Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/n/tip-zjbrcupapu08ePsyYhhhxiwk@git.kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 7a10822a
...@@ -121,7 +121,6 @@ FEATURE_TESTS = \ ...@@ -121,7 +121,6 @@ FEATURE_TESTS = \
libperl \ libperl \
libpython \ libpython \
libpython-version \ libpython-version \
strlcpy \
libbfd \ libbfd \
on-exit \ on-exit \
backtrace \ backtrace \
...@@ -436,12 +435,6 @@ else ...@@ -436,12 +435,6 @@ else
endif endif
endif endif
ifndef NO_STRLCPY
ifeq ($(feature-strlcpy), 1)
CFLAGS += -DHAVE_STRLCPY_SUPPORT
endif
endif
ifndef NO_ON_EXIT ifndef NO_ON_EXIT
ifeq ($(feature-on-exit), 1) ifeq ($(feature-on-exit), 1)
CFLAGS += -DHAVE_ON_EXIT_SUPPORT CFLAGS += -DHAVE_ON_EXIT_SUPPORT
......
...@@ -19,7 +19,6 @@ FILES= \ ...@@ -19,7 +19,6 @@ FILES= \
test-libperl \ test-libperl \
test-libpython \ test-libpython \
test-libpython-version \ test-libpython-version \
test-strlcpy \
test-libbfd \ test-libbfd \
test-on-exit \ test-on-exit \
test-backtrace \ test-backtrace \
...@@ -116,9 +115,6 @@ test-libpython: ...@@ -116,9 +115,6 @@ test-libpython:
test-libpython-version: test-libpython-version:
$(BUILD) $(FLAGS_PYTHON_EMBED) $(BUILD) $(FLAGS_PYTHON_EMBED)
test-strlcpy:
$(BUILD)
test-libbfd: test-libbfd:
$(BUILD) -DPACKAGE='perf' -DPACKAGE=perf -lbfd -ldl $(BUILD) -DPACKAGE='perf' -DPACKAGE=perf -lbfd -ldl
......
#include <stdlib.h>
extern size_t strlcpy(char *dest, const char *src, size_t size);
int main(void)
{
strlcpy(NULL, NULL, 0);
return 0;
}
...@@ -70,8 +70,7 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2 ...@@ -70,8 +70,7 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2
extern char *perf_pathdup(const char *fmt, ...) extern char *perf_pathdup(const char *fmt, ...)
__attribute__((format (printf, 1, 2))); __attribute__((format (printf, 1, 2)));
#ifndef HAVE_STRLCPY_SUPPORT /* Matches the libc/libbsd function attribute so we declare this unconditionally: */
extern size_t strlcpy(char *dest, const char *src, size_t size); extern size_t strlcpy(char *dest, const char *src, size_t size);
#endif
#endif /* __PERF_CACHE_H */ #endif /* __PERF_CACHE_H */
...@@ -23,4 +23,8 @@ ...@@ -23,4 +23,8 @@
# define __force # define __force
#endif #endif
#ifndef __weak
# define __weak __attribute__((weak))
#endif
#endif #endif
...@@ -22,19 +22,23 @@ static const char *get_perf_dir(void) ...@@ -22,19 +22,23 @@ static const char *get_perf_dir(void)
return "."; return ".";
} }
#ifndef HAVE_STRLCPY_SUPPORT /*
size_t strlcpy(char *dest, const char *src, size_t size) * If libc has strlcpy() then that version will override this
* implementation:
*/
size_t __weak strlcpy(char *dest, const char *src, size_t size)
{ {
size_t ret = strlen(src); size_t ret = strlen(src);
if (size) { if (size) {
size_t len = (ret >= size) ? size - 1 : ret; size_t len = (ret >= size) ? size - 1 : ret;
memcpy(dest, src, len); memcpy(dest, src, len);
dest[len] = '\0'; dest[len] = '\0';
} }
return ret; return ret;
} }
#endif
static char *get_pathname(void) static char *get_pathname(void)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment