elf32-v850.c 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281
  1. /* V850-specific support for 32-bit ELF
  2. Copyright (C) 1996-2022 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. /* XXX FIXME: This code is littered with 32bit int, 16bit short, 8bit char
  17. dependencies. As is the gas & simulator code for the v850. */
  18. #include "sysdep.h"
  19. #include "bfd.h"
  20. #include "bfdlink.h"
  21. #include "libbfd.h"
  22. #include "elf-bfd.h"
  23. #include "elf/v850.h"
  24. #include "libiberty.h"
  25. #include "elf32-v850.h"
  26. /* Sign-extend a 17-bit number. */
  27. #define SEXT17(x) ((((x) & 0x1ffff) ^ 0x10000) - 0x10000)
  28. /* Sign-extend a 22-bit number. */
  29. #define SEXT22(x) ((((x) & 0x3fffff) ^ 0x200000) - 0x200000)
  30. static reloc_howto_type v850_elf_howto_table[];
  31. /* Look through the relocs for a section during the first phase, and
  32. allocate space in the global offset table or procedure linkage
  33. table. */
  34. static bool
  35. v850_elf_check_relocs (bfd *abfd,
  36. struct bfd_link_info *info,
  37. asection *sec,
  38. const Elf_Internal_Rela *relocs)
  39. {
  40. bool ret = true;
  41. Elf_Internal_Shdr *symtab_hdr;
  42. struct elf_link_hash_entry **sym_hashes;
  43. const Elf_Internal_Rela *rel;
  44. const Elf_Internal_Rela *rel_end;
  45. unsigned int r_type;
  46. int other = 0;
  47. const char *common = NULL;
  48. if (bfd_link_relocatable (info))
  49. return true;
  50. #ifdef DEBUG
  51. _bfd_error_handler ("v850_elf_check_relocs called for section %pA in %pB",
  52. sec, abfd);
  53. #endif
  54. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  55. sym_hashes = elf_sym_hashes (abfd);
  56. rel_end = relocs + sec->reloc_count;
  57. for (rel = relocs; rel < rel_end; rel++)
  58. {
  59. unsigned long r_symndx;
  60. struct elf_link_hash_entry *h;
  61. r_symndx = ELF32_R_SYM (rel->r_info);
  62. if (r_symndx < symtab_hdr->sh_info)
  63. h = NULL;
  64. else
  65. {
  66. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  67. while (h->root.type == bfd_link_hash_indirect
  68. || h->root.type == bfd_link_hash_warning)
  69. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  70. }
  71. r_type = ELF32_R_TYPE (rel->r_info);
  72. switch (r_type)
  73. {
  74. default:
  75. break;
  76. /* This relocation describes the C++ object vtable hierarchy.
  77. Reconstruct it for later use during GC. */
  78. case R_V850_GNU_VTINHERIT:
  79. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  80. return false;
  81. break;
  82. /* This relocation describes which C++ vtable entries
  83. are actually used. Record for later use during GC. */
  84. case R_V850_GNU_VTENTRY:
  85. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  86. return false;
  87. break;
  88. case R_V850_SDA_16_16_SPLIT_OFFSET:
  89. case R_V850_SDA_16_16_OFFSET:
  90. case R_V850_SDA_15_16_OFFSET:
  91. case R_V810_GPWLO_1:
  92. case R_V850_HWLO:
  93. case R_V850_HWLO_1:
  94. other = V850_OTHER_SDA;
  95. common = ".scommon";
  96. goto small_data_common;
  97. case R_V850_ZDA_16_16_SPLIT_OFFSET:
  98. case R_V850_ZDA_16_16_OFFSET:
  99. case R_V850_ZDA_15_16_OFFSET:
  100. other = V850_OTHER_ZDA;
  101. common = ".zcommon";
  102. goto small_data_common;
  103. case R_V850_TDA_4_4_OFFSET:
  104. case R_V850_TDA_4_5_OFFSET:
  105. case R_V850_TDA_7_7_OFFSET:
  106. case R_V850_TDA_6_8_OFFSET:
  107. case R_V850_TDA_7_8_OFFSET:
  108. case R_V850_TDA_16_16_OFFSET:
  109. other = V850_OTHER_TDA;
  110. common = ".tcommon";
  111. /* fall through */
  112. #define V850_OTHER_MASK (V850_OTHER_TDA | V850_OTHER_SDA | V850_OTHER_ZDA)
  113. small_data_common:
  114. if (h)
  115. {
  116. /* Flag which type of relocation was used. */
  117. h->other |= other;
  118. if ((h->other & V850_OTHER_MASK) != (other & V850_OTHER_MASK)
  119. && (h->other & V850_OTHER_ERROR) == 0)
  120. {
  121. const char * msg;
  122. char *buff;
  123. switch (h->other & V850_OTHER_MASK)
  124. {
  125. default:
  126. msg = _("variable `%s' cannot occupy in multiple small data regions");
  127. break;
  128. case V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA:
  129. msg = _("variable `%s' can only be in one of the small, zero, and tiny data regions");
  130. break;
  131. case V850_OTHER_SDA | V850_OTHER_ZDA:
  132. msg = _("variable `%s' cannot be in both small and zero data regions simultaneously");
  133. break;
  134. case V850_OTHER_SDA | V850_OTHER_TDA:
  135. msg = _("variable `%s' cannot be in both small and tiny data regions simultaneously");
  136. break;
  137. case V850_OTHER_ZDA | V850_OTHER_TDA:
  138. msg = _("variable `%s' cannot be in both zero and tiny data regions simultaneously");
  139. break;
  140. }
  141. if (asprintf (&buff, msg, h->root.root.string) < 0)
  142. buff = NULL;
  143. else
  144. msg = buff;
  145. info->callbacks->warning (info, msg, h->root.root.string,
  146. abfd, h->root.u.def.section,
  147. (bfd_vma) 0);
  148. free (buff);
  149. bfd_set_error (bfd_error_bad_value);
  150. h->other |= V850_OTHER_ERROR;
  151. ret = false;
  152. }
  153. }
  154. if (h && h->root.type == bfd_link_hash_common
  155. && h->root.u.c.p
  156. && !strcmp (bfd_section_name (h->root.u.c.p->section), "COMMON"))
  157. {
  158. asection * section;
  159. section = h->root.u.c.p->section = bfd_make_section_old_way (abfd, common);
  160. section->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
  161. }
  162. #ifdef DEBUG
  163. fprintf (stderr, "v850_elf_check_relocs, found %s relocation for %s%s\n",
  164. v850_elf_howto_table[ (int)r_type ].name,
  165. (h && h->root.root.string) ? h->root.root.string : "<unknown>",
  166. (h->root.type == bfd_link_hash_common) ? ", symbol is common" : "");
  167. #endif
  168. break;
  169. }
  170. }
  171. return ret;
  172. }
  173. /* In the old version, when an entry was checked out from the table,
  174. it was deleted. This produced an error if the entry was needed
  175. more than once, as the second attempted retry failed.
  176. In the current version, the entry is not deleted, instead we set
  177. the field 'found' to TRUE. If a second lookup matches the same
  178. entry, then we know that the hi16s reloc has already been updated
  179. and does not need to be updated a second time.
  180. TODO - TOFIX: If it is possible that we need to restore 2 different
  181. addresses from the same table entry, where the first generates an
  182. overflow, whilst the second do not, then this code will fail. */
  183. typedef struct hi16s_location
  184. {
  185. bfd_vma addend;
  186. bfd_byte *address;
  187. unsigned long counter;
  188. bool found;
  189. struct hi16s_location *next;
  190. }
  191. hi16s_location;
  192. static hi16s_location * previous_hi16s;
  193. static hi16s_location * free_hi16s;
  194. static unsigned long hi16s_counter;
  195. static void
  196. remember_hi16s_reloc (bfd *abfd, bfd_vma addend, bfd_byte *address)
  197. {
  198. hi16s_location * entry = NULL;
  199. size_t amt = sizeof (* free_hi16s);
  200. /* Find a free structure. */
  201. if (free_hi16s == NULL)
  202. free_hi16s = bfd_zalloc (abfd, amt);
  203. entry = free_hi16s;
  204. free_hi16s = free_hi16s->next;
  205. entry->addend = addend;
  206. entry->address = address;
  207. entry->counter = hi16s_counter ++;
  208. entry->found = false;
  209. entry->next = previous_hi16s;
  210. previous_hi16s = entry;
  211. /* Cope with wrap around of our counter. */
  212. if (hi16s_counter == 0)
  213. {
  214. /* XXX: Assume that all counter entries differ only in their low 16 bits. */
  215. for (entry = previous_hi16s; entry != NULL; entry = entry->next)
  216. entry->counter &= 0xffff;
  217. hi16s_counter = 0x10000;
  218. }
  219. }
  220. static bfd_byte *
  221. find_remembered_hi16s_reloc (bfd_vma addend, bool *already_found)
  222. {
  223. hi16s_location *match = NULL;
  224. hi16s_location *entry;
  225. bfd_byte *addr;
  226. /* Search the table. Record the most recent entry that matches. */
  227. for (entry = previous_hi16s; entry; entry = entry->next)
  228. {
  229. if (entry->addend == addend
  230. && (match == NULL || match->counter < entry->counter))
  231. {
  232. match = entry;
  233. }
  234. }
  235. if (match == NULL)
  236. return NULL;
  237. /* Extract the address. */
  238. addr = match->address;
  239. /* Remember if this entry has already been used before. */
  240. if (already_found)
  241. * already_found = match->found;
  242. /* Note that this entry has now been used. */
  243. match->found = true;
  244. return addr;
  245. }
  246. /* Calculate the final operand value for a R_V850_LO16 or
  247. R_V850_LO16_SPLIT_OFFSET. *INSN is the current operand value and
  248. ADDEND is the sum of the relocation symbol and offset. Store the
  249. operand value in *INSN and return true on success.
  250. The assembler has already done some of this: If the value stored in
  251. the instruction has its 15th bit set, (counting from zero) then the
  252. assembler will have added 1 to the value stored in the associated
  253. HI16S reloc. So for example, these relocations:
  254. movhi hi( fred ), r0, r1
  255. movea lo( fred ), r1, r1
  256. will store 0 in the value fields for the MOVHI and MOVEA instructions
  257. and addend will be the address of fred, but for these instructions:
  258. movhi hi( fred + 0x123456 ), r0, r1
  259. movea lo( fred + 0x123456 ), r1, r1
  260. the value stored in the MOVHI instruction will be 0x12 and the value
  261. stored in the MOVEA instruction will be 0x3456. If however the
  262. instructions were:
  263. movhi hi( fred + 0x10ffff ), r0, r1
  264. movea lo( fred + 0x10ffff ), r1, r1
  265. then the value stored in the MOVHI instruction would be 0x11 (not
  266. 0x10) and the value stored in the MOVEA instruction would be 0xffff.
  267. Thus (assuming for the moment that the addend is 0), at run time the
  268. MOVHI instruction loads 0x110000 into r1, then the MOVEA instruction
  269. adds 0xffffffff (sign extension!) producing 0x10ffff. Similarly if
  270. the instructions were:
  271. movhi hi( fred - 1 ), r0, r1
  272. movea lo( fred - 1 ), r1, r1
  273. then 0 is stored in the MOVHI instruction and -1 is stored in the
  274. MOVEA instruction.
  275. Overflow can occur if the addition of the value stored in the
  276. instruction plus the addend sets the 15th bit when before it was clear.
  277. This is because the 15th bit will be sign extended into the high part,
  278. thus reducing its value by one, but since the 15th bit was originally
  279. clear, the assembler will not have added 1 to the previous HI16S reloc
  280. to compensate for this effect. For example:
  281. movhi hi( fred + 0x123456 ), r0, r1
  282. movea lo( fred + 0x123456 ), r1, r1
  283. The value stored in HI16S reloc is 0x12, the value stored in the LO16
  284. reloc is 0x3456. If we assume that the address of fred is 0x00007000
  285. then the relocations become:
  286. HI16S: 0x0012 + (0x00007000 >> 16) = 0x12
  287. LO16: 0x3456 + (0x00007000 & 0xffff) = 0xa456
  288. but when the instructions are executed, the MOVEA instruction's value
  289. is signed extended, so the sum becomes:
  290. 0x00120000
  291. + 0xffffa456
  292. ------------
  293. 0x0011a456 but 'fred + 0x123456' = 0x0012a456
  294. Note that if the 15th bit was set in the value stored in the LO16
  295. reloc, then we do not have to do anything:
  296. movhi hi( fred + 0x10ffff ), r0, r1
  297. movea lo( fred + 0x10ffff ), r1, r1
  298. HI16S: 0x0011 + (0x00007000 >> 16) = 0x11
  299. LO16: 0xffff + (0x00007000 & 0xffff) = 0x6fff
  300. 0x00110000
  301. + 0x00006fff
  302. ------------
  303. 0x00116fff = fred + 0x10ffff = 0x7000 + 0x10ffff
  304. Overflow can also occur if the computation carries into the 16th bit
  305. and it also results in the 15th bit having the same value as the 15th
  306. bit of the original value. What happens is that the HI16S reloc
  307. will have already examined the 15th bit of the original value and
  308. added 1 to the high part if the bit is set. This compensates for the
  309. sign extension of 15th bit of the result of the computation. But now
  310. there is a carry into the 16th bit, and this has not been allowed for.
  311. So, for example if fred is at address 0xf000:
  312. movhi hi( fred + 0xffff ), r0, r1 [bit 15 of the offset is set]
  313. movea lo( fred + 0xffff ), r1, r1
  314. HI16S: 0x0001 + (0x0000f000 >> 16) = 0x0001
  315. LO16: 0xffff + (0x0000f000 & 0xffff) = 0xefff (carry into bit 16 is lost)
  316. 0x00010000
  317. + 0xffffefff
  318. ------------
  319. 0x0000efff but 'fred + 0xffff' = 0x0001efff
  320. Similarly, if the 15th bit remains clear, but overflow occurs into
  321. the 16th bit then (assuming the address of fred is 0xf000):
  322. movhi hi( fred + 0x7000 ), r0, r1 [bit 15 of the offset is clear]
  323. movea lo( fred + 0x7000 ), r1, r1
  324. HI16S: 0x0000 + (0x0000f000 >> 16) = 0x0000
  325. LO16: 0x7000 + (0x0000f000 & 0xffff) = 0x6fff (carry into bit 16 is lost)
  326. 0x00000000
  327. + 0x00006fff
  328. ------------
  329. 0x00006fff but 'fred + 0x7000' = 0x00016fff
  330. Note - there is no need to change anything if a carry occurs, and the
  331. 15th bit changes its value from being set to being clear, as the HI16S
  332. reloc will have already added in 1 to the high part for us:
  333. movhi hi( fred + 0xffff ), r0, r1 [bit 15 of the offset is set]
  334. movea lo( fred + 0xffff ), r1, r1
  335. HI16S: 0x0001 + (0x00007000 >> 16)
  336. LO16: 0xffff + (0x00007000 & 0xffff) = 0x6fff (carry into bit 16 is lost)
  337. 0x00010000
  338. + 0x00006fff (bit 15 not set, so the top half is zero)
  339. ------------
  340. 0x00016fff which is right (assuming that fred is at 0x7000)
  341. but if the 15th bit goes from being clear to being set, then we must
  342. once again handle overflow:
  343. movhi hi( fred + 0x7000 ), r0, r1 [bit 15 of the offset is clear]
  344. movea lo( fred + 0x7000 ), r1, r1
  345. HI16S: 0x0000 + (0x0000ffff >> 16)
  346. LO16: 0x7000 + (0x0000ffff & 0xffff) = 0x6fff (carry into bit 16)
  347. 0x00000000
  348. + 0x00006fff (bit 15 not set, so the top half is zero)
  349. ------------
  350. 0x00006fff which is wrong (assuming that fred is at 0xffff). */
  351. static bool
  352. v850_elf_perform_lo16_relocation (bfd *abfd, unsigned long *insn,
  353. unsigned long addend)
  354. {
  355. #define BIT15_SET(x) ((x) & 0x8000)
  356. #define OVERFLOWS(a,i) ((((a) & 0xffff) + (i)) > 0xffff)
  357. if ((BIT15_SET (*insn + addend) && ! BIT15_SET (addend))
  358. || (OVERFLOWS (addend, *insn)
  359. && ((! BIT15_SET (*insn)) || (BIT15_SET (addend)))))
  360. {
  361. bool already_updated;
  362. bfd_byte *hi16s_address = find_remembered_hi16s_reloc
  363. (addend, & already_updated);
  364. /* Amend the matching HI16_S relocation. */
  365. if (hi16s_address != NULL)
  366. {
  367. if (! already_updated)
  368. {
  369. unsigned long hi_insn = bfd_get_16 (abfd, hi16s_address);
  370. hi_insn += 1;
  371. bfd_put_16 (abfd, hi_insn, hi16s_address);
  372. }
  373. }
  374. else
  375. {
  376. _bfd_error_handler (_("failed to find previous HI16 reloc"));
  377. return false;
  378. }
  379. }
  380. #undef OVERFLOWS
  381. #undef BIT15_SET
  382. /* Do not complain if value has top bit set, as this has been
  383. anticipated. */
  384. *insn = (*insn + addend) & 0xffff;
  385. return true;
  386. }
  387. /* FIXME: The code here probably ought to be removed and the code in reloc.c
  388. allowed to do its stuff instead. At least for most of the relocs, anyway. */
  389. static bfd_reloc_status_type
  390. v850_elf_perform_relocation (bfd *abfd,
  391. unsigned int r_type,
  392. bfd_vma addend,
  393. bfd_byte *address)
  394. {
  395. unsigned long insn;
  396. unsigned long result;
  397. bfd_signed_vma saddend = (bfd_signed_vma) addend;
  398. switch (r_type)
  399. {
  400. default:
  401. #ifdef DEBUG
  402. _bfd_error_handler ("%pB: unsupported relocation type %#x",
  403. abfd, r_type);
  404. #endif
  405. return bfd_reloc_notsupported;
  406. case R_V850_REL32:
  407. case R_V850_ABS32:
  408. case R_V810_WORD:
  409. case R_V850_PC32:
  410. bfd_put_32 (abfd, addend, address);
  411. return bfd_reloc_ok;
  412. case R_V850_WLO23:
  413. case R_V850_23:
  414. insn = bfd_get_32 (abfd, address);
  415. insn &= ~((0x7f << 4) | (0x7fff80 << (16-7)));
  416. insn |= ((addend & 0x7f) << 4) | ((addend & 0x7fff80) << (16-7));
  417. bfd_put_32 (abfd, (bfd_vma) insn, address);
  418. return bfd_reloc_ok;
  419. case R_V850_PCR22:
  420. case R_V850_22_PCREL:
  421. if (saddend > 0x1fffff || saddend < -0x200000)
  422. return bfd_reloc_overflow;
  423. if ((addend % 2) != 0)
  424. return bfd_reloc_dangerous;
  425. insn = bfd_get_32 (abfd, address);
  426. insn &= ~0xfffe003f;
  427. insn |= (((addend & 0xfffe) << 16) | ((addend & 0x3f0000) >> 16));
  428. bfd_put_32 (abfd, (bfd_vma) insn, address);
  429. return bfd_reloc_ok;
  430. case R_V850_PC17:
  431. case R_V850_17_PCREL:
  432. if (saddend > 0xffff || saddend < -0x10000)
  433. return bfd_reloc_overflow;
  434. if ((addend % 2) != 0)
  435. return bfd_reloc_dangerous;
  436. insn = bfd_get_32 (abfd, address);
  437. insn &= ~ 0xfffe0010;
  438. insn |= ((addend & 0xfffe) << 16) | ((addend & 0x10000) >> (16-4));
  439. break;
  440. case R_V850_PC16U:
  441. case R_V850_16_PCREL:
  442. if ((saddend < -0xffff) || (saddend > 0))
  443. return bfd_reloc_overflow;
  444. if ((addend % 2) != 0)
  445. return bfd_reloc_dangerous;
  446. insn = bfd_get_16 (abfd, address);
  447. insn &= ~0xfffe;
  448. insn |= (-addend & 0xfffe);
  449. break;
  450. case R_V850_PC9:
  451. case R_V850_9_PCREL:
  452. if (saddend > 0xff || saddend < -0x100)
  453. return bfd_reloc_overflow;
  454. if ((addend % 2) != 0)
  455. return bfd_reloc_dangerous;
  456. insn = bfd_get_16 (abfd, address);
  457. insn &= ~ 0xf870;
  458. insn |= ((addend & 0x1f0) << 7) | ((addend & 0x0e) << 3);
  459. break;
  460. case R_V810_WHI:
  461. case R_V850_HI16:
  462. addend += (bfd_get_16 (abfd, address) << 16);
  463. addend = (addend >> 16);
  464. insn = addend;
  465. break;
  466. case R_V810_WHI1:
  467. case R_V850_HI16_S:
  468. /* Remember where this relocation took place. */
  469. remember_hi16s_reloc (abfd, addend, address);
  470. addend += (bfd_get_16 (abfd, address) << 16);
  471. addend = (addend >> 16) + ((addend & 0x8000) != 0);
  472. /* This relocation cannot overflow. */
  473. if (addend > 0xffff)
  474. addend = 0;
  475. insn = addend;
  476. break;
  477. case R_V810_WLO:
  478. case R_V850_LO16:
  479. insn = bfd_get_16 (abfd, address);
  480. if (! v850_elf_perform_lo16_relocation (abfd, &insn, addend))
  481. return bfd_reloc_overflow;
  482. break;
  483. case R_V810_BYTE:
  484. case R_V850_8:
  485. addend += (char) bfd_get_8 (abfd, address);
  486. saddend = (bfd_signed_vma) addend;
  487. if (saddend > 0x7f || saddend < -0x80)
  488. return bfd_reloc_overflow;
  489. bfd_put_8 (abfd, addend, address);
  490. return bfd_reloc_ok;
  491. case R_V850_CALLT_16_16_OFFSET:
  492. addend += bfd_get_16 (abfd, address);
  493. saddend = (bfd_signed_vma) addend;
  494. if (saddend > 0xffff || saddend < 0)
  495. return bfd_reloc_overflow;
  496. insn = addend;
  497. break;
  498. case R_V850_CALLT_15_16_OFFSET:
  499. insn = bfd_get_16 (abfd, address);
  500. addend += insn & 0xfffe;
  501. saddend = (bfd_signed_vma) addend;
  502. if (saddend > 0xffff || saddend < 0)
  503. return bfd_reloc_overflow;
  504. insn = (0xfffe & addend)
  505. | (insn & ~0xfffe);
  506. break;
  507. case R_V850_CALLT_6_7_OFFSET:
  508. insn = bfd_get_16 (abfd, address);
  509. addend += ((insn & 0x3f) << 1);
  510. saddend = (bfd_signed_vma) addend;
  511. if (saddend > 0x7e || saddend < 0)
  512. return bfd_reloc_overflow;
  513. if (addend & 1)
  514. return bfd_reloc_dangerous;
  515. insn &= 0xff80;
  516. insn |= (addend >> 1);
  517. break;
  518. case R_V850_16:
  519. case R_V810_HWORD:
  520. case R_V850_SDA_16_16_OFFSET:
  521. case R_V850_ZDA_16_16_OFFSET:
  522. case R_V850_TDA_16_16_OFFSET:
  523. addend += bfd_get_16 (abfd, address);
  524. saddend = (bfd_signed_vma) addend;
  525. if (saddend > 0x7fff || saddend < -0x8000)
  526. return bfd_reloc_overflow;
  527. insn = addend;
  528. break;
  529. case R_V850_16_S1:
  530. case R_V850_SDA_15_16_OFFSET:
  531. case R_V850_ZDA_15_16_OFFSET:
  532. case R_V810_GPWLO_1:
  533. insn = bfd_get_16 (abfd, address);
  534. addend += (insn & 0xfffe);
  535. saddend = (bfd_signed_vma) addend;
  536. if (saddend > 0x7ffe || saddend < -0x8000)
  537. return bfd_reloc_overflow;
  538. if (addend & 1)
  539. return bfd_reloc_dangerous;
  540. insn = (addend &~ (bfd_vma) 1) | (insn & 1);
  541. break;
  542. case R_V850_TDA_6_8_OFFSET:
  543. insn = bfd_get_16 (abfd, address);
  544. addend += ((insn & 0x7e) << 1);
  545. saddend = (bfd_signed_vma) addend;
  546. if (saddend > 0xfc || saddend < 0)
  547. return bfd_reloc_overflow;
  548. if (addend & 3)
  549. return bfd_reloc_dangerous;
  550. insn &= 0xff81;
  551. insn |= (addend >> 1);
  552. break;
  553. case R_V850_TDA_7_8_OFFSET:
  554. insn = bfd_get_16 (abfd, address);
  555. addend += ((insn & 0x7f) << 1);
  556. saddend = (bfd_signed_vma) addend;
  557. if (saddend > 0xfe || saddend < 0)
  558. return bfd_reloc_overflow;
  559. if (addend & 1)
  560. return bfd_reloc_dangerous;
  561. insn &= 0xff80;
  562. insn |= (addend >> 1);
  563. break;
  564. case R_V850_TDA_7_7_OFFSET:
  565. insn = bfd_get_16 (abfd, address);
  566. addend += insn & 0x7f;
  567. saddend = (bfd_signed_vma) addend;
  568. if (saddend > 0x7f || saddend < 0)
  569. return bfd_reloc_overflow;
  570. insn &= 0xff80;
  571. insn |= addend;
  572. break;
  573. case R_V850_TDA_4_5_OFFSET:
  574. insn = bfd_get_16 (abfd, address);
  575. addend += ((insn & 0xf) << 1);
  576. saddend = (bfd_signed_vma) addend;
  577. if (saddend > 0x1e || saddend < 0)
  578. return bfd_reloc_overflow;
  579. if (addend & 1)
  580. return bfd_reloc_dangerous;
  581. insn &= 0xfff0;
  582. insn |= (addend >> 1);
  583. break;
  584. case R_V850_TDA_4_4_OFFSET:
  585. insn = bfd_get_16 (abfd, address);
  586. addend += insn & 0xf;
  587. saddend = (bfd_signed_vma) addend;
  588. if (saddend > 0xf || saddend < 0)
  589. return bfd_reloc_overflow;
  590. insn &= 0xfff0;
  591. insn |= addend;
  592. break;
  593. case R_V810_WLO_1:
  594. case R_V850_HWLO:
  595. case R_V850_HWLO_1:
  596. case R_V850_LO16_S1:
  597. insn = bfd_get_16 (abfd, address);
  598. result = insn & 0xfffe;
  599. if (! v850_elf_perform_lo16_relocation (abfd, &result, addend))
  600. return bfd_reloc_overflow;
  601. if (result & 1)
  602. return bfd_reloc_overflow;
  603. insn = (result & 0xfffe)
  604. | (insn & ~0xfffe);
  605. bfd_put_16 (abfd, insn, address);
  606. return bfd_reloc_ok;
  607. case R_V850_BLO:
  608. case R_V850_LO16_SPLIT_OFFSET:
  609. insn = bfd_get_32 (abfd, address);
  610. result = ((insn & 0xfffe0000) >> 16) | ((insn & 0x20) >> 5);
  611. if (! v850_elf_perform_lo16_relocation (abfd, &result, addend))
  612. return bfd_reloc_overflow;
  613. insn = (((result << 16) & 0xfffe0000)
  614. | ((result << 5) & 0x20)
  615. | (insn & ~0xfffe0020));
  616. bfd_put_32 (abfd, insn, address);
  617. return bfd_reloc_ok;
  618. case R_V850_16_SPLIT_OFFSET:
  619. case R_V850_SDA_16_16_SPLIT_OFFSET:
  620. case R_V850_ZDA_16_16_SPLIT_OFFSET:
  621. insn = bfd_get_32 (abfd, address);
  622. addend += ((insn & 0xfffe0000) >> 16) + ((insn & 0x20) >> 5);
  623. saddend = (bfd_signed_vma) addend;
  624. if (saddend > 0x7fff || saddend < -0x8000)
  625. return bfd_reloc_overflow;
  626. insn &= 0x0001ffdf;
  627. insn |= (addend & 1) << 5;
  628. insn |= (addend &~ (bfd_vma) 1) << 16;
  629. bfd_put_32 (abfd, (bfd_vma) insn, address);
  630. return bfd_reloc_ok;
  631. case R_V850_GNU_VTINHERIT:
  632. case R_V850_GNU_VTENTRY:
  633. return bfd_reloc_ok;
  634. }
  635. bfd_put_16 (abfd, (bfd_vma) insn, address);
  636. return bfd_reloc_ok;
  637. }
  638. /* Insert the addend into the instruction. */
  639. static bfd_reloc_status_type
  640. v850_elf_reloc (bfd *abfd ATTRIBUTE_UNUSED,
  641. arelent *reloc,
  642. asymbol *symbol,
  643. void * data ATTRIBUTE_UNUSED,
  644. asection *isection,
  645. bfd *obfd,
  646. char **err ATTRIBUTE_UNUSED)
  647. {
  648. long relocation;
  649. /* If there is an output BFD,
  650. and the symbol is not a section name (which is only defined at final link time),
  651. and either we are not putting the addend into the instruction
  652. or the addend is zero, so there is nothing to add into the instruction
  653. then just fixup the address and return. */
  654. if (obfd != NULL
  655. && (symbol->flags & BSF_SECTION_SYM) == 0
  656. && (! reloc->howto->partial_inplace
  657. || reloc->addend == 0))
  658. {
  659. reloc->address += isection->output_offset;
  660. return bfd_reloc_ok;
  661. }
  662. /* Catch relocs involving undefined symbols. */
  663. if (bfd_is_und_section (symbol->section)
  664. && (symbol->flags & BSF_WEAK) == 0
  665. && obfd == NULL)
  666. return bfd_reloc_undefined;
  667. /* We handle final linking of some relocs ourselves. */
  668. /* Is the address of the relocation really within the section? */
  669. if (reloc->address > bfd_get_section_limit (abfd, isection))
  670. return bfd_reloc_outofrange;
  671. /* Work out which section the relocation is targeted at and the
  672. initial relocation command value. */
  673. if (reloc->howto->pc_relative)
  674. return bfd_reloc_ok;
  675. /* Get symbol value. (Common symbols are special.) */
  676. if (bfd_is_com_section (symbol->section))
  677. relocation = 0;
  678. else
  679. relocation = symbol->value;
  680. /* Convert input-section-relative symbol value to absolute + addend. */
  681. relocation += symbol->section->output_section->vma;
  682. relocation += symbol->section->output_offset;
  683. relocation += reloc->addend;
  684. reloc->addend = relocation;
  685. return bfd_reloc_ok;
  686. }
  687. /* This function is used for relocs which are only used
  688. for relaxing, which the linker should otherwise ignore. */
  689. static bfd_reloc_status_type
  690. v850_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED,
  691. arelent *reloc_entry,
  692. asymbol *symbol ATTRIBUTE_UNUSED,
  693. void * data ATTRIBUTE_UNUSED,
  694. asection *input_section,
  695. bfd *output_bfd,
  696. char **error_message ATTRIBUTE_UNUSED)
  697. {
  698. if (output_bfd != NULL)
  699. reloc_entry->address += input_section->output_offset;
  700. return bfd_reloc_ok;
  701. }
  702. /* Note: It is REQUIRED that the 'type' value of each entry
  703. in this array match the index of the entry in the array.
  704. SeeAlso: RELOC_NUBMER in include/elf/v850.h. */
  705. static reloc_howto_type v850_elf_howto_table[] =
  706. {
  707. /* This reloc does nothing. */
  708. HOWTO (R_V850_NONE, /* Type. */
  709. 0, /* Rightshift. */
  710. 3, /* Size (0 = byte, 1 = short, 2 = long). */
  711. 0, /* Bitsize. */
  712. false, /* PC_relative. */
  713. 0, /* Bitpos. */
  714. complain_overflow_dont, /* Complain_on_overflow. */
  715. bfd_elf_generic_reloc, /* Special_function. */
  716. "R_V850_NONE", /* Name. */
  717. false, /* Partial_inplace. */
  718. 0, /* Src_mask. */
  719. 0, /* Dst_mask. */
  720. false), /* PCrel_offset. */
  721. /* A PC relative 9 bit branch. */
  722. HOWTO (R_V850_9_PCREL, /* Type. */
  723. 0, /* Rightshift. */
  724. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  725. 9, /* Bitsize. */
  726. true, /* PC_relative. */
  727. 0, /* Bitpos. */
  728. complain_overflow_bitfield, /* Complain_on_overflow. */
  729. v850_elf_reloc, /* Special_function. */
  730. "R_V850_9_PCREL", /* Name. */
  731. false, /* Partial_inplace. */
  732. 0x00ffffff, /* Src_mask. */
  733. 0x00ffffff, /* Dst_mask. */
  734. true), /* PCrel_offset. */
  735. /* A PC relative 22 bit branch. */
  736. HOWTO (R_V850_22_PCREL, /* Type. */
  737. 0, /* Rightshift. */
  738. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  739. 22, /* Bitsize. */
  740. true, /* PC_relative. */
  741. 0, /* Bitpos. */
  742. complain_overflow_signed, /* Complain_on_overflow. */
  743. v850_elf_reloc, /* Special_function. */
  744. "R_V850_22_PCREL", /* Name. */
  745. false, /* Partial_inplace. */
  746. 0x07ffff80, /* Src_mask. */
  747. 0x07ffff80, /* Dst_mask. */
  748. true), /* PCrel_offset. */
  749. /* High 16 bits of symbol value. */
  750. HOWTO (R_V850_HI16_S, /* Type. */
  751. 0, /* Rightshift. */
  752. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  753. 16, /* Bitsize. */
  754. false, /* PC_relative. */
  755. 0, /* Bitpos. */
  756. complain_overflow_dont, /* Complain_on_overflow. */
  757. v850_elf_reloc, /* Special_function. */
  758. "R_V850_HI16_S", /* Name. */
  759. false, /* Partial_inplace. */
  760. 0xffff, /* Src_mask. */
  761. 0xffff, /* Dst_mask. */
  762. false), /* PCrel_offset. */
  763. /* High 16 bits of symbol value. */
  764. HOWTO (R_V850_HI16, /* Type. */
  765. 0, /* Rightshift. */
  766. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  767. 16, /* Bitsize. */
  768. false, /* PC_relative. */
  769. 0, /* Bitpos. */
  770. complain_overflow_dont, /* Complain_on_overflow. */
  771. v850_elf_reloc, /* Special_function. */
  772. "R_V850_HI16", /* Name. */
  773. false, /* Partial_inplace. */
  774. 0xffff, /* Src_mask. */
  775. 0xffff, /* Dst_mask. */
  776. false), /* PCrel_offset. */
  777. /* Low 16 bits of symbol value. */
  778. HOWTO (R_V850_LO16, /* Type. */
  779. 0, /* Rightshift. */
  780. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  781. 16, /* Bitsize. */
  782. false, /* PC_relative. */
  783. 0, /* Bitpos. */
  784. complain_overflow_dont, /* Complain_on_overflow. */
  785. v850_elf_reloc, /* Special_function. */
  786. "R_V850_LO16", /* Name. */
  787. false, /* Partial_inplace. */
  788. 0xffff, /* Src_mask. */
  789. 0xffff, /* Dst_mask. */
  790. false), /* PCrel_offset. */
  791. /* Simple 32bit reloc. */
  792. HOWTO (R_V850_ABS32, /* Type. */
  793. 0, /* Rightshift. */
  794. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  795. 32, /* Bitsize. */
  796. false, /* PC_relative. */
  797. 0, /* Bitpos. */
  798. complain_overflow_dont, /* Complain_on_overflow. */
  799. v850_elf_reloc, /* Special_function. */
  800. "R_V850_ABS32", /* Name. */
  801. false, /* Partial_inplace. */
  802. 0xffffffff, /* Src_mask. */
  803. 0xffffffff, /* Dst_mask. */
  804. false), /* PCrel_offset. */
  805. /* Simple 16bit reloc. */
  806. HOWTO (R_V850_16, /* Type. */
  807. 0, /* Rightshift. */
  808. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  809. 16, /* Bitsize. */
  810. false, /* PC_relative. */
  811. 0, /* Bitpos. */
  812. complain_overflow_dont, /* Complain_on_overflow. */
  813. bfd_elf_generic_reloc, /* Special_function. */
  814. "R_V850_16", /* Name. */
  815. false, /* Partial_inplace. */
  816. 0xffff, /* Src_mask. */
  817. 0xffff, /* Dst_mask. */
  818. false), /* PCrel_offset. */
  819. /* Simple 8bit reloc. */
  820. HOWTO (R_V850_8, /* Type. */
  821. 0, /* Rightshift. */
  822. 0, /* Size (0 = byte, 1 = short, 2 = long). */
  823. 8, /* Bitsize. */
  824. false, /* PC_relative. */
  825. 0, /* Bitpos. */
  826. complain_overflow_dont, /* Complain_on_overflow. */
  827. bfd_elf_generic_reloc, /* Special_function. */
  828. "R_V850_8", /* Name. */
  829. false, /* Partial_inplace. */
  830. 0xff, /* Src_mask. */
  831. 0xff, /* Dst_mask. */
  832. false), /* PCrel_offset. */
  833. /* 16 bit offset from the short data area pointer. */
  834. HOWTO (R_V850_SDA_16_16_OFFSET, /* Type. */
  835. 0, /* Rightshift. */
  836. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  837. 16, /* Bitsize. */
  838. false, /* PC_relative. */
  839. 0, /* Bitpos. */
  840. complain_overflow_dont, /* Complain_on_overflow. */
  841. v850_elf_reloc, /* Special_function. */
  842. "R_V850_SDA_16_16_OFFSET", /* Name. */
  843. false, /* Partial_inplace. */
  844. 0xffff, /* Src_mask. */
  845. 0xffff, /* Dst_mask. */
  846. false), /* PCrel_offset. */
  847. /* 15 bit offset from the short data area pointer. */
  848. HOWTO (R_V850_SDA_15_16_OFFSET, /* Type. */
  849. 1, /* Rightshift. */
  850. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  851. 16, /* Bitsize. */
  852. false, /* PC_relative. */
  853. 1, /* Bitpos. */
  854. complain_overflow_dont, /* Complain_on_overflow. */
  855. v850_elf_reloc, /* Special_function. */
  856. "R_V850_SDA_15_16_OFFSET", /* Name. */
  857. false, /* Partial_inplace. */
  858. 0xfffe, /* Src_mask. */
  859. 0xfffe, /* Dst_mask. */
  860. false), /* PCrel_offset. */
  861. /* 16 bit offset from the zero data area pointer. */
  862. HOWTO (R_V850_ZDA_16_16_OFFSET, /* Type. */
  863. 0, /* Rightshift. */
  864. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  865. 16, /* Bitsize. */
  866. false, /* PC_relative. */
  867. 0, /* Bitpos. */
  868. complain_overflow_dont, /* Complain_on_overflow. */
  869. v850_elf_reloc, /* Special_function. */
  870. "R_V850_ZDA_16_16_OFFSET", /* Name. */
  871. false, /* Partial_inplace. */
  872. 0xffff, /* Src_mask. */
  873. 0xffff, /* Dst_mask. */
  874. false), /* PCrel_offset. */
  875. /* 15 bit offset from the zero data area pointer. */
  876. HOWTO (R_V850_ZDA_15_16_OFFSET, /* Type. */
  877. 1, /* Rightshift. */
  878. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  879. 16, /* Bitsize. */
  880. false, /* PC_relative. */
  881. 1, /* Bitpos. */
  882. complain_overflow_dont, /* Complain_on_overflow. */
  883. v850_elf_reloc, /* Special_function. */
  884. "R_V850_ZDA_15_16_OFFSET", /* Name. */
  885. false, /* Partial_inplace. */
  886. 0xfffe, /* Src_mask. */
  887. 0xfffe, /* Dst_mask. */
  888. false), /* PCrel_offset. */
  889. /* 6 bit offset from the tiny data area pointer. */
  890. HOWTO (R_V850_TDA_6_8_OFFSET, /* Type. */
  891. 2, /* Rightshift. */
  892. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  893. 8, /* Bitsize. */
  894. false, /* PC_relative. */
  895. 1, /* Bitpos. */
  896. complain_overflow_dont, /* Complain_on_overflow. */
  897. v850_elf_reloc, /* Special_function. */
  898. "R_V850_TDA_6_8_OFFSET", /* Name. */
  899. false, /* Partial_inplace. */
  900. 0x7e, /* Src_mask. */
  901. 0x7e, /* Dst_mask. */
  902. false), /* PCrel_offset. */
  903. /* 8 bit offset from the tiny data area pointer. */
  904. HOWTO (R_V850_TDA_7_8_OFFSET, /* Type. */
  905. 1, /* Rightshift. */
  906. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  907. 8, /* Bitsize. */
  908. false, /* PC_relative. */
  909. 0, /* Bitpos. */
  910. complain_overflow_dont, /* Complain_on_overflow. */
  911. v850_elf_reloc, /* Special_function. */
  912. "R_V850_TDA_7_8_OFFSET", /* Name. */
  913. false, /* Partial_inplace. */
  914. 0x7f, /* Src_mask. */
  915. 0x7f, /* Dst_mask. */
  916. false), /* PCrel_offset. */
  917. /* 7 bit offset from the tiny data area pointer. */
  918. HOWTO (R_V850_TDA_7_7_OFFSET, /* Type. */
  919. 0, /* Rightshift. */
  920. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  921. 7, /* Bitsize. */
  922. false, /* PC_relative. */
  923. 0, /* Bitpos. */
  924. complain_overflow_dont, /* Complain_on_overflow. */
  925. v850_elf_reloc, /* Special_function. */
  926. "R_V850_TDA_7_7_OFFSET", /* Name. */
  927. false, /* Partial_inplace. */
  928. 0x7f, /* Src_mask. */
  929. 0x7f, /* Dst_mask. */
  930. false), /* PCrel_offset. */
  931. /* 16 bit offset from the tiny data area pointer! */
  932. HOWTO (R_V850_TDA_16_16_OFFSET, /* Type. */
  933. 0, /* Rightshift. */
  934. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  935. 16, /* Bitsize. */
  936. false, /* PC_relative. */
  937. 0, /* Bitpos. */
  938. complain_overflow_dont, /* Complain_on_overflow. */
  939. v850_elf_reloc, /* Special_function. */
  940. "R_V850_TDA_16_16_OFFSET", /* Name. */
  941. false, /* Partial_inplace. */
  942. 0xffff, /* Src_mask. */
  943. 0xfff, /* Dst_mask. */
  944. false), /* PCrel_offset. */
  945. /* 5 bit offset from the tiny data area pointer. */
  946. HOWTO (R_V850_TDA_4_5_OFFSET, /* Type. */
  947. 1, /* Rightshift. */
  948. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  949. 5, /* Bitsize. */
  950. false, /* PC_relative. */
  951. 0, /* Bitpos. */
  952. complain_overflow_dont, /* Complain_on_overflow. */
  953. v850_elf_reloc, /* Special_function. */
  954. "R_V850_TDA_4_5_OFFSET", /* Name. */
  955. false, /* Partial_inplace. */
  956. 0x0f, /* Src_mask. */
  957. 0x0f, /* Dst_mask. */
  958. false), /* PCrel_offset. */
  959. /* 4 bit offset from the tiny data area pointer. */
  960. HOWTO (R_V850_TDA_4_4_OFFSET, /* Type. */
  961. 0, /* Rightshift. */
  962. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  963. 4, /* Bitsize. */
  964. false, /* PC_relative. */
  965. 0, /* Bitpos. */
  966. complain_overflow_dont, /* Complain_on_overflow. */
  967. v850_elf_reloc, /* Special_function. */
  968. "R_V850_TDA_4_4_OFFSET", /* Name. */
  969. false, /* Partial_inplace. */
  970. 0x0f, /* Src_mask. */
  971. 0x0f, /* Dst_mask. */
  972. false), /* PCrel_offset. */
  973. /* 16 bit offset from the short data area pointer. */
  974. HOWTO (R_V850_SDA_16_16_SPLIT_OFFSET, /* Type. */
  975. 0, /* Rightshift. */
  976. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  977. 16, /* Bitsize. */
  978. false, /* PC_relative. */
  979. 0, /* Bitpos. */
  980. complain_overflow_dont, /* Complain_on_overflow. */
  981. v850_elf_reloc, /* Special_function. */
  982. "R_V850_SDA_16_16_SPLIT_OFFSET",/* Name. */
  983. false, /* Partial_inplace. */
  984. 0xfffe0020, /* Src_mask. */
  985. 0xfffe0020, /* Dst_mask. */
  986. false), /* PCrel_offset. */
  987. /* 16 bit offset from the zero data area pointer. */
  988. HOWTO (R_V850_ZDA_16_16_SPLIT_OFFSET, /* Type. */
  989. 0, /* Rightshift. */
  990. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  991. 16, /* Bitsize. */
  992. false, /* PC_relative. */
  993. 0, /* Bitpos. */
  994. complain_overflow_dont, /* Complain_on_overflow. */
  995. v850_elf_reloc, /* Special_function. */
  996. "R_V850_ZDA_16_16_SPLIT_OFFSET",/* Name. */
  997. false, /* Partial_inplace. */
  998. 0xfffe0020, /* Src_mask. */
  999. 0xfffe0020, /* Dst_mask. */
  1000. false), /* PCrel_offset. */
  1001. /* 6 bit offset from the call table base pointer. */
  1002. HOWTO (R_V850_CALLT_6_7_OFFSET, /* Type. */
  1003. 0, /* Rightshift. */
  1004. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  1005. 7, /* Bitsize. */
  1006. false, /* PC_relative. */
  1007. 0, /* Bitpos. */
  1008. complain_overflow_dont, /* Complain_on_overflow. */
  1009. v850_elf_reloc, /* Special_function. */
  1010. "R_V850_CALLT_6_7_OFFSET", /* Name. */
  1011. false, /* Partial_inplace. */
  1012. 0x3f, /* Src_mask. */
  1013. 0x3f, /* Dst_mask. */
  1014. false), /* PCrel_offset. */
  1015. /* 16 bit offset from the call table base pointer. */
  1016. HOWTO (R_V850_CALLT_16_16_OFFSET, /* Type. */
  1017. 0, /* Rightshift. */
  1018. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  1019. 16, /* Bitsize. */
  1020. false, /* PC_relative. */
  1021. 0, /* Bitpos. */
  1022. complain_overflow_dont, /* Complain_on_overflow. */
  1023. v850_elf_reloc, /* Special_function. */
  1024. "R_V850_CALLT_16_16_OFFSET", /* Name. */
  1025. false, /* Partial_inplace. */
  1026. 0xffff, /* Src_mask. */
  1027. 0xffff, /* Dst_mask. */
  1028. false), /* PCrel_offset. */
  1029. /* GNU extension to record C++ vtable hierarchy */
  1030. HOWTO (R_V850_GNU_VTINHERIT, /* Type. */
  1031. 0, /* Rightshift. */
  1032. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  1033. 0, /* Bitsize. */
  1034. false, /* PC_relative. */
  1035. 0, /* Bitpos. */
  1036. complain_overflow_dont, /* Complain_on_overflow. */
  1037. NULL, /* Special_function. */
  1038. "R_V850_GNU_VTINHERIT", /* Name. */
  1039. false, /* Partial_inplace. */
  1040. 0, /* Src_mask. */
  1041. 0, /* Dst_mask. */
  1042. false), /* PCrel_offset. */
  1043. /* GNU extension to record C++ vtable member usage. */
  1044. HOWTO (R_V850_GNU_VTENTRY, /* Type. */
  1045. 0, /* Rightshift. */
  1046. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  1047. 0, /* Bitsize. */
  1048. false, /* PC_relative. */
  1049. 0, /* Bitpos. */
  1050. complain_overflow_dont, /* Complain_on_overflow. */
  1051. _bfd_elf_rel_vtable_reloc_fn, /* Special_function. */
  1052. "R_V850_GNU_VTENTRY", /* Name. */
  1053. false, /* Partial_inplace. */
  1054. 0, /* Src_mask. */
  1055. 0, /* Dst_mask. */
  1056. false), /* PCrel_offset. */
  1057. /* Indicates a .longcall pseudo-op. The compiler will generate a .longcall
  1058. pseudo-op when it finds a function call which can be relaxed. */
  1059. HOWTO (R_V850_LONGCALL, /* Type. */
  1060. 0, /* Rightshift. */
  1061. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  1062. 32, /* Bitsize. */
  1063. true, /* PC_relative. */
  1064. 0, /* Bitpos. */
  1065. complain_overflow_signed, /* Complain_on_overflow. */
  1066. v850_elf_ignore_reloc, /* Special_function. */
  1067. "R_V850_LONGCALL", /* Name. */
  1068. false, /* Partial_inplace. */
  1069. 0, /* Src_mask. */
  1070. 0, /* Dst_mask. */
  1071. true), /* PCrel_offset. */
  1072. /* Indicates a .longjump pseudo-op. The compiler will generate a
  1073. .longjump pseudo-op when it finds a branch which can be relaxed. */
  1074. HOWTO (R_V850_LONGJUMP, /* Type. */
  1075. 0, /* Rightshift. */
  1076. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  1077. 32, /* Bitsize. */
  1078. true, /* PC_relative. */
  1079. 0, /* Bitpos. */
  1080. complain_overflow_signed, /* Complain_on_overflow. */
  1081. v850_elf_ignore_reloc, /* Special_function. */
  1082. "R_V850_LONGJUMP", /* Name. */
  1083. false, /* Partial_inplace. */
  1084. 0, /* Src_mask. */
  1085. 0, /* Dst_mask. */
  1086. true), /* PCrel_offset. */
  1087. HOWTO (R_V850_ALIGN, /* Type. */
  1088. 0, /* Rightshift. */
  1089. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  1090. 0, /* Bitsize. */
  1091. false, /* PC_relative. */
  1092. 0, /* Bitpos. */
  1093. complain_overflow_unsigned, /* Complain_on_overflow. */
  1094. v850_elf_ignore_reloc, /* Special_function. */
  1095. "R_V850_ALIGN", /* Name. */
  1096. false, /* Partial_inplace. */
  1097. 0, /* Src_mask. */
  1098. 0, /* Dst_mask. */
  1099. true), /* PCrel_offset. */
  1100. /* Simple pc-relative 32bit reloc. */
  1101. HOWTO (R_V850_REL32, /* Type. */
  1102. 0, /* Rightshift. */
  1103. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  1104. 32, /* Bitsize. */
  1105. true, /* PC_relative. */
  1106. 0, /* Bitpos. */
  1107. complain_overflow_dont, /* Complain_on_overflow. */
  1108. v850_elf_reloc, /* Special_function. */
  1109. "R_V850_REL32", /* Name. */
  1110. false, /* Partial_inplace. */
  1111. 0xffffffff, /* Src_mask. */
  1112. 0xffffffff, /* Dst_mask. */
  1113. false), /* PCrel_offset. */
  1114. /* An ld.bu version of R_V850_LO16. */
  1115. HOWTO (R_V850_LO16_SPLIT_OFFSET, /* Type. */
  1116. 0, /* Rightshift. */
  1117. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  1118. 16, /* Bitsize. */
  1119. false, /* PC_relative. */
  1120. 0, /* Bitpos. */
  1121. complain_overflow_dont, /* Complain_on_overflow. */
  1122. v850_elf_reloc, /* Special_function. */
  1123. "R_V850_LO16_SPLIT_OFFSET", /* Name. */
  1124. false, /* Partial_inplace. */
  1125. 0xfffe0020, /* Src_mask. */
  1126. 0xfffe0020, /* Dst_mask. */
  1127. false), /* PCrel_offset. */
  1128. /* A unsigned PC relative 16 bit loop. */
  1129. HOWTO (R_V850_16_PCREL, /* Type. */
  1130. 0, /* Rightshift. */
  1131. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  1132. 16, /* Bitsize. */
  1133. true, /* PC_relative. */
  1134. 0, /* Bitpos. */
  1135. complain_overflow_bitfield, /* Complain_on_overflow. */
  1136. v850_elf_reloc, /* Special_function. */
  1137. "R_V850_16_PCREL", /* Name. */
  1138. false, /* Partial_inplace. */
  1139. 0xfffe, /* Src_mask. */
  1140. 0xfffe, /* Dst_mask. */
  1141. true), /* PCrel_offset. */
  1142. /* A PC relative 17 bit branch. */
  1143. HOWTO (R_V850_17_PCREL, /* Type. */
  1144. 0, /* Rightshift. */
  1145. 2, /* Size (0 = byte, 1 = short, 2 = long). */
  1146. 17, /* Bitsize. */
  1147. true, /* PC_relative. */
  1148. 0, /* Bitpos. */
  1149. complain_overflow_bitfield, /* Complain_on_overflow. */
  1150. v850_elf_reloc, /* Special_function. */
  1151. "R_V850_17_PCREL", /* Name. */
  1152. false, /* Partial_inplace. */
  1153. 0x0010fffe, /* Src_mask. */
  1154. 0x0010fffe, /* Dst_mask. */
  1155. true), /* PCrel_offset. */
  1156. /* A 23bit offset ld/st. */
  1157. HOWTO (R_V850_23, /* type. */
  1158. 0, /* rightshift. */
  1159. 2, /* size (0 = byte, 1 = short, 2 = long). */
  1160. 23, /* bitsize. */
  1161. false, /* pc_relative. */
  1162. 0, /* bitpos. */
  1163. complain_overflow_dont, /* complain_on_overflow. */
  1164. v850_elf_reloc, /* special_function. */
  1165. "R_V850_23", /* name. */
  1166. false, /* partial_inplace. */
  1167. 0xffff07f0, /* src_mask. */
  1168. 0xffff07f0, /* dst_mask. */
  1169. false), /* pcrel_offset. */
  1170. /* A PC relative 32 bit branch. */
  1171. HOWTO (R_V850_32_PCREL, /* type. */
  1172. 1, /* rightshift. */
  1173. 2, /* size (0 = byte, 1 = short, 2 = long). */
  1174. 32, /* bitsize. */
  1175. true, /* pc_relative. */
  1176. 1, /* bitpos. */
  1177. complain_overflow_signed, /* complain_on_overflow. */
  1178. v850_elf_reloc, /* special_function. */
  1179. "R_V850_32_PCREL", /* name. */
  1180. false, /* partial_inplace. */
  1181. 0xfffffffe, /* src_mask. */
  1182. 0xfffffffe, /* dst_mask. */
  1183. true), /* pcrel_offset. */
  1184. /* A absolute 32 bit branch. */
  1185. HOWTO (R_V850_32_ABS, /* type. */
  1186. 1, /* rightshift. */
  1187. 2, /* size (0 = byte, 1 = short, 2 = long). */
  1188. 32, /* bitsize. */
  1189. true, /* pc_relative. */
  1190. 1, /* bitpos. */
  1191. complain_overflow_signed, /* complain_on_overflow. */
  1192. v850_elf_reloc, /* special_function. */
  1193. "R_V850_32_ABS", /* name. */
  1194. false, /* partial_inplace. */
  1195. 0xfffffffe, /* src_mask. */
  1196. 0xfffffffe, /* dst_mask. */
  1197. false), /* pcrel_offset. */
  1198. /* High 16 bits of symbol value. */
  1199. HOWTO (R_V850_HI16, /* Type. */
  1200. 0, /* Rightshift. */
  1201. 1, /* Size (0 = byte, 1 = short, 2 = long). */
  1202. 16, /* Bitsize. */
  1203. false, /* PC_relative. */
  1204. 0, /* Bitpos. */
  1205. complain_overflow_dont, /* Complain_on_overflow. */
  1206. v850_elf_reloc, /* Special_function. */
  1207. "R_V850_HI16", /* Name. */
  1208. false, /* Partial_inplace. */
  1209. 0xffff, /* Src_mask. */
  1210. 0xffff, /* Dst_mask. */
  1211. false), /* PCrel_offset. */
  1212. /* Low 16 bits of symbol value. */
  1213. HOWTO (R_V850_16_S1, /* type. */
  1214. 1, /* rightshift. */
  1215. 1, /* size (0 = byte, 1 = short, 2 = long). */
  1216. 16, /* bitsize. */
  1217. false, /* pc_relative. */
  1218. 1, /* bitpos. */
  1219. complain_overflow_dont, /* complain_on_overflow. */
  1220. v850_elf_reloc, /* special_function. */
  1221. "R_V850_16_S1", /* name. */
  1222. false, /* partial_inplace. */
  1223. 0xfffe, /* src_mask. */
  1224. 0xfffe, /* dst_mask. */
  1225. false), /* pcrel_offset. */
  1226. /* Low 16 bits of symbol value. */
  1227. HOWTO (R_V850_LO16_S1, /* type. */
  1228. 1, /* rightshift. */
  1229. 1, /* size (0 = byte, 1 = short, 2 = long). */
  1230. 16, /* bitsize. */
  1231. false, /* pc_relative. */
  1232. 1, /* bitpos. */
  1233. complain_overflow_dont, /* complain_on_overflow. */
  1234. v850_elf_reloc, /* special_function. */
  1235. "R_V850_LO16_S1", /* name. */
  1236. false, /* partial_inplace. */
  1237. 0xfffe, /* src_mask. */
  1238. 0xfffe, /* dst_mask. */
  1239. false), /* pcrel_offset. */
  1240. /* 16 bit offset from the call table base pointer. */
  1241. HOWTO (R_V850_CALLT_15_16_OFFSET, /* type. */
  1242. 1, /* rightshift. */
  1243. 1, /* size (0 = byte, 1 = short, 2 = long). */
  1244. 16, /* bitsize. */
  1245. false, /* pc_relative. */
  1246. 1, /* bitpos. */
  1247. complain_overflow_dont, /* complain_on_overflow. */
  1248. v850_elf_reloc, /* special_function. */
  1249. "R_V850_CALLT_15_16_OFFSET", /* name. */
  1250. false, /* partial_inplace. */
  1251. 0xfffe, /* src_mask. */
  1252. 0xfffe, /* dst_mask. */
  1253. false), /* pcrel_offset. */
  1254. /* Like R_V850_32 PCREL, but referring to the GOT table entry for
  1255. the symbol. */
  1256. HOWTO (R_V850_32_GOTPCREL, /* type. */
  1257. 0, /* rightshift. */
  1258. 2, /* size (0 = byte, 1 = short, 2 = long). */
  1259. 32, /* bitsize. */
  1260. true, /* pc_relative. */
  1261. 0, /* bitpos. */
  1262. complain_overflow_unsigned, /* complain_on_overflow. */
  1263. v850_elf_reloc, /* special_function. */
  1264. "R_V850_32_GOTPCREL", /* name. */
  1265. false, /* partial_inplace. */
  1266. 0xffffffff, /* src_mask. */
  1267. 0xffffffff, /* dst_mask. */
  1268. true), /* pcrel_offset. */
  1269. /* Like R_V850_SDA_, but referring to the GOT table entry for
  1270. the symbol. */
  1271. HOWTO (R_V850_16_GOT, /* type. */
  1272. 0, /* rightshift. */
  1273. 2, /* size (0 = byte, 1 = short, 2 = long). */
  1274. 16, /* bitsize. */
  1275. false, /* pc_relative. */
  1276. 0, /* bitpos. */
  1277. complain_overflow_unsigned, /* complain_on_overflow. */
  1278. bfd_elf_generic_reloc, /* special_function. */
  1279. "R_V850_16_GOT", /* name. */
  1280. false, /* partial_inplace. */
  1281. 0xffff, /* src_mask. */
  1282. 0xffff, /* dst_mask. */
  1283. false), /* pcrel_offset. */
  1284. HOWTO (R_V850_32_GOT, /* type. */
  1285. 0, /* rightshift. */
  1286. 2, /* size (0 = byte, 1 = short, 2 = long). */
  1287. 32, /* bitsize. */
  1288. false, /* pc_relative. */
  1289. 0, /* bitpos. */
  1290. complain_overflow_unsigned, /* complain_on_overflow. */
  1291. bfd_elf_generic_reloc, /* special_function. */
  1292. "R_V850_32_GOT", /* name. */
  1293. false, /* partial_inplace. */
  1294. 0xffffffff, /* src_mask. */
  1295. 0xffffffff, /* dst_mask. */
  1296. false), /* pcrel_offset. */
  1297. /* Like R_V850_22_PCREL, but referring to the procedure linkage table
  1298. entry for the symbol. */
  1299. HOWTO (R_V850_22_PLT, /* type. */
  1300. 1, /* rightshift. */
  1301. 2, /* size (0 = byte, 1 = short, 2 = long). */
  1302. 22, /* bitsize. */
  1303. true, /* pc_relative. */
  1304. 7, /* bitpos. */
  1305. complain_overflow_signed, /* complain_on_overflow. */
  1306. bfd_elf_generic_reloc, /* special_function. */
  1307. "R_V850_22_PLT", /* name. */
  1308. false, /* partial_inplace. */
  1309. 0x07ffff80, /* src_mask. */
  1310. 0x07ffff80, /* dst_mask. */
  1311. true), /* pcrel_offset. */
  1312. HOWTO (R_V850_32_PLT, /* type. */
  1313. 1, /* rightshift. */
  1314. 2, /* size (0 = byte, 1 = short, 2 = long). */
  1315. 32, /* bitsize. */
  1316. true, /* pc_relative. */
  1317. 1, /* bitpos. */
  1318. complain_overflow_signed, /* complain_on_overflow. */
  1319. bfd_elf_generic_reloc, /* special_function. */
  1320. "R_V850_32_PLT", /* name. */
  1321. false, /* partial_inplace. */
  1322. 0xffffffff, /* src_mask. */
  1323. 0xffffffff, /* dst_mask. */
  1324. true), /* pcrel_offset. */
  1325. /* This is used only by the dynamic linker. The symbol should exist
  1326. both in the object being run and in some shared library. The
  1327. dynamic linker copies the data addressed by the symbol from the
  1328. shared library into the object, because the object being
  1329. run has to have the data at some particular address. */
  1330. HOWTO (R_V850_COPY, /* type. */
  1331. 0, /* rightshift. */
  1332. 2, /* size (0 = byte, 1 = short, 2 = long). */
  1333. 32, /* bitsize. */
  1334. false, /* pc_relative. */
  1335. 0, /* bitpos. */
  1336. complain_overflow_bitfield, /* complain_on_overflow. */
  1337. bfd_elf_generic_reloc, /* special_function. */
  1338. "R_V850_COPY", /* name. */
  1339. false, /* partial_inplace. */
  1340. 0xffffffff, /* src_mask. */
  1341. 0xffffffff, /* dst_mask. */
  1342. false), /* pcrel_offset. */
  1343. /* Like R_M32R_24, but used when setting global offset table
  1344. entries. */
  1345. HOWTO (R_V850_GLOB_DAT, /* type. */
  1346. 0, /* rightshift. */
  1347. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1348. 32, /* bitsize. */
  1349. false, /* pc_relative. */
  1350. 0, /* bitpos. */
  1351. complain_overflow_bitfield, /* complain_on_overflow. */
  1352. bfd_elf_generic_reloc, /* special_function. */
  1353. "R_V850_GLOB_DAT", /* name. */
  1354. false, /* partial_inplace. */
  1355. 0xffffffff, /* src_mask. */
  1356. 0xffffffff, /* dst_mask. */
  1357. false), /* pcrel_offset. */
  1358. /* Marks a procedure linkage table entry for a symbol. */
  1359. HOWTO (R_V850_JMP_SLOT, /* type. */
  1360. 0, /* rightshift. */
  1361. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1362. 32, /* bitsize. */
  1363. false, /* pc_relative. */
  1364. 0, /* bitpos. */
  1365. complain_overflow_bitfield, /* complain_on_overflow. */
  1366. bfd_elf_generic_reloc, /* special_function. */
  1367. "R_V850_JMP_SLOT", /* name. */
  1368. false, /* partial_inplace. */
  1369. 0xffffffff, /* src_mask. */
  1370. 0xffffffff, /* dst_mask. */
  1371. false), /* pcrel_offset. */
  1372. /* Used only by the dynamic linker. When the object is run, this
  1373. longword is set to the load address of the object, plus the
  1374. addend. */
  1375. HOWTO (R_V850_RELATIVE, /* type. */
  1376. 0, /* rightshift. */
  1377. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1378. 32, /* bitsize. */
  1379. false, /* pc_relative. */
  1380. 0, /* bitpos. */
  1381. complain_overflow_bitfield, /* complain_on_overflow. */
  1382. bfd_elf_generic_reloc, /* special_function. */
  1383. "R_V850_RELATIVE", /* name. */
  1384. false, /* partial_inplace. */
  1385. 0xffffffff, /* src_mask. */
  1386. 0xffffffff, /* dst_mask. */
  1387. false), /* pcrel_offset. */
  1388. HOWTO (R_V850_16_GOTOFF, /* type. */
  1389. 0, /* rightshift. */
  1390. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1391. 16, /* bitsize. */
  1392. false, /* pc_relative. */
  1393. 0, /* bitpos. */
  1394. complain_overflow_bitfield, /* complain_on_overflow. */
  1395. bfd_elf_generic_reloc, /* special_function. */
  1396. "R_V850_16_GOTOFF", /* name. */
  1397. false, /* partial_inplace. */
  1398. 0xffff, /* src_mask. */
  1399. 0xffff, /* dst_mask. */
  1400. false), /* pcrel_offset. */
  1401. HOWTO (R_V850_32_GOTOFF, /* type. */
  1402. 0, /* rightshift. */
  1403. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1404. 32, /* bitsize. */
  1405. false, /* pc_relative. */
  1406. 0, /* bitpos. */
  1407. complain_overflow_bitfield, /* complain_on_overflow. */
  1408. bfd_elf_generic_reloc, /* special_function. */
  1409. "R_V850_32_GOTOFF", /* name. */
  1410. false, /* partial_inplace. */
  1411. 0xffffffff, /* src_mask. */
  1412. 0xffffffff, /* dst_mask. */
  1413. false), /* pcrel_offset. */
  1414. HOWTO (R_V850_CODE, /* type. */
  1415. 0, /* rightshift. */
  1416. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1417. 0, /* bitsize. */
  1418. false, /* pc_relative. */
  1419. 0, /* bitpos. */
  1420. complain_overflow_unsigned, /* complain_on_overflow. */
  1421. v850_elf_ignore_reloc, /* special_function. */
  1422. "R_V850_CODE", /* name. */
  1423. false, /* partial_inplace. */
  1424. 0, /* src_mask. */
  1425. 0, /* dst_mask. */
  1426. true), /* pcrel_offset. */
  1427. HOWTO (R_V850_DATA, /* type. */
  1428. 0, /* rightshift. */
  1429. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1430. 0, /* bitsize. */
  1431. false, /* pc_relative. */
  1432. 0, /* bitpos. */
  1433. complain_overflow_unsigned, /* complain_on_overflow. */
  1434. v850_elf_ignore_reloc, /* special_function. */
  1435. "R_V850_DATA", /* name. */
  1436. false, /* partial_inplace. */
  1437. 0, /* src_mask. */
  1438. 0, /* dst_mask. */
  1439. true), /* pcrel_offset. */
  1440. };
  1441. /* Map BFD reloc types to V850 ELF reloc types. */
  1442. struct v850_elf_reloc_map
  1443. {
  1444. /* BFD_RELOC_V850_CALLT_16_16_OFFSET is 258, which will not fix in an
  1445. unsigned char. */
  1446. bfd_reloc_code_real_type bfd_reloc_val;
  1447. unsigned int elf_reloc_val;
  1448. };
  1449. static const struct v850_elf_reloc_map v850_elf_reloc_map[] =
  1450. {
  1451. { BFD_RELOC_NONE, R_V850_NONE },
  1452. { BFD_RELOC_V850_9_PCREL, R_V850_9_PCREL },
  1453. { BFD_RELOC_V850_22_PCREL, R_V850_22_PCREL },
  1454. { BFD_RELOC_HI16_S, R_V850_HI16_S },
  1455. { BFD_RELOC_HI16, R_V850_HI16 },
  1456. { BFD_RELOC_LO16, R_V850_LO16 },
  1457. { BFD_RELOC_32, R_V850_ABS32 },
  1458. { BFD_RELOC_32_PCREL, R_V850_REL32 },
  1459. { BFD_RELOC_16, R_V850_16 },
  1460. { BFD_RELOC_8, R_V850_8 },
  1461. { BFD_RELOC_V850_SDA_16_16_OFFSET, R_V850_SDA_16_16_OFFSET },
  1462. { BFD_RELOC_V850_SDA_15_16_OFFSET, R_V850_SDA_15_16_OFFSET },
  1463. { BFD_RELOC_V850_ZDA_16_16_OFFSET, R_V850_ZDA_16_16_OFFSET },
  1464. { BFD_RELOC_V850_ZDA_15_16_OFFSET, R_V850_ZDA_15_16_OFFSET },
  1465. { BFD_RELOC_V850_TDA_6_8_OFFSET, R_V850_TDA_6_8_OFFSET },
  1466. { BFD_RELOC_V850_TDA_7_8_OFFSET, R_V850_TDA_7_8_OFFSET },
  1467. { BFD_RELOC_V850_TDA_7_7_OFFSET, R_V850_TDA_7_7_OFFSET },
  1468. { BFD_RELOC_V850_TDA_16_16_OFFSET, R_V850_TDA_16_16_OFFSET },
  1469. { BFD_RELOC_V850_TDA_4_5_OFFSET, R_V850_TDA_4_5_OFFSET },
  1470. { BFD_RELOC_V850_TDA_4_4_OFFSET, R_V850_TDA_4_4_OFFSET },
  1471. { BFD_RELOC_V850_LO16_SPLIT_OFFSET, R_V850_LO16_SPLIT_OFFSET },
  1472. { BFD_RELOC_V850_SDA_16_16_SPLIT_OFFSET, R_V850_SDA_16_16_SPLIT_OFFSET },
  1473. { BFD_RELOC_V850_ZDA_16_16_SPLIT_OFFSET, R_V850_ZDA_16_16_SPLIT_OFFSET },
  1474. { BFD_RELOC_V850_CALLT_6_7_OFFSET, R_V850_CALLT_6_7_OFFSET },
  1475. { BFD_RELOC_V850_CALLT_16_16_OFFSET, R_V850_CALLT_16_16_OFFSET },
  1476. { BFD_RELOC_VTABLE_INHERIT, R_V850_GNU_VTINHERIT },
  1477. { BFD_RELOC_VTABLE_ENTRY, R_V850_GNU_VTENTRY },
  1478. { BFD_RELOC_V850_LONGCALL, R_V850_LONGCALL },
  1479. { BFD_RELOC_V850_LONGJUMP, R_V850_LONGJUMP },
  1480. { BFD_RELOC_V850_ALIGN, R_V850_ALIGN },
  1481. { BFD_RELOC_V850_16_PCREL, R_V850_16_PCREL },
  1482. { BFD_RELOC_V850_17_PCREL, R_V850_17_PCREL },
  1483. { BFD_RELOC_V850_23, R_V850_23 },
  1484. { BFD_RELOC_V850_32_PCREL, R_V850_32_PCREL },
  1485. { BFD_RELOC_V850_32_ABS, R_V850_32_ABS },
  1486. { BFD_RELOC_V850_16_SPLIT_OFFSET, R_V850_HI16 },
  1487. { BFD_RELOC_V850_16_S1, R_V850_16_S1 },
  1488. { BFD_RELOC_V850_LO16_S1, R_V850_LO16_S1 },
  1489. { BFD_RELOC_V850_CALLT_15_16_OFFSET, R_V850_CALLT_15_16_OFFSET },
  1490. { BFD_RELOC_V850_32_GOTPCREL, R_V850_32_GOTPCREL },
  1491. { BFD_RELOC_V850_16_GOT, R_V850_16_GOT },
  1492. { BFD_RELOC_V850_32_GOT, R_V850_32_GOT },
  1493. { BFD_RELOC_V850_22_PLT_PCREL, R_V850_22_PLT },
  1494. { BFD_RELOC_V850_32_PLT_PCREL, R_V850_32_PLT },
  1495. { BFD_RELOC_V850_COPY, R_V850_COPY },
  1496. { BFD_RELOC_V850_GLOB_DAT, R_V850_GLOB_DAT },
  1497. { BFD_RELOC_V850_JMP_SLOT, R_V850_JMP_SLOT },
  1498. { BFD_RELOC_V850_RELATIVE, R_V850_RELATIVE },
  1499. { BFD_RELOC_V850_16_GOTOFF, R_V850_16_GOTOFF },
  1500. { BFD_RELOC_V850_32_GOTOFF, R_V850_32_GOTOFF },
  1501. { BFD_RELOC_V850_CODE, R_V850_CODE },
  1502. { BFD_RELOC_V850_DATA, R_V850_DATA },
  1503. };
  1504. #define V800_RELOC(name,sz,bit,shift,complain,pcrel,resolver) \
  1505. HOWTO (name, shift, sz, bit, pcrel, 0, complain_overflow_ ## complain, \
  1506. bfd_elf_ ## resolver ## _reloc, #name, false, 0, ~0, false)
  1507. #define V800_EMPTY(name) EMPTY_HOWTO (name - R_V810_NONE)
  1508. #define bfd_elf_v850_reloc v850_elf_reloc
  1509. /* Note: It is REQUIRED that the 'type' value (R_V810_...) of each entry
  1510. in this array match the index of the entry in the array minus 0x30.
  1511. See: bfd_elf_v850_relocate_section(), v800_elf_reloc_type_lookup()
  1512. and v800_elf_info_to_howto(). */
  1513. static reloc_howto_type v800_elf_howto_table[] =
  1514. {
  1515. V800_RELOC (R_V810_NONE, 0, 0, 0, dont, false, generic), /* Type = 0x30 */
  1516. V800_RELOC (R_V810_BYTE, 0, 8, 0, dont, false, generic),
  1517. V800_RELOC (R_V810_HWORD, 1, 16, 0, dont, false, generic),
  1518. V800_RELOC (R_V810_WORD, 2, 32, 0, dont, false, generic),
  1519. V800_RELOC (R_V810_WLO, 1, 16, 0, dont, false, generic),
  1520. V800_RELOC (R_V810_WHI, 1, 16, 0, dont, false, generic),
  1521. V800_RELOC (R_V810_WHI1, 1, 16, 0, dont, false, generic),
  1522. V800_RELOC (R_V810_GPBYTE, 0, 8, 0, dont, false, v850),
  1523. V800_RELOC (R_V810_GPHWORD, 1, 16, 0, dont, false, v850),
  1524. V800_RELOC (R_V810_GPWORD, 2, 32, 0, dont, false, v850),
  1525. V800_RELOC (R_V810_GPWLO, 1, 16, 0, dont, false, v850),
  1526. V800_RELOC (R_V810_GPWHI, 1, 16, 0, dont, false, v850),
  1527. V800_RELOC (R_V810_GPWHI1, 1, 16, 0, dont, false, v850),
  1528. V800_RELOC (R_V850_HWLO, 1, 16, 0, dont, false, generic),
  1529. V800_EMPTY (R_V810_reserved1),
  1530. V800_RELOC (R_V850_EP7BIT, 0, 7, 0, unsigned, false, v850),
  1531. V800_RELOC (R_V850_EPHBYTE, 0, 8, 1, unsigned, false, v850),
  1532. V800_RELOC (R_V850_EPWBYTE, 0, 8, 2, unsigned, false, v850),
  1533. V800_RELOC (R_V850_REGHWLO, 1, 16, 0, dont, false, v850),
  1534. V800_EMPTY (R_V810_reserved2),
  1535. V800_RELOC (R_V850_GPHWLO, 1, 16, 0, dont, false, v850),
  1536. V800_EMPTY (R_V810_reserved3),
  1537. V800_RELOC (R_V850_PCR22, 2, 22, 0, signed, true, generic),
  1538. V800_RELOC (R_V850_BLO, 2, 24, 0, dont, false, v850),
  1539. V800_RELOC (R_V850_EP4BIT, 0, 4, 0, unsigned, false, v850),
  1540. V800_RELOC (R_V850_EP5BIT, 0, 5, 0, unsigned, false, v850),
  1541. V800_RELOC (R_V850_REGBLO, 2, 24, 0, dont, false, v850),
  1542. V800_RELOC (R_V850_GPBLO, 2, 24, 0, dont, false, v850),
  1543. V800_RELOC (R_V810_WLO_1, 1, 16, 0, dont, false, v850),
  1544. V800_RELOC (R_V810_GPWLO_1, 1, 16, 0, signed, false, v850),
  1545. V800_RELOC (R_V850_BLO_1, 2, 16, 0, signed, false, v850),
  1546. V800_RELOC (R_V850_HWLO_1, 1, 16, 0, signed, false, v850),
  1547. V800_EMPTY (R_V810_reserved4),
  1548. V800_RELOC (R_V850_GPBLO_1, 2, 16, 1, signed, false, v850),
  1549. V800_RELOC (R_V850_GPHWLO_1, 1, 16, 1, signed, false, v850),
  1550. V800_EMPTY (R_V810_reserved5),
  1551. V800_RELOC (R_V850_EPBLO, 2, 16, 1, signed, false, v850),
  1552. V800_RELOC (R_V850_EPHWLO, 1, 16, 1, signed, false, v850),
  1553. V800_EMPTY (R_V810_reserved6),
  1554. V800_RELOC (R_V850_EPWLO_N, 1, 16, 1, signed, false, v850),
  1555. V800_RELOC (R_V850_PC32, 2, 32, 1, signed, true, v850),
  1556. V800_RELOC (R_V850_W23BIT, 2, 23, 1, signed, false, v850),
  1557. V800_RELOC (R_V850_GPW23BIT, 2, 23, 1, signed, false, v850),
  1558. V800_RELOC (R_V850_EPW23BIT, 2, 23, 1, signed, false, v850),
  1559. V800_RELOC (R_V850_B23BIT, 2, 23, 1, signed, false, v850),
  1560. V800_RELOC (R_V850_GPB23BIT, 2, 23, 1, signed, false, v850),
  1561. V800_RELOC (R_V850_EPB23BIT, 2, 23, 1, signed, false, v850),
  1562. V800_RELOC (R_V850_PC16U, 1, 16, 1, unsigned, true, generic),
  1563. V800_RELOC (R_V850_PC17, 2, 17, 1, signed, true, generic),
  1564. V800_RELOC (R_V850_DW8, 2, 8, 2, signed, false, v850),
  1565. V800_RELOC (R_V850_GPDW8, 2, 8, 2, signed, false, v850),
  1566. V800_RELOC (R_V850_EPDW8, 2, 8, 2, signed, false, v850),
  1567. V800_RELOC (R_V850_PC9, 1, 9, 3, signed, true, v850),
  1568. V800_RELOC (R_V810_REGBYTE, 0, 8, 0, dont, false, v850),
  1569. V800_RELOC (R_V810_REGHWORD, 1, 16, 0, dont, false, v850),
  1570. V800_RELOC (R_V810_REGWORD, 2, 32, 0, dont, false, v850),
  1571. V800_RELOC (R_V810_REGWLO, 1, 16, 0, dont, false, v850),
  1572. V800_RELOC (R_V810_REGWHI, 1, 16, 0, dont, false, v850),
  1573. V800_RELOC (R_V810_REGWHI1, 1, 16, 0, dont, false, v850),
  1574. V800_RELOC (R_V850_REGW23BIT, 2, 23, 1, signed, false, v850),
  1575. V800_RELOC (R_V850_REGB23BIT, 2, 23, 1, signed, false, v850),
  1576. V800_RELOC (R_V850_REGDW8, 2, 8, 2, signed, false, v850),
  1577. V800_RELOC (R_V810_EPBYTE, 0, 8, 0, dont, false, v850),
  1578. V800_RELOC (R_V810_EPHWORD, 1, 16, 0, dont, false, v850),
  1579. V800_RELOC (R_V810_EPWORD, 2, 32, 0, dont, false, v850),
  1580. V800_RELOC (R_V850_WLO23, 2, 32, 1, dont, false, v850),
  1581. V800_RELOC (R_V850_WORD_E, 2, 32, 1, dont, false, v850),
  1582. V800_RELOC (R_V850_REGWORD_E, 2, 32, 1, dont, false, v850),
  1583. V800_RELOC (R_V850_WORD, 2, 32, 0, dont, false, v850),
  1584. V800_RELOC (R_V850_GPWORD, 2, 32, 0, dont, false, v850),
  1585. V800_RELOC (R_V850_REGWORD, 2, 32, 0, dont, false, v850),
  1586. V800_RELOC (R_V850_EPWORD, 2, 32, 0, dont, false, v850),
  1587. V800_RELOC (R_V810_TPBYTE, 0, 8, 0, dont, false, v850),
  1588. V800_RELOC (R_V810_TPHWORD, 1, 16, 0, dont, false, v850),
  1589. V800_RELOC (R_V810_TPWORD, 2, 32, 0, dont, false, v850),
  1590. V800_RELOC (R_V810_TPWLO, 1, 16, 0, dont, false, v850),
  1591. V800_RELOC (R_V810_TPWHI, 1, 16, 0, dont, false, v850),
  1592. V800_RELOC (R_V810_TPWHI1, 1, 16, 0, dont, false, v850),
  1593. V800_RELOC (R_V850_TPHWLO, 1, 16, 1, dont, false, v850),
  1594. V800_RELOC (R_V850_TPBLO, 2, 24, 0, dont, false, v850),
  1595. V800_RELOC (R_V810_TPWLO_1, 1, 16, 0, signed, false, v850),
  1596. V800_RELOC (R_V850_TPBLO_1, 2, 16, 0, signed, false, v850),
  1597. V800_RELOC (R_V850_TPHWLO_1, 1, 16, 0, signed, false, v850),
  1598. V800_RELOC (R_V850_TP23BIT, 2, 23, 0, signed, false, v850),
  1599. V800_RELOC (R_V850_TPW23BIT, 2, 23, 0, signed, false, v850),
  1600. V800_RELOC (R_V850_TPDW8, 2, 8, 0, signed, false, v850)
  1601. };
  1602. /* Map a bfd relocation into the appropriate howto structure. */
  1603. static reloc_howto_type *
  1604. v850_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1605. bfd_reloc_code_real_type code)
  1606. {
  1607. unsigned int i;
  1608. for (i = ARRAY_SIZE (v850_elf_reloc_map); i --;)
  1609. if (v850_elf_reloc_map[i].bfd_reloc_val == code)
  1610. {
  1611. unsigned int elf_reloc_val = v850_elf_reloc_map[i].elf_reloc_val;
  1612. BFD_ASSERT (v850_elf_howto_table[elf_reloc_val].type == elf_reloc_val);
  1613. return v850_elf_howto_table + elf_reloc_val;
  1614. }
  1615. return NULL;
  1616. }
  1617. static reloc_howto_type *
  1618. v850_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1619. const char *r_name)
  1620. {
  1621. unsigned int i;
  1622. for (i = 0;
  1623. i < sizeof (v850_elf_howto_table) / sizeof (v850_elf_howto_table[0]);
  1624. i++)
  1625. if (v850_elf_howto_table[i].name != NULL
  1626. && strcasecmp (v850_elf_howto_table[i].name, r_name) == 0)
  1627. return &v850_elf_howto_table[i];
  1628. return NULL;
  1629. }
  1630. /* Set the howto pointer for an V850 ELF reloc. */
  1631. static bool
  1632. v850_elf_info_to_howto_rel (bfd *abfd,
  1633. arelent *cache_ptr,
  1634. Elf_Internal_Rela *dst)
  1635. {
  1636. unsigned int r_type;
  1637. r_type = ELF32_R_TYPE (dst->r_info);
  1638. if (r_type >= (unsigned int) R_V850_max)
  1639. {
  1640. /* xgettext:c-format */
  1641. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  1642. abfd, r_type);
  1643. bfd_set_error (bfd_error_bad_value);
  1644. return false;
  1645. }
  1646. cache_ptr->howto = &v850_elf_howto_table[r_type];
  1647. return true;
  1648. }
  1649. /* Set the howto pointer for a V850 ELF reloc (type RELA). */
  1650. static bool
  1651. v850_elf_info_to_howto_rela (bfd *abfd,
  1652. arelent * cache_ptr,
  1653. Elf_Internal_Rela *dst)
  1654. {
  1655. unsigned int r_type;
  1656. r_type = ELF32_R_TYPE (dst->r_info);
  1657. if (r_type >= (unsigned int) R_V850_max)
  1658. {
  1659. /* xgettext:c-format */
  1660. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  1661. abfd, r_type);
  1662. bfd_set_error (bfd_error_bad_value);
  1663. return false;
  1664. }
  1665. cache_ptr->howto = &v850_elf_howto_table[r_type];
  1666. return true;
  1667. }
  1668. static bool
  1669. v850_elf_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name)
  1670. {
  1671. return ( (name[0] == '.' && (name[1] == 'L' || name[1] == '.'))
  1672. || (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_'));
  1673. }
  1674. static bool
  1675. v850_elf_is_target_special_symbol (bfd *abfd, asymbol *sym)
  1676. {
  1677. return v850_elf_is_local_label_name (abfd, sym->name);
  1678. }
  1679. /* We overload some of the bfd_reloc error codes for own purposes. */
  1680. #define bfd_reloc_gp_not_found bfd_reloc_other
  1681. #define bfd_reloc_ep_not_found bfd_reloc_continue
  1682. #define bfd_reloc_ctbp_not_found (bfd_reloc_dangerous + 1)
  1683. /* Perform a relocation as part of a final link. */
  1684. static bfd_reloc_status_type
  1685. v850_elf_final_link_relocate (reloc_howto_type *howto,
  1686. bfd *input_bfd,
  1687. bfd *output_bfd ATTRIBUTE_UNUSED,
  1688. asection *input_section,
  1689. bfd_byte *contents,
  1690. bfd_vma offset,
  1691. bfd_vma value,
  1692. bfd_vma addend,
  1693. struct bfd_link_info *info,
  1694. asection *sym_sec,
  1695. int is_local ATTRIBUTE_UNUSED)
  1696. {
  1697. unsigned int r_type = howto->type;
  1698. bfd_byte *hit_data = contents + offset;
  1699. /* Adjust the value according to the relocation. */
  1700. switch (r_type)
  1701. {
  1702. case R_V850_PC9:
  1703. case R_V850_9_PCREL:
  1704. value -= (input_section->output_section->vma
  1705. + input_section->output_offset);
  1706. value -= offset;
  1707. break;
  1708. case R_V850_PC16U:
  1709. case R_V850_16_PCREL:
  1710. value -= (input_section->output_section->vma
  1711. + input_section->output_offset
  1712. + offset);
  1713. /* If the sign extension will corrupt the value then we have overflowed. */
  1714. if ((value & 0xffff0000) != 0xffff0000)
  1715. return bfd_reloc_overflow;
  1716. break;
  1717. case R_V850_PC17:
  1718. case R_V850_17_PCREL:
  1719. value -= (input_section->output_section->vma
  1720. + input_section->output_offset
  1721. + offset);
  1722. /* If the sign extension will corrupt the value then we have overflowed. */
  1723. if (((value & 0xffff0000) != 0x0) && ((value & 0xffff0000) != 0xffff0000))
  1724. return bfd_reloc_overflow;
  1725. value = SEXT17 (value);
  1726. break;
  1727. case R_V850_PCR22:
  1728. case R_V850_22_PCREL:
  1729. value -= (input_section->output_section->vma
  1730. + input_section->output_offset
  1731. + offset);
  1732. /* If the sign extension will corrupt the value then we have overflowed. */
  1733. if (((value & 0xffe00000) != 0x0) && ((value & 0xffe00000) != 0xffe00000))
  1734. return bfd_reloc_overflow;
  1735. /* Only the bottom 22 bits of the PC are valid. */
  1736. value = SEXT22 (value);
  1737. break;
  1738. case R_V850_PC32:
  1739. case R_V850_32_PCREL:
  1740. value -= (input_section->output_section->vma
  1741. + input_section->output_offset
  1742. + offset);
  1743. break;
  1744. case R_V850_32_ABS:
  1745. case R_V850_23:
  1746. case R_V850_HI16_S:
  1747. case R_V850_HI16:
  1748. case R_V850_LO16:
  1749. case R_V850_LO16_S1:
  1750. case R_V850_LO16_SPLIT_OFFSET:
  1751. case R_V850_16:
  1752. case R_V850_ABS32:
  1753. case R_V850_8:
  1754. case R_V810_BYTE:
  1755. case R_V810_HWORD:
  1756. case R_V810_WORD:
  1757. case R_V810_WLO:
  1758. case R_V810_WHI:
  1759. case R_V810_WHI1:
  1760. case R_V810_WLO_1:
  1761. case R_V850_WLO23:
  1762. case R_V850_BLO:
  1763. break;
  1764. case R_V850_ZDA_15_16_OFFSET:
  1765. case R_V850_ZDA_16_16_OFFSET:
  1766. case R_V850_ZDA_16_16_SPLIT_OFFSET:
  1767. if (sym_sec == NULL)
  1768. return bfd_reloc_undefined;
  1769. value -= sym_sec->output_section->vma;
  1770. break;
  1771. case R_V850_SDA_15_16_OFFSET:
  1772. case R_V850_SDA_16_16_OFFSET:
  1773. case R_V850_SDA_16_16_SPLIT_OFFSET:
  1774. case R_V810_GPWLO_1:
  1775. {
  1776. unsigned long gp;
  1777. struct bfd_link_hash_entry * h;
  1778. if (sym_sec == NULL)
  1779. return bfd_reloc_undefined;
  1780. /* Get the value of __gp. */
  1781. h = bfd_link_hash_lookup (info->hash, "__gp", false, false, true);
  1782. if (h == NULL
  1783. || h->type != bfd_link_hash_defined)
  1784. return bfd_reloc_gp_not_found;
  1785. gp = (h->u.def.value
  1786. + h->u.def.section->output_section->vma
  1787. + h->u.def.section->output_offset);
  1788. value -= sym_sec->output_section->vma;
  1789. value -= (gp - sym_sec->output_section->vma);
  1790. }
  1791. break;
  1792. case R_V850_TDA_4_4_OFFSET:
  1793. case R_V850_TDA_4_5_OFFSET:
  1794. case R_V850_TDA_7_7_OFFSET:
  1795. case R_V850_TDA_7_8_OFFSET:
  1796. case R_V850_TDA_6_8_OFFSET:
  1797. case R_V850_TDA_16_16_OFFSET:
  1798. {
  1799. unsigned long ep;
  1800. struct bfd_link_hash_entry * h;
  1801. /* Get the value of __ep. */
  1802. h = bfd_link_hash_lookup (info->hash, "__ep", false, false, true);
  1803. if (h == NULL
  1804. || h->type != bfd_link_hash_defined)
  1805. return bfd_reloc_ep_not_found;
  1806. ep = (h->u.def.value
  1807. + h->u.def.section->output_section->vma
  1808. + h->u.def.section->output_offset);
  1809. value -= ep;
  1810. }
  1811. break;
  1812. case R_V850_CALLT_6_7_OFFSET:
  1813. {
  1814. unsigned long ctbp;
  1815. struct bfd_link_hash_entry * h;
  1816. /* Get the value of __ctbp. */
  1817. h = bfd_link_hash_lookup (info->hash, "__ctbp", false, false, true);
  1818. if (h == NULL
  1819. || h->type != bfd_link_hash_defined)
  1820. return bfd_reloc_ctbp_not_found;
  1821. ctbp = (h->u.def.value
  1822. + h->u.def.section->output_section->vma
  1823. + h->u.def.section->output_offset);
  1824. value -= ctbp;
  1825. }
  1826. break;
  1827. case R_V850_CALLT_15_16_OFFSET:
  1828. case R_V850_CALLT_16_16_OFFSET:
  1829. {
  1830. unsigned long ctbp;
  1831. struct bfd_link_hash_entry * h;
  1832. if (sym_sec == NULL)
  1833. return bfd_reloc_undefined;
  1834. /* Get the value of __ctbp. */
  1835. h = bfd_link_hash_lookup (info->hash, "__ctbp", false, false, true);
  1836. if (h == NULL
  1837. || h->type != bfd_link_hash_defined)
  1838. return bfd_reloc_ctbp_not_found;
  1839. ctbp = (h->u.def.value
  1840. + h->u.def.section->output_section->vma
  1841. + h->u.def.section->output_offset);
  1842. value -= sym_sec->output_section->vma;
  1843. value -= (ctbp - sym_sec->output_section->vma);
  1844. }
  1845. break;
  1846. case R_V850_NONE:
  1847. case R_V810_NONE:
  1848. case R_V850_GNU_VTINHERIT:
  1849. case R_V850_GNU_VTENTRY:
  1850. case R_V850_LONGCALL:
  1851. case R_V850_LONGJUMP:
  1852. case R_V850_ALIGN:
  1853. return bfd_reloc_ok;
  1854. default:
  1855. #ifdef DEBUG
  1856. _bfd_error_handler ("%pB: unsupported relocation type %#x",
  1857. input_bfd, r_type);
  1858. #endif
  1859. return bfd_reloc_notsupported;
  1860. }
  1861. /* Perform the relocation. */
  1862. return v850_elf_perform_relocation (input_bfd, r_type, value + addend, hit_data);
  1863. }
  1864. /* Relocate an V850 ELF section. */
  1865. static int
  1866. v850_elf_relocate_section (bfd *output_bfd,
  1867. struct bfd_link_info *info,
  1868. bfd *input_bfd,
  1869. asection *input_section,
  1870. bfd_byte *contents,
  1871. Elf_Internal_Rela *relocs,
  1872. Elf_Internal_Sym *local_syms,
  1873. asection **local_sections)
  1874. {
  1875. Elf_Internal_Shdr *symtab_hdr;
  1876. struct elf_link_hash_entry **sym_hashes;
  1877. Elf_Internal_Rela *rel;
  1878. Elf_Internal_Rela *relend;
  1879. symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
  1880. sym_hashes = elf_sym_hashes (input_bfd);
  1881. /* Reset the list of remembered HI16S relocs to empty. */
  1882. free_hi16s = previous_hi16s;
  1883. previous_hi16s = NULL;
  1884. hi16s_counter = 0;
  1885. rel = relocs;
  1886. relend = relocs + input_section->reloc_count;
  1887. for (; rel < relend; rel++)
  1888. {
  1889. unsigned int r_type;
  1890. reloc_howto_type *howto;
  1891. unsigned long r_symndx;
  1892. Elf_Internal_Sym *sym;
  1893. asection *sec;
  1894. struct elf_link_hash_entry *h;
  1895. bfd_vma relocation;
  1896. bfd_reloc_status_type r;
  1897. r_symndx = ELF32_R_SYM (rel->r_info);
  1898. r_type = ELF32_R_TYPE (rel->r_info);
  1899. if (r_type == R_V850_GNU_VTENTRY
  1900. || r_type == R_V850_GNU_VTINHERIT)
  1901. continue;
  1902. if (bfd_get_arch (input_bfd) == bfd_arch_v850_rh850)
  1903. howto = v800_elf_howto_table + (r_type - R_V810_NONE);
  1904. else
  1905. howto = v850_elf_howto_table + r_type;
  1906. BFD_ASSERT (r_type == howto->type);
  1907. h = NULL;
  1908. sym = NULL;
  1909. sec = NULL;
  1910. if (r_symndx < symtab_hdr->sh_info)
  1911. {
  1912. sym = local_syms + r_symndx;
  1913. sec = local_sections[r_symndx];
  1914. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  1915. }
  1916. else
  1917. {
  1918. bool unresolved_reloc, warned, ignored;
  1919. /* Note - this check is delayed until now as it is possible and
  1920. valid to have a file without any symbols but with relocs that
  1921. can be processed. */
  1922. if (sym_hashes == NULL)
  1923. {
  1924. info->callbacks->warning
  1925. (info, "no hash table available",
  1926. NULL, input_bfd, input_section, (bfd_vma) 0);
  1927. return false;
  1928. }
  1929. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  1930. r_symndx, symtab_hdr, sym_hashes,
  1931. h, sec, relocation,
  1932. unresolved_reloc, warned, ignored);
  1933. }
  1934. if (sec != NULL && discarded_section (sec))
  1935. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  1936. rel, 1, relend, howto, 0, contents);
  1937. if (bfd_link_relocatable (info))
  1938. continue;
  1939. /* FIXME: We should use the addend, but the COFF relocations don't. */
  1940. r = v850_elf_final_link_relocate (howto, input_bfd, output_bfd,
  1941. input_section,
  1942. contents, rel->r_offset,
  1943. relocation, rel->r_addend,
  1944. info, sec, h == NULL);
  1945. if (r != bfd_reloc_ok)
  1946. {
  1947. const char * name;
  1948. const char * msg = NULL;
  1949. if (h != NULL)
  1950. name = h->root.root.string;
  1951. else
  1952. {
  1953. name = (bfd_elf_string_from_elf_section
  1954. (input_bfd, symtab_hdr->sh_link, sym->st_name));
  1955. if (name == NULL || *name == '\0')
  1956. name = bfd_section_name (sec);
  1957. }
  1958. switch ((int) r)
  1959. {
  1960. case bfd_reloc_overflow:
  1961. (*info->callbacks->reloc_overflow)
  1962. (info, (h ? &h->root : NULL), name, howto->name,
  1963. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  1964. break;
  1965. case bfd_reloc_undefined:
  1966. (*info->callbacks->undefined_symbol)
  1967. (info, name, input_bfd, input_section, rel->r_offset, true);
  1968. break;
  1969. case bfd_reloc_outofrange:
  1970. msg = _("internal error: out of range error");
  1971. goto common_error;
  1972. case bfd_reloc_notsupported:
  1973. msg = _("internal error: unsupported relocation error");
  1974. goto common_error;
  1975. case bfd_reloc_dangerous:
  1976. msg = _("internal error: dangerous relocation");
  1977. goto common_error;
  1978. case bfd_reloc_gp_not_found:
  1979. msg = _("could not locate special linker symbol __gp");
  1980. goto common_error;
  1981. case bfd_reloc_ep_not_found:
  1982. msg = _("could not locate special linker symbol __ep");
  1983. goto common_error;
  1984. case bfd_reloc_ctbp_not_found:
  1985. msg = _("could not locate special linker symbol __ctbp");
  1986. goto common_error;
  1987. default:
  1988. msg = _("internal error: unknown error");
  1989. /* fall through */
  1990. common_error:
  1991. (*info->callbacks->warning) (info, msg, name, input_bfd,
  1992. input_section, rel->r_offset);
  1993. break;
  1994. }
  1995. }
  1996. }
  1997. return true;
  1998. }
  1999. static asection *
  2000. v850_elf_gc_mark_hook (asection *sec,
  2001. struct bfd_link_info *info,
  2002. Elf_Internal_Rela *rel,
  2003. struct elf_link_hash_entry *h,
  2004. Elf_Internal_Sym *sym)
  2005. {
  2006. if (h != NULL)
  2007. switch (ELF32_R_TYPE (rel->r_info))
  2008. {
  2009. case R_V850_GNU_VTINHERIT:
  2010. case R_V850_GNU_VTENTRY:
  2011. return NULL;
  2012. }
  2013. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  2014. }
  2015. static void
  2016. v850_set_note (bfd * abfd, asection * s, enum v850_notes note, unsigned int val)
  2017. {
  2018. bfd_byte * data = s->contents + ((note - 1) * SIZEOF_V850_NOTE);
  2019. bfd_put_32 (abfd, 4, data + 0);
  2020. bfd_put_32 (abfd, 4, data + 4);
  2021. bfd_put_32 (abfd, note, data + 8);
  2022. memcpy (data + 12, V850_NOTE_NAME, 4);
  2023. bfd_put_32 (abfd, val, data + 16);
  2024. }
  2025. /* Create the note section if not already present. This is done early so
  2026. that the linker maps the sections to the right place in the output. */
  2027. static asection *
  2028. v850_elf_make_note_section (bfd * abfd)
  2029. {
  2030. asection *s;
  2031. bfd_byte *data;
  2032. flagword flags;
  2033. enum v850_notes id;
  2034. /* Make the note section. */
  2035. flags = SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_MERGE;
  2036. s = bfd_make_section_anyway_with_flags (abfd, V850_NOTE_SECNAME, flags);
  2037. if (s == NULL)
  2038. return NULL;
  2039. if (!bfd_set_section_alignment (s, 2))
  2040. return NULL;
  2041. /* Allocate space for all known notes. */
  2042. if (!bfd_set_section_size (s, NUM_V850_NOTES * SIZEOF_V850_NOTE))
  2043. return NULL;
  2044. data = bfd_zalloc (abfd, NUM_V850_NOTES * SIZEOF_V850_NOTE);
  2045. if (data == NULL)
  2046. return NULL;
  2047. s->contents = data;
  2048. /* Provide default (= uninitilaised) values for all of the notes. */
  2049. for (id = V850_NOTE_ALIGNMENT; id <= NUM_V850_NOTES; id++)
  2050. v850_set_note (abfd, s, id, 0);
  2051. return s;
  2052. }
  2053. /* Create the note section if not already present. This is done early so
  2054. that the linker maps the sections to the right place in the output. */
  2055. bool
  2056. v850_elf_create_sections (struct bfd_link_info * info)
  2057. {
  2058. bfd * ibfd;
  2059. /* If we already have a note section, do not make another. */
  2060. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  2061. if (bfd_get_section_by_name (ibfd, V850_NOTE_SECNAME) != NULL)
  2062. return true;
  2063. return v850_elf_make_note_section (info->input_bfds) != NULL;
  2064. }
  2065. bool
  2066. v850_elf_set_note (bfd * abfd, enum v850_notes note, unsigned int val)
  2067. {
  2068. asection * notes = bfd_get_section_by_name (abfd, V850_NOTE_SECNAME);
  2069. if (val > 2)
  2070. /* At the moment, no known note has a value over 2. */
  2071. return false;
  2072. if (notes == NULL)
  2073. notes = v850_elf_make_note_section (abfd);
  2074. if (notes == NULL)
  2075. return false;
  2076. v850_set_note (abfd, notes, note, val);
  2077. return true;
  2078. }
  2079. /* Copy a v850 note section from one object module to another. */
  2080. static void
  2081. v850_elf_copy_notes (bfd *ibfd, bfd *obfd)
  2082. {
  2083. asection * onotes;
  2084. asection * inotes;
  2085. /* If the output bfd does not have a note section, then
  2086. skip the merge. The normal input to output section
  2087. copying will take care of everythng for us. */
  2088. if ((onotes = bfd_get_section_by_name (obfd, V850_NOTE_SECNAME)) == NULL)
  2089. return;
  2090. if ((inotes = bfd_get_section_by_name (ibfd, V850_NOTE_SECNAME)) == NULL)
  2091. return;
  2092. if (bfd_section_size (inotes) == bfd_section_size (onotes))
  2093. {
  2094. bfd_byte * icont;
  2095. bfd_byte * ocont;
  2096. if ((icont = elf_section_data (inotes)->this_hdr.contents) == NULL)
  2097. BFD_ASSERT (bfd_malloc_and_get_section (ibfd, inotes, & icont));
  2098. if ((ocont = elf_section_data (onotes)->this_hdr.contents) == NULL)
  2099. /* If the output is being stripped then it is possible for
  2100. the notes section to disappear. In this case do nothing. */
  2101. return;
  2102. /* Copy/overwrite notes from the input to the output. */
  2103. memcpy (ocont, icont, bfd_section_size (onotes));
  2104. }
  2105. }
  2106. /* Copy backend specific data from one object module to another. */
  2107. static bool
  2108. v850_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
  2109. {
  2110. v850_elf_copy_notes (ibfd, obfd);
  2111. return _bfd_elf_copy_private_bfd_data (ibfd, obfd);
  2112. }
  2113. #define bfd_elf32_bfd_copy_private_bfd_data v850_elf_copy_private_bfd_data
  2114. static bool
  2115. v850_elf_merge_notes (bfd * ibfd, bfd *obfd)
  2116. {
  2117. asection * onotes;
  2118. asection * inotes;
  2119. bool result = true;
  2120. /* If the output bfd does not have a note section, then
  2121. skip the merge. The normal input to output section
  2122. copying will take care of everythng for us. */
  2123. if ((onotes = bfd_get_section_by_name (obfd, V850_NOTE_SECNAME)) == NULL)
  2124. return true;
  2125. if ((inotes = bfd_get_section_by_name (ibfd, V850_NOTE_SECNAME)) != NULL)
  2126. {
  2127. enum v850_notes id;
  2128. bfd_byte * icont;
  2129. bfd_byte * ocont;
  2130. BFD_ASSERT (bfd_section_size (inotes) == bfd_section_size (onotes));
  2131. if ((icont = elf_section_data (inotes)->this_hdr.contents) == NULL)
  2132. BFD_ASSERT (bfd_malloc_and_get_section (ibfd, inotes, & icont));
  2133. if ((ocont = elf_section_data (onotes)->this_hdr.contents) == NULL)
  2134. BFD_ASSERT (bfd_malloc_and_get_section (obfd, onotes, & ocont));
  2135. for (id = V850_NOTE_ALIGNMENT; id <= NUM_V850_NOTES; id++)
  2136. {
  2137. unsigned int ival;
  2138. unsigned int oval;
  2139. bfd_byte * idata = icont + ((id - 1) * SIZEOF_V850_NOTE) + 16;
  2140. bfd_byte * odata = ocont + ((id - 1) * SIZEOF_V850_NOTE) + 16;
  2141. ival = bfd_get_32 (ibfd, idata);
  2142. oval = bfd_get_32 (obfd, odata);
  2143. if (ival == 0 || ival == oval)
  2144. continue;
  2145. if (oval == 0)
  2146. {
  2147. bfd_put_32 (obfd, ival, odata);
  2148. v850_set_note (obfd, onotes, id, ival);
  2149. continue;
  2150. }
  2151. /* We have a mismatch. The ABI defines how to handle
  2152. this siutation on a per note type basis. */
  2153. switch (id)
  2154. {
  2155. case V850_NOTE_ALIGNMENT:
  2156. if (oval == EF_RH850_DATA_ALIGN4)
  2157. {
  2158. _bfd_error_handler
  2159. /* xgettext:c-format */
  2160. (_("error: %pB needs 8-byte alignment but %pB is set for 4-byte alignment"),
  2161. ibfd, obfd);
  2162. result = false;
  2163. }
  2164. else
  2165. /* ibfd uses 4-byte alignment, obfd uses 8-byte alignment.
  2166. Leave the obfd alignment as it is. */
  2167. BFD_ASSERT (oval == EF_RH850_DATA_ALIGN8);
  2168. break;
  2169. case V850_NOTE_DATA_SIZE:
  2170. if (oval == EF_RH850_DOUBLE32)
  2171. {
  2172. _bfd_error_handler
  2173. /* xgettext:c-format */
  2174. (_("error: %pB uses 64-bit doubles but "
  2175. "%pB uses 32-bit doubles"), ibfd, obfd);
  2176. result = false;
  2177. }
  2178. else
  2179. /* ibfd uses 32-bit doubles, obfd uses 64-bit doubles.
  2180. This is acceptable. Honest, that is what the ABI says. */
  2181. BFD_ASSERT (oval == EF_RH850_DOUBLE64);
  2182. break;
  2183. case V850_NOTE_FPU_INFO:
  2184. if (oval == EF_RH850_FPU20)
  2185. {
  2186. _bfd_error_handler
  2187. /* xgettext:c-format */
  2188. (_("error: %pB uses FPU-3.0 but %pB only supports FPU-2.0"),
  2189. ibfd, obfd);
  2190. result = false;
  2191. }
  2192. else
  2193. /* ibfd uses FPU-2.0, obfd uses FPU-3.0. Leave obfd as it is. */
  2194. BFD_ASSERT (oval == EF_RH850_FPU30);
  2195. break;
  2196. default:
  2197. /* None of the other conflicts matter.
  2198. Stick with the current output values. */
  2199. break;
  2200. }
  2201. }
  2202. /* FIXME: We should also check for conflicts between the notes
  2203. and the EF flags in the ELF header. */
  2204. }
  2205. return result;
  2206. }
  2207. static void
  2208. print_v850_note (bfd * abfd, FILE * file, bfd_byte * data, enum v850_notes id)
  2209. {
  2210. unsigned int value = bfd_get_32 (abfd, data + ((id - 1) * SIZEOF_V850_NOTE) + 16);
  2211. switch (id)
  2212. {
  2213. case V850_NOTE_ALIGNMENT:
  2214. fprintf (file, _(" alignment of 8-byte entities: "));
  2215. switch (value)
  2216. {
  2217. case EF_RH850_DATA_ALIGN4: fprintf (file, _("4-byte")); break;
  2218. case EF_RH850_DATA_ALIGN8: fprintf (file, _("8-byte")); break;
  2219. case 0: fprintf (file, _("not set")); break;
  2220. default: fprintf (file, _("unknown: %x"), value); break;
  2221. }
  2222. fputc ('\n', file);
  2223. break;
  2224. case V850_NOTE_DATA_SIZE:
  2225. fprintf (file, _(" size of doubles: "));
  2226. switch (value)
  2227. {
  2228. case EF_RH850_DOUBLE32: fprintf (file, _("4-bytes")); break;
  2229. case EF_RH850_DOUBLE64: fprintf (file, _("8-bytes")); break;
  2230. case 0: fprintf (file, _("not set")); break;
  2231. default: fprintf (file, _("unknown: %x"), value); break;
  2232. }
  2233. fputc ('\n', file);
  2234. break;
  2235. case V850_NOTE_FPU_INFO:
  2236. fprintf (file, _(" FPU support required: "));
  2237. switch (value)
  2238. {
  2239. case EF_RH850_FPU20: fprintf (file, _("FPU-2.0")); break;
  2240. case EF_RH850_FPU30: fprintf (file, _("FPU-3.0")); break;
  2241. case 0: fprintf (file, _("none")); break;
  2242. default: fprintf (file, _("unknown: %x"), value); break;
  2243. }
  2244. fputc ('\n', file);
  2245. break;
  2246. case V850_NOTE_SIMD_INFO:
  2247. fprintf (file, _("SIMD use: "));
  2248. switch (value)
  2249. {
  2250. case EF_RH850_SIMD: fprintf (file, _("yes")); break;
  2251. case 0: fprintf (file, _("no")); break;
  2252. default: fprintf (file, _("unknown: %x"), value); break;
  2253. }
  2254. fputc ('\n', file);
  2255. break;
  2256. case V850_NOTE_CACHE_INFO:
  2257. fprintf (file, _("CACHE use: "));
  2258. switch (value)
  2259. {
  2260. case EF_RH850_CACHE: fprintf (file, _("yes")); break;
  2261. case 0: fprintf (file, _("no")); break;
  2262. default: fprintf (file, _("unknown: %x"), value); break;
  2263. }
  2264. fputc ('\n', file);
  2265. break;
  2266. case V850_NOTE_MMU_INFO:
  2267. fprintf (file, _("MMU use: "));
  2268. switch (value)
  2269. {
  2270. case EF_RH850_MMU: fprintf (file, _("yes")); break;
  2271. case 0: fprintf (file, _("no")); break;
  2272. default: fprintf (file, _("unknown: %x"), value); break;
  2273. }
  2274. fputc ('\n', file);
  2275. break;
  2276. default:
  2277. BFD_ASSERT (0);
  2278. }
  2279. }
  2280. static void
  2281. v850_elf_print_notes (bfd * abfd, FILE * file)
  2282. {
  2283. asection * notes = bfd_get_section_by_name (abfd, V850_NOTE_SECNAME);
  2284. enum v850_notes id;
  2285. if (notes == NULL || notes->contents == NULL)
  2286. return;
  2287. BFD_ASSERT (bfd_section_size (notes) == NUM_V850_NOTES * SIZEOF_V850_NOTE);
  2288. for (id = V850_NOTE_ALIGNMENT; id <= NUM_V850_NOTES; id++)
  2289. print_v850_note (abfd, file, notes->contents, id);
  2290. }
  2291. /* Set the right machine number and architecture. */
  2292. static bool
  2293. v850_elf_object_p (bfd *abfd)
  2294. {
  2295. enum bfd_architecture arch;
  2296. unsigned long mach;
  2297. switch (elf_elfheader (abfd)->e_machine)
  2298. {
  2299. case EM_V800:
  2300. arch = bfd_arch_v850_rh850;
  2301. mach = (elf_elfheader (abfd)->e_flags & EF_V800_850E3)
  2302. ? bfd_mach_v850e3v5 : bfd_mach_v850e2v3;
  2303. break;
  2304. case EM_CYGNUS_V850:
  2305. case EM_V850:
  2306. arch = bfd_arch_v850;
  2307. switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH)
  2308. {
  2309. default:
  2310. case E_V850_ARCH: mach = bfd_mach_v850; break;
  2311. case E_V850E_ARCH: mach = bfd_mach_v850e; break;
  2312. case E_V850E1_ARCH: mach = bfd_mach_v850e1; break;
  2313. case E_V850E2_ARCH: mach = bfd_mach_v850e2; break;
  2314. case E_V850E2V3_ARCH: mach = bfd_mach_v850e2v3; break;
  2315. case E_V850E3V5_ARCH: mach = bfd_mach_v850e3v5; break;
  2316. }
  2317. break;
  2318. default:
  2319. return false;
  2320. }
  2321. return bfd_default_set_arch_mach (abfd, arch, mach);
  2322. }
  2323. /* Store the machine number in the flags field. */
  2324. static bool
  2325. v850_elf_final_write_processing (bfd *abfd)
  2326. {
  2327. unsigned long val;
  2328. switch (bfd_get_arch (abfd))
  2329. {
  2330. case bfd_arch_v850_rh850:
  2331. val = EF_RH850_ABI;
  2332. if (bfd_get_mach (abfd) == bfd_mach_v850e3v5)
  2333. val |= EF_V800_850E3;
  2334. elf_elfheader (abfd)->e_flags |= val;
  2335. break;
  2336. case bfd_arch_v850:
  2337. switch (bfd_get_mach (abfd))
  2338. {
  2339. default:
  2340. case bfd_mach_v850: val = E_V850_ARCH; break;
  2341. case bfd_mach_v850e: val = E_V850E_ARCH; break;
  2342. case bfd_mach_v850e1: val = E_V850E1_ARCH; break;
  2343. case bfd_mach_v850e2: val = E_V850E2_ARCH; break;
  2344. case bfd_mach_v850e2v3: val = E_V850E2V3_ARCH; break;
  2345. case bfd_mach_v850e3v5: val = E_V850E3V5_ARCH; break;
  2346. }
  2347. elf_elfheader (abfd)->e_flags &=~ EF_V850_ARCH;
  2348. elf_elfheader (abfd)->e_flags |= val;
  2349. break;
  2350. default:
  2351. break;
  2352. }
  2353. return _bfd_elf_final_write_processing (abfd);
  2354. }
  2355. /* Function to keep V850 specific file flags. */
  2356. static bool
  2357. v850_elf_set_private_flags (bfd *abfd, flagword flags)
  2358. {
  2359. BFD_ASSERT (!elf_flags_init (abfd)
  2360. || elf_elfheader (abfd)->e_flags == flags);
  2361. elf_elfheader (abfd)->e_flags = flags;
  2362. elf_flags_init (abfd) = true;
  2363. return true;
  2364. }
  2365. /* Merge backend specific data from an object file
  2366. to the output object file when linking. */
  2367. static bool
  2368. v850_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
  2369. {
  2370. bfd *obfd = info->output_bfd;
  2371. flagword out_flags;
  2372. flagword in_flags;
  2373. bool result = true;
  2374. if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
  2375. || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
  2376. return true;
  2377. result &= v850_elf_merge_notes (ibfd, obfd);
  2378. in_flags = elf_elfheader (ibfd)->e_flags;
  2379. out_flags = elf_elfheader (obfd)->e_flags;
  2380. if (! elf_flags_init (obfd))
  2381. {
  2382. /* If the input is the default architecture then do not
  2383. bother setting the flags for the output architecture,
  2384. instead allow future merges to do this. If no future
  2385. merges ever set these flags then they will retain their
  2386. unitialised values, which surprise surprise, correspond
  2387. to the default values. */
  2388. if (bfd_get_arch_info (ibfd)->the_default)
  2389. return true;
  2390. elf_flags_init (obfd) = true;
  2391. elf_elfheader (obfd)->e_flags = in_flags;
  2392. if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
  2393. && bfd_get_arch_info (obfd)->the_default)
  2394. result &= bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
  2395. return result;
  2396. }
  2397. /* Check flag compatibility. */
  2398. if (in_flags == out_flags)
  2399. return result;
  2400. if (bfd_get_arch (obfd) == bfd_arch_v850_rh850)
  2401. {
  2402. if ((in_flags & EF_V800_850E3) != (out_flags & EF_V800_850E3))
  2403. {
  2404. _bfd_error_handler
  2405. (_("%pB: architecture mismatch with previous modules"), ibfd);
  2406. elf_elfheader (obfd)->e_flags |= EF_V800_850E3;
  2407. }
  2408. return result;
  2409. }
  2410. if ((in_flags & EF_V850_ARCH) != (out_flags & EF_V850_ARCH)
  2411. && (in_flags & EF_V850_ARCH) != E_V850_ARCH)
  2412. {
  2413. /* Allow earlier architecture binaries to be linked with later binaries.
  2414. Set the output binary to the later architecture, except for v850e1,
  2415. which we set to v850e. */
  2416. if ( (in_flags & EF_V850_ARCH) == E_V850E1_ARCH
  2417. && (out_flags & EF_V850_ARCH) == E_V850E_ARCH)
  2418. return result;
  2419. if ( (in_flags & EF_V850_ARCH) == E_V850_ARCH
  2420. && (out_flags & EF_V850_ARCH) == E_V850E_ARCH)
  2421. {
  2422. elf_elfheader (obfd)->e_flags =
  2423. ((out_flags & ~ EF_V850_ARCH) | E_V850E_ARCH);
  2424. return result;
  2425. }
  2426. if (( (in_flags & EF_V850_ARCH) == E_V850_ARCH
  2427. || (in_flags & EF_V850_ARCH) == E_V850E_ARCH)
  2428. && (out_flags & EF_V850_ARCH) == E_V850E2_ARCH)
  2429. {
  2430. elf_elfheader (obfd)->e_flags =
  2431. ((out_flags & ~ EF_V850_ARCH) | E_V850E2_ARCH);
  2432. return result;
  2433. }
  2434. if (( (in_flags & EF_V850_ARCH) == E_V850_ARCH
  2435. || (in_flags & EF_V850_ARCH) == E_V850E_ARCH
  2436. || (in_flags & EF_V850_ARCH) == E_V850E2_ARCH)
  2437. && (out_flags & EF_V850_ARCH) == E_V850E2V3_ARCH)
  2438. {
  2439. elf_elfheader (obfd)->e_flags =
  2440. ((out_flags & ~ EF_V850_ARCH) | E_V850E2V3_ARCH);
  2441. return result;
  2442. }
  2443. if (( (in_flags & EF_V850_ARCH) == E_V850_ARCH
  2444. || (in_flags & EF_V850_ARCH) == E_V850E_ARCH
  2445. || (in_flags & EF_V850_ARCH) == E_V850E2_ARCH
  2446. || (in_flags & EF_V850_ARCH) == E_V850E2V3_ARCH)
  2447. && (out_flags & EF_V850_ARCH) == E_V850E3V5_ARCH)
  2448. {
  2449. elf_elfheader (obfd)->e_flags =
  2450. ((out_flags & ~ EF_V850_ARCH) | E_V850E3V5_ARCH);
  2451. return result;
  2452. }
  2453. _bfd_error_handler
  2454. (_("%pB: architecture mismatch with previous modules"), ibfd);
  2455. }
  2456. return result;
  2457. }
  2458. /* Display the flags field. */
  2459. static bool
  2460. v850_elf_print_private_bfd_data (bfd *abfd, void * ptr)
  2461. {
  2462. FILE * file = (FILE *) ptr;
  2463. BFD_ASSERT (abfd != NULL && ptr != NULL);
  2464. _bfd_elf_print_private_bfd_data (abfd, ptr);
  2465. /* xgettext:c-format. */
  2466. fprintf (file, _("private flags = %lx: "), elf_elfheader (abfd)->e_flags);
  2467. if (bfd_get_arch (abfd) == bfd_arch_v850_rh850)
  2468. {
  2469. if ((elf_elfheader (abfd)->e_flags & EF_RH850_ABI) != EF_RH850_ABI)
  2470. fprintf (file, _("unknown v850 architecture"));
  2471. else if (elf_elfheader (abfd)->e_flags & EF_V800_850E3)
  2472. fprintf (file, _("v850 E3 architecture"));
  2473. else
  2474. fprintf (file, _("v850 architecture"));
  2475. }
  2476. else
  2477. {
  2478. switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH)
  2479. {
  2480. default:
  2481. case E_V850_ARCH: fprintf (file, _("v850 architecture")); break;
  2482. case E_V850E_ARCH: fprintf (file, _("v850e architecture")); break;
  2483. case E_V850E1_ARCH: fprintf (file, _("v850e1 architecture")); break;
  2484. case E_V850E2_ARCH: fprintf (file, _("v850e2 architecture")); break;
  2485. case E_V850E2V3_ARCH: fprintf (file, _("v850e2v3 architecture")); break;
  2486. case E_V850E3V5_ARCH: fprintf (file, _("v850e3v5 architecture")); break;
  2487. }
  2488. }
  2489. fputc ('\n', file);
  2490. v850_elf_print_notes (abfd, file);
  2491. return true;
  2492. }
  2493. /* V850 ELF uses four common sections. One is the usual one, and the
  2494. others are for (small) objects in one of the special data areas:
  2495. small, tiny and zero. All the objects are kept together, and then
  2496. referenced via the gp register, the ep register or the r0 register
  2497. respectively, which yields smaller, faster assembler code. This
  2498. approach is copied from elf32-mips.c. */
  2499. static asection v850_elf_scom_section;
  2500. static const asymbol v850_elf_scom_symbol =
  2501. GLOBAL_SYM_INIT (".scommon", &v850_elf_scom_section);
  2502. static asection v850_elf_scom_section =
  2503. BFD_FAKE_SECTION (v850_elf_scom_section, &v850_elf_scom_symbol,
  2504. ".scommon", 0,
  2505. SEC_IS_COMMON | SEC_SMALL_DATA | SEC_ALLOC | SEC_DATA);
  2506. static asection v850_elf_tcom_section;
  2507. static const asymbol v850_elf_tcom_symbol =
  2508. GLOBAL_SYM_INIT (".tcommon", &v850_elf_tcom_section);
  2509. static asection v850_elf_tcom_section =
  2510. BFD_FAKE_SECTION (v850_elf_tcom_section, &v850_elf_tcom_symbol,
  2511. ".tcommon", 0,
  2512. SEC_IS_COMMON | SEC_SMALL_DATA);
  2513. static asection v850_elf_zcom_section;
  2514. static const asymbol v850_elf_zcom_symbol =
  2515. GLOBAL_SYM_INIT (".zcommon", &v850_elf_zcom_section);
  2516. static asection v850_elf_zcom_section =
  2517. BFD_FAKE_SECTION (v850_elf_zcom_section, &v850_elf_zcom_symbol,
  2518. ".zcommon", 0,
  2519. SEC_IS_COMMON | SEC_SMALL_DATA);
  2520. /* Given a BFD section, try to locate the
  2521. corresponding ELF section index. */
  2522. static bool
  2523. v850_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
  2524. asection *sec,
  2525. int *retval)
  2526. {
  2527. if (strcmp (bfd_section_name (sec), ".scommon") == 0)
  2528. *retval = SHN_V850_SCOMMON;
  2529. else if (strcmp (bfd_section_name (sec), ".tcommon") == 0)
  2530. *retval = SHN_V850_TCOMMON;
  2531. else if (strcmp (bfd_section_name (sec), ".zcommon") == 0)
  2532. *retval = SHN_V850_ZCOMMON;
  2533. else
  2534. return false;
  2535. return true;
  2536. }
  2537. /* Handle the special V850 section numbers that a symbol may use. */
  2538. static void
  2539. v850_elf_symbol_processing (bfd *abfd, asymbol *asym)
  2540. {
  2541. elf_symbol_type * elfsym = (elf_symbol_type *) asym;
  2542. unsigned int indx;
  2543. indx = elfsym->internal_elf_sym.st_shndx;
  2544. /* If the section index is an "ordinary" index, then it may
  2545. refer to a v850 specific section created by the assembler.
  2546. Check the section's type and change the index it matches.
  2547. FIXME: Should we alter the st_shndx field as well ? */
  2548. if (indx < elf_numsections (abfd))
  2549. switch (elf_elfsections (abfd)[indx]->sh_type)
  2550. {
  2551. case SHT_V850_SCOMMON:
  2552. indx = SHN_V850_SCOMMON;
  2553. break;
  2554. case SHT_V850_TCOMMON:
  2555. indx = SHN_V850_TCOMMON;
  2556. break;
  2557. case SHT_V850_ZCOMMON:
  2558. indx = SHN_V850_ZCOMMON;
  2559. break;
  2560. default:
  2561. break;
  2562. }
  2563. switch (indx)
  2564. {
  2565. case SHN_V850_SCOMMON:
  2566. asym->section = & v850_elf_scom_section;
  2567. asym->value = elfsym->internal_elf_sym.st_size;
  2568. break;
  2569. case SHN_V850_TCOMMON:
  2570. asym->section = & v850_elf_tcom_section;
  2571. asym->value = elfsym->internal_elf_sym.st_size;
  2572. break;
  2573. case SHN_V850_ZCOMMON:
  2574. asym->section = & v850_elf_zcom_section;
  2575. asym->value = elfsym->internal_elf_sym.st_size;
  2576. break;
  2577. }
  2578. }
  2579. /* Hook called by the linker routine which adds symbols from an object
  2580. file. We must handle the special v850 section numbers here. */
  2581. static bool
  2582. v850_elf_add_symbol_hook (bfd *abfd,
  2583. struct bfd_link_info *info ATTRIBUTE_UNUSED,
  2584. Elf_Internal_Sym *sym,
  2585. const char **namep ATTRIBUTE_UNUSED,
  2586. flagword *flagsp ATTRIBUTE_UNUSED,
  2587. asection **secp,
  2588. bfd_vma *valp)
  2589. {
  2590. unsigned int indx = sym->st_shndx;
  2591. /* If the section index is an "ordinary" index, then it may
  2592. refer to a v850 specific section created by the assembler.
  2593. Check the section's type and change the index it matches.
  2594. FIXME: Should we alter the st_shndx field as well ? */
  2595. if (indx < elf_numsections (abfd))
  2596. switch (elf_elfsections (abfd)[indx]->sh_type)
  2597. {
  2598. case SHT_V850_SCOMMON:
  2599. indx = SHN_V850_SCOMMON;
  2600. break;
  2601. case SHT_V850_TCOMMON:
  2602. indx = SHN_V850_TCOMMON;
  2603. break;
  2604. case SHT_V850_ZCOMMON:
  2605. indx = SHN_V850_ZCOMMON;
  2606. break;
  2607. default:
  2608. break;
  2609. }
  2610. switch (indx)
  2611. {
  2612. case SHN_V850_SCOMMON:
  2613. *secp = bfd_make_section_old_way (abfd, ".scommon");
  2614. (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
  2615. *valp = sym->st_size;
  2616. break;
  2617. case SHN_V850_TCOMMON:
  2618. *secp = bfd_make_section_old_way (abfd, ".tcommon");
  2619. (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
  2620. *valp = sym->st_size;
  2621. break;
  2622. case SHN_V850_ZCOMMON:
  2623. *secp = bfd_make_section_old_way (abfd, ".zcommon");
  2624. (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
  2625. *valp = sym->st_size;
  2626. break;
  2627. }
  2628. return true;
  2629. }
  2630. static int
  2631. v850_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
  2632. const char *name ATTRIBUTE_UNUSED,
  2633. Elf_Internal_Sym *sym,
  2634. asection *input_sec,
  2635. struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
  2636. {
  2637. /* If we see a common symbol, which implies a relocatable link, then
  2638. if a symbol was in a special common section in an input file, mark
  2639. it as a special common in the output file. */
  2640. if (sym->st_shndx == SHN_COMMON)
  2641. {
  2642. if (strcmp (input_sec->name, ".scommon") == 0)
  2643. sym->st_shndx = SHN_V850_SCOMMON;
  2644. else if (strcmp (input_sec->name, ".tcommon") == 0)
  2645. sym->st_shndx = SHN_V850_TCOMMON;
  2646. else if (strcmp (input_sec->name, ".zcommon") == 0)
  2647. sym->st_shndx = SHN_V850_ZCOMMON;
  2648. }
  2649. /* The price we pay for using h->other unused bits as flags in the
  2650. linker is cleaning up after ourselves. */
  2651. sym->st_other &= ~(V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA
  2652. | V850_OTHER_ERROR);
  2653. return 1;
  2654. }
  2655. static bool
  2656. v850_elf_section_from_shdr (bfd *abfd,
  2657. Elf_Internal_Shdr *hdr,
  2658. const char *name,
  2659. int shindex)
  2660. {
  2661. flagword flags;
  2662. /* There ought to be a place to keep ELF backend specific flags, but
  2663. at the moment there isn't one. We just keep track of the
  2664. sections by their name, instead. */
  2665. if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
  2666. return false;
  2667. flags = 0;
  2668. switch (hdr->sh_type)
  2669. {
  2670. case SHT_V850_SCOMMON:
  2671. case SHT_V850_TCOMMON:
  2672. case SHT_V850_ZCOMMON:
  2673. flags = SEC_IS_COMMON;
  2674. }
  2675. if ((hdr->sh_flags & SHF_V850_GPREL) != 0)
  2676. flags |= SEC_SMALL_DATA;
  2677. return (flags == 0
  2678. || bfd_set_section_flags (hdr->bfd_section,
  2679. hdr->bfd_section->flags | flags));
  2680. }
  2681. /* Set the correct type for a V850 ELF section. We do this
  2682. by the section name, which is a hack, but ought to work. */
  2683. static bool
  2684. v850_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
  2685. Elf_Internal_Shdr *hdr,
  2686. asection *sec)
  2687. {
  2688. const char * name;
  2689. name = bfd_section_name (sec);
  2690. if (strcmp (name, ".scommon") == 0)
  2691. hdr->sh_type = SHT_V850_SCOMMON;
  2692. else if (strcmp (name, ".tcommon") == 0)
  2693. hdr->sh_type = SHT_V850_TCOMMON;
  2694. else if (strcmp (name, ".zcommon") == 0)
  2695. hdr->sh_type = SHT_V850_ZCOMMON;
  2696. /* Tweak the section type of .note.renesas. */
  2697. else if (strcmp (name, V850_NOTE_SECNAME) == 0)
  2698. {
  2699. hdr->sh_type = SHT_RENESAS_INFO;
  2700. hdr->sh_entsize = SIZEOF_V850_NOTE;
  2701. }
  2702. return true;
  2703. }
  2704. /* Delete some bytes from a section while relaxing. */
  2705. static bool
  2706. v850_elf_relax_delete_bytes (bfd *abfd,
  2707. asection *sec,
  2708. bfd_vma addr,
  2709. bfd_vma toaddr,
  2710. int count)
  2711. {
  2712. Elf_Internal_Shdr *symtab_hdr;
  2713. Elf32_External_Sym *extsyms;
  2714. Elf32_External_Sym *esym;
  2715. Elf32_External_Sym *esymend;
  2716. int sym_index;
  2717. unsigned int sec_shndx;
  2718. bfd_byte *contents;
  2719. Elf_Internal_Rela *irel;
  2720. Elf_Internal_Rela *irelend;
  2721. struct elf_link_hash_entry *sym_hash;
  2722. Elf_External_Sym_Shndx *shndx;
  2723. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  2724. extsyms = (Elf32_External_Sym *) symtab_hdr->contents;
  2725. sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
  2726. contents = elf_section_data (sec)->this_hdr.contents;
  2727. /* The deletion must stop at the next ALIGN reloc for an alignment
  2728. power larger than the number of bytes we are deleting. */
  2729. /* Actually delete the bytes. */
  2730. #if (DEBUG_RELAX & 2)
  2731. fprintf (stderr, "relax_delete: contents: sec: %s %p .. %p %x\n",
  2732. sec->name, addr, toaddr, count );
  2733. #endif
  2734. memmove (contents + addr, contents + addr + count,
  2735. toaddr - addr - count);
  2736. memset (contents + toaddr-count, 0, count);
  2737. /* Adjust all the relocs. */
  2738. irel = elf_section_data (sec)->relocs;
  2739. irelend = irel + sec->reloc_count;
  2740. if (elf_symtab_shndx_list (abfd))
  2741. {
  2742. Elf_Internal_Shdr *shndx_hdr;
  2743. shndx_hdr = & elf_symtab_shndx_list (abfd)->hdr;
  2744. shndx = (Elf_External_Sym_Shndx *) shndx_hdr->contents;
  2745. }
  2746. else
  2747. {
  2748. shndx = NULL;
  2749. }
  2750. for (; irel < irelend; irel++)
  2751. {
  2752. bfd_vma raddr, paddr, symval;
  2753. Elf_Internal_Sym isym;
  2754. /* Get the new reloc address. */
  2755. raddr = irel->r_offset;
  2756. if ((raddr >= (addr + count) && raddr < toaddr))
  2757. irel->r_offset -= count;
  2758. if (raddr >= addr && raddr < addr + count)
  2759. {
  2760. irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
  2761. (int) R_V850_NONE);
  2762. continue;
  2763. }
  2764. if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN)
  2765. continue;
  2766. bfd_elf32_swap_symbol_in (abfd,
  2767. extsyms + ELF32_R_SYM (irel->r_info),
  2768. shndx ? shndx + ELF32_R_SYM (irel->r_info) : NULL,
  2769. & isym);
  2770. if (isym.st_shndx != sec_shndx)
  2771. continue;
  2772. /* Get the value of the symbol referred to by the reloc. */
  2773. if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
  2774. {
  2775. symval = isym.st_value;
  2776. #if (DEBUG_RELAX & 2)
  2777. {
  2778. char * name = bfd_elf_string_from_elf_section
  2779. (abfd, symtab_hdr->sh_link, isym.st_name);
  2780. fprintf (stderr,
  2781. "relax_delete: local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
  2782. sec->name, name, isym.st_name,
  2783. sec->output_section->vma, sec->output_offset,
  2784. isym.st_value, irel->r_addend);
  2785. }
  2786. #endif
  2787. }
  2788. else
  2789. {
  2790. unsigned long indx;
  2791. struct elf_link_hash_entry * h;
  2792. /* An external symbol. */
  2793. indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
  2794. h = elf_sym_hashes (abfd) [indx];
  2795. BFD_ASSERT (h != NULL);
  2796. symval = h->root.u.def.value;
  2797. #if (DEBUG_RELAX & 2)
  2798. fprintf (stderr,
  2799. "relax_delete: defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
  2800. sec->name, h->root.root.string, h->root.u.def.value,
  2801. sec->output_section->vma, sec->output_offset, irel->r_addend);
  2802. #endif
  2803. }
  2804. paddr = symval + irel->r_addend;
  2805. if ( (symval >= addr + count && symval < toaddr)
  2806. && (paddr < addr + count || paddr >= toaddr))
  2807. irel->r_addend += count;
  2808. else if ( (symval < addr + count || symval >= toaddr)
  2809. && (paddr >= addr + count && paddr < toaddr))
  2810. irel->r_addend -= count;
  2811. }
  2812. /* Adjust the local symbols defined in this section. */
  2813. esym = extsyms;
  2814. esymend = esym + symtab_hdr->sh_info;
  2815. for (; esym < esymend; esym++, shndx = (shndx ? shndx + 1 : NULL))
  2816. {
  2817. Elf_Internal_Sym isym;
  2818. bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
  2819. if (isym.st_shndx == sec_shndx
  2820. && isym.st_value >= addr + count
  2821. && isym.st_value < toaddr)
  2822. {
  2823. isym.st_value -= count;
  2824. if (isym.st_value + isym.st_size >= toaddr)
  2825. isym.st_size += count;
  2826. bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
  2827. }
  2828. else if (isym.st_shndx == sec_shndx
  2829. && isym.st_value < addr + count)
  2830. {
  2831. if (isym.st_value+isym.st_size >= addr + count
  2832. && isym.st_value+isym.st_size < toaddr)
  2833. isym.st_size -= count;
  2834. if (isym.st_value >= addr
  2835. && isym.st_value < addr + count)
  2836. isym.st_value = addr;
  2837. bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
  2838. }
  2839. }
  2840. /* Now adjust the global symbols defined in this section. */
  2841. esym = extsyms + symtab_hdr->sh_info;
  2842. esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));
  2843. for (sym_index = 0; esym < esymend; esym ++, sym_index ++)
  2844. {
  2845. Elf_Internal_Sym isym;
  2846. bfd_elf32_swap_symbol_in (abfd, esym, shndx, & isym);
  2847. sym_hash = elf_sym_hashes (abfd) [sym_index];
  2848. if (isym.st_shndx == sec_shndx
  2849. && ((sym_hash)->root.type == bfd_link_hash_defined
  2850. || (sym_hash)->root.type == bfd_link_hash_defweak)
  2851. && (sym_hash)->root.u.def.section == sec
  2852. && (sym_hash)->root.u.def.value >= addr + count
  2853. && (sym_hash)->root.u.def.value < toaddr)
  2854. {
  2855. if ((sym_hash)->root.u.def.value + isym.st_size >= toaddr)
  2856. {
  2857. isym.st_size += count;
  2858. bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
  2859. }
  2860. (sym_hash)->root.u.def.value -= count;
  2861. }
  2862. else if (isym.st_shndx == sec_shndx
  2863. && ((sym_hash)->root.type == bfd_link_hash_defined
  2864. || (sym_hash)->root.type == bfd_link_hash_defweak)
  2865. && (sym_hash)->root.u.def.section == sec
  2866. && (sym_hash)->root.u.def.value < addr + count)
  2867. {
  2868. if ((sym_hash)->root.u.def.value+isym.st_size >= addr + count
  2869. && (sym_hash)->root.u.def.value+isym.st_size < toaddr)
  2870. isym.st_size -= count;
  2871. if ((sym_hash)->root.u.def.value >= addr
  2872. && (sym_hash)->root.u.def.value < addr + count)
  2873. (sym_hash)->root.u.def.value = addr;
  2874. bfd_elf32_swap_symbol_out (abfd, & isym, esym, shndx);
  2875. }
  2876. if (shndx)
  2877. ++ shndx;
  2878. }
  2879. return true;
  2880. }
  2881. #define NOP_OPCODE (0x0000)
  2882. #define MOVHI 0x0640 /* 4byte. */
  2883. #define MOVHI_MASK 0x07e0
  2884. #define MOVHI_R1(insn) ((insn) & 0x1f) /* 4byte. */
  2885. #define MOVHI_R2(insn) ((insn) >> 11)
  2886. #define MOVEA 0x0620 /* 2byte. */
  2887. #define MOVEA_MASK 0x07e0
  2888. #define MOVEA_R1(insn) ((insn) & 0x1f)
  2889. #define MOVEA_R2(insn) ((insn) >> 11)
  2890. #define JARL_4 0x00040780 /* 4byte. */
  2891. #define JARL_4_MASK 0xFFFF07FF
  2892. #define JARL_R2(insn) (int)(((insn) & (~JARL_4_MASK)) >> 11)
  2893. #define ADD_I 0x0240 /* 2byte. */
  2894. #define ADD_I_MASK 0x07e0
  2895. #define ADD_I5(insn) ((((insn) & 0x001f) << 11) >> 11) /* 2byte. */
  2896. #define ADD_R2(insn) ((insn) >> 11)
  2897. #define JMP_R 0x0060 /* 2byte. */
  2898. #define JMP_R_MASK 0xFFE0
  2899. #define JMP_R1(insn) ((insn) & 0x1f)
  2900. static bool
  2901. v850_elf_relax_section (bfd *abfd,
  2902. asection *sec,
  2903. struct bfd_link_info *link_info,
  2904. bool *again)
  2905. {
  2906. Elf_Internal_Shdr *symtab_hdr;
  2907. Elf_Internal_Rela *internal_relocs;
  2908. Elf_Internal_Rela *irel;
  2909. Elf_Internal_Rela *irelend;
  2910. Elf_Internal_Rela *irelalign = NULL;
  2911. Elf_Internal_Sym *isymbuf = NULL;
  2912. bfd_byte *contents = NULL;
  2913. bfd_vma addr = 0;
  2914. bfd_vma toaddr;
  2915. int align_pad_size = 0;
  2916. bool result = true;
  2917. *again = false;
  2918. if (bfd_link_relocatable (link_info)
  2919. || (sec->flags & SEC_RELOC) == 0
  2920. || sec->reloc_count == 0)
  2921. return true;
  2922. symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
  2923. internal_relocs = (_bfd_elf_link_read_relocs
  2924. (abfd, sec, NULL, NULL, link_info->keep_memory));
  2925. if (internal_relocs == NULL)
  2926. goto error_return;
  2927. irelend = internal_relocs + sec->reloc_count;
  2928. while (addr < sec->size)
  2929. {
  2930. toaddr = sec->size;
  2931. for (irel = internal_relocs; irel < irelend; irel ++)
  2932. if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
  2933. && irel->r_offset > addr
  2934. && irel->r_offset < toaddr)
  2935. toaddr = irel->r_offset;
  2936. #ifdef DEBUG_RELAX
  2937. fprintf (stderr, "relax region 0x%x to 0x%x align pad %d\n",
  2938. addr, toaddr, align_pad_size);
  2939. #endif
  2940. if (irelalign)
  2941. {
  2942. bfd_vma alignto;
  2943. bfd_vma alignmoveto;
  2944. alignmoveto = BFD_ALIGN (addr - align_pad_size, 1 << irelalign->r_addend);
  2945. alignto = BFD_ALIGN (addr, 1 << irelalign->r_addend);
  2946. if (alignmoveto < alignto)
  2947. {
  2948. bfd_vma i;
  2949. align_pad_size = alignto - alignmoveto;
  2950. #ifdef DEBUG_RELAX
  2951. fprintf (stderr, "relax move region 0x%x to 0x%x delete size 0x%x\n",
  2952. alignmoveto, toaddr, align_pad_size);
  2953. #endif
  2954. if (!v850_elf_relax_delete_bytes (abfd, sec, alignmoveto,
  2955. toaddr, align_pad_size))
  2956. goto error_return;
  2957. for (i = BFD_ALIGN (toaddr - align_pad_size, 1);
  2958. (i + 1) < toaddr; i += 2)
  2959. bfd_put_16 (abfd, NOP_OPCODE, contents + i);
  2960. addr = alignmoveto;
  2961. }
  2962. else
  2963. align_pad_size = 0;
  2964. }
  2965. for (irel = internal_relocs; irel < irelend; irel++)
  2966. {
  2967. bfd_vma laddr;
  2968. bfd_vma addend;
  2969. bfd_vma symval;
  2970. int insn[5];
  2971. int no_match = -1;
  2972. Elf_Internal_Rela *hi_irelfn;
  2973. Elf_Internal_Rela *lo_irelfn;
  2974. Elf_Internal_Rela *irelcall;
  2975. bfd_signed_vma foff;
  2976. unsigned int r_type;
  2977. if (! (irel->r_offset >= addr && irel->r_offset < toaddr
  2978. && (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL
  2979. || ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)))
  2980. continue;
  2981. #ifdef DEBUG_RELAX
  2982. fprintf (stderr, "relax check r_info 0x%x r_offset 0x%x r_addend 0x%x\n",
  2983. irel->r_info,
  2984. irel->r_offset,
  2985. irel->r_addend );
  2986. #endif
  2987. /* Get the section contents. */
  2988. if (contents == NULL)
  2989. {
  2990. if (elf_section_data (sec)->this_hdr.contents != NULL)
  2991. contents = elf_section_data (sec)->this_hdr.contents;
  2992. else
  2993. {
  2994. if (! bfd_malloc_and_get_section (abfd, sec, &contents))
  2995. goto error_return;
  2996. }
  2997. }
  2998. /* Read this BFD's local symbols if we haven't done so already. */
  2999. if (isymbuf == NULL && symtab_hdr->sh_info != 0)
  3000. {
  3001. isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
  3002. if (isymbuf == NULL)
  3003. isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
  3004. symtab_hdr->sh_info, 0,
  3005. NULL, NULL, NULL);
  3006. if (isymbuf == NULL)
  3007. goto error_return;
  3008. }
  3009. laddr = irel->r_offset;
  3010. if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGCALL)
  3011. {
  3012. /* Check code for -mlong-calls output. */
  3013. if (laddr + 16 <= (bfd_vma) sec->size)
  3014. {
  3015. insn[0] = bfd_get_16 (abfd, contents + laddr);
  3016. insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
  3017. insn[2] = bfd_get_32 (abfd, contents + laddr + 8);
  3018. insn[3] = bfd_get_16 (abfd, contents + laddr + 12);
  3019. insn[4] = bfd_get_16 (abfd, contents + laddr + 14);
  3020. if ((insn[0] & MOVHI_MASK) != MOVHI
  3021. || MOVHI_R1 (insn[0]) != 0)
  3022. no_match = 0;
  3023. if (no_match < 0
  3024. && ((insn[1] & MOVEA_MASK) != MOVEA
  3025. || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
  3026. no_match = 1;
  3027. if (no_match < 0
  3028. && (insn[2] & JARL_4_MASK) != JARL_4)
  3029. no_match = 2;
  3030. if (no_match < 0
  3031. && ((insn[3] & ADD_I_MASK) != ADD_I
  3032. || ADD_I5 (insn[3]) != 4
  3033. || JARL_R2 (insn[2]) != ADD_R2 (insn[3])))
  3034. no_match = 3;
  3035. if (no_match < 0
  3036. && ((insn[4] & JMP_R_MASK) != JMP_R
  3037. || MOVEA_R2 (insn[1]) != JMP_R1 (insn[4])))
  3038. no_match = 4;
  3039. }
  3040. else
  3041. {
  3042. _bfd_error_handler
  3043. /* xgettext:c-format */
  3044. (_("%pB: %#" PRIx64 ": warning: %s points to "
  3045. "unrecognized insns"),
  3046. abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL");
  3047. continue;
  3048. }
  3049. if (no_match >= 0)
  3050. {
  3051. _bfd_error_handler
  3052. /* xgettext:c-format */
  3053. (_("%pB: %#" PRIx64 ": warning: %s points to "
  3054. "unrecognized insn %#x"),
  3055. abfd,
  3056. (uint64_t) (irel->r_offset + no_match),
  3057. "R_V850_LONGCALL",
  3058. insn[no_match]);
  3059. continue;
  3060. }
  3061. /* Get the reloc for the address from which the register is
  3062. being loaded. This reloc will tell us which function is
  3063. actually being called. */
  3064. for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
  3065. {
  3066. r_type = ELF32_R_TYPE (hi_irelfn->r_info);
  3067. if (hi_irelfn->r_offset == laddr + 2
  3068. && (r_type == (int) R_V850_HI16_S || r_type == (int) R_V810_WHI1))
  3069. break;
  3070. }
  3071. for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
  3072. {
  3073. r_type = ELF32_R_TYPE (lo_irelfn->r_info);
  3074. if (lo_irelfn->r_offset == laddr + 6
  3075. && (r_type == (int) R_V850_LO16 || r_type == (int) R_V810_WLO))
  3076. break;
  3077. }
  3078. for (irelcall = internal_relocs; irelcall < irelend; irelcall ++)
  3079. {
  3080. r_type = ELF32_R_TYPE (irelcall->r_info);
  3081. if (irelcall->r_offset == laddr + 8
  3082. && (r_type == (int) R_V850_22_PCREL || r_type == (int) R_V850_PCR22))
  3083. break;
  3084. }
  3085. if ( hi_irelfn == irelend
  3086. || lo_irelfn == irelend
  3087. || irelcall == irelend)
  3088. {
  3089. _bfd_error_handler
  3090. /* xgettext:c-format */
  3091. (_("%pB: %#" PRIx64 ": warning: %s points to "
  3092. "unrecognized reloc"),
  3093. abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL");
  3094. continue;
  3095. }
  3096. if (ELF32_R_SYM (irelcall->r_info) < symtab_hdr->sh_info)
  3097. {
  3098. Elf_Internal_Sym * isym;
  3099. /* A local symbol. */
  3100. isym = isymbuf + ELF32_R_SYM (irelcall->r_info);
  3101. symval = isym->st_value;
  3102. }
  3103. else
  3104. {
  3105. unsigned long indx;
  3106. struct elf_link_hash_entry * h;
  3107. /* An external symbol. */
  3108. indx = ELF32_R_SYM (irelcall->r_info) - symtab_hdr->sh_info;
  3109. h = elf_sym_hashes (abfd)[indx];
  3110. BFD_ASSERT (h != NULL);
  3111. if ( h->root.type != bfd_link_hash_defined
  3112. && h->root.type != bfd_link_hash_defweak)
  3113. /* This appears to be a reference to an undefined
  3114. symbol. Just ignore it--it will be caught by the
  3115. regular reloc processing. */
  3116. continue;
  3117. symval = h->root.u.def.value;
  3118. }
  3119. if (symval + irelcall->r_addend != irelcall->r_offset + 4)
  3120. {
  3121. _bfd_error_handler
  3122. /* xgettext:c-format */
  3123. (_("%pB: %#" PRIx64 ": warning: %s points to "
  3124. "unrecognized reloc %#" PRIx64),
  3125. abfd, (uint64_t) irel->r_offset, "R_V850_LONGCALL",
  3126. (uint64_t) irelcall->r_offset);
  3127. continue;
  3128. }
  3129. /* Get the value of the symbol referred to by the reloc. */
  3130. if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
  3131. {
  3132. Elf_Internal_Sym *isym;
  3133. asection *sym_sec;
  3134. /* A local symbol. */
  3135. isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
  3136. if (isym->st_shndx == SHN_UNDEF)
  3137. sym_sec = bfd_und_section_ptr;
  3138. else if (isym->st_shndx == SHN_ABS)
  3139. sym_sec = bfd_abs_section_ptr;
  3140. else if (isym->st_shndx == SHN_COMMON)
  3141. sym_sec = bfd_com_section_ptr;
  3142. else
  3143. sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  3144. symval = (isym->st_value
  3145. + sym_sec->output_section->vma
  3146. + sym_sec->output_offset);
  3147. }
  3148. else
  3149. {
  3150. unsigned long indx;
  3151. struct elf_link_hash_entry *h;
  3152. /* An external symbol. */
  3153. indx = ELF32_R_SYM (hi_irelfn->r_info) - symtab_hdr->sh_info;
  3154. h = elf_sym_hashes (abfd)[indx];
  3155. BFD_ASSERT (h != NULL);
  3156. if ( h->root.type != bfd_link_hash_defined
  3157. && h->root.type != bfd_link_hash_defweak)
  3158. /* This appears to be a reference to an undefined
  3159. symbol. Just ignore it--it will be caught by the
  3160. regular reloc processing. */
  3161. continue;
  3162. symval = (h->root.u.def.value
  3163. + h->root.u.def.section->output_section->vma
  3164. + h->root.u.def.section->output_offset);
  3165. }
  3166. addend = irel->r_addend;
  3167. foff = (symval + addend
  3168. - (irel->r_offset
  3169. + sec->output_section->vma
  3170. + sec->output_offset
  3171. + 4));
  3172. #ifdef DEBUG_RELAX
  3173. fprintf (stderr, "relax longcall r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
  3174. irel->r_offset,
  3175. (irel->r_offset
  3176. + sec->output_section->vma
  3177. + sec->output_offset),
  3178. symval, addend, foff);
  3179. #endif
  3180. if (foff < -0x100000 || foff >= 0x100000)
  3181. /* After all that work, we can't shorten this function call. */
  3182. continue;
  3183. /* For simplicity of coding, we are going to modify the section
  3184. contents, the section relocs, and the BFD symbol table. We
  3185. must tell the rest of the code not to free up this
  3186. information. It would be possible to instead create a table
  3187. of changes which have to be made, as is done in coff-mips.c;
  3188. that would be more work, but would require less memory when
  3189. the linker is run. */
  3190. elf_section_data (sec)->relocs = internal_relocs;
  3191. elf_section_data (sec)->this_hdr.contents = contents;
  3192. symtab_hdr->contents = (bfd_byte *) isymbuf;
  3193. /* Replace the long call with a jarl. */
  3194. if (bfd_get_arch (abfd) == bfd_arch_v850_rh850)
  3195. irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_PCR22);
  3196. else
  3197. irel->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_22_PCREL);
  3198. addend = 0;
  3199. if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
  3200. /* If this needs to be changed because of future relaxing,
  3201. it will be handled here like other internal IND12W
  3202. relocs. */
  3203. bfd_put_32 (abfd,
  3204. 0x00000780 | (JARL_R2 (insn[2])<<11) | ((addend << 16) & 0xffff) | ((addend >> 16) & 0xf),
  3205. contents + irel->r_offset);
  3206. else
  3207. /* We can't fully resolve this yet, because the external
  3208. symbol value may be changed by future relaxing.
  3209. We let the final link phase handle it. */
  3210. bfd_put_32 (abfd, 0x00000780 | (JARL_R2 (insn[2])<<11),
  3211. contents + irel->r_offset);
  3212. hi_irelfn->r_info =
  3213. ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
  3214. lo_irelfn->r_info =
  3215. ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
  3216. irelcall->r_info =
  3217. ELF32_R_INFO (ELF32_R_SYM (irelcall->r_info), R_V850_NONE);
  3218. if (! v850_elf_relax_delete_bytes (abfd, sec,
  3219. irel->r_offset + 4, toaddr, 12))
  3220. goto error_return;
  3221. align_pad_size += 12;
  3222. }
  3223. else if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_LONGJUMP)
  3224. {
  3225. /* Check code for -mlong-jumps output. */
  3226. if (laddr + 10 <= (bfd_vma) sec->size)
  3227. {
  3228. insn[0] = bfd_get_16 (abfd, contents + laddr);
  3229. insn[1] = bfd_get_16 (abfd, contents + laddr + 4);
  3230. insn[2] = bfd_get_16 (abfd, contents + laddr + 8);
  3231. if ((insn[0] & MOVHI_MASK) != MOVHI
  3232. || MOVHI_R1 (insn[0]) != 0)
  3233. no_match = 0;
  3234. if (no_match < 0
  3235. && ((insn[1] & MOVEA_MASK) != MOVEA
  3236. || MOVHI_R2 (insn[0]) != MOVEA_R1 (insn[1])))
  3237. no_match = 1;
  3238. if (no_match < 0
  3239. && ((insn[2] & JMP_R_MASK) != JMP_R
  3240. || MOVEA_R2 (insn[1]) != JMP_R1 (insn[2])))
  3241. no_match = 2;
  3242. }
  3243. else
  3244. {
  3245. _bfd_error_handler
  3246. /* xgettext:c-format */
  3247. (_("%pB: %#" PRIx64 ": warning: %s points to "
  3248. "unrecognized insns"),
  3249. abfd, (uint64_t) irel->r_offset, "R_V850_LONGJUMP");
  3250. continue;
  3251. }
  3252. if (no_match >= 0)
  3253. {
  3254. _bfd_error_handler
  3255. /* xgettext:c-format */
  3256. (_("%pB: %#" PRIx64 ": warning: %s points to "
  3257. "unrecognized insn %#x"),
  3258. abfd,
  3259. (uint64_t) (irel->r_offset + no_match),
  3260. "R_V850_LONGJUMP",
  3261. insn[no_match]);
  3262. continue;
  3263. }
  3264. /* Get the reloc for the address from which the register is
  3265. being loaded. This reloc will tell us which function is
  3266. actually being called. */
  3267. for (hi_irelfn = internal_relocs; hi_irelfn < irelend; hi_irelfn ++)
  3268. {
  3269. r_type = ELF32_R_TYPE (hi_irelfn->r_info);
  3270. if (hi_irelfn->r_offset == laddr + 2
  3271. && ((r_type == (int) R_V850_HI16_S) || r_type == (int) R_V810_WHI1))
  3272. break;
  3273. }
  3274. for (lo_irelfn = internal_relocs; lo_irelfn < irelend; lo_irelfn ++)
  3275. {
  3276. r_type = ELF32_R_TYPE (lo_irelfn->r_info);
  3277. if (lo_irelfn->r_offset == laddr + 6
  3278. && (r_type == (int) R_V850_LO16 || r_type == (int) R_V810_WLO))
  3279. break;
  3280. }
  3281. if ( hi_irelfn == irelend
  3282. || lo_irelfn == irelend)
  3283. {
  3284. _bfd_error_handler
  3285. /* xgettext:c-format */
  3286. (_("%pB: %#" PRIx64 ": warning: %s points to "
  3287. "unrecognized reloc"),
  3288. abfd, (uint64_t) irel->r_offset, "R_V850_LONGJUMP");
  3289. continue;
  3290. }
  3291. /* Get the value of the symbol referred to by the reloc. */
  3292. if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
  3293. {
  3294. Elf_Internal_Sym * isym;
  3295. asection * sym_sec;
  3296. /* A local symbol. */
  3297. isym = isymbuf + ELF32_R_SYM (hi_irelfn->r_info);
  3298. if (isym->st_shndx == SHN_UNDEF)
  3299. sym_sec = bfd_und_section_ptr;
  3300. else if (isym->st_shndx == SHN_ABS)
  3301. sym_sec = bfd_abs_section_ptr;
  3302. else if (isym->st_shndx == SHN_COMMON)
  3303. sym_sec = bfd_com_section_ptr;
  3304. else
  3305. sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  3306. symval = (isym->st_value
  3307. + sym_sec->output_section->vma
  3308. + sym_sec->output_offset);
  3309. #ifdef DEBUG_RELAX
  3310. {
  3311. char * name = bfd_elf_string_from_elf_section
  3312. (abfd, symtab_hdr->sh_link, isym->st_name);
  3313. fprintf (stderr, "relax long jump local: sec: %s, sym: %s (%d), value: %x + %x + %x addend %x\n",
  3314. sym_sec->name, name, isym->st_name,
  3315. sym_sec->output_section->vma,
  3316. sym_sec->output_offset,
  3317. isym->st_value, irel->r_addend);
  3318. }
  3319. #endif
  3320. }
  3321. else
  3322. {
  3323. unsigned long indx;
  3324. struct elf_link_hash_entry * h;
  3325. /* An external symbol. */
  3326. indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
  3327. h = elf_sym_hashes (abfd)[indx];
  3328. BFD_ASSERT (h != NULL);
  3329. if ( h->root.type != bfd_link_hash_defined
  3330. && h->root.type != bfd_link_hash_defweak)
  3331. /* This appears to be a reference to an undefined
  3332. symbol. Just ignore it--it will be caught by the
  3333. regular reloc processing. */
  3334. continue;
  3335. symval = (h->root.u.def.value
  3336. + h->root.u.def.section->output_section->vma
  3337. + h->root.u.def.section->output_offset);
  3338. #ifdef DEBUG_RELAX
  3339. fprintf (stderr,
  3340. "relax longjump defined: sec: %s, name: %s, value: %x + %x + %x addend %x\n",
  3341. sec->name, h->root.root.string, h->root.u.def.value,
  3342. sec->output_section->vma, sec->output_offset, irel->r_addend);
  3343. #endif
  3344. }
  3345. addend = irel->r_addend;
  3346. foff = (symval + addend
  3347. - (irel->r_offset
  3348. + sec->output_section->vma
  3349. + sec->output_offset
  3350. + 4));
  3351. #ifdef DEBUG_RELAX
  3352. fprintf (stderr, "relax longjump r_offset 0x%x ptr 0x%x symbol 0x%x addend 0x%x distance 0x%x\n",
  3353. irel->r_offset,
  3354. (irel->r_offset
  3355. + sec->output_section->vma
  3356. + sec->output_offset),
  3357. symval, addend, foff);
  3358. #endif
  3359. if (foff < -0x100000 || foff >= 0x100000)
  3360. /* After all that work, we can't shorten this function call. */
  3361. continue;
  3362. /* For simplicity of coding, we are going to modify the section
  3363. contents, the section relocs, and the BFD symbol table. We
  3364. must tell the rest of the code not to free up this
  3365. information. It would be possible to instead create a table
  3366. of changes which have to be made, as is done in coff-mips.c;
  3367. that would be more work, but would require less memory when
  3368. the linker is run. */
  3369. elf_section_data (sec)->relocs = internal_relocs;
  3370. elf_section_data (sec)->this_hdr.contents = contents;
  3371. symtab_hdr->contents = (bfd_byte *) isymbuf;
  3372. if (foff < -0x100 || foff >= 0x100)
  3373. {
  3374. /* Replace the long jump with a jr. */
  3375. if (bfd_get_arch (abfd) == bfd_arch_v850_rh850)
  3376. irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_PCR22);
  3377. else
  3378. irel->r_info =
  3379. ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_22_PCREL);
  3380. irel->r_addend = addend;
  3381. addend = 0;
  3382. if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
  3383. /* If this needs to be changed because of future relaxing,
  3384. it will be handled here like other internal IND12W
  3385. relocs. */
  3386. bfd_put_32 (abfd,
  3387. 0x00000780 | ((addend << 15) & 0xffff0000) | ((addend >> 17) & 0xf),
  3388. contents + irel->r_offset);
  3389. else
  3390. /* We can't fully resolve this yet, because the external
  3391. symbol value may be changed by future relaxing.
  3392. We let the final link phase handle it. */
  3393. bfd_put_32 (abfd, 0x00000780, contents + irel->r_offset);
  3394. hi_irelfn->r_info =
  3395. ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
  3396. lo_irelfn->r_info =
  3397. ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
  3398. if (!v850_elf_relax_delete_bytes (abfd, sec,
  3399. irel->r_offset + 4, toaddr, 6))
  3400. goto error_return;
  3401. align_pad_size += 6;
  3402. }
  3403. else
  3404. {
  3405. /* Replace the long jump with a br. */
  3406. if (bfd_get_arch (abfd) == bfd_arch_v850_rh850)
  3407. irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_PC9);
  3408. else
  3409. irel->r_info =
  3410. ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_V850_9_PCREL);
  3411. irel->r_addend = addend;
  3412. addend = 0;
  3413. if (ELF32_R_SYM (hi_irelfn->r_info) < symtab_hdr->sh_info)
  3414. /* If this needs to be changed because of future relaxing,
  3415. it will be handled here like other internal IND12W
  3416. relocs. */
  3417. bfd_put_16 (abfd,
  3418. 0x0585 | ((addend << 10) & 0xf800) | ((addend << 3) & 0x0070),
  3419. contents + irel->r_offset);
  3420. else
  3421. /* We can't fully resolve this yet, because the external
  3422. symbol value may be changed by future relaxing.
  3423. We let the final link phase handle it. */
  3424. bfd_put_16 (abfd, 0x0585, contents + irel->r_offset);
  3425. hi_irelfn->r_info =
  3426. ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info), R_V850_NONE);
  3427. lo_irelfn->r_info =
  3428. ELF32_R_INFO (ELF32_R_SYM (lo_irelfn->r_info), R_V850_NONE);
  3429. if (!v850_elf_relax_delete_bytes (abfd, sec,
  3430. irel->r_offset + 2, toaddr, 8))
  3431. goto error_return;
  3432. align_pad_size += 8;
  3433. }
  3434. }
  3435. }
  3436. irelalign = NULL;
  3437. for (irel = internal_relocs; irel < irelend; irel++)
  3438. {
  3439. if (ELF32_R_TYPE (irel->r_info) == (int) R_V850_ALIGN
  3440. && irel->r_offset == toaddr)
  3441. {
  3442. irel->r_offset -= align_pad_size;
  3443. if (irelalign == NULL || irelalign->r_addend > irel->r_addend)
  3444. irelalign = irel;
  3445. }
  3446. }
  3447. addr = toaddr;
  3448. }
  3449. if (!irelalign)
  3450. {
  3451. #ifdef DEBUG_RELAX
  3452. fprintf (stderr, "relax pad %d shorten %d -> %d\n",
  3453. align_pad_size,
  3454. sec->size,
  3455. sec->size - align_pad_size);
  3456. #endif
  3457. sec->size -= align_pad_size;
  3458. }
  3459. finish:
  3460. if (elf_section_data (sec)->relocs != internal_relocs)
  3461. free (internal_relocs);
  3462. if (elf_section_data (sec)->this_hdr.contents != (unsigned char *) contents)
  3463. free (contents);
  3464. if (symtab_hdr->contents != (bfd_byte *) isymbuf)
  3465. free (isymbuf);
  3466. return result;
  3467. error_return:
  3468. result = false;
  3469. goto finish;
  3470. }
  3471. static const struct bfd_elf_special_section v850_elf_special_sections[] =
  3472. {
  3473. { STRING_COMMA_LEN (".call_table_data"), 0, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE) },
  3474. { STRING_COMMA_LEN (".call_table_text"), 0, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
  3475. + SHF_EXECINSTR) },
  3476. { STRING_COMMA_LEN (".rosdata"), -2, SHT_PROGBITS, (SHF_ALLOC
  3477. + SHF_V850_GPREL) },
  3478. { STRING_COMMA_LEN (".rozdata"), -2, SHT_PROGBITS, (SHF_ALLOC
  3479. + SHF_V850_R0REL) },
  3480. { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
  3481. + SHF_V850_GPREL) },
  3482. { STRING_COMMA_LEN (".scommon"), -2, SHT_V850_SCOMMON, (SHF_ALLOC + SHF_WRITE
  3483. + SHF_V850_GPREL) },
  3484. { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
  3485. + SHF_V850_GPREL) },
  3486. { STRING_COMMA_LEN (".tbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
  3487. + SHF_V850_EPREL) },
  3488. { STRING_COMMA_LEN (".tcommon"), -2, SHT_V850_TCOMMON, (SHF_ALLOC + SHF_WRITE
  3489. + SHF_V850_R0REL) },
  3490. { STRING_COMMA_LEN (".tdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
  3491. + SHF_V850_EPREL) },
  3492. { STRING_COMMA_LEN (".zbss"), -2, SHT_NOBITS, (SHF_ALLOC + SHF_WRITE
  3493. + SHF_V850_R0REL) },
  3494. { STRING_COMMA_LEN (".zcommon"), -2, SHT_V850_ZCOMMON, (SHF_ALLOC + SHF_WRITE
  3495. + SHF_V850_R0REL) },
  3496. { STRING_COMMA_LEN (".zdata"), -2, SHT_PROGBITS, (SHF_ALLOC + SHF_WRITE
  3497. + SHF_V850_R0REL) },
  3498. { NULL, 0, 0, 0, 0 }
  3499. };
  3500. #define TARGET_LITTLE_SYM v850_elf32_vec
  3501. #define TARGET_LITTLE_NAME "elf32-v850"
  3502. #define ELF_ARCH bfd_arch_v850
  3503. #define ELF_MACHINE_CODE EM_V850
  3504. #define ELF_MACHINE_ALT1 EM_CYGNUS_V850
  3505. #define ELF_MAXPAGESIZE 0x1000
  3506. #define elf_info_to_howto v850_elf_info_to_howto_rela
  3507. #define elf_info_to_howto_rel v850_elf_info_to_howto_rel
  3508. #define elf_backend_check_relocs v850_elf_check_relocs
  3509. #define elf_backend_relocate_section v850_elf_relocate_section
  3510. #define elf_backend_object_p v850_elf_object_p
  3511. #define elf_backend_final_write_processing v850_elf_final_write_processing
  3512. #define elf_backend_section_from_bfd_section v850_elf_section_from_bfd_section
  3513. #define elf_backend_symbol_processing v850_elf_symbol_processing
  3514. #define elf_backend_add_symbol_hook v850_elf_add_symbol_hook
  3515. #define elf_backend_link_output_symbol_hook v850_elf_link_output_symbol_hook
  3516. #define elf_backend_section_from_shdr v850_elf_section_from_shdr
  3517. #define elf_backend_fake_sections v850_elf_fake_sections
  3518. #define elf_backend_gc_mark_hook v850_elf_gc_mark_hook
  3519. #define elf_backend_special_sections v850_elf_special_sections
  3520. #define elf_backend_can_gc_sections 1
  3521. #define elf_backend_rela_normal 1
  3522. #define bfd_elf32_bfd_is_local_label_name v850_elf_is_local_label_name
  3523. #define bfd_elf32_bfd_is_target_special_symbol v850_elf_is_target_special_symbol
  3524. #define bfd_elf32_bfd_reloc_type_lookup v850_elf_reloc_type_lookup
  3525. #define bfd_elf32_bfd_reloc_name_lookup v850_elf_reloc_name_lookup
  3526. #define bfd_elf32_bfd_merge_private_bfd_data v850_elf_merge_private_bfd_data
  3527. #define bfd_elf32_bfd_set_private_flags v850_elf_set_private_flags
  3528. #define bfd_elf32_bfd_print_private_bfd_data v850_elf_print_private_bfd_data
  3529. #define bfd_elf32_bfd_relax_section v850_elf_relax_section
  3530. #define elf_symbol_leading_char '_'
  3531. #undef elf32_bed
  3532. #define elf32_bed elf32_v850_bed
  3533. #include "elf32-target.h"
  3534. /* Map BFD reloc types to V800 ELF reloc types. */
  3535. static const struct v850_elf_reloc_map v800_elf_reloc_map[] =
  3536. {
  3537. { BFD_RELOC_NONE, R_V810_NONE },
  3538. { BFD_RELOC_8, R_V810_BYTE },
  3539. { BFD_RELOC_16, R_V810_HWORD },
  3540. { BFD_RELOC_32, R_V810_WORD },
  3541. { BFD_RELOC_LO16, R_V810_WLO },
  3542. { BFD_RELOC_HI16, R_V810_WHI },
  3543. { BFD_RELOC_HI16_S, R_V810_WHI1 },
  3544. { BFD_RELOC_V850_32_PCREL, R_V850_PC32 },
  3545. { BFD_RELOC_V850_22_PCREL, R_V850_PCR22 },
  3546. { BFD_RELOC_V850_17_PCREL, R_V850_PC17 },
  3547. { BFD_RELOC_V850_16_PCREL, R_V850_PC16U },
  3548. { BFD_RELOC_V850_9_PCREL, R_V850_PC9 },
  3549. { BFD_RELOC_V850_LO16_S1, R_V810_WLO_1 }, /* Or R_V850_HWLO or R_V850_HWLO_1. */
  3550. { BFD_RELOC_V850_23, R_V850_WLO23 },
  3551. { BFD_RELOC_V850_LO16_SPLIT_OFFSET, R_V850_BLO },
  3552. { BFD_RELOC_V850_ZDA_16_16_OFFSET, R_V810_HWORD },
  3553. { BFD_RELOC_V850_TDA_16_16_OFFSET, R_V810_HWORD },
  3554. { BFD_RELOC_V850_SDA_16_16_OFFSET, R_V810_HWORD },
  3555. { BFD_RELOC_V850_SDA_15_16_OFFSET, R_V810_GPWLO_1 }
  3556. };
  3557. /* Map a bfd relocation into the appropriate howto structure. */
  3558. static reloc_howto_type *
  3559. v800_elf_reloc_type_lookup (bfd * abfd, bfd_reloc_code_real_type code)
  3560. {
  3561. unsigned int i;
  3562. BFD_ASSERT (bfd_get_arch (abfd) == bfd_arch_v850_rh850);
  3563. for (i = ARRAY_SIZE (v800_elf_reloc_map); i --;)
  3564. if (v800_elf_reloc_map[i].bfd_reloc_val == code)
  3565. {
  3566. unsigned int elf_reloc_val = v800_elf_reloc_map[i].elf_reloc_val;
  3567. unsigned int idx = elf_reloc_val - R_V810_NONE;
  3568. BFD_ASSERT (v800_elf_howto_table[idx].type == elf_reloc_val);
  3569. return v800_elf_howto_table + idx;
  3570. }
  3571. #ifdef DEBUG
  3572. fprintf (stderr, "failed to find v800 equiv of bfd reloc code %d\n", code);
  3573. #endif
  3574. return NULL;
  3575. }
  3576. static reloc_howto_type *
  3577. v800_elf_reloc_name_lookup (bfd * abfd, const char * r_name)
  3578. {
  3579. unsigned int i;
  3580. BFD_ASSERT (bfd_get_arch (abfd) == bfd_arch_v850_rh850);
  3581. for (i = ARRAY_SIZE (v800_elf_howto_table); i--;)
  3582. if (v800_elf_howto_table[i].name != NULL
  3583. && strcasecmp (v800_elf_howto_table[i].name, r_name) == 0)
  3584. return v800_elf_howto_table + i;
  3585. return NULL;
  3586. }
  3587. /* Set the howto pointer in CACHE_PTR for a V800 ELF reloc. */
  3588. static bool
  3589. v800_elf_info_to_howto (bfd * abfd,
  3590. arelent * cache_ptr,
  3591. Elf_Internal_Rela * dst)
  3592. {
  3593. unsigned int r_type = ELF32_R_TYPE (dst->r_info);
  3594. if (r_type == R_V800_NONE)
  3595. r_type = R_V810_NONE;
  3596. if (bfd_get_arch (abfd) != bfd_arch_v850_rh850
  3597. || r_type >= (unsigned int) R_V800_max
  3598. || r_type < (unsigned int) R_V810_NONE
  3599. || (r_type - R_V810_NONE) >= ARRAY_SIZE (v800_elf_howto_table))
  3600. {
  3601. /* xgettext:c-format */
  3602. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  3603. abfd, r_type);
  3604. bfd_set_error (bfd_error_bad_value);
  3605. return false;
  3606. }
  3607. cache_ptr->howto = v800_elf_howto_table + (r_type - R_V810_NONE);
  3608. return true;
  3609. }
  3610. #undef TARGET_LITTLE_SYM
  3611. #define TARGET_LITTLE_SYM v800_elf32_vec
  3612. #undef TARGET_LITTLE_NAME
  3613. #define TARGET_LITTLE_NAME "elf32-v850-rh850"
  3614. #undef ELF_ARCH
  3615. #define ELF_ARCH bfd_arch_v850_rh850
  3616. #undef ELF_MACHINE_CODE
  3617. #define ELF_MACHINE_CODE EM_V800
  3618. #undef ELF_MACHINE_ALT1
  3619. #undef elf32_bed
  3620. #define elf32_bed elf32_v850_rh850_bed
  3621. #undef elf_info_to_howto
  3622. #define elf_info_to_howto v800_elf_info_to_howto
  3623. #undef elf_info_to_howto_rel
  3624. #define elf_info_to_howto_rel NULL
  3625. #undef bfd_elf32_bfd_reloc_type_lookup
  3626. #define bfd_elf32_bfd_reloc_type_lookup v800_elf_reloc_type_lookup
  3627. #undef bfd_elf32_bfd_reloc_name_lookup
  3628. #define bfd_elf32_bfd_reloc_name_lookup v800_elf_reloc_name_lookup
  3629. #include "elf32-target.h"