Skip to content

Commit 8feb8ef

Browse files
committed
tools build feature: Check if get_current_dir_name() is available
As the namespace support code will use this, which is not available in some non _GNU_SOURCE libraries such as Android's bionic used in my container build tests (r12b and r15c at the moment). Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: https://lkml.kernel.org/n/tip-x56ypm940pwclwu45d7jfj47@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent fb50c09 commit 8feb8ef

8 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎tools/build/Makefile.feature‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ FEATURE_TESTS_BASIC := \
3333
dwarf_getlocations \
3434
fortify-source \
3535
sync-compare-and-swap \
36+
get_current_dir_name \
3637
glibc \
3738
gtk2 \
3839
gtk2-infobar \

‎tools/build/feature/Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ FILES= \
77
test-dwarf_getlocations.bin \
88
test-fortify-source.bin \
99
test-sync-compare-and-swap.bin \
10+
test-get_current_dir_name.bin \
1011
test-glibc.bin \
1112
test-gtk2.bin \
1213
test-gtk2-infobar.bin \
@@ -101,6 +102,9 @@ $(OUTPUT)test-bionic.bin:
101102
$(OUTPUT)test-libelf.bin:
102103
$(BUILD) -lelf
103104

105+
$(OUTPUT)test-get_current_dir_name.bin:
106+
$(BUILD)
107+
104108
$(OUTPUT)test-glibc.bin:
105109
$(BUILD)
106110

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
# include "test-libelf-mmap.c"
3535
#undef main
3636

37+
#define main main_test_get_current_dir_name
38+
# include "test-get_current_dir_name.c"
39+
#undef main
40+
3741
#define main main_test_glibc
3842
# include "test-glibc.c"
3943
#undef main
@@ -174,6 +178,7 @@ int main(int argc, char *argv[])
174178
main_test_hello();
175179
main_test_libelf();
176180
main_test_libelf_mmap();
181+
main_test_get_current_dir_name();
177182
main_test_glibc();
178183
main_test_dwarf();
179184
main_test_dwarf_getlocations();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#define _GNU_SOURCE
3+
#include <unistd.h>
4+
#include <stdlib.h>
5+
6+
int main(void)
7+
{
8+
free(get_current_dir_name());
9+
return 0;
10+
}

‎tools/perf/Makefile.config‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ ifndef NO_BIONIC
299299
endif
300300
endif
301301

302+
ifeq ($(feature-get_current_dir_name), 1)
303+
CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
304+
endif
305+
306+
302307
ifdef NO_LIBELF
303308
NO_DWARF := 1
304309
NO_DEMANGLE := 1

‎tools/perf/util/Build‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ libperf-y += evlist.o
1010
libperf-y += evsel.o
1111
libperf-y += evsel_fprintf.o
1212
libperf-y += find_bit.o
13+
libperf-y += get_current_dir_name.o
1314
libperf-y += kallsyms.o
1415
libperf-y += levenshtein.o
1516
libperf-y += llvm-utils.o
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (C) 2018, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
3+
//
4+
#ifndef HAVE_GET_CURRENT_DIR_NAME
5+
#include "util.h"
6+
#include <unistd.h>
7+
#include <stdlib.h>
8+
#include <stdlib.h>
9+
10+
/* Android's 'bionic' library, for one, doesn't have this */
11+
12+
char *get_current_dir_name(void)
13+
{
14+
char pwd[PATH_MAX];
15+
16+
return getcwd(pwd, sizeof(pwd)) == NULL ? NULL : strdup(pwd);
17+
}
18+
#endif // HAVE_GET_CURRENT_DIR_NAME

‎tools/perf/util/util.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ int fetch_kernel_version(unsigned int *puint,
5959

6060
const char *perf_tip(const char *dirpath);
6161

62+
#ifndef HAVE_GET_CURRENT_DIR_NAME
63+
char *get_current_dir_name(void);
64+
#endif
65+
6266
#ifndef HAVE_SCHED_GETCPU_SUPPORT
6367
int sched_getcpu(void);
6468
#endif

0 commit comments

Comments
 (0)