1 /* Copyright (C) 2001, 2002, 2003, 2005, 2006, 2008, 2009 Red Hat, Inc.
2 This file is part of elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 2001.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 elfutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 /* Recommended size of the buffer passed to ld_strerror. */
29 #define ERRBUFSIZE (512)
31 /* Character used to introduce version name after symbol. */
35 /* Methods for handling archives. */
38 defaultextract, /* Weak references don't cause archive member to
40 weakextract, /* Weak references cause archive member to be
42 allextract /* Extract all archive members regardless of
43 references (aka whole-archive). */
47 /* Type of output file. */
50 no_file_type = 0, /* None selected so far. */
51 executable_file_type, /* Executable. */
52 dso_file_type, /* DSO. */
53 dso_needed_file_type, /* DSO introduced by DT_NEEDED. */
54 relocatable_file_type, /* Relocatable object file. */
55 archive_file_type /* Archive (input only). */
61 /* The next file given at the command line. */
62 struct usedfiles *next;
63 /* Nonzero if this file is the beginning of a group. */
65 /* Nonzero if this file is the end of a group. */
67 /* Pointer to the beginning of the group. It is necessary to
68 explain why we cannot simply use the 'next' pointer and have a
69 circular single-linked list like in many cases. The problem is
70 that the last archive of the group, if it is the last file of the
71 group, contains the only existing pointer to the next file we
72 have to look at. All files are initially connected via the
73 'next' pointer in a single-linked list. Therefore we cannot
74 overwrite this value. It instead will be used once the group is
75 handled and we go on processing the rest of the files. */
76 struct usedfiles *group_backref;
78 /* Name/path of the file. */
80 /* Resolved file name. */
82 /* Name used as reference in DT_NEEDED entries. This is normally
83 the SONAME. If it is missing it's normally the fname above. */
85 /* Handle for the SONAME in the string table. */
86 struct Ebl_Strent *sonameent;
88 /* Help to identify duplicates. */
100 /* How to extract elements from archives. */
101 enum extract_rule extract_rule;
103 /* Lazy-loading rule. */
106 /* If this is a DSO the flag indicates whether the file is directly
107 used in a reference. */
110 /* True when file should be added to DT_NEEDED list only when
111 directly referenced. */
114 /* If nonzero this is the archive sequence number which can be used to
115 determine whether back refernces from -( -) or GROUP statements
116 have to be followed. */
119 /* Pointer to the record for the archive containing this file. */
120 struct usedfiles *archive_file;
122 /* Type of file. We have to distinguish these types since they
123 are searched for differently. */
124 enum file_type file_type;
125 /* This is the ELF library handle for this file. */
128 /* The ELF header. */
131 # define FILEINFO_EHDR(fi) (*(fi))
134 # define FILEINFO_EHDR(fi) (fi)
137 /* Index of the section header string table section. We use a
138 separate field and not the e_shstrndx field in the ELF header
139 since in case of a file with more than 64000 sections the index
140 might be stored in the section header of section zero. The
141 elf_getshdrstrndx() function can find the value but it is too
142 costly to repeat this call over and over. */
145 /* Info about the sections of the file. */
148 /* Handle for the section. Note that we can store a section
149 handle here because the file is not changing. This together
150 with the knowledge about the libelf library is enough for us to
151 assume the section reference remains valid at all times. */
153 /* Section header. */
156 # define SCNINFO_SHDR(si) (*(si))
159 # define SCNINFO_SHDR(si) (si)
161 /* Offset of this files section in the combined section. */
163 /* Index of the section in the output file. */
164 Elf32_Word outscnndx;
165 /* Index of the output section in the 'allsection' array. */
166 Elf32_Word allsectionsidx;
167 /* True if the section is used. */
169 /* True if section is an unused COMDAT section. */
171 /* True if this is a COMDAT group section. */
173 /* Section group number. This is the index of the SHT_GROUP section. */
175 /* Pointer back to the containing file information structure. */
176 struct usedfiles *fileinfo;
177 /* List of symbols in this section (set only for merge-able sections
178 and group sections). */
179 struct symbol *symbols;
180 /* Size of relocations in this section. Only used for relocation
183 /* Pointer to next section which is put in the given output
185 struct scninfo *next;
188 /* List of section group sections. */
189 struct scninfo *groups;
191 /* The symbol table section.
193 XXX Maybe support for more than one symbol table is needed. */
194 Elf_Data *symtabdata;
195 /* Extra section index table section. */
197 /* Dynamic symbol table section. */
198 Elf_Data *dynsymtabdata;
199 /* The version number section. */
200 Elf_Data *versymdata;
201 /* The defined versions. */
202 Elf_Data *verdefdata;
203 /* Number of versions defined. */
205 /* True if the version with the given index number is used in the
207 XElf_Versym *verdefused;
208 /* How many versions are used. */
210 /* Handle for name of the version. */
211 struct Ebl_Strent **verdefent;
212 /* The needed versions. */
213 Elf_Data *verneeddata;
214 /* String table section associated with the symbol table. */
215 Elf32_Word symstridx;
216 /* String table section associated with the dynamic symbol table. */
217 Elf32_Word dynsymstridx;
218 /* Number of entries in the symbol table. */
220 size_t nlocalsymbols;
222 /* Dynamic section. */
225 /* Indirection table for the symbols defined here. */
226 Elf32_Word *symindirect;
227 Elf32_Word *dynsymindirect;
228 /* For undefined or common symbols we need a reference to the symbol
230 struct symbol **symref;
231 struct symbol **dynsymref;
233 /* This is the file descriptor. The value is -1 if the descriptor
234 was already closed. This can happen if we needed file descriptors
235 to open new files. */
237 /* This flag is true if the descriptor was passed to the generic
238 functions from somewhere else. This is an implementation detail;
239 no machine-specific code must use this flag. */
242 /* True if any of the sections is merge-able. */
243 bool has_merge_sections;
247 /* Functions to test for the various types of files we handle. */
249 ld_file_rel_p (struct usedfiles *file)
251 return (elf_kind (file->elf) == ELF_K_ELF
252 && FILEINFO_EHDR (file->ehdr).e_type == ET_REL);
256 ld_file_dso_p (struct usedfiles *file)
258 return (elf_kind (file->elf) == ELF_K_ELF
259 && FILEINFO_EHDR (file->ehdr).e_type == ET_DYN);
263 ld_file_ar_p (struct usedfiles *file)
265 return elf_kind (file->elf) == ELF_K_AR;
271 /* The next path to search. */
272 struct pathelement *next;
275 /* Larger than zero if the directory exists, smaller than zero if not,
276 zero if it is not yet known. */
281 /* Forward declaration. */
285 /* Callback functions. */
288 /* Library names passed to the linker as -lXXX represent files named
289 libXXX.YY. The YY part can have different forms, depending on the
290 architecture. The generic set is .so and .a (in this order). */
291 const char **(*lib_extensions) (struct ld_state *)
292 __attribute__ ((__const__));
293 #define LIB_EXTENSION(state) \
294 DL_CALL_FCT ((state)->callbacks.lib_extensions, (state))
296 /* Process the given file. If the file is not yet open, open it.
297 The first parameter is a file descriptor for the file which can
298 be -1 to indicate the file has not yet been found. The second
299 parameter describes the file to be opened, the last one is the
300 state of the linker which among other information contain the
302 int (*file_process) (int fd, struct usedfiles *, struct ld_state *,
303 struct usedfiles **);
304 #define FILE_PROCESS(fd, file, state, nextp) \
305 DL_CALL_FCT ((state)->callbacks.file_process, (fd, file, state, nextp))
307 /* Close the given file. */
308 int (*file_close) (struct usedfiles *, struct ld_state *);
309 #define FILE_CLOSE(file, state) \
310 DL_CALL_FCT ((state)->callbacks.file_close, (file, state))
312 /* Create the output sections now. This requires knowledge about
313 all the sections we will need. It may be necessary to sort the
314 sections in the order they are supposed to appear in the
315 executable. The sorting use many different kinds of information
316 to optimize the resulting binary. Important is to respect
317 segment boundaries and the needed alignment. The mode of the
318 segments will be determined afterwards automatically by the
320 void (*create_sections) (struct ld_state *);
321 #define CREATE_SECTIONS(state) \
322 DL_CALL_FCT ((state)->callbacks.create_sections, (state))
324 /* Determine whether we have any non-weak unresolved references left. */
325 int (*flag_unresolved) (struct ld_state *);
326 #define FLAG_UNRESOLVED(state) \
327 DL_CALL_FCT ((state)->callbacks.flag_unresolved, (state))
329 /* Create the sections which are generated by the linker and are not
330 present in the input file. */
331 void (*generate_sections) (struct ld_state *);
332 #define GENERATE_SECTIONS(state) \
333 DL_CALL_FCT ((state)->callbacks.generate_sections, (state))
335 /* Open the output file. The file name is given or "a.out". We
336 create as much of the ELF structure as possible. */
337 int (*open_outfile) (struct ld_state *, int, int, int);
338 #define OPEN_OUTFILE(state, machine, class, data) \
339 DL_CALL_FCT ((state)->callbacks.open_outfile, (state, machine, class, data))
341 /* Create the data for the output file. */
342 int (*create_outfile) (struct ld_state *);
343 #define CREATE_OUTFILE(state) \
344 DL_CALL_FCT ((state)->callbacks.create_outfile, (state))
346 /* Process a relocation section. */
347 void (*relocate_section) (struct ld_state *, Elf_Scn *, struct scninfo *,
349 #define RELOCATE_SECTION(state, outscn, first, dblindirect) \
350 DL_CALL_FCT ((state)->callbacks.relocate_section, (state, outscn, first, \
353 /* Allocate a data buffer for the relocations of the given output
355 void (*count_relocations) (struct ld_state *, struct scninfo *);
356 #define COUNT_RELOCATIONS(state, scninfo) \
357 DL_CALL_FCT ((state)->callbacks.count_relocations, (state, scninfo))
359 /* Create relocations for executable or DSO. */
360 void (*create_relocations) (struct ld_state *, const Elf32_Word *);
361 #define CREATE_RELOCATIONS(state, dlbindirect) \
362 DL_CALL_FCT ((state)->callbacks.create_relocations, (state, dblindirect))
364 /* Finalize the output file. */
365 int (*finalize) (struct ld_state *);
366 #define FINALIZE(state) \
367 DL_CALL_FCT ((state)->callbacks.finalize, (state))
369 /* Check whether special section number is known. */
370 bool (*special_section_number_p) (struct ld_state *, size_t);
371 #define SPECIAL_SECTION_NUMBER_P(state, number) \
372 DL_CALL_FCT ((state)->callbacks.special_section_number_p, (state, number))
374 /* Check whether section type is known. */
375 bool (*section_type_p) (struct ld_state *, XElf_Word);
376 #define SECTION_TYPE_P(state, type) \
377 DL_CALL_FCT ((state)->callbacks.section_type_p, (state, type))
379 /* Return section flags for .dynamic section. */
380 XElf_Xword (*dynamic_section_flags) (struct ld_state *);
381 #define DYNAMIC_SECTION_FLAGS(state) \
382 DL_CALL_FCT ((state)->callbacks.dynamic_section_flags, (state))
384 /* Create the data structures for the .plt section and initialize it. */
385 void (*initialize_plt) (struct ld_state *, Elf_Scn *scn);
386 #define INITIALIZE_PLT(state, scn) \
387 DL_CALL_FCT ((state)->callbacks.initialize_plt, (state, scn))
389 /* Create the data structures for the .rel.plt section and initialize it. */
390 void (*initialize_pltrel) (struct ld_state *, Elf_Scn *scn);
391 #define INITIALIZE_PLTREL(state, scn) \
392 DL_CALL_FCT ((state)->callbacks.initialize_pltrel, (state, scn))
394 /* Finalize the .plt section the what belongs to them. */
395 void (*finalize_plt) (struct ld_state *, size_t, size_t, struct symbol **);
396 #define FINALIZE_PLT(state, nsym, nsym_dyn, ndxtosym) \
397 DL_CALL_FCT ((state)->callbacks.finalize_plt, (state, nsym, nsym_dyn, \
400 /* Create the data structures for the .got section and initialize it. */
401 void (*initialize_got) (struct ld_state *, Elf_Scn *scn);
402 #define INITIALIZE_GOT(state, scn) \
403 DL_CALL_FCT ((state)->callbacks.initialize_got, (state, scn))
405 /* Create the data structures for the .got.plt section and initialize it. */
406 void (*initialize_gotplt) (struct ld_state *, Elf_Scn *scn);
407 #define INITIALIZE_GOTPLT(state, scn) \
408 DL_CALL_FCT ((state)->callbacks.initialize_gotplt, (state, scn))
410 /* Return the tag corresponding to the native relocation type for
412 int (*rel_type) (struct ld_state *);
413 #define REL_TYPE(state) \
414 DL_CALL_FCT ((state)->callbacks.rel_type, (state))
418 /* Structure for symbol representation. This data structure is used a
419 lot, so size is important. */
424 /* Size of the object. */
426 /* Index of the symbol in the symbol table of the object. */
428 /* Index of the symbol in the symbol table of the output file. */
431 /* Description where the symbol is found/needed. */
433 struct usedfiles *file;
434 /* Index of the symbol table. */
437 /* Index of the symbol in the dynamic symbol table of the output
438 file. Note that the value only needs to be 16 bit wide since
439 there cannot be more sections in an executable or DSO. */
440 unsigned int outdynsymidx:16;
442 /* Type of the symbol. */
445 unsigned int defined:1;
446 unsigned int common:1;
448 unsigned int added:1;
449 unsigned int merged:1;
450 unsigned int local:1;
451 unsigned int hidden:1;
452 /* Nonzero if the symbol is on the from_dso list. */
453 unsigned int on_dsolist:1;
454 /* Nonzero if symbol needs copy relocation, reset when the
455 relocation has been created. */
456 unsigned int need_copy:1;
457 unsigned int in_dso:1;
461 /* Pointer to the handle created by the functions which create
462 merged section contents. We use 'void *' because there are
463 different implementations used. */
468 /* Pointer to next/previous symbol on whatever list the symbol is. */
470 struct symbol *previous;
471 /* Pointer to next symbol of the same section (only set for merge-able
473 struct symbol *next_in_scn;
477 /* Get the definition for the symbol table. */
478 #include <symbolhash.h>
480 /* Simple single linked list of file names. */
484 struct usedfiles *real;
485 struct filename_list *next;
492 /* Data structure to describe expression in linker script. */
514 struct expression *child;
517 struct expression *left;
518 struct expression *right;
525 /* Data structure for section name with flags. */
526 struct input_section_name
532 /* File name mask with section name. */
533 struct filemask_section_name
535 const char *filemask;
536 const char *excludemask;
537 struct input_section_name *section_name;
541 /* Data structure for assignments. */
544 const char *variable;
545 struct expression *expression;
551 /* Data structure describing input for an output section. */
562 struct assignment *assignment;
563 struct filemask_section_name *section;
566 struct input_rule *next;
570 /* Data structure to describe output section. */
571 struct output_section
574 struct input_rule *input;
575 XElf_Addr max_alignment;
580 /* Data structure to describe output file format. */
591 struct assignment *assignment;
592 struct output_section section;
595 struct output_rule *next;
599 /* List of all the segments the linker script describes. */
600 struct output_segment
603 struct output_rule *output_rules;
604 struct output_segment *next;
612 /* List of identifiers. */
619 id_str, /* Normal string. */
620 id_all, /* "*", matches all. */
621 id_wild /* Globbing wildcard string. */
626 const char *versionname;
630 struct id_list *next;
634 /* Version information. */
637 struct version *next;
638 struct id_list *local_names;
639 struct id_list *global_names;
640 const char *versionname;
641 const char *parentname;
645 /* Head for list of sections. */
648 /* Name of the sections. */
651 /* Accumulated flags for the sections. */
654 /* Type of the sections. */
657 /* Entry size. If there are differencs between the sections with
658 the same name this field contains 1. */
661 /* If non-NULL pointer to group signature. */
662 const char *grp_signature;
664 /* Maximum alignment for all sections. */
667 /* Distinguish between normal sections coming from the input file
668 and sections generated by the linker. */
671 scn_normal, /* Section from the input file(s). */
672 scn_dot_interp, /* Generated .interp section. */
673 scn_dot_got, /* Generated .got section. */
674 scn_dot_gotplt, /* Generated .got.plt section. */
675 scn_dot_dynrel, /* Generated .rel.dyn section. */
676 scn_dot_dynamic, /* Generated .dynamic section. */
677 scn_dot_dynsym, /* Generated .dynsym section. */
678 scn_dot_dynstr, /* Generated .dynstr section. */
679 scn_dot_hash, /* Generated .hash section. */
680 scn_dot_gnu_hash, /* Generated .gnu.hash section. */
681 scn_dot_plt, /* Generated .plt section. */
682 scn_dot_pltrel, /* Generated .rel.plt section. */
683 scn_dot_version, /* Generated .gnu.version section. */
684 scn_dot_version_r, /* Generated .gnu.version_r section. */
685 scn_dot_note_gnu_build_id /* Generated .note.gnu.build-id section. */
688 /* True is the section is used in the output. */
691 /* Total size (only determined this way for relocation sections). */
694 /* Filled in by the section sorting to indicate which segment the
698 /* Index of the output section. We cannot store the section handle
699 directly here since the handle is a pointer in a dynamically
700 allocated table which might move if it becomes too small for all
701 the sections. Using the index the correct value can be found at
705 /* Index of the STT_SECTION entry for this section in the symbol
709 /* Address of the section in the output file. */
712 /* Handle for the section name in the output file's section header
714 struct Ebl_Strent *nameent;
716 /* Tail of list of symbols for this section. Only set if the
717 section is merge-able. */
718 struct symbol *symbols;
720 /* Pointer to last section. */
721 struct scninfo *last;
725 /* Define hash table for sections. */
726 #include <sectionhash.h>
728 /* Define hash table for version symbols. */
729 #include <versionhash.h>
732 /* State of the linker. */
735 /* ELF backend library handle. */
738 /* List of all archives participating, in this order. */
739 struct usedfiles *archives;
740 /* End of the list. */
741 struct usedfiles *tailarchives;
742 /* If nonzero we are looking for the beginning of a group. */
743 bool group_start_requested;
744 /* Pointer to the archive starting the group. */
745 struct usedfiles *group_start_archive;
747 /* List of the DSOs we found. */
748 struct usedfiles *dsofiles;
749 /* Number of DSO files. */
751 /* Ultimate list of object files which are linked in. */
752 struct usedfiles *relfiles;
754 /* List the DT_NEEDED DSOs. */
755 struct usedfiles *needed;
757 /* Temporary storage for the parser. */
758 struct filename_list *srcfiles;
760 /* List of all the paths to look at. */
761 struct pathelement *paths;
762 /* Tail of the list. */
763 struct pathelement *tailpaths;
765 /* User provided paths for lookup of DSOs. */
766 struct pathelement *rpath;
767 struct pathelement *rpath_link;
768 struct pathelement *runpath;
769 struct pathelement *runpath_link;
770 struct Ebl_Strent *rxxpath_strent;
773 /* From the environment variable LD_LIBRARY_PATH. */
774 struct pathelement *ld_library_path1;
775 struct pathelement *ld_library_path2;
777 /* Name of the output file. */
778 const char *outfname;
779 /* Name of the temporary file we initially create. */
780 const char *tempfname;
781 /* File descriptor opened for the output file. */
783 /* The ELF descriptor for the output file. */
786 /* Type of output file. */
787 enum file_type file_type;
789 /* Is this a system library or not. */
790 bool is_system_library;
792 /* Page size to be assumed for the binary. */
795 /* Name of the interpreter for dynamically linked objects. */
797 /* Index of the .interp section. */
798 Elf32_Word interpscnidx;
800 /* Optimization level. */
801 unsigned long int optlevel;
803 /* If true static linking is requested. */
806 /* If true, add DT_NEEDED entries for following files if they are
810 /* How to extract elements from archives. */
811 enum extract_rule extract_rule;
813 /* Sequence number of the last archive we used. */
814 int last_archive_used;
816 /* If true print to stdout information about the files we are
820 /* If true multiple definitions are not considered an error; the
824 /* If true undefined symbols when building DSOs are not fatal. */
827 /* If true add line indentifying link-editor to .comment section. */
830 /* Stripping while linking. */
839 /* The callback function vector. */
840 struct callbacks callbacks;
842 /* Name of the entry symbol. Can also be a numeric value. */
845 /* The description of the segments in the output file. */
846 struct output_segment *output_segments;
848 /* List of the symbols we created from linker script definitions. */
849 struct symbol *lscript_syms;
850 size_t nlscript_syms;
852 /* Table with known symbols. */
853 ld_symbol_tab symbol_tab;
855 /* Table with used sections. */
856 ld_section_tab section_tab;
858 /* The list of sections once we collected them. */
859 struct scnhead **allsections;
861 size_t nusedsections;
862 size_t nnotesections;
864 /* Beginning of the list of symbols which are still unresolved. */
865 struct symbol *unresolved;
866 /* Number of truely unresolved entries in the list. */
868 /* Number of truely unresolved, non-weak entries in the list. */
869 size_t nunresolved_nonweak;
871 /* List of common symbols. */
872 struct symbol *common_syms;
873 /* Section for the common symbols. */
874 struct scninfo *common_section;
876 /* List of symbols defined in DSOs and used in a relocatable file.
877 DSO symbols not referenced in the relocatable files are not on
878 the list. If a symbol is on the list the on_dsolist field in the
879 'struct symbol' is nonzero. */
880 struct symbol *from_dso;
881 /* Number of entries in from_dso. */
883 /* Number of entries in the dynamic symbol table. */
885 /* Number of PLT entries from DSO references. */
887 /* Number of PLT entries from DSO references. */
889 /* Number of copy relocations. */
891 /* Section for copy relocations. */
892 struct scninfo *copy_section;
894 /* Keeping track of the number of symbols in the output file. */
896 size_t nlocalsymbols;
898 /* Special symbols. */
899 struct symbol *init_symbol;
900 struct symbol *fini_symbol;
902 /* The description of the segments in the output file as described
903 in the default linker script. This information will be used in
904 addition to the user-provided information. */
905 struct output_segment *default_output_segments;
906 /* Search paths added by the default linker script. */
907 struct pathelement *default_paths;
909 #ifndef BASE_ELF_NAME
910 /* The handle of the ld backend library. */
914 /* String table for the section headers. */
915 struct Ebl_Strtab *shstrtab;
917 /* True if output file should contain symbol table. */
919 /* Symbol table section. */
920 Elf32_Word symscnidx;
921 /* Extended section table section. */
922 Elf32_Word xndxscnidx;
923 /* Symbol string table section. */
924 Elf32_Word strscnidx;
926 /* True if output file should contain dynamic symbol table. */
928 /* Dynamic symbol table section. */
929 Elf32_Word dynsymscnidx;
930 /* Dynamic symbol string table section. */
931 Elf32_Word dynstrscnidx;
932 /* Dynamic symbol hash tables. */
934 size_t gnuhashscnidx;
936 /* Procedure linkage table section. */
937 Elf32_Word pltscnidx;
938 /* Number of entries already in the PLT section. */
940 /* Relocation for procedure linkage table section. */
941 Elf32_Word pltrelscnidx;
943 /* Global offset table section. */
944 Elf32_Word gotscnidx;
945 /* And the part of the PLT. */
946 Elf32_Word gotpltscnidx;
948 /* This section will hole all non-PLT relocations. */
949 Elf32_Word reldynscnidx;
951 /* Index of the sections to handle versioning. */
952 Elf32_Word versymscnidx;
953 Elf32_Word verneedscnidx;
954 /* XXX Should the following names be verneed...? */
955 /* Number of version definitions in input DSOs used. */
957 /* Number of input DSOs using versioning. */
959 /* Index of next version. */
967 /* Hash table for version symbol strings. Only strings without
968 special characters are hashed here. */
969 ld_version_str_tab version_str_tab;
970 /* At most one of the following two variables is set to true if either
971 global or local symbol binding is selected as the default. */
972 bool default_bind_local;
973 bool default_bind_global;
975 /* Execuatable stack selection. */
980 execstack_false_force
983 /* True if only used sections are used. */
986 /* Array to determine final index of symbol. */
987 Elf32_Word *dblindirect;
989 /* Section group handling. */
992 Elf32_Word outscnidx;
999 struct Ebl_Strent *nameent;
1000 struct symbol *symbol;
1001 struct scngroup *next;
1004 /* True if the output file needs a .got section. */
1006 /* Number of relocations for GOT section caused. */
1009 /* Number of entries needed in the .dynamic section. */
1011 /* To keep track of added entries. */
1012 int ndynamic_filled;
1013 /* Index for the dynamic section. */
1014 Elf32_Word dynamicscnidx;
1016 /* Flags set in the DT_FLAGS word. */
1017 Elf32_Word dt_flags;
1018 /* Flags set in the DT_FLAGS_1 word. */
1019 Elf32_Word dt_flags_1;
1020 /* Flags set in the DT_FEATURE_1 word. */
1021 Elf32_Word dt_feature_1;
1023 /* Lazy-loading state for dependencies. */
1026 /* True if an .eh_frame_hdr section should be generated. */
1029 /* What hash style to generate. */
1032 hash_style_none = 0,
1033 hash_style_sysv = 1,
1034 #define GENERATE_SYSV_HASH ((ld_state.hash_style & hash_style_sysv) != 0)
1036 #define GENERATE_GNU_HASH ((ld_state.hash_style & hash_style_gnu) != 0)
1041 /* True if in executables all global symbols should be exported in
1042 the dynamic symbol table. */
1043 bool export_all_dynamic;
1045 /* Build-ID style. NULL is none. */
1046 const char *build_id;
1047 Elf32_Word buildidscnidx;
1049 /* If DSO is generated, this is the SONAME. */
1052 /* List of all relocation sections. */
1053 struct scninfo *rellist;
1054 /* Total size of non-PLT relocations. */
1055 size_t relsize_total;
1057 /* Record for the GOT symbol, if known. */
1058 struct symbol *got_symbol;
1059 /* Record for the dynamic section symbol, if known. */
1060 struct symbol *dyn_symbol;
1062 /* Obstack used for small objects which will not be deleted. */
1063 struct obstack smem;
1067 /* The interface to the scanner. */
1069 /* Parser entry point. */
1070 extern int ldparse (void);
1072 /* The input file. */
1075 /* Name of the input file. */
1076 extern const char *ldin_fname;
1078 /* Current line number. Must be reset for a new file. */
1079 extern int ldlineno;
1081 /* If nonzero we are currently parsing a version script. */
1082 extern int ld_scan_version_script;
1084 /* Flags defined in ld.c. */
1086 extern int conserve_memory;
1089 /* Linker state. This contains all global information. */
1090 extern struct ld_state ld_state;
1093 /* Generic ld helper functions. */
1095 /* Append a new directory to search libraries in. */
1096 extern void ld_new_searchdir (const char *dir);
1098 /* Append a new file to the list of input files. */
1099 extern struct usedfiles *ld_new_inputfile (const char *fname,
1100 enum file_type type);
1103 /* These are the generic implementations for the callbacks used by ld. */
1105 /* Initialize state object. This callback function is called after the
1106 parameters are parsed but before any file is searched for. */
1107 extern int ld_prepare_state (const char *emulation);
1110 /* Function to determine whether an object will be dynamically linked. */
1111 extern bool dynamically_linked_p (void);
1113 /* Helper functions for the architecture specific code. */
1115 /* Checked whether the symbol is undefined and referenced from a DSO. */
1116 extern bool linked_from_dso_p (struct scninfo *scninfo, size_t symidx);
1117 #ifdef __GNUC_STDC_INLINE__
1118 __attribute__ ((__gnu_inline__))
1121 linked_from_dso_p (struct scninfo *scninfo, size_t symidx)
1123 struct usedfiles *file = scninfo->fileinfo;
1125 /* If this symbol is not undefined in this file it cannot come from
1127 if (symidx < file->nlocalsymbols)
1130 struct symbol *sym = file->symref[symidx];
1132 return sym->defined && sym->in_dso;