aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2020-08-13 13:49:44 -0700
committerAlexei Starovoitov <ast@kernel.org>2020-08-13 16:45:41 -0700
commit0f993845d723c87656552837b412994d6086f086 (patch)
treebf9c93f669615a61b4dbdcfa2e400fee402bdc73 /tools
parentselftests/bpf: Correct various core_reloc 64-bit assumptions (diff)
downloadlinux-dev-0f993845d723c87656552837b412994d6086f086.tar.xz
linux-dev-0f993845d723c87656552837b412994d6086f086.zip
tools/bpftool: Generate data section struct with conservative alignment
The comment in the code describes this in good details. Generate such a memory layout that would work both on 32-bit and 64-bit architectures for user-space. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200813204945.1020225-9-andriin@fb.com
Diffstat (limited to 'tools')
-rw-r--r--tools/bpf/bpftool/gen.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index db80e836816e..f61184653633 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -143,6 +143,20 @@ static int codegen_datasec_def(struct bpf_object *obj,
var_name, align);
return -EINVAL;
}
+ /* Assume 32-bit architectures when generating data section
+ * struct memory layout. Given bpftool can't know which target
+ * host architecture it's emitting skeleton for, we need to be
+ * conservative and assume 32-bit one to ensure enough padding
+ * bytes are generated for pointer and long types. This will
+ * still work correctly for 64-bit architectures, because in
+ * the worst case we'll generate unnecessary padding field,
+ * which on 64-bit architectures is not strictly necessary and
+ * would be handled by natural 8-byte alignment. But it still
+ * will be a correct memory layout, based on recorded offsets
+ * in BTF.
+ */
+ if (align > 4)
+ align = 4;
align_off = (off + align - 1) / align * align;
if (align_off != need_off) {