forked from wangliu-iscas/gcc-patch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
btf: correct generation for extern funcs [PR106773]
The eBPF loader expects to find entries for functions declared as extern in the corresponding BTF_KIND_DATASEC record, but we were not generating these entries. This patch adds support for the 'extern' linkage of function types in BTF, and creates entries for for them BTF_KIND_DATASEC records as needed. PR target/106773 gcc/ * btfout.cc (get_section_name): New function. (btf_collect_datasec): Use it here. Process functions, marking them 'extern' and generating DATASEC entries for them as appropriate. Move creation of BTF_KIND_FUNC records to here... (btf_dtd_emit_preprocess_cb): ... from here. gcc/testsuite/ * gcc.dg/debug/btf/btf-datasec-2.c: New test. * gcc.dg/debug/btf/btf-function-6.c: New test. include/ * btf.h (struct btf_var_secinfo): Update comments with notes about extern functions.
- Loading branch information
1 parent
925d711
commit 0b3d88c
Showing
4 changed files
with
139 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Test BTF generation of DATASEC records for extern functions. | ||
Only functions declared extern should have entries in DATASEC records. */ | ||
|
||
/* { dg-do compile } */ | ||
/* { dg-options "-O0 -gbtf -dA" } */ | ||
|
||
/* Expect one DATASEC with vlen=1 (.foo_sec) and one with vlen=2 (.bar_sec) */ | ||
/* { dg-final { scan-assembler-times "0xf000002\[\t \]+\[^\n\]*btt_info" 1 } } */ | ||
/* { dg-final { scan-assembler-times "0xf000001\[\t \]+\[^\n\]*btt_info" 1 } } */ | ||
|
||
/* Function entries should have offset and size of 0 at compile time. */ | ||
/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bts_offset" 3 } } */ | ||
/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bts_size" 3 } } */ | ||
|
||
extern int foo (int a) __attribute__((section(".foo_sec"))); | ||
|
||
|
||
extern int bar (int b) __attribute__((section(".bar_sec"))); | ||
extern void chacha (void) __attribute__((section(".bar_sec"))); | ||
|
||
__attribute__((section(".foo_sec"))) | ||
void baz (int *x) | ||
{ | ||
chacha (); | ||
|
||
*x = foo (bar (*x)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* Test BTF extern linkage for functions. | ||
We expect to see one BTF_KIND_FUNC type with global linkage (foo), and | ||
one BTF_KIND_FUNC type with extern linkage (extfunc). */ | ||
|
||
/* { dg-do compile } */ | ||
/* { dg-options "-O0 -gbtf -dA" } */ | ||
|
||
/* { dg-final { scan-assembler-times "btt_info: kind=12, kflag=0, linkage=2" 1 } } */ | ||
/* { dg-final { scan-assembler-times "btt_info: kind=12, kflag=0, linkage=1" 1 } } */ | ||
|
||
extern int extfunc(int a, int b); | ||
|
||
int foo (int x) { | ||
|
||
int y = extfunc (x, x+1); | ||
|
||
return y; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters