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];
203 free(sec->sec_name);
204 free(sec->raw_data);
205 free(sec->sec_vars);
207 free(sec->func_info.recs);
208 free(sec->line_info.recs);
209 free(sec->core_relo_info.recs);
249 struct dst_sec *secs = linker->secs, *sec;
262 sec = &linker->secs[new_cnt - 1];
263 sec->id = new_cnt - 1;
264 sec->sec_name = strdup(sec_name);
265 if (!sec->sec_name)
268 return sec;
299 struct dst_sec *sec;
341 sec = add_dst_sec(linker, ".strtab");
342 if (!sec)
345 sec->scn = elf_newscn(linker->elf);
346 if (!sec->scn) {
351 sec->shdr = elf64_getshdr(sec->scn);
352 if (!sec->shdr)
355 sec->data = elf_newdata(sec->scn);
356 if (!sec->data) {
361 str_off = strset__add_str(linker->strtab_strs, sec->sec_name);
365 sec->sec_idx = elf_ndxscn(sec->scn);
366 linker->elf_hdr->e_shstrndx = sec->sec_idx;
367 linker->strtab_sec_idx = sec->sec_idx;
369 sec->shdr->sh_name = str_off;
370 sec->shdr->sh_type = SHT_STRTAB;
371 sec->shdr->sh_flags = SHF_STRINGS;
372 sec->shdr->sh_offset = 0;
373 sec->shdr->sh_link = 0;
374 sec->shdr->sh_info = 0;
375 sec->shdr->sh_addralign = 1;
376 sec->shdr->sh_size = sec->sec_sz = 0;
377 sec->shdr->sh_entsize = 0;
380 sec = add_dst_sec(linker, ".symtab");
381 if (!sec)
384 sec->scn = elf_newscn(linker->elf);
385 if (!sec->scn) {
390 sec->shdr = elf64_getshdr(sec->scn);
391 if (!sec->shdr)
394 sec->data = elf_newdata(sec->scn);
395 if (!sec->data) {
400 str_off = strset__add_str(linker->strtab_strs, sec->sec_name);
404 sec->sec_idx = elf_ndxscn(sec->scn);
405 linker->symtab_sec_idx = sec->sec_idx;
407 sec->shdr->sh_name = str_off;
408 sec->shdr->sh_type = SHT_SYMTAB;
409 sec->shdr->sh_flags = 0;
410 sec->shdr->sh_offset = 0;
411 sec->shdr->sh_link = linker->strtab_sec_idx;
415 sec->shdr->sh_info = 0;
416 sec->shdr->sh_addralign = 8;
417 sec->shdr->sh_entsize = sizeof(Elf64_Sym);
479 static bool is_ignored_sec(struct src_sec *sec)
481 Elf64_Shdr *shdr = sec->shdr;
482 const char *name = sec->sec_name;
494 strcmp(sec->sec_name, ".text") == 0)
498 if (is_dwarf_sec_name(sec->sec_name))
518 struct src_sec *secs = obj->secs, *sec;
531 sec = &obj->secs[new_cnt - 1];
532 sec->id = new_cnt - 1;
533 sec->sec_name = sec_name;
535 return sec;
554 struct src_sec *sec;
628 sec = add_src_sec(obj, sec_name);
629 if (!sec)
632 sec->scn = scn;
633 sec->shdr = shdr;
634 sec->data = data;
635 sec->sec_idx = elf_ndxscn(scn);
637 if (is_ignored_sec(sec)) {
638 sec->skipped = true;
662 sec->skipped = true;
672 sec->skipped = true;
702 struct src_sec *sec;
715 sec = &obj->secs[i];
717 if (sec->sec_name[0] == '\0') {
718 pr_warn("ELF section #%zu has empty name in %s\n", sec->sec_idx, obj->filename);
722 if (sec->shdr->sh_addralign && !is_pow_of_2(sec->shdr->sh_addralign))
724 if (sec->shdr->sh_addralign != sec->data->d_align)
727 if (sec->shdr->sh_size != sec->data->d_size)
730 switch (sec->shdr->sh_type) {
732 err = linker_sanity_check_elf_symtab(obj, sec);
739 if (sec->shdr->sh_flags & SHF_EXECINSTR) {
740 if (sec->shdr->sh_size % sizeof(struct bpf_insn) != 0)
747 err = linker_sanity_check_elf_relos(obj, sec);
755 sec->sec_idx, sec->sec_name, (size_t)sec->shdr->sh_type, obj->filename);
763 static int linker_sanity_check_elf_symtab(struct src_obj *obj, struct src_sec *sec)
769 if (sec->shdr->sh_entsize != sizeof(Elf64_Sym))
771 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0)
774 if (!sec->shdr->sh_link || sec->shdr->sh_link >= obj->sec_cnt) {
776 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename);
779 link_sec = &obj->secs[sec->shdr->sh_link];
782 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename);
786 n = sec->shdr->sh_size / sec->shdr->sh_entsize;
787 sym = sec->data->d_buf;
804 i, sec->sec_idx, sym_bind);
809 i, sec->sec_idx, sym_vis);
824 i, sec->sec_idx, (size_t)sym->st_shndx, obj->filename);
837 static int linker_sanity_check_elf_relos(struct src_obj *obj, struct src_sec *sec)
843 if (sec->shdr->sh_entsize != sizeof(Elf64_Rel))
845 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0)
849 if (sec->shdr->sh_link != obj->symtab_sec_idx) {
851 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename);
856 if (!sec->shdr->sh_info || sec->shdr->sh_info >= obj->sec_cnt) {
858 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename);
861 link_sec = &obj->secs[sec->shdr->sh_info];
864 if (strncmp(sec->sec_name, ".rel", sizeof(".rel") - 1) != 0
865 || strcmp(sec->sec_name + sizeof(".rel") - 1, link_sec->sec_name) != 0) {
867 sec->sec_idx, obj->filename);
878 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename);
883 n = sec->shdr->sh_size / sec->shdr->sh_entsize;
884 relo = sec->data->d_buf;
893 i, sec->sec_idx, sym_type, obj->filename);
899 i, sec->sec_idx, sym_idx, obj->filename);
906 i, sec->sec_idx, sym_idx, obj->filename);
1036 struct dst_sec *sec;
1040 sec = &linker->secs[i];
1042 if (strcmp(sec->sec_name, sec_name) == 0)
1043 return sec;
1055 pr_warn("sec %s types mismatch\n", dst->sec_name);
1059 pr_warn("sec %s flags mismatch\n", dst->sec_name);
1063 pr_warn("sec %s entsize mismatch\n", dst->sec_name);
1152 static bool is_data_sec(struct src_sec *sec)
1154 if (!sec || sec->skipped)
1157 if (sec->ephemeral)
1159 return sec->shdr->sh_type == SHT_PROGBITS || sec->shdr->sh_type == SHT_NOBITS;
1162 static bool is_relo_sec(struct src_sec *sec)
1164 if (!sec || sec->skipped || sec->ephemeral)
1166 return sec->shdr->sh_type == SHT_REL;
1729 struct src_sec *sec;
1733 sec = &obj->secs[i];
1735 if (strcmp(sec->sec_name, sec_name) == 0)
1736 return sec;
1870 pr_warn("failed to find matching ELF sec '%s'\n", sec_name);
2072 struct src_sec *sec = &obj->secs[src_sym->st_shndx];
2087 insn->imm += sec->dst_off / sizeof(struct bpf_insn);
2089 insn->imm += sec->dst_off;
2133 struct src_sec *sec;
2149 sec = find_src_sec_by_name(obj, sec_name);
2150 if (sec) {
2152 if (sec->shdr)
2153 t->size = sec->shdr->sh_size;
2182 sec = add_src_sec(obj, sec_name);
2183 if (!sec)
2186 sec->ephemeral = true;
2187 sec->sec_idx = 0; /* will match UNDEF shndx in ELF */
2191 sec->sec_type_id = i;
2205 sym = find_sym_by_name(obj, sec->sec_idx, STT_OBJECT, var_name);
2556 struct dst_sec *sec;
2572 sec = &linker->secs[linker->strtab_sec_idx];
2573 sec->data->d_align = 1;
2574 sec->data->d_off = 0LL;
2575 sec->data->d_buf = (void *)strs;
2576 sec->data->d_type = ELF_T_BYTE;
2577 sec->data->d_size = strs_sz;
2578 sec->shdr->sh_size = strs_sz;
2581 sec = &linker->secs[i];
2584 if (sec->sec_idx == linker->strtab_sec_idx)
2588 if (!sec->scn)
2591 sec->data->d_buf = sec->raw_data;
2670 struct dst_sec *sec = &linker->secs[i];
2672 if (!sec->has_btf)
2675 id = btf__add_datasec(btf, sec->sec_name, sec->sec_sz);
2678 sec->sec_name, id);
2682 for (j = 0; j < sec->sec_var_cnt; j++) {
2683 struct btf_var_secinfo *vi = &sec->sec_vars[j];
2770 struct dst_sec *sec = &linker->secs[i];
2772 if (sec->func_info.rec_cnt) {
2774 func_rec_sz = sec->func_info.rec_sz;
2775 if (func_rec_sz != sec->func_info.rec_sz) {
2777 func_rec_sz, sec->func_info.rec_sz);
2781 funcs_sz += sizeof(struct btf_ext_info_sec) + func_rec_sz * sec->func_info.rec_cnt;
2783 if (sec->line_info.rec_cnt) {
2785 line_rec_sz = sec->line_info.rec_sz;
2786 if (line_rec_sz != sec->line_info.rec_sz) {
2788 line_rec_sz, sec->line_info.rec_sz);
2792 lines_sz += sizeof(struct btf_ext_info_sec) + line_rec_sz * sec->line_info.rec_cnt;
2794 if (sec->core_relo_info.rec_cnt) {
2796 core_relo_rec_sz = sec->core_relo_info.rec_sz;
2797 if (core_relo_rec_sz != sec->core_relo_info.rec_sz) {
2799 core_relo_rec_sz, sec->core_relo_info.rec_sz);
2803 core_relos_sz += sizeof(struct btf_ext_info_sec) + core_relo_rec_sz * sec->core_relo_info.rec_cnt;
2848 struct dst_sec *sec = &linker->secs[i];
2850 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->func_info);
2865 struct dst_sec *sec = &linker->secs[i];
2867 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->line_info);
2882 struct dst_sec *sec = &linker->secs[i];
2884 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->core_relo_info);