0007-fdpic.diff 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944
  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 05:22:57.786789746 +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. @@ -12718,10 +12858,18 @@ sh_output_mi_thunk (FILE *file, tree thu
  503. sibcall = gen_sibcalli_thunk (funexp, const0_rtx);
  504. else
  505. #endif
  506. - if (TARGET_SH2 && flag_pic)
  507. + if (TARGET_SH2 && (flag_pic || TARGET_FDPIC))
  508. {
  509. - sibcall = gen_sibcall_pcrel (funexp, const0_rtx);
  510. - XEXP (XVECEXP (sibcall, 0, 2), 0) = scratch2;
  511. + if (TARGET_FDPIC)
  512. + {
  513. + sibcall = gen_sibcall_pcrel_fdpic (funexp, const0_rtx);
  514. + XEXP (XVECEXP (sibcall, 0, 3), 0) = scratch2;
  515. + }
  516. + else
  517. + {
  518. + sibcall = gen_sibcall_pcrel (funexp, const0_rtx);
  519. + XEXP (XVECEXP (sibcall, 0, 2), 0) = scratch2;
  520. + }
  521. }
  522. else
  523. {
  524. @@ -12762,11 +12910,24 @@ sh_output_mi_thunk (FILE *file, tree thu
  525. epilogue_completed = 0;
  526. }
  527. +/* Return an RTX for the address of a function NAME of kind KIND,
  528. + placing the result in TARGET if not NULL. LAB should be non-NULL
  529. + for SFUNC_STATIC, if FDPIC; it will be set to (const_int 0) if jsr
  530. + should be used, or a label_ref if bsrf should be used. For FDPIC,
  531. + both SFUNC_GOT and SFUNC_STATIC will return the address of the
  532. + function itself, not a function descriptor, so they can only be
  533. + used with functions not using the FDPIC register that are known to
  534. + be called directory without a PLT entry. */
  535. +
  536. rtx
  537. -function_symbol (rtx target, const char *name, enum sh_function_kind kind)
  538. +function_symbol (rtx target, const char *name, enum sh_function_kind kind,
  539. + rtx *lab)
  540. {
  541. rtx sym;
  542. + if (lab)
  543. + *lab = const0_rtx;
  544. +
  545. /* If this is not an ordinary function, the name usually comes from a
  546. string literal or an sprintf buffer. Make sure we use the same
  547. string consistently, so that cse will be able to unify address loads. */
  548. @@ -12774,7 +12935,7 @@ function_symbol (rtx target, const char
  549. name = IDENTIFIER_POINTER (get_identifier (name));
  550. sym = gen_rtx_SYMBOL_REF (Pmode, name);
  551. SYMBOL_REF_FLAGS (sym) = SYMBOL_FLAG_FUNCTION;
  552. - if (flag_pic)
  553. + if (flag_pic || TARGET_FDPIC)
  554. switch (kind)
  555. {
  556. case FUNCTION_ORDINARY:
  557. @@ -12789,14 +12950,27 @@ function_symbol (rtx target, const char
  558. }
  559. case SFUNC_STATIC:
  560. {
  561. - /* ??? To allow cse to work, we use GOTOFF relocations.
  562. - We could add combiner patterns to transform this into
  563. - straight pc-relative calls with sym2PIC / bsrf when
  564. - label load and function call are still 1:1 and in the
  565. - same basic block during combine. */
  566. rtx reg = target ? target : gen_reg_rtx (Pmode);
  567. - emit_insn (gen_symGOTOFF2reg (reg, sym));
  568. + if (TARGET_FDPIC)
  569. + {
  570. + /* We use PC-relative calls, since GOTOFF can only refer
  571. + to writable data. This works along with
  572. + sh_sfunc_call. */
  573. + gcc_assert (lab != NULL);
  574. + *lab = PATTERN (gen_call_site ());
  575. + emit_insn (gen_sym_label2reg (reg, sym, *lab));
  576. + }
  577. + else
  578. + {
  579. + /* ??? To allow cse to work, we use GOTOFF relocations.
  580. + we could add combiner patterns to transform this into
  581. + straight pc-relative calls with sym2PIC / bsrf when
  582. + label load and function call are still 1:1 and in the
  583. + same basic block during combine. */
  584. + emit_insn (gen_symGOTOFF2reg (reg, sym));
  585. + }
  586. +
  587. sym = reg;
  588. break;
  589. }
  590. @@ -13419,6 +13593,12 @@ sh_conditional_register_usage (void)
  591. fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
  592. call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
  593. }
  594. + if (TARGET_FDPIC)
  595. + {
  596. + fixed_regs[PIC_REG] = 1;
  597. + call_used_regs[PIC_REG] = 1;
  598. + call_really_used_regs[PIC_REG] = 1;
  599. + }
  600. /* Renesas saves and restores mac registers on call. */
  601. if (TARGET_HITACHI && ! TARGET_NOMACSAVE)
  602. {
  603. @@ -14496,4 +14676,84 @@ sh_use_by_pieces_infrastructure_p (unsig
  604. }
  605. }
  606. +bool
  607. +sh_legitimate_constant_p (rtx x)
  608. +{
  609. + if (SH_OFFSETS_MUST_BE_WITHIN_SECTIONS_P)
  610. + {
  611. + rtx base, offset;
  612. +
  613. + split_const (x, &base, &offset);
  614. + if (GET_CODE (base) == SYMBOL_REF
  615. + && !offset_within_block_p (base, INTVAL (offset)))
  616. + return false;
  617. + }
  618. +
  619. + if (TARGET_FDPIC
  620. + && (SYMBOLIC_CONST_P (x)
  621. + || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
  622. + && SYMBOLIC_CONST_P (XEXP (XEXP (x, 0), 0)))))
  623. + return false;
  624. +
  625. + if (TARGET_SHMEDIA)
  626. + return ((GET_MODE (x) != DFmode
  627. + && GET_MODE_CLASS (GET_MODE (x)) != MODE_VECTOR_FLOAT)
  628. + || (x) == CONST0_RTX (GET_MODE (x))
  629. + || ! TARGET_SHMEDIA_FPU
  630. + || TARGET_SHMEDIA64);
  631. +
  632. + return (GET_CODE (x) != CONST_DOUBLE
  633. + || GET_MODE (x) == DFmode || GET_MODE (x) == SFmode
  634. + || GET_MODE (x) == DImode || GET_MODE (x) == VOIDmode);
  635. +}
  636. +
  637. +bool
  638. +sh_cannot_force_const_mem_p (machine_mode mode ATTRIBUTE_UNUSED,
  639. + rtx x ATTRIBUTE_UNUSED)
  640. +{
  641. + if (TARGET_FDPIC)
  642. + return true;
  643. +
  644. + return false;
  645. +}
  646. +
  647. +/* Emit insns to load the function address from FUNCDESC (an FDPIC
  648. + function descriptor) into r1 and the GOT address into r12,
  649. + returning an rtx for r1. */
  650. +
  651. +rtx
  652. +sh_load_function_descriptor (rtx funcdesc)
  653. +{
  654. + rtx r1 = gen_rtx_REG (Pmode, R1_REG);
  655. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  656. + rtx fnaddr = gen_rtx_MEM (Pmode, funcdesc);
  657. + rtx gotaddr = gen_rtx_MEM (Pmode, plus_constant (Pmode, funcdesc, 4));
  658. +
  659. + emit_move_insn (r1, fnaddr);
  660. + /* The ABI requires the entry point address to be loaded first, so
  661. + prevent the load from being moved after that of the GOT
  662. + address. */
  663. + emit_insn (gen_blockage ());
  664. + emit_move_insn (pic_reg, gotaddr);
  665. + return r1;
  666. +}
  667. +
  668. +/* Return an rtx holding the initial value of the FDPIC register (the
  669. + FDPIC pointer passed in from the caller). */
  670. +
  671. +rtx
  672. +sh_our_fdpic_reg (void)
  673. +{
  674. + return get_hard_reg_initial_val (Pmode, PIC_REG);
  675. +}
  676. +
  677. +/* Relocatable data for FDPIC binaries is not permitted in read-only
  678. + segments. */
  679. +
  680. +static int
  681. +sh_reloc_rw_mask (void)
  682. +{
  683. + return (flag_pic || TARGET_FDPIC) ? 3 : 0;
  684. +}
  685. +
  686. #include "gt-sh.h"
  687. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/sh.h gcc-5.2.0/gcc/config/sh/sh.h
  688. --- ../baseline/gcc-5.2.0/gcc/config/sh/sh.h 2015-09-04 20:23:46.711452245 +0000
  689. +++ gcc-5.2.0/gcc/config/sh/sh.h 2015-09-11 02:17:54.210157580 +0000
  690. @@ -321,7 +321,7 @@ extern int code_for_indirect_jump_scratc
  691. #endif
  692. #ifndef SUBTARGET_ASM_SPEC
  693. -#define SUBTARGET_ASM_SPEC ""
  694. +#define SUBTARGET_ASM_SPEC "%{!mno-fdpic:--fdpic}"
  695. #endif
  696. #if TARGET_ENDIAN_DEFAULT == MASK_LITTLE_ENDIAN
  697. @@ -349,7 +349,7 @@ extern int code_for_indirect_jump_scratc
  698. #define ASM_ISA_DEFAULT_SPEC ""
  699. #endif /* MASK_SH5 */
  700. -#define SUBTARGET_LINK_EMUL_SUFFIX ""
  701. +#define SUBTARGET_LINK_EMUL_SUFFIX "%{mfdpic:_fd}"
  702. #define SUBTARGET_LINK_SPEC ""
  703. /* Go via SH_LINK_SPEC to avoid code replication. */
  704. @@ -383,8 +383,18 @@ extern int code_for_indirect_jump_scratc
  705. "%{m2a*:%eSH2a does not support little-endian}}"
  706. #endif
  707. +#ifdef FDPIC_DEFAULT
  708. +#define FDPIC_SELF_SPECS "%{!mno-fdpic:-mfdpic}"
  709. +#else
  710. +#define FDPIC_SELF_SPECS
  711. +#endif
  712. +
  713. #undef DRIVER_SELF_SPECS
  714. -#define DRIVER_SELF_SPECS UNSUPPORTED_SH2A
  715. +#define DRIVER_SELF_SPECS UNSUPPORTED_SH2A SUBTARGET_DRIVER_SELF_SPECS \
  716. + FDPIC_SELF_SPECS
  717. +
  718. +#undef SUBTARGET_DRIVER_SELF_SPECS
  719. +#define SUBTARGET_DRIVER_SELF_SPECS
  720. #define ASSEMBLER_DIALECT assembler_dialect
  721. @@ -942,6 +952,14 @@ extern char sh_additional_register_names
  722. code access to data items. */
  723. #define PIC_OFFSET_TABLE_REGNUM (flag_pic ? PIC_REG : INVALID_REGNUM)
  724. +/* For FDPIC, the FDPIC register is call-clobbered (otherwise PLT
  725. + entries would need to handle saving and restoring it). */
  726. +#define PIC_OFFSET_TABLE_REG_CALL_CLOBBERED TARGET_FDPIC
  727. +
  728. +/* An rtx holding the initial value of the FDPIC register (the FDPIC
  729. + pointer passed in from the caller). */
  730. +#define OUR_FDPIC_REG sh_our_fdpic_reg ()
  731. +
  732. #define GOT_SYMBOL_NAME "*_GLOBAL_OFFSET_TABLE_"
  733. /* Definitions for register eliminations.
  734. @@ -1566,7 +1584,9 @@ struct sh_args {
  735. 6 000c 00000000 l2: .long function */
  736. /* Length in units of the trampoline for entering a nested function. */
  737. -#define TRAMPOLINE_SIZE (TARGET_SHMEDIA64 ? 40 : TARGET_SH5 ? 24 : 16)
  738. +// FIXME: what happens if someone tries fdpic on SH5?
  739. +#define TRAMPOLINE_SIZE \
  740. + (TARGET_SHMEDIA64 ? 40 : TARGET_SH5 ? 24 : TARGET_FDPIC ? 32 : 16)
  741. /* Alignment required for a trampoline in bits. */
  742. #define TRAMPOLINE_ALIGNMENT \
  743. @@ -1622,6 +1642,11 @@ struct sh_args {
  744. || GENERAL_REGISTER_P ((unsigned) reg_renumber[(REGNO)])) \
  745. : (REGNO) == R0_REG || (unsigned) reg_renumber[(REGNO)] == R0_REG)
  746. +/* True if SYMBOL + OFFSET constants must refer to something within
  747. + SYMBOL's section. */
  748. +// FIXME: is this correct?
  749. +#define SH_OFFSETS_MUST_BE_WITHIN_SECTIONS_P TARGET_FDPIC
  750. +
  751. /* Maximum number of registers that can appear in a valid memory
  752. address. */
  753. #define MAX_REGS_PER_ADDRESS 2
  754. @@ -2262,9 +2287,12 @@ extern int current_function_interrupt;
  755. /* We have to distinguish between code and data, so that we apply
  756. datalabel where and only where appropriate. Use sdataN for data. */
  757. #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
  758. - ((flag_pic && (GLOBAL) ? DW_EH_PE_indirect : 0) \
  759. - | (flag_pic ? DW_EH_PE_pcrel : DW_EH_PE_absptr) \
  760. - | ((CODE) ? 0 : (TARGET_SHMEDIA64 ? DW_EH_PE_sdata8 : DW_EH_PE_sdata4)))
  761. + ((TARGET_FDPIC \
  762. + ? ((GLOBAL) ? DW_EH_PE_indirect | DW_EH_PE_datarel \
  763. + : DW_EH_PE_pcrel) \
  764. + : ((flag_pic && (GLOBAL) ? DW_EH_PE_indirect : 0) \
  765. + | (flag_pic ? DW_EH_PE_pcrel : DW_EH_PE_absptr))) \
  766. + | ((CODE) ? 0 : (TARGET_SHMEDIA64 ? DW_EH_PE_sdata8 : DW_EH_PE_sdata4)))
  767. /* Handle special EH pointer encodings. Absolute, pc-relative, and
  768. indirect are handled automatically. */
  769. @@ -2277,6 +2305,17 @@ extern int current_function_interrupt;
  770. SYMBOL_REF_FLAGS (ADDR) |= SYMBOL_FLAG_FUNCTION; \
  771. if (0) goto DONE; \
  772. } \
  773. + if (TARGET_FDPIC \
  774. + && ((ENCODING) & 0xf0) == (DW_EH_PE_indirect | DW_EH_PE_datarel)) \
  775. + { \
  776. + fputs ("\t.ualong ", FILE); \
  777. + output_addr_const (FILE, ADDR); \
  778. + if (GET_CODE (ADDR) == SYMBOL_REF && SYMBOL_REF_FUNCTION_P (ADDR)) \
  779. + fputs ("@GOTFUNCDESC", FILE); \
  780. + else \
  781. + fputs ("@GOT", FILE); \
  782. + goto DONE; \
  783. + } \
  784. } while (0)
  785. #if (defined CRT_BEGIN || defined CRT_END) && ! __SHMEDIA__
  786. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/sh.md gcc-5.2.0/gcc/config/sh/sh.md
  787. --- ../baseline/gcc-5.2.0/gcc/config/sh/sh.md 2015-09-04 20:23:46.704785579 +0000
  788. +++ gcc-5.2.0/gcc/config/sh/sh.md 2015-09-03 22:30:13.462560589 +0000
  789. @@ -100,6 +100,7 @@
  790. (R8_REG 8)
  791. (R9_REG 9)
  792. (R10_REG 10)
  793. + (R12_REG 12)
  794. (R20_REG 20)
  795. (R21_REG 21)
  796. (R22_REG 22)
  797. @@ -170,6 +171,9 @@
  798. UNSPEC_SYMOFF
  799. ;; (unspec [OFFSET ANCHOR] UNSPEC_PCREL_SYMOFF) == OFFSET - (ANCHOR - .).
  800. UNSPEC_PCREL_SYMOFF
  801. + ;; For FDPIC
  802. + UNSPEC_GOTFUNCDESC
  803. + UNSPEC_GOTOFFFUNCDESC
  804. ;; Misc builtins
  805. UNSPEC_BUILTIN_STRLEN
  806. ])
  807. @@ -2495,15 +2499,18 @@
  808. ;; This reload would clobber the value in r0 we are trying to store.
  809. ;; If we let reload allocate r0, then this problem can never happen.
  810. (define_insn "udivsi3_i1"
  811. - [(set (match_operand:SI 0 "register_operand" "=z")
  812. + [(set (match_operand:SI 0 "register_operand" "=z,z")
  813. (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
  814. (clobber (reg:SI T_REG))
  815. (clobber (reg:SI PR_REG))
  816. (clobber (reg:SI R1_REG))
  817. (clobber (reg:SI R4_REG))
  818. - (use (match_operand:SI 1 "arith_reg_operand" "r"))]
  819. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  820. + (use (match_operand 2 "" "Z,Ccl"))]
  821. "TARGET_SH1 && TARGET_DIVIDE_CALL_DIV1"
  822. - "jsr @%1%#"
  823. + "@
  824. + jsr @%1%#
  825. + bsrf %1\\n%O2:%#"
  826. [(set_attr "type" "sfunc")
  827. (set_attr "needs_delay_slot" "yes")])
  828. @@ -2552,7 +2559,7 @@
  829. })
  830. (define_insn "udivsi3_i4"
  831. - [(set (match_operand:SI 0 "register_operand" "=y")
  832. + [(set (match_operand:SI 0 "register_operand" "=y,y")
  833. (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
  834. (clobber (reg:SI T_REG))
  835. (clobber (reg:SI PR_REG))
  836. @@ -2564,16 +2571,19 @@
  837. (clobber (reg:SI R4_REG))
  838. (clobber (reg:SI R5_REG))
  839. (clobber (reg:SI FPSCR_STAT_REG))
  840. - (use (match_operand:SI 1 "arith_reg_operand" "r"))
  841. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  842. + (use (match_operand 2 "" "Z,Ccl"))
  843. (use (reg:SI FPSCR_MODES_REG))]
  844. "TARGET_FPU_DOUBLE && ! TARGET_FPU_SINGLE"
  845. - "jsr @%1%#"
  846. + "@
  847. + jsr @%1%#
  848. + bsrf %1\\n%O2:%#"
  849. [(set_attr "type" "sfunc")
  850. (set_attr "fp_mode" "double")
  851. (set_attr "needs_delay_slot" "yes")])
  852. (define_insn "udivsi3_i4_single"
  853. - [(set (match_operand:SI 0 "register_operand" "=y")
  854. + [(set (match_operand:SI 0 "register_operand" "=y,y")
  855. (udiv:SI (reg:SI R4_REG) (reg:SI R5_REG)))
  856. (clobber (reg:SI T_REG))
  857. (clobber (reg:SI PR_REG))
  858. @@ -2584,10 +2594,13 @@
  859. (clobber (reg:SI R1_REG))
  860. (clobber (reg:SI R4_REG))
  861. (clobber (reg:SI R5_REG))
  862. - (use (match_operand:SI 1 "arith_reg_operand" "r"))]
  863. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  864. + (use (match_operand 2 "" "Z,Ccl"))]
  865. "(TARGET_FPU_SINGLE_ONLY || TARGET_FPU_DOUBLE || TARGET_SHCOMPACT)
  866. && TARGET_FPU_SINGLE"
  867. - "jsr @%1%#"
  868. + "@
  869. + jsr @%1%#
  870. + bsrf %1\\n%O2:%#"
  871. [(set_attr "type" "sfunc")
  872. (set_attr "needs_delay_slot" "yes")])
  873. @@ -2641,16 +2654,17 @@
  874. emit_move_insn (operands[0], operands[2]);
  875. DONE;
  876. }
  877. - function_symbol (operands[3], "__udivsi3_i4i", SFUNC_GOT);
  878. + function_symbol (operands[3], "__udivsi3_i4i", SFUNC_GOT, NULL);
  879. last = gen_udivsi3_i4_int (operands[0], operands[3]);
  880. }
  881. else if (TARGET_DIVIDE_CALL_FP)
  882. {
  883. - function_symbol (operands[3], "__udivsi3_i4", SFUNC_STATIC);
  884. + rtx lab;
  885. + function_symbol (operands[3], "__udivsi3_i4", SFUNC_STATIC, &lab);
  886. if (TARGET_FPU_SINGLE)
  887. - last = gen_udivsi3_i4_single (operands[0], operands[3]);
  888. + last = gen_udivsi3_i4_single (operands[0], operands[3], lab);
  889. else
  890. - last = gen_udivsi3_i4 (operands[0], operands[3]);
  891. + last = gen_udivsi3_i4 (operands[0], operands[3], lab);
  892. }
  893. else if (TARGET_SHMEDIA_FPU)
  894. {
  895. @@ -2670,19 +2684,20 @@
  896. {
  897. function_symbol (operands[3],
  898. TARGET_FPU_ANY ? "__udivsi3_i4" : "__udivsi3",
  899. - SFUNC_STATIC);
  900. + SFUNC_STATIC, NULL);
  901. if (TARGET_SHMEDIA)
  902. last = gen_udivsi3_i1_media (operands[0], operands[3]);
  903. else if (TARGET_FPU_ANY)
  904. - last = gen_udivsi3_i4_single (operands[0], operands[3]);
  905. + last = gen_udivsi3_i4_single (operands[0], operands[3], const0_rtx);
  906. else
  907. - last = gen_udivsi3_i1 (operands[0], operands[3]);
  908. + last = gen_udivsi3_i1 (operands[0], operands[3], const0_rtx);
  909. }
  910. else
  911. {
  912. - function_symbol (operands[3], "__udivsi3", SFUNC_STATIC);
  913. - last = gen_udivsi3_i1 (operands[0], operands[3]);
  914. + rtx lab;
  915. + function_symbol (operands[3], \"__udivsi3\", SFUNC_STATIC, &lab);
  916. + last = gen_udivsi3_i1 (operands[0], operands[3], lab);
  917. }
  918. emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
  919. emit_move_insn (gen_rtx_REG (SImode, 5), operands[2]);
  920. @@ -2810,7 +2825,7 @@
  921. emit_move_insn (gen_rtx_REG (DImode, R20_REG), x);
  922. break;
  923. }
  924. - sym = function_symbol (NULL, name, kind);
  925. + sym = function_symbol (NULL, name, kind, NULL);
  926. emit_insn (gen_divsi3_media_2 (operands[0], sym));
  927. DONE;
  928. }
  929. @@ -2830,31 +2845,37 @@
  930. })
  931. (define_insn "divsi3_i4"
  932. - [(set (match_operand:SI 0 "register_operand" "=y")
  933. + [(set (match_operand:SI 0 "register_operand" "=y,y")
  934. (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
  935. (clobber (reg:SI PR_REG))
  936. (clobber (reg:DF DR0_REG))
  937. (clobber (reg:DF DR2_REG))
  938. (clobber (reg:SI FPSCR_STAT_REG))
  939. - (use (match_operand:SI 1 "arith_reg_operand" "r"))
  940. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  941. + (use (match_operand 2 "" "Z,Ccl"))
  942. (use (reg:SI FPSCR_MODES_REG))]
  943. "TARGET_FPU_DOUBLE && ! TARGET_FPU_SINGLE"
  944. - "jsr @%1%#"
  945. + "@
  946. + jsr @%1%#
  947. + bsrf %1\\n%O2:%#"
  948. [(set_attr "type" "sfunc")
  949. (set_attr "fp_mode" "double")
  950. (set_attr "needs_delay_slot" "yes")])
  951. (define_insn "divsi3_i4_single"
  952. - [(set (match_operand:SI 0 "register_operand" "=y")
  953. + [(set (match_operand:SI 0 "register_operand" "=y,y")
  954. (div:SI (reg:SI R4_REG) (reg:SI R5_REG)))
  955. (clobber (reg:SI PR_REG))
  956. (clobber (reg:DF DR0_REG))
  957. (clobber (reg:DF DR2_REG))
  958. (clobber (reg:SI R2_REG))
  959. - (use (match_operand:SI 1 "arith_reg_operand" "r"))]
  960. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  961. + (use (match_operand 2 "" "Z,Ccl"))]
  962. "(TARGET_FPU_SINGLE_ONLY || TARGET_FPU_DOUBLE || TARGET_SHCOMPACT)
  963. && TARGET_FPU_SINGLE"
  964. - "jsr @%1%#"
  965. + "@
  966. + jsr @%1%#
  967. + bsrf %1\\n%O2:%#"
  968. [(set_attr "type" "sfunc")
  969. (set_attr "needs_delay_slot" "yes")])
  970. @@ -2893,16 +2914,17 @@
  971. /* Emit the move of the address to a pseudo outside of the libcall. */
  972. if (TARGET_DIVIDE_CALL_TABLE)
  973. {
  974. - function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT);
  975. + function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT, NULL);
  976. last = gen_divsi3_i4_int (operands[0], operands[3]);
  977. }
  978. else if (TARGET_DIVIDE_CALL_FP)
  979. {
  980. - function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_STATIC);
  981. + rtx lab;
  982. + function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_STATIC, &lab);
  983. if (TARGET_FPU_SINGLE)
  984. - last = gen_divsi3_i4_single (operands[0], operands[3]);
  985. + last = gen_divsi3_i4_single (operands[0], operands[3], lab);
  986. else
  987. - last = gen_divsi3_i4 (operands[0], operands[3]);
  988. + last = gen_divsi3_i4 (operands[0], operands[3], lab);
  989. }
  990. else if (TARGET_SH2A)
  991. {
  992. @@ -3007,23 +3029,23 @@
  993. emit_move_insn (gen_rtx_REG (Pmode, R20_REG), tab_base);
  994. }
  995. if (TARGET_FPU_ANY && TARGET_SH1)
  996. - function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_STATIC);
  997. + function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_STATIC, NULL);
  998. else if (TARGET_DIVIDE_CALL2)
  999. - function_symbol (operands[3], "__sdivsi3_2", SFUNC_STATIC);
  1000. + function_symbol (operands[3], "__sdivsi3_2", SFUNC_STATIC, NULL);
  1001. else
  1002. - function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT);
  1003. + function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT, NULL);
  1004. if (TARGET_SHMEDIA)
  1005. last = ((TARGET_DIVIDE_CALL2 ? gen_divsi3_media_2 : gen_divsi3_i1_media)
  1006. (operands[0], operands[3]));
  1007. else if (TARGET_FPU_ANY)
  1008. - last = gen_divsi3_i4_single (operands[0], operands[3]);
  1009. + last = gen_divsi3_i4_single (operands[0], operands[3], const0_rtx);
  1010. else
  1011. last = gen_divsi3_i1 (operands[0], operands[3]);
  1012. }
  1013. else
  1014. {
  1015. - function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT);
  1016. + function_symbol (operands[3], sh_divsi3_libfunc, SFUNC_GOT, NULL);
  1017. last = gen_divsi3_i1 (operands[0], operands[3]);
  1018. }
  1019. emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]);
  1020. @@ -3617,7 +3639,7 @@ label:
  1021. {
  1022. /* The address must be set outside the libcall,
  1023. since it goes into a pseudo. */
  1024. - rtx sym = function_symbol (NULL, "__mulsi3", SFUNC_STATIC);
  1025. + rtx sym = function_symbol (NULL, "__mulsi3", SFUNC_STATIC, NULL);
  1026. rtx addr = force_reg (SImode, sym);
  1027. rtx insns = gen_mulsi3_call (operands[0], operands[1],
  1028. operands[2], addr);
  1029. @@ -4873,7 +4895,7 @@ label:
  1030. {
  1031. emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
  1032. rtx funcaddr = gen_reg_rtx (Pmode);
  1033. - function_symbol (funcaddr, "__ashlsi3_r0", SFUNC_STATIC);
  1034. + function_symbol (funcaddr, "__ashlsi3_r0", SFUNC_STATIC, NULL);
  1035. emit_insn (gen_ashlsi3_d_call (operands[0], operands[2], funcaddr));
  1036. DONE;
  1037. @@ -5277,12 +5299,15 @@ label:
  1038. (define_insn "ashrsi3_n"
  1039. [(set (reg:SI R4_REG)
  1040. (ashiftrt:SI (reg:SI R4_REG)
  1041. - (match_operand:SI 0 "const_int_operand" "i")))
  1042. + (match_operand:SI 0 "const_int_operand" "i,i")))
  1043. (clobber (reg:SI T_REG))
  1044. (clobber (reg:SI PR_REG))
  1045. - (use (match_operand:SI 1 "arith_reg_operand" "r"))]
  1046. + (use (match_operand:SI 1 "arith_reg_operand" "r,r"))
  1047. + (use (match_operand 2 "" "Z,Ccl"))]
  1048. "TARGET_SH1"
  1049. - "jsr @%1%#"
  1050. + "@
  1051. + jsr @%1%#
  1052. + bsrf %1\\n%O2:%#"
  1053. [(set_attr "type" "sfunc")
  1054. (set_attr "needs_delay_slot" "yes")])
  1055. @@ -5435,7 +5460,7 @@ label:
  1056. {
  1057. emit_move_insn (gen_rtx_REG (SImode, R4_REG), operands[1]);
  1058. rtx funcaddr = gen_reg_rtx (Pmode);
  1059. - function_symbol (funcaddr, "__lshrsi3_r0", SFUNC_STATIC);
  1060. + function_symbol (funcaddr, "__lshrsi3_r0", SFUNC_STATIC, NULL);
  1061. emit_insn (gen_lshrsi3_d_call (operands[0], operands[2], funcaddr));
  1062. DONE;
  1063. }
  1064. @@ -7218,7 +7243,8 @@ label:
  1065. }
  1066. else if (TARGET_SHCOMPACT)
  1067. {
  1068. - operands[1] = function_symbol (NULL, "__ic_invalidate", SFUNC_STATIC);
  1069. + operands[1] = function_symbol (NULL, "__ic_invalidate", SFUNC_STATIC,
  1070. + NULL);
  1071. operands[1] = force_reg (Pmode, operands[1]);
  1072. emit_insn (gen_ic_invalidate_line_compact (operands[0], operands[1]));
  1073. DONE;
  1074. @@ -7300,7 +7326,7 @@ label:
  1075. tramp = force_reg (Pmode, operands[0]);
  1076. sfun = force_reg (Pmode, function_symbol (NULL, "__init_trampoline",
  1077. - SFUNC_STATIC));
  1078. + SFUNC_STATIC, NULL));
  1079. emit_move_insn (gen_rtx_REG (SImode, R2_REG), operands[1]);
  1080. emit_move_insn (gen_rtx_REG (SImode, R3_REG), operands[2]);
  1081. @@ -9342,7 +9368,27 @@ label:
  1082. (match_operand 1 "" ""))
  1083. (use (reg:SI FPSCR_MODES_REG))
  1084. (clobber (reg:SI PR_REG))]
  1085. - "TARGET_SH1"
  1086. + "TARGET_SH1 && !TARGET_FDPIC"
  1087. +{
  1088. + if (TARGET_SH2A && (dbr_sequence_length () == 0))
  1089. + return "jsr/n @%0";
  1090. + else
  1091. + return "jsr @%0%#";
  1092. +}
  1093. + [(set_attr "type" "call")
  1094. + (set (attr "fp_mode")
  1095. + (if_then_else (eq_attr "fpu_single" "yes")
  1096. + (const_string "single") (const_string "double")))
  1097. + (set_attr "needs_delay_slot" "yes")
  1098. + (set_attr "fp_set" "unknown")])
  1099. +
  1100. +(define_insn "calli_fdpic"
  1101. + [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "r"))
  1102. + (match_operand 1 "" ""))
  1103. + (use (reg:SI FPSCR_MODES_REG))
  1104. + (use (reg:SI PIC_REG))
  1105. + (clobber (reg:SI PR_REG))]
  1106. + "TARGET_SH1 && TARGET_FDPIC"
  1107. {
  1108. if (TARGET_SH2A && (dbr_sequence_length () == 0))
  1109. return "jsr/n @%0";
  1110. @@ -9471,7 +9517,28 @@ label:
  1111. (match_operand 2 "" "")))
  1112. (use (reg:SI FPSCR_MODES_REG))
  1113. (clobber (reg:SI PR_REG))]
  1114. - "TARGET_SH1"
  1115. + "TARGET_SH1 && !TARGET_FDPIC"
  1116. +{
  1117. + if (TARGET_SH2A && (dbr_sequence_length () == 0))
  1118. + return "jsr/n @%1";
  1119. + else
  1120. + return "jsr @%1%#";
  1121. +}
  1122. + [(set_attr "type" "call")
  1123. + (set (attr "fp_mode")
  1124. + (if_then_else (eq_attr "fpu_single" "yes")
  1125. + (const_string "single") (const_string "double")))
  1126. + (set_attr "needs_delay_slot" "yes")
  1127. + (set_attr "fp_set" "unknown")])
  1128. +
  1129. +(define_insn "call_valuei_fdpic"
  1130. + [(set (match_operand 0 "" "=rf")
  1131. + (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "r"))
  1132. + (match_operand 2 "" "")))
  1133. + (use (reg:SI FPSCR_REG))
  1134. + (use (reg:SI PIC_REG))
  1135. + (clobber (reg:SI PR_REG))]
  1136. + "TARGET_SH1 && TARGET_FDPIC"
  1137. {
  1138. if (TARGET_SH2A && (dbr_sequence_length () == 0))
  1139. return "jsr/n @%1";
  1140. @@ -9608,6 +9675,12 @@ label:
  1141. (clobber (reg:SI PR_REG))])]
  1142. ""
  1143. {
  1144. + if (TARGET_FDPIC)
  1145. + {
  1146. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  1147. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  1148. + }
  1149. +
  1150. if (TARGET_SHMEDIA)
  1151. {
  1152. operands[0] = shmedia_prepare_call_address (operands[0], 0);
  1153. @@ -9643,7 +9716,8 @@ label:
  1154. emit_insn (gen_force_mode_for_call ());
  1155. operands[0]
  1156. - = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
  1157. + = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1158. + SFUNC_GOT, NULL);
  1159. operands[0] = force_reg (SImode, operands[0]);
  1160. emit_move_insn (r0, func);
  1161. @@ -9667,7 +9741,7 @@ label:
  1162. emit_insn (gen_symGOTPLT2reg (reg, XEXP (operands[0], 0)));
  1163. XEXP (operands[0], 0) = reg;
  1164. }
  1165. - if (!flag_pic && TARGET_SH2A
  1166. + if (!flag_pic && !TARGET_FDPIC && TARGET_SH2A
  1167. && MEM_P (operands[0])
  1168. && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
  1169. {
  1170. @@ -9678,7 +9752,7 @@ label:
  1171. DONE;
  1172. }
  1173. }
  1174. - if (flag_pic && TARGET_SH2
  1175. + if ((flag_pic || TARGET_FDPIC) && TARGET_SH2
  1176. && MEM_P (operands[0])
  1177. && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
  1178. {
  1179. @@ -9691,7 +9765,13 @@ label:
  1180. operands[1] = operands[2];
  1181. }
  1182. - emit_call_insn (gen_calli (operands[0], operands[1]));
  1183. + if (TARGET_FDPIC)
  1184. + {
  1185. + operands[0] = sh_load_function_descriptor (operands[0]);
  1186. + emit_call_insn (gen_calli_fdpic (operands[0], operands[1]));
  1187. + }
  1188. + else
  1189. + emit_call_insn (gen_calli (operands[0], operands[1]));
  1190. DONE;
  1191. })
  1192. @@ -9771,7 +9851,7 @@ label:
  1193. emit_insn (gen_force_mode_for_call ());
  1194. operands[0] = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1195. - SFUNC_GOT);
  1196. + SFUNC_GOT, NULL);
  1197. operands[0] = force_reg (SImode, operands[0]);
  1198. emit_move_insn (r0, func);
  1199. @@ -9796,6 +9876,12 @@ label:
  1200. (clobber (reg:SI PR_REG))])]
  1201. ""
  1202. {
  1203. + if (TARGET_FDPIC)
  1204. + {
  1205. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  1206. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  1207. + }
  1208. +
  1209. if (TARGET_SHMEDIA)
  1210. {
  1211. operands[1] = shmedia_prepare_call_address (operands[1], 0);
  1212. @@ -9832,7 +9918,8 @@ label:
  1213. emit_insn (gen_force_mode_for_call ());
  1214. operands[1]
  1215. - = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
  1216. + = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1217. + SFUNC_GOT, NULL);
  1218. operands[1] = force_reg (SImode, operands[1]);
  1219. emit_move_insn (r0, func);
  1220. @@ -9858,7 +9945,7 @@ label:
  1221. emit_insn (gen_symGOTPLT2reg (reg, XEXP (operands[1], 0)));
  1222. XEXP (operands[1], 0) = reg;
  1223. }
  1224. - if (!flag_pic && TARGET_SH2A
  1225. + if (!flag_pic && !TARGET_FDPIC && TARGET_SH2A
  1226. && MEM_P (operands[1])
  1227. && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
  1228. {
  1229. @@ -9869,7 +9956,7 @@ label:
  1230. DONE;
  1231. }
  1232. }
  1233. - if (flag_pic && TARGET_SH2
  1234. + if ((flag_pic || TARGET_FDPIC) && TARGET_SH2
  1235. && MEM_P (operands[1])
  1236. && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
  1237. {
  1238. @@ -9880,7 +9967,14 @@ label:
  1239. else
  1240. operands[1] = force_reg (SImode, XEXP (operands[1], 0));
  1241. - emit_call_insn (gen_call_valuei (operands[0], operands[1], operands[2]));
  1242. + if (TARGET_FDPIC)
  1243. + {
  1244. + operands[1] = sh_load_function_descriptor (operands[1]);
  1245. + emit_call_insn (gen_call_valuei_fdpic (operands[0], operands[1],
  1246. + operands[2]));
  1247. + }
  1248. + else
  1249. + emit_call_insn (gen_call_valuei (operands[0], operands[1], operands[2]));
  1250. DONE;
  1251. })
  1252. @@ -9889,7 +9983,21 @@ label:
  1253. (match_operand 1 "" ""))
  1254. (use (reg:SI FPSCR_MODES_REG))
  1255. (return)]
  1256. - "TARGET_SH1"
  1257. + "TARGET_SH1 && !TARGET_FDPIC"
  1258. + "jmp @%0%#"
  1259. + [(set_attr "needs_delay_slot" "yes")
  1260. + (set (attr "fp_mode")
  1261. + (if_then_else (eq_attr "fpu_single" "yes")
  1262. + (const_string "single") (const_string "double")))
  1263. + (set_attr "type" "jump_ind")])
  1264. +
  1265. +(define_insn "sibcalli_fdpic"
  1266. + [(call (mem:SI (match_operand:SI 0 "register_operand" "k"))
  1267. + (match_operand 1 "" ""))
  1268. + (use (reg:SI FPSCR_MODES_REG))
  1269. + (use (reg:SI PIC_REG))
  1270. + (return)]
  1271. + "TARGET_SH1 && TARGET_FDPIC"
  1272. "jmp @%0%#"
  1273. [(set_attr "needs_delay_slot" "yes")
  1274. (set (attr "fp_mode")
  1275. @@ -9903,7 +10011,25 @@ label:
  1276. (use (match_operand 2 "" ""))
  1277. (use (reg:SI FPSCR_MODES_REG))
  1278. (return)]
  1279. - "TARGET_SH2"
  1280. + "TARGET_SH2 && !TARGET_FDPIC"
  1281. +{
  1282. + return "braf %0" "\n"
  1283. + "%O2:%#";
  1284. +}
  1285. + [(set_attr "needs_delay_slot" "yes")
  1286. + (set (attr "fp_mode")
  1287. + (if_then_else (eq_attr "fpu_single" "yes")
  1288. + (const_string "single") (const_string "double")))
  1289. + (set_attr "type" "jump_ind")])
  1290. +
  1291. +(define_insn "sibcalli_pcrel_fdpic"
  1292. + [(call (mem:SI (match_operand:SI 0 "arith_reg_operand" "k"))
  1293. + (match_operand 1 "" ""))
  1294. + (use (match_operand 2 "" ""))
  1295. + (use (reg:SI FPSCR_MODES_REG))
  1296. + (use (reg:SI PIC_REG))
  1297. + (return)]
  1298. + "TARGET_SH2 && TARGET_FDPIC"
  1299. {
  1300. return "braf %0" "\n"
  1301. "%O2:%#";
  1302. @@ -9936,7 +10062,7 @@ label:
  1303. (use (reg:SI FPSCR_MODES_REG))
  1304. (clobber (match_scratch:SI 2 "=k"))
  1305. (return)]
  1306. - "TARGET_SH2"
  1307. + "TARGET_SH2 && !TARGET_FDPIC"
  1308. "#"
  1309. "reload_completed"
  1310. [(const_int 0)]
  1311. @@ -9956,6 +10082,33 @@ label:
  1312. (const_string "single") (const_string "double")))
  1313. (set_attr "type" "jump_ind")])
  1314. +(define_insn_and_split "sibcall_pcrel_fdpic"
  1315. + [(call (mem:SI (match_operand:SI 0 "symbol_ref_operand" ""))
  1316. + (match_operand 1 "" ""))
  1317. + (use (reg:SI FPSCR_MODES_REG))
  1318. + (use (reg:SI PIC_REG))
  1319. + (clobber (match_scratch:SI 2 "=k"))
  1320. + (return)]
  1321. + "TARGET_SH2 && TARGET_FDPIC"
  1322. + "#"
  1323. + "reload_completed"
  1324. + [(const_int 0)]
  1325. +{
  1326. + rtx lab = PATTERN (gen_call_site ());
  1327. + rtx call_insn;
  1328. +
  1329. + emit_insn (gen_sym_label2reg (operands[2], operands[0], lab));
  1330. + call_insn = emit_call_insn (gen_sibcalli_pcrel_fdpic (operands[2], operands[1],
  1331. + copy_rtx (lab)));
  1332. + SIBLING_CALL_P (call_insn) = 1;
  1333. + DONE;
  1334. +}
  1335. + [(set_attr "needs_delay_slot" "yes")
  1336. + (set (attr "fp_mode")
  1337. + (if_then_else (eq_attr "fpu_single" "yes")
  1338. + (const_string "single") (const_string "double")))
  1339. + (set_attr "type" "jump_ind")])
  1340. +
  1341. (define_insn "sibcall_compact"
  1342. [(call (mem:SI (match_operand:SI 0 "register_operand" "k,k"))
  1343. (match_operand 1 "" ""))
  1344. @@ -10000,6 +10153,12 @@ label:
  1345. (return)])]
  1346. ""
  1347. {
  1348. + if (TARGET_FDPIC)
  1349. + {
  1350. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  1351. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  1352. + }
  1353. +
  1354. if (TARGET_SHMEDIA)
  1355. {
  1356. operands[0] = shmedia_prepare_call_address (operands[0], 1);
  1357. @@ -10045,7 +10204,8 @@ label:
  1358. emit_insn (gen_force_mode_for_call ());
  1359. operands[0]
  1360. - = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
  1361. + = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1362. + SFUNC_GOT, NULL);
  1363. operands[0] = force_reg (SImode, operands[0]);
  1364. /* We don't need a return trampoline, since the callee will
  1365. @@ -10071,7 +10231,7 @@ label:
  1366. emit_insn (gen_symGOT2reg (reg, XEXP (operands[0], 0)));
  1367. XEXP (operands[0], 0) = reg;
  1368. }
  1369. - if (flag_pic && TARGET_SH2
  1370. + if ((flag_pic || TARGET_FDPIC) && TARGET_SH2
  1371. && MEM_P (operands[0])
  1372. && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF
  1373. /* The PLT needs the PIC register, but the epilogue would have
  1374. @@ -10079,13 +10239,24 @@ label:
  1375. static functions. */
  1376. && SYMBOL_REF_LOCAL_P (XEXP (operands[0], 0)))
  1377. {
  1378. - emit_call_insn (gen_sibcall_pcrel (XEXP (operands[0], 0), operands[1]));
  1379. + if (TARGET_FDPIC)
  1380. + emit_call_insn (gen_sibcall_pcrel_fdpic (XEXP (operands[0], 0),
  1381. + operands[1]));
  1382. + else
  1383. + emit_call_insn (gen_sibcall_pcrel (XEXP (operands[0], 0),
  1384. + operands[1]));
  1385. DONE;
  1386. }
  1387. else
  1388. operands[0] = force_reg (SImode, XEXP (operands[0], 0));
  1389. - emit_call_insn (gen_sibcalli (operands[0], operands[1]));
  1390. + if (TARGET_FDPIC)
  1391. + {
  1392. + operands[0] = sh_load_function_descriptor (operands[0]);
  1393. + emit_call_insn (gen_sibcalli_fdpic (operands[0], operands[1]));
  1394. + }
  1395. + else
  1396. + emit_call_insn (gen_sibcalli (operands[0], operands[1]));
  1397. DONE;
  1398. })
  1399. @@ -10095,7 +10266,22 @@ label:
  1400. (match_operand 2 "" "")))
  1401. (use (reg:SI FPSCR_MODES_REG))
  1402. (return)]
  1403. - "TARGET_SH1"
  1404. + "TARGET_SH1 && !TARGET_FDPIC"
  1405. + "jmp @%1%#"
  1406. + [(set_attr "needs_delay_slot" "yes")
  1407. + (set (attr "fp_mode")
  1408. + (if_then_else (eq_attr "fpu_single" "yes")
  1409. + (const_string "single") (const_string "double")))
  1410. + (set_attr "type" "jump_ind")])
  1411. +
  1412. +(define_insn "sibcall_valuei_fdpic"
  1413. + [(set (match_operand 0 "" "=rf")
  1414. + (call (mem:SI (match_operand:SI 1 "register_operand" "k"))
  1415. + (match_operand 2 "" "")))
  1416. + (use (reg:SI FPSCR_MODES_REG))
  1417. + (use (reg:SI PIC_REG))
  1418. + (return)]
  1419. + "TARGET_SH1 && TARGET_FDPIC"
  1420. "jmp @%1%#"
  1421. [(set_attr "needs_delay_slot" "yes")
  1422. (set (attr "fp_mode")
  1423. @@ -10110,7 +10296,26 @@ label:
  1424. (use (match_operand 3 "" ""))
  1425. (use (reg:SI FPSCR_MODES_REG))
  1426. (return)]
  1427. - "TARGET_SH2"
  1428. + "TARGET_SH2 && !TARGET_FDPIC"
  1429. +{
  1430. + return "braf %1" "\n"
  1431. + "%O3:%#";
  1432. +}
  1433. + [(set_attr "needs_delay_slot" "yes")
  1434. + (set (attr "fp_mode")
  1435. + (if_then_else (eq_attr "fpu_single" "yes")
  1436. + (const_string "single") (const_string "double")))
  1437. + (set_attr "type" "jump_ind")])
  1438. +
  1439. +(define_insn "sibcall_valuei_pcrel_fdpic"
  1440. + [(set (match_operand 0 "" "=rf")
  1441. + (call (mem:SI (match_operand:SI 1 "arith_reg_operand" "k"))
  1442. + (match_operand 2 "" "")))
  1443. + (use (match_operand 3 "" ""))
  1444. + (use (reg:SI FPSCR_MODES_REG))
  1445. + (use (reg:SI PIC_REG))
  1446. + (return)]
  1447. + "TARGET_SH2 && TARGET_FDPIC"
  1448. {
  1449. return "braf %1" "\n"
  1450. "%O3:%#";
  1451. @@ -10128,7 +10333,7 @@ label:
  1452. (use (reg:SI FPSCR_MODES_REG))
  1453. (clobber (match_scratch:SI 3 "=k"))
  1454. (return)]
  1455. - "TARGET_SH2"
  1456. + "TARGET_SH2 && !TARGET_FDPIC"
  1457. "#"
  1458. "reload_completed"
  1459. [(const_int 0)]
  1460. @@ -10141,6 +10346,38 @@ label:
  1461. operands[3],
  1462. operands[2],
  1463. copy_rtx (lab)));
  1464. +
  1465. + SIBLING_CALL_P (call_insn) = 1;
  1466. + DONE;
  1467. +}
  1468. + [(set_attr "needs_delay_slot" "yes")
  1469. + (set (attr "fp_mode")
  1470. + (if_then_else (eq_attr "fpu_single" "yes")
  1471. + (const_string "single") (const_string "double")))
  1472. + (set_attr "type" "jump_ind")])
  1473. +
  1474. +(define_insn_and_split "sibcall_value_pcrel_fdpic"
  1475. + [(set (match_operand 0 "" "=rf")
  1476. + (call (mem:SI (match_operand:SI 1 "symbol_ref_operand" ""))
  1477. + (match_operand 2 "" "")))
  1478. + (use (reg:SI FPSCR_MODES_REG))
  1479. + (use (reg:SI PIC_REG))
  1480. + (clobber (match_scratch:SI 3 "=k"))
  1481. + (return)]
  1482. + "TARGET_SH2 && TARGET_FDPIC"
  1483. + "#"
  1484. + "reload_completed"
  1485. + [(const_int 0)]
  1486. +{
  1487. + rtx lab = PATTERN (gen_call_site ());
  1488. + rtx call_insn;
  1489. +
  1490. + emit_insn (gen_sym_label2reg (operands[3], operands[1], lab));
  1491. + call_insn = emit_call_insn (gen_sibcall_valuei_pcrel_fdpic (operands[0],
  1492. + operands[3],
  1493. + operands[2],
  1494. + copy_rtx (lab)));
  1495. +
  1496. SIBLING_CALL_P (call_insn) = 1;
  1497. DONE;
  1498. }
  1499. @@ -10197,6 +10434,12 @@ label:
  1500. (return)])]
  1501. ""
  1502. {
  1503. + if (TARGET_FDPIC)
  1504. + {
  1505. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  1506. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  1507. + }
  1508. +
  1509. if (TARGET_SHMEDIA)
  1510. {
  1511. operands[1] = shmedia_prepare_call_address (operands[1], 1);
  1512. @@ -10243,7 +10486,8 @@ label:
  1513. emit_insn (gen_force_mode_for_call ());
  1514. operands[1]
  1515. - = function_symbol (NULL, "__GCC_shcompact_call_trampoline", SFUNC_GOT);
  1516. + = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1517. + SFUNC_GOT, NULL);
  1518. operands[1] = force_reg (SImode, operands[1]);
  1519. /* We don't need a return trampoline, since the callee will
  1520. @@ -10270,7 +10514,7 @@ label:
  1521. emit_insn (gen_symGOT2reg (reg, XEXP (operands[1], 0)));
  1522. XEXP (operands[1], 0) = reg;
  1523. }
  1524. - if (flag_pic && TARGET_SH2
  1525. + if ((flag_pic || TARGET_FDPIC) && TARGET_SH2
  1526. && MEM_P (operands[1])
  1527. && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
  1528. /* The PLT needs the PIC register, but the epilogue would have
  1529. @@ -10278,15 +10522,28 @@ label:
  1530. static functions. */
  1531. && SYMBOL_REF_LOCAL_P (XEXP (operands[1], 0)))
  1532. {
  1533. - emit_call_insn (gen_sibcall_value_pcrel (operands[0],
  1534. - XEXP (operands[1], 0),
  1535. - operands[2]));
  1536. + if (TARGET_FDPIC)
  1537. + emit_call_insn (gen_sibcall_value_pcrel_fdpic (operands[0],
  1538. + XEXP (operands[1], 0),
  1539. + operands[2]));
  1540. + else
  1541. + emit_call_insn (gen_sibcall_value_pcrel (operands[0],
  1542. + XEXP (operands[1], 0),
  1543. + operands[2]));
  1544. DONE;
  1545. }
  1546. else
  1547. operands[1] = force_reg (SImode, XEXP (operands[1], 0));
  1548. - emit_call_insn (gen_sibcall_valuei (operands[0], operands[1], operands[2]));
  1549. + if (TARGET_FDPIC)
  1550. + {
  1551. + operands[1] = sh_load_function_descriptor (operands[1]);
  1552. + emit_call_insn (gen_sibcall_valuei_fdpic (operands[0], operands[1],
  1553. + operands[2]));
  1554. + }
  1555. + else
  1556. + emit_call_insn (gen_sibcall_valuei (operands[0], operands[1],
  1557. + operands[2]));
  1558. DONE;
  1559. })
  1560. @@ -10370,7 +10627,7 @@ label:
  1561. emit_insn (gen_force_mode_for_call ());
  1562. operands[1] = function_symbol (NULL, "__GCC_shcompact_call_trampoline",
  1563. - SFUNC_GOT);
  1564. + SFUNC_GOT, NULL);
  1565. operands[1] = force_reg (SImode, operands[1]);
  1566. emit_move_insn (r0, func);
  1567. @@ -10568,6 +10825,13 @@ label:
  1568. DONE;
  1569. }
  1570. + if (TARGET_FDPIC)
  1571. + {
  1572. + rtx pic_reg = gen_rtx_REG (Pmode, PIC_REG);
  1573. + emit_move_insn (pic_reg, OUR_FDPIC_REG);
  1574. + DONE;
  1575. + }
  1576. +
  1577. operands[1] = gen_rtx_REG (Pmode, PIC_REG);
  1578. operands[2] = gen_rtx_SYMBOL_REF (VOIDmode, GOT_SYMBOL_NAME);
  1579. @@ -10700,9 +10964,15 @@ label:
  1580. (set (match_operand 0 "" "") (mem (match_dup 3)))]
  1581. ""
  1582. {
  1583. + rtx picreg;
  1584. rtx mem;
  1585. bool stack_chk_guard_p = false;
  1586. + if (TARGET_FDPIC)
  1587. + picreg = OUR_FDPIC_REG;
  1588. + else
  1589. + picreg = gen_rtx_REG (Pmode, PIC_REG);
  1590. +
  1591. operands[2] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
  1592. operands[3] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
  1593. @@ -10742,11 +11012,11 @@ label:
  1594. insn to avoid combining (set A (plus rX r12)) and (set op0 (mem A))
  1595. when rX is a GOT address for the guard symbol. Ugly but doesn't
  1596. matter because this is a rare situation. */
  1597. +// FIXME: original fdpic patch did not have ssp case here ??
  1598. if (stack_chk_guard_p)
  1599. emit_insn (gen_chk_guard_add (operands[3], operands[2]));
  1600. else
  1601. - emit_move_insn (operands[3], gen_rtx_PLUS (Pmode, operands[2],
  1602. - gen_rtx_REG (Pmode, PIC_REG)));
  1603. + emit_move_insn (operands[3], gen_rtx_PLUS (Pmode, operands[2], picreg));
  1604. /* N.B. This is not constant for a GOTPLT relocation. */
  1605. mem = gen_rtx_MEM (Pmode, operands[3]);
  1606. @@ -10777,6 +11047,26 @@ label:
  1607. DONE;
  1608. })
  1609. +(define_expand "sym2GOTFUNCDESC"
  1610. + [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOTFUNCDESC))]
  1611. + "TARGET_FDPIC"
  1612. + "")
  1613. +
  1614. +(define_expand "symGOTFUNCDESC2reg"
  1615. + [(match_operand 0 "" "") (match_operand 1 "" "")]
  1616. + "TARGET_FDPIC"
  1617. +{
  1618. + rtx gotsym, insn;
  1619. +
  1620. + gotsym = gen_sym2GOTFUNCDESC (operands[1]);
  1621. + PUT_MODE (gotsym, Pmode);
  1622. + insn = emit_insn (gen_symGOT_load (operands[0], gotsym));
  1623. +
  1624. + MEM_READONLY_P (SET_SRC (PATTERN (insn))) = 1;
  1625. +
  1626. + DONE;
  1627. +})
  1628. +
  1629. (define_expand "symGOTPLT2reg"
  1630. [(match_operand 0 "" "") (match_operand 1 "" "")]
  1631. ""
  1632. @@ -10798,23 +11088,49 @@ label:
  1633. [(match_operand 0 "" "") (match_operand 1 "" "")]
  1634. ""
  1635. {
  1636. + rtx picreg;
  1637. rtx gotoffsym, insn;
  1638. rtx t = (!can_create_pseudo_p ()
  1639. ? operands[0]
  1640. : gen_reg_rtx (GET_MODE (operands[0])));
  1641. + if (TARGET_FDPIC)
  1642. + picreg = OUR_FDPIC_REG;
  1643. + else
  1644. + picreg = gen_rtx_REG (Pmode, PIC_REG);
  1645. +
  1646. gotoffsym = gen_sym2GOTOFF (operands[1]);
  1647. PUT_MODE (gotoffsym, Pmode);
  1648. emit_move_insn (t, gotoffsym);
  1649. - insn = emit_move_insn (operands[0],
  1650. - gen_rtx_PLUS (Pmode, t,
  1651. - gen_rtx_REG (Pmode, PIC_REG)));
  1652. + insn = emit_move_insn (operands[0], gen_rtx_PLUS (Pmode, t, picreg));
  1653. set_unique_reg_note (insn, REG_EQUAL, operands[1]);
  1654. DONE;
  1655. })
  1656. +(define_expand "sym2GOTOFFFUNCDESC"
  1657. + [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOTOFFFUNCDESC))]
  1658. + "TARGET_FDPIC"
  1659. + "")
  1660. +
  1661. +(define_expand "symGOTOFFFUNCDESC2reg"
  1662. + [(match_operand 0 "" "") (match_operand 1 "" "")]
  1663. + "TARGET_FDPIC"
  1664. +{
  1665. + rtx picreg = OUR_FDPIC_REG;
  1666. + rtx gotoffsym;
  1667. + rtx t = (!can_create_pseudo_p ()
  1668. + ? operands[0]
  1669. + : gen_reg_rtx (GET_MODE (operands[0])));
  1670. +
  1671. + gotoffsym = gen_sym2GOTOFFFUNCDESC (operands[1]);
  1672. + PUT_MODE (gotoffsym, Pmode);
  1673. + emit_move_insn (t, gotoffsym);
  1674. + emit_move_insn (operands[0], gen_rtx_PLUS (Pmode, t, picreg));
  1675. + DONE;
  1676. +})
  1677. +
  1678. (define_expand "symPLT_label2reg"
  1679. [(set (match_operand:SI 0 "" "")
  1680. (const:SI
  1681. @@ -11491,7 +11807,8 @@ label:
  1682. {
  1683. rtx reg = gen_rtx_REG (Pmode, R0_REG);
  1684. - function_symbol (reg, "__GCC_shcompact_return_trampoline", SFUNC_STATIC);
  1685. + function_symbol (reg, "__GCC_shcompact_return_trampoline", SFUNC_STATIC,
  1686. + NULL);
  1687. emit_jump_insn (gen_shcompact_return_tramp_i ());
  1688. DONE;
  1689. })
  1690. @@ -12581,18 +12898,22 @@ label:
  1691. (define_insn "block_move_real"
  1692. [(parallel [(set (mem:BLK (reg:SI R4_REG))
  1693. (mem:BLK (reg:SI R5_REG)))
  1694. - (use (match_operand:SI 0 "arith_reg_operand" "r"))
  1695. + (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
  1696. + (use (match_operand 1 "" "Z,Ccl"))
  1697. (clobber (reg:SI PR_REG))
  1698. (clobber (reg:SI R0_REG))])]
  1699. "TARGET_SH1 && ! TARGET_HARD_SH4"
  1700. - "jsr @%0%#"
  1701. + "@
  1702. + jsr @%0%#
  1703. + bsrf %0\\n%O1:%#"
  1704. [(set_attr "type" "sfunc")
  1705. (set_attr "needs_delay_slot" "yes")])
  1706. (define_insn "block_lump_real"
  1707. [(parallel [(set (mem:BLK (reg:SI R4_REG))
  1708. (mem:BLK (reg:SI R5_REG)))
  1709. - (use (match_operand:SI 0 "arith_reg_operand" "r"))
  1710. + (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
  1711. + (use (match_operand 1 "" "Z,Ccl"))
  1712. (use (reg:SI R6_REG))
  1713. (clobber (reg:SI PR_REG))
  1714. (clobber (reg:SI T_REG))
  1715. @@ -12601,27 +12922,33 @@ label:
  1716. (clobber (reg:SI R6_REG))
  1717. (clobber (reg:SI R0_REG))])]
  1718. "TARGET_SH1 && ! TARGET_HARD_SH4"
  1719. - "jsr @%0%#"
  1720. + "@
  1721. + jsr @%0%#
  1722. + bsrf %0\\n%O1:%#"
  1723. [(set_attr "type" "sfunc")
  1724. (set_attr "needs_delay_slot" "yes")])
  1725. (define_insn "block_move_real_i4"
  1726. [(parallel [(set (mem:BLK (reg:SI R4_REG))
  1727. (mem:BLK (reg:SI R5_REG)))
  1728. - (use (match_operand:SI 0 "arith_reg_operand" "r"))
  1729. + (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
  1730. + (use (match_operand 1 "" "Z,Ccl"))
  1731. (clobber (reg:SI PR_REG))
  1732. (clobber (reg:SI R0_REG))
  1733. (clobber (reg:SI R1_REG))
  1734. (clobber (reg:SI R2_REG))])]
  1735. "TARGET_HARD_SH4"
  1736. - "jsr @%0%#"
  1737. + "@
  1738. + jsr @%0%#
  1739. + bsrf %0\\n%O1:%#"
  1740. [(set_attr "type" "sfunc")
  1741. (set_attr "needs_delay_slot" "yes")])
  1742. (define_insn "block_lump_real_i4"
  1743. [(parallel [(set (mem:BLK (reg:SI R4_REG))
  1744. (mem:BLK (reg:SI R5_REG)))
  1745. - (use (match_operand:SI 0 "arith_reg_operand" "r"))
  1746. + (use (match_operand:SI 0 "arith_reg_operand" "r,r"))
  1747. + (use (match_operand 1 "" "Z,Ccl"))
  1748. (use (reg:SI R6_REG))
  1749. (clobber (reg:SI PR_REG))
  1750. (clobber (reg:SI T_REG))
  1751. @@ -12633,7 +12960,9 @@ label:
  1752. (clobber (reg:SI R2_REG))
  1753. (clobber (reg:SI R3_REG))])]
  1754. "TARGET_HARD_SH4"
  1755. - "jsr @%0%#"
  1756. + "@
  1757. + jsr @%0%#
  1758. + bsrf %0\\n%O1:%#"
  1759. [(set_attr "type" "sfunc")
  1760. (set_attr "needs_delay_slot" "yes")])
  1761. diff -urp ../baseline/gcc-5.2.0/gcc/config/sh/sh.opt gcc-5.2.0/gcc/config/sh/sh.opt
  1762. --- ../baseline/gcc-5.2.0/gcc/config/sh/sh.opt 2015-09-04 20:23:46.711452245 +0000
  1763. +++ gcc-5.2.0/gcc/config/sh/sh.opt 2015-09-03 21:20:40.109481724 +0000
  1764. @@ -264,6 +264,10 @@ mdivsi3_libfunc=
  1765. Target RejectNegative Joined Var(sh_divsi3_libfunc) Init("")
  1766. Specify name for 32 bit signed division function
  1767. +mfdpic
  1768. +Target Report Var(TARGET_FDPIC)
  1769. +Generate ELF FDPIC code
  1770. +
  1771. mfmovd
  1772. Target RejectNegative Mask(FMOVD)
  1773. Enable the use of 64-bit floating point registers in fmov instructions. See -mdalign if 64-bit alignment is required.
  1774. diff -urp ../baseline/gcc-5.2.0/gcc/config.gcc gcc-5.2.0/gcc/config.gcc
  1775. --- ../baseline/gcc-5.2.0/gcc/config.gcc 2015-09-04 20:23:46.711452245 +0000
  1776. +++ gcc-5.2.0/gcc/config.gcc 2015-09-04 21:38:42.364511457 +0000
  1777. @@ -2580,6 +2580,9 @@ sh-*-elf* | sh[12346l]*-*-elf* | \
  1778. tm_file="${tm_file} dbxelf.h elfos.h sh/elf.h"
  1779. case ${target} in
  1780. sh*-*-linux*) tmake_file="${tmake_file} sh/t-linux"
  1781. + if test x$enable_fdpic = xyes; then
  1782. + tm_defines="$tm_defines FDPIC_DEFAULT=1"
  1783. + fi
  1784. tm_file="${tm_file} gnu-user.h linux.h glibc-stdint.h sh/linux.h" ;;
  1785. sh*-*-netbsd*)
  1786. tm_file="${tm_file} netbsd.h netbsd-elf.h sh/netbsd-elf.h"
  1787. diff -urp ../baseline/gcc-5.2.0/gcc/doc/install.texi gcc-5.2.0/gcc/doc/install.texi
  1788. --- ../baseline/gcc-5.2.0/gcc/doc/install.texi 2015-05-12 08:49:59.000000000 +0000
  1789. +++ gcc-5.2.0/gcc/doc/install.texi 2015-09-04 21:46:28.384483042 +0000
  1790. @@ -1791,6 +1791,9 @@ When neither of these configure options
  1791. 128-bit @code{long double} when built against GNU C Library 2.4 and later,
  1792. 64-bit @code{long double} otherwise.
  1793. +@item --enable-fdpic
  1794. +On SH Linux systems, generate ELF FDPIC code.
  1795. +
  1796. @item --with-gmp=@var{pathname}
  1797. @itemx --with-gmp-include=@var{pathname}
  1798. @itemx --with-gmp-lib=@var{pathname}
  1799. diff -urp ../baseline/gcc-5.2.0/gcc/doc/invoke.texi gcc-5.2.0/gcc/doc/invoke.texi
  1800. --- ../baseline/gcc-5.2.0/gcc/doc/invoke.texi 2015-09-04 20:23:46.568118921 +0000
  1801. +++ gcc-5.2.0/gcc/doc/invoke.texi 2015-09-04 21:44:08.541158234 +0000
  1802. @@ -20921,6 +20921,10 @@ in effect.
  1803. Prefer zero-displacement conditional branches for conditional move instruction
  1804. patterns. This can result in faster code on the SH4 processor.
  1805. +@item -mfdpic
  1806. +@opindex fdpic
  1807. +Generate code using the FDPIC ABI.
  1808. +
  1809. @end table
  1810. @node Solaris 2 Options
  1811. diff -urp ../baseline/gcc-5.2.0/libitm/config/sh/sjlj.S gcc-5.2.0/libitm/config/sh/sjlj.S
  1812. --- ../baseline/gcc-5.2.0/libitm/config/sh/sjlj.S 2015-01-05 12:33:28.000000000 +0000
  1813. +++ gcc-5.2.0/libitm/config/sh/sjlj.S 2015-09-11 04:56:22.272911159 +0000
  1814. @@ -58,9 +58,6 @@ _ITM_beginTransaction:
  1815. jsr @r1
  1816. mov r15, r5
  1817. #else
  1818. - mova .Lgot, r0
  1819. - mov.l .Lgot, r12
  1820. - add r0, r12
  1821. mov.l .Lbegin, r1
  1822. bsrf r1
  1823. mov r15, r5
  1824. @@ -80,13 +77,11 @@ _ITM_beginTransaction:
  1825. cfi_endproc
  1826. .align 2
  1827. -.Lgot:
  1828. - .long _GLOBAL_OFFSET_TABLE_
  1829. .Lbegin:
  1830. #if defined HAVE_ATTRIBUTE_VISIBILITY || !defined __PIC__
  1831. .long GTM_begin_transaction
  1832. #else
  1833. - .long GTM_begin_transaction@PLT-(.Lbegin0-.)
  1834. + .long GTM_begin_transaction@PCREL-(.Lbegin0-.)
  1835. #endif
  1836. .size _ITM_beginTransaction, . - _ITM_beginTransaction