elfxx-tilegx.c 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133
  1. /* TILE-Gx-specific support for 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/tilegx.h"
  21. #include "opcode/tilegx.h"
  22. #include "libiberty.h"
  23. #include "elfxx-tilegx.h"
  24. #define ABI_64_P(abfd) \
  25. (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
  26. #define TILEGX_ELF_WORD_BYTES(htab) \
  27. ((htab)->bytes_per_word)
  28. /* The size of an external RELA relocation. */
  29. #define TILEGX_ELF_RELA_BYTES(htab) \
  30. ((htab)->bytes_per_rela)
  31. /* Both 32-bit and 64-bit tilegx encode this in an identical manner,
  32. so just take advantage of that. */
  33. #define TILEGX_ELF_R_TYPE(r_info) \
  34. ((r_info) & 0xFF)
  35. #define TILEGX_ELF_R_INFO(htab, in_rel, index, type) \
  36. ((htab)->r_info (in_rel, index, type))
  37. #define TILEGX_ELF_R_SYMNDX(htab, r_info) \
  38. ((htab)->r_symndx(r_info))
  39. #define TILEGX_ELF_DTPOFF_RELOC(htab) \
  40. ((htab)->dtpoff_reloc)
  41. #define TILEGX_ELF_DTPMOD_RELOC(htab) \
  42. ((htab)->dtpmod_reloc)
  43. #define TILEGX_ELF_TPOFF_RELOC(htab) \
  44. ((htab)->tpoff_reloc)
  45. #define TILEGX_ELF_PUT_WORD(htab, bfd, val, ptr) \
  46. ((htab)->put_word (bfd, val, ptr))
  47. /* The name of the dynamic interpreter. This is put in the .interp
  48. section. */
  49. #define ELF64_DYNAMIC_INTERPRETER "/lib/ld.so.1"
  50. #define ELF32_DYNAMIC_INTERPRETER "/lib32/ld.so.1"
  51. static reloc_howto_type tilegx_elf_howto_table [] =
  52. {
  53. /* This reloc does nothing. */
  54. HOWTO (R_TILEGX_NONE, /* type */
  55. 0, /* rightshift */
  56. 3, /* size (0 = byte, 1 = short, 2 = long) */
  57. 0, /* bitsize */
  58. false, /* pc_relative */
  59. 0, /* bitpos */
  60. complain_overflow_dont, /* complain_on_overflow */
  61. bfd_elf_generic_reloc, /* special_function */
  62. "R_TILEGX_NONE", /* name */
  63. false, /* partial_inplace */
  64. 0, /* src_mask */
  65. 0, /* dst_mask */
  66. false), /* pcrel_offset */
  67. #ifdef BFD64
  68. /* A 64 bit absolute relocation. */
  69. HOWTO (R_TILEGX_64, /* type */
  70. 0, /* rightshift */
  71. 4, /* size (0 = byte, 1 = short, 2 = long) */
  72. 64, /* bitsize */
  73. false, /* pc_relative */
  74. 0, /* bitpos */
  75. complain_overflow_dont, /* complain_on_overflow */
  76. bfd_elf_generic_reloc, /* special_function */
  77. "R_TILEGX_64", /* name */
  78. false, /* partial_inplace */
  79. 0, /* src_mask */
  80. 0xffffffffffffffffULL, /* dst_mask */
  81. false), /* pcrel_offset */
  82. #endif
  83. /* A 32 bit absolute relocation. */
  84. HOWTO (R_TILEGX_32, /* type */
  85. 0, /* rightshift */
  86. 2, /* size (0 = byte, 1 = short, 2 = long) */
  87. 32, /* bitsize */
  88. false, /* pc_relative */
  89. 0, /* bitpos */
  90. complain_overflow_dont, /* complain_on_overflow */
  91. bfd_elf_generic_reloc, /* special_function */
  92. "R_TILEGX_32", /* name */
  93. false, /* partial_inplace */
  94. 0, /* src_mask */
  95. 0xffffffff, /* dst_mask */
  96. false), /* pcrel_offset */
  97. /* A 16 bit absolute relocation. */
  98. HOWTO (R_TILEGX_16, /* type */
  99. 0, /* rightshift */
  100. 1, /* size (0 = byte, 1 = short, 2 = long) */
  101. 16, /* bitsize */
  102. false, /* pc_relative */
  103. 0, /* bitpos */
  104. complain_overflow_bitfield, /* complain_on_overflow */
  105. bfd_elf_generic_reloc, /* special_function */
  106. "R_TILEGX_16", /* name */
  107. false, /* partial_inplace */
  108. 0, /* src_mask */
  109. 0xffff, /* dst_mask */
  110. false), /* pcrel_offset */
  111. /* An 8 bit absolute relocation. */
  112. HOWTO (R_TILEGX_8, /* type */
  113. 0, /* rightshift */
  114. 0, /* size (0 = byte, 1 = short, 2 = long) */
  115. 8, /* bitsize */
  116. false, /* pc_relative */
  117. 0, /* bitpos */
  118. complain_overflow_unsigned, /* complain_on_overflow */
  119. bfd_elf_generic_reloc, /* special_function */
  120. "R_TILEGX_8", /* name */
  121. false, /* partial_inplace */
  122. 0, /* src_mask */
  123. 0xff, /* dst_mask */
  124. false), /* pcrel_offset */
  125. #ifdef BFD64
  126. /* A 64 bit pc-relative relocation. */
  127. HOWTO (R_TILEGX_64_PCREL,/* type */
  128. 0, /* rightshift */
  129. 4, /* size (0 = byte, 1 = short, 2 = long) */
  130. 64, /* bitsize */
  131. true, /* pc_relative */
  132. 0, /* bitpos */
  133. complain_overflow_dont, /* complain_on_overflow */
  134. bfd_elf_generic_reloc, /* special_function */
  135. "R_TILEGX_32_PCREL", /* name */
  136. false, /* partial_inplace */
  137. 0, /* src_mask */
  138. 0xffffffffffffffffULL, /* dst_mask */
  139. true), /* pcrel_offset */
  140. #endif
  141. /* A 32 bit pc-relative relocation. */
  142. HOWTO (R_TILEGX_32_PCREL,/* type */
  143. 0, /* rightshift */
  144. 2, /* size (0 = byte, 1 = short, 2 = long) */
  145. 32, /* bitsize */
  146. true, /* pc_relative */
  147. 0, /* bitpos */
  148. complain_overflow_dont, /* complain_on_overflow */
  149. bfd_elf_generic_reloc, /* special_function */
  150. "R_TILEGX_32_PCREL", /* name */
  151. false, /* partial_inplace */
  152. 0, /* src_mask */
  153. 0xffffffff, /* dst_mask */
  154. true), /* pcrel_offset */
  155. /* A 16 bit pc-relative relocation. */
  156. HOWTO (R_TILEGX_16_PCREL,/* type */
  157. 0, /* rightshift */
  158. 1, /* size (0 = byte, 1 = short, 2 = long) */
  159. 16, /* bitsize */
  160. true, /* pc_relative */
  161. 0, /* bitpos */
  162. complain_overflow_signed, /* complain_on_overflow */
  163. bfd_elf_generic_reloc, /* special_function */
  164. "R_TILEGX_16_PCREL", /* name */
  165. false, /* partial_inplace */
  166. 0, /* src_mask */
  167. 0xffff, /* dst_mask */
  168. true), /* pcrel_offset */
  169. /* An 8 bit pc-relative relocation. */
  170. HOWTO (R_TILEGX_8_PCREL, /* type */
  171. 0, /* rightshift */
  172. 0, /* size (0 = byte, 1 = short, 2 = long) */
  173. 8, /* bitsize */
  174. true, /* pc_relative */
  175. 0, /* bitpos */
  176. complain_overflow_signed, /* complain_on_overflow */
  177. bfd_elf_generic_reloc, /* special_function */
  178. "R_TILEGX_8_PCREL",/* name */
  179. false, /* partial_inplace */
  180. 0, /* src_mask */
  181. 0xff, /* dst_mask */
  182. true), /* pcrel_offset */
  183. /* A 16 bit relocation without overflow. */
  184. HOWTO (R_TILEGX_HW0, /* type */
  185. 0, /* rightshift */
  186. 1, /* size (0 = byte, 1 = short, 2 = long) */
  187. 16, /* bitsize */
  188. false, /* pc_relative */
  189. 0, /* bitpos */
  190. complain_overflow_dont,/* complain_on_overflow */
  191. bfd_elf_generic_reloc, /* special_function */
  192. "R_TILEGX_HW0", /* name */
  193. false, /* partial_inplace */
  194. 0, /* src_mask */
  195. 0xffff, /* dst_mask */
  196. false), /* pcrel_offset */
  197. /* A 16 bit relocation without overflow. */
  198. HOWTO (R_TILEGX_HW1, /* type */
  199. 16, /* rightshift */
  200. 1, /* size (0 = byte, 1 = short, 2 = long) */
  201. 16, /* bitsize */
  202. false, /* pc_relative */
  203. 0, /* bitpos */
  204. complain_overflow_dont,/* complain_on_overflow */
  205. bfd_elf_generic_reloc, /* special_function */
  206. "R_TILEGX_HW1", /* name */
  207. false, /* partial_inplace */
  208. 0, /* src_mask */
  209. 0xffff, /* dst_mask */
  210. false), /* pcrel_offset */
  211. /* A 16 bit relocation without overflow. */
  212. HOWTO (R_TILEGX_HW2, /* type */
  213. 32, /* rightshift */
  214. 1, /* size (0 = byte, 1 = short, 2 = long) */
  215. 16, /* bitsize */
  216. false, /* pc_relative */
  217. 0, /* bitpos */
  218. complain_overflow_dont,/* complain_on_overflow */
  219. bfd_elf_generic_reloc, /* special_function */
  220. "R_TILEGX_HW2", /* name */
  221. false, /* partial_inplace */
  222. 0, /* src_mask */
  223. 0xffff, /* dst_mask */
  224. false), /* pcrel_offset */
  225. /* A 16 bit relocation without overflow. */
  226. HOWTO (R_TILEGX_HW3, /* type */
  227. 48, /* rightshift */
  228. 1, /* size (0 = byte, 1 = short, 2 = long) */
  229. 16, /* bitsize */
  230. false, /* pc_relative */
  231. 0, /* bitpos */
  232. complain_overflow_dont,/* complain_on_overflow */
  233. bfd_elf_generic_reloc, /* special_function */
  234. "R_TILEGX_HW3", /* name */
  235. false, /* partial_inplace */
  236. 0, /* src_mask */
  237. 0xffff, /* dst_mask */
  238. false), /* pcrel_offset */
  239. /* A 16 bit relocation with overflow. */
  240. HOWTO (R_TILEGX_HW0_LAST, /* type */
  241. 0, /* rightshift */
  242. 1, /* size (0 = byte, 1 = short, 2 = long) */
  243. 16, /* bitsize */
  244. false, /* pc_relative */
  245. 0, /* bitpos */
  246. complain_overflow_signed,/* complain_on_overflow */
  247. bfd_elf_generic_reloc, /* special_function */
  248. "R_TILEGX_HW0_LAST", /* name */
  249. false, /* partial_inplace */
  250. 0, /* src_mask */
  251. 0xffff, /* dst_mask */
  252. false), /* pcrel_offset */
  253. /* A 16 bit relocation with overflow. */
  254. HOWTO (R_TILEGX_HW1_LAST, /* type */
  255. 16, /* rightshift */
  256. 1, /* size (0 = byte, 1 = short, 2 = long) */
  257. 16, /* bitsize */
  258. false, /* pc_relative */
  259. 0, /* bitpos */
  260. complain_overflow_signed,/* complain_on_overflow */
  261. bfd_elf_generic_reloc, /* special_function */
  262. "R_TILEGX_HW1_LAST", /* name */
  263. false, /* partial_inplace */
  264. 0, /* src_mask */
  265. 0xffff, /* dst_mask */
  266. false), /* pcrel_offset */
  267. /* A 16 bit relocation with overflow. */
  268. HOWTO (R_TILEGX_HW2_LAST, /* type */
  269. 32, /* rightshift */
  270. 1, /* size (0 = byte, 1 = short, 2 = long) */
  271. 16, /* bitsize */
  272. false, /* pc_relative */
  273. 0, /* bitpos */
  274. complain_overflow_signed,/* complain_on_overflow */
  275. bfd_elf_generic_reloc, /* special_function */
  276. "R_TILEGX_HW2_LAST", /* name */
  277. false, /* partial_inplace */
  278. 0, /* src_mask */
  279. 0xffff, /* dst_mask */
  280. false), /* pcrel_offset */
  281. HOWTO (R_TILEGX_COPY, /* type */
  282. 0, /* rightshift */
  283. 0, /* size (0 = byte, 1 = short, 2 = long) */
  284. 0, /* bitsize */
  285. false, /* pc_relative */
  286. 0, /* bitpos */
  287. complain_overflow_dont, /* complain_on_overflow */
  288. bfd_elf_generic_reloc, /* special_function */
  289. "R_TILEGX_COPY", /* name */
  290. false, /* partial_inplace */
  291. 0, /* src_mask */
  292. 0, /* dst_mask */
  293. true), /* pcrel_offset */
  294. HOWTO (R_TILEGX_GLOB_DAT, /* type */
  295. 0, /* rightshift */
  296. 0, /* size (0 = byte, 1 = short, 2 = long) */
  297. 0, /* bitsize */
  298. false, /* pc_relative */
  299. 0, /* bitpos */
  300. complain_overflow_dont, /* complain_on_overflow */
  301. bfd_elf_generic_reloc, /* special_function */
  302. "R_TILEGX_GLOB_DAT", /* name */
  303. false, /* partial_inplace */
  304. 0, /* src_mask */
  305. 0, /* dst_mask */
  306. true), /* pcrel_offset */
  307. HOWTO (R_TILEGX_JMP_SLOT, /* type */
  308. 0, /* rightshift */
  309. 0, /* size (0 = byte, 1 = short, 2 = long) */
  310. 0, /* bitsize */
  311. false, /* pc_relative */
  312. 0, /* bitpos */
  313. complain_overflow_dont, /* complain_on_overflow */
  314. bfd_elf_generic_reloc, /* special_function */
  315. "R_TILEGX_JMP_SLOT", /* name */
  316. false, /* partial_inplace */
  317. 0, /* src_mask */
  318. 0, /* dst_mask */
  319. true), /* pcrel_offset */
  320. HOWTO (R_TILEGX_RELATIVE, /* type */
  321. 0, /* rightshift */
  322. 0, /* size (0 = byte, 1 = short, 2 = long) */
  323. 0, /* bitsize */
  324. false, /* pc_relative */
  325. 0, /* bitpos */
  326. complain_overflow_dont, /* complain_on_overflow */
  327. bfd_elf_generic_reloc, /* special_function */
  328. "R_TILEGX_RELATIVE", /* name */
  329. false, /* partial_inplace */
  330. 0, /* src_mask */
  331. 0, /* dst_mask */
  332. true), /* pcrel_offset */
  333. HOWTO (R_TILEGX_BROFF_X1, /* type */
  334. TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
  335. 2, /* size (0 = byte, 1 = short, 2 = long) */
  336. 17, /* bitsize */
  337. true, /* pc_relative */
  338. 0, /* bitpos */
  339. complain_overflow_signed, /* complain_on_overflow */
  340. bfd_elf_generic_reloc, /* special_function */
  341. "R_TILEGX_BROFF_X1", /* name */
  342. false, /* partial_inplace */
  343. 0, /* src_mask */
  344. -1, /* dst_mask */
  345. true), /* pcrel_offset */
  346. HOWTO (R_TILEGX_JUMPOFF_X1, /* type */
  347. TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
  348. 2, /* size (0 = byte, 1 = short, 2 = long) */
  349. 27, /* bitsize */
  350. true, /* pc_relative */
  351. 0, /* bitpos */
  352. complain_overflow_signed,/* complain_on_overflow */
  353. bfd_elf_generic_reloc, /* special_function */
  354. "R_TILEGX_JUMPOFF_X1", /* name */
  355. false, /* partial_inplace */
  356. 0, /* src_mask */
  357. -1, /* dst_mask */
  358. true), /* pcrel_offset */
  359. HOWTO (R_TILEGX_JUMPOFF_X1_PLT, /* type */
  360. TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
  361. 2, /* size (0 = byte, 1 = short, 2 = long) */
  362. 27, /* bitsize */
  363. true, /* pc_relative */
  364. 0, /* bitpos */
  365. complain_overflow_signed,/* complain_on_overflow */
  366. bfd_elf_generic_reloc, /* special_function */
  367. "R_TILEGX_JUMPOFF_X1_PLT", /* name */
  368. false, /* partial_inplace */
  369. 0, /* src_mask */
  370. -1, /* dst_mask */
  371. true), /* pcrel_offset */
  372. #define TILEGX_IMM_HOWTO(name, size, bitsize) \
  373. HOWTO (name, 0, size, bitsize, false, 0, \
  374. complain_overflow_signed, bfd_elf_generic_reloc, \
  375. #name, false, 0, -1, false)
  376. #define TILEGX_UIMM_HOWTO(name, size, bitsize) \
  377. HOWTO (name, 0, size, bitsize, false, 0, \
  378. complain_overflow_unsigned, bfd_elf_generic_reloc, \
  379. #name, false, 0, -1, false)
  380. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X0, 0, 8),
  381. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y0, 0, 8),
  382. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X1, 0, 8),
  383. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y1, 0, 8),
  384. TILEGX_IMM_HOWTO(R_TILEGX_DEST_IMM8_X1, 0, 8),
  385. TILEGX_UIMM_HOWTO(R_TILEGX_MT_IMM14_X1, 1, 14),
  386. TILEGX_UIMM_HOWTO(R_TILEGX_MF_IMM14_X1, 1, 14),
  387. TILEGX_UIMM_HOWTO(R_TILEGX_MMSTART_X0, 0, 6),
  388. TILEGX_UIMM_HOWTO(R_TILEGX_MMEND_X0, 0, 6),
  389. TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_X0, 0, 6),
  390. TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_X1, 0, 6),
  391. TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_Y0, 0, 6),
  392. TILEGX_UIMM_HOWTO(R_TILEGX_SHAMT_Y1, 0, 6),
  393. #define TILEGX_IMM16_HOWTO(name, rshift) \
  394. HOWTO (name, rshift, 1, 16, false, 0, \
  395. complain_overflow_dont, bfd_elf_generic_reloc, \
  396. #name, false, 0, 0xffff, false)
  397. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW0, 0),
  398. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW0, 0),
  399. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW1, 16),
  400. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW1, 16),
  401. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW2, 32),
  402. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW2, 32),
  403. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW3, 48),
  404. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW3, 48),
  405. #define TILEGX_IMM16_HOWTO_LAST(name, rshift) \
  406. HOWTO (name, rshift, 1, 16, false, 0, \
  407. complain_overflow_signed, bfd_elf_generic_reloc, \
  408. #name, false, 0, 0xffff, false)
  409. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW0_LAST, 0),
  410. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW0_LAST, 0),
  411. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW1_LAST, 16),
  412. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW1_LAST, 16),
  413. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW2_LAST, 32),
  414. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW2_LAST, 32),
  415. /* PC-relative offsets. */
  416. #define TILEGX_IMM16_HOWTO_PCREL(name, rshift) \
  417. HOWTO (name, rshift, 1, 16, true, 0, \
  418. complain_overflow_dont, bfd_elf_generic_reloc, \
  419. #name, false, 0, 0xffff, true)
  420. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW0_PCREL, 0),
  421. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW0_PCREL, 0),
  422. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW1_PCREL, 16),
  423. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW1_PCREL, 16),
  424. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW2_PCREL, 32),
  425. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW2_PCREL, 32),
  426. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW3_PCREL, 48),
  427. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW3_PCREL, 48),
  428. #define TILEGX_IMM16_HOWTO_LAST_PCREL(name, rshift) \
  429. HOWTO (name, rshift, 1, 16, true, 0, \
  430. complain_overflow_signed, bfd_elf_generic_reloc, \
  431. #name, false, 0, 0xffff, true)
  432. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW0_LAST_PCREL, 0),
  433. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW0_LAST_PCREL, 0),
  434. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW1_LAST_PCREL, 16),
  435. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW1_LAST_PCREL, 16),
  436. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW2_LAST_PCREL, 32),
  437. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW2_LAST_PCREL, 32),
  438. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW0_GOT, 0),
  439. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW0_GOT, 0),
  440. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW0_PLT_PCREL, 0),
  441. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW0_PLT_PCREL, 0),
  442. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW1_PLT_PCREL, 16),
  443. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW1_PLT_PCREL, 16),
  444. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW2_PLT_PCREL, 32),
  445. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW2_PLT_PCREL, 32),
  446. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW0_LAST_GOT, 0),
  447. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW0_LAST_GOT, 0),
  448. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW1_LAST_GOT, 16),
  449. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW1_LAST_GOT, 16),
  450. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X0_HW3_PLT_PCREL, 48),
  451. TILEGX_IMM16_HOWTO_PCREL (R_TILEGX_IMM16_X1_HW3_PLT_PCREL, 48),
  452. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW0_TLS_GD, 0),
  453. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW0_TLS_GD, 0),
  454. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X0_HW0_TLS_LE, 0),
  455. TILEGX_IMM16_HOWTO (R_TILEGX_IMM16_X1_HW0_TLS_LE, 0),
  456. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE, 0),
  457. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE, 0),
  458. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE, 16),
  459. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE, 16),
  460. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD, 0),
  461. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD, 0),
  462. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD, 16),
  463. TILEGX_IMM16_HOWTO_LAST (R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD, 16),
  464. EMPTY_HOWTO (90),
  465. EMPTY_HOWTO (91),
  466. #define TILEGX_IMM16_HOWTO_TLS_IE(name, rshift) \
  467. HOWTO (name, rshift, 1, 16, false, 0, \
  468. complain_overflow_dont, bfd_elf_generic_reloc, \
  469. #name, false, 0, 0xffff, true)
  470. TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X0_HW0_TLS_IE, 0),
  471. TILEGX_IMM16_HOWTO_TLS_IE (R_TILEGX_IMM16_X1_HW0_TLS_IE, 0),
  472. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL, 0),
  473. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL, 0),
  474. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL, 16),
  475. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL, 16),
  476. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL, 32),
  477. TILEGX_IMM16_HOWTO_LAST_PCREL (R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL, 32),
  478. #define TILEGX_IMM16_HOWTO_LAST_TLS_IE(name, rshift) \
  479. HOWTO (name, rshift, 1, 16, false, 0, \
  480. complain_overflow_signed, bfd_elf_generic_reloc, \
  481. #name, false, 0, 0xffff, true)
  482. TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE, 0),
  483. TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE, 0),
  484. TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE, 16),
  485. TILEGX_IMM16_HOWTO_LAST_TLS_IE (R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE, 16),
  486. EMPTY_HOWTO (104),
  487. EMPTY_HOWTO (105),
  488. HOWTO(R_TILEGX_TLS_DTPMOD64, 0, 0, 0, false, 0, complain_overflow_dont,
  489. bfd_elf_generic_reloc, "R_TILEGX_TLS_DTPMOD64",
  490. false, 0, 0, true),
  491. HOWTO(R_TILEGX_TLS_DTPOFF64, 0, 4, 64, false, 0, complain_overflow_bitfield,
  492. bfd_elf_generic_reloc, "R_TILEGX_TLS_DTPOFF64",
  493. false, 0, -1, true),
  494. HOWTO(R_TILEGX_TLS_TPOFF64, 0, 0, 0, false, 0, complain_overflow_dont,
  495. bfd_elf_generic_reloc, "R_TILEGX_TLS_TPOFF64",
  496. false, 0, 0, true),
  497. HOWTO(R_TILEGX_TLS_DTPMOD32, 0, 0, 0, false, 0, complain_overflow_dont,
  498. bfd_elf_generic_reloc, "R_TILEGX_TLS_DTPMOD32",
  499. false, 0, 0, true),
  500. HOWTO(R_TILEGX_TLS_DTPOFF32, 0, 4, 32, false, 0, complain_overflow_bitfield,
  501. bfd_elf_generic_reloc, "R_TILEGX_TLS_DTPOFF32",
  502. false, 0, -1, true),
  503. HOWTO(R_TILEGX_TLS_TPOFF32, 0, 0, 0, false, 0, complain_overflow_dont,
  504. bfd_elf_generic_reloc, "R_TILEGX_TLS_TPOFF32",
  505. false, 0, 0, true),
  506. HOWTO (R_TILEGX_TLS_GD_CALL, /* type */
  507. TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES, /* rightshift */
  508. 2, /* size (0 = byte, 1 = short, 2 = long) */
  509. 27, /* bitsize */
  510. true, /* pc_relative */
  511. 0, /* bitpos */
  512. complain_overflow_signed,/* complain_on_overflow */
  513. bfd_elf_generic_reloc, /* special_function */
  514. "R_TILEGX_TLS_GD_CALL", /* name */
  515. false, /* partial_inplace */
  516. 0, /* src_mask */
  517. -1, /* dst_mask */
  518. true), /* pcrel_offset */
  519. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X0_TLS_GD_ADD, 0, 8),
  520. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X1_TLS_GD_ADD, 0, 8),
  521. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y0_TLS_GD_ADD, 0, 8),
  522. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y1_TLS_GD_ADD, 0, 8),
  523. TILEGX_IMM_HOWTO(R_TILEGX_TLS_IE_LOAD, 0, 8),
  524. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X0_TLS_ADD, 0, 8),
  525. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_X1_TLS_ADD, 0, 8),
  526. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y0_TLS_ADD, 0, 8),
  527. TILEGX_IMM_HOWTO(R_TILEGX_IMM8_Y1_TLS_ADD, 0, 8),
  528. };
  529. static reloc_howto_type tilegx_elf_howto_table2 [] =
  530. {
  531. /* GNU extension to record C++ vtable hierarchy */
  532. HOWTO (R_TILEGX_GNU_VTINHERIT, /* type */
  533. 0, /* rightshift */
  534. 4, /* size (0 = byte, 1 = short, 2 = long) */
  535. 0, /* bitsize */
  536. false, /* pc_relative */
  537. 0, /* bitpos */
  538. complain_overflow_dont, /* complain_on_overflow */
  539. NULL, /* special_function */
  540. "R_TILEGX_GNU_VTINHERIT", /* name */
  541. false, /* partial_inplace */
  542. 0, /* src_mask */
  543. 0, /* dst_mask */
  544. false), /* pcrel_offset */
  545. /* GNU extension to record C++ vtable member usage */
  546. HOWTO (R_TILEGX_GNU_VTENTRY, /* type */
  547. 0, /* rightshift */
  548. 4, /* size (0 = byte, 1 = short, 2 = long) */
  549. 0, /* bitsize */
  550. false, /* pc_relative */
  551. 0, /* bitpos */
  552. complain_overflow_dont, /* complain_on_overflow */
  553. _bfd_elf_rel_vtable_reloc_fn, /* special_function */
  554. "R_TILEGX_GNU_VTENTRY", /* name */
  555. false, /* partial_inplace */
  556. 0, /* src_mask */
  557. 0, /* dst_mask */
  558. false), /* pcrel_offset */
  559. };
  560. /* Map BFD reloc types to TILEGX ELF reloc types. */
  561. typedef struct tilegx_reloc_map
  562. {
  563. bfd_reloc_code_real_type bfd_reloc_val;
  564. unsigned int tilegx_reloc_val;
  565. reloc_howto_type * table;
  566. } reloc_map;
  567. static const reloc_map tilegx_reloc_map [] =
  568. {
  569. #define TH_REMAP(bfd, tilegx) \
  570. { bfd, tilegx, tilegx_elf_howto_table },
  571. /* Standard relocations. */
  572. TH_REMAP (BFD_RELOC_NONE, R_TILEGX_NONE)
  573. TH_REMAP (BFD_RELOC_64, R_TILEGX_64)
  574. TH_REMAP (BFD_RELOC_32, R_TILEGX_32)
  575. TH_REMAP (BFD_RELOC_16, R_TILEGX_16)
  576. TH_REMAP (BFD_RELOC_8, R_TILEGX_8)
  577. TH_REMAP (BFD_RELOC_64_PCREL, R_TILEGX_64_PCREL)
  578. TH_REMAP (BFD_RELOC_32_PCREL, R_TILEGX_32_PCREL)
  579. TH_REMAP (BFD_RELOC_16_PCREL, R_TILEGX_16_PCREL)
  580. TH_REMAP (BFD_RELOC_8_PCREL, R_TILEGX_8_PCREL)
  581. #define SIMPLE_REMAP(t) TH_REMAP (BFD_RELOC_##t, R_##t)
  582. /* Custom relocations. */
  583. SIMPLE_REMAP (TILEGX_HW0)
  584. SIMPLE_REMAP (TILEGX_HW1)
  585. SIMPLE_REMAP (TILEGX_HW2)
  586. SIMPLE_REMAP (TILEGX_HW3)
  587. SIMPLE_REMAP (TILEGX_HW0_LAST)
  588. SIMPLE_REMAP (TILEGX_HW1_LAST)
  589. SIMPLE_REMAP (TILEGX_HW2_LAST)
  590. SIMPLE_REMAP (TILEGX_COPY)
  591. SIMPLE_REMAP (TILEGX_GLOB_DAT)
  592. SIMPLE_REMAP (TILEGX_JMP_SLOT)
  593. SIMPLE_REMAP (TILEGX_RELATIVE)
  594. SIMPLE_REMAP (TILEGX_BROFF_X1)
  595. SIMPLE_REMAP (TILEGX_JUMPOFF_X1)
  596. SIMPLE_REMAP (TILEGX_JUMPOFF_X1_PLT)
  597. SIMPLE_REMAP (TILEGX_IMM8_X0)
  598. SIMPLE_REMAP (TILEGX_IMM8_Y0)
  599. SIMPLE_REMAP (TILEGX_IMM8_X1)
  600. SIMPLE_REMAP (TILEGX_IMM8_Y1)
  601. SIMPLE_REMAP (TILEGX_DEST_IMM8_X1)
  602. SIMPLE_REMAP (TILEGX_MT_IMM14_X1)
  603. SIMPLE_REMAP (TILEGX_MF_IMM14_X1)
  604. SIMPLE_REMAP (TILEGX_MMSTART_X0)
  605. SIMPLE_REMAP (TILEGX_MMEND_X0)
  606. SIMPLE_REMAP (TILEGX_SHAMT_X0)
  607. SIMPLE_REMAP (TILEGX_SHAMT_X1)
  608. SIMPLE_REMAP (TILEGX_SHAMT_Y0)
  609. SIMPLE_REMAP (TILEGX_SHAMT_Y1)
  610. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0)
  611. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0)
  612. SIMPLE_REMAP (TILEGX_IMM16_X0_HW1)
  613. SIMPLE_REMAP (TILEGX_IMM16_X1_HW1)
  614. SIMPLE_REMAP (TILEGX_IMM16_X0_HW2)
  615. SIMPLE_REMAP (TILEGX_IMM16_X1_HW2)
  616. SIMPLE_REMAP (TILEGX_IMM16_X0_HW3)
  617. SIMPLE_REMAP (TILEGX_IMM16_X1_HW3)
  618. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST)
  619. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST)
  620. SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST)
  621. SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST)
  622. SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_LAST)
  623. SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_LAST)
  624. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_PCREL)
  625. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_PCREL)
  626. SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_PCREL)
  627. SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_PCREL)
  628. SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_PCREL)
  629. SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_PCREL)
  630. SIMPLE_REMAP (TILEGX_IMM16_X0_HW3_PCREL)
  631. SIMPLE_REMAP (TILEGX_IMM16_X1_HW3_PCREL)
  632. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_PCREL)
  633. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_PCREL)
  634. SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_PCREL)
  635. SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_PCREL)
  636. SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_LAST_PCREL)
  637. SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_LAST_PCREL)
  638. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_GOT)
  639. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_GOT)
  640. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_PLT_PCREL)
  641. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_PLT_PCREL)
  642. SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_PLT_PCREL)
  643. SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_PLT_PCREL)
  644. SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_PLT_PCREL)
  645. SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_PLT_PCREL)
  646. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_GOT)
  647. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_GOT)
  648. SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_GOT)
  649. SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_GOT)
  650. SIMPLE_REMAP (TILEGX_IMM16_X0_HW3_PLT_PCREL)
  651. SIMPLE_REMAP (TILEGX_IMM16_X1_HW3_PLT_PCREL)
  652. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_TLS_GD)
  653. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_TLS_GD)
  654. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_TLS_LE)
  655. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_TLS_LE)
  656. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_TLS_LE)
  657. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_TLS_LE)
  658. SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_TLS_LE)
  659. SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_TLS_LE)
  660. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_TLS_GD)
  661. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_TLS_GD)
  662. SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_TLS_GD)
  663. SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_TLS_GD)
  664. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_TLS_IE)
  665. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_TLS_IE)
  666. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL)
  667. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL)
  668. SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL)
  669. SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL)
  670. SIMPLE_REMAP (TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL)
  671. SIMPLE_REMAP (TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL)
  672. SIMPLE_REMAP (TILEGX_IMM16_X0_HW0_LAST_TLS_IE)
  673. SIMPLE_REMAP (TILEGX_IMM16_X1_HW0_LAST_TLS_IE)
  674. SIMPLE_REMAP (TILEGX_IMM16_X0_HW1_LAST_TLS_IE)
  675. SIMPLE_REMAP (TILEGX_IMM16_X1_HW1_LAST_TLS_IE)
  676. SIMPLE_REMAP (TILEGX_TLS_DTPMOD64)
  677. SIMPLE_REMAP (TILEGX_TLS_DTPOFF64)
  678. SIMPLE_REMAP (TILEGX_TLS_TPOFF64)
  679. SIMPLE_REMAP (TILEGX_TLS_DTPMOD32)
  680. SIMPLE_REMAP (TILEGX_TLS_DTPOFF32)
  681. SIMPLE_REMAP (TILEGX_TLS_TPOFF32)
  682. SIMPLE_REMAP (TILEGX_TLS_GD_CALL)
  683. SIMPLE_REMAP (TILEGX_IMM8_X0_TLS_GD_ADD)
  684. SIMPLE_REMAP (TILEGX_IMM8_X1_TLS_GD_ADD)
  685. SIMPLE_REMAP (TILEGX_IMM8_Y0_TLS_GD_ADD)
  686. SIMPLE_REMAP (TILEGX_IMM8_Y1_TLS_GD_ADD)
  687. SIMPLE_REMAP (TILEGX_TLS_IE_LOAD)
  688. SIMPLE_REMAP (TILEGX_IMM8_X0_TLS_ADD)
  689. SIMPLE_REMAP (TILEGX_IMM8_X1_TLS_ADD)
  690. SIMPLE_REMAP (TILEGX_IMM8_Y0_TLS_ADD)
  691. SIMPLE_REMAP (TILEGX_IMM8_Y1_TLS_ADD)
  692. #undef SIMPLE_REMAP
  693. #undef TH_REMAP
  694. { BFD_RELOC_VTABLE_INHERIT, R_TILEGX_GNU_VTINHERIT, tilegx_elf_howto_table2 },
  695. { BFD_RELOC_VTABLE_ENTRY, R_TILEGX_GNU_VTENTRY, tilegx_elf_howto_table2 },
  696. };
  697. /* TILEGX ELF linker hash entry. */
  698. struct tilegx_elf_link_hash_entry
  699. {
  700. struct elf_link_hash_entry elf;
  701. #define GOT_UNKNOWN 0
  702. #define GOT_NORMAL 1
  703. #define GOT_TLS_GD 2
  704. #define GOT_TLS_IE 4
  705. unsigned char tls_type;
  706. };
  707. #define tilegx_elf_hash_entry(ent) \
  708. ((struct tilegx_elf_link_hash_entry *)(ent))
  709. struct _bfd_tilegx_elf_obj_tdata
  710. {
  711. struct elf_obj_tdata root;
  712. /* tls_type for each local got entry. */
  713. char *local_got_tls_type;
  714. };
  715. #define _bfd_tilegx_elf_tdata(abfd) \
  716. ((struct _bfd_tilegx_elf_obj_tdata *) (abfd)->tdata.any)
  717. #define _bfd_tilegx_elf_local_got_tls_type(abfd) \
  718. (_bfd_tilegx_elf_tdata (abfd)->local_got_tls_type)
  719. #define is_tilegx_elf(bfd) \
  720. (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
  721. && elf_tdata (bfd) != NULL \
  722. && elf_object_id (bfd) == TILEGX_ELF_DATA)
  723. #include "elf/common.h"
  724. #include "elf/internal.h"
  725. struct tilegx_elf_link_hash_table
  726. {
  727. struct elf_link_hash_table elf;
  728. int bytes_per_word;
  729. int word_align_power;
  730. int bytes_per_rela;
  731. int dtpmod_reloc;
  732. int dtpoff_reloc;
  733. int tpoff_reloc;
  734. bfd_vma (*r_info) (Elf_Internal_Rela *, bfd_vma, bfd_vma);
  735. bfd_vma (*r_symndx) (bfd_vma);
  736. void (*put_word) (bfd *, bfd_vma, void *);
  737. const char *dynamic_interpreter;
  738. /* Whether LE transition has been disabled for some of the
  739. sections. */
  740. bool disable_le_transition;
  741. };
  742. /* Get the Tile ELF linker hash table from a link_info structure. */
  743. #define tilegx_elf_hash_table(p) \
  744. ((is_elf_hash_table ((p)->hash) \
  745. && elf_hash_table_id (elf_hash_table (p)) == TILEGX_ELF_DATA) \
  746. ? (struct tilegx_elf_link_hash_table *) (p)->hash : NULL)
  747. #ifdef BFD64
  748. static bfd_vma
  749. tilegx_elf_r_info_64 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
  750. bfd_vma rel_index,
  751. bfd_vma type)
  752. {
  753. return ELF64_R_INFO (rel_index, type);
  754. }
  755. static bfd_vma
  756. tilegx_elf_r_symndx_64 (bfd_vma r_info)
  757. {
  758. return ELF64_R_SYM (r_info);
  759. }
  760. static void
  761. tilegx_put_word_64 (bfd *abfd, bfd_vma val, void *ptr)
  762. {
  763. bfd_put_64 (abfd, val, ptr);
  764. }
  765. #endif /* BFD64 */
  766. static bfd_vma
  767. tilegx_elf_r_info_32 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
  768. bfd_vma rel_index,
  769. bfd_vma type)
  770. {
  771. return ELF32_R_INFO (rel_index, type);
  772. }
  773. static bfd_vma
  774. tilegx_elf_r_symndx_32 (bfd_vma r_info)
  775. {
  776. return ELF32_R_SYM (r_info);
  777. }
  778. static void
  779. tilegx_put_word_32 (bfd *abfd, bfd_vma val, void *ptr)
  780. {
  781. bfd_put_32 (abfd, val, ptr);
  782. }
  783. reloc_howto_type *
  784. tilegx_reloc_type_lookup (bfd * abfd,
  785. bfd_reloc_code_real_type code)
  786. {
  787. unsigned int i;
  788. for (i = ARRAY_SIZE (tilegx_reloc_map); i--;)
  789. {
  790. const reloc_map * entry;
  791. entry = tilegx_reloc_map + i;
  792. if (entry->bfd_reloc_val == code)
  793. return entry->table + (entry->tilegx_reloc_val
  794. - entry->table[0].type);
  795. }
  796. /* xgettext:c-format */
  797. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  798. abfd, (int) code);
  799. bfd_set_error (bfd_error_bad_value);
  800. return NULL;
  801. }
  802. reloc_howto_type *
  803. tilegx_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  804. const char *r_name)
  805. {
  806. unsigned int i;
  807. for (i = 0;
  808. i < (sizeof (tilegx_elf_howto_table)
  809. / sizeof (tilegx_elf_howto_table[0]));
  810. i++)
  811. if (tilegx_elf_howto_table[i].name != NULL
  812. && strcasecmp (tilegx_elf_howto_table[i].name, r_name) == 0)
  813. return &tilegx_elf_howto_table[i];
  814. return NULL;
  815. }
  816. bool
  817. tilegx_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
  818. arelent *cache_ptr,
  819. Elf_Internal_Rela *dst)
  820. {
  821. unsigned int r_type = TILEGX_ELF_R_TYPE (dst->r_info);
  822. if (r_type <= (unsigned int) R_TILEGX_IMM8_Y1_TLS_ADD)
  823. cache_ptr->howto = &tilegx_elf_howto_table [r_type];
  824. else if (r_type - R_TILEGX_GNU_VTINHERIT
  825. <= ((unsigned int) R_TILEGX_GNU_VTENTRY
  826. - (unsigned int) R_TILEGX_GNU_VTINHERIT))
  827. cache_ptr->howto
  828. = &tilegx_elf_howto_table2 [r_type - R_TILEGX_GNU_VTINHERIT];
  829. else
  830. {
  831. /* xgettext:c-format */
  832. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  833. abfd, r_type);
  834. bfd_set_error (bfd_error_bad_value);
  835. return false;
  836. }
  837. return true;
  838. }
  839. typedef tilegx_bundle_bits (*tilegx_create_func)(int);
  840. static const tilegx_create_func reloc_to_create_func[] =
  841. {
  842. /* The first twenty relocation types don't correspond to operands */
  843. NULL,
  844. NULL,
  845. NULL,
  846. NULL,
  847. NULL,
  848. NULL,
  849. NULL,
  850. NULL,
  851. NULL,
  852. NULL,
  853. NULL,
  854. NULL,
  855. NULL,
  856. NULL,
  857. NULL,
  858. NULL,
  859. NULL,
  860. NULL,
  861. NULL,
  862. NULL,
  863. /* The remaining relocations are used for immediate operands */
  864. create_BrOff_X1,
  865. create_JumpOff_X1,
  866. create_JumpOff_X1,
  867. create_Imm8_X0,
  868. create_Imm8_Y0,
  869. create_Imm8_X1,
  870. create_Imm8_Y1,
  871. create_Dest_Imm8_X1,
  872. create_MT_Imm14_X1,
  873. create_MF_Imm14_X1,
  874. create_BFStart_X0,
  875. create_BFEnd_X0,
  876. create_ShAmt_X0,
  877. create_ShAmt_X1,
  878. create_ShAmt_Y0,
  879. create_ShAmt_Y1,
  880. create_Imm16_X0,
  881. create_Imm16_X1,
  882. create_Imm16_X0,
  883. create_Imm16_X1,
  884. create_Imm16_X0,
  885. create_Imm16_X1,
  886. create_Imm16_X0,
  887. create_Imm16_X1,
  888. create_Imm16_X0,
  889. create_Imm16_X1,
  890. create_Imm16_X0,
  891. create_Imm16_X1,
  892. create_Imm16_X0,
  893. create_Imm16_X1,
  894. create_Imm16_X0,
  895. create_Imm16_X1,
  896. create_Imm16_X0,
  897. create_Imm16_X1,
  898. create_Imm16_X0,
  899. create_Imm16_X1,
  900. create_Imm16_X0,
  901. create_Imm16_X1,
  902. create_Imm16_X0,
  903. create_Imm16_X1,
  904. create_Imm16_X0,
  905. create_Imm16_X1,
  906. create_Imm16_X0,
  907. create_Imm16_X1,
  908. create_Imm16_X0,
  909. create_Imm16_X1,
  910. create_Imm16_X0,
  911. create_Imm16_X1,
  912. create_Imm16_X0,
  913. create_Imm16_X1,
  914. create_Imm16_X0,
  915. create_Imm16_X1,
  916. create_Imm16_X0,
  917. create_Imm16_X1,
  918. create_Imm16_X0,
  919. create_Imm16_X1,
  920. create_Imm16_X0,
  921. create_Imm16_X1,
  922. create_Imm16_X0,
  923. create_Imm16_X1,
  924. create_Imm16_X0,
  925. create_Imm16_X1,
  926. create_Imm16_X0,
  927. create_Imm16_X1,
  928. create_Imm16_X0,
  929. create_Imm16_X1,
  930. create_Imm16_X0,
  931. create_Imm16_X1,
  932. create_Imm16_X0,
  933. create_Imm16_X1,
  934. NULL,
  935. NULL,
  936. create_Imm16_X0,
  937. create_Imm16_X1,
  938. create_Imm16_X0,
  939. create_Imm16_X1,
  940. create_Imm16_X0,
  941. create_Imm16_X1,
  942. create_Imm16_X0,
  943. create_Imm16_X1,
  944. create_Imm16_X0,
  945. create_Imm16_X1,
  946. create_Imm16_X0,
  947. create_Imm16_X1,
  948. };
  949. static void
  950. tilegx_elf_append_rela (bfd *abfd, asection *s, Elf_Internal_Rela *rel)
  951. {
  952. const struct elf_backend_data *bed;
  953. bfd_byte *loc;
  954. bed = get_elf_backend_data (abfd);
  955. loc = s->contents + (s->reloc_count++ * bed->s->sizeof_rela);
  956. bed->s->swap_reloca_out (abfd, rel, loc);
  957. }
  958. /* PLT/GOT stuff */
  959. /* The procedure linkage table starts with the following header:
  960. ld_add r28, r27, 8
  961. ld r27, r27
  962. {
  963. jr r27
  964. info 10 ## SP not offset, return PC in LR
  965. }
  966. Subsequent entries are the following, jumping to the header at the end:
  967. {
  968. moveli r28, <_GLOBAL_OFFSET_TABLE_ - 1f + MY_GOT_OFFSET>
  969. lnk r26
  970. }
  971. 1:
  972. {
  973. moveli r27, <_GLOBAL_OFFSET_TABLE_ - 1b>
  974. shl16insli r28, r28, <_GLOBAL_OFFSET_TABLE_ - 1b + MY_GOT_OFFSET>
  975. }
  976. {
  977. add r28, r26, r28
  978. shl16insli r27, r27, <_GLOBAL_OFFSET_TABLE_ - 1b>
  979. }
  980. {
  981. add r27, r26, r27
  982. ld r28, r28
  983. info 10 ## SP not offset, return PC in LR
  984. }
  985. {
  986. shl16insli r29, zero, MY_PLT_INDEX
  987. jr r28
  988. }
  989. This code sequence lets the code at at the start of the PLT determine
  990. which PLT entry was executed by examining 'r29'.
  991. Note that MY_PLT_INDEX skips over the header entries, so the first
  992. actual jump table entry has index zero.
  993. If the offset fits in 16 bits,
  994. lnk r26
  995. 1:
  996. {
  997. addli r28, r26, <_GLOBAL_OFFSET_TABLE_ - 1b + MY_GOT_OFFSET>
  998. moveli r27, <_GLOBAL_OFFSET_TABLE_ - 1b>
  999. }
  1000. {
  1001. shl16insli r29, zero, MY_PLT_INDEX
  1002. ld r28, r28
  1003. }
  1004. {
  1005. add r27, r26, r27
  1006. jr r28
  1007. }
  1008. info 10 ## SP not offset, return PC in LR
  1009. For the purpose of backtracing, the procedure linkage table ends with the
  1010. following tail entry:
  1011. info 10 ## SP not offset, return PC in LR
  1012. The 32-bit versions are similar, with ld4s replacing ld, and offsets into
  1013. the GOT being multiples of 4 instead of 8.
  1014. */
  1015. #define PLT_HEADER_SIZE_IN_BUNDLES 3
  1016. #define PLT_ENTRY_SIZE_IN_BUNDLES 5
  1017. #define PLT_TAIL_SIZE_IN_BUNDLES 1
  1018. #define PLT_HEADER_SIZE \
  1019. (PLT_HEADER_SIZE_IN_BUNDLES * TILEGX_BUNDLE_SIZE_IN_BYTES)
  1020. #define PLT_ENTRY_SIZE \
  1021. (PLT_ENTRY_SIZE_IN_BUNDLES * TILEGX_BUNDLE_SIZE_IN_BYTES)
  1022. #define PLT_TAIL_SIZE \
  1023. (PLT_TAIL_SIZE_IN_BUNDLES * TILEGX_BUNDLE_SIZE_IN_BYTES)
  1024. #define GOT_ENTRY_SIZE(htab) TILEGX_ELF_WORD_BYTES (htab)
  1025. #define GOTPLT_HEADER_SIZE(htab) (2 * GOT_ENTRY_SIZE (htab))
  1026. static const bfd_byte
  1027. tilegx64_plt0_entry[PLT_HEADER_SIZE] =
  1028. {
  1029. 0x00, 0x30, 0x48, 0x51,
  1030. 0x6e, 0x43, 0xa0, 0x18, /* { ld_add r28, r27, 8 } */
  1031. 0x00, 0x30, 0xbc, 0x35,
  1032. 0x00, 0x40, 0xde, 0x9e, /* { ld r27, r27 } */
  1033. 0xff, 0xaf, 0x30, 0x40,
  1034. 0x60, 0x73, 0x6a, 0x28, /* { info 10 ; jr r27 } */
  1035. };
  1036. static const bfd_byte
  1037. tilegx64_long_plt_entry[PLT_ENTRY_SIZE] =
  1038. {
  1039. 0xdc, 0x0f, 0x00, 0x10,
  1040. 0x0d, 0xf0, 0x6a, 0x28, /* { moveli r28, 0 ; lnk r26 } */
  1041. 0xdb, 0x0f, 0x00, 0x10,
  1042. 0x8e, 0x03, 0x00, 0x38, /* { moveli r27, 0 ; shl16insli r28, r28, 0 } */
  1043. 0x9c, 0xc6, 0x0d, 0xd0,
  1044. 0x6d, 0x03, 0x00, 0x38, /* { add r28, r26, r28 ; shl16insli r27, r27, 0 } */
  1045. 0x9b, 0xb6, 0xc5, 0xad,
  1046. 0xff, 0x57, 0xe0, 0x8e, /* { add r27, r26, r27 ; info 10 ; ld r28, r28 } */
  1047. 0xdd, 0x0f, 0x00, 0x70,
  1048. 0x80, 0x73, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; jr r28 } */
  1049. };
  1050. static const bfd_byte
  1051. tilegx64_short_plt_entry[PLT_ENTRY_SIZE] =
  1052. {
  1053. 0x00, 0x30, 0x48, 0x51,
  1054. 0x0d, 0xf0, 0x6a, 0x28, /* { lnk r26 } */
  1055. 0x9c, 0x06, 0x00, 0x90,
  1056. 0xed, 0x07, 0x00, 0x00, /* { addli r28, r26, 0 ; moveli r27, 0 } */
  1057. 0xdd, 0x0f, 0x00, 0x70,
  1058. 0x8e, 0xeb, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; ld r28, r28 } */
  1059. 0x9b, 0xb6, 0x0d, 0x50,
  1060. 0x80, 0x73, 0x6a, 0x28, /* { add r27, r26, r27 ; jr r28 } */
  1061. 0x00, 0x30, 0x48, 0xd1,
  1062. 0xff, 0x57, 0x18, 0x18, /* { info 10 } */
  1063. };
  1064. /* Reuse an existing info 10 bundle. */
  1065. static const bfd_byte *const tilegx64_plt_tail_entry =
  1066. &tilegx64_short_plt_entry[4 * TILEGX_BUNDLE_SIZE_IN_BYTES];
  1067. static const bfd_byte
  1068. tilegx32_plt0_entry[PLT_HEADER_SIZE] =
  1069. {
  1070. 0x00, 0x30, 0x48, 0x51,
  1071. 0x6e, 0x23, 0x58, 0x18, /* { ld4s_add r28, r27, 4 } */
  1072. 0x00, 0x30, 0xbc, 0x35,
  1073. 0x00, 0x40, 0xde, 0x9c, /* { ld4s r27, r27 } */
  1074. 0xff, 0xaf, 0x30, 0x40,
  1075. 0x60, 0x73, 0x6a, 0x28, /* { info 10 ; jr r27 } */
  1076. };
  1077. static const bfd_byte
  1078. tilegx32_long_plt_entry[PLT_ENTRY_SIZE] =
  1079. {
  1080. 0xdc, 0x0f, 0x00, 0x10,
  1081. 0x0d, 0xf0, 0x6a, 0x28, /* { moveli r28, 0 ; lnk r26 } */
  1082. 0xdb, 0x0f, 0x00, 0x10,
  1083. 0x8e, 0x03, 0x00, 0x38, /* { moveli r27, 0 ; shl16insli r28, r28, 0 } */
  1084. 0x9c, 0xc6, 0x0d, 0xd0,
  1085. 0x6d, 0x03, 0x00, 0x38, /* { add r28, r26, r28 ; shl16insli r27, r27, 0 } */
  1086. 0x9b, 0xb6, 0xc5, 0xad,
  1087. 0xff, 0x57, 0xe0, 0x8c, /* { add r27, r26, r27 ; info 10 ; ld4s r28, r28 } */
  1088. 0xdd, 0x0f, 0x00, 0x70,
  1089. 0x80, 0x73, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; jr r28 } */
  1090. };
  1091. static const bfd_byte
  1092. tilegx32_short_plt_entry[PLT_ENTRY_SIZE] =
  1093. {
  1094. 0x00, 0x30, 0x48, 0x51,
  1095. 0x0d, 0xf0, 0x6a, 0x28, /* { lnk r26 } */
  1096. 0x9c, 0x06, 0x00, 0x90,
  1097. 0xed, 0x07, 0x00, 0x00, /* { addli r28, r26, 0 ; moveli r27, 0 } */
  1098. 0xdd, 0x0f, 0x00, 0x70,
  1099. 0x8e, 0x9b, 0x6a, 0x28, /* { shl16insli r29, zero, 0 ; ld4s r28, r28 } */
  1100. 0x9b, 0xb6, 0x0d, 0x50,
  1101. 0x80, 0x73, 0x6a, 0x28, /* { add r27, r26, r27 ; jr r28 } */
  1102. 0x00, 0x30, 0x48, 0xd1,
  1103. 0xff, 0x57, 0x18, 0x18, /* { info 10 } */
  1104. };
  1105. /* Reuse an existing info 10 bundle. */
  1106. static const bfd_byte *const tilegx32_plt_tail_entry =
  1107. &tilegx64_short_plt_entry[4 * TILEGX_BUNDLE_SIZE_IN_BYTES];
  1108. static int
  1109. tilegx_plt_entry_build (bfd *output_bfd,
  1110. struct tilegx_elf_link_hash_table *htab,
  1111. asection *splt, asection *sgotplt,
  1112. bfd_vma offset, bfd_vma *r_offset)
  1113. {
  1114. int plt_index = (offset - PLT_HEADER_SIZE) / PLT_ENTRY_SIZE;
  1115. int got_offset = (plt_index * GOT_ENTRY_SIZE (htab)
  1116. + GOTPLT_HEADER_SIZE (htab));
  1117. tilegx_bundle_bits *pc;
  1118. /* Compute the distance from the got entry to the lnk. */
  1119. bfd_signed_vma dist_got_entry = sgotplt->output_section->vma
  1120. + sgotplt->output_offset
  1121. + got_offset
  1122. - splt->output_section->vma
  1123. - splt->output_offset
  1124. - offset
  1125. - TILEGX_BUNDLE_SIZE_IN_BYTES;
  1126. /* Compute the distance to GOTPLT[0]. */
  1127. bfd_signed_vma dist_got0 = dist_got_entry - got_offset;
  1128. /* Check whether we can use the short plt entry with 16-bit offset. */
  1129. bool short_plt_entry =
  1130. (dist_got_entry <= 0x7fff && dist_got0 >= -0x8000);
  1131. const tilegx_bundle_bits *plt_entry = (tilegx_bundle_bits *)
  1132. (ABI_64_P (output_bfd) ?
  1133. (short_plt_entry ? tilegx64_short_plt_entry : tilegx64_long_plt_entry) :
  1134. (short_plt_entry ? tilegx32_short_plt_entry : tilegx32_long_plt_entry));
  1135. /* Copy the plt entry template. */
  1136. memcpy (splt->contents + offset, plt_entry, PLT_ENTRY_SIZE);
  1137. /* Write the immediate offsets. */
  1138. pc = (tilegx_bundle_bits *)(splt->contents + offset);
  1139. if (short_plt_entry)
  1140. {
  1141. /* { lnk r28 } */
  1142. pc++;
  1143. /* { addli r28, r28, &GOTPLT[MY_GOT_INDEX] ; moveli r27, &GOTPLT[0] } */
  1144. *pc++ |= create_Imm16_X0 (dist_got_entry)
  1145. | create_Imm16_X1 (dist_got0);
  1146. /* { shl16insli r29, zero, MY_PLT_INDEX ; ld r28, r28 } */
  1147. *pc++ |= create_Imm16_X0 (plt_index);
  1148. }
  1149. else
  1150. {
  1151. /* { moveli r28, &GOTPLT[MY_GOT_INDEX] ; lnk r26 } */
  1152. *pc++ |= create_Imm16_X0 (dist_got_entry >> 16);
  1153. /* { moveli r27, &GOTPLT[0] ;
  1154. shl16insli r28, r28, &GOTPLT[MY_GOT_INDEX] } */
  1155. *pc++ |= create_Imm16_X0 (dist_got0 >> 16)
  1156. | create_Imm16_X1 (dist_got_entry);
  1157. /* { add r28, r26, r28 ; shl16insli r27, r27, &GOTPLT[0] } */
  1158. *pc++ |= create_Imm16_X1 (dist_got0);
  1159. /* { add r27, r26, r27 ; info 10 ; ld r28, r28 } */
  1160. pc++;
  1161. /* { shl16insli r29, zero, MY_GOT_INDEX ; jr r28 } */
  1162. *pc++ |= create_Imm16_X0 (plt_index);
  1163. }
  1164. /* Set the relocation offset. */
  1165. *r_offset = got_offset;
  1166. return plt_index;
  1167. }
  1168. /* Create an entry in an TILEGX ELF linker hash table. */
  1169. static struct bfd_hash_entry *
  1170. link_hash_newfunc (struct bfd_hash_entry *entry,
  1171. struct bfd_hash_table *table, const char *string)
  1172. {
  1173. /* Allocate the structure if it has not already been allocated by a
  1174. subclass. */
  1175. if (entry == NULL)
  1176. {
  1177. entry =
  1178. bfd_hash_allocate (table,
  1179. sizeof (struct tilegx_elf_link_hash_entry));
  1180. if (entry == NULL)
  1181. return entry;
  1182. }
  1183. /* Call the allocation method of the superclass. */
  1184. entry = _bfd_elf_link_hash_newfunc (entry, table, string);
  1185. if (entry != NULL)
  1186. {
  1187. struct tilegx_elf_link_hash_entry *eh;
  1188. eh = (struct tilegx_elf_link_hash_entry *) entry;
  1189. eh->tls_type = GOT_UNKNOWN;
  1190. }
  1191. return entry;
  1192. }
  1193. /* Create a TILEGX ELF linker hash table. */
  1194. struct bfd_link_hash_table *
  1195. tilegx_elf_link_hash_table_create (bfd *abfd)
  1196. {
  1197. struct tilegx_elf_link_hash_table *ret;
  1198. size_t amt = sizeof (struct tilegx_elf_link_hash_table);
  1199. ret = (struct tilegx_elf_link_hash_table *) bfd_zmalloc (amt);
  1200. if (ret == NULL)
  1201. return NULL;
  1202. #ifdef BFD64
  1203. if (ABI_64_P (abfd))
  1204. {
  1205. ret->bytes_per_word = 8;
  1206. ret->word_align_power = 3;
  1207. ret->bytes_per_rela = sizeof (Elf64_External_Rela);
  1208. ret->dtpoff_reloc = R_TILEGX_TLS_DTPOFF64;
  1209. ret->dtpmod_reloc = R_TILEGX_TLS_DTPMOD64;
  1210. ret->tpoff_reloc = R_TILEGX_TLS_TPOFF64;
  1211. ret->r_info = tilegx_elf_r_info_64;
  1212. ret->r_symndx = tilegx_elf_r_symndx_64;
  1213. ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
  1214. ret->put_word = tilegx_put_word_64;
  1215. }
  1216. else
  1217. #endif
  1218. {
  1219. ret->bytes_per_word = 4;
  1220. ret->word_align_power = 2;
  1221. ret->bytes_per_rela = sizeof (Elf32_External_Rela);
  1222. ret->dtpoff_reloc = R_TILEGX_TLS_DTPOFF32;
  1223. ret->dtpmod_reloc = R_TILEGX_TLS_DTPMOD32;
  1224. ret->tpoff_reloc = R_TILEGX_TLS_TPOFF32;
  1225. ret->r_info = tilegx_elf_r_info_32;
  1226. ret->r_symndx = tilegx_elf_r_symndx_32;
  1227. ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER;
  1228. ret->put_word = tilegx_put_word_32;
  1229. }
  1230. if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
  1231. sizeof (struct tilegx_elf_link_hash_entry),
  1232. TILEGX_ELF_DATA))
  1233. {
  1234. free (ret);
  1235. return NULL;
  1236. }
  1237. return &ret->elf.root;
  1238. }
  1239. /* Create the .got section. */
  1240. static bool
  1241. tilegx_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
  1242. {
  1243. flagword flags;
  1244. asection *s, *s_got;
  1245. struct elf_link_hash_entry *h;
  1246. const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  1247. struct elf_link_hash_table *htab = elf_hash_table (info);
  1248. /* This function may be called more than once. */
  1249. if (htab->sgot != NULL)
  1250. return true;
  1251. flags = bed->dynamic_sec_flags;
  1252. s = bfd_make_section_anyway_with_flags (abfd,
  1253. (bed->rela_plts_and_copies_p
  1254. ? ".rela.got" : ".rel.got"),
  1255. (bed->dynamic_sec_flags
  1256. | SEC_READONLY));
  1257. if (s == NULL
  1258. || !bfd_set_section_alignment (s, bed->s->log_file_align))
  1259. return false;
  1260. htab->srelgot = s;
  1261. s = s_got = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
  1262. if (s == NULL
  1263. || !bfd_set_section_alignment (s, bed->s->log_file_align))
  1264. return false;
  1265. htab->sgot = s;
  1266. /* The first bit of the global offset table is the header. */
  1267. s->size += bed->got_header_size;
  1268. if (bed->want_got_plt)
  1269. {
  1270. s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
  1271. if (s == NULL
  1272. || !bfd_set_section_alignment (s, bed->s->log_file_align))
  1273. return false;
  1274. htab->sgotplt = s;
  1275. /* Reserve room for the header. */
  1276. s->size += GOTPLT_HEADER_SIZE (tilegx_elf_hash_table (info));
  1277. }
  1278. if (bed->want_got_sym)
  1279. {
  1280. /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
  1281. section. We don't do this in the linker script because we don't want
  1282. to define the symbol if we are not creating a global offset
  1283. table. */
  1284. h = _bfd_elf_define_linkage_sym (abfd, info, s_got,
  1285. "_GLOBAL_OFFSET_TABLE_");
  1286. elf_hash_table (info)->hgot = h;
  1287. if (h == NULL)
  1288. return false;
  1289. }
  1290. return true;
  1291. }
  1292. /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
  1293. .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
  1294. hash table. */
  1295. bool
  1296. tilegx_elf_create_dynamic_sections (bfd *dynobj,
  1297. struct bfd_link_info *info)
  1298. {
  1299. if (!tilegx_elf_create_got_section (dynobj, info))
  1300. return false;
  1301. return _bfd_elf_create_dynamic_sections (dynobj, info);
  1302. }
  1303. /* Copy the extra info we tack onto an elf_link_hash_entry. */
  1304. void
  1305. tilegx_elf_copy_indirect_symbol (struct bfd_link_info *info,
  1306. struct elf_link_hash_entry *dir,
  1307. struct elf_link_hash_entry *ind)
  1308. {
  1309. struct tilegx_elf_link_hash_entry *edir, *eind;
  1310. edir = (struct tilegx_elf_link_hash_entry *) dir;
  1311. eind = (struct tilegx_elf_link_hash_entry *) ind;
  1312. if (ind->root.type == bfd_link_hash_indirect
  1313. && dir->got.refcount <= 0)
  1314. {
  1315. edir->tls_type = eind->tls_type;
  1316. eind->tls_type = GOT_UNKNOWN;
  1317. }
  1318. _bfd_elf_link_hash_copy_indirect (info, dir, ind);
  1319. }
  1320. static int
  1321. tilegx_tls_translate_to_le (int r_type)
  1322. {
  1323. switch (r_type)
  1324. {
  1325. case R_TILEGX_IMM16_X0_HW0_TLS_GD:
  1326. case R_TILEGX_IMM16_X0_HW0_TLS_IE:
  1327. return R_TILEGX_IMM16_X0_HW0_TLS_LE;
  1328. case R_TILEGX_IMM16_X1_HW0_TLS_GD:
  1329. case R_TILEGX_IMM16_X1_HW0_TLS_IE:
  1330. return R_TILEGX_IMM16_X1_HW0_TLS_LE;
  1331. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  1332. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  1333. return R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE;
  1334. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  1335. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  1336. return R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE;
  1337. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  1338. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  1339. return R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE;
  1340. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  1341. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  1342. return R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE;
  1343. }
  1344. return r_type;
  1345. }
  1346. static int
  1347. tilegx_tls_translate_to_ie (int r_type)
  1348. {
  1349. switch (r_type)
  1350. {
  1351. case R_TILEGX_IMM16_X0_HW0_TLS_GD:
  1352. case R_TILEGX_IMM16_X0_HW0_TLS_IE:
  1353. return R_TILEGX_IMM16_X0_HW0_TLS_IE;
  1354. case R_TILEGX_IMM16_X1_HW0_TLS_GD:
  1355. case R_TILEGX_IMM16_X1_HW0_TLS_IE:
  1356. return R_TILEGX_IMM16_X1_HW0_TLS_IE;
  1357. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  1358. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  1359. return R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE;
  1360. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  1361. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  1362. return R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE;
  1363. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  1364. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  1365. return R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE;
  1366. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  1367. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  1368. return R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE;
  1369. }
  1370. return r_type;
  1371. }
  1372. static int
  1373. tilegx_elf_tls_transition (struct bfd_link_info *info, int r_type,
  1374. int is_local, bool disable_le_transition)
  1375. {
  1376. if (!bfd_link_executable (info))
  1377. return r_type;
  1378. if (is_local && !disable_le_transition)
  1379. return tilegx_tls_translate_to_le (r_type);
  1380. else
  1381. return tilegx_tls_translate_to_ie (r_type);
  1382. }
  1383. /* Look through the relocs for a section during the first phase, and
  1384. allocate space in the global offset table or procedure linkage
  1385. table. */
  1386. bool
  1387. tilegx_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
  1388. asection *sec, const Elf_Internal_Rela *relocs)
  1389. {
  1390. struct tilegx_elf_link_hash_table *htab;
  1391. Elf_Internal_Shdr *symtab_hdr;
  1392. struct elf_link_hash_entry **sym_hashes;
  1393. const Elf_Internal_Rela *rel;
  1394. const Elf_Internal_Rela *rel_end;
  1395. asection *sreloc;
  1396. int num_relocs;
  1397. bool has_tls_gd_or_ie = false, has_tls_add = false;
  1398. if (bfd_link_relocatable (info))
  1399. return true;
  1400. htab = tilegx_elf_hash_table (info);
  1401. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  1402. sym_hashes = elf_sym_hashes (abfd);
  1403. sreloc = NULL;
  1404. num_relocs = sec->reloc_count;
  1405. BFD_ASSERT (is_tilegx_elf (abfd) || num_relocs == 0);
  1406. if (htab->elf.dynobj == NULL)
  1407. htab->elf.dynobj = abfd;
  1408. rel_end = relocs + num_relocs;
  1409. /* Check whether to do optimization to transform TLS GD/IE
  1410. referehces to TLS LE. We disable it if we're linking with old
  1411. TLS code sequences that do not support such optimization. Old
  1412. TLS code sequences have tls_gd_call/tls_ie_load relocations but
  1413. no tls_add relocations. */
  1414. for (rel = relocs; rel < rel_end && !has_tls_add; rel++)
  1415. {
  1416. int r_type = TILEGX_ELF_R_TYPE (rel->r_info);
  1417. switch (r_type)
  1418. {
  1419. case R_TILEGX_TLS_GD_CALL:
  1420. case R_TILEGX_TLS_IE_LOAD:
  1421. has_tls_gd_or_ie = true;
  1422. break;
  1423. case R_TILEGX_IMM8_X0_TLS_ADD:
  1424. case R_TILEGX_IMM8_Y0_TLS_ADD:
  1425. case R_TILEGX_IMM8_X1_TLS_ADD:
  1426. case R_TILEGX_IMM8_Y1_TLS_ADD:
  1427. has_tls_add = true;
  1428. break;
  1429. }
  1430. }
  1431. sec->sec_flg0 = (has_tls_gd_or_ie && !has_tls_add);
  1432. htab->disable_le_transition |= sec->sec_flg0;
  1433. for (rel = relocs; rel < rel_end; rel++)
  1434. {
  1435. unsigned int r_type;
  1436. unsigned int r_symndx;
  1437. struct elf_link_hash_entry *h;
  1438. int tls_type;
  1439. r_symndx = TILEGX_ELF_R_SYMNDX (htab, rel->r_info);
  1440. r_type = TILEGX_ELF_R_TYPE (rel->r_info);
  1441. if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
  1442. {
  1443. /* xgettext:c-format */
  1444. _bfd_error_handler (_("%pB: bad symbol index: %d"),
  1445. abfd, r_symndx);
  1446. return false;
  1447. }
  1448. if (r_symndx < symtab_hdr->sh_info)
  1449. h = NULL;
  1450. else
  1451. {
  1452. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  1453. while (h->root.type == bfd_link_hash_indirect
  1454. || h->root.type == bfd_link_hash_warning)
  1455. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1456. }
  1457. r_type = tilegx_elf_tls_transition (info, r_type, h == NULL,
  1458. sec->sec_flg0);
  1459. switch (r_type)
  1460. {
  1461. case R_TILEGX_IMM16_X0_HW0_TLS_LE:
  1462. case R_TILEGX_IMM16_X1_HW0_TLS_LE:
  1463. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
  1464. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
  1465. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
  1466. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
  1467. if (!bfd_link_executable (info))
  1468. goto r_tilegx_plt32;
  1469. break;
  1470. case R_TILEGX_IMM16_X0_HW0_TLS_GD:
  1471. case R_TILEGX_IMM16_X1_HW0_TLS_GD:
  1472. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  1473. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  1474. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  1475. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  1476. BFD_ASSERT (bfd_link_pic (info));
  1477. tls_type = GOT_TLS_GD;
  1478. goto have_got_reference;
  1479. case R_TILEGX_IMM16_X0_HW0_TLS_IE:
  1480. case R_TILEGX_IMM16_X1_HW0_TLS_IE:
  1481. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  1482. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  1483. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  1484. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  1485. tls_type = GOT_TLS_IE;
  1486. if (!bfd_link_executable (info))
  1487. info->flags |= DF_STATIC_TLS;
  1488. goto have_got_reference;
  1489. case R_TILEGX_IMM16_X0_HW0_GOT:
  1490. case R_TILEGX_IMM16_X1_HW0_GOT:
  1491. case R_TILEGX_IMM16_X0_HW0_LAST_GOT:
  1492. case R_TILEGX_IMM16_X1_HW0_LAST_GOT:
  1493. case R_TILEGX_IMM16_X0_HW1_LAST_GOT:
  1494. case R_TILEGX_IMM16_X1_HW1_LAST_GOT:
  1495. tls_type = GOT_NORMAL;
  1496. /* Fall Through */
  1497. have_got_reference:
  1498. /* This symbol requires a global offset table entry. */
  1499. {
  1500. int old_tls_type;
  1501. if (h != NULL)
  1502. {
  1503. h->got.refcount += 1;
  1504. old_tls_type = tilegx_elf_hash_entry(h)->tls_type;
  1505. }
  1506. else
  1507. {
  1508. bfd_signed_vma *local_got_refcounts;
  1509. /* This is a global offset table entry for a local symbol. */
  1510. local_got_refcounts = elf_local_got_refcounts (abfd);
  1511. if (local_got_refcounts == NULL)
  1512. {
  1513. bfd_size_type size;
  1514. size = symtab_hdr->sh_info;
  1515. size *= (sizeof (bfd_signed_vma) + sizeof(char));
  1516. local_got_refcounts = ((bfd_signed_vma *)
  1517. bfd_zalloc (abfd, size));
  1518. if (local_got_refcounts == NULL)
  1519. return false;
  1520. elf_local_got_refcounts (abfd) = local_got_refcounts;
  1521. _bfd_tilegx_elf_local_got_tls_type (abfd)
  1522. = (char *) (local_got_refcounts + symtab_hdr->sh_info);
  1523. }
  1524. local_got_refcounts[r_symndx] += 1;
  1525. old_tls_type = _bfd_tilegx_elf_local_got_tls_type (abfd) [r_symndx];
  1526. }
  1527. /* If a TLS symbol is accessed using IE at least once,
  1528. there is no point to use dynamic model for it. */
  1529. if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
  1530. && (old_tls_type != GOT_TLS_GD
  1531. || tls_type != GOT_TLS_IE))
  1532. {
  1533. if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
  1534. tls_type = old_tls_type;
  1535. else
  1536. {
  1537. _bfd_error_handler
  1538. /* xgettext:c-format */
  1539. (_("%pB: `%s' accessed both as normal and thread local symbol"),
  1540. abfd, h ? h->root.root.string : "<local>");
  1541. return false;
  1542. }
  1543. }
  1544. if (old_tls_type != tls_type)
  1545. {
  1546. if (h != NULL)
  1547. tilegx_elf_hash_entry (h)->tls_type = tls_type;
  1548. else
  1549. _bfd_tilegx_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
  1550. }
  1551. }
  1552. if (htab->elf.sgot == NULL)
  1553. {
  1554. if (!tilegx_elf_create_got_section (htab->elf.dynobj, info))
  1555. return false;
  1556. }
  1557. break;
  1558. case R_TILEGX_TLS_GD_CALL:
  1559. if (!bfd_link_executable (info))
  1560. {
  1561. /* These are basically R_TILEGX_JUMPOFF_X1_PLT relocs
  1562. against __tls_get_addr. */
  1563. struct bfd_link_hash_entry *bh = NULL;
  1564. if (! _bfd_generic_link_add_one_symbol (info, abfd,
  1565. "__tls_get_addr", 0,
  1566. bfd_und_section_ptr, 0,
  1567. NULL, false, false,
  1568. &bh))
  1569. return false;
  1570. h = (struct elf_link_hash_entry *) bh;
  1571. }
  1572. else
  1573. break;
  1574. /* Fall through */
  1575. case R_TILEGX_JUMPOFF_X1_PLT:
  1576. case R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
  1577. case R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
  1578. case R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
  1579. case R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
  1580. case R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
  1581. case R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
  1582. case R_TILEGX_IMM16_X0_HW3_PLT_PCREL:
  1583. case R_TILEGX_IMM16_X1_HW3_PLT_PCREL:
  1584. case R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
  1585. case R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
  1586. case R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
  1587. case R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
  1588. case R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
  1589. case R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
  1590. /* This symbol requires a procedure linkage table entry. We
  1591. actually build the entry in adjust_dynamic_symbol,
  1592. because this might be a case of linking PIC code without
  1593. linking in any dynamic objects, in which case we don't
  1594. need to generate a procedure linkage table after all. */
  1595. if (h != NULL)
  1596. {
  1597. h->needs_plt = 1;
  1598. h->plt.refcount += 1;
  1599. }
  1600. break;
  1601. case R_TILEGX_64_PCREL:
  1602. case R_TILEGX_32_PCREL:
  1603. case R_TILEGX_16_PCREL:
  1604. case R_TILEGX_8_PCREL:
  1605. case R_TILEGX_IMM16_X0_HW0_PCREL:
  1606. case R_TILEGX_IMM16_X1_HW0_PCREL:
  1607. case R_TILEGX_IMM16_X0_HW1_PCREL:
  1608. case R_TILEGX_IMM16_X1_HW1_PCREL:
  1609. case R_TILEGX_IMM16_X0_HW2_PCREL:
  1610. case R_TILEGX_IMM16_X1_HW2_PCREL:
  1611. case R_TILEGX_IMM16_X0_HW3_PCREL:
  1612. case R_TILEGX_IMM16_X1_HW3_PCREL:
  1613. case R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
  1614. case R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
  1615. case R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
  1616. case R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
  1617. case R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
  1618. case R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
  1619. if (h != NULL)
  1620. h->non_got_ref = 1;
  1621. if (h != NULL
  1622. && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
  1623. break;
  1624. /* Fall through. */
  1625. case R_TILEGX_64:
  1626. case R_TILEGX_32:
  1627. case R_TILEGX_16:
  1628. case R_TILEGX_8:
  1629. case R_TILEGX_HW0:
  1630. case R_TILEGX_HW1:
  1631. case R_TILEGX_HW2:
  1632. case R_TILEGX_HW3:
  1633. case R_TILEGX_HW0_LAST:
  1634. case R_TILEGX_HW1_LAST:
  1635. case R_TILEGX_HW2_LAST:
  1636. case R_TILEGX_COPY:
  1637. case R_TILEGX_GLOB_DAT:
  1638. case R_TILEGX_JMP_SLOT:
  1639. case R_TILEGX_RELATIVE:
  1640. case R_TILEGX_BROFF_X1:
  1641. case R_TILEGX_JUMPOFF_X1:
  1642. case R_TILEGX_IMM8_X0:
  1643. case R_TILEGX_IMM8_Y0:
  1644. case R_TILEGX_IMM8_X1:
  1645. case R_TILEGX_IMM8_Y1:
  1646. case R_TILEGX_DEST_IMM8_X1:
  1647. case R_TILEGX_MT_IMM14_X1:
  1648. case R_TILEGX_MF_IMM14_X1:
  1649. case R_TILEGX_MMSTART_X0:
  1650. case R_TILEGX_MMEND_X0:
  1651. case R_TILEGX_SHAMT_X0:
  1652. case R_TILEGX_SHAMT_X1:
  1653. case R_TILEGX_SHAMT_Y0:
  1654. case R_TILEGX_SHAMT_Y1:
  1655. case R_TILEGX_IMM16_X0_HW0:
  1656. case R_TILEGX_IMM16_X1_HW0:
  1657. case R_TILEGX_IMM16_X0_HW1:
  1658. case R_TILEGX_IMM16_X1_HW1:
  1659. case R_TILEGX_IMM16_X0_HW2:
  1660. case R_TILEGX_IMM16_X1_HW2:
  1661. case R_TILEGX_IMM16_X0_HW3:
  1662. case R_TILEGX_IMM16_X1_HW3:
  1663. case R_TILEGX_IMM16_X0_HW0_LAST:
  1664. case R_TILEGX_IMM16_X1_HW0_LAST:
  1665. case R_TILEGX_IMM16_X0_HW1_LAST:
  1666. case R_TILEGX_IMM16_X1_HW1_LAST:
  1667. case R_TILEGX_IMM16_X0_HW2_LAST:
  1668. case R_TILEGX_IMM16_X1_HW2_LAST:
  1669. if (h != NULL)
  1670. h->non_got_ref = 1;
  1671. r_tilegx_plt32:
  1672. if (h != NULL && !bfd_link_pic (info))
  1673. {
  1674. /* We may need a .plt entry if the function this reloc
  1675. refers to is in a shared lib. */
  1676. h->plt.refcount += 1;
  1677. }
  1678. /* If we are creating a shared library, and this is a reloc
  1679. against a global symbol, or a non PC relative reloc
  1680. against a local symbol, then we need to copy the reloc
  1681. into the shared library. However, if we are linking with
  1682. -Bsymbolic, we do not need to copy a reloc against a
  1683. global symbol which is defined in an object we are
  1684. including in the link (i.e., DEF_REGULAR is set). At
  1685. this point we have not seen all the input files, so it is
  1686. possible that DEF_REGULAR is not set now but will be set
  1687. later (it is never cleared). In case of a weak definition,
  1688. DEF_REGULAR may be cleared later by a strong definition in
  1689. a shared library. We account for that possibility below by
  1690. storing information in the relocs_copied field of the hash
  1691. table entry. A similar situation occurs when creating
  1692. shared libraries and symbol visibility changes render the
  1693. symbol local.
  1694. If on the other hand, we are creating an executable, we
  1695. may need to keep relocations for symbols satisfied by a
  1696. dynamic library if we manage to avoid copy relocs for the
  1697. symbol. */
  1698. if ((bfd_link_pic (info)
  1699. && (sec->flags & SEC_ALLOC) != 0
  1700. && (! tilegx_elf_howto_table[r_type].pc_relative
  1701. || (h != NULL
  1702. && (! info->symbolic
  1703. || h->root.type == bfd_link_hash_defweak
  1704. || !h->def_regular))))
  1705. || (!bfd_link_pic (info)
  1706. && (sec->flags & SEC_ALLOC) != 0
  1707. && h != NULL
  1708. && (h->root.type == bfd_link_hash_defweak
  1709. || !h->def_regular)))
  1710. {
  1711. struct elf_dyn_relocs *p;
  1712. struct elf_dyn_relocs **head;
  1713. /* When creating a shared object, we must copy these
  1714. relocs into the output file. We create a reloc
  1715. section in dynobj and make room for the reloc. */
  1716. if (sreloc == NULL)
  1717. {
  1718. sreloc = _bfd_elf_make_dynamic_reloc_section
  1719. (sec, htab->elf.dynobj, htab->word_align_power, abfd,
  1720. /*rela?*/ true);
  1721. if (sreloc == NULL)
  1722. return false;
  1723. }
  1724. /* If this is a global symbol, we count the number of
  1725. relocations we need for this symbol. */
  1726. if (h != NULL)
  1727. head = &h->dyn_relocs;
  1728. else
  1729. {
  1730. /* Track dynamic relocs needed for local syms too.
  1731. We really need local syms available to do this
  1732. easily. Oh well. */
  1733. asection *s;
  1734. void *vpp;
  1735. Elf_Internal_Sym *isym;
  1736. isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
  1737. abfd, r_symndx);
  1738. if (isym == NULL)
  1739. return false;
  1740. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  1741. if (s == NULL)
  1742. s = sec;
  1743. vpp = &elf_section_data (s)->local_dynrel;
  1744. head = (struct elf_dyn_relocs **) vpp;
  1745. }
  1746. p = *head;
  1747. if (p == NULL || p->sec != sec)
  1748. {
  1749. size_t amt = sizeof *p;
  1750. p = ((struct elf_dyn_relocs *)
  1751. bfd_alloc (htab->elf.dynobj, amt));
  1752. if (p == NULL)
  1753. return false;
  1754. p->next = *head;
  1755. *head = p;
  1756. p->sec = sec;
  1757. p->count = 0;
  1758. p->pc_count = 0;
  1759. }
  1760. p->count += 1;
  1761. if (tilegx_elf_howto_table[r_type].pc_relative)
  1762. p->pc_count += 1;
  1763. }
  1764. break;
  1765. case R_TILEGX_GNU_VTINHERIT:
  1766. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  1767. return false;
  1768. break;
  1769. case R_TILEGX_GNU_VTENTRY:
  1770. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  1771. return false;
  1772. break;
  1773. default:
  1774. break;
  1775. }
  1776. }
  1777. return true;
  1778. }
  1779. asection *
  1780. tilegx_elf_gc_mark_hook (asection *sec,
  1781. struct bfd_link_info *info,
  1782. Elf_Internal_Rela *rel,
  1783. struct elf_link_hash_entry *h,
  1784. Elf_Internal_Sym *sym)
  1785. {
  1786. if (h != NULL)
  1787. {
  1788. switch (TILEGX_ELF_R_TYPE (rel->r_info))
  1789. {
  1790. case R_TILEGX_GNU_VTINHERIT:
  1791. case R_TILEGX_GNU_VTENTRY:
  1792. return NULL;
  1793. }
  1794. }
  1795. /* FIXME: The test here, in check_relocs and in relocate_section
  1796. dealing with TLS optimization, ought to be !bfd_link_executable (info). */
  1797. if (bfd_link_pic (info))
  1798. {
  1799. struct bfd_link_hash_entry *bh;
  1800. switch (TILEGX_ELF_R_TYPE (rel->r_info))
  1801. {
  1802. case R_TILEGX_TLS_GD_CALL:
  1803. /* This reloc implicitly references __tls_get_addr. We know
  1804. another reloc will reference the same symbol as the one
  1805. on this reloc, so the real symbol and section will be
  1806. gc marked when processing the other reloc. That lets
  1807. us handle __tls_get_addr here. */
  1808. bh = NULL;
  1809. if (! _bfd_generic_link_add_one_symbol (info, sec->owner,
  1810. "__tls_get_addr", 0,
  1811. bfd_und_section_ptr,
  1812. 0, NULL, false,
  1813. false, &bh))
  1814. return NULL;
  1815. h = (struct elf_link_hash_entry *) bh;
  1816. BFD_ASSERT (h != NULL);
  1817. h->mark = 1;
  1818. if (h->is_weakalias)
  1819. weakdef (h)->mark = 1;
  1820. sym = NULL;
  1821. }
  1822. }
  1823. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  1824. }
  1825. /* Adjust a symbol defined by a dynamic object and referenced by a
  1826. regular object. The current definition is in some section of the
  1827. dynamic object, but we're not including those sections. We have to
  1828. change the definition to something the rest of the link can
  1829. understand. */
  1830. bool
  1831. tilegx_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
  1832. struct elf_link_hash_entry *h)
  1833. {
  1834. struct tilegx_elf_link_hash_table *htab;
  1835. bfd *dynobj;
  1836. asection *s, *srel;
  1837. htab = tilegx_elf_hash_table (info);
  1838. BFD_ASSERT (htab != NULL);
  1839. dynobj = htab->elf.dynobj;
  1840. /* Make sure we know what is going on here. */
  1841. BFD_ASSERT (dynobj != NULL
  1842. && (h->needs_plt
  1843. || h->is_weakalias
  1844. || (h->def_dynamic
  1845. && h->ref_regular
  1846. && !h->def_regular)));
  1847. /* If this is a function, put it in the procedure linkage table. We
  1848. will fill in the contents of the procedure linkage table later
  1849. (although we could actually do it here). */
  1850. if (h->type == STT_FUNC || h->needs_plt)
  1851. {
  1852. if (h->plt.refcount <= 0
  1853. || SYMBOL_CALLS_LOCAL (info, h)
  1854. || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  1855. && h->root.type == bfd_link_hash_undefweak))
  1856. {
  1857. /* This case can occur if we saw a R_TILEGX_JUMPOFF_X1_PLT
  1858. reloc in an input file, but the symbol was never referred
  1859. to by a dynamic object, or if all references were garbage
  1860. collected. In such a case, we don't actually need to build
  1861. a procedure linkage table, and we can just do a
  1862. R_TILEGX_JUMPOFF_X1 relocation instead. */
  1863. h->plt.offset = (bfd_vma) -1;
  1864. h->needs_plt = 0;
  1865. }
  1866. return true;
  1867. }
  1868. else
  1869. h->plt.offset = (bfd_vma) -1;
  1870. /* If this is a weak symbol, and there is a real definition, the
  1871. processor independent code will have arranged for us to see the
  1872. real definition first, and we can just use the same value. */
  1873. if (h->is_weakalias)
  1874. {
  1875. struct elf_link_hash_entry *def = weakdef (h);
  1876. BFD_ASSERT (def->root.type == bfd_link_hash_defined);
  1877. h->root.u.def.section = def->root.u.def.section;
  1878. h->root.u.def.value = def->root.u.def.value;
  1879. return true;
  1880. }
  1881. /* This is a reference to a symbol defined by a dynamic object which
  1882. is not a function. */
  1883. /* If we are creating a shared library, we must presume that the
  1884. only references to the symbol are via the global offset table.
  1885. For such cases we need not do anything here; the relocations will
  1886. be handled correctly by relocate_section. */
  1887. if (bfd_link_pic (info))
  1888. return true;
  1889. /* If there are no references to this symbol that do not use the
  1890. GOT, we don't need to generate a copy reloc. */
  1891. if (!h->non_got_ref)
  1892. return true;
  1893. /* If -z nocopyreloc was given, we won't generate them either. */
  1894. if (info->nocopyreloc)
  1895. {
  1896. h->non_got_ref = 0;
  1897. return true;
  1898. }
  1899. /* If we don't find any dynamic relocs in read-only sections, then
  1900. we'll be keeping the dynamic relocs and avoiding the copy reloc. */
  1901. if (!_bfd_elf_readonly_dynrelocs (h))
  1902. {
  1903. h->non_got_ref = 0;
  1904. return true;
  1905. }
  1906. /* We must allocate the symbol in our .dynbss section, which will
  1907. become part of the .bss section of the executable. There will be
  1908. an entry for this symbol in the .dynsym section. The dynamic
  1909. object will contain position independent code, so all references
  1910. from the dynamic object to this symbol will go through the global
  1911. offset table. The dynamic linker will use the .dynsym entry to
  1912. determine the address it must put in the global offset table, so
  1913. both the dynamic object and the regular object will refer to the
  1914. same memory location for the variable. */
  1915. /* We must generate a R_TILEGX_COPY reloc to tell the dynamic linker
  1916. to copy the initial value out of the dynamic object and into the
  1917. runtime process image. We need to remember the offset into the
  1918. .rel.bss section we are going to use. */
  1919. if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
  1920. {
  1921. s = htab->elf.sdynrelro;
  1922. srel = htab->elf.sreldynrelro;
  1923. }
  1924. else
  1925. {
  1926. s = htab->elf.sdynbss;
  1927. srel = htab->elf.srelbss;
  1928. }
  1929. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  1930. {
  1931. srel->size += TILEGX_ELF_RELA_BYTES (htab);
  1932. h->needs_copy = 1;
  1933. }
  1934. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  1935. }
  1936. /* Allocate space in .plt, .got and associated reloc sections for
  1937. dynamic relocs. */
  1938. static bool
  1939. allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
  1940. {
  1941. struct bfd_link_info *info;
  1942. struct tilegx_elf_link_hash_table *htab;
  1943. struct elf_dyn_relocs *p;
  1944. if (h->root.type == bfd_link_hash_indirect)
  1945. return true;
  1946. info = (struct bfd_link_info *) inf;
  1947. htab = tilegx_elf_hash_table (info);
  1948. BFD_ASSERT (htab != NULL);
  1949. if (htab->elf.dynamic_sections_created
  1950. && h->plt.refcount > 0)
  1951. {
  1952. /* Make sure this symbol is output as a dynamic symbol.
  1953. Undefined weak syms won't yet be marked as dynamic. */
  1954. if (h->dynindx == -1
  1955. && !h->forced_local)
  1956. {
  1957. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1958. return false;
  1959. }
  1960. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
  1961. {
  1962. asection *s = htab->elf.splt;
  1963. /* Allocate room for the header and tail. */
  1964. if (s->size == 0)
  1965. {
  1966. s->size = PLT_ENTRY_SIZE;
  1967. }
  1968. h->plt.offset = s->size - PLT_ENTRY_SIZE + PLT_HEADER_SIZE;
  1969. /* If this symbol is not defined in a regular file, and we are
  1970. not generating a shared library, then set the symbol to this
  1971. location in the .plt. This is required to make function
  1972. pointers compare as equal between the normal executable and
  1973. the shared library. */
  1974. if (! bfd_link_pic (info)
  1975. && !h->def_regular)
  1976. {
  1977. h->root.u.def.section = s;
  1978. h->root.u.def.value = h->plt.offset;
  1979. }
  1980. /* Make room for this entry. */
  1981. s->size += PLT_ENTRY_SIZE;
  1982. /* We also need to make an entry in the .got.plt section. */
  1983. htab->elf.sgotplt->size += GOT_ENTRY_SIZE (htab);
  1984. /* We also need to make an entry in the .rela.plt section. */
  1985. htab->elf.srelplt->size += TILEGX_ELF_RELA_BYTES (htab);
  1986. }
  1987. else
  1988. {
  1989. h->plt.offset = (bfd_vma) -1;
  1990. h->needs_plt = 0;
  1991. }
  1992. }
  1993. else
  1994. {
  1995. h->plt.offset = (bfd_vma) -1;
  1996. h->needs_plt = 0;
  1997. }
  1998. /* If a TLS_IE symbol is now local to the binary, make it a TLS_LE
  1999. requiring no TLS entry. */
  2000. if (h->got.refcount > 0
  2001. && !htab->disable_le_transition
  2002. && bfd_link_executable (info)
  2003. && h->dynindx == -1
  2004. && tilegx_elf_hash_entry(h)->tls_type == GOT_TLS_IE)
  2005. h->got.offset = (bfd_vma) -1;
  2006. else if (h->got.refcount > 0)
  2007. {
  2008. asection *s;
  2009. bool dyn;
  2010. int tls_type = tilegx_elf_hash_entry(h)->tls_type;
  2011. /* Make sure this symbol is output as a dynamic symbol.
  2012. Undefined weak syms won't yet be marked as dynamic. */
  2013. if (h->dynindx == -1
  2014. && !h->forced_local)
  2015. {
  2016. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2017. return false;
  2018. }
  2019. s = htab->elf.sgot;
  2020. h->got.offset = s->size;
  2021. s->size += TILEGX_ELF_WORD_BYTES (htab);
  2022. /* TLS_GD entries need 2 consecutive GOT slots. */
  2023. if (tls_type == GOT_TLS_GD)
  2024. s->size += TILEGX_ELF_WORD_BYTES (htab);
  2025. dyn = htab->elf.dynamic_sections_created;
  2026. /* TLS_IE needs one dynamic relocation,
  2027. TLS_GD needs two if local symbol and two if global. */
  2028. if (tls_type == GOT_TLS_GD || tls_type == GOT_TLS_IE)
  2029. htab->elf.srelgot->size += 2 * TILEGX_ELF_RELA_BYTES (htab);
  2030. else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  2031. bfd_link_pic (info),
  2032. h))
  2033. htab->elf.srelgot->size += TILEGX_ELF_RELA_BYTES (htab);
  2034. }
  2035. else
  2036. h->got.offset = (bfd_vma) -1;
  2037. if (h->dyn_relocs == NULL)
  2038. return true;
  2039. /* In the shared -Bsymbolic case, discard space allocated for
  2040. dynamic pc-relative relocs against symbols which turn out to be
  2041. defined in regular objects. For the normal shared case, discard
  2042. space for pc-relative relocs that have become local due to symbol
  2043. visibility changes. */
  2044. if (bfd_link_pic (info))
  2045. {
  2046. if (SYMBOL_CALLS_LOCAL (info, h))
  2047. {
  2048. struct elf_dyn_relocs **pp;
  2049. for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
  2050. {
  2051. p->count -= p->pc_count;
  2052. p->pc_count = 0;
  2053. if (p->count == 0)
  2054. *pp = p->next;
  2055. else
  2056. pp = &p->next;
  2057. }
  2058. }
  2059. /* Also discard relocs on undefined weak syms with non-default
  2060. visibility. */
  2061. if (h->dyn_relocs != NULL
  2062. && h->root.type == bfd_link_hash_undefweak)
  2063. {
  2064. if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  2065. || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
  2066. h->dyn_relocs = NULL;
  2067. /* Make sure undefined weak symbols are output as a dynamic
  2068. symbol in PIEs. */
  2069. else if (h->dynindx == -1
  2070. && !h->forced_local)
  2071. {
  2072. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2073. return false;
  2074. }
  2075. }
  2076. }
  2077. else
  2078. {
  2079. /* For the non-shared case, discard space for relocs against
  2080. symbols which turn out to need copy relocs or are not
  2081. dynamic. */
  2082. if (!h->non_got_ref
  2083. && ((h->def_dynamic
  2084. && !h->def_regular)
  2085. || (htab->elf.dynamic_sections_created
  2086. && (h->root.type == bfd_link_hash_undefweak
  2087. || h->root.type == bfd_link_hash_undefined))))
  2088. {
  2089. /* Make sure this symbol is output as a dynamic symbol.
  2090. Undefined weak syms won't yet be marked as dynamic. */
  2091. if (h->dynindx == -1
  2092. && !h->forced_local)
  2093. {
  2094. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2095. return false;
  2096. }
  2097. /* If that succeeded, we know we'll be keeping all the
  2098. relocs. */
  2099. if (h->dynindx != -1)
  2100. goto keep;
  2101. }
  2102. h->dyn_relocs = NULL;
  2103. keep: ;
  2104. }
  2105. /* Finally, allocate space. */
  2106. for (p = h->dyn_relocs; p != NULL; p = p->next)
  2107. {
  2108. asection *sreloc = elf_section_data (p->sec)->sreloc;
  2109. sreloc->size += p->count * TILEGX_ELF_RELA_BYTES (htab);
  2110. }
  2111. return true;
  2112. }
  2113. /* Return true if the dynamic symbol for a given section should be
  2114. omitted when creating a shared library. */
  2115. bool
  2116. tilegx_elf_omit_section_dynsym (bfd *output_bfd,
  2117. struct bfd_link_info *info,
  2118. asection *p)
  2119. {
  2120. /* We keep the .got section symbol so that explicit relocations
  2121. against the _GLOBAL_OFFSET_TABLE_ symbol emitted in PIC mode
  2122. can be turned into relocations against the .got symbol. */
  2123. if (strcmp (p->name, ".got") == 0)
  2124. return false;
  2125. return _bfd_elf_omit_section_dynsym_default (output_bfd, info, p);
  2126. }
  2127. bool
  2128. tilegx_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  2129. struct bfd_link_info *info)
  2130. {
  2131. struct tilegx_elf_link_hash_table *htab;
  2132. bfd *dynobj;
  2133. asection *s;
  2134. bfd *ibfd;
  2135. htab = tilegx_elf_hash_table (info);
  2136. BFD_ASSERT (htab != NULL);
  2137. dynobj = htab->elf.dynobj;
  2138. BFD_ASSERT (dynobj != NULL);
  2139. if (elf_hash_table (info)->dynamic_sections_created)
  2140. {
  2141. /* Set the contents of the .interp section to the interpreter. */
  2142. if (bfd_link_executable (info) && !info->nointerp)
  2143. {
  2144. s = bfd_get_linker_section (dynobj, ".interp");
  2145. BFD_ASSERT (s != NULL);
  2146. s->size = strlen (htab->dynamic_interpreter) + 1;
  2147. s->contents = (unsigned char *) htab->dynamic_interpreter;
  2148. }
  2149. }
  2150. /* Set up .got offsets for local syms, and space for local dynamic
  2151. relocs. */
  2152. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  2153. {
  2154. bfd_signed_vma *local_got;
  2155. bfd_signed_vma *end_local_got;
  2156. char *local_tls_type;
  2157. bfd_size_type locsymcount;
  2158. Elf_Internal_Shdr *symtab_hdr;
  2159. asection *srel;
  2160. if (! is_tilegx_elf (ibfd))
  2161. continue;
  2162. for (s = ibfd->sections; s != NULL; s = s->next)
  2163. {
  2164. struct elf_dyn_relocs *p;
  2165. for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
  2166. {
  2167. if (!bfd_is_abs_section (p->sec)
  2168. && bfd_is_abs_section (p->sec->output_section))
  2169. {
  2170. /* Input section has been discarded, either because
  2171. it is a copy of a linkonce section or due to
  2172. linker script /DISCARD/, so we'll be discarding
  2173. the relocs too. */
  2174. }
  2175. else if (p->count != 0)
  2176. {
  2177. srel = elf_section_data (p->sec)->sreloc;
  2178. srel->size += p->count * TILEGX_ELF_RELA_BYTES (htab);
  2179. if ((p->sec->output_section->flags & SEC_READONLY) != 0)
  2180. {
  2181. info->flags |= DF_TEXTREL;
  2182. info->callbacks->minfo (_("%pB: dynamic relocation in read-only section `%pA'\n"),
  2183. p->sec->owner, p->sec);
  2184. }
  2185. }
  2186. }
  2187. }
  2188. local_got = elf_local_got_refcounts (ibfd);
  2189. if (!local_got)
  2190. continue;
  2191. symtab_hdr = &elf_symtab_hdr (ibfd);
  2192. locsymcount = symtab_hdr->sh_info;
  2193. end_local_got = local_got + locsymcount;
  2194. local_tls_type = _bfd_tilegx_elf_local_got_tls_type (ibfd);
  2195. s = htab->elf.sgot;
  2196. srel = htab->elf.srelgot;
  2197. for (; local_got < end_local_got; ++local_got, ++local_tls_type)
  2198. {
  2199. if (*local_got > 0)
  2200. {
  2201. *local_got = s->size;
  2202. s->size += TILEGX_ELF_WORD_BYTES (htab);
  2203. if (*local_tls_type == GOT_TLS_GD)
  2204. s->size += TILEGX_ELF_WORD_BYTES (htab);
  2205. if (bfd_link_pic (info)
  2206. || *local_tls_type == GOT_TLS_GD
  2207. || *local_tls_type == GOT_TLS_IE)
  2208. srel->size += TILEGX_ELF_RELA_BYTES (htab);
  2209. }
  2210. else
  2211. *local_got = (bfd_vma) -1;
  2212. }
  2213. }
  2214. /* Allocate global sym .plt and .got entries, and space for global
  2215. sym dynamic relocs. */
  2216. elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
  2217. if (elf_hash_table (info)->dynamic_sections_created)
  2218. {
  2219. /* If the .got section is more than 0x8000 bytes, we add
  2220. 0x8000 to the value of _GLOBAL_OFFSET_TABLE_, so that 16
  2221. bit relocations have a greater chance of working. */
  2222. if (htab->elf.sgot->size >= 0x8000
  2223. && elf_hash_table (info)->hgot->root.u.def.value == 0)
  2224. elf_hash_table (info)->hgot->root.u.def.value = 0x8000;
  2225. }
  2226. if (htab->elf.sgotplt)
  2227. {
  2228. struct elf_link_hash_entry *got;
  2229. got = elf_link_hash_lookup (elf_hash_table (info),
  2230. "_GLOBAL_OFFSET_TABLE_",
  2231. false, false, false);
  2232. /* Don't allocate .got.plt section if there are no GOT nor PLT
  2233. entries and there is no refeence to _GLOBAL_OFFSET_TABLE_. */
  2234. if ((got == NULL
  2235. || !got->ref_regular_nonweak)
  2236. && (htab->elf.sgotplt->size
  2237. == (unsigned)GOTPLT_HEADER_SIZE (htab))
  2238. && (htab->elf.splt == NULL
  2239. || htab->elf.splt->size == 0)
  2240. && (htab->elf.sgot == NULL
  2241. || (htab->elf.sgot->size
  2242. == get_elf_backend_data (output_bfd)->got_header_size)))
  2243. htab->elf.sgotplt->size = 0;
  2244. }
  2245. /* The check_relocs and adjust_dynamic_symbol entry points have
  2246. determined the sizes of the various dynamic sections. Allocate
  2247. memory for them. */
  2248. for (s = dynobj->sections; s != NULL; s = s->next)
  2249. {
  2250. if ((s->flags & SEC_LINKER_CREATED) == 0)
  2251. continue;
  2252. if (s == htab->elf.splt
  2253. || s == htab->elf.sgot
  2254. || s == htab->elf.sgotplt
  2255. || s == htab->elf.sdynbss
  2256. || s == htab->elf.sdynrelro)
  2257. {
  2258. /* Strip this section if we don't need it; see the
  2259. comment below. */
  2260. }
  2261. else if (startswith (s->name, ".rela"))
  2262. {
  2263. if (s->size != 0)
  2264. {
  2265. /* We use the reloc_count field as a counter if we need
  2266. to copy relocs into the output file. */
  2267. s->reloc_count = 0;
  2268. }
  2269. }
  2270. else
  2271. {
  2272. /* It's not one of our sections. */
  2273. continue;
  2274. }
  2275. if (s->size == 0)
  2276. {
  2277. /* If we don't need this section, strip it from the
  2278. output file. This is mostly to handle .rela.bss and
  2279. .rela.plt. We must create both sections in
  2280. create_dynamic_sections, because they must be created
  2281. before the linker maps input sections to output
  2282. sections. The linker does that before
  2283. adjust_dynamic_symbol is called, and it is that
  2284. function which decides whether anything needs to go
  2285. into these sections. */
  2286. s->flags |= SEC_EXCLUDE;
  2287. continue;
  2288. }
  2289. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  2290. continue;
  2291. /* Allocate memory for the section contents. Zero the memory
  2292. for the benefit of .rela.plt, which has 4 unused entries
  2293. at the beginning, and we don't want garbage. */
  2294. s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
  2295. if (s->contents == NULL)
  2296. return false;
  2297. }
  2298. return _bfd_elf_add_dynamic_tags (output_bfd, info, true);
  2299. }
  2300. /* Return the base VMA address which should be subtracted from real addresses
  2301. when resolving @dtpoff relocation.
  2302. This is PT_TLS segment p_vaddr. */
  2303. static bfd_vma
  2304. dtpoff_base (struct bfd_link_info *info)
  2305. {
  2306. /* If tls_sec is NULL, we should have signalled an error already. */
  2307. if (elf_hash_table (info)->tls_sec == NULL)
  2308. return 0;
  2309. return elf_hash_table (info)->tls_sec->vma;
  2310. }
  2311. /* Return the relocation value for @tpoff relocation. */
  2312. static bfd_vma
  2313. tpoff (struct bfd_link_info *info, bfd_vma address)
  2314. {
  2315. struct elf_link_hash_table *htab = elf_hash_table (info);
  2316. /* If tls_sec is NULL, we should have signalled an error already. */
  2317. if (htab->tls_sec == NULL)
  2318. return 0;
  2319. return (address - htab->tls_sec->vma);
  2320. }
  2321. /* Copy SIZE bits from FROM to TO at address ADDR. */
  2322. static void
  2323. tilegx_copy_bits (bfd_byte *addr, int from, int to, int size)
  2324. {
  2325. int i;
  2326. for (i = 0; i < size; i++)
  2327. {
  2328. int from_byte = (from + i) / 8;
  2329. int from_bit = (from + i) % 8;
  2330. int to_byte = (to + i) / 8;
  2331. int to_bit = (to + i) % 8;
  2332. bfd_byte to_mask = 1 << to_bit;
  2333. addr[to_byte] = (addr[to_byte] & ~to_mask)
  2334. | ((addr[from_byte] >> from_bit << to_bit) & to_mask);
  2335. }
  2336. }
  2337. /* Replace the MASK bits in ADDR with those in INSN, for the next
  2338. TILEGX_BUNDLE_SIZE_IN_BYTES bytes. */
  2339. static void
  2340. tilegx_replace_insn (bfd_byte *addr, const bfd_byte *mask,
  2341. const bfd_byte *insn)
  2342. {
  2343. int i;
  2344. for (i = 0; i < TILEGX_BUNDLE_SIZE_IN_BYTES; i++)
  2345. {
  2346. addr[i] = (addr[i] & ~mask[i]) | (insn[i] & mask[i]);
  2347. }
  2348. }
  2349. /* Mask to extract the bits corresponding to an instruction in a
  2350. specific pipe of a bundle. */
  2351. static const bfd_byte insn_mask_X1[] = {
  2352. 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x3f
  2353. };
  2354. /* Mask to extract the bits corresponding to an instruction in a
  2355. specific pipe of a bundle, minus the destination operand and the
  2356. first source operand. */
  2357. static const bfd_byte insn_mask_X0_no_dest_no_srca[] = {
  2358. 0x00, 0xf0, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00
  2359. };
  2360. static const bfd_byte insn_mask_X1_no_dest_no_srca[] = {
  2361. 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x3f
  2362. };
  2363. static const bfd_byte insn_mask_Y0_no_dest_no_srca[] = {
  2364. 0x00, 0xf0, 0x0f, 0x78, 0x00, 0x00, 0x00, 0x00
  2365. };
  2366. static const bfd_byte insn_mask_Y1_no_dest_no_srca[] = {
  2367. 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x3c
  2368. };
  2369. /* Mask to extract the bits corresponding to an instruction in a
  2370. specific pipe of a bundle, minus the register operands. */
  2371. static const bfd_byte insn_mask_X0_no_operand[] = {
  2372. 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00
  2373. };
  2374. static const bfd_byte insn_mask_X1_no_operand[] = {
  2375. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x3f
  2376. };
  2377. static const bfd_byte insn_mask_Y0_no_operand[] = {
  2378. 0x00, 0x00, 0x0c, 0x78, 0x00, 0x00, 0x00, 0x00
  2379. };
  2380. static const bfd_byte insn_mask_Y1_no_operand[] = {
  2381. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x3c
  2382. };
  2383. /* Various instructions synthesized to support tls references. */
  2384. /* ld r0, r0 in the X1 pipe, used for tls ie. */
  2385. static const bfd_byte insn_tls_ie_ld_X1[] = {
  2386. 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0x6a, 0x28
  2387. };
  2388. /* ld4s r0, r0 in the X1 pipe, used for tls ie. */
  2389. static const bfd_byte insn_tls_ie_ld4s_X1[] = {
  2390. 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x6a, 0x28
  2391. };
  2392. /* add r0, r0, tp in various pipes, used for tls ie. */
  2393. static const bfd_byte insn_tls_ie_add_X0X1[] = {
  2394. 0x00, 0x50, 0x0f, 0x50, 0x00, 0xa8, 0x07, 0x28
  2395. };
  2396. static const bfd_byte insn_tls_ie_add_Y0Y1[] = {
  2397. 0x00, 0x50, 0x27, 0x2c, 0x00, 0xa8, 0x13, 0x9a
  2398. };
  2399. /* addx r0, r0, tp in various pipes, used for tls ie. */
  2400. static const bfd_byte insn_tls_ie_addx_X0X1[] = {
  2401. 0x00, 0x50, 0x0b, 0x50, 0x00, 0xa8, 0x05, 0x28
  2402. };
  2403. static const bfd_byte insn_tls_ie_addx_Y0Y1[] = {
  2404. 0x00, 0x50, 0x03, 0x2c, 0x00, 0xa8, 0x01, 0x9a
  2405. };
  2406. /* move r0, r0 in various pipes, used for tls gd. */
  2407. static const bfd_byte insn_tls_gd_add_X0X1[] = {
  2408. 0x00, 0xf0, 0x07, 0x51, 0x00, 0xf8, 0x3b, 0x28
  2409. };
  2410. static const bfd_byte insn_tls_gd_add_Y0Y1[] = {
  2411. 0x00, 0xf0, 0x0b, 0x54, 0x00, 0xf8, 0x05, 0xae
  2412. };
  2413. static const bfd_byte *insn_move_X0X1 = insn_tls_gd_add_X0X1;
  2414. static const bfd_byte *insn_move_Y0Y1 = insn_tls_gd_add_Y0Y1;
  2415. static const bfd_byte *insn_add_X0X1 = insn_tls_ie_add_X0X1;
  2416. static const bfd_byte *insn_add_Y0Y1 = insn_tls_ie_add_Y0Y1;
  2417. static const bfd_byte *insn_addx_X0X1 = insn_tls_ie_addx_X0X1;
  2418. static const bfd_byte *insn_addx_Y0Y1 = insn_tls_ie_addx_Y0Y1;
  2419. /* Relocate an TILEGX ELF section.
  2420. The RELOCATE_SECTION function is called by the new ELF backend linker
  2421. to handle the relocations for a section.
  2422. The relocs are always passed as Rela structures.
  2423. This function is responsible for adjusting the section contents as
  2424. necessary, and (if generating a relocatable output file) adjusting
  2425. the reloc addend as necessary.
  2426. This function does not have to worry about setting the reloc
  2427. address or the reloc symbol index.
  2428. LOCAL_SYMS is a pointer to the swapped in local symbols.
  2429. LOCAL_SECTIONS is an array giving the section in the input file
  2430. corresponding to the st_shndx field of each local symbol.
  2431. The global hash table entry for the global symbols can be found
  2432. via elf_sym_hashes (input_bfd).
  2433. When generating relocatable output, this function must handle
  2434. STB_LOCAL/STT_SECTION symbols specially. The output symbol is
  2435. going to be the section symbol corresponding to the output
  2436. section, which means that the addend must be adjusted
  2437. accordingly. */
  2438. int
  2439. tilegx_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
  2440. bfd *input_bfd, asection *input_section,
  2441. bfd_byte *contents, Elf_Internal_Rela *relocs,
  2442. Elf_Internal_Sym *local_syms,
  2443. asection **local_sections)
  2444. {
  2445. struct tilegx_elf_link_hash_table *htab;
  2446. Elf_Internal_Shdr *symtab_hdr;
  2447. struct elf_link_hash_entry **sym_hashes;
  2448. bfd_vma *local_got_offsets;
  2449. bfd_vma got_base;
  2450. asection *sreloc;
  2451. Elf_Internal_Rela *rel;
  2452. Elf_Internal_Rela *relend;
  2453. int num_relocs;
  2454. htab = tilegx_elf_hash_table (info);
  2455. BFD_ASSERT (htab != NULL);
  2456. symtab_hdr = &elf_symtab_hdr (input_bfd);
  2457. sym_hashes = elf_sym_hashes (input_bfd);
  2458. local_got_offsets = elf_local_got_offsets (input_bfd);
  2459. if (elf_hash_table (info)->hgot == NULL)
  2460. got_base = 0;
  2461. else
  2462. got_base = elf_hash_table (info)->hgot->root.u.def.value;
  2463. sreloc = elf_section_data (input_section)->sreloc;
  2464. rel = relocs;
  2465. num_relocs = input_section->reloc_count;
  2466. relend = relocs + num_relocs;
  2467. for (; rel < relend; rel++)
  2468. {
  2469. int r_type, tls_type;
  2470. bool is_tls_iele, is_tls_le;
  2471. reloc_howto_type *howto;
  2472. unsigned long r_symndx;
  2473. struct elf_link_hash_entry *h;
  2474. Elf_Internal_Sym *sym;
  2475. tilegx_create_func create_func;
  2476. asection *sec;
  2477. bfd_vma relocation;
  2478. bfd_reloc_status_type r;
  2479. const char *name;
  2480. bfd_vma off;
  2481. bool is_plt = false;
  2482. bool resolved_to_zero;
  2483. bool unresolved_reloc;
  2484. r_type = TILEGX_ELF_R_TYPE (rel->r_info);
  2485. if (r_type == R_TILEGX_GNU_VTINHERIT
  2486. || r_type == R_TILEGX_GNU_VTENTRY)
  2487. continue;
  2488. if ((unsigned int)r_type >= ARRAY_SIZE (tilegx_elf_howto_table))
  2489. return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
  2490. howto = tilegx_elf_howto_table + r_type;
  2491. /* This is a final link. */
  2492. r_symndx = TILEGX_ELF_R_SYMNDX (htab, rel->r_info);
  2493. h = NULL;
  2494. sym = NULL;
  2495. sec = NULL;
  2496. unresolved_reloc = false;
  2497. if (r_symndx < symtab_hdr->sh_info)
  2498. {
  2499. sym = local_syms + r_symndx;
  2500. sec = local_sections[r_symndx];
  2501. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  2502. }
  2503. else
  2504. {
  2505. bool warned ATTRIBUTE_UNUSED;
  2506. bool ignored ATTRIBUTE_UNUSED;
  2507. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  2508. r_symndx, symtab_hdr, sym_hashes,
  2509. h, sec, relocation,
  2510. unresolved_reloc, warned, ignored);
  2511. if (warned)
  2512. {
  2513. /* To avoid generating warning messages about truncated
  2514. relocations, set the relocation's address to be the same as
  2515. the start of this section. */
  2516. if (input_section->output_section != NULL)
  2517. relocation = input_section->output_section->vma;
  2518. else
  2519. relocation = 0;
  2520. }
  2521. }
  2522. if (sec != NULL && discarded_section (sec))
  2523. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  2524. rel, 1, relend, howto, 0, contents);
  2525. if (bfd_link_relocatable (info))
  2526. continue;
  2527. if (h != NULL)
  2528. name = h->root.root.string;
  2529. else
  2530. {
  2531. name = (bfd_elf_string_from_elf_section
  2532. (input_bfd, symtab_hdr->sh_link, sym->st_name));
  2533. if (name == NULL || *name == '\0')
  2534. name = bfd_section_name (sec);
  2535. }
  2536. switch (r_type)
  2537. {
  2538. case R_TILEGX_TLS_GD_CALL:
  2539. case R_TILEGX_IMM8_X0_TLS_GD_ADD:
  2540. case R_TILEGX_IMM8_Y0_TLS_GD_ADD:
  2541. case R_TILEGX_IMM8_X1_TLS_GD_ADD:
  2542. case R_TILEGX_IMM8_Y1_TLS_GD_ADD:
  2543. case R_TILEGX_IMM8_X0_TLS_ADD:
  2544. case R_TILEGX_IMM8_Y0_TLS_ADD:
  2545. case R_TILEGX_IMM8_X1_TLS_ADD:
  2546. case R_TILEGX_IMM8_Y1_TLS_ADD:
  2547. tls_type = GOT_UNKNOWN;
  2548. if (h == NULL && local_got_offsets)
  2549. tls_type =
  2550. _bfd_tilegx_elf_local_got_tls_type (input_bfd) [r_symndx];
  2551. else if (h != NULL)
  2552. tls_type = tilegx_elf_hash_entry(h)->tls_type;
  2553. is_tls_iele = (bfd_link_executable (info) || tls_type == GOT_TLS_IE);
  2554. is_tls_le = is_tls_iele && (!input_section->sec_flg0
  2555. && bfd_link_executable (info)
  2556. && (h == NULL || h->dynindx == -1));
  2557. if (r_type == R_TILEGX_TLS_GD_CALL)
  2558. {
  2559. if (is_tls_le)
  2560. {
  2561. /* GD -> LE */
  2562. tilegx_replace_insn (contents + rel->r_offset,
  2563. insn_mask_X1, insn_move_X0X1);
  2564. continue;
  2565. }
  2566. else if (is_tls_iele)
  2567. {
  2568. /* GD -> IE */
  2569. if (ABI_64_P (output_bfd))
  2570. tilegx_replace_insn (contents + rel->r_offset,
  2571. insn_mask_X1, insn_tls_ie_ld_X1);
  2572. else
  2573. tilegx_replace_insn (contents + rel->r_offset,
  2574. insn_mask_X1, insn_tls_ie_ld4s_X1);
  2575. continue;
  2576. }
  2577. /* GD -> GD */
  2578. h = (struct elf_link_hash_entry *)
  2579. bfd_link_hash_lookup (info->hash, "__tls_get_addr", false,
  2580. false, true);
  2581. BFD_ASSERT (h != NULL);
  2582. r_type = R_TILEGX_JUMPOFF_X1_PLT;
  2583. howto = tilegx_elf_howto_table + r_type;
  2584. }
  2585. else if (r_type == R_TILEGX_IMM8_X0_TLS_ADD
  2586. || r_type == R_TILEGX_IMM8_X1_TLS_ADD
  2587. || r_type == R_TILEGX_IMM8_Y0_TLS_ADD
  2588. || r_type == R_TILEGX_IMM8_Y1_TLS_ADD)
  2589. {
  2590. bool is_pipe0 =
  2591. (r_type == R_TILEGX_IMM8_X0_TLS_ADD
  2592. || r_type == R_TILEGX_IMM8_Y0_TLS_ADD);
  2593. bool is_X0X1 =
  2594. (r_type == R_TILEGX_IMM8_X0_TLS_ADD
  2595. || r_type == R_TILEGX_IMM8_X1_TLS_ADD);
  2596. int dest_begin = is_pipe0 ? 0 : 31;
  2597. int src_begin;
  2598. const bfd_byte *insn;
  2599. const bfd_byte *mask = NULL;
  2600. if (is_tls_le)
  2601. {
  2602. /* 1. copy dest operand into the first source operand.
  2603. 2. change the opcode to "move". */
  2604. src_begin = is_pipe0 ? 6 : 37;
  2605. insn = is_X0X1 ? insn_move_X0X1 : insn_move_Y0Y1;
  2606. switch (r_type)
  2607. {
  2608. case R_TILEGX_IMM8_X0_TLS_ADD:
  2609. mask = insn_mask_X0_no_dest_no_srca;
  2610. break;
  2611. case R_TILEGX_IMM8_X1_TLS_ADD:
  2612. mask = insn_mask_X1_no_dest_no_srca;
  2613. break;
  2614. case R_TILEGX_IMM8_Y0_TLS_ADD:
  2615. mask = insn_mask_Y0_no_dest_no_srca;
  2616. break;
  2617. case R_TILEGX_IMM8_Y1_TLS_ADD:
  2618. mask = insn_mask_Y1_no_dest_no_srca;
  2619. break;
  2620. }
  2621. }
  2622. else
  2623. {
  2624. /* 1. copy dest operand into the second source operand.
  2625. 2. change the opcode to "add". */
  2626. src_begin = is_pipe0 ? 12 : 43;
  2627. if (ABI_64_P (output_bfd))
  2628. insn = is_X0X1 ? insn_add_X0X1 : insn_add_Y0Y1;
  2629. else
  2630. insn = is_X0X1 ? insn_addx_X0X1 : insn_addx_Y0Y1;
  2631. switch (r_type)
  2632. {
  2633. case R_TILEGX_IMM8_X0_TLS_ADD:
  2634. mask = insn_mask_X0_no_operand;
  2635. break;
  2636. case R_TILEGX_IMM8_X1_TLS_ADD:
  2637. mask = insn_mask_X1_no_operand;
  2638. break;
  2639. case R_TILEGX_IMM8_Y0_TLS_ADD:
  2640. mask = insn_mask_Y0_no_operand;
  2641. break;
  2642. case R_TILEGX_IMM8_Y1_TLS_ADD:
  2643. mask = insn_mask_Y1_no_operand;
  2644. break;
  2645. }
  2646. }
  2647. tilegx_copy_bits (contents + rel->r_offset, dest_begin,
  2648. src_begin, 6);
  2649. tilegx_replace_insn (contents + rel->r_offset, mask, insn);
  2650. continue;
  2651. }
  2652. else
  2653. {
  2654. const bfd_byte *mask = NULL;
  2655. const bfd_byte *add_insn = NULL;
  2656. bool is_64bit = ABI_64_P (output_bfd);
  2657. switch (r_type)
  2658. {
  2659. case R_TILEGX_IMM8_X0_TLS_GD_ADD:
  2660. add_insn = is_tls_iele
  2661. ? (is_64bit ? insn_tls_ie_add_X0X1 : insn_tls_ie_addx_X0X1)
  2662. : insn_tls_gd_add_X0X1;
  2663. mask = insn_mask_X0_no_dest_no_srca;
  2664. break;
  2665. case R_TILEGX_IMM8_X1_TLS_GD_ADD:
  2666. add_insn = is_tls_iele
  2667. ? (is_64bit ? insn_tls_ie_add_X0X1 : insn_tls_ie_addx_X0X1)
  2668. : insn_tls_gd_add_X0X1;
  2669. mask = insn_mask_X1_no_dest_no_srca;
  2670. break;
  2671. case R_TILEGX_IMM8_Y0_TLS_GD_ADD:
  2672. add_insn = is_tls_iele
  2673. ? (is_64bit ? insn_tls_ie_add_Y0Y1 : insn_tls_ie_addx_Y0Y1)
  2674. : insn_tls_gd_add_Y0Y1;
  2675. mask = insn_mask_Y0_no_dest_no_srca;
  2676. break;
  2677. case R_TILEGX_IMM8_Y1_TLS_GD_ADD:
  2678. add_insn = is_tls_iele
  2679. ? (is_64bit ? insn_tls_ie_add_Y0Y1 : insn_tls_ie_addx_Y0Y1)
  2680. : insn_tls_gd_add_Y0Y1;
  2681. mask = insn_mask_Y1_no_dest_no_srca;
  2682. break;
  2683. }
  2684. tilegx_replace_insn (contents + rel->r_offset, mask, add_insn);
  2685. continue;
  2686. }
  2687. break;
  2688. case R_TILEGX_TLS_IE_LOAD:
  2689. if (!input_section->sec_flg0
  2690. && bfd_link_executable (info)
  2691. && (h == NULL || h->dynindx == -1))
  2692. {
  2693. /* IE -> LE */
  2694. tilegx_replace_insn (contents + rel->r_offset,
  2695. insn_mask_X1_no_dest_no_srca,
  2696. insn_move_X0X1);
  2697. }
  2698. else
  2699. {
  2700. /* IE -> IE */
  2701. if (ABI_64_P (output_bfd))
  2702. tilegx_replace_insn (contents + rel->r_offset,
  2703. insn_mask_X1_no_dest_no_srca,
  2704. insn_tls_ie_ld_X1);
  2705. else
  2706. tilegx_replace_insn (contents + rel->r_offset,
  2707. insn_mask_X1_no_dest_no_srca,
  2708. insn_tls_ie_ld4s_X1);
  2709. }
  2710. continue;
  2711. break;
  2712. default:
  2713. break;
  2714. }
  2715. resolved_to_zero = (h != NULL
  2716. && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
  2717. switch (r_type)
  2718. {
  2719. case R_TILEGX_IMM16_X0_HW0_GOT:
  2720. case R_TILEGX_IMM16_X1_HW0_GOT:
  2721. case R_TILEGX_IMM16_X0_HW0_LAST_GOT:
  2722. case R_TILEGX_IMM16_X1_HW0_LAST_GOT:
  2723. case R_TILEGX_IMM16_X0_HW1_LAST_GOT:
  2724. case R_TILEGX_IMM16_X1_HW1_LAST_GOT:
  2725. /* Relocation is to the entry for this symbol in the global
  2726. offset table. */
  2727. if (htab->elf.sgot == NULL)
  2728. abort ();
  2729. if (h != NULL)
  2730. {
  2731. bool dyn;
  2732. off = h->got.offset;
  2733. BFD_ASSERT (off != (bfd_vma) -1);
  2734. dyn = elf_hash_table (info)->dynamic_sections_created;
  2735. if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  2736. bfd_link_pic (info),
  2737. h)
  2738. || (bfd_link_pic (info)
  2739. && SYMBOL_REFERENCES_LOCAL (info, h)))
  2740. {
  2741. /* This is actually a static link, or it is a
  2742. -Bsymbolic link and the symbol is defined
  2743. locally, or the symbol was forced to be local
  2744. because of a version file. We must initialize
  2745. this entry in the global offset table. Since the
  2746. offset must always be a multiple
  2747. of 8 for 64-bit, we use the least significant bit
  2748. to record whether we have initialized it already.
  2749. When doing a dynamic link, we create a .rela.got
  2750. relocation entry to initialize the value. This
  2751. is done in the finish_dynamic_symbol routine. */
  2752. if ((off & 1) != 0)
  2753. off &= ~1;
  2754. else
  2755. {
  2756. TILEGX_ELF_PUT_WORD (htab, output_bfd, relocation,
  2757. htab->elf.sgot->contents + off);
  2758. h->got.offset |= 1;
  2759. }
  2760. }
  2761. else
  2762. unresolved_reloc = false;
  2763. }
  2764. else
  2765. {
  2766. BFD_ASSERT (local_got_offsets != NULL
  2767. && local_got_offsets[r_symndx] != (bfd_vma) -1);
  2768. off = local_got_offsets[r_symndx];
  2769. /* The offset must always be a multiple of 8 on 64-bit.
  2770. We use the least significant bit to record
  2771. whether we have already processed this entry. */
  2772. if ((off & 1) != 0)
  2773. off &= ~1;
  2774. else
  2775. {
  2776. if (bfd_link_pic (info))
  2777. {
  2778. asection *s;
  2779. Elf_Internal_Rela outrel;
  2780. /* We need to generate a R_TILEGX_RELATIVE reloc
  2781. for the dynamic linker. */
  2782. s = htab->elf.srelgot;
  2783. BFD_ASSERT (s != NULL);
  2784. outrel.r_offset = (htab->elf.sgot->output_section->vma
  2785. + htab->elf.sgot->output_offset
  2786. + off);
  2787. outrel.r_info =
  2788. TILEGX_ELF_R_INFO (htab, NULL, 0, R_TILEGX_RELATIVE);
  2789. outrel.r_addend = relocation;
  2790. relocation = 0;
  2791. tilegx_elf_append_rela (output_bfd, s, &outrel);
  2792. }
  2793. TILEGX_ELF_PUT_WORD (htab, output_bfd, relocation,
  2794. htab->elf.sgot->contents + off);
  2795. local_got_offsets[r_symndx] |= 1;
  2796. }
  2797. }
  2798. relocation = off - got_base;
  2799. break;
  2800. case R_TILEGX_JUMPOFF_X1_PLT:
  2801. case R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
  2802. case R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
  2803. case R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
  2804. case R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
  2805. case R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
  2806. case R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
  2807. case R_TILEGX_IMM16_X0_HW3_PLT_PCREL:
  2808. case R_TILEGX_IMM16_X1_HW3_PLT_PCREL:
  2809. case R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
  2810. case R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
  2811. case R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
  2812. case R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
  2813. case R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
  2814. case R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
  2815. /* Relocation is to the entry for this symbol in the
  2816. procedure linkage table. */
  2817. BFD_ASSERT (h != NULL);
  2818. if (h->plt.offset == (bfd_vma) -1 || htab->elf.splt == NULL)
  2819. {
  2820. /* We didn't make a PLT entry for this symbol. This
  2821. happens when statically linking PIC code, or when
  2822. using -Bsymbolic. */
  2823. break;
  2824. }
  2825. relocation = (htab->elf.splt->output_section->vma
  2826. + htab->elf.splt->output_offset
  2827. + h->plt.offset);
  2828. unresolved_reloc = false;
  2829. break;
  2830. case R_TILEGX_64_PCREL:
  2831. case R_TILEGX_32_PCREL:
  2832. case R_TILEGX_16_PCREL:
  2833. case R_TILEGX_8_PCREL:
  2834. case R_TILEGX_IMM16_X0_HW0_PCREL:
  2835. case R_TILEGX_IMM16_X1_HW0_PCREL:
  2836. case R_TILEGX_IMM16_X0_HW1_PCREL:
  2837. case R_TILEGX_IMM16_X1_HW1_PCREL:
  2838. case R_TILEGX_IMM16_X0_HW2_PCREL:
  2839. case R_TILEGX_IMM16_X1_HW2_PCREL:
  2840. case R_TILEGX_IMM16_X0_HW3_PCREL:
  2841. case R_TILEGX_IMM16_X1_HW3_PCREL:
  2842. case R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
  2843. case R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
  2844. case R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
  2845. case R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
  2846. case R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
  2847. case R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
  2848. if (h != NULL
  2849. && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
  2850. break;
  2851. /* Fall through. */
  2852. case R_TILEGX_64:
  2853. case R_TILEGX_32:
  2854. case R_TILEGX_16:
  2855. case R_TILEGX_8:
  2856. case R_TILEGX_HW0:
  2857. case R_TILEGX_HW1:
  2858. case R_TILEGX_HW2:
  2859. case R_TILEGX_HW3:
  2860. case R_TILEGX_HW0_LAST:
  2861. case R_TILEGX_HW1_LAST:
  2862. case R_TILEGX_HW2_LAST:
  2863. case R_TILEGX_COPY:
  2864. case R_TILEGX_GLOB_DAT:
  2865. case R_TILEGX_JMP_SLOT:
  2866. case R_TILEGX_RELATIVE:
  2867. case R_TILEGX_BROFF_X1:
  2868. case R_TILEGX_JUMPOFF_X1:
  2869. case R_TILEGX_IMM8_X0:
  2870. case R_TILEGX_IMM8_Y0:
  2871. case R_TILEGX_IMM8_X1:
  2872. case R_TILEGX_IMM8_Y1:
  2873. case R_TILEGX_DEST_IMM8_X1:
  2874. case R_TILEGX_MT_IMM14_X1:
  2875. case R_TILEGX_MF_IMM14_X1:
  2876. case R_TILEGX_MMSTART_X0:
  2877. case R_TILEGX_MMEND_X0:
  2878. case R_TILEGX_SHAMT_X0:
  2879. case R_TILEGX_SHAMT_X1:
  2880. case R_TILEGX_SHAMT_Y0:
  2881. case R_TILEGX_SHAMT_Y1:
  2882. case R_TILEGX_IMM16_X0_HW0:
  2883. case R_TILEGX_IMM16_X1_HW0:
  2884. case R_TILEGX_IMM16_X0_HW1:
  2885. case R_TILEGX_IMM16_X1_HW1:
  2886. case R_TILEGX_IMM16_X0_HW2:
  2887. case R_TILEGX_IMM16_X1_HW2:
  2888. case R_TILEGX_IMM16_X0_HW3:
  2889. case R_TILEGX_IMM16_X1_HW3:
  2890. case R_TILEGX_IMM16_X0_HW0_LAST:
  2891. case R_TILEGX_IMM16_X1_HW0_LAST:
  2892. case R_TILEGX_IMM16_X0_HW1_LAST:
  2893. case R_TILEGX_IMM16_X1_HW1_LAST:
  2894. case R_TILEGX_IMM16_X0_HW2_LAST:
  2895. case R_TILEGX_IMM16_X1_HW2_LAST:
  2896. if ((input_section->flags & SEC_ALLOC) == 0)
  2897. break;
  2898. if ((bfd_link_pic (info)
  2899. && (h == NULL
  2900. || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  2901. && !resolved_to_zero)
  2902. || h->root.type != bfd_link_hash_undefweak)
  2903. && (! howto->pc_relative
  2904. || !SYMBOL_CALLS_LOCAL (info, h)))
  2905. || (!bfd_link_pic (info)
  2906. && h != NULL
  2907. && h->dynindx != -1
  2908. && !h->non_got_ref
  2909. && ((h->def_dynamic
  2910. && !h->def_regular)
  2911. || h->root.type == bfd_link_hash_undefweak
  2912. || h->root.type == bfd_link_hash_undefined)))
  2913. {
  2914. Elf_Internal_Rela outrel;
  2915. bool skip, relocate = false;
  2916. /* When generating a shared object, these relocations
  2917. are copied into the output file to be resolved at run
  2918. time. */
  2919. BFD_ASSERT (sreloc != NULL);
  2920. skip = false;
  2921. outrel.r_offset =
  2922. _bfd_elf_section_offset (output_bfd, info, input_section,
  2923. rel->r_offset);
  2924. if (outrel.r_offset == (bfd_vma) -1)
  2925. skip = true;
  2926. else if (outrel.r_offset == (bfd_vma) -2)
  2927. skip = true, relocate = true;
  2928. outrel.r_offset += (input_section->output_section->vma
  2929. + input_section->output_offset);
  2930. switch (r_type)
  2931. {
  2932. case R_TILEGX_64_PCREL:
  2933. case R_TILEGX_32_PCREL:
  2934. case R_TILEGX_16_PCREL:
  2935. case R_TILEGX_8_PCREL:
  2936. /* If the symbol is not dynamic, we should not keep
  2937. a dynamic relocation. But an .rela.* slot has been
  2938. allocated for it, output R_TILEGX_NONE.
  2939. FIXME: Add code tracking needed dynamic relocs as
  2940. e.g. i386 has. */
  2941. if (h->dynindx == -1)
  2942. skip = true, relocate = true;
  2943. break;
  2944. }
  2945. if (skip)
  2946. memset (&outrel, 0, sizeof outrel);
  2947. /* h->dynindx may be -1 if the symbol was marked to
  2948. become local. */
  2949. else if (h != NULL &&
  2950. h->dynindx != -1
  2951. && (! is_plt
  2952. || !bfd_link_pic (info)
  2953. || !SYMBOLIC_BIND (info, h)
  2954. || !h->def_regular))
  2955. {
  2956. BFD_ASSERT (h->dynindx != -1);
  2957. outrel.r_info = TILEGX_ELF_R_INFO (htab, rel, h->dynindx, r_type);
  2958. outrel.r_addend = rel->r_addend;
  2959. }
  2960. else
  2961. {
  2962. if (r_type == R_TILEGX_32 || r_type == R_TILEGX_64)
  2963. {
  2964. outrel.r_info = TILEGX_ELF_R_INFO (htab, NULL, 0,
  2965. R_TILEGX_RELATIVE);
  2966. outrel.r_addend = relocation + rel->r_addend;
  2967. }
  2968. else
  2969. {
  2970. long indx;
  2971. outrel.r_addend = relocation + rel->r_addend;
  2972. if (is_plt)
  2973. sec = htab->elf.splt;
  2974. if (bfd_is_abs_section (sec))
  2975. indx = 0;
  2976. else if (sec == NULL || sec->owner == NULL)
  2977. {
  2978. bfd_set_error (bfd_error_bad_value);
  2979. return false;
  2980. }
  2981. else
  2982. {
  2983. asection *osec;
  2984. /* We are turning this relocation into one
  2985. against a section symbol. It would be
  2986. proper to subtract the symbol's value,
  2987. osec->vma, from the emitted reloc addend,
  2988. but ld.so expects buggy relocs. */
  2989. osec = sec->output_section;
  2990. indx = elf_section_data (osec)->dynindx;
  2991. if (indx == 0)
  2992. {
  2993. osec = htab->elf.text_index_section;
  2994. indx = elf_section_data (osec)->dynindx;
  2995. }
  2996. /* FIXME: we really should be able to link non-pic
  2997. shared libraries. */
  2998. if (indx == 0)
  2999. {
  3000. BFD_FAIL ();
  3001. _bfd_error_handler
  3002. (_("%pB: probably compiled without -fPIC?"),
  3003. input_bfd);
  3004. bfd_set_error (bfd_error_bad_value);
  3005. return false;
  3006. }
  3007. }
  3008. outrel.r_info = TILEGX_ELF_R_INFO (htab, rel, indx,
  3009. r_type);
  3010. }
  3011. }
  3012. tilegx_elf_append_rela (output_bfd, sreloc, &outrel);
  3013. /* This reloc will be computed at runtime, so there's no
  3014. need to do anything now. */
  3015. if (! relocate)
  3016. continue;
  3017. }
  3018. break;
  3019. case R_TILEGX_IMM16_X0_HW0_TLS_LE:
  3020. case R_TILEGX_IMM16_X1_HW0_TLS_LE:
  3021. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
  3022. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
  3023. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
  3024. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
  3025. if (!bfd_link_executable (info))
  3026. {
  3027. Elf_Internal_Rela outrel;
  3028. bool skip;
  3029. BFD_ASSERT (sreloc != NULL);
  3030. skip = false;
  3031. outrel.r_offset =
  3032. _bfd_elf_section_offset (output_bfd, info, input_section,
  3033. rel->r_offset);
  3034. if (outrel.r_offset == (bfd_vma) -1)
  3035. skip = true;
  3036. else if (outrel.r_offset == (bfd_vma) -2)
  3037. skip = true;
  3038. outrel.r_offset += (input_section->output_section->vma
  3039. + input_section->output_offset);
  3040. if (skip)
  3041. memset (&outrel, 0, sizeof outrel);
  3042. else
  3043. {
  3044. outrel.r_info = TILEGX_ELF_R_INFO (htab, NULL, 0, r_type);
  3045. outrel.r_addend = relocation - dtpoff_base (info)
  3046. + rel->r_addend;
  3047. }
  3048. tilegx_elf_append_rela (output_bfd, sreloc, &outrel);
  3049. continue;
  3050. }
  3051. relocation = tpoff (info, relocation);
  3052. break;
  3053. case R_TILEGX_IMM16_X0_HW0_TLS_GD:
  3054. case R_TILEGX_IMM16_X1_HW0_TLS_GD:
  3055. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  3056. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  3057. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  3058. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  3059. case R_TILEGX_IMM16_X0_HW0_TLS_IE:
  3060. case R_TILEGX_IMM16_X1_HW0_TLS_IE:
  3061. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  3062. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  3063. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  3064. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  3065. r_type = tilegx_elf_tls_transition (info, r_type, h == NULL,
  3066. input_section->sec_flg0);
  3067. tls_type = GOT_UNKNOWN;
  3068. if (h == NULL && local_got_offsets)
  3069. tls_type =
  3070. _bfd_tilegx_elf_local_got_tls_type (input_bfd) [r_symndx];
  3071. else if (h != NULL)
  3072. {
  3073. tls_type = tilegx_elf_hash_entry(h)->tls_type;
  3074. if (bfd_link_executable (info)
  3075. && h->dynindx == -1
  3076. && tls_type == GOT_TLS_IE)
  3077. r_type = (!input_section->sec_flg0
  3078. ? tilegx_tls_translate_to_le (r_type)
  3079. : tilegx_tls_translate_to_ie (r_type));
  3080. }
  3081. if (tls_type == GOT_TLS_IE)
  3082. r_type = tilegx_tls_translate_to_ie (r_type);
  3083. if (r_type == R_TILEGX_IMM16_X0_HW0_TLS_LE
  3084. || r_type == R_TILEGX_IMM16_X1_HW0_TLS_LE
  3085. || r_type == R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE
  3086. || r_type == R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE
  3087. || r_type == R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE
  3088. || r_type == R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE)
  3089. {
  3090. relocation = tpoff (info, relocation);
  3091. break;
  3092. }
  3093. if (h != NULL)
  3094. {
  3095. off = h->got.offset;
  3096. h->got.offset |= 1;
  3097. }
  3098. else
  3099. {
  3100. BFD_ASSERT (local_got_offsets != NULL);
  3101. off = local_got_offsets[r_symndx];
  3102. local_got_offsets[r_symndx] |= 1;
  3103. }
  3104. if (htab->elf.sgot == NULL)
  3105. abort ();
  3106. if ((off & 1) != 0)
  3107. off &= ~1;
  3108. else
  3109. {
  3110. Elf_Internal_Rela outrel;
  3111. int indx = 0;
  3112. bool need_relocs = false;
  3113. if (htab->elf.srelgot == NULL)
  3114. abort ();
  3115. if (h != NULL)
  3116. {
  3117. bool dyn;
  3118. dyn = htab->elf.dynamic_sections_created;
  3119. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  3120. bfd_link_pic (info),
  3121. h)
  3122. && (!bfd_link_pic (info)
  3123. || !SYMBOL_REFERENCES_LOCAL (info, h)))
  3124. {
  3125. indx = h->dynindx;
  3126. }
  3127. }
  3128. /* The GOT entries have not been initialized yet. Do it
  3129. now, and emit any relocations. */
  3130. if ((bfd_link_pic (info) || indx != 0)
  3131. && (h == NULL
  3132. || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  3133. || h->root.type != bfd_link_hash_undefweak))
  3134. need_relocs = true;
  3135. switch (r_type)
  3136. {
  3137. case R_TILEGX_IMM16_X0_HW0_TLS_IE:
  3138. case R_TILEGX_IMM16_X1_HW0_TLS_IE:
  3139. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  3140. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  3141. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  3142. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  3143. if (need_relocs) {
  3144. TILEGX_ELF_PUT_WORD (htab, output_bfd, 0,
  3145. htab->elf.sgot->contents + off);
  3146. outrel.r_offset = (htab->elf.sgot->output_section->vma
  3147. + htab->elf.sgot->output_offset + off);
  3148. outrel.r_addend = 0;
  3149. if (indx == 0)
  3150. outrel.r_addend = relocation - dtpoff_base (info);
  3151. outrel.r_info = TILEGX_ELF_R_INFO (htab, NULL, indx,
  3152. TILEGX_ELF_TPOFF_RELOC (htab));
  3153. tilegx_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
  3154. } else {
  3155. TILEGX_ELF_PUT_WORD (htab, output_bfd,
  3156. tpoff (info, relocation),
  3157. htab->elf.sgot->contents + off);
  3158. }
  3159. break;
  3160. case R_TILEGX_IMM16_X0_HW0_TLS_GD:
  3161. case R_TILEGX_IMM16_X1_HW0_TLS_GD:
  3162. case R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  3163. case R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  3164. case R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  3165. case R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  3166. if (need_relocs) {
  3167. outrel.r_offset = (htab->elf.sgot->output_section->vma
  3168. + htab->elf.sgot->output_offset + off);
  3169. outrel.r_addend = 0;
  3170. outrel.r_info = TILEGX_ELF_R_INFO (htab, NULL, indx,
  3171. TILEGX_ELF_DTPMOD_RELOC (htab));
  3172. TILEGX_ELF_PUT_WORD (htab, output_bfd, 0,
  3173. htab->elf.sgot->contents + off);
  3174. tilegx_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
  3175. if (indx == 0)
  3176. {
  3177. BFD_ASSERT (! unresolved_reloc);
  3178. TILEGX_ELF_PUT_WORD (htab, output_bfd,
  3179. relocation - dtpoff_base (info),
  3180. (htab->elf.sgot->contents + off +
  3181. TILEGX_ELF_WORD_BYTES (htab)));
  3182. }
  3183. else
  3184. {
  3185. TILEGX_ELF_PUT_WORD (htab, output_bfd, 0,
  3186. (htab->elf.sgot->contents + off +
  3187. TILEGX_ELF_WORD_BYTES (htab)));
  3188. outrel.r_info = TILEGX_ELF_R_INFO (htab, NULL, indx,
  3189. TILEGX_ELF_DTPOFF_RELOC (htab));
  3190. outrel.r_offset += TILEGX_ELF_WORD_BYTES (htab);
  3191. tilegx_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
  3192. }
  3193. }
  3194. else {
  3195. /* If we are not emitting relocations for a
  3196. general dynamic reference, then we must be in a
  3197. static link or an executable link with the
  3198. symbol binding locally. Mark it as belonging
  3199. to module 1, the executable. */
  3200. TILEGX_ELF_PUT_WORD (htab, output_bfd, 1,
  3201. htab->elf.sgot->contents + off );
  3202. TILEGX_ELF_PUT_WORD (htab, output_bfd,
  3203. relocation - dtpoff_base (info),
  3204. htab->elf.sgot->contents + off +
  3205. TILEGX_ELF_WORD_BYTES (htab));
  3206. }
  3207. break;
  3208. }
  3209. }
  3210. if (off >= (bfd_vma) -2)
  3211. abort ();
  3212. relocation = off - got_base;
  3213. unresolved_reloc = false;
  3214. howto = tilegx_elf_howto_table + r_type;
  3215. break;
  3216. default:
  3217. break;
  3218. }
  3219. /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
  3220. because such sections are not SEC_ALLOC and thus ld.so will
  3221. not process them. */
  3222. if (unresolved_reloc
  3223. && !((input_section->flags & SEC_DEBUGGING) != 0
  3224. && h->def_dynamic)
  3225. && _bfd_elf_section_offset (output_bfd, info, input_section,
  3226. rel->r_offset) != (bfd_vma) -1)
  3227. _bfd_error_handler
  3228. /* xgettext:c-format */
  3229. (_("%pB(%pA+%#" PRIx64 "): "
  3230. "unresolvable %s relocation against symbol `%s'"),
  3231. input_bfd,
  3232. input_section,
  3233. (uint64_t) rel->r_offset,
  3234. howto->name,
  3235. h->root.root.string);
  3236. r = bfd_reloc_continue;
  3237. /* Get the operand creation function, if any. */
  3238. create_func = reloc_to_create_func[r_type];
  3239. if (create_func == NULL)
  3240. {
  3241. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  3242. contents, rel->r_offset,
  3243. relocation, rel->r_addend);
  3244. }
  3245. else
  3246. {
  3247. if (howto->pc_relative)
  3248. {
  3249. relocation -=
  3250. input_section->output_section->vma + input_section->output_offset;
  3251. if (howto->pcrel_offset)
  3252. relocation -= rel->r_offset;
  3253. }
  3254. bfd_byte *data;
  3255. /* Add the relocation addend if any to the final target value */
  3256. relocation += rel->r_addend;
  3257. /* Do basic range checking */
  3258. r = bfd_check_overflow (howto->complain_on_overflow,
  3259. howto->bitsize,
  3260. howto->rightshift,
  3261. TILEGX_ELF_WORD_BYTES (htab) * 8,
  3262. relocation);
  3263. /*
  3264. * Write the relocated value out into the raw section data.
  3265. * Don't put a relocation out in the .rela section.
  3266. */
  3267. tilegx_bundle_bits mask = create_func(-1);
  3268. tilegx_bundle_bits value = create_func(relocation >> howto->rightshift);
  3269. /* Only touch bytes while the mask is not 0, so we
  3270. don't write to out of bounds memory if this is actually
  3271. a 16-bit switch instruction. */
  3272. for (data = contents + rel->r_offset; mask != 0; data++)
  3273. {
  3274. bfd_byte byte_mask = (bfd_byte)mask;
  3275. *data = (*data & ~byte_mask) | ((bfd_byte)value & byte_mask);
  3276. mask >>= 8;
  3277. value >>= 8;
  3278. }
  3279. }
  3280. if (r != bfd_reloc_ok)
  3281. {
  3282. const char *msg = NULL;
  3283. switch (r)
  3284. {
  3285. case bfd_reloc_overflow:
  3286. (*info->callbacks->reloc_overflow)
  3287. (info, (h ? &h->root : NULL), name, howto->name,
  3288. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  3289. break;
  3290. case bfd_reloc_undefined:
  3291. (*info->callbacks->undefined_symbol)
  3292. (info, name, input_bfd, input_section, rel->r_offset, true);
  3293. break;
  3294. case bfd_reloc_outofrange:
  3295. msg = _("internal error: out of range error");
  3296. break;
  3297. case bfd_reloc_notsupported:
  3298. msg = _("internal error: unsupported relocation error");
  3299. break;
  3300. case bfd_reloc_dangerous:
  3301. msg = _("internal error: dangerous relocation");
  3302. break;
  3303. default:
  3304. msg = _("internal error: unknown error");
  3305. break;
  3306. }
  3307. if (msg)
  3308. (*info->callbacks->warning) (info, msg, name, input_bfd,
  3309. input_section, rel->r_offset);
  3310. }
  3311. }
  3312. return true;
  3313. }
  3314. /* Finish up dynamic symbol handling. We set the contents of various
  3315. dynamic sections here. */
  3316. bool
  3317. tilegx_elf_finish_dynamic_symbol (bfd *output_bfd,
  3318. struct bfd_link_info *info,
  3319. struct elf_link_hash_entry *h,
  3320. Elf_Internal_Sym *sym)
  3321. {
  3322. struct tilegx_elf_link_hash_table *htab;
  3323. htab = tilegx_elf_hash_table (info);
  3324. BFD_ASSERT (htab != NULL);
  3325. if (h->plt.offset != (bfd_vma) -1)
  3326. {
  3327. asection *splt;
  3328. asection *srela;
  3329. asection *sgotplt;
  3330. Elf_Internal_Rela rela;
  3331. bfd_byte *loc;
  3332. bfd_vma r_offset;
  3333. const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
  3334. int rela_index;
  3335. /* This symbol has an entry in the PLT. Set it up. */
  3336. BFD_ASSERT (h->dynindx != -1);
  3337. splt = htab->elf.splt;
  3338. srela = htab->elf.srelplt;
  3339. sgotplt = htab->elf.sgotplt;
  3340. if (splt == NULL || srela == NULL)
  3341. abort ();
  3342. /* Fill in the entry in the procedure linkage table. */
  3343. rela_index = tilegx_plt_entry_build (output_bfd, htab, splt, sgotplt,
  3344. h->plt.offset, &r_offset);
  3345. /* Fill in the entry in the global offset table, which initially points
  3346. to the beginning of the plt. */
  3347. TILEGX_ELF_PUT_WORD (htab, output_bfd,
  3348. splt->output_section->vma + splt->output_offset,
  3349. sgotplt->contents + r_offset);
  3350. /* Fill in the entry in the .rela.plt section. */
  3351. rela.r_offset = (sgotplt->output_section->vma
  3352. + sgotplt->output_offset
  3353. + r_offset);
  3354. rela.r_addend = 0;
  3355. rela.r_info = TILEGX_ELF_R_INFO (htab, NULL, h->dynindx, R_TILEGX_JMP_SLOT);
  3356. loc = srela->contents + rela_index * TILEGX_ELF_RELA_BYTES (htab);
  3357. bed->s->swap_reloca_out (output_bfd, &rela, loc);
  3358. if (!h->def_regular)
  3359. {
  3360. /* Mark the symbol as undefined, rather than as defined in
  3361. the .plt section. Leave the value alone. */
  3362. sym->st_shndx = SHN_UNDEF;
  3363. /* If the symbol is weak, we do need to clear the value.
  3364. Otherwise, the PLT entry would provide a definition for
  3365. the symbol even if the symbol wasn't defined anywhere,
  3366. and so the symbol would never be NULL. */
  3367. if (!h->ref_regular_nonweak)
  3368. sym->st_value = 0;
  3369. }
  3370. }
  3371. if (h->got.offset != (bfd_vma) -1
  3372. && tilegx_elf_hash_entry(h)->tls_type != GOT_TLS_GD
  3373. && tilegx_elf_hash_entry(h)->tls_type != GOT_TLS_IE)
  3374. {
  3375. asection *sgot;
  3376. asection *srela;
  3377. Elf_Internal_Rela rela;
  3378. /* This symbol has an entry in the GOT. Set it up. */
  3379. sgot = htab->elf.sgot;
  3380. srela = htab->elf.srelgot;
  3381. BFD_ASSERT (sgot != NULL && srela != NULL);
  3382. rela.r_offset = (sgot->output_section->vma
  3383. + sgot->output_offset
  3384. + (h->got.offset &~ (bfd_vma) 1));
  3385. /* If this is a -Bsymbolic link, and the symbol is defined
  3386. locally, we just want to emit a RELATIVE reloc. Likewise if
  3387. the symbol was forced to be local because of a version file.
  3388. The entry in the global offset table will already have been
  3389. initialized in the relocate_section function. */
  3390. if (bfd_link_pic (info)
  3391. && (info->symbolic || h->dynindx == -1)
  3392. && h->def_regular)
  3393. {
  3394. asection *sec = h->root.u.def.section;
  3395. rela.r_info = TILEGX_ELF_R_INFO (htab, NULL, 0, R_TILEGX_RELATIVE);
  3396. rela.r_addend = (h->root.u.def.value
  3397. + sec->output_section->vma
  3398. + sec->output_offset);
  3399. }
  3400. else
  3401. {
  3402. rela.r_info = TILEGX_ELF_R_INFO (htab, NULL, h->dynindx, R_TILEGX_GLOB_DAT);
  3403. rela.r_addend = 0;
  3404. }
  3405. TILEGX_ELF_PUT_WORD (htab, output_bfd, 0,
  3406. sgot->contents + (h->got.offset & ~(bfd_vma) 1));
  3407. tilegx_elf_append_rela (output_bfd, srela, &rela);
  3408. }
  3409. if (h->needs_copy)
  3410. {
  3411. asection *s;
  3412. Elf_Internal_Rela rela;
  3413. /* This symbols needs a copy reloc. Set it up. */
  3414. BFD_ASSERT (h->dynindx != -1);
  3415. if (h->root.u.def.section == htab->elf.sdynrelro)
  3416. s = htab->elf.sreldynrelro;
  3417. else
  3418. s = htab->elf.srelbss;
  3419. BFD_ASSERT (s != NULL);
  3420. rela.r_offset = (h->root.u.def.value
  3421. + h->root.u.def.section->output_section->vma
  3422. + h->root.u.def.section->output_offset);
  3423. rela.r_info = TILEGX_ELF_R_INFO (htab, NULL, h->dynindx, R_TILEGX_COPY);
  3424. rela.r_addend = 0;
  3425. tilegx_elf_append_rela (output_bfd, s, &rela);
  3426. }
  3427. /* Mark some specially defined symbols as absolute. */
  3428. if (h == htab->elf.hdynamic
  3429. || (h == htab->elf.hgot || h == htab->elf.hplt))
  3430. sym->st_shndx = SHN_ABS;
  3431. return true;
  3432. }
  3433. /* Finish up the dynamic sections. */
  3434. static bool
  3435. tilegx_finish_dyn (bfd *output_bfd, struct bfd_link_info *info,
  3436. bfd *dynobj, asection *sdyn,
  3437. asection *splt ATTRIBUTE_UNUSED)
  3438. {
  3439. struct tilegx_elf_link_hash_table *htab;
  3440. const struct elf_backend_data *bed;
  3441. bfd_byte *dyncon, *dynconend;
  3442. size_t dynsize;
  3443. htab = tilegx_elf_hash_table (info);
  3444. BFD_ASSERT (htab != NULL);
  3445. bed = get_elf_backend_data (output_bfd);
  3446. dynsize = bed->s->sizeof_dyn;
  3447. dynconend = sdyn->contents + sdyn->size;
  3448. for (dyncon = sdyn->contents; dyncon < dynconend; dyncon += dynsize)
  3449. {
  3450. Elf_Internal_Dyn dyn;
  3451. asection *s;
  3452. bed->s->swap_dyn_in (dynobj, dyncon, &dyn);
  3453. switch (dyn.d_tag)
  3454. {
  3455. case DT_PLTGOT:
  3456. s = htab->elf.sgotplt;
  3457. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  3458. break;
  3459. case DT_JMPREL:
  3460. s = htab->elf.srelplt;
  3461. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  3462. break;
  3463. case DT_PLTRELSZ:
  3464. s = htab->elf.srelplt;
  3465. dyn.d_un.d_val = s->size;
  3466. break;
  3467. default:
  3468. continue;
  3469. }
  3470. bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
  3471. }
  3472. return true;
  3473. }
  3474. bool
  3475. tilegx_elf_finish_dynamic_sections (bfd *output_bfd,
  3476. struct bfd_link_info *info)
  3477. {
  3478. bfd *dynobj;
  3479. asection *sdyn;
  3480. struct tilegx_elf_link_hash_table *htab;
  3481. size_t pad_size;
  3482. htab = tilegx_elf_hash_table (info);
  3483. BFD_ASSERT (htab != NULL);
  3484. dynobj = htab->elf.dynobj;
  3485. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  3486. if (elf_hash_table (info)->dynamic_sections_created)
  3487. {
  3488. asection *splt;
  3489. bool ret;
  3490. splt = htab->elf.splt;
  3491. BFD_ASSERT (splt != NULL && sdyn != NULL);
  3492. ret = tilegx_finish_dyn (output_bfd, info, dynobj, sdyn, splt);
  3493. if (!ret)
  3494. return ret;
  3495. /* Fill in the head and tail entries in the procedure linkage table. */
  3496. if (splt->size > 0)
  3497. {
  3498. memcpy (splt->contents,
  3499. ABI_64_P (output_bfd) ?
  3500. tilegx64_plt0_entry : tilegx32_plt0_entry,
  3501. PLT_HEADER_SIZE);
  3502. memcpy (splt->contents + splt->size
  3503. - PLT_ENTRY_SIZE + PLT_HEADER_SIZE,
  3504. ABI_64_P (output_bfd) ?
  3505. tilegx64_plt_tail_entry : tilegx32_plt_tail_entry,
  3506. PLT_TAIL_SIZE);
  3507. /* Add padding so that the plt section is a multiple of its
  3508. entry size. */
  3509. pad_size = PLT_ENTRY_SIZE - PLT_HEADER_SIZE - PLT_TAIL_SIZE;
  3510. memset (splt->contents + splt->size - pad_size, 0, pad_size);
  3511. elf_section_data (splt->output_section)->this_hdr.sh_entsize
  3512. = PLT_ENTRY_SIZE;
  3513. }
  3514. }
  3515. if (htab->elf.sgotplt)
  3516. {
  3517. if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
  3518. {
  3519. _bfd_error_handler
  3520. (_("discarded output section: `%pA'"), htab->elf.sgotplt);
  3521. return false;
  3522. }
  3523. if (htab->elf.sgotplt->size > 0)
  3524. {
  3525. /* Write the first two entries in .got.plt, needed for the dynamic
  3526. linker. */
  3527. TILEGX_ELF_PUT_WORD (htab, output_bfd, (bfd_vma) -1,
  3528. htab->elf.sgotplt->contents);
  3529. TILEGX_ELF_PUT_WORD (htab, output_bfd, (bfd_vma) 0,
  3530. htab->elf.sgotplt->contents
  3531. + GOT_ENTRY_SIZE (htab));
  3532. elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize =
  3533. GOT_ENTRY_SIZE (htab);
  3534. }
  3535. }
  3536. if (htab->elf.sgot)
  3537. {
  3538. if (htab->elf.sgot->size > 0)
  3539. {
  3540. /* Set the first entry in the global offset table to the address of
  3541. the dynamic section. */
  3542. bfd_vma val = (sdyn ?
  3543. sdyn->output_section->vma + sdyn->output_offset :
  3544. 0);
  3545. TILEGX_ELF_PUT_WORD (htab, output_bfd, val,
  3546. htab->elf.sgot->contents);
  3547. elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize =
  3548. GOT_ENTRY_SIZE (htab);
  3549. }
  3550. }
  3551. return true;
  3552. }
  3553. /* Return address for Ith PLT stub in section PLT, for relocation REL
  3554. or (bfd_vma) -1 if it should not be included. */
  3555. bfd_vma
  3556. tilegx_elf_plt_sym_val (bfd_vma i, const asection *plt,
  3557. const arelent *rel ATTRIBUTE_UNUSED)
  3558. {
  3559. return plt->vma + PLT_HEADER_SIZE + i * PLT_ENTRY_SIZE;
  3560. }
  3561. enum elf_reloc_type_class
  3562. tilegx_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
  3563. const asection *rel_sec ATTRIBUTE_UNUSED,
  3564. const Elf_Internal_Rela *rela)
  3565. {
  3566. switch ((int) TILEGX_ELF_R_TYPE (rela->r_info))
  3567. {
  3568. case R_TILEGX_RELATIVE:
  3569. return reloc_class_relative;
  3570. case R_TILEGX_JMP_SLOT:
  3571. return reloc_class_plt;
  3572. case R_TILEGX_COPY:
  3573. return reloc_class_copy;
  3574. default:
  3575. return reloc_class_normal;
  3576. }
  3577. }
  3578. int
  3579. tilegx_additional_program_headers (bfd *abfd,
  3580. struct bfd_link_info *info ATTRIBUTE_UNUSED)
  3581. {
  3582. /* Each .intrpt section specified by the user adds another PT_LOAD
  3583. header since the sections are discontiguous. */
  3584. static const char intrpt_sections[4][9] =
  3585. {
  3586. ".intrpt0", ".intrpt1", ".intrpt2", ".intrpt3"
  3587. };
  3588. int count = 0;
  3589. int i;
  3590. for (i = 0; i < 4; i++)
  3591. {
  3592. asection *sec = bfd_get_section_by_name (abfd, intrpt_sections[i]);
  3593. if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
  3594. ++count;
  3595. }
  3596. /* Add four "padding" headers in to leave room in case a custom linker
  3597. script does something fancy. Otherwise ld complains that it ran
  3598. out of program headers and refuses to link. */
  3599. count += 4;
  3600. return count;
  3601. }
  3602. bool
  3603. _bfd_tilegx_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
  3604. {
  3605. bfd *obfd = info->output_bfd;
  3606. const char *targ1 = bfd_get_target (ibfd);
  3607. const char *targ2 = bfd_get_target (obfd);
  3608. if (strcmp (targ1, targ2) != 0)
  3609. {
  3610. _bfd_error_handler
  3611. /* xgettext:c-format */
  3612. (_("%pB: cannot link together %s and %s objects"),
  3613. ibfd, targ1, targ2);
  3614. bfd_set_error (bfd_error_bad_value);
  3615. return false;
  3616. }
  3617. return true;
  3618. }