public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [Bug translator/23775] New: Pass 2 failed when generate a kernel module for stap script which uses kernel trace-point
@ 2018-10-14 11:13 houtao1 at huawei dot com
  2018-10-14 11:29 ` [Bug translator/23775] " houtao1 at huawei dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: houtao1 at huawei dot com @ 2018-10-14 11:13 UTC (permalink / raw)
  To: systemtap

https://sourceware.org/bugzilla/show_bug.cgi?id=23775

            Bug ID: 23775
           Summary: Pass 2 failed when generate a kernel module for stap
                    script which uses kernel trace-point
           Product: systemtap
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: translator
          Assignee: systemtap at sourceware dot org
          Reporter: houtao1 at huawei dot com
  Target Milestone: ---

Pass 2 failed when generate a kernel module for stap script which use kernel
trace-point. A self-built kernel is used, and it is built by using option
O=output.

Environment:
system tap: version 4.0
Host: Fedora 27

Path illustration:
~/code/linux: the source directory for vanilla kernel v4.19-rc7
~/code/linux/newest: the build directory for kernel

Reproduction:
$ stap -v 4 --vp 04 -r ~/code/linux/newest/ -e 'probe
kernel.trace("block:block_rq_issue") { printf("got blk rq\n"); }'

WARNING: kernel release/architecture mismatch with host forces last-pass 4.
Pass 1: parsed user script and 494 library scripts using
291332virt/125992res/6500shr/119844data kb, in 260usr/40sys/294real ms.
derive-probes (location #0): kernel.trace("block:block_rq_issue") of keyword at
<input>:1:1
checking pattern '' vs. module 'kernel' file
'/home/htbegin/code/linux/newest//vmlinux'
Attempting to extract kernel debuginfo build ID from
/home/htbegin/code/linux/newest//vmlinux.id
Ignoring duplicate kernel source tree (DW_AT_comp_dir) at
'/home/htbegin/code/linux/newest'
Checking tracepoint glob
/home/htbegin/code/linux/newest//include/trace/events/*.h
Checking tracepoint glob /home/htbegin/code/linux/newest//include/trace/*.h
Checking tracepoint glob /home/htbegin/code/linux/newest//include/ras/*_event.h
Checking tracepoint glob
/home/htbegin/code/linux/newest//arch/x86/entry/vsyscall/*trace.h
Checking tracepoint glob
/home/htbegin/code/linux/newest//arch/x86/kernel/*trace.h
Checking tracepoint glob
/home/htbegin/code/linux/newest//arch/*/include/asm/*trace*.h
Checking tracepoint glob
/home/htbegin/code/linux/newest//arch/*/include/asm/trace/*.h
Checking tracepoint glob /home/htbegin/code/linux/newest//arch/*/kvm/*trace.h
Checking tracepoint glob
/home/htbegin/code/linux/newest//fs/xfs/linux-*/xfs_tr*.h
Checking tracepoint glob /home/htbegin/code/linux/newest//fs/*/*trace*.h
Checking tracepoint glob /home/htbegin/code/linux/newest//net/*/*trace*.h
Checking tracepoint glob /home/htbegin/code/linux/newest//sound/core/*_trace.h
Checking tracepoint glob /home/htbegin/code/linux/newest//sound/hda/*trace*.h
Checking tracepoint glob
/home/htbegin/code/linux/newest//sound/pci/hda/*_trace.h
Checking tracepoint glob
/home/htbegin/code/linux/newest//drivers/base/regmap/*trace*.h
Checking tracepoint glob
/home/htbegin/code/linux/newest//drivers/gpu/drm/*_trace.h
Checking tracepoint glob
/home/htbegin/code/linux/newest//drivers/gpu/drm/*/*_trace.h
Checking tracepoint glob
/home/htbegin/code/linux/newest//drivers/net/wireless/*/*/*trace*.h
Checking tracepoint glob
/home/htbegin/code/linux/newest//drivers/usb/host/*trace*.h
Checking tracepoint glob /home/htbegin/code/linux/newest//virt/kvm/*/*trace*.h
Pass 2: getting a tracepoint query for 0 headers: 
checking pattern '' vs. module 'kernel' file
'/home/htbegin/code/linux/newest//vmlinux'
checking pattern '' vs. module 'nandsim' file
'/home/htbegin/code/linux/newest/drivers/mtd/nand/raw/nandsim.ko'
blacklist regexps:
blfn:
^(atomic_notifier_call_chain|default_do_nmi|__die|die_nmi|do_debug|do_general_protection|do_int3|do_IRQ|do_page_fault|do_sparc64_fault|do_trap|dummy_nmi_callback|flush_icache_range|ia64_bad_break|ia64_do_page_fault|ia64_fault|io_check_error|mem_parity_error|nmi_watchdog_tick|notifier_call_chain|oops_begin|oops_end|program_check_exception|single_step_exception|sync_regs|unhandled_fault|unknown_nmi_error|xen_[gs]et_debugreg|xen_irq_.*|xen_.*_fl_direct.*|check_events|xen_adjust_exception_frame|xen_iret.*|xen_sysret64.*|test_ti_thread_flag.*|inat_get_opcode_attribute|system_call_after_swapgs|HYPERVISOR_[gs]et_debugreg|HYPERVISOR_event_channel_op|hash_64|hash_ptr|native_set_pte|.*raw_.*_lock.*|.*raw_.*_unlock.*|.*raw_.*_trylock.*|.*read_lock.*|.*read_unlock.*|.*read_trylock.*|.*write_lock.*|.*write_unlock.*|.*write_trylock.*|.*write_seqlock.*|.*write_sequnlock.*|.*spin_lock.*|.*spin_unlock.*|.*spin_trylock.*|.*spin_is_locked.*|rwsem_.*lock.*|.*mutex_.*lock.*|atomic_.*|atomic64_.*|get_bh|put_bh|.*apic.*|.*APIC.*|.*softirq.*|.*IRQ.*|.*_intr.*|__delay|.*kernel_text.*|get_current|current_.*|.*exception_tables.*|.*setup_rt_frame.*|.*preempt_count.*|preempt_schedule|__switch_to|special_mapping_.*|.*_pte_.*)$
blfn_ret: ^(do_exit|sys_exit|sys_exit_group)$
blfile:
^(kernel/kprobes\.c|arch/.*/kernel/kprobes\.c|.*/include/asm/io\.h|.*/include/asm/io-defs\.h|.*/include/asm/io_64\.h|.*/include/asm/bitops\.h|drivers/ide/ide-iops\.c|arch/.*/kernel/paravirt\.c|.*/include/asm/paravirt\.h|fs/seq_file\.c)$
blsection:
^(\.init\.|\.exit\.|\.devinit\.|\.devexit\.|\.cpuinit\.|\.cpuexit\.|\.meminit\.|\.memexit\.)
pattern '*' matches module 'kernel'
semantic error: resolution failed in tracepoint builder
   thrown from: elaborate.cxx:1077
semantic error: while resolving probe point: identifier 'kernel' at <input>:1:7
   thrown from: elaborate.cxx:1065
        source: probe kernel.trace("block:block_rq_issue") { printf("got blk
rq\n"); }
                      ^

semantic error: no match
   thrown from: elaborate.cxx:1028
deleting module_cache
tracepoint_builder releasing dwflpp
Pass 2: analyzed script: 0 probes, 0 functions, 0 embeds, 0 globals using
296120virt/131860res/7420shr/124632data kb, in 30usr/30sys/68real ms.
WARNING: unused command line option $1/@1
Pass 2: analysis failed.  [man error::pass2]
Running rm -rf /tmp/stap1Q8lBd
Spawn waitpid result (0x0): 0
Removed temporary directory "/tmp/stap1Q8lBd"

-- 
You are receiving this mail because:
You are the assignee for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug translator/23775] Pass 2 failed when generate a kernel module for stap script which uses kernel trace-point
  2018-10-14 11:13 [Bug translator/23775] New: Pass 2 failed when generate a kernel module for stap script which uses kernel trace-point houtao1 at huawei dot com
@ 2018-10-14 11:29 ` houtao1 at huawei dot com
  2018-10-14 11:41 ` houtao1 at huawei dot com
  2018-10-16 15:25 ` fche at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: houtao1 at huawei dot com @ 2018-10-14 11:29 UTC (permalink / raw)
  To: systemtap

https://sourceware.org/bugzilla/show_bug.cgi?id=23775

--- Comment #1 from houtao1 at huawei dot com ---
>Ignoring duplicate kernel source tree (DW_AT_comp_dir) at '/home/htbegin/code/linux/newest'
>Checking tracepoint glob /home/htbegin/code/linux/newest//include/trace/events/*.h
>Checking tracepoint glob /home/htbegin/code/linux/newest//include/trace/*.h
>Checking tracepoint glob /home/htbegin/code/linux/newest//include/ras/*_event.h
It seems that elaborator can not find the correct kernel source directory, so
it can not find the definition of trace-point block_rq_issue neither.

The problem can be fixed by the patch proposed in
https://sourceware.org/ml/systemtap/2018-q3/msg00166.html:

When generating kernel module for a systemtap script that uses trace-point
probe, if the vanilla kernel is built by using O=build_path option and
r=build_path option is passed to stap, stap will not be able to find
kernel_source_tree and will fail on pass-2.

Linux kernel will create a symlink named source to the source tree
for out-of-source build since (399b835be30e "kbuild: add a symlink
to the source for separate objdirs"), so fix the problem by checking
whether or not the symlink exists and using it as the kernel_source_tree.

Also using a new helper dir_exists() instead of file_exists() to
ensure the existence of the directory of source tree.

Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 tapsets.cxx | 34 ++++++++++++++++++++++++++--------
 util.cxx    | 13 +++++++++++++
 util.h      |  1 +
 3 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/tapsets.cxx b/tapsets.cxx
index ca94be4ce..8617796d8 100644
--- a/tapsets.cxx
+++ b/tapsets.cxx
@@ -12391,16 +12391,34 @@ tracepoint_builder::init_dw(systemtap_session& s)
     }

   // find kernel_source_tree from a source link, when different from build
-  if (s.kernel_source_tree == "" && endswith(s.kernel_build_tree, "/build"))
+  if (s.kernel_source_tree == "")
     {
-      string source_tree = s.kernel_build_tree;
-      source_tree.replace(source_tree.length() - 5, 5, "source");
-      if (file_exists(source_tree) &&
-          resolve_path(source_tree) != resolve_path(s.kernel_build_tree))
+      vector<string> source_trees;
+
+      // vendor kernel (e.g. Fedora): the source link is in the same dir
+      // as the build tree
+      if (endswith(s.kernel_build_tree, "/build"))
+        {
+          string source_tree = s.kernel_build_tree;
+          source_tree.replace(source_tree.length() - 5, 5, "source");
+          source_trees.push_back(source_tree);
+        }
+
+      // vanilla kernel: the source link is in the build tree
+      source_trees.push_back(s.kernel_build_tree + "/source");
+
+      for (unsigned i = 0; i < source_trees.size(); i++)
         {
-          if (s.verbose > 2)
-            clog << _F("Located kernel source tree at '%s'",
source_tree.c_str()) << endl;
-          s.kernel_source_tree = source_tree;
+          string source_tree = source_trees[i];
+
+          if (dir_exists(source_tree) &&
+              resolve_path(source_tree) != resolve_path(s.kernel_build_tree))
+            {
+              if (s.verbose > 2)
+                clog << _F("Located kernel source tree at '%s'",
source_tree.c_str()) << endl;
+              s.kernel_source_tree = source_tree;
+              break;
+            }
         }
     }

diff --git a/util.cxx b/util.cxx
index 1b1127995..b4f1e9c25 100644
--- a/util.cxx
+++ b/util.cxx
@@ -103,6 +103,19 @@ file_exists (const string &path)
   return false;
 }

+// Check that a dir is present
+bool
+dir_exists(const string &path)
+{
+  struct stat info;
+
+  if (stat(path.c_str(), &info) == 0 &&
+      S_ISDIR(info.st_mode))
+    return true;
+
+  return false;
+}
+
 // Copy a file.  The copy is done via a temporary file and atomic
 // rename.
 bool
diff --git a/util.h b/util.h
index b4c4e40b7..4e30d4237 100644
--- a/util.h
+++ b/util.h
@@ -72,6 +72,7 @@ const char *get_home_directory(void);
 size_t get_file_size(const std::string &path);
 size_t get_file_size(int fd);
 bool file_exists (const std::string &path);
+bool dir_exists(const std::string &path);
 bool copy_file(const std::string& src, const std::string& dest,
                bool verbose=false);
 int create_dir(const char *dir, int mode = 0777);
-- 
2.16.2.dirty

-- 
You are receiving this mail because:
You are the assignee for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug translator/23775] Pass 2 failed when generate a kernel module for stap script which uses kernel trace-point
  2018-10-14 11:13 [Bug translator/23775] New: Pass 2 failed when generate a kernel module for stap script which uses kernel trace-point houtao1 at huawei dot com
  2018-10-14 11:29 ` [Bug translator/23775] " houtao1 at huawei dot com
@ 2018-10-14 11:41 ` houtao1 at huawei dot com
  2018-10-16 15:25 ` fche at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: houtao1 at huawei dot com @ 2018-10-14 11:41 UTC (permalink / raw)
  To: systemtap

https://sourceware.org/bugzilla/show_bug.cgi?id=23775

--- Comment #2 from houtao1 at huawei dot com ---
Created attachment 11325
  --> https://sourceware.org/bugzilla/attachment.cgi?id=11325&action=edit
Fix searching of kernel_source_tree for kernel built with O option

-- 
You are receiving this mail because:
You are the assignee for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug translator/23775] Pass 2 failed when generate a kernel module for stap script which uses kernel trace-point
  2018-10-14 11:13 [Bug translator/23775] New: Pass 2 failed when generate a kernel module for stap script which uses kernel trace-point houtao1 at huawei dot com
  2018-10-14 11:29 ` [Bug translator/23775] " houtao1 at huawei dot com
  2018-10-14 11:41 ` houtao1 at huawei dot com
@ 2018-10-16 15:25 ` fche at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: fche at redhat dot com @ 2018-10-16 15:25 UTC (permalink / raw)
  To: systemtap

https://sourceware.org/bugzilla/show_bug.cgi?id=23775

Frank Ch. Eigler <fche at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |fche at redhat dot com
         Resolution|---                         |FIXED

--- Comment #3 from Frank Ch. Eigler <fche at redhat dot com> ---
thanks, merged

-- 
You are receiving this mail because:
You are the assignee for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-16 15:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-14 11:13 [Bug translator/23775] New: Pass 2 failed when generate a kernel module for stap script which uses kernel trace-point houtao1 at huawei dot com
2018-10-14 11:29 ` [Bug translator/23775] " houtao1 at huawei dot com
2018-10-14 11:41 ` houtao1 at huawei dot com
2018-10-16 15:25 ` fche at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).