1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00
llvm-mirror/lib/Target/BPF
Yonghong Song f45d1b55bd [BPF] Add BTF Var and DataSec Support
Two new kinds, BTF_KIND_VAR and BTF_KIND_DATASEC, are added.

BTF_KIND_VAR has the following specification:
   btf_type.name: var name
   btf_type.info: type kind
   btf_type.type: var type
   // btf_type is followed by one u32
   u32: varinfo (currently, only 0 - static, 1 - global allocated in elf sections)

Not all globals are supported in this patch. The following globals are supported:
  . static variables with or without section attributes
  . global variables with section attributes

The inclusion of globals with section attributes
is for future potential extraction of key/value
type id's from map definition.

BTF_KIND_DATASEC has the following specification:
  btf_type.name: section name associated with variable or
                 one of .data/.bss/.readonly
  btf_type.info: type kind and vlen for # of variables
  btf_type.size: 0
  #vlen number of the following:
    u32: id of corresponding BTF_KIND_VAR
    u32: in-session offset of the var
    u32: the size of memory var occupied

At the time of debug info emission, the data section
size is unknown, so the btf_type.size = 0 for
BTF_KIND_DATASEC. The loader can patch it during
loading time.

The in-session offseet of the var is only available
for static variables. For global variables, the
loader neeeds to assign the global variable symbol value in
symbol table to in-section offset.

The size of memory is used to specify the amount of the
memory a variable occupies. Typically, it equals to
the type size, but for certain structures, e.g.,
  struct tt {
    int a;
    int b;
    char c[];
   };
   static volatile struct tt s2 = {3, 4, "abcdefghi"};
The static variable s2 has size of 20.

Note that for BTF_KIND_DATASEC name, the section name
does not contain object name. The compiler does have
input module name. For example, two cases below:
   . clang -target bpf -O2 -g -c test.c
     The compiler knows the input file (module) is test.c
     and can generate sec name like test.data/test.bss etc.
   . clang -target bpf -O2 -g -emit-llvm -c test.c -o - |
     llc -march=bpf -filetype=obj -o test.o
     The llc compiler has the input file as stdin, and
     would generate something like stdin.data/stdin.bss etc.
     which does not really make sense.

For any user specificed section name, e.g.,
  static volatile int a __attribute__((section("id1")));
  static volatile const int b __attribute__((section("id2")));
The DataSec with name "id1" and "id2" does not contain
information whether the section is readonly or not.
The loader needs to check the corresponding elf section
flags for such information.

A simple example:
  -bash-4.4$ cat t.c
  int g1;
  int g2 = 3;
  const int g3 = 4;
  static volatile int s1;
  struct tt {
   int a;
   int b;
   char c[];
  };
  static volatile struct tt s2 = {3, 4, "abcdefghi"};
  static volatile const int s3 = 4;
  int m __attribute__((section("maps"), used)) = 4;
  int test() { return g1 + g2 + g3 + s1 + s2.a + s3 + m; }
  -bash-4.4$ clang -target bpf -O2 -g -S t.c
Checking t.s, 4 BTF_KIND_VAR's are generated (s1, s2, s3 and m).
4 BTF_KIND_DATASEC's are generated with names
".data", ".bss", ".rodata" and "maps".

Signed-off-by: Yonghong Song <yhs@fb.com>

Differential Revision: https://reviews.llvm.org/D59441

llvm-svn: 356326
2019-03-16 15:36:31 +00:00
..
AsmParser Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Disassembler bpf: disassembler support for XADD under sub-register mode 2019-02-28 19:22:34 +00:00
InstPrinter Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MCTargetDesc Use bitset for assembler predicates 2019-03-11 17:04:35 +00:00
TargetInfo Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPF.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPF.td [BPF] add code-gen support for JMP32 instructions 2019-02-07 10:43:09 +00:00
BPFAsmPrinter.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFCallingConv.td Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFFrameLowering.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFFrameLowering.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFInstrFormats.td [BPF] add code-gen support for JMP32 instructions 2019-02-07 10:43:09 +00:00
BPFInstrInfo.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFInstrInfo.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFInstrInfo.td bpf: enable sub-register code-gen for XADD 2019-02-28 19:21:28 +00:00
BPFISelDAGToDAG.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFISelLowering.cpp [BPF] add code-gen support for JMP32 instructions 2019-02-07 10:43:09 +00:00
BPFISelLowering.h [BPF] add code-gen support for JMP32 instructions 2019-02-07 10:43:09 +00:00
BPFMCInstLower.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFMCInstLower.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFMIChecking.cpp bpf: enable sub-register code-gen for XADD 2019-02-28 19:21:28 +00:00
BPFMIPeephole.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFRegisterInfo.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFRegisterInfo.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFRegisterInfo.td Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFSelectionDAGInfo.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFSelectionDAGInfo.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFSubtarget.cpp [BPF] add code-gen support for JMP32 instructions 2019-02-07 10:43:09 +00:00
BPFSubtarget.h [BPF] add code-gen support for JMP32 instructions 2019-02-07 10:43:09 +00:00
BPFTargetMachine.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BPFTargetMachine.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BTF.def [BPF] Add BTF Var and DataSec Support 2019-03-16 15:36:31 +00:00
BTF.h [BPF] Add BTF Var and DataSec Support 2019-03-16 15:36:31 +00:00
BTFDebug.cpp [BPF] Add BTF Var and DataSec Support 2019-03-16 15:36:31 +00:00
BTFDebug.h [BPF] Add BTF Var and DataSec Support 2019-03-16 15:36:31 +00:00
CMakeLists.txt [BPF] Generate BTF DebugInfo under BPF target 2018-12-19 16:40:25 +00:00
LLVMBuild.txt Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00