Collect the information of per-cpu variables from encoders of worker
threads to the primary encoder.
btf_encoder store per-cpu info separately, not in BTF. Previously, it
merged only BTF types generated by worker threads. So some of the
per-cpu info was missing.
Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
Tested-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: dwarves@vger.kernel.org
Link: https://lore.kernel.org/r/20220321230837.855572-1-kuifeng@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This patch improves the error seen by the user by setting errno in
cus__load_files(). Otherwise, we get a "No such file or directory" error
which might be confusing.
Before the patch, using a bogus file:
$ ./pahole -J ./vmlinux-5.3.18-24.102-default.debug
pahole: ./vmlinux-5.3.18-24.102-default.debug: No such file or directory
$ ls ./vmlinux-5.3.18-24.102-default.debug
/home/kkourt/src/hubble-fgs/vmlinux-5.3.18-24.102-default.debug
$
After the patch:
$ ./pahole -J ./vmlinux-5.3.18-24.102-default.debug
pahole: ./vmlinux-5.3.18-24.102-default.debug: Unknown error -22
$
Which is not very helpful, but less confusing.
Committer notes:
We need to turn the returned negative error to positive when setting it
to 'errno', that way the error message will be:
$ ./pahole -J ./vmlinux-5.3.18-24.102-default.debug
pahole: ./vmlinux-5.3.18-24.102-default.debug: Invalid argument
$
Because:
$ grep -w 22 /usr/include/*/errno*
/usr/include/asm-generic/errno-base.h:#define EINVAL 22 /* Invalid argument */
$
Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Link: http://lore.kernel.org/lkml/20220316132354.3226908-1-kkourt@kkourt.io
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
When trying to use BTF encoding for an apparently problematic kernel
file, pahole segfaults. As can be seen below [1], the problem is that we
are trying to dereference a NULL decoder.
Fix this by checking the return value of dwfl_getmodules which [2] will
return -1 on errors or an offset if one of the modules did not return
DWARF_CB_OK. (In this specific case, it was __cus__load_debug_types that
returned DWARF_CB_ABORT.)
[1]:
$ gdb -q --args ./pahole -J vmlinux-5.3.18-24.102-default.debug
Reading symbols from ./pahole...
(gdb) r
Starting program: /tmp/pahole/build/pahole -J vmlinux-5.3.18-24.102-default.debug
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7f4000e in gobuffer__size (gb=0x18) at /tmp/pahole/gobuffer.h:39
39 return gb->index;
(gdb) bt
(gdb) frame 1
1042 if (gobuffer__size(&encoder->percpu_secinfo) != 0)
(gdb) list
1037
1038 int btf_encoder__encode(struct btf_encoder *encoder)
1039 {
1040 int err;
1041
1042 if (gobuffer__size(&encoder->percpu_secinfo) != 0)
1043 btf_encoder__add_datasec(encoder, PERCPU_SECTION);
1044
1045 /* Empty file, nothing to do, so... done! */
1046 if (btf__get_nr_types(encoder->btf) == 0)
(gdb) print encoder
$1 = (struct btf_encoder *) 0x0
[2] https://sourceware.org/git/?p=elfutils.git;a=blob;f=libdwfl/libdwfl.h;h=f98f1d525d94bc7bcfc7c816890de5907ee4bd6d;hb=HEAD#l200
Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Link: http://lore.kernel.org/lkml/20220316132338.3226871-1-kkourt@kkourt.io
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This is the same strategy adopted by the bpftool when generating a
vmlinux file using:
$ bpftool btf dump file vmlinux format c > vmlinux.h
Testing it:
$ cat a.c
#include "vmlinux.h"
int main(void)
{
struct saved_context bla;
bla.ds = 1;
return bla.ds + 1;
}
$
$ rm -f a ; make a
cc a.c -o a
$
Now using pahole:
$ pahole --compile > vmlinux.h
$ rm -f a ; make a
$
This still have some issues, like:
$ pahole --compile ../build/allyesconfig/drivers/spi/spi-bitbang.o > spi.h
$ make spi
cc spi.c -o spi
In file included from spi.c:1:
spi.h:7127:38: error: ‘txrx_word’ declared as function returning an array
7127 | u32 (*txrx_word)(struct spi_device *, unsigned int, u32, u8, unsigned int)[4]; /* 200 32 */
| ^~~~~~~~~
make: *** [<builtin>: spi] Error 1
$
The original source code:
/* txrx_word[SPI_MODE_*]() just looks like a shift register */
u32 (*txrx_word[4])(struct spi_device *, unsigned int, u32, u8, unsigned int);
But this misgeneration predates this patch, so shouldn't prevent it from
being merged now, to make progress.
Also there are issues when generating from DWARF, so for now only accept
it if generating from BTF.
Trying to run it with dwarf produces, for now:
$ pahole -F dwarf --compile vmlinux
pahole: --compile currently only works with BTF.
$
Cc: Tony Jones <tonyj@suse.de>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
We can't have on the same compilation unit more than one of struct,
union, enum, class type with the same name, so when trying to create a
file with all types in a multi compilation unit binary debug
information we must disambiguate, do it by addint a __N prefix to the
type name.
This is the same strategy adopted by the bpftool when generating a
vmlinux file using:
$ bpftool btf dump file vmlinux format c > vmlinux.h
Testing it:
$ cat a.c
#include "vmlinux.h"
int main(void)
{
struct saved_context bla;
bla.ds = 1;
return bla.ds + 1;
}
$
$ rm -f a ; make a
cc a.c -o a
$
With an upcoming patch this will be possible using:
$ pahole --compile > vmlinux.h
$ rm -f a ; make a
$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
As we may have, say, both a typedef and a struct with the same name and
sometimes we need to emit both to reflect some types found in the Linux
kernel that use:
typedef struct foo {
...
} foo;
So we need both 'struct foo' and 'typedef foo'.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
To avoid emitting:
enum x86_intercept_stage {
};
Which isn't compilable.
The DWARF info for this enum in the Linux kernel has the declaration
flag set, but somehow this is not being available when loading from BTF.
So do the best we can at this enumeration__fprintf() time, that is to
just print zero members enumerations as a forward declaration.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
There are tools that don't set conf_load->conf_fprintf, like codiff, so
check for that in dwarves__resolve_cacheline_size().
Cc: Douglas Raillard <douglas.raillard@arm.com>
Fixes: 772725a77d ("dwarves_fprintf: Move cacheline_size into struct conf_fprintf")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tldr;
gdb pfunct
(gdb) run --compile tcp.o
Program received signal SIGFPE, Arithmetic exception.
0x00007ffff7f18551 in class__fprintf_cacheline_boundary (conf=0x7fffffffda10, offset=0, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_fprintf.c:1319
1319 uint32_t cacheline = offset / conf->cacheline_size;
(gdb) bt
#0 0x00007ffff7f18551 in class__fprintf_cacheline_boundary (conf=0x7fffffffda10, offset=0, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_fprintf.c:1319
#1 0x00007ffff7f16af2 in class_member__fprintf (member=0x45de10, union_member=false, type=0x45dfb0, cu=0x435a40, conf=0x7fffffffda10, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_fprintf.c:869
#2 0x00007ffff7f1717b in struct_member__fprintf (member=0x45de10, type=0x45dfb0, cu=0x435a40, conf=0x7fffffffda10, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_fprintf.c:983
#3 0x00007ffff7f1945c in __class__fprintf (class=0x45dcc0, cu=0x435a40, conf=0x7fffffffdbb0, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_fprintf.c:1583
#4 0x00007ffff7f1a6bd in tag__fprintf (tag=0x45dcc0, cu=0x435a40, conf=0x7fffffffdc70, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_fprintf.c:1906
#5 0x00007ffff7fbf022 in type__emit (tag=0x45dcc0, cu=0x435a40, prefix=0x0, suffix=0x0, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_emit.c:333
#6 0x00007ffff7fbed3d in tag__emit_definitions (tag=0x6b21e0, cu=0x435a40, emissions=0x408300 <emissions>, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_emit.c:265
#7 0x00007ffff7fbef45 in type__emit_definitions (tag=0x6b20c0, cu=0x435a40, emissions=0x408300 <emissions>, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_emit.c:315
#8 0x00007ffff7fbed15 in tag__emit_definitions (tag=0x6b3b40, cu=0x435a40, emissions=0x408300 <emissions>, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_emit.c:264
#9 0x00007ffff7fbef45 in type__emit_definitions (tag=0x6b31d0, cu=0x435a40, emissions=0x408300 <emissions>, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_emit.c:315
#10 0x00007ffff7fbed15 in tag__emit_definitions (tag=0x4cb920, cu=0x435a40, emissions=0x408300 <emissions>, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_emit.c:264
#11 0x00007ffff7fbef45 in type__emit_definitions (tag=0x4cb7d0, cu=0x435a40, emissions=0x408300 <emissions>, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/dwarves_emit.c:315
#12 0x0000000000403592 in function__emit_type_definitions (func=0x738ad0, cu=0x435a40, fp=0x7ffff7e17520 <_IO_2_1_stdout_>) at /var/home/acme/git/pahole/pfunct.c:353
#13 0x0000000000403670 in function__show (func=0x738ad0, cu=0x435a40) at /var/home/acme/git/pahole/pfunct.c:371
#14 0x00000000004038e9 in cu_function_iterator (cu=0x435a40, cookie=0x0) at /var/home/acme/git/pahole/pfunct.c:404
#15 0x00007ffff7f1296b in cus__for_each_cu (cus=0x4369e0, iterator=0x403869 <cu_function_iterator>, cookie=0x0, filter=0x0) at /var/home/acme/git/pahole/dwarves.c:1919
#16 0x000000000040432a in main (argc=3, argv=0x7fffffffe1f8) at /var/home/acme/git/pahole/pfunct.c:776
(gdb) p conf->cacheline_size
$2 = 0
We need to pass a conf_fprintf pointer to the chain starting with
function__emit_type_definitions(), i.e. dwarves_emit.c needs to receive
the printing configuration instead of, right at type__emit() synthesize
a conf_fprintf without initializing conf_fprintf->cacheline_size which
ends up in a division by zero.
But to fix this quicker just add a helper that checks if it is zero and
uses the conf_fprintf__defaults.cacheline_size field that is being
initialized by all tools via:
dwarves__resolve_cacheline_size(&conf_load, 0);
Fixes: 772725a77d ("dwarves_fprintf: Move cacheline_size into struct conf_fprintf")
Cc: Douglas Raillard <douglas.raillard@arm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Add interfaces to allow users of dwarf_loader to prepare and pass
per-thread data to steal-functions running on worker threads.
Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Link: https://lore.kernel.org/r/20220126192039.2840752-3-kuifeng@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
We use this in both the dwarf_loader.c and in fprintf.c, so define it in
dwarves.h that is included in both.
Reported-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/all/YbkTAPn3EEu6BUYR@archlinux-ax161
Cc: Domenico Andreoli <domenico.andreoli@linux.com>
Cc: Douglas RAILLARD <douglas.raillard@arm.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Jan Engelhardt <jengelh@inai.de>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Matteo Croce <mcroce@microsoft.com>
Cc: Matthias Schwarzott <zzam@gentoo.org>
Cc: Yonghong Song <yhs@fb.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This reverts commit 7c5e35b63b.
Dropped since it could not cope with recursive types. A new attempt will
be made on 1.24.
Signed-off-by: Douglas RAILLARD <douglas.raillard@arm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This reverts commit 005236c3e4.
Dropped since it could not cope with recursive types. A new attempt will
be made on 1.24.
Signed-off-by: Douglas RAILLARD <douglas.raillard@arm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Allow making inner struct enums and union anonymous, so that when using
-E to expand types we don't end up with multiple definitions for
expanded inner structs, allowing the resulting expanded struct to be
compilable.
Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
[ Applied it manually to cover some fuzz due to other patches ]
Link: https://lore.kernel.org/all/20211019100724.325570-2-douglas.raillard@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
In the past we saw the value of being able to disable specific features
due to problems in in its implementation, allowing users to use a subset
of functionality, without the problematic one.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
In the past we saw the value of being able to disable specific features
due to problems in in its implementation, allowing users to use a subset
of functionality, without the problematic one.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
LLVM patches ([1] for clang, [2] and [3] for BPF backend)
added support for btf_type_tag attributes. The following is
an example:
[$ ~] cat t.c
#define __tag1 __attribute__((btf_type_tag("tag1")))
#define __tag2 __attribute__((btf_type_tag("tag2")))
int __tag1 * __tag1 __tag2 *g __attribute__((section(".data..percpu")));
[$ ~] clang -O2 -g -c t.c
[$ ~] llvm-dwarfdump --debug-info t.o
t.o: file format elf64-x86-64
...
0x0000001e: DW_TAG_variable
DW_AT_name ("g")
DW_AT_type (0x00000033 "int **")
DW_AT_external (true)
DW_AT_decl_file ("/home/yhs/t.c")
DW_AT_decl_line (3)
DW_AT_location (DW_OP_addr 0x0)
0x00000033: DW_TAG_pointer_type
DW_AT_type (0x0000004b "int *")
0x00000038: DW_TAG_LLVM_annotation
DW_AT_name ("btf_type_tag")
DW_AT_const_value ("tag1")
0x00000041: DW_TAG_LLVM_annotation
DW_AT_name ("btf_type_tag")
DW_AT_const_value ("tag2")
0x0000004a: NULL
0x0000004b: DW_TAG_pointer_type
DW_AT_type (0x0000005a "int")
0x00000050: DW_TAG_LLVM_annotation
DW_AT_name ("btf_type_tag")
DW_AT_const_value ("tag1")
0x00000059: NULL
0x0000005a: DW_TAG_base_type
DW_AT_name ("int")
DW_AT_encoding (DW_ATE_signed)
DW_AT_byte_size (0x04)
0x00000061: NULL
From the above example, you can see that DW_TAG_pointer_type may contain
one or more DW_TAG_LLVM_annotation btf_type_tag tags. If
DW_TAG_LLVM_annotation tags are present inside DW_TAG_pointer_type, for
BTF encoding, pahole will need to follow [3] to generate a type chain
like:
var -> ptr -> tag2 -> tag1 -> ptr -> tag1 -> int
This patch implemented dwarf_loader support. If a pointer type contains
DW_TAG_LLVM_annotation tags, a new type btf_type_tag_ptr_type will be
created which will store the pointer tag itself and all
DW_TAG_LLVM_annotation tags. During recoding stage, the type chain will
be formed properly based on the above example.
An option "--skip_encoding_btf_type_tag" is added to disable
this new functionality.
[1] https://reviews.llvm.org/D111199
[2] https://reviews.llvm.org/D113222
[3] https://reviews.llvm.org/D113496
Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Cc: kernel-team@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Move DW_TAG_LLVM_annotation definition from dwarf_load.c to dutil.h as
it will be used later for btf_encoder.c. There is no functionality
change for this patch.
Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Cc: kernel-team@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Sync up to commit 94a49850c5ee61ea ("Makefile: enforce gnu89 standard").
This is needed to support BTF_KIND_TYPE_TAG.
Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Cc: kernel-team@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
$ pahole ~/c/split/foo.o
WARNING: DW_TAG_skeleton_unit used, please look for a .dwo file and use it instead.
A future version of pahole will support do this automagically.
$
Reported-by: https://twitter.com/trass3r
Link: https://github.com/acmel/dwarves/issues/23
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Now we know what that 0x4a thing is:
$ pahole ~/c/split/foo.o
die__process: DW_TAG_compile_unit, DW_TAG_type_unit or DW_TAG_partial_unit expected got skeleton_unit (0x4a)!
$
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
So that we can get it from user reports, i.e. instead of:
die__process: DW_TAG_compile_unit, DW_TAG_type_unit or DW_TAG_partial_unit expected got INVALID
We now get:
die__process: DW_TAG_compile_unit, DW_TAG_type_unit or DW_TAG_partial_unit expected got INVALID (0x4a)
That we can then look in dwarf.h and notice that there is this new:
DW_TAG_skeleton_unit = 0x4a,
Now lets go support it...
Reported-by: https://twitter.com/trass3r
Link: https://github.com/acmel/dwarves/issues/23
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
llvm commit ([1]) added support for btf_decl_tag attribute
with typedef declaration. Eventually, DW_TAG_LLVM_annotation
tag may appear inside dwarf typedef declaration tag.
kernel support for typedef BTF_KIND_DECL_TAG support
is introduced in [2]. There is no additional libbpf
change needed as the previous libbpf BTF_KIND_DECL_TAG
support is generic enough to cover new typedef use
cases.
This patch added parsing of DW_TAG_LLVM_annotation
for dwarf typedef decl.
$ cat t.c
$ clang -O2 -g -c t.c
$ llvm-dwarfdump --debug-info t.o
......
0x00000033: DW_TAG_typedef
DW_AT_type (0x00000051 "structure ")
DW_AT_name ("__t")
DW_AT_decl_file ("/home/yhs/t.c")
DW_AT_decl_line (3)
0x0000003e: DW_TAG_LLVM_annotation
DW_AT_name ("btf_decl_tag")
DW_AT_const_value ("tag1")
0x00000047: DW_TAG_LLVM_annotation
DW_AT_name ("btf_decl_tag")
DW_AT_const_value ("tag2")
0x00000050: NULL
Previously, pahole will issue a warning if typedef tag
contains any child tag. I removed this warning since
it is not true any more. Note that dwarf standard doesn't
prevent typedef decl tag from having nested tags.
In the future if we need to process any tag inside
typedef tag, we can just add code to process it.
[1] https://reviews.llvm.org/D110127
[2] https://lore.kernel.org/bpf/20211021195628.4018847-1-yhs@fb.com
Signed-off-by: Yonghong Song <yhs@fb.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Cc: kernel-team@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
When the alignment is larger than natural, it is very likely that the
source code was using the cacheline size. Therefore, use the cacheline
size when it would only result in increasing the alignment.
Committer tests:
This is one of the cases that this heuristic works well, 'struct Qdisc'
in the Linux kernel:
--- /tmp/btfdiff.dwarf.pXdgRU 2021-10-28 10:22:11.738200232 -0300
+++ /tmp/btfdiff.btf.bkDkdf 2021-10-28 10:22:11.925205061 -0300
@@ -107,7 +107,7 @@ struct Qdisc {
/* XXX 24 bytes hole, try to pack */
/* --- cacheline 2 boundary (128 bytes) --- */
- struct sk_buff_head gso_skb __attribute__((__aligned__(64))); /* 128 24 */
+ struct sk_buff_head gso_skb __attribute__((__aligned__(32))); /* 128 24 */
struct qdisc_skb_head q; /* 152 24 */
struct gnet_stats_basic_packed bstats; /* 176 16 */
/* --- cacheline 3 boundary (192 bytes) --- */
With this patch both DWARF and BTF generated output have the same
alignment.
Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Give access to struct conf_load in class__infer_alignment.
Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Remove the global variable and turn it into a member in struct
conf_fprintf, so that it can be used by other parts of the code.
Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Now that the alignment attributes are being inferred from BTF we need to
suppress it in btfdiff, as we can't infer for some cases, like when the
field is naturally aligned.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
BTF does not carry alignment information, but it carries the offset in
structs. This allows inferring the original alignment, yielding a C
header dump that is not identical to the original C code, but is
guaranteed to lead to the same memory layout.
This allows using the output of pahole in another program to poke at
memory, with the assurance that we will not read garbage.
Note: Since the alignment is inferred from the offset, it sometimes
happens that the offset was already correctly aligned, which means the
inferred alignment will be smaller than in the original source. This
does not impact the ability to read existing structs, but it could
impact creating such struct if other client code expects higher
alignment than the one exposed in the generated header.
Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
Cc: dwarves@vger.kernel.org
[ Split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
We'll use it in the BTF loader.
Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
[ Split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
We just need to record if we printed it for a member and if so, deduce
that from the number of spaces left to print before the end of line
comment (offset, size).
Fixes: a59459bb80 ("fprintf: Account inline type __aligned__ member types for spacing")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>