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

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