elf32-frv.c 206 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867
  1. /* FRV-specific support for 32-bit ELF.
  2. Copyright (C) 2002-2022 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include "bfd.h"
  18. #include "libbfd.h"
  19. #include "elf-bfd.h"
  20. #include "elf/frv.h"
  21. #include "dwarf2.h"
  22. #include "hashtab.h"
  23. #include "libiberty.h"
  24. /* Forward declarations. */
  25. static reloc_howto_type elf32_frv_howto_table [] =
  26. {
  27. /* This reloc does nothing. */
  28. HOWTO (R_FRV_NONE, /* type */
  29. 0, /* rightshift */
  30. 3, /* size (0 = byte, 1 = short, 2 = long) */
  31. 0, /* bitsize */
  32. false, /* pc_relative */
  33. 0, /* bitpos */
  34. complain_overflow_dont, /* complain_on_overflow */
  35. bfd_elf_generic_reloc, /* special_function */
  36. "R_FRV_NONE", /* name */
  37. false, /* partial_inplace */
  38. 0, /* src_mask */
  39. 0, /* dst_mask */
  40. false), /* pcrel_offset */
  41. /* A 32 bit absolute relocation. */
  42. HOWTO (R_FRV_32, /* type */
  43. 0, /* rightshift */
  44. 2, /* size (0 = byte, 1 = short, 2 = long) */
  45. 32, /* bitsize */
  46. false, /* pc_relative */
  47. 0, /* bitpos */
  48. complain_overflow_bitfield, /* complain_on_overflow */
  49. bfd_elf_generic_reloc, /* special_function */
  50. "R_FRV_32", /* name */
  51. false, /* partial_inplace */
  52. 0xffffffff, /* src_mask */
  53. 0xffffffff, /* dst_mask */
  54. false), /* pcrel_offset */
  55. /* A 16 bit pc-relative relocation. */
  56. HOWTO (R_FRV_LABEL16, /* type */
  57. 2, /* rightshift */
  58. 2, /* size (0 = byte, 1 = short, 2 = long) */
  59. 16, /* bitsize */
  60. true, /* pc_relative */
  61. 0, /* bitpos */
  62. complain_overflow_signed, /* complain_on_overflow */
  63. bfd_elf_generic_reloc, /* special_function */
  64. "R_FRV_LABEL16", /* name */
  65. false, /* partial_inplace */
  66. 0xffff, /* src_mask */
  67. 0xffff, /* dst_mask */
  68. true), /* pcrel_offset */
  69. /* A 24-bit pc-relative relocation. */
  70. HOWTO (R_FRV_LABEL24, /* type */
  71. 2, /* rightshift */
  72. 2, /* size (0 = byte, 1 = short, 2 = long) */
  73. 26, /* bitsize */
  74. true, /* pc_relative */
  75. 0, /* bitpos */
  76. complain_overflow_bitfield, /* complain_on_overflow */
  77. bfd_elf_generic_reloc, /* special_function */
  78. "R_FRV_LABEL24", /* name */
  79. false, /* partial_inplace */
  80. 0x7e03ffff, /* src_mask */
  81. 0x7e03ffff, /* dst_mask */
  82. true), /* pcrel_offset */
  83. HOWTO (R_FRV_LO16, /* type */
  84. 0, /* rightshift */
  85. 2, /* size (0 = byte, 1 = short, 2 = long) */
  86. 16, /* bitsize */
  87. false, /* pc_relative */
  88. 0, /* bitpos */
  89. complain_overflow_dont, /* complain_on_overflow */
  90. bfd_elf_generic_reloc, /* special_function */
  91. "R_FRV_LO16", /* name */
  92. false, /* partial_inplace */
  93. 0xffff, /* src_mask */
  94. 0xffff, /* dst_mask */
  95. false), /* pcrel_offset */
  96. HOWTO (R_FRV_HI16, /* type */
  97. 0, /* rightshift */
  98. 2, /* size (0 = byte, 1 = short, 2 = long) */
  99. 16, /* bitsize */
  100. false, /* pc_relative */
  101. 0, /* bitpos */
  102. complain_overflow_dont, /* complain_on_overflow */
  103. bfd_elf_generic_reloc, /* special_function */
  104. "R_FRV_HI16", /* name */
  105. false, /* partial_inplace */
  106. 0xffff, /* src_mask */
  107. 0xffff, /* dst_mask */
  108. false), /* pcrel_offset */
  109. HOWTO (R_FRV_GPREL12, /* type */
  110. 0, /* rightshift */
  111. 2, /* size (0 = byte, 1 = short, 2 = long) */
  112. 12, /* bitsize */
  113. false, /* pc_relative */
  114. 0, /* bitpos */
  115. complain_overflow_dont, /* complain_on_overflow */
  116. bfd_elf_generic_reloc, /* special_function */
  117. "R_FRV_GPREL12", /* name */
  118. false, /* partial_inplace */
  119. 0xfff, /* src_mask */
  120. 0xfff, /* dst_mask */
  121. false), /* pcrel_offset */
  122. HOWTO (R_FRV_GPRELU12, /* type */
  123. 0, /* rightshift */
  124. 2, /* size (0 = byte, 1 = short, 2 = long) */
  125. 12, /* bitsize */
  126. false, /* pc_relative */
  127. 0, /* bitpos */
  128. complain_overflow_dont, /* complain_on_overflow */
  129. bfd_elf_generic_reloc, /* special_function */
  130. "R_FRV_GPRELU12", /* name */
  131. false, /* partial_inplace */
  132. 0xfff, /* src_mask */
  133. 0x3f03f, /* dst_mask */
  134. false), /* pcrel_offset */
  135. HOWTO (R_FRV_GPREL32, /* type */
  136. 0, /* rightshift */
  137. 2, /* size (0 = byte, 1 = short, 2 = long) */
  138. 32, /* bitsize */
  139. false, /* pc_relative */
  140. 0, /* bitpos */
  141. complain_overflow_dont, /* complain_on_overflow */
  142. bfd_elf_generic_reloc, /* special_function */
  143. "R_FRV_GPREL32", /* name */
  144. false, /* partial_inplace */
  145. 0xffffffff, /* src_mask */
  146. 0xffffffff, /* dst_mask */
  147. false), /* pcrel_offset */
  148. HOWTO (R_FRV_GPRELHI, /* type */
  149. 0, /* rightshift */
  150. 2, /* size (0 = byte, 1 = short, 2 = long) */
  151. 16, /* bitsize */
  152. false, /* pc_relative */
  153. 0, /* bitpos */
  154. complain_overflow_dont, /* complain_on_overflow */
  155. bfd_elf_generic_reloc, /* special_function */
  156. "R_FRV_GPRELHI", /* name */
  157. false, /* partial_inplace */
  158. 0xffff, /* src_mask */
  159. 0xffff, /* dst_mask */
  160. false), /* pcrel_offset */
  161. HOWTO (R_FRV_GPRELLO, /* type */
  162. 0, /* rightshift */
  163. 2, /* size (0 = byte, 1 = short, 2 = long) */
  164. 16, /* bitsize */
  165. false, /* pc_relative */
  166. 0, /* bitpos */
  167. complain_overflow_dont, /* complain_on_overflow */
  168. bfd_elf_generic_reloc, /* special_function */
  169. "R_FRV_GPRELLO", /* name */
  170. false, /* partial_inplace */
  171. 0xffff, /* src_mask */
  172. 0xffff, /* dst_mask */
  173. false), /* pcrel_offset */
  174. /* A 12-bit signed operand with the GOT offset for the address of
  175. the symbol. */
  176. HOWTO (R_FRV_GOT12, /* type */
  177. 0, /* rightshift */
  178. 2, /* size (0 = byte, 1 = short, 2 = long) */
  179. 12, /* bitsize */
  180. false, /* pc_relative */
  181. 0, /* bitpos */
  182. complain_overflow_signed, /* complain_on_overflow */
  183. bfd_elf_generic_reloc, /* special_function */
  184. "R_FRV_GOT12", /* name */
  185. false, /* partial_inplace */
  186. 0xfff, /* src_mask */
  187. 0xfff, /* dst_mask */
  188. false), /* pcrel_offset */
  189. /* The upper 16 bits of the GOT offset for the address of the
  190. symbol. */
  191. HOWTO (R_FRV_GOTHI, /* type */
  192. 0, /* rightshift */
  193. 2, /* size (0 = byte, 1 = short, 2 = long) */
  194. 16, /* bitsize */
  195. false, /* pc_relative */
  196. 0, /* bitpos */
  197. complain_overflow_dont, /* complain_on_overflow */
  198. bfd_elf_generic_reloc, /* special_function */
  199. "R_FRV_GOTHI", /* name */
  200. false, /* partial_inplace */
  201. 0xffff, /* src_mask */
  202. 0xffff, /* dst_mask */
  203. false), /* pcrel_offset */
  204. /* The lower 16 bits of the GOT offset for the address of the
  205. symbol. */
  206. HOWTO (R_FRV_GOTLO, /* type */
  207. 0, /* rightshift */
  208. 2, /* size (0 = byte, 1 = short, 2 = long) */
  209. 16, /* bitsize */
  210. false, /* pc_relative */
  211. 0, /* bitpos */
  212. complain_overflow_dont, /* complain_on_overflow */
  213. bfd_elf_generic_reloc, /* special_function */
  214. "R_FRV_GOTLO", /* name */
  215. false, /* partial_inplace */
  216. 0xffff, /* src_mask */
  217. 0xffff, /* dst_mask */
  218. false), /* pcrel_offset */
  219. /* The 32-bit address of the canonical descriptor of a function. */
  220. HOWTO (R_FRV_FUNCDESC, /* type */
  221. 0, /* rightshift */
  222. 2, /* size (0 = byte, 1 = short, 2 = long) */
  223. 32, /* bitsize */
  224. false, /* pc_relative */
  225. 0, /* bitpos */
  226. complain_overflow_bitfield, /* complain_on_overflow */
  227. bfd_elf_generic_reloc, /* special_function */
  228. "R_FRV_FUNCDESC", /* name */
  229. false, /* partial_inplace */
  230. 0xffffffff, /* src_mask */
  231. 0xffffffff, /* dst_mask */
  232. false), /* pcrel_offset */
  233. /* A 12-bit signed operand with the GOT offset for the address of
  234. canonical descriptor of a function. */
  235. HOWTO (R_FRV_FUNCDESC_GOT12, /* type */
  236. 0, /* rightshift */
  237. 2, /* size (0 = byte, 1 = short, 2 = long) */
  238. 12, /* bitsize */
  239. false, /* pc_relative */
  240. 0, /* bitpos */
  241. complain_overflow_signed, /* complain_on_overflow */
  242. bfd_elf_generic_reloc, /* special_function */
  243. "R_FRV_FUNCDESC_GOT12", /* name */
  244. false, /* partial_inplace */
  245. 0xfff, /* src_mask */
  246. 0xfff, /* dst_mask */
  247. false), /* pcrel_offset */
  248. /* The upper 16 bits of the GOT offset for the address of the
  249. canonical descriptor of a function. */
  250. HOWTO (R_FRV_FUNCDESC_GOTHI, /* type */
  251. 0, /* rightshift */
  252. 2, /* size (0 = byte, 1 = short, 2 = long) */
  253. 16, /* bitsize */
  254. false, /* pc_relative */
  255. 0, /* bitpos */
  256. complain_overflow_dont, /* complain_on_overflow */
  257. bfd_elf_generic_reloc, /* special_function */
  258. "R_FRV_FUNCDESC_GOTHI", /* name */
  259. false, /* partial_inplace */
  260. 0xffff, /* src_mask */
  261. 0xffff, /* dst_mask */
  262. false), /* pcrel_offset */
  263. /* The lower 16 bits of the GOT offset for the address of the
  264. canonical descriptor of a function. */
  265. HOWTO (R_FRV_FUNCDESC_GOTLO, /* type */
  266. 0, /* rightshift */
  267. 2, /* size (0 = byte, 1 = short, 2 = long) */
  268. 16, /* bitsize */
  269. false, /* pc_relative */
  270. 0, /* bitpos */
  271. complain_overflow_dont, /* complain_on_overflow */
  272. bfd_elf_generic_reloc, /* special_function */
  273. "R_FRV_FUNCDESC_GOTLO", /* name */
  274. false, /* partial_inplace */
  275. 0xffff, /* src_mask */
  276. 0xffff, /* dst_mask */
  277. false), /* pcrel_offset */
  278. /* The 64-bit descriptor of a function. */
  279. HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
  280. 0, /* rightshift */
  281. 2, /* size (0 = byte, 1 = short, 2 = long) */
  282. 64, /* bitsize */
  283. false, /* pc_relative */
  284. 0, /* bitpos */
  285. complain_overflow_bitfield, /* complain_on_overflow */
  286. bfd_elf_generic_reloc, /* special_function */
  287. "R_FRV_FUNCDESC_VALUE", /* name */
  288. false, /* partial_inplace */
  289. 0xffffffff, /* src_mask */
  290. 0xffffffff, /* dst_mask */
  291. false), /* pcrel_offset */
  292. /* A 12-bit signed operand with the GOT offset for the address of
  293. canonical descriptor of a function. */
  294. HOWTO (R_FRV_FUNCDESC_GOTOFF12, /* type */
  295. 0, /* rightshift */
  296. 2, /* size (0 = byte, 1 = short, 2 = long) */
  297. 12, /* bitsize */
  298. false, /* pc_relative */
  299. 0, /* bitpos */
  300. complain_overflow_signed, /* complain_on_overflow */
  301. bfd_elf_generic_reloc, /* special_function */
  302. "R_FRV_FUNCDESC_GOTOFF12", /* name */
  303. false, /* partial_inplace */
  304. 0xfff, /* src_mask */
  305. 0xfff, /* dst_mask */
  306. false), /* pcrel_offset */
  307. /* The upper 16 bits of the GOT offset for the address of the
  308. canonical descriptor of a function. */
  309. HOWTO (R_FRV_FUNCDESC_GOTOFFHI, /* type */
  310. 0, /* rightshift */
  311. 2, /* size (0 = byte, 1 = short, 2 = long) */
  312. 16, /* bitsize */
  313. false, /* pc_relative */
  314. 0, /* bitpos */
  315. complain_overflow_dont, /* complain_on_overflow */
  316. bfd_elf_generic_reloc, /* special_function */
  317. "R_FRV_FUNCDESC_GOTOFFHI", /* name */
  318. false, /* partial_inplace */
  319. 0xffff, /* src_mask */
  320. 0xffff, /* dst_mask */
  321. false), /* pcrel_offset */
  322. /* The lower 16 bits of the GOT offset for the address of the
  323. canonical descriptor of a function. */
  324. HOWTO (R_FRV_FUNCDESC_GOTOFFLO, /* type */
  325. 0, /* rightshift */
  326. 2, /* size (0 = byte, 1 = short, 2 = long) */
  327. 16, /* bitsize */
  328. false, /* pc_relative */
  329. 0, /* bitpos */
  330. complain_overflow_dont, /* complain_on_overflow */
  331. bfd_elf_generic_reloc, /* special_function */
  332. "R_FRV_FUNCDESC_GOTOFFLO", /* name */
  333. false, /* partial_inplace */
  334. 0xffff, /* src_mask */
  335. 0xffff, /* dst_mask */
  336. false), /* pcrel_offset */
  337. /* A 12-bit signed operand with the GOT offset for the address of
  338. the symbol. */
  339. HOWTO (R_FRV_GOTOFF12, /* type */
  340. 0, /* rightshift */
  341. 2, /* size (0 = byte, 1 = short, 2 = long) */
  342. 12, /* bitsize */
  343. false, /* pc_relative */
  344. 0, /* bitpos */
  345. complain_overflow_signed, /* complain_on_overflow */
  346. bfd_elf_generic_reloc, /* special_function */
  347. "R_FRV_GOTOFF12", /* name */
  348. false, /* partial_inplace */
  349. 0xfff, /* src_mask */
  350. 0xfff, /* dst_mask */
  351. false), /* pcrel_offset */
  352. /* The upper 16 bits of the GOT offset for the address of the
  353. symbol. */
  354. HOWTO (R_FRV_GOTOFFHI, /* type */
  355. 0, /* rightshift */
  356. 2, /* size (0 = byte, 1 = short, 2 = long) */
  357. 16, /* bitsize */
  358. false, /* pc_relative */
  359. 0, /* bitpos */
  360. complain_overflow_dont, /* complain_on_overflow */
  361. bfd_elf_generic_reloc, /* special_function */
  362. "R_FRV_GOTOFFHI", /* name */
  363. false, /* partial_inplace */
  364. 0xffff, /* src_mask */
  365. 0xffff, /* dst_mask */
  366. false), /* pcrel_offset */
  367. /* The lower 16 bits of the GOT offset for the address of the
  368. symbol. */
  369. HOWTO (R_FRV_GOTOFFLO, /* type */
  370. 0, /* rightshift */
  371. 2, /* size (0 = byte, 1 = short, 2 = long) */
  372. 16, /* bitsize */
  373. false, /* pc_relative */
  374. 0, /* bitpos */
  375. complain_overflow_dont, /* complain_on_overflow */
  376. bfd_elf_generic_reloc, /* special_function */
  377. "R_FRV_GOTOFFLO", /* name */
  378. false, /* partial_inplace */
  379. 0xffff, /* src_mask */
  380. 0xffff, /* dst_mask */
  381. false), /* pcrel_offset */
  382. /* A 24-bit pc-relative relocation referencing the TLS PLT entry for
  383. a thread-local symbol. If the symbol number is 0, it refers to
  384. the module. */
  385. HOWTO (R_FRV_GETTLSOFF, /* type */
  386. 2, /* rightshift */
  387. 2, /* size (0 = byte, 1 = short, 2 = long) */
  388. 26, /* bitsize */
  389. true, /* pc_relative */
  390. 0, /* bitpos */
  391. complain_overflow_bitfield, /* complain_on_overflow */
  392. bfd_elf_generic_reloc, /* special_function */
  393. "R_FRV_GETTLSOFF", /* name */
  394. false, /* partial_inplace */
  395. 0x7e03ffff, /* src_mask */
  396. 0x7e03ffff, /* dst_mask */
  397. true), /* pcrel_offset */
  398. /* A 64-bit TLS descriptor for a symbol. This relocation is only
  399. valid as a REL, dynamic relocation. */
  400. HOWTO (R_FRV_TLSDESC_VALUE, /* type */
  401. 0, /* rightshift */
  402. 2, /* size (0 = byte, 1 = short, 2 = long) */
  403. 64, /* bitsize */
  404. false, /* pc_relative */
  405. 0, /* bitpos */
  406. complain_overflow_bitfield, /* complain_on_overflow */
  407. bfd_elf_generic_reloc, /* special_function */
  408. "R_FRV_TLSDESC_VALUE", /* name */
  409. false, /* partial_inplace */
  410. 0xffffffff, /* src_mask */
  411. 0xffffffff, /* dst_mask */
  412. false), /* pcrel_offset */
  413. /* A 12-bit signed operand with the GOT offset for the TLS
  414. descriptor of the symbol. */
  415. HOWTO (R_FRV_GOTTLSDESC12, /* type */
  416. 0, /* rightshift */
  417. 2, /* size (0 = byte, 1 = short, 2 = long) */
  418. 12, /* bitsize */
  419. false, /* pc_relative */
  420. 0, /* bitpos */
  421. complain_overflow_signed, /* complain_on_overflow */
  422. bfd_elf_generic_reloc, /* special_function */
  423. "R_FRV_GOTTLSDESC12", /* name */
  424. false, /* partial_inplace */
  425. 0xfff, /* src_mask */
  426. 0xfff, /* dst_mask */
  427. false), /* pcrel_offset */
  428. /* The upper 16 bits of the GOT offset for the TLS descriptor of the
  429. symbol. */
  430. HOWTO (R_FRV_GOTTLSDESCHI, /* type */
  431. 0, /* rightshift */
  432. 2, /* size (0 = byte, 1 = short, 2 = long) */
  433. 16, /* bitsize */
  434. false, /* pc_relative */
  435. 0, /* bitpos */
  436. complain_overflow_dont, /* complain_on_overflow */
  437. bfd_elf_generic_reloc, /* special_function */
  438. "R_FRV_GOTTLSDESCHI", /* name */
  439. false, /* partial_inplace */
  440. 0xffff, /* src_mask */
  441. 0xffff, /* dst_mask */
  442. false), /* pcrel_offset */
  443. /* The lower 16 bits of the GOT offset for the TLS descriptor of the
  444. symbol. */
  445. HOWTO (R_FRV_GOTTLSDESCLO, /* type */
  446. 0, /* rightshift */
  447. 2, /* size (0 = byte, 1 = short, 2 = long) */
  448. 16, /* bitsize */
  449. false, /* pc_relative */
  450. 0, /* bitpos */
  451. complain_overflow_dont, /* complain_on_overflow */
  452. bfd_elf_generic_reloc, /* special_function */
  453. "R_FRV_GOTTLSDESCLO", /* name */
  454. false, /* partial_inplace */
  455. 0xffff, /* src_mask */
  456. 0xffff, /* dst_mask */
  457. false), /* pcrel_offset */
  458. /* A 12-bit signed operand with the offset from the module base
  459. address to the thread-local symbol address. */
  460. HOWTO (R_FRV_TLSMOFF12, /* type */
  461. 0, /* rightshift */
  462. 2, /* size (0 = byte, 1 = short, 2 = long) */
  463. 12, /* bitsize */
  464. false, /* pc_relative */
  465. 0, /* bitpos */
  466. complain_overflow_signed, /* complain_on_overflow */
  467. bfd_elf_generic_reloc, /* special_function */
  468. "R_FRV_TLSMOFF12", /* name */
  469. false, /* partial_inplace */
  470. 0xfff, /* src_mask */
  471. 0xfff, /* dst_mask */
  472. false), /* pcrel_offset */
  473. /* The upper 16 bits of the offset from the module base address to
  474. the thread-local symbol address. */
  475. HOWTO (R_FRV_TLSMOFFHI, /* type */
  476. 0, /* rightshift */
  477. 2, /* size (0 = byte, 1 = short, 2 = long) */
  478. 16, /* bitsize */
  479. false, /* pc_relative */
  480. 0, /* bitpos */
  481. complain_overflow_dont, /* complain_on_overflow */
  482. bfd_elf_generic_reloc, /* special_function */
  483. "R_FRV_TLSMOFFHI", /* name */
  484. false, /* partial_inplace */
  485. 0xffff, /* src_mask */
  486. 0xffff, /* dst_mask */
  487. false), /* pcrel_offset */
  488. /* The lower 16 bits of the offset from the module base address to
  489. the thread-local symbol address. */
  490. HOWTO (R_FRV_TLSMOFFLO, /* type */
  491. 0, /* rightshift */
  492. 2, /* size (0 = byte, 1 = short, 2 = long) */
  493. 16, /* bitsize */
  494. false, /* pc_relative */
  495. 0, /* bitpos */
  496. complain_overflow_dont, /* complain_on_overflow */
  497. bfd_elf_generic_reloc, /* special_function */
  498. "R_FRV_TLSMOFFLO", /* name */
  499. false, /* partial_inplace */
  500. 0xffff, /* src_mask */
  501. 0xffff, /* dst_mask */
  502. false), /* pcrel_offset */
  503. /* A 12-bit signed operand with the GOT offset for the TLSOFF entry
  504. for a symbol. */
  505. HOWTO (R_FRV_GOTTLSOFF12, /* type */
  506. 0, /* rightshift */
  507. 2, /* size (0 = byte, 1 = short, 2 = long) */
  508. 12, /* bitsize */
  509. false, /* pc_relative */
  510. 0, /* bitpos */
  511. complain_overflow_signed, /* complain_on_overflow */
  512. bfd_elf_generic_reloc, /* special_function */
  513. "R_FRV_GOTTLSOFF12", /* name */
  514. false, /* partial_inplace */
  515. 0xfff, /* src_mask */
  516. 0xfff, /* dst_mask */
  517. false), /* pcrel_offset */
  518. /* The upper 16 bits of the GOT offset for the TLSOFF entry for a
  519. symbol. */
  520. HOWTO (R_FRV_GOTTLSOFFHI, /* type */
  521. 0, /* rightshift */
  522. 2, /* size (0 = byte, 1 = short, 2 = long) */
  523. 16, /* bitsize */
  524. false, /* pc_relative */
  525. 0, /* bitpos */
  526. complain_overflow_dont, /* complain_on_overflow */
  527. bfd_elf_generic_reloc, /* special_function */
  528. "R_FRV_GOTTLSOFFHI", /* name */
  529. false, /* partial_inplace */
  530. 0xffff, /* src_mask */
  531. 0xffff, /* dst_mask */
  532. false), /* pcrel_offset */
  533. /* The lower 16 bits of the GOT offset for the TLSOFF entry for a
  534. symbol. */
  535. HOWTO (R_FRV_GOTTLSOFFLO, /* type */
  536. 0, /* rightshift */
  537. 2, /* size (0 = byte, 1 = short, 2 = long) */
  538. 16, /* bitsize */
  539. false, /* pc_relative */
  540. 0, /* bitpos */
  541. complain_overflow_dont, /* complain_on_overflow */
  542. bfd_elf_generic_reloc, /* special_function */
  543. "R_FRV_GOTTLSOFFLO", /* name */
  544. false, /* partial_inplace */
  545. 0xffff, /* src_mask */
  546. 0xffff, /* dst_mask */
  547. false), /* pcrel_offset */
  548. /* The 32-bit offset from the thread pointer (not the module base
  549. address) to a thread-local symbol. */
  550. HOWTO (R_FRV_TLSOFF, /* type */
  551. 0, /* rightshift */
  552. 2, /* size (0 = byte, 1 = short, 2 = long) */
  553. 32, /* bitsize */
  554. false, /* pc_relative */
  555. 0, /* bitpos */
  556. complain_overflow_dont, /* complain_on_overflow */
  557. bfd_elf_generic_reloc, /* special_function */
  558. "R_FRV_TLSOFF", /* name */
  559. false, /* partial_inplace */
  560. 0xffffffff, /* src_mask */
  561. 0xffffffff, /* dst_mask */
  562. false), /* pcrel_offset */
  563. /* An annotation for linker relaxation, that denotes the
  564. symbol+addend whose TLS descriptor is referenced by the sum of
  565. the two input registers of an ldd instruction. */
  566. HOWTO (R_FRV_TLSDESC_RELAX, /* type */
  567. 0, /* rightshift */
  568. 2, /* size (0 = byte, 1 = short, 2 = long) */
  569. 0, /* bitsize */
  570. false, /* pc_relative */
  571. 0, /* bitpos */
  572. complain_overflow_dont, /* complain_on_overflow */
  573. bfd_elf_generic_reloc, /* special_function */
  574. "R_FRV_TLSDESC_RELAX", /* name */
  575. false, /* partial_inplace */
  576. 0, /* src_mask */
  577. 0, /* dst_mask */
  578. false), /* pcrel_offset */
  579. /* An annotation for linker relaxation, that denotes the
  580. symbol+addend whose TLS resolver entry point is given by the sum
  581. of the two register operands of an calll instruction. */
  582. HOWTO (R_FRV_GETTLSOFF_RELAX, /* type */
  583. 0, /* rightshift */
  584. 2, /* size (0 = byte, 1 = short, 2 = long) */
  585. 0, /* bitsize */
  586. false, /* pc_relative */
  587. 0, /* bitpos */
  588. complain_overflow_dont, /* complain_on_overflow */
  589. bfd_elf_generic_reloc, /* special_function */
  590. "R_FRV_GETTLSOFF_RELAX", /* name */
  591. false, /* partial_inplace */
  592. 0, /* src_mask */
  593. 0, /* dst_mask */
  594. false), /* pcrel_offset */
  595. /* An annotation for linker relaxation, that denotes the
  596. symbol+addend whose TLS offset GOT entry is given by the sum of
  597. the two input registers of an ld instruction. */
  598. HOWTO (R_FRV_TLSOFF_RELAX, /* type */
  599. 0, /* rightshift */
  600. 2, /* size (0 = byte, 1 = short, 2 = long) */
  601. 0, /* bitsize */
  602. false, /* pc_relative */
  603. 0, /* bitpos */
  604. complain_overflow_bitfield, /* complain_on_overflow */
  605. bfd_elf_generic_reloc, /* special_function */
  606. "R_FRV_TLSOFF_RELAX", /* name */
  607. false, /* partial_inplace */
  608. 0, /* src_mask */
  609. 0, /* dst_mask */
  610. false), /* pcrel_offset */
  611. /* A 32-bit offset from the module base address to
  612. the thread-local symbol address. */
  613. HOWTO (R_FRV_TLSMOFF, /* type */
  614. 0, /* rightshift */
  615. 2, /* size (0 = byte, 1 = short, 2 = long) */
  616. 32, /* bitsize */
  617. false, /* pc_relative */
  618. 0, /* bitpos */
  619. complain_overflow_dont, /* complain_on_overflow */
  620. bfd_elf_generic_reloc, /* special_function */
  621. "R_FRV_TLSMOFF", /* name */
  622. false, /* partial_inplace */
  623. 0xffffffff, /* src_mask */
  624. 0xffffffff, /* dst_mask */
  625. false), /* pcrel_offset */
  626. };
  627. /* GNU extension to record C++ vtable hierarchy. */
  628. static reloc_howto_type elf32_frv_vtinherit_howto =
  629. HOWTO (R_FRV_GNU_VTINHERIT, /* type */
  630. 0, /* rightshift */
  631. 2, /* size (0 = byte, 1 = short, 2 = long) */
  632. 0, /* bitsize */
  633. false, /* pc_relative */
  634. 0, /* bitpos */
  635. complain_overflow_dont, /* complain_on_overflow */
  636. NULL, /* special_function */
  637. "R_FRV_GNU_VTINHERIT", /* name */
  638. false, /* partial_inplace */
  639. 0, /* src_mask */
  640. 0, /* dst_mask */
  641. false); /* pcrel_offset */
  642. /* GNU extension to record C++ vtable member usage. */
  643. static reloc_howto_type elf32_frv_vtentry_howto =
  644. HOWTO (R_FRV_GNU_VTENTRY, /* type */
  645. 0, /* rightshift */
  646. 2, /* size (0 = byte, 1 = short, 2 = long) */
  647. 0, /* bitsize */
  648. false, /* pc_relative */
  649. 0, /* bitpos */
  650. complain_overflow_dont, /* complain_on_overflow */
  651. _bfd_elf_rel_vtable_reloc_fn, /* special_function */
  652. "R_FRV_GNU_VTENTRY", /* name */
  653. false, /* partial_inplace */
  654. 0, /* src_mask */
  655. 0, /* dst_mask */
  656. false); /* pcrel_offset */
  657. /* The following 3 relocations are REL. The only difference to the
  658. entries in the table above are that partial_inplace is true. */
  659. static reloc_howto_type elf32_frv_rel_32_howto =
  660. HOWTO (R_FRV_32, /* type */
  661. 0, /* rightshift */
  662. 2, /* size (0 = byte, 1 = short, 2 = long) */
  663. 32, /* bitsize */
  664. false, /* pc_relative */
  665. 0, /* bitpos */
  666. complain_overflow_bitfield, /* complain_on_overflow */
  667. bfd_elf_generic_reloc, /* special_function */
  668. "R_FRV_32", /* name */
  669. true, /* partial_inplace */
  670. 0xffffffff, /* src_mask */
  671. 0xffffffff, /* dst_mask */
  672. false); /* pcrel_offset */
  673. static reloc_howto_type elf32_frv_rel_funcdesc_howto =
  674. HOWTO (R_FRV_FUNCDESC, /* type */
  675. 0, /* rightshift */
  676. 2, /* size (0 = byte, 1 = short, 2 = long) */
  677. 32, /* bitsize */
  678. false, /* pc_relative */
  679. 0, /* bitpos */
  680. complain_overflow_bitfield, /* complain_on_overflow */
  681. bfd_elf_generic_reloc, /* special_function */
  682. "R_FRV_FUNCDESC", /* name */
  683. true, /* partial_inplace */
  684. 0xffffffff, /* src_mask */
  685. 0xffffffff, /* dst_mask */
  686. false); /* pcrel_offset */
  687. static reloc_howto_type elf32_frv_rel_funcdesc_value_howto =
  688. HOWTO (R_FRV_FUNCDESC_VALUE, /* type */
  689. 0, /* rightshift */
  690. 2, /* size (0 = byte, 1 = short, 2 = long) */
  691. 64, /* bitsize */
  692. false, /* pc_relative */
  693. 0, /* bitpos */
  694. complain_overflow_bitfield, /* complain_on_overflow */
  695. bfd_elf_generic_reloc, /* special_function */
  696. "R_FRV_FUNCDESC_VALUE", /* name */
  697. true, /* partial_inplace */
  698. 0xffffffff, /* src_mask */
  699. 0xffffffff, /* dst_mask */
  700. false); /* pcrel_offset */
  701. static reloc_howto_type elf32_frv_rel_tlsdesc_value_howto =
  702. /* A 64-bit TLS descriptor for a symbol. The first word resolves to
  703. an entry point, and the second resolves to a special argument.
  704. If the symbol turns out to be in static TLS, the entry point is a
  705. return instruction, and the special argument is the TLS offset
  706. for the symbol. If it's in dynamic TLS, the entry point is a TLS
  707. offset resolver, and the special argument is a pointer to a data
  708. structure allocated by the dynamic loader, containing the GOT
  709. address for the offset resolver, the module id, the offset within
  710. the module, and anything else the TLS offset resolver might need
  711. to determine the TLS offset for the symbol in the running
  712. thread. */
  713. HOWTO (R_FRV_TLSDESC_VALUE, /* type */
  714. 0, /* rightshift */
  715. 2, /* size (0 = byte, 1 = short, 2 = long) */
  716. 64, /* bitsize */
  717. false, /* pc_relative */
  718. 0, /* bitpos */
  719. complain_overflow_bitfield, /* complain_on_overflow */
  720. bfd_elf_generic_reloc, /* special_function */
  721. "R_FRV_TLSDESC_VALUE", /* name */
  722. true, /* partial_inplace */
  723. 0xffffffff, /* src_mask */
  724. 0xffffffff, /* dst_mask */
  725. false); /* pcrel_offset */
  726. static reloc_howto_type elf32_frv_rel_tlsoff_howto =
  727. /* The 32-bit offset from the thread pointer (not the module base
  728. address) to a thread-local symbol. */
  729. HOWTO (R_FRV_TLSOFF, /* type */
  730. 0, /* rightshift */
  731. 2, /* size (0 = byte, 1 = short, 2 = long) */
  732. 32, /* bitsize */
  733. false, /* pc_relative */
  734. 0, /* bitpos */
  735. complain_overflow_bitfield, /* complain_on_overflow */
  736. bfd_elf_generic_reloc, /* special_function */
  737. "R_FRV_TLSOFF", /* name */
  738. true, /* partial_inplace */
  739. 0xffffffff, /* src_mask */
  740. 0xffffffff, /* dst_mask */
  741. false); /* pcrel_offset */
  742. extern const bfd_target frv_elf32_fdpic_vec;
  743. #define IS_FDPIC(bfd) ((bfd)->xvec == &frv_elf32_fdpic_vec)
  744. /* An extension of the elf hash table data structure, containing some
  745. additional FRV-specific data. */
  746. struct frvfdpic_elf_link_hash_table
  747. {
  748. struct elf_link_hash_table elf;
  749. /* A pointer to the .rofixup section. */
  750. asection *sgotfixup;
  751. /* GOT base offset. */
  752. bfd_vma got0;
  753. /* Location of the first non-lazy PLT entry, i.e., the number of
  754. bytes taken by lazy PLT entries. If locally-bound TLS
  755. descriptors require a ret instruction, it will be placed at this
  756. offset. */
  757. bfd_vma plt0;
  758. /* A hash table holding information about which symbols were
  759. referenced with which PIC-related relocations. */
  760. struct htab *relocs_info;
  761. /* Summary reloc information collected by
  762. _frvfdpic_count_got_plt_entries. */
  763. struct _frvfdpic_dynamic_got_info *g;
  764. };
  765. /* Get the FRV ELF linker hash table from a link_info structure. */
  766. #define frvfdpic_hash_table(p) \
  767. ((is_elf_hash_table ((p)->hash) \
  768. && elf_hash_table_id (elf_hash_table (p)) == FRV_ELF_DATA) \
  769. ? (struct frvfdpic_elf_link_hash_table *) (p)->hash : NULL)
  770. #define frvfdpic_got_section(info) \
  771. (frvfdpic_hash_table (info)->elf.sgot)
  772. #define frvfdpic_gotrel_section(info) \
  773. (frvfdpic_hash_table (info)->elf.srelgot)
  774. #define frvfdpic_gotfixup_section(info) \
  775. (frvfdpic_hash_table (info)->sgotfixup)
  776. #define frvfdpic_plt_section(info) \
  777. (frvfdpic_hash_table (info)->elf.splt)
  778. #define frvfdpic_pltrel_section(info) \
  779. (frvfdpic_hash_table (info)->elf.srelplt)
  780. #define frvfdpic_relocs_info(info) \
  781. (frvfdpic_hash_table (info)->relocs_info)
  782. #define frvfdpic_got_initial_offset(info) \
  783. (frvfdpic_hash_table (info)->got0)
  784. #define frvfdpic_plt_initial_offset(info) \
  785. (frvfdpic_hash_table (info)->plt0)
  786. #define frvfdpic_dynamic_got_plt_info(info) \
  787. (frvfdpic_hash_table (info)->g)
  788. /* Currently it's the same, but if some day we have a reason to change
  789. it, we'd better be using a different macro.
  790. FIXME: if there's any TLS PLT entry that uses local-exec or
  791. initial-exec models, we could use the ret at the end of any of them
  792. instead of adding one more. */
  793. #define frvfdpic_plt_tls_ret_offset(info) \
  794. (frvfdpic_plt_initial_offset (info))
  795. /* The name of the dynamic interpreter. This is put in the .interp
  796. section. */
  797. #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
  798. #define DEFAULT_STACK_SIZE 0x20000
  799. /* This structure is used to collect the number of entries present in
  800. each addressable range of the got. */
  801. struct _frvfdpic_dynamic_got_info
  802. {
  803. /* Several bits of information about the current link. */
  804. struct bfd_link_info *info;
  805. /* Total GOT size needed for GOT entries within the 12-, 16- or 32-bit
  806. ranges. */
  807. bfd_vma got12, gotlos, gothilo;
  808. /* Total GOT size needed for function descriptor entries within the 12-,
  809. 16- or 32-bit ranges. */
  810. bfd_vma fd12, fdlos, fdhilo;
  811. /* Total GOT size needed by function descriptor entries referenced
  812. in PLT entries, that would be profitable to place in offsets
  813. close to the PIC register. */
  814. bfd_vma fdplt;
  815. /* Total PLT size needed by lazy PLT entries. */
  816. bfd_vma lzplt;
  817. /* Total GOT size needed for TLS descriptor entries within the 12-,
  818. 16- or 32-bit ranges. */
  819. bfd_vma tlsd12, tlsdlos, tlsdhilo;
  820. /* Total GOT size needed by TLS descriptors referenced in PLT
  821. entries, that would be profitable to place in offers close to the
  822. PIC register. */
  823. bfd_vma tlsdplt;
  824. /* Total PLT size needed by TLS lazy PLT entries. */
  825. bfd_vma tlslzplt;
  826. /* Number of relocations carried over from input object files. */
  827. unsigned long relocs;
  828. /* Number of fixups introduced by relocations in input object files. */
  829. unsigned long fixups;
  830. /* The number of fixups that reference the ret instruction added to
  831. the PLT for locally-resolved TLS descriptors. */
  832. unsigned long tls_ret_refs;
  833. };
  834. /* This structure is used to assign offsets to got entries, function
  835. descriptors, plt entries and lazy plt entries. */
  836. struct _frvfdpic_dynamic_got_plt_info
  837. {
  838. /* Summary information collected with _frvfdpic_count_got_plt_entries. */
  839. struct _frvfdpic_dynamic_got_info g;
  840. /* For each addressable range, we record a MAX (positive) and MIN
  841. (negative) value. CUR is used to assign got entries, and it's
  842. incremented from an initial positive value to MAX, then from MIN
  843. to FDCUR (unless FDCUR wraps around first). FDCUR is used to
  844. assign function descriptors, and it's decreased from an initial
  845. non-positive value to MIN, then from MAX down to CUR (unless CUR
  846. wraps around first). All of MIN, MAX, CUR and FDCUR always point
  847. to even words. ODD, if non-zero, indicates an odd word to be
  848. used for the next got entry, otherwise CUR is used and
  849. incremented by a pair of words, wrapping around when it reaches
  850. MAX. FDCUR is decremented (and wrapped) before the next function
  851. descriptor is chosen. FDPLT indicates the number of remaining
  852. slots that can be used for function descriptors used only by PLT
  853. entries.
  854. TMAX, TMIN and TCUR are used to assign TLS descriptors. TCUR
  855. starts as MAX, and grows up to TMAX, then wraps around to TMIN
  856. and grows up to MIN. TLSDPLT indicates the number of remaining
  857. slots that can be used for TLS descriptors used only by TLS PLT
  858. entries. */
  859. struct _frvfdpic_dynamic_got_alloc_data
  860. {
  861. bfd_signed_vma max, cur, odd, fdcur, min;
  862. bfd_signed_vma tmax, tcur, tmin;
  863. bfd_vma fdplt, tlsdplt;
  864. } got12, gotlos, gothilo;
  865. };
  866. /* Create an FRV ELF linker hash table. */
  867. static struct bfd_link_hash_table *
  868. frvfdpic_elf_link_hash_table_create (bfd *abfd)
  869. {
  870. struct frvfdpic_elf_link_hash_table *ret;
  871. size_t amt = sizeof (struct frvfdpic_elf_link_hash_table);
  872. ret = bfd_zmalloc (amt);
  873. if (ret == NULL)
  874. return NULL;
  875. if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
  876. _bfd_elf_link_hash_newfunc,
  877. sizeof (struct elf_link_hash_entry),
  878. FRV_ELF_DATA))
  879. {
  880. free (ret);
  881. return NULL;
  882. }
  883. return &ret->elf.root;
  884. }
  885. /* Decide whether a reference to a symbol can be resolved locally or
  886. not. If the symbol is protected, we want the local address, but
  887. its function descriptor must be assigned by the dynamic linker. */
  888. #define FRVFDPIC_SYM_LOCAL(INFO, H) \
  889. (_bfd_elf_symbol_refs_local_p ((H), (INFO), 1) \
  890. || ! elf_hash_table (INFO)->dynamic_sections_created)
  891. #define FRVFDPIC_FUNCDESC_LOCAL(INFO, H) \
  892. ((H)->dynindx == -1 || ! elf_hash_table (INFO)->dynamic_sections_created)
  893. /* This structure collects information on what kind of GOT, PLT or
  894. function descriptors are required by relocations that reference a
  895. certain symbol. */
  896. struct frvfdpic_relocs_info
  897. {
  898. /* The index of the symbol, as stored in the relocation r_info, if
  899. we have a local symbol; -1 otherwise. */
  900. long symndx;
  901. union
  902. {
  903. /* The input bfd in which the symbol is defined, if it's a local
  904. symbol. */
  905. bfd *abfd;
  906. /* If symndx == -1, the hash table entry corresponding to a global
  907. symbol (even if it turns out to bind locally, in which case it
  908. should ideally be replaced with section's symndx + addend). */
  909. struct elf_link_hash_entry *h;
  910. } d;
  911. /* The addend of the relocation that references the symbol. */
  912. bfd_vma addend;
  913. /* The fields above are used to identify an entry. The fields below
  914. contain information on how an entry is used and, later on, which
  915. locations it was assigned. */
  916. /* The following 3 fields record whether the symbol+addend above was
  917. ever referenced with a GOT relocation. The 12 suffix indicates a
  918. GOT12 relocation; los is used for GOTLO relocations that are not
  919. matched by a GOTHI relocation; hilo is used for GOTLO/GOTHI
  920. pairs. */
  921. unsigned got12:1;
  922. unsigned gotlos:1;
  923. unsigned gothilo:1;
  924. /* Whether a FUNCDESC relocation references symbol+addend. */
  925. unsigned fd:1;
  926. /* Whether a FUNCDESC_GOT relocation references symbol+addend. */
  927. unsigned fdgot12:1;
  928. unsigned fdgotlos:1;
  929. unsigned fdgothilo:1;
  930. /* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
  931. unsigned fdgoff12:1;
  932. unsigned fdgofflos:1;
  933. unsigned fdgoffhilo:1;
  934. /* Whether a GETTLSOFF relocation references symbol+addend. */
  935. unsigned tlsplt:1;
  936. /* FIXME: we should probably add tlspltdesc, tlspltoff and
  937. tlspltimm, to tell what kind of TLS PLT entry we're generating.
  938. We might instead just pre-compute flags telling whether the
  939. object is suitable for local exec, initial exec or general
  940. dynamic addressing, and use that all over the place. We could
  941. also try to do a better job of merging TLSOFF and TLSDESC entries
  942. in main executables, but perhaps we can get rid of TLSDESC
  943. entirely in them instead. */
  944. /* Whether a GOTTLSDESC relocation references symbol+addend. */
  945. unsigned tlsdesc12:1;
  946. unsigned tlsdesclos:1;
  947. unsigned tlsdeschilo:1;
  948. /* Whether a GOTTLSOFF relocation references symbol+addend. */
  949. unsigned tlsoff12:1;
  950. unsigned tlsofflos:1;
  951. unsigned tlsoffhilo:1;
  952. /* Whether symbol+addend is referenced with GOTOFF12, GOTOFFLO or
  953. GOTOFFHI relocations. The addend doesn't really matter, since we
  954. envision that this will only be used to check whether the symbol
  955. is mapped to the same segment as the got. */
  956. unsigned gotoff:1;
  957. /* Whether symbol+addend is referenced by a LABEL24 relocation. */
  958. unsigned call:1;
  959. /* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
  960. relocation. */
  961. unsigned sym:1;
  962. /* Whether we need a PLT entry for a symbol. Should be implied by
  963. something like:
  964. (call && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)) */
  965. unsigned plt:1;
  966. /* Whether a function descriptor should be created in this link unit
  967. for symbol+addend. Should be implied by something like:
  968. (plt || fdgotoff12 || fdgotofflos || fdgotofflohi
  969. || ((fd || fdgot12 || fdgotlos || fdgothilo)
  970. && (symndx != -1 || FRVFDPIC_FUNCDESC_LOCAL (info, d.h)))) */
  971. unsigned privfd:1;
  972. /* Whether a lazy PLT entry is needed for this symbol+addend.
  973. Should be implied by something like:
  974. (privfd && symndx == -1 && ! FRVFDPIC_SYM_LOCAL (info, d.h)
  975. && ! (info->flags & DF_BIND_NOW)) */
  976. unsigned lazyplt:1;
  977. /* Whether we've already emitted GOT relocations and PLT entries as
  978. needed for this symbol. */
  979. unsigned done:1;
  980. /* The number of R_FRV_32, R_FRV_FUNCDESC, R_FRV_FUNCDESC_VALUE and
  981. R_FRV_TLSDESC_VALUE, R_FRV_TLSOFF relocations referencing
  982. symbol+addend. */
  983. unsigned relocs32, relocsfd, relocsfdv, relocstlsd, relocstlsoff;
  984. /* The number of .rofixups entries and dynamic relocations allocated
  985. for this symbol, minus any that might have already been used. */
  986. unsigned fixups, dynrelocs;
  987. /* The offsets of the GOT entries assigned to symbol+addend, to the
  988. function descriptor's address, and to a function descriptor,
  989. respectively. Should be zero if unassigned. The offsets are
  990. counted from the value that will be assigned to the PIC register,
  991. not from the beginning of the .got section. */
  992. bfd_signed_vma got_entry, fdgot_entry, fd_entry;
  993. /* The offsets of the PLT entries assigned to symbol+addend,
  994. non-lazy and lazy, respectively. If unassigned, should be
  995. (bfd_vma)-1. */
  996. bfd_vma plt_entry, lzplt_entry;
  997. /* The offsets of the GOT entries for TLS offset and TLS descriptor. */
  998. bfd_signed_vma tlsoff_entry, tlsdesc_entry;
  999. /* The offset of the TLS offset PLT entry. */
  1000. bfd_vma tlsplt_entry;
  1001. };
  1002. /* Compute a hash with the key fields of an frvfdpic_relocs_info entry. */
  1003. static hashval_t
  1004. frvfdpic_relocs_info_hash (const void *entry_)
  1005. {
  1006. const struct frvfdpic_relocs_info *entry = entry_;
  1007. return (entry->symndx == -1
  1008. ? (long) entry->d.h->root.root.hash
  1009. : entry->symndx + (long) entry->d.abfd->id * 257) + entry->addend;
  1010. }
  1011. /* Test whether the key fields of two frvfdpic_relocs_info entries are
  1012. identical. */
  1013. static int
  1014. frvfdpic_relocs_info_eq (const void *entry1, const void *entry2)
  1015. {
  1016. const struct frvfdpic_relocs_info *e1 = entry1;
  1017. const struct frvfdpic_relocs_info *e2 = entry2;
  1018. return e1->symndx == e2->symndx && e1->addend == e2->addend
  1019. && (e1->symndx == -1 ? e1->d.h == e2->d.h : e1->d.abfd == e2->d.abfd);
  1020. }
  1021. /* Find or create an entry in a hash table HT that matches the key
  1022. fields of the given ENTRY. If it's not found, memory for a new
  1023. entry is allocated in ABFD's obstack. */
  1024. static struct frvfdpic_relocs_info *
  1025. frvfdpic_relocs_info_find (struct htab *ht,
  1026. bfd *abfd,
  1027. const struct frvfdpic_relocs_info *entry,
  1028. enum insert_option insert)
  1029. {
  1030. struct frvfdpic_relocs_info **loc =
  1031. (struct frvfdpic_relocs_info **) htab_find_slot (ht, entry, insert);
  1032. if (! loc)
  1033. return NULL;
  1034. if (*loc)
  1035. return *loc;
  1036. *loc = bfd_zalloc (abfd, sizeof (**loc));
  1037. if (! *loc)
  1038. return *loc;
  1039. (*loc)->symndx = entry->symndx;
  1040. (*loc)->d = entry->d;
  1041. (*loc)->addend = entry->addend;
  1042. (*loc)->plt_entry = (bfd_vma)-1;
  1043. (*loc)->lzplt_entry = (bfd_vma)-1;
  1044. (*loc)->tlsplt_entry = (bfd_vma)-1;
  1045. return *loc;
  1046. }
  1047. /* Obtain the address of the entry in HT associated with H's symbol +
  1048. addend, creating a new entry if none existed. ABFD is only used
  1049. for memory allocation purposes. */
  1050. inline static struct frvfdpic_relocs_info *
  1051. frvfdpic_relocs_info_for_global (struct htab *ht,
  1052. bfd *abfd,
  1053. struct elf_link_hash_entry *h,
  1054. bfd_vma addend,
  1055. enum insert_option insert)
  1056. {
  1057. struct frvfdpic_relocs_info entry;
  1058. entry.symndx = -1;
  1059. entry.d.h = h;
  1060. entry.addend = addend;
  1061. return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
  1062. }
  1063. /* Obtain the address of the entry in HT associated with the SYMNDXth
  1064. local symbol of the input bfd ABFD, plus the addend, creating a new
  1065. entry if none existed. */
  1066. inline static struct frvfdpic_relocs_info *
  1067. frvfdpic_relocs_info_for_local (struct htab *ht,
  1068. bfd *abfd,
  1069. long symndx,
  1070. bfd_vma addend,
  1071. enum insert_option insert)
  1072. {
  1073. struct frvfdpic_relocs_info entry;
  1074. entry.symndx = symndx;
  1075. entry.d.abfd = abfd;
  1076. entry.addend = addend;
  1077. return frvfdpic_relocs_info_find (ht, abfd, &entry, insert);
  1078. }
  1079. /* Merge fields set by check_relocs() of two entries that end up being
  1080. mapped to the same (presumably global) symbol. */
  1081. inline static void
  1082. frvfdpic_pic_merge_early_relocs_info (struct frvfdpic_relocs_info *e2,
  1083. struct frvfdpic_relocs_info const *e1)
  1084. {
  1085. e2->got12 |= e1->got12;
  1086. e2->gotlos |= e1->gotlos;
  1087. e2->gothilo |= e1->gothilo;
  1088. e2->fd |= e1->fd;
  1089. e2->fdgot12 |= e1->fdgot12;
  1090. e2->fdgotlos |= e1->fdgotlos;
  1091. e2->fdgothilo |= e1->fdgothilo;
  1092. e2->fdgoff12 |= e1->fdgoff12;
  1093. e2->fdgofflos |= e1->fdgofflos;
  1094. e2->fdgoffhilo |= e1->fdgoffhilo;
  1095. e2->tlsplt |= e1->tlsplt;
  1096. e2->tlsdesc12 |= e1->tlsdesc12;
  1097. e2->tlsdesclos |= e1->tlsdesclos;
  1098. e2->tlsdeschilo |= e1->tlsdeschilo;
  1099. e2->tlsoff12 |= e1->tlsoff12;
  1100. e2->tlsofflos |= e1->tlsofflos;
  1101. e2->tlsoffhilo |= e1->tlsoffhilo;
  1102. e2->gotoff |= e1->gotoff;
  1103. e2->call |= e1->call;
  1104. e2->sym |= e1->sym;
  1105. }
  1106. /* Every block of 65535 lazy PLT entries shares a single call to the
  1107. resolver, inserted in the 32768th lazy PLT entry (i.e., entry #
  1108. 32767, counting from 0). All other lazy PLT entries branch to it
  1109. in a single instruction. */
  1110. #define FRVFDPIC_LZPLT_BLOCK_SIZE ((bfd_vma) 8 * 65535 + 4)
  1111. #define FRVFDPIC_LZPLT_RESOLV_LOC (8 * 32767)
  1112. /* Add a dynamic relocation to the SRELOC section. */
  1113. inline static bfd_vma
  1114. _frvfdpic_add_dyn_reloc (bfd *output_bfd, asection *sreloc, bfd_vma offset,
  1115. int reloc_type, long dynindx, bfd_vma addend,
  1116. struct frvfdpic_relocs_info *entry)
  1117. {
  1118. Elf_Internal_Rela outrel;
  1119. bfd_vma reloc_offset;
  1120. outrel.r_offset = offset;
  1121. outrel.r_info = ELF32_R_INFO (dynindx, reloc_type);
  1122. outrel.r_addend = addend;
  1123. reloc_offset = sreloc->reloc_count * sizeof (Elf32_External_Rel);
  1124. BFD_ASSERT (reloc_offset < sreloc->size);
  1125. bfd_elf32_swap_reloc_out (output_bfd, &outrel,
  1126. sreloc->contents + reloc_offset);
  1127. sreloc->reloc_count++;
  1128. /* If the entry's index is zero, this relocation was probably to a
  1129. linkonce section that got discarded. We reserved a dynamic
  1130. relocation, but it was for another entry than the one we got at
  1131. the time of emitting the relocation. Unfortunately there's no
  1132. simple way for us to catch this situation, since the relocation
  1133. is cleared right before calling relocate_section, at which point
  1134. we no longer know what the relocation used to point to. */
  1135. if (entry->symndx)
  1136. {
  1137. BFD_ASSERT (entry->dynrelocs > 0);
  1138. entry->dynrelocs--;
  1139. }
  1140. return reloc_offset;
  1141. }
  1142. /* Add a fixup to the ROFIXUP section. */
  1143. static bfd_vma
  1144. _frvfdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma offset,
  1145. struct frvfdpic_relocs_info *entry)
  1146. {
  1147. bfd_vma fixup_offset;
  1148. if (rofixup->flags & SEC_EXCLUDE)
  1149. return -1;
  1150. fixup_offset = rofixup->reloc_count * 4;
  1151. if (rofixup->contents)
  1152. {
  1153. BFD_ASSERT (fixup_offset < rofixup->size);
  1154. bfd_put_32 (output_bfd, offset, rofixup->contents + fixup_offset);
  1155. }
  1156. rofixup->reloc_count++;
  1157. if (entry && entry->symndx)
  1158. {
  1159. /* See discussion about symndx == 0 in _frvfdpic_add_dyn_reloc
  1160. above. */
  1161. BFD_ASSERT (entry->fixups > 0);
  1162. entry->fixups--;
  1163. }
  1164. return fixup_offset;
  1165. }
  1166. /* Find the segment number in which OSEC, and output section, is
  1167. located. */
  1168. static unsigned
  1169. _frvfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
  1170. {
  1171. Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
  1172. return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
  1173. }
  1174. inline static bool
  1175. _frvfdpic_osec_readonly_p (bfd *output_bfd, asection *osec)
  1176. {
  1177. unsigned seg = _frvfdpic_osec_to_segment (output_bfd, osec);
  1178. return ! (elf_tdata (output_bfd)->phdr[seg].p_flags & PF_W);
  1179. }
  1180. #define FRVFDPIC_TLS_BIAS (2048 - 16)
  1181. /* Return the base VMA address which should be subtracted from real addresses
  1182. when resolving TLSMOFF relocation.
  1183. This is PT_TLS segment p_vaddr, plus the 2048-16 bias. */
  1184. static bfd_vma
  1185. tls_biased_base (struct bfd_link_info *info)
  1186. {
  1187. /* If tls_sec is NULL, we should have signalled an error already. */
  1188. if (elf_hash_table (info)->tls_sec == NULL)
  1189. return FRVFDPIC_TLS_BIAS;
  1190. return elf_hash_table (info)->tls_sec->vma + FRVFDPIC_TLS_BIAS;
  1191. }
  1192. /* Generate relocations for GOT entries, function descriptors, and
  1193. code for PLT and lazy PLT entries. */
  1194. inline static bool
  1195. _frvfdpic_emit_got_relocs_plt_entries (struct frvfdpic_relocs_info *entry,
  1196. bfd *output_bfd,
  1197. struct bfd_link_info *info,
  1198. asection *sec,
  1199. Elf_Internal_Sym *sym,
  1200. bfd_vma addend)
  1201. {
  1202. bfd_vma fd_lazy_rel_offset = (bfd_vma)-1;
  1203. int dynindx = -1;
  1204. if (entry->done)
  1205. return true;
  1206. entry->done = 1;
  1207. if (entry->got_entry || entry->fdgot_entry || entry->fd_entry
  1208. || entry->tlsoff_entry || entry->tlsdesc_entry)
  1209. {
  1210. /* If the symbol is dynamic, consider it for dynamic
  1211. relocations, otherwise decay to section + offset. */
  1212. if (entry->symndx == -1 && entry->d.h->dynindx != -1)
  1213. dynindx = entry->d.h->dynindx;
  1214. else
  1215. {
  1216. if (sec
  1217. && sec->output_section
  1218. && ! bfd_is_abs_section (sec->output_section)
  1219. && ! bfd_is_und_section (sec->output_section))
  1220. dynindx = elf_section_data (sec->output_section)->dynindx;
  1221. else
  1222. dynindx = 0;
  1223. }
  1224. }
  1225. /* Generate relocation for GOT entry pointing to the symbol. */
  1226. if (entry->got_entry)
  1227. {
  1228. int idx = dynindx;
  1229. bfd_vma ad = addend;
  1230. /* If the symbol is dynamic but binds locally, use
  1231. section+offset. */
  1232. if (sec && (entry->symndx != -1
  1233. || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
  1234. {
  1235. if (entry->symndx == -1)
  1236. ad += entry->d.h->root.u.def.value;
  1237. else
  1238. ad += sym->st_value;
  1239. ad += sec->output_offset;
  1240. if (sec->output_section && elf_section_data (sec->output_section))
  1241. idx = elf_section_data (sec->output_section)->dynindx;
  1242. else
  1243. idx = 0;
  1244. }
  1245. /* If we're linking an executable at a fixed address, we can
  1246. omit the dynamic relocation as long as the symbol is local to
  1247. this module. */
  1248. if (bfd_link_pde (info)
  1249. && (entry->symndx != -1
  1250. || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
  1251. {
  1252. if (sec)
  1253. ad += sec->output_section->vma;
  1254. if (entry->symndx != -1
  1255. || entry->d.h->root.type != bfd_link_hash_undefweak)
  1256. _frvfdpic_add_rofixup (output_bfd,
  1257. frvfdpic_gotfixup_section (info),
  1258. frvfdpic_got_section (info)->output_section
  1259. ->vma
  1260. + frvfdpic_got_section (info)->output_offset
  1261. + frvfdpic_got_initial_offset (info)
  1262. + entry->got_entry, entry);
  1263. }
  1264. else
  1265. _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
  1266. _bfd_elf_section_offset
  1267. (output_bfd, info,
  1268. frvfdpic_got_section (info),
  1269. frvfdpic_got_initial_offset (info)
  1270. + entry->got_entry)
  1271. + frvfdpic_got_section (info)
  1272. ->output_section->vma
  1273. + frvfdpic_got_section (info)->output_offset,
  1274. R_FRV_32, idx, ad, entry);
  1275. bfd_put_32 (output_bfd, ad,
  1276. frvfdpic_got_section (info)->contents
  1277. + frvfdpic_got_initial_offset (info)
  1278. + entry->got_entry);
  1279. }
  1280. /* Generate relocation for GOT entry pointing to a canonical
  1281. function descriptor. */
  1282. if (entry->fdgot_entry)
  1283. {
  1284. int reloc, idx;
  1285. bfd_vma ad = 0;
  1286. if (! (entry->symndx == -1
  1287. && entry->d.h->root.type == bfd_link_hash_undefweak
  1288. && FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
  1289. {
  1290. /* If the symbol is dynamic and there may be dynamic symbol
  1291. resolution because we are, or are linked with, a shared
  1292. library, emit a FUNCDESC relocation such that the dynamic
  1293. linker will allocate the function descriptor. If the
  1294. symbol needs a non-local function descriptor but binds
  1295. locally (e.g., its visibility is protected, emit a
  1296. dynamic relocation decayed to section+offset. */
  1297. if (entry->symndx == -1
  1298. && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)
  1299. && FRVFDPIC_SYM_LOCAL (info, entry->d.h)
  1300. && !bfd_link_pde (info))
  1301. {
  1302. reloc = R_FRV_FUNCDESC;
  1303. idx = elf_section_data (entry->d.h->root.u.def.section
  1304. ->output_section)->dynindx;
  1305. ad = entry->d.h->root.u.def.section->output_offset
  1306. + entry->d.h->root.u.def.value;
  1307. }
  1308. else if (entry->symndx == -1
  1309. && ! FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h))
  1310. {
  1311. reloc = R_FRV_FUNCDESC;
  1312. idx = dynindx;
  1313. ad = addend;
  1314. if (ad)
  1315. {
  1316. (*info->callbacks->reloc_dangerous)
  1317. (info, _("relocation requires zero addend"),
  1318. elf_hash_table (info)->dynobj,
  1319. frvfdpic_got_section (info),
  1320. entry->fdgot_entry);
  1321. return false;
  1322. }
  1323. }
  1324. else
  1325. {
  1326. /* Otherwise, we know we have a private function descriptor,
  1327. so reference it directly. */
  1328. if (elf_hash_table (info)->dynamic_sections_created)
  1329. BFD_ASSERT (entry->privfd);
  1330. reloc = R_FRV_32;
  1331. idx = elf_section_data (frvfdpic_got_section (info)
  1332. ->output_section)->dynindx;
  1333. ad = frvfdpic_got_section (info)->output_offset
  1334. + frvfdpic_got_initial_offset (info) + entry->fd_entry;
  1335. }
  1336. /* If there is room for dynamic symbol resolution, emit the
  1337. dynamic relocation. However, if we're linking an
  1338. executable at a fixed location, we won't have emitted a
  1339. dynamic symbol entry for the got section, so idx will be
  1340. zero, which means we can and should compute the address
  1341. of the private descriptor ourselves. */
  1342. if (bfd_link_pde (info)
  1343. && (entry->symndx != -1
  1344. || FRVFDPIC_FUNCDESC_LOCAL (info, entry->d.h)))
  1345. {
  1346. ad += frvfdpic_got_section (info)->output_section->vma;
  1347. _frvfdpic_add_rofixup (output_bfd,
  1348. frvfdpic_gotfixup_section (info),
  1349. frvfdpic_got_section (info)
  1350. ->output_section->vma
  1351. + frvfdpic_got_section (info)
  1352. ->output_offset
  1353. + frvfdpic_got_initial_offset (info)
  1354. + entry->fdgot_entry, entry);
  1355. }
  1356. else
  1357. _frvfdpic_add_dyn_reloc (output_bfd,
  1358. frvfdpic_gotrel_section (info),
  1359. _bfd_elf_section_offset
  1360. (output_bfd, info,
  1361. frvfdpic_got_section (info),
  1362. frvfdpic_got_initial_offset (info)
  1363. + entry->fdgot_entry)
  1364. + frvfdpic_got_section (info)
  1365. ->output_section->vma
  1366. + frvfdpic_got_section (info)
  1367. ->output_offset,
  1368. reloc, idx, ad, entry);
  1369. }
  1370. bfd_put_32 (output_bfd, ad,
  1371. frvfdpic_got_section (info)->contents
  1372. + frvfdpic_got_initial_offset (info)
  1373. + entry->fdgot_entry);
  1374. }
  1375. /* Generate relocation to fill in a private function descriptor in
  1376. the GOT. */
  1377. if (entry->fd_entry)
  1378. {
  1379. int idx = dynindx;
  1380. bfd_vma ad = addend;
  1381. bfd_vma ofst;
  1382. long lowword, highword;
  1383. /* If the symbol is dynamic but binds locally, use
  1384. section+offset. */
  1385. if (sec && (entry->symndx != -1
  1386. || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
  1387. {
  1388. if (entry->symndx == -1)
  1389. ad += entry->d.h->root.u.def.value;
  1390. else
  1391. ad += sym->st_value;
  1392. ad += sec->output_offset;
  1393. if (sec->output_section && elf_section_data (sec->output_section))
  1394. idx = elf_section_data (sec->output_section)->dynindx;
  1395. else
  1396. idx = 0;
  1397. }
  1398. /* If we're linking an executable at a fixed address, we can
  1399. omit the dynamic relocation as long as the symbol is local to
  1400. this module. */
  1401. if (bfd_link_pde (info)
  1402. && (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
  1403. {
  1404. if (sec)
  1405. ad += sec->output_section->vma;
  1406. ofst = 0;
  1407. if (entry->symndx != -1
  1408. || entry->d.h->root.type != bfd_link_hash_undefweak)
  1409. {
  1410. _frvfdpic_add_rofixup (output_bfd,
  1411. frvfdpic_gotfixup_section (info),
  1412. frvfdpic_got_section (info)
  1413. ->output_section->vma
  1414. + frvfdpic_got_section (info)
  1415. ->output_offset
  1416. + frvfdpic_got_initial_offset (info)
  1417. + entry->fd_entry, entry);
  1418. _frvfdpic_add_rofixup (output_bfd,
  1419. frvfdpic_gotfixup_section (info),
  1420. frvfdpic_got_section (info)
  1421. ->output_section->vma
  1422. + frvfdpic_got_section (info)
  1423. ->output_offset
  1424. + frvfdpic_got_initial_offset (info)
  1425. + entry->fd_entry + 4, entry);
  1426. }
  1427. }
  1428. else
  1429. {
  1430. ofst =
  1431. _frvfdpic_add_dyn_reloc (output_bfd,
  1432. entry->lazyplt
  1433. ? frvfdpic_pltrel_section (info)
  1434. : frvfdpic_gotrel_section (info),
  1435. _bfd_elf_section_offset
  1436. (output_bfd, info,
  1437. frvfdpic_got_section (info),
  1438. frvfdpic_got_initial_offset (info)
  1439. + entry->fd_entry)
  1440. + frvfdpic_got_section (info)
  1441. ->output_section->vma
  1442. + frvfdpic_got_section (info)
  1443. ->output_offset,
  1444. R_FRV_FUNCDESC_VALUE, idx, ad, entry);
  1445. }
  1446. /* If we've omitted the dynamic relocation, just emit the fixed
  1447. addresses of the symbol and of the local GOT base offset. */
  1448. if (bfd_link_pde (info)
  1449. && sec
  1450. && sec->output_section)
  1451. {
  1452. lowword = ad;
  1453. highword = frvfdpic_got_section (info)->output_section->vma
  1454. + frvfdpic_got_section (info)->output_offset
  1455. + frvfdpic_got_initial_offset (info);
  1456. }
  1457. else if (entry->lazyplt)
  1458. {
  1459. if (ad)
  1460. {
  1461. (*info->callbacks->reloc_dangerous)
  1462. (info, _("relocation requires zero addend"),
  1463. elf_hash_table (info)->dynobj,
  1464. frvfdpic_got_section (info),
  1465. entry->fd_entry);
  1466. return false;
  1467. }
  1468. fd_lazy_rel_offset = ofst;
  1469. /* A function descriptor used for lazy or local resolving is
  1470. initialized such that its high word contains the output
  1471. section index in which the PLT entries are located, and
  1472. the low word contains the address of the lazy PLT entry
  1473. entry point, that must be within the memory region
  1474. assigned to that section. */
  1475. lowword = entry->lzplt_entry + 4
  1476. + frvfdpic_plt_section (info)->output_offset
  1477. + frvfdpic_plt_section (info)->output_section->vma;
  1478. highword = _frvfdpic_osec_to_segment
  1479. (output_bfd, frvfdpic_plt_section (info)->output_section);
  1480. }
  1481. else
  1482. {
  1483. /* A function descriptor for a local function gets the index
  1484. of the section. For a non-local function, it's
  1485. disregarded. */
  1486. lowword = ad;
  1487. if (sec == NULL
  1488. || (entry->symndx == -1 && entry->d.h->dynindx != -1
  1489. && entry->d.h->dynindx == idx))
  1490. highword = 0;
  1491. else
  1492. highword = _frvfdpic_osec_to_segment
  1493. (output_bfd, sec->output_section);
  1494. }
  1495. bfd_put_32 (output_bfd, lowword,
  1496. frvfdpic_got_section (info)->contents
  1497. + frvfdpic_got_initial_offset (info)
  1498. + entry->fd_entry);
  1499. bfd_put_32 (output_bfd, highword,
  1500. frvfdpic_got_section (info)->contents
  1501. + frvfdpic_got_initial_offset (info)
  1502. + entry->fd_entry + 4);
  1503. }
  1504. /* Generate code for the PLT entry. */
  1505. if (entry->plt_entry != (bfd_vma) -1)
  1506. {
  1507. bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
  1508. + entry->plt_entry;
  1509. BFD_ASSERT (entry->fd_entry);
  1510. /* Figure out what kind of PLT entry we need, depending on the
  1511. location of the function descriptor within the GOT. */
  1512. if (entry->fd_entry >= -(1 << (12 - 1))
  1513. && entry->fd_entry < (1 << (12 - 1)))
  1514. {
  1515. /* lddi @(gr15, fd_entry), gr14 */
  1516. bfd_put_32 (output_bfd,
  1517. 0x9cccf000 | (entry->fd_entry & ((1 << 12) - 1)),
  1518. plt_code);
  1519. plt_code += 4;
  1520. }
  1521. else
  1522. {
  1523. if (entry->fd_entry >= -(1 << (16 - 1))
  1524. && entry->fd_entry < (1 << (16 - 1)))
  1525. {
  1526. /* setlos lo(fd_entry), gr14 */
  1527. bfd_put_32 (output_bfd,
  1528. 0x9cfc0000
  1529. | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
  1530. plt_code);
  1531. plt_code += 4;
  1532. }
  1533. else
  1534. {
  1535. /* sethi.p hi(fd_entry), gr14
  1536. setlo lo(fd_entry), gr14 */
  1537. bfd_put_32 (output_bfd,
  1538. 0x1cf80000
  1539. | ((entry->fd_entry >> 16)
  1540. & (((bfd_vma)1 << 16) - 1)),
  1541. plt_code);
  1542. plt_code += 4;
  1543. bfd_put_32 (output_bfd,
  1544. 0x9cf40000
  1545. | (entry->fd_entry & (((bfd_vma)1 << 16) - 1)),
  1546. plt_code);
  1547. plt_code += 4;
  1548. }
  1549. /* ldd @(gr14,gr15),gr14 */
  1550. bfd_put_32 (output_bfd, 0x9c08e14f, plt_code);
  1551. plt_code += 4;
  1552. }
  1553. /* jmpl @(gr14,gr0) */
  1554. bfd_put_32 (output_bfd, 0x8030e000, plt_code);
  1555. }
  1556. /* Generate code for the lazy PLT entry. */
  1557. if (entry->lzplt_entry != (bfd_vma) -1)
  1558. {
  1559. bfd_byte *lzplt_code = frvfdpic_plt_section (info)->contents
  1560. + entry->lzplt_entry;
  1561. bfd_vma resolverStub_addr;
  1562. bfd_put_32 (output_bfd, fd_lazy_rel_offset, lzplt_code);
  1563. lzplt_code += 4;
  1564. resolverStub_addr = entry->lzplt_entry / FRVFDPIC_LZPLT_BLOCK_SIZE
  1565. * FRVFDPIC_LZPLT_BLOCK_SIZE + FRVFDPIC_LZPLT_RESOLV_LOC;
  1566. if (resolverStub_addr >= frvfdpic_plt_initial_offset (info))
  1567. resolverStub_addr = frvfdpic_plt_initial_offset (info) - 12;
  1568. if (entry->lzplt_entry == resolverStub_addr)
  1569. {
  1570. /* This is a lazy PLT entry that includes a resolver call. */
  1571. /* ldd @(gr15,gr0), gr4
  1572. jmpl @(gr4,gr0) */
  1573. bfd_put_32 (output_bfd, 0x8808f140, lzplt_code);
  1574. bfd_put_32 (output_bfd, 0x80304000, lzplt_code + 4);
  1575. }
  1576. else
  1577. {
  1578. /* bra resolverStub */
  1579. bfd_put_32 (output_bfd,
  1580. 0xc01a0000
  1581. | (((resolverStub_addr - entry->lzplt_entry)
  1582. / 4) & (((bfd_vma)1 << 16) - 1)),
  1583. lzplt_code);
  1584. }
  1585. }
  1586. /* Generate relocation for GOT entry holding the TLS offset. */
  1587. if (entry->tlsoff_entry)
  1588. {
  1589. int idx = dynindx;
  1590. bfd_vma ad = addend;
  1591. if (entry->symndx != -1
  1592. || FRVFDPIC_SYM_LOCAL (info, entry->d.h))
  1593. {
  1594. /* If the symbol is dynamic but binds locally, use
  1595. section+offset. */
  1596. if (sec)
  1597. {
  1598. if (entry->symndx == -1)
  1599. ad += entry->d.h->root.u.def.value;
  1600. else
  1601. ad += sym->st_value;
  1602. ad += sec->output_offset;
  1603. if (sec->output_section
  1604. && elf_section_data (sec->output_section))
  1605. idx = elf_section_data (sec->output_section)->dynindx;
  1606. else
  1607. idx = 0;
  1608. }
  1609. }
  1610. /* *ABS*+addend is special for TLS relocations, use only the
  1611. addend. */
  1612. if (bfd_link_executable (info)
  1613. && idx == 0
  1614. && (bfd_is_abs_section (sec)
  1615. || bfd_is_und_section (sec)))
  1616. ;
  1617. /* If we're linking an executable, we can entirely omit the
  1618. dynamic relocation if the symbol is local to this module. */
  1619. else if (bfd_link_executable (info)
  1620. && (entry->symndx != -1
  1621. || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
  1622. {
  1623. if (sec)
  1624. ad += sec->output_section->vma - tls_biased_base (info);
  1625. }
  1626. else
  1627. {
  1628. if (idx == 0
  1629. && (bfd_is_abs_section (sec)
  1630. || bfd_is_und_section (sec)))
  1631. {
  1632. if (! elf_hash_table (info)->tls_sec)
  1633. {
  1634. (*info->callbacks->undefined_symbol)
  1635. (info, "TLS section", elf_hash_table (info)->dynobj,
  1636. frvfdpic_got_section (info), entry->tlsoff_entry, true);
  1637. return false;
  1638. }
  1639. idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
  1640. ad += FRVFDPIC_TLS_BIAS;
  1641. }
  1642. _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
  1643. _bfd_elf_section_offset
  1644. (output_bfd, info,
  1645. frvfdpic_got_section (info),
  1646. frvfdpic_got_initial_offset (info)
  1647. + entry->tlsoff_entry)
  1648. + frvfdpic_got_section (info)
  1649. ->output_section->vma
  1650. + frvfdpic_got_section (info)
  1651. ->output_offset,
  1652. R_FRV_TLSOFF, idx, ad, entry);
  1653. }
  1654. bfd_put_32 (output_bfd, ad,
  1655. frvfdpic_got_section (info)->contents
  1656. + frvfdpic_got_initial_offset (info)
  1657. + entry->tlsoff_entry);
  1658. }
  1659. if (entry->tlsdesc_entry)
  1660. {
  1661. int idx = dynindx;
  1662. bfd_vma ad = addend;
  1663. /* If the symbol is dynamic but binds locally, use
  1664. section+offset. */
  1665. if (sec && (entry->symndx != -1
  1666. || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
  1667. {
  1668. if (entry->symndx == -1)
  1669. ad += entry->d.h->root.u.def.value;
  1670. else
  1671. ad += sym->st_value;
  1672. ad += sec->output_offset;
  1673. if (sec->output_section && elf_section_data (sec->output_section))
  1674. idx = elf_section_data (sec->output_section)->dynindx;
  1675. else
  1676. idx = 0;
  1677. }
  1678. /* If we didn't set up a TLS offset entry, but we're linking an
  1679. executable and the symbol binds locally, we can use the
  1680. module offset in the TLS descriptor in relaxations. */
  1681. if (bfd_link_executable (info) && ! entry->tlsoff_entry)
  1682. entry->tlsoff_entry = entry->tlsdesc_entry + 4;
  1683. if (bfd_link_pde (info)
  1684. && ((idx == 0
  1685. && (bfd_is_abs_section (sec)
  1686. || bfd_is_und_section (sec)))
  1687. || entry->symndx != -1
  1688. || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
  1689. {
  1690. /* *ABS*+addend is special for TLS relocations, use only the
  1691. addend for the TLS offset, and take the module id as
  1692. 0. */
  1693. if (idx == 0
  1694. && (bfd_is_abs_section (sec)
  1695. || bfd_is_und_section (sec)))
  1696. ;
  1697. /* For other TLS symbols that bind locally, add the section
  1698. TLS offset to the addend. */
  1699. else if (sec)
  1700. ad += sec->output_section->vma - tls_biased_base (info);
  1701. bfd_put_32 (output_bfd,
  1702. frvfdpic_plt_section (info)->output_section->vma
  1703. + frvfdpic_plt_section (info)->output_offset
  1704. + frvfdpic_plt_tls_ret_offset (info),
  1705. frvfdpic_got_section (info)->contents
  1706. + frvfdpic_got_initial_offset (info)
  1707. + entry->tlsdesc_entry);
  1708. _frvfdpic_add_rofixup (output_bfd,
  1709. frvfdpic_gotfixup_section (info),
  1710. frvfdpic_got_section (info)
  1711. ->output_section->vma
  1712. + frvfdpic_got_section (info)
  1713. ->output_offset
  1714. + frvfdpic_got_initial_offset (info)
  1715. + entry->tlsdesc_entry, entry);
  1716. BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs);
  1717. /* We've used one of the reserved fixups, so discount it so
  1718. that we can check at the end that we've used them
  1719. all. */
  1720. frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs--;
  1721. /* While at that, make sure the ret instruction makes to the
  1722. right location in the PLT. We could do it only when we
  1723. got to 0, but since the check at the end will only print
  1724. a warning, make sure we have the ret in place in case the
  1725. warning is missed. */
  1726. bfd_put_32 (output_bfd, 0xc03a4000,
  1727. frvfdpic_plt_section (info)->contents
  1728. + frvfdpic_plt_tls_ret_offset (info));
  1729. }
  1730. else
  1731. {
  1732. if (idx == 0
  1733. && (bfd_is_abs_section (sec)
  1734. || bfd_is_und_section (sec)))
  1735. {
  1736. if (! elf_hash_table (info)->tls_sec)
  1737. {
  1738. (*info->callbacks->undefined_symbol)
  1739. (info, "TLS section", elf_hash_table (info)->dynobj,
  1740. frvfdpic_got_section (info), entry->tlsdesc_entry, true);
  1741. return false;
  1742. }
  1743. idx = elf_section_data (elf_hash_table (info)->tls_sec)->dynindx;
  1744. ad += FRVFDPIC_TLS_BIAS;
  1745. }
  1746. _frvfdpic_add_dyn_reloc (output_bfd, frvfdpic_gotrel_section (info),
  1747. _bfd_elf_section_offset
  1748. (output_bfd, info,
  1749. frvfdpic_got_section (info),
  1750. frvfdpic_got_initial_offset (info)
  1751. + entry->tlsdesc_entry)
  1752. + frvfdpic_got_section (info)
  1753. ->output_section->vma
  1754. + frvfdpic_got_section (info)
  1755. ->output_offset,
  1756. R_FRV_TLSDESC_VALUE, idx, ad, entry);
  1757. bfd_put_32 (output_bfd, 0,
  1758. frvfdpic_got_section (info)->contents
  1759. + frvfdpic_got_initial_offset (info)
  1760. + entry->tlsdesc_entry);
  1761. }
  1762. bfd_put_32 (output_bfd, ad,
  1763. frvfdpic_got_section (info)->contents
  1764. + frvfdpic_got_initial_offset (info)
  1765. + entry->tlsdesc_entry + 4);
  1766. }
  1767. /* Generate code for the get-TLS-offset PLT entry. */
  1768. if (entry->tlsplt_entry != (bfd_vma) -1)
  1769. {
  1770. bfd_byte *plt_code = frvfdpic_plt_section (info)->contents
  1771. + entry->tlsplt_entry;
  1772. if (bfd_link_executable (info)
  1773. && (entry->symndx != -1
  1774. || FRVFDPIC_SYM_LOCAL (info, entry->d.h)))
  1775. {
  1776. int idx = dynindx;
  1777. bfd_vma ad = addend;
  1778. /* sec may be NULL when referencing an undefweak symbol
  1779. while linking a static executable. */
  1780. if (!sec)
  1781. {
  1782. BFD_ASSERT (entry->symndx == -1
  1783. && entry->d.h->root.type == bfd_link_hash_undefweak);
  1784. }
  1785. else
  1786. {
  1787. if (entry->symndx == -1)
  1788. ad += entry->d.h->root.u.def.value;
  1789. else
  1790. ad += sym->st_value;
  1791. ad += sec->output_offset;
  1792. if (sec->output_section
  1793. && elf_section_data (sec->output_section))
  1794. idx = elf_section_data (sec->output_section)->dynindx;
  1795. else
  1796. idx = 0;
  1797. }
  1798. /* *ABS*+addend is special for TLS relocations, use only the
  1799. addend for the TLS offset, and take the module id as
  1800. 0. */
  1801. if (idx == 0
  1802. && (bfd_is_abs_section (sec)
  1803. || bfd_is_und_section (sec)))
  1804. ;
  1805. /* For other TLS symbols that bind locally, add the section
  1806. TLS offset to the addend. */
  1807. else if (sec)
  1808. ad += sec->output_section->vma - tls_biased_base (info);
  1809. if ((bfd_signed_vma)ad >= -(1 << (16 - 1))
  1810. && (bfd_signed_vma)ad < (1 << (16 - 1)))
  1811. {
  1812. /* setlos lo(ad), gr9 */
  1813. bfd_put_32 (output_bfd,
  1814. 0x92fc0000
  1815. | (ad
  1816. & (((bfd_vma)1 << 16) - 1)),
  1817. plt_code);
  1818. plt_code += 4;
  1819. }
  1820. else
  1821. {
  1822. /* sethi.p hi(ad), gr9
  1823. setlo lo(ad), gr9 */
  1824. bfd_put_32 (output_bfd,
  1825. 0x12f80000
  1826. | ((ad >> 16)
  1827. & (((bfd_vma)1 << 16) - 1)),
  1828. plt_code);
  1829. plt_code += 4;
  1830. bfd_put_32 (output_bfd,
  1831. 0x92f40000
  1832. | (ad
  1833. & (((bfd_vma)1 << 16) - 1)),
  1834. plt_code);
  1835. plt_code += 4;
  1836. }
  1837. /* ret */
  1838. bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
  1839. }
  1840. else if (entry->tlsoff_entry)
  1841. {
  1842. /* Figure out what kind of PLT entry we need, depending on the
  1843. location of the TLS descriptor within the GOT. */
  1844. if (entry->tlsoff_entry >= -(1 << (12 - 1))
  1845. && entry->tlsoff_entry < (1 << (12 - 1)))
  1846. {
  1847. /* ldi @(gr15, tlsoff_entry), gr9 */
  1848. bfd_put_32 (output_bfd,
  1849. 0x92c8f000 | (entry->tlsoff_entry
  1850. & ((1 << 12) - 1)),
  1851. plt_code);
  1852. plt_code += 4;
  1853. }
  1854. else
  1855. {
  1856. if (entry->tlsoff_entry >= -(1 << (16 - 1))
  1857. && entry->tlsoff_entry < (1 << (16 - 1)))
  1858. {
  1859. /* setlos lo(tlsoff_entry), gr8 */
  1860. bfd_put_32 (output_bfd,
  1861. 0x90fc0000
  1862. | (entry->tlsoff_entry
  1863. & (((bfd_vma)1 << 16) - 1)),
  1864. plt_code);
  1865. plt_code += 4;
  1866. }
  1867. else
  1868. {
  1869. /* sethi.p hi(tlsoff_entry), gr8
  1870. setlo lo(tlsoff_entry), gr8 */
  1871. bfd_put_32 (output_bfd,
  1872. 0x10f80000
  1873. | ((entry->tlsoff_entry >> 16)
  1874. & (((bfd_vma)1 << 16) - 1)),
  1875. plt_code);
  1876. plt_code += 4;
  1877. bfd_put_32 (output_bfd,
  1878. 0x90f40000
  1879. | (entry->tlsoff_entry
  1880. & (((bfd_vma)1 << 16) - 1)),
  1881. plt_code);
  1882. plt_code += 4;
  1883. }
  1884. /* ld @(gr15,gr8),gr9 */
  1885. bfd_put_32 (output_bfd, 0x9008f108, plt_code);
  1886. plt_code += 4;
  1887. }
  1888. /* ret */
  1889. bfd_put_32 (output_bfd, 0xc03a4000, plt_code);
  1890. }
  1891. else
  1892. {
  1893. BFD_ASSERT (entry->tlsdesc_entry);
  1894. /* Figure out what kind of PLT entry we need, depending on the
  1895. location of the TLS descriptor within the GOT. */
  1896. if (entry->tlsdesc_entry >= -(1 << (12 - 1))
  1897. && entry->tlsdesc_entry < (1 << (12 - 1)))
  1898. {
  1899. /* lddi @(gr15, tlsdesc_entry), gr8 */
  1900. bfd_put_32 (output_bfd,
  1901. 0x90ccf000 | (entry->tlsdesc_entry
  1902. & ((1 << 12) - 1)),
  1903. plt_code);
  1904. plt_code += 4;
  1905. }
  1906. else
  1907. {
  1908. if (entry->tlsdesc_entry >= -(1 << (16 - 1))
  1909. && entry->tlsdesc_entry < (1 << (16 - 1)))
  1910. {
  1911. /* setlos lo(tlsdesc_entry), gr8 */
  1912. bfd_put_32 (output_bfd,
  1913. 0x90fc0000
  1914. | (entry->tlsdesc_entry
  1915. & (((bfd_vma)1 << 16) - 1)),
  1916. plt_code);
  1917. plt_code += 4;
  1918. }
  1919. else
  1920. {
  1921. /* sethi.p hi(tlsdesc_entry), gr8
  1922. setlo lo(tlsdesc_entry), gr8 */
  1923. bfd_put_32 (output_bfd,
  1924. 0x10f80000
  1925. | ((entry->tlsdesc_entry >> 16)
  1926. & (((bfd_vma)1 << 16) - 1)),
  1927. plt_code);
  1928. plt_code += 4;
  1929. bfd_put_32 (output_bfd,
  1930. 0x90f40000
  1931. | (entry->tlsdesc_entry
  1932. & (((bfd_vma)1 << 16) - 1)),
  1933. plt_code);
  1934. plt_code += 4;
  1935. }
  1936. /* ldd @(gr15,gr8),gr8 */
  1937. bfd_put_32 (output_bfd, 0x9008f148, plt_code);
  1938. plt_code += 4;
  1939. }
  1940. /* jmpl @(gr8,gr0) */
  1941. bfd_put_32 (output_bfd, 0x80308000, plt_code);
  1942. }
  1943. }
  1944. return true;
  1945. }
  1946. /* Handle an FRV small data reloc. */
  1947. static bfd_reloc_status_type
  1948. elf32_frv_relocate_gprel12 (struct bfd_link_info *info,
  1949. bfd *input_bfd,
  1950. asection *input_section,
  1951. Elf_Internal_Rela *relocation,
  1952. bfd_byte *contents,
  1953. bfd_vma value)
  1954. {
  1955. bfd_vma insn;
  1956. bfd_vma gp;
  1957. struct bfd_link_hash_entry *h;
  1958. h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
  1959. gp = (h->u.def.value
  1960. + h->u.def.section->output_section->vma
  1961. + h->u.def.section->output_offset);
  1962. value -= input_section->output_section->vma;
  1963. value -= (gp - input_section->output_section->vma);
  1964. insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
  1965. value += relocation->r_addend;
  1966. if ((long) value > 0x7ff || (long) value < -0x800)
  1967. return bfd_reloc_overflow;
  1968. bfd_put_32 (input_bfd,
  1969. (insn & 0xfffff000) | (value & 0xfff),
  1970. contents + relocation->r_offset);
  1971. return bfd_reloc_ok;
  1972. }
  1973. /* Handle an FRV small data reloc. for the u12 field. */
  1974. static bfd_reloc_status_type
  1975. elf32_frv_relocate_gprelu12 (struct bfd_link_info *info,
  1976. bfd *input_bfd,
  1977. asection *input_section,
  1978. Elf_Internal_Rela *relocation,
  1979. bfd_byte *contents,
  1980. bfd_vma value)
  1981. {
  1982. bfd_vma insn;
  1983. bfd_vma gp;
  1984. struct bfd_link_hash_entry *h;
  1985. bfd_vma mask;
  1986. h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
  1987. gp = (h->u.def.value
  1988. + h->u.def.section->output_section->vma
  1989. + h->u.def.section->output_offset);
  1990. value -= input_section->output_section->vma;
  1991. value -= (gp - input_section->output_section->vma);
  1992. insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
  1993. value += relocation->r_addend;
  1994. if ((long) value > 0x7ff || (long) value < -0x800)
  1995. return bfd_reloc_overflow;
  1996. /* The high 6 bits go into bits 17-12. The low 6 bits go into bits 5-0. */
  1997. mask = 0x3f03f;
  1998. insn = (insn & ~mask) | ((value & 0xfc0) << 12) | (value & 0x3f);
  1999. bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
  2000. return bfd_reloc_ok;
  2001. }
  2002. /* Handle an FRV ELF HI16 reloc. */
  2003. static bfd_reloc_status_type
  2004. elf32_frv_relocate_hi16 (bfd *input_bfd,
  2005. Elf_Internal_Rela *relhi,
  2006. bfd_byte *contents,
  2007. bfd_vma value)
  2008. {
  2009. bfd_vma insn;
  2010. insn = bfd_get_32 (input_bfd, contents + relhi->r_offset);
  2011. value += relhi->r_addend;
  2012. value = ((value >> 16) & 0xffff);
  2013. insn = (insn & 0xffff0000) | value;
  2014. if ((long) value > 0xffff || (long) value < -0x10000)
  2015. return bfd_reloc_overflow;
  2016. bfd_put_32 (input_bfd, insn, contents + relhi->r_offset);
  2017. return bfd_reloc_ok;
  2018. }
  2019. static bfd_reloc_status_type
  2020. elf32_frv_relocate_lo16 (bfd *input_bfd,
  2021. Elf_Internal_Rela *rello,
  2022. bfd_byte *contents,
  2023. bfd_vma value)
  2024. {
  2025. bfd_vma insn;
  2026. insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
  2027. value += rello->r_addend;
  2028. value = value & 0xffff;
  2029. insn = (insn & 0xffff0000) | value;
  2030. if ((long) value > 0xffff || (long) value < -0x10000)
  2031. return bfd_reloc_overflow;
  2032. bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
  2033. return bfd_reloc_ok;
  2034. }
  2035. /* Perform the relocation for the CALL label24 instruction. */
  2036. static bfd_reloc_status_type
  2037. elf32_frv_relocate_label24 (bfd *input_bfd,
  2038. asection *input_section,
  2039. Elf_Internal_Rela *rello,
  2040. bfd_byte *contents,
  2041. bfd_vma value)
  2042. {
  2043. bfd_vma insn;
  2044. bfd_vma label6;
  2045. bfd_vma label18;
  2046. /* The format for the call instruction is:
  2047. 0 000000 0001111 000000000000000000
  2048. label6 opcode label18
  2049. The branch calculation is: pc + (4*label24)
  2050. where label24 is the concatenation of label6 and label18. */
  2051. /* Grab the instruction. */
  2052. insn = bfd_get_32 (input_bfd, contents + rello->r_offset);
  2053. value -= input_section->output_section->vma + input_section->output_offset;
  2054. value -= rello->r_offset;
  2055. value += rello->r_addend;
  2056. value = value >> 2;
  2057. label6 = value & 0xfc0000;
  2058. label6 = label6 << 7;
  2059. label18 = value & 0x3ffff;
  2060. insn = insn & 0x803c0000;
  2061. insn = insn | label6;
  2062. insn = insn | label18;
  2063. bfd_put_32 (input_bfd, insn, contents + rello->r_offset);
  2064. return bfd_reloc_ok;
  2065. }
  2066. static bfd_reloc_status_type
  2067. elf32_frv_relocate_gprelhi (struct bfd_link_info *info,
  2068. bfd *input_bfd,
  2069. asection *input_section,
  2070. Elf_Internal_Rela *relocation,
  2071. bfd_byte *contents,
  2072. bfd_vma value)
  2073. {
  2074. bfd_vma insn;
  2075. bfd_vma gp;
  2076. struct bfd_link_hash_entry *h;
  2077. h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
  2078. gp = (h->u.def.value
  2079. + h->u.def.section->output_section->vma
  2080. + h->u.def.section->output_offset);
  2081. value -= input_section->output_section->vma;
  2082. value -= (gp - input_section->output_section->vma);
  2083. value += relocation->r_addend;
  2084. value = ((value >> 16) & 0xffff);
  2085. if ((long) value > 0xffff || (long) value < -0x10000)
  2086. return bfd_reloc_overflow;
  2087. insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
  2088. insn = (insn & 0xffff0000) | value;
  2089. bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
  2090. return bfd_reloc_ok;
  2091. }
  2092. static bfd_reloc_status_type
  2093. elf32_frv_relocate_gprello (struct bfd_link_info *info,
  2094. bfd *input_bfd,
  2095. asection *input_section,
  2096. Elf_Internal_Rela *relocation,
  2097. bfd_byte *contents,
  2098. bfd_vma value)
  2099. {
  2100. bfd_vma insn;
  2101. bfd_vma gp;
  2102. struct bfd_link_hash_entry *h;
  2103. h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true);
  2104. gp = (h->u.def.value
  2105. + h->u.def.section->output_section->vma
  2106. + h->u.def.section->output_offset);
  2107. value -= input_section->output_section->vma;
  2108. value -= (gp - input_section->output_section->vma);
  2109. value += relocation->r_addend;
  2110. value = value & 0xffff;
  2111. if ((long) value > 0xffff || (long) value < -0x10000)
  2112. return bfd_reloc_overflow;
  2113. insn = bfd_get_32 (input_bfd, contents + relocation->r_offset);
  2114. insn = (insn & 0xffff0000) | value;
  2115. bfd_put_32 (input_bfd, insn, contents + relocation->r_offset);
  2116. return bfd_reloc_ok;
  2117. }
  2118. static reloc_howto_type *
  2119. frv_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  2120. bfd_reloc_code_real_type code)
  2121. {
  2122. switch (code)
  2123. {
  2124. default:
  2125. break;
  2126. case BFD_RELOC_NONE:
  2127. return &elf32_frv_howto_table[ (int) R_FRV_NONE];
  2128. case BFD_RELOC_32:
  2129. if (elf_elfheader (abfd)->e_type == ET_EXEC
  2130. || elf_elfheader (abfd)->e_type == ET_DYN)
  2131. return &elf32_frv_rel_32_howto;
  2132. /* Fall through. */
  2133. case BFD_RELOC_CTOR:
  2134. return &elf32_frv_howto_table[ (int) R_FRV_32];
  2135. case BFD_RELOC_FRV_LABEL16:
  2136. return &elf32_frv_howto_table[ (int) R_FRV_LABEL16];
  2137. case BFD_RELOC_FRV_LABEL24:
  2138. return &elf32_frv_howto_table[ (int) R_FRV_LABEL24];
  2139. case BFD_RELOC_FRV_LO16:
  2140. return &elf32_frv_howto_table[ (int) R_FRV_LO16];
  2141. case BFD_RELOC_FRV_HI16:
  2142. return &elf32_frv_howto_table[ (int) R_FRV_HI16];
  2143. case BFD_RELOC_FRV_GPREL12:
  2144. return &elf32_frv_howto_table[ (int) R_FRV_GPREL12];
  2145. case BFD_RELOC_FRV_GPRELU12:
  2146. return &elf32_frv_howto_table[ (int) R_FRV_GPRELU12];
  2147. case BFD_RELOC_FRV_GPREL32:
  2148. return &elf32_frv_howto_table[ (int) R_FRV_GPREL32];
  2149. case BFD_RELOC_FRV_GPRELHI:
  2150. return &elf32_frv_howto_table[ (int) R_FRV_GPRELHI];
  2151. case BFD_RELOC_FRV_GPRELLO:
  2152. return &elf32_frv_howto_table[ (int) R_FRV_GPRELLO];
  2153. case BFD_RELOC_FRV_GOT12:
  2154. return &elf32_frv_howto_table[ (int) R_FRV_GOT12];
  2155. case BFD_RELOC_FRV_GOTHI:
  2156. return &elf32_frv_howto_table[ (int) R_FRV_GOTHI];
  2157. case BFD_RELOC_FRV_GOTLO:
  2158. return &elf32_frv_howto_table[ (int) R_FRV_GOTLO];
  2159. case BFD_RELOC_FRV_FUNCDESC:
  2160. if (elf_elfheader (abfd)->e_type == ET_EXEC
  2161. || elf_elfheader (abfd)->e_type == ET_DYN)
  2162. return &elf32_frv_rel_funcdesc_howto;
  2163. return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC];
  2164. case BFD_RELOC_FRV_FUNCDESC_GOT12:
  2165. return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOT12];
  2166. case BFD_RELOC_FRV_FUNCDESC_GOTHI:
  2167. return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTHI];
  2168. case BFD_RELOC_FRV_FUNCDESC_GOTLO:
  2169. return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTLO];
  2170. case BFD_RELOC_FRV_FUNCDESC_VALUE:
  2171. if (elf_elfheader (abfd)->e_type == ET_EXEC
  2172. || elf_elfheader (abfd)->e_type == ET_DYN)
  2173. return &elf32_frv_rel_funcdesc_value_howto;
  2174. return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_VALUE];
  2175. case BFD_RELOC_FRV_FUNCDESC_GOTOFF12:
  2176. return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFF12];
  2177. case BFD_RELOC_FRV_FUNCDESC_GOTOFFHI:
  2178. return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFHI];
  2179. case BFD_RELOC_FRV_FUNCDESC_GOTOFFLO:
  2180. return &elf32_frv_howto_table[ (int) R_FRV_FUNCDESC_GOTOFFLO];
  2181. case BFD_RELOC_FRV_GOTOFF12:
  2182. return &elf32_frv_howto_table[ (int) R_FRV_GOTOFF12];
  2183. case BFD_RELOC_FRV_GOTOFFHI:
  2184. return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFHI];
  2185. case BFD_RELOC_FRV_GOTOFFLO:
  2186. return &elf32_frv_howto_table[ (int) R_FRV_GOTOFFLO];
  2187. case BFD_RELOC_FRV_GETTLSOFF:
  2188. return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF];
  2189. case BFD_RELOC_FRV_TLSDESC_VALUE:
  2190. if (elf_elfheader (abfd)->e_type == ET_EXEC
  2191. || elf_elfheader (abfd)->e_type == ET_DYN)
  2192. return &elf32_frv_rel_tlsdesc_value_howto;
  2193. return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_VALUE];
  2194. case BFD_RELOC_FRV_GOTTLSDESC12:
  2195. return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESC12];
  2196. case BFD_RELOC_FRV_GOTTLSDESCHI:
  2197. return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCHI];
  2198. case BFD_RELOC_FRV_GOTTLSDESCLO:
  2199. return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSDESCLO];
  2200. case BFD_RELOC_FRV_TLSMOFF12:
  2201. return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF12];
  2202. case BFD_RELOC_FRV_TLSMOFFHI:
  2203. return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFHI];
  2204. case BFD_RELOC_FRV_TLSMOFFLO:
  2205. return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFFLO];
  2206. case BFD_RELOC_FRV_GOTTLSOFF12:
  2207. return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFF12];
  2208. case BFD_RELOC_FRV_GOTTLSOFFHI:
  2209. return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFHI];
  2210. case BFD_RELOC_FRV_GOTTLSOFFLO:
  2211. return &elf32_frv_howto_table[ (int) R_FRV_GOTTLSOFFLO];
  2212. case BFD_RELOC_FRV_TLSOFF:
  2213. if (elf_elfheader (abfd)->e_type == ET_EXEC
  2214. || elf_elfheader (abfd)->e_type == ET_DYN)
  2215. return &elf32_frv_rel_tlsoff_howto;
  2216. return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF];
  2217. case BFD_RELOC_FRV_TLSDESC_RELAX:
  2218. return &elf32_frv_howto_table[ (int) R_FRV_TLSDESC_RELAX];
  2219. case BFD_RELOC_FRV_GETTLSOFF_RELAX:
  2220. return &elf32_frv_howto_table[ (int) R_FRV_GETTLSOFF_RELAX];
  2221. case BFD_RELOC_FRV_TLSOFF_RELAX:
  2222. return &elf32_frv_howto_table[ (int) R_FRV_TLSOFF_RELAX];
  2223. case BFD_RELOC_FRV_TLSMOFF:
  2224. return &elf32_frv_howto_table[ (int) R_FRV_TLSMOFF];
  2225. case BFD_RELOC_VTABLE_INHERIT:
  2226. return &elf32_frv_vtinherit_howto;
  2227. case BFD_RELOC_VTABLE_ENTRY:
  2228. return &elf32_frv_vtentry_howto;
  2229. }
  2230. return NULL;
  2231. }
  2232. static reloc_howto_type *
  2233. frv_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
  2234. {
  2235. unsigned int i;
  2236. for (i = 0;
  2237. i < sizeof (elf32_frv_howto_table) / sizeof (elf32_frv_howto_table[0]);
  2238. i++)
  2239. if (elf32_frv_howto_table[i].name != NULL
  2240. && strcasecmp (elf32_frv_howto_table[i].name, r_name) == 0)
  2241. return &elf32_frv_howto_table[i];
  2242. if (strcasecmp (elf32_frv_vtinherit_howto.name, r_name) == 0)
  2243. return &elf32_frv_vtinherit_howto;
  2244. if (strcasecmp (elf32_frv_vtentry_howto.name, r_name) == 0)
  2245. return &elf32_frv_vtentry_howto;
  2246. return NULL;
  2247. }
  2248. /* Set the howto pointer for an FRV ELF reloc. */
  2249. static bool
  2250. frv_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
  2251. arelent *cache_ptr,
  2252. Elf_Internal_Rela *dst)
  2253. {
  2254. unsigned int r_type;
  2255. r_type = ELF32_R_TYPE (dst->r_info);
  2256. switch (r_type)
  2257. {
  2258. case R_FRV_GNU_VTINHERIT:
  2259. cache_ptr->howto = &elf32_frv_vtinherit_howto;
  2260. break;
  2261. case R_FRV_GNU_VTENTRY:
  2262. cache_ptr->howto = &elf32_frv_vtentry_howto;
  2263. break;
  2264. default:
  2265. if (r_type >= ARRAY_SIZE (elf32_frv_howto_table))
  2266. {
  2267. /* xgettext:c-format */
  2268. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  2269. abfd, r_type);
  2270. bfd_set_error (bfd_error_bad_value);
  2271. return false;
  2272. }
  2273. cache_ptr->howto = & elf32_frv_howto_table [r_type];
  2274. break;
  2275. }
  2276. return true;
  2277. }
  2278. /* Set the howto pointer for an FRV ELF REL reloc. */
  2279. static bool
  2280. frvfdpic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
  2281. arelent *cache_ptr, Elf_Internal_Rela *dst)
  2282. {
  2283. unsigned int r_type;
  2284. r_type = ELF32_R_TYPE (dst->r_info);
  2285. switch (r_type)
  2286. {
  2287. case R_FRV_32:
  2288. cache_ptr->howto = &elf32_frv_rel_32_howto;
  2289. break;
  2290. case R_FRV_FUNCDESC:
  2291. cache_ptr->howto = &elf32_frv_rel_funcdesc_howto;
  2292. break;
  2293. case R_FRV_FUNCDESC_VALUE:
  2294. cache_ptr->howto = &elf32_frv_rel_funcdesc_value_howto;
  2295. break;
  2296. case R_FRV_TLSDESC_VALUE:
  2297. cache_ptr->howto = &elf32_frv_rel_tlsdesc_value_howto;
  2298. break;
  2299. case R_FRV_TLSOFF:
  2300. cache_ptr->howto = &elf32_frv_rel_tlsoff_howto;
  2301. break;
  2302. default:
  2303. cache_ptr->howto = NULL;
  2304. return false;
  2305. }
  2306. return true;
  2307. }
  2308. /* Perform a single relocation. By default we use the standard BFD
  2309. routines, but a few relocs, we have to do them ourselves. */
  2310. static bfd_reloc_status_type
  2311. frv_final_link_relocate (reloc_howto_type *howto,
  2312. bfd *input_bfd,
  2313. asection *input_section,
  2314. bfd_byte *contents,
  2315. Elf_Internal_Rela *rel,
  2316. bfd_vma relocation)
  2317. {
  2318. return _bfd_final_link_relocate (howto, input_bfd, input_section,
  2319. contents, rel->r_offset, relocation,
  2320. rel->r_addend);
  2321. }
  2322. /* Relocate an FRV ELF section.
  2323. The RELOCATE_SECTION function is called by the new ELF backend linker
  2324. to handle the relocations for a section.
  2325. The relocs are always passed as Rela structures; if the section
  2326. actually uses Rel structures, the r_addend field will always be
  2327. zero.
  2328. This function is responsible for adjusting the section contents as
  2329. necessary, and (if using Rela relocs and generating a relocatable
  2330. output file) adjusting the reloc addend as necessary.
  2331. This function does not have to worry about setting the reloc
  2332. address or the reloc symbol index.
  2333. LOCAL_SYMS is a pointer to the swapped in local symbols.
  2334. LOCAL_SECTIONS is an array giving the section in the input file
  2335. corresponding to the st_shndx field of each local symbol.
  2336. The global hash table entry for the global symbols can be found
  2337. via elf_sym_hashes (input_bfd).
  2338. When generating relocatable output, this function must handle
  2339. STB_LOCAL/STT_SECTION symbols specially. The output symbol is
  2340. going to be the section symbol corresponding to the output
  2341. section, which means that the addend must be adjusted
  2342. accordingly. */
  2343. static int
  2344. elf32_frv_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
  2345. struct bfd_link_info *info,
  2346. bfd *input_bfd,
  2347. asection *input_section,
  2348. bfd_byte *contents,
  2349. Elf_Internal_Rela *relocs,
  2350. Elf_Internal_Sym *local_syms,
  2351. asection **local_sections)
  2352. {
  2353. Elf_Internal_Shdr *symtab_hdr;
  2354. struct elf_link_hash_entry **sym_hashes;
  2355. Elf_Internal_Rela *rel;
  2356. Elf_Internal_Rela *relend;
  2357. unsigned isec_segment, got_segment, plt_segment, gprel_segment, tls_segment,
  2358. check_segment[2];
  2359. int silence_segment_error = !bfd_link_pic (info);
  2360. unsigned long insn;
  2361. symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
  2362. sym_hashes = elf_sym_hashes (input_bfd);
  2363. relend = relocs + input_section->reloc_count;
  2364. isec_segment = _frvfdpic_osec_to_segment (output_bfd,
  2365. input_section->output_section);
  2366. if (IS_FDPIC (output_bfd) && frvfdpic_got_section (info))
  2367. got_segment = _frvfdpic_osec_to_segment (output_bfd,
  2368. frvfdpic_got_section (info)
  2369. ->output_section);
  2370. else
  2371. got_segment = -1;
  2372. if (IS_FDPIC (output_bfd) && frvfdpic_gotfixup_section (info))
  2373. gprel_segment = _frvfdpic_osec_to_segment (output_bfd,
  2374. frvfdpic_gotfixup_section (info)
  2375. ->output_section);
  2376. else
  2377. gprel_segment = -1;
  2378. if (IS_FDPIC (output_bfd) && frvfdpic_plt_section (info))
  2379. plt_segment = _frvfdpic_osec_to_segment (output_bfd,
  2380. frvfdpic_plt_section (info)
  2381. ->output_section);
  2382. else
  2383. plt_segment = -1;
  2384. if (elf_hash_table (info)->tls_sec)
  2385. tls_segment = _frvfdpic_osec_to_segment (output_bfd,
  2386. elf_hash_table (info)->tls_sec);
  2387. else
  2388. tls_segment = -1;
  2389. for (rel = relocs; rel < relend; rel ++)
  2390. {
  2391. reloc_howto_type *howto;
  2392. unsigned long r_symndx;
  2393. Elf_Internal_Sym *sym;
  2394. asection *sec;
  2395. struct elf_link_hash_entry *h;
  2396. bfd_vma relocation;
  2397. bfd_reloc_status_type r;
  2398. const char *name;
  2399. int r_type;
  2400. asection *osec;
  2401. struct frvfdpic_relocs_info *picrel = NULL;
  2402. bfd_vma orig_addend = rel->r_addend;
  2403. r_type = ELF32_R_TYPE (rel->r_info);
  2404. if ( r_type == R_FRV_GNU_VTINHERIT
  2405. || r_type == R_FRV_GNU_VTENTRY)
  2406. continue;
  2407. r_symndx = ELF32_R_SYM (rel->r_info);
  2408. howto = elf32_frv_howto_table + ELF32_R_TYPE (rel->r_info);
  2409. h = NULL;
  2410. sym = NULL;
  2411. sec = NULL;
  2412. if (r_symndx < symtab_hdr->sh_info)
  2413. {
  2414. sym = local_syms + r_symndx;
  2415. osec = sec = local_sections [r_symndx];
  2416. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  2417. name = bfd_elf_string_from_elf_section
  2418. (input_bfd, symtab_hdr->sh_link, sym->st_name);
  2419. if (name == NULL || name[0] == 0)
  2420. name = bfd_section_name (sec);
  2421. }
  2422. else
  2423. {
  2424. bool warned, ignored;
  2425. bool unresolved_reloc;
  2426. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  2427. r_symndx, symtab_hdr, sym_hashes,
  2428. h, sec, relocation,
  2429. unresolved_reloc, warned, ignored);
  2430. osec = sec;
  2431. name = h->root.root.string;
  2432. }
  2433. if (sec != NULL && discarded_section (sec))
  2434. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  2435. rel, 1, relend, howto, 0, contents);
  2436. if (bfd_link_relocatable (info))
  2437. continue;
  2438. if (r_type != R_FRV_TLSMOFF
  2439. && h != NULL
  2440. && (h->root.type == bfd_link_hash_defined
  2441. || h->root.type == bfd_link_hash_defweak)
  2442. && !FRVFDPIC_SYM_LOCAL (info, h))
  2443. {
  2444. osec = sec = NULL;
  2445. relocation = 0;
  2446. }
  2447. switch (r_type)
  2448. {
  2449. case R_FRV_LABEL24:
  2450. case R_FRV_32:
  2451. if (! IS_FDPIC (output_bfd))
  2452. goto non_fdpic;
  2453. /* Fall through. */
  2454. case R_FRV_GOT12:
  2455. case R_FRV_GOTHI:
  2456. case R_FRV_GOTLO:
  2457. case R_FRV_FUNCDESC_GOT12:
  2458. case R_FRV_FUNCDESC_GOTHI:
  2459. case R_FRV_FUNCDESC_GOTLO:
  2460. case R_FRV_GOTOFF12:
  2461. case R_FRV_GOTOFFHI:
  2462. case R_FRV_GOTOFFLO:
  2463. case R_FRV_FUNCDESC_GOTOFF12:
  2464. case R_FRV_FUNCDESC_GOTOFFHI:
  2465. case R_FRV_FUNCDESC_GOTOFFLO:
  2466. case R_FRV_FUNCDESC:
  2467. case R_FRV_FUNCDESC_VALUE:
  2468. case R_FRV_GETTLSOFF:
  2469. case R_FRV_TLSDESC_VALUE:
  2470. case R_FRV_GOTTLSDESC12:
  2471. case R_FRV_GOTTLSDESCHI:
  2472. case R_FRV_GOTTLSDESCLO:
  2473. case R_FRV_TLSMOFF12:
  2474. case R_FRV_TLSMOFFHI:
  2475. case R_FRV_TLSMOFFLO:
  2476. case R_FRV_GOTTLSOFF12:
  2477. case R_FRV_GOTTLSOFFHI:
  2478. case R_FRV_GOTTLSOFFLO:
  2479. case R_FRV_TLSOFF:
  2480. case R_FRV_TLSDESC_RELAX:
  2481. case R_FRV_GETTLSOFF_RELAX:
  2482. case R_FRV_TLSOFF_RELAX:
  2483. case R_FRV_TLSMOFF:
  2484. if ((input_section->flags & SEC_ALLOC) == 0)
  2485. break;
  2486. if (h != NULL)
  2487. picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info
  2488. (info), input_bfd, h,
  2489. orig_addend, INSERT);
  2490. else
  2491. /* In order to find the entry we created before, we must
  2492. use the original addend, not the one that may have been
  2493. modified by _bfd_elf_rela_local_sym(). */
  2494. picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
  2495. (info), input_bfd, r_symndx,
  2496. orig_addend, INSERT);
  2497. if (! picrel)
  2498. return false;
  2499. if (!_frvfdpic_emit_got_relocs_plt_entries (picrel, output_bfd, info,
  2500. osec, sym,
  2501. rel->r_addend))
  2502. {
  2503. info->callbacks->einfo
  2504. /* xgettext:c-format */
  2505. (_("%H: relocation to `%s+%v'"
  2506. " may have caused the error above\n"),
  2507. input_bfd, input_section, rel->r_offset, name, rel->r_addend);
  2508. return false;
  2509. }
  2510. break;
  2511. default:
  2512. non_fdpic:
  2513. picrel = NULL;
  2514. if (h
  2515. && ! FRVFDPIC_SYM_LOCAL (info, h)
  2516. && _bfd_elf_section_offset (output_bfd, info, input_section,
  2517. rel->r_offset) != (bfd_vma) -1)
  2518. {
  2519. info->callbacks->einfo
  2520. (_("%H: relocation references symbol"
  2521. " not defined in the module\n"),
  2522. input_bfd, input_section, rel->r_offset);
  2523. return false;
  2524. }
  2525. break;
  2526. }
  2527. switch (r_type)
  2528. {
  2529. case R_FRV_GETTLSOFF:
  2530. case R_FRV_TLSDESC_VALUE:
  2531. case R_FRV_GOTTLSDESC12:
  2532. case R_FRV_GOTTLSDESCHI:
  2533. case R_FRV_GOTTLSDESCLO:
  2534. case R_FRV_TLSMOFF12:
  2535. case R_FRV_TLSMOFFHI:
  2536. case R_FRV_TLSMOFFLO:
  2537. case R_FRV_GOTTLSOFF12:
  2538. case R_FRV_GOTTLSOFFHI:
  2539. case R_FRV_GOTTLSOFFLO:
  2540. case R_FRV_TLSOFF:
  2541. case R_FRV_TLSDESC_RELAX:
  2542. case R_FRV_GETTLSOFF_RELAX:
  2543. case R_FRV_TLSOFF_RELAX:
  2544. case R_FRV_TLSMOFF:
  2545. if (sec && (bfd_is_abs_section (sec) || bfd_is_und_section (sec)))
  2546. relocation += tls_biased_base (info);
  2547. break;
  2548. default:
  2549. break;
  2550. }
  2551. /* Try to apply TLS relaxations. */
  2552. if (1)
  2553. switch (r_type)
  2554. {
  2555. #define LOCAL_EXEC_P(info, picrel) \
  2556. (bfd_link_executable (info) \
  2557. && (picrel->symndx != -1 || FRVFDPIC_SYM_LOCAL ((info), (picrel)->d.h)))
  2558. #define INITIAL_EXEC_P(info, picrel) \
  2559. ((bfd_link_executable (info)|| (info)->flags & DF_STATIC_TLS) \
  2560. && (picrel)->tlsoff_entry)
  2561. #define IN_RANGE_FOR_OFST12_P(value) \
  2562. ((bfd_vma)((value) + 2048) < (bfd_vma)4096)
  2563. #define IN_RANGE_FOR_SETLOS_P(value) \
  2564. ((bfd_vma)((value) + 32768) < (bfd_vma)65536)
  2565. #define TLSMOFF_IN_RANGE_FOR_SETLOS_P(value, info) \
  2566. (IN_RANGE_FOR_SETLOS_P ((value) - tls_biased_base (info)))
  2567. #define RELAX_GETTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
  2568. (LOCAL_EXEC_P ((info), (picrel)) \
  2569. && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
  2570. #define RELAX_GETTLSOFF_INITIAL_EXEC_P(info, picrel) \
  2571. (INITIAL_EXEC_P ((info), (picrel)) \
  2572. && IN_RANGE_FOR_OFST12_P ((picrel)->tlsoff_entry))
  2573. #define RELAX_TLSDESC_LOCAL_EXEC_P(info, picrel, value) \
  2574. (LOCAL_EXEC_P ((info), (picrel)))
  2575. #define RELAX_TLSDESC_INITIAL_EXEC_P(info, picrel) \
  2576. (INITIAL_EXEC_P ((info), (picrel)))
  2577. #define RELAX_GOTTLSOFF_LOCAL_EXEC_P(info, picrel, value) \
  2578. (LOCAL_EXEC_P ((info), (picrel)) \
  2579. && TLSMOFF_IN_RANGE_FOR_SETLOS_P((value), (info)))
  2580. case R_FRV_GETTLSOFF:
  2581. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2582. /* Is this a call instruction? */
  2583. if ((insn & (unsigned long)0x01fc0000) != 0x003c0000)
  2584. {
  2585. info->callbacks->einfo
  2586. (_("%H: R_FRV_GETTLSOFF not applied to a call instruction\n"),
  2587. input_bfd, input_section, rel->r_offset);
  2588. return false;
  2589. }
  2590. if (RELAX_GETTLSOFF_LOCAL_EXEC_P (info, picrel,
  2591. relocation + rel->r_addend))
  2592. {
  2593. /* Replace the call instruction (except the packing bit)
  2594. with setlos #tlsmofflo(symbol+offset), gr9. */
  2595. insn &= (unsigned long)0x80000000;
  2596. insn |= (unsigned long)0x12fc0000;
  2597. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2598. r_type = R_FRV_TLSMOFFLO;
  2599. howto = elf32_frv_howto_table + r_type;
  2600. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2601. }
  2602. else if (RELAX_GETTLSOFF_INITIAL_EXEC_P (info, picrel))
  2603. {
  2604. /* Replace the call instruction (except the packing bit)
  2605. with ldi @(gr15, #gottlsoff12(symbol+addend)), gr9. */
  2606. insn &= (unsigned long)0x80000000;
  2607. insn |= (unsigned long)0x12c8f000;
  2608. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2609. r_type = R_FRV_GOTTLSOFF12;
  2610. howto = elf32_frv_howto_table + r_type;
  2611. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2612. }
  2613. break;
  2614. case R_FRV_GOTTLSDESC12:
  2615. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2616. /* Is this an lddi instruction? */
  2617. if ((insn & (unsigned long)0x01fc0000) != 0x00cc0000)
  2618. {
  2619. info->callbacks->einfo
  2620. (_("%H: R_FRV_GOTTLSDESC12"
  2621. " not applied to an lddi instruction\n"),
  2622. input_bfd, input_section, rel->r_offset);
  2623. return false;
  2624. }
  2625. if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
  2626. relocation + rel->r_addend)
  2627. && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
  2628. info))
  2629. {
  2630. /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
  2631. with setlos #tlsmofflo(symbol+offset), gr<C+1>.
  2632. Preserve the packing bit. */
  2633. insn = (insn & (unsigned long)0x80000000)
  2634. | ((insn + (unsigned long)0x02000000)
  2635. & (unsigned long)0x7e000000);
  2636. insn |= (unsigned long)0x00fc0000;
  2637. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2638. r_type = R_FRV_TLSMOFFLO;
  2639. howto = elf32_frv_howto_table + r_type;
  2640. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2641. }
  2642. else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
  2643. relocation + rel->r_addend))
  2644. {
  2645. /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
  2646. with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
  2647. Preserve the packing bit. */
  2648. insn = (insn & (unsigned long)0x80000000)
  2649. | ((insn + (unsigned long)0x02000000)
  2650. & (unsigned long)0x7e000000);
  2651. insn |= (unsigned long)0x00f80000;
  2652. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2653. r_type = R_FRV_TLSMOFFHI;
  2654. howto = elf32_frv_howto_table + r_type;
  2655. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2656. }
  2657. else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
  2658. {
  2659. /* Replace lddi @(grB, #gottlsdesc12(symbol+offset), grC
  2660. with ldi @(grB, #gottlsoff12(symbol+offset),
  2661. gr<C+1>. Preserve the packing bit. If gottlsoff12
  2662. overflows, we'll error out, but that's sort-of ok,
  2663. since we'd started with gottlsdesc12, that's actually
  2664. more demanding. Compiling with -fPIE instead of
  2665. -fpie would fix it; linking with --relax should fix
  2666. it as well. */
  2667. insn = (insn & (unsigned long)0x80cbf000)
  2668. | ((insn + (unsigned long)0x02000000)
  2669. & (unsigned long)0x7e000000);
  2670. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2671. r_type = R_FRV_GOTTLSOFF12;
  2672. howto = elf32_frv_howto_table + r_type;
  2673. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2674. }
  2675. break;
  2676. case R_FRV_GOTTLSDESCHI:
  2677. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2678. /* Is this a sethi instruction? */
  2679. if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
  2680. {
  2681. info->callbacks->einfo
  2682. (_("%H: R_FRV_GOTTLSDESCHI"
  2683. " not applied to a sethi instruction\n"),
  2684. input_bfd, input_section, rel->r_offset);
  2685. return false;
  2686. }
  2687. if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
  2688. relocation + rel->r_addend)
  2689. || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
  2690. && IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry)))
  2691. {
  2692. /* Replace sethi with a nop. Preserve the packing bit. */
  2693. insn &= (unsigned long)0x80000000;
  2694. insn |= (unsigned long)0x00880000;
  2695. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2696. /* Nothing to relocate. */
  2697. continue;
  2698. }
  2699. else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
  2700. {
  2701. /* Simply decay GOTTLSDESC to GOTTLSOFF. */
  2702. r_type = R_FRV_GOTTLSOFFHI;
  2703. howto = elf32_frv_howto_table + r_type;
  2704. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2705. }
  2706. break;
  2707. case R_FRV_GOTTLSDESCLO:
  2708. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2709. /* Is this a setlo or setlos instruction? */
  2710. if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
  2711. {
  2712. info->callbacks->einfo
  2713. (_("%H: R_FRV_GOTTLSDESCLO"
  2714. " not applied to a setlo or setlos instruction\n"),
  2715. input_bfd, input_section, rel->r_offset);
  2716. return false;
  2717. }
  2718. if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
  2719. relocation + rel->r_addend)
  2720. || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
  2721. && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
  2722. {
  2723. /* Replace setlo/setlos with a nop. Preserve the
  2724. packing bit. */
  2725. insn &= (unsigned long)0x80000000;
  2726. insn |= (unsigned long)0x00880000;
  2727. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2728. /* Nothing to relocate. */
  2729. continue;
  2730. }
  2731. else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
  2732. {
  2733. /* If the corresponding sethi (if it exists) decayed
  2734. to a nop, make sure this becomes (or already is) a
  2735. setlos, not setlo. */
  2736. if (IN_RANGE_FOR_SETLOS_P (picrel->tlsoff_entry))
  2737. {
  2738. insn |= (unsigned long)0x00080000;
  2739. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2740. }
  2741. /* Simply decay GOTTLSDESC to GOTTLSOFF. */
  2742. r_type = R_FRV_GOTTLSOFFLO;
  2743. howto = elf32_frv_howto_table + r_type;
  2744. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2745. }
  2746. break;
  2747. case R_FRV_TLSDESC_RELAX:
  2748. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2749. /* Is this an ldd instruction? */
  2750. if ((insn & (unsigned long)0x01fc0fc0) != 0x00080140)
  2751. {
  2752. info->callbacks->einfo
  2753. (_("%H: R_FRV_TLSDESC_RELAX"
  2754. " not applied to an ldd instruction\n"),
  2755. input_bfd, input_section, rel->r_offset);
  2756. return false;
  2757. }
  2758. if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
  2759. relocation + rel->r_addend)
  2760. && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
  2761. info))
  2762. {
  2763. /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
  2764. with setlos #tlsmofflo(symbol+offset), gr<C+1>.
  2765. Preserve the packing bit. */
  2766. insn = (insn & (unsigned long)0x80000000)
  2767. | ((insn + (unsigned long)0x02000000)
  2768. & (unsigned long)0x7e000000);
  2769. insn |= (unsigned long)0x00fc0000;
  2770. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2771. r_type = R_FRV_TLSMOFFLO;
  2772. howto = elf32_frv_howto_table + r_type;
  2773. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2774. }
  2775. else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
  2776. relocation + rel->r_addend))
  2777. {
  2778. /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
  2779. with sethi #tlsmoffhi(symbol+offset), gr<C+1>.
  2780. Preserve the packing bit. */
  2781. insn = (insn & (unsigned long)0x80000000)
  2782. | ((insn + (unsigned long)0x02000000)
  2783. & (unsigned long)0x7e000000);
  2784. insn |= (unsigned long)0x00f80000;
  2785. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2786. r_type = R_FRV_TLSMOFFHI;
  2787. howto = elf32_frv_howto_table + r_type;
  2788. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2789. }
  2790. else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
  2791. && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
  2792. {
  2793. /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
  2794. with ldi @(grB, #gottlsoff12(symbol+offset), gr<C+1>.
  2795. Preserve the packing bit. */
  2796. insn = (insn & (unsigned long)0x8003f000)
  2797. | (unsigned long)0x00c80000
  2798. | ((insn + (unsigned long)0x02000000)
  2799. & (unsigned long)0x7e000000);
  2800. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2801. r_type = R_FRV_GOTTLSOFF12;
  2802. howto = elf32_frv_howto_table + r_type;
  2803. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2804. }
  2805. else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
  2806. {
  2807. /* Replace ldd #tlsdesc(symbol+offset)@(grB, grA), grC
  2808. with ld #tlsoff(symbol+offset)@(grB, grA), gr<C+1>.
  2809. Preserve the packing bit. */
  2810. insn = (insn & (unsigned long)0x81ffffbf)
  2811. | ((insn + (unsigned long)0x02000000)
  2812. & (unsigned long)0x7e000000);
  2813. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2814. /* #tlsoff(symbol+offset) is just a relaxation
  2815. annotation, so there's nothing left to
  2816. relocate. */
  2817. continue;
  2818. }
  2819. break;
  2820. case R_FRV_GETTLSOFF_RELAX:
  2821. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2822. /* Is this a calll or callil instruction? */
  2823. if ((insn & (unsigned long)0x7ff80fc0) != 0x02300000)
  2824. {
  2825. info->callbacks->einfo
  2826. (_("%H: R_FRV_GETTLSOFF_RELAX"
  2827. " not applied to a calll instruction\n"),
  2828. input_bfd, input_section, rel->r_offset);
  2829. return false;
  2830. }
  2831. if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
  2832. relocation + rel->r_addend)
  2833. && TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
  2834. info))
  2835. {
  2836. /* Replace calll with a nop. Preserve the packing bit. */
  2837. insn &= (unsigned long)0x80000000;
  2838. insn |= (unsigned long)0x00880000;
  2839. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2840. /* Nothing to relocate. */
  2841. continue;
  2842. }
  2843. else if (RELAX_TLSDESC_LOCAL_EXEC_P (info, picrel,
  2844. relocation + rel->r_addend))
  2845. {
  2846. /* Replace calll with setlo #tlsmofflo(symbol+offset), gr9.
  2847. Preserve the packing bit. */
  2848. insn &= (unsigned long)0x80000000;
  2849. insn |= (unsigned long)0x12f40000;
  2850. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2851. r_type = R_FRV_TLSMOFFLO;
  2852. howto = elf32_frv_howto_table + r_type;
  2853. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2854. }
  2855. else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel))
  2856. {
  2857. /* Replace calll with a nop. Preserve the packing bit. */
  2858. insn &= (unsigned long)0x80000000;
  2859. insn |= (unsigned long)0x00880000;
  2860. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2861. /* Nothing to relocate. */
  2862. continue;
  2863. }
  2864. break;
  2865. case R_FRV_GOTTLSOFF12:
  2866. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2867. /* Is this an ldi instruction? */
  2868. if ((insn & (unsigned long)0x01fc0000) != 0x00c80000)
  2869. {
  2870. info->callbacks->einfo
  2871. (_("%H: R_FRV_GOTTLSOFF12"
  2872. " not applied to an ldi instruction\n"),
  2873. input_bfd, input_section, rel->r_offset);
  2874. return false;
  2875. }
  2876. if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
  2877. relocation + rel->r_addend))
  2878. {
  2879. /* Replace ldi @(grB, #gottlsoff12(symbol+offset), grC
  2880. with setlos #tlsmofflo(symbol+offset), grC.
  2881. Preserve the packing bit. */
  2882. insn &= (unsigned long)0xfe000000;
  2883. insn |= (unsigned long)0x00fc0000;
  2884. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2885. r_type = R_FRV_TLSMOFFLO;
  2886. howto = elf32_frv_howto_table + r_type;
  2887. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2888. }
  2889. break;
  2890. case R_FRV_GOTTLSOFFHI:
  2891. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2892. /* Is this a sethi instruction? */
  2893. if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
  2894. {
  2895. info->callbacks->einfo
  2896. (_("%H: R_FRV_GOTTLSOFFHI"
  2897. " not applied to a sethi instruction\n"),
  2898. input_bfd, input_section, rel->r_offset);
  2899. return false;
  2900. }
  2901. if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
  2902. relocation + rel->r_addend)
  2903. || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
  2904. && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
  2905. {
  2906. /* Replace sethi with a nop. Preserve the packing bit. */
  2907. insn &= (unsigned long)0x80000000;
  2908. insn |= (unsigned long)0x00880000;
  2909. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2910. /* Nothing to relocate. */
  2911. continue;
  2912. }
  2913. break;
  2914. case R_FRV_GOTTLSOFFLO:
  2915. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2916. /* Is this a setlo or setlos instruction? */
  2917. if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
  2918. {
  2919. info->callbacks->einfo
  2920. (_("%H: R_FRV_GOTTLSOFFLO"
  2921. " not applied to a setlo or setlos instruction\n"),
  2922. input_bfd, input_section, rel->r_offset);
  2923. return false;
  2924. }
  2925. if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
  2926. relocation + rel->r_addend)
  2927. || (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
  2928. && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry)))
  2929. {
  2930. /* Replace setlo/setlos with a nop. Preserve the
  2931. packing bit. */
  2932. insn &= (unsigned long)0x80000000;
  2933. insn |= (unsigned long)0x00880000;
  2934. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2935. /* Nothing to relocate. */
  2936. continue;
  2937. }
  2938. break;
  2939. case R_FRV_TLSOFF_RELAX:
  2940. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2941. /* Is this an ld instruction? */
  2942. if ((insn & (unsigned long)0x01fc0fc0) != 0x00080100)
  2943. {
  2944. info->callbacks->einfo
  2945. (_("%H: R_FRV_TLSOFF_RELAX"
  2946. " not applied to an ld instruction\n"),
  2947. input_bfd, input_section, rel->r_offset);
  2948. return false;
  2949. }
  2950. if (RELAX_GOTTLSOFF_LOCAL_EXEC_P (info, picrel,
  2951. relocation + rel->r_addend))
  2952. {
  2953. /* Replace ld #gottlsoff(symbol+offset)@(grB, grA), grC
  2954. with setlos #tlsmofflo(symbol+offset), grC.
  2955. Preserve the packing bit. */
  2956. insn &= (unsigned long)0xfe000000;
  2957. insn |= (unsigned long)0x00fc0000;
  2958. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2959. r_type = R_FRV_TLSMOFFLO;
  2960. howto = elf32_frv_howto_table + r_type;
  2961. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2962. }
  2963. else if (RELAX_TLSDESC_INITIAL_EXEC_P (info, picrel)
  2964. && IN_RANGE_FOR_OFST12_P (picrel->tlsoff_entry))
  2965. {
  2966. /* Replace ld #tlsoff(symbol+offset)@(grB, grA), grC
  2967. with ldi @(grB, #gottlsoff12(symbol+offset), grC.
  2968. Preserve the packing bit. */
  2969. insn = (insn & (unsigned long)0xfe03f000)
  2970. | (unsigned long)0x00c80000;
  2971. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2972. r_type = R_FRV_GOTTLSOFF12;
  2973. howto = elf32_frv_howto_table + r_type;
  2974. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  2975. }
  2976. break;
  2977. case R_FRV_TLSMOFFHI:
  2978. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  2979. /* Is this a sethi instruction? */
  2980. if ((insn & (unsigned long)0x01ff0000) != 0x00f80000)
  2981. {
  2982. info->callbacks->einfo
  2983. (_("%H: R_FRV_TLSMOFFHI"
  2984. " not applied to a sethi instruction\n"),
  2985. input_bfd, input_section, rel->r_offset);
  2986. return false;
  2987. }
  2988. if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
  2989. info))
  2990. {
  2991. /* Replace sethi with a nop. Preserve the packing bit. */
  2992. insn &= (unsigned long)0x80000000;
  2993. insn |= (unsigned long)0x00880000;
  2994. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  2995. /* Nothing to relocate. */
  2996. continue;
  2997. }
  2998. break;
  2999. case R_FRV_TLSMOFFLO:
  3000. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  3001. /* Is this a setlo or setlos instruction? */
  3002. if ((insn & (unsigned long)0x01f70000) != 0x00f40000)
  3003. {
  3004. info->callbacks->einfo
  3005. (_("R_FRV_TLSMOFFLO"
  3006. " not applied to a setlo or setlos instruction\n"),
  3007. input_bfd, input_section, rel->r_offset);
  3008. return false;
  3009. }
  3010. if (TLSMOFF_IN_RANGE_FOR_SETLOS_P (relocation + rel->r_addend,
  3011. info))
  3012. /* If the corresponding sethi (if it exists) decayed
  3013. to a nop, make sure this becomes (or already is) a
  3014. setlos, not setlo. */
  3015. {
  3016. insn |= (unsigned long)0x00080000;
  3017. bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
  3018. }
  3019. break;
  3020. /*
  3021. There's nothing to relax in these:
  3022. R_FRV_TLSDESC_VALUE
  3023. R_FRV_TLSOFF
  3024. R_FRV_TLSMOFF12
  3025. R_FRV_TLSMOFFHI
  3026. R_FRV_TLSMOFFLO
  3027. R_FRV_TLSMOFF
  3028. */
  3029. default:
  3030. break;
  3031. }
  3032. switch (r_type)
  3033. {
  3034. case R_FRV_LABEL24:
  3035. check_segment[0] = isec_segment;
  3036. if (! IS_FDPIC (output_bfd))
  3037. check_segment[1] = isec_segment;
  3038. else if (picrel->plt)
  3039. {
  3040. relocation = frvfdpic_plt_section (info)->output_section->vma
  3041. + frvfdpic_plt_section (info)->output_offset
  3042. + picrel->plt_entry;
  3043. check_segment[1] = plt_segment;
  3044. }
  3045. /* We don't want to warn on calls to undefined weak symbols,
  3046. as calls to them must be protected by non-NULL tests
  3047. anyway, and unprotected calls would invoke undefined
  3048. behavior. */
  3049. else if (picrel->symndx == -1
  3050. && picrel->d.h->root.type == bfd_link_hash_undefweak)
  3051. check_segment[1] = check_segment[0];
  3052. else
  3053. check_segment[1] = sec
  3054. ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
  3055. : (unsigned)-1;
  3056. break;
  3057. case R_FRV_GOT12:
  3058. case R_FRV_GOTHI:
  3059. case R_FRV_GOTLO:
  3060. relocation = picrel->got_entry;
  3061. check_segment[0] = check_segment[1] = got_segment;
  3062. break;
  3063. case R_FRV_FUNCDESC_GOT12:
  3064. case R_FRV_FUNCDESC_GOTHI:
  3065. case R_FRV_FUNCDESC_GOTLO:
  3066. relocation = picrel->fdgot_entry;
  3067. check_segment[0] = check_segment[1] = got_segment;
  3068. break;
  3069. case R_FRV_GOTOFFHI:
  3070. case R_FRV_GOTOFF12:
  3071. case R_FRV_GOTOFFLO:
  3072. relocation -= frvfdpic_got_section (info)->output_section->vma
  3073. + frvfdpic_got_section (info)->output_offset
  3074. + frvfdpic_got_initial_offset (info);
  3075. check_segment[0] = got_segment;
  3076. check_segment[1] = sec
  3077. ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
  3078. : (unsigned)-1;
  3079. break;
  3080. case R_FRV_FUNCDESC_GOTOFF12:
  3081. case R_FRV_FUNCDESC_GOTOFFHI:
  3082. case R_FRV_FUNCDESC_GOTOFFLO:
  3083. relocation = picrel->fd_entry;
  3084. check_segment[0] = check_segment[1] = got_segment;
  3085. break;
  3086. case R_FRV_FUNCDESC:
  3087. {
  3088. int dynindx;
  3089. bfd_vma addend = rel->r_addend;
  3090. if (! (h && h->root.type == bfd_link_hash_undefweak
  3091. && FRVFDPIC_SYM_LOCAL (info, h)))
  3092. {
  3093. /* If the symbol is dynamic and there may be dynamic
  3094. symbol resolution because we are or are linked with a
  3095. shared library, emit a FUNCDESC relocation such that
  3096. the dynamic linker will allocate the function
  3097. descriptor. If the symbol needs a non-local function
  3098. descriptor but binds locally (e.g., its visibility is
  3099. protected, emit a dynamic relocation decayed to
  3100. section+offset. */
  3101. if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h)
  3102. && FRVFDPIC_SYM_LOCAL (info, h)
  3103. && !bfd_link_pde (info))
  3104. {
  3105. dynindx = elf_section_data (h->root.u.def.section
  3106. ->output_section)->dynindx;
  3107. addend += h->root.u.def.section->output_offset
  3108. + h->root.u.def.value;
  3109. }
  3110. else if (h && ! FRVFDPIC_FUNCDESC_LOCAL (info, h))
  3111. {
  3112. if (addend)
  3113. {
  3114. info->callbacks->einfo
  3115. (_("%H: %s references dynamic symbol"
  3116. " with nonzero addend\n"),
  3117. input_bfd, input_section, rel->r_offset,
  3118. "R_FRV_FUNCDESC");
  3119. return false;
  3120. }
  3121. dynindx = h->dynindx;
  3122. }
  3123. else
  3124. {
  3125. /* Otherwise, we know we have a private function
  3126. descriptor, so reference it directly. */
  3127. BFD_ASSERT (picrel->privfd);
  3128. r_type = R_FRV_32;
  3129. dynindx = elf_section_data (frvfdpic_got_section (info)
  3130. ->output_section)->dynindx;
  3131. addend = frvfdpic_got_section (info)->output_offset
  3132. + frvfdpic_got_initial_offset (info)
  3133. + picrel->fd_entry;
  3134. }
  3135. /* If there is room for dynamic symbol resolution, emit
  3136. the dynamic relocation. However, if we're linking an
  3137. executable at a fixed location, we won't have emitted a
  3138. dynamic symbol entry for the got section, so idx will
  3139. be zero, which means we can and should compute the
  3140. address of the private descriptor ourselves. */
  3141. if (bfd_link_pde (info)
  3142. && (!h || FRVFDPIC_FUNCDESC_LOCAL (info, h)))
  3143. {
  3144. addend += frvfdpic_got_section (info)->output_section->vma;
  3145. if ((bfd_section_flags (input_section->output_section)
  3146. & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
  3147. {
  3148. bfd_vma offset;
  3149. if (_frvfdpic_osec_readonly_p (output_bfd,
  3150. input_section
  3151. ->output_section))
  3152. {
  3153. info->callbacks->einfo
  3154. (_("%H: cannot emit fixups"
  3155. " in read-only section\n"),
  3156. input_bfd, input_section, rel->r_offset);
  3157. return false;
  3158. }
  3159. offset = _bfd_elf_section_offset
  3160. (output_bfd, info,
  3161. input_section, rel->r_offset);
  3162. if (offset != (bfd_vma)-1)
  3163. _frvfdpic_add_rofixup (output_bfd,
  3164. frvfdpic_gotfixup_section
  3165. (info),
  3166. offset + input_section
  3167. ->output_section->vma
  3168. + input_section->output_offset,
  3169. picrel);
  3170. }
  3171. }
  3172. else if ((bfd_section_flags (input_section->output_section)
  3173. & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
  3174. {
  3175. bfd_vma offset;
  3176. if (_frvfdpic_osec_readonly_p (output_bfd,
  3177. input_section
  3178. ->output_section))
  3179. {
  3180. info->callbacks->einfo
  3181. (_("%H: cannot emit dynamic relocations"
  3182. " in read-only section\n"),
  3183. input_bfd, input_section, rel->r_offset);
  3184. return false;
  3185. }
  3186. offset = _bfd_elf_section_offset
  3187. (output_bfd, info,
  3188. input_section, rel->r_offset);
  3189. if (offset != (bfd_vma)-1)
  3190. _frvfdpic_add_dyn_reloc (output_bfd,
  3191. frvfdpic_gotrel_section (info),
  3192. offset + input_section
  3193. ->output_section->vma
  3194. + input_section->output_offset,
  3195. r_type, dynindx, addend, picrel);
  3196. }
  3197. else
  3198. addend += frvfdpic_got_section (info)->output_section->vma;
  3199. }
  3200. /* We want the addend in-place because dynamic
  3201. relocations are REL. Setting relocation to it should
  3202. arrange for it to be installed. */
  3203. relocation = addend - rel->r_addend;
  3204. }
  3205. check_segment[0] = check_segment[1] = got_segment;
  3206. break;
  3207. case R_FRV_32:
  3208. if (! IS_FDPIC (output_bfd))
  3209. {
  3210. check_segment[0] = check_segment[1] = -1;
  3211. break;
  3212. }
  3213. /* Fall through. */
  3214. case R_FRV_FUNCDESC_VALUE:
  3215. {
  3216. int dynindx;
  3217. bfd_vma addend = rel->r_addend;
  3218. /* If the symbol is dynamic but binds locally, use
  3219. section+offset. */
  3220. if (h && ! FRVFDPIC_SYM_LOCAL (info, h))
  3221. {
  3222. if (addend && r_type == R_FRV_FUNCDESC_VALUE)
  3223. {
  3224. info->callbacks->einfo
  3225. (_("%H: %s references dynamic symbol"
  3226. " with nonzero addend\n"),
  3227. input_bfd, input_section, rel->r_offset,
  3228. "R_FRV_FUNCDESC_VALUE");
  3229. return false;
  3230. }
  3231. dynindx = h->dynindx;
  3232. }
  3233. else
  3234. {
  3235. if (h)
  3236. addend += h->root.u.def.value;
  3237. else
  3238. addend += sym->st_value;
  3239. if (osec)
  3240. addend += osec->output_offset;
  3241. if (osec && osec->output_section
  3242. && ! bfd_is_abs_section (osec->output_section)
  3243. && ! bfd_is_und_section (osec->output_section))
  3244. dynindx = elf_section_data (osec->output_section)->dynindx;
  3245. else
  3246. dynindx = 0;
  3247. }
  3248. /* If we're linking an executable at a fixed address, we
  3249. can omit the dynamic relocation as long as the symbol
  3250. is defined in the current link unit (which is implied
  3251. by its output section not being NULL). */
  3252. if (bfd_link_pde (info)
  3253. && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
  3254. {
  3255. if (osec)
  3256. addend += osec->output_section->vma;
  3257. if (IS_FDPIC (input_bfd)
  3258. && (bfd_section_flags (input_section->output_section)
  3259. & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
  3260. {
  3261. if (_frvfdpic_osec_readonly_p (output_bfd,
  3262. input_section
  3263. ->output_section))
  3264. {
  3265. info->callbacks->einfo
  3266. (_("%H: cannot emit fixups in read-only section\n"),
  3267. input_bfd, input_section, rel->r_offset);
  3268. return false;
  3269. }
  3270. if (!h || h->root.type != bfd_link_hash_undefweak)
  3271. {
  3272. bfd_vma offset = _bfd_elf_section_offset
  3273. (output_bfd, info,
  3274. input_section, rel->r_offset);
  3275. if (offset != (bfd_vma)-1)
  3276. {
  3277. _frvfdpic_add_rofixup (output_bfd,
  3278. frvfdpic_gotfixup_section
  3279. (info),
  3280. offset + input_section
  3281. ->output_section->vma
  3282. + input_section->output_offset,
  3283. picrel);
  3284. if (r_type == R_FRV_FUNCDESC_VALUE)
  3285. _frvfdpic_add_rofixup
  3286. (output_bfd,
  3287. frvfdpic_gotfixup_section (info),
  3288. offset
  3289. + input_section->output_section->vma
  3290. + input_section->output_offset + 4, picrel);
  3291. }
  3292. }
  3293. }
  3294. }
  3295. else
  3296. {
  3297. if ((bfd_section_flags (input_section->output_section)
  3298. & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
  3299. {
  3300. bfd_vma offset;
  3301. if (_frvfdpic_osec_readonly_p (output_bfd,
  3302. input_section
  3303. ->output_section))
  3304. {
  3305. info->callbacks->einfo
  3306. (_("%H: cannot emit dynamic relocations"
  3307. " in read-only section\n"),
  3308. input_bfd, input_section, rel->r_offset);
  3309. return false;
  3310. }
  3311. offset = _bfd_elf_section_offset
  3312. (output_bfd, info,
  3313. input_section, rel->r_offset);
  3314. if (offset != (bfd_vma)-1)
  3315. _frvfdpic_add_dyn_reloc (output_bfd,
  3316. frvfdpic_gotrel_section (info),
  3317. offset + input_section
  3318. ->output_section->vma
  3319. + input_section->output_offset,
  3320. r_type, dynindx, addend, picrel);
  3321. }
  3322. else if (osec)
  3323. addend += osec->output_section->vma;
  3324. /* We want the addend in-place because dynamic
  3325. relocations are REL. Setting relocation to it
  3326. should arrange for it to be installed. */
  3327. relocation = addend - rel->r_addend;
  3328. }
  3329. if (r_type == R_FRV_FUNCDESC_VALUE)
  3330. {
  3331. /* If we've omitted the dynamic relocation, just emit
  3332. the fixed addresses of the symbol and of the local
  3333. GOT base offset. */
  3334. if (bfd_link_pde (info)
  3335. && (!h || FRVFDPIC_SYM_LOCAL (info, h)))
  3336. bfd_put_32 (output_bfd,
  3337. frvfdpic_got_section (info)->output_section->vma
  3338. + frvfdpic_got_section (info)->output_offset
  3339. + frvfdpic_got_initial_offset (info),
  3340. contents + rel->r_offset + 4);
  3341. else
  3342. /* A function descriptor used for lazy or local
  3343. resolving is initialized such that its high word
  3344. contains the output section index in which the
  3345. PLT entries are located, and the low word
  3346. contains the offset of the lazy PLT entry entry
  3347. point into that section. */
  3348. bfd_put_32 (output_bfd,
  3349. h && ! FRVFDPIC_SYM_LOCAL (info, h)
  3350. ? 0
  3351. : _frvfdpic_osec_to_segment (output_bfd,
  3352. sec
  3353. ->output_section),
  3354. contents + rel->r_offset + 4);
  3355. }
  3356. }
  3357. check_segment[0] = check_segment[1] = got_segment;
  3358. break;
  3359. case R_FRV_GPREL12:
  3360. case R_FRV_GPRELU12:
  3361. case R_FRV_GPREL32:
  3362. case R_FRV_GPRELHI:
  3363. case R_FRV_GPRELLO:
  3364. check_segment[0] = gprel_segment;
  3365. check_segment[1] = sec
  3366. ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
  3367. : (unsigned)-1;
  3368. break;
  3369. case R_FRV_GETTLSOFF:
  3370. relocation = frvfdpic_plt_section (info)->output_section->vma
  3371. + frvfdpic_plt_section (info)->output_offset
  3372. + picrel->tlsplt_entry;
  3373. BFD_ASSERT (picrel->tlsplt_entry != (bfd_vma)-1
  3374. && picrel->tlsdesc_entry);
  3375. check_segment[0] = isec_segment;
  3376. check_segment[1] = plt_segment;
  3377. break;
  3378. case R_FRV_GOTTLSDESC12:
  3379. case R_FRV_GOTTLSDESCHI:
  3380. case R_FRV_GOTTLSDESCLO:
  3381. BFD_ASSERT (picrel->tlsdesc_entry);
  3382. relocation = picrel->tlsdesc_entry;
  3383. check_segment[0] = tls_segment;
  3384. check_segment[1] = sec
  3385. && ! bfd_is_abs_section (sec)
  3386. && ! bfd_is_und_section (sec)
  3387. ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
  3388. : tls_segment;
  3389. break;
  3390. case R_FRV_TLSMOFF12:
  3391. case R_FRV_TLSMOFFHI:
  3392. case R_FRV_TLSMOFFLO:
  3393. case R_FRV_TLSMOFF:
  3394. check_segment[0] = tls_segment;
  3395. if (! sec)
  3396. check_segment[1] = -1;
  3397. else if (bfd_is_abs_section (sec)
  3398. || bfd_is_und_section (sec))
  3399. {
  3400. relocation = 0;
  3401. check_segment[1] = tls_segment;
  3402. }
  3403. else if (sec->output_section)
  3404. {
  3405. relocation -= tls_biased_base (info);
  3406. check_segment[1] =
  3407. _frvfdpic_osec_to_segment (output_bfd, sec->output_section);
  3408. }
  3409. else
  3410. check_segment[1] = -1;
  3411. break;
  3412. case R_FRV_GOTTLSOFF12:
  3413. case R_FRV_GOTTLSOFFHI:
  3414. case R_FRV_GOTTLSOFFLO:
  3415. BFD_ASSERT (picrel->tlsoff_entry);
  3416. relocation = picrel->tlsoff_entry;
  3417. check_segment[0] = tls_segment;
  3418. check_segment[1] = sec
  3419. && ! bfd_is_abs_section (sec)
  3420. && ! bfd_is_und_section (sec)
  3421. ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
  3422. : tls_segment;
  3423. break;
  3424. case R_FRV_TLSDESC_VALUE:
  3425. case R_FRV_TLSOFF:
  3426. /* These shouldn't be present in input object files. */
  3427. check_segment[0] = check_segment[1] = isec_segment;
  3428. break;
  3429. case R_FRV_TLSDESC_RELAX:
  3430. case R_FRV_GETTLSOFF_RELAX:
  3431. case R_FRV_TLSOFF_RELAX:
  3432. /* These are just annotations for relaxation, nothing to do
  3433. here. */
  3434. continue;
  3435. default:
  3436. check_segment[0] = isec_segment;
  3437. check_segment[1] = sec
  3438. ? _frvfdpic_osec_to_segment (output_bfd, sec->output_section)
  3439. : (unsigned)-1;
  3440. break;
  3441. }
  3442. if (check_segment[0] != check_segment[1] && IS_FDPIC (output_bfd))
  3443. {
  3444. /* If you take this out, remove the #error from fdpic-static-6.d
  3445. in the ld testsuite. */
  3446. /* This helps catch problems in GCC while we can't do more
  3447. than static linking. The idea is to test whether the
  3448. input file basename is crt0.o only once. */
  3449. if (silence_segment_error == 1)
  3450. silence_segment_error =
  3451. (strlen (bfd_get_filename (input_bfd)) == 6
  3452. && filename_cmp (bfd_get_filename (input_bfd), "crt0.o") == 0)
  3453. || (strlen (bfd_get_filename (input_bfd)) > 6
  3454. && filename_cmp (bfd_get_filename (input_bfd)
  3455. + strlen (bfd_get_filename (input_bfd)) - 7,
  3456. "/crt0.o") == 0)
  3457. ? -1 : 0;
  3458. if (!silence_segment_error
  3459. /* We don't want duplicate errors for undefined
  3460. symbols. */
  3461. && !(picrel && picrel->symndx == -1
  3462. && picrel->d.h->root.type == bfd_link_hash_undefined))
  3463. {
  3464. info->callbacks->einfo
  3465. /* xgettext:c-format */
  3466. (_("%H: reloc against `%s' references a different segment\n"),
  3467. input_bfd, input_section, rel->r_offset, name);
  3468. }
  3469. if (!silence_segment_error && bfd_link_pic (info))
  3470. return false;
  3471. elf_elfheader (output_bfd)->e_flags |= EF_FRV_PIC;
  3472. }
  3473. switch (r_type)
  3474. {
  3475. case R_FRV_GOTOFFHI:
  3476. case R_FRV_TLSMOFFHI:
  3477. /* We need the addend to be applied before we shift the
  3478. value right. */
  3479. relocation += rel->r_addend;
  3480. /* Fall through. */
  3481. case R_FRV_GOTHI:
  3482. case R_FRV_FUNCDESC_GOTHI:
  3483. case R_FRV_FUNCDESC_GOTOFFHI:
  3484. case R_FRV_GOTTLSOFFHI:
  3485. case R_FRV_GOTTLSDESCHI:
  3486. relocation >>= 16;
  3487. /* Fall through. */
  3488. case R_FRV_GOTLO:
  3489. case R_FRV_FUNCDESC_GOTLO:
  3490. case R_FRV_GOTOFFLO:
  3491. case R_FRV_FUNCDESC_GOTOFFLO:
  3492. case R_FRV_GOTTLSOFFLO:
  3493. case R_FRV_GOTTLSDESCLO:
  3494. case R_FRV_TLSMOFFLO:
  3495. relocation &= 0xffff;
  3496. break;
  3497. default:
  3498. break;
  3499. }
  3500. switch (r_type)
  3501. {
  3502. case R_FRV_LABEL24:
  3503. if (! IS_FDPIC (output_bfd) || ! picrel->plt)
  3504. break;
  3505. /* Fall through. */
  3506. /* When referencing a GOT entry, a function descriptor or a
  3507. PLT, we don't want the addend to apply to the reference,
  3508. but rather to the referenced symbol. The actual entry
  3509. will have already been created taking the addend into
  3510. account, so cancel it out here. */
  3511. case R_FRV_GOT12:
  3512. case R_FRV_GOTHI:
  3513. case R_FRV_GOTLO:
  3514. case R_FRV_FUNCDESC_GOT12:
  3515. case R_FRV_FUNCDESC_GOTHI:
  3516. case R_FRV_FUNCDESC_GOTLO:
  3517. case R_FRV_FUNCDESC_GOTOFF12:
  3518. case R_FRV_FUNCDESC_GOTOFFHI:
  3519. case R_FRV_FUNCDESC_GOTOFFLO:
  3520. case R_FRV_GETTLSOFF:
  3521. case R_FRV_GOTTLSDESC12:
  3522. case R_FRV_GOTTLSDESCHI:
  3523. case R_FRV_GOTTLSDESCLO:
  3524. case R_FRV_GOTTLSOFF12:
  3525. case R_FRV_GOTTLSOFFHI:
  3526. case R_FRV_GOTTLSOFFLO:
  3527. /* Note that we only want GOTOFFHI, not GOTOFFLO or GOTOFF12
  3528. here, since we do want to apply the addend to the others.
  3529. Note that we've applied the addend to GOTOFFHI before we
  3530. shifted it right. */
  3531. case R_FRV_GOTOFFHI:
  3532. case R_FRV_TLSMOFFHI:
  3533. relocation -= rel->r_addend;
  3534. break;
  3535. default:
  3536. break;
  3537. }
  3538. if (r_type == R_FRV_HI16)
  3539. r = elf32_frv_relocate_hi16 (input_bfd, rel, contents, relocation);
  3540. else if (r_type == R_FRV_LO16)
  3541. r = elf32_frv_relocate_lo16 (input_bfd, rel, contents, relocation);
  3542. else if (r_type == R_FRV_LABEL24 || r_type == R_FRV_GETTLSOFF)
  3543. r = elf32_frv_relocate_label24 (input_bfd, input_section, rel,
  3544. contents, relocation);
  3545. else if (r_type == R_FRV_GPREL12)
  3546. r = elf32_frv_relocate_gprel12 (info, input_bfd, input_section, rel,
  3547. contents, relocation);
  3548. else if (r_type == R_FRV_GPRELU12)
  3549. r = elf32_frv_relocate_gprelu12 (info, input_bfd, input_section, rel,
  3550. contents, relocation);
  3551. else if (r_type == R_FRV_GPRELLO)
  3552. r = elf32_frv_relocate_gprello (info, input_bfd, input_section, rel,
  3553. contents, relocation);
  3554. else if (r_type == R_FRV_GPRELHI)
  3555. r = elf32_frv_relocate_gprelhi (info, input_bfd, input_section, rel,
  3556. contents, relocation);
  3557. else if (r_type == R_FRV_TLSOFF
  3558. || r_type == R_FRV_TLSDESC_VALUE)
  3559. r = bfd_reloc_notsupported;
  3560. else
  3561. r = frv_final_link_relocate (howto, input_bfd, input_section, contents,
  3562. rel, relocation);
  3563. if (r != bfd_reloc_ok)
  3564. {
  3565. const char * msg = (const char *) NULL;
  3566. switch (r)
  3567. {
  3568. case bfd_reloc_overflow:
  3569. (*info->callbacks->reloc_overflow)
  3570. (info, (h ? &h->root : NULL), name, howto->name,
  3571. (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
  3572. break;
  3573. case bfd_reloc_undefined:
  3574. (*info->callbacks->undefined_symbol)
  3575. (info, name, input_bfd, input_section, rel->r_offset, true);
  3576. break;
  3577. case bfd_reloc_outofrange:
  3578. msg = _("internal error: out of range error");
  3579. break;
  3580. case bfd_reloc_notsupported:
  3581. msg = _("internal error: unsupported relocation error");
  3582. break;
  3583. case bfd_reloc_dangerous:
  3584. msg = _("internal error: dangerous relocation");
  3585. break;
  3586. default:
  3587. msg = _("internal error: unknown error");
  3588. break;
  3589. }
  3590. if (msg)
  3591. {
  3592. info->callbacks->einfo
  3593. /* xgettext:c-format */
  3594. (_("%H: reloc against `%s': %s\n"),
  3595. input_bfd, input_section, rel->r_offset, name, msg);
  3596. return false;
  3597. }
  3598. }
  3599. }
  3600. return true;
  3601. }
  3602. /* Return the section that should be marked against GC for a given
  3603. relocation. */
  3604. static asection *
  3605. elf32_frv_gc_mark_hook (asection *sec,
  3606. struct bfd_link_info *info,
  3607. Elf_Internal_Rela *rel,
  3608. struct elf_link_hash_entry *h,
  3609. Elf_Internal_Sym *sym)
  3610. {
  3611. if (h != NULL)
  3612. switch (ELF32_R_TYPE (rel->r_info))
  3613. {
  3614. case R_FRV_GNU_VTINHERIT:
  3615. case R_FRV_GNU_VTENTRY:
  3616. return NULL;
  3617. }
  3618. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  3619. }
  3620. /* Hook called by the linker routine which adds symbols from an object
  3621. file. We use it to put .comm items in .scomm, and not .comm. */
  3622. static bool
  3623. elf32_frv_add_symbol_hook (bfd *abfd,
  3624. struct bfd_link_info *info,
  3625. Elf_Internal_Sym *sym,
  3626. const char **namep ATTRIBUTE_UNUSED,
  3627. flagword *flagsp ATTRIBUTE_UNUSED,
  3628. asection **secp,
  3629. bfd_vma *valp)
  3630. {
  3631. if (sym->st_shndx == SHN_COMMON
  3632. && !bfd_link_relocatable (info)
  3633. && (int)sym->st_size <= (int)bfd_get_gp_size (abfd))
  3634. {
  3635. /* Common symbols less than or equal to -G nn bytes are
  3636. automatically put into .sbss. */
  3637. asection *scomm = bfd_get_section_by_name (abfd, ".scommon");
  3638. if (scomm == NULL)
  3639. {
  3640. scomm = bfd_make_section_with_flags (abfd, ".scommon",
  3641. (SEC_ALLOC
  3642. | SEC_IS_COMMON
  3643. | SEC_SMALL_DATA
  3644. | SEC_LINKER_CREATED));
  3645. if (scomm == NULL)
  3646. return false;
  3647. }
  3648. *secp = scomm;
  3649. *valp = sym->st_size;
  3650. }
  3651. return true;
  3652. }
  3653. /* We need dynamic symbols for every section, since segments can
  3654. relocate independently. */
  3655. static bool
  3656. _frvfdpic_link_omit_section_dynsym (bfd *output_bfd ATTRIBUTE_UNUSED,
  3657. struct bfd_link_info *info
  3658. ATTRIBUTE_UNUSED,
  3659. asection *p ATTRIBUTE_UNUSED)
  3660. {
  3661. switch (elf_section_data (p)->this_hdr.sh_type)
  3662. {
  3663. case SHT_PROGBITS:
  3664. case SHT_NOBITS:
  3665. /* If sh_type is yet undecided, assume it could be
  3666. SHT_PROGBITS/SHT_NOBITS. */
  3667. case SHT_NULL:
  3668. return false;
  3669. /* There shouldn't be section relative relocations
  3670. against any other section. */
  3671. default:
  3672. return true;
  3673. }
  3674. }
  3675. /* Create a .got section, as well as its additional info field. This
  3676. is almost entirely copied from
  3677. elflink.c:_bfd_elf_create_got_section(). */
  3678. static bool
  3679. _frv_create_got_section (bfd *abfd, struct bfd_link_info *info)
  3680. {
  3681. flagword flags, pltflags;
  3682. asection *s;
  3683. struct elf_link_hash_entry *h;
  3684. struct bfd_link_hash_entry *bh;
  3685. const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  3686. int ptralign;
  3687. int offset;
  3688. /* This function may be called more than once. */
  3689. s = elf_hash_table (info)->sgot;
  3690. if (s != NULL)
  3691. return true;
  3692. /* Machine specific: although pointers are 32-bits wide, we want the
  3693. GOT to be aligned to a 64-bit boundary, such that function
  3694. descriptors in it can be accessed with 64-bit loads and
  3695. stores. */
  3696. ptralign = 3;
  3697. flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
  3698. | SEC_LINKER_CREATED);
  3699. pltflags = flags;
  3700. s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
  3701. elf_hash_table (info)->sgot = s;
  3702. if (s == NULL
  3703. || !bfd_set_section_alignment (s, ptralign))
  3704. return false;
  3705. if (bed->want_got_sym)
  3706. {
  3707. /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
  3708. (or .got.plt) section. We don't do this in the linker script
  3709. because we don't want to define the symbol if we are not creating
  3710. a global offset table. */
  3711. h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
  3712. elf_hash_table (info)->hgot = h;
  3713. if (h == NULL)
  3714. return false;
  3715. /* Machine-specific: we want the symbol for executables as
  3716. well. */
  3717. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  3718. return false;
  3719. }
  3720. /* The first bit of the global offset table is the header. */
  3721. s->size += bed->got_header_size;
  3722. /* This is the machine-specific part. Create and initialize section
  3723. data for the got. */
  3724. if (IS_FDPIC (abfd))
  3725. {
  3726. frvfdpic_relocs_info (info) = htab_try_create (1,
  3727. frvfdpic_relocs_info_hash,
  3728. frvfdpic_relocs_info_eq,
  3729. (htab_del) NULL);
  3730. if (! frvfdpic_relocs_info (info))
  3731. return false;
  3732. s = bfd_make_section_anyway_with_flags (abfd, ".rel.got",
  3733. (flags | SEC_READONLY));
  3734. elf_hash_table (info)->srelgot = s;
  3735. if (s == NULL
  3736. || !bfd_set_section_alignment (s, 2))
  3737. return false;
  3738. /* Machine-specific. */
  3739. s = bfd_make_section_anyway_with_flags (abfd, ".rofixup",
  3740. (flags | SEC_READONLY));
  3741. if (s == NULL
  3742. || !bfd_set_section_alignment (s, 2))
  3743. return false;
  3744. frvfdpic_gotfixup_section (info) = s;
  3745. offset = -2048;
  3746. flags = BSF_GLOBAL;
  3747. }
  3748. else
  3749. {
  3750. offset = 2048;
  3751. flags = BSF_GLOBAL | BSF_WEAK;
  3752. }
  3753. /* Define _gp in .rofixup, for FDPIC, or .got otherwise. If it
  3754. turns out that we're linking with a different linker script, the
  3755. linker script will override it. */
  3756. bh = NULL;
  3757. if (!(_bfd_generic_link_add_one_symbol
  3758. (info, abfd, "_gp", flags, s, offset, (const char *) NULL, false,
  3759. bed->collect, &bh)))
  3760. return false;
  3761. h = (struct elf_link_hash_entry *) bh;
  3762. h->def_regular = 1;
  3763. h->type = STT_OBJECT;
  3764. /* h->other = STV_HIDDEN; */ /* Should we? */
  3765. /* Machine-specific: we want the symbol for executables as well. */
  3766. if (IS_FDPIC (abfd) && ! bfd_elf_link_record_dynamic_symbol (info, h))
  3767. return false;
  3768. if (!IS_FDPIC (abfd))
  3769. return true;
  3770. /* FDPIC supports Thread Local Storage, and this may require a
  3771. procedure linkage table for TLS PLT entries. */
  3772. /* This is mostly copied from
  3773. elflink.c:_bfd_elf_create_dynamic_sections(). */
  3774. flags = pltflags;
  3775. pltflags |= SEC_CODE;
  3776. if (bed->plt_not_loaded)
  3777. pltflags &= ~ (SEC_CODE | SEC_LOAD | SEC_HAS_CONTENTS);
  3778. if (bed->plt_readonly)
  3779. pltflags |= SEC_READONLY;
  3780. s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
  3781. if (s == NULL
  3782. || !bfd_set_section_alignment (s, bed->plt_alignment))
  3783. return false;
  3784. /* FRV-specific: remember it. */
  3785. frvfdpic_plt_section (info) = s;
  3786. /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
  3787. .plt section. */
  3788. if (bed->want_plt_sym)
  3789. {
  3790. h = _bfd_elf_define_linkage_sym (abfd, info, s,
  3791. "_PROCEDURE_LINKAGE_TABLE_");
  3792. elf_hash_table (info)->hplt = h;
  3793. if (h == NULL)
  3794. return false;
  3795. }
  3796. /* FRV-specific: we want rel relocations for the plt. */
  3797. s = bfd_make_section_anyway_with_flags (abfd, ".rel.plt",
  3798. flags | SEC_READONLY);
  3799. if (s == NULL
  3800. || !bfd_set_section_alignment (s, bed->s->log_file_align))
  3801. return false;
  3802. /* FRV-specific: remember it. */
  3803. frvfdpic_pltrel_section (info) = s;
  3804. return true;
  3805. }
  3806. /* Make sure the got and plt sections exist, and that our pointers in
  3807. the link hash table point to them. */
  3808. static bool
  3809. elf32_frvfdpic_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
  3810. {
  3811. /* This is mostly copied from
  3812. elflink.c:_bfd_elf_create_dynamic_sections(). */
  3813. flagword flags;
  3814. asection *s;
  3815. const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  3816. flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
  3817. | SEC_LINKER_CREATED);
  3818. /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
  3819. .rel[a].bss sections. */
  3820. /* FRV-specific: we want to create the GOT and the PLT in the FRV
  3821. way. */
  3822. if (! _frv_create_got_section (abfd, info))
  3823. return false;
  3824. /* FRV-specific: make sure we created everything we wanted. */
  3825. BFD_ASSERT (frvfdpic_got_section (info) && frvfdpic_gotrel_section (info)
  3826. && frvfdpic_gotfixup_section (info)
  3827. && frvfdpic_plt_section (info)
  3828. && frvfdpic_pltrel_section (info));
  3829. if (bed->want_dynbss)
  3830. {
  3831. /* The .dynbss section is a place to put symbols which are defined
  3832. by dynamic objects, are referenced by regular objects, and are
  3833. not functions. We must allocate space for them in the process
  3834. image and use a R_*_COPY reloc to tell the dynamic linker to
  3835. initialize them at run time. The linker script puts the .dynbss
  3836. section into the .bss section of the final image. */
  3837. s = bfd_make_section_anyway_with_flags (abfd, ".dynbss",
  3838. SEC_ALLOC | SEC_LINKER_CREATED);
  3839. if (s == NULL)
  3840. return false;
  3841. /* The .rel[a].bss section holds copy relocs. This section is not
  3842. normally needed. We need to create it here, though, so that the
  3843. linker will map it to an output section. We can't just create it
  3844. only if we need it, because we will not know whether we need it
  3845. until we have seen all the input files, and the first time the
  3846. main linker code calls BFD after examining all the input files
  3847. (size_dynamic_sections) the input sections have already been
  3848. mapped to the output sections. If the section turns out not to
  3849. be needed, we can discard it later. We will never need this
  3850. section when generating a shared object, since they do not use
  3851. copy relocs. */
  3852. if (! bfd_link_pic (info))
  3853. {
  3854. s = bfd_make_section_anyway_with_flags (abfd,
  3855. (bed->default_use_rela_p
  3856. ? ".rela.bss" : ".rel.bss"),
  3857. flags | SEC_READONLY);
  3858. if (s == NULL
  3859. || !bfd_set_section_alignment (s, bed->s->log_file_align))
  3860. return false;
  3861. }
  3862. }
  3863. return true;
  3864. }
  3865. /* Compute the total GOT and PLT size required by each symbol in each
  3866. range. Symbols may require up to 4 words in the GOT: an entry
  3867. pointing to the symbol, an entry pointing to its function
  3868. descriptor, and a private function descriptors taking two
  3869. words. */
  3870. static void
  3871. _frvfdpic_count_nontls_entries (struct frvfdpic_relocs_info *entry,
  3872. struct _frvfdpic_dynamic_got_info *dinfo)
  3873. {
  3874. /* Allocate space for a GOT entry pointing to the symbol. */
  3875. if (entry->got12)
  3876. dinfo->got12 += 4;
  3877. else if (entry->gotlos)
  3878. dinfo->gotlos += 4;
  3879. else if (entry->gothilo)
  3880. dinfo->gothilo += 4;
  3881. else
  3882. entry->relocs32--;
  3883. entry->relocs32++;
  3884. /* Allocate space for a GOT entry pointing to the function
  3885. descriptor. */
  3886. if (entry->fdgot12)
  3887. dinfo->got12 += 4;
  3888. else if (entry->fdgotlos)
  3889. dinfo->gotlos += 4;
  3890. else if (entry->fdgothilo)
  3891. dinfo->gothilo += 4;
  3892. else
  3893. entry->relocsfd--;
  3894. entry->relocsfd++;
  3895. /* Decide whether we need a PLT entry, a function descriptor in the
  3896. GOT, and a lazy PLT entry for this symbol. */
  3897. entry->plt = entry->call
  3898. && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
  3899. && elf_hash_table (dinfo->info)->dynamic_sections_created;
  3900. entry->privfd = entry->plt
  3901. || entry->fdgoff12 || entry->fdgofflos || entry->fdgoffhilo
  3902. || ((entry->fd || entry->fdgot12 || entry->fdgotlos || entry->fdgothilo)
  3903. && (entry->symndx != -1
  3904. || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h)));
  3905. entry->lazyplt = entry->privfd
  3906. && entry->symndx == -1 && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
  3907. && ! (dinfo->info->flags & DF_BIND_NOW)
  3908. && elf_hash_table (dinfo->info)->dynamic_sections_created;
  3909. /* Allocate space for a function descriptor. */
  3910. if (entry->fdgoff12)
  3911. dinfo->fd12 += 8;
  3912. else if (entry->fdgofflos)
  3913. dinfo->fdlos += 8;
  3914. else if (entry->privfd && entry->plt)
  3915. dinfo->fdplt += 8;
  3916. else if (entry->privfd)
  3917. dinfo->fdhilo += 8;
  3918. else
  3919. entry->relocsfdv--;
  3920. entry->relocsfdv++;
  3921. if (entry->lazyplt)
  3922. dinfo->lzplt += 8;
  3923. }
  3924. /* Compute the total GOT size required by each TLS symbol in each
  3925. range. Symbols may require up to 5 words in the GOT: an entry
  3926. holding the TLS offset for the symbol, and an entry with a full TLS
  3927. descriptor taking 4 words. */
  3928. static void
  3929. _frvfdpic_count_tls_entries (struct frvfdpic_relocs_info *entry,
  3930. struct _frvfdpic_dynamic_got_info *dinfo,
  3931. bool subtract)
  3932. {
  3933. const int l = subtract ? -1 : 1;
  3934. /* Allocate space for a GOT entry with the TLS offset of the
  3935. symbol. */
  3936. if (entry->tlsoff12)
  3937. dinfo->got12 += 4 * l;
  3938. else if (entry->tlsofflos)
  3939. dinfo->gotlos += 4 * l;
  3940. else if (entry->tlsoffhilo)
  3941. dinfo->gothilo += 4 * l;
  3942. else
  3943. entry->relocstlsoff -= l;
  3944. entry->relocstlsoff += l;
  3945. /* If there's any TLSOFF relocation, mark the output file as not
  3946. suitable for dlopening. This mark will remain even if we relax
  3947. all such relocations, but this is not a problem, since we'll only
  3948. do so for executables, and we definitely don't want anyone
  3949. dlopening executables. */
  3950. if (entry->relocstlsoff)
  3951. dinfo->info->flags |= DF_STATIC_TLS;
  3952. /* Allocate space for a TLS descriptor. */
  3953. if (entry->tlsdesc12)
  3954. dinfo->tlsd12 += 8 * l;
  3955. else if (entry->tlsdesclos)
  3956. dinfo->tlsdlos += 8 * l;
  3957. else if (entry->tlsplt)
  3958. dinfo->tlsdplt += 8 * l;
  3959. else if (entry->tlsdeschilo)
  3960. dinfo->tlsdhilo += 8 * l;
  3961. else
  3962. entry->relocstlsd -= l;
  3963. entry->relocstlsd += l;
  3964. }
  3965. /* Compute the number of dynamic relocations and fixups that a symbol
  3966. requires, and add (or subtract) from the grand and per-symbol
  3967. totals. */
  3968. static void
  3969. _frvfdpic_count_relocs_fixups (struct frvfdpic_relocs_info *entry,
  3970. struct _frvfdpic_dynamic_got_info *dinfo,
  3971. bool subtract)
  3972. {
  3973. bfd_vma relocs = 0, fixups = 0, tlsrets = 0;
  3974. if (!bfd_link_pde (dinfo->info))
  3975. {
  3976. relocs = entry->relocs32 + entry->relocsfd + entry->relocsfdv
  3977. + entry->relocstlsd;
  3978. /* In the executable, TLS relocations to symbols that bind
  3979. locally (including those that resolve to global TLS offsets)
  3980. are resolved immediately, without any need for fixups or
  3981. dynamic relocations. In shared libraries, however, we must
  3982. emit dynamic relocations even for local symbols, because we
  3983. don't know the module id the library is going to get at
  3984. run-time, nor its TLS base offset. */
  3985. if (!bfd_link_executable (dinfo->info)
  3986. || (entry->symndx == -1
  3987. && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
  3988. relocs += entry->relocstlsoff;
  3989. }
  3990. else
  3991. {
  3992. if (entry->symndx != -1 || FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h))
  3993. {
  3994. if (entry->symndx != -1
  3995. || entry->d.h->root.type != bfd_link_hash_undefweak)
  3996. fixups += entry->relocs32 + 2 * entry->relocsfdv;
  3997. fixups += entry->relocstlsd;
  3998. tlsrets += entry->relocstlsd;
  3999. }
  4000. else
  4001. {
  4002. relocs += entry->relocs32 + entry->relocsfdv
  4003. + entry->relocstlsoff + entry->relocstlsd;
  4004. }
  4005. if (entry->symndx != -1
  4006. || FRVFDPIC_FUNCDESC_LOCAL (dinfo->info, entry->d.h))
  4007. {
  4008. if (entry->symndx != -1
  4009. || entry->d.h->root.type != bfd_link_hash_undefweak)
  4010. fixups += entry->relocsfd;
  4011. }
  4012. else
  4013. relocs += entry->relocsfd;
  4014. }
  4015. if (subtract)
  4016. {
  4017. relocs = - relocs;
  4018. fixups = - fixups;
  4019. tlsrets = - tlsrets;
  4020. }
  4021. entry->dynrelocs += relocs;
  4022. entry->fixups += fixups;
  4023. dinfo->relocs += relocs;
  4024. dinfo->fixups += fixups;
  4025. dinfo->tls_ret_refs += tlsrets;
  4026. }
  4027. /* Look for opportunities to relax TLS relocations. We can assume
  4028. we're linking the main executable or a static-tls library, since
  4029. otherwise we wouldn't have got here. When relaxing, we have to
  4030. first undo any previous accounting of TLS uses of fixups, dynamic
  4031. relocations, GOT and PLT entries. */
  4032. static void
  4033. _frvfdpic_relax_tls_entries (struct frvfdpic_relocs_info *entry,
  4034. struct _frvfdpic_dynamic_got_info *dinfo,
  4035. bool relaxing)
  4036. {
  4037. bool changed = ! relaxing;
  4038. BFD_ASSERT (bfd_link_executable (dinfo->info)
  4039. || (dinfo->info->flags & DF_STATIC_TLS));
  4040. if (entry->tlsdesc12 || entry->tlsdesclos || entry->tlsdeschilo)
  4041. {
  4042. if (! changed)
  4043. {
  4044. _frvfdpic_count_relocs_fixups (entry, dinfo, true);
  4045. _frvfdpic_count_tls_entries (entry, dinfo, true);
  4046. changed = true;
  4047. }
  4048. /* When linking an executable, we can always decay GOTTLSDESC to
  4049. TLSMOFF, if the symbol is local, or GOTTLSOFF, otherwise.
  4050. When linking a static-tls shared library, using TLSMOFF is
  4051. not an option, but we can still use GOTTLSOFF. When decaying
  4052. to GOTTLSOFF, we must keep the GOT entry in range. We know
  4053. it has to fit because we'll be trading the 4 words of hte TLS
  4054. descriptor for a single word in the same range. */
  4055. if (! bfd_link_executable (dinfo->info)
  4056. || (entry->symndx == -1
  4057. && ! FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)))
  4058. {
  4059. entry->tlsoff12 |= entry->tlsdesc12;
  4060. entry->tlsofflos |= entry->tlsdesclos;
  4061. entry->tlsoffhilo |= entry->tlsdeschilo;
  4062. }
  4063. entry->tlsdesc12 = entry->tlsdesclos = entry->tlsdeschilo = 0;
  4064. }
  4065. /* We can only decay TLSOFFs or call #gettlsoff to TLSMOFF in the
  4066. main executable. We have to check whether the symbol's TLSOFF is
  4067. in range for a setlos. For symbols with a hash entry, we can
  4068. determine exactly what to do; for others locals, we don't have
  4069. addresses handy, so we use the size of the TLS section as an
  4070. approximation. If we get it wrong, we'll retain a GOT entry
  4071. holding the TLS offset (without dynamic relocations or fixups),
  4072. but we'll still optimize away the loads from it. Since TLS sizes
  4073. are generally very small, it's probably not worth attempting to
  4074. do better than this. */
  4075. if ((entry->tlsplt
  4076. || entry->tlsoff12 || entry->tlsofflos || entry->tlsoffhilo)
  4077. && bfd_link_executable (dinfo->info) && relaxing
  4078. && ((entry->symndx == -1
  4079. && FRVFDPIC_SYM_LOCAL (dinfo->info, entry->d.h)
  4080. /* The above may hold for an undefweak TLS symbol, so make
  4081. sure we don't have this case before accessing def.value
  4082. and def.section. */
  4083. && (entry->d.h->root.type == bfd_link_hash_undefweak
  4084. || (bfd_vma)(entry->d.h->root.u.def.value
  4085. + (entry->d.h->root.u.def.section
  4086. ->output_section->vma)
  4087. + entry->d.h->root.u.def.section->output_offset
  4088. + entry->addend
  4089. - tls_biased_base (dinfo->info)
  4090. + 32768) < (bfd_vma)65536))
  4091. || (entry->symndx != -1
  4092. && (elf_hash_table (dinfo->info)->tls_sec->size
  4093. + entry->addend < 32768 + FRVFDPIC_TLS_BIAS))))
  4094. {
  4095. if (! changed)
  4096. {
  4097. _frvfdpic_count_relocs_fixups (entry, dinfo, true);
  4098. _frvfdpic_count_tls_entries (entry, dinfo, true);
  4099. changed = true;
  4100. }
  4101. entry->tlsplt =
  4102. entry->tlsoff12 = entry->tlsofflos = entry->tlsoffhilo = 0;
  4103. }
  4104. /* We can decay `call #gettlsoff' to a ldi #tlsoff if we already
  4105. have a #gottlsoff12 relocation for this entry, or if we can fit
  4106. one more in the 12-bit (and 16-bit) ranges. */
  4107. if (entry->tlsplt
  4108. && (entry->tlsoff12
  4109. || (relaxing
  4110. && dinfo->got12 + dinfo->fd12 + dinfo->tlsd12 <= 4096 - 12 - 4
  4111. && (dinfo->got12 + dinfo->fd12 + dinfo->tlsd12
  4112. + dinfo->gotlos + dinfo->fdlos + dinfo->tlsdlos
  4113. <= 65536 - 12 - 4))))
  4114. {
  4115. if (! changed)
  4116. {
  4117. _frvfdpic_count_relocs_fixups (entry, dinfo, true);
  4118. _frvfdpic_count_tls_entries (entry, dinfo, true);
  4119. changed = true;
  4120. }
  4121. entry->tlsoff12 = 1;
  4122. entry->tlsplt = 0;
  4123. }
  4124. if (changed)
  4125. {
  4126. _frvfdpic_count_tls_entries (entry, dinfo, false);
  4127. _frvfdpic_count_relocs_fixups (entry, dinfo, false);
  4128. }
  4129. return;
  4130. }
  4131. /* Compute the total GOT and PLT size required by each symbol in each range. *
  4132. Symbols may require up to 4 words in the GOT: an entry pointing to
  4133. the symbol, an entry pointing to its function descriptor, and a
  4134. private function descriptors taking two words. */
  4135. static int
  4136. _frvfdpic_count_got_plt_entries (void **entryp, void *dinfo_)
  4137. {
  4138. struct frvfdpic_relocs_info *entry = *entryp;
  4139. struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
  4140. _frvfdpic_count_nontls_entries (entry, dinfo);
  4141. if (bfd_link_executable (dinfo->info)
  4142. || (dinfo->info->flags & DF_STATIC_TLS))
  4143. _frvfdpic_relax_tls_entries (entry, dinfo, false);
  4144. else
  4145. {
  4146. _frvfdpic_count_tls_entries (entry, dinfo, false);
  4147. _frvfdpic_count_relocs_fixups (entry, dinfo, false);
  4148. }
  4149. return 1;
  4150. }
  4151. /* Determine the positive and negative ranges to be used by each
  4152. offset range in the GOT. FDCUR and CUR, that must be aligned to a
  4153. double-word boundary, are the minimum (negative) and maximum
  4154. (positive) GOT offsets already used by previous ranges, except for
  4155. an ODD entry that may have been left behind. GOT and FD indicate
  4156. the size of GOT entries and function descriptors that must be
  4157. placed within the range from -WRAP to WRAP. If there's room left,
  4158. up to FDPLT bytes should be reserved for additional function
  4159. descriptors. */
  4160. inline static bfd_signed_vma
  4161. _frvfdpic_compute_got_alloc_data (struct _frvfdpic_dynamic_got_alloc_data *gad,
  4162. bfd_signed_vma fdcur,
  4163. bfd_signed_vma odd,
  4164. bfd_signed_vma cur,
  4165. bfd_vma got,
  4166. bfd_vma fd,
  4167. bfd_vma fdplt,
  4168. bfd_vma tlsd,
  4169. bfd_vma tlsdplt,
  4170. bfd_vma wrap)
  4171. {
  4172. bfd_signed_vma wrapmin = -wrap;
  4173. const bfd_vma tdescsz = 8;
  4174. /* Start at the given initial points. */
  4175. gad->fdcur = fdcur;
  4176. gad->cur = cur;
  4177. /* If we had an incoming odd word and we have any got entries that
  4178. are going to use it, consume it, otherwise leave gad->odd at
  4179. zero. We might force gad->odd to zero and return the incoming
  4180. odd such that it is used by the next range, but then GOT entries
  4181. might appear to be out of order and we wouldn't be able to
  4182. shorten the GOT by one word if it turns out to end with an
  4183. unpaired GOT entry. */
  4184. if (odd && got)
  4185. {
  4186. gad->odd = odd;
  4187. got -= 4;
  4188. odd = 0;
  4189. }
  4190. else
  4191. gad->odd = 0;
  4192. /* If we're left with an unpaired GOT entry, compute its location
  4193. such that we can return it. Otherwise, if got doesn't require an
  4194. odd number of words here, either odd was already zero in the
  4195. block above, or it was set to zero because got was non-zero, or
  4196. got was already zero. In the latter case, we want the value of
  4197. odd to carry over to the return statement, so we don't want to
  4198. reset odd unless the condition below is true. */
  4199. if (got & 4)
  4200. {
  4201. odd = cur + got;
  4202. got += 4;
  4203. }
  4204. /* Compute the tentative boundaries of this range. */
  4205. gad->max = cur + got;
  4206. gad->min = fdcur - fd;
  4207. gad->fdplt = 0;
  4208. /* If function descriptors took too much space, wrap some of them
  4209. around. */
  4210. if (gad->min < wrapmin)
  4211. {
  4212. gad->max += wrapmin - gad->min;
  4213. gad->tmin = gad->min = wrapmin;
  4214. }
  4215. /* If GOT entries took too much space, wrap some of them around.
  4216. This may well cause gad->min to become lower than wrapmin. This
  4217. will cause a relocation overflow later on, so we don't have to
  4218. report it here . */
  4219. if ((bfd_vma) gad->max > wrap)
  4220. {
  4221. gad->min -= gad->max - wrap;
  4222. gad->max = wrap;
  4223. }
  4224. /* Add TLS descriptors. */
  4225. gad->tmax = gad->max + tlsd;
  4226. gad->tmin = gad->min;
  4227. gad->tlsdplt = 0;
  4228. /* If TLS descriptors took too much space, wrap an integral number
  4229. of them around. */
  4230. if ((bfd_vma) gad->tmax > wrap)
  4231. {
  4232. bfd_vma wrapsize = gad->tmax - wrap;
  4233. wrapsize += tdescsz / 2;
  4234. wrapsize &= ~ tdescsz / 2;
  4235. gad->tmin -= wrapsize;
  4236. gad->tmax -= wrapsize;
  4237. }
  4238. /* If there is space left and we have function descriptors
  4239. referenced in PLT entries that could take advantage of shorter
  4240. offsets, place them now. */
  4241. if (fdplt && gad->tmin > wrapmin)
  4242. {
  4243. bfd_vma fds;
  4244. if ((bfd_vma) (gad->tmin - wrapmin) < fdplt)
  4245. fds = gad->tmin - wrapmin;
  4246. else
  4247. fds = fdplt;
  4248. fdplt -= fds;
  4249. gad->min -= fds;
  4250. gad->tmin -= fds;
  4251. gad->fdplt += fds;
  4252. }
  4253. /* If there is more space left, try to place some more function
  4254. descriptors for PLT entries. */
  4255. if (fdplt && (bfd_vma) gad->tmax < wrap)
  4256. {
  4257. bfd_vma fds;
  4258. if ((bfd_vma) (wrap - gad->tmax) < fdplt)
  4259. fds = wrap - gad->tmax;
  4260. else
  4261. fds = fdplt;
  4262. fdplt -= fds;
  4263. gad->max += fds;
  4264. gad->tmax += fds;
  4265. gad->fdplt += fds;
  4266. }
  4267. /* If there is space left and we have TLS descriptors referenced in
  4268. PLT entries that could take advantage of shorter offsets, place
  4269. them now. */
  4270. if (tlsdplt && gad->tmin > wrapmin)
  4271. {
  4272. bfd_vma tlsds;
  4273. if ((bfd_vma) (gad->tmin - wrapmin) < tlsdplt)
  4274. tlsds = (gad->tmin - wrapmin) & ~ (tdescsz / 2);
  4275. else
  4276. tlsds = tlsdplt;
  4277. tlsdplt -= tlsds;
  4278. gad->tmin -= tlsds;
  4279. gad->tlsdplt += tlsds;
  4280. }
  4281. /* If there is more space left, try to place some more TLS
  4282. descriptors for PLT entries. Although we could try to fit an
  4283. additional TLS descriptor with half of it just before before the
  4284. wrap point and another right past the wrap point, this might
  4285. cause us to run out of space for the next region, so don't do
  4286. it. */
  4287. if (tlsdplt && (bfd_vma) gad->tmax < wrap - tdescsz / 2)
  4288. {
  4289. bfd_vma tlsds;
  4290. if ((bfd_vma) (wrap - gad->tmax) < tlsdplt)
  4291. tlsds = (wrap - gad->tmax) & ~ (tdescsz / 2);
  4292. else
  4293. tlsds = tlsdplt;
  4294. tlsdplt -= tlsds;
  4295. gad->tmax += tlsds;
  4296. gad->tlsdplt += tlsds;
  4297. }
  4298. /* If odd was initially computed as an offset past the wrap point,
  4299. wrap it around. */
  4300. if (odd > gad->max)
  4301. odd = gad->min + odd - gad->max;
  4302. /* _frvfdpic_get_got_entry() below will always wrap gad->cur if needed
  4303. before returning, so do it here too. This guarantees that,
  4304. should cur and fdcur meet at the wrap point, they'll both be
  4305. equal to min. */
  4306. if (gad->cur == gad->max)
  4307. gad->cur = gad->min;
  4308. /* Ditto for _frvfdpic_get_tlsdesc_entry(). */
  4309. gad->tcur = gad->max;
  4310. if (gad->tcur == gad->tmax)
  4311. gad->tcur = gad->tmin;
  4312. return odd;
  4313. }
  4314. /* Compute the location of the next GOT entry, given the allocation
  4315. data for a range. */
  4316. inline static bfd_signed_vma
  4317. _frvfdpic_get_got_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
  4318. {
  4319. bfd_signed_vma ret;
  4320. if (gad->odd)
  4321. {
  4322. /* If there was an odd word left behind, use it. */
  4323. ret = gad->odd;
  4324. gad->odd = 0;
  4325. }
  4326. else
  4327. {
  4328. /* Otherwise, use the word pointed to by cur, reserve the next
  4329. as an odd word, and skip to the next pair of words, possibly
  4330. wrapping around. */
  4331. ret = gad->cur;
  4332. gad->odd = gad->cur + 4;
  4333. gad->cur += 8;
  4334. if (gad->cur == gad->max)
  4335. gad->cur = gad->min;
  4336. }
  4337. return ret;
  4338. }
  4339. /* Compute the location of the next function descriptor entry in the
  4340. GOT, given the allocation data for a range. */
  4341. inline static bfd_signed_vma
  4342. _frvfdpic_get_fd_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
  4343. {
  4344. /* If we're at the bottom, wrap around, and only then allocate the
  4345. next pair of words. */
  4346. if (gad->fdcur == gad->min)
  4347. gad->fdcur = gad->max;
  4348. return gad->fdcur -= 8;
  4349. }
  4350. /* Compute the location of the next TLS descriptor entry in the GOT,
  4351. given the allocation data for a range. */
  4352. inline static bfd_signed_vma
  4353. _frvfdpic_get_tlsdesc_entry (struct _frvfdpic_dynamic_got_alloc_data *gad)
  4354. {
  4355. bfd_signed_vma ret;
  4356. ret = gad->tcur;
  4357. gad->tcur += 8;
  4358. /* If we're at the top of the region, wrap around to the bottom. */
  4359. if (gad->tcur == gad->tmax)
  4360. gad->tcur = gad->tmin;
  4361. return ret;
  4362. }
  4363. /* Assign GOT offsets for every GOT entry and function descriptor.
  4364. Doing everything in a single pass is tricky. */
  4365. static int
  4366. _frvfdpic_assign_got_entries (void **entryp, void *info_)
  4367. {
  4368. struct frvfdpic_relocs_info *entry = *entryp;
  4369. struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
  4370. if (entry->got12)
  4371. entry->got_entry = _frvfdpic_get_got_entry (&dinfo->got12);
  4372. else if (entry->gotlos)
  4373. entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
  4374. else if (entry->gothilo)
  4375. entry->got_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
  4376. if (entry->fdgot12)
  4377. entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->got12);
  4378. else if (entry->fdgotlos)
  4379. entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
  4380. else if (entry->fdgothilo)
  4381. entry->fdgot_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
  4382. if (entry->fdgoff12)
  4383. entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
  4384. else if (entry->plt && dinfo->got12.fdplt)
  4385. {
  4386. dinfo->got12.fdplt -= 8;
  4387. entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->got12);
  4388. }
  4389. else if (entry->fdgofflos)
  4390. entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
  4391. else if (entry->plt && dinfo->gotlos.fdplt)
  4392. {
  4393. dinfo->gotlos.fdplt -= 8;
  4394. entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gotlos);
  4395. }
  4396. else if (entry->plt)
  4397. {
  4398. dinfo->gothilo.fdplt -= 8;
  4399. entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
  4400. }
  4401. else if (entry->privfd)
  4402. entry->fd_entry = _frvfdpic_get_fd_entry (&dinfo->gothilo);
  4403. if (entry->tlsoff12)
  4404. entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->got12);
  4405. else if (entry->tlsofflos)
  4406. entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gotlos);
  4407. else if (entry->tlsoffhilo)
  4408. entry->tlsoff_entry = _frvfdpic_get_got_entry (&dinfo->gothilo);
  4409. if (entry->tlsdesc12)
  4410. entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
  4411. else if (entry->tlsplt && dinfo->got12.tlsdplt)
  4412. {
  4413. dinfo->got12.tlsdplt -= 8;
  4414. entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->got12);
  4415. }
  4416. else if (entry->tlsdesclos)
  4417. entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
  4418. else if (entry->tlsplt && dinfo->gotlos.tlsdplt)
  4419. {
  4420. dinfo->gotlos.tlsdplt -= 8;
  4421. entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gotlos);
  4422. }
  4423. else if (entry->tlsplt)
  4424. {
  4425. dinfo->gothilo.tlsdplt -= 8;
  4426. entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
  4427. }
  4428. else if (entry->tlsdeschilo)
  4429. entry->tlsdesc_entry = _frvfdpic_get_tlsdesc_entry (&dinfo->gothilo);
  4430. return 1;
  4431. }
  4432. /* Assign GOT offsets to private function descriptors used by PLT
  4433. entries (or referenced by 32-bit offsets), as well as PLT entries
  4434. and lazy PLT entries. */
  4435. static int
  4436. _frvfdpic_assign_plt_entries (void **entryp, void *info_)
  4437. {
  4438. struct frvfdpic_relocs_info *entry = *entryp;
  4439. struct _frvfdpic_dynamic_got_plt_info *dinfo = info_;
  4440. if (entry->privfd)
  4441. BFD_ASSERT (entry->fd_entry);
  4442. if (entry->plt)
  4443. {
  4444. int size;
  4445. /* We use the section's raw size to mark the location of the
  4446. next PLT entry. */
  4447. entry->plt_entry = frvfdpic_plt_section (dinfo->g.info)->size;
  4448. /* Figure out the length of this PLT entry based on the
  4449. addressing mode we need to reach the function descriptor. */
  4450. BFD_ASSERT (entry->fd_entry);
  4451. if (entry->fd_entry >= -(1 << (12 - 1))
  4452. && entry->fd_entry < (1 << (12 - 1)))
  4453. size = 8;
  4454. else if (entry->fd_entry >= -(1 << (16 - 1))
  4455. && entry->fd_entry < (1 << (16 - 1)))
  4456. size = 12;
  4457. else
  4458. size = 16;
  4459. frvfdpic_plt_section (dinfo->g.info)->size += size;
  4460. }
  4461. if (entry->lazyplt)
  4462. {
  4463. entry->lzplt_entry = dinfo->g.lzplt;
  4464. dinfo->g.lzplt += 8;
  4465. /* If this entry is the one that gets the resolver stub, account
  4466. for the additional instruction. */
  4467. if (entry->lzplt_entry % FRVFDPIC_LZPLT_BLOCK_SIZE
  4468. == FRVFDPIC_LZPLT_RESOLV_LOC)
  4469. dinfo->g.lzplt += 4;
  4470. }
  4471. if (entry->tlsplt)
  4472. {
  4473. int size;
  4474. entry->tlsplt_entry
  4475. = frvfdpic_plt_section (dinfo->g.info)->size;
  4476. if (bfd_link_executable (dinfo->g.info)
  4477. && (entry->symndx != -1
  4478. || FRVFDPIC_SYM_LOCAL (dinfo->g.info, entry->d.h)))
  4479. {
  4480. if ((bfd_signed_vma)entry->addend >= -(1 << (16 - 1))
  4481. /* FIXME: here we use the size of the TLS section
  4482. as an upper bound for the value of the TLS
  4483. symbol, because we may not know the exact value
  4484. yet. If we get it wrong, we'll just waste a
  4485. word in the PLT, and we should never get even
  4486. close to 32 KiB of TLS anyway. */
  4487. && elf_hash_table (dinfo->g.info)->tls_sec
  4488. && (elf_hash_table (dinfo->g.info)->tls_sec->size
  4489. + (bfd_signed_vma)(entry->addend) <= (1 << (16 - 1))))
  4490. size = 8;
  4491. else
  4492. size = 12;
  4493. }
  4494. else if (entry->tlsoff_entry)
  4495. {
  4496. if (entry->tlsoff_entry >= -(1 << (12 - 1))
  4497. && entry->tlsoff_entry < (1 << (12 - 1)))
  4498. size = 8;
  4499. else if (entry->tlsoff_entry >= -(1 << (16 - 1))
  4500. && entry->tlsoff_entry < (1 << (16 - 1)))
  4501. size = 12;
  4502. else
  4503. size = 16;
  4504. }
  4505. else
  4506. {
  4507. BFD_ASSERT (entry->tlsdesc_entry);
  4508. if (entry->tlsdesc_entry >= -(1 << (12 - 1))
  4509. && entry->tlsdesc_entry < (1 << (12 - 1)))
  4510. size = 8;
  4511. else if (entry->tlsdesc_entry >= -(1 << (16 - 1))
  4512. && entry->tlsdesc_entry < (1 << (16 - 1)))
  4513. size = 12;
  4514. else
  4515. size = 16;
  4516. }
  4517. frvfdpic_plt_section (dinfo->g.info)->size += size;
  4518. }
  4519. return 1;
  4520. }
  4521. /* Cancel out any effects of calling _frvfdpic_assign_got_entries and
  4522. _frvfdpic_assign_plt_entries. */
  4523. static int
  4524. _frvfdpic_reset_got_plt_entries (void **entryp, void *ignore ATTRIBUTE_UNUSED)
  4525. {
  4526. struct frvfdpic_relocs_info *entry = *entryp;
  4527. entry->got_entry = 0;
  4528. entry->fdgot_entry = 0;
  4529. entry->fd_entry = 0;
  4530. entry->plt_entry = (bfd_vma)-1;
  4531. entry->lzplt_entry = (bfd_vma)-1;
  4532. entry->tlsoff_entry = 0;
  4533. entry->tlsdesc_entry = 0;
  4534. entry->tlsplt_entry = (bfd_vma)-1;
  4535. return 1;
  4536. }
  4537. /* Follow indirect and warning hash entries so that each got entry
  4538. points to the final symbol definition. P must point to a pointer
  4539. to the hash table we're traversing. Since this traversal may
  4540. modify the hash table, we set this pointer to NULL to indicate
  4541. we've made a potentially-destructive change to the hash table, so
  4542. the traversal must be restarted. */
  4543. static int
  4544. _frvfdpic_resolve_final_relocs_info (void **entryp, void *p)
  4545. {
  4546. struct frvfdpic_relocs_info *entry = *entryp;
  4547. htab_t *htab = p;
  4548. if (entry->symndx == -1)
  4549. {
  4550. struct elf_link_hash_entry *h = entry->d.h;
  4551. struct frvfdpic_relocs_info *oentry;
  4552. while (h->root.type == bfd_link_hash_indirect
  4553. || h->root.type == bfd_link_hash_warning)
  4554. h = (struct elf_link_hash_entry *)h->root.u.i.link;
  4555. if (entry->d.h == h)
  4556. return 1;
  4557. oentry = frvfdpic_relocs_info_for_global (*htab, 0, h, entry->addend,
  4558. NO_INSERT);
  4559. if (oentry)
  4560. {
  4561. /* Merge the two entries. */
  4562. frvfdpic_pic_merge_early_relocs_info (oentry, entry);
  4563. htab_clear_slot (*htab, entryp);
  4564. return 1;
  4565. }
  4566. entry->d.h = h;
  4567. /* If we can't find this entry with the new bfd hash, re-insert
  4568. it, and get the traversal restarted. */
  4569. if (! htab_find (*htab, entry))
  4570. {
  4571. htab_clear_slot (*htab, entryp);
  4572. entryp = htab_find_slot (*htab, entry, INSERT);
  4573. if (! *entryp)
  4574. *entryp = entry;
  4575. /* Abort the traversal, since the whole table may have
  4576. moved, and leave it up to the parent to restart the
  4577. process. */
  4578. *(htab_t *)p = NULL;
  4579. return 0;
  4580. }
  4581. }
  4582. return 1;
  4583. }
  4584. /* Compute the total size of the GOT, the PLT, the dynamic relocations
  4585. section and the rofixup section. Assign locations for GOT and PLT
  4586. entries. */
  4587. static bool
  4588. _frvfdpic_size_got_plt (bfd *output_bfd,
  4589. struct _frvfdpic_dynamic_got_plt_info *gpinfop)
  4590. {
  4591. bfd_signed_vma odd;
  4592. bfd_vma limit, tlslimit;
  4593. struct bfd_link_info *info = gpinfop->g.info;
  4594. bfd *dynobj = elf_hash_table (info)->dynobj;
  4595. memcpy (frvfdpic_dynamic_got_plt_info (info), &gpinfop->g,
  4596. sizeof (gpinfop->g));
  4597. odd = 12;
  4598. /* Compute the total size taken by entries in the 12-bit and 16-bit
  4599. ranges, to tell how many PLT function descriptors we can bring
  4600. into the 12-bit range without causing the 16-bit range to
  4601. overflow. */
  4602. limit = odd + gpinfop->g.got12 + gpinfop->g.gotlos
  4603. + gpinfop->g.fd12 + gpinfop->g.fdlos
  4604. + gpinfop->g.tlsd12 + gpinfop->g.tlsdlos;
  4605. if (limit < (bfd_vma)1 << 16)
  4606. limit = ((bfd_vma)1 << 16) - limit;
  4607. else
  4608. limit = 0;
  4609. if (gpinfop->g.fdplt < limit)
  4610. {
  4611. tlslimit = (limit - gpinfop->g.fdplt) & ~ (bfd_vma) 8;
  4612. limit = gpinfop->g.fdplt;
  4613. }
  4614. else
  4615. tlslimit = 0;
  4616. if (gpinfop->g.tlsdplt < tlslimit)
  4617. tlslimit = gpinfop->g.tlsdplt;
  4618. /* Determine the ranges of GOT offsets that we can use for each
  4619. range of addressing modes. */
  4620. odd = _frvfdpic_compute_got_alloc_data (&gpinfop->got12,
  4621. 0,
  4622. odd,
  4623. 16,
  4624. gpinfop->g.got12,
  4625. gpinfop->g.fd12,
  4626. limit,
  4627. gpinfop->g.tlsd12,
  4628. tlslimit,
  4629. (bfd_vma)1 << (12-1));
  4630. odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gotlos,
  4631. gpinfop->got12.tmin,
  4632. odd,
  4633. gpinfop->got12.tmax,
  4634. gpinfop->g.gotlos,
  4635. gpinfop->g.fdlos,
  4636. gpinfop->g.fdplt
  4637. - gpinfop->got12.fdplt,
  4638. gpinfop->g.tlsdlos,
  4639. gpinfop->g.tlsdplt
  4640. - gpinfop->got12.tlsdplt,
  4641. (bfd_vma)1 << (16-1));
  4642. odd = _frvfdpic_compute_got_alloc_data (&gpinfop->gothilo,
  4643. gpinfop->gotlos.tmin,
  4644. odd,
  4645. gpinfop->gotlos.tmax,
  4646. gpinfop->g.gothilo,
  4647. gpinfop->g.fdhilo,
  4648. gpinfop->g.fdplt
  4649. - gpinfop->got12.fdplt
  4650. - gpinfop->gotlos.fdplt,
  4651. gpinfop->g.tlsdhilo,
  4652. gpinfop->g.tlsdplt
  4653. - gpinfop->got12.tlsdplt
  4654. - gpinfop->gotlos.tlsdplt,
  4655. (bfd_vma)1 << (32-1));
  4656. /* Now assign (most) GOT offsets. */
  4657. htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_got_entries,
  4658. gpinfop);
  4659. frvfdpic_got_section (info)->size = gpinfop->gothilo.tmax
  4660. - gpinfop->gothilo.tmin
  4661. /* If an odd word is the last word of the GOT, we don't need this
  4662. word to be part of the GOT. */
  4663. - (odd + 4 == gpinfop->gothilo.tmax ? 4 : 0);
  4664. if (frvfdpic_got_section (info)->size == 0)
  4665. frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
  4666. else if (frvfdpic_got_section (info)->size == 12
  4667. && ! elf_hash_table (info)->dynamic_sections_created)
  4668. {
  4669. frvfdpic_got_section (info)->flags |= SEC_EXCLUDE;
  4670. frvfdpic_got_section (info)->size = 0;
  4671. }
  4672. /* This will be non-NULL during relaxation. The assumption is that
  4673. the size of one of these sections will never grow, only shrink,
  4674. so we can use the larger buffer we allocated before. */
  4675. else if (frvfdpic_got_section (info)->contents == NULL)
  4676. {
  4677. frvfdpic_got_section (info)->contents =
  4678. (bfd_byte *) bfd_zalloc (dynobj,
  4679. frvfdpic_got_section (info)->size);
  4680. if (frvfdpic_got_section (info)->contents == NULL)
  4681. return false;
  4682. }
  4683. if (frvfdpic_gotrel_section (info))
  4684. /* Subtract the number of lzplt entries, since those will generate
  4685. relocations in the pltrel section. */
  4686. frvfdpic_gotrel_section (info)->size =
  4687. (gpinfop->g.relocs - gpinfop->g.lzplt / 8)
  4688. * get_elf_backend_data (output_bfd)->s->sizeof_rel;
  4689. else
  4690. BFD_ASSERT (gpinfop->g.relocs == 0);
  4691. if (frvfdpic_gotrel_section (info)->size == 0)
  4692. frvfdpic_gotrel_section (info)->flags |= SEC_EXCLUDE;
  4693. else if (frvfdpic_gotrel_section (info)->contents == NULL)
  4694. {
  4695. frvfdpic_gotrel_section (info)->contents =
  4696. (bfd_byte *) bfd_zalloc (dynobj,
  4697. frvfdpic_gotrel_section (info)->size);
  4698. if (frvfdpic_gotrel_section (info)->contents == NULL)
  4699. return false;
  4700. }
  4701. frvfdpic_gotfixup_section (info)->size = (gpinfop->g.fixups + 1) * 4;
  4702. if (frvfdpic_gotfixup_section (info)->size == 0)
  4703. frvfdpic_gotfixup_section (info)->flags |= SEC_EXCLUDE;
  4704. else if (frvfdpic_gotfixup_section (info)->contents == NULL)
  4705. {
  4706. frvfdpic_gotfixup_section (info)->contents =
  4707. (bfd_byte *) bfd_zalloc (dynobj,
  4708. frvfdpic_gotfixup_section (info)->size);
  4709. if (frvfdpic_gotfixup_section (info)->contents == NULL)
  4710. return false;
  4711. }
  4712. if (frvfdpic_pltrel_section (info))
  4713. {
  4714. frvfdpic_pltrel_section (info)->size =
  4715. gpinfop->g.lzplt / 8
  4716. * get_elf_backend_data (output_bfd)->s->sizeof_rel;
  4717. if (frvfdpic_pltrel_section (info)->size == 0)
  4718. frvfdpic_pltrel_section (info)->flags |= SEC_EXCLUDE;
  4719. else if (frvfdpic_pltrel_section (info)->contents == NULL)
  4720. {
  4721. frvfdpic_pltrel_section (info)->contents =
  4722. (bfd_byte *) bfd_zalloc (dynobj,
  4723. frvfdpic_pltrel_section (info)->size);
  4724. if (frvfdpic_pltrel_section (info)->contents == NULL)
  4725. return false;
  4726. }
  4727. }
  4728. /* Add 4 bytes for every block of at most 65535 lazy PLT entries,
  4729. such that there's room for the additional instruction needed to
  4730. call the resolver. Since _frvfdpic_assign_got_entries didn't
  4731. account for them, our block size is 4 bytes smaller than the real
  4732. block size. */
  4733. if (frvfdpic_plt_section (info))
  4734. {
  4735. frvfdpic_plt_section (info)->size = gpinfop->g.lzplt
  4736. + ((gpinfop->g.lzplt + (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) - 8)
  4737. / (FRVFDPIC_LZPLT_BLOCK_SIZE - 4) * 4);
  4738. }
  4739. /* Reset it, such that _frvfdpic_assign_plt_entries() can use it to
  4740. actually assign lazy PLT entries addresses. */
  4741. gpinfop->g.lzplt = 0;
  4742. /* Save information that we're going to need to generate GOT and PLT
  4743. entries. */
  4744. frvfdpic_got_initial_offset (info) = -gpinfop->gothilo.tmin;
  4745. if (get_elf_backend_data (output_bfd)->want_got_sym)
  4746. elf_hash_table (info)->hgot->root.u.def.value
  4747. = frvfdpic_got_initial_offset (info);
  4748. if (frvfdpic_plt_section (info))
  4749. frvfdpic_plt_initial_offset (info) =
  4750. frvfdpic_plt_section (info)->size;
  4751. /* Allocate a ret statement at plt_initial_offset, to be used by
  4752. locally-resolved TLS descriptors. */
  4753. if (gpinfop->g.tls_ret_refs)
  4754. frvfdpic_plt_section (info)->size += 4;
  4755. htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_assign_plt_entries,
  4756. gpinfop);
  4757. /* Allocate the PLT section contents only after
  4758. _frvfdpic_assign_plt_entries has a chance to add the size of the
  4759. non-lazy PLT entries. */
  4760. if (frvfdpic_plt_section (info))
  4761. {
  4762. if (frvfdpic_plt_section (info)->size == 0)
  4763. frvfdpic_plt_section (info)->flags |= SEC_EXCLUDE;
  4764. else if (frvfdpic_plt_section (info)->contents == NULL)
  4765. {
  4766. frvfdpic_plt_section (info)->contents =
  4767. (bfd_byte *) bfd_zalloc (dynobj,
  4768. frvfdpic_plt_section (info)->size);
  4769. if (frvfdpic_plt_section (info)->contents == NULL)
  4770. return false;
  4771. }
  4772. }
  4773. return true;
  4774. }
  4775. /* Set the sizes of the dynamic sections. */
  4776. static bool
  4777. elf32_frvfdpic_size_dynamic_sections (bfd *output_bfd,
  4778. struct bfd_link_info *info)
  4779. {
  4780. bfd *dynobj;
  4781. asection *s;
  4782. struct _frvfdpic_dynamic_got_plt_info gpinfo;
  4783. dynobj = elf_hash_table (info)->dynobj;
  4784. BFD_ASSERT (dynobj != NULL);
  4785. if (elf_hash_table (info)->dynamic_sections_created)
  4786. {
  4787. /* Set the contents of the .interp section to the interpreter. */
  4788. if (bfd_link_executable (info) && !info->nointerp)
  4789. {
  4790. s = bfd_get_linker_section (dynobj, ".interp");
  4791. BFD_ASSERT (s != NULL);
  4792. s->size = sizeof ELF_DYNAMIC_INTERPRETER;
  4793. s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
  4794. }
  4795. }
  4796. memset (&gpinfo, 0, sizeof (gpinfo));
  4797. gpinfo.g.info = info;
  4798. for (;;)
  4799. {
  4800. htab_t relocs = frvfdpic_relocs_info (info);
  4801. htab_traverse (relocs, _frvfdpic_resolve_final_relocs_info, &relocs);
  4802. if (relocs == frvfdpic_relocs_info (info))
  4803. break;
  4804. }
  4805. htab_traverse (frvfdpic_relocs_info (info), _frvfdpic_count_got_plt_entries,
  4806. &gpinfo.g);
  4807. /* Allocate space to save the summary information, we're going to
  4808. use it if we're doing relaxations. */
  4809. frvfdpic_dynamic_got_plt_info (info) = bfd_alloc (dynobj, sizeof (gpinfo.g));
  4810. if (!_frvfdpic_size_got_plt (output_bfd, &gpinfo))
  4811. return false;
  4812. return _bfd_elf_add_dynamic_tags (output_bfd, info, true);
  4813. }
  4814. static bool
  4815. elf32_frvfdpic_always_size_sections (bfd *output_bfd,
  4816. struct bfd_link_info *info)
  4817. {
  4818. if (!bfd_link_relocatable (info)
  4819. && !bfd_elf_stack_segment_size (output_bfd, info,
  4820. "__stacksize", DEFAULT_STACK_SIZE))
  4821. return false;
  4822. return true;
  4823. }
  4824. /* Check whether any of the relocations was optimized away, and
  4825. subtract it from the relocation or fixup count. */
  4826. static bool
  4827. _frvfdpic_check_discarded_relocs (bfd *abfd, asection *sec,
  4828. struct bfd_link_info *info,
  4829. bool *changed)
  4830. {
  4831. Elf_Internal_Shdr *symtab_hdr;
  4832. struct elf_link_hash_entry **sym_hashes;
  4833. Elf_Internal_Rela *rel, *erel;
  4834. if ((sec->flags & SEC_RELOC) == 0
  4835. || sec->reloc_count == 0)
  4836. return true;
  4837. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  4838. sym_hashes = elf_sym_hashes (abfd);
  4839. rel = elf_section_data (sec)->relocs;
  4840. /* Now examine each relocation. */
  4841. for (erel = rel + sec->reloc_count; rel < erel; rel++)
  4842. {
  4843. struct elf_link_hash_entry *h;
  4844. unsigned long r_symndx;
  4845. struct frvfdpic_relocs_info *picrel;
  4846. struct _frvfdpic_dynamic_got_info *dinfo;
  4847. if (ELF32_R_TYPE (rel->r_info) != R_FRV_32
  4848. && ELF32_R_TYPE (rel->r_info) != R_FRV_FUNCDESC)
  4849. continue;
  4850. if (_bfd_elf_section_offset (sec->output_section->owner,
  4851. info, sec, rel->r_offset)
  4852. != (bfd_vma)-1)
  4853. continue;
  4854. r_symndx = ELF32_R_SYM (rel->r_info);
  4855. if (r_symndx < symtab_hdr->sh_info)
  4856. h = NULL;
  4857. else
  4858. {
  4859. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  4860. while (h->root.type == bfd_link_hash_indirect
  4861. || h->root.type == bfd_link_hash_warning)
  4862. h = (struct elf_link_hash_entry *)h->root.u.i.link;
  4863. }
  4864. if (h != NULL)
  4865. picrel = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info),
  4866. abfd, h,
  4867. rel->r_addend, NO_INSERT);
  4868. else
  4869. picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info (info),
  4870. abfd, r_symndx,
  4871. rel->r_addend, NO_INSERT);
  4872. if (! picrel)
  4873. return false;
  4874. *changed = true;
  4875. dinfo = frvfdpic_dynamic_got_plt_info (info);
  4876. _frvfdpic_count_relocs_fixups (picrel, dinfo, true);
  4877. if (ELF32_R_TYPE (rel->r_info) == R_FRV_32)
  4878. picrel->relocs32--;
  4879. else /* we know (ELF32_R_TYPE (rel->r_info) == R_FRV_FUNCDESC) */
  4880. picrel->relocsfd--;
  4881. _frvfdpic_count_relocs_fixups (picrel, dinfo, false);
  4882. }
  4883. return true;
  4884. }
  4885. static bool
  4886. frvfdpic_elf_discard_info (bfd *ibfd,
  4887. struct elf_reloc_cookie *cookie ATTRIBUTE_UNUSED,
  4888. struct bfd_link_info *info)
  4889. {
  4890. bool changed = false;
  4891. asection *s;
  4892. bfd *obfd = NULL;
  4893. /* Account for relaxation of .eh_frame section. */
  4894. for (s = ibfd->sections; s; s = s->next)
  4895. if (s->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
  4896. {
  4897. if (!_frvfdpic_check_discarded_relocs (ibfd, s, info, &changed))
  4898. return false;
  4899. obfd = s->output_section->owner;
  4900. }
  4901. if (changed)
  4902. {
  4903. struct _frvfdpic_dynamic_got_plt_info gpinfo;
  4904. memset (&gpinfo, 0, sizeof (gpinfo));
  4905. memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info),
  4906. sizeof (gpinfo.g));
  4907. /* Clear GOT and PLT assignments. */
  4908. htab_traverse (frvfdpic_relocs_info (info),
  4909. _frvfdpic_reset_got_plt_entries,
  4910. NULL);
  4911. if (!_frvfdpic_size_got_plt (obfd, &gpinfo))
  4912. return false;
  4913. }
  4914. return true;
  4915. }
  4916. /* Look for opportunities to relax TLS relocations. We can assume
  4917. we're linking the main executable or a static-tls library, since
  4918. otherwise we wouldn't have got here. */
  4919. static int
  4920. _frvfdpic_relax_got_plt_entries (void **entryp, void *dinfo_)
  4921. {
  4922. struct frvfdpic_relocs_info *entry = *entryp;
  4923. struct _frvfdpic_dynamic_got_info *dinfo = dinfo_;
  4924. _frvfdpic_relax_tls_entries (entry, dinfo, true);
  4925. return 1;
  4926. }
  4927. static bool
  4928. elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
  4929. struct bfd_link_info *info, bool *again)
  4930. {
  4931. struct _frvfdpic_dynamic_got_plt_info gpinfo;
  4932. if (bfd_link_relocatable (info))
  4933. (*info->callbacks->einfo)
  4934. (_("%P%F: --relax and -r may not be used together\n"));
  4935. /* If we return early, we didn't change anything. */
  4936. *again = false;
  4937. /* We'll do our thing when requested to relax the GOT section. */
  4938. if (sec != frvfdpic_got_section (info))
  4939. return true;
  4940. /* We can only relax when linking the main executable or a library
  4941. that can't be dlopened. */
  4942. if (! bfd_link_executable (info) && ! (info->flags & DF_STATIC_TLS))
  4943. return true;
  4944. /* If there isn't a TLS section for this binary, we can't do
  4945. anything about its TLS relocations (it probably doesn't have
  4946. any. */
  4947. if (elf_hash_table (info)->tls_sec == NULL)
  4948. return true;
  4949. memset (&gpinfo, 0, sizeof (gpinfo));
  4950. memcpy (&gpinfo.g, frvfdpic_dynamic_got_plt_info (info), sizeof (gpinfo.g));
  4951. /* Now look for opportunities to relax, adjusting the GOT usage
  4952. as needed. */
  4953. htab_traverse (frvfdpic_relocs_info (info),
  4954. _frvfdpic_relax_got_plt_entries,
  4955. &gpinfo.g);
  4956. /* If we changed anything, reset and re-assign GOT and PLT entries. */
  4957. if (memcmp (frvfdpic_dynamic_got_plt_info (info),
  4958. &gpinfo.g, sizeof (gpinfo.g)) != 0)
  4959. {
  4960. /* Clear GOT and PLT assignments. */
  4961. htab_traverse (frvfdpic_relocs_info (info),
  4962. _frvfdpic_reset_got_plt_entries,
  4963. NULL);
  4964. /* The owner of the TLS section is the output bfd. There should
  4965. be a better way to get to it. */
  4966. if (!_frvfdpic_size_got_plt (elf_hash_table (info)->tls_sec->owner,
  4967. &gpinfo))
  4968. return false;
  4969. /* Repeat until we don't make any further changes. We could fail to
  4970. introduce changes in a round if, for example, the 12-bit range is
  4971. full, but we later release some space by getting rid of TLS
  4972. descriptors in it. We have to repeat the whole process because
  4973. we might have changed the size of a section processed before this
  4974. one. */
  4975. *again = true;
  4976. }
  4977. return true;
  4978. }
  4979. /* Fill in code and data in dynamic sections. */
  4980. static bool
  4981. elf32_frv_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  4982. struct bfd_link_info *info ATTRIBUTE_UNUSED)
  4983. {
  4984. /* Nothing to be done for non-FDPIC. */
  4985. return true;
  4986. }
  4987. static bool
  4988. elf32_frvfdpic_finish_dynamic_sections (bfd *output_bfd,
  4989. struct bfd_link_info *info)
  4990. {
  4991. bfd *dynobj;
  4992. asection *sdyn;
  4993. dynobj = elf_hash_table (info)->dynobj;
  4994. if (frvfdpic_dynamic_got_plt_info (info))
  4995. {
  4996. BFD_ASSERT (frvfdpic_dynamic_got_plt_info (info)->tls_ret_refs == 0);
  4997. }
  4998. if (frvfdpic_got_section (info))
  4999. {
  5000. BFD_ASSERT (frvfdpic_gotrel_section (info)->size
  5001. == (frvfdpic_gotrel_section (info)->reloc_count
  5002. * sizeof (Elf32_External_Rel)));
  5003. if (frvfdpic_gotfixup_section (info))
  5004. {
  5005. struct elf_link_hash_entry *hgot = elf_hash_table (info)->hgot;
  5006. bfd_vma got_value = hgot->root.u.def.value
  5007. + hgot->root.u.def.section->output_section->vma
  5008. + hgot->root.u.def.section->output_offset;
  5009. struct bfd_link_hash_entry *hend;
  5010. _frvfdpic_add_rofixup (output_bfd, frvfdpic_gotfixup_section (info),
  5011. got_value, 0);
  5012. if (frvfdpic_gotfixup_section (info)->size
  5013. != (frvfdpic_gotfixup_section (info)->reloc_count * 4))
  5014. {
  5015. error:
  5016. info->callbacks->einfo
  5017. ("LINKER BUG: .rofixup section size mismatch\n");
  5018. return false;
  5019. }
  5020. hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__",
  5021. false, false, true);
  5022. if (hend
  5023. && (hend->type == bfd_link_hash_defined
  5024. || hend->type == bfd_link_hash_defweak)
  5025. && hend->u.def.section->output_section != NULL)
  5026. {
  5027. bfd_vma value =
  5028. frvfdpic_gotfixup_section (info)->output_section->vma
  5029. + frvfdpic_gotfixup_section (info)->output_offset
  5030. + frvfdpic_gotfixup_section (info)->size
  5031. - hend->u.def.section->output_section->vma
  5032. - hend->u.def.section->output_offset;
  5033. BFD_ASSERT (hend->u.def.value == value);
  5034. if (hend->u.def.value != value)
  5035. goto error;
  5036. }
  5037. }
  5038. }
  5039. if (frvfdpic_pltrel_section (info))
  5040. {
  5041. BFD_ASSERT (frvfdpic_pltrel_section (info)->size
  5042. == (frvfdpic_pltrel_section (info)->reloc_count
  5043. * sizeof (Elf32_External_Rel)));
  5044. }
  5045. if (elf_hash_table (info)->dynamic_sections_created)
  5046. {
  5047. Elf32_External_Dyn * dyncon;
  5048. Elf32_External_Dyn * dynconend;
  5049. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  5050. BFD_ASSERT (sdyn != NULL);
  5051. dyncon = (Elf32_External_Dyn *) sdyn->contents;
  5052. dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
  5053. for (; dyncon < dynconend; dyncon++)
  5054. {
  5055. Elf_Internal_Dyn dyn;
  5056. bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
  5057. switch (dyn.d_tag)
  5058. {
  5059. default:
  5060. break;
  5061. case DT_PLTGOT:
  5062. dyn.d_un.d_ptr = frvfdpic_got_section (info)->output_section->vma
  5063. + frvfdpic_got_section (info)->output_offset
  5064. + frvfdpic_got_initial_offset (info);
  5065. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  5066. break;
  5067. case DT_JMPREL:
  5068. dyn.d_un.d_ptr = frvfdpic_pltrel_section (info)
  5069. ->output_section->vma
  5070. + frvfdpic_pltrel_section (info)->output_offset;
  5071. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  5072. break;
  5073. case DT_PLTRELSZ:
  5074. dyn.d_un.d_val = frvfdpic_pltrel_section (info)->size;
  5075. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  5076. break;
  5077. }
  5078. }
  5079. }
  5080. return true;
  5081. }
  5082. /* Adjust a symbol defined by a dynamic object and referenced by a
  5083. regular object. */
  5084. static bool
  5085. elf32_frvfdpic_adjust_dynamic_symbol
  5086. (struct bfd_link_info *info ATTRIBUTE_UNUSED,
  5087. struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
  5088. {
  5089. bfd * dynobj;
  5090. dynobj = elf_hash_table (info)->dynobj;
  5091. /* Make sure we know what is going on here. */
  5092. BFD_ASSERT (dynobj != NULL
  5093. && (h->is_weakalias
  5094. || (h->def_dynamic
  5095. && h->ref_regular
  5096. && !h->def_regular)));
  5097. /* If this is a weak symbol, and there is a real definition, the
  5098. processor independent code will have arranged for us to see the
  5099. real definition first, and we can just use the same value. */
  5100. if (h->is_weakalias)
  5101. {
  5102. struct elf_link_hash_entry *def = weakdef (h);
  5103. BFD_ASSERT (def->root.type == bfd_link_hash_defined);
  5104. h->root.u.def.section = def->root.u.def.section;
  5105. h->root.u.def.value = def->root.u.def.value;
  5106. return true;
  5107. }
  5108. return true;
  5109. }
  5110. /* Perform any actions needed for dynamic symbols. */
  5111. static bool
  5112. elf32_frvfdpic_finish_dynamic_symbol
  5113. (bfd *output_bfd ATTRIBUTE_UNUSED,
  5114. struct bfd_link_info *info ATTRIBUTE_UNUSED,
  5115. struct elf_link_hash_entry *h ATTRIBUTE_UNUSED,
  5116. Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
  5117. {
  5118. return true;
  5119. }
  5120. /* Decide whether to attempt to turn absptr or lsda encodings in
  5121. shared libraries into pcrel within the given input section. */
  5122. static bool
  5123. frvfdpic_elf_use_relative_eh_frame
  5124. (bfd *input_bfd ATTRIBUTE_UNUSED,
  5125. struct bfd_link_info *info ATTRIBUTE_UNUSED,
  5126. asection *eh_frame_section ATTRIBUTE_UNUSED)
  5127. {
  5128. /* We can't use PC-relative encodings in FDPIC binaries, in general. */
  5129. return false;
  5130. }
  5131. /* Adjust the contents of an eh_frame_hdr section before they're output. */
  5132. static bfd_byte
  5133. frvfdpic_elf_encode_eh_address (bfd *abfd,
  5134. struct bfd_link_info *info,
  5135. asection *osec, bfd_vma offset,
  5136. asection *loc_sec, bfd_vma loc_offset,
  5137. bfd_vma *encoded)
  5138. {
  5139. struct elf_link_hash_entry *h;
  5140. h = elf_hash_table (info)->hgot;
  5141. BFD_ASSERT (h && h->root.type == bfd_link_hash_defined);
  5142. if (! h || (_frvfdpic_osec_to_segment (abfd, osec)
  5143. == _frvfdpic_osec_to_segment (abfd, loc_sec->output_section)))
  5144. return _bfd_elf_encode_eh_address (abfd, info, osec, offset,
  5145. loc_sec, loc_offset, encoded);
  5146. BFD_ASSERT (_frvfdpic_osec_to_segment (abfd, osec)
  5147. == (_frvfdpic_osec_to_segment
  5148. (abfd, h->root.u.def.section->output_section)));
  5149. *encoded = osec->vma + offset
  5150. - (h->root.u.def.value
  5151. + h->root.u.def.section->output_section->vma
  5152. + h->root.u.def.section->output_offset);
  5153. return DW_EH_PE_datarel | DW_EH_PE_sdata4;
  5154. }
  5155. /* Look through the relocs for a section during the first phase.
  5156. Besides handling virtual table relocs for gc, we have to deal with
  5157. all sorts of PIC-related relocations. We describe below the
  5158. general plan on how to handle such relocations, even though we only
  5159. collect information at this point, storing them in hash tables for
  5160. perusal of later passes.
  5161. 32 relocations are propagated to the linker output when creating
  5162. position-independent output. LO16 and HI16 relocations are not
  5163. supposed to be encountered in this case.
  5164. LABEL16 should always be resolvable by the linker, since it's only
  5165. used by branches.
  5166. LABEL24, on the other hand, is used by calls. If it turns out that
  5167. the target of a call is a dynamic symbol, a PLT entry must be
  5168. created for it, which triggers the creation of a private function
  5169. descriptor and, unless lazy binding is disabled, a lazy PLT entry.
  5170. GPREL relocations require the referenced symbol to be in the same
  5171. segment as _gp, but this can only be checked later.
  5172. All GOT, GOTOFF and FUNCDESC relocations require a .got section to
  5173. exist. LABEL24 might as well, since it may require a PLT entry,
  5174. that will require a got.
  5175. Non-FUNCDESC GOT relocations require a GOT entry to be created
  5176. regardless of whether the symbol is dynamic. However, since a
  5177. global symbol that turns out to not be exported may have the same
  5178. address of a non-dynamic symbol, we don't assign GOT entries at
  5179. this point, such that we can share them in this case. A relocation
  5180. for the GOT entry always has to be created, be it to offset a
  5181. private symbol by the section load address, be it to get the symbol
  5182. resolved dynamically.
  5183. FUNCDESC GOT relocations require a GOT entry to be created, and
  5184. handled as if a FUNCDESC relocation was applied to the GOT entry in
  5185. an object file.
  5186. FUNCDESC relocations referencing a symbol that turns out to NOT be
  5187. dynamic cause a private function descriptor to be created. The
  5188. FUNCDESC relocation then decays to a 32 relocation that points at
  5189. the private descriptor. If the symbol is dynamic, the FUNCDESC
  5190. relocation is propagated to the linker output, such that the
  5191. dynamic linker creates the canonical descriptor, pointing to the
  5192. dynamically-resolved definition of the function.
  5193. Non-FUNCDESC GOTOFF relocations must always refer to non-dynamic
  5194. symbols that are assigned to the same segment as the GOT, but we
  5195. can only check this later, after we know the complete set of
  5196. symbols defined and/or exported.
  5197. FUNCDESC GOTOFF relocations require a function descriptor to be
  5198. created and, unless lazy binding is disabled or the symbol is not
  5199. dynamic, a lazy PLT entry. Since we can't tell at this point
  5200. whether a symbol is going to be dynamic, we have to decide later
  5201. whether to create a lazy PLT entry or bind the descriptor directly
  5202. to the private function.
  5203. FUNCDESC_VALUE relocations are not supposed to be present in object
  5204. files, but they may very well be simply propagated to the linker
  5205. output, since they have no side effect.
  5206. A function descriptor always requires a FUNCDESC_VALUE relocation.
  5207. Whether it's in .plt.rel or not depends on whether lazy binding is
  5208. enabled and on whether the referenced symbol is dynamic.
  5209. The existence of a lazy PLT requires the resolverStub lazy PLT
  5210. entry to be present.
  5211. As for assignment of GOT, PLT and lazy PLT entries, and private
  5212. descriptors, we might do them all sequentially, but we can do
  5213. better than that. For example, we can place GOT entries and
  5214. private function descriptors referenced using 12-bit operands
  5215. closer to the PIC register value, such that these relocations don't
  5216. overflow. Those that are only referenced with LO16 relocations
  5217. could come next, but we may as well place PLT-required function
  5218. descriptors in the 12-bit range to make them shorter. Symbols
  5219. referenced with LO16/HI16 may come next, but we may place
  5220. additional function descriptors in the 16-bit range if we can
  5221. reliably tell that we've already placed entries that are ever
  5222. referenced with only LO16. PLT entries are therefore generated as
  5223. small as possible, while not introducing relocation overflows in
  5224. GOT or FUNCDESC_GOTOFF relocations. Lazy PLT entries could be
  5225. generated before or after PLT entries, but not intermingled with
  5226. them, such that we can have more lazy PLT entries in range for a
  5227. branch to the resolverStub. The resolverStub should be emitted at
  5228. the most distant location from the first lazy PLT entry such that
  5229. it's still in range for a branch, or closer, if there isn't a need
  5230. for so many lazy PLT entries. Additional lazy PLT entries may be
  5231. emitted after the resolverStub, as long as branches are still in
  5232. range. If the branch goes out of range, longer lazy PLT entries
  5233. are emitted.
  5234. We could further optimize PLT and lazy PLT entries by giving them
  5235. priority in assignment to closer-to-gr17 locations depending on the
  5236. number of occurrences of references to them (assuming a function
  5237. that's called more often is more important for performance, so its
  5238. PLT entry should be faster), or taking hints from the compiler.
  5239. Given infinite time and money... :-) */
  5240. static bool
  5241. elf32_frv_check_relocs (bfd *abfd,
  5242. struct bfd_link_info *info,
  5243. asection *sec,
  5244. const Elf_Internal_Rela *relocs)
  5245. {
  5246. Elf_Internal_Shdr *symtab_hdr;
  5247. struct elf_link_hash_entry **sym_hashes;
  5248. const Elf_Internal_Rela *rel;
  5249. const Elf_Internal_Rela *rel_end;
  5250. bfd *dynobj;
  5251. struct frvfdpic_relocs_info *picrel;
  5252. if (bfd_link_relocatable (info))
  5253. return true;
  5254. symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  5255. sym_hashes = elf_sym_hashes (abfd);
  5256. dynobj = elf_hash_table (info)->dynobj;
  5257. rel_end = relocs + sec->reloc_count;
  5258. for (rel = relocs; rel < rel_end; rel++)
  5259. {
  5260. struct elf_link_hash_entry *h;
  5261. unsigned long r_symndx;
  5262. r_symndx = ELF32_R_SYM (rel->r_info);
  5263. if (r_symndx < symtab_hdr->sh_info)
  5264. h = NULL;
  5265. else
  5266. {
  5267. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  5268. while (h->root.type == bfd_link_hash_indirect
  5269. || h->root.type == bfd_link_hash_warning)
  5270. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  5271. }
  5272. switch (ELF32_R_TYPE (rel->r_info))
  5273. {
  5274. case R_FRV_GETTLSOFF:
  5275. case R_FRV_TLSDESC_VALUE:
  5276. case R_FRV_GOTTLSDESC12:
  5277. case R_FRV_GOTTLSDESCHI:
  5278. case R_FRV_GOTTLSDESCLO:
  5279. case R_FRV_GOTTLSOFF12:
  5280. case R_FRV_GOTTLSOFFHI:
  5281. case R_FRV_GOTTLSOFFLO:
  5282. case R_FRV_TLSOFF:
  5283. case R_FRV_GOT12:
  5284. case R_FRV_GOTHI:
  5285. case R_FRV_GOTLO:
  5286. case R_FRV_FUNCDESC_GOT12:
  5287. case R_FRV_FUNCDESC_GOTHI:
  5288. case R_FRV_FUNCDESC_GOTLO:
  5289. case R_FRV_GOTOFF12:
  5290. case R_FRV_GOTOFFHI:
  5291. case R_FRV_GOTOFFLO:
  5292. case R_FRV_FUNCDESC_GOTOFF12:
  5293. case R_FRV_FUNCDESC_GOTOFFHI:
  5294. case R_FRV_FUNCDESC_GOTOFFLO:
  5295. case R_FRV_FUNCDESC:
  5296. case R_FRV_FUNCDESC_VALUE:
  5297. case R_FRV_TLSMOFF12:
  5298. case R_FRV_TLSMOFFHI:
  5299. case R_FRV_TLSMOFFLO:
  5300. case R_FRV_TLSMOFF:
  5301. if (! IS_FDPIC (abfd))
  5302. goto bad_reloc;
  5303. /* Fall through. */
  5304. case R_FRV_GPREL12:
  5305. case R_FRV_GPRELU12:
  5306. case R_FRV_GPRELHI:
  5307. case R_FRV_GPRELLO:
  5308. case R_FRV_LABEL24:
  5309. case R_FRV_32:
  5310. if (! dynobj)
  5311. {
  5312. elf_hash_table (info)->dynobj = dynobj = abfd;
  5313. if (! _frv_create_got_section (abfd, info))
  5314. return false;
  5315. }
  5316. if (! IS_FDPIC (abfd))
  5317. {
  5318. picrel = NULL;
  5319. break;
  5320. }
  5321. if (h != NULL)
  5322. {
  5323. if (h->dynindx == -1)
  5324. switch (ELF_ST_VISIBILITY (h->other))
  5325. {
  5326. case STV_INTERNAL:
  5327. case STV_HIDDEN:
  5328. break;
  5329. default:
  5330. bfd_elf_link_record_dynamic_symbol (info, h);
  5331. break;
  5332. }
  5333. picrel
  5334. = frvfdpic_relocs_info_for_global (frvfdpic_relocs_info (info),
  5335. abfd, h,
  5336. rel->r_addend, INSERT);
  5337. }
  5338. else
  5339. picrel = frvfdpic_relocs_info_for_local (frvfdpic_relocs_info
  5340. (info), abfd, r_symndx,
  5341. rel->r_addend, INSERT);
  5342. if (! picrel)
  5343. return false;
  5344. break;
  5345. default:
  5346. picrel = NULL;
  5347. break;
  5348. }
  5349. switch (ELF32_R_TYPE (rel->r_info))
  5350. {
  5351. case R_FRV_LABEL24:
  5352. if (IS_FDPIC (abfd))
  5353. picrel->call = 1;
  5354. break;
  5355. case R_FRV_FUNCDESC_VALUE:
  5356. picrel->relocsfdv++;
  5357. if (bfd_section_flags (sec) & SEC_ALLOC)
  5358. picrel->relocs32--;
  5359. /* Fall through. */
  5360. case R_FRV_32:
  5361. if (! IS_FDPIC (abfd))
  5362. break;
  5363. picrel->sym = 1;
  5364. if (bfd_section_flags (sec) & SEC_ALLOC)
  5365. picrel->relocs32++;
  5366. break;
  5367. case R_FRV_GOT12:
  5368. picrel->got12 = 1;
  5369. break;
  5370. case R_FRV_GOTHI:
  5371. case R_FRV_GOTLO:
  5372. picrel->gothilo = 1;
  5373. break;
  5374. case R_FRV_FUNCDESC_GOT12:
  5375. picrel->fdgot12 = 1;
  5376. break;
  5377. case R_FRV_FUNCDESC_GOTHI:
  5378. case R_FRV_FUNCDESC_GOTLO:
  5379. picrel->fdgothilo = 1;
  5380. break;
  5381. case R_FRV_GOTOFF12:
  5382. case R_FRV_GOTOFFHI:
  5383. case R_FRV_GOTOFFLO:
  5384. picrel->gotoff = 1;
  5385. break;
  5386. case R_FRV_FUNCDESC_GOTOFF12:
  5387. picrel->fdgoff12 = 1;
  5388. break;
  5389. case R_FRV_FUNCDESC_GOTOFFHI:
  5390. case R_FRV_FUNCDESC_GOTOFFLO:
  5391. picrel->fdgoffhilo = 1;
  5392. break;
  5393. case R_FRV_FUNCDESC:
  5394. picrel->fd = 1;
  5395. picrel->relocsfd++;
  5396. break;
  5397. case R_FRV_GETTLSOFF:
  5398. picrel->tlsplt = 1;
  5399. break;
  5400. case R_FRV_TLSDESC_VALUE:
  5401. picrel->relocstlsd++;
  5402. goto bad_reloc;
  5403. case R_FRV_GOTTLSDESC12:
  5404. picrel->tlsdesc12 = 1;
  5405. break;
  5406. case R_FRV_GOTTLSDESCHI:
  5407. case R_FRV_GOTTLSDESCLO:
  5408. picrel->tlsdeschilo = 1;
  5409. break;
  5410. case R_FRV_TLSMOFF12:
  5411. case R_FRV_TLSMOFFHI:
  5412. case R_FRV_TLSMOFFLO:
  5413. case R_FRV_TLSMOFF:
  5414. break;
  5415. case R_FRV_GOTTLSOFF12:
  5416. picrel->tlsoff12 = 1;
  5417. info->flags |= DF_STATIC_TLS;
  5418. break;
  5419. case R_FRV_GOTTLSOFFHI:
  5420. case R_FRV_GOTTLSOFFLO:
  5421. picrel->tlsoffhilo = 1;
  5422. info->flags |= DF_STATIC_TLS;
  5423. break;
  5424. case R_FRV_TLSOFF:
  5425. picrel->relocstlsoff++;
  5426. info->flags |= DF_STATIC_TLS;
  5427. goto bad_reloc;
  5428. /* This relocation describes the C++ object vtable hierarchy.
  5429. Reconstruct it for later use during GC. */
  5430. case R_FRV_GNU_VTINHERIT:
  5431. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  5432. return false;
  5433. break;
  5434. /* This relocation describes which C++ vtable entries are actually
  5435. used. Record for later use during GC. */
  5436. case R_FRV_GNU_VTENTRY:
  5437. if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  5438. return false;
  5439. break;
  5440. case R_FRV_LABEL16:
  5441. case R_FRV_LO16:
  5442. case R_FRV_HI16:
  5443. case R_FRV_GPREL12:
  5444. case R_FRV_GPRELU12:
  5445. case R_FRV_GPREL32:
  5446. case R_FRV_GPRELHI:
  5447. case R_FRV_GPRELLO:
  5448. case R_FRV_TLSDESC_RELAX:
  5449. case R_FRV_GETTLSOFF_RELAX:
  5450. case R_FRV_TLSOFF_RELAX:
  5451. break;
  5452. default:
  5453. bad_reloc:
  5454. /* xgettext:c-format */
  5455. _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
  5456. abfd, (unsigned int) ELF32_R_TYPE (rel->r_info));
  5457. return false;
  5458. }
  5459. }
  5460. return true;
  5461. }
  5462. /* Return the machine subcode from the ELF e_flags header. */
  5463. static int
  5464. elf32_frv_machine (bfd *abfd)
  5465. {
  5466. switch (elf_elfheader (abfd)->e_flags & EF_FRV_CPU_MASK)
  5467. {
  5468. default: break;
  5469. case EF_FRV_CPU_FR550: return bfd_mach_fr550;
  5470. case EF_FRV_CPU_FR500: return bfd_mach_fr500;
  5471. case EF_FRV_CPU_FR450: return bfd_mach_fr450;
  5472. case EF_FRV_CPU_FR405: return bfd_mach_fr400;
  5473. case EF_FRV_CPU_FR400: return bfd_mach_fr400;
  5474. case EF_FRV_CPU_FR300: return bfd_mach_fr300;
  5475. case EF_FRV_CPU_SIMPLE: return bfd_mach_frvsimple;
  5476. case EF_FRV_CPU_TOMCAT: return bfd_mach_frvtomcat;
  5477. }
  5478. return bfd_mach_frv;
  5479. }
  5480. /* Set the right machine number for a FRV ELF file. */
  5481. static bool
  5482. elf32_frv_object_p (bfd *abfd)
  5483. {
  5484. bfd_default_set_arch_mach (abfd, bfd_arch_frv, elf32_frv_machine (abfd));
  5485. return (((elf_elfheader (abfd)->e_flags & EF_FRV_FDPIC) != 0)
  5486. == (IS_FDPIC (abfd)));
  5487. }
  5488. /* Function to set the ELF flag bits. */
  5489. static bool
  5490. frv_elf_set_private_flags (bfd *abfd, flagword flags)
  5491. {
  5492. elf_elfheader (abfd)->e_flags = flags;
  5493. elf_flags_init (abfd) = true;
  5494. return true;
  5495. }
  5496. /* Return true if the architecture described by elf header flag
  5497. EXTENSION is an extension of the architecture described by BASE. */
  5498. static bool
  5499. frv_elf_arch_extension_p (flagword base, flagword extension)
  5500. {
  5501. if (base == extension)
  5502. return true;
  5503. /* CPU_GENERIC code can be merged with code for a specific
  5504. architecture, in which case the result is marked as being
  5505. for the specific architecture. Everything is therefore
  5506. an extension of CPU_GENERIC. */
  5507. if (base == EF_FRV_CPU_GENERIC)
  5508. return true;
  5509. if (extension == EF_FRV_CPU_FR450)
  5510. if (base == EF_FRV_CPU_FR400 || base == EF_FRV_CPU_FR405)
  5511. return true;
  5512. if (extension == EF_FRV_CPU_FR405)
  5513. if (base == EF_FRV_CPU_FR400)
  5514. return true;
  5515. return false;
  5516. }
  5517. /* Merge backend specific data from an object file to the output
  5518. object file when linking. */
  5519. static bool
  5520. frv_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
  5521. {
  5522. bfd *obfd = info->output_bfd;
  5523. flagword old_flags, old_partial;
  5524. flagword new_flags, new_partial;
  5525. bool error = false;
  5526. char new_opt[80];
  5527. char old_opt[80];
  5528. /* FIXME: What should be checked when linking shared libraries? */
  5529. if ((ibfd->flags & DYNAMIC) != 0)
  5530. return true;
  5531. new_opt[0] = old_opt[0] = '\0';
  5532. new_flags = elf_elfheader (ibfd)->e_flags;
  5533. old_flags = elf_elfheader (obfd)->e_flags;
  5534. if (new_flags & EF_FRV_FDPIC)
  5535. new_flags &= ~EF_FRV_PIC;
  5536. #ifdef DEBUG
  5537. _bfd_error_handler
  5538. ("old_flags = 0x%.8x, new_flags = 0x%.8x, init = %s, filename = %s",
  5539. old_flags, new_flags, elf_flags_init (obfd) ? "yes" : "no",
  5540. bfd_get_filename (ibfd));
  5541. #endif
  5542. if (!elf_flags_init (obfd)) /* First call, no flags set. */
  5543. {
  5544. elf_flags_init (obfd) = true;
  5545. old_flags = new_flags;
  5546. }
  5547. else if (new_flags == old_flags) /* Compatible flags are ok. */
  5548. ;
  5549. else /* Possibly incompatible flags. */
  5550. {
  5551. /* Warn if different # of gprs are used. Note, 0 means nothing is
  5552. said about the size of gprs. */
  5553. new_partial = (new_flags & EF_FRV_GPR_MASK);
  5554. old_partial = (old_flags & EF_FRV_GPR_MASK);
  5555. if (new_partial == old_partial)
  5556. ;
  5557. else if (new_partial == 0)
  5558. ;
  5559. else if (old_partial == 0)
  5560. old_flags |= new_partial;
  5561. else
  5562. {
  5563. switch (new_partial)
  5564. {
  5565. default: strcat (new_opt, " -mgpr-??"); break;
  5566. case EF_FRV_GPR_32: strcat (new_opt, " -mgpr-32"); break;
  5567. case EF_FRV_GPR_64: strcat (new_opt, " -mgpr-64"); break;
  5568. }
  5569. switch (old_partial)
  5570. {
  5571. default: strcat (old_opt, " -mgpr-??"); break;
  5572. case EF_FRV_GPR_32: strcat (old_opt, " -mgpr-32"); break;
  5573. case EF_FRV_GPR_64: strcat (old_opt, " -mgpr-64"); break;
  5574. }
  5575. }
  5576. /* Warn if different # of fprs are used. Note, 0 means nothing is
  5577. said about the size of fprs. */
  5578. new_partial = (new_flags & EF_FRV_FPR_MASK);
  5579. old_partial = (old_flags & EF_FRV_FPR_MASK);
  5580. if (new_partial == old_partial)
  5581. ;
  5582. else if (new_partial == 0)
  5583. ;
  5584. else if (old_partial == 0)
  5585. old_flags |= new_partial;
  5586. else
  5587. {
  5588. switch (new_partial)
  5589. {
  5590. default: strcat (new_opt, " -mfpr-?"); break;
  5591. case EF_FRV_FPR_32: strcat (new_opt, " -mfpr-32"); break;
  5592. case EF_FRV_FPR_64: strcat (new_opt, " -mfpr-64"); break;
  5593. case EF_FRV_FPR_NONE: strcat (new_opt, " -msoft-float"); break;
  5594. }
  5595. switch (old_partial)
  5596. {
  5597. default: strcat (old_opt, " -mfpr-?"); break;
  5598. case EF_FRV_FPR_32: strcat (old_opt, " -mfpr-32"); break;
  5599. case EF_FRV_FPR_64: strcat (old_opt, " -mfpr-64"); break;
  5600. case EF_FRV_FPR_NONE: strcat (old_opt, " -msoft-float"); break;
  5601. }
  5602. }
  5603. /* Warn if different dword support was used. Note, 0 means nothing is
  5604. said about the dword support. */
  5605. new_partial = (new_flags & EF_FRV_DWORD_MASK);
  5606. old_partial = (old_flags & EF_FRV_DWORD_MASK);
  5607. if (new_partial == old_partial)
  5608. ;
  5609. else if (new_partial == 0)
  5610. ;
  5611. else if (old_partial == 0)
  5612. old_flags |= new_partial;
  5613. else
  5614. {
  5615. switch (new_partial)
  5616. {
  5617. default: strcat (new_opt, " -mdword-?"); break;
  5618. case EF_FRV_DWORD_YES: strcat (new_opt, " -mdword"); break;
  5619. case EF_FRV_DWORD_NO: strcat (new_opt, " -mno-dword"); break;
  5620. }
  5621. switch (old_partial)
  5622. {
  5623. default: strcat (old_opt, " -mdword-?"); break;
  5624. case EF_FRV_DWORD_YES: strcat (old_opt, " -mdword"); break;
  5625. case EF_FRV_DWORD_NO: strcat (old_opt, " -mno-dword"); break;
  5626. }
  5627. }
  5628. /* Or in flags that accumulate (ie, if one module uses it, mark that the
  5629. feature is used. */
  5630. old_flags |= new_flags & (EF_FRV_DOUBLE
  5631. | EF_FRV_MEDIA
  5632. | EF_FRV_MULADD
  5633. | EF_FRV_NON_PIC_RELOCS);
  5634. /* If any module was compiled without -G0, clear the G0 bit. */
  5635. old_flags = ((old_flags & ~ EF_FRV_G0)
  5636. | (old_flags & new_flags & EF_FRV_G0));
  5637. /* If any module was compiled without -mnopack, clear the mnopack bit. */
  5638. old_flags = ((old_flags & ~ EF_FRV_NOPACK)
  5639. | (old_flags & new_flags & EF_FRV_NOPACK));
  5640. /* We don't have to do anything if the pic flags are the same, or the new
  5641. module(s) were compiled with -mlibrary-pic. */
  5642. new_partial = (new_flags & EF_FRV_PIC_FLAGS);
  5643. old_partial = (old_flags & EF_FRV_PIC_FLAGS);
  5644. if ((new_partial == old_partial) || ((new_partial & EF_FRV_LIBPIC) != 0))
  5645. ;
  5646. /* If the old module(s) were compiled with -mlibrary-pic, copy in the pic
  5647. flags if any from the new module. */
  5648. else if ((old_partial & EF_FRV_LIBPIC) != 0)
  5649. old_flags = (old_flags & ~ EF_FRV_PIC_FLAGS) | new_partial;
  5650. /* If we have mixtures of -fpic and -fPIC, or in both bits. */
  5651. else if (new_partial != 0 && old_partial != 0)
  5652. old_flags |= new_partial;
  5653. /* One module was compiled for pic and the other was not, see if we have
  5654. had any relocations that are not pic-safe. */
  5655. else
  5656. {
  5657. if ((old_flags & EF_FRV_NON_PIC_RELOCS) == 0)
  5658. old_flags |= new_partial;
  5659. else
  5660. {
  5661. old_flags &= ~ EF_FRV_PIC_FLAGS;
  5662. #ifndef FRV_NO_PIC_ERROR
  5663. error = true;
  5664. _bfd_error_handler
  5665. /* xgettext:c-format */
  5666. (_("%pB: compiled with %s and linked with modules"
  5667. " that use non-pic relocations"),
  5668. ibfd, (new_flags & EF_FRV_BIGPIC) ? "-fPIC" : "-fpic");
  5669. #endif
  5670. }
  5671. }
  5672. /* Warn if different cpu is used (allow a specific cpu to override
  5673. the generic cpu). */
  5674. new_partial = (new_flags & EF_FRV_CPU_MASK);
  5675. old_partial = (old_flags & EF_FRV_CPU_MASK);
  5676. if (frv_elf_arch_extension_p (new_partial, old_partial))
  5677. ;
  5678. else if (frv_elf_arch_extension_p (old_partial, new_partial))
  5679. old_flags = (old_flags & ~EF_FRV_CPU_MASK) | new_partial;
  5680. else
  5681. {
  5682. switch (new_partial)
  5683. {
  5684. default: strcat (new_opt, " -mcpu=?"); break;
  5685. case EF_FRV_CPU_GENERIC: strcat (new_opt, " -mcpu=frv"); break;
  5686. case EF_FRV_CPU_SIMPLE: strcat (new_opt, " -mcpu=simple"); break;
  5687. case EF_FRV_CPU_FR550: strcat (new_opt, " -mcpu=fr550"); break;
  5688. case EF_FRV_CPU_FR500: strcat (new_opt, " -mcpu=fr500"); break;
  5689. case EF_FRV_CPU_FR450: strcat (new_opt, " -mcpu=fr450"); break;
  5690. case EF_FRV_CPU_FR405: strcat (new_opt, " -mcpu=fr405"); break;
  5691. case EF_FRV_CPU_FR400: strcat (new_opt, " -mcpu=fr400"); break;
  5692. case EF_FRV_CPU_FR300: strcat (new_opt, " -mcpu=fr300"); break;
  5693. case EF_FRV_CPU_TOMCAT: strcat (new_opt, " -mcpu=tomcat"); break;
  5694. }
  5695. switch (old_partial)
  5696. {
  5697. default: strcat (old_opt, " -mcpu=?"); break;
  5698. case EF_FRV_CPU_GENERIC: strcat (old_opt, " -mcpu=frv"); break;
  5699. case EF_FRV_CPU_SIMPLE: strcat (old_opt, " -mcpu=simple"); break;
  5700. case EF_FRV_CPU_FR550: strcat (old_opt, " -mcpu=fr550"); break;
  5701. case EF_FRV_CPU_FR500: strcat (old_opt, " -mcpu=fr500"); break;
  5702. case EF_FRV_CPU_FR450: strcat (old_opt, " -mcpu=fr450"); break;
  5703. case EF_FRV_CPU_FR405: strcat (old_opt, " -mcpu=fr405"); break;
  5704. case EF_FRV_CPU_FR400: strcat (old_opt, " -mcpu=fr400"); break;
  5705. case EF_FRV_CPU_FR300: strcat (old_opt, " -mcpu=fr300"); break;
  5706. case EF_FRV_CPU_TOMCAT: strcat (old_opt, " -mcpu=tomcat"); break;
  5707. }
  5708. }
  5709. /* Print out any mismatches from above. */
  5710. if (new_opt[0])
  5711. {
  5712. error = true;
  5713. _bfd_error_handler
  5714. /* xgettext:c-format */
  5715. (_("%pB: compiled with %s and linked with modules compiled with %s"),
  5716. ibfd, new_opt, old_opt);
  5717. }
  5718. /* Warn about any other mismatches */
  5719. new_partial = (new_flags & ~ EF_FRV_ALL_FLAGS);
  5720. old_partial = (old_flags & ~ EF_FRV_ALL_FLAGS);
  5721. if (new_partial != old_partial)
  5722. {
  5723. old_flags |= new_partial;
  5724. error = true;
  5725. _bfd_error_handler
  5726. /* xgettext:c-format */
  5727. (_("%pB: uses different unknown e_flags (%#x) fields"
  5728. " than previous modules (%#x)"),
  5729. ibfd, new_partial, old_partial);
  5730. }
  5731. }
  5732. /* If the cpu is -mcpu=simple, then set the -mnopack bit. */
  5733. if ((old_flags & EF_FRV_CPU_MASK) == EF_FRV_CPU_SIMPLE)
  5734. old_flags |= EF_FRV_NOPACK;
  5735. /* Update the old flags now with changes made above. */
  5736. old_partial = elf_elfheader (obfd)->e_flags & EF_FRV_CPU_MASK;
  5737. elf_elfheader (obfd)->e_flags = old_flags;
  5738. if (old_partial != (old_flags & EF_FRV_CPU_MASK))
  5739. bfd_default_set_arch_mach (obfd, bfd_arch_frv, elf32_frv_machine (obfd));
  5740. if (((new_flags & EF_FRV_FDPIC) == 0)
  5741. != (! IS_FDPIC (ibfd)))
  5742. {
  5743. error = true;
  5744. if (IS_FDPIC (obfd))
  5745. _bfd_error_handler
  5746. (_("%pB: cannot link non-fdpic object file into fdpic executable"),
  5747. ibfd);
  5748. else
  5749. _bfd_error_handler
  5750. (_("%pB: cannot link fdpic object file into non-fdpic executable"),
  5751. ibfd);
  5752. }
  5753. if (error)
  5754. bfd_set_error (bfd_error_bad_value);
  5755. return !error;
  5756. }
  5757. static bool
  5758. frv_elf_print_private_bfd_data (bfd *abfd, void * ptr)
  5759. {
  5760. FILE *file = (FILE *) ptr;
  5761. flagword flags;
  5762. BFD_ASSERT (abfd != NULL && ptr != NULL);
  5763. /* Print normal ELF private data. */
  5764. _bfd_elf_print_private_bfd_data (abfd, ptr);
  5765. flags = elf_elfheader (abfd)->e_flags;
  5766. fprintf (file, _("private flags = 0x%lx:"), (unsigned long) flags);
  5767. switch (flags & EF_FRV_CPU_MASK)
  5768. {
  5769. default: break;
  5770. case EF_FRV_CPU_SIMPLE: fprintf (file, " -mcpu=simple"); break;
  5771. case EF_FRV_CPU_FR550: fprintf (file, " -mcpu=fr550"); break;
  5772. case EF_FRV_CPU_FR500: fprintf (file, " -mcpu=fr500"); break;
  5773. case EF_FRV_CPU_FR450: fprintf (file, " -mcpu=fr450"); break;
  5774. case EF_FRV_CPU_FR405: fprintf (file, " -mcpu=fr405"); break;
  5775. case EF_FRV_CPU_FR400: fprintf (file, " -mcpu=fr400"); break;
  5776. case EF_FRV_CPU_FR300: fprintf (file, " -mcpu=fr300"); break;
  5777. case EF_FRV_CPU_TOMCAT: fprintf (file, " -mcpu=tomcat"); break;
  5778. }
  5779. switch (flags & EF_FRV_GPR_MASK)
  5780. {
  5781. default: break;
  5782. case EF_FRV_GPR_32: fprintf (file, " -mgpr-32"); break;
  5783. case EF_FRV_GPR_64: fprintf (file, " -mgpr-64"); break;
  5784. }
  5785. switch (flags & EF_FRV_FPR_MASK)
  5786. {
  5787. default: break;
  5788. case EF_FRV_FPR_32: fprintf (file, " -mfpr-32"); break;
  5789. case EF_FRV_FPR_64: fprintf (file, " -mfpr-64"); break;
  5790. case EF_FRV_FPR_NONE: fprintf (file, " -msoft-float"); break;
  5791. }
  5792. switch (flags & EF_FRV_DWORD_MASK)
  5793. {
  5794. default: break;
  5795. case EF_FRV_DWORD_YES: fprintf (file, " -mdword"); break;
  5796. case EF_FRV_DWORD_NO: fprintf (file, " -mno-dword"); break;
  5797. }
  5798. if (flags & EF_FRV_DOUBLE)
  5799. fprintf (file, " -mdouble");
  5800. if (flags & EF_FRV_MEDIA)
  5801. fprintf (file, " -mmedia");
  5802. if (flags & EF_FRV_MULADD)
  5803. fprintf (file, " -mmuladd");
  5804. if (flags & EF_FRV_PIC)
  5805. fprintf (file, " -fpic");
  5806. if (flags & EF_FRV_BIGPIC)
  5807. fprintf (file, " -fPIC");
  5808. if (flags & EF_FRV_LIBPIC)
  5809. fprintf (file, " -mlibrary-pic");
  5810. if (flags & EF_FRV_FDPIC)
  5811. fprintf (file, " -mfdpic");
  5812. if (flags & EF_FRV_NON_PIC_RELOCS)
  5813. fprintf (file, " non-pic relocations");
  5814. if (flags & EF_FRV_G0)
  5815. fprintf (file, " -G0");
  5816. fputc ('\n', file);
  5817. return true;
  5818. }
  5819. /* Support for core dump NOTE sections. */
  5820. static bool
  5821. elf32_frv_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
  5822. {
  5823. int offset;
  5824. unsigned int raw_size;
  5825. switch (note->descsz)
  5826. {
  5827. default:
  5828. return false;
  5829. /* The Linux/FRV elf_prstatus struct is 268 bytes long. The other
  5830. hardcoded offsets and sizes listed below (and contained within
  5831. this lexical block) refer to fields in the target's elf_prstatus
  5832. struct. */
  5833. case 268:
  5834. /* `pr_cursig' is at offset 12. */
  5835. elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
  5836. /* `pr_pid' is at offset 24. */
  5837. elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
  5838. /* `pr_reg' is at offset 72. */
  5839. offset = 72;
  5840. /* Most grok_prstatus implementations set `raw_size' to the size
  5841. of the pr_reg field. For Linux/FRV, we set `raw_size' to be
  5842. the size of `pr_reg' plus the size of `pr_exec_fdpic_loadmap'
  5843. and `pr_interp_fdpic_loadmap', both of which (by design)
  5844. immediately follow `pr_reg'. This will allow these fields to
  5845. be viewed by GDB as registers.
  5846. `pr_reg' is 184 bytes long. `pr_exec_fdpic_loadmap' and
  5847. `pr_interp_fdpic_loadmap' are 4 bytes each. */
  5848. raw_size = 184 + 4 + 4;
  5849. break;
  5850. }
  5851. /* Make a ".reg/999" section. */
  5852. return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size,
  5853. note->descpos + offset);
  5854. }
  5855. static bool
  5856. elf32_frv_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
  5857. {
  5858. switch (note->descsz)
  5859. {
  5860. default:
  5861. return false;
  5862. /* The Linux/FRV elf_prpsinfo struct is 124 bytes long. */
  5863. case 124:
  5864. /* `pr_fname' is found at offset 28 and is 16 bytes long. */
  5865. elf_tdata (abfd)->core->program
  5866. = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
  5867. /* `pr_psargs' is found at offset 44 and is 80 bytes long. */
  5868. elf_tdata (abfd)->core->command
  5869. = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
  5870. }
  5871. /* Note that for some reason, a spurious space is tacked
  5872. onto the end of the args in some (at least one anyway)
  5873. implementations, so strip it off if it exists. */
  5874. {
  5875. char *command = elf_tdata (abfd)->core->command;
  5876. int n = strlen (command);
  5877. if (0 < n && command[n - 1] == ' ')
  5878. command[n - 1] = '\0';
  5879. }
  5880. return true;
  5881. }
  5882. #define ELF_ARCH bfd_arch_frv
  5883. #define ELF_MACHINE_CODE EM_CYGNUS_FRV
  5884. #define ELF_MAXPAGESIZE 0x1000
  5885. #define TARGET_BIG_SYM frv_elf32_vec
  5886. #define TARGET_BIG_NAME "elf32-frv"
  5887. #define elf_info_to_howto frv_info_to_howto_rela
  5888. #define elf_backend_relocate_section elf32_frv_relocate_section
  5889. #define elf_backend_gc_mark_hook elf32_frv_gc_mark_hook
  5890. #define elf_backend_check_relocs elf32_frv_check_relocs
  5891. #define elf_backend_object_p elf32_frv_object_p
  5892. #define elf_backend_add_symbol_hook elf32_frv_add_symbol_hook
  5893. #define elf_backend_stack_align 8
  5894. #define elf_backend_can_gc_sections 1
  5895. #define elf_backend_rela_normal 1
  5896. #define bfd_elf32_bfd_reloc_type_lookup frv_reloc_type_lookup
  5897. #define bfd_elf32_bfd_reloc_name_lookup frv_reloc_name_lookup
  5898. #define bfd_elf32_bfd_set_private_flags frv_elf_set_private_flags
  5899. #define bfd_elf32_bfd_merge_private_bfd_data frv_elf_merge_private_bfd_data
  5900. #define bfd_elf32_bfd_print_private_bfd_data frv_elf_print_private_bfd_data
  5901. #define elf_backend_want_got_sym 1
  5902. #define elf_backend_got_header_size 0
  5903. #define elf_backend_want_got_plt 0
  5904. #define elf_backend_plt_readonly 1
  5905. #define elf_backend_want_plt_sym 0
  5906. #define elf_backend_plt_header_size 0
  5907. #define elf_backend_finish_dynamic_sections \
  5908. elf32_frv_finish_dynamic_sections
  5909. #define elf_backend_grok_prstatus elf32_frv_grok_prstatus
  5910. #define elf_backend_grok_psinfo elf32_frv_grok_psinfo
  5911. #define elf_backend_linux_prpsinfo32_ugid16 true
  5912. #include "elf32-target.h"
  5913. #undef ELF_TARGET_ID
  5914. #define ELF_TARGET_ID FRV_ELF_DATA
  5915. #undef ELF_MAXPAGESIZE
  5916. #define ELF_MAXPAGESIZE 0x4000
  5917. #undef TARGET_BIG_SYM
  5918. #define TARGET_BIG_SYM frv_elf32_fdpic_vec
  5919. #undef TARGET_BIG_NAME
  5920. #define TARGET_BIG_NAME "elf32-frvfdpic"
  5921. #undef elf32_bed
  5922. #define elf32_bed elf32_frvfdpic_bed
  5923. #undef elf_info_to_howto_rel
  5924. #define elf_info_to_howto_rel frvfdpic_info_to_howto_rel
  5925. #undef bfd_elf32_bfd_link_hash_table_create
  5926. #define bfd_elf32_bfd_link_hash_table_create \
  5927. frvfdpic_elf_link_hash_table_create
  5928. #undef elf_backend_always_size_sections
  5929. #define elf_backend_always_size_sections \
  5930. elf32_frvfdpic_always_size_sections
  5931. #undef elf_backend_create_dynamic_sections
  5932. #define elf_backend_create_dynamic_sections \
  5933. elf32_frvfdpic_create_dynamic_sections
  5934. #undef elf_backend_adjust_dynamic_symbol
  5935. #define elf_backend_adjust_dynamic_symbol \
  5936. elf32_frvfdpic_adjust_dynamic_symbol
  5937. #undef elf_backend_size_dynamic_sections
  5938. #define elf_backend_size_dynamic_sections \
  5939. elf32_frvfdpic_size_dynamic_sections
  5940. #undef bfd_elf32_bfd_relax_section
  5941. #define bfd_elf32_bfd_relax_section \
  5942. elf32_frvfdpic_relax_section
  5943. #undef elf_backend_finish_dynamic_symbol
  5944. #define elf_backend_finish_dynamic_symbol \
  5945. elf32_frvfdpic_finish_dynamic_symbol
  5946. #undef elf_backend_finish_dynamic_sections
  5947. #define elf_backend_finish_dynamic_sections \
  5948. elf32_frvfdpic_finish_dynamic_sections
  5949. #undef elf_backend_discard_info
  5950. #define elf_backend_discard_info \
  5951. frvfdpic_elf_discard_info
  5952. #undef elf_backend_can_make_relative_eh_frame
  5953. #define elf_backend_can_make_relative_eh_frame \
  5954. frvfdpic_elf_use_relative_eh_frame
  5955. #undef elf_backend_can_make_lsda_relative_eh_frame
  5956. #define elf_backend_can_make_lsda_relative_eh_frame \
  5957. frvfdpic_elf_use_relative_eh_frame
  5958. #undef elf_backend_encode_eh_address
  5959. #define elf_backend_encode_eh_address \
  5960. frvfdpic_elf_encode_eh_address
  5961. #undef elf_backend_may_use_rel_p
  5962. #define elf_backend_may_use_rel_p 1
  5963. #undef elf_backend_may_use_rela_p
  5964. #define elf_backend_may_use_rela_p 1
  5965. /* We use REL for dynamic relocations only. */
  5966. #undef elf_backend_default_use_rela_p
  5967. #define elf_backend_default_use_rela_p 1
  5968. #undef elf_backend_omit_section_dynsym
  5969. #define elf_backend_omit_section_dynsym _frvfdpic_link_omit_section_dynsym
  5970. #include "elf32-target.h"