200-mips_non_pic.patch 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. --- a/bfd/elf32-mips.c
  2. +++ b/bfd/elf32-mips.c
  3. @@ -1663,6 +1663,15 @@ static const struct ecoff_debug_swap mip
  4. #define elf_backend_plt_readonly 1
  5. #define elf_backend_plt_sym_val _bfd_mips_elf_plt_sym_val
  6. +/* Most MIPS ELF files do not contain a traditional PLT; only VxWorks
  7. + and non-PIC dynamic executables do. These settings only affect
  8. + _bfd_elf_create_dynamic_sections, which is only called when we
  9. + do want a traditional PLT. */
  10. +#undef elf_backend_want_plt_sym
  11. +#define elf_backend_want_plt_sym 1
  12. +#undef elf_backend_plt_readonly
  13. +#define elf_backend_plt_readonly 1
  14. +
  15. #define elf_backend_discard_info _bfd_mips_elf_discard_info
  16. #define elf_backend_ignore_discarded_relocs \
  17. _bfd_mips_elf_ignore_discarded_relocs
  18. @@ -1687,6 +1696,8 @@ static const struct ecoff_debug_swap mip
  19. #define bfd_elf32_bfd_print_private_bfd_data \
  20. _bfd_mips_elf_print_private_bfd_data
  21. +#define elf_backend_plt_sym_val _bfd_mips_elf_plt_sym_val
  22. +
  23. /* Support for SGI-ish mips targets. */
  24. #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec
  25. #define TARGET_LITTLE_NAME "elf32-littlemips"
  26. @@ -1790,6 +1801,7 @@ mips_vxworks_final_write_processing (bfd
  27. #undef elf_backend_additional_program_headers
  28. #undef elf_backend_modify_segment_map
  29. #undef elf_backend_symbol_processing
  30. +#undef elf_backend_plt_sym_val
  31. /* NOTE: elf_backend_rela_normal is not defined for MIPS. */
  32. #include "elf32-target.h"
  33. --- a/bfd/elfxx-mips.c
  34. +++ b/bfd/elfxx-mips.c
  35. @@ -694,6 +694,11 @@ static bfd *reldyn_sorting_bfd;
  36. /* Nonzero if ABFD is using NewABI conventions. */
  37. #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
  38. +/* Nonzero if ABFD is a non-PIC object. */
  39. +#define NON_PIC_P(abfd) \
  40. + (((elf_elfheader (abfd)->e_flags & EF_MIPS_PIC) == 0) \
  41. + && ((elf_elfheader (abfd)->e_flags & EF_MIPS_CPIC) == EF_MIPS_CPIC))
  42. +
  43. /* The IRIX compatibility level we are striving for. */
  44. #define IRIX_COMPAT(abfd) \
  45. (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
  46. @@ -706,6 +711,9 @@ static bfd *reldyn_sorting_bfd;
  47. #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
  48. (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
  49. +/* The name of the section holding non-PIC to PIC call stubs. */
  50. +#define NON_PIC_TO_PIC_STUB_SECTION_NAME ".MIPS.pic_stubs"
  51. +
  52. /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
  53. Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
  54. #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
  55. @@ -7619,7 +7627,9 @@ _bfd_mips_elf_check_relocs (bfd *abfd, s
  56. /* We need a stub, not a plt entry for the undefined
  57. function. But we record it as if it needs plt. See
  58. - _bfd_elf_adjust_dynamic_symbol. */
  59. + _bfd_elf_adjust_dynamic_symbol. Note that these relocations
  60. + are always used for PIC calls, even when using the new
  61. + non-PIC ABI. */
  62. h->needs_plt = 1;
  63. h->type = STT_FUNC;
  64. }
  65. @@ -7725,6 +7735,8 @@ _bfd_mips_elf_check_relocs (bfd *abfd, s
  66. case R_MIPS_32:
  67. case R_MIPS_REL32:
  68. case R_MIPS_64:
  69. + if (h != NULL)
  70. + h->non_got_ref = TRUE;
  71. /* In VxWorks executables, references to external symbols
  72. are handled using copy relocs or PLT stubs, so there's
  73. no need to add a .rela.dyn entry for this relocation. */
  74. @@ -7780,11 +7792,21 @@ _bfd_mips_elf_check_relocs (bfd *abfd, s
  75. case R_MIPS_GPREL16:
  76. case R_MIPS_LITERAL:
  77. case R_MIPS_GPREL32:
  78. + if (h != NULL
  79. + && (r_type == R_MIPS_GPREL16 || r_type == R_MIPS_GPREL32))
  80. + h->non_got_ref = TRUE;
  81. +
  82. if (SGI_COMPAT (abfd))
  83. mips_elf_hash_table (info)->compact_rel_size +=
  84. sizeof (Elf32_External_crinfo);
  85. break;
  86. + case R_MIPS_HI16:
  87. + case R_MIPS_LO16:
  88. + if (h != NULL && strcmp (h->root.root.string, "_gp_disp") != 0)
  89. + h->non_got_ref = TRUE;
  90. + break;
  91. +
  92. /* This relocation describes the C++ object vtable hierarchy.
  93. Reconstruct it for later use during GC. */
  94. case R_MIPS_GNU_VTINHERIT:
  95. @@ -7807,20 +7829,20 @@ _bfd_mips_elf_check_relocs (bfd *abfd, s
  96. /* We must not create a stub for a symbol that has relocations
  97. related to taking the function's address. This doesn't apply to
  98. - VxWorks, where CALL relocs refer to a .got.plt entry instead of
  99. - a normal .got entry. */
  100. + VxWorks or the non-PIC ABI, where CALL relocs refer to a
  101. + .got.plt entry instead of a normal .got entry. */
  102. if (!htab->is_vxworks && h != NULL)
  103. switch (r_type)
  104. {
  105. - default:
  106. - ((struct mips_elf_link_hash_entry *) h)->no_fn_stub = TRUE;
  107. - break;
  108. case R_MIPS16_CALL16:
  109. case R_MIPS_CALL16:
  110. case R_MIPS_CALL_HI16:
  111. case R_MIPS_CALL_LO16:
  112. case R_MIPS_JALR:
  113. break;
  114. + default:
  115. + ((struct mips_elf_link_hash_entry *) h)->no_fn_stub = TRUE;
  116. + break;
  117. }
  118. /* See if this reloc would need to refer to a MIPS16 hard-float stub,
  119. @@ -12514,7 +12536,9 @@ _bfd_mips_elf_merge_private_bfd_data (bf
  120. break;
  121. }
  122. }
  123. - if (null_input_bfd)
  124. + /* Dynamic objects normally have no sections, and do not reach
  125. + here - but they might if used as DYNOBJ. */
  126. + if (null_input_bfd || (ibfd->flags & DYNAMIC) != 0)
  127. return TRUE;
  128. ok = TRUE;
  129. --- a/bfd/elfxx-mips.h
  130. +++ b/bfd/elfxx-mips.h
  131. @@ -63,6 +63,9 @@ extern bfd_boolean _bfd_mips_elf_finish_
  132. extern bfd_boolean _bfd_mips_vxworks_finish_dynamic_symbol
  133. (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
  134. Elf_Internal_Sym *);
  135. +extern bfd_boolean _bfd_mips_nonpic_finish_dynamic_symbol
  136. + (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
  137. + Elf_Internal_Sym *);
  138. extern bfd_boolean _bfd_mips_elf_finish_dynamic_sections
  139. (bfd *, struct bfd_link_info *);
  140. extern void _bfd_mips_elf_final_write_processing
  141. @@ -153,6 +156,15 @@ extern const struct bfd_elf_special_sect
  142. extern bfd_boolean _bfd_mips_elf_common_definition (Elf_Internal_Sym *);
  143. +extern bfd_vma _bfd_mips_elf_plt_sym_val
  144. + (bfd_vma, const asection *, const arelent *);
  145. +extern void _bfd_mips_elf_begin_write_processing
  146. + (bfd *abfd, struct bfd_link_info *link_info);
  147. +extern bfd_boolean bfd_mips_elf_maybe_create_non_pic_to_pic_stubs_section
  148. + (struct bfd_link_info *);
  149. +extern void _bfd_mips_post_process_headers
  150. + (bfd *abfd, struct bfd_link_info *link_info);
  151. +
  152. #define elf_backend_common_definition _bfd_mips_elf_common_definition
  153. #define elf_backend_name_local_section_symbols \
  154. _bfd_mips_elf_name_local_section_symbols
  155. --- a/gas/config/tc-mips.c
  156. +++ b/gas/config/tc-mips.c
  157. @@ -1891,6 +1891,12 @@ md_begin (void)
  158. as_bad (_("-G may not be used in position-independent code"));
  159. g_switch_value = 0;
  160. }
  161. + else if (mips_abicalls)
  162. + {
  163. + if (g_switch_seen && g_switch_value != 0)
  164. + as_bad (_("-G may not be used with abicalls"));
  165. + g_switch_value = 0;
  166. + }
  167. if (! bfd_set_arch_mach (stdoutput, bfd_arch_mips, file_mips_arch))
  168. as_warn (_("Could not set architecture and machine"));
  169. @@ -11258,6 +11264,7 @@ enum options
  170. OPTION_PDR,
  171. OPTION_NO_PDR,
  172. OPTION_MVXWORKS_PIC,
  173. + OPTION_NON_PIC_ABICALLS,
  174. #endif /* OBJ_ELF */
  175. OPTION_END_OF_ENUM
  176. };
  177. @@ -11359,6 +11366,7 @@ struct option md_longopts[] =
  178. {"mpdr", no_argument, NULL, OPTION_PDR},
  179. {"mno-pdr", no_argument, NULL, OPTION_NO_PDR},
  180. {"mvxworks-pic", no_argument, NULL, OPTION_MVXWORKS_PIC},
  181. + {"mnon-pic-abicalls", no_argument, NULL, OPTION_NON_PIC_ABICALLS},
  182. #endif /* OBJ_ELF */
  183. {NULL, no_argument, NULL, 0}
  184. @@ -11783,6 +11791,11 @@ md_parse_option (int c, char *arg)
  185. case OPTION_MVXWORKS_PIC:
  186. mips_pic = VXWORKS_PIC;
  187. break;
  188. +
  189. + case OPTION_NON_PIC_ABICALLS:
  190. + mips_pic = NO_PIC;
  191. + mips_abicalls = TRUE;
  192. + break;
  193. #endif /* OBJ_ELF */
  194. default: