blob: 9509fb4e77b67c1b8a3586057e6aaca74108d547 [file] [log] [blame]
Patrick Williams213cb262021-08-07 19:21:33 -05001glibc 2.34 calls pthread_kill from the raise function. Before raise
2directly called the (tg)kill syscall. So allow pthread_kill to be the
3first frame in a backtrace where raise is expected. Also change some
4asserts to fprintf plus abort to make it more clear why the testcase
5fails.
6
7https://sourceware.org/bugzilla/show_bug.cgi?id=28190
8
9Signed-off-by: Mark Wielaard <mark@klomp.org>
10Upstream-Status: Submitted [https://sourceware.org/pipermail/elfutils-devel/2021q3/004019.html]
11---
12 tests/ChangeLog | 6 +++++
13 tests/backtrace.c | 62 +++++++++++++++++++++++++++++++++++++++++------
14 2 files changed, 61 insertions(+), 7 deletions(-)
15
16Index: elfutils-0.185/tests/ChangeLog
17===================================================================
18--- elfutils-0.185.orig/tests/ChangeLog
19+++ elfutils-0.185/tests/ChangeLog
20@@ -1,3 +1,9 @@
21+2021-08-04 Mark Wielaard <mark@klomp.org>
22+
23+ PR28190
24+ * backtrace.c (callback_verify): Check for pthread_kill as first
25+ frame. Change asserts to fprintf plus abort.
26+
27 2021-05-14 Frank Ch. Eigler <fche@redhat.com>
28
29 PR27859
30Index: elfutils-0.185/tests/backtrace.c
31===================================================================
32--- elfutils-0.185.orig/tests/backtrace.c
33+++ elfutils-0.185/tests/backtrace.c
34@@ -97,6 +97,9 @@ callback_verify (pid_t tid, unsigned fra
35 static bool reduce_frameno = false;
36 if (reduce_frameno)
37 frameno--;
38+ static bool pthread_kill_seen = false;
39+ if (pthread_kill_seen)
40+ frameno--;
41 if (! use_raise_jmp_patching && frameno >= 2)
42 frameno += 2;
43 const char *symname2 = NULL;
44@@ -107,11 +110,26 @@ callback_verify (pid_t tid, unsigned fra
45 && (strcmp (symname, "__kernel_vsyscall") == 0
46 || strcmp (symname, "__libc_do_syscall") == 0))
47 reduce_frameno = true;
48+ else if (! pthread_kill_seen && symname
49+ && strstr (symname, "pthread_kill") != NULL)
50+ pthread_kill_seen = true;
51 else
52- assert (symname && strcmp (symname, "raise") == 0);
53+ {
54+ if (!symname || strcmp (symname, "raise") != 0)
55+ {
56+ fprintf (stderr,
57+ "case 0: expected symname 'raise' got '%s'\n", symname);
58+ abort ();
59+ }
60+ }
61 break;
62 case 1:
63- assert (symname != NULL && strcmp (symname, "sigusr2") == 0);
64+ if (symname == NULL || strcmp (symname, "sigusr2") != 0)
65+ {
66+ fprintf (stderr,
67+ "case 1: expected symname 'sigusr2' got '%s'\n", symname);
68+ abort ();
69+ }
70 break;
71 case 2: // x86_64 only
72 /* __restore_rt - glibc maybe does not have to have this symbol. */
73@@ -120,11 +138,21 @@ callback_verify (pid_t tid, unsigned fra
74 if (use_raise_jmp_patching)
75 {
76 /* Verify we trapped on the very first instruction of jmp. */
77- assert (symname != NULL && strcmp (symname, "jmp") == 0);
78+ if (symname == NULL || strcmp (symname, "jmp") != 0)
79+ {
80+ fprintf (stderr,
81+ "case 3: expected symname 'raise' got '%s'\n", symname);
82+ abort ();
83+ }
84 mod = dwfl_addrmodule (dwfl, pc - 1);
85 if (mod)
86 symname2 = dwfl_module_addrname (mod, pc - 1);
87- assert (symname2 == NULL || strcmp (symname2, "jmp") != 0);
88+ if (symname2 == NULL || strcmp (symname2, "jmp") != 0)
89+ {
90+ fprintf (stderr,
91+ "case 3: expected symname2 'jmp' got '%s'\n", symname2);
92+ abort ();
93+ }
94 break;
95 }
96 FALLTHROUGH;
97@@ -137,11 +165,22 @@ callback_verify (pid_t tid, unsigned fra
98 duplicate_sigusr2 = true;
99 break;
100 }
101- assert (symname != NULL && strcmp (symname, "stdarg") == 0);
102+ if (symname == NULL || strcmp (symname, "stdarg") != 0)
103+ {
104+ fprintf (stderr,
105+ "case 4: expected symname 'stdarg' got '%s'\n", symname);
106+ abort ();
107+ }
108 break;
109 case 5:
110 /* Verify we trapped on the very last instruction of child. */
111- assert (symname != NULL && strcmp (symname, "backtracegen") == 0);
112+ if (symname == NULL || strcmp (symname, "backtracegen") != 0)
113+ {
114+ fprintf (stderr,
115+ "case 5: expected symname 'backtracegen' got '%s'\n",
116+ symname);
117+ abort ();
118+ }
119 mod = dwfl_addrmodule (dwfl, pc);
120 if (mod)
121 symname2 = dwfl_module_addrname (mod, pc);
122@@ -151,7 +190,15 @@ callback_verify (pid_t tid, unsigned fra
123 // instructions or even inserts some padding instructions at the end
124 // (which apparently happens on ppc64).
125 if (use_raise_jmp_patching)
126- assert (symname2 == NULL || strcmp (symname2, "backtracegen") != 0);
127+ {
128+ if (symname2 != NULL && strcmp (symname2, "backtracegen") == 0)
129+ {
130+ fprintf (stderr,
131+ "use_raise_jmp_patching didn't expect symname2 "
132+ "'backtracegen'\n");
133+ abort ();
134+ }
135+ }
136 break;
137 }
138 }