tilegx.cc 188 KB

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