tools/bpftool: Strip away modifiers from global variables

Reliably remove all the type modifiers from read-only (.rodata) global
variable definitions, including cases of inner field const modifiers and
arrays of const values.

Also modify one of selftests to ensure that const volatile struct doesn't
prevent user-space from modifying .rodata variable.

Fixes: 985ead416d ("bpftool: Add skeleton codegen command")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200713232409.3062144-3-andriin@fb.com
This commit is contained in:
Andrii Nakryiko 2020-07-13 16:24:09 -07:00 committed by Alexei Starovoitov
parent 7c819e7013
commit 0b20933d8c
4 changed files with 18 additions and 19 deletions

View file

@ -147,7 +147,7 @@ struct btf_dump_emit_type_decl_opts {
/* strip all the const/volatile/restrict mods */
bool strip_mods;
};
#define btf_dump_emit_type_decl_opts__last_field indent_level
#define btf_dump_emit_type_decl_opts__last_field strip_mods
LIBBPF_API int
btf_dump__emit_type_decl(struct btf_dump *d, __u32 id,