ldexp.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* ldexp.h -
  2. Copyright (C) 1991-2015 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 LDEXP_H
  17. #define LDEXP_H
  18. /* The result of an expression tree */
  19. typedef struct {
  20. bfd_vma value;
  21. char *str;
  22. asection *section;
  23. bfd_boolean valid_p;
  24. } etree_value_type;
  25. enum node_tree_enum {
  26. etree_binary,
  27. etree_trinary,
  28. etree_unary,
  29. etree_name,
  30. etree_assign,
  31. etree_provide,
  32. etree_provided,
  33. etree_value,
  34. etree_assert,
  35. etree_rel
  36. };
  37. typedef struct {
  38. int node_code;
  39. unsigned int lineno;
  40. const char *filename;
  41. enum node_tree_enum node_class;
  42. } node_type;
  43. typedef union etree_union {
  44. node_type type;
  45. struct {
  46. node_type type;
  47. union etree_union *lhs;
  48. union etree_union *rhs;
  49. } binary;
  50. struct {
  51. node_type type;
  52. union etree_union *cond;
  53. union etree_union *lhs;
  54. union etree_union *rhs;
  55. } trinary;
  56. struct {
  57. node_type type;
  58. const char *dst;
  59. union etree_union *src;
  60. bfd_boolean defsym;
  61. bfd_boolean hidden;
  62. } assign;
  63. struct {
  64. node_type type;
  65. union etree_union *child;
  66. } unary;
  67. struct {
  68. node_type type;
  69. const char *name;
  70. } name;
  71. struct {
  72. node_type type;
  73. bfd_vma value;
  74. char *str;
  75. } value;
  76. struct {
  77. node_type type;
  78. asection *section;
  79. bfd_vma value;
  80. } rel;
  81. struct {
  82. node_type type;
  83. union etree_union *child;
  84. const char *message;
  85. } assert_s;
  86. } etree_type;
  87. /* Expression evaluation control. */
  88. typedef enum
  89. {
  90. /* Parsing linker script. Will only return "valid" for expressions
  91. that evaluate to a constant. */
  92. lang_first_phase_enum,
  93. /* Prior to section sizing. */
  94. lang_mark_phase_enum,
  95. /* During section sizing. */
  96. lang_allocating_phase_enum,
  97. /* During assignment of symbol values when relaxation in progress. */
  98. lang_assigning_phase_enum,
  99. /* Final assignment of symbol values. */
  100. lang_final_phase_enum
  101. } lang_phase_type;
  102. union lang_statement_union;
  103. enum phase_enum {
  104. /* We step through the first four states here as we see the
  105. associated linker script tokens. */
  106. exp_dataseg_none,
  107. exp_dataseg_align_seen,
  108. exp_dataseg_relro_seen,
  109. exp_dataseg_end_seen,
  110. /* The last three states are final, and affect the value returned
  111. by DATA_SEGMENT_ALIGN. */
  112. exp_dataseg_relro_adjust,
  113. exp_dataseg_adjust,
  114. exp_dataseg_done
  115. };
  116. enum relro_enum {
  117. exp_dataseg_relro_none,
  118. exp_dataseg_relro_start,
  119. exp_dataseg_relro_end,
  120. };
  121. struct ldexp_control {
  122. /* Modify expression evaluation depending on this. */
  123. lang_phase_type phase;
  124. /* Principally used for diagnostics. */
  125. bfd_boolean assigning_to_dot;
  126. /* Set if the current expression used "dot", SEGMENT_START or
  127. ORIGIN, but not ABSOLUTE or combined symbols in a way that forces
  128. an absolute result. Used in tracking symbols assigned from dot
  129. outside of output section statements, in order to later convert
  130. them from absolute. */
  131. bfd_boolean rel_from_abs;
  132. /* If evaluating an assignment, the destination. Cleared if an
  133. etree_name NAME matches this, to signal a self-assignment.
  134. Note that an etree_name DEFINED does not clear this field, nor
  135. does the false branch of a trinary expression. */
  136. const char *assign_name;
  137. /* Working results. */
  138. etree_value_type result;
  139. bfd_vma dot;
  140. /* Current dot and section passed to ldexp folder. */
  141. bfd_vma *dotp;
  142. asection *section;
  143. /* State machine and results for DATASEG. */
  144. struct {
  145. enum phase_enum phase;
  146. bfd_vma base, relro_offset, relro_end, end, pagesize, maxpagesize;
  147. enum relro_enum relro;
  148. union lang_statement_union *relro_start_stat;
  149. union lang_statement_union *relro_end_stat;
  150. } dataseg;
  151. };
  152. extern struct ldexp_control expld;
  153. /* A maps from a segment name to a base address. */
  154. typedef struct segment_struct {
  155. /* The next segment in the linked list. */
  156. struct segment_struct *next;
  157. /* The name of the sgement. */
  158. const char *name;
  159. /* The base address for the segment. */
  160. bfd_vma value;
  161. /* True if a SEGMENT_START directive corresponding to this segment
  162. has been seen. */
  163. bfd_boolean used;
  164. } segment_type;
  165. /* The segments specified by the user on the command-line. */
  166. extern segment_type *segments;
  167. typedef struct _fill_type fill_type;
  168. etree_type *exp_intop
  169. (bfd_vma);
  170. etree_type *exp_bigintop
  171. (bfd_vma, char *);
  172. etree_type *exp_relop
  173. (asection *, bfd_vma);
  174. void exp_fold_tree
  175. (etree_type *, asection *, bfd_vma *);
  176. void exp_fold_tree_no_dot
  177. (etree_type *);
  178. etree_type *exp_binop
  179. (int, etree_type *, etree_type *);
  180. etree_type *exp_trinop
  181. (int,etree_type *, etree_type *, etree_type *);
  182. etree_type *exp_unop
  183. (int, etree_type *);
  184. etree_type *exp_nameop
  185. (int, const char *);
  186. etree_type *exp_assign
  187. (const char *, etree_type *, bfd_boolean);
  188. etree_type *exp_defsym
  189. (const char *, etree_type *);
  190. etree_type *exp_provide
  191. (const char *, etree_type *, bfd_boolean);
  192. etree_type *exp_assert
  193. (etree_type *, const char *);
  194. void exp_print_tree
  195. (etree_type *);
  196. bfd_vma exp_get_vma
  197. (etree_type *, bfd_vma, char *);
  198. int exp_get_value_int
  199. (etree_type *, int, char *);
  200. fill_type *exp_get_fill
  201. (etree_type *, fill_type *, char *);
  202. bfd_vma exp_get_abs_int
  203. (etree_type *, int, char *);
  204. void ldexp_init (void);
  205. void ldexp_finalize_syms (void);
  206. void ldexp_finish (void);
  207. #endif