elf32-frv.c 208 KB

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