Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

resolve_btfids: Change in-place update with raw binary output

Currently resolve_btfids updates .BTF_ids section of an ELF file
in-place, based on the contents of provided BTF, usually within the
same input file, and optionally a BTF base.

Change resolve_btfids behavior to enable BTF transformations as part
of its main operation. To achieve this, in-place ELF write in
resolve_btfids is replaced with generation of the following binaries:
* ${1}.BTF with .BTF section data
* ${1}.BTF_ids with .BTF_ids section data if it existed in ${1}
* ${1}.BTF.base with .BTF.base section data for out-of-tree modules

The execution of resolve_btfids and consumption of its output is
orchestrated by scripts/gen-btf.sh introduced in this patch.

The motivation for emitting binary data is that it allows simplifying
resolve_btfids implementation by delegating ELF update to the $OBJCOPY
tool [1], which is already widely used across the codebase.

There are two distinct paths for BTF generation and resolve_btfids
application in the kernel build: for vmlinux and for kernel modules.

For the vmlinux binary a .BTF section is added in a roundabout way to
ensure correct linking. The patch doesn't change this approach, only
the implementation is a little different.

Before this patch it worked as follows:

* pahole consumed .tmp_vmlinux1 [2] and added .BTF section with
llvm-objcopy [3] to it
* then everything except the .BTF section was stripped from .tmp_vmlinux1
into a .tmp_vmlinux1.bpf.o object [2], later linked into vmlinux
* resolve_btfids was executed later on vmlinux.unstripped [4],
updating it in-place

After this patch gen-btf.sh implements the following:

* pahole consumes .tmp_vmlinux1 and produces a *detached* file with
raw BTF data
* resolve_btfids consumes .tmp_vmlinux1 and detached BTF to produce
(potentially modified) .BTF, and .BTF_ids sections data
* a .tmp_vmlinux1.bpf.o object is then produced with objcopy copying
BTF output of resolve_btfids
* .BTF_ids data gets embedded into vmlinux.unstripped in
link-vmlinux.sh by objcopy --update-section

For kernel modules, creating a special .bpf.o file is not necessary,
and so embedding of sections data produced by resolve_btfids is
straightforward with objcopy.

With this patch an ELF file becomes effectively read-only within
resolve_btfids, which allows deleting elf_update() call and satellite
code (like compressed_section_fix [5]).

Endianness handling of .BTF_ids data is also changed. Previously the
"flags" part of the section was bswapped in sets_patch() [6], and then
Elf_Type was modified before elf_update() to signal to libelf that
bswap may be necessary. With this patch we explicitly bswap entire
data buffer on load and on dump.

[1] https://lore.kernel.org/bpf/131b4190-9c49-4f79-a99d-c00fac97fa44@linux.dev/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/link-vmlinux.sh?h=v6.18#n110
[3] https://git.kernel.org/pub/scm/devel/pahole/pahole.git/tree/btf_encoder.c?h=v1.31#n1803
[4] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/link-vmlinux.sh?h=v6.18#n284
[5] https://lore.kernel.org/bpf/20200819092342.259004-1-jolsa@kernel.org/
[6] https://lore.kernel.org/bpf/cover.1707223196.git.vmalik@redhat.com/

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Alan Maguire <alan.maguire@oracle.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/20251219181825.1289460-3-ihor.solodrai@linux.dev

authored by

Ihor Solodrai and committed by
Andrii Nakryiko
522397d0 014e1cdb

+328 -131
+1
MAINTAINERS
··· 4766 4766 F: net/sched/cls_bpf.c 4767 4767 F: samples/bpf/ 4768 4768 F: scripts/bpf_doc.py 4769 + F: scripts/gen-btf.sh 4769 4770 F: scripts/Makefile.btf 4770 4771 F: scripts/pahole-version.sh 4771 4772 F: tools/bpf/
+7 -5
scripts/Makefile.btf
··· 18 18 19 19 pahole-flags-$(call test-ge, $(pahole-ver), 130) += --btf_features=attributes 20 20 21 - ifneq ($(KBUILD_EXTMOD),) 22 - module-pahole-flags-$(call test-ge, $(pahole-ver), 128) += --btf_features=distilled_base 23 - endif 24 - 25 21 endif 26 22 27 23 pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) += --lang_exclude=rust 28 24 29 25 export PAHOLE_FLAGS := $(pahole-flags-y) 30 - export MODULE_PAHOLE_FLAGS := $(module-pahole-flags-y) 26 + 27 + resolve-btfids-flags-y := 28 + resolve-btfids-flags-$(CONFIG_WERROR) += --fatal_warnings 29 + resolve-btfids-flags-$(if $(KBUILD_EXTMOD),y) += --distill_base 30 + resolve-btfids-flags-$(if $(KBUILD_VERBOSE),y) += --verbose 31 + 32 + export RESOLVE_BTFIDS_FLAGS := $(resolve-btfids-flags-y)
+2 -3
scripts/Makefile.modfinal
··· 42 42 cmd_btf_ko = \ 43 43 if [ ! -f $(objtree)/vmlinux ]; then \ 44 44 printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \ 45 - else \ 46 - LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) $(MODULE_PAHOLE_FLAGS) --btf_base $(objtree)/vmlinux $@; \ 47 - $(RESOLVE_BTFIDS) -b $(objtree)/vmlinux $@; \ 45 + else \ 46 + $(srctree)/scripts/gen-btf.sh --btf_base $(objtree)/vmlinux $@; \ 48 47 fi; 49 48 50 49 # Same as newer-prereqs, but allows to exclude specified extra dependencies
+1 -1
scripts/Makefile.vmlinux
··· 71 71 vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o .vmlinux.export.o $(KBUILD_LDS) FORCE 72 72 +$(call if_changed_dep,link_vmlinux) 73 73 ifdef CONFIG_DEBUG_INFO_BTF 74 - vmlinux.unstripped: $(RESOLVE_BTFIDS) 74 + vmlinux.unstripped: $(RESOLVE_BTFIDS) $(srctree)/scripts/gen-btf.sh 75 75 endif 76 76 77 77 ifdef CONFIG_BUILDTIME_TABLE_SORT
+157
scripts/gen-btf.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + # Copyright (c) 2025 Meta Platforms, Inc. and affiliates. 4 + # 5 + # This script generates BTF data for the provided ELF file. 6 + # 7 + # Kernel BTF generation involves these conceptual steps: 8 + # 1. pahole generates BTF from DWARF data 9 + # 2. resolve_btfids applies kernel-specific btf2btf 10 + # transformations and computes data for .BTF_ids section 11 + # 3. the result gets linked/objcopied into the target binary 12 + # 13 + # How step (3) should be done differs between vmlinux, and 14 + # kernel modules, which is the primary reason for the existence 15 + # of this script. 16 + # 17 + # For modules the script expects vmlinux passed in as --btf_base. 18 + # Generated .BTF, .BTF.base and .BTF_ids sections become embedded 19 + # into the input ELF file with objcopy. 20 + # 21 + # For vmlinux the input file remains unchanged and two files are produced: 22 + # - ${1}.btf.o ready for linking into vmlinux 23 + # - ${1}.BTF_ids with .BTF_ids data blob 24 + # This output is consumed by scripts/link-vmlinux.sh 25 + 26 + set -e 27 + 28 + usage() 29 + { 30 + echo "Usage: $0 [--btf_base <file>] <target ELF file>" 31 + exit 1 32 + } 33 + 34 + BTF_BASE="" 35 + 36 + while [ $# -gt 0 ]; do 37 + case "$1" in 38 + --btf_base) 39 + BTF_BASE="$2" 40 + shift 2 41 + ;; 42 + -*) 43 + echo "Unknown option: $1" >&2 44 + usage 45 + ;; 46 + *) 47 + break 48 + ;; 49 + esac 50 + done 51 + 52 + if [ $# -ne 1 ]; then 53 + usage 54 + fi 55 + 56 + ELF_FILE="$1" 57 + shift 58 + 59 + is_enabled() { 60 + grep -q "^$1=y" ${objtree}/include/config/auto.conf 61 + } 62 + 63 + info() 64 + { 65 + printf " %-7s %s\n" "${1}" "${2}" 66 + } 67 + 68 + case "${KBUILD_VERBOSE}" in 69 + *1*) 70 + set -x 71 + ;; 72 + esac 73 + 74 + 75 + gen_btf_data() 76 + { 77 + info BTF "${ELF_FILE}" 78 + btf1="${ELF_FILE}.BTF.1" 79 + ${PAHOLE} -J ${PAHOLE_FLAGS} \ 80 + ${BTF_BASE:+--btf_base ${BTF_BASE}} \ 81 + --btf_encode_detached=${btf1} \ 82 + "${ELF_FILE}" 83 + 84 + info BTFIDS "${ELF_FILE}" 85 + ${RESOLVE_BTFIDS} ${RESOLVE_BTFIDS_FLAGS} \ 86 + ${BTF_BASE:+--btf_base ${BTF_BASE}} \ 87 + --btf ${btf1} "${ELF_FILE}" 88 + } 89 + 90 + gen_btf_o() 91 + { 92 + local btf_data=${ELF_FILE}.btf.o 93 + 94 + # Create ${btf_data} which contains just .BTF section but no symbols. Add 95 + # SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all 96 + # deletes all symbols including __start_BTF and __stop_BTF, which will 97 + # be redefined in the linker script. 98 + info OBJCOPY "${btf_data}" 99 + echo "" | ${CC} ${CLANG_FLAGS} -c -x c -o ${btf_data} - 100 + ${OBJCOPY} --add-section .BTF=${ELF_FILE}.BTF \ 101 + --set-section-flags .BTF=alloc,readonly ${btf_data} 102 + ${OBJCOPY} --only-section=.BTF --strip-all ${btf_data} 103 + 104 + # Change e_type to ET_REL so that it can be used to link final vmlinux. 105 + # GNU ld 2.35+ and lld do not allow an ET_EXEC input. 106 + if is_enabled CONFIG_CPU_BIG_ENDIAN; then 107 + et_rel='\0\1' 108 + else 109 + et_rel='\1\0' 110 + fi 111 + printf "${et_rel}" | dd of="${btf_data}" conv=notrunc bs=1 seek=16 status=none 112 + } 113 + 114 + embed_btf_data() 115 + { 116 + info OBJCOPY "${ELF_FILE}.BTF" 117 + ${OBJCOPY} --add-section .BTF=${ELF_FILE}.BTF ${ELF_FILE} 118 + 119 + # a module might not have a .BTF_ids or .BTF.base section 120 + local btf_base="${ELF_FILE}.BTF.base" 121 + if [ -f "${btf_base}" ]; then 122 + ${OBJCOPY} --add-section .BTF.base=${btf_base} ${ELF_FILE} 123 + fi 124 + local btf_ids="${ELF_FILE}.BTF_ids" 125 + if [ -f "${btf_ids}" ]; then 126 + ${OBJCOPY} --update-section .BTF_ids=${btf_ids} ${ELF_FILE} 127 + fi 128 + } 129 + 130 + cleanup() 131 + { 132 + rm -f "${ELF_FILE}.BTF.1" 133 + rm -f "${ELF_FILE}.BTF" 134 + if [ "${BTFGEN_MODE}" = "module" ]; then 135 + rm -f "${ELF_FILE}.BTF.base" 136 + rm -f "${ELF_FILE}.BTF_ids" 137 + fi 138 + } 139 + trap cleanup EXIT 140 + 141 + BTFGEN_MODE="vmlinux" 142 + if [ -n "${BTF_BASE}" ]; then 143 + BTFGEN_MODE="module" 144 + fi 145 + 146 + gen_btf_data 147 + 148 + case "${BTFGEN_MODE}" in 149 + vmlinux) 150 + gen_btf_o 151 + ;; 152 + module) 153 + embed_btf_data 154 + ;; 155 + esac 156 + 157 + exit 0
+143 -81
tools/bpf/resolve_btfids/main.c
··· 71 71 #include <fcntl.h> 72 72 #include <errno.h> 73 73 #include <linux/btf_ids.h> 74 + #include <linux/kallsyms.h> 74 75 #include <linux/rbtree.h> 75 76 #include <linux/zalloc.h> 76 77 #include <linux/err.h> 78 + #include <linux/limits.h> 77 79 #include <bpf/btf.h> 78 80 #include <bpf/libbpf.h> 79 81 #include <subcmd/parse-options.h> ··· 126 124 127 125 struct btf *btf; 128 126 struct btf *base_btf; 127 + bool distill_base; 129 128 130 129 struct { 131 130 int fd; ··· 327 324 return btf_id__add(root, id, BTF_ID_KIND_SYM); 328 325 } 329 326 330 - /* Older libelf.h and glibc elf.h might not yet define the ELF compression types. */ 331 - #ifndef SHF_COMPRESSED 332 - #define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */ 333 - #endif 334 - 335 - /* 336 - * The data of compressed section should be aligned to 4 337 - * (for 32bit) or 8 (for 64 bit) bytes. The binutils ld 338 - * sets sh_addralign to 1, which makes libelf fail with 339 - * misaligned section error during the update: 340 - * FAILED elf_update(WRITE): invalid section alignment 341 - * 342 - * While waiting for ld fix, we fix the compressed sections 343 - * sh_addralign value manualy. 344 - */ 345 - static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh) 327 + static void bswap_32_data(void *data, u32 nr_bytes) 346 328 { 347 - int expected = gelf_getclass(elf) == ELFCLASS32 ? 4 : 8; 329 + u32 cnt, i; 330 + u32 *ptr; 348 331 349 - if (!(sh->sh_flags & SHF_COMPRESSED)) 350 - return 0; 332 + cnt = nr_bytes / sizeof(u32); 333 + ptr = data; 351 334 352 - if (sh->sh_addralign == expected) 353 - return 0; 354 - 355 - pr_debug2(" - fixing wrong alignment sh_addralign %u, expected %u\n", 356 - sh->sh_addralign, expected); 357 - 358 - sh->sh_addralign = expected; 359 - 360 - if (gelf_update_shdr(scn, sh) == 0) { 361 - pr_err("FAILED cannot update section header: %s\n", 362 - elf_errmsg(-1)); 363 - return -1; 364 - } 365 - return 0; 335 + for (i = 0; i < cnt; i++) 336 + ptr[i] = bswap_32(ptr[i]); 366 337 } 367 338 368 339 static int elf_collect(struct object *obj) ··· 357 380 358 381 elf_version(EV_CURRENT); 359 382 360 - elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL); 383 + elf = elf_begin(fd, ELF_C_READ_MMAP_PRIVATE, NULL); 361 384 if (!elf) { 362 385 close(fd); 363 386 pr_err("FAILED cannot create ELF descriptor: %s\n", ··· 420 443 obj->efile.symbols_shndx = idx; 421 444 obj->efile.strtabidx = sh.sh_link; 422 445 } else if (!strcmp(name, BTF_IDS_SECTION)) { 446 + /* 447 + * If target endianness differs from host, we need to bswap32 448 + * the .BTF_ids section data on load, because .BTF_ids has 449 + * Elf_Type = ELF_T_BYTE, and so libelf returns data buffer in 450 + * the target endianness. We repeat this on dump. 451 + */ 452 + if (obj->efile.encoding != ELFDATANATIVE) { 453 + pr_debug("bswap_32 .BTF_ids data from target to host endianness\n"); 454 + bswap_32_data(data->d_buf, data->d_size); 455 + } 423 456 obj->efile.idlist = data; 424 457 obj->efile.idlist_shndx = idx; 425 458 obj->efile.idlist_addr = sh.sh_addr; 426 - } else if (!strcmp(name, BTF_BASE_ELF_SEC)) { 427 - /* If a .BTF.base section is found, do not resolve 428 - * BTF ids relative to vmlinux; resolve relative 429 - * to the .BTF.base section instead. btf__parse_split() 430 - * will take care of this once the base BTF it is 431 - * passed is NULL. 432 - */ 433 - obj->base_btf_path = NULL; 434 459 } 435 - 436 - if (compressed_section_fix(elf, scn, &sh)) 437 - return -1; 438 460 } 439 461 440 462 return 0; ··· 563 587 obj->base_btf = base_btf; 564 588 obj->btf = btf; 565 589 590 + if (obj->base_btf && obj->distill_base) { 591 + err = btf__distill_base(obj->btf, &base_btf, &btf); 592 + if (err) { 593 + pr_err("FAILED to distill base BTF: %s\n", strerror(errno)); 594 + goto out_err; 595 + } 596 + 597 + btf__free(obj->base_btf); 598 + btf__free(obj->btf); 599 + obj->base_btf = base_btf; 600 + obj->btf = btf; 601 + } 602 + 566 603 return 0; 567 604 568 605 out_err: 569 606 btf__free(base_btf); 570 607 btf__free(btf); 608 + obj->base_btf = NULL; 609 + obj->btf = NULL; 571 610 return err; 572 611 } 573 612 ··· 751 760 */ 752 761 BUILD_BUG_ON((u32 *)set8->pairs != &set8->pairs[0].id); 753 762 qsort(set8->pairs, set8->cnt, sizeof(set8->pairs[0]), cmp_id); 754 - 755 - /* 756 - * When ELF endianness does not match endianness of the 757 - * host, libelf will do the translation when updating 758 - * the ELF. This, however, corrupts SET8 flags which are 759 - * already in the target endianness. So, let's bswap 760 - * them to the host endianness and libelf will then 761 - * correctly translate everything. 762 - */ 763 - if (obj->efile.encoding != ELFDATANATIVE) { 764 - int i; 765 - 766 - set8->flags = bswap_32(set8->flags); 767 - for (i = 0; i < set8->cnt; i++) { 768 - set8->pairs[i].flags = 769 - bswap_32(set8->pairs[i].flags); 770 - } 771 - } 772 763 break; 773 764 default: 774 765 pr_err("Unexpected btf_id_kind %d for set '%s'\n", id->kind, id->name); ··· 766 793 767 794 static int symbols_patch(struct object *obj) 768 795 { 769 - off_t err; 770 - 771 796 if (__symbols_patch(obj, &obj->structs) || 772 797 __symbols_patch(obj, &obj->unions) || 773 798 __symbols_patch(obj, &obj->typedefs) || ··· 776 805 if (sets_patch(obj)) 777 806 return -1; 778 807 779 - /* Set type to ensure endian translation occurs. */ 780 - obj->efile.idlist->d_type = ELF_T_WORD; 808 + return 0; 809 + } 781 810 782 - elf_flagdata(obj->efile.idlist, ELF_C_SET, ELF_F_DIRTY); 811 + static int dump_raw_data(const char *out_path, const void *data, u32 size) 812 + { 813 + size_t written; 814 + FILE *file; 783 815 784 - err = elf_update(obj->efile.elf, ELF_C_WRITE); 785 - if (err < 0) { 786 - pr_err("FAILED elf_update(WRITE): %s\n", 787 - elf_errmsg(-1)); 816 + file = fopen(out_path, "wb"); 817 + if (!file) { 818 + pr_err("Couldn't open %s for writing\n", out_path); 819 + return -1; 788 820 } 789 821 790 - pr_debug("update %s for %s\n", 791 - err >= 0 ? "ok" : "failed", obj->path); 792 - return err < 0 ? -1 : 0; 822 + written = fwrite(data, 1, size, file); 823 + if (written != size) { 824 + pr_err("Failed to write data to %s\n", out_path); 825 + fclose(file); 826 + unlink(out_path); 827 + return -1; 828 + } 829 + 830 + fclose(file); 831 + pr_debug("Dumped %lu bytes of data to %s\n", size, out_path); 832 + 833 + return 0; 834 + } 835 + 836 + static int dump_raw_btf_ids(struct object *obj, const char *out_path) 837 + { 838 + Elf_Data *data = obj->efile.idlist; 839 + int err; 840 + 841 + if (!data || !data->d_buf) { 842 + pr_debug("%s has no BTF_ids data to dump\n", obj->path); 843 + return 0; 844 + } 845 + 846 + /* 847 + * If target endianness differs from host, we need to bswap32 the 848 + * .BTF_ids section data before dumping so that the output is in 849 + * target endianness. 850 + */ 851 + if (obj->efile.encoding != ELFDATANATIVE) { 852 + pr_debug("bswap_32 .BTF_ids data from host to target endianness\n"); 853 + bswap_32_data(data->d_buf, data->d_size); 854 + } 855 + 856 + err = dump_raw_data(out_path, data->d_buf, data->d_size); 857 + if (err) 858 + return -1; 859 + 860 + return 0; 861 + } 862 + 863 + static int dump_raw_btf(struct btf *btf, const char *out_path) 864 + { 865 + const void *raw_btf_data; 866 + u32 raw_btf_size; 867 + int err; 868 + 869 + raw_btf_data = btf__raw_data(btf, &raw_btf_size); 870 + if (!raw_btf_data) { 871 + pr_err("btf__raw_data() failed\n"); 872 + return -1; 873 + } 874 + 875 + err = dump_raw_data(out_path, raw_btf_data, raw_btf_size); 876 + if (err) 877 + return -1; 878 + 879 + return 0; 880 + } 881 + 882 + static inline int make_out_path(char *buf, u32 buf_sz, const char *in_path, const char *suffix) 883 + { 884 + int len = snprintf(buf, buf_sz, "%s%s", in_path, suffix); 885 + 886 + if (len < 0 || len >= buf_sz) { 887 + pr_err("Output path is too long: %s%s\n", in_path, suffix); 888 + return -E2BIG; 889 + } 890 + 891 + return 0; 793 892 } 794 893 795 894 static const char * const resolve_btfids_usage[] = { ··· 881 840 .sets = RB_ROOT, 882 841 }; 883 842 bool fatal_warnings = false; 843 + char out_path[PATH_MAX]; 844 + 884 845 struct option btfid_options[] = { 885 846 OPT_INCR('v', "verbose", &verbose, 886 847 "be more verbose (show errors, etc)"), ··· 892 849 "path of file providing base BTF"), 893 850 OPT_BOOLEAN(0, "fatal_warnings", &fatal_warnings, 894 851 "turn warnings into errors"), 852 + OPT_BOOLEAN(0, "distill_base", &obj.distill_base, 853 + "distill --btf_base and emit .BTF.base section data"), 895 854 OPT_END() 896 855 }; 897 856 int err = -1; ··· 905 860 906 861 obj.path = argv[0]; 907 862 863 + if (load_btf(&obj)) 864 + goto out; 865 + 908 866 if (elf_collect(&obj)) 909 867 goto out; 910 868 ··· 917 869 */ 918 870 if (obj.efile.idlist_shndx == -1 || 919 871 obj.efile.symbols_shndx == -1) { 920 - pr_debug("Cannot find .BTF_ids or symbols sections, nothing to do\n"); 921 - err = 0; 922 - goto out; 872 + pr_debug("Cannot find .BTF_ids or symbols sections, skip symbols resolution\n"); 873 + goto dump_btf; 923 874 } 924 875 925 876 if (symbols_collect(&obj)) 926 - goto out; 927 - 928 - if (load_btf(&obj)) 929 877 goto out; 930 878 931 879 if (symbols_resolve(&obj)) ··· 929 885 930 886 if (symbols_patch(&obj)) 931 887 goto out; 888 + 889 + err = make_out_path(out_path, sizeof(out_path), obj.path, BTF_IDS_SECTION); 890 + err = err ?: dump_raw_btf_ids(&obj, out_path); 891 + if (err) 892 + goto out; 893 + 894 + dump_btf: 895 + err = make_out_path(out_path, sizeof(out_path), obj.path, BTF_ELF_SEC); 896 + err = err ?: dump_raw_btf(obj.btf, out_path); 897 + if (err) 898 + goto out; 899 + 900 + if (obj.base_btf && obj.distill_base) { 901 + err = make_out_path(out_path, sizeof(out_path), obj.path, BTF_BASE_ELF_SEC); 902 + err = err ?: dump_raw_btf(obj.base_btf, out_path); 903 + if (err) 904 + goto out; 905 + } 932 906 933 907 if (!(fatal_warnings && warnings)) 934 908 err = 0;
+3
tools/testing/selftests/bpf/.gitignore
··· 45 45 xdp_hw_metadata 46 46 xdp_features 47 47 verification_cert.h 48 + *.BTF 49 + *.BTF_ids 50 + *.BTF.base
+6 -3
tools/testing/selftests/bpf/Makefile
··· 4 4 include ../../../scripts/Makefile.include 5 5 6 6 CXX ?= $(CROSS_COMPILE)g++ 7 + OBJCOPY ?= $(CROSS_COMPILE)objcopy 7 8 8 9 CURDIR := $(abspath .) 9 10 TOOLSDIR := $(abspath ../../..) ··· 654 653 | $(TRUNNER_OUTPUT)/%.test.d 655 654 $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@) 656 655 $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -MMD -MT $$@ -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F) 657 - $$(if $$(TEST_NEEDS_BTFIDS), \ 658 - $$(call msg,BTFIDS,$(TRUNNER_BINARY),$$@) \ 659 - $(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.bpf.o $$@) 656 + $$(if $$(TEST_NEEDS_BTFIDS), \ 657 + $$(call msg,BTFIDS,$(TRUNNER_BINARY),$$@) \ 658 + $(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.bpf.o $$@; \ 659 + $(OBJCOPY) --update-section .BTF_ids=$$@.BTF_ids $$@) 660 660 661 661 $(TRUNNER_TEST_OBJS:.o=.d): $(TRUNNER_OUTPUT)/%.test.d: \ 662 662 $(TRUNNER_TESTS_DIR)/%.c \ ··· 896 894 prog_tests/tests.h map_tests/tests.h verifier/tests.h \ 897 895 feature bpftool $(TEST_KMOD_TARGETS) \ 898 896 $(addprefix $(OUTPUT)/,*.o *.d *.skel.h *.lskel.h *.subskel.h \ 897 + *.BTF *.BTF_ids *.BTF.base \ 899 898 no_alu32 cpuv4 bpf_gcc \ 900 899 liburandom_read.so) \ 901 900 $(OUTPUT)/FEATURE-DUMP.selftests \
+2 -2
tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
··· 101 101 int type_id; 102 102 __u32 nr; 103 103 104 - btf = btf__parse_elf("btf_data.bpf.o", NULL); 104 + btf = btf__parse_raw("resolve_btfids.test.o.BTF"); 105 105 if (CHECK(libbpf_get_error(btf), "resolve", 106 - "Failed to load BTF from btf_data.bpf.o\n")) 106 + "Failed to load BTF from resolve_btfids.test.o.BTF\n")) 107 107 return -1; 108 108 109 109 nr = btf__type_cnt(btf);