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 (sec->shdr->sh_addralign && !is_pow_of_2(sec->shdr->sh_addralign)) in linker_sanity_check_elf()
724 if (sec->shdr->sh_addralign != sec->data->d_align) in linker_sanity_check_elf()
727 if (sec->shdr->sh_size != sec->data->d_size) in linker_sanity_check_elf()
730 switch (sec->shdr->sh_type) { in linker_sanity_check_elf()
732 err = linker_sanity_check_elf_symtab(obj, sec); in linker_sanity_check_elf()
739 if (sec->shdr->sh_flags & SHF_EXECINSTR) { in linker_sanity_check_elf()
740 if (sec->shdr->sh_size % sizeof(struct bpf_insn) != 0) in linker_sanity_check_elf()
747 err = linker_sanity_check_elf_relos(obj, sec); in linker_sanity_check_elf()
755 sec->sec_idx, sec->sec_name, (size_t)sec->shdr->sh_type, obj->filename); in linker_sanity_check_elf()
763 static int linker_sanity_check_elf_symtab(struct src_obj *obj, struct src_sec *sec) in linker_sanity_check_elf_symtab() argument
769 if (sec->shdr->sh_entsize != sizeof(Elf64_Sym)) in linker_sanity_check_elf_symtab()
771 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0) in linker_sanity_check_elf_symtab()
774 if (!sec->shdr->sh_link || sec->shdr->sh_link >= obj->sec_cnt) { in linker_sanity_check_elf_symtab()
776 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_symtab()
779 link_sec = &obj->secs[sec->shdr->sh_link]; in linker_sanity_check_elf_symtab()
782 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_symtab()
786 n = sec->shdr->sh_size / sec->shdr->sh_entsize; in linker_sanity_check_elf_symtab()
787 sym = sec->data->d_buf; in linker_sanity_check_elf_symtab()
804 i, sec->sec_idx, sym_bind); in linker_sanity_check_elf_symtab()
809 i, sec->sec_idx, sym_vis); in linker_sanity_check_elf_symtab()
824 i, sec->sec_idx, (size_t)sym->st_shndx, obj->filename); in linker_sanity_check_elf_symtab()
837 static int linker_sanity_check_elf_relos(struct src_obj *obj, struct src_sec *sec) in linker_sanity_check_elf_relos() argument
843 if (sec->shdr->sh_entsize != sizeof(Elf64_Rel)) in linker_sanity_check_elf_relos()
845 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0) in linker_sanity_check_elf_relos()
849 if (sec->shdr->sh_link != obj->symtab_sec_idx) { in linker_sanity_check_elf_relos()
851 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); in linker_sanity_check_elf_relos()
856 if (!sec->shdr->sh_info || sec->shdr->sh_info >= obj->sec_cnt) { in linker_sanity_check_elf_relos()
858 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename); in linker_sanity_check_elf_relos()
861 link_sec = &obj->secs[sec->shdr->sh_info]; in linker_sanity_check_elf_relos()
864 if (strncmp(sec->sec_name, ".rel", sizeof(".rel") - 1) != 0 in linker_sanity_check_elf_relos()
865 || strcmp(sec->sec_name + sizeof(".rel") - 1, link_sec->sec_name) != 0) { in linker_sanity_check_elf_relos()
867 sec->sec_idx, obj->filename); in linker_sanity_check_elf_relos()
878 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename); in linker_sanity_check_elf_relos()
883 n = sec->shdr->sh_size / sec->shdr->sh_entsize; in linker_sanity_check_elf_relos()
884 relo = sec->data->d_buf; in linker_sanity_check_elf_relos()
893 i, sec->sec_idx, sym_type, obj->filename); in linker_sanity_check_elf_relos()
899 i, sec->sec_idx, sym_idx, obj->filename); in linker_sanity_check_elf_relos()
906 i, sec->sec_idx, sym_idx, obj->filename); in linker_sanity_check_elf_relos()
1036 struct dst_sec *sec; in find_dst_sec_by_name() local
1040 sec = &linker->secs[i]; in find_dst_sec_by_name()
1042 if (strcmp(sec->sec_name, sec_name) == 0) in find_dst_sec_by_name()
1043 return sec; in find_dst_sec_by_name()
1055 pr_warn("sec %s types mismatch\n", dst->sec_name); in secs_match()
1059 pr_warn("sec %s flags mismatch\n", dst->sec_name); in secs_match()
1063 pr_warn("sec %s entsize mismatch\n", dst->sec_name); in secs_match()
1152 static bool is_data_sec(struct src_sec *sec) in is_data_sec() argument
1154 if (!sec || sec->skipped) in is_data_sec()
1157 if (sec->ephemeral) in is_data_sec()
1159 return sec->shdr->sh_type == SHT_PROGBITS || sec->shdr->sh_type == SHT_NOBITS; in is_data_sec()
1162 static bool is_relo_sec(struct src_sec *sec) in is_relo_sec() argument
1164 if (!sec || sec->skipped || sec->ephemeral) in is_relo_sec()
1166 return sec->shdr->sh_type == SHT_REL; in is_relo_sec()
1729 struct src_sec *sec; in find_src_sec_by_name() local
1733 sec = &obj->secs[i]; in find_src_sec_by_name()
1735 if (strcmp(sec->sec_name, sec_name) == 0) in find_src_sec_by_name()
1736 return sec; in find_src_sec_by_name()
1870 pr_warn("failed to find matching ELF sec '%s'\n", sec_name); in linker_append_elf_sym()
2072 struct src_sec *sec = &obj->secs[src_sym->st_shndx]; in linker_append_elf_relos() local
2087 insn->imm += sec->dst_off / sizeof(struct bpf_insn); in linker_append_elf_relos()
2089 insn->imm += sec->dst_off; in linker_append_elf_relos()
2133 struct src_sec *sec; in linker_fixup_btf() local
2149 sec = find_src_sec_by_name(obj, sec_name); in linker_fixup_btf()
2150 if (sec) { in linker_fixup_btf()
2152 if (sec->shdr) in linker_fixup_btf()
2153 t->size = sec->shdr->sh_size; in linker_fixup_btf()
2182 sec = add_src_sec(obj, sec_name); in linker_fixup_btf()
2183 if (!sec) in linker_fixup_btf()
2186 sec->ephemeral = true; in linker_fixup_btf()
2187 sec->sec_idx = 0; /* will match UNDEF shndx in ELF */ in linker_fixup_btf()
2191 sec->sec_type_id = i; in linker_fixup_btf()
2205 sym = find_sym_by_name(obj, sec->sec_idx, STT_OBJECT, var_name); in linker_fixup_btf()
2556 struct dst_sec *sec; in bpf_linker__finalize() local
2572 sec = &linker->secs[linker->strtab_sec_idx]; in bpf_linker__finalize()
2573 sec->data->d_align = 1; in bpf_linker__finalize()
2574 sec->data->d_off = 0LL; in bpf_linker__finalize()
2575 sec->data->d_buf = (void *)strs; in bpf_linker__finalize()
2576 sec->data->d_type = ELF_T_BYTE; in bpf_linker__finalize()
2577 sec->data->d_size = strs_sz; in bpf_linker__finalize()
2578 sec->shdr->sh_size = strs_sz; in bpf_linker__finalize()
2581 sec = &linker->secs[i]; in bpf_linker__finalize()
2584 if (sec->sec_idx == linker->strtab_sec_idx) in bpf_linker__finalize()
2588 if (!sec->scn) in bpf_linker__finalize()
2591 sec->data->d_buf = sec->raw_data; in bpf_linker__finalize()
2670 struct dst_sec *sec = &linker->secs[i]; in finalize_btf() local
2672 if (!sec->has_btf) in finalize_btf()
2675 id = btf__add_datasec(btf, sec->sec_name, sec->sec_sz); in finalize_btf()
2678 sec->sec_name, id); in finalize_btf()
2682 for (j = 0; j < sec->sec_var_cnt; j++) { in finalize_btf()
2683 struct btf_var_secinfo *vi = &sec->sec_vars[j]; in finalize_btf()
2770 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2772 if (sec->func_info.rec_cnt) { in finalize_btf_ext()
2774 func_rec_sz = sec->func_info.rec_sz; in finalize_btf_ext()
2775 if (func_rec_sz != sec->func_info.rec_sz) { in finalize_btf_ext()
2777 func_rec_sz, sec->func_info.rec_sz); in finalize_btf_ext()
2781 funcs_sz += sizeof(struct btf_ext_info_sec) + func_rec_sz * sec->func_info.rec_cnt; in finalize_btf_ext()
2783 if (sec->line_info.rec_cnt) { in finalize_btf_ext()
2785 line_rec_sz = sec->line_info.rec_sz; in finalize_btf_ext()
2786 if (line_rec_sz != sec->line_info.rec_sz) { in finalize_btf_ext()
2788 line_rec_sz, sec->line_info.rec_sz); in finalize_btf_ext()
2792 lines_sz += sizeof(struct btf_ext_info_sec) + line_rec_sz * sec->line_info.rec_cnt; in finalize_btf_ext()
2794 if (sec->core_relo_info.rec_cnt) { in finalize_btf_ext()
2796 core_relo_rec_sz = sec->core_relo_info.rec_sz; in finalize_btf_ext()
2797 if (core_relo_rec_sz != sec->core_relo_info.rec_sz) { in finalize_btf_ext()
2799 core_relo_rec_sz, sec->core_relo_info.rec_sz); in finalize_btf_ext()
2803 … core_relos_sz += sizeof(struct btf_ext_info_sec) + core_relo_rec_sz * sec->core_relo_info.rec_cnt; in finalize_btf_ext()
2848 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2850 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->func_info); in finalize_btf_ext()
2865 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2867 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->line_info); in finalize_btf_ext()
2882 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
2884 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->core_relo_info); in finalize_btf_ext()