Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752216AbbGMVqJ (ORCPT ); Mon, 13 Jul 2015 17:46:09 -0400 Received: from mail.kernel.org ([198.145.29.136]:45425 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751117AbbGMVqI (ORCPT ); Mon, 13 Jul 2015 17:46:08 -0400 Date: Mon, 13 Jul 2015 18:46:05 -0300 From: Arnaldo Carvalho de Melo To: Wang Nan Cc: ast@plumgrid.com, linux-kernel@vger.kernel.org, lizefan@huawei.com, hekuang@huawei.com, xiakaixu@huawei.com, pi3orama@163.com Subject: Re: [PATCH 14/39] perf tools: Auto detecting kernel build directory Message-ID: <20150713214605.GG2885@kernel.org> References: <1436445342-1402-1-git-send-email-wangnan0@huawei.com> <1436445342-1402-15-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1436445342-1402-15-git-send-email-wangnan0@huawei.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4563 Lines: 144 Em Thu, Jul 09, 2015 at 12:35:17PM +0000, Wang Nan escreveu: > This patch detects kernel build directory using a embedded shell > script 'kbuild_detector', which does this by checking existence of > include/generated/autoconf.h. > > clang working directory is changed to kbuild directory if it is found, > to help user use relative include path. Following patch will detect > kernel include directory, which contains relative include patch so this > workdir changing is needed. > > Users are allowed to set 'kbuild-dir = ""' manually to disable this > checking. What is the advantage of doing this using a hardcoded shell script, pipes, etc? Why not plain use some asprintf() for the pathnames to be tested, then check those, etc in plain C? I have applied everything up to 13/39, provided some coments to the others, will continue later today/tomorrow. Pushing what I have to perf/ebpf in my tree, Ah, please try, in your csets, to add the CC entries for the people you CC when posting the patches to lkml, so that, when I pull from your tree and then push to Ingo, people get notified, i.e. to follow the style we use in tip/ branches. Right now I am cherry-picking, but at some point I would like to do direct pulls. Thanks, - Arnaldo > Signed-off-by: Wang Nan > --- > tools/perf/util/llvm-utils.c | 56 +++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 55 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c > index dca16e7..2ca2bd6 100644 > --- a/tools/perf/util/llvm-utils.c > +++ b/tools/perf/util/llvm-utils.c > @@ -204,6 +204,51 @@ version_notice(void) > ); > } > > +static const char *kbuild_detector = > +"#!/usr/bin/env sh\n" > +"DEFAULT_KBUILD_DIR=/lib/modules/`uname -r`/build\n" > +"if test -z \"$KBUILD_DIR\"\n" > +"then\n" > +" KBUILD_DIR=$DEFAULT_KBUILD_DIR\n" > +"fi\n" > +"if test -f $KBUILD_DIR/include/generated/autoconf.h\n" > +"then\n" > +" echo -n $KBUILD_DIR\n" > +" exit 0\n" > +"fi\n" > +"exit -1\n"; > + > +static inline void > +get_kbuild_opts(char **kbuild_dir) > +{ > + int err; > + > + if (!kbuild_dir) > + return; > + > + *kbuild_dir = NULL; > + > + if (llvm_param.kbuild_dir && !llvm_param.kbuild_dir[0]) { > + pr_debug("[llvm.kbuild-dir] is set to \"\" deliberately.\n"); > + pr_debug("Skip kbuild options detection.\n"); > + return; > + } > + > + force_set_env("KBUILD_DIR", llvm_param.kbuild_dir); > + force_set_env("KBUILD_OPTS", llvm_param.kbuild_opts); > + err = read_from_pipe(kbuild_detector, > + ((void **)kbuild_dir), > + NULL); > + if (err) { > + pr_warning( > +"WARNING:\tunable to get correct kernel building directory.\n" > +"Hint:\tSet correct kbuild directory using 'kbuild-dir' option in [llvm]\n" > +" \tsection of ~/.perfconfig or set it to \"\" to suppress kbuild\n" > +" \tdetection.\n\n"); > + return; > + } > +} > + > int llvm__compile_bpf(const char *path, void **p_obj_buf, > size_t *p_obj_buf_sz) > { > @@ -211,6 +256,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, > char clang_path[PATH_MAX]; > const char *clang_opt = llvm_param.clang_opt; > const char *template = llvm_param.clang_bpf_cmd_template; > + char *kbuild_dir = NULL; > void *obj_buf = NULL; > size_t obj_buf_sz; > > @@ -228,10 +274,16 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, > return -ENOENT; > } > > + /* > + * This is an optional work. Even it fail we can continue our > + * work. Needn't to check error return. > + */ > + get_kbuild_opts(&kbuild_dir); > + > force_set_env("CLANG_EXEC", clang_path); > force_set_env("CLANG_OPTIONS", clang_opt); > force_set_env("KERNEL_INC_OPTIONS", NULL); > - force_set_env("WORKING_DIR", "."); > + force_set_env("WORKING_DIR", kbuild_dir ? : "."); > > /* > * Since we may reset clang's working dir, path of source file > @@ -252,6 +304,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, > goto errout; > } > > + free(kbuild_dir); > if (!p_obj_buf) > free(obj_buf); > else > @@ -261,6 +314,7 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf, > *p_obj_buf_sz = obj_buf_sz; > return 0; > errout: > + free(kbuild_dir); > free(obj_buf); > if (p_obj_buf) > *p_obj_buf = NULL; > -- > 1.8.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/