1 /* Copyright (C) 2001, 2002, 2003, 2005, 2006, 2008, 2009 Red Hat, Inc.
2 This file is part of Red Hat elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2001.
5 Red Hat elfutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by the
7 Free Software Foundation; version 2 of the License.
9 Red Hat elfutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with Red Hat elfutils; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
18 Red Hat elfutils is an included package of the Open Invention Network.
19 An included package of the Open Invention Network is a package for which
20 Open Invention Network licensees cross-license their patents. No patent
21 license is granted, either expressly or impliedly, by designation as an
22 included package. Should you wish to participate in the Open Invention
23 Network licensing program, please visit www.openinventionnetwork.com
24 <http://www.openinventionnetwork.com>. */
36 /* Recommended size of the buffer passed to ld_strerror. */
37 #define ERRBUFSIZE (512)
39 /* Character used to introduce version name after symbol. */
43 /* Methods for handling archives. */
46 defaultextract, /* Weak references don't cause archive member to
48 weakextract, /* Weak references cause archive member to be
50 allextract /* Extract all archive members regardless of
51 references (aka whole-archive). */
55 /* Type of output file. */
58 no_file_type = 0, /* None selected so far. */
59 executable_file_type, /* Executable. */
60 dso_file_type, /* DSO. */
61 dso_needed_file_type, /* DSO introduced by DT_NEEDED. */
62 relocatable_file_type, /* Relocatable object file. */
63 archive_file_type /* Archive (input only). */
69 /* The next file given at the command line. */
70 struct usedfiles *next;
71 /* Nonzero if this file is the beginning of a group. */
73 /* Nonzero if this file is the end of a group. */
75 /* Pointer to the beginning of the group. It is necessary to
76 explain why we cannot simply use the 'next' pointer and have a
77 circular single-linked list like in many cases. The problem is
78 that the last archive of the group, if it is the last file of the
79 group, contains the only existing pointer to the next file we
80 have to look at. All files are initially connected via the
81 'next' pointer in a single-linked list. Therefore we cannot
82 overwrite this value. It instead will be used once the group is
83 handled and we go on processing the rest of the files. */
84 struct usedfiles *group_backref;
86 /* Name/path of the file. */
88 /* Resolved file name. */
90 /* Name used as reference in DT_NEEDED entries. This is normally
91 the SONAME. If it is missing it's normally the fname above. */
93 /* Handle for the SONAME in the string table. */
94 struct Ebl_Strent *sonameent;
96 /* Help to identify duplicates. */
108 /* How to extract elements from archives. */
109 enum extract_rule extract_rule;
111 /* Lazy-loading rule. */
114 /* If this is a DSO the flag indicates whether the file is directly
115 used in a reference. */
118 /* True when file should be added to DT_NEEDED list only when
119 directly referenced. */
122 /* If nonzero this is the archive sequence number which can be used to
123 determine whether back refernces from -( -) or GROUP statements
124 have to be followed. */
127 /* Pointer to the record for the archive containing this file. */
128 struct usedfiles *archive_file;
130 /* Type of file. We have to distinguish these types since they
131 are searched for differently. */
132 enum file_type file_type;
133 /* This is the ELF library handle for this file. */
136 /* The ELF header. */
139 # define FILEINFO_EHDR(fi) (*(fi))
142 # define FILEINFO_EHDR(fi) (fi)
145 /* Index of the section header string table section. We use a
146 separate field and not the e_shstrndx field in the ELF header
147 since in case of a file with more than 64000 sections the index
148 might be stored in the section header of section zero. The
149 elf_getshdrstrndx() function can find the value but it is too
150 costly to repeat this call over and over. */
153 /* Info about the sections of the file. */
156 /* Handle for the section. Note that we can store a section
157 handle here because the file is not changing. This together
158 with the knowledge about the libelf library is enough for us to
159 assume the section reference remains valid at all times. */
161 /* Section header. */
164 # define SCNINFO_SHDR(si) (*(si))
167 # define SCNINFO_SHDR(si) (si)
169 /* Offset of this files section in the combined section. */
171 /* Index of the section in the output file. */
172 Elf32_Word outscnndx;
173 /* Index of the output section in the 'allsection' array. */
174 Elf32_Word allsectionsidx;
175 /* True if the section is used. */
177 /* True if section is an unused COMDAT section. */
179 /* True if this is a COMDAT group section. */
181 /* Section group number. This is the index of the SHT_GROUP section. */
183 /* Pointer back to the containing file information structure. */
184 struct usedfiles *fileinfo;
185 /* List of symbols in this section (set only for merge-able sections
186 and group sections). */
187 struct symbol *symbols;
188 /* Size of relocations in this section. Only used for relocation
191 /* Pointer to next section which is put in the given output
193 struct scninfo *next;
196 /* List of section group sections. */
197 struct scninfo *groups;
199 /* The symbol table section.
201 XXX Maybe support for more than one symbol table is needed. */
202 Elf_Data *symtabdata;
203 /* Extra section index table section. */
205 /* Dynamic symbol table section. */
206 Elf_Data *dynsymtabdata;
207 /* The version number section. */
208 Elf_Data *versymdata;
209 /* The defined versions. */
210 Elf_Data *verdefdata;
211 /* Number of versions defined. */
213 /* True if the version with the given index number is used in the
215 XElf_Versym *verdefused;
216 /* How many versions are used. */
218 /* Handle for name of the version. */
219 struct Ebl_Strent **verdefent;
220 /* The needed versions. */
221 Elf_Data *verneeddata;
222 /* String table section associated with the symbol table. */
223 Elf32_Word symstridx;
224 /* String table section associated with the dynamic symbol table. */
225 Elf32_Word dynsymstridx;
226 /* Number of entries in the symbol table. */
228 size_t nlocalsymbols;
230 /* Dynamic section. */
233 /* Indirection table for the symbols defined here. */
234 Elf32_Word *symindirect;
235 Elf32_Word *dynsymindirect;
236 /* For undefined or common symbols we need a reference to the symbol
238 struct symbol **symref;
239 struct symbol **dynsymref;
241 /* This is the file descriptor. The value is -1 if the descriptor
242 was already closed. This can happen if we needed file descriptors
243 to open new files. */
245 /* This flag is true if the descriptor was passed to the generic
246 functions from somewhere else. This is an implementation detail;
247 no machine-specific code must use this flag. */
250 /* True if any of the sections is merge-able. */
251 bool has_merge_sections;
255 /* Functions to test for the various types of files we handle. */
257 ld_file_rel_p (struct usedfiles *file)
259 return (elf_kind (file->elf) == ELF_K_ELF
260 && FILEINFO_EHDR (file->ehdr).e_type == ET_REL);
264 ld_file_dso_p (struct usedfiles *file)
266 return (elf_kind (file->elf) == ELF_K_ELF
267 && FILEINFO_EHDR (file->ehdr).e_type == ET_DYN);
271 ld_file_ar_p (struct usedfiles *file)
273 return elf_kind (file->elf) == ELF_K_AR;
279 /* The next path to search. */
280 struct pathelement *next;
283 /* Larger than zero if the directory exists, smaller than zero if not,
284 zero if it is not yet known. */
289 /* Forward declaration. */
293 /* Callback functions. */
296 /* Library names passed to the linker as -lXXX represent files named
297 libXXX.YY. The YY part can have different forms, depending on the
298 architecture. The generic set is .so and .a (in this order). */
299 const char **(*lib_extensions) (struct ld_state *)
300 __attribute__ ((__const__));
301 #define LIB_EXTENSION(state) \
302 DL_CALL_FCT ((state)->callbacks.lib_extensions, (state))
304 /* Process the given file. If the file is not yet open, open it.
305 The first parameter is a file descriptor for the file which can
306 be -1 to indicate the file has not yet been found. The second
307 parameter describes the file to be opened, the last one is the
308 state of the linker which among other information contain the
310 int (*file_process) (int fd, struct usedfiles *, struct ld_state *,
311 struct usedfiles **);
312 #define FILE_PROCESS(fd, file, state, nextp) \
313 DL_CALL_FCT ((state)->callbacks.file_process, (fd, file, state, nextp))
315 /* Close the given file. */
316 int (*file_close) (struct usedfiles *, struct ld_state *);
317 #define FILE_CLOSE(file, state) \
318 DL_CALL_FCT ((state)->callbacks.file_close, (file, state))
320 /* Create the output sections now. This requires knowledge about
321 all the sections we will need. It may be necessary to sort the
322 sections in the order they are supposed to appear in the
323 executable. The sorting use many different kinds of information
324 to optimize the resulting binary. Important is to respect
325 segment boundaries and the needed alignment. The mode of the
326 segments will be determined afterwards automatically by the
328 void (*create_sections) (struct ld_state *);
329 #define CREATE_SECTIONS(state) \
330 DL_CALL_FCT ((state)->callbacks.create_sections, (state))
332 /* Determine whether we have any non-weak unresolved references left. */
333 int (*flag_unresolved) (struct ld_state *);
334 #define FLAG_UNRESOLVED(state) \
335 DL_CALL_FCT ((state)->callbacks.flag_unresolved, (state))
337 /* Create the sections which are generated by the linker and are not
338 present in the input file. */
339 void (*generate_sections) (struct ld_state *);
340 #define GENERATE_SECTIONS(state) \
341 DL_CALL_FCT ((state)->callbacks.generate_sections, (state))
343 /* Open the output file. The file name is given or "a.out". We
344 create as much of the ELF structure as possible. */
345 int (*open_outfile) (struct ld_state *, int, int, int);
346 #define OPEN_OUTFILE(state, machine, class, data) \
347 DL_CALL_FCT ((state)->callbacks.open_outfile, (state, machine, class, data))
349 /* Create the data for the output file. */
350 int (*create_outfile) (struct ld_state *);
351 #define CREATE_OUTFILE(state) \
352 DL_CALL_FCT ((state)->callbacks.create_outfile, (state))
354 /* Process a relocation section. */
355 void (*relocate_section) (struct ld_state *, Elf_Scn *, struct scninfo *,
357 #define RELOCATE_SECTION(state, outscn, first, dblindirect) \
358 DL_CALL_FCT ((state)->callbacks.relocate_section, (state, outscn, first, \
361 /* Allocate a data buffer for the relocations of the given output
363 void (*count_relocations) (struct ld_state *, struct scninfo *);
364 #define COUNT_RELOCATIONS(state, scninfo) \
365 DL_CALL_FCT ((state)->callbacks.count_relocations, (state, scninfo))
367 /* Create relocations for executable or DSO. */
368 void (*create_relocations) (struct ld_state *, const Elf32_Word *);
369 #define CREATE_RELOCATIONS(state, dlbindirect) \
370 DL_CALL_FCT ((state)->callbacks.create_relocations, (state, dblindirect))
372 /* Finalize the output file. */
373 int (*finalize) (struct ld_state *);
374 #define FINALIZE(state) \
375 DL_CALL_FCT ((state)->callbacks.finalize, (state))
377 /* Check whether special section number is known. */
378 bool (*special_section_number_p) (struct ld_state *, size_t);
379 #define SPECIAL_SECTION_NUMBER_P(state, number) \
380 DL_CALL_FCT ((state)->callbacks.special_section_number_p, (state, number))
382 /* Check whether section type is known. */
383 bool (*section_type_p) (struct ld_state *, XElf_Word);
384 #define SECTION_TYPE_P(state, type) \
385 DL_CALL_FCT ((state)->callbacks.section_type_p, (state, type))
387 /* Return section flags for .dynamic section. */
388 XElf_Xword (*dynamic_section_flags) (struct ld_state *);
389 #define DYNAMIC_SECTION_FLAGS(state) \
390 DL_CALL_FCT ((state)->callbacks.dynamic_section_flags, (state))
392 /* Create the data structures for the .plt section and initialize it. */
393 void (*initialize_plt) (struct ld_state *, Elf_Scn *scn);
394 #define INITIALIZE_PLT(state, scn) \
395 DL_CALL_FCT ((state)->callbacks.initialize_plt, (state, scn))
397 /* Create the data structures for the .rel.plt section and initialize it. */
398 void (*initialize_pltrel) (struct ld_state *, Elf_Scn *scn);
399 #define INITIALIZE_PLTREL(state, scn) \
400 DL_CALL_FCT ((state)->callbacks.initialize_pltrel, (state, scn))
402 /* Finalize the .plt section the what belongs to them. */
403 void (*finalize_plt) (struct ld_state *, size_t, size_t, struct symbol **);
404 #define FINALIZE_PLT(state, nsym, nsym_dyn, ndxtosym) \
405 DL_CALL_FCT ((state)->callbacks.finalize_plt, (state, nsym, nsym_dyn, \
408 /* Create the data structures for the .got section and initialize it. */
409 void (*initialize_got) (struct ld_state *, Elf_Scn *scn);
410 #define INITIALIZE_GOT(state, scn) \
411 DL_CALL_FCT ((state)->callbacks.initialize_got, (state, scn))
413 /* Create the data structures for the .got.plt section and initialize it. */
414 void (*initialize_gotplt) (struct ld_state *, Elf_Scn *scn);
415 #define INITIALIZE_GOTPLT(state, scn) \
416 DL_CALL_FCT ((state)->callbacks.initialize_gotplt, (state, scn))
418 /* Return the tag corresponding to the native relocation type for
420 int (*rel_type) (struct ld_state *);
421 #define REL_TYPE(state) \
422 DL_CALL_FCT ((state)->callbacks.rel_type, (state))
426 /* Structure for symbol representation. This data structure is used a
427 lot, so size is important. */
432 /* Size of the object. */
434 /* Index of the symbol in the symbol table of the object. */
436 /* Index of the symbol in the symbol table of the output file. */
439 /* Description where the symbol is found/needed. */
441 struct usedfiles *file;
442 /* Index of the symbol table. */
445 /* Index of the symbol in the dynamic symbol table of the output
446 file. Note that the value only needs to be 16 bit wide since
447 there cannot be more sections in an executable or DSO. */
448 unsigned int outdynsymidx:16;
450 /* Type of the symbol. */
453 unsigned int defined:1;
454 unsigned int common:1;
456 unsigned int added:1;
457 unsigned int merged:1;
458 unsigned int local:1;
459 unsigned int hidden:1;
460 /* Nonzero if the symbol is on the from_dso list. */
461 unsigned int on_dsolist:1;
462 /* Nonzero if symbol needs copy relocation, reset when the
463 relocation has been created. */
464 unsigned int need_copy:1;
465 unsigned int in_dso:1;
469 /* Pointer to the handle created by the functions which create
470 merged section contents. We use 'void *' because there are
471 different implementations used. */
476 /* Pointer to next/previous symbol on whatever list the symbol is. */
478 struct symbol *previous;
479 /* Pointer to next symbol of the same section (only set for merge-able
481 struct symbol *next_in_scn;
485 /* Get the definition for the symbol table. */
486 #include <symbolhash.h>
488 /* Simple single linked list of file names. */
492 struct usedfiles *real;
493 struct filename_list *next;
500 /* Data structure to describe expression in linker script. */
522 struct expression *child;
525 struct expression *left;
526 struct expression *right;
533 /* Data structure for section name with flags. */
534 struct input_section_name
540 /* File name mask with section name. */
541 struct filemask_section_name
543 const char *filemask;
544 const char *excludemask;
545 struct input_section_name *section_name;
549 /* Data structure for assignments. */
552 const char *variable;
553 struct expression *expression;
559 /* Data structure describing input for an output section. */
570 struct assignment *assignment;
571 struct filemask_section_name *section;
574 struct input_rule *next;
578 /* Data structure to describe output section. */
579 struct output_section
582 struct input_rule *input;
583 XElf_Addr max_alignment;
588 /* Data structure to describe output file format. */
599 struct assignment *assignment;
600 struct output_section section;
603 struct output_rule *next;
607 /* List of all the segments the linker script describes. */
608 struct output_segment
611 struct output_rule *output_rules;
612 struct output_segment *next;
620 /* List of identifiers. */
627 id_str, /* Normal string. */
628 id_all, /* "*", matches all. */
629 id_wild /* Globbing wildcard string. */
634 const char *versionname;
638 struct id_list *next;
642 /* Version information. */
645 struct version *next;
646 struct id_list *local_names;
647 struct id_list *global_names;
648 const char *versionname;
649 const char *parentname;
653 /* Head for list of sections. */
656 /* Name of the sections. */
659 /* Accumulated flags for the sections. */
662 /* Type of the sections. */
665 /* Entry size. If there are differencs between the sections with
666 the same name this field contains 1. */
669 /* If non-NULL pointer to group signature. */
670 const char *grp_signature;
672 /* Maximum alignment for all sections. */
675 /* Distinguish between normal sections coming from the input file
676 and sections generated by the linker. */
679 scn_normal, /* Section from the input file(s). */
680 scn_dot_interp, /* Generated .interp section. */
681 scn_dot_got, /* Generated .got section. */
682 scn_dot_gotplt, /* Generated .got.plt section. */
683 scn_dot_dynrel, /* Generated .rel.dyn section. */
684 scn_dot_dynamic, /* Generated .dynamic section. */
685 scn_dot_dynsym, /* Generated .dynsym section. */
686 scn_dot_dynstr, /* Generated .dynstr section. */
687 scn_dot_hash, /* Generated .hash section. */
688 scn_dot_gnu_hash, /* Generated .gnu.hash section. */
689 scn_dot_plt, /* Generated .plt section. */
690 scn_dot_pltrel, /* Generated .rel.plt section. */
691 scn_dot_version, /* Generated .gnu.version section. */
692 scn_dot_version_r, /* Generated .gnu.version_r section. */
693 scn_dot_note_gnu_build_id /* Generated .note.gnu.build-id section. */
696 /* True is the section is used in the output. */
699 /* Total size (only determined this way for relocation sections). */
702 /* Filled in by the section sorting to indicate which segment the
706 /* Index of the output section. We cannot store the section handle
707 directly here since the handle is a pointer in a dynamically
708 allocated table which might move if it becomes too small for all
709 the sections. Using the index the correct value can be found at
713 /* Index of the STT_SECTION entry for this section in the symbol
717 /* Address of the section in the output file. */
720 /* Handle for the section name in the output file's section header
722 struct Ebl_Strent *nameent;
724 /* Tail of list of symbols for this section. Only set if the
725 section is merge-able. */
726 struct symbol *symbols;
728 /* Pointer to last section. */
729 struct scninfo *last;
733 /* Define hash table for sections. */
734 #include <sectionhash.h>
736 /* Define hash table for version symbols. */
737 #include <versionhash.h>
740 /* State of the linker. */
743 /* ELF backend library handle. */
746 /* List of all archives participating, in this order. */
747 struct usedfiles *archives;
748 /* End of the list. */
749 struct usedfiles *tailarchives;
750 /* If nonzero we are looking for the beginning of a group. */
751 bool group_start_requested;
752 /* Pointer to the archive starting the group. */
753 struct usedfiles *group_start_archive;
755 /* List of the DSOs we found. */
756 struct usedfiles *dsofiles;
757 /* Number of DSO files. */
759 /* Ultimate list of object files which are linked in. */
760 struct usedfiles *relfiles;
762 /* List the DT_NEEDED DSOs. */
763 struct usedfiles *needed;
765 /* Temporary storage for the parser. */
766 struct filename_list *srcfiles;
768 /* List of all the paths to look at. */
769 struct pathelement *paths;
770 /* Tail of the list. */
771 struct pathelement *tailpaths;
773 /* User provided paths for lookup of DSOs. */
774 struct pathelement *rpath;
775 struct pathelement *rpath_link;
776 struct pathelement *runpath;
777 struct pathelement *runpath_link;
778 struct Ebl_Strent *rxxpath_strent;
781 /* From the environment variable LD_LIBRARY_PATH. */
782 struct pathelement *ld_library_path1;
783 struct pathelement *ld_library_path2;
785 /* Name of the output file. */
786 const char *outfname;
787 /* Name of the temporary file we initially create. */
788 const char *tempfname;
789 /* File descriptor opened for the output file. */
791 /* The ELF descriptor for the output file. */
794 /* Type of output file. */
795 enum file_type file_type;
797 /* Is this a system library or not. */
798 bool is_system_library;
800 /* Page size to be assumed for the binary. */
803 /* Name of the interpreter for dynamically linked objects. */
805 /* Index of the .interp section. */
806 Elf32_Word interpscnidx;
808 /* Optimization level. */
809 unsigned long int optlevel;
811 /* If true static linking is requested. */
814 /* If true, add DT_NEEDED entries for following files if they are
818 /* How to extract elements from archives. */
819 enum extract_rule extract_rule;
821 /* Sequence number of the last archive we used. */
822 int last_archive_used;
824 /* If true print to stdout information about the files we are
828 /* If true multiple definitions are not considered an error; the
832 /* If true undefined symbols when building DSOs are not fatal. */
835 /* If true add line indentifying link-editor to .comment section. */
838 /* Stripping while linking. */
847 /* The callback function vector. */
848 struct callbacks callbacks;
850 /* Name of the entry symbol. Can also be a numeric value. */
853 /* The description of the segments in the output file. */
854 struct output_segment *output_segments;
856 /* List of the symbols we created from linker script definitions. */
857 struct symbol *lscript_syms;
858 size_t nlscript_syms;
860 /* Table with known symbols. */
861 ld_symbol_tab symbol_tab;
863 /* Table with used sections. */
864 ld_section_tab section_tab;
866 /* The list of sections once we collected them. */
867 struct scnhead **allsections;
869 size_t nusedsections;
870 size_t nnotesections;
872 /* Beginning of the list of symbols which are still unresolved. */
873 struct symbol *unresolved;
874 /* Number of truely unresolved entries in the list. */
876 /* Number of truely unresolved, non-weak entries in the list. */
877 size_t nunresolved_nonweak;
879 /* List of common symbols. */
880 struct symbol *common_syms;
881 /* Section for the common symbols. */
882 struct scninfo *common_section;
884 /* List of symbols defined in DSOs and used in a relocatable file.
885 DSO symbols not referenced in the relocatable files are not on
886 the list. If a symbol is on the list the on_dsolist field in the
887 'struct symbol' is nonzero. */
888 struct symbol *from_dso;
889 /* Number of entries in from_dso. */
891 /* Number of entries in the dynamic symbol table. */
893 /* Number of PLT entries from DSO references. */
895 /* Number of PLT entries from DSO references. */
897 /* Number of copy relocations. */
899 /* Section for copy relocations. */
900 struct scninfo *copy_section;
902 /* Keeping track of the number of symbols in the output file. */
904 size_t nlocalsymbols;
906 /* Special symbols. */
907 struct symbol *init_symbol;
908 struct symbol *fini_symbol;
910 /* The description of the segments in the output file as described
911 in the default linker script. This information will be used in
912 addition to the user-provided information. */
913 struct output_segment *default_output_segments;
914 /* Search paths added by the default linker script. */
915 struct pathelement *default_paths;
917 #ifndef BASE_ELF_NAME
918 /* The handle of the ld backend library. */
922 /* String table for the section headers. */
923 struct Ebl_Strtab *shstrtab;
925 /* True if output file should contain symbol table. */
927 /* Symbol table section. */
928 Elf32_Word symscnidx;
929 /* Extended section table section. */
930 Elf32_Word xndxscnidx;
931 /* Symbol string table section. */
932 Elf32_Word strscnidx;
934 /* True if output file should contain dynamic symbol table. */
936 /* Dynamic symbol table section. */
937 Elf32_Word dynsymscnidx;
938 /* Dynamic symbol string table section. */
939 Elf32_Word dynstrscnidx;
940 /* Dynamic symbol hash tables. */
942 size_t gnuhashscnidx;
944 /* Procedure linkage table section. */
945 Elf32_Word pltscnidx;
946 /* Number of entries already in the PLT section. */
948 /* Relocation for procedure linkage table section. */
949 Elf32_Word pltrelscnidx;
951 /* Global offset table section. */
952 Elf32_Word gotscnidx;
953 /* And the part of the PLT. */
954 Elf32_Word gotpltscnidx;
956 /* This section will hole all non-PLT relocations. */
957 Elf32_Word reldynscnidx;
959 /* Index of the sections to handle versioning. */
960 Elf32_Word versymscnidx;
961 Elf32_Word verneedscnidx;
962 /* XXX Should the following names be verneed...? */
963 /* Number of version definitions in input DSOs used. */
965 /* Number of input DSOs using versioning. */
967 /* Index of next version. */
975 /* Hash table for version symbol strings. Only strings without
976 special characters are hashed here. */
977 ld_version_str_tab version_str_tab;
978 /* At most one of the following two variables is set to true if either
979 global or local symbol binding is selected as the default. */
980 bool default_bind_local;
981 bool default_bind_global;
983 /* Execuatable stack selection. */
988 execstack_false_force
991 /* True if only used sections are used. */
994 /* Array to determine final index of symbol. */
995 Elf32_Word *dblindirect;
997 /* Section group handling. */
1000 Elf32_Word outscnidx;
1004 struct scnhead *scn;
1005 struct member *next;
1007 struct Ebl_Strent *nameent;
1008 struct symbol *symbol;
1009 struct scngroup *next;
1012 /* True if the output file needs a .got section. */
1014 /* Number of relocations for GOT section caused. */
1017 /* Number of entries needed in the .dynamic section. */
1019 /* To keep track of added entries. */
1020 int ndynamic_filled;
1021 /* Index for the dynamic section. */
1022 Elf32_Word dynamicscnidx;
1024 /* Flags set in the DT_FLAGS word. */
1025 Elf32_Word dt_flags;
1026 /* Flags set in the DT_FLAGS_1 word. */
1027 Elf32_Word dt_flags_1;
1028 /* Flags set in the DT_FEATURE_1 word. */
1029 Elf32_Word dt_feature_1;
1031 /* Lazy-loading state for dependencies. */
1034 /* True if an .eh_frame_hdr section should be generated. */
1037 /* What hash style to generate. */
1040 hash_style_none = 0,
1041 hash_style_sysv = 1,
1042 #define GENERATE_SYSV_HASH ((ld_state.hash_style & hash_style_sysv) != 0)
1044 #define GENERATE_GNU_HASH ((ld_state.hash_style & hash_style_gnu) != 0)
1049 /* True if in executables all global symbols should be exported in
1050 the dynamic symbol table. */
1051 bool export_all_dynamic;
1053 /* Build-ID style. NULL is none. */
1054 const char *build_id;
1055 Elf32_Word buildidscnidx;
1057 /* If DSO is generated, this is the SONAME. */
1060 /* List of all relocation sections. */
1061 struct scninfo *rellist;
1062 /* Total size of non-PLT relocations. */
1063 size_t relsize_total;
1065 /* Record for the GOT symbol, if known. */
1066 struct symbol *got_symbol;
1067 /* Record for the dynamic section symbol, if known. */
1068 struct symbol *dyn_symbol;
1070 /* Obstack used for small objects which will not be deleted. */
1071 struct obstack smem;
1075 /* The interface to the scanner. */
1077 /* Parser entry point. */
1078 extern int ldparse (void);
1080 /* The input file. */
1083 /* Name of the input file. */
1084 extern const char *ldin_fname;
1086 /* Current line number. Must be reset for a new file. */
1087 extern int ldlineno;
1089 /* If nonzero we are currently parsing a version script. */
1090 extern int ld_scan_version_script;
1092 /* Flags defined in ld.c. */
1094 extern int conserve_memory;
1097 /* Linker state. This contains all global information. */
1098 extern struct ld_state ld_state;
1101 /* Generic ld helper functions. */
1103 /* Append a new directory to search libraries in. */
1104 extern void ld_new_searchdir (const char *dir);
1106 /* Append a new file to the list of input files. */
1107 extern struct usedfiles *ld_new_inputfile (const char *fname,
1108 enum file_type type);
1111 /* These are the generic implementations for the callbacks used by ld. */
1113 /* Initialize state object. This callback function is called after the
1114 parameters are parsed but before any file is searched for. */
1115 extern int ld_prepare_state (const char *emulation);
1118 /* Function to determine whether an object will be dynamically linked. */
1119 extern bool dynamically_linked_p (void);
1121 /* Helper functions for the architecture specific code. */
1123 /* Checked whether the symbol is undefined and referenced from a DSO. */
1124 extern bool linked_from_dso_p (struct scninfo *scninfo, size_t symidx);
1125 #ifdef __GNUC_STDC_INLINE__
1126 __attribute__ ((__gnu_inline__))
1129 linked_from_dso_p (struct scninfo *scninfo, size_t symidx)
1131 struct usedfiles *file = scninfo->fileinfo;
1133 /* If this symbol is not undefined in this file it cannot come from
1135 if (symidx < file->nlocalsymbols)
1138 struct symbol *sym = file->symref[symidx];
1140 return sym->defined && sym->in_dso;