Lines Matching refs: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()
248 struct dst_sec *secs = linker->secs, *sec; in add_dst_sec() local
261 sec = &linker->secs[new_cnt - 1]; in add_dst_sec()
262 sec->id = new_cnt - 1; in add_dst_sec()
263 sec->sec_name = strdup(sec_name); in add_dst_sec()
264 if (!sec->sec_name) in add_dst_sec()
267 return sec; in add_dst_sec()
298 struct dst_sec *sec; in init_output_elf() local
340 sec = add_dst_sec(linker, ".strtab"); in init_output_elf()
341 if (!sec) in init_output_elf()
344 sec->scn = elf_newscn(linker->elf); in init_output_elf()
345 if (!sec->scn) { in init_output_elf()
350 sec->shdr = elf64_getshdr(sec->scn); in init_output_elf()
351 if (!sec->shdr) in init_output_elf()
354 sec->data = elf_newdata(sec->scn); in init_output_elf()
355 if (!sec->data) { in init_output_elf()
360 str_off = strset__add_str(linker->strtab_strs, sec->sec_name); in init_output_elf()
364 sec->sec_idx = elf_ndxscn(sec->scn); in init_output_elf()
365 linker->elf_hdr->e_shstrndx = sec->sec_idx; in init_output_elf()
366 linker->strtab_sec_idx = sec->sec_idx; in init_output_elf()
368 sec->shdr->sh_name = str_off; in init_output_elf()
369 sec->shdr->sh_type = SHT_STRTAB; in init_output_elf()
370 sec->shdr->sh_flags = SHF_STRINGS; in init_output_elf()
371 sec->shdr->sh_offset = 0; in init_output_elf()
372 sec->shdr->sh_link = 0; in init_output_elf()
373 sec->shdr->sh_info = 0; in init_output_elf()
374 sec->shdr->sh_addralign = 1; in init_output_elf()
375 sec->shdr->sh_size = sec->sec_sz = 0; in init_output_elf()
376 sec->shdr->sh_entsize = 0; in init_output_elf()
379 sec = add_dst_sec(linker, ".symtab"); in init_output_elf()
380 if (!sec) in init_output_elf()
383 sec->scn = elf_newscn(linker->elf); in init_output_elf()
384 if (!sec->scn) { in init_output_elf()
389 sec->shdr = elf64_getshdr(sec->scn); in init_output_elf()
390 if (!sec->shdr) in init_output_elf()
393 sec->data = elf_newdata(sec->scn); in init_output_elf()
394 if (!sec->data) { in init_output_elf()
399 str_off = strset__add_str(linker->strtab_strs, sec->sec_name); in init_output_elf()
403 sec->sec_idx = elf_ndxscn(sec->scn); in init_output_elf()
404 linker->symtab_sec_idx = sec->sec_idx; in init_output_elf()
406 sec->shdr->sh_name = str_off; in init_output_elf()
407 sec->shdr->sh_type = SHT_SYMTAB; in init_output_elf()
408 sec->shdr->sh_flags = 0; in init_output_elf()
409 sec->shdr->sh_offset = 0; in init_output_elf()
410 sec->shdr->sh_link = linker->strtab_sec_idx; in init_output_elf()
414 sec->shdr->sh_info = 0; in init_output_elf()
415 sec->shdr->sh_addralign = 8; in init_output_elf()
416 sec->shdr->sh_entsize = sizeof(Elf64_Sym); in init_output_elf()
478 static bool is_ignored_sec(struct src_sec *sec) in is_ignored_sec() argument
480 Elf64_Shdr *shdr = sec->shdr; in is_ignored_sec()
481 const char *name = sec->sec_name; in is_ignored_sec()
493 strcmp(sec->sec_name, ".text") == 0) in is_ignored_sec()
497 if (is_dwarf_sec_name(sec->sec_name)) in is_ignored_sec()
517 struct src_sec *secs = obj->secs, *sec; in add_src_sec() local
530 sec = &obj->secs[new_cnt - 1]; in add_src_sec()
531 sec->id = new_cnt - 1; in add_src_sec()
532 sec->sec_name = sec_name; in add_src_sec()
534 return sec; in add_src_sec()
553 struct src_sec *sec; in linker_load_obj_file() local
627 sec = add_src_sec(obj, sec_name); in linker_load_obj_file()
628 if (!sec) in linker_load_obj_file()
631 sec->scn = scn; in linker_load_obj_file()
632 sec->shdr = shdr; in linker_load_obj_file()
633 sec->data = data; in linker_load_obj_file()
634 sec->sec_idx = elf_ndxscn(scn); in linker_load_obj_file()
636 if (is_ignored_sec(sec)) { in linker_load_obj_file()
637 sec->skipped = true; in linker_load_obj_file()
661 sec->skipped = true; in linker_load_obj_file()
671 sec->skipped = true; in linker_load_obj_file()
706 struct src_sec *sec; in linker_sanity_check_elf() local
719 sec = &obj->secs[i]; in linker_sanity_check_elf()
721 if (sec->sec_name[0] == '\0') { in linker_sanity_check_elf()
722 pr_warn("ELF section #%zu has empty name in %s\n", sec->sec_idx, obj->filename); in linker_sanity_check_elf()
726 if (sec->shdr->sh_addralign && !is_pow_of_2(sec->shdr->sh_addralign)) in linker_sanity_check_elf()
728 if (sec->shdr->sh_addralign != sec->data->d_align) in linker_sanity_check_elf()
731 if (sec->shdr->sh_size != sec->data->d_size) in linker_sanity_check_elf()
734 switch (sec->shdr->sh_type) { in linker_sanity_check_elf()
736 err = linker_sanity_check_elf_symtab(obj, sec); in linker_sanity_check_elf()
743 if (sec->shdr->sh_flags & SHF_EXECINSTR) { in linker_sanity_check_elf()
744 if (sec->shdr->sh_size % sizeof(struct bpf_insn) != 0) in linker_sanity_check_elf()
751 err = linker_sanity_check_elf_relos(obj, sec); in linker_sanity_check_elf()
759 sec->sec_idx, sec->sec_name, (size_t)sec->shdr->sh_type, obj->filename); in linker_sanity_check_elf()
767 static int linker_sanity_check_elf_symtab(struct src_obj *obj, struct src_sec *sec) in linker_sanity_check_elf_symtab() argument
773 if (sec->shdr->sh_entsize != sizeof(Elf64_Sym)) in linker_sanity_check_elf_symtab()
775 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0) in linker_sanity_check_elf_symtab()
778 if (!sec->shdr->sh_link || sec->shdr->sh_link >= obj->sec_cnt) { in linker_sanity_check_elf_symtab()
780 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_symtab()
783 link_sec = &obj->secs[sec->shdr->sh_link]; in linker_sanity_check_elf_symtab()
786 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_symtab()
790 n = sec->shdr->sh_size / sec->shdr->sh_entsize; in linker_sanity_check_elf_symtab()
791 sym = sec->data->d_buf; in linker_sanity_check_elf_symtab()
808 i, sec->sec_idx, sym_bind); in linker_sanity_check_elf_symtab()
813 i, sec->sec_idx, sym_vis); in linker_sanity_check_elf_symtab()
828 i, sec->sec_idx, (size_t)sym->st_shndx, obj->filename); in linker_sanity_check_elf_symtab()
841 static int linker_sanity_check_elf_relos(struct src_obj *obj, struct src_sec *sec) in linker_sanity_check_elf_relos() argument
847 if (sec->shdr->sh_entsize != sizeof(Elf64_Rel)) in linker_sanity_check_elf_relos()
849 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0) in linker_sanity_check_elf_relos()
853 if (sec->shdr->sh_link != obj->symtab_sec_idx) { in linker_sanity_check_elf_relos()
855 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_relos()
860 if (!sec->shdr->sh_info || sec->shdr->sh_info >= obj->sec_cnt) { in linker_sanity_check_elf_relos()
862 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename); in linker_sanity_check_elf_relos()
865 link_sec = &obj->secs[sec->shdr->sh_info]; in linker_sanity_check_elf_relos()
868 if (strncmp(sec->sec_name, ".rel", sizeof(".rel") - 1) != 0 in linker_sanity_check_elf_relos()
869 || strcmp(sec->sec_name + sizeof(".rel") - 1, link_sec->sec_name) != 0) { in linker_sanity_check_elf_relos()
871 sec->sec_idx, obj->filename); in linker_sanity_check_elf_relos()
882 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename); in linker_sanity_check_elf_relos()
887 n = sec->shdr->sh_size / sec->shdr->sh_entsize; in linker_sanity_check_elf_relos()
888 relo = sec->data->d_buf; in linker_sanity_check_elf_relos()
897 i, sec->sec_idx, sym_type, obj->filename); in linker_sanity_check_elf_relos()
903 i, sec->sec_idx, sym_idx, obj->filename); in linker_sanity_check_elf_relos()
910 i, sec->sec_idx, sym_idx, obj->filename); in linker_sanity_check_elf_relos()
1040 struct dst_sec *sec; in find_dst_sec_by_name() local
1044 sec = &linker->secs[i]; in find_dst_sec_by_name()
1046 if (strcmp(sec->sec_name, sec_name) == 0) in find_dst_sec_by_name()
1047 return sec; in find_dst_sec_by_name()
1144 static bool is_data_sec(struct src_sec *sec) in is_data_sec() argument
1146 if (!sec || sec->skipped) in is_data_sec()
1149 if (sec->ephemeral) in is_data_sec()
1151 return sec->shdr->sh_type == SHT_PROGBITS || sec->shdr->sh_type == SHT_NOBITS; in is_data_sec()
1154 static bool is_relo_sec(struct src_sec *sec) in is_relo_sec() argument
1156 if (!sec || sec->skipped || sec->ephemeral) in is_relo_sec()
1158 return sec->shdr->sh_type == SHT_REL; in is_relo_sec()
1719 struct src_sec *sec; in find_src_sec_by_name() local
1723 sec = &obj->secs[i]; in find_src_sec_by_name()
1725 if (strcmp(sec->sec_name, sec_name) == 0) in find_src_sec_by_name()
1726 return sec; in find_src_sec_by_name()
2066 struct src_sec *sec = &obj->secs[src_sym->st_shndx]; in linker_append_elf_relos() local
2081 insn->imm += sec->dst_off / sizeof(struct bpf_insn); in linker_append_elf_relos()
2083 insn->imm += sec->dst_off; in linker_append_elf_relos()
2127 struct src_sec *sec; in linker_fixup_btf() local
2143 sec = find_src_sec_by_name(obj, sec_name); in linker_fixup_btf()
2144 if (sec) { in linker_fixup_btf()
2146 if (sec->shdr) in linker_fixup_btf()
2147 t->size = sec->shdr->sh_size; in linker_fixup_btf()
2176 sec = add_src_sec(obj, sec_name); in linker_fixup_btf()
2177 if (!sec) in linker_fixup_btf()
2180 sec->ephemeral = true; in linker_fixup_btf()
2181 sec->sec_idx = 0; /* will match UNDEF shndx in ELF */ in linker_fixup_btf()
2185 sec->sec_type_id = i; in linker_fixup_btf()
2199 sym = find_sym_by_name(obj, sec->sec_idx, STT_OBJECT, var_name); in linker_fixup_btf()
2550 struct dst_sec *sec; in bpf_linker__finalize() local
2566 sec = &linker->secs[linker->strtab_sec_idx]; in bpf_linker__finalize()
2567 sec->data->d_align = 1; in bpf_linker__finalize()
2568 sec->data->d_off = 0LL; in bpf_linker__finalize()
2569 sec->data->d_buf = (void *)strs; in bpf_linker__finalize()
2570 sec->data->d_type = ELF_T_BYTE; in bpf_linker__finalize()
2571 sec->data->d_size = strs_sz; in bpf_linker__finalize()
2572 sec->shdr->sh_size = strs_sz; in bpf_linker__finalize()
2575 sec = &linker->secs[i]; in bpf_linker__finalize()
2578 if (sec->sec_idx == linker->strtab_sec_idx) in bpf_linker__finalize()
2582 if (!sec->scn) in bpf_linker__finalize()
2585 sec->data->d_buf = sec->raw_data; in bpf_linker__finalize()
2663 struct dst_sec *sec = &linker->secs[i]; in finalize_btf() local
2665 if (!sec->has_btf) in finalize_btf()
2668 id = btf__add_datasec(btf, sec->sec_name, sec->sec_sz); in finalize_btf()
2671 sec->sec_name, id); in finalize_btf()
2675 for (j = 0; j < sec->sec_var_cnt; j++) { in finalize_btf()
2676 struct btf_var_secinfo *vi = &sec->sec_vars[j]; in finalize_btf()
2762 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2764 if (sec->func_info.rec_cnt) { in finalize_btf_ext()
2766 func_rec_sz = sec->func_info.rec_sz; in finalize_btf_ext()
2767 if (func_rec_sz != sec->func_info.rec_sz) { in finalize_btf_ext()
2769 func_rec_sz, sec->func_info.rec_sz); in finalize_btf_ext()
2773 funcs_sz += sizeof(struct btf_ext_info_sec) + func_rec_sz * sec->func_info.rec_cnt; in finalize_btf_ext()
2775 if (sec->line_info.rec_cnt) { in finalize_btf_ext()
2777 line_rec_sz = sec->line_info.rec_sz; in finalize_btf_ext()
2778 if (line_rec_sz != sec->line_info.rec_sz) { in finalize_btf_ext()
2780 line_rec_sz, sec->line_info.rec_sz); in finalize_btf_ext()
2784 lines_sz += sizeof(struct btf_ext_info_sec) + line_rec_sz * sec->line_info.rec_cnt; in finalize_btf_ext()
2786 if (sec->core_relo_info.rec_cnt) { in finalize_btf_ext()
2788 core_relo_rec_sz = sec->core_relo_info.rec_sz; in finalize_btf_ext()
2789 if (core_relo_rec_sz != sec->core_relo_info.rec_sz) { in finalize_btf_ext()
2791 core_relo_rec_sz, sec->core_relo_info.rec_sz); in finalize_btf_ext()
2795 … core_relos_sz += sizeof(struct btf_ext_info_sec) + core_relo_rec_sz * sec->core_relo_info.rec_cnt; in finalize_btf_ext()
2840 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2842 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->func_info); in finalize_btf_ext()
2857 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2859 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->line_info); in finalize_btf_ext()
2874 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2876 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->core_relo_info); in finalize_btf_ext()