elf64-ppc.c 443 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463
  1. /* PowerPC64-specific support for 64-bit ELF.
  2. Copyright (C) 1999-2015 Free Software Foundation, Inc.
  3. Written by Linus Nordberg, Swox AB <info@swox.com>,
  4. based on elf32-ppc.c by Ian Lance Taylor.
  5. Largely rewritten by Alan Modra.
  6. This file is part of BFD, the Binary File Descriptor library.
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 3 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License along
  16. with this program; if not, write to the Free Software Foundation, Inc.,
  17. 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  18. /* The 64-bit PowerPC ELF ABI may be found at
  19. http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
  20. http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
  21. #include "sysdep.h"
  22. #include <stdarg.h>
  23. #include "bfd.h"
  24. #include "bfdlink.h"
  25. #include "libbfd.h"
  26. #include "elf-bfd.h"
  27. #include "elf/ppc64.h"
  28. #include "elf64-ppc.h"
  29. #include "dwarf2.h"
  30. static bfd_reloc_status_type ppc64_elf_ha_reloc
  31. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  32. static bfd_reloc_status_type ppc64_elf_branch_reloc
  33. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  34. static bfd_reloc_status_type ppc64_elf_brtaken_reloc
  35. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  36. static bfd_reloc_status_type ppc64_elf_sectoff_reloc
  37. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  38. static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
  39. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  40. static bfd_reloc_status_type ppc64_elf_toc_reloc
  41. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  42. static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
  43. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  44. static bfd_reloc_status_type ppc64_elf_toc64_reloc
  45. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  46. static bfd_reloc_status_type ppc64_elf_unhandled_reloc
  47. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  48. static bfd_vma opd_entry_value
  49. (asection *, bfd_vma, asection **, bfd_vma *, bfd_boolean);
  50. #define TARGET_LITTLE_SYM powerpc_elf64_le_vec
  51. #define TARGET_LITTLE_NAME "elf64-powerpcle"
  52. #define TARGET_BIG_SYM powerpc_elf64_vec
  53. #define TARGET_BIG_NAME "elf64-powerpc"
  54. #define ELF_ARCH bfd_arch_powerpc
  55. #define ELF_TARGET_ID PPC64_ELF_DATA
  56. #define ELF_MACHINE_CODE EM_PPC64
  57. #define ELF_MAXPAGESIZE 0x10000
  58. #define ELF_COMMONPAGESIZE 0x10000
  59. #define elf_info_to_howto ppc64_elf_info_to_howto
  60. #define elf_backend_want_got_sym 0
  61. #define elf_backend_want_plt_sym 0
  62. #define elf_backend_plt_alignment 3
  63. #define elf_backend_plt_not_loaded 1
  64. #define elf_backend_got_header_size 8
  65. #define elf_backend_can_gc_sections 1
  66. #define elf_backend_can_refcount 1
  67. #define elf_backend_rela_normal 1
  68. #define elf_backend_default_execstack 0
  69. #define bfd_elf64_mkobject ppc64_elf_mkobject
  70. #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
  71. #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
  72. #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
  73. #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
  74. #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
  75. #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
  76. #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
  77. #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
  78. #define elf_backend_object_p ppc64_elf_object_p
  79. #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
  80. #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
  81. #define elf_backend_write_core_note ppc64_elf_write_core_note
  82. #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
  83. #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
  84. #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
  85. #define elf_backend_check_directives ppc64_elf_before_check_relocs
  86. #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
  87. #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
  88. #define elf_backend_check_relocs ppc64_elf_check_relocs
  89. #define elf_backend_gc_keep ppc64_elf_gc_keep
  90. #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
  91. #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
  92. #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
  93. #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
  94. #define elf_backend_hide_symbol ppc64_elf_hide_symbol
  95. #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
  96. #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
  97. #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
  98. #define elf_backend_hash_symbol ppc64_elf_hash_symbol
  99. #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
  100. #define elf_backend_action_discarded ppc64_elf_action_discarded
  101. #define elf_backend_relocate_section ppc64_elf_relocate_section
  102. #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
  103. #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
  104. #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
  105. #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
  106. #define elf_backend_special_sections ppc64_elf_special_sections
  107. #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
  108. /* The name of the dynamic interpreter. This is put in the .interp
  109. section. */
  110. #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
  111. /* The size in bytes of an entry in the procedure linkage table. */
  112. #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
  113. /* The initial size of the plt reserved for the dynamic linker. */
  114. #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
  115. /* Offsets to some stack save slots. */
  116. #define STK_LR 16
  117. #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
  118. /* This one is dodgy. ELFv2 does not have a linker word, so use the
  119. CR save slot. Used only by optimised __tls_get_addr call stub,
  120. relying on __tls_get_addr_opt not saving CR.. */
  121. #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
  122. /* TOC base pointers offset from start of TOC. */
  123. #define TOC_BASE_OFF 0x8000
  124. /* TOC base alignment. */
  125. #define TOC_BASE_ALIGN 256
  126. /* Offset of tp and dtp pointers from start of TLS block. */
  127. #define TP_OFFSET 0x7000
  128. #define DTP_OFFSET 0x8000
  129. /* .plt call stub instructions. The normal stub is like this, but
  130. sometimes the .plt entry crosses a 64k boundary and we need to
  131. insert an addi to adjust r11. */
  132. #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
  133. #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
  134. #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
  135. #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
  136. #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
  137. #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
  138. #define BCTR 0x4e800420 /* bctr */
  139. #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
  140. #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
  141. #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
  142. #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
  143. #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
  144. #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
  145. #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
  146. #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
  147. #define BNECTR 0x4ca20420 /* bnectr+ */
  148. #define BNECTR_P4 0x4ce20420 /* bnectr+ */
  149. #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
  150. #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
  151. #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
  152. #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
  153. #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
  154. #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
  155. #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
  156. /* glink call stub instructions. We enter with the index in R0. */
  157. #define GLINK_CALL_STUB_SIZE (16*4)
  158. /* 0: */
  159. /* .quad plt0-1f */
  160. /* __glink: */
  161. #define MFLR_R12 0x7d8802a6 /* mflr %12 */
  162. #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
  163. /* 1: */
  164. #define MFLR_R11 0x7d6802a6 /* mflr %11 */
  165. /* ld %2,(0b-1b)(%11) */
  166. #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
  167. #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
  168. /* ld %12,0(%11) */
  169. /* ld %2,8(%11) */
  170. /* mtctr %12 */
  171. /* ld %11,16(%11) */
  172. /* bctr */
  173. #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
  174. #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
  175. #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
  176. #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
  177. #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
  178. /* Pad with this. */
  179. #define NOP 0x60000000
  180. /* Some other nops. */
  181. #define CROR_151515 0x4def7b82
  182. #define CROR_313131 0x4ffffb82
  183. /* .glink entries for the first 32k functions are two instructions. */
  184. #define LI_R0_0 0x38000000 /* li %r0,0 */
  185. #define B_DOT 0x48000000 /* b . */
  186. /* After that, we need two instructions to load the index, followed by
  187. a branch. */
  188. #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
  189. #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
  190. /* Instructions used by the save and restore reg functions. */
  191. #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
  192. #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
  193. #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
  194. #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
  195. #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
  196. #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
  197. #define LI_R12_0 0x39800000 /* li %r12,0 */
  198. #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
  199. #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
  200. #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
  201. #define BLR 0x4e800020 /* blr */
  202. /* Since .opd is an array of descriptors and each entry will end up
  203. with identical R_PPC64_RELATIVE relocs, there is really no need to
  204. propagate .opd relocs; The dynamic linker should be taught to
  205. relocate .opd without reloc entries. */
  206. #ifndef NO_OPD_RELOCS
  207. #define NO_OPD_RELOCS 0
  208. #endif
  209. #ifndef ARRAY_SIZE
  210. #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
  211. #endif
  212. static inline int
  213. abiversion (bfd *abfd)
  214. {
  215. return elf_elfheader (abfd)->e_flags & EF_PPC64_ABI;
  216. }
  217. static inline void
  218. set_abiversion (bfd *abfd, int ver)
  219. {
  220. elf_elfheader (abfd)->e_flags &= ~EF_PPC64_ABI;
  221. elf_elfheader (abfd)->e_flags |= ver & EF_PPC64_ABI;
  222. }
  223. #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
  224. /* Relocation HOWTO's. */
  225. static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max];
  226. static reloc_howto_type ppc64_elf_howto_raw[] = {
  227. /* This reloc does nothing. */
  228. HOWTO (R_PPC64_NONE, /* type */
  229. 0, /* rightshift */
  230. 3, /* size (0 = byte, 1 = short, 2 = long) */
  231. 0, /* bitsize */
  232. FALSE, /* pc_relative */
  233. 0, /* bitpos */
  234. complain_overflow_dont, /* complain_on_overflow */
  235. bfd_elf_generic_reloc, /* special_function */
  236. "R_PPC64_NONE", /* name */
  237. FALSE, /* partial_inplace */
  238. 0, /* src_mask */
  239. 0, /* dst_mask */
  240. FALSE), /* pcrel_offset */
  241. /* A standard 32 bit relocation. */
  242. HOWTO (R_PPC64_ADDR32, /* type */
  243. 0, /* rightshift */
  244. 2, /* size (0 = byte, 1 = short, 2 = long) */
  245. 32, /* bitsize */
  246. FALSE, /* pc_relative */
  247. 0, /* bitpos */
  248. complain_overflow_bitfield, /* complain_on_overflow */
  249. bfd_elf_generic_reloc, /* special_function */
  250. "R_PPC64_ADDR32", /* name */
  251. FALSE, /* partial_inplace */
  252. 0, /* src_mask */
  253. 0xffffffff, /* dst_mask */
  254. FALSE), /* pcrel_offset */
  255. /* An absolute 26 bit branch; the lower two bits must be zero.
  256. FIXME: we don't check that, we just clear them. */
  257. HOWTO (R_PPC64_ADDR24, /* type */
  258. 0, /* rightshift */
  259. 2, /* size (0 = byte, 1 = short, 2 = long) */
  260. 26, /* bitsize */
  261. FALSE, /* pc_relative */
  262. 0, /* bitpos */
  263. complain_overflow_bitfield, /* complain_on_overflow */
  264. bfd_elf_generic_reloc, /* special_function */
  265. "R_PPC64_ADDR24", /* name */
  266. FALSE, /* partial_inplace */
  267. 0, /* src_mask */
  268. 0x03fffffc, /* dst_mask */
  269. FALSE), /* pcrel_offset */
  270. /* A standard 16 bit relocation. */
  271. HOWTO (R_PPC64_ADDR16, /* type */
  272. 0, /* rightshift */
  273. 1, /* size (0 = byte, 1 = short, 2 = long) */
  274. 16, /* bitsize */
  275. FALSE, /* pc_relative */
  276. 0, /* bitpos */
  277. complain_overflow_bitfield, /* complain_on_overflow */
  278. bfd_elf_generic_reloc, /* special_function */
  279. "R_PPC64_ADDR16", /* name */
  280. FALSE, /* partial_inplace */
  281. 0, /* src_mask */
  282. 0xffff, /* dst_mask */
  283. FALSE), /* pcrel_offset */
  284. /* A 16 bit relocation without overflow. */
  285. HOWTO (R_PPC64_ADDR16_LO, /* type */
  286. 0, /* rightshift */
  287. 1, /* size (0 = byte, 1 = short, 2 = long) */
  288. 16, /* bitsize */
  289. FALSE, /* pc_relative */
  290. 0, /* bitpos */
  291. complain_overflow_dont,/* complain_on_overflow */
  292. bfd_elf_generic_reloc, /* special_function */
  293. "R_PPC64_ADDR16_LO", /* name */
  294. FALSE, /* partial_inplace */
  295. 0, /* src_mask */
  296. 0xffff, /* dst_mask */
  297. FALSE), /* pcrel_offset */
  298. /* Bits 16-31 of an address. */
  299. HOWTO (R_PPC64_ADDR16_HI, /* type */
  300. 16, /* rightshift */
  301. 1, /* size (0 = byte, 1 = short, 2 = long) */
  302. 16, /* bitsize */
  303. FALSE, /* pc_relative */
  304. 0, /* bitpos */
  305. complain_overflow_signed, /* complain_on_overflow */
  306. bfd_elf_generic_reloc, /* special_function */
  307. "R_PPC64_ADDR16_HI", /* name */
  308. FALSE, /* partial_inplace */
  309. 0, /* src_mask */
  310. 0xffff, /* dst_mask */
  311. FALSE), /* pcrel_offset */
  312. /* Bits 16-31 of an address, plus 1 if the contents of the low 16
  313. bits, treated as a signed number, is negative. */
  314. HOWTO (R_PPC64_ADDR16_HA, /* type */
  315. 16, /* rightshift */
  316. 1, /* size (0 = byte, 1 = short, 2 = long) */
  317. 16, /* bitsize */
  318. FALSE, /* pc_relative */
  319. 0, /* bitpos */
  320. complain_overflow_signed, /* complain_on_overflow */
  321. ppc64_elf_ha_reloc, /* special_function */
  322. "R_PPC64_ADDR16_HA", /* name */
  323. FALSE, /* partial_inplace */
  324. 0, /* src_mask */
  325. 0xffff, /* dst_mask */
  326. FALSE), /* pcrel_offset */
  327. /* An absolute 16 bit branch; the lower two bits must be zero.
  328. FIXME: we don't check that, we just clear them. */
  329. HOWTO (R_PPC64_ADDR14, /* type */
  330. 0, /* rightshift */
  331. 2, /* size (0 = byte, 1 = short, 2 = long) */
  332. 16, /* bitsize */
  333. FALSE, /* pc_relative */
  334. 0, /* bitpos */
  335. complain_overflow_signed, /* complain_on_overflow */
  336. ppc64_elf_branch_reloc, /* special_function */
  337. "R_PPC64_ADDR14", /* name */
  338. FALSE, /* partial_inplace */
  339. 0, /* src_mask */
  340. 0x0000fffc, /* dst_mask */
  341. FALSE), /* pcrel_offset */
  342. /* An absolute 16 bit branch, for which bit 10 should be set to
  343. indicate that the branch is expected to be taken. The lower two
  344. bits must be zero. */
  345. HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
  346. 0, /* rightshift */
  347. 2, /* size (0 = byte, 1 = short, 2 = long) */
  348. 16, /* bitsize */
  349. FALSE, /* pc_relative */
  350. 0, /* bitpos */
  351. complain_overflow_signed, /* complain_on_overflow */
  352. ppc64_elf_brtaken_reloc, /* special_function */
  353. "R_PPC64_ADDR14_BRTAKEN",/* name */
  354. FALSE, /* partial_inplace */
  355. 0, /* src_mask */
  356. 0x0000fffc, /* dst_mask */
  357. FALSE), /* pcrel_offset */
  358. /* An absolute 16 bit branch, for which bit 10 should be set to
  359. indicate that the branch is not expected to be taken. The lower
  360. two bits must be zero. */
  361. HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
  362. 0, /* rightshift */
  363. 2, /* size (0 = byte, 1 = short, 2 = long) */
  364. 16, /* bitsize */
  365. FALSE, /* pc_relative */
  366. 0, /* bitpos */
  367. complain_overflow_signed, /* complain_on_overflow */
  368. ppc64_elf_brtaken_reloc, /* special_function */
  369. "R_PPC64_ADDR14_BRNTAKEN",/* name */
  370. FALSE, /* partial_inplace */
  371. 0, /* src_mask */
  372. 0x0000fffc, /* dst_mask */
  373. FALSE), /* pcrel_offset */
  374. /* A relative 26 bit branch; the lower two bits must be zero. */
  375. HOWTO (R_PPC64_REL24, /* type */
  376. 0, /* rightshift */
  377. 2, /* size (0 = byte, 1 = short, 2 = long) */
  378. 26, /* bitsize */
  379. TRUE, /* pc_relative */
  380. 0, /* bitpos */
  381. complain_overflow_signed, /* complain_on_overflow */
  382. ppc64_elf_branch_reloc, /* special_function */
  383. "R_PPC64_REL24", /* name */
  384. FALSE, /* partial_inplace */
  385. 0, /* src_mask */
  386. 0x03fffffc, /* dst_mask */
  387. TRUE), /* pcrel_offset */
  388. /* A relative 16 bit branch; the lower two bits must be zero. */
  389. HOWTO (R_PPC64_REL14, /* type */
  390. 0, /* rightshift */
  391. 2, /* size (0 = byte, 1 = short, 2 = long) */
  392. 16, /* bitsize */
  393. TRUE, /* pc_relative */
  394. 0, /* bitpos */
  395. complain_overflow_signed, /* complain_on_overflow */
  396. ppc64_elf_branch_reloc, /* special_function */
  397. "R_PPC64_REL14", /* name */
  398. FALSE, /* partial_inplace */
  399. 0, /* src_mask */
  400. 0x0000fffc, /* dst_mask */
  401. TRUE), /* pcrel_offset */
  402. /* A relative 16 bit branch. Bit 10 should be set to indicate that
  403. the branch is expected to be taken. The lower two bits must be
  404. zero. */
  405. HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
  406. 0, /* rightshift */
  407. 2, /* size (0 = byte, 1 = short, 2 = long) */
  408. 16, /* bitsize */
  409. TRUE, /* pc_relative */
  410. 0, /* bitpos */
  411. complain_overflow_signed, /* complain_on_overflow */
  412. ppc64_elf_brtaken_reloc, /* special_function */
  413. "R_PPC64_REL14_BRTAKEN", /* name */
  414. FALSE, /* partial_inplace */
  415. 0, /* src_mask */
  416. 0x0000fffc, /* dst_mask */
  417. TRUE), /* pcrel_offset */
  418. /* A relative 16 bit branch. Bit 10 should be set to indicate that
  419. the branch is not expected to be taken. The lower two bits must
  420. be zero. */
  421. HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
  422. 0, /* rightshift */
  423. 2, /* size (0 = byte, 1 = short, 2 = long) */
  424. 16, /* bitsize */
  425. TRUE, /* pc_relative */
  426. 0, /* bitpos */
  427. complain_overflow_signed, /* complain_on_overflow */
  428. ppc64_elf_brtaken_reloc, /* special_function */
  429. "R_PPC64_REL14_BRNTAKEN",/* name */
  430. FALSE, /* partial_inplace */
  431. 0, /* src_mask */
  432. 0x0000fffc, /* dst_mask */
  433. TRUE), /* pcrel_offset */
  434. /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
  435. symbol. */
  436. HOWTO (R_PPC64_GOT16, /* type */
  437. 0, /* rightshift */
  438. 1, /* size (0 = byte, 1 = short, 2 = long) */
  439. 16, /* bitsize */
  440. FALSE, /* pc_relative */
  441. 0, /* bitpos */
  442. complain_overflow_signed, /* complain_on_overflow */
  443. ppc64_elf_unhandled_reloc, /* special_function */
  444. "R_PPC64_GOT16", /* name */
  445. FALSE, /* partial_inplace */
  446. 0, /* src_mask */
  447. 0xffff, /* dst_mask */
  448. FALSE), /* pcrel_offset */
  449. /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
  450. the symbol. */
  451. HOWTO (R_PPC64_GOT16_LO, /* type */
  452. 0, /* rightshift */
  453. 1, /* size (0 = byte, 1 = short, 2 = long) */
  454. 16, /* bitsize */
  455. FALSE, /* pc_relative */
  456. 0, /* bitpos */
  457. complain_overflow_dont, /* complain_on_overflow */
  458. ppc64_elf_unhandled_reloc, /* special_function */
  459. "R_PPC64_GOT16_LO", /* name */
  460. FALSE, /* partial_inplace */
  461. 0, /* src_mask */
  462. 0xffff, /* dst_mask */
  463. FALSE), /* pcrel_offset */
  464. /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
  465. the symbol. */
  466. HOWTO (R_PPC64_GOT16_HI, /* type */
  467. 16, /* rightshift */
  468. 1, /* size (0 = byte, 1 = short, 2 = long) */
  469. 16, /* bitsize */
  470. FALSE, /* pc_relative */
  471. 0, /* bitpos */
  472. complain_overflow_signed,/* complain_on_overflow */
  473. ppc64_elf_unhandled_reloc, /* special_function */
  474. "R_PPC64_GOT16_HI", /* name */
  475. FALSE, /* partial_inplace */
  476. 0, /* src_mask */
  477. 0xffff, /* dst_mask */
  478. FALSE), /* pcrel_offset */
  479. /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
  480. the symbol. */
  481. HOWTO (R_PPC64_GOT16_HA, /* type */
  482. 16, /* rightshift */
  483. 1, /* size (0 = byte, 1 = short, 2 = long) */
  484. 16, /* bitsize */
  485. FALSE, /* pc_relative */
  486. 0, /* bitpos */
  487. complain_overflow_signed,/* complain_on_overflow */
  488. ppc64_elf_unhandled_reloc, /* special_function */
  489. "R_PPC64_GOT16_HA", /* name */
  490. FALSE, /* partial_inplace */
  491. 0, /* src_mask */
  492. 0xffff, /* dst_mask */
  493. FALSE), /* pcrel_offset */
  494. /* This is used only by the dynamic linker. The symbol should exist
  495. both in the object being run and in some shared library. The
  496. dynamic linker copies the data addressed by the symbol from the
  497. shared library into the object, because the object being
  498. run has to have the data at some particular address. */
  499. HOWTO (R_PPC64_COPY, /* type */
  500. 0, /* rightshift */
  501. 0, /* this one is variable size */
  502. 0, /* bitsize */
  503. FALSE, /* pc_relative */
  504. 0, /* bitpos */
  505. complain_overflow_dont, /* complain_on_overflow */
  506. ppc64_elf_unhandled_reloc, /* special_function */
  507. "R_PPC64_COPY", /* name */
  508. FALSE, /* partial_inplace */
  509. 0, /* src_mask */
  510. 0, /* dst_mask */
  511. FALSE), /* pcrel_offset */
  512. /* Like R_PPC64_ADDR64, but used when setting global offset table
  513. entries. */
  514. HOWTO (R_PPC64_GLOB_DAT, /* type */
  515. 0, /* rightshift */
  516. 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
  517. 64, /* bitsize */
  518. FALSE, /* pc_relative */
  519. 0, /* bitpos */
  520. complain_overflow_dont, /* complain_on_overflow */
  521. ppc64_elf_unhandled_reloc, /* special_function */
  522. "R_PPC64_GLOB_DAT", /* name */
  523. FALSE, /* partial_inplace */
  524. 0, /* src_mask */
  525. ONES (64), /* dst_mask */
  526. FALSE), /* pcrel_offset */
  527. /* Created by the link editor. Marks a procedure linkage table
  528. entry for a symbol. */
  529. HOWTO (R_PPC64_JMP_SLOT, /* type */
  530. 0, /* rightshift */
  531. 0, /* size (0 = byte, 1 = short, 2 = long) */
  532. 0, /* bitsize */
  533. FALSE, /* pc_relative */
  534. 0, /* bitpos */
  535. complain_overflow_dont, /* complain_on_overflow */
  536. ppc64_elf_unhandled_reloc, /* special_function */
  537. "R_PPC64_JMP_SLOT", /* name */
  538. FALSE, /* partial_inplace */
  539. 0, /* src_mask */
  540. 0, /* dst_mask */
  541. FALSE), /* pcrel_offset */
  542. /* Used only by the dynamic linker. When the object is run, this
  543. doubleword64 is set to the load address of the object, plus the
  544. addend. */
  545. HOWTO (R_PPC64_RELATIVE, /* type */
  546. 0, /* rightshift */
  547. 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
  548. 64, /* bitsize */
  549. FALSE, /* pc_relative */
  550. 0, /* bitpos */
  551. complain_overflow_dont, /* complain_on_overflow */
  552. bfd_elf_generic_reloc, /* special_function */
  553. "R_PPC64_RELATIVE", /* name */
  554. FALSE, /* partial_inplace */
  555. 0, /* src_mask */
  556. ONES (64), /* dst_mask */
  557. FALSE), /* pcrel_offset */
  558. /* Like R_PPC64_ADDR32, but may be unaligned. */
  559. HOWTO (R_PPC64_UADDR32, /* type */
  560. 0, /* rightshift */
  561. 2, /* size (0 = byte, 1 = short, 2 = long) */
  562. 32, /* bitsize */
  563. FALSE, /* pc_relative */
  564. 0, /* bitpos */
  565. complain_overflow_bitfield, /* complain_on_overflow */
  566. bfd_elf_generic_reloc, /* special_function */
  567. "R_PPC64_UADDR32", /* name */
  568. FALSE, /* partial_inplace */
  569. 0, /* src_mask */
  570. 0xffffffff, /* dst_mask */
  571. FALSE), /* pcrel_offset */
  572. /* Like R_PPC64_ADDR16, but may be unaligned. */
  573. HOWTO (R_PPC64_UADDR16, /* type */
  574. 0, /* rightshift */
  575. 1, /* size (0 = byte, 1 = short, 2 = long) */
  576. 16, /* bitsize */
  577. FALSE, /* pc_relative */
  578. 0, /* bitpos */
  579. complain_overflow_bitfield, /* complain_on_overflow */
  580. bfd_elf_generic_reloc, /* special_function */
  581. "R_PPC64_UADDR16", /* name */
  582. FALSE, /* partial_inplace */
  583. 0, /* src_mask */
  584. 0xffff, /* dst_mask */
  585. FALSE), /* pcrel_offset */
  586. /* 32-bit PC relative. */
  587. HOWTO (R_PPC64_REL32, /* type */
  588. 0, /* rightshift */
  589. 2, /* size (0 = byte, 1 = short, 2 = long) */
  590. 32, /* bitsize */
  591. TRUE, /* pc_relative */
  592. 0, /* bitpos */
  593. complain_overflow_signed, /* complain_on_overflow */
  594. bfd_elf_generic_reloc, /* special_function */
  595. "R_PPC64_REL32", /* name */
  596. FALSE, /* partial_inplace */
  597. 0, /* src_mask */
  598. 0xffffffff, /* dst_mask */
  599. TRUE), /* pcrel_offset */
  600. /* 32-bit relocation to the symbol's procedure linkage table. */
  601. HOWTO (R_PPC64_PLT32, /* type */
  602. 0, /* rightshift */
  603. 2, /* size (0 = byte, 1 = short, 2 = long) */
  604. 32, /* bitsize */
  605. FALSE, /* pc_relative */
  606. 0, /* bitpos */
  607. complain_overflow_bitfield, /* complain_on_overflow */
  608. ppc64_elf_unhandled_reloc, /* special_function */
  609. "R_PPC64_PLT32", /* name */
  610. FALSE, /* partial_inplace */
  611. 0, /* src_mask */
  612. 0xffffffff, /* dst_mask */
  613. FALSE), /* pcrel_offset */
  614. /* 32-bit PC relative relocation to the symbol's procedure linkage table.
  615. FIXME: R_PPC64_PLTREL32 not supported. */
  616. HOWTO (R_PPC64_PLTREL32, /* type */
  617. 0, /* rightshift */
  618. 2, /* size (0 = byte, 1 = short, 2 = long) */
  619. 32, /* bitsize */
  620. TRUE, /* pc_relative */
  621. 0, /* bitpos */
  622. complain_overflow_signed, /* complain_on_overflow */
  623. bfd_elf_generic_reloc, /* special_function */
  624. "R_PPC64_PLTREL32", /* name */
  625. FALSE, /* partial_inplace */
  626. 0, /* src_mask */
  627. 0xffffffff, /* dst_mask */
  628. TRUE), /* pcrel_offset */
  629. /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
  630. the symbol. */
  631. HOWTO (R_PPC64_PLT16_LO, /* type */
  632. 0, /* rightshift */
  633. 1, /* size (0 = byte, 1 = short, 2 = long) */
  634. 16, /* bitsize */
  635. FALSE, /* pc_relative */
  636. 0, /* bitpos */
  637. complain_overflow_dont, /* complain_on_overflow */
  638. ppc64_elf_unhandled_reloc, /* special_function */
  639. "R_PPC64_PLT16_LO", /* name */
  640. FALSE, /* partial_inplace */
  641. 0, /* src_mask */
  642. 0xffff, /* dst_mask */
  643. FALSE), /* pcrel_offset */
  644. /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
  645. the symbol. */
  646. HOWTO (R_PPC64_PLT16_HI, /* type */
  647. 16, /* rightshift */
  648. 1, /* size (0 = byte, 1 = short, 2 = long) */
  649. 16, /* bitsize */
  650. FALSE, /* pc_relative */
  651. 0, /* bitpos */
  652. complain_overflow_signed, /* complain_on_overflow */
  653. ppc64_elf_unhandled_reloc, /* special_function */
  654. "R_PPC64_PLT16_HI", /* name */
  655. FALSE, /* partial_inplace */
  656. 0, /* src_mask */
  657. 0xffff, /* dst_mask */
  658. FALSE), /* pcrel_offset */
  659. /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
  660. the symbol. */
  661. HOWTO (R_PPC64_PLT16_HA, /* type */
  662. 16, /* rightshift */
  663. 1, /* size (0 = byte, 1 = short, 2 = long) */
  664. 16, /* bitsize */
  665. FALSE, /* pc_relative */
  666. 0, /* bitpos */
  667. complain_overflow_signed, /* complain_on_overflow */
  668. ppc64_elf_unhandled_reloc, /* special_function */
  669. "R_PPC64_PLT16_HA", /* name */
  670. FALSE, /* partial_inplace */
  671. 0, /* src_mask */
  672. 0xffff, /* dst_mask */
  673. FALSE), /* pcrel_offset */
  674. /* 16-bit section relative relocation. */
  675. HOWTO (R_PPC64_SECTOFF, /* type */
  676. 0, /* rightshift */
  677. 1, /* size (0 = byte, 1 = short, 2 = long) */
  678. 16, /* bitsize */
  679. FALSE, /* pc_relative */
  680. 0, /* bitpos */
  681. complain_overflow_signed, /* complain_on_overflow */
  682. ppc64_elf_sectoff_reloc, /* special_function */
  683. "R_PPC64_SECTOFF", /* name */
  684. FALSE, /* partial_inplace */
  685. 0, /* src_mask */
  686. 0xffff, /* dst_mask */
  687. FALSE), /* pcrel_offset */
  688. /* Like R_PPC64_SECTOFF, but no overflow warning. */
  689. HOWTO (R_PPC64_SECTOFF_LO, /* type */
  690. 0, /* rightshift */
  691. 1, /* size (0 = byte, 1 = short, 2 = long) */
  692. 16, /* bitsize */
  693. FALSE, /* pc_relative */
  694. 0, /* bitpos */
  695. complain_overflow_dont, /* complain_on_overflow */
  696. ppc64_elf_sectoff_reloc, /* special_function */
  697. "R_PPC64_SECTOFF_LO", /* name */
  698. FALSE, /* partial_inplace */
  699. 0, /* src_mask */
  700. 0xffff, /* dst_mask */
  701. FALSE), /* pcrel_offset */
  702. /* 16-bit upper half section relative relocation. */
  703. HOWTO (R_PPC64_SECTOFF_HI, /* type */
  704. 16, /* rightshift */
  705. 1, /* size (0 = byte, 1 = short, 2 = long) */
  706. 16, /* bitsize */
  707. FALSE, /* pc_relative */
  708. 0, /* bitpos */
  709. complain_overflow_signed, /* complain_on_overflow */
  710. ppc64_elf_sectoff_reloc, /* special_function */
  711. "R_PPC64_SECTOFF_HI", /* name */
  712. FALSE, /* partial_inplace */
  713. 0, /* src_mask */
  714. 0xffff, /* dst_mask */
  715. FALSE), /* pcrel_offset */
  716. /* 16-bit upper half adjusted section relative relocation. */
  717. HOWTO (R_PPC64_SECTOFF_HA, /* type */
  718. 16, /* rightshift */
  719. 1, /* size (0 = byte, 1 = short, 2 = long) */
  720. 16, /* bitsize */
  721. FALSE, /* pc_relative */
  722. 0, /* bitpos */
  723. complain_overflow_signed, /* complain_on_overflow */
  724. ppc64_elf_sectoff_ha_reloc, /* special_function */
  725. "R_PPC64_SECTOFF_HA", /* name */
  726. FALSE, /* partial_inplace */
  727. 0, /* src_mask */
  728. 0xffff, /* dst_mask */
  729. FALSE), /* pcrel_offset */
  730. /* Like R_PPC64_REL24 without touching the two least significant bits. */
  731. HOWTO (R_PPC64_REL30, /* type */
  732. 2, /* rightshift */
  733. 2, /* size (0 = byte, 1 = short, 2 = long) */
  734. 30, /* bitsize */
  735. TRUE, /* pc_relative */
  736. 0, /* bitpos */
  737. complain_overflow_dont, /* complain_on_overflow */
  738. bfd_elf_generic_reloc, /* special_function */
  739. "R_PPC64_REL30", /* name */
  740. FALSE, /* partial_inplace */
  741. 0, /* src_mask */
  742. 0xfffffffc, /* dst_mask */
  743. TRUE), /* pcrel_offset */
  744. /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
  745. /* A standard 64-bit relocation. */
  746. HOWTO (R_PPC64_ADDR64, /* type */
  747. 0, /* rightshift */
  748. 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
  749. 64, /* bitsize */
  750. FALSE, /* pc_relative */
  751. 0, /* bitpos */
  752. complain_overflow_dont, /* complain_on_overflow */
  753. bfd_elf_generic_reloc, /* special_function */
  754. "R_PPC64_ADDR64", /* name */
  755. FALSE, /* partial_inplace */
  756. 0, /* src_mask */
  757. ONES (64), /* dst_mask */
  758. FALSE), /* pcrel_offset */
  759. /* The bits 32-47 of an address. */
  760. HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
  761. 32, /* rightshift */
  762. 1, /* size (0 = byte, 1 = short, 2 = long) */
  763. 16, /* bitsize */
  764. FALSE, /* pc_relative */
  765. 0, /* bitpos */
  766. complain_overflow_dont, /* complain_on_overflow */
  767. bfd_elf_generic_reloc, /* special_function */
  768. "R_PPC64_ADDR16_HIGHER", /* name */
  769. FALSE, /* partial_inplace */
  770. 0, /* src_mask */
  771. 0xffff, /* dst_mask */
  772. FALSE), /* pcrel_offset */
  773. /* The bits 32-47 of an address, plus 1 if the contents of the low
  774. 16 bits, treated as a signed number, is negative. */
  775. HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
  776. 32, /* rightshift */
  777. 1, /* size (0 = byte, 1 = short, 2 = long) */
  778. 16, /* bitsize */
  779. FALSE, /* pc_relative */
  780. 0, /* bitpos */
  781. complain_overflow_dont, /* complain_on_overflow */
  782. ppc64_elf_ha_reloc, /* special_function */
  783. "R_PPC64_ADDR16_HIGHERA", /* name */
  784. FALSE, /* partial_inplace */
  785. 0, /* src_mask */
  786. 0xffff, /* dst_mask */
  787. FALSE), /* pcrel_offset */
  788. /* The bits 48-63 of an address. */
  789. HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
  790. 48, /* rightshift */
  791. 1, /* size (0 = byte, 1 = short, 2 = long) */
  792. 16, /* bitsize */
  793. FALSE, /* pc_relative */
  794. 0, /* bitpos */
  795. complain_overflow_dont, /* complain_on_overflow */
  796. bfd_elf_generic_reloc, /* special_function */
  797. "R_PPC64_ADDR16_HIGHEST", /* name */
  798. FALSE, /* partial_inplace */
  799. 0, /* src_mask */
  800. 0xffff, /* dst_mask */
  801. FALSE), /* pcrel_offset */
  802. /* The bits 48-63 of an address, plus 1 if the contents of the low
  803. 16 bits, treated as a signed number, is negative. */
  804. HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
  805. 48, /* rightshift */
  806. 1, /* size (0 = byte, 1 = short, 2 = long) */
  807. 16, /* bitsize */
  808. FALSE, /* pc_relative */
  809. 0, /* bitpos */
  810. complain_overflow_dont, /* complain_on_overflow */
  811. ppc64_elf_ha_reloc, /* special_function */
  812. "R_PPC64_ADDR16_HIGHESTA", /* name */
  813. FALSE, /* partial_inplace */
  814. 0, /* src_mask */
  815. 0xffff, /* dst_mask */
  816. FALSE), /* pcrel_offset */
  817. /* Like ADDR64, but may be unaligned. */
  818. HOWTO (R_PPC64_UADDR64, /* type */
  819. 0, /* rightshift */
  820. 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
  821. 64, /* bitsize */
  822. FALSE, /* pc_relative */
  823. 0, /* bitpos */
  824. complain_overflow_dont, /* complain_on_overflow */
  825. bfd_elf_generic_reloc, /* special_function */
  826. "R_PPC64_UADDR64", /* name */
  827. FALSE, /* partial_inplace */
  828. 0, /* src_mask */
  829. ONES (64), /* dst_mask */
  830. FALSE), /* pcrel_offset */
  831. /* 64-bit relative relocation. */
  832. HOWTO (R_PPC64_REL64, /* type */
  833. 0, /* rightshift */
  834. 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
  835. 64, /* bitsize */
  836. TRUE, /* pc_relative */
  837. 0, /* bitpos */
  838. complain_overflow_dont, /* complain_on_overflow */
  839. bfd_elf_generic_reloc, /* special_function */
  840. "R_PPC64_REL64", /* name */
  841. FALSE, /* partial_inplace */
  842. 0, /* src_mask */
  843. ONES (64), /* dst_mask */
  844. TRUE), /* pcrel_offset */
  845. /* 64-bit relocation to the symbol's procedure linkage table. */
  846. HOWTO (R_PPC64_PLT64, /* type */
  847. 0, /* rightshift */
  848. 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
  849. 64, /* bitsize */
  850. FALSE, /* pc_relative */
  851. 0, /* bitpos */
  852. complain_overflow_dont, /* complain_on_overflow */
  853. ppc64_elf_unhandled_reloc, /* special_function */
  854. "R_PPC64_PLT64", /* name */
  855. FALSE, /* partial_inplace */
  856. 0, /* src_mask */
  857. ONES (64), /* dst_mask */
  858. FALSE), /* pcrel_offset */
  859. /* 64-bit PC relative relocation to the symbol's procedure linkage
  860. table. */
  861. /* FIXME: R_PPC64_PLTREL64 not supported. */
  862. HOWTO (R_PPC64_PLTREL64, /* type */
  863. 0, /* rightshift */
  864. 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
  865. 64, /* bitsize */
  866. TRUE, /* pc_relative */
  867. 0, /* bitpos */
  868. complain_overflow_dont, /* complain_on_overflow */
  869. ppc64_elf_unhandled_reloc, /* special_function */
  870. "R_PPC64_PLTREL64", /* name */
  871. FALSE, /* partial_inplace */
  872. 0, /* src_mask */
  873. ONES (64), /* dst_mask */
  874. TRUE), /* pcrel_offset */
  875. /* 16 bit TOC-relative relocation. */
  876. /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
  877. HOWTO (R_PPC64_TOC16, /* type */
  878. 0, /* rightshift */
  879. 1, /* size (0 = byte, 1 = short, 2 = long) */
  880. 16, /* bitsize */
  881. FALSE, /* pc_relative */
  882. 0, /* bitpos */
  883. complain_overflow_signed, /* complain_on_overflow */
  884. ppc64_elf_toc_reloc, /* special_function */
  885. "R_PPC64_TOC16", /* name */
  886. FALSE, /* partial_inplace */
  887. 0, /* src_mask */
  888. 0xffff, /* dst_mask */
  889. FALSE), /* pcrel_offset */
  890. /* 16 bit TOC-relative relocation without overflow. */
  891. /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
  892. HOWTO (R_PPC64_TOC16_LO, /* type */
  893. 0, /* rightshift */
  894. 1, /* size (0 = byte, 1 = short, 2 = long) */
  895. 16, /* bitsize */
  896. FALSE, /* pc_relative */
  897. 0, /* bitpos */
  898. complain_overflow_dont, /* complain_on_overflow */
  899. ppc64_elf_toc_reloc, /* special_function */
  900. "R_PPC64_TOC16_LO", /* name */
  901. FALSE, /* partial_inplace */
  902. 0, /* src_mask */
  903. 0xffff, /* dst_mask */
  904. FALSE), /* pcrel_offset */
  905. /* 16 bit TOC-relative relocation, high 16 bits. */
  906. /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
  907. HOWTO (R_PPC64_TOC16_HI, /* type */
  908. 16, /* rightshift */
  909. 1, /* size (0 = byte, 1 = short, 2 = long) */
  910. 16, /* bitsize */
  911. FALSE, /* pc_relative */
  912. 0, /* bitpos */
  913. complain_overflow_signed, /* complain_on_overflow */
  914. ppc64_elf_toc_reloc, /* special_function */
  915. "R_PPC64_TOC16_HI", /* name */
  916. FALSE, /* partial_inplace */
  917. 0, /* src_mask */
  918. 0xffff, /* dst_mask */
  919. FALSE), /* pcrel_offset */
  920. /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
  921. contents of the low 16 bits, treated as a signed number, is
  922. negative. */
  923. /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
  924. HOWTO (R_PPC64_TOC16_HA, /* type */
  925. 16, /* rightshift */
  926. 1, /* size (0 = byte, 1 = short, 2 = long) */
  927. 16, /* bitsize */
  928. FALSE, /* pc_relative */
  929. 0, /* bitpos */
  930. complain_overflow_signed, /* complain_on_overflow */
  931. ppc64_elf_toc_ha_reloc, /* special_function */
  932. "R_PPC64_TOC16_HA", /* name */
  933. FALSE, /* partial_inplace */
  934. 0, /* src_mask */
  935. 0xffff, /* dst_mask */
  936. FALSE), /* pcrel_offset */
  937. /* 64-bit relocation; insert value of TOC base (.TOC.). */
  938. /* R_PPC64_TOC 51 doubleword64 .TOC. */
  939. HOWTO (R_PPC64_TOC, /* type */
  940. 0, /* rightshift */
  941. 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
  942. 64, /* bitsize */
  943. FALSE, /* pc_relative */
  944. 0, /* bitpos */
  945. complain_overflow_dont, /* complain_on_overflow */
  946. ppc64_elf_toc64_reloc, /* special_function */
  947. "R_PPC64_TOC", /* name */
  948. FALSE, /* partial_inplace */
  949. 0, /* src_mask */
  950. ONES (64), /* dst_mask */
  951. FALSE), /* pcrel_offset */
  952. /* Like R_PPC64_GOT16, but also informs the link editor that the
  953. value to relocate may (!) refer to a PLT entry which the link
  954. editor (a) may replace with the symbol value. If the link editor
  955. is unable to fully resolve the symbol, it may (b) create a PLT
  956. entry and store the address to the new PLT entry in the GOT.
  957. This permits lazy resolution of function symbols at run time.
  958. The link editor may also skip all of this and just (c) emit a
  959. R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
  960. /* FIXME: R_PPC64_PLTGOT16 not implemented. */
  961. HOWTO (R_PPC64_PLTGOT16, /* type */
  962. 0, /* rightshift */
  963. 1, /* size (0 = byte, 1 = short, 2 = long) */
  964. 16, /* bitsize */
  965. FALSE, /* pc_relative */
  966. 0, /* bitpos */
  967. complain_overflow_signed, /* complain_on_overflow */
  968. ppc64_elf_unhandled_reloc, /* special_function */
  969. "R_PPC64_PLTGOT16", /* name */
  970. FALSE, /* partial_inplace */
  971. 0, /* src_mask */
  972. 0xffff, /* dst_mask */
  973. FALSE), /* pcrel_offset */
  974. /* Like R_PPC64_PLTGOT16, but without overflow. */
  975. /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
  976. HOWTO (R_PPC64_PLTGOT16_LO, /* type */
  977. 0, /* rightshift */
  978. 1, /* size (0 = byte, 1 = short, 2 = long) */
  979. 16, /* bitsize */
  980. FALSE, /* pc_relative */
  981. 0, /* bitpos */
  982. complain_overflow_dont, /* complain_on_overflow */
  983. ppc64_elf_unhandled_reloc, /* special_function */
  984. "R_PPC64_PLTGOT16_LO", /* name */
  985. FALSE, /* partial_inplace */
  986. 0, /* src_mask */
  987. 0xffff, /* dst_mask */
  988. FALSE), /* pcrel_offset */
  989. /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
  990. /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
  991. HOWTO (R_PPC64_PLTGOT16_HI, /* type */
  992. 16, /* rightshift */
  993. 1, /* size (0 = byte, 1 = short, 2 = long) */
  994. 16, /* bitsize */
  995. FALSE, /* pc_relative */
  996. 0, /* bitpos */
  997. complain_overflow_signed, /* complain_on_overflow */
  998. ppc64_elf_unhandled_reloc, /* special_function */
  999. "R_PPC64_PLTGOT16_HI", /* name */
  1000. FALSE, /* partial_inplace */
  1001. 0, /* src_mask */
  1002. 0xffff, /* dst_mask */
  1003. FALSE), /* pcrel_offset */
  1004. /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
  1005. 1 if the contents of the low 16 bits, treated as a signed number,
  1006. is negative. */
  1007. /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
  1008. HOWTO (R_PPC64_PLTGOT16_HA, /* type */
  1009. 16, /* rightshift */
  1010. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1011. 16, /* bitsize */
  1012. FALSE, /* pc_relative */
  1013. 0, /* bitpos */
  1014. complain_overflow_signed, /* complain_on_overflow */
  1015. ppc64_elf_unhandled_reloc, /* special_function */
  1016. "R_PPC64_PLTGOT16_HA", /* name */
  1017. FALSE, /* partial_inplace */
  1018. 0, /* src_mask */
  1019. 0xffff, /* dst_mask */
  1020. FALSE), /* pcrel_offset */
  1021. /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
  1022. HOWTO (R_PPC64_ADDR16_DS, /* type */
  1023. 0, /* rightshift */
  1024. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1025. 16, /* bitsize */
  1026. FALSE, /* pc_relative */
  1027. 0, /* bitpos */
  1028. complain_overflow_signed, /* complain_on_overflow */
  1029. bfd_elf_generic_reloc, /* special_function */
  1030. "R_PPC64_ADDR16_DS", /* name */
  1031. FALSE, /* partial_inplace */
  1032. 0, /* src_mask */
  1033. 0xfffc, /* dst_mask */
  1034. FALSE), /* pcrel_offset */
  1035. /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
  1036. HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
  1037. 0, /* rightshift */
  1038. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1039. 16, /* bitsize */
  1040. FALSE, /* pc_relative */
  1041. 0, /* bitpos */
  1042. complain_overflow_dont,/* complain_on_overflow */
  1043. bfd_elf_generic_reloc, /* special_function */
  1044. "R_PPC64_ADDR16_LO_DS",/* name */
  1045. FALSE, /* partial_inplace */
  1046. 0, /* src_mask */
  1047. 0xfffc, /* dst_mask */
  1048. FALSE), /* pcrel_offset */
  1049. /* Like R_PPC64_GOT16, but for instructions with a DS field. */
  1050. HOWTO (R_PPC64_GOT16_DS, /* type */
  1051. 0, /* rightshift */
  1052. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1053. 16, /* bitsize */
  1054. FALSE, /* pc_relative */
  1055. 0, /* bitpos */
  1056. complain_overflow_signed, /* complain_on_overflow */
  1057. ppc64_elf_unhandled_reloc, /* special_function */
  1058. "R_PPC64_GOT16_DS", /* name */
  1059. FALSE, /* partial_inplace */
  1060. 0, /* src_mask */
  1061. 0xfffc, /* dst_mask */
  1062. FALSE), /* pcrel_offset */
  1063. /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
  1064. HOWTO (R_PPC64_GOT16_LO_DS, /* type */
  1065. 0, /* rightshift */
  1066. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1067. 16, /* bitsize */
  1068. FALSE, /* pc_relative */
  1069. 0, /* bitpos */
  1070. complain_overflow_dont, /* complain_on_overflow */
  1071. ppc64_elf_unhandled_reloc, /* special_function */
  1072. "R_PPC64_GOT16_LO_DS", /* name */
  1073. FALSE, /* partial_inplace */
  1074. 0, /* src_mask */
  1075. 0xfffc, /* dst_mask */
  1076. FALSE), /* pcrel_offset */
  1077. /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
  1078. HOWTO (R_PPC64_PLT16_LO_DS, /* type */
  1079. 0, /* rightshift */
  1080. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1081. 16, /* bitsize */
  1082. FALSE, /* pc_relative */
  1083. 0, /* bitpos */
  1084. complain_overflow_dont, /* complain_on_overflow */
  1085. ppc64_elf_unhandled_reloc, /* special_function */
  1086. "R_PPC64_PLT16_LO_DS", /* name */
  1087. FALSE, /* partial_inplace */
  1088. 0, /* src_mask */
  1089. 0xfffc, /* dst_mask */
  1090. FALSE), /* pcrel_offset */
  1091. /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
  1092. HOWTO (R_PPC64_SECTOFF_DS, /* type */
  1093. 0, /* rightshift */
  1094. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1095. 16, /* bitsize */
  1096. FALSE, /* pc_relative */
  1097. 0, /* bitpos */
  1098. complain_overflow_signed, /* complain_on_overflow */
  1099. ppc64_elf_sectoff_reloc, /* special_function */
  1100. "R_PPC64_SECTOFF_DS", /* name */
  1101. FALSE, /* partial_inplace */
  1102. 0, /* src_mask */
  1103. 0xfffc, /* dst_mask */
  1104. FALSE), /* pcrel_offset */
  1105. /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
  1106. HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
  1107. 0, /* rightshift */
  1108. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1109. 16, /* bitsize */
  1110. FALSE, /* pc_relative */
  1111. 0, /* bitpos */
  1112. complain_overflow_dont, /* complain_on_overflow */
  1113. ppc64_elf_sectoff_reloc, /* special_function */
  1114. "R_PPC64_SECTOFF_LO_DS",/* name */
  1115. FALSE, /* partial_inplace */
  1116. 0, /* src_mask */
  1117. 0xfffc, /* dst_mask */
  1118. FALSE), /* pcrel_offset */
  1119. /* Like R_PPC64_TOC16, but for instructions with a DS field. */
  1120. HOWTO (R_PPC64_TOC16_DS, /* type */
  1121. 0, /* rightshift */
  1122. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1123. 16, /* bitsize */
  1124. FALSE, /* pc_relative */
  1125. 0, /* bitpos */
  1126. complain_overflow_signed, /* complain_on_overflow */
  1127. ppc64_elf_toc_reloc, /* special_function */
  1128. "R_PPC64_TOC16_DS", /* name */
  1129. FALSE, /* partial_inplace */
  1130. 0, /* src_mask */
  1131. 0xfffc, /* dst_mask */
  1132. FALSE), /* pcrel_offset */
  1133. /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
  1134. HOWTO (R_PPC64_TOC16_LO_DS, /* type */
  1135. 0, /* rightshift */
  1136. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1137. 16, /* bitsize */
  1138. FALSE, /* pc_relative */
  1139. 0, /* bitpos */
  1140. complain_overflow_dont, /* complain_on_overflow */
  1141. ppc64_elf_toc_reloc, /* special_function */
  1142. "R_PPC64_TOC16_LO_DS", /* name */
  1143. FALSE, /* partial_inplace */
  1144. 0, /* src_mask */
  1145. 0xfffc, /* dst_mask */
  1146. FALSE), /* pcrel_offset */
  1147. /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
  1148. /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
  1149. HOWTO (R_PPC64_PLTGOT16_DS, /* type */
  1150. 0, /* rightshift */
  1151. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1152. 16, /* bitsize */
  1153. FALSE, /* pc_relative */
  1154. 0, /* bitpos */
  1155. complain_overflow_signed, /* complain_on_overflow */
  1156. ppc64_elf_unhandled_reloc, /* special_function */
  1157. "R_PPC64_PLTGOT16_DS", /* name */
  1158. FALSE, /* partial_inplace */
  1159. 0, /* src_mask */
  1160. 0xfffc, /* dst_mask */
  1161. FALSE), /* pcrel_offset */
  1162. /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
  1163. /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
  1164. HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
  1165. 0, /* rightshift */
  1166. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1167. 16, /* bitsize */
  1168. FALSE, /* pc_relative */
  1169. 0, /* bitpos */
  1170. complain_overflow_dont, /* complain_on_overflow */
  1171. ppc64_elf_unhandled_reloc, /* special_function */
  1172. "R_PPC64_PLTGOT16_LO_DS",/* name */
  1173. FALSE, /* partial_inplace */
  1174. 0, /* src_mask */
  1175. 0xfffc, /* dst_mask */
  1176. FALSE), /* pcrel_offset */
  1177. /* Marker relocs for TLS. */
  1178. HOWTO (R_PPC64_TLS,
  1179. 0, /* rightshift */
  1180. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1181. 32, /* bitsize */
  1182. FALSE, /* pc_relative */
  1183. 0, /* bitpos */
  1184. complain_overflow_dont, /* complain_on_overflow */
  1185. bfd_elf_generic_reloc, /* special_function */
  1186. "R_PPC64_TLS", /* name */
  1187. FALSE, /* partial_inplace */
  1188. 0, /* src_mask */
  1189. 0, /* dst_mask */
  1190. FALSE), /* pcrel_offset */
  1191. HOWTO (R_PPC64_TLSGD,
  1192. 0, /* rightshift */
  1193. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1194. 32, /* bitsize */
  1195. FALSE, /* pc_relative */
  1196. 0, /* bitpos */
  1197. complain_overflow_dont, /* complain_on_overflow */
  1198. bfd_elf_generic_reloc, /* special_function */
  1199. "R_PPC64_TLSGD", /* name */
  1200. FALSE, /* partial_inplace */
  1201. 0, /* src_mask */
  1202. 0, /* dst_mask */
  1203. FALSE), /* pcrel_offset */
  1204. HOWTO (R_PPC64_TLSLD,
  1205. 0, /* rightshift */
  1206. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1207. 32, /* bitsize */
  1208. FALSE, /* pc_relative */
  1209. 0, /* bitpos */
  1210. complain_overflow_dont, /* complain_on_overflow */
  1211. bfd_elf_generic_reloc, /* special_function */
  1212. "R_PPC64_TLSLD", /* name */
  1213. FALSE, /* partial_inplace */
  1214. 0, /* src_mask */
  1215. 0, /* dst_mask */
  1216. FALSE), /* pcrel_offset */
  1217. HOWTO (R_PPC64_TOCSAVE,
  1218. 0, /* rightshift */
  1219. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1220. 32, /* bitsize */
  1221. FALSE, /* pc_relative */
  1222. 0, /* bitpos */
  1223. complain_overflow_dont, /* complain_on_overflow */
  1224. bfd_elf_generic_reloc, /* special_function */
  1225. "R_PPC64_TOCSAVE", /* name */
  1226. FALSE, /* partial_inplace */
  1227. 0, /* src_mask */
  1228. 0, /* dst_mask */
  1229. FALSE), /* pcrel_offset */
  1230. /* Computes the load module index of the load module that contains the
  1231. definition of its TLS sym. */
  1232. HOWTO (R_PPC64_DTPMOD64,
  1233. 0, /* rightshift */
  1234. 4, /* size (0 = byte, 1 = short, 2 = long) */
  1235. 64, /* bitsize */
  1236. FALSE, /* pc_relative */
  1237. 0, /* bitpos */
  1238. complain_overflow_dont, /* complain_on_overflow */
  1239. ppc64_elf_unhandled_reloc, /* special_function */
  1240. "R_PPC64_DTPMOD64", /* name */
  1241. FALSE, /* partial_inplace */
  1242. 0, /* src_mask */
  1243. ONES (64), /* dst_mask */
  1244. FALSE), /* pcrel_offset */
  1245. /* Computes a dtv-relative displacement, the difference between the value
  1246. of sym+add and the base address of the thread-local storage block that
  1247. contains the definition of sym, minus 0x8000. */
  1248. HOWTO (R_PPC64_DTPREL64,
  1249. 0, /* rightshift */
  1250. 4, /* size (0 = byte, 1 = short, 2 = long) */
  1251. 64, /* bitsize */
  1252. FALSE, /* pc_relative */
  1253. 0, /* bitpos */
  1254. complain_overflow_dont, /* complain_on_overflow */
  1255. ppc64_elf_unhandled_reloc, /* special_function */
  1256. "R_PPC64_DTPREL64", /* name */
  1257. FALSE, /* partial_inplace */
  1258. 0, /* src_mask */
  1259. ONES (64), /* dst_mask */
  1260. FALSE), /* pcrel_offset */
  1261. /* A 16 bit dtprel reloc. */
  1262. HOWTO (R_PPC64_DTPREL16,
  1263. 0, /* rightshift */
  1264. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1265. 16, /* bitsize */
  1266. FALSE, /* pc_relative */
  1267. 0, /* bitpos */
  1268. complain_overflow_signed, /* complain_on_overflow */
  1269. ppc64_elf_unhandled_reloc, /* special_function */
  1270. "R_PPC64_DTPREL16", /* name */
  1271. FALSE, /* partial_inplace */
  1272. 0, /* src_mask */
  1273. 0xffff, /* dst_mask */
  1274. FALSE), /* pcrel_offset */
  1275. /* Like DTPREL16, but no overflow. */
  1276. HOWTO (R_PPC64_DTPREL16_LO,
  1277. 0, /* rightshift */
  1278. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1279. 16, /* bitsize */
  1280. FALSE, /* pc_relative */
  1281. 0, /* bitpos */
  1282. complain_overflow_dont, /* complain_on_overflow */
  1283. ppc64_elf_unhandled_reloc, /* special_function */
  1284. "R_PPC64_DTPREL16_LO", /* name */
  1285. FALSE, /* partial_inplace */
  1286. 0, /* src_mask */
  1287. 0xffff, /* dst_mask */
  1288. FALSE), /* pcrel_offset */
  1289. /* Like DTPREL16_LO, but next higher group of 16 bits. */
  1290. HOWTO (R_PPC64_DTPREL16_HI,
  1291. 16, /* rightshift */
  1292. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1293. 16, /* bitsize */
  1294. FALSE, /* pc_relative */
  1295. 0, /* bitpos */
  1296. complain_overflow_signed, /* complain_on_overflow */
  1297. ppc64_elf_unhandled_reloc, /* special_function */
  1298. "R_PPC64_DTPREL16_HI", /* name */
  1299. FALSE, /* partial_inplace */
  1300. 0, /* src_mask */
  1301. 0xffff, /* dst_mask */
  1302. FALSE), /* pcrel_offset */
  1303. /* Like DTPREL16_HI, but adjust for low 16 bits. */
  1304. HOWTO (R_PPC64_DTPREL16_HA,
  1305. 16, /* rightshift */
  1306. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1307. 16, /* bitsize */
  1308. FALSE, /* pc_relative */
  1309. 0, /* bitpos */
  1310. complain_overflow_signed, /* complain_on_overflow */
  1311. ppc64_elf_unhandled_reloc, /* special_function */
  1312. "R_PPC64_DTPREL16_HA", /* name */
  1313. FALSE, /* partial_inplace */
  1314. 0, /* src_mask */
  1315. 0xffff, /* dst_mask */
  1316. FALSE), /* pcrel_offset */
  1317. /* Like DTPREL16_HI, but next higher group of 16 bits. */
  1318. HOWTO (R_PPC64_DTPREL16_HIGHER,
  1319. 32, /* rightshift */
  1320. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1321. 16, /* bitsize */
  1322. FALSE, /* pc_relative */
  1323. 0, /* bitpos */
  1324. complain_overflow_dont, /* complain_on_overflow */
  1325. ppc64_elf_unhandled_reloc, /* special_function */
  1326. "R_PPC64_DTPREL16_HIGHER", /* name */
  1327. FALSE, /* partial_inplace */
  1328. 0, /* src_mask */
  1329. 0xffff, /* dst_mask */
  1330. FALSE), /* pcrel_offset */
  1331. /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
  1332. HOWTO (R_PPC64_DTPREL16_HIGHERA,
  1333. 32, /* rightshift */
  1334. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1335. 16, /* bitsize */
  1336. FALSE, /* pc_relative */
  1337. 0, /* bitpos */
  1338. complain_overflow_dont, /* complain_on_overflow */
  1339. ppc64_elf_unhandled_reloc, /* special_function */
  1340. "R_PPC64_DTPREL16_HIGHERA", /* name */
  1341. FALSE, /* partial_inplace */
  1342. 0, /* src_mask */
  1343. 0xffff, /* dst_mask */
  1344. FALSE), /* pcrel_offset */
  1345. /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
  1346. HOWTO (R_PPC64_DTPREL16_HIGHEST,
  1347. 48, /* rightshift */
  1348. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1349. 16, /* bitsize */
  1350. FALSE, /* pc_relative */
  1351. 0, /* bitpos */
  1352. complain_overflow_dont, /* complain_on_overflow */
  1353. ppc64_elf_unhandled_reloc, /* special_function */
  1354. "R_PPC64_DTPREL16_HIGHEST", /* name */
  1355. FALSE, /* partial_inplace */
  1356. 0, /* src_mask */
  1357. 0xffff, /* dst_mask */
  1358. FALSE), /* pcrel_offset */
  1359. /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
  1360. HOWTO (R_PPC64_DTPREL16_HIGHESTA,
  1361. 48, /* rightshift */
  1362. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1363. 16, /* bitsize */
  1364. FALSE, /* pc_relative */
  1365. 0, /* bitpos */
  1366. complain_overflow_dont, /* complain_on_overflow */
  1367. ppc64_elf_unhandled_reloc, /* special_function */
  1368. "R_PPC64_DTPREL16_HIGHESTA", /* name */
  1369. FALSE, /* partial_inplace */
  1370. 0, /* src_mask */
  1371. 0xffff, /* dst_mask */
  1372. FALSE), /* pcrel_offset */
  1373. /* Like DTPREL16, but for insns with a DS field. */
  1374. HOWTO (R_PPC64_DTPREL16_DS,
  1375. 0, /* rightshift */
  1376. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1377. 16, /* bitsize */
  1378. FALSE, /* pc_relative */
  1379. 0, /* bitpos */
  1380. complain_overflow_signed, /* complain_on_overflow */
  1381. ppc64_elf_unhandled_reloc, /* special_function */
  1382. "R_PPC64_DTPREL16_DS", /* name */
  1383. FALSE, /* partial_inplace */
  1384. 0, /* src_mask */
  1385. 0xfffc, /* dst_mask */
  1386. FALSE), /* pcrel_offset */
  1387. /* Like DTPREL16_DS, but no overflow. */
  1388. HOWTO (R_PPC64_DTPREL16_LO_DS,
  1389. 0, /* rightshift */
  1390. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1391. 16, /* bitsize */
  1392. FALSE, /* pc_relative */
  1393. 0, /* bitpos */
  1394. complain_overflow_dont, /* complain_on_overflow */
  1395. ppc64_elf_unhandled_reloc, /* special_function */
  1396. "R_PPC64_DTPREL16_LO_DS", /* name */
  1397. FALSE, /* partial_inplace */
  1398. 0, /* src_mask */
  1399. 0xfffc, /* dst_mask */
  1400. FALSE), /* pcrel_offset */
  1401. /* Computes a tp-relative displacement, the difference between the value of
  1402. sym+add and the value of the thread pointer (r13). */
  1403. HOWTO (R_PPC64_TPREL64,
  1404. 0, /* rightshift */
  1405. 4, /* size (0 = byte, 1 = short, 2 = long) */
  1406. 64, /* bitsize */
  1407. FALSE, /* pc_relative */
  1408. 0, /* bitpos */
  1409. complain_overflow_dont, /* complain_on_overflow */
  1410. ppc64_elf_unhandled_reloc, /* special_function */
  1411. "R_PPC64_TPREL64", /* name */
  1412. FALSE, /* partial_inplace */
  1413. 0, /* src_mask */
  1414. ONES (64), /* dst_mask */
  1415. FALSE), /* pcrel_offset */
  1416. /* A 16 bit tprel reloc. */
  1417. HOWTO (R_PPC64_TPREL16,
  1418. 0, /* rightshift */
  1419. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1420. 16, /* bitsize */
  1421. FALSE, /* pc_relative */
  1422. 0, /* bitpos */
  1423. complain_overflow_signed, /* complain_on_overflow */
  1424. ppc64_elf_unhandled_reloc, /* special_function */
  1425. "R_PPC64_TPREL16", /* name */
  1426. FALSE, /* partial_inplace */
  1427. 0, /* src_mask */
  1428. 0xffff, /* dst_mask */
  1429. FALSE), /* pcrel_offset */
  1430. /* Like TPREL16, but no overflow. */
  1431. HOWTO (R_PPC64_TPREL16_LO,
  1432. 0, /* rightshift */
  1433. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1434. 16, /* bitsize */
  1435. FALSE, /* pc_relative */
  1436. 0, /* bitpos */
  1437. complain_overflow_dont, /* complain_on_overflow */
  1438. ppc64_elf_unhandled_reloc, /* special_function */
  1439. "R_PPC64_TPREL16_LO", /* name */
  1440. FALSE, /* partial_inplace */
  1441. 0, /* src_mask */
  1442. 0xffff, /* dst_mask */
  1443. FALSE), /* pcrel_offset */
  1444. /* Like TPREL16_LO, but next higher group of 16 bits. */
  1445. HOWTO (R_PPC64_TPREL16_HI,
  1446. 16, /* rightshift */
  1447. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1448. 16, /* bitsize */
  1449. FALSE, /* pc_relative */
  1450. 0, /* bitpos */
  1451. complain_overflow_signed, /* complain_on_overflow */
  1452. ppc64_elf_unhandled_reloc, /* special_function */
  1453. "R_PPC64_TPREL16_HI", /* name */
  1454. FALSE, /* partial_inplace */
  1455. 0, /* src_mask */
  1456. 0xffff, /* dst_mask */
  1457. FALSE), /* pcrel_offset */
  1458. /* Like TPREL16_HI, but adjust for low 16 bits. */
  1459. HOWTO (R_PPC64_TPREL16_HA,
  1460. 16, /* rightshift */
  1461. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1462. 16, /* bitsize */
  1463. FALSE, /* pc_relative */
  1464. 0, /* bitpos */
  1465. complain_overflow_signed, /* complain_on_overflow */
  1466. ppc64_elf_unhandled_reloc, /* special_function */
  1467. "R_PPC64_TPREL16_HA", /* name */
  1468. FALSE, /* partial_inplace */
  1469. 0, /* src_mask */
  1470. 0xffff, /* dst_mask */
  1471. FALSE), /* pcrel_offset */
  1472. /* Like TPREL16_HI, but next higher group of 16 bits. */
  1473. HOWTO (R_PPC64_TPREL16_HIGHER,
  1474. 32, /* rightshift */
  1475. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1476. 16, /* bitsize */
  1477. FALSE, /* pc_relative */
  1478. 0, /* bitpos */
  1479. complain_overflow_dont, /* complain_on_overflow */
  1480. ppc64_elf_unhandled_reloc, /* special_function */
  1481. "R_PPC64_TPREL16_HIGHER", /* name */
  1482. FALSE, /* partial_inplace */
  1483. 0, /* src_mask */
  1484. 0xffff, /* dst_mask */
  1485. FALSE), /* pcrel_offset */
  1486. /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
  1487. HOWTO (R_PPC64_TPREL16_HIGHERA,
  1488. 32, /* rightshift */
  1489. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1490. 16, /* bitsize */
  1491. FALSE, /* pc_relative */
  1492. 0, /* bitpos */
  1493. complain_overflow_dont, /* complain_on_overflow */
  1494. ppc64_elf_unhandled_reloc, /* special_function */
  1495. "R_PPC64_TPREL16_HIGHERA", /* name */
  1496. FALSE, /* partial_inplace */
  1497. 0, /* src_mask */
  1498. 0xffff, /* dst_mask */
  1499. FALSE), /* pcrel_offset */
  1500. /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
  1501. HOWTO (R_PPC64_TPREL16_HIGHEST,
  1502. 48, /* rightshift */
  1503. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1504. 16, /* bitsize */
  1505. FALSE, /* pc_relative */
  1506. 0, /* bitpos */
  1507. complain_overflow_dont, /* complain_on_overflow */
  1508. ppc64_elf_unhandled_reloc, /* special_function */
  1509. "R_PPC64_TPREL16_HIGHEST", /* name */
  1510. FALSE, /* partial_inplace */
  1511. 0, /* src_mask */
  1512. 0xffff, /* dst_mask */
  1513. FALSE), /* pcrel_offset */
  1514. /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
  1515. HOWTO (R_PPC64_TPREL16_HIGHESTA,
  1516. 48, /* rightshift */
  1517. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1518. 16, /* bitsize */
  1519. FALSE, /* pc_relative */
  1520. 0, /* bitpos */
  1521. complain_overflow_dont, /* complain_on_overflow */
  1522. ppc64_elf_unhandled_reloc, /* special_function */
  1523. "R_PPC64_TPREL16_HIGHESTA", /* name */
  1524. FALSE, /* partial_inplace */
  1525. 0, /* src_mask */
  1526. 0xffff, /* dst_mask */
  1527. FALSE), /* pcrel_offset */
  1528. /* Like TPREL16, but for insns with a DS field. */
  1529. HOWTO (R_PPC64_TPREL16_DS,
  1530. 0, /* rightshift */
  1531. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1532. 16, /* bitsize */
  1533. FALSE, /* pc_relative */
  1534. 0, /* bitpos */
  1535. complain_overflow_signed, /* complain_on_overflow */
  1536. ppc64_elf_unhandled_reloc, /* special_function */
  1537. "R_PPC64_TPREL16_DS", /* name */
  1538. FALSE, /* partial_inplace */
  1539. 0, /* src_mask */
  1540. 0xfffc, /* dst_mask */
  1541. FALSE), /* pcrel_offset */
  1542. /* Like TPREL16_DS, but no overflow. */
  1543. HOWTO (R_PPC64_TPREL16_LO_DS,
  1544. 0, /* rightshift */
  1545. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1546. 16, /* bitsize */
  1547. FALSE, /* pc_relative */
  1548. 0, /* bitpos */
  1549. complain_overflow_dont, /* complain_on_overflow */
  1550. ppc64_elf_unhandled_reloc, /* special_function */
  1551. "R_PPC64_TPREL16_LO_DS", /* name */
  1552. FALSE, /* partial_inplace */
  1553. 0, /* src_mask */
  1554. 0xfffc, /* dst_mask */
  1555. FALSE), /* pcrel_offset */
  1556. /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
  1557. with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
  1558. to the first entry relative to the TOC base (r2). */
  1559. HOWTO (R_PPC64_GOT_TLSGD16,
  1560. 0, /* rightshift */
  1561. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1562. 16, /* bitsize */
  1563. FALSE, /* pc_relative */
  1564. 0, /* bitpos */
  1565. complain_overflow_signed, /* complain_on_overflow */
  1566. ppc64_elf_unhandled_reloc, /* special_function */
  1567. "R_PPC64_GOT_TLSGD16", /* name */
  1568. FALSE, /* partial_inplace */
  1569. 0, /* src_mask */
  1570. 0xffff, /* dst_mask */
  1571. FALSE), /* pcrel_offset */
  1572. /* Like GOT_TLSGD16, but no overflow. */
  1573. HOWTO (R_PPC64_GOT_TLSGD16_LO,
  1574. 0, /* rightshift */
  1575. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1576. 16, /* bitsize */
  1577. FALSE, /* pc_relative */
  1578. 0, /* bitpos */
  1579. complain_overflow_dont, /* complain_on_overflow */
  1580. ppc64_elf_unhandled_reloc, /* special_function */
  1581. "R_PPC64_GOT_TLSGD16_LO", /* name */
  1582. FALSE, /* partial_inplace */
  1583. 0, /* src_mask */
  1584. 0xffff, /* dst_mask */
  1585. FALSE), /* pcrel_offset */
  1586. /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
  1587. HOWTO (R_PPC64_GOT_TLSGD16_HI,
  1588. 16, /* rightshift */
  1589. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1590. 16, /* bitsize */
  1591. FALSE, /* pc_relative */
  1592. 0, /* bitpos */
  1593. complain_overflow_signed, /* complain_on_overflow */
  1594. ppc64_elf_unhandled_reloc, /* special_function */
  1595. "R_PPC64_GOT_TLSGD16_HI", /* name */
  1596. FALSE, /* partial_inplace */
  1597. 0, /* src_mask */
  1598. 0xffff, /* dst_mask */
  1599. FALSE), /* pcrel_offset */
  1600. /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
  1601. HOWTO (R_PPC64_GOT_TLSGD16_HA,
  1602. 16, /* rightshift */
  1603. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1604. 16, /* bitsize */
  1605. FALSE, /* pc_relative */
  1606. 0, /* bitpos */
  1607. complain_overflow_signed, /* complain_on_overflow */
  1608. ppc64_elf_unhandled_reloc, /* special_function */
  1609. "R_PPC64_GOT_TLSGD16_HA", /* name */
  1610. FALSE, /* partial_inplace */
  1611. 0, /* src_mask */
  1612. 0xffff, /* dst_mask */
  1613. FALSE), /* pcrel_offset */
  1614. /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
  1615. with values (sym+add)@dtpmod and zero, and computes the offset to the
  1616. first entry relative to the TOC base (r2). */
  1617. HOWTO (R_PPC64_GOT_TLSLD16,
  1618. 0, /* rightshift */
  1619. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1620. 16, /* bitsize */
  1621. FALSE, /* pc_relative */
  1622. 0, /* bitpos */
  1623. complain_overflow_signed, /* complain_on_overflow */
  1624. ppc64_elf_unhandled_reloc, /* special_function */
  1625. "R_PPC64_GOT_TLSLD16", /* name */
  1626. FALSE, /* partial_inplace */
  1627. 0, /* src_mask */
  1628. 0xffff, /* dst_mask */
  1629. FALSE), /* pcrel_offset */
  1630. /* Like GOT_TLSLD16, but no overflow. */
  1631. HOWTO (R_PPC64_GOT_TLSLD16_LO,
  1632. 0, /* rightshift */
  1633. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1634. 16, /* bitsize */
  1635. FALSE, /* pc_relative */
  1636. 0, /* bitpos */
  1637. complain_overflow_dont, /* complain_on_overflow */
  1638. ppc64_elf_unhandled_reloc, /* special_function */
  1639. "R_PPC64_GOT_TLSLD16_LO", /* name */
  1640. FALSE, /* partial_inplace */
  1641. 0, /* src_mask */
  1642. 0xffff, /* dst_mask */
  1643. FALSE), /* pcrel_offset */
  1644. /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
  1645. HOWTO (R_PPC64_GOT_TLSLD16_HI,
  1646. 16, /* rightshift */
  1647. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1648. 16, /* bitsize */
  1649. FALSE, /* pc_relative */
  1650. 0, /* bitpos */
  1651. complain_overflow_signed, /* complain_on_overflow */
  1652. ppc64_elf_unhandled_reloc, /* special_function */
  1653. "R_PPC64_GOT_TLSLD16_HI", /* name */
  1654. FALSE, /* partial_inplace */
  1655. 0, /* src_mask */
  1656. 0xffff, /* dst_mask */
  1657. FALSE), /* pcrel_offset */
  1658. /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
  1659. HOWTO (R_PPC64_GOT_TLSLD16_HA,
  1660. 16, /* rightshift */
  1661. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1662. 16, /* bitsize */
  1663. FALSE, /* pc_relative */
  1664. 0, /* bitpos */
  1665. complain_overflow_signed, /* complain_on_overflow */
  1666. ppc64_elf_unhandled_reloc, /* special_function */
  1667. "R_PPC64_GOT_TLSLD16_HA", /* name */
  1668. FALSE, /* partial_inplace */
  1669. 0, /* src_mask */
  1670. 0xffff, /* dst_mask */
  1671. FALSE), /* pcrel_offset */
  1672. /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
  1673. the offset to the entry relative to the TOC base (r2). */
  1674. HOWTO (R_PPC64_GOT_DTPREL16_DS,
  1675. 0, /* rightshift */
  1676. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1677. 16, /* bitsize */
  1678. FALSE, /* pc_relative */
  1679. 0, /* bitpos */
  1680. complain_overflow_signed, /* complain_on_overflow */
  1681. ppc64_elf_unhandled_reloc, /* special_function */
  1682. "R_PPC64_GOT_DTPREL16_DS", /* name */
  1683. FALSE, /* partial_inplace */
  1684. 0, /* src_mask */
  1685. 0xfffc, /* dst_mask */
  1686. FALSE), /* pcrel_offset */
  1687. /* Like GOT_DTPREL16_DS, but no overflow. */
  1688. HOWTO (R_PPC64_GOT_DTPREL16_LO_DS,
  1689. 0, /* rightshift */
  1690. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1691. 16, /* bitsize */
  1692. FALSE, /* pc_relative */
  1693. 0, /* bitpos */
  1694. complain_overflow_dont, /* complain_on_overflow */
  1695. ppc64_elf_unhandled_reloc, /* special_function */
  1696. "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
  1697. FALSE, /* partial_inplace */
  1698. 0, /* src_mask */
  1699. 0xfffc, /* dst_mask */
  1700. FALSE), /* pcrel_offset */
  1701. /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
  1702. HOWTO (R_PPC64_GOT_DTPREL16_HI,
  1703. 16, /* rightshift */
  1704. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1705. 16, /* bitsize */
  1706. FALSE, /* pc_relative */
  1707. 0, /* bitpos */
  1708. complain_overflow_signed, /* complain_on_overflow */
  1709. ppc64_elf_unhandled_reloc, /* special_function */
  1710. "R_PPC64_GOT_DTPREL16_HI", /* name */
  1711. FALSE, /* partial_inplace */
  1712. 0, /* src_mask */
  1713. 0xffff, /* dst_mask */
  1714. FALSE), /* pcrel_offset */
  1715. /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
  1716. HOWTO (R_PPC64_GOT_DTPREL16_HA,
  1717. 16, /* rightshift */
  1718. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1719. 16, /* bitsize */
  1720. FALSE, /* pc_relative */
  1721. 0, /* bitpos */
  1722. complain_overflow_signed, /* complain_on_overflow */
  1723. ppc64_elf_unhandled_reloc, /* special_function */
  1724. "R_PPC64_GOT_DTPREL16_HA", /* name */
  1725. FALSE, /* partial_inplace */
  1726. 0, /* src_mask */
  1727. 0xffff, /* dst_mask */
  1728. FALSE), /* pcrel_offset */
  1729. /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
  1730. offset to the entry relative to the TOC base (r2). */
  1731. HOWTO (R_PPC64_GOT_TPREL16_DS,
  1732. 0, /* rightshift */
  1733. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1734. 16, /* bitsize */
  1735. FALSE, /* pc_relative */
  1736. 0, /* bitpos */
  1737. complain_overflow_signed, /* complain_on_overflow */
  1738. ppc64_elf_unhandled_reloc, /* special_function */
  1739. "R_PPC64_GOT_TPREL16_DS", /* name */
  1740. FALSE, /* partial_inplace */
  1741. 0, /* src_mask */
  1742. 0xfffc, /* dst_mask */
  1743. FALSE), /* pcrel_offset */
  1744. /* Like GOT_TPREL16_DS, but no overflow. */
  1745. HOWTO (R_PPC64_GOT_TPREL16_LO_DS,
  1746. 0, /* rightshift */
  1747. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1748. 16, /* bitsize */
  1749. FALSE, /* pc_relative */
  1750. 0, /* bitpos */
  1751. complain_overflow_dont, /* complain_on_overflow */
  1752. ppc64_elf_unhandled_reloc, /* special_function */
  1753. "R_PPC64_GOT_TPREL16_LO_DS", /* name */
  1754. FALSE, /* partial_inplace */
  1755. 0, /* src_mask */
  1756. 0xfffc, /* dst_mask */
  1757. FALSE), /* pcrel_offset */
  1758. /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
  1759. HOWTO (R_PPC64_GOT_TPREL16_HI,
  1760. 16, /* rightshift */
  1761. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1762. 16, /* bitsize */
  1763. FALSE, /* pc_relative */
  1764. 0, /* bitpos */
  1765. complain_overflow_signed, /* complain_on_overflow */
  1766. ppc64_elf_unhandled_reloc, /* special_function */
  1767. "R_PPC64_GOT_TPREL16_HI", /* name */
  1768. FALSE, /* partial_inplace */
  1769. 0, /* src_mask */
  1770. 0xffff, /* dst_mask */
  1771. FALSE), /* pcrel_offset */
  1772. /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
  1773. HOWTO (R_PPC64_GOT_TPREL16_HA,
  1774. 16, /* rightshift */
  1775. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1776. 16, /* bitsize */
  1777. FALSE, /* pc_relative */
  1778. 0, /* bitpos */
  1779. complain_overflow_signed, /* complain_on_overflow */
  1780. ppc64_elf_unhandled_reloc, /* special_function */
  1781. "R_PPC64_GOT_TPREL16_HA", /* name */
  1782. FALSE, /* partial_inplace */
  1783. 0, /* src_mask */
  1784. 0xffff, /* dst_mask */
  1785. FALSE), /* pcrel_offset */
  1786. HOWTO (R_PPC64_JMP_IREL, /* type */
  1787. 0, /* rightshift */
  1788. 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
  1789. 0, /* bitsize */
  1790. FALSE, /* pc_relative */
  1791. 0, /* bitpos */
  1792. complain_overflow_dont, /* complain_on_overflow */
  1793. ppc64_elf_unhandled_reloc, /* special_function */
  1794. "R_PPC64_JMP_IREL", /* name */
  1795. FALSE, /* partial_inplace */
  1796. 0, /* src_mask */
  1797. 0, /* dst_mask */
  1798. FALSE), /* pcrel_offset */
  1799. HOWTO (R_PPC64_IRELATIVE, /* type */
  1800. 0, /* rightshift */
  1801. 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
  1802. 64, /* bitsize */
  1803. FALSE, /* pc_relative */
  1804. 0, /* bitpos */
  1805. complain_overflow_dont, /* complain_on_overflow */
  1806. bfd_elf_generic_reloc, /* special_function */
  1807. "R_PPC64_IRELATIVE", /* name */
  1808. FALSE, /* partial_inplace */
  1809. 0, /* src_mask */
  1810. ONES (64), /* dst_mask */
  1811. FALSE), /* pcrel_offset */
  1812. /* A 16 bit relative relocation. */
  1813. HOWTO (R_PPC64_REL16, /* type */
  1814. 0, /* rightshift */
  1815. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1816. 16, /* bitsize */
  1817. TRUE, /* pc_relative */
  1818. 0, /* bitpos */
  1819. complain_overflow_signed, /* complain_on_overflow */
  1820. bfd_elf_generic_reloc, /* special_function */
  1821. "R_PPC64_REL16", /* name */
  1822. FALSE, /* partial_inplace */
  1823. 0, /* src_mask */
  1824. 0xffff, /* dst_mask */
  1825. TRUE), /* pcrel_offset */
  1826. /* A 16 bit relative relocation without overflow. */
  1827. HOWTO (R_PPC64_REL16_LO, /* type */
  1828. 0, /* rightshift */
  1829. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1830. 16, /* bitsize */
  1831. TRUE, /* pc_relative */
  1832. 0, /* bitpos */
  1833. complain_overflow_dont,/* complain_on_overflow */
  1834. bfd_elf_generic_reloc, /* special_function */
  1835. "R_PPC64_REL16_LO", /* name */
  1836. FALSE, /* partial_inplace */
  1837. 0, /* src_mask */
  1838. 0xffff, /* dst_mask */
  1839. TRUE), /* pcrel_offset */
  1840. /* The high order 16 bits of a relative address. */
  1841. HOWTO (R_PPC64_REL16_HI, /* type */
  1842. 16, /* rightshift */
  1843. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1844. 16, /* bitsize */
  1845. TRUE, /* pc_relative */
  1846. 0, /* bitpos */
  1847. complain_overflow_signed, /* complain_on_overflow */
  1848. bfd_elf_generic_reloc, /* special_function */
  1849. "R_PPC64_REL16_HI", /* name */
  1850. FALSE, /* partial_inplace */
  1851. 0, /* src_mask */
  1852. 0xffff, /* dst_mask */
  1853. TRUE), /* pcrel_offset */
  1854. /* The high order 16 bits of a relative address, plus 1 if the contents of
  1855. the low 16 bits, treated as a signed number, is negative. */
  1856. HOWTO (R_PPC64_REL16_HA, /* type */
  1857. 16, /* rightshift */
  1858. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1859. 16, /* bitsize */
  1860. TRUE, /* pc_relative */
  1861. 0, /* bitpos */
  1862. complain_overflow_signed, /* complain_on_overflow */
  1863. ppc64_elf_ha_reloc, /* special_function */
  1864. "R_PPC64_REL16_HA", /* name */
  1865. FALSE, /* partial_inplace */
  1866. 0, /* src_mask */
  1867. 0xffff, /* dst_mask */
  1868. TRUE), /* pcrel_offset */
  1869. /* Like R_PPC64_ADDR16_HI, but no overflow. */
  1870. HOWTO (R_PPC64_ADDR16_HIGH, /* type */
  1871. 16, /* rightshift */
  1872. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1873. 16, /* bitsize */
  1874. FALSE, /* pc_relative */
  1875. 0, /* bitpos */
  1876. complain_overflow_dont, /* complain_on_overflow */
  1877. bfd_elf_generic_reloc, /* special_function */
  1878. "R_PPC64_ADDR16_HIGH", /* name */
  1879. FALSE, /* partial_inplace */
  1880. 0, /* src_mask */
  1881. 0xffff, /* dst_mask */
  1882. FALSE), /* pcrel_offset */
  1883. /* Like R_PPC64_ADDR16_HA, but no overflow. */
  1884. HOWTO (R_PPC64_ADDR16_HIGHA, /* type */
  1885. 16, /* rightshift */
  1886. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1887. 16, /* bitsize */
  1888. FALSE, /* pc_relative */
  1889. 0, /* bitpos */
  1890. complain_overflow_dont, /* complain_on_overflow */
  1891. ppc64_elf_ha_reloc, /* special_function */
  1892. "R_PPC64_ADDR16_HIGHA", /* name */
  1893. FALSE, /* partial_inplace */
  1894. 0, /* src_mask */
  1895. 0xffff, /* dst_mask */
  1896. FALSE), /* pcrel_offset */
  1897. /* Like R_PPC64_DTPREL16_HI, but no overflow. */
  1898. HOWTO (R_PPC64_DTPREL16_HIGH,
  1899. 16, /* rightshift */
  1900. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1901. 16, /* bitsize */
  1902. FALSE, /* pc_relative */
  1903. 0, /* bitpos */
  1904. complain_overflow_dont, /* complain_on_overflow */
  1905. ppc64_elf_unhandled_reloc, /* special_function */
  1906. "R_PPC64_DTPREL16_HIGH", /* name */
  1907. FALSE, /* partial_inplace */
  1908. 0, /* src_mask */
  1909. 0xffff, /* dst_mask */
  1910. FALSE), /* pcrel_offset */
  1911. /* Like R_PPC64_DTPREL16_HA, but no overflow. */
  1912. HOWTO (R_PPC64_DTPREL16_HIGHA,
  1913. 16, /* rightshift */
  1914. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1915. 16, /* bitsize */
  1916. FALSE, /* pc_relative */
  1917. 0, /* bitpos */
  1918. complain_overflow_dont, /* complain_on_overflow */
  1919. ppc64_elf_unhandled_reloc, /* special_function */
  1920. "R_PPC64_DTPREL16_HIGHA", /* name */
  1921. FALSE, /* partial_inplace */
  1922. 0, /* src_mask */
  1923. 0xffff, /* dst_mask */
  1924. FALSE), /* pcrel_offset */
  1925. /* Like R_PPC64_TPREL16_HI, but no overflow. */
  1926. HOWTO (R_PPC64_TPREL16_HIGH,
  1927. 16, /* rightshift */
  1928. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1929. 16, /* bitsize */
  1930. FALSE, /* pc_relative */
  1931. 0, /* bitpos */
  1932. complain_overflow_dont, /* complain_on_overflow */
  1933. ppc64_elf_unhandled_reloc, /* special_function */
  1934. "R_PPC64_TPREL16_HIGH", /* name */
  1935. FALSE, /* partial_inplace */
  1936. 0, /* src_mask */
  1937. 0xffff, /* dst_mask */
  1938. FALSE), /* pcrel_offset */
  1939. /* Like R_PPC64_TPREL16_HA, but no overflow. */
  1940. HOWTO (R_PPC64_TPREL16_HIGHA,
  1941. 16, /* rightshift */
  1942. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1943. 16, /* bitsize */
  1944. FALSE, /* pc_relative */
  1945. 0, /* bitpos */
  1946. complain_overflow_dont, /* complain_on_overflow */
  1947. ppc64_elf_unhandled_reloc, /* special_function */
  1948. "R_PPC64_TPREL16_HIGHA", /* name */
  1949. FALSE, /* partial_inplace */
  1950. 0, /* src_mask */
  1951. 0xffff, /* dst_mask */
  1952. FALSE), /* pcrel_offset */
  1953. /* Like ADDR64, but use local entry point of function. */
  1954. HOWTO (R_PPC64_ADDR64_LOCAL, /* type */
  1955. 0, /* rightshift */
  1956. 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
  1957. 64, /* bitsize */
  1958. FALSE, /* pc_relative */
  1959. 0, /* bitpos */
  1960. complain_overflow_dont, /* complain_on_overflow */
  1961. bfd_elf_generic_reloc, /* special_function */
  1962. "R_PPC64_ADDR64_LOCAL", /* name */
  1963. FALSE, /* partial_inplace */
  1964. 0, /* src_mask */
  1965. ONES (64), /* dst_mask */
  1966. FALSE), /* pcrel_offset */
  1967. /* GNU extension to record C++ vtable hierarchy. */
  1968. HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
  1969. 0, /* rightshift */
  1970. 0, /* size (0 = byte, 1 = short, 2 = long) */
  1971. 0, /* bitsize */
  1972. FALSE, /* pc_relative */
  1973. 0, /* bitpos */
  1974. complain_overflow_dont, /* complain_on_overflow */
  1975. NULL, /* special_function */
  1976. "R_PPC64_GNU_VTINHERIT", /* name */
  1977. FALSE, /* partial_inplace */
  1978. 0, /* src_mask */
  1979. 0, /* dst_mask */
  1980. FALSE), /* pcrel_offset */
  1981. /* GNU extension to record C++ vtable member usage. */
  1982. HOWTO (R_PPC64_GNU_VTENTRY, /* type */
  1983. 0, /* rightshift */
  1984. 0, /* size (0 = byte, 1 = short, 2 = long) */
  1985. 0, /* bitsize */
  1986. FALSE, /* pc_relative */
  1987. 0, /* bitpos */
  1988. complain_overflow_dont, /* complain_on_overflow */
  1989. NULL, /* special_function */
  1990. "R_PPC64_GNU_VTENTRY", /* name */
  1991. FALSE, /* partial_inplace */
  1992. 0, /* src_mask */
  1993. 0, /* dst_mask */
  1994. FALSE), /* pcrel_offset */
  1995. };
  1996. /* Initialize the ppc64_elf_howto_table, so that linear accesses can
  1997. be done. */
  1998. static void
  1999. ppc_howto_init (void)
  2000. {
  2001. unsigned int i, type;
  2002. for (i = 0; i < ARRAY_SIZE (ppc64_elf_howto_raw); i++)
  2003. {
  2004. type = ppc64_elf_howto_raw[i].type;
  2005. BFD_ASSERT (type < ARRAY_SIZE (ppc64_elf_howto_table));
  2006. ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
  2007. }
  2008. }
  2009. static reloc_howto_type *
  2010. ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  2011. bfd_reloc_code_real_type code)
  2012. {
  2013. enum elf_ppc64_reloc_type r = R_PPC64_NONE;
  2014. if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
  2015. /* Initialize howto table if needed. */
  2016. ppc_howto_init ();
  2017. switch (code)
  2018. {
  2019. default:
  2020. return NULL;
  2021. case BFD_RELOC_NONE: r = R_PPC64_NONE;
  2022. break;
  2023. case BFD_RELOC_32: r = R_PPC64_ADDR32;
  2024. break;
  2025. case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24;
  2026. break;
  2027. case BFD_RELOC_16: r = R_PPC64_ADDR16;
  2028. break;
  2029. case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO;
  2030. break;
  2031. case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI;
  2032. break;
  2033. case BFD_RELOC_PPC64_ADDR16_HIGH: r = R_PPC64_ADDR16_HIGH;
  2034. break;
  2035. case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA;
  2036. break;
  2037. case BFD_RELOC_PPC64_ADDR16_HIGHA: r = R_PPC64_ADDR16_HIGHA;
  2038. break;
  2039. case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14;
  2040. break;
  2041. case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN;
  2042. break;
  2043. case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN;
  2044. break;
  2045. case BFD_RELOC_PPC_B26: r = R_PPC64_REL24;
  2046. break;
  2047. case BFD_RELOC_PPC_B16: r = R_PPC64_REL14;
  2048. break;
  2049. case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN;
  2050. break;
  2051. case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN;
  2052. break;
  2053. case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16;
  2054. break;
  2055. case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO;
  2056. break;
  2057. case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI;
  2058. break;
  2059. case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA;
  2060. break;
  2061. case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY;
  2062. break;
  2063. case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT;
  2064. break;
  2065. case BFD_RELOC_32_PCREL: r = R_PPC64_REL32;
  2066. break;
  2067. case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32;
  2068. break;
  2069. case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32;
  2070. break;
  2071. case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO;
  2072. break;
  2073. case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI;
  2074. break;
  2075. case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA;
  2076. break;
  2077. case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF;
  2078. break;
  2079. case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO;
  2080. break;
  2081. case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI;
  2082. break;
  2083. case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA;
  2084. break;
  2085. case BFD_RELOC_CTOR: r = R_PPC64_ADDR64;
  2086. break;
  2087. case BFD_RELOC_64: r = R_PPC64_ADDR64;
  2088. break;
  2089. case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER;
  2090. break;
  2091. case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA;
  2092. break;
  2093. case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST;
  2094. break;
  2095. case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA;
  2096. break;
  2097. case BFD_RELOC_64_PCREL: r = R_PPC64_REL64;
  2098. break;
  2099. case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64;
  2100. break;
  2101. case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64;
  2102. break;
  2103. case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16;
  2104. break;
  2105. case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO;
  2106. break;
  2107. case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI;
  2108. break;
  2109. case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA;
  2110. break;
  2111. case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC;
  2112. break;
  2113. case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16;
  2114. break;
  2115. case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO;
  2116. break;
  2117. case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI;
  2118. break;
  2119. case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA;
  2120. break;
  2121. case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS;
  2122. break;
  2123. case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS;
  2124. break;
  2125. case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS;
  2126. break;
  2127. case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS;
  2128. break;
  2129. case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS;
  2130. break;
  2131. case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS;
  2132. break;
  2133. case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS;
  2134. break;
  2135. case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS;
  2136. break;
  2137. case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS;
  2138. break;
  2139. case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS;
  2140. break;
  2141. case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS;
  2142. break;
  2143. case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS;
  2144. break;
  2145. case BFD_RELOC_PPC_TLSGD: r = R_PPC64_TLSGD;
  2146. break;
  2147. case BFD_RELOC_PPC_TLSLD: r = R_PPC64_TLSLD;
  2148. break;
  2149. case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64;
  2150. break;
  2151. case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16;
  2152. break;
  2153. case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO;
  2154. break;
  2155. case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI;
  2156. break;
  2157. case BFD_RELOC_PPC64_TPREL16_HIGH: r = R_PPC64_TPREL16_HIGH;
  2158. break;
  2159. case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA;
  2160. break;
  2161. case BFD_RELOC_PPC64_TPREL16_HIGHA: r = R_PPC64_TPREL16_HIGHA;
  2162. break;
  2163. case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64;
  2164. break;
  2165. case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16;
  2166. break;
  2167. case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO;
  2168. break;
  2169. case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI;
  2170. break;
  2171. case BFD_RELOC_PPC64_DTPREL16_HIGH: r = R_PPC64_DTPREL16_HIGH;
  2172. break;
  2173. case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA;
  2174. break;
  2175. case BFD_RELOC_PPC64_DTPREL16_HIGHA: r = R_PPC64_DTPREL16_HIGHA;
  2176. break;
  2177. case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64;
  2178. break;
  2179. case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16;
  2180. break;
  2181. case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO;
  2182. break;
  2183. case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI;
  2184. break;
  2185. case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA;
  2186. break;
  2187. case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16;
  2188. break;
  2189. case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO;
  2190. break;
  2191. case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI;
  2192. break;
  2193. case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA;
  2194. break;
  2195. case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS;
  2196. break;
  2197. case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS;
  2198. break;
  2199. case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI;
  2200. break;
  2201. case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA;
  2202. break;
  2203. case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS;
  2204. break;
  2205. case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS;
  2206. break;
  2207. case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI;
  2208. break;
  2209. case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA;
  2210. break;
  2211. case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS;
  2212. break;
  2213. case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS;
  2214. break;
  2215. case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER;
  2216. break;
  2217. case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA;
  2218. break;
  2219. case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST;
  2220. break;
  2221. case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA;
  2222. break;
  2223. case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS;
  2224. break;
  2225. case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS;
  2226. break;
  2227. case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER;
  2228. break;
  2229. case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA;
  2230. break;
  2231. case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST;
  2232. break;
  2233. case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA;
  2234. break;
  2235. case BFD_RELOC_16_PCREL: r = R_PPC64_REL16;
  2236. break;
  2237. case BFD_RELOC_LO16_PCREL: r = R_PPC64_REL16_LO;
  2238. break;
  2239. case BFD_RELOC_HI16_PCREL: r = R_PPC64_REL16_HI;
  2240. break;
  2241. case BFD_RELOC_HI16_S_PCREL: r = R_PPC64_REL16_HA;
  2242. break;
  2243. case BFD_RELOC_PPC64_ADDR64_LOCAL: r = R_PPC64_ADDR64_LOCAL;
  2244. break;
  2245. case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT;
  2246. break;
  2247. case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY;
  2248. break;
  2249. }
  2250. return ppc64_elf_howto_table[r];
  2251. };
  2252. static reloc_howto_type *
  2253. ppc64_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  2254. const char *r_name)
  2255. {
  2256. unsigned int i;
  2257. for (i = 0; i < ARRAY_SIZE (ppc64_elf_howto_raw); i++)
  2258. if (ppc64_elf_howto_raw[i].name != NULL
  2259. && strcasecmp (ppc64_elf_howto_raw[i].name, r_name) == 0)
  2260. return &ppc64_elf_howto_raw[i];
  2261. return NULL;
  2262. }
  2263. /* Set the howto pointer for a PowerPC ELF reloc. */
  2264. static void
  2265. ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
  2266. Elf_Internal_Rela *dst)
  2267. {
  2268. unsigned int type;
  2269. /* Initialize howto table if needed. */
  2270. if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
  2271. ppc_howto_init ();
  2272. type = ELF64_R_TYPE (dst->r_info);
  2273. if (type >= ARRAY_SIZE (ppc64_elf_howto_table))
  2274. {
  2275. (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
  2276. abfd, (int) type);
  2277. type = R_PPC64_NONE;
  2278. }
  2279. cache_ptr->howto = ppc64_elf_howto_table[type];
  2280. }
  2281. /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
  2282. static bfd_reloc_status_type
  2283. ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  2284. void *data, asection *input_section,
  2285. bfd *output_bfd, char **error_message)
  2286. {
  2287. /* If this is a relocatable link (output_bfd test tells us), just
  2288. call the generic function. Any adjustment will be done at final
  2289. link time. */
  2290. if (output_bfd != NULL)
  2291. return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  2292. input_section, output_bfd, error_message);
  2293. /* Adjust the addend for sign extension of the low 16 bits.
  2294. We won't actually be using the low 16 bits, so trashing them
  2295. doesn't matter. */
  2296. reloc_entry->addend += 0x8000;
  2297. return bfd_reloc_continue;
  2298. }
  2299. static bfd_reloc_status_type
  2300. ppc64_elf_branch_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  2301. void *data, asection *input_section,
  2302. bfd *output_bfd, char **error_message)
  2303. {
  2304. if (output_bfd != NULL)
  2305. return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  2306. input_section, output_bfd, error_message);
  2307. if (strcmp (symbol->section->name, ".opd") == 0
  2308. && (symbol->section->owner->flags & DYNAMIC) == 0)
  2309. {
  2310. bfd_vma dest = opd_entry_value (symbol->section,
  2311. symbol->value + reloc_entry->addend,
  2312. NULL, NULL, FALSE);
  2313. if (dest != (bfd_vma) -1)
  2314. reloc_entry->addend = dest - (symbol->value
  2315. + symbol->section->output_section->vma
  2316. + symbol->section->output_offset);
  2317. }
  2318. else
  2319. {
  2320. elf_symbol_type *elfsym = (elf_symbol_type *) symbol;
  2321. if (symbol->section->owner != abfd
  2322. && abiversion (symbol->section->owner) >= 2)
  2323. {
  2324. unsigned int i;
  2325. for (i = 0; i < symbol->section->owner->symcount; ++i)
  2326. {
  2327. asymbol *symdef = symbol->section->owner->outsymbols[i];
  2328. if (strcmp (symdef->name, symbol->name) == 0)
  2329. {
  2330. elfsym = (elf_symbol_type *) symdef;
  2331. break;
  2332. }
  2333. }
  2334. }
  2335. reloc_entry->addend
  2336. += PPC64_LOCAL_ENTRY_OFFSET (elfsym->internal_elf_sym.st_other);
  2337. }
  2338. return bfd_reloc_continue;
  2339. }
  2340. static bfd_reloc_status_type
  2341. ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  2342. void *data, asection *input_section,
  2343. bfd *output_bfd, char **error_message)
  2344. {
  2345. long insn;
  2346. enum elf_ppc64_reloc_type r_type;
  2347. bfd_size_type octets;
  2348. /* Assume 'at' branch hints. */
  2349. bfd_boolean is_isa_v2 = TRUE;
  2350. /* If this is a relocatable link (output_bfd test tells us), just
  2351. call the generic function. Any adjustment will be done at final
  2352. link time. */
  2353. if (output_bfd != NULL)
  2354. return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  2355. input_section, output_bfd, error_message);
  2356. octets = reloc_entry->address * bfd_octets_per_byte (abfd);
  2357. insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
  2358. insn &= ~(0x01 << 21);
  2359. r_type = reloc_entry->howto->type;
  2360. if (r_type == R_PPC64_ADDR14_BRTAKEN
  2361. || r_type == R_PPC64_REL14_BRTAKEN)
  2362. insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
  2363. if (is_isa_v2)
  2364. {
  2365. /* Set 'a' bit. This is 0b00010 in BO field for branch
  2366. on CR(BI) insns (BO == 001at or 011at), and 0b01000
  2367. for branch on CTR insns (BO == 1a00t or 1a01t). */
  2368. if ((insn & (0x14 << 21)) == (0x04 << 21))
  2369. insn |= 0x02 << 21;
  2370. else if ((insn & (0x14 << 21)) == (0x10 << 21))
  2371. insn |= 0x08 << 21;
  2372. else
  2373. goto out;
  2374. }
  2375. else
  2376. {
  2377. bfd_vma target = 0;
  2378. bfd_vma from;
  2379. if (!bfd_is_com_section (symbol->section))
  2380. target = symbol->value;
  2381. target += symbol->section->output_section->vma;
  2382. target += symbol->section->output_offset;
  2383. target += reloc_entry->addend;
  2384. from = (reloc_entry->address
  2385. + input_section->output_offset
  2386. + input_section->output_section->vma);
  2387. /* Invert 'y' bit if not the default. */
  2388. if ((bfd_signed_vma) (target - from) < 0)
  2389. insn ^= 0x01 << 21;
  2390. }
  2391. bfd_put_32 (abfd, insn, (bfd_byte *) data + octets);
  2392. out:
  2393. return ppc64_elf_branch_reloc (abfd, reloc_entry, symbol, data,
  2394. input_section, output_bfd, error_message);
  2395. }
  2396. static bfd_reloc_status_type
  2397. ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  2398. void *data, asection *input_section,
  2399. bfd *output_bfd, char **error_message)
  2400. {
  2401. /* If this is a relocatable link (output_bfd test tells us), just
  2402. call the generic function. Any adjustment will be done at final
  2403. link time. */
  2404. if (output_bfd != NULL)
  2405. return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  2406. input_section, output_bfd, error_message);
  2407. /* Subtract the symbol section base address. */
  2408. reloc_entry->addend -= symbol->section->output_section->vma;
  2409. return bfd_reloc_continue;
  2410. }
  2411. static bfd_reloc_status_type
  2412. ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  2413. void *data, asection *input_section,
  2414. bfd *output_bfd, char **error_message)
  2415. {
  2416. /* If this is a relocatable link (output_bfd test tells us), just
  2417. call the generic function. Any adjustment will be done at final
  2418. link time. */
  2419. if (output_bfd != NULL)
  2420. return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  2421. input_section, output_bfd, error_message);
  2422. /* Subtract the symbol section base address. */
  2423. reloc_entry->addend -= symbol->section->output_section->vma;
  2424. /* Adjust the addend for sign extension of the low 16 bits. */
  2425. reloc_entry->addend += 0x8000;
  2426. return bfd_reloc_continue;
  2427. }
  2428. static bfd_reloc_status_type
  2429. ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  2430. void *data, asection *input_section,
  2431. bfd *output_bfd, char **error_message)
  2432. {
  2433. bfd_vma TOCstart;
  2434. /* If this is a relocatable link (output_bfd test tells us), just
  2435. call the generic function. Any adjustment will be done at final
  2436. link time. */
  2437. if (output_bfd != NULL)
  2438. return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  2439. input_section, output_bfd, error_message);
  2440. TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
  2441. if (TOCstart == 0)
  2442. TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
  2443. /* Subtract the TOC base address. */
  2444. reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
  2445. return bfd_reloc_continue;
  2446. }
  2447. static bfd_reloc_status_type
  2448. ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  2449. void *data, asection *input_section,
  2450. bfd *output_bfd, char **error_message)
  2451. {
  2452. bfd_vma TOCstart;
  2453. /* If this is a relocatable link (output_bfd test tells us), just
  2454. call the generic function. Any adjustment will be done at final
  2455. link time. */
  2456. if (output_bfd != NULL)
  2457. return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  2458. input_section, output_bfd, error_message);
  2459. TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
  2460. if (TOCstart == 0)
  2461. TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
  2462. /* Subtract the TOC base address. */
  2463. reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
  2464. /* Adjust the addend for sign extension of the low 16 bits. */
  2465. reloc_entry->addend += 0x8000;
  2466. return bfd_reloc_continue;
  2467. }
  2468. static bfd_reloc_status_type
  2469. ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  2470. void *data, asection *input_section,
  2471. bfd *output_bfd, char **error_message)
  2472. {
  2473. bfd_vma TOCstart;
  2474. bfd_size_type octets;
  2475. /* If this is a relocatable link (output_bfd test tells us), just
  2476. call the generic function. Any adjustment will be done at final
  2477. link time. */
  2478. if (output_bfd != NULL)
  2479. return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  2480. input_section, output_bfd, error_message);
  2481. TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
  2482. if (TOCstart == 0)
  2483. TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
  2484. octets = reloc_entry->address * bfd_octets_per_byte (abfd);
  2485. bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
  2486. return bfd_reloc_ok;
  2487. }
  2488. static bfd_reloc_status_type
  2489. ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  2490. void *data, asection *input_section,
  2491. bfd *output_bfd, char **error_message)
  2492. {
  2493. /* If this is a relocatable link (output_bfd test tells us), just
  2494. call the generic function. Any adjustment will be done at final
  2495. link time. */
  2496. if (output_bfd != NULL)
  2497. return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  2498. input_section, output_bfd, error_message);
  2499. if (error_message != NULL)
  2500. {
  2501. static char buf[60];
  2502. sprintf (buf, "generic linker can't handle %s",
  2503. reloc_entry->howto->name);
  2504. *error_message = buf;
  2505. }
  2506. return bfd_reloc_dangerous;
  2507. }
  2508. /* Track GOT entries needed for a given symbol. We might need more
  2509. than one got entry per symbol. */
  2510. struct got_entry
  2511. {
  2512. struct got_entry *next;
  2513. /* The symbol addend that we'll be placing in the GOT. */
  2514. bfd_vma addend;
  2515. /* Unlike other ELF targets, we use separate GOT entries for the same
  2516. symbol referenced from different input files. This is to support
  2517. automatic multiple TOC/GOT sections, where the TOC base can vary
  2518. from one input file to another. After partitioning into TOC groups
  2519. we merge entries within the group.
  2520. Point to the BFD owning this GOT entry. */
  2521. bfd *owner;
  2522. /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
  2523. TLS_TPREL or TLS_DTPREL for tls entries. */
  2524. unsigned char tls_type;
  2525. /* Non-zero if got.ent points to real entry. */
  2526. unsigned char is_indirect;
  2527. /* Reference count until size_dynamic_sections, GOT offset thereafter. */
  2528. union
  2529. {
  2530. bfd_signed_vma refcount;
  2531. bfd_vma offset;
  2532. struct got_entry *ent;
  2533. } got;
  2534. };
  2535. /* The same for PLT. */
  2536. struct plt_entry
  2537. {
  2538. struct plt_entry *next;
  2539. bfd_vma addend;
  2540. union
  2541. {
  2542. bfd_signed_vma refcount;
  2543. bfd_vma offset;
  2544. } plt;
  2545. };
  2546. struct ppc64_elf_obj_tdata
  2547. {
  2548. struct elf_obj_tdata elf;
  2549. /* Shortcuts to dynamic linker sections. */
  2550. asection *got;
  2551. asection *relgot;
  2552. /* Used during garbage collection. We attach global symbols defined
  2553. on removed .opd entries to this section so that the sym is removed. */
  2554. asection *deleted_section;
  2555. /* TLS local dynamic got entry handling. Support for multiple GOT
  2556. sections means we potentially need one of these for each input bfd. */
  2557. struct got_entry tlsld_got;
  2558. union {
  2559. /* A copy of relocs before they are modified for --emit-relocs. */
  2560. Elf_Internal_Rela *relocs;
  2561. /* Section contents. */
  2562. bfd_byte *contents;
  2563. } opd;
  2564. /* Nonzero if this bfd has small toc/got relocs, ie. that expect
  2565. the reloc to be in the range -32768 to 32767. */
  2566. unsigned int has_small_toc_reloc : 1;
  2567. /* Set if toc/got ha relocs detected not using r2, or lo reloc
  2568. instruction not one we handle. */
  2569. unsigned int unexpected_toc_insn : 1;
  2570. };
  2571. #define ppc64_elf_tdata(bfd) \
  2572. ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
  2573. #define ppc64_tlsld_got(bfd) \
  2574. (&ppc64_elf_tdata (bfd)->tlsld_got)
  2575. #define is_ppc64_elf(bfd) \
  2576. (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
  2577. && elf_object_id (bfd) == PPC64_ELF_DATA)
  2578. /* Override the generic function because we store some extras. */
  2579. static bfd_boolean
  2580. ppc64_elf_mkobject (bfd *abfd)
  2581. {
  2582. return bfd_elf_allocate_object (abfd, sizeof (struct ppc64_elf_obj_tdata),
  2583. PPC64_ELF_DATA);
  2584. }
  2585. /* Fix bad default arch selected for a 64 bit input bfd when the
  2586. default is 32 bit. */
  2587. static bfd_boolean
  2588. ppc64_elf_object_p (bfd *abfd)
  2589. {
  2590. if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32)
  2591. {
  2592. Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
  2593. if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64)
  2594. {
  2595. /* Relies on arch after 32 bit default being 64 bit default. */
  2596. abfd->arch_info = abfd->arch_info->next;
  2597. BFD_ASSERT (abfd->arch_info->bits_per_word == 64);
  2598. }
  2599. }
  2600. return TRUE;
  2601. }
  2602. /* Support for core dump NOTE sections. */
  2603. static bfd_boolean
  2604. ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
  2605. {
  2606. size_t offset, size;
  2607. if (note->descsz != 504)
  2608. return FALSE;
  2609. /* pr_cursig */
  2610. elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
  2611. /* pr_pid */
  2612. elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
  2613. /* pr_reg */
  2614. offset = 112;
  2615. size = 384;
  2616. /* Make a ".reg/999" section. */
  2617. return _bfd_elfcore_make_pseudosection (abfd, ".reg",
  2618. size, note->descpos + offset);
  2619. }
  2620. static bfd_boolean
  2621. ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
  2622. {
  2623. if (note->descsz != 136)
  2624. return FALSE;
  2625. elf_tdata (abfd)->core->pid
  2626. = bfd_get_32 (abfd, note->descdata + 24);
  2627. elf_tdata (abfd)->core->program
  2628. = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
  2629. elf_tdata (abfd)->core->command
  2630. = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
  2631. return TRUE;
  2632. }
  2633. static char *
  2634. ppc64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
  2635. ...)
  2636. {
  2637. switch (note_type)
  2638. {
  2639. default:
  2640. return NULL;
  2641. case NT_PRPSINFO:
  2642. {
  2643. char data[136];
  2644. va_list ap;
  2645. va_start (ap, note_type);
  2646. memset (data, 0, sizeof (data));
  2647. strncpy (data + 40, va_arg (ap, const char *), 16);
  2648. strncpy (data + 56, va_arg (ap, const char *), 80);
  2649. va_end (ap);
  2650. return elfcore_write_note (abfd, buf, bufsiz,
  2651. "CORE", note_type, data, sizeof (data));
  2652. }
  2653. case NT_PRSTATUS:
  2654. {
  2655. char data[504];
  2656. va_list ap;
  2657. long pid;
  2658. int cursig;
  2659. const void *greg;
  2660. va_start (ap, note_type);
  2661. memset (data, 0, 112);
  2662. pid = va_arg (ap, long);
  2663. bfd_put_32 (abfd, pid, data + 32);
  2664. cursig = va_arg (ap, int);
  2665. bfd_put_16 (abfd, cursig, data + 12);
  2666. greg = va_arg (ap, const void *);
  2667. memcpy (data + 112, greg, 384);
  2668. memset (data + 496, 0, 8);
  2669. va_end (ap);
  2670. return elfcore_write_note (abfd, buf, bufsiz,
  2671. "CORE", note_type, data, sizeof (data));
  2672. }
  2673. }
  2674. }
  2675. /* Add extra PPC sections. */
  2676. static const struct bfd_elf_special_section ppc64_elf_special_sections[]=
  2677. {
  2678. { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, 0 },
  2679. { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
  2680. { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
  2681. { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
  2682. { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
  2683. { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
  2684. { NULL, 0, 0, 0, 0 }
  2685. };
  2686. enum _ppc64_sec_type {
  2687. sec_normal = 0,
  2688. sec_opd = 1,
  2689. sec_toc = 2
  2690. };
  2691. struct _ppc64_elf_section_data
  2692. {
  2693. struct bfd_elf_section_data elf;
  2694. union
  2695. {
  2696. /* An array with one entry for each opd function descriptor,
  2697. and some spares since opd entries may be either 16 or 24 bytes. */
  2698. #define OPD_NDX(OFF) ((OFF) >> 4)
  2699. struct _opd_sec_data
  2700. {
  2701. /* Points to the function code section for local opd entries. */
  2702. asection **func_sec;
  2703. /* After editing .opd, adjust references to opd local syms. */
  2704. long *adjust;
  2705. } opd;
  2706. /* An array for toc sections, indexed by offset/8. */
  2707. struct _toc_sec_data
  2708. {
  2709. /* Specifies the relocation symbol index used at a given toc offset. */
  2710. unsigned *symndx;
  2711. /* And the relocation addend. */
  2712. bfd_vma *add;
  2713. } toc;
  2714. } u;
  2715. enum _ppc64_sec_type sec_type:2;
  2716. /* Flag set when small branches are detected. Used to
  2717. select suitable defaults for the stub group size. */
  2718. unsigned int has_14bit_branch:1;
  2719. };
  2720. #define ppc64_elf_section_data(sec) \
  2721. ((struct _ppc64_elf_section_data *) elf_section_data (sec))
  2722. static bfd_boolean
  2723. ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
  2724. {
  2725. if (!sec->used_by_bfd)
  2726. {
  2727. struct _ppc64_elf_section_data *sdata;
  2728. bfd_size_type amt = sizeof (*sdata);
  2729. sdata = bfd_zalloc (abfd, amt);
  2730. if (sdata == NULL)
  2731. return FALSE;
  2732. sec->used_by_bfd = sdata;
  2733. }
  2734. return _bfd_elf_new_section_hook (abfd, sec);
  2735. }
  2736. static struct _opd_sec_data *
  2737. get_opd_info (asection * sec)
  2738. {
  2739. if (sec != NULL
  2740. && ppc64_elf_section_data (sec) != NULL
  2741. && ppc64_elf_section_data (sec)->sec_type == sec_opd)
  2742. return &ppc64_elf_section_data (sec)->u.opd;
  2743. return NULL;
  2744. }
  2745. /* Parameters for the qsort hook. */
  2746. static bfd_boolean synthetic_relocatable;
  2747. /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
  2748. static int
  2749. compare_symbols (const void *ap, const void *bp)
  2750. {
  2751. const asymbol *a = * (const asymbol **) ap;
  2752. const asymbol *b = * (const asymbol **) bp;
  2753. /* Section symbols first. */
  2754. if ((a->flags & BSF_SECTION_SYM) && !(b->flags & BSF_SECTION_SYM))
  2755. return -1;
  2756. if (!(a->flags & BSF_SECTION_SYM) && (b->flags & BSF_SECTION_SYM))
  2757. return 1;
  2758. /* then .opd symbols. */
  2759. if (strcmp (a->section->name, ".opd") == 0
  2760. && strcmp (b->section->name, ".opd") != 0)
  2761. return -1;
  2762. if (strcmp (a->section->name, ".opd") != 0
  2763. && strcmp (b->section->name, ".opd") == 0)
  2764. return 1;
  2765. /* then other code symbols. */
  2766. if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
  2767. == (SEC_CODE | SEC_ALLOC)
  2768. && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
  2769. != (SEC_CODE | SEC_ALLOC))
  2770. return -1;
  2771. if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
  2772. != (SEC_CODE | SEC_ALLOC)
  2773. && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
  2774. == (SEC_CODE | SEC_ALLOC))
  2775. return 1;
  2776. if (synthetic_relocatable)
  2777. {
  2778. if (a->section->id < b->section->id)
  2779. return -1;
  2780. if (a->section->id > b->section->id)
  2781. return 1;
  2782. }
  2783. if (a->value + a->section->vma < b->value + b->section->vma)
  2784. return -1;
  2785. if (a->value + a->section->vma > b->value + b->section->vma)
  2786. return 1;
  2787. /* For syms with the same value, prefer strong dynamic global function
  2788. syms over other syms. */
  2789. if ((a->flags & BSF_GLOBAL) != 0 && (b->flags & BSF_GLOBAL) == 0)
  2790. return -1;
  2791. if ((a->flags & BSF_GLOBAL) == 0 && (b->flags & BSF_GLOBAL) != 0)
  2792. return 1;
  2793. if ((a->flags & BSF_FUNCTION) != 0 && (b->flags & BSF_FUNCTION) == 0)
  2794. return -1;
  2795. if ((a->flags & BSF_FUNCTION) == 0 && (b->flags & BSF_FUNCTION) != 0)
  2796. return 1;
  2797. if ((a->flags & BSF_WEAK) == 0 && (b->flags & BSF_WEAK) != 0)
  2798. return -1;
  2799. if ((a->flags & BSF_WEAK) != 0 && (b->flags & BSF_WEAK) == 0)
  2800. return 1;
  2801. if ((a->flags & BSF_DYNAMIC) != 0 && (b->flags & BSF_DYNAMIC) == 0)
  2802. return -1;
  2803. if ((a->flags & BSF_DYNAMIC) == 0 && (b->flags & BSF_DYNAMIC) != 0)
  2804. return 1;
  2805. return 0;
  2806. }
  2807. /* Search SYMS for a symbol of the given VALUE. */
  2808. static asymbol *
  2809. sym_exists_at (asymbol **syms, long lo, long hi, unsigned int id, bfd_vma value)
  2810. {
  2811. long mid;
  2812. if (id == (unsigned) -1)
  2813. {
  2814. while (lo < hi)
  2815. {
  2816. mid = (lo + hi) >> 1;
  2817. if (syms[mid]->value + syms[mid]->section->vma < value)
  2818. lo = mid + 1;
  2819. else if (syms[mid]->value + syms[mid]->section->vma > value)
  2820. hi = mid;
  2821. else
  2822. return syms[mid];
  2823. }
  2824. }
  2825. else
  2826. {
  2827. while (lo < hi)
  2828. {
  2829. mid = (lo + hi) >> 1;
  2830. if (syms[mid]->section->id < id)
  2831. lo = mid + 1;
  2832. else if (syms[mid]->section->id > id)
  2833. hi = mid;
  2834. else if (syms[mid]->value < value)
  2835. lo = mid + 1;
  2836. else if (syms[mid]->value > value)
  2837. hi = mid;
  2838. else
  2839. return syms[mid];
  2840. }
  2841. }
  2842. return NULL;
  2843. }
  2844. static bfd_boolean
  2845. section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr)
  2846. {
  2847. bfd_vma vma = *(bfd_vma *) ptr;
  2848. return ((section->flags & SEC_ALLOC) != 0
  2849. && section->vma <= vma
  2850. && vma < section->vma + section->size);
  2851. }
  2852. /* Create synthetic symbols, effectively restoring "dot-symbol" function
  2853. entry syms. Also generate @plt symbols for the glink branch table.
  2854. Returns count of synthetic symbols in RET or -1 on error. */
  2855. static long
  2856. ppc64_elf_get_synthetic_symtab (bfd *abfd,
  2857. long static_count, asymbol **static_syms,
  2858. long dyn_count, asymbol **dyn_syms,
  2859. asymbol **ret)
  2860. {
  2861. asymbol *s;
  2862. long i;
  2863. long count;
  2864. char *names;
  2865. long symcount, codesecsym, codesecsymend, secsymend, opdsymend;
  2866. asection *opd = NULL;
  2867. bfd_boolean relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
  2868. asymbol **syms;
  2869. int abi = abiversion (abfd);
  2870. *ret = NULL;
  2871. if (abi < 2)
  2872. {
  2873. opd = bfd_get_section_by_name (abfd, ".opd");
  2874. if (opd == NULL && abi == 1)
  2875. return 0;
  2876. }
  2877. symcount = static_count;
  2878. if (!relocatable)
  2879. symcount += dyn_count;
  2880. if (symcount == 0)
  2881. return 0;
  2882. syms = bfd_malloc ((symcount + 1) * sizeof (*syms));
  2883. if (syms == NULL)
  2884. return -1;
  2885. if (!relocatable && static_count != 0 && dyn_count != 0)
  2886. {
  2887. /* Use both symbol tables. */
  2888. memcpy (syms, static_syms, static_count * sizeof (*syms));
  2889. memcpy (syms + static_count, dyn_syms, (dyn_count + 1) * sizeof (*syms));
  2890. }
  2891. else if (!relocatable && static_count == 0)
  2892. memcpy (syms, dyn_syms, (symcount + 1) * sizeof (*syms));
  2893. else
  2894. memcpy (syms, static_syms, (symcount + 1) * sizeof (*syms));
  2895. synthetic_relocatable = relocatable;
  2896. qsort (syms, symcount, sizeof (*syms), compare_symbols);
  2897. if (!relocatable && symcount > 1)
  2898. {
  2899. long j;
  2900. /* Trim duplicate syms, since we may have merged the normal and
  2901. dynamic symbols. Actually, we only care about syms that have
  2902. different values, so trim any with the same value. */
  2903. for (i = 1, j = 1; i < symcount; ++i)
  2904. if (syms[i - 1]->value + syms[i - 1]->section->vma
  2905. != syms[i]->value + syms[i]->section->vma)
  2906. syms[j++] = syms[i];
  2907. symcount = j;
  2908. }
  2909. i = 0;
  2910. if (strcmp (syms[i]->section->name, ".opd") == 0)
  2911. ++i;
  2912. codesecsym = i;
  2913. for (; i < symcount; ++i)
  2914. if (((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
  2915. != (SEC_CODE | SEC_ALLOC))
  2916. || (syms[i]->flags & BSF_SECTION_SYM) == 0)
  2917. break;
  2918. codesecsymend = i;
  2919. for (; i < symcount; ++i)
  2920. if ((syms[i]->flags & BSF_SECTION_SYM) == 0)
  2921. break;
  2922. secsymend = i;
  2923. for (; i < symcount; ++i)
  2924. if (strcmp (syms[i]->section->name, ".opd") != 0)
  2925. break;
  2926. opdsymend = i;
  2927. for (; i < symcount; ++i)
  2928. if ((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
  2929. != (SEC_CODE | SEC_ALLOC))
  2930. break;
  2931. symcount = i;
  2932. count = 0;
  2933. if (relocatable)
  2934. {
  2935. bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
  2936. arelent *r;
  2937. size_t size;
  2938. long relcount;
  2939. if (opdsymend == secsymend)
  2940. goto done;
  2941. slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
  2942. relcount = (opd->flags & SEC_RELOC) ? opd->reloc_count : 0;
  2943. if (relcount == 0)
  2944. goto done;
  2945. if (!(*slurp_relocs) (abfd, opd, static_syms, FALSE))
  2946. {
  2947. count = -1;
  2948. goto done;
  2949. }
  2950. size = 0;
  2951. for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
  2952. {
  2953. asymbol *sym;
  2954. while (r < opd->relocation + relcount
  2955. && r->address < syms[i]->value + opd->vma)
  2956. ++r;
  2957. if (r == opd->relocation + relcount)
  2958. break;
  2959. if (r->address != syms[i]->value + opd->vma)
  2960. continue;
  2961. if (r->howto->type != R_PPC64_ADDR64)
  2962. continue;
  2963. sym = *r->sym_ptr_ptr;
  2964. if (!sym_exists_at (syms, opdsymend, symcount,
  2965. sym->section->id, sym->value + r->addend))
  2966. {
  2967. ++count;
  2968. size += sizeof (asymbol);
  2969. size += strlen (syms[i]->name) + 2;
  2970. }
  2971. }
  2972. if (size == 0)
  2973. goto done;
  2974. s = *ret = bfd_malloc (size);
  2975. if (s == NULL)
  2976. {
  2977. count = -1;
  2978. goto done;
  2979. }
  2980. names = (char *) (s + count);
  2981. for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
  2982. {
  2983. asymbol *sym;
  2984. while (r < opd->relocation + relcount
  2985. && r->address < syms[i]->value + opd->vma)
  2986. ++r;
  2987. if (r == opd->relocation + relcount)
  2988. break;
  2989. if (r->address != syms[i]->value + opd->vma)
  2990. continue;
  2991. if (r->howto->type != R_PPC64_ADDR64)
  2992. continue;
  2993. sym = *r->sym_ptr_ptr;
  2994. if (!sym_exists_at (syms, opdsymend, symcount,
  2995. sym->section->id, sym->value + r->addend))
  2996. {
  2997. size_t len;
  2998. *s = *syms[i];
  2999. s->flags |= BSF_SYNTHETIC;
  3000. s->section = sym->section;
  3001. s->value = sym->value + r->addend;
  3002. s->name = names;
  3003. *names++ = '.';
  3004. len = strlen (syms[i]->name);
  3005. memcpy (names, syms[i]->name, len + 1);
  3006. names += len + 1;
  3007. /* Have udata.p point back to the original symbol this
  3008. synthetic symbol was derived from. */
  3009. s->udata.p = syms[i];
  3010. s++;
  3011. }
  3012. }
  3013. }
  3014. else
  3015. {
  3016. bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
  3017. bfd_byte *contents = NULL;
  3018. size_t size;
  3019. long plt_count = 0;
  3020. bfd_vma glink_vma = 0, resolv_vma = 0;
  3021. asection *dynamic, *glink = NULL, *relplt = NULL;
  3022. arelent *p;
  3023. if (opd != NULL && !bfd_malloc_and_get_section (abfd, opd, &contents))
  3024. {
  3025. free_contents_and_exit_err:
  3026. count = -1;
  3027. free_contents_and_exit:
  3028. if (contents)
  3029. free (contents);
  3030. goto done;
  3031. }
  3032. size = 0;
  3033. for (i = secsymend; i < opdsymend; ++i)
  3034. {
  3035. bfd_vma ent;
  3036. /* Ignore bogus symbols. */
  3037. if (syms[i]->value > opd->size - 8)
  3038. continue;
  3039. ent = bfd_get_64 (abfd, contents + syms[i]->value);
  3040. if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
  3041. {
  3042. ++count;
  3043. size += sizeof (asymbol);
  3044. size += strlen (syms[i]->name) + 2;
  3045. }
  3046. }
  3047. /* Get start of .glink stubs from DT_PPC64_GLINK. */
  3048. if (dyn_count != 0
  3049. && (dynamic = bfd_get_section_by_name (abfd, ".dynamic")) != NULL)
  3050. {
  3051. bfd_byte *dynbuf, *extdyn, *extdynend;
  3052. size_t extdynsize;
  3053. void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *);
  3054. if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf))
  3055. goto free_contents_and_exit_err;
  3056. extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
  3057. swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
  3058. extdyn = dynbuf;
  3059. extdynend = extdyn + dynamic->size;
  3060. for (; extdyn < extdynend; extdyn += extdynsize)
  3061. {
  3062. Elf_Internal_Dyn dyn;
  3063. (*swap_dyn_in) (abfd, extdyn, &dyn);
  3064. if (dyn.d_tag == DT_NULL)
  3065. break;
  3066. if (dyn.d_tag == DT_PPC64_GLINK)
  3067. {
  3068. /* The first glink stub starts at offset 32; see
  3069. comment in ppc64_elf_finish_dynamic_sections. */
  3070. glink_vma = dyn.d_un.d_val + GLINK_CALL_STUB_SIZE - 8 * 4;
  3071. /* The .glink section usually does not survive the final
  3072. link; search for the section (usually .text) where the
  3073. glink stubs now reside. */
  3074. glink = bfd_sections_find_if (abfd, section_covers_vma,
  3075. &glink_vma);
  3076. break;
  3077. }
  3078. }
  3079. free (dynbuf);
  3080. }
  3081. if (glink != NULL)
  3082. {
  3083. /* Determine __glink trampoline by reading the relative branch
  3084. from the first glink stub. */
  3085. bfd_byte buf[4];
  3086. unsigned int off = 0;
  3087. while (bfd_get_section_contents (abfd, glink, buf,
  3088. glink_vma + off - glink->vma, 4))
  3089. {
  3090. unsigned int insn = bfd_get_32 (abfd, buf);
  3091. insn ^= B_DOT;
  3092. if ((insn & ~0x3fffffc) == 0)
  3093. {
  3094. resolv_vma = glink_vma + off + (insn ^ 0x2000000) - 0x2000000;
  3095. break;
  3096. }
  3097. off += 4;
  3098. if (off > 4)
  3099. break;
  3100. }
  3101. if (resolv_vma)
  3102. size += sizeof (asymbol) + sizeof ("__glink_PLTresolve");
  3103. relplt = bfd_get_section_by_name (abfd, ".rela.plt");
  3104. if (relplt != NULL)
  3105. {
  3106. slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
  3107. if (! (*slurp_relocs) (abfd, relplt, dyn_syms, TRUE))
  3108. goto free_contents_and_exit_err;
  3109. plt_count = relplt->size / sizeof (Elf64_External_Rela);
  3110. size += plt_count * sizeof (asymbol);
  3111. p = relplt->relocation;
  3112. for (i = 0; i < plt_count; i++, p++)
  3113. {
  3114. size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
  3115. if (p->addend != 0)
  3116. size += sizeof ("+0x") - 1 + 16;
  3117. }
  3118. }
  3119. }
  3120. if (size == 0)
  3121. goto free_contents_and_exit;
  3122. s = *ret = bfd_malloc (size);
  3123. if (s == NULL)
  3124. goto free_contents_and_exit_err;
  3125. names = (char *) (s + count + plt_count + (resolv_vma != 0));
  3126. for (i = secsymend; i < opdsymend; ++i)
  3127. {
  3128. bfd_vma ent;
  3129. if (syms[i]->value > opd->size - 8)
  3130. continue;
  3131. ent = bfd_get_64 (abfd, contents + syms[i]->value);
  3132. if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
  3133. {
  3134. long lo, hi;
  3135. size_t len;
  3136. asection *sec = abfd->sections;
  3137. *s = *syms[i];
  3138. lo = codesecsym;
  3139. hi = codesecsymend;
  3140. while (lo < hi)
  3141. {
  3142. long mid = (lo + hi) >> 1;
  3143. if (syms[mid]->section->vma < ent)
  3144. lo = mid + 1;
  3145. else if (syms[mid]->section->vma > ent)
  3146. hi = mid;
  3147. else
  3148. {
  3149. sec = syms[mid]->section;
  3150. break;
  3151. }
  3152. }
  3153. if (lo >= hi && lo > codesecsym)
  3154. sec = syms[lo - 1]->section;
  3155. for (; sec != NULL; sec = sec->next)
  3156. {
  3157. if (sec->vma > ent)
  3158. break;
  3159. /* SEC_LOAD may not be set if SEC is from a separate debug
  3160. info file. */
  3161. if ((sec->flags & SEC_ALLOC) == 0)
  3162. break;
  3163. if ((sec->flags & SEC_CODE) != 0)
  3164. s->section = sec;
  3165. }
  3166. s->flags |= BSF_SYNTHETIC;
  3167. s->value = ent - s->section->vma;
  3168. s->name = names;
  3169. *names++ = '.';
  3170. len = strlen (syms[i]->name);
  3171. memcpy (names, syms[i]->name, len + 1);
  3172. names += len + 1;
  3173. /* Have udata.p point back to the original symbol this
  3174. synthetic symbol was derived from. */
  3175. s->udata.p = syms[i];
  3176. s++;
  3177. }
  3178. }
  3179. free (contents);
  3180. if (glink != NULL && relplt != NULL)
  3181. {
  3182. if (resolv_vma)
  3183. {
  3184. /* Add a symbol for the main glink trampoline. */
  3185. memset (s, 0, sizeof *s);
  3186. s->the_bfd = abfd;
  3187. s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
  3188. s->section = glink;
  3189. s->value = resolv_vma - glink->vma;
  3190. s->name = names;
  3191. memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
  3192. names += sizeof ("__glink_PLTresolve");
  3193. s++;
  3194. count++;
  3195. }
  3196. /* FIXME: It would be very much nicer to put sym@plt on the
  3197. stub rather than on the glink branch table entry. The
  3198. objdump disassembler would then use a sensible symbol
  3199. name on plt calls. The difficulty in doing so is
  3200. a) finding the stubs, and,
  3201. b) matching stubs against plt entries, and,
  3202. c) there can be multiple stubs for a given plt entry.
  3203. Solving (a) could be done by code scanning, but older
  3204. ppc64 binaries used different stubs to current code.
  3205. (b) is the tricky one since you need to known the toc
  3206. pointer for at least one function that uses a pic stub to
  3207. be able to calculate the plt address referenced.
  3208. (c) means gdb would need to set multiple breakpoints (or
  3209. find the glink branch itself) when setting breakpoints
  3210. for pending shared library loads. */
  3211. p = relplt->relocation;
  3212. for (i = 0; i < plt_count; i++, p++)
  3213. {
  3214. size_t len;
  3215. *s = **p->sym_ptr_ptr;
  3216. /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
  3217. we are defining a symbol, ensure one of them is set. */
  3218. if ((s->flags & BSF_LOCAL) == 0)
  3219. s->flags |= BSF_GLOBAL;
  3220. s->flags |= BSF_SYNTHETIC;
  3221. s->section = glink;
  3222. s->value = glink_vma - glink->vma;
  3223. s->name = names;
  3224. s->udata.p = NULL;
  3225. len = strlen ((*p->sym_ptr_ptr)->name);
  3226. memcpy (names, (*p->sym_ptr_ptr)->name, len);
  3227. names += len;
  3228. if (p->addend != 0)
  3229. {
  3230. memcpy (names, "+0x", sizeof ("+0x") - 1);
  3231. names += sizeof ("+0x") - 1;
  3232. bfd_sprintf_vma (abfd, names, p->addend);
  3233. names += strlen (names);
  3234. }
  3235. memcpy (names, "@plt", sizeof ("@plt"));
  3236. names += sizeof ("@plt");
  3237. s++;
  3238. if (abi < 2)
  3239. {
  3240. glink_vma += 8;
  3241. if (i >= 0x8000)
  3242. glink_vma += 4;
  3243. }
  3244. else
  3245. glink_vma += 4;
  3246. }
  3247. count += plt_count;
  3248. }
  3249. }
  3250. done:
  3251. free (syms);
  3252. return count;
  3253. }
  3254. /* The following functions are specific to the ELF linker, while
  3255. functions above are used generally. Those named ppc64_elf_* are
  3256. called by the main ELF linker code. They appear in this file more
  3257. or less in the order in which they are called. eg.
  3258. ppc64_elf_check_relocs is called early in the link process,
  3259. ppc64_elf_finish_dynamic_sections is one of the last functions
  3260. called.
  3261. PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
  3262. functions have both a function code symbol and a function descriptor
  3263. symbol. A call to foo in a relocatable object file looks like:
  3264. . .text
  3265. . x:
  3266. . bl .foo
  3267. . nop
  3268. The function definition in another object file might be:
  3269. . .section .opd
  3270. . foo: .quad .foo
  3271. . .quad .TOC.@tocbase
  3272. . .quad 0
  3273. .
  3274. . .text
  3275. . .foo: blr
  3276. When the linker resolves the call during a static link, the branch
  3277. unsurprisingly just goes to .foo and the .opd information is unused.
  3278. If the function definition is in a shared library, things are a little
  3279. different: The call goes via a plt call stub, the opd information gets
  3280. copied to the plt, and the linker patches the nop.
  3281. . x:
  3282. . bl .foo_stub
  3283. . ld 2,40(1)
  3284. .
  3285. .
  3286. . .foo_stub:
  3287. . std 2,40(1) # in practice, the call stub
  3288. . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
  3289. . addi 11,11,Lfoo@toc@l # this is the general idea
  3290. . ld 12,0(11)
  3291. . ld 2,8(11)
  3292. . mtctr 12
  3293. . ld 11,16(11)
  3294. . bctr
  3295. .
  3296. . .section .plt
  3297. . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
  3298. The "reloc ()" notation is supposed to indicate that the linker emits
  3299. an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
  3300. copying.
  3301. What are the difficulties here? Well, firstly, the relocations
  3302. examined by the linker in check_relocs are against the function code
  3303. sym .foo, while the dynamic relocation in the plt is emitted against
  3304. the function descriptor symbol, foo. Somewhere along the line, we need
  3305. to carefully copy dynamic link information from one symbol to the other.
  3306. Secondly, the generic part of the elf linker will make .foo a dynamic
  3307. symbol as is normal for most other backends. We need foo dynamic
  3308. instead, at least for an application final link. However, when
  3309. creating a shared library containing foo, we need to have both symbols
  3310. dynamic so that references to .foo are satisfied during the early
  3311. stages of linking. Otherwise the linker might decide to pull in a
  3312. definition from some other object, eg. a static library.
  3313. Update: As of August 2004, we support a new convention. Function
  3314. calls may use the function descriptor symbol, ie. "bl foo". This
  3315. behaves exactly as "bl .foo". */
  3316. /* Of those relocs that might be copied as dynamic relocs, this function
  3317. selects those that must be copied when linking a shared library,
  3318. even when the symbol is local. */
  3319. static int
  3320. must_be_dyn_reloc (struct bfd_link_info *info,
  3321. enum elf_ppc64_reloc_type r_type)
  3322. {
  3323. switch (r_type)
  3324. {
  3325. default:
  3326. return 1;
  3327. case R_PPC64_REL32:
  3328. case R_PPC64_REL64:
  3329. case R_PPC64_REL30:
  3330. return 0;
  3331. case R_PPC64_TPREL16:
  3332. case R_PPC64_TPREL16_LO:
  3333. case R_PPC64_TPREL16_HI:
  3334. case R_PPC64_TPREL16_HA:
  3335. case R_PPC64_TPREL16_DS:
  3336. case R_PPC64_TPREL16_LO_DS:
  3337. case R_PPC64_TPREL16_HIGH:
  3338. case R_PPC64_TPREL16_HIGHA:
  3339. case R_PPC64_TPREL16_HIGHER:
  3340. case R_PPC64_TPREL16_HIGHERA:
  3341. case R_PPC64_TPREL16_HIGHEST:
  3342. case R_PPC64_TPREL16_HIGHESTA:
  3343. case R_PPC64_TPREL64:
  3344. return !bfd_link_executable (info);
  3345. }
  3346. }
  3347. /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
  3348. copying dynamic variables from a shared lib into an app's dynbss
  3349. section, and instead use a dynamic relocation to point into the
  3350. shared lib. With code that gcc generates, it's vital that this be
  3351. enabled; In the PowerPC64 ABI, the address of a function is actually
  3352. the address of a function descriptor, which resides in the .opd
  3353. section. gcc uses the descriptor directly rather than going via the
  3354. GOT as some other ABI's do, which means that initialized function
  3355. pointers must reference the descriptor. Thus, a function pointer
  3356. initialized to the address of a function in a shared library will
  3357. either require a copy reloc, or a dynamic reloc. Using a copy reloc
  3358. redefines the function descriptor symbol to point to the copy. This
  3359. presents a problem as a plt entry for that function is also
  3360. initialized from the function descriptor symbol and the copy reloc
  3361. may not be initialized first. */
  3362. #define ELIMINATE_COPY_RELOCS 1
  3363. /* Section name for stubs is the associated section name plus this
  3364. string. */
  3365. #define STUB_SUFFIX ".stub"
  3366. /* Linker stubs.
  3367. ppc_stub_long_branch:
  3368. Used when a 14 bit branch (or even a 24 bit branch) can't reach its
  3369. destination, but a 24 bit branch in a stub section will reach.
  3370. . b dest
  3371. ppc_stub_plt_branch:
  3372. Similar to the above, but a 24 bit branch in the stub section won't
  3373. reach its destination.
  3374. . addis %r11,%r2,xxx@toc@ha
  3375. . ld %r12,xxx@toc@l(%r11)
  3376. . mtctr %r12
  3377. . bctr
  3378. ppc_stub_plt_call:
  3379. Used to call a function in a shared library. If it so happens that
  3380. the plt entry referenced crosses a 64k boundary, then an extra
  3381. "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
  3382. . std %r2,40(%r1)
  3383. . addis %r11,%r2,xxx@toc@ha
  3384. . ld %r12,xxx+0@toc@l(%r11)
  3385. . mtctr %r12
  3386. . ld %r2,xxx+8@toc@l(%r11)
  3387. . ld %r11,xxx+16@toc@l(%r11)
  3388. . bctr
  3389. ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
  3390. code to adjust the value and save r2 to support multiple toc sections.
  3391. A ppc_stub_long_branch with an r2 offset looks like:
  3392. . std %r2,40(%r1)
  3393. . addis %r2,%r2,off@ha
  3394. . addi %r2,%r2,off@l
  3395. . b dest
  3396. A ppc_stub_plt_branch with an r2 offset looks like:
  3397. . std %r2,40(%r1)
  3398. . addis %r11,%r2,xxx@toc@ha
  3399. . ld %r12,xxx@toc@l(%r11)
  3400. . addis %r2,%r2,off@ha
  3401. . addi %r2,%r2,off@l
  3402. . mtctr %r12
  3403. . bctr
  3404. In cases where the "addis" instruction would add zero, the "addis" is
  3405. omitted and following instructions modified slightly in some cases.
  3406. */
  3407. enum ppc_stub_type {
  3408. ppc_stub_none,
  3409. ppc_stub_long_branch,
  3410. ppc_stub_long_branch_r2off,
  3411. ppc_stub_plt_branch,
  3412. ppc_stub_plt_branch_r2off,
  3413. ppc_stub_plt_call,
  3414. ppc_stub_plt_call_r2save,
  3415. ppc_stub_global_entry,
  3416. ppc_stub_save_res
  3417. };
  3418. /* Information on stub grouping. */
  3419. struct map_stub
  3420. {
  3421. /* The stub section. */
  3422. asection *stub_sec;
  3423. /* This is the section to which stubs in the group will be attached. */
  3424. asection *link_sec;
  3425. /* Next group. */
  3426. struct map_stub *next;
  3427. /* Whether to emit a copy of register save/restore functions in this
  3428. group. */
  3429. int needs_save_res;
  3430. };
  3431. struct ppc_stub_hash_entry {
  3432. /* Base hash table entry structure. */
  3433. struct bfd_hash_entry root;
  3434. enum ppc_stub_type stub_type;
  3435. /* Group information. */
  3436. struct map_stub *group;
  3437. /* Offset within stub_sec of the beginning of this stub. */
  3438. bfd_vma stub_offset;
  3439. /* Given the symbol's value and its section we can determine its final
  3440. value when building the stubs (so the stub knows where to jump. */
  3441. bfd_vma target_value;
  3442. asection *target_section;
  3443. /* The symbol table entry, if any, that this was derived from. */
  3444. struct ppc_link_hash_entry *h;
  3445. struct plt_entry *plt_ent;
  3446. /* Symbol st_other. */
  3447. unsigned char other;
  3448. };
  3449. struct ppc_branch_hash_entry {
  3450. /* Base hash table entry structure. */
  3451. struct bfd_hash_entry root;
  3452. /* Offset within branch lookup table. */
  3453. unsigned int offset;
  3454. /* Generation marker. */
  3455. unsigned int iter;
  3456. };
  3457. /* Used to track dynamic relocations for local symbols. */
  3458. struct ppc_dyn_relocs
  3459. {
  3460. struct ppc_dyn_relocs *next;
  3461. /* The input section of the reloc. */
  3462. asection *sec;
  3463. /* Total number of relocs copied for the input section. */
  3464. unsigned int count : 31;
  3465. /* Whether this entry is for STT_GNU_IFUNC symbols. */
  3466. unsigned int ifunc : 1;
  3467. };
  3468. struct ppc_link_hash_entry
  3469. {
  3470. struct elf_link_hash_entry elf;
  3471. union {
  3472. /* A pointer to the most recently used stub hash entry against this
  3473. symbol. */
  3474. struct ppc_stub_hash_entry *stub_cache;
  3475. /* A pointer to the next symbol starting with a '.' */
  3476. struct ppc_link_hash_entry *next_dot_sym;
  3477. } u;
  3478. /* Track dynamic relocs copied for this symbol. */
  3479. struct elf_dyn_relocs *dyn_relocs;
  3480. /* Link between function code and descriptor symbols. */
  3481. struct ppc_link_hash_entry *oh;
  3482. /* Flag function code and descriptor symbols. */
  3483. unsigned int is_func:1;
  3484. unsigned int is_func_descriptor:1;
  3485. unsigned int fake:1;
  3486. /* Whether global opd/toc sym has been adjusted or not.
  3487. After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
  3488. should be set for all globals defined in any opd/toc section. */
  3489. unsigned int adjust_done:1;
  3490. /* Set if we twiddled this symbol to weak at some stage. */
  3491. unsigned int was_undefined:1;
  3492. /* Set if this is an out-of-line register save/restore function,
  3493. with non-standard calling convention. */
  3494. unsigned int save_res:1;
  3495. /* Contexts in which symbol is used in the GOT (or TOC).
  3496. TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
  3497. corresponding relocs are encountered during check_relocs.
  3498. tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
  3499. indicate the corresponding GOT entry type is not needed.
  3500. tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
  3501. a TPREL one. We use a separate flag rather than setting TPREL
  3502. just for convenience in distinguishing the two cases. */
  3503. #define TLS_GD 1 /* GD reloc. */
  3504. #define TLS_LD 2 /* LD reloc. */
  3505. #define TLS_TPREL 4 /* TPREL reloc, => IE. */
  3506. #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
  3507. #define TLS_TLS 16 /* Any TLS reloc. */
  3508. #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
  3509. #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
  3510. #define PLT_IFUNC 128 /* STT_GNU_IFUNC. */
  3511. unsigned char tls_mask;
  3512. };
  3513. /* ppc64 ELF linker hash table. */
  3514. struct ppc_link_hash_table
  3515. {
  3516. struct elf_link_hash_table elf;
  3517. /* The stub hash table. */
  3518. struct bfd_hash_table stub_hash_table;
  3519. /* Another hash table for plt_branch stubs. */
  3520. struct bfd_hash_table branch_hash_table;
  3521. /* Hash table for function prologue tocsave. */
  3522. htab_t tocsave_htab;
  3523. /* Various options and other info passed from the linker. */
  3524. struct ppc64_elf_params *params;
  3525. /* The size of sec_info below. */
  3526. unsigned int sec_info_arr_size;
  3527. /* Per-section array of extra section info. Done this way rather
  3528. than as part of ppc64_elf_section_data so we have the info for
  3529. non-ppc64 sections. */
  3530. struct
  3531. {
  3532. /* Along with elf_gp, specifies the TOC pointer used by this section. */
  3533. bfd_vma toc_off;
  3534. union
  3535. {
  3536. /* The section group that this section belongs to. */
  3537. struct map_stub *group;
  3538. /* A temp section list pointer. */
  3539. asection *list;
  3540. } u;
  3541. } *sec_info;
  3542. /* Linked list of groups. */
  3543. struct map_stub *group;
  3544. /* Temp used when calculating TOC pointers. */
  3545. bfd_vma toc_curr;
  3546. bfd *toc_bfd;
  3547. asection *toc_first_sec;
  3548. /* Used when adding symbols. */
  3549. struct ppc_link_hash_entry *dot_syms;
  3550. /* Shortcuts to get to dynamic linker sections. */
  3551. asection *dynbss;
  3552. asection *relbss;
  3553. asection *glink;
  3554. asection *sfpr;
  3555. asection *brlt;
  3556. asection *relbrlt;
  3557. asection *glink_eh_frame;
  3558. /* Shortcut to .__tls_get_addr and __tls_get_addr. */
  3559. struct ppc_link_hash_entry *tls_get_addr;
  3560. struct ppc_link_hash_entry *tls_get_addr_fd;
  3561. /* The size of reliplt used by got entry relocs. */
  3562. bfd_size_type got_reli_size;
  3563. /* Statistics. */
  3564. unsigned long stub_count[ppc_stub_global_entry];
  3565. /* Number of stubs against global syms. */
  3566. unsigned long stub_globals;
  3567. /* Set if we're linking code with function descriptors. */
  3568. unsigned int opd_abi:1;
  3569. /* Support for multiple toc sections. */
  3570. unsigned int do_multi_toc:1;
  3571. unsigned int multi_toc_needed:1;
  3572. unsigned int second_toc_pass:1;
  3573. unsigned int do_toc_opt:1;
  3574. /* Set on error. */
  3575. unsigned int stub_error:1;
  3576. /* Temp used by ppc64_elf_before_check_relocs. */
  3577. unsigned int twiddled_syms:1;
  3578. /* Incremented every time we size stubs. */
  3579. unsigned int stub_iteration;
  3580. /* Small local sym cache. */
  3581. struct sym_cache sym_cache;
  3582. };
  3583. /* Rename some of the generic section flags to better document how they
  3584. are used here. */
  3585. /* Nonzero if this section has TLS related relocations. */
  3586. #define has_tls_reloc sec_flg0
  3587. /* Nonzero if this section has a call to __tls_get_addr. */
  3588. #define has_tls_get_addr_call sec_flg1
  3589. /* Nonzero if this section has any toc or got relocs. */
  3590. #define has_toc_reloc sec_flg2
  3591. /* Nonzero if this section has a call to another section that uses
  3592. the toc or got. */
  3593. #define makes_toc_func_call sec_flg3
  3594. /* Recursion protection when determining above flag. */
  3595. #define call_check_in_progress sec_flg4
  3596. #define call_check_done sec_flg5
  3597. /* Get the ppc64 ELF linker hash table from a link_info structure. */
  3598. #define ppc_hash_table(p) \
  3599. (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
  3600. == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
  3601. #define ppc_stub_hash_lookup(table, string, create, copy) \
  3602. ((struct ppc_stub_hash_entry *) \
  3603. bfd_hash_lookup ((table), (string), (create), (copy)))
  3604. #define ppc_branch_hash_lookup(table, string, create, copy) \
  3605. ((struct ppc_branch_hash_entry *) \
  3606. bfd_hash_lookup ((table), (string), (create), (copy)))
  3607. /* Create an entry in the stub hash table. */
  3608. static struct bfd_hash_entry *
  3609. stub_hash_newfunc (struct bfd_hash_entry *entry,
  3610. struct bfd_hash_table *table,
  3611. const char *string)
  3612. {
  3613. /* Allocate the structure if it has not already been allocated by a
  3614. subclass. */
  3615. if (entry == NULL)
  3616. {
  3617. entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
  3618. if (entry == NULL)
  3619. return entry;
  3620. }
  3621. /* Call the allocation method of the superclass. */
  3622. entry = bfd_hash_newfunc (entry, table, string);
  3623. if (entry != NULL)
  3624. {
  3625. struct ppc_stub_hash_entry *eh;
  3626. /* Initialize the local fields. */
  3627. eh = (struct ppc_stub_hash_entry *) entry;
  3628. eh->stub_type = ppc_stub_none;
  3629. eh->group = NULL;
  3630. eh->stub_offset = 0;
  3631. eh->target_value = 0;
  3632. eh->target_section = NULL;
  3633. eh->h = NULL;
  3634. eh->plt_ent = NULL;
  3635. eh->other = 0;
  3636. }
  3637. return entry;
  3638. }
  3639. /* Create an entry in the branch hash table. */
  3640. static struct bfd_hash_entry *
  3641. branch_hash_newfunc (struct bfd_hash_entry *entry,
  3642. struct bfd_hash_table *table,
  3643. const char *string)
  3644. {
  3645. /* Allocate the structure if it has not already been allocated by a
  3646. subclass. */
  3647. if (entry == NULL)
  3648. {
  3649. entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
  3650. if (entry == NULL)
  3651. return entry;
  3652. }
  3653. /* Call the allocation method of the superclass. */
  3654. entry = bfd_hash_newfunc (entry, table, string);
  3655. if (entry != NULL)
  3656. {
  3657. struct ppc_branch_hash_entry *eh;
  3658. /* Initialize the local fields. */
  3659. eh = (struct ppc_branch_hash_entry *) entry;
  3660. eh->offset = 0;
  3661. eh->iter = 0;
  3662. }
  3663. return entry;
  3664. }
  3665. /* Create an entry in a ppc64 ELF linker hash table. */
  3666. static struct bfd_hash_entry *
  3667. link_hash_newfunc (struct bfd_hash_entry *entry,
  3668. struct bfd_hash_table *table,
  3669. const char *string)
  3670. {
  3671. /* Allocate the structure if it has not already been allocated by a
  3672. subclass. */
  3673. if (entry == NULL)
  3674. {
  3675. entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
  3676. if (entry == NULL)
  3677. return entry;
  3678. }
  3679. /* Call the allocation method of the superclass. */
  3680. entry = _bfd_elf_link_hash_newfunc (entry, table, string);
  3681. if (entry != NULL)
  3682. {
  3683. struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
  3684. memset (&eh->u.stub_cache, 0,
  3685. (sizeof (struct ppc_link_hash_entry)
  3686. - offsetof (struct ppc_link_hash_entry, u.stub_cache)));
  3687. /* When making function calls, old ABI code references function entry
  3688. points (dot symbols), while new ABI code references the function
  3689. descriptor symbol. We need to make any combination of reference and
  3690. definition work together, without breaking archive linking.
  3691. For a defined function "foo" and an undefined call to "bar":
  3692. An old object defines "foo" and ".foo", references ".bar" (possibly
  3693. "bar" too).
  3694. A new object defines "foo" and references "bar".
  3695. A new object thus has no problem with its undefined symbols being
  3696. satisfied by definitions in an old object. On the other hand, the
  3697. old object won't have ".bar" satisfied by a new object.
  3698. Keep a list of newly added dot-symbols. */
  3699. if (string[0] == '.')
  3700. {
  3701. struct ppc_link_hash_table *htab;
  3702. htab = (struct ppc_link_hash_table *) table;
  3703. eh->u.next_dot_sym = htab->dot_syms;
  3704. htab->dot_syms = eh;
  3705. }
  3706. }
  3707. return entry;
  3708. }
  3709. struct tocsave_entry {
  3710. asection *sec;
  3711. bfd_vma offset;
  3712. };
  3713. static hashval_t
  3714. tocsave_htab_hash (const void *p)
  3715. {
  3716. const struct tocsave_entry *e = (const struct tocsave_entry *) p;
  3717. return ((bfd_vma)(intptr_t) e->sec ^ e->offset) >> 3;
  3718. }
  3719. static int
  3720. tocsave_htab_eq (const void *p1, const void *p2)
  3721. {
  3722. const struct tocsave_entry *e1 = (const struct tocsave_entry *) p1;
  3723. const struct tocsave_entry *e2 = (const struct tocsave_entry *) p2;
  3724. return e1->sec == e2->sec && e1->offset == e2->offset;
  3725. }
  3726. /* Destroy a ppc64 ELF linker hash table. */
  3727. static void
  3728. ppc64_elf_link_hash_table_free (bfd *obfd)
  3729. {
  3730. struct ppc_link_hash_table *htab;
  3731. htab = (struct ppc_link_hash_table *) obfd->link.hash;
  3732. if (htab->tocsave_htab)
  3733. htab_delete (htab->tocsave_htab);
  3734. bfd_hash_table_free (&htab->branch_hash_table);
  3735. bfd_hash_table_free (&htab->stub_hash_table);
  3736. _bfd_elf_link_hash_table_free (obfd);
  3737. }
  3738. /* Create a ppc64 ELF linker hash table. */
  3739. static struct bfd_link_hash_table *
  3740. ppc64_elf_link_hash_table_create (bfd *abfd)
  3741. {
  3742. struct ppc_link_hash_table *htab;
  3743. bfd_size_type amt = sizeof (struct ppc_link_hash_table);
  3744. htab = bfd_zmalloc (amt);
  3745. if (htab == NULL)
  3746. return NULL;
  3747. if (!_bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc,
  3748. sizeof (struct ppc_link_hash_entry),
  3749. PPC64_ELF_DATA))
  3750. {
  3751. free (htab);
  3752. return NULL;
  3753. }
  3754. /* Init the stub hash table too. */
  3755. if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc,
  3756. sizeof (struct ppc_stub_hash_entry)))
  3757. {
  3758. _bfd_elf_link_hash_table_free (abfd);
  3759. return NULL;
  3760. }
  3761. /* And the branch hash table. */
  3762. if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc,
  3763. sizeof (struct ppc_branch_hash_entry)))
  3764. {
  3765. bfd_hash_table_free (&htab->stub_hash_table);
  3766. _bfd_elf_link_hash_table_free (abfd);
  3767. return NULL;
  3768. }
  3769. htab->tocsave_htab = htab_try_create (1024,
  3770. tocsave_htab_hash,
  3771. tocsave_htab_eq,
  3772. NULL);
  3773. if (htab->tocsave_htab == NULL)
  3774. {
  3775. ppc64_elf_link_hash_table_free (abfd);
  3776. return NULL;
  3777. }
  3778. htab->elf.root.hash_table_free = ppc64_elf_link_hash_table_free;
  3779. /* Initializing two fields of the union is just cosmetic. We really
  3780. only care about glist, but when compiled on a 32-bit host the
  3781. bfd_vma fields are larger. Setting the bfd_vma to zero makes
  3782. debugger inspection of these fields look nicer. */
  3783. htab->elf.init_got_refcount.refcount = 0;
  3784. htab->elf.init_got_refcount.glist = NULL;
  3785. htab->elf.init_plt_refcount.refcount = 0;
  3786. htab->elf.init_plt_refcount.glist = NULL;
  3787. htab->elf.init_got_offset.offset = 0;
  3788. htab->elf.init_got_offset.glist = NULL;
  3789. htab->elf.init_plt_offset.offset = 0;
  3790. htab->elf.init_plt_offset.glist = NULL;
  3791. return &htab->elf.root;
  3792. }
  3793. /* Create sections for linker generated code. */
  3794. static bfd_boolean
  3795. create_linkage_sections (bfd *dynobj, struct bfd_link_info *info)
  3796. {
  3797. struct ppc_link_hash_table *htab;
  3798. flagword flags;
  3799. htab = ppc_hash_table (info);
  3800. /* Create .sfpr for code to save and restore fp regs. */
  3801. flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
  3802. | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
  3803. htab->sfpr = bfd_make_section_anyway_with_flags (dynobj, ".sfpr",
  3804. flags);
  3805. if (htab->sfpr == NULL
  3806. || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
  3807. return FALSE;
  3808. /* Create .glink for lazy dynamic linking support. */
  3809. htab->glink = bfd_make_section_anyway_with_flags (dynobj, ".glink",
  3810. flags);
  3811. if (htab->glink == NULL
  3812. || ! bfd_set_section_alignment (dynobj, htab->glink, 3))
  3813. return FALSE;
  3814. if (!info->no_ld_generated_unwind_info)
  3815. {
  3816. flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
  3817. | SEC_IN_MEMORY | SEC_LINKER_CREATED);
  3818. htab->glink_eh_frame = bfd_make_section_anyway_with_flags (dynobj,
  3819. ".eh_frame",
  3820. flags);
  3821. if (htab->glink_eh_frame == NULL
  3822. || !bfd_set_section_alignment (dynobj, htab->glink_eh_frame, 2))
  3823. return FALSE;
  3824. }
  3825. flags = SEC_ALLOC | SEC_LINKER_CREATED;
  3826. htab->elf.iplt = bfd_make_section_anyway_with_flags (dynobj, ".iplt", flags);
  3827. if (htab->elf.iplt == NULL
  3828. || ! bfd_set_section_alignment (dynobj, htab->elf.iplt, 3))
  3829. return FALSE;
  3830. flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
  3831. | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
  3832. htab->elf.irelplt
  3833. = bfd_make_section_anyway_with_flags (dynobj, ".rela.iplt", flags);
  3834. if (htab->elf.irelplt == NULL
  3835. || ! bfd_set_section_alignment (dynobj, htab->elf.irelplt, 3))
  3836. return FALSE;
  3837. /* Create branch lookup table for plt_branch stubs. */
  3838. flags = (SEC_ALLOC | SEC_LOAD
  3839. | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
  3840. htab->brlt = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt",
  3841. flags);
  3842. if (htab->brlt == NULL
  3843. || ! bfd_set_section_alignment (dynobj, htab->brlt, 3))
  3844. return FALSE;
  3845. if (!bfd_link_pic (info))
  3846. return TRUE;
  3847. flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
  3848. | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
  3849. htab->relbrlt = bfd_make_section_anyway_with_flags (dynobj,
  3850. ".rela.branch_lt",
  3851. flags);
  3852. if (htab->relbrlt == NULL
  3853. || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3))
  3854. return FALSE;
  3855. return TRUE;
  3856. }
  3857. /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
  3858. bfd_boolean
  3859. ppc64_elf_init_stub_bfd (struct bfd_link_info *info,
  3860. struct ppc64_elf_params *params)
  3861. {
  3862. struct ppc_link_hash_table *htab;
  3863. elf_elfheader (params->stub_bfd)->e_ident[EI_CLASS] = ELFCLASS64;
  3864. /* Always hook our dynamic sections into the first bfd, which is the
  3865. linker created stub bfd. This ensures that the GOT header is at
  3866. the start of the output TOC section. */
  3867. htab = ppc_hash_table (info);
  3868. if (htab == NULL)
  3869. return FALSE;
  3870. htab->elf.dynobj = params->stub_bfd;
  3871. htab->params = params;
  3872. if (bfd_link_relocatable (info))
  3873. return TRUE;
  3874. return create_linkage_sections (htab->elf.dynobj, info);
  3875. }
  3876. /* Build a name for an entry in the stub hash table. */
  3877. static char *
  3878. ppc_stub_name (const asection *input_section,
  3879. const asection *sym_sec,
  3880. const struct ppc_link_hash_entry *h,
  3881. const Elf_Internal_Rela *rel)
  3882. {
  3883. char *stub_name;
  3884. ssize_t len;
  3885. /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
  3886. offsets from a sym as a branch target? In fact, we could
  3887. probably assume the addend is always zero. */
  3888. BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
  3889. if (h)
  3890. {
  3891. len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
  3892. stub_name = bfd_malloc (len);
  3893. if (stub_name == NULL)
  3894. return stub_name;
  3895. len = sprintf (stub_name, "%08x.%s+%x",
  3896. input_section->id & 0xffffffff,
  3897. h->elf.root.root.string,
  3898. (int) rel->r_addend & 0xffffffff);
  3899. }
  3900. else
  3901. {
  3902. len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
  3903. stub_name = bfd_malloc (len);
  3904. if (stub_name == NULL)
  3905. return stub_name;
  3906. len = sprintf (stub_name, "%08x.%x:%x+%x",
  3907. input_section->id & 0xffffffff,
  3908. sym_sec->id & 0xffffffff,
  3909. (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
  3910. (int) rel->r_addend & 0xffffffff);
  3911. }
  3912. if (len > 2 && stub_name[len - 2] == '+' && stub_name[len - 1] == '0')
  3913. stub_name[len - 2] = 0;
  3914. return stub_name;
  3915. }
  3916. /* Look up an entry in the stub hash. Stub entries are cached because
  3917. creating the stub name takes a bit of time. */
  3918. static struct ppc_stub_hash_entry *
  3919. ppc_get_stub_entry (const asection *input_section,
  3920. const asection *sym_sec,
  3921. struct ppc_link_hash_entry *h,
  3922. const Elf_Internal_Rela *rel,
  3923. struct ppc_link_hash_table *htab)
  3924. {
  3925. struct ppc_stub_hash_entry *stub_entry;
  3926. struct map_stub *group;
  3927. /* If this input section is part of a group of sections sharing one
  3928. stub section, then use the id of the first section in the group.
  3929. Stub names need to include a section id, as there may well be
  3930. more than one stub used to reach say, printf, and we need to
  3931. distinguish between them. */
  3932. group = htab->sec_info[input_section->id].u.group;
  3933. if (h != NULL && h->u.stub_cache != NULL
  3934. && h->u.stub_cache->h == h
  3935. && h->u.stub_cache->group == group)
  3936. {
  3937. stub_entry = h->u.stub_cache;
  3938. }
  3939. else
  3940. {
  3941. char *stub_name;
  3942. stub_name = ppc_stub_name (group->link_sec, sym_sec, h, rel);
  3943. if (stub_name == NULL)
  3944. return NULL;
  3945. stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
  3946. stub_name, FALSE, FALSE);
  3947. if (h != NULL)
  3948. h->u.stub_cache = stub_entry;
  3949. free (stub_name);
  3950. }
  3951. return stub_entry;
  3952. }
  3953. /* Add a new stub entry to the stub hash. Not all fields of the new
  3954. stub entry are initialised. */
  3955. static struct ppc_stub_hash_entry *
  3956. ppc_add_stub (const char *stub_name,
  3957. asection *section,
  3958. struct bfd_link_info *info)
  3959. {
  3960. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  3961. struct map_stub *group;
  3962. asection *link_sec;
  3963. asection *stub_sec;
  3964. struct ppc_stub_hash_entry *stub_entry;
  3965. group = htab->sec_info[section->id].u.group;
  3966. link_sec = group->link_sec;
  3967. stub_sec = group->stub_sec;
  3968. if (stub_sec == NULL)
  3969. {
  3970. size_t namelen;
  3971. bfd_size_type len;
  3972. char *s_name;
  3973. namelen = strlen (link_sec->name);
  3974. len = namelen + sizeof (STUB_SUFFIX);
  3975. s_name = bfd_alloc (htab->params->stub_bfd, len);
  3976. if (s_name == NULL)
  3977. return NULL;
  3978. memcpy (s_name, link_sec->name, namelen);
  3979. memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
  3980. stub_sec = (*htab->params->add_stub_section) (s_name, link_sec);
  3981. if (stub_sec == NULL)
  3982. return NULL;
  3983. group->stub_sec = stub_sec;
  3984. }
  3985. /* Enter this entry into the linker stub hash table. */
  3986. stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
  3987. TRUE, FALSE);
  3988. if (stub_entry == NULL)
  3989. {
  3990. info->callbacks->einfo (_("%P: %B: cannot create stub entry %s\n"),
  3991. section->owner, stub_name);
  3992. return NULL;
  3993. }
  3994. stub_entry->group = group;
  3995. stub_entry->stub_offset = 0;
  3996. return stub_entry;
  3997. }
  3998. /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
  3999. not already done. */
  4000. static bfd_boolean
  4001. create_got_section (bfd *abfd, struct bfd_link_info *info)
  4002. {
  4003. asection *got, *relgot;
  4004. flagword flags;
  4005. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  4006. if (!is_ppc64_elf (abfd))
  4007. return FALSE;
  4008. if (htab == NULL)
  4009. return FALSE;
  4010. if (!htab->elf.sgot
  4011. && !_bfd_elf_create_got_section (htab->elf.dynobj, info))
  4012. return FALSE;
  4013. flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
  4014. | SEC_LINKER_CREATED);
  4015. got = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
  4016. if (!got
  4017. || !bfd_set_section_alignment (abfd, got, 3))
  4018. return FALSE;
  4019. relgot = bfd_make_section_anyway_with_flags (abfd, ".rela.got",
  4020. flags | SEC_READONLY);
  4021. if (!relgot
  4022. || ! bfd_set_section_alignment (abfd, relgot, 3))
  4023. return FALSE;
  4024. ppc64_elf_tdata (abfd)->got = got;
  4025. ppc64_elf_tdata (abfd)->relgot = relgot;
  4026. return TRUE;
  4027. }
  4028. /* Create the dynamic sections, and set up shortcuts. */
  4029. static bfd_boolean
  4030. ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
  4031. {
  4032. struct ppc_link_hash_table *htab;
  4033. if (!_bfd_elf_create_dynamic_sections (dynobj, info))
  4034. return FALSE;
  4035. htab = ppc_hash_table (info);
  4036. if (htab == NULL)
  4037. return FALSE;
  4038. htab->dynbss = bfd_get_linker_section (dynobj, ".dynbss");
  4039. if (!bfd_link_pic (info))
  4040. htab->relbss = bfd_get_linker_section (dynobj, ".rela.bss");
  4041. if (!htab->elf.sgot || !htab->elf.splt || !htab->elf.srelplt || !htab->dynbss
  4042. || (!bfd_link_pic (info) && !htab->relbss))
  4043. abort ();
  4044. return TRUE;
  4045. }
  4046. /* Follow indirect and warning symbol links. */
  4047. static inline struct bfd_link_hash_entry *
  4048. follow_link (struct bfd_link_hash_entry *h)
  4049. {
  4050. while (h->type == bfd_link_hash_indirect
  4051. || h->type == bfd_link_hash_warning)
  4052. h = h->u.i.link;
  4053. return h;
  4054. }
  4055. static inline struct elf_link_hash_entry *
  4056. elf_follow_link (struct elf_link_hash_entry *h)
  4057. {
  4058. return (struct elf_link_hash_entry *) follow_link (&h->root);
  4059. }
  4060. static inline struct ppc_link_hash_entry *
  4061. ppc_follow_link (struct ppc_link_hash_entry *h)
  4062. {
  4063. return (struct ppc_link_hash_entry *) follow_link (&h->elf.root);
  4064. }
  4065. /* Merge PLT info on FROM with that on TO. */
  4066. static void
  4067. move_plt_plist (struct ppc_link_hash_entry *from,
  4068. struct ppc_link_hash_entry *to)
  4069. {
  4070. if (from->elf.plt.plist != NULL)
  4071. {
  4072. if (to->elf.plt.plist != NULL)
  4073. {
  4074. struct plt_entry **entp;
  4075. struct plt_entry *ent;
  4076. for (entp = &from->elf.plt.plist; (ent = *entp) != NULL; )
  4077. {
  4078. struct plt_entry *dent;
  4079. for (dent = to->elf.plt.plist; dent != NULL; dent = dent->next)
  4080. if (dent->addend == ent->addend)
  4081. {
  4082. dent->plt.refcount += ent->plt.refcount;
  4083. *entp = ent->next;
  4084. break;
  4085. }
  4086. if (dent == NULL)
  4087. entp = &ent->next;
  4088. }
  4089. *entp = to->elf.plt.plist;
  4090. }
  4091. to->elf.plt.plist = from->elf.plt.plist;
  4092. from->elf.plt.plist = NULL;
  4093. }
  4094. }
  4095. /* Copy the extra info we tack onto an elf_link_hash_entry. */
  4096. static void
  4097. ppc64_elf_copy_indirect_symbol (struct bfd_link_info *info,
  4098. struct elf_link_hash_entry *dir,
  4099. struct elf_link_hash_entry *ind)
  4100. {
  4101. struct ppc_link_hash_entry *edir, *eind;
  4102. edir = (struct ppc_link_hash_entry *) dir;
  4103. eind = (struct ppc_link_hash_entry *) ind;
  4104. edir->is_func |= eind->is_func;
  4105. edir->is_func_descriptor |= eind->is_func_descriptor;
  4106. edir->tls_mask |= eind->tls_mask;
  4107. if (eind->oh != NULL)
  4108. edir->oh = ppc_follow_link (eind->oh);
  4109. /* If called to transfer flags for a weakdef during processing
  4110. of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
  4111. We clear it ourselves for ELIMINATE_COPY_RELOCS. */
  4112. if (!(ELIMINATE_COPY_RELOCS
  4113. && eind->elf.root.type != bfd_link_hash_indirect
  4114. && edir->elf.dynamic_adjusted))
  4115. edir->elf.non_got_ref |= eind->elf.non_got_ref;
  4116. edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
  4117. edir->elf.ref_regular |= eind->elf.ref_regular;
  4118. edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
  4119. edir->elf.needs_plt |= eind->elf.needs_plt;
  4120. edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed;
  4121. /* Copy over any dynamic relocs we may have on the indirect sym. */
  4122. if (eind->dyn_relocs != NULL)
  4123. {
  4124. if (edir->dyn_relocs != NULL)
  4125. {
  4126. struct elf_dyn_relocs **pp;
  4127. struct elf_dyn_relocs *p;
  4128. /* Add reloc counts against the indirect sym to the direct sym
  4129. list. Merge any entries against the same section. */
  4130. for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
  4131. {
  4132. struct elf_dyn_relocs *q;
  4133. for (q = edir->dyn_relocs; q != NULL; q = q->next)
  4134. if (q->sec == p->sec)
  4135. {
  4136. q->pc_count += p->pc_count;
  4137. q->count += p->count;
  4138. *pp = p->next;
  4139. break;
  4140. }
  4141. if (q == NULL)
  4142. pp = &p->next;
  4143. }
  4144. *pp = edir->dyn_relocs;
  4145. }
  4146. edir->dyn_relocs = eind->dyn_relocs;
  4147. eind->dyn_relocs = NULL;
  4148. }
  4149. /* If we were called to copy over info for a weak sym, that's all.
  4150. You might think dyn_relocs need not be copied over; After all,
  4151. both syms will be dynamic or both non-dynamic so we're just
  4152. moving reloc accounting around. However, ELIMINATE_COPY_RELOCS
  4153. code in ppc64_elf_adjust_dynamic_symbol needs to check for
  4154. dyn_relocs in read-only sections, and it does so on what is the
  4155. DIR sym here. */
  4156. if (eind->elf.root.type != bfd_link_hash_indirect)
  4157. return;
  4158. /* Copy over got entries that we may have already seen to the
  4159. symbol which just became indirect. */
  4160. if (eind->elf.got.glist != NULL)
  4161. {
  4162. if (edir->elf.got.glist != NULL)
  4163. {
  4164. struct got_entry **entp;
  4165. struct got_entry *ent;
  4166. for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; )
  4167. {
  4168. struct got_entry *dent;
  4169. for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next)
  4170. if (dent->addend == ent->addend
  4171. && dent->owner == ent->owner
  4172. && dent->tls_type == ent->tls_type)
  4173. {
  4174. dent->got.refcount += ent->got.refcount;
  4175. *entp = ent->next;
  4176. break;
  4177. }
  4178. if (dent == NULL)
  4179. entp = &ent->next;
  4180. }
  4181. *entp = edir->elf.got.glist;
  4182. }
  4183. edir->elf.got.glist = eind->elf.got.glist;
  4184. eind->elf.got.glist = NULL;
  4185. }
  4186. /* And plt entries. */
  4187. move_plt_plist (eind, edir);
  4188. if (eind->elf.dynindx != -1)
  4189. {
  4190. if (edir->elf.dynindx != -1)
  4191. _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
  4192. edir->elf.dynstr_index);
  4193. edir->elf.dynindx = eind->elf.dynindx;
  4194. edir->elf.dynstr_index = eind->elf.dynstr_index;
  4195. eind->elf.dynindx = -1;
  4196. eind->elf.dynstr_index = 0;
  4197. }
  4198. }
  4199. /* Find the function descriptor hash entry from the given function code
  4200. hash entry FH. Link the entries via their OH fields. */
  4201. static struct ppc_link_hash_entry *
  4202. lookup_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab)
  4203. {
  4204. struct ppc_link_hash_entry *fdh = fh->oh;
  4205. if (fdh == NULL)
  4206. {
  4207. const char *fd_name = fh->elf.root.root.string + 1;
  4208. fdh = (struct ppc_link_hash_entry *)
  4209. elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE);
  4210. if (fdh == NULL)
  4211. return fdh;
  4212. fdh->is_func_descriptor = 1;
  4213. fdh->oh = fh;
  4214. fh->is_func = 1;
  4215. fh->oh = fdh;
  4216. }
  4217. return ppc_follow_link (fdh);
  4218. }
  4219. /* Make a fake function descriptor sym for the code sym FH. */
  4220. static struct ppc_link_hash_entry *
  4221. make_fdh (struct bfd_link_info *info,
  4222. struct ppc_link_hash_entry *fh)
  4223. {
  4224. bfd *abfd;
  4225. asymbol *newsym;
  4226. struct bfd_link_hash_entry *bh;
  4227. struct ppc_link_hash_entry *fdh;
  4228. abfd = fh->elf.root.u.undef.abfd;
  4229. newsym = bfd_make_empty_symbol (abfd);
  4230. newsym->name = fh->elf.root.root.string + 1;
  4231. newsym->section = bfd_und_section_ptr;
  4232. newsym->value = 0;
  4233. newsym->flags = BSF_WEAK;
  4234. bh = NULL;
  4235. if (!_bfd_generic_link_add_one_symbol (info, abfd, newsym->name,
  4236. newsym->flags, newsym->section,
  4237. newsym->value, NULL, FALSE, FALSE,
  4238. &bh))
  4239. return NULL;
  4240. fdh = (struct ppc_link_hash_entry *) bh;
  4241. fdh->elf.non_elf = 0;
  4242. fdh->fake = 1;
  4243. fdh->is_func_descriptor = 1;
  4244. fdh->oh = fh;
  4245. fh->is_func = 1;
  4246. fh->oh = fdh;
  4247. return fdh;
  4248. }
  4249. /* Fix function descriptor symbols defined in .opd sections to be
  4250. function type. */
  4251. static bfd_boolean
  4252. ppc64_elf_add_symbol_hook (bfd *ibfd,
  4253. struct bfd_link_info *info,
  4254. Elf_Internal_Sym *isym,
  4255. const char **name,
  4256. flagword *flags ATTRIBUTE_UNUSED,
  4257. asection **sec,
  4258. bfd_vma *value)
  4259. {
  4260. if ((ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
  4261. || ELF_ST_BIND (isym->st_info) == STB_GNU_UNIQUE)
  4262. && (ibfd->flags & DYNAMIC) == 0
  4263. && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
  4264. elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
  4265. if (*sec != NULL
  4266. && strcmp ((*sec)->name, ".opd") == 0)
  4267. {
  4268. asection *code_sec;
  4269. if (!(ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
  4270. || ELF_ST_TYPE (isym->st_info) == STT_FUNC))
  4271. isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
  4272. /* If the symbol is a function defined in .opd, and the function
  4273. code is in a discarded group, let it appear to be undefined. */
  4274. if (!bfd_link_relocatable (info)
  4275. && (*sec)->reloc_count != 0
  4276. && opd_entry_value (*sec, *value, &code_sec, NULL,
  4277. FALSE) != (bfd_vma) -1
  4278. && discarded_section (code_sec))
  4279. {
  4280. *sec = bfd_und_section_ptr;
  4281. isym->st_shndx = SHN_UNDEF;
  4282. }
  4283. }
  4284. else if (*sec != NULL
  4285. && strcmp ((*sec)->name, ".toc") == 0
  4286. && ELF_ST_TYPE (isym->st_info) == STT_OBJECT)
  4287. {
  4288. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  4289. if (htab != NULL)
  4290. htab->params->object_in_toc = 1;
  4291. }
  4292. if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)
  4293. {
  4294. if (abiversion (ibfd) == 0)
  4295. set_abiversion (ibfd, 2);
  4296. else if (abiversion (ibfd) == 1)
  4297. {
  4298. info->callbacks->einfo (_("%P: symbol '%s' has invalid st_other"
  4299. " for ABI version 1\n"), name);
  4300. bfd_set_error (bfd_error_bad_value);
  4301. return FALSE;
  4302. }
  4303. }
  4304. return TRUE;
  4305. }
  4306. /* Merge non-visibility st_other attributes: local entry point. */
  4307. static void
  4308. ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry *h,
  4309. const Elf_Internal_Sym *isym,
  4310. bfd_boolean definition,
  4311. bfd_boolean dynamic)
  4312. {
  4313. if (definition && !dynamic)
  4314. h->other = ((isym->st_other & ~ELF_ST_VISIBILITY (-1))
  4315. | ELF_ST_VISIBILITY (h->other));
  4316. }
  4317. /* This function makes an old ABI object reference to ".bar" cause the
  4318. inclusion of a new ABI object archive that defines "bar".
  4319. NAME is a symbol defined in an archive. Return a symbol in the hash
  4320. table that might be satisfied by the archive symbols. */
  4321. static struct elf_link_hash_entry *
  4322. ppc64_elf_archive_symbol_lookup (bfd *abfd,
  4323. struct bfd_link_info *info,
  4324. const char *name)
  4325. {
  4326. struct elf_link_hash_entry *h;
  4327. char *dot_name;
  4328. size_t len;
  4329. h = _bfd_elf_archive_symbol_lookup (abfd, info, name);
  4330. if (h != NULL
  4331. /* Don't return this sym if it is a fake function descriptor
  4332. created by add_symbol_adjust. */
  4333. && !(h->root.type == bfd_link_hash_undefweak
  4334. && ((struct ppc_link_hash_entry *) h)->fake))
  4335. return h;
  4336. if (name[0] == '.')
  4337. return h;
  4338. len = strlen (name);
  4339. dot_name = bfd_alloc (abfd, len + 2);
  4340. if (dot_name == NULL)
  4341. return (struct elf_link_hash_entry *) 0 - 1;
  4342. dot_name[0] = '.';
  4343. memcpy (dot_name + 1, name, len + 1);
  4344. h = _bfd_elf_archive_symbol_lookup (abfd, info, dot_name);
  4345. bfd_release (abfd, dot_name);
  4346. return h;
  4347. }
  4348. /* This function satisfies all old ABI object references to ".bar" if a
  4349. new ABI object defines "bar". Well, at least, undefined dot symbols
  4350. are made weak. This stops later archive searches from including an
  4351. object if we already have a function descriptor definition. It also
  4352. prevents the linker complaining about undefined symbols.
  4353. We also check and correct mismatched symbol visibility here. The
  4354. most restrictive visibility of the function descriptor and the
  4355. function entry symbol is used. */
  4356. static bfd_boolean
  4357. add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info)
  4358. {
  4359. struct ppc_link_hash_table *htab;
  4360. struct ppc_link_hash_entry *fdh;
  4361. if (eh->elf.root.type == bfd_link_hash_indirect)
  4362. return TRUE;
  4363. if (eh->elf.root.type == bfd_link_hash_warning)
  4364. eh = (struct ppc_link_hash_entry *) eh->elf.root.u.i.link;
  4365. if (eh->elf.root.root.string[0] != '.')
  4366. abort ();
  4367. htab = ppc_hash_table (info);
  4368. if (htab == NULL)
  4369. return FALSE;
  4370. fdh = lookup_fdh (eh, htab);
  4371. if (fdh == NULL)
  4372. {
  4373. if (!bfd_link_relocatable (info)
  4374. && (eh->elf.root.type == bfd_link_hash_undefined
  4375. || eh->elf.root.type == bfd_link_hash_undefweak)
  4376. && eh->elf.ref_regular)
  4377. {
  4378. /* Make an undefweak function descriptor sym, which is enough to
  4379. pull in an --as-needed shared lib, but won't cause link
  4380. errors. Archives are handled elsewhere. */
  4381. fdh = make_fdh (info, eh);
  4382. if (fdh == NULL)
  4383. return FALSE;
  4384. fdh->elf.ref_regular = 1;
  4385. }
  4386. }
  4387. else
  4388. {
  4389. unsigned entry_vis = ELF_ST_VISIBILITY (eh->elf.other) - 1;
  4390. unsigned descr_vis = ELF_ST_VISIBILITY (fdh->elf.other) - 1;
  4391. if (entry_vis < descr_vis)
  4392. fdh->elf.other += entry_vis - descr_vis;
  4393. else if (entry_vis > descr_vis)
  4394. eh->elf.other += descr_vis - entry_vis;
  4395. if ((fdh->elf.root.type == bfd_link_hash_defined
  4396. || fdh->elf.root.type == bfd_link_hash_defweak)
  4397. && eh->elf.root.type == bfd_link_hash_undefined)
  4398. {
  4399. eh->elf.root.type = bfd_link_hash_undefweak;
  4400. eh->was_undefined = 1;
  4401. htab->twiddled_syms = 1;
  4402. }
  4403. }
  4404. return TRUE;
  4405. }
  4406. /* Set up opd section info and abiversion for IBFD, and process list
  4407. of dot-symbols we made in link_hash_newfunc. */
  4408. static bfd_boolean
  4409. ppc64_elf_before_check_relocs (bfd *ibfd, struct bfd_link_info *info)
  4410. {
  4411. struct ppc_link_hash_table *htab;
  4412. struct ppc_link_hash_entry **p, *eh;
  4413. asection *opd = bfd_get_section_by_name (ibfd, ".opd");
  4414. if (opd != NULL && opd->size != 0)
  4415. {
  4416. if (abiversion (ibfd) == 0)
  4417. set_abiversion (ibfd, 1);
  4418. else if (abiversion (ibfd) == 2)
  4419. {
  4420. info->callbacks->einfo (_("%P: %B .opd not allowed in ABI"
  4421. " version %d\n"),
  4422. ibfd, abiversion (ibfd));
  4423. bfd_set_error (bfd_error_bad_value);
  4424. return FALSE;
  4425. }
  4426. if ((ibfd->flags & DYNAMIC) == 0
  4427. && (opd->flags & SEC_RELOC) != 0
  4428. && opd->reloc_count != 0
  4429. && !bfd_is_abs_section (opd->output_section))
  4430. {
  4431. /* Garbage collection needs some extra help with .opd sections.
  4432. We don't want to necessarily keep everything referenced by
  4433. relocs in .opd, as that would keep all functions. Instead,
  4434. if we reference an .opd symbol (a function descriptor), we
  4435. want to keep the function code symbol's section. This is
  4436. easy for global symbols, but for local syms we need to keep
  4437. information about the associated function section. */
  4438. bfd_size_type amt;
  4439. asection **opd_sym_map;
  4440. amt = OPD_NDX (opd->size) * sizeof (*opd_sym_map);
  4441. opd_sym_map = bfd_zalloc (ibfd, amt);
  4442. if (opd_sym_map == NULL)
  4443. return FALSE;
  4444. ppc64_elf_section_data (opd)->u.opd.func_sec = opd_sym_map;
  4445. BFD_ASSERT (ppc64_elf_section_data (opd)->sec_type == sec_normal);
  4446. ppc64_elf_section_data (opd)->sec_type = sec_opd;
  4447. }
  4448. }
  4449. if (!is_ppc64_elf (info->output_bfd))
  4450. return TRUE;
  4451. htab = ppc_hash_table (info);
  4452. if (htab == NULL)
  4453. return FALSE;
  4454. /* For input files without an explicit abiversion in e_flags
  4455. we should have flagged any with symbol st_other bits set
  4456. as ELFv1 and above flagged those with .opd as ELFv2.
  4457. Set the output abiversion if not yet set, and for any input
  4458. still ambiguous, take its abiversion from the output.
  4459. Differences in ABI are reported later. */
  4460. if (abiversion (info->output_bfd) == 0)
  4461. set_abiversion (info->output_bfd, abiversion (ibfd));
  4462. else if (abiversion (ibfd) == 0)
  4463. set_abiversion (ibfd, abiversion (info->output_bfd));
  4464. p = &htab->dot_syms;
  4465. while ((eh = *p) != NULL)
  4466. {
  4467. *p = NULL;
  4468. if (&eh->elf == htab->elf.hgot)
  4469. ;
  4470. else if (htab->elf.hgot == NULL
  4471. && strcmp (eh->elf.root.root.string, ".TOC.") == 0)
  4472. htab->elf.hgot = &eh->elf;
  4473. else if (!add_symbol_adjust (eh, info))
  4474. return FALSE;
  4475. p = &eh->u.next_dot_sym;
  4476. }
  4477. /* Clear the list for non-ppc64 input files. */
  4478. p = &htab->dot_syms;
  4479. while ((eh = *p) != NULL)
  4480. {
  4481. *p = NULL;
  4482. p = &eh->u.next_dot_sym;
  4483. }
  4484. /* We need to fix the undefs list for any syms we have twiddled to
  4485. undef_weak. */
  4486. if (htab->twiddled_syms)
  4487. {
  4488. bfd_link_repair_undef_list (&htab->elf.root);
  4489. htab->twiddled_syms = 0;
  4490. }
  4491. return TRUE;
  4492. }
  4493. /* Undo hash table changes when an --as-needed input file is determined
  4494. not to be needed. */
  4495. static bfd_boolean
  4496. ppc64_elf_notice_as_needed (bfd *ibfd,
  4497. struct bfd_link_info *info,
  4498. enum notice_asneeded_action act)
  4499. {
  4500. if (act == notice_not_needed)
  4501. {
  4502. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  4503. if (htab == NULL)
  4504. return FALSE;
  4505. htab->dot_syms = NULL;
  4506. }
  4507. return _bfd_elf_notice_as_needed (ibfd, info, act);
  4508. }
  4509. /* If --just-symbols against a final linked binary, then assume we need
  4510. toc adjusting stubs when calling functions defined there. */
  4511. static void
  4512. ppc64_elf_link_just_syms (asection *sec, struct bfd_link_info *info)
  4513. {
  4514. if ((sec->flags & SEC_CODE) != 0
  4515. && (sec->owner->flags & (EXEC_P | DYNAMIC)) != 0
  4516. && is_ppc64_elf (sec->owner))
  4517. {
  4518. if (abiversion (sec->owner) >= 2
  4519. || bfd_get_section_by_name (sec->owner, ".opd") != NULL)
  4520. sec->has_toc_reloc = 1;
  4521. }
  4522. _bfd_elf_link_just_syms (sec, info);
  4523. }
  4524. static struct plt_entry **
  4525. update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
  4526. unsigned long r_symndx, bfd_vma r_addend, int tls_type)
  4527. {
  4528. struct got_entry **local_got_ents = elf_local_got_ents (abfd);
  4529. struct plt_entry **local_plt;
  4530. unsigned char *local_got_tls_masks;
  4531. if (local_got_ents == NULL)
  4532. {
  4533. bfd_size_type size = symtab_hdr->sh_info;
  4534. size *= (sizeof (*local_got_ents)
  4535. + sizeof (*local_plt)
  4536. + sizeof (*local_got_tls_masks));
  4537. local_got_ents = bfd_zalloc (abfd, size);
  4538. if (local_got_ents == NULL)
  4539. return NULL;
  4540. elf_local_got_ents (abfd) = local_got_ents;
  4541. }
  4542. if ((tls_type & (PLT_IFUNC | TLS_EXPLICIT)) == 0)
  4543. {
  4544. struct got_entry *ent;
  4545. for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next)
  4546. if (ent->addend == r_addend
  4547. && ent->owner == abfd
  4548. && ent->tls_type == tls_type)
  4549. break;
  4550. if (ent == NULL)
  4551. {
  4552. bfd_size_type amt = sizeof (*ent);
  4553. ent = bfd_alloc (abfd, amt);
  4554. if (ent == NULL)
  4555. return FALSE;
  4556. ent->next = local_got_ents[r_symndx];
  4557. ent->addend = r_addend;
  4558. ent->owner = abfd;
  4559. ent->tls_type = tls_type;
  4560. ent->is_indirect = FALSE;
  4561. ent->got.refcount = 0;
  4562. local_got_ents[r_symndx] = ent;
  4563. }
  4564. ent->got.refcount += 1;
  4565. }
  4566. local_plt = (struct plt_entry **) (local_got_ents + symtab_hdr->sh_info);
  4567. local_got_tls_masks = (unsigned char *) (local_plt + symtab_hdr->sh_info);
  4568. local_got_tls_masks[r_symndx] |= tls_type;
  4569. return local_plt + r_symndx;
  4570. }
  4571. static bfd_boolean
  4572. update_plt_info (bfd *abfd, struct plt_entry **plist, bfd_vma addend)
  4573. {
  4574. struct plt_entry *ent;
  4575. for (ent = *plist; ent != NULL; ent = ent->next)
  4576. if (ent->addend == addend)
  4577. break;
  4578. if (ent == NULL)
  4579. {
  4580. bfd_size_type amt = sizeof (*ent);
  4581. ent = bfd_alloc (abfd, amt);
  4582. if (ent == NULL)
  4583. return FALSE;
  4584. ent->next = *plist;
  4585. ent->addend = addend;
  4586. ent->plt.refcount = 0;
  4587. *plist = ent;
  4588. }
  4589. ent->plt.refcount += 1;
  4590. return TRUE;
  4591. }
  4592. static bfd_boolean
  4593. is_branch_reloc (enum elf_ppc64_reloc_type r_type)
  4594. {
  4595. return (r_type == R_PPC64_REL24
  4596. || r_type == R_PPC64_REL14
  4597. || r_type == R_PPC64_REL14_BRTAKEN
  4598. || r_type == R_PPC64_REL14_BRNTAKEN
  4599. || r_type == R_PPC64_ADDR24
  4600. || r_type == R_PPC64_ADDR14
  4601. || r_type == R_PPC64_ADDR14_BRTAKEN
  4602. || r_type == R_PPC64_ADDR14_BRNTAKEN);
  4603. }
  4604. /* Look through the relocs for a section during the first phase, and
  4605. calculate needed space in the global offset table, procedure
  4606. linkage table, and dynamic reloc sections. */
  4607. static bfd_boolean
  4608. ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
  4609. asection *sec, const Elf_Internal_Rela *relocs)
  4610. {
  4611. struct ppc_link_hash_table *htab;
  4612. Elf_Internal_Shdr *symtab_hdr;
  4613. struct elf_link_hash_entry **sym_hashes;
  4614. const Elf_Internal_Rela *rel;
  4615. const Elf_Internal_Rela *rel_end;
  4616. asection *sreloc;
  4617. asection **opd_sym_map;
  4618. struct elf_link_hash_entry *tga, *dottga;
  4619. if (bfd_link_relocatable (info))
  4620. return TRUE;
  4621. /* Don't do anything special with non-loaded, non-alloced sections.
  4622. In particular, any relocs in such sections should not affect GOT
  4623. and PLT reference counting (ie. we don't allow them to create GOT
  4624. or PLT entries), there's no possibility or desire to optimize TLS
  4625. relocs, and there's not much point in propagating relocs to shared
  4626. libs that the dynamic linker won't relocate. */
  4627. if ((sec->flags & SEC_ALLOC) == 0)
  4628. return TRUE;
  4629. BFD_ASSERT (is_ppc64_elf (abfd));
  4630. htab = ppc_hash_table (info);
  4631. if (htab == NULL)
  4632. return FALSE;
  4633. tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
  4634. FALSE, FALSE, TRUE);
  4635. dottga = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
  4636. FALSE, FALSE, TRUE);
  4637. symtab_hdr = &elf_symtab_hdr (abfd);
  4638. sym_hashes = elf_sym_hashes (abfd);
  4639. sreloc = NULL;
  4640. opd_sym_map = NULL;
  4641. if (ppc64_elf_section_data (sec) != NULL
  4642. && ppc64_elf_section_data (sec)->sec_type == sec_opd)
  4643. opd_sym_map = ppc64_elf_section_data (sec)->u.opd.func_sec;
  4644. rel_end = relocs + sec->reloc_count;
  4645. for (rel = relocs; rel < rel_end; rel++)
  4646. {
  4647. unsigned long r_symndx;
  4648. struct elf_link_hash_entry *h;
  4649. enum elf_ppc64_reloc_type r_type;
  4650. int tls_type;
  4651. struct _ppc64_elf_section_data *ppc64_sec;
  4652. struct plt_entry **ifunc;
  4653. r_symndx = ELF64_R_SYM (rel->r_info);
  4654. if (r_symndx < symtab_hdr->sh_info)
  4655. h = NULL;
  4656. else
  4657. {
  4658. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  4659. h = elf_follow_link (h);
  4660. /* PR15323, ref flags aren't set for references in the same
  4661. object. */
  4662. h->root.non_ir_ref = 1;
  4663. if (h == htab->elf.hgot)
  4664. sec->has_toc_reloc = 1;
  4665. }
  4666. tls_type = 0;
  4667. ifunc = NULL;
  4668. if (h != NULL)
  4669. {
  4670. if (h->type == STT_GNU_IFUNC)
  4671. {
  4672. h->needs_plt = 1;
  4673. ifunc = &h->plt.plist;
  4674. }
  4675. }
  4676. else
  4677. {
  4678. Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  4679. abfd, r_symndx);
  4680. if (isym == NULL)
  4681. return FALSE;
  4682. if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
  4683. {
  4684. ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
  4685. rel->r_addend, PLT_IFUNC);
  4686. if (ifunc == NULL)
  4687. return FALSE;
  4688. }
  4689. }
  4690. r_type = ELF64_R_TYPE (rel->r_info);
  4691. if (is_branch_reloc (r_type))
  4692. {
  4693. if (h != NULL && (h == tga || h == dottga))
  4694. {
  4695. if (rel != relocs
  4696. && (ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSGD
  4697. || ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSLD))
  4698. /* We have a new-style __tls_get_addr call with a marker
  4699. reloc. */
  4700. ;
  4701. else
  4702. /* Mark this section as having an old-style call. */
  4703. sec->has_tls_get_addr_call = 1;
  4704. }
  4705. /* STT_GNU_IFUNC symbols must have a PLT entry. */
  4706. if (ifunc != NULL
  4707. && !update_plt_info (abfd, ifunc, rel->r_addend))
  4708. return FALSE;
  4709. }
  4710. switch (r_type)
  4711. {
  4712. case R_PPC64_TLSGD:
  4713. case R_PPC64_TLSLD:
  4714. /* These special tls relocs tie a call to __tls_get_addr with
  4715. its parameter symbol. */
  4716. break;
  4717. case R_PPC64_GOT_TLSLD16:
  4718. case R_PPC64_GOT_TLSLD16_LO:
  4719. case R_PPC64_GOT_TLSLD16_HI:
  4720. case R_PPC64_GOT_TLSLD16_HA:
  4721. tls_type = TLS_TLS | TLS_LD;
  4722. goto dogottls;
  4723. case R_PPC64_GOT_TLSGD16:
  4724. case R_PPC64_GOT_TLSGD16_LO:
  4725. case R_PPC64_GOT_TLSGD16_HI:
  4726. case R_PPC64_GOT_TLSGD16_HA:
  4727. tls_type = TLS_TLS | TLS_GD;
  4728. goto dogottls;
  4729. case R_PPC64_GOT_TPREL16_DS:
  4730. case R_PPC64_GOT_TPREL16_LO_DS:
  4731. case R_PPC64_GOT_TPREL16_HI:
  4732. case R_PPC64_GOT_TPREL16_HA:
  4733. if (bfd_link_pic (info))
  4734. info->flags |= DF_STATIC_TLS;
  4735. tls_type = TLS_TLS | TLS_TPREL;
  4736. goto dogottls;
  4737. case R_PPC64_GOT_DTPREL16_DS:
  4738. case R_PPC64_GOT_DTPREL16_LO_DS:
  4739. case R_PPC64_GOT_DTPREL16_HI:
  4740. case R_PPC64_GOT_DTPREL16_HA:
  4741. tls_type = TLS_TLS | TLS_DTPREL;
  4742. dogottls:
  4743. sec->has_tls_reloc = 1;
  4744. /* Fall thru */
  4745. case R_PPC64_GOT16:
  4746. case R_PPC64_GOT16_DS:
  4747. case R_PPC64_GOT16_HA:
  4748. case R_PPC64_GOT16_HI:
  4749. case R_PPC64_GOT16_LO:
  4750. case R_PPC64_GOT16_LO_DS:
  4751. /* This symbol requires a global offset table entry. */
  4752. sec->has_toc_reloc = 1;
  4753. if (r_type == R_PPC64_GOT_TLSLD16
  4754. || r_type == R_PPC64_GOT_TLSGD16
  4755. || r_type == R_PPC64_GOT_TPREL16_DS
  4756. || r_type == R_PPC64_GOT_DTPREL16_DS
  4757. || r_type == R_PPC64_GOT16
  4758. || r_type == R_PPC64_GOT16_DS)
  4759. {
  4760. htab->do_multi_toc = 1;
  4761. ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1;
  4762. }
  4763. if (ppc64_elf_tdata (abfd)->got == NULL
  4764. && !create_got_section (abfd, info))
  4765. return FALSE;
  4766. if (h != NULL)
  4767. {
  4768. struct ppc_link_hash_entry *eh;
  4769. struct got_entry *ent;
  4770. eh = (struct ppc_link_hash_entry *) h;
  4771. for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next)
  4772. if (ent->addend == rel->r_addend
  4773. && ent->owner == abfd
  4774. && ent->tls_type == tls_type)
  4775. break;
  4776. if (ent == NULL)
  4777. {
  4778. bfd_size_type amt = sizeof (*ent);
  4779. ent = bfd_alloc (abfd, amt);
  4780. if (ent == NULL)
  4781. return FALSE;
  4782. ent->next = eh->elf.got.glist;
  4783. ent->addend = rel->r_addend;
  4784. ent->owner = abfd;
  4785. ent->tls_type = tls_type;
  4786. ent->is_indirect = FALSE;
  4787. ent->got.refcount = 0;
  4788. eh->elf.got.glist = ent;
  4789. }
  4790. ent->got.refcount += 1;
  4791. eh->tls_mask |= tls_type;
  4792. }
  4793. else
  4794. /* This is a global offset table entry for a local symbol. */
  4795. if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
  4796. rel->r_addend, tls_type))
  4797. return FALSE;
  4798. /* We may also need a plt entry if the symbol turns out to be
  4799. an ifunc. */
  4800. if (h != NULL && !bfd_link_pic (info) && abiversion (abfd) != 1)
  4801. {
  4802. if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
  4803. return FALSE;
  4804. }
  4805. break;
  4806. case R_PPC64_PLT16_HA:
  4807. case R_PPC64_PLT16_HI:
  4808. case R_PPC64_PLT16_LO:
  4809. case R_PPC64_PLT32:
  4810. case R_PPC64_PLT64:
  4811. /* This symbol requires a procedure linkage table entry. We
  4812. actually build the entry in adjust_dynamic_symbol,
  4813. because this might be a case of linking PIC code without
  4814. linking in any dynamic objects, in which case we don't
  4815. need to generate a procedure linkage table after all. */
  4816. if (h == NULL)
  4817. {
  4818. /* It does not make sense to have a procedure linkage
  4819. table entry for a local symbol. */
  4820. bfd_set_error (bfd_error_bad_value);
  4821. return FALSE;
  4822. }
  4823. else
  4824. {
  4825. if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
  4826. return FALSE;
  4827. h->needs_plt = 1;
  4828. if (h->root.root.string[0] == '.'
  4829. && h->root.root.string[1] != '\0')
  4830. ((struct ppc_link_hash_entry *) h)->is_func = 1;
  4831. }
  4832. break;
  4833. /* The following relocations don't need to propagate the
  4834. relocation if linking a shared object since they are
  4835. section relative. */
  4836. case R_PPC64_SECTOFF:
  4837. case R_PPC64_SECTOFF_LO:
  4838. case R_PPC64_SECTOFF_HI:
  4839. case R_PPC64_SECTOFF_HA:
  4840. case R_PPC64_SECTOFF_DS:
  4841. case R_PPC64_SECTOFF_LO_DS:
  4842. case R_PPC64_DTPREL16:
  4843. case R_PPC64_DTPREL16_LO:
  4844. case R_PPC64_DTPREL16_HI:
  4845. case R_PPC64_DTPREL16_HA:
  4846. case R_PPC64_DTPREL16_DS:
  4847. case R_PPC64_DTPREL16_LO_DS:
  4848. case R_PPC64_DTPREL16_HIGH:
  4849. case R_PPC64_DTPREL16_HIGHA:
  4850. case R_PPC64_DTPREL16_HIGHER:
  4851. case R_PPC64_DTPREL16_HIGHERA:
  4852. case R_PPC64_DTPREL16_HIGHEST:
  4853. case R_PPC64_DTPREL16_HIGHESTA:
  4854. break;
  4855. /* Nor do these. */
  4856. case R_PPC64_REL16:
  4857. case R_PPC64_REL16_LO:
  4858. case R_PPC64_REL16_HI:
  4859. case R_PPC64_REL16_HA:
  4860. break;
  4861. /* Not supported as a dynamic relocation. */
  4862. case R_PPC64_ADDR64_LOCAL:
  4863. if (bfd_link_pic (info))
  4864. {
  4865. if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
  4866. ppc_howto_init ();
  4867. info->callbacks->einfo (_("%P: %H: %s reloc unsupported "
  4868. "in shared libraries and PIEs.\n"),
  4869. abfd, sec, rel->r_offset,
  4870. ppc64_elf_howto_table[r_type]->name);
  4871. bfd_set_error (bfd_error_bad_value);
  4872. return FALSE;
  4873. }
  4874. break;
  4875. case R_PPC64_TOC16:
  4876. case R_PPC64_TOC16_DS:
  4877. htab->do_multi_toc = 1;
  4878. ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1;
  4879. case R_PPC64_TOC16_LO:
  4880. case R_PPC64_TOC16_HI:
  4881. case R_PPC64_TOC16_HA:
  4882. case R_PPC64_TOC16_LO_DS:
  4883. sec->has_toc_reloc = 1;
  4884. break;
  4885. /* This relocation describes the C++ object vtable hierarchy.
  4886. Reconstruct it for later use during GC. */
  4887. case R_PPC64_GNU_VTINHERIT:
  4888. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  4889. return FALSE;
  4890. break;
  4891. /* This relocation describes which C++ vtable entries are actually
  4892. used. Record for later use during GC. */
  4893. case R_PPC64_GNU_VTENTRY:
  4894. BFD_ASSERT (h != NULL);
  4895. if (h != NULL
  4896. && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  4897. return FALSE;
  4898. break;
  4899. case R_PPC64_REL14:
  4900. case R_PPC64_REL14_BRTAKEN:
  4901. case R_PPC64_REL14_BRNTAKEN:
  4902. {
  4903. asection *dest = NULL;
  4904. /* Heuristic: If jumping outside our section, chances are
  4905. we are going to need a stub. */
  4906. if (h != NULL)
  4907. {
  4908. /* If the sym is weak it may be overridden later, so
  4909. don't assume we know where a weak sym lives. */
  4910. if (h->root.type == bfd_link_hash_defined)
  4911. dest = h->root.u.def.section;
  4912. }
  4913. else
  4914. {
  4915. Elf_Internal_Sym *isym;
  4916. isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  4917. abfd, r_symndx);
  4918. if (isym == NULL)
  4919. return FALSE;
  4920. dest = bfd_section_from_elf_index (abfd, isym->st_shndx);
  4921. }
  4922. if (dest != sec)
  4923. ppc64_elf_section_data (sec)->has_14bit_branch = 1;
  4924. }
  4925. /* Fall through. */
  4926. case R_PPC64_REL24:
  4927. if (h != NULL && ifunc == NULL)
  4928. {
  4929. /* We may need a .plt entry if the function this reloc
  4930. refers to is in a shared lib. */
  4931. if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
  4932. return FALSE;
  4933. h->needs_plt = 1;
  4934. if (h->root.root.string[0] == '.'
  4935. && h->root.root.string[1] != '\0')
  4936. ((struct ppc_link_hash_entry *) h)->is_func = 1;
  4937. if (h == tga || h == dottga)
  4938. sec->has_tls_reloc = 1;
  4939. }
  4940. break;
  4941. case R_PPC64_TPREL64:
  4942. tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL;
  4943. if (bfd_link_pic (info))
  4944. info->flags |= DF_STATIC_TLS;
  4945. goto dotlstoc;
  4946. case R_PPC64_DTPMOD64:
  4947. if (rel + 1 < rel_end
  4948. && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
  4949. && rel[1].r_offset == rel->r_offset + 8)
  4950. tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD;
  4951. else
  4952. tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD;
  4953. goto dotlstoc;
  4954. case R_PPC64_DTPREL64:
  4955. tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL;
  4956. if (rel != relocs
  4957. && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64)
  4958. && rel[-1].r_offset == rel->r_offset - 8)
  4959. /* This is the second reloc of a dtpmod, dtprel pair.
  4960. Don't mark with TLS_DTPREL. */
  4961. goto dodyn;
  4962. dotlstoc:
  4963. sec->has_tls_reloc = 1;
  4964. if (h != NULL)
  4965. {
  4966. struct ppc_link_hash_entry *eh;
  4967. eh = (struct ppc_link_hash_entry *) h;
  4968. eh->tls_mask |= tls_type;
  4969. }
  4970. else
  4971. if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
  4972. rel->r_addend, tls_type))
  4973. return FALSE;
  4974. ppc64_sec = ppc64_elf_section_data (sec);
  4975. if (ppc64_sec->sec_type != sec_toc)
  4976. {
  4977. bfd_size_type amt;
  4978. /* One extra to simplify get_tls_mask. */
  4979. amt = sec->size * sizeof (unsigned) / 8 + sizeof (unsigned);
  4980. ppc64_sec->u.toc.symndx = bfd_zalloc (abfd, amt);
  4981. if (ppc64_sec->u.toc.symndx == NULL)
  4982. return FALSE;
  4983. amt = sec->size * sizeof (bfd_vma) / 8;
  4984. ppc64_sec->u.toc.add = bfd_zalloc (abfd, amt);
  4985. if (ppc64_sec->u.toc.add == NULL)
  4986. return FALSE;
  4987. BFD_ASSERT (ppc64_sec->sec_type == sec_normal);
  4988. ppc64_sec->sec_type = sec_toc;
  4989. }
  4990. BFD_ASSERT (rel->r_offset % 8 == 0);
  4991. ppc64_sec->u.toc.symndx[rel->r_offset / 8] = r_symndx;
  4992. ppc64_sec->u.toc.add[rel->r_offset / 8] = rel->r_addend;
  4993. /* Mark the second slot of a GD or LD entry.
  4994. -1 to indicate GD and -2 to indicate LD. */
  4995. if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD))
  4996. ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -1;
  4997. else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD))
  4998. ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -2;
  4999. goto dodyn;
  5000. case R_PPC64_TPREL16:
  5001. case R_PPC64_TPREL16_LO:
  5002. case R_PPC64_TPREL16_HI:
  5003. case R_PPC64_TPREL16_HA:
  5004. case R_PPC64_TPREL16_DS:
  5005. case R_PPC64_TPREL16_LO_DS:
  5006. case R_PPC64_TPREL16_HIGH:
  5007. case R_PPC64_TPREL16_HIGHA:
  5008. case R_PPC64_TPREL16_HIGHER:
  5009. case R_PPC64_TPREL16_HIGHERA:
  5010. case R_PPC64_TPREL16_HIGHEST:
  5011. case R_PPC64_TPREL16_HIGHESTA:
  5012. if (bfd_link_pic (info))
  5013. {
  5014. info->flags |= DF_STATIC_TLS;
  5015. goto dodyn;
  5016. }
  5017. break;
  5018. case R_PPC64_ADDR64:
  5019. if (opd_sym_map != NULL
  5020. && rel + 1 < rel_end
  5021. && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC)
  5022. {
  5023. if (h != NULL)
  5024. {
  5025. if (h->root.root.string[0] == '.'
  5026. && h->root.root.string[1] != 0
  5027. && lookup_fdh ((struct ppc_link_hash_entry *) h, htab))
  5028. ;
  5029. else
  5030. ((struct ppc_link_hash_entry *) h)->is_func = 1;
  5031. }
  5032. else
  5033. {
  5034. asection *s;
  5035. Elf_Internal_Sym *isym;
  5036. isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  5037. abfd, r_symndx);
  5038. if (isym == NULL)
  5039. return FALSE;
  5040. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  5041. if (s != NULL && s != sec)
  5042. opd_sym_map[OPD_NDX (rel->r_offset)] = s;
  5043. }
  5044. }
  5045. /* Fall through. */
  5046. case R_PPC64_ADDR16:
  5047. case R_PPC64_ADDR16_DS:
  5048. case R_PPC64_ADDR16_HA:
  5049. case R_PPC64_ADDR16_HI:
  5050. case R_PPC64_ADDR16_HIGH:
  5051. case R_PPC64_ADDR16_HIGHA:
  5052. case R_PPC64_ADDR16_HIGHER:
  5053. case R_PPC64_ADDR16_HIGHERA:
  5054. case R_PPC64_ADDR16_HIGHEST:
  5055. case R_PPC64_ADDR16_HIGHESTA:
  5056. case R_PPC64_ADDR16_LO:
  5057. case R_PPC64_ADDR16_LO_DS:
  5058. if (h != NULL && !bfd_link_pic (info) && abiversion (abfd) != 1
  5059. && rel->r_addend == 0)
  5060. {
  5061. /* We may need a .plt entry if this reloc refers to a
  5062. function in a shared lib. */
  5063. if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
  5064. return FALSE;
  5065. h->pointer_equality_needed = 1;
  5066. }
  5067. /* Fall through. */
  5068. case R_PPC64_REL30:
  5069. case R_PPC64_REL32:
  5070. case R_PPC64_REL64:
  5071. case R_PPC64_ADDR14:
  5072. case R_PPC64_ADDR14_BRNTAKEN:
  5073. case R_PPC64_ADDR14_BRTAKEN:
  5074. case R_PPC64_ADDR24:
  5075. case R_PPC64_ADDR32:
  5076. case R_PPC64_UADDR16:
  5077. case R_PPC64_UADDR32:
  5078. case R_PPC64_UADDR64:
  5079. case R_PPC64_TOC:
  5080. if (h != NULL && !bfd_link_pic (info))
  5081. /* We may need a copy reloc. */
  5082. h->non_got_ref = 1;
  5083. /* Don't propagate .opd relocs. */
  5084. if (NO_OPD_RELOCS && opd_sym_map != NULL)
  5085. break;
  5086. /* If we are creating a shared library, and this is a reloc
  5087. against a global symbol, or a non PC relative reloc
  5088. against a local symbol, then we need to copy the reloc
  5089. into the shared library. However, if we are linking with
  5090. -Bsymbolic, we do not need to copy a reloc against a
  5091. global symbol which is defined in an object we are
  5092. including in the link (i.e., DEF_REGULAR is set). At
  5093. this point we have not seen all the input files, so it is
  5094. possible that DEF_REGULAR is not set now but will be set
  5095. later (it is never cleared). In case of a weak definition,
  5096. DEF_REGULAR may be cleared later by a strong definition in
  5097. a shared library. We account for that possibility below by
  5098. storing information in the dyn_relocs field of the hash
  5099. table entry. A similar situation occurs when creating
  5100. shared libraries and symbol visibility changes render the
  5101. symbol local.
  5102. If on the other hand, we are creating an executable, we
  5103. may need to keep relocations for symbols satisfied by a
  5104. dynamic library if we manage to avoid copy relocs for the
  5105. symbol. */
  5106. dodyn:
  5107. if ((bfd_link_pic (info)
  5108. && (must_be_dyn_reloc (info, r_type)
  5109. || (h != NULL
  5110. && (!SYMBOLIC_BIND (info, h)
  5111. || h->root.type == bfd_link_hash_defweak
  5112. || !h->def_regular))))
  5113. || (ELIMINATE_COPY_RELOCS
  5114. && !bfd_link_pic (info)
  5115. && h != NULL
  5116. && (h->root.type == bfd_link_hash_defweak
  5117. || !h->def_regular))
  5118. || (!bfd_link_pic (info)
  5119. && ifunc != NULL))
  5120. {
  5121. /* We must copy these reloc types into the output file.
  5122. Create a reloc section in dynobj and make room for
  5123. this reloc. */
  5124. if (sreloc == NULL)
  5125. {
  5126. sreloc = _bfd_elf_make_dynamic_reloc_section
  5127. (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
  5128. if (sreloc == NULL)
  5129. return FALSE;
  5130. }
  5131. /* If this is a global symbol, we count the number of
  5132. relocations we need for this symbol. */
  5133. if (h != NULL)
  5134. {
  5135. struct elf_dyn_relocs *p;
  5136. struct elf_dyn_relocs **head;
  5137. head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
  5138. p = *head;
  5139. if (p == NULL || p->sec != sec)
  5140. {
  5141. p = bfd_alloc (htab->elf.dynobj, sizeof *p);
  5142. if (p == NULL)
  5143. return FALSE;
  5144. p->next = *head;
  5145. *head = p;
  5146. p->sec = sec;
  5147. p->count = 0;
  5148. p->pc_count = 0;
  5149. }
  5150. p->count += 1;
  5151. if (!must_be_dyn_reloc (info, r_type))
  5152. p->pc_count += 1;
  5153. }
  5154. else
  5155. {
  5156. /* Track dynamic relocs needed for local syms too.
  5157. We really need local syms available to do this
  5158. easily. Oh well. */
  5159. struct ppc_dyn_relocs *p;
  5160. struct ppc_dyn_relocs **head;
  5161. bfd_boolean is_ifunc;
  5162. asection *s;
  5163. void *vpp;
  5164. Elf_Internal_Sym *isym;
  5165. isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  5166. abfd, r_symndx);
  5167. if (isym == NULL)
  5168. return FALSE;
  5169. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  5170. if (s == NULL)
  5171. s = sec;
  5172. vpp = &elf_section_data (s)->local_dynrel;
  5173. head = (struct ppc_dyn_relocs **) vpp;
  5174. is_ifunc = ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC;
  5175. p = *head;
  5176. if (p != NULL && p->sec == sec && p->ifunc != is_ifunc)
  5177. p = p->next;
  5178. if (p == NULL || p->sec != sec || p->ifunc != is_ifunc)
  5179. {
  5180. p = bfd_alloc (htab->elf.dynobj, sizeof *p);
  5181. if (p == NULL)
  5182. return FALSE;
  5183. p->next = *head;
  5184. *head = p;
  5185. p->sec = sec;
  5186. p->ifunc = is_ifunc;
  5187. p->count = 0;
  5188. }
  5189. p->count += 1;
  5190. }
  5191. }
  5192. break;
  5193. default:
  5194. break;
  5195. }
  5196. }
  5197. return TRUE;
  5198. }
  5199. /* Merge backend specific data from an object file to the output
  5200. object file when linking. */
  5201. static bfd_boolean
  5202. ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
  5203. {
  5204. unsigned long iflags, oflags;
  5205. if ((ibfd->flags & BFD_LINKER_CREATED) != 0)
  5206. return TRUE;
  5207. if (!is_ppc64_elf (ibfd) || !is_ppc64_elf (obfd))
  5208. return TRUE;
  5209. if (!_bfd_generic_verify_endian_match (ibfd, obfd))
  5210. return FALSE;
  5211. iflags = elf_elfheader (ibfd)->e_flags;
  5212. oflags = elf_elfheader (obfd)->e_flags;
  5213. if (iflags & ~EF_PPC64_ABI)
  5214. {
  5215. (*_bfd_error_handler)
  5216. (_("%B uses unknown e_flags 0x%lx"), ibfd, iflags);
  5217. bfd_set_error (bfd_error_bad_value);
  5218. return FALSE;
  5219. }
  5220. else if (iflags != oflags && iflags != 0)
  5221. {
  5222. (*_bfd_error_handler)
  5223. (_("%B: ABI version %ld is not compatible with ABI version %ld output"),
  5224. ibfd, iflags, oflags);
  5225. bfd_set_error (bfd_error_bad_value);
  5226. return FALSE;
  5227. }
  5228. /* Merge Tag_compatibility attributes and any common GNU ones. */
  5229. _bfd_elf_merge_object_attributes (ibfd, obfd);
  5230. return TRUE;
  5231. }
  5232. static bfd_boolean
  5233. ppc64_elf_print_private_bfd_data (bfd *abfd, void *ptr)
  5234. {
  5235. /* Print normal ELF private data. */
  5236. _bfd_elf_print_private_bfd_data (abfd, ptr);
  5237. if (elf_elfheader (abfd)->e_flags != 0)
  5238. {
  5239. FILE *file = ptr;
  5240. /* xgettext:c-format */
  5241. fprintf (file, _("private flags = 0x%lx:"),
  5242. elf_elfheader (abfd)->e_flags);
  5243. if ((elf_elfheader (abfd)->e_flags & EF_PPC64_ABI) != 0)
  5244. fprintf (file, _(" [abiv%ld]"),
  5245. elf_elfheader (abfd)->e_flags & EF_PPC64_ABI);
  5246. fputc ('\n', file);
  5247. }
  5248. return TRUE;
  5249. }
  5250. /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
  5251. of the code entry point, and its section, which must be in the same
  5252. object as OPD_SEC. Returns (bfd_vma) -1 on error. */
  5253. static bfd_vma
  5254. opd_entry_value (asection *opd_sec,
  5255. bfd_vma offset,
  5256. asection **code_sec,
  5257. bfd_vma *code_off,
  5258. bfd_boolean in_code_sec)
  5259. {
  5260. bfd *opd_bfd = opd_sec->owner;
  5261. Elf_Internal_Rela *relocs;
  5262. Elf_Internal_Rela *lo, *hi, *look;
  5263. bfd_vma val;
  5264. /* No relocs implies we are linking a --just-symbols object, or looking
  5265. at a final linked executable with addr2line or somesuch. */
  5266. if (opd_sec->reloc_count == 0)
  5267. {
  5268. bfd_byte *contents = ppc64_elf_tdata (opd_bfd)->opd.contents;
  5269. if (contents == NULL)
  5270. {
  5271. if (!bfd_malloc_and_get_section (opd_bfd, opd_sec, &contents))
  5272. return (bfd_vma) -1;
  5273. ppc64_elf_tdata (opd_bfd)->opd.contents = contents;
  5274. }
  5275. /* PR 17512: file: 64b9dfbb. */
  5276. if (offset + 7 >= opd_sec->size || offset + 7 < offset)
  5277. return (bfd_vma) -1;
  5278. val = bfd_get_64 (opd_bfd, contents + offset);
  5279. if (code_sec != NULL)
  5280. {
  5281. asection *sec, *likely = NULL;
  5282. if (in_code_sec)
  5283. {
  5284. sec = *code_sec;
  5285. if (sec->vma <= val
  5286. && val < sec->vma + sec->size)
  5287. likely = sec;
  5288. else
  5289. val = -1;
  5290. }
  5291. else
  5292. for (sec = opd_bfd->sections; sec != NULL; sec = sec->next)
  5293. if (sec->vma <= val
  5294. && (sec->flags & SEC_LOAD) != 0
  5295. && (sec->flags & SEC_ALLOC) != 0)
  5296. likely = sec;
  5297. if (likely != NULL)
  5298. {
  5299. *code_sec = likely;
  5300. if (code_off != NULL)
  5301. *code_off = val - likely->vma;
  5302. }
  5303. }
  5304. return val;
  5305. }
  5306. BFD_ASSERT (is_ppc64_elf (opd_bfd));
  5307. relocs = ppc64_elf_tdata (opd_bfd)->opd.relocs;
  5308. if (relocs == NULL)
  5309. relocs = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, TRUE);
  5310. /* PR 17512: file: df8e1fd6. */
  5311. if (relocs == NULL)
  5312. return (bfd_vma) -1;
  5313. /* Go find the opd reloc at the sym address. */
  5314. lo = relocs;
  5315. hi = lo + opd_sec->reloc_count - 1; /* ignore last reloc */
  5316. val = (bfd_vma) -1;
  5317. while (lo < hi)
  5318. {
  5319. look = lo + (hi - lo) / 2;
  5320. if (look->r_offset < offset)
  5321. lo = look + 1;
  5322. else if (look->r_offset > offset)
  5323. hi = look;
  5324. else
  5325. {
  5326. Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (opd_bfd);
  5327. if (ELF64_R_TYPE (look->r_info) == R_PPC64_ADDR64
  5328. && ELF64_R_TYPE ((look + 1)->r_info) == R_PPC64_TOC)
  5329. {
  5330. unsigned long symndx = ELF64_R_SYM (look->r_info);
  5331. asection *sec = NULL;
  5332. if (symndx >= symtab_hdr->sh_info
  5333. && elf_sym_hashes (opd_bfd) != NULL)
  5334. {
  5335. struct elf_link_hash_entry **sym_hashes;
  5336. struct elf_link_hash_entry *rh;
  5337. sym_hashes = elf_sym_hashes (opd_bfd);
  5338. rh = sym_hashes[symndx - symtab_hdr->sh_info];
  5339. if (rh != NULL)
  5340. {
  5341. rh = elf_follow_link (rh);
  5342. if (rh->root.type != bfd_link_hash_defined
  5343. && rh->root.type != bfd_link_hash_defweak)
  5344. break;
  5345. if (rh->root.u.def.section->owner == opd_bfd)
  5346. {
  5347. val = rh->root.u.def.value;
  5348. sec = rh->root.u.def.section;
  5349. }
  5350. }
  5351. }
  5352. if (sec == NULL)
  5353. {
  5354. Elf_Internal_Sym *sym;
  5355. if (symndx < symtab_hdr->sh_info)
  5356. {
  5357. sym = (Elf_Internal_Sym *) symtab_hdr->contents;
  5358. if (sym == NULL)
  5359. {
  5360. size_t symcnt = symtab_hdr->sh_info;
  5361. sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
  5362. symcnt, 0,
  5363. NULL, NULL, NULL);
  5364. if (sym == NULL)
  5365. break;
  5366. symtab_hdr->contents = (bfd_byte *) sym;
  5367. }
  5368. sym += symndx;
  5369. }
  5370. else
  5371. {
  5372. sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
  5373. 1, symndx,
  5374. NULL, NULL, NULL);
  5375. if (sym == NULL)
  5376. break;
  5377. }
  5378. sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
  5379. if (sec == NULL)
  5380. break;
  5381. BFD_ASSERT ((sec->flags & SEC_MERGE) == 0);
  5382. val = sym->st_value;
  5383. }
  5384. val += look->r_addend;
  5385. if (code_off != NULL)
  5386. *code_off = val;
  5387. if (code_sec != NULL)
  5388. {
  5389. if (in_code_sec && *code_sec != sec)
  5390. return -1;
  5391. else
  5392. *code_sec = sec;
  5393. }
  5394. if (sec->output_section != NULL)
  5395. val += sec->output_section->vma + sec->output_offset;
  5396. }
  5397. break;
  5398. }
  5399. }
  5400. return val;
  5401. }
  5402. /* If the ELF symbol SYM might be a function in SEC, return the
  5403. function size and set *CODE_OFF to the function's entry point,
  5404. otherwise return zero. */
  5405. static bfd_size_type
  5406. ppc64_elf_maybe_function_sym (const asymbol *sym, asection *sec,
  5407. bfd_vma *code_off)
  5408. {
  5409. bfd_size_type size;
  5410. if ((sym->flags & (BSF_SECTION_SYM | BSF_FILE | BSF_OBJECT
  5411. | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC)) != 0)
  5412. return 0;
  5413. size = 0;
  5414. if (!(sym->flags & BSF_SYNTHETIC))
  5415. size = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
  5416. if (strcmp (sym->section->name, ".opd") == 0)
  5417. {
  5418. struct _opd_sec_data *opd = get_opd_info (sym->section);
  5419. bfd_vma symval = sym->value;
  5420. if (opd != NULL
  5421. && opd->adjust != NULL
  5422. && elf_section_data (sym->section)->relocs != NULL)
  5423. {
  5424. /* opd_entry_value will use cached relocs that have been
  5425. adjusted, but with raw symbols. That means both local
  5426. and global symbols need adjusting. */
  5427. long adjust = opd->adjust[OPD_NDX (symval)];
  5428. if (adjust == -1)
  5429. return 0;
  5430. symval += adjust;
  5431. }
  5432. if (opd_entry_value (sym->section, symval,
  5433. &sec, code_off, TRUE) == (bfd_vma) -1)
  5434. return 0;
  5435. /* An old ABI binary with dot-syms has a size of 24 on the .opd
  5436. symbol. This size has nothing to do with the code size of the
  5437. function, which is what we're supposed to return, but the
  5438. code size isn't available without looking up the dot-sym.
  5439. However, doing that would be a waste of time particularly
  5440. since elf_find_function will look at the dot-sym anyway.
  5441. Now, elf_find_function will keep the largest size of any
  5442. function sym found at the code address of interest, so return
  5443. 1 here to avoid it incorrectly caching a larger function size
  5444. for a small function. This does mean we return the wrong
  5445. size for a new-ABI function of size 24, but all that does is
  5446. disable caching for such functions. */
  5447. if (size == 24)
  5448. size = 1;
  5449. }
  5450. else
  5451. {
  5452. if (sym->section != sec)
  5453. return 0;
  5454. *code_off = sym->value;
  5455. }
  5456. if (size == 0)
  5457. size = 1;
  5458. return size;
  5459. }
  5460. /* Return true if symbol is defined in a regular object file. */
  5461. static bfd_boolean
  5462. is_static_defined (struct elf_link_hash_entry *h)
  5463. {
  5464. return ((h->root.type == bfd_link_hash_defined
  5465. || h->root.type == bfd_link_hash_defweak)
  5466. && h->root.u.def.section != NULL
  5467. && h->root.u.def.section->output_section != NULL);
  5468. }
  5469. /* If FDH is a function descriptor symbol, return the associated code
  5470. entry symbol if it is defined. Return NULL otherwise. */
  5471. static struct ppc_link_hash_entry *
  5472. defined_code_entry (struct ppc_link_hash_entry *fdh)
  5473. {
  5474. if (fdh->is_func_descriptor)
  5475. {
  5476. struct ppc_link_hash_entry *fh = ppc_follow_link (fdh->oh);
  5477. if (fh->elf.root.type == bfd_link_hash_defined
  5478. || fh->elf.root.type == bfd_link_hash_defweak)
  5479. return fh;
  5480. }
  5481. return NULL;
  5482. }
  5483. /* If FH is a function code entry symbol, return the associated
  5484. function descriptor symbol if it is defined. Return NULL otherwise. */
  5485. static struct ppc_link_hash_entry *
  5486. defined_func_desc (struct ppc_link_hash_entry *fh)
  5487. {
  5488. if (fh->oh != NULL
  5489. && fh->oh->is_func_descriptor)
  5490. {
  5491. struct ppc_link_hash_entry *fdh = ppc_follow_link (fh->oh);
  5492. if (fdh->elf.root.type == bfd_link_hash_defined
  5493. || fdh->elf.root.type == bfd_link_hash_defweak)
  5494. return fdh;
  5495. }
  5496. return NULL;
  5497. }
  5498. /* Mark all our entry sym sections, both opd and code section. */
  5499. static void
  5500. ppc64_elf_gc_keep (struct bfd_link_info *info)
  5501. {
  5502. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  5503. struct bfd_sym_chain *sym;
  5504. if (htab == NULL)
  5505. return;
  5506. for (sym = info->gc_sym_list; sym != NULL; sym = sym->next)
  5507. {
  5508. struct ppc_link_hash_entry *eh, *fh;
  5509. asection *sec;
  5510. eh = (struct ppc_link_hash_entry *)
  5511. elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, TRUE);
  5512. if (eh == NULL)
  5513. continue;
  5514. if (eh->elf.root.type != bfd_link_hash_defined
  5515. && eh->elf.root.type != bfd_link_hash_defweak)
  5516. continue;
  5517. fh = defined_code_entry (eh);
  5518. if (fh != NULL)
  5519. {
  5520. sec = fh->elf.root.u.def.section;
  5521. sec->flags |= SEC_KEEP;
  5522. }
  5523. else if (get_opd_info (eh->elf.root.u.def.section) != NULL
  5524. && opd_entry_value (eh->elf.root.u.def.section,
  5525. eh->elf.root.u.def.value,
  5526. &sec, NULL, FALSE) != (bfd_vma) -1)
  5527. sec->flags |= SEC_KEEP;
  5528. sec = eh->elf.root.u.def.section;
  5529. sec->flags |= SEC_KEEP;
  5530. }
  5531. }
  5532. /* Mark sections containing dynamically referenced symbols. When
  5533. building shared libraries, we must assume that any visible symbol is
  5534. referenced. */
  5535. static bfd_boolean
  5536. ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry *h, void *inf)
  5537. {
  5538. struct bfd_link_info *info = (struct bfd_link_info *) inf;
  5539. struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
  5540. struct ppc_link_hash_entry *fdh;
  5541. struct bfd_elf_dynamic_list *d = info->dynamic_list;
  5542. /* Dynamic linking info is on the func descriptor sym. */
  5543. fdh = defined_func_desc (eh);
  5544. if (fdh != NULL)
  5545. eh = fdh;
  5546. if ((eh->elf.root.type == bfd_link_hash_defined
  5547. || eh->elf.root.type == bfd_link_hash_defweak)
  5548. && (eh->elf.ref_dynamic
  5549. || ((eh->elf.def_regular || ELF_COMMON_DEF_P (&eh->elf))
  5550. && ELF_ST_VISIBILITY (eh->elf.other) != STV_INTERNAL
  5551. && ELF_ST_VISIBILITY (eh->elf.other) != STV_HIDDEN
  5552. && (!bfd_link_executable (info)
  5553. || info->export_dynamic
  5554. || (eh->elf.dynamic
  5555. && d != NULL
  5556. && (*d->match) (&d->head, NULL, eh->elf.root.root.string)))
  5557. && (strchr (eh->elf.root.root.string, ELF_VER_CHR) != NULL
  5558. || !bfd_hide_sym_by_version (info->version_info,
  5559. eh->elf.root.root.string)))))
  5560. {
  5561. asection *code_sec;
  5562. struct ppc_link_hash_entry *fh;
  5563. eh->elf.root.u.def.section->flags |= SEC_KEEP;
  5564. /* Function descriptor syms cause the associated
  5565. function code sym section to be marked. */
  5566. fh = defined_code_entry (eh);
  5567. if (fh != NULL)
  5568. {
  5569. code_sec = fh->elf.root.u.def.section;
  5570. code_sec->flags |= SEC_KEEP;
  5571. }
  5572. else if (get_opd_info (eh->elf.root.u.def.section) != NULL
  5573. && opd_entry_value (eh->elf.root.u.def.section,
  5574. eh->elf.root.u.def.value,
  5575. &code_sec, NULL, FALSE) != (bfd_vma) -1)
  5576. code_sec->flags |= SEC_KEEP;
  5577. }
  5578. return TRUE;
  5579. }
  5580. /* Return the section that should be marked against GC for a given
  5581. relocation. */
  5582. static asection *
  5583. ppc64_elf_gc_mark_hook (asection *sec,
  5584. struct bfd_link_info *info,
  5585. Elf_Internal_Rela *rel,
  5586. struct elf_link_hash_entry *h,
  5587. Elf_Internal_Sym *sym)
  5588. {
  5589. asection *rsec;
  5590. /* Syms return NULL if we're marking .opd, so we avoid marking all
  5591. function sections, as all functions are referenced in .opd. */
  5592. rsec = NULL;
  5593. if (get_opd_info (sec) != NULL)
  5594. return rsec;
  5595. if (h != NULL)
  5596. {
  5597. enum elf_ppc64_reloc_type r_type;
  5598. struct ppc_link_hash_entry *eh, *fh, *fdh;
  5599. r_type = ELF64_R_TYPE (rel->r_info);
  5600. switch (r_type)
  5601. {
  5602. case R_PPC64_GNU_VTINHERIT:
  5603. case R_PPC64_GNU_VTENTRY:
  5604. break;
  5605. default:
  5606. switch (h->root.type)
  5607. {
  5608. case bfd_link_hash_defined:
  5609. case bfd_link_hash_defweak:
  5610. eh = (struct ppc_link_hash_entry *) h;
  5611. fdh = defined_func_desc (eh);
  5612. if (fdh != NULL)
  5613. eh = fdh;
  5614. /* Function descriptor syms cause the associated
  5615. function code sym section to be marked. */
  5616. fh = defined_code_entry (eh);
  5617. if (fh != NULL)
  5618. {
  5619. /* They also mark their opd section. */
  5620. eh->elf.root.u.def.section->gc_mark = 1;
  5621. rsec = fh->elf.root.u.def.section;
  5622. }
  5623. else if (get_opd_info (eh->elf.root.u.def.section) != NULL
  5624. && opd_entry_value (eh->elf.root.u.def.section,
  5625. eh->elf.root.u.def.value,
  5626. &rsec, NULL, FALSE) != (bfd_vma) -1)
  5627. eh->elf.root.u.def.section->gc_mark = 1;
  5628. else
  5629. rsec = h->root.u.def.section;
  5630. break;
  5631. case bfd_link_hash_common:
  5632. rsec = h->root.u.c.p->section;
  5633. break;
  5634. default:
  5635. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  5636. }
  5637. }
  5638. }
  5639. else
  5640. {
  5641. struct _opd_sec_data *opd;
  5642. rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
  5643. opd = get_opd_info (rsec);
  5644. if (opd != NULL && opd->func_sec != NULL)
  5645. {
  5646. rsec->gc_mark = 1;
  5647. rsec = opd->func_sec[OPD_NDX (sym->st_value + rel->r_addend)];
  5648. }
  5649. }
  5650. return rsec;
  5651. }
  5652. /* Update the .got, .plt. and dynamic reloc reference counts for the
  5653. section being removed. */
  5654. static bfd_boolean
  5655. ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
  5656. asection *sec, const Elf_Internal_Rela *relocs)
  5657. {
  5658. struct ppc_link_hash_table *htab;
  5659. Elf_Internal_Shdr *symtab_hdr;
  5660. struct elf_link_hash_entry **sym_hashes;
  5661. struct got_entry **local_got_ents;
  5662. const Elf_Internal_Rela *rel, *relend;
  5663. if (bfd_link_relocatable (info))
  5664. return TRUE;
  5665. if ((sec->flags & SEC_ALLOC) == 0)
  5666. return TRUE;
  5667. elf_section_data (sec)->local_dynrel = NULL;
  5668. htab = ppc_hash_table (info);
  5669. if (htab == NULL)
  5670. return FALSE;
  5671. symtab_hdr = &elf_symtab_hdr (abfd);
  5672. sym_hashes = elf_sym_hashes (abfd);
  5673. local_got_ents = elf_local_got_ents (abfd);
  5674. relend = relocs + sec->reloc_count;
  5675. for (rel = relocs; rel < relend; rel++)
  5676. {
  5677. unsigned long r_symndx;
  5678. enum elf_ppc64_reloc_type r_type;
  5679. struct elf_link_hash_entry *h = NULL;
  5680. unsigned char tls_type = 0;
  5681. r_symndx = ELF64_R_SYM (rel->r_info);
  5682. r_type = ELF64_R_TYPE (rel->r_info);
  5683. if (r_symndx >= symtab_hdr->sh_info)
  5684. {
  5685. struct ppc_link_hash_entry *eh;
  5686. struct elf_dyn_relocs **pp;
  5687. struct elf_dyn_relocs *p;
  5688. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  5689. h = elf_follow_link (h);
  5690. eh = (struct ppc_link_hash_entry *) h;
  5691. for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
  5692. if (p->sec == sec)
  5693. {
  5694. /* Everything must go for SEC. */
  5695. *pp = p->next;
  5696. break;
  5697. }
  5698. }
  5699. if (is_branch_reloc (r_type))
  5700. {
  5701. struct plt_entry **ifunc = NULL;
  5702. if (h != NULL)
  5703. {
  5704. if (h->type == STT_GNU_IFUNC)
  5705. ifunc = &h->plt.plist;
  5706. }
  5707. else if (local_got_ents != NULL)
  5708. {
  5709. struct plt_entry **local_plt = (struct plt_entry **)
  5710. (local_got_ents + symtab_hdr->sh_info);
  5711. unsigned char *local_got_tls_masks = (unsigned char *)
  5712. (local_plt + symtab_hdr->sh_info);
  5713. if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
  5714. ifunc = local_plt + r_symndx;
  5715. }
  5716. if (ifunc != NULL)
  5717. {
  5718. struct plt_entry *ent;
  5719. for (ent = *ifunc; ent != NULL; ent = ent->next)
  5720. if (ent->addend == rel->r_addend)
  5721. break;
  5722. if (ent == NULL)
  5723. abort ();
  5724. if (ent->plt.refcount > 0)
  5725. ent->plt.refcount -= 1;
  5726. continue;
  5727. }
  5728. }
  5729. switch (r_type)
  5730. {
  5731. case R_PPC64_GOT_TLSLD16:
  5732. case R_PPC64_GOT_TLSLD16_LO:
  5733. case R_PPC64_GOT_TLSLD16_HI:
  5734. case R_PPC64_GOT_TLSLD16_HA:
  5735. tls_type = TLS_TLS | TLS_LD;
  5736. goto dogot;
  5737. case R_PPC64_GOT_TLSGD16:
  5738. case R_PPC64_GOT_TLSGD16_LO:
  5739. case R_PPC64_GOT_TLSGD16_HI:
  5740. case R_PPC64_GOT_TLSGD16_HA:
  5741. tls_type = TLS_TLS | TLS_GD;
  5742. goto dogot;
  5743. case R_PPC64_GOT_TPREL16_DS:
  5744. case R_PPC64_GOT_TPREL16_LO_DS:
  5745. case R_PPC64_GOT_TPREL16_HI:
  5746. case R_PPC64_GOT_TPREL16_HA:
  5747. tls_type = TLS_TLS | TLS_TPREL;
  5748. goto dogot;
  5749. case R_PPC64_GOT_DTPREL16_DS:
  5750. case R_PPC64_GOT_DTPREL16_LO_DS:
  5751. case R_PPC64_GOT_DTPREL16_HI:
  5752. case R_PPC64_GOT_DTPREL16_HA:
  5753. tls_type = TLS_TLS | TLS_DTPREL;
  5754. goto dogot;
  5755. case R_PPC64_GOT16:
  5756. case R_PPC64_GOT16_DS:
  5757. case R_PPC64_GOT16_HA:
  5758. case R_PPC64_GOT16_HI:
  5759. case R_PPC64_GOT16_LO:
  5760. case R_PPC64_GOT16_LO_DS:
  5761. dogot:
  5762. {
  5763. struct got_entry *ent;
  5764. if (h != NULL)
  5765. ent = h->got.glist;
  5766. else
  5767. ent = local_got_ents[r_symndx];
  5768. for (; ent != NULL; ent = ent->next)
  5769. if (ent->addend == rel->r_addend
  5770. && ent->owner == abfd
  5771. && ent->tls_type == tls_type)
  5772. break;
  5773. if (ent == NULL)
  5774. abort ();
  5775. if (ent->got.refcount > 0)
  5776. ent->got.refcount -= 1;
  5777. }
  5778. break;
  5779. case R_PPC64_PLT16_HA:
  5780. case R_PPC64_PLT16_HI:
  5781. case R_PPC64_PLT16_LO:
  5782. case R_PPC64_PLT32:
  5783. case R_PPC64_PLT64:
  5784. case R_PPC64_REL14:
  5785. case R_PPC64_REL14_BRNTAKEN:
  5786. case R_PPC64_REL14_BRTAKEN:
  5787. case R_PPC64_REL24:
  5788. if (h != NULL)
  5789. {
  5790. struct plt_entry *ent;
  5791. for (ent = h->plt.plist; ent != NULL; ent = ent->next)
  5792. if (ent->addend == rel->r_addend)
  5793. break;
  5794. if (ent != NULL && ent->plt.refcount > 0)
  5795. ent->plt.refcount -= 1;
  5796. }
  5797. break;
  5798. default:
  5799. break;
  5800. }
  5801. }
  5802. return TRUE;
  5803. }
  5804. /* The maximum size of .sfpr. */
  5805. #define SFPR_MAX (218*4)
  5806. struct sfpr_def_parms
  5807. {
  5808. const char name[12];
  5809. unsigned char lo, hi;
  5810. bfd_byte * (*write_ent) (bfd *, bfd_byte *, int);
  5811. bfd_byte * (*write_tail) (bfd *, bfd_byte *, int);
  5812. };
  5813. /* Auto-generate _save*, _rest* functions in .sfpr.
  5814. If STUB_SEC is non-null, define alias symbols in STUB_SEC
  5815. instead. */
  5816. static bfd_boolean
  5817. sfpr_define (struct bfd_link_info *info,
  5818. const struct sfpr_def_parms *parm,
  5819. asection *stub_sec)
  5820. {
  5821. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  5822. unsigned int i;
  5823. size_t len = strlen (parm->name);
  5824. bfd_boolean writing = FALSE;
  5825. char sym[16];
  5826. if (htab == NULL)
  5827. return FALSE;
  5828. memcpy (sym, parm->name, len);
  5829. sym[len + 2] = 0;
  5830. for (i = parm->lo; i <= parm->hi; i++)
  5831. {
  5832. struct ppc_link_hash_entry *h;
  5833. sym[len + 0] = i / 10 + '0';
  5834. sym[len + 1] = i % 10 + '0';
  5835. h = (struct ppc_link_hash_entry *)
  5836. elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE);
  5837. if (stub_sec != NULL)
  5838. {
  5839. if (h != NULL
  5840. && h->elf.root.type == bfd_link_hash_defined
  5841. && h->elf.root.u.def.section == htab->sfpr)
  5842. {
  5843. struct elf_link_hash_entry *s;
  5844. char buf[32];
  5845. sprintf (buf, "%08x.%s", stub_sec->id & 0xffffffff, sym);
  5846. s = elf_link_hash_lookup (&htab->elf, buf, TRUE, TRUE, FALSE);
  5847. if (s == NULL)
  5848. return FALSE;
  5849. if (s->root.type == bfd_link_hash_new
  5850. || (s->root.type = bfd_link_hash_defined
  5851. && s->root.u.def.section == stub_sec))
  5852. {
  5853. s->root.type = bfd_link_hash_defined;
  5854. s->root.u.def.section = stub_sec;
  5855. s->root.u.def.value = (stub_sec->size
  5856. + h->elf.root.u.def.value);
  5857. s->ref_regular = 1;
  5858. s->def_regular = 1;
  5859. s->ref_regular_nonweak = 1;
  5860. s->forced_local = 1;
  5861. s->non_elf = 0;
  5862. s->root.linker_def = 1;
  5863. }
  5864. }
  5865. continue;
  5866. }
  5867. if (h != NULL)
  5868. {
  5869. h->save_res = 1;
  5870. if (!h->elf.def_regular)
  5871. {
  5872. h->elf.root.type = bfd_link_hash_defined;
  5873. h->elf.root.u.def.section = htab->sfpr;
  5874. h->elf.root.u.def.value = htab->sfpr->size;
  5875. h->elf.type = STT_FUNC;
  5876. h->elf.def_regular = 1;
  5877. _bfd_elf_link_hash_hide_symbol (info, &h->elf, TRUE);
  5878. writing = TRUE;
  5879. if (htab->sfpr->contents == NULL)
  5880. {
  5881. htab->sfpr->contents = bfd_alloc (htab->elf.dynobj, SFPR_MAX);
  5882. if (htab->sfpr->contents == NULL)
  5883. return FALSE;
  5884. }
  5885. }
  5886. }
  5887. if (writing)
  5888. {
  5889. bfd_byte *p = htab->sfpr->contents + htab->sfpr->size;
  5890. if (i != parm->hi)
  5891. p = (*parm->write_ent) (htab->elf.dynobj, p, i);
  5892. else
  5893. p = (*parm->write_tail) (htab->elf.dynobj, p, i);
  5894. htab->sfpr->size = p - htab->sfpr->contents;
  5895. }
  5896. }
  5897. return TRUE;
  5898. }
  5899. static bfd_byte *
  5900. savegpr0 (bfd *abfd, bfd_byte *p, int r)
  5901. {
  5902. bfd_put_32 (abfd, STD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
  5903. return p + 4;
  5904. }
  5905. static bfd_byte *
  5906. savegpr0_tail (bfd *abfd, bfd_byte *p, int r)
  5907. {
  5908. p = savegpr0 (abfd, p, r);
  5909. bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
  5910. p = p + 4;
  5911. bfd_put_32 (abfd, BLR, p);
  5912. return p + 4;
  5913. }
  5914. static bfd_byte *
  5915. restgpr0 (bfd *abfd, bfd_byte *p, int r)
  5916. {
  5917. bfd_put_32 (abfd, LD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
  5918. return p + 4;
  5919. }
  5920. static bfd_byte *
  5921. restgpr0_tail (bfd *abfd, bfd_byte *p, int r)
  5922. {
  5923. bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
  5924. p = p + 4;
  5925. p = restgpr0 (abfd, p, r);
  5926. bfd_put_32 (abfd, MTLR_R0, p);
  5927. p = p + 4;
  5928. if (r == 29)
  5929. {
  5930. p = restgpr0 (abfd, p, 30);
  5931. p = restgpr0 (abfd, p, 31);
  5932. }
  5933. bfd_put_32 (abfd, BLR, p);
  5934. return p + 4;
  5935. }
  5936. static bfd_byte *
  5937. savegpr1 (bfd *abfd, bfd_byte *p, int r)
  5938. {
  5939. bfd_put_32 (abfd, STD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
  5940. return p + 4;
  5941. }
  5942. static bfd_byte *
  5943. savegpr1_tail (bfd *abfd, bfd_byte *p, int r)
  5944. {
  5945. p = savegpr1 (abfd, p, r);
  5946. bfd_put_32 (abfd, BLR, p);
  5947. return p + 4;
  5948. }
  5949. static bfd_byte *
  5950. restgpr1 (bfd *abfd, bfd_byte *p, int r)
  5951. {
  5952. bfd_put_32 (abfd, LD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
  5953. return p + 4;
  5954. }
  5955. static bfd_byte *
  5956. restgpr1_tail (bfd *abfd, bfd_byte *p, int r)
  5957. {
  5958. p = restgpr1 (abfd, p, r);
  5959. bfd_put_32 (abfd, BLR, p);
  5960. return p + 4;
  5961. }
  5962. static bfd_byte *
  5963. savefpr (bfd *abfd, bfd_byte *p, int r)
  5964. {
  5965. bfd_put_32 (abfd, STFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
  5966. return p + 4;
  5967. }
  5968. static bfd_byte *
  5969. savefpr0_tail (bfd *abfd, bfd_byte *p, int r)
  5970. {
  5971. p = savefpr (abfd, p, r);
  5972. bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
  5973. p = p + 4;
  5974. bfd_put_32 (abfd, BLR, p);
  5975. return p + 4;
  5976. }
  5977. static bfd_byte *
  5978. restfpr (bfd *abfd, bfd_byte *p, int r)
  5979. {
  5980. bfd_put_32 (abfd, LFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
  5981. return p + 4;
  5982. }
  5983. static bfd_byte *
  5984. restfpr0_tail (bfd *abfd, bfd_byte *p, int r)
  5985. {
  5986. bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
  5987. p = p + 4;
  5988. p = restfpr (abfd, p, r);
  5989. bfd_put_32 (abfd, MTLR_R0, p);
  5990. p = p + 4;
  5991. if (r == 29)
  5992. {
  5993. p = restfpr (abfd, p, 30);
  5994. p = restfpr (abfd, p, 31);
  5995. }
  5996. bfd_put_32 (abfd, BLR, p);
  5997. return p + 4;
  5998. }
  5999. static bfd_byte *
  6000. savefpr1_tail (bfd *abfd, bfd_byte *p, int r)
  6001. {
  6002. p = savefpr (abfd, p, r);
  6003. bfd_put_32 (abfd, BLR, p);
  6004. return p + 4;
  6005. }
  6006. static bfd_byte *
  6007. restfpr1_tail (bfd *abfd, bfd_byte *p, int r)
  6008. {
  6009. p = restfpr (abfd, p, r);
  6010. bfd_put_32 (abfd, BLR, p);
  6011. return p + 4;
  6012. }
  6013. static bfd_byte *
  6014. savevr (bfd *abfd, bfd_byte *p, int r)
  6015. {
  6016. bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
  6017. p = p + 4;
  6018. bfd_put_32 (abfd, STVX_VR0_R12_R0 + (r << 21), p);
  6019. return p + 4;
  6020. }
  6021. static bfd_byte *
  6022. savevr_tail (bfd *abfd, bfd_byte *p, int r)
  6023. {
  6024. p = savevr (abfd, p, r);
  6025. bfd_put_32 (abfd, BLR, p);
  6026. return p + 4;
  6027. }
  6028. static bfd_byte *
  6029. restvr (bfd *abfd, bfd_byte *p, int r)
  6030. {
  6031. bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
  6032. p = p + 4;
  6033. bfd_put_32 (abfd, LVX_VR0_R12_R0 + (r << 21), p);
  6034. return p + 4;
  6035. }
  6036. static bfd_byte *
  6037. restvr_tail (bfd *abfd, bfd_byte *p, int r)
  6038. {
  6039. p = restvr (abfd, p, r);
  6040. bfd_put_32 (abfd, BLR, p);
  6041. return p + 4;
  6042. }
  6043. /* Called via elf_link_hash_traverse to transfer dynamic linking
  6044. information on function code symbol entries to their corresponding
  6045. function descriptor symbol entries. */
  6046. static bfd_boolean
  6047. func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
  6048. {
  6049. struct bfd_link_info *info;
  6050. struct ppc_link_hash_table *htab;
  6051. struct plt_entry *ent;
  6052. struct ppc_link_hash_entry *fh;
  6053. struct ppc_link_hash_entry *fdh;
  6054. bfd_boolean force_local;
  6055. fh = (struct ppc_link_hash_entry *) h;
  6056. if (fh->elf.root.type == bfd_link_hash_indirect)
  6057. return TRUE;
  6058. info = inf;
  6059. htab = ppc_hash_table (info);
  6060. if (htab == NULL)
  6061. return FALSE;
  6062. /* Resolve undefined references to dot-symbols as the value
  6063. in the function descriptor, if we have one in a regular object.
  6064. This is to satisfy cases like ".quad .foo". Calls to functions
  6065. in dynamic objects are handled elsewhere. */
  6066. if (fh->elf.root.type == bfd_link_hash_undefweak
  6067. && fh->was_undefined
  6068. && (fdh = defined_func_desc (fh)) != NULL
  6069. && get_opd_info (fdh->elf.root.u.def.section) != NULL
  6070. && opd_entry_value (fdh->elf.root.u.def.section,
  6071. fdh->elf.root.u.def.value,
  6072. &fh->elf.root.u.def.section,
  6073. &fh->elf.root.u.def.value, FALSE) != (bfd_vma) -1)
  6074. {
  6075. fh->elf.root.type = fdh->elf.root.type;
  6076. fh->elf.forced_local = 1;
  6077. fh->elf.def_regular = fdh->elf.def_regular;
  6078. fh->elf.def_dynamic = fdh->elf.def_dynamic;
  6079. }
  6080. /* If this is a function code symbol, transfer dynamic linking
  6081. information to the function descriptor symbol. */
  6082. if (!fh->is_func)
  6083. return TRUE;
  6084. for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next)
  6085. if (ent->plt.refcount > 0)
  6086. break;
  6087. if (ent == NULL
  6088. || fh->elf.root.root.string[0] != '.'
  6089. || fh->elf.root.root.string[1] == '\0')
  6090. return TRUE;
  6091. /* Find the corresponding function descriptor symbol. Create it
  6092. as undefined if necessary. */
  6093. fdh = lookup_fdh (fh, htab);
  6094. if (fdh == NULL
  6095. && !bfd_link_executable (info)
  6096. && (fh->elf.root.type == bfd_link_hash_undefined
  6097. || fh->elf.root.type == bfd_link_hash_undefweak))
  6098. {
  6099. fdh = make_fdh (info, fh);
  6100. if (fdh == NULL)
  6101. return FALSE;
  6102. }
  6103. /* Fake function descriptors are made undefweak. If the function
  6104. code symbol is strong undefined, make the fake sym the same.
  6105. If the function code symbol is defined, then force the fake
  6106. descriptor local; We can't support overriding of symbols in a
  6107. shared library on a fake descriptor. */
  6108. if (fdh != NULL
  6109. && fdh->fake
  6110. && fdh->elf.root.type == bfd_link_hash_undefweak)
  6111. {
  6112. if (fh->elf.root.type == bfd_link_hash_undefined)
  6113. {
  6114. fdh->elf.root.type = bfd_link_hash_undefined;
  6115. bfd_link_add_undef (&htab->elf.root, &fdh->elf.root);
  6116. }
  6117. else if (fh->elf.root.type == bfd_link_hash_defined
  6118. || fh->elf.root.type == bfd_link_hash_defweak)
  6119. {
  6120. _bfd_elf_link_hash_hide_symbol (info, &fdh->elf, TRUE);
  6121. }
  6122. }
  6123. if (fdh != NULL
  6124. && !fdh->elf.forced_local
  6125. && (!bfd_link_executable (info)
  6126. || fdh->elf.def_dynamic
  6127. || fdh->elf.ref_dynamic
  6128. || (fdh->elf.root.type == bfd_link_hash_undefweak
  6129. && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT)))
  6130. {
  6131. if (fdh->elf.dynindx == -1)
  6132. if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf))
  6133. return FALSE;
  6134. fdh->elf.ref_regular |= fh->elf.ref_regular;
  6135. fdh->elf.ref_dynamic |= fh->elf.ref_dynamic;
  6136. fdh->elf.ref_regular_nonweak |= fh->elf.ref_regular_nonweak;
  6137. fdh->elf.non_got_ref |= fh->elf.non_got_ref;
  6138. if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT)
  6139. {
  6140. move_plt_plist (fh, fdh);
  6141. fdh->elf.needs_plt = 1;
  6142. }
  6143. fdh->is_func_descriptor = 1;
  6144. fdh->oh = fh;
  6145. fh->oh = fdh;
  6146. }
  6147. /* Now that the info is on the function descriptor, clear the
  6148. function code sym info. Any function code syms for which we
  6149. don't have a definition in a regular file, we force local.
  6150. This prevents a shared library from exporting syms that have
  6151. been imported from another library. Function code syms that
  6152. are really in the library we must leave global to prevent the
  6153. linker dragging in a definition from a static library. */
  6154. force_local = (!fh->elf.def_regular
  6155. || fdh == NULL
  6156. || !fdh->elf.def_regular
  6157. || fdh->elf.forced_local);
  6158. _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
  6159. return TRUE;
  6160. }
  6161. static const struct sfpr_def_parms save_res_funcs[] =
  6162. {
  6163. { "_savegpr0_", 14, 31, savegpr0, savegpr0_tail },
  6164. { "_restgpr0_", 14, 29, restgpr0, restgpr0_tail },
  6165. { "_restgpr0_", 30, 31, restgpr0, restgpr0_tail },
  6166. { "_savegpr1_", 14, 31, savegpr1, savegpr1_tail },
  6167. { "_restgpr1_", 14, 31, restgpr1, restgpr1_tail },
  6168. { "_savefpr_", 14, 31, savefpr, savefpr0_tail },
  6169. { "_restfpr_", 14, 29, restfpr, restfpr0_tail },
  6170. { "_restfpr_", 30, 31, restfpr, restfpr0_tail },
  6171. { "._savef", 14, 31, savefpr, savefpr1_tail },
  6172. { "._restf", 14, 31, restfpr, restfpr1_tail },
  6173. { "_savevr_", 20, 31, savevr, savevr_tail },
  6174. { "_restvr_", 20, 31, restvr, restvr_tail }
  6175. };
  6176. /* Called near the start of bfd_elf_size_dynamic_sections. We use
  6177. this hook to a) provide some gcc support functions, and b) transfer
  6178. dynamic linking information gathered so far on function code symbol
  6179. entries, to their corresponding function descriptor symbol entries. */
  6180. static bfd_boolean
  6181. ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED,
  6182. struct bfd_link_info *info)
  6183. {
  6184. struct ppc_link_hash_table *htab;
  6185. unsigned int i;
  6186. htab = ppc_hash_table (info);
  6187. if (htab == NULL)
  6188. return FALSE;
  6189. if (!bfd_link_relocatable (info)
  6190. && htab->elf.hgot != NULL)
  6191. {
  6192. _bfd_elf_link_hash_hide_symbol (info, htab->elf.hgot, TRUE);
  6193. /* Make .TOC. defined so as to prevent it being made dynamic.
  6194. The wrong value here is fixed later in ppc64_elf_set_toc. */
  6195. if (!htab->elf.hgot->def_regular
  6196. || htab->elf.hgot->root.type != bfd_link_hash_defined)
  6197. {
  6198. htab->elf.hgot->root.type = bfd_link_hash_defined;
  6199. htab->elf.hgot->root.u.def.value = 0;
  6200. htab->elf.hgot->root.u.def.section = bfd_abs_section_ptr;
  6201. htab->elf.hgot->def_regular = 1;
  6202. htab->elf.hgot->root.linker_def = 1;
  6203. }
  6204. htab->elf.hgot->type = STT_OBJECT;
  6205. htab->elf.hgot->other = ((htab->elf.hgot->other & ~ELF_ST_VISIBILITY (-1))
  6206. | STV_HIDDEN);
  6207. }
  6208. if (htab->sfpr == NULL)
  6209. /* We don't have any relocs. */
  6210. return TRUE;
  6211. /* Provide any missing _save* and _rest* functions. */
  6212. htab->sfpr->size = 0;
  6213. if (htab->params->save_restore_funcs)
  6214. for (i = 0; i < ARRAY_SIZE (save_res_funcs); i++)
  6215. if (!sfpr_define (info, &save_res_funcs[i], NULL))
  6216. return FALSE;
  6217. elf_link_hash_traverse (&htab->elf, func_desc_adjust, info);
  6218. if (htab->sfpr->size == 0)
  6219. htab->sfpr->flags |= SEC_EXCLUDE;
  6220. return TRUE;
  6221. }
  6222. /* Return true if we have dynamic relocs that apply to read-only sections. */
  6223. static bfd_boolean
  6224. readonly_dynrelocs (struct elf_link_hash_entry *h)
  6225. {
  6226. struct ppc_link_hash_entry *eh;
  6227. struct elf_dyn_relocs *p;
  6228. eh = (struct ppc_link_hash_entry *) h;
  6229. for (p = eh->dyn_relocs; p != NULL; p = p->next)
  6230. {
  6231. asection *s = p->sec->output_section;
  6232. if (s != NULL && (s->flags & SEC_READONLY) != 0)
  6233. return TRUE;
  6234. }
  6235. return FALSE;
  6236. }
  6237. /* Adjust a symbol defined by a dynamic object and referenced by a
  6238. regular object. The current definition is in some section of the
  6239. dynamic object, but we're not including those sections. We have to
  6240. change the definition to something the rest of the link can
  6241. understand. */
  6242. static bfd_boolean
  6243. ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
  6244. struct elf_link_hash_entry *h)
  6245. {
  6246. struct ppc_link_hash_table *htab;
  6247. asection *s;
  6248. htab = ppc_hash_table (info);
  6249. if (htab == NULL)
  6250. return FALSE;
  6251. /* Deal with function syms. */
  6252. if (h->type == STT_FUNC
  6253. || h->type == STT_GNU_IFUNC
  6254. || h->needs_plt)
  6255. {
  6256. /* Clear procedure linkage table information for any symbol that
  6257. won't need a .plt entry. */
  6258. struct plt_entry *ent;
  6259. for (ent = h->plt.plist; ent != NULL; ent = ent->next)
  6260. if (ent->plt.refcount > 0)
  6261. break;
  6262. if (ent == NULL
  6263. || (h->type != STT_GNU_IFUNC
  6264. && (SYMBOL_CALLS_LOCAL (info, h)
  6265. || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  6266. && h->root.type == bfd_link_hash_undefweak)))
  6267. || ((struct ppc_link_hash_entry *) h)->save_res)
  6268. {
  6269. h->plt.plist = NULL;
  6270. h->needs_plt = 0;
  6271. h->pointer_equality_needed = 0;
  6272. }
  6273. else if (abiversion (info->output_bfd) == 2)
  6274. {
  6275. /* Taking a function's address in a read/write section
  6276. doesn't require us to define the function symbol in the
  6277. executable on a global entry stub. A dynamic reloc can
  6278. be used instead. */
  6279. if (h->pointer_equality_needed
  6280. && h->type != STT_GNU_IFUNC
  6281. && !readonly_dynrelocs (h))
  6282. {
  6283. h->pointer_equality_needed = 0;
  6284. h->non_got_ref = 0;
  6285. }
  6286. /* After adjust_dynamic_symbol, non_got_ref set in the
  6287. non-shared case means that we have allocated space in
  6288. .dynbss for the symbol and thus dyn_relocs for this
  6289. symbol should be discarded.
  6290. If we get here we know we are making a PLT entry for this
  6291. symbol, and in an executable we'd normally resolve
  6292. relocations against this symbol to the PLT entry. Allow
  6293. dynamic relocs if the reference is weak, and the dynamic
  6294. relocs will not cause text relocation. */
  6295. else if (!h->ref_regular_nonweak
  6296. && h->non_got_ref
  6297. && h->type != STT_GNU_IFUNC
  6298. && !readonly_dynrelocs (h))
  6299. h->non_got_ref = 0;
  6300. /* If making a plt entry, then we don't need copy relocs. */
  6301. return TRUE;
  6302. }
  6303. }
  6304. else
  6305. h->plt.plist = NULL;
  6306. /* If this is a weak symbol, and there is a real definition, the
  6307. processor independent code will have arranged for us to see the
  6308. real definition first, and we can just use the same value. */
  6309. if (h->u.weakdef != NULL)
  6310. {
  6311. BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
  6312. || h->u.weakdef->root.type == bfd_link_hash_defweak);
  6313. h->root.u.def.section = h->u.weakdef->root.u.def.section;
  6314. h->root.u.def.value = h->u.weakdef->root.u.def.value;
  6315. if (ELIMINATE_COPY_RELOCS)
  6316. h->non_got_ref = h->u.weakdef->non_got_ref;
  6317. return TRUE;
  6318. }
  6319. /* If we are creating a shared library, we must presume that the
  6320. only references to the symbol are via the global offset table.
  6321. For such cases we need not do anything here; the relocations will
  6322. be handled correctly by relocate_section. */
  6323. if (bfd_link_pic (info))
  6324. return TRUE;
  6325. /* If there are no references to this symbol that do not use the
  6326. GOT, we don't need to generate a copy reloc. */
  6327. if (!h->non_got_ref)
  6328. return TRUE;
  6329. /* Don't generate a copy reloc for symbols defined in the executable. */
  6330. if (!h->def_dynamic || !h->ref_regular || h->def_regular)
  6331. return TRUE;
  6332. /* If -z nocopyreloc was given, don't generate them either. */
  6333. if (info->nocopyreloc)
  6334. {
  6335. h->non_got_ref = 0;
  6336. return TRUE;
  6337. }
  6338. /* If we didn't find any dynamic relocs in read-only sections, then
  6339. we'll be keeping the dynamic relocs and avoiding the copy reloc. */
  6340. if (ELIMINATE_COPY_RELOCS && !readonly_dynrelocs (h))
  6341. {
  6342. h->non_got_ref = 0;
  6343. return TRUE;
  6344. }
  6345. /* Protected variables do not work with .dynbss. The copy in
  6346. .dynbss won't be used by the shared library with the protected
  6347. definition for the variable. Text relocations are preferable
  6348. to an incorrect program. */
  6349. if (h->protected_def)
  6350. {
  6351. h->non_got_ref = 0;
  6352. return TRUE;
  6353. }
  6354. if (h->plt.plist != NULL)
  6355. {
  6356. /* We should never get here, but unfortunately there are versions
  6357. of gcc out there that improperly (for this ABI) put initialized
  6358. function pointers, vtable refs and suchlike in read-only
  6359. sections. Allow them to proceed, but warn that this might
  6360. break at runtime. */
  6361. info->callbacks->einfo
  6362. (_("%P: copy reloc against `%T' requires lazy plt linking; "
  6363. "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
  6364. h->root.root.string);
  6365. }
  6366. /* This is a reference to a symbol defined by a dynamic object which
  6367. is not a function. */
  6368. /* We must allocate the symbol in our .dynbss section, which will
  6369. become part of the .bss section of the executable. There will be
  6370. an entry for this symbol in the .dynsym section. The dynamic
  6371. object will contain position independent code, so all references
  6372. from the dynamic object to this symbol will go through the global
  6373. offset table. The dynamic linker will use the .dynsym entry to
  6374. determine the address it must put in the global offset table, so
  6375. both the dynamic object and the regular object will refer to the
  6376. same memory location for the variable. */
  6377. /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
  6378. to copy the initial value out of the dynamic object and into the
  6379. runtime process image. We need to remember the offset into the
  6380. .rela.bss section we are going to use. */
  6381. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  6382. {
  6383. htab->relbss->size += sizeof (Elf64_External_Rela);
  6384. h->needs_copy = 1;
  6385. }
  6386. s = htab->dynbss;
  6387. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  6388. }
  6389. /* If given a function descriptor symbol, hide both the function code
  6390. sym and the descriptor. */
  6391. static void
  6392. ppc64_elf_hide_symbol (struct bfd_link_info *info,
  6393. struct elf_link_hash_entry *h,
  6394. bfd_boolean force_local)
  6395. {
  6396. struct ppc_link_hash_entry *eh;
  6397. _bfd_elf_link_hash_hide_symbol (info, h, force_local);
  6398. eh = (struct ppc_link_hash_entry *) h;
  6399. if (eh->is_func_descriptor)
  6400. {
  6401. struct ppc_link_hash_entry *fh = eh->oh;
  6402. if (fh == NULL)
  6403. {
  6404. const char *p, *q;
  6405. struct ppc_link_hash_table *htab;
  6406. char save;
  6407. /* We aren't supposed to use alloca in BFD because on
  6408. systems which do not have alloca the version in libiberty
  6409. calls xmalloc, which might cause the program to crash
  6410. when it runs out of memory. This function doesn't have a
  6411. return status, so there's no way to gracefully return an
  6412. error. So cheat. We know that string[-1] can be safely
  6413. accessed; It's either a string in an ELF string table,
  6414. or allocated in an objalloc structure. */
  6415. p = eh->elf.root.root.string - 1;
  6416. save = *p;
  6417. *(char *) p = '.';
  6418. htab = ppc_hash_table (info);
  6419. if (htab == NULL)
  6420. return;
  6421. fh = (struct ppc_link_hash_entry *)
  6422. elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
  6423. *(char *) p = save;
  6424. /* Unfortunately, if it so happens that the string we were
  6425. looking for was allocated immediately before this string,
  6426. then we overwrote the string terminator. That's the only
  6427. reason the lookup should fail. */
  6428. if (fh == NULL)
  6429. {
  6430. q = eh->elf.root.root.string + strlen (eh->elf.root.root.string);
  6431. while (q >= eh->elf.root.root.string && *q == *p)
  6432. --q, --p;
  6433. if (q < eh->elf.root.root.string && *p == '.')
  6434. fh = (struct ppc_link_hash_entry *)
  6435. elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
  6436. }
  6437. if (fh != NULL)
  6438. {
  6439. eh->oh = fh;
  6440. fh->oh = eh;
  6441. }
  6442. }
  6443. if (fh != NULL)
  6444. _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
  6445. }
  6446. }
  6447. static bfd_boolean
  6448. get_sym_h (struct elf_link_hash_entry **hp,
  6449. Elf_Internal_Sym **symp,
  6450. asection **symsecp,
  6451. unsigned char **tls_maskp,
  6452. Elf_Internal_Sym **locsymsp,
  6453. unsigned long r_symndx,
  6454. bfd *ibfd)
  6455. {
  6456. Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
  6457. if (r_symndx >= symtab_hdr->sh_info)
  6458. {
  6459. struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
  6460. struct elf_link_hash_entry *h;
  6461. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  6462. h = elf_follow_link (h);
  6463. if (hp != NULL)
  6464. *hp = h;
  6465. if (symp != NULL)
  6466. *symp = NULL;
  6467. if (symsecp != NULL)
  6468. {
  6469. asection *symsec = NULL;
  6470. if (h->root.type == bfd_link_hash_defined
  6471. || h->root.type == bfd_link_hash_defweak)
  6472. symsec = h->root.u.def.section;
  6473. *symsecp = symsec;
  6474. }
  6475. if (tls_maskp != NULL)
  6476. {
  6477. struct ppc_link_hash_entry *eh;
  6478. eh = (struct ppc_link_hash_entry *) h;
  6479. *tls_maskp = &eh->tls_mask;
  6480. }
  6481. }
  6482. else
  6483. {
  6484. Elf_Internal_Sym *sym;
  6485. Elf_Internal_Sym *locsyms = *locsymsp;
  6486. if (locsyms == NULL)
  6487. {
  6488. locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
  6489. if (locsyms == NULL)
  6490. locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
  6491. symtab_hdr->sh_info,
  6492. 0, NULL, NULL, NULL);
  6493. if (locsyms == NULL)
  6494. return FALSE;
  6495. *locsymsp = locsyms;
  6496. }
  6497. sym = locsyms + r_symndx;
  6498. if (hp != NULL)
  6499. *hp = NULL;
  6500. if (symp != NULL)
  6501. *symp = sym;
  6502. if (symsecp != NULL)
  6503. *symsecp = bfd_section_from_elf_index (ibfd, sym->st_shndx);
  6504. if (tls_maskp != NULL)
  6505. {
  6506. struct got_entry **lgot_ents;
  6507. unsigned char *tls_mask;
  6508. tls_mask = NULL;
  6509. lgot_ents = elf_local_got_ents (ibfd);
  6510. if (lgot_ents != NULL)
  6511. {
  6512. struct plt_entry **local_plt = (struct plt_entry **)
  6513. (lgot_ents + symtab_hdr->sh_info);
  6514. unsigned char *lgot_masks = (unsigned char *)
  6515. (local_plt + symtab_hdr->sh_info);
  6516. tls_mask = &lgot_masks[r_symndx];
  6517. }
  6518. *tls_maskp = tls_mask;
  6519. }
  6520. }
  6521. return TRUE;
  6522. }
  6523. /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
  6524. error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
  6525. type suitable for optimization, and 1 otherwise. */
  6526. static int
  6527. get_tls_mask (unsigned char **tls_maskp,
  6528. unsigned long *toc_symndx,
  6529. bfd_vma *toc_addend,
  6530. Elf_Internal_Sym **locsymsp,
  6531. const Elf_Internal_Rela *rel,
  6532. bfd *ibfd)
  6533. {
  6534. unsigned long r_symndx;
  6535. int next_r;
  6536. struct elf_link_hash_entry *h;
  6537. Elf_Internal_Sym *sym;
  6538. asection *sec;
  6539. bfd_vma off;
  6540. r_symndx = ELF64_R_SYM (rel->r_info);
  6541. if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
  6542. return 0;
  6543. if ((*tls_maskp != NULL && **tls_maskp != 0)
  6544. || sec == NULL
  6545. || ppc64_elf_section_data (sec) == NULL
  6546. || ppc64_elf_section_data (sec)->sec_type != sec_toc)
  6547. return 1;
  6548. /* Look inside a TOC section too. */
  6549. if (h != NULL)
  6550. {
  6551. BFD_ASSERT (h->root.type == bfd_link_hash_defined);
  6552. off = h->root.u.def.value;
  6553. }
  6554. else
  6555. off = sym->st_value;
  6556. off += rel->r_addend;
  6557. BFD_ASSERT (off % 8 == 0);
  6558. r_symndx = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8];
  6559. next_r = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8 + 1];
  6560. if (toc_symndx != NULL)
  6561. *toc_symndx = r_symndx;
  6562. if (toc_addend != NULL)
  6563. *toc_addend = ppc64_elf_section_data (sec)->u.toc.add[off / 8];
  6564. if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
  6565. return 0;
  6566. if ((h == NULL || is_static_defined (h))
  6567. && (next_r == -1 || next_r == -2))
  6568. return 1 - next_r;
  6569. return 1;
  6570. }
  6571. /* Find (or create) an entry in the tocsave hash table. */
  6572. static struct tocsave_entry *
  6573. tocsave_find (struct ppc_link_hash_table *htab,
  6574. enum insert_option insert,
  6575. Elf_Internal_Sym **local_syms,
  6576. const Elf_Internal_Rela *irela,
  6577. bfd *ibfd)
  6578. {
  6579. unsigned long r_indx;
  6580. struct elf_link_hash_entry *h;
  6581. Elf_Internal_Sym *sym;
  6582. struct tocsave_entry ent, *p;
  6583. hashval_t hash;
  6584. struct tocsave_entry **slot;
  6585. r_indx = ELF64_R_SYM (irela->r_info);
  6586. if (!get_sym_h (&h, &sym, &ent.sec, NULL, local_syms, r_indx, ibfd))
  6587. return NULL;
  6588. if (ent.sec == NULL || ent.sec->output_section == NULL)
  6589. {
  6590. (*_bfd_error_handler)
  6591. (_("%B: undefined symbol on R_PPC64_TOCSAVE relocation"));
  6592. return NULL;
  6593. }
  6594. if (h != NULL)
  6595. ent.offset = h->root.u.def.value;
  6596. else
  6597. ent.offset = sym->st_value;
  6598. ent.offset += irela->r_addend;
  6599. hash = tocsave_htab_hash (&ent);
  6600. slot = ((struct tocsave_entry **)
  6601. htab_find_slot_with_hash (htab->tocsave_htab, &ent, hash, insert));
  6602. if (slot == NULL)
  6603. return NULL;
  6604. if (*slot == NULL)
  6605. {
  6606. p = (struct tocsave_entry *) bfd_alloc (ibfd, sizeof (*p));
  6607. if (p == NULL)
  6608. return NULL;
  6609. *p = ent;
  6610. *slot = p;
  6611. }
  6612. return *slot;
  6613. }
  6614. /* Adjust all global syms defined in opd sections. In gcc generated
  6615. code for the old ABI, these will already have been done. */
  6616. static bfd_boolean
  6617. adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
  6618. {
  6619. struct ppc_link_hash_entry *eh;
  6620. asection *sym_sec;
  6621. struct _opd_sec_data *opd;
  6622. if (h->root.type == bfd_link_hash_indirect)
  6623. return TRUE;
  6624. if (h->root.type != bfd_link_hash_defined
  6625. && h->root.type != bfd_link_hash_defweak)
  6626. return TRUE;
  6627. eh = (struct ppc_link_hash_entry *) h;
  6628. if (eh->adjust_done)
  6629. return TRUE;
  6630. sym_sec = eh->elf.root.u.def.section;
  6631. opd = get_opd_info (sym_sec);
  6632. if (opd != NULL && opd->adjust != NULL)
  6633. {
  6634. long adjust = opd->adjust[OPD_NDX (eh->elf.root.u.def.value)];
  6635. if (adjust == -1)
  6636. {
  6637. /* This entry has been deleted. */
  6638. asection *dsec = ppc64_elf_tdata (sym_sec->owner)->deleted_section;
  6639. if (dsec == NULL)
  6640. {
  6641. for (dsec = sym_sec->owner->sections; dsec; dsec = dsec->next)
  6642. if (discarded_section (dsec))
  6643. {
  6644. ppc64_elf_tdata (sym_sec->owner)->deleted_section = dsec;
  6645. break;
  6646. }
  6647. }
  6648. eh->elf.root.u.def.value = 0;
  6649. eh->elf.root.u.def.section = dsec;
  6650. }
  6651. else
  6652. eh->elf.root.u.def.value += adjust;
  6653. eh->adjust_done = 1;
  6654. }
  6655. return TRUE;
  6656. }
  6657. /* Handles decrementing dynamic reloc counts for the reloc specified by
  6658. R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
  6659. have already been determined. */
  6660. static bfd_boolean
  6661. dec_dynrel_count (bfd_vma r_info,
  6662. asection *sec,
  6663. struct bfd_link_info *info,
  6664. Elf_Internal_Sym **local_syms,
  6665. struct elf_link_hash_entry *h,
  6666. Elf_Internal_Sym *sym)
  6667. {
  6668. enum elf_ppc64_reloc_type r_type;
  6669. asection *sym_sec = NULL;
  6670. /* Can this reloc be dynamic? This switch, and later tests here
  6671. should be kept in sync with the code in check_relocs. */
  6672. r_type = ELF64_R_TYPE (r_info);
  6673. switch (r_type)
  6674. {
  6675. default:
  6676. return TRUE;
  6677. case R_PPC64_TPREL16:
  6678. case R_PPC64_TPREL16_LO:
  6679. case R_PPC64_TPREL16_HI:
  6680. case R_PPC64_TPREL16_HA:
  6681. case R_PPC64_TPREL16_DS:
  6682. case R_PPC64_TPREL16_LO_DS:
  6683. case R_PPC64_TPREL16_HIGH:
  6684. case R_PPC64_TPREL16_HIGHA:
  6685. case R_PPC64_TPREL16_HIGHER:
  6686. case R_PPC64_TPREL16_HIGHERA:
  6687. case R_PPC64_TPREL16_HIGHEST:
  6688. case R_PPC64_TPREL16_HIGHESTA:
  6689. if (!bfd_link_pic (info))
  6690. return TRUE;
  6691. case R_PPC64_TPREL64:
  6692. case R_PPC64_DTPMOD64:
  6693. case R_PPC64_DTPREL64:
  6694. case R_PPC64_ADDR64:
  6695. case R_PPC64_REL30:
  6696. case R_PPC64_REL32:
  6697. case R_PPC64_REL64:
  6698. case R_PPC64_ADDR14:
  6699. case R_PPC64_ADDR14_BRNTAKEN:
  6700. case R_PPC64_ADDR14_BRTAKEN:
  6701. case R_PPC64_ADDR16:
  6702. case R_PPC64_ADDR16_DS:
  6703. case R_PPC64_ADDR16_HA:
  6704. case R_PPC64_ADDR16_HI:
  6705. case R_PPC64_ADDR16_HIGH:
  6706. case R_PPC64_ADDR16_HIGHA:
  6707. case R_PPC64_ADDR16_HIGHER:
  6708. case R_PPC64_ADDR16_HIGHERA:
  6709. case R_PPC64_ADDR16_HIGHEST:
  6710. case R_PPC64_ADDR16_HIGHESTA:
  6711. case R_PPC64_ADDR16_LO:
  6712. case R_PPC64_ADDR16_LO_DS:
  6713. case R_PPC64_ADDR24:
  6714. case R_PPC64_ADDR32:
  6715. case R_PPC64_UADDR16:
  6716. case R_PPC64_UADDR32:
  6717. case R_PPC64_UADDR64:
  6718. case R_PPC64_TOC:
  6719. break;
  6720. }
  6721. if (local_syms != NULL)
  6722. {
  6723. unsigned long r_symndx;
  6724. bfd *ibfd = sec->owner;
  6725. r_symndx = ELF64_R_SYM (r_info);
  6726. if (!get_sym_h (&h, &sym, &sym_sec, NULL, local_syms, r_symndx, ibfd))
  6727. return FALSE;
  6728. }
  6729. if ((bfd_link_pic (info)
  6730. && (must_be_dyn_reloc (info, r_type)
  6731. || (h != NULL
  6732. && (!SYMBOLIC_BIND (info, h)
  6733. || h->root.type == bfd_link_hash_defweak
  6734. || !h->def_regular))))
  6735. || (ELIMINATE_COPY_RELOCS
  6736. && !bfd_link_pic (info)
  6737. && h != NULL
  6738. && (h->root.type == bfd_link_hash_defweak
  6739. || !h->def_regular)))
  6740. ;
  6741. else
  6742. return TRUE;
  6743. if (h != NULL)
  6744. {
  6745. struct elf_dyn_relocs *p;
  6746. struct elf_dyn_relocs **pp;
  6747. pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
  6748. /* elf_gc_sweep may have already removed all dyn relocs associated
  6749. with local syms for a given section. Also, symbol flags are
  6750. changed by elf_gc_sweep_symbol, confusing the test above. Don't
  6751. report a dynreloc miscount. */
  6752. if (*pp == NULL && info->gc_sections)
  6753. return TRUE;
  6754. while ((p = *pp) != NULL)
  6755. {
  6756. if (p->sec == sec)
  6757. {
  6758. if (!must_be_dyn_reloc (info, r_type))
  6759. p->pc_count -= 1;
  6760. p->count -= 1;
  6761. if (p->count == 0)
  6762. *pp = p->next;
  6763. return TRUE;
  6764. }
  6765. pp = &p->next;
  6766. }
  6767. }
  6768. else
  6769. {
  6770. struct ppc_dyn_relocs *p;
  6771. struct ppc_dyn_relocs **pp;
  6772. void *vpp;
  6773. bfd_boolean is_ifunc;
  6774. if (local_syms == NULL)
  6775. sym_sec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
  6776. if (sym_sec == NULL)
  6777. sym_sec = sec;
  6778. vpp = &elf_section_data (sym_sec)->local_dynrel;
  6779. pp = (struct ppc_dyn_relocs **) vpp;
  6780. if (*pp == NULL && info->gc_sections)
  6781. return TRUE;
  6782. is_ifunc = ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC;
  6783. while ((p = *pp) != NULL)
  6784. {
  6785. if (p->sec == sec && p->ifunc == is_ifunc)
  6786. {
  6787. p->count -= 1;
  6788. if (p->count == 0)
  6789. *pp = p->next;
  6790. return TRUE;
  6791. }
  6792. pp = &p->next;
  6793. }
  6794. }
  6795. info->callbacks->einfo (_("%P: dynreloc miscount for %B, section %A\n"),
  6796. sec->owner, sec);
  6797. bfd_set_error (bfd_error_bad_value);
  6798. return FALSE;
  6799. }
  6800. /* Remove unused Official Procedure Descriptor entries. Currently we
  6801. only remove those associated with functions in discarded link-once
  6802. sections, or weakly defined functions that have been overridden. It
  6803. would be possible to remove many more entries for statically linked
  6804. applications. */
  6805. bfd_boolean
  6806. ppc64_elf_edit_opd (struct bfd_link_info *info)
  6807. {
  6808. bfd *ibfd;
  6809. bfd_boolean some_edited = FALSE;
  6810. asection *need_pad = NULL;
  6811. struct ppc_link_hash_table *htab;
  6812. htab = ppc_hash_table (info);
  6813. if (htab == NULL)
  6814. return FALSE;
  6815. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  6816. {
  6817. asection *sec;
  6818. Elf_Internal_Rela *relstart, *rel, *relend;
  6819. Elf_Internal_Shdr *symtab_hdr;
  6820. Elf_Internal_Sym *local_syms;
  6821. struct _opd_sec_data *opd;
  6822. bfd_boolean need_edit, add_aux_fields, broken;
  6823. bfd_size_type cnt_16b = 0;
  6824. if (!is_ppc64_elf (ibfd))
  6825. continue;
  6826. sec = bfd_get_section_by_name (ibfd, ".opd");
  6827. if (sec == NULL || sec->size == 0)
  6828. continue;
  6829. if (sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
  6830. continue;
  6831. if (sec->output_section == bfd_abs_section_ptr)
  6832. continue;
  6833. /* Look through the section relocs. */
  6834. if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0)
  6835. continue;
  6836. local_syms = NULL;
  6837. symtab_hdr = &elf_symtab_hdr (ibfd);
  6838. /* Read the relocations. */
  6839. relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
  6840. info->keep_memory);
  6841. if (relstart == NULL)
  6842. return FALSE;
  6843. /* First run through the relocs to check they are sane, and to
  6844. determine whether we need to edit this opd section. */
  6845. need_edit = FALSE;
  6846. broken = FALSE;
  6847. need_pad = sec;
  6848. relend = relstart + sec->reloc_count;
  6849. for (rel = relstart; rel < relend; )
  6850. {
  6851. enum elf_ppc64_reloc_type r_type;
  6852. unsigned long r_symndx;
  6853. asection *sym_sec;
  6854. struct elf_link_hash_entry *h;
  6855. Elf_Internal_Sym *sym;
  6856. bfd_vma offset;
  6857. /* .opd contains an array of 16 or 24 byte entries. We're
  6858. only interested in the reloc pointing to a function entry
  6859. point. */
  6860. offset = rel->r_offset;
  6861. if (rel + 1 == relend
  6862. || rel[1].r_offset != offset + 8)
  6863. {
  6864. /* If someone messes with .opd alignment then after a
  6865. "ld -r" we might have padding in the middle of .opd.
  6866. Also, there's nothing to prevent someone putting
  6867. something silly in .opd with the assembler. No .opd
  6868. optimization for them! */
  6869. broken_opd:
  6870. (*_bfd_error_handler)
  6871. (_("%B: .opd is not a regular array of opd entries"), ibfd);
  6872. broken = TRUE;
  6873. break;
  6874. }
  6875. if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64
  6876. || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC)
  6877. {
  6878. (*_bfd_error_handler)
  6879. (_("%B: unexpected reloc type %u in .opd section"),
  6880. ibfd, r_type);
  6881. broken = TRUE;
  6882. break;
  6883. }
  6884. r_symndx = ELF64_R_SYM (rel->r_info);
  6885. if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
  6886. r_symndx, ibfd))
  6887. goto error_ret;
  6888. if (sym_sec == NULL || sym_sec->owner == NULL)
  6889. {
  6890. const char *sym_name;
  6891. if (h != NULL)
  6892. sym_name = h->root.root.string;
  6893. else
  6894. sym_name = bfd_elf_sym_name (ibfd, symtab_hdr, sym,
  6895. sym_sec);
  6896. (*_bfd_error_handler)
  6897. (_("%B: undefined sym `%s' in .opd section"),
  6898. ibfd, sym_name);
  6899. broken = TRUE;
  6900. break;
  6901. }
  6902. /* opd entries are always for functions defined in the
  6903. current input bfd. If the symbol isn't defined in the
  6904. input bfd, then we won't be using the function in this
  6905. bfd; It must be defined in a linkonce section in another
  6906. bfd, or is weak. It's also possible that we are
  6907. discarding the function due to a linker script /DISCARD/,
  6908. which we test for via the output_section. */
  6909. if (sym_sec->owner != ibfd
  6910. || sym_sec->output_section == bfd_abs_section_ptr)
  6911. need_edit = TRUE;
  6912. rel += 2;
  6913. if (rel + 1 == relend
  6914. || (rel + 2 < relend
  6915. && ELF64_R_TYPE (rel[2].r_info) == R_PPC64_TOC))
  6916. ++rel;
  6917. if (rel == relend)
  6918. {
  6919. if (sec->size == offset + 24)
  6920. {
  6921. need_pad = NULL;
  6922. break;
  6923. }
  6924. if (sec->size == offset + 16)
  6925. {
  6926. cnt_16b++;
  6927. break;
  6928. }
  6929. goto broken_opd;
  6930. }
  6931. else if (rel + 1 < relend
  6932. && ELF64_R_TYPE (rel[0].r_info) == R_PPC64_ADDR64
  6933. && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOC)
  6934. {
  6935. if (rel[0].r_offset == offset + 16)
  6936. cnt_16b++;
  6937. else if (rel[0].r_offset != offset + 24)
  6938. goto broken_opd;
  6939. }
  6940. else
  6941. goto broken_opd;
  6942. }
  6943. add_aux_fields = htab->params->non_overlapping_opd && cnt_16b > 0;
  6944. if (!broken && (need_edit || add_aux_fields))
  6945. {
  6946. Elf_Internal_Rela *write_rel;
  6947. Elf_Internal_Shdr *rel_hdr;
  6948. bfd_byte *rptr, *wptr;
  6949. bfd_byte *new_contents;
  6950. bfd_size_type amt;
  6951. new_contents = NULL;
  6952. amt = OPD_NDX (sec->size) * sizeof (long);
  6953. opd = &ppc64_elf_section_data (sec)->u.opd;
  6954. opd->adjust = bfd_zalloc (sec->owner, amt);
  6955. if (opd->adjust == NULL)
  6956. return FALSE;
  6957. ppc64_elf_section_data (sec)->sec_type = sec_opd;
  6958. /* This seems a waste of time as input .opd sections are all
  6959. zeros as generated by gcc, but I suppose there's no reason
  6960. this will always be so. We might start putting something in
  6961. the third word of .opd entries. */
  6962. if ((sec->flags & SEC_IN_MEMORY) == 0)
  6963. {
  6964. bfd_byte *loc;
  6965. if (!bfd_malloc_and_get_section (ibfd, sec, &loc))
  6966. {
  6967. if (loc != NULL)
  6968. free (loc);
  6969. error_ret:
  6970. if (local_syms != NULL
  6971. && symtab_hdr->contents != (unsigned char *) local_syms)
  6972. free (local_syms);
  6973. if (elf_section_data (sec)->relocs != relstart)
  6974. free (relstart);
  6975. return FALSE;
  6976. }
  6977. sec->contents = loc;
  6978. sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
  6979. }
  6980. elf_section_data (sec)->relocs = relstart;
  6981. new_contents = sec->contents;
  6982. if (add_aux_fields)
  6983. {
  6984. new_contents = bfd_malloc (sec->size + cnt_16b * 8);
  6985. if (new_contents == NULL)
  6986. return FALSE;
  6987. need_pad = NULL;
  6988. }
  6989. wptr = new_contents;
  6990. rptr = sec->contents;
  6991. write_rel = relstart;
  6992. for (rel = relstart; rel < relend; )
  6993. {
  6994. unsigned long r_symndx;
  6995. asection *sym_sec;
  6996. struct elf_link_hash_entry *h;
  6997. struct ppc_link_hash_entry *fdh = NULL;
  6998. Elf_Internal_Sym *sym;
  6999. long opd_ent_size;
  7000. Elf_Internal_Rela *next_rel;
  7001. bfd_boolean skip;
  7002. r_symndx = ELF64_R_SYM (rel->r_info);
  7003. if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
  7004. r_symndx, ibfd))
  7005. goto error_ret;
  7006. next_rel = rel + 2;
  7007. if (next_rel + 1 == relend
  7008. || (next_rel + 2 < relend
  7009. && ELF64_R_TYPE (next_rel[2].r_info) == R_PPC64_TOC))
  7010. ++next_rel;
  7011. /* See if the .opd entry is full 24 byte or
  7012. 16 byte (with fd_aux entry overlapped with next
  7013. fd_func). */
  7014. opd_ent_size = 24;
  7015. if (next_rel == relend)
  7016. {
  7017. if (sec->size == rel->r_offset + 16)
  7018. opd_ent_size = 16;
  7019. }
  7020. else if (next_rel->r_offset == rel->r_offset + 16)
  7021. opd_ent_size = 16;
  7022. if (h != NULL
  7023. && h->root.root.string[0] == '.')
  7024. {
  7025. fdh = lookup_fdh ((struct ppc_link_hash_entry *) h, htab);
  7026. if (fdh != NULL
  7027. && fdh->elf.root.type != bfd_link_hash_defined
  7028. && fdh->elf.root.type != bfd_link_hash_defweak)
  7029. fdh = NULL;
  7030. }
  7031. skip = (sym_sec->owner != ibfd
  7032. || sym_sec->output_section == bfd_abs_section_ptr);
  7033. if (skip)
  7034. {
  7035. if (fdh != NULL && sym_sec->owner == ibfd)
  7036. {
  7037. /* Arrange for the function descriptor sym
  7038. to be dropped. */
  7039. fdh->elf.root.u.def.value = 0;
  7040. fdh->elf.root.u.def.section = sym_sec;
  7041. }
  7042. opd->adjust[OPD_NDX (rel->r_offset)] = -1;
  7043. if (NO_OPD_RELOCS || bfd_link_relocatable (info))
  7044. rel = next_rel;
  7045. else
  7046. while (1)
  7047. {
  7048. if (!dec_dynrel_count (rel->r_info, sec, info,
  7049. NULL, h, sym))
  7050. goto error_ret;
  7051. if (++rel == next_rel)
  7052. break;
  7053. r_symndx = ELF64_R_SYM (rel->r_info);
  7054. if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
  7055. r_symndx, ibfd))
  7056. goto error_ret;
  7057. }
  7058. }
  7059. else
  7060. {
  7061. /* We'll be keeping this opd entry. */
  7062. long adjust;
  7063. if (fdh != NULL)
  7064. {
  7065. /* Redefine the function descriptor symbol to
  7066. this location in the opd section. It is
  7067. necessary to update the value here rather
  7068. than using an array of adjustments as we do
  7069. for local symbols, because various places
  7070. in the generic ELF code use the value
  7071. stored in u.def.value. */
  7072. fdh->elf.root.u.def.value = wptr - new_contents;
  7073. fdh->adjust_done = 1;
  7074. }
  7075. /* Local syms are a bit tricky. We could
  7076. tweak them as they can be cached, but
  7077. we'd need to look through the local syms
  7078. for the function descriptor sym which we
  7079. don't have at the moment. So keep an
  7080. array of adjustments. */
  7081. adjust = (wptr - new_contents) - (rptr - sec->contents);
  7082. opd->adjust[OPD_NDX (rel->r_offset)] = adjust;
  7083. if (wptr != rptr)
  7084. memcpy (wptr, rptr, opd_ent_size);
  7085. wptr += opd_ent_size;
  7086. if (add_aux_fields && opd_ent_size == 16)
  7087. {
  7088. memset (wptr, '\0', 8);
  7089. wptr += 8;
  7090. }
  7091. /* We need to adjust any reloc offsets to point to the
  7092. new opd entries. */
  7093. for ( ; rel != next_rel; ++rel)
  7094. {
  7095. rel->r_offset += adjust;
  7096. if (write_rel != rel)
  7097. memcpy (write_rel, rel, sizeof (*rel));
  7098. ++write_rel;
  7099. }
  7100. }
  7101. rptr += opd_ent_size;
  7102. }
  7103. sec->size = wptr - new_contents;
  7104. sec->reloc_count = write_rel - relstart;
  7105. if (add_aux_fields)
  7106. {
  7107. free (sec->contents);
  7108. sec->contents = new_contents;
  7109. }
  7110. /* Fudge the header size too, as this is used later in
  7111. elf_bfd_final_link if we are emitting relocs. */
  7112. rel_hdr = _bfd_elf_single_rel_hdr (sec);
  7113. rel_hdr->sh_size = sec->reloc_count * rel_hdr->sh_entsize;
  7114. some_edited = TRUE;
  7115. }
  7116. else if (elf_section_data (sec)->relocs != relstart)
  7117. free (relstart);
  7118. if (local_syms != NULL
  7119. && symtab_hdr->contents != (unsigned char *) local_syms)
  7120. {
  7121. if (!info->keep_memory)
  7122. free (local_syms);
  7123. else
  7124. symtab_hdr->contents = (unsigned char *) local_syms;
  7125. }
  7126. }
  7127. if (some_edited)
  7128. elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL);
  7129. /* If we are doing a final link and the last .opd entry is just 16 byte
  7130. long, add a 8 byte padding after it. */
  7131. if (need_pad != NULL && !bfd_link_relocatable (info))
  7132. {
  7133. bfd_byte *p;
  7134. if ((need_pad->flags & SEC_IN_MEMORY) == 0)
  7135. {
  7136. BFD_ASSERT (need_pad->size > 0);
  7137. p = bfd_malloc (need_pad->size + 8);
  7138. if (p == NULL)
  7139. return FALSE;
  7140. if (! bfd_get_section_contents (need_pad->owner, need_pad,
  7141. p, 0, need_pad->size))
  7142. return FALSE;
  7143. need_pad->contents = p;
  7144. need_pad->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
  7145. }
  7146. else
  7147. {
  7148. p = bfd_realloc (need_pad->contents, need_pad->size + 8);
  7149. if (p == NULL)
  7150. return FALSE;
  7151. need_pad->contents = p;
  7152. }
  7153. memset (need_pad->contents + need_pad->size, 0, 8);
  7154. need_pad->size += 8;
  7155. }
  7156. return TRUE;
  7157. }
  7158. /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
  7159. asection *
  7160. ppc64_elf_tls_setup (struct bfd_link_info *info)
  7161. {
  7162. struct ppc_link_hash_table *htab;
  7163. htab = ppc_hash_table (info);
  7164. if (htab == NULL)
  7165. return NULL;
  7166. if (abiversion (info->output_bfd) == 1)
  7167. htab->opd_abi = 1;
  7168. if (htab->params->no_multi_toc)
  7169. htab->do_multi_toc = 0;
  7170. else if (!htab->do_multi_toc)
  7171. htab->params->no_multi_toc = 1;
  7172. htab->tls_get_addr = ((struct ppc_link_hash_entry *)
  7173. elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
  7174. FALSE, FALSE, TRUE));
  7175. /* Move dynamic linking info to the function descriptor sym. */
  7176. if (htab->tls_get_addr != NULL)
  7177. func_desc_adjust (&htab->tls_get_addr->elf, info);
  7178. htab->tls_get_addr_fd = ((struct ppc_link_hash_entry *)
  7179. elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
  7180. FALSE, FALSE, TRUE));
  7181. if (htab->params->tls_get_addr_opt)
  7182. {
  7183. struct elf_link_hash_entry *opt, *opt_fd, *tga, *tga_fd;
  7184. opt = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr_opt",
  7185. FALSE, FALSE, TRUE);
  7186. if (opt != NULL)
  7187. func_desc_adjust (opt, info);
  7188. opt_fd = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt",
  7189. FALSE, FALSE, TRUE);
  7190. if (opt_fd != NULL
  7191. && (opt_fd->root.type == bfd_link_hash_defined
  7192. || opt_fd->root.type == bfd_link_hash_defweak))
  7193. {
  7194. /* If glibc supports an optimized __tls_get_addr call stub,
  7195. signalled by the presence of __tls_get_addr_opt, and we'll
  7196. be calling __tls_get_addr via a plt call stub, then
  7197. make __tls_get_addr point to __tls_get_addr_opt. */
  7198. tga_fd = &htab->tls_get_addr_fd->elf;
  7199. if (htab->elf.dynamic_sections_created
  7200. && tga_fd != NULL
  7201. && (tga_fd->type == STT_FUNC
  7202. || tga_fd->needs_plt)
  7203. && !(SYMBOL_CALLS_LOCAL (info, tga_fd)
  7204. || (ELF_ST_VISIBILITY (tga_fd->other) != STV_DEFAULT
  7205. && tga_fd->root.type == bfd_link_hash_undefweak)))
  7206. {
  7207. struct plt_entry *ent;
  7208. for (ent = tga_fd->plt.plist; ent != NULL; ent = ent->next)
  7209. if (ent->plt.refcount > 0)
  7210. break;
  7211. if (ent != NULL)
  7212. {
  7213. tga_fd->root.type = bfd_link_hash_indirect;
  7214. tga_fd->root.u.i.link = &opt_fd->root;
  7215. ppc64_elf_copy_indirect_symbol (info, opt_fd, tga_fd);
  7216. if (opt_fd->dynindx != -1)
  7217. {
  7218. /* Use __tls_get_addr_opt in dynamic relocations. */
  7219. opt_fd->dynindx = -1;
  7220. _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
  7221. opt_fd->dynstr_index);
  7222. if (!bfd_elf_link_record_dynamic_symbol (info, opt_fd))
  7223. return NULL;
  7224. }
  7225. htab->tls_get_addr_fd = (struct ppc_link_hash_entry *) opt_fd;
  7226. tga = &htab->tls_get_addr->elf;
  7227. if (opt != NULL && tga != NULL)
  7228. {
  7229. tga->root.type = bfd_link_hash_indirect;
  7230. tga->root.u.i.link = &opt->root;
  7231. ppc64_elf_copy_indirect_symbol (info, opt, tga);
  7232. _bfd_elf_link_hash_hide_symbol (info, opt,
  7233. tga->forced_local);
  7234. htab->tls_get_addr = (struct ppc_link_hash_entry *) opt;
  7235. }
  7236. htab->tls_get_addr_fd->oh = htab->tls_get_addr;
  7237. htab->tls_get_addr_fd->is_func_descriptor = 1;
  7238. if (htab->tls_get_addr != NULL)
  7239. {
  7240. htab->tls_get_addr->oh = htab->tls_get_addr_fd;
  7241. htab->tls_get_addr->is_func = 1;
  7242. }
  7243. }
  7244. }
  7245. }
  7246. else if (htab->params->tls_get_addr_opt < 0)
  7247. htab->params->tls_get_addr_opt = 0;
  7248. }
  7249. return _bfd_elf_tls_setup (info->output_bfd, info);
  7250. }
  7251. /* Return TRUE iff REL is a branch reloc with a global symbol matching
  7252. HASH1 or HASH2. */
  7253. static bfd_boolean
  7254. branch_reloc_hash_match (const bfd *ibfd,
  7255. const Elf_Internal_Rela *rel,
  7256. const struct ppc_link_hash_entry *hash1,
  7257. const struct ppc_link_hash_entry *hash2)
  7258. {
  7259. Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
  7260. enum elf_ppc64_reloc_type r_type = ELF64_R_TYPE (rel->r_info);
  7261. unsigned int r_symndx = ELF64_R_SYM (rel->r_info);
  7262. if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type))
  7263. {
  7264. struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
  7265. struct elf_link_hash_entry *h;
  7266. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  7267. h = elf_follow_link (h);
  7268. if (h == &hash1->elf || h == &hash2->elf)
  7269. return TRUE;
  7270. }
  7271. return FALSE;
  7272. }
  7273. /* Run through all the TLS relocs looking for optimization
  7274. opportunities. The linker has been hacked (see ppc64elf.em) to do
  7275. a preliminary section layout so that we know the TLS segment
  7276. offsets. We can't optimize earlier because some optimizations need
  7277. to know the tp offset, and we need to optimize before allocating
  7278. dynamic relocations. */
  7279. bfd_boolean
  7280. ppc64_elf_tls_optimize (struct bfd_link_info *info)
  7281. {
  7282. bfd *ibfd;
  7283. asection *sec;
  7284. struct ppc_link_hash_table *htab;
  7285. unsigned char *toc_ref;
  7286. int pass;
  7287. if (!bfd_link_executable (info))
  7288. return TRUE;
  7289. htab = ppc_hash_table (info);
  7290. if (htab == NULL)
  7291. return FALSE;
  7292. /* Make two passes over the relocs. On the first pass, mark toc
  7293. entries involved with tls relocs, and check that tls relocs
  7294. involved in setting up a tls_get_addr call are indeed followed by
  7295. such a call. If they are not, we can't do any tls optimization.
  7296. On the second pass twiddle tls_mask flags to notify
  7297. relocate_section that optimization can be done, and adjust got
  7298. and plt refcounts. */
  7299. toc_ref = NULL;
  7300. for (pass = 0; pass < 2; ++pass)
  7301. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  7302. {
  7303. Elf_Internal_Sym *locsyms = NULL;
  7304. asection *toc = bfd_get_section_by_name (ibfd, ".toc");
  7305. for (sec = ibfd->sections; sec != NULL; sec = sec->next)
  7306. if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
  7307. {
  7308. Elf_Internal_Rela *relstart, *rel, *relend;
  7309. bfd_boolean found_tls_get_addr_arg = 0;
  7310. /* Read the relocations. */
  7311. relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
  7312. info->keep_memory);
  7313. if (relstart == NULL)
  7314. {
  7315. free (toc_ref);
  7316. return FALSE;
  7317. }
  7318. relend = relstart + sec->reloc_count;
  7319. for (rel = relstart; rel < relend; rel++)
  7320. {
  7321. enum elf_ppc64_reloc_type r_type;
  7322. unsigned long r_symndx;
  7323. struct elf_link_hash_entry *h;
  7324. Elf_Internal_Sym *sym;
  7325. asection *sym_sec;
  7326. unsigned char *tls_mask;
  7327. unsigned char tls_set, tls_clear, tls_type = 0;
  7328. bfd_vma value;
  7329. bfd_boolean ok_tprel, is_local;
  7330. long toc_ref_index = 0;
  7331. int expecting_tls_get_addr = 0;
  7332. bfd_boolean ret = FALSE;
  7333. r_symndx = ELF64_R_SYM (rel->r_info);
  7334. if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms,
  7335. r_symndx, ibfd))
  7336. {
  7337. err_free_rel:
  7338. if (elf_section_data (sec)->relocs != relstart)
  7339. free (relstart);
  7340. if (toc_ref != NULL)
  7341. free (toc_ref);
  7342. if (locsyms != NULL
  7343. && (elf_symtab_hdr (ibfd).contents
  7344. != (unsigned char *) locsyms))
  7345. free (locsyms);
  7346. return ret;
  7347. }
  7348. if (h != NULL)
  7349. {
  7350. if (h->root.type == bfd_link_hash_defined
  7351. || h->root.type == bfd_link_hash_defweak)
  7352. value = h->root.u.def.value;
  7353. else if (h->root.type == bfd_link_hash_undefweak)
  7354. value = 0;
  7355. else
  7356. {
  7357. found_tls_get_addr_arg = 0;
  7358. continue;
  7359. }
  7360. }
  7361. else
  7362. /* Symbols referenced by TLS relocs must be of type
  7363. STT_TLS. So no need for .opd local sym adjust. */
  7364. value = sym->st_value;
  7365. ok_tprel = FALSE;
  7366. is_local = FALSE;
  7367. if (h == NULL
  7368. || !h->def_dynamic)
  7369. {
  7370. is_local = TRUE;
  7371. if (h != NULL
  7372. && h->root.type == bfd_link_hash_undefweak)
  7373. ok_tprel = TRUE;
  7374. else
  7375. {
  7376. value += sym_sec->output_offset;
  7377. value += sym_sec->output_section->vma;
  7378. value -= htab->elf.tls_sec->vma;
  7379. ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31)
  7380. < (bfd_vma) 1 << 32);
  7381. }
  7382. }
  7383. r_type = ELF64_R_TYPE (rel->r_info);
  7384. /* If this section has old-style __tls_get_addr calls
  7385. without marker relocs, then check that each
  7386. __tls_get_addr call reloc is preceded by a reloc
  7387. that conceivably belongs to the __tls_get_addr arg
  7388. setup insn. If we don't find matching arg setup
  7389. relocs, don't do any tls optimization. */
  7390. if (pass == 0
  7391. && sec->has_tls_get_addr_call
  7392. && h != NULL
  7393. && (h == &htab->tls_get_addr->elf
  7394. || h == &htab->tls_get_addr_fd->elf)
  7395. && !found_tls_get_addr_arg
  7396. && is_branch_reloc (r_type))
  7397. {
  7398. info->callbacks->minfo (_("%H __tls_get_addr lost arg, "
  7399. "TLS optimization disabled\n"),
  7400. ibfd, sec, rel->r_offset);
  7401. ret = TRUE;
  7402. goto err_free_rel;
  7403. }
  7404. found_tls_get_addr_arg = 0;
  7405. switch (r_type)
  7406. {
  7407. case R_PPC64_GOT_TLSLD16:
  7408. case R_PPC64_GOT_TLSLD16_LO:
  7409. expecting_tls_get_addr = 1;
  7410. found_tls_get_addr_arg = 1;
  7411. /* Fall thru */
  7412. case R_PPC64_GOT_TLSLD16_HI:
  7413. case R_PPC64_GOT_TLSLD16_HA:
  7414. /* These relocs should never be against a symbol
  7415. defined in a shared lib. Leave them alone if
  7416. that turns out to be the case. */
  7417. if (!is_local)
  7418. continue;
  7419. /* LD -> LE */
  7420. tls_set = 0;
  7421. tls_clear = TLS_LD;
  7422. tls_type = TLS_TLS | TLS_LD;
  7423. break;
  7424. case R_PPC64_GOT_TLSGD16:
  7425. case R_PPC64_GOT_TLSGD16_LO:
  7426. expecting_tls_get_addr = 1;
  7427. found_tls_get_addr_arg = 1;
  7428. /* Fall thru */
  7429. case R_PPC64_GOT_TLSGD16_HI:
  7430. case R_PPC64_GOT_TLSGD16_HA:
  7431. if (ok_tprel)
  7432. /* GD -> LE */
  7433. tls_set = 0;
  7434. else
  7435. /* GD -> IE */
  7436. tls_set = TLS_TLS | TLS_TPRELGD;
  7437. tls_clear = TLS_GD;
  7438. tls_type = TLS_TLS | TLS_GD;
  7439. break;
  7440. case R_PPC64_GOT_TPREL16_DS:
  7441. case R_PPC64_GOT_TPREL16_LO_DS:
  7442. case R_PPC64_GOT_TPREL16_HI:
  7443. case R_PPC64_GOT_TPREL16_HA:
  7444. if (ok_tprel)
  7445. {
  7446. /* IE -> LE */
  7447. tls_set = 0;
  7448. tls_clear = TLS_TPREL;
  7449. tls_type = TLS_TLS | TLS_TPREL;
  7450. break;
  7451. }
  7452. continue;
  7453. case R_PPC64_TLSGD:
  7454. case R_PPC64_TLSLD:
  7455. found_tls_get_addr_arg = 1;
  7456. /* Fall thru */
  7457. case R_PPC64_TLS:
  7458. case R_PPC64_TOC16:
  7459. case R_PPC64_TOC16_LO:
  7460. if (sym_sec == NULL || sym_sec != toc)
  7461. continue;
  7462. /* Mark this toc entry as referenced by a TLS
  7463. code sequence. We can do that now in the
  7464. case of R_PPC64_TLS, and after checking for
  7465. tls_get_addr for the TOC16 relocs. */
  7466. if (toc_ref == NULL)
  7467. toc_ref = bfd_zmalloc (toc->output_section->rawsize / 8);
  7468. if (toc_ref == NULL)
  7469. goto err_free_rel;
  7470. if (h != NULL)
  7471. value = h->root.u.def.value;
  7472. else
  7473. value = sym->st_value;
  7474. value += rel->r_addend;
  7475. if (value % 8 != 0)
  7476. continue;
  7477. BFD_ASSERT (value < toc->size
  7478. && toc->output_offset % 8 == 0);
  7479. toc_ref_index = (value + toc->output_offset) / 8;
  7480. if (r_type == R_PPC64_TLS
  7481. || r_type == R_PPC64_TLSGD
  7482. || r_type == R_PPC64_TLSLD)
  7483. {
  7484. toc_ref[toc_ref_index] = 1;
  7485. continue;
  7486. }
  7487. if (pass != 0 && toc_ref[toc_ref_index] == 0)
  7488. continue;
  7489. tls_set = 0;
  7490. tls_clear = 0;
  7491. expecting_tls_get_addr = 2;
  7492. break;
  7493. case R_PPC64_TPREL64:
  7494. if (pass == 0
  7495. || sec != toc
  7496. || toc_ref == NULL
  7497. || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
  7498. continue;
  7499. if (ok_tprel)
  7500. {
  7501. /* IE -> LE */
  7502. tls_set = TLS_EXPLICIT;
  7503. tls_clear = TLS_TPREL;
  7504. break;
  7505. }
  7506. continue;
  7507. case R_PPC64_DTPMOD64:
  7508. if (pass == 0
  7509. || sec != toc
  7510. || toc_ref == NULL
  7511. || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
  7512. continue;
  7513. if (rel + 1 < relend
  7514. && (rel[1].r_info
  7515. == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64))
  7516. && rel[1].r_offset == rel->r_offset + 8)
  7517. {
  7518. if (ok_tprel)
  7519. /* GD -> LE */
  7520. tls_set = TLS_EXPLICIT | TLS_GD;
  7521. else
  7522. /* GD -> IE */
  7523. tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD;
  7524. tls_clear = TLS_GD;
  7525. }
  7526. else
  7527. {
  7528. if (!is_local)
  7529. continue;
  7530. /* LD -> LE */
  7531. tls_set = TLS_EXPLICIT;
  7532. tls_clear = TLS_LD;
  7533. }
  7534. break;
  7535. default:
  7536. continue;
  7537. }
  7538. if (pass == 0)
  7539. {
  7540. if (!expecting_tls_get_addr
  7541. || !sec->has_tls_get_addr_call)
  7542. continue;
  7543. if (rel + 1 < relend
  7544. && branch_reloc_hash_match (ibfd, rel + 1,
  7545. htab->tls_get_addr,
  7546. htab->tls_get_addr_fd))
  7547. {
  7548. if (expecting_tls_get_addr == 2)
  7549. {
  7550. /* Check for toc tls entries. */
  7551. unsigned char *toc_tls;
  7552. int retval;
  7553. retval = get_tls_mask (&toc_tls, NULL, NULL,
  7554. &locsyms,
  7555. rel, ibfd);
  7556. if (retval == 0)
  7557. goto err_free_rel;
  7558. if (toc_tls != NULL)
  7559. {
  7560. if ((*toc_tls & (TLS_GD | TLS_LD)) != 0)
  7561. found_tls_get_addr_arg = 1;
  7562. if (retval > 1)
  7563. toc_ref[toc_ref_index] = 1;
  7564. }
  7565. }
  7566. continue;
  7567. }
  7568. if (expecting_tls_get_addr != 1)
  7569. continue;
  7570. /* Uh oh, we didn't find the expected call. We
  7571. could just mark this symbol to exclude it
  7572. from tls optimization but it's safer to skip
  7573. the entire optimization. */
  7574. info->callbacks->minfo (_("%H arg lost __tls_get_addr, "
  7575. "TLS optimization disabled\n"),
  7576. ibfd, sec, rel->r_offset);
  7577. ret = TRUE;
  7578. goto err_free_rel;
  7579. }
  7580. if (expecting_tls_get_addr && htab->tls_get_addr != NULL)
  7581. {
  7582. struct plt_entry *ent;
  7583. for (ent = htab->tls_get_addr->elf.plt.plist;
  7584. ent != NULL;
  7585. ent = ent->next)
  7586. if (ent->addend == 0)
  7587. {
  7588. if (ent->plt.refcount > 0)
  7589. {
  7590. ent->plt.refcount -= 1;
  7591. expecting_tls_get_addr = 0;
  7592. }
  7593. break;
  7594. }
  7595. }
  7596. if (expecting_tls_get_addr && htab->tls_get_addr_fd != NULL)
  7597. {
  7598. struct plt_entry *ent;
  7599. for (ent = htab->tls_get_addr_fd->elf.plt.plist;
  7600. ent != NULL;
  7601. ent = ent->next)
  7602. if (ent->addend == 0)
  7603. {
  7604. if (ent->plt.refcount > 0)
  7605. ent->plt.refcount -= 1;
  7606. break;
  7607. }
  7608. }
  7609. if (tls_clear == 0)
  7610. continue;
  7611. if ((tls_set & TLS_EXPLICIT) == 0)
  7612. {
  7613. struct got_entry *ent;
  7614. /* Adjust got entry for this reloc. */
  7615. if (h != NULL)
  7616. ent = h->got.glist;
  7617. else
  7618. ent = elf_local_got_ents (ibfd)[r_symndx];
  7619. for (; ent != NULL; ent = ent->next)
  7620. if (ent->addend == rel->r_addend
  7621. && ent->owner == ibfd
  7622. && ent->tls_type == tls_type)
  7623. break;
  7624. if (ent == NULL)
  7625. abort ();
  7626. if (tls_set == 0)
  7627. {
  7628. /* We managed to get rid of a got entry. */
  7629. if (ent->got.refcount > 0)
  7630. ent->got.refcount -= 1;
  7631. }
  7632. }
  7633. else
  7634. {
  7635. /* If we got rid of a DTPMOD/DTPREL reloc pair then
  7636. we'll lose one or two dyn relocs. */
  7637. if (!dec_dynrel_count (rel->r_info, sec, info,
  7638. NULL, h, sym))
  7639. return FALSE;
  7640. if (tls_set == (TLS_EXPLICIT | TLS_GD))
  7641. {
  7642. if (!dec_dynrel_count ((rel + 1)->r_info, sec, info,
  7643. NULL, h, sym))
  7644. return FALSE;
  7645. }
  7646. }
  7647. *tls_mask |= tls_set;
  7648. *tls_mask &= ~tls_clear;
  7649. }
  7650. if (elf_section_data (sec)->relocs != relstart)
  7651. free (relstart);
  7652. }
  7653. if (locsyms != NULL
  7654. && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms))
  7655. {
  7656. if (!info->keep_memory)
  7657. free (locsyms);
  7658. else
  7659. elf_symtab_hdr (ibfd).contents = (unsigned char *) locsyms;
  7660. }
  7661. }
  7662. if (toc_ref != NULL)
  7663. free (toc_ref);
  7664. return TRUE;
  7665. }
  7666. /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
  7667. the values of any global symbols in a toc section that has been
  7668. edited. Globals in toc sections should be a rarity, so this function
  7669. sets a flag if any are found in toc sections other than the one just
  7670. edited, so that futher hash table traversals can be avoided. */
  7671. struct adjust_toc_info
  7672. {
  7673. asection *toc;
  7674. unsigned long *skip;
  7675. bfd_boolean global_toc_syms;
  7676. };
  7677. enum toc_skip_enum { ref_from_discarded = 1, can_optimize = 2 };
  7678. static bfd_boolean
  7679. adjust_toc_syms (struct elf_link_hash_entry *h, void *inf)
  7680. {
  7681. struct ppc_link_hash_entry *eh;
  7682. struct adjust_toc_info *toc_inf = (struct adjust_toc_info *) inf;
  7683. unsigned long i;
  7684. if (h->root.type != bfd_link_hash_defined
  7685. && h->root.type != bfd_link_hash_defweak)
  7686. return TRUE;
  7687. eh = (struct ppc_link_hash_entry *) h;
  7688. if (eh->adjust_done)
  7689. return TRUE;
  7690. if (eh->elf.root.u.def.section == toc_inf->toc)
  7691. {
  7692. if (eh->elf.root.u.def.value > toc_inf->toc->rawsize)
  7693. i = toc_inf->toc->rawsize >> 3;
  7694. else
  7695. i = eh->elf.root.u.def.value >> 3;
  7696. if ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0)
  7697. {
  7698. (*_bfd_error_handler)
  7699. (_("%s defined on removed toc entry"), eh->elf.root.root.string);
  7700. do
  7701. ++i;
  7702. while ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0);
  7703. eh->elf.root.u.def.value = (bfd_vma) i << 3;
  7704. }
  7705. eh->elf.root.u.def.value -= toc_inf->skip[i];
  7706. eh->adjust_done = 1;
  7707. }
  7708. else if (strcmp (eh->elf.root.u.def.section->name, ".toc") == 0)
  7709. toc_inf->global_toc_syms = TRUE;
  7710. return TRUE;
  7711. }
  7712. /* Return TRUE iff INSN is one we expect on a _LO variety toc/got reloc. */
  7713. static bfd_boolean
  7714. ok_lo_toc_insn (unsigned int insn)
  7715. {
  7716. return ((insn & (0x3f << 26)) == 14u << 26 /* addi */
  7717. || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
  7718. || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
  7719. || (insn & (0x3f << 26)) == 36u << 26 /* stw */
  7720. || (insn & (0x3f << 26)) == 38u << 26 /* stb */
  7721. || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
  7722. || (insn & (0x3f << 26)) == 42u << 26 /* lha */
  7723. || (insn & (0x3f << 26)) == 44u << 26 /* sth */
  7724. || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
  7725. || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
  7726. || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
  7727. || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
  7728. || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
  7729. || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
  7730. || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
  7731. && (insn & 3) != 1)
  7732. || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */
  7733. && ((insn & 3) == 0 || (insn & 3) == 3))
  7734. || (insn & (0x3f << 26)) == 12u << 26 /* addic */);
  7735. }
  7736. /* Examine all relocs referencing .toc sections in order to remove
  7737. unused .toc entries. */
  7738. bfd_boolean
  7739. ppc64_elf_edit_toc (struct bfd_link_info *info)
  7740. {
  7741. bfd *ibfd;
  7742. struct adjust_toc_info toc_inf;
  7743. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  7744. htab->do_toc_opt = 1;
  7745. toc_inf.global_toc_syms = TRUE;
  7746. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  7747. {
  7748. asection *toc, *sec;
  7749. Elf_Internal_Shdr *symtab_hdr;
  7750. Elf_Internal_Sym *local_syms;
  7751. Elf_Internal_Rela *relstart, *rel, *toc_relocs;
  7752. unsigned long *skip, *drop;
  7753. unsigned char *used;
  7754. unsigned char *keep, last, some_unused;
  7755. if (!is_ppc64_elf (ibfd))
  7756. continue;
  7757. toc = bfd_get_section_by_name (ibfd, ".toc");
  7758. if (toc == NULL
  7759. || toc->size == 0
  7760. || toc->sec_info_type == SEC_INFO_TYPE_JUST_SYMS
  7761. || discarded_section (toc))
  7762. continue;
  7763. toc_relocs = NULL;
  7764. local_syms = NULL;
  7765. symtab_hdr = &elf_symtab_hdr (ibfd);
  7766. /* Look at sections dropped from the final link. */
  7767. skip = NULL;
  7768. relstart = NULL;
  7769. for (sec = ibfd->sections; sec != NULL; sec = sec->next)
  7770. {
  7771. if (sec->reloc_count == 0
  7772. || !discarded_section (sec)
  7773. || get_opd_info (sec)
  7774. || (sec->flags & SEC_ALLOC) == 0
  7775. || (sec->flags & SEC_DEBUGGING) != 0)
  7776. continue;
  7777. relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, FALSE);
  7778. if (relstart == NULL)
  7779. goto error_ret;
  7780. /* Run through the relocs to see which toc entries might be
  7781. unused. */
  7782. for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
  7783. {
  7784. enum elf_ppc64_reloc_type r_type;
  7785. unsigned long r_symndx;
  7786. asection *sym_sec;
  7787. struct elf_link_hash_entry *h;
  7788. Elf_Internal_Sym *sym;
  7789. bfd_vma val;
  7790. r_type = ELF64_R_TYPE (rel->r_info);
  7791. switch (r_type)
  7792. {
  7793. default:
  7794. continue;
  7795. case R_PPC64_TOC16:
  7796. case R_PPC64_TOC16_LO:
  7797. case R_PPC64_TOC16_HI:
  7798. case R_PPC64_TOC16_HA:
  7799. case R_PPC64_TOC16_DS:
  7800. case R_PPC64_TOC16_LO_DS:
  7801. break;
  7802. }
  7803. r_symndx = ELF64_R_SYM (rel->r_info);
  7804. if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
  7805. r_symndx, ibfd))
  7806. goto error_ret;
  7807. if (sym_sec != toc)
  7808. continue;
  7809. if (h != NULL)
  7810. val = h->root.u.def.value;
  7811. else
  7812. val = sym->st_value;
  7813. val += rel->r_addend;
  7814. if (val >= toc->size)
  7815. continue;
  7816. /* Anything in the toc ought to be aligned to 8 bytes.
  7817. If not, don't mark as unused. */
  7818. if (val & 7)
  7819. continue;
  7820. if (skip == NULL)
  7821. {
  7822. skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8);
  7823. if (skip == NULL)
  7824. goto error_ret;
  7825. }
  7826. skip[val >> 3] = ref_from_discarded;
  7827. }
  7828. if (elf_section_data (sec)->relocs != relstart)
  7829. free (relstart);
  7830. }
  7831. /* For largetoc loads of address constants, we can convert
  7832. . addis rx,2,addr@got@ha
  7833. . ld ry,addr@got@l(rx)
  7834. to
  7835. . addis rx,2,addr@toc@ha
  7836. . addi ry,rx,addr@toc@l
  7837. when addr is within 2G of the toc pointer. This then means
  7838. that the word storing "addr" in the toc is no longer needed. */
  7839. if (!ppc64_elf_tdata (ibfd)->has_small_toc_reloc
  7840. && toc->output_section->rawsize < (bfd_vma) 1 << 31
  7841. && toc->reloc_count != 0)
  7842. {
  7843. /* Read toc relocs. */
  7844. toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
  7845. info->keep_memory);
  7846. if (toc_relocs == NULL)
  7847. goto error_ret;
  7848. for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
  7849. {
  7850. enum elf_ppc64_reloc_type r_type;
  7851. unsigned long r_symndx;
  7852. asection *sym_sec;
  7853. struct elf_link_hash_entry *h;
  7854. Elf_Internal_Sym *sym;
  7855. bfd_vma val, addr;
  7856. r_type = ELF64_R_TYPE (rel->r_info);
  7857. if (r_type != R_PPC64_ADDR64)
  7858. continue;
  7859. r_symndx = ELF64_R_SYM (rel->r_info);
  7860. if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
  7861. r_symndx, ibfd))
  7862. goto error_ret;
  7863. if (sym_sec == NULL
  7864. || discarded_section (sym_sec))
  7865. continue;
  7866. if (!SYMBOL_REFERENCES_LOCAL (info, h))
  7867. continue;
  7868. if (h != NULL)
  7869. {
  7870. if (h->type == STT_GNU_IFUNC)
  7871. continue;
  7872. val = h->root.u.def.value;
  7873. }
  7874. else
  7875. {
  7876. if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
  7877. continue;
  7878. val = sym->st_value;
  7879. }
  7880. val += rel->r_addend;
  7881. val += sym_sec->output_section->vma + sym_sec->output_offset;
  7882. /* We don't yet know the exact toc pointer value, but we
  7883. know it will be somewhere in the toc section. Don't
  7884. optimize if the difference from any possible toc
  7885. pointer is outside [ff..f80008000, 7fff7fff]. */
  7886. addr = toc->output_section->vma + TOC_BASE_OFF;
  7887. if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32)
  7888. continue;
  7889. addr = toc->output_section->vma + toc->output_section->rawsize;
  7890. if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32)
  7891. continue;
  7892. if (skip == NULL)
  7893. {
  7894. skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8);
  7895. if (skip == NULL)
  7896. goto error_ret;
  7897. }
  7898. skip[rel->r_offset >> 3]
  7899. |= can_optimize | ((rel - toc_relocs) << 2);
  7900. }
  7901. }
  7902. if (skip == NULL)
  7903. continue;
  7904. used = bfd_zmalloc (sizeof (*used) * (toc->size + 7) / 8);
  7905. if (used == NULL)
  7906. {
  7907. error_ret:
  7908. if (local_syms != NULL
  7909. && symtab_hdr->contents != (unsigned char *) local_syms)
  7910. free (local_syms);
  7911. if (sec != NULL
  7912. && relstart != NULL
  7913. && elf_section_data (sec)->relocs != relstart)
  7914. free (relstart);
  7915. if (toc_relocs != NULL
  7916. && elf_section_data (toc)->relocs != toc_relocs)
  7917. free (toc_relocs);
  7918. if (skip != NULL)
  7919. free (skip);
  7920. return FALSE;
  7921. }
  7922. /* Now check all kept sections that might reference the toc.
  7923. Check the toc itself last. */
  7924. for (sec = (ibfd->sections == toc && toc->next ? toc->next
  7925. : ibfd->sections);
  7926. sec != NULL;
  7927. sec = (sec == toc ? NULL
  7928. : sec->next == NULL ? toc
  7929. : sec->next == toc && toc->next ? toc->next
  7930. : sec->next))
  7931. {
  7932. int repeat;
  7933. if (sec->reloc_count == 0
  7934. || discarded_section (sec)
  7935. || get_opd_info (sec)
  7936. || (sec->flags & SEC_ALLOC) == 0
  7937. || (sec->flags & SEC_DEBUGGING) != 0)
  7938. continue;
  7939. relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
  7940. info->keep_memory);
  7941. if (relstart == NULL)
  7942. {
  7943. free (used);
  7944. goto error_ret;
  7945. }
  7946. /* Mark toc entries referenced as used. */
  7947. do
  7948. {
  7949. repeat = 0;
  7950. for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
  7951. {
  7952. enum elf_ppc64_reloc_type r_type;
  7953. unsigned long r_symndx;
  7954. asection *sym_sec;
  7955. struct elf_link_hash_entry *h;
  7956. Elf_Internal_Sym *sym;
  7957. bfd_vma val;
  7958. enum {no_check, check_lo, check_ha} insn_check;
  7959. r_type = ELF64_R_TYPE (rel->r_info);
  7960. switch (r_type)
  7961. {
  7962. default:
  7963. insn_check = no_check;
  7964. break;
  7965. case R_PPC64_GOT_TLSLD16_HA:
  7966. case R_PPC64_GOT_TLSGD16_HA:
  7967. case R_PPC64_GOT_TPREL16_HA:
  7968. case R_PPC64_GOT_DTPREL16_HA:
  7969. case R_PPC64_GOT16_HA:
  7970. case R_PPC64_TOC16_HA:
  7971. insn_check = check_ha;
  7972. break;
  7973. case R_PPC64_GOT_TLSLD16_LO:
  7974. case R_PPC64_GOT_TLSGD16_LO:
  7975. case R_PPC64_GOT_TPREL16_LO_DS:
  7976. case R_PPC64_GOT_DTPREL16_LO_DS:
  7977. case R_PPC64_GOT16_LO:
  7978. case R_PPC64_GOT16_LO_DS:
  7979. case R_PPC64_TOC16_LO:
  7980. case R_PPC64_TOC16_LO_DS:
  7981. insn_check = check_lo;
  7982. break;
  7983. }
  7984. if (insn_check != no_check)
  7985. {
  7986. bfd_vma off = rel->r_offset & ~3;
  7987. unsigned char buf[4];
  7988. unsigned int insn;
  7989. if (!bfd_get_section_contents (ibfd, sec, buf, off, 4))
  7990. {
  7991. free (used);
  7992. goto error_ret;
  7993. }
  7994. insn = bfd_get_32 (ibfd, buf);
  7995. if (insn_check == check_lo
  7996. ? !ok_lo_toc_insn (insn)
  7997. : ((insn & ((0x3f << 26) | 0x1f << 16))
  7998. != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
  7999. {
  8000. char str[12];
  8001. ppc64_elf_tdata (ibfd)->unexpected_toc_insn = 1;
  8002. sprintf (str, "%#08x", insn);
  8003. info->callbacks->einfo
  8004. (_("%P: %H: toc optimization is not supported for"
  8005. " %s instruction.\n"),
  8006. ibfd, sec, rel->r_offset & ~3, str);
  8007. }
  8008. }
  8009. switch (r_type)
  8010. {
  8011. case R_PPC64_TOC16:
  8012. case R_PPC64_TOC16_LO:
  8013. case R_PPC64_TOC16_HI:
  8014. case R_PPC64_TOC16_HA:
  8015. case R_PPC64_TOC16_DS:
  8016. case R_PPC64_TOC16_LO_DS:
  8017. /* In case we're taking addresses of toc entries. */
  8018. case R_PPC64_ADDR64:
  8019. break;
  8020. default:
  8021. continue;
  8022. }
  8023. r_symndx = ELF64_R_SYM (rel->r_info);
  8024. if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
  8025. r_symndx, ibfd))
  8026. {
  8027. free (used);
  8028. goto error_ret;
  8029. }
  8030. if (sym_sec != toc)
  8031. continue;
  8032. if (h != NULL)
  8033. val = h->root.u.def.value;
  8034. else
  8035. val = sym->st_value;
  8036. val += rel->r_addend;
  8037. if (val >= toc->size)
  8038. continue;
  8039. if ((skip[val >> 3] & can_optimize) != 0)
  8040. {
  8041. bfd_vma off;
  8042. unsigned char opc;
  8043. switch (r_type)
  8044. {
  8045. case R_PPC64_TOC16_HA:
  8046. break;
  8047. case R_PPC64_TOC16_LO_DS:
  8048. off = rel->r_offset;
  8049. off += (bfd_big_endian (ibfd) ? -2 : 3);
  8050. if (!bfd_get_section_contents (ibfd, sec, &opc,
  8051. off, 1))
  8052. {
  8053. free (used);
  8054. goto error_ret;
  8055. }
  8056. if ((opc & (0x3f << 2)) == (58u << 2))
  8057. break;
  8058. /* Fall thru */
  8059. default:
  8060. /* Wrong sort of reloc, or not a ld. We may
  8061. as well clear ref_from_discarded too. */
  8062. skip[val >> 3] = 0;
  8063. }
  8064. }
  8065. if (sec != toc)
  8066. used[val >> 3] = 1;
  8067. /* For the toc section, we only mark as used if this
  8068. entry itself isn't unused. */
  8069. else if ((used[rel->r_offset >> 3]
  8070. || !(skip[rel->r_offset >> 3] & ref_from_discarded))
  8071. && !used[val >> 3])
  8072. {
  8073. /* Do all the relocs again, to catch reference
  8074. chains. */
  8075. repeat = 1;
  8076. used[val >> 3] = 1;
  8077. }
  8078. }
  8079. }
  8080. while (repeat);
  8081. if (elf_section_data (sec)->relocs != relstart)
  8082. free (relstart);
  8083. }
  8084. /* Merge the used and skip arrays. Assume that TOC
  8085. doublewords not appearing as either used or unused belong
  8086. to to an entry more than one doubleword in size. */
  8087. for (drop = skip, keep = used, last = 0, some_unused = 0;
  8088. drop < skip + (toc->size + 7) / 8;
  8089. ++drop, ++keep)
  8090. {
  8091. if (*keep)
  8092. {
  8093. *drop &= ~ref_from_discarded;
  8094. if ((*drop & can_optimize) != 0)
  8095. some_unused = 1;
  8096. last = 0;
  8097. }
  8098. else if ((*drop & ref_from_discarded) != 0)
  8099. {
  8100. some_unused = 1;
  8101. last = ref_from_discarded;
  8102. }
  8103. else
  8104. *drop = last;
  8105. }
  8106. free (used);
  8107. if (some_unused)
  8108. {
  8109. bfd_byte *contents, *src;
  8110. unsigned long off;
  8111. Elf_Internal_Sym *sym;
  8112. bfd_boolean local_toc_syms = FALSE;
  8113. /* Shuffle the toc contents, and at the same time convert the
  8114. skip array from booleans into offsets. */
  8115. if (!bfd_malloc_and_get_section (ibfd, toc, &contents))
  8116. goto error_ret;
  8117. elf_section_data (toc)->this_hdr.contents = contents;
  8118. for (src = contents, off = 0, drop = skip;
  8119. src < contents + toc->size;
  8120. src += 8, ++drop)
  8121. {
  8122. if ((*drop & (can_optimize | ref_from_discarded)) != 0)
  8123. off += 8;
  8124. else if (off != 0)
  8125. {
  8126. *drop = off;
  8127. memcpy (src - off, src, 8);
  8128. }
  8129. }
  8130. *drop = off;
  8131. toc->rawsize = toc->size;
  8132. toc->size = src - contents - off;
  8133. /* Adjust addends for relocs against the toc section sym,
  8134. and optimize any accesses we can. */
  8135. for (sec = ibfd->sections; sec != NULL; sec = sec->next)
  8136. {
  8137. if (sec->reloc_count == 0
  8138. || discarded_section (sec))
  8139. continue;
  8140. relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
  8141. info->keep_memory);
  8142. if (relstart == NULL)
  8143. goto error_ret;
  8144. for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
  8145. {
  8146. enum elf_ppc64_reloc_type r_type;
  8147. unsigned long r_symndx;
  8148. asection *sym_sec;
  8149. struct elf_link_hash_entry *h;
  8150. bfd_vma val;
  8151. r_type = ELF64_R_TYPE (rel->r_info);
  8152. switch (r_type)
  8153. {
  8154. default:
  8155. continue;
  8156. case R_PPC64_TOC16:
  8157. case R_PPC64_TOC16_LO:
  8158. case R_PPC64_TOC16_HI:
  8159. case R_PPC64_TOC16_HA:
  8160. case R_PPC64_TOC16_DS:
  8161. case R_PPC64_TOC16_LO_DS:
  8162. case R_PPC64_ADDR64:
  8163. break;
  8164. }
  8165. r_symndx = ELF64_R_SYM (rel->r_info);
  8166. if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
  8167. r_symndx, ibfd))
  8168. goto error_ret;
  8169. if (sym_sec != toc)
  8170. continue;
  8171. if (h != NULL)
  8172. val = h->root.u.def.value;
  8173. else
  8174. {
  8175. val = sym->st_value;
  8176. if (val != 0)
  8177. local_toc_syms = TRUE;
  8178. }
  8179. val += rel->r_addend;
  8180. if (val > toc->rawsize)
  8181. val = toc->rawsize;
  8182. else if ((skip[val >> 3] & ref_from_discarded) != 0)
  8183. continue;
  8184. else if ((skip[val >> 3] & can_optimize) != 0)
  8185. {
  8186. Elf_Internal_Rela *tocrel
  8187. = toc_relocs + (skip[val >> 3] >> 2);
  8188. unsigned long tsym = ELF64_R_SYM (tocrel->r_info);
  8189. switch (r_type)
  8190. {
  8191. case R_PPC64_TOC16_HA:
  8192. rel->r_info = ELF64_R_INFO (tsym, R_PPC64_TOC16_HA);
  8193. break;
  8194. case R_PPC64_TOC16_LO_DS:
  8195. rel->r_info = ELF64_R_INFO (tsym, R_PPC64_LO_DS_OPT);
  8196. break;
  8197. default:
  8198. if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
  8199. ppc_howto_init ();
  8200. info->callbacks->einfo
  8201. (_("%P: %H: %s references "
  8202. "optimized away TOC entry\n"),
  8203. ibfd, sec, rel->r_offset,
  8204. ppc64_elf_howto_table[r_type]->name);
  8205. bfd_set_error (bfd_error_bad_value);
  8206. goto error_ret;
  8207. }
  8208. rel->r_addend = tocrel->r_addend;
  8209. elf_section_data (sec)->relocs = relstart;
  8210. continue;
  8211. }
  8212. if (h != NULL || sym->st_value != 0)
  8213. continue;
  8214. rel->r_addend -= skip[val >> 3];
  8215. elf_section_data (sec)->relocs = relstart;
  8216. }
  8217. if (elf_section_data (sec)->relocs != relstart)
  8218. free (relstart);
  8219. }
  8220. /* We shouldn't have local or global symbols defined in the TOC,
  8221. but handle them anyway. */
  8222. if (local_syms != NULL)
  8223. for (sym = local_syms;
  8224. sym < local_syms + symtab_hdr->sh_info;
  8225. ++sym)
  8226. if (sym->st_value != 0
  8227. && bfd_section_from_elf_index (ibfd, sym->st_shndx) == toc)
  8228. {
  8229. unsigned long i;
  8230. if (sym->st_value > toc->rawsize)
  8231. i = toc->rawsize >> 3;
  8232. else
  8233. i = sym->st_value >> 3;
  8234. if ((skip[i] & (ref_from_discarded | can_optimize)) != 0)
  8235. {
  8236. if (local_toc_syms)
  8237. (*_bfd_error_handler)
  8238. (_("%s defined on removed toc entry"),
  8239. bfd_elf_sym_name (ibfd, symtab_hdr, sym, NULL));
  8240. do
  8241. ++i;
  8242. while ((skip[i] & (ref_from_discarded | can_optimize)));
  8243. sym->st_value = (bfd_vma) i << 3;
  8244. }
  8245. sym->st_value -= skip[i];
  8246. symtab_hdr->contents = (unsigned char *) local_syms;
  8247. }
  8248. /* Adjust any global syms defined in this toc input section. */
  8249. if (toc_inf.global_toc_syms)
  8250. {
  8251. toc_inf.toc = toc;
  8252. toc_inf.skip = skip;
  8253. toc_inf.global_toc_syms = FALSE;
  8254. elf_link_hash_traverse (elf_hash_table (info), adjust_toc_syms,
  8255. &toc_inf);
  8256. }
  8257. if (toc->reloc_count != 0)
  8258. {
  8259. Elf_Internal_Shdr *rel_hdr;
  8260. Elf_Internal_Rela *wrel;
  8261. bfd_size_type sz;
  8262. /* Remove unused toc relocs, and adjust those we keep. */
  8263. if (toc_relocs == NULL)
  8264. toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
  8265. info->keep_memory);
  8266. if (toc_relocs == NULL)
  8267. goto error_ret;
  8268. wrel = toc_relocs;
  8269. for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
  8270. if ((skip[rel->r_offset >> 3]
  8271. & (ref_from_discarded | can_optimize)) == 0)
  8272. {
  8273. wrel->r_offset = rel->r_offset - skip[rel->r_offset >> 3];
  8274. wrel->r_info = rel->r_info;
  8275. wrel->r_addend = rel->r_addend;
  8276. ++wrel;
  8277. }
  8278. else if (!dec_dynrel_count (rel->r_info, toc, info,
  8279. &local_syms, NULL, NULL))
  8280. goto error_ret;
  8281. elf_section_data (toc)->relocs = toc_relocs;
  8282. toc->reloc_count = wrel - toc_relocs;
  8283. rel_hdr = _bfd_elf_single_rel_hdr (toc);
  8284. sz = rel_hdr->sh_entsize;
  8285. rel_hdr->sh_size = toc->reloc_count * sz;
  8286. }
  8287. }
  8288. else if (toc_relocs != NULL
  8289. && elf_section_data (toc)->relocs != toc_relocs)
  8290. free (toc_relocs);
  8291. if (local_syms != NULL
  8292. && symtab_hdr->contents != (unsigned char *) local_syms)
  8293. {
  8294. if (!info->keep_memory)
  8295. free (local_syms);
  8296. else
  8297. symtab_hdr->contents = (unsigned char *) local_syms;
  8298. }
  8299. free (skip);
  8300. }
  8301. return TRUE;
  8302. }
  8303. /* Return true iff input section I references the TOC using
  8304. instructions limited to +/-32k offsets. */
  8305. bfd_boolean
  8306. ppc64_elf_has_small_toc_reloc (asection *i)
  8307. {
  8308. return (is_ppc64_elf (i->owner)
  8309. && ppc64_elf_tdata (i->owner)->has_small_toc_reloc);
  8310. }
  8311. /* Allocate space for one GOT entry. */
  8312. static void
  8313. allocate_got (struct elf_link_hash_entry *h,
  8314. struct bfd_link_info *info,
  8315. struct got_entry *gent)
  8316. {
  8317. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  8318. bfd_boolean dyn;
  8319. struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
  8320. int entsize = (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)
  8321. ? 16 : 8);
  8322. int rentsize = (gent->tls_type & eh->tls_mask & TLS_GD
  8323. ? 2 : 1) * sizeof (Elf64_External_Rela);
  8324. asection *got = ppc64_elf_tdata (gent->owner)->got;
  8325. gent->got.offset = got->size;
  8326. got->size += entsize;
  8327. dyn = htab->elf.dynamic_sections_created;
  8328. if (h->type == STT_GNU_IFUNC)
  8329. {
  8330. htab->elf.irelplt->size += rentsize;
  8331. htab->got_reli_size += rentsize;
  8332. }
  8333. else if ((bfd_link_pic (info)
  8334. || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
  8335. && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  8336. || h->root.type != bfd_link_hash_undefweak))
  8337. {
  8338. asection *relgot = ppc64_elf_tdata (gent->owner)->relgot;
  8339. relgot->size += rentsize;
  8340. }
  8341. }
  8342. /* This function merges got entries in the same toc group. */
  8343. static void
  8344. merge_got_entries (struct got_entry **pent)
  8345. {
  8346. struct got_entry *ent, *ent2;
  8347. for (ent = *pent; ent != NULL; ent = ent->next)
  8348. if (!ent->is_indirect)
  8349. for (ent2 = ent->next; ent2 != NULL; ent2 = ent2->next)
  8350. if (!ent2->is_indirect
  8351. && ent2->addend == ent->addend
  8352. && ent2->tls_type == ent->tls_type
  8353. && elf_gp (ent2->owner) == elf_gp (ent->owner))
  8354. {
  8355. ent2->is_indirect = TRUE;
  8356. ent2->got.ent = ent;
  8357. }
  8358. }
  8359. /* Allocate space in .plt, .got and associated reloc sections for
  8360. dynamic relocs. */
  8361. static bfd_boolean
  8362. allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
  8363. {
  8364. struct bfd_link_info *info;
  8365. struct ppc_link_hash_table *htab;
  8366. asection *s;
  8367. struct ppc_link_hash_entry *eh;
  8368. struct elf_dyn_relocs *p;
  8369. struct got_entry **pgent, *gent;
  8370. if (h->root.type == bfd_link_hash_indirect)
  8371. return TRUE;
  8372. info = (struct bfd_link_info *) inf;
  8373. htab = ppc_hash_table (info);
  8374. if (htab == NULL)
  8375. return FALSE;
  8376. if ((htab->elf.dynamic_sections_created
  8377. && h->dynindx != -1
  8378. && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
  8379. || h->type == STT_GNU_IFUNC)
  8380. {
  8381. struct plt_entry *pent;
  8382. bfd_boolean doneone = FALSE;
  8383. for (pent = h->plt.plist; pent != NULL; pent = pent->next)
  8384. if (pent->plt.refcount > 0)
  8385. {
  8386. if (!htab->elf.dynamic_sections_created
  8387. || h->dynindx == -1)
  8388. {
  8389. s = htab->elf.iplt;
  8390. pent->plt.offset = s->size;
  8391. s->size += PLT_ENTRY_SIZE (htab);
  8392. s = htab->elf.irelplt;
  8393. }
  8394. else
  8395. {
  8396. /* If this is the first .plt entry, make room for the special
  8397. first entry. */
  8398. s = htab->elf.splt;
  8399. if (s->size == 0)
  8400. s->size += PLT_INITIAL_ENTRY_SIZE (htab);
  8401. pent->plt.offset = s->size;
  8402. /* Make room for this entry. */
  8403. s->size += PLT_ENTRY_SIZE (htab);
  8404. /* Make room for the .glink code. */
  8405. s = htab->glink;
  8406. if (s->size == 0)
  8407. s->size += GLINK_CALL_STUB_SIZE;
  8408. if (htab->opd_abi)
  8409. {
  8410. /* We need bigger stubs past index 32767. */
  8411. if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
  8412. s->size += 4;
  8413. s->size += 2*4;
  8414. }
  8415. else
  8416. s->size += 4;
  8417. /* We also need to make an entry in the .rela.plt section. */
  8418. s = htab->elf.srelplt;
  8419. }
  8420. s->size += sizeof (Elf64_External_Rela);
  8421. doneone = TRUE;
  8422. }
  8423. else
  8424. pent->plt.offset = (bfd_vma) -1;
  8425. if (!doneone)
  8426. {
  8427. h->plt.plist = NULL;
  8428. h->needs_plt = 0;
  8429. }
  8430. }
  8431. else
  8432. {
  8433. h->plt.plist = NULL;
  8434. h->needs_plt = 0;
  8435. }
  8436. eh = (struct ppc_link_hash_entry *) h;
  8437. /* Run through the TLS GD got entries first if we're changing them
  8438. to TPREL. */
  8439. if ((eh->tls_mask & TLS_TPRELGD) != 0)
  8440. for (gent = h->got.glist; gent != NULL; gent = gent->next)
  8441. if (gent->got.refcount > 0
  8442. && (gent->tls_type & TLS_GD) != 0)
  8443. {
  8444. /* This was a GD entry that has been converted to TPREL. If
  8445. there happens to be a TPREL entry we can use that one. */
  8446. struct got_entry *ent;
  8447. for (ent = h->got.glist; ent != NULL; ent = ent->next)
  8448. if (ent->got.refcount > 0
  8449. && (ent->tls_type & TLS_TPREL) != 0
  8450. && ent->addend == gent->addend
  8451. && ent->owner == gent->owner)
  8452. {
  8453. gent->got.refcount = 0;
  8454. break;
  8455. }
  8456. /* If not, then we'll be using our own TPREL entry. */
  8457. if (gent->got.refcount != 0)
  8458. gent->tls_type = TLS_TLS | TLS_TPREL;
  8459. }
  8460. /* Remove any list entry that won't generate a word in the GOT before
  8461. we call merge_got_entries. Otherwise we risk merging to empty
  8462. entries. */
  8463. pgent = &h->got.glist;
  8464. while ((gent = *pgent) != NULL)
  8465. if (gent->got.refcount > 0)
  8466. {
  8467. if ((gent->tls_type & TLS_LD) != 0
  8468. && !h->def_dynamic)
  8469. {
  8470. ppc64_tlsld_got (gent->owner)->got.refcount += 1;
  8471. *pgent = gent->next;
  8472. }
  8473. else
  8474. pgent = &gent->next;
  8475. }
  8476. else
  8477. *pgent = gent->next;
  8478. if (!htab->do_multi_toc)
  8479. merge_got_entries (&h->got.glist);
  8480. for (gent = h->got.glist; gent != NULL; gent = gent->next)
  8481. if (!gent->is_indirect)
  8482. {
  8483. /* Make sure this symbol is output as a dynamic symbol.
  8484. Undefined weak syms won't yet be marked as dynamic,
  8485. nor will all TLS symbols. */
  8486. if (h->dynindx == -1
  8487. && !h->forced_local
  8488. && h->type != STT_GNU_IFUNC
  8489. && htab->elf.dynamic_sections_created)
  8490. {
  8491. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  8492. return FALSE;
  8493. }
  8494. if (!is_ppc64_elf (gent->owner))
  8495. abort ();
  8496. allocate_got (h, info, gent);
  8497. }
  8498. if (eh->dyn_relocs == NULL
  8499. || (!htab->elf.dynamic_sections_created
  8500. && h->type != STT_GNU_IFUNC))
  8501. return TRUE;
  8502. /* In the shared -Bsymbolic case, discard space allocated for
  8503. dynamic pc-relative relocs against symbols which turn out to be
  8504. defined in regular objects. For the normal shared case, discard
  8505. space for relocs that have become local due to symbol visibility
  8506. changes. */
  8507. if (bfd_link_pic (info))
  8508. {
  8509. /* Relocs that use pc_count are those that appear on a call insn,
  8510. or certain REL relocs (see must_be_dyn_reloc) that can be
  8511. generated via assembly. We want calls to protected symbols to
  8512. resolve directly to the function rather than going via the plt.
  8513. If people want function pointer comparisons to work as expected
  8514. then they should avoid writing weird assembly. */
  8515. if (SYMBOL_CALLS_LOCAL (info, h))
  8516. {
  8517. struct elf_dyn_relocs **pp;
  8518. for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
  8519. {
  8520. p->count -= p->pc_count;
  8521. p->pc_count = 0;
  8522. if (p->count == 0)
  8523. *pp = p->next;
  8524. else
  8525. pp = &p->next;
  8526. }
  8527. }
  8528. /* Also discard relocs on undefined weak syms with non-default
  8529. visibility. */
  8530. if (eh->dyn_relocs != NULL
  8531. && h->root.type == bfd_link_hash_undefweak)
  8532. {
  8533. if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
  8534. eh->dyn_relocs = NULL;
  8535. /* Make sure this symbol is output as a dynamic symbol.
  8536. Undefined weak syms won't yet be marked as dynamic. */
  8537. else if (h->dynindx == -1
  8538. && !h->forced_local)
  8539. {
  8540. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  8541. return FALSE;
  8542. }
  8543. }
  8544. }
  8545. else if (h->type == STT_GNU_IFUNC)
  8546. {
  8547. if (!h->non_got_ref)
  8548. eh->dyn_relocs = NULL;
  8549. }
  8550. else if (ELIMINATE_COPY_RELOCS)
  8551. {
  8552. /* For the non-shared case, discard space for relocs against
  8553. symbols which turn out to need copy relocs or are not
  8554. dynamic. */
  8555. if (!h->non_got_ref
  8556. && !h->def_regular)
  8557. {
  8558. /* Make sure this symbol is output as a dynamic symbol.
  8559. Undefined weak syms won't yet be marked as dynamic. */
  8560. if (h->dynindx == -1
  8561. && !h->forced_local)
  8562. {
  8563. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  8564. return FALSE;
  8565. }
  8566. /* If that succeeded, we know we'll be keeping all the
  8567. relocs. */
  8568. if (h->dynindx != -1)
  8569. goto keep;
  8570. }
  8571. eh->dyn_relocs = NULL;
  8572. keep: ;
  8573. }
  8574. /* Finally, allocate space. */
  8575. for (p = eh->dyn_relocs; p != NULL; p = p->next)
  8576. {
  8577. asection *sreloc = elf_section_data (p->sec)->sreloc;
  8578. if (eh->elf.type == STT_GNU_IFUNC)
  8579. sreloc = htab->elf.irelplt;
  8580. sreloc->size += p->count * sizeof (Elf64_External_Rela);
  8581. }
  8582. return TRUE;
  8583. }
  8584. /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
  8585. to set up space for global entry stubs. These are put in glink,
  8586. after the branch table. */
  8587. static bfd_boolean
  8588. size_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
  8589. {
  8590. struct bfd_link_info *info;
  8591. struct ppc_link_hash_table *htab;
  8592. struct plt_entry *pent;
  8593. asection *s;
  8594. if (h->root.type == bfd_link_hash_indirect)
  8595. return TRUE;
  8596. if (!h->pointer_equality_needed)
  8597. return TRUE;
  8598. if (h->def_regular)
  8599. return TRUE;
  8600. info = inf;
  8601. htab = ppc_hash_table (info);
  8602. if (htab == NULL)
  8603. return FALSE;
  8604. s = htab->glink;
  8605. for (pent = h->plt.plist; pent != NULL; pent = pent->next)
  8606. if (pent->plt.offset != (bfd_vma) -1
  8607. && pent->addend == 0)
  8608. {
  8609. /* For ELFv2, if this symbol is not defined in a regular file
  8610. and we are not generating a shared library or pie, then we
  8611. need to define the symbol in the executable on a call stub.
  8612. This is to avoid text relocations. */
  8613. s->size = (s->size + 15) & -16;
  8614. h->root.u.def.section = s;
  8615. h->root.u.def.value = s->size;
  8616. s->size += 16;
  8617. break;
  8618. }
  8619. return TRUE;
  8620. }
  8621. /* Set DF_TEXTREL if we find any dynamic relocs that apply to
  8622. read-only sections. */
  8623. static bfd_boolean
  8624. maybe_set_textrel (struct elf_link_hash_entry *h, void *info)
  8625. {
  8626. if (h->root.type == bfd_link_hash_indirect)
  8627. return TRUE;
  8628. if (readonly_dynrelocs (h))
  8629. {
  8630. ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
  8631. /* Not an error, just cut short the traversal. */
  8632. return FALSE;
  8633. }
  8634. return TRUE;
  8635. }
  8636. /* Set the sizes of the dynamic sections. */
  8637. static bfd_boolean
  8638. ppc64_elf_size_dynamic_sections (bfd *output_bfd,
  8639. struct bfd_link_info *info)
  8640. {
  8641. struct ppc_link_hash_table *htab;
  8642. bfd *dynobj;
  8643. asection *s;
  8644. bfd_boolean relocs;
  8645. bfd *ibfd;
  8646. struct got_entry *first_tlsld;
  8647. htab = ppc_hash_table (info);
  8648. if (htab == NULL)
  8649. return FALSE;
  8650. dynobj = htab->elf.dynobj;
  8651. if (dynobj == NULL)
  8652. abort ();
  8653. if (htab->elf.dynamic_sections_created)
  8654. {
  8655. /* Set the contents of the .interp section to the interpreter. */
  8656. if (bfd_link_executable (info) && !info->nointerp)
  8657. {
  8658. s = bfd_get_linker_section (dynobj, ".interp");
  8659. if (s == NULL)
  8660. abort ();
  8661. s->size = sizeof ELF_DYNAMIC_INTERPRETER;
  8662. s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
  8663. }
  8664. }
  8665. /* Set up .got offsets for local syms, and space for local dynamic
  8666. relocs. */
  8667. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  8668. {
  8669. struct got_entry **lgot_ents;
  8670. struct got_entry **end_lgot_ents;
  8671. struct plt_entry **local_plt;
  8672. struct plt_entry **end_local_plt;
  8673. unsigned char *lgot_masks;
  8674. bfd_size_type locsymcount;
  8675. Elf_Internal_Shdr *symtab_hdr;
  8676. if (!is_ppc64_elf (ibfd))
  8677. continue;
  8678. for (s = ibfd->sections; s != NULL; s = s->next)
  8679. {
  8680. struct ppc_dyn_relocs *p;
  8681. for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
  8682. {
  8683. if (!bfd_is_abs_section (p->sec)
  8684. && bfd_is_abs_section (p->sec->output_section))
  8685. {
  8686. /* Input section has been discarded, either because
  8687. it is a copy of a linkonce section or due to
  8688. linker script /DISCARD/, so we'll be discarding
  8689. the relocs too. */
  8690. }
  8691. else if (p->count != 0)
  8692. {
  8693. asection *srel = elf_section_data (p->sec)->sreloc;
  8694. if (p->ifunc)
  8695. srel = htab->elf.irelplt;
  8696. srel->size += p->count * sizeof (Elf64_External_Rela);
  8697. if ((p->sec->output_section->flags & SEC_READONLY) != 0)
  8698. info->flags |= DF_TEXTREL;
  8699. }
  8700. }
  8701. }
  8702. lgot_ents = elf_local_got_ents (ibfd);
  8703. if (!lgot_ents)
  8704. continue;
  8705. symtab_hdr = &elf_symtab_hdr (ibfd);
  8706. locsymcount = symtab_hdr->sh_info;
  8707. end_lgot_ents = lgot_ents + locsymcount;
  8708. local_plt = (struct plt_entry **) end_lgot_ents;
  8709. end_local_plt = local_plt + locsymcount;
  8710. lgot_masks = (unsigned char *) end_local_plt;
  8711. s = ppc64_elf_tdata (ibfd)->got;
  8712. for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
  8713. {
  8714. struct got_entry **pent, *ent;
  8715. pent = lgot_ents;
  8716. while ((ent = *pent) != NULL)
  8717. if (ent->got.refcount > 0)
  8718. {
  8719. if ((ent->tls_type & *lgot_masks & TLS_LD) != 0)
  8720. {
  8721. ppc64_tlsld_got (ibfd)->got.refcount += 1;
  8722. *pent = ent->next;
  8723. }
  8724. else
  8725. {
  8726. unsigned int ent_size = 8;
  8727. unsigned int rel_size = sizeof (Elf64_External_Rela);
  8728. ent->got.offset = s->size;
  8729. if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
  8730. {
  8731. ent_size *= 2;
  8732. rel_size *= 2;
  8733. }
  8734. s->size += ent_size;
  8735. if ((*lgot_masks & PLT_IFUNC) != 0)
  8736. {
  8737. htab->elf.irelplt->size += rel_size;
  8738. htab->got_reli_size += rel_size;
  8739. }
  8740. else if (bfd_link_pic (info))
  8741. {
  8742. asection *srel = ppc64_elf_tdata (ibfd)->relgot;
  8743. srel->size += rel_size;
  8744. }
  8745. pent = &ent->next;
  8746. }
  8747. }
  8748. else
  8749. *pent = ent->next;
  8750. }
  8751. /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
  8752. for (; local_plt < end_local_plt; ++local_plt)
  8753. {
  8754. struct plt_entry *ent;
  8755. for (ent = *local_plt; ent != NULL; ent = ent->next)
  8756. if (ent->plt.refcount > 0)
  8757. {
  8758. s = htab->elf.iplt;
  8759. ent->plt.offset = s->size;
  8760. s->size += PLT_ENTRY_SIZE (htab);
  8761. htab->elf.irelplt->size += sizeof (Elf64_External_Rela);
  8762. }
  8763. else
  8764. ent->plt.offset = (bfd_vma) -1;
  8765. }
  8766. }
  8767. /* Allocate global sym .plt and .got entries, and space for global
  8768. sym dynamic relocs. */
  8769. elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
  8770. /* Stash the end of glink branch table. */
  8771. if (htab->glink != NULL)
  8772. htab->glink->rawsize = htab->glink->size;
  8773. if (!htab->opd_abi && !bfd_link_pic (info))
  8774. elf_link_hash_traverse (&htab->elf, size_global_entry_stubs, info);
  8775. first_tlsld = NULL;
  8776. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  8777. {
  8778. struct got_entry *ent;
  8779. if (!is_ppc64_elf (ibfd))
  8780. continue;
  8781. ent = ppc64_tlsld_got (ibfd);
  8782. if (ent->got.refcount > 0)
  8783. {
  8784. if (!htab->do_multi_toc && first_tlsld != NULL)
  8785. {
  8786. ent->is_indirect = TRUE;
  8787. ent->got.ent = first_tlsld;
  8788. }
  8789. else
  8790. {
  8791. if (first_tlsld == NULL)
  8792. first_tlsld = ent;
  8793. s = ppc64_elf_tdata (ibfd)->got;
  8794. ent->got.offset = s->size;
  8795. ent->owner = ibfd;
  8796. s->size += 16;
  8797. if (bfd_link_pic (info))
  8798. {
  8799. asection *srel = ppc64_elf_tdata (ibfd)->relgot;
  8800. srel->size += sizeof (Elf64_External_Rela);
  8801. }
  8802. }
  8803. }
  8804. else
  8805. ent->got.offset = (bfd_vma) -1;
  8806. }
  8807. /* We now have determined the sizes of the various dynamic sections.
  8808. Allocate memory for them. */
  8809. relocs = FALSE;
  8810. for (s = dynobj->sections; s != NULL; s = s->next)
  8811. {
  8812. if ((s->flags & SEC_LINKER_CREATED) == 0)
  8813. continue;
  8814. if (s == htab->brlt || s == htab->relbrlt)
  8815. /* These haven't been allocated yet; don't strip. */
  8816. continue;
  8817. else if (s == htab->elf.sgot
  8818. || s == htab->elf.splt
  8819. || s == htab->elf.iplt
  8820. || s == htab->glink
  8821. || s == htab->dynbss)
  8822. {
  8823. /* Strip this section if we don't need it; see the
  8824. comment below. */
  8825. }
  8826. else if (s == htab->glink_eh_frame)
  8827. {
  8828. if (!bfd_is_abs_section (s->output_section))
  8829. /* Not sized yet. */
  8830. continue;
  8831. }
  8832. else if (CONST_STRNEQ (s->name, ".rela"))
  8833. {
  8834. if (s->size != 0)
  8835. {
  8836. if (s != htab->elf.srelplt)
  8837. relocs = TRUE;
  8838. /* We use the reloc_count field as a counter if we need
  8839. to copy relocs into the output file. */
  8840. s->reloc_count = 0;
  8841. }
  8842. }
  8843. else
  8844. {
  8845. /* It's not one of our sections, so don't allocate space. */
  8846. continue;
  8847. }
  8848. if (s->size == 0)
  8849. {
  8850. /* If we don't need this section, strip it from the
  8851. output file. This is mostly to handle .rela.bss and
  8852. .rela.plt. We must create both sections in
  8853. create_dynamic_sections, because they must be created
  8854. before the linker maps input sections to output
  8855. sections. The linker does that before
  8856. adjust_dynamic_symbol is called, and it is that
  8857. function which decides whether anything needs to go
  8858. into these sections. */
  8859. s->flags |= SEC_EXCLUDE;
  8860. continue;
  8861. }
  8862. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  8863. continue;
  8864. /* Allocate memory for the section contents. We use bfd_zalloc
  8865. here in case unused entries are not reclaimed before the
  8866. section's contents are written out. This should not happen,
  8867. but this way if it does we get a R_PPC64_NONE reloc in .rela
  8868. sections instead of garbage.
  8869. We also rely on the section contents being zero when writing
  8870. the GOT. */
  8871. s->contents = bfd_zalloc (dynobj, s->size);
  8872. if (s->contents == NULL)
  8873. return FALSE;
  8874. }
  8875. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  8876. {
  8877. if (!is_ppc64_elf (ibfd))
  8878. continue;
  8879. s = ppc64_elf_tdata (ibfd)->got;
  8880. if (s != NULL && s != htab->elf.sgot)
  8881. {
  8882. if (s->size == 0)
  8883. s->flags |= SEC_EXCLUDE;
  8884. else
  8885. {
  8886. s->contents = bfd_zalloc (ibfd, s->size);
  8887. if (s->contents == NULL)
  8888. return FALSE;
  8889. }
  8890. }
  8891. s = ppc64_elf_tdata (ibfd)->relgot;
  8892. if (s != NULL)
  8893. {
  8894. if (s->size == 0)
  8895. s->flags |= SEC_EXCLUDE;
  8896. else
  8897. {
  8898. s->contents = bfd_zalloc (ibfd, s->size);
  8899. if (s->contents == NULL)
  8900. return FALSE;
  8901. relocs = TRUE;
  8902. s->reloc_count = 0;
  8903. }
  8904. }
  8905. }
  8906. if (htab->elf.dynamic_sections_created)
  8907. {
  8908. bfd_boolean tls_opt;
  8909. /* Add some entries to the .dynamic section. We fill in the
  8910. values later, in ppc64_elf_finish_dynamic_sections, but we
  8911. must add the entries now so that we get the correct size for
  8912. the .dynamic section. The DT_DEBUG entry is filled in by the
  8913. dynamic linker and used by the debugger. */
  8914. #define add_dynamic_entry(TAG, VAL) \
  8915. _bfd_elf_add_dynamic_entry (info, TAG, VAL)
  8916. if (bfd_link_executable (info))
  8917. {
  8918. if (!add_dynamic_entry (DT_DEBUG, 0))
  8919. return FALSE;
  8920. }
  8921. if (htab->elf.splt != NULL && htab->elf.splt->size != 0)
  8922. {
  8923. if (!add_dynamic_entry (DT_PLTGOT, 0)
  8924. || !add_dynamic_entry (DT_PLTRELSZ, 0)
  8925. || !add_dynamic_entry (DT_PLTREL, DT_RELA)
  8926. || !add_dynamic_entry (DT_JMPREL, 0)
  8927. || !add_dynamic_entry (DT_PPC64_GLINK, 0))
  8928. return FALSE;
  8929. }
  8930. if (NO_OPD_RELOCS && abiversion (output_bfd) <= 1)
  8931. {
  8932. if (!add_dynamic_entry (DT_PPC64_OPD, 0)
  8933. || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
  8934. return FALSE;
  8935. }
  8936. tls_opt = (htab->params->tls_get_addr_opt
  8937. && htab->tls_get_addr_fd != NULL
  8938. && htab->tls_get_addr_fd->elf.plt.plist != NULL);
  8939. if (tls_opt || !htab->opd_abi)
  8940. {
  8941. if (!add_dynamic_entry (DT_PPC64_OPT, tls_opt ? PPC64_OPT_TLS : 0))
  8942. return FALSE;
  8943. }
  8944. if (relocs)
  8945. {
  8946. if (!add_dynamic_entry (DT_RELA, 0)
  8947. || !add_dynamic_entry (DT_RELASZ, 0)
  8948. || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
  8949. return FALSE;
  8950. /* If any dynamic relocs apply to a read-only section,
  8951. then we need a DT_TEXTREL entry. */
  8952. if ((info->flags & DF_TEXTREL) == 0)
  8953. elf_link_hash_traverse (&htab->elf, maybe_set_textrel, info);
  8954. if ((info->flags & DF_TEXTREL) != 0)
  8955. {
  8956. if (!add_dynamic_entry (DT_TEXTREL, 0))
  8957. return FALSE;
  8958. }
  8959. }
  8960. }
  8961. #undef add_dynamic_entry
  8962. return TRUE;
  8963. }
  8964. /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
  8965. static bfd_boolean
  8966. ppc64_elf_hash_symbol (struct elf_link_hash_entry *h)
  8967. {
  8968. if (h->plt.plist != NULL
  8969. && !h->def_regular
  8970. && !h->pointer_equality_needed)
  8971. return FALSE;
  8972. return _bfd_elf_hash_symbol (h);
  8973. }
  8974. /* Determine the type of stub needed, if any, for a call. */
  8975. static inline enum ppc_stub_type
  8976. ppc_type_of_stub (asection *input_sec,
  8977. const Elf_Internal_Rela *rel,
  8978. struct ppc_link_hash_entry **hash,
  8979. struct plt_entry **plt_ent,
  8980. bfd_vma destination,
  8981. unsigned long local_off)
  8982. {
  8983. struct ppc_link_hash_entry *h = *hash;
  8984. bfd_vma location;
  8985. bfd_vma branch_offset;
  8986. bfd_vma max_branch_offset;
  8987. enum elf_ppc64_reloc_type r_type;
  8988. if (h != NULL)
  8989. {
  8990. struct plt_entry *ent;
  8991. struct ppc_link_hash_entry *fdh = h;
  8992. if (h->oh != NULL
  8993. && h->oh->is_func_descriptor)
  8994. {
  8995. fdh = ppc_follow_link (h->oh);
  8996. *hash = fdh;
  8997. }
  8998. for (ent = fdh->elf.plt.plist; ent != NULL; ent = ent->next)
  8999. if (ent->addend == rel->r_addend
  9000. && ent->plt.offset != (bfd_vma) -1)
  9001. {
  9002. *plt_ent = ent;
  9003. return ppc_stub_plt_call;
  9004. }
  9005. /* Here, we know we don't have a plt entry. If we don't have a
  9006. either a defined function descriptor or a defined entry symbol
  9007. in a regular object file, then it is pointless trying to make
  9008. any other type of stub. */
  9009. if (!is_static_defined (&fdh->elf)
  9010. && !is_static_defined (&h->elf))
  9011. return ppc_stub_none;
  9012. }
  9013. else if (elf_local_got_ents (input_sec->owner) != NULL)
  9014. {
  9015. Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (input_sec->owner);
  9016. struct plt_entry **local_plt = (struct plt_entry **)
  9017. elf_local_got_ents (input_sec->owner) + symtab_hdr->sh_info;
  9018. unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
  9019. if (local_plt[r_symndx] != NULL)
  9020. {
  9021. struct plt_entry *ent;
  9022. for (ent = local_plt[r_symndx]; ent != NULL; ent = ent->next)
  9023. if (ent->addend == rel->r_addend
  9024. && ent->plt.offset != (bfd_vma) -1)
  9025. {
  9026. *plt_ent = ent;
  9027. return ppc_stub_plt_call;
  9028. }
  9029. }
  9030. }
  9031. /* Determine where the call point is. */
  9032. location = (input_sec->output_offset
  9033. + input_sec->output_section->vma
  9034. + rel->r_offset);
  9035. branch_offset = destination - location;
  9036. r_type = ELF64_R_TYPE (rel->r_info);
  9037. /* Determine if a long branch stub is needed. */
  9038. max_branch_offset = 1 << 25;
  9039. if (r_type != R_PPC64_REL24)
  9040. max_branch_offset = 1 << 15;
  9041. if (branch_offset + max_branch_offset >= 2 * max_branch_offset - local_off)
  9042. /* We need a stub. Figure out whether a long_branch or plt_branch
  9043. is needed later. */
  9044. return ppc_stub_long_branch;
  9045. return ppc_stub_none;
  9046. }
  9047. /* With power7 weakly ordered memory model, it is possible for ld.so
  9048. to update a plt entry in one thread and have another thread see a
  9049. stale zero toc entry. To avoid this we need some sort of acquire
  9050. barrier in the call stub. One solution is to make the load of the
  9051. toc word seem to appear to depend on the load of the function entry
  9052. word. Another solution is to test for r2 being zero, and branch to
  9053. the appropriate glink entry if so.
  9054. . fake dep barrier compare
  9055. . ld 12,xxx(2) ld 12,xxx(2)
  9056. . mtctr 12 mtctr 12
  9057. . xor 11,12,12 ld 2,xxx+8(2)
  9058. . add 2,2,11 cmpldi 2,0
  9059. . ld 2,xxx+8(2) bnectr+
  9060. . bctr b <glink_entry>
  9061. The solution involving the compare turns out to be faster, so
  9062. that's what we use unless the branch won't reach. */
  9063. #define ALWAYS_USE_FAKE_DEP 0
  9064. #define ALWAYS_EMIT_R2SAVE 0
  9065. #define PPC_LO(v) ((v) & 0xffff)
  9066. #define PPC_HI(v) (((v) >> 16) & 0xffff)
  9067. #define PPC_HA(v) PPC_HI ((v) + 0x8000)
  9068. static inline unsigned int
  9069. plt_stub_size (struct ppc_link_hash_table *htab,
  9070. struct ppc_stub_hash_entry *stub_entry,
  9071. bfd_vma off)
  9072. {
  9073. unsigned size = 12;
  9074. if (ALWAYS_EMIT_R2SAVE
  9075. || stub_entry->stub_type == ppc_stub_plt_call_r2save)
  9076. size += 4;
  9077. if (PPC_HA (off) != 0)
  9078. size += 4;
  9079. if (htab->opd_abi)
  9080. {
  9081. size += 4;
  9082. if (htab->params->plt_static_chain)
  9083. size += 4;
  9084. if (htab->params->plt_thread_safe
  9085. && htab->elf.dynamic_sections_created
  9086. && stub_entry->h != NULL
  9087. && stub_entry->h->elf.dynindx != -1)
  9088. size += 8;
  9089. if (PPC_HA (off + 8 + 8 * htab->params->plt_static_chain) != PPC_HA (off))
  9090. size += 4;
  9091. }
  9092. if (stub_entry->h != NULL
  9093. && (stub_entry->h == htab->tls_get_addr_fd
  9094. || stub_entry->h == htab->tls_get_addr)
  9095. && htab->params->tls_get_addr_opt)
  9096. size += 13 * 4;
  9097. return size;
  9098. }
  9099. /* If this stub would cross fewer 2**plt_stub_align boundaries if we align,
  9100. then return the padding needed to do so. */
  9101. static inline unsigned int
  9102. plt_stub_pad (struct ppc_link_hash_table *htab,
  9103. struct ppc_stub_hash_entry *stub_entry,
  9104. bfd_vma plt_off)
  9105. {
  9106. int stub_align = 1 << htab->params->plt_stub_align;
  9107. unsigned stub_size = plt_stub_size (htab, stub_entry, plt_off);
  9108. bfd_vma stub_off = stub_entry->group->stub_sec->size;
  9109. if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align)
  9110. > ((stub_size - 1) & -stub_align))
  9111. return stub_align - (stub_off & (stub_align - 1));
  9112. return 0;
  9113. }
  9114. /* Build a .plt call stub. */
  9115. static inline bfd_byte *
  9116. build_plt_stub (struct ppc_link_hash_table *htab,
  9117. struct ppc_stub_hash_entry *stub_entry,
  9118. bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
  9119. {
  9120. bfd *obfd = htab->params->stub_bfd;
  9121. bfd_boolean plt_load_toc = htab->opd_abi;
  9122. bfd_boolean plt_static_chain = htab->params->plt_static_chain;
  9123. bfd_boolean plt_thread_safe = (htab->params->plt_thread_safe
  9124. && htab->elf.dynamic_sections_created
  9125. && stub_entry->h != NULL
  9126. && stub_entry->h->elf.dynindx != -1);
  9127. bfd_boolean use_fake_dep = plt_thread_safe;
  9128. bfd_vma cmp_branch_off = 0;
  9129. if (!ALWAYS_USE_FAKE_DEP
  9130. && plt_load_toc
  9131. && plt_thread_safe
  9132. && !((stub_entry->h == htab->tls_get_addr_fd
  9133. || stub_entry->h == htab->tls_get_addr)
  9134. && htab->params->tls_get_addr_opt))
  9135. {
  9136. bfd_vma pltoff = stub_entry->plt_ent->plt.offset & ~1;
  9137. bfd_vma pltindex = ((pltoff - PLT_INITIAL_ENTRY_SIZE (htab))
  9138. / PLT_ENTRY_SIZE (htab));
  9139. bfd_vma glinkoff = GLINK_CALL_STUB_SIZE + pltindex * 8;
  9140. bfd_vma to, from;
  9141. if (pltindex > 32768)
  9142. glinkoff += (pltindex - 32768) * 4;
  9143. to = (glinkoff
  9144. + htab->glink->output_offset
  9145. + htab->glink->output_section->vma);
  9146. from = (p - stub_entry->group->stub_sec->contents
  9147. + 4 * (ALWAYS_EMIT_R2SAVE
  9148. || stub_entry->stub_type == ppc_stub_plt_call_r2save)
  9149. + 4 * (PPC_HA (offset) != 0)
  9150. + 4 * (PPC_HA (offset + 8 + 8 * plt_static_chain)
  9151. != PPC_HA (offset))
  9152. + 4 * (plt_static_chain != 0)
  9153. + 20
  9154. + stub_entry->group->stub_sec->output_offset
  9155. + stub_entry->group->stub_sec->output_section->vma);
  9156. cmp_branch_off = to - from;
  9157. use_fake_dep = cmp_branch_off + (1 << 25) >= (1 << 26);
  9158. }
  9159. if (PPC_HA (offset) != 0)
  9160. {
  9161. if (r != NULL)
  9162. {
  9163. if (ALWAYS_EMIT_R2SAVE
  9164. || stub_entry->stub_type == ppc_stub_plt_call_r2save)
  9165. r[0].r_offset += 4;
  9166. r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
  9167. r[1].r_offset = r[0].r_offset + 4;
  9168. r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
  9169. r[1].r_addend = r[0].r_addend;
  9170. if (plt_load_toc)
  9171. {
  9172. if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
  9173. {
  9174. r[2].r_offset = r[1].r_offset + 4;
  9175. r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO);
  9176. r[2].r_addend = r[0].r_addend;
  9177. }
  9178. else
  9179. {
  9180. r[2].r_offset = r[1].r_offset + 8 + 8 * use_fake_dep;
  9181. r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
  9182. r[2].r_addend = r[0].r_addend + 8;
  9183. if (plt_static_chain)
  9184. {
  9185. r[3].r_offset = r[2].r_offset + 4;
  9186. r[3].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
  9187. r[3].r_addend = r[0].r_addend + 16;
  9188. }
  9189. }
  9190. }
  9191. }
  9192. if (ALWAYS_EMIT_R2SAVE
  9193. || stub_entry->stub_type == ppc_stub_plt_call_r2save)
  9194. bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p), p += 4;
  9195. if (plt_load_toc)
  9196. {
  9197. bfd_put_32 (obfd, ADDIS_R11_R2 | PPC_HA (offset), p), p += 4;
  9198. bfd_put_32 (obfd, LD_R12_0R11 | PPC_LO (offset), p), p += 4;
  9199. }
  9200. else
  9201. {
  9202. bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
  9203. bfd_put_32 (obfd, LD_R12_0R12 | PPC_LO (offset), p), p += 4;
  9204. }
  9205. if (plt_load_toc
  9206. && PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
  9207. {
  9208. bfd_put_32 (obfd, ADDI_R11_R11 | PPC_LO (offset), p), p += 4;
  9209. offset = 0;
  9210. }
  9211. bfd_put_32 (obfd, MTCTR_R12, p), p += 4;
  9212. if (plt_load_toc)
  9213. {
  9214. if (use_fake_dep)
  9215. {
  9216. bfd_put_32 (obfd, XOR_R2_R12_R12, p), p += 4;
  9217. bfd_put_32 (obfd, ADD_R11_R11_R2, p), p += 4;
  9218. }
  9219. bfd_put_32 (obfd, LD_R2_0R11 | PPC_LO (offset + 8), p), p += 4;
  9220. if (plt_static_chain)
  9221. bfd_put_32 (obfd, LD_R11_0R11 | PPC_LO (offset + 16), p), p += 4;
  9222. }
  9223. }
  9224. else
  9225. {
  9226. if (r != NULL)
  9227. {
  9228. if (ALWAYS_EMIT_R2SAVE
  9229. || stub_entry->stub_type == ppc_stub_plt_call_r2save)
  9230. r[0].r_offset += 4;
  9231. r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
  9232. if (plt_load_toc)
  9233. {
  9234. if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
  9235. {
  9236. r[1].r_offset = r[0].r_offset + 4;
  9237. r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16);
  9238. r[1].r_addend = r[0].r_addend;
  9239. }
  9240. else
  9241. {
  9242. r[1].r_offset = r[0].r_offset + 8 + 8 * use_fake_dep;
  9243. r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
  9244. r[1].r_addend = r[0].r_addend + 8 + 8 * plt_static_chain;
  9245. if (plt_static_chain)
  9246. {
  9247. r[2].r_offset = r[1].r_offset + 4;
  9248. r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
  9249. r[2].r_addend = r[0].r_addend + 8;
  9250. }
  9251. }
  9252. }
  9253. }
  9254. if (ALWAYS_EMIT_R2SAVE
  9255. || stub_entry->stub_type == ppc_stub_plt_call_r2save)
  9256. bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p), p += 4;
  9257. bfd_put_32 (obfd, LD_R12_0R2 | PPC_LO (offset), p), p += 4;
  9258. if (plt_load_toc
  9259. && PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
  9260. {
  9261. bfd_put_32 (obfd, ADDI_R2_R2 | PPC_LO (offset), p), p += 4;
  9262. offset = 0;
  9263. }
  9264. bfd_put_32 (obfd, MTCTR_R12, p), p += 4;
  9265. if (plt_load_toc)
  9266. {
  9267. if (use_fake_dep)
  9268. {
  9269. bfd_put_32 (obfd, XOR_R11_R12_R12, p), p += 4;
  9270. bfd_put_32 (obfd, ADD_R2_R2_R11, p), p += 4;
  9271. }
  9272. if (plt_static_chain)
  9273. bfd_put_32 (obfd, LD_R11_0R2 | PPC_LO (offset + 16), p), p += 4;
  9274. bfd_put_32 (obfd, LD_R2_0R2 | PPC_LO (offset + 8), p), p += 4;
  9275. }
  9276. }
  9277. if (plt_load_toc && plt_thread_safe && !use_fake_dep)
  9278. {
  9279. bfd_put_32 (obfd, CMPLDI_R2_0, p), p += 4;
  9280. bfd_put_32 (obfd, BNECTR_P4, p), p += 4;
  9281. bfd_put_32 (obfd, B_DOT | (cmp_branch_off & 0x3fffffc), p), p += 4;
  9282. }
  9283. else
  9284. bfd_put_32 (obfd, BCTR, p), p += 4;
  9285. return p;
  9286. }
  9287. /* Build a special .plt call stub for __tls_get_addr. */
  9288. #define LD_R11_0R3 0xe9630000
  9289. #define LD_R12_0R3 0xe9830000
  9290. #define MR_R0_R3 0x7c601b78
  9291. #define CMPDI_R11_0 0x2c2b0000
  9292. #define ADD_R3_R12_R13 0x7c6c6a14
  9293. #define BEQLR 0x4d820020
  9294. #define MR_R3_R0 0x7c030378
  9295. #define STD_R11_0R1 0xf9610000
  9296. #define BCTRL 0x4e800421
  9297. #define LD_R11_0R1 0xe9610000
  9298. #define MTLR_R11 0x7d6803a6
  9299. static inline bfd_byte *
  9300. build_tls_get_addr_stub (struct ppc_link_hash_table *htab,
  9301. struct ppc_stub_hash_entry *stub_entry,
  9302. bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
  9303. {
  9304. bfd *obfd = htab->params->stub_bfd;
  9305. bfd_put_32 (obfd, LD_R11_0R3 + 0, p), p += 4;
  9306. bfd_put_32 (obfd, LD_R12_0R3 + 8, p), p += 4;
  9307. bfd_put_32 (obfd, MR_R0_R3, p), p += 4;
  9308. bfd_put_32 (obfd, CMPDI_R11_0, p), p += 4;
  9309. bfd_put_32 (obfd, ADD_R3_R12_R13, p), p += 4;
  9310. bfd_put_32 (obfd, BEQLR, p), p += 4;
  9311. bfd_put_32 (obfd, MR_R3_R0, p), p += 4;
  9312. bfd_put_32 (obfd, MFLR_R11, p), p += 4;
  9313. bfd_put_32 (obfd, STD_R11_0R1 + STK_LINKER (htab), p), p += 4;
  9314. if (r != NULL)
  9315. r[0].r_offset += 9 * 4;
  9316. p = build_plt_stub (htab, stub_entry, p, offset, r);
  9317. bfd_put_32 (obfd, BCTRL, p - 4);
  9318. bfd_put_32 (obfd, LD_R2_0R1 + STK_TOC (htab), p), p += 4;
  9319. bfd_put_32 (obfd, LD_R11_0R1 + STK_LINKER (htab), p), p += 4;
  9320. bfd_put_32 (obfd, MTLR_R11, p), p += 4;
  9321. bfd_put_32 (obfd, BLR, p), p += 4;
  9322. return p;
  9323. }
  9324. static Elf_Internal_Rela *
  9325. get_relocs (asection *sec, int count)
  9326. {
  9327. Elf_Internal_Rela *relocs;
  9328. struct bfd_elf_section_data *elfsec_data;
  9329. elfsec_data = elf_section_data (sec);
  9330. relocs = elfsec_data->relocs;
  9331. if (relocs == NULL)
  9332. {
  9333. bfd_size_type relsize;
  9334. relsize = sec->reloc_count * sizeof (*relocs);
  9335. relocs = bfd_alloc (sec->owner, relsize);
  9336. if (relocs == NULL)
  9337. return NULL;
  9338. elfsec_data->relocs = relocs;
  9339. elfsec_data->rela.hdr = bfd_zalloc (sec->owner,
  9340. sizeof (Elf_Internal_Shdr));
  9341. if (elfsec_data->rela.hdr == NULL)
  9342. return NULL;
  9343. elfsec_data->rela.hdr->sh_size = (sec->reloc_count
  9344. * sizeof (Elf64_External_Rela));
  9345. elfsec_data->rela.hdr->sh_entsize = sizeof (Elf64_External_Rela);
  9346. sec->reloc_count = 0;
  9347. }
  9348. relocs += sec->reloc_count;
  9349. sec->reloc_count += count;
  9350. return relocs;
  9351. }
  9352. static bfd_vma
  9353. get_r2off (struct bfd_link_info *info,
  9354. struct ppc_stub_hash_entry *stub_entry)
  9355. {
  9356. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  9357. bfd_vma r2off = htab->sec_info[stub_entry->target_section->id].toc_off;
  9358. if (r2off == 0)
  9359. {
  9360. /* Support linking -R objects. Get the toc pointer from the
  9361. opd entry. */
  9362. char buf[8];
  9363. if (!htab->opd_abi)
  9364. return r2off;
  9365. asection *opd = stub_entry->h->elf.root.u.def.section;
  9366. bfd_vma opd_off = stub_entry->h->elf.root.u.def.value;
  9367. if (strcmp (opd->name, ".opd") != 0
  9368. || opd->reloc_count != 0)
  9369. {
  9370. info->callbacks->einfo (_("%P: cannot find opd entry toc for `%T'\n"),
  9371. stub_entry->h->elf.root.root.string);
  9372. bfd_set_error (bfd_error_bad_value);
  9373. return (bfd_vma) -1;
  9374. }
  9375. if (!bfd_get_section_contents (opd->owner, opd, buf, opd_off + 8, 8))
  9376. return (bfd_vma) -1;
  9377. r2off = bfd_get_64 (opd->owner, buf);
  9378. r2off -= elf_gp (info->output_bfd);
  9379. }
  9380. r2off -= htab->sec_info[stub_entry->group->link_sec->id].toc_off;
  9381. return r2off;
  9382. }
  9383. static bfd_boolean
  9384. ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
  9385. {
  9386. struct ppc_stub_hash_entry *stub_entry;
  9387. struct ppc_branch_hash_entry *br_entry;
  9388. struct bfd_link_info *info;
  9389. struct ppc_link_hash_table *htab;
  9390. bfd_byte *loc;
  9391. bfd_byte *p;
  9392. bfd_vma dest, off;
  9393. int size;
  9394. Elf_Internal_Rela *r;
  9395. asection *plt;
  9396. /* Massage our args to the form they really have. */
  9397. stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
  9398. info = in_arg;
  9399. htab = ppc_hash_table (info);
  9400. if (htab == NULL)
  9401. return FALSE;
  9402. /* Make a note of the offset within the stubs for this entry. */
  9403. stub_entry->stub_offset = stub_entry->group->stub_sec->size;
  9404. loc = stub_entry->group->stub_sec->contents + stub_entry->stub_offset;
  9405. htab->stub_count[stub_entry->stub_type - 1] += 1;
  9406. switch (stub_entry->stub_type)
  9407. {
  9408. case ppc_stub_long_branch:
  9409. case ppc_stub_long_branch_r2off:
  9410. /* Branches are relative. This is where we are going to. */
  9411. dest = (stub_entry->target_value
  9412. + stub_entry->target_section->output_offset
  9413. + stub_entry->target_section->output_section->vma);
  9414. dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
  9415. off = dest;
  9416. /* And this is where we are coming from. */
  9417. off -= (stub_entry->stub_offset
  9418. + stub_entry->group->stub_sec->output_offset
  9419. + stub_entry->group->stub_sec->output_section->vma);
  9420. size = 4;
  9421. if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
  9422. {
  9423. bfd_vma r2off = get_r2off (info, stub_entry);
  9424. if (r2off == (bfd_vma) -1)
  9425. {
  9426. htab->stub_error = TRUE;
  9427. return FALSE;
  9428. }
  9429. bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
  9430. loc += 4;
  9431. size = 8;
  9432. if (PPC_HA (r2off) != 0)
  9433. {
  9434. bfd_put_32 (htab->params->stub_bfd,
  9435. ADDIS_R2_R2 | PPC_HA (r2off), loc);
  9436. loc += 4;
  9437. size += 4;
  9438. }
  9439. if (PPC_LO (r2off) != 0)
  9440. {
  9441. bfd_put_32 (htab->params->stub_bfd,
  9442. ADDI_R2_R2 | PPC_LO (r2off), loc);
  9443. loc += 4;
  9444. size += 4;
  9445. }
  9446. off -= size - 4;
  9447. }
  9448. bfd_put_32 (htab->params->stub_bfd, B_DOT | (off & 0x3fffffc), loc);
  9449. if (off + (1 << 25) >= (bfd_vma) (1 << 26))
  9450. {
  9451. info->callbacks->einfo
  9452. (_("%P: long branch stub `%s' offset overflow\n"),
  9453. stub_entry->root.string);
  9454. htab->stub_error = TRUE;
  9455. return FALSE;
  9456. }
  9457. if (info->emitrelocations)
  9458. {
  9459. r = get_relocs (stub_entry->group->stub_sec, 1);
  9460. if (r == NULL)
  9461. return FALSE;
  9462. r->r_offset = loc - stub_entry->group->stub_sec->contents;
  9463. r->r_info = ELF64_R_INFO (0, R_PPC64_REL24);
  9464. r->r_addend = dest;
  9465. if (stub_entry->h != NULL)
  9466. {
  9467. struct elf_link_hash_entry **hashes;
  9468. unsigned long symndx;
  9469. struct ppc_link_hash_entry *h;
  9470. hashes = elf_sym_hashes (htab->params->stub_bfd);
  9471. if (hashes == NULL)
  9472. {
  9473. bfd_size_type hsize;
  9474. hsize = (htab->stub_globals + 1) * sizeof (*hashes);
  9475. hashes = bfd_zalloc (htab->params->stub_bfd, hsize);
  9476. if (hashes == NULL)
  9477. return FALSE;
  9478. elf_sym_hashes (htab->params->stub_bfd) = hashes;
  9479. htab->stub_globals = 1;
  9480. }
  9481. symndx = htab->stub_globals++;
  9482. h = stub_entry->h;
  9483. hashes[symndx] = &h->elf;
  9484. r->r_info = ELF64_R_INFO (symndx, R_PPC64_REL24);
  9485. if (h->oh != NULL && h->oh->is_func)
  9486. h = ppc_follow_link (h->oh);
  9487. if (h->elf.root.u.def.section != stub_entry->target_section)
  9488. /* H is an opd symbol. The addend must be zero. */
  9489. r->r_addend = 0;
  9490. else
  9491. {
  9492. off = (h->elf.root.u.def.value
  9493. + h->elf.root.u.def.section->output_offset
  9494. + h->elf.root.u.def.section->output_section->vma);
  9495. r->r_addend -= off;
  9496. }
  9497. }
  9498. }
  9499. break;
  9500. case ppc_stub_plt_branch:
  9501. case ppc_stub_plt_branch_r2off:
  9502. br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
  9503. stub_entry->root.string + 9,
  9504. FALSE, FALSE);
  9505. if (br_entry == NULL)
  9506. {
  9507. info->callbacks->einfo (_("%P: can't find branch stub `%s'\n"),
  9508. stub_entry->root.string);
  9509. htab->stub_error = TRUE;
  9510. return FALSE;
  9511. }
  9512. dest = (stub_entry->target_value
  9513. + stub_entry->target_section->output_offset
  9514. + stub_entry->target_section->output_section->vma);
  9515. if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
  9516. dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
  9517. bfd_put_64 (htab->brlt->owner, dest,
  9518. htab->brlt->contents + br_entry->offset);
  9519. if (br_entry->iter == htab->stub_iteration)
  9520. {
  9521. br_entry->iter = 0;
  9522. if (htab->relbrlt != NULL)
  9523. {
  9524. /* Create a reloc for the branch lookup table entry. */
  9525. Elf_Internal_Rela rela;
  9526. bfd_byte *rl;
  9527. rela.r_offset = (br_entry->offset
  9528. + htab->brlt->output_offset
  9529. + htab->brlt->output_section->vma);
  9530. rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
  9531. rela.r_addend = dest;
  9532. rl = htab->relbrlt->contents;
  9533. rl += (htab->relbrlt->reloc_count++
  9534. * sizeof (Elf64_External_Rela));
  9535. bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl);
  9536. }
  9537. else if (info->emitrelocations)
  9538. {
  9539. r = get_relocs (htab->brlt, 1);
  9540. if (r == NULL)
  9541. return FALSE;
  9542. /* brlt, being SEC_LINKER_CREATED does not go through the
  9543. normal reloc processing. Symbols and offsets are not
  9544. translated from input file to output file form, so
  9545. set up the offset per the output file. */
  9546. r->r_offset = (br_entry->offset
  9547. + htab->brlt->output_offset
  9548. + htab->brlt->output_section->vma);
  9549. r->r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
  9550. r->r_addend = dest;
  9551. }
  9552. }
  9553. dest = (br_entry->offset
  9554. + htab->brlt->output_offset
  9555. + htab->brlt->output_section->vma);
  9556. off = (dest
  9557. - elf_gp (htab->brlt->output_section->owner)
  9558. - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
  9559. if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
  9560. {
  9561. info->callbacks->einfo
  9562. (_("%P: linkage table error against `%T'\n"),
  9563. stub_entry->root.string);
  9564. bfd_set_error (bfd_error_bad_value);
  9565. htab->stub_error = TRUE;
  9566. return FALSE;
  9567. }
  9568. if (info->emitrelocations)
  9569. {
  9570. r = get_relocs (stub_entry->group->stub_sec, 1 + (PPC_HA (off) != 0));
  9571. if (r == NULL)
  9572. return FALSE;
  9573. r[0].r_offset = loc - stub_entry->group->stub_sec->contents;
  9574. if (bfd_big_endian (info->output_bfd))
  9575. r[0].r_offset += 2;
  9576. if (stub_entry->stub_type == ppc_stub_plt_branch_r2off)
  9577. r[0].r_offset += 4;
  9578. r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
  9579. r[0].r_addend = dest;
  9580. if (PPC_HA (off) != 0)
  9581. {
  9582. r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
  9583. r[1].r_offset = r[0].r_offset + 4;
  9584. r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
  9585. r[1].r_addend = r[0].r_addend;
  9586. }
  9587. }
  9588. if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
  9589. {
  9590. if (PPC_HA (off) != 0)
  9591. {
  9592. size = 16;
  9593. bfd_put_32 (htab->params->stub_bfd,
  9594. ADDIS_R12_R2 | PPC_HA (off), loc);
  9595. loc += 4;
  9596. bfd_put_32 (htab->params->stub_bfd,
  9597. LD_R12_0R12 | PPC_LO (off), loc);
  9598. }
  9599. else
  9600. {
  9601. size = 12;
  9602. bfd_put_32 (htab->params->stub_bfd,
  9603. LD_R12_0R2 | PPC_LO (off), loc);
  9604. }
  9605. }
  9606. else
  9607. {
  9608. bfd_vma r2off = get_r2off (info, stub_entry);
  9609. if (r2off == (bfd_vma) -1)
  9610. {
  9611. htab->stub_error = TRUE;
  9612. return FALSE;
  9613. }
  9614. bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
  9615. loc += 4;
  9616. size = 16;
  9617. if (PPC_HA (off) != 0)
  9618. {
  9619. size += 4;
  9620. bfd_put_32 (htab->params->stub_bfd,
  9621. ADDIS_R12_R2 | PPC_HA (off), loc);
  9622. loc += 4;
  9623. bfd_put_32 (htab->params->stub_bfd,
  9624. LD_R12_0R12 | PPC_LO (off), loc);
  9625. }
  9626. else
  9627. bfd_put_32 (htab->params->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
  9628. if (PPC_HA (r2off) != 0)
  9629. {
  9630. size += 4;
  9631. loc += 4;
  9632. bfd_put_32 (htab->params->stub_bfd,
  9633. ADDIS_R2_R2 | PPC_HA (r2off), loc);
  9634. }
  9635. if (PPC_LO (r2off) != 0)
  9636. {
  9637. size += 4;
  9638. loc += 4;
  9639. bfd_put_32 (htab->params->stub_bfd,
  9640. ADDI_R2_R2 | PPC_LO (r2off), loc);
  9641. }
  9642. }
  9643. loc += 4;
  9644. bfd_put_32 (htab->params->stub_bfd, MTCTR_R12, loc);
  9645. loc += 4;
  9646. bfd_put_32 (htab->params->stub_bfd, BCTR, loc);
  9647. break;
  9648. case ppc_stub_plt_call:
  9649. case ppc_stub_plt_call_r2save:
  9650. if (stub_entry->h != NULL
  9651. && stub_entry->h->is_func_descriptor
  9652. && stub_entry->h->oh != NULL)
  9653. {
  9654. struct ppc_link_hash_entry *fh = ppc_follow_link (stub_entry->h->oh);
  9655. /* If the old-ABI "dot-symbol" is undefined make it weak so
  9656. we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
  9657. if (fh->elf.root.type == bfd_link_hash_undefined)
  9658. fh->elf.root.type = bfd_link_hash_undefweak;
  9659. /* Stop undo_symbol_twiddle changing it back to undefined. */
  9660. fh->was_undefined = 0;
  9661. }
  9662. /* Now build the stub. */
  9663. dest = stub_entry->plt_ent->plt.offset & ~1;
  9664. if (dest >= (bfd_vma) -2)
  9665. abort ();
  9666. plt = htab->elf.splt;
  9667. if (!htab->elf.dynamic_sections_created
  9668. || stub_entry->h == NULL
  9669. || stub_entry->h->elf.dynindx == -1)
  9670. plt = htab->elf.iplt;
  9671. dest += plt->output_offset + plt->output_section->vma;
  9672. if (stub_entry->h == NULL
  9673. && (stub_entry->plt_ent->plt.offset & 1) == 0)
  9674. {
  9675. Elf_Internal_Rela rela;
  9676. bfd_byte *rl;
  9677. rela.r_offset = dest;
  9678. if (htab->opd_abi)
  9679. rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
  9680. else
  9681. rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
  9682. rela.r_addend = (stub_entry->target_value
  9683. + stub_entry->target_section->output_offset
  9684. + stub_entry->target_section->output_section->vma);
  9685. rl = (htab->elf.irelplt->contents
  9686. + (htab->elf.irelplt->reloc_count++
  9687. * sizeof (Elf64_External_Rela)));
  9688. bfd_elf64_swap_reloca_out (info->output_bfd, &rela, rl);
  9689. stub_entry->plt_ent->plt.offset |= 1;
  9690. }
  9691. off = (dest
  9692. - elf_gp (plt->output_section->owner)
  9693. - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
  9694. if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
  9695. {
  9696. info->callbacks->einfo
  9697. (_("%P: linkage table error against `%T'\n"),
  9698. stub_entry->h != NULL
  9699. ? stub_entry->h->elf.root.root.string
  9700. : "<local sym>");
  9701. bfd_set_error (bfd_error_bad_value);
  9702. htab->stub_error = TRUE;
  9703. return FALSE;
  9704. }
  9705. if (htab->params->plt_stub_align != 0)
  9706. {
  9707. unsigned pad = plt_stub_pad (htab, stub_entry, off);
  9708. stub_entry->group->stub_sec->size += pad;
  9709. stub_entry->stub_offset = stub_entry->group->stub_sec->size;
  9710. loc += pad;
  9711. }
  9712. r = NULL;
  9713. if (info->emitrelocations)
  9714. {
  9715. r = get_relocs (stub_entry->group->stub_sec,
  9716. ((PPC_HA (off) != 0)
  9717. + (htab->opd_abi
  9718. ? 2 + (htab->params->plt_static_chain
  9719. && PPC_HA (off + 16) == PPC_HA (off))
  9720. : 1)));
  9721. if (r == NULL)
  9722. return FALSE;
  9723. r[0].r_offset = loc - stub_entry->group->stub_sec->contents;
  9724. if (bfd_big_endian (info->output_bfd))
  9725. r[0].r_offset += 2;
  9726. r[0].r_addend = dest;
  9727. }
  9728. if (stub_entry->h != NULL
  9729. && (stub_entry->h == htab->tls_get_addr_fd
  9730. || stub_entry->h == htab->tls_get_addr)
  9731. && htab->params->tls_get_addr_opt)
  9732. p = build_tls_get_addr_stub (htab, stub_entry, loc, off, r);
  9733. else
  9734. p = build_plt_stub (htab, stub_entry, loc, off, r);
  9735. size = p - loc;
  9736. break;
  9737. case ppc_stub_save_res:
  9738. return TRUE;
  9739. default:
  9740. BFD_FAIL ();
  9741. return FALSE;
  9742. }
  9743. stub_entry->group->stub_sec->size += size;
  9744. if (htab->params->emit_stub_syms)
  9745. {
  9746. struct elf_link_hash_entry *h;
  9747. size_t len1, len2;
  9748. char *name;
  9749. const char *const stub_str[] = { "long_branch",
  9750. "long_branch_r2off",
  9751. "plt_branch",
  9752. "plt_branch_r2off",
  9753. "plt_call",
  9754. "plt_call" };
  9755. len1 = strlen (stub_str[stub_entry->stub_type - 1]);
  9756. len2 = strlen (stub_entry->root.string);
  9757. name = bfd_malloc (len1 + len2 + 2);
  9758. if (name == NULL)
  9759. return FALSE;
  9760. memcpy (name, stub_entry->root.string, 9);
  9761. memcpy (name + 9, stub_str[stub_entry->stub_type - 1], len1);
  9762. memcpy (name + len1 + 9, stub_entry->root.string + 8, len2 - 8 + 1);
  9763. h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
  9764. if (h == NULL)
  9765. return FALSE;
  9766. if (h->root.type == bfd_link_hash_new)
  9767. {
  9768. h->root.type = bfd_link_hash_defined;
  9769. h->root.u.def.section = stub_entry->group->stub_sec;
  9770. h->root.u.def.value = stub_entry->stub_offset;
  9771. h->ref_regular = 1;
  9772. h->def_regular = 1;
  9773. h->ref_regular_nonweak = 1;
  9774. h->forced_local = 1;
  9775. h->non_elf = 0;
  9776. h->root.linker_def = 1;
  9777. }
  9778. }
  9779. return TRUE;
  9780. }
  9781. /* As above, but don't actually build the stub. Just bump offset so
  9782. we know stub section sizes, and select plt_branch stubs where
  9783. long_branch stubs won't do. */
  9784. static bfd_boolean
  9785. ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
  9786. {
  9787. struct ppc_stub_hash_entry *stub_entry;
  9788. struct bfd_link_info *info;
  9789. struct ppc_link_hash_table *htab;
  9790. bfd_vma off;
  9791. int size;
  9792. /* Massage our args to the form they really have. */
  9793. stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
  9794. info = in_arg;
  9795. htab = ppc_hash_table (info);
  9796. if (htab == NULL)
  9797. return FALSE;
  9798. if (stub_entry->h != NULL
  9799. && stub_entry->h->save_res
  9800. && stub_entry->h->elf.root.type == bfd_link_hash_defined
  9801. && stub_entry->h->elf.root.u.def.section == htab->sfpr)
  9802. {
  9803. /* Don't make stubs to out-of-line register save/restore
  9804. functions. Instead, emit copies of the functions. */
  9805. stub_entry->group->needs_save_res = 1;
  9806. stub_entry->stub_type = ppc_stub_save_res;
  9807. return TRUE;
  9808. }
  9809. if (stub_entry->stub_type == ppc_stub_plt_call
  9810. || stub_entry->stub_type == ppc_stub_plt_call_r2save)
  9811. {
  9812. asection *plt;
  9813. off = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1;
  9814. if (off >= (bfd_vma) -2)
  9815. abort ();
  9816. plt = htab->elf.splt;
  9817. if (!htab->elf.dynamic_sections_created
  9818. || stub_entry->h == NULL
  9819. || stub_entry->h->elf.dynindx == -1)
  9820. plt = htab->elf.iplt;
  9821. off += (plt->output_offset
  9822. + plt->output_section->vma
  9823. - elf_gp (plt->output_section->owner)
  9824. - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
  9825. size = plt_stub_size (htab, stub_entry, off);
  9826. if (htab->params->plt_stub_align)
  9827. size += plt_stub_pad (htab, stub_entry, off);
  9828. if (info->emitrelocations)
  9829. {
  9830. stub_entry->group->stub_sec->reloc_count
  9831. += ((PPC_HA (off) != 0)
  9832. + (htab->opd_abi
  9833. ? 2 + (htab->params->plt_static_chain
  9834. && PPC_HA (off + 16) == PPC_HA (off))
  9835. : 1));
  9836. stub_entry->group->stub_sec->flags |= SEC_RELOC;
  9837. }
  9838. }
  9839. else
  9840. {
  9841. /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
  9842. variants. */
  9843. bfd_vma r2off = 0;
  9844. bfd_vma local_off = 0;
  9845. off = (stub_entry->target_value
  9846. + stub_entry->target_section->output_offset
  9847. + stub_entry->target_section->output_section->vma);
  9848. off -= (stub_entry->group->stub_sec->size
  9849. + stub_entry->group->stub_sec->output_offset
  9850. + stub_entry->group->stub_sec->output_section->vma);
  9851. /* Reset the stub type from the plt variant in case we now
  9852. can reach with a shorter stub. */
  9853. if (stub_entry->stub_type >= ppc_stub_plt_branch)
  9854. stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch;
  9855. size = 4;
  9856. if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
  9857. {
  9858. r2off = get_r2off (info, stub_entry);
  9859. if (r2off == (bfd_vma) -1)
  9860. {
  9861. htab->stub_error = TRUE;
  9862. return FALSE;
  9863. }
  9864. size = 8;
  9865. if (PPC_HA (r2off) != 0)
  9866. size += 4;
  9867. if (PPC_LO (r2off) != 0)
  9868. size += 4;
  9869. off -= size - 4;
  9870. }
  9871. local_off = PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
  9872. /* If the branch offset if too big, use a ppc_stub_plt_branch.
  9873. Do the same for -R objects without function descriptors. */
  9874. if (off + (1 << 25) >= (bfd_vma) (1 << 26) - local_off
  9875. || (stub_entry->stub_type == ppc_stub_long_branch_r2off
  9876. && r2off == 0
  9877. && htab->sec_info[stub_entry->target_section->id].toc_off == 0))
  9878. {
  9879. struct ppc_branch_hash_entry *br_entry;
  9880. br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
  9881. stub_entry->root.string + 9,
  9882. TRUE, FALSE);
  9883. if (br_entry == NULL)
  9884. {
  9885. info->callbacks->einfo (_("%P: can't build branch stub `%s'\n"),
  9886. stub_entry->root.string);
  9887. htab->stub_error = TRUE;
  9888. return FALSE;
  9889. }
  9890. if (br_entry->iter != htab->stub_iteration)
  9891. {
  9892. br_entry->iter = htab->stub_iteration;
  9893. br_entry->offset = htab->brlt->size;
  9894. htab->brlt->size += 8;
  9895. if (htab->relbrlt != NULL)
  9896. htab->relbrlt->size += sizeof (Elf64_External_Rela);
  9897. else if (info->emitrelocations)
  9898. {
  9899. htab->brlt->reloc_count += 1;
  9900. htab->brlt->flags |= SEC_RELOC;
  9901. }
  9902. }
  9903. stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch;
  9904. off = (br_entry->offset
  9905. + htab->brlt->output_offset
  9906. + htab->brlt->output_section->vma
  9907. - elf_gp (htab->brlt->output_section->owner)
  9908. - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
  9909. if (info->emitrelocations)
  9910. {
  9911. stub_entry->group->stub_sec->reloc_count
  9912. += 1 + (PPC_HA (off) != 0);
  9913. stub_entry->group->stub_sec->flags |= SEC_RELOC;
  9914. }
  9915. if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
  9916. {
  9917. size = 12;
  9918. if (PPC_HA (off) != 0)
  9919. size = 16;
  9920. }
  9921. else
  9922. {
  9923. size = 16;
  9924. if (PPC_HA (off) != 0)
  9925. size += 4;
  9926. if (PPC_HA (r2off) != 0)
  9927. size += 4;
  9928. if (PPC_LO (r2off) != 0)
  9929. size += 4;
  9930. }
  9931. }
  9932. else if (info->emitrelocations)
  9933. {
  9934. stub_entry->group->stub_sec->reloc_count += 1;
  9935. stub_entry->group->stub_sec->flags |= SEC_RELOC;
  9936. }
  9937. }
  9938. stub_entry->group->stub_sec->size += size;
  9939. return TRUE;
  9940. }
  9941. /* Set up various things so that we can make a list of input sections
  9942. for each output section included in the link. Returns -1 on error,
  9943. 0 when no stubs will be needed, and 1 on success. */
  9944. int
  9945. ppc64_elf_setup_section_lists (struct bfd_link_info *info)
  9946. {
  9947. unsigned int id;
  9948. bfd_size_type amt;
  9949. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  9950. if (htab == NULL)
  9951. return -1;
  9952. htab->sec_info_arr_size = bfd_get_next_section_id ();
  9953. amt = sizeof (*htab->sec_info) * (htab->sec_info_arr_size);
  9954. htab->sec_info = bfd_zmalloc (amt);
  9955. if (htab->sec_info == NULL)
  9956. return -1;
  9957. /* Set toc_off for com, und, abs and ind sections. */
  9958. for (id = 0; id < 3; id++)
  9959. htab->sec_info[id].toc_off = TOC_BASE_OFF;
  9960. return 1;
  9961. }
  9962. /* Set up for first pass at multitoc partitioning. */
  9963. void
  9964. ppc64_elf_start_multitoc_partition (struct bfd_link_info *info)
  9965. {
  9966. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  9967. htab->toc_curr = ppc64_elf_set_toc (info, info->output_bfd);
  9968. htab->toc_bfd = NULL;
  9969. htab->toc_first_sec = NULL;
  9970. }
  9971. /* The linker repeatedly calls this function for each TOC input section
  9972. and linker generated GOT section. Group input bfds such that the toc
  9973. within a group is less than 64k in size. */
  9974. bfd_boolean
  9975. ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
  9976. {
  9977. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  9978. bfd_vma addr, off, limit;
  9979. if (htab == NULL)
  9980. return FALSE;
  9981. if (!htab->second_toc_pass)
  9982. {
  9983. /* Keep track of the first .toc or .got section for this input bfd. */
  9984. bfd_boolean new_bfd = htab->toc_bfd != isec->owner;
  9985. if (new_bfd)
  9986. {
  9987. htab->toc_bfd = isec->owner;
  9988. htab->toc_first_sec = isec;
  9989. }
  9990. addr = isec->output_offset + isec->output_section->vma;
  9991. off = addr - htab->toc_curr;
  9992. limit = 0x80008000;
  9993. if (ppc64_elf_tdata (isec->owner)->has_small_toc_reloc)
  9994. limit = 0x10000;
  9995. if (off + isec->size > limit)
  9996. {
  9997. addr = (htab->toc_first_sec->output_offset
  9998. + htab->toc_first_sec->output_section->vma);
  9999. htab->toc_curr = addr;
  10000. htab->toc_curr &= -TOC_BASE_ALIGN;
  10001. }
  10002. /* toc_curr is the base address of this toc group. Set elf_gp
  10003. for the input section to be the offset relative to the
  10004. output toc base plus 0x8000. Making the input elf_gp an
  10005. offset allows us to move the toc as a whole without
  10006. recalculating input elf_gp. */
  10007. off = htab->toc_curr - elf_gp (isec->output_section->owner);
  10008. off += TOC_BASE_OFF;
  10009. /* Die if someone uses a linker script that doesn't keep input
  10010. file .toc and .got together. */
  10011. if (new_bfd
  10012. && elf_gp (isec->owner) != 0
  10013. && elf_gp (isec->owner) != off)
  10014. return FALSE;
  10015. elf_gp (isec->owner) = off;
  10016. return TRUE;
  10017. }
  10018. /* During the second pass toc_first_sec points to the start of
  10019. a toc group, and toc_curr is used to track the old elf_gp.
  10020. We use toc_bfd to ensure we only look at each bfd once. */
  10021. if (htab->toc_bfd == isec->owner)
  10022. return TRUE;
  10023. htab->toc_bfd = isec->owner;
  10024. if (htab->toc_first_sec == NULL
  10025. || htab->toc_curr != elf_gp (isec->owner))
  10026. {
  10027. htab->toc_curr = elf_gp (isec->owner);
  10028. htab->toc_first_sec = isec;
  10029. }
  10030. addr = (htab->toc_first_sec->output_offset
  10031. + htab->toc_first_sec->output_section->vma);
  10032. off = addr - elf_gp (isec->output_section->owner) + TOC_BASE_OFF;
  10033. elf_gp (isec->owner) = off;
  10034. return TRUE;
  10035. }
  10036. /* Called via elf_link_hash_traverse to merge GOT entries for global
  10037. symbol H. */
  10038. static bfd_boolean
  10039. merge_global_got (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
  10040. {
  10041. if (h->root.type == bfd_link_hash_indirect)
  10042. return TRUE;
  10043. merge_got_entries (&h->got.glist);
  10044. return TRUE;
  10045. }
  10046. /* Called via elf_link_hash_traverse to allocate GOT entries for global
  10047. symbol H. */
  10048. static bfd_boolean
  10049. reallocate_got (struct elf_link_hash_entry *h, void *inf)
  10050. {
  10051. struct got_entry *gent;
  10052. if (h->root.type == bfd_link_hash_indirect)
  10053. return TRUE;
  10054. for (gent = h->got.glist; gent != NULL; gent = gent->next)
  10055. if (!gent->is_indirect)
  10056. allocate_got (h, (struct bfd_link_info *) inf, gent);
  10057. return TRUE;
  10058. }
  10059. /* Called on the first multitoc pass after the last call to
  10060. ppc64_elf_next_toc_section. This function removes duplicate GOT
  10061. entries. */
  10062. bfd_boolean
  10063. ppc64_elf_layout_multitoc (struct bfd_link_info *info)
  10064. {
  10065. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  10066. struct bfd *ibfd, *ibfd2;
  10067. bfd_boolean done_something;
  10068. htab->multi_toc_needed = htab->toc_curr != elf_gp (info->output_bfd);
  10069. if (!htab->do_multi_toc)
  10070. return FALSE;
  10071. /* Merge global sym got entries within a toc group. */
  10072. elf_link_hash_traverse (&htab->elf, merge_global_got, info);
  10073. /* And tlsld_got. */
  10074. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  10075. {
  10076. struct got_entry *ent, *ent2;
  10077. if (!is_ppc64_elf (ibfd))
  10078. continue;
  10079. ent = ppc64_tlsld_got (ibfd);
  10080. if (!ent->is_indirect
  10081. && ent->got.offset != (bfd_vma) -1)
  10082. {
  10083. for (ibfd2 = ibfd->link.next; ibfd2 != NULL; ibfd2 = ibfd2->link.next)
  10084. {
  10085. if (!is_ppc64_elf (ibfd2))
  10086. continue;
  10087. ent2 = ppc64_tlsld_got (ibfd2);
  10088. if (!ent2->is_indirect
  10089. && ent2->got.offset != (bfd_vma) -1
  10090. && elf_gp (ibfd2) == elf_gp (ibfd))
  10091. {
  10092. ent2->is_indirect = TRUE;
  10093. ent2->got.ent = ent;
  10094. }
  10095. }
  10096. }
  10097. }
  10098. /* Zap sizes of got sections. */
  10099. htab->elf.irelplt->rawsize = htab->elf.irelplt->size;
  10100. htab->elf.irelplt->size -= htab->got_reli_size;
  10101. htab->got_reli_size = 0;
  10102. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  10103. {
  10104. asection *got, *relgot;
  10105. if (!is_ppc64_elf (ibfd))
  10106. continue;
  10107. got = ppc64_elf_tdata (ibfd)->got;
  10108. if (got != NULL)
  10109. {
  10110. got->rawsize = got->size;
  10111. got->size = 0;
  10112. relgot = ppc64_elf_tdata (ibfd)->relgot;
  10113. relgot->rawsize = relgot->size;
  10114. relgot->size = 0;
  10115. }
  10116. }
  10117. /* Now reallocate the got, local syms first. We don't need to
  10118. allocate section contents again since we never increase size. */
  10119. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  10120. {
  10121. struct got_entry **lgot_ents;
  10122. struct got_entry **end_lgot_ents;
  10123. struct plt_entry **local_plt;
  10124. struct plt_entry **end_local_plt;
  10125. unsigned char *lgot_masks;
  10126. bfd_size_type locsymcount;
  10127. Elf_Internal_Shdr *symtab_hdr;
  10128. asection *s;
  10129. if (!is_ppc64_elf (ibfd))
  10130. continue;
  10131. lgot_ents = elf_local_got_ents (ibfd);
  10132. if (!lgot_ents)
  10133. continue;
  10134. symtab_hdr = &elf_symtab_hdr (ibfd);
  10135. locsymcount = symtab_hdr->sh_info;
  10136. end_lgot_ents = lgot_ents + locsymcount;
  10137. local_plt = (struct plt_entry **) end_lgot_ents;
  10138. end_local_plt = local_plt + locsymcount;
  10139. lgot_masks = (unsigned char *) end_local_plt;
  10140. s = ppc64_elf_tdata (ibfd)->got;
  10141. for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
  10142. {
  10143. struct got_entry *ent;
  10144. for (ent = *lgot_ents; ent != NULL; ent = ent->next)
  10145. {
  10146. unsigned int ent_size = 8;
  10147. unsigned int rel_size = sizeof (Elf64_External_Rela);
  10148. ent->got.offset = s->size;
  10149. if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
  10150. {
  10151. ent_size *= 2;
  10152. rel_size *= 2;
  10153. }
  10154. s->size += ent_size;
  10155. if ((*lgot_masks & PLT_IFUNC) != 0)
  10156. {
  10157. htab->elf.irelplt->size += rel_size;
  10158. htab->got_reli_size += rel_size;
  10159. }
  10160. else if (bfd_link_pic (info))
  10161. {
  10162. asection *srel = ppc64_elf_tdata (ibfd)->relgot;
  10163. srel->size += rel_size;
  10164. }
  10165. }
  10166. }
  10167. }
  10168. elf_link_hash_traverse (&htab->elf, reallocate_got, info);
  10169. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  10170. {
  10171. struct got_entry *ent;
  10172. if (!is_ppc64_elf (ibfd))
  10173. continue;
  10174. ent = ppc64_tlsld_got (ibfd);
  10175. if (!ent->is_indirect
  10176. && ent->got.offset != (bfd_vma) -1)
  10177. {
  10178. asection *s = ppc64_elf_tdata (ibfd)->got;
  10179. ent->got.offset = s->size;
  10180. s->size += 16;
  10181. if (bfd_link_pic (info))
  10182. {
  10183. asection *srel = ppc64_elf_tdata (ibfd)->relgot;
  10184. srel->size += sizeof (Elf64_External_Rela);
  10185. }
  10186. }
  10187. }
  10188. done_something = htab->elf.irelplt->rawsize != htab->elf.irelplt->size;
  10189. if (!done_something)
  10190. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  10191. {
  10192. asection *got;
  10193. if (!is_ppc64_elf (ibfd))
  10194. continue;
  10195. got = ppc64_elf_tdata (ibfd)->got;
  10196. if (got != NULL)
  10197. {
  10198. done_something = got->rawsize != got->size;
  10199. if (done_something)
  10200. break;
  10201. }
  10202. }
  10203. if (done_something)
  10204. (*htab->params->layout_sections_again) ();
  10205. /* Set up for second pass over toc sections to recalculate elf_gp
  10206. on input sections. */
  10207. htab->toc_bfd = NULL;
  10208. htab->toc_first_sec = NULL;
  10209. htab->second_toc_pass = TRUE;
  10210. return done_something;
  10211. }
  10212. /* Called after second pass of multitoc partitioning. */
  10213. void
  10214. ppc64_elf_finish_multitoc_partition (struct bfd_link_info *info)
  10215. {
  10216. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  10217. /* After the second pass, toc_curr tracks the TOC offset used
  10218. for code sections below in ppc64_elf_next_input_section. */
  10219. htab->toc_curr = TOC_BASE_OFF;
  10220. }
  10221. /* No toc references were found in ISEC. If the code in ISEC makes no
  10222. calls, then there's no need to use toc adjusting stubs when branching
  10223. into ISEC. Actually, indirect calls from ISEC are OK as they will
  10224. load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
  10225. needed, and 2 if a cyclical call-graph was found but no other reason
  10226. for a stub was detected. If called from the top level, a return of
  10227. 2 means the same as a return of 0. */
  10228. static int
  10229. toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec)
  10230. {
  10231. int ret;
  10232. /* Mark this section as checked. */
  10233. isec->call_check_done = 1;
  10234. /* We know none of our code bearing sections will need toc stubs. */
  10235. if ((isec->flags & SEC_LINKER_CREATED) != 0)
  10236. return 0;
  10237. if (isec->size == 0)
  10238. return 0;
  10239. if (isec->output_section == NULL)
  10240. return 0;
  10241. ret = 0;
  10242. if (isec->reloc_count != 0)
  10243. {
  10244. Elf_Internal_Rela *relstart, *rel;
  10245. Elf_Internal_Sym *local_syms;
  10246. struct ppc_link_hash_table *htab;
  10247. relstart = _bfd_elf_link_read_relocs (isec->owner, isec, NULL, NULL,
  10248. info->keep_memory);
  10249. if (relstart == NULL)
  10250. return -1;
  10251. /* Look for branches to outside of this section. */
  10252. local_syms = NULL;
  10253. htab = ppc_hash_table (info);
  10254. if (htab == NULL)
  10255. return -1;
  10256. for (rel = relstart; rel < relstart + isec->reloc_count; ++rel)
  10257. {
  10258. enum elf_ppc64_reloc_type r_type;
  10259. unsigned long r_symndx;
  10260. struct elf_link_hash_entry *h;
  10261. struct ppc_link_hash_entry *eh;
  10262. Elf_Internal_Sym *sym;
  10263. asection *sym_sec;
  10264. struct _opd_sec_data *opd;
  10265. bfd_vma sym_value;
  10266. bfd_vma dest;
  10267. r_type = ELF64_R_TYPE (rel->r_info);
  10268. if (r_type != R_PPC64_REL24
  10269. && r_type != R_PPC64_REL14
  10270. && r_type != R_PPC64_REL14_BRTAKEN
  10271. && r_type != R_PPC64_REL14_BRNTAKEN)
  10272. continue;
  10273. r_symndx = ELF64_R_SYM (rel->r_info);
  10274. if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, r_symndx,
  10275. isec->owner))
  10276. {
  10277. ret = -1;
  10278. break;
  10279. }
  10280. /* Calls to dynamic lib functions go through a plt call stub
  10281. that uses r2. */
  10282. eh = (struct ppc_link_hash_entry *) h;
  10283. if (eh != NULL
  10284. && (eh->elf.plt.plist != NULL
  10285. || (eh->oh != NULL
  10286. && ppc_follow_link (eh->oh)->elf.plt.plist != NULL)))
  10287. {
  10288. ret = 1;
  10289. break;
  10290. }
  10291. if (sym_sec == NULL)
  10292. /* Ignore other undefined symbols. */
  10293. continue;
  10294. /* Assume branches to other sections not included in the
  10295. link need stubs too, to cover -R and absolute syms. */
  10296. if (sym_sec->output_section == NULL)
  10297. {
  10298. ret = 1;
  10299. break;
  10300. }
  10301. if (h == NULL)
  10302. sym_value = sym->st_value;
  10303. else
  10304. {
  10305. if (h->root.type != bfd_link_hash_defined
  10306. && h->root.type != bfd_link_hash_defweak)
  10307. abort ();
  10308. sym_value = h->root.u.def.value;
  10309. }
  10310. sym_value += rel->r_addend;
  10311. /* If this branch reloc uses an opd sym, find the code section. */
  10312. opd = get_opd_info (sym_sec);
  10313. if (opd != NULL)
  10314. {
  10315. if (h == NULL && opd->adjust != NULL)
  10316. {
  10317. long adjust;
  10318. adjust = opd->adjust[OPD_NDX (sym_value)];
  10319. if (adjust == -1)
  10320. /* Assume deleted functions won't ever be called. */
  10321. continue;
  10322. sym_value += adjust;
  10323. }
  10324. dest = opd_entry_value (sym_sec, sym_value,
  10325. &sym_sec, NULL, FALSE);
  10326. if (dest == (bfd_vma) -1)
  10327. continue;
  10328. }
  10329. else
  10330. dest = (sym_value
  10331. + sym_sec->output_offset
  10332. + sym_sec->output_section->vma);
  10333. /* Ignore branch to self. */
  10334. if (sym_sec == isec)
  10335. continue;
  10336. /* If the called function uses the toc, we need a stub. */
  10337. if (sym_sec->has_toc_reloc
  10338. || sym_sec->makes_toc_func_call)
  10339. {
  10340. ret = 1;
  10341. break;
  10342. }
  10343. /* Assume any branch that needs a long branch stub might in fact
  10344. need a plt_branch stub. A plt_branch stub uses r2. */
  10345. else if (dest - (isec->output_offset
  10346. + isec->output_section->vma
  10347. + rel->r_offset) + (1 << 25)
  10348. >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
  10349. ? h->other
  10350. : sym->st_other))
  10351. {
  10352. ret = 1;
  10353. break;
  10354. }
  10355. /* If calling back to a section in the process of being
  10356. tested, we can't say for sure that no toc adjusting stubs
  10357. are needed, so don't return zero. */
  10358. else if (sym_sec->call_check_in_progress)
  10359. ret = 2;
  10360. /* Branches to another section that itself doesn't have any TOC
  10361. references are OK. Recursively call ourselves to check. */
  10362. else if (!sym_sec->call_check_done)
  10363. {
  10364. int recur;
  10365. /* Mark current section as indeterminate, so that other
  10366. sections that call back to current won't be marked as
  10367. known. */
  10368. isec->call_check_in_progress = 1;
  10369. recur = toc_adjusting_stub_needed (info, sym_sec);
  10370. isec->call_check_in_progress = 0;
  10371. if (recur != 0)
  10372. {
  10373. ret = recur;
  10374. if (recur != 2)
  10375. break;
  10376. }
  10377. }
  10378. }
  10379. if (local_syms != NULL
  10380. && (elf_symtab_hdr (isec->owner).contents
  10381. != (unsigned char *) local_syms))
  10382. free (local_syms);
  10383. if (elf_section_data (isec)->relocs != relstart)
  10384. free (relstart);
  10385. }
  10386. if ((ret & 1) == 0
  10387. && isec->map_head.s != NULL
  10388. && (strcmp (isec->output_section->name, ".init") == 0
  10389. || strcmp (isec->output_section->name, ".fini") == 0))
  10390. {
  10391. if (isec->map_head.s->has_toc_reloc
  10392. || isec->map_head.s->makes_toc_func_call)
  10393. ret = 1;
  10394. else if (!isec->map_head.s->call_check_done)
  10395. {
  10396. int recur;
  10397. isec->call_check_in_progress = 1;
  10398. recur = toc_adjusting_stub_needed (info, isec->map_head.s);
  10399. isec->call_check_in_progress = 0;
  10400. if (recur != 0)
  10401. ret = recur;
  10402. }
  10403. }
  10404. if (ret == 1)
  10405. isec->makes_toc_func_call = 1;
  10406. return ret;
  10407. }
  10408. /* The linker repeatedly calls this function for each input section,
  10409. in the order that input sections are linked into output sections.
  10410. Build lists of input sections to determine groupings between which
  10411. we may insert linker stubs. */
  10412. bfd_boolean
  10413. ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec)
  10414. {
  10415. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  10416. if (htab == NULL)
  10417. return FALSE;
  10418. if ((isec->output_section->flags & SEC_CODE) != 0
  10419. && isec->output_section->id < htab->sec_info_arr_size)
  10420. {
  10421. /* This happens to make the list in reverse order,
  10422. which is what we want. */
  10423. htab->sec_info[isec->id].u.list
  10424. = htab->sec_info[isec->output_section->id].u.list;
  10425. htab->sec_info[isec->output_section->id].u.list = isec;
  10426. }
  10427. if (htab->multi_toc_needed)
  10428. {
  10429. /* Analyse sections that aren't already flagged as needing a
  10430. valid toc pointer. Exclude .fixup for the linux kernel.
  10431. .fixup contains branches, but only back to the function that
  10432. hit an exception. */
  10433. if (!(isec->has_toc_reloc
  10434. || (isec->flags & SEC_CODE) == 0
  10435. || strcmp (isec->name, ".fixup") == 0
  10436. || isec->call_check_done))
  10437. {
  10438. if (toc_adjusting_stub_needed (info, isec) < 0)
  10439. return FALSE;
  10440. }
  10441. /* Make all sections use the TOC assigned for this object file.
  10442. This will be wrong for pasted sections; We fix that in
  10443. check_pasted_section(). */
  10444. if (elf_gp (isec->owner) != 0)
  10445. htab->toc_curr = elf_gp (isec->owner);
  10446. }
  10447. htab->sec_info[isec->id].toc_off = htab->toc_curr;
  10448. return TRUE;
  10449. }
  10450. /* Check that all .init and .fini sections use the same toc, if they
  10451. have toc relocs. */
  10452. static bfd_boolean
  10453. check_pasted_section (struct bfd_link_info *info, const char *name)
  10454. {
  10455. asection *o = bfd_get_section_by_name (info->output_bfd, name);
  10456. if (o != NULL)
  10457. {
  10458. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  10459. bfd_vma toc_off = 0;
  10460. asection *i;
  10461. for (i = o->map_head.s; i != NULL; i = i->map_head.s)
  10462. if (i->has_toc_reloc)
  10463. {
  10464. if (toc_off == 0)
  10465. toc_off = htab->sec_info[i->id].toc_off;
  10466. else if (toc_off != htab->sec_info[i->id].toc_off)
  10467. return FALSE;
  10468. }
  10469. if (toc_off == 0)
  10470. for (i = o->map_head.s; i != NULL; i = i->map_head.s)
  10471. if (i->makes_toc_func_call)
  10472. {
  10473. toc_off = htab->sec_info[i->id].toc_off;
  10474. break;
  10475. }
  10476. /* Make sure the whole pasted function uses the same toc offset. */
  10477. if (toc_off != 0)
  10478. for (i = o->map_head.s; i != NULL; i = i->map_head.s)
  10479. htab->sec_info[i->id].toc_off = toc_off;
  10480. }
  10481. return TRUE;
  10482. }
  10483. bfd_boolean
  10484. ppc64_elf_check_init_fini (struct bfd_link_info *info)
  10485. {
  10486. return (check_pasted_section (info, ".init")
  10487. & check_pasted_section (info, ".fini"));
  10488. }
  10489. /* See whether we can group stub sections together. Grouping stub
  10490. sections may result in fewer stubs. More importantly, we need to
  10491. put all .init* and .fini* stubs at the beginning of the .init or
  10492. .fini output sections respectively, because glibc splits the
  10493. _init and _fini functions into multiple parts. Putting a stub in
  10494. the middle of a function is not a good idea. */
  10495. static bfd_boolean
  10496. group_sections (struct bfd_link_info *info,
  10497. bfd_size_type stub_group_size,
  10498. bfd_boolean stubs_always_before_branch)
  10499. {
  10500. struct ppc_link_hash_table *htab;
  10501. asection *osec;
  10502. bfd_size_type stub14_group_size;
  10503. bfd_boolean suppress_size_errors;
  10504. htab = ppc_hash_table (info);
  10505. if (htab == NULL)
  10506. return FALSE;
  10507. suppress_size_errors = FALSE;
  10508. stub14_group_size = stub_group_size >> 10;
  10509. if (stub_group_size == 1)
  10510. {
  10511. /* Default values. */
  10512. if (stubs_always_before_branch)
  10513. {
  10514. stub_group_size = 0x1e00000;
  10515. stub14_group_size = 0x7800;
  10516. }
  10517. else
  10518. {
  10519. stub_group_size = 0x1c00000;
  10520. stub14_group_size = 0x7000;
  10521. }
  10522. suppress_size_errors = TRUE;
  10523. }
  10524. for (osec = info->output_bfd->sections; osec != NULL; osec = osec->next)
  10525. {
  10526. asection *tail;
  10527. if (osec->id >= htab->sec_info_arr_size)
  10528. continue;
  10529. tail = htab->sec_info[osec->id].u.list;
  10530. while (tail != NULL)
  10531. {
  10532. asection *curr;
  10533. asection *prev;
  10534. bfd_size_type total;
  10535. bfd_boolean big_sec;
  10536. bfd_vma curr_toc;
  10537. struct map_stub *group;
  10538. curr = tail;
  10539. total = tail->size;
  10540. big_sec = total > (ppc64_elf_section_data (tail) != NULL
  10541. && ppc64_elf_section_data (tail)->has_14bit_branch
  10542. ? stub14_group_size : stub_group_size);
  10543. if (big_sec && !suppress_size_errors)
  10544. (*_bfd_error_handler) (_("%B section %A exceeds stub group size"),
  10545. tail->owner, tail);
  10546. curr_toc = htab->sec_info[tail->id].toc_off;
  10547. while ((prev = htab->sec_info[curr->id].u.list) != NULL
  10548. && ((total += curr->output_offset - prev->output_offset)
  10549. < (ppc64_elf_section_data (prev) != NULL
  10550. && ppc64_elf_section_data (prev)->has_14bit_branch
  10551. ? stub14_group_size : stub_group_size))
  10552. && htab->sec_info[prev->id].toc_off == curr_toc)
  10553. curr = prev;
  10554. /* OK, the size from the start of CURR to the end is less
  10555. than stub_group_size and thus can be handled by one stub
  10556. section. (or the tail section is itself larger than
  10557. stub_group_size, in which case we may be toast.) We
  10558. should really be keeping track of the total size of stubs
  10559. added here, as stubs contribute to the final output
  10560. section size. That's a little tricky, and this way will
  10561. only break if stubs added make the total size more than
  10562. 2^25, ie. for the default stub_group_size, if stubs total
  10563. more than 2097152 bytes, or nearly 75000 plt call stubs. */
  10564. group = bfd_alloc (curr->owner, sizeof (*group));
  10565. if (group == NULL)
  10566. return FALSE;
  10567. group->link_sec = curr;
  10568. group->stub_sec = NULL;
  10569. group->needs_save_res = 0;
  10570. group->next = htab->group;
  10571. htab->group = group;
  10572. do
  10573. {
  10574. prev = htab->sec_info[tail->id].u.list;
  10575. /* Set up this stub group. */
  10576. htab->sec_info[tail->id].u.group = group;
  10577. }
  10578. while (tail != curr && (tail = prev) != NULL);
  10579. /* But wait, there's more! Input sections up to stub_group_size
  10580. bytes before the stub section can be handled by it too.
  10581. Don't do this if we have a really large section after the
  10582. stubs, as adding more stubs increases the chance that
  10583. branches may not reach into the stub section. */
  10584. if (!stubs_always_before_branch && !big_sec)
  10585. {
  10586. total = 0;
  10587. while (prev != NULL
  10588. && ((total += tail->output_offset - prev->output_offset)
  10589. < (ppc64_elf_section_data (prev) != NULL
  10590. && ppc64_elf_section_data (prev)->has_14bit_branch
  10591. ? stub14_group_size : stub_group_size))
  10592. && htab->sec_info[prev->id].toc_off == curr_toc)
  10593. {
  10594. tail = prev;
  10595. prev = htab->sec_info[tail->id].u.list;
  10596. htab->sec_info[tail->id].u.group = group;
  10597. }
  10598. }
  10599. tail = prev;
  10600. }
  10601. }
  10602. return TRUE;
  10603. }
  10604. static const unsigned char glink_eh_frame_cie[] =
  10605. {
  10606. 0, 0, 0, 16, /* length. */
  10607. 0, 0, 0, 0, /* id. */
  10608. 1, /* CIE version. */
  10609. 'z', 'R', 0, /* Augmentation string. */
  10610. 4, /* Code alignment. */
  10611. 0x78, /* Data alignment. */
  10612. 65, /* RA reg. */
  10613. 1, /* Augmentation size. */
  10614. DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding. */
  10615. DW_CFA_def_cfa, 1, 0, /* def_cfa: r1 offset 0. */
  10616. 0, 0, 0, 0
  10617. };
  10618. /* Stripping output sections is normally done before dynamic section
  10619. symbols have been allocated. This function is called later, and
  10620. handles cases like htab->brlt which is mapped to its own output
  10621. section. */
  10622. static void
  10623. maybe_strip_output (struct bfd_link_info *info, asection *isec)
  10624. {
  10625. if (isec->size == 0
  10626. && isec->output_section->size == 0
  10627. && !(isec->output_section->flags & SEC_KEEP)
  10628. && !bfd_section_removed_from_list (info->output_bfd,
  10629. isec->output_section)
  10630. && elf_section_data (isec->output_section)->dynindx == 0)
  10631. {
  10632. isec->output_section->flags |= SEC_EXCLUDE;
  10633. bfd_section_list_remove (info->output_bfd, isec->output_section);
  10634. info->output_bfd->section_count--;
  10635. }
  10636. }
  10637. /* Determine and set the size of the stub section for a final link.
  10638. The basic idea here is to examine all the relocations looking for
  10639. PC-relative calls to a target that is unreachable with a "bl"
  10640. instruction. */
  10641. bfd_boolean
  10642. ppc64_elf_size_stubs (struct bfd_link_info *info)
  10643. {
  10644. bfd_size_type stub_group_size;
  10645. bfd_boolean stubs_always_before_branch;
  10646. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  10647. if (htab == NULL)
  10648. return FALSE;
  10649. if (htab->params->plt_thread_safe == -1 && !bfd_link_executable (info))
  10650. htab->params->plt_thread_safe = 1;
  10651. if (!htab->opd_abi)
  10652. htab->params->plt_thread_safe = 0;
  10653. else if (htab->params->plt_thread_safe == -1)
  10654. {
  10655. static const char *const thread_starter[] =
  10656. {
  10657. "pthread_create",
  10658. /* libstdc++ */
  10659. "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
  10660. /* librt */
  10661. "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
  10662. "mq_notify", "create_timer",
  10663. /* libanl */
  10664. "getaddrinfo_a",
  10665. /* libgomp */
  10666. "GOMP_parallel",
  10667. "GOMP_parallel_start",
  10668. "GOMP_parallel_loop_static",
  10669. "GOMP_parallel_loop_static_start",
  10670. "GOMP_parallel_loop_dynamic",
  10671. "GOMP_parallel_loop_dynamic_start",
  10672. "GOMP_parallel_loop_guided",
  10673. "GOMP_parallel_loop_guided_start",
  10674. "GOMP_parallel_loop_runtime",
  10675. "GOMP_parallel_loop_runtime_start",
  10676. "GOMP_parallel_sections",
  10677. "GOMP_parallel_sections_start",
  10678. /* libgo */
  10679. "__go_go",
  10680. };
  10681. unsigned i;
  10682. for (i = 0; i < ARRAY_SIZE (thread_starter); i++)
  10683. {
  10684. struct elf_link_hash_entry *h;
  10685. h = elf_link_hash_lookup (&htab->elf, thread_starter[i],
  10686. FALSE, FALSE, TRUE);
  10687. htab->params->plt_thread_safe = h != NULL && h->ref_regular;
  10688. if (htab->params->plt_thread_safe)
  10689. break;
  10690. }
  10691. }
  10692. stubs_always_before_branch = htab->params->group_size < 0;
  10693. if (htab->params->group_size < 0)
  10694. stub_group_size = -htab->params->group_size;
  10695. else
  10696. stub_group_size = htab->params->group_size;
  10697. if (!group_sections (info, stub_group_size, stubs_always_before_branch))
  10698. return FALSE;
  10699. while (1)
  10700. {
  10701. bfd *input_bfd;
  10702. unsigned int bfd_indx;
  10703. struct map_stub *group;
  10704. asection *stub_sec;
  10705. htab->stub_iteration += 1;
  10706. for (input_bfd = info->input_bfds, bfd_indx = 0;
  10707. input_bfd != NULL;
  10708. input_bfd = input_bfd->link.next, bfd_indx++)
  10709. {
  10710. Elf_Internal_Shdr *symtab_hdr;
  10711. asection *section;
  10712. Elf_Internal_Sym *local_syms = NULL;
  10713. if (!is_ppc64_elf (input_bfd))
  10714. continue;
  10715. /* We'll need the symbol table in a second. */
  10716. symtab_hdr = &elf_symtab_hdr (input_bfd);
  10717. if (symtab_hdr->sh_info == 0)
  10718. continue;
  10719. /* Walk over each section attached to the input bfd. */
  10720. for (section = input_bfd->sections;
  10721. section != NULL;
  10722. section = section->next)
  10723. {
  10724. Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
  10725. /* If there aren't any relocs, then there's nothing more
  10726. to do. */
  10727. if ((section->flags & SEC_RELOC) == 0
  10728. || (section->flags & SEC_ALLOC) == 0
  10729. || (section->flags & SEC_LOAD) == 0
  10730. || (section->flags & SEC_CODE) == 0
  10731. || section->reloc_count == 0)
  10732. continue;
  10733. /* If this section is a link-once section that will be
  10734. discarded, then don't create any stubs. */
  10735. if (section->output_section == NULL
  10736. || section->output_section->owner != info->output_bfd)
  10737. continue;
  10738. /* Get the relocs. */
  10739. internal_relocs
  10740. = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL,
  10741. info->keep_memory);
  10742. if (internal_relocs == NULL)
  10743. goto error_ret_free_local;
  10744. /* Now examine each relocation. */
  10745. irela = internal_relocs;
  10746. irelaend = irela + section->reloc_count;
  10747. for (; irela < irelaend; irela++)
  10748. {
  10749. enum elf_ppc64_reloc_type r_type;
  10750. unsigned int r_indx;
  10751. enum ppc_stub_type stub_type;
  10752. struct ppc_stub_hash_entry *stub_entry;
  10753. asection *sym_sec, *code_sec;
  10754. bfd_vma sym_value, code_value;
  10755. bfd_vma destination;
  10756. unsigned long local_off;
  10757. bfd_boolean ok_dest;
  10758. struct ppc_link_hash_entry *hash;
  10759. struct ppc_link_hash_entry *fdh;
  10760. struct elf_link_hash_entry *h;
  10761. Elf_Internal_Sym *sym;
  10762. char *stub_name;
  10763. const asection *id_sec;
  10764. struct _opd_sec_data *opd;
  10765. struct plt_entry *plt_ent;
  10766. r_type = ELF64_R_TYPE (irela->r_info);
  10767. r_indx = ELF64_R_SYM (irela->r_info);
  10768. if (r_type >= R_PPC64_max)
  10769. {
  10770. bfd_set_error (bfd_error_bad_value);
  10771. goto error_ret_free_internal;
  10772. }
  10773. /* Only look for stubs on branch instructions. */
  10774. if (r_type != R_PPC64_REL24
  10775. && r_type != R_PPC64_REL14
  10776. && r_type != R_PPC64_REL14_BRTAKEN
  10777. && r_type != R_PPC64_REL14_BRNTAKEN)
  10778. continue;
  10779. /* Now determine the call target, its name, value,
  10780. section. */
  10781. if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
  10782. r_indx, input_bfd))
  10783. goto error_ret_free_internal;
  10784. hash = (struct ppc_link_hash_entry *) h;
  10785. ok_dest = FALSE;
  10786. fdh = NULL;
  10787. sym_value = 0;
  10788. if (hash == NULL)
  10789. {
  10790. sym_value = sym->st_value;
  10791. ok_dest = TRUE;
  10792. }
  10793. else if (hash->elf.root.type == bfd_link_hash_defined
  10794. || hash->elf.root.type == bfd_link_hash_defweak)
  10795. {
  10796. sym_value = hash->elf.root.u.def.value;
  10797. if (sym_sec->output_section != NULL)
  10798. ok_dest = TRUE;
  10799. }
  10800. else if (hash->elf.root.type == bfd_link_hash_undefweak
  10801. || hash->elf.root.type == bfd_link_hash_undefined)
  10802. {
  10803. /* Recognise an old ABI func code entry sym, and
  10804. use the func descriptor sym instead if it is
  10805. defined. */
  10806. if (hash->elf.root.root.string[0] == '.'
  10807. && (fdh = lookup_fdh (hash, htab)) != NULL)
  10808. {
  10809. if (fdh->elf.root.type == bfd_link_hash_defined
  10810. || fdh->elf.root.type == bfd_link_hash_defweak)
  10811. {
  10812. sym_sec = fdh->elf.root.u.def.section;
  10813. sym_value = fdh->elf.root.u.def.value;
  10814. if (sym_sec->output_section != NULL)
  10815. ok_dest = TRUE;
  10816. }
  10817. else
  10818. fdh = NULL;
  10819. }
  10820. }
  10821. else
  10822. {
  10823. bfd_set_error (bfd_error_bad_value);
  10824. goto error_ret_free_internal;
  10825. }
  10826. destination = 0;
  10827. local_off = 0;
  10828. if (ok_dest)
  10829. {
  10830. sym_value += irela->r_addend;
  10831. destination = (sym_value
  10832. + sym_sec->output_offset
  10833. + sym_sec->output_section->vma);
  10834. local_off = PPC64_LOCAL_ENTRY_OFFSET (hash
  10835. ? hash->elf.other
  10836. : sym->st_other);
  10837. }
  10838. code_sec = sym_sec;
  10839. code_value = sym_value;
  10840. opd = get_opd_info (sym_sec);
  10841. if (opd != NULL)
  10842. {
  10843. bfd_vma dest;
  10844. if (hash == NULL && opd->adjust != NULL)
  10845. {
  10846. long adjust = opd->adjust[OPD_NDX (sym_value)];
  10847. if (adjust == -1)
  10848. continue;
  10849. code_value += adjust;
  10850. sym_value += adjust;
  10851. }
  10852. dest = opd_entry_value (sym_sec, sym_value,
  10853. &code_sec, &code_value, FALSE);
  10854. if (dest != (bfd_vma) -1)
  10855. {
  10856. destination = dest;
  10857. if (fdh != NULL)
  10858. {
  10859. /* Fixup old ABI sym to point at code
  10860. entry. */
  10861. hash->elf.root.type = bfd_link_hash_defweak;
  10862. hash->elf.root.u.def.section = code_sec;
  10863. hash->elf.root.u.def.value = code_value;
  10864. }
  10865. }
  10866. }
  10867. /* Determine what (if any) linker stub is needed. */
  10868. plt_ent = NULL;
  10869. stub_type = ppc_type_of_stub (section, irela, &hash,
  10870. &plt_ent, destination,
  10871. local_off);
  10872. if (stub_type != ppc_stub_plt_call)
  10873. {
  10874. /* Check whether we need a TOC adjusting stub.
  10875. Since the linker pastes together pieces from
  10876. different object files when creating the
  10877. _init and _fini functions, it may be that a
  10878. call to what looks like a local sym is in
  10879. fact a call needing a TOC adjustment. */
  10880. if (code_sec != NULL
  10881. && code_sec->output_section != NULL
  10882. && (htab->sec_info[code_sec->id].toc_off
  10883. != htab->sec_info[section->id].toc_off)
  10884. && (code_sec->has_toc_reloc
  10885. || code_sec->makes_toc_func_call))
  10886. stub_type = ppc_stub_long_branch_r2off;
  10887. }
  10888. if (stub_type == ppc_stub_none)
  10889. continue;
  10890. /* __tls_get_addr calls might be eliminated. */
  10891. if (stub_type != ppc_stub_plt_call
  10892. && hash != NULL
  10893. && (hash == htab->tls_get_addr
  10894. || hash == htab->tls_get_addr_fd)
  10895. && section->has_tls_reloc
  10896. && irela != internal_relocs)
  10897. {
  10898. /* Get tls info. */
  10899. unsigned char *tls_mask;
  10900. if (!get_tls_mask (&tls_mask, NULL, NULL, &local_syms,
  10901. irela - 1, input_bfd))
  10902. goto error_ret_free_internal;
  10903. if (*tls_mask != 0)
  10904. continue;
  10905. }
  10906. if (stub_type == ppc_stub_plt_call
  10907. && irela + 1 < irelaend
  10908. && irela[1].r_offset == irela->r_offset + 4
  10909. && ELF64_R_TYPE (irela[1].r_info) == R_PPC64_TOCSAVE)
  10910. {
  10911. if (!tocsave_find (htab, INSERT,
  10912. &local_syms, irela + 1, input_bfd))
  10913. goto error_ret_free_internal;
  10914. }
  10915. else if (stub_type == ppc_stub_plt_call)
  10916. stub_type = ppc_stub_plt_call_r2save;
  10917. /* Support for grouping stub sections. */
  10918. id_sec = htab->sec_info[section->id].u.group->link_sec;
  10919. /* Get the name of this stub. */
  10920. stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
  10921. if (!stub_name)
  10922. goto error_ret_free_internal;
  10923. stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
  10924. stub_name, FALSE, FALSE);
  10925. if (stub_entry != NULL)
  10926. {
  10927. /* The proper stub has already been created. */
  10928. free (stub_name);
  10929. if (stub_type == ppc_stub_plt_call_r2save)
  10930. stub_entry->stub_type = stub_type;
  10931. continue;
  10932. }
  10933. stub_entry = ppc_add_stub (stub_name, section, info);
  10934. if (stub_entry == NULL)
  10935. {
  10936. free (stub_name);
  10937. error_ret_free_internal:
  10938. if (elf_section_data (section)->relocs == NULL)
  10939. free (internal_relocs);
  10940. error_ret_free_local:
  10941. if (local_syms != NULL
  10942. && (symtab_hdr->contents
  10943. != (unsigned char *) local_syms))
  10944. free (local_syms);
  10945. return FALSE;
  10946. }
  10947. stub_entry->stub_type = stub_type;
  10948. if (stub_type != ppc_stub_plt_call
  10949. && stub_type != ppc_stub_plt_call_r2save)
  10950. {
  10951. stub_entry->target_value = code_value;
  10952. stub_entry->target_section = code_sec;
  10953. }
  10954. else
  10955. {
  10956. stub_entry->target_value = sym_value;
  10957. stub_entry->target_section = sym_sec;
  10958. }
  10959. stub_entry->h = hash;
  10960. stub_entry->plt_ent = plt_ent;
  10961. stub_entry->other = hash ? hash->elf.other : sym->st_other;
  10962. if (stub_entry->h != NULL)
  10963. htab->stub_globals += 1;
  10964. }
  10965. /* We're done with the internal relocs, free them. */
  10966. if (elf_section_data (section)->relocs != internal_relocs)
  10967. free (internal_relocs);
  10968. }
  10969. if (local_syms != NULL
  10970. && symtab_hdr->contents != (unsigned char *) local_syms)
  10971. {
  10972. if (!info->keep_memory)
  10973. free (local_syms);
  10974. else
  10975. symtab_hdr->contents = (unsigned char *) local_syms;
  10976. }
  10977. }
  10978. /* We may have added some stubs. Find out the new size of the
  10979. stub sections. */
  10980. for (stub_sec = htab->params->stub_bfd->sections;
  10981. stub_sec != NULL;
  10982. stub_sec = stub_sec->next)
  10983. if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
  10984. {
  10985. stub_sec->rawsize = stub_sec->size;
  10986. stub_sec->size = 0;
  10987. stub_sec->reloc_count = 0;
  10988. stub_sec->flags &= ~SEC_RELOC;
  10989. }
  10990. htab->brlt->size = 0;
  10991. htab->brlt->reloc_count = 0;
  10992. htab->brlt->flags &= ~SEC_RELOC;
  10993. if (htab->relbrlt != NULL)
  10994. htab->relbrlt->size = 0;
  10995. bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info);
  10996. for (group = htab->group; group != NULL; group = group->next)
  10997. if (group->needs_save_res)
  10998. group->stub_sec->size += htab->sfpr->size;
  10999. if (info->emitrelocations
  11000. && htab->glink != NULL && htab->glink->size != 0)
  11001. {
  11002. htab->glink->reloc_count = 1;
  11003. htab->glink->flags |= SEC_RELOC;
  11004. }
  11005. if (htab->glink_eh_frame != NULL
  11006. && !bfd_is_abs_section (htab->glink_eh_frame->output_section)
  11007. && htab->glink_eh_frame->output_section->size != 0)
  11008. {
  11009. size_t size = 0, align;
  11010. for (stub_sec = htab->params->stub_bfd->sections;
  11011. stub_sec != NULL;
  11012. stub_sec = stub_sec->next)
  11013. if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
  11014. size += 24;
  11015. if (htab->glink != NULL && htab->glink->size != 0)
  11016. size += 24;
  11017. if (size != 0)
  11018. size += sizeof (glink_eh_frame_cie);
  11019. align = 1;
  11020. align <<= htab->glink_eh_frame->output_section->alignment_power;
  11021. align -= 1;
  11022. size = (size + align) & ~align;
  11023. htab->glink_eh_frame->rawsize = htab->glink_eh_frame->size;
  11024. htab->glink_eh_frame->size = size;
  11025. }
  11026. if (htab->params->plt_stub_align != 0)
  11027. for (stub_sec = htab->params->stub_bfd->sections;
  11028. stub_sec != NULL;
  11029. stub_sec = stub_sec->next)
  11030. if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
  11031. stub_sec->size = ((stub_sec->size
  11032. + (1 << htab->params->plt_stub_align) - 1)
  11033. & (-1 << htab->params->plt_stub_align));
  11034. for (stub_sec = htab->params->stub_bfd->sections;
  11035. stub_sec != NULL;
  11036. stub_sec = stub_sec->next)
  11037. if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
  11038. && stub_sec->rawsize != stub_sec->size)
  11039. break;
  11040. /* Exit from this loop when no stubs have been added, and no stubs
  11041. have changed size. */
  11042. if (stub_sec == NULL
  11043. && (htab->glink_eh_frame == NULL
  11044. || htab->glink_eh_frame->rawsize == htab->glink_eh_frame->size))
  11045. break;
  11046. /* Ask the linker to do its stuff. */
  11047. (*htab->params->layout_sections_again) ();
  11048. }
  11049. if (htab->glink_eh_frame != NULL
  11050. && htab->glink_eh_frame->size != 0)
  11051. {
  11052. bfd_vma val;
  11053. bfd_byte *p, *last_fde;
  11054. size_t last_fde_len, size, align, pad;
  11055. asection *stub_sec;
  11056. p = bfd_zalloc (htab->glink_eh_frame->owner, htab->glink_eh_frame->size);
  11057. if (p == NULL)
  11058. return FALSE;
  11059. htab->glink_eh_frame->contents = p;
  11060. last_fde = p;
  11061. memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
  11062. /* CIE length (rewrite in case little-endian). */
  11063. last_fde_len = sizeof (glink_eh_frame_cie) - 4;
  11064. bfd_put_32 (htab->elf.dynobj, last_fde_len, p);
  11065. p += sizeof (glink_eh_frame_cie);
  11066. for (stub_sec = htab->params->stub_bfd->sections;
  11067. stub_sec != NULL;
  11068. stub_sec = stub_sec->next)
  11069. if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
  11070. {
  11071. last_fde = p;
  11072. last_fde_len = 20;
  11073. /* FDE length. */
  11074. bfd_put_32 (htab->elf.dynobj, 20, p);
  11075. p += 4;
  11076. /* CIE pointer. */
  11077. val = p - htab->glink_eh_frame->contents;
  11078. bfd_put_32 (htab->elf.dynobj, val, p);
  11079. p += 4;
  11080. /* Offset to stub section, written later. */
  11081. p += 4;
  11082. /* stub section size. */
  11083. bfd_put_32 (htab->elf.dynobj, stub_sec->size, p);
  11084. p += 4;
  11085. /* Augmentation. */
  11086. p += 1;
  11087. /* Pad. */
  11088. p += 7;
  11089. }
  11090. if (htab->glink != NULL && htab->glink->size != 0)
  11091. {
  11092. last_fde = p;
  11093. last_fde_len = 20;
  11094. /* FDE length. */
  11095. bfd_put_32 (htab->elf.dynobj, 20, p);
  11096. p += 4;
  11097. /* CIE pointer. */
  11098. val = p - htab->glink_eh_frame->contents;
  11099. bfd_put_32 (htab->elf.dynobj, val, p);
  11100. p += 4;
  11101. /* Offset to .glink, written later. */
  11102. p += 4;
  11103. /* .glink size. */
  11104. bfd_put_32 (htab->elf.dynobj, htab->glink->size - 8, p);
  11105. p += 4;
  11106. /* Augmentation. */
  11107. p += 1;
  11108. *p++ = DW_CFA_advance_loc + 1;
  11109. *p++ = DW_CFA_register;
  11110. *p++ = 65;
  11111. *p++ = htab->opd_abi ? 12 : 0;
  11112. *p++ = DW_CFA_advance_loc + 4;
  11113. *p++ = DW_CFA_restore_extended;
  11114. *p++ = 65;
  11115. }
  11116. /* Subsume any padding into the last FDE if user .eh_frame
  11117. sections are aligned more than glink_eh_frame. Otherwise any
  11118. zero padding will be seen as a terminator. */
  11119. size = p - htab->glink_eh_frame->contents;
  11120. align = 1;
  11121. align <<= htab->glink_eh_frame->output_section->alignment_power;
  11122. align -= 1;
  11123. pad = ((size + align) & ~align) - size;
  11124. htab->glink_eh_frame->size = size + pad;
  11125. bfd_put_32 (htab->elf.dynobj, last_fde_len + pad, last_fde);
  11126. }
  11127. maybe_strip_output (info, htab->brlt);
  11128. if (htab->glink_eh_frame != NULL)
  11129. maybe_strip_output (info, htab->glink_eh_frame);
  11130. return TRUE;
  11131. }
  11132. /* Called after we have determined section placement. If sections
  11133. move, we'll be called again. Provide a value for TOCstart. */
  11134. bfd_vma
  11135. ppc64_elf_set_toc (struct bfd_link_info *info, bfd *obfd)
  11136. {
  11137. asection *s;
  11138. bfd_vma TOCstart, adjust;
  11139. if (info != NULL)
  11140. {
  11141. struct elf_link_hash_entry *h;
  11142. struct elf_link_hash_table *htab = elf_hash_table (info);
  11143. if (is_elf_hash_table (htab)
  11144. && htab->hgot != NULL)
  11145. h = htab->hgot;
  11146. else
  11147. {
  11148. h = elf_link_hash_lookup (htab, ".TOC.", FALSE, FALSE, TRUE);
  11149. if (is_elf_hash_table (htab))
  11150. htab->hgot = h;
  11151. }
  11152. if (h != NULL
  11153. && h->root.type == bfd_link_hash_defined
  11154. && !h->root.linker_def
  11155. && (!is_elf_hash_table (htab)
  11156. || h->def_regular))
  11157. {
  11158. TOCstart = (h->root.u.def.value - TOC_BASE_OFF
  11159. + h->root.u.def.section->output_offset
  11160. + h->root.u.def.section->output_section->vma);
  11161. _bfd_set_gp_value (obfd, TOCstart);
  11162. return TOCstart;
  11163. }
  11164. }
  11165. /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
  11166. order. The TOC starts where the first of these sections starts. */
  11167. s = bfd_get_section_by_name (obfd, ".got");
  11168. if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
  11169. s = bfd_get_section_by_name (obfd, ".toc");
  11170. if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
  11171. s = bfd_get_section_by_name (obfd, ".tocbss");
  11172. if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
  11173. s = bfd_get_section_by_name (obfd, ".plt");
  11174. if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
  11175. {
  11176. /* This may happen for
  11177. o references to TOC base (SYM@toc / TOC[tc0]) without a
  11178. .toc directive
  11179. o bad linker script
  11180. o --gc-sections and empty TOC sections
  11181. FIXME: Warn user? */
  11182. /* Look for a likely section. We probably won't even be
  11183. using TOCstart. */
  11184. for (s = obfd->sections; s != NULL; s = s->next)
  11185. if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY
  11186. | SEC_EXCLUDE))
  11187. == (SEC_ALLOC | SEC_SMALL_DATA))
  11188. break;
  11189. if (s == NULL)
  11190. for (s = obfd->sections; s != NULL; s = s->next)
  11191. if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_EXCLUDE))
  11192. == (SEC_ALLOC | SEC_SMALL_DATA))
  11193. break;
  11194. if (s == NULL)
  11195. for (s = obfd->sections; s != NULL; s = s->next)
  11196. if ((s->flags & (SEC_ALLOC | SEC_READONLY | SEC_EXCLUDE))
  11197. == SEC_ALLOC)
  11198. break;
  11199. if (s == NULL)
  11200. for (s = obfd->sections; s != NULL; s = s->next)
  11201. if ((s->flags & (SEC_ALLOC | SEC_EXCLUDE)) == SEC_ALLOC)
  11202. break;
  11203. }
  11204. TOCstart = 0;
  11205. if (s != NULL)
  11206. TOCstart = s->output_section->vma + s->output_offset;
  11207. /* Force alignment. */
  11208. adjust = TOCstart & (TOC_BASE_ALIGN - 1);
  11209. TOCstart -= adjust;
  11210. _bfd_set_gp_value (obfd, TOCstart);
  11211. if (info != NULL && s != NULL)
  11212. {
  11213. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  11214. if (htab != NULL)
  11215. {
  11216. if (htab->elf.hgot != NULL)
  11217. {
  11218. htab->elf.hgot->root.u.def.value = TOC_BASE_OFF - adjust;
  11219. htab->elf.hgot->root.u.def.section = s;
  11220. }
  11221. }
  11222. else
  11223. {
  11224. struct bfd_link_hash_entry *bh = NULL;
  11225. _bfd_generic_link_add_one_symbol (info, obfd, ".TOC.", BSF_GLOBAL,
  11226. s, TOC_BASE_OFF - adjust,
  11227. NULL, FALSE, FALSE, &bh);
  11228. }
  11229. }
  11230. return TOCstart;
  11231. }
  11232. /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
  11233. write out any global entry stubs. */
  11234. static bfd_boolean
  11235. build_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
  11236. {
  11237. struct bfd_link_info *info;
  11238. struct ppc_link_hash_table *htab;
  11239. struct plt_entry *pent;
  11240. asection *s;
  11241. if (h->root.type == bfd_link_hash_indirect)
  11242. return TRUE;
  11243. if (!h->pointer_equality_needed)
  11244. return TRUE;
  11245. if (h->def_regular)
  11246. return TRUE;
  11247. info = inf;
  11248. htab = ppc_hash_table (info);
  11249. if (htab == NULL)
  11250. return FALSE;
  11251. s = htab->glink;
  11252. for (pent = h->plt.plist; pent != NULL; pent = pent->next)
  11253. if (pent->plt.offset != (bfd_vma) -1
  11254. && pent->addend == 0)
  11255. {
  11256. bfd_byte *p;
  11257. asection *plt;
  11258. bfd_vma off;
  11259. p = s->contents + h->root.u.def.value;
  11260. plt = htab->elf.splt;
  11261. if (!htab->elf.dynamic_sections_created
  11262. || h->dynindx == -1)
  11263. plt = htab->elf.iplt;
  11264. off = pent->plt.offset + plt->output_offset + plt->output_section->vma;
  11265. off -= h->root.u.def.value + s->output_offset + s->output_section->vma;
  11266. if (off + 0x80008000 > 0xffffffff || (off & 3) != 0)
  11267. {
  11268. info->callbacks->einfo
  11269. (_("%P: linkage table error against `%T'\n"),
  11270. h->root.root.string);
  11271. bfd_set_error (bfd_error_bad_value);
  11272. htab->stub_error = TRUE;
  11273. }
  11274. htab->stub_count[ppc_stub_global_entry - 1] += 1;
  11275. if (htab->params->emit_stub_syms)
  11276. {
  11277. size_t len = strlen (h->root.root.string);
  11278. char *name = bfd_malloc (sizeof "12345678.global_entry." + len);
  11279. if (name == NULL)
  11280. return FALSE;
  11281. sprintf (name, "%08x.global_entry.%s", s->id, h->root.root.string);
  11282. h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
  11283. if (h == NULL)
  11284. return FALSE;
  11285. if (h->root.type == bfd_link_hash_new)
  11286. {
  11287. h->root.type = bfd_link_hash_defined;
  11288. h->root.u.def.section = s;
  11289. h->root.u.def.value = p - s->contents;
  11290. h->ref_regular = 1;
  11291. h->def_regular = 1;
  11292. h->ref_regular_nonweak = 1;
  11293. h->forced_local = 1;
  11294. h->non_elf = 0;
  11295. h->root.linker_def = 1;
  11296. }
  11297. }
  11298. if (PPC_HA (off) != 0)
  11299. {
  11300. bfd_put_32 (s->owner, ADDIS_R12_R12 | PPC_HA (off), p);
  11301. p += 4;
  11302. }
  11303. bfd_put_32 (s->owner, LD_R12_0R12 | PPC_LO (off), p);
  11304. p += 4;
  11305. bfd_put_32 (s->owner, MTCTR_R12, p);
  11306. p += 4;
  11307. bfd_put_32 (s->owner, BCTR, p);
  11308. break;
  11309. }
  11310. return TRUE;
  11311. }
  11312. /* Build all the stubs associated with the current output file.
  11313. The stubs are kept in a hash table attached to the main linker
  11314. hash table. This function is called via gldelf64ppc_finish. */
  11315. bfd_boolean
  11316. ppc64_elf_build_stubs (struct bfd_link_info *info,
  11317. char **stats)
  11318. {
  11319. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  11320. struct map_stub *group;
  11321. asection *stub_sec;
  11322. bfd_byte *p;
  11323. int stub_sec_count = 0;
  11324. if (htab == NULL)
  11325. return FALSE;
  11326. /* Allocate memory to hold the linker stubs. */
  11327. for (stub_sec = htab->params->stub_bfd->sections;
  11328. stub_sec != NULL;
  11329. stub_sec = stub_sec->next)
  11330. if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
  11331. && stub_sec->size != 0)
  11332. {
  11333. stub_sec->contents = bfd_zalloc (htab->params->stub_bfd, stub_sec->size);
  11334. if (stub_sec->contents == NULL)
  11335. return FALSE;
  11336. /* We want to check that built size is the same as calculated
  11337. size. rawsize is a convenient location to use. */
  11338. stub_sec->rawsize = stub_sec->size;
  11339. stub_sec->size = 0;
  11340. }
  11341. if (htab->glink != NULL && htab->glink->size != 0)
  11342. {
  11343. unsigned int indx;
  11344. bfd_vma plt0;
  11345. /* Build the .glink plt call stub. */
  11346. if (htab->params->emit_stub_syms)
  11347. {
  11348. struct elf_link_hash_entry *h;
  11349. h = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
  11350. TRUE, FALSE, FALSE);
  11351. if (h == NULL)
  11352. return FALSE;
  11353. if (h->root.type == bfd_link_hash_new)
  11354. {
  11355. h->root.type = bfd_link_hash_defined;
  11356. h->root.u.def.section = htab->glink;
  11357. h->root.u.def.value = 8;
  11358. h->ref_regular = 1;
  11359. h->def_regular = 1;
  11360. h->ref_regular_nonweak = 1;
  11361. h->forced_local = 1;
  11362. h->non_elf = 0;
  11363. h->root.linker_def = 1;
  11364. }
  11365. }
  11366. plt0 = (htab->elf.splt->output_section->vma
  11367. + htab->elf.splt->output_offset
  11368. - 16);
  11369. if (info->emitrelocations)
  11370. {
  11371. Elf_Internal_Rela *r = get_relocs (htab->glink, 1);
  11372. if (r == NULL)
  11373. return FALSE;
  11374. r->r_offset = (htab->glink->output_offset
  11375. + htab->glink->output_section->vma);
  11376. r->r_info = ELF64_R_INFO (0, R_PPC64_REL64);
  11377. r->r_addend = plt0;
  11378. }
  11379. p = htab->glink->contents;
  11380. plt0 -= htab->glink->output_section->vma + htab->glink->output_offset;
  11381. bfd_put_64 (htab->glink->owner, plt0, p);
  11382. p += 8;
  11383. if (htab->opd_abi)
  11384. {
  11385. bfd_put_32 (htab->glink->owner, MFLR_R12, p);
  11386. p += 4;
  11387. bfd_put_32 (htab->glink->owner, BCL_20_31, p);
  11388. p += 4;
  11389. bfd_put_32 (htab->glink->owner, MFLR_R11, p);
  11390. p += 4;
  11391. bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
  11392. p += 4;
  11393. bfd_put_32 (htab->glink->owner, MTLR_R12, p);
  11394. p += 4;
  11395. bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
  11396. p += 4;
  11397. bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
  11398. p += 4;
  11399. bfd_put_32 (htab->glink->owner, LD_R2_0R11 | 8, p);
  11400. p += 4;
  11401. bfd_put_32 (htab->glink->owner, MTCTR_R12, p);
  11402. p += 4;
  11403. bfd_put_32 (htab->glink->owner, LD_R11_0R11 | 16, p);
  11404. p += 4;
  11405. }
  11406. else
  11407. {
  11408. bfd_put_32 (htab->glink->owner, MFLR_R0, p);
  11409. p += 4;
  11410. bfd_put_32 (htab->glink->owner, BCL_20_31, p);
  11411. p += 4;
  11412. bfd_put_32 (htab->glink->owner, MFLR_R11, p);
  11413. p += 4;
  11414. bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
  11415. p += 4;
  11416. bfd_put_32 (htab->glink->owner, MTLR_R0, p);
  11417. p += 4;
  11418. bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p);
  11419. p += 4;
  11420. bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
  11421. p += 4;
  11422. bfd_put_32 (htab->glink->owner, ADDI_R0_R12 | (-48 & 0xffff), p);
  11423. p += 4;
  11424. bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
  11425. p += 4;
  11426. bfd_put_32 (htab->glink->owner, SRDI_R0_R0_2, p);
  11427. p += 4;
  11428. bfd_put_32 (htab->glink->owner, MTCTR_R12, p);
  11429. p += 4;
  11430. bfd_put_32 (htab->glink->owner, LD_R11_0R11 | 8, p);
  11431. p += 4;
  11432. }
  11433. bfd_put_32 (htab->glink->owner, BCTR, p);
  11434. p += 4;
  11435. while (p - htab->glink->contents < GLINK_CALL_STUB_SIZE)
  11436. {
  11437. bfd_put_32 (htab->glink->owner, NOP, p);
  11438. p += 4;
  11439. }
  11440. /* Build the .glink lazy link call stubs. */
  11441. indx = 0;
  11442. while (p < htab->glink->contents + htab->glink->rawsize)
  11443. {
  11444. if (htab->opd_abi)
  11445. {
  11446. if (indx < 0x8000)
  11447. {
  11448. bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p);
  11449. p += 4;
  11450. }
  11451. else
  11452. {
  11453. bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p);
  11454. p += 4;
  11455. bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx),
  11456. p);
  11457. p += 4;
  11458. }
  11459. }
  11460. bfd_put_32 (htab->glink->owner,
  11461. B_DOT | ((htab->glink->contents - p + 8) & 0x3fffffc), p);
  11462. indx++;
  11463. p += 4;
  11464. }
  11465. /* Build .glink global entry stubs. */
  11466. if (htab->glink->size > htab->glink->rawsize)
  11467. elf_link_hash_traverse (&htab->elf, build_global_entry_stubs, info);
  11468. }
  11469. if (htab->brlt != NULL && htab->brlt->size != 0)
  11470. {
  11471. htab->brlt->contents = bfd_zalloc (htab->brlt->owner,
  11472. htab->brlt->size);
  11473. if (htab->brlt->contents == NULL)
  11474. return FALSE;
  11475. }
  11476. if (htab->relbrlt != NULL && htab->relbrlt->size != 0)
  11477. {
  11478. htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner,
  11479. htab->relbrlt->size);
  11480. if (htab->relbrlt->contents == NULL)
  11481. return FALSE;
  11482. }
  11483. /* Build the stubs as directed by the stub hash table. */
  11484. bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
  11485. for (group = htab->group; group != NULL; group = group->next)
  11486. if (group->needs_save_res)
  11487. {
  11488. stub_sec = group->stub_sec;
  11489. memcpy (stub_sec->contents + stub_sec->size, htab->sfpr->contents,
  11490. htab->sfpr->size);
  11491. if (htab->params->emit_stub_syms)
  11492. {
  11493. unsigned int i;
  11494. for (i = 0; i < ARRAY_SIZE (save_res_funcs); i++)
  11495. if (!sfpr_define (info, &save_res_funcs[i], stub_sec))
  11496. return FALSE;
  11497. }
  11498. stub_sec->size += htab->sfpr->size;
  11499. }
  11500. if (htab->relbrlt != NULL)
  11501. htab->relbrlt->reloc_count = 0;
  11502. if (htab->params->plt_stub_align != 0)
  11503. for (stub_sec = htab->params->stub_bfd->sections;
  11504. stub_sec != NULL;
  11505. stub_sec = stub_sec->next)
  11506. if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
  11507. stub_sec->size = ((stub_sec->size
  11508. + (1 << htab->params->plt_stub_align) - 1)
  11509. & (-1 << htab->params->plt_stub_align));
  11510. for (stub_sec = htab->params->stub_bfd->sections;
  11511. stub_sec != NULL;
  11512. stub_sec = stub_sec->next)
  11513. if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
  11514. {
  11515. stub_sec_count += 1;
  11516. if (stub_sec->rawsize != stub_sec->size)
  11517. break;
  11518. }
  11519. /* Note that the glink_eh_frame check here is not only testing that
  11520. the generated size matched the calculated size but also that
  11521. bfd_elf_discard_info didn't make any changes to the section. */
  11522. if (stub_sec != NULL
  11523. || (htab->glink_eh_frame != NULL
  11524. && htab->glink_eh_frame->rawsize != htab->glink_eh_frame->size))
  11525. {
  11526. htab->stub_error = TRUE;
  11527. info->callbacks->einfo (_("%P: stubs don't match calculated size\n"));
  11528. }
  11529. if (htab->stub_error)
  11530. return FALSE;
  11531. if (stats != NULL)
  11532. {
  11533. *stats = bfd_malloc (500);
  11534. if (*stats == NULL)
  11535. return FALSE;
  11536. sprintf (*stats, _("linker stubs in %u group%s\n"
  11537. " branch %lu\n"
  11538. " toc adjust %lu\n"
  11539. " long branch %lu\n"
  11540. " long toc adj %lu\n"
  11541. " plt call %lu\n"
  11542. " plt call toc %lu\n"
  11543. " global entry %lu"),
  11544. stub_sec_count,
  11545. stub_sec_count == 1 ? "" : "s",
  11546. htab->stub_count[ppc_stub_long_branch - 1],
  11547. htab->stub_count[ppc_stub_long_branch_r2off - 1],
  11548. htab->stub_count[ppc_stub_plt_branch - 1],
  11549. htab->stub_count[ppc_stub_plt_branch_r2off - 1],
  11550. htab->stub_count[ppc_stub_plt_call - 1],
  11551. htab->stub_count[ppc_stub_plt_call_r2save - 1],
  11552. htab->stub_count[ppc_stub_global_entry - 1]);
  11553. }
  11554. return TRUE;
  11555. }
  11556. /* This function undoes the changes made by add_symbol_adjust. */
  11557. static bfd_boolean
  11558. undo_symbol_twiddle (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
  11559. {
  11560. struct ppc_link_hash_entry *eh;
  11561. if (h->root.type == bfd_link_hash_indirect)
  11562. return TRUE;
  11563. eh = (struct ppc_link_hash_entry *) h;
  11564. if (eh->elf.root.type != bfd_link_hash_undefweak || !eh->was_undefined)
  11565. return TRUE;
  11566. eh->elf.root.type = bfd_link_hash_undefined;
  11567. return TRUE;
  11568. }
  11569. void
  11570. ppc64_elf_restore_symbols (struct bfd_link_info *info)
  11571. {
  11572. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  11573. if (htab != NULL)
  11574. elf_link_hash_traverse (&htab->elf, undo_symbol_twiddle, info);
  11575. }
  11576. /* What to do when ld finds relocations against symbols defined in
  11577. discarded sections. */
  11578. static unsigned int
  11579. ppc64_elf_action_discarded (asection *sec)
  11580. {
  11581. if (strcmp (".opd", sec->name) == 0)
  11582. return 0;
  11583. if (strcmp (".toc", sec->name) == 0)
  11584. return 0;
  11585. if (strcmp (".toc1", sec->name) == 0)
  11586. return 0;
  11587. return _bfd_elf_default_action_discarded (sec);
  11588. }
  11589. /* The RELOCATE_SECTION function is called by the ELF backend linker
  11590. to handle the relocations for a section.
  11591. The relocs are always passed as Rela structures; if the section
  11592. actually uses Rel structures, the r_addend field will always be
  11593. zero.
  11594. This function is responsible for adjust the section contents as
  11595. necessary, and (if using Rela relocs and generating a
  11596. relocatable output file) adjusting the reloc addend as
  11597. necessary.
  11598. This function does not have to worry about setting the reloc
  11599. address or the reloc symbol index.
  11600. LOCAL_SYMS is a pointer to the swapped in local symbols.
  11601. LOCAL_SECTIONS is an array giving the section in the input file
  11602. corresponding to the st_shndx field of each local symbol.
  11603. The global hash table entry for the global symbols can be found
  11604. via elf_sym_hashes (input_bfd).
  11605. When generating relocatable output, this function must handle
  11606. STB_LOCAL/STT_SECTION symbols specially. The output symbol is
  11607. going to be the section symbol corresponding to the output
  11608. section, which means that the addend must be adjusted
  11609. accordingly. */
  11610. static bfd_boolean
  11611. ppc64_elf_relocate_section (bfd *output_bfd,
  11612. struct bfd_link_info *info,
  11613. bfd *input_bfd,
  11614. asection *input_section,
  11615. bfd_byte *contents,
  11616. Elf_Internal_Rela *relocs,
  11617. Elf_Internal_Sym *local_syms,
  11618. asection **local_sections)
  11619. {
  11620. struct ppc_link_hash_table *htab;
  11621. Elf_Internal_Shdr *symtab_hdr;
  11622. struct elf_link_hash_entry **sym_hashes;
  11623. Elf_Internal_Rela *rel;
  11624. Elf_Internal_Rela *relend;
  11625. Elf_Internal_Rela outrel;
  11626. bfd_byte *loc;
  11627. struct got_entry **local_got_ents;
  11628. bfd_vma TOCstart;
  11629. bfd_boolean ret = TRUE;
  11630. bfd_boolean is_opd;
  11631. /* Assume 'at' branch hints. */
  11632. bfd_boolean is_isa_v2 = TRUE;
  11633. bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
  11634. /* Initialize howto table if needed. */
  11635. if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
  11636. ppc_howto_init ();
  11637. htab = ppc_hash_table (info);
  11638. if (htab == NULL)
  11639. return FALSE;
  11640. /* Don't relocate stub sections. */
  11641. if (input_section->owner == htab->params->stub_bfd)
  11642. return TRUE;
  11643. BFD_ASSERT (is_ppc64_elf (input_bfd));
  11644. local_got_ents = elf_local_got_ents (input_bfd);
  11645. TOCstart = elf_gp (output_bfd);
  11646. symtab_hdr = &elf_symtab_hdr (input_bfd);
  11647. sym_hashes = elf_sym_hashes (input_bfd);
  11648. is_opd = ppc64_elf_section_data (input_section)->sec_type == sec_opd;
  11649. rel = relocs;
  11650. relend = relocs + input_section->reloc_count;
  11651. for (; rel < relend; rel++)
  11652. {
  11653. enum elf_ppc64_reloc_type r_type;
  11654. bfd_vma addend;
  11655. bfd_reloc_status_type r;
  11656. Elf_Internal_Sym *sym;
  11657. asection *sec;
  11658. struct elf_link_hash_entry *h_elf;
  11659. struct ppc_link_hash_entry *h;
  11660. struct ppc_link_hash_entry *fdh;
  11661. const char *sym_name;
  11662. unsigned long r_symndx, toc_symndx;
  11663. bfd_vma toc_addend;
  11664. unsigned char tls_mask, tls_gd, tls_type;
  11665. unsigned char sym_type;
  11666. bfd_vma relocation;
  11667. bfd_boolean unresolved_reloc;
  11668. bfd_boolean warned;
  11669. enum { DEST_NORMAL, DEST_OPD, DEST_STUB } reloc_dest;
  11670. unsigned int insn;
  11671. unsigned int mask;
  11672. struct ppc_stub_hash_entry *stub_entry;
  11673. bfd_vma max_br_offset;
  11674. bfd_vma from;
  11675. const Elf_Internal_Rela orig_rel = *rel;
  11676. reloc_howto_type *howto;
  11677. struct reloc_howto_struct alt_howto;
  11678. r_type = ELF64_R_TYPE (rel->r_info);
  11679. r_symndx = ELF64_R_SYM (rel->r_info);
  11680. /* For old style R_PPC64_TOC relocs with a zero symbol, use the
  11681. symbol of the previous ADDR64 reloc. The symbol gives us the
  11682. proper TOC base to use. */
  11683. if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC)
  11684. && rel != relocs
  11685. && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64
  11686. && is_opd)
  11687. r_symndx = ELF64_R_SYM (rel[-1].r_info);
  11688. sym = NULL;
  11689. sec = NULL;
  11690. h_elf = NULL;
  11691. sym_name = NULL;
  11692. unresolved_reloc = FALSE;
  11693. warned = FALSE;
  11694. if (r_symndx < symtab_hdr->sh_info)
  11695. {
  11696. /* It's a local symbol. */
  11697. struct _opd_sec_data *opd;
  11698. sym = local_syms + r_symndx;
  11699. sec = local_sections[r_symndx];
  11700. sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
  11701. sym_type = ELF64_ST_TYPE (sym->st_info);
  11702. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  11703. opd = get_opd_info (sec);
  11704. if (opd != NULL && opd->adjust != NULL)
  11705. {
  11706. long adjust = opd->adjust[OPD_NDX (sym->st_value
  11707. + rel->r_addend)];
  11708. if (adjust == -1)
  11709. relocation = 0;
  11710. else
  11711. {
  11712. /* If this is a relocation against the opd section sym
  11713. and we have edited .opd, adjust the reloc addend so
  11714. that ld -r and ld --emit-relocs output is correct.
  11715. If it is a reloc against some other .opd symbol,
  11716. then the symbol value will be adjusted later. */
  11717. if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
  11718. rel->r_addend += adjust;
  11719. else
  11720. relocation += adjust;
  11721. }
  11722. }
  11723. }
  11724. else
  11725. {
  11726. bfd_boolean ignored;
  11727. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  11728. r_symndx, symtab_hdr, sym_hashes,
  11729. h_elf, sec, relocation,
  11730. unresolved_reloc, warned, ignored);
  11731. sym_name = h_elf->root.root.string;
  11732. sym_type = h_elf->type;
  11733. if (sec != NULL
  11734. && sec->owner == output_bfd
  11735. && strcmp (sec->name, ".opd") == 0)
  11736. {
  11737. /* This is a symbol defined in a linker script. All
  11738. such are defined in output sections, even those
  11739. defined by simple assignment from a symbol defined in
  11740. an input section. Transfer the symbol to an
  11741. appropriate input .opd section, so that a branch to
  11742. this symbol will be mapped to the location specified
  11743. by the opd entry. */
  11744. struct bfd_link_order *lo;
  11745. for (lo = sec->map_head.link_order; lo != NULL; lo = lo->next)
  11746. if (lo->type == bfd_indirect_link_order)
  11747. {
  11748. asection *isec = lo->u.indirect.section;
  11749. if (h_elf->root.u.def.value >= isec->output_offset
  11750. && h_elf->root.u.def.value < (isec->output_offset
  11751. + isec->size))
  11752. {
  11753. h_elf->root.u.def.value -= isec->output_offset;
  11754. h_elf->root.u.def.section = isec;
  11755. sec = isec;
  11756. break;
  11757. }
  11758. }
  11759. }
  11760. }
  11761. h = (struct ppc_link_hash_entry *) h_elf;
  11762. if (sec != NULL && discarded_section (sec))
  11763. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  11764. rel, 1, relend,
  11765. ppc64_elf_howto_table[r_type], 0,
  11766. contents);
  11767. if (bfd_link_relocatable (info))
  11768. continue;
  11769. if (h != NULL && &h->elf == htab->elf.hgot)
  11770. {
  11771. relocation = TOCstart + htab->sec_info[input_section->id].toc_off;
  11772. sec = bfd_abs_section_ptr;
  11773. unresolved_reloc = FALSE;
  11774. }
  11775. /* TLS optimizations. Replace instruction sequences and relocs
  11776. based on information we collected in tls_optimize. We edit
  11777. RELOCS so that --emit-relocs will output something sensible
  11778. for the final instruction stream. */
  11779. tls_mask = 0;
  11780. tls_gd = 0;
  11781. toc_symndx = 0;
  11782. if (h != NULL)
  11783. tls_mask = h->tls_mask;
  11784. else if (local_got_ents != NULL)
  11785. {
  11786. struct plt_entry **local_plt = (struct plt_entry **)
  11787. (local_got_ents + symtab_hdr->sh_info);
  11788. unsigned char *lgot_masks = (unsigned char *)
  11789. (local_plt + symtab_hdr->sh_info);
  11790. tls_mask = lgot_masks[r_symndx];
  11791. }
  11792. if (tls_mask == 0
  11793. && (r_type == R_PPC64_TLS
  11794. || r_type == R_PPC64_TLSGD
  11795. || r_type == R_PPC64_TLSLD))
  11796. {
  11797. /* Check for toc tls entries. */
  11798. unsigned char *toc_tls;
  11799. if (!get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
  11800. &local_syms, rel, input_bfd))
  11801. return FALSE;
  11802. if (toc_tls)
  11803. tls_mask = *toc_tls;
  11804. }
  11805. /* Check that tls relocs are used with tls syms, and non-tls
  11806. relocs are used with non-tls syms. */
  11807. if (r_symndx != STN_UNDEF
  11808. && r_type != R_PPC64_NONE
  11809. && (h == NULL
  11810. || h->elf.root.type == bfd_link_hash_defined
  11811. || h->elf.root.type == bfd_link_hash_defweak)
  11812. && (IS_PPC64_TLS_RELOC (r_type)
  11813. != (sym_type == STT_TLS
  11814. || (sym_type == STT_SECTION
  11815. && (sec->flags & SEC_THREAD_LOCAL) != 0))))
  11816. {
  11817. if (tls_mask != 0
  11818. && (r_type == R_PPC64_TLS
  11819. || r_type == R_PPC64_TLSGD
  11820. || r_type == R_PPC64_TLSLD))
  11821. /* R_PPC64_TLS is OK against a symbol in the TOC. */
  11822. ;
  11823. else
  11824. info->callbacks->einfo
  11825. (!IS_PPC64_TLS_RELOC (r_type)
  11826. ? _("%P: %H: %s used with TLS symbol `%T'\n")
  11827. : _("%P: %H: %s used with non-TLS symbol `%T'\n"),
  11828. input_bfd, input_section, rel->r_offset,
  11829. ppc64_elf_howto_table[r_type]->name,
  11830. sym_name);
  11831. }
  11832. /* Ensure reloc mapping code below stays sane. */
  11833. if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1
  11834. || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1
  11835. || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3)
  11836. || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3)
  11837. || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3)
  11838. || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3)
  11839. || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3)
  11840. || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3)
  11841. || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3)
  11842. || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3))
  11843. abort ();
  11844. switch (r_type)
  11845. {
  11846. default:
  11847. break;
  11848. case R_PPC64_LO_DS_OPT:
  11849. insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
  11850. if ((insn & (0x3f << 26)) != 58u << 26)
  11851. abort ();
  11852. insn += (14u << 26) - (58u << 26);
  11853. bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
  11854. r_type = R_PPC64_TOC16_LO;
  11855. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  11856. break;
  11857. case R_PPC64_TOC16:
  11858. case R_PPC64_TOC16_LO:
  11859. case R_PPC64_TOC16_DS:
  11860. case R_PPC64_TOC16_LO_DS:
  11861. {
  11862. /* Check for toc tls entries. */
  11863. unsigned char *toc_tls;
  11864. int retval;
  11865. retval = get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
  11866. &local_syms, rel, input_bfd);
  11867. if (retval == 0)
  11868. return FALSE;
  11869. if (toc_tls)
  11870. {
  11871. tls_mask = *toc_tls;
  11872. if (r_type == R_PPC64_TOC16_DS
  11873. || r_type == R_PPC64_TOC16_LO_DS)
  11874. {
  11875. if (tls_mask != 0
  11876. && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0)
  11877. goto toctprel;
  11878. }
  11879. else
  11880. {
  11881. /* If we found a GD reloc pair, then we might be
  11882. doing a GD->IE transition. */
  11883. if (retval == 2)
  11884. {
  11885. tls_gd = TLS_TPRELGD;
  11886. if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
  11887. goto tls_ldgd_opt;
  11888. }
  11889. else if (retval == 3)
  11890. {
  11891. if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
  11892. goto tls_ldgd_opt;
  11893. }
  11894. }
  11895. }
  11896. }
  11897. break;
  11898. case R_PPC64_GOT_TPREL16_HI:
  11899. case R_PPC64_GOT_TPREL16_HA:
  11900. if (tls_mask != 0
  11901. && (tls_mask & TLS_TPREL) == 0)
  11902. {
  11903. rel->r_offset -= d_offset;
  11904. bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
  11905. r_type = R_PPC64_NONE;
  11906. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  11907. }
  11908. break;
  11909. case R_PPC64_GOT_TPREL16_DS:
  11910. case R_PPC64_GOT_TPREL16_LO_DS:
  11911. if (tls_mask != 0
  11912. && (tls_mask & TLS_TPREL) == 0)
  11913. {
  11914. toctprel:
  11915. insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
  11916. insn &= 31 << 21;
  11917. insn |= 0x3c0d0000; /* addis 0,13,0 */
  11918. bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
  11919. r_type = R_PPC64_TPREL16_HA;
  11920. if (toc_symndx != 0)
  11921. {
  11922. rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
  11923. rel->r_addend = toc_addend;
  11924. /* We changed the symbol. Start over in order to
  11925. get h, sym, sec etc. right. */
  11926. rel--;
  11927. continue;
  11928. }
  11929. else
  11930. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  11931. }
  11932. break;
  11933. case R_PPC64_TLS:
  11934. if (tls_mask != 0
  11935. && (tls_mask & TLS_TPREL) == 0)
  11936. {
  11937. insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
  11938. insn = _bfd_elf_ppc_at_tls_transform (insn, 13);
  11939. if (insn == 0)
  11940. abort ();
  11941. bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
  11942. /* Was PPC64_TLS which sits on insn boundary, now
  11943. PPC64_TPREL16_LO which is at low-order half-word. */
  11944. rel->r_offset += d_offset;
  11945. r_type = R_PPC64_TPREL16_LO;
  11946. if (toc_symndx != 0)
  11947. {
  11948. rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
  11949. rel->r_addend = toc_addend;
  11950. /* We changed the symbol. Start over in order to
  11951. get h, sym, sec etc. right. */
  11952. rel--;
  11953. continue;
  11954. }
  11955. else
  11956. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  11957. }
  11958. break;
  11959. case R_PPC64_GOT_TLSGD16_HI:
  11960. case R_PPC64_GOT_TLSGD16_HA:
  11961. tls_gd = TLS_TPRELGD;
  11962. if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
  11963. goto tls_gdld_hi;
  11964. break;
  11965. case R_PPC64_GOT_TLSLD16_HI:
  11966. case R_PPC64_GOT_TLSLD16_HA:
  11967. if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
  11968. {
  11969. tls_gdld_hi:
  11970. if ((tls_mask & tls_gd) != 0)
  11971. r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
  11972. + R_PPC64_GOT_TPREL16_DS);
  11973. else
  11974. {
  11975. rel->r_offset -= d_offset;
  11976. bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
  11977. r_type = R_PPC64_NONE;
  11978. }
  11979. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  11980. }
  11981. break;
  11982. case R_PPC64_GOT_TLSGD16:
  11983. case R_PPC64_GOT_TLSGD16_LO:
  11984. tls_gd = TLS_TPRELGD;
  11985. if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
  11986. goto tls_ldgd_opt;
  11987. break;
  11988. case R_PPC64_GOT_TLSLD16:
  11989. case R_PPC64_GOT_TLSLD16_LO:
  11990. if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
  11991. {
  11992. unsigned int insn1, insn2, insn3;
  11993. bfd_vma offset;
  11994. tls_ldgd_opt:
  11995. offset = (bfd_vma) -1;
  11996. /* If not using the newer R_PPC64_TLSGD/LD to mark
  11997. __tls_get_addr calls, we must trust that the call
  11998. stays with its arg setup insns, ie. that the next
  11999. reloc is the __tls_get_addr call associated with
  12000. the current reloc. Edit both insns. */
  12001. if (input_section->has_tls_get_addr_call
  12002. && rel + 1 < relend
  12003. && branch_reloc_hash_match (input_bfd, rel + 1,
  12004. htab->tls_get_addr,
  12005. htab->tls_get_addr_fd))
  12006. offset = rel[1].r_offset;
  12007. /* We read the low GOT_TLS (or TOC16) insn because we
  12008. need to keep the destination reg. It may be
  12009. something other than the usual r3, and moved to r3
  12010. before the call by intervening code. */
  12011. insn1 = bfd_get_32 (output_bfd,
  12012. contents + rel->r_offset - d_offset);
  12013. if ((tls_mask & tls_gd) != 0)
  12014. {
  12015. /* IE */
  12016. insn1 &= (0x1f << 21) | (0x1f << 16);
  12017. insn1 |= 58 << 26; /* ld */
  12018. insn2 = 0x7c636a14; /* add 3,3,13 */
  12019. if (offset != (bfd_vma) -1)
  12020. rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
  12021. if ((tls_mask & TLS_EXPLICIT) == 0)
  12022. r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
  12023. + R_PPC64_GOT_TPREL16_DS);
  12024. else
  12025. r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16;
  12026. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  12027. }
  12028. else
  12029. {
  12030. /* LE */
  12031. insn1 &= 0x1f << 21;
  12032. insn1 |= 0x3c0d0000; /* addis r,13,0 */
  12033. insn2 = 0x38630000; /* addi 3,3,0 */
  12034. if (tls_gd == 0)
  12035. {
  12036. /* Was an LD reloc. */
  12037. if (toc_symndx)
  12038. sec = local_sections[toc_symndx];
  12039. for (r_symndx = 0;
  12040. r_symndx < symtab_hdr->sh_info;
  12041. r_symndx++)
  12042. if (local_sections[r_symndx] == sec)
  12043. break;
  12044. if (r_symndx >= symtab_hdr->sh_info)
  12045. r_symndx = STN_UNDEF;
  12046. rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
  12047. if (r_symndx != STN_UNDEF)
  12048. rel->r_addend -= (local_syms[r_symndx].st_value
  12049. + sec->output_offset
  12050. + sec->output_section->vma);
  12051. }
  12052. else if (toc_symndx != 0)
  12053. {
  12054. r_symndx = toc_symndx;
  12055. rel->r_addend = toc_addend;
  12056. }
  12057. r_type = R_PPC64_TPREL16_HA;
  12058. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  12059. if (offset != (bfd_vma) -1)
  12060. {
  12061. rel[1].r_info = ELF64_R_INFO (r_symndx,
  12062. R_PPC64_TPREL16_LO);
  12063. rel[1].r_offset = offset + d_offset;
  12064. rel[1].r_addend = rel->r_addend;
  12065. }
  12066. }
  12067. bfd_put_32 (output_bfd, insn1,
  12068. contents + rel->r_offset - d_offset);
  12069. if (offset != (bfd_vma) -1)
  12070. {
  12071. insn3 = bfd_get_32 (output_bfd,
  12072. contents + offset + 4);
  12073. if (insn3 == NOP
  12074. || insn3 == CROR_151515 || insn3 == CROR_313131)
  12075. {
  12076. rel[1].r_offset += 4;
  12077. bfd_put_32 (output_bfd, insn2, contents + offset + 4);
  12078. insn2 = NOP;
  12079. }
  12080. bfd_put_32 (output_bfd, insn2, contents + offset);
  12081. }
  12082. if ((tls_mask & tls_gd) == 0
  12083. && (tls_gd == 0 || toc_symndx != 0))
  12084. {
  12085. /* We changed the symbol. Start over in order
  12086. to get h, sym, sec etc. right. */
  12087. rel--;
  12088. continue;
  12089. }
  12090. }
  12091. break;
  12092. case R_PPC64_TLSGD:
  12093. if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
  12094. {
  12095. unsigned int insn2, insn3;
  12096. bfd_vma offset = rel->r_offset;
  12097. if ((tls_mask & TLS_TPRELGD) != 0)
  12098. {
  12099. /* IE */
  12100. r_type = R_PPC64_NONE;
  12101. insn2 = 0x7c636a14; /* add 3,3,13 */
  12102. }
  12103. else
  12104. {
  12105. /* LE */
  12106. if (toc_symndx != 0)
  12107. {
  12108. r_symndx = toc_symndx;
  12109. rel->r_addend = toc_addend;
  12110. }
  12111. r_type = R_PPC64_TPREL16_LO;
  12112. rel->r_offset = offset + d_offset;
  12113. insn2 = 0x38630000; /* addi 3,3,0 */
  12114. }
  12115. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  12116. /* Zap the reloc on the _tls_get_addr call too. */
  12117. BFD_ASSERT (offset == rel[1].r_offset);
  12118. rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
  12119. insn3 = bfd_get_32 (output_bfd,
  12120. contents + offset + 4);
  12121. if (insn3 == NOP
  12122. || insn3 == CROR_151515 || insn3 == CROR_313131)
  12123. {
  12124. rel->r_offset += 4;
  12125. bfd_put_32 (output_bfd, insn2, contents + offset + 4);
  12126. insn2 = NOP;
  12127. }
  12128. bfd_put_32 (output_bfd, insn2, contents + offset);
  12129. if ((tls_mask & TLS_TPRELGD) == 0 && toc_symndx != 0)
  12130. {
  12131. rel--;
  12132. continue;
  12133. }
  12134. }
  12135. break;
  12136. case R_PPC64_TLSLD:
  12137. if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
  12138. {
  12139. unsigned int insn2, insn3;
  12140. bfd_vma offset = rel->r_offset;
  12141. if (toc_symndx)
  12142. sec = local_sections[toc_symndx];
  12143. for (r_symndx = 0;
  12144. r_symndx < symtab_hdr->sh_info;
  12145. r_symndx++)
  12146. if (local_sections[r_symndx] == sec)
  12147. break;
  12148. if (r_symndx >= symtab_hdr->sh_info)
  12149. r_symndx = STN_UNDEF;
  12150. rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
  12151. if (r_symndx != STN_UNDEF)
  12152. rel->r_addend -= (local_syms[r_symndx].st_value
  12153. + sec->output_offset
  12154. + sec->output_section->vma);
  12155. r_type = R_PPC64_TPREL16_LO;
  12156. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  12157. rel->r_offset = offset + d_offset;
  12158. /* Zap the reloc on the _tls_get_addr call too. */
  12159. BFD_ASSERT (offset == rel[1].r_offset);
  12160. rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
  12161. insn2 = 0x38630000; /* addi 3,3,0 */
  12162. insn3 = bfd_get_32 (output_bfd,
  12163. contents + offset + 4);
  12164. if (insn3 == NOP
  12165. || insn3 == CROR_151515 || insn3 == CROR_313131)
  12166. {
  12167. rel->r_offset += 4;
  12168. bfd_put_32 (output_bfd, insn2, contents + offset + 4);
  12169. insn2 = NOP;
  12170. }
  12171. bfd_put_32 (output_bfd, insn2, contents + offset);
  12172. rel--;
  12173. continue;
  12174. }
  12175. break;
  12176. case R_PPC64_DTPMOD64:
  12177. if (rel + 1 < relend
  12178. && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
  12179. && rel[1].r_offset == rel->r_offset + 8)
  12180. {
  12181. if ((tls_mask & TLS_GD) == 0)
  12182. {
  12183. rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE);
  12184. if ((tls_mask & TLS_TPRELGD) != 0)
  12185. r_type = R_PPC64_TPREL64;
  12186. else
  12187. {
  12188. bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
  12189. r_type = R_PPC64_NONE;
  12190. }
  12191. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  12192. }
  12193. }
  12194. else
  12195. {
  12196. if ((tls_mask & TLS_LD) == 0)
  12197. {
  12198. bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
  12199. r_type = R_PPC64_NONE;
  12200. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  12201. }
  12202. }
  12203. break;
  12204. case R_PPC64_TPREL64:
  12205. if ((tls_mask & TLS_TPREL) == 0)
  12206. {
  12207. r_type = R_PPC64_NONE;
  12208. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  12209. }
  12210. break;
  12211. case R_PPC64_REL16_HA:
  12212. /* If we are generating a non-PIC executable, edit
  12213. . 0: addis 2,12,.TOC.-0b@ha
  12214. . addi 2,2,.TOC.-0b@l
  12215. used by ELFv2 global entry points to set up r2, to
  12216. . lis 2,.TOC.@ha
  12217. . addi 2,2,.TOC.@l
  12218. if .TOC. is in range. */
  12219. if (!bfd_link_pic (info)
  12220. && !info->traditional_format
  12221. && h != NULL && &h->elf == htab->elf.hgot
  12222. && rel + 1 < relend
  12223. && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_REL16_LO)
  12224. && rel[1].r_offset == rel->r_offset + 4
  12225. && rel[1].r_addend == rel->r_addend + 4
  12226. && relocation + 0x80008000 <= 0xffffffff)
  12227. {
  12228. unsigned int insn1, insn2;
  12229. bfd_vma offset = rel->r_offset - d_offset;
  12230. insn1 = bfd_get_32 (output_bfd, contents + offset);
  12231. insn2 = bfd_get_32 (output_bfd, contents + offset + 4);
  12232. if ((insn1 & 0xffff0000) == 0x3c4c0000 /* addis 2,12 */
  12233. && (insn2 & 0xffff0000) == 0x38420000 /* addi 2,2 */)
  12234. {
  12235. r_type = R_PPC64_ADDR16_HA;
  12236. rel->r_info = ELF64_R_INFO (r_symndx, r_type);
  12237. rel->r_addend -= d_offset;
  12238. rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_ADDR16_LO);
  12239. rel[1].r_addend -= d_offset + 4;
  12240. bfd_put_32 (output_bfd, 0x3c400000, contents + offset);
  12241. }
  12242. }
  12243. break;
  12244. }
  12245. /* Handle other relocations that tweak non-addend part of insn. */
  12246. insn = 0;
  12247. max_br_offset = 1 << 25;
  12248. addend = rel->r_addend;
  12249. reloc_dest = DEST_NORMAL;
  12250. switch (r_type)
  12251. {
  12252. default:
  12253. break;
  12254. case R_PPC64_TOCSAVE:
  12255. if (relocation + addend == (rel->r_offset
  12256. + input_section->output_offset
  12257. + input_section->output_section->vma)
  12258. && tocsave_find (htab, NO_INSERT,
  12259. &local_syms, rel, input_bfd))
  12260. {
  12261. insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
  12262. if (insn == NOP
  12263. || insn == CROR_151515 || insn == CROR_313131)
  12264. bfd_put_32 (input_bfd,
  12265. STD_R2_0R1 + STK_TOC (htab),
  12266. contents + rel->r_offset);
  12267. }
  12268. break;
  12269. /* Branch taken prediction relocations. */
  12270. case R_PPC64_ADDR14_BRTAKEN:
  12271. case R_PPC64_REL14_BRTAKEN:
  12272. insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
  12273. /* Fall thru. */
  12274. /* Branch not taken prediction relocations. */
  12275. case R_PPC64_ADDR14_BRNTAKEN:
  12276. case R_PPC64_REL14_BRNTAKEN:
  12277. insn |= bfd_get_32 (output_bfd,
  12278. contents + rel->r_offset) & ~(0x01 << 21);
  12279. /* Fall thru. */
  12280. case R_PPC64_REL14:
  12281. max_br_offset = 1 << 15;
  12282. /* Fall thru. */
  12283. case R_PPC64_REL24:
  12284. /* Calls to functions with a different TOC, such as calls to
  12285. shared objects, need to alter the TOC pointer. This is
  12286. done using a linkage stub. A REL24 branching to these
  12287. linkage stubs needs to be followed by a nop, as the nop
  12288. will be replaced with an instruction to restore the TOC
  12289. base pointer. */
  12290. fdh = h;
  12291. if (h != NULL
  12292. && h->oh != NULL
  12293. && h->oh->is_func_descriptor)
  12294. fdh = ppc_follow_link (h->oh);
  12295. stub_entry = ppc_get_stub_entry (input_section, sec, fdh, &orig_rel,
  12296. htab);
  12297. if (stub_entry != NULL
  12298. && (stub_entry->stub_type == ppc_stub_plt_call
  12299. || stub_entry->stub_type == ppc_stub_plt_call_r2save
  12300. || stub_entry->stub_type == ppc_stub_plt_branch_r2off
  12301. || stub_entry->stub_type == ppc_stub_long_branch_r2off))
  12302. {
  12303. bfd_boolean can_plt_call = FALSE;
  12304. /* All of these stubs will modify r2, so there must be a
  12305. branch and link followed by a nop. The nop is
  12306. replaced by an insn to restore r2. */
  12307. if (rel->r_offset + 8 <= input_section->size)
  12308. {
  12309. unsigned long br;
  12310. br = bfd_get_32 (input_bfd,
  12311. contents + rel->r_offset);
  12312. if ((br & 1) != 0)
  12313. {
  12314. unsigned long nop;
  12315. nop = bfd_get_32 (input_bfd,
  12316. contents + rel->r_offset + 4);
  12317. if (nop == NOP
  12318. || nop == CROR_151515 || nop == CROR_313131)
  12319. {
  12320. if (h != NULL
  12321. && (h == htab->tls_get_addr_fd
  12322. || h == htab->tls_get_addr)
  12323. && htab->params->tls_get_addr_opt)
  12324. {
  12325. /* Special stub used, leave nop alone. */
  12326. }
  12327. else
  12328. bfd_put_32 (input_bfd,
  12329. LD_R2_0R1 + STK_TOC (htab),
  12330. contents + rel->r_offset + 4);
  12331. can_plt_call = TRUE;
  12332. }
  12333. }
  12334. }
  12335. if (!can_plt_call && h != NULL)
  12336. {
  12337. const char *name = h->elf.root.root.string;
  12338. if (*name == '.')
  12339. ++name;
  12340. if (strncmp (name, "__libc_start_main", 17) == 0
  12341. && (name[17] == 0 || name[17] == '@'))
  12342. {
  12343. /* Allow crt1 branch to go via a toc adjusting
  12344. stub. Other calls that never return could do
  12345. the same, if we could detect such. */
  12346. can_plt_call = TRUE;
  12347. }
  12348. }
  12349. if (!can_plt_call)
  12350. {
  12351. /* g++ as of 20130507 emits self-calls without a
  12352. following nop. This is arguably wrong since we
  12353. have conflicting information. On the one hand a
  12354. global symbol and on the other a local call
  12355. sequence, but don't error for this special case.
  12356. It isn't possible to cheaply verify we have
  12357. exactly such a call. Allow all calls to the same
  12358. section. */
  12359. asection *code_sec = sec;
  12360. if (get_opd_info (sec) != NULL)
  12361. {
  12362. bfd_vma off = (relocation + addend
  12363. - sec->output_section->vma
  12364. - sec->output_offset);
  12365. opd_entry_value (sec, off, &code_sec, NULL, FALSE);
  12366. }
  12367. if (code_sec == input_section)
  12368. can_plt_call = TRUE;
  12369. }
  12370. if (!can_plt_call)
  12371. {
  12372. if (stub_entry->stub_type == ppc_stub_plt_call
  12373. || stub_entry->stub_type == ppc_stub_plt_call_r2save)
  12374. info->callbacks->einfo
  12375. (_("%P: %H: call to `%T' lacks nop, can't restore toc; "
  12376. "recompile with -fPIC\n"),
  12377. input_bfd, input_section, rel->r_offset, sym_name);
  12378. else
  12379. info->callbacks->einfo
  12380. (_("%P: %H: call to `%T' lacks nop, can't restore toc; "
  12381. "(-mcmodel=small toc adjust stub)\n"),
  12382. input_bfd, input_section, rel->r_offset, sym_name);
  12383. bfd_set_error (bfd_error_bad_value);
  12384. ret = FALSE;
  12385. }
  12386. if (can_plt_call
  12387. && (stub_entry->stub_type == ppc_stub_plt_call
  12388. || stub_entry->stub_type == ppc_stub_plt_call_r2save))
  12389. unresolved_reloc = FALSE;
  12390. }
  12391. if ((stub_entry == NULL
  12392. || stub_entry->stub_type == ppc_stub_long_branch
  12393. || stub_entry->stub_type == ppc_stub_plt_branch)
  12394. && get_opd_info (sec) != NULL)
  12395. {
  12396. /* The branch destination is the value of the opd entry. */
  12397. bfd_vma off = (relocation + addend
  12398. - sec->output_section->vma
  12399. - sec->output_offset);
  12400. bfd_vma dest = opd_entry_value (sec, off, NULL, NULL, FALSE);
  12401. if (dest != (bfd_vma) -1)
  12402. {
  12403. relocation = dest;
  12404. addend = 0;
  12405. reloc_dest = DEST_OPD;
  12406. }
  12407. }
  12408. /* If the branch is out of reach we ought to have a long
  12409. branch stub. */
  12410. from = (rel->r_offset
  12411. + input_section->output_offset
  12412. + input_section->output_section->vma);
  12413. relocation += PPC64_LOCAL_ENTRY_OFFSET (fdh
  12414. ? fdh->elf.other
  12415. : sym->st_other);
  12416. if (stub_entry != NULL
  12417. && (stub_entry->stub_type == ppc_stub_long_branch
  12418. || stub_entry->stub_type == ppc_stub_plt_branch)
  12419. && (r_type == R_PPC64_ADDR14_BRTAKEN
  12420. || r_type == R_PPC64_ADDR14_BRNTAKEN
  12421. || (relocation + addend - from + max_br_offset
  12422. < 2 * max_br_offset)))
  12423. /* Don't use the stub if this branch is in range. */
  12424. stub_entry = NULL;
  12425. if (stub_entry != NULL)
  12426. {
  12427. /* Munge up the value and addend so that we call the stub
  12428. rather than the procedure directly. */
  12429. asection *stub_sec = stub_entry->group->stub_sec;
  12430. if (stub_entry->stub_type == ppc_stub_save_res)
  12431. relocation += (stub_sec->output_offset
  12432. + stub_sec->output_section->vma
  12433. + stub_sec->size - htab->sfpr->size
  12434. - htab->sfpr->output_offset
  12435. - htab->sfpr->output_section->vma);
  12436. else
  12437. relocation = (stub_entry->stub_offset
  12438. + stub_sec->output_offset
  12439. + stub_sec->output_section->vma);
  12440. addend = 0;
  12441. reloc_dest = DEST_STUB;
  12442. if ((stub_entry->stub_type == ppc_stub_plt_call
  12443. || stub_entry->stub_type == ppc_stub_plt_call_r2save)
  12444. && (ALWAYS_EMIT_R2SAVE
  12445. || stub_entry->stub_type == ppc_stub_plt_call_r2save)
  12446. && rel + 1 < relend
  12447. && rel[1].r_offset == rel->r_offset + 4
  12448. && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOCSAVE)
  12449. relocation += 4;
  12450. }
  12451. if (insn != 0)
  12452. {
  12453. if (is_isa_v2)
  12454. {
  12455. /* Set 'a' bit. This is 0b00010 in BO field for branch
  12456. on CR(BI) insns (BO == 001at or 011at), and 0b01000
  12457. for branch on CTR insns (BO == 1a00t or 1a01t). */
  12458. if ((insn & (0x14 << 21)) == (0x04 << 21))
  12459. insn |= 0x02 << 21;
  12460. else if ((insn & (0x14 << 21)) == (0x10 << 21))
  12461. insn |= 0x08 << 21;
  12462. else
  12463. break;
  12464. }
  12465. else
  12466. {
  12467. /* Invert 'y' bit if not the default. */
  12468. if ((bfd_signed_vma) (relocation + addend - from) < 0)
  12469. insn ^= 0x01 << 21;
  12470. }
  12471. bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
  12472. }
  12473. /* NOP out calls to undefined weak functions.
  12474. We can thus call a weak function without first
  12475. checking whether the function is defined. */
  12476. else if (h != NULL
  12477. && h->elf.root.type == bfd_link_hash_undefweak
  12478. && h->elf.dynindx == -1
  12479. && r_type == R_PPC64_REL24
  12480. && relocation == 0
  12481. && addend == 0)
  12482. {
  12483. bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
  12484. continue;
  12485. }
  12486. break;
  12487. }
  12488. /* Set `addend'. */
  12489. tls_type = 0;
  12490. switch (r_type)
  12491. {
  12492. default:
  12493. info->callbacks->einfo
  12494. (_("%P: %B: unknown relocation type %d for `%T'\n"),
  12495. input_bfd, (int) r_type, sym_name);
  12496. bfd_set_error (bfd_error_bad_value);
  12497. ret = FALSE;
  12498. continue;
  12499. case R_PPC64_NONE:
  12500. case R_PPC64_TLS:
  12501. case R_PPC64_TLSGD:
  12502. case R_PPC64_TLSLD:
  12503. case R_PPC64_TOCSAVE:
  12504. case R_PPC64_GNU_VTINHERIT:
  12505. case R_PPC64_GNU_VTENTRY:
  12506. continue;
  12507. /* GOT16 relocations. Like an ADDR16 using the symbol's
  12508. address in the GOT as relocation value instead of the
  12509. symbol's value itself. Also, create a GOT entry for the
  12510. symbol and put the symbol value there. */
  12511. case R_PPC64_GOT_TLSGD16:
  12512. case R_PPC64_GOT_TLSGD16_LO:
  12513. case R_PPC64_GOT_TLSGD16_HI:
  12514. case R_PPC64_GOT_TLSGD16_HA:
  12515. tls_type = TLS_TLS | TLS_GD;
  12516. goto dogot;
  12517. case R_PPC64_GOT_TLSLD16:
  12518. case R_PPC64_GOT_TLSLD16_LO:
  12519. case R_PPC64_GOT_TLSLD16_HI:
  12520. case R_PPC64_GOT_TLSLD16_HA:
  12521. tls_type = TLS_TLS | TLS_LD;
  12522. goto dogot;
  12523. case R_PPC64_GOT_TPREL16_DS:
  12524. case R_PPC64_GOT_TPREL16_LO_DS:
  12525. case R_PPC64_GOT_TPREL16_HI:
  12526. case R_PPC64_GOT_TPREL16_HA:
  12527. tls_type = TLS_TLS | TLS_TPREL;
  12528. goto dogot;
  12529. case R_PPC64_GOT_DTPREL16_DS:
  12530. case R_PPC64_GOT_DTPREL16_LO_DS:
  12531. case R_PPC64_GOT_DTPREL16_HI:
  12532. case R_PPC64_GOT_DTPREL16_HA:
  12533. tls_type = TLS_TLS | TLS_DTPREL;
  12534. goto dogot;
  12535. case R_PPC64_GOT16:
  12536. case R_PPC64_GOT16_LO:
  12537. case R_PPC64_GOT16_HI:
  12538. case R_PPC64_GOT16_HA:
  12539. case R_PPC64_GOT16_DS:
  12540. case R_PPC64_GOT16_LO_DS:
  12541. dogot:
  12542. {
  12543. /* Relocation is to the entry for this symbol in the global
  12544. offset table. */
  12545. asection *got;
  12546. bfd_vma *offp;
  12547. bfd_vma off;
  12548. unsigned long indx = 0;
  12549. struct got_entry *ent;
  12550. if (tls_type == (TLS_TLS | TLS_LD)
  12551. && (h == NULL
  12552. || !h->elf.def_dynamic))
  12553. ent = ppc64_tlsld_got (input_bfd);
  12554. else
  12555. {
  12556. if (h != NULL)
  12557. {
  12558. bfd_boolean dyn = htab->elf.dynamic_sections_created;
  12559. if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info),
  12560. &h->elf)
  12561. || (bfd_link_pic (info)
  12562. && SYMBOL_REFERENCES_LOCAL (info, &h->elf)))
  12563. /* This is actually a static link, or it is a
  12564. -Bsymbolic link and the symbol is defined
  12565. locally, or the symbol was forced to be local
  12566. because of a version file. */
  12567. ;
  12568. else
  12569. {
  12570. BFD_ASSERT (h->elf.dynindx != -1);
  12571. indx = h->elf.dynindx;
  12572. unresolved_reloc = FALSE;
  12573. }
  12574. ent = h->elf.got.glist;
  12575. }
  12576. else
  12577. {
  12578. if (local_got_ents == NULL)
  12579. abort ();
  12580. ent = local_got_ents[r_symndx];
  12581. }
  12582. for (; ent != NULL; ent = ent->next)
  12583. if (ent->addend == orig_rel.r_addend
  12584. && ent->owner == input_bfd
  12585. && ent->tls_type == tls_type)
  12586. break;
  12587. }
  12588. if (ent == NULL)
  12589. abort ();
  12590. if (ent->is_indirect)
  12591. ent = ent->got.ent;
  12592. offp = &ent->got.offset;
  12593. got = ppc64_elf_tdata (ent->owner)->got;
  12594. if (got == NULL)
  12595. abort ();
  12596. /* The offset must always be a multiple of 8. We use the
  12597. least significant bit to record whether we have already
  12598. processed this entry. */
  12599. off = *offp;
  12600. if ((off & 1) != 0)
  12601. off &= ~1;
  12602. else
  12603. {
  12604. /* Generate relocs for the dynamic linker, except in
  12605. the case of TLSLD where we'll use one entry per
  12606. module. */
  12607. asection *relgot;
  12608. bfd_boolean ifunc;
  12609. *offp = off | 1;
  12610. relgot = NULL;
  12611. ifunc = (h != NULL
  12612. ? h->elf.type == STT_GNU_IFUNC
  12613. : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC);
  12614. if (ifunc)
  12615. relgot = htab->elf.irelplt;
  12616. else if ((bfd_link_pic (info) || indx != 0)
  12617. && (h == NULL
  12618. || (tls_type == (TLS_TLS | TLS_LD)
  12619. && !h->elf.def_dynamic)
  12620. || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
  12621. || h->elf.root.type != bfd_link_hash_undefweak))
  12622. relgot = ppc64_elf_tdata (ent->owner)->relgot;
  12623. if (relgot != NULL)
  12624. {
  12625. outrel.r_offset = (got->output_section->vma
  12626. + got->output_offset
  12627. + off);
  12628. outrel.r_addend = addend;
  12629. if (tls_type & (TLS_LD | TLS_GD))
  12630. {
  12631. outrel.r_addend = 0;
  12632. outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64);
  12633. if (tls_type == (TLS_TLS | TLS_GD))
  12634. {
  12635. loc = relgot->contents;
  12636. loc += (relgot->reloc_count++
  12637. * sizeof (Elf64_External_Rela));
  12638. bfd_elf64_swap_reloca_out (output_bfd,
  12639. &outrel, loc);
  12640. outrel.r_offset += 8;
  12641. outrel.r_addend = addend;
  12642. outrel.r_info
  12643. = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
  12644. }
  12645. }
  12646. else if (tls_type == (TLS_TLS | TLS_DTPREL))
  12647. outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
  12648. else if (tls_type == (TLS_TLS | TLS_TPREL))
  12649. outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64);
  12650. else if (indx != 0)
  12651. outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
  12652. else
  12653. {
  12654. if (ifunc)
  12655. outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
  12656. else
  12657. outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
  12658. /* Write the .got section contents for the sake
  12659. of prelink. */
  12660. loc = got->contents + off;
  12661. bfd_put_64 (output_bfd, outrel.r_addend + relocation,
  12662. loc);
  12663. }
  12664. if (indx == 0 && tls_type != (TLS_TLS | TLS_LD))
  12665. {
  12666. outrel.r_addend += relocation;
  12667. if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL))
  12668. {
  12669. if (htab->elf.tls_sec == NULL)
  12670. outrel.r_addend = 0;
  12671. else
  12672. outrel.r_addend -= htab->elf.tls_sec->vma;
  12673. }
  12674. }
  12675. loc = relgot->contents;
  12676. loc += (relgot->reloc_count++
  12677. * sizeof (Elf64_External_Rela));
  12678. bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
  12679. }
  12680. /* Init the .got section contents here if we're not
  12681. emitting a reloc. */
  12682. else
  12683. {
  12684. relocation += addend;
  12685. if (tls_type == (TLS_TLS | TLS_LD))
  12686. relocation = 1;
  12687. else if (tls_type != 0)
  12688. {
  12689. if (htab->elf.tls_sec == NULL)
  12690. relocation = 0;
  12691. else
  12692. {
  12693. relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
  12694. if (tls_type == (TLS_TLS | TLS_TPREL))
  12695. relocation += DTP_OFFSET - TP_OFFSET;
  12696. }
  12697. if (tls_type == (TLS_TLS | TLS_GD))
  12698. {
  12699. bfd_put_64 (output_bfd, relocation,
  12700. got->contents + off + 8);
  12701. relocation = 1;
  12702. }
  12703. }
  12704. bfd_put_64 (output_bfd, relocation,
  12705. got->contents + off);
  12706. }
  12707. }
  12708. if (off >= (bfd_vma) -2)
  12709. abort ();
  12710. relocation = got->output_section->vma + got->output_offset + off;
  12711. addend = -(TOCstart + htab->sec_info[input_section->id].toc_off);
  12712. }
  12713. break;
  12714. case R_PPC64_PLT16_HA:
  12715. case R_PPC64_PLT16_HI:
  12716. case R_PPC64_PLT16_LO:
  12717. case R_PPC64_PLT32:
  12718. case R_PPC64_PLT64:
  12719. /* Relocation is to the entry for this symbol in the
  12720. procedure linkage table. */
  12721. /* Resolve a PLT reloc against a local symbol directly,
  12722. without using the procedure linkage table. */
  12723. if (h == NULL)
  12724. break;
  12725. /* It's possible that we didn't make a PLT entry for this
  12726. symbol. This happens when statically linking PIC code,
  12727. or when using -Bsymbolic. Go find a match if there is a
  12728. PLT entry. */
  12729. if (htab->elf.splt != NULL)
  12730. {
  12731. struct plt_entry *ent;
  12732. for (ent = h->elf.plt.plist; ent != NULL; ent = ent->next)
  12733. if (ent->plt.offset != (bfd_vma) -1
  12734. && ent->addend == orig_rel.r_addend)
  12735. {
  12736. relocation = (htab->elf.splt->output_section->vma
  12737. + htab->elf.splt->output_offset
  12738. + ent->plt.offset);
  12739. unresolved_reloc = FALSE;
  12740. break;
  12741. }
  12742. }
  12743. break;
  12744. case R_PPC64_TOC:
  12745. /* Relocation value is TOC base. */
  12746. relocation = TOCstart;
  12747. if (r_symndx == STN_UNDEF)
  12748. relocation += htab->sec_info[input_section->id].toc_off;
  12749. else if (unresolved_reloc)
  12750. ;
  12751. else if (sec != NULL && sec->id < htab->sec_info_arr_size)
  12752. relocation += htab->sec_info[sec->id].toc_off;
  12753. else
  12754. unresolved_reloc = TRUE;
  12755. goto dodyn;
  12756. /* TOC16 relocs. We want the offset relative to the TOC base,
  12757. which is the address of the start of the TOC plus 0x8000.
  12758. The TOC consists of sections .got, .toc, .tocbss, and .plt,
  12759. in this order. */
  12760. case R_PPC64_TOC16:
  12761. case R_PPC64_TOC16_LO:
  12762. case R_PPC64_TOC16_HI:
  12763. case R_PPC64_TOC16_DS:
  12764. case R_PPC64_TOC16_LO_DS:
  12765. case R_PPC64_TOC16_HA:
  12766. addend -= TOCstart + htab->sec_info[input_section->id].toc_off;
  12767. break;
  12768. /* Relocate against the beginning of the section. */
  12769. case R_PPC64_SECTOFF:
  12770. case R_PPC64_SECTOFF_LO:
  12771. case R_PPC64_SECTOFF_HI:
  12772. case R_PPC64_SECTOFF_DS:
  12773. case R_PPC64_SECTOFF_LO_DS:
  12774. case R_PPC64_SECTOFF_HA:
  12775. if (sec != NULL)
  12776. addend -= sec->output_section->vma;
  12777. break;
  12778. case R_PPC64_REL16:
  12779. case R_PPC64_REL16_LO:
  12780. case R_PPC64_REL16_HI:
  12781. case R_PPC64_REL16_HA:
  12782. break;
  12783. case R_PPC64_REL14:
  12784. case R_PPC64_REL14_BRNTAKEN:
  12785. case R_PPC64_REL14_BRTAKEN:
  12786. case R_PPC64_REL24:
  12787. break;
  12788. case R_PPC64_TPREL16:
  12789. case R_PPC64_TPREL16_LO:
  12790. case R_PPC64_TPREL16_HI:
  12791. case R_PPC64_TPREL16_HA:
  12792. case R_PPC64_TPREL16_DS:
  12793. case R_PPC64_TPREL16_LO_DS:
  12794. case R_PPC64_TPREL16_HIGH:
  12795. case R_PPC64_TPREL16_HIGHA:
  12796. case R_PPC64_TPREL16_HIGHER:
  12797. case R_PPC64_TPREL16_HIGHERA:
  12798. case R_PPC64_TPREL16_HIGHEST:
  12799. case R_PPC64_TPREL16_HIGHESTA:
  12800. if (h != NULL
  12801. && h->elf.root.type == bfd_link_hash_undefweak
  12802. && h->elf.dynindx == -1)
  12803. {
  12804. /* Make this relocation against an undefined weak symbol
  12805. resolve to zero. This is really just a tweak, since
  12806. code using weak externs ought to check that they are
  12807. defined before using them. */
  12808. bfd_byte *p = contents + rel->r_offset - d_offset;
  12809. insn = bfd_get_32 (output_bfd, p);
  12810. insn = _bfd_elf_ppc_at_tprel_transform (insn, 13);
  12811. if (insn != 0)
  12812. bfd_put_32 (output_bfd, insn, p);
  12813. break;
  12814. }
  12815. if (htab->elf.tls_sec != NULL)
  12816. addend -= htab->elf.tls_sec->vma + TP_OFFSET;
  12817. if (bfd_link_pic (info))
  12818. /* The TPREL16 relocs shouldn't really be used in shared
  12819. libs as they will result in DT_TEXTREL being set, but
  12820. support them anyway. */
  12821. goto dodyn;
  12822. break;
  12823. case R_PPC64_DTPREL16:
  12824. case R_PPC64_DTPREL16_LO:
  12825. case R_PPC64_DTPREL16_HI:
  12826. case R_PPC64_DTPREL16_HA:
  12827. case R_PPC64_DTPREL16_DS:
  12828. case R_PPC64_DTPREL16_LO_DS:
  12829. case R_PPC64_DTPREL16_HIGH:
  12830. case R_PPC64_DTPREL16_HIGHA:
  12831. case R_PPC64_DTPREL16_HIGHER:
  12832. case R_PPC64_DTPREL16_HIGHERA:
  12833. case R_PPC64_DTPREL16_HIGHEST:
  12834. case R_PPC64_DTPREL16_HIGHESTA:
  12835. if (htab->elf.tls_sec != NULL)
  12836. addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
  12837. break;
  12838. case R_PPC64_ADDR64_LOCAL:
  12839. addend += PPC64_LOCAL_ENTRY_OFFSET (h != NULL
  12840. ? h->elf.other
  12841. : sym->st_other);
  12842. break;
  12843. case R_PPC64_DTPMOD64:
  12844. relocation = 1;
  12845. addend = 0;
  12846. goto dodyn;
  12847. case R_PPC64_TPREL64:
  12848. if (htab->elf.tls_sec != NULL)
  12849. addend -= htab->elf.tls_sec->vma + TP_OFFSET;
  12850. goto dodyn;
  12851. case R_PPC64_DTPREL64:
  12852. if (htab->elf.tls_sec != NULL)
  12853. addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
  12854. /* Fall thru */
  12855. /* Relocations that may need to be propagated if this is a
  12856. dynamic object. */
  12857. case R_PPC64_REL30:
  12858. case R_PPC64_REL32:
  12859. case R_PPC64_REL64:
  12860. case R_PPC64_ADDR14:
  12861. case R_PPC64_ADDR14_BRNTAKEN:
  12862. case R_PPC64_ADDR14_BRTAKEN:
  12863. case R_PPC64_ADDR16:
  12864. case R_PPC64_ADDR16_DS:
  12865. case R_PPC64_ADDR16_HA:
  12866. case R_PPC64_ADDR16_HI:
  12867. case R_PPC64_ADDR16_HIGH:
  12868. case R_PPC64_ADDR16_HIGHA:
  12869. case R_PPC64_ADDR16_HIGHER:
  12870. case R_PPC64_ADDR16_HIGHERA:
  12871. case R_PPC64_ADDR16_HIGHEST:
  12872. case R_PPC64_ADDR16_HIGHESTA:
  12873. case R_PPC64_ADDR16_LO:
  12874. case R_PPC64_ADDR16_LO_DS:
  12875. case R_PPC64_ADDR24:
  12876. case R_PPC64_ADDR32:
  12877. case R_PPC64_ADDR64:
  12878. case R_PPC64_UADDR16:
  12879. case R_PPC64_UADDR32:
  12880. case R_PPC64_UADDR64:
  12881. dodyn:
  12882. if ((input_section->flags & SEC_ALLOC) == 0)
  12883. break;
  12884. if (NO_OPD_RELOCS && is_opd)
  12885. break;
  12886. if ((bfd_link_pic (info)
  12887. && (h == NULL
  12888. || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
  12889. || h->elf.root.type != bfd_link_hash_undefweak)
  12890. && (must_be_dyn_reloc (info, r_type)
  12891. || !SYMBOL_CALLS_LOCAL (info, &h->elf)))
  12892. || (ELIMINATE_COPY_RELOCS
  12893. && !bfd_link_pic (info)
  12894. && h != NULL
  12895. && h->elf.dynindx != -1
  12896. && !h->elf.non_got_ref
  12897. && !h->elf.def_regular)
  12898. || (!bfd_link_pic (info)
  12899. && (h != NULL
  12900. ? h->elf.type == STT_GNU_IFUNC
  12901. : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)))
  12902. {
  12903. bfd_boolean skip, relocate;
  12904. asection *sreloc;
  12905. bfd_vma out_off;
  12906. /* When generating a dynamic object, these relocations
  12907. are copied into the output file to be resolved at run
  12908. time. */
  12909. skip = FALSE;
  12910. relocate = FALSE;
  12911. out_off = _bfd_elf_section_offset (output_bfd, info,
  12912. input_section, rel->r_offset);
  12913. if (out_off == (bfd_vma) -1)
  12914. skip = TRUE;
  12915. else if (out_off == (bfd_vma) -2)
  12916. skip = TRUE, relocate = TRUE;
  12917. out_off += (input_section->output_section->vma
  12918. + input_section->output_offset);
  12919. outrel.r_offset = out_off;
  12920. outrel.r_addend = rel->r_addend;
  12921. /* Optimize unaligned reloc use. */
  12922. if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0)
  12923. || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0))
  12924. r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64;
  12925. else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0)
  12926. || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0))
  12927. r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32;
  12928. else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0)
  12929. || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0))
  12930. r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16;
  12931. if (skip)
  12932. memset (&outrel, 0, sizeof outrel);
  12933. else if (!SYMBOL_REFERENCES_LOCAL (info, &h->elf)
  12934. && !is_opd
  12935. && r_type != R_PPC64_TOC)
  12936. {
  12937. BFD_ASSERT (h->elf.dynindx != -1);
  12938. outrel.r_info = ELF64_R_INFO (h->elf.dynindx, r_type);
  12939. }
  12940. else
  12941. {
  12942. /* This symbol is local, or marked to become local,
  12943. or this is an opd section reloc which must point
  12944. at a local function. */
  12945. outrel.r_addend += relocation;
  12946. if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
  12947. {
  12948. if (is_opd && h != NULL)
  12949. {
  12950. /* Lie about opd entries. This case occurs
  12951. when building shared libraries and we
  12952. reference a function in another shared
  12953. lib. The same thing happens for a weak
  12954. definition in an application that's
  12955. overridden by a strong definition in a
  12956. shared lib. (I believe this is a generic
  12957. bug in binutils handling of weak syms.)
  12958. In these cases we won't use the opd
  12959. entry in this lib. */
  12960. unresolved_reloc = FALSE;
  12961. }
  12962. if (!is_opd
  12963. && r_type == R_PPC64_ADDR64
  12964. && (h != NULL
  12965. ? h->elf.type == STT_GNU_IFUNC
  12966. : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))
  12967. outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
  12968. else
  12969. {
  12970. outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
  12971. /* We need to relocate .opd contents for ld.so.
  12972. Prelink also wants simple and consistent rules
  12973. for relocs. This make all RELATIVE relocs have
  12974. *r_offset equal to r_addend. */
  12975. relocate = TRUE;
  12976. }
  12977. }
  12978. else
  12979. {
  12980. long indx = 0;
  12981. if (h != NULL
  12982. ? h->elf.type == STT_GNU_IFUNC
  12983. : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
  12984. {
  12985. info->callbacks->einfo
  12986. (_("%P: %H: %s for indirect "
  12987. "function `%T' unsupported\n"),
  12988. input_bfd, input_section, rel->r_offset,
  12989. ppc64_elf_howto_table[r_type]->name,
  12990. sym_name);
  12991. ret = FALSE;
  12992. }
  12993. else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec))
  12994. ;
  12995. else if (sec == NULL || sec->owner == NULL)
  12996. {
  12997. bfd_set_error (bfd_error_bad_value);
  12998. return FALSE;
  12999. }
  13000. else
  13001. {
  13002. asection *osec;
  13003. osec = sec->output_section;
  13004. indx = elf_section_data (osec)->dynindx;
  13005. if (indx == 0)
  13006. {
  13007. if ((osec->flags & SEC_READONLY) == 0
  13008. && htab->elf.data_index_section != NULL)
  13009. osec = htab->elf.data_index_section;
  13010. else
  13011. osec = htab->elf.text_index_section;
  13012. indx = elf_section_data (osec)->dynindx;
  13013. }
  13014. BFD_ASSERT (indx != 0);
  13015. /* We are turning this relocation into one
  13016. against a section symbol, so subtract out
  13017. the output section's address but not the
  13018. offset of the input section in the output
  13019. section. */
  13020. outrel.r_addend -= osec->vma;
  13021. }
  13022. outrel.r_info = ELF64_R_INFO (indx, r_type);
  13023. }
  13024. }
  13025. sreloc = elf_section_data (input_section)->sreloc;
  13026. if (h != NULL
  13027. ? h->elf.type == STT_GNU_IFUNC
  13028. : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
  13029. sreloc = htab->elf.irelplt;
  13030. if (sreloc == NULL)
  13031. abort ();
  13032. if (sreloc->reloc_count * sizeof (Elf64_External_Rela)
  13033. >= sreloc->size)
  13034. abort ();
  13035. loc = sreloc->contents;
  13036. loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
  13037. bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
  13038. /* If this reloc is against an external symbol, it will
  13039. be computed at runtime, so there's no need to do
  13040. anything now. However, for the sake of prelink ensure
  13041. that the section contents are a known value. */
  13042. if (! relocate)
  13043. {
  13044. unresolved_reloc = FALSE;
  13045. /* The value chosen here is quite arbitrary as ld.so
  13046. ignores section contents except for the special
  13047. case of .opd where the contents might be accessed
  13048. before relocation. Choose zero, as that won't
  13049. cause reloc overflow. */
  13050. relocation = 0;
  13051. addend = 0;
  13052. /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
  13053. to improve backward compatibility with older
  13054. versions of ld. */
  13055. if (r_type == R_PPC64_ADDR64)
  13056. addend = outrel.r_addend;
  13057. /* Adjust pc_relative relocs to have zero in *r_offset. */
  13058. else if (ppc64_elf_howto_table[r_type]->pc_relative)
  13059. addend = (input_section->output_section->vma
  13060. + input_section->output_offset
  13061. + rel->r_offset);
  13062. }
  13063. }
  13064. break;
  13065. case R_PPC64_COPY:
  13066. case R_PPC64_GLOB_DAT:
  13067. case R_PPC64_JMP_SLOT:
  13068. case R_PPC64_JMP_IREL:
  13069. case R_PPC64_RELATIVE:
  13070. /* We shouldn't ever see these dynamic relocs in relocatable
  13071. files. */
  13072. /* Fall through. */
  13073. case R_PPC64_PLTGOT16:
  13074. case R_PPC64_PLTGOT16_DS:
  13075. case R_PPC64_PLTGOT16_HA:
  13076. case R_PPC64_PLTGOT16_HI:
  13077. case R_PPC64_PLTGOT16_LO:
  13078. case R_PPC64_PLTGOT16_LO_DS:
  13079. case R_PPC64_PLTREL32:
  13080. case R_PPC64_PLTREL64:
  13081. /* These ones haven't been implemented yet. */
  13082. info->callbacks->einfo
  13083. (_("%P: %B: %s is not supported for `%T'\n"),
  13084. input_bfd,
  13085. ppc64_elf_howto_table[r_type]->name, sym_name);
  13086. bfd_set_error (bfd_error_invalid_operation);
  13087. ret = FALSE;
  13088. continue;
  13089. }
  13090. /* Multi-instruction sequences that access the TOC can be
  13091. optimized, eg. addis ra,r2,0; addi rb,ra,x;
  13092. to nop; addi rb,r2,x; */
  13093. switch (r_type)
  13094. {
  13095. default:
  13096. break;
  13097. case R_PPC64_GOT_TLSLD16_HI:
  13098. case R_PPC64_GOT_TLSGD16_HI:
  13099. case R_PPC64_GOT_TPREL16_HI:
  13100. case R_PPC64_GOT_DTPREL16_HI:
  13101. case R_PPC64_GOT16_HI:
  13102. case R_PPC64_TOC16_HI:
  13103. /* These relocs would only be useful if building up an
  13104. offset to later add to r2, perhaps in an indexed
  13105. addressing mode instruction. Don't try to optimize.
  13106. Unfortunately, the possibility of someone building up an
  13107. offset like this or even with the HA relocs, means that
  13108. we need to check the high insn when optimizing the low
  13109. insn. */
  13110. break;
  13111. case R_PPC64_GOT_TLSLD16_HA:
  13112. case R_PPC64_GOT_TLSGD16_HA:
  13113. case R_PPC64_GOT_TPREL16_HA:
  13114. case R_PPC64_GOT_DTPREL16_HA:
  13115. case R_PPC64_GOT16_HA:
  13116. case R_PPC64_TOC16_HA:
  13117. if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000
  13118. && !ppc64_elf_tdata (input_bfd)->unexpected_toc_insn)
  13119. {
  13120. bfd_byte *p = contents + (rel->r_offset & ~3);
  13121. bfd_put_32 (input_bfd, NOP, p);
  13122. }
  13123. break;
  13124. case R_PPC64_GOT_TLSLD16_LO:
  13125. case R_PPC64_GOT_TLSGD16_LO:
  13126. case R_PPC64_GOT_TPREL16_LO_DS:
  13127. case R_PPC64_GOT_DTPREL16_LO_DS:
  13128. case R_PPC64_GOT16_LO:
  13129. case R_PPC64_GOT16_LO_DS:
  13130. case R_PPC64_TOC16_LO:
  13131. case R_PPC64_TOC16_LO_DS:
  13132. if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000
  13133. && !ppc64_elf_tdata (input_bfd)->unexpected_toc_insn)
  13134. {
  13135. bfd_byte *p = contents + (rel->r_offset & ~3);
  13136. insn = bfd_get_32 (input_bfd, p);
  13137. if ((insn & (0x3f << 26)) == 12u << 26 /* addic */)
  13138. {
  13139. /* Transform addic to addi when we change reg. */
  13140. insn &= ~((0x3f << 26) | (0x1f << 16));
  13141. insn |= (14u << 26) | (2 << 16);
  13142. }
  13143. else
  13144. {
  13145. insn &= ~(0x1f << 16);
  13146. insn |= 2 << 16;
  13147. }
  13148. bfd_put_32 (input_bfd, insn, p);
  13149. }
  13150. break;
  13151. }
  13152. /* Do any further special processing. */
  13153. howto = ppc64_elf_howto_table[(int) r_type];
  13154. switch (r_type)
  13155. {
  13156. default:
  13157. break;
  13158. case R_PPC64_REL16_HA:
  13159. case R_PPC64_ADDR16_HA:
  13160. case R_PPC64_ADDR16_HIGHA:
  13161. case R_PPC64_ADDR16_HIGHERA:
  13162. case R_PPC64_ADDR16_HIGHESTA:
  13163. case R_PPC64_TOC16_HA:
  13164. case R_PPC64_SECTOFF_HA:
  13165. case R_PPC64_TPREL16_HA:
  13166. case R_PPC64_TPREL16_HIGHA:
  13167. case R_PPC64_TPREL16_HIGHERA:
  13168. case R_PPC64_TPREL16_HIGHESTA:
  13169. case R_PPC64_DTPREL16_HA:
  13170. case R_PPC64_DTPREL16_HIGHA:
  13171. case R_PPC64_DTPREL16_HIGHERA:
  13172. case R_PPC64_DTPREL16_HIGHESTA:
  13173. /* It's just possible that this symbol is a weak symbol
  13174. that's not actually defined anywhere. In that case,
  13175. 'sec' would be NULL, and we should leave the symbol
  13176. alone (it will be set to zero elsewhere in the link). */
  13177. if (sec == NULL)
  13178. break;
  13179. /* Fall thru */
  13180. case R_PPC64_GOT16_HA:
  13181. case R_PPC64_PLTGOT16_HA:
  13182. case R_PPC64_PLT16_HA:
  13183. case R_PPC64_GOT_TLSGD16_HA:
  13184. case R_PPC64_GOT_TLSLD16_HA:
  13185. case R_PPC64_GOT_TPREL16_HA:
  13186. case R_PPC64_GOT_DTPREL16_HA:
  13187. /* Add 0x10000 if sign bit in 0:15 is set.
  13188. Bits 0:15 are not used. */
  13189. addend += 0x8000;
  13190. break;
  13191. case R_PPC64_ADDR16_DS:
  13192. case R_PPC64_ADDR16_LO_DS:
  13193. case R_PPC64_GOT16_DS:
  13194. case R_PPC64_GOT16_LO_DS:
  13195. case R_PPC64_PLT16_LO_DS:
  13196. case R_PPC64_SECTOFF_DS:
  13197. case R_PPC64_SECTOFF_LO_DS:
  13198. case R_PPC64_TOC16_DS:
  13199. case R_PPC64_TOC16_LO_DS:
  13200. case R_PPC64_PLTGOT16_DS:
  13201. case R_PPC64_PLTGOT16_LO_DS:
  13202. case R_PPC64_GOT_TPREL16_DS:
  13203. case R_PPC64_GOT_TPREL16_LO_DS:
  13204. case R_PPC64_GOT_DTPREL16_DS:
  13205. case R_PPC64_GOT_DTPREL16_LO_DS:
  13206. case R_PPC64_TPREL16_DS:
  13207. case R_PPC64_TPREL16_LO_DS:
  13208. case R_PPC64_DTPREL16_DS:
  13209. case R_PPC64_DTPREL16_LO_DS:
  13210. insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
  13211. mask = 3;
  13212. /* If this reloc is against an lq insn, then the value must be
  13213. a multiple of 16. This is somewhat of a hack, but the
  13214. "correct" way to do this by defining _DQ forms of all the
  13215. _DS relocs bloats all reloc switches in this file. It
  13216. doesn't seem to make much sense to use any of these relocs
  13217. in data, so testing the insn should be safe. */
  13218. if ((insn & (0x3f << 26)) == (56u << 26))
  13219. mask = 15;
  13220. if (((relocation + addend) & mask) != 0)
  13221. {
  13222. info->callbacks->einfo
  13223. (_("%P: %H: error: %s not a multiple of %u\n"),
  13224. input_bfd, input_section, rel->r_offset,
  13225. howto->name,
  13226. mask + 1);
  13227. bfd_set_error (bfd_error_bad_value);
  13228. ret = FALSE;
  13229. continue;
  13230. }
  13231. break;
  13232. }
  13233. /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
  13234. because such sections are not SEC_ALLOC and thus ld.so will
  13235. not process them. */
  13236. if (unresolved_reloc
  13237. && !((input_section->flags & SEC_DEBUGGING) != 0
  13238. && h->elf.def_dynamic)
  13239. && _bfd_elf_section_offset (output_bfd, info, input_section,
  13240. rel->r_offset) != (bfd_vma) -1)
  13241. {
  13242. info->callbacks->einfo
  13243. (_("%P: %H: unresolvable %s against `%T'\n"),
  13244. input_bfd, input_section, rel->r_offset,
  13245. howto->name,
  13246. h->elf.root.root.string);
  13247. ret = FALSE;
  13248. }
  13249. /* 16-bit fields in insns mostly have signed values, but a
  13250. few insns have 16-bit unsigned values. Really, we should
  13251. have different reloc types. */
  13252. if (howto->complain_on_overflow != complain_overflow_dont
  13253. && howto->dst_mask == 0xffff
  13254. && (input_section->flags & SEC_CODE) != 0)
  13255. {
  13256. enum complain_overflow complain = complain_overflow_signed;
  13257. insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
  13258. if ((insn & (0x3f << 26)) == 10u << 26 /* cmpli */)
  13259. complain = complain_overflow_bitfield;
  13260. else if (howto->rightshift == 0
  13261. ? ((insn & (0x3f << 26)) == 28u << 26 /* andi */
  13262. || (insn & (0x3f << 26)) == 24u << 26 /* ori */
  13263. || (insn & (0x3f << 26)) == 26u << 26 /* xori */)
  13264. : ((insn & (0x3f << 26)) == 29u << 26 /* andis */
  13265. || (insn & (0x3f << 26)) == 25u << 26 /* oris */
  13266. || (insn & (0x3f << 26)) == 27u << 26 /* xoris */))
  13267. complain = complain_overflow_unsigned;
  13268. if (howto->complain_on_overflow != complain)
  13269. {
  13270. alt_howto = *howto;
  13271. alt_howto.complain_on_overflow = complain;
  13272. howto = &alt_howto;
  13273. }
  13274. }
  13275. r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
  13276. rel->r_offset, relocation, addend);
  13277. if (r != bfd_reloc_ok)
  13278. {
  13279. char *more_info = NULL;
  13280. const char *reloc_name = howto->name;
  13281. if (reloc_dest != DEST_NORMAL)
  13282. {
  13283. more_info = bfd_malloc (strlen (reloc_name) + 8);
  13284. if (more_info != NULL)
  13285. {
  13286. strcpy (more_info, reloc_name);
  13287. strcat (more_info, (reloc_dest == DEST_OPD
  13288. ? " (OPD)" : " (stub)"));
  13289. reloc_name = more_info;
  13290. }
  13291. }
  13292. if (r == bfd_reloc_overflow)
  13293. {
  13294. /* On code like "if (foo) foo();" don't report overflow
  13295. on a branch to zero when foo is undefined. */
  13296. if (!warned
  13297. && (reloc_dest == DEST_STUB
  13298. || !(h != NULL
  13299. && (h->elf.root.type == bfd_link_hash_undefweak
  13300. || h->elf.root.type == bfd_link_hash_undefined)
  13301. && is_branch_reloc (r_type))))
  13302. {
  13303. if (!((*info->callbacks->reloc_overflow)
  13304. (info, &h->elf.root, sym_name,
  13305. reloc_name, orig_rel.r_addend,
  13306. input_bfd, input_section, rel->r_offset)))
  13307. return FALSE;
  13308. }
  13309. }
  13310. else
  13311. {
  13312. info->callbacks->einfo
  13313. (_("%P: %H: %s against `%T': error %d\n"),
  13314. input_bfd, input_section, rel->r_offset,
  13315. reloc_name, sym_name, (int) r);
  13316. ret = FALSE;
  13317. }
  13318. if (more_info != NULL)
  13319. free (more_info);
  13320. }
  13321. }
  13322. /* If we're emitting relocations, then shortly after this function
  13323. returns, reloc offsets and addends for this section will be
  13324. adjusted. Worse, reloc symbol indices will be for the output
  13325. file rather than the input. Save a copy of the relocs for
  13326. opd_entry_value. */
  13327. if (is_opd && (info->emitrelocations || bfd_link_relocatable (info)))
  13328. {
  13329. bfd_size_type amt;
  13330. amt = input_section->reloc_count * sizeof (Elf_Internal_Rela);
  13331. rel = bfd_alloc (input_bfd, amt);
  13332. BFD_ASSERT (ppc64_elf_tdata (input_bfd)->opd.relocs == NULL);
  13333. ppc64_elf_tdata (input_bfd)->opd.relocs = rel;
  13334. if (rel == NULL)
  13335. return FALSE;
  13336. memcpy (rel, relocs, amt);
  13337. }
  13338. return ret;
  13339. }
  13340. /* Adjust the value of any local symbols in opd sections. */
  13341. static int
  13342. ppc64_elf_output_symbol_hook (struct bfd_link_info *info,
  13343. const char *name ATTRIBUTE_UNUSED,
  13344. Elf_Internal_Sym *elfsym,
  13345. asection *input_sec,
  13346. struct elf_link_hash_entry *h)
  13347. {
  13348. struct _opd_sec_data *opd;
  13349. long adjust;
  13350. bfd_vma value;
  13351. if (h != NULL)
  13352. return 1;
  13353. opd = get_opd_info (input_sec);
  13354. if (opd == NULL || opd->adjust == NULL)
  13355. return 1;
  13356. value = elfsym->st_value - input_sec->output_offset;
  13357. if (!bfd_link_relocatable (info))
  13358. value -= input_sec->output_section->vma;
  13359. adjust = opd->adjust[OPD_NDX (value)];
  13360. if (adjust == -1)
  13361. return 2;
  13362. elfsym->st_value += adjust;
  13363. return 1;
  13364. }
  13365. /* Finish up dynamic symbol handling. We set the contents of various
  13366. dynamic sections here. */
  13367. static bfd_boolean
  13368. ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
  13369. struct bfd_link_info *info,
  13370. struct elf_link_hash_entry *h,
  13371. Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
  13372. {
  13373. struct ppc_link_hash_table *htab;
  13374. struct plt_entry *ent;
  13375. Elf_Internal_Rela rela;
  13376. bfd_byte *loc;
  13377. htab = ppc_hash_table (info);
  13378. if (htab == NULL)
  13379. return FALSE;
  13380. for (ent = h->plt.plist; ent != NULL; ent = ent->next)
  13381. if (ent->plt.offset != (bfd_vma) -1)
  13382. {
  13383. /* This symbol has an entry in the procedure linkage
  13384. table. Set it up. */
  13385. if (!htab->elf.dynamic_sections_created
  13386. || h->dynindx == -1)
  13387. {
  13388. BFD_ASSERT (h->type == STT_GNU_IFUNC
  13389. && h->def_regular
  13390. && (h->root.type == bfd_link_hash_defined
  13391. || h->root.type == bfd_link_hash_defweak));
  13392. rela.r_offset = (htab->elf.iplt->output_section->vma
  13393. + htab->elf.iplt->output_offset
  13394. + ent->plt.offset);
  13395. if (htab->opd_abi)
  13396. rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
  13397. else
  13398. rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
  13399. rela.r_addend = (h->root.u.def.value
  13400. + h->root.u.def.section->output_offset
  13401. + h->root.u.def.section->output_section->vma
  13402. + ent->addend);
  13403. loc = (htab->elf.irelplt->contents
  13404. + (htab->elf.irelplt->reloc_count++
  13405. * sizeof (Elf64_External_Rela)));
  13406. }
  13407. else
  13408. {
  13409. rela.r_offset = (htab->elf.splt->output_section->vma
  13410. + htab->elf.splt->output_offset
  13411. + ent->plt.offset);
  13412. rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
  13413. rela.r_addend = ent->addend;
  13414. loc = (htab->elf.srelplt->contents
  13415. + ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE (htab))
  13416. / PLT_ENTRY_SIZE (htab) * sizeof (Elf64_External_Rela)));
  13417. }
  13418. bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
  13419. if (!htab->opd_abi)
  13420. {
  13421. if (!h->def_regular)
  13422. {
  13423. /* Mark the symbol as undefined, rather than as
  13424. defined in glink. Leave the value if there were
  13425. any relocations where pointer equality matters
  13426. (this is a clue for the dynamic linker, to make
  13427. function pointer comparisons work between an
  13428. application and shared library), otherwise set it
  13429. to zero. */
  13430. sym->st_shndx = SHN_UNDEF;
  13431. if (!h->pointer_equality_needed)
  13432. sym->st_value = 0;
  13433. else if (!h->ref_regular_nonweak)
  13434. {
  13435. /* This breaks function pointer comparisons, but
  13436. that is better than breaking tests for a NULL
  13437. function pointer. */
  13438. sym->st_value = 0;
  13439. }
  13440. }
  13441. }
  13442. }
  13443. if (h->needs_copy)
  13444. {
  13445. /* This symbol needs a copy reloc. Set it up. */
  13446. if (h->dynindx == -1
  13447. || (h->root.type != bfd_link_hash_defined
  13448. && h->root.type != bfd_link_hash_defweak)
  13449. || htab->relbss == NULL)
  13450. abort ();
  13451. rela.r_offset = (h->root.u.def.value
  13452. + h->root.u.def.section->output_section->vma
  13453. + h->root.u.def.section->output_offset);
  13454. rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
  13455. rela.r_addend = 0;
  13456. loc = htab->relbss->contents;
  13457. loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela);
  13458. bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
  13459. }
  13460. return TRUE;
  13461. }
  13462. /* Used to decide how to sort relocs in an optimal manner for the
  13463. dynamic linker, before writing them out. */
  13464. static enum elf_reloc_type_class
  13465. ppc64_elf_reloc_type_class (const struct bfd_link_info *info,
  13466. const asection *rel_sec,
  13467. const Elf_Internal_Rela *rela)
  13468. {
  13469. enum elf_ppc64_reloc_type r_type;
  13470. struct ppc_link_hash_table *htab = ppc_hash_table (info);
  13471. if (rel_sec == htab->elf.irelplt)
  13472. return reloc_class_ifunc;
  13473. r_type = ELF64_R_TYPE (rela->r_info);
  13474. switch (r_type)
  13475. {
  13476. case R_PPC64_RELATIVE:
  13477. return reloc_class_relative;
  13478. case R_PPC64_JMP_SLOT:
  13479. return reloc_class_plt;
  13480. case R_PPC64_COPY:
  13481. return reloc_class_copy;
  13482. default:
  13483. return reloc_class_normal;
  13484. }
  13485. }
  13486. /* Finish up the dynamic sections. */
  13487. static bfd_boolean
  13488. ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
  13489. struct bfd_link_info *info)
  13490. {
  13491. struct ppc_link_hash_table *htab;
  13492. bfd *dynobj;
  13493. asection *sdyn;
  13494. htab = ppc_hash_table (info);
  13495. if (htab == NULL)
  13496. return FALSE;
  13497. dynobj = htab->elf.dynobj;
  13498. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  13499. if (htab->elf.dynamic_sections_created)
  13500. {
  13501. Elf64_External_Dyn *dyncon, *dynconend;
  13502. if (sdyn == NULL || htab->elf.sgot == NULL)
  13503. abort ();
  13504. dyncon = (Elf64_External_Dyn *) sdyn->contents;
  13505. dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
  13506. for (; dyncon < dynconend; dyncon++)
  13507. {
  13508. Elf_Internal_Dyn dyn;
  13509. asection *s;
  13510. bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
  13511. switch (dyn.d_tag)
  13512. {
  13513. default:
  13514. continue;
  13515. case DT_PPC64_GLINK:
  13516. s = htab->glink;
  13517. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  13518. /* We stupidly defined DT_PPC64_GLINK to be the start
  13519. of glink rather than the first entry point, which is
  13520. what ld.so needs, and now have a bigger stub to
  13521. support automatic multiple TOCs. */
  13522. dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 8 * 4;
  13523. break;
  13524. case DT_PPC64_OPD:
  13525. s = bfd_get_section_by_name (output_bfd, ".opd");
  13526. if (s == NULL)
  13527. continue;
  13528. dyn.d_un.d_ptr = s->vma;
  13529. break;
  13530. case DT_PPC64_OPT:
  13531. if (htab->do_multi_toc && htab->multi_toc_needed)
  13532. dyn.d_un.d_val |= PPC64_OPT_MULTI_TOC;
  13533. break;
  13534. case DT_PPC64_OPDSZ:
  13535. s = bfd_get_section_by_name (output_bfd, ".opd");
  13536. if (s == NULL)
  13537. continue;
  13538. dyn.d_un.d_val = s->size;
  13539. break;
  13540. case DT_PLTGOT:
  13541. s = htab->elf.splt;
  13542. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  13543. break;
  13544. case DT_JMPREL:
  13545. s = htab->elf.srelplt;
  13546. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  13547. break;
  13548. case DT_PLTRELSZ:
  13549. dyn.d_un.d_val = htab->elf.srelplt->size;
  13550. break;
  13551. case DT_RELASZ:
  13552. /* Don't count procedure linkage table relocs in the
  13553. overall reloc count. */
  13554. s = htab->elf.srelplt;
  13555. if (s == NULL)
  13556. continue;
  13557. dyn.d_un.d_val -= s->size;
  13558. break;
  13559. case DT_RELA:
  13560. /* We may not be using the standard ELF linker script.
  13561. If .rela.plt is the first .rela section, we adjust
  13562. DT_RELA to not include it. */
  13563. s = htab->elf.srelplt;
  13564. if (s == NULL)
  13565. continue;
  13566. if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
  13567. continue;
  13568. dyn.d_un.d_ptr += s->size;
  13569. break;
  13570. }
  13571. bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
  13572. }
  13573. }
  13574. if (htab->elf.sgot != NULL && htab->elf.sgot->size != 0)
  13575. {
  13576. /* Fill in the first entry in the global offset table.
  13577. We use it to hold the link-time TOCbase. */
  13578. bfd_put_64 (output_bfd,
  13579. elf_gp (output_bfd) + TOC_BASE_OFF,
  13580. htab->elf.sgot->contents);
  13581. /* Set .got entry size. */
  13582. elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 8;
  13583. }
  13584. if (htab->elf.splt != NULL && htab->elf.splt->size != 0)
  13585. {
  13586. /* Set .plt entry size. */
  13587. elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize
  13588. = PLT_ENTRY_SIZE (htab);
  13589. }
  13590. /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
  13591. brlt ourselves if emitrelocations. */
  13592. if (htab->brlt != NULL
  13593. && htab->brlt->reloc_count != 0
  13594. && !_bfd_elf_link_output_relocs (output_bfd,
  13595. htab->brlt,
  13596. elf_section_data (htab->brlt)->rela.hdr,
  13597. elf_section_data (htab->brlt)->relocs,
  13598. NULL))
  13599. return FALSE;
  13600. if (htab->glink != NULL
  13601. && htab->glink->reloc_count != 0
  13602. && !_bfd_elf_link_output_relocs (output_bfd,
  13603. htab->glink,
  13604. elf_section_data (htab->glink)->rela.hdr,
  13605. elf_section_data (htab->glink)->relocs,
  13606. NULL))
  13607. return FALSE;
  13608. if (htab->glink_eh_frame != NULL
  13609. && htab->glink_eh_frame->size != 0)
  13610. {
  13611. bfd_vma val;
  13612. bfd_byte *p;
  13613. asection *stub_sec;
  13614. p = htab->glink_eh_frame->contents + sizeof (glink_eh_frame_cie);
  13615. for (stub_sec = htab->params->stub_bfd->sections;
  13616. stub_sec != NULL;
  13617. stub_sec = stub_sec->next)
  13618. if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
  13619. {
  13620. /* FDE length. */
  13621. p += 4;
  13622. /* CIE pointer. */
  13623. p += 4;
  13624. /* Offset to stub section. */
  13625. val = (stub_sec->output_section->vma
  13626. + stub_sec->output_offset);
  13627. val -= (htab->glink_eh_frame->output_section->vma
  13628. + htab->glink_eh_frame->output_offset
  13629. + (p - htab->glink_eh_frame->contents));
  13630. if (val + 0x80000000 > 0xffffffff)
  13631. {
  13632. info->callbacks->einfo
  13633. (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
  13634. stub_sec->name);
  13635. return FALSE;
  13636. }
  13637. bfd_put_32 (dynobj, val, p);
  13638. p += 4;
  13639. /* stub section size. */
  13640. p += 4;
  13641. /* Augmentation. */
  13642. p += 1;
  13643. /* Pad. */
  13644. p += 7;
  13645. }
  13646. if (htab->glink != NULL && htab->glink->size != 0)
  13647. {
  13648. /* FDE length. */
  13649. p += 4;
  13650. /* CIE pointer. */
  13651. p += 4;
  13652. /* Offset to .glink. */
  13653. val = (htab->glink->output_section->vma
  13654. + htab->glink->output_offset
  13655. + 8);
  13656. val -= (htab->glink_eh_frame->output_section->vma
  13657. + htab->glink_eh_frame->output_offset
  13658. + (p - htab->glink_eh_frame->contents));
  13659. if (val + 0x80000000 > 0xffffffff)
  13660. {
  13661. info->callbacks->einfo
  13662. (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
  13663. htab->glink->name);
  13664. return FALSE;
  13665. }
  13666. bfd_put_32 (dynobj, val, p);
  13667. p += 4;
  13668. /* .glink size. */
  13669. p += 4;
  13670. /* Augmentation. */
  13671. p += 1;
  13672. /* Ops. */
  13673. p += 7;
  13674. }
  13675. if (htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME
  13676. && !_bfd_elf_write_section_eh_frame (output_bfd, info,
  13677. htab->glink_eh_frame,
  13678. htab->glink_eh_frame->contents))
  13679. return FALSE;
  13680. }
  13681. /* We need to handle writing out multiple GOT sections ourselves,
  13682. since we didn't add them to DYNOBJ. We know dynobj is the first
  13683. bfd. */
  13684. while ((dynobj = dynobj->link.next) != NULL)
  13685. {
  13686. asection *s;
  13687. if (!is_ppc64_elf (dynobj))
  13688. continue;
  13689. s = ppc64_elf_tdata (dynobj)->got;
  13690. if (s != NULL
  13691. && s->size != 0
  13692. && s->output_section != bfd_abs_section_ptr
  13693. && !bfd_set_section_contents (output_bfd, s->output_section,
  13694. s->contents, s->output_offset,
  13695. s->size))
  13696. return FALSE;
  13697. s = ppc64_elf_tdata (dynobj)->relgot;
  13698. if (s != NULL
  13699. && s->size != 0
  13700. && s->output_section != bfd_abs_section_ptr
  13701. && !bfd_set_section_contents (output_bfd, s->output_section,
  13702. s->contents, s->output_offset,
  13703. s->size))
  13704. return FALSE;
  13705. }
  13706. return TRUE;
  13707. }
  13708. #include "elf64-target.h"
  13709. /* FreeBSD support */
  13710. #undef TARGET_LITTLE_SYM
  13711. #undef TARGET_LITTLE_NAME
  13712. #undef TARGET_BIG_SYM
  13713. #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
  13714. #undef TARGET_BIG_NAME
  13715. #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
  13716. #undef ELF_OSABI
  13717. #define ELF_OSABI ELFOSABI_FREEBSD
  13718. #undef elf64_bed
  13719. #define elf64_bed elf64_powerpc_fbsd_bed
  13720. #include "elf64-target.h"