public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/113453] New: bpf: func_info and line_info missing in .BTF.ext
@ 2024-01-17 16:35 cupertino.miranda at oracle dot com
  2024-02-28 19:24 ` [Bug target/113453] " cvs-commit at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: cupertino.miranda at oracle dot com @ 2024-01-17 16:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113453

            Bug ID: 113453
           Summary: bpf: func_info and line_info missing in .BTF.ext
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cupertino.miranda at oracle dot com
  Target Milestone: ---

This is a placeholder for the implementation for func_info and line_info
content in .BTF.ext section, required in particular cases by the kernel
verifier.

For the particular case of func_info, it is a required when get identified as a
BPF_PSEUDO_FUNC.
# if (insn->src_reg == BPF_PSEUDO_FUNC) {
#   ...
#   if (!aux->func_info) {
#           verbose(env, "missing btf func_info\n");
#           return -EINVAL;
#   }

Which gets triggered by the following code:
#  /* mark the insn, so it's recognized by insn_is_pseudo_func() */
#   if (relo->type == RELO_SUBPROG_ADDR)
#           insn[0].src_reg = BPF_PSEUDO_FUNC;

Documentation for the content of .BTF.ext can be found in:
 - https://docs.kernel.org/bpf/btf.html

func_info keeps a record of all entry point addresses and section to any
BTF_KIND_FUNC entry. By traversing the func_info content the BPF infrastructure
can recover code location for any BTF_KIND_FUNC.

A few requirements to note for the implementation are, as mentioned in
documentation:

  for func_info:
  - func_info[0].insn_off must be 0.
  - the func_info insn_off is in strictly increasing order and matches bpf func
boundaries.
  for line_info:
  - the first insn in each func must have a line_info record pointing to it.
  - the line_info insn_off is in strictly increasing order.

Other observations are that function entry symbol relocation in the func_info
require that all relocations in func_info should be resolved within the object
file (resolved by gas), relative to the function section symbol.
This was observed in the content of the clang objects.

The assembly of one of this entries in clang .s file is:
  .long 7
  .long .Lfunc_begin2

Within the object one can see:
  38:   07 00 00 00 30 00 00 00         add %r0,48
                        3c: R_BPF_64_NODYLD32   tc

.Lfunc_begin2 is removed from the object, but its value is in-place resolved
with the value 0x30 (offset of .Lfunc_begin2 from tc) as the addend from its
section "tc", in this particular case.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug target/113453] bpf: func_info and line_info missing in .BTF.ext
  2024-01-17 16:35 [Bug target/113453] New: bpf: func_info and line_info missing in .BTF.ext cupertino.miranda at oracle dot com
@ 2024-02-28 19:24 ` cvs-commit at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-28 19:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113453

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Cupertino Miranda <cupermir@gcc.gnu.org>:

https://gcc.gnu.org/g:77142bdba485057550c5d849864948b0d20be8af

commit r14-9224-g77142bdba485057550c5d849864948b0d20be8af
Author: Cupertino Miranda <cupertino.miranda@oracle.com>
Date:   Mon Feb 12 17:46:03 2024 +0000

    bpf: implementation of func_info in .BTF.ext.

    Kernel verifier complains in some particular cases for missing func_info
    implementation in .BTF.ext. This patch implements it.

    Strings are cached locally in coreout.cc to avoid adding duplicated
    strings in the string list. This string deduplication should eventually
    be moved to the CTFC functions such that this happens widely.

    With this implementation, the CO-RE relocations information was also
    simplified and integrated with the FuncInfo structures.

    gcc/Changelog:

            PR target/113453
            * config/bpf/bpf.cc (bpf_function_prologue): Define target
            hook.
            * config/bpf/coreout.cc (brf_ext_info_section)
            (btf_ext_info): Move from coreout.h
            (btf_ext_funcinfo, btf_ext_lineinfo): Add struct.
            (bpf_core_reloc): Rename to btf_ext_core_reloc.
            (btf_ext): Add static variable.
            (btfext_info_sec_find_or_add, SEARCH_NODE_AND_RETURN)
            (bpf_create_or_find_funcinfo, bpt_create_core_reloc)
            (btf_ext_add_string, btf_funcinfo_type_callback)
            (btf_add_func_info_for, btf_validate_funcinfo)
            (btf_ext_info_len, output_btfext_func_info): Add function.
            (output_btfext_header, bpf_core_reloc_add)
            (output_btfext_core_relocs, btf_ext_init, btf_ext_output):
            Change to support new structs.
            * config/bpf/coreout.h (btf_ext_funcinfo, btf_ext_lineinfo):
            Move and change in coreout.cc.
            (btf_add_func_info_for, btf_ext_add_string): Add prototypes.

    gcc/testsuite/ChangeLog:
            PR target/113453
            * gcc.target/bpf/btfext-funcinfo-nocore.c: Add.
            * gcc.target/bpf/btfext-funcinfo.c: Add.
            * gcc.target/bpf/core-attr-5.c: Fix regexp.
            * gcc.target/bpf/core-attr-6.c: Fix regexp.
            * gcc.target/bpf/core-builtin-fieldinfo-offset-1.c: Fix regexp.
            * gcc.target/bpf/core-section-1.c: Fix regexp.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-28 19:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17 16:35 [Bug target/113453] New: bpf: func_info and line_info missing in .BTF.ext cupertino.miranda at oracle dot com
2024-02-28 19:24 ` [Bug target/113453] " cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).