tools/perf: Turn strlcpy() into a __weak function
authorIngo Molnar <mingo@kernel.org>
Tue, 1 Oct 2013 11:26:13 +0000 (13:26 +0200)
committerIngo Molnar <mingo@kernel.org>
Wed, 9 Oct 2013 06:48:49 +0000 (08:48 +0200)
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>
tools/perf/config/Makefile
tools/perf/config/feature-checks/Makefile
tools/perf/config/feature-checks/test-strlcpy.c [deleted file]
tools/perf/util/cache.h
tools/perf/util/include/linux/compiler.h
tools/perf/util/path.c

index c0c83440de9794b0bb68d98d807ece895f8e362a..3207c25b15f03b482b08993194ac5bee3e073733 100644 (file)
@@ -121,7 +121,6 @@ FEATURE_TESTS =                             \
        libperl                         \
        libpython                       \
        libpython-version               \
-       strlcpy                         \
        libbfd                          \
        on-exit                         \
        backtrace                       \
@@ -436,12 +435,6 @@ else
   endif
 endif
 
-ifndef NO_STRLCPY
-  ifeq ($(feature-strlcpy), 1)
-    CFLAGS += -DHAVE_STRLCPY_SUPPORT
-  endif
-endif
-
 ifndef NO_ON_EXIT
   ifeq ($(feature-on-exit), 1)
     CFLAGS += -DHAVE_ON_EXIT_SUPPORT
index 0e4dbc2d5c8af925e68e270b6f08f77b7119cb4d..c65bdac0ebe21b2bc32ce781964cf335edc2cd02 100644 (file)
@@ -19,7 +19,6 @@ FILES=                                        \
        test-libperl                    \
        test-libpython                  \
        test-libpython-version          \
-       test-strlcpy                    \
        test-libbfd                     \
        test-on-exit                    \
        test-backtrace                  \
@@ -116,9 +115,6 @@ test-libpython:
 test-libpython-version:
        $(BUILD) $(FLAGS_PYTHON_EMBED)
 
-test-strlcpy:
-       $(BUILD)
-
 test-libbfd:
        $(BUILD) -DPACKAGE='perf' -DPACKAGE=perf -lbfd -ldl
 
diff --git a/tools/perf/config/feature-checks/test-strlcpy.c b/tools/perf/config/feature-checks/test-strlcpy.c
deleted file mode 100644 (file)
index 4a6b6ff..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <stdlib.h>
-extern size_t strlcpy(char *dest, const char *src, size_t size);
-
-int main(void)
-{
-       strlcpy(NULL, NULL, 0);
-       return 0;
-}
index 442953c1ce852d0cfd28ebc66f3eb4ee2e863e37..7b176dd02e1ae94e6f5479b78ae4c2e84bb7836c 100644 (file)
@@ -70,8 +70,7 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2
 extern char *perf_pathdup(const char *fmt, ...)
        __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);
-#endif
 
 #endif /* __PERF_CACHE_H */
index bef4d3ddc493f9774853700c5560b069d9403d6e..b003ad7200b230702b133071ab3d402395ab57e6 100644 (file)
@@ -23,4 +23,8 @@
 # define __force
 #endif
 
+#ifndef __weak
+# define __weak                        __attribute__((weak))
+#endif
+
 #endif
index f3958743b7433da906712925444e1fce65984acb..5d13cb45b3171a98a171b0f7228d1fff470bf8c0 100644 (file)
@@ -22,19 +22,23 @@ static const char *get_perf_dir(void)
        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);
 
        if (size) {
                size_t len = (ret >= size) ? size - 1 : ret;
+
                memcpy(dest, src, len);
                dest[len] = '\0';
        }
+
        return ret;
 }
-#endif
 
 static char *get_pathname(void)
 {