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

tools build: Check if gettid() is available before providing helper

Laura reported that the perf build failed in fedora when we got a glibc
that provides gettid(), which I reproduced using fedora rawhide with the
glibc-devel-2.29.9000-26.fc31.x86_64 package.

Add a feature check to avoid providing a gettid() helper in such
systems.

On a fedora rawhide system with this patch applied we now get:

[root@7a5f55352234 perf]# grep gettid /tmp/build/perf/FEATURE-DUMP
feature-gettid=1
[root@7a5f55352234 perf]# cat /tmp/build/perf/feature/test-gettid.make.output
[root@7a5f55352234 perf]# ldd /tmp/build/perf/feature/test-gettid.bin
linux-vdso.so.1 (0x00007ffc6b1f6000)
libc.so.6 => /lib64/libc.so.6 (0x00007f04e0a74000)
/lib64/ld-linux-x86-64.so.2 (0x00007f04e0c47000)
[root@7a5f55352234 perf]# nm /tmp/build/perf/feature/test-gettid.bin | grep -w gettid
U gettid@@GLIBC_2.30
[root@7a5f55352234 perf]#

While on a fedora:29 system:

[acme@quaco perf]$ grep gettid /tmp/build/perf/FEATURE-DUMP
feature-gettid=0
[acme@quaco perf]$ cat /tmp/build/perf/feature/test-gettid.make.output
test-gettid.c: In function ‘main’:
test-gettid.c:8:9: error: implicit declaration of function ‘gettid’; did you mean ‘getgid’? [-Werror=implicit-function-declaration]
return gettid();
^~~~~~
getgid
cc1: all warnings being treated as errors
[acme@quaco perf]$

Reported-by: Laura Abbott <labbott@redhat.com>
Tested-by: Laura Abbott <labbott@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lkml.kernel.org/n/tip-yfy3ch53agmklwu9o7rlgf9c@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+27
+1
tools/build/Makefile.feature
··· 36 36 fortify-source \ 37 37 sync-compare-and-swap \ 38 38 get_current_dir_name \ 39 + gettid \ 39 40 glibc \ 40 41 gtk2 \ 41 42 gtk2-infobar \
+4
tools/build/feature/Makefile
··· 54 54 test-get_cpuid.bin \ 55 55 test-sdt.bin \ 56 56 test-cxx.bin \ 57 + test-gettid.bin \ 57 58 test-jvmti.bin \ 58 59 test-jvmti-cmlr.bin \ 59 60 test-sched_getcpu.bin \ ··· 267 266 268 267 $(OUTPUT)test-cxx.bin: 269 268 $(BUILDXX) -std=gnu++11 269 + 270 + $(OUTPUT)test-gettid.bin: 271 + $(BUILD) 270 272 271 273 $(OUTPUT)test-jvmti.bin: 272 274 $(BUILD)
+5
tools/build/feature/test-all.c
··· 38 38 # include "test-get_current_dir_name.c" 39 39 #undef main 40 40 41 + #define main main_test_gettid 42 + # include "test-gettid.c" 43 + #undef main 44 + 41 45 #define main main_test_glibc 42 46 # include "test-glibc.c" 43 47 #undef main ··· 199 195 main_test_libelf(); 200 196 main_test_libelf_mmap(); 201 197 main_test_get_current_dir_name(); 198 + main_test_gettid(); 202 199 main_test_glibc(); 203 200 main_test_dwarf(); 204 201 main_test_dwarf_getlocations();
+11
tools/build/feature/test-gettid.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Copyright (C) 2019, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> 3 + #define _GNU_SOURCE 4 + #include <unistd.h> 5 + 6 + int main(void) 7 + { 8 + return gettid(); 9 + } 10 + 11 + #undef _GNU_SOURCE
+4
tools/perf/Makefile.config
··· 332 332 CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME 333 333 endif 334 334 335 + ifeq ($(feature-gettid), 1) 336 + CFLAGS += -DHAVE_GETTID 337 + endif 338 + 335 339 ifdef NO_LIBELF 336 340 NO_DWARF := 1 337 341 NO_DEMANGLE := 1
+2
tools/perf/jvmti/jvmti_agent.c
··· 45 45 static char jit_path[PATH_MAX]; 46 46 static void *marker_addr; 47 47 48 + #ifndef HAVE_GETTID 48 49 static inline pid_t gettid(void) 49 50 { 50 51 return (pid_t)syscall(__NR_gettid); 51 52 } 53 + #endif 52 54 53 55 static int get_e_machine(struct jitheader *hdr) 54 56 {