Lines Matching refs:ld_state
60 static const char **ld_generic_lib_extensions (struct ld_state *)
63 struct ld_state *statep);
65 struct ld_state *statep,
67 static void ld_generic_generate_sections (struct ld_state *statep);
68 static void ld_generic_create_sections (struct ld_state *statep);
69 static int ld_generic_flag_unresolved (struct ld_state *statep);
70 static int ld_generic_open_outfile (struct ld_state *statep, int machine,
72 static int ld_generic_create_outfile (struct ld_state *statep);
73 static void ld_generic_relocate_section (struct ld_state *statep,
77 static int ld_generic_finalize (struct ld_state *statep);
78 static bool ld_generic_special_section_number_p (struct ld_state *statep,
80 static bool ld_generic_section_type_p (struct ld_state *statep,
82 static XElf_Xword ld_generic_dynamic_section_flags (struct ld_state *statep);
83 static void ld_generic_initialize_plt (struct ld_state *statep, Elf_Scn *scn);
84 static void ld_generic_initialize_pltrel (struct ld_state *statep,
86 static void ld_generic_initialize_got (struct ld_state *statep, Elf_Scn *scn);
87 static void ld_generic_initialize_gotplt (struct ld_state *statep,
89 static void ld_generic_finalize_plt (struct ld_state *statep, size_t nsym,
92 static int ld_generic_rel_type (struct ld_state *statep);
93 static void ld_generic_count_relocations (struct ld_state *statep,
95 static void ld_generic_create_relocations (struct ld_state *statep,
156 return (ld_state.file_type == dso_file_type || ld_state.nplt > 0 in dynamically_linked_p()
157 || ld_state.ngot > 0); in dynamically_linked_p()
183 ld_state.nodefs = true; in ld_prepare_state()
187 ld_state.add_ld_comment = true; in ld_prepare_state()
191 ld_state.nextveridx = 2; in ld_prepare_state()
194 ld_symbol_tab_init (&ld_state.symbol_tab, 1027); in ld_prepare_state()
195 ld_section_tab_init (&ld_state.section_tab, 67); in ld_prepare_state()
196 ld_version_str_tab_init (&ld_state.version_str_tab, 67); in ld_prepare_state()
199 ld_state.shstrtab = ebl_strtabinit (true); in ld_prepare_state()
200 if (ld_state.shstrtab == NULL) in ld_prepare_state()
205 ld_state.callbacks.lib_extensions = ld_generic_lib_extensions; in ld_prepare_state()
206 ld_state.callbacks.file_process = ld_generic_file_process; in ld_prepare_state()
207 ld_state.callbacks.file_close = ld_generic_file_close; in ld_prepare_state()
208 ld_state.callbacks.generate_sections = ld_generic_generate_sections; in ld_prepare_state()
209 ld_state.callbacks.create_sections = ld_generic_create_sections; in ld_prepare_state()
210 ld_state.callbacks.flag_unresolved = ld_generic_flag_unresolved; in ld_prepare_state()
211 ld_state.callbacks.open_outfile = ld_generic_open_outfile; in ld_prepare_state()
212 ld_state.callbacks.create_outfile = ld_generic_create_outfile; in ld_prepare_state()
213 ld_state.callbacks.relocate_section = ld_generic_relocate_section; in ld_prepare_state()
214 ld_state.callbacks.finalize = ld_generic_finalize; in ld_prepare_state()
215 ld_state.callbacks.special_section_number_p = in ld_prepare_state()
217 ld_state.callbacks.section_type_p = ld_generic_section_type_p; in ld_prepare_state()
218 ld_state.callbacks.dynamic_section_flags = ld_generic_dynamic_section_flags; in ld_prepare_state()
219 ld_state.callbacks.initialize_plt = ld_generic_initialize_plt; in ld_prepare_state()
220 ld_state.callbacks.initialize_pltrel = ld_generic_initialize_pltrel; in ld_prepare_state()
221 ld_state.callbacks.initialize_got = ld_generic_initialize_got; in ld_prepare_state()
222 ld_state.callbacks.initialize_gotplt = ld_generic_initialize_gotplt; in ld_prepare_state()
223 ld_state.callbacks.finalize_plt = ld_generic_finalize_plt; in ld_prepare_state()
224 ld_state.callbacks.rel_type = ld_generic_rel_type; in ld_prepare_state()
225 ld_state.callbacks.count_relocations = ld_generic_count_relocations; in ld_prepare_state()
226 ld_state.callbacks.create_relocations = ld_generic_create_relocations; in ld_prepare_state()
233 emulation = ebl_backend_name (ld_state.ebl); in ld_prepare_state()
253 int (*initfct) (struct ld_state *) in ld_prepare_state()
254 = (int (*) (struct ld_state *)) dlsym (h, initname); in ld_prepare_state()
262 ld_state.ldlib = h; in ld_prepare_state()
265 return initfct (&ld_state); in ld_prepare_state()
270 extern int INIT_FCT_NAME(BASE_ELF_NAME) (struct ld_state *); in ld_prepare_state()
271 return INIT_FCT_NAME(BASE_ELF_NAME) (&ld_state); in ld_prepare_state()
327 return (check_for_duplicate2 (newp, ld_state.relfiles) in check_for_duplicate()
328 || check_for_duplicate2 (newp, ld_state.dsofiles) in check_for_duplicate()
329 || check_for_duplicate2 (newp, ld_state.needed)); in check_for_duplicate()
357 const char **exts = (ld_state.statically in open_along_path2()
359 : LIB_EXTENSION (&ld_state)); in open_along_path2()
410 fileinfo->rfname = obstack_strdup (&ld_state.smem, rfname); in open_along_path2()
412 if (unlikely (ld_state.trace_files)) in open_along_path2()
468 if (unlikely (ld_state.trace_files)) in open_along_path()
481 err = open_along_path2 (fileinfo, ld_state.ld_library_path1); in open_along_path()
487 ? ld_state.paths : ld_state.rpath_link); in open_along_path()
492 err = open_along_path2 (fileinfo, ld_state.ld_library_path2); in open_along_path()
498 err = open_along_path2 (fileinfo, ld_state.runpath_link); in open_along_path()
502 err = open_along_path2 (fileinfo, ld_state.default_paths); in open_along_path()
566 ebl_symbol_type_name (ld_state.ebl, oldp->type, in check_type_and_size()
569 ebl_symbol_type_name (ld_state.ebl, XELF_ST_TYPE (sym->st_info), in check_type_and_size()
612 --ld_state.nunresolved; in check_definition()
614 --ld_state.nunresolved_nonweak; in check_definition()
615 CDBL_LIST_DEL (ld_state.unresolved, oldp); in check_definition()
619 CDBL_LIST_DEL (ld_state.common_syms, oldp); in check_definition()
638 && (!ld_state.muldefs || verbose) in check_definition()
661 scnname = ebl_section_name (ld_state.ebl, shndx, 0, buf, sizeof (buf), in check_definition()
670 ebl_symbol_type_name (ld_state.ebl, XELF_ST_TYPE (sym->st_info), in check_definition()
685 scnname = ebl_section_name (ld_state.ebl, oldp->scndx, oldp->scndx, in check_definition()
693 if (likely (!ld_state.muldefs)) in check_definition()
704 CDBL_LIST_ADD_REAR (ld_state.from_dso, oldp); in check_definition()
705 ++ld_state.nfrom_dso; in check_definition()
710 ++ld_state.nplt; in check_definition()
712 ++ld_state.ngot; in check_definition()
730 CDBL_LIST_DEL (ld_state.from_dso, oldp); in check_definition()
731 --ld_state.nfrom_dso; in check_definition()
734 --ld_state.nplt; in check_definition()
736 --ld_state.ngot; in check_definition()
768 CDBL_LIST_ADD_REAR (ld_state.from_dso, oldp); in check_definition()
769 ++ld_state.nfrom_dso; in check_definition()
774 ++ld_state.nplt; in check_definition()
776 ++ld_state.ngot; in check_definition()
785 CDBL_LIST_ADD_REAR (ld_state.common_syms, oldp); in check_definition()
880 if (ld_state.strip == strip_none in mark_section_group()
882 || (!ebl_debugscn_p (ld_state.ebl, in mark_section_group()
887 || !ebl_debugscn_p (ld_state.ebl, in mark_section_group()
946 if (unlikely (shdr->sh_flags & SHF_GROUP) && ld_state.gc_sections) in mark_section_used()
975 && (ld_state.strip == strip_none in add_section()
982 && (fileinfo->status != in_archive || !ld_state.gc_sections)) in add_section()
1003 queued = ld_section_tab_find (&ld_state.section_tab, hval, &search); in add_section()
1058 queued->flags = ebl_sh_flags_combine (ld_state.ebl, queued->flags, in add_section()
1079 ld_state.need_tls |= (shdr->sh_flags & SHF_TLS) != 0; in add_section()
1082 ld_section_tab_insert (&ld_state.section_tab, hval, queued); in add_section()
1116 obstack_calloc (&ld_state.smem, scncnt * sizeof (struct scninfo)); in add_relocatable_file()
1217 obstack_calloc (&ld_state.smem, in add_relocatable_file()
1220 obstack_alloc (&ld_state.smem, in add_relocatable_file()
1251 obstack_calloc (&ld_state.smem, sizeof (struct symbol)); in add_relocatable_file()
1334 else if (! SECTION_TYPE_P (&ld_state, shdr->sh_type) in add_relocatable_file()
1376 && ld_state.execstack != execstack_false_force) in add_relocatable_file()
1377 ld_state.execstack = execstack_true; in add_relocatable_file()
1390 obstack_calloc (&ld_state.smem, in add_relocatable_file()
1428 obstack_calloc (&ld_state.smem, sizeof (struct symbol)); in add_relocatable_file()
1456 obstack_calloc (&ld_state.smem, ((nsymbols - nlocalsymbols) in add_relocatable_file()
1529 struct symbol *oldp = ld_symbol_tab_find (&ld_state.symbol_tab, in add_relocatable_file()
1535 newp = (struct symbol *) obstack_alloc (&ld_state.smem, in add_relocatable_file()
1563 CDBL_LIST_ADD_REAR (ld_state.unresolved, newp); in add_relocatable_file()
1564 ++ld_state.nunresolved; in add_relocatable_file()
1566 ++ld_state.nunresolved_nonweak; in add_relocatable_file()
1573 CDBL_LIST_ADD_REAR (ld_state.common_syms, newp); in add_relocatable_file()
1577 if (unlikely (ld_symbol_tab_insert (&ld_state.symbol_tab, in add_relocatable_file()
1590 ld_state.init_symbol = newp; in add_relocatable_file()
1592 ld_state.fini_symbol = newp; in add_relocatable_file()
1641 if (unlikely (ld_state.relfiles == NULL)) in add_relocatable_file()
1642 ld_state.relfiles = fileinfo->next = fileinfo; in add_relocatable_file()
1645 fileinfo->next = ld_state.relfiles->next; in add_relocatable_file()
1646 ld_state.relfiles = ld_state.relfiles->next = fileinfo; in add_relocatable_file()
1650 ld_state.nsymtab += fileinfo->nsymtab; in add_relocatable_file()
1651 ld_state.nlocalsymbols += fileinfo->nlocalsymbols; in add_relocatable_file()
1655 CSNGL_LIST_ADD_REAR (ld_state.dsofiles, fileinfo); in add_relocatable_file()
1656 ++ld_state.ndsofiles; in add_relocatable_file()
1664 ++ld_state.ndsofiles; in add_relocatable_file()
1695 res |= FILE_PROCESS (-1, curp, &ld_state, &curp); in ld_handle_filename_list()
1762 ld_state.srcfiles = NULL; in open_elf()
1787 fnames = ld_state.srcfiles; in open_elf()
1798 ld_state.srcfiles = NULL; in open_elf()
1840 if (unlikely (ld_state.trace_files)) in add_whole_archive()
1875 assert (ld_state.extract_rule == defaultextract in extract_from_archive()
1876 || ld_state.extract_rule == weakextract); in extract_from_archive()
1877 if ((likely (ld_state.extract_rule == defaultextract) in extract_from_archive()
1878 ? ld_state.nunresolved_nonweak : ld_state.nunresolved) == 0) in extract_from_archive()
1911 struct symbol *sym = ld_symbol_tab_find (&ld_state.symbol_tab, in extract_from_archive()
1936 newp = ld_new_inputfile (obstack_strdup (&ld_state.smem, in extract_from_archive()
1941 if (unlikely (ld_state.trace_files)) in extract_from_archive()
1964 ld_state.last_archive_used = fileinfo->archive_seq; in extract_from_archive()
2011 ebl_object_type_name (ld_state.ebl, in file_process2()
2020 != ebl_get_elfmachine (ld_state.ebl)) in file_process2()
2025 ebl_backend_name (ld_state.ebl)); in file_process2()
2061 if (ld_state.file_type == relocatable_file_type) in file_process2()
2105 CSNGL_LIST_ADD_REAR (ld_state.needed, newp); in file_process2()
2130 newp = (char *) obstack_alloc (&ld_state.smem, len); in file_process2()
2139 if (unlikely (ld_state.extract_rule == allextract)) in file_process2()
2143 else if (ld_state.file_type == relocatable_file_type) in file_process2()
2154 if (ld_state.group_start_requested in file_process2()
2155 && ld_state.group_start_archive == NULL) in file_process2()
2156 ld_state.group_start_archive = fileinfo; in file_process2()
2158 if (ld_state.archives == NULL) in file_process2()
2159 ld_state.archives = fileinfo; in file_process2()
2161 if (ld_state.tailarchives != NULL) in file_process2()
2162 ld_state.tailarchives->next = fileinfo; in file_process2()
2163 ld_state.tailarchives = fileinfo; in file_process2()
2185 struct ld_state *statep, struct usedfiles **nextp) in ld_generic_file_process()
2195 ld_state.group_start_requested = true; in ld_generic_file_process()
2244 if (ld_state.last_archive_used > fileinfo->group_backref->archive_seq) in ld_generic_file_process()
2247 ld_state.last_archive_used = 0; in ld_generic_file_process()
2254 struct usedfiles *runp = ld_state.archives; in ld_generic_file_process()
2269 ld_state.archives = NULL; in ld_generic_file_process()
2281 if (ld_state.group_start_requested) in ld_generic_file_process()
2283 if (ld_state.group_start_archive != ld_state.tailarchives) in ld_generic_file_process()
2286 *nextp = ld_state.tailarchives->group_backref = in ld_generic_file_process()
2287 ld_state.group_start_archive; in ld_generic_file_process()
2288 ld_state.last_archive_used = 0; in ld_generic_file_process()
2294 if (ld_state.tailarchives != fileinfo) in ld_generic_file_process()
2296 *nextp = ld_state.group_start_archive; in ld_generic_file_process()
2297 ld_state.last_archive_used = 0; in ld_generic_file_process()
2302 ld_state.group_start_requested = false; in ld_generic_file_process()
2303 ld_state.group_start_archive = NULL; in ld_generic_file_process()
2315 ld_generic_lib_extensions (struct ld_state *statep __attribute__ ((__unused__))) in ld_generic_lib_extensions()
2328 ld_generic_flag_unresolved (struct ld_state *statep) in ld_generic_flag_unresolved()
2332 if (ld_state.nunresolved_nonweak > 0) in ld_generic_flag_unresolved()
2338 s = first = ld_state.unresolved->next; in ld_generic_flag_unresolved()
2349 ld_state.need_got = true; in ld_generic_flag_unresolved()
2353 ld_state.got_symbol = s; in ld_generic_flag_unresolved()
2355 ld_state.dyn_symbol = s; in ld_generic_flag_unresolved()
2357 else if (ld_state.file_type != dso_file_type || !ld_state.nodefs) in ld_generic_flag_unresolved()
2386 ld_generic_file_close (struct usedfiles *fileinfo, struct ld_state *statep) in ld_generic_file_close()
2410 newp = (struct scnhead *) obstack_calloc (&ld_state.smem, in new_generated_scn()
2414 newp->nameent = ebl_strtabadd (ld_state.shstrtab, name, 0); in new_generated_scn()
2424 ld_section_tab_insert (&ld_state.section_tab, elf_hash (name), newp); in new_generated_scn()
2431 ld_generic_generate_sections (struct ld_state *statep) in ld_generic_generate_sections()
2434 int rel_type = REL_TYPE (&ld_state) == DT_REL ? SHT_REL : SHT_RELA; in ld_generic_generate_sections()
2458 if (ld_state.interp != NULL || ld_state.file_type != dso_file_type) in ld_generic_generate_sections()
2464 DYNAMIC_SECTION_FLAGS (&ld_state), in ld_generic_generate_sections()
2465 xelf_fsize (ld_state.outelf, ELF_T_DYN, 1), in ld_generic_generate_sections()
2466 xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1)); in ld_generic_generate_sections()
2471 ld_state.need_dynsym = true; in ld_generic_generate_sections()
2473 xelf_fsize (ld_state.outelf, ELF_T_SYM, 1), in ld_generic_generate_sections()
2474 xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1)); in ld_generic_generate_sections()
2489 if (ld_state.nplt > 0) in ld_generic_generate_sections()
2496 xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1), in ld_generic_generate_sections()
2497 xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1)); in ld_generic_generate_sections()
2503 ? xelf_fsize (ld_state.outelf, ELF_T_REL, 1) in ld_generic_generate_sections()
2504 : xelf_fsize (ld_state.outelf, ELF_T_RELA, 1), in ld_generic_generate_sections()
2505 xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1)); in ld_generic_generate_sections()
2510 xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1), in ld_generic_generate_sections()
2511 xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1)); in ld_generic_generate_sections()
2515 if (ld_state.from_dso != NULL) in ld_generic_generate_sections()
2517 struct symbol *srunp = ld_state.from_dso; in ld_generic_generate_sections()
2552 ++ld_state.nverdeffile; in ld_generic_generate_sections()
2553 ++ld_state.nverdefused; in ld_generic_generate_sections()
2557 while ((srunp = srunp->next) != ld_state.from_dso); in ld_generic_generate_sections()
2564 xelf_fsize (ld_state.outelf, ELF_T_WORD, 1)); in ld_generic_generate_sections()
2570 if (ld_state.ndsofiles > 0) in ld_generic_generate_sections()
2572 struct usedfiles *frunp = ld_state.dsofiles; in ld_generic_generate_sections()
2587 while ((frunp = frunp->next) != ld_state.dsofiles); in ld_generic_generate_sections()
2593 xelf_fsize (ld_state.outelf, ELF_T_HALF, 1), in ld_generic_generate_sections()
2594 xelf_fsize (ld_state.outelf, ELF_T_HALF, 1)); in ld_generic_generate_sections()
2597 ld_state.ndynamic = (7 + (ld_state.runpath != NULL in ld_generic_generate_sections()
2598 || ld_state.rpath != NULL) in ld_generic_generate_sections()
2600 + (ld_state.init_symbol != NULL ? 1 : 0) in ld_generic_generate_sections()
2601 + (ld_state.fini_symbol != NULL ? 1 : 0) in ld_generic_generate_sections()
2604 + (ld_state.nplt > 0 ? 4 : 0) in ld_generic_generate_sections()
2605 + (ld_state.relsize_total > 0 ? 3 : 0)); in ld_generic_generate_sections()
2610 ld_state.need_symtab = (ld_state.file_type == relocatable_file_type in ld_generic_generate_sections()
2611 || ld_state.strip == strip_none); in ld_generic_generate_sections()
2614 if (ld_state.need_got) in ld_generic_generate_sections()
2618 xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1), in ld_generic_generate_sections()
2619 xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1)); in ld_generic_generate_sections()
2622 if (ld_state.relsize_total > 0) in ld_generic_generate_sections()
2625 ? xelf_fsize (ld_state.outelf, ELF_T_REL, 1) in ld_generic_generate_sections()
2626 : xelf_fsize (ld_state.outelf, ELF_T_RELA, 1), in ld_generic_generate_sections()
2627 xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1)); in ld_generic_generate_sections()
2636 if (status != 0 && ld_state.tempfname != NULL) in remove_tempfile()
2637 unlink (ld_state.tempfname); in remove_tempfile()
2644 ld_generic_open_outfile (struct ld_state *statep, int machine, int klass, in ld_generic_open_outfile()
2651 if (ld_state.outfname == NULL) in ld_generic_open_outfile()
2652 ld_state.outfname = "a.out"; in ld_generic_open_outfile()
2654 size_t outfname_len = strlen (ld_state.outfname); in ld_generic_open_outfile()
2655 char *tempfname = (char *) obstack_alloc (&ld_state.smem, in ld_generic_open_outfile()
2657 ld_state.tempfname = tempfname; in ld_generic_open_outfile()
2663 strcpy (mempcpy (tempfname, ld_state.outfname, outfname_len), ".XXXXXX"); in ld_generic_open_outfile()
2671 ld_state.file_type == relocatable_file_type in ld_generic_open_outfile()
2679 ld_state.outfd = fd; in ld_generic_open_outfile()
2686 Elf *elf = ld_state.outelf = elf_begin (fd, in ld_generic_open_outfile()
2711 if (ld_state.file_type == executable_file_type) in ld_generic_open_outfile()
2713 else if (ld_state.file_type == dso_file_type) in ld_generic_open_outfile()
2717 assert (ld_state.file_type == relocatable_file_type); in ld_generic_open_outfile()
2743 struct symbol *runp = ld_state.from_dso; in compute_copy_reloc_offset()
2771 while ((runp = runp->next) != ld_state.from_dso); in compute_copy_reloc_offset()
2782 struct symbol *runp = ld_state.common_syms; in compute_common_symbol_offset()
2803 while ((runp = runp->next) != ld_state.common_syms); in compute_common_symbol_offset()
2842 ++ld_state.nnotesections; in match_section()
2844 ld_state.allsections[ld_state.nallsections++] = (*scnhead); in match_section()
2900 newp = (struct scnhead *) obstack_calloc (&ld_state.smem, in match_section()
2917 ++ld_state.nnotesections; in match_section()
2919 ld_state.allsections[ld_state.nallsections++] = newp; in match_section()
2926 queued = ld_state.allsections[ld_state.nallsections - 1]; in match_section()
2940 queued->flags = ebl_sh_flags_combine (ld_state.ebl, in match_section()
2959 struct scnhead *temp[ld_state.nallsections]; in sort_sections_lscript()
2962 memcpy (temp, ld_state.allsections, in sort_sections_lscript()
2963 ld_state.nallsections * sizeof (temp[0])); in sort_sections_lscript()
2964 size_t nallsections = ld_state.nallsections; in sort_sections_lscript()
2967 struct output_segment *segment = ld_state.output_segments->next; in sort_sections_lscript()
2968 ld_state.output_segments->next = NULL; in sort_sections_lscript()
2969 ld_state.output_segments = segment; in sort_sections_lscript()
2974 ld_state.nallsections = 0; in sort_sections_lscript()
3003 last_writable = ld_state.nallsections - 1; in sort_sections_lscript()
3010 if (ld_state.ncopy > 0 || ld_state.common_syms != NULL) in sort_sections_lscript()
3015 if (ld_state.allsections[last_writable]->type != SHT_NOBITS) in sort_sections_lscript()
3021 memmove (&ld_state.allsections[last_writable + 1], in sort_sections_lscript()
3022 &ld_state.allsections[last_writable], in sort_sections_lscript()
3023 (ld_state.nallsections - last_writable) in sort_sections_lscript()
3024 * sizeof (ld_state.allsections[0])); in sort_sections_lscript()
3026 ld_state.allsections[last_writable] = (struct scnhead *) in sort_sections_lscript()
3027 obstack_calloc (&ld_state.smem, sizeof (struct scnhead)); in sort_sections_lscript()
3030 ld_state.allsections[last_writable]->name = ".bss"; in sort_sections_lscript()
3032 ld_state.allsections[last_writable]->type = SHT_NOBITS; in sort_sections_lscript()
3034 ld_state.allsections[last_writable]->segment_nr in sort_sections_lscript()
3035 = ld_state.allsections[last_writable - 1]->segment_nr; in sort_sections_lscript()
3040 if (ld_state.ncopy > 0) in sort_sections_lscript()
3044 obstack_calloc (&ld_state.smem, sizeof (*si) + sizeof (XElf_Shdr)); in sort_sections_lscript()
3047 struct scninfo *si = (struct scninfo *) obstack_calloc (&ld_state.smem, in sort_sections_lscript()
3057 ld_state.copy_section = si; in sort_sections_lscript()
3059 if (likely (ld_state.allsections[last_writable]->last != NULL)) in sort_sections_lscript()
3061 si->next = ld_state.allsections[last_writable]->last->next; in sort_sections_lscript()
3062 ld_state.allsections[last_writable]->last->next = si; in sort_sections_lscript()
3063 ld_state.allsections[last_writable]->last = si; in sort_sections_lscript()
3066 ld_state.allsections[last_writable]->last = si->next = si; in sort_sections_lscript()
3070 if (ld_state.common_syms != NULL) in sort_sections_lscript()
3074 obstack_calloc (&ld_state.smem, sizeof (*si) + sizeof (XElf_Shdr)); in sort_sections_lscript()
3077 struct scninfo *si = (struct scninfo *) obstack_calloc (&ld_state.smem, in sort_sections_lscript()
3087 ld_state.common_section = si; in sort_sections_lscript()
3089 if (likely (ld_state.allsections[last_writable]->last != NULL)) in sort_sections_lscript()
3091 si->next = ld_state.allsections[last_writable]->last->next; in sort_sections_lscript()
3092 ld_state.allsections[last_writable]->last->next = si; in sort_sections_lscript()
3093 ld_state.allsections[last_writable]->last = si; in sort_sections_lscript()
3096 ld_state.allsections[last_writable]->last = si->next = si; in sort_sections_lscript()
3117 ld_generic_create_sections (struct ld_state *statep) in ld_generic_create_sections()
3125 if (ld_state.file_type != relocatable_file_type) in ld_generic_create_sections()
3130 for (cnt = 0; cnt < ld_state.nallsections; ++cnt) in ld_generic_create_sections()
3131 if ((ld_state.allsections[cnt]->type == SHT_REL in ld_generic_create_sections()
3132 || ld_state.allsections[cnt]->type == SHT_RELA) in ld_generic_create_sections()
3135 && ld_state.allsections[cnt]->last != NULL) in ld_generic_create_sections()
3138 list = ld_state.allsections[cnt]->last; in ld_generic_create_sections()
3143 list->next = ld_state.allsections[cnt]->last->next; in ld_generic_create_sections()
3144 ld_state.allsections[cnt]->last->next = first; in ld_generic_create_sections()
3145 list = ld_state.allsections[cnt]->last; in ld_generic_create_sections()
3149 ld_state.allsections[cnt] = NULL; in ld_generic_create_sections()
3151 ld_state.rellist = list; in ld_generic_create_sections()
3153 if (ld_state.output_segments == NULL) in ld_generic_create_sections()
3162 for (cnt = 0; cnt < ld_state.nallsections; ++cnt) in ld_generic_create_sections()
3164 struct scnhead *head = ld_state.allsections[cnt]; in ld_generic_create_sections()
3177 if (ld_state.file_type == relocatable_file_type in ld_generic_create_sections()
3210 scn = elf_newscn (ld_state.outelf); in ld_generic_create_sections()
3221 here_group->next = ld_state.groups; in ld_generic_create_sections()
3229 = ebl_strtabadd (ld_state.shstrtab, in ld_generic_create_sections()
3238 ld_state.groups = here_group; in ld_generic_create_sections()
3243 here_group = ld_state.groups; in ld_generic_create_sections()
3275 head->nameent = ebl_strtabadd (ld_state.shstrtab, head->name, 0); in ld_generic_create_sections()
3279 scn = elf_newscn (ld_state.outelf); in ld_generic_create_sections()
3302 ld_state.dynsymscnidx = elf_ndxscn (scn); in ld_generic_create_sections()
3306 groups = ld_state.groups; in ld_generic_create_sections()
3314 scn = elf_getscn (ld_state.outelf, groups->outscnidx); in ld_generic_create_sections()
3354 bool result = ld_state.default_bind_local; in reduce_symbol_p()
3381 verp = ld_version_str_tab_find (&ld_state.version_str_tab, in reduce_symbol_p()
3417 xelf_getshdr (elf_getscn (ld_state.outelf, 1), shdr); in eval_expression()
3425 val = ld_state.pagesize; in eval_expression()
3575 if (ld_state.is_system_library) in optimal_bucket_size()
3621 if (ld_state.entry != NULL) in find_entry_point()
3623 struct symbol search = { .name = ld_state.entry }; in find_entry_point()
3626 syment = ld_symbol_tab_find (&ld_state.symbol_tab, in find_entry_point()
3627 elf_hash (ld_state.entry), &search); in find_entry_point()
3631 Elf_Data *data = elf_getdata (elf_getscn (ld_state.outelf, in find_entry_point()
3632 ld_state.symscnidx), NULL); in find_entry_point()
3638 xelf_getsym (data, ld_state.dblindirect[syment->outsymidx], sym); in find_entry_point()
3640 if (sym == NULL && ld_state.need_dynsym && syment->outdynsymidx != 0) in find_entry_point()
3643 data = elf_getdata (elf_getscn (ld_state.outelf, in find_entry_point()
3644 ld_state.dynsymscnidx), NULL); in find_entry_point()
3657 assert (ld_state.need_symtab); in find_entry_point()
3658 assert (ld_state.symscnidx != 0); in find_entry_point()
3671 if (ld_state.file_type == executable_file_type) in find_entry_point()
3673 if (ld_state.entry != NULL) in find_entry_point()
3676 ld_state.entry, in find_entry_point()
3677 xelf_getclass (ld_state.outelf) == ELFCLASS32 ? 10 : 18, in find_entry_point()
3682 xelf_getclass (ld_state.outelf) == ELFCLASS32 ? 10 : 18, in find_entry_point()
3694 assert (ld_state.file_type != relocatable_file_type); in fillin_special_symbol()
3719 Elf_Data *data = elf_getdata (elf_getscn (ld_state.outelf, scnidx), in fillin_special_symbol()
3724 assert (elf_getdata (elf_getscn (ld_state.outelf, scnidx), data) in fillin_special_symbol()
3781 runp->verdefused[def->vd_ndx] = ld_state.nextveridx++; in allocate_version_names()
3797 size_t verneed_size = xelf_fsize (ld_state.outelf, ELF_T_VNEED, 1); in create_verneed_data()
3798 size_t vernaux_size = xelf_fsize (ld_state.outelf, ELF_T_VNAUX, 1); in create_verneed_data()
3902 optimal_gnu_hash_size (gnuhashcodes, nsym_dyn, ld_state.optlevel, in create_gnu_hash()
3906 Elf_Scn *hashscn = elf_getscn (ld_state.outelf, ld_state.gnuhashscnidx); in create_gnu_hash()
3914 shdr->sh_link = ld_state.dynsymscnidx; in create_gnu_hash()
3917 hashdata->d_size = (xelf_fsize (ld_state.outelf, ELF_T_ADDR, in create_gnu_hash()
3929 gnu_buckets = &gnu_bitmask[xelf_fsize (ld_state.outelf, ELF_T_ADDR, in create_gnu_hash()
3960 bool bm32 = (xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1) in create_gnu_hash()
4055 nbucket = optimal_bucket_size (hashcodes, nsym_dyn, ld_state.optlevel); in create_hash()
4057 Elf_Scn *hashscn = elf_getscn (ld_state.outelf, ld_state.hashscnidx); in create_hash()
4065 shdr->sh_link = ld_state.dynsymscnidx; in create_hash()
4117 if (strcmp (ld_state.build_id, "md5") == 0 in create_build_id_section()
4118 || strcmp (ld_state.build_id, "uuid") == 0) in create_build_id_section()
4120 else if (strcmp (ld_state.build_id, "sha1") == 0) in create_build_id_section()
4124 assert (ld_state.build_id[0] == '0' && ld_state.build_id[1] == 'x'); in create_build_id_section()
4127 d->d_size += strlen (ld_state.build_id) / 2; in create_build_id_section()
4141 (void) elf_getshdrstrndx (ld_state.outelf, &shstrndx); in compute_hash_sum()
4143 const char *ident = elf_getident (ld_state.outelf, NULL); in compute_hash_sum()
4151 while ((scn = elf_nextscn (ld_state.outelf, scn)) != NULL) in compute_hash_sum()
4158 if (SECTION_STRIP_P (shdr, elf_strptr (ld_state.outelf, shstrndx, in compute_hash_sum()
4179 if (gelf_xlatetof (ld_state.outelf, data, data, ident[EI_DATA]) in compute_hash_sum()
4188 if (gelf_xlatetom (ld_state.outelf, data, data, ident[EI_DATA]) in compute_hash_sum()
4202 Elf_Data *d = elf_getdata (elf_getscn (ld_state.outelf, in compute_build_id()
4203 ld_state.buildidscnidx), NULL); in compute_build_id()
4211 if (strcmp (ld_state.build_id, "sha1") == 0) in compute_build_id()
4227 else if (strcmp (ld_state.build_id, "md5") == 0) in compute_build_id()
4243 else if (strcmp (ld_state.build_id, "uuid") == 0) in compute_build_id()
4259 const char *cp = ld_state.build_id + 2; in compute_build_id()
4294 ld_generic_create_outfile (struct ld_state *statep) in ld_generic_create_outfile()
4339 if (ld_state.need_symtab) in ld_generic_create_outfile()
4343 symscn = elf_newscn (ld_state.outelf); in ld_generic_create_outfile()
4344 ld_state.symscnidx = elf_ndxscn (symscn); in ld_generic_create_outfile()
4354 nsym_allocated = (1 + ld_state.nsymtab + ld_state.nplt + ld_state.ngot in ld_generic_create_outfile()
4355 + ld_state.nusedsections + ld_state.nlscript_syms); in ld_generic_create_outfile()
4356 symdata->d_size = xelf_fsize (ld_state.outelf, ELF_T_SYM, in ld_generic_create_outfile()
4361 if (unlikely (ld_state.nusedsections >= SHN_LORESERVE)) in ld_generic_create_outfile()
4363 xndxscn = elf_newscn (ld_state.outelf); in ld_generic_create_outfile()
4364 ld_state.xndxscnidx = elf_ndxscn (xndxscn); in ld_generic_create_outfile()
4377 xndxdata->d_size = xelf_fsize (ld_state.outelf, ELF_T_WORD, in ld_generic_create_outfile()
4381 xelf_fsize (ld_state.outelf, ELF_T_WORD, in ld_generic_create_outfile()
4390 assert (ld_state.need_dynsym); in ld_generic_create_outfile()
4394 symscn = elf_getscn (ld_state.outelf, ld_state.dynsymscnidx); in ld_generic_create_outfile()
4405 nsym_allocated = (1 + ld_state.nsymtab + ld_state.nplt + ld_state.ngot in ld_generic_create_outfile()
4406 - ld_state.nlocalsymbols + ld_state.nlscript_syms); in ld_generic_create_outfile()
4407 symdata->d_size = xelf_fsize (ld_state.outelf, ELF_T_SYM, in ld_generic_create_outfile()
4413 xelf_fsize (ld_state.outelf, ELF_T_SYM, 1)); in ld_generic_create_outfile()
4416 symdata->d_align = xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1); in ld_generic_create_outfile()
4427 for (cnt = 0; cnt < ld_state.nallsections; ++cnt) in ld_generic_create_outfile()
4429 struct scnhead *head = ld_state.allsections[cnt]; in ld_generic_create_outfile()
4440 scn = elf_getscn (ld_state.outelf, head->scnidx); in ld_generic_create_outfile()
4451 const char *interp = ld_state.interp ?: "/lib/ld.so.1"; in ld_generic_create_outfile()
4462 ld_state.interpscnidx = head->scnidx; in ld_generic_create_outfile()
4470 ld_state.gotscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4473 INITIALIZE_GOT (&ld_state, scn); in ld_generic_create_outfile()
4481 ld_state.gotpltscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4484 INITIALIZE_GOTPLT (&ld_state, scn); in ld_generic_create_outfile()
4499 outdata->d_size = ld_state.relsize_total; in ld_generic_create_outfile()
4501 outdata->d_type = (REL_TYPE (&ld_state) == DT_REL in ld_generic_create_outfile()
4504 outdata->d_align = xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1); in ld_generic_create_outfile()
4507 ld_state.reldynscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4518 if (ld_state.dt_flags != 0) in ld_generic_create_outfile()
4519 ++ld_state.ndynamic; in ld_generic_create_outfile()
4520 if (ld_state.dt_flags_1 != 0) in ld_generic_create_outfile()
4521 ++ld_state.ndynamic; in ld_generic_create_outfile()
4522 if (ld_state.dt_feature_1 != 0) in ld_generic_create_outfile()
4523 ++ld_state.ndynamic; in ld_generic_create_outfile()
4532 outdata->d_size = xelf_fsize (ld_state.outelf, ELF_T_DYN, in ld_generic_create_outfile()
4533 ld_state.ndynamic); in ld_generic_create_outfile()
4537 outdata->d_align = xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1); in ld_generic_create_outfile()
4540 ld_state.dynamicscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4548 assert (ld_state.dynsymscnidx == elf_ndxscn (scn)); in ld_generic_create_outfile()
4556 ld_state.dynstrscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4565 if (ld_state.ndsofiles > 0) in ld_generic_create_outfile()
4567 struct usedfiles *frunp = ld_state.dsofiles; in ld_generic_create_outfile()
4573 while ((frunp = frunp->next) != ld_state.dsofiles); in ld_generic_create_outfile()
4580 if (ld_state.runpath != NULL || ld_state.rpath != NULL) in ld_generic_create_outfile()
4589 if (ld_state.runpath != NULL) in ld_generic_create_outfile()
4591 startp = ld_state.runpath; in ld_generic_create_outfile()
4596 startp = ld_state.rpath; in ld_generic_create_outfile()
4604 cp = str = (char *) obstack_alloc (&ld_state.smem, len); in ld_generic_create_outfile()
4616 ld_state.rxxpath_strent = ebl_strtabadd (dynstrtab, str, len); in ld_generic_create_outfile()
4617 ld_state.rxxpath_tag = tag; in ld_generic_create_outfile()
4626 ld_state.hashscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4634 ld_state.gnuhashscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4642 ld_state.pltscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4645 INITIALIZE_PLT (&ld_state, scn); in ld_generic_create_outfile()
4653 ld_state.pltrelscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4656 INITIALIZE_PLTREL (&ld_state, scn); in ld_generic_create_outfile()
4664 ld_state.versymscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4672 ld_state.verneedscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4680 ld_state.buildidscnidx = elf_ndxscn (scn); in ld_generic_create_outfile()
4692 if (ld_state.need_symtab) in ld_generic_create_outfile()
4739 if (ld_state.file_type == relocatable_file_type) in ld_generic_create_outfile()
4766 data->d_size = xelf_fsize (ld_state.outelf, type, head->relsize); in ld_generic_create_outfile()
4769 data->d_align = xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1); in ld_generic_create_outfile()
5111 if (ld_state.add_ld_comment in ld_generic_create_outfile()
5158 if (ld_state.got_symbol != NULL) in ld_generic_create_outfile()
5162 fillin_special_symbol (ld_state.got_symbol, ld_state.gotpltscnidx, in ld_generic_create_outfile()
5167 if (ld_state.dyn_symbol != NULL) in ld_generic_create_outfile()
5170 fillin_special_symbol (ld_state.dyn_symbol, ld_state.dynamicscnidx, in ld_generic_create_outfile()
5176 if (ld_state.lscript_syms != NULL) in ld_generic_create_outfile()
5178 struct symbol *rsym = ld_state.lscript_syms; in ld_generic_create_outfile()
5188 file = ld_state.relfiles->next; in ld_generic_create_outfile()
5189 symdata = elf_getdata (elf_getscn (ld_state.outelf, ld_state.symscnidx), in ld_generic_create_outfile()
5200 assert (ld_state.file_type != relocatable_file_type in ld_generic_create_outfile()
5213 for (cnt = ld_state.need_symtab ? 1 : file->nlocalsymbols; cnt < maxcnt; in ld_generic_create_outfile()
5226 if (ld_state.need_symtab) in ld_generic_create_outfile()
5235 < ld_state.nallsections); in ld_generic_create_outfile()
5236 file->symindirect[cnt] = ld_state.allsections[file->scninfo[xndx].allsectionsidx]->scnsymidx; in ld_generic_create_outfile()
5244 if ((ld_state.strip >= strip_all || !ld_state.need_symtab) in ld_generic_create_outfile()
5265 if (!ld_state.export_all_dynamic && !ld_state.need_symtab) in ld_generic_create_outfile()
5289 if (!ld_state.need_symtab) in ld_generic_create_outfile()
5330 sym->st_value = (ld_state.common_section->offset in ld_generic_create_outfile()
5332 assert (ld_state.common_section->outscnndx < SHN_LORESERVE); in ld_generic_create_outfile()
5333 sym->st_shndx = ld_state.common_section->outscnndx; in ld_generic_create_outfile()
5339 if (SPECIAL_SECTION_NUMBER_P (&ld_state, sym->st_shndx)) in ld_generic_create_outfile()
5349 && (ld_state.strip < strip_everything in ld_generic_create_outfile()
5390 = ld_symbol_tab_find (&ld_state.symbol_tab, in ld_generic_create_outfile()
5416 while ((file = file->next) != ld_state.relfiles->next); in ld_generic_create_outfile()
5422 if (ld_state.verneedscnidx != 0) in ld_generic_create_outfile()
5430 runp = ld_state.dsofiles->next; in ld_generic_create_outfile()
5433 while ((runp = runp->next) != ld_state.dsofiles->next); in ld_generic_create_outfile()
5435 if (ld_state.needed != NULL) in ld_generic_create_outfile()
5437 runp = ld_state.needed->next; in ld_generic_create_outfile()
5440 while ((runp = runp->next) != ld_state.needed->next); in ld_generic_create_outfile()
5445 if (ld_state.default_bind_local || ld_state.version_str_tab.filled > 0) in ld_generic_create_outfile()
5472 if (ld_state.strip == strip_everything) in ld_generic_create_outfile()
5501 if (ld_state.from_dso != NULL) in ld_generic_create_outfile()
5504 size_t plt_base = nsym + ld_state.nfrom_dso - ld_state.nplt; in ld_generic_create_outfile()
5508 assert (ld_state.nfrom_dso >= ld_state.nplt); in ld_generic_create_outfile()
5509 runp = ld_state.from_dso; in ld_generic_create_outfile()
5556 char *newp = (char *) obstack_alloc (&ld_state.smem, namelen); in ld_generic_create_outfile()
5570 while ((runp = runp->next) != ld_state.from_dso); in ld_generic_create_outfile()
5573 assert (plt_idx == ld_state.nplt); in ld_generic_create_outfile()
5579 symdata->d_size = xelf_fsize (ld_state.outelf, ELF_T_SYM, nsym); in ld_generic_create_outfile()
5581 xndxdata->d_size = xelf_fsize (ld_state.outelf, ELF_T_WORD, nsym); in ld_generic_create_outfile()
5584 strscn = elf_newscn (ld_state.outelf); in ld_generic_create_outfile()
5585 ld_state.strscnidx = elf_ndxscn (strscn); in ld_generic_create_outfile()
5625 ld_state.dblindirect = dblindirect in ld_generic_create_outfile()
5648 && (ld_state.need_symtab || ld_state.export_all_dynamic)) in ld_generic_create_outfile()
5726 if (ld_state.versymscnidx != 0) in ld_generic_create_outfile()
5731 versymscn = elf_getscn (ld_state.outelf, ld_state.versymscnidx); in ld_generic_create_outfile()
5738 versymdata->d_size = xelf_fsize (ld_state.outelf, ELF_T_HALF, in ld_generic_create_outfile()
5741 versymdata->d_align = xelf_fsize (ld_state.outelf, ELF_T_HALF, 1); in ld_generic_create_outfile()
5751 if (unlikely (!ld_state.need_symtab)) in ld_generic_create_outfile()
5755 size_t reduce = xelf_fsize (ld_state.outelf, ELF_T_SYM, nsym_local - 1); in ld_generic_create_outfile()
5797 else if (ld_state.need_dynsym) in ld_generic_create_outfile()
5802 dynsymscn = elf_getscn (ld_state.outelf, ld_state.dynsymscnidx); in ld_generic_create_outfile()
5805 dynstrdata = elf_newdata (elf_getscn (ld_state.outelf, in ld_generic_create_outfile()
5806 ld_state.dynstrscnidx)); in ld_generic_create_outfile()
5813 dynsymdata->d_size = xelf_fsize (ld_state.outelf, ELF_T_SYM, in ld_generic_create_outfile()
5816 xelf_fsize (ld_state.outelf, ELF_T_SYM, 1)); in ld_generic_create_outfile()
5819 dynsymdata->d_align = xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1); in ld_generic_create_outfile()
5823 hashcodes = (Elf32_Word *) xcalloc (__builtin_popcount ((int) ld_state.hash_style) in ld_generic_create_outfile()
5856 || (!ld_state.export_all_dynamic in ld_generic_create_outfile()
5878 if (ld_state.file_type != relocatable_file_type) in ld_generic_create_outfile()
5883 assert (ld_state.hashscnidx != 0 || ld_state.gnuhashscnidx != 0); in ld_generic_create_outfile()
5928 versymdata->d_size = xelf_fsize (ld_state.outelf, ELF_T_HALF, in ld_generic_create_outfile()
5935 shdr->sh_link = ld_state.dynsymscnidx; in ld_generic_create_outfile()
5941 if (ld_state.file_type != relocatable_file_type) in ld_generic_create_outfile()
5968 if (ld_state.verneedscnidx != 0) in ld_generic_create_outfile()
5973 size_t verneed_size = xelf_fsize (ld_state.outelf, ELF_T_VNEED, 1); in ld_generic_create_outfile()
5974 size_t vernaux_size = xelf_fsize (ld_state.outelf, ELF_T_VNAUX, 1); in ld_generic_create_outfile()
5978 verneedscn = elf_getscn (ld_state.outelf, ld_state.verneedscnidx); in ld_generic_create_outfile()
5986 verneeddata->d_size = (ld_state.nverdeffile * verneed_size in ld_generic_create_outfile()
5987 + ld_state.nverdefused * vernaux_size); in ld_generic_create_outfile()
5990 verneeddata->d_align = xelf_fsize (ld_state.outelf, ELF_T_WORD, 1); in ld_generic_create_outfile()
5994 ntotal = ld_state.nverdeffile; in ld_generic_create_outfile()
5995 runp = ld_state.dsofiles->next; in ld_generic_create_outfile()
6002 while (ntotal > 0 && runp != ld_state.dsofiles->next); in ld_generic_create_outfile()
6006 runp = ld_state.needed->next; in ld_generic_create_outfile()
6013 while (ntotal > 0 && runp != ld_state.needed->next); in ld_generic_create_outfile()
6019 shdr->sh_link = ld_state.dynstrscnidx; in ld_generic_create_outfile()
6020 shdr->sh_info = ld_state.nverdeffile; in ld_generic_create_outfile()
6025 dynsymdata->d_size = xelf_fsize (ld_state.outelf, ELF_T_SYM, nsym_dyn); in ld_generic_create_outfile()
6027 versymdata->d_size = xelf_fsize (ld_state.outelf, ELF_T_HALF, in ld_generic_create_outfile()
6035 shdr->sh_link = ld_state.dynstrscnidx; in ld_generic_create_outfile()
6044 ld_state.ndynsym = nsym_dyn; in ld_generic_create_outfile()
6047 symscn = elf_getscn (ld_state.outelf, ld_state.symscnidx); in ld_generic_create_outfile()
6055 shdr->sh_link = ld_state.strscnidx; in ld_generic_create_outfile()
6057 shdr->sh_entsize = xelf_fsize (ld_state.outelf, ELF_T_SYM, 1); in ld_generic_create_outfile()
6063 if (ld_state.symscnidx != 0) in ld_generic_create_outfile()
6064 symtab_ent = ebl_strtabadd (ld_state.shstrtab, ".symtab", 8); in ld_generic_create_outfile()
6065 if (ld_state.xndxscnidx != 0) in ld_generic_create_outfile()
6066 xndx_ent = ebl_strtabadd (ld_state.shstrtab, ".symtab_shndx", 14); in ld_generic_create_outfile()
6067 if (ld_state.strscnidx != 0) in ld_generic_create_outfile()
6068 strtab_ent = ebl_strtabadd (ld_state.shstrtab, ".strtab", 8); in ld_generic_create_outfile()
6079 shstrtab_scn = elf_newscn (ld_state.outelf); in ld_generic_create_outfile()
6087 shstrtab_ent = ebl_strtabadd (ld_state.shstrtab, ".shstrtab", 10); in ld_generic_create_outfile()
6098 ebl_strtabfinalize (ld_state.shstrtab, data); in ld_generic_create_outfile()
6101 for (cnt = 0; cnt < ld_state.nallsections; ++cnt) in ld_generic_create_outfile()
6102 if (ld_state.allsections[cnt]->scnidx != 0) in ld_generic_create_outfile()
6106 scn = elf_getscn (ld_state.outelf, ld_state.allsections[cnt]->scnidx); in ld_generic_create_outfile()
6111 shdr->sh_name = ebl_strtaboffset (ld_state.allsections[cnt]->nameent); in ld_generic_create_outfile()
6121 Elf_Scn *scn = elf_getscn (ld_state.outelf, ld_state.symscnidx); in ld_generic_create_outfile()
6133 Elf_Scn *scn = elf_getscn (ld_state.outelf, ld_state.xndxscnidx); in ld_generic_create_outfile()
6145 Elf_Scn *scn = elf_getscn (ld_state.outelf, ld_state.strscnidx); in ld_generic_create_outfile()
6173 groups = ld_state.groups; in ld_generic_create_outfile()
6176 Elf_Scn *scn = elf_getscn (ld_state.outelf, groups->outscnidx); in ld_generic_create_outfile()
6183 shdr->sh_link = ld_state.symscnidx; in ld_generic_create_outfile()
6196 shdr->sh_info = ld_state.dblindirect[si]; in ld_generic_create_outfile()
6206 if (ld_state.file_type != relocatable_file_type) in ld_generic_create_outfile()
6220 struct output_segment *segment = ld_state.output_segments; in ld_generic_create_outfile()
6228 nphdr += ld_state.nnotesections; in ld_generic_create_outfile()
6237 if (ld_state.interp != NULL || ld_state.file_type != dso_file_type) in ld_generic_create_outfile()
6242 if (ld_state.need_tls) in ld_generic_create_outfile()
6247 if (xelf_newphdr (ld_state.outelf, nphdr) == 0) in ld_generic_create_outfile()
6255 if (elf_update (ld_state.outelf, ELF_C_NULL) == -1) in ld_generic_create_outfile()
6263 Elf_Scn *scn = elf_getscn (ld_state.outelf, in ld_generic_create_outfile()
6264 ld_state.allsections[nsec]->scnidx); in ld_generic_create_outfile()
6282 if (ld_state.interp != NULL in ld_generic_create_outfile()
6283 || ld_state.file_type != dso_file_type) in ld_generic_create_outfile()
6287 segment = ld_state.output_segments; in ld_generic_create_outfile()
6296 segment->align = ld_state.pagesize; in ld_generic_create_outfile()
6304 if (ld_state.allsections[nsec]->name in ld_generic_create_outfile()
6317 isect = first = ld_state.allsections[nsec]->last; in ld_generic_create_outfile()
6330 ld_state.allsections[nsec]->addr = addr; in ld_generic_create_outfile()
6352 if (segment == ld_state.output_segments) in ld_generic_create_outfile()
6391 if (++nsec >= ld_state.nallsections) in ld_generic_create_outfile()
6394 scn = elf_getscn (ld_state.outelf, in ld_generic_create_outfile()
6395 ld_state.allsections[nsec]->scnidx); in ld_generic_create_outfile()
6442 xelf_getphdr_ptr (ld_state.outelf, nphdr, phdr); in ld_generic_create_outfile()
6453 (void) xelf_update_phdr (ld_state.outelf, nphdr, phdr); in ld_generic_create_outfile()
6461 xelf_getehdr (ld_state.outelf, ehdr); in ld_generic_create_outfile()
6465 if (ld_state.need_tls) in ld_generic_create_outfile()
6467 xelf_getphdr_ptr (ld_state.outelf, nphdr, phdr); in ld_generic_create_outfile()
6476 ld_state.tls_tcb = tls_end; in ld_generic_create_outfile()
6477 ld_state.tls_start = tls_start; in ld_generic_create_outfile()
6479 (void) xelf_update_phdr (ld_state.outelf, nphdr, phdr); in ld_generic_create_outfile()
6484 xelf_getphdr_ptr (ld_state.outelf, nphdr, phdr); in ld_generic_create_outfile()
6492 | (ld_state.execstack == execstack_true ? PF_X : 0)); in ld_generic_create_outfile()
6493 phdr->p_align = xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1); in ld_generic_create_outfile()
6495 (void) xelf_update_phdr (ld_state.outelf, nphdr, phdr); in ld_generic_create_outfile()
6501 if (ld_state.need_symtab) in ld_generic_create_outfile()
6518 sym->st_value += ld_state.allsections[shndx - 1]->addr; in ld_generic_create_outfile()
6526 if (ld_state.need_dynsym) in ld_generic_create_outfile()
6538 sym->st_value += ld_state.allsections[sym->st_shndx - 1]->addr; in ld_generic_create_outfile()
6552 while ((se = ld_symbol_tab_iterate (&ld_state.symbol_tab, &p)) != NULL) in ld_generic_create_outfile()
6582 if (ld_state.reldynscnidx != 0) in ld_generic_create_outfile()
6584 assert (ld_state.dynsymscnidx != 0); in ld_generic_create_outfile()
6585 scn = elf_getscn (ld_state.outelf, ld_state.reldynscnidx); in ld_generic_create_outfile()
6589 shdr->sh_link = ld_state.dynsymscnidx; in ld_generic_create_outfile()
6600 if (ld_state.interp != NULL || ld_state.file_type != dso_file_type) in ld_generic_create_outfile()
6602 assert (ld_state.interpscnidx != 0); in ld_generic_create_outfile()
6603 xelf_getshdr (elf_getscn (ld_state.outelf, in ld_generic_create_outfile()
6604 ld_state.interpscnidx), shdr); in ld_generic_create_outfile()
6607 xelf_getphdr_ptr (ld_state.outelf, idx, phdr); in ld_generic_create_outfile()
6610 phdr->p_vaddr = ld_state.output_segments->addr + phdr->p_offset; in ld_generic_create_outfile()
6615 phdr->p_align = xelf_fsize (ld_state.outelf, ELF_T_ADDR, 1); in ld_generic_create_outfile()
6617 (void) xelf_update_phdr (ld_state.outelf, idx, phdr); in ld_generic_create_outfile()
6621 xelf_getphdr_ptr (ld_state.outelf, idx, phdr); in ld_generic_create_outfile()
6631 (void) xelf_update_phdr (ld_state.outelf, idx, phdr); in ld_generic_create_outfile()
6637 assert (ld_state.dynamicscnidx); in ld_generic_create_outfile()
6638 outscn = elf_getscn (ld_state.outelf, ld_state.dynamicscnidx); in ld_generic_create_outfile()
6642 xelf_getphdr_ptr (ld_state.outelf, idx, phdr); in ld_generic_create_outfile()
6652 (void) xelf_update_phdr (ld_state.outelf, idx, phdr); in ld_generic_create_outfile()
6655 assert (ld_state.dynstrscnidx != 0); in ld_generic_create_outfile()
6656 shdr->sh_link = ld_state.dynstrscnidx; in ld_generic_create_outfile()
6664 if (ld_state.ndsofiles > 0) in ld_generic_create_outfile()
6666 struct usedfiles *runp = ld_state.dsofiles->next; in ld_generic_create_outfile()
6673 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6676 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6680 while ((runp = runp->next) != ld_state.dsofiles->next); in ld_generic_create_outfile()
6684 if (ld_state.rxxpath_strent != NULL) in ld_generic_create_outfile()
6685 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6686 ld_state.rxxpath_tag, in ld_generic_create_outfile()
6687 ebl_strtaboffset (ld_state.rxxpath_strent)); in ld_generic_create_outfile()
6691 if (ld_state.init_symbol != NULL) in ld_generic_create_outfile()
6695 if (ld_state.need_symtab) in ld_generic_create_outfile()
6697 dblindirect[ld_state.init_symbol->outsymidx], in ld_generic_create_outfile()
6700 xelf_getsym (dynsymdata, ld_state.init_symbol->outdynsymidx, in ld_generic_create_outfile()
6704 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6707 if (ld_state.fini_symbol != NULL) in ld_generic_create_outfile()
6711 if (ld_state.need_symtab) in ld_generic_create_outfile()
6713 dblindirect[ld_state.fini_symbol->outsymidx], in ld_generic_create_outfile()
6716 xelf_getsym (dynsymdata, ld_state.fini_symbol->outdynsymidx, in ld_generic_create_outfile()
6720 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6726 xelf_getshdr (elf_getscn (ld_state.outelf, ld_state.hashscnidx), in ld_generic_create_outfile()
6729 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, DT_HASH, in ld_generic_create_outfile()
6733 assert (ld_state.dynsymscnidx != 0); in ld_generic_create_outfile()
6734 xelf_getshdr (elf_getscn (ld_state.outelf, ld_state.dynsymscnidx), in ld_generic_create_outfile()
6737 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, DT_SYMTAB, in ld_generic_create_outfile()
6740 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, DT_SYMENT, in ld_generic_create_outfile()
6741 xelf_fsize (ld_state.outelf, ELF_T_SYM, 1)); in ld_generic_create_outfile()
6744 xelf_getshdr (elf_getscn (ld_state.outelf, ld_state.dynstrscnidx), in ld_generic_create_outfile()
6747 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, DT_STRTAB, in ld_generic_create_outfile()
6750 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, DT_STRSZ, in ld_generic_create_outfile()
6754 if (ld_state.nplt > 0) in ld_generic_create_outfile()
6757 xelf_getshdr (elf_getscn (ld_state.outelf, in ld_generic_create_outfile()
6758 ld_state.gotpltscnidx), shdr); in ld_generic_create_outfile()
6760 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6765 xelf_getshdr (elf_getscn (ld_state.outelf, in ld_generic_create_outfile()
6766 ld_state.pltrelscnidx), shdr); in ld_generic_create_outfile()
6768 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6771 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6774 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6778 if (ld_state.relsize_total > 0) in ld_generic_create_outfile()
6781 xelf_getshdr (elf_getscn (ld_state.outelf, in ld_generic_create_outfile()
6782 ld_state.reldynscnidx), shdr); in ld_generic_create_outfile()
6784 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6791 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6797 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6800 ? xelf_fsize (ld_state.outelf, ELF_T_REL, 1) in ld_generic_create_outfile()
6801 : xelf_fsize (ld_state.outelf, ELF_T_RELA, in ld_generic_create_outfile()
6805 if (ld_state.verneedscnidx != 0) in ld_generic_create_outfile()
6807 xelf_getshdr (elf_getscn (ld_state.outelf, in ld_generic_create_outfile()
6808 ld_state.verneedscnidx), shdr); in ld_generic_create_outfile()
6810 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6813 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6814 DT_VERNEEDNUM, ld_state.nverdeffile); in ld_generic_create_outfile()
6817 if (ld_state.versymscnidx != 0) in ld_generic_create_outfile()
6819 xelf_getshdr (elf_getscn (ld_state.outelf, in ld_generic_create_outfile()
6820 ld_state.versymscnidx), shdr); in ld_generic_create_outfile()
6822 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6827 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, DT_DEBUG, 0); in ld_generic_create_outfile()
6828 assert (ld_state.ndynamic_filled < ld_state.ndynamic); in ld_generic_create_outfile()
6831 if (ld_state.dt_flags != 0) in ld_generic_create_outfile()
6832 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, DT_FLAGS, in ld_generic_create_outfile()
6833 ld_state.dt_flags); in ld_generic_create_outfile()
6836 if (ld_state.dt_flags_1 != 0) in ld_generic_create_outfile()
6837 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6838 DT_FLAGS_1, ld_state.dt_flags_1); in ld_generic_create_outfile()
6841 if (ld_state.dt_feature_1 != 0) in ld_generic_create_outfile()
6842 new_dynamic_entry (dyndata, ld_state.ndynamic_filled++, in ld_generic_create_outfile()
6843 DT_FEATURE_1, ld_state.dt_feature_1); in ld_generic_create_outfile()
6845 assert (ld_state.ndynamic_filled <= ld_state.ndynamic); in ld_generic_create_outfile()
6860 assert (ld_state.file_type == relocatable_file_type); in ld_generic_create_outfile()
6863 outscn = elf_getscn (ld_state.outelf, rellist->scnidx); in ld_generic_create_outfile()
6869 shdr->sh_link = ld_state.symscnidx; in ld_generic_create_outfile()
6889 if (ld_state.rellist != NULL) in ld_generic_create_outfile()
6891 assert (ld_state.file_type != relocatable_file_type); in ld_generic_create_outfile()
6898 xelf_getehdr (ld_state.outelf, ehdr); in ld_generic_create_outfile()
6909 Elf_Scn *scn = elf_getscn (ld_state.outelf, 0); in ld_generic_create_outfile()
6924 if (ld_state.file_type != relocatable_file_type) in ld_generic_create_outfile()
6928 if (unlikely (xelf_update_ehdr (ld_state.outelf, ehdr) == 0)) in ld_generic_create_outfile()
6935 free (ld_state.dblindirect); in ld_generic_create_outfile()
6943 if (ld_state.build_id != NULL) in ld_generic_create_outfile()
6957 ld_generic_relocate_section (struct ld_state *statep, Elf_Scn *outscn, in ld_generic_relocate_section()
6969 ld_generic_finalize (struct ld_state *statep) in ld_generic_finalize()
6972 if (elf_update (ld_state.outelf, ELF_C_WRITE) == -1) in ld_generic_finalize()
6977 if (elf_end (ld_state.outelf) != 0) in ld_generic_finalize()
6983 if (fstat (ld_state.outfd, &temp_st) != 0) in ld_generic_finalize()
6988 if (rename (ld_state.tempfname, ld_state.outfname) != 0) in ld_generic_finalize()
6994 if (stat (ld_state.outfname, &new_st) != 0 in ld_generic_finalize()
6999 unlink (ld_state.outfname); in ld_generic_finalize()
7005 (void) close (ld_state.outfd); in ld_generic_finalize()
7008 ld_state.tempfname = NULL; in ld_generic_finalize()
7015 ld_generic_special_section_number_p (struct ld_state *statep, size_t number) in ld_generic_special_section_number_p()
7023 ld_generic_section_type_p (struct ld_state *statep, GElf_Word type) in ld_generic_section_type_p()
7039 ld_generic_dynamic_section_flags (struct ld_state *statep) in ld_generic_dynamic_section_flags()
7048 ld_generic_initialize_plt (struct ld_state *statep, Elf_Scn *scn) in ld_generic_initialize_plt()
7059 ld_generic_initialize_pltrel (struct ld_state *statep, Elf_Scn *scn) in ld_generic_initialize_pltrel()
7070 ld_generic_initialize_got (struct ld_state *statep, Elf_Scn *scn) in ld_generic_initialize_got()
7081 ld_generic_initialize_gotplt (struct ld_state *statep, Elf_Scn *scn) in ld_generic_initialize_gotplt()
7092 ld_generic_finalize_plt (struct ld_state *statep, size_t nsym, size_t nsym_dyn, in ld_generic_finalize_plt()
7100 ld_generic_rel_type (struct ld_state *statep) in ld_generic_rel_type()
7113 ld_generic_count_relocations (struct ld_state *statep, struct scninfo *scninfo) in ld_generic_count_relocations()
7124 ld_generic_create_relocations (struct ld_state *statep, in ld_generic_create_relocations()