0001-or1k-Add-mcmodel-option-to-handle-large-GOTs.patch 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. From 35c0801efa26bf248d278b5711b77a19e95b2f57 Mon Sep 17 00:00:00 2001
  2. From: Stafford Horne <shorne@gmail.com>
  3. Date: Tue, 6 Apr 2021 05:47:17 +0900
  4. Subject: [PATCH] or1k: Add mcmodel option to handle large GOTs
  5. When building libgeos we get an error with:
  6. linux-uclibc/9.3.0/crtbeginS.o: in function `__do_global_dtors_aux':
  7. crtstuff.c:(.text+0x118): relocation truncated to fit: R_OR1K_GOT16 against symbol `__cxa_finalize' defined in .text section in
  8. /home/shorne/work/openrisc/3eb9f9d0f6d8274b2d19753c006bd83f7d536e3c/output/host/or1k-buildroot-linux-uclibc/sysroot/lib/libc.so.
  9. This is caused by GOT code having a limit of 64k. In OpenRISC this
  10. looks to be the only relocation code pattern to be limited to 64k.
  11. This patch allows specifying a new option -mcmodel=large which can be
  12. used to generate 2 more instructions to construct 32-bit addresses for
  13. up to 4G GOTs.
  14. gcc/ChangeLog:
  15. PR target/99783
  16. * config/or1k/or1k-opts.h: New file.
  17. * config/or1k/or1k.c (or1k_legitimize_address_1, print_reloc):
  18. Support generating gotha relocations if -mcmodel=large is
  19. specified.
  20. * config/or1k/or1k.h (TARGET_CMODEL_SMALL, TARGET_CMODEL_LARGE):
  21. New macros.
  22. * config/or1k/or1k.opt (mcmodel=): New option.
  23. * doc/invoke.texi (OpenRISC Options): Document mcmodel.
  24. Uptream: eff8110674ef193481d3657456a262beeb9951ff
  25. Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
  26. [Romain: add Upstream tag]
  27. Signed-off-by: Romain Naour <romain.naour@gmail.com>
  28. ---
  29. gcc/config/or1k/or1k-opts.h | 30 ++++++++++++++++++++++++++++++
  30. gcc/config/or1k/or1k.c | 11 +++++++++--
  31. gcc/config/or1k/or1k.h | 7 +++++++
  32. gcc/config/or1k/or1k.opt | 19 +++++++++++++++++++
  33. gcc/doc/invoke.texi | 12 +++++++++++-
  34. 5 files changed, 76 insertions(+), 3 deletions(-)
  35. create mode 100644 gcc/config/or1k/or1k-opts.h
  36. diff --git a/gcc/config/or1k/or1k-opts.h b/gcc/config/or1k/or1k-opts.h
  37. new file mode 100644
  38. index 00000000000..f791b894fdd
  39. --- /dev/null
  40. +++ b/gcc/config/or1k/or1k-opts.h
  41. @@ -0,0 +1,30 @@
  42. +/* Definitions for option handling for OpenRISC.
  43. + Copyright (C) 2021 Free Software Foundation, Inc.
  44. + Contributed by Stafford Horne.
  45. +
  46. + This file is part of GCC.
  47. +
  48. + GCC is free software; you can redistribute it and/or modify it
  49. + under the terms of the GNU General Public License as published
  50. + by the Free Software Foundation; either version 3, or (at your
  51. + option) any later version.
  52. +
  53. + GCC is distributed in the hope that it will be useful, but WITHOUT
  54. + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  55. + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  56. + License for more details.
  57. +
  58. + You should have received a copy of the GNU General Public License
  59. + along with GCC; see the file COPYING3. If not see
  60. + <http://www.gnu.org/licenses/>. */
  61. +
  62. +#ifndef GCC_OR1K_OPTS_H
  63. +#define GCC_OR1K_OPTS_H
  64. +
  65. +/* The OpenRISC code generation models available. */
  66. +enum or1k_cmodel_type {
  67. + CMODEL_SMALL,
  68. + CMODEL_LARGE
  69. +};
  70. +
  71. +#endif /* GCC_OR1K_OPTS_H */
  72. diff --git a/gcc/config/or1k/or1k.c b/gcc/config/or1k/or1k.c
  73. index e772a7addea..27d3fa17995 100644
  74. --- a/gcc/config/or1k/or1k.c
  75. +++ b/gcc/config/or1k/or1k.c
  76. @@ -750,7 +750,14 @@ or1k_legitimize_address_1 (rtx x, rtx scratch)
  77. {
  78. base = gen_sym_unspec (base, UNSPEC_GOT);
  79. crtl->uses_pic_offset_table = 1;
  80. - t2 = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, base);
  81. + if (TARGET_CMODEL_LARGE)
  82. + {
  83. + emit_insn (gen_rtx_SET (t1, gen_rtx_HIGH (Pmode, base)));
  84. + emit_insn (gen_add3_insn (t1, t1, pic_offset_table_rtx));
  85. + t2 = gen_rtx_LO_SUM (Pmode, t1, base);
  86. + }
  87. + else
  88. + t2 = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, base);
  89. t2 = gen_const_mem (Pmode, t2);
  90. emit_insn (gen_rtx_SET (t1, t2));
  91. base = t1;
  92. @@ -1089,7 +1096,7 @@ print_reloc (FILE *stream, rtx x, HOST_WIDE_INT add, reloc_kind kind)
  93. no special markup. */
  94. static const char * const relocs[RKIND_MAX][RTYPE_MAX] = {
  95. { "lo", "got", "gotofflo", "tpofflo", "gottpofflo", "tlsgdlo" },
  96. - { "ha", NULL, "gotoffha", "tpoffha", "gottpoffha", "tlsgdhi" },
  97. + { "ha", "gotha", "gotoffha", "tpoffha", "gottpoffha", "tlsgdhi" },
  98. };
  99. reloc_type type = RTYPE_DIRECT;
  100. diff --git a/gcc/config/or1k/or1k.h b/gcc/config/or1k/or1k.h
  101. index fe01ab81ead..669907e7e74 100644
  102. --- a/gcc/config/or1k/or1k.h
  103. +++ b/gcc/config/or1k/or1k.h
  104. @@ -21,6 +21,8 @@
  105. #ifndef GCC_OR1K_H
  106. #define GCC_OR1K_H
  107. +#include "config/or1k/or1k-opts.h"
  108. +
  109. /* Names to predefine in the preprocessor for this target machine. */
  110. #define TARGET_CPU_CPP_BUILTINS() \
  111. do \
  112. @@ -37,6 +39,11 @@
  113. } \
  114. while (0)
  115. +#define TARGET_CMODEL_SMALL \
  116. + (or1k_code_model == CMODEL_SMALL)
  117. +#define TARGET_CMODEL_LARGE \
  118. + (or1k_code_model == CMODEL_LARGE)
  119. +
  120. /* Storage layout. */
  121. #define DEFAULT_SIGNED_CHAR 1
  122. diff --git a/gcc/config/or1k/or1k.opt b/gcc/config/or1k/or1k.opt
  123. index 6bd0f3eee6d..cc23e3b8856 100644
  124. --- a/gcc/config/or1k/or1k.opt
  125. +++ b/gcc/config/or1k/or1k.opt
  126. @@ -21,6 +21,9 @@
  127. ; See the GCC internals manual (options.texi) for a description of
  128. ; this file's format.
  129. +HeaderInclude
  130. +config/or1k/or1k-opts.h
  131. +
  132. mhard-div
  133. Target RejectNegative InverseMask(SOFT_DIV)
  134. Enable generation of hardware divide (l.div, l.divu) instructions. This is the
  135. @@ -63,6 +66,22 @@ When -mhard-float is selected, enables generation of unordered floating point
  136. compare and set flag (lf.sfun*) instructions. By default functions from libgcc
  137. are used to perform unordered floating point compare and set flag operations.
  138. +mcmodel=
  139. +Target RejectNegative Joined Enum(or1k_cmodel_type) Var(or1k_code_model) Init(CMODEL_SMALL)
  140. +Specify the code model used for accessing memory addresses. Specifying large
  141. +enables generating binaries with large global offset tables. By default the
  142. +value is small.
  143. +
  144. +Enum
  145. +Name(or1k_cmodel_type) Type(enum or1k_cmodel_type)
  146. +Known code model types (for use with the -mcmodel= option):
  147. +
  148. +EnumValue
  149. +Enum(or1k_cmodel_type) String(small) Value(CMODEL_SMALL)
  150. +
  151. +EnumValue
  152. +Enum(or1k_cmodel_type) String(large) Value(CMODEL_LARGE)
  153. +
  154. mcmov
  155. Target RejectNegative Mask(CMOV)
  156. Enable generation of conditional move (l.cmov) instructions. By default the
  157. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
  158. index f1217812280..90c6186fc14 100644
  159. --- a/gcc/doc/invoke.texi
  160. +++ b/gcc/doc/invoke.texi
  161. @@ -1136,7 +1136,8 @@ Objective-C and Objective-C++ Dialects}.
  162. @gccoptlist{-mboard=@var{name} -mnewlib -mhard-mul -mhard-div @gol
  163. -msoft-mul -msoft-div @gol
  164. -msoft-float -mhard-float -mdouble-float -munordered-float @gol
  165. --mcmov -mror -mrori -msext -msfimm -mshftimm}
  166. +-mcmov -mror -mrori -msext -msfimm -mshftimm @gol
  167. +-mcmodel=@var{code-model}}
  168. @emph{PDP-11 Options}
  169. @gccoptlist{-mfpu -msoft-float -mac0 -mno-ac0 -m40 -m45 -m10 @gol
  170. @@ -26444,6 +26445,15 @@ Enable generation of shift with immediate (@code{l.srai}, @code{l.srli},
  171. @code{l.slli}) instructions. By default extra instructions will be generated
  172. to store the immediate to a register first.
  173. +@item -mcmodel=small
  174. +@opindex mcmodel=small
  175. +Generate OpenRISC code for the small model: The GOT is limited to 64k. This is
  176. +the default model.
  177. +
  178. +@item -mcmodel=large
  179. +@opindex mcmodel=large
  180. +Generate OpenRISC code for the large model: The GOT may grow up to 4G in size.
  181. +
  182. @end table
  183. --
  184. 2.34.3