Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+12 -24
-7
tools/perf/config/Makefile
··· 121 121 libperl \ 122 122 libpython \ 123 123 libpython-version \ 124 - strlcpy \ 125 124 libbfd \ 126 125 on-exit \ 127 126 backtrace \ ··· 432 433 endif 433 434 endif 434 435 endif 435 - endif 436 - endif 437 - 438 - ifndef NO_STRLCPY 439 - ifeq ($(feature-strlcpy), 1) 440 - CFLAGS += -DHAVE_STRLCPY_SUPPORT 441 436 endif 442 437 endif 443 438
-4
tools/perf/config/feature-checks/Makefile
··· 19 19 test-libperl \ 20 20 test-libpython \ 21 21 test-libpython-version \ 22 - test-strlcpy \ 23 22 test-libbfd \ 24 23 test-on-exit \ 25 24 test-backtrace \ ··· 114 115 115 116 test-libpython-version: 116 117 $(BUILD) $(FLAGS_PYTHON_EMBED) 117 - 118 - test-strlcpy: 119 - $(BUILD) 120 118 121 119 test-libbfd: 122 120 $(BUILD) -DPACKAGE='perf' -DPACKAGE=perf -lbfd -ldl
-8
tools/perf/config/feature-checks/test-strlcpy.c
··· 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 - }
+1 -2
tools/perf/util/cache.h
··· 70 70 extern char *perf_pathdup(const char *fmt, ...) 71 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 74 extern size_t strlcpy(char *dest, const char *src, size_t size); 75 - #endif 76 75 77 76 #endif /* __PERF_CACHE_H */
+4
tools/perf/util/include/linux/compiler.h
··· 23 23 # define __force 24 24 #endif 25 25 26 + #ifndef __weak 27 + # define __weak __attribute__((weak)) 28 + #endif 29 + 26 30 #endif
+7 -3
tools/perf/util/path.c
··· 22 22 return "."; 23 23 } 24 24 25 - #ifndef HAVE_STRLCPY_SUPPORT 26 - size_t strlcpy(char *dest, const char *src, size_t size) 25 + /* 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 31 size_t ret = strlen(src); 29 32 30 33 if (size) { 31 34 size_t len = (ret >= size) ? size - 1 : ret; 35 + 32 36 memcpy(dest, src, len); 33 37 dest[len] = '\0'; 34 38 } 39 + 35 40 return ret; 36 41 } 37 - #endif 38 42 39 43 static char *get_pathname(void) 40 44 {