This is an archive of the discontinued LLVM Phabricator instance.

BPF: set .BTF and .BTF.ext section alignment to 4
ClosedPublic

Authored by yonghong-song on Oct 19 2021, 4:15 PM.

Details

Summary

Currently, .BTF and .BTF.ext has default alignment of 1.
For example,

$ cat t.c 
  int foo() { return 0; }
$ clang -target bpf -O2 -c -g t.c 
$ llvm-readelf -S t.o 
  ... 
  Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  ... 
  [ 7] .BTF              PROGBITS        0000000000000000 000167 00008b 00      0   0  1
  [ 8] .BTF.ext          PROGBITS        0000000000000000 0001f2 000050 00      0   0  1

But to have no misaligned data access, .BTF and .BTF.ext
actually requires alignment of 4. Misalignment is not an issue
for architecture like x64/arm64 as it can handle it well. But
some architectures like mips may incur a trap if .BTF/.BTF.ext
is not properly aligned.

This patch explicitly forced .BTF and .BTF.ext alignment to be 4.
For the above example, we will have

[ 7] .BTF              PROGBITS        0000000000000000 000168 00008b 00      0   0  4
[ 8] .BTF.ext          PROGBITS        0000000000000000 0001f4 000050 00      0   0  4

Diff Detail

Event Timeline

yonghong-song created this revision.Oct 19 2021, 4:15 PM
yonghong-song requested review of this revision.Oct 19 2021, 4:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2021, 4:15 PM
anakryiko accepted this revision.Oct 19 2021, 4:16 PM

Great, thank you!

This revision is now accepted and ready to land.Oct 19 2021, 4:16 PM
This revision was landed with ongoing or failed builds.Oct 19 2021, 4:26 PM
This revision was automatically updated to reflect the committed changes.