Lines Matching full:sec
164 static int linker_sanity_check_elf_symtab(struct src_obj *obj, struct src_sec *sec);
165 static int linker_sanity_check_elf_relos(struct src_obj *obj, struct src_sec *sec);
201 struct dst_sec *sec = &linker->secs[i]; in bpf_linker__free() local
203 free(sec->sec_name); in bpf_linker__free()
204 free(sec->raw_data); in bpf_linker__free()
205 free(sec->sec_vars); in bpf_linker__free()
207 free(sec->func_info.recs); in bpf_linker__free()
208 free(sec->line_info.recs); in bpf_linker__free()
209 free(sec->core_relo_info.recs); in bpf_linker__free()
249 struct dst_sec *secs = linker->secs, *sec; in add_dst_sec() local
262 sec = &linker->secs[new_cnt - 1]; in add_dst_sec()
263 sec->id = new_cnt - 1; in add_dst_sec()
264 sec->sec_name = strdup(sec_name); in add_dst_sec()
265 if (!sec->sec_name) in add_dst_sec()
268 return sec; in add_dst_sec()
299 struct dst_sec *sec; in init_output_elf() local
341 sec = add_dst_sec(linker, ".strtab"); in init_output_elf()
342 if (!sec) in init_output_elf()
345 sec->scn = elf_newscn(linker->elf); in init_output_elf()
346 if (!sec->scn) { in init_output_elf()
351 sec->shdr = elf64_getshdr(sec->scn); in init_output_elf()
352 if (!sec->shdr) in init_output_elf()
355 sec->data = elf_newdata(sec->scn); in init_output_elf()
356 if (!sec->data) { in init_output_elf()
361 str_off = strset__add_str(linker->strtab_strs, sec->sec_name); in init_output_elf()
365 sec->sec_idx = elf_ndxscn(sec->scn); in init_output_elf()
366 linker->elf_hdr->e_shstrndx = sec->sec_idx; in init_output_elf()
367 linker->strtab_sec_idx = sec->sec_idx; in init_output_elf()
369 sec->shdr->sh_name = str_off; in init_output_elf()
370 sec->shdr->sh_type = SHT_STRTAB; in init_output_elf()
371 sec->shdr->sh_flags = SHF_STRINGS; in init_output_elf()
372 sec->shdr->sh_offset = 0; in init_output_elf()
373 sec->shdr->sh_link = 0; in init_output_elf()
374 sec->shdr->sh_info = 0; in init_output_elf()
375 sec->shdr->sh_addralign = 1; in init_output_elf()
376 sec->shdr->sh_size = sec->sec_sz = 0; in init_output_elf()
377 sec->shdr->sh_entsize = 0; in init_output_elf()
380 sec = add_dst_sec(linker, ".symtab"); in init_output_elf()
381 if (!sec) in init_output_elf()
384 sec->scn = elf_newscn(linker->elf); in init_output_elf()
385 if (!sec->scn) { in init_output_elf()
390 sec->shdr = elf64_getshdr(sec->scn); in init_output_elf()
391 if (!sec->shdr) in init_output_elf()
394 sec->data = elf_newdata(sec->scn); in init_output_elf()
395 if (!sec->data) { in init_output_elf()
400 str_off = strset__add_str(linker->strtab_strs, sec->sec_name); in init_output_elf()
404 sec->sec_idx = elf_ndxscn(sec->scn); in init_output_elf()
405 linker->symtab_sec_idx = sec->sec_idx; in init_output_elf()
407 sec->shdr->sh_name = str_off; in init_output_elf()
408 sec->shdr->sh_type = SHT_SYMTAB; in init_output_elf()
409 sec->shdr->sh_flags = 0; in init_output_elf()
410 sec->shdr->sh_offset = 0; in init_output_elf()
411 sec->shdr->sh_link = linker->strtab_sec_idx; in init_output_elf()
415 sec->shdr->sh_info = 0; in init_output_elf()
416 sec->shdr->sh_addralign = 8; in init_output_elf()
417 sec->shdr->sh_entsize = sizeof(Elf64_Sym); in init_output_elf()
479 static bool is_ignored_sec(struct src_sec *sec) in is_ignored_sec() argument
481 Elf64_Shdr *shdr = sec->shdr; in is_ignored_sec()
482 const char *name = sec->sec_name; in is_ignored_sec()
494 strcmp(sec->sec_name, ".text") == 0) in is_ignored_sec()
498 if (is_dwarf_sec_name(sec->sec_name)) in is_ignored_sec()
518 struct src_sec *secs = obj->secs, *sec; in add_src_sec() local
531 sec = &obj->secs[new_cnt - 1]; in add_src_sec()
532 sec->id = new_cnt - 1; in add_src_sec()
533 sec->sec_name = sec_name; in add_src_sec()
535 return sec; in add_src_sec()
554 struct src_sec *sec; in linker_load_obj_file() local
628 sec = add_src_sec(obj, sec_name); in linker_load_obj_file()
629 if (!sec) in linker_load_obj_file()
632 sec->scn = scn; in linker_load_obj_file()
633 sec->shdr = shdr; in linker_load_obj_file()
634 sec->data = data; in linker_load_obj_file()
635 sec->sec_idx = elf_ndxscn(scn); in linker_load_obj_file()
637 if (is_ignored_sec(sec)) { in linker_load_obj_file()
638 sec->skipped = true; in linker_load_obj_file()
662 sec->skipped = true; in linker_load_obj_file()
672 sec->skipped = true; in linker_load_obj_file()
702 struct src_sec *sec; in linker_sanity_check_elf() local
715 sec = &obj->secs[i]; in linker_sanity_check_elf()
717 if (sec->sec_name[0] == '\0') { in linker_sanity_check_elf()
718 pr_warn("ELF section #%zu has empty name in %s\n", sec->sec_idx, obj->filename); in linker_sanity_check_elf()
722 if (is_dwarf_sec_name(sec->sec_name)) in linker_sanity_check_elf()
725 if (sec->shdr->sh_addralign && !is_pow_of_2(sec->shdr->sh_addralign)) { in linker_sanity_check_elf()
727 sec->sec_idx, (long long unsigned)sec->shdr->sh_addralign, in linker_sanity_check_elf()
731 if (sec->shdr->sh_addralign != sec->data->d_align) { in linker_sanity_check_elf()
733 sec->sec_idx, (long long unsigned)sec->shdr->sh_addralign, in linker_sanity_check_elf()
734 (long long unsigned)sec->data->d_align, obj->filename); in linker_sanity_check_elf()
738 if (sec->shdr->sh_size != sec->data->d_size) { in linker_sanity_check_elf()
740 sec->sec_idx, (long long unsigned)sec->shdr->sh_size, in linker_sanity_check_elf()
741 (long long unsigned)sec->data->d_size, obj->filename); in linker_sanity_check_elf()
745 switch (sec->shdr->sh_type) { in linker_sanity_check_elf()
747 err = linker_sanity_check_elf_symtab(obj, sec); in linker_sanity_check_elf()
754 if (sec->shdr->sh_flags & SHF_EXECINSTR) { in linker_sanity_check_elf()
755 if (sec->shdr->sh_size % sizeof(struct bpf_insn) != 0) { in linker_sanity_check_elf()
757 sec->sec_idx, (long long unsigned)sec->shdr->sh_size, in linker_sanity_check_elf()
766 err = linker_sanity_check_elf_relos(obj, sec); in linker_sanity_check_elf()
774 sec->sec_idx, sec->sec_name, (size_t)sec->shdr->sh_type, obj->filename); in linker_sanity_check_elf()
782 static int linker_sanity_check_elf_symtab(struct src_obj *obj, struct src_sec *sec) in linker_sanity_check_elf_symtab() argument
788 if (sec->shdr->sh_entsize != sizeof(Elf64_Sym)) in linker_sanity_check_elf_symtab()
790 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0) in linker_sanity_check_elf_symtab()
793 if (!sec->shdr->sh_link || sec->shdr->sh_link >= obj->sec_cnt) { in linker_sanity_check_elf_symtab()
795 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_symtab()
798 link_sec = &obj->secs[sec->shdr->sh_link]; in linker_sanity_check_elf_symtab()
801 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_symtab()
805 n = sec->shdr->sh_size / sec->shdr->sh_entsize; in linker_sanity_check_elf_symtab()
806 sym = sec->data->d_buf; in linker_sanity_check_elf_symtab()
823 i, sec->sec_idx, sym_bind); in linker_sanity_check_elf_symtab()
828 i, sec->sec_idx, sym_vis); in linker_sanity_check_elf_symtab()
843 i, sec->sec_idx, (size_t)sym->st_shndx, obj->filename); in linker_sanity_check_elf_symtab()
856 static int linker_sanity_check_elf_relos(struct src_obj *obj, struct src_sec *sec) in linker_sanity_check_elf_relos() argument
862 if (sec->shdr->sh_entsize != sizeof(Elf64_Rel)) in linker_sanity_check_elf_relos()
864 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0) in linker_sanity_check_elf_relos()
868 if (sec->shdr->sh_link != obj->symtab_sec_idx) { in linker_sanity_check_elf_relos()
870 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_relos()
875 if (!sec->shdr->sh_info || sec->shdr->sh_info >= obj->sec_cnt) { in linker_sanity_check_elf_relos()
877 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename); in linker_sanity_check_elf_relos()
880 link_sec = &obj->secs[sec->shdr->sh_info]; in linker_sanity_check_elf_relos()
883 if (strncmp(sec->sec_name, ".rel", sizeof(".rel") - 1) != 0 in linker_sanity_check_elf_relos()
884 || strcmp(sec->sec_name + sizeof(".rel") - 1, link_sec->sec_name) != 0) { in linker_sanity_check_elf_relos()
886 sec->sec_idx, obj->filename); in linker_sanity_check_elf_relos()
897 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename); in linker_sanity_check_elf_relos()
902 n = sec->shdr->sh_size / sec->shdr->sh_entsize; in linker_sanity_check_elf_relos()
903 relo = sec->data->d_buf; in linker_sanity_check_elf_relos()
912 i, sec->sec_idx, sym_type, obj->filename); in linker_sanity_check_elf_relos()
918 i, sec->sec_idx, sym_idx, obj->filename); in linker_sanity_check_elf_relos()
925 i, sec->sec_idx, sym_idx, obj->filename); in linker_sanity_check_elf_relos()
1055 struct dst_sec *sec; in find_dst_sec_by_name() local
1059 sec = &linker->secs[i]; in find_dst_sec_by_name()
1061 if (strcmp(sec->sec_name, sec_name) == 0) in find_dst_sec_by_name()
1062 return sec; in find_dst_sec_by_name()
1074 pr_warn("sec %s types mismatch\n", dst->sec_name); in secs_match()
1078 pr_warn("sec %s flags mismatch\n", dst->sec_name); in secs_match()
1082 pr_warn("sec %s entsize mismatch\n", dst->sec_name); in secs_match()
1171 static bool is_data_sec(struct src_sec *sec) in is_data_sec() argument
1173 if (!sec || sec->skipped) in is_data_sec()
1176 if (sec->ephemeral) in is_data_sec()
1178 return sec->shdr->sh_type == SHT_PROGBITS || sec->shdr->sh_type == SHT_NOBITS; in is_data_sec()
1181 static bool is_relo_sec(struct src_sec *sec) in is_relo_sec() argument
1183 if (!sec || sec->skipped || sec->ephemeral) in is_relo_sec()
1185 return sec->shdr->sh_type == SHT_REL; in is_relo_sec()
1748 struct src_sec *sec; in find_src_sec_by_name() local
1752 sec = &obj->secs[i]; in find_src_sec_by_name()
1754 if (strcmp(sec->sec_name, sec_name) == 0) in find_src_sec_by_name()
1755 return sec; in find_src_sec_by_name()
1889 pr_warn("failed to find matching ELF sec '%s'\n", sec_name); in linker_append_elf_sym()
2091 struct src_sec *sec = &obj->secs[src_sym->st_shndx]; in linker_append_elf_relos() local
2106 insn->imm += sec->dst_off / sizeof(struct bpf_insn); in linker_append_elf_relos()
2108 insn->imm += sec->dst_off; in linker_append_elf_relos()
2152 struct src_sec *sec; in linker_fixup_btf() local
2168 sec = find_src_sec_by_name(obj, sec_name); in linker_fixup_btf()
2169 if (sec) { in linker_fixup_btf()
2171 if (sec->shdr) in linker_fixup_btf()
2172 t->size = sec->shdr->sh_size; in linker_fixup_btf()
2201 sec = add_src_sec(obj, sec_name); in linker_fixup_btf()
2202 if (!sec) in linker_fixup_btf()
2205 sec->ephemeral = true; in linker_fixup_btf()
2206 sec->sec_idx = 0; /* will match UNDEF shndx in ELF */ in linker_fixup_btf()
2210 sec->sec_type_id = i; in linker_fixup_btf()
2224 sym = find_sym_by_name(obj, sec->sec_idx, STT_OBJECT, var_name); in linker_fixup_btf()
2575 struct dst_sec *sec; in bpf_linker__finalize() local
2591 sec = &linker->secs[linker->strtab_sec_idx]; in bpf_linker__finalize()
2592 sec->data->d_align = 1; in bpf_linker__finalize()
2593 sec->data->d_off = 0LL; in bpf_linker__finalize()
2594 sec->data->d_buf = (void *)strs; in bpf_linker__finalize()
2595 sec->data->d_type = ELF_T_BYTE; in bpf_linker__finalize()
2596 sec->data->d_size = strs_sz; in bpf_linker__finalize()
2597 sec->shdr->sh_size = strs_sz; in bpf_linker__finalize()
2600 sec = &linker->secs[i]; in bpf_linker__finalize()
2603 if (sec->sec_idx == linker->strtab_sec_idx) in bpf_linker__finalize()
2607 if (!sec->scn) in bpf_linker__finalize()
2610 sec->data->d_buf = sec->raw_data; in bpf_linker__finalize()
2689 struct dst_sec *sec = &linker->secs[i]; in finalize_btf() local
2691 if (!sec->has_btf) in finalize_btf()
2694 id = btf__add_datasec(btf, sec->sec_name, sec->sec_sz); in finalize_btf()
2697 sec->sec_name, id); in finalize_btf()
2701 for (j = 0; j < sec->sec_var_cnt; j++) { in finalize_btf()
2702 struct btf_var_secinfo *vi = &sec->sec_vars[j]; in finalize_btf()
2789 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2791 if (sec->func_info.rec_cnt) { in finalize_btf_ext()
2793 func_rec_sz = sec->func_info.rec_sz; in finalize_btf_ext()
2794 if (func_rec_sz != sec->func_info.rec_sz) { in finalize_btf_ext()
2796 func_rec_sz, sec->func_info.rec_sz); in finalize_btf_ext()
2800 funcs_sz += sizeof(struct btf_ext_info_sec) + func_rec_sz * sec->func_info.rec_cnt; in finalize_btf_ext()
2802 if (sec->line_info.rec_cnt) { in finalize_btf_ext()
2804 line_rec_sz = sec->line_info.rec_sz; in finalize_btf_ext()
2805 if (line_rec_sz != sec->line_info.rec_sz) { in finalize_btf_ext()
2807 line_rec_sz, sec->line_info.rec_sz); in finalize_btf_ext()
2811 lines_sz += sizeof(struct btf_ext_info_sec) + line_rec_sz * sec->line_info.rec_cnt; in finalize_btf_ext()
2813 if (sec->core_relo_info.rec_cnt) { in finalize_btf_ext()
2815 core_relo_rec_sz = sec->core_relo_info.rec_sz; in finalize_btf_ext()
2816 if (core_relo_rec_sz != sec->core_relo_info.rec_sz) { in finalize_btf_ext()
2818 core_relo_rec_sz, sec->core_relo_info.rec_sz); in finalize_btf_ext()
2822 … core_relos_sz += sizeof(struct btf_ext_info_sec) + core_relo_rec_sz * sec->core_relo_info.rec_cnt; in finalize_btf_ext()
2867 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2869 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->func_info); in finalize_btf_ext()
2884 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2886 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->line_info); in finalize_btf_ext()
2901 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2903 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->core_relo_info); in finalize_btf_ext()