elf32-or1k.c 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416
  1. /* Or1k-specific support for 32-bit ELF.
  2. Copyright (C) 2001-2022 Free Software Foundation, Inc.
  3. Contributed for OR32 by Johan Rydberg, jrydberg@opencores.org
  4. PIC parts added by Stefan Kristiansson, stefan.kristiansson@saunalahti.fi,
  5. largely based on elf32-m32r.c and elf32-microblaze.c.
  6. This file is part of BFD, the Binary File Descriptor library.
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 3 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, see <http://www.gnu.org/licenses/>. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "libbfd.h"
  20. #include "elf-bfd.h"
  21. #include "elf/or1k.h"
  22. #include "libiberty.h"
  23. #define N_ONES(X) (((bfd_vma)2 << (X)) - 1)
  24. #define PLT_ENTRY_SIZE 16
  25. #define PLT_ENTRY_SIZE_LARGE (6*4)
  26. #define PLT_MAX_INSN_COUNT 6
  27. #define OR1K_MOVHI(D) (0x18000000 | (D << 21))
  28. #define OR1K_ADRP(D) (0x08000000 | (D << 21))
  29. #define OR1K_LWZ(D,A) (0x84000000 | (D << 21) | (A << 16))
  30. #define OR1K_ADD(D,A,B) (0xE0000000 | (D << 21) | (A << 16) | (B << 11))
  31. #define OR1K_ORI(D,A) (0xA8000000 | (D << 21) | (A << 16))
  32. #define OR1K_ORI0(D) (0xA8000000 | (D << 21))
  33. #define OR1K_JR(B) (0x44000000 | (B << 11))
  34. #define OR1K_NOP 0x15000000
  35. #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
  36. static reloc_howto_type or1k_elf_howto_table[] =
  37. {
  38. /* This reloc does nothing. */
  39. HOWTO (R_OR1K_NONE, /* type */
  40. 0, /* rightshift */
  41. 3, /* size (0 = byte, 1 = short, 2 = long) */
  42. 0, /* bitsize */
  43. false, /* pc_relative */
  44. 0, /* bitpos */
  45. complain_overflow_dont, /* complain_on_overflow */
  46. bfd_elf_generic_reloc, /* special_function */
  47. "R_OR1K_NONE", /* name */
  48. false, /* partial_inplace */
  49. 0, /* src_mask */
  50. 0, /* dst_mask */
  51. false), /* pcrel_offset */
  52. HOWTO (R_OR1K_32,
  53. 0, /* rightshift */
  54. 2, /* size (0 = byte, 1 = short, 2 = long) */
  55. 32, /* bitsize */
  56. false, /* pc_relative */
  57. 0, /* bitpos */
  58. complain_overflow_unsigned, /* complain_on_overflow */
  59. bfd_elf_generic_reloc, /* special_function */
  60. "R_OR1K_32", /* name */
  61. false, /* partial_inplace */
  62. 0, /* src_mask */
  63. 0xffffffff, /* dst_mask */
  64. false), /* pcrel_offset */
  65. HOWTO (R_OR1K_16,
  66. 0, /* rightshift */
  67. 1, /* size (0 = byte, 1 = short, 2 = long) */
  68. 16, /* bitsize */
  69. false, /* pc_relative */
  70. 0, /* bitpos */
  71. complain_overflow_unsigned, /* complain_on_overflow */
  72. bfd_elf_generic_reloc, /* special_function */
  73. "R_OR1K_16", /* name */
  74. false, /* partial_inplace */
  75. 0, /* src_mask */
  76. 0xffff, /* dst_mask */
  77. false), /* pcrel_offset */
  78. HOWTO (R_OR1K_8,
  79. 0, /* rightshift */
  80. 0, /* size (0 = byte, 1 = short, 2 = long) */
  81. 8, /* bitsize */
  82. false, /* pc_relative */
  83. 0, /* bitpos */
  84. complain_overflow_unsigned, /* complain_on_overflow */
  85. bfd_elf_generic_reloc, /* special_function */
  86. "R_OR1K_8", /* name */
  87. false, /* partial_inplace */
  88. 0, /* src_mask */
  89. 0xff, /* dst_mask */
  90. false), /* pcrel_offset */
  91. HOWTO (R_OR1K_LO_16_IN_INSN, /* type */
  92. 0, /* rightshift */
  93. 2, /* size (0 = byte, 1 = short, 2 = long) */
  94. 16, /* bitsize */
  95. false, /* pc_relative */
  96. 0, /* bitpos */
  97. complain_overflow_dont, /* complain_on_overflow */
  98. bfd_elf_generic_reloc, /* special_function */
  99. "R_OR1K_LO_16_IN_INSN", /* name */
  100. false, /* partial_inplace */
  101. 0, /* src_mask */
  102. 0x0000ffff, /* dst_mask */
  103. false), /* pcrel_offset */
  104. HOWTO (R_OR1K_HI_16_IN_INSN, /* type */
  105. 16, /* rightshift */
  106. 2, /* size (0 = byte, 1 = short, 2 = long) */
  107. 16, /* bitsize */
  108. false, /* pc_relative */
  109. 0, /* bitpos */
  110. complain_overflow_dont, /* complain_on_overflow */
  111. bfd_elf_generic_reloc, /* special_function */
  112. "R_OR1K_HI_16_IN_INSN", /* name */
  113. false, /* partial_inplace */
  114. 0, /* src_mask */
  115. 0x0000ffff, /* dst_mask */
  116. false), /* pcrel_offset */
  117. /* A PC relative 26 bit relocation, right shifted by 2. */
  118. HOWTO (R_OR1K_INSN_REL_26, /* type */
  119. 2, /* rightshift */
  120. 2, /* size (0 = byte, 1 = short, 2 = long) */
  121. 26, /* bitsize */
  122. true, /* pc_relative */
  123. 0, /* bitpos */
  124. complain_overflow_signed, /* complain_on_overflow */
  125. bfd_elf_generic_reloc, /* special_function */
  126. "R_OR1K_INSN_REL_26", /* name */
  127. false, /* partial_inplace */
  128. 0, /* src_mask */
  129. 0x03ffffff, /* dst_mask */
  130. true), /* pcrel_offset */
  131. /* GNU extension to record C++ vtable hierarchy. */
  132. HOWTO (R_OR1K_GNU_VTINHERIT, /* type */
  133. 0, /* rightshift */
  134. 2, /* size (0 = byte, 1 = short, 2 = long) */
  135. 0, /* bitsize */
  136. false, /* pc_relative */
  137. 0, /* bitpos */
  138. complain_overflow_dont, /* complain_on_overflow */
  139. NULL, /* special_function */
  140. "R_OR1K_GNU_VTINHERIT", /* name */
  141. false, /* partial_inplace */
  142. 0, /* src_mask */
  143. 0, /* dst_mask */
  144. false), /* pcrel_offset */
  145. /* GNU extension to record C++ vtable member usage. */
  146. HOWTO (R_OR1K_GNU_VTENTRY, /* type */
  147. 0, /* rightshift */
  148. 2, /* size (0 = byte, 1 = short, 2 = long) */
  149. 0, /* bitsize */
  150. false, /* pc_relative */
  151. 0, /* bitpos */
  152. complain_overflow_dont, /* complain_on_overflow */
  153. _bfd_elf_rel_vtable_reloc_fn, /* special_function */
  154. "R_OR1K_GNU_VTENTRY", /* name */
  155. false, /* partial_inplace */
  156. 0, /* src_mask */
  157. 0, /* dst_mask */
  158. false), /* pcrel_offset */
  159. HOWTO (R_OR1K_32_PCREL,
  160. 0, /* rightshift */
  161. 2, /* size (0 = byte, 1 = short, 2 = long) */
  162. 32, /* bitsize */
  163. true, /* pc_relative */
  164. 0, /* bitpos */
  165. complain_overflow_signed, /* complain_on_overflow */
  166. bfd_elf_generic_reloc, /* special_function */
  167. "R_OR1K_32_PCREL", /* name */
  168. false, /* partial_inplace */
  169. 0, /* src_mask */
  170. 0xffffffff, /* dst_mask */
  171. true), /* pcrel_offset */
  172. HOWTO (R_OR1K_16_PCREL,
  173. 0, /* rightshift */
  174. 1, /* size (0 = byte, 1 = short, 2 = long) */
  175. 16, /* bitsize */
  176. true, /* pc_relative */
  177. 0, /* bitpos */
  178. complain_overflow_signed, /* complain_on_overflow */
  179. bfd_elf_generic_reloc, /* special_function */
  180. "R_OR1K_16_PCREL", /* name */
  181. false, /* partial_inplace */
  182. 0, /* src_mask */
  183. 0xffff, /* dst_mask */
  184. true), /* pcrel_offset */
  185. HOWTO (R_OR1K_8_PCREL,
  186. 0, /* rightshift */
  187. 0, /* size (0 = byte, 1 = short, 2 = long) */
  188. 8, /* bitsize */
  189. true, /* pc_relative */
  190. 0, /* bitpos */
  191. complain_overflow_signed, /* complain_on_overflow */
  192. bfd_elf_generic_reloc, /* special_function */
  193. "R_OR1K_8_PCREL", /* name */
  194. false, /* partial_inplace */
  195. 0, /* src_mask */
  196. 0xff, /* dst_mask */
  197. true), /* pcrel_offset */
  198. HOWTO (R_OR1K_GOTPC_HI16, /* Type. */
  199. 16, /* Rightshift. */
  200. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  201. 16, /* Bitsize. */
  202. true, /* PC_relative. */
  203. 0, /* Bitpos. */
  204. complain_overflow_dont, /* Complain on overflow. */
  205. bfd_elf_generic_reloc, /* Special Function. */
  206. "R_OR1K_GOTPC_HI16", /* Name. */
  207. false, /* Partial Inplace. */
  208. 0, /* Source Mask. */
  209. 0xffff, /* Dest Mask. */
  210. true), /* PC relative offset? */
  211. HOWTO (R_OR1K_GOTPC_LO16, /* Type. */
  212. 0, /* Rightshift. */
  213. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  214. 16, /* Bitsize. */
  215. true, /* PC_relative. */
  216. 0, /* Bitpos. */
  217. complain_overflow_dont, /* Complain on overflow. */
  218. bfd_elf_generic_reloc, /* Special Function. */
  219. "R_OR1K_GOTPC_LO16", /* Name. */
  220. false, /* Partial Inplace. */
  221. 0, /* Source Mask. */
  222. 0xffff, /* Dest Mask. */
  223. true), /* PC relative offset? */
  224. HOWTO (R_OR1K_GOT16, /* type */
  225. 0, /* rightshift */
  226. 2, /* size (0 = byte, 1 = short, 2 = long) */
  227. 16, /* bitsize */
  228. false, /* pc_relative */
  229. 0, /* bitpos */
  230. complain_overflow_signed, /* complain_on_overflow */
  231. bfd_elf_generic_reloc, /* special_function */
  232. "R_OR1K_GOT16", /* name */
  233. false, /* partial_inplace */
  234. 0, /* src_mask */
  235. 0xffff, /* dst_mask */
  236. false), /* pcrel_offset */
  237. /* A 26 bit PLT relocation. Shifted by 2. */
  238. HOWTO (R_OR1K_PLT26, /* Type. */
  239. 2, /* Rightshift. */
  240. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  241. 26, /* Bitsize. */
  242. true, /* pc_relative. */
  243. 0, /* Bitpos. */
  244. complain_overflow_signed, /* Complain on overflow. */
  245. bfd_elf_generic_reloc, /* Special Function. */
  246. "R_OR1K_PLT26", /* Name. */
  247. false, /* Partial Inplace. */
  248. 0, /* Source Mask. */
  249. 0x03ffffff, /* Dest Mask. */
  250. true), /* PC relative offset? */
  251. HOWTO (R_OR1K_GOTOFF_HI16, /* type */
  252. 16, /* rightshift */
  253. 2, /* size (0 = byte, 1 = short, 2 = long) */
  254. 16, /* bitsize */
  255. false, /* pc_relative */
  256. 0, /* bitpos */
  257. complain_overflow_dont, /* complain_on_overflow */
  258. bfd_elf_generic_reloc, /* special_function */
  259. "R_OR1K_GOTOFF_HI16", /* name */
  260. false, /* partial_inplace */
  261. 0x0, /* src_mask */
  262. 0xffff, /* dst_mask */
  263. false), /* pcrel_offset */
  264. HOWTO (R_OR1K_GOTOFF_LO16, /* type */
  265. 0, /* rightshift */
  266. 2, /* size (0 = byte, 1 = short, 2 = long) */
  267. 16, /* bitsize */
  268. false, /* pc_relative */
  269. 0, /* bitpos */
  270. complain_overflow_dont, /* complain_on_overflow */
  271. bfd_elf_generic_reloc, /* special_function */
  272. "R_OR1K_GOTOFF_LO16", /* name */
  273. false, /* partial_inplace */
  274. 0x0, /* src_mask */
  275. 0xffff, /* dst_mask */
  276. false), /* pcrel_offset */
  277. HOWTO (R_OR1K_COPY, /* type */
  278. 0, /* rightshift */
  279. 2, /* size (0 = byte, 1 = short, 2 = long) */
  280. 32, /* bitsize */
  281. false, /* pc_relative */
  282. 0, /* bitpos */
  283. complain_overflow_bitfield, /* complain_on_overflow */
  284. bfd_elf_generic_reloc, /* special_function */
  285. "R_OR1K_COPY", /* name */
  286. false, /* partial_inplace */
  287. 0xffffffff, /* src_mask */
  288. 0xffffffff, /* dst_mask */
  289. false), /* pcrel_offset */
  290. HOWTO (R_OR1K_GLOB_DAT, /* type */
  291. 0, /* rightshift */
  292. 2, /* size (0 = byte, 1 = short, 2 = long) */
  293. 32, /* bitsize */
  294. false, /* pc_relative */
  295. 0, /* bitpos */
  296. complain_overflow_bitfield, /* complain_on_overflow */
  297. bfd_elf_generic_reloc, /* special_function */
  298. "R_OR1K_GLOB_DAT", /* name */
  299. false, /* partial_inplace */
  300. 0xffffffff, /* src_mask */
  301. 0xffffffff, /* dst_mask */
  302. false), /* pcrel_offset */
  303. HOWTO (R_OR1K_JMP_SLOT, /* type */
  304. 0, /* rightshift */
  305. 2, /* size (0 = byte, 1 = short, 2 = long) */
  306. 32, /* bitsize */
  307. false, /* pc_relative */
  308. 0, /* bitpos */
  309. complain_overflow_bitfield, /* complain_on_overflow */
  310. bfd_elf_generic_reloc, /* special_function */
  311. "R_OR1K_JMP_SLOT", /* name */
  312. false, /* partial_inplace */
  313. 0xffffffff, /* src_mask */
  314. 0xffffffff, /* dst_mask */
  315. false), /* pcrel_offset */
  316. HOWTO (R_OR1K_RELATIVE, /* type */
  317. 0, /* rightshift */
  318. 2, /* size (0 = byte, 1 = short, 2 = long) */
  319. 32, /* bitsize */
  320. false, /* pc_relative */
  321. 0, /* bitpos */
  322. complain_overflow_bitfield, /* complain_on_overflow */
  323. bfd_elf_generic_reloc, /* special_function */
  324. "R_OR1K_RELATIVE", /* name */
  325. false, /* partial_inplace */
  326. 0xffffffff, /* src_mask */
  327. 0xffffffff, /* dst_mask */
  328. false), /* pcrel_offset */
  329. HOWTO (R_OR1K_TLS_GD_HI16, /* type */
  330. 16, /* rightshift */
  331. 2, /* size (0 = byte, 1 = short, 2 = long) */
  332. 16, /* bitsize */
  333. false, /* pc_relative */
  334. 0, /* bitpos */
  335. complain_overflow_dont, /* complain_on_overflow */
  336. bfd_elf_generic_reloc, /* special_function */
  337. "R_OR1K_TLS_GD_HI16", /* name */
  338. false, /* partial_inplace */
  339. 0x0, /* src_mask */
  340. 0xffff, /* dst_mask */
  341. false), /* pcrel_offset */
  342. HOWTO (R_OR1K_TLS_GD_LO16, /* type */
  343. 0, /* rightshift */
  344. 2, /* size (0 = byte, 1 = short, 2 = long) */
  345. 16, /* bitsize */
  346. false, /* pc_relative */
  347. 0, /* bitpos */
  348. complain_overflow_dont, /* complain_on_overflow */
  349. bfd_elf_generic_reloc, /* special_function */
  350. "R_OR1K_TLS_GD_LO16", /* name */
  351. false, /* partial_inplace */
  352. 0x0, /* src_mask */
  353. 0xffff, /* dst_mask */
  354. false), /* pcrel_offset */
  355. HOWTO (R_OR1K_TLS_LDM_HI16, /* type */
  356. 16, /* rightshift */
  357. 2, /* size (0 = byte, 1 = short, 2 = long) */
  358. 16, /* bitsize */
  359. false, /* pc_relative */
  360. 0, /* bitpos */
  361. complain_overflow_dont, /* complain_on_overflow */
  362. bfd_elf_generic_reloc, /* special_function */
  363. "R_OR1K_TLS_LDM_HI16", /* name */
  364. false, /* partial_inplace */
  365. 0x0, /* src_mask */
  366. 0xffff, /* dst_mask */
  367. false), /* pcrel_offset */
  368. HOWTO (R_OR1K_TLS_LDM_LO16, /* type */
  369. 0, /* rightshift */
  370. 2, /* size (0 = byte, 1 = short, 2 = long) */
  371. 16, /* bitsize */
  372. false, /* pc_relative */
  373. 0, /* bitpos */
  374. complain_overflow_dont, /* complain_on_overflow */
  375. bfd_elf_generic_reloc, /* special_function */
  376. "R_OR1K_TLS_LDM_LO16", /* name */
  377. false, /* partial_inplace */
  378. 0x0, /* src_mask */
  379. 0xffff, /* dst_mask */
  380. false), /* pcrel_offset */
  381. HOWTO (R_OR1K_TLS_LDO_HI16, /* type */
  382. 16, /* rightshift */
  383. 2, /* size (0 = byte, 1 = short, 2 = long) */
  384. 16, /* bitsize */
  385. false, /* pc_relative */
  386. 0, /* bitpos */
  387. complain_overflow_dont, /* complain_on_overflow */
  388. bfd_elf_generic_reloc, /* special_function */
  389. "R_OR1K_TLS_LDO_HI16", /* name */
  390. false, /* partial_inplace */
  391. 0x0, /* src_mask */
  392. 0xffff, /* dst_mask */
  393. false), /* pcrel_offset */
  394. HOWTO (R_OR1K_TLS_LDO_LO16, /* type */
  395. 0, /* rightshift */
  396. 2, /* size (0 = byte, 1 = short, 2 = long) */
  397. 16, /* bitsize */
  398. false, /* pc_relative */
  399. 0, /* bitpos */
  400. complain_overflow_dont, /* complain_on_overflow */
  401. bfd_elf_generic_reloc, /* special_function */
  402. "R_OR1K_TLS_LDO_LO16", /* name */
  403. false, /* partial_inplace */
  404. 0x0, /* src_mask */
  405. 0xffff, /* dst_mask */
  406. false), /* pcrel_offset */
  407. HOWTO (R_OR1K_TLS_IE_HI16, /* type */
  408. 16, /* rightshift */
  409. 2, /* size (0 = byte, 1 = short, 2 = long) */
  410. 16, /* bitsize */
  411. false, /* pc_relative */
  412. 0, /* bitpos */
  413. complain_overflow_dont, /* complain_on_overflow */
  414. bfd_elf_generic_reloc, /* special_function */
  415. "R_OR1K_TLS_IE_HI16", /* name */
  416. false, /* partial_inplace */
  417. 0x0, /* src_mask */
  418. 0xffff, /* dst_mask */
  419. false), /* pcrel_offset */
  420. HOWTO (R_OR1K_TLS_IE_LO16, /* type */
  421. 0, /* rightshift */
  422. 2, /* size (0 = byte, 1 = short, 2 = long) */
  423. 16, /* bitsize */
  424. false, /* pc_relative */
  425. 0, /* bitpos */
  426. complain_overflow_dont, /* complain_on_overflow */
  427. bfd_elf_generic_reloc, /* special_function */
  428. "R_OR1K_TLS_IE_LO16", /* name */
  429. false, /* partial_inplace */
  430. 0x0, /* src_mask */
  431. 0xffff, /* dst_mask */
  432. false), /* pcrel_offset */
  433. HOWTO (R_OR1K_TLS_LE_HI16, /* type */
  434. 16, /* rightshift */
  435. 2, /* size (0 = byte, 1 = short, 2 = long) */
  436. 16, /* bitsize */
  437. false, /* pc_relative */
  438. 0, /* bitpos */
  439. complain_overflow_dont, /* complain_on_overflow */
  440. bfd_elf_generic_reloc, /* special_function */
  441. "R_OR1K_TLS_LE_HI16", /* name */
  442. false, /* partial_inplace */
  443. 0x0, /* src_mask */
  444. 0xffff, /* dst_mask */
  445. false), /* pcrel_offset */
  446. HOWTO (R_OR1K_TLS_LE_LO16, /* type */
  447. 0, /* rightshift */
  448. 2, /* size (0 = byte, 1 = short, 2 = long) */
  449. 16, /* bitsize */
  450. false, /* pc_relative */
  451. 0, /* bitpos */
  452. complain_overflow_dont, /* complain_on_overflow */
  453. bfd_elf_generic_reloc, /* special_function */
  454. "R_OR1K_TLS_LE_LO16", /* name */
  455. false, /* partial_inplace */
  456. 0x0, /* src_mask */
  457. 0xffff, /* dst_mask */
  458. false), /* pcrel_offset */
  459. HOWTO (R_OR1K_TLS_TPOFF, /* type */
  460. 0, /* rightshift */
  461. 2, /* size (0 = byte, 1 = short, 2 = long) */
  462. 32, /* bitsize */
  463. false, /* pc_relative */
  464. 0, /* bitpos */
  465. complain_overflow_bitfield, /* complain_on_overflow */
  466. bfd_elf_generic_reloc, /* special_function */
  467. "R_OR1K_TLS_TPOFF", /* name */
  468. false, /* partial_inplace */
  469. 0xffffffff, /* src_mask */
  470. 0xffffffff, /* dst_mask */
  471. false), /* pcrel_offset */
  472. HOWTO (R_OR1K_TLS_DTPOFF, /* type */
  473. 0, /* rightshift */
  474. 2, /* size (0 = byte, 1 = short, 2 = long) */
  475. 32, /* bitsize */
  476. false, /* pc_relative */
  477. 0, /* bitpos */
  478. complain_overflow_bitfield, /* complain_on_overflow */
  479. bfd_elf_generic_reloc, /* special_function */
  480. "R_OR1K_TLS_DTPOFF", /* name */
  481. false, /* partial_inplace */
  482. 0xffffffff, /* src_mask */
  483. 0xffffffff, /* dst_mask */
  484. false), /* pcrel_offset */
  485. HOWTO (R_OR1K_TLS_DTPMOD, /* type */
  486. 0, /* rightshift */
  487. 2, /* size (0 = byte, 1 = short, 2 = long) */
  488. 32, /* bitsize */
  489. false, /* pc_relative */
  490. 0, /* bitpos */
  491. complain_overflow_bitfield, /* complain_on_overflow */
  492. bfd_elf_generic_reloc, /* special_function */
  493. "R_OR1K_TLS_DTPMOD", /* name */
  494. false, /* partial_inplace */
  495. 0xffffffff, /* src_mask */
  496. 0xffffffff, /* dst_mask */
  497. false), /* pcrel_offset */
  498. HOWTO (R_OR1K_AHI16, /* type */
  499. 16, /* rightshift */
  500. 2, /* size (0 = byte, 1 = short, 2 = long) */
  501. 16, /* bitsize */
  502. false, /* pc_relative */
  503. 0, /* bitpos */
  504. complain_overflow_dont, /* complain_on_overflow */
  505. bfd_elf_generic_reloc, /* special_function */
  506. "R_OR1K_AHI16", /* name */
  507. false, /* partial_inplace */
  508. 0x0, /* src_mask */
  509. 0xffff, /* dst_mask */
  510. false), /* pcrel_offset */
  511. HOWTO (R_OR1K_GOTOFF_AHI16, /* type */
  512. 16, /* rightshift */
  513. 2, /* size (0 = byte, 1 = short, 2 = long) */
  514. 16, /* bitsize */
  515. false, /* pc_relative */
  516. 0, /* bitpos */
  517. complain_overflow_dont, /* complain_on_overflow */
  518. bfd_elf_generic_reloc, /* special_function */
  519. "R_OR1K_GOTOFF_AHI16", /* name */
  520. false, /* partial_inplace */
  521. 0x0, /* src_mask */
  522. 0xffff, /* dst_mask */
  523. false), /* pcrel_offset */
  524. HOWTO (R_OR1K_TLS_IE_AHI16, /* type */
  525. 16, /* rightshift */
  526. 2, /* size (0 = byte, 1 = short, 2 = long) */
  527. 16, /* bitsize */
  528. false, /* pc_relative */
  529. 0, /* bitpos */
  530. complain_overflow_dont, /* complain_on_overflow */
  531. bfd_elf_generic_reloc, /* special_function */
  532. "R_OR1K_TLS_IE_AHI16", /* name */
  533. false, /* partial_inplace */
  534. 0x0, /* src_mask */
  535. 0xffff, /* dst_mask */
  536. false), /* pcrel_offset */
  537. HOWTO (R_OR1K_TLS_LE_AHI16, /* type */
  538. 16, /* rightshift */
  539. 2, /* size (0 = byte, 1 = short, 2 = long) */
  540. 16, /* bitsize */
  541. false, /* pc_relative */
  542. 0, /* bitpos */
  543. complain_overflow_dont, /* complain_on_overflow */
  544. bfd_elf_generic_reloc, /* special_function */
  545. "R_OR1K_TLS_LE_AHI16", /* name */
  546. false, /* partial_inplace */
  547. 0x0, /* src_mask */
  548. 0xffff, /* dst_mask */
  549. false), /* pcrel_offset */
  550. HOWTO (R_OR1K_SLO16, /* type */
  551. 0, /* rightshift */
  552. 2, /* size (0 = byte, 1 = short, 2 = long) */
  553. 16, /* bitsize */
  554. false, /* pc_relative */
  555. 0, /* bitpos */
  556. complain_overflow_dont, /* complain_on_overflow */
  557. bfd_elf_generic_reloc, /* special_function */
  558. "R_OR1K_SLO16", /* name */
  559. false, /* partial_inplace */
  560. 0x0, /* src_mask */
  561. 0xffff, /* dst_mask */
  562. false), /* pcrel_offset */
  563. HOWTO (R_OR1K_GOTOFF_SLO16, /* type */
  564. 0, /* rightshift */
  565. 2, /* size (0 = byte, 1 = short, 2 = long) */
  566. 16, /* bitsize */
  567. false, /* pc_relative */
  568. 0, /* bitpos */
  569. complain_overflow_dont, /* complain_on_overflow */
  570. bfd_elf_generic_reloc, /* special_function */
  571. "R_OR1K_GOTOFF_SLO16", /* name */
  572. false, /* partial_inplace */
  573. 0x0, /* src_mask */
  574. 0xffff, /* dst_mask */
  575. false), /* pcrel_offset */
  576. HOWTO (R_OR1K_TLS_LE_SLO16, /* type */
  577. 0, /* rightshift */
  578. 2, /* size (0 = byte, 1 = short, 2 = long) */
  579. 16, /* bitsize */
  580. false, /* pc_relative */
  581. 0, /* bitpos */
  582. complain_overflow_dont, /* complain_on_overflow */
  583. bfd_elf_generic_reloc, /* special_function */
  584. "R_OR1K_TLS_LE_SLO16", /* name */
  585. false, /* partial_inplace */
  586. 0x0, /* src_mask */
  587. 0xffff, /* dst_mask */
  588. false), /* pcrel_offset */
  589. /* A page relative 21 bit relocation, right shifted by 13, aligned.
  590. Note that this is *page* relative, not pc relative. The idea is
  591. similar, but normally the section alignment is not such that the
  592. assembler can infer a final value, which it attempts to do with
  593. pc-relative relocations to local symbols. */
  594. HOWTO (R_OR1K_PCREL_PG21, /* type */
  595. 13, /* rightshift */
  596. 2, /* size (0 = byte, 1 = short, 2 = long) */
  597. 21, /* bitsize */
  598. false, /* pc_relative */
  599. 0, /* bitpos */
  600. complain_overflow_signed, /* complain_on_overflow */
  601. bfd_elf_generic_reloc, /* special_function */
  602. "R_OR1K_PCREL_PG21", /* name */
  603. false, /* partial_inplace */
  604. 0, /* src_mask */
  605. 0x001fffff, /* dst_mask */
  606. true), /* pcrel_offset */
  607. HOWTO (R_OR1K_GOT_PG21, /* type */
  608. 13, /* rightshift */
  609. 2, /* size (0 = byte, 1 = short, 2 = long) */
  610. 21, /* bitsize */
  611. false, /* pc_relative */
  612. 0, /* bitpos */
  613. complain_overflow_signed, /* complain_on_overflow */
  614. bfd_elf_generic_reloc, /* special_function */
  615. "R_OR1K_GOT_PG21", /* name */
  616. false, /* partial_inplace */
  617. 0, /* src_mask */
  618. 0x001fffff, /* dst_mask */
  619. true), /* pcrel_offset */
  620. HOWTO (R_OR1K_TLS_GD_PG21, /* type */
  621. 13, /* rightshift */
  622. 2, /* size (0 = byte, 1 = short, 2 = long) */
  623. 21, /* bitsize */
  624. false, /* pc_relative */
  625. 0, /* bitpos */
  626. complain_overflow_signed, /* complain_on_overflow */
  627. bfd_elf_generic_reloc, /* special_function */
  628. "R_OR1K_TLS_GD_PG21", /* name */
  629. false, /* partial_inplace */
  630. 0, /* src_mask */
  631. 0x001fffff, /* dst_mask */
  632. true), /* pcrel_offset */
  633. HOWTO (R_OR1K_TLS_LDM_PG21, /* type */
  634. 13, /* rightshift */
  635. 2, /* size (0 = byte, 1 = short, 2 = long) */
  636. 21, /* bitsize */
  637. false, /* pc_relative */
  638. 0, /* bitpos */
  639. complain_overflow_signed, /* complain_on_overflow */
  640. bfd_elf_generic_reloc, /* special_function */
  641. "R_OR1K_TLS_LDM_PG21", /* name */
  642. false, /* partial_inplace */
  643. 0, /* src_mask */
  644. 0x001fffff, /* dst_mask */
  645. true), /* pcrel_offset */
  646. HOWTO (R_OR1K_TLS_IE_PG21, /* type */
  647. 13, /* rightshift */
  648. 2, /* size (0 = byte, 1 = short, 2 = long) */
  649. 21, /* bitsize */
  650. false, /* pc_relative */
  651. 0, /* bitpos */
  652. complain_overflow_signed, /* complain_on_overflow */
  653. bfd_elf_generic_reloc, /* special_function */
  654. "R_OR1K_TLS_IE_PG21", /* name */
  655. false, /* partial_inplace */
  656. 0, /* src_mask */
  657. 0x001fffff, /* dst_mask */
  658. true), /* pcrel_offset */
  659. HOWTO (R_OR1K_LO13, /* type */
  660. 0, /* rightshift */
  661. 2, /* size (0 = byte, 1 = short, 2 = long) */
  662. 16, /* bitsize */
  663. false, /* pc_relative */
  664. 0, /* bitpos */
  665. complain_overflow_dont, /* complain_on_overflow */
  666. bfd_elf_generic_reloc, /* special_function */
  667. "R_OR1K_LO13", /* name */
  668. false, /* partial_inplace */
  669. 0x0, /* src_mask */
  670. 0xffff, /* dst_mask */
  671. false), /* pcrel_offset */
  672. HOWTO (R_OR1K_GOT_LO13, /* type */
  673. 0, /* rightshift */
  674. 2, /* size (0 = byte, 1 = short, 2 = long) */
  675. 16, /* bitsize */
  676. false, /* pc_relative */
  677. 0, /* bitpos */
  678. complain_overflow_dont, /* complain_on_overflow */
  679. bfd_elf_generic_reloc, /* special_function */
  680. "R_OR1K_GOT_LO13", /* name */
  681. false, /* partial_inplace */
  682. 0x0, /* src_mask */
  683. 0xffff, /* dst_mask */
  684. false), /* pcrel_offset */
  685. HOWTO (R_OR1K_TLS_GD_LO13, /* type */
  686. 0, /* rightshift */
  687. 2, /* size (0 = byte, 1 = short, 2 = long) */
  688. 16, /* bitsize */
  689. false, /* pc_relative */
  690. 0, /* bitpos */
  691. complain_overflow_dont, /* complain_on_overflow */
  692. bfd_elf_generic_reloc, /* special_function */
  693. "R_OR1K_TLS_GD_LO13", /* name */
  694. false, /* partial_inplace */
  695. 0x0, /* src_mask */
  696. 0xffff, /* dst_mask */
  697. false), /* pcrel_offset */
  698. HOWTO (R_OR1K_TLS_LDM_LO13, /* type */
  699. 0, /* rightshift */
  700. 2, /* size (0 = byte, 1 = short, 2 = long) */
  701. 16, /* bitsize */
  702. false, /* pc_relative */
  703. 0, /* bitpos */
  704. complain_overflow_dont, /* complain_on_overflow */
  705. bfd_elf_generic_reloc, /* special_function */
  706. "R_OR1K_TLD_LDM_LO13", /* name */
  707. false, /* partial_inplace */
  708. 0x0, /* src_mask */
  709. 0xffff, /* dst_mask */
  710. false), /* pcrel_offset */
  711. HOWTO (R_OR1K_TLS_IE_LO13, /* type */
  712. 0, /* rightshift */
  713. 2, /* size (0 = byte, 1 = short, 2 = long) */
  714. 16, /* bitsize */
  715. false, /* pc_relative */
  716. 0, /* bitpos */
  717. complain_overflow_dont, /* complain_on_overflow */
  718. bfd_elf_generic_reloc, /* special_function */
  719. "R_OR1K_TLS_IE_LO13", /* name */
  720. false, /* partial_inplace */
  721. 0x0, /* src_mask */
  722. 0xffff, /* dst_mask */
  723. false), /* pcrel_offset */
  724. HOWTO (R_OR1K_SLO13, /* type */
  725. 0, /* rightshift */
  726. 2, /* size (0 = byte, 1 = short, 2 = long) */
  727. 16, /* bitsize */
  728. false, /* pc_relative */
  729. 0, /* bitpos */
  730. complain_overflow_dont, /* complain_on_overflow */
  731. bfd_elf_generic_reloc, /* special_function */
  732. "R_OR1K_SLO13", /* name */
  733. false, /* partial_inplace */
  734. 0x0, /* src_mask */
  735. 0xffff, /* dst_mask */
  736. false), /* pcrel_offset */
  737. /* A 26 bit PLT relocation, using ADRP. Shifted by 2. */
  738. HOWTO (R_OR1K_PLTA26, /* Type. */
  739. 2, /* Rightshift. */
  740. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  741. 26, /* Bitsize. */
  742. true, /* pc_relative. */
  743. 0, /* Bitpos. */
  744. complain_overflow_signed, /* Complain on overflow. */
  745. bfd_elf_generic_reloc, /* Special Function. */
  746. "R_OR1K_PLTA26", /* Name. */
  747. false, /* Partial Inplace. */
  748. 0, /* Source Mask. */
  749. 0x03ffffff, /* Dest Mask. */
  750. true), /* PC relative offset? */
  751. HOWTO (R_OR1K_GOT_AHI16, /* type */
  752. 16, /* rightshift */
  753. 2, /* size (0 = byte, 1 = short, 2 = long) */
  754. 16, /* bitsize */
  755. false, /* pc_relative */
  756. 0, /* bitpos */
  757. complain_overflow_signed, /* complain_on_overflow */
  758. bfd_elf_generic_reloc, /* special_function */
  759. "R_OR1K_GOT_AHI16", /* name */
  760. false, /* partial_inplace */
  761. 0, /* src_mask */
  762. 0xffff, /* dst_mask */
  763. false), /* pcrel_offset */
  764. };
  765. /* A copy of the R_OR1K_GOT16 used in the presense of R_OR1K_GOT_AHI16
  766. relocations when we know we can ignore overflows. */
  767. static reloc_howto_type or1k_elf_got16_no_overflow_howto =
  768. HOWTO (R_OR1K_GOT16, /* type */
  769. 0, /* rightshift */
  770. 2, /* size (0 = byte, 1 = short, 2 = long) */
  771. 16, /* bitsize */
  772. false, /* pc_relative */
  773. 0, /* bitpos */
  774. complain_overflow_dont, /* complain_on_overflow */
  775. bfd_elf_generic_reloc, /* special_function */
  776. "R_OR1K_GOT16", /* name */
  777. false, /* partial_inplace */
  778. 0, /* src_mask */
  779. 0xffff, /* dst_mask */
  780. false); /* pcrel_offset */
  781. /* Map BFD reloc types to Or1k ELF reloc types. */
  782. struct or1k_reloc_map
  783. {
  784. bfd_reloc_code_real_type bfd_reloc_val;
  785. unsigned int or1k_reloc_val;
  786. };
  787. static const struct or1k_reloc_map or1k_reloc_map[] =
  788. {
  789. { BFD_RELOC_NONE, R_OR1K_NONE },
  790. { BFD_RELOC_32, R_OR1K_32 },
  791. { BFD_RELOC_16, R_OR1K_16 },
  792. { BFD_RELOC_8, R_OR1K_8 },
  793. { BFD_RELOC_LO16, R_OR1K_LO_16_IN_INSN },
  794. { BFD_RELOC_HI16, R_OR1K_HI_16_IN_INSN },
  795. { BFD_RELOC_HI16_S, R_OR1K_AHI16 },
  796. { BFD_RELOC_OR1K_REL_26, R_OR1K_INSN_REL_26 },
  797. { BFD_RELOC_VTABLE_ENTRY, R_OR1K_GNU_VTENTRY },
  798. { BFD_RELOC_VTABLE_INHERIT, R_OR1K_GNU_VTINHERIT },
  799. { BFD_RELOC_32_PCREL, R_OR1K_32_PCREL },
  800. { BFD_RELOC_16_PCREL, R_OR1K_16_PCREL },
  801. { BFD_RELOC_8_PCREL, R_OR1K_8_PCREL },
  802. { BFD_RELOC_LO16_GOTOFF, R_OR1K_GOTOFF_LO16 },
  803. { BFD_RELOC_HI16_GOTOFF, R_OR1K_GOTOFF_HI16 },
  804. { BFD_RELOC_HI16_S_GOTOFF, R_OR1K_GOTOFF_AHI16 },
  805. { BFD_RELOC_OR1K_GOTPC_HI16, R_OR1K_GOTPC_HI16 },
  806. { BFD_RELOC_OR1K_GOTPC_LO16, R_OR1K_GOTPC_LO16 },
  807. { BFD_RELOC_OR1K_GOT16, R_OR1K_GOT16 },
  808. { BFD_RELOC_OR1K_PLT26, R_OR1K_PLT26 },
  809. { BFD_RELOC_OR1K_GLOB_DAT, R_OR1K_GLOB_DAT },
  810. { BFD_RELOC_OR1K_COPY, R_OR1K_COPY },
  811. { BFD_RELOC_OR1K_JMP_SLOT, R_OR1K_JMP_SLOT },
  812. { BFD_RELOC_OR1K_RELATIVE, R_OR1K_RELATIVE },
  813. { BFD_RELOC_OR1K_TLS_GD_HI16, R_OR1K_TLS_GD_HI16 },
  814. { BFD_RELOC_OR1K_TLS_GD_LO16, R_OR1K_TLS_GD_LO16 },
  815. { BFD_RELOC_OR1K_TLS_LDM_HI16, R_OR1K_TLS_LDM_HI16 },
  816. { BFD_RELOC_OR1K_TLS_LDM_LO16, R_OR1K_TLS_LDM_LO16 },
  817. { BFD_RELOC_OR1K_TLS_LDO_HI16, R_OR1K_TLS_LDO_HI16 },
  818. { BFD_RELOC_OR1K_TLS_LDO_LO16, R_OR1K_TLS_LDO_LO16 },
  819. { BFD_RELOC_OR1K_TLS_IE_HI16, R_OR1K_TLS_IE_HI16 },
  820. { BFD_RELOC_OR1K_TLS_IE_LO16, R_OR1K_TLS_IE_LO16 },
  821. { BFD_RELOC_OR1K_TLS_IE_AHI16, R_OR1K_TLS_IE_AHI16 },
  822. { BFD_RELOC_OR1K_TLS_LE_HI16, R_OR1K_TLS_LE_HI16 },
  823. { BFD_RELOC_OR1K_TLS_LE_LO16, R_OR1K_TLS_LE_LO16 },
  824. { BFD_RELOC_OR1K_TLS_LE_AHI16, R_OR1K_TLS_LE_AHI16 },
  825. { BFD_RELOC_OR1K_SLO16, R_OR1K_SLO16 },
  826. { BFD_RELOC_OR1K_GOTOFF_SLO16, R_OR1K_GOTOFF_SLO16 },
  827. { BFD_RELOC_OR1K_TLS_LE_SLO16, R_OR1K_TLS_LE_SLO16 },
  828. { BFD_RELOC_OR1K_PCREL_PG21, R_OR1K_PCREL_PG21 },
  829. { BFD_RELOC_OR1K_GOT_PG21, R_OR1K_GOT_PG21 },
  830. { BFD_RELOC_OR1K_TLS_GD_PG21, R_OR1K_TLS_GD_PG21 },
  831. { BFD_RELOC_OR1K_TLS_LDM_PG21, R_OR1K_TLS_LDM_PG21 },
  832. { BFD_RELOC_OR1K_TLS_IE_PG21, R_OR1K_TLS_IE_PG21 },
  833. { BFD_RELOC_OR1K_LO13, R_OR1K_LO13 },
  834. { BFD_RELOC_OR1K_GOT_LO13, R_OR1K_GOT_LO13 },
  835. { BFD_RELOC_OR1K_TLS_GD_LO13, R_OR1K_TLS_GD_LO13 },
  836. { BFD_RELOC_OR1K_TLS_LDM_LO13, R_OR1K_TLS_LDM_LO13 },
  837. { BFD_RELOC_OR1K_TLS_IE_LO13, R_OR1K_TLS_IE_LO13 },
  838. { BFD_RELOC_OR1K_SLO13, R_OR1K_SLO13 },
  839. { BFD_RELOC_OR1K_PLTA26, R_OR1K_PLTA26 },
  840. { BFD_RELOC_OR1K_GOT_AHI16, R_OR1K_GOT_AHI16 },
  841. };
  842. /* tls_type is a mask used to track how each symbol is accessed,
  843. it may be accessed via multiple types of TLS access methods.
  844. We track this for sizing (allocating got + relocation section space) and
  845. for how to process relocations. */
  846. #define TLS_UNKNOWN 0
  847. #define TLS_NONE 1
  848. #define TLS_GD 2
  849. #define TLS_LD 4
  850. #define TLS_IE 8
  851. #define TLS_LE 16
  852. /* The size of the TLS thread control block, used to offset LE access. */
  853. #define TCB_SIZE 16
  854. /* ELF linker hash entry. */
  855. struct elf_or1k_link_hash_entry
  856. {
  857. struct elf_link_hash_entry root;
  858. /* For calculating PLT size. */
  859. bfd_vma plt_index;
  860. /* Track type of TLS access. */
  861. unsigned char tls_type;
  862. };
  863. /* ELF object data. */
  864. struct elf_or1k_obj_tdata
  865. {
  866. struct elf_obj_tdata root;
  867. /* tls_type for each local got entry. */
  868. unsigned char *local_tls_type;
  869. };
  870. #define elf_or1k_tdata(abfd) \
  871. ((struct elf_or1k_obj_tdata *) (abfd)->tdata.any)
  872. #define elf_or1k_local_tls_type(abfd) \
  873. (elf_or1k_tdata (abfd)->local_tls_type)
  874. /* ELF linker hash table. */
  875. struct elf_or1k_link_hash_table
  876. {
  877. struct elf_link_hash_table root;
  878. bfd_vma plt_count;
  879. bool saw_plta;
  880. };
  881. static size_t
  882. elf_or1k_plt_entry_size (bfd_vma plt_index)
  883. {
  884. bfd_vma plt_reloc;
  885. plt_reloc = plt_index * sizeof (Elf32_External_Rela);
  886. return (plt_reloc > 0xffff) ? PLT_ENTRY_SIZE_LARGE : PLT_ENTRY_SIZE;
  887. }
  888. /* Get the ELF linker hash table from a link_info structure. */
  889. #define or1k_elf_hash_table(p) \
  890. ((is_elf_hash_table ((p)->hash) \
  891. && elf_hash_table_id (elf_hash_table (p)) == OR1K_ELF_DATA) \
  892. ? (struct elf_or1k_link_hash_table *) (p)->hash : NULL)
  893. static bool
  894. elf_or1k_mkobject (bfd *abfd)
  895. {
  896. return bfd_elf_allocate_object (abfd, sizeof (struct elf_or1k_obj_tdata),
  897. OR1K_ELF_DATA);
  898. }
  899. /* Create an entry in an or1k ELF linker hash table. */
  900. static struct bfd_hash_entry *
  901. or1k_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
  902. struct bfd_hash_table *table,
  903. const char *string)
  904. {
  905. struct elf_or1k_link_hash_entry *ret =
  906. (struct elf_or1k_link_hash_entry *) entry;
  907. /* Allocate the structure if it has not already been allocated by a
  908. subclass. */
  909. if (ret == NULL)
  910. ret = bfd_hash_allocate (table,
  911. sizeof (struct elf_or1k_link_hash_entry));
  912. if (ret == NULL)
  913. return NULL;
  914. /* Call the allocation method of the superclass. */
  915. ret = ((struct elf_or1k_link_hash_entry *)
  916. _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
  917. table, string));
  918. if (ret != NULL)
  919. {
  920. struct elf_or1k_link_hash_entry *eh;
  921. eh = (struct elf_or1k_link_hash_entry *) ret;
  922. eh->tls_type = TLS_UNKNOWN;
  923. }
  924. return (struct bfd_hash_entry *) ret;
  925. }
  926. /* Create an or1k ELF linker hash table. */
  927. static struct bfd_link_hash_table *
  928. or1k_elf_link_hash_table_create (bfd *abfd)
  929. {
  930. struct elf_or1k_link_hash_table *ret;
  931. size_t amt = sizeof (struct elf_or1k_link_hash_table);
  932. ret = bfd_zmalloc (amt);
  933. if (ret == NULL)
  934. return NULL;
  935. if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
  936. or1k_elf_link_hash_newfunc,
  937. sizeof (struct elf_or1k_link_hash_entry),
  938. OR1K_ELF_DATA))
  939. {
  940. free (ret);
  941. return NULL;
  942. }
  943. return &ret->root.root;
  944. }
  945. static reloc_howto_type *
  946. or1k_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
  947. bfd_reloc_code_real_type bcode)
  948. {
  949. unsigned int i;
  950. for (i = 0; i < ARRAY_SIZE (or1k_reloc_map); i++)
  951. if (or1k_reloc_map[i].bfd_reloc_val == bcode)
  952. {
  953. unsigned int ocode = or1k_reloc_map[i].or1k_reloc_val;
  954. if (ocode < (unsigned int) R_OR1K_max)
  955. return &or1k_elf_howto_table[ocode];
  956. else
  957. break;
  958. }
  959. return NULL;
  960. }
  961. static reloc_howto_type *
  962. or1k_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  963. const char *r_name)
  964. {
  965. unsigned int i;
  966. for (i = 0; i < R_OR1K_max; i++)
  967. if (or1k_elf_howto_table[i].name != NULL
  968. && strcasecmp (or1k_elf_howto_table[i].name, r_name) == 0)
  969. return &or1k_elf_howto_table[i];
  970. return NULL;
  971. }
  972. /* Set the howto pointer for an Or1k ELF reloc. */
  973. static bool
  974. or1k_info_to_howto_rela (bfd * abfd,
  975. arelent * cache_ptr,
  976. Elf_Internal_Rela * dst)
  977. {
  978. unsigned int r_type;
  979. r_type = ELF32_R_TYPE (dst->r_info);
  980. if (r_type >= (unsigned int) R_OR1K_max)
  981. {
  982. /* xgettext:c-format */
  983. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  984. abfd, r_type);
  985. bfd_set_error (bfd_error_bad_value);
  986. return false;
  987. }
  988. cache_ptr->howto = & or1k_elf_howto_table[r_type];
  989. return true;
  990. }
  991. /* Return the relocation value for @tpoff relocations.. */
  992. static bfd_vma
  993. tpoff (struct bfd_link_info *info, bfd_vma address, bool dynamic)
  994. {
  995. struct elf_link_hash_table *htab = elf_hash_table (info);
  996. bfd_vma base;
  997. /* If tls_sec is NULL, we should have signalled an error already. */
  998. if (htab->tls_sec == NULL)
  999. return 0;
  1000. if (dynamic)
  1001. return address - htab->tls_sec->vma;
  1002. else
  1003. {
  1004. /* On or1k, the tp points to just after the tcb, if we have an alignment
  1005. greater than the tcb size we need to offset by the alignment difference. */
  1006. base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power)
  1007. - TCB_SIZE;
  1008. /* The thread pointer on or1k stores the address after the TCB where
  1009. the data is, just compute the difference. No need to compensate
  1010. for the size of TCB. */
  1011. return address - htab->tls_sec->vma + base;
  1012. }
  1013. }
  1014. /* If we have both IE and GD accesses to a symbol the IE relocations should be
  1015. offset by 8 bytes because the got contains both GD and IE entries. */
  1016. static bfd_vma
  1017. or1k_initial_exec_offset (reloc_howto_type *howto, unsigned char tls_type_mask)
  1018. {
  1019. switch (howto->type)
  1020. {
  1021. case R_OR1K_TLS_IE_HI16:
  1022. case R_OR1K_TLS_IE_LO16:
  1023. case R_OR1K_TLS_IE_PG21:
  1024. case R_OR1K_TLS_IE_LO13:
  1025. case R_OR1K_TLS_IE_AHI16:
  1026. return (tls_type_mask & TLS_GD) != 0 ? 8 : 0;
  1027. default:
  1028. return 0;
  1029. }
  1030. }
  1031. /* Like _bfd_final_link_relocate, but handles non-contiguous fields. */
  1032. static bfd_reloc_status_type
  1033. or1k_final_link_relocate (reloc_howto_type *howto, bfd *input_bfd,
  1034. asection *input_section, bfd_byte *contents,
  1035. bfd_vma offset, bfd_vma value)
  1036. {
  1037. bfd_reloc_status_type status = bfd_reloc_ok;
  1038. int size = bfd_get_reloc_size (howto);
  1039. bfd_vma x, place;
  1040. /* Sanity check the address. */
  1041. if (offset + size > bfd_get_section_limit_octets (input_bfd, input_section))
  1042. return bfd_reloc_outofrange;
  1043. place = (input_section->output_section->vma
  1044. + input_section->output_offset
  1045. + (howto->pcrel_offset ? offset : 0));
  1046. switch (howto->type)
  1047. {
  1048. case R_OR1K_AHI16:
  1049. case R_OR1K_GOT_AHI16:
  1050. case R_OR1K_GOTOFF_AHI16:
  1051. case R_OR1K_TLS_IE_AHI16:
  1052. case R_OR1K_TLS_LE_AHI16:
  1053. /* Adjust the operand to match with a signed LO16. */
  1054. value += 0x8000;
  1055. break;
  1056. case R_OR1K_INSN_REL_26:
  1057. value -= place;
  1058. /* Diagnose mis-aligned branch targets. */
  1059. if (value & 3)
  1060. status = bfd_reloc_dangerous;
  1061. break;
  1062. case R_OR1K_PCREL_PG21:
  1063. case R_OR1K_GOT_PG21:
  1064. case R_OR1K_TLS_GD_PG21:
  1065. case R_OR1K_TLS_LDM_PG21:
  1066. case R_OR1K_TLS_IE_PG21:
  1067. value = (value & -8192) - (place & -8192);
  1068. break;
  1069. case R_OR1K_LO13:
  1070. case R_OR1K_GOT_LO13:
  1071. case R_OR1K_TLS_GD_LO13:
  1072. case R_OR1K_TLS_LDM_LO13:
  1073. case R_OR1K_TLS_IE_LO13:
  1074. case R_OR1K_SLO13:
  1075. value &= 8191;
  1076. break;
  1077. default:
  1078. if (howto->pc_relative)
  1079. value -= place;
  1080. break;
  1081. }
  1082. status = bfd_check_overflow (howto->complain_on_overflow,
  1083. howto->bitsize,
  1084. howto->rightshift,
  1085. bfd_arch_bits_per_address (input_bfd),
  1086. value);
  1087. value >>= howto->rightshift;
  1088. /* If we're overwriting the entire destination,
  1089. then no need to read the current contents. */
  1090. if (size == 0 || howto->dst_mask == N_ONES (size))
  1091. x = 0;
  1092. else
  1093. {
  1094. BFD_ASSERT (size == 4);
  1095. x = bfd_get_32 (input_bfd, contents + offset);
  1096. }
  1097. switch (howto->type)
  1098. {
  1099. case R_OR1K_SLO16:
  1100. case R_OR1K_GOTOFF_SLO16:
  1101. case R_OR1K_TLS_LE_SLO16:
  1102. case R_OR1K_SLO13:
  1103. /* The split imm16 field used for stores. */
  1104. x = (x & ~0x3e007ff) | ((value & 0xf800) << 10) | (value & 0x7ff);
  1105. break;
  1106. default:
  1107. {
  1108. bfd_vma fieldmask = howto->dst_mask;
  1109. value <<= howto->bitpos;
  1110. x = (x & ~fieldmask) | (value & fieldmask);
  1111. }
  1112. break;
  1113. }
  1114. /* Put the relocated value back in the object file. */
  1115. switch (size)
  1116. {
  1117. case 0:
  1118. break;
  1119. case 1:
  1120. bfd_put_8 (input_bfd, x, contents + offset);
  1121. break;
  1122. case 2:
  1123. bfd_put_16 (input_bfd, x, contents + offset);
  1124. break;
  1125. case 4:
  1126. bfd_put_32 (input_bfd, x, contents + offset);
  1127. break;
  1128. #ifdef BFD64
  1129. case 8:
  1130. bfd_put_64 (input_bfd, x, contents + offset);
  1131. break;
  1132. #endif
  1133. default:
  1134. _bfd_error_handler
  1135. (_("%pB: Cannot handle relocation value size of %d"),
  1136. input_bfd, size);
  1137. abort ();
  1138. }
  1139. return status;
  1140. }
  1141. /* Relocate an Or1k ELF section.
  1142. The RELOCATE_SECTION function is called by the new ELF backend linker
  1143. to handle the relocations for a section.
  1144. The relocs are always passed as Rela structures; if the section
  1145. actually uses Rel structures, the r_addend field will always be
  1146. zero.
  1147. This function is responsible for adjusting the section contents as
  1148. necessary, and (if using Rela relocs and generating a relocatable
  1149. output file) adjusting the reloc addend as necessary.
  1150. This function does not have to worry about setting the reloc
  1151. address or the reloc symbol index.
  1152. LOCAL_SYMS is a pointer to the swapped in local symbols.
  1153. LOCAL_SECTIONS is an array giving the section in the input file
  1154. corresponding to the st_shndx field of each local symbol.
  1155. The global hash table entry for the global symbols can be found
  1156. via elf_sym_hashes (input_bfd).
  1157. When generating relocatable output, this function must handle
  1158. STB_LOCAL/STT_SECTION symbols specially. The output symbol is
  1159. going to be the section symbol corresponding to the output
  1160. section, which means that the addend must be adjusted
  1161. accordingly. */
  1162. static int
  1163. or1k_elf_relocate_section (bfd *output_bfd,
  1164. struct bfd_link_info *info,
  1165. bfd *input_bfd,
  1166. asection *input_section,
  1167. bfd_byte *contents,
  1168. Elf_Internal_Rela *relocs,
  1169. Elf_Internal_Sym *local_syms,
  1170. asection **local_sections)
  1171. {
  1172. Elf_Internal_Shdr *symtab_hdr;
  1173. struct elf_link_hash_entry **sym_hashes;
  1174. Elf_Internal_Rela *rel;
  1175. Elf_Internal_Rela *relend;
  1176. struct elf_or1k_link_hash_table *htab = or1k_elf_hash_table (info);
  1177. asection *sreloc;
  1178. bfd_vma *local_got_offsets;
  1179. asection *sgot, *splt;
  1180. bfd_vma plt_base, got_base, got_sym_value;
  1181. bool ret_val = true;
  1182. bool saw_gotha = false;
  1183. if (htab == NULL)
  1184. return false;
  1185. local_got_offsets = elf_local_got_offsets (input_bfd);
  1186. sreloc = elf_section_data (input_section)->sreloc;
  1187. splt = htab->root.splt;
  1188. plt_base = 0;
  1189. if (splt != NULL)
  1190. plt_base = splt->output_section->vma + splt->output_offset;
  1191. sgot = htab->root.sgot;
  1192. got_sym_value = got_base = 0;
  1193. if (sgot != NULL)
  1194. {
  1195. struct elf_link_hash_entry *hgot = htab->root.hgot;
  1196. got_sym_value = (hgot->root.u.def.value
  1197. + hgot->root.u.def.section->output_section->vma
  1198. + hgot->root.u.def.section->output_offset);
  1199. got_base = sgot->output_section->vma + sgot->output_offset;
  1200. }
  1201. symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  1202. sym_hashes = elf_sym_hashes (input_bfd);
  1203. relend = relocs + input_section->reloc_count;
  1204. for (rel = relocs; rel < relend; rel++)
  1205. {
  1206. reloc_howto_type *howto;
  1207. unsigned long r_symndx;
  1208. Elf_Internal_Sym *sym;
  1209. asection *sec;
  1210. struct elf_link_hash_entry *h;
  1211. bfd_vma relocation;
  1212. bfd_reloc_status_type r;
  1213. const char *name = NULL;
  1214. int r_type;
  1215. r_type = ELF32_R_TYPE (rel->r_info);
  1216. r_symndx = ELF32_R_SYM (rel->r_info);
  1217. if (r_type == R_OR1K_GNU_VTINHERIT
  1218. || r_type == R_OR1K_GNU_VTENTRY)
  1219. continue;
  1220. if (r_type < 0 || r_type >= (int) R_OR1K_max)
  1221. {
  1222. _bfd_error_handler
  1223. (_("%pB: unknown relocation type %d"),
  1224. input_bfd, (int) r_type);
  1225. bfd_set_error (bfd_error_bad_value);
  1226. ret_val = false;
  1227. continue;
  1228. }
  1229. howto = or1k_elf_howto_table + ELF32_R_TYPE (rel->r_info);
  1230. h = NULL;
  1231. sym = NULL;
  1232. sec = NULL;
  1233. if (r_symndx < symtab_hdr->sh_info)
  1234. {
  1235. sym = local_syms + r_symndx;
  1236. sec = local_sections[r_symndx];
  1237. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  1238. name = bfd_elf_string_from_elf_section
  1239. (input_bfd, symtab_hdr->sh_link, sym->st_name);
  1240. name = name == NULL ? bfd_section_name (sec) : name;
  1241. }
  1242. else
  1243. {
  1244. bool unresolved_reloc, warned, ignored;
  1245. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  1246. r_symndx, symtab_hdr, sym_hashes,
  1247. h, sec, relocation,
  1248. unresolved_reloc, warned, ignored);
  1249. name = h->root.root.string;
  1250. }
  1251. if (sec != NULL && discarded_section (sec))
  1252. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  1253. rel, 1, relend, howto, 0, contents);
  1254. if (bfd_link_relocatable (info))
  1255. continue;
  1256. switch (howto->type)
  1257. {
  1258. case R_OR1K_PLT26:
  1259. case R_OR1K_PLTA26:
  1260. /* If the call is not local, redirect the branch to the PLT.
  1261. Otherwise do nothing to send the branch to the symbol direct. */
  1262. if (!SYMBOL_CALLS_LOCAL (info, h)
  1263. && h->plt.offset != (bfd_vma) -1)
  1264. relocation = plt_base + h->plt.offset;
  1265. /* Addend should be zero. */
  1266. if (rel->r_addend != 0)
  1267. {
  1268. _bfd_error_handler
  1269. (_("%pB: addend should be zero for plt relocations"),
  1270. input_bfd);
  1271. bfd_set_error (bfd_error_bad_value);
  1272. ret_val = false;
  1273. }
  1274. break;
  1275. case R_OR1K_GOT_AHI16:
  1276. case R_OR1K_GOT16:
  1277. case R_OR1K_GOT_PG21:
  1278. case R_OR1K_GOT_LO13:
  1279. {
  1280. bfd_vma off;
  1281. /* Relocation is to the entry for this symbol
  1282. in the global offset table. */
  1283. BFD_ASSERT (sgot != NULL);
  1284. if (h != NULL)
  1285. {
  1286. bool dyn;
  1287. off = h->got.offset;
  1288. BFD_ASSERT (off != (bfd_vma) -1);
  1289. dyn = htab->root.dynamic_sections_created;
  1290. if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  1291. bfd_link_pic (info),
  1292. h)
  1293. || (bfd_link_pic (info)
  1294. && SYMBOL_REFERENCES_LOCAL (info, h)))
  1295. {
  1296. /* This is actually a static link, or it is a -Bsymbolic
  1297. link and the symbol is defined locally, or the symbol
  1298. was forced to be local because of a version file.
  1299. We must initialize this entry in the GOT. Since the
  1300. offset must always be a multiple of 4, we use the least
  1301. significant bit to record whether we have initialized
  1302. it already.
  1303. When doing a dynamic link, we create a .rela.got
  1304. relocation entry to initialize the value. This
  1305. is done in the finish_dynamic_symbol routine. */
  1306. if ((off & 1) != 0)
  1307. off &= ~1;
  1308. else
  1309. {
  1310. /* Write entry in GOT. */
  1311. bfd_put_32 (output_bfd, relocation,
  1312. sgot->contents + off);
  1313. /* Mark GOT entry as having been written. */
  1314. h->got.offset |= 1;
  1315. }
  1316. }
  1317. }
  1318. else
  1319. {
  1320. bfd_byte *loc;
  1321. BFD_ASSERT (local_got_offsets != NULL
  1322. && local_got_offsets[r_symndx] != (bfd_vma) -1);
  1323. /* Get offset into GOT table. */
  1324. off = local_got_offsets[r_symndx];
  1325. /* The offset must always be a multiple of 4. We use
  1326. the least significant bit to record whether we have
  1327. already processed this entry. */
  1328. if ((off & 1) != 0)
  1329. off &= ~1;
  1330. else
  1331. {
  1332. /* Write entry in GOT. */
  1333. bfd_put_32 (output_bfd, relocation, sgot->contents + off);
  1334. if (bfd_link_pic (info))
  1335. {
  1336. asection *srelgot;
  1337. Elf_Internal_Rela outrel;
  1338. /* We need to generate a R_OR1K_RELATIVE reloc
  1339. for the dynamic linker. */
  1340. srelgot = htab->root.srelgot;
  1341. BFD_ASSERT (srelgot != NULL);
  1342. outrel.r_offset = got_base + off;
  1343. outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
  1344. outrel.r_addend = relocation;
  1345. loc = srelgot->contents;
  1346. loc += (srelgot->reloc_count
  1347. * sizeof (Elf32_External_Rela));
  1348. bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
  1349. ++srelgot->reloc_count;
  1350. }
  1351. local_got_offsets[r_symndx] |= 1;
  1352. }
  1353. }
  1354. /* The GOT_PG21 and GOT_LO13 relocs are pc-relative,
  1355. while the GOT16 reloc is GOT relative. */
  1356. relocation = got_base + off;
  1357. if (r_type == R_OR1K_GOT16
  1358. || r_type == R_OR1K_GOT_AHI16)
  1359. relocation -= got_sym_value;
  1360. if (r_type == R_OR1K_GOT_AHI16)
  1361. saw_gotha = true;
  1362. /* If we have a R_OR1K_GOT16 following a R_OR1K_GOT_AHI16
  1363. relocation we assume the code is doing the right thing to avoid
  1364. overflows. */
  1365. if (r_type == R_OR1K_GOT16 && saw_gotha)
  1366. howto = &or1k_elf_got16_no_overflow_howto;
  1367. /* Addend should be zero. */
  1368. if (rel->r_addend != 0)
  1369. {
  1370. _bfd_error_handler
  1371. (_("%pB: addend should be zero for got relocations"),
  1372. input_bfd);
  1373. bfd_set_error (bfd_error_bad_value);
  1374. ret_val = false;
  1375. }
  1376. }
  1377. break;
  1378. case R_OR1K_GOTOFF_LO16:
  1379. case R_OR1K_GOTOFF_HI16:
  1380. case R_OR1K_GOTOFF_AHI16:
  1381. case R_OR1K_GOTOFF_SLO16:
  1382. /* Relocation is offset from GOT. */
  1383. BFD_ASSERT (sgot != NULL);
  1384. if (!SYMBOL_REFERENCES_LOCAL (info, h))
  1385. {
  1386. _bfd_error_handler
  1387. (_("%pB: gotoff relocation against dynamic symbol %s"),
  1388. input_bfd, h->root.root.string);
  1389. ret_val = false;
  1390. bfd_set_error (bfd_error_bad_value);
  1391. }
  1392. relocation -= got_sym_value;
  1393. break;
  1394. case R_OR1K_INSN_REL_26:
  1395. /* For a non-shared link, these will reference plt or call the
  1396. version of actual object. */
  1397. if (bfd_link_pic (info) && !SYMBOL_CALLS_LOCAL (info, h))
  1398. {
  1399. _bfd_error_handler
  1400. (_("%pB: pc-relative relocation against dynamic symbol %s"),
  1401. input_bfd, name);
  1402. ret_val = false;
  1403. bfd_set_error (bfd_error_bad_value);
  1404. }
  1405. break;
  1406. case R_OR1K_PCREL_PG21:
  1407. case R_OR1K_LO13:
  1408. case R_OR1K_SLO13:
  1409. /* For a non-shared link, these will reference either the plt
  1410. or a .dynbss copy of the symbol. */
  1411. if (bfd_link_pic (info) && !SYMBOL_REFERENCES_LOCAL (info, h))
  1412. {
  1413. _bfd_error_handler
  1414. (_("%pB: pc-relative relocation against dynamic symbol %s"),
  1415. input_bfd, name);
  1416. ret_val = false;
  1417. bfd_set_error (bfd_error_bad_value);
  1418. }
  1419. break;
  1420. case R_OR1K_HI_16_IN_INSN:
  1421. case R_OR1K_LO_16_IN_INSN:
  1422. case R_OR1K_AHI16:
  1423. case R_OR1K_SLO16:
  1424. if (bfd_link_pic (info))
  1425. {
  1426. _bfd_error_handler
  1427. (_("%pB: non-pic relocation against symbol %s"),
  1428. input_bfd, name);
  1429. ret_val = false;
  1430. bfd_set_error (bfd_error_bad_value);
  1431. }
  1432. break;
  1433. case R_OR1K_32:
  1434. /* R_OR1K_16? */
  1435. {
  1436. /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
  1437. from removed linkonce sections, or sections discarded by
  1438. a linker script. */
  1439. if (r_symndx == STN_UNDEF
  1440. || (input_section->flags & SEC_ALLOC) == 0)
  1441. break;
  1442. /* Emit a direct relocation if the symbol is dynamic,
  1443. or a RELATIVE reloc for shared objects. We can omit
  1444. RELATIVE relocs to local undefweak symbols. */
  1445. if (bfd_link_pic (info)
  1446. ? (h == NULL
  1447. || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  1448. || h->root.type != bfd_link_hash_undefweak)
  1449. : (h != NULL
  1450. && h->dynindx != -1
  1451. && !h->non_got_ref
  1452. && ((h->def_dynamic && !h->def_regular)
  1453. || h->root.type == bfd_link_hash_undefweak
  1454. || h->root.type == bfd_link_hash_undefined)))
  1455. {
  1456. Elf_Internal_Rela outrel;
  1457. bfd_byte *loc;
  1458. bool skip;
  1459. /* When generating a shared object, these relocations
  1460. are copied into the output file to be resolved at run
  1461. time. */
  1462. BFD_ASSERT (sreloc != NULL);
  1463. skip = false;
  1464. outrel.r_offset =
  1465. _bfd_elf_section_offset (output_bfd, info, input_section,
  1466. rel->r_offset);
  1467. if (outrel.r_offset == (bfd_vma) -1)
  1468. skip = true;
  1469. else if (outrel.r_offset == (bfd_vma) -2)
  1470. skip = true;
  1471. outrel.r_offset += (input_section->output_section->vma
  1472. + input_section->output_offset);
  1473. if (skip)
  1474. memset (&outrel, 0, sizeof outrel);
  1475. else if (SYMBOL_REFERENCES_LOCAL (info, h))
  1476. {
  1477. outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
  1478. outrel.r_addend = relocation + rel->r_addend;
  1479. }
  1480. else
  1481. {
  1482. BFD_ASSERT (h->dynindx != -1);
  1483. outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
  1484. outrel.r_addend = rel->r_addend;
  1485. }
  1486. loc = sreloc->contents;
  1487. loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
  1488. bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
  1489. break;
  1490. }
  1491. break;
  1492. }
  1493. case R_OR1K_TLS_LDM_HI16:
  1494. case R_OR1K_TLS_LDM_LO16:
  1495. case R_OR1K_TLS_LDM_PG21:
  1496. case R_OR1K_TLS_LDM_LO13:
  1497. case R_OR1K_TLS_LDO_HI16:
  1498. case R_OR1K_TLS_LDO_LO16:
  1499. /* TODO: implement support for local dynamic. */
  1500. BFD_FAIL ();
  1501. _bfd_error_handler
  1502. (_("%pB: support for local dynamic not implemented"),
  1503. input_bfd);
  1504. bfd_set_error (bfd_error_bad_value);
  1505. return false;
  1506. case R_OR1K_TLS_GD_HI16:
  1507. case R_OR1K_TLS_GD_LO16:
  1508. case R_OR1K_TLS_GD_PG21:
  1509. case R_OR1K_TLS_GD_LO13:
  1510. case R_OR1K_TLS_IE_HI16:
  1511. case R_OR1K_TLS_IE_LO16:
  1512. case R_OR1K_TLS_IE_PG21:
  1513. case R_OR1K_TLS_IE_LO13:
  1514. case R_OR1K_TLS_IE_AHI16:
  1515. {
  1516. bfd_vma gotoff;
  1517. Elf_Internal_Rela rela;
  1518. asection *srelgot;
  1519. bfd_byte *loc;
  1520. bool dynamic;
  1521. int indx = 0;
  1522. unsigned char tls_type;
  1523. srelgot = htab->root.srelgot;
  1524. /* Mark as TLS related GOT entry by setting
  1525. bit 2 to indcate TLS and bit 1 to indicate GOT. */
  1526. if (h != NULL)
  1527. {
  1528. gotoff = h->got.offset;
  1529. tls_type = ((struct elf_or1k_link_hash_entry *) h)->tls_type;
  1530. h->got.offset |= 3;
  1531. }
  1532. else
  1533. {
  1534. unsigned char *local_tls_type;
  1535. gotoff = local_got_offsets[r_symndx];
  1536. local_tls_type = (unsigned char *) elf_or1k_local_tls_type (input_bfd);
  1537. tls_type = local_tls_type == NULL ? TLS_NONE
  1538. : local_tls_type[r_symndx];
  1539. local_got_offsets[r_symndx] |= 3;
  1540. }
  1541. /* Only process the relocation once. */
  1542. if ((gotoff & 1) != 0)
  1543. {
  1544. gotoff += or1k_initial_exec_offset (howto, tls_type);
  1545. /* The PG21 and LO13 relocs are pc-relative, while the
  1546. rest are GOT relative. */
  1547. relocation = got_base + (gotoff & ~3);
  1548. if (!(r_type == R_OR1K_TLS_GD_PG21
  1549. || r_type == R_OR1K_TLS_GD_LO13
  1550. || r_type == R_OR1K_TLS_IE_PG21
  1551. || r_type == R_OR1K_TLS_IE_LO13))
  1552. relocation -= got_sym_value;
  1553. break;
  1554. }
  1555. BFD_ASSERT (elf_hash_table (info)->hgot == NULL
  1556. || elf_hash_table (info)->hgot->root.u.def.value == 0);
  1557. if (h != NULL)
  1558. {
  1559. bool dyn = htab->root.dynamic_sections_created;
  1560. bool pic = bfd_link_pic (info);
  1561. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, pic, h)
  1562. && (!pic || !SYMBOL_REFERENCES_LOCAL (info, h)))
  1563. indx = h->dynindx;
  1564. }
  1565. /* Dynamic entries will require relocations. If we do not need
  1566. them we will just use the default R_OR1K_NONE and
  1567. not set anything. */
  1568. dynamic = (bfd_link_pic (info) || indx != 0)
  1569. && (h == NULL
  1570. || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  1571. || h->root.type != bfd_link_hash_undefweak);
  1572. /* Shared GD. */
  1573. if (dynamic && ((tls_type & TLS_GD) != 0))
  1574. {
  1575. int i;
  1576. /* Add DTPMOD and DTPOFF GOT and rela entries. */
  1577. for (i = 0; i < 2; ++i)
  1578. {
  1579. BFD_ASSERT (srelgot->contents != NULL);
  1580. rela.r_offset = got_base + gotoff + i*4;
  1581. if (h != NULL && h->dynindx != -1)
  1582. {
  1583. rela.r_info = ELF32_R_INFO (h->dynindx,
  1584. (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
  1585. rela.r_addend = 0;
  1586. }
  1587. else
  1588. {
  1589. rela.r_info = ELF32_R_INFO (0,
  1590. (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
  1591. rela.r_addend =
  1592. (i == 0 ? 0 : tpoff (info, relocation, dynamic));
  1593. }
  1594. loc = srelgot->contents;
  1595. loc += (srelgot->reloc_count++
  1596. * sizeof (Elf32_External_Rela));
  1597. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1598. bfd_put_32 (output_bfd, 0, sgot->contents + gotoff + i*4);
  1599. }
  1600. }
  1601. /* Static GD. */
  1602. else if ((tls_type & TLS_GD) != 0)
  1603. {
  1604. bfd_put_32 (output_bfd, 1, sgot->contents + gotoff);
  1605. bfd_put_32 (output_bfd, tpoff (info, relocation, dynamic),
  1606. sgot->contents + gotoff + 4);
  1607. }
  1608. gotoff += or1k_initial_exec_offset (howto, tls_type);
  1609. /* Shared IE. */
  1610. if (dynamic && ((tls_type & TLS_IE) != 0))
  1611. {
  1612. BFD_ASSERT (srelgot->contents != NULL);
  1613. /* Add TPOFF GOT and rela entries. */
  1614. rela.r_offset = got_base + gotoff;
  1615. if (h != NULL && h->dynindx != -1)
  1616. {
  1617. rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_TLS_TPOFF);
  1618. rela.r_addend = 0;
  1619. }
  1620. else
  1621. {
  1622. rela.r_info = ELF32_R_INFO (0, R_OR1K_TLS_TPOFF);
  1623. rela.r_addend = tpoff (info, relocation, dynamic);
  1624. }
  1625. loc = srelgot->contents;
  1626. loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
  1627. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1628. bfd_put_32 (output_bfd, 0, sgot->contents + gotoff);
  1629. }
  1630. /* Static IE. */
  1631. else if ((tls_type & TLS_IE) != 0)
  1632. bfd_put_32 (output_bfd, tpoff (info, relocation, dynamic),
  1633. sgot->contents + gotoff);
  1634. /* The PG21 and LO13 relocs are pc-relative, while the
  1635. rest are GOT relative. */
  1636. relocation = got_base + gotoff;
  1637. if (!(r_type == R_OR1K_TLS_GD_PG21
  1638. || r_type == R_OR1K_TLS_GD_LO13
  1639. || r_type == R_OR1K_TLS_IE_PG21
  1640. || r_type == R_OR1K_TLS_IE_LO13))
  1641. relocation -= got_sym_value;
  1642. }
  1643. break;
  1644. case R_OR1K_TLS_LE_HI16:
  1645. case R_OR1K_TLS_LE_LO16:
  1646. case R_OR1K_TLS_LE_AHI16:
  1647. case R_OR1K_TLS_LE_SLO16:
  1648. /* Relocation is offset from TP. */
  1649. relocation = tpoff (info, relocation, 0);
  1650. break;
  1651. case R_OR1K_TLS_DTPMOD:
  1652. case R_OR1K_TLS_DTPOFF:
  1653. case R_OR1K_TLS_TPOFF:
  1654. /* These are resolved dynamically on load and shouldn't
  1655. be used as linker input. */
  1656. BFD_FAIL ();
  1657. _bfd_error_handler
  1658. (_("%pB: will not resolve runtime TLS relocation"),
  1659. input_bfd);
  1660. bfd_set_error (bfd_error_bad_value);
  1661. return false;
  1662. default:
  1663. break;
  1664. }
  1665. r = or1k_final_link_relocate (howto, input_bfd, input_section, contents,
  1666. rel->r_offset, relocation + rel->r_addend);
  1667. if (r != bfd_reloc_ok)
  1668. {
  1669. const char *msg = NULL;
  1670. switch (r)
  1671. {
  1672. case bfd_reloc_overflow:
  1673. (*info->callbacks->reloc_overflow)
  1674. (info, (h ? &h->root : NULL), name, howto->name,
  1675. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  1676. break;
  1677. case bfd_reloc_undefined:
  1678. (*info->callbacks->undefined_symbol)
  1679. (info, name, input_bfd, input_section, rel->r_offset, true);
  1680. break;
  1681. case bfd_reloc_outofrange:
  1682. msg = _("internal error: out of range error");
  1683. break;
  1684. case bfd_reloc_notsupported:
  1685. msg = _("internal error: unsupported relocation error");
  1686. break;
  1687. case bfd_reloc_dangerous:
  1688. msg = _("internal error: dangerous relocation");
  1689. break;
  1690. default:
  1691. msg = _("internal error: unknown error");
  1692. break;
  1693. }
  1694. if (msg)
  1695. (*info->callbacks->warning) (info, msg, name, input_bfd,
  1696. input_section, rel->r_offset);
  1697. }
  1698. }
  1699. return ret_val;
  1700. }
  1701. /* Return the section that should be marked against GC for a given
  1702. relocation. */
  1703. static asection *
  1704. or1k_elf_gc_mark_hook (asection *sec,
  1705. struct bfd_link_info *info,
  1706. Elf_Internal_Rela *rel,
  1707. struct elf_link_hash_entry *h,
  1708. Elf_Internal_Sym *sym)
  1709. {
  1710. if (h != NULL)
  1711. switch (ELF32_R_TYPE (rel->r_info))
  1712. {
  1713. case R_OR1K_GNU_VTINHERIT:
  1714. case R_OR1K_GNU_VTENTRY:
  1715. return NULL;
  1716. }
  1717. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  1718. }
  1719. /* Look through the relocs for a section during the first phase. */
  1720. static bool
  1721. or1k_elf_check_relocs (bfd *abfd,
  1722. struct bfd_link_info *info,
  1723. asection *sec,
  1724. const Elf_Internal_Rela *relocs)
  1725. {
  1726. Elf_Internal_Shdr *symtab_hdr;
  1727. struct elf_link_hash_entry **sym_hashes;
  1728. const Elf_Internal_Rela *rel;
  1729. const Elf_Internal_Rela *rel_end;
  1730. struct elf_or1k_link_hash_table *htab;
  1731. bfd *dynobj;
  1732. asection *sreloc = NULL;
  1733. if (bfd_link_relocatable (info))
  1734. return true;
  1735. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  1736. sym_hashes = elf_sym_hashes (abfd);
  1737. htab = or1k_elf_hash_table (info);
  1738. if (htab == NULL)
  1739. return false;
  1740. dynobj = htab->root.dynobj;
  1741. rel_end = relocs + sec->reloc_count;
  1742. for (rel = relocs; rel < rel_end; rel++)
  1743. {
  1744. struct elf_link_hash_entry *h;
  1745. unsigned long r_symndx;
  1746. unsigned char tls_type;
  1747. int r_type;
  1748. r_symndx = ELF32_R_SYM (rel->r_info);
  1749. if (r_symndx < symtab_hdr->sh_info)
  1750. h = NULL;
  1751. else
  1752. {
  1753. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  1754. while (h->root.type == bfd_link_hash_indirect
  1755. || h->root.type == bfd_link_hash_warning)
  1756. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1757. }
  1758. r_type = ELF32_R_TYPE (rel->r_info);
  1759. switch (r_type)
  1760. {
  1761. case R_OR1K_TLS_GD_HI16:
  1762. case R_OR1K_TLS_GD_LO16:
  1763. case R_OR1K_TLS_GD_PG21:
  1764. case R_OR1K_TLS_GD_LO13:
  1765. tls_type = TLS_GD;
  1766. break;
  1767. case R_OR1K_TLS_LDM_HI16:
  1768. case R_OR1K_TLS_LDM_LO16:
  1769. case R_OR1K_TLS_LDM_PG21:
  1770. case R_OR1K_TLS_LDM_LO13:
  1771. case R_OR1K_TLS_LDO_HI16:
  1772. case R_OR1K_TLS_LDO_LO16:
  1773. tls_type = TLS_LD;
  1774. break;
  1775. case R_OR1K_TLS_IE_HI16:
  1776. case R_OR1K_TLS_IE_LO16:
  1777. case R_OR1K_TLS_IE_PG21:
  1778. case R_OR1K_TLS_IE_LO13:
  1779. case R_OR1K_TLS_IE_AHI16:
  1780. tls_type = TLS_IE;
  1781. break;
  1782. case R_OR1K_TLS_LE_HI16:
  1783. case R_OR1K_TLS_LE_LO16:
  1784. case R_OR1K_TLS_LE_AHI16:
  1785. case R_OR1K_TLS_LE_SLO16:
  1786. tls_type = TLS_LE;
  1787. break;
  1788. default:
  1789. tls_type = TLS_NONE;
  1790. }
  1791. /* Record TLS type. */
  1792. if (h != NULL)
  1793. ((struct elf_or1k_link_hash_entry *) h)->tls_type |= tls_type;
  1794. else
  1795. {
  1796. unsigned char *local_tls_type;
  1797. /* This is a TLS type record for a local symbol. */
  1798. local_tls_type = (unsigned char *) elf_or1k_local_tls_type (abfd);
  1799. if (local_tls_type == NULL)
  1800. {
  1801. bfd_size_type size;
  1802. size = symtab_hdr->sh_info;
  1803. local_tls_type = bfd_zalloc (abfd, size);
  1804. if (local_tls_type == NULL)
  1805. return false;
  1806. elf_or1k_local_tls_type (abfd) = local_tls_type;
  1807. }
  1808. local_tls_type[r_symndx] |= tls_type;
  1809. }
  1810. switch (r_type)
  1811. {
  1812. /* This relocation describes the C++ object vtable hierarchy.
  1813. Reconstruct it for later use during GC. */
  1814. case R_OR1K_GNU_VTINHERIT:
  1815. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  1816. return false;
  1817. break;
  1818. /* This relocation describes which C++ vtable entries are actually
  1819. used. Record for later use during GC. */
  1820. case R_OR1K_GNU_VTENTRY:
  1821. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  1822. return false;
  1823. break;
  1824. /* This relocation requires .plt entry. */
  1825. case R_OR1K_PLTA26:
  1826. htab->saw_plta = true;
  1827. /* FALLTHRU */
  1828. case R_OR1K_PLT26:
  1829. if (h != NULL)
  1830. {
  1831. h->needs_plt = 1;
  1832. h->plt.refcount += 1;
  1833. }
  1834. break;
  1835. case R_OR1K_GOT_AHI16:
  1836. case R_OR1K_GOT16:
  1837. case R_OR1K_GOT_PG21:
  1838. case R_OR1K_GOT_LO13:
  1839. case R_OR1K_TLS_GD_HI16:
  1840. case R_OR1K_TLS_GD_LO16:
  1841. case R_OR1K_TLS_GD_PG21:
  1842. case R_OR1K_TLS_GD_LO13:
  1843. case R_OR1K_TLS_IE_HI16:
  1844. case R_OR1K_TLS_IE_LO16:
  1845. case R_OR1K_TLS_IE_PG21:
  1846. case R_OR1K_TLS_IE_LO13:
  1847. case R_OR1K_TLS_IE_AHI16:
  1848. if (h != NULL)
  1849. h->got.refcount += 1;
  1850. else
  1851. {
  1852. bfd_signed_vma *local_got_refcounts;
  1853. /* This is a global offset table entry for a local symbol. */
  1854. local_got_refcounts = elf_local_got_refcounts (abfd);
  1855. if (local_got_refcounts == NULL)
  1856. {
  1857. bfd_size_type size;
  1858. size = symtab_hdr->sh_info;
  1859. size *= sizeof (bfd_signed_vma);
  1860. local_got_refcounts = bfd_zalloc (abfd, size);
  1861. if (local_got_refcounts == NULL)
  1862. return false;
  1863. elf_local_got_refcounts (abfd) = local_got_refcounts;
  1864. }
  1865. local_got_refcounts[r_symndx] += 1;
  1866. }
  1867. /* FALLTHRU */
  1868. case R_OR1K_GOTOFF_HI16:
  1869. case R_OR1K_GOTOFF_LO16:
  1870. case R_OR1K_GOTOFF_AHI16:
  1871. case R_OR1K_GOTOFF_SLO16:
  1872. if (htab->root.sgot == NULL)
  1873. {
  1874. if (dynobj == NULL)
  1875. htab->root.dynobj = dynobj = abfd;
  1876. if (!_bfd_elf_create_got_section (dynobj, info))
  1877. return false;
  1878. }
  1879. break;
  1880. case R_OR1K_INSN_REL_26:
  1881. case R_OR1K_HI_16_IN_INSN:
  1882. case R_OR1K_LO_16_IN_INSN:
  1883. case R_OR1K_AHI16:
  1884. case R_OR1K_SLO16:
  1885. case R_OR1K_32:
  1886. case R_OR1K_PCREL_PG21:
  1887. case R_OR1K_LO13:
  1888. case R_OR1K_SLO13:
  1889. {
  1890. if (h != NULL && !bfd_link_pic (info))
  1891. {
  1892. /* We may need a copy reloc. */
  1893. h->non_got_ref = 1;
  1894. /* We may also need a .plt entry. */
  1895. h->plt.refcount += 1;
  1896. if (r_type != R_OR1K_INSN_REL_26)
  1897. h->pointer_equality_needed = 1;
  1898. }
  1899. /* If we are creating a shared library, and this is a reloc
  1900. against a global symbol, or a non PC relative reloc
  1901. against a local symbol, then we need to copy the reloc
  1902. into the shared library. However, if we are linking with
  1903. -Bsymbolic, we do not need to copy a reloc against a
  1904. global symbol which is defined in an object we are
  1905. including in the link (i.e., DEF_REGULAR is set). At
  1906. this point we have not seen all the input files, so it is
  1907. possible that DEF_REGULAR is not set now but will be set
  1908. later (it is never cleared). In case of a weak definition,
  1909. DEF_REGULAR may be cleared later by a strong definition in
  1910. a shared library. We account for that possibility below by
  1911. storing information in the relocs_copied field of the hash
  1912. table entry. A similar situation occurs when creating
  1913. shared libraries and symbol visibility changes render the
  1914. symbol local.
  1915. If on the other hand, we are creating an executable, we
  1916. may need to keep relocations for symbols satisfied by a
  1917. dynamic library if we manage to avoid copy relocs for the
  1918. symbol. */
  1919. if ((bfd_link_pic (info)
  1920. && (sec->flags & SEC_ALLOC) != 0
  1921. && (r_type != R_OR1K_INSN_REL_26
  1922. || (h != NULL
  1923. && (!SYMBOLIC_BIND (info, h)
  1924. || h->root.type == bfd_link_hash_defweak
  1925. || !h->def_regular))))
  1926. || (!bfd_link_pic (info)
  1927. && (sec->flags & SEC_ALLOC) != 0
  1928. && h != NULL
  1929. && (h->root.type == bfd_link_hash_defweak
  1930. || !h->def_regular)))
  1931. {
  1932. struct elf_dyn_relocs *sec_relocs;
  1933. struct elf_dyn_relocs **head;
  1934. /* When creating a shared object, we must copy these
  1935. relocs into the output file. We create a reloc
  1936. section in dynobj and make room for the reloc. */
  1937. if (sreloc == NULL)
  1938. {
  1939. const char *name;
  1940. unsigned int strndx = elf_elfheader (abfd)->e_shstrndx;
  1941. unsigned int shnam = _bfd_elf_single_rel_hdr (sec)->sh_name;
  1942. name = bfd_elf_string_from_elf_section (abfd, strndx, shnam);
  1943. if (name == NULL)
  1944. return false;
  1945. if (!startswith (name, ".rela")
  1946. || strcmp (bfd_section_name (sec), name + 5) != 0)
  1947. {
  1948. _bfd_error_handler
  1949. /* xgettext:c-format */
  1950. (_("%pB: bad relocation section name `%s\'"),
  1951. abfd, name);
  1952. }
  1953. if (htab->root.dynobj == NULL)
  1954. htab->root.dynobj = abfd;
  1955. dynobj = htab->root.dynobj;
  1956. sreloc = bfd_get_section_by_name (dynobj, name);
  1957. if (sreloc == NULL)
  1958. {
  1959. sreloc = _bfd_elf_make_dynamic_reloc_section
  1960. (sec, dynobj, 2, abfd, /*rela?*/ true);
  1961. if (sreloc == NULL)
  1962. return false;
  1963. }
  1964. elf_section_data (sec)->sreloc = sreloc;
  1965. }
  1966. /* If this is a global symbol, we count the number of
  1967. relocations we need for this symbol. */
  1968. if (h != NULL)
  1969. head = &h->dyn_relocs;
  1970. else
  1971. {
  1972. /* Track dynamic relocs needed for local syms too.
  1973. We really need local syms available to do this
  1974. easily. Oh well. */
  1975. asection *s;
  1976. Elf_Internal_Sym *isym;
  1977. void *vpp;
  1978. isym = bfd_sym_from_r_symndx (&htab->root.sym_cache,
  1979. abfd, r_symndx);
  1980. if (isym == NULL)
  1981. return false;
  1982. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  1983. if (s == NULL)
  1984. return false;
  1985. vpp = &elf_section_data (s)->local_dynrel;
  1986. head = (struct elf_dyn_relocs **) vpp;
  1987. }
  1988. sec_relocs = *head;
  1989. /* Allocate this sections dynamic reolcations structure if this
  1990. is a new section. */
  1991. if (sec_relocs == NULL || sec_relocs->sec != sec)
  1992. {
  1993. size_t amt = sizeof *sec_relocs;
  1994. sec_relocs = ((struct elf_dyn_relocs *)
  1995. bfd_alloc (htab->root.dynobj, amt));
  1996. if (sec_relocs == NULL)
  1997. return false;
  1998. sec_relocs->next = *head;
  1999. *head = sec_relocs;
  2000. sec_relocs->sec = sec;
  2001. sec_relocs->count = 0;
  2002. sec_relocs->pc_count = 0;
  2003. }
  2004. sec_relocs->count += 1;
  2005. if (r_type == R_OR1K_INSN_REL_26)
  2006. sec_relocs->pc_count += 1;
  2007. }
  2008. }
  2009. break;
  2010. }
  2011. }
  2012. return true;
  2013. }
  2014. static void
  2015. or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj,
  2016. unsigned insns[], size_t insn_count)
  2017. {
  2018. unsigned nodelay = elf_elfheader (output_bfd)->e_flags & EF_OR1K_NODELAY;
  2019. unsigned output_insns[PLT_MAX_INSN_COUNT];
  2020. /* Copy instructions into the output buffer. */
  2021. for (size_t i = 0; i < insn_count; i++)
  2022. output_insns[i] = insns[i];
  2023. /* Honor the no-delay-slot setting. */
  2024. if (insns[insn_count-1] == OR1K_NOP)
  2025. {
  2026. unsigned slot1, slot2;
  2027. if (nodelay)
  2028. slot1 = insns[insn_count-2], slot2 = insnj;
  2029. else
  2030. slot1 = insnj, slot2 = insns[insn_count-2];
  2031. output_insns[insn_count-2] = slot1;
  2032. output_insns[insn_count-1] = slot2;
  2033. output_insns[insn_count] = OR1K_NOP;
  2034. }
  2035. else
  2036. {
  2037. unsigned slot1, slot2;
  2038. if (nodelay)
  2039. slot1 = insns[insn_count-1], slot2 = insnj;
  2040. else
  2041. slot1 = insnj, slot2 = insns[insn_count-1];
  2042. output_insns[insn_count-1] = slot1;
  2043. output_insns[insn_count] = slot2;
  2044. }
  2045. /* Write out the output buffer. */
  2046. for (size_t i = 0; i < (insn_count+1); i++)
  2047. bfd_put_32 (output_bfd, output_insns[i], contents + (i*4));
  2048. }
  2049. /* Finish up the dynamic sections. */
  2050. static bool
  2051. or1k_elf_finish_dynamic_sections (bfd *output_bfd,
  2052. struct bfd_link_info *info)
  2053. {
  2054. bfd *dynobj;
  2055. asection *sdyn, *sgot;
  2056. struct elf_or1k_link_hash_table *htab;
  2057. htab = or1k_elf_hash_table (info);
  2058. if (htab == NULL)
  2059. return false;
  2060. dynobj = htab->root.dynobj;
  2061. sgot = htab->root.sgotplt;
  2062. sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
  2063. if (htab->root.dynamic_sections_created)
  2064. {
  2065. asection *splt;
  2066. Elf32_External_Dyn *dyncon, *dynconend;
  2067. BFD_ASSERT (sgot != NULL && sdyn != NULL);
  2068. dyncon = (Elf32_External_Dyn *) sdyn->contents;
  2069. dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
  2070. for (; dyncon < dynconend; dyncon++)
  2071. {
  2072. Elf_Internal_Dyn dyn;
  2073. asection *s;
  2074. bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
  2075. switch (dyn.d_tag)
  2076. {
  2077. default:
  2078. continue;
  2079. case DT_PLTGOT:
  2080. s = htab->root.sgotplt;
  2081. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  2082. break;
  2083. case DT_JMPREL:
  2084. s = htab->root.srelplt;
  2085. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  2086. break;
  2087. case DT_PLTRELSZ:
  2088. s = htab->root.srelplt;
  2089. dyn.d_un.d_val = s->size;
  2090. break;
  2091. }
  2092. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  2093. }
  2094. /* Fill in the first entry in the procedure linkage table. */
  2095. splt = htab->root.splt;
  2096. if (splt && splt->size > 0)
  2097. {
  2098. unsigned plt[PLT_MAX_INSN_COUNT];
  2099. size_t plt_insn_count = 3;
  2100. bfd_vma got_addr = sgot->output_section->vma + sgot->output_offset;
  2101. /* Note we force 16 byte alignment on the .got, so that
  2102. the movhi/adrp can be shared between the two loads. */
  2103. if (htab->saw_plta)
  2104. {
  2105. bfd_vma pc = splt->output_section->vma + splt->output_offset;
  2106. unsigned pa = ((got_addr >> 13) - (pc >> 13)) & 0x1fffff;
  2107. unsigned po = got_addr & 0x1fff;
  2108. plt[0] = OR1K_ADRP(12) | pa;
  2109. plt[1] = OR1K_LWZ(15,12) | (po + 8);
  2110. plt[2] = OR1K_LWZ(12,12) | (po + 4);
  2111. }
  2112. else if (bfd_link_pic (info))
  2113. {
  2114. plt[0] = OR1K_LWZ(15, 16) | 8; /* .got+8 */
  2115. plt[1] = OR1K_LWZ(12, 16) | 4; /* .got+4 */
  2116. plt[2] = OR1K_NOP;
  2117. }
  2118. else
  2119. {
  2120. unsigned ha = ((got_addr + 0x8000) >> 16) & 0xffff;
  2121. unsigned lo = got_addr & 0xffff;
  2122. plt[0] = OR1K_MOVHI(12) | ha;
  2123. plt[1] = OR1K_LWZ(15,12) | (lo + 8);
  2124. plt[2] = OR1K_LWZ(12,12) | (lo + 4);
  2125. }
  2126. or1k_write_plt_entry (output_bfd, splt->contents, OR1K_JR(15),
  2127. plt, plt_insn_count);
  2128. elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
  2129. }
  2130. }
  2131. /* Set the first entry in the global offset table to the address of
  2132. the dynamic section. */
  2133. if (sgot && sgot->size > 0)
  2134. {
  2135. if (sdyn == NULL)
  2136. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
  2137. else
  2138. bfd_put_32 (output_bfd,
  2139. sdyn->output_section->vma + sdyn->output_offset,
  2140. sgot->contents);
  2141. elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
  2142. }
  2143. if (htab->root.sgot && htab->root.sgot->size > 0)
  2144. elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize = 4;
  2145. return true;
  2146. }
  2147. /* Finish up dynamic symbol handling. We set the contents of various
  2148. dynamic sections here. */
  2149. static bool
  2150. or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
  2151. struct bfd_link_info *info,
  2152. struct elf_link_hash_entry *h,
  2153. Elf_Internal_Sym *sym)
  2154. {
  2155. struct elf_or1k_link_hash_table *htab;
  2156. bfd_byte *loc;
  2157. htab = or1k_elf_hash_table (info);
  2158. if (htab == NULL)
  2159. return false;
  2160. if (h->plt.offset != (bfd_vma) -1)
  2161. {
  2162. unsigned int plt[PLT_MAX_INSN_COUNT];
  2163. size_t plt_insn_count = 3;
  2164. asection *splt;
  2165. asection *sgot;
  2166. asection *srela;
  2167. bfd_vma plt_base_addr;
  2168. bfd_vma plt_addr;
  2169. bfd_vma plt_index;
  2170. bfd_vma plt_reloc;
  2171. bfd_vma got_base_addr;
  2172. bfd_vma got_offset;
  2173. bfd_vma got_addr;
  2174. Elf_Internal_Rela rela;
  2175. bool large_plt_entry;
  2176. /* This symbol has an entry in the procedure linkage table. Set
  2177. it up. */
  2178. BFD_ASSERT (h->dynindx != -1);
  2179. splt = htab->root.splt;
  2180. sgot = htab->root.sgotplt;
  2181. srela = htab->root.srelplt;
  2182. BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
  2183. plt_base_addr = splt->output_section->vma + splt->output_offset;
  2184. got_base_addr = sgot->output_section->vma + sgot->output_offset;
  2185. /* Get the index in the procedure linkage table which
  2186. corresponds to this symbol. This is the index of this symbol
  2187. in all the symbols for which we are making plt entries. The
  2188. first entry in the procedure linkage table is reserved. */
  2189. plt_index = ((struct elf_or1k_link_hash_entry *) h)->plt_index;
  2190. plt_addr = plt_base_addr + h->plt.offset;
  2191. plt_reloc = plt_index * sizeof (Elf32_External_Rela);
  2192. large_plt_entry = (elf_or1k_plt_entry_size (plt_index)
  2193. == PLT_ENTRY_SIZE_LARGE);
  2194. /* Get the offset into the .got table of the entry that
  2195. corresponds to this function. Each .got entry is 4 bytes.
  2196. The first three are reserved. */
  2197. got_offset = (plt_index + 3) * 4;
  2198. got_addr = got_base_addr + got_offset;
  2199. /* Fill in the entry in the procedure linkage table. */
  2200. if (htab->saw_plta)
  2201. {
  2202. unsigned pa = ((got_addr >> 13) - (plt_addr >> 13)) & 0x1fffff;
  2203. unsigned po = (got_addr & 0x1fff);
  2204. plt[0] = OR1K_ADRP(12) | pa;
  2205. plt[1] = OR1K_LWZ(12,12) | po;
  2206. plt[2] = OR1K_ORI0(11) | plt_reloc;
  2207. }
  2208. else if (bfd_link_pic (info))
  2209. {
  2210. if (large_plt_entry)
  2211. {
  2212. unsigned gotha = ((got_offset + 0x8000) >> 16) & 0xffff;
  2213. unsigned got = got_offset & 0xffff;
  2214. unsigned pltrelhi = (plt_reloc >> 16) & 0xffff;
  2215. unsigned pltrello = plt_reloc & 0xffff;
  2216. plt[0] = OR1K_MOVHI(12) | gotha;
  2217. plt[1] = OR1K_ADD(12,12,16);
  2218. plt[2] = OR1K_LWZ(12,12) | got;
  2219. plt[3] = OR1K_MOVHI(11) | pltrelhi;
  2220. plt[4] = OR1K_ORI(11,11) | pltrello;
  2221. plt_insn_count = 5;
  2222. }
  2223. else
  2224. {
  2225. plt[0] = OR1K_LWZ(12,16) | got_offset;
  2226. plt[1] = OR1K_ORI0(11) | plt_reloc;
  2227. plt[2] = OR1K_NOP;
  2228. }
  2229. }
  2230. else
  2231. {
  2232. unsigned ha = ((got_addr + 0x8000) >> 16) & 0xffff;
  2233. unsigned lo = got_addr & 0xffff;
  2234. plt[0] = OR1K_MOVHI(12) | ha;
  2235. plt[1] = OR1K_LWZ(12,12) | lo;
  2236. plt[2] = OR1K_ORI0(11) | plt_reloc;
  2237. }
  2238. /* For large code model we fixup the non-PIC PLT relocation instructions
  2239. here. */
  2240. if (large_plt_entry && !bfd_link_pic (info))
  2241. {
  2242. unsigned pltrelhi = (plt_reloc >> 16) & 0xffff;
  2243. unsigned pltrello = plt_reloc & 0xffff;
  2244. plt[2] = OR1K_MOVHI(11) | pltrelhi;
  2245. plt[3] = OR1K_ORI(11,11) | pltrello;
  2246. plt[4] = OR1K_NOP;
  2247. plt_insn_count = 5;
  2248. }
  2249. or1k_write_plt_entry (output_bfd, splt->contents + h->plt.offset,
  2250. OR1K_JR(12), plt, plt_insn_count);
  2251. /* Fill in the entry in the global offset table. We initialize it to
  2252. point to the top of the plt. This is done to lazy lookup the actual
  2253. symbol as the first plt entry will be setup by libc to call the
  2254. runtime dynamic linker. */
  2255. bfd_put_32 (output_bfd, plt_base_addr, sgot->contents + got_offset);
  2256. /* Fill in the entry in the .rela.plt section. */
  2257. rela.r_offset = got_addr;
  2258. rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_JMP_SLOT);
  2259. rela.r_addend = 0;
  2260. loc = srela->contents;
  2261. loc += plt_index * sizeof (Elf32_External_Rela);
  2262. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  2263. if (!h->def_regular)
  2264. {
  2265. /* Mark the symbol as undefined, rather than as defined in
  2266. the .plt section. Leave the value alone. */
  2267. sym->st_shndx = SHN_UNDEF;
  2268. }
  2269. }
  2270. if (h->got.offset != (bfd_vma) -1
  2271. && (h->got.offset & 2) == 0) /* Homemade TLS check. */
  2272. {
  2273. asection *sgot;
  2274. asection *srelgot;
  2275. Elf_Internal_Rela rela;
  2276. /* This symbol has an entry in the global offset table. Set it
  2277. up. */
  2278. sgot = htab->root.sgot;
  2279. srelgot = htab->root.srelgot;
  2280. BFD_ASSERT (sgot != NULL && srelgot != NULL);
  2281. rela.r_offset = (sgot->output_section->vma
  2282. + sgot->output_offset
  2283. + (h->got.offset &~ 1));
  2284. /* If this is a -Bsymbolic link, and the symbol is defined
  2285. locally, we just want to emit a RELATIVE reloc. Likewise if
  2286. the symbol was forced to be local because of a version file.
  2287. The entry in the global offset table will already have been
  2288. initialized in the relocate_section function. */
  2289. if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
  2290. {
  2291. rela.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
  2292. rela.r_addend = (h->root.u.def.value
  2293. + h->root.u.def.section->output_section->vma
  2294. + h->root.u.def.section->output_offset);
  2295. }
  2296. else
  2297. {
  2298. BFD_ASSERT ((h->got.offset & 1) == 0);
  2299. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
  2300. rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_GLOB_DAT);
  2301. rela.r_addend = 0;
  2302. }
  2303. loc = srelgot->contents;
  2304. loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
  2305. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  2306. ++srelgot->reloc_count;
  2307. }
  2308. if (h->needs_copy)
  2309. {
  2310. asection *s;
  2311. Elf_Internal_Rela rela;
  2312. /* This symbols needs a copy reloc. Set it up. */
  2313. BFD_ASSERT (h->dynindx != -1
  2314. && (h->root.type == bfd_link_hash_defined
  2315. || h->root.type == bfd_link_hash_defweak));
  2316. rela.r_offset = (h->root.u.def.value
  2317. + h->root.u.def.section->output_section->vma
  2318. + h->root.u.def.section->output_offset);
  2319. rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_COPY);
  2320. rela.r_addend = 0;
  2321. if (h->root.u.def.section == htab->root.sdynrelro)
  2322. s = htab->root.sreldynrelro;
  2323. else
  2324. s = htab->root.srelbss;
  2325. loc = s->contents + s->reloc_count * sizeof (Elf32_External_Rela);
  2326. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  2327. ++s->reloc_count;
  2328. }
  2329. /* Mark some specially defined symbols as absolute. */
  2330. if (strcmp (h->root.root.string, "_DYNAMIC") == 0
  2331. || h == htab->root.hgot)
  2332. sym->st_shndx = SHN_ABS;
  2333. return true;
  2334. }
  2335. static enum elf_reloc_type_class
  2336. or1k_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
  2337. const asection *rel_sec ATTRIBUTE_UNUSED,
  2338. const Elf_Internal_Rela *rela)
  2339. {
  2340. switch ((int) ELF32_R_TYPE (rela->r_info))
  2341. {
  2342. case R_OR1K_RELATIVE: return reloc_class_relative;
  2343. case R_OR1K_JMP_SLOT: return reloc_class_plt;
  2344. case R_OR1K_COPY: return reloc_class_copy;
  2345. default: return reloc_class_normal;
  2346. }
  2347. }
  2348. /* Adjust a symbol defined by a dynamic object and referenced by a
  2349. regular object. The current definition is in some section of the
  2350. dynamic object, but we're not including those sections. We have to
  2351. change the definition to something the rest of the link can
  2352. understand. */
  2353. static bool
  2354. or1k_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
  2355. struct elf_link_hash_entry *h)
  2356. {
  2357. struct elf_or1k_link_hash_table *htab;
  2358. bfd *dynobj;
  2359. asection *s, *srel;
  2360. dynobj = elf_hash_table (info)->dynobj;
  2361. /* Make sure we know what is going on here. */
  2362. BFD_ASSERT (dynobj != NULL
  2363. && (h->needs_plt
  2364. || h->is_weakalias
  2365. || (h->def_dynamic
  2366. && h->ref_regular
  2367. && !h->def_regular)));
  2368. /* If this is a function, put it in the procedure linkage table. We
  2369. will fill in the contents of the procedure linkage table later,
  2370. when we know the address of the .got section. */
  2371. if (h->type == STT_FUNC
  2372. || h->needs_plt)
  2373. {
  2374. if (h->plt.refcount <= 0
  2375. || (SYMBOL_CALLS_LOCAL (info, h)
  2376. || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  2377. && h->root.type == bfd_link_hash_undefweak)))
  2378. {
  2379. /* This case can occur if we saw a PLT reloc in an input
  2380. file, but the symbol was never referred to by a dynamic
  2381. object. In such a case, we don't actually need to build
  2382. a procedure linkage table, and we can just do a PCREL
  2383. reloc instead. */
  2384. h->plt.offset = (bfd_vma) -1;
  2385. h->needs_plt = 0;
  2386. }
  2387. return true;
  2388. }
  2389. else
  2390. h->plt.offset = (bfd_vma) -1;
  2391. /* If this is a weak symbol, and there is a real definition, the
  2392. processor independent code will have arranged for us to see the
  2393. real definition first, and we can just use the same value. */
  2394. if (h->is_weakalias)
  2395. {
  2396. struct elf_link_hash_entry *def = weakdef (h);
  2397. BFD_ASSERT (def->root.type == bfd_link_hash_defined);
  2398. h->root.u.def.section = def->root.u.def.section;
  2399. h->root.u.def.value = def->root.u.def.value;
  2400. return true;
  2401. }
  2402. /* This is a reference to a symbol defined by a dynamic object which
  2403. is not a function. */
  2404. /* If we are creating a shared library, we must presume that the
  2405. only references to the symbol are via the global offset table.
  2406. For such cases we need not do anything here; the relocations will
  2407. be handled correctly by relocate_section. */
  2408. if (bfd_link_pic (info))
  2409. return true;
  2410. /* If there are no references to this symbol that do not use the
  2411. GOT, we don't need to generate a copy reloc. */
  2412. if (!h->non_got_ref)
  2413. return true;
  2414. /* If -z nocopyreloc was given, we won't generate them either. */
  2415. if (info->nocopyreloc)
  2416. {
  2417. h->non_got_ref = 0;
  2418. return true;
  2419. }
  2420. /* If we don't find any dynamic relocs in read-only sections, then
  2421. we'll be keeping the dynamic relocs and avoiding the copy reloc. */
  2422. if (!_bfd_elf_readonly_dynrelocs (h))
  2423. {
  2424. h->non_got_ref = 0;
  2425. return true;
  2426. }
  2427. /* We must allocate the symbol in our .dynbss section, which will
  2428. become part of the .bss section of the executable. There will be
  2429. an entry for this symbol in the .dynsym section. The dynamic
  2430. object will contain position independent code, so all references
  2431. from the dynamic object to this symbol will go through the global
  2432. offset table. The dynamic linker will use the .dynsym entry to
  2433. determine the address it must put in the global offset table, so
  2434. both the dynamic object and the regular object will refer to the
  2435. same memory location for the variable. */
  2436. htab = or1k_elf_hash_table (info);
  2437. if (htab == NULL)
  2438. return false;
  2439. /* We must generate a R_OR1K_COPY reloc to tell the dynamic linker
  2440. to copy the initial value out of the dynamic object and into the
  2441. runtime process image. We need to remember the offset into the
  2442. .rela.bss section we are going to use. */
  2443. if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
  2444. {
  2445. s = htab->root.sdynrelro;
  2446. srel = htab->root.sreldynrelro;
  2447. }
  2448. else
  2449. {
  2450. s = htab->root.sdynbss;
  2451. srel = htab->root.srelbss;
  2452. }
  2453. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  2454. {
  2455. srel->size += sizeof (Elf32_External_Rela);
  2456. h->needs_copy = 1;
  2457. }
  2458. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  2459. }
  2460. /* Caclulate an update the sizes required for a symbol in the GOT and
  2461. RELA relocation section based on the TLS_TYPE and whether or not the symbol
  2462. is DYNAMIC.
  2463. Symbols with TLS_GD access require 8 bytes in the GOT and, if dynamic,
  2464. require two relocation entries. Symbols with TLS_IE access require 4 bytes
  2465. in the GOT and, if dynamic, require one relocation entry. Symbols may have
  2466. both TLS_GD and TLS_IE access to be accounted for.
  2467. Other symbols require 4 bytes in the GOT table and, if dynamic, require one
  2468. relocation entry. */
  2469. static void
  2470. or1k_set_got_and_rela_sizes (const unsigned char tls_type,
  2471. const bool dynamic,
  2472. bfd_vma *got_size,
  2473. bfd_vma *rela_size)
  2474. {
  2475. bool is_tls_entry = false;
  2476. /* TLS GD requires two GOT entries and two relocs. */
  2477. if ((tls_type & TLS_GD) != 0)
  2478. {
  2479. *got_size += 8;
  2480. is_tls_entry = true;
  2481. }
  2482. if ((tls_type & TLS_IE) != 0)
  2483. {
  2484. *got_size += 4;
  2485. is_tls_entry = true;
  2486. }
  2487. if (!is_tls_entry)
  2488. *got_size += 4;
  2489. if (dynamic)
  2490. {
  2491. if ((tls_type & TLS_GD) != 0)
  2492. *rela_size += 2 * sizeof (Elf32_External_Rela);
  2493. if ((tls_type & TLS_IE) != 0)
  2494. *rela_size += sizeof (Elf32_External_Rela);
  2495. if (!is_tls_entry)
  2496. *rela_size += sizeof (Elf32_External_Rela);
  2497. }
  2498. }
  2499. /* Allocate space in .plt, .got and associated reloc sections for
  2500. dynamic relocs. */
  2501. static bool
  2502. allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
  2503. {
  2504. struct bfd_link_info *info;
  2505. struct elf_or1k_link_hash_table *htab;
  2506. struct elf_dyn_relocs *sec_relocs;
  2507. if (h->root.type == bfd_link_hash_indirect)
  2508. return true;
  2509. info = (struct bfd_link_info *) inf;
  2510. htab = or1k_elf_hash_table (info);
  2511. if (htab == NULL)
  2512. return false;
  2513. if (htab->root.dynamic_sections_created
  2514. && h->plt.refcount > 0)
  2515. {
  2516. /* Make sure this symbol is output as a dynamic symbol.
  2517. Undefined weak syms won't yet be marked as dynamic. */
  2518. if (h->dynindx == -1
  2519. && !h->forced_local)
  2520. {
  2521. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2522. return false;
  2523. }
  2524. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
  2525. {
  2526. asection *splt = htab->root.splt;
  2527. bfd_vma plt_index;
  2528. /* Track the index of our plt entry for use in calculating size. */
  2529. plt_index = htab->plt_count++;
  2530. ((struct elf_or1k_link_hash_entry *) h)->plt_index = plt_index;
  2531. /* If this is the first .plt entry, make room for the special
  2532. first entry. */
  2533. if (splt->size == 0)
  2534. splt->size = elf_or1k_plt_entry_size (plt_index);
  2535. h->plt.offset = splt->size;
  2536. /* If this symbol is not defined in a regular file, and we are
  2537. not generating a shared library, then set the symbol to this
  2538. location in the .plt. This is required to make function
  2539. pointers compare as equal between the normal executable and
  2540. the shared library. */
  2541. if (! bfd_link_pic (info)
  2542. && !h->def_regular)
  2543. {
  2544. h->root.u.def.section = splt;
  2545. h->root.u.def.value = h->plt.offset;
  2546. }
  2547. /* Make room for this entry. */
  2548. splt->size += elf_or1k_plt_entry_size (plt_index);
  2549. /* We also need to make an entry in the .got.plt section, which
  2550. will be placed in the .got section by the linker script. */
  2551. htab->root.sgotplt->size += 4;
  2552. /* We also need to make an entry in the .rel.plt section. */
  2553. htab->root.srelplt->size += sizeof (Elf32_External_Rela);
  2554. }
  2555. else
  2556. {
  2557. h->plt.offset = (bfd_vma) -1;
  2558. h->needs_plt = 0;
  2559. }
  2560. }
  2561. else
  2562. {
  2563. h->plt.offset = (bfd_vma) -1;
  2564. h->needs_plt = 0;
  2565. }
  2566. if (h->got.refcount > 0)
  2567. {
  2568. asection *sgot;
  2569. bool dyn;
  2570. unsigned char tls_type;
  2571. /* Make sure this symbol is output as a dynamic symbol.
  2572. Undefined weak syms won't yet be marked as dynamic. */
  2573. if (h->dynindx == -1
  2574. && !h->forced_local)
  2575. {
  2576. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2577. return false;
  2578. }
  2579. sgot = htab->root.sgot;
  2580. h->got.offset = sgot->size;
  2581. tls_type = ((struct elf_or1k_link_hash_entry *) h)->tls_type;
  2582. dyn = htab->root.dynamic_sections_created;
  2583. dyn = WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h);
  2584. or1k_set_got_and_rela_sizes (tls_type, dyn,
  2585. &sgot->size, &htab->root.srelgot->size);
  2586. }
  2587. else
  2588. h->got.offset = (bfd_vma) -1;
  2589. if (h->dyn_relocs == NULL)
  2590. return true;
  2591. /* In the shared -Bsymbolic case, discard space allocated for
  2592. dynamic pc-relative relocs against symbols which turn out to be
  2593. defined in regular objects. For the normal shared case, discard
  2594. space for pc-relative relocs that have become local due to symbol
  2595. visibility changes. */
  2596. if (bfd_link_pic (info))
  2597. {
  2598. if (SYMBOL_CALLS_LOCAL (info, h))
  2599. {
  2600. struct elf_dyn_relocs **pp;
  2601. for (pp = &h->dyn_relocs; (sec_relocs = *pp) != NULL;)
  2602. {
  2603. sec_relocs->count -= sec_relocs->pc_count;
  2604. sec_relocs->pc_count = 0;
  2605. if (sec_relocs->count == 0)
  2606. *pp = sec_relocs->next;
  2607. else
  2608. pp = &sec_relocs->next;
  2609. }
  2610. }
  2611. /* Also discard relocs on undefined weak syms with non-default
  2612. visibility. */
  2613. if (h->dyn_relocs != NULL
  2614. && h->root.type == bfd_link_hash_undefweak)
  2615. {
  2616. if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
  2617. h->dyn_relocs = NULL;
  2618. /* Make sure undefined weak symbols are output as a dynamic
  2619. symbol in PIEs. */
  2620. else if (h->dynindx == -1
  2621. && !h->forced_local)
  2622. {
  2623. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2624. return false;
  2625. }
  2626. }
  2627. }
  2628. else
  2629. {
  2630. /* For the non-shared case, discard space for relocs against
  2631. symbols which turn out to need copy relocs or are not
  2632. dynamic. */
  2633. if (!h->non_got_ref
  2634. && ((h->def_dynamic
  2635. && !h->def_regular)
  2636. || (htab->root.dynamic_sections_created
  2637. && (h->root.type == bfd_link_hash_undefweak
  2638. || h->root.type == bfd_link_hash_undefined))))
  2639. {
  2640. /* Make sure this symbol is output as a dynamic symbol.
  2641. Undefined weak syms won't yet be marked as dynamic. */
  2642. if (h->dynindx == -1
  2643. && !h->forced_local)
  2644. {
  2645. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2646. return false;
  2647. }
  2648. /* If that succeeded, we know we'll be keeping all the
  2649. relocs. */
  2650. if (h->dynindx != -1)
  2651. goto keep;
  2652. }
  2653. h->dyn_relocs = NULL;
  2654. keep: ;
  2655. }
  2656. /* Finally, allocate space. */
  2657. for (sec_relocs = h->dyn_relocs;
  2658. sec_relocs != NULL;
  2659. sec_relocs = sec_relocs->next)
  2660. {
  2661. asection *sreloc = elf_section_data (sec_relocs->sec)->sreloc;
  2662. sreloc->size += sec_relocs->count * sizeof (Elf32_External_Rela);
  2663. }
  2664. return true;
  2665. }
  2666. /* Set the sizes of the dynamic sections. */
  2667. static bool
  2668. or1k_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  2669. struct bfd_link_info *info)
  2670. {
  2671. struct elf_or1k_link_hash_table *htab;
  2672. bfd *dynobj;
  2673. asection *s;
  2674. bool relocs;
  2675. bfd *ibfd;
  2676. htab = or1k_elf_hash_table (info);
  2677. if (htab == NULL)
  2678. return false;
  2679. dynobj = htab->root.dynobj;
  2680. BFD_ASSERT (dynobj != NULL);
  2681. if (htab->root.dynamic_sections_created)
  2682. {
  2683. /* Set the contents of the .interp section to the interpreter. */
  2684. if (bfd_link_executable (info) && !info->nointerp)
  2685. {
  2686. s = bfd_get_section_by_name (dynobj, ".interp");
  2687. BFD_ASSERT (s != NULL);
  2688. s->size = sizeof ELF_DYNAMIC_INTERPRETER;
  2689. s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
  2690. }
  2691. }
  2692. /* Set up .got offsets for local syms, and space for local dynamic
  2693. relocs. */
  2694. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  2695. {
  2696. bfd_signed_vma *local_got;
  2697. bfd_signed_vma *end_local_got;
  2698. bfd_size_type locsymcount;
  2699. Elf_Internal_Shdr *symtab_hdr;
  2700. unsigned char *local_tls_type;
  2701. asection *srel;
  2702. if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
  2703. continue;
  2704. for (s = ibfd->sections; s != NULL; s = s->next)
  2705. {
  2706. struct elf_dyn_relocs *sec_relocs;
  2707. for (sec_relocs = ((struct elf_dyn_relocs *)
  2708. elf_section_data (s)->local_dynrel);
  2709. sec_relocs != NULL;
  2710. sec_relocs = sec_relocs->next)
  2711. {
  2712. if (! bfd_is_abs_section (sec_relocs->sec)
  2713. && bfd_is_abs_section (sec_relocs->sec->output_section))
  2714. {
  2715. /* Input section has been discarded, either because
  2716. it is a copy of a linkonce section or due to
  2717. linker script /DISCARD/, so we'll be discarding
  2718. the relocs too. */
  2719. }
  2720. else if (sec_relocs->count != 0)
  2721. {
  2722. srel = elf_section_data (sec_relocs->sec)->sreloc;
  2723. srel->size += sec_relocs->count
  2724. * sizeof (Elf32_External_Rela);
  2725. if ((sec_relocs->sec->output_section->flags & SEC_READONLY)
  2726. != 0)
  2727. info->flags |= DF_TEXTREL;
  2728. }
  2729. }
  2730. }
  2731. local_got = elf_local_got_refcounts (ibfd);
  2732. if (!local_got)
  2733. continue;
  2734. symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
  2735. locsymcount = symtab_hdr->sh_info;
  2736. end_local_got = local_got + locsymcount;
  2737. s = htab->root.sgot;
  2738. srel = htab->root.srelgot;
  2739. local_tls_type = (unsigned char *) elf_or1k_local_tls_type (ibfd);
  2740. for (; local_got < end_local_got; ++local_got)
  2741. {
  2742. if (*local_got > 0)
  2743. {
  2744. unsigned char tls_type = (local_tls_type == NULL)
  2745. ? TLS_UNKNOWN
  2746. : *local_tls_type;
  2747. *local_got = s->size;
  2748. or1k_set_got_and_rela_sizes (tls_type, bfd_link_pic (info),
  2749. &s->size, &srel->size);
  2750. }
  2751. else
  2752. *local_got = (bfd_vma) -1;
  2753. if (local_tls_type)
  2754. ++local_tls_type;
  2755. }
  2756. }
  2757. /* Allocate global sym .plt and .got entries, and space for global
  2758. sym dynamic relocs. */
  2759. elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
  2760. /* We now have determined the sizes of the various dynamic sections.
  2761. Allocate memory for them. */
  2762. relocs = false;
  2763. for (s = dynobj->sections; s != NULL; s = s->next)
  2764. {
  2765. if ((s->flags & SEC_LINKER_CREATED) == 0)
  2766. continue;
  2767. if (s == htab->root.splt
  2768. || s == htab->root.sgot
  2769. || s == htab->root.sgotplt
  2770. || s == htab->root.sdynbss
  2771. || s == htab->root.sdynrelro)
  2772. {
  2773. /* Strip this section if we don't need it; see the
  2774. comment below. */
  2775. }
  2776. else if (startswith (bfd_section_name (s), ".rela"))
  2777. {
  2778. if (s->size != 0 && s != htab->root.srelplt)
  2779. relocs = true;
  2780. /* We use the reloc_count field as a counter if we need
  2781. to copy relocs into the output file. */
  2782. s->reloc_count = 0;
  2783. }
  2784. else
  2785. /* It's not one of our sections, so don't allocate space. */
  2786. continue;
  2787. if (s->size == 0)
  2788. {
  2789. /* If we don't need this section, strip it from the
  2790. output file. This is mostly to handle .rela.bss and
  2791. .rela.plt. We must create both sections in
  2792. create_dynamic_sections, because they must be created
  2793. before the linker maps input sections to output
  2794. sections. The linker does that before
  2795. adjust_dynamic_symbol is called, and it is that
  2796. function which decides whether anything needs to go
  2797. into these sections. */
  2798. s->flags |= SEC_EXCLUDE;
  2799. continue;
  2800. }
  2801. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  2802. continue;
  2803. /* Allocate memory for the section contents. We use bfd_zalloc
  2804. here in case unused entries are not reclaimed before the
  2805. section's contents are written out. This should not happen,
  2806. but this way if it does, we get a R_OR1K_NONE reloc instead
  2807. of garbage. */
  2808. s->contents = bfd_zalloc (dynobj, s->size);
  2809. if (s->contents == NULL)
  2810. return false;
  2811. }
  2812. return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
  2813. }
  2814. /* Copy the extra info we tack onto an elf_link_hash_entry. */
  2815. static void
  2816. or1k_elf_copy_indirect_symbol (struct bfd_link_info *info,
  2817. struct elf_link_hash_entry *dir,
  2818. struct elf_link_hash_entry *ind)
  2819. {
  2820. struct elf_or1k_link_hash_entry * edir;
  2821. struct elf_or1k_link_hash_entry * eind;
  2822. edir = (struct elf_or1k_link_hash_entry *) dir;
  2823. eind = (struct elf_or1k_link_hash_entry *) ind;
  2824. if (ind->root.type == bfd_link_hash_indirect)
  2825. {
  2826. if (dir->got.refcount <= 0)
  2827. {
  2828. edir->tls_type = eind->tls_type;
  2829. eind->tls_type = TLS_UNKNOWN;
  2830. }
  2831. }
  2832. _bfd_elf_link_hash_copy_indirect (info, dir, ind);
  2833. }
  2834. /* Set the right machine number. */
  2835. static bool
  2836. or1k_elf_object_p (bfd *abfd)
  2837. {
  2838. unsigned long mach = bfd_mach_or1k;
  2839. if (elf_elfheader (abfd)->e_flags & EF_OR1K_NODELAY)
  2840. mach = bfd_mach_or1knd;
  2841. return bfd_default_set_arch_mach (abfd, bfd_arch_or1k, mach);
  2842. }
  2843. /* Store the machine number in the flags field. */
  2844. static bool
  2845. or1k_elf_final_write_processing (bfd *abfd)
  2846. {
  2847. switch (bfd_get_mach (abfd))
  2848. {
  2849. default:
  2850. case bfd_mach_or1k:
  2851. break;
  2852. case bfd_mach_or1knd:
  2853. elf_elfheader (abfd)->e_flags |= EF_OR1K_NODELAY;
  2854. break;
  2855. }
  2856. return _bfd_elf_final_write_processing (abfd);
  2857. }
  2858. static bool
  2859. or1k_elf_set_private_flags (bfd *abfd, flagword flags)
  2860. {
  2861. BFD_ASSERT (!elf_flags_init (abfd)
  2862. || elf_elfheader (abfd)->e_flags == flags);
  2863. elf_elfheader (abfd)->e_flags = flags;
  2864. elf_flags_init (abfd) = true;
  2865. return true;
  2866. }
  2867. /* Make sure all input files are consistent with respect to
  2868. EF_OR1K_NODELAY flag setting. */
  2869. static bool
  2870. elf32_or1k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
  2871. {
  2872. bfd *obfd = info->output_bfd;
  2873. flagword out_flags;
  2874. flagword in_flags;
  2875. in_flags = elf_elfheader (ibfd)->e_flags;
  2876. out_flags = elf_elfheader (obfd)->e_flags;
  2877. if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
  2878. || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
  2879. return true;
  2880. if (!elf_flags_init (obfd))
  2881. {
  2882. elf_flags_init (obfd) = true;
  2883. elf_elfheader (obfd)->e_flags = in_flags;
  2884. return true;
  2885. }
  2886. if (in_flags == out_flags)
  2887. return true;
  2888. if ((in_flags & EF_OR1K_NODELAY) != (out_flags & EF_OR1K_NODELAY))
  2889. {
  2890. _bfd_error_handler
  2891. (_("%pB: %s flag mismatch with previous modules"),
  2892. ibfd, "EF_OR1K_NODELAY");
  2893. bfd_set_error (bfd_error_bad_value);
  2894. return false;
  2895. }
  2896. return true;
  2897. }
  2898. /* Implement elf_backend_grok_prstatus:
  2899. Support for core dump NOTE sections. */
  2900. static bool
  2901. or1k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
  2902. {
  2903. int offset;
  2904. size_t size;
  2905. switch (note->descsz)
  2906. {
  2907. default:
  2908. return false;
  2909. case 212: /* Linux/OpenRISC */
  2910. /* pr_cursig */
  2911. elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
  2912. /* pr_pid */
  2913. elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
  2914. /* pr_reg */
  2915. offset = 72;
  2916. size = 132;
  2917. break;
  2918. }
  2919. /* Make a ".reg/999" section. */
  2920. return _bfd_elfcore_make_pseudosection (abfd, ".reg",
  2921. size, note->descpos + offset);
  2922. }
  2923. /* Implement elf_backend_grok_psinfo. */
  2924. static bool
  2925. or1k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
  2926. {
  2927. switch (note->descsz)
  2928. {
  2929. default:
  2930. return false;
  2931. case 128: /* Linux/OpenRISC elf_prpsinfo */
  2932. elf_tdata (abfd)->core->program
  2933. = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
  2934. elf_tdata (abfd)->core->command
  2935. = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
  2936. }
  2937. return true;
  2938. }
  2939. #define ELF_ARCH bfd_arch_or1k
  2940. #define ELF_MACHINE_CODE EM_OR1K
  2941. #define ELF_TARGET_ID OR1K_ELF_DATA
  2942. #define ELF_MAXPAGESIZE 0x2000
  2943. #define TARGET_BIG_SYM or1k_elf32_vec
  2944. #define TARGET_BIG_NAME "elf32-or1k"
  2945. #define elf_info_to_howto_rel NULL
  2946. #define elf_info_to_howto or1k_info_to_howto_rela
  2947. #define elf_backend_relocate_section or1k_elf_relocate_section
  2948. #define elf_backend_gc_mark_hook or1k_elf_gc_mark_hook
  2949. #define elf_backend_check_relocs or1k_elf_check_relocs
  2950. #define elf_backend_reloc_type_class or1k_elf_reloc_type_class
  2951. #define elf_backend_can_gc_sections 1
  2952. #define elf_backend_rela_normal 1
  2953. #define bfd_elf32_mkobject elf_or1k_mkobject
  2954. #define bfd_elf32_bfd_merge_private_bfd_data elf32_or1k_merge_private_bfd_data
  2955. #define bfd_elf32_bfd_set_private_flags or1k_elf_set_private_flags
  2956. #define bfd_elf32_bfd_reloc_type_lookup or1k_reloc_type_lookup
  2957. #define bfd_elf32_bfd_reloc_name_lookup or1k_reloc_name_lookup
  2958. #define elf_backend_object_p or1k_elf_object_p
  2959. #define elf_backend_final_write_processing or1k_elf_final_write_processing
  2960. #define elf_backend_can_refcount 1
  2961. #define elf_backend_plt_readonly 1
  2962. #define elf_backend_want_got_plt 1
  2963. #define elf_backend_want_plt_sym 0
  2964. #define elf_backend_got_header_size 12
  2965. #define elf_backend_dtrel_excludes_plt 1
  2966. #define elf_backend_want_dynrelro 1
  2967. #define bfd_elf32_bfd_link_hash_table_create or1k_elf_link_hash_table_create
  2968. #define elf_backend_copy_indirect_symbol or1k_elf_copy_indirect_symbol
  2969. #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
  2970. #define elf_backend_finish_dynamic_sections or1k_elf_finish_dynamic_sections
  2971. #define elf_backend_size_dynamic_sections or1k_elf_size_dynamic_sections
  2972. #define elf_backend_adjust_dynamic_symbol or1k_elf_adjust_dynamic_symbol
  2973. #define elf_backend_finish_dynamic_symbol or1k_elf_finish_dynamic_symbol
  2974. #define elf_backend_grok_prstatus or1k_grok_prstatus
  2975. #define elf_backend_grok_psinfo or1k_grok_psinfo
  2976. #include "elf32-target.h"