Go to file
Arnaldo Carvalho de Melo a7d9c58cb8 fprintf: Add missing closing parens to the align attribute
Noticed while trying to use pfunct's -b option, that will show a
function prototype + the types it uses in its function signature, i.e.:

  $ pfunct -b -f tcp_sendmsg tcp.o
  typedef long long unsigned int __u64;
  typedef __u64 __addrpair;

  typedef unsigned int __u32;
  typedef __u32 __be32;

  typedef short unsigned int __u16;

  typedef __u32 __portpair;

  typedef __u16 __be16;

  struct hlist_node {
  	struct hlist_node *        next;                 /*     0     8 */
  	struct hlist_node * *      pprev;                /*     8     8 */

  	/* size: 16, cachelines: 1, members: 2 */
  	/* last cacheline: 16 bytes */
  };

  <SNIP tons of types>

  struct sock {
  	struct sock_common         __sk_common;          /*     0   136 */
  	/* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */
  	socket_lock_t              sk_lock;              /*   136    32 */
  	atomic_t                   sk_drops;             /*   168     4 */
  	/* --- cacheline 10 boundary (640 bytes) --- */
<SNIP the rest of the 'struct sock' members>
  	struct sock_cgroup_data    sk_cgrp_data;         /*   640     8 */
  	struct mem_cgroup *        sk_memcg;             /*   648     8 */
  	void                       (*sk_state_change)(struct sock *); /*   656     8 */
  	void                       (*sk_data_ready)(struct sock *); /*   664     8 */
  	void                       (*sk_write_space)(struct sock *); /*   672     8 */
  	void                       (*sk_error_report)(struct sock *); /*   680     8 */
  	int                        (*sk_backlog_rcv)(struct sock *, struct sk_buff *); /*   688     8 */
  	void                       (*sk_destruct)(struct sock *); /*   696     8 */
  	/* --- cacheline 11 boundary (704 bytes) --- */
  	struct sock_reuseport *    sk_reuseport_cb;      /*   704     8 */
  	struct callback_head       sk_rcu __attribute__((__aligned__(8))); /*   712    16 */

  	/* size: 728, cachelines: 12, members: 84 */
  	/* sum members: 715, holes: 4, sum holes: 8 */
  	/* sum bitfield members: 40 bits (5 bytes) */
  	/* paddings: 1, sum paddings: 4 */
  	/* forced alignments: 1 */
  	/* last cacheline: 24 bytes */
  };

<SNIP some more types>

  struct kiocb;

  struct msghdr {
  	void *                     msg_name;             /*     0     8 */
  	int                        msg_namelen;          /*     8     4 */

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

  	struct iov_iter            msg_iter;             /*    16    40 */
  	void *                     msg_control;          /*    56     8 */
  	/* --- cacheline 1 boundary (64 bytes) --- */
  	__kernel_size_t            msg_controllen;       /*    64     8 */
  	unsigned int               msg_flags;            /*    72     4 */

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

  	struct kiocb *             msg_iocb;             /*    80     8 */

  	/* size: 88, cachelines: 2, members: 7 */
  	/* sum members: 80, holes: 2, sum holes: 8 */
  	/* last cacheline: 24 bytes */
  };

  typedef __kernel_size_t size_t;

  int tcp_sendmsg(struct sock * sk, struct msghdr * msg, size_t size);
  $

So if we then redirect the output to a file and if we make it a empty
function instead of a prototype, i.e. if we make the last line above to
become this:

  int tcp_sendmsg(struct sock * sk, struct msghdr * msg, size_t size) {}

then build with gcc -g to have it build as a .o with DWARF info, then we
should be able to see if the struct rebuilt from DWARF matches the
original struct used to generate the DWARF, going full circle:

  $ pfunct -b -f tcp_sendmsg tcp.o > tcp_sendmsg_types.c
  $ gcc -c tcp_sendmsg_types.c -g
  $ file tcp_sendmsg_types.o
  tcp_sendmsg_types.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
  $ pahole -E -C sock tcp_sendmsg_types.o > tcp_sendmsg_types.o.pahole
  $ pahole -E -C sock tcp.o > tcp.o.pahole
  $ diff -u tcp_sendmsg_types.o.pahole tcp.o.pahole
  $ wc -l tcp_sendmsg_types.o.pahole
  420 tcp_sendmsg_types.o.pahole
  $

So all the types that come from sock are expanded and all its details
are reconstructed in the same way for both cases.

  $ pahole -C sock tcp.o | tail
	struct sock_reuseport *    sk_reuseport_cb;      /*   704     8 */
	struct callback_head       sk_rcu __attribute__((__aligned__(8))); /*   712    16 */

	/* size: 728, cachelines: 12, members: 84 */
	/* sum members: 715, holes: 4, sum holes: 8 */
	/* sum bitfield members: 40 bits (5 bytes) */
	/* paddings: 1, sum paddings: 4 */
	/* forced alignments: 1 */
	/* last cacheline: 24 bytes */
  };
  $ pahole -C sock tcp_sendmsg_types.o | tail
	struct sock_reuseport *    sk_reuseport_cb;      /*   704     8 */
	struct callback_head       sk_rcu __attribute__((__aligned__(8))); /*   712    16 */

	/* size: 728, cachelines: 12, members: 84 */
	/* sum members: 715, holes: 4, sum holes: 8 */
	/* sum bitfield members: 40 bits (5 bytes) */
	/* paddings: 1, sum paddings: 4 */
	/* forced alignments: 1 */
	/* last cacheline: 24 bytes */
  };
  $

Reported-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andrii Nakryiko <andriin@fb.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Yonghong Song <yhs@fb.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-04-04 10:48:17 -03:00
cmake/modules cmake: Add comments explaining build_id and fedora/rh detection 2009-06-27 13:32:20 -03:00
lib libbpf: Sync in latest libbpf sources 2019-03-29 15:53:13 -03:00
man-pages dwarves_fprintf: Allow suppressing the __attribute__((__aligned__(N)) 2019-04-03 18:10:16 -03:00
ostra [OSTRA]: Change ostra-cg license to GPLv2 2007-12-24 12:25:17 -02:00
rpm/SPECS v1.12 - New Release 2018-08-16 16:15:27 -03:00
.gitignore pahole: Add build dir, config.h to .gitignore 2019-02-11 12:55:46 -03:00
.gitmodules pahole: add libbpf as submodule under lib/bpf 2019-02-11 12:56:40 -03:00
CMakeLists.txt libbpf: Build as PIC and statically link into libdwarves 2019-02-19 10:21:29 -03:00
COPYING [LICENSE]: Add COPYING file and add missing license info on some files 2007-12-17 14:15:42 -02:00
MANIFEST MANIFEST: Add missing COPYING file 2018-09-11 11:22:41 -03:00
NEWS v1.12 - New Release 2018-08-16 16:15:27 -03:00
README [CMAKE]: Make the default install prefix be /usr/local 2007-04-19 18:01:47 -03:00
README.DEBUG README.DEBUG: Add an extra step to make the instructions cut'n'exec 2017-12-14 14:15:54 -03:00
README.btf README.btf: Add section on validating the .BTF section via the kernel 2018-08-16 12:05:29 -03:00
README.ctracer ctracer: update README.ctracer, f9 has the dwarves 2008-10-29 08:54:53 -02:00
btf_encoder.c dwarf_loader: Use DWARF recommended uniform bit offset scheme 2019-03-29 15:55:37 -03:00
btf_encoder.h Fixup copyright notices for BTF files authored by Facebook engineers 2019-01-18 20:34:05 -03:00
btf_loader.c dwarf_loader: Use DWARF recommended uniform bit offset scheme 2019-03-29 15:55:37 -03:00
btfdiff btfdiff: Use --suppress_aligned_attribute with -F dwarf 2019-04-03 18:10:16 -03:00
codiff.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
config.h.cmake [DWARVES] Fixes a FIXME relating to a missing elf (libdw) symbol check. 2008-02-12 21:08:49 -02:00
ctf.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
ctf_encoder.c libctf: The type_ids returned are uint32_t fixup where it was uint16_t 2019-03-11 11:44:53 -03:00
ctf_encoder.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
ctf_loader.c loaders: Record CU's endianness in dwarf/btf/ctf loaders 2019-03-29 15:55:37 -03:00
ctfdwdiff ctfdwdiff: Don't ask for variables and inline expansions in pfunct 2009-03-31 19:21:46 -03:00
ctracer.c dwarves: Introduce type_id_t for use with the type IDs 2019-03-11 11:44:53 -03:00
dtagnames.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
dutil.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
dutil.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
dwarf_loader.c dwarf_loader: Handle DW_TAG_label in inline expansions 2019-04-03 21:34:01 -03:00
dwarves.c class__find_holes: Zero out bit_hole/hole on member 2019-04-03 21:10:05 -03:00
dwarves.h dwarves_fprintf: Allow suppressing the __attribute__((__aligned__(N)) 2019-04-03 18:10:16 -03:00
dwarves_emit.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
dwarves_emit.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
dwarves_fprintf.c fprintf: Add missing closing parens to the align attribute 2019-04-04 10:48:17 -03:00
dwarves_reorganize.c reorganize: Disable the bitfield coalescing/moving steps 2019-04-03 18:35:43 -03:00
dwarves_reorganize.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
elf_symtab.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
elf_symtab.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
elfcreator.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
elfcreator.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
gobuffer.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
gobuffer.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
hash.h [DWARVES]: Use a hash table for the tags in a CU 2008-02-11 11:47:17 -02:00
libbtf.c btf_encoder: run BTF deduplication before writing out to ELF 2019-02-18 11:00:03 -03:00
libbtf.h btf_elf: Rename btf_elf__free() to btf_elf__delete() 2019-02-14 17:06:40 -03:00
libctf.c libctf: The type_ids returned are uint32_t fixup where it was uint16_t 2019-03-11 11:44:53 -03:00
libctf.h libctf: The type_ids returned are uint32_t fixup where it was uint16_t 2019-03-11 11:44:53 -03:00
list.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
pahole.c dwarves_fprintf: Allow suppressing the __attribute__((__aligned__(N)) 2019-04-03 18:10:16 -03:00
pdwtags.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
pfunct.c dwarves: Introduce type_id_t for use with the type IDs 2019-03-11 11:44:53 -03:00
pglobal.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
prefcnt.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
rbtree.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
rbtree.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
regtest regtest: Accept --diff instad of plain 'diff' as long option 2012-05-14 19:36:58 -03:00
scncopy.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
strings.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
strings.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
syscse.c dwarves: Introduce type_id_t for use with the type IDs 2019-03-11 11:44:53 -03:00

README

Build instructions:

1. install cmake
2. mkdir build
3. cd build
4. cmake -D__LIB=lib ..
5. make install

Default is to be installed on /usr/local, see rpm spec file for
installing on other places.

Known to work scenarios:

Mandriva Cooker:

cmake 2.4.5-1mdv2007.1
libelfutils1-devel 0.123-1mdv2007.1

Debian Unstable:

cmake 2.4.5-1
libdw-dev 0.123-2

Fedora Core 6:

cmake 2.4.5-2.fc6
elfutils-devel 0.126-1.fc6