Skip to content

Commit bc380eb

Browse files
Delyan Kratunovanakryiko
authored andcommitted
libbpf: .text routines are subprograms in strict mode
Currently, libbpf considers a single routine in .text to be a program. This is particularly confusing when it comes to library objects - a single routine meant to be used as an extern will instead be considered a bpf_program. This patch hides this compatibility behavior behind the pre-existing SEC_NAME strict mode flag. Signed-off-by: Delyan Kratunov <delyank@fb.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/018de8d0d67c04bf436055270d35d394ba393505.1647473511.git.delyank@fb.com
1 parent 5a5c11e commit bc380eb

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,7 +3832,14 @@ static bool prog_is_subprog(const struct bpf_object *obj,
38323832
* .text programs are subprograms (even if they are not called from
38333833
* other programs), because libbpf never explicitly supported mixing
38343834
* SEC()-designated BPF programs and .text entry-point BPF programs.
3835+
*
3836+
* In libbpf 1.0 strict mode, we always consider .text
3837+
* programs to be subprograms.
38353838
*/
3839+
3840+
if (libbpf_mode & LIBBPF_STRICT_SEC_NAME)
3841+
return prog->sec_idx == obj->efile.text_shndx;
3842+
38363843
return prog->sec_idx == obj->efile.text_shndx && obj->nr_programs > 1;
38373844
}
38383845

tools/lib/bpf/libbpf_legacy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ enum libbpf_strict_mode {
5454
*
5555
* Note, in this mode the program pin path will be based on the
5656
* function name instead of section name.
57+
*
58+
* Additionally, routines in the .text section are always considered
59+
* sub-programs. Legacy behavior allows for a single routine in .text
60+
* to be a program.
5761
*/
5862
LIBBPF_STRICT_SEC_NAME = 0x04,
5963
/*

0 commit comments

Comments
 (0)