regressions.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v2 3/3] tools/perf: Fix to get declared file name from clang DWARF5
       [not found]   ` <5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net>
@ 2023-06-15 14:02     ` Georg Müller
  2023-06-15 20:01     ` [PATCH] perf probe: read DWARF files from the correct CU Georg Müller
  2023-06-28  8:23     ` [PATCH v2 0/2] perf probe: fix regression introduced by switch to die_get_decl_file Georg Müller
  2 siblings, 0 replies; 12+ messages in thread
From: Georg Müller @ 2023-06-15 14:02 UTC (permalink / raw)
  To: Masami Hiramatsu (Google), Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, linux-perf-users, linux-kernel,
	Steven Rostedt, regressions

Hi all,

I have found a solution for this bug and will post a patch later today.

Am 09.06.23 um 14:21 schrieb Georg Müller:
>
> Am 01.11.22 um 14:48 schrieb Masami Hiramatsu (Google):
>> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
>>
>> Fix to get the declared file name even if it uses file index 0
>> in DWARF5, using custom die_get_decl_file() function.
>>
>
> this patch breaks perf probe on fedora 38.
>

The problem is that die_get_file_name() uses the wrong cu_die.

I was pointed to the solution by reading elfutils commit e1db5cdc9:

     dwarf_decl_file uses dwarf_attr_integrate to get the DW_AT_decl_file
     attribute. This means the attribute might come from a different DIE
     in a different CU. If so, we need to use the CU associated with the
     attribute, not the original DIE, to resolve the file name.

The correct cu_die has to be obtained via

     dwarf_attr_integrate(dw_die, DW_AT_decl_file, &attr_mem)

and then cu_die from the cu from attr_mem (dwarf_cu_die(attr_mem.cu, &cu_die, ...)
to obtain it) has to be used.

Best regards,
Georg

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

* [PATCH] perf probe: read DWARF files from the correct CU
       [not found]   ` <5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net>
  2023-06-15 14:02     ` [PATCH v2 3/3] tools/perf: Fix to get declared file name from clang DWARF5 Georg Müller
@ 2023-06-15 20:01     ` Georg Müller
  2023-06-22 22:04       ` Georg Müller
  2023-07-11 12:57       ` Arnaldo Carvalho de Melo
  2023-06-28  8:23     ` [PATCH v2 0/2] perf probe: fix regression introduced by switch to die_get_decl_file Georg Müller
  2 siblings, 2 replies; 12+ messages in thread
From: Georg Müller @ 2023-06-15 20:01 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Masami Hiramatsu (Google)
  Cc: Georg Müller, regressions, Arnaldo Carvalho de Melo,
	linux-perf-users, linux-kernel

After switching from dwarf_decl_file() to die_get_decl_file(), it is not
possible to add probes for certain functions of certain binaries:

 $ perf probe -x /usr/lib/systemd/systemd-logind match_unit_removed
 A function DIE doesn't have decl_line. Maybe broken DWARF?
 A function DIE doesn't have decl_line. Maybe broken DWARF?
 Probe point 'match_unit_removed' not found.
    Error: Failed to add events.

The problem is that die_get_decl_file() uses the wrong CU to search for
the file. elfutils commit e1db5cdc9f has some good explanation for this:

    dwarf_decl_file uses dwarf_attr_integrate to get the DW_AT_decl_file
    attribute. This means the attribute might come from a different DIE
    in a different CU. If so, we need to use the CU associated with the
    attribute, not the original DIE, to resolve the file name.

This patch uses the same source of information as elfutils: use attribute
DW_AT_decl_file and use this CU to search for the file.

Fixes: dc9a5d2ccd5c ("perf probe: Fix to get declared file name from clang DWARF5")
Signed-off-by: Georg Müller <georgmueller@gmx.net>
Link: https://lore.kernel.org/r/5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net/
---
 tools/perf/util/dwarf-aux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index b07414409771..137b3ed9897b 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -478,8 +478,10 @@ static const char *die_get_file_name(Dwarf_Die *dw_die, int idx)
 {
 	Dwarf_Die cu_die;
 	Dwarf_Files *files;
+	Dwarf_Attribute attr_mem;

-	if (idx < 0 || !dwarf_diecu(dw_die, &cu_die, NULL, NULL) ||
+	if (idx < 0 || !dwarf_attr_integrate(dw_die, DW_AT_decl_file, &attr_mem) ||
+	    !dwarf_cu_die(attr_mem.cu, &cu_die, NULL, NULL, NULL, NULL, NULL, NULL) ||
 	    dwarf_getsrcfiles(&cu_die, &files, NULL) != 0)
 		return NULL;

--
2.41.0


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

* Re: [PATCH] perf probe: read DWARF files from the correct CU
  2023-06-15 20:01     ` [PATCH] perf probe: read DWARF files from the correct CU Georg Müller
@ 2023-06-22 22:04       ` Georg Müller
  2023-07-11 12:57       ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 12+ messages in thread
From: Georg Müller @ 2023-06-22 22:04 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Masami Hiramatsu (Google)
  Cc: regressions, Arnaldo Carvalho de Melo, linux-perf-users, linux-kernel


Hi,

Am 15.06.23 um 22:01 schrieb Georg Müller:
> After switching from dwarf_decl_file() to die_get_decl_file(), it is not
> possible to add probes for certain functions of certain binaries:
>
>   $ perf probe -x /usr/lib/systemd/systemd-logind match_unit_removed
>   A function DIE doesn't have decl_line. Maybe broken DWARF?
>   A function DIE doesn't have decl_line. Maybe broken DWARF?
>   Probe point 'match_unit_removed' not found.
>      Error: Failed to add events.
>
> The problem is that die_get_decl_file() uses the wrong CU to search for
> the file. elfutils commit e1db5cdc9f has some good explanation for this:
>
>      dwarf_decl_file uses dwarf_attr_integrate to get the DW_AT_decl_file
>      attribute. This means the attribute might come from a different DIE
>      in a different CU. If so, we need to use the CU associated with the
>      attribute, not the original DIE, to resolve the file name.
>
> This patch uses the same source of information as elfutils: use attribute
> DW_AT_decl_file and use this CU to search for the file.
>
> Fixes: dc9a5d2ccd5c ("perf probe: Fix to get declared file name from clang DWARF5")
> Signed-off-by: Georg Müller <georgmueller@gmx.net>
> Link: https://lore.kernel.org/r/5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net/
> ---
>   tools/perf/util/dwarf-aux.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
> index b07414409771..137b3ed9897b 100644
> --- a/tools/perf/util/dwarf-aux.c
> +++ b/tools/perf/util/dwarf-aux.c
> @@ -478,8 +478,10 @@ static const char *die_get_file_name(Dwarf_Die *dw_die, int idx)
>   {
>   	Dwarf_Die cu_die;
>   	Dwarf_Files *files;
> +	Dwarf_Attribute attr_mem;
>
> -	if (idx < 0 || !dwarf_diecu(dw_die, &cu_die, NULL, NULL) ||
> +	if (idx < 0 || !dwarf_attr_integrate(dw_die, DW_AT_decl_file, &attr_mem) ||
> +	    !dwarf_cu_die(attr_mem.cu, &cu_die, NULL, NULL, NULL, NULL, NULL, NULL) ||
>   	    dwarf_getsrcfiles(&cu_die, &files, NULL) != 0)
>   		return NULL;
>
> --
> 2.41.0
>


Just a question regarding the patch:
Should I also add a testcase to show the issue or is this enough? It can be
reproduced quite simple with two .c files and one .h file, the same test as the
one added in elfutils with commit e1db5cdc9f, compiled with the same three steps
as in the comment of the shell script, but without "-flto":

https://sourceware.org/git/?p=elfutils.git;a=commitdiff;h=e1db5cdc9f230f8de4df1a0f38dca69b283ee57a

Best regards,
Georg

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

* [PATCH v2 0/2] perf probe: fix regression introduced by switch to die_get_decl_file
       [not found]   ` <5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net>
  2023-06-15 14:02     ` [PATCH v2 3/3] tools/perf: Fix to get declared file name from clang DWARF5 Georg Müller
  2023-06-15 20:01     ` [PATCH] perf probe: read DWARF files from the correct CU Georg Müller
@ 2023-06-28  8:23     ` Georg Müller
  2023-06-28  8:23       ` [PATCH v2 1/2] perf probe: add test for " Georg Müller
                         ` (2 more replies)
  2 siblings, 3 replies; 12+ messages in thread
From: Georg Müller @ 2023-06-28  8:23 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Masami Hiramatsu (Google)
  Cc: Georg Müller, regressions, Arnaldo Carvalho de Melo,
	linux-perf-users, linux-kernel

When switching from dwarf_decl_file() to die_get_decl_file(), a regression
was introduced when having a binary where the DWARF info is split to
multiple CUs. It is not possible to add probes to certain functions.

These patches introduce a testcase which shows the current regression
and a fix for the issue

Signed-off-by: Georg Müller <georgmueller@gmx.net>
Link: https://lore.kernel.org/r/5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net/

---
Changes in v2:
 - Add testcase

Georg Müller (2):
  perf probe: add test for regression introduced by switch to
    die_get_decl_file
  perf probe: read DWARF files from the correct CU

 .../shell/test_uprobe_from_different_cu.sh    | 77 +++++++++++++++++++
 tools/perf/util/dwarf-aux.c                   |  4 +-
 2 files changed, 80 insertions(+), 1 deletion(-)
 create mode 100755 tools/perf/tests/shell/test_uprobe_from_different_cu.sh

--
2.41.0


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

* [PATCH v2 1/2] perf probe: add test for regression introduced by switch to die_get_decl_file
  2023-06-28  8:23     ` [PATCH v2 0/2] perf probe: fix regression introduced by switch to die_get_decl_file Georg Müller
@ 2023-06-28  8:23       ` Georg Müller
  2023-07-27 17:45         ` Ian Rogers
  2023-06-28  8:23       ` [PATCH v2 2/2] perf probe: read DWARF files from the correct CU Georg Müller
  2023-06-28  8:41       ` [PATCH v2 0/2] perf probe: fix regression introduced by switch to die_get_decl_file Linux regression tracking (Thorsten Leemhuis)
  2 siblings, 1 reply; 12+ messages in thread
From: Georg Müller @ 2023-06-28  8:23 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Masami Hiramatsu (Google)
  Cc: Georg Müller, regressions, Arnaldo Carvalho de Melo,
	linux-perf-users, linux-kernel

This patch adds a test to validate that perf probe works for binaries
where DWARF info is split into multiple CUs

Signed-off-by: Georg Müller <georgmueller@gmx.net>
Link: https://lore.kernel.org/r/5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net/
---
 .../shell/test_uprobe_from_different_cu.sh    | 77 +++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100755 tools/perf/tests/shell/test_uprobe_from_different_cu.sh

diff --git a/tools/perf/tests/shell/test_uprobe_from_different_cu.sh b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh
new file mode 100755
index 000000000000..00d2e0e2e0c2
--- /dev/null
+++ b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+# test perf probe of function from different CU
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+temp_dir=$(mktemp -d /tmp/perf-uprobe-different-cu-sh.XXXXXXXXXX)
+
+cleanup()
+{
+	trap - EXIT TERM INT
+	if [[ "${temp_dir}" =~ ^/tmp/perf-uprobe-different-cu-sh.*$ ]]; then
+		echo "--- Cleaning up ---"
+		perf probe -x ${temp_dir}/testfile -d foo
+		rm -f "${temp_dir}/"*
+		rmdir "${temp_dir}"
+	fi
+}
+
+trap_cleanup()
+{
+        cleanup
+        exit 1
+}
+
+trap trap_cleanup EXIT TERM INT
+
+cat > ${temp_dir}/testfile-foo.h << EOF
+struct t
+{
+  int *p;
+  int c;
+};
+
+extern int foo (int i, struct t *t);
+EOF
+
+cat > ${temp_dir}/testfile-foo.c << EOF
+#include "testfile-foo.h"
+
+int
+foo (int i, struct t *t)
+{
+  int j, res = 0;
+  for (j = 0; j < i && j < t->c; j++)
+    res += t->p[j];
+
+  return res;
+}
+EOF
+
+cat > ${temp_dir}/testfile-main.c << EOF
+#include "testfile-foo.h"
+
+static struct t g;
+
+int
+main (int argc, char **argv)
+{
+  int i;
+  int j[argc];
+  g.c = argc;
+  g.p = j;
+  for (i = 0; i < argc; i++)
+    j[i] = (int) argv[i][0];
+  return foo (3, &g);
+}
+EOF
+
+gcc -g -Og -flto -c ${temp_dir}/testfile-foo.c -o ${temp_dir}/testfile-foo.o
+gcc -g -Og -c ${temp_dir}/testfile-main.c -o ${temp_dir}/testfile-main.o
+gcc -g -Og -o ${temp_dir}/testfile ${temp_dir}/testfile-foo.o ${temp_dir}/testfile-main.o
+
+perf probe -x ${temp_dir}/testfile --funcs foo
+perf probe -x ${temp_dir}/testfile foo
+
+cleanup
--
2.41.0


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

* [PATCH v2 2/2] perf probe: read DWARF files from the correct CU
  2023-06-28  8:23     ` [PATCH v2 0/2] perf probe: fix regression introduced by switch to die_get_decl_file Georg Müller
  2023-06-28  8:23       ` [PATCH v2 1/2] perf probe: add test for " Georg Müller
@ 2023-06-28  8:23       ` Georg Müller
  2023-06-28  8:41       ` [PATCH v2 0/2] perf probe: fix regression introduced by switch to die_get_decl_file Linux regression tracking (Thorsten Leemhuis)
  2 siblings, 0 replies; 12+ messages in thread
From: Georg Müller @ 2023-06-28  8:23 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, Masami Hiramatsu (Google)
  Cc: Georg Müller, regressions, Arnaldo Carvalho de Melo,
	linux-perf-users, linux-kernel

After switching from dwarf_decl_file() to die_get_decl_file(), it is not
possible to add probes for certain functions:

 $ perf probe -x /usr/lib/systemd/systemd-logind match_unit_removed
 A function DIE doesn't have decl_line. Maybe broken DWARF?
 A function DIE doesn't have decl_line. Maybe broken DWARF?
 Probe point 'match_unit_removed' not found.
    Error: Failed to add events.

The problem is that die_get_decl_file() uses the wrong CU to search for
the file. elfutils commit e1db5cdc9f has some good explanation for this:

    dwarf_decl_file uses dwarf_attr_integrate to get the DW_AT_decl_file
    attribute. This means the attribute might come from a different DIE
    in a different CU. If so, we need to use the CU associated with the
    attribute, not the original DIE, to resolve the file name.

This patch uses the same source of information as elfutils: use attribute
DW_AT_decl_file and use this CU to search for the file.

Fixes: dc9a5d2ccd5c ("perf probe: Fix to get declared file name from clang DWARF5")
Signed-off-by: Georg Müller <georgmueller@gmx.net>
Link: https://lore.kernel.org/r/5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net/
---
 tools/perf/util/dwarf-aux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index b07414409771..137b3ed9897b 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -478,8 +478,10 @@ static const char *die_get_file_name(Dwarf_Die *dw_die, int idx)
 {
 	Dwarf_Die cu_die;
 	Dwarf_Files *files;
+	Dwarf_Attribute attr_mem;

-	if (idx < 0 || !dwarf_diecu(dw_die, &cu_die, NULL, NULL) ||
+	if (idx < 0 || !dwarf_attr_integrate(dw_die, DW_AT_decl_file, &attr_mem) ||
+	    !dwarf_cu_die(attr_mem.cu, &cu_die, NULL, NULL, NULL, NULL, NULL, NULL) ||
 	    dwarf_getsrcfiles(&cu_die, &files, NULL) != 0)
 		return NULL;

--
2.41.0


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

* Re: [PATCH v2 0/2] perf probe: fix regression introduced by switch to die_get_decl_file
  2023-06-28  8:23     ` [PATCH v2 0/2] perf probe: fix regression introduced by switch to die_get_decl_file Georg Müller
  2023-06-28  8:23       ` [PATCH v2 1/2] perf probe: add test for " Georg Müller
  2023-06-28  8:23       ` [PATCH v2 2/2] perf probe: read DWARF files from the correct CU Georg Müller
@ 2023-06-28  8:41       ` Linux regression tracking (Thorsten Leemhuis)
  2 siblings, 0 replies; 12+ messages in thread
From: Linux regression tracking (Thorsten Leemhuis) @ 2023-06-28  8:41 UTC (permalink / raw)
  To: Georg Müller, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Ian Rogers, Adrian Hunter,
	Masami Hiramatsu (Google)
  Cc: regressions, Arnaldo Carvalho de Melo, linux-perf-users, linux-kernel

On 28.06.23 10:23, Georg Müller wrote:
> When switching from dwarf_decl_file() to die_get_decl_file(), a regression
> was introduced when having a binary where the DWARF info is split to
> multiple CUs. It is not possible to add probes to certain functions.
> 
> These patches introduce a testcase which shows the current regression
> and a fix for the issue
> 
> Signed-off-by: Georg Müller <georgmueller@gmx.net>
> Link: https://lore.kernel.org/r/5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net/

FWIW, you in both commits might want to add a

 Cc: stable@vger.kernel.org

to ensure the fix is backported to appropriate releases (e.g. 6.4 and
6.3, if the latter doesn't go EOL earlier).

Ciao, Thorsten

P.S.: Some (I guess: most) maintainers prefer if patch series are
startet as new threads

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

* Re: [PATCH] perf probe: read DWARF files from the correct CU
  2023-06-15 20:01     ` [PATCH] perf probe: read DWARF files from the correct CU Georg Müller
  2023-06-22 22:04       ` Georg Müller
@ 2023-07-11 12:57       ` Arnaldo Carvalho de Melo
  2023-07-11 13:20         ` Masami Hiramatsu
  1 sibling, 1 reply; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-07-11 12:57 UTC (permalink / raw)
  To: Georg Müller
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Ian Rogers, Adrian Hunter,
	Masami Hiramatsu (Google),
	regressions, Arnaldo Carvalho de Melo, linux-perf-users,
	linux-kernel

Em Thu, Jun 15, 2023 at 10:01:37PM +0200, Georg Müller escreveu:
> After switching from dwarf_decl_file() to die_get_decl_file(), it is not
> possible to add probes for certain functions of certain binaries:
> 
>  $ perf probe -x /usr/lib/systemd/systemd-logind match_unit_removed
>  A function DIE doesn't have decl_line. Maybe broken DWARF?
>  A function DIE doesn't have decl_line. Maybe broken DWARF?
>  Probe point 'match_unit_removed' not found.
>     Error: Failed to add events.
> 
> The problem is that die_get_decl_file() uses the wrong CU to search for
> the file. elfutils commit e1db5cdc9f has some good explanation for this:
> 
>     dwarf_decl_file uses dwarf_attr_integrate to get the DW_AT_decl_file
>     attribute. This means the attribute might come from a different DIE
>     in a different CU. If so, we need to use the CU associated with the
>     attribute, not the original DIE, to resolve the file name.
> 
> This patch uses the same source of information as elfutils: use attribute
> DW_AT_decl_file and use this CU to search for the file.

Thanks, applied to the perf-tools branch, that will be submitted for
Linux v6.5.

- Arnaldo
 
> Fixes: dc9a5d2ccd5c ("perf probe: Fix to get declared file name from clang DWARF5")
> Signed-off-by: Georg Müller <georgmueller@gmx.net>
> Link: https://lore.kernel.org/r/5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net/
> ---
>  tools/perf/util/dwarf-aux.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
> index b07414409771..137b3ed9897b 100644
> --- a/tools/perf/util/dwarf-aux.c
> +++ b/tools/perf/util/dwarf-aux.c
> @@ -478,8 +478,10 @@ static const char *die_get_file_name(Dwarf_Die *dw_die, int idx)
>  {
>  	Dwarf_Die cu_die;
>  	Dwarf_Files *files;
> +	Dwarf_Attribute attr_mem;
> 
> -	if (idx < 0 || !dwarf_diecu(dw_die, &cu_die, NULL, NULL) ||
> +	if (idx < 0 || !dwarf_attr_integrate(dw_die, DW_AT_decl_file, &attr_mem) ||
> +	    !dwarf_cu_die(attr_mem.cu, &cu_die, NULL, NULL, NULL, NULL, NULL, NULL) ||
>  	    dwarf_getsrcfiles(&cu_die, &files, NULL) != 0)
>  		return NULL;
> 
> --
> 2.41.0
> 

-- 

- Arnaldo

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

* Re: [PATCH] perf probe: read DWARF files from the correct CU
  2023-07-11 12:57       ` Arnaldo Carvalho de Melo
@ 2023-07-11 13:20         ` Masami Hiramatsu
  2023-07-11 14:41           ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 12+ messages in thread
From: Masami Hiramatsu @ 2023-07-11 13:20 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Georg Müller, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Ian Rogers,
	Adrian Hunter, Masami Hiramatsu (Google),
	regressions, Arnaldo Carvalho de Melo, linux-perf-users,
	linux-kernel

On Tue, 11 Jul 2023 09:57:45 -0300
Arnaldo Carvalho de Melo <acme@kernel.org> wrote:

> Em Thu, Jun 15, 2023 at 10:01:37PM +0200, Georg Müller escreveu:
> > After switching from dwarf_decl_file() to die_get_decl_file(), it is not
> > possible to add probes for certain functions of certain binaries:
> > 
> >  $ perf probe -x /usr/lib/systemd/systemd-logind match_unit_removed
> >  A function DIE doesn't have decl_line. Maybe broken DWARF?
> >  A function DIE doesn't have decl_line. Maybe broken DWARF?
> >  Probe point 'match_unit_removed' not found.
> >     Error: Failed to add events.
> > 
> > The problem is that die_get_decl_file() uses the wrong CU to search for
> > the file. elfutils commit e1db5cdc9f has some good explanation for this:
> > 
> >     dwarf_decl_file uses dwarf_attr_integrate to get the DW_AT_decl_file
> >     attribute. This means the attribute might come from a different DIE
> >     in a different CU. If so, we need to use the CU associated with the
> >     attribute, not the original DIE, to resolve the file name.
> > 
> > This patch uses the same source of information as elfutils: use attribute
> > DW_AT_decl_file and use this CU to search for the file.
> 
> Thanks, applied to the perf-tools branch, that will be submitted for
> Linux v6.5.

Thanks Arnaldo and Georg,

It sounds perfect reason why that happened. I didn't expect the case that
the attribute comes from another CU...

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

> 
> - Arnaldo
>  
> > Fixes: dc9a5d2ccd5c ("perf probe: Fix to get declared file name from clang DWARF5")
> > Signed-off-by: Georg Müller <georgmueller@gmx.net>
> > Link: https://lore.kernel.org/r/5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net/
> > ---
> >  tools/perf/util/dwarf-aux.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
> > index b07414409771..137b3ed9897b 100644
> > --- a/tools/perf/util/dwarf-aux.c
> > +++ b/tools/perf/util/dwarf-aux.c
> > @@ -478,8 +478,10 @@ static const char *die_get_file_name(Dwarf_Die *dw_die, int idx)
> >  {
> >  	Dwarf_Die cu_die;
> >  	Dwarf_Files *files;
> > +	Dwarf_Attribute attr_mem;
> > 
> > -	if (idx < 0 || !dwarf_diecu(dw_die, &cu_die, NULL, NULL) ||
> > +	if (idx < 0 || !dwarf_attr_integrate(dw_die, DW_AT_decl_file, &attr_mem) ||
> > +	    !dwarf_cu_die(attr_mem.cu, &cu_die, NULL, NULL, NULL, NULL, NULL, NULL) ||
> >  	    dwarf_getsrcfiles(&cu_die, &files, NULL) != 0)
> >  		return NULL;
> > 
> > --
> > 2.41.0
> > 
> 
> -- 
> 
> - Arnaldo


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

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

* Re: [PATCH] perf probe: read DWARF files from the correct CU
  2023-07-11 13:20         ` Masami Hiramatsu
@ 2023-07-11 14:41           ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-07-11 14:41 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Georg Müller, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Ian Rogers,
	Adrian Hunter, regressions, Arnaldo Carvalho de Melo,
	linux-perf-users, linux-kernel

Em Tue, Jul 11, 2023 at 10:20:00PM +0900, Masami Hiramatsu escreveu:
> On Tue, 11 Jul 2023 09:57:45 -0300 Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> > Em Thu, Jun 15, 2023 at 10:01:37PM +0200, Georg Müller escreveu:
> > > The problem is that die_get_decl_file() uses the wrong CU to search for
> > > the file. elfutils commit e1db5cdc9f has some good explanation for this:
> > > 
> > >     dwarf_decl_file uses dwarf_attr_integrate to get the DW_AT_decl_file
> > >     attribute. This means the attribute might come from a different DIE
> > >     in a different CU. If so, we need to use the CU associated with the
> > >     attribute, not the original DIE, to resolve the file name.
> > > 
> > > This patch uses the same source of information as elfutils: use attribute
> > > DW_AT_decl_file and use this CU to search for the file.
> > 
> > Thanks, applied to the perf-tools branch, that will be submitted for
> > Linux v6.5.
 
> Thanks Arnaldo and Georg,
 
> It sounds perfect reason why that happened. I didn't expect the case that
> the attribute comes from another CU...
 
> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
 
Thanks, added it to the cset.

- Arnaldo

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

* Re: [PATCH v2 1/2] perf probe: add test for regression introduced by switch to die_get_decl_file
  2023-06-28  8:23       ` [PATCH v2 1/2] perf probe: add test for " Georg Müller
@ 2023-07-27 17:45         ` Ian Rogers
  2023-07-28 14:41           ` Georg Müller
  0 siblings, 1 reply; 12+ messages in thread
From: Ian Rogers @ 2023-07-27 17:45 UTC (permalink / raw)
  To: Georg Müller
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Adrian Hunter, Masami Hiramatsu (Google),
	regressions, Arnaldo Carvalho de Melo, linux-perf-users,
	linux-kernel

On Wed, Jun 28, 2023 at 1:25 AM Georg Müller <georgmueller@gmx.net> wrote:
>
> This patch adds a test to validate that perf probe works for binaries
> where DWARF info is split into multiple CUs
>
> Signed-off-by: Georg Müller <georgmueller@gmx.net>
> Link: https://lore.kernel.org/r/5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net/
> ---
>  .../shell/test_uprobe_from_different_cu.sh    | 77 +++++++++++++++++++
>  1 file changed, 77 insertions(+)
>  create mode 100755 tools/perf/tests/shell/test_uprobe_from_different_cu.sh
>
> diff --git a/tools/perf/tests/shell/test_uprobe_from_different_cu.sh b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh
> new file mode 100755
> index 000000000000..00d2e0e2e0c2
> --- /dev/null
> +++ b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh
> @@ -0,0 +1,77 @@
> +#!/bin/bash
> +# test perf probe of function from different CU
> +# SPDX-License-Identifier: GPL-2.0
> +
> +set -e
> +
> +temp_dir=$(mktemp -d /tmp/perf-uprobe-different-cu-sh.XXXXXXXXXX)
> +
> +cleanup()
> +{
> +       trap - EXIT TERM INT
> +       if [[ "${temp_dir}" =~ ^/tmp/perf-uprobe-different-cu-sh.*$ ]]; then
> +               echo "--- Cleaning up ---"
> +               perf probe -x ${temp_dir}/testfile -d foo
> +               rm -f "${temp_dir}/"*
> +               rmdir "${temp_dir}"
> +       fi
> +}
> +
> +trap_cleanup()
> +{
> +        cleanup
> +        exit 1
> +}
> +
> +trap trap_cleanup EXIT TERM INT
> +
> +cat > ${temp_dir}/testfile-foo.h << EOF
> +struct t
> +{
> +  int *p;
> +  int c;
> +};
> +
> +extern int foo (int i, struct t *t);
> +EOF
> +
> +cat > ${temp_dir}/testfile-foo.c << EOF
> +#include "testfile-foo.h"
> +
> +int
> +foo (int i, struct t *t)
> +{
> +  int j, res = 0;
> +  for (j = 0; j < i && j < t->c; j++)
> +    res += t->p[j];
> +
> +  return res;
> +}
> +EOF
> +
> +cat > ${temp_dir}/testfile-main.c << EOF
> +#include "testfile-foo.h"
> +
> +static struct t g;
> +
> +int
> +main (int argc, char **argv)
> +{
> +  int i;
> +  int j[argc];
> +  g.c = argc;
> +  g.p = j;
> +  for (i = 0; i < argc; i++)
> +    j[i] = (int) argv[i][0];
> +  return foo (3, &g);
> +}
> +EOF
> +
> +gcc -g -Og -flto -c ${temp_dir}/testfile-foo.c -o ${temp_dir}/testfile-foo.o
> +gcc -g -Og -c ${temp_dir}/testfile-main.c -o ${temp_dir}/testfile-main.o
> +gcc -g -Og -o ${temp_dir}/testfile ${temp_dir}/testfile-foo.o ${temp_dir}/testfile-main.o

Thanks for the test Georg! By directly relying on gcc this test fails
for me in some constrained environments, like containers. I think
there should be a skip if gcc isn't present. A different option is to
just build the test code into the perf binary itself as a test
workload:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/workloads?h=perf-tools-next

Wdyt? Thanks,
Ian

> +
> +perf probe -x ${temp_dir}/testfile --funcs foo
> +perf probe -x ${temp_dir}/testfile foo
> +
> +cleanup
> --
> 2.41.0
>

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

* Re: [PATCH v2 1/2] perf probe: add test for regression introduced by switch to die_get_decl_file
  2023-07-27 17:45         ` Ian Rogers
@ 2023-07-28 14:41           ` Georg Müller
  0 siblings, 0 replies; 12+ messages in thread
From: Georg Müller @ 2023-07-28 14:41 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Adrian Hunter, Masami Hiramatsu (Google),
	regressions, Arnaldo Carvalho de Melo, linux-perf-users,
	linux-kernel


Am 27.07.23 um 19:45 schrieb Ian Rogers:
> On Wed, Jun 28, 2023 at 1:25 AM Georg Müller <georgmueller@gmx.net> wrote:
>
> Thanks for the test Georg! By directly relying on gcc this test fails
> for me in some constrained environments, like containers. I think
> there should be a skip if gcc isn't present. A different option is to
> just build the test code into the perf binary itself as a test
> workload:
> https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/workloads?h=perf-tools-next
>
> Wdyt? Thanks,
> Ian
>

I prepare a commit which checks for gcc and skips the test in this case.

I think building thi test code into the perf binary itself is not an option
here, since the test relies on a special setup of using -flto for one of the
compilation units.

There is also a cleanup issue if anything fails. This will be included in
the patch as well.

Best regards,
Georg

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

end of thread, other threads:[~2023-07-28 14:42 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <166731050151.2100653.8202870942871353491.stgit@devnote3>
     [not found] ` <166731052936.2100653.13380621874859467731.stgit@devnote3>
     [not found]   ` <5a00d5a5-7be7-ef8a-4044-9a16249fff25@gmx.net>
2023-06-15 14:02     ` [PATCH v2 3/3] tools/perf: Fix to get declared file name from clang DWARF5 Georg Müller
2023-06-15 20:01     ` [PATCH] perf probe: read DWARF files from the correct CU Georg Müller
2023-06-22 22:04       ` Georg Müller
2023-07-11 12:57       ` Arnaldo Carvalho de Melo
2023-07-11 13:20         ` Masami Hiramatsu
2023-07-11 14:41           ` Arnaldo Carvalho de Melo
2023-06-28  8:23     ` [PATCH v2 0/2] perf probe: fix regression introduced by switch to die_get_decl_file Georg Müller
2023-06-28  8:23       ` [PATCH v2 1/2] perf probe: add test for " Georg Müller
2023-07-27 17:45         ` Ian Rogers
2023-07-28 14:41           ` Georg Müller
2023-06-28  8:23       ` [PATCH v2 2/2] perf probe: read DWARF files from the correct CU Georg Müller
2023-06-28  8:41       ` [PATCH v2 0/2] perf probe: fix regression introduced by switch to die_get_decl_file Linux regression tracking (Thorsten Leemhuis)

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).