Blame 0001-fprintf-Fixup-handling-classes-with-no-members.patch

Petr Šabata e2f63e
From b1412a88bb616f449401be285d43b028962992b9 Mon Sep 17 00:00:00 2001
Petr Šabata e2f63e
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Petr Šabata e2f63e
Date: Mon, 1 Jul 2019 11:37:40 -0300
Petr Šabata e2f63e
Subject: [PATCH 1/1] fprintf: Fixup handling classes with no members
Petr Šabata e2f63e
Petr Šabata e2f63e
Will Cohen reported this NULL pointer dereference while processing some
Petr Šabata e2f63e
object linking with cuda:
Petr Šabata e2f63e
Petr Šabata e2f63e
  #0  0x00007ffff7f91453 in __class__fprintf (class=0x522560, cu=0x40ff80, conf=0x7fffffffa930, fp=0x7ffff7ece780 <_IO_2_1_stdout_>)
Petr Šabata e2f63e
      at /home/acme/git/pahole/dwarves_fprintf.c:1624
Petr Šabata e2f63e
  #1  0x00007ffff7f92195 in tag__fprintf (tag=0x522560, cu=0x40ff80, conf=0x7fffffffa930, fp=0x7ffff7ece780 <_IO_2_1_stdout_>)
Petr Šabata e2f63e
      at /home/acme/git/pahole/dwarves_fprintf.c:1835
Petr Šabata e2f63e
  #2  0x00007ffff7f90b57 in __class__fprintf (class=0x5224c0, cu=0x40ff80, conf=0x7fffffffaaa0, fp=0x7ffff7ece780 <_IO_2_1_stdout_>)
Petr Šabata e2f63e
      at /home/acme/git/pahole/dwarves_fprintf.c:1406
Petr Šabata e2f63e
  #3  0x00007ffff7f92195 in tag__fprintf (tag=0x5224c0, cu=0x40ff80, conf=0x40a200 <conf>, fp=0x7ffff7ece780 <_IO_2_1_stdout_>)
Petr Šabata e2f63e
      at /home/acme/git/pahole/dwarves_fprintf.c:1835
Petr Šabata e2f63e
  #4  0x0000000000402d03 in class_formatter (class=0x5224c0, cu=0x40ff80, id=1257) at /home/acme/git/pahole/pahole.c:224
Petr Šabata e2f63e
  #5  0x0000000000403074 in print_classes (cu=0x40ff80) at /home/acme/git/pahole/pahole.c:319
Petr Šabata e2f63e
  #6  0x0000000000404bb2 in pahole_stealer (cu=0x40ff80, conf_load=0x40a240 <conf_load>) at /home/acme/git/pahole/pahole.c:1174
Petr Šabata e2f63e
  #7  0x00007ffff7f9ff73 in finalize_cu (cus=0x40b2b0, cu=0x40ff80, dcu=0x7fffffffacf0, conf=0x40a240 <conf_load>)
Petr Šabata e2f63e
      at /home/acme/git/pahole/dwarf_loader.c:2227
Petr Šabata e2f63e
  #8  0x00007ffff7f9ffac in finalize_cu_immediately (cus=0x40b2b0, cu=0x40ff80, dcu=0x7fffffffacf0, conf=0x40a240 <conf_load>)
Petr Šabata e2f63e
      at /home/acme/git/pahole/dwarf_loader.c:2236
Petr Šabata e2f63e
  #9  0x00007ffff7fa064c in cus__load_module (cus=0x40b2b0, conf=0x40a240 <conf_load>, mod=0x40d760, dw=0x40e980, elf=0x40b360,
Petr Šabata e2f63e
      filename=0x7fffffffd5e3 "examples/wcohen/02_Exercise.cuda") at /home/acme/git/pahole/dwarf_loader.c:2389
Petr Šabata e2f63e
  #10 0x00007ffff7fa0760 in cus__process_dwflmod (dwflmod=0x40d760, userdata=0x40d770, name=0x40d910 "examples/wcohen/02_Exercise.cuda",
Petr Šabata e2f63e
      base=4194304, arg=0x7fffffffcf10) at /home/acme/git/pahole/dwarf_loader.c:2434
Petr Šabata e2f63e
  #11 0x00007ffff7f32be1 in dwfl_getmodules () from /lib64/libdw.so.1
Petr Šabata e2f63e
  #12 0x00007ffff7fa0820 in cus__process_file (cus=0x40b2b0, conf=0x40a240 <conf_load>, fd=3,
Petr Šabata e2f63e
      filename=0x7fffffffd5e3 "examples/wcohen/02_Exercise.cuda") at /home/acme/git/pahole/dwarf_loader.c:2487
Petr Šabata e2f63e
  #13 0x00007ffff7fa089c in dwarf__load_file (cus=0x40b2b0, conf=0x40a240 <conf_load>, filename=0x7fffffffd5e3 "examples/wcohen/02_Exercise.cuda")
Petr Šabata e2f63e
      at /home/acme/git/pahole/dwarf_loader.c:2504
Petr Šabata e2f63e
  #14 0x00007ffff7f8b0dd in cus__load_file (cus=0x40b2b0, conf=0x40a240 <conf_load>, filename=0x7fffffffd5e3 "examples/wcohen/02_Exercise.cuda")
Petr Šabata e2f63e
      at /home/acme/git/pahole/dwarves.c:1745
Petr Šabata e2f63e
  #15 0x00007ffff7f8bc2a in cus__load_files (cus=0x40b2b0, conf=0x40a240 <conf_load>, filenames=0x7fffffffd150)
Petr Šabata e2f63e
      at /home/acme/git/pahole/dwarves.c:2109
Petr Šabata e2f63e
  #16 0x0000000000404ff0 in main (argc=2, argv=0x7fffffffd148) at /home/acme/git/pahole/pahole.c:1294
Petr Šabata e2f63e
  (gdb)
Petr Šabata e2f63e
Petr Šabata e2f63e
  (gdb) p class__name(class, cu)
Petr Šabata e2f63e
  $6 = 0x5cbb85 "__nv_hdl_helper_trait<__nv_dl_tag<int (*)(int, char**), main, 1u>, void (main(int, char**)::__lambda0::*)(int, double&)const>"
Petr Šabata e2f63e
  (gdb) p class->type.nr_members
Petr Šabata e2f63e
  $7 = 0
Petr Šabata e2f63e
  (gdb) p last
Petr Šabata e2f63e
  $8 = (struct class_member *) 0x0
Petr Šabata e2f63e
  (gdb)
Petr Šabata e2f63e
Petr Šabata e2f63e
So, before checking for bitfield details, first check if there were
Petr Šabata e2f63e
members.
Petr Šabata e2f63e
Petr Šabata e2f63e
Now, if we show all structs/classes in that object file and look for the
Petr Šabata e2f63e
above data structure, we find it inside another:
Petr Šabata e2f63e
Petr Šabata e2f63e
  $ pahole examples/wcohen/02_Exercise.cuda
Petr Šabata e2f63e
  <SNIP>
Petr Šabata e2f63e
  struct __nv_hdl_helper_trait_outer<false, false, int, Kokkos::View<double**>, Kokkos::View<double*>, Kokkos::View<double*> > {
Petr Šabata e2f63e
          struct __nv_hdl_helper_trait<__nv_dl_tag<int (*)(int, char**), main, 1u>, void (main(int, char**)::__lambda0::*)(int, double&)const> {
Petr Šabata e2f63e
                  class __nv_hdl_wrapper_t<false, false, __nv_dl_tag<int (*)(int, char**), main, 1u>, void(int, double&), int, Kokkos::View<doubl get<main(int, char**)::__lambda0>(class __lambda0, int, class View<double**>, class View<double*>, class View<double*>);
Petr Šabata e2f63e
Petr Šabata e2f63e
                  /* size: 1, cachelines: 0, members: 0 */
Petr Šabata e2f63e
                  /* padding: 1 */
Petr Šabata e2f63e
                  /* last cacheline: 1 bytes */
Petr Šabata e2f63e
          };
Petr Šabata e2f63e
Petr Šabata e2f63e
          /* size: 1, cachelines: 0, members: 0 */
Petr Šabata e2f63e
          /* padding: 1 */
Petr Šabata e2f63e
          /* last cacheline: 1 bytes */
Petr Šabata e2f63e
  };
Petr Šabata e2f63e
  <SNIP>
Petr Šabata e2f63e
  $
Petr Šabata e2f63e
Petr Šabata e2f63e
Reported-by: William Cohen <wcohen@redhat.com>
Petr Šabata e2f63e
Fixes: 13e5b9fc00ee ("fprintf: Add unnamed bitfield padding at the end to rebuild original type")
Petr Šabata e2f63e
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Petr Šabata e2f63e
---
Petr Šabata e2f63e
 dwarves_fprintf.c | 2 +-
Petr Šabata e2f63e
 1 file changed, 1 insertion(+), 1 deletion(-)
Petr Šabata e2f63e
Petr Šabata e2f63e
diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c
Petr Šabata e2f63e
index 8ad1ced7840c..706f1b5033f5 100644
Petr Šabata e2f63e
--- a/dwarves_fprintf.c
Petr Šabata e2f63e
+++ b/dwarves_fprintf.c
Petr Šabata e2f63e
@@ -1620,7 +1620,7 @@ static size_t __class__fprintf(struct class *class, const struct cu *cu,
Petr Šabata e2f63e
 	 * to avoid adding the forced bitfield paddings and have btfdiff happy.
Petr Šabata e2f63e
 	 */
Petr Šabata e2f63e
 	if (class->padding != 0 && type->alignment == 0 && cconf.has_alignment_info &&
Petr Šabata e2f63e
-	    !cconf.suppress_force_paddings) {
Petr Šabata e2f63e
+	    !cconf.suppress_force_paddings && last != NULL) {
Petr Šabata e2f63e
 		tag_pos = cu__type(cu, last->tag.type);
Petr Šabata e2f63e
 		size = tag__size(tag_pos, cu);
Petr Šabata e2f63e
 
Petr Šabata e2f63e
-- 
Petr Šabata e2f63e
2.20.1
Petr Šabata e2f63e