1. 27 3月, 2021 5 次提交
  2. 26 3月, 2021 2 次提交
  3. 23 3月, 2021 1 次提交
  4. 20 3月, 2021 2 次提交
    • J
      libbpf: Fix BTF dump of pointer-to-array-of-struct · 901ee1d7
      Jean-Philippe Brucker 提交于
      The vmlinux.h generated from BTF is invalid when building
      drivers/phy/ti/phy-gmii-sel.c with clang:
      
      vmlinux.h:61702:27: error: array type has incomplete element type ‘struct reg_field’
      61702 |  const struct reg_field (*regfields)[3];
            |                           ^~~~~~~~~
      
      bpftool generates a forward declaration for this struct regfield, which
      compilers aren't happy about. Here's a simplified reproducer:
      
      	struct inner {
      		int val;
      	};
      	struct outer {
      		struct inner (*ptr_to_array)[2];
      	} A;
      
      After build with clang -> bpftool btf dump c -> clang/gcc:
      ./def-clang.h:11:23: error: array has incomplete element type 'struct inner'
              struct inner (*ptr_to_array)[2];
      
      Member ptr_to_array of struct outer is a pointer to an array of struct
      inner. In the DWARF generated by clang, struct outer appears before
      struct inner, so when converting BTF of struct outer into C, bpftool
      issues a forward declaration to struct inner. With GCC the DWARF info is
      reversed so struct inner gets fully defined.
      
      That forward declaration is not sufficient when compilers handle an
      array of the struct, even when it's only used through a pointer. Note
      that we can trigger the same issue with an intermediate typedef:
      
      	struct inner {
      	        int val;
      	};
      	typedef struct inner inner2_t[2];
      	struct outer {
      	        inner2_t *ptr_to_array;
      	} A;
      
      Becomes:
      
      	struct inner;
      	typedef struct inner inner2_t[2];
      
      And causes:
      
      ./def-clang.h:10:30: error: array has incomplete element type 'struct inner'
      	typedef struct inner inner2_t[2];
      
      To fix this, clear through_ptr whenever we encounter an intermediate
      array, to make the inner struct part of a strong link and force full
      declaration.
      
      Fixes: 351131b5 ("libbpf: add btf_dump API for BTF-to-C conversion")
      Signed-off-by: NJean-Philippe Brucker <jean-philippe@linaro.org>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210319112554.794552-2-jean-philippe@linaro.org
      901ee1d7
    • K
      libbpf: Add explicit padding to btf_dump_emit_type_decl_opts · ea24b195
      KP Singh 提交于
      Similar to
      https://lore.kernel.org/bpf/20210313210920.1959628-2-andrii@kernel.org/
      
      When DECLARE_LIBBPF_OPTS is used with inline field initialization, e.g:
      
        DECLARE_LIBBPF_OPTS(btf_dump_emit_type_decl_opts, opts,
          .field_name = var_ident,
          .indent_level = 2,
          .strip_mods = strip_mods,
        );
      
      and compiled in debug mode, the compiler generates code which
      leaves the padding uninitialized and triggers errors within libbpf APIs
      which require strict zero initialization of OPTS structs.
      
      Adding anonymous padding field fixes the issue.
      
      Fixes: 9f81654e ("libbpf: Expose BTF-to-C type declaration emitting API")
      Suggested-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NKP Singh <kpsingh@kernel.org>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20210319192117.2310658-1-kpsingh@kernel.org
      ea24b195
  5. 19 3月, 2021 7 次提交
    • A
      libbpf: Add BPF static linker BTF and BTF.ext support · 8fd27bf6
      Andrii Nakryiko 提交于
      Add .BTF and .BTF.ext static linking logic.
      
      When multiple BPF object files are linked together, their respective .BTF and
      .BTF.ext sections are merged together. BTF types are not just concatenated,
      but also deduplicated. .BTF.ext data is grouped by type (func info, line info,
      core_relos) and target section names, and then all the records are
      concatenated together, preserving their relative order. All the BTF type ID
      references and string offsets are updated as necessary, to take into account
      possibly deduplicated strings and types.
      
      BTF DATASEC types are handled specially. Their respective var_secinfos are
      accumulated separately in special per-section data and then final DATASEC
      types are emitted at the very end during bpf_linker__finalize() operation,
      just before emitting final ELF output file.
      
      BTF data can also provide "section annotations" for some extern variables.
      Such concept is missing in ELF, but BTF will have DATASEC types for such
      special extern datasections (e.g., .kconfig, .ksyms). Such sections are called
      "ephemeral" internally. Internally linker will keep metadata for each such
      section, collecting variables information, but those sections won't be emitted
      into the final ELF file.
      
      Also, given LLVM/Clang during compilation emits BTF DATASECS that are
      incomplete, missing section size and variable offsets for static variables,
      BPF static linker will initially fix up such DATASECs, using ELF symbols data.
      The final DATASECs will preserve section sizes and all variable offsets. This
      is handled correctly by libbpf already, so won't cause any new issues. On the
      other hand, it's actually a nice property to have a complete BTF data without
      runtime adjustments done during bpf_object__open() by libbpf. In that sense,
      BPF static linker is also a BTF normalizer.
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210318194036.3521577-8-andrii@kernel.org
      8fd27bf6
    • A
      libbpf: Add BPF static linker APIs · faf6ed32
      Andrii Nakryiko 提交于
      Introduce BPF static linker APIs to libbpf. BPF static linker allows to
      perform static linking of multiple BPF object files into a single combined
      resulting object file, preserving all the BPF programs, maps, global
      variables, etc.
      
      Data sections (.bss, .data, .rodata, .maps, maps, etc) with the same name are
      concatenated together. Similarly, code sections are also concatenated. All the
      symbols and ELF relocations are also concatenated in their respective ELF
      sections and are adjusted accordingly to the new object file layout.
      
      Static variables and functions are handled correctly as well, adjusting BPF
      instructions offsets to reflect new variable/function offset within the
      combined ELF section. Such relocations are referencing STT_SECTION symbols and
      that stays intact.
      
      Data sections in different files can have different alignment requirements, so
      that is taken care of as well, adjusting sizes and offsets as necessary to
      satisfy both old and new alignment requirements.
      
      DWARF data sections are stripped out, currently. As well as LLLVM_ADDRSIG
      section, which is ignored by libbpf in bpf_object__open() anyways. So, in
      a way, BPF static linker is an analogue to `llvm-strip -g`, which is a pretty
      nice property, especially if resulting .o file is then used to generate BPF
      skeleton.
      
      Original string sections are ignored and instead we construct our own set of
      unique strings using libbpf-internal `struct strset` API.
      
      To reduce the size of the patch, all the .BTF and .BTF.ext processing was
      moved into a separate patch.
      
      The high-level API consists of just 4 functions:
        - bpf_linker__new() creates an instance of BPF static linker. It accepts
          output filename and (currently empty) options struct;
        - bpf_linker__add_file() takes input filename and appends it to the already
          processed ELF data; it can be called multiple times, one for each BPF
          ELF object file that needs to be linked in;
        - bpf_linker__finalize() needs to be called to dump final ELF contents into
          the output file, specified when bpf_linker was created; after
          bpf_linker__finalize() is called, no more bpf_linker__add_file() and
          bpf_linker__finalize() calls are allowed, they will return error;
        - regardless of whether bpf_linker__finalize() was called or not,
          bpf_linker__free() will free up all the used resources.
      
      Currently, BPF static linker doesn't resolve cross-object file references
      (extern variables and/or functions). This will be added in the follow up patch
      set.
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210318194036.3521577-7-andrii@kernel.org
      faf6ed32
    • A
      libbpf: Add generic BTF type shallow copy API · 9af44bc5
      Andrii Nakryiko 提交于
      Add btf__add_type() API that performs shallow copy of a given BTF type from
      the source BTF into the destination BTF. All the information and type IDs are
      preserved, but all the strings encountered are added into the destination BTF
      and corresponding offsets are rewritten. BTF type IDs are assumed to be
      correct or such that will be (somehow) modified afterwards.
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210318194036.3521577-6-andrii@kernel.org
      9af44bc5
    • A
      libbpf: Extract internal set-of-strings datastructure APIs · 90d76d3e
      Andrii Nakryiko 提交于
      Extract BTF logic for maintaining a set of strings data structure, used for
      BTF strings section construction in writable mode, into separate re-usable
      API. This data structure is going to be used by bpf_linker to maintains ELF
      STRTAB section, which has the same layout as BTF strings section.
      Suggested-by: NAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210318194036.3521577-5-andrii@kernel.org
      90d76d3e
    • A
      libbpf: Rename internal memory-management helpers · 3b029e06
      Andrii Nakryiko 提交于
      Rename btf_add_mem() and btf_ensure_mem() helpers that abstract away details
      of dynamically resizable memory to use libbpf_ prefix, as they are not
      BTF-specific. No functional changes.
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210318194036.3521577-4-andrii@kernel.org
      3b029e06
    • A
      libbpf: Generalize BTF and BTF.ext type ID and strings iteration · f36e99a4
      Andrii Nakryiko 提交于
      Extract and generalize the logic to iterate BTF type ID and string offset
      fields within BTF types and .BTF.ext data. Expose this internally in libbpf
      for re-use by bpf_linker.
      
      Additionally, complete strings deduplication handling for BTF.ext (e.g., CO-RE
      access strings), which was previously missing. There previously was no
      case of deduplicating .BTF.ext data, but bpf_linker is going to use it.
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210318194036.3521577-3-andrii@kernel.org
      f36e99a4
    • A
      libbpf: Expose btf_type_by_id() internally · e14ef4bf
      Andrii Nakryiko 提交于
      btf_type_by_id() is internal-only convenience API returning non-const pointer
      to struct btf_type. Expose it outside of btf.c for re-use.
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210318194036.3521577-2-andrii@kernel.org
      e14ef4bf
  6. 18 3月, 2021 3 次提交
  7. 17 3月, 2021 1 次提交
  8. 16 3月, 2021 1 次提交
  9. 11 3月, 2021 2 次提交
  10. 09 3月, 2021 3 次提交
  11. 05 3月, 2021 3 次提交
  12. 04 3月, 2021 1 次提交
  13. 27 2月, 2021 2 次提交
  14. 13 2月, 2021 2 次提交
  15. 04 2月, 2021 1 次提交
  16. 26 1月, 2021 1 次提交
  17. 22 1月, 2021 1 次提交
  18. 14 1月, 2021 1 次提交
  19. 13 1月, 2021 1 次提交