elf32-microblaze.c 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483
  1. /* Xilinx MicroBlaze-specific support for 32-bit ELF
  2. Copyright (C) 2009-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
  14. Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include "bfd.h"
  18. #include "bfdlink.h"
  19. #include "libbfd.h"
  20. #include "elf-bfd.h"
  21. #include "elf/microblaze.h"
  22. #include <assert.h>
  23. #define USE_RELA /* Only USE_REL is actually significant, but this is
  24. here are a reminder... */
  25. #define INST_WORD_SIZE 4
  26. static int ro_small_data_pointer = 0;
  27. static int rw_small_data_pointer = 0;
  28. static reloc_howto_type * microblaze_elf_howto_table [(int) R_MICROBLAZE_max];
  29. static reloc_howto_type microblaze_elf_howto_raw[] =
  30. {
  31. /* This reloc does nothing. */
  32. HOWTO (R_MICROBLAZE_NONE, /* Type. */
  33. 0, /* Rightshift. */
  34. 3, /* Size (0 = byte, 1 = short, 2 = long). */
  35. 0, /* Bitsize. */
  36. false, /* PC_relative. */
  37. 0, /* Bitpos. */
  38. complain_overflow_dont, /* Complain on overflow. */
  39. NULL, /* Special Function. */
  40. "R_MICROBLAZE_NONE", /* Name. */
  41. false, /* Partial Inplace. */
  42. 0, /* Source Mask. */
  43. 0, /* Dest Mask. */
  44. false), /* PC relative offset? */
  45. /* A standard 32 bit relocation. */
  46. HOWTO (R_MICROBLAZE_32, /* Type. */
  47. 0, /* Rightshift. */
  48. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  49. 32, /* Bitsize. */
  50. false, /* PC_relative. */
  51. 0, /* Bitpos. */
  52. complain_overflow_bitfield, /* Complain on overflow. */
  53. bfd_elf_generic_reloc,/* Special Function. */
  54. "R_MICROBLAZE_32", /* Name. */
  55. false, /* Partial Inplace. */
  56. 0, /* Source Mask. */
  57. 0xffffffff, /* Dest Mask. */
  58. false), /* PC relative offset? */
  59. /* A standard PCREL 32 bit relocation. */
  60. HOWTO (R_MICROBLAZE_32_PCREL,/* Type. */
  61. 0, /* Rightshift. */
  62. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  63. 32, /* Bitsize. */
  64. true, /* PC_relative. */
  65. 0, /* Bitpos. */
  66. complain_overflow_bitfield, /* Complain on overflow. */
  67. bfd_elf_generic_reloc,/* Special Function. */
  68. "R_MICROBLAZE_32_PCREL", /* Name. */
  69. true, /* Partial Inplace. */
  70. 0, /* Source Mask. */
  71. 0xffffffff, /* Dest Mask. */
  72. true), /* PC relative offset? */
  73. /* A 64 bit PCREL relocation. Table-entry not really used. */
  74. HOWTO (R_MICROBLAZE_64_PCREL,/* Type. */
  75. 0, /* Rightshift. */
  76. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  77. 16, /* Bitsize. */
  78. true, /* PC_relative. */
  79. 0, /* Bitpos. */
  80. complain_overflow_dont, /* Complain on overflow. */
  81. bfd_elf_generic_reloc,/* Special Function. */
  82. "R_MICROBLAZE_64_PCREL", /* Name. */
  83. false, /* Partial Inplace. */
  84. 0, /* Source Mask. */
  85. 0x0000ffff, /* Dest Mask. */
  86. true), /* PC relative offset? */
  87. /* The low half of a PCREL 32 bit relocation. */
  88. HOWTO (R_MICROBLAZE_32_PCREL_LO, /* Type. */
  89. 0, /* Rightshift. */
  90. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  91. 16, /* Bitsize. */
  92. true, /* PC_relative. */
  93. 0, /* Bitpos. */
  94. complain_overflow_signed, /* Complain on overflow. */
  95. bfd_elf_generic_reloc, /* Special Function. */
  96. "R_MICROBLAZE_32_PCREL_LO", /* Name. */
  97. false, /* Partial Inplace. */
  98. 0, /* Source Mask. */
  99. 0x0000ffff, /* Dest Mask. */
  100. true), /* PC relative offset? */
  101. /* A 64 bit relocation. Table entry not really used. */
  102. HOWTO (R_MICROBLAZE_64, /* Type. */
  103. 0, /* Rightshift. */
  104. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  105. 16, /* Bitsize. */
  106. false, /* PC_relative. */
  107. 0, /* Bitpos. */
  108. complain_overflow_dont, /* Complain on overflow. */
  109. bfd_elf_generic_reloc,/* Special Function. */
  110. "R_MICROBLAZE_64", /* Name. */
  111. false, /* Partial Inplace. */
  112. 0, /* Source Mask. */
  113. 0x0000ffff, /* Dest Mask. */
  114. false), /* PC relative offset? */
  115. /* The low half of a 32 bit relocation. */
  116. HOWTO (R_MICROBLAZE_32_LO, /* Type. */
  117. 0, /* Rightshift. */
  118. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  119. 16, /* Bitsize. */
  120. false, /* PC_relative. */
  121. 0, /* Bitpos. */
  122. complain_overflow_signed, /* Complain on overflow. */
  123. bfd_elf_generic_reloc,/* Special Function. */
  124. "R_MICROBLAZE_32_LO", /* Name. */
  125. false, /* Partial Inplace. */
  126. 0, /* Source Mask. */
  127. 0x0000ffff, /* Dest Mask. */
  128. false), /* PC relative offset? */
  129. /* Read-only small data section relocation. */
  130. HOWTO (R_MICROBLAZE_SRO32, /* Type. */
  131. 0, /* Rightshift. */
  132. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  133. 16, /* Bitsize. */
  134. false, /* PC_relative. */
  135. 0, /* Bitpos. */
  136. complain_overflow_bitfield, /* Complain on overflow. */
  137. bfd_elf_generic_reloc,/* Special Function. */
  138. "R_MICROBLAZE_SRO32", /* Name. */
  139. false, /* Partial Inplace. */
  140. 0, /* Source Mask. */
  141. 0x0000ffff, /* Dest Mask. */
  142. false), /* PC relative offset? */
  143. /* Read-write small data area relocation. */
  144. HOWTO (R_MICROBLAZE_SRW32, /* Type. */
  145. 0, /* Rightshift. */
  146. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  147. 16, /* Bitsize. */
  148. false, /* PC_relative. */
  149. 0, /* Bitpos. */
  150. complain_overflow_bitfield, /* Complain on overflow. */
  151. bfd_elf_generic_reloc,/* Special Function. */
  152. "R_MICROBLAZE_SRW32", /* Name. */
  153. false, /* Partial Inplace. */
  154. 0, /* Source Mask. */
  155. 0x0000ffff, /* Dest Mask. */
  156. false), /* PC relative offset? */
  157. /* This reloc does nothing. Used for relaxation. */
  158. HOWTO (R_MICROBLAZE_64_NONE, /* Type. */
  159. 0, /* Rightshift. */
  160. 3, /* Size (0 = byte, 1 = short, 2 = long). */
  161. 0, /* Bitsize. */
  162. true, /* PC_relative. */
  163. 0, /* Bitpos. */
  164. complain_overflow_dont, /* Complain on overflow. */
  165. NULL, /* Special Function. */
  166. "R_MICROBLAZE_64_NONE",/* Name. */
  167. false, /* Partial Inplace. */
  168. 0, /* Source Mask. */
  169. 0, /* Dest Mask. */
  170. false), /* PC relative offset? */
  171. /* Symbol Op Symbol relocation. */
  172. HOWTO (R_MICROBLAZE_32_SYM_OP_SYM, /* Type. */
  173. 0, /* Rightshift. */
  174. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  175. 32, /* Bitsize. */
  176. false, /* PC_relative. */
  177. 0, /* Bitpos. */
  178. complain_overflow_bitfield, /* Complain on overflow. */
  179. bfd_elf_generic_reloc,/* Special Function. */
  180. "R_MICROBLAZE_32_SYM_OP_SYM", /* Name. */
  181. false, /* Partial Inplace. */
  182. 0, /* Source Mask. */
  183. 0xffffffff, /* Dest Mask. */
  184. false), /* PC relative offset? */
  185. /* GNU extension to record C++ vtable hierarchy. */
  186. HOWTO (R_MICROBLAZE_GNU_VTINHERIT, /* Type. */
  187. 0, /* Rightshift. */
  188. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  189. 0, /* Bitsize. */
  190. false, /* PC_relative. */
  191. 0, /* Bitpos. */
  192. complain_overflow_dont,/* Complain on overflow. */
  193. NULL, /* Special Function. */
  194. "R_MICROBLAZE_GNU_VTINHERIT", /* Name. */
  195. false, /* Partial Inplace. */
  196. 0, /* Source Mask. */
  197. 0, /* Dest Mask. */
  198. false), /* PC relative offset? */
  199. /* GNU extension to record C++ vtable member usage. */
  200. HOWTO (R_MICROBLAZE_GNU_VTENTRY, /* Type. */
  201. 0, /* Rightshift. */
  202. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  203. 0, /* Bitsize. */
  204. false, /* PC_relative. */
  205. 0, /* Bitpos. */
  206. complain_overflow_dont,/* Complain on overflow. */
  207. _bfd_elf_rel_vtable_reloc_fn, /* Special Function. */
  208. "R_MICROBLAZE_GNU_VTENTRY", /* Name. */
  209. false, /* Partial Inplace. */
  210. 0, /* Source Mask. */
  211. 0, /* Dest Mask. */
  212. false), /* PC relative offset? */
  213. /* A 64 bit GOTPC relocation. Table-entry not really used. */
  214. HOWTO (R_MICROBLAZE_GOTPC_64, /* Type. */
  215. 0, /* Rightshift. */
  216. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  217. 16, /* Bitsize. */
  218. true, /* PC_relative. */
  219. 0, /* Bitpos. */
  220. complain_overflow_dont, /* Complain on overflow. */
  221. bfd_elf_generic_reloc, /* Special Function. */
  222. "R_MICROBLAZE_GOTPC_64", /* Name. */
  223. false, /* Partial Inplace. */
  224. 0, /* Source Mask. */
  225. 0x0000ffff, /* Dest Mask. */
  226. true), /* PC relative offset? */
  227. /* A 64 bit TEXTPCREL relocation. Table-entry not really used. */
  228. HOWTO (R_MICROBLAZE_TEXTPCREL_64, /* Type. */
  229. 0, /* Rightshift. */
  230. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  231. 16, /* Bitsize. */
  232. true, /* PC_relative. */
  233. 0, /* Bitpos. */
  234. complain_overflow_dont, /* Complain on overflow. */
  235. bfd_elf_generic_reloc, /* Special Function. */
  236. "R_MICROBLAZE_TEXTPCREL_64", /* Name. */
  237. false, /* Partial Inplace. */
  238. 0, /* Source Mask. */
  239. 0x0000ffff, /* Dest Mask. */
  240. true), /* PC relative offset? */
  241. /* A 64 bit GOT relocation. Table-entry not really used. */
  242. HOWTO (R_MICROBLAZE_GOT_64, /* Type. */
  243. 0, /* Rightshift. */
  244. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  245. 16, /* Bitsize. */
  246. false, /* PC_relative. */
  247. 0, /* Bitpos. */
  248. complain_overflow_dont, /* Complain on overflow. */
  249. bfd_elf_generic_reloc,/* Special Function. */
  250. "R_MICROBLAZE_GOT_64",/* Name. */
  251. false, /* Partial Inplace. */
  252. 0, /* Source Mask. */
  253. 0x0000ffff, /* Dest Mask. */
  254. false), /* PC relative offset? */
  255. /* A 64 bit TEXTREL relocation. Table-entry not really used. */
  256. HOWTO (R_MICROBLAZE_TEXTREL_64, /* Type. */
  257. 0, /* Rightshift. */
  258. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  259. 16, /* Bitsize. */
  260. false, /* PC_relative. */
  261. 0, /* Bitpos. */
  262. complain_overflow_dont, /* Complain on overflow. */
  263. bfd_elf_generic_reloc,/* Special Function. */
  264. "R_MICROBLAZE_TEXTREL_64",/* Name. */
  265. false, /* Partial Inplace. */
  266. 0, /* Source Mask. */
  267. 0x0000ffff, /* Dest Mask. */
  268. false), /* PC relative offset? */
  269. /* A 64 bit PLT relocation. Table-entry not really used. */
  270. HOWTO (R_MICROBLAZE_PLT_64, /* Type. */
  271. 0, /* Rightshift. */
  272. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  273. 16, /* Bitsize. */
  274. true, /* PC_relative. */
  275. 0, /* Bitpos. */
  276. complain_overflow_dont, /* Complain on overflow. */
  277. bfd_elf_generic_reloc,/* Special Function. */
  278. "R_MICROBLAZE_PLT_64",/* Name. */
  279. false, /* Partial Inplace. */
  280. 0, /* Source Mask. */
  281. 0x0000ffff, /* Dest Mask. */
  282. true), /* PC relative offset? */
  283. /* Table-entry not really used. */
  284. HOWTO (R_MICROBLAZE_REL, /* Type. */
  285. 0, /* Rightshift. */
  286. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  287. 16, /* Bitsize. */
  288. true, /* PC_relative. */
  289. 0, /* Bitpos. */
  290. complain_overflow_dont, /* Complain on overflow. */
  291. bfd_elf_generic_reloc,/* Special Function. */
  292. "R_MICROBLAZE_REL", /* Name. */
  293. false, /* Partial Inplace. */
  294. 0, /* Source Mask. */
  295. 0x0000ffff, /* Dest Mask. */
  296. true), /* PC relative offset? */
  297. /* Table-entry not really used. */
  298. HOWTO (R_MICROBLAZE_JUMP_SLOT,/* Type. */
  299. 0, /* Rightshift. */
  300. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  301. 16, /* Bitsize. */
  302. true, /* PC_relative. */
  303. 0, /* Bitpos. */
  304. complain_overflow_dont, /* Complain on overflow. */
  305. bfd_elf_generic_reloc,/* Special Function. */
  306. "R_MICROBLAZE_JUMP_SLOT", /* Name. */
  307. false, /* Partial Inplace. */
  308. 0, /* Source Mask. */
  309. 0x0000ffff, /* Dest Mask. */
  310. true), /* PC relative offset? */
  311. /* Table-entry not really used. */
  312. HOWTO (R_MICROBLAZE_GLOB_DAT,/* Type. */
  313. 0, /* Rightshift. */
  314. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  315. 16, /* Bitsize. */
  316. true, /* PC_relative. */
  317. 0, /* Bitpos. */
  318. complain_overflow_dont, /* Complain on overflow. */
  319. bfd_elf_generic_reloc,/* Special Function. */
  320. "R_MICROBLAZE_GLOB_DAT", /* Name. */
  321. false, /* Partial Inplace. */
  322. 0, /* Source Mask. */
  323. 0x0000ffff, /* Dest Mask. */
  324. true), /* PC relative offset? */
  325. /* A 64 bit GOT relative relocation. Table-entry not really used. */
  326. HOWTO (R_MICROBLAZE_GOTOFF_64, /* Type. */
  327. 0, /* Rightshift. */
  328. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  329. 16, /* Bitsize. */
  330. false, /* PC_relative. */
  331. 0, /* Bitpos. */
  332. complain_overflow_dont, /* Complain on overflow. */
  333. bfd_elf_generic_reloc,/* Special Function. */
  334. "R_MICROBLAZE_GOTOFF_64", /* Name. */
  335. false, /* Partial Inplace. */
  336. 0, /* Source Mask. */
  337. 0x0000ffff, /* Dest Mask. */
  338. false), /* PC relative offset? */
  339. /* A 32 bit GOT relative relocation. Table-entry not really used. */
  340. HOWTO (R_MICROBLAZE_GOTOFF_32, /* Type. */
  341. 0, /* Rightshift. */
  342. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  343. 16, /* Bitsize. */
  344. false, /* PC_relative. */
  345. 0, /* Bitpos. */
  346. complain_overflow_dont, /* Complain on overflow. */
  347. bfd_elf_generic_reloc, /* Special Function. */
  348. "R_MICROBLAZE_GOTOFF_32", /* Name. */
  349. false, /* Partial Inplace. */
  350. 0, /* Source Mask. */
  351. 0x0000ffff, /* Dest Mask. */
  352. false), /* PC relative offset? */
  353. /* COPY relocation. Table-entry not really used. */
  354. HOWTO (R_MICROBLAZE_COPY, /* Type. */
  355. 0, /* Rightshift. */
  356. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  357. 16, /* Bitsize. */
  358. false, /* PC_relative. */
  359. 0, /* Bitpos. */
  360. complain_overflow_dont, /* Complain on overflow. */
  361. bfd_elf_generic_reloc,/* Special Function. */
  362. "R_MICROBLAZE_COPY", /* Name. */
  363. false, /* Partial Inplace. */
  364. 0, /* Source Mask. */
  365. 0x0000ffff, /* Dest Mask. */
  366. false), /* PC relative offset? */
  367. /* Marker relocs for TLS. */
  368. HOWTO (R_MICROBLAZE_TLS,
  369. 0, /* rightshift */
  370. 2, /* size (0 = byte, 1 = short, 2 = long) */
  371. 32, /* bitsize */
  372. false, /* pc_relative */
  373. 0, /* bitpos */
  374. complain_overflow_dont, /* complain_on_overflow */
  375. bfd_elf_generic_reloc, /* special_function */
  376. "R_MICROBLAZE_TLS", /* name */
  377. false, /* partial_inplace */
  378. 0, /* src_mask */
  379. 0x0000ffff, /* dst_mask */
  380. false), /* pcrel_offset */
  381. HOWTO (R_MICROBLAZE_TLSGD,
  382. 0, /* rightshift */
  383. 2, /* size (0 = byte, 1 = short, 2 = long) */
  384. 32, /* bitsize */
  385. false, /* pc_relative */
  386. 0, /* bitpos */
  387. complain_overflow_dont, /* complain_on_overflow */
  388. bfd_elf_generic_reloc, /* special_function */
  389. "R_MICROBLAZE_TLSGD", /* name */
  390. false, /* partial_inplace */
  391. 0, /* src_mask */
  392. 0x0000ffff, /* dst_mask */
  393. false), /* pcrel_offset */
  394. HOWTO (R_MICROBLAZE_TLSLD,
  395. 0, /* rightshift */
  396. 2, /* size (0 = byte, 1 = short, 2 = long) */
  397. 32, /* bitsize */
  398. false, /* pc_relative */
  399. 0, /* bitpos */
  400. complain_overflow_dont, /* complain_on_overflow */
  401. bfd_elf_generic_reloc, /* special_function */
  402. "R_MICROBLAZE_TLSLD", /* name */
  403. false, /* partial_inplace */
  404. 0, /* src_mask */
  405. 0x0000ffff, /* dst_mask */
  406. false), /* pcrel_offset */
  407. /* Computes the load module index of the load module that contains the
  408. definition of its TLS sym. */
  409. HOWTO (R_MICROBLAZE_TLSDTPMOD32,
  410. 0, /* rightshift */
  411. 2, /* size (0 = byte, 1 = short, 2 = long) */
  412. 32, /* bitsize */
  413. false, /* pc_relative */
  414. 0, /* bitpos */
  415. complain_overflow_dont, /* complain_on_overflow */
  416. bfd_elf_generic_reloc, /* special_function */
  417. "R_MICROBLAZE_TLSDTPMOD32", /* name */
  418. false, /* partial_inplace */
  419. 0, /* src_mask */
  420. 0x0000ffff, /* dst_mask */
  421. false), /* pcrel_offset */
  422. /* Computes a dtv-relative displacement, the difference between the value
  423. of sym+add and the base address of the thread-local storage block that
  424. contains the definition of sym, minus 0x8000. Used for initializing GOT */
  425. HOWTO (R_MICROBLAZE_TLSDTPREL32,
  426. 0, /* rightshift */
  427. 2, /* size (0 = byte, 1 = short, 2 = long) */
  428. 32, /* bitsize */
  429. false, /* pc_relative */
  430. 0, /* bitpos */
  431. complain_overflow_dont, /* complain_on_overflow */
  432. bfd_elf_generic_reloc, /* special_function */
  433. "R_MICROBLAZE_TLSDTPREL32", /* name */
  434. false, /* partial_inplace */
  435. 0, /* src_mask */
  436. 0x0000ffff, /* dst_mask */
  437. false), /* pcrel_offset */
  438. /* Computes a dtv-relative displacement, the difference between the value
  439. of sym+add and the base address of the thread-local storage block that
  440. contains the definition of sym, minus 0x8000. */
  441. HOWTO (R_MICROBLAZE_TLSDTPREL64,
  442. 0, /* rightshift */
  443. 2, /* size (0 = byte, 1 = short, 2 = long) */
  444. 32, /* bitsize */
  445. false, /* pc_relative */
  446. 0, /* bitpos */
  447. complain_overflow_dont, /* complain_on_overflow */
  448. bfd_elf_generic_reloc, /* special_function */
  449. "R_MICROBLAZE_TLSDTPREL64", /* name */
  450. false, /* partial_inplace */
  451. 0, /* src_mask */
  452. 0x0000ffff, /* dst_mask */
  453. false), /* pcrel_offset */
  454. /* Computes a tp-relative displacement, the difference between the value of
  455. sym+add and the value of the thread pointer (r13). */
  456. HOWTO (R_MICROBLAZE_TLSGOTTPREL32,
  457. 0, /* rightshift */
  458. 2, /* size (0 = byte, 1 = short, 2 = long) */
  459. 32, /* bitsize */
  460. false, /* pc_relative */
  461. 0, /* bitpos */
  462. complain_overflow_dont, /* complain_on_overflow */
  463. bfd_elf_generic_reloc, /* special_function */
  464. "R_MICROBLAZE_TLSGOTTPREL32", /* name */
  465. false, /* partial_inplace */
  466. 0, /* src_mask */
  467. 0x0000ffff, /* dst_mask */
  468. false), /* pcrel_offset */
  469. /* Computes a tp-relative displacement, the difference between the value of
  470. sym+add and the value of the thread pointer (r13). */
  471. HOWTO (R_MICROBLAZE_TLSTPREL32,
  472. 0, /* rightshift */
  473. 2, /* size (0 = byte, 1 = short, 2 = long) */
  474. 32, /* bitsize */
  475. false, /* pc_relative */
  476. 0, /* bitpos */
  477. complain_overflow_dont, /* complain_on_overflow */
  478. bfd_elf_generic_reloc, /* special_function */
  479. "R_MICROBLAZE_TLSTPREL32", /* name */
  480. false, /* partial_inplace */
  481. 0, /* src_mask */
  482. 0x0000ffff, /* dst_mask */
  483. false), /* pcrel_offset */
  484. };
  485. #ifndef NUM_ELEM
  486. #define NUM_ELEM(a) (sizeof (a) / sizeof (a)[0])
  487. #endif
  488. /* Initialize the microblaze_elf_howto_table, so that linear accesses can be done. */
  489. static void
  490. microblaze_elf_howto_init (void)
  491. {
  492. unsigned int i;
  493. for (i = NUM_ELEM (microblaze_elf_howto_raw); i--;)
  494. {
  495. unsigned int type;
  496. type = microblaze_elf_howto_raw[i].type;
  497. BFD_ASSERT (type < NUM_ELEM (microblaze_elf_howto_table));
  498. microblaze_elf_howto_table [type] = & microblaze_elf_howto_raw [i];
  499. }
  500. }
  501. static reloc_howto_type *
  502. microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
  503. bfd_reloc_code_real_type code)
  504. {
  505. enum elf_microblaze_reloc_type microblaze_reloc = R_MICROBLAZE_NONE;
  506. switch (code)
  507. {
  508. case BFD_RELOC_NONE:
  509. microblaze_reloc = R_MICROBLAZE_NONE;
  510. break;
  511. case BFD_RELOC_MICROBLAZE_64_NONE:
  512. microblaze_reloc = R_MICROBLAZE_64_NONE;
  513. break;
  514. case BFD_RELOC_32:
  515. microblaze_reloc = R_MICROBLAZE_32;
  516. break;
  517. /* RVA is treated the same as 32 */
  518. case BFD_RELOC_RVA:
  519. microblaze_reloc = R_MICROBLAZE_32;
  520. break;
  521. case BFD_RELOC_32_PCREL:
  522. microblaze_reloc = R_MICROBLAZE_32_PCREL;
  523. break;
  524. case BFD_RELOC_64_PCREL:
  525. microblaze_reloc = R_MICROBLAZE_64_PCREL;
  526. break;
  527. case BFD_RELOC_MICROBLAZE_32_LO_PCREL:
  528. microblaze_reloc = R_MICROBLAZE_32_PCREL_LO;
  529. break;
  530. case BFD_RELOC_64:
  531. microblaze_reloc = R_MICROBLAZE_64;
  532. break;
  533. case BFD_RELOC_MICROBLAZE_32_LO:
  534. microblaze_reloc = R_MICROBLAZE_32_LO;
  535. break;
  536. case BFD_RELOC_MICROBLAZE_32_ROSDA:
  537. microblaze_reloc = R_MICROBLAZE_SRO32;
  538. break;
  539. case BFD_RELOC_MICROBLAZE_32_RWSDA:
  540. microblaze_reloc = R_MICROBLAZE_SRW32;
  541. break;
  542. case BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM:
  543. microblaze_reloc = R_MICROBLAZE_32_SYM_OP_SYM;
  544. break;
  545. case BFD_RELOC_VTABLE_INHERIT:
  546. microblaze_reloc = R_MICROBLAZE_GNU_VTINHERIT;
  547. break;
  548. case BFD_RELOC_VTABLE_ENTRY:
  549. microblaze_reloc = R_MICROBLAZE_GNU_VTENTRY;
  550. break;
  551. case BFD_RELOC_MICROBLAZE_64_GOTPC:
  552. microblaze_reloc = R_MICROBLAZE_GOTPC_64;
  553. break;
  554. case BFD_RELOC_MICROBLAZE_64_GOT:
  555. microblaze_reloc = R_MICROBLAZE_GOT_64;
  556. break;
  557. case BFD_RELOC_MICROBLAZE_64_TEXTPCREL:
  558. microblaze_reloc = R_MICROBLAZE_TEXTPCREL_64;
  559. break;
  560. case BFD_RELOC_MICROBLAZE_64_TEXTREL:
  561. microblaze_reloc = R_MICROBLAZE_TEXTREL_64;
  562. break;
  563. case BFD_RELOC_MICROBLAZE_64_PLT:
  564. microblaze_reloc = R_MICROBLAZE_PLT_64;
  565. break;
  566. case BFD_RELOC_MICROBLAZE_64_GOTOFF:
  567. microblaze_reloc = R_MICROBLAZE_GOTOFF_64;
  568. break;
  569. case BFD_RELOC_MICROBLAZE_32_GOTOFF:
  570. microblaze_reloc = R_MICROBLAZE_GOTOFF_32;
  571. break;
  572. case BFD_RELOC_MICROBLAZE_64_TLSGD:
  573. microblaze_reloc = R_MICROBLAZE_TLSGD;
  574. break;
  575. case BFD_RELOC_MICROBLAZE_64_TLSLD:
  576. microblaze_reloc = R_MICROBLAZE_TLSLD;
  577. break;
  578. case BFD_RELOC_MICROBLAZE_32_TLSDTPREL:
  579. microblaze_reloc = R_MICROBLAZE_TLSDTPREL32;
  580. break;
  581. case BFD_RELOC_MICROBLAZE_64_TLSDTPREL:
  582. microblaze_reloc = R_MICROBLAZE_TLSDTPREL64;
  583. break;
  584. case BFD_RELOC_MICROBLAZE_32_TLSDTPMOD:
  585. microblaze_reloc = R_MICROBLAZE_TLSDTPMOD32;
  586. break;
  587. case BFD_RELOC_MICROBLAZE_64_TLSGOTTPREL:
  588. microblaze_reloc = R_MICROBLAZE_TLSGOTTPREL32;
  589. break;
  590. case BFD_RELOC_MICROBLAZE_64_TLSTPREL:
  591. microblaze_reloc = R_MICROBLAZE_TLSTPREL32;
  592. break;
  593. case BFD_RELOC_MICROBLAZE_COPY:
  594. microblaze_reloc = R_MICROBLAZE_COPY;
  595. break;
  596. default:
  597. return (reloc_howto_type *) NULL;
  598. }
  599. if (!microblaze_elf_howto_table [R_MICROBLAZE_32])
  600. /* Initialize howto table if needed. */
  601. microblaze_elf_howto_init ();
  602. return microblaze_elf_howto_table [(int) microblaze_reloc];
  603. };
  604. static reloc_howto_type *
  605. microblaze_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  606. const char *r_name)
  607. {
  608. unsigned int i;
  609. for (i = 0; i < NUM_ELEM (microblaze_elf_howto_raw); i++)
  610. if (microblaze_elf_howto_raw[i].name != NULL
  611. && strcasecmp (microblaze_elf_howto_raw[i].name, r_name) == 0)
  612. return &microblaze_elf_howto_raw[i];
  613. return NULL;
  614. }
  615. /* Set the howto pointer for a RCE ELF reloc. */
  616. static bool
  617. microblaze_elf_info_to_howto (bfd * abfd,
  618. arelent * cache_ptr,
  619. Elf_Internal_Rela * dst)
  620. {
  621. unsigned int r_type;
  622. if (!microblaze_elf_howto_table [R_MICROBLAZE_32])
  623. /* Initialize howto table if needed. */
  624. microblaze_elf_howto_init ();
  625. r_type = ELF32_R_TYPE (dst->r_info);
  626. if (r_type >= R_MICROBLAZE_max)
  627. {
  628. /* xgettext:c-format */
  629. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  630. abfd, r_type);
  631. bfd_set_error (bfd_error_bad_value);
  632. return false;
  633. }
  634. cache_ptr->howto = microblaze_elf_howto_table [r_type];
  635. return true;
  636. }
  637. /* Relax table contains information about instructions which can
  638. be removed by relaxation -- replacing a long address with a
  639. short address. */
  640. struct relax_table
  641. {
  642. /* Address where bytes may be deleted. */
  643. bfd_vma addr;
  644. /* Number of bytes to be deleted. */
  645. size_t size;
  646. };
  647. struct _microblaze_elf_section_data
  648. {
  649. struct bfd_elf_section_data elf;
  650. /* Count of used relaxation table entries. */
  651. size_t relax_count;
  652. /* Relaxation table. */
  653. struct relax_table *relax;
  654. };
  655. #define microblaze_elf_section_data(sec) \
  656. ((struct _microblaze_elf_section_data *) elf_section_data (sec))
  657. static bool
  658. microblaze_elf_new_section_hook (bfd *abfd, asection *sec)
  659. {
  660. if (!sec->used_by_bfd)
  661. {
  662. struct _microblaze_elf_section_data *sdata;
  663. size_t amt = sizeof (*sdata);
  664. sdata = bfd_zalloc (abfd, amt);
  665. if (sdata == NULL)
  666. return false;
  667. sec->used_by_bfd = sdata;
  668. }
  669. return _bfd_elf_new_section_hook (abfd, sec);
  670. }
  671. /* Microblaze ELF local labels start with 'L.' or '$L', not '.L'. */
  672. static bool
  673. microblaze_elf_is_local_label_name (bfd *abfd, const char *name)
  674. {
  675. if (name[0] == 'L' && name[1] == '.')
  676. return true;
  677. if (name[0] == '$' && name[1] == 'L')
  678. return true;
  679. /* With gcc, the labels go back to starting with '.', so we accept
  680. the generic ELF local label syntax as well. */
  681. return _bfd_elf_is_local_label_name (abfd, name);
  682. }
  683. /* ELF linker hash entry. */
  684. struct elf32_mb_link_hash_entry
  685. {
  686. struct elf_link_hash_entry elf;
  687. /* TLS Reference Types for the symbol; Updated by check_relocs */
  688. #define TLS_GD 1 /* GD reloc. */
  689. #define TLS_LD 2 /* LD reloc. */
  690. #define TLS_TPREL 4 /* TPREL reloc, => IE. */
  691. #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
  692. #define TLS_TLS 16 /* Any TLS reloc. */
  693. unsigned char tls_mask;
  694. };
  695. #define IS_TLS_GD(x) (x == (TLS_TLS | TLS_GD))
  696. #define IS_TLS_LD(x) (x == (TLS_TLS | TLS_LD))
  697. #define IS_TLS_DTPREL(x) (x == (TLS_TLS | TLS_DTPREL))
  698. #define IS_TLS_NONE(x) (x == 0)
  699. #define elf32_mb_hash_entry(ent) ((struct elf32_mb_link_hash_entry *)(ent))
  700. /* ELF linker hash table. */
  701. struct elf32_mb_link_hash_table
  702. {
  703. struct elf_link_hash_table elf;
  704. /* TLS Local Dynamic GOT Entry */
  705. union {
  706. bfd_signed_vma refcount;
  707. bfd_vma offset;
  708. } tlsld_got;
  709. };
  710. /* Nonzero if this section has TLS related relocations. */
  711. #define has_tls_reloc sec_flg0
  712. /* Get the ELF linker hash table from a link_info structure. */
  713. #define elf32_mb_hash_table(p) \
  714. ((is_elf_hash_table ((p)->hash) \
  715. && elf_hash_table_id (elf_hash_table (p)) == MICROBLAZE_ELF_DATA) \
  716. ? (struct elf32_mb_link_hash_table *) (p)->hash : NULL)
  717. /* Create an entry in a microblaze ELF linker hash table. */
  718. static struct bfd_hash_entry *
  719. link_hash_newfunc (struct bfd_hash_entry *entry,
  720. struct bfd_hash_table *table,
  721. const char *string)
  722. {
  723. /* Allocate the structure if it has not already been allocated by a
  724. subclass. */
  725. if (entry == NULL)
  726. {
  727. entry = bfd_hash_allocate (table,
  728. sizeof (struct elf32_mb_link_hash_entry));
  729. if (entry == NULL)
  730. return entry;
  731. }
  732. /* Call the allocation method of the superclass. */
  733. entry = _bfd_elf_link_hash_newfunc (entry, table, string);
  734. if (entry != NULL)
  735. {
  736. struct elf32_mb_link_hash_entry *eh;
  737. eh = (struct elf32_mb_link_hash_entry *) entry;
  738. eh->tls_mask = 0;
  739. }
  740. return entry;
  741. }
  742. /* Create a mb ELF linker hash table. */
  743. static struct bfd_link_hash_table *
  744. microblaze_elf_link_hash_table_create (bfd *abfd)
  745. {
  746. struct elf32_mb_link_hash_table *ret;
  747. size_t amt = sizeof (struct elf32_mb_link_hash_table);
  748. ret = (struct elf32_mb_link_hash_table *) bfd_zmalloc (amt);
  749. if (ret == NULL)
  750. return NULL;
  751. if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
  752. sizeof (struct elf32_mb_link_hash_entry),
  753. MICROBLAZE_ELF_DATA))
  754. {
  755. free (ret);
  756. return NULL;
  757. }
  758. return &ret->elf.root;
  759. }
  760. /* Set the values of the small data pointers. */
  761. static void
  762. microblaze_elf_final_sdp (struct bfd_link_info *info)
  763. {
  764. struct bfd_link_hash_entry *h;
  765. h = bfd_link_hash_lookup (info->hash, RO_SDA_ANCHOR_NAME, false, false, true);
  766. if (h != (struct bfd_link_hash_entry *) NULL
  767. && h->type == bfd_link_hash_defined)
  768. ro_small_data_pointer = (h->u.def.value
  769. + h->u.def.section->output_section->vma
  770. + h->u.def.section->output_offset);
  771. h = bfd_link_hash_lookup (info->hash, RW_SDA_ANCHOR_NAME, false, false, true);
  772. if (h != (struct bfd_link_hash_entry *) NULL
  773. && h->type == bfd_link_hash_defined)
  774. rw_small_data_pointer = (h->u.def.value
  775. + h->u.def.section->output_section->vma
  776. + h->u.def.section->output_offset);
  777. }
  778. static bfd_vma
  779. dtprel_base (struct bfd_link_info *info)
  780. {
  781. /* If tls_sec is NULL, we should have signalled an error already. */
  782. if (elf_hash_table (info)->tls_sec == NULL)
  783. return 0;
  784. return elf_hash_table (info)->tls_sec->vma;
  785. }
  786. /* The size of the thread control block. */
  787. #define TCB_SIZE 8
  788. /* Output a simple dynamic relocation into SRELOC. */
  789. static void
  790. microblaze_elf_output_dynamic_relocation (bfd *output_bfd,
  791. asection *sreloc,
  792. unsigned long reloc_index,
  793. unsigned long indx,
  794. int r_type,
  795. bfd_vma offset,
  796. bfd_vma addend)
  797. {
  798. Elf_Internal_Rela rel;
  799. rel.r_info = ELF32_R_INFO (indx, r_type);
  800. rel.r_offset = offset;
  801. rel.r_addend = addend;
  802. bfd_elf32_swap_reloca_out (output_bfd, &rel,
  803. (sreloc->contents + reloc_index * sizeof (Elf32_External_Rela)));
  804. }
  805. /* This code is taken from elf32-m32r.c
  806. There is some attempt to make this function usable for many architectures,
  807. both USE_REL and USE_RELA ['twould be nice if such a critter existed],
  808. if only to serve as a learning tool.
  809. The RELOCATE_SECTION function is called by the new ELF backend linker
  810. to handle the relocations for a section.
  811. The relocs are always passed as Rela structures; if the section
  812. actually uses Rel structures, the r_addend field will always be
  813. zero.
  814. This function is responsible for adjust the section contents as
  815. necessary, and (if using Rela relocs and generating a
  816. relocatable output file) adjusting the reloc addend as
  817. necessary.
  818. This function does not have to worry about setting the reloc
  819. address or the reloc symbol index.
  820. LOCAL_SYMS is a pointer to the swapped in local symbols.
  821. LOCAL_SECTIONS is an array giving the section in the input file
  822. corresponding to the st_shndx field of each local symbol.
  823. The global hash table entry for the global symbols can be found
  824. via elf_sym_hashes (input_bfd).
  825. When generating relocatable output, this function must handle
  826. STB_LOCAL/STT_SECTION symbols specially. The output symbol is
  827. going to be the section symbol corresponding to the output
  828. section, which means that the addend must be adjusted
  829. accordingly. */
  830. static int
  831. microblaze_elf_relocate_section (bfd *output_bfd,
  832. struct bfd_link_info *info,
  833. bfd *input_bfd,
  834. asection *input_section,
  835. bfd_byte *contents,
  836. Elf_Internal_Rela *relocs,
  837. Elf_Internal_Sym *local_syms,
  838. asection **local_sections)
  839. {
  840. struct elf32_mb_link_hash_table *htab;
  841. Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  842. struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
  843. Elf_Internal_Rela *rel, *relend;
  844. int endian = (bfd_little_endian (output_bfd)) ? 0 : 2;
  845. /* Assume success. */
  846. bool ret = true;
  847. asection *sreloc;
  848. bfd_vma *local_got_offsets;
  849. unsigned int tls_type;
  850. if (!microblaze_elf_howto_table[R_MICROBLAZE_max-1])
  851. microblaze_elf_howto_init ();
  852. htab = elf32_mb_hash_table (info);
  853. if (htab == NULL)
  854. return false;
  855. local_got_offsets = elf_local_got_offsets (input_bfd);
  856. sreloc = elf_section_data (input_section)->sreloc;
  857. rel = relocs;
  858. relend = relocs + input_section->reloc_count;
  859. for (; rel < relend; rel++)
  860. {
  861. int r_type;
  862. reloc_howto_type *howto;
  863. unsigned long r_symndx;
  864. bfd_vma addend = rel->r_addend;
  865. bfd_vma offset = rel->r_offset;
  866. struct elf_link_hash_entry *h;
  867. Elf_Internal_Sym *sym;
  868. asection *sec;
  869. const char *sym_name;
  870. bfd_reloc_status_type r = bfd_reloc_ok;
  871. const char *errmsg = NULL;
  872. bool unresolved_reloc = false;
  873. h = NULL;
  874. r_type = ELF32_R_TYPE (rel->r_info);
  875. tls_type = 0;
  876. if (r_type < 0 || r_type >= (int) R_MICROBLAZE_max)
  877. {
  878. /* xgettext:c-format */
  879. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  880. input_bfd, (int) r_type);
  881. bfd_set_error (bfd_error_bad_value);
  882. ret = false;
  883. continue;
  884. }
  885. howto = microblaze_elf_howto_table[r_type];
  886. r_symndx = ELF32_R_SYM (rel->r_info);
  887. if (bfd_link_relocatable (info))
  888. {
  889. /* This is a relocatable link. We don't have to change
  890. anything, unless the reloc is against a section symbol,
  891. in which case we have to adjust according to where the
  892. section symbol winds up in the output section. */
  893. sec = NULL;
  894. if (r_symndx >= symtab_hdr->sh_info)
  895. /* External symbol. */
  896. continue;
  897. /* Local symbol. */
  898. sym = local_syms + r_symndx;
  899. sym_name = "<local symbol>";
  900. /* STT_SECTION: symbol is associated with a section. */
  901. if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
  902. /* Symbol isn't associated with a section. Nothing to do. */
  903. continue;
  904. sec = local_sections[r_symndx];
  905. addend += sec->output_offset + sym->st_value;
  906. #ifndef USE_REL
  907. /* This can't be done for USE_REL because it doesn't mean anything
  908. and elf_link_input_bfd asserts this stays zero. */
  909. /* rel->r_addend = addend; */
  910. #endif
  911. #ifndef USE_REL
  912. /* Addends are stored with relocs. We're done. */
  913. continue;
  914. #else /* USE_REL */
  915. /* If partial_inplace, we need to store any additional addend
  916. back in the section. */
  917. if (!howto->partial_inplace)
  918. continue;
  919. /* ??? Here is a nice place to call a special_function like handler. */
  920. r = _bfd_relocate_contents (howto, input_bfd, addend,
  921. contents + offset);
  922. #endif /* USE_REL */
  923. }
  924. else
  925. {
  926. bfd_vma relocation;
  927. bool resolved_to_zero;
  928. /* This is a final link. */
  929. sym = NULL;
  930. sec = NULL;
  931. unresolved_reloc = false;
  932. if (r_symndx < symtab_hdr->sh_info)
  933. {
  934. /* Local symbol. */
  935. sym = local_syms + r_symndx;
  936. sec = local_sections[r_symndx];
  937. if (sec == 0)
  938. continue;
  939. sym_name = "<local symbol>";
  940. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  941. /* r_addend may have changed if the reference section was
  942. a merge section. */
  943. addend = rel->r_addend;
  944. }
  945. else
  946. {
  947. /* External symbol. */
  948. bool warned ATTRIBUTE_UNUSED;
  949. bool ignored ATTRIBUTE_UNUSED;
  950. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  951. r_symndx, symtab_hdr, sym_hashes,
  952. h, sec, relocation,
  953. unresolved_reloc, warned, ignored);
  954. sym_name = h->root.root.string;
  955. }
  956. /* Sanity check the address. */
  957. if (offset > bfd_get_section_limit (input_bfd, input_section))
  958. {
  959. r = bfd_reloc_outofrange;
  960. goto check_reloc;
  961. }
  962. resolved_to_zero = (h != NULL
  963. && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
  964. switch ((int) r_type)
  965. {
  966. case (int) R_MICROBLAZE_SRO32 :
  967. {
  968. const char *name;
  969. /* Only relocate if the symbol is defined. */
  970. if (sec)
  971. {
  972. name = bfd_section_name (sec);
  973. if (strcmp (name, ".sdata2") == 0
  974. || strcmp (name, ".sbss2") == 0)
  975. {
  976. if (ro_small_data_pointer == 0)
  977. microblaze_elf_final_sdp (info);
  978. if (ro_small_data_pointer == 0)
  979. {
  980. ret = false;
  981. r = bfd_reloc_undefined;
  982. goto check_reloc;
  983. }
  984. /* At this point `relocation' contains the object's
  985. address. */
  986. relocation -= ro_small_data_pointer;
  987. /* Now it contains the offset from _SDA2_BASE_. */
  988. r = _bfd_final_link_relocate (howto, input_bfd,
  989. input_section,
  990. contents, offset,
  991. relocation, addend);
  992. }
  993. else
  994. {
  995. _bfd_error_handler
  996. /* xgettext:c-format */
  997. (_("%pB: the target (%s) of an %s relocation"
  998. " is in the wrong section (%pA)"),
  999. input_bfd,
  1000. sym_name,
  1001. microblaze_elf_howto_table[(int) r_type]->name,
  1002. sec);
  1003. /*bfd_set_error (bfd_error_bad_value); ??? why? */
  1004. ret = false;
  1005. continue;
  1006. }
  1007. }
  1008. }
  1009. break;
  1010. case (int) R_MICROBLAZE_SRW32 :
  1011. {
  1012. const char *name;
  1013. /* Only relocate if the symbol is defined. */
  1014. if (sec)
  1015. {
  1016. name = bfd_section_name (sec);
  1017. if (strcmp (name, ".sdata") == 0
  1018. || strcmp (name, ".sbss") == 0)
  1019. {
  1020. if (rw_small_data_pointer == 0)
  1021. microblaze_elf_final_sdp (info);
  1022. if (rw_small_data_pointer == 0)
  1023. {
  1024. ret = false;
  1025. r = bfd_reloc_undefined;
  1026. goto check_reloc;
  1027. }
  1028. /* At this point `relocation' contains the object's
  1029. address. */
  1030. relocation -= rw_small_data_pointer;
  1031. /* Now it contains the offset from _SDA_BASE_. */
  1032. r = _bfd_final_link_relocate (howto, input_bfd,
  1033. input_section,
  1034. contents, offset,
  1035. relocation, addend);
  1036. }
  1037. else
  1038. {
  1039. _bfd_error_handler
  1040. /* xgettext:c-format */
  1041. (_("%pB: the target (%s) of an %s relocation"
  1042. " is in the wrong section (%pA)"),
  1043. input_bfd,
  1044. sym_name,
  1045. microblaze_elf_howto_table[(int) r_type]->name,
  1046. sec);
  1047. /*bfd_set_error (bfd_error_bad_value); ??? why? */
  1048. ret = false;
  1049. continue;
  1050. }
  1051. }
  1052. }
  1053. break;
  1054. case (int) R_MICROBLAZE_32_SYM_OP_SYM:
  1055. break; /* Do nothing. */
  1056. case (int) R_MICROBLAZE_GOTPC_64:
  1057. relocation = (htab->elf.sgotplt->output_section->vma
  1058. + htab->elf.sgotplt->output_offset);
  1059. relocation -= (input_section->output_section->vma
  1060. + input_section->output_offset
  1061. + offset + INST_WORD_SIZE);
  1062. relocation += addend;
  1063. bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
  1064. contents + offset + endian);
  1065. bfd_put_16 (input_bfd, relocation & 0xffff,
  1066. contents + offset + endian + INST_WORD_SIZE);
  1067. break;
  1068. case (int) R_MICROBLAZE_TEXTPCREL_64:
  1069. relocation = input_section->output_section->vma;
  1070. relocation -= (input_section->output_section->vma
  1071. + input_section->output_offset
  1072. + offset + INST_WORD_SIZE);
  1073. relocation += addend;
  1074. bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
  1075. contents + offset + endian);
  1076. bfd_put_16 (input_bfd, relocation & 0xffff,
  1077. contents + offset + endian + INST_WORD_SIZE);
  1078. break;
  1079. case (int) R_MICROBLAZE_PLT_64:
  1080. {
  1081. bfd_vma immediate;
  1082. if (htab->elf.splt != NULL && h != NULL
  1083. && h->plt.offset != (bfd_vma) -1)
  1084. {
  1085. relocation = (htab->elf.splt->output_section->vma
  1086. + htab->elf.splt->output_offset
  1087. + h->plt.offset);
  1088. unresolved_reloc = false;
  1089. immediate = relocation - (input_section->output_section->vma
  1090. + input_section->output_offset
  1091. + offset + INST_WORD_SIZE);
  1092. bfd_put_16 (input_bfd, (immediate >> 16) & 0xffff,
  1093. contents + offset + endian);
  1094. bfd_put_16 (input_bfd, immediate & 0xffff,
  1095. contents + offset + endian + INST_WORD_SIZE);
  1096. }
  1097. else
  1098. {
  1099. relocation -= (input_section->output_section->vma
  1100. + input_section->output_offset
  1101. + offset + INST_WORD_SIZE);
  1102. immediate = relocation;
  1103. bfd_put_16 (input_bfd, (immediate >> 16) & 0xffff,
  1104. contents + offset + endian);
  1105. bfd_put_16 (input_bfd, immediate & 0xffff,
  1106. contents + offset + endian + INST_WORD_SIZE);
  1107. }
  1108. break;
  1109. }
  1110. case (int) R_MICROBLAZE_TLSGD:
  1111. tls_type = (TLS_TLS | TLS_GD);
  1112. goto dogot;
  1113. case (int) R_MICROBLAZE_TLSLD:
  1114. tls_type = (TLS_TLS | TLS_LD);
  1115. /* Fall through. */
  1116. dogot:
  1117. case (int) R_MICROBLAZE_GOT_64:
  1118. {
  1119. bfd_vma *offp;
  1120. bfd_vma off, off2;
  1121. unsigned long indx;
  1122. bfd_vma static_value;
  1123. bool need_relocs = false;
  1124. if (htab->elf.sgot == NULL)
  1125. abort ();
  1126. indx = 0;
  1127. offp = NULL;
  1128. /* 1. Identify GOT Offset;
  1129. 2. Compute Static Values
  1130. 3. Process Module Id, Process Offset
  1131. 4. Fixup Relocation with GOT offset value. */
  1132. /* 1. Determine GOT Offset to use : TLS_LD, global, local */
  1133. if (IS_TLS_LD (tls_type))
  1134. offp = &htab->tlsld_got.offset;
  1135. else if (h != NULL)
  1136. {
  1137. if (htab->elf.sgotplt != NULL
  1138. && h->got.offset != (bfd_vma) -1)
  1139. offp = &h->got.offset;
  1140. else
  1141. abort ();
  1142. }
  1143. else
  1144. {
  1145. if (local_got_offsets == NULL)
  1146. abort ();
  1147. offp = &local_got_offsets[r_symndx];
  1148. }
  1149. if (!offp)
  1150. abort ();
  1151. off = (*offp) & ~1;
  1152. off2 = off;
  1153. if (IS_TLS_LD(tls_type) || IS_TLS_GD(tls_type))
  1154. off2 = off + 4;
  1155. /* Symbol index to use for relocs */
  1156. if (h != NULL)
  1157. {
  1158. bool dyn =
  1159. elf_hash_table (info)->dynamic_sections_created;
  1160. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  1161. bfd_link_pic (info),
  1162. h)
  1163. && (!bfd_link_pic (info)
  1164. || !SYMBOL_REFERENCES_LOCAL (info, h)))
  1165. indx = h->dynindx;
  1166. }
  1167. /* Need to generate relocs ? */
  1168. if ((bfd_link_pic (info) || indx != 0)
  1169. && (h == NULL
  1170. || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  1171. && !resolved_to_zero)
  1172. || h->root.type != bfd_link_hash_undefweak))
  1173. need_relocs = true;
  1174. /* 2. Compute/Emit Static value of r-expression */
  1175. static_value = relocation + addend;
  1176. /* 3. Process module-id and offset */
  1177. if (! ((*offp) & 1) )
  1178. {
  1179. bfd_vma got_offset;
  1180. got_offset = (htab->elf.sgot->output_section->vma
  1181. + htab->elf.sgot->output_offset
  1182. + off);
  1183. /* Process module-id */
  1184. if (IS_TLS_LD(tls_type))
  1185. {
  1186. if (! bfd_link_pic (info))
  1187. bfd_put_32 (output_bfd, 1,
  1188. htab->elf.sgot->contents + off);
  1189. else
  1190. microblaze_elf_output_dynamic_relocation
  1191. (output_bfd,
  1192. htab->elf.srelgot,
  1193. htab->elf.srelgot->reloc_count++,
  1194. /* symindex= */ 0, R_MICROBLAZE_TLSDTPMOD32,
  1195. got_offset, 0);
  1196. }
  1197. else if (IS_TLS_GD(tls_type))
  1198. {
  1199. if (! need_relocs)
  1200. bfd_put_32 (output_bfd, 1,
  1201. htab->elf.sgot->contents + off);
  1202. else
  1203. microblaze_elf_output_dynamic_relocation
  1204. (output_bfd,
  1205. htab->elf.srelgot,
  1206. htab->elf.srelgot->reloc_count++,
  1207. /* symindex= */ indx, R_MICROBLAZE_TLSDTPMOD32,
  1208. got_offset, indx ? 0 : static_value);
  1209. }
  1210. /* Process Offset */
  1211. if (htab->elf.srelgot == NULL)
  1212. abort ();
  1213. got_offset = (htab->elf.sgot->output_section->vma
  1214. + htab->elf.sgot->output_offset
  1215. + off2);
  1216. if (IS_TLS_LD(tls_type))
  1217. {
  1218. /* For LD, offset should be 0 */
  1219. *offp |= 1;
  1220. bfd_put_32 (output_bfd, 0,
  1221. htab->elf.sgot->contents + off2);
  1222. }
  1223. else if (IS_TLS_GD(tls_type))
  1224. {
  1225. *offp |= 1;
  1226. static_value -= dtprel_base(info);
  1227. if (need_relocs)
  1228. microblaze_elf_output_dynamic_relocation
  1229. (output_bfd,
  1230. htab->elf.srelgot,
  1231. htab->elf.srelgot->reloc_count++,
  1232. /* symindex= */ indx, R_MICROBLAZE_TLSDTPREL32,
  1233. got_offset, indx ? 0 : static_value);
  1234. else
  1235. bfd_put_32 (output_bfd, static_value,
  1236. htab->elf.sgot->contents + off2);
  1237. }
  1238. else
  1239. {
  1240. bfd_put_32 (output_bfd, static_value,
  1241. htab->elf.sgot->contents + off2);
  1242. /* Relocs for dyn symbols generated by
  1243. finish_dynamic_symbols */
  1244. if (bfd_link_pic (info) && h == NULL)
  1245. {
  1246. *offp |= 1;
  1247. microblaze_elf_output_dynamic_relocation
  1248. (output_bfd,
  1249. htab->elf.srelgot,
  1250. htab->elf.srelgot->reloc_count++,
  1251. /* symindex= */ indx, R_MICROBLAZE_REL,
  1252. got_offset, static_value);
  1253. }
  1254. }
  1255. }
  1256. /* 4. Fixup Relocation with GOT offset value
  1257. Compute relative address of GOT entry for applying
  1258. the current relocation */
  1259. relocation = htab->elf.sgot->output_section->vma
  1260. + htab->elf.sgot->output_offset
  1261. + off
  1262. - htab->elf.sgotplt->output_section->vma
  1263. - htab->elf.sgotplt->output_offset;
  1264. /* Apply Current Relocation */
  1265. bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
  1266. contents + offset + endian);
  1267. bfd_put_16 (input_bfd, relocation & 0xffff,
  1268. contents + offset + endian + INST_WORD_SIZE);
  1269. unresolved_reloc = false;
  1270. break;
  1271. }
  1272. case (int) R_MICROBLAZE_GOTOFF_64:
  1273. {
  1274. bfd_vma immediate;
  1275. unsigned short lo, high;
  1276. relocation += addend;
  1277. relocation -= (htab->elf.sgotplt->output_section->vma
  1278. + htab->elf.sgotplt->output_offset);
  1279. /* Write this value into correct location. */
  1280. immediate = relocation;
  1281. lo = immediate & 0x0000ffff;
  1282. high = (immediate >> 16) & 0x0000ffff;
  1283. bfd_put_16 (input_bfd, high, contents + offset + endian);
  1284. bfd_put_16 (input_bfd, lo,
  1285. contents + offset + INST_WORD_SIZE + endian);
  1286. break;
  1287. }
  1288. case (int) R_MICROBLAZE_GOTOFF_32:
  1289. {
  1290. relocation += addend;
  1291. relocation -= (htab->elf.sgotplt->output_section->vma
  1292. + htab->elf.sgotplt->output_offset);
  1293. /* Write this value into correct location. */
  1294. bfd_put_32 (input_bfd, relocation, contents + offset);
  1295. break;
  1296. }
  1297. case (int) R_MICROBLAZE_TLSDTPREL64:
  1298. relocation += addend;
  1299. relocation -= dtprel_base(info);
  1300. bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
  1301. contents + offset + 2);
  1302. bfd_put_16 (input_bfd, relocation & 0xffff,
  1303. contents + offset + 2 + INST_WORD_SIZE);
  1304. break;
  1305. case (int) R_MICROBLAZE_TEXTREL_64:
  1306. case (int) R_MICROBLAZE_TEXTREL_32_LO:
  1307. case (int) R_MICROBLAZE_64_PCREL :
  1308. case (int) R_MICROBLAZE_64:
  1309. case (int) R_MICROBLAZE_32:
  1310. {
  1311. /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
  1312. from removed linkonce sections, or sections discarded by
  1313. a linker script. */
  1314. if (r_symndx == STN_UNDEF || (input_section->flags & SEC_ALLOC) == 0)
  1315. {
  1316. relocation += addend;
  1317. if (r_type == R_MICROBLAZE_32)
  1318. bfd_put_32 (input_bfd, relocation, contents + offset);
  1319. else
  1320. {
  1321. if (r_type == R_MICROBLAZE_64_PCREL)
  1322. relocation -= (input_section->output_section->vma
  1323. + input_section->output_offset
  1324. + offset + INST_WORD_SIZE);
  1325. else if (r_type == R_MICROBLAZE_TEXTREL_64
  1326. || r_type == R_MICROBLAZE_TEXTREL_32_LO)
  1327. relocation -= input_section->output_section->vma;
  1328. if (r_type == R_MICROBLAZE_TEXTREL_32_LO)
  1329. bfd_put_16 (input_bfd, relocation & 0xffff,
  1330. contents + offset + endian);
  1331. else
  1332. {
  1333. bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
  1334. contents + offset + endian);
  1335. bfd_put_16 (input_bfd, relocation & 0xffff,
  1336. contents + offset + endian + INST_WORD_SIZE);
  1337. }
  1338. }
  1339. break;
  1340. }
  1341. if ((bfd_link_pic (info)
  1342. && (h == NULL
  1343. || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  1344. && !resolved_to_zero)
  1345. || h->root.type != bfd_link_hash_undefweak)
  1346. && (!howto->pc_relative
  1347. || (h != NULL
  1348. && h->dynindx != -1
  1349. && (!info->symbolic
  1350. || !h->def_regular))))
  1351. || (!bfd_link_pic (info)
  1352. && h != NULL
  1353. && h->dynindx != -1
  1354. && !h->non_got_ref
  1355. && ((h->def_dynamic
  1356. && !h->def_regular)
  1357. || h->root.type == bfd_link_hash_undefweak
  1358. || h->root.type == bfd_link_hash_undefined)))
  1359. {
  1360. Elf_Internal_Rela outrel;
  1361. bfd_byte *loc;
  1362. bool skip;
  1363. /* When generating a shared object, these relocations
  1364. are copied into the output file to be resolved at run
  1365. time. */
  1366. BFD_ASSERT (sreloc != NULL);
  1367. skip = false;
  1368. outrel.r_offset =
  1369. _bfd_elf_section_offset (output_bfd, info, input_section,
  1370. rel->r_offset);
  1371. if (outrel.r_offset == (bfd_vma) -1)
  1372. skip = true;
  1373. else if (outrel.r_offset == (bfd_vma) -2)
  1374. skip = true;
  1375. outrel.r_offset += (input_section->output_section->vma
  1376. + input_section->output_offset);
  1377. if (skip)
  1378. memset (&outrel, 0, sizeof outrel);
  1379. /* h->dynindx may be -1 if the symbol was marked to
  1380. become local. */
  1381. else if (h != NULL
  1382. && ((! info->symbolic && h->dynindx != -1)
  1383. || !h->def_regular))
  1384. {
  1385. BFD_ASSERT (h->dynindx != -1);
  1386. outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
  1387. outrel.r_addend = addend;
  1388. }
  1389. else
  1390. {
  1391. if (r_type == R_MICROBLAZE_32)
  1392. {
  1393. outrel.r_info = ELF32_R_INFO (0, R_MICROBLAZE_REL);
  1394. outrel.r_addend = relocation + addend;
  1395. }
  1396. else
  1397. {
  1398. BFD_FAIL ();
  1399. _bfd_error_handler
  1400. (_("%pB: probably compiled without -fPIC?"),
  1401. input_bfd);
  1402. bfd_set_error (bfd_error_bad_value);
  1403. return false;
  1404. }
  1405. }
  1406. loc = sreloc->contents;
  1407. loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
  1408. bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
  1409. break;
  1410. }
  1411. else
  1412. {
  1413. relocation += addend;
  1414. if (r_type == R_MICROBLAZE_32)
  1415. bfd_put_32 (input_bfd, relocation, contents + offset);
  1416. else
  1417. {
  1418. if (r_type == R_MICROBLAZE_64_PCREL)
  1419. relocation -= (input_section->output_section->vma
  1420. + input_section->output_offset
  1421. + offset + INST_WORD_SIZE);
  1422. else if (r_type == R_MICROBLAZE_TEXTREL_64
  1423. || r_type == R_MICROBLAZE_TEXTREL_32_LO)
  1424. relocation -= input_section->output_section->vma;
  1425. if (r_type == R_MICROBLAZE_TEXTREL_32_LO)
  1426. {
  1427. bfd_put_16 (input_bfd, relocation & 0xffff,
  1428. contents + offset + endian);
  1429. }
  1430. else
  1431. {
  1432. bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
  1433. contents + offset + endian);
  1434. bfd_put_16 (input_bfd, relocation & 0xffff,
  1435. contents + offset + endian
  1436. + INST_WORD_SIZE);
  1437. }
  1438. }
  1439. break;
  1440. }
  1441. }
  1442. default :
  1443. r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  1444. contents, offset,
  1445. relocation, addend);
  1446. break;
  1447. }
  1448. }
  1449. check_reloc:
  1450. if (r != bfd_reloc_ok)
  1451. {
  1452. /* FIXME: This should be generic enough to go in a utility. */
  1453. const char *name;
  1454. if (h != NULL)
  1455. name = h->root.root.string;
  1456. else
  1457. {
  1458. name = (bfd_elf_string_from_elf_section
  1459. (input_bfd, symtab_hdr->sh_link, sym->st_name));
  1460. if (name == NULL || *name == '\0')
  1461. name = bfd_section_name (sec);
  1462. }
  1463. if (errmsg != NULL)
  1464. goto common_error;
  1465. switch (r)
  1466. {
  1467. case bfd_reloc_overflow:
  1468. (*info->callbacks->reloc_overflow)
  1469. (info, (h ? &h->root : NULL), name, howto->name,
  1470. (bfd_vma) 0, input_bfd, input_section, offset);
  1471. break;
  1472. case bfd_reloc_undefined:
  1473. (*info->callbacks->undefined_symbol)
  1474. (info, name, input_bfd, input_section, offset, true);
  1475. break;
  1476. case bfd_reloc_outofrange:
  1477. errmsg = _("internal error: out of range error");
  1478. goto common_error;
  1479. case bfd_reloc_notsupported:
  1480. errmsg = _("internal error: unsupported relocation error");
  1481. goto common_error;
  1482. case bfd_reloc_dangerous:
  1483. errmsg = _("internal error: dangerous error");
  1484. goto common_error;
  1485. default:
  1486. errmsg = _("internal error: unknown error");
  1487. /* Fall through. */
  1488. common_error:
  1489. (*info->callbacks->warning) (info, errmsg, name, input_bfd,
  1490. input_section, offset);
  1491. break;
  1492. }
  1493. }
  1494. }
  1495. return ret;
  1496. }
  1497. /* Calculate fixup value for reference. */
  1498. static size_t
  1499. calc_fixup (bfd_vma start, bfd_vma size, asection *sec)
  1500. {
  1501. bfd_vma end = start + size;
  1502. size_t i, fixup = 0;
  1503. struct _microblaze_elf_section_data *sdata;
  1504. if (sec == NULL || (sdata = microblaze_elf_section_data (sec)) == NULL)
  1505. return 0;
  1506. /* Look for addr in relax table, total fixup value. */
  1507. for (i = 0; i < sdata->relax_count; i++)
  1508. {
  1509. if (end <= sdata->relax[i].addr)
  1510. break;
  1511. if (end != start && start > sdata->relax[i].addr)
  1512. continue;
  1513. fixup += sdata->relax[i].size;
  1514. }
  1515. return fixup;
  1516. }
  1517. /* Read-modify-write into the bfd, an immediate value into appropriate fields of
  1518. a 32-bit instruction. */
  1519. static void
  1520. microblaze_bfd_write_imm_value_32 (bfd *abfd, bfd_byte *bfd_addr, bfd_vma val)
  1521. {
  1522. unsigned long instr = bfd_get_32 (abfd, bfd_addr);
  1523. instr &= ~0x0000ffff;
  1524. instr |= (val & 0x0000ffff);
  1525. bfd_put_32 (abfd, instr, bfd_addr);
  1526. }
  1527. /* Read-modify-write into the bfd, an immediate value into appropriate fields of
  1528. two consecutive 32-bit instructions. */
  1529. static void
  1530. microblaze_bfd_write_imm_value_64 (bfd *abfd, bfd_byte *bfd_addr, bfd_vma val)
  1531. {
  1532. unsigned long instr_hi;
  1533. unsigned long instr_lo;
  1534. instr_hi = bfd_get_32 (abfd, bfd_addr);
  1535. instr_hi &= ~0x0000ffff;
  1536. instr_hi |= ((val >> 16) & 0x0000ffff);
  1537. bfd_put_32 (abfd, instr_hi, bfd_addr);
  1538. instr_lo = bfd_get_32 (abfd, bfd_addr + INST_WORD_SIZE);
  1539. instr_lo &= ~0x0000ffff;
  1540. instr_lo |= (val & 0x0000ffff);
  1541. bfd_put_32 (abfd, instr_lo, bfd_addr + INST_WORD_SIZE);
  1542. }
  1543. static bool
  1544. microblaze_elf_relax_section (bfd *abfd,
  1545. asection *sec,
  1546. struct bfd_link_info *link_info,
  1547. bool *again)
  1548. {
  1549. Elf_Internal_Shdr *symtab_hdr;
  1550. Elf_Internal_Rela *internal_relocs;
  1551. Elf_Internal_Rela *free_relocs = NULL;
  1552. Elf_Internal_Rela *irel, *irelend;
  1553. bfd_byte *contents = NULL;
  1554. bfd_byte *free_contents = NULL;
  1555. int rel_count;
  1556. unsigned int shndx;
  1557. size_t i, sym_index;
  1558. asection *o;
  1559. struct elf_link_hash_entry *sym_hash;
  1560. Elf_Internal_Sym *isymbuf, *isymend;
  1561. Elf_Internal_Sym *isym;
  1562. size_t symcount;
  1563. size_t offset;
  1564. bfd_vma src, dest;
  1565. struct _microblaze_elf_section_data *sdata;
  1566. /* We only do this once per section. We may be able to delete some code
  1567. by running multiple passes, but it is not worth it. */
  1568. *again = false;
  1569. /* Only do this for a text section. */
  1570. if (bfd_link_relocatable (link_info)
  1571. || (sec->flags & SEC_RELOC) == 0
  1572. || (sec->flags & SEC_CODE) == 0
  1573. || sec->reloc_count == 0
  1574. || (sdata = microblaze_elf_section_data (sec)) == NULL)
  1575. return true;
  1576. BFD_ASSERT ((sec->size > 0) || (sec->rawsize > 0));
  1577. /* If this is the first time we have been called for this section,
  1578. initialize the cooked size. */
  1579. if (sec->size == 0)
  1580. sec->size = sec->rawsize;
  1581. /* Get symbols for this section. */
  1582. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  1583. isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
  1584. symcount = symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
  1585. if (isymbuf == NULL)
  1586. isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symcount,
  1587. 0, NULL, NULL, NULL);
  1588. BFD_ASSERT (isymbuf != NULL);
  1589. internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory);
  1590. if (internal_relocs == NULL)
  1591. goto error_return;
  1592. if (! link_info->keep_memory)
  1593. free_relocs = internal_relocs;
  1594. sdata->relax_count = 0;
  1595. sdata->relax = (struct relax_table *) bfd_malloc ((sec->reloc_count + 1)
  1596. * sizeof (*sdata->relax));
  1597. if (sdata->relax == NULL)
  1598. goto error_return;
  1599. irelend = internal_relocs + sec->reloc_count;
  1600. rel_count = 0;
  1601. for (irel = internal_relocs; irel < irelend; irel++, rel_count++)
  1602. {
  1603. bfd_vma symval;
  1604. if ((ELF32_R_TYPE (irel->r_info) != (int) R_MICROBLAZE_64_PCREL)
  1605. && (ELF32_R_TYPE (irel->r_info) != (int) R_MICROBLAZE_64)
  1606. && (ELF32_R_TYPE (irel->r_info) != (int) R_MICROBLAZE_TEXTREL_64))
  1607. continue; /* Can't delete this reloc. */
  1608. /* Get the section contents. */
  1609. if (contents == NULL)
  1610. {
  1611. if (elf_section_data (sec)->this_hdr.contents != NULL)
  1612. contents = elf_section_data (sec)->this_hdr.contents;
  1613. else
  1614. {
  1615. contents = (bfd_byte *) bfd_malloc (sec->size);
  1616. if (contents == NULL)
  1617. goto error_return;
  1618. free_contents = contents;
  1619. if (!bfd_get_section_contents (abfd, sec, contents,
  1620. (file_ptr) 0, sec->size))
  1621. goto error_return;
  1622. elf_section_data (sec)->this_hdr.contents = contents;
  1623. }
  1624. }
  1625. /* Get the value of the symbol referred to by the reloc. */
  1626. if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
  1627. {
  1628. /* A local symbol. */
  1629. asection *sym_sec;
  1630. isym = isymbuf + ELF32_R_SYM (irel->r_info);
  1631. if (isym->st_shndx == SHN_UNDEF)
  1632. sym_sec = bfd_und_section_ptr;
  1633. else if (isym->st_shndx == SHN_ABS)
  1634. sym_sec = bfd_abs_section_ptr;
  1635. else if (isym->st_shndx == SHN_COMMON)
  1636. sym_sec = bfd_com_section_ptr;
  1637. else
  1638. sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  1639. symval = _bfd_elf_rela_local_sym (abfd, isym, &sym_sec, irel);
  1640. }
  1641. else
  1642. {
  1643. unsigned long indx;
  1644. struct elf_link_hash_entry *h;
  1645. indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
  1646. h = elf_sym_hashes (abfd)[indx];
  1647. BFD_ASSERT (h != NULL);
  1648. if (h->root.type != bfd_link_hash_defined
  1649. && h->root.type != bfd_link_hash_defweak)
  1650. /* This appears to be a reference to an undefined
  1651. symbol. Just ignore it--it will be caught by the
  1652. regular reloc processing. */
  1653. continue;
  1654. symval = (h->root.u.def.value
  1655. + h->root.u.def.section->output_section->vma
  1656. + h->root.u.def.section->output_offset);
  1657. }
  1658. /* If this is a PC-relative reloc, subtract the instr offset from
  1659. the symbol value. */
  1660. if (ELF32_R_TYPE (irel->r_info) == (int) R_MICROBLAZE_64_PCREL)
  1661. {
  1662. symval = symval + irel->r_addend
  1663. - (irel->r_offset
  1664. + sec->output_section->vma
  1665. + sec->output_offset);
  1666. }
  1667. else if (ELF32_R_TYPE (irel->r_info) == (int) R_MICROBLAZE_TEXTREL_64)
  1668. {
  1669. symval = symval + irel->r_addend - (sec->output_section->vma);
  1670. }
  1671. else
  1672. symval += irel->r_addend;
  1673. if ((symval & 0xffff8000) == 0
  1674. || (symval & 0xffff8000) == 0xffff8000)
  1675. {
  1676. /* We can delete this instruction. */
  1677. sdata->relax[sdata->relax_count].addr = irel->r_offset;
  1678. sdata->relax[sdata->relax_count].size = INST_WORD_SIZE;
  1679. sdata->relax_count++;
  1680. /* Rewrite relocation type. */
  1681. switch ((enum elf_microblaze_reloc_type) ELF32_R_TYPE (irel->r_info))
  1682. {
  1683. case R_MICROBLAZE_64_PCREL:
  1684. irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
  1685. (int) R_MICROBLAZE_32_PCREL_LO);
  1686. break;
  1687. case R_MICROBLAZE_64:
  1688. irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
  1689. (int) R_MICROBLAZE_32_LO);
  1690. break;
  1691. case R_MICROBLAZE_TEXTREL_64:
  1692. irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
  1693. (int) R_MICROBLAZE_TEXTREL_32_LO);
  1694. break;
  1695. default:
  1696. /* Cannot happen. */
  1697. BFD_ASSERT (false);
  1698. }
  1699. }
  1700. } /* Loop through all relocations. */
  1701. /* Loop through the relocs again, and see if anything needs to change. */
  1702. if (sdata->relax_count > 0)
  1703. {
  1704. shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
  1705. rel_count = 0;
  1706. sdata->relax[sdata->relax_count].addr = sec->size;
  1707. for (irel = internal_relocs; irel < irelend; irel++, rel_count++)
  1708. {
  1709. bfd_vma nraddr;
  1710. /* Get the new reloc address. */
  1711. nraddr = irel->r_offset - calc_fixup (irel->r_offset, 0, sec);
  1712. switch ((enum elf_microblaze_reloc_type) ELF32_R_TYPE (irel->r_info))
  1713. {
  1714. default:
  1715. break;
  1716. case R_MICROBLAZE_64_PCREL:
  1717. break;
  1718. case R_MICROBLAZE_TEXTREL_64:
  1719. case R_MICROBLAZE_TEXTREL_32_LO:
  1720. case R_MICROBLAZE_64:
  1721. case R_MICROBLAZE_32_LO:
  1722. /* If this reloc is against a symbol defined in this
  1723. section, we must check the addend to see it will put the value in
  1724. range to be adjusted, and hence must be changed. */
  1725. if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
  1726. {
  1727. isym = isymbuf + ELF32_R_SYM (irel->r_info);
  1728. /* Only handle relocs against .text. */
  1729. if (isym->st_shndx == shndx
  1730. && ELF32_ST_TYPE (isym->st_info) == STT_SECTION)
  1731. irel->r_addend -= calc_fixup (irel->r_addend, 0, sec);
  1732. }
  1733. break;
  1734. case R_MICROBLAZE_NONE:
  1735. {
  1736. /* This was a PC-relative instruction that was
  1737. completely resolved. */
  1738. size_t sfix, efix;
  1739. bfd_vma target_address;
  1740. target_address = irel->r_addend + irel->r_offset;
  1741. sfix = calc_fixup (irel->r_offset, 0, sec);
  1742. efix = calc_fixup (target_address, 0, sec);
  1743. irel->r_addend -= (efix - sfix);
  1744. /* Should use HOWTO. */
  1745. microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset,
  1746. irel->r_addend);
  1747. }
  1748. break;
  1749. case R_MICROBLAZE_64_NONE:
  1750. {
  1751. /* This was a PC-relative 64-bit instruction that was
  1752. completely resolved. */
  1753. size_t sfix, efix;
  1754. bfd_vma target_address;
  1755. target_address = irel->r_addend + irel->r_offset + INST_WORD_SIZE;
  1756. sfix = calc_fixup (irel->r_offset + INST_WORD_SIZE, 0, sec);
  1757. efix = calc_fixup (target_address, 0, sec);
  1758. irel->r_addend -= (efix - sfix);
  1759. microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset
  1760. + INST_WORD_SIZE, irel->r_addend);
  1761. }
  1762. break;
  1763. }
  1764. irel->r_offset = nraddr;
  1765. } /* Change all relocs in this section. */
  1766. /* Look through all other sections. */
  1767. for (o = abfd->sections; o != NULL; o = o->next)
  1768. {
  1769. Elf_Internal_Rela *irelocs;
  1770. Elf_Internal_Rela *irelscan, *irelscanend;
  1771. bfd_byte *ocontents;
  1772. if (o == sec
  1773. || (o->flags & SEC_RELOC) == 0
  1774. || o->reloc_count == 0)
  1775. continue;
  1776. /* We always cache the relocs. Perhaps, if info->keep_memory is
  1777. FALSE, we should free them, if we are permitted to. */
  1778. irelocs = _bfd_elf_link_read_relocs (abfd, o, NULL, NULL, true);
  1779. if (irelocs == NULL)
  1780. goto error_return;
  1781. ocontents = NULL;
  1782. irelscanend = irelocs + o->reloc_count;
  1783. for (irelscan = irelocs; irelscan < irelscanend; irelscan++)
  1784. {
  1785. if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)
  1786. {
  1787. isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
  1788. /* Look at the reloc only if the value has been resolved. */
  1789. if (isym->st_shndx == shndx
  1790. && (ELF32_ST_TYPE (isym->st_info) == STT_SECTION))
  1791. {
  1792. if (ocontents == NULL)
  1793. {
  1794. if (elf_section_data (o)->this_hdr.contents != NULL)
  1795. ocontents = elf_section_data (o)->this_hdr.contents;
  1796. else
  1797. {
  1798. /* We always cache the section contents.
  1799. Perhaps, if info->keep_memory is FALSE, we
  1800. should free them, if we are permitted to. */
  1801. if (o->rawsize == 0)
  1802. o->rawsize = o->size;
  1803. ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
  1804. if (ocontents == NULL)
  1805. goto error_return;
  1806. if (!bfd_get_section_contents (abfd, o, ocontents,
  1807. (file_ptr) 0,
  1808. o->rawsize))
  1809. goto error_return;
  1810. elf_section_data (o)->this_hdr.contents = ocontents;
  1811. }
  1812. }
  1813. irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec);
  1814. }
  1815. else if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_SYM_OP_SYM)
  1816. {
  1817. isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
  1818. /* Look at the reloc only if the value has been resolved. */
  1819. if (ocontents == NULL)
  1820. {
  1821. if (elf_section_data (o)->this_hdr.contents != NULL)
  1822. ocontents = elf_section_data (o)->this_hdr.contents;
  1823. else
  1824. {
  1825. /* We always cache the section contents.
  1826. Perhaps, if info->keep_memory is FALSE, we
  1827. should free them, if we are permitted to. */
  1828. if (o->rawsize == 0)
  1829. o->rawsize = o->size;
  1830. ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
  1831. if (ocontents == NULL)
  1832. goto error_return;
  1833. if (!bfd_get_section_contents (abfd, o, ocontents,
  1834. (file_ptr) 0,
  1835. o->rawsize))
  1836. goto error_return;
  1837. elf_section_data (o)->this_hdr.contents = ocontents;
  1838. }
  1839. }
  1840. irelscan->r_addend -= calc_fixup (irel->r_addend
  1841. + isym->st_value,
  1842. 0,
  1843. sec);
  1844. }
  1845. }
  1846. else if ((ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_PCREL_LO)
  1847. || (ELF32_R_TYPE (irelscan->r_info)
  1848. == (int) R_MICROBLAZE_32_LO)
  1849. || (ELF32_R_TYPE (irelscan->r_info)
  1850. == (int) R_MICROBLAZE_TEXTREL_32_LO))
  1851. {
  1852. isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
  1853. /* Look at the reloc only if the value has been resolved. */
  1854. if (isym->st_shndx == shndx
  1855. && (ELF32_ST_TYPE (isym->st_info) == STT_SECTION))
  1856. {
  1857. bfd_vma immediate;
  1858. bfd_vma target_address;
  1859. if (ocontents == NULL)
  1860. {
  1861. if (elf_section_data (o)->this_hdr.contents != NULL)
  1862. ocontents = elf_section_data (o)->this_hdr.contents;
  1863. else
  1864. {
  1865. /* We always cache the section contents.
  1866. Perhaps, if info->keep_memory is FALSE, we
  1867. should free them, if we are permitted to. */
  1868. if (o->rawsize == 0)
  1869. o->rawsize = o->size;
  1870. ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
  1871. if (ocontents == NULL)
  1872. goto error_return;
  1873. if (!bfd_get_section_contents (abfd, o, ocontents,
  1874. (file_ptr) 0,
  1875. o->rawsize))
  1876. goto error_return;
  1877. elf_section_data (o)->this_hdr.contents = ocontents;
  1878. }
  1879. }
  1880. unsigned long instr = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
  1881. immediate = instr & 0x0000ffff;
  1882. target_address = immediate;
  1883. offset = calc_fixup (target_address, 0, sec);
  1884. immediate -= offset;
  1885. irelscan->r_addend -= offset;
  1886. microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
  1887. irelscan->r_addend);
  1888. }
  1889. }
  1890. if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64
  1891. || (ELF32_R_TYPE (irelscan->r_info)
  1892. == (int) R_MICROBLAZE_TEXTREL_64))
  1893. {
  1894. isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
  1895. /* Look at the reloc only if the value has been resolved. */
  1896. if (isym->st_shndx == shndx
  1897. && (ELF32_ST_TYPE (isym->st_info) == STT_SECTION))
  1898. {
  1899. if (ocontents == NULL)
  1900. {
  1901. if (elf_section_data (o)->this_hdr.contents != NULL)
  1902. ocontents = elf_section_data (o)->this_hdr.contents;
  1903. else
  1904. {
  1905. /* We always cache the section contents.
  1906. Perhaps, if info->keep_memory is FALSE, we
  1907. should free them, if we are permitted to. */
  1908. if (o->rawsize == 0)
  1909. o->rawsize = o->size;
  1910. ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
  1911. if (ocontents == NULL)
  1912. goto error_return;
  1913. if (!bfd_get_section_contents (abfd, o, ocontents,
  1914. (file_ptr) 0,
  1915. o->rawsize))
  1916. goto error_return;
  1917. elf_section_data (o)->this_hdr.contents = ocontents;
  1918. }
  1919. }
  1920. offset = calc_fixup (irelscan->r_addend, 0, sec);
  1921. irelscan->r_addend -= offset;
  1922. }
  1923. }
  1924. else if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64_PCREL)
  1925. {
  1926. isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
  1927. /* Look at the reloc only if the value has been resolved. */
  1928. if (isym->st_shndx == shndx
  1929. && (ELF32_ST_TYPE (isym->st_info) == STT_SECTION))
  1930. {
  1931. bfd_vma immediate;
  1932. bfd_vma target_address;
  1933. if (ocontents == NULL)
  1934. {
  1935. if (elf_section_data (o)->this_hdr.contents != NULL)
  1936. ocontents = elf_section_data (o)->this_hdr.contents;
  1937. else
  1938. {
  1939. /* We always cache the section contents.
  1940. Perhaps, if info->keep_memory is FALSE, we
  1941. should free them, if we are permitted to. */
  1942. if (o->rawsize == 0)
  1943. o->rawsize = o->size;
  1944. ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
  1945. if (ocontents == NULL)
  1946. goto error_return;
  1947. if (!bfd_get_section_contents (abfd, o, ocontents,
  1948. (file_ptr) 0,
  1949. o->rawsize))
  1950. goto error_return;
  1951. elf_section_data (o)->this_hdr.contents = ocontents;
  1952. }
  1953. }
  1954. unsigned long instr_hi = bfd_get_32 (abfd, ocontents
  1955. + irelscan->r_offset);
  1956. unsigned long instr_lo = bfd_get_32 (abfd, ocontents
  1957. + irelscan->r_offset
  1958. + INST_WORD_SIZE);
  1959. immediate = (instr_hi & 0x0000ffff) << 16;
  1960. immediate |= (instr_lo & 0x0000ffff);
  1961. target_address = immediate;
  1962. offset = calc_fixup (target_address, 0, sec);
  1963. immediate -= offset;
  1964. irelscan->r_addend -= offset;
  1965. microblaze_bfd_write_imm_value_64 (abfd, ocontents
  1966. + irelscan->r_offset, immediate);
  1967. }
  1968. }
  1969. }
  1970. }
  1971. /* Adjust the local symbols defined in this section. */
  1972. isymend = isymbuf + symtab_hdr->sh_info;
  1973. for (isym = isymbuf; isym < isymend; isym++)
  1974. {
  1975. if (isym->st_shndx == shndx)
  1976. {
  1977. isym->st_value -= calc_fixup (isym->st_value, 0, sec);
  1978. if (isym->st_size)
  1979. isym->st_size -= calc_fixup (isym->st_value, isym->st_size, sec);
  1980. }
  1981. }
  1982. /* Now adjust the global symbols defined in this section. */
  1983. isym = isymbuf + symtab_hdr->sh_info;
  1984. symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)) - symtab_hdr->sh_info;
  1985. for (sym_index = 0; sym_index < symcount; sym_index++)
  1986. {
  1987. sym_hash = elf_sym_hashes (abfd)[sym_index];
  1988. if ((sym_hash->root.type == bfd_link_hash_defined
  1989. || sym_hash->root.type == bfd_link_hash_defweak)
  1990. && sym_hash->root.u.def.section == sec)
  1991. {
  1992. sym_hash->root.u.def.value -= calc_fixup (sym_hash->root.u.def.value,
  1993. 0, sec);
  1994. if (sym_hash->size)
  1995. sym_hash->size -= calc_fixup (sym_hash->root.u.def.value,
  1996. sym_hash->size, sec);
  1997. }
  1998. }
  1999. /* Physically move the code and change the cooked size. */
  2000. dest = sdata->relax[0].addr;
  2001. for (i = 0; i < sdata->relax_count; i++)
  2002. {
  2003. size_t len;
  2004. src = sdata->relax[i].addr + sdata->relax[i].size;
  2005. len = (sdata->relax[i+1].addr - sdata->relax[i].addr
  2006. - sdata->relax[i].size);
  2007. memmove (contents + dest, contents + src, len);
  2008. sec->size -= sdata->relax[i].size;
  2009. dest += len;
  2010. }
  2011. elf_section_data (sec)->relocs = internal_relocs;
  2012. free_relocs = NULL;
  2013. elf_section_data (sec)->this_hdr.contents = contents;
  2014. free_contents = NULL;
  2015. symtab_hdr->contents = (bfd_byte *) isymbuf;
  2016. }
  2017. free (free_relocs);
  2018. free_relocs = NULL;
  2019. if (free_contents != NULL)
  2020. {
  2021. if (!link_info->keep_memory)
  2022. free (free_contents);
  2023. else
  2024. /* Cache the section contents for elf_link_input_bfd. */
  2025. elf_section_data (sec)->this_hdr.contents = contents;
  2026. free_contents = NULL;
  2027. }
  2028. if (sdata->relax_count == 0)
  2029. {
  2030. *again = false;
  2031. free (sdata->relax);
  2032. sdata->relax = NULL;
  2033. }
  2034. else
  2035. *again = true;
  2036. return true;
  2037. error_return:
  2038. free (free_relocs);
  2039. free (free_contents);
  2040. free (sdata->relax);
  2041. sdata->relax = NULL;
  2042. sdata->relax_count = 0;
  2043. return false;
  2044. }
  2045. /* Return the section that should be marked against GC for a given
  2046. relocation. */
  2047. static asection *
  2048. microblaze_elf_gc_mark_hook (asection *sec,
  2049. struct bfd_link_info * info,
  2050. Elf_Internal_Rela * rel,
  2051. struct elf_link_hash_entry * h,
  2052. Elf_Internal_Sym * sym)
  2053. {
  2054. if (h != NULL)
  2055. switch (ELF32_R_TYPE (rel->r_info))
  2056. {
  2057. case R_MICROBLAZE_GNU_VTINHERIT:
  2058. case R_MICROBLAZE_GNU_VTENTRY:
  2059. return NULL;
  2060. }
  2061. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  2062. }
  2063. /* PIC support. */
  2064. #define PLT_ENTRY_SIZE 16
  2065. #define PLT_ENTRY_WORD_0 0xb0000000 /* "imm 0". */
  2066. #define PLT_ENTRY_WORD_1 0xe9940000 /* "lwi r12,r20,0" - relocated to lwi r12,r20,func@GOT. */
  2067. #define PLT_ENTRY_WORD_1_NOPIC 0xe9800000 /* "lwi r12,r0,0" - non-PIC object. */
  2068. #define PLT_ENTRY_WORD_2 0x98186000 /* "brad r12". */
  2069. #define PLT_ENTRY_WORD_3 0x80000000 /* "nop". */
  2070. static bool
  2071. update_local_sym_info (bfd *abfd,
  2072. Elf_Internal_Shdr *symtab_hdr,
  2073. unsigned long r_symndx,
  2074. unsigned int tls_type)
  2075. {
  2076. bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
  2077. unsigned char *local_got_tls_masks;
  2078. if (local_got_refcounts == NULL)
  2079. {
  2080. bfd_size_type size = symtab_hdr->sh_info;
  2081. size *= (sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks));
  2082. local_got_refcounts = bfd_zalloc (abfd, size);
  2083. if (local_got_refcounts == NULL)
  2084. return false;
  2085. elf_local_got_refcounts (abfd) = local_got_refcounts;
  2086. }
  2087. local_got_tls_masks =
  2088. (unsigned char *) (local_got_refcounts + symtab_hdr->sh_info);
  2089. local_got_tls_masks[r_symndx] |= tls_type;
  2090. local_got_refcounts[r_symndx] += 1;
  2091. return true;
  2092. }
  2093. /* Look through the relocs for a section during the first phase. */
  2094. static bool
  2095. microblaze_elf_check_relocs (bfd * abfd,
  2096. struct bfd_link_info * info,
  2097. asection * sec,
  2098. const Elf_Internal_Rela * relocs)
  2099. {
  2100. Elf_Internal_Shdr * symtab_hdr;
  2101. struct elf_link_hash_entry ** sym_hashes;
  2102. const Elf_Internal_Rela * rel;
  2103. const Elf_Internal_Rela * rel_end;
  2104. struct elf32_mb_link_hash_table *htab;
  2105. asection *sreloc = NULL;
  2106. if (bfd_link_relocatable (info))
  2107. return true;
  2108. htab = elf32_mb_hash_table (info);
  2109. if (htab == NULL)
  2110. return false;
  2111. symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
  2112. sym_hashes = elf_sym_hashes (abfd);
  2113. rel_end = relocs + sec->reloc_count;
  2114. for (rel = relocs; rel < rel_end; rel++)
  2115. {
  2116. unsigned int r_type;
  2117. struct elf_link_hash_entry * h;
  2118. unsigned long r_symndx;
  2119. unsigned char tls_type = 0;
  2120. r_symndx = ELF32_R_SYM (rel->r_info);
  2121. r_type = ELF32_R_TYPE (rel->r_info);
  2122. if (r_symndx < symtab_hdr->sh_info)
  2123. h = NULL;
  2124. else
  2125. {
  2126. h = sym_hashes [r_symndx - symtab_hdr->sh_info];
  2127. while (h->root.type == bfd_link_hash_indirect
  2128. || h->root.type == bfd_link_hash_warning)
  2129. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  2130. }
  2131. switch (r_type)
  2132. {
  2133. /* This relocation describes the C++ object vtable hierarchy.
  2134. Reconstruct it for later use during GC. */
  2135. case R_MICROBLAZE_GNU_VTINHERIT:
  2136. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  2137. return false;
  2138. break;
  2139. /* This relocation describes which C++ vtable entries are actually
  2140. used. Record for later use during GC. */
  2141. case R_MICROBLAZE_GNU_VTENTRY:
  2142. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  2143. return false;
  2144. break;
  2145. /* This relocation requires .plt entry. */
  2146. case R_MICROBLAZE_PLT_64:
  2147. if (h != NULL)
  2148. {
  2149. h->needs_plt = 1;
  2150. h->plt.refcount += 1;
  2151. }
  2152. break;
  2153. /* This relocation requires .got entry. */
  2154. case R_MICROBLAZE_TLSGD:
  2155. tls_type |= (TLS_TLS | TLS_GD);
  2156. goto dogottls;
  2157. case R_MICROBLAZE_TLSLD:
  2158. tls_type |= (TLS_TLS | TLS_LD);
  2159. /* Fall through. */
  2160. dogottls:
  2161. sec->has_tls_reloc = 1;
  2162. /* Fall through. */
  2163. case R_MICROBLAZE_GOT_64:
  2164. if (htab->elf.sgot == NULL)
  2165. {
  2166. if (htab->elf.dynobj == NULL)
  2167. htab->elf.dynobj = abfd;
  2168. if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
  2169. return false;
  2170. }
  2171. if (h != NULL)
  2172. {
  2173. h->got.refcount += 1;
  2174. elf32_mb_hash_entry (h)->tls_mask |= tls_type;
  2175. }
  2176. else
  2177. {
  2178. if (! update_local_sym_info(abfd, symtab_hdr, r_symndx, tls_type) )
  2179. return false;
  2180. }
  2181. break;
  2182. case R_MICROBLAZE_GOTOFF_64:
  2183. case R_MICROBLAZE_GOTOFF_32:
  2184. if (htab->elf.sgot == NULL)
  2185. {
  2186. if (htab->elf.dynobj == NULL)
  2187. htab->elf.dynobj = abfd;
  2188. if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
  2189. return false;
  2190. }
  2191. break;
  2192. case R_MICROBLAZE_64:
  2193. case R_MICROBLAZE_64_PCREL:
  2194. case R_MICROBLAZE_32:
  2195. {
  2196. if (h != NULL && !bfd_link_pic (info))
  2197. {
  2198. /* we may need a copy reloc. */
  2199. h->non_got_ref = 1;
  2200. /* we may also need a .plt entry. */
  2201. h->plt.refcount += 1;
  2202. if (ELF32_R_TYPE (rel->r_info) != R_MICROBLAZE_64_PCREL)
  2203. h->pointer_equality_needed = 1;
  2204. }
  2205. /* If we are creating a shared library, and this is a reloc
  2206. against a global symbol, or a non PC relative reloc
  2207. against a local symbol, then we need to copy the reloc
  2208. into the shared library. However, if we are linking with
  2209. -Bsymbolic, we do not need to copy a reloc against a
  2210. global symbol which is defined in an object we are
  2211. including in the link (i.e., DEF_REGULAR is set). At
  2212. this point we have not seen all the input files, so it is
  2213. possible that DEF_REGULAR is not set now but will be set
  2214. later (it is never cleared). In case of a weak definition,
  2215. DEF_REGULAR may be cleared later by a strong definition in
  2216. a shared library. We account for that possibility below by
  2217. storing information in the relocs_copied field of the hash
  2218. table entry. A similar situation occurs when creating
  2219. shared libraries and symbol visibility changes render the
  2220. symbol local.
  2221. If on the other hand, we are creating an executable, we
  2222. may need to keep relocations for symbols satisfied by a
  2223. dynamic library if we manage to avoid copy relocs for the
  2224. symbol. */
  2225. if ((bfd_link_pic (info)
  2226. && (sec->flags & SEC_ALLOC) != 0
  2227. && (r_type != R_MICROBLAZE_64_PCREL
  2228. || (h != NULL
  2229. && (! info->symbolic
  2230. || h->root.type == bfd_link_hash_defweak
  2231. || !h->def_regular))))
  2232. || (!bfd_link_pic (info)
  2233. && (sec->flags & SEC_ALLOC) != 0
  2234. && h != NULL
  2235. && (h->root.type == bfd_link_hash_defweak
  2236. || !h->def_regular)))
  2237. {
  2238. struct elf_dyn_relocs *p;
  2239. struct elf_dyn_relocs **head;
  2240. /* When creating a shared object, we must copy these
  2241. relocs into the output file. We create a reloc
  2242. section in dynobj and make room for the reloc. */
  2243. if (sreloc == NULL)
  2244. {
  2245. bfd *dynobj;
  2246. if (htab->elf.dynobj == NULL)
  2247. htab->elf.dynobj = abfd;
  2248. dynobj = htab->elf.dynobj;
  2249. sreloc = _bfd_elf_make_dynamic_reloc_section (sec, dynobj,
  2250. 2, abfd, 1);
  2251. if (sreloc == NULL)
  2252. return false;
  2253. }
  2254. /* If this is a global symbol, we count the number of
  2255. relocations we need for this symbol. */
  2256. if (h != NULL)
  2257. head = &h->dyn_relocs;
  2258. else
  2259. {
  2260. /* Track dynamic relocs needed for local syms too.
  2261. We really need local syms available to do this
  2262. easily. Oh well. */
  2263. asection *s;
  2264. Elf_Internal_Sym *isym;
  2265. void *vpp;
  2266. isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
  2267. abfd, r_symndx);
  2268. if (isym == NULL)
  2269. return false;
  2270. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  2271. if (s == NULL)
  2272. return false;
  2273. vpp = &elf_section_data (s)->local_dynrel;
  2274. head = (struct elf_dyn_relocs **) vpp;
  2275. }
  2276. p = *head;
  2277. if (p == NULL || p->sec != sec)
  2278. {
  2279. size_t amt = sizeof *p;
  2280. p = ((struct elf_dyn_relocs *)
  2281. bfd_alloc (htab->elf.dynobj, amt));
  2282. if (p == NULL)
  2283. return false;
  2284. p->next = *head;
  2285. *head = p;
  2286. p->sec = sec;
  2287. p->count = 0;
  2288. p->pc_count = 0;
  2289. }
  2290. p->count += 1;
  2291. if (r_type == R_MICROBLAZE_64_PCREL)
  2292. p->pc_count += 1;
  2293. }
  2294. }
  2295. break;
  2296. }
  2297. }
  2298. return true;
  2299. }
  2300. /* Copy the extra info we tack onto an elf_link_hash_entry. */
  2301. static void
  2302. microblaze_elf_copy_indirect_symbol (struct bfd_link_info *info,
  2303. struct elf_link_hash_entry *dir,
  2304. struct elf_link_hash_entry *ind)
  2305. {
  2306. struct elf32_mb_link_hash_entry *edir, *eind;
  2307. edir = (struct elf32_mb_link_hash_entry *) dir;
  2308. eind = (struct elf32_mb_link_hash_entry *) ind;
  2309. edir->tls_mask |= eind->tls_mask;
  2310. _bfd_elf_link_hash_copy_indirect (info, dir, ind);
  2311. }
  2312. static bool
  2313. microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
  2314. struct elf_link_hash_entry *h)
  2315. {
  2316. struct elf32_mb_link_hash_table *htab;
  2317. asection *s, *srel;
  2318. unsigned int power_of_two;
  2319. htab = elf32_mb_hash_table (info);
  2320. if (htab == NULL)
  2321. return false;
  2322. /* If this is a function, put it in the procedure linkage table. We
  2323. will fill in the contents of the procedure linkage table later,
  2324. when we know the address of the .got section. */
  2325. if (h->type == STT_FUNC
  2326. || h->needs_plt)
  2327. {
  2328. if (h->plt.refcount <= 0
  2329. || SYMBOL_CALLS_LOCAL (info, h)
  2330. || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  2331. && h->root.type == bfd_link_hash_undefweak))
  2332. {
  2333. /* This case can occur if we saw a PLT reloc in an input
  2334. file, but the symbol was never referred to by a dynamic
  2335. object, or if all references were garbage collected. In
  2336. such a case, we don't actually need to build a procedure
  2337. linkage table, and we can just do a PC32 reloc instead. */
  2338. h->plt.offset = (bfd_vma) -1;
  2339. h->needs_plt = 0;
  2340. }
  2341. return true;
  2342. }
  2343. else
  2344. /* It's possible that we incorrectly decided a .plt reloc was
  2345. needed for an R_MICROBLAZE_64_PCREL reloc to a non-function sym in
  2346. check_relocs. We can't decide accurately between function and
  2347. non-function syms in check-relocs; Objects loaded later in
  2348. the link may change h->type. So fix it now. */
  2349. h->plt.offset = (bfd_vma) -1;
  2350. /* If this is a weak symbol, and there is a real definition, the
  2351. processor independent code will have arranged for us to see the
  2352. real definition first, and we can just use the same value. */
  2353. if (h->is_weakalias)
  2354. {
  2355. struct elf_link_hash_entry *def = weakdef (h);
  2356. BFD_ASSERT (def->root.type == bfd_link_hash_defined);
  2357. h->root.u.def.section = def->root.u.def.section;
  2358. h->root.u.def.value = def->root.u.def.value;
  2359. return true;
  2360. }
  2361. /* This is a reference to a symbol defined by a dynamic object which
  2362. is not a function. */
  2363. /* If we are creating a shared library, we must presume that the
  2364. only references to the symbol are via the global offset table.
  2365. For such cases we need not do anything here; the relocations will
  2366. be handled correctly by relocate_section. */
  2367. if (bfd_link_pic (info))
  2368. return true;
  2369. /* If there are no references to this symbol that do not use the
  2370. GOT, we don't need to generate a copy reloc. */
  2371. if (!h->non_got_ref)
  2372. return true;
  2373. /* If -z nocopyreloc was given, we won't generate them either. */
  2374. if (info->nocopyreloc)
  2375. {
  2376. h->non_got_ref = 0;
  2377. return true;
  2378. }
  2379. /* If we don't find any dynamic relocs in read-only sections, then
  2380. we'll be keeping the dynamic relocs and avoiding the copy reloc. */
  2381. if (!_bfd_elf_readonly_dynrelocs (h))
  2382. {
  2383. h->non_got_ref = 0;
  2384. return true;
  2385. }
  2386. /* We must allocate the symbol in our .dynbss section, which will
  2387. become part of the .bss section of the executable. There will be
  2388. an entry for this symbol in the .dynsym section. The dynamic
  2389. object will contain position independent code, so all references
  2390. from the dynamic object to this symbol will go through the global
  2391. offset table. The dynamic linker will use the .dynsym entry to
  2392. determine the address it must put in the global offset table, so
  2393. both the dynamic object and the regular object will refer to the
  2394. same memory location for the variable. */
  2395. /* We must generate a R_MICROBLAZE_COPY reloc to tell the dynamic linker
  2396. to copy the initial value out of the dynamic object and into the
  2397. runtime process image. */
  2398. if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
  2399. {
  2400. s = htab->elf.sdynrelro;
  2401. srel = htab->elf.sreldynrelro;
  2402. }
  2403. else
  2404. {
  2405. s = htab->elf.sdynbss;
  2406. srel = htab->elf.srelbss;
  2407. }
  2408. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
  2409. {
  2410. srel->size += sizeof (Elf32_External_Rela);
  2411. h->needs_copy = 1;
  2412. }
  2413. /* We need to figure out the alignment required for this symbol. I
  2414. have no idea how ELF linkers handle this. */
  2415. power_of_two = bfd_log2 (h->size);
  2416. if (power_of_two > 3)
  2417. power_of_two = 3;
  2418. /* Apply the required alignment. */
  2419. s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
  2420. if (power_of_two > s->alignment_power)
  2421. {
  2422. if (!bfd_set_section_alignment (s, power_of_two))
  2423. return false;
  2424. }
  2425. /* Define the symbol as being at this point in the section. */
  2426. h->root.u.def.section = s;
  2427. h->root.u.def.value = s->size;
  2428. /* Increment the section size to make room for the symbol. */
  2429. s->size += h->size;
  2430. return true;
  2431. }
  2432. /* Allocate space in .plt, .got and associated reloc sections for
  2433. dynamic relocs. */
  2434. static bool
  2435. allocate_dynrelocs (struct elf_link_hash_entry *h, void * dat)
  2436. {
  2437. struct bfd_link_info *info;
  2438. struct elf32_mb_link_hash_table *htab;
  2439. struct elf32_mb_link_hash_entry *eh;
  2440. struct elf_dyn_relocs *p;
  2441. if (h->root.type == bfd_link_hash_indirect)
  2442. return true;
  2443. info = (struct bfd_link_info *) dat;
  2444. htab = elf32_mb_hash_table (info);
  2445. if (htab == NULL)
  2446. return false;
  2447. if (htab->elf.dynamic_sections_created
  2448. && h->plt.refcount > 0)
  2449. {
  2450. /* Make sure this symbol is output as a dynamic symbol.
  2451. Undefined weak syms won't yet be marked as dynamic. */
  2452. if (h->dynindx == -1
  2453. && !h->forced_local)
  2454. {
  2455. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2456. return false;
  2457. }
  2458. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
  2459. {
  2460. asection *s = htab->elf.splt;
  2461. /* The first entry in .plt is reserved. */
  2462. if (s->size == 0)
  2463. s->size = PLT_ENTRY_SIZE;
  2464. h->plt.offset = s->size;
  2465. /* If this symbol is not defined in a regular file, and we are
  2466. not generating a shared library, then set the symbol to this
  2467. location in the .plt. This is required to make function
  2468. pointers compare as equal between the normal executable and
  2469. the shared library. */
  2470. if (! bfd_link_pic (info)
  2471. && !h->def_regular)
  2472. {
  2473. h->root.u.def.section = s;
  2474. h->root.u.def.value = h->plt.offset;
  2475. }
  2476. /* Make room for this entry. */
  2477. s->size += PLT_ENTRY_SIZE;
  2478. /* We also need to make an entry in the .got.plt section, which
  2479. will be placed in the .got section by the linker script. */
  2480. htab->elf.sgotplt->size += 4;
  2481. /* We also need to make an entry in the .rel.plt section. */
  2482. htab->elf.srelplt->size += sizeof (Elf32_External_Rela);
  2483. }
  2484. else
  2485. {
  2486. h->plt.offset = (bfd_vma) -1;
  2487. h->needs_plt = 0;
  2488. }
  2489. }
  2490. else
  2491. {
  2492. h->plt.offset = (bfd_vma) -1;
  2493. h->needs_plt = 0;
  2494. }
  2495. eh = (struct elf32_mb_link_hash_entry *) h;
  2496. if (h->got.refcount > 0)
  2497. {
  2498. unsigned int need;
  2499. asection *s;
  2500. /* Make sure this symbol is output as a dynamic symbol.
  2501. Undefined weak syms won't yet be marked as dynamic. */
  2502. if (h->dynindx == -1
  2503. && !h->forced_local)
  2504. {
  2505. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2506. return false;
  2507. }
  2508. need = 0;
  2509. if ((eh->tls_mask & TLS_TLS) != 0)
  2510. {
  2511. /* Handle TLS Symbol */
  2512. if ((eh->tls_mask & TLS_LD) != 0)
  2513. {
  2514. if (!eh->elf.def_dynamic)
  2515. /* We'll just use htab->tlsld_got.offset. This should
  2516. always be the case. It's a little odd if we have
  2517. a local dynamic reloc against a non-local symbol. */
  2518. htab->tlsld_got.refcount += 1;
  2519. else
  2520. need += 8;
  2521. }
  2522. if ((eh->tls_mask & TLS_GD) != 0)
  2523. need += 8;
  2524. }
  2525. else
  2526. {
  2527. /* Regular (non-TLS) symbol */
  2528. need += 4;
  2529. }
  2530. if (need == 0)
  2531. {
  2532. h->got.offset = (bfd_vma) -1;
  2533. }
  2534. else
  2535. {
  2536. s = htab->elf.sgot;
  2537. h->got.offset = s->size;
  2538. s->size += need;
  2539. htab->elf.srelgot->size += need * (sizeof (Elf32_External_Rela) / 4);
  2540. }
  2541. }
  2542. else
  2543. h->got.offset = (bfd_vma) -1;
  2544. if (h->dyn_relocs == NULL)
  2545. return true;
  2546. /* In the shared -Bsymbolic case, discard space allocated for
  2547. dynamic pc-relative relocs against symbols which turn out to be
  2548. defined in regular objects. For the normal shared case, discard
  2549. space for pc-relative relocs that have become local due to symbol
  2550. visibility changes. */
  2551. if (bfd_link_pic (info))
  2552. {
  2553. if (h->def_regular
  2554. && (h->forced_local
  2555. || info->symbolic))
  2556. {
  2557. struct elf_dyn_relocs **pp;
  2558. for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
  2559. {
  2560. p->count -= p->pc_count;
  2561. p->pc_count = 0;
  2562. if (p->count == 0)
  2563. *pp = p->next;
  2564. else
  2565. pp = &p->next;
  2566. }
  2567. }
  2568. else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
  2569. h->dyn_relocs = NULL;
  2570. }
  2571. else
  2572. {
  2573. /* For the non-shared case, discard space for relocs against
  2574. symbols which turn out to need copy relocs or are not
  2575. dynamic. */
  2576. if (!h->non_got_ref
  2577. && ((h->def_dynamic
  2578. && !h->def_regular)
  2579. || (htab->elf.dynamic_sections_created
  2580. && (h->root.type == bfd_link_hash_undefweak
  2581. || h->root.type == bfd_link_hash_undefined))))
  2582. {
  2583. /* Make sure this symbol is output as a dynamic symbol.
  2584. Undefined weak syms won't yet be marked as dynamic. */
  2585. if (h->dynindx == -1
  2586. && !h->forced_local)
  2587. {
  2588. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2589. return false;
  2590. }
  2591. /* If that succeeded, we know we'll be keeping all the
  2592. relocs. */
  2593. if (h->dynindx != -1)
  2594. goto keep;
  2595. }
  2596. h->dyn_relocs = NULL;
  2597. keep: ;
  2598. }
  2599. /* Finally, allocate space. */
  2600. for (p = h->dyn_relocs; p != NULL; p = p->next)
  2601. {
  2602. asection *sreloc = elf_section_data (p->sec)->sreloc;
  2603. sreloc->size += p->count * sizeof (Elf32_External_Rela);
  2604. }
  2605. return true;
  2606. }
  2607. /* Set the sizes of the dynamic sections. */
  2608. static bool
  2609. microblaze_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  2610. struct bfd_link_info *info)
  2611. {
  2612. struct elf32_mb_link_hash_table *htab;
  2613. bfd *dynobj;
  2614. asection *s;
  2615. bfd *ibfd;
  2616. htab = elf32_mb_hash_table (info);
  2617. if (htab == NULL)
  2618. return false;
  2619. dynobj = htab->elf.dynobj;
  2620. BFD_ASSERT (dynobj != NULL);
  2621. /* Set up .got offsets for local syms, and space for local dynamic
  2622. relocs. */
  2623. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  2624. {
  2625. bfd_signed_vma *local_got;
  2626. bfd_signed_vma *end_local_got;
  2627. bfd_size_type locsymcount;
  2628. Elf_Internal_Shdr *symtab_hdr;
  2629. unsigned char *lgot_masks;
  2630. asection *srel;
  2631. if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
  2632. continue;
  2633. for (s = ibfd->sections; s != NULL; s = s->next)
  2634. {
  2635. struct elf_dyn_relocs *p;
  2636. for (p = ((struct elf_dyn_relocs *)
  2637. elf_section_data (s)->local_dynrel);
  2638. p != NULL;
  2639. p = p->next)
  2640. {
  2641. if (!bfd_is_abs_section (p->sec)
  2642. && bfd_is_abs_section (p->sec->output_section))
  2643. {
  2644. /* Input section has been discarded, either because
  2645. it is a copy of a linkonce section or due to
  2646. linker script /DISCARD/, so we'll be discarding
  2647. the relocs too. */
  2648. }
  2649. else if (p->count != 0)
  2650. {
  2651. srel = elf_section_data (p->sec)->sreloc;
  2652. srel->size += p->count * sizeof (Elf32_External_Rela);
  2653. if ((p->sec->output_section->flags & SEC_READONLY) != 0)
  2654. info->flags |= DF_TEXTREL;
  2655. }
  2656. }
  2657. }
  2658. local_got = elf_local_got_refcounts (ibfd);
  2659. if (!local_got)
  2660. continue;
  2661. symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
  2662. locsymcount = symtab_hdr->sh_info;
  2663. end_local_got = local_got + locsymcount;
  2664. lgot_masks = (unsigned char *) end_local_got;
  2665. s = htab->elf.sgot;
  2666. srel = htab->elf.srelgot;
  2667. for (; local_got < end_local_got; ++local_got, ++lgot_masks)
  2668. {
  2669. if (*local_got > 0)
  2670. {
  2671. unsigned int need = 0;
  2672. if ((*lgot_masks & TLS_TLS) != 0)
  2673. {
  2674. if ((*lgot_masks & TLS_GD) != 0)
  2675. need += 8;
  2676. if ((*lgot_masks & TLS_LD) != 0)
  2677. htab->tlsld_got.refcount += 1;
  2678. }
  2679. else
  2680. need += 4;
  2681. if (need == 0)
  2682. {
  2683. *local_got = (bfd_vma) -1;
  2684. }
  2685. else
  2686. {
  2687. *local_got = s->size;
  2688. s->size += need;
  2689. if (bfd_link_pic (info))
  2690. srel->size += need * (sizeof (Elf32_External_Rela) / 4);
  2691. }
  2692. }
  2693. else
  2694. *local_got = (bfd_vma) -1;
  2695. }
  2696. }
  2697. /* Allocate global sym .plt and .got entries, and space for global
  2698. sym dynamic relocs. */
  2699. elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
  2700. if (htab->tlsld_got.refcount > 0)
  2701. {
  2702. htab->tlsld_got.offset = htab->elf.sgot->size;
  2703. htab->elf.sgot->size += 8;
  2704. if (bfd_link_pic (info))
  2705. htab->elf.srelgot->size += sizeof (Elf32_External_Rela);
  2706. }
  2707. else
  2708. htab->tlsld_got.offset = (bfd_vma) -1;
  2709. if (elf_hash_table (info)->dynamic_sections_created)
  2710. {
  2711. /* Make space for the trailing nop in .plt. */
  2712. if (htab->elf.splt->size > 0)
  2713. htab->elf.splt->size += 4;
  2714. }
  2715. /* The check_relocs and adjust_dynamic_symbol entry points have
  2716. determined the sizes of the various dynamic sections. Allocate
  2717. memory for them. */
  2718. for (s = dynobj->sections; s != NULL; s = s->next)
  2719. {
  2720. const char *name;
  2721. bool strip = false;
  2722. if ((s->flags & SEC_LINKER_CREATED) == 0)
  2723. continue;
  2724. /* It's OK to base decisions on the section name, because none
  2725. of the dynobj section names depend upon the input files. */
  2726. name = bfd_section_name (s);
  2727. if (startswith (name, ".rela"))
  2728. {
  2729. if (s->size == 0)
  2730. {
  2731. /* If we don't need this section, strip it from the
  2732. output file. This is to handle .rela.bss and
  2733. .rela.plt. We must create it in
  2734. create_dynamic_sections, because it must be created
  2735. before the linker maps input sections to output
  2736. sections. The linker does that before
  2737. adjust_dynamic_symbol is called, and it is that
  2738. function which decides whether anything needs to go
  2739. into these sections. */
  2740. strip = true;
  2741. }
  2742. else
  2743. {
  2744. /* We use the reloc_count field as a counter if we need
  2745. to copy relocs into the output file. */
  2746. s->reloc_count = 0;
  2747. }
  2748. }
  2749. else if (s != htab->elf.splt
  2750. && s != htab->elf.sgot
  2751. && s != htab->elf.sgotplt
  2752. && s != htab->elf.sdynbss
  2753. && s != htab->elf.sdynrelro)
  2754. {
  2755. /* It's not one of our sections, so don't allocate space. */
  2756. continue;
  2757. }
  2758. if (strip)
  2759. {
  2760. s->flags |= SEC_EXCLUDE;
  2761. continue;
  2762. }
  2763. /* Allocate memory for the section contents. */
  2764. /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
  2765. Unused entries should be reclaimed before the section's contents
  2766. are written out, but at the moment this does not happen. Thus in
  2767. order to prevent writing out garbage, we initialise the section's
  2768. contents to zero. */
  2769. s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
  2770. if (s->contents == NULL && s->size != 0)
  2771. return false;
  2772. }
  2773. /* ??? Force DF_BIND_NOW? */
  2774. info->flags |= DF_BIND_NOW;
  2775. return _bfd_elf_add_dynamic_tags (output_bfd, info, true);
  2776. }
  2777. /* Finish up dynamic symbol handling. We set the contents of various
  2778. dynamic sections here. */
  2779. static bool
  2780. microblaze_elf_finish_dynamic_symbol (bfd *output_bfd,
  2781. struct bfd_link_info *info,
  2782. struct elf_link_hash_entry *h,
  2783. Elf_Internal_Sym *sym)
  2784. {
  2785. struct elf32_mb_link_hash_table *htab;
  2786. struct elf32_mb_link_hash_entry *eh = elf32_mb_hash_entry(h);
  2787. htab = elf32_mb_hash_table (info);
  2788. if (htab == NULL)
  2789. return false;
  2790. if (h->plt.offset != (bfd_vma) -1)
  2791. {
  2792. asection *splt;
  2793. asection *srela;
  2794. asection *sgotplt;
  2795. Elf_Internal_Rela rela;
  2796. bfd_byte *loc;
  2797. bfd_vma plt_index;
  2798. bfd_vma got_offset;
  2799. bfd_vma got_addr;
  2800. /* This symbol has an entry in the procedure linkage table. Set
  2801. it up. */
  2802. BFD_ASSERT (h->dynindx != -1);
  2803. splt = htab->elf.splt;
  2804. srela = htab->elf.srelplt;
  2805. sgotplt = htab->elf.sgotplt;
  2806. BFD_ASSERT (splt != NULL && srela != NULL && sgotplt != NULL);
  2807. plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1; /* first entry reserved. */
  2808. got_offset = (plt_index + 3) * 4; /* 3 reserved ??? */
  2809. got_addr = got_offset;
  2810. /* For non-PIC objects we need absolute address of the GOT entry. */
  2811. if (!bfd_link_pic (info))
  2812. got_addr += sgotplt->output_section->vma + sgotplt->output_offset;
  2813. /* Fill in the entry in the procedure linkage table. */
  2814. bfd_put_32 (output_bfd, PLT_ENTRY_WORD_0 + ((got_addr >> 16) & 0xffff),
  2815. splt->contents + h->plt.offset);
  2816. if (bfd_link_pic (info))
  2817. bfd_put_32 (output_bfd, PLT_ENTRY_WORD_1 + (got_addr & 0xffff),
  2818. splt->contents + h->plt.offset + 4);
  2819. else
  2820. bfd_put_32 (output_bfd, PLT_ENTRY_WORD_1_NOPIC + (got_addr & 0xffff),
  2821. splt->contents + h->plt.offset + 4);
  2822. bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD_2,
  2823. splt->contents + h->plt.offset + 8);
  2824. bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD_3,
  2825. splt->contents + h->plt.offset + 12);
  2826. /* Any additions to the .got section??? */
  2827. /* bfd_put_32 (output_bfd,
  2828. splt->output_section->vma + splt->output_offset + h->plt.offset + 4,
  2829. sgotplt->contents + got_offset); */
  2830. /* Fill in the entry in the .rela.plt section. */
  2831. rela.r_offset = (sgotplt->output_section->vma
  2832. + sgotplt->output_offset
  2833. + got_offset);
  2834. rela.r_info = ELF32_R_INFO (h->dynindx, R_MICROBLAZE_JUMP_SLOT);
  2835. rela.r_addend = 0;
  2836. loc = srela->contents;
  2837. loc += plt_index * sizeof (Elf32_External_Rela);
  2838. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  2839. if (!h->def_regular)
  2840. {
  2841. /* Mark the symbol as undefined, rather than as defined in
  2842. the .plt section. Zero the value. */
  2843. sym->st_shndx = SHN_UNDEF;
  2844. sym->st_value = 0;
  2845. }
  2846. }
  2847. /* h->got.refcount to be checked ? */
  2848. if (h->got.offset != (bfd_vma) -1 &&
  2849. ! ((h->got.offset & 1) ||
  2850. IS_TLS_LD(eh->tls_mask) || IS_TLS_GD(eh->tls_mask)))
  2851. {
  2852. asection *sgot;
  2853. asection *srela;
  2854. bfd_vma offset;
  2855. /* This symbol has an entry in the global offset table. Set it
  2856. up. */
  2857. sgot = htab->elf.sgot;
  2858. srela = htab->elf.srelgot;
  2859. BFD_ASSERT (sgot != NULL && srela != NULL);
  2860. offset = (sgot->output_section->vma + sgot->output_offset
  2861. + (h->got.offset &~ (bfd_vma) 1));
  2862. /* If this is a -Bsymbolic link, and the symbol is defined
  2863. locally, we just want to emit a RELATIVE reloc. Likewise if
  2864. the symbol was forced to be local because of a version file.
  2865. The entry in the global offset table will already have been
  2866. initialized in the relocate_section function. */
  2867. if (bfd_link_pic (info)
  2868. && ((info->symbolic && h->def_regular)
  2869. || h->dynindx == -1))
  2870. {
  2871. asection *sec = h->root.u.def.section;
  2872. bfd_vma value;
  2873. value = h->root.u.def.value;
  2874. if (sec->output_section != NULL)
  2875. /* PR 21180: If the output section is NULL, then the symbol is no
  2876. longer needed, and in theory the GOT entry is redundant. But
  2877. it is too late to change our minds now... */
  2878. value += sec->output_section->vma + sec->output_offset;
  2879. microblaze_elf_output_dynamic_relocation (output_bfd,
  2880. srela, srela->reloc_count++,
  2881. /* symindex= */ 0,
  2882. R_MICROBLAZE_REL, offset,
  2883. value);
  2884. }
  2885. else
  2886. {
  2887. microblaze_elf_output_dynamic_relocation (output_bfd,
  2888. srela, srela->reloc_count++,
  2889. h->dynindx,
  2890. R_MICROBLAZE_GLOB_DAT,
  2891. offset, 0);
  2892. }
  2893. bfd_put_32 (output_bfd, (bfd_vma) 0,
  2894. sgot->contents + (h->got.offset &~ (bfd_vma) 1));
  2895. }
  2896. if (h->needs_copy)
  2897. {
  2898. asection *s;
  2899. Elf_Internal_Rela rela;
  2900. bfd_byte *loc;
  2901. /* This symbols needs a copy reloc. Set it up. */
  2902. BFD_ASSERT (h->dynindx != -1);
  2903. rela.r_offset = (h->root.u.def.value
  2904. + h->root.u.def.section->output_section->vma
  2905. + h->root.u.def.section->output_offset);
  2906. rela.r_info = ELF32_R_INFO (h->dynindx, R_MICROBLAZE_COPY);
  2907. rela.r_addend = 0;
  2908. if (h->root.u.def.section == htab->elf.sdynrelro)
  2909. s = htab->elf.sreldynrelro;
  2910. else
  2911. s = htab->elf.srelbss;
  2912. loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
  2913. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  2914. }
  2915. /* Mark some specially defined symbols as absolute. */
  2916. if (h == htab->elf.hdynamic
  2917. || h == htab->elf.hgot
  2918. || h == htab->elf.hplt)
  2919. sym->st_shndx = SHN_ABS;
  2920. return true;
  2921. }
  2922. /* Finish up the dynamic sections. */
  2923. static bool
  2924. microblaze_elf_finish_dynamic_sections (bfd *output_bfd,
  2925. struct bfd_link_info *info)
  2926. {
  2927. bfd *dynobj;
  2928. asection *sdyn, *sgot;
  2929. struct elf32_mb_link_hash_table *htab;
  2930. htab = elf32_mb_hash_table (info);
  2931. if (htab == NULL)
  2932. return false;
  2933. dynobj = htab->elf.dynobj;
  2934. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  2935. if (htab->elf.dynamic_sections_created)
  2936. {
  2937. asection *splt;
  2938. Elf32_External_Dyn *dyncon, *dynconend;
  2939. dyncon = (Elf32_External_Dyn *) sdyn->contents;
  2940. dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
  2941. for (; dyncon < dynconend; dyncon++)
  2942. {
  2943. Elf_Internal_Dyn dyn;
  2944. asection *s;
  2945. bool size;
  2946. bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
  2947. switch (dyn.d_tag)
  2948. {
  2949. case DT_PLTGOT:
  2950. s = htab->elf.sgotplt;
  2951. size = false;
  2952. break;
  2953. case DT_PLTRELSZ:
  2954. s = htab->elf.srelplt;
  2955. size = true;
  2956. break;
  2957. case DT_JMPREL:
  2958. s = htab->elf.srelplt;
  2959. size = false;
  2960. break;
  2961. default:
  2962. continue;
  2963. }
  2964. if (s == NULL)
  2965. dyn.d_un.d_val = 0;
  2966. else
  2967. {
  2968. if (!size)
  2969. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  2970. else
  2971. dyn.d_un.d_val = s->size;
  2972. }
  2973. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  2974. }
  2975. splt = htab->elf.splt;
  2976. BFD_ASSERT (splt != NULL && sdyn != NULL);
  2977. /* Clear the first entry in the procedure linkage table,
  2978. and put a nop in the last four bytes. */
  2979. if (splt->size > 0)
  2980. {
  2981. memset (splt->contents, 0, PLT_ENTRY_SIZE);
  2982. bfd_put_32 (output_bfd, (bfd_vma) 0x80000000 /* nop. */,
  2983. splt->contents + splt->size - 4);
  2984. if (splt->output_section != bfd_abs_section_ptr)
  2985. elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
  2986. }
  2987. }
  2988. /* Set the first entry in the global offset table to the address of
  2989. the dynamic section. */
  2990. sgot = htab->elf.sgotplt;
  2991. if (sgot && sgot->size > 0)
  2992. {
  2993. if (sdyn == NULL)
  2994. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
  2995. else
  2996. bfd_put_32 (output_bfd,
  2997. sdyn->output_section->vma + sdyn->output_offset,
  2998. sgot->contents);
  2999. elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
  3000. }
  3001. if (htab->elf.sgot && htab->elf.sgot->size > 0)
  3002. elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 4;
  3003. return true;
  3004. }
  3005. /* Hook called by the linker routine which adds symbols from an object
  3006. file. We use it to put .comm items in .sbss, and not .bss. */
  3007. static bool
  3008. microblaze_elf_add_symbol_hook (bfd *abfd,
  3009. struct bfd_link_info *info,
  3010. Elf_Internal_Sym *sym,
  3011. const char **namep ATTRIBUTE_UNUSED,
  3012. flagword *flagsp ATTRIBUTE_UNUSED,
  3013. asection **secp,
  3014. bfd_vma *valp)
  3015. {
  3016. if (sym->st_shndx == SHN_COMMON
  3017. && !bfd_link_relocatable (info)
  3018. && sym->st_size <= elf_gp_size (abfd))
  3019. {
  3020. /* Common symbols less than or equal to -G nn bytes are automatically
  3021. put into .sbss. */
  3022. *secp = bfd_make_section_old_way (abfd, ".sbss");
  3023. if (*secp == NULL
  3024. || !bfd_set_section_flags (*secp, SEC_IS_COMMON | SEC_SMALL_DATA))
  3025. return false;
  3026. *valp = sym->st_size;
  3027. }
  3028. return true;
  3029. }
  3030. #define TARGET_LITTLE_SYM microblaze_elf32_le_vec
  3031. #define TARGET_LITTLE_NAME "elf32-microblazeel"
  3032. #define TARGET_BIG_SYM microblaze_elf32_vec
  3033. #define TARGET_BIG_NAME "elf32-microblaze"
  3034. #define ELF_ARCH bfd_arch_microblaze
  3035. #define ELF_TARGET_ID MICROBLAZE_ELF_DATA
  3036. #define ELF_MACHINE_CODE EM_MICROBLAZE
  3037. #define ELF_MACHINE_ALT1 EM_MICROBLAZE_OLD
  3038. #define ELF_MAXPAGESIZE 0x1000
  3039. #define elf_info_to_howto microblaze_elf_info_to_howto
  3040. #define elf_info_to_howto_rel NULL
  3041. #define bfd_elf32_bfd_reloc_type_lookup microblaze_elf_reloc_type_lookup
  3042. #define bfd_elf32_bfd_is_local_label_name microblaze_elf_is_local_label_name
  3043. #define bfd_elf32_new_section_hook microblaze_elf_new_section_hook
  3044. #define elf_backend_relocate_section microblaze_elf_relocate_section
  3045. #define bfd_elf32_bfd_relax_section microblaze_elf_relax_section
  3046. #define bfd_elf32_bfd_merge_private_bfd_data _bfd_generic_verify_endian_match
  3047. #define bfd_elf32_bfd_reloc_name_lookup microblaze_elf_reloc_name_lookup
  3048. #define elf_backend_gc_mark_hook microblaze_elf_gc_mark_hook
  3049. #define elf_backend_check_relocs microblaze_elf_check_relocs
  3050. #define elf_backend_copy_indirect_symbol microblaze_elf_copy_indirect_symbol
  3051. #define bfd_elf32_bfd_link_hash_table_create microblaze_elf_link_hash_table_create
  3052. #define elf_backend_can_gc_sections 1
  3053. #define elf_backend_can_refcount 1
  3054. #define elf_backend_want_got_plt 1
  3055. #define elf_backend_plt_readonly 1
  3056. #define elf_backend_got_header_size 12
  3057. #define elf_backend_want_dynrelro 1
  3058. #define elf_backend_rela_normal 1
  3059. #define elf_backend_dtrel_excludes_plt 1
  3060. #define elf_backend_adjust_dynamic_symbol microblaze_elf_adjust_dynamic_symbol
  3061. #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
  3062. #define elf_backend_finish_dynamic_sections microblaze_elf_finish_dynamic_sections
  3063. #define elf_backend_finish_dynamic_symbol microblaze_elf_finish_dynamic_symbol
  3064. #define elf_backend_size_dynamic_sections microblaze_elf_size_dynamic_sections
  3065. #define elf_backend_add_symbol_hook microblaze_elf_add_symbol_hook
  3066. #include "elf32-target.h"