0007-fdpic.diff 68 KB

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