elf32-ppc.c 311 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793
  1. /* PowerPC-specific support for 32-bit ELF
  2. Copyright (C) 1994-2015 Free Software Foundation, Inc.
  3. Written by Ian Lance Taylor, Cygnus Support.
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the
  15. Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  16. Boston, MA 02110-1301, USA. */
  17. /* This file is based on a preliminary PowerPC ELF ABI. The
  18. information may not match the final PowerPC ELF ABI. It includes
  19. suggestions from the in-progress Embedded PowerPC ABI, and that
  20. information may also not match. */
  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/ppc.h"
  28. #include "elf32-ppc.h"
  29. #include "elf-vxworks.h"
  30. #include "dwarf2.h"
  31. #include "elf-linux-psinfo.h"
  32. typedef enum split16_format_type
  33. {
  34. split16a_type = 0,
  35. split16d_type
  36. }
  37. split16_format_type;
  38. /* RELA relocations are used here. */
  39. static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
  40. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  41. static bfd_reloc_status_type ppc_elf_unhandled_reloc
  42. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  43. /* Branch prediction bit for branch taken relocs. */
  44. #define BRANCH_PREDICT_BIT 0x200000
  45. /* Mask to set RA in memory instructions. */
  46. #define RA_REGISTER_MASK 0x001f0000
  47. /* Value to shift register by to insert RA. */
  48. #define RA_REGISTER_SHIFT 16
  49. /* The name of the dynamic interpreter. This is put in the .interp
  50. section. */
  51. #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
  52. /* For old-style PLT. */
  53. /* The number of single-slot PLT entries (the rest use two slots). */
  54. #define PLT_NUM_SINGLE_ENTRIES 8192
  55. /* For new-style .glink and .plt. */
  56. #define GLINK_PLTRESOLVE 16*4
  57. #define GLINK_ENTRY_SIZE 4*4
  58. #define TLS_GET_ADDR_GLINK_SIZE 12*4
  59. /* VxWorks uses its own plt layout, filled in by the static linker. */
  60. /* The standard VxWorks PLT entry. */
  61. #define VXWORKS_PLT_ENTRY_SIZE 32
  62. static const bfd_vma ppc_elf_vxworks_plt_entry
  63. [VXWORKS_PLT_ENTRY_SIZE / 4] =
  64. {
  65. 0x3d800000, /* lis r12,0 */
  66. 0x818c0000, /* lwz r12,0(r12) */
  67. 0x7d8903a6, /* mtctr r12 */
  68. 0x4e800420, /* bctr */
  69. 0x39600000, /* li r11,0 */
  70. 0x48000000, /* b 14 <.PLT0resolve+0x4> */
  71. 0x60000000, /* nop */
  72. 0x60000000, /* nop */
  73. };
  74. static const bfd_vma ppc_elf_vxworks_pic_plt_entry
  75. [VXWORKS_PLT_ENTRY_SIZE / 4] =
  76. {
  77. 0x3d9e0000, /* addis r12,r30,0 */
  78. 0x818c0000, /* lwz r12,0(r12) */
  79. 0x7d8903a6, /* mtctr r12 */
  80. 0x4e800420, /* bctr */
  81. 0x39600000, /* li r11,0 */
  82. 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */
  83. 0x60000000, /* nop */
  84. 0x60000000, /* nop */
  85. };
  86. /* The initial VxWorks PLT entry. */
  87. #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32
  88. static const bfd_vma ppc_elf_vxworks_plt0_entry
  89. [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
  90. {
  91. 0x3d800000, /* lis r12,0 */
  92. 0x398c0000, /* addi r12,r12,0 */
  93. 0x800c0008, /* lwz r0,8(r12) */
  94. 0x7c0903a6, /* mtctr r0 */
  95. 0x818c0004, /* lwz r12,4(r12) */
  96. 0x4e800420, /* bctr */
  97. 0x60000000, /* nop */
  98. 0x60000000, /* nop */
  99. };
  100. static const bfd_vma ppc_elf_vxworks_pic_plt0_entry
  101. [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
  102. {
  103. 0x819e0008, /* lwz r12,8(r30) */
  104. 0x7d8903a6, /* mtctr r12 */
  105. 0x819e0004, /* lwz r12,4(r30) */
  106. 0x4e800420, /* bctr */
  107. 0x60000000, /* nop */
  108. 0x60000000, /* nop */
  109. 0x60000000, /* nop */
  110. 0x60000000, /* nop */
  111. };
  112. /* For executables, we have some additional relocations in
  113. .rela.plt.unloaded, for the kernel loader. */
  114. /* The number of non-JMP_SLOT relocations per PLT0 slot. */
  115. #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3
  116. /* The number of relocations in the PLTResolve slot. */
  117. #define VXWORKS_PLTRESOLVE_RELOCS 2
  118. /* The number of relocations in the PLTResolve slot when when creating
  119. a shared library. */
  120. #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0
  121. /* Some instructions. */
  122. #define ADDIS_11_11 0x3d6b0000
  123. #define ADDIS_11_30 0x3d7e0000
  124. #define ADDIS_12_12 0x3d8c0000
  125. #define ADDI_11_11 0x396b0000
  126. #define ADD_0_11_11 0x7c0b5a14
  127. #define ADD_3_12_2 0x7c6c1214
  128. #define ADD_11_0_11 0x7d605a14
  129. #define B 0x48000000
  130. #define BA 0x48000002
  131. #define BCL_20_31 0x429f0005
  132. #define BCTR 0x4e800420
  133. #define BEQLR 0x4d820020
  134. #define CMPWI_11_0 0x2c0b0000
  135. #define LIS_11 0x3d600000
  136. #define LIS_12 0x3d800000
  137. #define LWZU_0_12 0x840c0000
  138. #define LWZ_0_12 0x800c0000
  139. #define LWZ_11_3 0x81630000
  140. #define LWZ_11_11 0x816b0000
  141. #define LWZ_11_30 0x817e0000
  142. #define LWZ_12_3 0x81830000
  143. #define LWZ_12_12 0x818c0000
  144. #define MR_0_3 0x7c601b78
  145. #define MR_3_0 0x7c030378
  146. #define MFLR_0 0x7c0802a6
  147. #define MFLR_12 0x7d8802a6
  148. #define MTCTR_0 0x7c0903a6
  149. #define MTCTR_11 0x7d6903a6
  150. #define MTLR_0 0x7c0803a6
  151. #define NOP 0x60000000
  152. #define SUB_11_11_12 0x7d6c5850
  153. /* Offset of tp and dtp pointers from start of TLS block. */
  154. #define TP_OFFSET 0x7000
  155. #define DTP_OFFSET 0x8000
  156. /* The value of a defined global symbol. */
  157. #define SYM_VAL(SYM) \
  158. ((SYM)->root.u.def.section->output_section->vma \
  159. + (SYM)->root.u.def.section->output_offset \
  160. + (SYM)->root.u.def.value)
  161. static reloc_howto_type *ppc_elf_howto_table[R_PPC_max];
  162. static reloc_howto_type ppc_elf_howto_raw[] = {
  163. /* This reloc does nothing. */
  164. HOWTO (R_PPC_NONE, /* type */
  165. 0, /* rightshift */
  166. 3, /* size (0 = byte, 1 = short, 2 = long) */
  167. 0, /* bitsize */
  168. FALSE, /* pc_relative */
  169. 0, /* bitpos */
  170. complain_overflow_dont, /* complain_on_overflow */
  171. bfd_elf_generic_reloc, /* special_function */
  172. "R_PPC_NONE", /* name */
  173. FALSE, /* partial_inplace */
  174. 0, /* src_mask */
  175. 0, /* dst_mask */
  176. FALSE), /* pcrel_offset */
  177. /* A standard 32 bit relocation. */
  178. HOWTO (R_PPC_ADDR32, /* type */
  179. 0, /* rightshift */
  180. 2, /* size (0 = byte, 1 = short, 2 = long) */
  181. 32, /* bitsize */
  182. FALSE, /* pc_relative */
  183. 0, /* bitpos */
  184. complain_overflow_dont, /* complain_on_overflow */
  185. bfd_elf_generic_reloc, /* special_function */
  186. "R_PPC_ADDR32", /* name */
  187. FALSE, /* partial_inplace */
  188. 0, /* src_mask */
  189. 0xffffffff, /* dst_mask */
  190. FALSE), /* pcrel_offset */
  191. /* An absolute 26 bit branch; the lower two bits must be zero.
  192. FIXME: we don't check that, we just clear them. */
  193. HOWTO (R_PPC_ADDR24, /* type */
  194. 0, /* rightshift */
  195. 2, /* size (0 = byte, 1 = short, 2 = long) */
  196. 26, /* bitsize */
  197. FALSE, /* pc_relative */
  198. 0, /* bitpos */
  199. complain_overflow_signed, /* complain_on_overflow */
  200. bfd_elf_generic_reloc, /* special_function */
  201. "R_PPC_ADDR24", /* name */
  202. FALSE, /* partial_inplace */
  203. 0, /* src_mask */
  204. 0x3fffffc, /* dst_mask */
  205. FALSE), /* pcrel_offset */
  206. /* A standard 16 bit relocation. */
  207. HOWTO (R_PPC_ADDR16, /* type */
  208. 0, /* rightshift */
  209. 1, /* size (0 = byte, 1 = short, 2 = long) */
  210. 16, /* bitsize */
  211. FALSE, /* pc_relative */
  212. 0, /* bitpos */
  213. complain_overflow_bitfield, /* complain_on_overflow */
  214. bfd_elf_generic_reloc, /* special_function */
  215. "R_PPC_ADDR16", /* name */
  216. FALSE, /* partial_inplace */
  217. 0, /* src_mask */
  218. 0xffff, /* dst_mask */
  219. FALSE), /* pcrel_offset */
  220. /* A 16 bit relocation without overflow. */
  221. HOWTO (R_PPC_ADDR16_LO, /* type */
  222. 0, /* rightshift */
  223. 1, /* size (0 = byte, 1 = short, 2 = long) */
  224. 16, /* bitsize */
  225. FALSE, /* pc_relative */
  226. 0, /* bitpos */
  227. complain_overflow_dont,/* complain_on_overflow */
  228. bfd_elf_generic_reloc, /* special_function */
  229. "R_PPC_ADDR16_LO", /* name */
  230. FALSE, /* partial_inplace */
  231. 0, /* src_mask */
  232. 0xffff, /* dst_mask */
  233. FALSE), /* pcrel_offset */
  234. /* The high order 16 bits of an address. */
  235. HOWTO (R_PPC_ADDR16_HI, /* type */
  236. 16, /* rightshift */
  237. 1, /* size (0 = byte, 1 = short, 2 = long) */
  238. 16, /* bitsize */
  239. FALSE, /* pc_relative */
  240. 0, /* bitpos */
  241. complain_overflow_dont, /* complain_on_overflow */
  242. bfd_elf_generic_reloc, /* special_function */
  243. "R_PPC_ADDR16_HI", /* name */
  244. FALSE, /* partial_inplace */
  245. 0, /* src_mask */
  246. 0xffff, /* dst_mask */
  247. FALSE), /* pcrel_offset */
  248. /* The high order 16 bits of an address, plus 1 if the contents of
  249. the low 16 bits, treated as a signed number, is negative. */
  250. HOWTO (R_PPC_ADDR16_HA, /* type */
  251. 16, /* rightshift */
  252. 1, /* size (0 = byte, 1 = short, 2 = long) */
  253. 16, /* bitsize */
  254. FALSE, /* pc_relative */
  255. 0, /* bitpos */
  256. complain_overflow_dont, /* complain_on_overflow */
  257. ppc_elf_addr16_ha_reloc, /* special_function */
  258. "R_PPC_ADDR16_HA", /* name */
  259. FALSE, /* partial_inplace */
  260. 0, /* src_mask */
  261. 0xffff, /* dst_mask */
  262. FALSE), /* pcrel_offset */
  263. /* An absolute 16 bit branch; the lower two bits must be zero.
  264. FIXME: we don't check that, we just clear them. */
  265. HOWTO (R_PPC_ADDR14, /* type */
  266. 0, /* rightshift */
  267. 2, /* size (0 = byte, 1 = short, 2 = long) */
  268. 16, /* bitsize */
  269. FALSE, /* pc_relative */
  270. 0, /* bitpos */
  271. complain_overflow_signed, /* complain_on_overflow */
  272. bfd_elf_generic_reloc, /* special_function */
  273. "R_PPC_ADDR14", /* name */
  274. FALSE, /* partial_inplace */
  275. 0, /* src_mask */
  276. 0xfffc, /* dst_mask */
  277. FALSE), /* pcrel_offset */
  278. /* An absolute 16 bit branch, for which bit 10 should be set to
  279. indicate that the branch is expected to be taken. The lower two
  280. bits must be zero. */
  281. HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
  282. 0, /* rightshift */
  283. 2, /* size (0 = byte, 1 = short, 2 = long) */
  284. 16, /* bitsize */
  285. FALSE, /* pc_relative */
  286. 0, /* bitpos */
  287. complain_overflow_signed, /* complain_on_overflow */
  288. bfd_elf_generic_reloc, /* special_function */
  289. "R_PPC_ADDR14_BRTAKEN",/* name */
  290. FALSE, /* partial_inplace */
  291. 0, /* src_mask */
  292. 0xfffc, /* dst_mask */
  293. FALSE), /* pcrel_offset */
  294. /* An absolute 16 bit branch, for which bit 10 should be set to
  295. indicate that the branch is not expected to be taken. The lower
  296. two bits must be zero. */
  297. HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
  298. 0, /* rightshift */
  299. 2, /* size (0 = byte, 1 = short, 2 = long) */
  300. 16, /* bitsize */
  301. FALSE, /* pc_relative */
  302. 0, /* bitpos */
  303. complain_overflow_signed, /* complain_on_overflow */
  304. bfd_elf_generic_reloc, /* special_function */
  305. "R_PPC_ADDR14_BRNTAKEN",/* name */
  306. FALSE, /* partial_inplace */
  307. 0, /* src_mask */
  308. 0xfffc, /* dst_mask */
  309. FALSE), /* pcrel_offset */
  310. /* A relative 26 bit branch; the lower two bits must be zero. */
  311. HOWTO (R_PPC_REL24, /* type */
  312. 0, /* rightshift */
  313. 2, /* size (0 = byte, 1 = short, 2 = long) */
  314. 26, /* bitsize */
  315. TRUE, /* pc_relative */
  316. 0, /* bitpos */
  317. complain_overflow_signed, /* complain_on_overflow */
  318. bfd_elf_generic_reloc, /* special_function */
  319. "R_PPC_REL24", /* name */
  320. FALSE, /* partial_inplace */
  321. 0, /* src_mask */
  322. 0x3fffffc, /* dst_mask */
  323. TRUE), /* pcrel_offset */
  324. /* A relative 16 bit branch; the lower two bits must be zero. */
  325. HOWTO (R_PPC_REL14, /* type */
  326. 0, /* rightshift */
  327. 2, /* size (0 = byte, 1 = short, 2 = long) */
  328. 16, /* bitsize */
  329. TRUE, /* pc_relative */
  330. 0, /* bitpos */
  331. complain_overflow_signed, /* complain_on_overflow */
  332. bfd_elf_generic_reloc, /* special_function */
  333. "R_PPC_REL14", /* name */
  334. FALSE, /* partial_inplace */
  335. 0, /* src_mask */
  336. 0xfffc, /* dst_mask */
  337. TRUE), /* pcrel_offset */
  338. /* A relative 16 bit branch. Bit 10 should be set to indicate that
  339. the branch is expected to be taken. The lower two bits must be
  340. zero. */
  341. HOWTO (R_PPC_REL14_BRTAKEN, /* type */
  342. 0, /* rightshift */
  343. 2, /* size (0 = byte, 1 = short, 2 = long) */
  344. 16, /* bitsize */
  345. TRUE, /* pc_relative */
  346. 0, /* bitpos */
  347. complain_overflow_signed, /* complain_on_overflow */
  348. bfd_elf_generic_reloc, /* special_function */
  349. "R_PPC_REL14_BRTAKEN", /* name */
  350. FALSE, /* partial_inplace */
  351. 0, /* src_mask */
  352. 0xfffc, /* dst_mask */
  353. TRUE), /* pcrel_offset */
  354. /* A relative 16 bit branch. Bit 10 should be set to indicate that
  355. the branch is not expected to be taken. The lower two bits must
  356. be zero. */
  357. HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
  358. 0, /* rightshift */
  359. 2, /* size (0 = byte, 1 = short, 2 = long) */
  360. 16, /* bitsize */
  361. TRUE, /* pc_relative */
  362. 0, /* bitpos */
  363. complain_overflow_signed, /* complain_on_overflow */
  364. bfd_elf_generic_reloc, /* special_function */
  365. "R_PPC_REL14_BRNTAKEN",/* name */
  366. FALSE, /* partial_inplace */
  367. 0, /* src_mask */
  368. 0xfffc, /* dst_mask */
  369. TRUE), /* pcrel_offset */
  370. /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
  371. symbol. */
  372. HOWTO (R_PPC_GOT16, /* type */
  373. 0, /* rightshift */
  374. 1, /* size (0 = byte, 1 = short, 2 = long) */
  375. 16, /* bitsize */
  376. FALSE, /* pc_relative */
  377. 0, /* bitpos */
  378. complain_overflow_signed, /* complain_on_overflow */
  379. bfd_elf_generic_reloc, /* special_function */
  380. "R_PPC_GOT16", /* name */
  381. FALSE, /* partial_inplace */
  382. 0, /* src_mask */
  383. 0xffff, /* dst_mask */
  384. FALSE), /* pcrel_offset */
  385. /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
  386. the symbol. */
  387. HOWTO (R_PPC_GOT16_LO, /* type */
  388. 0, /* rightshift */
  389. 1, /* size (0 = byte, 1 = short, 2 = long) */
  390. 16, /* bitsize */
  391. FALSE, /* pc_relative */
  392. 0, /* bitpos */
  393. complain_overflow_dont, /* complain_on_overflow */
  394. bfd_elf_generic_reloc, /* special_function */
  395. "R_PPC_GOT16_LO", /* name */
  396. FALSE, /* partial_inplace */
  397. 0, /* src_mask */
  398. 0xffff, /* dst_mask */
  399. FALSE), /* pcrel_offset */
  400. /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
  401. the symbol. */
  402. HOWTO (R_PPC_GOT16_HI, /* type */
  403. 16, /* rightshift */
  404. 1, /* size (0 = byte, 1 = short, 2 = long) */
  405. 16, /* bitsize */
  406. FALSE, /* pc_relative */
  407. 0, /* bitpos */
  408. complain_overflow_dont, /* complain_on_overflow */
  409. bfd_elf_generic_reloc, /* special_function */
  410. "R_PPC_GOT16_HI", /* name */
  411. FALSE, /* partial_inplace */
  412. 0, /* src_mask */
  413. 0xffff, /* dst_mask */
  414. FALSE), /* pcrel_offset */
  415. /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
  416. the symbol. */
  417. HOWTO (R_PPC_GOT16_HA, /* type */
  418. 16, /* rightshift */
  419. 1, /* size (0 = byte, 1 = short, 2 = long) */
  420. 16, /* bitsize */
  421. FALSE, /* pc_relative */
  422. 0, /* bitpos */
  423. complain_overflow_dont, /* complain_on_overflow */
  424. ppc_elf_addr16_ha_reloc, /* special_function */
  425. "R_PPC_GOT16_HA", /* name */
  426. FALSE, /* partial_inplace */
  427. 0, /* src_mask */
  428. 0xffff, /* dst_mask */
  429. FALSE), /* pcrel_offset */
  430. /* Like R_PPC_REL24, but referring to the procedure linkage table
  431. entry for the symbol. */
  432. HOWTO (R_PPC_PLTREL24, /* type */
  433. 0, /* rightshift */
  434. 2, /* size (0 = byte, 1 = short, 2 = long) */
  435. 26, /* bitsize */
  436. TRUE, /* pc_relative */
  437. 0, /* bitpos */
  438. complain_overflow_signed, /* complain_on_overflow */
  439. bfd_elf_generic_reloc, /* special_function */
  440. "R_PPC_PLTREL24", /* name */
  441. FALSE, /* partial_inplace */
  442. 0, /* src_mask */
  443. 0x3fffffc, /* dst_mask */
  444. TRUE), /* pcrel_offset */
  445. /* This is used only by the dynamic linker. The symbol should exist
  446. both in the object being run and in some shared library. The
  447. dynamic linker copies the data addressed by the symbol from the
  448. shared library into the object, because the object being
  449. run has to have the data at some particular address. */
  450. HOWTO (R_PPC_COPY, /* type */
  451. 0, /* rightshift */
  452. 2, /* size (0 = byte, 1 = short, 2 = long) */
  453. 32, /* bitsize */
  454. FALSE, /* pc_relative */
  455. 0, /* bitpos */
  456. complain_overflow_dont, /* complain_on_overflow */
  457. bfd_elf_generic_reloc, /* special_function */
  458. "R_PPC_COPY", /* name */
  459. FALSE, /* partial_inplace */
  460. 0, /* src_mask */
  461. 0, /* dst_mask */
  462. FALSE), /* pcrel_offset */
  463. /* Like R_PPC_ADDR32, but used when setting global offset table
  464. entries. */
  465. HOWTO (R_PPC_GLOB_DAT, /* type */
  466. 0, /* rightshift */
  467. 2, /* size (0 = byte, 1 = short, 2 = long) */
  468. 32, /* bitsize */
  469. FALSE, /* pc_relative */
  470. 0, /* bitpos */
  471. complain_overflow_dont, /* complain_on_overflow */
  472. bfd_elf_generic_reloc, /* special_function */
  473. "R_PPC_GLOB_DAT", /* name */
  474. FALSE, /* partial_inplace */
  475. 0, /* src_mask */
  476. 0xffffffff, /* dst_mask */
  477. FALSE), /* pcrel_offset */
  478. /* Marks a procedure linkage table entry for a symbol. */
  479. HOWTO (R_PPC_JMP_SLOT, /* type */
  480. 0, /* rightshift */
  481. 2, /* size (0 = byte, 1 = short, 2 = long) */
  482. 32, /* bitsize */
  483. FALSE, /* pc_relative */
  484. 0, /* bitpos */
  485. complain_overflow_dont, /* complain_on_overflow */
  486. bfd_elf_generic_reloc, /* special_function */
  487. "R_PPC_JMP_SLOT", /* name */
  488. FALSE, /* partial_inplace */
  489. 0, /* src_mask */
  490. 0, /* dst_mask */
  491. FALSE), /* pcrel_offset */
  492. /* Used only by the dynamic linker. When the object is run, this
  493. longword is set to the load address of the object, plus the
  494. addend. */
  495. HOWTO (R_PPC_RELATIVE, /* type */
  496. 0, /* rightshift */
  497. 2, /* size (0 = byte, 1 = short, 2 = long) */
  498. 32, /* bitsize */
  499. FALSE, /* pc_relative */
  500. 0, /* bitpos */
  501. complain_overflow_dont, /* complain_on_overflow */
  502. bfd_elf_generic_reloc, /* special_function */
  503. "R_PPC_RELATIVE", /* name */
  504. FALSE, /* partial_inplace */
  505. 0, /* src_mask */
  506. 0xffffffff, /* dst_mask */
  507. FALSE), /* pcrel_offset */
  508. /* Like R_PPC_REL24, but uses the value of the symbol within the
  509. object rather than the final value. Normally used for
  510. _GLOBAL_OFFSET_TABLE_. */
  511. HOWTO (R_PPC_LOCAL24PC, /* type */
  512. 0, /* rightshift */
  513. 2, /* size (0 = byte, 1 = short, 2 = long) */
  514. 26, /* bitsize */
  515. TRUE, /* pc_relative */
  516. 0, /* bitpos */
  517. complain_overflow_signed, /* complain_on_overflow */
  518. bfd_elf_generic_reloc, /* special_function */
  519. "R_PPC_LOCAL24PC", /* name */
  520. FALSE, /* partial_inplace */
  521. 0, /* src_mask */
  522. 0x3fffffc, /* dst_mask */
  523. TRUE), /* pcrel_offset */
  524. /* Like R_PPC_ADDR32, but may be unaligned. */
  525. HOWTO (R_PPC_UADDR32, /* type */
  526. 0, /* rightshift */
  527. 2, /* size (0 = byte, 1 = short, 2 = long) */
  528. 32, /* bitsize */
  529. FALSE, /* pc_relative */
  530. 0, /* bitpos */
  531. complain_overflow_dont, /* complain_on_overflow */
  532. bfd_elf_generic_reloc, /* special_function */
  533. "R_PPC_UADDR32", /* name */
  534. FALSE, /* partial_inplace */
  535. 0, /* src_mask */
  536. 0xffffffff, /* dst_mask */
  537. FALSE), /* pcrel_offset */
  538. /* Like R_PPC_ADDR16, but may be unaligned. */
  539. HOWTO (R_PPC_UADDR16, /* type */
  540. 0, /* rightshift */
  541. 1, /* size (0 = byte, 1 = short, 2 = long) */
  542. 16, /* bitsize */
  543. FALSE, /* pc_relative */
  544. 0, /* bitpos */
  545. complain_overflow_bitfield, /* complain_on_overflow */
  546. bfd_elf_generic_reloc, /* special_function */
  547. "R_PPC_UADDR16", /* name */
  548. FALSE, /* partial_inplace */
  549. 0, /* src_mask */
  550. 0xffff, /* dst_mask */
  551. FALSE), /* pcrel_offset */
  552. /* 32-bit PC relative */
  553. HOWTO (R_PPC_REL32, /* type */
  554. 0, /* rightshift */
  555. 2, /* size (0 = byte, 1 = short, 2 = long) */
  556. 32, /* bitsize */
  557. TRUE, /* pc_relative */
  558. 0, /* bitpos */
  559. complain_overflow_dont, /* complain_on_overflow */
  560. bfd_elf_generic_reloc, /* special_function */
  561. "R_PPC_REL32", /* name */
  562. FALSE, /* partial_inplace */
  563. 0, /* src_mask */
  564. 0xffffffff, /* dst_mask */
  565. TRUE), /* pcrel_offset */
  566. /* 32-bit relocation to the symbol's procedure linkage table.
  567. FIXME: not supported. */
  568. HOWTO (R_PPC_PLT32, /* type */
  569. 0, /* rightshift */
  570. 2, /* size (0 = byte, 1 = short, 2 = long) */
  571. 32, /* bitsize */
  572. FALSE, /* pc_relative */
  573. 0, /* bitpos */
  574. complain_overflow_dont, /* complain_on_overflow */
  575. bfd_elf_generic_reloc, /* special_function */
  576. "R_PPC_PLT32", /* name */
  577. FALSE, /* partial_inplace */
  578. 0, /* src_mask */
  579. 0, /* dst_mask */
  580. FALSE), /* pcrel_offset */
  581. /* 32-bit PC relative relocation to the symbol's procedure linkage table.
  582. FIXME: not supported. */
  583. HOWTO (R_PPC_PLTREL32, /* type */
  584. 0, /* rightshift */
  585. 2, /* size (0 = byte, 1 = short, 2 = long) */
  586. 32, /* bitsize */
  587. TRUE, /* pc_relative */
  588. 0, /* bitpos */
  589. complain_overflow_dont, /* complain_on_overflow */
  590. bfd_elf_generic_reloc, /* special_function */
  591. "R_PPC_PLTREL32", /* name */
  592. FALSE, /* partial_inplace */
  593. 0, /* src_mask */
  594. 0, /* dst_mask */
  595. TRUE), /* pcrel_offset */
  596. /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
  597. the symbol. */
  598. HOWTO (R_PPC_PLT16_LO, /* type */
  599. 0, /* rightshift */
  600. 1, /* size (0 = byte, 1 = short, 2 = long) */
  601. 16, /* bitsize */
  602. FALSE, /* pc_relative */
  603. 0, /* bitpos */
  604. complain_overflow_dont, /* complain_on_overflow */
  605. bfd_elf_generic_reloc, /* special_function */
  606. "R_PPC_PLT16_LO", /* name */
  607. FALSE, /* partial_inplace */
  608. 0, /* src_mask */
  609. 0xffff, /* dst_mask */
  610. FALSE), /* pcrel_offset */
  611. /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
  612. the symbol. */
  613. HOWTO (R_PPC_PLT16_HI, /* type */
  614. 16, /* rightshift */
  615. 1, /* size (0 = byte, 1 = short, 2 = long) */
  616. 16, /* bitsize */
  617. FALSE, /* pc_relative */
  618. 0, /* bitpos */
  619. complain_overflow_dont, /* complain_on_overflow */
  620. bfd_elf_generic_reloc, /* special_function */
  621. "R_PPC_PLT16_HI", /* name */
  622. FALSE, /* partial_inplace */
  623. 0, /* src_mask */
  624. 0xffff, /* dst_mask */
  625. FALSE), /* pcrel_offset */
  626. /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
  627. the symbol. */
  628. HOWTO (R_PPC_PLT16_HA, /* type */
  629. 16, /* rightshift */
  630. 1, /* size (0 = byte, 1 = short, 2 = long) */
  631. 16, /* bitsize */
  632. FALSE, /* pc_relative */
  633. 0, /* bitpos */
  634. complain_overflow_dont, /* complain_on_overflow */
  635. ppc_elf_addr16_ha_reloc, /* special_function */
  636. "R_PPC_PLT16_HA", /* name */
  637. FALSE, /* partial_inplace */
  638. 0, /* src_mask */
  639. 0xffff, /* dst_mask */
  640. FALSE), /* pcrel_offset */
  641. /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
  642. small data items. */
  643. HOWTO (R_PPC_SDAREL16, /* type */
  644. 0, /* rightshift */
  645. 1, /* size (0 = byte, 1 = short, 2 = long) */
  646. 16, /* bitsize */
  647. FALSE, /* pc_relative */
  648. 0, /* bitpos */
  649. complain_overflow_signed, /* complain_on_overflow */
  650. bfd_elf_generic_reloc, /* special_function */
  651. "R_PPC_SDAREL16", /* name */
  652. FALSE, /* partial_inplace */
  653. 0, /* src_mask */
  654. 0xffff, /* dst_mask */
  655. FALSE), /* pcrel_offset */
  656. /* 16-bit section relative relocation. */
  657. HOWTO (R_PPC_SECTOFF, /* type */
  658. 0, /* rightshift */
  659. 1, /* size (0 = byte, 1 = short, 2 = long) */
  660. 16, /* bitsize */
  661. FALSE, /* pc_relative */
  662. 0, /* bitpos */
  663. complain_overflow_signed, /* complain_on_overflow */
  664. bfd_elf_generic_reloc, /* special_function */
  665. "R_PPC_SECTOFF", /* name */
  666. FALSE, /* partial_inplace */
  667. 0, /* src_mask */
  668. 0xffff, /* dst_mask */
  669. FALSE), /* pcrel_offset */
  670. /* 16-bit lower half section relative relocation. */
  671. HOWTO (R_PPC_SECTOFF_LO, /* type */
  672. 0, /* rightshift */
  673. 1, /* size (0 = byte, 1 = short, 2 = long) */
  674. 16, /* bitsize */
  675. FALSE, /* pc_relative */
  676. 0, /* bitpos */
  677. complain_overflow_dont, /* complain_on_overflow */
  678. bfd_elf_generic_reloc, /* special_function */
  679. "R_PPC_SECTOFF_LO", /* name */
  680. FALSE, /* partial_inplace */
  681. 0, /* src_mask */
  682. 0xffff, /* dst_mask */
  683. FALSE), /* pcrel_offset */
  684. /* 16-bit upper half section relative relocation. */
  685. HOWTO (R_PPC_SECTOFF_HI, /* type */
  686. 16, /* rightshift */
  687. 1, /* size (0 = byte, 1 = short, 2 = long) */
  688. 16, /* bitsize */
  689. FALSE, /* pc_relative */
  690. 0, /* bitpos */
  691. complain_overflow_dont, /* complain_on_overflow */
  692. bfd_elf_generic_reloc, /* special_function */
  693. "R_PPC_SECTOFF_HI", /* name */
  694. FALSE, /* partial_inplace */
  695. 0, /* src_mask */
  696. 0xffff, /* dst_mask */
  697. FALSE), /* pcrel_offset */
  698. /* 16-bit upper half adjusted section relative relocation. */
  699. HOWTO (R_PPC_SECTOFF_HA, /* type */
  700. 16, /* rightshift */
  701. 1, /* size (0 = byte, 1 = short, 2 = long) */
  702. 16, /* bitsize */
  703. FALSE, /* pc_relative */
  704. 0, /* bitpos */
  705. complain_overflow_dont, /* complain_on_overflow */
  706. ppc_elf_addr16_ha_reloc, /* special_function */
  707. "R_PPC_SECTOFF_HA", /* name */
  708. FALSE, /* partial_inplace */
  709. 0, /* src_mask */
  710. 0xffff, /* dst_mask */
  711. FALSE), /* pcrel_offset */
  712. /* Marker relocs for TLS. */
  713. HOWTO (R_PPC_TLS,
  714. 0, /* rightshift */
  715. 2, /* size (0 = byte, 1 = short, 2 = long) */
  716. 32, /* bitsize */
  717. FALSE, /* pc_relative */
  718. 0, /* bitpos */
  719. complain_overflow_dont, /* complain_on_overflow */
  720. bfd_elf_generic_reloc, /* special_function */
  721. "R_PPC_TLS", /* name */
  722. FALSE, /* partial_inplace */
  723. 0, /* src_mask */
  724. 0, /* dst_mask */
  725. FALSE), /* pcrel_offset */
  726. HOWTO (R_PPC_TLSGD,
  727. 0, /* rightshift */
  728. 2, /* size (0 = byte, 1 = short, 2 = long) */
  729. 32, /* bitsize */
  730. FALSE, /* pc_relative */
  731. 0, /* bitpos */
  732. complain_overflow_dont, /* complain_on_overflow */
  733. bfd_elf_generic_reloc, /* special_function */
  734. "R_PPC_TLSGD", /* name */
  735. FALSE, /* partial_inplace */
  736. 0, /* src_mask */
  737. 0, /* dst_mask */
  738. FALSE), /* pcrel_offset */
  739. HOWTO (R_PPC_TLSLD,
  740. 0, /* rightshift */
  741. 2, /* size (0 = byte, 1 = short, 2 = long) */
  742. 32, /* bitsize */
  743. FALSE, /* pc_relative */
  744. 0, /* bitpos */
  745. complain_overflow_dont, /* complain_on_overflow */
  746. bfd_elf_generic_reloc, /* special_function */
  747. "R_PPC_TLSLD", /* name */
  748. FALSE, /* partial_inplace */
  749. 0, /* src_mask */
  750. 0, /* dst_mask */
  751. FALSE), /* pcrel_offset */
  752. /* Computes the load module index of the load module that contains the
  753. definition of its TLS sym. */
  754. HOWTO (R_PPC_DTPMOD32,
  755. 0, /* rightshift */
  756. 2, /* size (0 = byte, 1 = short, 2 = long) */
  757. 32, /* bitsize */
  758. FALSE, /* pc_relative */
  759. 0, /* bitpos */
  760. complain_overflow_dont, /* complain_on_overflow */
  761. ppc_elf_unhandled_reloc, /* special_function */
  762. "R_PPC_DTPMOD32", /* name */
  763. FALSE, /* partial_inplace */
  764. 0, /* src_mask */
  765. 0xffffffff, /* dst_mask */
  766. FALSE), /* pcrel_offset */
  767. /* Computes a dtv-relative displacement, the difference between the value
  768. of sym+add and the base address of the thread-local storage block that
  769. contains the definition of sym, minus 0x8000. */
  770. HOWTO (R_PPC_DTPREL32,
  771. 0, /* rightshift */
  772. 2, /* size (0 = byte, 1 = short, 2 = long) */
  773. 32, /* bitsize */
  774. FALSE, /* pc_relative */
  775. 0, /* bitpos */
  776. complain_overflow_dont, /* complain_on_overflow */
  777. ppc_elf_unhandled_reloc, /* special_function */
  778. "R_PPC_DTPREL32", /* name */
  779. FALSE, /* partial_inplace */
  780. 0, /* src_mask */
  781. 0xffffffff, /* dst_mask */
  782. FALSE), /* pcrel_offset */
  783. /* A 16 bit dtprel reloc. */
  784. HOWTO (R_PPC_DTPREL16,
  785. 0, /* rightshift */
  786. 1, /* size (0 = byte, 1 = short, 2 = long) */
  787. 16, /* bitsize */
  788. FALSE, /* pc_relative */
  789. 0, /* bitpos */
  790. complain_overflow_signed, /* complain_on_overflow */
  791. ppc_elf_unhandled_reloc, /* special_function */
  792. "R_PPC_DTPREL16", /* name */
  793. FALSE, /* partial_inplace */
  794. 0, /* src_mask */
  795. 0xffff, /* dst_mask */
  796. FALSE), /* pcrel_offset */
  797. /* Like DTPREL16, but no overflow. */
  798. HOWTO (R_PPC_DTPREL16_LO,
  799. 0, /* rightshift */
  800. 1, /* size (0 = byte, 1 = short, 2 = long) */
  801. 16, /* bitsize */
  802. FALSE, /* pc_relative */
  803. 0, /* bitpos */
  804. complain_overflow_dont, /* complain_on_overflow */
  805. ppc_elf_unhandled_reloc, /* special_function */
  806. "R_PPC_DTPREL16_LO", /* name */
  807. FALSE, /* partial_inplace */
  808. 0, /* src_mask */
  809. 0xffff, /* dst_mask */
  810. FALSE), /* pcrel_offset */
  811. /* Like DTPREL16_LO, but next higher group of 16 bits. */
  812. HOWTO (R_PPC_DTPREL16_HI,
  813. 16, /* rightshift */
  814. 1, /* size (0 = byte, 1 = short, 2 = long) */
  815. 16, /* bitsize */
  816. FALSE, /* pc_relative */
  817. 0, /* bitpos */
  818. complain_overflow_dont, /* complain_on_overflow */
  819. ppc_elf_unhandled_reloc, /* special_function */
  820. "R_PPC_DTPREL16_HI", /* name */
  821. FALSE, /* partial_inplace */
  822. 0, /* src_mask */
  823. 0xffff, /* dst_mask */
  824. FALSE), /* pcrel_offset */
  825. /* Like DTPREL16_HI, but adjust for low 16 bits. */
  826. HOWTO (R_PPC_DTPREL16_HA,
  827. 16, /* rightshift */
  828. 1, /* size (0 = byte, 1 = short, 2 = long) */
  829. 16, /* bitsize */
  830. FALSE, /* pc_relative */
  831. 0, /* bitpos */
  832. complain_overflow_dont, /* complain_on_overflow */
  833. ppc_elf_unhandled_reloc, /* special_function */
  834. "R_PPC_DTPREL16_HA", /* name */
  835. FALSE, /* partial_inplace */
  836. 0, /* src_mask */
  837. 0xffff, /* dst_mask */
  838. FALSE), /* pcrel_offset */
  839. /* Computes a tp-relative displacement, the difference between the value of
  840. sym+add and the value of the thread pointer (r13). */
  841. HOWTO (R_PPC_TPREL32,
  842. 0, /* rightshift */
  843. 2, /* size (0 = byte, 1 = short, 2 = long) */
  844. 32, /* bitsize */
  845. FALSE, /* pc_relative */
  846. 0, /* bitpos */
  847. complain_overflow_dont, /* complain_on_overflow */
  848. ppc_elf_unhandled_reloc, /* special_function */
  849. "R_PPC_TPREL32", /* name */
  850. FALSE, /* partial_inplace */
  851. 0, /* src_mask */
  852. 0xffffffff, /* dst_mask */
  853. FALSE), /* pcrel_offset */
  854. /* A 16 bit tprel reloc. */
  855. HOWTO (R_PPC_TPREL16,
  856. 0, /* rightshift */
  857. 1, /* size (0 = byte, 1 = short, 2 = long) */
  858. 16, /* bitsize */
  859. FALSE, /* pc_relative */
  860. 0, /* bitpos */
  861. complain_overflow_signed, /* complain_on_overflow */
  862. ppc_elf_unhandled_reloc, /* special_function */
  863. "R_PPC_TPREL16", /* name */
  864. FALSE, /* partial_inplace */
  865. 0, /* src_mask */
  866. 0xffff, /* dst_mask */
  867. FALSE), /* pcrel_offset */
  868. /* Like TPREL16, but no overflow. */
  869. HOWTO (R_PPC_TPREL16_LO,
  870. 0, /* rightshift */
  871. 1, /* size (0 = byte, 1 = short, 2 = long) */
  872. 16, /* bitsize */
  873. FALSE, /* pc_relative */
  874. 0, /* bitpos */
  875. complain_overflow_dont, /* complain_on_overflow */
  876. ppc_elf_unhandled_reloc, /* special_function */
  877. "R_PPC_TPREL16_LO", /* name */
  878. FALSE, /* partial_inplace */
  879. 0, /* src_mask */
  880. 0xffff, /* dst_mask */
  881. FALSE), /* pcrel_offset */
  882. /* Like TPREL16_LO, but next higher group of 16 bits. */
  883. HOWTO (R_PPC_TPREL16_HI,
  884. 16, /* rightshift */
  885. 1, /* size (0 = byte, 1 = short, 2 = long) */
  886. 16, /* bitsize */
  887. FALSE, /* pc_relative */
  888. 0, /* bitpos */
  889. complain_overflow_dont, /* complain_on_overflow */
  890. ppc_elf_unhandled_reloc, /* special_function */
  891. "R_PPC_TPREL16_HI", /* name */
  892. FALSE, /* partial_inplace */
  893. 0, /* src_mask */
  894. 0xffff, /* dst_mask */
  895. FALSE), /* pcrel_offset */
  896. /* Like TPREL16_HI, but adjust for low 16 bits. */
  897. HOWTO (R_PPC_TPREL16_HA,
  898. 16, /* rightshift */
  899. 1, /* size (0 = byte, 1 = short, 2 = long) */
  900. 16, /* bitsize */
  901. FALSE, /* pc_relative */
  902. 0, /* bitpos */
  903. complain_overflow_dont, /* complain_on_overflow */
  904. ppc_elf_unhandled_reloc, /* special_function */
  905. "R_PPC_TPREL16_HA", /* name */
  906. FALSE, /* partial_inplace */
  907. 0, /* src_mask */
  908. 0xffff, /* dst_mask */
  909. FALSE), /* pcrel_offset */
  910. /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
  911. with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
  912. to the first entry. */
  913. HOWTO (R_PPC_GOT_TLSGD16,
  914. 0, /* rightshift */
  915. 1, /* size (0 = byte, 1 = short, 2 = long) */
  916. 16, /* bitsize */
  917. FALSE, /* pc_relative */
  918. 0, /* bitpos */
  919. complain_overflow_signed, /* complain_on_overflow */
  920. ppc_elf_unhandled_reloc, /* special_function */
  921. "R_PPC_GOT_TLSGD16", /* name */
  922. FALSE, /* partial_inplace */
  923. 0, /* src_mask */
  924. 0xffff, /* dst_mask */
  925. FALSE), /* pcrel_offset */
  926. /* Like GOT_TLSGD16, but no overflow. */
  927. HOWTO (R_PPC_GOT_TLSGD16_LO,
  928. 0, /* rightshift */
  929. 1, /* size (0 = byte, 1 = short, 2 = long) */
  930. 16, /* bitsize */
  931. FALSE, /* pc_relative */
  932. 0, /* bitpos */
  933. complain_overflow_dont, /* complain_on_overflow */
  934. ppc_elf_unhandled_reloc, /* special_function */
  935. "R_PPC_GOT_TLSGD16_LO", /* name */
  936. FALSE, /* partial_inplace */
  937. 0, /* src_mask */
  938. 0xffff, /* dst_mask */
  939. FALSE), /* pcrel_offset */
  940. /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
  941. HOWTO (R_PPC_GOT_TLSGD16_HI,
  942. 16, /* rightshift */
  943. 1, /* size (0 = byte, 1 = short, 2 = long) */
  944. 16, /* bitsize */
  945. FALSE, /* pc_relative */
  946. 0, /* bitpos */
  947. complain_overflow_dont, /* complain_on_overflow */
  948. ppc_elf_unhandled_reloc, /* special_function */
  949. "R_PPC_GOT_TLSGD16_HI", /* name */
  950. FALSE, /* partial_inplace */
  951. 0, /* src_mask */
  952. 0xffff, /* dst_mask */
  953. FALSE), /* pcrel_offset */
  954. /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
  955. HOWTO (R_PPC_GOT_TLSGD16_HA,
  956. 16, /* rightshift */
  957. 1, /* size (0 = byte, 1 = short, 2 = long) */
  958. 16, /* bitsize */
  959. FALSE, /* pc_relative */
  960. 0, /* bitpos */
  961. complain_overflow_dont, /* complain_on_overflow */
  962. ppc_elf_unhandled_reloc, /* special_function */
  963. "R_PPC_GOT_TLSGD16_HA", /* name */
  964. FALSE, /* partial_inplace */
  965. 0, /* src_mask */
  966. 0xffff, /* dst_mask */
  967. FALSE), /* pcrel_offset */
  968. /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
  969. with values (sym+add)@dtpmod and zero, and computes the offset to the
  970. first entry. */
  971. HOWTO (R_PPC_GOT_TLSLD16,
  972. 0, /* rightshift */
  973. 1, /* size (0 = byte, 1 = short, 2 = long) */
  974. 16, /* bitsize */
  975. FALSE, /* pc_relative */
  976. 0, /* bitpos */
  977. complain_overflow_signed, /* complain_on_overflow */
  978. ppc_elf_unhandled_reloc, /* special_function */
  979. "R_PPC_GOT_TLSLD16", /* name */
  980. FALSE, /* partial_inplace */
  981. 0, /* src_mask */
  982. 0xffff, /* dst_mask */
  983. FALSE), /* pcrel_offset */
  984. /* Like GOT_TLSLD16, but no overflow. */
  985. HOWTO (R_PPC_GOT_TLSLD16_LO,
  986. 0, /* rightshift */
  987. 1, /* size (0 = byte, 1 = short, 2 = long) */
  988. 16, /* bitsize */
  989. FALSE, /* pc_relative */
  990. 0, /* bitpos */
  991. complain_overflow_dont, /* complain_on_overflow */
  992. ppc_elf_unhandled_reloc, /* special_function */
  993. "R_PPC_GOT_TLSLD16_LO", /* name */
  994. FALSE, /* partial_inplace */
  995. 0, /* src_mask */
  996. 0xffff, /* dst_mask */
  997. FALSE), /* pcrel_offset */
  998. /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
  999. HOWTO (R_PPC_GOT_TLSLD16_HI,
  1000. 16, /* rightshift */
  1001. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1002. 16, /* bitsize */
  1003. FALSE, /* pc_relative */
  1004. 0, /* bitpos */
  1005. complain_overflow_dont, /* complain_on_overflow */
  1006. ppc_elf_unhandled_reloc, /* special_function */
  1007. "R_PPC_GOT_TLSLD16_HI", /* name */
  1008. FALSE, /* partial_inplace */
  1009. 0, /* src_mask */
  1010. 0xffff, /* dst_mask */
  1011. FALSE), /* pcrel_offset */
  1012. /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
  1013. HOWTO (R_PPC_GOT_TLSLD16_HA,
  1014. 16, /* rightshift */
  1015. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1016. 16, /* bitsize */
  1017. FALSE, /* pc_relative */
  1018. 0, /* bitpos */
  1019. complain_overflow_dont, /* complain_on_overflow */
  1020. ppc_elf_unhandled_reloc, /* special_function */
  1021. "R_PPC_GOT_TLSLD16_HA", /* name */
  1022. FALSE, /* partial_inplace */
  1023. 0, /* src_mask */
  1024. 0xffff, /* dst_mask */
  1025. FALSE), /* pcrel_offset */
  1026. /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
  1027. the offset to the entry. */
  1028. HOWTO (R_PPC_GOT_DTPREL16,
  1029. 0, /* rightshift */
  1030. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1031. 16, /* bitsize */
  1032. FALSE, /* pc_relative */
  1033. 0, /* bitpos */
  1034. complain_overflow_signed, /* complain_on_overflow */
  1035. ppc_elf_unhandled_reloc, /* special_function */
  1036. "R_PPC_GOT_DTPREL16", /* name */
  1037. FALSE, /* partial_inplace */
  1038. 0, /* src_mask */
  1039. 0xffff, /* dst_mask */
  1040. FALSE), /* pcrel_offset */
  1041. /* Like GOT_DTPREL16, but no overflow. */
  1042. HOWTO (R_PPC_GOT_DTPREL16_LO,
  1043. 0, /* rightshift */
  1044. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1045. 16, /* bitsize */
  1046. FALSE, /* pc_relative */
  1047. 0, /* bitpos */
  1048. complain_overflow_dont, /* complain_on_overflow */
  1049. ppc_elf_unhandled_reloc, /* special_function */
  1050. "R_PPC_GOT_DTPREL16_LO", /* name */
  1051. FALSE, /* partial_inplace */
  1052. 0, /* src_mask */
  1053. 0xffff, /* dst_mask */
  1054. FALSE), /* pcrel_offset */
  1055. /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
  1056. HOWTO (R_PPC_GOT_DTPREL16_HI,
  1057. 16, /* rightshift */
  1058. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1059. 16, /* bitsize */
  1060. FALSE, /* pc_relative */
  1061. 0, /* bitpos */
  1062. complain_overflow_dont, /* complain_on_overflow */
  1063. ppc_elf_unhandled_reloc, /* special_function */
  1064. "R_PPC_GOT_DTPREL16_HI", /* name */
  1065. FALSE, /* partial_inplace */
  1066. 0, /* src_mask */
  1067. 0xffff, /* dst_mask */
  1068. FALSE), /* pcrel_offset */
  1069. /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
  1070. HOWTO (R_PPC_GOT_DTPREL16_HA,
  1071. 16, /* rightshift */
  1072. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1073. 16, /* bitsize */
  1074. FALSE, /* pc_relative */
  1075. 0, /* bitpos */
  1076. complain_overflow_dont, /* complain_on_overflow */
  1077. ppc_elf_unhandled_reloc, /* special_function */
  1078. "R_PPC_GOT_DTPREL16_HA", /* name */
  1079. FALSE, /* partial_inplace */
  1080. 0, /* src_mask */
  1081. 0xffff, /* dst_mask */
  1082. FALSE), /* pcrel_offset */
  1083. /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
  1084. offset to the entry. */
  1085. HOWTO (R_PPC_GOT_TPREL16,
  1086. 0, /* rightshift */
  1087. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1088. 16, /* bitsize */
  1089. FALSE, /* pc_relative */
  1090. 0, /* bitpos */
  1091. complain_overflow_signed, /* complain_on_overflow */
  1092. ppc_elf_unhandled_reloc, /* special_function */
  1093. "R_PPC_GOT_TPREL16", /* name */
  1094. FALSE, /* partial_inplace */
  1095. 0, /* src_mask */
  1096. 0xffff, /* dst_mask */
  1097. FALSE), /* pcrel_offset */
  1098. /* Like GOT_TPREL16, but no overflow. */
  1099. HOWTO (R_PPC_GOT_TPREL16_LO,
  1100. 0, /* rightshift */
  1101. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1102. 16, /* bitsize */
  1103. FALSE, /* pc_relative */
  1104. 0, /* bitpos */
  1105. complain_overflow_dont, /* complain_on_overflow */
  1106. ppc_elf_unhandled_reloc, /* special_function */
  1107. "R_PPC_GOT_TPREL16_LO", /* name */
  1108. FALSE, /* partial_inplace */
  1109. 0, /* src_mask */
  1110. 0xffff, /* dst_mask */
  1111. FALSE), /* pcrel_offset */
  1112. /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
  1113. HOWTO (R_PPC_GOT_TPREL16_HI,
  1114. 16, /* rightshift */
  1115. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1116. 16, /* bitsize */
  1117. FALSE, /* pc_relative */
  1118. 0, /* bitpos */
  1119. complain_overflow_dont, /* complain_on_overflow */
  1120. ppc_elf_unhandled_reloc, /* special_function */
  1121. "R_PPC_GOT_TPREL16_HI", /* name */
  1122. FALSE, /* partial_inplace */
  1123. 0, /* src_mask */
  1124. 0xffff, /* dst_mask */
  1125. FALSE), /* pcrel_offset */
  1126. /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
  1127. HOWTO (R_PPC_GOT_TPREL16_HA,
  1128. 16, /* rightshift */
  1129. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1130. 16, /* bitsize */
  1131. FALSE, /* pc_relative */
  1132. 0, /* bitpos */
  1133. complain_overflow_dont, /* complain_on_overflow */
  1134. ppc_elf_unhandled_reloc, /* special_function */
  1135. "R_PPC_GOT_TPREL16_HA", /* name */
  1136. FALSE, /* partial_inplace */
  1137. 0, /* src_mask */
  1138. 0xffff, /* dst_mask */
  1139. FALSE), /* pcrel_offset */
  1140. /* The remaining relocs are from the Embedded ELF ABI, and are not
  1141. in the SVR4 ELF ABI. */
  1142. /* 32 bit value resulting from the addend minus the symbol. */
  1143. HOWTO (R_PPC_EMB_NADDR32, /* type */
  1144. 0, /* rightshift */
  1145. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1146. 32, /* bitsize */
  1147. FALSE, /* pc_relative */
  1148. 0, /* bitpos */
  1149. complain_overflow_dont, /* complain_on_overflow */
  1150. bfd_elf_generic_reloc, /* special_function */
  1151. "R_PPC_EMB_NADDR32", /* name */
  1152. FALSE, /* partial_inplace */
  1153. 0, /* src_mask */
  1154. 0xffffffff, /* dst_mask */
  1155. FALSE), /* pcrel_offset */
  1156. /* 16 bit value resulting from the addend minus the symbol. */
  1157. HOWTO (R_PPC_EMB_NADDR16, /* type */
  1158. 0, /* rightshift */
  1159. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1160. 16, /* bitsize */
  1161. FALSE, /* pc_relative */
  1162. 0, /* bitpos */
  1163. complain_overflow_signed, /* complain_on_overflow */
  1164. bfd_elf_generic_reloc, /* special_function */
  1165. "R_PPC_EMB_NADDR16", /* name */
  1166. FALSE, /* partial_inplace */
  1167. 0, /* src_mask */
  1168. 0xffff, /* dst_mask */
  1169. FALSE), /* pcrel_offset */
  1170. /* 16 bit value resulting from the addend minus the symbol. */
  1171. HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
  1172. 0, /* rightshift */
  1173. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1174. 16, /* bitsize */
  1175. FALSE, /* pc_relative */
  1176. 0, /* bitpos */
  1177. complain_overflow_dont,/* complain_on_overflow */
  1178. bfd_elf_generic_reloc, /* special_function */
  1179. "R_PPC_EMB_ADDR16_LO", /* name */
  1180. FALSE, /* partial_inplace */
  1181. 0, /* src_mask */
  1182. 0xffff, /* dst_mask */
  1183. FALSE), /* pcrel_offset */
  1184. /* The high order 16 bits of the addend minus the symbol. */
  1185. HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
  1186. 16, /* rightshift */
  1187. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1188. 16, /* bitsize */
  1189. FALSE, /* pc_relative */
  1190. 0, /* bitpos */
  1191. complain_overflow_dont, /* complain_on_overflow */
  1192. bfd_elf_generic_reloc, /* special_function */
  1193. "R_PPC_EMB_NADDR16_HI", /* name */
  1194. FALSE, /* partial_inplace */
  1195. 0, /* src_mask */
  1196. 0xffff, /* dst_mask */
  1197. FALSE), /* pcrel_offset */
  1198. /* The high order 16 bits of the result of the addend minus the address,
  1199. plus 1 if the contents of the low 16 bits, treated as a signed number,
  1200. is negative. */
  1201. HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
  1202. 16, /* rightshift */
  1203. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1204. 16, /* bitsize */
  1205. FALSE, /* pc_relative */
  1206. 0, /* bitpos */
  1207. complain_overflow_dont, /* complain_on_overflow */
  1208. ppc_elf_addr16_ha_reloc, /* special_function */
  1209. "R_PPC_EMB_NADDR16_HA", /* name */
  1210. FALSE, /* partial_inplace */
  1211. 0, /* src_mask */
  1212. 0xffff, /* dst_mask */
  1213. FALSE), /* pcrel_offset */
  1214. /* 16 bit value resulting from allocating a 4 byte word to hold an
  1215. address in the .sdata section, and returning the offset from
  1216. _SDA_BASE_ for that relocation. */
  1217. HOWTO (R_PPC_EMB_SDAI16, /* type */
  1218. 0, /* rightshift */
  1219. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1220. 16, /* bitsize */
  1221. FALSE, /* pc_relative */
  1222. 0, /* bitpos */
  1223. complain_overflow_signed, /* complain_on_overflow */
  1224. bfd_elf_generic_reloc, /* special_function */
  1225. "R_PPC_EMB_SDAI16", /* name */
  1226. FALSE, /* partial_inplace */
  1227. 0, /* src_mask */
  1228. 0xffff, /* dst_mask */
  1229. FALSE), /* pcrel_offset */
  1230. /* 16 bit value resulting from allocating a 4 byte word to hold an
  1231. address in the .sdata2 section, and returning the offset from
  1232. _SDA2_BASE_ for that relocation. */
  1233. HOWTO (R_PPC_EMB_SDA2I16, /* type */
  1234. 0, /* rightshift */
  1235. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1236. 16, /* bitsize */
  1237. FALSE, /* pc_relative */
  1238. 0, /* bitpos */
  1239. complain_overflow_signed, /* complain_on_overflow */
  1240. bfd_elf_generic_reloc, /* special_function */
  1241. "R_PPC_EMB_SDA2I16", /* name */
  1242. FALSE, /* partial_inplace */
  1243. 0, /* src_mask */
  1244. 0xffff, /* dst_mask */
  1245. FALSE), /* pcrel_offset */
  1246. /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
  1247. small data items. */
  1248. HOWTO (R_PPC_EMB_SDA2REL, /* type */
  1249. 0, /* rightshift */
  1250. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1251. 16, /* bitsize */
  1252. FALSE, /* pc_relative */
  1253. 0, /* bitpos */
  1254. complain_overflow_signed, /* complain_on_overflow */
  1255. bfd_elf_generic_reloc, /* special_function */
  1256. "R_PPC_EMB_SDA2REL", /* name */
  1257. FALSE, /* partial_inplace */
  1258. 0, /* src_mask */
  1259. 0xffff, /* dst_mask */
  1260. FALSE), /* pcrel_offset */
  1261. /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
  1262. signed offset from the appropriate base, and filling in the register
  1263. field with the appropriate register (0, 2, or 13). */
  1264. HOWTO (R_PPC_EMB_SDA21, /* type */
  1265. 0, /* rightshift */
  1266. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1267. 16, /* bitsize */
  1268. FALSE, /* pc_relative */
  1269. 0, /* bitpos */
  1270. complain_overflow_signed, /* complain_on_overflow */
  1271. bfd_elf_generic_reloc, /* special_function */
  1272. "R_PPC_EMB_SDA21", /* name */
  1273. FALSE, /* partial_inplace */
  1274. 0, /* src_mask */
  1275. 0xffff, /* dst_mask */
  1276. FALSE), /* pcrel_offset */
  1277. /* Relocation not handled: R_PPC_EMB_MRKREF */
  1278. /* Relocation not handled: R_PPC_EMB_RELSEC16 */
  1279. /* Relocation not handled: R_PPC_EMB_RELST_LO */
  1280. /* Relocation not handled: R_PPC_EMB_RELST_HI */
  1281. /* Relocation not handled: R_PPC_EMB_RELST_HA */
  1282. /* Relocation not handled: R_PPC_EMB_BIT_FLD */
  1283. /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
  1284. in the 16 bit signed offset from the appropriate base, and filling in the
  1285. register field with the appropriate register (0, 2, or 13). */
  1286. HOWTO (R_PPC_EMB_RELSDA, /* type */
  1287. 0, /* rightshift */
  1288. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1289. 16, /* bitsize */
  1290. FALSE, /* pc_relative */
  1291. 0, /* bitpos */
  1292. complain_overflow_signed, /* complain_on_overflow */
  1293. bfd_elf_generic_reloc, /* special_function */
  1294. "R_PPC_EMB_RELSDA", /* name */
  1295. FALSE, /* partial_inplace */
  1296. 0, /* src_mask */
  1297. 0xffff, /* dst_mask */
  1298. FALSE), /* pcrel_offset */
  1299. /* A relative 8 bit branch. */
  1300. HOWTO (R_PPC_VLE_REL8, /* type */
  1301. 1, /* rightshift */
  1302. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1303. 8, /* bitsize */
  1304. TRUE, /* pc_relative */
  1305. 0, /* bitpos */
  1306. complain_overflow_signed, /* complain_on_overflow */
  1307. bfd_elf_generic_reloc, /* special_function */
  1308. "R_PPC_VLE_REL8", /* name */
  1309. FALSE, /* partial_inplace */
  1310. 0, /* src_mask */
  1311. 0xff, /* dst_mask */
  1312. TRUE), /* pcrel_offset */
  1313. /* A relative 15 bit branch. */
  1314. HOWTO (R_PPC_VLE_REL15, /* type */
  1315. 1, /* rightshift */
  1316. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1317. 15, /* bitsize */
  1318. TRUE, /* pc_relative */
  1319. 1, /* bitpos */
  1320. complain_overflow_signed, /* complain_on_overflow */
  1321. bfd_elf_generic_reloc, /* special_function */
  1322. "R_PPC_VLE_REL15", /* name */
  1323. FALSE, /* partial_inplace */
  1324. 0, /* src_mask */
  1325. 0xfe, /* dst_mask */
  1326. TRUE), /* pcrel_offset */
  1327. /* A relative 24 bit branch. */
  1328. HOWTO (R_PPC_VLE_REL24, /* type */
  1329. 1, /* rightshift */
  1330. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1331. 24, /* bitsize */
  1332. TRUE, /* pc_relative */
  1333. 1, /* bitpos */
  1334. complain_overflow_signed, /* complain_on_overflow */
  1335. bfd_elf_generic_reloc, /* special_function */
  1336. "R_PPC_VLE_REL24", /* name */
  1337. FALSE, /* partial_inplace */
  1338. 0, /* src_mask */
  1339. 0x1fffffe, /* dst_mask */
  1340. TRUE), /* pcrel_offset */
  1341. /* The 16 LSBS in split16a format. */
  1342. HOWTO (R_PPC_VLE_LO16A, /* type */
  1343. 0, /* rightshift */
  1344. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1345. 16, /* bitsize */
  1346. FALSE, /* pc_relative */
  1347. 0, /* bitpos */
  1348. complain_overflow_dont, /* complain_on_overflow */
  1349. bfd_elf_generic_reloc, /* special_function */
  1350. "R_PPC_VLE_LO16A", /* name */
  1351. FALSE, /* partial_inplace */
  1352. 0, /* src_mask */
  1353. 0x1f007ff, /* dst_mask */
  1354. FALSE), /* pcrel_offset */
  1355. /* The 16 LSBS in split16d format. */
  1356. HOWTO (R_PPC_VLE_LO16D, /* type */
  1357. 0, /* rightshift */
  1358. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1359. 16, /* bitsize */
  1360. FALSE, /* pc_relative */
  1361. 0, /* bitpos */
  1362. complain_overflow_dont, /* complain_on_overflow */
  1363. bfd_elf_generic_reloc, /* special_function */
  1364. "R_PPC_VLE_LO16D", /* name */
  1365. FALSE, /* partial_inplace */
  1366. 0, /* src_mask */
  1367. 0x1f07ff, /* dst_mask */
  1368. FALSE), /* pcrel_offset */
  1369. /* Bits 16-31 split16a format. */
  1370. HOWTO (R_PPC_VLE_HI16A, /* type */
  1371. 16, /* rightshift */
  1372. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1373. 16, /* bitsize */
  1374. FALSE, /* pc_relative */
  1375. 0, /* bitpos */
  1376. complain_overflow_dont, /* complain_on_overflow */
  1377. bfd_elf_generic_reloc, /* special_function */
  1378. "R_PPC_VLE_HI16A", /* name */
  1379. FALSE, /* partial_inplace */
  1380. 0, /* src_mask */
  1381. 0x1f007ff, /* dst_mask */
  1382. FALSE), /* pcrel_offset */
  1383. /* Bits 16-31 split16d format. */
  1384. HOWTO (R_PPC_VLE_HI16D, /* type */
  1385. 16, /* rightshift */
  1386. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1387. 16, /* bitsize */
  1388. FALSE, /* pc_relative */
  1389. 0, /* bitpos */
  1390. complain_overflow_dont, /* complain_on_overflow */
  1391. bfd_elf_generic_reloc, /* special_function */
  1392. "R_PPC_VLE_HI16D", /* name */
  1393. FALSE, /* partial_inplace */
  1394. 0, /* src_mask */
  1395. 0x1f07ff, /* dst_mask */
  1396. FALSE), /* pcrel_offset */
  1397. /* Bits 16-31 (High Adjusted) in split16a format. */
  1398. HOWTO (R_PPC_VLE_HA16A, /* type */
  1399. 16, /* rightshift */
  1400. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1401. 16, /* bitsize */
  1402. FALSE, /* pc_relative */
  1403. 0, /* bitpos */
  1404. complain_overflow_dont, /* complain_on_overflow */
  1405. bfd_elf_generic_reloc, /* special_function */
  1406. "R_PPC_VLE_HA16A", /* name */
  1407. FALSE, /* partial_inplace */
  1408. 0, /* src_mask */
  1409. 0x1f007ff, /* dst_mask */
  1410. FALSE), /* pcrel_offset */
  1411. /* Bits 16-31 (High Adjusted) in split16d format. */
  1412. HOWTO (R_PPC_VLE_HA16D, /* type */
  1413. 16, /* rightshift */
  1414. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1415. 16, /* bitsize */
  1416. FALSE, /* pc_relative */
  1417. 0, /* bitpos */
  1418. complain_overflow_dont, /* complain_on_overflow */
  1419. bfd_elf_generic_reloc, /* special_function */
  1420. "R_PPC_VLE_HA16D", /* name */
  1421. FALSE, /* partial_inplace */
  1422. 0, /* src_mask */
  1423. 0x1f07ff, /* dst_mask */
  1424. FALSE), /* pcrel_offset */
  1425. /* This reloc is like R_PPC_EMB_SDA21 but only applies to e_add16i
  1426. instructions. If the register base is 0 then the linker changes
  1427. the e_add16i to an e_li instruction. */
  1428. HOWTO (R_PPC_VLE_SDA21, /* type */
  1429. 0, /* rightshift */
  1430. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1431. 16, /* bitsize */
  1432. FALSE, /* pc_relative */
  1433. 0, /* bitpos */
  1434. complain_overflow_signed, /* complain_on_overflow */
  1435. bfd_elf_generic_reloc, /* special_function */
  1436. "R_PPC_VLE_SDA21", /* name */
  1437. FALSE, /* partial_inplace */
  1438. 0, /* src_mask */
  1439. 0xffff, /* dst_mask */
  1440. FALSE), /* pcrel_offset */
  1441. /* Like R_PPC_VLE_SDA21 but ignore overflow. */
  1442. HOWTO (R_PPC_VLE_SDA21_LO, /* type */
  1443. 0, /* rightshift */
  1444. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1445. 16, /* bitsize */
  1446. FALSE, /* pc_relative */
  1447. 0, /* bitpos */
  1448. complain_overflow_dont, /* complain_on_overflow */
  1449. bfd_elf_generic_reloc, /* special_function */
  1450. "R_PPC_VLE_SDA21_LO", /* name */
  1451. FALSE, /* partial_inplace */
  1452. 0, /* src_mask */
  1453. 0xffff, /* dst_mask */
  1454. FALSE), /* pcrel_offset */
  1455. /* The 16 LSBS relative to _SDA_BASE_ in split16a format. */
  1456. HOWTO (R_PPC_VLE_SDAREL_LO16A,/* type */
  1457. 0, /* rightshift */
  1458. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1459. 16, /* bitsize */
  1460. FALSE, /* pc_relative */
  1461. 0, /* bitpos */
  1462. complain_overflow_dont, /* complain_on_overflow */
  1463. bfd_elf_generic_reloc, /* special_function */
  1464. "R_PPC_VLE_SDAREL_LO16A", /* name */
  1465. FALSE, /* partial_inplace */
  1466. 0, /* src_mask */
  1467. 0x1f007ff, /* dst_mask */
  1468. FALSE), /* pcrel_offset */
  1469. /* The 16 LSBS relative to _SDA_BASE_ in split16d format. */
  1470. HOWTO (R_PPC_VLE_SDAREL_LO16D, /* type */
  1471. 0, /* rightshift */
  1472. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1473. 16, /* bitsize */
  1474. FALSE, /* pc_relative */
  1475. 0, /* bitpos */
  1476. complain_overflow_dont, /* complain_on_overflow */
  1477. bfd_elf_generic_reloc, /* special_function */
  1478. "R_PPC_VLE_SDAREL_LO16D", /* name */
  1479. FALSE, /* partial_inplace */
  1480. 0, /* src_mask */
  1481. 0x1f07ff, /* dst_mask */
  1482. FALSE), /* pcrel_offset */
  1483. /* Bits 16-31 relative to _SDA_BASE_ in split16a format. */
  1484. HOWTO (R_PPC_VLE_SDAREL_HI16A, /* type */
  1485. 16, /* rightshift */
  1486. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1487. 16, /* bitsize */
  1488. FALSE, /* pc_relative */
  1489. 0, /* bitpos */
  1490. complain_overflow_dont, /* complain_on_overflow */
  1491. bfd_elf_generic_reloc, /* special_function */
  1492. "R_PPC_VLE_SDAREL_HI16A", /* name */
  1493. FALSE, /* partial_inplace */
  1494. 0, /* src_mask */
  1495. 0x1f007ff, /* dst_mask */
  1496. FALSE), /* pcrel_offset */
  1497. /* Bits 16-31 relative to _SDA_BASE_ in split16d format. */
  1498. HOWTO (R_PPC_VLE_SDAREL_HI16D, /* type */
  1499. 16, /* rightshift */
  1500. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1501. 16, /* bitsize */
  1502. FALSE, /* pc_relative */
  1503. 0, /* bitpos */
  1504. complain_overflow_dont, /* complain_on_overflow */
  1505. bfd_elf_generic_reloc, /* special_function */
  1506. "R_PPC_VLE_SDAREL_HI16D", /* name */
  1507. FALSE, /* partial_inplace */
  1508. 0, /* src_mask */
  1509. 0x1f07ff, /* dst_mask */
  1510. FALSE), /* pcrel_offset */
  1511. /* Bits 16-31 (HA) relative to _SDA_BASE split16a format. */
  1512. HOWTO (R_PPC_VLE_SDAREL_HA16A, /* type */
  1513. 16, /* rightshift */
  1514. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1515. 16, /* bitsize */
  1516. FALSE, /* pc_relative */
  1517. 0, /* bitpos */
  1518. complain_overflow_dont, /* complain_on_overflow */
  1519. bfd_elf_generic_reloc, /* special_function */
  1520. "R_PPC_VLE_SDAREL_HA16A", /* name */
  1521. FALSE, /* partial_inplace */
  1522. 0, /* src_mask */
  1523. 0x1f007ff, /* dst_mask */
  1524. FALSE), /* pcrel_offset */
  1525. /* Bits 16-31 (HA) relative to _SDA_BASE split16d format. */
  1526. HOWTO (R_PPC_VLE_SDAREL_HA16D, /* type */
  1527. 16, /* rightshift */
  1528. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1529. 16, /* bitsize */
  1530. FALSE, /* pc_relative */
  1531. 0, /* bitpos */
  1532. complain_overflow_dont, /* complain_on_overflow */
  1533. bfd_elf_generic_reloc, /* special_function */
  1534. "R_PPC_VLE_SDAREL_HA16D", /* name */
  1535. FALSE, /* partial_inplace */
  1536. 0, /* src_mask */
  1537. 0x1f07ff, /* dst_mask */
  1538. FALSE), /* pcrel_offset */
  1539. HOWTO (R_PPC_IRELATIVE, /* type */
  1540. 0, /* rightshift */
  1541. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1542. 32, /* bitsize */
  1543. FALSE, /* pc_relative */
  1544. 0, /* bitpos */
  1545. complain_overflow_dont, /* complain_on_overflow */
  1546. bfd_elf_generic_reloc, /* special_function */
  1547. "R_PPC_IRELATIVE", /* name */
  1548. FALSE, /* partial_inplace */
  1549. 0, /* src_mask */
  1550. 0xffffffff, /* dst_mask */
  1551. FALSE), /* pcrel_offset */
  1552. /* A 16 bit relative relocation. */
  1553. HOWTO (R_PPC_REL16, /* type */
  1554. 0, /* rightshift */
  1555. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1556. 16, /* bitsize */
  1557. TRUE, /* pc_relative */
  1558. 0, /* bitpos */
  1559. complain_overflow_signed, /* complain_on_overflow */
  1560. bfd_elf_generic_reloc, /* special_function */
  1561. "R_PPC_REL16", /* name */
  1562. FALSE, /* partial_inplace */
  1563. 0, /* src_mask */
  1564. 0xffff, /* dst_mask */
  1565. TRUE), /* pcrel_offset */
  1566. /* A 16 bit relative relocation without overflow. */
  1567. HOWTO (R_PPC_REL16_LO, /* type */
  1568. 0, /* rightshift */
  1569. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1570. 16, /* bitsize */
  1571. TRUE, /* pc_relative */
  1572. 0, /* bitpos */
  1573. complain_overflow_dont,/* complain_on_overflow */
  1574. bfd_elf_generic_reloc, /* special_function */
  1575. "R_PPC_REL16_LO", /* name */
  1576. FALSE, /* partial_inplace */
  1577. 0, /* src_mask */
  1578. 0xffff, /* dst_mask */
  1579. TRUE), /* pcrel_offset */
  1580. /* The high order 16 bits of a relative address. */
  1581. HOWTO (R_PPC_REL16_HI, /* type */
  1582. 16, /* rightshift */
  1583. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1584. 16, /* bitsize */
  1585. TRUE, /* pc_relative */
  1586. 0, /* bitpos */
  1587. complain_overflow_dont, /* complain_on_overflow */
  1588. bfd_elf_generic_reloc, /* special_function */
  1589. "R_PPC_REL16_HI", /* name */
  1590. FALSE, /* partial_inplace */
  1591. 0, /* src_mask */
  1592. 0xffff, /* dst_mask */
  1593. TRUE), /* pcrel_offset */
  1594. /* The high order 16 bits of a relative address, plus 1 if the contents of
  1595. the low 16 bits, treated as a signed number, is negative. */
  1596. HOWTO (R_PPC_REL16_HA, /* type */
  1597. 16, /* rightshift */
  1598. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1599. 16, /* bitsize */
  1600. TRUE, /* pc_relative */
  1601. 0, /* bitpos */
  1602. complain_overflow_dont, /* complain_on_overflow */
  1603. ppc_elf_addr16_ha_reloc, /* special_function */
  1604. "R_PPC_REL16_HA", /* name */
  1605. FALSE, /* partial_inplace */
  1606. 0, /* src_mask */
  1607. 0xffff, /* dst_mask */
  1608. TRUE), /* pcrel_offset */
  1609. /* GNU extension to record C++ vtable hierarchy. */
  1610. HOWTO (R_PPC_GNU_VTINHERIT, /* type */
  1611. 0, /* rightshift */
  1612. 0, /* size (0 = byte, 1 = short, 2 = long) */
  1613. 0, /* bitsize */
  1614. FALSE, /* pc_relative */
  1615. 0, /* bitpos */
  1616. complain_overflow_dont, /* complain_on_overflow */
  1617. NULL, /* special_function */
  1618. "R_PPC_GNU_VTINHERIT", /* name */
  1619. FALSE, /* partial_inplace */
  1620. 0, /* src_mask */
  1621. 0, /* dst_mask */
  1622. FALSE), /* pcrel_offset */
  1623. /* GNU extension to record C++ vtable member usage. */
  1624. HOWTO (R_PPC_GNU_VTENTRY, /* type */
  1625. 0, /* rightshift */
  1626. 0, /* size (0 = byte, 1 = short, 2 = long) */
  1627. 0, /* bitsize */
  1628. FALSE, /* pc_relative */
  1629. 0, /* bitpos */
  1630. complain_overflow_dont, /* complain_on_overflow */
  1631. NULL, /* special_function */
  1632. "R_PPC_GNU_VTENTRY", /* name */
  1633. FALSE, /* partial_inplace */
  1634. 0, /* src_mask */
  1635. 0, /* dst_mask */
  1636. FALSE), /* pcrel_offset */
  1637. /* Phony reloc to handle AIX style TOC entries. */
  1638. HOWTO (R_PPC_TOC16, /* type */
  1639. 0, /* rightshift */
  1640. 1, /* size (0 = byte, 1 = short, 2 = long) */
  1641. 16, /* bitsize */
  1642. FALSE, /* pc_relative */
  1643. 0, /* bitpos */
  1644. complain_overflow_signed, /* complain_on_overflow */
  1645. bfd_elf_generic_reloc, /* special_function */
  1646. "R_PPC_TOC16", /* name */
  1647. FALSE, /* partial_inplace */
  1648. 0, /* src_mask */
  1649. 0xffff, /* dst_mask */
  1650. FALSE), /* pcrel_offset */
  1651. };
  1652. /* External 32-bit PPC structure for PRPSINFO. This structure is
  1653. ABI-defined, thus we choose to use char arrays here in order to
  1654. avoid dealing with different types in different architectures.
  1655. The PPC 32-bit structure uses int for `pr_uid' and `pr_gid' while
  1656. most non-PPC architectures use `short int'.
  1657. This structure will ultimately be written in the corefile's note
  1658. section, as the PRPSINFO. */
  1659. struct elf_external_ppc_linux_prpsinfo32
  1660. {
  1661. char pr_state; /* Numeric process state. */
  1662. char pr_sname; /* Char for pr_state. */
  1663. char pr_zomb; /* Zombie. */
  1664. char pr_nice; /* Nice val. */
  1665. char pr_flag[4]; /* Flags. */
  1666. char pr_uid[4];
  1667. char pr_gid[4];
  1668. char pr_pid[4];
  1669. char pr_ppid[4];
  1670. char pr_pgrp[4];
  1671. char pr_sid[4];
  1672. char pr_fname[16]; /* Filename of executable. */
  1673. char pr_psargs[80]; /* Initial part of arg list. */
  1674. };
  1675. /* Helper macro to swap (properly handling endianess) things from the
  1676. `elf_internal_prpsinfo' structure to the `elf_external_ppc_prpsinfo32'
  1677. structure.
  1678. Note that FROM should be a pointer, and TO should be the explicit type. */
  1679. #define PPC_LINUX_PRPSINFO32_SWAP_FIELDS(abfd, from, to) \
  1680. do \
  1681. { \
  1682. H_PUT_8 (abfd, from->pr_state, &to.pr_state); \
  1683. H_PUT_8 (abfd, from->pr_sname, &to.pr_sname); \
  1684. H_PUT_8 (abfd, from->pr_zomb, &to.pr_zomb); \
  1685. H_PUT_8 (abfd, from->pr_nice, &to.pr_nice); \
  1686. H_PUT_32 (abfd, from->pr_flag, to.pr_flag); \
  1687. H_PUT_32 (abfd, from->pr_uid, to.pr_uid); \
  1688. H_PUT_32 (abfd, from->pr_gid, to.pr_gid); \
  1689. H_PUT_32 (abfd, from->pr_pid, to.pr_pid); \
  1690. H_PUT_32 (abfd, from->pr_ppid, to.pr_ppid); \
  1691. H_PUT_32 (abfd, from->pr_pgrp, to.pr_pgrp); \
  1692. H_PUT_32 (abfd, from->pr_sid, to.pr_sid); \
  1693. strncpy (to.pr_fname, from->pr_fname, sizeof (to.pr_fname)); \
  1694. strncpy (to.pr_psargs, from->pr_psargs, sizeof (to.pr_psargs)); \
  1695. } while (0)
  1696. /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
  1697. static void
  1698. ppc_elf_howto_init (void)
  1699. {
  1700. unsigned int i, type;
  1701. for (i = 0;
  1702. i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
  1703. i++)
  1704. {
  1705. type = ppc_elf_howto_raw[i].type;
  1706. if (type >= (sizeof (ppc_elf_howto_table)
  1707. / sizeof (ppc_elf_howto_table[0])))
  1708. abort ();
  1709. ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
  1710. }
  1711. }
  1712. static reloc_howto_type *
  1713. ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1714. bfd_reloc_code_real_type code)
  1715. {
  1716. enum elf_ppc_reloc_type r;
  1717. /* Initialize howto table if not already done. */
  1718. if (!ppc_elf_howto_table[R_PPC_ADDR32])
  1719. ppc_elf_howto_init ();
  1720. switch (code)
  1721. {
  1722. default:
  1723. return NULL;
  1724. case BFD_RELOC_NONE: r = R_PPC_NONE; break;
  1725. case BFD_RELOC_32: r = R_PPC_ADDR32; break;
  1726. case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break;
  1727. case BFD_RELOC_PPC64_ADDR16_DS:
  1728. case BFD_RELOC_16: r = R_PPC_ADDR16; break;
  1729. case BFD_RELOC_PPC64_ADDR16_LO_DS:
  1730. case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break;
  1731. case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break;
  1732. case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break;
  1733. case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break;
  1734. case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break;
  1735. case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break;
  1736. case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break;
  1737. case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break;
  1738. case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break;
  1739. case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break;
  1740. case BFD_RELOC_PPC64_GOT16_DS:
  1741. case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break;
  1742. case BFD_RELOC_PPC64_GOT16_LO_DS:
  1743. case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break;
  1744. case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break;
  1745. case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break;
  1746. case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break;
  1747. case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break;
  1748. case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break;
  1749. case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break;
  1750. case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break;
  1751. case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break;
  1752. case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break;
  1753. case BFD_RELOC_PPC64_PLT16_LO_DS:
  1754. case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break;
  1755. case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break;
  1756. case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break;
  1757. case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
  1758. case BFD_RELOC_PPC64_SECTOFF_DS:
  1759. case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
  1760. case BFD_RELOC_PPC64_SECTOFF_LO_DS:
  1761. case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
  1762. case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
  1763. case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
  1764. case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
  1765. case BFD_RELOC_PPC64_TOC16_DS:
  1766. case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
  1767. case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
  1768. case BFD_RELOC_PPC_TLSGD: r = R_PPC_TLSGD; break;
  1769. case BFD_RELOC_PPC_TLSLD: r = R_PPC_TLSLD; break;
  1770. case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
  1771. case BFD_RELOC_PPC64_TPREL16_DS:
  1772. case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
  1773. case BFD_RELOC_PPC64_TPREL16_LO_DS:
  1774. case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
  1775. case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
  1776. case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
  1777. case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
  1778. case BFD_RELOC_PPC64_DTPREL16_DS:
  1779. case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
  1780. case BFD_RELOC_PPC64_DTPREL16_LO_DS:
  1781. case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;
  1782. case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break;
  1783. case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break;
  1784. case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break;
  1785. case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break;
  1786. case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break;
  1787. case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break;
  1788. case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break;
  1789. case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break;
  1790. case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break;
  1791. case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break;
  1792. case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break;
  1793. case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break;
  1794. case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break;
  1795. case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break;
  1796. case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break;
  1797. case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break;
  1798. case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break;
  1799. case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break;
  1800. case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break;
  1801. case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break;
  1802. case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break;
  1803. case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break;
  1804. case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break;
  1805. case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break;
  1806. case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break;
  1807. case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break;
  1808. case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break;
  1809. case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break;
  1810. case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break;
  1811. case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break;
  1812. case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break;
  1813. case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break;
  1814. case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break;
  1815. case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break;
  1816. case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break;
  1817. case BFD_RELOC_PPC_VLE_REL8: r = R_PPC_VLE_REL8; break;
  1818. case BFD_RELOC_PPC_VLE_REL15: r = R_PPC_VLE_REL15; break;
  1819. case BFD_RELOC_PPC_VLE_REL24: r = R_PPC_VLE_REL24; break;
  1820. case BFD_RELOC_PPC_VLE_LO16A: r = R_PPC_VLE_LO16A; break;
  1821. case BFD_RELOC_PPC_VLE_LO16D: r = R_PPC_VLE_LO16D; break;
  1822. case BFD_RELOC_PPC_VLE_HI16A: r = R_PPC_VLE_HI16A; break;
  1823. case BFD_RELOC_PPC_VLE_HI16D: r = R_PPC_VLE_HI16D; break;
  1824. case BFD_RELOC_PPC_VLE_HA16A: r = R_PPC_VLE_HA16A; break;
  1825. case BFD_RELOC_PPC_VLE_HA16D: r = R_PPC_VLE_HA16D; break;
  1826. case BFD_RELOC_PPC_VLE_SDA21: r = R_PPC_VLE_SDA21; break;
  1827. case BFD_RELOC_PPC_VLE_SDA21_LO: r = R_PPC_VLE_SDA21_LO; break;
  1828. case BFD_RELOC_PPC_VLE_SDAREL_LO16A:
  1829. r = R_PPC_VLE_SDAREL_LO16A;
  1830. break;
  1831. case BFD_RELOC_PPC_VLE_SDAREL_LO16D:
  1832. r = R_PPC_VLE_SDAREL_LO16D;
  1833. break;
  1834. case BFD_RELOC_PPC_VLE_SDAREL_HI16A:
  1835. r = R_PPC_VLE_SDAREL_HI16A;
  1836. break;
  1837. case BFD_RELOC_PPC_VLE_SDAREL_HI16D:
  1838. r = R_PPC_VLE_SDAREL_HI16D;
  1839. break;
  1840. case BFD_RELOC_PPC_VLE_SDAREL_HA16A:
  1841. r = R_PPC_VLE_SDAREL_HA16A;
  1842. break;
  1843. case BFD_RELOC_PPC_VLE_SDAREL_HA16D:
  1844. r = R_PPC_VLE_SDAREL_HA16D;
  1845. break;
  1846. case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break;
  1847. case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break;
  1848. case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break;
  1849. case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break;
  1850. case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break;
  1851. case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break;
  1852. }
  1853. return ppc_elf_howto_table[r];
  1854. };
  1855. static reloc_howto_type *
  1856. ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1857. const char *r_name)
  1858. {
  1859. unsigned int i;
  1860. for (i = 0;
  1861. i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
  1862. i++)
  1863. if (ppc_elf_howto_raw[i].name != NULL
  1864. && strcasecmp (ppc_elf_howto_raw[i].name, r_name) == 0)
  1865. return &ppc_elf_howto_raw[i];
  1866. return NULL;
  1867. }
  1868. /* Set the howto pointer for a PowerPC ELF reloc. */
  1869. static void
  1870. ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
  1871. arelent *cache_ptr,
  1872. Elf_Internal_Rela *dst)
  1873. {
  1874. unsigned int r_type;
  1875. /* Initialize howto table if not already done. */
  1876. if (!ppc_elf_howto_table[R_PPC_ADDR32])
  1877. ppc_elf_howto_init ();
  1878. r_type = ELF32_R_TYPE (dst->r_info);
  1879. if (r_type >= R_PPC_max)
  1880. {
  1881. (*_bfd_error_handler) (_("%B: unrecognised PPC reloc number: %d"),
  1882. abfd, r_type);
  1883. bfd_set_error (bfd_error_bad_value);
  1884. r_type = R_PPC_NONE;
  1885. }
  1886. cache_ptr->howto = ppc_elf_howto_table[r_type];
  1887. /* Just because the above assert didn't trigger doesn't mean that
  1888. ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */
  1889. if (!cache_ptr->howto)
  1890. {
  1891. (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
  1892. abfd, r_type);
  1893. bfd_set_error (bfd_error_bad_value);
  1894. cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE];
  1895. }
  1896. }
  1897. /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
  1898. static bfd_reloc_status_type
  1899. ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED,
  1900. arelent *reloc_entry,
  1901. asymbol *symbol,
  1902. void *data ATTRIBUTE_UNUSED,
  1903. asection *input_section,
  1904. bfd *output_bfd,
  1905. char **error_message ATTRIBUTE_UNUSED)
  1906. {
  1907. bfd_vma relocation;
  1908. if (output_bfd != NULL)
  1909. {
  1910. reloc_entry->address += input_section->output_offset;
  1911. return bfd_reloc_ok;
  1912. }
  1913. if (bfd_is_com_section (symbol->section))
  1914. relocation = 0;
  1915. else
  1916. relocation = symbol->value;
  1917. relocation += symbol->section->output_section->vma;
  1918. relocation += symbol->section->output_offset;
  1919. relocation += reloc_entry->addend;
  1920. if (reloc_entry->howto->pc_relative)
  1921. relocation -= reloc_entry->address;
  1922. reloc_entry->addend += (relocation & 0x8000) << 1;
  1923. return bfd_reloc_continue;
  1924. }
  1925. static bfd_reloc_status_type
  1926. ppc_elf_unhandled_reloc (bfd *abfd,
  1927. arelent *reloc_entry,
  1928. asymbol *symbol,
  1929. void *data,
  1930. asection *input_section,
  1931. bfd *output_bfd,
  1932. char **error_message)
  1933. {
  1934. /* If this is a relocatable link (output_bfd test tells us), just
  1935. call the generic function. Any adjustment will be done at final
  1936. link time. */
  1937. if (output_bfd != NULL)
  1938. return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
  1939. input_section, output_bfd, error_message);
  1940. if (error_message != NULL)
  1941. {
  1942. static char buf[60];
  1943. sprintf (buf, _("generic linker can't handle %s"),
  1944. reloc_entry->howto->name);
  1945. *error_message = buf;
  1946. }
  1947. return bfd_reloc_dangerous;
  1948. }
  1949. /* Sections created by the linker. */
  1950. typedef struct elf_linker_section
  1951. {
  1952. /* Pointer to the bfd section. */
  1953. asection *section;
  1954. /* Section name. */
  1955. const char *name;
  1956. /* Associated bss section name. */
  1957. const char *bss_name;
  1958. /* Associated symbol name. */
  1959. const char *sym_name;
  1960. /* Associated symbol. */
  1961. struct elf_link_hash_entry *sym;
  1962. } elf_linker_section_t;
  1963. /* Linked list of allocated pointer entries. This hangs off of the
  1964. symbol lists, and provides allows us to return different pointers,
  1965. based on different addend's. */
  1966. typedef struct elf_linker_section_pointers
  1967. {
  1968. /* next allocated pointer for this symbol */
  1969. struct elf_linker_section_pointers *next;
  1970. /* offset of pointer from beginning of section */
  1971. bfd_vma offset;
  1972. /* addend used */
  1973. bfd_vma addend;
  1974. /* which linker section this is */
  1975. elf_linker_section_t *lsect;
  1976. } elf_linker_section_pointers_t;
  1977. struct ppc_elf_obj_tdata
  1978. {
  1979. struct elf_obj_tdata elf;
  1980. /* A mapping from local symbols to offsets into the various linker
  1981. sections added. This is index by the symbol index. */
  1982. elf_linker_section_pointers_t **linker_section_pointers;
  1983. /* Flags used to auto-detect plt type. */
  1984. unsigned int makes_plt_call : 1;
  1985. unsigned int has_rel16 : 1;
  1986. };
  1987. #define ppc_elf_tdata(bfd) \
  1988. ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
  1989. #define elf_local_ptr_offsets(bfd) \
  1990. (ppc_elf_tdata (bfd)->linker_section_pointers)
  1991. #define is_ppc_elf(bfd) \
  1992. (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
  1993. && elf_object_id (bfd) == PPC32_ELF_DATA)
  1994. /* Override the generic function because we store some extras. */
  1995. static bfd_boolean
  1996. ppc_elf_mkobject (bfd *abfd)
  1997. {
  1998. return bfd_elf_allocate_object (abfd, sizeof (struct ppc_elf_obj_tdata),
  1999. PPC32_ELF_DATA);
  2000. }
  2001. /* Fix bad default arch selected for a 32 bit input bfd when the
  2002. default is 64 bit. */
  2003. static bfd_boolean
  2004. ppc_elf_object_p (bfd *abfd)
  2005. {
  2006. if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
  2007. {
  2008. Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
  2009. if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
  2010. {
  2011. /* Relies on arch after 64 bit default being 32 bit default. */
  2012. abfd->arch_info = abfd->arch_info->next;
  2013. BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
  2014. }
  2015. }
  2016. return TRUE;
  2017. }
  2018. /* Function to set whether a module needs the -mrelocatable bit set. */
  2019. static bfd_boolean
  2020. ppc_elf_set_private_flags (bfd *abfd, flagword flags)
  2021. {
  2022. BFD_ASSERT (!elf_flags_init (abfd)
  2023. || elf_elfheader (abfd)->e_flags == flags);
  2024. elf_elfheader (abfd)->e_flags = flags;
  2025. elf_flags_init (abfd) = TRUE;
  2026. return TRUE;
  2027. }
  2028. /* Support for core dump NOTE sections. */
  2029. static bfd_boolean
  2030. ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
  2031. {
  2032. int offset;
  2033. unsigned int size;
  2034. switch (note->descsz)
  2035. {
  2036. default:
  2037. return FALSE;
  2038. case 268: /* Linux/PPC. */
  2039. /* pr_cursig */
  2040. elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
  2041. /* pr_pid */
  2042. elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
  2043. /* pr_reg */
  2044. offset = 72;
  2045. size = 192;
  2046. break;
  2047. }
  2048. /* Make a ".reg/999" section. */
  2049. return _bfd_elfcore_make_pseudosection (abfd, ".reg",
  2050. size, note->descpos + offset);
  2051. }
  2052. static bfd_boolean
  2053. ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
  2054. {
  2055. switch (note->descsz)
  2056. {
  2057. default:
  2058. return FALSE;
  2059. case 128: /* Linux/PPC elf_prpsinfo. */
  2060. elf_tdata (abfd)->core->pid
  2061. = bfd_get_32 (abfd, note->descdata + 16);
  2062. elf_tdata (abfd)->core->program
  2063. = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
  2064. elf_tdata (abfd)->core->command
  2065. = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
  2066. }
  2067. /* Note that for some reason, a spurious space is tacked
  2068. onto the end of the args in some (at least one anyway)
  2069. implementations, so strip it off if it exists. */
  2070. {
  2071. char *command = elf_tdata (abfd)->core->command;
  2072. int n = strlen (command);
  2073. if (0 < n && command[n - 1] == ' ')
  2074. command[n - 1] = '\0';
  2075. }
  2076. return TRUE;
  2077. }
  2078. char *
  2079. elfcore_write_ppc_linux_prpsinfo32 (bfd *abfd, char *buf, int *bufsiz,
  2080. const struct elf_internal_linux_prpsinfo *prpsinfo)
  2081. {
  2082. struct elf_external_ppc_linux_prpsinfo32 data;
  2083. memset (&data, 0, sizeof (data));
  2084. PPC_LINUX_PRPSINFO32_SWAP_FIELDS (abfd, prpsinfo, data);
  2085. return elfcore_write_note (abfd, buf, bufsiz,
  2086. "CORE", NT_PRPSINFO, &data, sizeof (data));
  2087. }
  2088. static char *
  2089. ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...)
  2090. {
  2091. switch (note_type)
  2092. {
  2093. default:
  2094. return NULL;
  2095. case NT_PRPSINFO:
  2096. {
  2097. char data[128];
  2098. va_list ap;
  2099. va_start (ap, note_type);
  2100. memset (data, 0, sizeof (data));
  2101. strncpy (data + 32, va_arg (ap, const char *), 16);
  2102. strncpy (data + 48, va_arg (ap, const char *), 80);
  2103. va_end (ap);
  2104. return elfcore_write_note (abfd, buf, bufsiz,
  2105. "CORE", note_type, data, sizeof (data));
  2106. }
  2107. case NT_PRSTATUS:
  2108. {
  2109. char data[268];
  2110. va_list ap;
  2111. long pid;
  2112. int cursig;
  2113. const void *greg;
  2114. va_start (ap, note_type);
  2115. memset (data, 0, 72);
  2116. pid = va_arg (ap, long);
  2117. bfd_put_32 (abfd, pid, data + 24);
  2118. cursig = va_arg (ap, int);
  2119. bfd_put_16 (abfd, cursig, data + 12);
  2120. greg = va_arg (ap, const void *);
  2121. memcpy (data + 72, greg, 192);
  2122. memset (data + 264, 0, 4);
  2123. va_end (ap);
  2124. return elfcore_write_note (abfd, buf, bufsiz,
  2125. "CORE", note_type, data, sizeof (data));
  2126. }
  2127. }
  2128. }
  2129. static flagword
  2130. ppc_elf_lookup_section_flags (char *flag_name)
  2131. {
  2132. if (!strcmp (flag_name, "SHF_PPC_VLE"))
  2133. return SHF_PPC_VLE;
  2134. return 0;
  2135. }
  2136. /* Add the VLE flag if required. */
  2137. bfd_boolean
  2138. ppc_elf_section_processing (bfd *abfd, Elf_Internal_Shdr *shdr)
  2139. {
  2140. if (bfd_get_mach (abfd) == bfd_mach_ppc_vle
  2141. && (shdr->sh_flags & SHF_EXECINSTR) != 0)
  2142. shdr->sh_flags |= SHF_PPC_VLE;
  2143. return TRUE;
  2144. }
  2145. /* Return address for Ith PLT stub in section PLT, for relocation REL
  2146. or (bfd_vma) -1 if it should not be included. */
  2147. static bfd_vma
  2148. ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED,
  2149. const asection *plt ATTRIBUTE_UNUSED,
  2150. const arelent *rel)
  2151. {
  2152. return rel->address;
  2153. }
  2154. /* Handle a PowerPC specific section when reading an object file. This
  2155. is called when bfd_section_from_shdr finds a section with an unknown
  2156. type. */
  2157. static bfd_boolean
  2158. ppc_elf_section_from_shdr (bfd *abfd,
  2159. Elf_Internal_Shdr *hdr,
  2160. const char *name,
  2161. int shindex)
  2162. {
  2163. asection *newsect;
  2164. flagword flags;
  2165. if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
  2166. return FALSE;
  2167. newsect = hdr->bfd_section;
  2168. flags = bfd_get_section_flags (abfd, newsect);
  2169. if (hdr->sh_flags & SHF_EXCLUDE)
  2170. flags |= SEC_EXCLUDE;
  2171. if (hdr->sh_type == SHT_ORDERED)
  2172. flags |= SEC_SORT_ENTRIES;
  2173. bfd_set_section_flags (abfd, newsect, flags);
  2174. return TRUE;
  2175. }
  2176. /* Set up any other section flags and such that may be necessary. */
  2177. static bfd_boolean
  2178. ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
  2179. Elf_Internal_Shdr *shdr,
  2180. asection *asect)
  2181. {
  2182. if ((asect->flags & SEC_SORT_ENTRIES) != 0)
  2183. shdr->sh_type = SHT_ORDERED;
  2184. return TRUE;
  2185. }
  2186. /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
  2187. need to bump up the number of section headers. */
  2188. static int
  2189. ppc_elf_additional_program_headers (bfd *abfd,
  2190. struct bfd_link_info *info ATTRIBUTE_UNUSED)
  2191. {
  2192. asection *s;
  2193. int ret = 0;
  2194. s = bfd_get_section_by_name (abfd, ".sbss2");
  2195. if (s != NULL && (s->flags & SEC_ALLOC) != 0)
  2196. ++ret;
  2197. s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
  2198. if (s != NULL && (s->flags & SEC_ALLOC) != 0)
  2199. ++ret;
  2200. return ret;
  2201. }
  2202. /* Modify the segment map for VLE executables. */
  2203. bfd_boolean
  2204. ppc_elf_modify_segment_map (bfd *abfd,
  2205. struct bfd_link_info *info ATTRIBUTE_UNUSED)
  2206. {
  2207. struct elf_segment_map *m, *n;
  2208. bfd_size_type amt;
  2209. unsigned int j, k;
  2210. bfd_boolean sect0_vle, sectj_vle;
  2211. /* At this point in the link, output sections have already been sorted by
  2212. LMA and assigned to segments. All that is left to do is to ensure
  2213. there is no mixing of VLE & non-VLE sections in a text segment.
  2214. If we find that case, we split the segment.
  2215. We maintain the original output section order. */
  2216. for (m = elf_seg_map (abfd); m != NULL; m = m->next)
  2217. {
  2218. if (m->count == 0)
  2219. continue;
  2220. sect0_vle = (elf_section_flags (m->sections[0]) & SHF_PPC_VLE) != 0;
  2221. for (j = 1; j < m->count; ++j)
  2222. {
  2223. sectj_vle = (elf_section_flags (m->sections[j]) & SHF_PPC_VLE) != 0;
  2224. if (sectj_vle != sect0_vle)
  2225. break;
  2226. }
  2227. if (j >= m->count)
  2228. continue;
  2229. /* sections 0..j-1 stay in this (current) segment,
  2230. the remainder are put in a new segment.
  2231. The scan resumes with the new segment. */
  2232. /* Fix the new segment. */
  2233. amt = sizeof (struct elf_segment_map);
  2234. amt += (m->count - j - 1) * sizeof (asection *);
  2235. n = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
  2236. if (n == NULL)
  2237. return FALSE;
  2238. n->p_type = PT_LOAD;
  2239. n->p_flags = PF_X | PF_R;
  2240. if (sectj_vle)
  2241. n->p_flags |= PF_PPC_VLE;
  2242. n->count = m->count - j;
  2243. for (k = 0; k < n->count; ++k)
  2244. {
  2245. n->sections[k] = m->sections[j+k];
  2246. m->sections[j+k] = NULL;
  2247. }
  2248. n->next = m->next;
  2249. m->next = n;
  2250. /* Fix the current segment */
  2251. m->count = j;
  2252. }
  2253. return TRUE;
  2254. }
  2255. /* Add extra PPC sections -- Note, for now, make .sbss2 and
  2256. .PPC.EMB.sbss0 a normal section, and not a bss section so
  2257. that the linker doesn't crater when trying to make more than
  2258. 2 sections. */
  2259. static const struct bfd_elf_special_section ppc_elf_special_sections[] =
  2260. {
  2261. { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR },
  2262. { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
  2263. { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS, SHF_ALLOC },
  2264. { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
  2265. { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS, SHF_ALLOC },
  2266. { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED, SHF_ALLOC },
  2267. { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE, 0 },
  2268. { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS, SHF_ALLOC },
  2269. { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS, SHF_ALLOC },
  2270. { NULL, 0, 0, 0, 0 }
  2271. };
  2272. /* This is what we want for new plt/got. */
  2273. static struct bfd_elf_special_section ppc_alt_plt =
  2274. { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC };
  2275. static const struct bfd_elf_special_section *
  2276. ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
  2277. {
  2278. const struct bfd_elf_special_section *ssect;
  2279. /* See if this is one of the special sections. */
  2280. if (sec->name == NULL)
  2281. return NULL;
  2282. ssect = _bfd_elf_get_special_section (sec->name, ppc_elf_special_sections,
  2283. sec->use_rela_p);
  2284. if (ssect != NULL)
  2285. {
  2286. if (ssect == ppc_elf_special_sections && (sec->flags & SEC_LOAD) != 0)
  2287. ssect = &ppc_alt_plt;
  2288. return ssect;
  2289. }
  2290. return _bfd_elf_get_sec_type_attr (abfd, sec);
  2291. }
  2292. /* Very simple linked list structure for recording apuinfo values. */
  2293. typedef struct apuinfo_list
  2294. {
  2295. struct apuinfo_list *next;
  2296. unsigned long value;
  2297. }
  2298. apuinfo_list;
  2299. static apuinfo_list *head;
  2300. static bfd_boolean apuinfo_set;
  2301. static void
  2302. apuinfo_list_init (void)
  2303. {
  2304. head = NULL;
  2305. apuinfo_set = FALSE;
  2306. }
  2307. static void
  2308. apuinfo_list_add (unsigned long value)
  2309. {
  2310. apuinfo_list *entry = head;
  2311. while (entry != NULL)
  2312. {
  2313. if (entry->value == value)
  2314. return;
  2315. entry = entry->next;
  2316. }
  2317. entry = bfd_malloc (sizeof (* entry));
  2318. if (entry == NULL)
  2319. return;
  2320. entry->value = value;
  2321. entry->next = head;
  2322. head = entry;
  2323. }
  2324. static unsigned
  2325. apuinfo_list_length (void)
  2326. {
  2327. apuinfo_list *entry;
  2328. unsigned long count;
  2329. for (entry = head, count = 0;
  2330. entry;
  2331. entry = entry->next)
  2332. ++ count;
  2333. return count;
  2334. }
  2335. static inline unsigned long
  2336. apuinfo_list_element (unsigned long number)
  2337. {
  2338. apuinfo_list * entry;
  2339. for (entry = head;
  2340. entry && number --;
  2341. entry = entry->next)
  2342. ;
  2343. return entry ? entry->value : 0;
  2344. }
  2345. static void
  2346. apuinfo_list_finish (void)
  2347. {
  2348. apuinfo_list *entry;
  2349. for (entry = head; entry;)
  2350. {
  2351. apuinfo_list *next = entry->next;
  2352. free (entry);
  2353. entry = next;
  2354. }
  2355. head = NULL;
  2356. }
  2357. #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
  2358. #define APUINFO_LABEL "APUinfo"
  2359. /* Scan the input BFDs and create a linked list of
  2360. the APUinfo values that will need to be emitted. */
  2361. static void
  2362. ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
  2363. {
  2364. bfd *ibfd;
  2365. asection *asec;
  2366. char *buffer = NULL;
  2367. bfd_size_type largest_input_size = 0;
  2368. unsigned i;
  2369. unsigned long length;
  2370. const char *error_message = NULL;
  2371. if (link_info == NULL)
  2372. return;
  2373. apuinfo_list_init ();
  2374. /* Read in the input sections contents. */
  2375. for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link.next)
  2376. {
  2377. unsigned long datum;
  2378. asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
  2379. if (asec == NULL)
  2380. continue;
  2381. error_message = _("corrupt %s section in %B");
  2382. length = asec->size;
  2383. if (length < 20)
  2384. goto fail;
  2385. apuinfo_set = TRUE;
  2386. if (largest_input_size < asec->size)
  2387. {
  2388. if (buffer)
  2389. free (buffer);
  2390. largest_input_size = asec->size;
  2391. buffer = bfd_malloc (largest_input_size);
  2392. if (!buffer)
  2393. return;
  2394. }
  2395. if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
  2396. || (bfd_bread (buffer, length, ibfd) != length))
  2397. {
  2398. error_message = _("unable to read in %s section from %B");
  2399. goto fail;
  2400. }
  2401. /* Verify the contents of the header. Note - we have to
  2402. extract the values this way in order to allow for a
  2403. host whose endian-ness is different from the target. */
  2404. datum = bfd_get_32 (ibfd, buffer);
  2405. if (datum != sizeof APUINFO_LABEL)
  2406. goto fail;
  2407. datum = bfd_get_32 (ibfd, buffer + 8);
  2408. if (datum != 0x2)
  2409. goto fail;
  2410. if (strcmp (buffer + 12, APUINFO_LABEL) != 0)
  2411. goto fail;
  2412. /* Get the number of bytes used for apuinfo entries. */
  2413. datum = bfd_get_32 (ibfd, buffer + 4);
  2414. if (datum + 20 != length)
  2415. goto fail;
  2416. /* Scan the apuinfo section, building a list of apuinfo numbers. */
  2417. for (i = 0; i < datum; i += 4)
  2418. apuinfo_list_add (bfd_get_32 (ibfd, buffer + 20 + i));
  2419. }
  2420. error_message = NULL;
  2421. if (apuinfo_set)
  2422. {
  2423. /* Compute the size of the output section. */
  2424. unsigned num_entries = apuinfo_list_length ();
  2425. /* Set the output section size, if it exists. */
  2426. asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
  2427. if (asec && ! bfd_set_section_size (abfd, asec, 20 + num_entries * 4))
  2428. {
  2429. ibfd = abfd;
  2430. error_message = _("warning: unable to set size of %s section in %B");
  2431. }
  2432. }
  2433. fail:
  2434. if (buffer)
  2435. free (buffer);
  2436. if (error_message)
  2437. (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME);
  2438. }
  2439. /* Prevent the output section from accumulating the input sections'
  2440. contents. We have already stored this in our linked list structure. */
  2441. static bfd_boolean
  2442. ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
  2443. struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
  2444. asection *asec,
  2445. bfd_byte *contents ATTRIBUTE_UNUSED)
  2446. {
  2447. return apuinfo_set && strcmp (asec->name, APUINFO_SECTION_NAME) == 0;
  2448. }
  2449. /* Finally we can generate the output section. */
  2450. static void
  2451. ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
  2452. {
  2453. bfd_byte *buffer;
  2454. asection *asec;
  2455. unsigned i;
  2456. unsigned num_entries;
  2457. bfd_size_type length;
  2458. asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
  2459. if (asec == NULL)
  2460. return;
  2461. if (!apuinfo_set)
  2462. return;
  2463. length = asec->size;
  2464. if (length < 20)
  2465. return;
  2466. buffer = bfd_malloc (length);
  2467. if (buffer == NULL)
  2468. {
  2469. (*_bfd_error_handler)
  2470. (_("failed to allocate space for new APUinfo section."));
  2471. return;
  2472. }
  2473. /* Create the apuinfo header. */
  2474. num_entries = apuinfo_list_length ();
  2475. bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
  2476. bfd_put_32 (abfd, num_entries * 4, buffer + 4);
  2477. bfd_put_32 (abfd, 0x2, buffer + 8);
  2478. strcpy ((char *) buffer + 12, APUINFO_LABEL);
  2479. length = 20;
  2480. for (i = 0; i < num_entries; i++)
  2481. {
  2482. bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
  2483. length += 4;
  2484. }
  2485. if (length != asec->size)
  2486. (*_bfd_error_handler) (_("failed to compute new APUinfo section."));
  2487. if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
  2488. (*_bfd_error_handler) (_("failed to install new APUinfo section."));
  2489. free (buffer);
  2490. apuinfo_list_finish ();
  2491. }
  2492. static bfd_boolean
  2493. is_nonpic_glink_stub (bfd *abfd, asection *glink, bfd_vma off)
  2494. {
  2495. bfd_byte buf[GLINK_ENTRY_SIZE];
  2496. if (!bfd_get_section_contents (abfd, glink, buf, off, GLINK_ENTRY_SIZE))
  2497. return FALSE;
  2498. return ((bfd_get_32 (abfd, buf + 0) & 0xffff0000) == LIS_11
  2499. && (bfd_get_32 (abfd, buf + 4) & 0xffff0000) == LWZ_11_11
  2500. && bfd_get_32 (abfd, buf + 8) == MTCTR_11
  2501. && bfd_get_32 (abfd, buf + 12) == BCTR);
  2502. }
  2503. static bfd_boolean
  2504. section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr)
  2505. {
  2506. bfd_vma vma = *(bfd_vma *) ptr;
  2507. return ((section->flags & SEC_ALLOC) != 0
  2508. && section->vma <= vma
  2509. && vma < section->vma + section->size);
  2510. }
  2511. static long
  2512. ppc_elf_get_synthetic_symtab (bfd *abfd, long symcount, asymbol **syms,
  2513. long dynsymcount, asymbol **dynsyms,
  2514. asymbol **ret)
  2515. {
  2516. bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
  2517. asection *plt, *relplt, *dynamic, *glink;
  2518. bfd_vma glink_vma = 0;
  2519. bfd_vma resolv_vma = 0;
  2520. bfd_vma stub_vma;
  2521. asymbol *s;
  2522. arelent *p;
  2523. long count, i;
  2524. size_t size;
  2525. char *names;
  2526. bfd_byte buf[4];
  2527. *ret = NULL;
  2528. if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
  2529. return 0;
  2530. if (dynsymcount <= 0)
  2531. return 0;
  2532. relplt = bfd_get_section_by_name (abfd, ".rela.plt");
  2533. if (relplt == NULL)
  2534. return 0;
  2535. plt = bfd_get_section_by_name (abfd, ".plt");
  2536. if (plt == NULL)
  2537. return 0;
  2538. /* Call common code to handle old-style executable PLTs. */
  2539. if (elf_section_flags (plt) & SHF_EXECINSTR)
  2540. return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms,
  2541. dynsymcount, dynsyms, ret);
  2542. /* If this object was prelinked, the prelinker stored the address
  2543. of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */
  2544. dynamic = bfd_get_section_by_name (abfd, ".dynamic");
  2545. if (dynamic != NULL)
  2546. {
  2547. bfd_byte *dynbuf, *extdyn, *extdynend;
  2548. size_t extdynsize;
  2549. void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *);
  2550. if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf))
  2551. return -1;
  2552. extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
  2553. swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
  2554. extdyn = dynbuf;
  2555. extdynend = extdyn + dynamic->size;
  2556. for (; extdyn < extdynend; extdyn += extdynsize)
  2557. {
  2558. Elf_Internal_Dyn dyn;
  2559. (*swap_dyn_in) (abfd, extdyn, &dyn);
  2560. if (dyn.d_tag == DT_NULL)
  2561. break;
  2562. if (dyn.d_tag == DT_PPC_GOT)
  2563. {
  2564. unsigned int g_o_t = dyn.d_un.d_val;
  2565. asection *got = bfd_get_section_by_name (abfd, ".got");
  2566. if (got != NULL
  2567. && bfd_get_section_contents (abfd, got, buf,
  2568. g_o_t - got->vma + 4, 4))
  2569. glink_vma = bfd_get_32 (abfd, buf);
  2570. break;
  2571. }
  2572. }
  2573. free (dynbuf);
  2574. }
  2575. /* Otherwise we read the first plt entry. */
  2576. if (glink_vma == 0)
  2577. {
  2578. if (bfd_get_section_contents (abfd, plt, buf, 0, 4))
  2579. glink_vma = bfd_get_32 (abfd, buf);
  2580. }
  2581. if (glink_vma == 0)
  2582. return 0;
  2583. /* The .glink section usually does not survive the final
  2584. link; search for the section (usually .text) where the
  2585. glink stubs now reside. */
  2586. glink = bfd_sections_find_if (abfd, section_covers_vma, &glink_vma);
  2587. if (glink == NULL)
  2588. return 0;
  2589. /* Determine glink PLT resolver by reading the relative branch
  2590. from the first glink stub. */
  2591. if (bfd_get_section_contents (abfd, glink, buf,
  2592. glink_vma - glink->vma, 4))
  2593. {
  2594. unsigned int insn = bfd_get_32 (abfd, buf);
  2595. /* The first glink stub may either branch to the resolver ... */
  2596. insn ^= B;
  2597. if ((insn & ~0x3fffffc) == 0)
  2598. resolv_vma = glink_vma + (insn ^ 0x2000000) - 0x2000000;
  2599. /* ... or fall through a bunch of NOPs. */
  2600. else if ((insn ^ B ^ NOP) == 0)
  2601. for (i = 4;
  2602. bfd_get_section_contents (abfd, glink, buf,
  2603. glink_vma - glink->vma + i, 4);
  2604. i += 4)
  2605. if (bfd_get_32 (abfd, buf) != NOP)
  2606. {
  2607. resolv_vma = glink_vma + i;
  2608. break;
  2609. }
  2610. }
  2611. count = relplt->size / sizeof (Elf32_External_Rela);
  2612. /* If the stubs are those for -shared/-pie then we might have
  2613. multiple stubs for each plt entry. If that is the case then
  2614. there is no way to associate stubs with their plt entries short
  2615. of figuring out the GOT pointer value used in the stub. */
  2616. if (!is_nonpic_glink_stub (abfd, glink,
  2617. glink_vma - GLINK_ENTRY_SIZE - glink->vma))
  2618. return 0;
  2619. slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
  2620. if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE))
  2621. return -1;
  2622. size = count * sizeof (asymbol);
  2623. p = relplt->relocation;
  2624. for (i = 0; i < count; i++, p++)
  2625. {
  2626. size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
  2627. if (p->addend != 0)
  2628. size += sizeof ("+0x") - 1 + 8;
  2629. }
  2630. size += sizeof (asymbol) + sizeof ("__glink");
  2631. if (resolv_vma)
  2632. size += sizeof (asymbol) + sizeof ("__glink_PLTresolve");
  2633. s = *ret = bfd_malloc (size);
  2634. if (s == NULL)
  2635. return -1;
  2636. stub_vma = glink_vma;
  2637. names = (char *) (s + count + 1 + (resolv_vma != 0));
  2638. p = relplt->relocation + count - 1;
  2639. for (i = 0; i < count; i++)
  2640. {
  2641. size_t len;
  2642. *s = **p->sym_ptr_ptr;
  2643. /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
  2644. we are defining a symbol, ensure one of them is set. */
  2645. if ((s->flags & BSF_LOCAL) == 0)
  2646. s->flags |= BSF_GLOBAL;
  2647. s->flags |= BSF_SYNTHETIC;
  2648. s->section = glink;
  2649. stub_vma -= 16;
  2650. if (strcmp ((*p->sym_ptr_ptr)->name, "__tls_get_addr_opt") == 0)
  2651. stub_vma -= 32;
  2652. s->value = stub_vma - glink->vma;
  2653. s->name = names;
  2654. s->udata.p = NULL;
  2655. len = strlen ((*p->sym_ptr_ptr)->name);
  2656. memcpy (names, (*p->sym_ptr_ptr)->name, len);
  2657. names += len;
  2658. if (p->addend != 0)
  2659. {
  2660. memcpy (names, "+0x", sizeof ("+0x") - 1);
  2661. names += sizeof ("+0x") - 1;
  2662. bfd_sprintf_vma (abfd, names, p->addend);
  2663. names += strlen (names);
  2664. }
  2665. memcpy (names, "@plt", sizeof ("@plt"));
  2666. names += sizeof ("@plt");
  2667. ++s;
  2668. --p;
  2669. }
  2670. /* Add a symbol at the start of the glink branch table. */
  2671. memset (s, 0, sizeof *s);
  2672. s->the_bfd = abfd;
  2673. s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
  2674. s->section = glink;
  2675. s->value = glink_vma - glink->vma;
  2676. s->name = names;
  2677. memcpy (names, "__glink", sizeof ("__glink"));
  2678. names += sizeof ("__glink");
  2679. s++;
  2680. count++;
  2681. if (resolv_vma)
  2682. {
  2683. /* Add a symbol for the glink PLT resolver. */
  2684. memset (s, 0, sizeof *s);
  2685. s->the_bfd = abfd;
  2686. s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
  2687. s->section = glink;
  2688. s->value = resolv_vma - glink->vma;
  2689. s->name = names;
  2690. memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
  2691. names += sizeof ("__glink_PLTresolve");
  2692. s++;
  2693. count++;
  2694. }
  2695. return count;
  2696. }
  2697. /* The following functions are specific to the ELF linker, while
  2698. functions above are used generally. They appear in this file more
  2699. or less in the order in which they are called. eg.
  2700. ppc_elf_check_relocs is called early in the link process,
  2701. ppc_elf_finish_dynamic_sections is one of the last functions
  2702. called. */
  2703. /* Track PLT entries needed for a given symbol. We might need more
  2704. than one glink entry per symbol when generating a pic binary. */
  2705. struct plt_entry
  2706. {
  2707. struct plt_entry *next;
  2708. /* -fPIC uses multiple GOT sections, one per file, called ".got2".
  2709. This field stores the offset into .got2 used to initialise the
  2710. GOT pointer reg. It will always be at least 32768. (Current
  2711. gcc always uses an offset of 32768, but ld -r will pack .got2
  2712. sections together resulting in larger offsets). */
  2713. bfd_vma addend;
  2714. /* The .got2 section. */
  2715. asection *sec;
  2716. /* PLT refcount or offset. */
  2717. union
  2718. {
  2719. bfd_signed_vma refcount;
  2720. bfd_vma offset;
  2721. } plt;
  2722. /* .glink stub offset. */
  2723. bfd_vma glink_offset;
  2724. };
  2725. /* Of those relocs that might be copied as dynamic relocs, this function
  2726. selects those that must be copied when linking a shared library,
  2727. even when the symbol is local. */
  2728. static int
  2729. must_be_dyn_reloc (struct bfd_link_info *info,
  2730. enum elf_ppc_reloc_type r_type)
  2731. {
  2732. switch (r_type)
  2733. {
  2734. default:
  2735. return 1;
  2736. case R_PPC_REL24:
  2737. case R_PPC_REL14:
  2738. case R_PPC_REL14_BRTAKEN:
  2739. case R_PPC_REL14_BRNTAKEN:
  2740. case R_PPC_REL32:
  2741. return 0;
  2742. case R_PPC_TPREL32:
  2743. case R_PPC_TPREL16:
  2744. case R_PPC_TPREL16_LO:
  2745. case R_PPC_TPREL16_HI:
  2746. case R_PPC_TPREL16_HA:
  2747. return !bfd_link_executable (info);
  2748. }
  2749. }
  2750. /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
  2751. copying dynamic variables from a shared lib into an app's dynbss
  2752. section, and instead use a dynamic relocation to point into the
  2753. shared lib. */
  2754. #define ELIMINATE_COPY_RELOCS 1
  2755. /* Used to track dynamic relocations for local symbols. */
  2756. struct ppc_dyn_relocs
  2757. {
  2758. struct ppc_dyn_relocs *next;
  2759. /* The input section of the reloc. */
  2760. asection *sec;
  2761. /* Total number of relocs copied for the input section. */
  2762. unsigned int count : 31;
  2763. /* Whether this entry is for STT_GNU_IFUNC symbols. */
  2764. unsigned int ifunc : 1;
  2765. };
  2766. /* PPC ELF linker hash entry. */
  2767. struct ppc_elf_link_hash_entry
  2768. {
  2769. struct elf_link_hash_entry elf;
  2770. /* If this symbol is used in the linker created sections, the processor
  2771. specific backend uses this field to map the field into the offset
  2772. from the beginning of the section. */
  2773. elf_linker_section_pointers_t *linker_section_pointer;
  2774. /* Track dynamic relocs copied for this symbol. */
  2775. struct elf_dyn_relocs *dyn_relocs;
  2776. /* Contexts in which symbol is used in the GOT (or TOC).
  2777. TLS_GD .. TLS_TLS bits are or'd into the mask as the
  2778. corresponding relocs are encountered during check_relocs.
  2779. tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
  2780. indicate the corresponding GOT entry type is not needed. */
  2781. #define TLS_GD 1 /* GD reloc. */
  2782. #define TLS_LD 2 /* LD reloc. */
  2783. #define TLS_TPREL 4 /* TPREL reloc, => IE. */
  2784. #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
  2785. #define TLS_TLS 16 /* Any TLS reloc. */
  2786. #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
  2787. #define PLT_IFUNC 64 /* STT_GNU_IFUNC. */
  2788. char tls_mask;
  2789. /* Nonzero if we have seen a small data relocation referring to this
  2790. symbol. */
  2791. unsigned char has_sda_refs : 1;
  2792. /* Flag use of given relocations. */
  2793. unsigned char has_addr16_ha : 1;
  2794. unsigned char has_addr16_lo : 1;
  2795. };
  2796. #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
  2797. /* PPC ELF linker hash table. */
  2798. struct ppc_elf_link_hash_table
  2799. {
  2800. struct elf_link_hash_table elf;
  2801. /* Various options passed from the linker. */
  2802. struct ppc_elf_params *params;
  2803. /* Short-cuts to get to dynamic linker sections. */
  2804. asection *got;
  2805. asection *relgot;
  2806. asection *glink;
  2807. asection *plt;
  2808. asection *relplt;
  2809. asection *iplt;
  2810. asection *reliplt;
  2811. asection *dynbss;
  2812. asection *relbss;
  2813. asection *dynsbss;
  2814. asection *relsbss;
  2815. elf_linker_section_t sdata[2];
  2816. asection *sbss;
  2817. asection *glink_eh_frame;
  2818. /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */
  2819. asection *srelplt2;
  2820. /* The .got.plt section (VxWorks only)*/
  2821. asection *sgotplt;
  2822. /* Shortcut to __tls_get_addr. */
  2823. struct elf_link_hash_entry *tls_get_addr;
  2824. /* The bfd that forced an old-style PLT. */
  2825. bfd *old_bfd;
  2826. /* TLS local dynamic got entry handling. */
  2827. union {
  2828. bfd_signed_vma refcount;
  2829. bfd_vma offset;
  2830. } tlsld_got;
  2831. /* Offset of branch table to PltResolve function in glink. */
  2832. bfd_vma glink_pltresolve;
  2833. /* Size of reserved GOT entries. */
  2834. unsigned int got_header_size;
  2835. /* Non-zero if allocating the header left a gap. */
  2836. unsigned int got_gap;
  2837. /* The type of PLT we have chosen to use. */
  2838. enum ppc_elf_plt_type plt_type;
  2839. /* True if the target system is VxWorks. */
  2840. unsigned int is_vxworks:1;
  2841. /* The size of PLT entries. */
  2842. int plt_entry_size;
  2843. /* The distance between adjacent PLT slots. */
  2844. int plt_slot_size;
  2845. /* The size of the first PLT entry. */
  2846. int plt_initial_entry_size;
  2847. /* Small local sym cache. */
  2848. struct sym_cache sym_cache;
  2849. };
  2850. /* Rename some of the generic section flags to better document how they
  2851. are used for ppc32. The flags are only valid for ppc32 elf objects. */
  2852. /* Nonzero if this section has TLS related relocations. */
  2853. #define has_tls_reloc sec_flg0
  2854. /* Nonzero if this section has a call to __tls_get_addr. */
  2855. #define has_tls_get_addr_call sec_flg1
  2856. /* Get the PPC ELF linker hash table from a link_info structure. */
  2857. #define ppc_elf_hash_table(p) \
  2858. (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
  2859. == PPC32_ELF_DATA ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL)
  2860. /* Create an entry in a PPC ELF linker hash table. */
  2861. static struct bfd_hash_entry *
  2862. ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
  2863. struct bfd_hash_table *table,
  2864. const char *string)
  2865. {
  2866. /* Allocate the structure if it has not already been allocated by a
  2867. subclass. */
  2868. if (entry == NULL)
  2869. {
  2870. entry = bfd_hash_allocate (table,
  2871. sizeof (struct ppc_elf_link_hash_entry));
  2872. if (entry == NULL)
  2873. return entry;
  2874. }
  2875. /* Call the allocation method of the superclass. */
  2876. entry = _bfd_elf_link_hash_newfunc (entry, table, string);
  2877. if (entry != NULL)
  2878. {
  2879. ppc_elf_hash_entry (entry)->linker_section_pointer = NULL;
  2880. ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
  2881. ppc_elf_hash_entry (entry)->tls_mask = 0;
  2882. ppc_elf_hash_entry (entry)->has_sda_refs = 0;
  2883. }
  2884. return entry;
  2885. }
  2886. /* Create a PPC ELF linker hash table. */
  2887. static struct bfd_link_hash_table *
  2888. ppc_elf_link_hash_table_create (bfd *abfd)
  2889. {
  2890. struct ppc_elf_link_hash_table *ret;
  2891. static struct ppc_elf_params default_params = { PLT_OLD, 0, 1, 0, 0, 12, 0 };
  2892. ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
  2893. if (ret == NULL)
  2894. return NULL;
  2895. if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
  2896. ppc_elf_link_hash_newfunc,
  2897. sizeof (struct ppc_elf_link_hash_entry),
  2898. PPC32_ELF_DATA))
  2899. {
  2900. free (ret);
  2901. return NULL;
  2902. }
  2903. ret->elf.init_plt_refcount.refcount = 0;
  2904. ret->elf.init_plt_refcount.glist = NULL;
  2905. ret->elf.init_plt_offset.offset = 0;
  2906. ret->elf.init_plt_offset.glist = NULL;
  2907. ret->params = &default_params;
  2908. ret->sdata[0].name = ".sdata";
  2909. ret->sdata[0].sym_name = "_SDA_BASE_";
  2910. ret->sdata[0].bss_name = ".sbss";
  2911. ret->sdata[1].name = ".sdata2";
  2912. ret->sdata[1].sym_name = "_SDA2_BASE_";
  2913. ret->sdata[1].bss_name = ".sbss2";
  2914. ret->plt_entry_size = 12;
  2915. ret->plt_slot_size = 8;
  2916. ret->plt_initial_entry_size = 72;
  2917. return &ret->elf.root;
  2918. }
  2919. /* Hook linker params into hash table. */
  2920. void
  2921. ppc_elf_link_params (struct bfd_link_info *info, struct ppc_elf_params *params)
  2922. {
  2923. struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
  2924. if (htab)
  2925. htab->params = params;
  2926. }
  2927. /* Create .got and the related sections. */
  2928. static bfd_boolean
  2929. ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info)
  2930. {
  2931. struct ppc_elf_link_hash_table *htab;
  2932. asection *s;
  2933. flagword flags;
  2934. if (!_bfd_elf_create_got_section (abfd, info))
  2935. return FALSE;
  2936. htab = ppc_elf_hash_table (info);
  2937. htab->got = s = bfd_get_linker_section (abfd, ".got");
  2938. if (s == NULL)
  2939. abort ();
  2940. if (htab->is_vxworks)
  2941. {
  2942. htab->sgotplt = bfd_get_linker_section (abfd, ".got.plt");
  2943. if (!htab->sgotplt)
  2944. abort ();
  2945. }
  2946. else
  2947. {
  2948. /* The powerpc .got has a blrl instruction in it. Mark it
  2949. executable. */
  2950. flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS
  2951. | SEC_IN_MEMORY | SEC_LINKER_CREATED);
  2952. if (!bfd_set_section_flags (abfd, s, flags))
  2953. return FALSE;
  2954. }
  2955. htab->relgot = bfd_get_linker_section (abfd, ".rela.got");
  2956. if (!htab->relgot)
  2957. abort ();
  2958. return TRUE;
  2959. }
  2960. /* Create a special linker section, used for R_PPC_EMB_SDAI16 and
  2961. R_PPC_EMB_SDA2I16 pointers. These sections become part of .sdata
  2962. and .sdata2. Create _SDA_BASE_ and _SDA2_BASE too. */
  2963. static bfd_boolean
  2964. ppc_elf_create_linker_section (bfd *abfd,
  2965. struct bfd_link_info *info,
  2966. flagword flags,
  2967. elf_linker_section_t *lsect)
  2968. {
  2969. asection *s;
  2970. flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
  2971. | SEC_LINKER_CREATED);
  2972. s = bfd_make_section_anyway_with_flags (abfd, lsect->name, flags);
  2973. if (s == NULL)
  2974. return FALSE;
  2975. lsect->section = s;
  2976. /* Define the sym on the first section of this name. */
  2977. s = bfd_get_section_by_name (abfd, lsect->name);
  2978. lsect->sym = _bfd_elf_define_linkage_sym (abfd, info, s, lsect->sym_name);
  2979. if (lsect->sym == NULL)
  2980. return FALSE;
  2981. lsect->sym->root.u.def.value = 0x8000;
  2982. return TRUE;
  2983. }
  2984. static bfd_boolean
  2985. ppc_elf_create_glink (bfd *abfd, struct bfd_link_info *info)
  2986. {
  2987. struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
  2988. asection *s;
  2989. flagword flags;
  2990. flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS
  2991. | SEC_IN_MEMORY | SEC_LINKER_CREATED);
  2992. s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags);
  2993. htab->glink = s;
  2994. if (s == NULL
  2995. || !bfd_set_section_alignment (abfd, s,
  2996. htab->params->ppc476_workaround ? 6 : 4))
  2997. return FALSE;
  2998. if (!info->no_ld_generated_unwind_info)
  2999. {
  3000. flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
  3001. | SEC_IN_MEMORY | SEC_LINKER_CREATED);
  3002. s = bfd_make_section_anyway_with_flags (abfd, ".eh_frame", flags);
  3003. htab->glink_eh_frame = s;
  3004. if (s == NULL
  3005. || !bfd_set_section_alignment (abfd, s, 2))
  3006. return FALSE;
  3007. }
  3008. flags = SEC_ALLOC | SEC_LINKER_CREATED;
  3009. s = bfd_make_section_anyway_with_flags (abfd, ".iplt", flags);
  3010. htab->iplt = s;
  3011. if (s == NULL
  3012. || !bfd_set_section_alignment (abfd, s, 4))
  3013. return FALSE;
  3014. flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
  3015. | SEC_IN_MEMORY | SEC_LINKER_CREATED);
  3016. s = bfd_make_section_anyway_with_flags (abfd, ".rela.iplt", flags);
  3017. htab->reliplt = s;
  3018. if (s == NULL
  3019. || ! bfd_set_section_alignment (abfd, s, 2))
  3020. return FALSE;
  3021. if (!ppc_elf_create_linker_section (abfd, info, 0,
  3022. &htab->sdata[0]))
  3023. return FALSE;
  3024. if (!ppc_elf_create_linker_section (abfd, info, SEC_READONLY,
  3025. &htab->sdata[1]))
  3026. return FALSE;
  3027. return TRUE;
  3028. }
  3029. /* We have to create .dynsbss and .rela.sbss here so that they get mapped
  3030. to output sections (just like _bfd_elf_create_dynamic_sections has
  3031. to create .dynbss and .rela.bss). */
  3032. static bfd_boolean
  3033. ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
  3034. {
  3035. struct ppc_elf_link_hash_table *htab;
  3036. asection *s;
  3037. flagword flags;
  3038. htab = ppc_elf_hash_table (info);
  3039. if (htab->got == NULL
  3040. && !ppc_elf_create_got (abfd, info))
  3041. return FALSE;
  3042. if (!_bfd_elf_create_dynamic_sections (abfd, info))
  3043. return FALSE;
  3044. if (htab->glink == NULL
  3045. && !ppc_elf_create_glink (abfd, info))
  3046. return FALSE;
  3047. htab->dynbss = bfd_get_linker_section (abfd, ".dynbss");
  3048. s = bfd_make_section_anyway_with_flags (abfd, ".dynsbss",
  3049. SEC_ALLOC | SEC_LINKER_CREATED);
  3050. htab->dynsbss = s;
  3051. if (s == NULL)
  3052. return FALSE;
  3053. if (! bfd_link_pic (info))
  3054. {
  3055. htab->relbss = bfd_get_linker_section (abfd, ".rela.bss");
  3056. flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
  3057. | SEC_IN_MEMORY | SEC_LINKER_CREATED);
  3058. s = bfd_make_section_anyway_with_flags (abfd, ".rela.sbss", flags);
  3059. htab->relsbss = s;
  3060. if (s == NULL
  3061. || ! bfd_set_section_alignment (abfd, s, 2))
  3062. return FALSE;
  3063. }
  3064. if (htab->is_vxworks
  3065. && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
  3066. return FALSE;
  3067. htab->relplt = bfd_get_linker_section (abfd, ".rela.plt");
  3068. htab->plt = s = bfd_get_linker_section (abfd, ".plt");
  3069. if (s == NULL)
  3070. abort ();
  3071. flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED;
  3072. if (htab->plt_type == PLT_VXWORKS)
  3073. /* The VxWorks PLT is a loaded section with contents. */
  3074. flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY;
  3075. return bfd_set_section_flags (abfd, s, flags);
  3076. }
  3077. /* Copy the extra info we tack onto an elf_link_hash_entry. */
  3078. static void
  3079. ppc_elf_copy_indirect_symbol (struct bfd_link_info *info,
  3080. struct elf_link_hash_entry *dir,
  3081. struct elf_link_hash_entry *ind)
  3082. {
  3083. struct ppc_elf_link_hash_entry *edir, *eind;
  3084. edir = (struct ppc_elf_link_hash_entry *) dir;
  3085. eind = (struct ppc_elf_link_hash_entry *) ind;
  3086. edir->tls_mask |= eind->tls_mask;
  3087. edir->has_sda_refs |= eind->has_sda_refs;
  3088. /* If called to transfer flags for a weakdef during processing
  3089. of elf_adjust_dynamic_symbol, don't copy non_got_ref.
  3090. We clear it ourselves for ELIMINATE_COPY_RELOCS. */
  3091. if (!(ELIMINATE_COPY_RELOCS
  3092. && eind->elf.root.type != bfd_link_hash_indirect
  3093. && edir->elf.dynamic_adjusted))
  3094. edir->elf.non_got_ref |= eind->elf.non_got_ref;
  3095. edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
  3096. edir->elf.ref_regular |= eind->elf.ref_regular;
  3097. edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
  3098. edir->elf.needs_plt |= eind->elf.needs_plt;
  3099. edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed;
  3100. if (eind->dyn_relocs != NULL)
  3101. {
  3102. if (edir->dyn_relocs != NULL)
  3103. {
  3104. struct elf_dyn_relocs **pp;
  3105. struct elf_dyn_relocs *p;
  3106. /* Add reloc counts against the indirect sym to the direct sym
  3107. list. Merge any entries against the same section. */
  3108. for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
  3109. {
  3110. struct elf_dyn_relocs *q;
  3111. for (q = edir->dyn_relocs; q != NULL; q = q->next)
  3112. if (q->sec == p->sec)
  3113. {
  3114. q->pc_count += p->pc_count;
  3115. q->count += p->count;
  3116. *pp = p->next;
  3117. break;
  3118. }
  3119. if (q == NULL)
  3120. pp = &p->next;
  3121. }
  3122. *pp = edir->dyn_relocs;
  3123. }
  3124. edir->dyn_relocs = eind->dyn_relocs;
  3125. eind->dyn_relocs = NULL;
  3126. }
  3127. /* If we were called to copy over info for a weak sym, that's all.
  3128. You might think dyn_relocs need not be copied over; After all,
  3129. both syms will be dynamic or both non-dynamic so we're just
  3130. moving reloc accounting around. However, ELIMINATE_COPY_RELOCS
  3131. code in ppc_elf_adjust_dynamic_symbol needs to check for
  3132. dyn_relocs in read-only sections, and it does so on what is the
  3133. DIR sym here. */
  3134. if (eind->elf.root.type != bfd_link_hash_indirect)
  3135. return;
  3136. /* Copy over the GOT refcount entries that we may have already seen to
  3137. the symbol which just became indirect. */
  3138. edir->elf.got.refcount += eind->elf.got.refcount;
  3139. eind->elf.got.refcount = 0;
  3140. /* And plt entries. */
  3141. if (eind->elf.plt.plist != NULL)
  3142. {
  3143. if (edir->elf.plt.plist != NULL)
  3144. {
  3145. struct plt_entry **entp;
  3146. struct plt_entry *ent;
  3147. for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; )
  3148. {
  3149. struct plt_entry *dent;
  3150. for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next)
  3151. if (dent->sec == ent->sec && dent->addend == ent->addend)
  3152. {
  3153. dent->plt.refcount += ent->plt.refcount;
  3154. *entp = ent->next;
  3155. break;
  3156. }
  3157. if (dent == NULL)
  3158. entp = &ent->next;
  3159. }
  3160. *entp = edir->elf.plt.plist;
  3161. }
  3162. edir->elf.plt.plist = eind->elf.plt.plist;
  3163. eind->elf.plt.plist = NULL;
  3164. }
  3165. if (eind->elf.dynindx != -1)
  3166. {
  3167. if (edir->elf.dynindx != -1)
  3168. _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
  3169. edir->elf.dynstr_index);
  3170. edir->elf.dynindx = eind->elf.dynindx;
  3171. edir->elf.dynstr_index = eind->elf.dynstr_index;
  3172. eind->elf.dynindx = -1;
  3173. eind->elf.dynstr_index = 0;
  3174. }
  3175. }
  3176. /* Hook called by the linker routine which adds symbols from an object
  3177. file. We use it to put .comm items in .sbss, and not .bss. */
  3178. static bfd_boolean
  3179. ppc_elf_add_symbol_hook (bfd *abfd,
  3180. struct bfd_link_info *info,
  3181. Elf_Internal_Sym *sym,
  3182. const char **namep ATTRIBUTE_UNUSED,
  3183. flagword *flagsp ATTRIBUTE_UNUSED,
  3184. asection **secp,
  3185. bfd_vma *valp)
  3186. {
  3187. if (sym->st_shndx == SHN_COMMON
  3188. && !bfd_link_relocatable (info)
  3189. && is_ppc_elf (info->output_bfd)
  3190. && sym->st_size <= elf_gp_size (abfd))
  3191. {
  3192. /* Common symbols less than or equal to -G nn bytes are automatically
  3193. put into .sbss. */
  3194. struct ppc_elf_link_hash_table *htab;
  3195. htab = ppc_elf_hash_table (info);
  3196. if (htab->sbss == NULL)
  3197. {
  3198. flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED;
  3199. if (!htab->elf.dynobj)
  3200. htab->elf.dynobj = abfd;
  3201. htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
  3202. ".sbss",
  3203. flags);
  3204. if (htab->sbss == NULL)
  3205. return FALSE;
  3206. }
  3207. *secp = htab->sbss;
  3208. *valp = sym->st_size;
  3209. }
  3210. if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
  3211. || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
  3212. && (abfd->flags & DYNAMIC) == 0
  3213. && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
  3214. elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
  3215. return TRUE;
  3216. }
  3217. /* Find a linker generated pointer with a given addend and type. */
  3218. static elf_linker_section_pointers_t *
  3219. elf_find_pointer_linker_section
  3220. (elf_linker_section_pointers_t *linker_pointers,
  3221. bfd_vma addend,
  3222. elf_linker_section_t *lsect)
  3223. {
  3224. for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next)
  3225. if (lsect == linker_pointers->lsect && addend == linker_pointers->addend)
  3226. return linker_pointers;
  3227. return NULL;
  3228. }
  3229. /* Allocate a pointer to live in a linker created section. */
  3230. static bfd_boolean
  3231. elf_allocate_pointer_linker_section (bfd *abfd,
  3232. elf_linker_section_t *lsect,
  3233. struct elf_link_hash_entry *h,
  3234. const Elf_Internal_Rela *rel)
  3235. {
  3236. elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL;
  3237. elf_linker_section_pointers_t *linker_section_ptr;
  3238. unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
  3239. bfd_size_type amt;
  3240. BFD_ASSERT (lsect != NULL);
  3241. /* Is this a global symbol? */
  3242. if (h != NULL)
  3243. {
  3244. struct ppc_elf_link_hash_entry *eh;
  3245. /* Has this symbol already been allocated? If so, our work is done. */
  3246. eh = (struct ppc_elf_link_hash_entry *) h;
  3247. if (elf_find_pointer_linker_section (eh->linker_section_pointer,
  3248. rel->r_addend,
  3249. lsect))
  3250. return TRUE;
  3251. ptr_linker_section_ptr = &eh->linker_section_pointer;
  3252. }
  3253. else
  3254. {
  3255. BFD_ASSERT (is_ppc_elf (abfd));
  3256. /* Allocation of a pointer to a local symbol. */
  3257. elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
  3258. /* Allocate a table to hold the local symbols if first time. */
  3259. if (!ptr)
  3260. {
  3261. unsigned int num_symbols = elf_symtab_hdr (abfd).sh_info;
  3262. amt = num_symbols;
  3263. amt *= sizeof (elf_linker_section_pointers_t *);
  3264. ptr = bfd_zalloc (abfd, amt);
  3265. if (!ptr)
  3266. return FALSE;
  3267. elf_local_ptr_offsets (abfd) = ptr;
  3268. }
  3269. /* Has this symbol already been allocated? If so, our work is done. */
  3270. if (elf_find_pointer_linker_section (ptr[r_symndx],
  3271. rel->r_addend,
  3272. lsect))
  3273. return TRUE;
  3274. ptr_linker_section_ptr = &ptr[r_symndx];
  3275. }
  3276. /* Allocate space for a pointer in the linker section, and allocate
  3277. a new pointer record from internal memory. */
  3278. BFD_ASSERT (ptr_linker_section_ptr != NULL);
  3279. amt = sizeof (elf_linker_section_pointers_t);
  3280. linker_section_ptr = bfd_alloc (abfd, amt);
  3281. if (!linker_section_ptr)
  3282. return FALSE;
  3283. linker_section_ptr->next = *ptr_linker_section_ptr;
  3284. linker_section_ptr->addend = rel->r_addend;
  3285. linker_section_ptr->lsect = lsect;
  3286. *ptr_linker_section_ptr = linker_section_ptr;
  3287. if (!bfd_set_section_alignment (lsect->section->owner, lsect->section, 2))
  3288. return FALSE;
  3289. linker_section_ptr->offset = lsect->section->size;
  3290. lsect->section->size += 4;
  3291. #ifdef DEBUG
  3292. fprintf (stderr,
  3293. "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
  3294. lsect->name, (long) linker_section_ptr->offset,
  3295. (long) lsect->section->size);
  3296. #endif
  3297. return TRUE;
  3298. }
  3299. static struct plt_entry **
  3300. update_local_sym_info (bfd *abfd,
  3301. Elf_Internal_Shdr *symtab_hdr,
  3302. unsigned long r_symndx,
  3303. int tls_type)
  3304. {
  3305. bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
  3306. struct plt_entry **local_plt;
  3307. char *local_got_tls_masks;
  3308. if (local_got_refcounts == NULL)
  3309. {
  3310. bfd_size_type size = symtab_hdr->sh_info;
  3311. size *= (sizeof (*local_got_refcounts)
  3312. + sizeof (*local_plt)
  3313. + sizeof (*local_got_tls_masks));
  3314. local_got_refcounts = bfd_zalloc (abfd, size);
  3315. if (local_got_refcounts == NULL)
  3316. return NULL;
  3317. elf_local_got_refcounts (abfd) = local_got_refcounts;
  3318. }
  3319. local_plt = (struct plt_entry **) (local_got_refcounts + symtab_hdr->sh_info);
  3320. local_got_tls_masks = (char *) (local_plt + symtab_hdr->sh_info);
  3321. local_got_tls_masks[r_symndx] |= tls_type;
  3322. if (tls_type != PLT_IFUNC)
  3323. local_got_refcounts[r_symndx] += 1;
  3324. return local_plt + r_symndx;
  3325. }
  3326. static bfd_boolean
  3327. update_plt_info (bfd *abfd, struct plt_entry **plist,
  3328. asection *sec, bfd_vma addend)
  3329. {
  3330. struct plt_entry *ent;
  3331. if (addend < 32768)
  3332. sec = NULL;
  3333. for (ent = *plist; ent != NULL; ent = ent->next)
  3334. if (ent->sec == sec && ent->addend == addend)
  3335. break;
  3336. if (ent == NULL)
  3337. {
  3338. bfd_size_type amt = sizeof (*ent);
  3339. ent = bfd_alloc (abfd, amt);
  3340. if (ent == NULL)
  3341. return FALSE;
  3342. ent->next = *plist;
  3343. ent->sec = sec;
  3344. ent->addend = addend;
  3345. ent->plt.refcount = 0;
  3346. *plist = ent;
  3347. }
  3348. ent->plt.refcount += 1;
  3349. return TRUE;
  3350. }
  3351. static struct plt_entry *
  3352. find_plt_ent (struct plt_entry **plist, asection *sec, bfd_vma addend)
  3353. {
  3354. struct plt_entry *ent;
  3355. if (addend < 32768)
  3356. sec = NULL;
  3357. for (ent = *plist; ent != NULL; ent = ent->next)
  3358. if (ent->sec == sec && ent->addend == addend)
  3359. break;
  3360. return ent;
  3361. }
  3362. static bfd_boolean
  3363. is_branch_reloc (enum elf_ppc_reloc_type r_type)
  3364. {
  3365. return (r_type == R_PPC_PLTREL24
  3366. || r_type == R_PPC_LOCAL24PC
  3367. || r_type == R_PPC_REL24
  3368. || r_type == R_PPC_REL14
  3369. || r_type == R_PPC_REL14_BRTAKEN
  3370. || r_type == R_PPC_REL14_BRNTAKEN
  3371. || r_type == R_PPC_ADDR24
  3372. || r_type == R_PPC_ADDR14
  3373. || r_type == R_PPC_ADDR14_BRTAKEN
  3374. || r_type == R_PPC_ADDR14_BRNTAKEN);
  3375. }
  3376. static void
  3377. bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type)
  3378. {
  3379. (*_bfd_error_handler)
  3380. (_("%B: relocation %s cannot be used when making a shared object"),
  3381. abfd,
  3382. ppc_elf_howto_table[r_type]->name);
  3383. bfd_set_error (bfd_error_bad_value);
  3384. }
  3385. /* Look through the relocs for a section during the first phase, and
  3386. allocate space in the global offset table or procedure linkage
  3387. table. */
  3388. static bfd_boolean
  3389. ppc_elf_check_relocs (bfd *abfd,
  3390. struct bfd_link_info *info,
  3391. asection *sec,
  3392. const Elf_Internal_Rela *relocs)
  3393. {
  3394. struct ppc_elf_link_hash_table *htab;
  3395. Elf_Internal_Shdr *symtab_hdr;
  3396. struct elf_link_hash_entry **sym_hashes;
  3397. const Elf_Internal_Rela *rel;
  3398. const Elf_Internal_Rela *rel_end;
  3399. asection *got2, *sreloc;
  3400. struct elf_link_hash_entry *tga;
  3401. if (bfd_link_relocatable (info))
  3402. return TRUE;
  3403. /* Don't do anything special with non-loaded, non-alloced sections.
  3404. In particular, any relocs in such sections should not affect GOT
  3405. and PLT reference counting (ie. we don't allow them to create GOT
  3406. or PLT entries), there's no possibility or desire to optimize TLS
  3407. relocs, and there's not much point in propagating relocs to shared
  3408. libs that the dynamic linker won't relocate. */
  3409. if ((sec->flags & SEC_ALLOC) == 0)
  3410. return TRUE;
  3411. #ifdef DEBUG
  3412. _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
  3413. sec, abfd);
  3414. #endif
  3415. BFD_ASSERT (is_ppc_elf (abfd));
  3416. /* Initialize howto table if not already done. */
  3417. if (!ppc_elf_howto_table[R_PPC_ADDR32])
  3418. ppc_elf_howto_init ();
  3419. htab = ppc_elf_hash_table (info);
  3420. if (htab->glink == NULL)
  3421. {
  3422. if (htab->elf.dynobj == NULL)
  3423. htab->elf.dynobj = abfd;
  3424. if (!ppc_elf_create_glink (htab->elf.dynobj, info))
  3425. return FALSE;
  3426. }
  3427. tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
  3428. FALSE, FALSE, TRUE);
  3429. symtab_hdr = &elf_symtab_hdr (abfd);
  3430. sym_hashes = elf_sym_hashes (abfd);
  3431. got2 = bfd_get_section_by_name (abfd, ".got2");
  3432. sreloc = NULL;
  3433. rel_end = relocs + sec->reloc_count;
  3434. for (rel = relocs; rel < rel_end; rel++)
  3435. {
  3436. unsigned long r_symndx;
  3437. enum elf_ppc_reloc_type r_type;
  3438. struct elf_link_hash_entry *h;
  3439. int tls_type;
  3440. r_symndx = ELF32_R_SYM (rel->r_info);
  3441. if (r_symndx < symtab_hdr->sh_info)
  3442. h = NULL;
  3443. else
  3444. {
  3445. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  3446. while (h->root.type == bfd_link_hash_indirect
  3447. || h->root.type == bfd_link_hash_warning)
  3448. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  3449. /* PR15323, ref flags aren't set for references in the same
  3450. object. */
  3451. h->root.non_ir_ref = 1;
  3452. }
  3453. /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
  3454. This shows up in particular in an R_PPC_ADDR32 in the eabi
  3455. startup code. */
  3456. if (h != NULL
  3457. && htab->got == NULL
  3458. && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
  3459. {
  3460. if (htab->elf.dynobj == NULL)
  3461. htab->elf.dynobj = abfd;
  3462. if (!ppc_elf_create_got (htab->elf.dynobj, info))
  3463. return FALSE;
  3464. BFD_ASSERT (h == htab->elf.hgot);
  3465. }
  3466. tls_type = 0;
  3467. r_type = ELF32_R_TYPE (rel->r_info);
  3468. if (h == NULL && !htab->is_vxworks)
  3469. {
  3470. Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  3471. abfd, r_symndx);
  3472. if (isym == NULL)
  3473. return FALSE;
  3474. if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
  3475. {
  3476. struct plt_entry **ifunc;
  3477. /* Set PLT_IFUNC flag for this sym, no GOT entry yet. */
  3478. ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
  3479. PLT_IFUNC);
  3480. if (ifunc == NULL)
  3481. return FALSE;
  3482. /* STT_GNU_IFUNC symbols must have a PLT entry;
  3483. In a non-pie executable even when there are
  3484. no plt calls. */
  3485. if (!bfd_link_pic (info)
  3486. || is_branch_reloc (r_type))
  3487. {
  3488. bfd_vma addend = 0;
  3489. if (r_type == R_PPC_PLTREL24)
  3490. {
  3491. ppc_elf_tdata (abfd)->makes_plt_call = 1;
  3492. if (bfd_link_pic (info))
  3493. addend = rel->r_addend;
  3494. }
  3495. if (!update_plt_info (abfd, ifunc, got2, addend))
  3496. return FALSE;
  3497. }
  3498. }
  3499. }
  3500. if (!htab->is_vxworks
  3501. && is_branch_reloc (r_type)
  3502. && h != NULL
  3503. && h == tga)
  3504. {
  3505. if (rel != relocs
  3506. && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD
  3507. || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD))
  3508. /* We have a new-style __tls_get_addr call with a marker
  3509. reloc. */
  3510. ;
  3511. else
  3512. /* Mark this section as having an old-style call. */
  3513. sec->has_tls_get_addr_call = 1;
  3514. }
  3515. switch (r_type)
  3516. {
  3517. case R_PPC_TLSGD:
  3518. case R_PPC_TLSLD:
  3519. /* These special tls relocs tie a call to __tls_get_addr with
  3520. its parameter symbol. */
  3521. break;
  3522. case R_PPC_GOT_TLSLD16:
  3523. case R_PPC_GOT_TLSLD16_LO:
  3524. case R_PPC_GOT_TLSLD16_HI:
  3525. case R_PPC_GOT_TLSLD16_HA:
  3526. tls_type = TLS_TLS | TLS_LD;
  3527. goto dogottls;
  3528. case R_PPC_GOT_TLSGD16:
  3529. case R_PPC_GOT_TLSGD16_LO:
  3530. case R_PPC_GOT_TLSGD16_HI:
  3531. case R_PPC_GOT_TLSGD16_HA:
  3532. tls_type = TLS_TLS | TLS_GD;
  3533. goto dogottls;
  3534. case R_PPC_GOT_TPREL16:
  3535. case R_PPC_GOT_TPREL16_LO:
  3536. case R_PPC_GOT_TPREL16_HI:
  3537. case R_PPC_GOT_TPREL16_HA:
  3538. if (bfd_link_pic (info))
  3539. info->flags |= DF_STATIC_TLS;
  3540. tls_type = TLS_TLS | TLS_TPREL;
  3541. goto dogottls;
  3542. case R_PPC_GOT_DTPREL16:
  3543. case R_PPC_GOT_DTPREL16_LO:
  3544. case R_PPC_GOT_DTPREL16_HI:
  3545. case R_PPC_GOT_DTPREL16_HA:
  3546. tls_type = TLS_TLS | TLS_DTPREL;
  3547. dogottls:
  3548. sec->has_tls_reloc = 1;
  3549. /* Fall thru */
  3550. /* GOT16 relocations */
  3551. case R_PPC_GOT16:
  3552. case R_PPC_GOT16_LO:
  3553. case R_PPC_GOT16_HI:
  3554. case R_PPC_GOT16_HA:
  3555. /* This symbol requires a global offset table entry. */
  3556. if (htab->got == NULL)
  3557. {
  3558. if (htab->elf.dynobj == NULL)
  3559. htab->elf.dynobj = abfd;
  3560. if (!ppc_elf_create_got (htab->elf.dynobj, info))
  3561. return FALSE;
  3562. }
  3563. if (h != NULL)
  3564. {
  3565. h->got.refcount += 1;
  3566. ppc_elf_hash_entry (h)->tls_mask |= tls_type;
  3567. }
  3568. else
  3569. /* This is a global offset table entry for a local symbol. */
  3570. if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
  3571. return FALSE;
  3572. /* We may also need a plt entry if the symbol turns out to be
  3573. an ifunc. */
  3574. if (h != NULL && !bfd_link_pic (info))
  3575. {
  3576. if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
  3577. return FALSE;
  3578. }
  3579. break;
  3580. /* Indirect .sdata relocation. */
  3581. case R_PPC_EMB_SDAI16:
  3582. if (bfd_link_pic (info))
  3583. {
  3584. bad_shared_reloc (abfd, r_type);
  3585. return FALSE;
  3586. }
  3587. htab->sdata[0].sym->ref_regular = 1;
  3588. if (!elf_allocate_pointer_linker_section (abfd, &htab->sdata[0],
  3589. h, rel))
  3590. return FALSE;
  3591. if (h != NULL)
  3592. {
  3593. ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
  3594. h->non_got_ref = TRUE;
  3595. }
  3596. break;
  3597. /* Indirect .sdata2 relocation. */
  3598. case R_PPC_EMB_SDA2I16:
  3599. if (bfd_link_pic (info))
  3600. {
  3601. bad_shared_reloc (abfd, r_type);
  3602. return FALSE;
  3603. }
  3604. htab->sdata[1].sym->ref_regular = 1;
  3605. if (!elf_allocate_pointer_linker_section (abfd, &htab->sdata[1],
  3606. h, rel))
  3607. return FALSE;
  3608. if (h != NULL)
  3609. {
  3610. ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
  3611. h->non_got_ref = TRUE;
  3612. }
  3613. break;
  3614. case R_PPC_SDAREL16:
  3615. htab->sdata[0].sym->ref_regular = 1;
  3616. /* Fall thru */
  3617. case R_PPC_VLE_SDAREL_LO16A:
  3618. case R_PPC_VLE_SDAREL_LO16D:
  3619. case R_PPC_VLE_SDAREL_HI16A:
  3620. case R_PPC_VLE_SDAREL_HI16D:
  3621. case R_PPC_VLE_SDAREL_HA16A:
  3622. case R_PPC_VLE_SDAREL_HA16D:
  3623. if (h != NULL)
  3624. {
  3625. ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
  3626. h->non_got_ref = TRUE;
  3627. }
  3628. break;
  3629. case R_PPC_VLE_REL8:
  3630. case R_PPC_VLE_REL15:
  3631. case R_PPC_VLE_REL24:
  3632. case R_PPC_VLE_LO16A:
  3633. case R_PPC_VLE_LO16D:
  3634. case R_PPC_VLE_HI16A:
  3635. case R_PPC_VLE_HI16D:
  3636. case R_PPC_VLE_HA16A:
  3637. case R_PPC_VLE_HA16D:
  3638. break;
  3639. case R_PPC_EMB_SDA2REL:
  3640. if (bfd_link_pic (info))
  3641. {
  3642. bad_shared_reloc (abfd, r_type);
  3643. return FALSE;
  3644. }
  3645. htab->sdata[1].sym->ref_regular = 1;
  3646. if (h != NULL)
  3647. {
  3648. ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
  3649. h->non_got_ref = TRUE;
  3650. }
  3651. break;
  3652. case R_PPC_VLE_SDA21_LO:
  3653. case R_PPC_VLE_SDA21:
  3654. case R_PPC_EMB_SDA21:
  3655. case R_PPC_EMB_RELSDA:
  3656. if (bfd_link_pic (info))
  3657. {
  3658. bad_shared_reloc (abfd, r_type);
  3659. return FALSE;
  3660. }
  3661. if (h != NULL)
  3662. {
  3663. ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
  3664. h->non_got_ref = TRUE;
  3665. }
  3666. break;
  3667. case R_PPC_EMB_NADDR32:
  3668. case R_PPC_EMB_NADDR16:
  3669. case R_PPC_EMB_NADDR16_LO:
  3670. case R_PPC_EMB_NADDR16_HI:
  3671. case R_PPC_EMB_NADDR16_HA:
  3672. if (bfd_link_pic (info))
  3673. {
  3674. bad_shared_reloc (abfd, r_type);
  3675. return FALSE;
  3676. }
  3677. if (h != NULL)
  3678. h->non_got_ref = TRUE;
  3679. break;
  3680. case R_PPC_PLTREL24:
  3681. if (h == NULL)
  3682. break;
  3683. /* Fall through */
  3684. case R_PPC_PLT32:
  3685. case R_PPC_PLTREL32:
  3686. case R_PPC_PLT16_LO:
  3687. case R_PPC_PLT16_HI:
  3688. case R_PPC_PLT16_HA:
  3689. #ifdef DEBUG
  3690. fprintf (stderr, "Reloc requires a PLT entry\n");
  3691. #endif
  3692. /* This symbol requires a procedure linkage table entry. We
  3693. actually build the entry in finish_dynamic_symbol,
  3694. because this might be a case of linking PIC code without
  3695. linking in any dynamic objects, in which case we don't
  3696. need to generate a procedure linkage table after all. */
  3697. if (h == NULL)
  3698. {
  3699. /* It does not make sense to have a procedure linkage
  3700. table entry for a local symbol. */
  3701. info->callbacks->einfo (_("%P: %H: %s reloc against local symbol\n"),
  3702. abfd, sec, rel->r_offset,
  3703. ppc_elf_howto_table[r_type]->name);
  3704. bfd_set_error (bfd_error_bad_value);
  3705. return FALSE;
  3706. }
  3707. else
  3708. {
  3709. bfd_vma addend = 0;
  3710. if (r_type == R_PPC_PLTREL24)
  3711. {
  3712. ppc_elf_tdata (abfd)->makes_plt_call = 1;
  3713. if (bfd_link_pic (info))
  3714. addend = rel->r_addend;
  3715. }
  3716. h->needs_plt = 1;
  3717. if (!update_plt_info (abfd, &h->plt.plist, got2, addend))
  3718. return FALSE;
  3719. }
  3720. break;
  3721. /* The following relocations don't need to propagate the
  3722. relocation if linking a shared object since they are
  3723. section relative. */
  3724. case R_PPC_SECTOFF:
  3725. case R_PPC_SECTOFF_LO:
  3726. case R_PPC_SECTOFF_HI:
  3727. case R_PPC_SECTOFF_HA:
  3728. case R_PPC_DTPREL16:
  3729. case R_PPC_DTPREL16_LO:
  3730. case R_PPC_DTPREL16_HI:
  3731. case R_PPC_DTPREL16_HA:
  3732. case R_PPC_TOC16:
  3733. break;
  3734. case R_PPC_REL16:
  3735. case R_PPC_REL16_LO:
  3736. case R_PPC_REL16_HI:
  3737. case R_PPC_REL16_HA:
  3738. ppc_elf_tdata (abfd)->has_rel16 = 1;
  3739. break;
  3740. /* These are just markers. */
  3741. case R_PPC_TLS:
  3742. case R_PPC_EMB_MRKREF:
  3743. case R_PPC_NONE:
  3744. case R_PPC_max:
  3745. case R_PPC_RELAX:
  3746. case R_PPC_RELAX_PLT:
  3747. case R_PPC_RELAX_PLTREL24:
  3748. break;
  3749. /* These should only appear in dynamic objects. */
  3750. case R_PPC_COPY:
  3751. case R_PPC_GLOB_DAT:
  3752. case R_PPC_JMP_SLOT:
  3753. case R_PPC_RELATIVE:
  3754. case R_PPC_IRELATIVE:
  3755. break;
  3756. /* These aren't handled yet. We'll report an error later. */
  3757. case R_PPC_ADDR30:
  3758. case R_PPC_EMB_RELSEC16:
  3759. case R_PPC_EMB_RELST_LO:
  3760. case R_PPC_EMB_RELST_HI:
  3761. case R_PPC_EMB_RELST_HA:
  3762. case R_PPC_EMB_BIT_FLD:
  3763. break;
  3764. /* This refers only to functions defined in the shared library. */
  3765. case R_PPC_LOCAL24PC:
  3766. if (h != NULL && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
  3767. {
  3768. htab->plt_type = PLT_OLD;
  3769. htab->old_bfd = abfd;
  3770. }
  3771. if (h != NULL && h->type == STT_GNU_IFUNC)
  3772. {
  3773. if (bfd_link_pic (info))
  3774. {
  3775. info->callbacks->einfo (_("%P: %H: @local call to ifunc %s\n"),
  3776. abfd, sec, rel->r_offset,
  3777. h->root.root.string);
  3778. bfd_set_error (bfd_error_bad_value);
  3779. return FALSE;
  3780. }
  3781. h->needs_plt = 1;
  3782. if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
  3783. return FALSE;
  3784. }
  3785. break;
  3786. /* This relocation describes the C++ object vtable hierarchy.
  3787. Reconstruct it for later use during GC. */
  3788. case R_PPC_GNU_VTINHERIT:
  3789. if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  3790. return FALSE;
  3791. break;
  3792. /* This relocation describes which C++ vtable entries are actually
  3793. used. Record for later use during GC. */
  3794. case R_PPC_GNU_VTENTRY:
  3795. BFD_ASSERT (h != NULL);
  3796. if (h != NULL
  3797. && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  3798. return FALSE;
  3799. break;
  3800. /* We shouldn't really be seeing these. */
  3801. case R_PPC_TPREL32:
  3802. case R_PPC_TPREL16:
  3803. case R_PPC_TPREL16_LO:
  3804. case R_PPC_TPREL16_HI:
  3805. case R_PPC_TPREL16_HA:
  3806. if (bfd_link_pic (info))
  3807. info->flags |= DF_STATIC_TLS;
  3808. goto dodyn;
  3809. /* Nor these. */
  3810. case R_PPC_DTPMOD32:
  3811. case R_PPC_DTPREL32:
  3812. goto dodyn;
  3813. case R_PPC_REL32:
  3814. if (h == NULL
  3815. && got2 != NULL
  3816. && (sec->flags & SEC_CODE) != 0
  3817. && bfd_link_pic (info)
  3818. && htab->plt_type == PLT_UNSET)
  3819. {
  3820. /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
  3821. the start of a function, which assembles to a REL32
  3822. reference to .got2. If we detect one of these, then
  3823. force the old PLT layout because the linker cannot
  3824. reliably deduce the GOT pointer value needed for
  3825. PLT call stubs. */
  3826. asection *s;
  3827. Elf_Internal_Sym *isym;
  3828. isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  3829. abfd, r_symndx);
  3830. if (isym == NULL)
  3831. return FALSE;
  3832. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  3833. if (s == got2)
  3834. {
  3835. htab->plt_type = PLT_OLD;
  3836. htab->old_bfd = abfd;
  3837. }
  3838. }
  3839. if (h == NULL || h == htab->elf.hgot)
  3840. break;
  3841. /* fall through */
  3842. case R_PPC_ADDR32:
  3843. case R_PPC_ADDR16:
  3844. case R_PPC_ADDR16_LO:
  3845. case R_PPC_ADDR16_HI:
  3846. case R_PPC_ADDR16_HA:
  3847. case R_PPC_UADDR32:
  3848. case R_PPC_UADDR16:
  3849. if (h != NULL && !bfd_link_pic (info))
  3850. {
  3851. /* We may need a plt entry if the symbol turns out to be
  3852. a function defined in a dynamic object. */
  3853. if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
  3854. return FALSE;
  3855. /* We may need a copy reloc too. */
  3856. h->non_got_ref = 1;
  3857. h->pointer_equality_needed = 1;
  3858. if (r_type == R_PPC_ADDR16_HA)
  3859. ppc_elf_hash_entry (h)->has_addr16_ha = 1;
  3860. if (r_type == R_PPC_ADDR16_LO)
  3861. ppc_elf_hash_entry (h)->has_addr16_lo = 1;
  3862. }
  3863. goto dodyn;
  3864. case R_PPC_REL24:
  3865. case R_PPC_REL14:
  3866. case R_PPC_REL14_BRTAKEN:
  3867. case R_PPC_REL14_BRNTAKEN:
  3868. if (h == NULL)
  3869. break;
  3870. if (h == htab->elf.hgot)
  3871. {
  3872. if (htab->plt_type == PLT_UNSET)
  3873. {
  3874. htab->plt_type = PLT_OLD;
  3875. htab->old_bfd = abfd;
  3876. }
  3877. break;
  3878. }
  3879. /* fall through */
  3880. case R_PPC_ADDR24:
  3881. case R_PPC_ADDR14:
  3882. case R_PPC_ADDR14_BRTAKEN:
  3883. case R_PPC_ADDR14_BRNTAKEN:
  3884. if (h != NULL && !bfd_link_pic (info))
  3885. {
  3886. /* We may need a plt entry if the symbol turns out to be
  3887. a function defined in a dynamic object. */
  3888. h->needs_plt = 1;
  3889. if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
  3890. return FALSE;
  3891. break;
  3892. }
  3893. dodyn:
  3894. /* If we are creating a shared library, and this is a reloc
  3895. against a global symbol, or a non PC relative reloc
  3896. against a local symbol, then we need to copy the reloc
  3897. into the shared library. However, if we are linking with
  3898. -Bsymbolic, we do not need to copy a reloc against a
  3899. global symbol which is defined in an object we are
  3900. including in the link (i.e., DEF_REGULAR is set). At
  3901. this point we have not seen all the input files, so it is
  3902. possible that DEF_REGULAR is not set now but will be set
  3903. later (it is never cleared). In case of a weak definition,
  3904. DEF_REGULAR may be cleared later by a strong definition in
  3905. a shared library. We account for that possibility below by
  3906. storing information in the dyn_relocs field of the hash
  3907. table entry. A similar situation occurs when creating
  3908. shared libraries and symbol visibility changes render the
  3909. symbol local.
  3910. If on the other hand, we are creating an executable, we
  3911. may need to keep relocations for symbols satisfied by a
  3912. dynamic library if we manage to avoid copy relocs for the
  3913. symbol. */
  3914. if ((bfd_link_pic (info)
  3915. && (must_be_dyn_reloc (info, r_type)
  3916. || (h != NULL
  3917. && (!SYMBOLIC_BIND (info, h)
  3918. || h->root.type == bfd_link_hash_defweak
  3919. || !h->def_regular))))
  3920. || (ELIMINATE_COPY_RELOCS
  3921. && !bfd_link_pic (info)
  3922. && h != NULL
  3923. && (h->root.type == bfd_link_hash_defweak
  3924. || !h->def_regular)))
  3925. {
  3926. #ifdef DEBUG
  3927. fprintf (stderr,
  3928. "ppc_elf_check_relocs needs to "
  3929. "create relocation for %s\n",
  3930. (h && h->root.root.string
  3931. ? h->root.root.string : "<unknown>"));
  3932. #endif
  3933. if (sreloc == NULL)
  3934. {
  3935. if (htab->elf.dynobj == NULL)
  3936. htab->elf.dynobj = abfd;
  3937. sreloc = _bfd_elf_make_dynamic_reloc_section
  3938. (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE);
  3939. if (sreloc == NULL)
  3940. return FALSE;
  3941. }
  3942. /* If this is a global symbol, we count the number of
  3943. relocations we need for this symbol. */
  3944. if (h != NULL)
  3945. {
  3946. struct elf_dyn_relocs *p;
  3947. struct elf_dyn_relocs **rel_head;
  3948. rel_head = &ppc_elf_hash_entry (h)->dyn_relocs;
  3949. p = *rel_head;
  3950. if (p == NULL || p->sec != sec)
  3951. {
  3952. p = bfd_alloc (htab->elf.dynobj, sizeof *p);
  3953. if (p == NULL)
  3954. return FALSE;
  3955. p->next = *rel_head;
  3956. *rel_head = p;
  3957. p->sec = sec;
  3958. p->count = 0;
  3959. p->pc_count = 0;
  3960. }
  3961. p->count += 1;
  3962. if (!must_be_dyn_reloc (info, r_type))
  3963. p->pc_count += 1;
  3964. }
  3965. else
  3966. {
  3967. /* Track dynamic relocs needed for local syms too.
  3968. We really need local syms available to do this
  3969. easily. Oh well. */
  3970. struct ppc_dyn_relocs *p;
  3971. struct ppc_dyn_relocs **rel_head;
  3972. bfd_boolean is_ifunc;
  3973. asection *s;
  3974. void *vpp;
  3975. Elf_Internal_Sym *isym;
  3976. isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  3977. abfd, r_symndx);
  3978. if (isym == NULL)
  3979. return FALSE;
  3980. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  3981. if (s == NULL)
  3982. s = sec;
  3983. vpp = &elf_section_data (s)->local_dynrel;
  3984. rel_head = (struct ppc_dyn_relocs **) vpp;
  3985. is_ifunc = ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC;
  3986. p = *rel_head;
  3987. if (p != NULL && p->sec == sec && p->ifunc != is_ifunc)
  3988. p = p->next;
  3989. if (p == NULL || p->sec != sec || p->ifunc != is_ifunc)
  3990. {
  3991. p = bfd_alloc (htab->elf.dynobj, sizeof *p);
  3992. if (p == NULL)
  3993. return FALSE;
  3994. p->next = *rel_head;
  3995. *rel_head = p;
  3996. p->sec = sec;
  3997. p->ifunc = is_ifunc;
  3998. p->count = 0;
  3999. }
  4000. p->count += 1;
  4001. }
  4002. }
  4003. break;
  4004. }
  4005. }
  4006. return TRUE;
  4007. }
  4008. /* Merge object attributes from IBFD into OBFD. Raise an error if
  4009. there are conflicting attributes. */
  4010. static bfd_boolean
  4011. ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
  4012. {
  4013. obj_attribute *in_attr, *in_attrs;
  4014. obj_attribute *out_attr, *out_attrs;
  4015. if (!elf_known_obj_attributes_proc (obfd)[0].i)
  4016. {
  4017. /* This is the first object. Copy the attributes. */
  4018. _bfd_elf_copy_obj_attributes (ibfd, obfd);
  4019. /* Use the Tag_null value to indicate the attributes have been
  4020. initialized. */
  4021. elf_known_obj_attributes_proc (obfd)[0].i = 1;
  4022. return TRUE;
  4023. }
  4024. in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
  4025. out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
  4026. /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge
  4027. non-conflicting ones. */
  4028. in_attr = &in_attrs[Tag_GNU_Power_ABI_FP];
  4029. out_attr = &out_attrs[Tag_GNU_Power_ABI_FP];
  4030. if (in_attr->i != out_attr->i)
  4031. {
  4032. out_attr->type = 1;
  4033. if (out_attr->i == 0)
  4034. out_attr->i = in_attr->i;
  4035. else if (in_attr->i == 0)
  4036. ;
  4037. else if (out_attr->i == 1 && in_attr->i == 2)
  4038. _bfd_error_handler
  4039. (_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd);
  4040. else if (out_attr->i == 1 && in_attr->i == 3)
  4041. _bfd_error_handler
  4042. (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
  4043. obfd, ibfd);
  4044. else if (out_attr->i == 3 && in_attr->i == 1)
  4045. _bfd_error_handler
  4046. (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
  4047. ibfd, obfd);
  4048. else if (out_attr->i == 3 && in_attr->i == 2)
  4049. _bfd_error_handler
  4050. (_("Warning: %B uses soft float, %B uses single-precision hard float"),
  4051. ibfd, obfd);
  4052. else if (out_attr->i == 2 && (in_attr->i == 1 || in_attr->i == 3))
  4053. _bfd_error_handler
  4054. (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd);
  4055. else if (in_attr->i > 3)
  4056. _bfd_error_handler
  4057. (_("Warning: %B uses unknown floating point ABI %d"), ibfd,
  4058. in_attr->i);
  4059. else
  4060. _bfd_error_handler
  4061. (_("Warning: %B uses unknown floating point ABI %d"), obfd,
  4062. out_attr->i);
  4063. }
  4064. /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and
  4065. merge non-conflicting ones. */
  4066. in_attr = &in_attrs[Tag_GNU_Power_ABI_Vector];
  4067. out_attr = &out_attrs[Tag_GNU_Power_ABI_Vector];
  4068. if (in_attr->i != out_attr->i)
  4069. {
  4070. const char *in_abi = NULL, *out_abi = NULL;
  4071. switch (in_attr->i)
  4072. {
  4073. case 1: in_abi = "generic"; break;
  4074. case 2: in_abi = "AltiVec"; break;
  4075. case 3: in_abi = "SPE"; break;
  4076. }
  4077. switch (out_attr->i)
  4078. {
  4079. case 1: out_abi = "generic"; break;
  4080. case 2: out_abi = "AltiVec"; break;
  4081. case 3: out_abi = "SPE"; break;
  4082. }
  4083. out_attr->type = 1;
  4084. if (out_attr->i == 0)
  4085. out_attr->i = in_attr->i;
  4086. else if (in_attr->i == 0)
  4087. ;
  4088. /* For now, allow generic to transition to AltiVec or SPE
  4089. without a warning. If GCC marked files with their stack
  4090. alignment and used don't-care markings for files which are
  4091. not affected by the vector ABI, we could warn about this
  4092. case too. */
  4093. else if (out_attr->i == 1)
  4094. out_attr->i = in_attr->i;
  4095. else if (in_attr->i == 1)
  4096. ;
  4097. else if (in_abi == NULL)
  4098. _bfd_error_handler
  4099. (_("Warning: %B uses unknown vector ABI %d"), ibfd,
  4100. in_attr->i);
  4101. else if (out_abi == NULL)
  4102. _bfd_error_handler
  4103. (_("Warning: %B uses unknown vector ABI %d"), obfd,
  4104. in_attr->i);
  4105. else
  4106. _bfd_error_handler
  4107. (_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""),
  4108. ibfd, obfd, in_abi, out_abi);
  4109. }
  4110. /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes
  4111. and merge non-conflicting ones. */
  4112. in_attr = &in_attrs[Tag_GNU_Power_ABI_Struct_Return];
  4113. out_attr = &out_attrs[Tag_GNU_Power_ABI_Struct_Return];
  4114. if (in_attr->i != out_attr->i)
  4115. {
  4116. out_attr->type = 1;
  4117. if (out_attr->i == 0)
  4118. out_attr->i = in_attr->i;
  4119. else if (in_attr->i == 0)
  4120. ;
  4121. else if (out_attr->i == 1 && in_attr->i == 2)
  4122. _bfd_error_handler
  4123. (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd, ibfd);
  4124. else if (out_attr->i == 2 && in_attr->i == 1)
  4125. _bfd_error_handler
  4126. (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd, obfd);
  4127. else if (in_attr->i > 2)
  4128. _bfd_error_handler
  4129. (_("Warning: %B uses unknown small structure return convention %d"), ibfd,
  4130. in_attr->i);
  4131. else
  4132. _bfd_error_handler
  4133. (_("Warning: %B uses unknown small structure return convention %d"), obfd,
  4134. out_attr->i);
  4135. }
  4136. /* Merge Tag_compatibility attributes and any common GNU ones. */
  4137. _bfd_elf_merge_object_attributes (ibfd, obfd);
  4138. return TRUE;
  4139. }
  4140. /* Merge backend specific data from an object file to the output
  4141. object file when linking. */
  4142. static bfd_boolean
  4143. ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
  4144. {
  4145. flagword old_flags;
  4146. flagword new_flags;
  4147. bfd_boolean error;
  4148. if (!is_ppc_elf (ibfd) || !is_ppc_elf (obfd))
  4149. return TRUE;
  4150. /* Check if we have the same endianness. */
  4151. if (! _bfd_generic_verify_endian_match (ibfd, obfd))
  4152. return FALSE;
  4153. if (!ppc_elf_merge_obj_attributes (ibfd, obfd))
  4154. return FALSE;
  4155. new_flags = elf_elfheader (ibfd)->e_flags;
  4156. old_flags = elf_elfheader (obfd)->e_flags;
  4157. if (!elf_flags_init (obfd))
  4158. {
  4159. /* First call, no flags set. */
  4160. elf_flags_init (obfd) = TRUE;
  4161. elf_elfheader (obfd)->e_flags = new_flags;
  4162. }
  4163. /* Compatible flags are ok. */
  4164. else if (new_flags == old_flags)
  4165. ;
  4166. /* Incompatible flags. */
  4167. else
  4168. {
  4169. /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
  4170. to be linked with either. */
  4171. error = FALSE;
  4172. if ((new_flags & EF_PPC_RELOCATABLE) != 0
  4173. && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
  4174. {
  4175. error = TRUE;
  4176. (*_bfd_error_handler)
  4177. (_("%B: compiled with -mrelocatable and linked with "
  4178. "modules compiled normally"), ibfd);
  4179. }
  4180. else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
  4181. && (old_flags & EF_PPC_RELOCATABLE) != 0)
  4182. {
  4183. error = TRUE;
  4184. (*_bfd_error_handler)
  4185. (_("%B: compiled normally and linked with "
  4186. "modules compiled with -mrelocatable"), ibfd);
  4187. }
  4188. /* The output is -mrelocatable-lib iff both the input files are. */
  4189. if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
  4190. elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
  4191. /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
  4192. but each input file is either -mrelocatable or -mrelocatable-lib. */
  4193. if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
  4194. && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
  4195. && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
  4196. elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
  4197. /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
  4198. any module uses it. */
  4199. elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
  4200. new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
  4201. old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
  4202. /* Warn about any other mismatches. */
  4203. if (new_flags != old_flags)
  4204. {
  4205. error = TRUE;
  4206. (*_bfd_error_handler)
  4207. (_("%B: uses different e_flags (0x%lx) fields "
  4208. "than previous modules (0x%lx)"),
  4209. ibfd, (long) new_flags, (long) old_flags);
  4210. }
  4211. if (error)
  4212. {
  4213. bfd_set_error (bfd_error_bad_value);
  4214. return FALSE;
  4215. }
  4216. }
  4217. return TRUE;
  4218. }
  4219. static void
  4220. ppc_elf_vle_split16 (bfd *output_bfd, bfd_byte *loc,
  4221. bfd_vma value,
  4222. split16_format_type split16_format)
  4223. {
  4224. unsigned int insn, top5;
  4225. insn = bfd_get_32 (output_bfd, loc);
  4226. top5 = value & 0xf800;
  4227. top5 = top5 << (split16_format == split16a_type ? 9 : 5);
  4228. insn |= top5;
  4229. insn |= value & 0x7ff;
  4230. bfd_put_32 (output_bfd, insn, loc);
  4231. }
  4232. /* Choose which PLT scheme to use, and set .plt flags appropriately.
  4233. Returns -1 on error, 0 for old PLT, 1 for new PLT. */
  4234. int
  4235. ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
  4236. struct bfd_link_info *info)
  4237. {
  4238. struct ppc_elf_link_hash_table *htab;
  4239. flagword flags;
  4240. htab = ppc_elf_hash_table (info);
  4241. if (htab->plt_type == PLT_UNSET)
  4242. {
  4243. struct elf_link_hash_entry *h;
  4244. if (htab->params->plt_style == PLT_OLD)
  4245. htab->plt_type = PLT_OLD;
  4246. else if (bfd_link_pic (info)
  4247. && htab->elf.dynamic_sections_created
  4248. && (h = elf_link_hash_lookup (&htab->elf, "_mcount",
  4249. FALSE, FALSE, TRUE)) != NULL
  4250. && (h->type == STT_FUNC
  4251. || h->needs_plt)
  4252. && h->ref_regular
  4253. && !(SYMBOL_CALLS_LOCAL (info, h)
  4254. || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  4255. && h->root.type == bfd_link_hash_undefweak)))
  4256. {
  4257. /* Profiling of shared libs (and pies) is not supported with
  4258. secure plt, because ppc32 does profiling before a
  4259. function prologue and a secure plt pic call stubs needs
  4260. r30 to be set up. */
  4261. htab->plt_type = PLT_OLD;
  4262. }
  4263. else
  4264. {
  4265. bfd *ibfd;
  4266. enum ppc_elf_plt_type plt_type = htab->params->plt_style;
  4267. /* Look through the reloc flags left by ppc_elf_check_relocs.
  4268. Use the old style bss plt if a file makes plt calls
  4269. without using the new relocs, and if ld isn't given
  4270. --secure-plt and we never see REL16 relocs. */
  4271. if (plt_type == PLT_UNSET)
  4272. plt_type = PLT_OLD;
  4273. for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link.next)
  4274. if (is_ppc_elf (ibfd))
  4275. {
  4276. if (ppc_elf_tdata (ibfd)->has_rel16)
  4277. plt_type = PLT_NEW;
  4278. else if (ppc_elf_tdata (ibfd)->makes_plt_call)
  4279. {
  4280. plt_type = PLT_OLD;
  4281. htab->old_bfd = ibfd;
  4282. break;
  4283. }
  4284. }
  4285. htab->plt_type = plt_type;
  4286. }
  4287. }
  4288. if (htab->plt_type == PLT_OLD && htab->params->plt_style == PLT_NEW)
  4289. {
  4290. if (htab->old_bfd != NULL)
  4291. info->callbacks->einfo (_("%P: bss-plt forced due to %B\n"),
  4292. htab->old_bfd);
  4293. else
  4294. info->callbacks->einfo (_("%P: bss-plt forced by profiling\n"));
  4295. }
  4296. BFD_ASSERT (htab->plt_type != PLT_VXWORKS);
  4297. if (htab->plt_type == PLT_NEW)
  4298. {
  4299. flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
  4300. | SEC_IN_MEMORY | SEC_LINKER_CREATED);
  4301. /* The new PLT is a loaded section. */
  4302. if (htab->plt != NULL
  4303. && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags))
  4304. return -1;
  4305. /* The new GOT is not executable. */
  4306. if (htab->got != NULL
  4307. && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags))
  4308. return -1;
  4309. }
  4310. else
  4311. {
  4312. /* Stop an unused .glink section from affecting .text alignment. */
  4313. if (htab->glink != NULL
  4314. && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0))
  4315. return -1;
  4316. }
  4317. return htab->plt_type == PLT_NEW;
  4318. }
  4319. /* Return the section that should be marked against GC for a given
  4320. relocation. */
  4321. static asection *
  4322. ppc_elf_gc_mark_hook (asection *sec,
  4323. struct bfd_link_info *info,
  4324. Elf_Internal_Rela *rel,
  4325. struct elf_link_hash_entry *h,
  4326. Elf_Internal_Sym *sym)
  4327. {
  4328. if (h != NULL)
  4329. switch (ELF32_R_TYPE (rel->r_info))
  4330. {
  4331. case R_PPC_GNU_VTINHERIT:
  4332. case R_PPC_GNU_VTENTRY:
  4333. return NULL;
  4334. }
  4335. return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
  4336. }
  4337. /* Update the got, plt and dynamic reloc reference counts for the
  4338. section being removed. */
  4339. static bfd_boolean
  4340. ppc_elf_gc_sweep_hook (bfd *abfd,
  4341. struct bfd_link_info *info,
  4342. asection *sec,
  4343. const Elf_Internal_Rela *relocs)
  4344. {
  4345. struct ppc_elf_link_hash_table *htab;
  4346. Elf_Internal_Shdr *symtab_hdr;
  4347. struct elf_link_hash_entry **sym_hashes;
  4348. bfd_signed_vma *local_got_refcounts;
  4349. const Elf_Internal_Rela *rel, *relend;
  4350. asection *got2;
  4351. if (bfd_link_relocatable (info))
  4352. return TRUE;
  4353. if ((sec->flags & SEC_ALLOC) == 0)
  4354. return TRUE;
  4355. elf_section_data (sec)->local_dynrel = NULL;
  4356. htab = ppc_elf_hash_table (info);
  4357. symtab_hdr = &elf_symtab_hdr (abfd);
  4358. sym_hashes = elf_sym_hashes (abfd);
  4359. local_got_refcounts = elf_local_got_refcounts (abfd);
  4360. got2 = bfd_get_section_by_name (abfd, ".got2");
  4361. relend = relocs + sec->reloc_count;
  4362. for (rel = relocs; rel < relend; rel++)
  4363. {
  4364. unsigned long r_symndx;
  4365. enum elf_ppc_reloc_type r_type;
  4366. struct elf_link_hash_entry *h = NULL;
  4367. r_symndx = ELF32_R_SYM (rel->r_info);
  4368. if (r_symndx >= symtab_hdr->sh_info)
  4369. {
  4370. struct elf_dyn_relocs **pp, *p;
  4371. struct ppc_elf_link_hash_entry *eh;
  4372. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  4373. while (h->root.type == bfd_link_hash_indirect
  4374. || h->root.type == bfd_link_hash_warning)
  4375. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  4376. eh = (struct ppc_elf_link_hash_entry *) h;
  4377. for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
  4378. if (p->sec == sec)
  4379. {
  4380. /* Everything must go for SEC. */
  4381. *pp = p->next;
  4382. break;
  4383. }
  4384. }
  4385. r_type = ELF32_R_TYPE (rel->r_info);
  4386. if (!htab->is_vxworks
  4387. && h == NULL
  4388. && local_got_refcounts != NULL
  4389. && (!bfd_link_pic (info)
  4390. || is_branch_reloc (r_type)))
  4391. {
  4392. struct plt_entry **local_plt = (struct plt_entry **)
  4393. (local_got_refcounts + symtab_hdr->sh_info);
  4394. char *local_got_tls_masks = (char *)
  4395. (local_plt + symtab_hdr->sh_info);
  4396. if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
  4397. {
  4398. struct plt_entry **ifunc = local_plt + r_symndx;
  4399. bfd_vma addend = 0;
  4400. struct plt_entry *ent;
  4401. if (r_type == R_PPC_PLTREL24 && bfd_link_pic (info))
  4402. addend = rel->r_addend;
  4403. ent = find_plt_ent (ifunc, got2, addend);
  4404. if (ent->plt.refcount > 0)
  4405. ent->plt.refcount -= 1;
  4406. continue;
  4407. }
  4408. }
  4409. switch (r_type)
  4410. {
  4411. case R_PPC_GOT_TLSLD16:
  4412. case R_PPC_GOT_TLSLD16_LO:
  4413. case R_PPC_GOT_TLSLD16_HI:
  4414. case R_PPC_GOT_TLSLD16_HA:
  4415. case R_PPC_GOT_TLSGD16:
  4416. case R_PPC_GOT_TLSGD16_LO:
  4417. case R_PPC_GOT_TLSGD16_HI:
  4418. case R_PPC_GOT_TLSGD16_HA:
  4419. case R_PPC_GOT_TPREL16:
  4420. case R_PPC_GOT_TPREL16_LO:
  4421. case R_PPC_GOT_TPREL16_HI:
  4422. case R_PPC_GOT_TPREL16_HA:
  4423. case R_PPC_GOT_DTPREL16:
  4424. case R_PPC_GOT_DTPREL16_LO:
  4425. case R_PPC_GOT_DTPREL16_HI:
  4426. case R_PPC_GOT_DTPREL16_HA:
  4427. case R_PPC_GOT16:
  4428. case R_PPC_GOT16_LO:
  4429. case R_PPC_GOT16_HI:
  4430. case R_PPC_GOT16_HA:
  4431. if (h != NULL)
  4432. {
  4433. if (h->got.refcount > 0)
  4434. h->got.refcount--;
  4435. if (!bfd_link_pic (info))
  4436. {
  4437. struct plt_entry *ent;
  4438. ent = find_plt_ent (&h->plt.plist, NULL, 0);
  4439. if (ent != NULL && ent->plt.refcount > 0)
  4440. ent->plt.refcount -= 1;
  4441. }
  4442. }
  4443. else if (local_got_refcounts != NULL)
  4444. {
  4445. if (local_got_refcounts[r_symndx] > 0)
  4446. local_got_refcounts[r_symndx]--;
  4447. }
  4448. break;
  4449. case R_PPC_REL24:
  4450. case R_PPC_REL14:
  4451. case R_PPC_REL14_BRTAKEN:
  4452. case R_PPC_REL14_BRNTAKEN:
  4453. case R_PPC_REL32:
  4454. if (h == NULL || h == htab->elf.hgot)
  4455. break;
  4456. /* Fall thru */
  4457. case R_PPC_ADDR32:
  4458. case R_PPC_ADDR24:
  4459. case R_PPC_ADDR16:
  4460. case R_PPC_ADDR16_LO:
  4461. case R_PPC_ADDR16_HI:
  4462. case R_PPC_ADDR16_HA:
  4463. case R_PPC_ADDR14:
  4464. case R_PPC_ADDR14_BRTAKEN:
  4465. case R_PPC_ADDR14_BRNTAKEN:
  4466. case R_PPC_UADDR32:
  4467. case R_PPC_UADDR16:
  4468. if (bfd_link_pic (info))
  4469. break;
  4470. case R_PPC_PLT32:
  4471. case R_PPC_PLTREL24:
  4472. case R_PPC_PLTREL32:
  4473. case R_PPC_PLT16_LO:
  4474. case R_PPC_PLT16_HI:
  4475. case R_PPC_PLT16_HA:
  4476. if (h != NULL)
  4477. {
  4478. bfd_vma addend = 0;
  4479. struct plt_entry *ent;
  4480. if (r_type == R_PPC_PLTREL24 && bfd_link_pic (info))
  4481. addend = rel->r_addend;
  4482. ent = find_plt_ent (&h->plt.plist, got2, addend);
  4483. if (ent != NULL && ent->plt.refcount > 0)
  4484. ent->plt.refcount -= 1;
  4485. }
  4486. break;
  4487. default:
  4488. break;
  4489. }
  4490. }
  4491. return TRUE;
  4492. }
  4493. /* Set plt output section type, htab->tls_get_addr, and call the
  4494. generic ELF tls_setup function. */
  4495. asection *
  4496. ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
  4497. {
  4498. struct ppc_elf_link_hash_table *htab;
  4499. htab = ppc_elf_hash_table (info);
  4500. htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
  4501. FALSE, FALSE, TRUE);
  4502. if (htab->plt_type != PLT_NEW)
  4503. htab->params->no_tls_get_addr_opt = TRUE;
  4504. if (!htab->params->no_tls_get_addr_opt)
  4505. {
  4506. struct elf_link_hash_entry *opt, *tga;
  4507. opt = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt",
  4508. FALSE, FALSE, TRUE);
  4509. if (opt != NULL
  4510. && (opt->root.type == bfd_link_hash_defined
  4511. || opt->root.type == bfd_link_hash_defweak))
  4512. {
  4513. /* If glibc supports an optimized __tls_get_addr call stub,
  4514. signalled by the presence of __tls_get_addr_opt, and we'll
  4515. be calling __tls_get_addr via a plt call stub, then
  4516. make __tls_get_addr point to __tls_get_addr_opt. */
  4517. tga = htab->tls_get_addr;
  4518. if (htab->elf.dynamic_sections_created
  4519. && tga != NULL
  4520. && (tga->type == STT_FUNC
  4521. || tga->needs_plt)
  4522. && !(SYMBOL_CALLS_LOCAL (info, tga)
  4523. || (ELF_ST_VISIBILITY (tga->other) != STV_DEFAULT
  4524. && tga->root.type == bfd_link_hash_undefweak)))
  4525. {
  4526. struct plt_entry *ent;
  4527. for (ent = tga->plt.plist; ent != NULL; ent = ent->next)
  4528. if (ent->plt.refcount > 0)
  4529. break;
  4530. if (ent != NULL)
  4531. {
  4532. tga->root.type = bfd_link_hash_indirect;
  4533. tga->root.u.i.link = &opt->root;
  4534. ppc_elf_copy_indirect_symbol (info, opt, tga);
  4535. if (opt->dynindx != -1)
  4536. {
  4537. /* Use __tls_get_addr_opt in dynamic relocations. */
  4538. opt->dynindx = -1;
  4539. _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
  4540. opt->dynstr_index);
  4541. if (!bfd_elf_link_record_dynamic_symbol (info, opt))
  4542. return FALSE;
  4543. }
  4544. htab->tls_get_addr = opt;
  4545. }
  4546. }
  4547. }
  4548. else
  4549. htab->params->no_tls_get_addr_opt = TRUE;
  4550. }
  4551. if (htab->plt_type == PLT_NEW
  4552. && htab->plt != NULL
  4553. && htab->plt->output_section != NULL)
  4554. {
  4555. elf_section_type (htab->plt->output_section) = SHT_PROGBITS;
  4556. elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE;
  4557. }
  4558. return _bfd_elf_tls_setup (obfd, info);
  4559. }
  4560. /* Return TRUE iff REL is a branch reloc with a global symbol matching
  4561. HASH. */
  4562. static bfd_boolean
  4563. branch_reloc_hash_match (const bfd *ibfd,
  4564. const Elf_Internal_Rela *rel,
  4565. const struct elf_link_hash_entry *hash)
  4566. {
  4567. Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
  4568. enum elf_ppc_reloc_type r_type = ELF32_R_TYPE (rel->r_info);
  4569. unsigned int r_symndx = ELF32_R_SYM (rel->r_info);
  4570. if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type))
  4571. {
  4572. struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
  4573. struct elf_link_hash_entry *h;
  4574. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  4575. while (h->root.type == bfd_link_hash_indirect
  4576. || h->root.type == bfd_link_hash_warning)
  4577. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  4578. if (h == hash)
  4579. return TRUE;
  4580. }
  4581. return FALSE;
  4582. }
  4583. /* Run through all the TLS relocs looking for optimization
  4584. opportunities. */
  4585. bfd_boolean
  4586. ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
  4587. struct bfd_link_info *info)
  4588. {
  4589. bfd *ibfd;
  4590. asection *sec;
  4591. struct ppc_elf_link_hash_table *htab;
  4592. int pass;
  4593. if (!bfd_link_executable (info))
  4594. return TRUE;
  4595. htab = ppc_elf_hash_table (info);
  4596. if (htab == NULL)
  4597. return FALSE;
  4598. /* Make two passes through the relocs. First time check that tls
  4599. relocs involved in setting up a tls_get_addr call are indeed
  4600. followed by such a call. If they are not, don't do any tls
  4601. optimization. On the second pass twiddle tls_mask flags to
  4602. notify relocate_section that optimization can be done, and
  4603. adjust got and plt refcounts. */
  4604. for (pass = 0; pass < 2; ++pass)
  4605. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  4606. {
  4607. Elf_Internal_Sym *locsyms = NULL;
  4608. Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
  4609. asection *got2 = bfd_get_section_by_name (ibfd, ".got2");
  4610. for (sec = ibfd->sections; sec != NULL; sec = sec->next)
  4611. if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
  4612. {
  4613. Elf_Internal_Rela *relstart, *rel, *relend;
  4614. int expecting_tls_get_addr = 0;
  4615. /* Read the relocations. */
  4616. relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
  4617. info->keep_memory);
  4618. if (relstart == NULL)
  4619. return FALSE;
  4620. relend = relstart + sec->reloc_count;
  4621. for (rel = relstart; rel < relend; rel++)
  4622. {
  4623. enum elf_ppc_reloc_type r_type;
  4624. unsigned long r_symndx;
  4625. struct elf_link_hash_entry *h = NULL;
  4626. char *tls_mask;
  4627. char tls_set, tls_clear;
  4628. bfd_boolean is_local;
  4629. bfd_signed_vma *got_count;
  4630. r_symndx = ELF32_R_SYM (rel->r_info);
  4631. if (r_symndx >= symtab_hdr->sh_info)
  4632. {
  4633. struct elf_link_hash_entry **sym_hashes;
  4634. sym_hashes = elf_sym_hashes (ibfd);
  4635. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  4636. while (h->root.type == bfd_link_hash_indirect
  4637. || h->root.type == bfd_link_hash_warning)
  4638. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  4639. }
  4640. is_local = FALSE;
  4641. if (h == NULL
  4642. || !h->def_dynamic)
  4643. is_local = TRUE;
  4644. r_type = ELF32_R_TYPE (rel->r_info);
  4645. /* If this section has old-style __tls_get_addr calls
  4646. without marker relocs, then check that each
  4647. __tls_get_addr call reloc is preceded by a reloc
  4648. that conceivably belongs to the __tls_get_addr arg
  4649. setup insn. If we don't find matching arg setup
  4650. relocs, don't do any tls optimization. */
  4651. if (pass == 0
  4652. && sec->has_tls_get_addr_call
  4653. && h != NULL
  4654. && h == htab->tls_get_addr
  4655. && !expecting_tls_get_addr
  4656. && is_branch_reloc (r_type))
  4657. {
  4658. info->callbacks->minfo ("%H __tls_get_addr lost arg, "
  4659. "TLS optimization disabled\n",
  4660. ibfd, sec, rel->r_offset);
  4661. if (elf_section_data (sec)->relocs != relstart)
  4662. free (relstart);
  4663. return TRUE;
  4664. }
  4665. expecting_tls_get_addr = 0;
  4666. switch (r_type)
  4667. {
  4668. case R_PPC_GOT_TLSLD16:
  4669. case R_PPC_GOT_TLSLD16_LO:
  4670. expecting_tls_get_addr = 1;
  4671. /* Fall thru */
  4672. case R_PPC_GOT_TLSLD16_HI:
  4673. case R_PPC_GOT_TLSLD16_HA:
  4674. /* These relocs should never be against a symbol
  4675. defined in a shared lib. Leave them alone if
  4676. that turns out to be the case. */
  4677. if (!is_local)
  4678. continue;
  4679. /* LD -> LE */
  4680. tls_set = 0;
  4681. tls_clear = TLS_LD;
  4682. break;
  4683. case R_PPC_GOT_TLSGD16:
  4684. case R_PPC_GOT_TLSGD16_LO:
  4685. expecting_tls_get_addr = 1;
  4686. /* Fall thru */
  4687. case R_PPC_GOT_TLSGD16_HI:
  4688. case R_PPC_GOT_TLSGD16_HA:
  4689. if (is_local)
  4690. /* GD -> LE */
  4691. tls_set = 0;
  4692. else
  4693. /* GD -> IE */
  4694. tls_set = TLS_TLS | TLS_TPRELGD;
  4695. tls_clear = TLS_GD;
  4696. break;
  4697. case R_PPC_GOT_TPREL16:
  4698. case R_PPC_GOT_TPREL16_LO:
  4699. case R_PPC_GOT_TPREL16_HI:
  4700. case R_PPC_GOT_TPREL16_HA:
  4701. if (is_local)
  4702. {
  4703. /* IE -> LE */
  4704. tls_set = 0;
  4705. tls_clear = TLS_TPREL;
  4706. break;
  4707. }
  4708. else
  4709. continue;
  4710. case R_PPC_TLSGD:
  4711. case R_PPC_TLSLD:
  4712. expecting_tls_get_addr = 2;
  4713. tls_set = 0;
  4714. tls_clear = 0;
  4715. break;
  4716. default:
  4717. continue;
  4718. }
  4719. if (pass == 0)
  4720. {
  4721. if (!expecting_tls_get_addr
  4722. || (expecting_tls_get_addr == 1
  4723. && !sec->has_tls_get_addr_call))
  4724. continue;
  4725. if (rel + 1 < relend
  4726. && branch_reloc_hash_match (ibfd, rel + 1,
  4727. htab->tls_get_addr))
  4728. continue;
  4729. /* Uh oh, we didn't find the expected call. We
  4730. could just mark this symbol to exclude it
  4731. from tls optimization but it's safer to skip
  4732. the entire optimization. */
  4733. info->callbacks->minfo (_("%H arg lost __tls_get_addr, "
  4734. "TLS optimization disabled\n"),
  4735. ibfd, sec, rel->r_offset);
  4736. if (elf_section_data (sec)->relocs != relstart)
  4737. free (relstart);
  4738. return TRUE;
  4739. }
  4740. if (expecting_tls_get_addr)
  4741. {
  4742. struct plt_entry *ent;
  4743. bfd_vma addend = 0;
  4744. if (bfd_link_pic (info)
  4745. && ELF32_R_TYPE (rel[1].r_info) == R_PPC_PLTREL24)
  4746. addend = rel[1].r_addend;
  4747. ent = find_plt_ent (&htab->tls_get_addr->plt.plist,
  4748. got2, addend);
  4749. if (ent != NULL && ent->plt.refcount > 0)
  4750. ent->plt.refcount -= 1;
  4751. if (expecting_tls_get_addr == 2)
  4752. continue;
  4753. }
  4754. if (h != NULL)
  4755. {
  4756. tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
  4757. got_count = &h->got.refcount;
  4758. }
  4759. else
  4760. {
  4761. bfd_signed_vma *lgot_refs;
  4762. struct plt_entry **local_plt;
  4763. char *lgot_masks;
  4764. if (locsyms == NULL)
  4765. {
  4766. locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
  4767. if (locsyms == NULL)
  4768. locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
  4769. symtab_hdr->sh_info,
  4770. 0, NULL, NULL, NULL);
  4771. if (locsyms == NULL)
  4772. {
  4773. if (elf_section_data (sec)->relocs != relstart)
  4774. free (relstart);
  4775. return FALSE;
  4776. }
  4777. }
  4778. lgot_refs = elf_local_got_refcounts (ibfd);
  4779. if (lgot_refs == NULL)
  4780. abort ();
  4781. local_plt = (struct plt_entry **)
  4782. (lgot_refs + symtab_hdr->sh_info);
  4783. lgot_masks = (char *) (local_plt + symtab_hdr->sh_info);
  4784. tls_mask = &lgot_masks[r_symndx];
  4785. got_count = &lgot_refs[r_symndx];
  4786. }
  4787. if (tls_set == 0)
  4788. {
  4789. /* We managed to get rid of a got entry. */
  4790. if (*got_count > 0)
  4791. *got_count -= 1;
  4792. }
  4793. *tls_mask |= tls_set;
  4794. *tls_mask &= ~tls_clear;
  4795. }
  4796. if (elf_section_data (sec)->relocs != relstart)
  4797. free (relstart);
  4798. }
  4799. if (locsyms != NULL
  4800. && (symtab_hdr->contents != (unsigned char *) locsyms))
  4801. {
  4802. if (!info->keep_memory)
  4803. free (locsyms);
  4804. else
  4805. symtab_hdr->contents = (unsigned char *) locsyms;
  4806. }
  4807. }
  4808. return TRUE;
  4809. }
  4810. /* Return true if we have dynamic relocs that apply to read-only sections. */
  4811. static bfd_boolean
  4812. readonly_dynrelocs (struct elf_link_hash_entry *h)
  4813. {
  4814. struct elf_dyn_relocs *p;
  4815. for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
  4816. {
  4817. asection *s = p->sec->output_section;
  4818. if (s != NULL
  4819. && ((s->flags & (SEC_READONLY | SEC_ALLOC))
  4820. == (SEC_READONLY | SEC_ALLOC)))
  4821. return TRUE;
  4822. }
  4823. return FALSE;
  4824. }
  4825. /* Adjust a symbol defined by a dynamic object and referenced by a
  4826. regular object. The current definition is in some section of the
  4827. dynamic object, but we're not including those sections. We have to
  4828. change the definition to something the rest of the link can
  4829. understand. */
  4830. static bfd_boolean
  4831. ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
  4832. struct elf_link_hash_entry *h)
  4833. {
  4834. struct ppc_elf_link_hash_table *htab;
  4835. asection *s;
  4836. #ifdef DEBUG
  4837. fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
  4838. h->root.root.string);
  4839. #endif
  4840. /* Make sure we know what is going on here. */
  4841. htab = ppc_elf_hash_table (info);
  4842. BFD_ASSERT (htab->elf.dynobj != NULL
  4843. && (h->needs_plt
  4844. || h->type == STT_GNU_IFUNC
  4845. || h->u.weakdef != NULL
  4846. || (h->def_dynamic
  4847. && h->ref_regular
  4848. && !h->def_regular)));
  4849. /* Deal with function syms. */
  4850. if (h->type == STT_FUNC
  4851. || h->type == STT_GNU_IFUNC
  4852. || h->needs_plt)
  4853. {
  4854. /* Clear procedure linkage table information for any symbol that
  4855. won't need a .plt entry. */
  4856. struct plt_entry *ent;
  4857. for (ent = h->plt.plist; ent != NULL; ent = ent->next)
  4858. if (ent->plt.refcount > 0)
  4859. break;
  4860. if (ent == NULL
  4861. || (h->type != STT_GNU_IFUNC
  4862. && (SYMBOL_CALLS_LOCAL (info, h)
  4863. || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  4864. && h->root.type == bfd_link_hash_undefweak))))
  4865. {
  4866. /* A PLT entry is not required/allowed when:
  4867. 1. We are not using ld.so; because then the PLT entry
  4868. can't be set up, so we can't use one. In this case,
  4869. ppc_elf_adjust_dynamic_symbol won't even be called.
  4870. 2. GC has rendered the entry unused.
  4871. 3. We know for certain that a call to this symbol
  4872. will go to this object, or will remain undefined. */
  4873. h->plt.plist = NULL;
  4874. h->needs_plt = 0;
  4875. h->pointer_equality_needed = 0;
  4876. }
  4877. else
  4878. {
  4879. /* Taking a function's address in a read/write section
  4880. doesn't require us to define the function symbol in the
  4881. executable on a plt call stub. A dynamic reloc can
  4882. be used instead. */
  4883. if (h->pointer_equality_needed
  4884. && h->type != STT_GNU_IFUNC
  4885. && !htab->is_vxworks
  4886. && !ppc_elf_hash_entry (h)->has_sda_refs
  4887. && !readonly_dynrelocs (h))
  4888. {
  4889. h->pointer_equality_needed = 0;
  4890. h->non_got_ref = 0;
  4891. }
  4892. /* After adjust_dynamic_symbol, non_got_ref set in the
  4893. non-shared case means that we have allocated space in
  4894. .dynbss for the symbol and thus dyn_relocs for this
  4895. symbol should be discarded.
  4896. If we get here we know we are making a PLT entry for this
  4897. symbol, and in an executable we'd normally resolve
  4898. relocations against this symbol to the PLT entry. Allow
  4899. dynamic relocs if the reference is weak, and the dynamic
  4900. relocs will not cause text relocation. */
  4901. else if (!h->ref_regular_nonweak
  4902. && h->non_got_ref
  4903. && h->type != STT_GNU_IFUNC
  4904. && !htab->is_vxworks
  4905. && !ppc_elf_hash_entry (h)->has_sda_refs
  4906. && !readonly_dynrelocs (h))
  4907. h->non_got_ref = 0;
  4908. }
  4909. h->protected_def = 0;
  4910. return TRUE;
  4911. }
  4912. else
  4913. h->plt.plist = NULL;
  4914. /* If this is a weak symbol, and there is a real definition, the
  4915. processor independent code will have arranged for us to see the
  4916. real definition first, and we can just use the same value. */
  4917. if (h->u.weakdef != NULL)
  4918. {
  4919. BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
  4920. || h->u.weakdef->root.type == bfd_link_hash_defweak);
  4921. h->root.u.def.section = h->u.weakdef->root.u.def.section;
  4922. h->root.u.def.value = h->u.weakdef->root.u.def.value;
  4923. if (ELIMINATE_COPY_RELOCS)
  4924. h->non_got_ref = h->u.weakdef->non_got_ref;
  4925. return TRUE;
  4926. }
  4927. /* This is a reference to a symbol defined by a dynamic object which
  4928. is not a function. */
  4929. /* If we are creating a shared library, we must presume that the
  4930. only references to the symbol are via the global offset table.
  4931. For such cases we need not do anything here; the relocations will
  4932. be handled correctly by relocate_section. */
  4933. if (bfd_link_pic (info))
  4934. {
  4935. h->protected_def = 0;
  4936. return TRUE;
  4937. }
  4938. /* If there are no references to this symbol that do not use the
  4939. GOT, we don't need to generate a copy reloc. */
  4940. if (!h->non_got_ref)
  4941. {
  4942. h->protected_def = 0;
  4943. return TRUE;
  4944. }
  4945. /* Protected variables do not work with .dynbss. The copy in
  4946. .dynbss won't be used by the shared library with the protected
  4947. definition for the variable. Editing to PIC, or text relocations
  4948. are preferable to an incorrect program. */
  4949. if (h->protected_def)
  4950. {
  4951. if (ELIMINATE_COPY_RELOCS
  4952. && ppc_elf_hash_entry (h)->has_addr16_ha
  4953. && ppc_elf_hash_entry (h)->has_addr16_lo
  4954. && htab->params->pic_fixup == 0
  4955. && info->disable_target_specific_optimizations <= 1)
  4956. htab->params->pic_fixup = 1;
  4957. h->non_got_ref = 0;
  4958. return TRUE;
  4959. }
  4960. /* If -z nocopyreloc was given, we won't generate them either. */
  4961. if (info->nocopyreloc)
  4962. {
  4963. h->non_got_ref = 0;
  4964. return TRUE;
  4965. }
  4966. /* If we didn't find any dynamic relocs in read-only sections, then
  4967. we'll be keeping the dynamic relocs and avoiding the copy reloc.
  4968. We can't do this if there are any small data relocations. This
  4969. doesn't work on VxWorks, where we can not have dynamic
  4970. relocations (other than copy and jump slot relocations) in an
  4971. executable. */
  4972. if (ELIMINATE_COPY_RELOCS
  4973. && !ppc_elf_hash_entry (h)->has_sda_refs
  4974. && !htab->is_vxworks
  4975. && !h->def_regular
  4976. && !readonly_dynrelocs (h))
  4977. {
  4978. h->non_got_ref = 0;
  4979. return TRUE;
  4980. }
  4981. /* We must allocate the symbol in our .dynbss section, which will
  4982. become part of the .bss section of the executable. There will be
  4983. an entry for this symbol in the .dynsym section. The dynamic
  4984. object will contain position independent code, so all references
  4985. from the dynamic object to this symbol will go through the global
  4986. offset table. The dynamic linker will use the .dynsym entry to
  4987. determine the address it must put in the global offset table, so
  4988. both the dynamic object and the regular object will refer to the
  4989. same memory location for the variable.
  4990. Of course, if the symbol is referenced using SDAREL relocs, we
  4991. must instead allocate it in .sbss. */
  4992. if (ppc_elf_hash_entry (h)->has_sda_refs)
  4993. s = htab->dynsbss;
  4994. else
  4995. s = htab->dynbss;
  4996. BFD_ASSERT (s != NULL);
  4997. /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
  4998. copy the initial value out of the dynamic object and into the
  4999. runtime process image. We need to remember the offset into the
  5000. .rela.bss section we are going to use. */
  5001. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  5002. {
  5003. asection *srel;
  5004. if (ppc_elf_hash_entry (h)->has_sda_refs)
  5005. srel = htab->relsbss;
  5006. else
  5007. srel = htab->relbss;
  5008. BFD_ASSERT (srel != NULL);
  5009. srel->size += sizeof (Elf32_External_Rela);
  5010. h->needs_copy = 1;
  5011. }
  5012. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  5013. }
  5014. /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is
  5015. xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0,
  5016. specifying the addend on the plt relocation. For -fpic code, the sym
  5017. is xxxxxxxx.plt_pic32.<callee>, and for -fPIC
  5018. xxxxxxxx.got2.plt_pic32.<callee>. */
  5019. static bfd_boolean
  5020. add_stub_sym (struct plt_entry *ent,
  5021. struct elf_link_hash_entry *h,
  5022. struct bfd_link_info *info)
  5023. {
  5024. struct elf_link_hash_entry *sh;
  5025. size_t len1, len2, len3;
  5026. char *name;
  5027. const char *stub;
  5028. struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
  5029. if (bfd_link_pic (info))
  5030. stub = ".plt_pic32.";
  5031. else
  5032. stub = ".plt_call32.";
  5033. len1 = strlen (h->root.root.string);
  5034. len2 = strlen (stub);
  5035. len3 = 0;
  5036. if (ent->sec)
  5037. len3 = strlen (ent->sec->name);
  5038. name = bfd_malloc (len1 + len2 + len3 + 9);
  5039. if (name == NULL)
  5040. return FALSE;
  5041. sprintf (name, "%08x", (unsigned) ent->addend & 0xffffffff);
  5042. if (ent->sec)
  5043. memcpy (name + 8, ent->sec->name, len3);
  5044. memcpy (name + 8 + len3, stub, len2);
  5045. memcpy (name + 8 + len3 + len2, h->root.root.string, len1 + 1);
  5046. sh = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
  5047. if (sh == NULL)
  5048. return FALSE;
  5049. if (sh->root.type == bfd_link_hash_new)
  5050. {
  5051. sh->root.type = bfd_link_hash_defined;
  5052. sh->root.u.def.section = htab->glink;
  5053. sh->root.u.def.value = ent->glink_offset;
  5054. sh->ref_regular = 1;
  5055. sh->def_regular = 1;
  5056. sh->ref_regular_nonweak = 1;
  5057. sh->forced_local = 1;
  5058. sh->non_elf = 0;
  5059. sh->root.linker_def = 1;
  5060. }
  5061. return TRUE;
  5062. }
  5063. /* Allocate NEED contiguous space in .got, and return the offset.
  5064. Handles allocation of the got header when crossing 32k. */
  5065. static bfd_vma
  5066. allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
  5067. {
  5068. bfd_vma where;
  5069. unsigned int max_before_header;
  5070. if (htab->plt_type == PLT_VXWORKS)
  5071. {
  5072. where = htab->got->size;
  5073. htab->got->size += need;
  5074. }
  5075. else
  5076. {
  5077. max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764;
  5078. if (need <= htab->got_gap)
  5079. {
  5080. where = max_before_header - htab->got_gap;
  5081. htab->got_gap -= need;
  5082. }
  5083. else
  5084. {
  5085. if (htab->got->size + need > max_before_header
  5086. && htab->got->size <= max_before_header)
  5087. {
  5088. htab->got_gap = max_before_header - htab->got->size;
  5089. htab->got->size = max_before_header + htab->got_header_size;
  5090. }
  5091. where = htab->got->size;
  5092. htab->got->size += need;
  5093. }
  5094. }
  5095. return where;
  5096. }
  5097. /* Allocate space in associated reloc sections for dynamic relocs. */
  5098. static bfd_boolean
  5099. allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
  5100. {
  5101. struct bfd_link_info *info = inf;
  5102. struct ppc_elf_link_hash_entry *eh;
  5103. struct ppc_elf_link_hash_table *htab;
  5104. struct elf_dyn_relocs *p;
  5105. if (h->root.type == bfd_link_hash_indirect)
  5106. return TRUE;
  5107. htab = ppc_elf_hash_table (info);
  5108. if (htab->elf.dynamic_sections_created
  5109. || h->type == STT_GNU_IFUNC)
  5110. {
  5111. struct plt_entry *ent;
  5112. bfd_boolean doneone = FALSE;
  5113. bfd_vma plt_offset = 0, glink_offset = 0;
  5114. bfd_boolean dyn;
  5115. for (ent = h->plt.plist; ent != NULL; ent = ent->next)
  5116. if (ent->plt.refcount > 0)
  5117. {
  5118. /* Make sure this symbol is output as a dynamic symbol. */
  5119. if (h->dynindx == -1
  5120. && !h->forced_local
  5121. && !h->def_regular
  5122. && htab->elf.dynamic_sections_created)
  5123. {
  5124. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  5125. return FALSE;
  5126. }
  5127. dyn = htab->elf.dynamic_sections_created;
  5128. if (bfd_link_pic (info)
  5129. || h->type == STT_GNU_IFUNC
  5130. || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
  5131. {
  5132. asection *s = htab->plt;
  5133. if (!dyn || h->dynindx == -1)
  5134. s = htab->iplt;
  5135. if (htab->plt_type == PLT_NEW || !dyn || h->dynindx == -1)
  5136. {
  5137. if (!doneone)
  5138. {
  5139. plt_offset = s->size;
  5140. s->size += 4;
  5141. }
  5142. ent->plt.offset = plt_offset;
  5143. s = htab->glink;
  5144. if (!doneone || bfd_link_pic (info))
  5145. {
  5146. glink_offset = s->size;
  5147. s->size += GLINK_ENTRY_SIZE;
  5148. if (h == htab->tls_get_addr
  5149. && !htab->params->no_tls_get_addr_opt)
  5150. s->size += TLS_GET_ADDR_GLINK_SIZE - GLINK_ENTRY_SIZE;
  5151. }
  5152. if (!doneone
  5153. && !bfd_link_pic (info)
  5154. && h->def_dynamic
  5155. && !h->def_regular)
  5156. {
  5157. h->root.u.def.section = s;
  5158. h->root.u.def.value = glink_offset;
  5159. }
  5160. ent->glink_offset = glink_offset;
  5161. if (htab->params->emit_stub_syms
  5162. && !add_stub_sym (ent, h, info))
  5163. return FALSE;
  5164. }
  5165. else
  5166. {
  5167. if (!doneone)
  5168. {
  5169. /* If this is the first .plt entry, make room
  5170. for the special first entry. */
  5171. if (s->size == 0)
  5172. s->size += htab->plt_initial_entry_size;
  5173. /* The PowerPC PLT is actually composed of two
  5174. parts, the first part is 2 words (for a load
  5175. and a jump), and then there is a remaining
  5176. word available at the end. */
  5177. plt_offset = (htab->plt_initial_entry_size
  5178. + (htab->plt_slot_size
  5179. * ((s->size
  5180. - htab->plt_initial_entry_size)
  5181. / htab->plt_entry_size)));
  5182. /* If this symbol is not defined in a regular
  5183. file, and we are not generating a shared
  5184. library, then set the symbol to this location
  5185. in the .plt. This is to avoid text
  5186. relocations, and is required to make
  5187. function pointers compare as equal between
  5188. the normal executable and the shared library. */
  5189. if (! bfd_link_pic (info)
  5190. && h->def_dynamic
  5191. && !h->def_regular)
  5192. {
  5193. h->root.u.def.section = s;
  5194. h->root.u.def.value = plt_offset;
  5195. }
  5196. /* Make room for this entry. */
  5197. s->size += htab->plt_entry_size;
  5198. /* After the 8192nd entry, room for two entries
  5199. is allocated. */
  5200. if (htab->plt_type == PLT_OLD
  5201. && (s->size - htab->plt_initial_entry_size)
  5202. / htab->plt_entry_size
  5203. > PLT_NUM_SINGLE_ENTRIES)
  5204. s->size += htab->plt_entry_size;
  5205. }
  5206. ent->plt.offset = plt_offset;
  5207. }
  5208. /* We also need to make an entry in the .rela.plt section. */
  5209. if (!doneone)
  5210. {
  5211. if (!htab->elf.dynamic_sections_created
  5212. || h->dynindx == -1)
  5213. htab->reliplt->size += sizeof (Elf32_External_Rela);
  5214. else
  5215. {
  5216. htab->relplt->size += sizeof (Elf32_External_Rela);
  5217. if (htab->plt_type == PLT_VXWORKS)
  5218. {
  5219. /* Allocate space for the unloaded relocations. */
  5220. if (!bfd_link_pic (info)
  5221. && htab->elf.dynamic_sections_created)
  5222. {
  5223. if (ent->plt.offset
  5224. == (bfd_vma) htab->plt_initial_entry_size)
  5225. {
  5226. htab->srelplt2->size
  5227. += (sizeof (Elf32_External_Rela)
  5228. * VXWORKS_PLTRESOLVE_RELOCS);
  5229. }
  5230. htab->srelplt2->size
  5231. += (sizeof (Elf32_External_Rela)
  5232. * VXWORKS_PLT_NON_JMP_SLOT_RELOCS);
  5233. }
  5234. /* Every PLT entry has an associated GOT entry in
  5235. .got.plt. */
  5236. htab->sgotplt->size += 4;
  5237. }
  5238. }
  5239. doneone = TRUE;
  5240. }
  5241. }
  5242. else
  5243. ent->plt.offset = (bfd_vma) -1;
  5244. }
  5245. else
  5246. ent->plt.offset = (bfd_vma) -1;
  5247. if (!doneone)
  5248. {
  5249. h->plt.plist = NULL;
  5250. h->needs_plt = 0;
  5251. }
  5252. }
  5253. else
  5254. {
  5255. h->plt.plist = NULL;
  5256. h->needs_plt = 0;
  5257. }
  5258. eh = (struct ppc_elf_link_hash_entry *) h;
  5259. if (eh->elf.got.refcount > 0
  5260. || (ELIMINATE_COPY_RELOCS
  5261. && !eh->elf.def_regular
  5262. && eh->elf.protected_def
  5263. && eh->has_addr16_ha
  5264. && eh->has_addr16_lo
  5265. && htab->params->pic_fixup > 0))
  5266. {
  5267. bfd_boolean dyn;
  5268. unsigned int need;
  5269. /* Make sure this symbol is output as a dynamic symbol. */
  5270. if (eh->elf.dynindx == -1
  5271. && !eh->elf.forced_local
  5272. && eh->elf.type != STT_GNU_IFUNC
  5273. && htab->elf.dynamic_sections_created)
  5274. {
  5275. if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
  5276. return FALSE;
  5277. }
  5278. need = 0;
  5279. if ((eh->tls_mask & TLS_TLS) != 0)
  5280. {
  5281. if ((eh->tls_mask & TLS_LD) != 0)
  5282. {
  5283. if (!eh->elf.def_dynamic)
  5284. /* We'll just use htab->tlsld_got.offset. This should
  5285. always be the case. It's a little odd if we have
  5286. a local dynamic reloc against a non-local symbol. */
  5287. htab->tlsld_got.refcount += 1;
  5288. else
  5289. need += 8;
  5290. }
  5291. if ((eh->tls_mask & TLS_GD) != 0)
  5292. need += 8;
  5293. if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
  5294. need += 4;
  5295. if ((eh->tls_mask & TLS_DTPREL) != 0)
  5296. need += 4;
  5297. }
  5298. else
  5299. need += 4;
  5300. if (need == 0)
  5301. eh->elf.got.offset = (bfd_vma) -1;
  5302. else
  5303. {
  5304. eh->elf.got.offset = allocate_got (htab, need);
  5305. dyn = htab->elf.dynamic_sections_created;
  5306. if ((bfd_link_pic (info)
  5307. || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
  5308. && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
  5309. || eh->elf.root.type != bfd_link_hash_undefweak))
  5310. {
  5311. asection *rsec = htab->relgot;
  5312. if (eh->elf.type == STT_GNU_IFUNC)
  5313. rsec = htab->reliplt;
  5314. /* All the entries we allocated need relocs.
  5315. Except LD only needs one. */
  5316. if ((eh->tls_mask & TLS_LD) != 0
  5317. && eh->elf.def_dynamic)
  5318. need -= 4;
  5319. rsec->size += need * (sizeof (Elf32_External_Rela) / 4);
  5320. }
  5321. }
  5322. }
  5323. else
  5324. eh->elf.got.offset = (bfd_vma) -1;
  5325. if (eh->dyn_relocs == NULL
  5326. || !htab->elf.dynamic_sections_created)
  5327. return TRUE;
  5328. /* In the shared -Bsymbolic case, discard space allocated for
  5329. dynamic pc-relative relocs against symbols which turn out to be
  5330. defined in regular objects. For the normal shared case, discard
  5331. space for relocs that have become local due to symbol visibility
  5332. changes. */
  5333. if (bfd_link_pic (info))
  5334. {
  5335. /* Relocs that use pc_count are those that appear on a call insn,
  5336. or certain REL relocs (see must_be_dyn_reloc) that can be
  5337. generated via assembly. We want calls to protected symbols to
  5338. resolve directly to the function rather than going via the plt.
  5339. If people want function pointer comparisons to work as expected
  5340. then they should avoid writing weird assembly. */
  5341. if (SYMBOL_CALLS_LOCAL (info, h))
  5342. {
  5343. struct elf_dyn_relocs **pp;
  5344. for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
  5345. {
  5346. p->count -= p->pc_count;
  5347. p->pc_count = 0;
  5348. if (p->count == 0)
  5349. *pp = p->next;
  5350. else
  5351. pp = &p->next;
  5352. }
  5353. }
  5354. if (htab->is_vxworks)
  5355. {
  5356. struct elf_dyn_relocs **pp;
  5357. for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
  5358. {
  5359. if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
  5360. *pp = p->next;
  5361. else
  5362. pp = &p->next;
  5363. }
  5364. }
  5365. /* Discard relocs on undefined symbols that must be local. */
  5366. if (eh->dyn_relocs != NULL
  5367. && h->root.type == bfd_link_hash_undefined
  5368. && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
  5369. || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
  5370. eh->dyn_relocs = NULL;
  5371. /* Also discard relocs on undefined weak syms with non-default
  5372. visibility. */
  5373. if (eh->dyn_relocs != NULL
  5374. && h->root.type == bfd_link_hash_undefweak)
  5375. {
  5376. if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
  5377. eh->dyn_relocs = NULL;
  5378. /* Make sure undefined weak symbols are output as a dynamic
  5379. symbol in PIEs. */
  5380. else if (h->dynindx == -1
  5381. && !h->forced_local
  5382. && !h->def_regular)
  5383. {
  5384. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  5385. return FALSE;
  5386. }
  5387. }
  5388. }
  5389. else if (ELIMINATE_COPY_RELOCS)
  5390. {
  5391. /* For the non-shared case, discard space for relocs against
  5392. symbols which turn out to need copy relocs or are not
  5393. dynamic. */
  5394. if (!h->non_got_ref
  5395. && !h->def_regular
  5396. && !(h->protected_def
  5397. && eh->has_addr16_ha
  5398. && eh->has_addr16_lo
  5399. && htab->params->pic_fixup > 0))
  5400. {
  5401. /* Make sure this symbol is output as a dynamic symbol.
  5402. Undefined weak syms won't yet be marked as dynamic. */
  5403. if (h->dynindx == -1
  5404. && !h->forced_local)
  5405. {
  5406. if (! bfd_elf_link_record_dynamic_symbol (info, h))
  5407. return FALSE;
  5408. }
  5409. /* If that succeeded, we know we'll be keeping all the
  5410. relocs. */
  5411. if (h->dynindx != -1)
  5412. goto keep;
  5413. }
  5414. eh->dyn_relocs = NULL;
  5415. keep: ;
  5416. }
  5417. /* Finally, allocate space. */
  5418. for (p = eh->dyn_relocs; p != NULL; p = p->next)
  5419. {
  5420. asection *sreloc = elf_section_data (p->sec)->sreloc;
  5421. if (eh->elf.type == STT_GNU_IFUNC)
  5422. sreloc = htab->reliplt;
  5423. sreloc->size += p->count * sizeof (Elf32_External_Rela);
  5424. }
  5425. return TRUE;
  5426. }
  5427. /* Set DF_TEXTREL if we find any dynamic relocs that apply to
  5428. read-only sections. */
  5429. static bfd_boolean
  5430. maybe_set_textrel (struct elf_link_hash_entry *h, void *info)
  5431. {
  5432. if (h->root.type == bfd_link_hash_indirect)
  5433. return TRUE;
  5434. if (readonly_dynrelocs (h))
  5435. {
  5436. ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
  5437. /* Not an error, just cut short the traversal. */
  5438. return FALSE;
  5439. }
  5440. return TRUE;
  5441. }
  5442. static const unsigned char glink_eh_frame_cie[] =
  5443. {
  5444. 0, 0, 0, 16, /* length. */
  5445. 0, 0, 0, 0, /* id. */
  5446. 1, /* CIE version. */
  5447. 'z', 'R', 0, /* Augmentation string. */
  5448. 4, /* Code alignment. */
  5449. 0x7c, /* Data alignment. */
  5450. 65, /* RA reg. */
  5451. 1, /* Augmentation size. */
  5452. DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding. */
  5453. DW_CFA_def_cfa, 1, 0 /* def_cfa: r1 offset 0. */
  5454. };
  5455. /* Set the sizes of the dynamic sections. */
  5456. static bfd_boolean
  5457. ppc_elf_size_dynamic_sections (bfd *output_bfd,
  5458. struct bfd_link_info *info)
  5459. {
  5460. struct ppc_elf_link_hash_table *htab;
  5461. asection *s;
  5462. bfd_boolean relocs;
  5463. bfd *ibfd;
  5464. #ifdef DEBUG
  5465. fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
  5466. #endif
  5467. htab = ppc_elf_hash_table (info);
  5468. BFD_ASSERT (htab->elf.dynobj != NULL);
  5469. if (elf_hash_table (info)->dynamic_sections_created)
  5470. {
  5471. /* Set the contents of the .interp section to the interpreter. */
  5472. if (bfd_link_executable (info) && !info->nointerp)
  5473. {
  5474. s = bfd_get_linker_section (htab->elf.dynobj, ".interp");
  5475. BFD_ASSERT (s != NULL);
  5476. s->size = sizeof ELF_DYNAMIC_INTERPRETER;
  5477. s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
  5478. }
  5479. }
  5480. if (htab->plt_type == PLT_OLD)
  5481. htab->got_header_size = 16;
  5482. else if (htab->plt_type == PLT_NEW)
  5483. htab->got_header_size = 12;
  5484. /* Set up .got offsets for local syms, and space for local dynamic
  5485. relocs. */
  5486. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  5487. {
  5488. bfd_signed_vma *local_got;
  5489. bfd_signed_vma *end_local_got;
  5490. struct plt_entry **local_plt;
  5491. struct plt_entry **end_local_plt;
  5492. char *lgot_masks;
  5493. bfd_size_type locsymcount;
  5494. Elf_Internal_Shdr *symtab_hdr;
  5495. if (!is_ppc_elf (ibfd))
  5496. continue;
  5497. for (s = ibfd->sections; s != NULL; s = s->next)
  5498. {
  5499. struct ppc_dyn_relocs *p;
  5500. for (p = ((struct ppc_dyn_relocs *)
  5501. elf_section_data (s)->local_dynrel);
  5502. p != NULL;
  5503. p = p->next)
  5504. {
  5505. if (!bfd_is_abs_section (p->sec)
  5506. && bfd_is_abs_section (p->sec->output_section))
  5507. {
  5508. /* Input section has been discarded, either because
  5509. it is a copy of a linkonce section or due to
  5510. linker script /DISCARD/, so we'll be discarding
  5511. the relocs too. */
  5512. }
  5513. else if (htab->is_vxworks
  5514. && strcmp (p->sec->output_section->name,
  5515. ".tls_vars") == 0)
  5516. {
  5517. /* Relocations in vxworks .tls_vars sections are
  5518. handled specially by the loader. */
  5519. }
  5520. else if (p->count != 0)
  5521. {
  5522. asection *sreloc = elf_section_data (p->sec)->sreloc;
  5523. if (p->ifunc)
  5524. sreloc = htab->reliplt;
  5525. sreloc->size += p->count * sizeof (Elf32_External_Rela);
  5526. if ((p->sec->output_section->flags
  5527. & (SEC_READONLY | SEC_ALLOC))
  5528. == (SEC_READONLY | SEC_ALLOC))
  5529. info->flags |= DF_TEXTREL;
  5530. }
  5531. }
  5532. }
  5533. local_got = elf_local_got_refcounts (ibfd);
  5534. if (!local_got)
  5535. continue;
  5536. symtab_hdr = &elf_symtab_hdr (ibfd);
  5537. locsymcount = symtab_hdr->sh_info;
  5538. end_local_got = local_got + locsymcount;
  5539. local_plt = (struct plt_entry **) end_local_got;
  5540. end_local_plt = local_plt + locsymcount;
  5541. lgot_masks = (char *) end_local_plt;
  5542. for (; local_got < end_local_got; ++local_got, ++lgot_masks)
  5543. if (*local_got > 0)
  5544. {
  5545. unsigned int need = 0;
  5546. if ((*lgot_masks & TLS_TLS) != 0)
  5547. {
  5548. if ((*lgot_masks & TLS_GD) != 0)
  5549. need += 8;
  5550. if ((*lgot_masks & TLS_LD) != 0)
  5551. htab->tlsld_got.refcount += 1;
  5552. if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
  5553. need += 4;
  5554. if ((*lgot_masks & TLS_DTPREL) != 0)
  5555. need += 4;
  5556. }
  5557. else
  5558. need += 4;
  5559. if (need == 0)
  5560. *local_got = (bfd_vma) -1;
  5561. else
  5562. {
  5563. *local_got = allocate_got (htab, need);
  5564. if (bfd_link_pic (info))
  5565. {
  5566. asection *srel = htab->relgot;
  5567. if ((*lgot_masks & PLT_IFUNC) != 0)
  5568. srel = htab->reliplt;
  5569. srel->size += need * (sizeof (Elf32_External_Rela) / 4);
  5570. }
  5571. }
  5572. }
  5573. else
  5574. *local_got = (bfd_vma) -1;
  5575. if (htab->is_vxworks)
  5576. continue;
  5577. /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
  5578. for (; local_plt < end_local_plt; ++local_plt)
  5579. {
  5580. struct plt_entry *ent;
  5581. bfd_boolean doneone = FALSE;
  5582. bfd_vma plt_offset = 0, glink_offset = 0;
  5583. for (ent = *local_plt; ent != NULL; ent = ent->next)
  5584. if (ent->plt.refcount > 0)
  5585. {
  5586. s = htab->iplt;
  5587. if (!doneone)
  5588. {
  5589. plt_offset = s->size;
  5590. s->size += 4;
  5591. }
  5592. ent->plt.offset = plt_offset;
  5593. s = htab->glink;
  5594. if (!doneone || bfd_link_pic (info))
  5595. {
  5596. glink_offset = s->size;
  5597. s->size += GLINK_ENTRY_SIZE;
  5598. }
  5599. ent->glink_offset = glink_offset;
  5600. if (!doneone)
  5601. {
  5602. htab->reliplt->size += sizeof (Elf32_External_Rela);
  5603. doneone = TRUE;
  5604. }
  5605. }
  5606. else
  5607. ent->plt.offset = (bfd_vma) -1;
  5608. }
  5609. }
  5610. /* Allocate space for global sym dynamic relocs. */
  5611. elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
  5612. if (htab->tlsld_got.refcount > 0)
  5613. {
  5614. htab->tlsld_got.offset = allocate_got (htab, 8);
  5615. if (bfd_link_pic (info))
  5616. htab->relgot->size += sizeof (Elf32_External_Rela);
  5617. }
  5618. else
  5619. htab->tlsld_got.offset = (bfd_vma) -1;
  5620. if (htab->got != NULL && htab->plt_type != PLT_VXWORKS)
  5621. {
  5622. unsigned int g_o_t = 32768;
  5623. /* If we haven't allocated the header, do so now. When we get here,
  5624. for old plt/got the got size will be 0 to 32764 (not allocated),
  5625. or 32780 to 65536 (header allocated). For new plt/got, the
  5626. corresponding ranges are 0 to 32768 and 32780 to 65536. */
  5627. if (htab->got->size <= 32768)
  5628. {
  5629. g_o_t = htab->got->size;
  5630. if (htab->plt_type == PLT_OLD)
  5631. g_o_t += 4;
  5632. htab->got->size += htab->got_header_size;
  5633. }
  5634. htab->elf.hgot->root.u.def.value = g_o_t;
  5635. }
  5636. if (bfd_link_pic (info))
  5637. {
  5638. struct elf_link_hash_entry *sda = htab->sdata[0].sym;
  5639. sda->root.u.def.section = htab->elf.hgot->root.u.def.section;
  5640. sda->root.u.def.value = htab->elf.hgot->root.u.def.value;
  5641. }
  5642. if (info->emitrelocations)
  5643. {
  5644. struct elf_link_hash_entry *sda = htab->sdata[0].sym;
  5645. if (sda != NULL && sda->ref_regular)
  5646. sda->root.u.def.section->flags |= SEC_KEEP;
  5647. sda = htab->sdata[1].sym;
  5648. if (sda != NULL && sda->ref_regular)
  5649. sda->root.u.def.section->flags |= SEC_KEEP;
  5650. }
  5651. if (htab->glink != NULL
  5652. && htab->glink->size != 0
  5653. && htab->elf.dynamic_sections_created)
  5654. {
  5655. htab->glink_pltresolve = htab->glink->size;
  5656. /* Space for the branch table. */
  5657. htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4;
  5658. /* Pad out to align the start of PLTresolve. */
  5659. htab->glink->size += -htab->glink->size & (htab->params->ppc476_workaround
  5660. ? 63 : 15);
  5661. htab->glink->size += GLINK_PLTRESOLVE;
  5662. if (htab->params->emit_stub_syms)
  5663. {
  5664. struct elf_link_hash_entry *sh;
  5665. sh = elf_link_hash_lookup (&htab->elf, "__glink",
  5666. TRUE, FALSE, FALSE);
  5667. if (sh == NULL)
  5668. return FALSE;
  5669. if (sh->root.type == bfd_link_hash_new)
  5670. {
  5671. sh->root.type = bfd_link_hash_defined;
  5672. sh->root.u.def.section = htab->glink;
  5673. sh->root.u.def.value = htab->glink_pltresolve;
  5674. sh->ref_regular = 1;
  5675. sh->def_regular = 1;
  5676. sh->ref_regular_nonweak = 1;
  5677. sh->forced_local = 1;
  5678. sh->non_elf = 0;
  5679. sh->root.linker_def = 1;
  5680. }
  5681. sh = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
  5682. TRUE, FALSE, FALSE);
  5683. if (sh == NULL)
  5684. return FALSE;
  5685. if (sh->root.type == bfd_link_hash_new)
  5686. {
  5687. sh->root.type = bfd_link_hash_defined;
  5688. sh->root.u.def.section = htab->glink;
  5689. sh->root.u.def.value = htab->glink->size - GLINK_PLTRESOLVE;
  5690. sh->ref_regular = 1;
  5691. sh->def_regular = 1;
  5692. sh->ref_regular_nonweak = 1;
  5693. sh->forced_local = 1;
  5694. sh->non_elf = 0;
  5695. sh->root.linker_def = 1;
  5696. }
  5697. }
  5698. }
  5699. if (htab->glink != NULL
  5700. && htab->glink->size != 0
  5701. && htab->glink_eh_frame != NULL
  5702. && !bfd_is_abs_section (htab->glink_eh_frame->output_section)
  5703. && _bfd_elf_eh_frame_present (info))
  5704. {
  5705. s = htab->glink_eh_frame;
  5706. s->size = sizeof (glink_eh_frame_cie) + 20;
  5707. if (bfd_link_pic (info))
  5708. {
  5709. s->size += 4;
  5710. if (htab->glink->size - GLINK_PLTRESOLVE + 8 >= 256)
  5711. s->size += 4;
  5712. }
  5713. }
  5714. /* We've now determined the sizes of the various dynamic sections.
  5715. Allocate memory for them. */
  5716. relocs = FALSE;
  5717. for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
  5718. {
  5719. bfd_boolean strip_section = TRUE;
  5720. if ((s->flags & SEC_LINKER_CREATED) == 0)
  5721. continue;
  5722. if (s == htab->plt
  5723. || s == htab->got)
  5724. {
  5725. /* We'd like to strip these sections if they aren't needed, but if
  5726. we've exported dynamic symbols from them we must leave them.
  5727. It's too late to tell BFD to get rid of the symbols. */
  5728. if (htab->elf.hplt != NULL)
  5729. strip_section = FALSE;
  5730. /* Strip this section if we don't need it; see the
  5731. comment below. */
  5732. }
  5733. else if (s == htab->iplt
  5734. || s == htab->glink
  5735. || s == htab->glink_eh_frame
  5736. || s == htab->sgotplt
  5737. || s == htab->sbss
  5738. || s == htab->dynbss
  5739. || s == htab->dynsbss)
  5740. {
  5741. /* Strip these too. */
  5742. }
  5743. else if (s == htab->sdata[0].section
  5744. || s == htab->sdata[1].section)
  5745. {
  5746. strip_section = (s->flags & SEC_KEEP) == 0;
  5747. }
  5748. else if (CONST_STRNEQ (bfd_get_section_name (htab->elf.dynobj, s),
  5749. ".rela"))
  5750. {
  5751. if (s->size != 0)
  5752. {
  5753. /* Remember whether there are any relocation sections. */
  5754. relocs = TRUE;
  5755. /* We use the reloc_count field as a counter if we need
  5756. to copy relocs into the output file. */
  5757. s->reloc_count = 0;
  5758. }
  5759. }
  5760. else
  5761. {
  5762. /* It's not one of our sections, so don't allocate space. */
  5763. continue;
  5764. }
  5765. if (s->size == 0 && strip_section)
  5766. {
  5767. /* If we don't need this section, strip it from the
  5768. output file. This is mostly to handle .rela.bss and
  5769. .rela.plt. We must create both sections in
  5770. create_dynamic_sections, because they must be created
  5771. before the linker maps input sections to output
  5772. sections. The linker does that before
  5773. adjust_dynamic_symbol is called, and it is that
  5774. function which decides whether anything needs to go
  5775. into these sections. */
  5776. s->flags |= SEC_EXCLUDE;
  5777. continue;
  5778. }
  5779. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  5780. continue;
  5781. /* Allocate memory for the section contents. */
  5782. s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
  5783. if (s->contents == NULL)
  5784. return FALSE;
  5785. }
  5786. if (htab->elf.dynamic_sections_created)
  5787. {
  5788. /* Add some entries to the .dynamic section. We fill in the
  5789. values later, in ppc_elf_finish_dynamic_sections, but we
  5790. must add the entries now so that we get the correct size for
  5791. the .dynamic section. The DT_DEBUG entry is filled in by the
  5792. dynamic linker and used by the debugger. */
  5793. #define add_dynamic_entry(TAG, VAL) \
  5794. _bfd_elf_add_dynamic_entry (info, TAG, VAL)
  5795. if (bfd_link_executable (info))
  5796. {
  5797. if (!add_dynamic_entry (DT_DEBUG, 0))
  5798. return FALSE;
  5799. }
  5800. if (htab->plt != NULL && htab->plt->size != 0)
  5801. {
  5802. if (!add_dynamic_entry (DT_PLTGOT, 0)
  5803. || !add_dynamic_entry (DT_PLTRELSZ, 0)
  5804. || !add_dynamic_entry (DT_PLTREL, DT_RELA)
  5805. || !add_dynamic_entry (DT_JMPREL, 0))
  5806. return FALSE;
  5807. }
  5808. if (htab->plt_type == PLT_NEW
  5809. && htab->glink != NULL
  5810. && htab->glink->size != 0)
  5811. {
  5812. if (!add_dynamic_entry (DT_PPC_GOT, 0))
  5813. return FALSE;
  5814. if (!htab->params->no_tls_get_addr_opt
  5815. && htab->tls_get_addr != NULL
  5816. && htab->tls_get_addr->plt.plist != NULL
  5817. && !add_dynamic_entry (DT_PPC_OPT, PPC_OPT_TLS))
  5818. return FALSE;
  5819. }
  5820. if (relocs)
  5821. {
  5822. if (!add_dynamic_entry (DT_RELA, 0)
  5823. || !add_dynamic_entry (DT_RELASZ, 0)
  5824. || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
  5825. return FALSE;
  5826. }
  5827. /* If any dynamic relocs apply to a read-only section, then we
  5828. need a DT_TEXTREL entry. */
  5829. if ((info->flags & DF_TEXTREL) == 0)
  5830. elf_link_hash_traverse (elf_hash_table (info), maybe_set_textrel,
  5831. info);
  5832. if ((info->flags & DF_TEXTREL) != 0)
  5833. {
  5834. if (!add_dynamic_entry (DT_TEXTREL, 0))
  5835. return FALSE;
  5836. }
  5837. if (htab->is_vxworks
  5838. && !elf_vxworks_add_dynamic_entries (output_bfd, info))
  5839. return FALSE;
  5840. }
  5841. #undef add_dynamic_entry
  5842. if (htab->glink_eh_frame != NULL
  5843. && htab->glink_eh_frame->contents != NULL)
  5844. {
  5845. unsigned char *p = htab->glink_eh_frame->contents;
  5846. bfd_vma val;
  5847. memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
  5848. /* CIE length (rewrite in case little-endian). */
  5849. bfd_put_32 (htab->elf.dynobj, sizeof (glink_eh_frame_cie) - 4, p);
  5850. p += sizeof (glink_eh_frame_cie);
  5851. /* FDE length. */
  5852. val = htab->glink_eh_frame->size - 4 - sizeof (glink_eh_frame_cie);
  5853. bfd_put_32 (htab->elf.dynobj, val, p);
  5854. p += 4;
  5855. /* CIE pointer. */
  5856. val = p - htab->glink_eh_frame->contents;
  5857. bfd_put_32 (htab->elf.dynobj, val, p);
  5858. p += 4;
  5859. /* Offset to .glink. Set later. */
  5860. p += 4;
  5861. /* .glink size. */
  5862. bfd_put_32 (htab->elf.dynobj, htab->glink->size, p);
  5863. p += 4;
  5864. /* Augmentation. */
  5865. p += 1;
  5866. if (bfd_link_pic (info)
  5867. && htab->elf.dynamic_sections_created)
  5868. {
  5869. bfd_vma adv = (htab->glink->size - GLINK_PLTRESOLVE + 8) >> 2;
  5870. if (adv < 64)
  5871. *p++ = DW_CFA_advance_loc + adv;
  5872. else if (adv < 256)
  5873. {
  5874. *p++ = DW_CFA_advance_loc1;
  5875. *p++ = adv;
  5876. }
  5877. else if (adv < 65536)
  5878. {
  5879. *p++ = DW_CFA_advance_loc2;
  5880. bfd_put_16 (htab->elf.dynobj, adv, p);
  5881. p += 2;
  5882. }
  5883. else
  5884. {
  5885. *p++ = DW_CFA_advance_loc4;
  5886. bfd_put_32 (htab->elf.dynobj, adv, p);
  5887. p += 4;
  5888. }
  5889. *p++ = DW_CFA_register;
  5890. *p++ = 65;
  5891. p++;
  5892. *p++ = DW_CFA_advance_loc + 4;
  5893. *p++ = DW_CFA_restore_extended;
  5894. *p++ = 65;
  5895. }
  5896. BFD_ASSERT ((bfd_vma) ((p + 3 - htab->glink_eh_frame->contents) & -4)
  5897. == htab->glink_eh_frame->size);
  5898. }
  5899. return TRUE;
  5900. }
  5901. /* Arrange to have _SDA_BASE_ or _SDA2_BASE_ stripped from the output
  5902. if it looks like nothing is using them. */
  5903. static void
  5904. maybe_strip_sdasym (bfd *output_bfd, elf_linker_section_t *lsect)
  5905. {
  5906. struct elf_link_hash_entry *sda = lsect->sym;
  5907. if (sda != NULL && !sda->ref_regular && sda->dynindx == -1)
  5908. {
  5909. asection *s;
  5910. s = bfd_get_section_by_name (output_bfd, lsect->name);
  5911. if (s == NULL || bfd_section_removed_from_list (output_bfd, s))
  5912. {
  5913. s = bfd_get_section_by_name (output_bfd, lsect->bss_name);
  5914. if (s == NULL || bfd_section_removed_from_list (output_bfd, s))
  5915. {
  5916. sda->def_regular = 0;
  5917. /* This is somewhat magic. See elf_link_output_extsym. */
  5918. sda->ref_dynamic = 1;
  5919. sda->forced_local = 0;
  5920. }
  5921. }
  5922. }
  5923. }
  5924. void
  5925. ppc_elf_maybe_strip_sdata_syms (struct bfd_link_info *info)
  5926. {
  5927. struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
  5928. if (htab != NULL)
  5929. {
  5930. maybe_strip_sdasym (info->output_bfd, &htab->sdata[0]);
  5931. maybe_strip_sdasym (info->output_bfd, &htab->sdata[1]);
  5932. }
  5933. }
  5934. /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
  5935. static bfd_boolean
  5936. ppc_elf_hash_symbol (struct elf_link_hash_entry *h)
  5937. {
  5938. if (h->plt.plist != NULL
  5939. && !h->def_regular
  5940. && (!h->pointer_equality_needed
  5941. || !h->ref_regular_nonweak))
  5942. return FALSE;
  5943. return _bfd_elf_hash_symbol (h);
  5944. }
  5945. #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
  5946. /* Relaxation trampolines. r12 is available for clobbering (r11, is
  5947. used for some functions that are allowed to break the ABI). */
  5948. static const int shared_stub_entry[] =
  5949. {
  5950. 0x7c0802a6, /* mflr 0 */
  5951. 0x429f0005, /* bcl 20, 31, .Lxxx */
  5952. 0x7d8802a6, /* mflr 12 */
  5953. 0x3d8c0000, /* addis 12, 12, (xxx-.Lxxx)@ha */
  5954. 0x398c0000, /* addi 12, 12, (xxx-.Lxxx)@l */
  5955. 0x7c0803a6, /* mtlr 0 */
  5956. 0x7d8903a6, /* mtctr 12 */
  5957. 0x4e800420, /* bctr */
  5958. };
  5959. static const int stub_entry[] =
  5960. {
  5961. 0x3d800000, /* lis 12,xxx@ha */
  5962. 0x398c0000, /* addi 12,12,xxx@l */
  5963. 0x7d8903a6, /* mtctr 12 */
  5964. 0x4e800420, /* bctr */
  5965. };
  5966. struct ppc_elf_relax_info
  5967. {
  5968. unsigned int workaround_size;
  5969. unsigned int picfixup_size;
  5970. };
  5971. /* This function implements long branch trampolines, and the ppc476
  5972. icache bug workaround. Any section needing trampolines or patch
  5973. space for the workaround has its size extended so that we can
  5974. add trampolines at the end of the section. */
  5975. static bfd_boolean
  5976. ppc_elf_relax_section (bfd *abfd,
  5977. asection *isec,
  5978. struct bfd_link_info *link_info,
  5979. bfd_boolean *again)
  5980. {
  5981. struct one_branch_fixup
  5982. {
  5983. struct one_branch_fixup *next;
  5984. asection *tsec;
  5985. /* Final link, can use the symbol offset. For a
  5986. relocatable link we use the symbol's index. */
  5987. bfd_vma toff;
  5988. bfd_vma trampoff;
  5989. };
  5990. Elf_Internal_Shdr *symtab_hdr;
  5991. bfd_byte *contents = NULL;
  5992. Elf_Internal_Sym *isymbuf = NULL;
  5993. Elf_Internal_Rela *internal_relocs = NULL;
  5994. Elf_Internal_Rela *irel, *irelend = NULL;
  5995. struct one_branch_fixup *branch_fixups = NULL;
  5996. struct ppc_elf_relax_info *relax_info = NULL;
  5997. unsigned changes = 0;
  5998. bfd_boolean workaround_change;
  5999. struct ppc_elf_link_hash_table *htab;
  6000. bfd_size_type trampbase, trampoff, newsize, picfixup_size;
  6001. asection *got2;
  6002. bfd_boolean maybe_pasted;
  6003. *again = FALSE;
  6004. /* No need to do anything with non-alloc or non-code sections. */
  6005. if ((isec->flags & SEC_ALLOC) == 0
  6006. || (isec->flags & SEC_CODE) == 0
  6007. || (isec->flags & SEC_LINKER_CREATED) != 0
  6008. || isec->size < 4)
  6009. return TRUE;
  6010. /* We cannot represent the required PIC relocs in the output, so don't
  6011. do anything. The linker doesn't support mixing -shared and -r
  6012. anyway. */
  6013. if (bfd_link_relocatable (link_info) && bfd_link_pic (link_info))
  6014. return TRUE;
  6015. htab = ppc_elf_hash_table (link_info);
  6016. if (htab == NULL)
  6017. return TRUE;
  6018. isec->size = (isec->size + 3) & -4;
  6019. if (isec->rawsize == 0)
  6020. isec->rawsize = isec->size;
  6021. trampbase = isec->size;
  6022. BFD_ASSERT (isec->sec_info_type == SEC_INFO_TYPE_NONE
  6023. || isec->sec_info_type == SEC_INFO_TYPE_TARGET);
  6024. isec->sec_info_type = SEC_INFO_TYPE_TARGET;
  6025. if (htab->params->ppc476_workaround
  6026. || htab->params->pic_fixup > 0)
  6027. {
  6028. if (elf_section_data (isec)->sec_info == NULL)
  6029. {
  6030. elf_section_data (isec)->sec_info
  6031. = bfd_zalloc (abfd, sizeof (struct ppc_elf_relax_info));
  6032. if (elf_section_data (isec)->sec_info == NULL)
  6033. return FALSE;
  6034. }
  6035. relax_info = elf_section_data (isec)->sec_info;
  6036. trampbase -= relax_info->workaround_size;
  6037. }
  6038. maybe_pasted = (strcmp (isec->output_section->name, ".init") == 0
  6039. || strcmp (isec->output_section->name, ".fini") == 0);
  6040. /* Space for a branch around any trampolines. */
  6041. trampoff = trampbase;
  6042. if (maybe_pasted && trampbase == isec->rawsize)
  6043. trampoff += 4;
  6044. symtab_hdr = &elf_symtab_hdr (abfd);
  6045. picfixup_size = 0;
  6046. if (htab->params->branch_trampolines
  6047. || htab->params->pic_fixup > 0)
  6048. {
  6049. /* Get a copy of the native relocations. */
  6050. if (isec->reloc_count != 0)
  6051. {
  6052. internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL,
  6053. link_info->keep_memory);
  6054. if (internal_relocs == NULL)
  6055. goto error_return;
  6056. }
  6057. got2 = bfd_get_section_by_name (abfd, ".got2");
  6058. irelend = internal_relocs + isec->reloc_count;
  6059. for (irel = internal_relocs; irel < irelend; irel++)
  6060. {
  6061. unsigned long r_type = ELF32_R_TYPE (irel->r_info);
  6062. bfd_vma toff, roff;
  6063. asection *tsec;
  6064. struct one_branch_fixup *f;
  6065. size_t insn_offset = 0;
  6066. bfd_vma max_branch_offset = 0, val;
  6067. bfd_byte *hit_addr;
  6068. unsigned long t0;
  6069. struct elf_link_hash_entry *h;
  6070. struct plt_entry **plist;
  6071. unsigned char sym_type;
  6072. switch (r_type)
  6073. {
  6074. case R_PPC_REL24:
  6075. case R_PPC_LOCAL24PC:
  6076. case R_PPC_PLTREL24:
  6077. max_branch_offset = 1 << 25;
  6078. break;
  6079. case R_PPC_REL14:
  6080. case R_PPC_REL14_BRTAKEN:
  6081. case R_PPC_REL14_BRNTAKEN:
  6082. max_branch_offset = 1 << 15;
  6083. break;
  6084. case R_PPC_ADDR16_HA:
  6085. if (htab->params->pic_fixup > 0)
  6086. break;
  6087. continue;
  6088. default:
  6089. continue;
  6090. }
  6091. /* Get the value of the symbol referred to by the reloc. */
  6092. h = NULL;
  6093. if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
  6094. {
  6095. /* A local symbol. */
  6096. Elf_Internal_Sym *isym;
  6097. /* Read this BFD's local symbols. */
  6098. if (isymbuf == NULL)
  6099. {
  6100. isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
  6101. if (isymbuf == NULL)
  6102. isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
  6103. symtab_hdr->sh_info, 0,
  6104. NULL, NULL, NULL);
  6105. if (isymbuf == 0)
  6106. goto error_return;
  6107. }
  6108. isym = isymbuf + ELF32_R_SYM (irel->r_info);
  6109. if (isym->st_shndx == SHN_UNDEF)
  6110. tsec = bfd_und_section_ptr;
  6111. else if (isym->st_shndx == SHN_ABS)
  6112. tsec = bfd_abs_section_ptr;
  6113. else if (isym->st_shndx == SHN_COMMON)
  6114. tsec = bfd_com_section_ptr;
  6115. else
  6116. tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  6117. toff = isym->st_value;
  6118. sym_type = ELF_ST_TYPE (isym->st_info);
  6119. }
  6120. else
  6121. {
  6122. /* Global symbol handling. */
  6123. unsigned long indx;
  6124. indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
  6125. h = elf_sym_hashes (abfd)[indx];
  6126. while (h->root.type == bfd_link_hash_indirect
  6127. || h->root.type == bfd_link_hash_warning)
  6128. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  6129. if (h->root.type == bfd_link_hash_defined
  6130. || h->root.type == bfd_link_hash_defweak)
  6131. {
  6132. tsec = h->root.u.def.section;
  6133. toff = h->root.u.def.value;
  6134. }
  6135. else if (h->root.type == bfd_link_hash_undefined
  6136. || h->root.type == bfd_link_hash_undefweak)
  6137. {
  6138. tsec = bfd_und_section_ptr;
  6139. toff = bfd_link_relocatable (link_info) ? indx : 0;
  6140. }
  6141. else
  6142. continue;
  6143. /* If this branch is to __tls_get_addr then we may later
  6144. optimise away the call. We won't be needing a long-
  6145. branch stub in that case. */
  6146. if (bfd_link_executable (link_info)
  6147. && h == htab->tls_get_addr
  6148. && irel != internal_relocs)
  6149. {
  6150. unsigned long t_symndx = ELF32_R_SYM (irel[-1].r_info);
  6151. unsigned long t_rtype = ELF32_R_TYPE (irel[-1].r_info);
  6152. unsigned int tls_mask = 0;
  6153. /* The previous reloc should be one of R_PPC_TLSGD or
  6154. R_PPC_TLSLD, or for older object files, a reloc
  6155. on the __tls_get_addr arg setup insn. Get tls
  6156. mask bits from the symbol on that reloc. */
  6157. if (t_symndx < symtab_hdr->sh_info)
  6158. {
  6159. bfd_vma *local_got_offsets = elf_local_got_offsets (abfd);
  6160. if (local_got_offsets != NULL)
  6161. {
  6162. struct plt_entry **local_plt = (struct plt_entry **)
  6163. (local_got_offsets + symtab_hdr->sh_info);
  6164. char *lgot_masks = (char *)
  6165. (local_plt + symtab_hdr->sh_info);
  6166. tls_mask = lgot_masks[t_symndx];
  6167. }
  6168. }
  6169. else
  6170. {
  6171. struct elf_link_hash_entry *th
  6172. = elf_sym_hashes (abfd)[t_symndx - symtab_hdr->sh_info];
  6173. while (th->root.type == bfd_link_hash_indirect
  6174. || th->root.type == bfd_link_hash_warning)
  6175. th = (struct elf_link_hash_entry *) th->root.u.i.link;
  6176. tls_mask
  6177. = ((struct ppc_elf_link_hash_entry *) th)->tls_mask;
  6178. }
  6179. /* The mask bits tell us if the call will be
  6180. optimised away. */
  6181. if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0
  6182. && (t_rtype == R_PPC_TLSGD
  6183. || t_rtype == R_PPC_GOT_TLSGD16
  6184. || t_rtype == R_PPC_GOT_TLSGD16_LO))
  6185. continue;
  6186. if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0
  6187. && (t_rtype == R_PPC_TLSLD
  6188. || t_rtype == R_PPC_GOT_TLSLD16
  6189. || t_rtype == R_PPC_GOT_TLSLD16_LO))
  6190. continue;
  6191. }
  6192. sym_type = h->type;
  6193. }
  6194. if (r_type == R_PPC_ADDR16_HA)
  6195. {
  6196. if (h != NULL
  6197. && !h->def_regular
  6198. && h->protected_def
  6199. && ppc_elf_hash_entry (h)->has_addr16_ha
  6200. && ppc_elf_hash_entry (h)->has_addr16_lo)
  6201. picfixup_size += 12;
  6202. continue;
  6203. }
  6204. /* The condition here under which we call find_plt_ent must
  6205. match that in relocate_section. If we call find_plt_ent here
  6206. but not in relocate_section, or vice versa, then the branch
  6207. destination used here may be incorrect. */
  6208. plist = NULL;
  6209. if (h != NULL)
  6210. {
  6211. /* We know is_branch_reloc (r_type) is true. */
  6212. if (h->type == STT_GNU_IFUNC
  6213. || r_type == R_PPC_PLTREL24)
  6214. plist = &h->plt.plist;
  6215. }
  6216. else if (sym_type == STT_GNU_IFUNC
  6217. && elf_local_got_offsets (abfd) != NULL)
  6218. {
  6219. bfd_vma *local_got_offsets = elf_local_got_offsets (abfd);
  6220. struct plt_entry **local_plt = (struct plt_entry **)
  6221. (local_got_offsets + symtab_hdr->sh_info);
  6222. plist = local_plt + ELF32_R_SYM (irel->r_info);
  6223. }
  6224. if (plist != NULL)
  6225. {
  6226. bfd_vma addend = 0;
  6227. struct plt_entry *ent;
  6228. if (r_type == R_PPC_PLTREL24 && bfd_link_pic (link_info))
  6229. addend = irel->r_addend;
  6230. ent = find_plt_ent (plist, got2, addend);
  6231. if (ent != NULL)
  6232. {
  6233. if (htab->plt_type == PLT_NEW
  6234. || h == NULL
  6235. || !htab->elf.dynamic_sections_created
  6236. || h->dynindx == -1)
  6237. {
  6238. tsec = htab->glink;
  6239. toff = ent->glink_offset;
  6240. }
  6241. else
  6242. {
  6243. tsec = htab->plt;
  6244. toff = ent->plt.offset;
  6245. }
  6246. }
  6247. }
  6248. /* If the branch and target are in the same section, you have
  6249. no hope of adding stubs. We'll error out later should the
  6250. branch overflow. */
  6251. if (tsec == isec)
  6252. continue;
  6253. /* There probably isn't any reason to handle symbols in
  6254. SEC_MERGE sections; SEC_MERGE doesn't seem a likely
  6255. attribute for a code section, and we are only looking at
  6256. branches. However, implement it correctly here as a
  6257. reference for other target relax_section functions. */
  6258. if (0 && tsec->sec_info_type == SEC_INFO_TYPE_MERGE)
  6259. {
  6260. /* At this stage in linking, no SEC_MERGE symbol has been
  6261. adjusted, so all references to such symbols need to be
  6262. passed through _bfd_merged_section_offset. (Later, in
  6263. relocate_section, all SEC_MERGE symbols *except* for
  6264. section symbols have been adjusted.)
  6265. gas may reduce relocations against symbols in SEC_MERGE
  6266. sections to a relocation against the section symbol when
  6267. the original addend was zero. When the reloc is against
  6268. a section symbol we should include the addend in the
  6269. offset passed to _bfd_merged_section_offset, since the
  6270. location of interest is the original symbol. On the
  6271. other hand, an access to "sym+addend" where "sym" is not
  6272. a section symbol should not include the addend; Such an
  6273. access is presumed to be an offset from "sym"; The
  6274. location of interest is just "sym". */
  6275. if (sym_type == STT_SECTION)
  6276. toff += irel->r_addend;
  6277. toff
  6278. = _bfd_merged_section_offset (abfd, &tsec,
  6279. elf_section_data (tsec)->sec_info,
  6280. toff);
  6281. if (sym_type != STT_SECTION)
  6282. toff += irel->r_addend;
  6283. }
  6284. /* PLTREL24 addends are special. */
  6285. else if (r_type != R_PPC_PLTREL24)
  6286. toff += irel->r_addend;
  6287. /* Attempted -shared link of non-pic code loses. */
  6288. if ((!bfd_link_relocatable (link_info)
  6289. && tsec == bfd_und_section_ptr)
  6290. || tsec->output_section == NULL
  6291. || (tsec->owner != NULL
  6292. && (tsec->owner->flags & BFD_PLUGIN) != 0))
  6293. continue;
  6294. roff = irel->r_offset;
  6295. /* If the branch is in range, no need to do anything. */
  6296. if (tsec != bfd_und_section_ptr
  6297. && (!bfd_link_relocatable (link_info)
  6298. /* A relocatable link may have sections moved during
  6299. final link, so do not presume they remain in range. */
  6300. || tsec->output_section == isec->output_section))
  6301. {
  6302. bfd_vma symaddr, reladdr;
  6303. symaddr = tsec->output_section->vma + tsec->output_offset + toff;
  6304. reladdr = isec->output_section->vma + isec->output_offset + roff;
  6305. if (symaddr - reladdr + max_branch_offset
  6306. < 2 * max_branch_offset)
  6307. continue;
  6308. }
  6309. /* Look for an existing fixup to this address. */
  6310. for (f = branch_fixups; f ; f = f->next)
  6311. if (f->tsec == tsec && f->toff == toff)
  6312. break;
  6313. if (f == NULL)
  6314. {
  6315. size_t size;
  6316. unsigned long stub_rtype;
  6317. val = trampoff - roff;
  6318. if (val >= max_branch_offset)
  6319. /* Oh dear, we can't reach a trampoline. Don't try to add
  6320. one. We'll report an error later. */
  6321. continue;
  6322. if (bfd_link_pic (link_info))
  6323. {
  6324. size = 4 * ARRAY_SIZE (shared_stub_entry);
  6325. insn_offset = 12;
  6326. }
  6327. else
  6328. {
  6329. size = 4 * ARRAY_SIZE (stub_entry);
  6330. insn_offset = 0;
  6331. }
  6332. stub_rtype = R_PPC_RELAX;
  6333. if (tsec == htab->plt
  6334. || tsec == htab->glink)
  6335. {
  6336. stub_rtype = R_PPC_RELAX_PLT;
  6337. if (r_type == R_PPC_PLTREL24)
  6338. stub_rtype = R_PPC_RELAX_PLTREL24;
  6339. }
  6340. /* Hijack the old relocation. Since we need two
  6341. relocations for this use a "composite" reloc. */
  6342. irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
  6343. stub_rtype);
  6344. irel->r_offset = trampoff + insn_offset;
  6345. if (r_type == R_PPC_PLTREL24
  6346. && stub_rtype != R_PPC_RELAX_PLTREL24)
  6347. irel->r_addend = 0;
  6348. /* Record the fixup so we don't do it again this section. */
  6349. f = bfd_malloc (sizeof (*f));
  6350. f->next = branch_fixups;
  6351. f->tsec = tsec;
  6352. f->toff = toff;
  6353. f->trampoff = trampoff;
  6354. branch_fixups = f;
  6355. trampoff += size;
  6356. changes++;
  6357. }
  6358. else
  6359. {
  6360. val = f->trampoff - roff;
  6361. if (val >= max_branch_offset)
  6362. continue;
  6363. /* Nop out the reloc, since we're finalizing things here. */
  6364. irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
  6365. }
  6366. /* Get the section contents. */
  6367. if (contents == NULL)
  6368. {
  6369. /* Get cached copy if it exists. */
  6370. if (elf_section_data (isec)->this_hdr.contents != NULL)
  6371. contents = elf_section_data (isec)->this_hdr.contents;
  6372. /* Go get them off disk. */
  6373. else if (!bfd_malloc_and_get_section (abfd, isec, &contents))
  6374. goto error_return;
  6375. }
  6376. /* Fix up the existing branch to hit the trampoline. */
  6377. hit_addr = contents + roff;
  6378. switch (r_type)
  6379. {
  6380. case R_PPC_REL24:
  6381. case R_PPC_LOCAL24PC:
  6382. case R_PPC_PLTREL24:
  6383. t0 = bfd_get_32 (abfd, hit_addr);
  6384. t0 &= ~0x3fffffc;
  6385. t0 |= val & 0x3fffffc;
  6386. bfd_put_32 (abfd, t0, hit_addr);
  6387. break;
  6388. case R_PPC_REL14:
  6389. case R_PPC_REL14_BRTAKEN:
  6390. case R_PPC_REL14_BRNTAKEN:
  6391. t0 = bfd_get_32 (abfd, hit_addr);
  6392. t0 &= ~0xfffc;
  6393. t0 |= val & 0xfffc;
  6394. bfd_put_32 (abfd, t0, hit_addr);
  6395. break;
  6396. }
  6397. }
  6398. while (branch_fixups != NULL)
  6399. {
  6400. struct one_branch_fixup *f = branch_fixups;
  6401. branch_fixups = branch_fixups->next;
  6402. free (f);
  6403. }
  6404. }
  6405. workaround_change = FALSE;
  6406. newsize = trampoff;
  6407. if (htab->params->ppc476_workaround
  6408. && (!bfd_link_relocatable (link_info)
  6409. || isec->output_section->alignment_power >= htab->params->pagesize_p2))
  6410. {
  6411. bfd_vma addr, end_addr;
  6412. unsigned int crossings;
  6413. bfd_vma pagesize = (bfd_vma) 1 << htab->params->pagesize_p2;
  6414. addr = isec->output_section->vma + isec->output_offset;
  6415. end_addr = addr + trampoff;
  6416. addr &= -pagesize;
  6417. crossings = ((end_addr & -pagesize) - addr) >> htab->params->pagesize_p2;
  6418. if (crossings != 0)
  6419. {
  6420. /* Keep space aligned, to ensure the patch code itself does
  6421. not cross a page. Don't decrease size calculated on a
  6422. previous pass as otherwise we might never settle on a layout. */
  6423. newsize = 15 - ((end_addr - 1) & 15);
  6424. newsize += crossings * 16;
  6425. if (relax_info->workaround_size < newsize)
  6426. {
  6427. relax_info->workaround_size = newsize;
  6428. workaround_change = TRUE;
  6429. }
  6430. /* Ensure relocate_section is called. */
  6431. isec->flags |= SEC_RELOC;
  6432. }
  6433. newsize = trampoff + relax_info->workaround_size;
  6434. }
  6435. if (htab->params->pic_fixup > 0)
  6436. {
  6437. picfixup_size -= relax_info->picfixup_size;
  6438. if (picfixup_size != 0)
  6439. relax_info->picfixup_size += picfixup_size;
  6440. newsize += relax_info->picfixup_size;
  6441. }
  6442. if (changes != 0 || picfixup_size != 0 || workaround_change)
  6443. isec->size = newsize;
  6444. if (isymbuf != NULL
  6445. && symtab_hdr->contents != (unsigned char *) isymbuf)
  6446. {
  6447. if (! link_info->keep_memory)
  6448. free (isymbuf);
  6449. else
  6450. {
  6451. /* Cache the symbols for elf_link_input_bfd. */
  6452. symtab_hdr->contents = (unsigned char *) isymbuf;
  6453. }
  6454. }
  6455. if (contents != NULL
  6456. && elf_section_data (isec)->this_hdr.contents != contents)
  6457. {
  6458. if (!changes && !link_info->keep_memory)
  6459. free (contents);
  6460. else
  6461. {
  6462. /* Cache the section contents for elf_link_input_bfd. */
  6463. elf_section_data (isec)->this_hdr.contents = contents;
  6464. }
  6465. }
  6466. changes += picfixup_size;
  6467. if (changes != 0)
  6468. {
  6469. /* Append sufficient NOP relocs so we can write out relocation
  6470. information for the trampolines. */
  6471. Elf_Internal_Shdr *rel_hdr;
  6472. Elf_Internal_Rela *new_relocs = bfd_malloc ((changes + isec->reloc_count)
  6473. * sizeof (*new_relocs));
  6474. unsigned ix;
  6475. if (!new_relocs)
  6476. goto error_return;
  6477. memcpy (new_relocs, internal_relocs,
  6478. isec->reloc_count * sizeof (*new_relocs));
  6479. for (ix = changes; ix--;)
  6480. {
  6481. irel = new_relocs + ix + isec->reloc_count;
  6482. irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
  6483. }
  6484. if (internal_relocs != elf_section_data (isec)->relocs)
  6485. free (internal_relocs);
  6486. elf_section_data (isec)->relocs = new_relocs;
  6487. isec->reloc_count += changes;
  6488. rel_hdr = _bfd_elf_single_rel_hdr (isec);
  6489. rel_hdr->sh_size += changes * rel_hdr->sh_entsize;
  6490. }
  6491. else if (internal_relocs != NULL
  6492. && elf_section_data (isec)->relocs != internal_relocs)
  6493. free (internal_relocs);
  6494. *again = changes != 0 || workaround_change;
  6495. return TRUE;
  6496. error_return:
  6497. while (branch_fixups != NULL)
  6498. {
  6499. struct one_branch_fixup *f = branch_fixups;
  6500. branch_fixups = branch_fixups->next;
  6501. free (f);
  6502. }
  6503. if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
  6504. free (isymbuf);
  6505. if (contents != NULL
  6506. && elf_section_data (isec)->this_hdr.contents != contents)
  6507. free (contents);
  6508. if (internal_relocs != NULL
  6509. && elf_section_data (isec)->relocs != internal_relocs)
  6510. free (internal_relocs);
  6511. return FALSE;
  6512. }
  6513. /* What to do when ld finds relocations against symbols defined in
  6514. discarded sections. */
  6515. static unsigned int
  6516. ppc_elf_action_discarded (asection *sec)
  6517. {
  6518. if (strcmp (".fixup", sec->name) == 0)
  6519. return 0;
  6520. if (strcmp (".got2", sec->name) == 0)
  6521. return 0;
  6522. return _bfd_elf_default_action_discarded (sec);
  6523. }
  6524. /* Fill in the address for a pointer generated in a linker section. */
  6525. static bfd_vma
  6526. elf_finish_pointer_linker_section (bfd *input_bfd,
  6527. elf_linker_section_t *lsect,
  6528. struct elf_link_hash_entry *h,
  6529. bfd_vma relocation,
  6530. const Elf_Internal_Rela *rel)
  6531. {
  6532. elf_linker_section_pointers_t *linker_section_ptr;
  6533. BFD_ASSERT (lsect != NULL);
  6534. if (h != NULL)
  6535. {
  6536. /* Handle global symbol. */
  6537. struct ppc_elf_link_hash_entry *eh;
  6538. eh = (struct ppc_elf_link_hash_entry *) h;
  6539. BFD_ASSERT (eh->elf.def_regular);
  6540. linker_section_ptr = eh->linker_section_pointer;
  6541. }
  6542. else
  6543. {
  6544. /* Handle local symbol. */
  6545. unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
  6546. BFD_ASSERT (is_ppc_elf (input_bfd));
  6547. BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
  6548. linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx];
  6549. }
  6550. linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr,
  6551. rel->r_addend,
  6552. lsect);
  6553. BFD_ASSERT (linker_section_ptr != NULL);
  6554. /* Offset will always be a multiple of four, so use the bottom bit
  6555. as a "written" flag. */
  6556. if ((linker_section_ptr->offset & 1) == 0)
  6557. {
  6558. bfd_put_32 (lsect->section->owner,
  6559. relocation + linker_section_ptr->addend,
  6560. lsect->section->contents + linker_section_ptr->offset);
  6561. linker_section_ptr->offset += 1;
  6562. }
  6563. relocation = (lsect->section->output_section->vma
  6564. + lsect->section->output_offset
  6565. + linker_section_ptr->offset - 1
  6566. - SYM_VAL (lsect->sym));
  6567. #ifdef DEBUG
  6568. fprintf (stderr,
  6569. "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
  6570. lsect->name, (long) relocation, (long) relocation);
  6571. #endif
  6572. return relocation;
  6573. }
  6574. #define PPC_LO(v) ((v) & 0xffff)
  6575. #define PPC_HI(v) (((v) >> 16) & 0xffff)
  6576. #define PPC_HA(v) PPC_HI ((v) + 0x8000)
  6577. static void
  6578. write_glink_stub (struct plt_entry *ent, asection *plt_sec, unsigned char *p,
  6579. struct bfd_link_info *info)
  6580. {
  6581. struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
  6582. bfd *output_bfd = info->output_bfd;
  6583. bfd_vma plt;
  6584. plt = ((ent->plt.offset & ~1)
  6585. + plt_sec->output_section->vma
  6586. + plt_sec->output_offset);
  6587. if (bfd_link_pic (info))
  6588. {
  6589. bfd_vma got = 0;
  6590. if (ent->addend >= 32768)
  6591. got = (ent->addend
  6592. + ent->sec->output_section->vma
  6593. + ent->sec->output_offset);
  6594. else if (htab->elf.hgot != NULL)
  6595. got = SYM_VAL (htab->elf.hgot);
  6596. plt -= got;
  6597. if (plt + 0x8000 < 0x10000)
  6598. {
  6599. bfd_put_32 (output_bfd, LWZ_11_30 + PPC_LO (plt), p);
  6600. p += 4;
  6601. bfd_put_32 (output_bfd, MTCTR_11, p);
  6602. p += 4;
  6603. bfd_put_32 (output_bfd, BCTR, p);
  6604. p += 4;
  6605. bfd_put_32 (output_bfd, htab->params->ppc476_workaround ? BA : NOP, p);
  6606. p += 4;
  6607. }
  6608. else
  6609. {
  6610. bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (plt), p);
  6611. p += 4;
  6612. bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
  6613. p += 4;
  6614. bfd_put_32 (output_bfd, MTCTR_11, p);
  6615. p += 4;
  6616. bfd_put_32 (output_bfd, BCTR, p);
  6617. p += 4;
  6618. }
  6619. }
  6620. else
  6621. {
  6622. bfd_put_32 (output_bfd, LIS_11 + PPC_HA (plt), p);
  6623. p += 4;
  6624. bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
  6625. p += 4;
  6626. bfd_put_32 (output_bfd, MTCTR_11, p);
  6627. p += 4;
  6628. bfd_put_32 (output_bfd, BCTR, p);
  6629. p += 4;
  6630. }
  6631. }
  6632. /* Return true if symbol is defined statically. */
  6633. static bfd_boolean
  6634. is_static_defined (struct elf_link_hash_entry *h)
  6635. {
  6636. return ((h->root.type == bfd_link_hash_defined
  6637. || h->root.type == bfd_link_hash_defweak)
  6638. && h->root.u.def.section != NULL
  6639. && h->root.u.def.section->output_section != NULL);
  6640. }
  6641. /* If INSN is an opcode that may be used with an @tls operand, return
  6642. the transformed insn for TLS optimisation, otherwise return 0. If
  6643. REG is non-zero only match an insn with RB or RA equal to REG. */
  6644. unsigned int
  6645. _bfd_elf_ppc_at_tls_transform (unsigned int insn, unsigned int reg)
  6646. {
  6647. unsigned int rtra;
  6648. if ((insn & (0x3f << 26)) != 31 << 26)
  6649. return 0;
  6650. if (reg == 0 || ((insn >> 11) & 0x1f) == reg)
  6651. rtra = insn & ((1 << 26) - (1 << 16));
  6652. else if (((insn >> 16) & 0x1f) == reg)
  6653. rtra = (insn & (0x1f << 21)) | ((insn & (0x1f << 11)) << 5);
  6654. else
  6655. return 0;
  6656. if ((insn & (0x3ff << 1)) == 266 << 1)
  6657. /* add -> addi. */
  6658. insn = 14 << 26;
  6659. else if ((insn & (0x1f << 1)) == 23 << 1
  6660. && ((insn & (0x1f << 6)) < 14 << 6
  6661. || ((insn & (0x1f << 6)) >= 16 << 6
  6662. && (insn & (0x1f << 6)) < 24 << 6)))
  6663. /* load and store indexed -> dform. */
  6664. insn = (32 | ((insn >> 6) & 0x1f)) << 26;
  6665. else if ((insn & (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
  6666. /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
  6667. insn = ((58 | ((insn >> 6) & 4)) << 26) | ((insn >> 6) & 1);
  6668. else if ((insn & (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
  6669. /* lwax -> lwa. */
  6670. insn = (58 << 26) | 2;
  6671. else
  6672. return 0;
  6673. insn |= rtra;
  6674. return insn;
  6675. }
  6676. /* If INSN is an opcode that may be used with an @tprel operand, return
  6677. the transformed insn for an undefined weak symbol, ie. with the
  6678. thread pointer REG operand removed. Otherwise return 0. */
  6679. unsigned int
  6680. _bfd_elf_ppc_at_tprel_transform (unsigned int insn, unsigned int reg)
  6681. {
  6682. if ((insn & (0x1f << 16)) == reg << 16
  6683. && ((insn & (0x3f << 26)) == 14u << 26 /* addi */
  6684. || (insn & (0x3f << 26)) == 15u << 26 /* addis */
  6685. || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
  6686. || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
  6687. || (insn & (0x3f << 26)) == 36u << 26 /* stw */
  6688. || (insn & (0x3f << 26)) == 38u << 26 /* stb */
  6689. || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
  6690. || (insn & (0x3f << 26)) == 42u << 26 /* lha */
  6691. || (insn & (0x3f << 26)) == 44u << 26 /* sth */
  6692. || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
  6693. || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
  6694. || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
  6695. || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
  6696. || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
  6697. || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
  6698. || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
  6699. && (insn & 3) != 1)
  6700. || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */
  6701. && ((insn & 3) == 0 || (insn & 3) == 3))))
  6702. {
  6703. insn &= ~(0x1f << 16);
  6704. }
  6705. else if ((insn & (0x1f << 21)) == reg << 21
  6706. && ((insn & (0x3e << 26)) == 24u << 26 /* ori, oris */
  6707. || (insn & (0x3e << 26)) == 26u << 26 /* xori,xoris */
  6708. || (insn & (0x3e << 26)) == 28u << 26 /* andi,andis */))
  6709. {
  6710. insn &= ~(0x1f << 21);
  6711. insn |= (insn & (0x1f << 16)) << 5;
  6712. if ((insn & (0x3e << 26)) == 26 << 26 /* xori,xoris */)
  6713. insn -= 2 >> 26; /* convert to ori,oris */
  6714. }
  6715. else
  6716. insn = 0;
  6717. return insn;
  6718. }
  6719. static bfd_boolean
  6720. is_insn_ds_form (unsigned int insn)
  6721. {
  6722. return ((insn & (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
  6723. || (insn & (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
  6724. || (insn & (0x3f << 26)) == 57u << 26 /* lfdp */
  6725. || (insn & (0x3f << 26)) == 61u << 26 /* stfdp */);
  6726. }
  6727. static bfd_boolean
  6728. is_insn_dq_form (unsigned int insn)
  6729. {
  6730. return (insn & (0x3f << 26)) == 56u << 26; /* lq */
  6731. }
  6732. /* The RELOCATE_SECTION function is called by the ELF backend linker
  6733. to handle the relocations for a section.
  6734. The relocs are always passed as Rela structures; if the section
  6735. actually uses Rel structures, the r_addend field will always be
  6736. zero.
  6737. This function is responsible for adjust the section contents as
  6738. necessary, and (if using Rela relocs and generating a
  6739. relocatable output file) adjusting the reloc addend as
  6740. necessary.
  6741. This function does not have to worry about setting the reloc
  6742. address or the reloc symbol index.
  6743. LOCAL_SYMS is a pointer to the swapped in local symbols.
  6744. LOCAL_SECTIONS is an array giving the section in the input file
  6745. corresponding to the st_shndx field of each local symbol.
  6746. The global hash table entry for the global symbols can be found
  6747. via elf_sym_hashes (input_bfd).
  6748. When generating relocatable output, this function must handle
  6749. STB_LOCAL/STT_SECTION symbols specially. The output symbol is
  6750. going to be the section symbol corresponding to the output
  6751. section, which means that the addend must be adjusted
  6752. accordingly. */
  6753. static bfd_boolean
  6754. ppc_elf_relocate_section (bfd *output_bfd,
  6755. struct bfd_link_info *info,
  6756. bfd *input_bfd,
  6757. asection *input_section,
  6758. bfd_byte *contents,
  6759. Elf_Internal_Rela *relocs,
  6760. Elf_Internal_Sym *local_syms,
  6761. asection **local_sections)
  6762. {
  6763. Elf_Internal_Shdr *symtab_hdr;
  6764. struct elf_link_hash_entry **sym_hashes;
  6765. struct ppc_elf_link_hash_table *htab;
  6766. Elf_Internal_Rela *rel;
  6767. Elf_Internal_Rela *relend;
  6768. Elf_Internal_Rela outrel;
  6769. asection *got2;
  6770. bfd_vma *local_got_offsets;
  6771. bfd_boolean ret = TRUE;
  6772. bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
  6773. bfd_boolean is_vxworks_tls;
  6774. unsigned int picfixup_size = 0;
  6775. struct ppc_elf_relax_info *relax_info = NULL;
  6776. #ifdef DEBUG
  6777. _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
  6778. "%ld relocations%s",
  6779. input_bfd, input_section,
  6780. (long) input_section->reloc_count,
  6781. (bfd_link_relocatable (info)) ? " (relocatable)" : "");
  6782. #endif
  6783. got2 = bfd_get_section_by_name (input_bfd, ".got2");
  6784. /* Initialize howto table if not already done. */
  6785. if (!ppc_elf_howto_table[R_PPC_ADDR32])
  6786. ppc_elf_howto_init ();
  6787. htab = ppc_elf_hash_table (info);
  6788. local_got_offsets = elf_local_got_offsets (input_bfd);
  6789. symtab_hdr = &elf_symtab_hdr (input_bfd);
  6790. sym_hashes = elf_sym_hashes (input_bfd);
  6791. /* We have to handle relocations in vxworks .tls_vars sections
  6792. specially, because the dynamic loader is 'weird'. */
  6793. is_vxworks_tls = (htab->is_vxworks && bfd_link_pic (info)
  6794. && !strcmp (input_section->output_section->name,
  6795. ".tls_vars"));
  6796. if (input_section->sec_info_type == SEC_INFO_TYPE_TARGET)
  6797. relax_info = elf_section_data (input_section)->sec_info;
  6798. rel = relocs;
  6799. relend = relocs + input_section->reloc_count;
  6800. for (; rel < relend; rel++)
  6801. {
  6802. enum elf_ppc_reloc_type r_type;
  6803. bfd_vma addend;
  6804. bfd_reloc_status_type r;
  6805. Elf_Internal_Sym *sym;
  6806. asection *sec;
  6807. struct elf_link_hash_entry *h;
  6808. const char *sym_name;
  6809. reloc_howto_type *howto;
  6810. unsigned long r_symndx;
  6811. bfd_vma relocation;
  6812. bfd_vma branch_bit, from;
  6813. bfd_boolean unresolved_reloc;
  6814. bfd_boolean warned;
  6815. unsigned int tls_type, tls_mask, tls_gd;
  6816. struct plt_entry **ifunc;
  6817. struct reloc_howto_struct alt_howto;
  6818. r_type = ELF32_R_TYPE (rel->r_info);
  6819. sym = NULL;
  6820. sec = NULL;
  6821. h = NULL;
  6822. unresolved_reloc = FALSE;
  6823. warned = FALSE;
  6824. r_symndx = ELF32_R_SYM (rel->r_info);
  6825. if (r_symndx < symtab_hdr->sh_info)
  6826. {
  6827. sym = local_syms + r_symndx;
  6828. sec = local_sections[r_symndx];
  6829. sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
  6830. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  6831. }
  6832. else
  6833. {
  6834. bfd_boolean ignored;
  6835. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  6836. r_symndx, symtab_hdr, sym_hashes,
  6837. h, sec, relocation,
  6838. unresolved_reloc, warned, ignored);
  6839. sym_name = h->root.root.string;
  6840. }
  6841. if (sec != NULL && discarded_section (sec))
  6842. {
  6843. /* For relocs against symbols from removed linkonce sections,
  6844. or sections discarded by a linker script, we just want the
  6845. section contents zeroed. Avoid any special processing. */
  6846. howto = NULL;
  6847. if (r_type < R_PPC_max)
  6848. howto = ppc_elf_howto_table[r_type];
  6849. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  6850. rel, 1, relend, howto, 0, contents);
  6851. }
  6852. if (bfd_link_relocatable (info))
  6853. {
  6854. if (got2 != NULL
  6855. && r_type == R_PPC_PLTREL24
  6856. && rel->r_addend != 0)
  6857. {
  6858. /* R_PPC_PLTREL24 is rather special. If non-zero, the
  6859. addend specifies the GOT pointer offset within .got2. */
  6860. rel->r_addend += got2->output_offset;
  6861. }
  6862. if (r_type != R_PPC_RELAX_PLT
  6863. && r_type != R_PPC_RELAX_PLTREL24
  6864. && r_type != R_PPC_RELAX)
  6865. continue;
  6866. }
  6867. /* TLS optimizations. Replace instruction sequences and relocs
  6868. based on information we collected in tls_optimize. We edit
  6869. RELOCS so that --emit-relocs will output something sensible
  6870. for the final instruction stream. */
  6871. tls_mask = 0;
  6872. tls_gd = 0;
  6873. if (h != NULL)
  6874. tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
  6875. else if (local_got_offsets != NULL)
  6876. {
  6877. struct plt_entry **local_plt;
  6878. char *lgot_masks;
  6879. local_plt
  6880. = (struct plt_entry **) (local_got_offsets + symtab_hdr->sh_info);
  6881. lgot_masks = (char *) (local_plt + symtab_hdr->sh_info);
  6882. tls_mask = lgot_masks[r_symndx];
  6883. }
  6884. /* Ensure reloc mapping code below stays sane. */
  6885. if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
  6886. || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
  6887. || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
  6888. || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
  6889. || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)
  6890. || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
  6891. || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
  6892. || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
  6893. abort ();
  6894. switch (r_type)
  6895. {
  6896. default:
  6897. break;
  6898. case R_PPC_GOT_TPREL16:
  6899. case R_PPC_GOT_TPREL16_LO:
  6900. if ((tls_mask & TLS_TLS) != 0
  6901. && (tls_mask & TLS_TPREL) == 0)
  6902. {
  6903. bfd_vma insn;
  6904. insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
  6905. insn &= 31 << 21;
  6906. insn |= 0x3c020000; /* addis 0,2,0 */
  6907. bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
  6908. r_type = R_PPC_TPREL16_HA;
  6909. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  6910. }
  6911. break;
  6912. case R_PPC_TLS:
  6913. if ((tls_mask & TLS_TLS) != 0
  6914. && (tls_mask & TLS_TPREL) == 0)
  6915. {
  6916. bfd_vma insn;
  6917. insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
  6918. insn = _bfd_elf_ppc_at_tls_transform (insn, 2);
  6919. if (insn == 0)
  6920. abort ();
  6921. bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
  6922. r_type = R_PPC_TPREL16_LO;
  6923. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  6924. /* Was PPC_TLS which sits on insn boundary, now
  6925. PPC_TPREL16_LO which is at low-order half-word. */
  6926. rel->r_offset += d_offset;
  6927. }
  6928. break;
  6929. case R_PPC_GOT_TLSGD16_HI:
  6930. case R_PPC_GOT_TLSGD16_HA:
  6931. tls_gd = TLS_TPRELGD;
  6932. if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
  6933. goto tls_gdld_hi;
  6934. break;
  6935. case R_PPC_GOT_TLSLD16_HI:
  6936. case R_PPC_GOT_TLSLD16_HA:
  6937. if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
  6938. {
  6939. tls_gdld_hi:
  6940. if ((tls_mask & tls_gd) != 0)
  6941. r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
  6942. + R_PPC_GOT_TPREL16);
  6943. else
  6944. {
  6945. rel->r_offset -= d_offset;
  6946. bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
  6947. r_type = R_PPC_NONE;
  6948. }
  6949. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  6950. }
  6951. break;
  6952. case R_PPC_GOT_TLSGD16:
  6953. case R_PPC_GOT_TLSGD16_LO:
  6954. tls_gd = TLS_TPRELGD;
  6955. if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
  6956. goto tls_ldgd_opt;
  6957. break;
  6958. case R_PPC_GOT_TLSLD16:
  6959. case R_PPC_GOT_TLSLD16_LO:
  6960. if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
  6961. {
  6962. unsigned int insn1, insn2;
  6963. bfd_vma offset;
  6964. tls_ldgd_opt:
  6965. offset = (bfd_vma) -1;
  6966. /* If not using the newer R_PPC_TLSGD/LD to mark
  6967. __tls_get_addr calls, we must trust that the call
  6968. stays with its arg setup insns, ie. that the next
  6969. reloc is the __tls_get_addr call associated with
  6970. the current reloc. Edit both insns. */
  6971. if (input_section->has_tls_get_addr_call
  6972. && rel + 1 < relend
  6973. && branch_reloc_hash_match (input_bfd, rel + 1,
  6974. htab->tls_get_addr))
  6975. offset = rel[1].r_offset;
  6976. /* We read the low GOT_TLS insn because we need to keep
  6977. the destination reg. It may be something other than
  6978. the usual r3, and moved to r3 before the call by
  6979. intervening code. */
  6980. insn1 = bfd_get_32 (output_bfd,
  6981. contents + rel->r_offset - d_offset);
  6982. if ((tls_mask & tls_gd) != 0)
  6983. {
  6984. /* IE */
  6985. insn1 &= (0x1f << 21) | (0x1f << 16);
  6986. insn1 |= 32 << 26; /* lwz */
  6987. if (offset != (bfd_vma) -1)
  6988. {
  6989. rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
  6990. insn2 = 0x7c631214; /* add 3,3,2 */
  6991. bfd_put_32 (output_bfd, insn2, contents + offset);
  6992. }
  6993. r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
  6994. + R_PPC_GOT_TPREL16);
  6995. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  6996. }
  6997. else
  6998. {
  6999. /* LE */
  7000. insn1 &= 0x1f << 21;
  7001. insn1 |= 0x3c020000; /* addis r,2,0 */
  7002. if (tls_gd == 0)
  7003. {
  7004. /* Was an LD reloc. */
  7005. for (r_symndx = 0;
  7006. r_symndx < symtab_hdr->sh_info;
  7007. r_symndx++)
  7008. if (local_sections[r_symndx] == sec)
  7009. break;
  7010. if (r_symndx >= symtab_hdr->sh_info)
  7011. r_symndx = STN_UNDEF;
  7012. rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
  7013. if (r_symndx != STN_UNDEF)
  7014. rel->r_addend -= (local_syms[r_symndx].st_value
  7015. + sec->output_offset
  7016. + sec->output_section->vma);
  7017. }
  7018. r_type = R_PPC_TPREL16_HA;
  7019. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  7020. if (offset != (bfd_vma) -1)
  7021. {
  7022. rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
  7023. rel[1].r_offset = offset + d_offset;
  7024. rel[1].r_addend = rel->r_addend;
  7025. insn2 = 0x38630000; /* addi 3,3,0 */
  7026. bfd_put_32 (output_bfd, insn2, contents + offset);
  7027. }
  7028. }
  7029. bfd_put_32 (output_bfd, insn1,
  7030. contents + rel->r_offset - d_offset);
  7031. if (tls_gd == 0)
  7032. {
  7033. /* We changed the symbol on an LD reloc. Start over
  7034. in order to get h, sym, sec etc. right. */
  7035. rel--;
  7036. continue;
  7037. }
  7038. }
  7039. break;
  7040. case R_PPC_TLSGD:
  7041. if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
  7042. {
  7043. unsigned int insn2;
  7044. bfd_vma offset = rel->r_offset;
  7045. if ((tls_mask & TLS_TPRELGD) != 0)
  7046. {
  7047. /* IE */
  7048. r_type = R_PPC_NONE;
  7049. insn2 = 0x7c631214; /* add 3,3,2 */
  7050. }
  7051. else
  7052. {
  7053. /* LE */
  7054. r_type = R_PPC_TPREL16_LO;
  7055. rel->r_offset += d_offset;
  7056. insn2 = 0x38630000; /* addi 3,3,0 */
  7057. }
  7058. rel->r_info = ELF32_R_INFO (r_symndx, r_type);
  7059. bfd_put_32 (output_bfd, insn2, contents + offset);
  7060. /* Zap the reloc on the _tls_get_addr call too. */
  7061. BFD_ASSERT (offset == rel[1].r_offset);
  7062. rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
  7063. }
  7064. break;
  7065. case R_PPC_TLSLD:
  7066. if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
  7067. {
  7068. unsigned int insn2;
  7069. for (r_symndx = 0;
  7070. r_symndx < symtab_hdr->sh_info;
  7071. r_symndx++)
  7072. if (local_sections[r_symndx] == sec)
  7073. break;
  7074. if (r_symndx >= symtab_hdr->sh_info)
  7075. r_symndx = STN_UNDEF;
  7076. rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
  7077. if (r_symndx != STN_UNDEF)
  7078. rel->r_addend -= (local_syms[r_symndx].st_value
  7079. + sec->output_offset
  7080. + sec->output_section->vma);
  7081. rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
  7082. rel->r_offset += d_offset;
  7083. insn2 = 0x38630000; /* addi 3,3,0 */
  7084. bfd_put_32 (output_bfd, insn2,
  7085. contents + rel->r_offset - d_offset);
  7086. /* Zap the reloc on the _tls_get_addr call too. */
  7087. BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset);
  7088. rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
  7089. rel--;
  7090. continue;
  7091. }
  7092. break;
  7093. }
  7094. /* Handle other relocations that tweak non-addend part of insn. */
  7095. branch_bit = 0;
  7096. switch (r_type)
  7097. {
  7098. default:
  7099. break;
  7100. /* Branch taken prediction relocations. */
  7101. case R_PPC_ADDR14_BRTAKEN:
  7102. case R_PPC_REL14_BRTAKEN:
  7103. branch_bit = BRANCH_PREDICT_BIT;
  7104. /* Fall thru */
  7105. /* Branch not taken prediction relocations. */
  7106. case R_PPC_ADDR14_BRNTAKEN:
  7107. case R_PPC_REL14_BRNTAKEN:
  7108. {
  7109. bfd_vma insn;
  7110. insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
  7111. insn &= ~BRANCH_PREDICT_BIT;
  7112. insn |= branch_bit;
  7113. from = (rel->r_offset
  7114. + input_section->output_offset
  7115. + input_section->output_section->vma);
  7116. /* Invert 'y' bit if not the default. */
  7117. if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
  7118. insn ^= BRANCH_PREDICT_BIT;
  7119. bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
  7120. break;
  7121. }
  7122. }
  7123. if (ELIMINATE_COPY_RELOCS
  7124. && h != NULL
  7125. && !h->def_regular
  7126. && h->protected_def
  7127. && ppc_elf_hash_entry (h)->has_addr16_ha
  7128. && ppc_elf_hash_entry (h)->has_addr16_lo
  7129. && htab->params->pic_fixup > 0)
  7130. {
  7131. /* Convert lis;addi or lis;load/store accessing a protected
  7132. variable defined in a shared library to PIC. */
  7133. unsigned int insn;
  7134. if (r_type == R_PPC_ADDR16_HA)
  7135. {
  7136. insn = bfd_get_32 (output_bfd,
  7137. contents + rel->r_offset - d_offset);
  7138. if ((insn & (0x3f << 26)) == (15u << 26)
  7139. && (insn & (0x1f << 16)) == 0 /* lis */)
  7140. {
  7141. bfd_byte *p;
  7142. bfd_vma off;
  7143. bfd_vma got_addr;
  7144. p = (contents + input_section->size
  7145. - relax_info->workaround_size
  7146. - relax_info->picfixup_size
  7147. + picfixup_size);
  7148. off = (p - contents) - (rel->r_offset - d_offset);
  7149. if (off > 0x1fffffc || (off & 3) != 0)
  7150. info->callbacks->einfo
  7151. (_("%P: %H: fixup branch overflow\n"),
  7152. input_bfd, input_section, rel->r_offset);
  7153. bfd_put_32 (output_bfd, B | off,
  7154. contents + rel->r_offset - d_offset);
  7155. got_addr = (htab->got->output_section->vma
  7156. + htab->got->output_offset
  7157. + (h->got.offset & ~1));
  7158. rel->r_info = ELF32_R_INFO (0, R_PPC_ADDR16_HA);
  7159. rel->r_addend = got_addr;
  7160. rel->r_offset = (p - contents) + d_offset;
  7161. insn &= ~0xffff;
  7162. insn |= ((unsigned int )(got_addr + 0x8000) >> 16) & 0xffff;
  7163. bfd_put_32 (output_bfd, insn, p);
  7164. /* Convert lis to lwz, loading address from GOT. */
  7165. insn &= ~0xffff;
  7166. insn ^= (32u ^ 15u) << 26;
  7167. insn |= (insn & (0x1f << 21)) >> 5;
  7168. insn |= got_addr & 0xffff;
  7169. bfd_put_32 (output_bfd, insn, p + 4);
  7170. bfd_put_32 (output_bfd, B | ((-4 - off) & 0x3ffffff), p + 8);
  7171. picfixup_size += 12;
  7172. /* Use one of the spare relocs, so --emit-relocs
  7173. output is reasonable. */
  7174. memmove (rel + 1, rel, (relend - rel - 1) * sizeof (*rel));
  7175. rel++;
  7176. rel->r_info = ELF32_R_INFO (0, R_PPC_ADDR16_LO);
  7177. rel->r_offset += 4;
  7178. /* Continue on as if we had a got reloc, to output
  7179. dynamic reloc. */
  7180. r_type = R_PPC_GOT16_LO;
  7181. }
  7182. else
  7183. info->callbacks->einfo
  7184. (_("%P: %H: error: %s with unexpected instruction %x\n"),
  7185. input_bfd, input_section, rel->r_offset,
  7186. "R_PPC_ADDR16_HA", insn);
  7187. }
  7188. else if (r_type == R_PPC_ADDR16_LO)
  7189. {
  7190. insn = bfd_get_32 (output_bfd,
  7191. contents + rel->r_offset - d_offset);
  7192. if ((insn & (0x3f << 26)) == 14u << 26 /* addi */
  7193. || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
  7194. || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
  7195. || (insn & (0x3f << 26)) == 36u << 26 /* stw */
  7196. || (insn & (0x3f << 26)) == 38u << 26 /* stb */
  7197. || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
  7198. || (insn & (0x3f << 26)) == 42u << 26 /* lha */
  7199. || (insn & (0x3f << 26)) == 44u << 26 /* sth */
  7200. || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
  7201. || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
  7202. || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
  7203. || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
  7204. || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
  7205. || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
  7206. || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
  7207. && (insn & 3) != 1)
  7208. || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */
  7209. && ((insn & 3) == 0 || (insn & 3) == 3)))
  7210. {
  7211. /* Arrange to apply the reloc addend, if any. */
  7212. relocation = 0;
  7213. unresolved_reloc = FALSE;
  7214. rel->r_info = ELF32_R_INFO (0, r_type);
  7215. }
  7216. else
  7217. info->callbacks->einfo
  7218. (_("%P: %H: error: %s with unexpected instruction %x\n"),
  7219. input_bfd, input_section, rel->r_offset,
  7220. "R_PPC_ADDR16_LO", insn);
  7221. }
  7222. }
  7223. ifunc = NULL;
  7224. if (!htab->is_vxworks)
  7225. {
  7226. struct plt_entry *ent;
  7227. if (h != NULL)
  7228. {
  7229. if (h->type == STT_GNU_IFUNC)
  7230. ifunc = &h->plt.plist;
  7231. }
  7232. else if (local_got_offsets != NULL
  7233. && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
  7234. {
  7235. struct plt_entry **local_plt;
  7236. local_plt = (struct plt_entry **) (local_got_offsets
  7237. + symtab_hdr->sh_info);
  7238. ifunc = local_plt + r_symndx;
  7239. }
  7240. ent = NULL;
  7241. if (ifunc != NULL
  7242. && (!bfd_link_pic (info)
  7243. || is_branch_reloc (r_type)))
  7244. {
  7245. addend = 0;
  7246. if (r_type == R_PPC_PLTREL24 && bfd_link_pic (info))
  7247. addend = rel->r_addend;
  7248. ent = find_plt_ent (ifunc, got2, addend);
  7249. }
  7250. if (ent != NULL)
  7251. {
  7252. if (h == NULL && (ent->plt.offset & 1) == 0)
  7253. {
  7254. Elf_Internal_Rela rela;
  7255. bfd_byte *loc;
  7256. rela.r_offset = (htab->iplt->output_section->vma
  7257. + htab->iplt->output_offset
  7258. + ent->plt.offset);
  7259. rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
  7260. rela.r_addend = relocation;
  7261. loc = htab->reliplt->contents;
  7262. loc += (htab->reliplt->reloc_count++
  7263. * sizeof (Elf32_External_Rela));
  7264. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  7265. ent->plt.offset |= 1;
  7266. }
  7267. if (h == NULL && (ent->glink_offset & 1) == 0)
  7268. {
  7269. unsigned char *p = ((unsigned char *) htab->glink->contents
  7270. + ent->glink_offset);
  7271. write_glink_stub (ent, htab->iplt, p, info);
  7272. ent->glink_offset |= 1;
  7273. }
  7274. unresolved_reloc = FALSE;
  7275. if (htab->plt_type == PLT_NEW
  7276. || !htab->elf.dynamic_sections_created
  7277. || h == NULL
  7278. || h->dynindx == -1)
  7279. relocation = (htab->glink->output_section->vma
  7280. + htab->glink->output_offset
  7281. + (ent->glink_offset & ~1));
  7282. else
  7283. relocation = (htab->plt->output_section->vma
  7284. + htab->plt->output_offset
  7285. + ent->plt.offset);
  7286. }
  7287. }
  7288. addend = rel->r_addend;
  7289. tls_type = 0;
  7290. howto = NULL;
  7291. if (r_type < R_PPC_max)
  7292. howto = ppc_elf_howto_table[r_type];
  7293. switch (r_type)
  7294. {
  7295. default:
  7296. info->callbacks->einfo
  7297. (_("%P: %B: unknown relocation type %d for symbol %s\n"),
  7298. input_bfd, (int) r_type, sym_name);
  7299. bfd_set_error (bfd_error_bad_value);
  7300. ret = FALSE;
  7301. continue;
  7302. case R_PPC_NONE:
  7303. case R_PPC_TLS:
  7304. case R_PPC_TLSGD:
  7305. case R_PPC_TLSLD:
  7306. case R_PPC_EMB_MRKREF:
  7307. case R_PPC_GNU_VTINHERIT:
  7308. case R_PPC_GNU_VTENTRY:
  7309. continue;
  7310. /* GOT16 relocations. Like an ADDR16 using the symbol's
  7311. address in the GOT as relocation value instead of the
  7312. symbol's value itself. Also, create a GOT entry for the
  7313. symbol and put the symbol value there. */
  7314. case R_PPC_GOT_TLSGD16:
  7315. case R_PPC_GOT_TLSGD16_LO:
  7316. case R_PPC_GOT_TLSGD16_HI:
  7317. case R_PPC_GOT_TLSGD16_HA:
  7318. tls_type = TLS_TLS | TLS_GD;
  7319. goto dogot;
  7320. case R_PPC_GOT_TLSLD16:
  7321. case R_PPC_GOT_TLSLD16_LO:
  7322. case R_PPC_GOT_TLSLD16_HI:
  7323. case R_PPC_GOT_TLSLD16_HA:
  7324. tls_type = TLS_TLS | TLS_LD;
  7325. goto dogot;
  7326. case R_PPC_GOT_TPREL16:
  7327. case R_PPC_GOT_TPREL16_LO:
  7328. case R_PPC_GOT_TPREL16_HI:
  7329. case R_PPC_GOT_TPREL16_HA:
  7330. tls_type = TLS_TLS | TLS_TPREL;
  7331. goto dogot;
  7332. case R_PPC_GOT_DTPREL16:
  7333. case R_PPC_GOT_DTPREL16_LO:
  7334. case R_PPC_GOT_DTPREL16_HI:
  7335. case R_PPC_GOT_DTPREL16_HA:
  7336. tls_type = TLS_TLS | TLS_DTPREL;
  7337. goto dogot;
  7338. case R_PPC_GOT16:
  7339. case R_PPC_GOT16_LO:
  7340. case R_PPC_GOT16_HI:
  7341. case R_PPC_GOT16_HA:
  7342. tls_mask = 0;
  7343. dogot:
  7344. {
  7345. /* Relocation is to the entry for this symbol in the global
  7346. offset table. */
  7347. bfd_vma off;
  7348. bfd_vma *offp;
  7349. unsigned long indx;
  7350. if (htab->got == NULL)
  7351. abort ();
  7352. indx = 0;
  7353. if (tls_type == (TLS_TLS | TLS_LD)
  7354. && (h == NULL
  7355. || !h->def_dynamic))
  7356. offp = &htab->tlsld_got.offset;
  7357. else if (h != NULL)
  7358. {
  7359. bfd_boolean dyn;
  7360. dyn = htab->elf.dynamic_sections_created;
  7361. if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
  7362. || (bfd_link_pic (info)
  7363. && SYMBOL_REFERENCES_LOCAL (info, h)))
  7364. /* This is actually a static link, or it is a
  7365. -Bsymbolic link and the symbol is defined
  7366. locally, or the symbol was forced to be local
  7367. because of a version file. */
  7368. ;
  7369. else
  7370. {
  7371. BFD_ASSERT (h->dynindx != -1);
  7372. indx = h->dynindx;
  7373. unresolved_reloc = FALSE;
  7374. }
  7375. offp = &h->got.offset;
  7376. }
  7377. else
  7378. {
  7379. if (local_got_offsets == NULL)
  7380. abort ();
  7381. offp = &local_got_offsets[r_symndx];
  7382. }
  7383. /* The offset must always be a multiple of 4. We use the
  7384. least significant bit to record whether we have already
  7385. processed this entry. */
  7386. off = *offp;
  7387. if ((off & 1) != 0)
  7388. off &= ~1;
  7389. else
  7390. {
  7391. unsigned int tls_m = (tls_mask
  7392. & (TLS_LD | TLS_GD | TLS_DTPREL
  7393. | TLS_TPREL | TLS_TPRELGD));
  7394. if (offp == &htab->tlsld_got.offset)
  7395. tls_m = TLS_LD;
  7396. else if (h == NULL
  7397. || !h->def_dynamic)
  7398. tls_m &= ~TLS_LD;
  7399. /* We might have multiple got entries for this sym.
  7400. Initialize them all. */
  7401. do
  7402. {
  7403. int tls_ty = 0;
  7404. if ((tls_m & TLS_LD) != 0)
  7405. {
  7406. tls_ty = TLS_TLS | TLS_LD;
  7407. tls_m &= ~TLS_LD;
  7408. }
  7409. else if ((tls_m & TLS_GD) != 0)
  7410. {
  7411. tls_ty = TLS_TLS | TLS_GD;
  7412. tls_m &= ~TLS_GD;
  7413. }
  7414. else if ((tls_m & TLS_DTPREL) != 0)
  7415. {
  7416. tls_ty = TLS_TLS | TLS_DTPREL;
  7417. tls_m &= ~TLS_DTPREL;
  7418. }
  7419. else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
  7420. {
  7421. tls_ty = TLS_TLS | TLS_TPREL;
  7422. tls_m = 0;
  7423. }
  7424. /* Generate relocs for the dynamic linker. */
  7425. if ((bfd_link_pic (info) || indx != 0)
  7426. && (offp == &htab->tlsld_got.offset
  7427. || h == NULL
  7428. || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  7429. || h->root.type != bfd_link_hash_undefweak))
  7430. {
  7431. asection *rsec = htab->relgot;
  7432. bfd_byte * loc;
  7433. if (ifunc != NULL)
  7434. rsec = htab->reliplt;
  7435. outrel.r_offset = (htab->got->output_section->vma
  7436. + htab->got->output_offset
  7437. + off);
  7438. outrel.r_addend = 0;
  7439. if (tls_ty & (TLS_LD | TLS_GD))
  7440. {
  7441. outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
  7442. if (tls_ty == (TLS_TLS | TLS_GD))
  7443. {
  7444. loc = rsec->contents;
  7445. loc += (rsec->reloc_count++
  7446. * sizeof (Elf32_External_Rela));
  7447. bfd_elf32_swap_reloca_out (output_bfd,
  7448. &outrel, loc);
  7449. outrel.r_offset += 4;
  7450. outrel.r_info
  7451. = ELF32_R_INFO (indx, R_PPC_DTPREL32);
  7452. }
  7453. }
  7454. else if (tls_ty == (TLS_TLS | TLS_DTPREL))
  7455. outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
  7456. else if (tls_ty == (TLS_TLS | TLS_TPREL))
  7457. outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
  7458. else if (indx != 0)
  7459. outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
  7460. else if (ifunc != NULL)
  7461. outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
  7462. else
  7463. outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
  7464. if (indx == 0 && tls_ty != (TLS_TLS | TLS_LD))
  7465. {
  7466. outrel.r_addend += relocation;
  7467. if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
  7468. {
  7469. if (htab->elf.tls_sec == NULL)
  7470. outrel.r_addend = 0;
  7471. else
  7472. outrel.r_addend -= htab->elf.tls_sec->vma;
  7473. }
  7474. }
  7475. loc = rsec->contents;
  7476. loc += (rsec->reloc_count++
  7477. * sizeof (Elf32_External_Rela));
  7478. bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
  7479. }
  7480. /* Init the .got section contents if we're not
  7481. emitting a reloc. */
  7482. else
  7483. {
  7484. bfd_vma value = relocation;
  7485. if (tls_ty == (TLS_TLS | TLS_LD))
  7486. value = 1;
  7487. else if (tls_ty != 0)
  7488. {
  7489. if (htab->elf.tls_sec == NULL)
  7490. value = 0;
  7491. else
  7492. {
  7493. value -= htab->elf.tls_sec->vma + DTP_OFFSET;
  7494. if (tls_ty == (TLS_TLS | TLS_TPREL))
  7495. value += DTP_OFFSET - TP_OFFSET;
  7496. }
  7497. if (tls_ty == (TLS_TLS | TLS_GD))
  7498. {
  7499. bfd_put_32 (output_bfd, value,
  7500. htab->got->contents + off + 4);
  7501. value = 1;
  7502. }
  7503. }
  7504. bfd_put_32 (output_bfd, value,
  7505. htab->got->contents + off);
  7506. }
  7507. off += 4;
  7508. if (tls_ty & (TLS_LD | TLS_GD))
  7509. off += 4;
  7510. }
  7511. while (tls_m != 0);
  7512. off = *offp;
  7513. *offp = off | 1;
  7514. }
  7515. if (off >= (bfd_vma) -2)
  7516. abort ();
  7517. if ((tls_type & TLS_TLS) != 0)
  7518. {
  7519. if (tls_type != (TLS_TLS | TLS_LD))
  7520. {
  7521. if ((tls_mask & TLS_LD) != 0
  7522. && !(h == NULL
  7523. || !h->def_dynamic))
  7524. off += 8;
  7525. if (tls_type != (TLS_TLS | TLS_GD))
  7526. {
  7527. if ((tls_mask & TLS_GD) != 0)
  7528. off += 8;
  7529. if (tls_type != (TLS_TLS | TLS_DTPREL))
  7530. {
  7531. if ((tls_mask & TLS_DTPREL) != 0)
  7532. off += 4;
  7533. }
  7534. }
  7535. }
  7536. }
  7537. /* If here for a picfixup, we're done. */
  7538. if (r_type != ELF32_R_TYPE (rel->r_info))
  7539. continue;
  7540. relocation = (htab->got->output_section->vma
  7541. + htab->got->output_offset
  7542. + off
  7543. - SYM_VAL (htab->elf.hgot));
  7544. /* Addends on got relocations don't make much sense.
  7545. x+off@got is actually x@got+off, and since the got is
  7546. generated by a hash table traversal, the value in the
  7547. got at entry m+n bears little relation to the entry m. */
  7548. if (addend != 0)
  7549. info->callbacks->einfo
  7550. (_("%P: %H: non-zero addend on %s reloc against `%s'\n"),
  7551. input_bfd, input_section, rel->r_offset,
  7552. howto->name,
  7553. sym_name);
  7554. }
  7555. break;
  7556. /* Relocations that need no special processing. */
  7557. case R_PPC_LOCAL24PC:
  7558. /* It makes no sense to point a local relocation
  7559. at a symbol not in this object. */
  7560. if (unresolved_reloc)
  7561. {
  7562. if (! (*info->callbacks->undefined_symbol) (info,
  7563. h->root.root.string,
  7564. input_bfd,
  7565. input_section,
  7566. rel->r_offset,
  7567. TRUE))
  7568. return FALSE;
  7569. continue;
  7570. }
  7571. break;
  7572. case R_PPC_DTPREL16:
  7573. case R_PPC_DTPREL16_LO:
  7574. case R_PPC_DTPREL16_HI:
  7575. case R_PPC_DTPREL16_HA:
  7576. if (htab->elf.tls_sec != NULL)
  7577. addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
  7578. break;
  7579. /* Relocations that may need to be propagated if this is a shared
  7580. object. */
  7581. case R_PPC_TPREL16:
  7582. case R_PPC_TPREL16_LO:
  7583. case R_PPC_TPREL16_HI:
  7584. case R_PPC_TPREL16_HA:
  7585. if (h != NULL
  7586. && h->root.type == bfd_link_hash_undefweak
  7587. && h->dynindx == -1)
  7588. {
  7589. /* Make this relocation against an undefined weak symbol
  7590. resolve to zero. This is really just a tweak, since
  7591. code using weak externs ought to check that they are
  7592. defined before using them. */
  7593. bfd_byte *p = contents + rel->r_offset - d_offset;
  7594. unsigned int insn = bfd_get_32 (output_bfd, p);
  7595. insn = _bfd_elf_ppc_at_tprel_transform (insn, 2);
  7596. if (insn != 0)
  7597. bfd_put_32 (output_bfd, insn, p);
  7598. break;
  7599. }
  7600. if (htab->elf.tls_sec != NULL)
  7601. addend -= htab->elf.tls_sec->vma + TP_OFFSET;
  7602. /* The TPREL16 relocs shouldn't really be used in shared
  7603. libs as they will result in DT_TEXTREL being set, but
  7604. support them anyway. */
  7605. goto dodyn;
  7606. case R_PPC_TPREL32:
  7607. if (htab->elf.tls_sec != NULL)
  7608. addend -= htab->elf.tls_sec->vma + TP_OFFSET;
  7609. goto dodyn;
  7610. case R_PPC_DTPREL32:
  7611. if (htab->elf.tls_sec != NULL)
  7612. addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
  7613. goto dodyn;
  7614. case R_PPC_DTPMOD32:
  7615. relocation = 1;
  7616. addend = 0;
  7617. goto dodyn;
  7618. case R_PPC_REL16:
  7619. case R_PPC_REL16_LO:
  7620. case R_PPC_REL16_HI:
  7621. case R_PPC_REL16_HA:
  7622. break;
  7623. case R_PPC_REL32:
  7624. if (h == NULL || h == htab->elf.hgot)
  7625. break;
  7626. /* fall through */
  7627. case R_PPC_ADDR32:
  7628. case R_PPC_ADDR16:
  7629. case R_PPC_ADDR16_LO:
  7630. case R_PPC_ADDR16_HI:
  7631. case R_PPC_ADDR16_HA:
  7632. case R_PPC_UADDR32:
  7633. case R_PPC_UADDR16:
  7634. goto dodyn;
  7635. case R_PPC_VLE_REL8:
  7636. case R_PPC_VLE_REL15:
  7637. case R_PPC_VLE_REL24:
  7638. case R_PPC_REL24:
  7639. case R_PPC_REL14:
  7640. case R_PPC_REL14_BRTAKEN:
  7641. case R_PPC_REL14_BRNTAKEN:
  7642. /* If these relocations are not to a named symbol, they can be
  7643. handled right here, no need to bother the dynamic linker. */
  7644. if (SYMBOL_CALLS_LOCAL (info, h)
  7645. || h == htab->elf.hgot)
  7646. break;
  7647. /* fall through */
  7648. case R_PPC_ADDR24:
  7649. case R_PPC_ADDR14:
  7650. case R_PPC_ADDR14_BRTAKEN:
  7651. case R_PPC_ADDR14_BRNTAKEN:
  7652. if (h != NULL && !bfd_link_pic (info))
  7653. break;
  7654. /* fall through */
  7655. dodyn:
  7656. if ((input_section->flags & SEC_ALLOC) == 0
  7657. || is_vxworks_tls)
  7658. break;
  7659. if ((bfd_link_pic (info)
  7660. && !(h != NULL
  7661. && ((h->root.type == bfd_link_hash_undefined
  7662. && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
  7663. || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
  7664. || (h->root.type == bfd_link_hash_undefweak
  7665. && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)))
  7666. && (must_be_dyn_reloc (info, r_type)
  7667. || !SYMBOL_CALLS_LOCAL (info, h)))
  7668. || (ELIMINATE_COPY_RELOCS
  7669. && !bfd_link_pic (info)
  7670. && h != NULL
  7671. && h->dynindx != -1
  7672. && !h->non_got_ref
  7673. && !h->def_regular
  7674. && !(h->protected_def
  7675. && ppc_elf_hash_entry (h)->has_addr16_ha
  7676. && ppc_elf_hash_entry (h)->has_addr16_lo
  7677. && htab->params->pic_fixup > 0)))
  7678. {
  7679. int skip;
  7680. bfd_byte *loc;
  7681. asection *sreloc;
  7682. #ifdef DEBUG
  7683. fprintf (stderr, "ppc_elf_relocate_section needs to "
  7684. "create relocation for %s\n",
  7685. (h && h->root.root.string
  7686. ? h->root.root.string : "<unknown>"));
  7687. #endif
  7688. /* When generating a shared object, these relocations
  7689. are copied into the output file to be resolved at run
  7690. time. */
  7691. sreloc = elf_section_data (input_section)->sreloc;
  7692. if (ifunc)
  7693. sreloc = htab->reliplt;
  7694. if (sreloc == NULL)
  7695. return FALSE;
  7696. skip = 0;
  7697. outrel.r_offset = _bfd_elf_section_offset (output_bfd, info,
  7698. input_section,
  7699. rel->r_offset);
  7700. if (outrel.r_offset == (bfd_vma) -1
  7701. || outrel.r_offset == (bfd_vma) -2)
  7702. skip = (int) outrel.r_offset;
  7703. outrel.r_offset += (input_section->output_section->vma
  7704. + input_section->output_offset);
  7705. if (skip)
  7706. memset (&outrel, 0, sizeof outrel);
  7707. else if ((h != NULL
  7708. && (h->root.type == bfd_link_hash_undefined
  7709. || h->root.type == bfd_link_hash_undefweak))
  7710. || !SYMBOL_REFERENCES_LOCAL (info, h))
  7711. {
  7712. BFD_ASSERT (h->dynindx != -1);
  7713. unresolved_reloc = FALSE;
  7714. outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
  7715. outrel.r_addend = rel->r_addend;
  7716. }
  7717. else
  7718. {
  7719. outrel.r_addend = relocation + rel->r_addend;
  7720. if (r_type != R_PPC_ADDR32)
  7721. {
  7722. long indx = 0;
  7723. if (ifunc != NULL)
  7724. {
  7725. /* If we get here when building a static
  7726. executable, then the libc startup function
  7727. responsible for applying indirect function
  7728. relocations is going to complain about
  7729. the reloc type.
  7730. If we get here when building a dynamic
  7731. executable, it will be because we have
  7732. a text relocation. The dynamic loader
  7733. will set the text segment writable and
  7734. non-executable to apply text relocations.
  7735. So we'll segfault when trying to run the
  7736. indirection function to resolve the reloc. */
  7737. info->callbacks->einfo
  7738. (_("%P: %H: relocation %s for indirect "
  7739. "function %s unsupported\n"),
  7740. input_bfd, input_section, rel->r_offset,
  7741. howto->name,
  7742. sym_name);
  7743. ret = FALSE;
  7744. }
  7745. else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec))
  7746. ;
  7747. else if (sec == NULL || sec->owner == NULL)
  7748. {
  7749. bfd_set_error (bfd_error_bad_value);
  7750. ret = FALSE;
  7751. }
  7752. else
  7753. {
  7754. asection *osec;
  7755. /* We are turning this relocation into one
  7756. against a section symbol. It would be
  7757. proper to subtract the symbol's value,
  7758. osec->vma, from the emitted reloc addend,
  7759. but ld.so expects buggy relocs.
  7760. FIXME: Why not always use a zero index? */
  7761. osec = sec->output_section;
  7762. indx = elf_section_data (osec)->dynindx;
  7763. if (indx == 0)
  7764. {
  7765. osec = htab->elf.text_index_section;
  7766. indx = elf_section_data (osec)->dynindx;
  7767. }
  7768. BFD_ASSERT (indx != 0);
  7769. #ifdef DEBUG
  7770. if (indx == 0)
  7771. printf ("indx=%ld section=%s flags=%08x name=%s\n",
  7772. indx, osec->name, osec->flags,
  7773. h->root.root.string);
  7774. #endif
  7775. }
  7776. outrel.r_info = ELF32_R_INFO (indx, r_type);
  7777. }
  7778. else if (ifunc != NULL)
  7779. outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
  7780. else
  7781. outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
  7782. }
  7783. loc = sreloc->contents;
  7784. loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
  7785. bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
  7786. if (skip == -1)
  7787. continue;
  7788. /* This reloc will be computed at runtime. We clear the memory
  7789. so that it contains predictable value. */
  7790. if (! skip
  7791. && ((input_section->flags & SEC_ALLOC) != 0
  7792. || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
  7793. {
  7794. relocation = howto->pc_relative ? outrel.r_offset : 0;
  7795. addend = 0;
  7796. break;
  7797. }
  7798. }
  7799. break;
  7800. case R_PPC_RELAX_PLT:
  7801. case R_PPC_RELAX_PLTREL24:
  7802. if (h != NULL)
  7803. {
  7804. struct plt_entry *ent;
  7805. bfd_vma got2_addend = 0;
  7806. if (r_type == R_PPC_RELAX_PLTREL24)
  7807. {
  7808. if (bfd_link_pic (info))
  7809. got2_addend = addend;
  7810. addend = 0;
  7811. }
  7812. ent = find_plt_ent (&h->plt.plist, got2, got2_addend);
  7813. if (htab->plt_type == PLT_NEW)
  7814. relocation = (htab->glink->output_section->vma
  7815. + htab->glink->output_offset
  7816. + ent->glink_offset);
  7817. else
  7818. relocation = (htab->plt->output_section->vma
  7819. + htab->plt->output_offset
  7820. + ent->plt.offset);
  7821. }
  7822. /* Fall thru */
  7823. case R_PPC_RELAX:
  7824. {
  7825. const int *stub;
  7826. size_t size;
  7827. size_t insn_offset = rel->r_offset;
  7828. unsigned int insn;
  7829. if (bfd_link_pic (info))
  7830. {
  7831. relocation -= (input_section->output_section->vma
  7832. + input_section->output_offset
  7833. + rel->r_offset - 4);
  7834. stub = shared_stub_entry;
  7835. bfd_put_32 (output_bfd, stub[0], contents + insn_offset - 12);
  7836. bfd_put_32 (output_bfd, stub[1], contents + insn_offset - 8);
  7837. bfd_put_32 (output_bfd, stub[2], contents + insn_offset - 4);
  7838. stub += 3;
  7839. size = ARRAY_SIZE (shared_stub_entry) - 3;
  7840. }
  7841. else
  7842. {
  7843. stub = stub_entry;
  7844. size = ARRAY_SIZE (stub_entry);
  7845. }
  7846. relocation += addend;
  7847. if (bfd_link_relocatable (info))
  7848. relocation = 0;
  7849. /* First insn is HA, second is LO. */
  7850. insn = *stub++;
  7851. insn |= ((relocation + 0x8000) >> 16) & 0xffff;
  7852. bfd_put_32 (output_bfd, insn, contents + insn_offset);
  7853. insn_offset += 4;
  7854. insn = *stub++;
  7855. insn |= relocation & 0xffff;
  7856. bfd_put_32 (output_bfd, insn, contents + insn_offset);
  7857. insn_offset += 4;
  7858. size -= 2;
  7859. while (size != 0)
  7860. {
  7861. insn = *stub++;
  7862. --size;
  7863. bfd_put_32 (output_bfd, insn, contents + insn_offset);
  7864. insn_offset += 4;
  7865. }
  7866. /* Rewrite the reloc and convert one of the trailing nop
  7867. relocs to describe this relocation. */
  7868. BFD_ASSERT (ELF32_R_TYPE (relend[-1].r_info) == R_PPC_NONE);
  7869. /* The relocs are at the bottom 2 bytes */
  7870. rel[0].r_offset += d_offset;
  7871. memmove (rel + 1, rel, (relend - rel - 1) * sizeof (*rel));
  7872. rel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA);
  7873. rel[1].r_offset += 4;
  7874. rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO);
  7875. rel++;
  7876. }
  7877. continue;
  7878. /* Indirect .sdata relocation. */
  7879. case R_PPC_EMB_SDAI16:
  7880. BFD_ASSERT (htab->sdata[0].section != NULL);
  7881. if (!is_static_defined (htab->sdata[0].sym))
  7882. {
  7883. unresolved_reloc = TRUE;
  7884. break;
  7885. }
  7886. relocation
  7887. = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0],
  7888. h, relocation, rel);
  7889. addend = 0;
  7890. break;
  7891. /* Indirect .sdata2 relocation. */
  7892. case R_PPC_EMB_SDA2I16:
  7893. BFD_ASSERT (htab->sdata[1].section != NULL);
  7894. if (!is_static_defined (htab->sdata[1].sym))
  7895. {
  7896. unresolved_reloc = TRUE;
  7897. break;
  7898. }
  7899. relocation
  7900. = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1],
  7901. h, relocation, rel);
  7902. addend = 0;
  7903. break;
  7904. /* Handle the TOC16 reloc. We want to use the offset within the .got
  7905. section, not the actual VMA. This is appropriate when generating
  7906. an embedded ELF object, for which the .got section acts like the
  7907. AIX .toc section. */
  7908. case R_PPC_TOC16: /* phony GOT16 relocations */
  7909. if (sec == NULL || sec->output_section == NULL)
  7910. {
  7911. unresolved_reloc = TRUE;
  7912. break;
  7913. }
  7914. BFD_ASSERT (strcmp (bfd_get_section_name (sec->owner, sec),
  7915. ".got") == 0
  7916. || strcmp (bfd_get_section_name (sec->owner, sec),
  7917. ".cgot") == 0);
  7918. addend -= sec->output_section->vma + sec->output_offset + 0x8000;
  7919. break;
  7920. case R_PPC_PLTREL24:
  7921. if (h != NULL && ifunc == NULL)
  7922. {
  7923. struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2,
  7924. bfd_link_pic (info) ? addend : 0);
  7925. if (ent == NULL
  7926. || htab->plt == NULL)
  7927. {
  7928. /* We didn't make a PLT entry for this symbol. This
  7929. happens when statically linking PIC code, or when
  7930. using -Bsymbolic. */
  7931. }
  7932. else
  7933. {
  7934. /* Relocation is to the entry for this symbol in the
  7935. procedure linkage table. */
  7936. unresolved_reloc = FALSE;
  7937. if (htab->plt_type == PLT_NEW)
  7938. relocation = (htab->glink->output_section->vma
  7939. + htab->glink->output_offset
  7940. + ent->glink_offset);
  7941. else
  7942. relocation = (htab->plt->output_section->vma
  7943. + htab->plt->output_offset
  7944. + ent->plt.offset);
  7945. }
  7946. }
  7947. /* R_PPC_PLTREL24 is rather special. If non-zero, the
  7948. addend specifies the GOT pointer offset within .got2.
  7949. Don't apply it to the relocation field. */
  7950. addend = 0;
  7951. break;
  7952. /* Relocate against _SDA_BASE_. */
  7953. case R_PPC_SDAREL16:
  7954. {
  7955. const char *name;
  7956. struct elf_link_hash_entry *sda = htab->sdata[0].sym;
  7957. if (sec == NULL
  7958. || sec->output_section == NULL
  7959. || !is_static_defined (sda))
  7960. {
  7961. unresolved_reloc = TRUE;
  7962. break;
  7963. }
  7964. addend -= SYM_VAL (sda);
  7965. name = bfd_get_section_name (output_bfd, sec->output_section);
  7966. if (!(strcmp (name, ".sdata") == 0
  7967. || strcmp (name, ".sbss") == 0))
  7968. {
  7969. info->callbacks->einfo
  7970. (_("%P: %B: the target (%s) of a %s relocation is "
  7971. "in the wrong output section (%s)\n"),
  7972. input_bfd,
  7973. sym_name,
  7974. howto->name,
  7975. name);
  7976. }
  7977. }
  7978. break;
  7979. /* Relocate against _SDA2_BASE_. */
  7980. case R_PPC_EMB_SDA2REL:
  7981. {
  7982. const char *name;
  7983. struct elf_link_hash_entry *sda = htab->sdata[1].sym;
  7984. if (sec == NULL
  7985. || sec->output_section == NULL
  7986. || !is_static_defined (sda))
  7987. {
  7988. unresolved_reloc = TRUE;
  7989. break;
  7990. }
  7991. addend -= SYM_VAL (sda);
  7992. name = bfd_get_section_name (output_bfd, sec->output_section);
  7993. if (!(strcmp (name, ".sdata2") == 0
  7994. || strcmp (name, ".sbss2") == 0))
  7995. {
  7996. info->callbacks->einfo
  7997. (_("%P: %B: the target (%s) of a %s relocation is "
  7998. "in the wrong output section (%s)\n"),
  7999. input_bfd,
  8000. sym_name,
  8001. howto->name,
  8002. name);
  8003. }
  8004. }
  8005. break;
  8006. case R_PPC_VLE_LO16A:
  8007. relocation = relocation + addend;
  8008. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8009. relocation, split16a_type);
  8010. continue;
  8011. case R_PPC_VLE_LO16D:
  8012. relocation = relocation + addend;
  8013. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8014. relocation, split16d_type);
  8015. continue;
  8016. case R_PPC_VLE_HI16A:
  8017. relocation = (relocation + addend) >> 16;
  8018. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8019. relocation, split16a_type);
  8020. continue;
  8021. case R_PPC_VLE_HI16D:
  8022. relocation = (relocation + addend) >> 16;
  8023. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8024. relocation, split16d_type);
  8025. continue;
  8026. case R_PPC_VLE_HA16A:
  8027. relocation = (relocation + addend + 0x8000) >> 16;
  8028. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8029. relocation, split16a_type);
  8030. continue;
  8031. case R_PPC_VLE_HA16D:
  8032. relocation = (relocation + addend + 0x8000) >> 16;
  8033. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8034. relocation, split16d_type);
  8035. continue;
  8036. /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
  8037. case R_PPC_EMB_SDA21:
  8038. case R_PPC_VLE_SDA21:
  8039. case R_PPC_EMB_RELSDA:
  8040. case R_PPC_VLE_SDA21_LO:
  8041. {
  8042. const char *name;
  8043. int reg;
  8044. unsigned int insn;
  8045. struct elf_link_hash_entry *sda = NULL;
  8046. if (sec == NULL || sec->output_section == NULL)
  8047. {
  8048. unresolved_reloc = TRUE;
  8049. break;
  8050. }
  8051. name = bfd_get_section_name (output_bfd, sec->output_section);
  8052. if (strcmp (name, ".sdata") == 0
  8053. || strcmp (name, ".sbss") == 0)
  8054. {
  8055. reg = 13;
  8056. sda = htab->sdata[0].sym;
  8057. }
  8058. else if (strcmp (name, ".sdata2") == 0
  8059. || strcmp (name, ".sbss2") == 0)
  8060. {
  8061. reg = 2;
  8062. sda = htab->sdata[1].sym;
  8063. }
  8064. else if (strcmp (name, ".PPC.EMB.sdata0") == 0
  8065. || strcmp (name, ".PPC.EMB.sbss0") == 0)
  8066. {
  8067. reg = 0;
  8068. }
  8069. else
  8070. {
  8071. info->callbacks->einfo
  8072. (_("%P: %B: the target (%s) of a %s relocation is "
  8073. "in the wrong output section (%s)\n"),
  8074. input_bfd,
  8075. sym_name,
  8076. howto->name,
  8077. name);
  8078. bfd_set_error (bfd_error_bad_value);
  8079. ret = FALSE;
  8080. continue;
  8081. }
  8082. if (sda != NULL)
  8083. {
  8084. if (!is_static_defined (sda))
  8085. {
  8086. unresolved_reloc = TRUE;
  8087. break;
  8088. }
  8089. addend -= SYM_VAL (sda);
  8090. }
  8091. insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
  8092. if (reg == 0
  8093. && (r_type == R_PPC_VLE_SDA21
  8094. || r_type == R_PPC_VLE_SDA21_LO))
  8095. {
  8096. relocation = relocation + addend;
  8097. addend = 0;
  8098. /* Force e_li insn, keeping RT from original insn. */
  8099. insn &= 0x1f << 21;
  8100. insn |= 28u << 26;
  8101. /* We have an li20 field, bits 17..20, 11..15, 21..31. */
  8102. /* Top 4 bits of value to 17..20. */
  8103. insn |= (relocation & 0xf0000) >> 5;
  8104. /* Next 5 bits of the value to 11..15. */
  8105. insn |= (relocation & 0xf800) << 5;
  8106. /* And the final 11 bits of the value to bits 21 to 31. */
  8107. insn |= relocation & 0x7ff;
  8108. bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
  8109. if (r_type == R_PPC_VLE_SDA21
  8110. && ((relocation + 0x80000) & 0xffffffff) > 0x100000)
  8111. goto overflow;
  8112. continue;
  8113. }
  8114. else if (r_type == R_PPC_EMB_SDA21
  8115. || r_type == R_PPC_VLE_SDA21
  8116. || r_type == R_PPC_VLE_SDA21_LO)
  8117. {
  8118. /* Fill in register field. */
  8119. insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
  8120. }
  8121. bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
  8122. }
  8123. break;
  8124. case R_PPC_VLE_SDAREL_LO16A:
  8125. case R_PPC_VLE_SDAREL_LO16D:
  8126. case R_PPC_VLE_SDAREL_HI16A:
  8127. case R_PPC_VLE_SDAREL_HI16D:
  8128. case R_PPC_VLE_SDAREL_HA16A:
  8129. case R_PPC_VLE_SDAREL_HA16D:
  8130. {
  8131. bfd_vma value;
  8132. const char *name;
  8133. //int reg;
  8134. struct elf_link_hash_entry *sda = NULL;
  8135. if (sec == NULL || sec->output_section == NULL)
  8136. {
  8137. unresolved_reloc = TRUE;
  8138. break;
  8139. }
  8140. name = bfd_get_section_name (output_bfd, sec->output_section);
  8141. if (strcmp (name, ".sdata") == 0
  8142. || strcmp (name, ".sbss") == 0)
  8143. {
  8144. //reg = 13;
  8145. sda = htab->sdata[0].sym;
  8146. }
  8147. else if (strcmp (name, ".sdata2") == 0
  8148. || strcmp (name, ".sbss2") == 0)
  8149. {
  8150. //reg = 2;
  8151. sda = htab->sdata[1].sym;
  8152. }
  8153. else
  8154. {
  8155. (*_bfd_error_handler)
  8156. (_("%B: the target (%s) of a %s relocation is "
  8157. "in the wrong output section (%s)"),
  8158. input_bfd,
  8159. sym_name,
  8160. howto->name,
  8161. name);
  8162. bfd_set_error (bfd_error_bad_value);
  8163. ret = FALSE;
  8164. continue;
  8165. }
  8166. if (sda != NULL)
  8167. {
  8168. if (!is_static_defined (sda))
  8169. {
  8170. unresolved_reloc = TRUE;
  8171. break;
  8172. }
  8173. }
  8174. value = (sda->root.u.def.section->output_section->vma
  8175. + sda->root.u.def.section->output_offset
  8176. + addend);
  8177. if (r_type == R_PPC_VLE_SDAREL_LO16A)
  8178. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8179. value, split16a_type);
  8180. else if (r_type == R_PPC_VLE_SDAREL_LO16D)
  8181. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8182. value, split16d_type);
  8183. else if (r_type == R_PPC_VLE_SDAREL_HI16A)
  8184. {
  8185. value = value >> 16;
  8186. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8187. value, split16a_type);
  8188. }
  8189. else if (r_type == R_PPC_VLE_SDAREL_HI16D)
  8190. {
  8191. value = value >> 16;
  8192. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8193. value, split16d_type);
  8194. }
  8195. else if (r_type == R_PPC_VLE_SDAREL_HA16A)
  8196. {
  8197. value = (value + 0x8000) >> 16;
  8198. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8199. value, split16a_type);
  8200. }
  8201. else if (r_type == R_PPC_VLE_SDAREL_HA16D)
  8202. {
  8203. value = (value + 0x8000) >> 16;
  8204. ppc_elf_vle_split16 (output_bfd, contents + rel->r_offset,
  8205. value, split16d_type);
  8206. }
  8207. }
  8208. continue;
  8209. /* Relocate against the beginning of the section. */
  8210. case R_PPC_SECTOFF:
  8211. case R_PPC_SECTOFF_LO:
  8212. case R_PPC_SECTOFF_HI:
  8213. case R_PPC_SECTOFF_HA:
  8214. if (sec == NULL || sec->output_section == NULL)
  8215. {
  8216. unresolved_reloc = TRUE;
  8217. break;
  8218. }
  8219. addend -= sec->output_section->vma;
  8220. break;
  8221. /* Negative relocations. */
  8222. case R_PPC_EMB_NADDR32:
  8223. case R_PPC_EMB_NADDR16:
  8224. case R_PPC_EMB_NADDR16_LO:
  8225. case R_PPC_EMB_NADDR16_HI:
  8226. case R_PPC_EMB_NADDR16_HA:
  8227. addend -= 2 * relocation;
  8228. break;
  8229. case R_PPC_COPY:
  8230. case R_PPC_GLOB_DAT:
  8231. case R_PPC_JMP_SLOT:
  8232. case R_PPC_RELATIVE:
  8233. case R_PPC_IRELATIVE:
  8234. case R_PPC_PLT32:
  8235. case R_PPC_PLTREL32:
  8236. case R_PPC_PLT16_LO:
  8237. case R_PPC_PLT16_HI:
  8238. case R_PPC_PLT16_HA:
  8239. case R_PPC_ADDR30:
  8240. case R_PPC_EMB_RELSEC16:
  8241. case R_PPC_EMB_RELST_LO:
  8242. case R_PPC_EMB_RELST_HI:
  8243. case R_PPC_EMB_RELST_HA:
  8244. case R_PPC_EMB_BIT_FLD:
  8245. info->callbacks->einfo
  8246. (_("%P: %B: relocation %s is not yet supported for symbol %s\n"),
  8247. input_bfd,
  8248. howto->name,
  8249. sym_name);
  8250. bfd_set_error (bfd_error_invalid_operation);
  8251. ret = FALSE;
  8252. continue;
  8253. }
  8254. /* Do any further special processing. */
  8255. switch (r_type)
  8256. {
  8257. default:
  8258. break;
  8259. case R_PPC_ADDR16_HA:
  8260. case R_PPC_REL16_HA:
  8261. case R_PPC_SECTOFF_HA:
  8262. case R_PPC_TPREL16_HA:
  8263. case R_PPC_DTPREL16_HA:
  8264. case R_PPC_EMB_NADDR16_HA:
  8265. case R_PPC_EMB_RELST_HA:
  8266. /* It's just possible that this symbol is a weak symbol
  8267. that's not actually defined anywhere. In that case,
  8268. 'sec' would be NULL, and we should leave the symbol
  8269. alone (it will be set to zero elsewhere in the link). */
  8270. if (sec == NULL)
  8271. break;
  8272. /* Fall thru */
  8273. case R_PPC_PLT16_HA:
  8274. case R_PPC_GOT16_HA:
  8275. case R_PPC_GOT_TLSGD16_HA:
  8276. case R_PPC_GOT_TLSLD16_HA:
  8277. case R_PPC_GOT_TPREL16_HA:
  8278. case R_PPC_GOT_DTPREL16_HA:
  8279. /* Add 0x10000 if sign bit in 0:15 is set.
  8280. Bits 0:15 are not used. */
  8281. addend += 0x8000;
  8282. break;
  8283. case R_PPC_ADDR16:
  8284. case R_PPC_ADDR16_LO:
  8285. case R_PPC_GOT16:
  8286. case R_PPC_GOT16_LO:
  8287. case R_PPC_SDAREL16:
  8288. case R_PPC_SECTOFF:
  8289. case R_PPC_SECTOFF_LO:
  8290. case R_PPC_DTPREL16:
  8291. case R_PPC_DTPREL16_LO:
  8292. case R_PPC_TPREL16:
  8293. case R_PPC_TPREL16_LO:
  8294. case R_PPC_GOT_TLSGD16:
  8295. case R_PPC_GOT_TLSGD16_LO:
  8296. case R_PPC_GOT_TLSLD16:
  8297. case R_PPC_GOT_TLSLD16_LO:
  8298. case R_PPC_GOT_DTPREL16:
  8299. case R_PPC_GOT_DTPREL16_LO:
  8300. case R_PPC_GOT_TPREL16:
  8301. case R_PPC_GOT_TPREL16_LO:
  8302. {
  8303. /* The 32-bit ABI lacks proper relocations to deal with
  8304. certain 64-bit instructions. Prevent damage to bits
  8305. that make up part of the insn opcode. */
  8306. unsigned int insn, mask, lobit;
  8307. insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
  8308. mask = 0;
  8309. if (is_insn_ds_form (insn))
  8310. mask = 3;
  8311. else if (is_insn_dq_form (insn))
  8312. mask = 15;
  8313. else
  8314. break;
  8315. lobit = mask & (relocation + addend);
  8316. if (lobit != 0)
  8317. {
  8318. addend -= lobit;
  8319. info->callbacks->einfo
  8320. (_("%P: %H: error: %s against `%s' not a multiple of %u\n"),
  8321. input_bfd, input_section, rel->r_offset,
  8322. howto->name, sym_name, mask + 1);
  8323. bfd_set_error (bfd_error_bad_value);
  8324. ret = FALSE;
  8325. }
  8326. addend += insn & mask;
  8327. }
  8328. break;
  8329. }
  8330. #ifdef DEBUG
  8331. fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, "
  8332. "offset = %ld, addend = %ld\n",
  8333. howto->name,
  8334. (int) r_type,
  8335. sym_name,
  8336. r_symndx,
  8337. (long) rel->r_offset,
  8338. (long) addend);
  8339. #endif
  8340. if (unresolved_reloc
  8341. && !((input_section->flags & SEC_DEBUGGING) != 0
  8342. && h->def_dynamic)
  8343. && _bfd_elf_section_offset (output_bfd, info, input_section,
  8344. rel->r_offset) != (bfd_vma) -1)
  8345. {
  8346. info->callbacks->einfo
  8347. (_("%P: %H: unresolvable %s relocation against symbol `%s'\n"),
  8348. input_bfd, input_section, rel->r_offset,
  8349. howto->name,
  8350. sym_name);
  8351. ret = FALSE;
  8352. }
  8353. /* 16-bit fields in insns mostly have signed values, but a
  8354. few insns have 16-bit unsigned values. Really, we should
  8355. have different reloc types. */
  8356. if (howto->complain_on_overflow != complain_overflow_dont
  8357. && howto->dst_mask == 0xffff
  8358. && (input_section->flags & SEC_CODE) != 0)
  8359. {
  8360. enum complain_overflow complain = complain_overflow_signed;
  8361. if ((elf_section_flags (input_section) & SHF_PPC_VLE) == 0)
  8362. {
  8363. unsigned int insn;
  8364. insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
  8365. if ((insn & (0x3f << 26)) == 10u << 26 /* cmpli */)
  8366. complain = complain_overflow_bitfield;
  8367. else if ((insn & (0x3f << 26)) == 28u << 26 /* andi */
  8368. || (insn & (0x3f << 26)) == 24u << 26 /* ori */
  8369. || (insn & (0x3f << 26)) == 26u << 26 /* xori */)
  8370. complain = complain_overflow_unsigned;
  8371. }
  8372. if (howto->complain_on_overflow != complain)
  8373. {
  8374. alt_howto = *howto;
  8375. alt_howto.complain_on_overflow = complain;
  8376. howto = &alt_howto;
  8377. }
  8378. }
  8379. r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
  8380. rel->r_offset, relocation, addend);
  8381. if (r != bfd_reloc_ok)
  8382. {
  8383. if (r == bfd_reloc_overflow)
  8384. {
  8385. overflow:
  8386. /* On code like "if (foo) foo();" don't report overflow
  8387. on a branch to zero when foo is undefined. */
  8388. if (!warned
  8389. && !(h != NULL
  8390. && (h->root.type == bfd_link_hash_undefweak
  8391. || h->root.type == bfd_link_hash_undefined)
  8392. && is_branch_reloc (r_type)))
  8393. {
  8394. if (!((*info->callbacks->reloc_overflow)
  8395. (info, (h ? &h->root : NULL), sym_name,
  8396. howto->name, rel->r_addend,
  8397. input_bfd, input_section, rel->r_offset)))
  8398. return FALSE;
  8399. }
  8400. }
  8401. else
  8402. {
  8403. info->callbacks->einfo
  8404. (_("%P: %H: %s reloc against `%s': error %d\n"),
  8405. input_bfd, input_section, rel->r_offset,
  8406. howto->name, sym_name, (int) r);
  8407. ret = FALSE;
  8408. }
  8409. }
  8410. }
  8411. #ifdef DEBUG
  8412. fprintf (stderr, "\n");
  8413. #endif
  8414. if (input_section->sec_info_type == SEC_INFO_TYPE_TARGET
  8415. && input_section->size != input_section->rawsize
  8416. && (strcmp (input_section->output_section->name, ".init") == 0
  8417. || strcmp (input_section->output_section->name, ".fini") == 0))
  8418. {
  8419. /* Branch around the trampolines. */
  8420. unsigned int insn = B + input_section->size - input_section->rawsize;
  8421. bfd_put_32 (input_bfd, insn, contents + input_section->rawsize);
  8422. }
  8423. if (htab->params->ppc476_workaround
  8424. && input_section->sec_info_type == SEC_INFO_TYPE_TARGET
  8425. && (!bfd_link_relocatable (info)
  8426. || (input_section->output_section->alignment_power
  8427. >= htab->params->pagesize_p2)))
  8428. {
  8429. bfd_vma start_addr, end_addr, addr;
  8430. bfd_vma pagesize = (bfd_vma) 1 << htab->params->pagesize_p2;
  8431. if (relax_info->workaround_size != 0)
  8432. {
  8433. bfd_byte *p;
  8434. unsigned int n;
  8435. bfd_byte fill[4];
  8436. bfd_put_32 (input_bfd, BA, fill);
  8437. p = contents + input_section->size - relax_info->workaround_size;
  8438. n = relax_info->workaround_size >> 2;
  8439. while (n--)
  8440. {
  8441. memcpy (p, fill, 4);
  8442. p += 4;
  8443. }
  8444. }
  8445. /* The idea is: Replace the last instruction on a page with a
  8446. branch to a patch area. Put the insn there followed by a
  8447. branch back to the next page. Complicated a little by
  8448. needing to handle moved conditional branches, and by not
  8449. wanting to touch data-in-text. */
  8450. start_addr = (input_section->output_section->vma
  8451. + input_section->output_offset);
  8452. end_addr = (start_addr + input_section->size
  8453. - relax_info->workaround_size);
  8454. for (addr = ((start_addr & -pagesize) + pagesize - 4);
  8455. addr < end_addr;
  8456. addr += pagesize)
  8457. {
  8458. bfd_vma offset = addr - start_addr;
  8459. Elf_Internal_Rela *lo, *hi;
  8460. bfd_boolean is_data;
  8461. bfd_vma patch_off, patch_addr;
  8462. unsigned int insn;
  8463. /* Do we have a data reloc at this offset? If so, leave
  8464. the word alone. */
  8465. is_data = FALSE;
  8466. lo = relocs;
  8467. hi = relend;
  8468. rel = NULL;
  8469. while (lo < hi)
  8470. {
  8471. rel = lo + (hi - lo) / 2;
  8472. if (rel->r_offset < offset)
  8473. lo = rel + 1;
  8474. else if (rel->r_offset > offset + 3)
  8475. hi = rel;
  8476. else
  8477. {
  8478. switch (ELF32_R_TYPE (rel->r_info))
  8479. {
  8480. case R_PPC_ADDR32:
  8481. case R_PPC_UADDR32:
  8482. case R_PPC_REL32:
  8483. case R_PPC_ADDR30:
  8484. is_data = TRUE;
  8485. break;
  8486. default:
  8487. break;
  8488. }
  8489. break;
  8490. }
  8491. }
  8492. if (is_data)
  8493. continue;
  8494. /* Some instructions can be left alone too. Unconditional
  8495. branches, except for bcctr with BO=0x14 (bctr, bctrl),
  8496. avoid the icache failure.
  8497. The problem occurs due to prefetch across a page boundary
  8498. where stale instructions can be fetched from the next
  8499. page, and the mechanism for flushing these bad
  8500. instructions fails under certain circumstances. The
  8501. unconditional branches:
  8502. 1) Branch: b, bl, ba, bla,
  8503. 2) Branch Conditional: bc, bca, bcl, bcla,
  8504. 3) Branch Conditional to Link Register: bclr, bclrl,
  8505. where (2) and (3) have BO=0x14 making them unconditional,
  8506. prevent the bad prefetch because the prefetch itself is
  8507. affected by these instructions. This happens even if the
  8508. instruction is not executed.
  8509. A bctr example:
  8510. .
  8511. . lis 9,new_page@ha
  8512. . addi 9,9,new_page@l
  8513. . mtctr 9
  8514. . bctr
  8515. . nop
  8516. . nop
  8517. . new_page:
  8518. .
  8519. The bctr is not predicted taken due to ctr not being
  8520. ready, so prefetch continues on past the bctr into the
  8521. new page which might have stale instructions. If they
  8522. fail to be flushed, then they will be executed after the
  8523. bctr executes. Either of the following modifications
  8524. prevent the bad prefetch from happening in the first
  8525. place:
  8526. .
  8527. . lis 9,new_page@ha lis 9,new_page@ha
  8528. . addi 9,9,new_page@l addi 9,9,new_page@l
  8529. . mtctr 9 mtctr 9
  8530. . bctr bctr
  8531. . nop b somewhere_else
  8532. . b somewhere_else nop
  8533. . new_page: new_page:
  8534. . */
  8535. insn = bfd_get_32 (input_bfd, contents + offset);
  8536. if ((insn & (0x3f << 26)) == (18u << 26) /* b,bl,ba,bla */
  8537. || ((insn & (0x3f << 26)) == (16u << 26) /* bc,bcl,bca,bcla*/
  8538. && (insn & (0x14 << 21)) == (0x14 << 21)) /* with BO=0x14 */
  8539. || ((insn & (0x3f << 26)) == (19u << 26)
  8540. && (insn & (0x3ff << 1)) == (16u << 1) /* bclr,bclrl */
  8541. && (insn & (0x14 << 21)) == (0x14 << 21)))/* with BO=0x14 */
  8542. continue;
  8543. patch_addr = (start_addr + input_section->size
  8544. - relax_info->workaround_size);
  8545. patch_addr = (patch_addr + 15) & -16;
  8546. patch_off = patch_addr - start_addr;
  8547. bfd_put_32 (input_bfd, B + patch_off - offset, contents + offset);
  8548. if (rel != NULL
  8549. && rel->r_offset >= offset
  8550. && rel->r_offset < offset + 4)
  8551. {
  8552. asection *sreloc;
  8553. /* If the insn we are patching had a reloc, adjust the
  8554. reloc r_offset so that the reloc applies to the moved
  8555. location. This matters for -r and --emit-relocs. */
  8556. if (rel + 1 != relend)
  8557. {
  8558. Elf_Internal_Rela tmp = *rel;
  8559. /* Keep the relocs sorted by r_offset. */
  8560. memmove (rel, rel + 1, (relend - (rel + 1)) * sizeof (*rel));
  8561. relend[-1] = tmp;
  8562. }
  8563. relend[-1].r_offset += patch_off - offset;
  8564. /* Adjust REL16 addends too. */
  8565. switch (ELF32_R_TYPE (relend[-1].r_info))
  8566. {
  8567. case R_PPC_REL16:
  8568. case R_PPC_REL16_LO:
  8569. case R_PPC_REL16_HI:
  8570. case R_PPC_REL16_HA:
  8571. relend[-1].r_addend += patch_off - offset;
  8572. break;
  8573. default:
  8574. break;
  8575. }
  8576. /* If we are building a PIE or shared library with
  8577. non-PIC objects, perhaps we had a dynamic reloc too?
  8578. If so, the dynamic reloc must move with the insn. */
  8579. sreloc = elf_section_data (input_section)->sreloc;
  8580. if (sreloc != NULL)
  8581. {
  8582. Elf32_External_Rela *slo, *shi, *srelend;
  8583. bfd_vma soffset;
  8584. slo = (Elf32_External_Rela *) sreloc->contents;
  8585. shi = srelend = slo + sreloc->reloc_count;
  8586. soffset = (offset + input_section->output_section->vma
  8587. + input_section->output_offset);
  8588. while (slo < shi)
  8589. {
  8590. Elf32_External_Rela *srel = slo + (shi - slo) / 2;
  8591. bfd_elf32_swap_reloca_in (output_bfd, (bfd_byte *) srel,
  8592. &outrel);
  8593. if (outrel.r_offset < soffset)
  8594. slo = srel + 1;
  8595. else if (outrel.r_offset > soffset + 3)
  8596. shi = srel;
  8597. else
  8598. {
  8599. if (srel + 1 != srelend)
  8600. {
  8601. memmove (srel, srel + 1,
  8602. (srelend - (srel + 1)) * sizeof (*srel));
  8603. srel = srelend - 1;
  8604. }
  8605. outrel.r_offset += patch_off - offset;
  8606. bfd_elf32_swap_reloca_out (output_bfd, &outrel,
  8607. (bfd_byte *) srel);
  8608. break;
  8609. }
  8610. }
  8611. }
  8612. }
  8613. else
  8614. rel = NULL;
  8615. if ((insn & (0x3f << 26)) == (16u << 26) /* bc */
  8616. && (insn & 2) == 0 /* relative */)
  8617. {
  8618. bfd_vma delta = ((insn & 0xfffc) ^ 0x8000) - 0x8000;
  8619. delta += offset - patch_off;
  8620. if (bfd_link_relocatable (info) && rel != NULL)
  8621. delta = 0;
  8622. if (!bfd_link_relocatable (info) && rel != NULL)
  8623. {
  8624. enum elf_ppc_reloc_type r_type;
  8625. r_type = ELF32_R_TYPE (relend[-1].r_info);
  8626. if (r_type == R_PPC_REL14_BRTAKEN)
  8627. insn |= BRANCH_PREDICT_BIT;
  8628. else if (r_type == R_PPC_REL14_BRNTAKEN)
  8629. insn &= ~BRANCH_PREDICT_BIT;
  8630. else
  8631. BFD_ASSERT (r_type == R_PPC_REL14);
  8632. if ((r_type == R_PPC_REL14_BRTAKEN
  8633. || r_type == R_PPC_REL14_BRNTAKEN)
  8634. && delta + 0x8000 < 0x10000
  8635. && (bfd_signed_vma) delta < 0)
  8636. insn ^= BRANCH_PREDICT_BIT;
  8637. }
  8638. if (delta + 0x8000 < 0x10000)
  8639. {
  8640. bfd_put_32 (input_bfd,
  8641. (insn & ~0xfffc) | (delta & 0xfffc),
  8642. contents + patch_off);
  8643. patch_off += 4;
  8644. bfd_put_32 (input_bfd,
  8645. B | ((offset + 4 - patch_off) & 0x3fffffc),
  8646. contents + patch_off);
  8647. patch_off += 4;
  8648. }
  8649. else
  8650. {
  8651. if (rel != NULL)
  8652. {
  8653. unsigned int r_sym = ELF32_R_SYM (relend[-1].r_info);
  8654. relend[-1].r_offset += 8;
  8655. relend[-1].r_info = ELF32_R_INFO (r_sym, R_PPC_REL24);
  8656. }
  8657. bfd_put_32 (input_bfd,
  8658. (insn & ~0xfffc) | 8,
  8659. contents + patch_off);
  8660. patch_off += 4;
  8661. bfd_put_32 (input_bfd,
  8662. B | ((offset + 4 - patch_off) & 0x3fffffc),
  8663. contents + patch_off);
  8664. patch_off += 4;
  8665. bfd_put_32 (input_bfd,
  8666. B | ((delta - 8) & 0x3fffffc),
  8667. contents + patch_off);
  8668. patch_off += 4;
  8669. }
  8670. }
  8671. else
  8672. {
  8673. bfd_put_32 (input_bfd, insn, contents + patch_off);
  8674. patch_off += 4;
  8675. bfd_put_32 (input_bfd,
  8676. B | ((offset + 4 - patch_off) & 0x3fffffc),
  8677. contents + patch_off);
  8678. patch_off += 4;
  8679. }
  8680. BFD_ASSERT (patch_off <= input_section->size);
  8681. relax_info->workaround_size = input_section->size - patch_off;
  8682. }
  8683. }
  8684. return ret;
  8685. }
  8686. /* Finish up dynamic symbol handling. We set the contents of various
  8687. dynamic sections here. */
  8688. static bfd_boolean
  8689. ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
  8690. struct bfd_link_info *info,
  8691. struct elf_link_hash_entry *h,
  8692. Elf_Internal_Sym *sym)
  8693. {
  8694. struct ppc_elf_link_hash_table *htab;
  8695. struct plt_entry *ent;
  8696. bfd_boolean doneone;
  8697. #ifdef DEBUG
  8698. fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
  8699. h->root.root.string);
  8700. #endif
  8701. htab = ppc_elf_hash_table (info);
  8702. BFD_ASSERT (htab->elf.dynobj != NULL);
  8703. doneone = FALSE;
  8704. for (ent = h->plt.plist; ent != NULL; ent = ent->next)
  8705. if (ent->plt.offset != (bfd_vma) -1)
  8706. {
  8707. if (!doneone)
  8708. {
  8709. Elf_Internal_Rela rela;
  8710. bfd_byte *loc;
  8711. bfd_vma reloc_index;
  8712. if (htab->plt_type == PLT_NEW
  8713. || !htab->elf.dynamic_sections_created
  8714. || h->dynindx == -1)
  8715. reloc_index = ent->plt.offset / 4;
  8716. else
  8717. {
  8718. reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size)
  8719. / htab->plt_slot_size);
  8720. if (reloc_index > PLT_NUM_SINGLE_ENTRIES
  8721. && htab->plt_type == PLT_OLD)
  8722. reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
  8723. }
  8724. /* This symbol has an entry in the procedure linkage table.
  8725. Set it up. */
  8726. if (htab->plt_type == PLT_VXWORKS
  8727. && htab->elf.dynamic_sections_created
  8728. && h->dynindx != -1)
  8729. {
  8730. bfd_vma got_offset;
  8731. const bfd_vma *plt_entry;
  8732. /* The first three entries in .got.plt are reserved. */
  8733. got_offset = (reloc_index + 3) * 4;
  8734. /* Use the right PLT. */
  8735. plt_entry = bfd_link_pic (info) ? ppc_elf_vxworks_pic_plt_entry
  8736. : ppc_elf_vxworks_plt_entry;
  8737. /* Fill in the .plt on VxWorks. */
  8738. if (bfd_link_pic (info))
  8739. {
  8740. bfd_put_32 (output_bfd,
  8741. plt_entry[0] | PPC_HA (got_offset),
  8742. htab->plt->contents + ent->plt.offset + 0);
  8743. bfd_put_32 (output_bfd,
  8744. plt_entry[1] | PPC_LO (got_offset),
  8745. htab->plt->contents + ent->plt.offset + 4);
  8746. }
  8747. else
  8748. {
  8749. bfd_vma got_loc = got_offset + SYM_VAL (htab->elf.hgot);
  8750. bfd_put_32 (output_bfd,
  8751. plt_entry[0] | PPC_HA (got_loc),
  8752. htab->plt->contents + ent->plt.offset + 0);
  8753. bfd_put_32 (output_bfd,
  8754. plt_entry[1] | PPC_LO (got_loc),
  8755. htab->plt->contents + ent->plt.offset + 4);
  8756. }
  8757. bfd_put_32 (output_bfd, plt_entry[2],
  8758. htab->plt->contents + ent->plt.offset + 8);
  8759. bfd_put_32 (output_bfd, plt_entry[3],
  8760. htab->plt->contents + ent->plt.offset + 12);
  8761. /* This instruction is an immediate load. The value loaded is
  8762. the byte offset of the R_PPC_JMP_SLOT relocation from the
  8763. start of the .rela.plt section. The value is stored in the
  8764. low-order 16 bits of the load instruction. */
  8765. /* NOTE: It appears that this is now an index rather than a
  8766. prescaled offset. */
  8767. bfd_put_32 (output_bfd,
  8768. plt_entry[4] | reloc_index,
  8769. htab->plt->contents + ent->plt.offset + 16);
  8770. /* This instruction is a PC-relative branch whose target is
  8771. the start of the PLT section. The address of this branch
  8772. instruction is 20 bytes beyond the start of this PLT entry.
  8773. The address is encoded in bits 6-29, inclusive. The value
  8774. stored is right-shifted by two bits, permitting a 26-bit
  8775. offset. */
  8776. bfd_put_32 (output_bfd,
  8777. (plt_entry[5]
  8778. | (-(ent->plt.offset + 20) & 0x03fffffc)),
  8779. htab->plt->contents + ent->plt.offset + 20);
  8780. bfd_put_32 (output_bfd, plt_entry[6],
  8781. htab->plt->contents + ent->plt.offset + 24);
  8782. bfd_put_32 (output_bfd, plt_entry[7],
  8783. htab->plt->contents + ent->plt.offset + 28);
  8784. /* Fill in the GOT entry corresponding to this PLT slot with
  8785. the address immediately after the "bctr" instruction
  8786. in this PLT entry. */
  8787. bfd_put_32 (output_bfd, (htab->plt->output_section->vma
  8788. + htab->plt->output_offset
  8789. + ent->plt.offset + 16),
  8790. htab->sgotplt->contents + got_offset);
  8791. if (!bfd_link_pic (info))
  8792. {
  8793. /* Fill in a couple of entries in .rela.plt.unloaded. */
  8794. loc = htab->srelplt2->contents
  8795. + ((VXWORKS_PLTRESOLVE_RELOCS + reloc_index
  8796. * VXWORKS_PLT_NON_JMP_SLOT_RELOCS)
  8797. * sizeof (Elf32_External_Rela));
  8798. /* Provide the @ha relocation for the first instruction. */
  8799. rela.r_offset = (htab->plt->output_section->vma
  8800. + htab->plt->output_offset
  8801. + ent->plt.offset + 2);
  8802. rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
  8803. R_PPC_ADDR16_HA);
  8804. rela.r_addend = got_offset;
  8805. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  8806. loc += sizeof (Elf32_External_Rela);
  8807. /* Provide the @l relocation for the second instruction. */
  8808. rela.r_offset = (htab->plt->output_section->vma
  8809. + htab->plt->output_offset
  8810. + ent->plt.offset + 6);
  8811. rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
  8812. R_PPC_ADDR16_LO);
  8813. rela.r_addend = got_offset;
  8814. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  8815. loc += sizeof (Elf32_External_Rela);
  8816. /* Provide a relocation for the GOT entry corresponding to this
  8817. PLT slot. Point it at the middle of the .plt entry. */
  8818. rela.r_offset = (htab->sgotplt->output_section->vma
  8819. + htab->sgotplt->output_offset
  8820. + got_offset);
  8821. rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
  8822. R_PPC_ADDR32);
  8823. rela.r_addend = ent->plt.offset + 16;
  8824. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  8825. }
  8826. /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT.
  8827. In particular, the offset for the relocation is not the
  8828. address of the PLT entry for this function, as specified
  8829. by the ABI. Instead, the offset is set to the address of
  8830. the GOT slot for this function. See EABI 4.4.4.1. */
  8831. rela.r_offset = (htab->sgotplt->output_section->vma
  8832. + htab->sgotplt->output_offset
  8833. + got_offset);
  8834. }
  8835. else
  8836. {
  8837. asection *splt = htab->plt;
  8838. if (!htab->elf.dynamic_sections_created
  8839. || h->dynindx == -1)
  8840. splt = htab->iplt;
  8841. rela.r_offset = (splt->output_section->vma
  8842. + splt->output_offset
  8843. + ent->plt.offset);
  8844. if (htab->plt_type == PLT_OLD
  8845. || !htab->elf.dynamic_sections_created
  8846. || h->dynindx == -1)
  8847. {
  8848. /* We don't need to fill in the .plt. The ppc dynamic
  8849. linker will fill it in. */
  8850. }
  8851. else
  8852. {
  8853. bfd_vma val = (htab->glink_pltresolve + ent->plt.offset
  8854. + htab->glink->output_section->vma
  8855. + htab->glink->output_offset);
  8856. bfd_put_32 (output_bfd, val,
  8857. splt->contents + ent->plt.offset);
  8858. }
  8859. }
  8860. /* Fill in the entry in the .rela.plt section. */
  8861. rela.r_addend = 0;
  8862. if (!htab->elf.dynamic_sections_created
  8863. || h->dynindx == -1)
  8864. {
  8865. BFD_ASSERT (h->type == STT_GNU_IFUNC
  8866. && h->def_regular
  8867. && (h->root.type == bfd_link_hash_defined
  8868. || h->root.type == bfd_link_hash_defweak));
  8869. rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
  8870. rela.r_addend = SYM_VAL (h);
  8871. }
  8872. else
  8873. rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
  8874. if (!htab->elf.dynamic_sections_created
  8875. || h->dynindx == -1)
  8876. loc = (htab->reliplt->contents
  8877. + (htab->reliplt->reloc_count++
  8878. * sizeof (Elf32_External_Rela)));
  8879. else
  8880. loc = (htab->relplt->contents
  8881. + reloc_index * sizeof (Elf32_External_Rela));
  8882. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  8883. if (!h->def_regular)
  8884. {
  8885. /* Mark the symbol as undefined, rather than as
  8886. defined in the .plt section. Leave the value if
  8887. there were any relocations where pointer equality
  8888. matters (this is a clue for the dynamic linker, to
  8889. make function pointer comparisons work between an
  8890. application and shared library), otherwise set it
  8891. to zero. */
  8892. sym->st_shndx = SHN_UNDEF;
  8893. if (!h->pointer_equality_needed)
  8894. sym->st_value = 0;
  8895. else if (!h->ref_regular_nonweak)
  8896. {
  8897. /* This breaks function pointer comparisons, but
  8898. that is better than breaking tests for a NULL
  8899. function pointer. */
  8900. sym->st_value = 0;
  8901. }
  8902. }
  8903. else if (h->type == STT_GNU_IFUNC
  8904. && !bfd_link_pic (info))
  8905. {
  8906. /* Set the value of ifunc symbols in a non-pie
  8907. executable to the glink entry. This is to avoid
  8908. text relocations. We can't do this for ifunc in
  8909. allocate_dynrelocs, as we do for normal dynamic
  8910. function symbols with plt entries, because we need
  8911. to keep the original value around for the ifunc
  8912. relocation. */
  8913. sym->st_shndx = (_bfd_elf_section_from_bfd_section
  8914. (output_bfd, htab->glink->output_section));
  8915. sym->st_value = (ent->glink_offset
  8916. + htab->glink->output_offset
  8917. + htab->glink->output_section->vma);
  8918. }
  8919. doneone = TRUE;
  8920. }
  8921. if (htab->plt_type == PLT_NEW
  8922. || !htab->elf.dynamic_sections_created
  8923. || h->dynindx == -1)
  8924. {
  8925. unsigned char *p;
  8926. asection *splt = htab->plt;
  8927. if (!htab->elf.dynamic_sections_created
  8928. || h->dynindx == -1)
  8929. splt = htab->iplt;
  8930. p = (unsigned char *) htab->glink->contents + ent->glink_offset;
  8931. if (h == htab->tls_get_addr && !htab->params->no_tls_get_addr_opt)
  8932. {
  8933. bfd_put_32 (output_bfd, LWZ_11_3, p);
  8934. p += 4;
  8935. bfd_put_32 (output_bfd, LWZ_12_3 + 4, p);
  8936. p += 4;
  8937. bfd_put_32 (output_bfd, MR_0_3, p);
  8938. p += 4;
  8939. bfd_put_32 (output_bfd, CMPWI_11_0, p);
  8940. p += 4;
  8941. bfd_put_32 (output_bfd, ADD_3_12_2, p);
  8942. p += 4;
  8943. bfd_put_32 (output_bfd, BEQLR, p);
  8944. p += 4;
  8945. bfd_put_32 (output_bfd, MR_3_0, p);
  8946. p += 4;
  8947. bfd_put_32 (output_bfd, NOP, p);
  8948. p += 4;
  8949. }
  8950. write_glink_stub (ent, splt, p, info);
  8951. if (!bfd_link_pic (info))
  8952. /* We only need one non-PIC glink stub. */
  8953. break;
  8954. }
  8955. else
  8956. break;
  8957. }
  8958. if (h->needs_copy)
  8959. {
  8960. asection *s;
  8961. Elf_Internal_Rela rela;
  8962. bfd_byte *loc;
  8963. /* This symbols needs a copy reloc. Set it up. */
  8964. #ifdef DEBUG
  8965. fprintf (stderr, ", copy");
  8966. #endif
  8967. BFD_ASSERT (h->dynindx != -1);
  8968. if (ppc_elf_hash_entry (h)->has_sda_refs)
  8969. s = htab->relsbss;
  8970. else
  8971. s = htab->relbss;
  8972. BFD_ASSERT (s != NULL);
  8973. rela.r_offset = SYM_VAL (h);
  8974. rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
  8975. rela.r_addend = 0;
  8976. loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
  8977. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  8978. }
  8979. #ifdef DEBUG
  8980. fprintf (stderr, "\n");
  8981. #endif
  8982. return TRUE;
  8983. }
  8984. static enum elf_reloc_type_class
  8985. ppc_elf_reloc_type_class (const struct bfd_link_info *info,
  8986. const asection *rel_sec,
  8987. const Elf_Internal_Rela *rela)
  8988. {
  8989. struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
  8990. if (rel_sec == htab->reliplt)
  8991. return reloc_class_ifunc;
  8992. switch (ELF32_R_TYPE (rela->r_info))
  8993. {
  8994. case R_PPC_RELATIVE:
  8995. return reloc_class_relative;
  8996. case R_PPC_JMP_SLOT:
  8997. return reloc_class_plt;
  8998. case R_PPC_COPY:
  8999. return reloc_class_copy;
  9000. default:
  9001. return reloc_class_normal;
  9002. }
  9003. }
  9004. /* Finish up the dynamic sections. */
  9005. static bfd_boolean
  9006. ppc_elf_finish_dynamic_sections (bfd *output_bfd,
  9007. struct bfd_link_info *info)
  9008. {
  9009. asection *sdyn;
  9010. asection *splt;
  9011. struct ppc_elf_link_hash_table *htab;
  9012. bfd_vma got;
  9013. bfd *dynobj;
  9014. bfd_boolean ret = TRUE;
  9015. #ifdef DEBUG
  9016. fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
  9017. #endif
  9018. htab = ppc_elf_hash_table (info);
  9019. dynobj = elf_hash_table (info)->dynobj;
  9020. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  9021. if (htab->is_vxworks)
  9022. splt = bfd_get_linker_section (dynobj, ".plt");
  9023. else
  9024. splt = NULL;
  9025. got = 0;
  9026. if (htab->elf.hgot != NULL)
  9027. got = SYM_VAL (htab->elf.hgot);
  9028. if (htab->elf.dynamic_sections_created)
  9029. {
  9030. Elf32_External_Dyn *dyncon, *dynconend;
  9031. BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
  9032. dyncon = (Elf32_External_Dyn *) sdyn->contents;
  9033. dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
  9034. for (; dyncon < dynconend; dyncon++)
  9035. {
  9036. Elf_Internal_Dyn dyn;
  9037. asection *s;
  9038. bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
  9039. switch (dyn.d_tag)
  9040. {
  9041. case DT_PLTGOT:
  9042. if (htab->is_vxworks)
  9043. s = htab->sgotplt;
  9044. else
  9045. s = htab->plt;
  9046. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  9047. break;
  9048. case DT_PLTRELSZ:
  9049. dyn.d_un.d_val = htab->relplt->size;
  9050. break;
  9051. case DT_JMPREL:
  9052. s = htab->relplt;
  9053. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  9054. break;
  9055. case DT_PPC_GOT:
  9056. dyn.d_un.d_ptr = got;
  9057. break;
  9058. case DT_RELASZ:
  9059. if (htab->is_vxworks)
  9060. {
  9061. if (htab->relplt)
  9062. dyn.d_un.d_ptr -= htab->relplt->size;
  9063. break;
  9064. }
  9065. continue;
  9066. default:
  9067. if (htab->is_vxworks
  9068. && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
  9069. break;
  9070. continue;
  9071. }
  9072. bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
  9073. }
  9074. }
  9075. if (htab->got != NULL)
  9076. {
  9077. if (htab->elf.hgot->root.u.def.section == htab->got
  9078. || htab->elf.hgot->root.u.def.section == htab->sgotplt)
  9079. {
  9080. unsigned char *p = htab->elf.hgot->root.u.def.section->contents;
  9081. p += htab->elf.hgot->root.u.def.value;
  9082. if (htab->plt_type == PLT_OLD)
  9083. {
  9084. /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4
  9085. so that a function can easily find the address of
  9086. _GLOBAL_OFFSET_TABLE_. */
  9087. BFD_ASSERT (htab->elf.hgot->root.u.def.value - 4
  9088. < htab->elf.hgot->root.u.def.section->size);
  9089. bfd_put_32 (output_bfd, 0x4e800021, p - 4);
  9090. }
  9091. if (sdyn != NULL)
  9092. {
  9093. bfd_vma val = sdyn->output_section->vma + sdyn->output_offset;
  9094. BFD_ASSERT (htab->elf.hgot->root.u.def.value
  9095. < htab->elf.hgot->root.u.def.section->size);
  9096. bfd_put_32 (output_bfd, val, p);
  9097. }
  9098. }
  9099. else
  9100. {
  9101. info->callbacks->einfo (_("%P: %s not defined in linker created %s\n"),
  9102. htab->elf.hgot->root.root.string,
  9103. (htab->sgotplt != NULL
  9104. ? htab->sgotplt->name : htab->got->name));
  9105. bfd_set_error (bfd_error_bad_value);
  9106. ret = FALSE;
  9107. }
  9108. elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
  9109. }
  9110. /* Fill in the first entry in the VxWorks procedure linkage table. */
  9111. if (splt && splt->size > 0)
  9112. {
  9113. /* Use the right PLT. */
  9114. const bfd_vma *plt_entry = (bfd_link_pic (info)
  9115. ? ppc_elf_vxworks_pic_plt0_entry
  9116. : ppc_elf_vxworks_plt0_entry);
  9117. if (!bfd_link_pic (info))
  9118. {
  9119. bfd_vma got_value = SYM_VAL (htab->elf.hgot);
  9120. bfd_put_32 (output_bfd, plt_entry[0] | PPC_HA (got_value),
  9121. splt->contents + 0);
  9122. bfd_put_32 (output_bfd, plt_entry[1] | PPC_LO (got_value),
  9123. splt->contents + 4);
  9124. }
  9125. else
  9126. {
  9127. bfd_put_32 (output_bfd, plt_entry[0], splt->contents + 0);
  9128. bfd_put_32 (output_bfd, plt_entry[1], splt->contents + 4);
  9129. }
  9130. bfd_put_32 (output_bfd, plt_entry[2], splt->contents + 8);
  9131. bfd_put_32 (output_bfd, plt_entry[3], splt->contents + 12);
  9132. bfd_put_32 (output_bfd, plt_entry[4], splt->contents + 16);
  9133. bfd_put_32 (output_bfd, plt_entry[5], splt->contents + 20);
  9134. bfd_put_32 (output_bfd, plt_entry[6], splt->contents + 24);
  9135. bfd_put_32 (output_bfd, plt_entry[7], splt->contents + 28);
  9136. if (! bfd_link_pic (info))
  9137. {
  9138. Elf_Internal_Rela rela;
  9139. bfd_byte *loc;
  9140. loc = htab->srelplt2->contents;
  9141. /* Output the @ha relocation for the first instruction. */
  9142. rela.r_offset = (htab->plt->output_section->vma
  9143. + htab->plt->output_offset
  9144. + 2);
  9145. rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
  9146. rela.r_addend = 0;
  9147. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  9148. loc += sizeof (Elf32_External_Rela);
  9149. /* Output the @l relocation for the second instruction. */
  9150. rela.r_offset = (htab->plt->output_section->vma
  9151. + htab->plt->output_offset
  9152. + 6);
  9153. rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
  9154. rela.r_addend = 0;
  9155. bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
  9156. loc += sizeof (Elf32_External_Rela);
  9157. /* Fix up the remaining relocations. They may have the wrong
  9158. symbol index for _G_O_T_ or _P_L_T_ depending on the order
  9159. in which symbols were output. */
  9160. while (loc < htab->srelplt2->contents + htab->srelplt2->size)
  9161. {
  9162. Elf_Internal_Rela rel;
  9163. bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
  9164. rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
  9165. bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
  9166. loc += sizeof (Elf32_External_Rela);
  9167. bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
  9168. rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
  9169. bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
  9170. loc += sizeof (Elf32_External_Rela);
  9171. bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
  9172. rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32);
  9173. bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
  9174. loc += sizeof (Elf32_External_Rela);
  9175. }
  9176. }
  9177. }
  9178. if (htab->glink != NULL
  9179. && htab->glink->contents != NULL
  9180. && htab->elf.dynamic_sections_created)
  9181. {
  9182. unsigned char *p;
  9183. unsigned char *endp;
  9184. bfd_vma res0;
  9185. unsigned int i;
  9186. /*
  9187. * PIC glink code is the following:
  9188. *
  9189. * # ith PLT code stub.
  9190. * addis 11,30,(plt+(i-1)*4-got)@ha
  9191. * lwz 11,(plt+(i-1)*4-got)@l(11)
  9192. * mtctr 11
  9193. * bctr
  9194. *
  9195. * # A table of branches, one for each plt entry.
  9196. * # The idea is that the plt call stub loads ctr and r11 with these
  9197. * # addresses, so (r11 - res_0) gives the plt index * 4.
  9198. * res_0: b PLTresolve
  9199. * res_1: b PLTresolve
  9200. * .
  9201. * # Some number of entries towards the end can be nops
  9202. * res_n_m3: nop
  9203. * res_n_m2: nop
  9204. * res_n_m1:
  9205. *
  9206. * PLTresolve:
  9207. * addis 11,11,(1f-res_0)@ha
  9208. * mflr 0
  9209. * bcl 20,31,1f
  9210. * 1: addi 11,11,(1b-res_0)@l
  9211. * mflr 12
  9212. * mtlr 0
  9213. * sub 11,11,12 # r11 = index * 4
  9214. * addis 12,12,(got+4-1b)@ha
  9215. * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve
  9216. * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address
  9217. * mtctr 0
  9218. * add 0,11,11
  9219. * add 11,0,11 # r11 = index * 12 = reloc offset.
  9220. * bctr
  9221. */
  9222. static const unsigned int pic_plt_resolve[] =
  9223. {
  9224. ADDIS_11_11,
  9225. MFLR_0,
  9226. BCL_20_31,
  9227. ADDI_11_11,
  9228. MFLR_12,
  9229. MTLR_0,
  9230. SUB_11_11_12,
  9231. ADDIS_12_12,
  9232. LWZ_0_12,
  9233. LWZ_12_12,
  9234. MTCTR_0,
  9235. ADD_0_11_11,
  9236. ADD_11_0_11,
  9237. BCTR,
  9238. NOP,
  9239. NOP
  9240. };
  9241. /*
  9242. * Non-PIC glink code is a little simpler.
  9243. *
  9244. * # ith PLT code stub.
  9245. * lis 11,(plt+(i-1)*4)@ha
  9246. * lwz 11,(plt+(i-1)*4)@l(11)
  9247. * mtctr 11
  9248. * bctr
  9249. *
  9250. * The branch table is the same, then comes
  9251. *
  9252. * PLTresolve:
  9253. * lis 12,(got+4)@ha
  9254. * addis 11,11,(-res_0)@ha
  9255. * lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve
  9256. * addi 11,11,(-res_0)@l # r11 = index * 4
  9257. * mtctr 0
  9258. * add 0,11,11
  9259. * lwz 12,(got+8)@l(12) # got[2] contains the map address
  9260. * add 11,0,11 # r11 = index * 12 = reloc offset.
  9261. * bctr
  9262. */
  9263. static const unsigned int plt_resolve[] =
  9264. {
  9265. LIS_12,
  9266. ADDIS_11_11,
  9267. LWZ_0_12,
  9268. ADDI_11_11,
  9269. MTCTR_0,
  9270. ADD_0_11_11,
  9271. LWZ_12_12,
  9272. ADD_11_0_11,
  9273. BCTR,
  9274. NOP,
  9275. NOP,
  9276. NOP,
  9277. NOP,
  9278. NOP,
  9279. NOP,
  9280. NOP
  9281. };
  9282. if (ARRAY_SIZE (pic_plt_resolve) != GLINK_PLTRESOLVE / 4)
  9283. abort ();
  9284. if (ARRAY_SIZE (plt_resolve) != GLINK_PLTRESOLVE / 4)
  9285. abort ();
  9286. /* Build the branch table, one for each plt entry (less one),
  9287. and perhaps some padding. */
  9288. p = htab->glink->contents;
  9289. p += htab->glink_pltresolve;
  9290. endp = htab->glink->contents;
  9291. endp += htab->glink->size - GLINK_PLTRESOLVE;
  9292. while (p < endp - (htab->params->ppc476_workaround ? 0 : 8 * 4))
  9293. {
  9294. bfd_put_32 (output_bfd, B + endp - p, p);
  9295. p += 4;
  9296. }
  9297. while (p < endp)
  9298. {
  9299. bfd_put_32 (output_bfd, NOP, p);
  9300. p += 4;
  9301. }
  9302. res0 = (htab->glink_pltresolve
  9303. + htab->glink->output_section->vma
  9304. + htab->glink->output_offset);
  9305. if (htab->params->ppc476_workaround)
  9306. {
  9307. /* Ensure that a call stub at the end of a page doesn't
  9308. result in prefetch over the end of the page into the
  9309. glink branch table. */
  9310. bfd_vma pagesize = (bfd_vma) 1 << htab->params->pagesize_p2;
  9311. bfd_vma page_addr;
  9312. bfd_vma glink_start = (htab->glink->output_section->vma
  9313. + htab->glink->output_offset);
  9314. for (page_addr = res0 & -pagesize;
  9315. page_addr > glink_start;
  9316. page_addr -= pagesize)
  9317. {
  9318. /* We have a plt call stub that may need fixing. */
  9319. bfd_byte *loc;
  9320. unsigned int insn;
  9321. loc = htab->glink->contents + page_addr - 4 - glink_start;
  9322. insn = bfd_get_32 (output_bfd, loc);
  9323. if (insn == BCTR)
  9324. {
  9325. /* By alignment, we know that there must be at least
  9326. one other call stub before this one. */
  9327. insn = bfd_get_32 (output_bfd, loc - 16);
  9328. if (insn == BCTR)
  9329. bfd_put_32 (output_bfd, B | (-16 & 0x3fffffc), loc);
  9330. else
  9331. bfd_put_32 (output_bfd, B | (-20 & 0x3fffffc), loc);
  9332. }
  9333. }
  9334. }
  9335. /* Last comes the PLTresolve stub. */
  9336. if (bfd_link_pic (info))
  9337. {
  9338. bfd_vma bcl;
  9339. for (i = 0; i < ARRAY_SIZE (pic_plt_resolve); i++)
  9340. {
  9341. unsigned int insn = pic_plt_resolve[i];
  9342. if (htab->params->ppc476_workaround && insn == NOP)
  9343. insn = BA + 0;
  9344. bfd_put_32 (output_bfd, insn, p);
  9345. p += 4;
  9346. }
  9347. p -= 4 * ARRAY_SIZE (pic_plt_resolve);
  9348. bcl = (htab->glink->size - GLINK_PLTRESOLVE + 3*4
  9349. + htab->glink->output_section->vma
  9350. + htab->glink->output_offset);
  9351. bfd_put_32 (output_bfd,
  9352. ADDIS_11_11 + PPC_HA (bcl - res0), p + 0*4);
  9353. bfd_put_32 (output_bfd,
  9354. ADDI_11_11 + PPC_LO (bcl - res0), p + 3*4);
  9355. bfd_put_32 (output_bfd,
  9356. ADDIS_12_12 + PPC_HA (got + 4 - bcl), p + 7*4);
  9357. if (PPC_HA (got + 4 - bcl) == PPC_HA (got + 8 - bcl))
  9358. {
  9359. bfd_put_32 (output_bfd,
  9360. LWZ_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
  9361. bfd_put_32 (output_bfd,
  9362. LWZ_12_12 + PPC_LO (got + 8 - bcl), p + 9*4);
  9363. }
  9364. else
  9365. {
  9366. bfd_put_32 (output_bfd,
  9367. LWZU_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
  9368. bfd_put_32 (output_bfd,
  9369. LWZ_12_12 + 4, p + 9*4);
  9370. }
  9371. }
  9372. else
  9373. {
  9374. for (i = 0; i < ARRAY_SIZE (plt_resolve); i++)
  9375. {
  9376. unsigned int insn = plt_resolve[i];
  9377. if (htab->params->ppc476_workaround && insn == NOP)
  9378. insn = BA + 0;
  9379. bfd_put_32 (output_bfd, insn, p);
  9380. p += 4;
  9381. }
  9382. p -= 4 * ARRAY_SIZE (plt_resolve);
  9383. bfd_put_32 (output_bfd,
  9384. LIS_12 + PPC_HA (got + 4), p + 0*4);
  9385. bfd_put_32 (output_bfd,
  9386. ADDIS_11_11 + PPC_HA (-res0), p + 1*4);
  9387. bfd_put_32 (output_bfd,
  9388. ADDI_11_11 + PPC_LO (-res0), p + 3*4);
  9389. if (PPC_HA (got + 4) == PPC_HA (got + 8))
  9390. {
  9391. bfd_put_32 (output_bfd,
  9392. LWZ_0_12 + PPC_LO (got + 4), p + 2*4);
  9393. bfd_put_32 (output_bfd,
  9394. LWZ_12_12 + PPC_LO (got + 8), p + 6*4);
  9395. }
  9396. else
  9397. {
  9398. bfd_put_32 (output_bfd,
  9399. LWZU_0_12 + PPC_LO (got + 4), p + 2*4);
  9400. bfd_put_32 (output_bfd,
  9401. LWZ_12_12 + 4, p + 6*4);
  9402. }
  9403. }
  9404. }
  9405. if (htab->glink_eh_frame != NULL
  9406. && htab->glink_eh_frame->contents != NULL)
  9407. {
  9408. unsigned char *p = htab->glink_eh_frame->contents;
  9409. bfd_vma val;
  9410. p += sizeof (glink_eh_frame_cie);
  9411. /* FDE length. */
  9412. p += 4;
  9413. /* CIE pointer. */
  9414. p += 4;
  9415. /* Offset to .glink. */
  9416. val = (htab->glink->output_section->vma
  9417. + htab->glink->output_offset);
  9418. val -= (htab->glink_eh_frame->output_section->vma
  9419. + htab->glink_eh_frame->output_offset);
  9420. val -= p - htab->glink_eh_frame->contents;
  9421. bfd_put_32 (htab->elf.dynobj, val, p);
  9422. if (htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME
  9423. && !_bfd_elf_write_section_eh_frame (output_bfd, info,
  9424. htab->glink_eh_frame,
  9425. htab->glink_eh_frame->contents))
  9426. return FALSE;
  9427. }
  9428. return ret;
  9429. }
  9430. #define TARGET_LITTLE_SYM powerpc_elf32_le_vec
  9431. #define TARGET_LITTLE_NAME "elf32-powerpcle"
  9432. #define TARGET_BIG_SYM powerpc_elf32_vec
  9433. #define TARGET_BIG_NAME "elf32-powerpc"
  9434. #define ELF_ARCH bfd_arch_powerpc
  9435. #define ELF_TARGET_ID PPC32_ELF_DATA
  9436. #define ELF_MACHINE_CODE EM_PPC
  9437. #ifdef __QNXTARGET__
  9438. #define ELF_MAXPAGESIZE 0x1000
  9439. #define ELF_COMMONPAGESIZE 0x1000
  9440. #else
  9441. #define ELF_MAXPAGESIZE 0x10000
  9442. #define ELF_COMMONPAGESIZE 0x10000
  9443. #endif
  9444. #define ELF_MINPAGESIZE 0x1000
  9445. #define elf_info_to_howto ppc_elf_info_to_howto
  9446. #ifdef EM_CYGNUS_POWERPC
  9447. #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
  9448. #endif
  9449. #ifdef EM_PPC_OLD
  9450. #define ELF_MACHINE_ALT2 EM_PPC_OLD
  9451. #endif
  9452. #define elf_backend_plt_not_loaded 1
  9453. #define elf_backend_can_gc_sections 1
  9454. #define elf_backend_can_refcount 1
  9455. #define elf_backend_rela_normal 1
  9456. #define elf_backend_caches_rawsize 1
  9457. #define bfd_elf32_mkobject ppc_elf_mkobject
  9458. #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
  9459. #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
  9460. #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
  9461. #define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup
  9462. #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
  9463. #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
  9464. #define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab
  9465. #define elf_backend_object_p ppc_elf_object_p
  9466. #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
  9467. #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
  9468. #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
  9469. #define elf_backend_relocate_section ppc_elf_relocate_section
  9470. #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
  9471. #define elf_backend_check_relocs ppc_elf_check_relocs
  9472. #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
  9473. #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
  9474. #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
  9475. #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
  9476. #define elf_backend_hash_symbol ppc_elf_hash_symbol
  9477. #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
  9478. #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
  9479. #define elf_backend_fake_sections ppc_elf_fake_sections
  9480. #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
  9481. #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
  9482. #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
  9483. #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
  9484. #define elf_backend_write_core_note ppc_elf_write_core_note
  9485. #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
  9486. #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
  9487. #define elf_backend_final_write_processing ppc_elf_final_write_processing
  9488. #define elf_backend_write_section ppc_elf_write_section
  9489. #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr
  9490. #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
  9491. #define elf_backend_action_discarded ppc_elf_action_discarded
  9492. #define elf_backend_init_index_section _bfd_elf_init_1_index_section
  9493. #define elf_backend_lookup_section_flags_hook ppc_elf_lookup_section_flags
  9494. #define elf_backend_section_processing ppc_elf_section_processing
  9495. #include "elf32-target.h"
  9496. /* FreeBSD Target */
  9497. #undef TARGET_LITTLE_SYM
  9498. #undef TARGET_LITTLE_NAME
  9499. #undef TARGET_BIG_SYM
  9500. #define TARGET_BIG_SYM powerpc_elf32_fbsd_vec
  9501. #undef TARGET_BIG_NAME
  9502. #define TARGET_BIG_NAME "elf32-powerpc-freebsd"
  9503. #undef ELF_OSABI
  9504. #define ELF_OSABI ELFOSABI_FREEBSD
  9505. #undef elf32_bed
  9506. #define elf32_bed elf32_powerpc_fbsd_bed
  9507. #include "elf32-target.h"
  9508. /* VxWorks Target */
  9509. #undef TARGET_LITTLE_SYM
  9510. #undef TARGET_LITTLE_NAME
  9511. #undef TARGET_BIG_SYM
  9512. #define TARGET_BIG_SYM powerpc_elf32_vxworks_vec
  9513. #undef TARGET_BIG_NAME
  9514. #define TARGET_BIG_NAME "elf32-powerpc-vxworks"
  9515. #undef ELF_OSABI
  9516. /* VxWorks uses the elf default section flags for .plt. */
  9517. static const struct bfd_elf_special_section *
  9518. ppc_elf_vxworks_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
  9519. {
  9520. if (sec->name == NULL)
  9521. return NULL;
  9522. if (strcmp (sec->name, ".plt") == 0)
  9523. return _bfd_elf_get_sec_type_attr (abfd, sec);
  9524. return ppc_elf_get_sec_type_attr (abfd, sec);
  9525. }
  9526. /* Like ppc_elf_link_hash_table_create, but overrides
  9527. appropriately for VxWorks. */
  9528. static struct bfd_link_hash_table *
  9529. ppc_elf_vxworks_link_hash_table_create (bfd *abfd)
  9530. {
  9531. struct bfd_link_hash_table *ret;
  9532. ret = ppc_elf_link_hash_table_create (abfd);
  9533. if (ret)
  9534. {
  9535. struct ppc_elf_link_hash_table *htab
  9536. = (struct ppc_elf_link_hash_table *)ret;
  9537. htab->is_vxworks = 1;
  9538. htab->plt_type = PLT_VXWORKS;
  9539. htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE;
  9540. htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE;
  9541. htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE;
  9542. }
  9543. return ret;
  9544. }
  9545. /* Tweak magic VxWorks symbols as they are loaded. */
  9546. static bfd_boolean
  9547. ppc_elf_vxworks_add_symbol_hook (bfd *abfd,
  9548. struct bfd_link_info *info,
  9549. Elf_Internal_Sym *sym,
  9550. const char **namep ATTRIBUTE_UNUSED,
  9551. flagword *flagsp ATTRIBUTE_UNUSED,
  9552. asection **secp,
  9553. bfd_vma *valp)
  9554. {
  9555. if (!elf_vxworks_add_symbol_hook(abfd, info, sym,namep, flagsp, secp,
  9556. valp))
  9557. return FALSE;
  9558. return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp);
  9559. }
  9560. static void
  9561. ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
  9562. {
  9563. ppc_elf_final_write_processing(abfd, linker);
  9564. elf_vxworks_final_write_processing(abfd, linker);
  9565. }
  9566. /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
  9567. define it. */
  9568. #undef elf_backend_want_plt_sym
  9569. #define elf_backend_want_plt_sym 1
  9570. #undef elf_backend_want_got_plt
  9571. #define elf_backend_want_got_plt 1
  9572. #undef elf_backend_got_symbol_offset
  9573. #define elf_backend_got_symbol_offset 0
  9574. #undef elf_backend_plt_not_loaded
  9575. #define elf_backend_plt_not_loaded 0
  9576. #undef elf_backend_plt_readonly
  9577. #define elf_backend_plt_readonly 1
  9578. #undef elf_backend_got_header_size
  9579. #define elf_backend_got_header_size 12
  9580. #undef bfd_elf32_get_synthetic_symtab
  9581. #undef bfd_elf32_bfd_link_hash_table_create
  9582. #define bfd_elf32_bfd_link_hash_table_create \
  9583. ppc_elf_vxworks_link_hash_table_create
  9584. #undef elf_backend_add_symbol_hook
  9585. #define elf_backend_add_symbol_hook \
  9586. ppc_elf_vxworks_add_symbol_hook
  9587. #undef elf_backend_link_output_symbol_hook
  9588. #define elf_backend_link_output_symbol_hook \
  9589. elf_vxworks_link_output_symbol_hook
  9590. #undef elf_backend_final_write_processing
  9591. #define elf_backend_final_write_processing \
  9592. ppc_elf_vxworks_final_write_processing
  9593. #undef elf_backend_get_sec_type_attr
  9594. #define elf_backend_get_sec_type_attr \
  9595. ppc_elf_vxworks_get_sec_type_attr
  9596. #undef elf_backend_emit_relocs
  9597. #define elf_backend_emit_relocs \
  9598. elf_vxworks_emit_relocs
  9599. #undef elf32_bed
  9600. #define elf32_bed ppc_elf_vxworks_bed
  9601. #undef elf_backend_post_process_headers
  9602. #include "elf32-target.h"