Skip to content

Commit

Permalink
btf: set .BTF section alignment to 16
Browse files Browse the repository at this point in the history
This is to avoid misaligned access when memory-mapping ELF sections.

Signed-off-by: Giuliano Procida <gprocida@google.com>
  • Loading branch information
myxoid committed Dec 2, 2020
1 parent 0fdee39 commit a3d940a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libbtf.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,14 @@ static int btf_elf__write(const char *filename, struct btf *btf)
goto unlink;
}

snprintf(cmd, sizeof(cmd), "%s --set-section-alignment .BTF=16 %s",
llvm_objcopy, filename);
if (system(cmd)) {
/* non-fatal, this is a nice-to-have and it's only supported from LLVM 10 */
fprintf(stderr, "%s: warning: failed to align .BTF section in '%s': %d!\n",
__func__, filename, errno);
}

err = 0;
unlink:
unlink(tmp_fn);
Expand Down

0 comments on commit a3d940a

Please sign in to comment.