tilegx.cc 189 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974
  1. // tilegx.cc -- tilegx target support for gold.
  2. // Copyright (C) 2012-2022 Free Software Foundation, Inc.
  3. // Written by Jiong Wang (jiwang@tilera.com)
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. #include "gold.h"
  18. #include <cstring>
  19. #include "elfcpp.h"
  20. #include "dwarf.h"
  21. #include "parameters.h"
  22. #include "reloc.h"
  23. #include "tilegx.h"
  24. #include "object.h"
  25. #include "symtab.h"
  26. #include "layout.h"
  27. #include "output.h"
  28. #include "copy-relocs.h"
  29. #include "target.h"
  30. #include "target-reloc.h"
  31. #include "target-select.h"
  32. #include "tls.h"
  33. #include "gc.h"
  34. #include "icf.h"
  35. // the first got entry reserved
  36. const int32_t TILEGX_GOT_RESERVE_COUNT = 1;
  37. // the first two .got.plt entry reserved
  38. const int32_t TILEGX_GOTPLT_RESERVE_COUNT = 2;
  39. // 1. for both 64/32 bit mode, the instruction bundle is always 64bit.
  40. // 2. thus .plt section should always be aligned to 64 bit.
  41. const int32_t TILEGX_INST_BUNDLE_SIZE = 64;
  42. namespace
  43. {
  44. using namespace gold;
  45. // A class to handle the PLT data.
  46. // This is an abstract base class that handles most of the linker details
  47. // but does not know the actual contents of PLT entries. The derived
  48. // classes below fill in those details.
  49. template<int size, bool big_endian>
  50. class Output_data_plt_tilegx : public Output_section_data
  51. {
  52. public:
  53. typedef Output_data_reloc<elfcpp::SHT_RELA, true,size, big_endian>
  54. Reloc_section;
  55. Output_data_plt_tilegx(Layout* layout, uint64_t addralign,
  56. Output_data_got<size, big_endian>* got,
  57. Output_data_space* got_plt,
  58. Output_data_space* got_irelative)
  59. : Output_section_data(addralign), layout_(layout),
  60. irelative_rel_(NULL), got_(got), got_plt_(got_plt),
  61. got_irelative_(got_irelative), count_(0),
  62. irelative_count_(0), free_list_()
  63. { this->init(layout); }
  64. Output_data_plt_tilegx(Layout* layout, uint64_t plt_entry_size,
  65. Output_data_got<size, big_endian>* got,
  66. Output_data_space* got_plt,
  67. Output_data_space* got_irelative,
  68. unsigned int plt_count)
  69. : Output_section_data((plt_count + 1) * plt_entry_size,
  70. TILEGX_INST_BUNDLE_SIZE, false),
  71. layout_(layout), irelative_rel_(NULL), got_(got),
  72. got_plt_(got_plt), got_irelative_(got_irelative), count_(plt_count),
  73. irelative_count_(0), free_list_()
  74. {
  75. this->init(layout);
  76. // Initialize the free list and reserve the first entry.
  77. this->free_list_.init((plt_count + 1) * plt_entry_size, false);
  78. this->free_list_.remove(0, plt_entry_size);
  79. }
  80. // Initialize the PLT section.
  81. void
  82. init(Layout* layout);
  83. // Add an entry to the PLT.
  84. void
  85. add_entry(Symbol_table*, Layout*, Symbol* gsym);
  86. // Add an entry to the PLT for a local STT_GNU_IFUNC symbol.
  87. unsigned int
  88. add_local_ifunc_entry(Symbol_table*, Layout*,
  89. Sized_relobj_file<size, big_endian>*, unsigned int);
  90. // Add the relocation for a PLT entry.
  91. void
  92. add_relocation(Symbol_table*, Layout*, Symbol*, unsigned int);
  93. // Return the .rela.plt section data.
  94. Reloc_section*
  95. rela_plt()
  96. { return this->rel_; }
  97. // Return where the IRELATIVE relocations should go in the PLT
  98. // relocations.
  99. Reloc_section*
  100. rela_irelative(Symbol_table*, Layout*);
  101. // Return whether we created a section for IRELATIVE relocations.
  102. bool
  103. has_irelative_section() const
  104. { return this->irelative_rel_ != NULL; }
  105. // Return the number of PLT entries.
  106. unsigned int
  107. entry_count() const
  108. { return this->count_ + this->irelative_count_; }
  109. // Return the offset of the first non-reserved PLT entry.
  110. unsigned int
  111. first_plt_entry_offset()
  112. { return this->get_plt_entry_size(); }
  113. // Return the size of a PLT entry.
  114. unsigned int
  115. get_plt_entry_size() const
  116. { return plt_entry_size; }
  117. // Reserve a slot in the PLT for an existing symbol in an incremental update.
  118. void
  119. reserve_slot(unsigned int plt_index)
  120. {
  121. this->free_list_.remove((plt_index + 1) * this->get_plt_entry_size(),
  122. (plt_index + 2) * this->get_plt_entry_size());
  123. }
  124. // Return the PLT address to use for a global symbol.
  125. uint64_t
  126. address_for_global(const Symbol*);
  127. // Return the PLT address to use for a local symbol.
  128. uint64_t
  129. address_for_local(const Relobj*, unsigned int symndx);
  130. protected:
  131. // Fill in the first PLT entry.
  132. void
  133. fill_first_plt_entry(unsigned char*);
  134. // Fill in a normal PLT entry. Returns the offset into the entry that
  135. // should be the initial GOT slot value.
  136. void
  137. fill_plt_entry(unsigned char*,
  138. typename elfcpp::Elf_types<size>::Elf_Addr,
  139. unsigned int,
  140. typename elfcpp::Elf_types<size>::Elf_Addr,
  141. unsigned int, unsigned int);
  142. void
  143. do_adjust_output_section(Output_section* os);
  144. // Write to a map file.
  145. void
  146. do_print_to_mapfile(Mapfile* mapfile) const
  147. { mapfile->print_output_data(this, _("** PLT")); }
  148. private:
  149. // Set the final size.
  150. void
  151. set_final_data_size();
  152. // Write out the PLT data.
  153. void
  154. do_write(Output_file*);
  155. // A pointer to the Layout class, so that we can find the .dynamic
  156. // section when we write out the GOT PLT section.
  157. Layout* layout_;
  158. // The reloc section.
  159. Reloc_section* rel_;
  160. // The IRELATIVE relocs, if necessary. These must follow the
  161. // regular PLT relocations.
  162. Reloc_section* irelative_rel_;
  163. // The .got section.
  164. Output_data_got<size, big_endian>* got_;
  165. // The .got.plt section.
  166. Output_data_space* got_plt_;
  167. // The part of the .got.plt section used for IRELATIVE relocs.
  168. Output_data_space* got_irelative_;
  169. // The number of PLT entries.
  170. unsigned int count_;
  171. // Number of PLT entries with R_TILEGX_IRELATIVE relocs. These
  172. // follow the regular PLT entries.
  173. unsigned int irelative_count_;
  174. // List of available regions within the section, for incremental
  175. // update links.
  176. Free_list free_list_;
  177. // The size of an entry in the PLT.
  178. static const int plt_entry_size = 40;
  179. // The first entry in the PLT.
  180. static const unsigned char first_plt_entry[plt_entry_size];
  181. // Other entries in the PLT for an executable.
  182. static const unsigned char plt_entry[plt_entry_size];
  183. };
  184. // The tilegx target class.
  185. // See the ABI at
  186. // http://www.tilera.com/scm
  187. // TLS info comes from
  188. // http://people.redhat.com/drepper/tls.pdf
  189. template<int size, bool big_endian>
  190. class Target_tilegx : public Sized_target<size, big_endian>
  191. {
  192. public:
  193. // TileGX use RELA
  194. typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian>
  195. Reloc_section;
  196. Target_tilegx(const Target::Target_info* info = &tilegx_info)
  197. : Sized_target<size, big_endian>(info),
  198. got_(NULL), plt_(NULL), got_plt_(NULL), got_irelative_(NULL),
  199. global_offset_table_(NULL), tilegx_dynamic_(NULL), rela_dyn_(NULL),
  200. rela_irelative_(NULL), copy_relocs_(elfcpp::R_TILEGX_COPY),
  201. got_mod_index_offset_(-1U),
  202. tls_get_addr_sym_defined_(false)
  203. { }
  204. // Scan the relocations to look for symbol adjustments.
  205. void
  206. gc_process_relocs(Symbol_table* symtab,
  207. Layout* layout,
  208. Sized_relobj_file<size, big_endian>* object,
  209. unsigned int data_shndx,
  210. unsigned int sh_type,
  211. const unsigned char* prelocs,
  212. size_t reloc_count,
  213. Output_section* output_section,
  214. bool needs_special_offset_handling,
  215. size_t local_symbol_count,
  216. const unsigned char* plocal_symbols);
  217. // Scan the relocations to look for symbol adjustments.
  218. void
  219. scan_relocs(Symbol_table* symtab,
  220. Layout* layout,
  221. Sized_relobj_file<size, big_endian>* object,
  222. unsigned int data_shndx,
  223. unsigned int sh_type,
  224. const unsigned char* prelocs,
  225. size_t reloc_count,
  226. Output_section* output_section,
  227. bool needs_special_offset_handling,
  228. size_t local_symbol_count,
  229. const unsigned char* plocal_symbols);
  230. // Finalize the sections.
  231. void
  232. do_finalize_sections(Layout*, const Input_objects*, Symbol_table*);
  233. // Return the value to use for a dynamic which requires special
  234. // treatment.
  235. uint64_t
  236. do_dynsym_value(const Symbol*) const;
  237. // Relocate a section.
  238. void
  239. relocate_section(const Relocate_info<size, big_endian>*,
  240. unsigned int sh_type,
  241. const unsigned char* prelocs,
  242. size_t reloc_count,
  243. Output_section* output_section,
  244. bool needs_special_offset_handling,
  245. unsigned char* view,
  246. typename elfcpp::Elf_types<size>::Elf_Addr view_address,
  247. section_size_type view_size,
  248. const Reloc_symbol_changes*);
  249. // Scan the relocs during a relocatable link.
  250. void
  251. scan_relocatable_relocs(Symbol_table* symtab,
  252. Layout* layout,
  253. Sized_relobj_file<size, big_endian>* object,
  254. unsigned int data_shndx,
  255. unsigned int sh_type,
  256. const unsigned char* prelocs,
  257. size_t reloc_count,
  258. Output_section* output_section,
  259. bool needs_special_offset_handling,
  260. size_t local_symbol_count,
  261. const unsigned char* plocal_symbols,
  262. Relocatable_relocs*);
  263. // Scan the relocs for --emit-relocs.
  264. void
  265. emit_relocs_scan(Symbol_table* symtab,
  266. Layout* layout,
  267. Sized_relobj_file<size, big_endian>* object,
  268. unsigned int data_shndx,
  269. unsigned int sh_type,
  270. const unsigned char* prelocs,
  271. size_t reloc_count,
  272. Output_section* output_section,
  273. bool needs_special_offset_handling,
  274. size_t local_symbol_count,
  275. const unsigned char* plocal_syms,
  276. Relocatable_relocs* rr);
  277. // Relocate a section during a relocatable link.
  278. void
  279. relocate_relocs(
  280. const Relocate_info<size, big_endian>*,
  281. unsigned int sh_type,
  282. const unsigned char* prelocs,
  283. size_t reloc_count,
  284. Output_section* output_section,
  285. typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
  286. unsigned char* view,
  287. typename elfcpp::Elf_types<size>::Elf_Addr view_address,
  288. section_size_type view_size,
  289. unsigned char* reloc_view,
  290. section_size_type reloc_view_size);
  291. // Return whether SYM is defined by the ABI.
  292. bool
  293. do_is_defined_by_abi(const Symbol* sym) const
  294. { return strcmp(sym->name(), "__tls_get_addr") == 0; }
  295. // define tilegx specific symbols
  296. virtual void
  297. do_define_standard_symbols(Symbol_table*, Layout*);
  298. // Return the PLT section.
  299. uint64_t
  300. do_plt_address_for_global(const Symbol* gsym) const
  301. { return this->plt_section()->address_for_global(gsym); }
  302. uint64_t
  303. do_plt_address_for_local(const Relobj* relobj, unsigned int symndx) const
  304. { return this->plt_section()->address_for_local(relobj, symndx); }
  305. // This function should be defined in targets that can use relocation
  306. // types to determine (implemented in local_reloc_may_be_function_pointer
  307. // and global_reloc_may_be_function_pointer)
  308. // if a function's pointer is taken. ICF uses this in safe mode to only
  309. // fold those functions whose pointer is defintely not taken. For tilegx
  310. // pie binaries, safe ICF cannot be done by looking at relocation types.
  311. bool
  312. do_can_check_for_function_pointers() const
  313. { return true; }
  314. // Return the base for a DW_EH_PE_datarel encoding.
  315. uint64_t
  316. do_ehframe_datarel_base() const;
  317. // Return whether there is a GOT section.
  318. bool
  319. has_got_section() const
  320. { return this->got_ != NULL; }
  321. // Return the size of the GOT section.
  322. section_size_type
  323. got_size() const
  324. {
  325. gold_assert(this->got_ != NULL);
  326. return this->got_->data_size();
  327. }
  328. // Return the number of entries in the GOT.
  329. unsigned int
  330. got_entry_count() const
  331. {
  332. if (this->got_ == NULL)
  333. return 0;
  334. return this->got_size() / (size / 8);
  335. }
  336. // Return the number of entries in the PLT.
  337. unsigned int
  338. plt_entry_count() const;
  339. // Return the offset of the first non-reserved PLT entry.
  340. unsigned int
  341. first_plt_entry_offset() const;
  342. // Return the size of each PLT entry.
  343. unsigned int
  344. plt_entry_size() const;
  345. // Create the GOT section for an incremental update.
  346. Output_data_got_base*
  347. init_got_plt_for_update(Symbol_table* symtab,
  348. Layout* layout,
  349. unsigned int got_count,
  350. unsigned int plt_count);
  351. // Reserve a GOT entry for a local symbol, and regenerate any
  352. // necessary dynamic relocations.
  353. void
  354. reserve_local_got_entry(unsigned int got_index,
  355. Sized_relobj<size, big_endian>* obj,
  356. unsigned int r_sym,
  357. unsigned int got_type);
  358. // Reserve a GOT entry for a global symbol, and regenerate any
  359. // necessary dynamic relocations.
  360. void
  361. reserve_global_got_entry(unsigned int got_index, Symbol* gsym,
  362. unsigned int got_type);
  363. // Register an existing PLT entry for a global symbol.
  364. void
  365. register_global_plt_entry(Symbol_table*, Layout*, unsigned int plt_index,
  366. Symbol* gsym);
  367. // Force a COPY relocation for a given symbol.
  368. void
  369. emit_copy_reloc(Symbol_table*, Symbol*, Output_section*, off_t);
  370. // Apply an incremental relocation.
  371. void
  372. apply_relocation(const Relocate_info<size, big_endian>* relinfo,
  373. typename elfcpp::Elf_types<size>::Elf_Addr r_offset,
  374. unsigned int r_type,
  375. typename elfcpp::Elf_types<size>::Elf_Swxword r_addend,
  376. const Symbol* gsym,
  377. unsigned char* view,
  378. typename elfcpp::Elf_types<size>::Elf_Addr address,
  379. section_size_type view_size);
  380. private:
  381. // The class which scans relocations.
  382. class Scan
  383. {
  384. public:
  385. Scan()
  386. : issued_non_pic_error_(false)
  387. { }
  388. static inline int
  389. get_reference_flags(unsigned int r_type);
  390. inline void
  391. local(Symbol_table* symtab, Layout* layout, Target_tilegx* target,
  392. Sized_relobj_file<size, big_endian>* object,
  393. unsigned int data_shndx,
  394. Output_section* output_section,
  395. const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
  396. const elfcpp::Sym<size, big_endian>& lsym,
  397. bool is_discarded);
  398. inline void
  399. global(Symbol_table* symtab, Layout* layout, Target_tilegx* target,
  400. Sized_relobj_file<size, big_endian>* object,
  401. unsigned int data_shndx,
  402. Output_section* output_section,
  403. const elfcpp::Rela<size, big_endian>& reloc, unsigned int r_type,
  404. Symbol* gsym);
  405. inline bool
  406. local_reloc_may_be_function_pointer(Symbol_table* symtab, Layout* layout,
  407. Target_tilegx* target,
  408. Sized_relobj_file<size, big_endian>* object,
  409. unsigned int data_shndx,
  410. Output_section* output_section,
  411. const elfcpp::Rela<size, big_endian>& reloc,
  412. unsigned int r_type,
  413. const elfcpp::Sym<size, big_endian>& lsym);
  414. inline bool
  415. global_reloc_may_be_function_pointer(Symbol_table* symtab, Layout* layout,
  416. Target_tilegx* target,
  417. Sized_relobj_file<size, big_endian>* object,
  418. unsigned int data_shndx,
  419. Output_section* output_section,
  420. const elfcpp::Rela<size, big_endian>& reloc,
  421. unsigned int r_type,
  422. Symbol* gsym);
  423. private:
  424. static void
  425. unsupported_reloc_local(Sized_relobj_file<size, big_endian>*,
  426. unsigned int r_type);
  427. static void
  428. unsupported_reloc_global(Sized_relobj_file<size, big_endian>*,
  429. unsigned int r_type, Symbol*);
  430. void
  431. check_non_pic(Relobj*, unsigned int r_type);
  432. inline bool
  433. possible_function_pointer_reloc(unsigned int r_type);
  434. bool
  435. reloc_needs_plt_for_ifunc(Sized_relobj_file<size, big_endian>*,
  436. unsigned int r_type);
  437. // Whether we have issued an error about a non-PIC compilation.
  438. bool issued_non_pic_error_;
  439. };
  440. // The class which implements relocation.
  441. class Relocate
  442. {
  443. public:
  444. Relocate()
  445. { }
  446. ~Relocate()
  447. {
  448. }
  449. // Do a relocation. Return false if the caller should not issue
  450. // any warnings about this relocation.
  451. inline bool
  452. relocate(const Relocate_info<size, big_endian>*, unsigned int,
  453. Target_tilegx*, Output_section*, size_t, const unsigned char*,
  454. const Sized_symbol<size>*, const Symbol_value<size>*,
  455. unsigned char*, typename elfcpp::Elf_types<size>::Elf_Addr,
  456. section_size_type);
  457. };
  458. // Adjust TLS relocation type based on the options and whether this
  459. // is a local symbol.
  460. static tls::Tls_optimization
  461. optimize_tls_reloc(bool is_final, int r_type);
  462. // Get the GOT section, creating it if necessary.
  463. Output_data_got<size, big_endian>*
  464. got_section(Symbol_table*, Layout*);
  465. // Get the GOT PLT section.
  466. Output_data_space*
  467. got_plt_section() const
  468. {
  469. gold_assert(this->got_plt_ != NULL);
  470. return this->got_plt_;
  471. }
  472. // Create the PLT section.
  473. void
  474. make_plt_section(Symbol_table* symtab, Layout* layout);
  475. // Create a PLT entry for a global symbol.
  476. void
  477. make_plt_entry(Symbol_table*, Layout*, Symbol*);
  478. // Create a PLT entry for a local STT_GNU_IFUNC symbol.
  479. void
  480. make_local_ifunc_plt_entry(Symbol_table*, Layout*,
  481. Sized_relobj_file<size, big_endian>* relobj,
  482. unsigned int local_sym_index);
  483. // Create a GOT entry for the TLS module index.
  484. unsigned int
  485. got_mod_index_entry(Symbol_table* symtab, Layout* layout,
  486. Sized_relobj_file<size, big_endian>* object);
  487. // Get the PLT section.
  488. Output_data_plt_tilegx<size, big_endian>*
  489. plt_section() const
  490. {
  491. gold_assert(this->plt_ != NULL);
  492. return this->plt_;
  493. }
  494. // Get the dynamic reloc section, creating it if necessary.
  495. Reloc_section*
  496. rela_dyn_section(Layout*);
  497. // Get the section to use for IRELATIVE relocations.
  498. Reloc_section*
  499. rela_irelative_section(Layout*);
  500. // Add a potential copy relocation.
  501. void
  502. copy_reloc(Symbol_table* symtab, Layout* layout,
  503. Sized_relobj_file<size, big_endian>* object,
  504. unsigned int shndx, Output_section* output_section,
  505. Symbol* sym, const elfcpp::Rela<size, big_endian>& reloc)
  506. {
  507. unsigned int r_type = elfcpp::elf_r_type<size>(reloc.get_r_info());
  508. this->copy_relocs_.copy_reloc(symtab, layout,
  509. symtab->get_sized_symbol<size>(sym),
  510. object, shndx, output_section,
  511. r_type, reloc.get_r_offset(),
  512. reloc.get_r_addend(),
  513. this->rela_dyn_section(layout));
  514. }
  515. // Information about this specific target which we pass to the
  516. // general Target structure.
  517. static const Target::Target_info tilegx_info;
  518. // The types of GOT entries needed for this platform.
  519. // These values are exposed to the ABI in an incremental link.
  520. // Do not renumber existing values without changing the version
  521. // number of the .gnu_incremental_inputs section.
  522. enum Got_type
  523. {
  524. GOT_TYPE_STANDARD = 0, // GOT entry for a regular symbol
  525. GOT_TYPE_TLS_OFFSET = 1, // GOT entry for TLS offset
  526. GOT_TYPE_TLS_PAIR = 2, // GOT entry for TLS module/offset pair
  527. GOT_TYPE_TLS_DESC = 3 // GOT entry for TLS_DESC pair
  528. };
  529. // This type is used as the argument to the target specific
  530. // relocation routines. The only target specific reloc is
  531. // R_X86_64_TLSDESC against a local symbol.
  532. struct Tlsdesc_info
  533. {
  534. Tlsdesc_info(Sized_relobj_file<size, big_endian>* a_object,
  535. unsigned int a_r_sym)
  536. : object(a_object), r_sym(a_r_sym)
  537. { }
  538. // The object in which the local symbol is defined.
  539. Sized_relobj_file<size, big_endian>* object;
  540. // The local symbol index in the object.
  541. unsigned int r_sym;
  542. };
  543. // The GOT section.
  544. Output_data_got<size, big_endian>* got_;
  545. // The PLT section.
  546. Output_data_plt_tilegx<size, big_endian>* plt_;
  547. // The GOT PLT section.
  548. Output_data_space* got_plt_;
  549. // The GOT section for IRELATIVE relocations.
  550. Output_data_space* got_irelative_;
  551. // The _GLOBAL_OFFSET_TABLE_ symbol.
  552. Symbol* global_offset_table_;
  553. // The _TILEGX_DYNAMIC_ symbol.
  554. Symbol* tilegx_dynamic_;
  555. // The dynamic reloc section.
  556. Reloc_section* rela_dyn_;
  557. // The section to use for IRELATIVE relocs.
  558. Reloc_section* rela_irelative_;
  559. // Relocs saved to avoid a COPY reloc.
  560. Copy_relocs<elfcpp::SHT_RELA, size, big_endian> copy_relocs_;
  561. // Offset of the GOT entry for the TLS module index.
  562. unsigned int got_mod_index_offset_;
  563. // True if the _tls_get_addr symbol has been defined.
  564. bool tls_get_addr_sym_defined_;
  565. };
  566. template<>
  567. const Target::Target_info Target_tilegx<64, false>::tilegx_info =
  568. {
  569. 64, // size
  570. false, // is_big_endian
  571. elfcpp::EM_TILEGX, // machine_code
  572. false, // has_make_symbol
  573. false, // has_resolve
  574. false, // has_code_fill
  575. true, // is_default_stack_executable
  576. false, // can_icf_inline_merge_sections
  577. '\0', // wrap_char
  578. "/lib/ld.so.1", // program interpreter
  579. 0x10000, // default_text_segment_address
  580. 0x10000, // abi_pagesize (overridable by -z max-page-size)
  581. 0x10000, // common_pagesize (overridable by -z common-page-size)
  582. false, // isolate_execinstr
  583. 0, // rosegment_gap
  584. elfcpp::SHN_UNDEF, // small_common_shndx
  585. elfcpp::SHN_UNDEF, // large_common_shndx
  586. 0, // small_common_section_flags
  587. 0, // large_common_section_flags
  588. NULL, // attributes_section
  589. NULL, // attributes_vendor
  590. "_start", // entry_symbol_name
  591. 32, // hash_entry_size
  592. elfcpp::SHT_PROGBITS, // unwind_section_type
  593. };
  594. template<>
  595. const Target::Target_info Target_tilegx<32, false>::tilegx_info =
  596. {
  597. 32, // size
  598. false, // is_big_endian
  599. elfcpp::EM_TILEGX, // machine_code
  600. false, // has_make_symbol
  601. false, // has_resolve
  602. false, // has_code_fill
  603. true, // is_default_stack_executable
  604. false, // can_icf_inline_merge_sections
  605. '\0', // wrap_char
  606. "/lib32/ld.so.1", // program interpreter
  607. 0x10000, // default_text_segment_address
  608. 0x10000, // abi_pagesize (overridable by -z max-page-size)
  609. 0x10000, // common_pagesize (overridable by -z common-page-size)
  610. false, // isolate_execinstr
  611. 0, // rosegment_gap
  612. elfcpp::SHN_UNDEF, // small_common_shndx
  613. elfcpp::SHN_UNDEF, // large_common_shndx
  614. 0, // small_common_section_flags
  615. 0, // large_common_section_flags
  616. NULL, // attributes_section
  617. NULL, // attributes_vendor
  618. "_start", // entry_symbol_name
  619. 32, // hash_entry_size
  620. elfcpp::SHT_PROGBITS, // unwind_section_type
  621. };
  622. template<>
  623. const Target::Target_info Target_tilegx<64, true>::tilegx_info =
  624. {
  625. 64, // size
  626. true, // is_big_endian
  627. elfcpp::EM_TILEGX, // machine_code
  628. false, // has_make_symbol
  629. false, // has_resolve
  630. false, // has_code_fill
  631. true, // is_default_stack_executable
  632. false, // can_icf_inline_merge_sections
  633. '\0', // wrap_char
  634. "/lib/ld.so.1", // program interpreter
  635. 0x10000, // default_text_segment_address
  636. 0x10000, // abi_pagesize (overridable by -z max-page-size)
  637. 0x10000, // common_pagesize (overridable by -z common-page-size)
  638. false, // isolate_execinstr
  639. 0, // rosegment_gap
  640. elfcpp::SHN_UNDEF, // small_common_shndx
  641. elfcpp::SHN_UNDEF, // large_common_shndx
  642. 0, // small_common_section_flags
  643. 0, // large_common_section_flags
  644. NULL, // attributes_section
  645. NULL, // attributes_vendor
  646. "_start", // entry_symbol_name
  647. 32, // hash_entry_size
  648. elfcpp::SHT_PROGBITS, // unwind_section_type
  649. };
  650. template<>
  651. const Target::Target_info Target_tilegx<32, true>::tilegx_info =
  652. {
  653. 32, // size
  654. true, // is_big_endian
  655. elfcpp::EM_TILEGX, // machine_code
  656. false, // has_make_symbol
  657. false, // has_resolve
  658. false, // has_code_fill
  659. true, // is_default_stack_executable
  660. false, // can_icf_inline_merge_sections
  661. '\0', // wrap_char
  662. "/lib32/ld.so.1", // program interpreter
  663. 0x10000, // default_text_segment_address
  664. 0x10000, // abi_pagesize (overridable by -z max-page-size)
  665. 0x10000, // common_pagesize (overridable by -z common-page-size)
  666. false, // isolate_execinstr
  667. 0, // rosegment_gap
  668. elfcpp::SHN_UNDEF, // small_common_shndx
  669. elfcpp::SHN_UNDEF, // large_common_shndx
  670. 0, // small_common_section_flags
  671. 0, // large_common_section_flags
  672. NULL, // attributes_section
  673. NULL, // attributes_vendor
  674. "_start", // entry_symbol_name
  675. 32, // hash_entry_size
  676. elfcpp::SHT_PROGBITS, // unwind_section_type
  677. };
  678. // tilegx relocation handlers
  679. template<int size, bool big_endian>
  680. class Tilegx_relocate_functions
  681. {
  682. public:
  683. // overflow check will be supported later
  684. typedef enum
  685. {
  686. STATUS_OKAY, // No error during relocation.
  687. STATUS_OVERFLOW, // Relocation overflow.
  688. STATUS_BAD_RELOC // Relocation cannot be applied.
  689. } Status;
  690. struct Tilegx_howto
  691. {
  692. // right shift operand by this number of bits.
  693. unsigned char srshift;
  694. // the offset to apply relocation.
  695. unsigned char doffset;
  696. // set to 1 for pc-relative relocation.
  697. unsigned char is_pcrel;
  698. // size in bits, or 0 if this table entry should be ignored.
  699. unsigned char bsize;
  700. // whether we need to check overflow.
  701. unsigned char overflow;
  702. };
  703. static const Tilegx_howto howto[elfcpp::R_TILEGX_NUM];
  704. private:
  705. // Do a simple rela relocation
  706. template<int valsize>
  707. static inline void
  708. rela(unsigned char* view,
  709. const Sized_relobj_file<size, big_endian>* object,
  710. const Symbol_value<size>* psymval,
  711. typename elfcpp::Swap<size, big_endian>::Valtype addend,
  712. elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset,
  713. elfcpp::Elf_Xword bitmask)
  714. {
  715. typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
  716. Valtype* wv = reinterpret_cast<Valtype*>(view);
  717. Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
  718. Valtype reloc = 0;
  719. if (size == 32)
  720. reloc = Bits<32>::sign_extend(psymval->value(object, addend)) >> srshift;
  721. else
  722. reloc = psymval->value(object, addend) >> srshift;
  723. elfcpp::Elf_Xword dst_mask = bitmask << doffset;
  724. val &= ~dst_mask;
  725. reloc &= bitmask;
  726. elfcpp::Swap<valsize, big_endian>::writeval(wv, val | (reloc<<doffset));
  727. }
  728. // Do a simple rela relocation
  729. template<int valsize>
  730. static inline void
  731. rela_ua(unsigned char* view,
  732. const Sized_relobj_file<size, big_endian>* object,
  733. const Symbol_value<size>* psymval,
  734. typename elfcpp::Swap<size, big_endian>::Valtype addend,
  735. elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset,
  736. elfcpp::Elf_Xword bitmask)
  737. {
  738. typedef typename elfcpp::Swap_unaligned<valsize, big_endian>::Valtype
  739. Valtype;
  740. unsigned char* wv = view;
  741. Valtype val = elfcpp::Swap_unaligned<valsize, big_endian>::readval(wv);
  742. Valtype reloc = 0;
  743. if (size == 32)
  744. reloc = Bits<32>::sign_extend(psymval->value(object, addend)) >> srshift;
  745. else
  746. reloc = psymval->value(object, addend) >> srshift;
  747. elfcpp::Elf_Xword dst_mask = bitmask << doffset;
  748. val &= ~dst_mask;
  749. reloc &= bitmask;
  750. elfcpp::Swap_unaligned<valsize, big_endian>::writeval(wv,
  751. val | (reloc<<doffset));
  752. }
  753. template<int valsize>
  754. static inline void
  755. rela(unsigned char* view,
  756. const Sized_relobj_file<size, big_endian>* object,
  757. const Symbol_value<size>* psymval,
  758. typename elfcpp::Swap<size, big_endian>::Valtype addend,
  759. elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset1,
  760. elfcpp::Elf_Xword bitmask1, elfcpp::Elf_Xword doffset2,
  761. elfcpp::Elf_Xword bitmask2)
  762. {
  763. typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
  764. Valtype* wv = reinterpret_cast<Valtype*>(view);
  765. Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
  766. Valtype reloc = 0;
  767. if (size == 32)
  768. reloc = Bits<32>::sign_extend(psymval->value(object, addend)) >> srshift;
  769. else
  770. reloc = psymval->value(object, addend) >> srshift;
  771. elfcpp::Elf_Xword dst_mask = (bitmask1 << doffset1)
  772. | (bitmask2 << doffset2);
  773. val &= ~dst_mask;
  774. reloc = ((reloc & bitmask1) << doffset1)
  775. | ((reloc & bitmask2) << doffset2);
  776. elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
  777. }
  778. // Do a simple PC relative relocation with a Symbol_value with the
  779. // addend in the relocation.
  780. template<int valsize>
  781. static inline void
  782. pcrela(unsigned char* view,
  783. const Sized_relobj_file<size, big_endian>* object,
  784. const Symbol_value<size>* psymval,
  785. typename elfcpp::Swap<size, big_endian>::Valtype addend,
  786. typename elfcpp::Elf_types<size>::Elf_Addr address,
  787. elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset,
  788. elfcpp::Elf_Xword bitmask)
  789. {
  790. typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
  791. Valtype* wv = reinterpret_cast<Valtype*>(view);
  792. Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
  793. Valtype reloc = 0;
  794. if (size == 32)
  795. reloc = Bits<32>::sign_extend(psymval->value(object, addend) - address)
  796. >> srshift;
  797. else
  798. reloc = (psymval->value(object, addend) - address) >> srshift;
  799. elfcpp::Elf_Xword dst_mask = bitmask << doffset;
  800. val &= ~dst_mask;
  801. reloc &= bitmask;
  802. elfcpp::Swap<valsize, big_endian>::writeval(wv, val | (reloc<<doffset));
  803. }
  804. template<int valsize>
  805. static inline void
  806. pcrela_ua(unsigned char* view,
  807. const Sized_relobj_file<size, big_endian>* object,
  808. const Symbol_value<size>* psymval,
  809. typename elfcpp::Swap<size, big_endian>::Valtype addend,
  810. typename elfcpp::Elf_types<size>::Elf_Addr address,
  811. elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset,
  812. elfcpp::Elf_Xword bitmask)
  813. {
  814. typedef typename elfcpp::Swap_unaligned<valsize, big_endian>::Valtype
  815. Valtype;
  816. unsigned char* wv = view;
  817. Valtype reloc = 0;
  818. if (size == 32)
  819. reloc = Bits<32>::sign_extend(psymval->value(object, addend) - address)
  820. >> srshift;
  821. else
  822. reloc = (psymval->value(object, addend) - address) >> srshift;
  823. reloc &= bitmask;
  824. elfcpp::Swap<valsize, big_endian>::writeval(wv, reloc << doffset);
  825. }
  826. template<int valsize>
  827. static inline void
  828. pcrela(unsigned char* view,
  829. const Sized_relobj_file<size, big_endian>* object,
  830. const Symbol_value<size>* psymval,
  831. typename elfcpp::Swap<size, big_endian>::Valtype addend,
  832. typename elfcpp::Elf_types<size>::Elf_Addr address,
  833. elfcpp::Elf_Xword srshift, elfcpp::Elf_Xword doffset1,
  834. elfcpp::Elf_Xword bitmask1, elfcpp::Elf_Xword doffset2,
  835. elfcpp::Elf_Xword bitmask2)
  836. {
  837. typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
  838. Valtype* wv = reinterpret_cast<Valtype*>(view);
  839. Valtype val = elfcpp::Swap<valsize, big_endian>::readval(wv);
  840. Valtype reloc = 0;
  841. if (size == 32)
  842. reloc = Bits<32>::sign_extend(psymval->value(object, addend) - address)
  843. >> srshift;
  844. else
  845. reloc = (psymval->value(object, addend) - address) >> srshift;
  846. elfcpp::Elf_Xword dst_mask = (bitmask1 << doffset1)
  847. | (bitmask2 << doffset2);
  848. val &= ~dst_mask;
  849. reloc = ((reloc & bitmask1) << doffset1)
  850. | ((reloc & bitmask2) << doffset2);
  851. elfcpp::Swap<valsize, big_endian>::writeval(wv, val | reloc);
  852. }
  853. typedef Tilegx_relocate_functions<size, big_endian> This;
  854. typedef Relocate_functions<size, big_endian> Base;
  855. public:
  856. static inline void
  857. abs64(unsigned char* view,
  858. const Sized_relobj_file<size, big_endian>* object,
  859. const Symbol_value<size>* psymval,
  860. typename elfcpp::Elf_types<size>::Elf_Addr addend)
  861. {
  862. This::template rela_ua<64>(view, object, psymval, addend, 0, 0,
  863. 0xffffffffffffffffllu);
  864. }
  865. static inline void
  866. abs32(unsigned char* view,
  867. const Sized_relobj_file<size, big_endian>* object,
  868. const Symbol_value<size>* psymval,
  869. typename elfcpp::Elf_types<size>::Elf_Addr addend)
  870. {
  871. This::template rela_ua<32>(view, object, psymval, addend, 0, 0,
  872. 0xffffffff);
  873. }
  874. static inline void
  875. abs16(unsigned char* view,
  876. const Sized_relobj_file<size, big_endian>* object,
  877. const Symbol_value<size>* psymval,
  878. typename elfcpp::Elf_types<size>::Elf_Addr addend)
  879. {
  880. This::template rela_ua<16>(view, object, psymval, addend, 0, 0,
  881. 0xffff);
  882. }
  883. static inline void
  884. pc_abs64(unsigned char* view,
  885. const Sized_relobj_file<size, big_endian>* object,
  886. const Symbol_value<size>* psymval,
  887. typename elfcpp::Elf_types<size>::Elf_Addr addend,
  888. typename elfcpp::Elf_types<size>::Elf_Addr address)
  889. {
  890. This::template pcrela_ua<64>(view, object, psymval, addend, address, 0, 0,
  891. 0xffffffffffffffffllu);
  892. }
  893. static inline void
  894. pc_abs32(unsigned char* view,
  895. const Sized_relobj_file<size, big_endian>* object,
  896. const Symbol_value<size>* psymval,
  897. typename elfcpp::Elf_types<size>::Elf_Addr addend,
  898. typename elfcpp::Elf_types<size>::Elf_Addr address)
  899. {
  900. This::template pcrela_ua<32>(view, object, psymval, addend, address, 0, 0,
  901. 0xffffffff);
  902. }
  903. static inline void
  904. pc_abs16(unsigned char* view,
  905. const Sized_relobj_file<size, big_endian>* object,
  906. const Symbol_value<size>* psymval,
  907. typename elfcpp::Elf_types<size>::Elf_Addr addend,
  908. typename elfcpp::Elf_types<size>::Elf_Addr address)
  909. {
  910. This::template pcrela_ua<16>(view, object, psymval, addend, address, 0, 0,
  911. 0xffff);
  912. }
  913. static inline void
  914. imm_x_general(unsigned char* view,
  915. const Sized_relobj_file<size, big_endian>* object,
  916. const Symbol_value<size>* psymval,
  917. typename elfcpp::Elf_types<size>::Elf_Addr addend,
  918. Tilegx_howto &r_howto)
  919. {
  920. This::template rela<64>(view, object, psymval, addend,
  921. (elfcpp::Elf_Xword)(r_howto.srshift),
  922. (elfcpp::Elf_Xword)(r_howto.doffset),
  923. (elfcpp::Elf_Xword)((1 << r_howto.bsize) - 1));
  924. }
  925. static inline void
  926. imm_x_pcrel_general(unsigned char* view,
  927. const Sized_relobj_file<size, big_endian>* object,
  928. const Symbol_value<size>* psymval,
  929. typename elfcpp::Elf_types<size>::Elf_Addr addend,
  930. typename elfcpp::Elf_types<size>::Elf_Addr address,
  931. Tilegx_howto &r_howto)
  932. {
  933. This::template pcrela<64>(view, object, psymval, addend, address,
  934. (elfcpp::Elf_Xword)(r_howto.srshift),
  935. (elfcpp::Elf_Xword)(r_howto.doffset),
  936. (elfcpp::Elf_Xword)((1 << r_howto.bsize) - 1));
  937. }
  938. static inline void
  939. imm_x_two_part_general(unsigned char* view,
  940. const Sized_relobj_file<size, big_endian>* object,
  941. const Symbol_value<size>* psymval,
  942. typename elfcpp::Elf_types<size>::Elf_Addr addend,
  943. typename elfcpp::Elf_types<size>::Elf_Addr address,
  944. unsigned int r_type)
  945. {
  946. elfcpp::Elf_Xword doffset1 = 0llu;
  947. elfcpp::Elf_Xword doffset2 = 0llu;
  948. elfcpp::Elf_Xword dmask1 = 0llu;
  949. elfcpp::Elf_Xword dmask2 = 0llu;
  950. elfcpp::Elf_Xword rshift = 0llu;
  951. unsigned int pc_rel = 0;
  952. switch (r_type)
  953. {
  954. case elfcpp::R_TILEGX_BROFF_X1:
  955. doffset1 = 31llu;
  956. doffset2 = 37llu;
  957. dmask1 = 0x3fllu;
  958. dmask2 = 0x1ffc0llu;
  959. rshift = 3llu;
  960. pc_rel = 1;
  961. break;
  962. case elfcpp::R_TILEGX_DEST_IMM8_X1:
  963. doffset1 = 31llu;
  964. doffset2 = 43llu;
  965. dmask1 = 0x3fllu;
  966. dmask2 = 0xc0llu;
  967. rshift = 0llu;
  968. break;
  969. }
  970. if (pc_rel)
  971. This::template pcrela<64>(view, object, psymval, addend, address,
  972. rshift, doffset1, dmask1, doffset2, dmask2);
  973. else
  974. This::template rela<64>(view, object, psymval, addend, rshift,
  975. doffset1, dmask1, doffset2, dmask2);
  976. }
  977. static inline void
  978. tls_relax(unsigned char* view, unsigned int r_type,
  979. tls::Tls_optimization opt_t)
  980. {
  981. const uint64_t TILEGX_X_MOVE_R0_R0 = 0x283bf8005107f000llu;
  982. const uint64_t TILEGX_Y_MOVE_R0_R0 = 0xae05f800540bf000llu;
  983. const uint64_t TILEGX_X_LD = 0x286ae80000000000llu;
  984. const uint64_t TILEGX_X_LD4S = 0x286a980000000000llu;
  985. const uint64_t TILEGX_X1_FULL_MASK = 0x3fffffff80000000llu;
  986. const uint64_t TILEGX_X0_RRR_MASK = 0x000000007ffc0000llu;
  987. const uint64_t TILEGX_X1_RRR_MASK = 0x3ffe000000000000llu;
  988. const uint64_t TILEGX_Y0_RRR_MASK = 0x00000000780c0000llu;
  989. const uint64_t TILEGX_Y1_RRR_MASK = 0x3c06000000000000llu;
  990. const uint64_t TILEGX_X0_RRR_SRCB_MASK = 0x000000007ffff000llu;
  991. const uint64_t TILEGX_X1_RRR_SRCB_MASK = 0x3ffff80000000000llu;
  992. const uint64_t TILEGX_Y0_RRR_SRCB_MASK = 0x00000000780ff000llu;
  993. const uint64_t TILEGX_Y1_RRR_SRCB_MASK = 0x3c07f80000000000llu;
  994. const uint64_t TILEGX_X_ADD_R0_R0_TP = 0x2807a800500f5000llu;
  995. const uint64_t TILEGX_Y_ADD_R0_R0_TP = 0x9a13a8002c275000llu;
  996. const uint64_t TILEGX_X_ADDX_R0_R0_TP = 0x2805a800500b5000llu;
  997. const uint64_t TILEGX_Y_ADDX_R0_R0_TP = 0x9a01a8002c035000llu;
  998. const uint64_t R_TILEGX_IMM8_X0_TLS_ADD_MASK =
  999. (TILEGX_X0_RRR_MASK | (0x3Fllu << 12));
  1000. const uint64_t R_TILEGX_IMM8_X1_TLS_ADD_MASK =
  1001. (TILEGX_X1_RRR_MASK | (0x3Fllu << 43));
  1002. const uint64_t R_TILEGX_IMM8_Y0_TLS_ADD_MASK =
  1003. (TILEGX_Y0_RRR_MASK | (0x3Fllu << 12));
  1004. const uint64_t R_TILEGX_IMM8_Y1_TLS_ADD_MASK =
  1005. (TILEGX_Y1_RRR_MASK | (0x3Fllu << 43));
  1006. const uint64_t R_TILEGX_IMM8_X0_TLS_ADD_LE_MASK =
  1007. (TILEGX_X0_RRR_SRCB_MASK | (0x3Fllu << 6));
  1008. const uint64_t R_TILEGX_IMM8_X1_TLS_ADD_LE_MASK =
  1009. (TILEGX_X1_RRR_SRCB_MASK | (0x3Fllu << 37));
  1010. const uint64_t R_TILEGX_IMM8_Y0_TLS_ADD_LE_MASK =
  1011. (TILEGX_Y0_RRR_SRCB_MASK | (0x3Fllu << 6));
  1012. const uint64_t R_TILEGX_IMM8_Y1_TLS_ADD_LE_MASK =
  1013. (TILEGX_Y1_RRR_SRCB_MASK | (0x3Fllu << 37));
  1014. typedef typename elfcpp::Swap<64, big_endian>::Valtype Valtype;
  1015. Valtype* wv = reinterpret_cast<Valtype*>(view);
  1016. Valtype val = elfcpp::Swap<64, big_endian>::readval(wv);
  1017. Valtype reloc = 0;
  1018. switch (r_type)
  1019. {
  1020. case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
  1021. if (opt_t == tls::TLSOPT_NONE) {
  1022. // GD/IE: 1. copy dest operand into the second source operand
  1023. // 2. change the opcode to "add"
  1024. reloc = (val & 0x3Fllu) << 12; // featch the dest reg
  1025. reloc |= ((size == 32
  1026. ? TILEGX_X_ADDX_R0_R0_TP
  1027. : TILEGX_X_ADD_R0_R0_TP)
  1028. & TILEGX_X0_RRR_MASK); // change opcode
  1029. val &= ~R_TILEGX_IMM8_X0_TLS_ADD_MASK;
  1030. } else if (opt_t == tls::TLSOPT_TO_LE) {
  1031. // LE: 1. copy dest operand into the first source operand
  1032. // 2. change the opcode to "move"
  1033. reloc = (val & 0x3Fllu) << 6;
  1034. reloc |= (TILEGX_X_MOVE_R0_R0 & TILEGX_X0_RRR_SRCB_MASK);
  1035. val &= ~R_TILEGX_IMM8_X0_TLS_ADD_LE_MASK;
  1036. } else
  1037. gold_unreachable();
  1038. break;
  1039. case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
  1040. if (opt_t == tls::TLSOPT_NONE) {
  1041. reloc = (val & (0x3Fllu << 31)) << 12;
  1042. reloc |= ((size == 32
  1043. ? TILEGX_X_ADDX_R0_R0_TP
  1044. : TILEGX_X_ADD_R0_R0_TP)
  1045. & TILEGX_X1_RRR_MASK);
  1046. val &= ~R_TILEGX_IMM8_X1_TLS_ADD_MASK;
  1047. } else if (opt_t == tls::TLSOPT_TO_LE) {
  1048. reloc = (val & (0x3Fllu << 31)) << 6;
  1049. reloc |= (TILEGX_X_MOVE_R0_R0 & TILEGX_X1_RRR_SRCB_MASK);
  1050. val &= ~R_TILEGX_IMM8_X1_TLS_ADD_LE_MASK;
  1051. } else
  1052. gold_unreachable();
  1053. break;
  1054. case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
  1055. if (opt_t == tls::TLSOPT_NONE) {
  1056. reloc = (val & 0x3Fllu) << 12;
  1057. reloc |= ((size == 32
  1058. ? TILEGX_Y_ADDX_R0_R0_TP
  1059. : TILEGX_Y_ADD_R0_R0_TP)
  1060. & TILEGX_Y0_RRR_MASK);
  1061. val &= ~R_TILEGX_IMM8_Y0_TLS_ADD_MASK;
  1062. } else if (opt_t == tls::TLSOPT_TO_LE) {
  1063. reloc = (val & 0x3Fllu) << 6;
  1064. reloc |= (TILEGX_Y_MOVE_R0_R0 & TILEGX_Y0_RRR_SRCB_MASK);
  1065. val &= ~R_TILEGX_IMM8_Y0_TLS_ADD_LE_MASK;
  1066. } else
  1067. gold_unreachable();
  1068. break;
  1069. case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
  1070. if (opt_t == tls::TLSOPT_NONE) {
  1071. reloc = (val & (0x3Fllu << 31)) << 12;
  1072. reloc |= ((size == 32
  1073. ? TILEGX_Y_ADDX_R0_R0_TP
  1074. : TILEGX_Y_ADD_R0_R0_TP)
  1075. & TILEGX_Y1_RRR_MASK);
  1076. val &= ~R_TILEGX_IMM8_Y1_TLS_ADD_MASK;
  1077. } else if (opt_t == tls::TLSOPT_TO_LE) {
  1078. reloc = (val & (0x3Fllu << 31)) << 6;
  1079. reloc |= (TILEGX_Y_MOVE_R0_R0 & TILEGX_Y1_RRR_SRCB_MASK);
  1080. val &= ~R_TILEGX_IMM8_Y1_TLS_ADD_LE_MASK;
  1081. } else
  1082. gold_unreachable();
  1083. break;
  1084. case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
  1085. if (opt_t == tls::TLSOPT_NONE) {
  1086. // GD see comments for optimize_tls_reloc
  1087. reloc = TILEGX_X_MOVE_R0_R0 & TILEGX_X0_RRR_SRCB_MASK;
  1088. val &= ~TILEGX_X0_RRR_SRCB_MASK;
  1089. } else if (opt_t == tls::TLSOPT_TO_IE
  1090. || opt_t == tls::TLSOPT_TO_LE) {
  1091. // IE/LE
  1092. reloc = (size == 32
  1093. ? TILEGX_X_ADDX_R0_R0_TP
  1094. : TILEGX_X_ADD_R0_R0_TP)
  1095. & TILEGX_X0_RRR_SRCB_MASK;
  1096. val &= ~TILEGX_X0_RRR_SRCB_MASK;
  1097. }
  1098. break;
  1099. case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
  1100. if (opt_t == tls::TLSOPT_NONE) {
  1101. reloc = TILEGX_X_MOVE_R0_R0 & TILEGX_X1_RRR_SRCB_MASK;
  1102. val &= ~TILEGX_X1_RRR_SRCB_MASK;
  1103. } else if (opt_t == tls::TLSOPT_TO_IE
  1104. || opt_t == tls::TLSOPT_TO_LE) {
  1105. reloc = (size == 32
  1106. ? TILEGX_X_ADDX_R0_R0_TP
  1107. : TILEGX_X_ADD_R0_R0_TP)
  1108. & TILEGX_X1_RRR_SRCB_MASK;
  1109. val &= ~TILEGX_X1_RRR_SRCB_MASK;
  1110. }
  1111. break;
  1112. case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
  1113. if (opt_t == tls::TLSOPT_NONE) {
  1114. reloc = TILEGX_Y_MOVE_R0_R0 & TILEGX_Y0_RRR_SRCB_MASK;
  1115. val &= ~TILEGX_Y0_RRR_SRCB_MASK;
  1116. } else if (opt_t == tls::TLSOPT_TO_IE
  1117. || opt_t == tls::TLSOPT_TO_LE) {
  1118. reloc = (size == 32
  1119. ? TILEGX_Y_ADDX_R0_R0_TP
  1120. : TILEGX_Y_ADD_R0_R0_TP)
  1121. & TILEGX_Y0_RRR_SRCB_MASK;
  1122. val &= ~TILEGX_Y0_RRR_SRCB_MASK;
  1123. }
  1124. break;
  1125. case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
  1126. if (opt_t == tls::TLSOPT_NONE) {
  1127. reloc = TILEGX_Y_MOVE_R0_R0 & TILEGX_Y1_RRR_SRCB_MASK;
  1128. val &= ~TILEGX_Y1_RRR_SRCB_MASK;
  1129. } else if (opt_t == tls::TLSOPT_TO_IE
  1130. || opt_t == tls::TLSOPT_TO_LE) {
  1131. reloc = (size == 32
  1132. ? TILEGX_Y_ADDX_R0_R0_TP
  1133. : TILEGX_Y_ADD_R0_R0_TP)
  1134. & TILEGX_Y1_RRR_SRCB_MASK;
  1135. val &= ~TILEGX_Y1_RRR_SRCB_MASK;
  1136. }
  1137. break;
  1138. case elfcpp::R_TILEGX_TLS_IE_LOAD:
  1139. if (opt_t == tls::TLSOPT_NONE) {
  1140. // IE
  1141. reloc = (size == 32
  1142. ? TILEGX_X_LD4S
  1143. : TILEGX_X_LD)
  1144. & TILEGX_X1_RRR_SRCB_MASK;
  1145. val &= ~TILEGX_X1_RRR_SRCB_MASK;
  1146. } else if (opt_t == tls::TLSOPT_TO_LE) {
  1147. // LE
  1148. reloc = TILEGX_X_MOVE_R0_R0 & TILEGX_X1_RRR_SRCB_MASK;
  1149. val &= ~TILEGX_X1_RRR_SRCB_MASK;
  1150. } else
  1151. gold_unreachable();
  1152. break;
  1153. case elfcpp::R_TILEGX_TLS_GD_CALL:
  1154. if (opt_t == tls::TLSOPT_TO_IE) {
  1155. // ld/ld4s r0, r0
  1156. reloc = (size == 32
  1157. ? TILEGX_X_LD4S
  1158. : TILEGX_X_LD) & TILEGX_X1_FULL_MASK;
  1159. val &= ~TILEGX_X1_FULL_MASK;
  1160. } else if (opt_t == tls::TLSOPT_TO_LE) {
  1161. // move r0, r0
  1162. reloc = TILEGX_X_MOVE_R0_R0 & TILEGX_X1_FULL_MASK;
  1163. val &= ~TILEGX_X1_FULL_MASK;
  1164. } else
  1165. // should be handled in ::relocate
  1166. gold_unreachable();
  1167. break;
  1168. default:
  1169. gold_unreachable();
  1170. break;
  1171. }
  1172. elfcpp::Swap<64, big_endian>::writeval(wv, val | reloc);
  1173. }
  1174. };
  1175. template<>
  1176. const Tilegx_relocate_functions<64, false>::Tilegx_howto
  1177. Tilegx_relocate_functions<64, false>::howto[elfcpp::R_TILEGX_NUM] =
  1178. {
  1179. { 0, 0, 0, 0, 0}, // R_TILEGX_NONE
  1180. { 0, 0, 0, 64, 0}, // R_TILEGX_64
  1181. { 0, 0, 0, 32, 0}, // R_TILEGX_32
  1182. { 0, 0, 0, 16, 0}, // R_TILEGX_16
  1183. { 0, 0, 0, 8, 0}, // R_TILEGX_8
  1184. { 0, 0, 1, 64, 0}, // R_TILEGX_64_PCREL
  1185. { 0, 0, 1, 32, 0}, // R_TILEGX_32_PCREL
  1186. { 0, 0, 1, 16, 0}, // R_TILEGX_16_PCREL
  1187. { 0, 0, 1, 8, 0}, // R_TILEGX_8_PCREL
  1188. { 0, 0, 0, 0, 0}, // R_TILEGX_HW0
  1189. { 16, 0, 0, 0, 0}, // R_TILEGX_HW1
  1190. { 32, 0, 0, 0, 0}, // R_TILEGX_HW2
  1191. { 48, 0, 0, 0, 0}, // R_TILEGX_HW3
  1192. { 0, 0, 0, 0, 0}, // R_TILEGX_HW0_LAST
  1193. { 16, 0, 0, 0, 0}, // R_TILEGX_HW1_LAST
  1194. { 32, 0, 0, 0, 0}, // R_TILEGX_HW2_LAST
  1195. { 0, 0, 0, 0, 0}, // R_TILEGX_COPY
  1196. { 0, 0, 0, 8, 0}, // R_TILEGX_GLOB_DAT
  1197. { 0, 0, 0, 0, 0}, // R_TILEGX_JMP_SLOT
  1198. { 0, 0, 0, 0, 0}, // R_TILEGX_RELATIVE
  1199. { 3, 1, 1, 0, 0}, // R_TILEGX_BROFF_X1
  1200. { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1
  1201. { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1_PLT
  1202. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X0
  1203. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y0
  1204. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X1
  1205. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y1
  1206. { 0, 1, 0, 8, 0}, // R_TILEGX_DEST_IMM8_X1
  1207. { 0, 1, 0, 8, 0}, // R_TILEGX_MT_IMM14_X1
  1208. { 0, 1, 0, 8, 0}, // R_TILEGX_MF_IMM14_X1
  1209. { 0, 1, 0, 8, 0}, // R_TILEGX_MMSTART_X0
  1210. { 0, 1, 0, 8, 0}, // R_TILEGX_MMEND_X0
  1211. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X0
  1212. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X1
  1213. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y0
  1214. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y1
  1215. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0
  1216. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0
  1217. { 16, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW1
  1218. { 16, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW1
  1219. { 32, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW2
  1220. { 32, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW2
  1221. { 48, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW3
  1222. { 48, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW3
  1223. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST
  1224. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST
  1225. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST
  1226. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST
  1227. { 32, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST
  1228. { 32, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST
  1229. { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PCREL
  1230. { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PCREL
  1231. { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PCREL
  1232. { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PCREL
  1233. { 32, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PCREL
  1234. { 32, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PCREL
  1235. { 48, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW3_PCREL
  1236. { 48, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW3_PCREL
  1237. { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PCREL
  1238. { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PCREL
  1239. { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PCREL
  1240. { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PCREL
  1241. { 32, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PCREL
  1242. { 32, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PCREL
  1243. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_GOT
  1244. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_GOT
  1245. { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PLT_PCREL
  1246. { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PLT_PCREL
  1247. { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PLT_PCREL
  1248. { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PLT_PCREL
  1249. { 32, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PLT_PCREL
  1250. { 32, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PLT_PCREL
  1251. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_GOT
  1252. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_GOT
  1253. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_GOT
  1254. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_GOT
  1255. { 32, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_GOT
  1256. { 32, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_GOT
  1257. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_GD
  1258. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_GD
  1259. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_LE
  1260. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_LE
  1261. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE
  1262. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE
  1263. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE
  1264. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE
  1265. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
  1266. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
  1267. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
  1268. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
  1269. { 0, 0, 0, 0, 0}, // R_TILEGX_IRELATIVE
  1270. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1271. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_IE
  1272. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_IE
  1273. { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL
  1274. { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL
  1275. { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL
  1276. { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL
  1277. { 32, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL
  1278. { 32, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL
  1279. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
  1280. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
  1281. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
  1282. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
  1283. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1284. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1285. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD64
  1286. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF64
  1287. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF64
  1288. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD32
  1289. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF32
  1290. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF32
  1291. { 3, 31, 1, 27, 0}, // R_TILEGX_TLS_GD_CALL
  1292. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_GD_ADD
  1293. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_GD_ADD
  1294. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_GD_ADD
  1295. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_GD_ADD
  1296. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_IE_LOAD
  1297. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_ADD
  1298. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_ADD
  1299. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_ADD
  1300. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_ADD
  1301. { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTINHERIT
  1302. { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTENTRY
  1303. };
  1304. template<>
  1305. const Tilegx_relocate_functions<32, false>::Tilegx_howto
  1306. Tilegx_relocate_functions<32, false>::howto[elfcpp::R_TILEGX_NUM] =
  1307. {
  1308. { 0, 0, 0, 0, 0}, // R_TILEGX_NONE
  1309. { 0, 0, 0, 64, 0}, // R_TILEGX_64
  1310. { 0, 0, 0, 32, 0}, // R_TILEGX_32
  1311. { 0, 0, 0, 16, 0}, // R_TILEGX_16
  1312. { 0, 0, 0, 8, 0}, // R_TILEGX_8
  1313. { 0, 0, 1, 64, 0}, // R_TILEGX_64_PCREL
  1314. { 0, 0, 1, 32, 0}, // R_TILEGX_32_PCREL
  1315. { 0, 0, 1, 16, 0}, // R_TILEGX_16_PCREL
  1316. { 0, 0, 1, 8, 0}, // R_TILEGX_8_PCREL
  1317. { 0, 0, 0, 0, 0}, // R_TILEGX_HW0
  1318. { 16, 0, 0, 0, 0}, // R_TILEGX_HW1
  1319. { 31, 0, 0, 0, 0}, // R_TILEGX_HW2
  1320. { 31, 0, 0, 0, 0}, // R_TILEGX_HW3
  1321. { 0, 0, 0, 0, 0}, // R_TILEGX_HW0_LAST
  1322. { 16, 0, 0, 0, 0}, // R_TILEGX_HW1_LAST
  1323. { 31, 0, 0, 0, 0}, // R_TILEGX_HW2_LAST
  1324. { 0, 0, 0, 0, 0}, // R_TILEGX_COPY
  1325. { 0, 0, 0, 8, 0}, // R_TILEGX_GLOB_DAT
  1326. { 0, 0, 0, 0, 0}, // R_TILEGX_JMP_SLOT
  1327. { 0, 0, 0, 0, 0}, // R_TILEGX_RELATIVE
  1328. { 3, 1, 1, 0, 0}, // R_TILEGX_BROFF_X1
  1329. { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1
  1330. { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1_PLT
  1331. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X0
  1332. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y0
  1333. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X1
  1334. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y1
  1335. { 0, 1, 0, 8, 0}, // R_TILEGX_DEST_IMM8_X1
  1336. { 0, 1, 0, 8, 0}, // R_TILEGX_MT_IMM14_X1
  1337. { 0, 1, 0, 8, 0}, // R_TILEGX_MF_IMM14_X1
  1338. { 0, 1, 0, 8, 0}, // R_TILEGX_MMSTART_X0
  1339. { 0, 1, 0, 8, 0}, // R_TILEGX_MMEND_X0
  1340. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X0
  1341. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X1
  1342. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y0
  1343. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y1
  1344. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0
  1345. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0
  1346. { 16, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW1
  1347. { 16, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW1
  1348. { 31, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW2
  1349. { 31, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW2
  1350. { 31, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW3
  1351. { 31, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW3
  1352. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST
  1353. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST
  1354. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST
  1355. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST
  1356. { 31, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST
  1357. { 31, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST
  1358. { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PCREL
  1359. { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PCREL
  1360. { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PCREL
  1361. { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PCREL
  1362. { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PCREL
  1363. { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PCREL
  1364. { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW3_PCREL
  1365. { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW3_PCREL
  1366. { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PCREL
  1367. { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PCREL
  1368. { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PCREL
  1369. { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PCREL
  1370. { 31, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PCREL
  1371. { 31, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PCREL
  1372. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_GOT
  1373. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_GOT
  1374. { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PLT_PCREL
  1375. { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PLT_PCREL
  1376. { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PLT_PCREL
  1377. { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PLT_PCREL
  1378. { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PLT_PCREL
  1379. { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PLT_PCREL
  1380. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_GOT
  1381. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_GOT
  1382. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_GOT
  1383. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_GOT
  1384. { 31, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_GOT
  1385. { 31, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_GOT
  1386. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_GD
  1387. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_GD
  1388. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_LE
  1389. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_LE
  1390. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE
  1391. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE
  1392. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE
  1393. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE
  1394. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
  1395. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
  1396. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
  1397. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
  1398. { 0, 0, 0, 0, 0}, // R_TILEGX_IRELATIVE
  1399. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1400. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_IE
  1401. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_IE
  1402. { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL
  1403. { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL
  1404. { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL
  1405. { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL
  1406. { 31, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL
  1407. { 31, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL
  1408. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
  1409. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
  1410. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
  1411. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
  1412. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1413. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1414. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD64
  1415. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF64
  1416. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF64
  1417. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD32
  1418. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF32
  1419. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF32
  1420. { 3, 31, 1, 27, 0}, // R_TILEGX_TLS_GD_CALL
  1421. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_GD_ADD
  1422. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_GD_ADD
  1423. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_GD_ADD
  1424. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_GD_ADD
  1425. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_IE_LOAD
  1426. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_ADD
  1427. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_ADD
  1428. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_ADD
  1429. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_ADD
  1430. { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTINHERIT
  1431. { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTENTRY
  1432. };
  1433. template<>
  1434. const Tilegx_relocate_functions<64, true>::Tilegx_howto
  1435. Tilegx_relocate_functions<64, true>::howto[elfcpp::R_TILEGX_NUM] =
  1436. {
  1437. { 0, 0, 0, 0, 0}, // R_TILEGX_NONE
  1438. { 0, 0, 0, 64, 0}, // R_TILEGX_64
  1439. { 0, 0, 0, 32, 0}, // R_TILEGX_32
  1440. { 0, 0, 0, 16, 0}, // R_TILEGX_16
  1441. { 0, 0, 0, 8, 0}, // R_TILEGX_8
  1442. { 0, 0, 1, 64, 0}, // R_TILEGX_64_PCREL
  1443. { 0, 0, 1, 32, 0}, // R_TILEGX_32_PCREL
  1444. { 0, 0, 1, 16, 0}, // R_TILEGX_16_PCREL
  1445. { 0, 0, 1, 8, 0}, // R_TILEGX_8_PCREL
  1446. { 0, 0, 0, 0, 0}, // R_TILEGX_HW0
  1447. { 16, 0, 0, 0, 0}, // R_TILEGX_HW1
  1448. { 32, 0, 0, 0, 0}, // R_TILEGX_HW2
  1449. { 48, 0, 0, 0, 0}, // R_TILEGX_HW3
  1450. { 0, 0, 0, 0, 0}, // R_TILEGX_HW0_LAST
  1451. { 16, 0, 0, 0, 0}, // R_TILEGX_HW1_LAST
  1452. { 32, 0, 0, 0, 0}, // R_TILEGX_HW2_LAST
  1453. { 0, 0, 0, 0, 0}, // R_TILEGX_COPY
  1454. { 0, 0, 0, 8, 0}, // R_TILEGX_GLOB_DAT
  1455. { 0, 0, 0, 0, 0}, // R_TILEGX_JMP_SLOT
  1456. { 0, 0, 0, 0, 0}, // R_TILEGX_RELATIVE
  1457. { 3, 1, 1, 0, 0}, // R_TILEGX_BROFF_X1
  1458. { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1
  1459. { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1_PLT
  1460. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X0
  1461. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y0
  1462. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X1
  1463. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y1
  1464. { 0, 1, 0, 8, 0}, // R_TILEGX_DEST_IMM8_X1
  1465. { 0, 1, 0, 8, 0}, // R_TILEGX_MT_IMM14_X1
  1466. { 0, 1, 0, 8, 0}, // R_TILEGX_MF_IMM14_X1
  1467. { 0, 1, 0, 8, 0}, // R_TILEGX_MMSTART_X0
  1468. { 0, 1, 0, 8, 0}, // R_TILEGX_MMEND_X0
  1469. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X0
  1470. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X1
  1471. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y0
  1472. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y1
  1473. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0
  1474. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0
  1475. { 16, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW1
  1476. { 16, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW1
  1477. { 32, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW2
  1478. { 32, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW2
  1479. { 48, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW3
  1480. { 48, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW3
  1481. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST
  1482. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST
  1483. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST
  1484. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST
  1485. { 32, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST
  1486. { 32, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST
  1487. { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PCREL
  1488. { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PCREL
  1489. { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PCREL
  1490. { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PCREL
  1491. { 32, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PCREL
  1492. { 32, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PCREL
  1493. { 48, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW3_PCREL
  1494. { 48, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW3_PCREL
  1495. { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PCREL
  1496. { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PCREL
  1497. { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PCREL
  1498. { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PCREL
  1499. { 32, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PCREL
  1500. { 32, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PCREL
  1501. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_GOT
  1502. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_GOT
  1503. { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PLT_PCREL
  1504. { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PLT_PCREL
  1505. { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PLT_PCREL
  1506. { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PLT_PCREL
  1507. { 32, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PLT_PCREL
  1508. { 32, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PLT_PCREL
  1509. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_GOT
  1510. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_GOT
  1511. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_GOT
  1512. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_GOT
  1513. { 32, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_GOT
  1514. { 32, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_GOT
  1515. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_GD
  1516. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_GD
  1517. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_LE
  1518. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_LE
  1519. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE
  1520. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE
  1521. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE
  1522. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE
  1523. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
  1524. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
  1525. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
  1526. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
  1527. { 0, 0, 0, 0, 0}, // R_TILEGX_IRELATIVE
  1528. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1529. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_IE
  1530. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_IE
  1531. { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL
  1532. { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL
  1533. { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL
  1534. { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL
  1535. { 32, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL
  1536. { 32, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL
  1537. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
  1538. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
  1539. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
  1540. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
  1541. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1542. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1543. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD64
  1544. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF64
  1545. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF64
  1546. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD32
  1547. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF32
  1548. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF32
  1549. { 3, 31, 1, 27, 0}, // R_TILEGX_TLS_GD_CALL
  1550. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_GD_ADD
  1551. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_GD_ADD
  1552. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_GD_ADD
  1553. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_GD_ADD
  1554. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_IE_LOAD
  1555. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_ADD
  1556. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_ADD
  1557. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_ADD
  1558. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_ADD
  1559. { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTINHERIT
  1560. { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTENTRY
  1561. };
  1562. template<>
  1563. const Tilegx_relocate_functions<32, true>::Tilegx_howto
  1564. Tilegx_relocate_functions<32, true>::howto[elfcpp::R_TILEGX_NUM] =
  1565. {
  1566. { 0, 0, 0, 0, 0}, // R_TILEGX_NONE
  1567. { 0, 0, 0, 64, 0}, // R_TILEGX_64
  1568. { 0, 0, 0, 32, 0}, // R_TILEGX_32
  1569. { 0, 0, 0, 16, 0}, // R_TILEGX_16
  1570. { 0, 0, 0, 8, 0}, // R_TILEGX_8
  1571. { 0, 0, 1, 64, 0}, // R_TILEGX_64_PCREL
  1572. { 0, 0, 1, 32, 0}, // R_TILEGX_32_PCREL
  1573. { 0, 0, 1, 16, 0}, // R_TILEGX_16_PCREL
  1574. { 0, 0, 1, 8, 0}, // R_TILEGX_8_PCREL
  1575. { 0, 0, 0, 0, 0}, // R_TILEGX_HW0
  1576. { 16, 0, 0, 0, 0}, // R_TILEGX_HW1
  1577. { 31, 0, 0, 0, 0}, // R_TILEGX_HW2
  1578. { 31, 0, 0, 0, 0}, // R_TILEGX_HW3
  1579. { 0, 0, 0, 0, 0}, // R_TILEGX_HW0_LAST
  1580. { 16, 0, 0, 0, 0}, // R_TILEGX_HW1_LAST
  1581. { 31, 0, 0, 0, 0}, // R_TILEGX_HW2_LAST
  1582. { 0, 0, 0, 0, 0}, // R_TILEGX_COPY
  1583. { 0, 0, 0, 8, 0}, // R_TILEGX_GLOB_DAT
  1584. { 0, 0, 0, 0, 0}, // R_TILEGX_JMP_SLOT
  1585. { 0, 0, 0, 0, 0}, // R_TILEGX_RELATIVE
  1586. { 3, 1, 1, 0, 0}, // R_TILEGX_BROFF_X1
  1587. { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1
  1588. { 3, 31, 1, 27, 0}, // R_TILEGX_JUMPOFF_X1_PLT
  1589. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X0
  1590. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y0
  1591. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_X1
  1592. { 0, 1, 0, 8, 0}, // R_TILEGX_IMM8_Y1
  1593. { 0, 1, 0, 8, 0}, // R_TILEGX_DEST_IMM8_X1
  1594. { 0, 1, 0, 8, 0}, // R_TILEGX_MT_IMM14_X1
  1595. { 0, 1, 0, 8, 0}, // R_TILEGX_MF_IMM14_X1
  1596. { 0, 1, 0, 8, 0}, // R_TILEGX_MMSTART_X0
  1597. { 0, 1, 0, 8, 0}, // R_TILEGX_MMEND_X0
  1598. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X0
  1599. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_X1
  1600. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y0
  1601. { 0, 1, 0, 8, 0}, // R_TILEGX_SHAMT_Y1
  1602. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0
  1603. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0
  1604. { 16, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW1
  1605. { 16, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW1
  1606. { 31, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW2
  1607. { 31, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW2
  1608. { 31, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW3
  1609. { 31, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW3
  1610. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST
  1611. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST
  1612. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST
  1613. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST
  1614. { 31, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST
  1615. { 31, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST
  1616. { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PCREL
  1617. { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PCREL
  1618. { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PCREL
  1619. { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PCREL
  1620. { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PCREL
  1621. { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PCREL
  1622. { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW3_PCREL
  1623. { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW3_PCREL
  1624. { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PCREL
  1625. { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PCREL
  1626. { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PCREL
  1627. { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PCREL
  1628. { 31, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PCREL
  1629. { 31, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PCREL
  1630. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_GOT
  1631. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_GOT
  1632. { 0, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW0_PLT_PCREL
  1633. { 0, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW0_PLT_PCREL
  1634. { 16, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW1_PLT_PCREL
  1635. { 16, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW1_PLT_PCREL
  1636. { 31, 12, 1, 16, 0}, // R_TILEGX_IMM16_X0_HW2_PLT_PCREL
  1637. { 31, 43, 1, 16, 0}, // R_TILEGX_IMM16_X1_HW2_PLT_PCREL
  1638. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_GOT
  1639. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_GOT
  1640. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_GOT
  1641. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_GOT
  1642. { 31, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_GOT
  1643. { 31, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_GOT
  1644. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_GD
  1645. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_GD
  1646. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_LE
  1647. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_LE
  1648. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE
  1649. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE
  1650. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE
  1651. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE
  1652. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD
  1653. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD
  1654. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD
  1655. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD
  1656. { 0, 0, 0, 0, 0}, // R_TILEGX_IRELATIVE
  1657. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1658. { 0, 12, 0, 16, 0}, // R_TILEGX_IMM16_X0_HW0_TLS_IE
  1659. { 0, 43, 0, 16, 0}, // R_TILEGX_IMM16_X1_HW0_TLS_IE
  1660. { 0, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL
  1661. { 0, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL
  1662. { 16, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL
  1663. { 16, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL
  1664. { 31, 12, 1, 16, 1}, // R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL
  1665. { 31, 43, 1, 16, 1}, // R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL
  1666. { 0, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE
  1667. { 0, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE
  1668. { 16, 12, 0, 16, 1}, // R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE
  1669. { 16, 43, 0, 16, 1}, // R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE
  1670. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1671. { 0, 0, 0, 0, 0}, // R_TILEGX_INVALID
  1672. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD64
  1673. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF64
  1674. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF64
  1675. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPMOD32
  1676. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_DTPOFF32
  1677. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_TPOFF32
  1678. { 3, 31, 1, 27, 0}, // R_TILEGX_TLS_GD_CALL
  1679. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_GD_ADD
  1680. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_GD_ADD
  1681. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_GD_ADD
  1682. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_GD_ADD
  1683. { 0, 0, 0, 0, 0}, // R_TILEGX_TLS_IE_LOAD
  1684. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X0_TLS_ADD
  1685. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_X1_TLS_ADD
  1686. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y0_TLS_ADD
  1687. { 0, 0, 0, 0, 0}, // R_TILEGX_IMM8_Y1_TLS_ADD
  1688. { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTINHERIT
  1689. { 0, 0, 0, 0, 0}, // R_TILEGX_GNU_VTENTRY
  1690. };
  1691. // Get the GOT section, creating it if necessary.
  1692. template<int size, bool big_endian>
  1693. Output_data_got<size, big_endian>*
  1694. Target_tilegx<size, big_endian>::got_section(Symbol_table* symtab,
  1695. Layout* layout)
  1696. {
  1697. if (this->got_ == NULL)
  1698. {
  1699. gold_assert(symtab != NULL && layout != NULL);
  1700. // When using -z now, we can treat .got.plt as a relro section.
  1701. // Without -z now, it is modified after program startup by lazy
  1702. // PLT relocations.
  1703. bool is_got_plt_relro = parameters->options().now();
  1704. Output_section_order got_order = (is_got_plt_relro
  1705. ? ORDER_RELRO
  1706. : ORDER_RELRO_LAST);
  1707. Output_section_order got_plt_order = (is_got_plt_relro
  1708. ? ORDER_RELRO
  1709. : ORDER_NON_RELRO_FIRST);
  1710. this->got_ = new Output_data_got<size, big_endian>();
  1711. layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
  1712. (elfcpp::SHF_ALLOC
  1713. | elfcpp::SHF_WRITE),
  1714. this->got_, got_order, true);
  1715. // Define _GLOBAL_OFFSET_TABLE_ at the start of the PLT.
  1716. this->global_offset_table_ =
  1717. symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
  1718. Symbol_table::PREDEFINED,
  1719. this->got_,
  1720. 0, 0, elfcpp::STT_OBJECT,
  1721. elfcpp::STB_LOCAL,
  1722. elfcpp::STV_HIDDEN, 0,
  1723. false, false);
  1724. if (parameters->options().shared()) {
  1725. // we need to keep the address of .dynamic section in the
  1726. // first got entry for .so
  1727. this->tilegx_dynamic_ =
  1728. symtab->define_in_output_data("_TILEGX_DYNAMIC_", NULL,
  1729. Symbol_table::PREDEFINED,
  1730. layout->dynamic_section(),
  1731. 0, 0, elfcpp::STT_OBJECT,
  1732. elfcpp::STB_LOCAL,
  1733. elfcpp::STV_HIDDEN, 0,
  1734. false, false);
  1735. this->got_->add_global(this->tilegx_dynamic_, GOT_TYPE_STANDARD);
  1736. } else
  1737. // for executable, just set the first entry to zero.
  1738. this->got_->set_current_data_size(size / 8);
  1739. this->got_plt_ = new Output_data_space(size / 8, "** GOT PLT");
  1740. layout->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS,
  1741. (elfcpp::SHF_ALLOC
  1742. | elfcpp::SHF_WRITE),
  1743. this->got_plt_, got_plt_order,
  1744. is_got_plt_relro);
  1745. // The first two entries are reserved.
  1746. this->got_plt_->set_current_data_size
  1747. (TILEGX_GOTPLT_RESERVE_COUNT * (size / 8));
  1748. if (!is_got_plt_relro)
  1749. {
  1750. // Those bytes can go into the relro segment.
  1751. layout->increase_relro(size / 8);
  1752. }
  1753. // If there are any IRELATIVE relocations, they get GOT entries
  1754. // in .got.plt after the jump slot entries.
  1755. this->got_irelative_
  1756. = new Output_data_space(size / 8, "** GOT IRELATIVE PLT");
  1757. layout->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS,
  1758. (elfcpp::SHF_ALLOC
  1759. | elfcpp::SHF_WRITE),
  1760. this->got_irelative_,
  1761. got_plt_order, is_got_plt_relro);
  1762. }
  1763. return this->got_;
  1764. }
  1765. // Get the dynamic reloc section, creating it if necessary.
  1766. template<int size, bool big_endian>
  1767. typename Target_tilegx<size, big_endian>::Reloc_section*
  1768. Target_tilegx<size, big_endian>::rela_dyn_section(Layout* layout)
  1769. {
  1770. if (this->rela_dyn_ == NULL)
  1771. {
  1772. gold_assert(layout != NULL);
  1773. this->rela_dyn_ = new Reloc_section(parameters->options().combreloc());
  1774. layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
  1775. elfcpp::SHF_ALLOC, this->rela_dyn_,
  1776. ORDER_DYNAMIC_RELOCS, false);
  1777. }
  1778. return this->rela_dyn_;
  1779. }
  1780. // Get the section to use for IRELATIVE relocs, creating it if
  1781. // necessary. These go in .rela.dyn, but only after all other dynamic
  1782. // relocations. They need to follow the other dynamic relocations so
  1783. // that they can refer to global variables initialized by those
  1784. // relocs.
  1785. template<int size, bool big_endian>
  1786. typename Target_tilegx<size, big_endian>::Reloc_section*
  1787. Target_tilegx<size, big_endian>::rela_irelative_section(Layout* layout)
  1788. {
  1789. if (this->rela_irelative_ == NULL)
  1790. {
  1791. // Make sure we have already created the dynamic reloc section.
  1792. this->rela_dyn_section(layout);
  1793. this->rela_irelative_ = new Reloc_section(false);
  1794. layout->add_output_section_data(".rela.dyn", elfcpp::SHT_RELA,
  1795. elfcpp::SHF_ALLOC, this->rela_irelative_,
  1796. ORDER_DYNAMIC_RELOCS, false);
  1797. gold_assert(this->rela_dyn_->output_section()
  1798. == this->rela_irelative_->output_section());
  1799. }
  1800. return this->rela_irelative_;
  1801. }
  1802. // Initialize the PLT section.
  1803. template<int size, bool big_endian>
  1804. void
  1805. Output_data_plt_tilegx<size, big_endian>::init(Layout* layout)
  1806. {
  1807. this->rel_ = new Reloc_section(false);
  1808. layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
  1809. elfcpp::SHF_ALLOC, this->rel_,
  1810. ORDER_DYNAMIC_PLT_RELOCS, false);
  1811. }
  1812. template<int size, bool big_endian>
  1813. void
  1814. Output_data_plt_tilegx<size, big_endian>::do_adjust_output_section(
  1815. Output_section* os)
  1816. {
  1817. os->set_entsize(this->get_plt_entry_size());
  1818. }
  1819. // Add an entry to the PLT.
  1820. template<int size, bool big_endian>
  1821. void
  1822. Output_data_plt_tilegx<size, big_endian>::add_entry(Symbol_table* symtab,
  1823. Layout* layout, Symbol* gsym)
  1824. {
  1825. gold_assert(!gsym->has_plt_offset());
  1826. unsigned int plt_index;
  1827. off_t plt_offset;
  1828. section_offset_type got_offset;
  1829. unsigned int* pcount;
  1830. unsigned int reserved;
  1831. Output_data_space* got;
  1832. if (gsym->type() == elfcpp::STT_GNU_IFUNC
  1833. && gsym->can_use_relative_reloc(false))
  1834. {
  1835. pcount = &this->irelative_count_;
  1836. reserved = 0;
  1837. got = this->got_irelative_;
  1838. }
  1839. else
  1840. {
  1841. pcount = &this->count_;
  1842. reserved = TILEGX_GOTPLT_RESERVE_COUNT;
  1843. got = this->got_plt_;
  1844. }
  1845. if (!this->is_data_size_valid())
  1846. {
  1847. plt_index = *pcount;
  1848. // TILEGX .plt section layout
  1849. //
  1850. // ----
  1851. // plt_header
  1852. // ----
  1853. // plt stub
  1854. // ----
  1855. // ...
  1856. // ----
  1857. //
  1858. // TILEGX .got.plt section layout
  1859. //
  1860. // ----
  1861. // reserv1
  1862. // ----
  1863. // reserv2
  1864. // ----
  1865. // entries for normal function
  1866. // ----
  1867. // ...
  1868. // ----
  1869. // entries for ifunc
  1870. // ----
  1871. // ...
  1872. // ----
  1873. if (got == this->got_irelative_)
  1874. plt_offset = plt_index * this->get_plt_entry_size();
  1875. else
  1876. plt_offset = (plt_index + 1) * this->get_plt_entry_size();
  1877. ++*pcount;
  1878. got_offset = (plt_index + reserved) * (size / 8);
  1879. gold_assert(got_offset == got->current_data_size());
  1880. // Every PLT entry needs a GOT entry which points back to the PLT
  1881. // entry (this will be changed by the dynamic linker, normally
  1882. // lazily when the function is called).
  1883. got->set_current_data_size(got_offset + size / 8);
  1884. }
  1885. else
  1886. {
  1887. // FIXME: This is probably not correct for IRELATIVE relocs.
  1888. // For incremental updates, find an available slot.
  1889. plt_offset = this->free_list_.allocate(this->get_plt_entry_size(),
  1890. this->get_plt_entry_size(), 0);
  1891. if (plt_offset == -1)
  1892. gold_fallback(_("out of patch space (PLT);"
  1893. " relink with --incremental-full"));
  1894. // The GOT and PLT entries have a 1-1 correspondance, so the GOT offset
  1895. // can be calculated from the PLT index, adjusting for the three
  1896. // reserved entries at the beginning of the GOT.
  1897. plt_index = plt_offset / this->get_plt_entry_size() - 1;
  1898. got_offset = (plt_index + reserved) * (size / 8);
  1899. }
  1900. gsym->set_plt_offset(plt_offset);
  1901. // Every PLT entry needs a reloc.
  1902. this->add_relocation(symtab, layout, gsym, got_offset);
  1903. // Note that we don't need to save the symbol. The contents of the
  1904. // PLT are independent of which symbols are used. The symbols only
  1905. // appear in the relocations.
  1906. }
  1907. // Add an entry to the PLT for a local STT_GNU_IFUNC symbol. Return
  1908. // the PLT offset.
  1909. template<int size, bool big_endian>
  1910. unsigned int
  1911. Output_data_plt_tilegx<size, big_endian>::add_local_ifunc_entry(
  1912. Symbol_table* symtab,
  1913. Layout* layout,
  1914. Sized_relobj_file<size, big_endian>* relobj,
  1915. unsigned int local_sym_index)
  1916. {
  1917. unsigned int plt_offset =
  1918. this->irelative_count_ * this->get_plt_entry_size();
  1919. ++this->irelative_count_;
  1920. section_offset_type got_offset = this->got_irelative_->current_data_size();
  1921. // Every PLT entry needs a GOT entry which points back to the PLT
  1922. // entry.
  1923. this->got_irelative_->set_current_data_size(got_offset + size / 8);
  1924. // Every PLT entry needs a reloc.
  1925. Reloc_section* rela = this->rela_irelative(symtab, layout);
  1926. rela->add_symbolless_local_addend(relobj, local_sym_index,
  1927. elfcpp::R_TILEGX_IRELATIVE,
  1928. this->got_irelative_, got_offset, 0);
  1929. return plt_offset;
  1930. }
  1931. // Add the relocation for a PLT entry.
  1932. template<int size, bool big_endian>
  1933. void
  1934. Output_data_plt_tilegx<size, big_endian>::add_relocation(Symbol_table* symtab,
  1935. Layout* layout,
  1936. Symbol* gsym,
  1937. unsigned int got_offset)
  1938. {
  1939. if (gsym->type() == elfcpp::STT_GNU_IFUNC
  1940. && gsym->can_use_relative_reloc(false))
  1941. {
  1942. Reloc_section* rela = this->rela_irelative(symtab, layout);
  1943. rela->add_symbolless_global_addend(gsym, elfcpp::R_TILEGX_IRELATIVE,
  1944. this->got_irelative_, got_offset, 0);
  1945. }
  1946. else
  1947. {
  1948. gsym->set_needs_dynsym_entry();
  1949. this->rel_->add_global(gsym, elfcpp::R_TILEGX_JMP_SLOT, this->got_plt_,
  1950. got_offset, 0);
  1951. }
  1952. }
  1953. // Return where the IRELATIVE relocations should go in the PLT. These
  1954. // follow the JUMP_SLOT and the TLSDESC relocations.
  1955. template<int size, bool big_endian>
  1956. typename Output_data_plt_tilegx<size, big_endian>::Reloc_section*
  1957. Output_data_plt_tilegx<size, big_endian>::rela_irelative(Symbol_table* symtab,
  1958. Layout* layout)
  1959. {
  1960. if (this->irelative_rel_ == NULL)
  1961. {
  1962. // case we see any later on.
  1963. this->irelative_rel_ = new Reloc_section(false);
  1964. layout->add_output_section_data(".rela.plt", elfcpp::SHT_RELA,
  1965. elfcpp::SHF_ALLOC, this->irelative_rel_,
  1966. ORDER_DYNAMIC_PLT_RELOCS, false);
  1967. gold_assert(this->irelative_rel_->output_section()
  1968. == this->rel_->output_section());
  1969. if (parameters->doing_static_link())
  1970. {
  1971. // A statically linked executable will only have a .rela.plt
  1972. // section to hold R_TILEGX_IRELATIVE relocs for
  1973. // STT_GNU_IFUNC symbols. The library will use these
  1974. // symbols to locate the IRELATIVE relocs at program startup
  1975. // time.
  1976. symtab->define_in_output_data("__rela_iplt_start", NULL,
  1977. Symbol_table::PREDEFINED,
  1978. this->irelative_rel_, 0, 0,
  1979. elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
  1980. elfcpp::STV_HIDDEN, 0, false, true);
  1981. symtab->define_in_output_data("__rela_iplt_end", NULL,
  1982. Symbol_table::PREDEFINED,
  1983. this->irelative_rel_, 0, 0,
  1984. elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
  1985. elfcpp::STV_HIDDEN, 0, true, true);
  1986. }
  1987. }
  1988. return this->irelative_rel_;
  1989. }
  1990. // Return the PLT address to use for a global symbol.
  1991. template<int size, bool big_endian>
  1992. uint64_t
  1993. Output_data_plt_tilegx<size, big_endian>::address_for_global(
  1994. const Symbol* gsym)
  1995. {
  1996. uint64_t offset = 0;
  1997. if (gsym->type() == elfcpp::STT_GNU_IFUNC
  1998. && gsym->can_use_relative_reloc(false))
  1999. offset = (this->count_ + 1) * this->get_plt_entry_size();
  2000. return this->address() + offset + gsym->plt_offset();
  2001. }
  2002. // Return the PLT address to use for a local symbol. These are always
  2003. // IRELATIVE relocs.
  2004. template<int size, bool big_endian>
  2005. uint64_t
  2006. Output_data_plt_tilegx<size, big_endian>::address_for_local(
  2007. const Relobj* object,
  2008. unsigned int r_sym)
  2009. {
  2010. return (this->address()
  2011. + (this->count_ + 1) * this->get_plt_entry_size()
  2012. + object->local_plt_offset(r_sym));
  2013. }
  2014. // Set the final size.
  2015. template<int size, bool big_endian>
  2016. void
  2017. Output_data_plt_tilegx<size, big_endian>::set_final_data_size()
  2018. {
  2019. unsigned int count = this->count_ + this->irelative_count_;
  2020. this->set_data_size((count + 1) * this->get_plt_entry_size());
  2021. }
  2022. // The first entry in the PLT for an executable.
  2023. template<>
  2024. const unsigned char
  2025. Output_data_plt_tilegx<64, false>::first_plt_entry[plt_entry_size] =
  2026. {
  2027. 0x00, 0x30, 0x48, 0x51,
  2028. 0x6e, 0x43, 0xa0, 0x18, // { ld_add r28, r27, 8 }
  2029. 0x00, 0x30, 0xbc, 0x35,
  2030. 0x00, 0x40, 0xde, 0x9e, // { ld r27, r27 }
  2031. 0xff, 0xaf, 0x30, 0x40,
  2032. 0x60, 0x73, 0x6a, 0x28, // { info 10 ; jr r27 }
  2033. // padding
  2034. 0x00, 0x00, 0x00, 0x00,
  2035. 0x00, 0x00, 0x00, 0x00,
  2036. 0x00, 0x00, 0x00, 0x00,
  2037. 0x00, 0x00, 0x00, 0x00
  2038. };
  2039. template<>
  2040. const unsigned char
  2041. Output_data_plt_tilegx<32, false>::first_plt_entry[plt_entry_size] =
  2042. {
  2043. 0x00, 0x30, 0x48, 0x51,
  2044. 0x6e, 0x23, 0x58, 0x18, // { ld4s_add r28, r27, 4 }
  2045. 0x00, 0x30, 0xbc, 0x35,
  2046. 0x00, 0x40, 0xde, 0x9c, // { ld4s r27, r27 }
  2047. 0xff, 0xaf, 0x30, 0x40,
  2048. 0x60, 0x73, 0x6a, 0x28, // { info 10 ; jr r27 }
  2049. // padding
  2050. 0x00, 0x00, 0x00, 0x00,
  2051. 0x00, 0x00, 0x00, 0x00,
  2052. 0x00, 0x00, 0x00, 0x00,
  2053. 0x00, 0x00, 0x00, 0x00
  2054. };
  2055. template<>
  2056. const unsigned char
  2057. Output_data_plt_tilegx<64, true>::first_plt_entry[plt_entry_size] =
  2058. {
  2059. 0x00, 0x30, 0x48, 0x51,
  2060. 0x6e, 0x43, 0xa0, 0x18, // { ld_add r28, r27, 8 }
  2061. 0x00, 0x30, 0xbc, 0x35,
  2062. 0x00, 0x40, 0xde, 0x9e, // { ld r27, r27 }
  2063. 0xff, 0xaf, 0x30, 0x40,
  2064. 0x60, 0x73, 0x6a, 0x28, // { info 10 ; jr r27 }
  2065. // padding
  2066. 0x00, 0x00, 0x00, 0x00,
  2067. 0x00, 0x00, 0x00, 0x00,
  2068. 0x00, 0x00, 0x00, 0x00,
  2069. 0x00, 0x00, 0x00, 0x00
  2070. };
  2071. template<>
  2072. const unsigned char
  2073. Output_data_plt_tilegx<32, true>::first_plt_entry[plt_entry_size] =
  2074. {
  2075. 0x00, 0x30, 0x48, 0x51,
  2076. 0x6e, 0x23, 0x58, 0x18, // { ld4s_add r28, r27, 4 }
  2077. 0x00, 0x30, 0xbc, 0x35,
  2078. 0x00, 0x40, 0xde, 0x9c, // { ld4s r27, r27 }
  2079. 0xff, 0xaf, 0x30, 0x40,
  2080. 0x60, 0x73, 0x6a, 0x28, // { info 10 ; jr r27 }
  2081. // padding
  2082. 0x00, 0x00, 0x00, 0x00,
  2083. 0x00, 0x00, 0x00, 0x00,
  2084. 0x00, 0x00, 0x00, 0x00,
  2085. 0x00, 0x00, 0x00, 0x00
  2086. };
  2087. template<int size, bool big_endian>
  2088. void
  2089. Output_data_plt_tilegx<size, big_endian>::fill_first_plt_entry(
  2090. unsigned char* pov)
  2091. {
  2092. memcpy(pov, first_plt_entry, plt_entry_size);
  2093. }
  2094. // Subsequent entries in the PLT for an executable.
  2095. template<>
  2096. const unsigned char
  2097. Output_data_plt_tilegx<64, false>::plt_entry[plt_entry_size] =
  2098. {
  2099. 0xdc, 0x0f, 0x00, 0x10,
  2100. 0x0d, 0xf0, 0x6a, 0x28, // { moveli r28, 0 ; lnk r26 }
  2101. 0xdb, 0x0f, 0x00, 0x10,
  2102. 0x8e, 0x03, 0x00, 0x38, // { moveli r27, 0 ; shl16insli r28, r28, 0 }
  2103. 0x9c, 0xc6, 0x0d, 0xd0,
  2104. 0x6d, 0x03, 0x00, 0x38, // { add r28, r26, r28 ; shl16insli r27, r27, 0 }
  2105. 0x9b, 0xb6, 0xc5, 0xad,
  2106. 0xff, 0x57, 0xe0, 0x8e, // { add r27, r26, r27 ; info 10 ; ld r28, r28 }
  2107. 0xdd, 0x0f, 0x00, 0x70,
  2108. 0x80, 0x73, 0x6a, 0x28, // { shl16insli r29, zero, 0 ; jr r28 }
  2109. };
  2110. template<>
  2111. const unsigned char
  2112. Output_data_plt_tilegx<32, false>::plt_entry[plt_entry_size] =
  2113. {
  2114. 0xdc, 0x0f, 0x00, 0x10,
  2115. 0x0d, 0xf0, 0x6a, 0x28, // { moveli r28, 0 ; lnk r26 }
  2116. 0xdb, 0x0f, 0x00, 0x10,
  2117. 0x8e, 0x03, 0x00, 0x38, // { moveli r27, 0 ; shl16insli r28, r28, 0 }
  2118. 0x9c, 0xc6, 0x0d, 0xd0,
  2119. 0x6d, 0x03, 0x00, 0x38, // { add r28, r26, r28 ; shl16insli r27, r27, 0 }
  2120. 0x9b, 0xb6, 0xc5, 0xad,
  2121. 0xff, 0x57, 0xe0, 0x8c, // { add r27, r26, r27 ; info 10 ; ld4s r28, r28 }
  2122. 0xdd, 0x0f, 0x00, 0x70,
  2123. 0x80, 0x73, 0x6a, 0x28, // { shl16insli r29, zero, 0 ; jr r28 }
  2124. };
  2125. template<>
  2126. const unsigned char
  2127. Output_data_plt_tilegx<64, true>::plt_entry[plt_entry_size] =
  2128. {
  2129. 0xdc, 0x0f, 0x00, 0x10,
  2130. 0x0d, 0xf0, 0x6a, 0x28, // { moveli r28, 0 ; lnk r26 }
  2131. 0xdb, 0x0f, 0x00, 0x10,
  2132. 0x8e, 0x03, 0x00, 0x38, // { moveli r27, 0 ; shl16insli r28, r28, 0 }
  2133. 0x9c, 0xc6, 0x0d, 0xd0,
  2134. 0x6d, 0x03, 0x00, 0x38, // { add r28, r26, r28 ; shl16insli r27, r27, 0 }
  2135. 0x9b, 0xb6, 0xc5, 0xad,
  2136. 0xff, 0x57, 0xe0, 0x8e, // { add r27, r26, r27 ; info 10 ; ld r28, r28 }
  2137. 0xdd, 0x0f, 0x00, 0x70,
  2138. 0x80, 0x73, 0x6a, 0x28, // { shl16insli r29, zero, 0 ; jr r28 }
  2139. };
  2140. template<>
  2141. const unsigned char
  2142. Output_data_plt_tilegx<32, true>::plt_entry[plt_entry_size] =
  2143. {
  2144. 0xdc, 0x0f, 0x00, 0x10,
  2145. 0x0d, 0xf0, 0x6a, 0x28, // { moveli r28, 0 ; lnk r26 }
  2146. 0xdb, 0x0f, 0x00, 0x10,
  2147. 0x8e, 0x03, 0x00, 0x38, // { moveli r27, 0 ; shl16insli r28, r28, 0 }
  2148. 0x9c, 0xc6, 0x0d, 0xd0,
  2149. 0x6d, 0x03, 0x00, 0x38, // { add r28, r26, r28 ; shl16insli r27, r27, 0 }
  2150. 0x9b, 0xb6, 0xc5, 0xad,
  2151. 0xff, 0x57, 0xe0, 0x8c, // { add r27, r26, r27 ; info 10 ; ld4s r28, r28 }
  2152. 0xdd, 0x0f, 0x00, 0x70,
  2153. 0x80, 0x73, 0x6a, 0x28, // { shl16insli r29, zero, 0 ; jr r28 }
  2154. };
  2155. template<int size, bool big_endian>
  2156. void
  2157. Output_data_plt_tilegx<size, big_endian>::fill_plt_entry(
  2158. unsigned char* pov,
  2159. typename elfcpp::Elf_types<size>::Elf_Addr gotplt_base,
  2160. unsigned int got_offset,
  2161. typename elfcpp::Elf_types<size>::Elf_Addr plt_base,
  2162. unsigned int plt_offset, unsigned int plt_index)
  2163. {
  2164. const uint32_t TILEGX_IMM16_MASK = 0xFFFF;
  2165. const uint32_t TILEGX_X0_IMM16_BITOFF = 12;
  2166. const uint32_t TILEGX_X1_IMM16_BITOFF = 43;
  2167. typedef typename elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::Valtype
  2168. Valtype;
  2169. memcpy(pov, plt_entry, plt_entry_size);
  2170. // first bundle in plt stub - x0
  2171. Valtype* wv = reinterpret_cast<Valtype*>(pov);
  2172. Valtype val = elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::readval(wv);
  2173. Valtype reloc =
  2174. ((gotplt_base + got_offset) - (plt_base + plt_offset + 8)) >> 16;
  2175. elfcpp::Elf_Xword dst_mask =
  2176. (elfcpp::Elf_Xword)(TILEGX_IMM16_MASK) << TILEGX_X0_IMM16_BITOFF;
  2177. val &= ~dst_mask;
  2178. reloc &= TILEGX_IMM16_MASK;
  2179. elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::writeval(wv,
  2180. val | (reloc<<TILEGX_X0_IMM16_BITOFF));
  2181. // second bundle in plt stub - x1
  2182. wv = reinterpret_cast<Valtype*>(pov + 8);
  2183. val = elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::readval(wv);
  2184. reloc = (gotplt_base + got_offset) - (plt_base + plt_offset + 8);
  2185. dst_mask = (elfcpp::Elf_Xword)(TILEGX_IMM16_MASK) << TILEGX_X1_IMM16_BITOFF;
  2186. val &= ~dst_mask;
  2187. reloc &= TILEGX_IMM16_MASK;
  2188. elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::writeval(wv,
  2189. val | (reloc<<TILEGX_X1_IMM16_BITOFF));
  2190. // second bundle in plt stub - x0
  2191. wv = reinterpret_cast<Valtype*>(pov + 8);
  2192. val = elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::readval(wv);
  2193. reloc = (gotplt_base - (plt_base + plt_offset + 8)) >> 16;
  2194. dst_mask = (elfcpp::Elf_Xword)(TILEGX_IMM16_MASK) << TILEGX_X0_IMM16_BITOFF;
  2195. val &= ~dst_mask;
  2196. reloc &= TILEGX_IMM16_MASK;
  2197. elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::writeval(wv,
  2198. val | (reloc<<TILEGX_X0_IMM16_BITOFF));
  2199. // third bundle in plt stub - x1
  2200. wv = reinterpret_cast<Valtype*>(pov + 16);
  2201. val = elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::readval(wv);
  2202. reloc = gotplt_base - (plt_base + plt_offset + 8);
  2203. dst_mask = (elfcpp::Elf_Xword)(TILEGX_IMM16_MASK) << TILEGX_X1_IMM16_BITOFF;
  2204. val &= ~dst_mask;
  2205. reloc &= TILEGX_IMM16_MASK;
  2206. elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::writeval(wv,
  2207. val | (reloc<<TILEGX_X1_IMM16_BITOFF));
  2208. // fifth bundle in plt stub - carry plt_index x0
  2209. wv = reinterpret_cast<Valtype*>(pov + 32);
  2210. val = elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::readval(wv);
  2211. dst_mask = (elfcpp::Elf_Xword)(TILEGX_IMM16_MASK) << TILEGX_X0_IMM16_BITOFF;
  2212. val &= ~dst_mask;
  2213. plt_index &= TILEGX_IMM16_MASK;
  2214. elfcpp::Swap<TILEGX_INST_BUNDLE_SIZE, big_endian>::writeval(wv,
  2215. val | (plt_index<<TILEGX_X0_IMM16_BITOFF));
  2216. }
  2217. // Write out the PLT. This uses the hand-coded instructions above.
  2218. template<int size, bool big_endian>
  2219. void
  2220. Output_data_plt_tilegx<size, big_endian>::do_write(Output_file* of)
  2221. {
  2222. const off_t offset = this->offset();
  2223. const section_size_type oview_size =
  2224. convert_to_section_size_type(this->data_size());
  2225. unsigned char* const oview = of->get_output_view(offset, oview_size);
  2226. const off_t got_file_offset = this->got_plt_->offset();
  2227. gold_assert(parameters->incremental_update()
  2228. || (got_file_offset + this->got_plt_->data_size()
  2229. == this->got_irelative_->offset()));
  2230. const section_size_type got_size =
  2231. convert_to_section_size_type(this->got_plt_->data_size()
  2232. + this->got_irelative_->data_size());
  2233. unsigned char* const got_view = of->get_output_view(got_file_offset,
  2234. got_size);
  2235. unsigned char* pov = oview;
  2236. // The base address of the .plt section.
  2237. typename elfcpp::Elf_types<size>::Elf_Addr plt_address = this->address();
  2238. typename elfcpp::Elf_types<size>::Elf_Addr got_address =
  2239. this->got_plt_->address();
  2240. this->fill_first_plt_entry(pov);
  2241. pov += this->get_plt_entry_size();
  2242. unsigned char* got_pov = got_view;
  2243. // first entry of .got.plt are set to -1
  2244. // second entry of .got.plt are set to 0
  2245. memset(got_pov, 0xff, size / 8);
  2246. got_pov += size / 8;
  2247. memset(got_pov, 0x0, size / 8);
  2248. got_pov += size / 8;
  2249. unsigned int plt_offset = this->get_plt_entry_size();
  2250. const unsigned int count = this->count_ + this->irelative_count_;
  2251. unsigned int got_offset = (size / 8) * TILEGX_GOTPLT_RESERVE_COUNT;
  2252. for (unsigned int plt_index = 0;
  2253. plt_index < count;
  2254. ++plt_index,
  2255. pov += this->get_plt_entry_size(),
  2256. got_pov += size / 8,
  2257. plt_offset += this->get_plt_entry_size(),
  2258. got_offset += size / 8)
  2259. {
  2260. // Set and adjust the PLT entry itself.
  2261. this->fill_plt_entry(pov, got_address, got_offset,
  2262. plt_address, plt_offset, plt_index);
  2263. // Initialize entry in .got.plt to plt start address
  2264. elfcpp::Swap<size, big_endian>::writeval(got_pov, plt_address);
  2265. }
  2266. gold_assert(static_cast<section_size_type>(pov - oview) == oview_size);
  2267. gold_assert(static_cast<section_size_type>(got_pov - got_view) == got_size);
  2268. of->write_output_view(offset, oview_size, oview);
  2269. of->write_output_view(got_file_offset, got_size, got_view);
  2270. }
  2271. // Create the PLT section.
  2272. template<int size, bool big_endian>
  2273. void
  2274. Target_tilegx<size, big_endian>::make_plt_section(Symbol_table* symtab,
  2275. Layout* layout)
  2276. {
  2277. if (this->plt_ == NULL)
  2278. {
  2279. // Create the GOT sections first.
  2280. this->got_section(symtab, layout);
  2281. // Ensure that .rela.dyn always appears before .rela.plt,
  2282. // because on TILE-Gx, .rela.dyn needs to include .rela.plt
  2283. // in it's range.
  2284. this->rela_dyn_section(layout);
  2285. this->plt_ = new Output_data_plt_tilegx<size, big_endian>(layout,
  2286. TILEGX_INST_BUNDLE_SIZE, this->got_, this->got_plt_,
  2287. this->got_irelative_);
  2288. layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
  2289. (elfcpp::SHF_ALLOC
  2290. | elfcpp::SHF_EXECINSTR),
  2291. this->plt_, ORDER_NON_RELRO_FIRST,
  2292. false);
  2293. // Make the sh_info field of .rela.plt point to .plt.
  2294. Output_section* rela_plt_os = this->plt_->rela_plt()->output_section();
  2295. rela_plt_os->set_info_section(this->plt_->output_section());
  2296. }
  2297. }
  2298. // Create a PLT entry for a global symbol.
  2299. template<int size, bool big_endian>
  2300. void
  2301. Target_tilegx<size, big_endian>::make_plt_entry(Symbol_table* symtab,
  2302. Layout* layout, Symbol* gsym)
  2303. {
  2304. if (gsym->has_plt_offset())
  2305. return;
  2306. if (this->plt_ == NULL)
  2307. this->make_plt_section(symtab, layout);
  2308. this->plt_->add_entry(symtab, layout, gsym);
  2309. }
  2310. // Make a PLT entry for a local STT_GNU_IFUNC symbol.
  2311. template<int size, bool big_endian>
  2312. void
  2313. Target_tilegx<size, big_endian>::make_local_ifunc_plt_entry(
  2314. Symbol_table* symtab, Layout* layout,
  2315. Sized_relobj_file<size, big_endian>* relobj,
  2316. unsigned int local_sym_index)
  2317. {
  2318. if (relobj->local_has_plt_offset(local_sym_index))
  2319. return;
  2320. if (this->plt_ == NULL)
  2321. this->make_plt_section(symtab, layout);
  2322. unsigned int plt_offset = this->plt_->add_local_ifunc_entry(symtab, layout,
  2323. relobj,
  2324. local_sym_index);
  2325. relobj->set_local_plt_offset(local_sym_index, plt_offset);
  2326. }
  2327. // Return the number of entries in the PLT.
  2328. template<int size, bool big_endian>
  2329. unsigned int
  2330. Target_tilegx<size, big_endian>::plt_entry_count() const
  2331. {
  2332. if (this->plt_ == NULL)
  2333. return 0;
  2334. return this->plt_->entry_count();
  2335. }
  2336. // Return the offset of the first non-reserved PLT entry.
  2337. template<int size, bool big_endian>
  2338. unsigned int
  2339. Target_tilegx<size, big_endian>::first_plt_entry_offset() const
  2340. {
  2341. return this->plt_->first_plt_entry_offset();
  2342. }
  2343. // Return the size of each PLT entry.
  2344. template<int size, bool big_endian>
  2345. unsigned int
  2346. Target_tilegx<size, big_endian>::plt_entry_size() const
  2347. {
  2348. return this->plt_->get_plt_entry_size();
  2349. }
  2350. // Create the GOT and PLT sections for an incremental update.
  2351. template<int size, bool big_endian>
  2352. Output_data_got_base*
  2353. Target_tilegx<size, big_endian>::init_got_plt_for_update(Symbol_table* symtab,
  2354. Layout* layout,
  2355. unsigned int got_count,
  2356. unsigned int plt_count)
  2357. {
  2358. gold_assert(this->got_ == NULL);
  2359. this->got_ =
  2360. new Output_data_got<size, big_endian>((got_count
  2361. + TILEGX_GOT_RESERVE_COUNT)
  2362. * (size / 8));
  2363. layout->add_output_section_data(".got", elfcpp::SHT_PROGBITS,
  2364. (elfcpp::SHF_ALLOC
  2365. | elfcpp::SHF_WRITE),
  2366. this->got_, ORDER_RELRO_LAST,
  2367. true);
  2368. // Define _GLOBAL_OFFSET_TABLE_ at the start of the GOT.
  2369. this->global_offset_table_ =
  2370. symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
  2371. Symbol_table::PREDEFINED,
  2372. this->got_,
  2373. 0, 0, elfcpp::STT_OBJECT,
  2374. elfcpp::STB_LOCAL,
  2375. elfcpp::STV_HIDDEN, 0,
  2376. false, false);
  2377. if (parameters->options().shared()) {
  2378. this->tilegx_dynamic_ =
  2379. symtab->define_in_output_data("_TILEGX_DYNAMIC_", NULL,
  2380. Symbol_table::PREDEFINED,
  2381. layout->dynamic_section(),
  2382. 0, 0, elfcpp::STT_OBJECT,
  2383. elfcpp::STB_LOCAL,
  2384. elfcpp::STV_HIDDEN, 0,
  2385. false, false);
  2386. this->got_->add_global(this->tilegx_dynamic_, GOT_TYPE_STANDARD);
  2387. } else
  2388. this->got_->set_current_data_size(size / 8);
  2389. // Add the two reserved entries.
  2390. this->got_plt_
  2391. = new Output_data_space((plt_count + TILEGX_GOTPLT_RESERVE_COUNT)
  2392. * (size / 8), size / 8, "** GOT PLT");
  2393. layout->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS,
  2394. (elfcpp::SHF_ALLOC
  2395. | elfcpp::SHF_WRITE),
  2396. this->got_plt_, ORDER_NON_RELRO_FIRST,
  2397. false);
  2398. // If there are any IRELATIVE relocations, they get GOT entries in
  2399. // .got.plt after the jump slot.
  2400. this->got_irelative_
  2401. = new Output_data_space(0, size / 8, "** GOT IRELATIVE PLT");
  2402. layout->add_output_section_data(".got.plt", elfcpp::SHT_PROGBITS,
  2403. elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE,
  2404. this->got_irelative_,
  2405. ORDER_NON_RELRO_FIRST, false);
  2406. // Create the PLT section.
  2407. this->plt_ = new Output_data_plt_tilegx<size, big_endian>(layout,
  2408. this->plt_entry_size(), this->got_, this->got_plt_, this->got_irelative_,
  2409. plt_count);
  2410. layout->add_output_section_data(".plt", elfcpp::SHT_PROGBITS,
  2411. elfcpp::SHF_ALLOC | elfcpp::SHF_EXECINSTR,
  2412. this->plt_, ORDER_PLT, false);
  2413. // Make the sh_info field of .rela.plt point to .plt.
  2414. Output_section* rela_plt_os = this->plt_->rela_plt()->output_section();
  2415. rela_plt_os->set_info_section(this->plt_->output_section());
  2416. // Create the rela_dyn section.
  2417. this->rela_dyn_section(layout);
  2418. return this->got_;
  2419. }
  2420. // Reserve a GOT entry for a local symbol, and regenerate any
  2421. // necessary dynamic relocations.
  2422. template<int size, bool big_endian>
  2423. void
  2424. Target_tilegx<size, big_endian>::reserve_local_got_entry(
  2425. unsigned int got_index,
  2426. Sized_relobj<size, big_endian>* obj,
  2427. unsigned int r_sym,
  2428. unsigned int got_type)
  2429. {
  2430. unsigned int got_offset = (got_index + TILEGX_GOT_RESERVE_COUNT)
  2431. * (size / 8);
  2432. Reloc_section* rela_dyn = this->rela_dyn_section(NULL);
  2433. this->got_->reserve_local(got_index, obj, r_sym, got_type);
  2434. switch (got_type)
  2435. {
  2436. case GOT_TYPE_STANDARD:
  2437. if (parameters->options().output_is_position_independent())
  2438. rela_dyn->add_local_relative(obj, r_sym, elfcpp::R_TILEGX_RELATIVE,
  2439. this->got_, got_offset, 0, false);
  2440. break;
  2441. case GOT_TYPE_TLS_OFFSET:
  2442. rela_dyn->add_local(obj, r_sym,
  2443. size == 32 ? elfcpp::R_TILEGX_TLS_DTPOFF32
  2444. : elfcpp::R_TILEGX_TLS_DTPOFF64,
  2445. this->got_, got_offset, 0);
  2446. break;
  2447. case GOT_TYPE_TLS_PAIR:
  2448. this->got_->reserve_slot(got_index + 1);
  2449. rela_dyn->add_local(obj, r_sym,
  2450. size == 32 ? elfcpp::R_TILEGX_TLS_DTPMOD32
  2451. : elfcpp::R_TILEGX_TLS_DTPMOD64,
  2452. this->got_, got_offset, 0);
  2453. break;
  2454. case GOT_TYPE_TLS_DESC:
  2455. gold_fatal(_("TLS_DESC not yet supported for incremental linking"));
  2456. break;
  2457. default:
  2458. gold_unreachable();
  2459. }
  2460. }
  2461. // Reserve a GOT entry for a global symbol, and regenerate any
  2462. // necessary dynamic relocations.
  2463. template<int size, bool big_endian>
  2464. void
  2465. Target_tilegx<size, big_endian>::reserve_global_got_entry(
  2466. unsigned int got_index, Symbol* gsym, unsigned int got_type)
  2467. {
  2468. unsigned int got_offset = (got_index + TILEGX_GOT_RESERVE_COUNT)
  2469. * (size / 8);
  2470. Reloc_section* rela_dyn = this->rela_dyn_section(NULL);
  2471. this->got_->reserve_global(got_index, gsym, got_type);
  2472. switch (got_type)
  2473. {
  2474. case GOT_TYPE_STANDARD:
  2475. if (!gsym->final_value_is_known())
  2476. {
  2477. if (gsym->is_from_dynobj()
  2478. || gsym->is_undefined()
  2479. || gsym->is_preemptible()
  2480. || gsym->type() == elfcpp::STT_GNU_IFUNC)
  2481. rela_dyn->add_global(gsym, elfcpp::R_TILEGX_GLOB_DAT,
  2482. this->got_, got_offset, 0);
  2483. else
  2484. rela_dyn->add_global_relative(gsym, elfcpp::R_TILEGX_RELATIVE,
  2485. this->got_, got_offset, 0, false);
  2486. }
  2487. break;
  2488. case GOT_TYPE_TLS_OFFSET:
  2489. rela_dyn->add_global_relative(gsym,
  2490. size == 32 ? elfcpp::R_TILEGX_TLS_TPOFF32
  2491. : elfcpp::R_TILEGX_TLS_TPOFF64,
  2492. this->got_, got_offset, 0, false);
  2493. break;
  2494. case GOT_TYPE_TLS_PAIR:
  2495. this->got_->reserve_slot(got_index + 1);
  2496. rela_dyn->add_global_relative(gsym,
  2497. size == 32 ? elfcpp::R_TILEGX_TLS_DTPMOD32
  2498. : elfcpp::R_TILEGX_TLS_DTPMOD64,
  2499. this->got_, got_offset, 0, false);
  2500. rela_dyn->add_global_relative(gsym,
  2501. size == 32 ? elfcpp::R_TILEGX_TLS_DTPOFF32
  2502. : elfcpp::R_TILEGX_TLS_DTPOFF64,
  2503. this->got_, got_offset + size / 8,
  2504. 0, false);
  2505. break;
  2506. case GOT_TYPE_TLS_DESC:
  2507. gold_fatal(_("TLS_DESC not yet supported for TILEGX"));
  2508. break;
  2509. default:
  2510. gold_unreachable();
  2511. }
  2512. }
  2513. // Register an existing PLT entry for a global symbol.
  2514. template<int size, bool big_endian>
  2515. void
  2516. Target_tilegx<size, big_endian>::register_global_plt_entry(
  2517. Symbol_table* symtab, Layout* layout, unsigned int plt_index, Symbol* gsym)
  2518. {
  2519. gold_assert(this->plt_ != NULL);
  2520. gold_assert(!gsym->has_plt_offset());
  2521. this->plt_->reserve_slot(plt_index);
  2522. gsym->set_plt_offset((plt_index + 1) * this->plt_entry_size());
  2523. unsigned int got_offset = (plt_index + 2) * (size / 8);
  2524. this->plt_->add_relocation(symtab, layout, gsym, got_offset);
  2525. }
  2526. // Force a COPY relocation for a given symbol.
  2527. template<int size, bool big_endian>
  2528. void
  2529. Target_tilegx<size, big_endian>::emit_copy_reloc(
  2530. Symbol_table* symtab, Symbol* sym, Output_section* os, off_t offset)
  2531. {
  2532. this->copy_relocs_.emit_copy_reloc(symtab,
  2533. symtab->get_sized_symbol<size>(sym),
  2534. os,
  2535. offset,
  2536. this->rela_dyn_section(NULL));
  2537. }
  2538. // Create a GOT entry for the TLS module index.
  2539. template<int size, bool big_endian>
  2540. unsigned int
  2541. Target_tilegx<size, big_endian>::got_mod_index_entry(Symbol_table* symtab,
  2542. Layout* layout,
  2543. Sized_relobj_file<size, big_endian>* object)
  2544. {
  2545. if (this->got_mod_index_offset_ == -1U)
  2546. {
  2547. gold_assert(symtab != NULL && layout != NULL && object != NULL);
  2548. Reloc_section* rela_dyn = this->rela_dyn_section(layout);
  2549. Output_data_got<size, big_endian>* got
  2550. = this->got_section(symtab, layout);
  2551. unsigned int got_offset = got->add_constant(0);
  2552. rela_dyn->add_local(object, 0,
  2553. size == 32 ? elfcpp::R_TILEGX_TLS_DTPMOD32
  2554. : elfcpp::R_TILEGX_TLS_DTPMOD64, got,
  2555. got_offset, 0);
  2556. got->add_constant(0);
  2557. this->got_mod_index_offset_ = got_offset;
  2558. }
  2559. return this->got_mod_index_offset_;
  2560. }
  2561. // Optimize the TLS relocation type based on what we know about the
  2562. // symbol. IS_FINAL is true if the final address of this symbol is
  2563. // known at link time.
  2564. //
  2565. // the transformation rules is described below:
  2566. //
  2567. // compiler GD reference
  2568. // |
  2569. // V
  2570. // moveli tmp, hw1_last_tls_gd(x) X0/X1
  2571. // shl16insli r0, tmp, hw0_tls_gd(x) X0/X1
  2572. // addi r0, got, tls_add(x) Y0/Y1/X0/X1
  2573. // jal tls_gd_call(x) X1
  2574. // addi adr, r0, tls_gd_add(x) Y0/Y1/X0/X1
  2575. //
  2576. // linker tranformation of GD insn sequence
  2577. // |
  2578. // V
  2579. // ==> GD:
  2580. // moveli tmp, hw1_last_tls_gd(x) X0/X1
  2581. // shl16insli r0, tmp, hw0_tls_gd(x) X0/X1
  2582. // add r0, got, r0 Y0/Y1/X0/X1
  2583. // jal plt(__tls_get_addr) X1
  2584. // move adr, r0 Y0/Y1/X0/X1
  2585. // ==> IE:
  2586. // moveli tmp, hw1_last_tls_ie(x) X0/X1
  2587. // shl16insli r0, tmp, hw0_tls_ie(x) X0/X1
  2588. // add r0, got, r0 Y0/Y1/X0/X1
  2589. // ld r0, r0 X1
  2590. // add adr, r0, tp Y0/Y1/X0/X1
  2591. // ==> LE:
  2592. // moveli tmp, hw1_last_tls_le(x) X0/X1
  2593. // shl16insli r0, tmp, hw0_tls_le(x) X0/X1
  2594. // move r0, r0 Y0/Y1/X0/X1
  2595. // move r0, r0 Y0/Y1/X0/X1
  2596. // add adr, r0, tp Y0/Y1/X0/X1
  2597. //
  2598. //
  2599. // compiler IE reference
  2600. // |
  2601. // V
  2602. // moveli tmp, hw1_last_tls_ie(x) X0/X1
  2603. // shl16insli tmp, tmp, hw0_tls_ie(x) X0/X1
  2604. // addi tmp, got, tls_add(x) Y0/Y1/X0/X1
  2605. // ld_tls tmp, tmp, tls_ie_load(x) X1
  2606. // add adr, tmp, tp Y0/Y1/X0/X1
  2607. //
  2608. // linker transformation for IE insn sequence
  2609. // |
  2610. // V
  2611. // ==> IE:
  2612. // moveli tmp, hw1_last_tls_ie(x) X0/X1
  2613. // shl16insli tmp, tmp, hw0_tls_ie(x) X0/X1
  2614. // add tmp, got, tmp Y0/Y1/X0/X1
  2615. // ld tmp, tmp X1
  2616. // add adr, tmp, tp Y0/Y1/X0/X1
  2617. // ==> LE:
  2618. // moveli tmp, hw1_last_tls_le(x) X0/X1
  2619. // shl16insli tmp, tmp, hw0_tls_le(x) X0/X1
  2620. // move tmp, tmp Y0/Y1/X0/X1
  2621. // move tmp, tmp Y0/Y1/X0/X1
  2622. //
  2623. //
  2624. // compiler LE reference
  2625. // |
  2626. // V
  2627. // moveli tmp, hw1_last_tls_le(x) X0/X1
  2628. // shl16insli tmp, tmp, hw0_tls_le(x) X0/X1
  2629. // add adr, tmp, tp Y0/Y1/X0/X1
  2630. template<int size, bool big_endian>
  2631. tls::Tls_optimization
  2632. Target_tilegx<size, big_endian>::optimize_tls_reloc(bool is_final, int r_type)
  2633. {
  2634. // If we are generating a shared library, then we can't do anything
  2635. // in the linker.
  2636. if (parameters->options().shared())
  2637. return tls::TLSOPT_NONE;
  2638. switch (r_type)
  2639. {
  2640. // unique GD relocations
  2641. case elfcpp::R_TILEGX_TLS_GD_CALL:
  2642. case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
  2643. case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
  2644. case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
  2645. case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
  2646. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
  2647. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
  2648. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  2649. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  2650. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  2651. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  2652. // These are General-Dynamic which permits fully general TLS
  2653. // access. Since we know that we are generating an executable,
  2654. // we can convert this to Initial-Exec. If we also know that
  2655. // this is a local symbol, we can further switch to Local-Exec.
  2656. if (is_final)
  2657. return tls::TLSOPT_TO_LE;
  2658. return tls::TLSOPT_TO_IE;
  2659. // unique IE relocations
  2660. case elfcpp::R_TILEGX_TLS_IE_LOAD:
  2661. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
  2662. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
  2663. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  2664. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  2665. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  2666. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  2667. // These are Initial-Exec relocs which get the thread offset
  2668. // from the GOT. If we know that we are linking against the
  2669. // local symbol, we can switch to Local-Exec, which links the
  2670. // thread offset into the instruction.
  2671. if (is_final)
  2672. return tls::TLSOPT_TO_LE;
  2673. return tls::TLSOPT_NONE;
  2674. // could be created for both GD and IE
  2675. // but they are expanded into the same
  2676. // instruction in GD and IE.
  2677. case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
  2678. case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
  2679. case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
  2680. case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
  2681. if (is_final)
  2682. return tls::TLSOPT_TO_LE;
  2683. return tls::TLSOPT_NONE;
  2684. // unique LE relocations
  2685. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
  2686. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
  2687. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
  2688. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
  2689. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
  2690. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
  2691. // When we already have Local-Exec, there is nothing further we
  2692. // can do.
  2693. return tls::TLSOPT_NONE;
  2694. default:
  2695. gold_unreachable();
  2696. }
  2697. }
  2698. // Get the Reference_flags for a particular relocation.
  2699. template<int size, bool big_endian>
  2700. int
  2701. Target_tilegx<size, big_endian>::Scan::get_reference_flags(unsigned int r_type)
  2702. {
  2703. switch (r_type)
  2704. {
  2705. case elfcpp::R_TILEGX_NONE:
  2706. case elfcpp::R_TILEGX_GNU_VTINHERIT:
  2707. case elfcpp::R_TILEGX_GNU_VTENTRY:
  2708. // No symbol reference.
  2709. return 0;
  2710. case elfcpp::R_TILEGX_64:
  2711. case elfcpp::R_TILEGX_32:
  2712. case elfcpp::R_TILEGX_16:
  2713. case elfcpp::R_TILEGX_8:
  2714. return Symbol::ABSOLUTE_REF;
  2715. case elfcpp::R_TILEGX_BROFF_X1:
  2716. case elfcpp::R_TILEGX_64_PCREL:
  2717. case elfcpp::R_TILEGX_32_PCREL:
  2718. case elfcpp::R_TILEGX_16_PCREL:
  2719. case elfcpp::R_TILEGX_8_PCREL:
  2720. case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
  2721. case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
  2722. case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
  2723. case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
  2724. case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
  2725. case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
  2726. case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
  2727. case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
  2728. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
  2729. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
  2730. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
  2731. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
  2732. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
  2733. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
  2734. return Symbol::RELATIVE_REF;
  2735. case elfcpp::R_TILEGX_JUMPOFF_X1:
  2736. case elfcpp::R_TILEGX_JUMPOFF_X1_PLT:
  2737. case elfcpp::R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
  2738. case elfcpp::R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
  2739. case elfcpp::R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
  2740. case elfcpp::R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
  2741. case elfcpp::R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
  2742. case elfcpp::R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
  2743. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
  2744. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
  2745. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
  2746. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
  2747. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
  2748. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
  2749. return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF;
  2750. case elfcpp::R_TILEGX_IMM16_X0_HW0:
  2751. case elfcpp::R_TILEGX_IMM16_X1_HW0:
  2752. case elfcpp::R_TILEGX_IMM16_X0_HW1:
  2753. case elfcpp::R_TILEGX_IMM16_X1_HW1:
  2754. case elfcpp::R_TILEGX_IMM16_X0_HW2:
  2755. case elfcpp::R_TILEGX_IMM16_X1_HW2:
  2756. case elfcpp::R_TILEGX_IMM16_X0_HW3:
  2757. case elfcpp::R_TILEGX_IMM16_X1_HW3:
  2758. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
  2759. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
  2760. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
  2761. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
  2762. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
  2763. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
  2764. return Symbol::ABSOLUTE_REF;
  2765. case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
  2766. case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
  2767. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
  2768. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
  2769. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
  2770. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
  2771. // Absolute in GOT.
  2772. return Symbol::ABSOLUTE_REF;
  2773. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
  2774. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
  2775. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
  2776. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
  2777. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
  2778. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
  2779. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
  2780. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
  2781. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  2782. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  2783. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  2784. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  2785. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
  2786. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
  2787. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  2788. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  2789. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  2790. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  2791. case elfcpp::R_TILEGX_TLS_DTPOFF64:
  2792. case elfcpp::R_TILEGX_TLS_DTPMOD32:
  2793. case elfcpp::R_TILEGX_TLS_DTPOFF32:
  2794. case elfcpp::R_TILEGX_TLS_TPOFF32:
  2795. case elfcpp::R_TILEGX_TLS_GD_CALL:
  2796. case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
  2797. case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
  2798. case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
  2799. case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
  2800. case elfcpp::R_TILEGX_TLS_IE_LOAD:
  2801. case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
  2802. case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
  2803. case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
  2804. case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
  2805. return Symbol::TLS_REF;
  2806. case elfcpp::R_TILEGX_COPY:
  2807. case elfcpp::R_TILEGX_GLOB_DAT:
  2808. case elfcpp::R_TILEGX_JMP_SLOT:
  2809. case elfcpp::R_TILEGX_RELATIVE:
  2810. case elfcpp::R_TILEGX_TLS_TPOFF64:
  2811. case elfcpp::R_TILEGX_TLS_DTPMOD64:
  2812. default:
  2813. // Not expected. We will give an error later.
  2814. return 0;
  2815. }
  2816. }
  2817. // Report an unsupported relocation against a local symbol.
  2818. template<int size, bool big_endian>
  2819. void
  2820. Target_tilegx<size, big_endian>::Scan::unsupported_reloc_local(
  2821. Sized_relobj_file<size, big_endian>* object,
  2822. unsigned int r_type)
  2823. {
  2824. gold_error(_("%s: unsupported reloc %u against local symbol"),
  2825. object->name().c_str(), r_type);
  2826. }
  2827. // We are about to emit a dynamic relocation of type R_TYPE. If the
  2828. // dynamic linker does not support it, issue an error.
  2829. template<int size, bool big_endian>
  2830. void
  2831. Target_tilegx<size, big_endian>::Scan::check_non_pic(Relobj* object,
  2832. unsigned int r_type)
  2833. {
  2834. switch (r_type)
  2835. {
  2836. // These are the relocation types supported by glibc for tilegx
  2837. // which should always work.
  2838. case elfcpp::R_TILEGX_RELATIVE:
  2839. case elfcpp::R_TILEGX_GLOB_DAT:
  2840. case elfcpp::R_TILEGX_JMP_SLOT:
  2841. case elfcpp::R_TILEGX_TLS_DTPMOD64:
  2842. case elfcpp::R_TILEGX_TLS_DTPOFF64:
  2843. case elfcpp::R_TILEGX_TLS_TPOFF64:
  2844. case elfcpp::R_TILEGX_8:
  2845. case elfcpp::R_TILEGX_16:
  2846. case elfcpp::R_TILEGX_32:
  2847. case elfcpp::R_TILEGX_64:
  2848. case elfcpp::R_TILEGX_COPY:
  2849. case elfcpp::R_TILEGX_IMM16_X0_HW0:
  2850. case elfcpp::R_TILEGX_IMM16_X1_HW0:
  2851. case elfcpp::R_TILEGX_IMM16_X0_HW1:
  2852. case elfcpp::R_TILEGX_IMM16_X1_HW1:
  2853. case elfcpp::R_TILEGX_IMM16_X0_HW2:
  2854. case elfcpp::R_TILEGX_IMM16_X1_HW2:
  2855. case elfcpp::R_TILEGX_IMM16_X0_HW3:
  2856. case elfcpp::R_TILEGX_IMM16_X1_HW3:
  2857. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
  2858. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
  2859. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
  2860. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
  2861. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
  2862. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
  2863. case elfcpp::R_TILEGX_BROFF_X1:
  2864. case elfcpp::R_TILEGX_JUMPOFF_X1:
  2865. case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
  2866. case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
  2867. case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
  2868. case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
  2869. case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
  2870. case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
  2871. case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
  2872. case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
  2873. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
  2874. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
  2875. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
  2876. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
  2877. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
  2878. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
  2879. return;
  2880. default:
  2881. // This prevents us from issuing more than one error per reloc
  2882. // section. But we can still wind up issuing more than one
  2883. // error per object file.
  2884. if (this->issued_non_pic_error_)
  2885. return;
  2886. gold_assert(parameters->options().output_is_position_independent());
  2887. object->error(_("requires unsupported dynamic reloc %u; "
  2888. "recompile with -fPIC"),
  2889. r_type);
  2890. this->issued_non_pic_error_ = true;
  2891. return;
  2892. case elfcpp::R_TILEGX_NONE:
  2893. gold_unreachable();
  2894. }
  2895. }
  2896. // Return whether we need to make a PLT entry for a relocation of the
  2897. // given type against a STT_GNU_IFUNC symbol.
  2898. template<int size, bool big_endian>
  2899. bool
  2900. Target_tilegx<size, big_endian>::Scan::reloc_needs_plt_for_ifunc(
  2901. Sized_relobj_file<size, big_endian>* object, unsigned int r_type)
  2902. {
  2903. int flags = Scan::get_reference_flags(r_type);
  2904. if (flags & Symbol::TLS_REF)
  2905. gold_error(_("%s: unsupported TLS reloc %u for IFUNC symbol"),
  2906. object->name().c_str(), r_type);
  2907. return flags != 0;
  2908. }
  2909. // Scan a relocation for a local symbol.
  2910. template<int size, bool big_endian>
  2911. inline void
  2912. Target_tilegx<size, big_endian>::Scan::local(Symbol_table* symtab,
  2913. Layout* layout,
  2914. Target_tilegx<size, big_endian>* target,
  2915. Sized_relobj_file<size, big_endian>* object,
  2916. unsigned int data_shndx,
  2917. Output_section* output_section,
  2918. const elfcpp::Rela<size, big_endian>& reloc,
  2919. unsigned int r_type,
  2920. const elfcpp::Sym<size, big_endian>& lsym,
  2921. bool is_discarded)
  2922. {
  2923. if (is_discarded)
  2924. return;
  2925. // A local STT_GNU_IFUNC symbol may require a PLT entry.
  2926. bool is_ifunc = lsym.get_st_type() == elfcpp::STT_GNU_IFUNC;
  2927. if (is_ifunc && this->reloc_needs_plt_for_ifunc(object, r_type))
  2928. {
  2929. unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
  2930. target->make_local_ifunc_plt_entry(symtab, layout, object, r_sym);
  2931. }
  2932. switch (r_type)
  2933. {
  2934. case elfcpp::R_TILEGX_NONE:
  2935. case elfcpp::R_TILEGX_GNU_VTINHERIT:
  2936. case elfcpp::R_TILEGX_GNU_VTENTRY:
  2937. break;
  2938. // If building a shared library (or a position-independent
  2939. // executable), because the runtime address needs plus
  2940. // the module base address, so generate a R_TILEGX_RELATIVE.
  2941. case elfcpp::R_TILEGX_32:
  2942. case elfcpp::R_TILEGX_64:
  2943. if (parameters->options().output_is_position_independent())
  2944. {
  2945. unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
  2946. Reloc_section* rela_dyn = target->rela_dyn_section(layout);
  2947. rela_dyn->add_local_relative(object, r_sym,
  2948. elfcpp::R_TILEGX_RELATIVE,
  2949. output_section, data_shndx,
  2950. reloc.get_r_offset(),
  2951. reloc.get_r_addend(), is_ifunc);
  2952. }
  2953. break;
  2954. // If building a shared library (or a position-independent
  2955. // executable), we need to create a dynamic relocation for this
  2956. // location.
  2957. case elfcpp::R_TILEGX_8:
  2958. case elfcpp::R_TILEGX_16:
  2959. case elfcpp::R_TILEGX_IMM16_X0_HW0:
  2960. case elfcpp::R_TILEGX_IMM16_X1_HW0:
  2961. case elfcpp::R_TILEGX_IMM16_X0_HW1:
  2962. case elfcpp::R_TILEGX_IMM16_X1_HW1:
  2963. case elfcpp::R_TILEGX_IMM16_X0_HW2:
  2964. case elfcpp::R_TILEGX_IMM16_X1_HW2:
  2965. case elfcpp::R_TILEGX_IMM16_X0_HW3:
  2966. case elfcpp::R_TILEGX_IMM16_X1_HW3:
  2967. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
  2968. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
  2969. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
  2970. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
  2971. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
  2972. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
  2973. if (parameters->options().output_is_position_independent())
  2974. {
  2975. this->check_non_pic(object, r_type);
  2976. Reloc_section* rela_dyn = target->rela_dyn_section(layout);
  2977. unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
  2978. if (lsym.get_st_type() != elfcpp::STT_SECTION)
  2979. rela_dyn->add_local(object, r_sym, r_type, output_section,
  2980. data_shndx, reloc.get_r_offset(),
  2981. reloc.get_r_addend());
  2982. else
  2983. {
  2984. gold_assert(lsym.get_st_value() == 0);
  2985. rela_dyn->add_symbolless_local_addend(object, r_sym, r_type,
  2986. output_section,
  2987. data_shndx,
  2988. reloc.get_r_offset(),
  2989. reloc.get_r_addend());
  2990. }
  2991. }
  2992. break;
  2993. // R_TILEGX_JUMPOFF_X1_PLT against local symbol
  2994. // may happen for ifunc case.
  2995. case elfcpp::R_TILEGX_JUMPOFF_X1_PLT:
  2996. case elfcpp::R_TILEGX_JUMPOFF_X1:
  2997. case elfcpp::R_TILEGX_64_PCREL:
  2998. case elfcpp::R_TILEGX_32_PCREL:
  2999. case elfcpp::R_TILEGX_16_PCREL:
  3000. case elfcpp::R_TILEGX_8_PCREL:
  3001. case elfcpp::R_TILEGX_BROFF_X1:
  3002. case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
  3003. case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
  3004. case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
  3005. case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
  3006. case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
  3007. case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
  3008. case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
  3009. case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
  3010. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
  3011. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
  3012. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
  3013. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
  3014. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
  3015. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
  3016. case elfcpp::R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
  3017. case elfcpp::R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
  3018. case elfcpp::R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
  3019. case elfcpp::R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
  3020. case elfcpp::R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
  3021. case elfcpp::R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
  3022. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
  3023. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
  3024. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
  3025. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
  3026. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
  3027. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
  3028. break;
  3029. case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
  3030. case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
  3031. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
  3032. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
  3033. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
  3034. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
  3035. {
  3036. // The symbol requires a GOT entry.
  3037. Output_data_got<size, big_endian>* got
  3038. = target->got_section(symtab, layout);
  3039. unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
  3040. // For a STT_GNU_IFUNC symbol we want the PLT offset. That
  3041. // lets function pointers compare correctly with shared
  3042. // libraries. Otherwise we would need an IRELATIVE reloc.
  3043. bool is_new;
  3044. if (is_ifunc)
  3045. is_new = got->add_local_plt(object, r_sym, GOT_TYPE_STANDARD);
  3046. else
  3047. is_new = got->add_local(object, r_sym, GOT_TYPE_STANDARD);
  3048. if (is_new)
  3049. {
  3050. // tilegx dynamic linker will not update local got entry,
  3051. // so, if we are generating a shared object, we need to add a
  3052. // dynamic relocation for this symbol's GOT entry to inform
  3053. // dynamic linker plus the load base explicitly.
  3054. if (parameters->options().output_is_position_independent())
  3055. {
  3056. unsigned int got_offset
  3057. = object->local_got_offset(r_sym, GOT_TYPE_STANDARD);
  3058. Reloc_section* rela_dyn = target->rela_dyn_section(layout);
  3059. rela_dyn->add_local_relative(object, r_sym,
  3060. r_type,
  3061. got, got_offset, 0, is_ifunc);
  3062. }
  3063. }
  3064. }
  3065. break;
  3066. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
  3067. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
  3068. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
  3069. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
  3070. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
  3071. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
  3072. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
  3073. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
  3074. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  3075. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  3076. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  3077. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  3078. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
  3079. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
  3080. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  3081. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  3082. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  3083. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  3084. case elfcpp::R_TILEGX_TLS_GD_CALL:
  3085. case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
  3086. case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
  3087. case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
  3088. case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
  3089. case elfcpp::R_TILEGX_TLS_IE_LOAD:
  3090. case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
  3091. case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
  3092. case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
  3093. case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
  3094. {
  3095. bool output_is_shared = parameters->options().shared();
  3096. const tls::Tls_optimization opt_t =
  3097. Target_tilegx<size, big_endian>::optimize_tls_reloc(
  3098. !output_is_shared, r_type);
  3099. switch (r_type)
  3100. {
  3101. case elfcpp::R_TILEGX_TLS_GD_CALL:
  3102. // FIXME: predefine __tls_get_addr
  3103. //
  3104. // R_TILEGX_TLS_GD_CALL implicitly reference __tls_get_addr,
  3105. // while all other target, x86/arm/mips/powerpc/sparc
  3106. // generate tls relocation against __tls_get_addr explicitly,
  3107. // so for TILEGX, we need the following hack.
  3108. if (opt_t == tls::TLSOPT_NONE) {
  3109. if (!target->tls_get_addr_sym_defined_) {
  3110. Symbol* sym = NULL;
  3111. options::parse_set(NULL, "__tls_get_addr",
  3112. (gold::options::String_set*)
  3113. &parameters->options().undefined());
  3114. symtab->add_undefined_symbols_from_command_line(layout);
  3115. target->tls_get_addr_sym_defined_ = true;
  3116. sym = symtab->lookup("__tls_get_addr");
  3117. sym->set_in_reg();
  3118. }
  3119. target->make_plt_entry(symtab, layout,
  3120. symtab->lookup("__tls_get_addr"));
  3121. }
  3122. break;
  3123. // only make effect when applying relocation
  3124. case elfcpp::R_TILEGX_TLS_IE_LOAD:
  3125. case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
  3126. case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
  3127. case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
  3128. case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
  3129. case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
  3130. case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
  3131. case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
  3132. case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
  3133. break;
  3134. // GD: requires two GOT entry for module index and offset
  3135. // IE: requires one GOT entry for tp-relative offset
  3136. // LE: shouldn't happen for global symbol
  3137. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
  3138. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
  3139. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  3140. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  3141. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  3142. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  3143. {
  3144. if (opt_t == tls::TLSOPT_NONE) {
  3145. Output_data_got<size, big_endian> *got
  3146. = target->got_section(symtab, layout);
  3147. unsigned int r_sym
  3148. = elfcpp::elf_r_sym<size>(reloc.get_r_info());
  3149. unsigned int shndx = lsym.get_st_shndx();
  3150. bool is_ordinary;
  3151. shndx = object->adjust_sym_shndx(r_sym, shndx,
  3152. &is_ordinary);
  3153. if (!is_ordinary)
  3154. object->error(_("local symbol %u has bad shndx %u"),
  3155. r_sym, shndx);
  3156. else
  3157. got->add_local_pair_with_rel(object, r_sym, shndx,
  3158. GOT_TYPE_TLS_PAIR,
  3159. target->rela_dyn_section(layout),
  3160. size == 32
  3161. ? elfcpp::R_TILEGX_TLS_DTPMOD32
  3162. : elfcpp::R_TILEGX_TLS_DTPMOD64);
  3163. } else if (opt_t == tls::TLSOPT_TO_IE) {
  3164. Output_data_got<size, big_endian>* got
  3165. = target->got_section(symtab, layout);
  3166. Reloc_section* rela_dyn
  3167. = target->rela_dyn_section(layout);
  3168. unsigned int r_sym
  3169. = elfcpp::elf_r_sym<size>(reloc.get_r_info());
  3170. unsigned int off = got->add_constant(0);
  3171. object->set_local_got_offset(r_sym,
  3172. GOT_TYPE_TLS_OFFSET,off);
  3173. rela_dyn->add_symbolless_local_addend(object, r_sym,
  3174. size == 32
  3175. ? elfcpp::R_TILEGX_TLS_TPOFF32
  3176. : elfcpp::R_TILEGX_TLS_TPOFF64,
  3177. got, off, 0);
  3178. } else if (opt_t != tls::TLSOPT_TO_LE)
  3179. // only TO_LE is allowed for local symbol
  3180. unsupported_reloc_local(object, r_type);
  3181. }
  3182. break;
  3183. // IE
  3184. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
  3185. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
  3186. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  3187. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  3188. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  3189. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  3190. {
  3191. layout->set_has_static_tls();
  3192. if (opt_t == tls::TLSOPT_NONE) {
  3193. Output_data_got<size, big_endian>* got
  3194. = target->got_section(symtab, layout);
  3195. Reloc_section* rela_dyn
  3196. = target->rela_dyn_section(layout);
  3197. unsigned int r_sym
  3198. = elfcpp::elf_r_sym<size>(reloc.get_r_info());
  3199. unsigned int off = got->add_constant(0);
  3200. object->set_local_got_offset(r_sym,
  3201. GOT_TYPE_TLS_OFFSET, off);
  3202. rela_dyn->add_symbolless_local_addend(object, r_sym,
  3203. size == 32
  3204. ? elfcpp::R_TILEGX_TLS_TPOFF32
  3205. : elfcpp::R_TILEGX_TLS_TPOFF64,
  3206. got, off, 0);
  3207. } else if (opt_t != tls::TLSOPT_TO_LE)
  3208. unsupported_reloc_local(object, r_type);
  3209. }
  3210. break;
  3211. // LE
  3212. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
  3213. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
  3214. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
  3215. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
  3216. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
  3217. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
  3218. layout->set_has_static_tls();
  3219. if (parameters->options().shared()) {
  3220. // defer to dynamic linker
  3221. gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
  3222. unsigned int r_sym
  3223. = elfcpp::elf_r_sym<size>(reloc.get_r_info());
  3224. Reloc_section* rela_dyn = target->rela_dyn_section(layout);
  3225. rela_dyn->add_symbolless_local_addend(object, r_sym, r_type,
  3226. output_section, data_shndx,
  3227. reloc.get_r_offset(), 0);
  3228. }
  3229. break;
  3230. default:
  3231. gold_unreachable();
  3232. }
  3233. }
  3234. break;
  3235. case elfcpp::R_TILEGX_COPY:
  3236. case elfcpp::R_TILEGX_GLOB_DAT:
  3237. case elfcpp::R_TILEGX_JMP_SLOT:
  3238. case elfcpp::R_TILEGX_RELATIVE:
  3239. // These are outstanding tls relocs, which are unexpected when linking
  3240. case elfcpp::R_TILEGX_TLS_TPOFF32:
  3241. case elfcpp::R_TILEGX_TLS_TPOFF64:
  3242. case elfcpp::R_TILEGX_TLS_DTPMOD32:
  3243. case elfcpp::R_TILEGX_TLS_DTPMOD64:
  3244. case elfcpp::R_TILEGX_TLS_DTPOFF32:
  3245. case elfcpp::R_TILEGX_TLS_DTPOFF64:
  3246. gold_error(_("%s: unexpected reloc %u in object file"),
  3247. object->name().c_str(), r_type);
  3248. break;
  3249. default:
  3250. gold_error(_("%s: unsupported reloc %u against local symbol"),
  3251. object->name().c_str(), r_type);
  3252. break;
  3253. }
  3254. }
  3255. // Report an unsupported relocation against a global symbol.
  3256. template<int size, bool big_endian>
  3257. void
  3258. Target_tilegx<size, big_endian>::Scan::unsupported_reloc_global(
  3259. Sized_relobj_file<size, big_endian>* object,
  3260. unsigned int r_type,
  3261. Symbol* gsym)
  3262. {
  3263. gold_error(_("%s: unsupported reloc %u against global symbol %s"),
  3264. object->name().c_str(), r_type, gsym->demangled_name().c_str());
  3265. }
  3266. // Returns true if this relocation type could be that of a function pointer.
  3267. template<int size, bool big_endian>
  3268. inline bool
  3269. Target_tilegx<size, big_endian>::Scan::possible_function_pointer_reloc(
  3270. unsigned int r_type)
  3271. {
  3272. switch (r_type)
  3273. {
  3274. case elfcpp::R_TILEGX_IMM16_X0_HW0:
  3275. case elfcpp::R_TILEGX_IMM16_X1_HW0:
  3276. case elfcpp::R_TILEGX_IMM16_X0_HW1:
  3277. case elfcpp::R_TILEGX_IMM16_X1_HW1:
  3278. case elfcpp::R_TILEGX_IMM16_X0_HW2:
  3279. case elfcpp::R_TILEGX_IMM16_X1_HW2:
  3280. case elfcpp::R_TILEGX_IMM16_X0_HW3:
  3281. case elfcpp::R_TILEGX_IMM16_X1_HW3:
  3282. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
  3283. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
  3284. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
  3285. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
  3286. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
  3287. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
  3288. case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
  3289. case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
  3290. case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
  3291. case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
  3292. case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
  3293. case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
  3294. case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
  3295. case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
  3296. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
  3297. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
  3298. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
  3299. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
  3300. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
  3301. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
  3302. case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
  3303. case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
  3304. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
  3305. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
  3306. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
  3307. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
  3308. {
  3309. return true;
  3310. }
  3311. }
  3312. return false;
  3313. }
  3314. // For safe ICF, scan a relocation for a local symbol to check if it
  3315. // corresponds to a function pointer being taken. In that case mark
  3316. // the function whose pointer was taken as not foldable.
  3317. template<int size, bool big_endian>
  3318. inline bool
  3319. Target_tilegx<size, big_endian>::Scan::local_reloc_may_be_function_pointer(
  3320. Symbol_table* ,
  3321. Layout* ,
  3322. Target_tilegx<size, big_endian>* ,
  3323. Sized_relobj_file<size, big_endian>* ,
  3324. unsigned int ,
  3325. Output_section* ,
  3326. const elfcpp::Rela<size, big_endian>& ,
  3327. unsigned int r_type,
  3328. const elfcpp::Sym<size, big_endian>&)
  3329. {
  3330. return possible_function_pointer_reloc(r_type);
  3331. }
  3332. // For safe ICF, scan a relocation for a global symbol to check if it
  3333. // corresponds to a function pointer being taken. In that case mark
  3334. // the function whose pointer was taken as not foldable.
  3335. template<int size, bool big_endian>
  3336. inline bool
  3337. Target_tilegx<size, big_endian>::Scan::global_reloc_may_be_function_pointer(
  3338. Symbol_table*,
  3339. Layout* ,
  3340. Target_tilegx<size, big_endian>* ,
  3341. Sized_relobj_file<size, big_endian>* ,
  3342. unsigned int ,
  3343. Output_section* ,
  3344. const elfcpp::Rela<size, big_endian>& ,
  3345. unsigned int r_type,
  3346. Symbol* gsym)
  3347. {
  3348. // GOT is not a function.
  3349. if (strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
  3350. return false;
  3351. // When building a shared library, do not fold symbols whose visibility
  3352. // is hidden, internal or protected.
  3353. return ((parameters->options().shared()
  3354. && (gsym->visibility() == elfcpp::STV_INTERNAL
  3355. || gsym->visibility() == elfcpp::STV_PROTECTED
  3356. || gsym->visibility() == elfcpp::STV_HIDDEN))
  3357. || possible_function_pointer_reloc(r_type));
  3358. }
  3359. // Scan a relocation for a global symbol.
  3360. template<int size, bool big_endian>
  3361. inline void
  3362. Target_tilegx<size, big_endian>::Scan::global(Symbol_table* symtab,
  3363. Layout* layout,
  3364. Target_tilegx<size, big_endian>* target,
  3365. Sized_relobj_file<size, big_endian>* object,
  3366. unsigned int data_shndx,
  3367. Output_section* output_section,
  3368. const elfcpp::Rela<size, big_endian>& reloc,
  3369. unsigned int r_type,
  3370. Symbol* gsym)
  3371. {
  3372. // A reference to _GLOBAL_OFFSET_TABLE_ implies that we need a got
  3373. // section. We check here to avoid creating a dynamic reloc against
  3374. // _GLOBAL_OFFSET_TABLE_.
  3375. if (!target->has_got_section()
  3376. && strcmp(gsym->name(), "_GLOBAL_OFFSET_TABLE_") == 0)
  3377. target->got_section(symtab, layout);
  3378. // A STT_GNU_IFUNC symbol may require a PLT entry.
  3379. if (gsym->type() == elfcpp::STT_GNU_IFUNC
  3380. && this->reloc_needs_plt_for_ifunc(object, r_type))
  3381. target->make_plt_entry(symtab, layout, gsym);
  3382. switch (r_type)
  3383. {
  3384. case elfcpp::R_TILEGX_NONE:
  3385. case elfcpp::R_TILEGX_GNU_VTINHERIT:
  3386. case elfcpp::R_TILEGX_GNU_VTENTRY:
  3387. break;
  3388. case elfcpp::R_TILEGX_DEST_IMM8_X1:
  3389. case elfcpp::R_TILEGX_IMM16_X0_HW0:
  3390. case elfcpp::R_TILEGX_IMM16_X1_HW0:
  3391. case elfcpp::R_TILEGX_IMM16_X0_HW1:
  3392. case elfcpp::R_TILEGX_IMM16_X1_HW1:
  3393. case elfcpp::R_TILEGX_IMM16_X0_HW2:
  3394. case elfcpp::R_TILEGX_IMM16_X1_HW2:
  3395. case elfcpp::R_TILEGX_IMM16_X0_HW3:
  3396. case elfcpp::R_TILEGX_IMM16_X1_HW3:
  3397. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
  3398. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
  3399. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
  3400. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
  3401. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
  3402. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
  3403. case elfcpp::R_TILEGX_64:
  3404. case elfcpp::R_TILEGX_32:
  3405. case elfcpp::R_TILEGX_16:
  3406. case elfcpp::R_TILEGX_8:
  3407. {
  3408. // Make a PLT entry if necessary.
  3409. if (gsym->needs_plt_entry())
  3410. {
  3411. target->make_plt_entry(symtab, layout, gsym);
  3412. // Since this is not a PC-relative relocation, we may be
  3413. // taking the address of a function. In that case we need to
  3414. // set the entry in the dynamic symbol table to the address of
  3415. // the PLT entry.
  3416. if (gsym->is_from_dynobj() && !parameters->options().shared())
  3417. gsym->set_needs_dynsym_value();
  3418. }
  3419. // Make a dynamic relocation if necessary.
  3420. if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
  3421. {
  3422. if (!parameters->options().output_is_position_independent()
  3423. && gsym->may_need_copy_reloc())
  3424. {
  3425. target->copy_reloc(symtab, layout, object,
  3426. data_shndx, output_section, gsym, reloc);
  3427. }
  3428. else if (((size == 64 && r_type == elfcpp::R_TILEGX_64)
  3429. || (size == 32 && r_type == elfcpp::R_TILEGX_32))
  3430. && gsym->type() == elfcpp::STT_GNU_IFUNC
  3431. && gsym->can_use_relative_reloc(false)
  3432. && !gsym->is_from_dynobj()
  3433. && !gsym->is_undefined()
  3434. && !gsym->is_preemptible())
  3435. {
  3436. // Use an IRELATIVE reloc for a locally defined
  3437. // STT_GNU_IFUNC symbol. This makes a function
  3438. // address in a PIE executable match the address in a
  3439. // shared library that it links against.
  3440. Reloc_section* rela_dyn =
  3441. target->rela_irelative_section(layout);
  3442. unsigned int r_type = elfcpp::R_TILEGX_IRELATIVE;
  3443. rela_dyn->add_symbolless_global_addend(gsym, r_type,
  3444. output_section, object,
  3445. data_shndx,
  3446. reloc.get_r_offset(),
  3447. reloc.get_r_addend());
  3448. } else if ((r_type == elfcpp::R_TILEGX_64
  3449. || r_type == elfcpp::R_TILEGX_32)
  3450. && gsym->can_use_relative_reloc(false))
  3451. {
  3452. Reloc_section* rela_dyn = target->rela_dyn_section(layout);
  3453. rela_dyn->add_global_relative(gsym, elfcpp::R_TILEGX_RELATIVE,
  3454. output_section, object,
  3455. data_shndx,
  3456. reloc.get_r_offset(),
  3457. reloc.get_r_addend(), false);
  3458. }
  3459. else
  3460. {
  3461. this->check_non_pic(object, r_type);
  3462. Reloc_section* rela_dyn = target->rela_dyn_section(layout);
  3463. rela_dyn->add_global(gsym, r_type, output_section, object,
  3464. data_shndx, reloc.get_r_offset(),
  3465. reloc.get_r_addend());
  3466. }
  3467. }
  3468. }
  3469. break;
  3470. case elfcpp::R_TILEGX_BROFF_X1:
  3471. case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
  3472. case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
  3473. case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
  3474. case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
  3475. case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
  3476. case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
  3477. case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
  3478. case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
  3479. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
  3480. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
  3481. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
  3482. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
  3483. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
  3484. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
  3485. case elfcpp::R_TILEGX_64_PCREL:
  3486. case elfcpp::R_TILEGX_32_PCREL:
  3487. case elfcpp::R_TILEGX_16_PCREL:
  3488. case elfcpp::R_TILEGX_8_PCREL:
  3489. {
  3490. // Make a PLT entry if necessary.
  3491. if (gsym->needs_plt_entry())
  3492. target->make_plt_entry(symtab, layout, gsym);
  3493. // Make a dynamic relocation if necessary.
  3494. if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type)))
  3495. {
  3496. if (parameters->options().output_is_executable()
  3497. && gsym->may_need_copy_reloc())
  3498. {
  3499. target->copy_reloc(symtab, layout, object,
  3500. data_shndx, output_section, gsym, reloc);
  3501. }
  3502. else
  3503. {
  3504. this->check_non_pic(object, r_type);
  3505. Reloc_section* rela_dyn = target->rela_dyn_section(layout);
  3506. rela_dyn->add_global(gsym, r_type, output_section, object,
  3507. data_shndx, reloc.get_r_offset(),
  3508. reloc.get_r_addend());
  3509. }
  3510. }
  3511. }
  3512. break;
  3513. case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
  3514. case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
  3515. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
  3516. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
  3517. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
  3518. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
  3519. {
  3520. // The symbol requires a GOT entry.
  3521. Output_data_got<size, big_endian>* got
  3522. = target->got_section(symtab, layout);
  3523. if (gsym->final_value_is_known())
  3524. {
  3525. // For a STT_GNU_IFUNC symbol we want the PLT address.
  3526. if (gsym->type() == elfcpp::STT_GNU_IFUNC)
  3527. got->add_global_plt(gsym, GOT_TYPE_STANDARD);
  3528. else
  3529. got->add_global(gsym, GOT_TYPE_STANDARD);
  3530. }
  3531. else
  3532. {
  3533. // If this symbol is not fully resolved, we need to add a
  3534. // dynamic relocation for it.
  3535. Reloc_section* rela_dyn = target->rela_dyn_section(layout);
  3536. // Use a GLOB_DAT rather than a RELATIVE reloc if:
  3537. //
  3538. // 1) The symbol may be defined in some other module.
  3539. //
  3540. // 2) We are building a shared library and this is a
  3541. // protected symbol; using GLOB_DAT means that the dynamic
  3542. // linker can use the address of the PLT in the main
  3543. // executable when appropriate so that function address
  3544. // comparisons work.
  3545. //
  3546. // 3) This is a STT_GNU_IFUNC symbol in position dependent
  3547. // code, again so that function address comparisons work.
  3548. if (gsym->is_from_dynobj()
  3549. || gsym->is_undefined()
  3550. || gsym->is_preemptible()
  3551. || (gsym->visibility() == elfcpp::STV_PROTECTED
  3552. && parameters->options().shared())
  3553. || (gsym->type() == elfcpp::STT_GNU_IFUNC
  3554. && parameters->options().output_is_position_independent()))
  3555. got->add_global_with_rel(gsym, GOT_TYPE_STANDARD, rela_dyn,
  3556. elfcpp::R_TILEGX_GLOB_DAT);
  3557. else
  3558. {
  3559. // For a STT_GNU_IFUNC symbol we want to write the PLT
  3560. // offset into the GOT, so that function pointer
  3561. // comparisons work correctly.
  3562. bool is_new;
  3563. if (gsym->type() != elfcpp::STT_GNU_IFUNC)
  3564. is_new = got->add_global(gsym, GOT_TYPE_STANDARD);
  3565. else
  3566. {
  3567. is_new = got->add_global_plt(gsym, GOT_TYPE_STANDARD);
  3568. // Tell the dynamic linker to use the PLT address
  3569. // when resolving relocations.
  3570. if (gsym->is_from_dynobj()
  3571. && !parameters->options().shared())
  3572. gsym->set_needs_dynsym_value();
  3573. }
  3574. if (is_new)
  3575. {
  3576. unsigned int got_off = gsym->got_offset(GOT_TYPE_STANDARD);
  3577. rela_dyn->add_global_relative(gsym,
  3578. r_type,
  3579. got, got_off, 0, false);
  3580. }
  3581. }
  3582. }
  3583. }
  3584. break;
  3585. // a minor difference here for R_TILEGX_JUMPOFF_X1
  3586. // between bfd linker and gold linker for gold, when
  3587. // R_TILEGX_JUMPOFF_X1 against global symbol, we
  3588. // turn it into JUMPOFF_X1_PLT, otherwise the distance
  3589. // to the symbol function may overflow at runtime.
  3590. case elfcpp::R_TILEGX_JUMPOFF_X1:
  3591. case elfcpp::R_TILEGX_JUMPOFF_X1_PLT:
  3592. case elfcpp::R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
  3593. case elfcpp::R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
  3594. case elfcpp::R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
  3595. case elfcpp::R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
  3596. case elfcpp::R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
  3597. case elfcpp::R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
  3598. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
  3599. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
  3600. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
  3601. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
  3602. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
  3603. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
  3604. // If the symbol is fully resolved, this is just a PC32 reloc.
  3605. // Otherwise we need a PLT entry.
  3606. if (gsym->final_value_is_known())
  3607. break;
  3608. // If building a shared library, we can also skip the PLT entry
  3609. // if the symbol is defined in the output file and is protected
  3610. // or hidden.
  3611. if (gsym->is_defined()
  3612. && !gsym->is_from_dynobj()
  3613. && !gsym->is_preemptible())
  3614. break;
  3615. target->make_plt_entry(symtab, layout, gsym);
  3616. break;
  3617. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
  3618. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
  3619. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
  3620. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
  3621. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
  3622. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
  3623. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
  3624. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
  3625. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  3626. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  3627. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  3628. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  3629. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
  3630. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
  3631. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  3632. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  3633. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  3634. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  3635. case elfcpp::R_TILEGX_TLS_GD_CALL:
  3636. case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
  3637. case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
  3638. case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
  3639. case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
  3640. case elfcpp::R_TILEGX_TLS_IE_LOAD:
  3641. case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
  3642. case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
  3643. case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
  3644. case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
  3645. {
  3646. const bool is_final = gsym->final_value_is_known();
  3647. const tls::Tls_optimization opt_t =
  3648. Target_tilegx<size, big_endian>::optimize_tls_reloc(is_final,
  3649. r_type);
  3650. switch (r_type)
  3651. {
  3652. // only expand to plt against __tls_get_addr in GD model
  3653. case elfcpp::R_TILEGX_TLS_GD_CALL:
  3654. if (opt_t == tls::TLSOPT_NONE) {
  3655. // FIXME: it's better '__tls_get_addr' referenced explicitly
  3656. if (!target->tls_get_addr_sym_defined_) {
  3657. Symbol* sym = NULL;
  3658. options::parse_set(NULL, "__tls_get_addr",
  3659. (gold::options::String_set*)
  3660. &parameters->options().undefined());
  3661. symtab->add_undefined_symbols_from_command_line(layout);
  3662. target->tls_get_addr_sym_defined_ = true;
  3663. sym = symtab->lookup("__tls_get_addr");
  3664. sym->set_in_reg();
  3665. }
  3666. target->make_plt_entry(symtab, layout,
  3667. symtab->lookup("__tls_get_addr"));
  3668. }
  3669. break;
  3670. // only make effect when applying relocation
  3671. case elfcpp::R_TILEGX_TLS_IE_LOAD:
  3672. case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
  3673. case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
  3674. case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
  3675. case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
  3676. case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
  3677. case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
  3678. case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
  3679. case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
  3680. break;
  3681. // GD: requires two GOT entry for module index and offset
  3682. // IE: requires one GOT entry for tp-relative offset
  3683. // LE: shouldn't happen for global symbol
  3684. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
  3685. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
  3686. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  3687. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  3688. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  3689. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  3690. {
  3691. if (opt_t == tls::TLSOPT_NONE) {
  3692. Output_data_got<size, big_endian>* got
  3693. = target->got_section(symtab, layout);
  3694. got->add_global_pair_with_rel(gsym, GOT_TYPE_TLS_PAIR,
  3695. target->rela_dyn_section(layout),
  3696. size == 32
  3697. ? elfcpp::R_TILEGX_TLS_DTPMOD32
  3698. : elfcpp::R_TILEGX_TLS_DTPMOD64,
  3699. size == 32
  3700. ? elfcpp::R_TILEGX_TLS_DTPOFF32
  3701. : elfcpp::R_TILEGX_TLS_DTPOFF64);
  3702. } else if (opt_t == tls::TLSOPT_TO_IE) {
  3703. // Create a GOT entry for the tp-relative offset.
  3704. Output_data_got<size, big_endian>* got
  3705. = target->got_section(symtab, layout);
  3706. got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
  3707. target->rela_dyn_section(layout),
  3708. size == 32
  3709. ? elfcpp::R_TILEGX_TLS_TPOFF32
  3710. : elfcpp::R_TILEGX_TLS_TPOFF64);
  3711. } else if (opt_t != tls::TLSOPT_TO_LE)
  3712. // exteranl symbol should not be optimized to TO_LE
  3713. unsupported_reloc_global(object, r_type, gsym);
  3714. }
  3715. break;
  3716. // IE
  3717. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
  3718. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
  3719. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  3720. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  3721. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  3722. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  3723. {
  3724. layout->set_has_static_tls();
  3725. if (opt_t == tls::TLSOPT_NONE) {
  3726. // Create a GOT entry for the tp-relative offset.
  3727. Output_data_got<size, big_endian>* got
  3728. = target->got_section(symtab, layout);
  3729. got->add_global_with_rel(gsym, GOT_TYPE_TLS_OFFSET,
  3730. target->rela_dyn_section(layout),
  3731. size == 32
  3732. ? elfcpp::R_TILEGX_TLS_TPOFF32
  3733. : elfcpp::R_TILEGX_TLS_TPOFF64);
  3734. } else if (opt_t != tls::TLSOPT_TO_LE)
  3735. unsupported_reloc_global(object, r_type, gsym);
  3736. }
  3737. break;
  3738. // LE
  3739. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
  3740. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
  3741. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
  3742. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
  3743. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
  3744. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
  3745. layout->set_has_static_tls();
  3746. if (parameters->options().shared()) {
  3747. // defer to dynamic linker
  3748. Reloc_section* rela_dyn = target->rela_dyn_section(layout);
  3749. rela_dyn->add_symbolless_global_addend(gsym, r_type,
  3750. output_section, object,
  3751. data_shndx,
  3752. reloc.get_r_offset(), 0);
  3753. }
  3754. break;
  3755. default:
  3756. gold_unreachable();
  3757. }
  3758. }
  3759. break;
  3760. // below are outstanding relocs
  3761. // should not existed in static linking stage
  3762. case elfcpp::R_TILEGX_COPY:
  3763. case elfcpp::R_TILEGX_GLOB_DAT:
  3764. case elfcpp::R_TILEGX_JMP_SLOT:
  3765. case elfcpp::R_TILEGX_RELATIVE:
  3766. case elfcpp::R_TILEGX_TLS_TPOFF32:
  3767. case elfcpp::R_TILEGX_TLS_TPOFF64:
  3768. case elfcpp::R_TILEGX_TLS_DTPMOD32:
  3769. case elfcpp::R_TILEGX_TLS_DTPMOD64:
  3770. case elfcpp::R_TILEGX_TLS_DTPOFF32:
  3771. case elfcpp::R_TILEGX_TLS_DTPOFF64:
  3772. gold_error(_("%s: unexpected reloc %u in object file"),
  3773. object->name().c_str(), r_type);
  3774. break;
  3775. default:
  3776. gold_error(_("%s: unsupported reloc %u against global symbol %s"),
  3777. object->name().c_str(), r_type,
  3778. gsym->demangled_name().c_str());
  3779. break;
  3780. }
  3781. }
  3782. template<int size, bool big_endian>
  3783. void
  3784. Target_tilegx<size, big_endian>::gc_process_relocs(Symbol_table* symtab,
  3785. Layout* layout,
  3786. Sized_relobj_file<size, big_endian>* object,
  3787. unsigned int data_shndx,
  3788. unsigned int sh_type,
  3789. const unsigned char* prelocs,
  3790. size_t reloc_count,
  3791. Output_section* output_section,
  3792. bool needs_special_offset_handling,
  3793. size_t local_symbol_count,
  3794. const unsigned char* plocal_symbols)
  3795. {
  3796. typedef Target_tilegx<size, big_endian> Tilegx;
  3797. typedef typename Target_tilegx<size, big_endian>::Scan Scan;
  3798. typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
  3799. Classify_reloc;
  3800. if (sh_type == elfcpp::SHT_REL)
  3801. {
  3802. return;
  3803. }
  3804. gold::gc_process_relocs<size, big_endian, Tilegx, Scan, Classify_reloc>(
  3805. symtab,
  3806. layout,
  3807. this,
  3808. object,
  3809. data_shndx,
  3810. prelocs,
  3811. reloc_count,
  3812. output_section,
  3813. needs_special_offset_handling,
  3814. local_symbol_count,
  3815. plocal_symbols);
  3816. }
  3817. // Scan relocations for a section.
  3818. template<int size, bool big_endian>
  3819. void
  3820. Target_tilegx<size, big_endian>::scan_relocs(Symbol_table* symtab,
  3821. Layout* layout,
  3822. Sized_relobj_file<size, big_endian>* object,
  3823. unsigned int data_shndx,
  3824. unsigned int sh_type,
  3825. const unsigned char* prelocs,
  3826. size_t reloc_count,
  3827. Output_section* output_section,
  3828. bool needs_special_offset_handling,
  3829. size_t local_symbol_count,
  3830. const unsigned char* plocal_symbols)
  3831. {
  3832. typedef Target_tilegx<size, big_endian> Tilegx;
  3833. typedef typename Target_tilegx<size, big_endian>::Scan Scan;
  3834. typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
  3835. Classify_reloc;
  3836. if (sh_type == elfcpp::SHT_REL)
  3837. {
  3838. gold_error(_("%s: unsupported REL reloc section"),
  3839. object->name().c_str());
  3840. return;
  3841. }
  3842. gold::scan_relocs<size, big_endian, Tilegx, Scan, Classify_reloc>(
  3843. symtab,
  3844. layout,
  3845. this,
  3846. object,
  3847. data_shndx,
  3848. prelocs,
  3849. reloc_count,
  3850. output_section,
  3851. needs_special_offset_handling,
  3852. local_symbol_count,
  3853. plocal_symbols);
  3854. }
  3855. template<int size, bool big_endian>
  3856. void
  3857. Target_tilegx<size, big_endian>::do_define_standard_symbols(
  3858. Symbol_table* symtab,
  3859. Layout* layout)
  3860. {
  3861. Output_section* feedback_section = layout->find_output_section(".feedback");
  3862. if (feedback_section != NULL)
  3863. {
  3864. symtab->define_in_output_data("__feedback_section_end",
  3865. NULL,
  3866. Symbol_table::PREDEFINED,
  3867. feedback_section,
  3868. 0,
  3869. 0,
  3870. elfcpp::STT_NOTYPE,
  3871. elfcpp::STB_GLOBAL,
  3872. elfcpp::STV_HIDDEN,
  3873. 0,
  3874. true, // offset_is_from_end
  3875. false);
  3876. }
  3877. }
  3878. // Finalize the sections.
  3879. template<int size, bool big_endian>
  3880. void
  3881. Target_tilegx<size, big_endian>::do_finalize_sections(
  3882. Layout* layout,
  3883. const Input_objects*,
  3884. Symbol_table* symtab)
  3885. {
  3886. const Reloc_section* rel_plt = (this->plt_ == NULL
  3887. ? NULL
  3888. : this->plt_->rela_plt());
  3889. layout->add_target_dynamic_tags(false, this->got_plt_, rel_plt,
  3890. this->rela_dyn_, true, true);
  3891. // Emit any relocs we saved in an attempt to avoid generating COPY
  3892. // relocs.
  3893. if (this->copy_relocs_.any_saved_relocs())
  3894. this->copy_relocs_.emit(this->rela_dyn_section(layout));
  3895. // Set the size of the _GLOBAL_OFFSET_TABLE_ symbol to the size of
  3896. // the .got section.
  3897. Symbol* sym = this->global_offset_table_;
  3898. if (sym != NULL)
  3899. {
  3900. uint64_t data_size = this->got_->current_data_size();
  3901. symtab->get_sized_symbol<size>(sym)->set_symsize(data_size);
  3902. // If the .got section is more than 0x8000 bytes, we add
  3903. // 0x8000 to the value of _GLOBAL_OFFSET_TABLE_, so that 16
  3904. // bit relocations have a greater chance of working.
  3905. if (data_size >= 0x8000)
  3906. symtab->get_sized_symbol<size>(sym)->set_value(
  3907. symtab->get_sized_symbol<size>(sym)->value() + 0x8000);
  3908. }
  3909. if (parameters->doing_static_link()
  3910. && (this->plt_ == NULL || !this->plt_->has_irelative_section()))
  3911. {
  3912. // If linking statically, make sure that the __rela_iplt symbols
  3913. // were defined if necessary, even if we didn't create a PLT.
  3914. static const Define_symbol_in_segment syms[] =
  3915. {
  3916. {
  3917. "__rela_iplt_start", // name
  3918. elfcpp::PT_LOAD, // segment_type
  3919. elfcpp::PF_W, // segment_flags_set
  3920. elfcpp::PF(0), // segment_flags_clear
  3921. 0, // value
  3922. 0, // size
  3923. elfcpp::STT_NOTYPE, // type
  3924. elfcpp::STB_GLOBAL, // binding
  3925. elfcpp::STV_HIDDEN, // visibility
  3926. 0, // nonvis
  3927. Symbol::SEGMENT_START, // offset_from_base
  3928. true // only_if_ref
  3929. },
  3930. {
  3931. "__rela_iplt_end", // name
  3932. elfcpp::PT_LOAD, // segment_type
  3933. elfcpp::PF_W, // segment_flags_set
  3934. elfcpp::PF(0), // segment_flags_clear
  3935. 0, // value
  3936. 0, // size
  3937. elfcpp::STT_NOTYPE, // type
  3938. elfcpp::STB_GLOBAL, // binding
  3939. elfcpp::STV_HIDDEN, // visibility
  3940. 0, // nonvis
  3941. Symbol::SEGMENT_START, // offset_from_base
  3942. true // only_if_ref
  3943. }
  3944. };
  3945. symtab->define_symbols(layout, 2, syms,
  3946. layout->script_options()->saw_sections_clause());
  3947. }
  3948. }
  3949. // Perform a relocation.
  3950. template<int size, bool big_endian>
  3951. inline bool
  3952. Target_tilegx<size, big_endian>::Relocate::relocate(
  3953. const Relocate_info<size, big_endian>* relinfo,
  3954. unsigned int,
  3955. Target_tilegx<size, big_endian>* target,
  3956. Output_section*,
  3957. size_t relnum,
  3958. const unsigned char* preloc,
  3959. const Sized_symbol<size>* gsym,
  3960. const Symbol_value<size>* psymval,
  3961. unsigned char* view,
  3962. typename elfcpp::Elf_types<size>::Elf_Addr address,
  3963. section_size_type)
  3964. {
  3965. if (view == NULL)
  3966. return true;
  3967. typedef Tilegx_relocate_functions<size, big_endian> TilegxReloc;
  3968. typename TilegxReloc::Tilegx_howto r_howto;
  3969. const elfcpp::Rela<size, big_endian> rela(preloc);
  3970. unsigned int r_type = elfcpp::elf_r_type<size>(rela.get_r_info());
  3971. const Sized_relobj_file<size, big_endian>* object = relinfo->object;
  3972. // Pick the value to use for symbols defined in the PLT.
  3973. Symbol_value<size> symval;
  3974. if (gsym != NULL
  3975. && gsym->use_plt_offset(Scan::get_reference_flags(r_type)))
  3976. {
  3977. symval.set_output_value(target->plt_address_for_global(gsym));
  3978. psymval = &symval;
  3979. }
  3980. else if (gsym == NULL && psymval->is_ifunc_symbol())
  3981. {
  3982. unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
  3983. if (object->local_has_plt_offset(r_sym))
  3984. {
  3985. symval.set_output_value(target->plt_address_for_local(object, r_sym));
  3986. psymval = &symval;
  3987. }
  3988. }
  3989. elfcpp::Elf_Xword addend = rela.get_r_addend();
  3990. // Get the GOT offset if needed.
  3991. // For tilegx, the GOT pointer points to the start of the GOT section.
  3992. bool have_got_offset = false;
  3993. int got_offset = 0;
  3994. int got_base = target->got_ != NULL
  3995. ? target->got_->current_data_size() >= 0x8000 ? 0x8000 : 0
  3996. : 0;
  3997. unsigned int got_type = GOT_TYPE_STANDARD;
  3998. bool always_apply_relocation = false;
  3999. switch (r_type)
  4000. {
  4001. case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
  4002. case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
  4003. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
  4004. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
  4005. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
  4006. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
  4007. if (gsym != NULL)
  4008. {
  4009. gold_assert(gsym->has_got_offset(got_type));
  4010. got_offset = gsym->got_offset(got_type) - got_base;
  4011. }
  4012. else
  4013. {
  4014. unsigned int r_sym = elfcpp::elf_r_sym<size>(rela.get_r_info());
  4015. gold_assert(object->local_has_got_offset(r_sym, got_type));
  4016. got_offset =
  4017. object->local_got_offset(r_sym, got_type) - got_base;
  4018. }
  4019. have_got_offset = true;
  4020. break;
  4021. default:
  4022. break;
  4023. }
  4024. r_howto = TilegxReloc::howto[r_type];
  4025. switch (r_type)
  4026. {
  4027. case elfcpp::R_TILEGX_NONE:
  4028. case elfcpp::R_TILEGX_GNU_VTINHERIT:
  4029. case elfcpp::R_TILEGX_GNU_VTENTRY:
  4030. break;
  4031. case elfcpp::R_TILEGX_IMM16_X0_HW0_GOT:
  4032. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_GOT:
  4033. case elfcpp::R_TILEGX_IMM16_X1_HW0_GOT:
  4034. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_GOT:
  4035. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_GOT:
  4036. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_GOT:
  4037. gold_assert(have_got_offset);
  4038. symval.set_output_value(got_offset);
  4039. psymval = &symval;
  4040. always_apply_relocation = true;
  4041. addend = 0;
  4042. // Fall through.
  4043. // when under PIC mode, these relocations are deferred to rtld
  4044. case elfcpp::R_TILEGX_IMM16_X0_HW0:
  4045. case elfcpp::R_TILEGX_IMM16_X1_HW0:
  4046. case elfcpp::R_TILEGX_IMM16_X0_HW1:
  4047. case elfcpp::R_TILEGX_IMM16_X1_HW1:
  4048. case elfcpp::R_TILEGX_IMM16_X0_HW2:
  4049. case elfcpp::R_TILEGX_IMM16_X1_HW2:
  4050. case elfcpp::R_TILEGX_IMM16_X0_HW3:
  4051. case elfcpp::R_TILEGX_IMM16_X1_HW3:
  4052. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST:
  4053. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST:
  4054. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST:
  4055. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST:
  4056. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST:
  4057. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST:
  4058. if (always_apply_relocation
  4059. || !parameters->options().output_is_position_independent())
  4060. TilegxReloc::imm_x_general(view, object, psymval, addend, r_howto);
  4061. break;
  4062. case elfcpp::R_TILEGX_JUMPOFF_X1:
  4063. case elfcpp::R_TILEGX_JUMPOFF_X1_PLT:
  4064. gold_assert(gsym == NULL
  4065. || gsym->has_plt_offset()
  4066. || gsym->final_value_is_known()
  4067. || (gsym->is_defined()
  4068. && !gsym->is_from_dynobj()
  4069. && !gsym->is_preemptible()));
  4070. TilegxReloc::imm_x_pcrel_general(view, object, psymval, addend,
  4071. address, r_howto);
  4072. break;
  4073. case elfcpp::R_TILEGX_IMM16_X0_HW0_PLT_PCREL:
  4074. case elfcpp::R_TILEGX_IMM16_X0_HW0_PCREL:
  4075. case elfcpp::R_TILEGX_IMM16_X1_HW0_PLT_PCREL:
  4076. case elfcpp::R_TILEGX_IMM16_X1_HW0_PCREL:
  4077. case elfcpp::R_TILEGX_IMM16_X0_HW1_PLT_PCREL:
  4078. case elfcpp::R_TILEGX_IMM16_X0_HW1_PCREL:
  4079. case elfcpp::R_TILEGX_IMM16_X1_HW1_PLT_PCREL:
  4080. case elfcpp::R_TILEGX_IMM16_X1_HW1_PCREL:
  4081. case elfcpp::R_TILEGX_IMM16_X0_HW2_PLT_PCREL:
  4082. case elfcpp::R_TILEGX_IMM16_X0_HW2_PCREL:
  4083. case elfcpp::R_TILEGX_IMM16_X1_HW2_PLT_PCREL:
  4084. case elfcpp::R_TILEGX_IMM16_X1_HW2_PCREL:
  4085. case elfcpp::R_TILEGX_IMM16_X0_HW3_PCREL:
  4086. case elfcpp::R_TILEGX_IMM16_X1_HW3_PCREL:
  4087. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL:
  4088. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_PCREL:
  4089. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL:
  4090. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_PCREL:
  4091. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL:
  4092. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_PCREL:
  4093. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL:
  4094. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_PCREL:
  4095. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL:
  4096. case elfcpp::R_TILEGX_IMM16_X0_HW2_LAST_PCREL:
  4097. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL:
  4098. case elfcpp::R_TILEGX_IMM16_X1_HW2_LAST_PCREL:
  4099. TilegxReloc::imm_x_pcrel_general(view, object, psymval, addend,
  4100. address, r_howto);
  4101. break;
  4102. case elfcpp::R_TILEGX_BROFF_X1:
  4103. case elfcpp::R_TILEGX_DEST_IMM8_X1:
  4104. TilegxReloc::imm_x_two_part_general(view, object, psymval,
  4105. addend, address, r_type);
  4106. break;
  4107. // below are general relocation types, which can be
  4108. // handled by target-independent handlers
  4109. case elfcpp::R_TILEGX_64:
  4110. TilegxReloc::abs64(view, object, psymval, addend);
  4111. break;
  4112. case elfcpp::R_TILEGX_64_PCREL:
  4113. TilegxReloc::pc_abs64(view, object, psymval, addend, address);
  4114. break;
  4115. case elfcpp::R_TILEGX_32:
  4116. TilegxReloc::abs32(view, object, psymval, addend);
  4117. break;
  4118. case elfcpp::R_TILEGX_32_PCREL:
  4119. TilegxReloc::pc_abs32(view, object, psymval, addend, address);
  4120. break;
  4121. case elfcpp::R_TILEGX_16:
  4122. TilegxReloc::abs16(view, object, psymval, addend);
  4123. break;
  4124. case elfcpp::R_TILEGX_16_PCREL:
  4125. TilegxReloc::pc_abs16(view, object, psymval, addend, address);
  4126. break;
  4127. case elfcpp::R_TILEGX_8:
  4128. Relocate_functions<size, big_endian>::rela8(view, object,
  4129. psymval, addend);
  4130. break;
  4131. case elfcpp::R_TILEGX_8_PCREL:
  4132. Relocate_functions<size, big_endian>::pcrela8(view, object,
  4133. psymval, addend, address);
  4134. break;
  4135. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
  4136. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
  4137. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
  4138. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
  4139. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
  4140. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
  4141. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
  4142. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
  4143. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  4144. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  4145. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  4146. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  4147. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
  4148. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
  4149. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  4150. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  4151. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  4152. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  4153. case elfcpp::R_TILEGX_TLS_GD_CALL:
  4154. case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
  4155. case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
  4156. case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
  4157. case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
  4158. case elfcpp::R_TILEGX_TLS_IE_LOAD:
  4159. case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
  4160. case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
  4161. case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
  4162. case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
  4163. {
  4164. const bool is_final = (gsym == NULL
  4165. ? !parameters->options().shared()
  4166. : gsym->final_value_is_known());
  4167. tls::Tls_optimization opt_t =
  4168. Target_tilegx<size, big_endian>::optimize_tls_reloc(is_final,
  4169. r_type);
  4170. switch (r_type)
  4171. {
  4172. case elfcpp::R_TILEGX_TLS_GD_CALL:
  4173. {
  4174. if (opt_t == tls::TLSOPT_NONE) {
  4175. Symbol *tls_sym = relinfo->symtab->lookup("__tls_get_addr");
  4176. symval.set_output_value(
  4177. target->plt_address_for_global(tls_sym));
  4178. psymval = &symval;
  4179. TilegxReloc::imm_x_pcrel_general(view, object, psymval,
  4180. addend, address, r_howto);
  4181. }
  4182. else if (opt_t == tls::TLSOPT_TO_IE
  4183. || opt_t == tls::TLSOPT_TO_LE)
  4184. TilegxReloc::tls_relax(view, r_type, opt_t);
  4185. }
  4186. break;
  4187. // XX_TLS_GD is the same as normal X_GOT relocation
  4188. // except allocating a got entry pair,
  4189. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_GD:
  4190. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_GD:
  4191. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD:
  4192. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD:
  4193. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD:
  4194. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD:
  4195. if (opt_t == tls::TLSOPT_NONE) {
  4196. got_type = GOT_TYPE_TLS_PAIR;
  4197. have_got_offset = true;
  4198. } else if (opt_t == tls::TLSOPT_TO_IE) {
  4199. got_type = GOT_TYPE_TLS_OFFSET;
  4200. have_got_offset = true;
  4201. }
  4202. goto do_update_value;
  4203. // XX_TLS_IE is the same as normal X_GOT relocation
  4204. // except allocating one additional runtime relocation
  4205. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_IE:
  4206. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_IE:
  4207. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE:
  4208. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE:
  4209. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE:
  4210. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE:
  4211. if (opt_t == tls::TLSOPT_NONE) {
  4212. got_type = GOT_TYPE_TLS_OFFSET;
  4213. have_got_offset = true;
  4214. }
  4215. // Fall through.
  4216. do_update_value:
  4217. if (have_got_offset) {
  4218. if (gsym != NULL) {
  4219. gold_assert(gsym->has_got_offset(got_type));
  4220. got_offset = gsym->got_offset(got_type) - got_base;
  4221. } else {
  4222. unsigned int r_sym
  4223. = elfcpp::elf_r_sym<size>(rela.get_r_info());
  4224. gold_assert(object->local_has_got_offset(r_sym, got_type));
  4225. got_offset =
  4226. object->local_got_offset(r_sym, got_type) - got_base;
  4227. }
  4228. }
  4229. if (opt_t == tls::TLSOPT_NONE
  4230. || opt_t == tls::TLSOPT_TO_IE) {
  4231. // for both GD/IE, these relocations
  4232. // actually calculate got offset, so
  4233. // there behavior are the same
  4234. gold_assert(have_got_offset);
  4235. symval.set_output_value(got_offset);
  4236. psymval = &symval;
  4237. addend = 0;
  4238. TilegxReloc::imm_x_general(view, object, psymval,
  4239. addend, r_howto);
  4240. break;
  4241. } // else if (opt_t == tls::TLSOPT_TO_LE)
  4242. // both GD/IE are turned into LE, which
  4243. // is absolute relocation.
  4244. // Fall through.
  4245. // LE
  4246. //
  4247. // tp
  4248. // |
  4249. // V
  4250. // t_var1 | t_var2 | t_var3 | ...
  4251. // --------------------------------------------------
  4252. //
  4253. // so offset to tp should be negative, we get offset
  4254. // from the following formular for LE
  4255. //
  4256. // t_var1_off = t_var1_sym_value - tls_section_start
  4257. //
  4258. case elfcpp::R_TILEGX_IMM16_X0_HW0_TLS_LE:
  4259. case elfcpp::R_TILEGX_IMM16_X1_HW0_TLS_LE:
  4260. case elfcpp::R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE:
  4261. case elfcpp::R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE:
  4262. case elfcpp::R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE:
  4263. case elfcpp::R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE:
  4264. {
  4265. Output_segment *tls_segment = relinfo->layout->tls_segment();
  4266. if (tls_segment == NULL) {
  4267. gold_assert(parameters->errors()->error_count() > 0
  4268. || issue_undefined_symbol_error(gsym));
  4269. return false;
  4270. }
  4271. typename elfcpp::Elf_types<size>::Elf_Addr value
  4272. = psymval->value(relinfo->object, 0);
  4273. symval.set_output_value(value);
  4274. psymval = &symval;
  4275. TilegxReloc::imm_x_general(view, object, psymval,
  4276. addend, r_howto);
  4277. }
  4278. break;
  4279. // tls relaxation
  4280. case elfcpp::R_TILEGX_TLS_IE_LOAD:
  4281. case elfcpp::R_TILEGX_IMM8_X0_TLS_ADD:
  4282. case elfcpp::R_TILEGX_IMM8_X1_TLS_ADD:
  4283. case elfcpp::R_TILEGX_IMM8_Y0_TLS_ADD:
  4284. case elfcpp::R_TILEGX_IMM8_Y1_TLS_ADD:
  4285. case elfcpp::R_TILEGX_IMM8_X0_TLS_GD_ADD:
  4286. case elfcpp::R_TILEGX_IMM8_X1_TLS_GD_ADD:
  4287. case elfcpp::R_TILEGX_IMM8_Y0_TLS_GD_ADD:
  4288. case elfcpp::R_TILEGX_IMM8_Y1_TLS_GD_ADD:
  4289. TilegxReloc::tls_relax(view, r_type, opt_t);
  4290. break;
  4291. default:
  4292. gold_unreachable();
  4293. }
  4294. }
  4295. break;
  4296. // below are outstanding relocs
  4297. // should not existed in static linking stage
  4298. case elfcpp::R_TILEGX_COPY:
  4299. case elfcpp::R_TILEGX_GLOB_DAT:
  4300. case elfcpp::R_TILEGX_JMP_SLOT:
  4301. case elfcpp::R_TILEGX_RELATIVE:
  4302. case elfcpp::R_TILEGX_TLS_TPOFF32:
  4303. case elfcpp::R_TILEGX_TLS_TPOFF64:
  4304. case elfcpp::R_TILEGX_TLS_DTPMOD32:
  4305. case elfcpp::R_TILEGX_TLS_DTPMOD64:
  4306. case elfcpp::R_TILEGX_TLS_DTPOFF32:
  4307. case elfcpp::R_TILEGX_TLS_DTPOFF64:
  4308. gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
  4309. _("unexpected reloc %u in object file"),
  4310. r_type);
  4311. break;
  4312. default:
  4313. gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
  4314. _("unsupported reloc %u"),
  4315. r_type);
  4316. break;
  4317. }
  4318. return true;
  4319. }
  4320. // Relocate section data.
  4321. template<int size, bool big_endian>
  4322. void
  4323. Target_tilegx<size, big_endian>::relocate_section(
  4324. const Relocate_info<size, big_endian>* relinfo,
  4325. unsigned int sh_type,
  4326. const unsigned char* prelocs,
  4327. size_t reloc_count,
  4328. Output_section* output_section,
  4329. bool needs_special_offset_handling,
  4330. unsigned char* view,
  4331. typename elfcpp::Elf_types<size>::Elf_Addr address,
  4332. section_size_type view_size,
  4333. const Reloc_symbol_changes* reloc_symbol_changes)
  4334. {
  4335. typedef Target_tilegx<size, big_endian> Tilegx;
  4336. typedef typename Target_tilegx<size, big_endian>::Relocate Tilegx_relocate;
  4337. typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
  4338. Classify_reloc;
  4339. gold_assert(sh_type == elfcpp::SHT_RELA);
  4340. gold::relocate_section<size, big_endian, Tilegx, Tilegx_relocate,
  4341. gold::Default_comdat_behavior, Classify_reloc>(
  4342. relinfo,
  4343. this,
  4344. prelocs,
  4345. reloc_count,
  4346. output_section,
  4347. needs_special_offset_handling,
  4348. view,
  4349. address,
  4350. view_size,
  4351. reloc_symbol_changes);
  4352. }
  4353. // Apply an incremental relocation. Incremental relocations always refer
  4354. // to global symbols.
  4355. template<int size, bool big_endian>
  4356. void
  4357. Target_tilegx<size, big_endian>::apply_relocation(
  4358. const Relocate_info<size, big_endian>* relinfo,
  4359. typename elfcpp::Elf_types<size>::Elf_Addr r_offset,
  4360. unsigned int r_type,
  4361. typename elfcpp::Elf_types<size>::Elf_Swxword r_addend,
  4362. const Symbol* gsym,
  4363. unsigned char* view,
  4364. typename elfcpp::Elf_types<size>::Elf_Addr address,
  4365. section_size_type view_size)
  4366. {
  4367. gold::apply_relocation<size, big_endian, Target_tilegx<size, big_endian>,
  4368. typename Target_tilegx<size, big_endian>::Relocate>(
  4369. relinfo,
  4370. this,
  4371. r_offset,
  4372. r_type,
  4373. r_addend,
  4374. gsym,
  4375. view,
  4376. address,
  4377. view_size);
  4378. }
  4379. // Scan the relocs during a relocatable link.
  4380. template<int size, bool big_endian>
  4381. void
  4382. Target_tilegx<size, big_endian>::scan_relocatable_relocs(
  4383. Symbol_table* symtab,
  4384. Layout* layout,
  4385. Sized_relobj_file<size, big_endian>* object,
  4386. unsigned int data_shndx,
  4387. unsigned int sh_type,
  4388. const unsigned char* prelocs,
  4389. size_t reloc_count,
  4390. Output_section* output_section,
  4391. bool needs_special_offset_handling,
  4392. size_t local_symbol_count,
  4393. const unsigned char* plocal_symbols,
  4394. Relocatable_relocs* rr)
  4395. {
  4396. typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
  4397. Classify_reloc;
  4398. typedef gold::Default_scan_relocatable_relocs<Classify_reloc>
  4399. Scan_relocatable_relocs;
  4400. gold_assert(sh_type == elfcpp::SHT_RELA);
  4401. gold::scan_relocatable_relocs<size, big_endian, Scan_relocatable_relocs>(
  4402. symtab,
  4403. layout,
  4404. object,
  4405. data_shndx,
  4406. prelocs,
  4407. reloc_count,
  4408. output_section,
  4409. needs_special_offset_handling,
  4410. local_symbol_count,
  4411. plocal_symbols,
  4412. rr);
  4413. }
  4414. // Scan the relocs for --emit-relocs.
  4415. template<int size, bool big_endian>
  4416. void
  4417. Target_tilegx<size, big_endian>::emit_relocs_scan(
  4418. Symbol_table* symtab,
  4419. Layout* layout,
  4420. Sized_relobj_file<size, big_endian>* object,
  4421. unsigned int data_shndx,
  4422. unsigned int sh_type,
  4423. const unsigned char* prelocs,
  4424. size_t reloc_count,
  4425. Output_section* output_section,
  4426. bool needs_special_offset_handling,
  4427. size_t local_symbol_count,
  4428. const unsigned char* plocal_syms,
  4429. Relocatable_relocs* rr)
  4430. {
  4431. typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
  4432. Classify_reloc;
  4433. typedef gold::Default_emit_relocs_strategy<Classify_reloc>
  4434. Emit_relocs_strategy;
  4435. gold_assert(sh_type == elfcpp::SHT_RELA);
  4436. gold::scan_relocatable_relocs<size, big_endian, Emit_relocs_strategy>(
  4437. symtab,
  4438. layout,
  4439. object,
  4440. data_shndx,
  4441. prelocs,
  4442. reloc_count,
  4443. output_section,
  4444. needs_special_offset_handling,
  4445. local_symbol_count,
  4446. plocal_syms,
  4447. rr);
  4448. }
  4449. // Relocate a section during a relocatable link.
  4450. template<int size, bool big_endian>
  4451. void
  4452. Target_tilegx<size, big_endian>::relocate_relocs(
  4453. const Relocate_info<size, big_endian>* relinfo,
  4454. unsigned int sh_type,
  4455. const unsigned char* prelocs,
  4456. size_t reloc_count,
  4457. Output_section* output_section,
  4458. typename elfcpp::Elf_types<size>::Elf_Off offset_in_output_section,
  4459. unsigned char* view,
  4460. typename elfcpp::Elf_types<size>::Elf_Addr view_address,
  4461. section_size_type view_size,
  4462. unsigned char* reloc_view,
  4463. section_size_type reloc_view_size)
  4464. {
  4465. typedef gold::Default_classify_reloc<elfcpp::SHT_RELA, size, big_endian>
  4466. Classify_reloc;
  4467. gold_assert(sh_type == elfcpp::SHT_RELA);
  4468. gold::relocate_relocs<size, big_endian, Classify_reloc>(
  4469. relinfo,
  4470. prelocs,
  4471. reloc_count,
  4472. output_section,
  4473. offset_in_output_section,
  4474. view,
  4475. view_address,
  4476. view_size,
  4477. reloc_view,
  4478. reloc_view_size);
  4479. }
  4480. // Return the value to use for a dynamic which requires special
  4481. // treatment. This is how we support equality comparisons of function
  4482. // pointers across shared library boundaries, as described in the
  4483. // processor specific ABI supplement.
  4484. template<int size, bool big_endian>
  4485. uint64_t
  4486. Target_tilegx<size, big_endian>::do_dynsym_value(const Symbol* gsym) const
  4487. {
  4488. gold_assert(gsym->is_from_dynobj() && gsym->has_plt_offset());
  4489. return this->plt_address_for_global(gsym);
  4490. }
  4491. // Return the value to use for the base of a DW_EH_PE_datarel offset
  4492. // in an FDE. Solaris and SVR4 use DW_EH_PE_datarel because their
  4493. // assembler can not write out the difference between two labels in
  4494. // different sections, so instead of using a pc-relative value they
  4495. // use an offset from the GOT.
  4496. template<int size, bool big_endian>
  4497. uint64_t
  4498. Target_tilegx<size, big_endian>::do_ehframe_datarel_base() const
  4499. {
  4500. gold_assert(this->global_offset_table_ != NULL);
  4501. Symbol* sym = this->global_offset_table_;
  4502. Sized_symbol<size>* ssym = static_cast<Sized_symbol<size>*>(sym);
  4503. return ssym->value();
  4504. }
  4505. // The selector for tilegx object files.
  4506. template<int size, bool big_endian>
  4507. class Target_selector_tilegx : public Target_selector
  4508. {
  4509. public:
  4510. Target_selector_tilegx()
  4511. : Target_selector(elfcpp::EM_TILEGX, size, big_endian,
  4512. (size == 64
  4513. ? (big_endian ? "elf64-tilegx-be" : "elf64-tilegx-le")
  4514. : (big_endian ? "elf32-tilegx-be"
  4515. : "elf32-tilegx-le")),
  4516. (size == 64
  4517. ? (big_endian ? "elf64tilegx_be" : "elf64tilegx")
  4518. : (big_endian ? "elf32tilegx_be" : "elf32tilegx")))
  4519. { }
  4520. Target*
  4521. do_instantiate_target()
  4522. { return new Target_tilegx<size, big_endian>(); }
  4523. };
  4524. Target_selector_tilegx<64, false> target_selector_tilegx64_le;
  4525. Target_selector_tilegx<32, false> target_selector_tilegx32_le;
  4526. Target_selector_tilegx<64, true> target_selector_tilegx64_be;
  4527. Target_selector_tilegx<32, true> target_selector_tilegx32_be;
  4528. } // End anonymous namespace.