diff options
author | Ingo Molnar <mingo@kernel.org> | 2013-10-01 07:26:13 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2013-10-09 02:48:49 -0400 |
commit | fb1c9185e36cf9c616ac15f54e54a01f052672bd (patch) | |
tree | ab6bcf354a39a2e662fd3492ca9f8b4384b3a7d9 | |
parent | 7a10822a30060eceddda16c051086c00acb449c9 (diff) |
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.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | tools/perf/config/Makefile | 7 | ||||
-rw-r--r-- | tools/perf/config/feature-checks/Makefile | 4 | ||||
-rw-r--r-- | tools/perf/config/feature-checks/test-strlcpy.c | 8 | ||||
-rw-r--r-- | tools/perf/util/cache.h | 3 | ||||
-rw-r--r-- | tools/perf/util/include/linux/compiler.h | 4 | ||||
-rw-r--r-- | tools/perf/util/path.c | 10 |
6 files changed, 12 insertions, 24 deletions
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile index c0c83440de97..3207c25b15f0 100644 --- a/tools/perf/config/Makefile +++ b/tools/perf/config/Makefile | |||
@@ -121,7 +121,6 @@ FEATURE_TESTS = \ | |||
121 | libperl \ | 121 | libperl \ |
122 | libpython \ | 122 | libpython \ |
123 | libpython-version \ | 123 | libpython-version \ |
124 | strlcpy \ | ||
125 | libbfd \ | 124 | libbfd \ |
126 | on-exit \ | 125 | on-exit \ |
127 | backtrace \ | 126 | backtrace \ |
@@ -436,12 +435,6 @@ else | |||
436 | endif | 435 | endif |
437 | endif | 436 | endif |
438 | 437 | ||
439 | ifndef NO_STRLCPY | ||
440 | ifeq ($(feature-strlcpy), 1) | ||
441 | CFLAGS += -DHAVE_STRLCPY_SUPPORT | ||
442 | endif | ||
443 | endif | ||
444 | |||
445 | ifndef NO_ON_EXIT | 438 | ifndef NO_ON_EXIT |
446 | ifeq ($(feature-on-exit), 1) | 439 | ifeq ($(feature-on-exit), 1) |
447 | CFLAGS += -DHAVE_ON_EXIT_SUPPORT | 440 | CFLAGS += -DHAVE_ON_EXIT_SUPPORT |
diff --git a/tools/perf/config/feature-checks/Makefile b/tools/perf/config/feature-checks/Makefile index 0e4dbc2d5c8a..c65bdac0ebe2 100644 --- a/tools/perf/config/feature-checks/Makefile +++ b/tools/perf/config/feature-checks/Makefile | |||
@@ -19,7 +19,6 @@ FILES= \ | |||
19 | test-libperl \ | 19 | test-libperl \ |
20 | test-libpython \ | 20 | test-libpython \ |
21 | test-libpython-version \ | 21 | test-libpython-version \ |
22 | test-strlcpy \ | ||
23 | test-libbfd \ | 22 | test-libbfd \ |
24 | test-on-exit \ | 23 | test-on-exit \ |
25 | test-backtrace \ | 24 | test-backtrace \ |
@@ -116,9 +115,6 @@ test-libpython: | |||
116 | test-libpython-version: | 115 | test-libpython-version: |
117 | $(BUILD) $(FLAGS_PYTHON_EMBED) | 116 | $(BUILD) $(FLAGS_PYTHON_EMBED) |
118 | 117 | ||
119 | test-strlcpy: | ||
120 | $(BUILD) | ||
121 | |||
122 | test-libbfd: | 118 | test-libbfd: |
123 | $(BUILD) -DPACKAGE='perf' -DPACKAGE=perf -lbfd -ldl | 119 | $(BUILD) -DPACKAGE='perf' -DPACKAGE=perf -lbfd -ldl |
124 | 120 | ||
diff --git a/tools/perf/config/feature-checks/test-strlcpy.c b/tools/perf/config/feature-checks/test-strlcpy.c deleted file mode 100644 index 4a6b6ff06f74..000000000000 --- a/tools/perf/config/feature-checks/test-strlcpy.c +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | #include <stdlib.h> | ||
2 | extern size_t strlcpy(char *dest, const char *src, size_t size); | ||
3 | |||
4 | int main(void) | ||
5 | { | ||
6 | strlcpy(NULL, NULL, 0); | ||
7 | return 0; | ||
8 | } | ||
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 442953c1ce85..7b176dd02e1a 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h | |||
@@ -70,8 +70,7 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2 | |||
70 | extern char *perf_pathdup(const char *fmt, ...) | 70 | extern char *perf_pathdup(const char *fmt, ...) |
71 | __attribute__((format (printf, 1, 2))); | 71 | __attribute__((format (printf, 1, 2))); |
72 | 72 | ||
73 | #ifndef HAVE_STRLCPY_SUPPORT | 73 | /* Matches the libc/libbsd function attribute so we declare this unconditionally: */ |
74 | extern size_t strlcpy(char *dest, const char *src, size_t size); | 74 | extern size_t strlcpy(char *dest, const char *src, size_t size); |
75 | #endif | ||
76 | 75 | ||
77 | #endif /* __PERF_CACHE_H */ | 76 | #endif /* __PERF_CACHE_H */ |
diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h index bef4d3ddc493..b003ad7200b2 100644 --- a/tools/perf/util/include/linux/compiler.h +++ b/tools/perf/util/include/linux/compiler.h | |||
@@ -23,4 +23,8 @@ | |||
23 | # define __force | 23 | # define __force |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | #ifndef __weak | ||
27 | # define __weak __attribute__((weak)) | ||
28 | #endif | ||
29 | |||
26 | #endif | 30 | #endif |
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c index f3958743b743..5d13cb45b317 100644 --- a/tools/perf/util/path.c +++ b/tools/perf/util/path.c | |||
@@ -22,19 +22,23 @@ static const char *get_perf_dir(void) | |||
22 | return "."; | 22 | return "."; |
23 | } | 23 | } |
24 | 24 | ||
25 | #ifndef HAVE_STRLCPY_SUPPORT | 25 | /* |
26 | size_t strlcpy(char *dest, const char *src, size_t size) | 26 | * If libc has strlcpy() then that version will override this |
27 | * implementation: | ||
28 | */ | ||
29 | size_t __weak strlcpy(char *dest, const char *src, size_t size) | ||
27 | { | 30 | { |
28 | size_t ret = strlen(src); | 31 | size_t ret = strlen(src); |
29 | 32 | ||
30 | if (size) { | 33 | if (size) { |
31 | size_t len = (ret >= size) ? size - 1 : ret; | 34 | size_t len = (ret >= size) ? size - 1 : ret; |
35 | |||
32 | memcpy(dest, src, len); | 36 | memcpy(dest, src, len); |
33 | dest[len] = '\0'; | 37 | dest[len] = '\0'; |
34 | } | 38 | } |
39 | |||
35 | return ret; | 40 | return ret; |
36 | } | 41 | } |
37 | #endif | ||
38 | 42 | ||
39 | static char *get_pathname(void) | 43 | static char *get_pathname(void) |
40 | { | 44 | { |