elf32-nds32.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* NDS32-specific support for 32-bit ELF.
  2. Copyright (C) 2012-2022 Free Software Foundation, Inc.
  3. Contributed by Andes Technology Corporation.
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program 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.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  16. 02110-1301, USA.*/
  17. #ifndef ELF32_NDS32_H
  18. #define ELF32_NDS32_H
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /* Relocation flags encoded in r_addend. */
  23. /* Relocation flags for R_NDS32_ERLAX_ENTRY. */
  24. /* Set if relax on this section is done or disabled. */
  25. #define R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG (1u << 31)
  26. /* Optimize for performance. */
  27. #define R_NDS32_RELAX_ENTRY_OPTIMIZE_FLAG (1u << 30)
  28. /* Optimize for size. Branch destination 4-byte adjustment
  29. may be disabled. */
  30. #define R_NDS32_RELAX_ENTRY_OPTIMIZE_FOR_SPACE_FLAG (1u << 29)
  31. /* To distinguish the assembly code generated by compiler
  32. or written manually. */
  33. #define R_NDS32_RELAX_ENTRY_VERBATIM_FLAG (1u << 28)
  34. /* Two bits for ICT to comply with files without directive. */
  35. /* ICT small model. */
  36. #define R_NDS32_RELAX_ENTRY_ICT_SMALL (0x2u << 4)
  37. /* ICT large model. */
  38. #define R_NDS32_RELAX_ENTRY_ICT_LARGE (0x3u << 4)
  39. /* Mask for get ict bits. */
  40. #define R_NDS32_RELAX_ENTRY_ICT_MASK (0x3u << 4)
  41. /* Relocation flags for R_NDS32_INSN16. */
  42. /* Tag the nop16 can be removed. */
  43. #define R_NDS32_INSN16_CONVERT_FLAG (1u << 0)
  44. /* Convert a gp-relative access (e.g., lwi.gp)
  45. to fp-as-gp access (lwi37.fp).
  46. This value is used by linker internally only.
  47. It's fine to change the vlaue. */
  48. #define R_NDS32_INSN16_FP7U2_FLAG (1u << 1)
  49. /* Relocation flags for R_NDS32_RELAX_REGION_OMIT_FP_START/END. */
  50. /* OMIT_FP_FLAG marks the region for applying fp-as-gp
  51. optimization. */
  52. #define R_NDS32_RELAX_REGION_OMIT_FP_FLAG (1u << 0)
  53. /* NOT_OMIT_FP_FLAG is set if this region is not worth
  54. for fp-as-gp. */
  55. #define R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG (1u << 1)
  56. /* A Innermost loop region. Some optimizations is suppressed
  57. in this region due to performance drop. */
  58. #define R_NDS32_RELAX_REGION_INNERMOST_LOOP_FLAG (1u << 4)
  59. /* Tag range for LOADSTORE relocation. */
  60. enum
  61. {
  62. NDS32_LOADSTORE_NONE = 0x0,
  63. NDS32_LOADSTORE_BYTE = 0x1,
  64. NDS32_LOADSTORE_HALF = 0x2,
  65. NDS32_LOADSTORE_WORD = 0x4,
  66. NDS32_LOADSTORE_FLOAT_S = 0x8,
  67. NDS32_LOADSTORE_FLOAT_D = 0x10,
  68. NDS32_LOADSTORE_IMM = 0x20
  69. };
  70. struct section_id_list_t
  71. {
  72. int id;
  73. struct section_id_list_t *next;
  74. };
  75. extern struct section_id_list_t *elf32_nds32_lookup_section_id
  76. (int, struct section_id_list_t **);
  77. extern int elf32_nds32_check_relax_group (bfd *, asection *);
  78. extern int elf32_nds32_unify_relax_group (bfd *, asection *);
  79. extern int nds32_elf_unify_tls_model (bfd *, asection *, bfd_byte *,
  80. struct bfd_link_info *);
  81. extern int nds32_convert_32_to_16 (bfd *, uint32_t, uint16_t *, int *);
  82. extern int nds32_convert_16_to_32 (bfd *, uint16_t, uint32_t *);
  83. extern void bfd_elf32_nds32_set_target_option (struct bfd_link_info *,
  84. int, int, FILE *,
  85. int, int, int);
  86. #define nds32_elf_hash_table(p) \
  87. ((is_elf_hash_table ((p)->hash) \
  88. && elf_hash_table_id (elf_hash_table (p)) == NDS32_ELF_DATA) \
  89. ? (struct elf_nds32_link_hash_table *) (p)->hash : NULL)
  90. #define elf32_nds32_compute_jump_table_size(htab) \
  91. ((htab)->next_tls_desc_index * 4)
  92. #define elf32_nds32_local_tlsdesc_gotent(bfd) \
  93. (elf_nds32_tdata (bfd)->local_tlsdesc_gotent)
  94. /* Hash table structure for target nds32. There are some members to
  95. save target options passed from nds32elf.em to bfd. */
  96. struct elf_nds32_link_hash_table
  97. {
  98. struct elf_link_hash_table root;
  99. /* Target dependent options. */
  100. int relax_fp_as_gp; /* --mrelax-omit-fp. */
  101. int eliminate_gc_relocs; /* --meliminate-gc-relocs. */
  102. FILE *sym_ld_script; /* --mgen-symbol-ld-script=<file>. */
  103. int hyper_relax; /* Relax for symbol not in RW sections. */
  104. int tls_desc_trampoline; /* --m[no-]tlsdesc-trampoline. */
  105. /* Disable if linking a dynamically linked executable. */
  106. int load_store_relax;
  107. /* Offset in .plt section of tls_nds32_trampoline. */
  108. bfd_vma tls_trampoline;
  109. /* The index of the next unused R_NDS32_TLS_DESC slot in .rel.plt. */
  110. bfd_vma next_tls_desc_index;
  111. /* How many R_NDS32_TLS_DESC relocations were generated so far. */
  112. bfd_vma num_tls_desc;
  113. /* The amount of space used by the reserved portion of the sgotplt
  114. section, plus whatever space is used by the jump slots. */
  115. bfd_vma sgotplt_jump_table_size;
  116. /* True if the target uses REL relocations. */
  117. int use_rel;
  118. };
  119. #ifdef __cplusplus
  120. }
  121. #endif
  122. #endif /* ELF32_NDS32_H */