Lines Matching +full:force +full:- +full:m1

1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
165 libbpf_print(LIBBPF_WARN, "libbpf: " fmt ": %s\n", ##__VA_ARGS__, elf_errmsg(-1))
198 free(linker->filename); in bpf_linker__free()
200 if (linker->elf) in bpf_linker__free()
201 elf_end(linker->elf); in bpf_linker__free()
203 if (linker->fd >= 0 && linker->fd_is_owned) in bpf_linker__free()
204 close(linker->fd); in bpf_linker__free()
206 strset__free(linker->strtab_strs); in bpf_linker__free()
208 btf__free(linker->btf); in bpf_linker__free()
209 btf_ext__free(linker->btf_ext); in bpf_linker__free()
211 for (i = 1; i < linker->sec_cnt; i++) { in bpf_linker__free()
212 struct dst_sec *sec = &linker->secs[i]; in bpf_linker__free()
214 free(sec->sec_name); in bpf_linker__free()
215 free(sec->raw_data); in bpf_linker__free()
216 free(sec->sec_vars); in bpf_linker__free()
218 free(sec->func_info.recs); in bpf_linker__free()
219 free(sec->line_info.recs); in bpf_linker__free()
220 free(sec->core_relo_info.recs); in bpf_linker__free()
222 free(linker->secs); in bpf_linker__free()
224 free(linker->glob_syms); in bpf_linker__free()
245 linker->filename = strdup(filename); in bpf_linker__new()
246 if (!linker->filename) { in bpf_linker__new()
247 err = -ENOMEM; in bpf_linker__new()
251 linker->fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); in bpf_linker__new()
252 if (linker->fd < 0) { in bpf_linker__new()
253 err = -errno; in bpf_linker__new()
257 linker->fd_is_owned = true; in bpf_linker__new()
267 return errno = -err, NULL; in bpf_linker__new()
292 linker->filename = strdup(filename); in bpf_linker__new_fd()
293 if (!linker->filename) { in bpf_linker__new_fd()
294 err = -ENOMEM; in bpf_linker__new_fd()
298 linker->fd = fd; in bpf_linker__new_fd()
299 linker->fd_is_owned = false; in bpf_linker__new_fd()
309 return errno = -err, NULL; in bpf_linker__new_fd()
314 struct dst_sec *secs = linker->secs, *sec; in add_dst_sec()
315 size_t new_cnt = linker->sec_cnt ? linker->sec_cnt + 1 : 2; in add_dst_sec()
322 memset(secs + linker->sec_cnt, 0, (new_cnt - linker->sec_cnt) * sizeof(*secs)); in add_dst_sec()
324 linker->secs = secs; in add_dst_sec()
325 linker->sec_cnt = new_cnt; in add_dst_sec()
327 sec = &linker->secs[new_cnt - 1]; in add_dst_sec()
328 sec->id = new_cnt - 1; in add_dst_sec()
329 sec->sec_name = strdup(sec_name); in add_dst_sec()
330 if (!sec->sec_name) in add_dst_sec()
338 struct dst_sec *symtab = &linker->secs[linker->symtab_sec_idx]; in add_new_sym()
340 size_t sym_cnt = symtab->sec_sz / sizeof(*sym); in add_new_sym()
342 syms = libbpf_reallocarray(symtab->raw_data, sym_cnt + 1, sizeof(*sym)); in add_new_sym()
349 symtab->raw_data = syms; in add_new_sym()
350 symtab->sec_sz += sizeof(*sym); in add_new_sym()
351 symtab->shdr->sh_size += sizeof(*sym); in add_new_sym()
352 symtab->data->d_size += sizeof(*sym); in add_new_sym()
366 linker->elf = elf_begin(linker->fd, ELF_C_WRITE, NULL); in init_output_elf()
367 if (!linker->elf) { in init_output_elf()
369 return -EINVAL; in init_output_elf()
373 linker->elf_hdr = elf64_newehdr(linker->elf); in init_output_elf()
374 if (!linker->elf_hdr) { in init_output_elf()
376 return -EINVAL; in init_output_elf()
379 linker->elf_hdr->e_machine = EM_BPF; in init_output_elf()
380 linker->elf_hdr->e_type = ET_REL; in init_output_elf()
382 linker->elf_hdr->e_ident[EI_DATA] = ELFDATANONE; in init_output_elf()
386 linker->strtab_strs = strset__new(INT_MAX, "", sizeof("")); in init_output_elf()
387 if (libbpf_get_error(linker->strtab_strs)) in init_output_elf()
388 return libbpf_get_error(linker->strtab_strs); in init_output_elf()
392 return -ENOMEM; in init_output_elf()
394 sec->scn = elf_newscn(linker->elf); in init_output_elf()
395 if (!sec->scn) { in init_output_elf()
397 return -EINVAL; in init_output_elf()
400 sec->shdr = elf64_getshdr(sec->scn); in init_output_elf()
401 if (!sec->shdr) in init_output_elf()
402 return -EINVAL; in init_output_elf()
404 sec->data = elf_newdata(sec->scn); in init_output_elf()
405 if (!sec->data) { in init_output_elf()
407 return -EINVAL; in init_output_elf()
410 str_off = strset__add_str(linker->strtab_strs, sec->sec_name); in init_output_elf()
414 sec->sec_idx = elf_ndxscn(sec->scn); in init_output_elf()
415 linker->elf_hdr->e_shstrndx = sec->sec_idx; in init_output_elf()
416 linker->strtab_sec_idx = sec->sec_idx; in init_output_elf()
418 sec->shdr->sh_name = str_off; in init_output_elf()
419 sec->shdr->sh_type = SHT_STRTAB; in init_output_elf()
420 sec->shdr->sh_flags = SHF_STRINGS; in init_output_elf()
421 sec->shdr->sh_offset = 0; in init_output_elf()
422 sec->shdr->sh_link = 0; in init_output_elf()
423 sec->shdr->sh_info = 0; in init_output_elf()
424 sec->shdr->sh_addralign = 1; in init_output_elf()
425 sec->shdr->sh_size = sec->sec_sz = 0; in init_output_elf()
426 sec->shdr->sh_entsize = 0; in init_output_elf()
431 return -ENOMEM; in init_output_elf()
433 sec->scn = elf_newscn(linker->elf); in init_output_elf()
434 if (!sec->scn) { in init_output_elf()
436 return -EINVAL; in init_output_elf()
439 sec->shdr = elf64_getshdr(sec->scn); in init_output_elf()
440 if (!sec->shdr) in init_output_elf()
441 return -EINVAL; in init_output_elf()
443 sec->data = elf_newdata(sec->scn); in init_output_elf()
444 if (!sec->data) { in init_output_elf()
446 return -EINVAL; in init_output_elf()
448 /* Ensure libelf translates byte-order of symbol records */ in init_output_elf()
449 sec->data->d_type = ELF_T_SYM; in init_output_elf()
451 str_off = strset__add_str(linker->strtab_strs, sec->sec_name); in init_output_elf()
455 sec->sec_idx = elf_ndxscn(sec->scn); in init_output_elf()
456 linker->symtab_sec_idx = sec->sec_idx; in init_output_elf()
458 sec->shdr->sh_name = str_off; in init_output_elf()
459 sec->shdr->sh_type = SHT_SYMTAB; in init_output_elf()
460 sec->shdr->sh_flags = 0; in init_output_elf()
461 sec->shdr->sh_offset = 0; in init_output_elf()
462 sec->shdr->sh_link = linker->strtab_sec_idx; in init_output_elf()
466 sec->shdr->sh_info = 0; in init_output_elf()
467 sec->shdr->sh_addralign = 8; in init_output_elf()
468 sec->shdr->sh_entsize = sizeof(Elf64_Sym); in init_output_elf()
471 linker->btf = btf__new_empty(); in init_output_elf()
472 err = libbpf_get_error(linker->btf); in init_output_elf()
476 /* add the special all-zero symbol */ in init_output_elf()
479 return -EINVAL; in init_output_elf()
481 init_sym->st_name = 0; in init_output_elf()
482 init_sym->st_info = 0; in init_output_elf()
483 init_sym->st_other = 0; in init_output_elf()
484 init_sym->st_shndx = SHN_UNDEF; in init_output_elf()
485 init_sym->st_value = 0; in init_output_elf()
486 init_sym->st_size = 0; in init_output_elf()
525 return libbpf_err(-EINVAL); in bpf_linker__add_file()
527 if (!linker->elf) in bpf_linker__add_file()
528 return libbpf_err(-EINVAL); in bpf_linker__add_file()
532 err = -errno; in bpf_linker__add_file()
549 return libbpf_err(-EINVAL); in bpf_linker__add_fd()
551 if (!linker->elf) in bpf_linker__add_fd()
552 return libbpf_err(-EINVAL); in bpf_linker__add_fd()
555 return libbpf_err(-EINVAL); in bpf_linker__add_fd()
569 return libbpf_err(-EINVAL); in bpf_linker__add_buf()
571 if (!linker->elf) in bpf_linker__add_buf()
572 return libbpf_err(-EINVAL); in bpf_linker__add_buf()
578 ret = -errno; in bpf_linker__add_buf()
587 ret = -errno; in bpf_linker__add_buf()
603 return strncmp(name, ".debug_", sizeof(".debug_") - 1) == 0; in is_dwarf_sec_name()
608 Elf64_Shdr *shdr = sec->shdr; in is_ignored_sec()
609 const char *name = sec->sec_name; in is_ignored_sec()
612 if (shdr->sh_type == SHT_STRTAB) in is_ignored_sec()
616 if (shdr->sh_type == SHT_LLVM_ADDRSIG) in is_ignored_sec()
620 if (shdr->sh_type == SHT_PROGBITS && shdr->sh_size == 0 && in is_ignored_sec()
621 strcmp(sec->sec_name, ".text") == 0) in is_ignored_sec()
625 if (is_dwarf_sec_name(sec->sec_name)) in is_ignored_sec()
628 if (strncmp(name, ".rel", sizeof(".rel") - 1) == 0) { in is_ignored_sec()
629 name += sizeof(".rel") - 1; in is_ignored_sec()
645 struct src_sec *secs = obj->secs, *sec; in add_src_sec()
646 size_t new_cnt = obj->sec_cnt ? obj->sec_cnt + 1 : 2; in add_src_sec()
653 memset(secs + obj->sec_cnt, 0, (new_cnt - obj->sec_cnt) * sizeof(*secs)); in add_src_sec()
655 obj->secs = secs; in add_src_sec()
656 obj->sec_cnt = new_cnt; in add_src_sec()
658 sec = &obj->secs[new_cnt - 1]; in add_src_sec()
659 sec->id = new_cnt - 1; in add_src_sec()
660 sec->sec_name = sec_name; in add_src_sec()
675 unsigned char link_byteorder = linker->elf_hdr->e_ident[EI_DATA]; in linker_load_obj_file()
684 pr_debug("linker: adding object file '%s'...\n", obj->filename); in linker_load_obj_file()
686 obj->elf = elf_begin(obj->fd, ELF_C_READ_MMAP, NULL); in linker_load_obj_file()
687 if (!obj->elf) { in linker_load_obj_file()
688 pr_warn_elf("failed to parse ELF file '%s'", obj->filename); in linker_load_obj_file()
689 return -EINVAL; in linker_load_obj_file()
692 /* Sanity check ELF file high-level properties */ in linker_load_obj_file()
693 ehdr = elf64_getehdr(obj->elf); in linker_load_obj_file()
695 pr_warn_elf("failed to get ELF header for %s", obj->filename); in linker_load_obj_file()
696 return -EINVAL; in linker_load_obj_file()
700 obj_byteorder = ehdr->e_ident[EI_DATA]; in linker_load_obj_file()
702 err = -EOPNOTSUPP; in linker_load_obj_file()
703 pr_warn("unknown byte order of ELF file %s\n", obj->filename); in linker_load_obj_file()
707 linker->elf_hdr->e_ident[EI_DATA] = obj_byteorder; in linker_load_obj_file()
708 linker->swapped_endian = obj_byteorder != host_byteorder; in linker_load_obj_file()
709 pr_debug("linker: set %s-endian output byte order\n", in linker_load_obj_file()
712 err = -EOPNOTSUPP; in linker_load_obj_file()
713 pr_warn("byte order mismatch with ELF file %s\n", obj->filename); in linker_load_obj_file()
717 if (ehdr->e_type != ET_REL in linker_load_obj_file()
718 || ehdr->e_machine != EM_BPF in linker_load_obj_file()
719 || ehdr->e_ident[EI_CLASS] != ELFCLASS64) { in linker_load_obj_file()
720 err = -EOPNOTSUPP; in linker_load_obj_file()
721 pr_warn_elf("unsupported kind of ELF file %s", obj->filename); in linker_load_obj_file()
725 if (elf_getshdrstrndx(obj->elf, &obj->shstrs_sec_idx)) { in linker_load_obj_file()
726 pr_warn_elf("failed to get SHSTRTAB section index for %s", obj->filename); in linker_load_obj_file()
727 return -EINVAL; in linker_load_obj_file()
731 while ((scn = elf_nextscn(obj->elf, scn)) != NULL) { in linker_load_obj_file()
738 sec_idx, obj->filename); in linker_load_obj_file()
739 return -EINVAL; in linker_load_obj_file()
742 sec_name = elf_strptr(obj->elf, obj->shstrs_sec_idx, shdr->sh_name); in linker_load_obj_file()
745 sec_idx, obj->filename); in linker_load_obj_file()
746 return -EINVAL; in linker_load_obj_file()
752 sec_idx, sec_name, obj->filename); in linker_load_obj_file()
753 return -EINVAL; in linker_load_obj_file()
758 return -ENOMEM; in linker_load_obj_file()
760 sec->scn = scn; in linker_load_obj_file()
761 sec->shdr = shdr; in linker_load_obj_file()
762 sec->data = data; in linker_load_obj_file()
763 sec->sec_idx = elf_ndxscn(scn); in linker_load_obj_file()
766 sec->skipped = true; in linker_load_obj_file()
770 switch (shdr->sh_type) { in linker_load_obj_file()
772 if (obj->symtab_sec_idx) { in linker_load_obj_file()
773 err = -EOPNOTSUPP; in linker_load_obj_file()
777 obj->symtab_sec_idx = sec_idx; in linker_load_obj_file()
784 obj->btf = btf__new(data->d_buf, shdr->sh_size); in linker_load_obj_file()
785 err = libbpf_get_error(obj->btf); in linker_load_obj_file()
788 obj->filename, errstr(err)); in linker_load_obj_file()
791 sec->skipped = true; in linker_load_obj_file()
795 obj->btf_ext = btf_ext__new(data->d_buf, shdr->sh_size); in linker_load_obj_file()
796 err = libbpf_get_error(obj->btf_ext); in linker_load_obj_file()
799 obj->filename, errstr(err)); in linker_load_obj_file()
802 sec->skipped = true; in linker_load_obj_file()
816 sec_idx, sec_name, obj->filename); in linker_load_obj_file()
817 err = -EINVAL; in linker_load_obj_file()
835 if (!obj->symtab_sec_idx) { in linker_sanity_check_elf()
836 pr_warn("ELF is missing SYMTAB section in %s\n", obj->filename); in linker_sanity_check_elf()
837 return -EINVAL; in linker_sanity_check_elf()
839 if (!obj->shstrs_sec_idx) { in linker_sanity_check_elf()
840 pr_warn("ELF is missing section headers STRTAB section in %s\n", obj->filename); in linker_sanity_check_elf()
841 return -EINVAL; in linker_sanity_check_elf()
844 for (i = 1; i < obj->sec_cnt; i++) { in linker_sanity_check_elf()
845 sec = &obj->secs[i]; in linker_sanity_check_elf()
847 if (sec->sec_name[0] == '\0') { in linker_sanity_check_elf()
848 pr_warn("ELF section #%zu has empty name in %s\n", sec->sec_idx, obj->filename); in linker_sanity_check_elf()
849 return -EINVAL; in linker_sanity_check_elf()
852 if (is_dwarf_sec_name(sec->sec_name)) in linker_sanity_check_elf()
855 if (sec->shdr->sh_addralign && !is_pow_of_2(sec->shdr->sh_addralign)) { in linker_sanity_check_elf()
856 pr_warn("ELF section #%zu alignment %llu is non pow-of-2 alignment in %s\n", in linker_sanity_check_elf()
857 sec->sec_idx, (long long unsigned)sec->shdr->sh_addralign, in linker_sanity_check_elf()
858 obj->filename); in linker_sanity_check_elf()
859 return -EINVAL; in linker_sanity_check_elf()
861 if (sec->shdr->sh_addralign != sec->data->d_align) { in linker_sanity_check_elf()
863 sec->sec_idx, (long long unsigned)sec->shdr->sh_addralign, in linker_sanity_check_elf()
864 (long long unsigned)sec->data->d_align, obj->filename); in linker_sanity_check_elf()
865 return -EINVAL; in linker_sanity_check_elf()
868 if (sec->shdr->sh_size != sec->data->d_size) { in linker_sanity_check_elf()
870 sec->sec_idx, (long long unsigned)sec->shdr->sh_size, in linker_sanity_check_elf()
871 (long long unsigned)sec->data->d_size, obj->filename); in linker_sanity_check_elf()
872 return -EINVAL; in linker_sanity_check_elf()
875 switch (sec->shdr->sh_type) { in linker_sanity_check_elf()
884 if (sec->shdr->sh_flags & SHF_EXECINSTR) { in linker_sanity_check_elf()
885 if (sec->shdr->sh_size % sizeof(struct bpf_insn) != 0) { in linker_sanity_check_elf()
887 sec->sec_idx, (long long unsigned)sec->shdr->sh_size, in linker_sanity_check_elf()
888 obj->filename); in linker_sanity_check_elf()
889 return -EINVAL; in linker_sanity_check_elf()
904 sec->sec_idx, sec->sec_name, (size_t)sec->shdr->sh_type, obj->filename); in linker_sanity_check_elf()
905 return -EINVAL; in linker_sanity_check_elf()
918 if (sec->shdr->sh_entsize != sizeof(Elf64_Sym)) in linker_sanity_check_elf_symtab()
919 return -EINVAL; in linker_sanity_check_elf_symtab()
920 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0) in linker_sanity_check_elf_symtab()
921 return -EINVAL; in linker_sanity_check_elf_symtab()
923 if (!sec->shdr->sh_link || sec->shdr->sh_link >= obj->sec_cnt) { in linker_sanity_check_elf_symtab()
925 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_symtab()
926 return -EINVAL; in linker_sanity_check_elf_symtab()
928 link_sec = &obj->secs[sec->shdr->sh_link]; in linker_sanity_check_elf_symtab()
929 if (link_sec->shdr->sh_type != SHT_STRTAB) { in linker_sanity_check_elf_symtab()
931 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_symtab()
932 return -EINVAL; in linker_sanity_check_elf_symtab()
935 n = sec->shdr->sh_size / sec->shdr->sh_entsize; in linker_sanity_check_elf_symtab()
936 sym = sec->data->d_buf; in linker_sanity_check_elf_symtab()
938 int sym_type = ELF64_ST_TYPE(sym->st_info); in linker_sanity_check_elf_symtab()
939 int sym_bind = ELF64_ST_BIND(sym->st_info); in linker_sanity_check_elf_symtab()
940 int sym_vis = ELF64_ST_VISIBILITY(sym->st_other); in linker_sanity_check_elf_symtab()
943 if (sym->st_name != 0 || sym->st_info != 0 in linker_sanity_check_elf_symtab()
944 || sym->st_other != 0 || sym->st_shndx != 0 in linker_sanity_check_elf_symtab()
945 || sym->st_value != 0 || sym->st_size != 0) { in linker_sanity_check_elf_symtab()
946 pr_warn("ELF sym #0 is invalid in %s\n", obj->filename); in linker_sanity_check_elf_symtab()
947 return -EINVAL; in linker_sanity_check_elf_symtab()
953 i, sec->sec_idx, sym_bind); in linker_sanity_check_elf_symtab()
954 return -EINVAL; in linker_sanity_check_elf_symtab()
958 i, sec->sec_idx, sym_vis); in linker_sanity_check_elf_symtab()
959 return -EINVAL; in linker_sanity_check_elf_symtab()
961 if (sym->st_shndx == 0) { in linker_sanity_check_elf_symtab()
963 || sym->st_value != 0 || sym->st_size != 0) { in linker_sanity_check_elf_symtab()
965 i, obj->filename); in linker_sanity_check_elf_symtab()
967 return -EINVAL; in linker_sanity_check_elf_symtab()
971 if (sym->st_shndx < SHN_LORESERVE && sym->st_shndx >= obj->sec_cnt) { in linker_sanity_check_elf_symtab()
973 i, sec->sec_idx, (size_t)sym->st_shndx, obj->filename); in linker_sanity_check_elf_symtab()
974 return -EINVAL; in linker_sanity_check_elf_symtab()
977 if (sym->st_value != 0) in linker_sanity_check_elf_symtab()
978 return -EINVAL; in linker_sanity_check_elf_symtab()
992 if (sec->shdr->sh_entsize != sizeof(Elf64_Rel)) in linker_sanity_check_elf_relos()
993 return -EINVAL; in linker_sanity_check_elf_relos()
994 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0) in linker_sanity_check_elf_relos()
995 return -EINVAL; in linker_sanity_check_elf_relos()
998 if (sec->shdr->sh_link != obj->symtab_sec_idx) { in linker_sanity_check_elf_relos()
1000 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_relos()
1001 return -EINVAL; in linker_sanity_check_elf_relos()
1005 if (!sec->shdr->sh_info || sec->shdr->sh_info >= obj->sec_cnt) { in linker_sanity_check_elf_relos()
1007 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename); in linker_sanity_check_elf_relos()
1008 return -EINVAL; in linker_sanity_check_elf_relos()
1010 link_sec = &obj->secs[sec->shdr->sh_info]; in linker_sanity_check_elf_relos()
1012 /* .rel<secname> -> <secname> pattern is followed */ in linker_sanity_check_elf_relos()
1013 if (strncmp(sec->sec_name, ".rel", sizeof(".rel") - 1) != 0 in linker_sanity_check_elf_relos()
1014 || strcmp(sec->sec_name + sizeof(".rel") - 1, link_sec->sec_name) != 0) { in linker_sanity_check_elf_relos()
1016 sec->sec_idx, obj->filename); in linker_sanity_check_elf_relos()
1017 return -EINVAL; in linker_sanity_check_elf_relos()
1021 if (link_sec->skipped) in linker_sanity_check_elf_relos()
1025 if (link_sec->shdr->sh_type != SHT_PROGBITS && link_sec->shdr->sh_type != SHT_NOBITS) { in linker_sanity_check_elf_relos()
1027 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename); in linker_sanity_check_elf_relos()
1028 return -EINVAL; in linker_sanity_check_elf_relos()
1032 n = sec->shdr->sh_size / sec->shdr->sh_entsize; in linker_sanity_check_elf_relos()
1033 relo = sec->data->d_buf; in linker_sanity_check_elf_relos()
1034 sym_sec = &obj->secs[obj->symtab_sec_idx]; in linker_sanity_check_elf_relos()
1036 size_t sym_idx = ELF64_R_SYM(relo->r_info); in linker_sanity_check_elf_relos()
1037 size_t sym_type = ELF64_R_TYPE(relo->r_info); in linker_sanity_check_elf_relos()
1042 i, sec->sec_idx, sym_type, obj->filename); in linker_sanity_check_elf_relos()
1043 return -EINVAL; in linker_sanity_check_elf_relos()
1046 if (!sym_idx || sym_idx * sizeof(Elf64_Sym) >= sym_sec->shdr->sh_size) { in linker_sanity_check_elf_relos()
1048 i, sec->sec_idx, sym_idx, obj->filename); in linker_sanity_check_elf_relos()
1049 return -EINVAL; in linker_sanity_check_elf_relos()
1052 if (link_sec->shdr->sh_flags & SHF_EXECINSTR) { in linker_sanity_check_elf_relos()
1053 if (relo->r_offset % sizeof(struct bpf_insn) != 0) { in linker_sanity_check_elf_relos()
1055 i, sec->sec_idx, sym_idx, obj->filename); in linker_sanity_check_elf_relos()
1056 return -EINVAL; in linker_sanity_check_elf_relos()
1069 return -EINVAL; in check_btf_type_id()
1082 return -EINVAL; in check_btf_str_off()
1092 if (!obj->btf) in linker_sanity_check_btf()
1095 n = btf__type_cnt(obj->btf); in linker_sanity_check_btf()
1100 t = btf_type_by_id(obj->btf, i); in linker_sanity_check_btf()
1107 return -EINVAL; in linker_sanity_check_btf()
1114 if (!btf__str_by_offset(obj->btf, *str_off)) in linker_sanity_check_btf()
1115 return -EINVAL; in linker_sanity_check_btf()
1126 if (!obj->btf_ext) in linker_sanity_check_btf_ext()
1130 if (!obj->btf) in linker_sanity_check_btf_ext()
1131 return -EINVAL; in linker_sanity_check_btf_ext()
1133 err = err ?: btf_ext_visit_type_ids(obj->btf_ext, check_btf_type_id, obj->btf); in linker_sanity_check_btf_ext()
1134 err = err ?: btf_ext_visit_str_offs(obj->btf_ext, check_btf_str_off, obj->btf); in linker_sanity_check_btf_ext()
1148 dst_sec->sec_sz = 0; in init_sec()
1149 dst_sec->sec_idx = 0; in init_sec()
1150 dst_sec->ephemeral = src_sec->ephemeral; in init_sec()
1153 if (src_sec->ephemeral) in init_sec()
1156 scn = elf_newscn(linker->elf); in init_sec()
1158 return -ENOMEM; in init_sec()
1161 return -ENOMEM; in init_sec()
1164 return -ENOMEM; in init_sec()
1166 dst_sec->scn = scn; in init_sec()
1167 dst_sec->shdr = shdr; in init_sec()
1168 dst_sec->data = data; in init_sec()
1169 dst_sec->sec_idx = elf_ndxscn(scn); in init_sec()
1171 name_off = strset__add_str(linker->strtab_strs, src_sec->sec_name); in init_sec()
1175 shdr->sh_name = name_off; in init_sec()
1176 shdr->sh_type = src_sec->shdr->sh_type; in init_sec()
1177 shdr->sh_flags = src_sec->shdr->sh_flags; in init_sec()
1178 shdr->sh_size = 0; in init_sec()
1183 shdr->sh_link = 0; in init_sec()
1184 shdr->sh_info = 0; in init_sec()
1185 shdr->sh_addralign = src_sec->shdr->sh_addralign; in init_sec()
1186 shdr->sh_entsize = src_sec->shdr->sh_entsize; in init_sec()
1188 data->d_type = src_sec->data->d_type; in init_sec()
1189 data->d_size = 0; in init_sec()
1190 data->d_buf = NULL; in init_sec()
1191 data->d_align = src_sec->data->d_align; in init_sec()
1192 data->d_off = 0; in init_sec()
1202 for (i = 1; i < linker->sec_cnt; i++) { in find_dst_sec_by_name()
1203 sec = &linker->secs[i]; in find_dst_sec_by_name()
1205 if (strcmp(sec->sec_name, sec_name) == 0) in find_dst_sec_by_name()
1214 if (dst->ephemeral || src->ephemeral) in secs_match()
1217 if (dst->shdr->sh_type != src->shdr->sh_type) { in secs_match()
1218 pr_warn("sec %s types mismatch\n", dst->sec_name); in secs_match()
1221 if (dst->shdr->sh_flags != src->shdr->sh_flags) { in secs_match()
1222 pr_warn("sec %s flags mismatch\n", dst->sec_name); in secs_match()
1225 if (dst->shdr->sh_entsize != src->shdr->sh_entsize) { in secs_match()
1226 pr_warn("sec %s entsize mismatch\n", dst->sec_name); in secs_match()
1235 if (dst_sec->sec_sz != src_sec->shdr->sh_size) in sec_content_is_same()
1237 if (memcmp(dst_sec->raw_data, src_sec->data->d_buf, dst_sec->sec_sz) != 0) in sec_content_is_same()
1244 if (!sec || sec->ephemeral) in is_exec_sec()
1246 return (sec->shdr->sh_type == SHT_PROGBITS) && in is_exec_sec()
1247 (sec->shdr->sh_flags & SHF_EXECINSTR); in is_exec_sec()
1270 if (src->ephemeral) in extend_sec()
1274 * ephemeral) and non-externs (map definitions). So it's possible that in extend_sec()
1275 * it has to be "upgraded" from ephemeral to non-ephemeral when the in extend_sec()
1276 * first non-ephemeral entity appears. In such case, we add ELF in extend_sec()
1279 if (dst->ephemeral) { in extend_sec()
1285 dst_align = dst->shdr->sh_addralign; in extend_sec()
1286 src_align = src->shdr->sh_addralign; in extend_sec()
1292 dst_align_sz = (dst->sec_sz + dst_align - 1) / dst_align * dst_align; in extend_sec()
1294 /* no need to re-align final size */ in extend_sec()
1295 dst_final_sz = dst_align_sz + src->shdr->sh_size; in extend_sec()
1297 if (src->shdr->sh_type != SHT_NOBITS) { in extend_sec()
1298 tmp = realloc(dst->raw_data, dst_final_sz); in extend_sec()
1300 * 1. When dst->raw_data is NULL it returns: in extend_sec()
1302 * 2. When dst->raw_data is not-NULL it frees dst->raw_data and returns NULL, in extend_sec()
1307 * dst->raw_data would be freed again in bpf_linker__free(). in extend_sec()
1312 return -ENOMEM; in extend_sec()
1313 dst->raw_data = tmp; in extend_sec()
1316 memset(dst->raw_data + dst->sec_sz, 0, dst_align_sz - dst->sec_sz); in extend_sec()
1318 memcpy(dst->raw_data + dst_align_sz, src->data->d_buf, src->shdr->sh_size); in extend_sec()
1320 /* convert added bpf insns to native byte-order */ in extend_sec()
1321 if (linker->swapped_endian && is_exec_sec(dst)) in extend_sec()
1322 exec_sec_bswap(dst->raw_data + dst_align_sz, src->shdr->sh_size); in extend_sec()
1325 dst->sec_sz = dst_final_sz; in extend_sec()
1326 dst->shdr->sh_size = dst_final_sz; in extend_sec()
1327 dst->data->d_size = dst_final_sz; in extend_sec()
1329 dst->shdr->sh_addralign = dst_align; in extend_sec()
1330 dst->data->d_align = dst_align; in extend_sec()
1332 src->dst_off = dst_align_sz; in extend_sec()
1339 if (!sec || sec->skipped) in is_data_sec()
1342 if (sec->ephemeral) in is_data_sec()
1344 return sec->shdr->sh_type == SHT_PROGBITS || sec->shdr->sh_type == SHT_NOBITS; in is_data_sec()
1349 if (!sec || sec->skipped || sec->ephemeral) in is_relo_sec()
1351 return sec->shdr->sh_type == SHT_REL; in is_relo_sec()
1358 for (i = 1; i < obj->sec_cnt; i++) { in linker_append_sec_data()
1362 src_sec = &obj->secs[i]; in linker_append_sec_data()
1366 dst_sec = find_dst_sec_by_name(linker, src_sec->sec_name); in linker_append_sec_data()
1368 dst_sec = add_dst_sec(linker, src_sec->sec_name); in linker_append_sec_data()
1370 return -ENOMEM; in linker_append_sec_data()
1373 pr_warn("failed to init section '%s'\n", src_sec->sec_name); in linker_append_sec_data()
1378 pr_warn("ELF sections %s are incompatible\n", src_sec->sec_name); in linker_append_sec_data()
1379 return -1; in linker_append_sec_data()
1383 if (strcmp(src_sec->sec_name, "license") == 0 in linker_append_sec_data()
1384 || strcmp(src_sec->sec_name, "version") == 0) { in linker_append_sec_data()
1386 pr_warn("non-identical contents of section '%s' are not supported\n", src_sec->sec_name); in linker_append_sec_data()
1387 return -EINVAL; in linker_append_sec_data()
1389 src_sec->skipped = true; in linker_append_sec_data()
1390 src_sec->dst_id = dst_sec->id; in linker_append_sec_data()
1396 src_sec->dst_id = dst_sec->id; in linker_append_sec_data()
1408 struct src_sec *symtab = &obj->secs[obj->symtab_sec_idx]; in linker_append_elf_syms()
1409 Elf64_Sym *sym = symtab->data->d_buf; in linker_append_elf_syms()
1410 int i, n = symtab->shdr->sh_size / symtab->shdr->sh_entsize, err; in linker_append_elf_syms()
1411 int str_sec_idx = symtab->shdr->sh_link; in linker_append_elf_syms()
1414 obj->sym_map = calloc(n + 1, sizeof(*obj->sym_map)); in linker_append_elf_syms()
1415 if (!obj->sym_map) in linker_append_elf_syms()
1416 return -ENOMEM; in linker_append_elf_syms()
1419 /* We already validated all-zero symbol #0 and we already in linker_append_elf_syms()
1425 sym_name = elf_strptr(obj->elf, str_sec_idx, sym->st_name); in linker_append_elf_syms()
1427 pr_warn("can't fetch symbol name for symbol #%d in '%s'\n", i, obj->filename); in linker_append_elf_syms()
1428 return -EINVAL; in linker_append_elf_syms()
1441 struct dst_sec *symtab = &linker->secs[linker->symtab_sec_idx]; in get_sym_by_idx()
1442 Elf64_Sym *syms = symtab->raw_data; in get_sym_by_idx()
1453 for (i = 0; i < linker->glob_sym_cnt; i++) { in find_glob_sym()
1454 glob_sym = &linker->glob_syms[i]; in find_glob_sym()
1455 name = strset__data(linker->strtab_strs) + glob_sym->name_off; in find_glob_sym()
1468 syms = libbpf_reallocarray(linker->glob_syms, linker->glob_sym_cnt + 1, in add_glob_sym()
1469 sizeof(*linker->glob_syms)); in add_glob_sym()
1473 sym = &syms[linker->glob_sym_cnt]; in add_glob_sym()
1475 sym->var_idx = -1; in add_glob_sym()
1477 linker->glob_syms = syms; in add_glob_sym()
1478 linker->glob_sym_cnt++; in add_glob_sym()
1499 n1 = btf__str_by_offset(btf1, t1->name_off); in glob_sym_btf_matches()
1500 n2 = btf__str_by_offset(btf2, t2->name_off); in glob_sym_btf_matches()
1539 n1 = btf__str_by_offset(btf1, t1->name_off); in glob_sym_btf_matches()
1540 n2 = btf__str_by_offset(btf2, t2->name_off); in glob_sym_btf_matches()
1560 if (t1->size != t2->size) { in glob_sym_btf_matches()
1562 sym_name, btf_kind_str(t1), n1, t1->size, t2->size); in glob_sym_btf_matches()
1572 id1 = t1->type; in glob_sym_btf_matches()
1573 id2 = t2->type; in glob_sym_btf_matches()
1577 id1 = btf_array(t1)->type; in glob_sym_btf_matches()
1578 id2 = btf_array(t2)->type; in glob_sym_btf_matches()
1589 id1 = t1->type; in glob_sym_btf_matches()
1590 id2 = t2->type; in glob_sym_btf_matches()
1594 is_static1 = btf_var(t1)->linkage == BTF_VAR_STATIC; in glob_sym_btf_matches()
1595 is_static2 = btf_var(t2)->linkage == BTF_VAR_STATIC; in glob_sym_btf_matches()
1601 id1 = t1->type; in glob_sym_btf_matches()
1602 id2 = t2->type; in glob_sym_btf_matches()
1606 const struct btf_member *m1, *m2; in glob_sym_btf_matches() local
1618 m1 = btf_members(t1); in glob_sym_btf_matches()
1620 for (i = 0; i < n; i++, m1++, m2++) { in glob_sym_btf_matches()
1621 n1 = btf__str_by_offset(btf1, m1->name_off); in glob_sym_btf_matches()
1622 n2 = btf__str_by_offset(btf2, m2->name_off); in glob_sym_btf_matches()
1628 if (m1->offset != m2->offset) { in glob_sym_btf_matches()
1633 if (!glob_sym_btf_matches(sym_name, exact, btf1, m1->type, btf2, m2->type)) in glob_sym_btf_matches()
1640 const struct btf_param *m1, *m2; in glob_sym_btf_matches() local
1649 m1 = btf_params(t1); in glob_sym_btf_matches()
1651 for (i = 0; i < n; i++, m1++, m2++) { in glob_sym_btf_matches()
1653 if (!glob_sym_btf_matches(sym_name, exact, btf1, m1->type, btf2, m2->type)) in glob_sym_btf_matches()
1658 id1 = t1->type; in glob_sym_btf_matches()
1659 id2 = t2->type; in glob_sym_btf_matches()
1687 if (main_def->map_type != extra_def->map_type) { in map_defs_match()
1693 if (main_def->key_size != extra_def->key_size) { in map_defs_match()
1697 if (!!main_def->key_type_id != !!extra_def->key_type_id) { in map_defs_match()
1701 if ((main_def->parts & MAP_DEF_KEY_TYPE) in map_defs_match()
1703 main_btf, main_def->key_type_id, in map_defs_match()
1704 extra_btf, extra_def->key_type_id)) { in map_defs_match()
1710 if (main_def->value_size != extra_def->value_size) { in map_defs_match()
1714 if (!!main_def->value_type_id != !!extra_def->value_type_id) { in map_defs_match()
1718 if ((main_def->parts & MAP_DEF_VALUE_TYPE) in map_defs_match()
1720 main_btf, main_def->value_type_id, in map_defs_match()
1721 extra_btf, extra_def->value_type_id)) { in map_defs_match()
1726 if (main_def->max_entries != extra_def->max_entries) { in map_defs_match()
1730 if (main_def->map_flags != extra_def->map_flags) { in map_defs_match()
1734 if (main_def->numa_node != extra_def->numa_node) { in map_defs_match()
1738 if (main_def->pinning != extra_def->pinning) { in map_defs_match()
1743 if ((main_def->parts & MAP_DEF_INNER_MAP) != (extra_def->parts & MAP_DEF_INNER_MAP)) { in map_defs_match()
1748 if (main_def->parts & MAP_DEF_INNER_MAP) { in map_defs_match()
1774 t = btf__type_by_id(obj->btf, btf_id); in glob_map_defs_match()
1779 t = skip_mods_and_typedefs(obj->btf, t->type, NULL); in glob_map_defs_match()
1781 err = parse_btf_map_def(sym_name, obj->btf, t, true /*strict*/, &src_def, &src_inner_def); in glob_map_defs_match()
1787 /* re-parse existing map definition */ in glob_map_defs_match()
1788 t = btf__type_by_id(linker->btf, glob_sym->btf_id); in glob_map_defs_match()
1789 t = skip_mods_and_typedefs(linker->btf, t->type, NULL); in glob_map_defs_match()
1790 err = parse_btf_map_def(sym_name, linker->btf, t, true /*strict*/, &dst_def, &dst_inner_def); in glob_map_defs_match()
1801 return map_defs_match(sym_name, linker->btf, &dst_def, &dst_inner_def, in glob_map_defs_match()
1802 obj->btf, &src_def, &src_inner_def); in glob_map_defs_match()
1814 if (!glob_sym->btf_id || !btf_id) { in glob_syms_match()
1819 src_t = btf__type_by_id(obj->btf, btf_id); in glob_syms_match()
1827 if (glob_sym->sec_id && strcmp(linker->secs[glob_sym->sec_id].sec_name, MAPS_ELF_SEC) == 0) in glob_syms_match()
1831 linker->btf, glob_sym->btf_id, obj->btf, btf_id)) in glob_syms_match()
1839 return (btf_is_var(t) && btf_var(t)->linkage != BTF_VAR_STATIC) in btf_is_non_static()
1851 if (!obj->btf) { in find_glob_sym_btf()
1852 pr_warn("failed to find BTF info for object '%s'\n", obj->filename); in find_glob_sym_btf()
1853 return -EINVAL; in find_glob_sym_btf()
1856 n = btf__type_cnt(obj->btf); in find_glob_sym_btf()
1858 t = btf__type_by_id(obj->btf, i); in find_glob_sym_btf()
1864 name = btf__str_by_offset(obj->btf, t->name_off); in find_glob_sym_btf()
1878 t = btf__type_by_id(obj->btf, vi->type); in find_glob_sym_btf()
1879 name = btf__str_by_offset(obj->btf, t->name_off); in find_glob_sym_btf()
1883 if (btf_is_var(t) && btf_var(t)->linkage == BTF_VAR_STATIC) in find_glob_sym_btf()
1888 if (btf_id && btf_id != vi->type) { in find_glob_sym_btf()
1890 sym_name, btf_id, vi->type); in find_glob_sym_btf()
1891 return -EINVAL; in find_glob_sym_btf()
1895 *out_btf_id = vi->type; in find_glob_sym_btf()
1901 /* free-floating extern or global FUNC */ in find_glob_sym_btf()
1909 return -ENOENT; in find_glob_sym_btf()
1917 for (i = 1; i < obj->sec_cnt; i++) { in find_src_sec_by_name()
1918 sec = &obj->secs[i]; in find_src_sec_by_name()
1920 if (strcmp(sec->sec_name, sec_name) == 0) in find_src_sec_by_name()
1940 btf_var(dst_t)->linkage = BTF_VAR_GLOBAL_ALLOCATED; in complete_extern_btf_info()
1944 dst_t->info = btf_type_info(BTF_KIND_FUNC, BTF_FUNC_GLOBAL, 0); in complete_extern_btf_info()
1947 src_t = btf_type_by_id(src_btf, src_t->type); in complete_extern_btf_info()
1948 dst_t = btf_type_by_id(dst_btf, dst_t->type); in complete_extern_btf_info()
1964 if (!src_p->name_off) in complete_extern_btf_info()
1968 s = btf__str_by_offset(src_btf, src_p->name_off); in complete_extern_btf_info()
1972 dst_p->name_off = off; in complete_extern_btf_info()
1979 sym->st_info = ELF64_ST_INFO(sym_bind, ELF64_ST_TYPE(sym->st_info)); in sym_update_bind()
1984 sym->st_info = ELF64_ST_INFO(ELF64_ST_BIND(sym->st_info), sym_type); in sym_update_type()
1992 sym->st_other &= ~0x03; in sym_update_visibility()
1993 sym->st_other |= sym_vis; in sym_update_visibility()
2008 sym_type = ELF64_ST_TYPE(sym->st_info); in linker_append_elf_sym()
2009 sym_bind = ELF64_ST_BIND(sym->st_info); in linker_append_elf_sym()
2010 sym_vis = ELF64_ST_VISIBILITY(sym->st_other); in linker_append_elf_sym()
2011 sym_is_extern = sym->st_shndx == SHN_UNDEF; in linker_append_elf_sym()
2014 if (!obj->btf) { in linker_append_elf_sym()
2016 return -ENOTSUP; in linker_append_elf_sym()
2018 } else if (sym->st_shndx < SHN_LORESERVE) { in linker_append_elf_sym()
2019 src_sec = &obj->secs[sym->st_shndx]; in linker_append_elf_sym()
2020 if (src_sec->skipped) in linker_append_elf_sym()
2022 dst_sec = &linker->secs[src_sec->dst_id]; in linker_append_elf_sym()
2025 if (sym_type == STT_SECTION && dst_sec->sec_sym_idx) { in linker_append_elf_sym()
2026 obj->sym_map[src_sym_idx] = dst_sec->sec_sym_idx; in linker_append_elf_sym()
2043 t = btf__type_by_id(obj->btf, btf_sec_id); in linker_append_elf_sym()
2044 sec_name = btf__str_by_offset(obj->btf, t->name_off); in linker_append_elf_sym()
2056 return -ENOENT; in linker_append_elf_sym()
2058 dst_sec = &linker->secs[src_sec->dst_id]; in linker_append_elf_sym()
2068 obj->sym_map[src_sym_idx] = glob_sym->sym_idx; in linker_append_elf_sym()
2070 /* If both symbols are non-externs, at least one of in linker_append_elf_sym()
2074 if (!sym_is_extern && !glob_sym->is_extern in linker_append_elf_sym()
2075 && !glob_sym->is_weak && sym_bind != STB_WEAK) { in linker_append_elf_sym()
2076 pr_warn("conflicting non-weak symbol #%d (%s) definition in '%s'\n", in linker_append_elf_sym()
2077 src_sym_idx, sym_name, obj->filename); in linker_append_elf_sym()
2078 return -EINVAL; in linker_append_elf_sym()
2082 return -EINVAL; in linker_append_elf_sym()
2084 dst_sym = get_sym_by_idx(linker, glob_sym->sym_idx); in linker_append_elf_sym()
2086 /* If new symbol is strong, then force dst_sym to be strong as in linker_append_elf_sym()
2087 * well; this way a mix of weak and non-weak extern in linker_append_elf_sym()
2096 glob_sym->is_weak = false; in linker_append_elf_sym()
2099 /* Non-default visibility is "contaminating", with stricter in linker_append_elf_sym()
2105 if (sym_vis > ELF64_ST_VISIBILITY(dst_sym->st_other)) in linker_append_elf_sym()
2118 * strong-strong conflict. We also already tightened binding in linker_append_elf_sym()
2121 if (!glob_sym->is_extern && sym_bind == STB_WEAK) in linker_append_elf_sym()
2124 /* At this point, new symbol is strong non-extern, in linker_append_elf_sym()
2129 dst_sym->st_shndx = dst_sec->sec_idx; in linker_append_elf_sym()
2130 dst_sym->st_value = src_sec->dst_off + sym->st_value; in linker_append_elf_sym()
2131 dst_sym->st_size = sym->st_size; in linker_append_elf_sym()
2133 /* see comment below about dst_sec->id vs dst_sec->sec_idx */ in linker_append_elf_sym()
2134 glob_sym->sec_id = dst_sec->id; in linker_append_elf_sym()
2135 glob_sym->is_extern = false; in linker_append_elf_sym()
2137 if (complete_extern_btf_info(linker->btf, glob_sym->btf_id, in linker_append_elf_sym()
2138 obj->btf, btf_id)) in linker_append_elf_sym()
2139 return -EINVAL; in linker_append_elf_sym()
2142 glob_sym->underlying_btf_id = 0; in linker_append_elf_sym()
2144 obj->sym_map[src_sym_idx] = glob_sym->sym_idx; in linker_append_elf_sym()
2149 name_off = strset__add_str(linker->strtab_strs, sym_name); in linker_append_elf_sym()
2155 return -ENOMEM; in linker_append_elf_sym()
2157 dst_sym->st_name = name_off; in linker_append_elf_sym()
2158 dst_sym->st_info = sym->st_info; in linker_append_elf_sym()
2159 dst_sym->st_other = sym->st_other; in linker_append_elf_sym()
2160 dst_sym->st_shndx = dst_sec ? dst_sec->sec_idx : sym->st_shndx; in linker_append_elf_sym()
2161 dst_sym->st_value = (src_sec ? src_sec->dst_off : 0) + sym->st_value; in linker_append_elf_sym()
2162 dst_sym->st_size = sym->st_size; in linker_append_elf_sym()
2164 obj->sym_map[src_sym_idx] = dst_sym_idx; in linker_append_elf_sym()
2167 dst_sec->sec_sym_idx = dst_sym_idx; in linker_append_elf_sym()
2168 dst_sym->st_value = 0; in linker_append_elf_sym()
2174 return -ENOMEM; in linker_append_elf_sym()
2176 glob_sym->sym_idx = dst_sym_idx; in linker_append_elf_sym()
2177 /* we use dst_sec->id (and not dst_sec->sec_idx), because in linker_append_elf_sym()
2181 * associated with it, so dst_sec->id == dst_sec->sec_idx == 0. in linker_append_elf_sym()
2183 glob_sym->sec_id = dst_sec ? dst_sec->id : 0; in linker_append_elf_sym()
2184 glob_sym->name_off = name_off; in linker_append_elf_sym()
2186 glob_sym->btf_id = 0; in linker_append_elf_sym()
2187 glob_sym->is_extern = sym_is_extern; in linker_append_elf_sym()
2188 glob_sym->is_weak = sym_bind == STB_WEAK; in linker_append_elf_sym()
2196 struct src_sec *src_symtab = &obj->secs[obj->symtab_sec_idx]; in linker_append_elf_relos()
2199 for (i = 1; i < obj->sec_cnt; i++) { in linker_append_elf_relos()
2205 src_sec = &obj->secs[i]; in linker_append_elf_relos()
2209 /* shdr->sh_info points to relocatable section */ in linker_append_elf_relos()
2210 src_linked_sec = &obj->secs[src_sec->shdr->sh_info]; in linker_append_elf_relos()
2211 if (src_linked_sec->skipped) in linker_append_elf_relos()
2214 dst_sec = find_dst_sec_by_name(linker, src_sec->sec_name); in linker_append_elf_relos()
2216 dst_sec = add_dst_sec(linker, src_sec->sec_name); in linker_append_elf_relos()
2218 return -ENOMEM; in linker_append_elf_relos()
2221 pr_warn("failed to init section '%s'\n", src_sec->sec_name); in linker_append_elf_relos()
2225 pr_warn("sections %s are not compatible\n", src_sec->sec_name); in linker_append_elf_relos()
2226 return -1; in linker_append_elf_relos()
2229 /* shdr->sh_link points to SYMTAB */ in linker_append_elf_relos()
2230 dst_sec->shdr->sh_link = linker->symtab_sec_idx; in linker_append_elf_relos()
2232 /* shdr->sh_info points to relocated section */ in linker_append_elf_relos()
2233 dst_linked_sec = &linker->secs[src_linked_sec->dst_id]; in linker_append_elf_relos()
2234 dst_sec->shdr->sh_info = dst_linked_sec->sec_idx; in linker_append_elf_relos()
2236 src_sec->dst_id = dst_sec->id; in linker_append_elf_relos()
2241 src_rel = src_sec->data->d_buf; in linker_append_elf_relos()
2242 dst_rel = dst_sec->raw_data + src_sec->dst_off; in linker_append_elf_relos()
2243 n = src_sec->shdr->sh_size / src_sec->shdr->sh_entsize; in linker_append_elf_relos()
2248 src_sym_idx = ELF64_R_SYM(src_rel->r_info); in linker_append_elf_relos()
2249 src_sym = src_symtab->data->d_buf + sizeof(*src_sym) * src_sym_idx; in linker_append_elf_relos()
2251 dst_sym_idx = obj->sym_map[src_sym_idx]; in linker_append_elf_relos()
2252 dst_rel->r_offset += src_linked_sec->dst_off; in linker_append_elf_relos()
2253 sym_type = ELF64_R_TYPE(src_rel->r_info); in linker_append_elf_relos()
2254 dst_rel->r_info = ELF64_R_INFO(dst_sym_idx, sym_type); in linker_append_elf_relos()
2256 if (ELF64_ST_TYPE(src_sym->st_info) == STT_SECTION) { in linker_append_elf_relos()
2257 struct src_sec *sec = &obj->secs[src_sym->st_shndx]; in linker_append_elf_relos()
2260 if (src_linked_sec->shdr->sh_flags & SHF_EXECINSTR) { in linker_append_elf_relos()
2270 insn = dst_linked_sec->raw_data + dst_rel->r_offset; in linker_append_elf_relos()
2271 if (insn->code == (BPF_JMP | BPF_CALL)) in linker_append_elf_relos()
2272 insn->imm += sec->dst_off / sizeof(struct bpf_insn); in linker_append_elf_relos()
2274 insn->imm += sec->dst_off; in linker_append_elf_relos()
2276 pr_warn("relocation against STT_SECTION in non-exec section is not supported!\n"); in linker_append_elf_relos()
2277 return -EINVAL; in linker_append_elf_relos()
2290 struct src_sec *symtab = &obj->secs[obj->symtab_sec_idx]; in find_sym_by_name()
2291 Elf64_Sym *sym = symtab->data->d_buf; in find_sym_by_name()
2292 int i, n = symtab->shdr->sh_size / symtab->shdr->sh_entsize; in find_sym_by_name()
2293 int str_sec_idx = symtab->shdr->sh_link; in find_sym_by_name()
2297 if (sym->st_shndx != sec_idx) in find_sym_by_name()
2299 if (ELF64_ST_TYPE(sym->st_info) != sym_type) in find_sym_by_name()
2302 name = elf_strptr(obj->elf, str_sec_idx, sym->st_name); in find_sym_by_name()
2321 if (!obj->btf) in linker_fixup_btf()
2324 n = btf__type_cnt(obj->btf); in linker_fixup_btf()
2329 t = btf_type_by_id(obj->btf, i); in linker_fixup_btf()
2333 sec_name = btf__str_by_offset(obj->btf, t->name_off); in linker_fixup_btf()
2337 if (sec->shdr) in linker_fixup_btf()
2338 t->size = sec->shdr->sh_size; in linker_fixup_btf()
2345 * sections, we pre-create "section shells" to be able in linker_fixup_btf()
2346 * to keep track of extra per-section metadata later in linker_fixup_btf()
2355 * matching non-extern VAR/FUNC in other sections. in linker_fixup_btf()
2369 return -ENOMEM; in linker_fixup_btf()
2371 sec->ephemeral = true; in linker_fixup_btf()
2372 sec->sec_idx = 0; /* will match UNDEF shndx in ELF */ in linker_fixup_btf()
2376 sec->sec_type_id = i; in linker_fixup_btf()
2381 const struct btf_type *vt = btf__type_by_id(obj->btf, vi->type); in linker_fixup_btf()
2390 var_name = btf__str_by_offset(obj->btf, vt->name_off); in linker_fixup_btf()
2391 var_linkage = btf_var(vt)->linkage; in linker_fixup_btf()
2397 sym = find_sym_by_name(obj, sec->sec_idx, STT_OBJECT, var_name); in linker_fixup_btf()
2400 return -ENOENT; in linker_fixup_btf()
2403 vi->offset = sym->st_value; in linker_fixup_btf()
2416 if (!obj->btf) in linker_append_btf()
2419 start_id = btf__type_cnt(linker->btf); in linker_append_btf()
2420 n = btf__type_cnt(obj->btf); in linker_append_btf()
2422 obj->btf_type_map = calloc(n + 1, sizeof(int)); in linker_append_btf()
2423 if (!obj->btf_type_map) in linker_append_btf()
2424 return -ENOMEM; in linker_append_btf()
2429 t = btf__type_by_id(obj->btf, i); in linker_append_btf()
2437 name = btf__str_by_offset(obj->btf, t->name_off); in linker_append_btf()
2449 * to strong symbol or weak got upgraded to non-weak in linker_append_btf()
2451 if (glob_sym->underlying_btf_id == 0) in linker_append_btf()
2452 glob_sym->underlying_btf_id = -t->type; in linker_append_btf()
2458 if (glob_sym->btf_id) { in linker_append_btf()
2460 obj->btf_type_map[i] = glob_sym->btf_id; in linker_append_btf()
2465 id = btf__add_type(linker->btf, obj->btf, t); in linker_append_btf()
2467 pr_warn("failed to append BTF type #%d from file '%s'\n", i, obj->filename); in linker_append_btf()
2471 obj->btf_type_map[i] = id; in linker_append_btf()
2475 glob_sym->btf_id = id; in linker_append_btf()
2476 glob_sym->underlying_btf_id = -t->type; in linker_append_btf()
2481 n = btf__type_cnt(linker->btf); in linker_append_btf()
2483 struct btf_type *dst_t = btf_type_by_id(linker->btf, i); in linker_append_btf()
2492 int new_id = obj->btf_type_map[*type_id]; in linker_append_btf()
2498 return -EINVAL; in linker_append_btf()
2501 *type_id = obj->btf_type_map[*type_id]; in linker_append_btf()
2508 for (i = 0; i < linker->glob_sym_cnt; i++) { in linker_append_btf()
2509 struct glob_sym *glob_sym = &linker->glob_syms[i]; in linker_append_btf()
2512 if (glob_sym->underlying_btf_id >= 0) in linker_append_btf()
2515 glob_sym->underlying_btf_id = obj->btf_type_map[-glob_sym->underlying_btf_id]; in linker_append_btf()
2517 glob_t = btf_type_by_id(linker->btf, glob_sym->btf_id); in linker_append_btf()
2518 glob_t->type = glob_sym->underlying_btf_id; in linker_append_btf()
2522 for (i = 1; i < obj->sec_cnt; i++) { in linker_append_btf()
2528 src_sec = &obj->secs[i]; in linker_append_btf()
2529 if (!src_sec->sec_type_id || src_sec->skipped) in linker_append_btf()
2531 dst_sec = &linker->secs[src_sec->dst_id]; in linker_append_btf()
2537 * file otherwise has no read-only static variables in in linker_append_btf()
2541 dst_sec->has_btf = true; in linker_append_btf()
2543 t = btf__type_by_id(obj->btf, src_sec->sec_type_id); in linker_append_btf()
2547 void *sec_vars = dst_sec->sec_vars; in linker_append_btf()
2548 int new_id = obj->btf_type_map[src_var->type]; in linker_append_btf()
2551 t = btf_type_by_id(linker->btf, new_id); in linker_append_btf()
2553 name = btf__str_by_offset(linker->btf, t->name_off); in linker_append_btf()
2555 if (glob_sym->sec_id != dst_sec->id) { in linker_append_btf()
2557 name, glob_sym->sec_id, dst_sec->id); in linker_append_btf()
2558 return -EINVAL; in linker_append_btf()
2567 if (glob_sym && glob_sym->var_idx >= 0) { in linker_append_btf()
2574 dst_var = &dst_sec->sec_vars[glob_sym->var_idx]; in linker_append_btf()
2577 * re-calculate and update it in sec_var. in linker_append_btf()
2579 sz = btf__resolve_size(linker->btf, glob_sym->underlying_btf_id); in linker_append_btf()
2583 return -EINVAL; in linker_append_btf()
2585 dst_var->size = sz; in linker_append_btf()
2590 dst_sec->sec_var_cnt + 1, in linker_append_btf()
2591 sizeof(*dst_sec->sec_vars)); in linker_append_btf()
2593 return -ENOMEM; in linker_append_btf()
2595 dst_sec->sec_vars = sec_vars; in linker_append_btf()
2596 dst_sec->sec_var_cnt++; in linker_append_btf()
2598 dst_var = &dst_sec->sec_vars[dst_sec->sec_var_cnt - 1]; in linker_append_btf()
2599 dst_var->type = obj->btf_type_map[src_var->type]; in linker_append_btf()
2600 dst_var->size = src_var->size; in linker_append_btf()
2601 dst_var->offset = src_sec->dst_off + src_var->offset; in linker_append_btf()
2604 glob_sym->var_idx = dst_sec->sec_var_cnt - 1; in linker_append_btf()
2615 tmp = libbpf_reallocarray(ext_data->recs, ext_data->rec_cnt + 1, ext_data->rec_sz); in add_btf_ext_rec()
2618 ext_data->recs = tmp; in add_btf_ext_rec()
2620 tmp += ext_data->rec_cnt * ext_data->rec_sz; in add_btf_ext_rec()
2621 memcpy(tmp, src_rec, ext_data->rec_sz); in add_btf_ext_rec()
2623 ext_data->rec_cnt++; in add_btf_ext_rec()
2636 if (!obj->btf_ext) in linker_append_btf_ext()
2639 rec_sz = obj->btf_ext->func_info.rec_size; in linker_append_btf_ext()
2640 for_each_btf_ext_sec(&obj->btf_ext->func_info, ext_sec) { in linker_append_btf_ext()
2643 sec_name = btf__name_by_offset(obj->btf, ext_sec->sec_name_off); in linker_append_btf_ext()
2647 return -EINVAL; in linker_append_btf_ext()
2649 dst_sec = &linker->secs[src_sec->dst_id]; in linker_append_btf_ext()
2651 if (dst_sec->func_info.rec_sz == 0) in linker_append_btf_ext()
2652 dst_sec->func_info.rec_sz = rec_sz; in linker_append_btf_ext()
2653 if (dst_sec->func_info.rec_sz != rec_sz) { in linker_append_btf_ext()
2655 return -EINVAL; in linker_append_btf_ext()
2658 for_each_btf_ext_rec(&obj->btf_ext->func_info, ext_sec, i, src_rec) { in linker_append_btf_ext()
2659 dst_rec = add_btf_ext_rec(&dst_sec->func_info, src_rec); in linker_append_btf_ext()
2661 return -ENOMEM; in linker_append_btf_ext()
2663 dst_rec->insn_off += src_sec->dst_off; in linker_append_btf_ext()
2664 dst_rec->type_id = obj->btf_type_map[dst_rec->type_id]; in linker_append_btf_ext()
2668 rec_sz = obj->btf_ext->line_info.rec_size; in linker_append_btf_ext()
2669 for_each_btf_ext_sec(&obj->btf_ext->line_info, ext_sec) { in linker_append_btf_ext()
2672 sec_name = btf__name_by_offset(obj->btf, ext_sec->sec_name_off); in linker_append_btf_ext()
2676 return -EINVAL; in linker_append_btf_ext()
2678 dst_sec = &linker->secs[src_sec->dst_id]; in linker_append_btf_ext()
2680 if (dst_sec->line_info.rec_sz == 0) in linker_append_btf_ext()
2681 dst_sec->line_info.rec_sz = rec_sz; in linker_append_btf_ext()
2682 if (dst_sec->line_info.rec_sz != rec_sz) { in linker_append_btf_ext()
2684 return -EINVAL; in linker_append_btf_ext()
2687 for_each_btf_ext_rec(&obj->btf_ext->line_info, ext_sec, i, src_rec) { in linker_append_btf_ext()
2688 dst_rec = add_btf_ext_rec(&dst_sec->line_info, src_rec); in linker_append_btf_ext()
2690 return -ENOMEM; in linker_append_btf_ext()
2692 dst_rec->insn_off += src_sec->dst_off; in linker_append_btf_ext()
2694 s = btf__str_by_offset(obj->btf, src_rec->file_name_off); in linker_append_btf_ext()
2695 str_off = btf__add_str(linker->btf, s); in linker_append_btf_ext()
2697 return -ENOMEM; in linker_append_btf_ext()
2698 dst_rec->file_name_off = str_off; in linker_append_btf_ext()
2700 s = btf__str_by_offset(obj->btf, src_rec->line_off); in linker_append_btf_ext()
2701 str_off = btf__add_str(linker->btf, s); in linker_append_btf_ext()
2703 return -ENOMEM; in linker_append_btf_ext()
2704 dst_rec->line_off = str_off; in linker_append_btf_ext()
2706 /* dst_rec->line_col is fine */ in linker_append_btf_ext()
2710 rec_sz = obj->btf_ext->core_relo_info.rec_size; in linker_append_btf_ext()
2711 for_each_btf_ext_sec(&obj->btf_ext->core_relo_info, ext_sec) { in linker_append_btf_ext()
2714 sec_name = btf__name_by_offset(obj->btf, ext_sec->sec_name_off); in linker_append_btf_ext()
2718 return -EINVAL; in linker_append_btf_ext()
2720 dst_sec = &linker->secs[src_sec->dst_id]; in linker_append_btf_ext()
2722 if (dst_sec->core_relo_info.rec_sz == 0) in linker_append_btf_ext()
2723 dst_sec->core_relo_info.rec_sz = rec_sz; in linker_append_btf_ext()
2724 if (dst_sec->core_relo_info.rec_sz != rec_sz) { in linker_append_btf_ext()
2726 return -EINVAL; in linker_append_btf_ext()
2729 for_each_btf_ext_rec(&obj->btf_ext->core_relo_info, ext_sec, i, src_rec) { in linker_append_btf_ext()
2730 dst_rec = add_btf_ext_rec(&dst_sec->core_relo_info, src_rec); in linker_append_btf_ext()
2732 return -ENOMEM; in linker_append_btf_ext()
2734 dst_rec->insn_off += src_sec->dst_off; in linker_append_btf_ext()
2735 dst_rec->type_id = obj->btf_type_map[dst_rec->type_id]; in linker_append_btf_ext()
2737 s = btf__str_by_offset(obj->btf, src_rec->access_str_off); in linker_append_btf_ext()
2738 str_off = btf__add_str(linker->btf, s); in linker_append_btf_ext()
2740 return -ENOMEM; in linker_append_btf_ext()
2741 dst_rec->access_str_off = str_off; in linker_append_btf_ext()
2743 /* dst_rec->kind is fine */ in linker_append_btf_ext()
2757 if (!linker->elf) in bpf_linker__finalize()
2758 return libbpf_err(-EINVAL); in bpf_linker__finalize()
2765 strs_sz = strset__data_size(linker->strtab_strs); in bpf_linker__finalize()
2766 strs = strset__data(linker->strtab_strs); in bpf_linker__finalize()
2768 sec = &linker->secs[linker->strtab_sec_idx]; in bpf_linker__finalize()
2769 sec->data->d_align = 1; in bpf_linker__finalize()
2770 sec->data->d_off = 0LL; in bpf_linker__finalize()
2771 sec->data->d_buf = (void *)strs; in bpf_linker__finalize()
2772 sec->data->d_type = ELF_T_BYTE; in bpf_linker__finalize()
2773 sec->data->d_size = strs_sz; in bpf_linker__finalize()
2774 sec->shdr->sh_size = strs_sz; in bpf_linker__finalize()
2776 for (i = 1; i < linker->sec_cnt; i++) { in bpf_linker__finalize()
2777 sec = &linker->secs[i]; in bpf_linker__finalize()
2780 if (sec->sec_idx == linker->strtab_sec_idx) in bpf_linker__finalize()
2784 if (!sec->scn) in bpf_linker__finalize()
2787 /* restore sections with bpf insns to target byte-order */ in bpf_linker__finalize()
2788 if (linker->swapped_endian && is_exec_sec(sec)) in bpf_linker__finalize()
2789 exec_sec_bswap(sec->raw_data, sec->sec_sz); in bpf_linker__finalize()
2791 sec->data->d_buf = sec->raw_data; in bpf_linker__finalize()
2795 if (elf_update(linker->elf, ELF_C_NULL) < 0) { in bpf_linker__finalize()
2796 err = -EINVAL; in bpf_linker__finalize()
2802 if (elf_update(linker->elf, ELF_C_WRITE) < 0) { in bpf_linker__finalize()
2803 err = -EINVAL; in bpf_linker__finalize()
2808 elf_end(linker->elf); in bpf_linker__finalize()
2809 linker->elf = NULL; in bpf_linker__finalize()
2811 if (linker->fd_is_owned) in bpf_linker__finalize()
2812 close(linker->fd); in bpf_linker__finalize()
2813 linker->fd = -1; in bpf_linker__finalize()
2826 name_off = strset__add_str(linker->strtab_strs, sec_name); in emit_elf_data_sec()
2830 scn = elf_newscn(linker->elf); in emit_elf_data_sec()
2832 return -ENOMEM; in emit_elf_data_sec()
2835 return -ENOMEM; in emit_elf_data_sec()
2838 return -EINVAL; in emit_elf_data_sec()
2840 shdr->sh_name = name_off; in emit_elf_data_sec()
2841 shdr->sh_type = SHT_PROGBITS; in emit_elf_data_sec()
2842 shdr->sh_flags = 0; in emit_elf_data_sec()
2843 shdr->sh_size = raw_sz; in emit_elf_data_sec()
2844 shdr->sh_link = 0; in emit_elf_data_sec()
2845 shdr->sh_info = 0; in emit_elf_data_sec()
2846 shdr->sh_addralign = align; in emit_elf_data_sec()
2847 shdr->sh_entsize = 0; in emit_elf_data_sec()
2849 data->d_type = ELF_T_BYTE; in emit_elf_data_sec()
2850 data->d_size = raw_sz; in emit_elf_data_sec()
2851 data->d_buf = (void *)raw_data; in emit_elf_data_sec()
2852 data->d_align = align; in emit_elf_data_sec()
2853 data->d_off = 0; in emit_elf_data_sec()
2862 struct btf *btf = linker->btf; in finalize_btf()
2868 if (btf__type_cnt(linker->btf) == 1) in finalize_btf()
2871 for (i = 1; i < linker->sec_cnt; i++) { in finalize_btf()
2872 struct dst_sec *sec = &linker->secs[i]; in finalize_btf()
2874 if (!sec->has_btf) in finalize_btf()
2877 id = btf__add_datasec(btf, sec->sec_name, sec->sec_sz); in finalize_btf()
2880 sec->sec_name, id); in finalize_btf()
2884 for (j = 0; j < sec->sec_var_cnt; j++) { in finalize_btf()
2885 struct btf_var_secinfo *vi = &sec->sec_vars[j]; in finalize_btf()
2887 if (btf__add_datasec_var_info(btf, vi->type, vi->offset, vi->size)) in finalize_btf()
2888 return -EINVAL; in finalize_btf()
2898 opts.btf_ext = linker->btf_ext; in finalize_btf()
2899 err = btf__dedup(linker->btf, &opts); in finalize_btf()
2906 link_endianness = linker->elf_hdr->e_ident[EI_DATA] == ELFDATA2MSB ? in finalize_btf()
2908 btf__set_endianness(linker->btf, link_endianness); in finalize_btf()
2909 if (linker->btf_ext) in finalize_btf()
2910 btf_ext__set_endianness(linker->btf_ext, link_endianness); in finalize_btf()
2913 raw_data = btf__raw_data(linker->btf, &raw_sz); in finalize_btf()
2915 return -ENOMEM; in finalize_btf()
2924 if (linker->btf_ext) { in finalize_btf()
2925 raw_data = btf_ext__raw_data(linker->btf_ext, &raw_sz); in finalize_btf()
2927 return -ENOMEM; in finalize_btf()
2947 if (!sec_data->rec_cnt) in emit_btf_ext_data()
2950 str_off = btf__add_str(linker->btf, sec_name); in emit_btf_ext_data()
2952 return -ENOMEM; in emit_btf_ext_data()
2955 sec_info->sec_name_off = str_off; in emit_btf_ext_data()
2956 sec_info->num_info = sec_data->rec_cnt; in emit_btf_ext_data()
2959 sz = sec_data->rec_cnt * sec_data->rec_sz; in emit_btf_ext_data()
2960 memcpy(cur, sec_data->recs, sz); in emit_btf_ext_data()
2963 return cur - output; in emit_btf_ext_data()
2978 for (i = 1; i < linker->sec_cnt; i++) { in finalize_btf_ext()
2979 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext()
2981 if (sec->func_info.rec_cnt) { in finalize_btf_ext()
2983 func_rec_sz = sec->func_info.rec_sz; in finalize_btf_ext()
2984 if (func_rec_sz != sec->func_info.rec_sz) { in finalize_btf_ext()
2986 func_rec_sz, sec->func_info.rec_sz); in finalize_btf_ext()
2987 return -EINVAL; in finalize_btf_ext()
2990 funcs_sz += sizeof(struct btf_ext_info_sec) + func_rec_sz * sec->func_info.rec_cnt; in finalize_btf_ext()
2992 if (sec->line_info.rec_cnt) { in finalize_btf_ext()
2994 line_rec_sz = sec->line_info.rec_sz; in finalize_btf_ext()
2995 if (line_rec_sz != sec->line_info.rec_sz) { in finalize_btf_ext()
2997 line_rec_sz, sec->line_info.rec_sz); in finalize_btf_ext()
2998 return -EINVAL; in finalize_btf_ext()
3001 lines_sz += sizeof(struct btf_ext_info_sec) + line_rec_sz * sec->line_info.rec_cnt; in finalize_btf_ext()
3003 if (sec->core_relo_info.rec_cnt) { in finalize_btf_ext()
3005 core_relo_rec_sz = sec->core_relo_info.rec_sz; in finalize_btf_ext()
3006 if (core_relo_rec_sz != sec->core_relo_info.rec_sz) { in finalize_btf_ext()
3008 core_relo_rec_sz, sec->core_relo_info.rec_sz); in finalize_btf_ext()
3009 return -EINVAL; in finalize_btf_ext()
3012 … core_relos_sz += sizeof(struct btf_ext_info_sec) + core_relo_rec_sz * sec->core_relo_info.rec_cnt; in finalize_btf_ext()
3035 return -ENOMEM; in finalize_btf_ext()
3038 hdr->magic = BTF_MAGIC; in finalize_btf_ext()
3039 hdr->version = BTF_VERSION; in finalize_btf_ext()
3040 hdr->flags = 0; in finalize_btf_ext()
3041 hdr->hdr_len = sizeof(struct btf_ext_header); in finalize_btf_ext()
3045 hdr->func_info_off = 0; in finalize_btf_ext()
3046 hdr->func_info_len = funcs_sz; in finalize_btf_ext()
3047 hdr->line_info_off = funcs_sz; in finalize_btf_ext()
3048 hdr->line_info_len = lines_sz; in finalize_btf_ext()
3049 hdr->core_relo_off = funcs_sz + lines_sz; in finalize_btf_ext()
3050 hdr->core_relo_len = core_relos_sz; in finalize_btf_ext()
3056 for (i = 1; i < linker->sec_cnt; i++) { in finalize_btf_ext()
3057 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext()
3059 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->func_info); in finalize_btf_ext()
3073 for (i = 1; i < linker->sec_cnt; i++) { in finalize_btf_ext()
3074 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext()
3076 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->line_info); in finalize_btf_ext()
3090 for (i = 1; i < linker->sec_cnt; i++) { in finalize_btf_ext()
3091 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext()
3093 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->core_relo_info); in finalize_btf_ext()
3103 linker->btf_ext = btf_ext__new(data, total_sz); in finalize_btf_ext()
3104 err = libbpf_get_error(linker->btf_ext); in finalize_btf_ext()
3106 linker->btf_ext = NULL; in finalize_btf_ext()