Skip to content

Commit 4541a8b

Browse files
committed
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>
1 parent e01f0ef commit 4541a8b

6 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎tools/build/Makefile.feature‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ FEATURE_TESTS_BASIC := \
3636
fortify-source \
3737
sync-compare-and-swap \
3838
get_current_dir_name \
39+
gettid \
3940
glibc \
4041
gtk2 \
4142
gtk2-infobar \

‎tools/build/feature/Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ FILES= \
5454
test-get_cpuid.bin \
5555
test-sdt.bin \
5656
test-cxx.bin \
57+
test-gettid.bin \
5758
test-jvmti.bin \
5859
test-jvmti-cmlr.bin \
5960
test-sched_getcpu.bin \
@@ -267,6 +268,9 @@ $(OUTPUT)test-sdt.bin:
267268
$(OUTPUT)test-cxx.bin:
268269
$(BUILDXX) -std=gnu++11
269270

271+
$(OUTPUT)test-gettid.bin:
272+
$(BUILD)
273+
270274
$(OUTPUT)test-jvmti.bin:
271275
$(BUILD)
272276

‎tools/build/feature/test-all.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
# include "test-get_current_dir_name.c"
3939
#undef main
4040

41+
#define main main_test_gettid
42+
# include "test-gettid.c"
43+
#undef main
44+
4145
#define main main_test_glibc
4246
# include "test-glibc.c"
4347
#undef main
@@ -195,6 +199,7 @@ int main(int argc, char *argv[])
195199
main_test_libelf();
196200
main_test_libelf_mmap();
197201
main_test_get_current_dir_name();
202+
main_test_gettid();
198203
main_test_glibc();
199204
main_test_dwarf();
200205
main_test_dwarf_getlocations();

‎tools/build/feature/test-gettid.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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

‎tools/perf/Makefile.config‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ ifeq ($(feature-get_current_dir_name), 1)
332332
CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
333333
endif
334334

335+
ifeq ($(feature-gettid), 1)
336+
CFLAGS += -DHAVE_GETTID
337+
endif
338+
335339
ifdef NO_LIBELF
336340
NO_DWARF := 1
337341
NO_DEMANGLE := 1

‎tools/perf/jvmti/jvmti_agent.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
static char jit_path[PATH_MAX];
4646
static void *marker_addr;
4747

48+
#ifndef HAVE_GETTID
4849
static inline pid_t gettid(void)
4950
{
5051
return (pid_t)syscall(__NR_gettid);
5152
}
53+
#endif
5254

5355
static int get_e_machine(struct jitheader *hdr)
5456
{

0 commit comments

Comments
 (0)