elf32-tilepro.c 110 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770
  1. /* TILEPro-specific support for 32-bit ELF.
  2. Copyright (C) 2011-2022 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include "bfd.h"
  18. #include "libbfd.h"
  19. #include "elf-bfd.h"
  20. #include "elf/tilepro.h"
  21. #include "opcode/tilepro.h"
  22. #include "libiberty.h"
  23. #include "elf32-tilepro.h"
  24. #define TILEPRO_BYTES_PER_WORD 4
  25. static reloc_howto_type tilepro_elf_howto_table [] =
  26. {
  27. /* This reloc does nothing. */
  28. HOWTO (R_TILEPRO_NONE, /* type */
  29. 0, /* rightshift */
  30. 3, /* size (0 = byte, 1 = short, 2 = long) */
  31. 0, /* bitsize */
  32. false, /* pc_relative */
  33. 0, /* bitpos */
  34. complain_overflow_dont, /* complain_on_overflow */
  35. bfd_elf_generic_reloc, /* special_function */
  36. "R_TILEPRO_NONE", /* name */
  37. false, /* partial_inplace */
  38. 0, /* src_mask */
  39. 0, /* dst_mask */
  40. false), /* pcrel_offset */
  41. /* A 32 bit absolute relocation. */
  42. HOWTO (R_TILEPRO_32, /* type */
  43. 0, /* rightshift */
  44. 2, /* size (0 = byte, 1 = short, 2 = long) */
  45. 32, /* bitsize */
  46. false, /* pc_relative */
  47. 0, /* bitpos */
  48. complain_overflow_dont, /* complain_on_overflow */
  49. bfd_elf_generic_reloc, /* special_function */
  50. "R_TILEPRO_32", /* name */
  51. false, /* partial_inplace */
  52. 0, /* src_mask */
  53. 0xffffffff, /* dst_mask */
  54. false), /* pcrel_offset */
  55. /* A 16 bit absolute relocation. */
  56. HOWTO (R_TILEPRO_16, /* type */
  57. 0, /* rightshift */
  58. 1, /* size (0 = byte, 1 = short, 2 = long) */
  59. 16, /* bitsize */
  60. false, /* pc_relative */
  61. 0, /* bitpos */
  62. complain_overflow_bitfield, /* complain_on_overflow */
  63. bfd_elf_generic_reloc, /* special_function */
  64. "R_TILEPRO_16", /* name */
  65. false, /* partial_inplace */
  66. 0, /* src_mask */
  67. 0xffff, /* dst_mask */
  68. false), /* pcrel_offset */
  69. /* An 8 bit absolute relocation. */
  70. HOWTO (R_TILEPRO_8, /* type */
  71. 0, /* rightshift */
  72. 0, /* size (0 = byte, 1 = short, 2 = long) */
  73. 8, /* bitsize */
  74. false, /* pc_relative */
  75. 0, /* bitpos */
  76. complain_overflow_unsigned, /* complain_on_overflow */
  77. bfd_elf_generic_reloc, /* special_function */
  78. "R_TILEPRO_8", /* name */
  79. false, /* partial_inplace */
  80. 0, /* src_mask */
  81. 0xff, /* dst_mask */
  82. false), /* pcrel_offset */
  83. /* A 32 bit pc-relative relocation. */
  84. HOWTO (R_TILEPRO_32_PCREL,/* type */
  85. 0, /* rightshift */
  86. 2, /* size (0 = byte, 1 = short, 2 = long) */
  87. 32, /* bitsize */
  88. true, /* pc_relative */
  89. 0, /* bitpos */
  90. complain_overflow_dont, /* complain_on_overflow */
  91. bfd_elf_generic_reloc, /* special_function */
  92. "R_TILEPRO_32_PCREL", /* name */
  93. false, /* partial_inplace */
  94. 0, /* src_mask */
  95. 0xffffffff, /* dst_mask */
  96. true), /* pcrel_offset */
  97. /* A 16 bit pc-relative relocation. */
  98. HOWTO (R_TILEPRO_16_PCREL,/* type */
  99. 0, /* rightshift */
  100. 1, /* size (0 = byte, 1 = short, 2 = long) */
  101. 16, /* bitsize */
  102. true, /* pc_relative */
  103. 0, /* bitpos */
  104. complain_overflow_signed, /* complain_on_overflow */
  105. bfd_elf_generic_reloc, /* special_function */
  106. "R_TILEPRO_16_PCREL", /* name */
  107. false, /* partial_inplace */
  108. 0, /* src_mask */
  109. 0xffff, /* dst_mask */
  110. true), /* pcrel_offset */
  111. /* An 8 bit pc-relative relocation. */
  112. HOWTO (R_TILEPRO_8_PCREL, /* type */
  113. 0, /* rightshift */
  114. 0, /* size (0 = byte, 1 = short, 2 = long) */
  115. 8, /* bitsize */
  116. true, /* pc_relative */
  117. 0, /* bitpos */
  118. complain_overflow_signed, /* complain_on_overflow */
  119. bfd_elf_generic_reloc, /* special_function */
  120. "R_TILEPRO_8_PCREL",/* name */
  121. false, /* partial_inplace */
  122. 0, /* src_mask */
  123. 0xff, /* dst_mask */
  124. true), /* pcrel_offset */
  125. /* A 16 bit relocation without overflow. */
  126. HOWTO (R_TILEPRO_LO16, /* type */
  127. 0, /* rightshift */
  128. 1, /* size (0 = byte, 1 = short, 2 = long) */
  129. 16, /* bitsize */
  130. false, /* pc_relative */
  131. 0, /* bitpos */
  132. complain_overflow_dont,/* complain_on_overflow */
  133. bfd_elf_generic_reloc, /* special_function */
  134. "R_TILEPRO_LO16", /* name */
  135. false, /* partial_inplace */
  136. 0, /* src_mask */
  137. 0xffff, /* dst_mask */
  138. false), /* pcrel_offset */
  139. /* The high order 16 bits of an address. */
  140. HOWTO (R_TILEPRO_HI16, /* type */
  141. 16, /* rightshift */
  142. 1, /* size (0 = byte, 1 = short, 2 = long) */
  143. 16, /* bitsize */
  144. false, /* pc_relative */
  145. 0, /* bitpos */
  146. complain_overflow_dont, /* complain_on_overflow */
  147. bfd_elf_generic_reloc, /* special_function */
  148. "R_TILEPRO_HI16", /* name */
  149. false, /* partial_inplace */
  150. 0, /* src_mask */
  151. 0xffff, /* dst_mask */
  152. false), /* pcrel_offset */
  153. /* The high order 16 bits of an address, plus 1 if the contents of
  154. the low 16 bits, treated as a signed number, is negative. */
  155. HOWTO (R_TILEPRO_HA16, /* type */
  156. 16, /* rightshift */
  157. 1, /* size (0 = byte, 1 = short, 2 = long) */
  158. 16, /* bitsize */
  159. false, /* pc_relative */
  160. 0, /* bitpos */
  161. complain_overflow_dont, /* complain_on_overflow */
  162. bfd_elf_generic_reloc, /* special_function */
  163. "R_TILEPRO_HA16", /* name */
  164. false, /* partial_inplace */
  165. 0, /* src_mask */
  166. 0xffff, /* dst_mask */
  167. false), /* pcrel_offset */
  168. HOWTO (R_TILEPRO_COPY, /* type */
  169. 0, /* rightshift */
  170. 0, /* size (0 = byte, 1 = short, 2 = long) */
  171. 0, /* bitsize */
  172. false, /* pc_relative */
  173. 0, /* bitpos */
  174. complain_overflow_dont, /* complain_on_overflow */
  175. bfd_elf_generic_reloc, /* special_function */
  176. "R_TILEPRO_COPY", /* name */
  177. false, /* partial_inplace */
  178. 0, /* src_mask */
  179. 0, /* dst_mask */
  180. true), /* pcrel_offset */
  181. HOWTO (R_TILEPRO_GLOB_DAT, /* type */
  182. 0, /* rightshift */
  183. 0, /* size (0 = byte, 1 = short, 2 = long) */
  184. 0, /* bitsize */
  185. false, /* pc_relative */
  186. 0, /* bitpos */
  187. complain_overflow_dont, /* complain_on_overflow */
  188. bfd_elf_generic_reloc, /* special_function */
  189. "R_TILEPRO_GLOB_DAT", /* name */
  190. false, /* partial_inplace */
  191. 0, /* src_mask */
  192. 0, /* dst_mask */
  193. true), /* pcrel_offset */
  194. HOWTO (R_TILEPRO_JMP_SLOT, /* type */
  195. 0, /* rightshift */
  196. 0, /* size (0 = byte, 1 = short, 2 = long) */
  197. 0, /* bitsize */
  198. false, /* pc_relative */
  199. 0, /* bitpos */
  200. complain_overflow_dont, /* complain_on_overflow */
  201. bfd_elf_generic_reloc, /* special_function */
  202. "R_TILEPRO_JMP_SLOT", /* name */
  203. false, /* partial_inplace */
  204. 0, /* src_mask */
  205. 0, /* dst_mask */
  206. true), /* pcrel_offset */
  207. HOWTO (R_TILEPRO_RELATIVE, /* type */
  208. 0, /* rightshift */
  209. 0, /* size (0 = byte, 1 = short, 2 = long) */
  210. 0, /* bitsize */
  211. false, /* pc_relative */
  212. 0, /* bitpos */
  213. complain_overflow_dont, /* complain_on_overflow */
  214. bfd_elf_generic_reloc, /* special_function */
  215. "R_TILEPRO_RELATIVE", /* name */
  216. false, /* partial_inplace */
  217. 0, /* src_mask */
  218. 0, /* dst_mask */
  219. true), /* pcrel_offset */
  220. HOWTO (R_TILEPRO_BROFF_X1, /* type */
  221. TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
  222. 2, /* size (0 = byte, 1 = short, 2 = long) */
  223. 17, /* bitsize */
  224. true, /* pc_relative */
  225. 0, /* bitpos */
  226. complain_overflow_signed, /* complain_on_overflow */
  227. bfd_elf_generic_reloc, /* special_function */
  228. "R_TILEPRO_BROFF_X1", /* name */
  229. false, /* partial_inplace */
  230. 0, /* src_mask */
  231. -1, /* dst_mask */
  232. true), /* pcrel_offset */
  233. HOWTO (R_TILEPRO_JOFFLONG_X1, /* type */
  234. TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
  235. 2, /* size (0 = byte, 1 = short, 2 = long) */
  236. 29, /* bitsize */
  237. true, /* pc_relative */
  238. 0, /* bitpos */
  239. complain_overflow_signed,/* complain_on_overflow */
  240. bfd_elf_generic_reloc, /* special_function */
  241. "R_TILEPRO_JOFFLONG_X1", /* name */
  242. false, /* partial_inplace */
  243. 0, /* src_mask */
  244. -1, /* dst_mask */
  245. true), /* pcrel_offset */
  246. HOWTO (R_TILEPRO_JOFFLONG_X1_PLT, /* type */
  247. TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
  248. 2, /* size (0 = byte, 1 = short, 2 = long) */
  249. 29, /* bitsize */
  250. true, /* pc_relative */
  251. 0, /* bitpos */
  252. complain_overflow_signed,/* complain_on_overflow */
  253. bfd_elf_generic_reloc, /* special_function */
  254. "R_TILEPRO_JOFFLONG_X1_PLT", /* name */
  255. false, /* partial_inplace */
  256. 0, /* src_mask */
  257. -1, /* dst_mask */
  258. true), /* pcrel_offset */
  259. #define TILEPRO_IMM_HOWTO(name, size, bitsize) \
  260. HOWTO (name, 0, size, bitsize, false, 0, \
  261. complain_overflow_signed, bfd_elf_generic_reloc, \
  262. #name, false, 0, -1, false)
  263. #define TILEPRO_UIMM_HOWTO(name, size, bitsize) \
  264. HOWTO (name, 0, size, bitsize, false, 0, \
  265. complain_overflow_unsigned, bfd_elf_generic_reloc, \
  266. #name, false, 0, -1, false)
  267. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_X0, 0, 8),
  268. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_Y0, 0, 8),
  269. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_X1, 0, 8),
  270. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_Y1, 0, 8),
  271. TILEPRO_UIMM_HOWTO(R_TILEPRO_MT_IMM15_X1, 1, 15),
  272. TILEPRO_UIMM_HOWTO(R_TILEPRO_MF_IMM15_X1, 1, 15),
  273. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM16_X0, 1, 16),
  274. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM16_X1, 1, 16),
  275. #define TILEPRO_IMM16_HOWTO(name, rshift) \
  276. HOWTO (name, rshift, 1, 16, false, 0, \
  277. complain_overflow_dont, bfd_elf_generic_reloc, \
  278. #name, false, 0, 0xffff, false)
  279. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_LO, 0),
  280. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_LO, 0),
  281. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_HI, 16),
  282. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_HI, 16),
  283. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_HA, 16),
  284. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_HA, 16),
  285. /* PC-relative offsets. */
  286. HOWTO (R_TILEPRO_IMM16_X0_PCREL, /* type */
  287. 0, /* rightshift */
  288. 1, /* size (0 = byte, 1 = short, 2 = long) */
  289. 16, /* bitsize */
  290. true, /* pc_relative */
  291. 0, /* bitpos */
  292. complain_overflow_signed, /* complain_on_overflow */
  293. bfd_elf_generic_reloc, /* special_function */
  294. "R_TILEPRO_IMM16_X0_PCREL",/* name */
  295. false, /* partial_inplace */
  296. 0, /* src_mask */
  297. -1, /* dst_mask */
  298. true), /* pcrel_offset */
  299. HOWTO (R_TILEPRO_IMM16_X1_PCREL, /* type */
  300. 0, /* rightshift */
  301. 1, /* size (0 = byte, 1 = short, 2 = long) */
  302. 16, /* bitsize */
  303. true, /* pc_relative */
  304. 0, /* bitpos */
  305. complain_overflow_signed, /* complain_on_overflow */
  306. bfd_elf_generic_reloc, /* special_function */
  307. "R_TILEPRO_IMM16_X1_PCREL",/* name */
  308. false, /* partial_inplace */
  309. 0, /* src_mask */
  310. -1, /* dst_mask */
  311. true), /* pcrel_offset */
  312. #define TILEPRO_IMM16_HOWTO_PCREL(name, rshift) \
  313. HOWTO (name, rshift, 1, 16, true, 0, \
  314. complain_overflow_dont, bfd_elf_generic_reloc, \
  315. #name, false, 0, 0xffff, true)
  316. TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X0_LO_PCREL, 0),
  317. TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X1_LO_PCREL, 0),
  318. TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X0_HI_PCREL, 16),
  319. TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X1_HI_PCREL, 16),
  320. TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X0_HA_PCREL, 16),
  321. TILEPRO_IMM16_HOWTO_PCREL (R_TILEPRO_IMM16_X1_HA_PCREL, 16),
  322. /* Byte offset into GOT for a particular symbol. */
  323. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM16_X0_GOT, 1, 16),
  324. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM16_X1_GOT, 1, 16),
  325. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_GOT_LO, 0),
  326. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_GOT_LO, 0),
  327. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_GOT_HI, 16),
  328. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_GOT_HI, 16),
  329. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_GOT_HA, 16),
  330. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_GOT_HA, 16),
  331. TILEPRO_UIMM_HOWTO(R_TILEPRO_MMSTART_X0, 0, 5),
  332. TILEPRO_UIMM_HOWTO(R_TILEPRO_MMEND_X0, 0, 5),
  333. TILEPRO_UIMM_HOWTO(R_TILEPRO_MMSTART_X1, 0, 5),
  334. TILEPRO_UIMM_HOWTO(R_TILEPRO_MMEND_X1, 0, 5),
  335. TILEPRO_UIMM_HOWTO(R_TILEPRO_SHAMT_X0, 0, 5),
  336. TILEPRO_UIMM_HOWTO(R_TILEPRO_SHAMT_X1, 0, 5),
  337. TILEPRO_UIMM_HOWTO(R_TILEPRO_SHAMT_Y0, 0, 5),
  338. TILEPRO_UIMM_HOWTO(R_TILEPRO_SHAMT_Y1, 0, 5),
  339. TILEPRO_IMM_HOWTO(R_TILEPRO_DEST_IMM8_X1, 0, 8),
  340. /* These relocs are currently not defined. */
  341. EMPTY_HOWTO (56),
  342. EMPTY_HOWTO (57),
  343. EMPTY_HOWTO (58),
  344. EMPTY_HOWTO (59),
  345. HOWTO (R_TILEPRO_TLS_GD_CALL, /* type */
  346. TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
  347. 2, /* size (0 = byte, 1 = short, 2 = long) */
  348. 29, /* bitsize */
  349. true, /* pc_relative */
  350. 0, /* bitpos */
  351. complain_overflow_signed,/* complain_on_overflow */
  352. bfd_elf_generic_reloc, /* special_function */
  353. "R_TILEPRO_TLS_GD_CALL", /* name */
  354. false, /* partial_inplace */
  355. 0, /* src_mask */
  356. -1, /* dst_mask */
  357. true), /* pcrel_offset */
  358. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_X0_TLS_GD_ADD, 0, 8),
  359. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_X1_TLS_GD_ADD, 0, 8),
  360. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_Y0_TLS_GD_ADD, 0, 8),
  361. TILEPRO_IMM_HOWTO(R_TILEPRO_IMM8_Y1_TLS_GD_ADD, 0, 8),
  362. TILEPRO_IMM_HOWTO(R_TILEPRO_TLS_IE_LOAD, 0, 8),
  363. /* Offsets into the GOT of TLS Descriptors. */
  364. HOWTO (R_TILEPRO_IMM16_X0_TLS_GD,/* type */
  365. 0, /* rightshift */
  366. 1, /* size (0 = byte, 1 = short, 2 = long) */
  367. 16, /* bitsize */
  368. false, /* pc_relative */
  369. 0, /* bitpos */
  370. complain_overflow_signed, /* complain_on_overflow */
  371. bfd_elf_generic_reloc, /* special_function */
  372. "R_TILEPRO_IMM16_X0_TLS_GD",/* name */
  373. false, /* partial_inplace */
  374. 0, /* src_mask */
  375. 0xffff, /* dst_mask */
  376. false), /* pcrel_offset */
  377. HOWTO (R_TILEPRO_IMM16_X1_TLS_GD,/* type */
  378. 0, /* rightshift */
  379. 1, /* size (0 = byte, 1 = short, 2 = long) */
  380. 16, /* bitsize */
  381. false, /* pc_relative */
  382. 0, /* bitpos */
  383. complain_overflow_signed, /* complain_on_overflow */
  384. bfd_elf_generic_reloc, /* special_function */
  385. "R_TILEPRO_IMM16_X1_TLS_GD",/* name */
  386. false, /* partial_inplace */
  387. 0, /* src_mask */
  388. 0xffff, /* dst_mask */
  389. false), /* pcrel_offset */
  390. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_GD_LO, 0),
  391. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_GD_LO, 0),
  392. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_GD_HI, 16),
  393. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_GD_HI, 16),
  394. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_GD_HA, 16),
  395. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_GD_HA, 16),
  396. /* Offsets into the GOT of TLS Descriptors. */
  397. HOWTO (R_TILEPRO_IMM16_X0_TLS_IE,/* type */
  398. 0, /* rightshift */
  399. 1, /* size (0 = byte, 1 = short, 2 = long) */
  400. 16, /* bitsize */
  401. false, /* pc_relative */
  402. 0, /* bitpos */
  403. complain_overflow_signed, /* complain_on_overflow */
  404. bfd_elf_generic_reloc, /* special_function */
  405. "R_TILEPRO_IMM16_X0_TLS_IE",/* name */
  406. false, /* partial_inplace */
  407. 0, /* src_mask */
  408. -1, /* dst_mask */
  409. true), /* pcrel_offset */
  410. HOWTO (R_TILEPRO_IMM16_X1_TLS_IE,/* type */
  411. 0, /* rightshift */
  412. 1, /* size (0 = byte, 1 = short, 2 = long) */
  413. 16, /* bitsize */
  414. false, /* pc_relative */
  415. 0, /* bitpos */
  416. complain_overflow_signed, /* complain_on_overflow */
  417. bfd_elf_generic_reloc, /* special_function */
  418. "R_TILEPRO_IMM16_X1_TLS_IE",/* name */
  419. false, /* partial_inplace */
  420. 0, /* src_mask */
  421. -1, /* dst_mask */
  422. true), /* pcrel_offset */
  423. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_IE_LO, 0),
  424. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_IE_LO, 0),
  425. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_IE_HI, 16),
  426. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_IE_HI, 16),
  427. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_IE_HA, 16),
  428. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_IE_HA, 16),
  429. /* These are common with the Solaris TLS implementation. */
  430. HOWTO(R_TILEPRO_TLS_DTPMOD32, 0, 0, 0, false, 0, complain_overflow_dont,
  431. bfd_elf_generic_reloc, "R_TILEPRO_TLS_DTPMOD32",
  432. false, 0, 0, true),
  433. HOWTO(R_TILEPRO_TLS_DTPOFF32, 0, 2, 32, false, 0, complain_overflow_bitfield,
  434. bfd_elf_generic_reloc, "R_TILEPRO_TLS_DTPOFF32",
  435. false, 0, 0xFFFFFFFF, true),
  436. HOWTO(R_TILEPRO_TLS_TPOFF32, 0, 0, 0, false, 0, complain_overflow_dont,
  437. bfd_elf_generic_reloc, "R_TILEPRO_TLS_TPOFF32",
  438. false, 0, 0, true),
  439. HOWTO (R_TILEPRO_IMM16_X0_TLS_LE,/* type */
  440. 0, /* rightshift */
  441. 1, /* size (0 = byte, 1 = short, 2 = long) */
  442. 16, /* bitsize */
  443. false, /* pc_relative */
  444. 0, /* bitpos */
  445. complain_overflow_signed, /* complain_on_overflow */
  446. bfd_elf_generic_reloc, /* special_function */
  447. "R_TILEPRO_IMM16_X0_TLS_LE",/* name */
  448. false, /* partial_inplace */
  449. 0, /* src_mask */
  450. -1, /* dst_mask */
  451. true), /* pcrel_offset */
  452. HOWTO (R_TILEPRO_IMM16_X1_TLS_LE,/* type */
  453. 0, /* rightshift */
  454. 1, /* size (0 = byte, 1 = short, 2 = long) */
  455. 16, /* bitsize */
  456. false, /* pc_relative */
  457. 0, /* bitpos */
  458. complain_overflow_signed, /* complain_on_overflow */
  459. bfd_elf_generic_reloc, /* special_function */
  460. "R_TILEPRO_IMM16_X1_TLS_LE",/* name */
  461. false, /* partial_inplace */
  462. 0, /* src_mask */
  463. -1, /* dst_mask */
  464. true), /* pcrel_offset */
  465. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_LE_LO, 0),
  466. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_LE_LO, 0),
  467. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_LE_HI, 16),
  468. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_LE_HI, 16),
  469. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X0_TLS_LE_HA, 16),
  470. TILEPRO_IMM16_HOWTO (R_TILEPRO_IMM16_X1_TLS_LE_HA, 16),
  471. };
  472. static reloc_howto_type tilepro_elf_howto_table2 [] =
  473. {
  474. /* GNU extension to record C++ vtable hierarchy */
  475. HOWTO (R_TILEPRO_GNU_VTINHERIT, /* type */
  476. 0, /* rightshift */
  477. 2, /* size (0 = byte, 1 = short, 2 = long) */
  478. 0, /* bitsize */
  479. false, /* pc_relative */
  480. 0, /* bitpos */
  481. complain_overflow_dont, /* complain_on_overflow */
  482. NULL, /* special_function */
  483. "R_TILEPRO_GNU_VTINHERIT", /* name */
  484. false, /* partial_inplace */
  485. 0, /* src_mask */
  486. 0, /* dst_mask */
  487. false), /* pcrel_offset */
  488. /* GNU extension to record C++ vtable member usage */
  489. HOWTO (R_TILEPRO_GNU_VTENTRY, /* type */
  490. 0, /* rightshift */
  491. 2, /* size (0 = byte, 1 = short, 2 = long) */
  492. 0, /* bitsize */
  493. false, /* pc_relative */
  494. 0, /* bitpos */
  495. complain_overflow_dont, /* complain_on_overflow */
  496. _bfd_elf_rel_vtable_reloc_fn, /* special_function */
  497. "R_TILEPRO_GNU_VTENTRY", /* name */
  498. false, /* partial_inplace */
  499. 0, /* src_mask */
  500. 0, /* dst_mask */
  501. false), /* pcrel_offset */
  502. };
  503. /* Map BFD reloc types to TILEPRO ELF reloc types. */
  504. typedef struct tilepro_reloc_map
  505. {
  506. bfd_reloc_code_real_type bfd_reloc_val;
  507. unsigned int tilepro_reloc_val;
  508. reloc_howto_type * table;
  509. } reloc_map;
  510. static const reloc_map tilepro_reloc_map [] =
  511. {
  512. #define TH_REMAP(bfd, tilepro) \
  513. { bfd, tilepro, tilepro_elf_howto_table },
  514. /* Standard relocations. */
  515. TH_REMAP (BFD_RELOC_NONE, R_TILEPRO_NONE)
  516. TH_REMAP (BFD_RELOC_32, R_TILEPRO_32)
  517. TH_REMAP (BFD_RELOC_16, R_TILEPRO_16)
  518. TH_REMAP (BFD_RELOC_8, R_TILEPRO_8)
  519. TH_REMAP (BFD_RELOC_32_PCREL, R_TILEPRO_32_PCREL)
  520. TH_REMAP (BFD_RELOC_16_PCREL, R_TILEPRO_16_PCREL)
  521. TH_REMAP (BFD_RELOC_8_PCREL, R_TILEPRO_8_PCREL)
  522. TH_REMAP (BFD_RELOC_LO16, R_TILEPRO_LO16)
  523. TH_REMAP (BFD_RELOC_HI16, R_TILEPRO_HI16)
  524. TH_REMAP (BFD_RELOC_HI16_S, R_TILEPRO_HA16)
  525. /* Custom relocations. */
  526. TH_REMAP (BFD_RELOC_TILEPRO_COPY, R_TILEPRO_COPY)
  527. TH_REMAP (BFD_RELOC_TILEPRO_GLOB_DAT, R_TILEPRO_GLOB_DAT)
  528. TH_REMAP (BFD_RELOC_TILEPRO_JMP_SLOT, R_TILEPRO_JMP_SLOT)
  529. TH_REMAP (BFD_RELOC_TILEPRO_RELATIVE, R_TILEPRO_RELATIVE)
  530. TH_REMAP (BFD_RELOC_TILEPRO_BROFF_X1, R_TILEPRO_BROFF_X1)
  531. TH_REMAP (BFD_RELOC_TILEPRO_JOFFLONG_X1, R_TILEPRO_JOFFLONG_X1)
  532. TH_REMAP (BFD_RELOC_TILEPRO_JOFFLONG_X1_PLT, R_TILEPRO_JOFFLONG_X1_PLT)
  533. TH_REMAP (BFD_RELOC_TILEPRO_IMM8_X0, R_TILEPRO_IMM8_X0)
  534. TH_REMAP (BFD_RELOC_TILEPRO_IMM8_Y0, R_TILEPRO_IMM8_Y0)
  535. TH_REMAP (BFD_RELOC_TILEPRO_IMM8_X1, R_TILEPRO_IMM8_X1)
  536. TH_REMAP (BFD_RELOC_TILEPRO_IMM8_Y1, R_TILEPRO_IMM8_Y1)
  537. TH_REMAP (BFD_RELOC_TILEPRO_DEST_IMM8_X1, R_TILEPRO_DEST_IMM8_X1)
  538. TH_REMAP (BFD_RELOC_TILEPRO_MT_IMM15_X1, R_TILEPRO_MT_IMM15_X1)
  539. TH_REMAP (BFD_RELOC_TILEPRO_MF_IMM15_X1, R_TILEPRO_MF_IMM15_X1)
  540. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0, R_TILEPRO_IMM16_X0)
  541. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1, R_TILEPRO_IMM16_X1)
  542. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_LO, R_TILEPRO_IMM16_X0_LO)
  543. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_LO, R_TILEPRO_IMM16_X1_LO)
  544. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_HI, R_TILEPRO_IMM16_X0_HI)
  545. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_HI, R_TILEPRO_IMM16_X1_HI)
  546. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_HA, R_TILEPRO_IMM16_X0_HA)
  547. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_HA, R_TILEPRO_IMM16_X1_HA)
  548. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_PCREL, R_TILEPRO_IMM16_X0_PCREL)
  549. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_PCREL, R_TILEPRO_IMM16_X1_PCREL)
  550. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_LO_PCREL, R_TILEPRO_IMM16_X0_LO_PCREL)
  551. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_LO_PCREL, R_TILEPRO_IMM16_X1_LO_PCREL)
  552. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_HI_PCREL, R_TILEPRO_IMM16_X0_HI_PCREL)
  553. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_HI_PCREL, R_TILEPRO_IMM16_X1_HI_PCREL)
  554. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_HA_PCREL, R_TILEPRO_IMM16_X0_HA_PCREL)
  555. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_HA_PCREL, R_TILEPRO_IMM16_X1_HA_PCREL)
  556. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_GOT, R_TILEPRO_IMM16_X0_GOT)
  557. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_GOT, R_TILEPRO_IMM16_X1_GOT)
  558. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_GOT_LO, R_TILEPRO_IMM16_X0_GOT_LO)
  559. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_GOT_LO, R_TILEPRO_IMM16_X1_GOT_LO)
  560. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_GOT_HI, R_TILEPRO_IMM16_X0_GOT_HI)
  561. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_GOT_HI, R_TILEPRO_IMM16_X1_GOT_HI)
  562. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_GOT_HA, R_TILEPRO_IMM16_X0_GOT_HA)
  563. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_GOT_HA, R_TILEPRO_IMM16_X1_GOT_HA)
  564. TH_REMAP (BFD_RELOC_TILEPRO_MMSTART_X0, R_TILEPRO_MMSTART_X0)
  565. TH_REMAP (BFD_RELOC_TILEPRO_MMEND_X0, R_TILEPRO_MMEND_X0)
  566. TH_REMAP (BFD_RELOC_TILEPRO_MMSTART_X1, R_TILEPRO_MMSTART_X1)
  567. TH_REMAP (BFD_RELOC_TILEPRO_MMEND_X1, R_TILEPRO_MMEND_X1)
  568. TH_REMAP (BFD_RELOC_TILEPRO_SHAMT_X0, R_TILEPRO_SHAMT_X0)
  569. TH_REMAP (BFD_RELOC_TILEPRO_SHAMT_X1, R_TILEPRO_SHAMT_X1)
  570. TH_REMAP (BFD_RELOC_TILEPRO_SHAMT_Y0, R_TILEPRO_SHAMT_Y0)
  571. TH_REMAP (BFD_RELOC_TILEPRO_SHAMT_Y1, R_TILEPRO_SHAMT_Y1)
  572. TH_REMAP (BFD_RELOC_TILEPRO_TLS_GD_CALL, R_TILEPRO_TLS_GD_CALL)
  573. TH_REMAP (BFD_RELOC_TILEPRO_IMM8_X0_TLS_GD_ADD, R_TILEPRO_IMM8_X0_TLS_GD_ADD)
  574. TH_REMAP (BFD_RELOC_TILEPRO_IMM8_X1_TLS_GD_ADD, R_TILEPRO_IMM8_X1_TLS_GD_ADD)
  575. TH_REMAP (BFD_RELOC_TILEPRO_IMM8_Y0_TLS_GD_ADD, R_TILEPRO_IMM8_Y0_TLS_GD_ADD)
  576. TH_REMAP (BFD_RELOC_TILEPRO_IMM8_Y1_TLS_GD_ADD, R_TILEPRO_IMM8_Y1_TLS_GD_ADD)
  577. TH_REMAP (BFD_RELOC_TILEPRO_TLS_IE_LOAD, R_TILEPRO_TLS_IE_LOAD)
  578. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD, R_TILEPRO_IMM16_X0_TLS_GD)
  579. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD, R_TILEPRO_IMM16_X1_TLS_GD)
  580. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_LO, R_TILEPRO_IMM16_X0_TLS_GD_LO)
  581. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_LO, R_TILEPRO_IMM16_X1_TLS_GD_LO)
  582. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_HI, R_TILEPRO_IMM16_X0_TLS_GD_HI)
  583. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_HI, R_TILEPRO_IMM16_X1_TLS_GD_HI)
  584. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_GD_HA, R_TILEPRO_IMM16_X0_TLS_GD_HA)
  585. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_GD_HA, R_TILEPRO_IMM16_X1_TLS_GD_HA)
  586. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE, R_TILEPRO_IMM16_X0_TLS_IE)
  587. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE, R_TILEPRO_IMM16_X1_TLS_IE)
  588. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_LO, R_TILEPRO_IMM16_X0_TLS_IE_LO)
  589. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_LO, R_TILEPRO_IMM16_X1_TLS_IE_LO)
  590. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_HI, R_TILEPRO_IMM16_X0_TLS_IE_HI)
  591. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_HI, R_TILEPRO_IMM16_X1_TLS_IE_HI)
  592. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_IE_HA, R_TILEPRO_IMM16_X0_TLS_IE_HA)
  593. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_IE_HA, R_TILEPRO_IMM16_X1_TLS_IE_HA)
  594. TH_REMAP (BFD_RELOC_TILEPRO_TLS_DTPMOD32, R_TILEPRO_TLS_DTPMOD32)
  595. TH_REMAP (BFD_RELOC_TILEPRO_TLS_DTPOFF32, R_TILEPRO_TLS_DTPOFF32)
  596. TH_REMAP (BFD_RELOC_TILEPRO_TLS_TPOFF32, R_TILEPRO_TLS_TPOFF32)
  597. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE, R_TILEPRO_IMM16_X0_TLS_LE)
  598. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE, R_TILEPRO_IMM16_X1_TLS_LE)
  599. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE_LO, R_TILEPRO_IMM16_X0_TLS_LE_LO)
  600. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE_LO, R_TILEPRO_IMM16_X1_TLS_LE_LO)
  601. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE_HI, R_TILEPRO_IMM16_X0_TLS_LE_HI)
  602. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE_HI, R_TILEPRO_IMM16_X1_TLS_LE_HI)
  603. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X0_TLS_LE_HA, R_TILEPRO_IMM16_X0_TLS_LE_HA)
  604. TH_REMAP (BFD_RELOC_TILEPRO_IMM16_X1_TLS_LE_HA, R_TILEPRO_IMM16_X1_TLS_LE_HA)
  605. #undef TH_REMAP
  606. { BFD_RELOC_VTABLE_INHERIT, R_TILEPRO_GNU_VTINHERIT, tilepro_elf_howto_table2 },
  607. { BFD_RELOC_VTABLE_ENTRY, R_TILEPRO_GNU_VTENTRY, tilepro_elf_howto_table2 },
  608. };
  609. /* TILEPRO ELF linker hash entry. */
  610. struct tilepro_elf_link_hash_entry
  611. {
  612. struct elf_link_hash_entry elf;
  613. #define GOT_UNKNOWN 0
  614. #define GOT_NORMAL 1
  615. #define GOT_TLS_GD 2
  616. #define GOT_TLS_IE 4
  617. unsigned char tls_type;
  618. };
  619. #define tilepro_elf_hash_entry(ent) \
  620. ((struct tilepro_elf_link_hash_entry *)(ent))
  621. struct _bfd_tilepro_elf_obj_tdata
  622. {
  623. struct elf_obj_tdata root;
  624. /* tls_type for each local got entry. */
  625. char *local_got_tls_type;
  626. };
  627. #define _bfd_tilepro_elf_tdata(abfd) \
  628. ((struct _bfd_tilepro_elf_obj_tdata *) (abfd)->tdata.any)
  629. #define _bfd_tilepro_elf_local_got_tls_type(abfd) \
  630. (_bfd_tilepro_elf_tdata (abfd)->local_got_tls_type)
  631. #define is_tilepro_elf(bfd) \
  632. (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
  633. && elf_tdata (bfd) != NULL \
  634. && elf_object_id (bfd) == TILEPRO_ELF_DATA)
  635. /* Allocate TILEPro ELF private object data. */
  636. static bool
  637. tilepro_elf_mkobject (bfd *abfd)
  638. {
  639. return bfd_elf_allocate_object (abfd,
  640. sizeof (struct _bfd_tilepro_elf_obj_tdata),
  641. TILEPRO_ELF_DATA);
  642. }
  643. #include "elf/common.h"
  644. #include "elf/internal.h"
  645. /* Get the Tilepro ELF linker hash table from a link_info structure. */
  646. #define tilepro_elf_hash_table(p) \
  647. ((is_elf_hash_table ((p)->hash) \
  648. && elf_hash_table_id (elf_hash_table (p)) == TILEPRO_ELF_DATA) \
  649. ? (struct elf_link_hash_table *) (p)->hash : NULL)
  650. static reloc_howto_type *
  651. tilepro_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
  652. bfd_reloc_code_real_type code)
  653. {
  654. unsigned int i;
  655. for (i = ARRAY_SIZE (tilepro_reloc_map); i--;)
  656. {
  657. const reloc_map * entry;
  658. entry = tilepro_reloc_map + i;
  659. if (entry->bfd_reloc_val == code)
  660. return entry->table + (entry->tilepro_reloc_val
  661. - entry->table[0].type);
  662. }
  663. return NULL;
  664. }
  665. static reloc_howto_type *
  666. tilepro_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  667. const char *r_name)
  668. {
  669. unsigned int i;
  670. for (i = 0;
  671. i < (sizeof (tilepro_elf_howto_table)
  672. / sizeof (tilepro_elf_howto_table[0]));
  673. i++)
  674. if (tilepro_elf_howto_table[i].name != NULL
  675. && strcasecmp (tilepro_elf_howto_table[i].name, r_name) == 0)
  676. return &tilepro_elf_howto_table[i];
  677. return NULL;
  678. }
  679. /* Set the howto pointer for an TILEPro ELF reloc. */
  680. static bool
  681. tilepro_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
  682. arelent * cache_ptr,
  683. Elf_Internal_Rela * dst)
  684. {
  685. unsigned int r_type = ELF32_R_TYPE (dst->r_info);
  686. if (r_type <= (unsigned int) R_TILEPRO_IMM16_X1_TLS_LE_HA)
  687. cache_ptr->howto = &tilepro_elf_howto_table [r_type];
  688. else if (r_type - R_TILEPRO_GNU_VTINHERIT
  689. <= ((unsigned int) R_TILEPRO_GNU_VTENTRY
  690. - (unsigned int) R_TILEPRO_GNU_VTINHERIT))
  691. cache_ptr->howto
  692. = &tilepro_elf_howto_table2 [r_type - R_TILEPRO_GNU_VTINHERIT];
  693. else
  694. {
  695. /* xgettext:c-format */
  696. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  697. abfd, r_type);
  698. bfd_set_error (bfd_error_bad_value);
  699. return false;
  700. }
  701. return true;
  702. }
  703. typedef tilepro_bundle_bits (*tilepro_create_func)(int);
  704. static const tilepro_create_func reloc_to_create_func[] =
  705. {
  706. /* The first fourteen relocation types don't correspond to operands */
  707. NULL,
  708. NULL,
  709. NULL,
  710. NULL,
  711. NULL,
  712. NULL,
  713. NULL,
  714. NULL,
  715. NULL,
  716. NULL,
  717. NULL,
  718. NULL,
  719. NULL,
  720. NULL,
  721. /* The remaining relocations are used for immediate operands */
  722. create_BrOff_X1,
  723. create_JOffLong_X1,
  724. create_JOffLong_X1,
  725. create_Imm8_X0,
  726. create_Imm8_Y0,
  727. create_Imm8_X1,
  728. create_Imm8_Y1,
  729. create_MT_Imm15_X1,
  730. create_MF_Imm15_X1,
  731. create_Imm16_X0,
  732. create_Imm16_X1,
  733. create_Imm16_X0,
  734. create_Imm16_X1,
  735. create_Imm16_X0,
  736. create_Imm16_X1,
  737. create_Imm16_X0,
  738. create_Imm16_X1,
  739. create_Imm16_X0,
  740. create_Imm16_X1,
  741. create_Imm16_X0,
  742. create_Imm16_X1,
  743. create_Imm16_X0,
  744. create_Imm16_X1,
  745. create_Imm16_X0,
  746. create_Imm16_X1,
  747. create_Imm16_X0,
  748. create_Imm16_X1,
  749. create_Imm16_X0,
  750. create_Imm16_X1,
  751. create_Imm16_X0,
  752. create_Imm16_X1,
  753. create_Imm16_X0,
  754. create_Imm16_X1,
  755. create_MMStart_X0,
  756. create_MMEnd_X0,
  757. create_MMStart_X1,
  758. create_MMEnd_X1,
  759. create_ShAmt_X0,
  760. create_ShAmt_X1,
  761. create_ShAmt_Y0,
  762. create_ShAmt_Y1,
  763. create_Dest_Imm8_X1,
  764. NULL,
  765. NULL,
  766. NULL,
  767. NULL,
  768. NULL,
  769. NULL,
  770. NULL,
  771. NULL,
  772. NULL,
  773. NULL,
  774. create_Imm16_X0,
  775. create_Imm16_X1,
  776. create_Imm16_X0,
  777. create_Imm16_X1,
  778. create_Imm16_X0,
  779. create_Imm16_X1,
  780. create_Imm16_X0,
  781. create_Imm16_X1,
  782. create_Imm16_X0,
  783. create_Imm16_X1,
  784. create_Imm16_X0,
  785. create_Imm16_X1,
  786. create_Imm16_X0,
  787. create_Imm16_X1,
  788. create_Imm16_X0,
  789. create_Imm16_X1,
  790. NULL,
  791. NULL,
  792. NULL,
  793. create_Imm16_X0,
  794. create_Imm16_X1,
  795. create_Imm16_X0,
  796. create_Imm16_X1,
  797. create_Imm16_X0,
  798. create_Imm16_X1,
  799. create_Imm16_X0,
  800. create_Imm16_X1,
  801. };
  802. #define NELEMS(a) ((int) (sizeof (a) / sizeof ((a)[0])))
  803. /* Support for core dump NOTE sections. */
  804. static bool
  805. tilepro_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
  806. {
  807. int offset;
  808. size_t size;
  809. if (note->descsz != TILEPRO_PRSTATUS_SIZEOF)
  810. return false;
  811. /* pr_cursig */
  812. elf_tdata (abfd)->core->signal =
  813. bfd_get_16 (abfd, note->descdata + TILEPRO_PRSTATUS_OFFSET_PR_CURSIG);
  814. /* pr_pid */
  815. elf_tdata (abfd)->core->pid =
  816. bfd_get_32 (abfd, note->descdata + TILEPRO_PRSTATUS_OFFSET_PR_PID);
  817. /* pr_reg */
  818. offset = TILEPRO_PRSTATUS_OFFSET_PR_REG;
  819. size = TILEPRO_GREGSET_T_SIZE;
  820. /* Make a ".reg/999" section. */
  821. return _bfd_elfcore_make_pseudosection (abfd, ".reg",
  822. size, note->descpos + offset);
  823. }
  824. static bool
  825. tilepro_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
  826. {
  827. if (note->descsz != TILEPRO_PRPSINFO_SIZEOF)
  828. return false;
  829. elf_tdata (abfd)->core->program
  830. = _bfd_elfcore_strndup (abfd,
  831. note->descdata + TILEPRO_PRPSINFO_OFFSET_PR_FNAME,
  832. 16);
  833. elf_tdata (abfd)->core->command
  834. = _bfd_elfcore_strndup (abfd,
  835. note->descdata + TILEPRO_PRPSINFO_OFFSET_PR_PSARGS,
  836. ELF_PR_PSARGS_SIZE);
  837. /* Note that for some reason, a spurious space is tacked
  838. onto the end of the args in some (at least one anyway)
  839. implementations, so strip it off if it exists. */
  840. {
  841. char *command = elf_tdata (abfd)->core->command;
  842. int n = strlen (command);
  843. if (0 < n && command[n - 1] == ' ')
  844. command[n - 1] = '\0';
  845. }
  846. return true;
  847. }
  848. static void
  849. tilepro_elf_append_rela_32 (bfd *abfd, asection *s, Elf_Internal_Rela *rel)
  850. {
  851. Elf32_External_Rela *loc32;
  852. loc32 = (Elf32_External_Rela *) s->contents;
  853. loc32 += s->reloc_count++;
  854. bfd_elf32_swap_reloca_out (abfd, rel, (bfd_byte *) loc32);
  855. }
  856. /* PLT/GOT stuff */
  857. /* The procedure linkage table starts with the following header:
  858. {
  859. rli r29, r29, 16
  860. lwadd r28, r27, 4
  861. }
  862. lw r27, r27
  863. {
  864. info 10 ## SP not offset, return PC in LR
  865. jr r27
  866. }
  867. Subsequent entries are the following, jumping to the header at the end:
  868. lnk r28
  869. 1:
  870. {
  871. auli r28, r28, <_GLOBAL_OFFSET_TABLE_ - 1b + MY_GOT_OFFSET>
  872. auli r27, r28, <_GLOBAL_OFFSET_TABLE_ - 1b>
  873. }
  874. {
  875. addli r28, r28, <_GLOBAL_OFFSET_TABLE_ - 1b + MY_GOT_OFFSET>
  876. addli r27, r27, <_GLOBAL_OFFSET_TABLE_ - 1b>
  877. }
  878. {
  879. auli r29, zero, MY_PLT_INDEX
  880. lw r28, r28
  881. }
  882. {
  883. info 10 ## SP not offset, return PC in LR
  884. jr r28
  885. }
  886. We initially store MY_PLT_INDEX in the high bits so that we can use the all
  887. 16 bits as an unsigned offset; if we use the low bits we would get an
  888. unwanted sign extension. The PLT header then rotates the index to get the
  889. right value, before calling the resolution routine. This computation can
  890. fit in unused bundle slots so it's free.
  891. This code sequence lets the code at at the start of the PLT determine
  892. which PLT entry was executed by examining 'r29'.
  893. Note that MY_PLT_INDEX skips over the header entries, so the first
  894. actual jump table entry has index zero.
  895. */
  896. #define PLT_HEADER_SIZE_IN_BUNDLES 3
  897. #define PLT_ENTRY_SIZE_IN_BUNDLES 5
  898. #define PLT_HEADER_SIZE \
  899. (PLT_HEADER_SIZE_IN_BUNDLES * TILEPRO_BUNDLE_SIZE_IN_BYTES)
  900. #define PLT_ENTRY_SIZE \
  901. (PLT_ENTRY_SIZE_IN_BUNDLES * TILEPRO_BUNDLE_SIZE_IN_BYTES)
  902. /* The size in bytes of an entry in the global offset table. */
  903. #define GOT_ENTRY_SIZE TILEPRO_BYTES_PER_WORD
  904. #define GOTPLT_HEADER_SIZE (2 * GOT_ENTRY_SIZE)
  905. static const bfd_byte
  906. tilepro_plt0_entry[PLT_HEADER_SIZE] =
  907. {
  908. 0x5d, 0x07, 0x03, 0x70,
  909. 0x6e, 0x23, 0xd0, 0x30, /* { rli r29, r29, 16 ; lwadd r28, r27, 4 } */
  910. 0x00, 0x50, 0xba, 0x6d,
  911. 0x00, 0x08, 0x6d, 0xdc, /* { lw r27, r27 } */
  912. 0xff, 0xaf, 0x10, 0x50,
  913. 0x60, 0x03, 0x18, 0x08, /* { info 10 ; jr r27 } */
  914. };
  915. static const bfd_byte
  916. tilepro_short_plt_entry[PLT_ENTRY_SIZE] =
  917. {
  918. 0x00, 0x50, 0x16, 0x70,
  919. 0x0e, 0x00, 0x1a, 0x08, /* { lnk r28 } */
  920. 0x1c, 0x07, 0x00, 0xa0,
  921. 0x8d, 0x03, 0x00, 0x18, /* { addli r28, r28, 0 ; addli r27, r28, 0 } */
  922. 0xdd, 0x0f, 0x00, 0x30,
  923. 0x8e, 0x73, 0x0b, 0x40, /* { auli r29, zero, 0 ; lw r28, r28 } */
  924. 0xff, 0xaf, 0x10, 0x50,
  925. 0x80, 0x03, 0x18, 0x08, /* { info 10 ; jr r28 } */
  926. 0x00, 0x00, 0x00, 0x00,
  927. 0x00, 0x00, 0x00, 0x00,
  928. };
  929. static const bfd_byte
  930. tilepro_long_plt_entry[PLT_ENTRY_SIZE] =
  931. {
  932. 0x00, 0x50, 0x16, 0x70,
  933. 0x0e, 0x00, 0x1a, 0x08, /* { lnk r28 } */
  934. 0x1c, 0x07, 0x00, 0xb0,
  935. 0x8d, 0x03, 0x00, 0x20, /* { auli r28, r28, 0 ; auli r27, r28, 0 } */
  936. 0x1c, 0x07, 0x00, 0xa0,
  937. 0x6d, 0x03, 0x00, 0x18, /* { addli r28, r28, 0 ; addli r27, r27, 0 } */
  938. 0xdd, 0x0f, 0x00, 0x30,
  939. 0x8e, 0x73, 0x0b, 0x40, /* { auli r29, zero, 0 ; lw r28, r28 } */
  940. 0xff, 0xaf, 0x10, 0x50,
  941. 0x80, 0x03, 0x18, 0x08, /* { info 10 ; jr r28 } */
  942. };
  943. static bfd_vma
  944. tilepro_ha16(bfd_vma vma)
  945. {
  946. return ((vma >> 16) + ((vma >> 15) & 1)) & 0xffff;
  947. }
  948. static int
  949. tilepro_plt_entry_build (asection *splt, asection *sgotplt, bfd_vma offset,
  950. bfd_vma *r_offset)
  951. {
  952. int plt_index = (offset - PLT_ENTRY_SIZE) / PLT_ENTRY_SIZE;
  953. int got_offset = plt_index * GOT_ENTRY_SIZE + GOTPLT_HEADER_SIZE;
  954. tilepro_bundle_bits *pc;
  955. /* Compute the distance from the got entry to the lnk. */
  956. bfd_signed_vma dist_got_entry = sgotplt->output_section->vma
  957. + sgotplt->output_offset
  958. + got_offset
  959. - splt->output_section->vma
  960. - splt->output_offset
  961. - offset
  962. - TILEPRO_BUNDLE_SIZE_IN_BYTES;
  963. /* Compute the distance to GOTPLT[0]. */
  964. bfd_signed_vma dist_got0 = dist_got_entry - got_offset;
  965. /* Check whether we can use the short plt entry with 16-bit offset. */
  966. bool short_plt_entry =
  967. (dist_got_entry <= 0x7fff && dist_got0 >= -0x8000);
  968. /* Copy the plt entry template. */
  969. memcpy (splt->contents + offset,
  970. short_plt_entry ? tilepro_short_plt_entry : tilepro_long_plt_entry,
  971. PLT_ENTRY_SIZE);
  972. /* Write the immediate offsets. */
  973. pc = (tilepro_bundle_bits *)(splt->contents + offset);
  974. pc++;
  975. if (!short_plt_entry)
  976. {
  977. /* { auli r28, r28, &GOTPLT[MY_GOT_INDEX] ; auli r27, r28, &GOTPLT[0] } */
  978. *pc++ |= create_Imm16_X0 (tilepro_ha16 (dist_got_entry))
  979. | create_Imm16_X1 (tilepro_ha16 (dist_got0));
  980. }
  981. /* { addli r28, r28, &GOTPLT[MY_GOT_INDEX] ; addli r27, r28, &GOTPLT[0] } or
  982. { addli r28, r28, &GOTPLT[MY_GOT_INDEX] ; addli r27, r27, &GOTPLT[0] } */
  983. *pc++ |= create_Imm16_X0 (dist_got_entry)
  984. | create_Imm16_X1 (dist_got0);
  985. /* { auli r29, zero, MY_PLT_INDEX ; lw r28, r28 } */
  986. *pc |= create_Imm16_X0 (plt_index);
  987. /* Set the relocation offset. */
  988. *r_offset = got_offset;
  989. return plt_index;
  990. }
  991. #define TILEPRO_ELF_RELA_BYTES (sizeof(Elf32_External_Rela))
  992. /* Create an entry in an TILEPro ELF linker hash table. */
  993. static struct bfd_hash_entry *
  994. link_hash_newfunc (struct bfd_hash_entry *entry,
  995. struct bfd_hash_table *table, const char *string)
  996. {
  997. /* Allocate the structure if it has not already been allocated by a
  998. subclass. */
  999. if (entry == NULL)
  1000. {
  1001. entry =
  1002. bfd_hash_allocate (table,
  1003. sizeof (struct tilepro_elf_link_hash_entry));
  1004. if (entry == NULL)
  1005. return entry;
  1006. }
  1007. /* Call the allocation method of the superclass. */
  1008. entry = _bfd_elf_link_hash_newfunc (entry, table, string);
  1009. if (entry != NULL)
  1010. {
  1011. struct tilepro_elf_link_hash_entry *eh;
  1012. eh = (struct tilepro_elf_link_hash_entry *) entry;
  1013. eh->tls_type = GOT_UNKNOWN;
  1014. }
  1015. return entry;
  1016. }
  1017. /* Create a TILEPRO ELF linker hash table. */
  1018. static struct bfd_link_hash_table *
  1019. tilepro_elf_link_hash_table_create (bfd *abfd)
  1020. {
  1021. struct elf_link_hash_table *ret;
  1022. size_t amt = sizeof (struct elf_link_hash_table);
  1023. ret = (struct elf_link_hash_table *) bfd_zmalloc (amt);
  1024. if (ret == NULL)
  1025. return NULL;
  1026. if (!_bfd_elf_link_hash_table_init (ret, abfd, link_hash_newfunc,
  1027. sizeof (struct tilepro_elf_link_hash_entry),
  1028. TILEPRO_ELF_DATA))
  1029. {
  1030. free (ret);
  1031. return NULL;
  1032. }
  1033. return &ret->root;
  1034. }
  1035. /* Create the .got section. */
  1036. static bool
  1037. tilepro_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
  1038. {
  1039. flagword flags;
  1040. asection *s, *s_got;
  1041. struct elf_link_hash_entry *h;
  1042. const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  1043. struct elf_link_hash_table *htab = elf_hash_table (info);
  1044. /* This function may be called more than once. */
  1045. if (htab->sgot != NULL)
  1046. return true;
  1047. flags = bed->dynamic_sec_flags;
  1048. s = bfd_make_section_with_flags (abfd,
  1049. (bed->rela_plts_and_copies_p
  1050. ? ".rela.got" : ".rel.got"),
  1051. (bed->dynamic_sec_flags
  1052. | SEC_READONLY));
  1053. if (s == NULL
  1054. || !bfd_set_section_alignment (s, bed->s->log_file_align))
  1055. return false;
  1056. htab->srelgot = s;
  1057. s = s_got = bfd_make_section_with_flags (abfd, ".got", flags);
  1058. if (s == NULL
  1059. || !bfd_set_section_alignment (s, bed->s->log_file_align))
  1060. return false;
  1061. htab->sgot = s;
  1062. /* The first bit of the global offset table is the header. */
  1063. s->size += bed->got_header_size;
  1064. if (bed->want_got_plt)
  1065. {
  1066. s = bfd_make_section_with_flags (abfd, ".got.plt", flags);
  1067. if (s == NULL
  1068. || !bfd_set_section_alignment (s, bed->s->log_file_align))
  1069. return false;
  1070. htab->sgotplt = s;
  1071. /* Reserve room for the header. */
  1072. s->size += GOTPLT_HEADER_SIZE;
  1073. }
  1074. if (bed->want_got_sym)
  1075. {
  1076. /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
  1077. section. We don't do this in the linker script because we don't want
  1078. to define the symbol if we are not creating a global offset
  1079. table. */
  1080. h = _bfd_elf_define_linkage_sym (abfd, info, s_got,
  1081. "_GLOBAL_OFFSET_TABLE_");
  1082. elf_hash_table (info)->hgot = h;
  1083. if (h == NULL)
  1084. return false;
  1085. }
  1086. return true;
  1087. }
  1088. /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
  1089. .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
  1090. hash table. */
  1091. static bool
  1092. tilepro_elf_create_dynamic_sections (bfd *dynobj,
  1093. struct bfd_link_info *info)
  1094. {
  1095. if (!tilepro_elf_create_got_section (dynobj, info))
  1096. return false;
  1097. return _bfd_elf_create_dynamic_sections (dynobj, info);
  1098. }
  1099. /* Copy the extra info we tack onto an elf_link_hash_entry. */
  1100. static void
  1101. tilepro_elf_copy_indirect_symbol (struct bfd_link_info *info,
  1102. struct elf_link_hash_entry *dir,
  1103. struct elf_link_hash_entry *ind)
  1104. {
  1105. struct tilepro_elf_link_hash_entry *edir, *eind;
  1106. edir = (struct tilepro_elf_link_hash_entry *) dir;
  1107. eind = (struct tilepro_elf_link_hash_entry *) ind;
  1108. if (ind->root.type == bfd_link_hash_indirect
  1109. && dir->got.refcount <= 0)
  1110. {
  1111. edir->tls_type = eind->tls_type;
  1112. eind->tls_type = GOT_UNKNOWN;
  1113. }
  1114. _bfd_elf_link_hash_copy_indirect (info, dir, ind);
  1115. }
  1116. static int
  1117. tilepro_tls_translate_to_le (int r_type)
  1118. {
  1119. switch (r_type)
  1120. {
  1121. case R_TILEPRO_IMM16_X0_TLS_GD:
  1122. case R_TILEPRO_IMM16_X0_TLS_IE:
  1123. return R_TILEPRO_IMM16_X0_TLS_LE;
  1124. case R_TILEPRO_IMM16_X1_TLS_GD:
  1125. case R_TILEPRO_IMM16_X1_TLS_IE:
  1126. return R_TILEPRO_IMM16_X1_TLS_LE;
  1127. case R_TILEPRO_IMM16_X0_TLS_GD_LO:
  1128. case R_TILEPRO_IMM16_X0_TLS_IE_LO:
  1129. return R_TILEPRO_IMM16_X0_TLS_LE_LO;
  1130. case R_TILEPRO_IMM16_X1_TLS_GD_LO:
  1131. case R_TILEPRO_IMM16_X1_TLS_IE_LO:
  1132. return R_TILEPRO_IMM16_X1_TLS_LE_LO;
  1133. case R_TILEPRO_IMM16_X0_TLS_GD_HI:
  1134. case R_TILEPRO_IMM16_X0_TLS_IE_HI:
  1135. return R_TILEPRO_IMM16_X0_TLS_LE_HI;
  1136. case R_TILEPRO_IMM16_X1_TLS_GD_HI:
  1137. case R_TILEPRO_IMM16_X1_TLS_IE_HI:
  1138. return R_TILEPRO_IMM16_X1_TLS_LE_HI;
  1139. case R_TILEPRO_IMM16_X0_TLS_GD_HA:
  1140. case R_TILEPRO_IMM16_X0_TLS_IE_HA:
  1141. return R_TILEPRO_IMM16_X0_TLS_LE_HA;
  1142. case R_TILEPRO_IMM16_X1_TLS_GD_HA:
  1143. case R_TILEPRO_IMM16_X1_TLS_IE_HA:
  1144. return R_TILEPRO_IMM16_X1_TLS_LE_HA;
  1145. }
  1146. return r_type;
  1147. }
  1148. static int
  1149. tilepro_tls_translate_to_ie (int r_type)
  1150. {
  1151. switch (r_type)
  1152. {
  1153. case R_TILEPRO_IMM16_X0_TLS_GD:
  1154. case R_TILEPRO_IMM16_X0_TLS_IE:
  1155. return R_TILEPRO_IMM16_X0_TLS_IE;
  1156. case R_TILEPRO_IMM16_X1_TLS_GD:
  1157. case R_TILEPRO_IMM16_X1_TLS_IE:
  1158. return R_TILEPRO_IMM16_X1_TLS_IE;
  1159. case R_TILEPRO_IMM16_X0_TLS_GD_LO:
  1160. case R_TILEPRO_IMM16_X0_TLS_IE_LO:
  1161. return R_TILEPRO_IMM16_X0_TLS_IE_LO;
  1162. case R_TILEPRO_IMM16_X1_TLS_GD_LO:
  1163. case R_TILEPRO_IMM16_X1_TLS_IE_LO:
  1164. return R_TILEPRO_IMM16_X1_TLS_IE_LO;
  1165. case R_TILEPRO_IMM16_X0_TLS_GD_HI:
  1166. case R_TILEPRO_IMM16_X0_TLS_IE_HI:
  1167. return R_TILEPRO_IMM16_X0_TLS_IE_HI;
  1168. case R_TILEPRO_IMM16_X1_TLS_GD_HI:
  1169. case R_TILEPRO_IMM16_X1_TLS_IE_HI:
  1170. return R_TILEPRO_IMM16_X1_TLS_IE_HI;
  1171. case R_TILEPRO_IMM16_X0_TLS_GD_HA:
  1172. case R_TILEPRO_IMM16_X0_TLS_IE_HA:
  1173. return R_TILEPRO_IMM16_X0_TLS_IE_HA;
  1174. case R_TILEPRO_IMM16_X1_TLS_GD_HA:
  1175. case R_TILEPRO_IMM16_X1_TLS_IE_HA:
  1176. return R_TILEPRO_IMM16_X1_TLS_IE_HA;
  1177. }
  1178. return r_type;
  1179. }
  1180. static int
  1181. tilepro_elf_tls_transition (struct bfd_link_info *info, int r_type,
  1182. int is_local)
  1183. {
  1184. if (!bfd_link_executable (info))
  1185. return r_type;
  1186. if (is_local)
  1187. return tilepro_tls_translate_to_le (r_type);
  1188. else
  1189. return tilepro_tls_translate_to_ie (r_type);
  1190. }
  1191. /* Look through the relocs for a section during the first phase, and
  1192. allocate space in the global offset table or procedure linkage
  1193. table. */
  1194. static bool
  1195. tilepro_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
  1196. asection *sec, const Elf_Internal_Rela *relocs)
  1197. {
  1198. struct elf_link_hash_table *htab;
  1199. Elf_Internal_Shdr *symtab_hdr;
  1200. struct elf_link_hash_entry **sym_hashes;
  1201. const Elf_Internal_Rela *rel;
  1202. const Elf_Internal_Rela *rel_end;
  1203. asection *sreloc;
  1204. int num_relocs;
  1205. if (bfd_link_relocatable (info))
  1206. return true;
  1207. htab = tilepro_elf_hash_table (info);
  1208. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  1209. sym_hashes = elf_sym_hashes (abfd);
  1210. sreloc = NULL;
  1211. num_relocs = sec->reloc_count;
  1212. BFD_ASSERT (is_tilepro_elf (abfd) || num_relocs == 0);
  1213. if (htab->dynobj == NULL)
  1214. htab->dynobj = abfd;
  1215. rel_end = relocs + num_relocs;
  1216. for (rel = relocs; rel < rel_end; rel++)
  1217. {
  1218. unsigned int r_type;
  1219. unsigned int r_symndx;
  1220. struct elf_link_hash_entry *h;
  1221. int tls_type;
  1222. r_symndx = ELF32_R_SYM (rel->r_info);
  1223. r_type = ELF32_R_TYPE (rel->r_info);
  1224. if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
  1225. {
  1226. /* xgettext:c-format */
  1227. _bfd_error_handler (_("%pB: bad symbol index: %d"),
  1228. abfd, r_symndx);
  1229. return false;
  1230. }
  1231. if (r_symndx < symtab_hdr->sh_info)
  1232. h = NULL;
  1233. else
  1234. {
  1235. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  1236. while (h->root.type == bfd_link_hash_indirect
  1237. || h->root.type == bfd_link_hash_warning)
  1238. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1239. }
  1240. r_type = tilepro_elf_tls_transition (info, r_type, h == NULL);
  1241. switch (r_type)
  1242. {
  1243. case R_TILEPRO_IMM16_X0_TLS_LE:
  1244. case R_TILEPRO_IMM16_X1_TLS_LE:
  1245. case R_TILEPRO_IMM16_X0_TLS_LE_LO:
  1246. case R_TILEPRO_IMM16_X1_TLS_LE_LO:
  1247. case R_TILEPRO_IMM16_X0_TLS_LE_HI:
  1248. case R_TILEPRO_IMM16_X1_TLS_LE_HI:
  1249. case R_TILEPRO_IMM16_X0_TLS_LE_HA:
  1250. case R_TILEPRO_IMM16_X1_TLS_LE_HA:
  1251. if (!bfd_link_executable (info))
  1252. goto r_tilepro_plt32;
  1253. break;
  1254. case R_TILEPRO_IMM16_X0_TLS_GD:
  1255. case R_TILEPRO_IMM16_X1_TLS_GD:
  1256. case R_TILEPRO_IMM16_X0_TLS_GD_LO:
  1257. case R_TILEPRO_IMM16_X1_TLS_GD_LO:
  1258. case R_TILEPRO_IMM16_X0_TLS_GD_HI:
  1259. case R_TILEPRO_IMM16_X1_TLS_GD_HI:
  1260. case R_TILEPRO_IMM16_X0_TLS_GD_HA:
  1261. case R_TILEPRO_IMM16_X1_TLS_GD_HA:
  1262. BFD_ASSERT (bfd_link_pic (info));
  1263. tls_type = GOT_TLS_GD;
  1264. goto have_got_reference;
  1265. case R_TILEPRO_IMM16_X0_TLS_IE:
  1266. case R_TILEPRO_IMM16_X1_TLS_IE:
  1267. case R_TILEPRO_IMM16_X0_TLS_IE_LO:
  1268. case R_TILEPRO_IMM16_X1_TLS_IE_LO:
  1269. case R_TILEPRO_IMM16_X0_TLS_IE_HI:
  1270. case R_TILEPRO_IMM16_X1_TLS_IE_HI:
  1271. case R_TILEPRO_IMM16_X0_TLS_IE_HA:
  1272. case R_TILEPRO_IMM16_X1_TLS_IE_HA:
  1273. tls_type = GOT_TLS_IE;
  1274. if (!bfd_link_executable (info))
  1275. info->flags |= DF_STATIC_TLS;
  1276. goto have_got_reference;
  1277. case R_TILEPRO_IMM16_X0_GOT:
  1278. case R_TILEPRO_IMM16_X1_GOT:
  1279. case R_TILEPRO_IMM16_X0_GOT_LO:
  1280. case R_TILEPRO_IMM16_X1_GOT_LO:
  1281. case R_TILEPRO_IMM16_X0_GOT_HI:
  1282. case R_TILEPRO_IMM16_X1_GOT_HI:
  1283. case R_TILEPRO_IMM16_X0_GOT_HA:
  1284. case R_TILEPRO_IMM16_X1_GOT_HA:
  1285. tls_type = GOT_NORMAL;
  1286. /* Fall Through */
  1287. have_got_reference:
  1288. /* This symbol requires a global offset table entry. */
  1289. {
  1290. int old_tls_type;
  1291. if (h != NULL)
  1292. {
  1293. h->got.refcount += 1;
  1294. old_tls_type = tilepro_elf_hash_entry(h)->tls_type;
  1295. }
  1296. else
  1297. {
  1298. bfd_signed_vma *local_got_refcounts;
  1299. /* This is a global offset table entry for a local symbol. */
  1300. local_got_refcounts = elf_local_got_refcounts (abfd);
  1301. if (local_got_refcounts == NULL)
  1302. {
  1303. bfd_size_type size;
  1304. size = symtab_hdr->sh_info;
  1305. size *= (sizeof (bfd_signed_vma) + sizeof(char));
  1306. local_got_refcounts = ((bfd_signed_vma *)
  1307. bfd_zalloc (abfd, size));
  1308. if (local_got_refcounts == NULL)
  1309. return false;
  1310. elf_local_got_refcounts (abfd) = local_got_refcounts;
  1311. _bfd_tilepro_elf_local_got_tls_type (abfd)
  1312. = (char *) (local_got_refcounts + symtab_hdr->sh_info);
  1313. }
  1314. local_got_refcounts[r_symndx] += 1;
  1315. old_tls_type =
  1316. _bfd_tilepro_elf_local_got_tls_type (abfd) [r_symndx];
  1317. }
  1318. /* If a TLS symbol is accessed using IE at least once,
  1319. there is no point to use dynamic model for it. */
  1320. if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
  1321. && (old_tls_type != GOT_TLS_GD
  1322. || tls_type != GOT_TLS_IE))
  1323. {
  1324. if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
  1325. tls_type = old_tls_type;
  1326. else
  1327. {
  1328. _bfd_error_handler
  1329. /* xgettext:c-format */
  1330. (_("%pB: `%s' accessed both as normal and thread local symbol"),
  1331. abfd, h ? h->root.root.string : "<local>");
  1332. return false;
  1333. }
  1334. }
  1335. if (old_tls_type != tls_type)
  1336. {
  1337. if (h != NULL)
  1338. tilepro_elf_hash_entry (h)->tls_type = tls_type;
  1339. else
  1340. _bfd_tilepro_elf_local_got_tls_type (abfd) [r_symndx] =
  1341. tls_type;
  1342. }
  1343. }
  1344. if (htab->sgot == NULL)
  1345. {
  1346. if (!tilepro_elf_create_got_section (htab->dynobj, info))
  1347. return false;
  1348. }
  1349. break;
  1350. case R_TILEPRO_TLS_GD_CALL:
  1351. if (!bfd_link_executable (info))
  1352. {
  1353. /* These are basically R_TILEPRO_JOFFLONG_X1_PLT relocs
  1354. against __tls_get_addr. */
  1355. struct bfd_link_hash_entry *bh = NULL;
  1356. if (! _bfd_generic_link_add_one_symbol (info, abfd,
  1357. "__tls_get_addr", 0,
  1358. bfd_und_section_ptr, 0,
  1359. NULL, false, false,
  1360. &bh))
  1361. return false;
  1362. h = (struct elf_link_hash_entry *) bh;
  1363. }
  1364. else
  1365. break;
  1366. /* Fall through */
  1367. case R_TILEPRO_JOFFLONG_X1_PLT:
  1368. /* This symbol requires a procedure linkage table entry. We
  1369. actually build the entry in adjust_dynamic_symbol,
  1370. because this might be a case of linking PIC code without
  1371. linking in any dynamic objects, in which case we don't
  1372. need to generate a procedure linkage table after all. */
  1373. if (h != NULL)
  1374. {
  1375. h->needs_plt = 1;
  1376. h->plt.refcount += 1;
  1377. }
  1378. break;
  1379. case R_TILEPRO_32_PCREL:
  1380. case R_TILEPRO_16_PCREL:
  1381. case R_TILEPRO_8_PCREL:
  1382. case R_TILEPRO_IMM16_X0_PCREL:
  1383. case R_TILEPRO_IMM16_X1_PCREL:
  1384. case R_TILEPRO_IMM16_X0_LO_PCREL:
  1385. case R_TILEPRO_IMM16_X1_LO_PCREL:
  1386. case R_TILEPRO_IMM16_X0_HI_PCREL:
  1387. case R_TILEPRO_IMM16_X1_HI_PCREL:
  1388. case R_TILEPRO_IMM16_X0_HA_PCREL:
  1389. case R_TILEPRO_IMM16_X1_HA_PCREL:
  1390. if (h != NULL)
  1391. h->non_got_ref = 1;
  1392. if (h != NULL
  1393. && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
  1394. break;
  1395. /* Fall through. */
  1396. case R_TILEPRO_32:
  1397. case R_TILEPRO_16:
  1398. case R_TILEPRO_8:
  1399. case R_TILEPRO_LO16:
  1400. case R_TILEPRO_HI16:
  1401. case R_TILEPRO_HA16:
  1402. case R_TILEPRO_COPY:
  1403. case R_TILEPRO_GLOB_DAT:
  1404. case R_TILEPRO_JMP_SLOT:
  1405. case R_TILEPRO_RELATIVE:
  1406. case R_TILEPRO_BROFF_X1:
  1407. case R_TILEPRO_JOFFLONG_X1:
  1408. case R_TILEPRO_IMM8_X0:
  1409. case R_TILEPRO_IMM8_Y0:
  1410. case R_TILEPRO_IMM8_X1:
  1411. case R_TILEPRO_IMM8_Y1:
  1412. case R_TILEPRO_DEST_IMM8_X1:
  1413. case R_TILEPRO_MT_IMM15_X1:
  1414. case R_TILEPRO_MF_IMM15_X1:
  1415. case R_TILEPRO_IMM16_X0:
  1416. case R_TILEPRO_IMM16_X1:
  1417. case R_TILEPRO_IMM16_X0_LO:
  1418. case R_TILEPRO_IMM16_X1_LO:
  1419. case R_TILEPRO_IMM16_X0_HI:
  1420. case R_TILEPRO_IMM16_X1_HI:
  1421. case R_TILEPRO_IMM16_X0_HA:
  1422. case R_TILEPRO_IMM16_X1_HA:
  1423. case R_TILEPRO_MMSTART_X0:
  1424. case R_TILEPRO_MMEND_X0:
  1425. case R_TILEPRO_MMSTART_X1:
  1426. case R_TILEPRO_MMEND_X1:
  1427. case R_TILEPRO_SHAMT_X0:
  1428. case R_TILEPRO_SHAMT_X1:
  1429. case R_TILEPRO_SHAMT_Y0:
  1430. case R_TILEPRO_SHAMT_Y1:
  1431. if (h != NULL)
  1432. h->non_got_ref = 1;
  1433. r_tilepro_plt32:
  1434. if (h != NULL && !bfd_link_pic (info))
  1435. {
  1436. /* We may need a .plt entry if the function this reloc
  1437. refers to is in a shared lib. */
  1438. h->plt.refcount += 1;
  1439. }
  1440. /* If we are creating a shared library, and this is a reloc
  1441. against a global symbol, or a non PC relative reloc
  1442. against a local symbol, then we need to copy the reloc
  1443. into the shared library. However, if we are linking with
  1444. -Bsymbolic, we do not need to copy a reloc against a
  1445. global symbol which is defined in an object we are
  1446. including in the link (i.e., DEF_REGULAR is set). At
  1447. this point we have not seen all the input files, so it is
  1448. possible that DEF_REGULAR is not set now but will be set
  1449. later (it is never cleared). In case of a weak definition,
  1450. DEF_REGULAR may be cleared later by a strong definition in
  1451. a shared library. We account for that possibility below by
  1452. storing information in the relocs_copied field of the hash
  1453. table entry. A similar situation occurs when creating
  1454. shared libraries and symbol visibility changes render the
  1455. symbol local.
  1456. If on the other hand, we are creating an executable, we
  1457. may need to keep relocations for symbols satisfied by a
  1458. dynamic library if we manage to avoid copy relocs for the
  1459. symbol. */
  1460. if ((bfd_link_pic (info)
  1461. && (sec->flags & SEC_ALLOC) != 0
  1462. && (! tilepro_elf_howto_table[r_type].pc_relative
  1463. || (h != NULL
  1464. && (! info->symbolic
  1465. || h->root.type == bfd_link_hash_defweak
  1466. || !h->def_regular))))
  1467. || (!bfd_link_pic (info)
  1468. && (sec->flags & SEC_ALLOC) != 0
  1469. && h != NULL
  1470. && (h->root.type == bfd_link_hash_defweak
  1471. || !h->def_regular)))
  1472. {
  1473. struct elf_dyn_relocs *p;
  1474. struct elf_dyn_relocs **head;
  1475. /* When creating a shared object, we must copy these
  1476. relocs into the output file. We create a reloc
  1477. section in dynobj and make room for the reloc. */
  1478. if (sreloc == NULL)
  1479. {
  1480. sreloc = _bfd_elf_make_dynamic_reloc_section
  1481. (sec, htab->dynobj, 2, abfd, /*rela?*/ true);
  1482. if (sreloc == NULL)
  1483. return false;
  1484. }
  1485. /* If this is a global symbol, we count the number of
  1486. relocations we need for this symbol. */
  1487. if (h != NULL)
  1488. head = &h->dyn_relocs;
  1489. else
  1490. {
  1491. /* Track dynamic relocs needed for local syms too.
  1492. We really need local syms available to do this
  1493. easily. Oh well. */
  1494. asection *s;
  1495. void *vpp;
  1496. Elf_Internal_Sym *isym;
  1497. isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  1498. abfd, r_symndx);
  1499. if (isym == NULL)
  1500. return false;
  1501. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  1502. if (s == NULL)
  1503. s = sec;
  1504. vpp = &elf_section_data (s)->local_dynrel;
  1505. head = (struct elf_dyn_relocs **) vpp;
  1506. }
  1507. p = *head;
  1508. if (p == NULL || p->sec != sec)
  1509. {
  1510. size_t amt = sizeof *p;
  1511. p = ((struct elf_dyn_relocs *)
  1512. bfd_alloc (htab->dynobj, amt));
  1513. if (p == NULL)
  1514. return false;
  1515. p->next = *head;
  1516. *head = p;
  1517. p->sec = sec;
  1518. p->count = 0;
  1519. p->pc_count = 0;
  1520. }
  1521. p->count += 1;
  1522. if (tilepro_elf_howto_table[r_type].pc_relative)
  1523. p->pc_count += 1;
  1524. }
  1525. break;
  1526. case R_TILEPRO_GNU_VTINHERIT:
  1527. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  1528. return false;
  1529. break;
  1530. case R_TILEPRO_GNU_VTENTRY:
  1531. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  1532. return false;
  1533. break;
  1534. default:
  1535. break;
  1536. }
  1537. }
  1538. return true;
  1539. }
  1540. static asection *
  1541. tilepro_elf_gc_mark_hook (asection *sec,
  1542. struct bfd_link_info *info,
  1543. Elf_Internal_Rela *rel,
  1544. struct elf_link_hash_entry *h,
  1545. Elf_Internal_Sym *sym)
  1546. {
  1547. if (h != NULL)
  1548. {
  1549. switch (ELF32_R_TYPE (rel->r_info))
  1550. {
  1551. case R_TILEPRO_GNU_VTINHERIT:
  1552. case R_TILEPRO_GNU_VTENTRY:
  1553. return NULL;
  1554. }
  1555. }
  1556. /* FIXME: The test here, in check_relocs and in relocate_section
  1557. dealing with TLS optimization, ought to be !bfd_link_executable (info). */
  1558. if (bfd_link_pic (info))
  1559. {
  1560. struct bfd_link_hash_entry *bh;
  1561. switch (ELF32_R_TYPE (rel->r_info))
  1562. {
  1563. case R_TILEPRO_TLS_GD_CALL:
  1564. /* This reloc implicitly references __tls_get_addr. We know
  1565. another reloc will reference the same symbol as the one
  1566. on this reloc, so the real symbol and section will be
  1567. gc marked when processing the other reloc. That lets
  1568. us handle __tls_get_addr here. */
  1569. bh = NULL;
  1570. if (! _bfd_generic_link_add_one_symbol (info, sec->owner,
  1571. "__tls_get_addr", 0,
  1572. bfd_und_section_ptr,
  1573. 0, NULL, false,
  1574. false, &bh))
  1575. return NULL;
  1576. h = (struct elf_link_hash_entry *) bh;
  1577. BFD_ASSERT (h != NULL);
  1578. h->mark = 1;
  1579. if (h->is_weakalias)
  1580. weakdef (h)->mark = 1;
  1581. sym = NULL;
  1582. }
  1583. }
  1584. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  1585. }
  1586. /* Adjust a symbol defined by a dynamic object and referenced by a
  1587. regular object. The current definition is in some section of the
  1588. dynamic object, but we're not including those sections. We have to
  1589. change the definition to something the rest of the link can
  1590. understand. */
  1591. static bool
  1592. tilepro_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
  1593. struct elf_link_hash_entry *h)
  1594. {
  1595. struct elf_link_hash_table *htab;
  1596. asection *s, *srel;
  1597. htab = tilepro_elf_hash_table (info);
  1598. BFD_ASSERT (htab != NULL);
  1599. /* Make sure we know what is going on here. */
  1600. BFD_ASSERT (htab->dynobj != NULL
  1601. && (h->needs_plt
  1602. || h->is_weakalias
  1603. || (h->def_dynamic
  1604. && h->ref_regular
  1605. && !h->def_regular)));
  1606. /* If this is a function, put it in the procedure linkage table. We
  1607. will fill in the contents of the procedure linkage table later
  1608. (although we could actually do it here). */
  1609. if (h->type == STT_FUNC || h->needs_plt)
  1610. {
  1611. if (h->plt.refcount <= 0
  1612. || SYMBOL_CALLS_LOCAL (info, h)
  1613. || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  1614. && h->root.type == bfd_link_hash_undefweak))
  1615. {
  1616. /* This case can occur if we saw a R_TILEPRO_JOFFLONG_X1_PLT
  1617. reloc in an input file, but the symbol was never referred
  1618. to by a dynamic object, or if all references were garbage
  1619. collected. In such a case, we don't actually need to build
  1620. a procedure linkage table, and we can just do a
  1621. R_TILEPRO_JOFFLONG_X1 relocation instead. */
  1622. h->plt.offset = (bfd_vma) -1;
  1623. h->needs_plt = 0;
  1624. }
  1625. return true;
  1626. }
  1627. else
  1628. h->plt.offset = (bfd_vma) -1;
  1629. /* If this is a weak symbol, and there is a real definition, the
  1630. processor independent code will have arranged for us to see the
  1631. real definition first, and we can just use the same value. */
  1632. if (h->is_weakalias)
  1633. {
  1634. struct elf_link_hash_entry *def = weakdef (h);
  1635. BFD_ASSERT (def->root.type == bfd_link_hash_defined);
  1636. h->root.u.def.section = def->root.u.def.section;
  1637. h->root.u.def.value = def->root.u.def.value;
  1638. return true;
  1639. }
  1640. /* This is a reference to a symbol defined by a dynamic object which
  1641. is not a function. */
  1642. /* If we are creating a shared library, we must presume that the
  1643. only references to the symbol are via the global offset table.
  1644. For such cases we need not do anything here; the relocations will
  1645. be handled correctly by relocate_section. */
  1646. if (bfd_link_pic (info))
  1647. return true;
  1648. /* If there are no references to this symbol that do not use the
  1649. GOT, we don't need to generate a copy reloc. */
  1650. if (!h->non_got_ref)
  1651. return true;
  1652. /* If -z nocopyreloc was given, we won't generate them either. */
  1653. if (info->nocopyreloc)
  1654. {
  1655. h->non_got_ref = 0;
  1656. return true;
  1657. }
  1658. /* If we don't find any dynamic relocs in read-only sections, then
  1659. we'll be keeping the dynamic relocs and avoiding the copy reloc. */
  1660. if (!_bfd_elf_readonly_dynrelocs (h))
  1661. {
  1662. h->non_got_ref = 0;
  1663. return true;
  1664. }
  1665. /* We must allocate the symbol in our .dynbss section, which will
  1666. become part of the .bss section of the executable. There will be
  1667. an entry for this symbol in the .dynsym section. The dynamic
  1668. object will contain position independent code, so all references
  1669. from the dynamic object to this symbol will go through the global
  1670. offset table. The dynamic linker will use the .dynsym entry to
  1671. determine the address it must put in the global offset table, so
  1672. both the dynamic object and the regular object will refer to the
  1673. same memory location for the variable. */
  1674. /* We must generate a R_TILEPRO_COPY reloc to tell the dynamic linker
  1675. to copy the initial value out of the dynamic object and into the
  1676. runtime process image. We need to remember the offset into the
  1677. .rel.bss section we are going to use. */
  1678. if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
  1679. {
  1680. s = htab->sdynrelro;
  1681. srel = htab->sreldynrelro;
  1682. }
  1683. else
  1684. {
  1685. s = htab->sdynbss;
  1686. srel = htab->srelbss;
  1687. }
  1688. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  1689. {
  1690. srel->size += TILEPRO_ELF_RELA_BYTES;
  1691. h->needs_copy = 1;
  1692. }
  1693. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  1694. }
  1695. /* Allocate space in .plt, .got and associated reloc sections for
  1696. dynamic relocs. */
  1697. static bool
  1698. allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
  1699. {
  1700. struct bfd_link_info *info;
  1701. struct elf_link_hash_table *htab;
  1702. struct elf_dyn_relocs *p;
  1703. if (h->root.type == bfd_link_hash_indirect)
  1704. return true;
  1705. info = (struct bfd_link_info *) inf;
  1706. htab = tilepro_elf_hash_table (info);
  1707. BFD_ASSERT (htab != NULL);
  1708. if (htab->dynamic_sections_created
  1709. && h->plt.refcount > 0)
  1710. {
  1711. /* Make sure this symbol is output as a dynamic symbol.
  1712. Undefined weak syms won't yet be marked as dynamic. */
  1713. if (h->dynindx == -1
  1714. && !h->forced_local)
  1715. {
  1716. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1717. return false;
  1718. }
  1719. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
  1720. {
  1721. asection *s = htab->splt;
  1722. /* Allocate room for the header. */
  1723. if (s->size == 0)
  1724. {
  1725. s->size = PLT_ENTRY_SIZE;
  1726. }
  1727. h->plt.offset = s->size;
  1728. /* If this symbol is not defined in a regular file, and we are
  1729. not generating a shared library, then set the symbol to this
  1730. location in the .plt. This is required to make function
  1731. pointers compare as equal between the normal executable and
  1732. the shared library. */
  1733. if (! bfd_link_pic (info)
  1734. && !h->def_regular)
  1735. {
  1736. h->root.u.def.section = s;
  1737. h->root.u.def.value = h->plt.offset;
  1738. }
  1739. /* Make room for this entry. */
  1740. s->size += PLT_ENTRY_SIZE;
  1741. /* We also need to make an entry in the .got.plt section. */
  1742. htab->sgotplt->size += GOT_ENTRY_SIZE;
  1743. /* We also need to make an entry in the .rela.plt section. */
  1744. htab->srelplt->size += TILEPRO_ELF_RELA_BYTES;
  1745. }
  1746. else
  1747. {
  1748. h->plt.offset = (bfd_vma) -1;
  1749. h->needs_plt = 0;
  1750. }
  1751. }
  1752. else
  1753. {
  1754. h->plt.offset = (bfd_vma) -1;
  1755. h->needs_plt = 0;
  1756. }
  1757. /* If a TLS_IE symbol is now local to the binary, make it a TLS_LE
  1758. requiring no TLS entry. */
  1759. if (h->got.refcount > 0
  1760. && bfd_link_executable (info)
  1761. && h->dynindx == -1
  1762. && tilepro_elf_hash_entry(h)->tls_type == GOT_TLS_IE)
  1763. h->got.offset = (bfd_vma) -1;
  1764. else if (h->got.refcount > 0)
  1765. {
  1766. asection *s;
  1767. bool dyn;
  1768. int tls_type = tilepro_elf_hash_entry(h)->tls_type;
  1769. /* Make sure this symbol is output as a dynamic symbol.
  1770. Undefined weak syms won't yet be marked as dynamic. */
  1771. if (h->dynindx == -1
  1772. && !h->forced_local)
  1773. {
  1774. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1775. return false;
  1776. }
  1777. s = htab->sgot;
  1778. h->got.offset = s->size;
  1779. s->size += TILEPRO_BYTES_PER_WORD;
  1780. /* R_TILEPRO_IMM16_Xn_TLS_GD entries need 2 consecutive GOT slots. */
  1781. if (tls_type == GOT_TLS_GD)
  1782. s->size += TILEPRO_BYTES_PER_WORD;
  1783. dyn = htab->dynamic_sections_created;
  1784. /* R_TILEPRO_IMM16_Xn_TLS_IE_xxx needs one dynamic relocation,
  1785. R_TILEPRO_IMM16_Xn_TLS_GD_xxx needs two if local symbol and two if
  1786. global. */
  1787. if (tls_type == GOT_TLS_GD || tls_type == GOT_TLS_IE)
  1788. htab->srelgot->size += 2 * TILEPRO_ELF_RELA_BYTES;
  1789. else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  1790. bfd_link_pic (info),
  1791. h))
  1792. htab->srelgot->size += TILEPRO_ELF_RELA_BYTES;
  1793. }
  1794. else
  1795. h->got.offset = (bfd_vma) -1;
  1796. if (h->dyn_relocs == NULL)
  1797. return true;
  1798. /* In the shared -Bsymbolic case, discard space allocated for
  1799. dynamic pc-relative relocs against symbols which turn out to be
  1800. defined in regular objects. For the normal shared case, discard
  1801. space for pc-relative relocs that have become local due to symbol
  1802. visibility changes. */
  1803. if (bfd_link_pic (info))
  1804. {
  1805. if (SYMBOL_CALLS_LOCAL (info, h))
  1806. {
  1807. struct elf_dyn_relocs **pp;
  1808. for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
  1809. {
  1810. p->count -= p->pc_count;
  1811. p->pc_count = 0;
  1812. if (p->count == 0)
  1813. *pp = p->next;
  1814. else
  1815. pp = &p->next;
  1816. }
  1817. }
  1818. /* Also discard relocs on undefined weak syms with non-default
  1819. visibility. */
  1820. if (h->dyn_relocs != NULL
  1821. && h->root.type == bfd_link_hash_undefweak)
  1822. {
  1823. if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  1824. || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
  1825. h->dyn_relocs = NULL;
  1826. /* Make sure undefined weak symbols are output as a dynamic
  1827. symbol in PIEs. */
  1828. else if (h->dynindx == -1
  1829. && !h->forced_local)
  1830. {
  1831. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1832. return false;
  1833. }
  1834. }
  1835. }
  1836. else
  1837. {
  1838. /* For the non-shared case, discard space for relocs against
  1839. symbols which turn out to need copy relocs or are not
  1840. dynamic. */
  1841. if (!h->non_got_ref
  1842. && ((h->def_dynamic
  1843. && !h->def_regular)
  1844. || (htab->dynamic_sections_created
  1845. && (h->root.type == bfd_link_hash_undefweak
  1846. || h->root.type == bfd_link_hash_undefined))))
  1847. {
  1848. /* Make sure this symbol is output as a dynamic symbol.
  1849. Undefined weak syms won't yet be marked as dynamic. */
  1850. if (h->dynindx == -1
  1851. && !h->forced_local)
  1852. {
  1853. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1854. return false;
  1855. }
  1856. /* If that succeeded, we know we'll be keeping all the
  1857. relocs. */
  1858. if (h->dynindx != -1)
  1859. goto keep;
  1860. }
  1861. h->dyn_relocs = NULL;
  1862. keep: ;
  1863. }
  1864. /* Finally, allocate space. */
  1865. for (p = h->dyn_relocs; p != NULL; p = p->next)
  1866. {
  1867. asection *sreloc = elf_section_data (p->sec)->sreloc;
  1868. sreloc->size += p->count * TILEPRO_ELF_RELA_BYTES;
  1869. }
  1870. return true;
  1871. }
  1872. /* Return true if the dynamic symbol for a given section should be
  1873. omitted when creating a shared library. */
  1874. static bool
  1875. tilepro_elf_omit_section_dynsym (bfd *output_bfd,
  1876. struct bfd_link_info *info,
  1877. asection *p)
  1878. {
  1879. /* We keep the .got section symbol so that explicit relocations
  1880. against the _GLOBAL_OFFSET_TABLE_ symbol emitted in PIC mode
  1881. can be turned into relocations against the .got symbol. */
  1882. if (strcmp (p->name, ".got") == 0)
  1883. return false;
  1884. return _bfd_elf_omit_section_dynsym_default (output_bfd, info, p);
  1885. }
  1886. /* Set the sizes of the dynamic sections. */
  1887. #define ELF32_DYNAMIC_INTERPRETER "/lib/ld.so.1"
  1888. static bool
  1889. tilepro_elf_size_dynamic_sections (bfd *output_bfd,
  1890. struct bfd_link_info *info)
  1891. {
  1892. (void)output_bfd;
  1893. struct elf_link_hash_table *htab;
  1894. bfd *dynobj;
  1895. asection *s;
  1896. bfd *ibfd;
  1897. htab = tilepro_elf_hash_table (info);
  1898. BFD_ASSERT (htab != NULL);
  1899. dynobj = htab->dynobj;
  1900. BFD_ASSERT (dynobj != NULL);
  1901. if (elf_hash_table (info)->dynamic_sections_created)
  1902. {
  1903. /* Set the contents of the .interp section to the interpreter. */
  1904. if (bfd_link_executable (info) && !info->nointerp)
  1905. {
  1906. s = bfd_get_linker_section (dynobj, ".interp");
  1907. BFD_ASSERT (s != NULL);
  1908. s->size = sizeof ELF32_DYNAMIC_INTERPRETER;
  1909. s->contents = (unsigned char *) ELF32_DYNAMIC_INTERPRETER;
  1910. }
  1911. }
  1912. /* Set up .got offsets for local syms, and space for local dynamic
  1913. relocs. */
  1914. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  1915. {
  1916. bfd_signed_vma *local_got;
  1917. bfd_signed_vma *end_local_got;
  1918. char *local_tls_type;
  1919. bfd_size_type locsymcount;
  1920. Elf_Internal_Shdr *symtab_hdr;
  1921. asection *srel;
  1922. if (! is_tilepro_elf (ibfd))
  1923. continue;
  1924. for (s = ibfd->sections; s != NULL; s = s->next)
  1925. {
  1926. struct elf_dyn_relocs *p;
  1927. for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
  1928. {
  1929. if (!bfd_is_abs_section (p->sec)
  1930. && bfd_is_abs_section (p->sec->output_section))
  1931. {
  1932. /* Input section has been discarded, either because
  1933. it is a copy of a linkonce section or due to
  1934. linker script /DISCARD/, so we'll be discarding
  1935. the relocs too. */
  1936. }
  1937. else if (p->count != 0)
  1938. {
  1939. srel = elf_section_data (p->sec)->sreloc;
  1940. srel->size += p->count * TILEPRO_ELF_RELA_BYTES;
  1941. if ((p->sec->output_section->flags & SEC_READONLY) != 0)
  1942. {
  1943. info->flags |= DF_TEXTREL;
  1944. info->callbacks->minfo (_("%pB: dynamic relocation in read-only section `%pA'\n"),
  1945. p->sec->owner, p->sec);
  1946. }
  1947. }
  1948. }
  1949. }
  1950. local_got = elf_local_got_refcounts (ibfd);
  1951. if (!local_got)
  1952. continue;
  1953. symtab_hdr = &elf_symtab_hdr (ibfd);
  1954. locsymcount = symtab_hdr->sh_info;
  1955. end_local_got = local_got + locsymcount;
  1956. local_tls_type = _bfd_tilepro_elf_local_got_tls_type (ibfd);
  1957. s = htab->sgot;
  1958. srel = htab->srelgot;
  1959. for (; local_got < end_local_got; ++local_got, ++local_tls_type)
  1960. {
  1961. if (*local_got > 0)
  1962. {
  1963. *local_got = s->size;
  1964. s->size += TILEPRO_BYTES_PER_WORD;
  1965. if (*local_tls_type == GOT_TLS_GD)
  1966. s->size += TILEPRO_BYTES_PER_WORD;
  1967. if (bfd_link_pic (info)
  1968. || *local_tls_type == GOT_TLS_GD
  1969. || *local_tls_type == GOT_TLS_IE)
  1970. srel->size += TILEPRO_ELF_RELA_BYTES;
  1971. }
  1972. else
  1973. *local_got = (bfd_vma) -1;
  1974. }
  1975. }
  1976. /* Allocate global sym .plt and .got entries, and space for global
  1977. sym dynamic relocs. */
  1978. elf_link_hash_traverse (htab, allocate_dynrelocs, info);
  1979. if (elf_hash_table (info)->dynamic_sections_created)
  1980. {
  1981. /* If the .got section is more than 0x8000 bytes, we add
  1982. 0x8000 to the value of _GLOBAL_OFFSET_TABLE_, so that 16
  1983. bit relocations have a greater chance of working. */
  1984. if (htab->sgot->size >= 0x8000
  1985. && elf_hash_table (info)->hgot->root.u.def.value == 0)
  1986. elf_hash_table (info)->hgot->root.u.def.value = 0x8000;
  1987. }
  1988. if (htab->sgotplt)
  1989. {
  1990. struct elf_link_hash_entry *got;
  1991. got = elf_link_hash_lookup (elf_hash_table (info),
  1992. "_GLOBAL_OFFSET_TABLE_",
  1993. false, false, false);
  1994. /* Don't allocate .got.plt section if there are no GOT nor PLT
  1995. entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
  1996. if ((got == NULL
  1997. || !got->ref_regular_nonweak)
  1998. && (htab->sgotplt->size
  1999. == GOTPLT_HEADER_SIZE)
  2000. && (htab->splt == NULL
  2001. || htab->splt->size == 0)
  2002. && (htab->sgot == NULL
  2003. || (htab->sgot->size
  2004. == get_elf_backend_data (output_bfd)->got_header_size)))
  2005. htab->sgotplt->size = 0;
  2006. }
  2007. /* The check_relocs and adjust_dynamic_symbol entry points have
  2008. determined the sizes of the various dynamic sections. Allocate
  2009. memory for them. */
  2010. for (s = dynobj->sections; s != NULL; s = s->next)
  2011. {
  2012. if ((s->flags & SEC_LINKER_CREATED) == 0)
  2013. continue;
  2014. if (s == htab->splt
  2015. || s == htab->sgot
  2016. || s == htab->sgotplt
  2017. || s == htab->sdynbss
  2018. || s == htab->sdynrelro)
  2019. {
  2020. /* Strip this section if we don't need it; see the
  2021. comment below. */
  2022. }
  2023. else if (startswith (s->name, ".rela"))
  2024. {
  2025. if (s->size != 0)
  2026. {
  2027. /* We use the reloc_count field as a counter if we need
  2028. to copy relocs into the output file. */
  2029. s->reloc_count = 0;
  2030. }
  2031. }
  2032. else
  2033. {
  2034. /* It's not one of our sections. */
  2035. continue;
  2036. }
  2037. if (s->size == 0)
  2038. {
  2039. /* If we don't need this section, strip it from the
  2040. output file. This is mostly to handle .rela.bss and
  2041. .rela.plt. We must create both sections in
  2042. create_dynamic_sections, because they must be created
  2043. before the linker maps input sections to output
  2044. sections. The linker does that before
  2045. adjust_dynamic_symbol is called, and it is that
  2046. function which decides whether anything needs to go
  2047. into these sections. */
  2048. s->flags |= SEC_EXCLUDE;
  2049. continue;
  2050. }
  2051. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  2052. continue;
  2053. /* Allocate memory for the section contents. Zero the memory
  2054. for the benefit of .rela.plt, which has 4 unused entries
  2055. at the beginning, and we don't want garbage. */
  2056. s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
  2057. if (s->contents == NULL)
  2058. return false;
  2059. }
  2060. return _bfd_elf_add_dynamic_tags (output_bfd, info, true);
  2061. }
  2062. /* Return the base VMA address which should be subtracted from real addresses
  2063. when resolving @dtpoff relocation.
  2064. This is PT_TLS segment p_vaddr. */
  2065. static bfd_vma
  2066. dtpoff_base (struct bfd_link_info *info)
  2067. {
  2068. /* If tls_sec is NULL, we should have signalled an error already. */
  2069. if (elf_hash_table (info)->tls_sec == NULL)
  2070. return 0;
  2071. return elf_hash_table (info)->tls_sec->vma;
  2072. }
  2073. /* Return the relocation value for R_TILEPRO_TLS_TPOFF32. */
  2074. static bfd_vma
  2075. tpoff (struct bfd_link_info *info, bfd_vma address)
  2076. {
  2077. struct elf_link_hash_table *htab = elf_hash_table (info);
  2078. /* If tls_sec is NULL, we should have signalled an error already. */
  2079. if (htab->tls_sec == NULL)
  2080. return 0;
  2081. return (address - htab->tls_sec->vma);
  2082. }
  2083. /* Replace the MASK bits in ADDR with those in INSN, for the next
  2084. TILEPRO_BUNDLE_SIZE_IN_BYTES bytes. */
  2085. static void
  2086. tilepro_replace_insn (bfd_byte *addr, const bfd_byte *mask,
  2087. const bfd_byte *insn)
  2088. {
  2089. int i;
  2090. for (i = 0; i < TILEPRO_BUNDLE_SIZE_IN_BYTES; i++)
  2091. {
  2092. addr[i] = (addr[i] & ~mask[i]) | (insn[i] & mask[i]);
  2093. }
  2094. }
  2095. /* Mask to extract the bits corresponding to an instruction in a
  2096. specific pipe of a bundle. */
  2097. static const bfd_byte insn_mask_X1[] = {
  2098. 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x7f
  2099. };
  2100. /* Mask to extract the bits corresponding to an instruction in a
  2101. specific pipe of a bundle, minus the destination operand and the
  2102. first source operand. */
  2103. static const bfd_byte insn_mask_X0_no_dest_no_srca[] = {
  2104. 0x00, 0xf0, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00
  2105. };
  2106. static const bfd_byte insn_mask_X1_no_dest_no_srca[] = {
  2107. 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x7f
  2108. };
  2109. static const bfd_byte insn_mask_Y0_no_dest_no_srca[] = {
  2110. 0x00, 0xf0, 0x0f, 0x78, 0x00, 0x00, 0x00, 0x00
  2111. };
  2112. static const bfd_byte insn_mask_Y1_no_dest_no_srca[] = {
  2113. 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x78
  2114. };
  2115. /* Mask to extract the first source operand of an instruction. */
  2116. static const bfd_byte srca_mask_X0[] = {
  2117. 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  2118. };
  2119. static const bfd_byte srca_mask_X1[] = {
  2120. 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00
  2121. };
  2122. /* Various instructions synthesized to support tls references. */
  2123. /* move r0, r0 in the X1 pipe, used for tls le. */
  2124. static const bfd_byte insn_tls_le_move_X1[] = {
  2125. 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x33, 0x08
  2126. };
  2127. /* move r0, zero in the X0 and X1 pipe, used for tls le. */
  2128. static const bfd_byte insn_tls_le_move_zero_X0X1[] = {
  2129. 0xc0, 0xff, 0xcf, 0x00, 0xe0, 0xff, 0x33, 0x08
  2130. };
  2131. /* lw r0, r0 in the X1 pipe, used for tls ie. */
  2132. static const bfd_byte insn_tls_ie_lw_X1[] = {
  2133. 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x0b, 0x40
  2134. };
  2135. /* add r0, r0, tp in various pipes, used for tls ie. */
  2136. static const bfd_byte insn_tls_ie_add_X0X1[] = {
  2137. 0x00, 0x50, 0x0f, 0x00, 0x00, 0xa8, 0x07, 0x08
  2138. };
  2139. static const bfd_byte insn_tls_ie_add_Y0Y1[] = {
  2140. 0x00, 0x50, 0x03, 0x08, 0x00, 0xa8, 0x01, 0x8c
  2141. };
  2142. /* move r0, r0 in various pipes, used for tls gd. */
  2143. static const bfd_byte insn_tls_gd_add_X0X1[] = {
  2144. 0x00, 0xf0, 0xcf, 0x00, 0x00, 0xf8, 0x33, 0x08
  2145. };
  2146. static const bfd_byte insn_tls_gd_add_Y0Y1[] = {
  2147. 0x00, 0xf0, 0x0b, 0x18, 0x00, 0xf8, 0x05, 0x9c
  2148. };
  2149. /* Relocate an TILEPRO ELF section.
  2150. The RELOCATE_SECTION function is called by the new ELF backend linker
  2151. to handle the relocations for a section.
  2152. The relocs are always passed as Rela structures.
  2153. This function is responsible for adjusting the section contents as
  2154. necessary, and (if generating a relocatable output file) adjusting
  2155. the reloc addend as necessary.
  2156. This function does not have to worry about setting the reloc
  2157. address or the reloc symbol index.
  2158. LOCAL_SYMS is a pointer to the swapped in local symbols.
  2159. LOCAL_SECTIONS is an array giving the section in the input file
  2160. corresponding to the st_shndx field of each local symbol.
  2161. The global hash table entry for the global symbols can be found
  2162. via elf_sym_hashes (input_bfd).
  2163. When generating relocatable output, this function must handle
  2164. STB_LOCAL/STT_SECTION symbols specially. The output symbol is
  2165. going to be the section symbol corresponding to the output
  2166. section, which means that the addend must be adjusted
  2167. accordingly. */
  2168. static int
  2169. tilepro_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
  2170. bfd *input_bfd, asection *input_section,
  2171. bfd_byte *contents, Elf_Internal_Rela *relocs,
  2172. Elf_Internal_Sym *local_syms,
  2173. asection **local_sections)
  2174. {
  2175. struct elf_link_hash_table *htab;
  2176. Elf_Internal_Shdr *symtab_hdr;
  2177. struct elf_link_hash_entry **sym_hashes;
  2178. bfd_vma *local_got_offsets;
  2179. bfd_vma got_base;
  2180. asection *sreloc;
  2181. Elf_Internal_Rela *rel;
  2182. Elf_Internal_Rela *relend;
  2183. int num_relocs;
  2184. htab = tilepro_elf_hash_table (info);
  2185. BFD_ASSERT (htab != NULL);
  2186. symtab_hdr = &elf_symtab_hdr (input_bfd);
  2187. sym_hashes = elf_sym_hashes (input_bfd);
  2188. local_got_offsets = elf_local_got_offsets (input_bfd);
  2189. if (elf_hash_table (info)->hgot == NULL)
  2190. got_base = 0;
  2191. else
  2192. got_base = elf_hash_table (info)->hgot->root.u.def.value;
  2193. sreloc = elf_section_data (input_section)->sreloc;
  2194. rel = relocs;
  2195. num_relocs = input_section->reloc_count;
  2196. relend = relocs + num_relocs;
  2197. for (; rel < relend; rel++)
  2198. {
  2199. int r_type, tls_type;
  2200. bool is_tls_iele, is_tls_le;
  2201. reloc_howto_type *howto;
  2202. unsigned long r_symndx;
  2203. struct elf_link_hash_entry *h;
  2204. Elf_Internal_Sym *sym;
  2205. tilepro_create_func create_func;
  2206. asection *sec;
  2207. bfd_vma relocation;
  2208. bfd_reloc_status_type r;
  2209. const char *name;
  2210. bfd_vma off;
  2211. bool is_plt = false;
  2212. bool resolved_to_zero;
  2213. bool unresolved_reloc;
  2214. r_type = ELF32_R_TYPE (rel->r_info);
  2215. if (r_type == R_TILEPRO_GNU_VTINHERIT
  2216. || r_type == R_TILEPRO_GNU_VTENTRY)
  2217. continue;
  2218. if ((unsigned int)r_type >= NELEMS(tilepro_elf_howto_table))
  2219. return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
  2220. howto = tilepro_elf_howto_table + r_type;
  2221. /* This is a final link. */
  2222. r_symndx = ELF32_R_SYM (rel->r_info);
  2223. h = NULL;
  2224. sym = NULL;
  2225. sec = NULL;
  2226. unresolved_reloc = false;
  2227. if (r_symndx < symtab_hdr->sh_info)
  2228. {
  2229. sym = local_syms + r_symndx;
  2230. sec = local_sections[r_symndx];
  2231. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  2232. }
  2233. else
  2234. {
  2235. bool warned ATTRIBUTE_UNUSED;
  2236. bool ignored ATTRIBUTE_UNUSED;
  2237. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  2238. r_symndx, symtab_hdr, sym_hashes,
  2239. h, sec, relocation,
  2240. unresolved_reloc, warned, ignored);
  2241. if (warned)
  2242. {
  2243. /* To avoid generating warning messages about truncated
  2244. relocations, set the relocation's address to be the same as
  2245. the start of this section. */
  2246. if (input_section->output_section != NULL)
  2247. relocation = input_section->output_section->vma;
  2248. else
  2249. relocation = 0;
  2250. }
  2251. }
  2252. if (sec != NULL && discarded_section (sec))
  2253. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  2254. rel, 1, relend, howto, 0, contents);
  2255. if (bfd_link_relocatable (info))
  2256. continue;
  2257. if (h != NULL)
  2258. name = h->root.root.string;
  2259. else
  2260. {
  2261. name = (bfd_elf_string_from_elf_section
  2262. (input_bfd, symtab_hdr->sh_link, sym->st_name));
  2263. if (name == NULL || *name == '\0')
  2264. name = bfd_section_name (sec);
  2265. }
  2266. switch (r_type)
  2267. {
  2268. case R_TILEPRO_TLS_GD_CALL:
  2269. case R_TILEPRO_IMM8_X0_TLS_GD_ADD:
  2270. case R_TILEPRO_IMM8_Y0_TLS_GD_ADD:
  2271. case R_TILEPRO_IMM8_X1_TLS_GD_ADD:
  2272. case R_TILEPRO_IMM8_Y1_TLS_GD_ADD:
  2273. case R_TILEPRO_IMM16_X0_TLS_GD_HA:
  2274. case R_TILEPRO_IMM16_X1_TLS_GD_HA:
  2275. case R_TILEPRO_IMM16_X0_TLS_IE_HA:
  2276. case R_TILEPRO_IMM16_X1_TLS_IE_HA:
  2277. tls_type = GOT_UNKNOWN;
  2278. if (h == NULL && local_got_offsets)
  2279. tls_type =
  2280. _bfd_tilepro_elf_local_got_tls_type (input_bfd) [r_symndx];
  2281. else if (h != NULL)
  2282. tls_type = tilepro_elf_hash_entry(h)->tls_type;
  2283. is_tls_iele = (bfd_link_executable (info) || tls_type == GOT_TLS_IE);
  2284. is_tls_le = is_tls_iele && (bfd_link_executable (info)
  2285. && (h == NULL || h->dynindx == -1));
  2286. if (r_type == R_TILEPRO_TLS_GD_CALL)
  2287. {
  2288. if (is_tls_le)
  2289. {
  2290. /* GD -> LE */
  2291. tilepro_replace_insn (contents + rel->r_offset,
  2292. insn_mask_X1, insn_tls_le_move_X1);
  2293. continue;
  2294. }
  2295. else if (is_tls_iele)
  2296. {
  2297. /* GD -> IE */
  2298. tilepro_replace_insn (contents + rel->r_offset,
  2299. insn_mask_X1, insn_tls_ie_lw_X1);
  2300. continue;
  2301. }
  2302. /* GD -> GD */
  2303. h = (struct elf_link_hash_entry *)
  2304. bfd_link_hash_lookup (info->hash, "__tls_get_addr", false,
  2305. false, true);
  2306. BFD_ASSERT (h != NULL);
  2307. r_type = R_TILEPRO_JOFFLONG_X1_PLT;
  2308. howto = tilepro_elf_howto_table + r_type;
  2309. }
  2310. else if (r_type == R_TILEPRO_IMM16_X0_TLS_GD_HA
  2311. || r_type == R_TILEPRO_IMM16_X0_TLS_IE_HA)
  2312. {
  2313. if (is_tls_le)
  2314. tilepro_replace_insn (contents + rel->r_offset, srca_mask_X0,
  2315. insn_tls_le_move_zero_X0X1);
  2316. }
  2317. else if (r_type == R_TILEPRO_IMM16_X1_TLS_GD_HA
  2318. || r_type == R_TILEPRO_IMM16_X1_TLS_IE_HA)
  2319. {
  2320. if (is_tls_le)
  2321. tilepro_replace_insn (contents + rel->r_offset, srca_mask_X1,
  2322. insn_tls_le_move_zero_X0X1);
  2323. }
  2324. else
  2325. {
  2326. const bfd_byte *mask = NULL;
  2327. const bfd_byte *add_insn = NULL;
  2328. switch (r_type)
  2329. {
  2330. case R_TILEPRO_IMM8_X0_TLS_GD_ADD:
  2331. add_insn = is_tls_iele ? insn_tls_ie_add_X0X1
  2332. : insn_tls_gd_add_X0X1;
  2333. mask = insn_mask_X0_no_dest_no_srca;
  2334. break;
  2335. case R_TILEPRO_IMM8_X1_TLS_GD_ADD:
  2336. add_insn = is_tls_iele ? insn_tls_ie_add_X0X1
  2337. : insn_tls_gd_add_X0X1;
  2338. mask = insn_mask_X1_no_dest_no_srca;
  2339. break;
  2340. case R_TILEPRO_IMM8_Y0_TLS_GD_ADD:
  2341. add_insn = is_tls_iele ? insn_tls_ie_add_Y0Y1
  2342. : insn_tls_gd_add_Y0Y1;
  2343. mask = insn_mask_Y0_no_dest_no_srca;
  2344. break;
  2345. case R_TILEPRO_IMM8_Y1_TLS_GD_ADD:
  2346. add_insn = is_tls_iele ? insn_tls_ie_add_Y0Y1
  2347. : insn_tls_gd_add_Y0Y1;
  2348. mask = insn_mask_Y1_no_dest_no_srca;
  2349. break;
  2350. }
  2351. tilepro_replace_insn (contents + rel->r_offset, mask, add_insn);
  2352. continue;
  2353. }
  2354. break;
  2355. case R_TILEPRO_TLS_IE_LOAD:
  2356. if (bfd_link_executable (info) && (h == NULL || h->dynindx == -1))
  2357. /* IE -> LE */
  2358. tilepro_replace_insn (contents + rel->r_offset,
  2359. insn_mask_X1_no_dest_no_srca,
  2360. insn_tls_le_move_X1);
  2361. else
  2362. /* IE -> IE */
  2363. tilepro_replace_insn (contents + rel->r_offset,
  2364. insn_mask_X1_no_dest_no_srca,
  2365. insn_tls_ie_lw_X1);
  2366. continue;
  2367. break;
  2368. default:
  2369. break;
  2370. }
  2371. resolved_to_zero = (h != NULL
  2372. && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
  2373. switch (r_type)
  2374. {
  2375. case R_TILEPRO_IMM16_X0_GOT:
  2376. case R_TILEPRO_IMM16_X1_GOT:
  2377. case R_TILEPRO_IMM16_X0_GOT_LO:
  2378. case R_TILEPRO_IMM16_X1_GOT_LO:
  2379. case R_TILEPRO_IMM16_X0_GOT_HI:
  2380. case R_TILEPRO_IMM16_X1_GOT_HI:
  2381. case R_TILEPRO_IMM16_X0_GOT_HA:
  2382. case R_TILEPRO_IMM16_X1_GOT_HA:
  2383. /* Relocation is to the entry for this symbol in the global
  2384. offset table. */
  2385. if (htab->sgot == NULL)
  2386. abort ();
  2387. if (h != NULL)
  2388. {
  2389. bool dyn;
  2390. off = h->got.offset;
  2391. BFD_ASSERT (off != (bfd_vma) -1);
  2392. dyn = elf_hash_table (info)->dynamic_sections_created;
  2393. if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  2394. bfd_link_pic (info),
  2395. h)
  2396. || (bfd_link_pic (info)
  2397. && SYMBOL_REFERENCES_LOCAL (info, h)))
  2398. {
  2399. /* This is actually a static link, or it is a
  2400. -Bsymbolic link and the symbol is defined
  2401. locally, or the symbol was forced to be local
  2402. because of a version file. We must initialize
  2403. this entry in the global offset table. Since the
  2404. offset must always be a multiple
  2405. of 4 for 32-bit, we use the least significant bit
  2406. to record whether we have initialized it already.
  2407. When doing a dynamic link, we create a .rela.got
  2408. relocation entry to initialize the value. This
  2409. is done in the finish_dynamic_symbol routine. */
  2410. if ((off & 1) != 0)
  2411. off &= ~1;
  2412. else
  2413. {
  2414. bfd_put_32 (output_bfd, relocation,
  2415. htab->sgot->contents + off);
  2416. h->got.offset |= 1;
  2417. }
  2418. }
  2419. else
  2420. unresolved_reloc = false;
  2421. }
  2422. else
  2423. {
  2424. BFD_ASSERT (local_got_offsets != NULL
  2425. && local_got_offsets[r_symndx] != (bfd_vma) -1);
  2426. off = local_got_offsets[r_symndx];
  2427. /* The offset must always be a multiple of 4 on 32-bit.
  2428. We use the least significant bit to record
  2429. whether we have already processed this entry. */
  2430. if ((off & 1) != 0)
  2431. off &= ~1;
  2432. else
  2433. {
  2434. if (bfd_link_pic (info))
  2435. {
  2436. asection *s;
  2437. Elf_Internal_Rela outrel;
  2438. /* We need to generate a R_TILEPRO_RELATIVE reloc
  2439. for the dynamic linker. */
  2440. s = htab->srelgot;
  2441. BFD_ASSERT (s != NULL);
  2442. outrel.r_offset = (htab->sgot->output_section->vma
  2443. + htab->sgot->output_offset
  2444. + off);
  2445. outrel.r_info = ELF32_R_INFO (0, R_TILEPRO_RELATIVE);
  2446. outrel.r_addend = relocation;
  2447. relocation = 0;
  2448. tilepro_elf_append_rela_32 (output_bfd, s, &outrel);
  2449. }
  2450. bfd_put_32 (output_bfd, relocation,
  2451. htab->sgot->contents + off);
  2452. local_got_offsets[r_symndx] |= 1;
  2453. }
  2454. }
  2455. relocation = off - got_base;
  2456. break;
  2457. case R_TILEPRO_JOFFLONG_X1_PLT:
  2458. /* Relocation is to the entry for this symbol in the
  2459. procedure linkage table. */
  2460. BFD_ASSERT (h != NULL);
  2461. if (h->plt.offset == (bfd_vma) -1 || htab->splt == NULL)
  2462. {
  2463. /* We didn't make a PLT entry for this symbol. This
  2464. happens when statically linking PIC code, or when
  2465. using -Bsymbolic. */
  2466. break;
  2467. }
  2468. relocation = (htab->splt->output_section->vma
  2469. + htab->splt->output_offset
  2470. + h->plt.offset);
  2471. unresolved_reloc = false;
  2472. break;
  2473. case R_TILEPRO_32_PCREL:
  2474. case R_TILEPRO_16_PCREL:
  2475. case R_TILEPRO_8_PCREL:
  2476. case R_TILEPRO_IMM16_X0_PCREL:
  2477. case R_TILEPRO_IMM16_X1_PCREL:
  2478. case R_TILEPRO_IMM16_X0_LO_PCREL:
  2479. case R_TILEPRO_IMM16_X1_LO_PCREL:
  2480. case R_TILEPRO_IMM16_X0_HI_PCREL:
  2481. case R_TILEPRO_IMM16_X1_HI_PCREL:
  2482. case R_TILEPRO_IMM16_X0_HA_PCREL:
  2483. case R_TILEPRO_IMM16_X1_HA_PCREL:
  2484. if (h != NULL
  2485. && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
  2486. break;
  2487. /* Fall through. */
  2488. case R_TILEPRO_32:
  2489. case R_TILEPRO_16:
  2490. case R_TILEPRO_8:
  2491. case R_TILEPRO_LO16:
  2492. case R_TILEPRO_HI16:
  2493. case R_TILEPRO_HA16:
  2494. case R_TILEPRO_COPY:
  2495. case R_TILEPRO_GLOB_DAT:
  2496. case R_TILEPRO_JMP_SLOT:
  2497. case R_TILEPRO_RELATIVE:
  2498. case R_TILEPRO_BROFF_X1:
  2499. case R_TILEPRO_JOFFLONG_X1:
  2500. case R_TILEPRO_IMM8_X0:
  2501. case R_TILEPRO_IMM8_Y0:
  2502. case R_TILEPRO_IMM8_X1:
  2503. case R_TILEPRO_IMM8_Y1:
  2504. case R_TILEPRO_DEST_IMM8_X1:
  2505. case R_TILEPRO_MT_IMM15_X1:
  2506. case R_TILEPRO_MF_IMM15_X1:
  2507. case R_TILEPRO_IMM16_X0:
  2508. case R_TILEPRO_IMM16_X1:
  2509. case R_TILEPRO_IMM16_X0_LO:
  2510. case R_TILEPRO_IMM16_X1_LO:
  2511. case R_TILEPRO_IMM16_X0_HI:
  2512. case R_TILEPRO_IMM16_X1_HI:
  2513. case R_TILEPRO_IMM16_X0_HA:
  2514. case R_TILEPRO_IMM16_X1_HA:
  2515. case R_TILEPRO_MMSTART_X0:
  2516. case R_TILEPRO_MMEND_X0:
  2517. case R_TILEPRO_MMSTART_X1:
  2518. case R_TILEPRO_MMEND_X1:
  2519. case R_TILEPRO_SHAMT_X0:
  2520. case R_TILEPRO_SHAMT_X1:
  2521. case R_TILEPRO_SHAMT_Y0:
  2522. case R_TILEPRO_SHAMT_Y1:
  2523. if ((input_section->flags & SEC_ALLOC) == 0)
  2524. break;
  2525. if ((bfd_link_pic (info)
  2526. && (h == NULL
  2527. || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  2528. && !resolved_to_zero)
  2529. || h->root.type != bfd_link_hash_undefweak)
  2530. && (! howto->pc_relative
  2531. || !SYMBOL_CALLS_LOCAL (info, h)))
  2532. || (!bfd_link_pic (info)
  2533. && h != NULL
  2534. && h->dynindx != -1
  2535. && !h->non_got_ref
  2536. && ((h->def_dynamic
  2537. && !h->def_regular)
  2538. || h->root.type == bfd_link_hash_undefweak
  2539. || h->root.type == bfd_link_hash_undefined)))
  2540. {
  2541. Elf_Internal_Rela outrel;
  2542. bool skip, relocate = false;
  2543. /* When generating a shared object, these relocations
  2544. are copied into the output file to be resolved at run
  2545. time. */
  2546. BFD_ASSERT (sreloc != NULL);
  2547. skip = false;
  2548. outrel.r_offset =
  2549. _bfd_elf_section_offset (output_bfd, info, input_section,
  2550. rel->r_offset);
  2551. if (outrel.r_offset == (bfd_vma) -1)
  2552. skip = true;
  2553. else if (outrel.r_offset == (bfd_vma) -2)
  2554. skip = true, relocate = true;
  2555. outrel.r_offset += (input_section->output_section->vma
  2556. + input_section->output_offset);
  2557. switch (r_type)
  2558. {
  2559. case R_TILEPRO_32_PCREL:
  2560. case R_TILEPRO_16_PCREL:
  2561. case R_TILEPRO_8_PCREL:
  2562. /* If the symbol is not dynamic, we should not keep
  2563. a dynamic relocation. But an .rela.* slot has been
  2564. allocated for it, output R_TILEPRO_NONE.
  2565. FIXME: Add code tracking needed dynamic relocs as
  2566. e.g. i386 has. */
  2567. if (h->dynindx == -1)
  2568. skip = true, relocate = true;
  2569. break;
  2570. }
  2571. if (skip)
  2572. memset (&outrel, 0, sizeof outrel);
  2573. /* h->dynindx may be -1 if the symbol was marked to
  2574. become local. */
  2575. else if (h != NULL &&
  2576. h->dynindx != -1
  2577. && (! is_plt
  2578. || !bfd_link_pic (info)
  2579. || !SYMBOLIC_BIND (info, h)
  2580. || !h->def_regular))
  2581. {
  2582. BFD_ASSERT (h->dynindx != -1);
  2583. outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
  2584. outrel.r_addend = rel->r_addend;
  2585. }
  2586. else
  2587. {
  2588. if (r_type == R_TILEPRO_32)
  2589. {
  2590. outrel.r_info = ELF32_R_INFO (0, R_TILEPRO_RELATIVE);
  2591. outrel.r_addend = relocation + rel->r_addend;
  2592. }
  2593. else
  2594. {
  2595. long indx;
  2596. outrel.r_addend = relocation + rel->r_addend;
  2597. if (is_plt)
  2598. sec = htab->splt;
  2599. if (bfd_is_abs_section (sec))
  2600. indx = 0;
  2601. else if (sec == NULL || sec->owner == NULL)
  2602. {
  2603. bfd_set_error (bfd_error_bad_value);
  2604. return false;
  2605. }
  2606. else
  2607. {
  2608. asection *osec;
  2609. /* We are turning this relocation into one
  2610. against a section symbol. It would be
  2611. proper to subtract the symbol's value,
  2612. osec->vma, from the emitted reloc addend,
  2613. but ld.so expects buggy relocs. */
  2614. osec = sec->output_section;
  2615. indx = elf_section_data (osec)->dynindx;
  2616. if (indx == 0)
  2617. {
  2618. osec = htab->text_index_section;
  2619. indx = elf_section_data (osec)->dynindx;
  2620. }
  2621. /* FIXME: we really should be able to link non-pic
  2622. shared libraries. */
  2623. if (indx == 0)
  2624. {
  2625. BFD_FAIL ();
  2626. _bfd_error_handler
  2627. (_("%pB: probably compiled without -fPIC?"),
  2628. input_bfd);
  2629. bfd_set_error (bfd_error_bad_value);
  2630. return false;
  2631. }
  2632. }
  2633. outrel.r_info = ELF32_R_INFO (indx, r_type);
  2634. }
  2635. }
  2636. tilepro_elf_append_rela_32 (output_bfd, sreloc, &outrel);
  2637. /* This reloc will be computed at runtime, so there's no
  2638. need to do anything now. */
  2639. if (! relocate)
  2640. continue;
  2641. }
  2642. break;
  2643. case R_TILEPRO_IMM16_X0_TLS_LE:
  2644. case R_TILEPRO_IMM16_X1_TLS_LE:
  2645. case R_TILEPRO_IMM16_X0_TLS_LE_LO:
  2646. case R_TILEPRO_IMM16_X1_TLS_LE_LO:
  2647. case R_TILEPRO_IMM16_X0_TLS_LE_HI:
  2648. case R_TILEPRO_IMM16_X1_TLS_LE_HI:
  2649. case R_TILEPRO_IMM16_X0_TLS_LE_HA:
  2650. case R_TILEPRO_IMM16_X1_TLS_LE_HA:
  2651. if (!bfd_link_executable (info))
  2652. {
  2653. Elf_Internal_Rela outrel;
  2654. bool skip;
  2655. BFD_ASSERT (sreloc != NULL);
  2656. skip = false;
  2657. outrel.r_offset =
  2658. _bfd_elf_section_offset (output_bfd, info, input_section,
  2659. rel->r_offset);
  2660. if (outrel.r_offset == (bfd_vma) -1)
  2661. skip = true;
  2662. else if (outrel.r_offset == (bfd_vma) -2)
  2663. skip = true;
  2664. outrel.r_offset += (input_section->output_section->vma
  2665. + input_section->output_offset);
  2666. if (skip)
  2667. memset (&outrel, 0, sizeof outrel);
  2668. else
  2669. {
  2670. outrel.r_info = ELF32_R_INFO (0, r_type);
  2671. outrel.r_addend = relocation - dtpoff_base (info)
  2672. + rel->r_addend;
  2673. }
  2674. tilepro_elf_append_rela_32 (output_bfd, sreloc, &outrel);
  2675. continue;
  2676. }
  2677. relocation = tpoff (info, relocation);
  2678. break;
  2679. case R_TILEPRO_IMM16_X0_TLS_GD:
  2680. case R_TILEPRO_IMM16_X1_TLS_GD:
  2681. case R_TILEPRO_IMM16_X0_TLS_GD_LO:
  2682. case R_TILEPRO_IMM16_X1_TLS_GD_LO:
  2683. case R_TILEPRO_IMM16_X0_TLS_GD_HI:
  2684. case R_TILEPRO_IMM16_X1_TLS_GD_HI:
  2685. case R_TILEPRO_IMM16_X0_TLS_GD_HA:
  2686. case R_TILEPRO_IMM16_X1_TLS_GD_HA:
  2687. case R_TILEPRO_IMM16_X0_TLS_IE:
  2688. case R_TILEPRO_IMM16_X1_TLS_IE:
  2689. case R_TILEPRO_IMM16_X0_TLS_IE_LO:
  2690. case R_TILEPRO_IMM16_X1_TLS_IE_LO:
  2691. case R_TILEPRO_IMM16_X0_TLS_IE_HI:
  2692. case R_TILEPRO_IMM16_X1_TLS_IE_HI:
  2693. case R_TILEPRO_IMM16_X0_TLS_IE_HA:
  2694. case R_TILEPRO_IMM16_X1_TLS_IE_HA:
  2695. r_type = tilepro_elf_tls_transition (info, r_type, h == NULL);
  2696. tls_type = GOT_UNKNOWN;
  2697. if (h == NULL && local_got_offsets)
  2698. tls_type
  2699. = _bfd_tilepro_elf_local_got_tls_type (input_bfd) [r_symndx];
  2700. else if (h != NULL)
  2701. {
  2702. tls_type = tilepro_elf_hash_entry(h)->tls_type;
  2703. if (bfd_link_executable (info)
  2704. && h->dynindx == -1
  2705. && tls_type == GOT_TLS_IE)
  2706. r_type = tilepro_tls_translate_to_le (r_type);
  2707. }
  2708. if (tls_type == GOT_TLS_IE)
  2709. r_type = tilepro_tls_translate_to_ie (r_type);
  2710. if (r_type == R_TILEPRO_IMM16_X0_TLS_LE
  2711. || r_type == R_TILEPRO_IMM16_X1_TLS_LE
  2712. || r_type == R_TILEPRO_IMM16_X0_TLS_LE_LO
  2713. || r_type == R_TILEPRO_IMM16_X1_TLS_LE_LO
  2714. || r_type == R_TILEPRO_IMM16_X0_TLS_LE_HI
  2715. || r_type == R_TILEPRO_IMM16_X1_TLS_LE_HI
  2716. || r_type == R_TILEPRO_IMM16_X0_TLS_LE_HA
  2717. || r_type == R_TILEPRO_IMM16_X1_TLS_LE_HA)
  2718. {
  2719. relocation = tpoff (info, relocation);
  2720. break;
  2721. }
  2722. if (h != NULL)
  2723. {
  2724. off = h->got.offset;
  2725. h->got.offset |= 1;
  2726. }
  2727. else
  2728. {
  2729. BFD_ASSERT (local_got_offsets != NULL);
  2730. off = local_got_offsets[r_symndx];
  2731. local_got_offsets[r_symndx] |= 1;
  2732. }
  2733. if (htab->sgot == NULL)
  2734. abort ();
  2735. if ((off & 1) != 0)
  2736. off &= ~1;
  2737. else
  2738. {
  2739. Elf_Internal_Rela outrel;
  2740. int indx = 0;
  2741. bool need_relocs = false;
  2742. if (htab->srelgot == NULL)
  2743. abort ();
  2744. if (h != NULL)
  2745. {
  2746. bool dyn;
  2747. dyn = htab->dynamic_sections_created;
  2748. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  2749. bfd_link_pic (info),
  2750. h)
  2751. && (!bfd_link_pic (info)
  2752. || !SYMBOL_REFERENCES_LOCAL (info, h)))
  2753. {
  2754. indx = h->dynindx;
  2755. }
  2756. }
  2757. /* The GOT entries have not been initialized yet. Do it
  2758. now, and emit any relocations. */
  2759. if ((bfd_link_pic (info) || indx != 0)
  2760. && (h == NULL
  2761. || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  2762. || h->root.type != bfd_link_hash_undefweak))
  2763. need_relocs = true;
  2764. switch (r_type)
  2765. {
  2766. case R_TILEPRO_IMM16_X0_TLS_IE:
  2767. case R_TILEPRO_IMM16_X1_TLS_IE:
  2768. case R_TILEPRO_IMM16_X0_TLS_IE_LO:
  2769. case R_TILEPRO_IMM16_X1_TLS_IE_LO:
  2770. case R_TILEPRO_IMM16_X0_TLS_IE_HI:
  2771. case R_TILEPRO_IMM16_X1_TLS_IE_HI:
  2772. case R_TILEPRO_IMM16_X0_TLS_IE_HA:
  2773. case R_TILEPRO_IMM16_X1_TLS_IE_HA:
  2774. if (need_relocs) {
  2775. bfd_put_32 (output_bfd, 0, htab->sgot->contents + off);
  2776. outrel.r_offset = (htab->sgot->output_section->vma
  2777. + htab->sgot->output_offset + off);
  2778. outrel.r_addend = 0;
  2779. if (indx == 0)
  2780. outrel.r_addend = relocation - dtpoff_base (info);
  2781. outrel.r_info = ELF32_R_INFO (indx, R_TILEPRO_TLS_TPOFF32);
  2782. tilepro_elf_append_rela_32 (output_bfd, htab->srelgot,
  2783. &outrel);
  2784. } else {
  2785. bfd_put_32 (output_bfd, tpoff (info, relocation),
  2786. htab->sgot->contents + off);
  2787. }
  2788. break;
  2789. case R_TILEPRO_IMM16_X0_TLS_GD:
  2790. case R_TILEPRO_IMM16_X1_TLS_GD:
  2791. case R_TILEPRO_IMM16_X0_TLS_GD_LO:
  2792. case R_TILEPRO_IMM16_X1_TLS_GD_LO:
  2793. case R_TILEPRO_IMM16_X0_TLS_GD_HI:
  2794. case R_TILEPRO_IMM16_X1_TLS_GD_HI:
  2795. case R_TILEPRO_IMM16_X0_TLS_GD_HA:
  2796. case R_TILEPRO_IMM16_X1_TLS_GD_HA:
  2797. if (need_relocs) {
  2798. outrel.r_offset = (htab->sgot->output_section->vma
  2799. + htab->sgot->output_offset + off);
  2800. outrel.r_addend = 0;
  2801. outrel.r_info = ELF32_R_INFO (indx, R_TILEPRO_TLS_DTPMOD32);
  2802. bfd_put_32 (output_bfd, 0, htab->sgot->contents + off);
  2803. tilepro_elf_append_rela_32 (output_bfd, htab->srelgot,
  2804. &outrel);
  2805. if (indx == 0)
  2806. {
  2807. BFD_ASSERT (! unresolved_reloc);
  2808. bfd_put_32 (output_bfd,
  2809. relocation - dtpoff_base (info),
  2810. (htab->sgot->contents + off +
  2811. TILEPRO_BYTES_PER_WORD));
  2812. }
  2813. else
  2814. {
  2815. bfd_put_32 (output_bfd, 0,
  2816. (htab->sgot->contents + off +
  2817. TILEPRO_BYTES_PER_WORD));
  2818. outrel.r_info = ELF32_R_INFO (indx,
  2819. R_TILEPRO_TLS_DTPOFF32);
  2820. outrel.r_offset += TILEPRO_BYTES_PER_WORD;
  2821. tilepro_elf_append_rela_32 (output_bfd,
  2822. htab->srelgot, &outrel);
  2823. }
  2824. }
  2825. else {
  2826. /* If we are not emitting relocations for a
  2827. general dynamic reference, then we must be in a
  2828. static link or an executable link with the
  2829. symbol binding locally. Mark it as belonging
  2830. to module 1, the executable. */
  2831. bfd_put_32 (output_bfd, 1,
  2832. htab->sgot->contents + off );
  2833. bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
  2834. htab->sgot->contents + off +
  2835. TILEPRO_BYTES_PER_WORD);
  2836. }
  2837. break;
  2838. }
  2839. }
  2840. if (off >= (bfd_vma) -2)
  2841. abort ();
  2842. relocation = off - got_base;
  2843. unresolved_reloc = false;
  2844. howto = tilepro_elf_howto_table + r_type;
  2845. break;
  2846. default:
  2847. break;
  2848. }
  2849. /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
  2850. because such sections are not SEC_ALLOC and thus ld.so will
  2851. not process them. */
  2852. if (unresolved_reloc
  2853. && !((input_section->flags & SEC_DEBUGGING) != 0
  2854. && h->def_dynamic)
  2855. && _bfd_elf_section_offset (output_bfd, info, input_section,
  2856. rel->r_offset) != (bfd_vma) -1)
  2857. _bfd_error_handler
  2858. /* xgettext:c-format */
  2859. (_("%pB(%pA+%#" PRIx64 "): "
  2860. "unresolvable %s relocation against symbol `%s'"),
  2861. input_bfd,
  2862. input_section,
  2863. (uint64_t) rel->r_offset,
  2864. howto->name,
  2865. h->root.root.string);
  2866. r = bfd_reloc_continue;
  2867. /* For the _HA types, we add 0x8000 so that if bit 15 is set,
  2868. * we will increment bit 16. The howto->rightshift takes care
  2869. * of the rest for us. */
  2870. switch (r_type)
  2871. {
  2872. case R_TILEPRO_HA16:
  2873. case R_TILEPRO_IMM16_X0_HA:
  2874. case R_TILEPRO_IMM16_X1_HA:
  2875. case R_TILEPRO_IMM16_X0_HA_PCREL:
  2876. case R_TILEPRO_IMM16_X1_HA_PCREL:
  2877. case R_TILEPRO_IMM16_X0_GOT_HA:
  2878. case R_TILEPRO_IMM16_X1_GOT_HA:
  2879. case R_TILEPRO_IMM16_X0_TLS_GD_HA:
  2880. case R_TILEPRO_IMM16_X1_TLS_GD_HA:
  2881. case R_TILEPRO_IMM16_X0_TLS_IE_HA:
  2882. case R_TILEPRO_IMM16_X1_TLS_IE_HA:
  2883. relocation += 0x8000;
  2884. break;
  2885. }
  2886. /* Get the operand creation function, if any. */
  2887. create_func = reloc_to_create_func[r_type];
  2888. if (create_func == NULL)
  2889. {
  2890. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  2891. contents, rel->r_offset,
  2892. relocation, rel->r_addend);
  2893. }
  2894. else
  2895. {
  2896. if (howto->pc_relative)
  2897. {
  2898. relocation -=
  2899. input_section->output_section->vma + input_section->output_offset;
  2900. if (howto->pcrel_offset)
  2901. relocation -= rel->r_offset;
  2902. }
  2903. bfd_byte *data;
  2904. /* Add the relocation addend if any to the final target value */
  2905. relocation += rel->r_addend;
  2906. /* Do basic range checking */
  2907. r = bfd_check_overflow (howto->complain_on_overflow,
  2908. howto->bitsize,
  2909. howto->rightshift,
  2910. 32,
  2911. relocation);
  2912. /*
  2913. * Write the relocated value out into the raw section data.
  2914. * Don't put a relocation out in the .rela section.
  2915. */
  2916. tilepro_bundle_bits mask = create_func(-1);
  2917. tilepro_bundle_bits value = create_func(relocation >> howto->rightshift);
  2918. /* Only touch bytes while the mask is not 0, so we
  2919. don't write to out of bounds memory if this is actually
  2920. a 16-bit switch instruction. */
  2921. for (data = contents + rel->r_offset; mask != 0; data++)
  2922. {
  2923. bfd_byte byte_mask = (bfd_byte)mask;
  2924. *data = (*data & ~byte_mask) | ((bfd_byte)value & byte_mask);
  2925. mask >>= 8;
  2926. value >>= 8;
  2927. }
  2928. }
  2929. if (r != bfd_reloc_ok)
  2930. {
  2931. const char *msg = NULL;
  2932. switch (r)
  2933. {
  2934. case bfd_reloc_overflow:
  2935. (*info->callbacks->reloc_overflow)
  2936. (info, (h ? &h->root : NULL), name, howto->name,
  2937. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  2938. break;
  2939. case bfd_reloc_undefined:
  2940. (*info->callbacks->undefined_symbol)
  2941. (info, name, input_bfd, input_section, rel->r_offset, true);
  2942. break;
  2943. case bfd_reloc_outofrange:
  2944. msg = _("internal error: out of range error");
  2945. break;
  2946. case bfd_reloc_notsupported:
  2947. msg = _("internal error: unsupported relocation error");
  2948. break;
  2949. case bfd_reloc_dangerous:
  2950. msg = _("internal error: dangerous relocation");
  2951. break;
  2952. default:
  2953. msg = _("internal error: unknown error");
  2954. break;
  2955. }
  2956. if (msg)
  2957. (*info->callbacks->warning) (info, msg, name, input_bfd,
  2958. input_section, rel->r_offset);
  2959. }
  2960. }
  2961. return true;
  2962. }
  2963. /* Finish up dynamic symbol handling. We set the contents of various
  2964. dynamic sections here. */
  2965. static bool
  2966. tilepro_elf_finish_dynamic_symbol (bfd *output_bfd,
  2967. struct bfd_link_info *info,
  2968. struct elf_link_hash_entry *h,
  2969. Elf_Internal_Sym *sym)
  2970. {
  2971. struct elf_link_hash_table *htab;
  2972. htab = tilepro_elf_hash_table (info);
  2973. BFD_ASSERT (htab != NULL);
  2974. if (h->plt.offset != (bfd_vma) -1)
  2975. {
  2976. asection *splt;
  2977. asection *srela;
  2978. asection *sgotplt;
  2979. Elf_Internal_Rela rela;
  2980. bfd_byte *loc;
  2981. bfd_vma r_offset;
  2982. int rela_index;
  2983. /* This symbol has an entry in the PLT. Set it up. */
  2984. BFD_ASSERT (h->dynindx != -1);
  2985. splt = htab->splt;
  2986. srela = htab->srelplt;
  2987. sgotplt = htab->sgotplt;
  2988. if (splt == NULL || srela == NULL)
  2989. abort ();
  2990. /* Fill in the entry in the procedure linkage table. */
  2991. rela_index = tilepro_plt_entry_build (splt, sgotplt, h->plt.offset,
  2992. &r_offset);
  2993. /* Fill in the entry in the global offset table, which initially points
  2994. to the beginning of the plt. */
  2995. bfd_put_32 (output_bfd, splt->output_section->vma + splt->output_offset,
  2996. sgotplt->contents + r_offset);
  2997. /* Fill in the entry in the .rela.plt section. */
  2998. rela.r_offset = (sgotplt->output_section->vma
  2999. + sgotplt->output_offset
  3000. + r_offset);
  3001. rela.r_addend = 0;
  3002. rela.r_info = ELF32_R_INFO (h->dynindx, R_TILEPRO_JMP_SLOT);
  3003. loc = srela->contents + rela_index * sizeof (Elf32_External_Rela);
  3004. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  3005. if (!h->def_regular)
  3006. {
  3007. /* Mark the symbol as undefined, rather than as defined in
  3008. the .plt section. Leave the value alone. */
  3009. sym->st_shndx = SHN_UNDEF;
  3010. /* If the symbol is weak, we do need to clear the value.
  3011. Otherwise, the PLT entry would provide a definition for
  3012. the symbol even if the symbol wasn't defined anywhere,
  3013. and so the symbol would never be NULL. */
  3014. if (!h->ref_regular_nonweak)
  3015. sym->st_value = 0;
  3016. }
  3017. }
  3018. if (h->got.offset != (bfd_vma) -1
  3019. && tilepro_elf_hash_entry(h)->tls_type != GOT_TLS_GD
  3020. && tilepro_elf_hash_entry(h)->tls_type != GOT_TLS_IE)
  3021. {
  3022. asection *sgot;
  3023. asection *srela;
  3024. Elf_Internal_Rela rela;
  3025. /* This symbol has an entry in the GOT. Set it up. */
  3026. sgot = htab->sgot;
  3027. srela = htab->srelgot;
  3028. BFD_ASSERT (sgot != NULL && srela != NULL);
  3029. rela.r_offset = (sgot->output_section->vma
  3030. + sgot->output_offset
  3031. + (h->got.offset &~ (bfd_vma) 1));
  3032. /* If this is a -Bsymbolic link, and the symbol is defined
  3033. locally, we just want to emit a RELATIVE reloc. Likewise if
  3034. the symbol was forced to be local because of a version file.
  3035. The entry in the global offset table will already have been
  3036. initialized in the relocate_section function. */
  3037. if (bfd_link_pic (info)
  3038. && (info->symbolic || h->dynindx == -1)
  3039. && h->def_regular)
  3040. {
  3041. asection *sec = h->root.u.def.section;
  3042. rela.r_info = ELF32_R_INFO (0, R_TILEPRO_RELATIVE);
  3043. rela.r_addend = (h->root.u.def.value
  3044. + sec->output_section->vma
  3045. + sec->output_offset);
  3046. }
  3047. else
  3048. {
  3049. rela.r_info = ELF32_R_INFO (h->dynindx, R_TILEPRO_GLOB_DAT);
  3050. rela.r_addend = 0;
  3051. }
  3052. bfd_put_32 (output_bfd, 0,
  3053. sgot->contents + (h->got.offset & ~(bfd_vma) 1));
  3054. tilepro_elf_append_rela_32 (output_bfd, srela, &rela);
  3055. }
  3056. if (h->needs_copy)
  3057. {
  3058. asection *s;
  3059. Elf_Internal_Rela rela;
  3060. /* This symbols needs a copy reloc. Set it up. */
  3061. BFD_ASSERT (h->dynindx != -1);
  3062. rela.r_offset = (h->root.u.def.value
  3063. + h->root.u.def.section->output_section->vma
  3064. + h->root.u.def.section->output_offset);
  3065. rela.r_info = ELF32_R_INFO (h->dynindx, R_TILEPRO_COPY);
  3066. rela.r_addend = 0;
  3067. if (h->root.u.def.section == htab->sdynrelro)
  3068. s = htab->sreldynrelro;
  3069. else
  3070. s = htab->srelbss;
  3071. tilepro_elf_append_rela_32 (output_bfd, s, &rela);
  3072. }
  3073. /* Mark some specially defined symbols as absolute. */
  3074. if (h == htab->hdynamic
  3075. || (h == htab->hgot || h == htab->hplt))
  3076. sym->st_shndx = SHN_ABS;
  3077. return true;
  3078. }
  3079. /* Finish up the dynamic sections. */
  3080. static bool
  3081. tilepro_finish_dyn (bfd *output_bfd, struct bfd_link_info *info,
  3082. bfd *dynobj, asection *sdyn,
  3083. asection *splt ATTRIBUTE_UNUSED)
  3084. {
  3085. Elf32_External_Dyn *dyncon, *dynconend;
  3086. struct elf_link_hash_table *htab;
  3087. htab = tilepro_elf_hash_table (info);
  3088. BFD_ASSERT (htab != NULL);
  3089. dyncon = (Elf32_External_Dyn *) sdyn->contents;
  3090. dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
  3091. for (; dyncon < dynconend; dyncon++)
  3092. {
  3093. Elf_Internal_Dyn dyn;
  3094. asection *s;
  3095. bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
  3096. switch (dyn.d_tag)
  3097. {
  3098. case DT_PLTGOT:
  3099. s = htab->sgotplt;
  3100. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  3101. break;
  3102. case DT_JMPREL:
  3103. s = htab->srelplt;
  3104. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  3105. break;
  3106. case DT_PLTRELSZ:
  3107. s = htab->srelplt;
  3108. dyn.d_un.d_val = s->size;
  3109. break;
  3110. default:
  3111. continue;
  3112. }
  3113. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  3114. }
  3115. return true;
  3116. }
  3117. static bool
  3118. tilepro_elf_finish_dynamic_sections (bfd *output_bfd,
  3119. struct bfd_link_info *info)
  3120. {
  3121. bfd *dynobj;
  3122. asection *sdyn;
  3123. struct elf_link_hash_table *htab;
  3124. htab = tilepro_elf_hash_table (info);
  3125. BFD_ASSERT (htab != NULL);
  3126. dynobj = htab->dynobj;
  3127. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  3128. if (elf_hash_table (info)->dynamic_sections_created)
  3129. {
  3130. asection *splt;
  3131. bool ret;
  3132. splt = htab->splt;
  3133. BFD_ASSERT (splt != NULL && sdyn != NULL);
  3134. ret = tilepro_finish_dyn (output_bfd, info, dynobj, sdyn, splt);
  3135. if (!ret)
  3136. return ret;
  3137. /* Fill in the first entry in the procedure linkage table. */
  3138. if (splt->size > 0)
  3139. {
  3140. memcpy (splt->contents, tilepro_plt0_entry, PLT_HEADER_SIZE);
  3141. memset (splt->contents + PLT_HEADER_SIZE, 0,
  3142. PLT_ENTRY_SIZE - PLT_HEADER_SIZE);
  3143. }
  3144. if (elf_section_data (splt->output_section) != NULL)
  3145. elf_section_data (splt->output_section)->this_hdr.sh_entsize
  3146. = PLT_ENTRY_SIZE;
  3147. }
  3148. if (htab->sgotplt)
  3149. {
  3150. if (bfd_is_abs_section (htab->sgotplt->output_section))
  3151. {
  3152. _bfd_error_handler
  3153. (_("discarded output section: `%pA'"), htab->sgotplt);
  3154. return false;
  3155. }
  3156. if (htab->sgotplt->size > 0)
  3157. {
  3158. /* Write the first two entries in .got.plt, needed for the dynamic
  3159. linker. */
  3160. bfd_put_32 (output_bfd, (bfd_vma) -1,
  3161. htab->sgotplt->contents);
  3162. bfd_put_32 (output_bfd, (bfd_vma) 0,
  3163. htab->sgotplt->contents + GOT_ENTRY_SIZE);
  3164. }
  3165. elf_section_data (htab->sgotplt->output_section)->this_hdr.sh_entsize
  3166. = GOT_ENTRY_SIZE;
  3167. }
  3168. if (htab->sgot)
  3169. {
  3170. if (htab->sgot->size > 0)
  3171. {
  3172. /* Set the first entry in the global offset table to the address of
  3173. the dynamic section. */
  3174. bfd_vma val = (sdyn ?
  3175. sdyn->output_section->vma + sdyn->output_offset :
  3176. 0);
  3177. bfd_put_32 (output_bfd, val, htab->sgot->contents);
  3178. }
  3179. elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize
  3180. = GOT_ENTRY_SIZE;
  3181. }
  3182. return true;
  3183. }
  3184. /* Return address for Ith PLT stub in section PLT, for relocation REL
  3185. or (bfd_vma) -1 if it should not be included. */
  3186. static bfd_vma
  3187. tilepro_elf_plt_sym_val (bfd_vma i, const asection *plt,
  3188. const arelent *rel ATTRIBUTE_UNUSED)
  3189. {
  3190. return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
  3191. }
  3192. static enum elf_reloc_type_class
  3193. tilepro_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
  3194. const asection *rel_sec ATTRIBUTE_UNUSED,
  3195. const Elf_Internal_Rela *rela)
  3196. {
  3197. switch ((int) ELF32_R_TYPE (rela->r_info))
  3198. {
  3199. case R_TILEPRO_RELATIVE:
  3200. return reloc_class_relative;
  3201. case R_TILEPRO_JMP_SLOT:
  3202. return reloc_class_plt;
  3203. case R_TILEPRO_COPY:
  3204. return reloc_class_copy;
  3205. default:
  3206. return reloc_class_normal;
  3207. }
  3208. }
  3209. static int
  3210. tilepro_additional_program_headers (bfd *abfd,
  3211. struct bfd_link_info *info ATTRIBUTE_UNUSED)
  3212. {
  3213. /* Each .intrpt section specified by the user adds another PT_LOAD
  3214. header since the sections are discontiguous. */
  3215. static const char intrpt_sections[4][9] =
  3216. {
  3217. ".intrpt0", ".intrpt1", ".intrpt2", ".intrpt3"
  3218. };
  3219. int count = 0;
  3220. int i;
  3221. for (i = 0; i < 4; i++)
  3222. {
  3223. asection *sec = bfd_get_section_by_name (abfd, intrpt_sections[i]);
  3224. if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
  3225. ++count;
  3226. }
  3227. /* Add four "padding" headers in to leave room in case a custom linker
  3228. script does something fancy. Otherwise ld complains that it ran
  3229. out of program headers and refuses to link. */
  3230. count += 4;
  3231. return count;
  3232. }
  3233. #define ELF_ARCH bfd_arch_tilepro
  3234. #define ELF_TARGET_ID TILEPRO_ELF_DATA
  3235. #define ELF_MACHINE_CODE EM_TILEPRO
  3236. #define ELF_MAXPAGESIZE 0x10000
  3237. #define ELF_COMMONPAGESIZE 0x10000
  3238. #define TARGET_LITTLE_SYM tilepro_elf32_vec
  3239. #define TARGET_LITTLE_NAME "elf32-tilepro"
  3240. #define elf_backend_reloc_type_class tilepro_reloc_type_class
  3241. #define bfd_elf32_bfd_reloc_name_lookup tilepro_reloc_name_lookup
  3242. #define bfd_elf32_bfd_link_hash_table_create tilepro_elf_link_hash_table_create
  3243. #define bfd_elf32_bfd_reloc_type_lookup tilepro_reloc_type_lookup
  3244. #define elf_backend_copy_indirect_symbol tilepro_elf_copy_indirect_symbol
  3245. #define elf_backend_create_dynamic_sections tilepro_elf_create_dynamic_sections
  3246. #define elf_backend_check_relocs tilepro_elf_check_relocs
  3247. #define elf_backend_adjust_dynamic_symbol tilepro_elf_adjust_dynamic_symbol
  3248. #define elf_backend_omit_section_dynsym tilepro_elf_omit_section_dynsym
  3249. #define elf_backend_size_dynamic_sections tilepro_elf_size_dynamic_sections
  3250. #define elf_backend_relocate_section tilepro_elf_relocate_section
  3251. #define elf_backend_finish_dynamic_symbol tilepro_elf_finish_dynamic_symbol
  3252. #define elf_backend_finish_dynamic_sections tilepro_elf_finish_dynamic_sections
  3253. #define elf_backend_gc_mark_hook tilepro_elf_gc_mark_hook
  3254. #define elf_backend_plt_sym_val tilepro_elf_plt_sym_val
  3255. #define elf_info_to_howto_rel NULL
  3256. #define elf_info_to_howto tilepro_info_to_howto_rela
  3257. #define elf_backend_grok_prstatus tilepro_elf_grok_prstatus
  3258. #define elf_backend_grok_psinfo tilepro_elf_grok_psinfo
  3259. #define elf_backend_additional_program_headers tilepro_additional_program_headers
  3260. #define bfd_elf32_mkobject tilepro_elf_mkobject
  3261. #define elf_backend_init_index_section _bfd_elf_init_1_index_section
  3262. #define elf_backend_can_gc_sections 1
  3263. #define elf_backend_can_refcount 1
  3264. #define elf_backend_want_got_plt 1
  3265. #define elf_backend_plt_readonly 1
  3266. /* Align PLT mod 64 byte L2 line size. */
  3267. #define elf_backend_plt_alignment 6
  3268. #define elf_backend_want_plt_sym 1
  3269. #define elf_backend_got_header_size GOT_ENTRY_SIZE
  3270. #define elf_backend_want_dynrelro 1
  3271. #define elf_backend_rela_normal 1
  3272. #define elf_backend_default_execstack 0
  3273. #include "elf32-target.h"