From 1cd6472e3f8d3fdee0fd19f7088807b284d3080f Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 1 Dec 2016 14:00:25 +0100 Subject: tools build: Make fixdep parsing wait for last target The fixdep tool, among other things, replaces the target of the object in the gcc generated dependency output file. The parsing code assumes there's only single target in the rule but this is not always the case as described in here: https://gcc.gnu.org/ml/gcc-help/2016-11/msg00099.html Make the fixdep code smart enough to skip all the possible targets. Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Acked-by: Peter Foley Cc: Wang Nan Link: http://lkml.kernel.org/r/20161201130025.GA16430@krava Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/fixdep.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tools/build') diff --git a/tools/build/fixdep.c b/tools/build/fixdep.c index 1521d36cef0d..734d1547cbae 100644 --- a/tools/build/fixdep.c +++ b/tools/build/fixdep.c @@ -49,7 +49,7 @@ static void parse_dep_file(void *map, size_t len) char *end = m + len; char *p; char s[PATH_MAX]; - int is_target; + int is_target, has_target = 0; int saw_any_target = 0; int is_first_dep = 0; @@ -67,7 +67,8 @@ static void parse_dep_file(void *map, size_t len) if (is_target) { /* The /next/ file is the first dependency */ is_first_dep = 1; - } else { + has_target = 1; + } else if (has_target) { /* Save this token/filename */ memcpy(s, m, p-m); s[p - m] = 0; -- cgit v1.2.3-73-gaa49b From baa1973ebcf6a7bd15522a5b6a35a8fefd6cb232 Mon Sep 17 00:00:00 2001 From: Peter Foley Date: Sun, 27 Nov 2016 21:43:46 -0500 Subject: tools build: Fix objtool build with clang Clang doesn't support multiple arguments being passed to -Wp, so split them. Fixes this error: HOSTCC tools/objtool/fixdep.o cat: tools/objtool/.fixdep.o.d: No such file or directory Signed-off-by: Peter Foley Tested-by: Arnaldo Carvalho de Melo Acked-by: Jiri Olsa Cc: Wang Nan Link: http://lkml.kernel.org/r/20161128024346.17371-1-pefoley2@pefoley.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/Build.include | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/build') diff --git a/tools/build/Build.include b/tools/build/Build.include index c4ae12a5d0a5..62dcf0c7aac2 100644 --- a/tools/build/Build.include +++ b/tools/build/Build.include @@ -89,12 +89,12 @@ if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ # - per target C flags # - per object C flags # - BUILD_STR macro to allow '-D"$(variable)"' constructs -c_flags_1 = -Wp,-MD,$(depfile),-MT,$@ $(CFLAGS) -D"BUILD_STR(s)=\#s" $(CFLAGS_$(basetarget).o) $(CFLAGS_$(obj)) +c_flags_1 = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CFLAGS) -D"BUILD_STR(s)=\#s" $(CFLAGS_$(basetarget).o) $(CFLAGS_$(obj)) c_flags_2 = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(c_flags_1)) c_flags = $(filter-out $(CFLAGS_REMOVE_$(obj)), $(c_flags_2)) -cxx_flags = -Wp,-MD,$(depfile),-MT,$@ $(CXXFLAGS) -D"BUILD_STR(s)=\#s" $(CXXFLAGS_$(basetarget).o) $(CXXFLAGS_$(obj)) +cxx_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CXXFLAGS) -D"BUILD_STR(s)=\#s" $(CXXFLAGS_$(basetarget).o) $(CXXFLAGS_$(obj)) ### ## HOSTCC C flags -host_c_flags = -Wp,-MD,$(depfile),-MT,$@ $(CHOSTFLAGS) -D"BUILD_STR(s)=\#s" $(CHOSTFLAGS_$(basetarget).o) $(CHOSTFLAGS_$(obj)) +host_c_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CHOSTFLAGS) -D"BUILD_STR(s)=\#s" $(CHOSTFLAGS_$(basetarget).o) $(CHOSTFLAGS_$(obj)) -- cgit v1.2.3-73-gaa49b From cb40d55b595cd117ef7c1880247605875b2115e8 Mon Sep 17 00:00:00 2001 From: Wang Nan Date: Sat, 26 Nov 2016 07:03:31 +0000 Subject: tools build: Add feature detection for LLVM Check if basic LLVM compiling environment is ready. Use llvm-config to detect include and library directories. Avoid using 'llvm-config --cxxflags' because its result contain some unwanted flags like --sysroot (if LLVM is built by yocto). Use '?=' to set LLVM_CONFIG, so explicitly passing LLVM_CONFIG to make would override it. Use 'llvm-config --libs BPF' to check if BPF backend is compiled in. Since now BPF bytecode is the only required backend, no need to waste time linking llvm and clang if BPF backend is missing. This also introduce an implicit requirement that LLVM should be new enough. Old LLVM doesn't support BPF backend. Signed-off-by: Wang Nan Cc: Alexei Starovoitov Cc: He Kuang Cc: Jiri Olsa Cc: Joe Stringer Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/20161126070354.141764-8-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/feature/Makefile | 8 ++++++++ tools/build/feature/test-llvm.cpp | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 tools/build/feature/test-llvm.cpp (limited to 'tools/build') diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index 8f668bce8996..c09de59affc9 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -55,6 +55,7 @@ FILES := $(addprefix $(OUTPUT),$(FILES)) CC := $(CROSS_COMPILE)gcc -MD CXX := $(CROSS_COMPILE)g++ -MD PKG_CONFIG := $(CROSS_COMPILE)pkg-config +LLVM_CONFIG ?= llvm-config all: $(FILES) @@ -229,6 +230,13 @@ $(OUTPUT)test-cxx.bin: $(OUTPUT)test-jvmti.bin: $(BUILD) +$(OUTPUT)test-llvm.bin: + $(BUILDXX) -std=gnu++11 \ + -I$(shell $(LLVM_CONFIG) --includedir) \ + -L$(shell $(LLVM_CONFIG) --libdir) \ + $(shell $(LLVM_CONFIG) --libs Core BPF) \ + $(shell $(LLVM_CONFIG) --system-libs) + -include $(OUTPUT)*.d ############################### diff --git a/tools/build/feature/test-llvm.cpp b/tools/build/feature/test-llvm.cpp new file mode 100644 index 000000000000..d8d2cee35345 --- /dev/null +++ b/tools/build/feature/test-llvm.cpp @@ -0,0 +1,8 @@ +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/raw_ostream.h" +int main() +{ + llvm::errs() << "Hello World!\n"; + llvm::llvm_shutdown(); + return 0; +} -- cgit v1.2.3-73-gaa49b From c7fb4f62e2a97bd25d555263ef501fe053edcbb6 Mon Sep 17 00:00:00 2001 From: Wang Nan Date: Sat, 26 Nov 2016 07:03:32 +0000 Subject: tools build: Add feature detection for clang Check if basic clang compiling environment is ready. Doesn't like 'llvm-config --libs' which can returns llvm libraries in right order and duplicates some libraries if necessary, there's no correspondence for clang libraries (-lclangxxx). to avoid extra complexity and to avoid new clang breaking libraries ordering, use --start-group and --end-group. In this test case, manually identify required clang libs and hope it to be stable. Putting all clang libraries here is possible (use make's wildcard), but then feature checking becomes very slow. Signed-off-by: Wang Nan Cc: Alexei Starovoitov Cc: He Kuang Cc: Jiri Olsa Cc: Joe Stringer Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/20161126070354.141764-9-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/feature/Makefile | 10 ++++++++++ tools/build/feature/test-clang.cpp | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tools/build/feature/test-clang.cpp (limited to 'tools/build') diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index c09de59affc9..871d5536951d 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -237,6 +237,16 @@ $(OUTPUT)test-llvm.bin: $(shell $(LLVM_CONFIG) --libs Core BPF) \ $(shell $(LLVM_CONFIG) --system-libs) +$(OUTPUT)test-clang.bin: + $(BUILDXX) -std=gnu++11 \ + -I$(shell $(LLVM_CONFIG) --includedir) \ + -L$(shell $(LLVM_CONFIG) --libdir) \ + -Wl,--start-group -lclangBasic -lclangDriver \ + -lclangFrontend -lclangEdit -lclangLex \ + -lclangAST -Wl,--end-group \ + $(shell $(LLVM_CONFIG) --libs Core option) \ + $(shell $(LLVM_CONFIG) --system-libs) + -include $(OUTPUT)*.d ############################### diff --git a/tools/build/feature/test-clang.cpp b/tools/build/feature/test-clang.cpp new file mode 100644 index 000000000000..e23c1b1f1b91 --- /dev/null +++ b/tools/build/feature/test-clang.cpp @@ -0,0 +1,21 @@ +#include "clang/Basic/VirtualFileSystem.h" +#include "clang/Driver/Driver.h" +#include "clang/Frontend/TextDiagnosticPrinter.h" +#include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/raw_ostream.h" + +using namespace clang; +using namespace clang::driver; + +int main() +{ + IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); + + DiagnosticsEngine Diags(DiagID, &*DiagOpts); + Driver TheDriver("test", "bpf-pc-linux", Diags); + + llvm::llvm_shutdown(); + return 0; +} -- cgit v1.2.3-73-gaa49b From a5ba0a1a5af312c4b4bfe78dc054d832103ec27d Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sun, 4 Dec 2016 21:42:52 +0100 Subject: tools build: Make the .cmd file more readable Putting extra line between dependencies and cmd_* definition to make it more readable. Before: $ cat .builtin-top.o.cmd ... /home/jolsa/kernel/linux-perf/tools/include/linux/stringify.h \ /home/jolsa/kernel/linux-perf/tools/include/linux/time64.h cmd_builtin-top.o := gcc -Wp,-MD,./.builtin-top.o.d -Wp,-MT,builtin-... ... After: $ cat .builtin-top.o.cmd ... /home/jolsa/kernel/linux-perf/tools/include/linux/stringify.h \ /home/jolsa/kernel/linux-perf/tools/include/linux/time64.h cmd_builtin-top.o := gcc -Wp,-MD,./.builtin-top.o.d -Wp,-MT,builtin-... ... Signed-off-by: Jiri Olsa Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1480884178-8072-2-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/Build.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/build') diff --git a/tools/build/Build.include b/tools/build/Build.include index 62dcf0c7aac2..475152c52871 100644 --- a/tools/build/Build.include +++ b/tools/build/Build.include @@ -65,7 +65,7 @@ dep-cmd = $(if $(wildcard $(fixdep)), printf '\# cannot find fixdep (%s)\n' $(fixdep) > $(dot-target).cmd; \ printf '\# using basic dep data\n\n' >> $(dot-target).cmd; \ cat $(depfile) >> $(dot-target).cmd; \ - printf '%s\n' 'cmd_$@ := $(make-cmd)' >> $(dot-target).cmd) + printf '\n%s\n' 'cmd_$@ := $(make-cmd)' >> $(dot-target).cmd) ### # if_changed_dep - execute command if any prerequisite is newer than -- cgit v1.2.3-73-gaa49b From 2fedf79b69cf05b7e8e82a42d749c621155dd812 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sun, 4 Dec 2016 21:42:53 +0100 Subject: tools build: Move tabs to spaces where suitable We've been hit several times by a Makefile bug where line indented by tab was falsely considered as target command. We prevent this by always using space indentation for everything except for the target commands. Signed-off-by: Jiri Olsa Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1480884178-8072-3-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/build/Build.include | 12 ++-- tools/build/Makefile.feature | 138 +++++++++++++++++++++---------------------- tools/build/feature/Makefile | 102 ++++++++++++++++---------------- 3 files changed, 126 insertions(+), 126 deletions(-) (limited to 'tools/build') diff --git a/tools/build/Build.include b/tools/build/Build.include index 475152c52871..418871d02ebf 100644 --- a/tools/build/Build.include +++ b/tools/build/Build.include @@ -72,15 +72,15 @@ dep-cmd = $(if $(wildcard $(fixdep)), # target, or command line has changed and update # dependencies in the cmd file if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)), \ - @set -e; \ - $(echo-cmd) $(cmd_$(1)) && $(dep-cmd)) + @set -e; \ + $(echo-cmd) $(cmd_$(1)) && $(dep-cmd)) # if_changed - execute command if any prerequisite is newer than # target, or command line has changed -if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ - @set -e; \ - $(echo-cmd) $(cmd_$(1)); \ - printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) +if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ + @set -e; \ + $(echo-cmd) $(cmd_$(1)); \ + printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) ### # C flags to be used in rule definitions, includes: diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index ae52e029dd22..e3fb5ecbdcb6 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -27,58 +27,58 @@ endef # the rule that uses them - an example for that is the 'bionic' # feature check. ] # -FEATURE_TESTS_BASIC := \ - backtrace \ - dwarf \ - dwarf_getlocations \ - fortify-source \ - sync-compare-and-swap \ - glibc \ - gtk2 \ - gtk2-infobar \ - libaudit \ - libbfd \ - libelf \ - libelf-getphdrnum \ - libelf-gelf_getnote \ - libelf-getshdrstrndx \ - libelf-mmap \ - libnuma \ - numa_num_possible_cpus \ - libperl \ - libpython \ - libpython-version \ - libslang \ - libcrypto \ - libunwind \ - libunwind-x86 \ - libunwind-x86_64 \ - libunwind-arm \ - libunwind-aarch64 \ - pthread-attr-setaffinity-np \ - stackprotector-all \ - timerfd \ - libdw-dwarf-unwind \ - zlib \ - lzma \ - get_cpuid \ - bpf \ - sdt +FEATURE_TESTS_BASIC := \ + backtrace \ + dwarf \ + dwarf_getlocations \ + fortify-source \ + sync-compare-and-swap \ + glibc \ + gtk2 \ + gtk2-infobar \ + libaudit \ + libbfd \ + libelf \ + libelf-getphdrnum \ + libelf-gelf_getnote \ + libelf-getshdrstrndx \ + libelf-mmap \ + libnuma \ + numa_num_possible_cpus \ + libperl \ + libpython \ + libpython-version \ + libslang \ + libcrypto \ + libunwind \ + libunwind-x86 \ + libunwind-x86_64 \ + libunwind-arm \ + libunwind-aarch64 \ + pthread-attr-setaffinity-np \ + stackprotector-all \ + timerfd \ + libdw-dwarf-unwind \ + zlib \ + lzma \ + get_cpuid \ + bpf \ + sdt # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list # of all feature tests -FEATURE_TESTS_EXTRA := \ - bionic \ - compile-32 \ - compile-x32 \ - cplus-demangle \ - hello \ - libbabeltrace \ - liberty \ - liberty-z \ - libunwind-debug-frame \ - libunwind-debug-frame-arm \ - libunwind-debug-frame-aarch64 +FEATURE_TESTS_EXTRA := \ + bionic \ + compile-32 \ + compile-x32 \ + cplus-demangle \ + hello \ + libbabeltrace \ + liberty \ + liberty-z \ + libunwind-debug-frame \ + libunwind-debug-frame-arm \ + libunwind-debug-frame-aarch64 FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC) @@ -86,26 +86,26 @@ ifeq ($(FEATURE_TESTS),all) FEATURE_TESTS := $(FEATURE_TESTS_BASIC) $(FEATURE_TESTS_EXTRA) endif -FEATURE_DISPLAY ?= \ - dwarf \ - dwarf_getlocations \ - glibc \ - gtk2 \ - libaudit \ - libbfd \ - libelf \ - libnuma \ - numa_num_possible_cpus \ - libperl \ - libpython \ - libslang \ - libcrypto \ - libunwind \ - libdw-dwarf-unwind \ - zlib \ - lzma \ - get_cpuid \ - bpf +FEATURE_DISPLAY ?= \ + dwarf \ + dwarf_getlocations \ + glibc \ + gtk2 \ + libaudit \ + libbfd \ + libelf \ + libnuma \ + numa_num_possible_cpus \ + libperl \ + libpython \ + libslang \ + libcrypto \ + libunwind \ + libdw-dwarf-unwind \ + zlib \ + lzma \ + get_cpuid \ + bpf # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features. # If in the future we need per-feature checks/flags for features not diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index 871d5536951d..303196c16019 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -1,54 +1,54 @@ -FILES= \ - test-all.bin \ - test-backtrace.bin \ - test-bionic.bin \ - test-dwarf.bin \ - test-dwarf_getlocations.bin \ - test-fortify-source.bin \ - test-sync-compare-and-swap.bin \ - test-glibc.bin \ - test-gtk2.bin \ - test-gtk2-infobar.bin \ - test-hello.bin \ - test-libaudit.bin \ - test-libbfd.bin \ - test-liberty.bin \ - test-liberty-z.bin \ - test-cplus-demangle.bin \ - test-libelf.bin \ - test-libelf-getphdrnum.bin \ - test-libelf-gelf_getnote.bin \ - test-libelf-getshdrstrndx.bin \ - test-libelf-mmap.bin \ - test-libnuma.bin \ - test-numa_num_possible_cpus.bin \ - test-libperl.bin \ - test-libpython.bin \ - test-libpython-version.bin \ - test-libslang.bin \ - test-libcrypto.bin \ - test-libunwind.bin \ - test-libunwind-debug-frame.bin \ - test-libunwind-x86.bin \ - test-libunwind-x86_64.bin \ - test-libunwind-arm.bin \ - test-libunwind-aarch64.bin \ - test-libunwind-debug-frame-arm.bin \ - test-libunwind-debug-frame-aarch64.bin \ - test-pthread-attr-setaffinity-np.bin \ - test-stackprotector-all.bin \ - test-timerfd.bin \ - test-libdw-dwarf-unwind.bin \ - test-libbabeltrace.bin \ - test-compile-32.bin \ - test-compile-x32.bin \ - test-zlib.bin \ - test-lzma.bin \ - test-bpf.bin \ - test-get_cpuid.bin \ - test-sdt.bin \ - test-cxx.bin \ - test-jvmti.bin +FILES= \ + test-all.bin \ + test-backtrace.bin \ + test-bionic.bin \ + test-dwarf.bin \ + test-dwarf_getlocations.bin \ + test-fortify-source.bin \ + test-sync-compare-and-swap.bin \ + test-glibc.bin \ + test-gtk2.bin \ + test-gtk2-infobar.bin \ + test-hello.bin \ + test-libaudit.bin \ + test-libbfd.bin \ + test-liberty.bin \ + test-liberty-z.bin \ + test-cplus-demangle.bin \ + test-libelf.bin \ + test-libelf-getphdrnum.bin \ + test-libelf-gelf_getnote.bin \ + test-libelf-getshdrstrndx.bin \ + test-libelf-mmap.bin \ + test-libnuma.bin \ + test-numa_num_possible_cpus.bin \ + test-libperl.bin \ + test-libpython.bin \ + test-libpython-version.bin \ + test-libslang.bin \ + test-libcrypto.bin \ + test-libunwind.bin \ + test-libunwind-debug-frame.bin \ + test-libunwind-x86.bin \ + test-libunwind-x86_64.bin \ + test-libunwind-arm.bin \ + test-libunwind-aarch64.bin \ + test-libunwind-debug-frame-arm.bin \ + test-libunwind-debug-frame-aarch64.bin \ + test-pthread-attr-setaffinity-np.bin \ + test-stackprotector-all.bin \ + test-timerfd.bin \ + test-libdw-dwarf-unwind.bin \ + test-libbabeltrace.bin \ + test-compile-32.bin \ + test-compile-x32.bin \ + test-zlib.bin \ + test-lzma.bin \ + test-bpf.bin \ + test-get_cpuid.bin \ + test-sdt.bin \ + test-cxx.bin \ + test-jvmti.bin FILES := $(addprefix $(OUTPUT),$(FILES)) -- cgit v1.2.3-73-gaa49b