Lines Matching full:sec

174 static int linker_sanity_check_elf_symtab(struct src_obj *obj, struct src_sec *sec);
175 static int linker_sanity_check_elf_relos(struct src_obj *obj, struct src_sec *sec);
211 struct dst_sec *sec = &linker->secs[i];
213 free(sec->sec_name);
214 free(sec->raw_data);
215 free(sec->sec_vars);
217 free(sec->func_info.recs);
218 free(sec->line_info.recs);
219 free(sec->core_relo_info.recs);
313 struct dst_sec *secs = linker->secs, *sec;
326 sec = &linker->secs[new_cnt - 1];
327 sec->id = new_cnt - 1;
328 sec->sec_name = strdup(sec_name);
329 if (!sec->sec_name)
332 return sec;
363 struct dst_sec *sec;
389 sec = add_dst_sec(linker, ".strtab");
390 if (!sec)
393 sec->scn = elf_newscn(linker->elf);
394 if (!sec->scn) {
399 sec->shdr = elf64_getshdr(sec->scn);
400 if (!sec->shdr)
403 sec->data = elf_newdata(sec->scn);
404 if (!sec->data) {
409 str_off = strset__add_str(linker->strtab_strs, sec->sec_name);
413 sec->sec_idx = elf_ndxscn(sec->scn);
414 linker->elf_hdr->e_shstrndx = sec->sec_idx;
415 linker->strtab_sec_idx = sec->sec_idx;
417 sec->shdr->sh_name = str_off;
418 sec->shdr->sh_type = SHT_STRTAB;
419 sec->shdr->sh_flags = SHF_STRINGS;
420 sec->shdr->sh_offset = 0;
421 sec->shdr->sh_link = 0;
422 sec->shdr->sh_info = 0;
423 sec->shdr->sh_addralign = 1;
424 sec->shdr->sh_size = sec->sec_sz = 0;
425 sec->shdr->sh_entsize = 0;
428 sec = add_dst_sec(linker, ".symtab");
429 if (!sec)
432 sec->scn = elf_newscn(linker->elf);
433 if (!sec->scn) {
438 sec->shdr = elf64_getshdr(sec->scn);
439 if (!sec->shdr)
442 sec->data = elf_newdata(sec->scn);
443 if (!sec->data) {
448 sec->data->d_type = ELF_T_SYM;
450 str_off = strset__add_str(linker->strtab_strs, sec->sec_name);
454 sec->sec_idx = elf_ndxscn(sec->scn);
455 linker->symtab_sec_idx = sec->sec_idx;
457 sec->shdr->sh_name = str_off;
458 sec->shdr->sh_type = SHT_SYMTAB;
459 sec->shdr->sh_flags = 0;
460 sec->shdr->sh_offset = 0;
461 sec->shdr->sh_link = linker->strtab_sec_idx;
465 sec->shdr->sh_info = 0;
466 sec->shdr->sh_addralign = 8;
467 sec->shdr->sh_entsize = sizeof(Elf64_Sym);
605 static bool is_ignored_sec(struct src_sec *sec)
607 Elf64_Shdr *shdr = sec->shdr;
608 const char *name = sec->sec_name;
620 strcmp(sec->sec_name, ".text") == 0)
624 if (is_dwarf_sec_name(sec->sec_name))
644 struct src_sec *secs = obj->secs, *sec;
657 sec = &obj->secs[new_cnt - 1];
658 sec->id = new_cnt - 1;
659 sec->sec_name = sec_name;
661 return sec;
672 struct src_sec *sec;
755 sec = add_src_sec(obj, sec_name);
756 if (!sec)
759 sec->scn = scn;
760 sec->shdr = shdr;
761 sec->data = data;
762 sec->sec_idx = elf_ndxscn(scn);
764 if (is_ignored_sec(sec)) {
765 sec->skipped = true;
790 sec->skipped = true;
801 sec->skipped = true;
831 struct src_sec *sec;
844 sec = &obj->secs[i];
846 if (sec->sec_name[0] == '\0') {
847 pr_warn("ELF section #%zu has empty name in %s\n", sec->sec_idx, obj->filename);
851 if (is_dwarf_sec_name(sec->sec_name))
854 if (sec->shdr->sh_addralign && !is_pow_of_2(sec->shdr->sh_addralign)) {
856 sec->sec_idx, (long long unsigned)sec->shdr->sh_addralign,
860 if (sec->shdr->sh_addralign != sec->data->d_align) {
862 sec->sec_idx, (long long unsigned)sec->shdr->sh_addralign,
863 (long long unsigned)sec->data->d_align, obj->filename);
867 if (sec->shdr->sh_size != sec->data->d_size) {
869 sec->sec_idx, (long long unsigned)sec->shdr->sh_size,
870 (long long unsigned)sec->data->d_size, obj->filename);
874 switch (sec->shdr->sh_type) {
876 err = linker_sanity_check_elf_symtab(obj, sec);
883 if (sec->shdr->sh_flags & SHF_EXECINSTR) {
884 if (sec->shdr->sh_size % sizeof(struct bpf_insn) != 0) {
886 sec->sec_idx, (long long unsigned)sec->shdr->sh_size,
895 err = linker_sanity_check_elf_relos(obj, sec);
903 sec->sec_idx, sec->sec_name, (size_t)sec->shdr->sh_type, obj->filename);
911 static int linker_sanity_check_elf_symtab(struct src_obj *obj, struct src_sec *sec)
917 if (sec->shdr->sh_entsize != sizeof(Elf64_Sym))
919 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0)
922 if (!sec->shdr->sh_link || sec->shdr->sh_link >= obj->sec_cnt) {
924 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename);
927 link_sec = &obj->secs[sec->shdr->sh_link];
930 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename);
934 n = sec->shdr->sh_size / sec->shdr->sh_entsize;
935 sym = sec->data->d_buf;
952 i, sec->sec_idx, sym_bind);
957 i, sec->sec_idx, sym_vis);
972 i, sec->sec_idx, (size_t)sym->st_shndx, obj->filename);
985 static int linker_sanity_check_elf_relos(struct src_obj *obj, struct src_sec *sec)
991 if (sec->shdr->sh_entsize != sizeof(Elf64_Rel))
993 if (sec->shdr->sh_size % sec->shdr->sh_entsize != 0)
997 if (sec->shdr->sh_link != obj->symtab_sec_idx) {
999 sec->sec_idx, (size_t)sec->shdr->sh_link, obj->filename);
1004 if (!sec->shdr->sh_info || sec->shdr->sh_info >= obj->sec_cnt) {
1006 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename);
1009 link_sec = &obj->secs[sec->shdr->sh_info];
1012 if (strncmp(sec->sec_name, ".rel", sizeof(".rel") - 1) != 0
1013 || strcmp(sec->sec_name + sizeof(".rel") - 1, link_sec->sec_name) != 0) {
1015 sec->sec_idx, obj->filename);
1026 sec->sec_idx, (size_t)sec->shdr->sh_info, obj->filename);
1031 n = sec->shdr->sh_size / sec->shdr->sh_entsize;
1032 relo = sec->data->d_buf;
1041 i, sec->sec_idx, sym_type, obj->filename);
1047 i, sec->sec_idx, sym_idx, obj->filename);
1054 i, sec->sec_idx, sym_idx, obj->filename);
1198 struct dst_sec *sec;
1202 sec = &linker->secs[i];
1204 if (strcmp(sec->sec_name, sec_name) == 0)
1205 return sec;
1217 pr_warn("sec %s types mismatch\n", dst->sec_name);
1221 pr_warn("sec %s flags mismatch\n", dst->sec_name);
1225 pr_warn("sec %s entsize mismatch\n", dst->sec_name);
1241 static bool is_exec_sec(struct dst_sec *sec)
1243 if (!sec || sec->ephemeral)
1245 return (sec->shdr->sh_type == SHT_PROGBITS) &&
1246 (sec->shdr->sh_flags & SHF_EXECINSTR);
1336 static bool is_data_sec(struct src_sec *sec)
1338 if (!sec || sec->skipped)
1341 if (sec->ephemeral)
1343 return sec->shdr->sh_type == SHT_PROGBITS || sec->shdr->sh_type == SHT_NOBITS;
1346 static bool is_relo_sec(struct src_sec *sec)
1348 if (!sec || sec->skipped || sec->ephemeral)
1350 return sec->shdr->sh_type == SHT_REL;
1913 struct src_sec *sec;
1917 sec = &obj->secs[i];
1919 if (strcmp(sec->sec_name, sec_name) == 0)
1920 return sec;
2054 pr_warn("failed to find matching ELF sec '%s'\n", sec_name);
2256 struct src_sec *sec = &obj->secs[src_sym->st_shndx];
2271 insn->imm += sec->dst_off / sizeof(struct bpf_insn);
2273 insn->imm += sec->dst_off;
2317 struct src_sec *sec;
2333 sec = find_src_sec_by_name(obj, sec_name);
2334 if (sec) {
2336 if (sec->shdr)
2337 t->size = sec->shdr->sh_size;
2366 sec = add_src_sec(obj, sec_name);
2367 if (!sec)
2370 sec->ephemeral = true;
2371 sec->sec_idx = 0; /* will match UNDEF shndx in ELF */
2375 sec->sec_type_id = i;
2396 sym = find_sym_by_name(obj, sec->sec_idx, STT_OBJECT, var_name);
2751 struct dst_sec *sec;
2767 sec = &linker->secs[linker->strtab_sec_idx];
2768 sec->data->d_align = 1;
2769 sec->data->d_off = 0LL;
2770 sec->data->d_buf = (void *)strs;
2771 sec->data->d_type = ELF_T_BYTE;
2772 sec->data->d_size = strs_sz;
2773 sec->shdr->sh_size = strs_sz;
2776 sec = &linker->secs[i];
2779 if (sec->sec_idx == linker->strtab_sec_idx)
2783 if (!sec->scn)
2787 if (linker->swapped_endian && is_exec_sec(sec))
2788 exec_sec_bswap(sec->raw_data, sec->sec_sz);
2790 sec->data->d_buf = sec->raw_data;
2871 struct dst_sec *sec = &linker->secs[i];
2873 if (!sec->has_btf)
2876 id = btf__add_datasec(btf, sec->sec_name, sec->sec_sz);
2879 sec->sec_name, id);
2883 for (j = 0; j < sec->sec_var_cnt; j++) {
2884 struct btf_var_secinfo *vi = &sec->sec_vars[j];
2978 struct dst_sec *sec = &linker->secs[i];
2980 if (sec->func_info.rec_cnt) {
2982 func_rec_sz = sec->func_info.rec_sz;
2983 if (func_rec_sz != sec->func_info.rec_sz) {
2985 func_rec_sz, sec->func_info.rec_sz);
2989 funcs_sz += sizeof(struct btf_ext_info_sec) + func_rec_sz * sec->func_info.rec_cnt;
2991 if (sec->line_info.rec_cnt) {
2993 line_rec_sz = sec->line_info.rec_sz;
2994 if (line_rec_sz != sec->line_info.rec_sz) {
2996 line_rec_sz, sec->line_info.rec_sz);
3000 lines_sz += sizeof(struct btf_ext_info_sec) + line_rec_sz * sec->line_info.rec_cnt;
3002 if (sec->core_relo_info.rec_cnt) {
3004 core_relo_rec_sz = sec->core_relo_info.rec_sz;
3005 if (core_relo_rec_sz != sec->core_relo_info.rec_sz) {
3007 core_relo_rec_sz, sec->core_relo_info.rec_sz);
3011 core_relos_sz += sizeof(struct btf_ext_info_sec) + core_relo_rec_sz * sec->core_relo_info.rec_cnt;
3056 struct dst_sec *sec = &linker->secs[i];
3058 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->func_info);
3073 struct dst_sec *sec = &linker->secs[i];
3075 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->line_info);
3090 struct dst_sec *sec = &linker->secs[i];
3092 sz = emit_btf_ext_data(linker, cur, sec->sec_name, &sec->core_relo_info);