elf32-lm32.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424
  1. /* Lattice Mico32-specific support for 32-bit ELF
  2. Copyright (C) 2008-2022 Free Software Foundation, Inc.
  3. Contributed by Jon Beniston <jon@beniston.com>
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "libbfd.h"
  20. #include "elf-bfd.h"
  21. #include "elf/lm32.h"
  22. #define DEFAULT_STACK_SIZE 0x20000
  23. #define PLT_ENTRY_SIZE 20
  24. #define PLT0_ENTRY_WORD0 0
  25. #define PLT0_ENTRY_WORD1 0
  26. #define PLT0_ENTRY_WORD2 0
  27. #define PLT0_ENTRY_WORD3 0
  28. #define PLT0_ENTRY_WORD4 0
  29. #define PLT0_PIC_ENTRY_WORD0 0
  30. #define PLT0_PIC_ENTRY_WORD1 0
  31. #define PLT0_PIC_ENTRY_WORD2 0
  32. #define PLT0_PIC_ENTRY_WORD3 0
  33. #define PLT0_PIC_ENTRY_WORD4 0
  34. #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
  35. extern const bfd_target lm32_elf32_fdpic_vec;
  36. #define IS_FDPIC(bfd) ((bfd)->xvec == &lm32_elf32_fdpic_vec)
  37. static bfd_reloc_status_type lm32_elf_gprel_reloc
  38. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  39. /* lm32 ELF linker hash table. */
  40. struct elf_lm32_link_hash_table
  41. {
  42. struct elf_link_hash_table root;
  43. /* Short-cuts to get to dynamic linker sections. */
  44. asection *sfixup32;
  45. asection *sdynbss;
  46. asection *srelbss;
  47. int relocs32;
  48. };
  49. /* Get the lm32 ELF linker hash table from a link_info structure. */
  50. #define lm32_elf_hash_table(p) \
  51. ((is_elf_hash_table ((p)->hash) \
  52. && elf_hash_table_id (elf_hash_table (p)) == LM32_ELF_DATA) \
  53. ? (struct elf_lm32_link_hash_table *) (p)->hash : NULL)
  54. #define lm32fdpic_got_section(info) \
  55. (lm32_elf_hash_table (info)->root.sgot)
  56. #define lm32fdpic_gotrel_section(info) \
  57. (lm32_elf_hash_table (info)->root.srelgot)
  58. #define lm32fdpic_fixup32_section(info) \
  59. (lm32_elf_hash_table (info)->sfixup32)
  60. struct weak_symbol_list
  61. {
  62. const char *name;
  63. struct weak_symbol_list *next;
  64. };
  65. /* Create an lm32 ELF linker hash table. */
  66. static struct bfd_link_hash_table *
  67. lm32_elf_link_hash_table_create (bfd *abfd)
  68. {
  69. struct elf_lm32_link_hash_table *ret;
  70. size_t amt = sizeof (struct elf_lm32_link_hash_table);
  71. ret = bfd_zmalloc (amt);
  72. if (ret == NULL)
  73. return NULL;
  74. if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
  75. _bfd_elf_link_hash_newfunc,
  76. sizeof (struct elf_link_hash_entry),
  77. LM32_ELF_DATA))
  78. {
  79. free (ret);
  80. return NULL;
  81. }
  82. return &ret->root.root;
  83. }
  84. /* Add a fixup to the ROFIXUP section. */
  85. static bfd_vma
  86. _lm32fdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma relocation)
  87. {
  88. bfd_vma fixup_offset;
  89. if (rofixup->flags & SEC_EXCLUDE)
  90. return -1;
  91. fixup_offset = rofixup->reloc_count * 4;
  92. if (rofixup->contents)
  93. {
  94. BFD_ASSERT (fixup_offset < rofixup->size);
  95. if (fixup_offset < rofixup->size)
  96. bfd_put_32 (output_bfd, relocation, rofixup->contents + fixup_offset);
  97. }
  98. rofixup->reloc_count++;
  99. return fixup_offset;
  100. }
  101. /* Create .rofixup sections in DYNOBJ, and set up
  102. shortcuts to them in our hash table. */
  103. static bool
  104. create_rofixup_section (bfd *dynobj, struct bfd_link_info *info)
  105. {
  106. struct elf_lm32_link_hash_table *htab;
  107. htab = lm32_elf_hash_table (info);
  108. if (htab == NULL)
  109. return false;
  110. /* Fixup section for R_LM32_32 relocs. */
  111. lm32fdpic_fixup32_section (info)
  112. = bfd_make_section_anyway_with_flags (dynobj,
  113. ".rofixup",
  114. (SEC_ALLOC
  115. | SEC_LOAD
  116. | SEC_HAS_CONTENTS
  117. | SEC_IN_MEMORY
  118. | SEC_LINKER_CREATED
  119. | SEC_READONLY));
  120. if (lm32fdpic_fixup32_section (info) == NULL
  121. || !bfd_set_section_alignment (lm32fdpic_fixup32_section (info), 2))
  122. return false;
  123. return true;
  124. }
  125. static reloc_howto_type lm32_elf_howto_table [] =
  126. {
  127. /* This reloc does nothing. */
  128. HOWTO (R_LM32_NONE, /* type */
  129. 0, /* rightshift */
  130. 3, /* size (0 = byte, 1 = short, 2 = long) */
  131. 0, /* bitsize */
  132. false, /* pc_relative */
  133. 0, /* bitpos */
  134. complain_overflow_dont, /* complain_on_overflow */
  135. bfd_elf_generic_reloc, /* special_function */
  136. "R_LM32_NONE", /* name */
  137. false, /* partial_inplace */
  138. 0, /* src_mask */
  139. 0, /* dst_mask */
  140. false), /* pcrel_offset */
  141. /* An 8 bit absolute relocation. */
  142. HOWTO (R_LM32_8, /* type */
  143. 0, /* rightshift */
  144. 0, /* size (0 = byte, 1 = short, 2 = long) */
  145. 8, /* bitsize */
  146. false, /* pc_relative */
  147. 0, /* bitpos */
  148. complain_overflow_bitfield,/* complain_on_overflow */
  149. bfd_elf_generic_reloc, /* special_function */
  150. "R_LM32_8", /* name */
  151. false, /* partial_inplace */
  152. 0, /* src_mask */
  153. 0xff, /* dst_mask */
  154. false), /* pcrel_offset */
  155. /* A 16 bit absolute relocation. */
  156. HOWTO (R_LM32_16, /* type */
  157. 0, /* rightshift */
  158. 1, /* size (0 = byte, 1 = short, 2 = long) */
  159. 16, /* bitsize */
  160. false, /* pc_relative */
  161. 0, /* bitpos */
  162. complain_overflow_bitfield,/* complain_on_overflow */
  163. bfd_elf_generic_reloc, /* special_function */
  164. "R_LM32_16", /* name */
  165. false, /* partial_inplace */
  166. 0, /* src_mask */
  167. 0xffff, /* dst_mask */
  168. false), /* pcrel_offset */
  169. /* A 32 bit absolute relocation. */
  170. HOWTO (R_LM32_32, /* type */
  171. 0, /* rightshift */
  172. 2, /* size (0 = byte, 1 = short, 2 = long) */
  173. 32, /* bitsize */
  174. false, /* pc_relative */
  175. 0, /* bitpos */
  176. complain_overflow_bitfield,/* complain_on_overflow */
  177. bfd_elf_generic_reloc, /* special_function */
  178. "R_LM32_32", /* name */
  179. false, /* partial_inplace */
  180. 0, /* src_mask */
  181. 0xffffffff, /* dst_mask */
  182. false), /* pcrel_offset */
  183. HOWTO (R_LM32_HI16, /* type */
  184. 16, /* rightshift */
  185. 2, /* size (0 = byte, 1 = short, 2 = long) */
  186. 16, /* bitsize */
  187. false, /* pc_relative */
  188. 0, /* bitpos */
  189. complain_overflow_bitfield,/* complain_on_overflow */
  190. bfd_elf_generic_reloc, /* special_function */
  191. "R_LM32_HI16", /* name */
  192. false, /* partial_inplace */
  193. 0, /* src_mask */
  194. 0xffff, /* dst_mask */
  195. false), /* pcrel_offset */
  196. HOWTO (R_LM32_LO16, /* type */
  197. 0, /* rightshift */
  198. 2, /* size (0 = byte, 1 = short, 2 = long) */
  199. 16, /* bitsize */
  200. false, /* pc_relative */
  201. 0, /* bitpos */
  202. complain_overflow_dont, /* complain_on_overflow */
  203. bfd_elf_generic_reloc, /* special_function */
  204. "R_LM32_LO16", /* name */
  205. false, /* partial_inplace */
  206. 0, /* src_mask */
  207. 0xffff, /* dst_mask */
  208. false), /* pcrel_offset */
  209. HOWTO (R_LM32_GPREL16, /* type */
  210. 0, /* rightshift */
  211. 2, /* size (0 = byte, 1 = short, 2 = long) */
  212. 16, /* bitsize */
  213. false, /* pc_relative */
  214. 0, /* bitpos */
  215. complain_overflow_dont, /* complain_on_overflow */
  216. lm32_elf_gprel_reloc, /* special_function */
  217. "R_LM32_GPREL16", /* name */
  218. false, /* partial_inplace */
  219. 0, /* src_mask */
  220. 0xffff, /* dst_mask */
  221. false), /* pcrel_offset */
  222. HOWTO (R_LM32_CALL, /* type */
  223. 2, /* rightshift */
  224. 2, /* size (0 = byte, 1 = short, 2 = long) */
  225. 26, /* bitsize */
  226. true, /* pc_relative */
  227. 0, /* bitpos */
  228. complain_overflow_signed, /* complain_on_overflow */
  229. bfd_elf_generic_reloc, /* special_function */
  230. "R_LM32_CALL", /* name */
  231. false, /* partial_inplace */
  232. 0, /* src_mask */
  233. 0x3ffffff, /* dst_mask */
  234. true), /* pcrel_offset */
  235. HOWTO (R_LM32_BRANCH, /* type */
  236. 2, /* rightshift */
  237. 2, /* size (0 = byte, 1 = short, 2 = long) */
  238. 16, /* bitsize */
  239. true, /* pc_relative */
  240. 0, /* bitpos */
  241. complain_overflow_signed, /* complain_on_overflow */
  242. bfd_elf_generic_reloc, /* special_function */
  243. "R_LM32_BRANCH", /* name */
  244. false, /* partial_inplace */
  245. 0, /* src_mask */
  246. 0xffff, /* dst_mask */
  247. true), /* pcrel_offset */
  248. /* GNU extension to record C++ vtable hierarchy. */
  249. HOWTO (R_LM32_GNU_VTINHERIT, /* type */
  250. 0, /* rightshift */
  251. 2, /* size (0 = byte, 1 = short, 2 = long) */
  252. 0, /* bitsize */
  253. false, /* pc_relative */
  254. 0, /* bitpos */
  255. complain_overflow_dont, /* complain_on_overflow */
  256. NULL, /* special_function */
  257. "R_LM32_GNU_VTINHERIT", /* name */
  258. false, /* partial_inplace */
  259. 0, /* src_mask */
  260. 0, /* dst_mask */
  261. false), /* pcrel_offset */
  262. /* GNU extension to record C++ vtable member usage. */
  263. HOWTO (R_LM32_GNU_VTENTRY, /* type */
  264. 0, /* rightshift */
  265. 2, /* size (0 = byte, 1 = short, 2 = long) */
  266. 0, /* bitsize */
  267. false, /* pc_relative */
  268. 0, /* bitpos */
  269. complain_overflow_dont, /* complain_on_overflow */
  270. _bfd_elf_rel_vtable_reloc_fn,/* special_function */
  271. "R_LM32_GNU_VTENTRY", /* name */
  272. false, /* partial_inplace */
  273. 0, /* src_mask */
  274. 0, /* dst_mask */
  275. false), /* pcrel_offset */
  276. HOWTO (R_LM32_16_GOT, /* type */
  277. 0, /* rightshift */
  278. 2, /* size (0 = byte, 1 = short, 2 = long) */
  279. 16, /* bitsize */
  280. false, /* pc_relative */
  281. 0, /* bitpos */
  282. complain_overflow_signed, /* complain_on_overflow */
  283. bfd_elf_generic_reloc, /* special_function */
  284. "R_LM32_16_GOT", /* name */
  285. false, /* partial_inplace */
  286. 0, /* src_mask */
  287. 0xffff, /* dst_mask */
  288. false), /* pcrel_offset */
  289. HOWTO (R_LM32_GOTOFF_HI16, /* type */
  290. 16, /* rightshift */
  291. 2, /* size (0 = byte, 1 = short, 2 = long) */
  292. 16, /* bitsize */
  293. false, /* pc_relative */
  294. 0, /* bitpos */
  295. complain_overflow_dont, /* complain_on_overflow */
  296. bfd_elf_generic_reloc, /* special_function */
  297. "R_LM32_GOTOFF_HI16", /* name */
  298. false, /* partial_inplace */
  299. 0xffff, /* src_mask */
  300. 0xffff, /* dst_mask */
  301. false), /* pcrel_offset */
  302. HOWTO (R_LM32_GOTOFF_LO16, /* type */
  303. 0, /* rightshift */
  304. 2, /* size (0 = byte, 1 = short, 2 = long) */
  305. 16, /* bitsize */
  306. false, /* pc_relative */
  307. 0, /* bitpos */
  308. complain_overflow_dont, /* complain_on_overflow */
  309. bfd_elf_generic_reloc, /* special_function */
  310. "R_LM32_GOTOFF_LO16", /* name */
  311. false, /* partial_inplace */
  312. 0xffff, /* src_mask */
  313. 0xffff, /* dst_mask */
  314. false), /* pcrel_offset */
  315. HOWTO (R_LM32_COPY, /* type */
  316. 0, /* rightshift */
  317. 2, /* size (0 = byte, 1 = short, 2 = long) */
  318. 32, /* bitsize */
  319. false, /* pc_relative */
  320. 0, /* bitpos */
  321. complain_overflow_bitfield, /* complain_on_overflow */
  322. bfd_elf_generic_reloc, /* special_function */
  323. "R_LM32_COPY", /* name */
  324. false, /* partial_inplace */
  325. 0xffffffff, /* src_mask */
  326. 0xffffffff, /* dst_mask */
  327. false), /* pcrel_offset */
  328. HOWTO (R_LM32_GLOB_DAT, /* type */
  329. 0, /* rightshift */
  330. 2, /* size (0 = byte, 1 = short, 2 = long) */
  331. 32, /* bitsize */
  332. false, /* pc_relative */
  333. 0, /* bitpos */
  334. complain_overflow_bitfield, /* complain_on_overflow */
  335. bfd_elf_generic_reloc, /* special_function */
  336. "R_LM32_GLOB_DAT", /* name */
  337. false, /* partial_inplace */
  338. 0xffffffff, /* src_mask */
  339. 0xffffffff, /* dst_mask */
  340. false), /* pcrel_offset */
  341. HOWTO (R_LM32_JMP_SLOT, /* type */
  342. 0, /* rightshift */
  343. 2, /* size (0 = byte, 1 = short, 2 = long) */
  344. 32, /* bitsize */
  345. false, /* pc_relative */
  346. 0, /* bitpos */
  347. complain_overflow_bitfield, /* complain_on_overflow */
  348. bfd_elf_generic_reloc, /* special_function */
  349. "R_LM32_JMP_SLOT", /* name */
  350. false, /* partial_inplace */
  351. 0xffffffff, /* src_mask */
  352. 0xffffffff, /* dst_mask */
  353. false), /* pcrel_offset */
  354. HOWTO (R_LM32_RELATIVE, /* type */
  355. 0, /* rightshift */
  356. 2, /* size (0 = byte, 1 = short, 2 = long) */
  357. 32, /* bitsize */
  358. false, /* pc_relative */
  359. 0, /* bitpos */
  360. complain_overflow_bitfield, /* complain_on_overflow */
  361. bfd_elf_generic_reloc, /* special_function */
  362. "R_LM32_RELATIVE", /* name */
  363. false, /* partial_inplace */
  364. 0xffffffff, /* src_mask */
  365. 0xffffffff, /* dst_mask */
  366. false), /* pcrel_offset */
  367. };
  368. /* Map BFD reloc types to lm32 ELF reloc types. */
  369. struct lm32_reloc_map
  370. {
  371. bfd_reloc_code_real_type bfd_reloc_val;
  372. unsigned char elf_reloc_val;
  373. };
  374. static const struct lm32_reloc_map lm32_reloc_map[] =
  375. {
  376. { BFD_RELOC_NONE, R_LM32_NONE },
  377. { BFD_RELOC_8, R_LM32_8 },
  378. { BFD_RELOC_16, R_LM32_16 },
  379. { BFD_RELOC_32, R_LM32_32 },
  380. { BFD_RELOC_HI16, R_LM32_HI16 },
  381. { BFD_RELOC_LO16, R_LM32_LO16 },
  382. { BFD_RELOC_GPREL16, R_LM32_GPREL16 },
  383. { BFD_RELOC_LM32_CALL, R_LM32_CALL },
  384. { BFD_RELOC_LM32_BRANCH, R_LM32_BRANCH },
  385. { BFD_RELOC_VTABLE_INHERIT, R_LM32_GNU_VTINHERIT },
  386. { BFD_RELOC_VTABLE_ENTRY, R_LM32_GNU_VTENTRY },
  387. { BFD_RELOC_LM32_16_GOT, R_LM32_16_GOT },
  388. { BFD_RELOC_LM32_GOTOFF_HI16, R_LM32_GOTOFF_HI16 },
  389. { BFD_RELOC_LM32_GOTOFF_LO16, R_LM32_GOTOFF_LO16 },
  390. { BFD_RELOC_LM32_COPY, R_LM32_COPY },
  391. { BFD_RELOC_LM32_GLOB_DAT, R_LM32_GLOB_DAT },
  392. { BFD_RELOC_LM32_JMP_SLOT, R_LM32_JMP_SLOT },
  393. { BFD_RELOC_LM32_RELATIVE, R_LM32_RELATIVE },
  394. };
  395. static reloc_howto_type *
  396. lm32_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  397. bfd_reloc_code_real_type code)
  398. {
  399. unsigned int i;
  400. for (i = 0; i < sizeof (lm32_reloc_map) / sizeof (lm32_reloc_map[0]); i++)
  401. if (lm32_reloc_map[i].bfd_reloc_val == code)
  402. return &lm32_elf_howto_table[lm32_reloc_map[i].elf_reloc_val];
  403. return NULL;
  404. }
  405. static reloc_howto_type *
  406. lm32_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  407. const char *r_name)
  408. {
  409. unsigned int i;
  410. for (i = 0;
  411. i < sizeof (lm32_elf_howto_table) / sizeof (lm32_elf_howto_table[0]);
  412. i++)
  413. if (lm32_elf_howto_table[i].name != NULL
  414. && strcasecmp (lm32_elf_howto_table[i].name, r_name) == 0)
  415. return &lm32_elf_howto_table[i];
  416. return NULL;
  417. }
  418. /* Set the howto pointer for an Lattice Mico32 ELF reloc. */
  419. static bool
  420. lm32_info_to_howto_rela (bfd *abfd,
  421. arelent *cache_ptr,
  422. Elf_Internal_Rela *dst)
  423. {
  424. unsigned int r_type;
  425. r_type = ELF32_R_TYPE (dst->r_info);
  426. if (r_type >= (unsigned int) R_LM32_max)
  427. {
  428. /* xgettext:c-format */
  429. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  430. abfd, r_type);
  431. bfd_set_error (bfd_error_bad_value);
  432. return false;
  433. }
  434. cache_ptr->howto = &lm32_elf_howto_table[r_type];
  435. return true;
  436. }
  437. /* Set the right machine number for an Lattice Mico32 ELF file. */
  438. static bool
  439. lm32_elf_object_p (bfd *abfd)
  440. {
  441. return bfd_default_set_arch_mach (abfd, bfd_arch_lm32, bfd_mach_lm32);
  442. }
  443. /* Set machine type flags just before file is written out. */
  444. static bool
  445. lm32_elf_final_write_processing (bfd *abfd)
  446. {
  447. elf_elfheader (abfd)->e_machine = EM_LATTICEMICO32;
  448. elf_elfheader (abfd)->e_flags &=~ EF_LM32_MACH;
  449. switch (bfd_get_mach (abfd))
  450. {
  451. case bfd_mach_lm32:
  452. elf_elfheader (abfd)->e_flags |= E_LM32_MACH;
  453. break;
  454. default:
  455. abort ();
  456. }
  457. return _bfd_elf_final_write_processing (abfd);
  458. }
  459. /* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
  460. dangerous relocation. */
  461. static bool
  462. lm32_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
  463. {
  464. unsigned int count;
  465. asymbol **sym;
  466. unsigned int i;
  467. /* If we've already figured out what GP will be, just return it. */
  468. *pgp = _bfd_get_gp_value (output_bfd);
  469. if (*pgp)
  470. return true;
  471. count = bfd_get_symcount (output_bfd);
  472. sym = bfd_get_outsymbols (output_bfd);
  473. /* The linker script will have created a symbol named `_gp' with the
  474. appropriate value. */
  475. if (sym == NULL)
  476. i = count;
  477. else
  478. {
  479. for (i = 0; i < count; i++, sym++)
  480. {
  481. const char *name;
  482. name = bfd_asymbol_name (*sym);
  483. if (*name == '_' && strcmp (name, "_gp") == 0)
  484. {
  485. *pgp = bfd_asymbol_value (*sym);
  486. _bfd_set_gp_value (output_bfd, *pgp);
  487. break;
  488. }
  489. }
  490. }
  491. if (i >= count)
  492. {
  493. /* Only get the error once. */
  494. *pgp = 4;
  495. _bfd_set_gp_value (output_bfd, *pgp);
  496. return false;
  497. }
  498. return true;
  499. }
  500. /* We have to figure out the gp value, so that we can adjust the
  501. symbol value correctly. We look up the symbol _gp in the output
  502. BFD. If we can't find it, we're stuck. We cache it in the ELF
  503. target data. We don't need to adjust the symbol value for an
  504. external symbol if we are producing relocatable output. */
  505. static bfd_reloc_status_type
  506. lm32_elf_final_gp (bfd *output_bfd, asymbol *symbol, bool relocatable,
  507. char **error_message, bfd_vma *pgp)
  508. {
  509. if (bfd_is_und_section (symbol->section) && !relocatable)
  510. {
  511. *pgp = 0;
  512. return bfd_reloc_undefined;
  513. }
  514. *pgp = _bfd_get_gp_value (output_bfd);
  515. if (*pgp == 0 && (!relocatable || (symbol->flags & BSF_SECTION_SYM) != 0))
  516. {
  517. if (relocatable)
  518. {
  519. /* Make up a value. */
  520. *pgp = symbol->section->output_section->vma + 0x4000;
  521. _bfd_set_gp_value (output_bfd, *pgp);
  522. }
  523. else if (!lm32_elf_assign_gp (output_bfd, pgp))
  524. {
  525. *error_message =
  526. (char *)
  527. _("global pointer relative relocation when _gp not defined");
  528. return bfd_reloc_dangerous;
  529. }
  530. }
  531. return bfd_reloc_ok;
  532. }
  533. static bfd_reloc_status_type
  534. lm32_elf_do_gprel_relocate (bfd *abfd,
  535. reloc_howto_type *howto,
  536. asection *input_section ATTRIBUTE_UNUSED,
  537. bfd_byte *data,
  538. bfd_vma offset,
  539. bfd_vma symbol_value,
  540. bfd_vma addend)
  541. {
  542. return _bfd_final_link_relocate (howto, abfd, input_section,
  543. data, offset, symbol_value, addend);
  544. }
  545. static bfd_reloc_status_type
  546. lm32_elf_gprel_reloc (bfd *abfd,
  547. arelent *reloc_entry,
  548. asymbol *symbol,
  549. void *data,
  550. asection *input_section,
  551. bfd *output_bfd,
  552. char **msg)
  553. {
  554. bfd_vma relocation;
  555. bfd_vma gp;
  556. bfd_reloc_status_type r;
  557. if (output_bfd != (bfd *) NULL
  558. && (symbol->flags & BSF_SECTION_SYM) == 0
  559. && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
  560. {
  561. reloc_entry->address += input_section->output_offset;
  562. return bfd_reloc_ok;
  563. }
  564. if (output_bfd != NULL)
  565. return bfd_reloc_ok;
  566. relocation = symbol->value
  567. + symbol->section->output_section->vma + symbol->section->output_offset;
  568. if ((r =
  569. lm32_elf_final_gp (abfd, symbol, false, msg, &gp)) == bfd_reloc_ok)
  570. {
  571. relocation = relocation + reloc_entry->addend - gp;
  572. reloc_entry->addend = 0;
  573. if ((signed) relocation < -32768 || (signed) relocation > 32767)
  574. {
  575. *msg = _("global pointer relative address out of range");
  576. r = bfd_reloc_outofrange;
  577. }
  578. else
  579. {
  580. r = lm32_elf_do_gprel_relocate (abfd, reloc_entry->howto,
  581. input_section,
  582. data, reloc_entry->address,
  583. relocation, reloc_entry->addend);
  584. }
  585. }
  586. return r;
  587. }
  588. /* Find the segment number in which OSEC, and output section, is
  589. located. */
  590. static unsigned
  591. _lm32fdpic_osec_to_segment (bfd *output_bfd, asection *osec)
  592. {
  593. struct elf_segment_map *m;
  594. Elf_Internal_Phdr *p;
  595. /* Find the segment that contains the output_section. */
  596. for (m = elf_seg_map (output_bfd), p = elf_tdata (output_bfd)->phdr;
  597. m != NULL;
  598. m = m->next, p++)
  599. {
  600. int i;
  601. for (i = m->count - 1; i >= 0; i--)
  602. if (m->sections[i] == osec)
  603. break;
  604. if (i >= 0)
  605. break;
  606. }
  607. return p - elf_tdata (output_bfd)->phdr;
  608. }
  609. /* Determine if an output section is read-only. */
  610. inline static bool
  611. _lm32fdpic_osec_readonly_p (bfd *output_bfd, asection *osec)
  612. {
  613. unsigned seg = _lm32fdpic_osec_to_segment (output_bfd, osec);
  614. return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
  615. }
  616. /* Relocate a section */
  617. static int
  618. lm32_elf_relocate_section (bfd *output_bfd,
  619. struct bfd_link_info *info,
  620. bfd *input_bfd,
  621. asection *input_section,
  622. bfd_byte *contents,
  623. Elf_Internal_Rela *relocs,
  624. Elf_Internal_Sym *local_syms,
  625. asection **local_sections)
  626. {
  627. Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  628. struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
  629. Elf_Internal_Rela *rel, *relend;
  630. struct elf_lm32_link_hash_table *htab = lm32_elf_hash_table (info);
  631. bfd_vma *local_got_offsets;
  632. asection *sgot;
  633. if (htab == NULL)
  634. return false;
  635. local_got_offsets = elf_local_got_offsets (input_bfd);
  636. sgot = htab->root.sgot;
  637. symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  638. sym_hashes = elf_sym_hashes (input_bfd);
  639. rel = relocs;
  640. relend = relocs + input_section->reloc_count;
  641. for (; rel < relend; rel++)
  642. {
  643. reloc_howto_type *howto;
  644. unsigned int r_type;
  645. unsigned long r_symndx;
  646. Elf_Internal_Sym *sym;
  647. asection *sec;
  648. struct elf_link_hash_entry *h;
  649. bfd_vma relocation;
  650. bfd_vma gp;
  651. bfd_reloc_status_type r;
  652. const char *name = NULL;
  653. r_symndx = ELF32_R_SYM (rel->r_info);
  654. r_type = ELF32_R_TYPE (rel->r_info);
  655. if (r_type == R_LM32_GNU_VTENTRY
  656. || r_type == R_LM32_GNU_VTINHERIT )
  657. continue;
  658. h = NULL;
  659. sym = NULL;
  660. sec = NULL;
  661. howto = lm32_elf_howto_table + r_type;
  662. if (r_symndx < symtab_hdr->sh_info)
  663. {
  664. /* It's a local symbol. */
  665. sym = local_syms + r_symndx;
  666. sec = local_sections[r_symndx];
  667. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  668. name = bfd_elf_string_from_elf_section
  669. (input_bfd, symtab_hdr->sh_link, sym->st_name);
  670. name = name == NULL ? bfd_section_name (sec) : name;
  671. }
  672. else
  673. {
  674. /* It's a global symbol. */
  675. bool unresolved_reloc;
  676. bool warned, ignored;
  677. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  678. r_symndx, symtab_hdr, sym_hashes,
  679. h, sec, relocation,
  680. unresolved_reloc, warned, ignored);
  681. name = h->root.root.string;
  682. }
  683. if (sec != NULL && discarded_section (sec))
  684. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  685. rel, 1, relend, howto, 0, contents);
  686. if (bfd_link_relocatable (info))
  687. {
  688. /* This is a relocatable link. We don't have to change
  689. anything, unless the reloc is against a section symbol,
  690. in which case we have to adjust according to where the
  691. section symbol winds up in the output section. */
  692. if (sym == NULL || ELF_ST_TYPE (sym->st_info) != STT_SECTION)
  693. continue;
  694. /* If partial_inplace, we need to store any additional addend
  695. back in the section. */
  696. if (! howto->partial_inplace)
  697. continue;
  698. /* Shouldn't reach here. */
  699. abort ();
  700. r = bfd_reloc_ok;
  701. }
  702. else
  703. {
  704. switch (howto->type)
  705. {
  706. case R_LM32_GPREL16:
  707. if (!lm32_elf_assign_gp (output_bfd, &gp))
  708. r = bfd_reloc_dangerous;
  709. else
  710. {
  711. relocation = relocation + rel->r_addend - gp;
  712. rel->r_addend = 0;
  713. if ((signed)relocation < -32768 || (signed)relocation > 32767)
  714. r = bfd_reloc_outofrange;
  715. else
  716. {
  717. r = _bfd_final_link_relocate (howto, input_bfd,
  718. input_section, contents,
  719. rel->r_offset, relocation,
  720. rel->r_addend);
  721. }
  722. }
  723. break;
  724. case R_LM32_16_GOT:
  725. /* Relocation is to the entry for this symbol in the global
  726. offset table. */
  727. BFD_ASSERT (sgot != NULL);
  728. if (h != NULL)
  729. {
  730. bool dyn;
  731. bfd_vma off;
  732. off = h->got.offset;
  733. BFD_ASSERT (off != (bfd_vma) -1);
  734. dyn = htab->root.dynamic_sections_created;
  735. if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
  736. bfd_link_pic (info),
  737. h)
  738. || (bfd_link_pic (info)
  739. && (info->symbolic
  740. || h->dynindx == -1
  741. || h->forced_local)
  742. && h->def_regular))
  743. {
  744. /* This is actually a static link, or it is a
  745. -Bsymbolic link and the symbol is defined
  746. locally, or the symbol was forced to be local
  747. because of a version file. We must initialize
  748. this entry in the global offset table. Since the
  749. offset must always be a multiple of 4, we use the
  750. least significant bit to record whether we have
  751. initialized it already.
  752. When doing a dynamic link, we create a .rela.got
  753. relocation entry to initialize the value. This
  754. is done in the finish_dynamic_symbol routine. */
  755. if ((off & 1) != 0)
  756. off &= ~1;
  757. else
  758. {
  759. /* Write entry in GOT */
  760. bfd_put_32 (output_bfd, relocation,
  761. sgot->contents + off);
  762. /* Create entry in .rofixup pointing to GOT entry. */
  763. if (IS_FDPIC (output_bfd) && h->root.type != bfd_link_hash_undefweak)
  764. {
  765. _lm32fdpic_add_rofixup (output_bfd,
  766. lm32fdpic_fixup32_section
  767. (info),
  768. sgot->output_section->vma
  769. + sgot->output_offset
  770. + off);
  771. }
  772. /* Mark GOT entry as having been written. */
  773. h->got.offset |= 1;
  774. }
  775. }
  776. relocation = sgot->output_offset + off;
  777. }
  778. else
  779. {
  780. bfd_vma off;
  781. bfd_byte *loc;
  782. BFD_ASSERT (local_got_offsets != NULL
  783. && local_got_offsets[r_symndx] != (bfd_vma) -1);
  784. /* Get offset into GOT table. */
  785. off = local_got_offsets[r_symndx];
  786. /* The offset must always be a multiple of 4. We use
  787. the least significant bit to record whether we have
  788. already processed this entry. */
  789. if ((off & 1) != 0)
  790. off &= ~1;
  791. else
  792. {
  793. /* Write entry in GOT. */
  794. bfd_put_32 (output_bfd, relocation, sgot->contents + off);
  795. /* Create entry in .rofixup pointing to GOT entry. */
  796. if (IS_FDPIC (output_bfd))
  797. {
  798. _lm32fdpic_add_rofixup (output_bfd,
  799. lm32fdpic_fixup32_section
  800. (info),
  801. sgot->output_section->vma
  802. + sgot->output_offset
  803. + off);
  804. }
  805. if (bfd_link_pic (info))
  806. {
  807. asection *srelgot;
  808. Elf_Internal_Rela outrel;
  809. /* We need to generate a R_LM32_RELATIVE reloc
  810. for the dynamic linker. */
  811. srelgot = htab->root.srelgot;
  812. BFD_ASSERT (srelgot != NULL);
  813. outrel.r_offset = (sgot->output_section->vma
  814. + sgot->output_offset
  815. + off);
  816. outrel.r_info = ELF32_R_INFO (0, R_LM32_RELATIVE);
  817. outrel.r_addend = relocation;
  818. loc = srelgot->contents;
  819. loc += srelgot->reloc_count * sizeof (Elf32_External_Rela);
  820. bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
  821. ++srelgot->reloc_count;
  822. }
  823. local_got_offsets[r_symndx] |= 1;
  824. }
  825. relocation = sgot->output_offset + off;
  826. }
  827. /* Addend should be zero. */
  828. if (rel->r_addend != 0)
  829. _bfd_error_handler
  830. (_("internal error: addend should be zero for %s"),
  831. "R_LM32_16_GOT");
  832. r = _bfd_final_link_relocate (howto,
  833. input_bfd,
  834. input_section,
  835. contents,
  836. rel->r_offset,
  837. relocation,
  838. rel->r_addend);
  839. break;
  840. case R_LM32_GOTOFF_LO16:
  841. case R_LM32_GOTOFF_HI16:
  842. /* Relocation is offset from GOT. */
  843. BFD_ASSERT (sgot != NULL);
  844. relocation -= sgot->output_section->vma;
  845. /* Account for sign-extension. */
  846. if ((r_type == R_LM32_GOTOFF_HI16)
  847. && ((relocation + rel->r_addend) & 0x8000))
  848. rel->r_addend += 0x10000;
  849. r = _bfd_final_link_relocate (howto,
  850. input_bfd,
  851. input_section,
  852. contents,
  853. rel->r_offset,
  854. relocation,
  855. rel->r_addend);
  856. break;
  857. case R_LM32_32:
  858. if (IS_FDPIC (output_bfd))
  859. {
  860. if ((!h) || (h && h->root.type != bfd_link_hash_undefweak))
  861. {
  862. /* Only create .rofixup entries for relocs in loadable sections. */
  863. if ((bfd_section_flags (input_section->output_section)
  864. & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
  865. {
  866. /* Check address to be modified is writable. */
  867. if (_lm32fdpic_osec_readonly_p (output_bfd,
  868. input_section
  869. ->output_section))
  870. {
  871. info->callbacks->warning
  872. (info,
  873. _("cannot emit dynamic relocations in read-only section"),
  874. name, input_bfd, input_section, rel->r_offset);
  875. return false;
  876. }
  877. /* Create entry in .rofixup section. */
  878. _lm32fdpic_add_rofixup (output_bfd,
  879. lm32fdpic_fixup32_section (info),
  880. input_section->output_section->vma
  881. + input_section->output_offset
  882. + rel->r_offset);
  883. }
  884. }
  885. }
  886. /* Fall through. */
  887. default:
  888. r = _bfd_final_link_relocate (howto,
  889. input_bfd,
  890. input_section,
  891. contents,
  892. rel->r_offset,
  893. relocation,
  894. rel->r_addend);
  895. break;
  896. }
  897. }
  898. if (r != bfd_reloc_ok)
  899. {
  900. const char *msg = NULL;
  901. arelent bfd_reloc;
  902. if (! lm32_info_to_howto_rela (input_bfd, &bfd_reloc, rel))
  903. continue;
  904. howto = bfd_reloc.howto;
  905. if (h != NULL)
  906. name = h->root.root.string;
  907. else
  908. {
  909. name = (bfd_elf_string_from_elf_section
  910. (input_bfd, symtab_hdr->sh_link, sym->st_name));
  911. if (name == NULL || *name == '\0')
  912. name = bfd_section_name (sec);
  913. }
  914. switch (r)
  915. {
  916. case bfd_reloc_overflow:
  917. if ((h != NULL)
  918. && (h->root.type == bfd_link_hash_undefweak))
  919. break;
  920. (*info->callbacks->reloc_overflow)
  921. (info, (h ? &h->root : NULL), name, howto->name,
  922. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  923. break;
  924. case bfd_reloc_undefined:
  925. (*info->callbacks->undefined_symbol)
  926. (info, name, input_bfd, input_section, rel->r_offset, true);
  927. break;
  928. case bfd_reloc_outofrange:
  929. msg = _("internal error: out of range error");
  930. goto common_error;
  931. case bfd_reloc_notsupported:
  932. msg = _("internal error: unsupported relocation error");
  933. goto common_error;
  934. case bfd_reloc_dangerous:
  935. msg = _("internal error: dangerous error");
  936. goto common_error;
  937. default:
  938. msg = _("internal error: unknown error");
  939. /* fall through */
  940. common_error:
  941. (*info->callbacks->warning) (info, msg, name, input_bfd,
  942. input_section, rel->r_offset);
  943. break;
  944. }
  945. }
  946. }
  947. return true;
  948. }
  949. static asection *
  950. lm32_elf_gc_mark_hook (asection *sec,
  951. struct bfd_link_info *info,
  952. Elf_Internal_Rela *rel,
  953. struct elf_link_hash_entry *h,
  954. Elf_Internal_Sym *sym)
  955. {
  956. if (h != NULL)
  957. switch (ELF32_R_TYPE (rel->r_info))
  958. {
  959. case R_LM32_GNU_VTINHERIT:
  960. case R_LM32_GNU_VTENTRY:
  961. return NULL;
  962. }
  963. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  964. }
  965. /* Look through the relocs for a section during the first phase. */
  966. static bool
  967. lm32_elf_check_relocs (bfd *abfd,
  968. struct bfd_link_info *info,
  969. asection *sec,
  970. const Elf_Internal_Rela *relocs)
  971. {
  972. Elf_Internal_Shdr *symtab_hdr;
  973. struct elf_link_hash_entry **sym_hashes;
  974. const Elf_Internal_Rela *rel;
  975. const Elf_Internal_Rela *rel_end;
  976. struct elf_lm32_link_hash_table *htab;
  977. bfd *dynobj;
  978. if (bfd_link_relocatable (info))
  979. return true;
  980. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  981. sym_hashes = elf_sym_hashes (abfd);
  982. htab = lm32_elf_hash_table (info);
  983. if (htab == NULL)
  984. return false;
  985. dynobj = htab->root.dynobj;
  986. rel_end = relocs + sec->reloc_count;
  987. for (rel = relocs; rel < rel_end; rel++)
  988. {
  989. int r_type;
  990. struct elf_link_hash_entry *h;
  991. unsigned long r_symndx;
  992. r_symndx = ELF32_R_SYM (rel->r_info);
  993. r_type = ELF32_R_TYPE (rel->r_info);
  994. if (r_symndx < symtab_hdr->sh_info)
  995. h = NULL;
  996. else
  997. {
  998. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  999. while (h->root.type == bfd_link_hash_indirect
  1000. || h->root.type == bfd_link_hash_warning)
  1001. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1002. }
  1003. /* Some relocs require a global offset table. */
  1004. if (htab->root.sgot == NULL)
  1005. {
  1006. switch (r_type)
  1007. {
  1008. case R_LM32_16_GOT:
  1009. case R_LM32_GOTOFF_HI16:
  1010. case R_LM32_GOTOFF_LO16:
  1011. if (dynobj == NULL)
  1012. htab->root.dynobj = dynobj = abfd;
  1013. if (!_bfd_elf_create_got_section (dynobj, info))
  1014. return false;
  1015. break;
  1016. }
  1017. }
  1018. /* Some relocs require a rofixup table. */
  1019. if (IS_FDPIC (abfd))
  1020. {
  1021. switch (r_type)
  1022. {
  1023. case R_LM32_32:
  1024. /* FDPIC requires a GOT if there is a .rofixup section
  1025. (Normal ELF doesn't). */
  1026. if (dynobj == NULL)
  1027. htab->root.dynobj = dynobj = abfd;
  1028. if (!_bfd_elf_create_got_section (dynobj, info))
  1029. return false;
  1030. /* Create .rofixup section */
  1031. if (htab->sfixup32 == NULL)
  1032. {
  1033. if (! create_rofixup_section (dynobj, info))
  1034. return false;
  1035. }
  1036. break;
  1037. case R_LM32_16_GOT:
  1038. case R_LM32_GOTOFF_HI16:
  1039. case R_LM32_GOTOFF_LO16:
  1040. /* Create .rofixup section. */
  1041. if (htab->sfixup32 == NULL)
  1042. {
  1043. if (dynobj == NULL)
  1044. htab->root.dynobj = dynobj = abfd;
  1045. if (! create_rofixup_section (dynobj, info))
  1046. return false;
  1047. }
  1048. break;
  1049. }
  1050. }
  1051. switch (r_type)
  1052. {
  1053. case R_LM32_16_GOT:
  1054. if (h != NULL)
  1055. h->got.refcount += 1;
  1056. else
  1057. {
  1058. bfd_signed_vma *local_got_refcounts;
  1059. /* This is a global offset table entry for a local symbol. */
  1060. local_got_refcounts = elf_local_got_refcounts (abfd);
  1061. if (local_got_refcounts == NULL)
  1062. {
  1063. bfd_size_type size;
  1064. size = symtab_hdr->sh_info;
  1065. size *= sizeof (bfd_signed_vma);
  1066. local_got_refcounts = bfd_zalloc (abfd, size);
  1067. if (local_got_refcounts == NULL)
  1068. return false;
  1069. elf_local_got_refcounts (abfd) = local_got_refcounts;
  1070. }
  1071. local_got_refcounts[r_symndx] += 1;
  1072. }
  1073. break;
  1074. /* This relocation describes the C++ object vtable hierarchy.
  1075. Reconstruct it for later use during GC. */
  1076. case R_LM32_GNU_VTINHERIT:
  1077. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  1078. return false;
  1079. break;
  1080. /* This relocation describes which C++ vtable entries are actually
  1081. used. Record for later use during GC. */
  1082. case R_LM32_GNU_VTENTRY:
  1083. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  1084. return false;
  1085. break;
  1086. }
  1087. }
  1088. return true;
  1089. }
  1090. /* Finish up the dynamic sections. */
  1091. static bool
  1092. lm32_elf_finish_dynamic_sections (bfd *output_bfd,
  1093. struct bfd_link_info *info)
  1094. {
  1095. struct elf_lm32_link_hash_table *htab;
  1096. bfd *dynobj;
  1097. asection *sdyn;
  1098. asection *sgot;
  1099. htab = lm32_elf_hash_table (info);
  1100. if (htab == NULL)
  1101. return false;
  1102. dynobj = htab->root.dynobj;
  1103. sgot = htab->root.sgotplt;
  1104. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  1105. if (htab->root.dynamic_sections_created)
  1106. {
  1107. asection *splt;
  1108. Elf32_External_Dyn *dyncon, *dynconend;
  1109. BFD_ASSERT (sgot != NULL && sdyn != NULL);
  1110. dyncon = (Elf32_External_Dyn *) sdyn->contents;
  1111. dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
  1112. for (; dyncon < dynconend; dyncon++)
  1113. {
  1114. Elf_Internal_Dyn dyn;
  1115. asection *s;
  1116. bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
  1117. switch (dyn.d_tag)
  1118. {
  1119. default:
  1120. break;
  1121. case DT_PLTGOT:
  1122. s = htab->root.sgotplt;
  1123. goto get_vma;
  1124. case DT_JMPREL:
  1125. s = htab->root.srelplt;
  1126. get_vma:
  1127. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  1128. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  1129. break;
  1130. case DT_PLTRELSZ:
  1131. s = htab->root.srelplt;
  1132. dyn.d_un.d_val = s->size;
  1133. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  1134. break;
  1135. }
  1136. }
  1137. /* Fill in the first entry in the procedure linkage table. */
  1138. splt = htab->root.splt;
  1139. if (splt && splt->size > 0)
  1140. {
  1141. if (bfd_link_pic (info))
  1142. {
  1143. bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD0, splt->contents);
  1144. bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD1, splt->contents + 4);
  1145. bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD2, splt->contents + 8);
  1146. bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD3, splt->contents + 12);
  1147. bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD4, splt->contents + 16);
  1148. }
  1149. else
  1150. {
  1151. unsigned long addr;
  1152. /* addr = .got + 4 */
  1153. addr = sgot->output_section->vma + sgot->output_offset + 4;
  1154. bfd_put_32 (output_bfd,
  1155. PLT0_ENTRY_WORD0 | ((addr >> 16) & 0xffff),
  1156. splt->contents);
  1157. bfd_put_32 (output_bfd,
  1158. PLT0_ENTRY_WORD1 | (addr & 0xffff),
  1159. splt->contents + 4);
  1160. bfd_put_32 (output_bfd, PLT0_ENTRY_WORD2, splt->contents + 8);
  1161. bfd_put_32 (output_bfd, PLT0_ENTRY_WORD3, splt->contents + 12);
  1162. bfd_put_32 (output_bfd, PLT0_ENTRY_WORD4, splt->contents + 16);
  1163. }
  1164. elf_section_data (splt->output_section)->this_hdr.sh_entsize =
  1165. PLT_ENTRY_SIZE;
  1166. }
  1167. }
  1168. /* Fill in the first three entries in the global offset table. */
  1169. if (sgot && sgot->size > 0)
  1170. {
  1171. if (sdyn == NULL)
  1172. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
  1173. else
  1174. bfd_put_32 (output_bfd,
  1175. sdyn->output_section->vma + sdyn->output_offset,
  1176. sgot->contents);
  1177. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
  1178. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
  1179. /* FIXME: This can be null if create_dynamic_sections wasn't called. */
  1180. if (elf_section_data (sgot->output_section) != NULL)
  1181. elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
  1182. }
  1183. if (lm32fdpic_fixup32_section (info))
  1184. {
  1185. struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot;
  1186. bfd_vma got_value = hgot->root.u.def.value
  1187. + hgot->root.u.def.section->output_section->vma
  1188. + hgot->root.u.def.section->output_offset;
  1189. struct bfd_link_hash_entry *hend;
  1190. /* Last entry is pointer to GOT. */
  1191. _lm32fdpic_add_rofixup (output_bfd, lm32fdpic_fixup32_section (info), got_value);
  1192. /* Check we wrote enough entries. */
  1193. if (lm32fdpic_fixup32_section (info)->size
  1194. != (lm32fdpic_fixup32_section (info)->reloc_count * 4))
  1195. {
  1196. _bfd_error_handler
  1197. ("LINKER BUG: .rofixup section size mismatch: size/4 %" PRId64
  1198. " != relocs %d",
  1199. (int64_t) (lm32fdpic_fixup32_section (info)->size / 4),
  1200. lm32fdpic_fixup32_section (info)->reloc_count);
  1201. return false;
  1202. }
  1203. hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__",
  1204. false, false, true);
  1205. if (hend
  1206. && (hend->type == bfd_link_hash_defined
  1207. || hend->type == bfd_link_hash_defweak)
  1208. && hend->u.def.section->output_section != NULL)
  1209. {
  1210. bfd_vma value =
  1211. lm32fdpic_fixup32_section (info)->output_section->vma
  1212. + lm32fdpic_fixup32_section (info)->output_offset
  1213. + lm32fdpic_fixup32_section (info)->size
  1214. - hend->u.def.section->output_section->vma
  1215. - hend->u.def.section->output_offset;
  1216. BFD_ASSERT (hend->u.def.value == value);
  1217. if (hend->u.def.value != value)
  1218. {
  1219. _bfd_error_handler
  1220. ("LINKER BUG: .rofixup section hend->u.def.value != value: %"
  1221. PRId64 " != %" PRId64,
  1222. (int64_t) hend->u.def.value, (int64_t) value);
  1223. return false;
  1224. }
  1225. }
  1226. }
  1227. return true;
  1228. }
  1229. /* Finish up dynamic symbol handling. We set the contents of various
  1230. dynamic sections here. */
  1231. static bool
  1232. lm32_elf_finish_dynamic_symbol (bfd *output_bfd,
  1233. struct bfd_link_info *info,
  1234. struct elf_link_hash_entry *h,
  1235. Elf_Internal_Sym *sym)
  1236. {
  1237. struct elf_lm32_link_hash_table *htab;
  1238. bfd_byte *loc;
  1239. htab = lm32_elf_hash_table (info);
  1240. if (htab == NULL)
  1241. return false;
  1242. if (h->plt.offset != (bfd_vma) -1)
  1243. {
  1244. asection *splt;
  1245. asection *sgot;
  1246. asection *srela;
  1247. bfd_vma plt_index;
  1248. bfd_vma got_offset;
  1249. Elf_Internal_Rela rela;
  1250. /* This symbol has an entry in the procedure linkage table. Set
  1251. it up. */
  1252. BFD_ASSERT (h->dynindx != -1);
  1253. splt = htab->root.splt;
  1254. sgot = htab->root.sgotplt;
  1255. srela = htab->root.srelplt;
  1256. BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
  1257. /* Get the index in the procedure linkage table which
  1258. corresponds to this symbol. This is the index of this symbol
  1259. in all the symbols for which we are making plt entries. The
  1260. first entry in the procedure linkage table is reserved. */
  1261. plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
  1262. /* Get the offset into the .got table of the entry that
  1263. corresponds to this function. Each .got entry is 4 bytes.
  1264. The first three are reserved. */
  1265. got_offset = (plt_index + 3) * 4;
  1266. /* Fill in the entry in the procedure linkage table. */
  1267. if (! bfd_link_pic (info))
  1268. {
  1269. /* TODO */
  1270. }
  1271. else
  1272. {
  1273. /* TODO */
  1274. }
  1275. /* Fill in the entry in the global offset table. */
  1276. bfd_put_32 (output_bfd,
  1277. (splt->output_section->vma
  1278. + splt->output_offset
  1279. + h->plt.offset
  1280. + 12), /* same offset */
  1281. sgot->contents + got_offset);
  1282. /* Fill in the entry in the .rela.plt section. */
  1283. rela.r_offset = (sgot->output_section->vma
  1284. + sgot->output_offset
  1285. + got_offset);
  1286. rela.r_info = ELF32_R_INFO (h->dynindx, R_LM32_JMP_SLOT);
  1287. rela.r_addend = 0;
  1288. loc = srela->contents;
  1289. loc += plt_index * sizeof (Elf32_External_Rela);
  1290. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1291. if (!h->def_regular)
  1292. {
  1293. /* Mark the symbol as undefined, rather than as defined in
  1294. the .plt section. Leave the value alone. */
  1295. sym->st_shndx = SHN_UNDEF;
  1296. }
  1297. }
  1298. if (h->got.offset != (bfd_vma) -1)
  1299. {
  1300. asection *sgot;
  1301. asection *srela;
  1302. Elf_Internal_Rela rela;
  1303. /* This symbol has an entry in the global offset table. Set it
  1304. up. */
  1305. sgot = htab->root.sgot;
  1306. srela = htab->root.srelgot;
  1307. BFD_ASSERT (sgot != NULL && srela != NULL);
  1308. rela.r_offset = (sgot->output_section->vma
  1309. + sgot->output_offset
  1310. + (h->got.offset &~ 1));
  1311. /* If this is a -Bsymbolic link, and the symbol is defined
  1312. locally, we just want to emit a RELATIVE reloc. Likewise if
  1313. the symbol was forced to be local because of a version file.
  1314. The entry in the global offset table will already have been
  1315. initialized in the relocate_section function. */
  1316. if (bfd_link_pic (info)
  1317. && (info->symbolic
  1318. || h->dynindx == -1
  1319. || h->forced_local)
  1320. && h->def_regular)
  1321. {
  1322. rela.r_info = ELF32_R_INFO (0, R_LM32_RELATIVE);
  1323. rela.r_addend = (h->root.u.def.value
  1324. + h->root.u.def.section->output_section->vma
  1325. + h->root.u.def.section->output_offset);
  1326. }
  1327. else
  1328. {
  1329. BFD_ASSERT ((h->got.offset & 1) == 0);
  1330. bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
  1331. rela.r_info = ELF32_R_INFO (h->dynindx, R_LM32_GLOB_DAT);
  1332. rela.r_addend = 0;
  1333. }
  1334. loc = srela->contents;
  1335. loc += srela->reloc_count * sizeof (Elf32_External_Rela);
  1336. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1337. ++srela->reloc_count;
  1338. }
  1339. if (h->needs_copy)
  1340. {
  1341. asection *s;
  1342. Elf_Internal_Rela rela;
  1343. /* This symbols needs a copy reloc. Set it up. */
  1344. BFD_ASSERT (h->dynindx != -1
  1345. && (h->root.type == bfd_link_hash_defined
  1346. || h->root.type == bfd_link_hash_defweak));
  1347. s = bfd_get_linker_section (htab->root.dynobj, ".rela.bss");
  1348. BFD_ASSERT (s != NULL);
  1349. rela.r_offset = (h->root.u.def.value
  1350. + h->root.u.def.section->output_section->vma
  1351. + h->root.u.def.section->output_offset);
  1352. rela.r_info = ELF32_R_INFO (h->dynindx, R_LM32_COPY);
  1353. rela.r_addend = 0;
  1354. loc = s->contents;
  1355. loc += s->reloc_count * sizeof (Elf32_External_Rela);
  1356. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  1357. ++s->reloc_count;
  1358. }
  1359. /* Mark some specially defined symbols as absolute. */
  1360. if (h == htab->root.hdynamic || h == htab->root.hgot)
  1361. sym->st_shndx = SHN_ABS;
  1362. return true;
  1363. }
  1364. static enum elf_reloc_type_class
  1365. lm32_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
  1366. const asection *rel_sec ATTRIBUTE_UNUSED,
  1367. const Elf_Internal_Rela *rela)
  1368. {
  1369. switch ((int) ELF32_R_TYPE (rela->r_info))
  1370. {
  1371. case R_LM32_RELATIVE: return reloc_class_relative;
  1372. case R_LM32_JMP_SLOT: return reloc_class_plt;
  1373. case R_LM32_COPY: return reloc_class_copy;
  1374. default: return reloc_class_normal;
  1375. }
  1376. }
  1377. /* Adjust a symbol defined by a dynamic object and referenced by a
  1378. regular object. The current definition is in some section of the
  1379. dynamic object, but we're not including those sections. We have to
  1380. change the definition to something the rest of the link can
  1381. understand. */
  1382. static bool
  1383. lm32_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
  1384. struct elf_link_hash_entry *h)
  1385. {
  1386. struct elf_lm32_link_hash_table *htab;
  1387. bfd *dynobj;
  1388. asection *s;
  1389. dynobj = elf_hash_table (info)->dynobj;
  1390. /* Make sure we know what is going on here. */
  1391. BFD_ASSERT (dynobj != NULL
  1392. && (h->needs_plt
  1393. || h->is_weakalias
  1394. || (h->def_dynamic
  1395. && h->ref_regular
  1396. && !h->def_regular)));
  1397. /* If this is a function, put it in the procedure linkage table. We
  1398. will fill in the contents of the procedure linkage table later,
  1399. when we know the address of the .got section. */
  1400. if (h->type == STT_FUNC
  1401. || h->needs_plt)
  1402. {
  1403. if (! bfd_link_pic (info)
  1404. && !h->def_dynamic
  1405. && !h->ref_dynamic
  1406. && h->root.type != bfd_link_hash_undefweak
  1407. && h->root.type != bfd_link_hash_undefined)
  1408. {
  1409. /* This case can occur if we saw a PLT reloc in an input
  1410. file, but the symbol was never referred to by a dynamic
  1411. object. In such a case, we don't actually need to build
  1412. a procedure linkage table, and we can just do a PCREL
  1413. reloc instead. */
  1414. h->plt.offset = (bfd_vma) -1;
  1415. h->needs_plt = 0;
  1416. }
  1417. return true;
  1418. }
  1419. else
  1420. h->plt.offset = (bfd_vma) -1;
  1421. /* If this is a weak symbol, and there is a real definition, the
  1422. processor independent code will have arranged for us to see the
  1423. real definition first, and we can just use the same value. */
  1424. if (h->is_weakalias)
  1425. {
  1426. struct elf_link_hash_entry *def = weakdef (h);
  1427. BFD_ASSERT (def->root.type == bfd_link_hash_defined);
  1428. h->root.u.def.section = def->root.u.def.section;
  1429. h->root.u.def.value = def->root.u.def.value;
  1430. return true;
  1431. }
  1432. /* This is a reference to a symbol defined by a dynamic object which
  1433. is not a function. */
  1434. /* If we are creating a shared library, we must presume that the
  1435. only references to the symbol are via the global offset table.
  1436. For such cases we need not do anything here; the relocations will
  1437. be handled correctly by relocate_section. */
  1438. if (bfd_link_pic (info))
  1439. return true;
  1440. /* If there are no references to this symbol that do not use the
  1441. GOT, we don't need to generate a copy reloc. */
  1442. if (!h->non_got_ref)
  1443. return true;
  1444. /* If -z nocopyreloc was given, we won't generate them either. */
  1445. if (0 && info->nocopyreloc)
  1446. {
  1447. h->non_got_ref = 0;
  1448. return true;
  1449. }
  1450. /* If we don't find any dynamic relocs in read-only sections, then
  1451. we'll be keeping the dynamic relocs and avoiding the copy reloc. */
  1452. if (0 && !_bfd_elf_readonly_dynrelocs (h))
  1453. {
  1454. h->non_got_ref = 0;
  1455. return true;
  1456. }
  1457. /* We must allocate the symbol in our .dynbss section, which will
  1458. become part of the .bss section of the executable. There will be
  1459. an entry for this symbol in the .dynsym section. The dynamic
  1460. object will contain position independent code, so all references
  1461. from the dynamic object to this symbol will go through the global
  1462. offset table. The dynamic linker will use the .dynsym entry to
  1463. determine the address it must put in the global offset table, so
  1464. both the dynamic object and the regular object will refer to the
  1465. same memory location for the variable. */
  1466. htab = lm32_elf_hash_table (info);
  1467. if (htab == NULL)
  1468. return false;
  1469. s = htab->sdynbss;
  1470. BFD_ASSERT (s != NULL);
  1471. /* We must generate a R_LM32_COPY reloc to tell the dynamic linker
  1472. to copy the initial value out of the dynamic object and into the
  1473. runtime process image. We need to remember the offset into the
  1474. .rela.bss section we are going to use. */
  1475. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  1476. {
  1477. asection *srel;
  1478. srel = htab->srelbss;
  1479. BFD_ASSERT (srel != NULL);
  1480. srel->size += sizeof (Elf32_External_Rela);
  1481. h->needs_copy = 1;
  1482. }
  1483. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  1484. }
  1485. /* Allocate space in .plt, .got and associated reloc sections for
  1486. dynamic relocs. */
  1487. static bool
  1488. allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
  1489. {
  1490. struct bfd_link_info *info;
  1491. struct elf_lm32_link_hash_table *htab;
  1492. struct elf_dyn_relocs *p;
  1493. if (h->root.type == bfd_link_hash_indirect)
  1494. return true;
  1495. info = (struct bfd_link_info *) inf;
  1496. htab = lm32_elf_hash_table (info);
  1497. if (htab == NULL)
  1498. return false;
  1499. if (htab->root.dynamic_sections_created
  1500. && h->plt.refcount > 0)
  1501. {
  1502. /* Make sure this symbol is output as a dynamic symbol.
  1503. Undefined weak syms won't yet be marked as dynamic. */
  1504. if (h->dynindx == -1
  1505. && !h->forced_local)
  1506. {
  1507. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1508. return false;
  1509. }
  1510. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
  1511. {
  1512. asection *s = htab->root.splt;
  1513. /* If this is the first .plt entry, make room for the special
  1514. first entry. */
  1515. if (s->size == 0)
  1516. s->size += PLT_ENTRY_SIZE;
  1517. h->plt.offset = s->size;
  1518. /* If this symbol is not defined in a regular file, and we are
  1519. not generating a shared library, then set the symbol to this
  1520. location in the .plt. This is required to make function
  1521. pointers compare as equal between the normal executable and
  1522. the shared library. */
  1523. if (! bfd_link_pic (info)
  1524. && !h->def_regular)
  1525. {
  1526. h->root.u.def.section = s;
  1527. h->root.u.def.value = h->plt.offset;
  1528. }
  1529. /* Make room for this entry. */
  1530. s->size += PLT_ENTRY_SIZE;
  1531. /* We also need to make an entry in the .got.plt section, which
  1532. will be placed in the .got section by the linker script. */
  1533. htab->root.sgotplt->size += 4;
  1534. /* We also need to make an entry in the .rel.plt section. */
  1535. htab->root.srelplt->size += sizeof (Elf32_External_Rela);
  1536. }
  1537. else
  1538. {
  1539. h->plt.offset = (bfd_vma) -1;
  1540. h->needs_plt = 0;
  1541. }
  1542. }
  1543. else
  1544. {
  1545. h->plt.offset = (bfd_vma) -1;
  1546. h->needs_plt = 0;
  1547. }
  1548. if (h->got.refcount > 0)
  1549. {
  1550. asection *s;
  1551. bool dyn;
  1552. /* Make sure this symbol is output as a dynamic symbol.
  1553. Undefined weak syms won't yet be marked as dynamic. */
  1554. if (h->dynindx == -1
  1555. && !h->forced_local)
  1556. {
  1557. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1558. return false;
  1559. }
  1560. s = htab->root.sgot;
  1561. h->got.offset = s->size;
  1562. s->size += 4;
  1563. dyn = htab->root.dynamic_sections_created;
  1564. if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h))
  1565. htab->root.srelgot->size += sizeof (Elf32_External_Rela);
  1566. }
  1567. else
  1568. h->got.offset = (bfd_vma) -1;
  1569. if (h->dyn_relocs == NULL)
  1570. return true;
  1571. /* In the shared -Bsymbolic case, discard space allocated for
  1572. dynamic pc-relative relocs against symbols which turn out to be
  1573. defined in regular objects. For the normal shared case, discard
  1574. space for pc-relative relocs that have become local due to symbol
  1575. visibility changes. */
  1576. if (bfd_link_pic (info))
  1577. {
  1578. if (h->def_regular
  1579. && (h->forced_local
  1580. || info->symbolic))
  1581. {
  1582. struct elf_dyn_relocs **pp;
  1583. for (pp = &h->dyn_relocs; (p = *pp) != NULL;)
  1584. {
  1585. p->count -= p->pc_count;
  1586. p->pc_count = 0;
  1587. if (p->count == 0)
  1588. *pp = p->next;
  1589. else
  1590. pp = &p->next;
  1591. }
  1592. }
  1593. /* Also discard relocs on undefined weak syms with non-default
  1594. visibility. */
  1595. if (h->dyn_relocs != NULL
  1596. && h->root.type == bfd_link_hash_undefweak)
  1597. {
  1598. if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
  1599. h->dyn_relocs = NULL;
  1600. /* Make sure undefined weak symbols are output as a dynamic
  1601. symbol in PIEs. */
  1602. else if (h->dynindx == -1
  1603. && !h->forced_local)
  1604. {
  1605. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1606. return false;
  1607. }
  1608. }
  1609. }
  1610. else
  1611. {
  1612. /* For the non-shared case, discard space for relocs against
  1613. symbols which turn out to need copy relocs or are not
  1614. dynamic. */
  1615. if (!h->non_got_ref
  1616. && ((h->def_dynamic
  1617. && !h->def_regular)
  1618. || (htab->root.dynamic_sections_created
  1619. && (h->root.type == bfd_link_hash_undefweak
  1620. || h->root.type == bfd_link_hash_undefined))))
  1621. {
  1622. /* Make sure this symbol is output as a dynamic symbol.
  1623. Undefined weak syms won't yet be marked as dynamic. */
  1624. if (h->dynindx == -1
  1625. && !h->forced_local)
  1626. {
  1627. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  1628. return false;
  1629. }
  1630. /* If that succeeded, we know we'll be keeping all the
  1631. relocs. */
  1632. if (h->dynindx != -1)
  1633. goto keep;
  1634. }
  1635. h->dyn_relocs = NULL;
  1636. keep: ;
  1637. }
  1638. /* Finally, allocate space. */
  1639. for (p = h->dyn_relocs; p != NULL; p = p->next)
  1640. {
  1641. asection *sreloc = elf_section_data (p->sec)->sreloc;
  1642. sreloc->size += p->count * sizeof (Elf32_External_Rela);
  1643. }
  1644. return true;
  1645. }
  1646. /* Set the sizes of the dynamic sections. */
  1647. static bool
  1648. lm32_elf_size_dynamic_sections (bfd *output_bfd,
  1649. struct bfd_link_info *info)
  1650. {
  1651. struct elf_lm32_link_hash_table *htab;
  1652. bfd *dynobj;
  1653. asection *s;
  1654. bool relocs;
  1655. bfd *ibfd;
  1656. htab = lm32_elf_hash_table (info);
  1657. if (htab == NULL)
  1658. return false;
  1659. dynobj = htab->root.dynobj;
  1660. BFD_ASSERT (dynobj != NULL);
  1661. if (htab->root.dynamic_sections_created)
  1662. {
  1663. /* Set the contents of the .interp section to the interpreter. */
  1664. if (bfd_link_executable (info) && !info->nointerp)
  1665. {
  1666. s = bfd_get_linker_section (dynobj, ".interp");
  1667. BFD_ASSERT (s != NULL);
  1668. s->size = sizeof ELF_DYNAMIC_INTERPRETER;
  1669. s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
  1670. }
  1671. }
  1672. /* Set up .got offsets for local syms, and space for local dynamic
  1673. relocs. */
  1674. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  1675. {
  1676. bfd_signed_vma *local_got;
  1677. bfd_signed_vma *end_local_got;
  1678. bfd_size_type locsymcount;
  1679. Elf_Internal_Shdr *symtab_hdr;
  1680. asection *srel;
  1681. if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
  1682. continue;
  1683. for (s = ibfd->sections; s != NULL; s = s->next)
  1684. {
  1685. struct elf_dyn_relocs *p;
  1686. for (p = ((struct elf_dyn_relocs *)
  1687. elf_section_data (s)->local_dynrel);
  1688. p != NULL;
  1689. p = p->next)
  1690. {
  1691. if (! bfd_is_abs_section (p->sec)
  1692. && bfd_is_abs_section (p->sec->output_section))
  1693. {
  1694. /* Input section has been discarded, either because
  1695. it is a copy of a linkonce section or due to
  1696. linker script /DISCARD/, so we'll be discarding
  1697. the relocs too. */
  1698. }
  1699. else if (p->count != 0)
  1700. {
  1701. srel = elf_section_data (p->sec)->sreloc;
  1702. srel->size += p->count * sizeof (Elf32_External_Rela);
  1703. if ((p->sec->output_section->flags & SEC_READONLY) != 0)
  1704. info->flags |= DF_TEXTREL;
  1705. }
  1706. }
  1707. }
  1708. local_got = elf_local_got_refcounts (ibfd);
  1709. if (!local_got)
  1710. continue;
  1711. symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
  1712. locsymcount = symtab_hdr->sh_info;
  1713. end_local_got = local_got + locsymcount;
  1714. s = htab->root.sgot;
  1715. srel = htab->root.srelgot;
  1716. for (; local_got < end_local_got; ++local_got)
  1717. {
  1718. if (*local_got > 0)
  1719. {
  1720. *local_got = s->size;
  1721. s->size += 4;
  1722. if (bfd_link_pic (info))
  1723. srel->size += sizeof (Elf32_External_Rela);
  1724. }
  1725. else
  1726. *local_got = (bfd_vma) -1;
  1727. }
  1728. }
  1729. /* Allocate global sym .plt and .got entries, and space for global
  1730. sym dynamic relocs. */
  1731. elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
  1732. /* We now have determined the sizes of the various dynamic sections.
  1733. Allocate memory for them. */
  1734. relocs = false;
  1735. for (s = dynobj->sections; s != NULL; s = s->next)
  1736. {
  1737. if ((s->flags & SEC_LINKER_CREATED) == 0)
  1738. continue;
  1739. if (s == htab->root.splt
  1740. || s == htab->root.sgot
  1741. || s == htab->root.sgotplt
  1742. || s == htab->sdynbss)
  1743. {
  1744. /* Strip this section if we don't need it; see the
  1745. comment below. */
  1746. }
  1747. else if (startswith (bfd_section_name (s), ".rela"))
  1748. {
  1749. if (s->size != 0 && s != htab->root.srelplt)
  1750. relocs = true;
  1751. /* We use the reloc_count field as a counter if we need
  1752. to copy relocs into the output file. */
  1753. s->reloc_count = 0;
  1754. }
  1755. else
  1756. /* It's not one of our sections, so don't allocate space. */
  1757. continue;
  1758. if (s->size == 0)
  1759. {
  1760. /* If we don't need this section, strip it from the
  1761. output file. This is mostly to handle .rela.bss and
  1762. .rela.plt. We must create both sections in
  1763. create_dynamic_sections, because they must be created
  1764. before the linker maps input sections to output
  1765. sections. The linker does that before
  1766. adjust_dynamic_symbol is called, and it is that
  1767. function which decides whether anything needs to go
  1768. into these sections. */
  1769. s->flags |= SEC_EXCLUDE;
  1770. continue;
  1771. }
  1772. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  1773. continue;
  1774. /* Allocate memory for the section contents. We use bfd_zalloc
  1775. here in case unused entries are not reclaimed before the
  1776. section's contents are written out. This should not happen,
  1777. but this way if it does, we get a R_LM32_NONE reloc instead
  1778. of garbage. */
  1779. s->contents = bfd_zalloc (dynobj, s->size);
  1780. if (s->contents == NULL)
  1781. return false;
  1782. }
  1783. if (!_bfd_elf_add_dynamic_tags (output_bfd, info, relocs))
  1784. return false;
  1785. /* Allocate .rofixup section. */
  1786. if (IS_FDPIC (output_bfd))
  1787. {
  1788. struct weak_symbol_list *list_start = NULL, *list_end = NULL;
  1789. int rgot_weak_count = 0;
  1790. int r32_count = 0;
  1791. int rgot_count = 0;
  1792. /* Look for deleted sections. */
  1793. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  1794. {
  1795. for (s = ibfd->sections; s != NULL; s = s->next)
  1796. {
  1797. if (s->reloc_count)
  1798. {
  1799. /* Count relocs that need .rofixup entires. */
  1800. Elf_Internal_Rela *internal_relocs, *end;
  1801. internal_relocs = elf_section_data (s)->relocs;
  1802. if (internal_relocs == NULL)
  1803. internal_relocs = (_bfd_elf_link_read_relocs (ibfd, s, NULL, NULL, false));
  1804. if (internal_relocs != NULL)
  1805. {
  1806. end = internal_relocs + s->reloc_count;
  1807. while (internal_relocs < end)
  1808. {
  1809. Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
  1810. struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
  1811. unsigned long r_symndx;
  1812. struct elf_link_hash_entry *h;
  1813. symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
  1814. sym_hashes = elf_sym_hashes (ibfd);
  1815. r_symndx = ELF32_R_SYM (internal_relocs->r_info);
  1816. h = NULL;
  1817. if (r_symndx < symtab_hdr->sh_info)
  1818. {
  1819. }
  1820. else
  1821. {
  1822. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  1823. while (h->root.type == bfd_link_hash_indirect
  1824. || h->root.type == bfd_link_hash_warning)
  1825. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  1826. }
  1827. /* Don't generate entries for weak symbols. */
  1828. if (!h || (h && h->root.type != bfd_link_hash_undefweak))
  1829. {
  1830. if (!discarded_section (s) && !((bfd_section_flags (s) & SEC_ALLOC) == 0))
  1831. {
  1832. switch (ELF32_R_TYPE (internal_relocs->r_info))
  1833. {
  1834. case R_LM32_32:
  1835. r32_count++;
  1836. break;
  1837. case R_LM32_16_GOT:
  1838. rgot_count++;
  1839. break;
  1840. }
  1841. }
  1842. }
  1843. else
  1844. {
  1845. struct weak_symbol_list *current, *new_entry;
  1846. /* Is this symbol already in the list? */
  1847. for (current = list_start; current; current = current->next)
  1848. {
  1849. if (!strcmp (current->name, h->root.root.string))
  1850. break;
  1851. }
  1852. if (!current && !discarded_section (s) && (bfd_section_flags (s) & SEC_ALLOC))
  1853. {
  1854. /* Will this have an entry in the GOT. */
  1855. if (ELF32_R_TYPE (internal_relocs->r_info) == R_LM32_16_GOT)
  1856. {
  1857. /* Create a new entry. */
  1858. new_entry = malloc (sizeof (struct weak_symbol_list));
  1859. if (!new_entry)
  1860. return false;
  1861. new_entry->name = h->root.root.string;
  1862. new_entry->next = NULL;
  1863. /* Add to list */
  1864. if (list_start == NULL)
  1865. {
  1866. list_start = new_entry;
  1867. list_end = new_entry;
  1868. }
  1869. else
  1870. {
  1871. list_end->next = new_entry;
  1872. list_end = new_entry;
  1873. }
  1874. /* Increase count of undefined weak symbols in the got. */
  1875. rgot_weak_count++;
  1876. }
  1877. }
  1878. }
  1879. internal_relocs++;
  1880. }
  1881. }
  1882. else
  1883. return false;
  1884. }
  1885. }
  1886. }
  1887. /* Free list. */
  1888. while (list_start)
  1889. {
  1890. list_end = list_start->next;
  1891. free (list_start);
  1892. list_start = list_end;
  1893. }
  1894. /* Size sections. */
  1895. lm32fdpic_fixup32_section (info)->size
  1896. = (r32_count + (htab->root.sgot->size / 4) - rgot_weak_count + 1) * 4;
  1897. if (lm32fdpic_fixup32_section (info)->size == 0)
  1898. lm32fdpic_fixup32_section (info)->flags |= SEC_EXCLUDE;
  1899. else
  1900. {
  1901. lm32fdpic_fixup32_section (info)->contents =
  1902. bfd_zalloc (dynobj, lm32fdpic_fixup32_section (info)->size);
  1903. if (lm32fdpic_fixup32_section (info)->contents == NULL)
  1904. return false;
  1905. }
  1906. }
  1907. return true;
  1908. }
  1909. /* Create dynamic sections when linking against a dynamic object. */
  1910. static bool
  1911. lm32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
  1912. {
  1913. struct elf_lm32_link_hash_table *htab;
  1914. flagword flags, pltflags;
  1915. asection *s;
  1916. const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  1917. int ptralign = 2; /* 32bit */
  1918. htab = lm32_elf_hash_table (info);
  1919. if (htab == NULL)
  1920. return false;
  1921. /* Make sure we have a GOT - For the case where we have a dynamic object
  1922. but none of the relocs in check_relocs */
  1923. if (!_bfd_elf_create_got_section (abfd, info))
  1924. return false;
  1925. if (IS_FDPIC (abfd) && (htab->sfixup32 == NULL))
  1926. {
  1927. if (! create_rofixup_section (abfd, info))
  1928. return false;
  1929. }
  1930. /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
  1931. .rel[a].bss sections. */
  1932. flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
  1933. | SEC_LINKER_CREATED);
  1934. pltflags = flags;
  1935. pltflags |= SEC_CODE;
  1936. if (bed->plt_not_loaded)
  1937. pltflags &= ~ (SEC_LOAD | SEC_HAS_CONTENTS);
  1938. if (bed->plt_readonly)
  1939. pltflags |= SEC_READONLY;
  1940. s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
  1941. htab->root.splt = s;
  1942. if (s == NULL
  1943. || !bfd_set_section_alignment (s, bed->plt_alignment))
  1944. return false;
  1945. if (bed->want_plt_sym)
  1946. {
  1947. /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
  1948. .plt section. */
  1949. struct bfd_link_hash_entry *bh = NULL;
  1950. struct elf_link_hash_entry *h;
  1951. if (! (_bfd_generic_link_add_one_symbol
  1952. (info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
  1953. (bfd_vma) 0, NULL, false,
  1954. get_elf_backend_data (abfd)->collect, &bh)))
  1955. return false;
  1956. h = (struct elf_link_hash_entry *) bh;
  1957. h->def_regular = 1;
  1958. h->type = STT_OBJECT;
  1959. htab->root.hplt = h;
  1960. if (bfd_link_pic (info)
  1961. && ! bfd_elf_link_record_dynamic_symbol (info, h))
  1962. return false;
  1963. }
  1964. s = bfd_make_section_anyway_with_flags (abfd,
  1965. bed->default_use_rela_p
  1966. ? ".rela.plt" : ".rel.plt",
  1967. flags | SEC_READONLY);
  1968. htab->root.srelplt = s;
  1969. if (s == NULL
  1970. || !bfd_set_section_alignment (s, ptralign))
  1971. return false;
  1972. if (htab->root.sgot == NULL
  1973. && !_bfd_elf_create_got_section (abfd, info))
  1974. return false;
  1975. if (bed->want_dynbss)
  1976. {
  1977. /* The .dynbss section is a place to put symbols which are defined
  1978. by dynamic objects, are referenced by regular objects, and are
  1979. not functions. We must allocate space for them in the process
  1980. image and use a R_*_COPY reloc to tell the dynamic linker to
  1981. initialize them at run time. The linker script puts the .dynbss
  1982. section into the .bss section of the final image. */
  1983. s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
  1984. SEC_ALLOC | SEC_LINKER_CREATED);
  1985. htab->sdynbss = s;
  1986. if (s == NULL)
  1987. return false;
  1988. /* The .rel[a].bss section holds copy relocs. This section is not
  1989. normally needed. We need to create it here, though, so that the
  1990. linker will map it to an output section. We can't just create it
  1991. only if we need it, because we will not know whether we need it
  1992. until we have seen all the input files, and the first time the
  1993. main linker code calls BFD after examining all the input files
  1994. (size_dynamic_sections) the input sections have already been
  1995. mapped to the output sections. If the section turns out not to
  1996. be needed, we can discard it later. We will never need this
  1997. section when generating a shared object, since they do not use
  1998. copy relocs. */
  1999. if (! bfd_link_pic (info))
  2000. {
  2001. s = bfd_make_section_anyway_with_flags (abfd,
  2002. (bed->default_use_rela_p
  2003. ? ".rela.bss" : ".rel.bss"),
  2004. flags | SEC_READONLY);
  2005. htab->srelbss = s;
  2006. if (s == NULL
  2007. || !bfd_set_section_alignment (s, ptralign))
  2008. return false;
  2009. }
  2010. }
  2011. return true;
  2012. }
  2013. static bool
  2014. lm32_elf_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
  2015. {
  2016. if (!bfd_link_relocatable (info))
  2017. {
  2018. if (!bfd_elf_stack_segment_size (output_bfd, info,
  2019. "__stacksize", DEFAULT_STACK_SIZE))
  2020. return false;
  2021. asection *sec = bfd_get_section_by_name (output_bfd, ".stack");
  2022. if (sec)
  2023. sec->size = info->stacksize >= 0 ? info->stacksize : 0;
  2024. }
  2025. return true;
  2026. }
  2027. static bool
  2028. lm32_elf_fdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
  2029. {
  2030. unsigned i;
  2031. if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
  2032. || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
  2033. return true;
  2034. if (! _bfd_elf_copy_private_bfd_data (ibfd, obfd))
  2035. return false;
  2036. if (! elf_tdata (ibfd) || ! elf_tdata (ibfd)->phdr
  2037. || ! elf_tdata (obfd) || ! elf_tdata (obfd)->phdr)
  2038. return true;
  2039. /* Copy the stack size. */
  2040. for (i = 0; i < elf_elfheader (ibfd)->e_phnum; i++)
  2041. if (elf_tdata (ibfd)->phdr[i].p_type == PT_GNU_STACK)
  2042. {
  2043. Elf_Internal_Phdr *iphdr = &elf_tdata (ibfd)->phdr[i];
  2044. for (i = 0; i < elf_elfheader (obfd)->e_phnum; i++)
  2045. if (elf_tdata (obfd)->phdr[i].p_type == PT_GNU_STACK)
  2046. {
  2047. memcpy (&elf_tdata (obfd)->phdr[i], iphdr, sizeof (*iphdr));
  2048. /* Rewrite the phdrs, since we're only called after they were first written. */
  2049. if (bfd_seek (obfd, (bfd_signed_vma) get_elf_backend_data (obfd)
  2050. ->s->sizeof_ehdr, SEEK_SET) != 0
  2051. || get_elf_backend_data (obfd)->s->write_out_phdrs (obfd, elf_tdata (obfd)->phdr,
  2052. elf_elfheader (obfd)->e_phnum) != 0)
  2053. return false;
  2054. break;
  2055. }
  2056. break;
  2057. }
  2058. return true;
  2059. }
  2060. #define ELF_ARCH bfd_arch_lm32
  2061. #define ELF_TARGET_ID LM32_ELF_DATA
  2062. #define ELF_MACHINE_CODE EM_LATTICEMICO32
  2063. #define ELF_MAXPAGESIZE 0x1000
  2064. #define TARGET_BIG_SYM lm32_elf32_vec
  2065. #define TARGET_BIG_NAME "elf32-lm32"
  2066. #define bfd_elf32_bfd_reloc_type_lookup lm32_reloc_type_lookup
  2067. #define bfd_elf32_bfd_reloc_name_lookup lm32_reloc_name_lookup
  2068. #define elf_info_to_howto lm32_info_to_howto_rela
  2069. #define elf_info_to_howto_rel NULL
  2070. #define elf_backend_rela_normal 1
  2071. #define elf_backend_object_p lm32_elf_object_p
  2072. #define elf_backend_final_write_processing lm32_elf_final_write_processing
  2073. #define elf_backend_stack_align 8
  2074. #define elf_backend_can_gc_sections 1
  2075. #define elf_backend_can_refcount 1
  2076. #define elf_backend_gc_mark_hook lm32_elf_gc_mark_hook
  2077. #define elf_backend_plt_readonly 1
  2078. #define elf_backend_want_got_plt 1
  2079. #define elf_backend_want_plt_sym 0
  2080. #define elf_backend_got_header_size 12
  2081. #define elf_backend_dtrel_excludes_plt 1
  2082. #define bfd_elf32_bfd_link_hash_table_create lm32_elf_link_hash_table_create
  2083. #define elf_backend_check_relocs lm32_elf_check_relocs
  2084. #define elf_backend_reloc_type_class lm32_elf_reloc_type_class
  2085. #define elf_backend_size_dynamic_sections lm32_elf_size_dynamic_sections
  2086. #define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
  2087. #define elf_backend_create_dynamic_sections lm32_elf_create_dynamic_sections
  2088. #define elf_backend_finish_dynamic_sections lm32_elf_finish_dynamic_sections
  2089. #define elf_backend_adjust_dynamic_symbol lm32_elf_adjust_dynamic_symbol
  2090. #define elf_backend_finish_dynamic_symbol lm32_elf_finish_dynamic_symbol
  2091. #define elf_backend_relocate_section lm32_elf_relocate_section
  2092. #include "elf32-target.h"
  2093. #undef ELF_MAXPAGESIZE
  2094. #define ELF_MAXPAGESIZE 0x4000
  2095. #undef TARGET_BIG_SYM
  2096. #define TARGET_BIG_SYM lm32_elf32_fdpic_vec
  2097. #undef TARGET_BIG_NAME
  2098. #define TARGET_BIG_NAME "elf32-lm32fdpic"
  2099. #undef elf32_bed
  2100. #define elf32_bed elf32_lm32fdpic_bed
  2101. #undef elf_backend_always_size_sections
  2102. #define elf_backend_always_size_sections lm32_elf_always_size_sections
  2103. #undef bfd_elf32_bfd_copy_private_bfd_data
  2104. #define bfd_elf32_bfd_copy_private_bfd_data lm32_elf_fdpic_copy_private_bfd_data
  2105. #include "elf32-target.h"