ldemul.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* ld-emul.h - Linker emulation header file
  2. Copyright (C) 1991-2022 Free Software Foundation, Inc.
  3. This file is part of the GNU Binutils.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #ifndef LDEMUL_H
  17. #define LDEMUL_H
  18. /* Forward declaration for ldemul_add_options() and others. */
  19. struct option;
  20. extern void ldemul_hll
  21. (char *);
  22. extern void ldemul_syslib
  23. (char *);
  24. extern void ldemul_after_parse
  25. (void);
  26. extern void ldemul_before_parse
  27. (void);
  28. extern void ldemul_before_plugin_all_symbols_read
  29. (void);
  30. extern void ldemul_after_open
  31. (void);
  32. extern void ldemul_after_check_relocs
  33. (void);
  34. extern void ldemul_before_place_orphans
  35. (void);
  36. extern void ldemul_after_allocation
  37. (void);
  38. extern void ldemul_before_allocation
  39. (void);
  40. extern void ldemul_set_output_arch
  41. (void);
  42. extern char *ldemul_choose_target
  43. (int, char**);
  44. extern void ldemul_choose_mode
  45. (char *);
  46. extern void ldemul_list_emulations
  47. (FILE *);
  48. extern void ldemul_list_emulation_options
  49. (FILE *);
  50. extern char *ldemul_get_script
  51. (int *isfile);
  52. extern void ldemul_finish
  53. (void);
  54. extern void ldemul_set_symbols
  55. (void);
  56. extern void ldemul_create_output_section_statements
  57. (void);
  58. extern lang_output_section_statement_type *ldemul_place_orphan
  59. (asection *, const char *, int);
  60. extern bool ldemul_parse_args
  61. (int, char **);
  62. extern void ldemul_add_options
  63. (int, char **, int, struct option **, int, struct option **);
  64. extern bool ldemul_handle_option
  65. (int);
  66. extern bool ldemul_unrecognized_file
  67. (struct lang_input_statement_struct *);
  68. extern bool ldemul_recognized_file
  69. (struct lang_input_statement_struct *);
  70. extern bool ldemul_open_dynamic_archive
  71. (const char *, struct search_dirs *, struct lang_input_statement_struct *);
  72. extern char *ldemul_default_target
  73. (int, char**);
  74. extern void after_parse_default
  75. (void);
  76. extern void after_open_default
  77. (void);
  78. extern void after_check_relocs_default
  79. (void);
  80. extern void before_place_orphans_default
  81. (void);
  82. extern void after_allocation_default
  83. (void);
  84. extern void before_allocation_default
  85. (void);
  86. extern void finish_default
  87. (void);
  88. extern void finish_default
  89. (void);
  90. extern void set_output_arch_default
  91. (void);
  92. extern void syslib_default
  93. (char*);
  94. extern void hll_default
  95. (char*);
  96. extern int ldemul_find_potential_libraries
  97. (char *, struct lang_input_statement_struct *);
  98. extern struct bfd_elf_version_expr *ldemul_new_vers_pattern
  99. (struct bfd_elf_version_expr *);
  100. extern void ldemul_extra_map_file_text
  101. (bfd *, struct bfd_link_info *, FILE *);
  102. /* Return 1 if we are emitting CTF early, and 0 if ldemul_examine_strtab_for_ctf
  103. will be called by the target. */
  104. extern int ldemul_emit_ctf_early
  105. (void);
  106. /* Called from per-target code to examine the strtab and symtab. */
  107. extern void ldemul_acquire_strings_for_ctf
  108. (struct ctf_dict *, struct elf_strtab_hash *);
  109. extern void ldemul_new_dynsym_for_ctf
  110. (struct ctf_dict *, int symidx, struct elf_internal_sym *);
  111. extern bool ldemul_print_symbol
  112. (struct bfd_link_hash_entry *hash_entry, void *ptr);
  113. typedef struct ld_emulation_xfer_struct {
  114. /* Run before parsing the command line and script file.
  115. Set the architecture, maybe other things. */
  116. void (*before_parse) (void);
  117. /* Handle the SYSLIB (low level library) script command. */
  118. void (*syslib) (char *);
  119. /* Handle the HLL (high level library) script command. */
  120. void (*hll) (char *);
  121. /* Run after parsing the command line and script file. */
  122. void (*after_parse) (void);
  123. /* Run before calling plugin 'all symbols read' hook. */
  124. void (*before_plugin_all_symbols_read) (void);
  125. /* Run after opening all input files, and loading the symbols. */
  126. void (*after_open) (void);
  127. /* Run after checking relocations. */
  128. void (*after_check_relocs) (void);
  129. /* Run before placing orphans. */
  130. void (*before_place_orphans) (void);
  131. /* Run after allocating output sections. */
  132. void (*after_allocation) (void);
  133. /* Set the output architecture and machine if possible. */
  134. void (*set_output_arch) (void);
  135. /* Decide which target name to use. */
  136. char * (*choose_target) (int, char**);
  137. /* Run before allocating output sections. */
  138. void (*before_allocation) (void);
  139. /* Return the appropriate linker script. */
  140. char * (*get_script) (int *isfile);
  141. /* The name of this emulation. */
  142. char *emulation_name;
  143. /* The output format. */
  144. char *target_name;
  145. /* Run after assigning values from the script. */
  146. void (*finish) (void);
  147. /* Create any output sections needed by the target. */
  148. void (*create_output_section_statements) (void);
  149. /* Try to open a dynamic library. ARCH is an architecture name, and
  150. is normally the empty string. ENTRY is the lang_input_statement
  151. that should be opened. */
  152. bool (*open_dynamic_archive)
  153. (const char *arch, struct search_dirs *,
  154. struct lang_input_statement_struct *entry);
  155. /* Place an orphan section. Return TRUE if it was placed, FALSE if
  156. the default action should be taken. This field may be NULL, in
  157. which case the default action will always be taken. */
  158. lang_output_section_statement_type *(*place_orphan)
  159. (asection *, const char *, int);
  160. /* Run after assigning parsing with the args, but before
  161. reading the script. Used to initialize symbols used in the script. */
  162. void (*set_symbols) (void);
  163. /* Parse args which the base linker doesn't understand.
  164. Return TRUE if the arg needs no further processing. */
  165. bool (*parse_args) (int, char **);
  166. /* Hook to add options to parameters passed by the base linker to
  167. getopt_long and getopt_long_only calls. */
  168. void (*add_options)
  169. (int, char **, int, struct option **, int, struct option **);
  170. /* Companion to the above to handle an option. Returns TRUE if it is
  171. one of our options. */
  172. bool (*handle_option) (int);
  173. /* Run to handle files which are not recognized as object files or
  174. archives. Return TRUE if the file was handled. */
  175. bool (*unrecognized_file)
  176. (struct lang_input_statement_struct *);
  177. /* Run to list the command line options which parse_args handles. */
  178. void (* list_options) (FILE *);
  179. /* Run to specially handle files which *are* recognized as object
  180. files or archives. Return TRUE if the file was handled. */
  181. bool (*recognized_file)
  182. (struct lang_input_statement_struct *);
  183. /* Called when looking for libraries in a directory specified
  184. via a linker command line option or linker script option.
  185. Files that match the pattern "lib*.a" have already been scanned.
  186. (For VMS files matching ":lib*.a" have also been scanned). */
  187. int (* find_potential_libraries)
  188. (char *, struct lang_input_statement_struct *);
  189. /* Called when adding a new version pattern. PowerPC64-ELF uses
  190. this hook to add a pattern matching ".foo" for every "foo". */
  191. struct bfd_elf_version_expr * (*new_vers_pattern)
  192. (struct bfd_elf_version_expr *);
  193. /* Called when printing the map file, in case there are
  194. emulation-specific sections for it. */
  195. void (*extra_map_file_text)
  196. (bfd *, struct bfd_link_info *, FILE *);
  197. /* If this returns true, we emit CTF as early as possible: if false, we emit
  198. CTF once the strtab and symtab are laid out. */
  199. int (*emit_ctf_early)
  200. (void);
  201. /* Called to examine the string table late enough in linking that it is
  202. finally laid out. If emit_ctf_early returns true, this is not called, and
  203. ldemul_maybe_emit_ctf emits CTF in 'early' mode: otherwise, it waits
  204. until 'late'. (Late mode needs explicit support at per-target link time to
  205. get called at all). If set, called by ld when the examine_strtab
  206. bfd_link_callback is invoked by per-target code. */
  207. void (*acquire_strings_for_ctf) (struct ctf_dict *, struct elf_strtab_hash *);
  208. /* Called when a new symbol is added to the dynamic symbol table. If
  209. emit_ctf_early returns true, this is not called, and ldemul_maybe_emit_ctf
  210. emits CTF in 'early' mode: otherwise, it waits until 'late'. (Late mode
  211. needs explicit support at per-target link time to get called at all). If
  212. set, called by ld when the ctf_new_symbol bfd_link_callback is invoked by
  213. per-target code. Called with a NULL symbol when no further symbols will be
  214. provided. */
  215. void (*new_dynsym_for_ctf) (struct ctf_dict *, int, struct elf_internal_sym *);
  216. /* Called when printing a symbol to the map file. AIX uses this
  217. hook to flag gc'd symbols. */
  218. bool (*print_symbol)
  219. (struct bfd_link_hash_entry *hash_entry, void *ptr);
  220. } ld_emulation_xfer_type;
  221. typedef enum {
  222. intel_ic960_ld_mode_enum,
  223. default_mode_enum,
  224. intel_gld960_ld_mode_enum
  225. } lang_emulation_mode_enum_type;
  226. extern ld_emulation_xfer_type *ld_emulations[];
  227. #endif