elf32-or1k.c 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860
  1. /* Or1k-specific support for 32-bit ELF.
  2. Copyright (C) 2001-2015 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 PLT_ENTRY_SIZE 20
  24. #define PLT0_ENTRY_WORD0 0x19800000 /* l.movhi r12, 0 <- hi(.got+4) */
  25. #define PLT0_ENTRY_WORD1 0xa98c0000 /* l.ori r12, r12, 0 <- lo(.got+4) */
  26. #define PLT0_ENTRY_WORD2 0x85ec0004 /* l.lwz r15, 4(r12) <- *(.got+8)*/
  27. #define PLT0_ENTRY_WORD3 0x44007800 /* l.jr r15 */
  28. #define PLT0_ENTRY_WORD4 0x858c0000 /* l.lwz r12, 0(r12) */
  29. #define PLT0_PIC_ENTRY_WORD0 0x85900004 /* l.lwz r12, 4(r16) */
  30. #define PLT0_PIC_ENTRY_WORD1 0x85f00008 /* l.lwz r15, 8(r16) */
  31. #define PLT0_PIC_ENTRY_WORD2 0x44007800 /* l.jr r15 */
  32. #define PLT0_PIC_ENTRY_WORD3 0x15000000 /* l.nop */
  33. #define PLT0_PIC_ENTRY_WORD4 0x15000000 /* l.nop */
  34. #define PLT_ENTRY_WORD0 0x19800000 /* l.movhi r12, 0 <- hi(got idx addr) */
  35. #define PLT_ENTRY_WORD1 0xa98c0000 /* l.ori r12, r12, 0 <- lo(got idx addr) */
  36. #define PLT_ENTRY_WORD2 0x858c0000 /* l.lwz r12, 0(r12) */
  37. #define PLT_ENTRY_WORD3 0x44006000 /* l.jr r12 */
  38. #define PLT_ENTRY_WORD4 0xa9600000 /* l.ori r11, r0, 0 <- reloc offset */
  39. #define PLT_PIC_ENTRY_WORD0 0x85900000 /* l.lwz r12, 0(r16) <- index in got */
  40. #define PLT_PIC_ENTRY_WORD1 0xa9600000 /* l.ori r11, r0, 0 <- reloc offset */
  41. #define PLT_PIC_ENTRY_WORD2 0x44006000 /* l.jr r12 */
  42. #define PLT_PIC_ENTRY_WORD3 0x15000000 /* l.nop */
  43. #define PLT_PIC_ENTRY_WORD4 0x15000000 /* l.nop */
  44. #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
  45. static reloc_howto_type or1k_elf_howto_table[] =
  46. {
  47. /* This reloc does nothing. */
  48. HOWTO (R_OR1K_NONE, /* type */
  49. 0, /* rightshift */
  50. 3, /* size (0 = byte, 1 = short, 2 = long) */
  51. 0, /* bitsize */
  52. FALSE, /* pc_relative */
  53. 0, /* bitpos */
  54. complain_overflow_dont, /* complain_on_overflow */
  55. bfd_elf_generic_reloc, /* special_function */
  56. "R_OR1K_NONE", /* name */
  57. FALSE, /* partial_inplace */
  58. 0, /* src_mask */
  59. 0, /* dst_mask */
  60. FALSE), /* pcrel_offset */
  61. HOWTO (R_OR1K_32,
  62. 0, /* rightshift */
  63. 2, /* size (0 = byte, 1 = short, 2 = long) */
  64. 32, /* bitsize */
  65. FALSE, /* pc_relative */
  66. 0, /* bitpos */
  67. complain_overflow_unsigned, /* complain_on_overflow */
  68. bfd_elf_generic_reloc, /* special_function */
  69. "R_OR1K_32", /* name */
  70. FALSE, /* partial_inplace */
  71. 0, /* src_mask */
  72. 0xffffffff, /* dst_mask */
  73. FALSE), /* pcrel_offset */
  74. HOWTO (R_OR1K_16,
  75. 0, /* rightshift */
  76. 1, /* size (0 = byte, 1 = short, 2 = long) */
  77. 16, /* bitsize */
  78. FALSE, /* pc_relative */
  79. 0, /* bitpos */
  80. complain_overflow_unsigned, /* complain_on_overflow */
  81. bfd_elf_generic_reloc, /* special_function */
  82. "R_OR1K_16", /* name */
  83. FALSE, /* partial_inplace */
  84. 0, /* src_mask */
  85. 0xffff, /* dst_mask */
  86. FALSE), /* pcrel_offset */
  87. HOWTO (R_OR1K_8,
  88. 0, /* rightshift */
  89. 0, /* size (0 = byte, 1 = short, 2 = long) */
  90. 8, /* bitsize */
  91. FALSE, /* pc_relative */
  92. 0, /* bitpos */
  93. complain_overflow_unsigned, /* complain_on_overflow */
  94. bfd_elf_generic_reloc, /* special_function */
  95. "R_OR1K_8", /* name */
  96. FALSE, /* partial_inplace */
  97. 0, /* src_mask */
  98. 0xff, /* dst_mask */
  99. FALSE), /* pcrel_offset */
  100. HOWTO (R_OR1K_LO_16_IN_INSN, /* type */
  101. 0, /* rightshift */
  102. 2, /* size (0 = byte, 1 = short, 2 = long) */
  103. 16, /* bitsize */
  104. FALSE, /* pc_relative */
  105. 0, /* bitpos */
  106. complain_overflow_dont, /* complain_on_overflow */
  107. bfd_elf_generic_reloc, /* special_function */
  108. "R_OR1K_LO_16_IN_INSN", /* name */
  109. FALSE, /* partial_inplace */
  110. 0, /* src_mask */
  111. 0x0000ffff, /* dst_mask */
  112. FALSE), /* pcrel_offset */
  113. HOWTO (R_OR1K_HI_16_IN_INSN, /* type */
  114. 16, /* rightshift */
  115. 2, /* size (0 = byte, 1 = short, 2 = long) */
  116. 16, /* bitsize */
  117. FALSE, /* pc_relative */
  118. 0, /* bitpos */
  119. complain_overflow_dont, /* complain_on_overflow */
  120. bfd_elf_generic_reloc, /* special_function */
  121. "R_OR1K_HI_16_IN_INSN", /* name */
  122. FALSE, /* partial_inplace */
  123. 0, /* src_mask */
  124. 0x0000ffff, /* dst_mask */
  125. FALSE), /* pcrel_offset */
  126. /* A PC relative 26 bit relocation, right shifted by 2. */
  127. HOWTO (R_OR1K_INSN_REL_26, /* type */
  128. 2, /* rightshift */
  129. 2, /* size (0 = byte, 1 = short, 2 = long) */
  130. 26, /* bitsize */
  131. TRUE, /* pc_relative */
  132. 0, /* bitpos */
  133. complain_overflow_signed, /* complain_on_overflow */
  134. bfd_elf_generic_reloc, /* special_function */
  135. "R_OR1K_INSN_REL_26", /* name */
  136. FALSE, /* partial_inplace */
  137. 0, /* src_mask */
  138. 0x03ffffff, /* dst_mask */
  139. TRUE), /* pcrel_offset */
  140. /* GNU extension to record C++ vtable hierarchy. */
  141. HOWTO (R_OR1K_GNU_VTINHERIT, /* type */
  142. 0, /* rightshift */
  143. 2, /* size (0 = byte, 1 = short, 2 = long) */
  144. 0, /* bitsize */
  145. FALSE, /* pc_relative */
  146. 0, /* bitpos */
  147. complain_overflow_dont, /* complain_on_overflow */
  148. NULL, /* special_function */
  149. "R_OR1K_GNU_VTINHERIT", /* name */
  150. FALSE, /* partial_inplace */
  151. 0, /* src_mask */
  152. 0, /* dst_mask */
  153. FALSE), /* pcrel_offset */
  154. /* GNU extension to record C++ vtable member usage. */
  155. HOWTO (R_OR1K_GNU_VTENTRY, /* type */
  156. 0, /* rightshift */
  157. 2, /* size (0 = byte, 1 = short, 2 = long) */
  158. 0, /* bitsize */
  159. FALSE, /* pc_relative */
  160. 0, /* bitpos */
  161. complain_overflow_dont, /* complain_on_overflow */
  162. _bfd_elf_rel_vtable_reloc_fn, /* special_function */
  163. "R_OR1K_GNU_VTENTRY", /* name */
  164. FALSE, /* partial_inplace */
  165. 0, /* src_mask */
  166. 0, /* dst_mask */
  167. FALSE), /* pcrel_offset */
  168. HOWTO (R_OR1K_32_PCREL,
  169. 0, /* rightshift */
  170. 2, /* size (0 = byte, 1 = short, 2 = long) */
  171. 32, /* bitsize */
  172. TRUE, /* pc_relative */
  173. 0, /* bitpos */
  174. complain_overflow_signed, /* complain_on_overflow */
  175. bfd_elf_generic_reloc, /* special_function */
  176. "R_OR1K_32_PCREL", /* name */
  177. FALSE, /* partial_inplace */
  178. 0, /* src_mask */
  179. 0xffffffff, /* dst_mask */
  180. TRUE), /* pcrel_offset */
  181. HOWTO (R_OR1K_16_PCREL,
  182. 0, /* rightshift */
  183. 1, /* size (0 = byte, 1 = short, 2 = long) */
  184. 16, /* bitsize */
  185. TRUE, /* pc_relative */
  186. 0, /* bitpos */
  187. complain_overflow_signed, /* complain_on_overflow */
  188. bfd_elf_generic_reloc, /* special_function */
  189. "R_OR1K_16_PCREL", /* name */
  190. FALSE, /* partial_inplace */
  191. 0, /* src_mask */
  192. 0xffff, /* dst_mask */
  193. TRUE), /* pcrel_offset */
  194. HOWTO (R_OR1K_8_PCREL,
  195. 0, /* rightshift */
  196. 0, /* size (0 = byte, 1 = short, 2 = long) */
  197. 8, /* bitsize */
  198. TRUE, /* pc_relative */
  199. 0, /* bitpos */
  200. complain_overflow_signed, /* complain_on_overflow */
  201. bfd_elf_generic_reloc, /* special_function */
  202. "R_OR1K_8_PCREL", /* name */
  203. FALSE, /* partial_inplace */
  204. 0, /* src_mask */
  205. 0xff, /* dst_mask */
  206. TRUE), /* pcrel_offset */
  207. HOWTO (R_OR1K_GOTPC_HI16, /* Type. */
  208. 16, /* Rightshift. */
  209. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  210. 16, /* Bitsize. */
  211. TRUE, /* PC_relative. */
  212. 0, /* Bitpos. */
  213. complain_overflow_dont, /* Complain on overflow. */
  214. bfd_elf_generic_reloc, /* Special Function. */
  215. "R_OR1K_GOTPC_HI16", /* Name. */
  216. FALSE, /* Partial Inplace. */
  217. 0, /* Source Mask. */
  218. 0xffff, /* Dest Mask. */
  219. TRUE), /* PC relative offset? */
  220. HOWTO (R_OR1K_GOTPC_LO16, /* Type. */
  221. 0, /* Rightshift. */
  222. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  223. 16, /* Bitsize. */
  224. TRUE, /* PC_relative. */
  225. 0, /* Bitpos. */
  226. complain_overflow_dont, /* Complain on overflow. */
  227. bfd_elf_generic_reloc, /* Special Function. */
  228. "R_OR1K_GOTPC_LO16", /* Name. */
  229. FALSE, /* Partial Inplace. */
  230. 0, /* Source Mask. */
  231. 0xffff, /* Dest Mask. */
  232. TRUE), /* PC relative offset? */
  233. HOWTO (R_OR1K_GOT16, /* type */
  234. 0, /* rightshift */
  235. 2, /* size (0 = byte, 1 = short, 2 = long) */
  236. 16, /* bitsize */
  237. FALSE, /* pc_relative */
  238. 0, /* bitpos */
  239. complain_overflow_signed, /* complain_on_overflow */
  240. bfd_elf_generic_reloc, /* special_function */
  241. "R_OR1K_GOT16", /* name */
  242. FALSE, /* partial_inplace */
  243. 0, /* src_mask */
  244. 0xffff, /* dst_mask */
  245. FALSE), /* pcrel_offset */
  246. /* A 26 bit PLT relocation. Shifted by 2. */
  247. HOWTO (R_OR1K_PLT26, /* Type. */
  248. 2, /* Rightshift. */
  249. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  250. 26, /* Bitsize. */
  251. TRUE, /* PC_relative. */
  252. 0, /* Bitpos. */
  253. complain_overflow_dont, /* Complain on overflow. */
  254. bfd_elf_generic_reloc,/* Special Function. */
  255. "R_OR1K_PLT26", /* Name. */
  256. FALSE, /* Partial Inplace. */
  257. 0, /* Source Mask. */
  258. 0x03ffffff, /* Dest Mask. */
  259. TRUE), /* PC relative offset? */
  260. HOWTO (R_OR1K_GOTOFF_HI16, /* type */
  261. 16, /* rightshift */
  262. 2, /* size (0 = byte, 1 = short, 2 = long) */
  263. 16, /* bitsize */
  264. FALSE, /* pc_relative */
  265. 0, /* bitpos */
  266. complain_overflow_dont, /* complain_on_overflow */
  267. bfd_elf_generic_reloc, /* special_function */
  268. "R_OR1K_GOTOFF_HI16", /* name */
  269. FALSE, /* partial_inplace */
  270. 0x0, /* src_mask */
  271. 0xffff, /* dst_mask */
  272. FALSE), /* pcrel_offset */
  273. HOWTO (R_OR1K_GOTOFF_LO16, /* type */
  274. 0, /* rightshift */
  275. 2, /* size (0 = byte, 1 = short, 2 = long) */
  276. 16, /* bitsize */
  277. FALSE, /* pc_relative */
  278. 0, /* bitpos */
  279. complain_overflow_dont, /* complain_on_overflow */
  280. bfd_elf_generic_reloc, /* special_function */
  281. "R_OR1K_GOTOFF_LO16", /* name */
  282. FALSE, /* partial_inplace */
  283. 0x0, /* src_mask */
  284. 0xffff, /* dst_mask */
  285. FALSE), /* pcrel_offset */
  286. HOWTO (R_OR1K_COPY, /* type */
  287. 0, /* rightshift */
  288. 2, /* size (0 = byte, 1 = short, 2 = long) */
  289. 32, /* bitsize */
  290. FALSE, /* pc_relative */
  291. 0, /* bitpos */
  292. complain_overflow_bitfield, /* complain_on_overflow */
  293. bfd_elf_generic_reloc, /* special_function */
  294. "R_OR1K_COPY", /* name */
  295. FALSE, /* partial_inplace */
  296. 0xffffffff, /* src_mask */
  297. 0xffffffff, /* dst_mask */
  298. FALSE), /* pcrel_offset */
  299. HOWTO (R_OR1K_GLOB_DAT, /* type */
  300. 0, /* rightshift */
  301. 2, /* size (0 = byte, 1 = short, 2 = long) */
  302. 32, /* bitsize */
  303. FALSE, /* pc_relative */
  304. 0, /* bitpos */
  305. complain_overflow_bitfield, /* complain_on_overflow */
  306. bfd_elf_generic_reloc, /* special_function */
  307. "R_OR1K_GLOB_DAT", /* name */
  308. FALSE, /* partial_inplace */
  309. 0xffffffff, /* src_mask */
  310. 0xffffffff, /* dst_mask */
  311. FALSE), /* pcrel_offset */
  312. HOWTO (R_OR1K_JMP_SLOT, /* type */
  313. 0, /* rightshift */
  314. 2, /* size (0 = byte, 1 = short, 2 = long) */
  315. 32, /* bitsize */
  316. FALSE, /* pc_relative */
  317. 0, /* bitpos */
  318. complain_overflow_bitfield, /* complain_on_overflow */
  319. bfd_elf_generic_reloc, /* special_function */
  320. "R_OR1K_JMP_SLOT", /* name */
  321. FALSE, /* partial_inplace */
  322. 0xffffffff, /* src_mask */
  323. 0xffffffff, /* dst_mask */
  324. FALSE), /* pcrel_offset */
  325. HOWTO (R_OR1K_RELATIVE, /* type */
  326. 0, /* rightshift */
  327. 2, /* size (0 = byte, 1 = short, 2 = long) */
  328. 32, /* bitsize */
  329. FALSE, /* pc_relative */
  330. 0, /* bitpos */
  331. complain_overflow_bitfield, /* complain_on_overflow */
  332. bfd_elf_generic_reloc, /* special_function */
  333. "R_OR1K_RELATIVE", /* name */
  334. FALSE, /* partial_inplace */
  335. 0xffffffff, /* src_mask */
  336. 0xffffffff, /* dst_mask */
  337. FALSE), /* pcrel_offset */
  338. HOWTO (R_OR1K_TLS_GD_HI16, /* type */
  339. 16, /* rightshift */
  340. 2, /* size (0 = byte, 1 = short, 2 = long) */
  341. 16, /* bitsize */
  342. FALSE, /* pc_relative */
  343. 0, /* bitpos */
  344. complain_overflow_dont, /* complain_on_overflow */
  345. bfd_elf_generic_reloc, /* special_function */
  346. "R_OR1K_TLS_GD_HI16", /* name */
  347. FALSE, /* partial_inplace */
  348. 0x0, /* src_mask */
  349. 0xffff, /* dst_mask */
  350. FALSE), /* pcrel_offset */
  351. HOWTO (R_OR1K_TLS_GD_LO16, /* type */
  352. 0, /* rightshift */
  353. 2, /* size (0 = byte, 1 = short, 2 = long) */
  354. 16, /* bitsize */
  355. FALSE, /* pc_relative */
  356. 0, /* bitpos */
  357. complain_overflow_dont, /* complain_on_overflow */
  358. bfd_elf_generic_reloc, /* special_function */
  359. "R_OR1K_TLS_GD_LO16", /* name */
  360. FALSE, /* partial_inplace */
  361. 0x0, /* src_mask */
  362. 0xffff, /* dst_mask */
  363. FALSE), /* pcrel_offset */
  364. HOWTO (R_OR1K_TLS_LDM_HI16, /* type */
  365. 16, /* rightshift */
  366. 2, /* size (0 = byte, 1 = short, 2 = long) */
  367. 16, /* bitsize */
  368. FALSE, /* pc_relative */
  369. 0, /* bitpos */
  370. complain_overflow_dont, /* complain_on_overflow */
  371. bfd_elf_generic_reloc, /* special_function */
  372. "R_OR1K_TLS_LDM_HI16", /* name */
  373. FALSE, /* partial_inplace */
  374. 0x0, /* src_mask */
  375. 0xffff, /* dst_mask */
  376. FALSE), /* pcrel_offset */
  377. HOWTO (R_OR1K_TLS_LDM_LO16, /* type */
  378. 0, /* rightshift */
  379. 2, /* size (0 = byte, 1 = short, 2 = long) */
  380. 16, /* bitsize */
  381. FALSE, /* pc_relative */
  382. 0, /* bitpos */
  383. complain_overflow_dont, /* complain_on_overflow */
  384. bfd_elf_generic_reloc, /* special_function */
  385. "R_OR1K_TLS_LDM_LO16", /* name */
  386. FALSE, /* partial_inplace */
  387. 0x0, /* src_mask */
  388. 0xffff, /* dst_mask */
  389. FALSE), /* pcrel_offset */
  390. HOWTO (R_OR1K_TLS_LDO_HI16, /* type */
  391. 16, /* rightshift */
  392. 2, /* size (0 = byte, 1 = short, 2 = long) */
  393. 16, /* bitsize */
  394. FALSE, /* pc_relative */
  395. 0, /* bitpos */
  396. complain_overflow_dont, /* complain_on_overflow */
  397. bfd_elf_generic_reloc, /* special_function */
  398. "R_OR1K_TLS_LDO_HI16", /* name */
  399. FALSE, /* partial_inplace */
  400. 0x0, /* src_mask */
  401. 0xffff, /* dst_mask */
  402. FALSE), /* pcrel_offset */
  403. HOWTO (R_OR1K_TLS_LDO_LO16, /* type */
  404. 0, /* rightshift */
  405. 2, /* size (0 = byte, 1 = short, 2 = long) */
  406. 16, /* bitsize */
  407. FALSE, /* pc_relative */
  408. 0, /* bitpos */
  409. complain_overflow_dont, /* complain_on_overflow */
  410. bfd_elf_generic_reloc, /* special_function */
  411. "R_OR1K_TLS_LDO_LO16", /* name */
  412. FALSE, /* partial_inplace */
  413. 0x0, /* src_mask */
  414. 0xffff, /* dst_mask */
  415. FALSE), /* pcrel_offset */
  416. HOWTO (R_OR1K_TLS_IE_HI16, /* type */
  417. 16, /* rightshift */
  418. 2, /* size (0 = byte, 1 = short, 2 = long) */
  419. 16, /* bitsize */
  420. FALSE, /* pc_relative */
  421. 0, /* bitpos */
  422. complain_overflow_dont, /* complain_on_overflow */
  423. bfd_elf_generic_reloc, /* special_function */
  424. "R_OR1K_TLS_IE_HI16", /* name */
  425. FALSE, /* partial_inplace */
  426. 0x0, /* src_mask */
  427. 0xffff, /* dst_mask */
  428. FALSE), /* pcrel_offset */
  429. HOWTO (R_OR1K_TLS_IE_LO16, /* type */
  430. 0, /* rightshift */
  431. 2, /* size (0 = byte, 1 = short, 2 = long) */
  432. 16, /* bitsize */
  433. FALSE, /* pc_relative */
  434. 0, /* bitpos */
  435. complain_overflow_dont, /* complain_on_overflow */
  436. bfd_elf_generic_reloc, /* special_function */
  437. "R_OR1K_TLS_IE_LO16", /* name */
  438. FALSE, /* partial_inplace */
  439. 0x0, /* src_mask */
  440. 0xffff, /* dst_mask */
  441. FALSE), /* pcrel_offset */
  442. HOWTO (R_OR1K_TLS_LE_HI16, /* type */
  443. 16, /* rightshift */
  444. 2, /* size (0 = byte, 1 = short, 2 = long) */
  445. 16, /* bitsize */
  446. FALSE, /* pc_relative */
  447. 0, /* bitpos */
  448. complain_overflow_dont, /* complain_on_overflow */
  449. bfd_elf_generic_reloc, /* special_function */
  450. "R_OR1K_TLS_LE_HI16", /* name */
  451. FALSE, /* partial_inplace */
  452. 0x0, /* src_mask */
  453. 0xffff, /* dst_mask */
  454. FALSE), /* pcrel_offset */
  455. HOWTO (R_OR1K_TLS_LE_LO16, /* type */
  456. 0, /* rightshift */
  457. 2, /* size (0 = byte, 1 = short, 2 = long) */
  458. 16, /* bitsize */
  459. FALSE, /* pc_relative */
  460. 0, /* bitpos */
  461. complain_overflow_dont, /* complain_on_overflow */
  462. bfd_elf_generic_reloc, /* special_function */
  463. "R_OR1K_TLS_LE_LO16", /* name */
  464. FALSE, /* partial_inplace */
  465. 0x0, /* src_mask */
  466. 0xffff, /* dst_mask */
  467. FALSE), /* pcrel_offset */
  468. };
  469. /* Map BFD reloc types to Or1k ELF reloc types. */
  470. struct or1k_reloc_map
  471. {
  472. bfd_reloc_code_real_type bfd_reloc_val;
  473. unsigned int or1k_reloc_val;
  474. };
  475. static const struct or1k_reloc_map or1k_reloc_map[] =
  476. {
  477. { BFD_RELOC_NONE, R_OR1K_NONE },
  478. { BFD_RELOC_32, R_OR1K_32 },
  479. { BFD_RELOC_16, R_OR1K_16 },
  480. { BFD_RELOC_8, R_OR1K_8 },
  481. { BFD_RELOC_LO16, R_OR1K_LO_16_IN_INSN },
  482. { BFD_RELOC_HI16, R_OR1K_HI_16_IN_INSN },
  483. { BFD_RELOC_OR1K_REL_26, R_OR1K_INSN_REL_26 },
  484. { BFD_RELOC_VTABLE_ENTRY, R_OR1K_GNU_VTENTRY },
  485. { BFD_RELOC_VTABLE_INHERIT, R_OR1K_GNU_VTINHERIT },
  486. { BFD_RELOC_32_PCREL, R_OR1K_32_PCREL },
  487. { BFD_RELOC_16_PCREL, R_OR1K_16_PCREL },
  488. { BFD_RELOC_8_PCREL, R_OR1K_8_PCREL },
  489. { BFD_RELOC_OR1K_GOTPC_HI16, R_OR1K_GOTPC_HI16 },
  490. { BFD_RELOC_OR1K_GOTPC_LO16, R_OR1K_GOTPC_LO16 },
  491. { BFD_RELOC_OR1K_GOT16, R_OR1K_GOT16 },
  492. { BFD_RELOC_OR1K_PLT26, R_OR1K_PLT26 },
  493. { BFD_RELOC_OR1K_GOTOFF_HI16, R_OR1K_GOTOFF_HI16 },
  494. { BFD_RELOC_OR1K_GOTOFF_LO16, R_OR1K_GOTOFF_LO16 },
  495. { BFD_RELOC_OR1K_GLOB_DAT, R_OR1K_GLOB_DAT },
  496. { BFD_RELOC_OR1K_COPY, R_OR1K_COPY },
  497. { BFD_RELOC_OR1K_JMP_SLOT, R_OR1K_JMP_SLOT },
  498. { BFD_RELOC_OR1K_RELATIVE, R_OR1K_RELATIVE },
  499. { BFD_RELOC_OR1K_TLS_GD_HI16, R_OR1K_TLS_GD_HI16 },
  500. { BFD_RELOC_OR1K_TLS_GD_LO16, R_OR1K_TLS_GD_LO16 },
  501. { BFD_RELOC_OR1K_TLS_LDM_HI16, R_OR1K_TLS_LDM_HI16 },
  502. { BFD_RELOC_OR1K_TLS_LDM_LO16, R_OR1K_TLS_LDM_LO16 },
  503. { BFD_RELOC_OR1K_TLS_LDO_HI16, R_OR1K_TLS_LDO_HI16 },
  504. { BFD_RELOC_OR1K_TLS_LDO_LO16, R_OR1K_TLS_LDO_LO16 },
  505. { BFD_RELOC_OR1K_TLS_IE_HI16, R_OR1K_TLS_IE_HI16 },
  506. { BFD_RELOC_OR1K_TLS_IE_LO16, R_OR1K_TLS_IE_LO16 },
  507. { BFD_RELOC_OR1K_TLS_LE_HI16, R_OR1K_TLS_LE_HI16 },
  508. { BFD_RELOC_OR1K_TLS_LE_LO16, R_OR1K_TLS_LE_LO16 },
  509. };
  510. /* The linker needs to keep track of the number of relocs that it
  511. decides to copy as dynamic relocs in check_relocs for each symbol.
  512. This is so that it can later discard them if they are found to be
  513. unnecessary. We store the information in a field extending the
  514. regular ELF linker hash table. */
  515. struct elf_or1k_dyn_relocs
  516. {
  517. struct elf_or1k_dyn_relocs *next;
  518. /* The input section of the reloc. */
  519. asection *sec;
  520. /* Total number of relocs copied for the input section. */
  521. bfd_size_type count;
  522. /* Number of pc-relative relocs copied for the input section. */
  523. bfd_size_type pc_count;
  524. };
  525. #define TLS_UNKNOWN 0
  526. #define TLS_NONE 1
  527. #define TLS_GD 2
  528. #define TLS_LD 3
  529. #define TLS_IE 4
  530. #define TLS_LE 5
  531. /* ELF linker hash entry. */
  532. struct elf_or1k_link_hash_entry
  533. {
  534. struct elf_link_hash_entry root;
  535. /* Track dynamic relocs copied for this symbol. */
  536. struct elf_or1k_dyn_relocs *dyn_relocs;
  537. /* Track type of TLS access. */
  538. unsigned char tls_type;
  539. };
  540. /* ELF object data. */
  541. struct elf_or1k_obj_tdata
  542. {
  543. struct elf_obj_tdata root;
  544. /* tls_type for each local got entry. */
  545. unsigned char *local_tls_type;
  546. };
  547. #define elf_or1k_tdata(abfd) \
  548. ((struct elf_or1k_obj_tdata *) (abfd)->tdata.any)
  549. #define elf_or1k_local_tls_type(abfd) \
  550. (elf_or1k_tdata (abfd)->local_tls_type)
  551. /* ELF linker hash table. */
  552. struct elf_or1k_link_hash_table
  553. {
  554. struct elf_link_hash_table root;
  555. /* Short-cuts to get to dynamic linker sections. */
  556. asection *sgot;
  557. asection *sgotplt;
  558. asection *srelgot;
  559. asection *splt;
  560. asection *srelplt;
  561. asection *sdynbss;
  562. asection *srelbss;
  563. /* Small local sym to section mapping cache. */
  564. struct sym_cache sym_sec;
  565. };
  566. /* Get the ELF linker hash table from a link_info structure. */
  567. #define or1k_elf_hash_table(p) \
  568. (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
  569. == OR1K_ELF_DATA ? ((struct elf_or1k_link_hash_table *) ((p)->hash)) : NULL)
  570. static bfd_boolean
  571. elf_or1k_mkobject (bfd *abfd)
  572. {
  573. return bfd_elf_allocate_object (abfd, sizeof (struct elf_or1k_obj_tdata),
  574. OR1K_ELF_DATA);
  575. }
  576. /* Create an entry in an or1k ELF linker hash table. */
  577. static struct bfd_hash_entry *
  578. or1k_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
  579. struct bfd_hash_table *table,
  580. const char *string)
  581. {
  582. struct elf_or1k_link_hash_entry *ret =
  583. (struct elf_or1k_link_hash_entry *) entry;
  584. /* Allocate the structure if it has not already been allocated by a
  585. subclass. */
  586. if (ret == NULL)
  587. ret = bfd_hash_allocate (table,
  588. sizeof (struct elf_or1k_link_hash_entry));
  589. if (ret == NULL)
  590. return NULL;
  591. /* Call the allocation method of the superclass. */
  592. ret = ((struct elf_or1k_link_hash_entry *)
  593. _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
  594. table, string));
  595. if (ret != NULL)
  596. {
  597. struct elf_or1k_link_hash_entry *eh;
  598. eh = (struct elf_or1k_link_hash_entry *) ret;
  599. eh->dyn_relocs = NULL;
  600. eh->tls_type = TLS_UNKNOWN;
  601. }
  602. return (struct bfd_hash_entry *) ret;
  603. }
  604. /* Create an or1k ELF linker hash table. */
  605. static struct bfd_link_hash_table *
  606. or1k_elf_link_hash_table_create (bfd *abfd)
  607. {
  608. struct elf_or1k_link_hash_table *ret;
  609. bfd_size_type amt = sizeof (struct elf_or1k_link_hash_table);
  610. ret = bfd_zmalloc (amt);
  611. if (ret == NULL)
  612. return NULL;
  613. if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
  614. or1k_elf_link_hash_newfunc,
  615. sizeof (struct elf_or1k_link_hash_entry),
  616. OR1K_ELF_DATA))
  617. {
  618. free (ret);
  619. return NULL;
  620. }
  621. return &ret->root.root;
  622. }
  623. static reloc_howto_type *
  624. or1k_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
  625. bfd_reloc_code_real_type code)
  626. {
  627. unsigned int i;
  628. for (i = ARRAY_SIZE (or1k_reloc_map); i--;)
  629. if (or1k_reloc_map[i].bfd_reloc_val == code)
  630. return & or1k_elf_howto_table[or1k_reloc_map[i].or1k_reloc_val];
  631. return NULL;
  632. }
  633. static reloc_howto_type *
  634. or1k_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  635. const char *r_name)
  636. {
  637. unsigned int i;
  638. for (i = 0;
  639. i < (sizeof (or1k_elf_howto_table)
  640. / sizeof (or1k_elf_howto_table[0]));
  641. i++)
  642. if (or1k_elf_howto_table[i].name != NULL
  643. && strcasecmp (or1k_elf_howto_table[i].name, r_name) == 0)
  644. return &or1k_elf_howto_table[i];
  645. return NULL;
  646. }
  647. /* Set the howto pointer for an Or1k ELF reloc. */
  648. static void
  649. or1k_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
  650. arelent * cache_ptr,
  651. Elf_Internal_Rela * dst)
  652. {
  653. unsigned int r_type;
  654. r_type = ELF32_R_TYPE (dst->r_info);
  655. if (r_type >= (unsigned int) R_OR1K_max)
  656. {
  657. _bfd_error_handler (_("%B: invalid OR1K reloc number: %d"), abfd, r_type);
  658. r_type = 0;
  659. }
  660. cache_ptr->howto = & or1k_elf_howto_table[r_type];
  661. }
  662. /* Return the relocation value for @tpoff relocations.. */
  663. static bfd_vma
  664. tpoff (struct bfd_link_info *info, bfd_vma address)
  665. {
  666. /* If tls_sec is NULL, we should have signalled an error already. */
  667. if (elf_hash_table (info)->tls_sec == NULL)
  668. return 0;
  669. /* The thread pointer on or1k stores the address after the TCB where
  670. the data is, just compute the difference. No need to compensate
  671. for the size of TCB. */
  672. return (address - elf_hash_table (info)->tls_sec->vma);
  673. }
  674. /* Relocate an Or1k ELF section.
  675. The RELOCATE_SECTION function is called by the new ELF backend linker
  676. to handle the relocations for a section.
  677. The relocs are always passed as Rela structures; if the section
  678. actually uses Rel structures, the r_addend field will always be
  679. zero.
  680. This function is responsible for adjusting the section contents as
  681. necessary, and (if using Rela relocs and generating a relocatable
  682. output file) adjusting the reloc addend as necessary.
  683. This function does not have to worry about setting the reloc
  684. address or the reloc symbol index.
  685. LOCAL_SYMS is a pointer to the swapped in local symbols.
  686. LOCAL_SECTIONS is an array giving the section in the input file
  687. corresponding to the st_shndx field of each local symbol.
  688. The global hash table entry for the global symbols can be found
  689. via elf_sym_hashes (input_bfd).
  690. When generating relocatable output, this function must handle
  691. STB_LOCAL/STT_SECTION symbols specially. The output symbol is
  692. going to be the section symbol corresponding to the output
  693. section, which means that the addend must be adjusted
  694. accordingly. */
  695. static bfd_boolean
  696. or1k_elf_relocate_section (bfd *output_bfd,
  697. struct bfd_link_info *info,
  698. bfd *input_bfd,
  699. asection *input_section,
  700. bfd_byte *contents,
  701. Elf_Internal_Rela *relocs,
  702. Elf_Internal_Sym *local_syms,
  703. asection **local_sections)
  704. {
  705. Elf_Internal_Shdr *symtab_hdr;
  706. struct elf_link_hash_entry **sym_hashes;
  707. Elf_Internal_Rela *rel;
  708. Elf_Internal_Rela *relend;
  709. struct elf_or1k_link_hash_table *htab = or1k_elf_hash_table (info);
  710. bfd *dynobj;
  711. asection *sreloc;
  712. bfd_vma *local_got_offsets;
  713. asection *sgot;
  714. if (htab == NULL)
  715. return FALSE;
  716. dynobj = htab->root.dynobj;
  717. local_got_offsets = elf_local_got_offsets (input_bfd);
  718. sreloc = elf_section_data (input_section)->sreloc;
  719. sgot = htab->sgot;
  720. symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  721. sym_hashes = elf_sym_hashes (input_bfd);
  722. relend = relocs + input_section->reloc_count;
  723. for (rel = relocs; rel < relend; rel++)
  724. {
  725. reloc_howto_type *howto;
  726. unsigned long r_symndx;
  727. Elf_Internal_Sym *sym;
  728. asection *sec;
  729. struct elf_link_hash_entry *h;
  730. bfd_vma relocation;
  731. bfd_reloc_status_type r;
  732. const char *name = NULL;
  733. int r_type;
  734. r_type = ELF32_R_TYPE (rel->r_info);
  735. r_symndx = ELF32_R_SYM (rel->r_info);
  736. if (r_type == R_OR1K_GNU_VTINHERIT
  737. || r_type == R_OR1K_GNU_VTENTRY)
  738. continue;
  739. if (r_type < 0 || r_type >= (int) R_OR1K_max)
  740. {
  741. bfd_set_error (bfd_error_bad_value);
  742. return FALSE;
  743. }
  744. howto = or1k_elf_howto_table + ELF32_R_TYPE (rel->r_info);
  745. h = NULL;
  746. sym = NULL;
  747. sec = NULL;
  748. if (r_symndx < symtab_hdr->sh_info)
  749. {
  750. sym = local_syms + r_symndx;
  751. sec = local_sections[r_symndx];
  752. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  753. name = bfd_elf_string_from_elf_section
  754. (input_bfd, symtab_hdr->sh_link, sym->st_name);
  755. name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
  756. }
  757. else
  758. {
  759. bfd_boolean unresolved_reloc, warned, ignored;
  760. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  761. r_symndx, symtab_hdr, sym_hashes,
  762. h, sec, relocation,
  763. unresolved_reloc, warned, ignored);
  764. }
  765. if (sec != NULL && discarded_section (sec))
  766. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  767. rel, 1, relend, howto, 0, contents);
  768. if (bfd_link_relocatable (info))
  769. continue;
  770. switch (howto->type)
  771. {
  772. case R_OR1K_PLT26:
  773. {
  774. if (htab->splt != NULL && h != NULL
  775. && h->plt.offset != (bfd_vma) -1)
  776. {
  777. relocation = (htab->splt->output_section->vma
  778. + htab->splt->output_offset
  779. + h->plt.offset);
  780. }
  781. break;
  782. }
  783. case R_OR1K_GOT16:
  784. /* Relocation is to the entry for this symbol in the global
  785. offset table. */
  786. BFD_ASSERT (sgot != NULL);
  787. if (h != NULL)
  788. {
  789. bfd_boolean dyn;
  790. bfd_vma off;
  791. off = h->got.offset;
  792. BFD_ASSERT (off != (bfd_vma) -1);
  793. dyn = htab->root.dynamic_sections_created;
  794. if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  795. bfd_link_pic (info),
  796. h)
  797. || (bfd_link_pic (info)
  798. && SYMBOL_REFERENCES_LOCAL (info, h)))
  799. {
  800. /* This is actually a static link, or it is a
  801. -Bsymbolic link and the symbol is defined
  802. locally, or the symbol was forced to be local
  803. because of a version file. We must initialize
  804. this entry in the global offset table. Since the
  805. offset must always be a multiple of 4, we use the
  806. least significant bit to record whether we have
  807. initialized it already.
  808. When doing a dynamic link, we create a .rela.got
  809. relocation entry to initialize the value. This
  810. is done in the finish_dynamic_symbol routine. */
  811. if ((off & 1) != 0)
  812. off &= ~1;
  813. else
  814. {
  815. /* Write entry in GOT. */
  816. bfd_put_32 (output_bfd, relocation,
  817. sgot->contents + off);
  818. /* Mark GOT entry as having been written. */
  819. h->got.offset |= 1;
  820. }
  821. }
  822. relocation = sgot->output_offset + off;
  823. }
  824. else
  825. {
  826. bfd_vma off;
  827. bfd_byte *loc;
  828. BFD_ASSERT (local_got_offsets != NULL
  829. && local_got_offsets[r_symndx] != (bfd_vma) -1);
  830. /* Get offset into GOT table. */
  831. off = local_got_offsets[r_symndx];
  832. /* The offset must always be a multiple of 4. We use
  833. the least significant bit to record whether we have
  834. already processed this entry. */
  835. if ((off & 1) != 0)
  836. off &= ~1;
  837. else
  838. {
  839. /* Write entry in GOT. */
  840. bfd_put_32 (output_bfd, relocation, sgot->contents + off);
  841. if (bfd_link_pic (info))
  842. {
  843. asection *srelgot;
  844. Elf_Internal_Rela outrel;
  845. /* We need to generate a R_OR1K_RELATIVE reloc
  846. for the dynamic linker. */
  847. srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
  848. BFD_ASSERT (srelgot != NULL);
  849. outrel.r_offset = (sgot->output_section->vma
  850. + sgot->output_offset
  851. + off);
  852. outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
  853. outrel.r_addend = relocation;
  854. loc = srelgot->contents;
  855. loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
  856. bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
  857. ++srelgot->reloc_count;
  858. }
  859. local_got_offsets[r_symndx] |= 1;
  860. }
  861. relocation = sgot->output_offset + off;
  862. }
  863. /* Addend should be zero. */
  864. if (rel->r_addend != 0)
  865. (*_bfd_error_handler)
  866. (_("internal error: addend should be zero for R_OR1K_GOT16"));
  867. break;
  868. case R_OR1K_GOTOFF_LO16:
  869. case R_OR1K_GOTOFF_HI16:
  870. /* Relocation is offset from GOT. */
  871. BFD_ASSERT (sgot != NULL);
  872. relocation -= sgot->output_section->vma;
  873. break;
  874. case R_OR1K_INSN_REL_26:
  875. case R_OR1K_HI_16_IN_INSN:
  876. case R_OR1K_LO_16_IN_INSN:
  877. case R_OR1K_32:
  878. /* R_OR1K_16? */
  879. {
  880. /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
  881. from removed linkonce sections, or sections discarded by
  882. a linker script. */
  883. if (r_symndx == STN_UNDEF
  884. || (input_section->flags & SEC_ALLOC) == 0)
  885. break;
  886. if ((bfd_link_pic (info)
  887. && (h == NULL
  888. || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  889. || h->root.type != bfd_link_hash_undefweak)
  890. && (howto->type != R_OR1K_INSN_REL_26
  891. || !SYMBOL_CALLS_LOCAL (info, h)))
  892. || (!bfd_link_pic (info)
  893. && h != NULL
  894. && h->dynindx != -1
  895. && !h->non_got_ref
  896. && ((h->def_dynamic
  897. && !h->def_regular)
  898. || h->root.type == bfd_link_hash_undefweak
  899. || h->root.type == bfd_link_hash_undefined)))
  900. {
  901. Elf_Internal_Rela outrel;
  902. bfd_byte *loc;
  903. bfd_boolean skip;
  904. /* When generating a shared object, these relocations
  905. are copied into the output file to be resolved at run
  906. time. */
  907. BFD_ASSERT (sreloc != NULL);
  908. skip = FALSE;
  909. outrel.r_offset =
  910. _bfd_elf_section_offset (output_bfd, info, input_section,
  911. rel->r_offset);
  912. if (outrel.r_offset == (bfd_vma) -1)
  913. skip = TRUE;
  914. else if (outrel.r_offset == (bfd_vma) -2)
  915. skip = TRUE;
  916. outrel.r_offset += (input_section->output_section->vma
  917. + input_section->output_offset);
  918. if (skip)
  919. memset (&outrel, 0, sizeof outrel);
  920. /* h->dynindx may be -1 if the symbol was marked to
  921. become local. */
  922. else if (h != NULL
  923. && ((! info->symbolic && h->dynindx != -1)
  924. || !h->def_regular))
  925. {
  926. BFD_ASSERT (h->dynindx != -1);
  927. outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
  928. outrel.r_addend = rel->r_addend;
  929. }
  930. else
  931. {
  932. if (r_type == R_OR1K_32)
  933. {
  934. outrel.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
  935. outrel.r_addend = relocation + rel->r_addend;
  936. }
  937. else
  938. {
  939. BFD_FAIL ();
  940. (*_bfd_error_handler)
  941. (_("%B: probably compiled without -fPIC?"),
  942. input_bfd);
  943. bfd_set_error (bfd_error_bad_value);
  944. return FALSE;
  945. }
  946. }
  947. loc = sreloc->contents;
  948. loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
  949. bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
  950. break;
  951. }
  952. break;
  953. }
  954. case R_OR1K_TLS_LDM_HI16:
  955. case R_OR1K_TLS_LDM_LO16:
  956. case R_OR1K_TLS_LDO_HI16:
  957. case R_OR1K_TLS_LDO_LO16:
  958. /* TODO: implement support for local dynamic. */
  959. BFD_FAIL ();
  960. (*_bfd_error_handler)
  961. (_("%B: support for local dynamic not implemented"),
  962. input_bfd);
  963. bfd_set_error (bfd_error_bad_value);
  964. return FALSE;
  965. case R_OR1K_TLS_GD_HI16:
  966. case R_OR1K_TLS_GD_LO16:
  967. case R_OR1K_TLS_IE_HI16:
  968. case R_OR1K_TLS_IE_LO16:
  969. {
  970. bfd_vma gotoff;
  971. Elf_Internal_Rela rela;
  972. bfd_byte *loc;
  973. int dynamic;
  974. sreloc = bfd_get_section_by_name (dynobj, ".rela.got");
  975. /* Mark as TLS related GOT entry by setting
  976. bit 2 as well as bit 1. */
  977. if (h != NULL)
  978. {
  979. gotoff = h->got.offset;
  980. h->got.offset |= 3;
  981. }
  982. else
  983. {
  984. gotoff = local_got_offsets[r_symndx];
  985. local_got_offsets[r_symndx] |= 3;
  986. }
  987. /* Only process the relocation once. */
  988. if (gotoff & 1)
  989. {
  990. relocation = sgot->output_offset + (gotoff & ~3);
  991. break;
  992. }
  993. BFD_ASSERT (elf_hash_table (info)->hgot == NULL
  994. || elf_hash_table (info)->hgot->root.u.def.value == 0);
  995. /* Dynamic entries will require relocations. if we do not need
  996. them we will just use the default R_OR1K_NONE and
  997. not set anything. */
  998. dynamic = bfd_link_pic (info)
  999. || (sec && (sec->flags & SEC_ALLOC) != 0
  1000. && h != NULL
  1001. && (h->root.type == bfd_link_hash_defweak || !h->def_regular));
  1002. /* Shared GD. */
  1003. if (dynamic && (howto->type == R_OR1K_TLS_GD_HI16
  1004. || howto->type == R_OR1K_TLS_GD_LO16))
  1005. {
  1006. int i;
  1007. /* Add DTPMOD and DTPOFF GOT and rela entries. */
  1008. for (i = 0; i < 2; ++i)
  1009. {
  1010. rela.r_offset = sgot->output_section->vma +
  1011. sgot->output_offset + gotoff + i*4;
  1012. if (h != NULL && h->dynindx != -1)
  1013. {
  1014. rela.r_info = ELF32_R_INFO (h->dynindx,
  1015. (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
  1016. rela.r_addend = 0;
  1017. }
  1018. else
  1019. {
  1020. rela.r_info = ELF32_R_INFO (0,
  1021. (i == 0 ? R_OR1K_TLS_DTPMOD : R_OR1K_TLS_DTPOFF));
  1022. rela.r_addend = tpoff (info, relocation);
  1023. }
  1024. loc = sreloc->contents;
  1025. loc += sreloc->reloc_count++ *
  1026. sizeof (Elf32_External_Rela);
  1027. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1028. bfd_put_32 (output_bfd, 0, sgot->contents + gotoff + i*4);
  1029. }
  1030. }
  1031. /* Static GD. */
  1032. else if (howto->type == R_OR1K_TLS_GD_HI16
  1033. || howto->type == R_OR1K_TLS_GD_LO16)
  1034. {
  1035. bfd_put_32 (output_bfd, 1, sgot->contents + gotoff);
  1036. bfd_put_32 (output_bfd, tpoff (info, relocation),
  1037. sgot->contents + gotoff + 4);
  1038. }
  1039. /* Shared IE. */
  1040. else if (dynamic)
  1041. {
  1042. /* Add TPOFF GOT and rela entries. */
  1043. rela.r_offset = sgot->output_section->vma +
  1044. sgot->output_offset + gotoff;
  1045. if (h != NULL && h->dynindx != -1)
  1046. {
  1047. rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_TLS_TPOFF);
  1048. rela.r_addend = 0;
  1049. }
  1050. else
  1051. {
  1052. rela.r_info = ELF32_R_INFO (0, R_OR1K_TLS_TPOFF);
  1053. rela.r_addend = tpoff (info, relocation);
  1054. }
  1055. loc = sreloc->contents;
  1056. loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
  1057. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1058. bfd_put_32 (output_bfd, 0, sgot->contents + gotoff);
  1059. }
  1060. /* Static IE. */
  1061. else
  1062. {
  1063. bfd_put_32 (output_bfd, tpoff (info, relocation),
  1064. sgot->contents + gotoff);
  1065. }
  1066. relocation = sgot->output_offset + gotoff;
  1067. break;
  1068. }
  1069. case R_OR1K_TLS_LE_HI16:
  1070. case R_OR1K_TLS_LE_LO16:
  1071. /* Relocation is offset from TP. */
  1072. relocation = tpoff (info, relocation);
  1073. break;
  1074. case R_OR1K_TLS_DTPMOD:
  1075. case R_OR1K_TLS_DTPOFF:
  1076. case R_OR1K_TLS_TPOFF:
  1077. /* These are resolved dynamically on load and shouldn't
  1078. be used as linker input. */
  1079. BFD_FAIL ();
  1080. (*_bfd_error_handler)
  1081. (_("%B: will not resolve runtime TLS relocation"),
  1082. input_bfd);
  1083. bfd_set_error (bfd_error_bad_value);
  1084. return FALSE;
  1085. default:
  1086. break;
  1087. }
  1088. r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
  1089. rel->r_offset, relocation, rel->r_addend);
  1090. if (r != bfd_reloc_ok)
  1091. {
  1092. const char *msg = NULL;
  1093. switch (r)
  1094. {
  1095. case bfd_reloc_overflow:
  1096. r = info->callbacks->reloc_overflow
  1097. (info, (h ? &h->root : NULL), name, howto->name,
  1098. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  1099. break;
  1100. case bfd_reloc_undefined:
  1101. r = info->callbacks->undefined_symbol
  1102. (info, name, input_bfd, input_section, rel->r_offset, TRUE);
  1103. break;
  1104. case bfd_reloc_outofrange:
  1105. msg = _("internal error: out of range error");
  1106. break;
  1107. case bfd_reloc_notsupported:
  1108. msg = _("internal error: unsupported relocation error");
  1109. break;
  1110. case bfd_reloc_dangerous:
  1111. msg = _("internal error: dangerous relocation");
  1112. break;
  1113. default:
  1114. msg = _("internal error: unknown error");
  1115. break;
  1116. }
  1117. if (msg)
  1118. r = info->callbacks->warning
  1119. (info, msg, name, input_bfd, input_section, rel->r_offset);
  1120. if (!r)
  1121. return FALSE;
  1122. }
  1123. }
  1124. return TRUE;
  1125. }
  1126. /* Return the section that should be marked against GC for a given
  1127. relocation. */
  1128. static asection *
  1129. or1k_elf_gc_mark_hook (asection *sec,
  1130. struct bfd_link_info *info,
  1131. Elf_Internal_Rela *rel,
  1132. struct elf_link_hash_entry *h,
  1133. Elf_Internal_Sym *sym)
  1134. {
  1135. if (h != NULL)
  1136. switch (ELF32_R_TYPE (rel->r_info))
  1137. {
  1138. case R_OR1K_GNU_VTINHERIT:
  1139. case R_OR1K_GNU_VTENTRY:
  1140. return NULL;
  1141. }
  1142. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  1143. }
  1144. static bfd_boolean
  1145. or1k_elf_gc_sweep_hook (bfd *abfd,
  1146. struct bfd_link_info *info ATTRIBUTE_UNUSED,
  1147. asection *sec,
  1148. const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED)
  1149. {
  1150. /* Update the got entry reference counts for the section being removed. */
  1151. Elf_Internal_Shdr *symtab_hdr;
  1152. struct elf_link_hash_entry **sym_hashes;
  1153. bfd_signed_vma *local_got_refcounts;
  1154. const Elf_Internal_Rela *rel, *relend;
  1155. elf_section_data (sec)->local_dynrel = NULL;
  1156. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  1157. sym_hashes = elf_sym_hashes (abfd);
  1158. local_got_refcounts = elf_local_got_refcounts (abfd);
  1159. relend = relocs + sec->reloc_count;
  1160. for (rel = relocs; rel < relend; rel++)
  1161. {
  1162. unsigned long r_symndx;
  1163. struct elf_link_hash_entry *h = NULL;
  1164. r_symndx = ELF32_R_SYM (rel->r_info);
  1165. if (r_symndx >= symtab_hdr->sh_info)
  1166. {
  1167. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  1168. while (h->root.type == bfd_link_hash_indirect
  1169. || h->root.type == bfd_link_hash_warning)
  1170. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1171. }
  1172. switch (ELF32_R_TYPE (rel->r_info))
  1173. {
  1174. case R_OR1K_GOT16:
  1175. if (h != NULL)
  1176. {
  1177. if (h->got.refcount > 0)
  1178. h->got.refcount--;
  1179. }
  1180. else
  1181. {
  1182. if (local_got_refcounts && local_got_refcounts[r_symndx] > 0)
  1183. local_got_refcounts[r_symndx]--;
  1184. }
  1185. break;
  1186. default:
  1187. break;
  1188. }
  1189. }
  1190. return TRUE;
  1191. }
  1192. /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
  1193. shortcuts to them in our hash table. */
  1194. static bfd_boolean
  1195. create_got_section (bfd *dynobj, struct bfd_link_info *info)
  1196. {
  1197. struct elf_or1k_link_hash_table *htab;
  1198. asection *s;
  1199. /* This function may be called more than once. */
  1200. s = bfd_get_section_by_name (dynobj, ".got");
  1201. if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0)
  1202. return TRUE;
  1203. htab = or1k_elf_hash_table (info);
  1204. if (htab == NULL)
  1205. return FALSE;
  1206. if (! _bfd_elf_create_got_section (dynobj, info))
  1207. return FALSE;
  1208. htab->sgot = bfd_get_section_by_name (dynobj, ".got");
  1209. htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
  1210. htab->srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
  1211. if (! htab->sgot || ! htab->sgotplt || ! htab->srelgot)
  1212. abort ();
  1213. if (! bfd_set_section_flags (dynobj, htab->srelgot, SEC_ALLOC
  1214. | SEC_LOAD
  1215. | SEC_HAS_CONTENTS
  1216. | SEC_IN_MEMORY
  1217. | SEC_LINKER_CREATED
  1218. | SEC_READONLY)
  1219. || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
  1220. return FALSE;
  1221. return TRUE;
  1222. }
  1223. /* Look through the relocs for a section during the first phase. */
  1224. static bfd_boolean
  1225. or1k_elf_check_relocs (bfd *abfd,
  1226. struct bfd_link_info *info,
  1227. asection *sec,
  1228. const Elf_Internal_Rela *relocs)
  1229. {
  1230. Elf_Internal_Shdr *symtab_hdr;
  1231. struct elf_link_hash_entry **sym_hashes;
  1232. const Elf_Internal_Rela *rel;
  1233. const Elf_Internal_Rela *rel_end;
  1234. struct elf_or1k_link_hash_table *htab;
  1235. bfd *dynobj;
  1236. asection *sreloc = NULL;
  1237. if (bfd_link_relocatable (info))
  1238. return TRUE;
  1239. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  1240. sym_hashes = elf_sym_hashes (abfd);
  1241. htab = or1k_elf_hash_table (info);
  1242. if (htab == NULL)
  1243. return FALSE;
  1244. dynobj = htab->root.dynobj;
  1245. rel_end = relocs + sec->reloc_count;
  1246. for (rel = relocs; rel < rel_end; rel++)
  1247. {
  1248. struct elf_link_hash_entry *h;
  1249. unsigned long r_symndx;
  1250. unsigned char tls_type;
  1251. r_symndx = ELF32_R_SYM (rel->r_info);
  1252. if (r_symndx < symtab_hdr->sh_info)
  1253. h = NULL;
  1254. else
  1255. {
  1256. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  1257. while (h->root.type == bfd_link_hash_indirect
  1258. || h->root.type == bfd_link_hash_warning)
  1259. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1260. /* PR15323, ref flags aren't set for references in the same
  1261. object. */
  1262. h->root.non_ir_ref = 1;
  1263. }
  1264. switch (ELF32_R_TYPE (rel->r_info))
  1265. {
  1266. case R_OR1K_TLS_GD_HI16:
  1267. case R_OR1K_TLS_GD_LO16:
  1268. tls_type = TLS_GD;
  1269. break;
  1270. case R_OR1K_TLS_LDM_HI16:
  1271. case R_OR1K_TLS_LDM_LO16:
  1272. case R_OR1K_TLS_LDO_HI16:
  1273. case R_OR1K_TLS_LDO_LO16:
  1274. tls_type = TLS_LD;
  1275. break;
  1276. case R_OR1K_TLS_IE_HI16:
  1277. case R_OR1K_TLS_IE_LO16:
  1278. tls_type = TLS_IE;
  1279. break;
  1280. case R_OR1K_TLS_LE_HI16:
  1281. case R_OR1K_TLS_LE_LO16:
  1282. tls_type = TLS_LE;
  1283. break;
  1284. default:
  1285. tls_type = TLS_NONE;
  1286. }
  1287. /* Record TLS type. */
  1288. if (h != NULL)
  1289. ((struct elf_or1k_link_hash_entry *) h)->tls_type = tls_type;
  1290. else
  1291. {
  1292. unsigned char *local_tls_type;
  1293. /* This is a TLS type record for a local symbol. */
  1294. local_tls_type = (unsigned char *) elf_or1k_local_tls_type (abfd);
  1295. if (local_tls_type == NULL)
  1296. {
  1297. bfd_size_type size;
  1298. size = symtab_hdr->sh_info;
  1299. local_tls_type = bfd_zalloc (abfd, size);
  1300. if (local_tls_type == NULL)
  1301. return FALSE;
  1302. elf_or1k_local_tls_type (abfd) = local_tls_type;
  1303. }
  1304. local_tls_type[r_symndx] = tls_type;
  1305. }
  1306. switch (ELF32_R_TYPE (rel->r_info))
  1307. {
  1308. /* This relocation describes the C++ object vtable hierarchy.
  1309. Reconstruct it for later use during GC. */
  1310. case R_OR1K_GNU_VTINHERIT:
  1311. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  1312. return FALSE;
  1313. break;
  1314. /* This relocation describes which C++ vtable entries are actually
  1315. used. Record for later use during GC. */
  1316. case R_OR1K_GNU_VTENTRY:
  1317. BFD_ASSERT (h != NULL);
  1318. if (h != NULL
  1319. && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  1320. return FALSE;
  1321. break;
  1322. /* This relocation requires .plt entry. */
  1323. case R_OR1K_PLT26:
  1324. if (h != NULL)
  1325. {
  1326. h->needs_plt = 1;
  1327. h->plt.refcount += 1;
  1328. }
  1329. break;
  1330. case R_OR1K_GOT16:
  1331. case R_OR1K_GOTOFF_HI16:
  1332. case R_OR1K_GOTOFF_LO16:
  1333. case R_OR1K_TLS_GD_HI16:
  1334. case R_OR1K_TLS_GD_LO16:
  1335. case R_OR1K_TLS_IE_HI16:
  1336. case R_OR1K_TLS_IE_LO16:
  1337. if (htab->sgot == NULL)
  1338. {
  1339. if (dynobj == NULL)
  1340. htab->root.dynobj = dynobj = abfd;
  1341. if (! create_got_section (dynobj, info))
  1342. return FALSE;
  1343. }
  1344. if (ELF32_R_TYPE (rel->r_info) != R_OR1K_GOTOFF_HI16 &&
  1345. ELF32_R_TYPE (rel->r_info) != R_OR1K_GOTOFF_LO16)
  1346. {
  1347. if (h != NULL)
  1348. h->got.refcount += 1;
  1349. else
  1350. {
  1351. bfd_signed_vma *local_got_refcounts;
  1352. /* This is a global offset table entry for a local symbol. */
  1353. local_got_refcounts = elf_local_got_refcounts (abfd);
  1354. if (local_got_refcounts == NULL)
  1355. {
  1356. bfd_size_type size;
  1357. size = symtab_hdr->sh_info;
  1358. size *= sizeof (bfd_signed_vma);
  1359. local_got_refcounts = bfd_zalloc (abfd, size);
  1360. if (local_got_refcounts == NULL)
  1361. return FALSE;
  1362. elf_local_got_refcounts (abfd) = local_got_refcounts;
  1363. }
  1364. local_got_refcounts[r_symndx] += 1;
  1365. }
  1366. }
  1367. break;
  1368. case R_OR1K_INSN_REL_26:
  1369. case R_OR1K_HI_16_IN_INSN:
  1370. case R_OR1K_LO_16_IN_INSN:
  1371. case R_OR1K_32:
  1372. /* R_OR1K_16? */
  1373. {
  1374. if (h != NULL && !bfd_link_pic (info))
  1375. {
  1376. /* We may need a copy reloc. */
  1377. h->non_got_ref = 1;
  1378. /* We may also need a .plt entry. */
  1379. h->plt.refcount += 1;
  1380. if (ELF32_R_TYPE (rel->r_info) != R_OR1K_INSN_REL_26)
  1381. h->pointer_equality_needed = 1;
  1382. }
  1383. /* If we are creating a shared library, and this is a reloc
  1384. against a global symbol, or a non PC relative reloc
  1385. against a local symbol, then we need to copy the reloc
  1386. into the shared library. However, if we are linking with
  1387. -Bsymbolic, we do not need to copy a reloc against a
  1388. global symbol which is defined in an object we are
  1389. including in the link (i.e., DEF_REGULAR is set). At
  1390. this point we have not seen all the input files, so it is
  1391. possible that DEF_REGULAR is not set now but will be set
  1392. later (it is never cleared). In case of a weak definition,
  1393. DEF_REGULAR may be cleared later by a strong definition in
  1394. a shared library. We account for that possibility below by
  1395. storing information in the relocs_copied field of the hash
  1396. table entry. A similar situation occurs when creating
  1397. shared libraries and symbol visibility changes render the
  1398. symbol local.
  1399. If on the other hand, we are creating an executable, we
  1400. may need to keep relocations for symbols satisfied by a
  1401. dynamic library if we manage to avoid copy relocs for the
  1402. symbol. */
  1403. if ((bfd_link_pic (info)
  1404. && (sec->flags & SEC_ALLOC) != 0
  1405. && (ELF32_R_TYPE (rel->r_info) != R_OR1K_INSN_REL_26
  1406. || (h != NULL
  1407. && (!SYMBOLIC_BIND (info, h)
  1408. || h->root.type == bfd_link_hash_defweak
  1409. || !h->def_regular))))
  1410. || (!bfd_link_pic (info)
  1411. && (sec->flags & SEC_ALLOC) != 0
  1412. && h != NULL
  1413. && (h->root.type == bfd_link_hash_defweak
  1414. || !h->def_regular)))
  1415. {
  1416. struct elf_or1k_dyn_relocs *p;
  1417. struct elf_or1k_dyn_relocs **head;
  1418. /* When creating a shared object, we must copy these
  1419. relocs into the output file. We create a reloc
  1420. section in dynobj and make room for the reloc. */
  1421. if (sreloc == NULL)
  1422. {
  1423. const char *name;
  1424. unsigned int strndx = elf_elfheader (abfd)->e_shstrndx;
  1425. unsigned int shnam = _bfd_elf_single_rel_hdr (sec)->sh_name;
  1426. name = bfd_elf_string_from_elf_section (abfd, strndx, shnam);
  1427. if (name == NULL)
  1428. return FALSE;
  1429. if (strncmp (name, ".rela", 5) != 0
  1430. || strcmp (bfd_get_section_name (abfd, sec),
  1431. name + 5) != 0)
  1432. {
  1433. (*_bfd_error_handler)
  1434. (_("%B: bad relocation section name `%s\'"),
  1435. abfd, name);
  1436. }
  1437. if (htab->root.dynobj == NULL)
  1438. htab->root.dynobj = abfd;
  1439. dynobj = htab->root.dynobj;
  1440. sreloc = bfd_get_section_by_name (dynobj, name);
  1441. if (sreloc == NULL)
  1442. {
  1443. sreloc = _bfd_elf_make_dynamic_reloc_section
  1444. (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
  1445. if (sreloc == NULL)
  1446. return FALSE;
  1447. }
  1448. elf_section_data (sec)->sreloc = sreloc;
  1449. }
  1450. /* If this is a global symbol, we count the number of
  1451. relocations we need for this symbol. */
  1452. if (h != NULL)
  1453. head = &((struct elf_or1k_link_hash_entry *) h)->dyn_relocs;
  1454. else
  1455. {
  1456. /* Track dynamic relocs needed for local syms too.
  1457. We really need local syms available to do this
  1458. easily. Oh well. */
  1459. asection *s;
  1460. Elf_Internal_Sym *isym;
  1461. void *vpp;
  1462. isym = bfd_sym_from_r_symndx (&htab->sym_sec,
  1463. abfd, r_symndx);
  1464. if (isym == NULL)
  1465. return FALSE;
  1466. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  1467. if (s == NULL)
  1468. return FALSE;
  1469. vpp = &elf_section_data (s)->local_dynrel;
  1470. head = (struct elf_or1k_dyn_relocs **) vpp;
  1471. }
  1472. p = *head;
  1473. if (p == NULL || p->sec != sec)
  1474. {
  1475. bfd_size_type amt = sizeof *p;
  1476. p = ((struct elf_or1k_dyn_relocs *)
  1477. bfd_alloc (htab->root.dynobj, amt));
  1478. if (p == NULL)
  1479. return FALSE;
  1480. p->next = *head;
  1481. *head = p;
  1482. p->sec = sec;
  1483. p->count = 0;
  1484. p->pc_count = 0;
  1485. }
  1486. p->count += 1;
  1487. if (ELF32_R_TYPE (rel->r_info) == R_OR1K_INSN_REL_26)
  1488. p->pc_count += 1;
  1489. }
  1490. }
  1491. break;
  1492. }
  1493. }
  1494. return TRUE;
  1495. }
  1496. /* Finish up the dynamic sections. */
  1497. static bfd_boolean
  1498. or1k_elf_finish_dynamic_sections (bfd *output_bfd,
  1499. struct bfd_link_info *info)
  1500. {
  1501. bfd *dynobj;
  1502. asection *sdyn, *sgot;
  1503. struct elf_or1k_link_hash_table *htab;
  1504. htab = or1k_elf_hash_table (info);
  1505. if (htab == NULL)
  1506. return FALSE;
  1507. dynobj = htab->root.dynobj;
  1508. sgot = htab->sgotplt;
  1509. sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
  1510. if (htab->root.dynamic_sections_created)
  1511. {
  1512. asection *splt;
  1513. Elf32_External_Dyn *dyncon, *dynconend;
  1514. BFD_ASSERT (sgot != NULL && sdyn != NULL);
  1515. dyncon = (Elf32_External_Dyn *) sdyn->contents;
  1516. dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
  1517. for (; dyncon < dynconend; dyncon++)
  1518. {
  1519. Elf_Internal_Dyn dyn;
  1520. asection *s;
  1521. bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
  1522. switch (dyn.d_tag)
  1523. {
  1524. default:
  1525. continue;
  1526. case DT_PLTGOT:
  1527. s = htab->sgot->output_section;
  1528. BFD_ASSERT (s != NULL);
  1529. dyn.d_un.d_ptr = s->vma;
  1530. break;
  1531. case DT_JMPREL:
  1532. s = htab->srelplt->output_section;
  1533. BFD_ASSERT (s != NULL);
  1534. dyn.d_un.d_ptr = s->vma;
  1535. break;
  1536. case DT_PLTRELSZ:
  1537. s = htab->srelplt->output_section;
  1538. BFD_ASSERT (s != NULL);
  1539. dyn.d_un.d_val = s->size;
  1540. break;
  1541. case DT_RELASZ:
  1542. /* My reading of the SVR4 ABI indicates that the
  1543. procedure linkage table relocs (DT_JMPREL) should be
  1544. included in the overall relocs (DT_RELA). This is
  1545. what Solaris does. However, UnixWare can not handle
  1546. that case. Therefore, we override the DT_RELASZ entry
  1547. here to make it not include the JMPREL relocs. Since
  1548. the linker script arranges for .rela.plt to follow all
  1549. other relocation sections, we don't have to worry
  1550. about changing the DT_RELA entry. */
  1551. if (htab->srelplt != NULL)
  1552. {
  1553. /* FIXME: this calculation sometimes produces
  1554. wrong result, the problem is that the dyn.d_un.d_val
  1555. is not always correct, needs investigation why
  1556. that happens. In the meantime, reading the
  1557. ".rela.dyn" section by name seems to yield
  1558. correct result.
  1559. s = htab->srelplt->output_section;
  1560. dyn.d_un.d_val -= s->size;
  1561. */
  1562. s = bfd_get_section_by_name (output_bfd, ".rela.dyn");
  1563. dyn.d_un.d_val = s ? s->size : 0;
  1564. }
  1565. break;
  1566. }
  1567. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  1568. }
  1569. /* Fill in the first entry in the procedure linkage table. */
  1570. splt = htab->splt;
  1571. if (splt && splt->size > 0)
  1572. {
  1573. if (bfd_link_pic (info))
  1574. {
  1575. bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD0,
  1576. splt->contents);
  1577. bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD1,
  1578. splt->contents + 4);
  1579. bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD2,
  1580. splt->contents + 8);
  1581. bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD3,
  1582. splt->contents + 12);
  1583. bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD4,
  1584. splt->contents + 16);
  1585. }
  1586. else
  1587. {
  1588. unsigned long addr;
  1589. /* addr = .got + 4 */
  1590. addr = sgot->output_section->vma + sgot->output_offset + 4;
  1591. bfd_put_32 (output_bfd,
  1592. PLT0_ENTRY_WORD0 | ((addr >> 16) & 0xffff),
  1593. splt->contents);
  1594. bfd_put_32 (output_bfd,
  1595. PLT0_ENTRY_WORD1 | (addr & 0xffff),
  1596. splt->contents + 4);
  1597. bfd_put_32 (output_bfd, PLT0_ENTRY_WORD2, splt->contents + 8);
  1598. bfd_put_32 (output_bfd, PLT0_ENTRY_WORD3, splt->contents + 12);
  1599. bfd_put_32 (output_bfd, PLT0_ENTRY_WORD4, splt->contents + 16);
  1600. }
  1601. elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
  1602. }
  1603. }
  1604. /* Set the first entry in the global offset table to the address of
  1605. the dynamic section. */
  1606. if (sgot && sgot->size > 0)
  1607. {
  1608. if (sdyn == NULL)
  1609. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
  1610. else
  1611. bfd_put_32 (output_bfd,
  1612. sdyn->output_section->vma + sdyn->output_offset,
  1613. sgot->contents);
  1614. elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
  1615. }
  1616. if (htab->sgot && htab->sgot->size > 0)
  1617. elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 4;
  1618. return TRUE;
  1619. }
  1620. /* Finish up dynamic symbol handling. We set the contents of various
  1621. dynamic sections here. */
  1622. static bfd_boolean
  1623. or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
  1624. struct bfd_link_info *info,
  1625. struct elf_link_hash_entry *h,
  1626. Elf_Internal_Sym *sym)
  1627. {
  1628. struct elf_or1k_link_hash_table *htab;
  1629. bfd_byte *loc;
  1630. htab = or1k_elf_hash_table (info);
  1631. if (htab == NULL)
  1632. return FALSE;
  1633. if (h->plt.offset != (bfd_vma) -1)
  1634. {
  1635. asection *splt;
  1636. asection *sgot;
  1637. asection *srela;
  1638. bfd_vma plt_index;
  1639. bfd_vma got_offset;
  1640. bfd_vma got_addr;
  1641. Elf_Internal_Rela rela;
  1642. /* This symbol has an entry in the procedure linkage table. Set
  1643. it up. */
  1644. BFD_ASSERT (h->dynindx != -1);
  1645. splt = htab->splt;
  1646. sgot = htab->sgotplt;
  1647. srela = htab->srelplt;
  1648. BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
  1649. /* Get the index in the procedure linkage table which
  1650. corresponds to this symbol. This is the index of this symbol
  1651. in all the symbols for which we are making plt entries. The
  1652. first entry in the procedure linkage table is reserved. */
  1653. plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
  1654. /* Get the offset into the .got table of the entry that
  1655. corresponds to this function. Each .got entry is 4 bytes.
  1656. The first three are reserved. */
  1657. got_offset = (plt_index + 3) * 4;
  1658. got_addr = got_offset;
  1659. /* Fill in the entry in the procedure linkage table. */
  1660. if (! bfd_link_pic (info))
  1661. {
  1662. got_addr += htab->sgotplt->output_section->vma
  1663. + htab->sgotplt->output_offset;
  1664. bfd_put_32 (output_bfd, PLT_ENTRY_WORD0 | ((got_addr >> 16) & 0xffff),
  1665. splt->contents + h->plt.offset);
  1666. bfd_put_32 (output_bfd, PLT_ENTRY_WORD1 | (got_addr & 0xffff),
  1667. splt->contents + h->plt.offset + 4);
  1668. bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD2,
  1669. splt->contents + h->plt.offset + 8);
  1670. bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD3,
  1671. splt->contents + h->plt.offset + 12);
  1672. bfd_put_32 (output_bfd, PLT_ENTRY_WORD4
  1673. | plt_index * sizeof (Elf32_External_Rela),
  1674. splt->contents + h->plt.offset + 16);
  1675. }
  1676. else
  1677. {
  1678. bfd_put_32 (output_bfd, PLT_PIC_ENTRY_WORD0 | (got_addr & 0xffff),
  1679. splt->contents + h->plt.offset);
  1680. bfd_put_32 (output_bfd, PLT_PIC_ENTRY_WORD1
  1681. | plt_index * sizeof (Elf32_External_Rela),
  1682. splt->contents + h->plt.offset + 4);
  1683. bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD2,
  1684. splt->contents + h->plt.offset + 8);
  1685. bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD3,
  1686. splt->contents + h->plt.offset + 12);
  1687. bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD4,
  1688. splt->contents + h->plt.offset + 16);
  1689. }
  1690. /* Fill in the entry in the global offset table. */
  1691. bfd_put_32 (output_bfd,
  1692. (splt->output_section->vma
  1693. + splt->output_offset), /* Same offset. */
  1694. sgot->contents + got_offset);
  1695. /* Fill in the entry in the .rela.plt section. */
  1696. rela.r_offset = (sgot->output_section->vma
  1697. + sgot->output_offset
  1698. + got_offset);
  1699. rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_JMP_SLOT);
  1700. rela.r_addend = 0;
  1701. loc = srela->contents;
  1702. loc += plt_index * sizeof (Elf32_External_Rela);
  1703. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1704. if (!h->def_regular)
  1705. {
  1706. /* Mark the symbol as undefined, rather than as defined in
  1707. the .plt section. Leave the value alone. */
  1708. sym->st_shndx = SHN_UNDEF;
  1709. }
  1710. }
  1711. if (h->got.offset != (bfd_vma) -1
  1712. && (h->got.offset & 2) == 0) /* Homemade TLS check. */
  1713. {
  1714. asection *sgot;
  1715. asection *srela;
  1716. Elf_Internal_Rela rela;
  1717. /* This symbol has an entry in the global offset table. Set it
  1718. up. */
  1719. sgot = htab->sgot;
  1720. srela = htab->srelgot;
  1721. BFD_ASSERT (sgot != NULL && srela != NULL);
  1722. rela.r_offset = (sgot->output_section->vma
  1723. + sgot->output_offset
  1724. + (h->got.offset &~ 1));
  1725. /* If this is a -Bsymbolic link, and the symbol is defined
  1726. locally, we just want to emit a RELATIVE reloc. Likewise if
  1727. the symbol was forced to be local because of a version file.
  1728. The entry in the global offset table will already have been
  1729. initialized in the relocate_section function. */
  1730. if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
  1731. {
  1732. rela.r_info = ELF32_R_INFO (0, R_OR1K_RELATIVE);
  1733. rela.r_addend = (h->root.u.def.value
  1734. + h->root.u.def.section->output_section->vma
  1735. + h->root.u.def.section->output_offset);
  1736. }
  1737. else
  1738. {
  1739. BFD_ASSERT ((h->got.offset & 1) == 0);
  1740. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
  1741. rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_GLOB_DAT);
  1742. rela.r_addend = 0;
  1743. }
  1744. loc = srela->contents;
  1745. loc += srela->reloc_count * sizeof (Elf32_External_Rela);
  1746. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1747. ++srela->reloc_count;
  1748. }
  1749. if (h->needs_copy)
  1750. {
  1751. asection *s;
  1752. Elf_Internal_Rela rela;
  1753. /* This symbols needs a copy reloc. Set it up. */
  1754. BFD_ASSERT (h->dynindx != -1
  1755. && (h->root.type == bfd_link_hash_defined
  1756. || h->root.type == bfd_link_hash_defweak));
  1757. s = bfd_get_section_by_name (h->root.u.def.section->owner,
  1758. ".rela.bss");
  1759. BFD_ASSERT (s != NULL);
  1760. rela.r_offset = (h->root.u.def.value
  1761. + h->root.u.def.section->output_section->vma
  1762. + h->root.u.def.section->output_offset);
  1763. rela.r_info = ELF32_R_INFO (h->dynindx, R_OR1K_COPY);
  1764. rela.r_addend = 0;
  1765. loc = s->contents;
  1766. loc += s->reloc_count * sizeof (Elf32_External_Rela);
  1767. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1768. ++s->reloc_count;
  1769. }
  1770. /* Mark some specially defined symbols as absolute. */
  1771. if (strcmp (h->root.root.string, "_DYNAMIC") == 0
  1772. || h == htab->root.hgot)
  1773. sym->st_shndx = SHN_ABS;
  1774. return TRUE;
  1775. }
  1776. static enum elf_reloc_type_class
  1777. or1k_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
  1778. const asection *rel_sec ATTRIBUTE_UNUSED,
  1779. const Elf_Internal_Rela *rela)
  1780. {
  1781. switch ((int) ELF32_R_TYPE (rela->r_info))
  1782. {
  1783. case R_OR1K_RELATIVE: return reloc_class_relative;
  1784. case R_OR1K_JMP_SLOT: return reloc_class_plt;
  1785. case R_OR1K_COPY: return reloc_class_copy;
  1786. default: return reloc_class_normal;
  1787. }
  1788. }
  1789. /* Adjust a symbol defined by a dynamic object and referenced by a
  1790. regular object. The current definition is in some section of the
  1791. dynamic object, but we're not including those sections. We have to
  1792. change the definition to something the rest of the link can
  1793. understand. */
  1794. static bfd_boolean
  1795. or1k_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
  1796. struct elf_link_hash_entry *h)
  1797. {
  1798. struct elf_or1k_link_hash_table *htab;
  1799. struct elf_or1k_link_hash_entry *eh;
  1800. struct elf_or1k_dyn_relocs *p;
  1801. bfd *dynobj;
  1802. asection *s;
  1803. dynobj = elf_hash_table (info)->dynobj;
  1804. /* Make sure we know what is going on here. */
  1805. BFD_ASSERT (dynobj != NULL
  1806. && (h->needs_plt
  1807. || h->u.weakdef != NULL
  1808. || (h->def_dynamic
  1809. && h->ref_regular
  1810. && !h->def_regular)));
  1811. /* If this is a function, put it in the procedure linkage table. We
  1812. will fill in the contents of the procedure linkage table later,
  1813. when we know the address of the .got section. */
  1814. if (h->type == STT_FUNC
  1815. || h->needs_plt)
  1816. {
  1817. if (! bfd_link_pic (info)
  1818. && !h->def_dynamic
  1819. && !h->ref_dynamic
  1820. && h->root.type != bfd_link_hash_undefweak
  1821. && h->root.type != bfd_link_hash_undefined)
  1822. {
  1823. /* This case can occur if we saw a PLT reloc in an input
  1824. file, but the symbol was never referred to by a dynamic
  1825. object. In such a case, we don't actually need to build
  1826. a procedure linkage table, and we can just do a PCREL
  1827. reloc instead. */
  1828. h->plt.offset = (bfd_vma) -1;
  1829. h->needs_plt = 0;
  1830. }
  1831. return TRUE;
  1832. }
  1833. else
  1834. h->plt.offset = (bfd_vma) -1;
  1835. /* If this is a weak symbol, and there is a real definition, the
  1836. processor independent code will have arranged for us to see the
  1837. real definition first, and we can just use the same value. */
  1838. if (h->u.weakdef != NULL)
  1839. {
  1840. BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
  1841. || h->u.weakdef->root.type == bfd_link_hash_defweak);
  1842. h->root.u.def.section = h->u.weakdef->root.u.def.section;
  1843. h->root.u.def.value = h->u.weakdef->root.u.def.value;
  1844. return TRUE;
  1845. }
  1846. /* This is a reference to a symbol defined by a dynamic object which
  1847. is not a function. */
  1848. /* If we are creating a shared library, we must presume that the
  1849. only references to the symbol are via the global offset table.
  1850. For such cases we need not do anything here; the relocations will
  1851. be handled correctly by relocate_section. */
  1852. if (bfd_link_pic (info))
  1853. return TRUE;
  1854. /* If there are no references to this symbol that do not use the
  1855. GOT, we don't need to generate a copy reloc. */
  1856. if (!h->non_got_ref)
  1857. return TRUE;
  1858. /* If -z nocopyreloc was given, we won't generate them either. */
  1859. if (info->nocopyreloc)
  1860. {
  1861. h->non_got_ref = 0;
  1862. return TRUE;
  1863. }
  1864. eh = (struct elf_or1k_link_hash_entry *) h;
  1865. for (p = eh->dyn_relocs; p != NULL; p = p->next)
  1866. {
  1867. s = p->sec->output_section;
  1868. if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0)
  1869. break;
  1870. }
  1871. /* If we didn't find any dynamic relocs in sections which needs the
  1872. copy reloc, then we'll be keeping the dynamic relocs and avoiding
  1873. the copy reloc. */
  1874. if (p == NULL)
  1875. {
  1876. h->non_got_ref = 0;
  1877. return TRUE;
  1878. }
  1879. /* We must allocate the symbol in our .dynbss section, which will
  1880. become part of the .bss section of the executable. There will be
  1881. an entry for this symbol in the .dynsym section. The dynamic
  1882. object will contain position independent code, so all references
  1883. from the dynamic object to this symbol will go through the global
  1884. offset table. The dynamic linker will use the .dynsym entry to
  1885. determine the address it must put in the global offset table, so
  1886. both the dynamic object and the regular object will refer to the
  1887. same memory location for the variable. */
  1888. htab = or1k_elf_hash_table (info);
  1889. if (htab == NULL)
  1890. return FALSE;
  1891. s = htab->sdynbss;
  1892. BFD_ASSERT (s != NULL);
  1893. /* We must generate a R_OR1K_COPY reloc to tell the dynamic linker
  1894. to copy the initial value out of the dynamic object and into the
  1895. runtime process image. We need to remember the offset into the
  1896. .rela.bss section we are going to use. */
  1897. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  1898. {
  1899. asection *srel;
  1900. srel = htab->srelbss;
  1901. BFD_ASSERT (srel != NULL);
  1902. srel->size += sizeof (Elf32_External_Rela);
  1903. h->needs_copy = 1;
  1904. }
  1905. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  1906. }
  1907. /* Allocate space in .plt, .got and associated reloc sections for
  1908. dynamic relocs. */
  1909. static bfd_boolean
  1910. allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
  1911. {
  1912. struct bfd_link_info *info;
  1913. struct elf_or1k_link_hash_table *htab;
  1914. struct elf_or1k_link_hash_entry *eh;
  1915. struct elf_or1k_dyn_relocs *p;
  1916. if (h->root.type == bfd_link_hash_indirect)
  1917. return TRUE;
  1918. info = (struct bfd_link_info *) inf;
  1919. htab = or1k_elf_hash_table (info);
  1920. if (htab == NULL)
  1921. return FALSE;
  1922. eh = (struct elf_or1k_link_hash_entry *) h;
  1923. if (htab->root.dynamic_sections_created
  1924. && h->plt.refcount > 0)
  1925. {
  1926. /* Make sure this symbol is output as a dynamic symbol.
  1927. Undefined weak syms won't yet be marked as dynamic. */
  1928. if (h->dynindx == -1
  1929. && !h->forced_local)
  1930. {
  1931. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1932. return FALSE;
  1933. }
  1934. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
  1935. {
  1936. asection *s = htab->splt;
  1937. /* If this is the first .plt entry, make room for the special
  1938. first entry. */
  1939. if (s->size == 0)
  1940. s->size = PLT_ENTRY_SIZE;
  1941. h->plt.offset = s->size;
  1942. /* If this symbol is not defined in a regular file, and we are
  1943. not generating a shared library, then set the symbol to this
  1944. location in the .plt. This is required to make function
  1945. pointers compare as equal between the normal executable and
  1946. the shared library. */
  1947. if (! bfd_link_pic (info)
  1948. && !h->def_regular)
  1949. {
  1950. h->root.u.def.section = s;
  1951. h->root.u.def.value = h->plt.offset;
  1952. }
  1953. /* Make room for this entry. */
  1954. s->size += PLT_ENTRY_SIZE;
  1955. /* We also need to make an entry in the .got.plt section, which
  1956. will be placed in the .got section by the linker script. */
  1957. htab->sgotplt->size += 4;
  1958. /* We also need to make an entry in the .rel.plt section. */
  1959. htab->srelplt->size += sizeof (Elf32_External_Rela);
  1960. }
  1961. else
  1962. {
  1963. h->plt.offset = (bfd_vma) -1;
  1964. h->needs_plt = 0;
  1965. }
  1966. }
  1967. else
  1968. {
  1969. h->plt.offset = (bfd_vma) -1;
  1970. h->needs_plt = 0;
  1971. }
  1972. if (h->got.refcount > 0)
  1973. {
  1974. asection *s;
  1975. bfd_boolean dyn;
  1976. unsigned char tls_type;
  1977. /* Make sure this symbol is output as a dynamic symbol.
  1978. Undefined weak syms won't yet be marked as dynamic. */
  1979. if (h->dynindx == -1
  1980. && !h->forced_local)
  1981. {
  1982. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1983. return FALSE;
  1984. }
  1985. s = htab->sgot;
  1986. h->got.offset = s->size;
  1987. tls_type = ((struct elf_or1k_link_hash_entry *) h)->tls_type;
  1988. /* TLS GD requires two GOT and two relocs. */
  1989. if (tls_type == TLS_GD)
  1990. s->size += 8;
  1991. else
  1992. s->size += 4;
  1993. dyn = htab->root.dynamic_sections_created;
  1994. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
  1995. {
  1996. if (tls_type == TLS_GD)
  1997. htab->srelgot->size += 2 * sizeof (Elf32_External_Rela);
  1998. else
  1999. htab->srelgot->size += sizeof (Elf32_External_Rela);
  2000. }
  2001. }
  2002. else
  2003. h->got.offset = (bfd_vma) -1;
  2004. if (eh->dyn_relocs == NULL)
  2005. return TRUE;
  2006. /* In the shared -Bsymbolic case, discard space allocated for
  2007. dynamic pc-relative relocs against symbols which turn out to be
  2008. defined in regular objects. For the normal shared case, discard
  2009. space for pc-relative relocs that have become local due to symbol
  2010. visibility changes. */
  2011. if (bfd_link_pic (info))
  2012. {
  2013. if (SYMBOL_CALLS_LOCAL (info, h))
  2014. {
  2015. struct elf_or1k_dyn_relocs **pp;
  2016. for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
  2017. {
  2018. p->count -= p->pc_count;
  2019. p->pc_count = 0;
  2020. if (p->count == 0)
  2021. *pp = p->next;
  2022. else
  2023. pp = &p->next;
  2024. }
  2025. }
  2026. /* Also discard relocs on undefined weak syms with non-default
  2027. visibility. */
  2028. if (eh->dyn_relocs != NULL
  2029. && h->root.type == bfd_link_hash_undefweak)
  2030. {
  2031. if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
  2032. eh->dyn_relocs = NULL;
  2033. /* Make sure undefined weak symbols are output as a dynamic
  2034. symbol in PIEs. */
  2035. else if (h->dynindx == -1
  2036. && !h->forced_local)
  2037. {
  2038. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2039. return FALSE;
  2040. }
  2041. }
  2042. }
  2043. else
  2044. {
  2045. /* For the non-shared case, discard space for relocs against
  2046. symbols which turn out to need copy relocs or are not
  2047. dynamic. */
  2048. if (!h->non_got_ref
  2049. && ((h->def_dynamic
  2050. && !h->def_regular)
  2051. || (htab->root.dynamic_sections_created
  2052. && (h->root.type == bfd_link_hash_undefweak
  2053. || h->root.type == bfd_link_hash_undefined))))
  2054. {
  2055. /* Make sure this symbol is output as a dynamic symbol.
  2056. Undefined weak syms won't yet be marked as dynamic. */
  2057. if (h->dynindx == -1
  2058. && !h->forced_local)
  2059. {
  2060. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  2061. return FALSE;
  2062. }
  2063. /* If that succeeded, we know we'll be keeping all the
  2064. relocs. */
  2065. if (h->dynindx != -1)
  2066. goto keep;
  2067. }
  2068. eh->dyn_relocs = NULL;
  2069. keep: ;
  2070. }
  2071. /* Finally, allocate space. */
  2072. for (p = eh->dyn_relocs; p != NULL; p = p->next)
  2073. {
  2074. asection *sreloc = elf_section_data (p->sec)->sreloc;
  2075. sreloc->size += p->count * sizeof (Elf32_External_Rela);
  2076. }
  2077. return TRUE;
  2078. }
  2079. /* Find any dynamic relocs that apply to read-only sections. */
  2080. static bfd_boolean
  2081. readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf)
  2082. {
  2083. struct elf_or1k_link_hash_entry *eh;
  2084. struct elf_or1k_dyn_relocs *p;
  2085. eh = (struct elf_or1k_link_hash_entry *) h;
  2086. for (p = eh->dyn_relocs; p != NULL; p = p->next)
  2087. {
  2088. asection *s = p->sec->output_section;
  2089. if (s != NULL && (s->flags & SEC_READONLY) != 0)
  2090. {
  2091. struct bfd_link_info *info = (struct bfd_link_info *) inf;
  2092. info->flags |= DF_TEXTREL;
  2093. /* Not an error, just cut short the traversal. */
  2094. return FALSE;
  2095. }
  2096. }
  2097. return TRUE;
  2098. }
  2099. /* Set the sizes of the dynamic sections. */
  2100. static bfd_boolean
  2101. or1k_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  2102. struct bfd_link_info *info)
  2103. {
  2104. struct elf_or1k_link_hash_table *htab;
  2105. bfd *dynobj;
  2106. asection *s;
  2107. bfd_boolean relocs;
  2108. bfd *ibfd;
  2109. htab = or1k_elf_hash_table (info);
  2110. if (htab == NULL)
  2111. return FALSE;
  2112. dynobj = htab->root.dynobj;
  2113. BFD_ASSERT (dynobj != NULL);
  2114. if (htab->root.dynamic_sections_created)
  2115. {
  2116. /* Set the contents of the .interp section to the interpreter. */
  2117. if (bfd_link_executable (info) && !info->nointerp)
  2118. {
  2119. s = bfd_get_section_by_name (dynobj, ".interp");
  2120. BFD_ASSERT (s != NULL);
  2121. s->size = sizeof ELF_DYNAMIC_INTERPRETER;
  2122. s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
  2123. }
  2124. }
  2125. /* Set up .got offsets for local syms, and space for local dynamic
  2126. relocs. */
  2127. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  2128. {
  2129. bfd_signed_vma *local_got;
  2130. bfd_signed_vma *end_local_got;
  2131. bfd_size_type locsymcount;
  2132. Elf_Internal_Shdr *symtab_hdr;
  2133. unsigned char *local_tls_type;
  2134. asection *srel;
  2135. if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
  2136. continue;
  2137. for (s = ibfd->sections; s != NULL; s = s->next)
  2138. {
  2139. struct elf_or1k_dyn_relocs *p;
  2140. for (p = ((struct elf_or1k_dyn_relocs *)
  2141. elf_section_data (s)->local_dynrel);
  2142. p != NULL;
  2143. p = p->next)
  2144. {
  2145. if (! bfd_is_abs_section (p->sec)
  2146. && bfd_is_abs_section (p->sec->output_section))
  2147. {
  2148. /* Input section has been discarded, either because
  2149. it is a copy of a linkonce section or due to
  2150. linker script /DISCARD/, so we'll be discarding
  2151. the relocs too. */
  2152. }
  2153. else if (p->count != 0)
  2154. {
  2155. srel = elf_section_data (p->sec)->sreloc;
  2156. srel->size += p->count * sizeof (Elf32_External_Rela);
  2157. if ((p->sec->output_section->flags & SEC_READONLY) != 0)
  2158. info->flags |= DF_TEXTREL;
  2159. }
  2160. }
  2161. }
  2162. local_got = elf_local_got_refcounts (ibfd);
  2163. if (!local_got)
  2164. continue;
  2165. symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
  2166. locsymcount = symtab_hdr->sh_info;
  2167. end_local_got = local_got + locsymcount;
  2168. s = htab->sgot;
  2169. srel = htab->srelgot;
  2170. local_tls_type = (unsigned char *) elf_or1k_local_tls_type (ibfd);
  2171. for (; local_got < end_local_got; ++local_got)
  2172. {
  2173. if (*local_got > 0)
  2174. {
  2175. *local_got = s->size;
  2176. /* TLS GD requires two GOT and two relocs. */
  2177. if (local_tls_type != NULL && *local_tls_type == TLS_GD)
  2178. s->size += 8;
  2179. else
  2180. s->size += 4;
  2181. if (bfd_link_pic (info))
  2182. {
  2183. if (local_tls_type != NULL && *local_tls_type == TLS_GD)
  2184. srel->size += 2 * sizeof (Elf32_External_Rela);
  2185. else
  2186. srel->size += sizeof (Elf32_External_Rela);
  2187. }
  2188. }
  2189. else
  2190. *local_got = (bfd_vma) -1;
  2191. if (local_tls_type)
  2192. ++local_tls_type;
  2193. }
  2194. }
  2195. /* Allocate global sym .plt and .got entries, and space for global
  2196. sym dynamic relocs. */
  2197. elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
  2198. /* We now have determined the sizes of the various dynamic sections.
  2199. Allocate memory for them. */
  2200. relocs = FALSE;
  2201. for (s = dynobj->sections; s != NULL; s = s->next)
  2202. {
  2203. if ((s->flags & SEC_LINKER_CREATED) == 0)
  2204. continue;
  2205. if (s == htab->splt
  2206. || s == htab->sgot
  2207. || s == htab->sgotplt
  2208. || s == htab->sdynbss)
  2209. {
  2210. /* Strip this section if we don't need it; see the
  2211. comment below. */
  2212. }
  2213. else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
  2214. {
  2215. if (s->size != 0 && s != htab->srelplt)
  2216. relocs = TRUE;
  2217. /* We use the reloc_count field as a counter if we need
  2218. to copy relocs into the output file. */
  2219. s->reloc_count = 0;
  2220. }
  2221. else
  2222. /* It's not one of our sections, so don't allocate space. */
  2223. continue;
  2224. if (s->size == 0)
  2225. {
  2226. /* If we don't need this section, strip it from the
  2227. output file. This is mostly to handle .rela.bss and
  2228. .rela.plt. We must create both sections in
  2229. create_dynamic_sections, because they must be created
  2230. before the linker maps input sections to output
  2231. sections. The linker does that before
  2232. adjust_dynamic_symbol is called, and it is that
  2233. function which decides whether anything needs to go
  2234. into these sections. */
  2235. s->flags |= SEC_EXCLUDE;
  2236. continue;
  2237. }
  2238. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  2239. continue;
  2240. /* Allocate memory for the section contents. We use bfd_zalloc
  2241. here in case unused entries are not reclaimed before the
  2242. section's contents are written out. This should not happen,
  2243. but this way if it does, we get a R_OR1K_NONE reloc instead
  2244. of garbage. */
  2245. s->contents = bfd_zalloc (dynobj, s->size);
  2246. if (s->contents == NULL)
  2247. return FALSE;
  2248. }
  2249. if (htab->root.dynamic_sections_created)
  2250. {
  2251. /* Add some entries to the .dynamic section. We fill in the
  2252. values later, in or1k_elf_finish_dynamic_sections, but we
  2253. must add the entries now so that we get the correct size for
  2254. the .dynamic section. The DT_DEBUG entry is filled in by the
  2255. dynamic linker and used by the debugger. */
  2256. #define add_dynamic_entry(TAG, VAL) \
  2257. _bfd_elf_add_dynamic_entry (info, TAG, VAL)
  2258. if (bfd_link_executable (info))
  2259. {
  2260. if (! add_dynamic_entry (DT_DEBUG, 0))
  2261. return FALSE;
  2262. }
  2263. if (htab->splt->size != 0)
  2264. {
  2265. if (! add_dynamic_entry (DT_PLTGOT, 0)
  2266. || ! add_dynamic_entry (DT_PLTRELSZ, 0)
  2267. || ! add_dynamic_entry (DT_PLTREL, DT_RELA)
  2268. || ! add_dynamic_entry (DT_JMPREL, 0))
  2269. return FALSE;
  2270. }
  2271. if (relocs)
  2272. {
  2273. if (! add_dynamic_entry (DT_RELA, 0)
  2274. || ! add_dynamic_entry (DT_RELASZ, 0)
  2275. || ! add_dynamic_entry (DT_RELAENT,
  2276. sizeof (Elf32_External_Rela)))
  2277. return FALSE;
  2278. /* If any dynamic relocs apply to a read-only section,
  2279. then we need a DT_TEXTREL entry. */
  2280. if ((info->flags & DF_TEXTREL) == 0)
  2281. elf_link_hash_traverse (&htab->root, readonly_dynrelocs,
  2282. info);
  2283. if ((info->flags & DF_TEXTREL) != 0)
  2284. {
  2285. if (! add_dynamic_entry (DT_TEXTREL, 0))
  2286. return FALSE;
  2287. }
  2288. }
  2289. }
  2290. #undef add_dynamic_entry
  2291. return TRUE;
  2292. }
  2293. /* Create dynamic sections when linking against a dynamic object. */
  2294. static bfd_boolean
  2295. or1k_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
  2296. {
  2297. struct elf_or1k_link_hash_table *htab;
  2298. htab = or1k_elf_hash_table (info);
  2299. if (htab == NULL)
  2300. return FALSE;
  2301. if (!htab->sgot && !create_got_section (dynobj, info))
  2302. return FALSE;
  2303. if (!_bfd_elf_create_dynamic_sections (dynobj, info))
  2304. return FALSE;
  2305. htab->splt = bfd_get_section_by_name (dynobj, ".plt");
  2306. htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
  2307. htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
  2308. if (!bfd_link_pic (info))
  2309. htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
  2310. if (!htab->splt || !htab->srelplt || !htab->sdynbss
  2311. || (!bfd_link_pic (info) && !htab->srelbss))
  2312. abort ();
  2313. return TRUE;
  2314. }
  2315. /* Copy the extra info we tack onto an elf_link_hash_entry. */
  2316. static void
  2317. or1k_elf_copy_indirect_symbol (struct bfd_link_info *info,
  2318. struct elf_link_hash_entry *dir,
  2319. struct elf_link_hash_entry *ind)
  2320. {
  2321. struct elf_or1k_link_hash_entry * edir;
  2322. struct elf_or1k_link_hash_entry * eind;
  2323. edir = (struct elf_or1k_link_hash_entry *) dir;
  2324. eind = (struct elf_or1k_link_hash_entry *) ind;
  2325. if (eind->dyn_relocs != NULL)
  2326. {
  2327. if (edir->dyn_relocs != NULL)
  2328. {
  2329. struct elf_or1k_dyn_relocs **pp;
  2330. struct elf_or1k_dyn_relocs *p;
  2331. /* Add reloc counts against the indirect sym to the direct sym
  2332. list. Merge any entries against the same section. */
  2333. for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
  2334. {
  2335. struct elf_or1k_dyn_relocs *q;
  2336. for (q = edir->dyn_relocs; q != NULL; q = q->next)
  2337. if (q->sec == p->sec)
  2338. {
  2339. q->pc_count += p->pc_count;
  2340. q->count += p->count;
  2341. *pp = p->next;
  2342. break;
  2343. }
  2344. if (q == NULL)
  2345. pp = &p->next;
  2346. }
  2347. *pp = edir->dyn_relocs;
  2348. }
  2349. edir->dyn_relocs = eind->dyn_relocs;
  2350. eind->dyn_relocs = NULL;
  2351. }
  2352. if (ind->root.type == bfd_link_hash_indirect)
  2353. {
  2354. if (dir->got.refcount <= 0)
  2355. {
  2356. edir->tls_type = eind->tls_type;
  2357. eind->tls_type = TLS_UNKNOWN;
  2358. }
  2359. }
  2360. _bfd_elf_link_hash_copy_indirect (info, dir, ind);
  2361. }
  2362. /* Set the right machine number. */
  2363. static bfd_boolean
  2364. or1k_elf_object_p (bfd *abfd)
  2365. {
  2366. unsigned long mach = bfd_mach_or1k;
  2367. if (elf_elfheader (abfd)->e_flags & EF_OR1K_NODELAY)
  2368. mach = bfd_mach_or1knd;
  2369. return bfd_default_set_arch_mach (abfd, bfd_arch_or1k, mach);
  2370. }
  2371. /* Store the machine number in the flags field. */
  2372. static void
  2373. or1k_elf_final_write_processing (bfd *abfd,
  2374. bfd_boolean linker ATTRIBUTE_UNUSED)
  2375. {
  2376. switch (bfd_get_mach (abfd))
  2377. {
  2378. default:
  2379. case bfd_mach_or1k:
  2380. break;
  2381. case bfd_mach_or1knd:
  2382. elf_elfheader (abfd)->e_flags |= EF_OR1K_NODELAY;
  2383. break;
  2384. }
  2385. }
  2386. static bfd_boolean
  2387. or1k_elf_set_private_flags (bfd *abfd, flagword flags)
  2388. {
  2389. BFD_ASSERT (!elf_flags_init (abfd)
  2390. || elf_elfheader (abfd)->e_flags == flags);
  2391. elf_elfheader (abfd)->e_flags = flags;
  2392. elf_flags_init (abfd) = TRUE;
  2393. return TRUE;
  2394. }
  2395. /* Make sure all input files are consistent with respect to
  2396. EF_OR1K_NODELAY flag setting. */
  2397. static bfd_boolean
  2398. elf32_or1k_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
  2399. {
  2400. flagword out_flags;
  2401. flagword in_flags;
  2402. in_flags = elf_elfheader (ibfd)->e_flags;
  2403. out_flags = elf_elfheader (obfd)->e_flags;
  2404. if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
  2405. || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
  2406. return TRUE;
  2407. if (!elf_flags_init (obfd))
  2408. {
  2409. elf_flags_init (obfd) = TRUE;
  2410. elf_elfheader (obfd)->e_flags = in_flags;
  2411. return TRUE;
  2412. }
  2413. if (in_flags == out_flags)
  2414. return TRUE;
  2415. if ((in_flags & EF_OR1K_NODELAY) != (out_flags & EF_OR1K_NODELAY))
  2416. {
  2417. (*_bfd_error_handler)
  2418. (_("%B: EF_OR1K_NODELAY flag mismatch with previous modules"), ibfd);
  2419. bfd_set_error (bfd_error_bad_value);
  2420. return FALSE;
  2421. }
  2422. return TRUE;
  2423. }
  2424. #define ELF_ARCH bfd_arch_or1k
  2425. #define ELF_MACHINE_CODE EM_OR1K
  2426. #define ELF_TARGET_ID OR1K_ELF_DATA
  2427. #define ELF_MAXPAGESIZE 0x2000
  2428. #define TARGET_BIG_SYM or1k_elf32_vec
  2429. #define TARGET_BIG_NAME "elf32-or1k"
  2430. #define elf_info_to_howto_rel NULL
  2431. #define elf_info_to_howto or1k_info_to_howto_rela
  2432. #define elf_backend_relocate_section or1k_elf_relocate_section
  2433. #define elf_backend_gc_mark_hook or1k_elf_gc_mark_hook
  2434. #define elf_backend_gc_sweep_hook or1k_elf_gc_sweep_hook
  2435. #define elf_backend_check_relocs or1k_elf_check_relocs
  2436. #define elf_backend_reloc_type_class or1k_elf_reloc_type_class
  2437. #define elf_backend_can_gc_sections 1
  2438. #define elf_backend_rela_normal 1
  2439. #define bfd_elf32_mkobject elf_or1k_mkobject
  2440. #define bfd_elf32_bfd_merge_private_bfd_data elf32_or1k_merge_private_bfd_data
  2441. #define bfd_elf32_bfd_set_private_flags or1k_elf_set_private_flags
  2442. #define bfd_elf32_bfd_reloc_type_lookup or1k_reloc_type_lookup
  2443. #define bfd_elf32_bfd_reloc_name_lookup or1k_reloc_name_lookup
  2444. #define elf_backend_object_p or1k_elf_object_p
  2445. #define elf_backend_final_write_processing or1k_elf_final_write_processing
  2446. #define elf_backend_can_refcount 1
  2447. #define elf_backend_plt_readonly 1
  2448. #define elf_backend_want_got_plt 1
  2449. #define elf_backend_want_plt_sym 0
  2450. #define elf_backend_got_header_size 12
  2451. #define bfd_elf32_bfd_link_hash_table_create or1k_elf_link_hash_table_create
  2452. #define elf_backend_copy_indirect_symbol or1k_elf_copy_indirect_symbol
  2453. #define elf_backend_create_dynamic_sections or1k_elf_create_dynamic_sections
  2454. #define elf_backend_finish_dynamic_sections or1k_elf_finish_dynamic_sections
  2455. #define elf_backend_size_dynamic_sections or1k_elf_size_dynamic_sections
  2456. #define elf_backend_adjust_dynamic_symbol or1k_elf_adjust_dynamic_symbol
  2457. #define elf_backend_finish_dynamic_symbol or1k_elf_finish_dynamic_symbol
  2458. #include "elf32-target.h"