From: Frank Ch. Eigler Date: Mon, 24 Aug 2009 14:34:45 +0000 (-0400) Subject: PR4186: cross-architecture probe building X-Git-Tag: release-1.0~119 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=1392896dcda33324d43392f8e99fed240cf5fb9b;p=systemtap.git PR4186: cross-architecture probe building * main.cxx (main): Add 'a:' and 'B:' options. * session.h (kbuildflags): New place to store -B args. * testsuite/systemtap.base/cmd_parse.exp: Test them lightly. * buildrun.cxx (run_make_cmd): Use "--no-print-directory" rather than ">/dev/null" in kbuild invocations. Pass '-a' and '-B' flags along. * hash.cxx (find_script_hash): Add them. * NEWS, stap.1.in: Mention this. --- diff --git a/NEWS b/NEWS index f07acd9f6..a78439794 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,14 @@ * What's new +- It is now possible to cross-compile systemtap scripts for foreign + architectures, using the new '-a ARCH' and '-B OPT=VALUE' flags. + For example, put arm-linux-gcc etc. into your $PATH, and point + systemtap at the target kernel build tree with: + stap -a arm -B CROSS_COMPILE=arm-linux- -r /build/tree [...] + The -B option is passed to kbuild make. -r identifies the already + configured/built kernel tree and -a its architecture (kbuild ARCH=...). + Systemtap will infer -p4. + - It is now possible to define multiple probe aliases with the same name. A probe will expand to all matching aliases. probe foo = bar { } diff --git a/buildrun.cxx b/buildrun.cxx index 1820002df..69cc5a662 100644 --- a/buildrun.cxx +++ b/buildrun.cxx @@ -59,9 +59,9 @@ run_make_cmd(systemtap_session& s, string& make_cmd) if (s.verbose > 2) make_cmd += " V=1"; else if (s.verbose > 1) - make_cmd += " >/dev/null"; + make_cmd += " --no-print-directory"; else - make_cmd += " -s >/dev/null"; + make_cmd += " -s --no-print-directory"; return stap_system (s.verbose, make_cmd); } @@ -222,8 +222,17 @@ compile_pass (systemtap_session& s) // Run make string make_cmd = string("make") - + string (" -C \"") + module_dir + string("\""); - make_cmd += string(" M=\"") + s.tmpdir + string("\" modules"); + + string (" -C \"") + module_dir + string("\""); // XXX: lex_cast_qstring? + make_cmd += string(" M=\"") + s.tmpdir + string("\""); + + // Add architecture + make_cmd += string(" ARCH=") + lex_cast_qstring(s.architecture); + + // Add any custom kbuild flags + for (unsigned k=0; k::iterator it = s.unwindsym_modules.begin(); it != s.unwindsym_modules.end(); diff --git a/main.cxx b/main.cxx index 15447efcf..d62c2fac6 100644 --- a/main.cxx +++ b/main.cxx @@ -106,11 +106,13 @@ usage (systemtap_session& s, int exitcode) clog << " " << s.include_path[i] << endl; clog << " -D NM=VAL emit macro definition into generated C code" << endl + << " -B NM=VAL pass option to kbuild make" << endl << " -R DIR look in DIR for runtime, instead of" << endl << " " << s.runtime_path << endl << " -r DIR cross-compile to kernel with given build tree; or else" << endl << " -r RELEASE cross-compile to kernel /lib/modules/RELEASE/build, instead of" << endl << " " << s.kernel_build_tree << endl + << " -a ARCH cross-compile to given architecture, instead of " << s.architecture << endl << " -m MODULE set probe module name, instead of " << endl << " " << s.module_name << endl << " -o FILE send script output to file, instead of stdout. This supports" << endl @@ -590,8 +592,8 @@ main (int argc, char * const argv []) { "unprivileged", 0, &long_opt, LONG_OPT_UNPRIVILEGED }, { NULL, 0, NULL, 0 } }; - int grc = getopt_long (argc, argv, "hVMvtp:I:e:o:R:r:m:kgPc:x:D:bs:uqwl:d:L:FS:", - long_options, NULL); + int grc = getopt_long (argc, argv, "hVMvtp:I:e:o:R:r:a:m:kgPc:x:D:bs:uqwl:d:L:FS:B:", + long_options, NULL); if (grc < 0) break; switch (grc) @@ -711,6 +713,10 @@ main (int argc, char * const argv []) setup_kernel_release(s, optarg); break; + case 'a': + s.architecture = string(optarg); + break; + case 'k': s.keep_tmpdir = true; s.use_cache = false; /* User wants to keep a usable build tree. */ @@ -792,6 +798,10 @@ main (int argc, char * const argv []) s.load_only = true; break; + case 'B': + s.kbuildflags.push_back (string (optarg)); + break; + case 0: switch (long_opt) { diff --git a/session.h b/session.h index ea9144251..24e6ae808 100644 --- a/session.h +++ b/session.h @@ -83,6 +83,7 @@ struct systemtap_session std::vector include_path; std::vector macros; std::vector args; + std::vector kbuildflags; std::string kernel_release; std::string kernel_base_release; std::string kernel_build_tree; diff --git a/stap.1.in b/stap.1.in index a45c90a67..fc72cf325 100644 --- a/stap.1.in +++ b/stap.1.in @@ -153,6 +153,10 @@ description of pass 2 for details. Add the given C preprocessor directive to the module Makefile. These can be used to override limit parameters described below. .TP +.BI \-B " NAME=VALUE" +Add the given make directive to the kernel module build's make invocation. +These can be used to add or override kconfig options. +.TP .BI \-R " DIR" Look for the systemtap runtime sources in the given directory. .TP diff --git a/testsuite/systemtap.base/cmd_parse.exp b/testsuite/systemtap.base/cmd_parse.exp index 7f5f70d9f..8824e6c4b 100644 --- a/testsuite/systemtap.base/cmd_parse.exp +++ b/testsuite/systemtap.base/cmd_parse.exp @@ -1,5 +1,5 @@ if {![installtest_p]} { - for {set i 0} { $i < 8} {incr i} { + for {set i 0} { $i < 16} {incr i} { untested cmd_parse$i } return @@ -129,3 +129,29 @@ expect { eof { fail "cmd_parse14: eof" } } wait;catch {close} + +set uname [exec uname -r] +spawn sh -c "stap -m do_not_cache_me -B kernelrelease -p4 -e 'probe begin {exit()}'" +# the \r below is meant to match the "kernelrelease" output, as distinct from +# any possible auxiliary make verbosity. +expect { + -re "$uname\r" { pass "cmd_parse15" } + timeout { fail "cmd_parse15: timeout" } + eof { fail "cmd_parse15: eof" } +} +wait;catch {close} + +set uname [exec uname -m] +spawn sh -c "stap -m do_not_cache_me -a $uname -p4 -e 'probe begin {exit()}'" +# the \r below is meant to match the "kernelrelease" output, as distinct from +# any possible auxiliary make verbosity. +expect { + -re "do_not_cache_me.ko\r" { pass "cmd_parse16" } + timeout { fail "cmd_parse16: timeout" } + eof { fail "cmd_parse16: eof" } +} +wait;catch {close} + + +# NB: when adding extra tests here, increment the ![installtest_p] +# loop count too at the top.