BPF: set .BTF and .BTF.ext section alignment to 4
authorYonghong Song <yhs@fb.com>
Tue, 19 Oct 2021 22:29:12 +0000 (15:29 -0700)
committerYonghong Song <yhs@fb.com>
Tue, 19 Oct 2021 23:26:01 +0000 (16:26 -0700)
commitcd40b5a71290bab313cc431fb9a90ac3f9f3fa02
tree28345fc660b18108ee2f894cfa877bdb16e76124
parentb6b7fe60a444e03387b0e8be31bc1742ead36b25
BPF: set .BTF and .BTF.ext section alignment to 4

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

Differential Revision: https://reviews.llvm.org/D112106
llvm/lib/Target/BPF/BTFDebug.cpp
llvm/test/CodeGen/BPF/BTF/align.ll [new file with mode: 0644]