dwarf_loader: Store the DW_AT_alignment if available

DWARF got a DW_AT_alignment as described in:

  http://dwarfstd.org/ShowIssue.php?issue=140528.1

This appeared first in DWARF5:

  http://dwarfstd.org/doc/DWARF5.pdf

In:

 ----------------------------------------------------------------------

Chapter 2.

General Description

2.24    Alignment

A debugging information entry may have a DW_AT_alignment attribute whose
value of class constant is a positive, non-zero, integer describing the
alignment of the entity.

For example, an alignment attribute whose value is 8 indicates that the
entity to which it applies occurs at an address that is a multiple of
eight (not a multiple of 8 or 256)

 ----------------------------------------------------------------------

Use it on a struct present in the running kernel, i.e. not specifying
which ELF file to look for the DWARF info to use:

  $ pahole -C inet_timewait_death_row
  struct inet_timewait_death_row {
  	atomic_t                   tw_count;             /*     0     4 */

  	/* XXX 60 bytes hole, try to pack */

  	/* --- cacheline 1 boundary (64 bytes) --- */
  	struct inet_hashinfo *     hashinfo __attribute__((__aligned__(64)); /*    64     8 */
  	int                        sysctl_max_tw_buckets; /*    72     4 */

  	/* size: 128, cachelines: 2, members: 3 */
  	/* sum members: 16, holes: 1, sum holes: 60 */
  	/* padding: 52 */
  };
  $

Now to do some tweaking to get that "__attribute..." part nicely, hum,
aligned in the pahole output :-)

BTW: the original struct is in the kernel sources:

  include/net/netns/ipv4.h

  struct inet_timewait_death_row {
          atomic_t                tw_count;

          struct inet_hashinfo    *hashinfo ____cacheline_aligned_in_smp;
          int                     sysctl_max_tw_buckets;
  };

Reported-by: Mark Wielaard <mark@klomp.org>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Andrii Nakryiko <andriin@fb.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Yonghong Song <yhs@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2 files changed