linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] perf-probe: Fix to die_entrypc() returns error correctly
       [not found] <20201126172849.GE53384@kernel.org>
@ 2020-11-27  5:48 ` Masami Hiramatsu
  2020-11-27  5:48 ` [PATCH 2/2] perf-probe: Change function definition check due to broken dwarf Masami Hiramatsu
  1 sibling, 0 replies; 3+ messages in thread
From: Masami Hiramatsu @ 2020-11-27  5:48 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Thomas Richter
  Cc: linux-perf-users, linux-kernel, Sumanth Korikkar, Masami Hiramatsu

Fix die_entrypc() to return error correctly if the DIE has no
DW_AT_ranges attribute. Since dwarf_ranges() will treat the case
as an empty ranges and return 0, we have to check it by ourselves.

Fixes: 91e2f539eeda ("perf probe: Fix to show function entry line as probe-able")
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/util/dwarf-aux.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index aa898014ad12..03c1a39c312a 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -373,6 +373,7 @@ bool die_is_func_def(Dwarf_Die *dw_die)
 int die_entrypc(Dwarf_Die *dw_die, Dwarf_Addr *addr)
 {
 	Dwarf_Addr base, end;
+	Dwarf_Attribute attr;
 
 	if (!addr)
 		return -EINVAL;
@@ -380,6 +381,13 @@ int die_entrypc(Dwarf_Die *dw_die, Dwarf_Addr *addr)
 	if (dwarf_entrypc(dw_die, addr) == 0)
 		return 0;
 
+	/*
+	 *  Since the dwarf_ranges() will return 0 if there is no
+	 * DW_AT_ranges attribute, we should check it first.
+	 */
+	if (!dwarf_attr(dw_die, DW_AT_ranges, &attr))
+		return -ENOENT;
+
 	return dwarf_ranges(dw_die, 0, &base, addr, &end) < 0 ? -ENOENT : 0;
 }
 


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

* [PATCH 2/2] perf-probe: Change function definition check due to broken dwarf
       [not found] <20201126172849.GE53384@kernel.org>
  2020-11-27  5:48 ` [PATCH 1/2] perf-probe: Fix to die_entrypc() returns error correctly Masami Hiramatsu
@ 2020-11-27  5:48 ` Masami Hiramatsu
  2020-11-27 17:36   ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 3+ messages in thread
From: Masami Hiramatsu @ 2020-11-27  5:48 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Thomas Richter
  Cc: linux-perf-users, linux-kernel, Sumanth Korikkar, Masami Hiramatsu

Since some gcc generates a broken DWARF which lacks DW_AT_declaration
attribute from the subprogram DIE of function prototype.
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97060)

So, in addition to the DW_AT_declaration check, we also check the
subprogram DIE has DW_AT_inline or actual entry pc.

Reported-by: Thomas Richter <tmricht@linux.ibm.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/perf/util/dwarf-aux.c    |   20 ++++++++++++++++++--
 tools/perf/util/probe-finder.c |    3 +--
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index 03c1a39c312a..7b2d471a6419 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -356,9 +356,25 @@ bool die_is_signed_type(Dwarf_Die *tp_die)
 bool die_is_func_def(Dwarf_Die *dw_die)
 {
 	Dwarf_Attribute attr;
+	Dwarf_Addr addr = 0;
+
+	if (dwarf_tag(dw_die) != DW_TAG_subprogram)
+		return false;
+
+	if (dwarf_attr(dw_die, DW_AT_declaration, &attr))
+		return false;
 
-	return (dwarf_tag(dw_die) == DW_TAG_subprogram &&
-		dwarf_attr(dw_die, DW_AT_declaration, &attr) == NULL);
+	/*
+	 * DW_AT_declaration can be lost from function declaration
+	 * by gcc's bug #97060.
+	 * So we need to check this subprogram DIE has DW_AT_inline
+	 * or an entry address.
+	 */
+	if (!dwarf_attr(dw_die, DW_AT_inline, &attr) &&
+	    die_entrypc(dw_die, &addr) < 0)
+		return false;
+
+	return true;
 }
 
 /**
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 2c4061035f77..76dd349aa48d 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -1885,8 +1885,7 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
 	if (lr->file && strtailcmp(lr->file, dwarf_decl_file(sp_die)))
 		return DWARF_CB_OK;
 
-	if (die_is_func_def(sp_die) &&
-	    die_match_name(sp_die, lr->function)) {
+	if (die_match_name(sp_die, lr->function) && die_is_func_def(sp_die)) {
 		lf->fname = dwarf_decl_file(sp_die);
 		dwarf_decl_line(sp_die, &lr->offset);
 		pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset);


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

* Re: [PATCH 2/2] perf-probe: Change function definition check due to broken dwarf
  2020-11-27  5:48 ` [PATCH 2/2] perf-probe: Change function definition check due to broken dwarf Masami Hiramatsu
@ 2020-11-27 17:36   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-11-27 17:36 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Thomas Richter, linux-perf-users, linux-kernel, Sumanth Korikkar

Em Fri, Nov 27, 2020 at 02:48:55PM +0900, Masami Hiramatsu escreveu:
> Since some gcc generates a broken DWARF which lacks DW_AT_declaration
> attribute from the subprogram DIE of function prototype.
> (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97060)
> 
> So, in addition to the DW_AT_declaration check, we also check the
> subprogram DIE has DW_AT_inline or actual entry pc.

Thanks, applied and tested both patches on a fedora 33 system where
previously those tests were failing:

    Committer testing:

      # cat /etc/fedora-release
      Fedora release 33 (Thirty Three)
      #

    Before:

      # perf test vfs_getname
      78: Use vfs_getname probe to get syscall args filenames             : FAILED!
      79: Check open filename arg using perf trace + vfs_getname          : FAILED!
      81: Add vfs_getname probe to get syscall args filenames             : FAILED!
      #

    After:

      # perf test vfs_getname
      78: Use vfs_getname probe to get syscall args filenames             : Ok
      79: Check open filename arg using perf trace + vfs_getname          : Ok
      81: Add vfs_getname probe to get syscall args filenames             : Ok
      #


- Arnaldo
 
> Reported-by: Thomas Richter <tmricht@linux.ibm.com>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  tools/perf/util/dwarf-aux.c    |   20 ++++++++++++++++++--
>  tools/perf/util/probe-finder.c |    3 +--
>  2 files changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
> index 03c1a39c312a..7b2d471a6419 100644
> --- a/tools/perf/util/dwarf-aux.c
> +++ b/tools/perf/util/dwarf-aux.c
> @@ -356,9 +356,25 @@ bool die_is_signed_type(Dwarf_Die *tp_die)
>  bool die_is_func_def(Dwarf_Die *dw_die)
>  {
>  	Dwarf_Attribute attr;
> +	Dwarf_Addr addr = 0;
> +
> +	if (dwarf_tag(dw_die) != DW_TAG_subprogram)
> +		return false;
> +
> +	if (dwarf_attr(dw_die, DW_AT_declaration, &attr))
> +		return false;
>  
> -	return (dwarf_tag(dw_die) == DW_TAG_subprogram &&
> -		dwarf_attr(dw_die, DW_AT_declaration, &attr) == NULL);
> +	/*
> +	 * DW_AT_declaration can be lost from function declaration
> +	 * by gcc's bug #97060.
> +	 * So we need to check this subprogram DIE has DW_AT_inline
> +	 * or an entry address.
> +	 */
> +	if (!dwarf_attr(dw_die, DW_AT_inline, &attr) &&
> +	    die_entrypc(dw_die, &addr) < 0)
> +		return false;
> +
> +	return true;
>  }
>  
>  /**
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index 2c4061035f77..76dd349aa48d 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -1885,8 +1885,7 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
>  	if (lr->file && strtailcmp(lr->file, dwarf_decl_file(sp_die)))
>  		return DWARF_CB_OK;
>  
> -	if (die_is_func_def(sp_die) &&
> -	    die_match_name(sp_die, lr->function)) {
> +	if (die_match_name(sp_die, lr->function) && die_is_func_def(sp_die)) {
>  		lf->fname = dwarf_decl_file(sp_die);
>  		dwarf_decl_line(sp_die, &lr->offset);
>  		pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset);
> 

-- 

- Arnaldo

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

end of thread, other threads:[~2020-11-27 17:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20201126172849.GE53384@kernel.org>
2020-11-27  5:48 ` [PATCH 1/2] perf-probe: Fix to die_entrypc() returns error correctly Masami Hiramatsu
2020-11-27  5:48 ` [PATCH 2/2] perf-probe: Change function definition check due to broken dwarf Masami Hiramatsu
2020-11-27 17:36   ` Arnaldo Carvalho de Melo

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 NNTP newsgroup(s).