loaders: Strip away volatile/const/restrict when fixing bitfields
btf_loader and ctf_loader didn't remove const/volatile/restrict, so
bitfields using modifiers were not adjusted properly.
This patch abstracts logic of stripping aways typedefs and access
modifiers into tag__strip_typedefs_and_modifiers, which handles any
interleaving of typedefs and modifiers. dwarf_loader was adapter to
reuse this function as well, instead of custom goto loop.
REPRO:
$ cat vc_map.c
typedef unsigned int u32;
typedef volatile u32 vu32;
typedef vu32 vu32_t;
typedef struct vc_map {
volatile unsigned int tx: 1;
vu32_t rx: 1;
void *x1, *x2;
} vc_map;
int main() {
struct vc_map s;
return 0;
}
BEFORE:
$ ~/pahole/build/pahole -F btf vc_map
struct vc_map {
volatile unsigned int tx:1; /* 0: 0 4 */
vu32_t rx:1; /* 0: 0 4 */
/* XXX 30 bits hole, try to pack */
/* XXX 4 bytes hole, try to pack */
void * x1; /* 8 8 */
void * x2; /* 16 8 */
/* size: 24, cachelines: 1, members: 4 */
/* sum members: 20, holes: 1, sum holes: 4 */
/* bit holes: 1, sum bit holes: 30 bits */
/* last cacheline: 24 bytes */
};
AFTER:
$ ~/pahole/build/pahole -F btf vc_map
struct vc_map {
volatile unsigned int tx:1; /* 0:31 4 */
vu32_t rx:1; /* 0:30 4 */
/* XXX 30 bits hole, try to pack */
/* XXX 4 bytes hole, try to pack */
void * x1; /* 8 8 */
void * x2; /* 16 8 */
/* size: 24, cachelines: 1, members: 4 */
/* sum members: 20, holes: 1, sum holes: 4 */
/* bit holes: 1, sum bit holes: 30 bits */
/* last cacheline: 24 bytes */
};
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
5 files changed