0007-fdpic.diff 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953
  1. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/constraints.md gcc-5.2.0/gcc/config/sh/constraints.md
  2. --- ../baseline/gcc-5.2.0/gcc/config/sh/constraints.md 2015-03-23 18:57:58.000000000 +0000
  3. +++ gcc-5.2.0/gcc/config/sh/constraints.md 2015-09-03 17:12:56.462760038 +0000
  4. @@ -25,6 +25,7 @@
  5. ;; Bsc: SCRATCH - for the scratch register in movsi_ie in the
  6. ;; fldi0 / fldi0 cases
  7. ;; Cxx: Constants other than only CONST_INT
  8. +;; Ccl: call site label
  9. ;; Css: signed 16-bit constant, literal or symbolic
  10. ;; Csu: unsigned 16-bit constant, literal or symbolic
  11. ;; Csy: label or symbol
  12. @@ -233,6 +234,11 @@
  13. hence mova is being used, hence do not select this pattern."
  14. (match_code "scratch"))
  15. +(define_constraint "Ccl"
  16. + "A call site label, for bsrf."
  17. + (and (match_code "unspec")
  18. + (match_test "XINT (op, 1) == UNSPEC_CALLER")))
  19. +
  20. (define_constraint "Css"
  21. "A signed 16-bit constant, literal or symbolic."
  22. (and (match_code "const")
  23. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/linux.h gcc-5.2.0/gcc/config/sh/linux.h
  24. --- ../baseline/gcc-5.2.0/gcc/config/sh/linux.h 2015-09-04 20:23:46.714785579 +0000
  25. +++ gcc-5.2.0/gcc/config/sh/linux.h 2015-09-11 01:48:36.830264737 +0000
  26. @@ -63,7 +63,8 @@ along with GCC; see the file COPYING3.
  27. #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
  28. #undef SUBTARGET_LINK_EMUL_SUFFIX
  29. -#define SUBTARGET_LINK_EMUL_SUFFIX "_linux"
  30. +#define SUBTARGET_LINK_EMUL_SUFFIX "%{mfdpic:_fd;:_linux}"
  31. +
  32. #undef SUBTARGET_LINK_SPEC
  33. #define SUBTARGET_LINK_SPEC \
  34. "%{shared:-shared} \
  35. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/sh-c.c gcc-5.2.0/gcc/config/sh/sh-c.c
  36. --- ../baseline/gcc-5.2.0/gcc/config/sh/sh-c.c 2015-01-09 20:18:42.000000000 +0000
  37. +++ gcc-5.2.0/gcc/config/sh/sh-c.c 2015-09-03 18:22:04.182507130 +0000
  38. @@ -149,6 +149,11 @@ sh_cpu_cpp_builtins (cpp_reader* pfile)
  39. builtin_define ("__HITACHI__");
  40. if (TARGET_FMOVD)
  41. builtin_define ("__FMOVD_ENABLED__");
  42. + if (TARGET_FDPIC)
  43. + {
  44. + builtin_define ("__SH_FDPIC__");
  45. + builtin_define ("__FDPIC__");
  46. + }
  47. builtin_define (TARGET_LITTLE_ENDIAN
  48. ? "__LITTLE_ENDIAN__" : "__BIG_ENDIAN__");
  49. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/sh-mem.cc gcc-5.2.0/gcc/config/sh/sh-mem.cc
  50. --- ../baseline/gcc-5.2.0/gcc/config/sh/sh-mem.cc 2015-01-15 13:28:42.000000000 +0000
  51. +++ gcc-5.2.0/gcc/config/sh/sh-mem.cc 2015-09-03 17:37:09.436004777 +0000
  52. @@ -136,11 +136,13 @@ expand_block_move (rtx *operands)
  53. rtx func_addr_rtx = gen_reg_rtx (Pmode);
  54. rtx r4 = gen_rtx_REG (SImode, 4);
  55. rtx r5 = gen_rtx_REG (SImode, 5);
  56. + rtx lab;
  57. - function_symbol (func_addr_rtx, "__movmemSI12_i4", SFUNC_STATIC);
  58. + function_symbol (func_addr_rtx, "__movmemSI12_i4", SFUNC_STATIC,
  59. + &lab);
  60. force_into (XEXP (operands[0], 0), r4);
  61. force_into (XEXP (operands[1], 0), r5);
  62. - emit_insn (gen_block_move_real_i4 (func_addr_rtx));
  63. + emit_insn (gen_block_move_real_i4 (func_addr_rtx, lab));
  64. return true;
  65. }
  66. else if (! optimize_size)
  67. @@ -151,15 +153,16 @@ expand_block_move (rtx *operands)
  68. rtx r4 = gen_rtx_REG (SImode, 4);
  69. rtx r5 = gen_rtx_REG (SImode, 5);
  70. rtx r6 = gen_rtx_REG (SImode, 6);
  71. + rtx lab;
  72. entry_name = (bytes & 4 ? "__movmem_i4_odd" : "__movmem_i4_even");
  73. - function_symbol (func_addr_rtx, entry_name, SFUNC_STATIC);
  74. + function_symbol (func_addr_rtx, entry_name, SFUNC_STATIC, &lab);
  75. force_into (XEXP (operands[0], 0), r4);
  76. force_into (XEXP (operands[1], 0), r5);
  77. dwords = bytes >> 3;
  78. emit_insn (gen_move_insn (r6, GEN_INT (dwords - 1)));
  79. - emit_insn (gen_block_lump_real_i4 (func_addr_rtx));
  80. + emit_insn (gen_block_lump_real_i4 (func_addr_rtx, lab));
  81. return true;
  82. }
  83. else
  84. @@ -171,12 +174,13 @@ expand_block_move (rtx *operands)
  85. rtx func_addr_rtx = gen_reg_rtx (Pmode);
  86. rtx r4 = gen_rtx_REG (SImode, 4);
  87. rtx r5 = gen_rtx_REG (SImode, 5);
  88. + rtx lab;
  89. sprintf (entry, "__movmemSI%d", bytes);
  90. - function_symbol (func_addr_rtx, entry, SFUNC_STATIC);
  91. + function_symbol (func_addr_rtx, entry, SFUNC_STATIC, &lab);
  92. force_into (XEXP (operands[0], 0), r4);
  93. force_into (XEXP (operands[1], 0), r5);
  94. - emit_insn (gen_block_move_real (func_addr_rtx));
  95. + emit_insn (gen_block_move_real (func_addr_rtx, lab));
  96. return true;
  97. }
  98. @@ -189,8 +193,9 @@ expand_block_move (rtx *operands)
  99. rtx r4 = gen_rtx_REG (SImode, 4);
  100. rtx r5 = gen_rtx_REG (SImode, 5);
  101. rtx r6 = gen_rtx_REG (SImode, 6);
  102. + rtx lab;
  103. - function_symbol (func_addr_rtx, "__movmem", SFUNC_STATIC);
  104. + function_symbol (func_addr_rtx, "__movmem", SFUNC_STATIC, &lab);
  105. force_into (XEXP (operands[0], 0), r4);
  106. force_into (XEXP (operands[1], 0), r5);
  107. @@ -203,7 +208,7 @@ expand_block_move (rtx *operands)
  108. final_switch = 16 - ((bytes / 4) % 16);
  109. while_loop = ((bytes / 4) / 16 - 1) * 16;
  110. emit_insn (gen_move_insn (r6, GEN_INT (while_loop + final_switch)));
  111. - emit_insn (gen_block_lump_real (func_addr_rtx));
  112. + emit_insn (gen_block_lump_real (func_addr_rtx, lab));
  113. return true;
  114. }
  115. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/sh-protos.h gcc-5.2.0/gcc/config/sh/sh-protos.h
  116. --- ../baseline/gcc-5.2.0/gcc/config/sh/sh-protos.h 2015-09-04 20:23:46.684785581 +0000
  117. +++ gcc-5.2.0/gcc/config/sh/sh-protos.h 2015-09-03 17:24:17.489385180 +0000
  118. @@ -379,7 +379,7 @@ extern void fpscr_set_from_mem (int, HAR
  119. extern void sh_pr_interrupt (struct cpp_reader *);
  120. extern void sh_pr_trapa (struct cpp_reader *);
  121. extern void sh_pr_nosave_low_regs (struct cpp_reader *);
  122. -extern rtx function_symbol (rtx, const char *, enum sh_function_kind);
  123. +extern rtx function_symbol (rtx, const char *, enum sh_function_kind, rtx *);
  124. extern rtx sh_get_pr_initial_val (void);
  125. extern void sh_init_cumulative_args (CUMULATIVE_ARGS *, tree, rtx, tree,
  126. @@ -398,4 +398,7 @@ extern bool sh_hard_regno_mode_ok (unsig
  127. extern machine_mode sh_hard_regno_caller_save_mode (unsigned int, unsigned int,
  128. machine_mode);
  129. extern bool sh_can_use_simple_return_p (void);
  130. +extern bool sh_legitimate_constant_p (rtx);
  131. +extern rtx sh_load_function_descriptor (rtx);
  132. +extern rtx sh_our_fdpic_reg (void);
  133. #endif /* ! GCC_SH_PROTOS_H */
  134. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/sh.c gcc-5.2.0/gcc/config/sh/sh.c
  135. --- ../baseline/gcc-5.2.0/gcc/config/sh/sh.c 2015-09-04 20:23:46.694785580 +0000
  136. +++ gcc-5.2.0/gcc/config/sh/sh.c 2015-09-21 08:34:37.673856781 +0000
  137. @@ -288,6 +288,7 @@ static rtx sh_expand_builtin (tree, rtx,
  138. static void sh_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
  139. HOST_WIDE_INT, tree);
  140. static void sh_file_start (void);
  141. +static bool sh_assemble_integer (rtx, unsigned, int);
  142. static bool flow_dependent_p (rtx, rtx);
  143. static void flow_dependent_p_1 (rtx, const_rtx, void *);
  144. static int shiftcosts (rtx);
  145. @@ -296,6 +297,7 @@ static int addsubcosts (rtx);
  146. static int multcosts (rtx);
  147. static bool unspec_caller_rtx_p (rtx);
  148. static bool sh_cannot_copy_insn_p (rtx_insn *);
  149. +static bool sh_cannot_force_const_mem_p (machine_mode, rtx);
  150. static bool sh_rtx_costs (rtx, int, int, int, int *, bool);
  151. static int sh_address_cost (rtx, machine_mode, addr_space_t, bool);
  152. static int sh_pr_n_sets (void);
  153. @@ -353,6 +355,7 @@ static void sh_encode_section_info (tree
  154. static bool sh2a_function_vector_p (tree);
  155. static void sh_trampoline_init (rtx, tree, rtx);
  156. static rtx sh_trampoline_adjust_address (rtx);
  157. +static int sh_reloc_rw_mask (void);
  158. static void sh_conditional_register_usage (void);
  159. static bool sh_legitimate_constant_p (machine_mode, rtx);
  160. static int mov_insn_size (machine_mode, bool);
  161. @@ -437,6 +440,9 @@ static const struct attribute_spec sh_at
  162. #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
  163. #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
  164. +#undef TARGET_ASM_INTEGER
  165. +#define TARGET_ASM_INTEGER sh_assemble_integer
  166. +
  167. #undef TARGET_REGISTER_MOVE_COST
  168. #define TARGET_REGISTER_MOVE_COST sh_register_move_cost
  169. @@ -695,6 +701,12 @@ static const struct attribute_spec sh_at
  170. #undef TARGET_ATOMIC_TEST_AND_SET_TRUEVAL
  171. #define TARGET_ATOMIC_TEST_AND_SET_TRUEVAL 0x80
  172. +#undef TARGET_CANNOT_FORCE_CONST_MEM
  173. +#define TARGET_CANNOT_FORCE_CONST_MEM sh_cannot_force_const_mem_p
  174. +
  175. +#undef TARGET_ASM_RELOC_RW_MASK
  176. +#define TARGET_ASM_RELOC_RW_MASK sh_reloc_rw_mask
  177. +
  178. struct gcc_target targetm = TARGET_INITIALIZER;
  179. @@ -1012,6 +1024,13 @@ sh_option_override (void)
  180. if (! global_options_set.x_TARGET_ZDCBRANCH && TARGET_HARD_SH4)
  181. TARGET_ZDCBRANCH = 1;
  182. + if (TARGET_FDPIC && !flag_pic)
  183. + flag_pic = 2;
  184. +
  185. + if (TARGET_FDPIC
  186. + && (TARGET_SHMEDIA || TARGET_SHCOMPACT || !TARGET_SH2))
  187. + sorry ("non-SH2 FDPIC");
  188. +
  189. for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
  190. if (! VALID_REGISTER_P (regno))
  191. sh_register_names[regno][0] = '\0';
  192. @@ -1020,7 +1039,7 @@ sh_option_override (void)
  193. if (! VALID_REGISTER_P (ADDREGNAMES_REGNO (regno)))
  194. sh_additional_register_names[regno][0] = '\0';
  195. - if ((flag_pic && ! TARGET_PREFERGOT)
  196. + if (((flag_pic || TARGET_FDPIC) && ! TARGET_PREFERGOT)
  197. || (TARGET_SHMEDIA && !TARGET_PT_FIXED))
  198. flag_no_function_cse = 1;
  199. @@ -1695,6 +1714,14 @@ sh_asm_output_addr_const_extra (FILE *fi
  200. output_addr_const (file, XVECEXP (x, 0, 1));
  201. fputs ("-.)", file);
  202. break;
  203. + case UNSPEC_GOTFUNCDESC:
  204. + output_addr_const (file, XVECEXP (x, 0, 0));
  205. + fputs ("@GOTFUNCDESC", file);
  206. + break;
  207. + case UNSPEC_GOTOFFFUNCDESC:
  208. + output_addr_const (file, XVECEXP (x, 0, 0));
  209. + fputs ("@GOTOFFFUNCDESC", file);
  210. + break;
  211. default:
  212. return false;
  213. }
  214. @@ -1721,8 +1748,10 @@ sh_encode_section_info (tree decl, rtx r
  215. void
  216. prepare_move_operands (rtx operands[], machine_mode mode)
  217. {
  218. + rtx tmp, base, offset;
  219. +
  220. if ((mode == SImode || mode == DImode)
  221. - && flag_pic
  222. + && (flag_pic || TARGET_FDPIC)
  223. && ! ((mode == Pmode || mode == ptr_mode)
  224. && tls_symbolic_operand (operands[1], Pmode) != TLS_MODEL_NONE))
  225. {
  226. @@ -1842,7 +1871,7 @@ prepare_move_operands (rtx operands[], m
  227. {
  228. rtx tga_op1, tga_ret, tmp, tmp2;
  229. - if (! flag_pic
  230. + if (! flag_pic && ! TARGET_FDPIC
  231. && (tls_kind == TLS_MODEL_GLOBAL_DYNAMIC
  232. || tls_kind == TLS_MODEL_LOCAL_DYNAMIC
  233. || tls_kind == TLS_MODEL_INITIAL_EXEC))
  234. @@ -1863,6 +1892,11 @@ prepare_move_operands (rtx operands[], m
  235. {
  236. case TLS_MODEL_GLOBAL_DYNAMIC:
  237. tga_ret = gen_rtx_REG (Pmode, R0_REG);
  238. + if (TARGET_FDPIC)
  239. + {
  240. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  241. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  242. + }
  243. emit_call_insn (gen_tls_global_dynamic (tga_ret, op1));
  244. tmp = gen_reg_rtx (Pmode);
  245. emit_move_insn (tmp, tga_ret);
  246. @@ -1871,6 +1905,11 @@ prepare_move_operands (rtx operands[], m
  247. case TLS_MODEL_LOCAL_DYNAMIC:
  248. tga_ret = gen_rtx_REG (Pmode, R0_REG);
  249. + if (TARGET_FDPIC)
  250. + {
  251. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  252. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  253. + }
  254. emit_call_insn (gen_tls_local_dynamic (tga_ret, op1));
  255. tmp = gen_reg_rtx (Pmode);
  256. @@ -1888,6 +1927,11 @@ prepare_move_operands (rtx operands[], m
  257. case TLS_MODEL_INITIAL_EXEC:
  258. tga_op1 = !can_create_pseudo_p () ? op0 : gen_reg_rtx (Pmode);
  259. tmp = gen_sym2GOTTPOFF (op1);
  260. + if (TARGET_FDPIC)
  261. + {
  262. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  263. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  264. + }
  265. emit_insn (gen_tls_initial_exec (tga_op1, tmp));
  266. op1 = tga_op1;
  267. break;
  268. @@ -1914,6 +1958,20 @@ prepare_move_operands (rtx operands[], m
  269. operands[1] = op1;
  270. }
  271. }
  272. +
  273. + if (SH_OFFSETS_MUST_BE_WITHIN_SECTIONS_P)
  274. + {
  275. + split_const (operands[1], &base, &offset);
  276. + if (GET_CODE (base) == SYMBOL_REF
  277. + && !offset_within_block_p (base, INTVAL (offset)))
  278. + {
  279. + tmp = can_create_pseudo_p () ? gen_reg_rtx (mode) : operands[0];
  280. + emit_move_insn (tmp, base);
  281. + if (!arith_operand (offset, mode))
  282. + offset = force_reg (mode, offset);
  283. + emit_insn (gen_add3_insn (operands[0], tmp, offset));
  284. + }
  285. + }
  286. }
  287. /* Implement the canonicalize_comparison target hook for the combine
  288. @@ -3018,6 +3076,26 @@ sh_file_start (void)
  289. }
  290. }
  291. +/* Implementation of TARGET_ASM_INTEGER for SH. Pointers to functions
  292. + need to be output as pointers to function descriptors for
  293. + FDPIC. */
  294. +
  295. +static bool
  296. +sh_assemble_integer (rtx value, unsigned int size, int aligned_p)
  297. +{
  298. + if (TARGET_FDPIC
  299. + && size == UNITS_PER_WORD
  300. + && GET_CODE (value) == SYMBOL_REF
  301. + && SYMBOL_REF_FUNCTION_P (value))
  302. + {
  303. + fputs ("\t.long\t", asm_out_file);
  304. + output_addr_const (asm_out_file, value);
  305. + fputs ("@FUNCDESC\n", asm_out_file);
  306. + return true;
  307. + }
  308. + return default_assemble_integer (value, size, aligned_p);
  309. +}
  310. +
  311. /* Check if PAT includes UNSPEC_CALLER unspec pattern. */
  312. static bool
  313. unspec_caller_rtx_p (rtx pat)
  314. @@ -3044,7 +3122,7 @@ sh_cannot_copy_insn_p (rtx_insn *insn)
  315. {
  316. rtx pat;
  317. - if (!reload_completed || !flag_pic)
  318. + if (!reload_completed || (!flag_pic && !TARGET_FDPIC))
  319. return false;
  320. if (!NONJUMP_INSN_P (insn))
  321. @@ -3053,6 +3131,19 @@ sh_cannot_copy_insn_p (rtx_insn *insn)
  322. return false;
  323. pat = PATTERN (insn);
  324. +
  325. + if (GET_CODE (pat) == CLOBBER || GET_CODE (pat) == USE)
  326. + return false;
  327. +
  328. + if (TARGET_FDPIC
  329. + && GET_CODE (pat) == PARALLEL)
  330. + {
  331. + rtx t = XVECEXP (pat, 0, XVECLEN (pat, 0) - 1);
  332. + if (GET_CODE (t) == USE
  333. + && unspec_caller_rtx_p (XEXP (t, 0)))
  334. + return true;
  335. + }
  336. +
  337. if (GET_CODE (pat) != SET)
  338. return false;
  339. pat = SET_SRC (pat);
  340. @@ -4027,6 +4118,7 @@ expand_ashiftrt (rtx *operands)
  341. rtx wrk;
  342. char func[18];
  343. int value;
  344. + rtx lab;
  345. if (TARGET_DYNSHIFT)
  346. {
  347. @@ -4092,8 +4184,8 @@ expand_ashiftrt (rtx *operands)
  348. /* Load the value into an arg reg and call a helper. */
  349. emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
  350. sprintf (func, "__ashiftrt_r4_%d", value);
  351. - function_symbol (wrk, func, SFUNC_STATIC);
  352. - emit_insn (gen_ashrsi3_n (GEN_INT (value), wrk));
  353. + function_symbol (wrk, func, SFUNC_STATIC, &lab);
  354. + emit_insn (gen_ashrsi3_n (GEN_INT (value), wrk, lab));
  355. emit_move_insn (operands[0], gen_rtx_REG (SImode, 4));
  356. return true;
  357. }
  358. @@ -7941,7 +8033,9 @@ sh_expand_prologue (void)
  359. stack_usage += d;
  360. }
  361. - if (flag_pic && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM))
  362. + if (flag_pic
  363. + && !TARGET_FDPIC
  364. + && df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM))
  365. emit_insn (gen_GOTaddr2picreg (const0_rtx));
  366. if (SHMEDIA_REGS_STACK_ADJUST ())
  367. @@ -7951,7 +8045,7 @@ sh_expand_prologue (void)
  368. function_symbol (gen_rtx_REG (Pmode, R0_REG),
  369. (TARGET_FPU_ANY
  370. ? "__GCC_push_shmedia_regs"
  371. - : "__GCC_push_shmedia_regs_nofpu"), SFUNC_GOT);
  372. + : "__GCC_push_shmedia_regs_nofpu"), SFUNC_GOT, NULL);
  373. emit_insn (gen_shmedia_save_restore_regs_compact
  374. (GEN_INT (-SHMEDIA_REGS_STACK_ADJUST ())));
  375. }
  376. @@ -7974,7 +8068,7 @@ sh_expand_prologue (void)
  377. /* This must NOT go through the PLT, otherwise mach and macl
  378. may be clobbered. */
  379. function_symbol (gen_rtx_REG (Pmode, R0_REG),
  380. - "__GCC_shcompact_incoming_args", SFUNC_GOT);
  381. + "__GCC_shcompact_incoming_args", SFUNC_GOT, NULL);
  382. emit_insn (gen_shcompact_incoming_args ());
  383. }
  384. @@ -8064,7 +8158,7 @@ sh_expand_epilogue (bool sibcall_p)
  385. function_symbol (gen_rtx_REG (Pmode, R0_REG),
  386. (TARGET_FPU_ANY
  387. ? "__GCC_pop_shmedia_regs"
  388. - : "__GCC_pop_shmedia_regs_nofpu"), SFUNC_GOT);
  389. + : "__GCC_pop_shmedia_regs_nofpu"), SFUNC_GOT, NULL);
  390. /* This must NOT go through the PLT, otherwise mach and macl
  391. may be clobbered. */
  392. emit_insn (gen_shmedia_save_restore_regs_compact
  393. @@ -10445,7 +10539,9 @@ nonpic_symbol_mentioned_p (rtx x)
  394. || XINT (x, 1) == UNSPEC_PLT
  395. || XINT (x, 1) == UNSPEC_PCREL
  396. || XINT (x, 1) == UNSPEC_SYMOFF
  397. - || XINT (x, 1) == UNSPEC_PCREL_SYMOFF))
  398. + || XINT (x, 1) == UNSPEC_PCREL_SYMOFF
  399. + || XINT (x, 1) == UNSPEC_GOTFUNCDESC
  400. + || XINT (x, 1) == UNSPEC_GOTOFFFUNCDESC))
  401. return false;
  402. fmt = GET_RTX_FORMAT (GET_CODE (x));
  403. @@ -10480,7 +10576,28 @@ legitimize_pic_address (rtx orig, machin
  404. if (reg == NULL_RTX)
  405. reg = gen_reg_rtx (Pmode);
  406. - emit_insn (gen_symGOTOFF2reg (reg, orig));
  407. + if (TARGET_FDPIC
  408. + && GET_CODE (orig) == SYMBOL_REF
  409. + && SYMBOL_REF_FUNCTION_P (orig))
  410. + {
  411. + /* Weak functions may be NULL which doesn't work with
  412. + GOTOFFFUNCDESC because the runtime offset is not known. */
  413. + if (SYMBOL_REF_WEAK (orig))
  414. + emit_insn (gen_symGOTFUNCDESC2reg (reg, orig));
  415. + else
  416. + emit_insn (gen_symGOTOFFFUNCDESC2reg (reg, orig));
  417. + }
  418. + else if (TARGET_FDPIC
  419. + && (GET_CODE (orig) == LABEL_REF
  420. + || (GET_CODE (orig) == SYMBOL_REF
  421. + && SYMBOL_REF_DECL (orig)
  422. + && (TREE_READONLY (SYMBOL_REF_DECL (orig))
  423. + || SYMBOL_REF_EXTERNAL_P (orig)
  424. + || DECL_SECTION_NAME(SYMBOL_REF_DECL(orig))) )))
  425. + /* In FDPIC, GOTOFF can only be used for writable data. */
  426. + emit_insn (gen_symGOT2reg (reg, orig));
  427. + else
  428. + emit_insn (gen_symGOTOFF2reg (reg, orig));
  429. return reg;
  430. }
  431. else if (GET_CODE (orig) == SYMBOL_REF)
  432. @@ -10488,7 +10605,10 @@ legitimize_pic_address (rtx orig, machin
  433. if (reg == NULL_RTX)
  434. reg = gen_reg_rtx (Pmode);
  435. - emit_insn (gen_symGOT2reg (reg, orig));
  436. + if (TARGET_FDPIC && SYMBOL_REF_FUNCTION_P (orig))
  437. + emit_insn (gen_symGOTFUNCDESC2reg (reg, orig));
  438. + else
  439. + emit_insn (gen_symGOT2reg (reg, orig));
  440. return reg;
  441. }
  442. return orig;
  443. @@ -11662,20 +11782,40 @@ sh_trampoline_init (rtx tramp_mem, tree
  444. emit_insn (gen_initialize_trampoline (tramp, cxt, fnaddr));
  445. return;
  446. }
  447. - emit_move_insn (change_address (tramp_mem, SImode, NULL_RTX),
  448. - gen_int_mode (TARGET_LITTLE_ENDIAN ? 0xd301d202 : 0xd202d301,
  449. - SImode));
  450. - emit_move_insn (adjust_address (tramp_mem, SImode, 4),
  451. - gen_int_mode (TARGET_LITTLE_ENDIAN ? 0x0009422b : 0x422b0009,
  452. - SImode));
  453. - emit_move_insn (adjust_address (tramp_mem, SImode, 8), cxt);
  454. - emit_move_insn (adjust_address (tramp_mem, SImode, 12), fnaddr);
  455. + if (TARGET_FDPIC)
  456. + {
  457. + rtx a = force_reg (Pmode, plus_constant (Pmode, XEXP (tramp_mem, 0), 8));
  458. + emit_move_insn (adjust_address (tramp_mem, SImode, 0), a);
  459. + emit_move_insn (adjust_address (tramp_mem, SImode, 4), OUR_FDPIC_REG);
  460. + emit_move_insn (adjust_address (tramp_mem, SImode, 8),
  461. + gen_int_mode (TARGET_LITTLE_ENDIAN ? 0xd203d302 : 0xd302d203,
  462. + SImode));
  463. + emit_move_insn (adjust_address (tramp_mem, SImode, 12),
  464. + gen_int_mode (TARGET_LITTLE_ENDIAN ? 0x5c216122 : 0x61225c21,
  465. + SImode));
  466. + emit_move_insn (adjust_address (tramp_mem, SImode, 16),
  467. + gen_int_mode (TARGET_LITTLE_ENDIAN ? 0x0009412b : 0x412b0009,
  468. + SImode));
  469. + emit_move_insn (adjust_address (tramp_mem, SImode, 20), cxt);
  470. + emit_move_insn (adjust_address (tramp_mem, SImode, 24), fnaddr);
  471. + }
  472. + else
  473. + {
  474. + emit_move_insn (change_address (tramp_mem, SImode, NULL_RTX),
  475. + gen_int_mode (TARGET_LITTLE_ENDIAN ? 0xd301d202 : 0xd202d301,
  476. + SImode));
  477. + emit_move_insn (adjust_address (tramp_mem, SImode, 4),
  478. + gen_int_mode (TARGET_LITTLE_ENDIAN ? 0x0009422b : 0x422b0009,
  479. + SImode));
  480. + emit_move_insn (adjust_address (tramp_mem, SImode, 8), cxt);
  481. + emit_move_insn (adjust_address (tramp_mem, SImode, 12), fnaddr);
  482. + }
  483. if (TARGET_HARD_SH4 || TARGET_SH5)
  484. {
  485. if (!TARGET_INLINE_IC_INVALIDATE
  486. || (!(TARGET_SH4A || TARGET_SH4_300) && TARGET_USERMODE))
  487. emit_library_call (function_symbol (NULL, "__ic_invalidate",
  488. - FUNCTION_ORDINARY),
  489. + FUNCTION_ORDINARY, NULL),
  490. LCT_NORMAL, VOIDmode, 1, tramp, SImode);
  491. else
  492. emit_insn (gen_ic_invalidate_line (tramp));
  493. @@ -11705,7 +11845,7 @@ sh_function_ok_for_sibcall (tree decl, t
  494. && (! TARGET_SHCOMPACT
  495. || crtl->args.info.stack_regs == 0)
  496. && ! sh_cfun_interrupt_handler_p ()
  497. - && (! flag_pic
  498. + && (! flag_pic || TARGET_FDPIC
  499. || (decl && ! (TREE_PUBLIC (decl) || DECL_WEAK (decl)))
  500. || (decl && DECL_VISIBILITY (decl) != VISIBILITY_DEFAULT)));
  501. }
  502. @@ -11719,7 +11859,7 @@ sh_expand_sym_label2reg (rtx reg, rtx sy
  503. if (!is_weak && SYMBOL_REF_LOCAL_P (sym))
  504. emit_insn (gen_sym_label2reg (reg, sym, lab));
  505. - else if (sibcall_p)
  506. + else if (sibcall_p && SYMBOL_REF_LOCAL_P (sym))
  507. emit_insn (gen_symPCREL_label2reg (reg, sym, lab));
  508. else
  509. emit_insn (gen_symPLT_label2reg (reg, sym, lab));
  510. @@ -12718,10 +12858,18 @@ sh_output_mi_thunk (FILE *file, tree thu
  511. sibcall = gen_sibcalli_thunk (funexp, const0_rtx);
  512. else
  513. #endif
  514. - if (TARGET_SH2 && flag_pic)
  515. + if (TARGET_SH2 && (flag_pic || TARGET_FDPIC))
  516. {
  517. - sibcall = gen_sibcall_pcrel (funexp, const0_rtx);
  518. - XEXP (XVECEXP (sibcall, 0, 2), 0) = scratch2;
  519. + if (TARGET_FDPIC)
  520. + {
  521. + sibcall = gen_sibcall_pcrel_fdpic (funexp, const0_rtx);
  522. + XEXP (XVECEXP (sibcall, 0, 3), 0) = scratch2;
  523. + }
  524. + else
  525. + {
  526. + sibcall = gen_sibcall_pcrel (funexp, const0_rtx);
  527. + XEXP (XVECEXP (sibcall, 0, 2), 0) = scratch2;
  528. + }
  529. }
  530. else
  531. {
  532. @@ -12762,11 +12910,24 @@ sh_output_mi_thunk (FILE *file, tree thu
  533. epilogue_completed = 0;
  534. }
  535. +/* Return an RTX for the address of a function NAME of kind KIND,
  536. + placing the result in TARGET if not NULL. LAB should be non-NULL
  537. + for SFUNC_STATIC, if FDPIC; it will be set to (const_int 0) if jsr
  538. + should be used, or a label_ref if bsrf should be used. For FDPIC,
  539. + both SFUNC_GOT and SFUNC_STATIC will return the address of the
  540. + function itself, not a function descriptor, so they can only be
  541. + used with functions not using the FDPIC register that are known to
  542. + be called directory without a PLT entry. */
  543. +
  544. rtx
  545. -function_symbol (rtx target, const char *name, enum sh_function_kind kind)
  546. +function_symbol (rtx target, const char *name, enum sh_function_kind kind,
  547. + rtx *lab)
  548. {
  549. rtx sym;
  550. + if (lab)
  551. + *lab = const0_rtx;
  552. +
  553. /* If this is not an ordinary function, the name usually comes from a
  554. string literal or an sprintf buffer. Make sure we use the same
  555. string consistently, so that cse will be able to unify address loads. */
  556. @@ -12774,7 +12935,7 @@ function_symbol (rtx target, const char
  557. name = IDENTIFIER_POINTER (get_identifier (name));
  558. sym = gen_rtx_SYMBOL_REF (Pmode, name);
  559. SYMBOL_REF_FLAGS (sym) = SYMBOL_FLAG_FUNCTION;
  560. - if (flag_pic)
  561. + if (flag_pic || TARGET_FDPIC)
  562. switch (kind)
  563. {
  564. case FUNCTION_ORDINARY:
  565. @@ -12789,14 +12950,27 @@ function_symbol (rtx target, const char
  566. }
  567. case SFUNC_STATIC:
  568. {
  569. - /* ??? To allow cse to work, we use GOTOFF relocations.
  570. - We could add combiner patterns to transform this into
  571. - straight pc-relative calls with sym2PIC / bsrf when
  572. - label load and function call are still 1:1 and in the
  573. - same basic block during combine. */
  574. rtx reg = target ? target : gen_reg_rtx (Pmode);
  575. - emit_insn (gen_symGOTOFF2reg (reg, sym));
  576. + if (TARGET_FDPIC)
  577. + {
  578. + /* We use PC-relative calls, since GOTOFF can only refer
  579. + to writable data. This works along with
  580. + sh_sfunc_call. */
  581. + gcc_assert (lab != NULL);
  582. + *lab = PATTERN (gen_call_site ());
  583. + emit_insn (gen_sym_label2reg (reg, sym, *lab));
  584. + }
  585. + else
  586. + {
  587. + /* ??? To allow cse to work, we use GOTOFF relocations.
  588. + we could add combiner patterns to transform this into
  589. + straight pc-relative calls with sym2PIC / bsrf when
  590. + label load and function call are still 1:1 and in the
  591. + same basic block during combine. */
  592. + emit_insn (gen_symGOTOFF2reg (reg, sym));
  593. + }
  594. +
  595. sym = reg;
  596. break;
  597. }
  598. @@ -13419,6 +13593,12 @@ sh_conditional_register_usage (void)
  599. fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
  600. call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
  601. }
  602. + if (TARGET_FDPIC)
  603. + {
  604. + fixed_regs[PIC_REG] = 1;
  605. + call_used_regs[PIC_REG] = 1;
  606. + call_really_used_regs[PIC_REG] = 1;
  607. + }
  608. /* Renesas saves and restores mac registers on call. */
  609. if (TARGET_HITACHI && ! TARGET_NOMACSAVE)
  610. {
  611. @@ -14496,4 +14676,84 @@ sh_use_by_pieces_infrastructure_p (unsig
  612. }
  613. }
  614. +bool
  615. +sh_legitimate_constant_p (rtx x)
  616. +{
  617. + if (SH_OFFSETS_MUST_BE_WITHIN_SECTIONS_P)
  618. + {
  619. + rtx base, offset;
  620. +
  621. + split_const (x, &base, &offset);
  622. + if (GET_CODE (base) == SYMBOL_REF
  623. + && !offset_within_block_p (base, INTVAL (offset)))
  624. + return false;
  625. + }
  626. +
  627. + if (TARGET_FDPIC
  628. + && (SYMBOLIC_CONST_P (x)
  629. + || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
  630. + && SYMBOLIC_CONST_P (XEXP (XEXP (x, 0), 0)))))
  631. + return false;
  632. +
  633. + if (TARGET_SHMEDIA)
  634. + return ((GET_MODE (x) != DFmode
  635. + && GET_MODE_CLASS (GET_MODE (x)) != MODE_VECTOR_FLOAT)
  636. + || (x) == CONST0_RTX (GET_MODE (x))
  637. + || ! TARGET_SHMEDIA_FPU
  638. + || TARGET_SHMEDIA64);
  639. +
  640. + return (GET_CODE (x) != CONST_DOUBLE
  641. + || GET_MODE (x) == DFmode || GET_MODE (x) == SFmode
  642. + || GET_MODE (x) == DImode || GET_MODE (x) == VOIDmode);
  643. +}
  644. +
  645. +bool
  646. +sh_cannot_force_const_mem_p (machine_mode mode ATTRIBUTE_UNUSED,
  647. + rtx x ATTRIBUTE_UNUSED)
  648. +{
  649. + if (TARGET_FDPIC)
  650. + return true;
  651. +
  652. + return false;
  653. +}
  654. +
  655. +/* Emit insns to load the function address from FUNCDESC (an FDPIC
  656. + function descriptor) into r1 and the GOT address into r12,
  657. + returning an rtx for r1. */
  658. +
  659. +rtx
  660. +sh_load_function_descriptor (rtx funcdesc)
  661. +{
  662. + rtx r1 = gen_rtx_REG (Pmode, R1_REG);
  663. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  664. + rtx fnaddr = gen_rtx_MEM (Pmode, funcdesc);
  665. + rtx gotaddr = gen_rtx_MEM (Pmode, plus_constant (Pmode, funcdesc, 4));
  666. +
  667. + emit_move_insn (r1, fnaddr);
  668. + /* The ABI requires the entry point address to be loaded first, so
  669. + prevent the load from being moved after that of the GOT
  670. + address. */
  671. + emit_insn (gen_blockage ());
  672. + emit_move_insn (pic_reg, gotaddr);
  673. + return r1;
  674. +}
  675. +
  676. +/* Return an rtx holding the initial value of the FDPIC register (the
  677. + FDPIC pointer passed in from the caller). */
  678. +
  679. +rtx
  680. +sh_our_fdpic_reg (void)
  681. +{
  682. + return get_hard_reg_initial_val (Pmode, PIC_REG);
  683. +}
  684. +
  685. +/* Relocatable data for FDPIC binaries is not permitted in read-only
  686. + segments. */
  687. +
  688. +static int
  689. +sh_reloc_rw_mask (void)
  690. +{
  691. + return (flag_pic || TARGET_FDPIC) ? 3 : 0;
  692. +}
  693. +
  694. #include "gt-sh.h"
  695. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/sh.h gcc-5.2.0/gcc/config/sh/sh.h
  696. --- ../baseline/gcc-5.2.0/gcc/config/sh/sh.h 2015-09-04 20:23:46.711452245 +0000
  697. +++ gcc-5.2.0/gcc/config/sh/sh.h 2015-09-11 02:17:54.210157580 +0000
  698. @@ -321,7 +321,7 @@ extern int code_for_indirect_jump_scratc
  699. #endif
  700. #ifndef SUBTARGET_ASM_SPEC
  701. -#define SUBTARGET_ASM_SPEC ""
  702. +#define SUBTARGET_ASM_SPEC "%{!mno-fdpic:--fdpic}"
  703. #endif
  704. #if TARGET_ENDIAN_DEFAULT == MASK_LITTLE_ENDIAN
  705. @@ -349,7 +349,7 @@ extern int code_for_indirect_jump_scratc
  706. #define ASM_ISA_DEFAULT_SPEC ""
  707. #endif /* MASK_SH5 */
  708. -#define SUBTARGET_LINK_EMUL_SUFFIX ""
  709. +#define SUBTARGET_LINK_EMUL_SUFFIX "%{mfdpic:_fd}"
  710. #define SUBTARGET_LINK_SPEC ""
  711. /* Go via SH_LINK_SPEC to avoid code replication. */
  712. @@ -383,8 +383,18 @@ extern int code_for_indirect_jump_scratc
  713. "%{m2a*:%eSH2a does not support little-endian}}"
  714. #endif
  715. +#ifdef FDPIC_DEFAULT
  716. +#define FDPIC_SELF_SPECS "%{!mno-fdpic:-mfdpic}"
  717. +#else
  718. +#define FDPIC_SELF_SPECS
  719. +#endif
  720. +
  721. #undef DRIVER_SELF_SPECS
  722. -#define DRIVER_SELF_SPECS UNSUPPORTED_SH2A
  723. +#define DRIVER_SELF_SPECS UNSUPPORTED_SH2A SUBTARGET_DRIVER_SELF_SPECS \
  724. + FDPIC_SELF_SPECS
  725. +
  726. +#undef SUBTARGET_DRIVER_SELF_SPECS
  727. +#define SUBTARGET_DRIVER_SELF_SPECS
  728. #define ASSEMBLER_DIALECT assembler_dialect
  729. @@ -942,6 +952,14 @@ extern char sh_additional_register_names
  730. code access to data items. */
  731. #define PIC_OFFSET_TABLE_REGNUM (flag_pic ? PIC_REG : INVALID_REGNUM)
  732. +/* For FDPIC, the FDPIC register is call-clobbered (otherwise PLT
  733. + entries would need to handle saving and restoring it). */
  734. +#define PIC_OFFSET_TABLE_REG_CALL_CLOBBERED TARGET_FDPIC
  735. +
  736. +/* An rtx holding the initial value of the FDPIC register (the FDPIC
  737. + pointer passed in from the caller). */
  738. +#define OUR_FDPIC_REG sh_our_fdpic_reg ()
  739. +
  740. #define GOT_SYMBOL_NAME "*_GLOBAL_OFFSET_TABLE_"
  741. /* Definitions for register eliminations.
  742. @@ -1566,7 +1584,9 @@ struct sh_args {
  743. 6 000c 00000000 l2: .long function */
  744. /* Length in units of the trampoline for entering a nested function. */
  745. -#define TRAMPOLINE_SIZE (TARGET_SHMEDIA64 ? 40 : TARGET_SH5 ? 24 : 16)
  746. +// FIXME: what happens if someone tries fdpic on SH5?
  747. +#define TRAMPOLINE_SIZE \
  748. + (TARGET_SHMEDIA64 ? 40 : TARGET_SH5 ? 24 : TARGET_FDPIC ? 32 : 16)
  749. /* Alignment required for a trampoline in bits. */
  750. #define TRAMPOLINE_ALIGNMENT \
  751. @@ -1622,6 +1642,11 @@ struct sh_args {
  752. || GENERAL_REGISTER_P ((unsigned) reg_renumber[(REGNO)])) \
  753. : (REGNO) == R0_REG || (unsigned) reg_renumber[(REGNO)] == R0_REG)
  754. +/* True if SYMBOL + OFFSET constants must refer to something within
  755. + SYMBOL's section. */
  756. +// FIXME: is this correct?
  757. +#define SH_OFFSETS_MUST_BE_WITHIN_SECTIONS_P TARGET_FDPIC
  758. +
  759. /* Maximum number of registers that can appear in a valid memory
  760. address. */
  761. #define MAX_REGS_PER_ADDRESS 2
  762. @@ -2262,9 +2287,12 @@ extern int current_function_interrupt;
  763. /* We have to distinguish between code and data, so that we apply
  764. datalabel where and only where appropriate. Use sdataN for data. */
  765. #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
  766. - ((flag_pic && (GLOBAL) ? DW_EH_PE_indirect : 0) \
  767. - | (flag_pic ? DW_EH_PE_pcrel : DW_EH_PE_absptr) \
  768. - | ((CODE) ? 0 : (TARGET_SHMEDIA64 ? DW_EH_PE_sdata8 : DW_EH_PE_sdata4)))
  769. + ((TARGET_FDPIC \
  770. + ? ((GLOBAL) ? DW_EH_PE_indirect | DW_EH_PE_datarel \
  771. + : DW_EH_PE_pcrel) \
  772. + : ((flag_pic && (GLOBAL) ? DW_EH_PE_indirect : 0) \
  773. + | (flag_pic ? DW_EH_PE_pcrel : DW_EH_PE_absptr))) \
  774. + | ((CODE) ? 0 : (TARGET_SHMEDIA64 ? DW_EH_PE_sdata8 : DW_EH_PE_sdata4)))
  775. /* Handle special EH pointer encodings. Absolute, pc-relative, and
  776. indirect are handled automatically. */
  777. @@ -2277,6 +2305,17 @@ extern int current_function_interrupt;
  778. SYMBOL_REF_FLAGS (ADDR) |= SYMBOL_FLAG_FUNCTION; \
  779. if (0) goto DONE; \
  780. } \
  781. + if (TARGET_FDPIC \
  782. + && ((ENCODING) & 0xf0) == (DW_EH_PE_indirect | DW_EH_PE_datarel)) \
  783. + { \
  784. + fputs ("\t.ualong ", FILE); \
  785. + output_addr_const (FILE, ADDR); \
  786. + if (GET_CODE (ADDR) == SYMBOL_REF && SYMBOL_REF_FUNCTION_P (ADDR)) \
  787. + fputs ("@GOTFUNCDESC", FILE); \
  788. + else \
  789. + fputs ("@GOT", FILE); \
  790. + goto DONE; \
  791. + } \
  792. } while (0)
  793. #if (defined CRT_BEGIN || defined CRT_END) && ! __SHMEDIA__
  794. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/sh.md gcc-5.2.0/gcc/config/sh/sh.md
  795. --- ../baseline/gcc-5.2.0/gcc/config/sh/sh.md 2015-09-04 20:23:46.704785579 +0000
  796. +++ gcc-5.2.0/gcc/config/sh/sh.md 2015-09-21 07:54:18.237105881 +0000
  797. @@ -100,6 +100,7 @@
  798. (R8_REG 8)
  799. (R9_REG 9)
  800. (R10_REG 10)
  801. + (R12_REG 12)
  802. (R20_REG 20)
  803. (R21_REG 21)
  804. (R22_REG 22)
  805. @@ -170,6 +171,9 @@
  806. UNSPEC_SYMOFF
  807. ;; (unspec [OFFSET ANCHOR] UNSPEC_PCREL_SYMOFF) == OFFSET - (ANCHOR - .).
  808. UNSPEC_PCREL_SYMOFF
  809. + ;; For FDPIC
  810. + UNSPEC_GOTFUNCDESC
  811. + UNSPEC_GOTOFFFUNCDESC
  812. ;; Misc builtins
  813. UNSPEC_BUILTIN_STRLEN
  814. ])
  815. @@ -2495,15 +2499,18 @@
  816. ;; This reload would clobber the value in r0 we are trying to store.
  817. ;; If we let reload allocate r0, then this problem can never happen.
  818. (define_insn "udivsi3_i1"
  819. - [(set (match_operand:SI 0 "register_operand" "=z")
  820. + [(set (match_operand:SI 0 "register_operand" "=z,z")
  821. (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
  822. (clobber (reg:SI T_REG))
  823. (clobber (reg:SI PR_REG))
  824. (clobber (reg:SI R1_REG))
  825. (clobber (reg:SI R4_REG))
  826. - (use (match_operand:SI 1 "arith_reg_operand" "r"))]
  827. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  828. + (use (match_operand 2 "" "Z,Ccl"))]
  829. "TARGET_SH1 && TARGET_DIVIDE_CALL_DIV1"
  830. - "jsr @%1%#"
  831. + "@
  832. + jsr @%1%#
  833. + bsrf %1\\n%O2:%#"
  834. [(set_attr "type" "sfunc")
  835. (set_attr "needs_delay_slot" "yes")])
  836. @@ -2552,7 +2559,7 @@
  837. })
  838. (define_insn "udivsi3_i4"
  839. - [(set (match_operand:SI 0 "register_operand" "=y")
  840. + [(set (match_operand:SI 0 "register_operand" "=y,y")
  841. (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
  842. (clobber (reg:SI T_REG))
  843. (clobber (reg:SI PR_REG))
  844. @@ -2564,16 +2571,19 @@
  845. (clobber (reg:SI R4_REG))
  846. (clobber (reg:SI R5_REG))
  847. (clobber (reg:SI FPSCR_STAT_REG))
  848. - (use (match_operand:SI 1 "arith_reg_operand" "r"))
  849. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  850. + (use (match_operand 2 "" "Z,Ccl"))
  851. (use (reg:SI FPSCR_MODES_REG))]
  852. "TARGET_FPU_DOUBLE && ! TARGET_FPU_SINGLE"
  853. - "jsr @%1%#"
  854. + "@
  855. + jsr @%1%#
  856. + bsrf %1\\n%O2:%#"
  857. [(set_attr "type" "sfunc")
  858. (set_attr "fp_mode" "double")
  859. (set_attr "needs_delay_slot" "yes")])
  860. (define_insn "udivsi3_i4_single"
  861. - [(set (match_operand:SI 0 "register_operand" "=y")
  862. + [(set (match_operand:SI 0 "register_operand" "=y,y")
  863. (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
  864. (clobber (reg:SI T_REG))
  865. (clobber (reg:SI PR_REG))
  866. @@ -2584,10 +2594,13 @@
  867. (clobber (reg:SI R1_REG))
  868. (clobber (reg:SI R4_REG))
  869. (clobber (reg:SI R5_REG))
  870. - (use (match_operand:SI 1 "arith_reg_operand" "r"))]
  871. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  872. + (use (match_operand 2 "" "Z,Ccl"))]
  873. "(TARGET_FPU_SINGLE_ONLY || TARGET_FPU_DOUBLE || TARGET_SHCOMPACT)
  874. && TARGET_FPU_SINGLE"
  875. - "jsr @%1%#"
  876. + "@
  877. + jsr @%1%#
  878. + bsrf %1\\n%O2:%#"
  879. [(set_attr "type" "sfunc")
  880. (set_attr "needs_delay_slot" "yes")])
  881. @@ -2641,16 +2654,17 @@
  882. emit_move_insn (operands[0], operands[2]);
  883. DONE;
  884. }
  885. - function_symbol (operands[3], "__udivsi3_i4i", SFUNC_GOT);
  886. + function_symbol (operands[3], "__udivsi3_i4i", SFUNC_GOT, NULL);
  887. last = gen_udivsi3_i4_int (operands[0], operands[3]);
  888. }
  889. else if (TARGET_DIVIDE_CALL_FP)
  890. {
  891. - function_symbol (operands[3], "__udivsi3_i4", SFUNC_STATIC);
  892. + rtx lab;
  893. + function_symbol (operands[3], "__udivsi3_i4", SFUNC_STATIC, &lab);
  894. if (TARGET_FPU_SINGLE)
  895. - last = gen_udivsi3_i4_single (operands[0], operands[3]);
  896. + last = gen_udivsi3_i4_single (operands[0], operands[3], lab);
  897. else
  898. - last = gen_udivsi3_i4 (operands[0], operands[3]);
  899. + last = gen_udivsi3_i4 (operands[0], operands[3], lab);
  900. }
  901. else if (TARGET_SHMEDIA_FPU)
  902. {
  903. @@ -2670,19 +2684,20 @@
  904. {
  905. function_symbol (operands[3],
  906. TARGET_FPU_ANY ? "__udivsi3_i4" : "__udivsi3",
  907. - SFUNC_STATIC);
  908. + SFUNC_STATIC, NULL);
  909. if (TARGET_SHMEDIA)
  910. last = gen_udivsi3_i1_media (operands[0], operands[3]);
  911. else if (TARGET_FPU_ANY)
  912. - last = gen_udivsi3_i4_single (operands[0], operands[3]);
  913. + last = gen_udivsi3_i4_single (operands[0], operands[3], const0_rtx);
  914. else
  915. - last = gen_udivsi3_i1 (operands[0], operands[3]);
  916. + last = gen_udivsi3_i1 (operands[0], operands[3], const0_rtx);
  917. }
  918. else
  919. {
  920. - function_symbol (operands[3], "__udivsi3", SFUNC_STATIC);
  921. - last = gen_udivsi3_i1 (operands[0], operands[3]);
  922. + rtx lab;
  923. + function_symbol (operands[3], \"__udivsi3\", SFUNC_STATIC, &lab);
  924. + last = gen_udivsi3_i1 (operands[0], operands[3], lab);
  925. }
  926. emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
  927. emit_move_insn (gen_rtx_REG (SImode, 5), operands[2]);
  928. @@ -2810,7 +2825,7 @@
  929. emit_move_insn (gen_rtx_REG (DImode, R20_REG), x);
  930. break;
  931. }
  932. - sym = function_symbol (NULL, name, kind);
  933. + sym = function_symbol (NULL, name, kind, NULL);
  934. emit_insn (gen_divsi3_media_2 (operands[0], sym));
  935. DONE;
  936. }
  937. @@ -2830,31 +2845,37 @@
  938. })
  939. (define_insn "divsi3_i4"
  940. - [(set (match_operand:SI 0 "register_operand" "=y")
  941. + [(set (match_operand:SI 0 "register_operand" "=y,y")
  942. (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
  943. (clobber (reg:SI PR_REG))
  944. (clobber (reg:DF DR0_REG))
  945. (clobber (reg:DF DR2_REG))
  946. (clobber (reg:SI FPSCR_STAT_REG))
  947. - (use (match_operand:SI 1 "arith_reg_operand" "r"))
  948. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  949. + (use (match_operand 2 "" "Z,Ccl"))
  950. (use (reg:SI FPSCR_MODES_REG))]
  951. "TARGET_FPU_DOUBLE && ! TARGET_FPU_SINGLE"
  952. - "jsr @%1%#"
  953. + "@
  954. + jsr @%1%#
  955. + bsrf %1\\n%O2:%#"
  956. [(set_attr "type" "sfunc")
  957. (set_attr "fp_mode" "double")
  958. (set_attr "needs_delay_slot" "yes")])
  959. (define_insn "divsi3_i4_single"
  960. - [(set (match_operand:SI 0 "register_operand" "=y")
  961. + [(set (match_operand:SI 0 "register_operand" "=y,y")
  962. (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
  963. (clobber (reg:SI PR_REG))
  964. (clobber (reg:DF DR0_REG))
  965. (clobber (reg:DF DR2_REG))
  966. (clobber (reg:SI R2_REG))
  967. - (use (match_operand:SI 1 "arith_reg_operand" "r"))]
  968. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  969. + (use (match_operand 2 "" "Z,Ccl"))]
  970. "(TARGET_FPU_SINGLE_ONLY || TARGET_FPU_DOUBLE || TARGET_SHCOMPACT)
  971. && TARGET_FPU_SINGLE"
  972. - "jsr @%1%#"
  973. + "@
  974. + jsr @%1%#
  975. + bsrf %1\\n%O2:%#"
  976. [(set_attr "type" "sfunc")
  977. (set_attr "needs_delay_slot" "yes")])
  978. @@ -2893,16 +2914,17 @@
  979. /* Emit the move of the address to a pseudo outside of the libcall. */
  980. if (TARGET_DIVIDE_CALL_TABLE)
  981. {
  982. - function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT);
  983. + function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT, NULL);
  984. last = gen_divsi3_i4_int (operands[0], operands[3]);
  985. }
  986. else if (TARGET_DIVIDE_CALL_FP)
  987. {
  988. - function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_STATIC);
  989. + rtx lab;
  990. + function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_STATIC, &lab);
  991. if (TARGET_FPU_SINGLE)
  992. - last = gen_divsi3_i4_single (operands[0], operands[3]);
  993. + last = gen_divsi3_i4_single (operands[0], operands[3], lab);
  994. else
  995. - last = gen_divsi3_i4 (operands[0], operands[3]);
  996. + last = gen_divsi3_i4 (operands[0], operands[3], lab);
  997. }
  998. else if (TARGET_SH2A)
  999. {
  1000. @@ -3007,23 +3029,23 @@
  1001. emit_move_insn (gen_rtx_REG (Pmode, R20_REG), tab_base);
  1002. }
  1003. if (TARGET_FPU_ANY && TARGET_SH1)
  1004. - function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_STATIC);
  1005. + function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_STATIC, NULL);
  1006. else if (TARGET_DIVIDE_CALL2)
  1007. - function_symbol (operands[3], "__sdivsi3_2", SFUNC_STATIC);
  1008. + function_symbol (operands[3], "__sdivsi3_2", SFUNC_STATIC, NULL);
  1009. else
  1010. - function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT);
  1011. + function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT, NULL);
  1012. if (TARGET_SHMEDIA)
  1013. last = ((TARGET_DIVIDE_CALL2 ? gen_divsi3_media_2 : gen_divsi3_i1_media)
  1014. (operands[0], operands[3]));
  1015. else if (TARGET_FPU_ANY)
  1016. - last = gen_divsi3_i4_single (operands[0], operands[3]);
  1017. + last = gen_divsi3_i4_single (operands[0], operands[3], const0_rtx);
  1018. else
  1019. last = gen_divsi3_i1 (operands[0], operands[3]);
  1020. }
  1021. else
  1022. {
  1023. - function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT);
  1024. + function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT, NULL);
  1025. last = gen_divsi3_i1 (operands[0], operands[3]);
  1026. }
  1027. emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
  1028. @@ -3617,7 +3639,7 @@ label:
  1029. {
  1030. /* The address must be set outside the libcall,
  1031. since it goes into a pseudo. */
  1032. - rtx sym = function_symbol (NULL, "__mulsi3", SFUNC_STATIC);
  1033. + rtx sym = function_symbol (NULL, "__mulsi3", SFUNC_STATIC, NULL);
  1034. rtx addr = force_reg (SImode, sym);
  1035. rtx insns = gen_mulsi3_call (operands[0], operands[1],
  1036. operands[2], addr);
  1037. @@ -4873,7 +4895,7 @@ label:
  1038. {
  1039. emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
  1040. rtx funcaddr = gen_reg_rtx (Pmode);
  1041. - function_symbol (funcaddr, "__ashlsi3_r0", SFUNC_STATIC);
  1042. + function_symbol (funcaddr, "__ashlsi3_r0", SFUNC_STATIC, NULL);
  1043. emit_insn (gen_ashlsi3_d_call (operands[0], operands[2], funcaddr));
  1044. DONE;
  1045. @@ -5277,12 +5299,15 @@ label:
  1046. (define_insn "ashrsi3_n"
  1047. [(set (reg:SI R4_REG)
  1048. (ashiftrt:SI (reg:SI R4_REG)
  1049. - (match_operand:SI 0 "const_int_operand" "i")))
  1050. + (match_operand:SI 0 "const_int_operand" "i,i")))
  1051. (clobber (reg:SI T_REG))
  1052. (clobber (reg:SI PR_REG))
  1053. - (use (match_operand:SI 1 "arith_reg_operand" "r"))]
  1054. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  1055. + (use (match_operand 2 "" "Z,Ccl"))]
  1056. "TARGET_SH1"
  1057. - "jsr @%1%#"
  1058. + "@
  1059. + jsr @%1%#
  1060. + bsrf %1\\n%O2:%#"
  1061. [(set_attr "type" "sfunc")
  1062. (set_attr "needs_delay_slot" "yes")])
  1063. @@ -5435,7 +5460,7 @@ label:
  1064. {
  1065. emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
  1066. rtx funcaddr = gen_reg_rtx (Pmode);
  1067. - function_symbol (funcaddr, "__lshrsi3_r0", SFUNC_STATIC);
  1068. + function_symbol (funcaddr, "__lshrsi3_r0", SFUNC_STATIC, NULL);
  1069. emit_insn (gen_lshrsi3_d_call (operands[0], operands[2], funcaddr));
  1070. DONE;
  1071. }
  1072. @@ -7218,7 +7243,8 @@ label:
  1073. }
  1074. else if (TARGET_SHCOMPACT)
  1075. {
  1076. - operands[1] = function_symbol (NULL, "__ic_invalidate", SFUNC_STATIC);
  1077. + operands[1] = function_symbol (NULL, "__ic_invalidate", SFUNC_STATIC,
  1078. + NULL);
  1079. operands[1] = force_reg (Pmode, operands[1]);
  1080. emit_insn (gen_ic_invalidate_line_compact (operands[0], operands[1]));
  1081. DONE;
  1082. @@ -7300,7 +7326,7 @@ label:
  1083. tramp = force_reg (Pmode, operands[0]);
  1084. sfun = force_reg (Pmode, function_symbol (NULL, "__init_trampoline",
  1085. - SFUNC_STATIC));
  1086. + SFUNC_STATIC, NULL));
  1087. emit_move_insn (gen_rtx_REG (SImode, R2_REG), operands[1]);
  1088. emit_move_insn (gen_rtx_REG (SImode, R3_REG), operands[2]);
  1089. @@ -9342,7 +9368,27 @@ label:
  1090. (match_operand 1 "" ""))
  1091. (use (reg:SI FPSCR_MODES_REG))
  1092. (clobber (reg:SI PR_REG))]
  1093. - "TARGET_SH1"
  1094. + "TARGET_SH1 && !TARGET_FDPIC"
  1095. +{
  1096. + if (TARGET_SH2A && (dbr_sequence_length () == 0))
  1097. + return "jsr/n @%0";
  1098. + else
  1099. + return "jsr @%0%#";
  1100. +}
  1101. + [(set_attr "type" "call")
  1102. + (set (attr "fp_mode")
  1103. + (if_then_else (eq_attr "fpu_single" "yes")
  1104. + (const_string "single") (const_string "double")))
  1105. + (set_attr "needs_delay_slot" "yes")
  1106. + (set_attr "fp_set" "unknown")])
  1107. +
  1108. +(define_insn "calli_fdpic"
  1109. + [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
  1110. + (match_operand 1 "" ""))
  1111. + (use (reg:SI FPSCR_MODES_REG))
  1112. + (use (reg:SI PIC_REG))
  1113. + (clobber (reg:SI PR_REG))]
  1114. + "TARGET_SH1 && TARGET_FDPIC"
  1115. {
  1116. if (TARGET_SH2A && (dbr_sequence_length () == 0))
  1117. return "jsr/n @%0";
  1118. @@ -9471,7 +9517,28 @@ label:
  1119. (match_operand 2 "" "")))
  1120. (use (reg:SI FPSCR_MODES_REG))
  1121. (clobber (reg:SI PR_REG))]
  1122. - "TARGET_SH1"
  1123. + "TARGET_SH1 && !TARGET_FDPIC"
  1124. +{
  1125. + if (TARGET_SH2A && (dbr_sequence_length () == 0))
  1126. + return "jsr/n @%1";
  1127. + else
  1128. + return "jsr @%1%#";
  1129. +}
  1130. + [(set_attr "type" "call")
  1131. + (set (attr "fp_mode")
  1132. + (if_then_else (eq_attr "fpu_single" "yes")
  1133. + (const_string "single") (const_string "double")))
  1134. + (set_attr "needs_delay_slot" "yes")
  1135. + (set_attr "fp_set" "unknown")])
  1136. +
  1137. +(define_insn "call_valuei_fdpic"
  1138. + [(set (match_operand 0 "" "=rf")
  1139. + (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
  1140. + (match_operand 2 "" "")))
  1141. + (use (reg:SI FPSCR_REG))
  1142. + (use (reg:SI PIC_REG))
  1143. + (clobber (reg:SI PR_REG))]
  1144. + "TARGET_SH1 && TARGET_FDPIC"
  1145. {
  1146. if (TARGET_SH2A && (dbr_sequence_length () == 0))
  1147. return "jsr/n @%1";
  1148. @@ -9608,6 +9675,12 @@ label:
  1149. (clobber (reg:SI PR_REG))])]
  1150. ""
  1151. {
  1152. + if (TARGET_FDPIC)
  1153. + {
  1154. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  1155. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  1156. + }
  1157. +
  1158. if (TARGET_SHMEDIA)
  1159. {
  1160. operands[0] = shmedia_prepare_call_address (operands[0], 0);
  1161. @@ -9643,7 +9716,8 @@ label:
  1162. emit_insn (gen_force_mode_for_call ());
  1163. operands[0]
  1164. - = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
  1165. + = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1166. + SFUNC_GOT, NULL);
  1167. operands[0] = force_reg (SImode, operands[0]);
  1168. emit_move_insn (r0, func);
  1169. @@ -9667,7 +9741,7 @@ label:
  1170. emit_insn (gen_symGOTPLT2reg (reg, XEXP (operands[0], 0)));
  1171. XEXP (operands[0], 0) = reg;
  1172. }
  1173. - if (!flag_pic && TARGET_SH2A
  1174. + if (!flag_pic && !TARGET_FDPIC && TARGET_SH2A
  1175. && MEM_P (operands[0])
  1176. && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
  1177. {
  1178. @@ -9678,7 +9752,7 @@ label:
  1179. DONE;
  1180. }
  1181. }
  1182. - if (flag_pic && TARGET_SH2
  1183. + if ((flag_pic || TARGET_FDPIC) && TARGET_SH2
  1184. && MEM_P (operands[0])
  1185. && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
  1186. {
  1187. @@ -9691,7 +9765,13 @@ label:
  1188. operands[1] = operands[2];
  1189. }
  1190. - emit_call_insn (gen_calli (operands[0], operands[1]));
  1191. + if (TARGET_FDPIC)
  1192. + {
  1193. + operands[0] = sh_load_function_descriptor (operands[0]);
  1194. + emit_call_insn (gen_calli_fdpic (operands[0], operands[1]));
  1195. + }
  1196. + else
  1197. + emit_call_insn (gen_calli (operands[0], operands[1]));
  1198. DONE;
  1199. })
  1200. @@ -9771,7 +9851,7 @@ label:
  1201. emit_insn (gen_force_mode_for_call ());
  1202. operands[0] = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1203. - SFUNC_GOT);
  1204. + SFUNC_GOT, NULL);
  1205. operands[0] = force_reg (SImode, operands[0]);
  1206. emit_move_insn (r0, func);
  1207. @@ -9796,6 +9876,12 @@ label:
  1208. (clobber (reg:SI PR_REG))])]
  1209. ""
  1210. {
  1211. + if (TARGET_FDPIC)
  1212. + {
  1213. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  1214. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  1215. + }
  1216. +
  1217. if (TARGET_SHMEDIA)
  1218. {
  1219. operands[1] = shmedia_prepare_call_address (operands[1], 0);
  1220. @@ -9832,7 +9918,8 @@ label:
  1221. emit_insn (gen_force_mode_for_call ());
  1222. operands[1]
  1223. - = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
  1224. + = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1225. + SFUNC_GOT, NULL);
  1226. operands[1] = force_reg (SImode, operands[1]);
  1227. emit_move_insn (r0, func);
  1228. @@ -9858,7 +9945,7 @@ label:
  1229. emit_insn (gen_symGOTPLT2reg (reg, XEXP (operands[1], 0)));
  1230. XEXP (operands[1], 0) = reg;
  1231. }
  1232. - if (!flag_pic && TARGET_SH2A
  1233. + if (!flag_pic && !TARGET_FDPIC && TARGET_SH2A
  1234. && MEM_P (operands[1])
  1235. && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
  1236. {
  1237. @@ -9869,7 +9956,7 @@ label:
  1238. DONE;
  1239. }
  1240. }
  1241. - if (flag_pic && TARGET_SH2
  1242. + if ((flag_pic || TARGET_FDPIC) && TARGET_SH2
  1243. && MEM_P (operands[1])
  1244. && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
  1245. {
  1246. @@ -9880,7 +9967,14 @@ label:
  1247. else
  1248. operands[1] = force_reg (SImode, XEXP (operands[1], 0));
  1249. - emit_call_insn (gen_call_valuei (operands[0], operands[1], operands[2]));
  1250. + if (TARGET_FDPIC)
  1251. + {
  1252. + operands[1] = sh_load_function_descriptor (operands[1]);
  1253. + emit_call_insn (gen_call_valuei_fdpic (operands[0], operands[1],
  1254. + operands[2]));
  1255. + }
  1256. + else
  1257. + emit_call_insn (gen_call_valuei (operands[0], operands[1], operands[2]));
  1258. DONE;
  1259. })
  1260. @@ -9889,7 +9983,21 @@ label:
  1261. (match_operand 1 "" ""))
  1262. (use (reg:SI FPSCR_MODES_REG))
  1263. (return)]
  1264. - "TARGET_SH1"
  1265. + "TARGET_SH1 && !TARGET_FDPIC"
  1266. + "jmp @%0%#"
  1267. + [(set_attr "needs_delay_slot" "yes")
  1268. + (set (attr "fp_mode")
  1269. + (if_then_else (eq_attr "fpu_single" "yes")
  1270. + (const_string "single") (const_string "double")))
  1271. + (set_attr "type" "jump_ind")])
  1272. +
  1273. +(define_insn "sibcalli_fdpic"
  1274. + [(call (mem:SI (match_operand:SI 0 "register_operand" "k"))
  1275. + (match_operand 1 "" ""))
  1276. + (use (reg:SI FPSCR_MODES_REG))
  1277. + (use (reg:SI PIC_REG))
  1278. + (return)]
  1279. + "TARGET_SH1 && TARGET_FDPIC"
  1280. "jmp @%0%#"
  1281. [(set_attr "needs_delay_slot" "yes")
  1282. (set (attr "fp_mode")
  1283. @@ -9903,7 +10011,25 @@ label:
  1284. (use (match_operand 2 "" ""))
  1285. (use (reg:SI FPSCR_MODES_REG))
  1286. (return)]
  1287. - "TARGET_SH2"
  1288. + "TARGET_SH2 && !TARGET_FDPIC"
  1289. +{
  1290. + return "braf %0" "\n"
  1291. + "%O2:%#";
  1292. +}
  1293. + [(set_attr "needs_delay_slot" "yes")
  1294. + (set (attr "fp_mode")
  1295. + (if_then_else (eq_attr "fpu_single" "yes")
  1296. + (const_string "single") (const_string "double")))
  1297. + (set_attr "type" "jump_ind")])
  1298. +
  1299. +(define_insn "sibcalli_pcrel_fdpic"
  1300. + [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "k"))
  1301. + (match_operand 1 "" ""))
  1302. + (use (match_operand 2 "" ""))
  1303. + (use (reg:SI FPSCR_MODES_REG))
  1304. + (use (reg:SI PIC_REG))
  1305. + (return)]
  1306. + "TARGET_SH2 && TARGET_FDPIC"
  1307. {
  1308. return "braf %0" "\n"
  1309. "%O2:%#";
  1310. @@ -9936,7 +10062,7 @@ label:
  1311. (use (reg:SI FPSCR_MODES_REG))
  1312. (clobber (match_scratch:SI 2 "=k"))
  1313. (return)]
  1314. - "TARGET_SH2"
  1315. + "TARGET_SH2 && !TARGET_FDPIC"
  1316. "#"
  1317. "reload_completed"
  1318. [(const_int 0)]
  1319. @@ -9956,6 +10082,33 @@ label:
  1320. (const_string "single") (const_string "double")))
  1321. (set_attr "type" "jump_ind")])
  1322. +(define_insn_and_split "sibcall_pcrel_fdpic"
  1323. + [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" ""))
  1324. + (match_operand 1 "" ""))
  1325. + (use (reg:SI FPSCR_MODES_REG))
  1326. + (use (reg:SI PIC_REG))
  1327. + (clobber (match_scratch:SI 2 "=k"))
  1328. + (return)]
  1329. + "TARGET_SH2 && TARGET_FDPIC"
  1330. + "#"
  1331. + "reload_completed"
  1332. + [(const_int 0)]
  1333. +{
  1334. + rtx lab = PATTERN (gen_call_site ());
  1335. + rtx call_insn;
  1336. +
  1337. + sh_expand_sym_label2reg (operands[2], operands[0], lab, true);
  1338. + call_insn = emit_call_insn (gen_sibcalli_pcrel_fdpic (operands[2], operands[1],
  1339. + copy_rtx (lab)));
  1340. + SIBLING_CALL_P (call_insn) = 1;
  1341. + DONE;
  1342. +}
  1343. + [(set_attr "needs_delay_slot" "yes")
  1344. + (set (attr "fp_mode")
  1345. + (if_then_else (eq_attr "fpu_single" "yes")
  1346. + (const_string "single") (const_string "double")))
  1347. + (set_attr "type" "jump_ind")])
  1348. +
  1349. (define_insn "sibcall_compact"
  1350. [(call (mem:SI (match_operand:SI 0 "register_operand" "k,k"))
  1351. (match_operand 1 "" ""))
  1352. @@ -10000,6 +10153,12 @@ label:
  1353. (return)])]
  1354. ""
  1355. {
  1356. + if (TARGET_FDPIC)
  1357. + {
  1358. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  1359. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  1360. + }
  1361. +
  1362. if (TARGET_SHMEDIA)
  1363. {
  1364. operands[0] = shmedia_prepare_call_address (operands[0], 1);
  1365. @@ -10045,7 +10204,8 @@ label:
  1366. emit_insn (gen_force_mode_for_call ());
  1367. operands[0]
  1368. - = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
  1369. + = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1370. + SFUNC_GOT, NULL);
  1371. operands[0] = force_reg (SImode, operands[0]);
  1372. /* We don't need a return trampoline, since the callee will
  1373. @@ -10071,7 +10231,7 @@ label:
  1374. emit_insn (gen_symGOT2reg (reg, XEXP (operands[0], 0)));
  1375. XEXP (operands[0], 0) = reg;
  1376. }
  1377. - if (flag_pic && TARGET_SH2
  1378. + if ((flag_pic || TARGET_FDPIC) && TARGET_SH2
  1379. && MEM_P (operands[0])
  1380. && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
  1381. /* The PLT needs the PIC register, but the epilogue would have
  1382. @@ -10079,13 +10239,24 @@ label:
  1383. static functions. */
  1384. && SYMBOL_REF_LOCAL_P (XEXP (operands[0], 0)))
  1385. {
  1386. - emit_call_insn (gen_sibcall_pcrel (XEXP (operands[0], 0), operands[1]));
  1387. + if (TARGET_FDPIC)
  1388. + emit_call_insn (gen_sibcall_pcrel_fdpic (XEXP (operands[0], 0),
  1389. + operands[1]));
  1390. + else
  1391. + emit_call_insn (gen_sibcall_pcrel (XEXP (operands[0], 0),
  1392. + operands[1]));
  1393. DONE;
  1394. }
  1395. else
  1396. operands[0] = force_reg (SImode, XEXP (operands[0], 0));
  1397. - emit_call_insn (gen_sibcalli (operands[0], operands[1]));
  1398. + if (TARGET_FDPIC)
  1399. + {
  1400. + operands[0] = sh_load_function_descriptor (operands[0]);
  1401. + emit_call_insn (gen_sibcalli_fdpic (operands[0], operands[1]));
  1402. + }
  1403. + else
  1404. + emit_call_insn (gen_sibcalli (operands[0], operands[1]));
  1405. DONE;
  1406. })
  1407. @@ -10095,7 +10266,22 @@ label:
  1408. (match_operand 2 "" "")))
  1409. (use (reg:SI FPSCR_MODES_REG))
  1410. (return)]
  1411. - "TARGET_SH1"
  1412. + "TARGET_SH1 && !TARGET_FDPIC"
  1413. + "jmp @%1%#"
  1414. + [(set_attr "needs_delay_slot" "yes")
  1415. + (set (attr "fp_mode")
  1416. + (if_then_else (eq_attr "fpu_single" "yes")
  1417. + (const_string "single") (const_string "double")))
  1418. + (set_attr "type" "jump_ind")])
  1419. +
  1420. +(define_insn "sibcall_valuei_fdpic"
  1421. + [(set (match_operand 0 "" "=rf")
  1422. + (call (mem:SI (match_operand:SI 1 "register_operand" "k"))
  1423. + (match_operand 2 "" "")))
  1424. + (use (reg:SI FPSCR_MODES_REG))
  1425. + (use (reg:SI PIC_REG))
  1426. + (return)]
  1427. + "TARGET_SH1 && TARGET_FDPIC"
  1428. "jmp @%1%#"
  1429. [(set_attr "needs_delay_slot" "yes")
  1430. (set (attr "fp_mode")
  1431. @@ -10110,7 +10296,26 @@ label:
  1432. (use (match_operand 3 "" ""))
  1433. (use (reg:SI FPSCR_MODES_REG))
  1434. (return)]
  1435. - "TARGET_SH2"
  1436. + "TARGET_SH2 && !TARGET_FDPIC"
  1437. +{
  1438. + return "braf %1" "\n"
  1439. + "%O3:%#";
  1440. +}
  1441. + [(set_attr "needs_delay_slot" "yes")
  1442. + (set (attr "fp_mode")
  1443. + (if_then_else (eq_attr "fpu_single" "yes")
  1444. + (const_string "single") (const_string "double")))
  1445. + (set_attr "type" "jump_ind")])
  1446. +
  1447. +(define_insn "sibcall_valuei_pcrel_fdpic"
  1448. + [(set (match_operand 0 "" "=rf")
  1449. + (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "k"))
  1450. + (match_operand 2 "" "")))
  1451. + (use (match_operand 3 "" ""))
  1452. + (use (reg:SI FPSCR_MODES_REG))
  1453. + (use (reg:SI PIC_REG))
  1454. + (return)]
  1455. + "TARGET_SH2 && TARGET_FDPIC"
  1456. {
  1457. return "braf %1" "\n"
  1458. "%O3:%#";
  1459. @@ -10128,7 +10333,7 @@ label:
  1460. (use (reg:SI FPSCR_MODES_REG))
  1461. (clobber (match_scratch:SI 3 "=k"))
  1462. (return)]
  1463. - "TARGET_SH2"
  1464. + "TARGET_SH2 && !TARGET_FDPIC"
  1465. "#"
  1466. "reload_completed"
  1467. [(const_int 0)]
  1468. @@ -10141,6 +10346,38 @@ label:
  1469. operands[3],
  1470. operands[2],
  1471. copy_rtx (lab)));
  1472. +
  1473. + SIBLING_CALL_P (call_insn) = 1;
  1474. + DONE;
  1475. +}
  1476. + [(set_attr "needs_delay_slot" "yes")
  1477. + (set (attr "fp_mode")
  1478. + (if_then_else (eq_attr "fpu_single" "yes")
  1479. + (const_string "single") (const_string "double")))
  1480. + (set_attr "type" "jump_ind")])
  1481. +
  1482. +(define_insn_and_split "sibcall_value_pcrel_fdpic"
  1483. + [(set (match_operand 0 "" "=rf")
  1484. + (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" ""))
  1485. + (match_operand 2 "" "")))
  1486. + (use (reg:SI FPSCR_MODES_REG))
  1487. + (use (reg:SI PIC_REG))
  1488. + (clobber (match_scratch:SI 3 "=k"))
  1489. + (return)]
  1490. + "TARGET_SH2 && TARGET_FDPIC"
  1491. + "#"
  1492. + "reload_completed"
  1493. + [(const_int 0)]
  1494. +{
  1495. + rtx lab = PATTERN (gen_call_site ());
  1496. + rtx call_insn;
  1497. +
  1498. + sh_expand_sym_label2reg (operands[3], operands[1], lab, true);
  1499. + call_insn = emit_call_insn (gen_sibcall_valuei_pcrel_fdpic (operands[0],
  1500. + operands[3],
  1501. + operands[2],
  1502. + copy_rtx (lab)));
  1503. +
  1504. SIBLING_CALL_P (call_insn) = 1;
  1505. DONE;
  1506. }
  1507. @@ -10197,6 +10434,12 @@ label:
  1508. (return)])]
  1509. ""
  1510. {
  1511. + if (TARGET_FDPIC)
  1512. + {
  1513. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  1514. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  1515. + }
  1516. +
  1517. if (TARGET_SHMEDIA)
  1518. {
  1519. operands[1] = shmedia_prepare_call_address (operands[1], 1);
  1520. @@ -10243,7 +10486,8 @@ label:
  1521. emit_insn (gen_force_mode_for_call ());
  1522. operands[1]
  1523. - = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
  1524. + = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1525. + SFUNC_GOT, NULL);
  1526. operands[1] = force_reg (SImode, operands[1]);
  1527. /* We don't need a return trampoline, since the callee will
  1528. @@ -10270,7 +10514,7 @@ label:
  1529. emit_insn (gen_symGOT2reg (reg, XEXP (operands[1], 0)));
  1530. XEXP (operands[1], 0) = reg;
  1531. }
  1532. - if (flag_pic && TARGET_SH2
  1533. + if ((flag_pic || TARGET_FDPIC) && TARGET_SH2
  1534. && MEM_P (operands[1])
  1535. && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
  1536. /* The PLT needs the PIC register, but the epilogue would have
  1537. @@ -10278,15 +10522,28 @@ label:
  1538. static functions. */
  1539. && SYMBOL_REF_LOCAL_P (XEXP (operands[1], 0)))
  1540. {
  1541. - emit_call_insn (gen_sibcall_value_pcrel (operands[0],
  1542. - XEXP (operands[1], 0),
  1543. - operands[2]));
  1544. + if (TARGET_FDPIC)
  1545. + emit_call_insn (gen_sibcall_value_pcrel_fdpic (operands[0],
  1546. + XEXP (operands[1], 0),
  1547. + operands[2]));
  1548. + else
  1549. + emit_call_insn (gen_sibcall_value_pcrel (operands[0],
  1550. + XEXP (operands[1], 0),
  1551. + operands[2]));
  1552. DONE;
  1553. }
  1554. else
  1555. operands[1] = force_reg (SImode, XEXP (operands[1], 0));
  1556. - emit_call_insn (gen_sibcall_valuei (operands[0], operands[1], operands[2]));
  1557. + if (TARGET_FDPIC)
  1558. + {
  1559. + operands[1] = sh_load_function_descriptor (operands[1]);
  1560. + emit_call_insn (gen_sibcall_valuei_fdpic (operands[0], operands[1],
  1561. + operands[2]));
  1562. + }
  1563. + else
  1564. + emit_call_insn (gen_sibcall_valuei (operands[0], operands[1],
  1565. + operands[2]));
  1566. DONE;
  1567. })
  1568. @@ -10370,7 +10627,7 @@ label:
  1569. emit_insn (gen_force_mode_for_call ());
  1570. operands[1] = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1571. - SFUNC_GOT);
  1572. + SFUNC_GOT, NULL);
  1573. operands[1] = force_reg (SImode, operands[1]);
  1574. emit_move_insn (r0, func);
  1575. @@ -10568,6 +10825,13 @@ label:
  1576. DONE;
  1577. }
  1578. + if (TARGET_FDPIC)
  1579. + {
  1580. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  1581. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  1582. + DONE;
  1583. + }
  1584. +
  1585. operands[1] = gen_rtx_REG (Pmode, PIC_REG);
  1586. operands[2] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);
  1587. @@ -10700,9 +10964,15 @@ label:
  1588. (set (match_operand 0 "" "") (mem (match_dup 3)))]
  1589. ""
  1590. {
  1591. + rtx picreg;
  1592. rtx mem;
  1593. bool stack_chk_guard_p = false;
  1594. + if (TARGET_FDPIC)
  1595. + picreg = OUR_FDPIC_REG;
  1596. + else
  1597. + picreg = gen_rtx_REG (Pmode, PIC_REG);
  1598. +
  1599. operands[2] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
  1600. operands[3] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
  1601. @@ -10742,11 +11012,11 @@ label:
  1602. insn to avoid combining (set A (plus rX r12)) and (set op0 (mem A))
  1603. when rX is a GOT address for the guard symbol. Ugly but doesn't
  1604. matter because this is a rare situation. */
  1605. +// FIXME: original fdpic patch did not have ssp case here ??
  1606. if (stack_chk_guard_p)
  1607. emit_insn (gen_chk_guard_add (operands[3], operands[2]));
  1608. else
  1609. - emit_move_insn (operands[3], gen_rtx_PLUS (Pmode, operands[2],
  1610. - gen_rtx_REG (Pmode, PIC_REG)));
  1611. + emit_move_insn (operands[3], gen_rtx_PLUS (Pmode, operands[2], picreg));
  1612. /* N.B. This is not constant for a GOTPLT relocation. */
  1613. mem = gen_rtx_MEM (Pmode, operands[3]);
  1614. @@ -10777,6 +11047,26 @@ label:
  1615. DONE;
  1616. })
  1617. +(define_expand "sym2GOTFUNCDESC"
  1618. + [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOTFUNCDESC))]
  1619. + "TARGET_FDPIC"
  1620. + "")
  1621. +
  1622. +(define_expand "symGOTFUNCDESC2reg"
  1623. + [(match_operand 0 "" "") (match_operand 1 "" "")]
  1624. + "TARGET_FDPIC"
  1625. +{
  1626. + rtx gotsym, insn;
  1627. +
  1628. + gotsym = gen_sym2GOTFUNCDESC (operands[1]);
  1629. + PUT_MODE (gotsym, Pmode);
  1630. + insn = emit_insn (gen_symGOT_load (operands[0], gotsym));
  1631. +
  1632. + MEM_READONLY_P (SET_SRC (PATTERN (insn))) = 1;
  1633. +
  1634. + DONE;
  1635. +})
  1636. +
  1637. (define_expand "symGOTPLT2reg"
  1638. [(match_operand 0 "" "") (match_operand 1 "" "")]
  1639. ""
  1640. @@ -10798,23 +11088,49 @@ label:
  1641. [(match_operand 0 "" "") (match_operand 1 "" "")]
  1642. ""
  1643. {
  1644. + rtx picreg;
  1645. rtx gotoffsym, insn;
  1646. rtx t = (!can_create_pseudo_p ()
  1647. ? operands[0]
  1648. : gen_reg_rtx (GET_MODE (operands[0])));
  1649. + if (TARGET_FDPIC)
  1650. + picreg = OUR_FDPIC_REG;
  1651. + else
  1652. + picreg = gen_rtx_REG (Pmode, PIC_REG);
  1653. +
  1654. gotoffsym = gen_sym2GOTOFF (operands[1]);
  1655. PUT_MODE (gotoffsym, Pmode);
  1656. emit_move_insn (t, gotoffsym);
  1657. - insn = emit_move_insn (operands[0],
  1658. - gen_rtx_PLUS (Pmode, t,
  1659. - gen_rtx_REG (Pmode, PIC_REG)));
  1660. + insn = emit_move_insn (operands[0], gen_rtx_PLUS (Pmode, t, picreg));
  1661. set_unique_reg_note (insn, REG_EQUAL, operands[1]);
  1662. DONE;
  1663. })
  1664. +(define_expand "sym2GOTOFFFUNCDESC"
  1665. + [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOTOFFFUNCDESC))]
  1666. + "TARGET_FDPIC"
  1667. + "")
  1668. +
  1669. +(define_expand "symGOTOFFFUNCDESC2reg"
  1670. + [(match_operand 0 "" "") (match_operand 1 "" "")]
  1671. + "TARGET_FDPIC"
  1672. +{
  1673. + rtx picreg = OUR_FDPIC_REG;
  1674. + rtx gotoffsym;
  1675. + rtx t = (!can_create_pseudo_p ()
  1676. + ? operands[0]
  1677. + : gen_reg_rtx (GET_MODE (operands[0])));
  1678. +
  1679. + gotoffsym = gen_sym2GOTOFFFUNCDESC (operands[1]);
  1680. + PUT_MODE (gotoffsym, Pmode);
  1681. + emit_move_insn (t, gotoffsym);
  1682. + emit_move_insn (operands[0], gen_rtx_PLUS (Pmode, t, picreg));
  1683. + DONE;
  1684. +})
  1685. +
  1686. (define_expand "symPLT_label2reg"
  1687. [(set (match_operand:SI 0 "" "")
  1688. (const:SI
  1689. @@ -11491,7 +11807,8 @@ label:
  1690. {
  1691. rtx reg = gen_rtx_REG (Pmode, R0_REG);
  1692. - function_symbol (reg, "__GCC_shcompact_return_trampoline", SFUNC_STATIC);
  1693. + function_symbol (reg, "__GCC_shcompact_return_trampoline", SFUNC_STATIC,
  1694. + NULL);
  1695. emit_jump_insn (gen_shcompact_return_tramp_i ());
  1696. DONE;
  1697. })
  1698. @@ -12581,18 +12898,22 @@ label:
  1699. (define_insn "block_move_real"
  1700. [(parallel [(set (mem:BLK (reg:SI R4_REG))
  1701. (mem:BLK (reg:SI R5_REG)))
  1702. - (use (match_operand:SI 0 "arith_reg_operand" "r"))
  1703. + (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
  1704. + (use (match_operand 1 "" "Z,Ccl"))
  1705. (clobber (reg:SI PR_REG))
  1706. (clobber (reg:SI R0_REG))])]
  1707. "TARGET_SH1 && ! TARGET_HARD_SH4"
  1708. - "jsr @%0%#"
  1709. + "@
  1710. + jsr @%0%#
  1711. + bsrf %0\\n%O1:%#"
  1712. [(set_attr "type" "sfunc")
  1713. (set_attr "needs_delay_slot" "yes")])
  1714. (define_insn "block_lump_real"
  1715. [(parallel [(set (mem:BLK (reg:SI R4_REG))
  1716. (mem:BLK (reg:SI R5_REG)))
  1717. - (use (match_operand:SI 0 "arith_reg_operand" "r"))
  1718. + (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
  1719. + (use (match_operand 1 "" "Z,Ccl"))
  1720. (use (reg:SI R6_REG))
  1721. (clobber (reg:SI PR_REG))
  1722. (clobber (reg:SI T_REG))
  1723. @@ -12601,27 +12922,33 @@ label:
  1724. (clobber (reg:SI R6_REG))
  1725. (clobber (reg:SI R0_REG))])]
  1726. "TARGET_SH1 && ! TARGET_HARD_SH4"
  1727. - "jsr @%0%#"
  1728. + "@
  1729. + jsr @%0%#
  1730. + bsrf %0\\n%O1:%#"
  1731. [(set_attr "type" "sfunc")
  1732. (set_attr "needs_delay_slot" "yes")])
  1733. (define_insn "block_move_real_i4"
  1734. [(parallel [(set (mem:BLK (reg:SI R4_REG))
  1735. (mem:BLK (reg:SI R5_REG)))
  1736. - (use (match_operand:SI 0 "arith_reg_operand" "r"))
  1737. + (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
  1738. + (use (match_operand 1 "" "Z,Ccl"))
  1739. (clobber (reg:SI PR_REG))
  1740. (clobber (reg:SI R0_REG))
  1741. (clobber (reg:SI R1_REG))
  1742. (clobber (reg:SI R2_REG))])]
  1743. "TARGET_HARD_SH4"
  1744. - "jsr @%0%#"
  1745. + "@
  1746. + jsr @%0%#
  1747. + bsrf %0\\n%O1:%#"
  1748. [(set_attr "type" "sfunc")
  1749. (set_attr "needs_delay_slot" "yes")])
  1750. (define_insn "block_lump_real_i4"
  1751. [(parallel [(set (mem:BLK (reg:SI R4_REG))
  1752. (mem:BLK (reg:SI R5_REG)))
  1753. - (use (match_operand:SI 0 "arith_reg_operand" "r"))
  1754. + (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
  1755. + (use (match_operand 1 "" "Z,Ccl"))
  1756. (use (reg:SI R6_REG))
  1757. (clobber (reg:SI PR_REG))
  1758. (clobber (reg:SI T_REG))
  1759. @@ -12633,7 +12960,9 @@ label:
  1760. (clobber (reg:SI R2_REG))
  1761. (clobber (reg:SI R3_REG))])]
  1762. "TARGET_HARD_SH4"
  1763. - "jsr @%0%#"
  1764. + "@
  1765. + jsr @%0%#
  1766. + bsrf %0\\n%O1:%#"
  1767. [(set_attr "type" "sfunc")
  1768. (set_attr "needs_delay_slot" "yes")])
  1769. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/sh.opt gcc-5.2.0/gcc/config/sh/sh.opt
  1770. --- ../baseline/gcc-5.2.0/gcc/config/sh/sh.opt 2015-09-04 20:23:46.711452245 +0000
  1771. +++ gcc-5.2.0/gcc/config/sh/sh.opt 2015-09-03 21:20:40.109481724 +0000
  1772. @@ -264,6 +264,10 @@ mdivsi3_libfunc=
  1773. Target RejectNegative Joined Var(sh_divsi3_libfunc) Init("")
  1774. Specify name for 32 bit signed division function
  1775. +mfdpic
  1776. +Target Report Var(TARGET_FDPIC)
  1777. +Generate ELF FDPIC code
  1778. +
  1779. mfmovd
  1780. Target RejectNegative Mask(FMOVD)
  1781. Enable the use of 64-bit floating point registers in fmov instructions. See -mdalign if 64-bit alignment is required.
  1782. diff -urp ../baseline/gcc-5.2.0/gcc/config.gcc gcc-5.2.0/gcc/config.gcc
  1783. --- ../baseline/gcc-5.2.0/gcc/config.gcc 2015-09-04 20:23:46.711452245 +0000
  1784. +++ gcc-5.2.0/gcc/config.gcc 2015-09-04 21:38:42.364511457 +0000
  1785. @@ -2580,6 +2580,9 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
  1786. tm_file="${tm_file} dbxelf.h elfos.h sh/elf.h"
  1787. case ${target} in
  1788. sh*-*-linux*) tmake_file="${tmake_file} sh/t-linux"
  1789. + if test x$enable_fdpic = xyes; then
  1790. + tm_defines="$tm_defines FDPIC_DEFAULT=1"
  1791. + fi
  1792. tm_file="${tm_file} gnu-user.h linux.h glibc-stdint.h sh/linux.h" ;;
  1793. sh*-*-netbsd*)
  1794. tm_file="${tm_file} netbsd.h netbsd-elf.h sh/netbsd-elf.h"
  1795. diff -urp ../baseline/gcc-5.2.0/gcc/doc/install.texi gcc-5.2.0/gcc/doc/install.texi
  1796. --- ../baseline/gcc-5.2.0/gcc/doc/install.texi 2015-05-12 08:49:59.000000000 +0000
  1797. +++ gcc-5.2.0/gcc/doc/install.texi 2015-09-04 21:46:28.384483042 +0000
  1798. @@ -1791,6 +1791,9 @@ When neither of these configure options
  1799. 128-bit @code{long double} when built against GNU C Library 2.4 and later,
  1800. 64-bit @code{long double} otherwise.
  1801. +@item --enable-fdpic
  1802. +On SH Linux systems, generate ELF FDPIC code.
  1803. +
  1804. @item --with-gmp=@var{pathname}
  1805. @itemx --with-gmp-include=@var{pathname}
  1806. @itemx --with-gmp-lib=@var{pathname}
  1807. diff -urp ../baseline/gcc-5.2.0/gcc/doc/invoke.texi gcc-5.2.0/gcc/doc/invoke.texi
  1808. --- ../baseline/gcc-5.2.0/gcc/doc/invoke.texi 2015-09-04 20:23:46.568118921 +0000
  1809. +++ gcc-5.2.0/gcc/doc/invoke.texi 2015-09-04 21:44:08.541158234 +0000
  1810. @@ -20921,6 +20921,10 @@ in effect.
  1811. Prefer zero-displacement conditional branches for conditional move instruction
  1812. patterns. This can result in faster code on the SH4 processor.
  1813. +@item -mfdpic
  1814. +@opindex fdpic
  1815. +Generate code using the FDPIC ABI.
  1816. +
  1817. @end table
  1818. @node Solaris 2 Options
  1819. diff -urp ../baseline/gcc-5.2.0/libitm/config/sh/sjlj.S gcc-5.2.0/libitm/config/sh/sjlj.S
  1820. --- ../baseline/gcc-5.2.0/libitm/config/sh/sjlj.S 2015-01-05 12:33:28.000000000 +0000
  1821. +++ gcc-5.2.0/libitm/config/sh/sjlj.S 2015-09-11 04:56:22.272911159 +0000
  1822. @@ -58,9 +58,6 @@ _ITM_beginTransaction:
  1823. jsr @r1
  1824. mov r15, r5
  1825. #else
  1826. - mova .Lgot, r0
  1827. - mov.l .Lgot, r12
  1828. - add r0, r12
  1829. mov.l .Lbegin, r1
  1830. bsrf r1
  1831. mov r15, r5
  1832. @@ -80,13 +77,11 @@ _ITM_beginTransaction:
  1833. cfi_endproc
  1834. .align 2
  1835. -.Lgot:
  1836. - .long _GLOBAL_OFFSET_TABLE_
  1837. .Lbegin:
  1838. #if defined HAVE_ATTRIBUTE_VISIBILITY || !defined __PIC__
  1839. .long GTM_begin_transaction
  1840. #else
  1841. - .long GTM_begin_transaction@PLT-(.Lbegin0-.)
  1842. + .long GTM_begin_transaction@PCREL-(.Lbegin0-.)
  1843. #endif
  1844. .size _ITM_beginTransaction, . - _ITM_beginTransaction