0007-fdpic.diff 64 KB

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