Lines Matching full:sec
175 static int linker_sanity_check_elf_symtab(struct src_obj *obj, struct src_sec *sec);
176 static int linker_sanity_check_elf_relos(struct src_obj *obj, struct src_sec *sec);
212 struct dst_sec *sec = &linker->secs[i]; in bpf_linker__free() local
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()
314 struct dst_sec *secs = linker->secs, *sec; in add_dst_sec() local
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()
333 return sec; in add_dst_sec()
364 struct dst_sec *sec; in init_output_elf() local
390 sec = add_dst_sec(linker, ".strtab"); in init_output_elf()
391 if (!sec) in init_output_elf()
394 sec->scn = elf_newscn(linker->elf); in init_output_elf()
395 if (!sec->scn) { in init_output_elf()
400 sec->shdr = elf64_getshdr(sec->scn); in init_output_elf()
401 if (!sec->shdr) in init_output_elf()
404 sec->data = elf_newdata(sec->scn); in init_output_elf()
405 if (!sec->data) { 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()
429 sec = add_dst_sec(linker, ".symtab"); in init_output_elf()
430 if (!sec) in init_output_elf()
433 sec->scn = elf_newscn(linker->elf); in init_output_elf()
434 if (!sec->scn) { in init_output_elf()
439 sec->shdr = elf64_getshdr(sec->scn); in init_output_elf()
440 if (!sec->shdr) in init_output_elf()
443 sec->data = elf_newdata(sec->scn); in init_output_elf()
444 if (!sec->data) { 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()
606 static bool is_ignored_sec(struct src_sec *sec) in is_ignored_sec() argument
608 Elf64_Shdr *shdr = sec->shdr; in is_ignored_sec()
609 const char *name = sec->sec_name; 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()
645 struct src_sec *secs = obj->secs, *sec; in add_src_sec() local
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()
662 return sec; in add_src_sec()
673 struct src_sec *sec; in linker_load_obj_file() local
756 sec = add_src_sec(obj, sec_name); in linker_load_obj_file()
757 if (!sec) 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()
765 if (is_ignored_sec(sec)) { in linker_load_obj_file()
766 sec->skipped = true; in linker_load_obj_file()
791 sec->skipped = true; in linker_load_obj_file()
802 sec->skipped = true; in linker_load_obj_file()
832 struct src_sec *sec; in linker_sanity_check_elf() local
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()
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()
857 sec->sec_idx, (long long unsigned)sec->shdr->sh_addralign, 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()
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()
875 switch (sec->shdr->sh_type) { in linker_sanity_check_elf()
877 err = linker_sanity_check_elf_symtab(obj, sec); 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()
896 err = linker_sanity_check_elf_relos(obj, sec); 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()
912 static int linker_sanity_check_elf_symtab(struct src_obj *obj, struct src_sec *sec) in linker_sanity_check_elf_symtab() argument
918 if (sec->shdr->sh_entsize != sizeof(Elf64_Sym)) in linker_sanity_check_elf_symtab()
920 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0) 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()
928 link_sec = &obj->secs[sec->shdr->sh_link]; in linker_sanity_check_elf_symtab()
931 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename); 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()
953 i, sec->sec_idx, sym_bind); in linker_sanity_check_elf_symtab()
958 i, sec->sec_idx, sym_vis); in linker_sanity_check_elf_symtab()
973 i, sec->sec_idx, (size_t)sym->st_shndx, obj->filename); in linker_sanity_check_elf_symtab()
986 static int linker_sanity_check_elf_relos(struct src_obj *obj, struct src_sec *sec) in linker_sanity_check_elf_relos() argument
992 if (sec->shdr->sh_entsize != sizeof(Elf64_Rel)) in linker_sanity_check_elf_relos()
994 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0) 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()
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()
1010 link_sec = &obj->secs[sec->shdr->sh_info]; 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()
1027 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename); 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()
1042 i, sec->sec_idx, sym_type, obj->filename); in linker_sanity_check_elf_relos()
1048 i, sec->sec_idx, sym_idx, obj->filename); in linker_sanity_check_elf_relos()
1055 i, sec->sec_idx, sym_idx, obj->filename); in linker_sanity_check_elf_relos()
1199 struct dst_sec *sec; in find_dst_sec_by_name() local
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()
1206 return sec; in find_dst_sec_by_name()
1218 pr_warn("sec %s types mismatch\n", dst->sec_name); in secs_match()
1222 pr_warn("sec %s flags mismatch\n", dst->sec_name); in secs_match()
1226 pr_warn("sec %s entsize mismatch\n", dst->sec_name); in secs_match()
1242 static bool is_exec_sec(struct dst_sec *sec) in is_exec_sec() argument
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()
1337 static bool is_data_sec(struct src_sec *sec) in is_data_sec() argument
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()
1347 static bool is_relo_sec(struct src_sec *sec) in is_relo_sec() argument
1349 if (!sec || sec->skipped || sec->ephemeral) in is_relo_sec()
1351 return sec->shdr->sh_type == SHT_REL; in is_relo_sec()
1914 struct src_sec *sec; in find_src_sec_by_name() local
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()
1921 return sec; in find_src_sec_by_name()
2055 pr_warn("failed to find matching ELF sec '%s'\n", sec_name); in linker_append_elf_sym()
2257 struct src_sec *sec = &obj->secs[src_sym->st_shndx]; in linker_append_elf_relos() local
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()
2318 struct src_sec *sec; in linker_fixup_btf() local
2334 sec = find_src_sec_by_name(obj, sec_name); in linker_fixup_btf()
2335 if (sec) { in linker_fixup_btf()
2337 if (sec->shdr) in linker_fixup_btf()
2338 t->size = sec->shdr->sh_size; in linker_fixup_btf()
2367 sec = add_src_sec(obj, sec_name); in linker_fixup_btf()
2368 if (!sec) 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()
2397 sym = find_sym_by_name(obj, sec->sec_idx, STT_OBJECT, var_name); in linker_fixup_btf()
2752 struct dst_sec *sec; in bpf_linker__finalize() local
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()
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()
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()
2872 struct dst_sec *sec = &linker->secs[i]; in finalize_btf() local
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()
2979 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
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()
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()
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()
3012 … core_relos_sz += sizeof(struct btf_ext_info_sec) + core_relo_rec_sz * sec->core_relo_info.rec_cnt; in finalize_btf_ext()
3057 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
3059 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->func_info); in finalize_btf_ext()
3074 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
3076 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->line_info); in finalize_btf_ext()
3091 struct dst_sec *sec = &linker->secs[i]; in finalize_btf_ext() local
3093 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->core_relo_info); in finalize_btf_ext()