mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 17:36:06 +00:00

When BPF object files are linked with bpftool, every symbol must be accompanied by BTF info. Ensure that extern functions referenced by global variable initializers are included in BTF. The primary motivation is "static" initialization of PROG maps: ```c extern int elsewhere(struct xdp_md *); struct { __uint(type, BPF_MAP_TYPE_PROG_ARRAY); __uint(max_entries, 1); __type(key, int); __type(value, int); __array(values, int (struct xdp_md *)); } prog_map SEC(".maps") = { .values = { elsewhere } }; ``` BPF backend needs debug info to produce BTF. Debug info is not normally generated for external variables and functions. Previously, it was solved differently for variables (collecting variable declarations in ExternalDeclarations vector) and functions (logic invoked during codegen in CGExpr.cpp). This patch generalises ExternalDefclarations to include both function and variable declarations. This change ensures that function references are not missed no matter the context. Previously external functions referenced in constant expressions lacked debug info.
10 lines
374 B
C
10 lines
374 B
C
// RUN: %clang -g -target bpf -S -emit-llvm %s -o - | FileCheck %s
|
|
//
|
|
// When linking BPF object files via bpftool, BTF info is required for
|
|
// every symbol. BTF is generated from debug info. Ensure that debug info
|
|
// is emitted for extern functions referenced via variable initializers.
|
|
//
|
|
// CHECK: !DISubprogram(name: "fn"
|
|
extern void fn(void);
|
|
void (*pfn) (void) = &fn;
|