[PATCH] D84002: BPF: generate .rodata BTF datasec for certain initialized local var's

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 22:43:41 PDT 2020


yonghong-song created this revision.
yonghong-song added reviewers: ast, anakryiko.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Currently, BTF datasec type for .rodata is generated only if there are 
user-defined readonly global variables which have debuginfo generated.

Certain readonly global variables may be generated from initialized
local variables. For example,

  void foo(const void *); 
  int test() {
    const struct {
      unsigned a[4];
      char b;
    } val = { .a = {2, 3, 4, 5}, .b = 6 };
    foo(&val);
    return 0;
  }

The clang will create a private linkage const global to store
the initialized value:

  @__const.test.val = private unnamed_addr constant %struct.anon
      { [4 x i32] [i32 2, i32 3, i32 4, i32 5], i8 6 }, align 4

This global variable eventually is put in .rodata ELF section.

If there is .rodata ELF section, libbpf expects a BTF .rodata
datasec as well even though it may be empty meaning there are no
global readonly variables with proper debuginfo. Martin reported
a bug where without this empty BTF .rodata datasec, the bpftool
gen will exit with an error.

This patch fixed the issue by generating .rodata BTF datasec
if there exists local var intial data which will result in
.rodata ELF section.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84002

Files:
  llvm/lib/Target/BPF/BTFDebug.cpp
  llvm/test/CodeGen/BPF/BTF/local-var-readonly-1.ll
  llvm/test/CodeGen/BPF/BTF/local-var-readonly-2.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84002.278663.patch
Type: text/x-patch
Size: 13384 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200717/383629f2/attachment.bin>


More information about the llvm-commits mailing list