On Mon, Jan 18, 2021 at 8:01 AM Giuliano Procida <gprocida@xxxxxxxxxx> wrote: > > This is to avoid misaligned access when memory-mapping ELF sections. > > Signed-off-by: Giuliano Procida <gprocida@xxxxxxxxxx> > --- > libbtf.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/libbtf.c b/libbtf.c > index 7552d8e..2f12d53 100644 > --- a/libbtf.c > +++ b/libbtf.c > @@ -797,6 +797,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); does it align inside the ELF file to 16 bytes, or does it request the linker to align it at 16 byte alignment in memory? Given .BTF section is not loadable, trying to understand the implications. > + if (system(cmd)) { Also curious, if objcopy emits error (saying that --set-section-alignment argument is not recognized), will that error be shown in stdout? or system() consumes it without redirecting it to stdout? > + /* 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); Probably better to emit this warning only in verbose mode, otherwise lots of people will start complaining that they get some new warnings from pahole. > + } > + > err = 0; > unlink: > unlink(tmp_fn); > -- > 2.30.0.284.gd98b1dd5eaa7-goog >