elfnn-aarch64.c 281 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388
  1. /* AArch64-specific support for NN-bit ELF.
  2. Copyright (C) 2009-2015 Free Software Foundation, Inc.
  3. Contributed by ARM Ltd.
  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; see the file COPYING3. If not,
  15. see <http://www.gnu.org/licenses/>. */
  16. /* Notes on implementation:
  17. Thread Local Store (TLS)
  18. Overview:
  19. The implementation currently supports both traditional TLS and TLS
  20. descriptors, but only general dynamic (GD).
  21. For traditional TLS the assembler will present us with code
  22. fragments of the form:
  23. adrp x0, :tlsgd:foo
  24. R_AARCH64_TLSGD_ADR_PAGE21(foo)
  25. add x0, :tlsgd_lo12:foo
  26. R_AARCH64_TLSGD_ADD_LO12_NC(foo)
  27. bl __tls_get_addr
  28. nop
  29. For TLS descriptors the assembler will present us with code
  30. fragments of the form:
  31. adrp x0, :tlsdesc:foo R_AARCH64_TLSDESC_ADR_PAGE21(foo)
  32. ldr x1, [x0, #:tlsdesc_lo12:foo] R_AARCH64_TLSDESC_LD64_LO12(foo)
  33. add x0, x0, #:tlsdesc_lo12:foo R_AARCH64_TLSDESC_ADD_LO12(foo)
  34. .tlsdesccall foo
  35. blr x1 R_AARCH64_TLSDESC_CALL(foo)
  36. The relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} against foo
  37. indicate that foo is thread local and should be accessed via the
  38. traditional TLS mechanims.
  39. The relocations R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC}
  40. against foo indicate that 'foo' is thread local and should be accessed
  41. via a TLS descriptor mechanism.
  42. The precise instruction sequence is only relevant from the
  43. perspective of linker relaxation which is currently not implemented.
  44. The static linker must detect that 'foo' is a TLS object and
  45. allocate a double GOT entry. The GOT entry must be created for both
  46. global and local TLS symbols. Note that this is different to none
  47. TLS local objects which do not need a GOT entry.
  48. In the traditional TLS mechanism, the double GOT entry is used to
  49. provide the tls_index structure, containing module and offset
  50. entries. The static linker places the relocation R_AARCH64_TLS_DTPMOD
  51. on the module entry. The loader will subsequently fixup this
  52. relocation with the module identity.
  53. For global traditional TLS symbols the static linker places an
  54. R_AARCH64_TLS_DTPREL relocation on the offset entry. The loader
  55. will subsequently fixup the offset. For local TLS symbols the static
  56. linker fixes up offset.
  57. In the TLS descriptor mechanism the double GOT entry is used to
  58. provide the descriptor. The static linker places the relocation
  59. R_AARCH64_TLSDESC on the first GOT slot. The loader will
  60. subsequently fix this up.
  61. Implementation:
  62. The handling of TLS symbols is implemented across a number of
  63. different backend functions. The following is a top level view of
  64. what processing is performed where.
  65. The TLS implementation maintains state information for each TLS
  66. symbol. The state information for local and global symbols is kept
  67. in different places. Global symbols use generic BFD structures while
  68. local symbols use backend specific structures that are allocated and
  69. maintained entirely by the backend.
  70. The flow:
  71. elfNN_aarch64_check_relocs()
  72. This function is invoked for each relocation.
  73. The TLS relocations R_AARCH64_TLSGD_{ADR_PREL21,ADD_LO12_NC} and
  74. R_AARCH64_TLSDESC_{ADR_PAGE21,LD64_LO12_NC,ADD_LO12_NC} are
  75. spotted. One time creation of local symbol data structures are
  76. created when the first local symbol is seen.
  77. The reference count for a symbol is incremented. The GOT type for
  78. each symbol is marked as general dynamic.
  79. elfNN_aarch64_allocate_dynrelocs ()
  80. For each global with positive reference count we allocate a double
  81. GOT slot. For a traditional TLS symbol we allocate space for two
  82. relocation entries on the GOT, for a TLS descriptor symbol we
  83. allocate space for one relocation on the slot. Record the GOT offset
  84. for this symbol.
  85. elfNN_aarch64_size_dynamic_sections ()
  86. Iterate all input BFDS, look for in the local symbol data structure
  87. constructed earlier for local TLS symbols and allocate them double
  88. GOT slots along with space for a single GOT relocation. Update the
  89. local symbol structure to record the GOT offset allocated.
  90. elfNN_aarch64_relocate_section ()
  91. Calls elfNN_aarch64_final_link_relocate ()
  92. Emit the relevant TLS relocations against the GOT for each TLS
  93. symbol. For local TLS symbols emit the GOT offset directly. The GOT
  94. relocations are emitted once the first time a TLS symbol is
  95. encountered. The implementation uses the LSB of the GOT offset to
  96. flag that the relevant GOT relocations for a symbol have been
  97. emitted. All of the TLS code that uses the GOT offset needs to take
  98. care to mask out this flag bit before using the offset.
  99. elfNN_aarch64_final_link_relocate ()
  100. Fixup the R_AARCH64_TLSGD_{ADR_PREL21, ADD_LO12_NC} relocations. */
  101. #include "sysdep.h"
  102. #include "bfd.h"
  103. #include "libiberty.h"
  104. #include "libbfd.h"
  105. #include "bfd_stdint.h"
  106. #include "elf-bfd.h"
  107. #include "bfdlink.h"
  108. #include "objalloc.h"
  109. #include "elf/aarch64.h"
  110. #include "elfxx-aarch64.h"
  111. #define ARCH_SIZE NN
  112. #if ARCH_SIZE == 64
  113. #define AARCH64_R(NAME) R_AARCH64_ ## NAME
  114. #define AARCH64_R_STR(NAME) "R_AARCH64_" #NAME
  115. #define HOWTO64(...) HOWTO (__VA_ARGS__)
  116. #define HOWTO32(...) EMPTY_HOWTO (0)
  117. #define LOG_FILE_ALIGN 3
  118. #endif
  119. #if ARCH_SIZE == 32
  120. #define AARCH64_R(NAME) R_AARCH64_P32_ ## NAME
  121. #define AARCH64_R_STR(NAME) "R_AARCH64_P32_" #NAME
  122. #define HOWTO64(...) EMPTY_HOWTO (0)
  123. #define HOWTO32(...) HOWTO (__VA_ARGS__)
  124. #define LOG_FILE_ALIGN 2
  125. #endif
  126. #define IS_AARCH64_TLS_RELOC(R_TYPE) \
  127. ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
  128. || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
  129. || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
  130. || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
  131. || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
  132. || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
  133. || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC \
  134. || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC \
  135. || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
  136. || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC \
  137. || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
  138. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12 \
  139. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12 \
  140. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC \
  141. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
  142. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
  143. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21 \
  144. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12 \
  145. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC \
  146. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12 \
  147. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC \
  148. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12 \
  149. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC \
  150. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12 \
  151. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC \
  152. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0 \
  153. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC \
  154. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1 \
  155. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC \
  156. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2 \
  157. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 \
  158. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12 \
  159. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC \
  160. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0 \
  161. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC \
  162. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 \
  163. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC \
  164. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 \
  165. || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPMOD \
  166. || (R_TYPE) == BFD_RELOC_AARCH64_TLS_DTPREL \
  167. || (R_TYPE) == BFD_RELOC_AARCH64_TLS_TPREL \
  168. || IS_AARCH64_TLSDESC_RELOC ((R_TYPE)))
  169. #define IS_AARCH64_TLS_RELAX_RELOC(R_TYPE) \
  170. ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
  171. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
  172. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
  173. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
  174. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
  175. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
  176. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC \
  177. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
  178. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
  179. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1 \
  180. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
  181. || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21 \
  182. || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 \
  183. || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC \
  184. || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC \
  185. || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_MOVW_G1 \
  186. || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 \
  187. || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19 \
  188. || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC \
  189. || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1 \
  190. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC \
  191. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21 \
  192. || (R_TYPE) == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21)
  193. #define IS_AARCH64_TLSDESC_RELOC(R_TYPE) \
  194. ((R_TYPE) == BFD_RELOC_AARCH64_TLSDESC \
  195. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD \
  196. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC \
  197. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21 \
  198. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21 \
  199. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_CALL \
  200. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC \
  201. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC \
  202. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LDR \
  203. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_LD_PREL19 \
  204. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC \
  205. || (R_TYPE) == BFD_RELOC_AARCH64_TLSDESC_OFF_G1)
  206. #define ELIMINATE_COPY_RELOCS 0
  207. /* Return size of a relocation entry. HTAB is the bfd's
  208. elf_aarch64_link_hash_entry. */
  209. #define RELOC_SIZE(HTAB) (sizeof (ElfNN_External_Rela))
  210. /* GOT Entry size - 8 bytes in ELF64 and 4 bytes in ELF32. */
  211. #define GOT_ENTRY_SIZE (ARCH_SIZE / 8)
  212. #define PLT_ENTRY_SIZE (32)
  213. #define PLT_SMALL_ENTRY_SIZE (16)
  214. #define PLT_TLSDESC_ENTRY_SIZE (32)
  215. /* Encoding of the nop instruction */
  216. #define INSN_NOP 0xd503201f
  217. #define aarch64_compute_jump_table_size(htab) \
  218. (((htab)->root.srelplt == NULL) ? 0 \
  219. : (htab)->root.srelplt->reloc_count * GOT_ENTRY_SIZE)
  220. /* The first entry in a procedure linkage table looks like this
  221. if the distance between the PLTGOT and the PLT is < 4GB use
  222. these PLT entries. Note that the dynamic linker gets &PLTGOT[2]
  223. in x16 and needs to work out PLTGOT[1] by using an address of
  224. [x16,#-GOT_ENTRY_SIZE]. */
  225. static const bfd_byte elfNN_aarch64_small_plt0_entry[PLT_ENTRY_SIZE] =
  226. {
  227. 0xf0, 0x7b, 0xbf, 0xa9, /* stp x16, x30, [sp, #-16]! */
  228. 0x10, 0x00, 0x00, 0x90, /* adrp x16, (GOT+16) */
  229. #if ARCH_SIZE == 64
  230. 0x11, 0x0A, 0x40, 0xf9, /* ldr x17, [x16, #PLT_GOT+0x10] */
  231. 0x10, 0x42, 0x00, 0x91, /* add x16, x16,#PLT_GOT+0x10 */
  232. #else
  233. 0x11, 0x0A, 0x40, 0xb9, /* ldr w17, [x16, #PLT_GOT+0x8] */
  234. 0x10, 0x22, 0x00, 0x11, /* add w16, w16,#PLT_GOT+0x8 */
  235. #endif
  236. 0x20, 0x02, 0x1f, 0xd6, /* br x17 */
  237. 0x1f, 0x20, 0x03, 0xd5, /* nop */
  238. 0x1f, 0x20, 0x03, 0xd5, /* nop */
  239. 0x1f, 0x20, 0x03, 0xd5, /* nop */
  240. };
  241. /* Per function entry in a procedure linkage table looks like this
  242. if the distance between the PLTGOT and the PLT is < 4GB use
  243. these PLT entries. */
  244. static const bfd_byte elfNN_aarch64_small_plt_entry[PLT_SMALL_ENTRY_SIZE] =
  245. {
  246. 0x10, 0x00, 0x00, 0x90, /* adrp x16, PLTGOT + n * 8 */
  247. #if ARCH_SIZE == 64
  248. 0x11, 0x02, 0x40, 0xf9, /* ldr x17, [x16, PLTGOT + n * 8] */
  249. 0x10, 0x02, 0x00, 0x91, /* add x16, x16, :lo12:PLTGOT + n * 8 */
  250. #else
  251. 0x11, 0x02, 0x40, 0xb9, /* ldr w17, [x16, PLTGOT + n * 4] */
  252. 0x10, 0x02, 0x00, 0x11, /* add w16, w16, :lo12:PLTGOT + n * 4 */
  253. #endif
  254. 0x20, 0x02, 0x1f, 0xd6, /* br x17. */
  255. };
  256. static const bfd_byte
  257. elfNN_aarch64_tlsdesc_small_plt_entry[PLT_TLSDESC_ENTRY_SIZE] =
  258. {
  259. 0xe2, 0x0f, 0xbf, 0xa9, /* stp x2, x3, [sp, #-16]! */
  260. 0x02, 0x00, 0x00, 0x90, /* adrp x2, 0 */
  261. 0x03, 0x00, 0x00, 0x90, /* adrp x3, 0 */
  262. #if ARCH_SIZE == 64
  263. 0x42, 0x00, 0x40, 0xf9, /* ldr x2, [x2, #0] */
  264. 0x63, 0x00, 0x00, 0x91, /* add x3, x3, 0 */
  265. #else
  266. 0x42, 0x00, 0x40, 0xb9, /* ldr w2, [x2, #0] */
  267. 0x63, 0x00, 0x00, 0x11, /* add w3, w3, 0 */
  268. #endif
  269. 0x40, 0x00, 0x1f, 0xd6, /* br x2 */
  270. 0x1f, 0x20, 0x03, 0xd5, /* nop */
  271. 0x1f, 0x20, 0x03, 0xd5, /* nop */
  272. };
  273. #define elf_info_to_howto elfNN_aarch64_info_to_howto
  274. #define elf_info_to_howto_rel elfNN_aarch64_info_to_howto
  275. #define AARCH64_ELF_ABI_VERSION 0
  276. /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
  277. #define ALL_ONES (~ (bfd_vma) 0)
  278. /* Indexed by the bfd interal reloc enumerators.
  279. Therefore, the table needs to be synced with BFD_RELOC_AARCH64_*
  280. in reloc.c. */
  281. static reloc_howto_type elfNN_aarch64_howto_table[] =
  282. {
  283. EMPTY_HOWTO (0),
  284. /* Basic data relocations. */
  285. #if ARCH_SIZE == 64
  286. HOWTO (R_AARCH64_NULL, /* type */
  287. 0, /* rightshift */
  288. 3, /* size (0 = byte, 1 = short, 2 = long) */
  289. 0, /* bitsize */
  290. FALSE, /* pc_relative */
  291. 0, /* bitpos */
  292. complain_overflow_dont, /* complain_on_overflow */
  293. bfd_elf_generic_reloc, /* special_function */
  294. "R_AARCH64_NULL", /* name */
  295. FALSE, /* partial_inplace */
  296. 0, /* src_mask */
  297. 0, /* dst_mask */
  298. FALSE), /* pcrel_offset */
  299. #else
  300. HOWTO (R_AARCH64_NONE, /* type */
  301. 0, /* rightshift */
  302. 3, /* size (0 = byte, 1 = short, 2 = long) */
  303. 0, /* bitsize */
  304. FALSE, /* pc_relative */
  305. 0, /* bitpos */
  306. complain_overflow_dont, /* complain_on_overflow */
  307. bfd_elf_generic_reloc, /* special_function */
  308. "R_AARCH64_NONE", /* name */
  309. FALSE, /* partial_inplace */
  310. 0, /* src_mask */
  311. 0, /* dst_mask */
  312. FALSE), /* pcrel_offset */
  313. #endif
  314. /* .xword: (S+A) */
  315. HOWTO64 (AARCH64_R (ABS64), /* type */
  316. 0, /* rightshift */
  317. 4, /* size (4 = long long) */
  318. 64, /* bitsize */
  319. FALSE, /* pc_relative */
  320. 0, /* bitpos */
  321. complain_overflow_unsigned, /* complain_on_overflow */
  322. bfd_elf_generic_reloc, /* special_function */
  323. AARCH64_R_STR (ABS64), /* name */
  324. FALSE, /* partial_inplace */
  325. ALL_ONES, /* src_mask */
  326. ALL_ONES, /* dst_mask */
  327. FALSE), /* pcrel_offset */
  328. /* .word: (S+A) */
  329. HOWTO (AARCH64_R (ABS32), /* type */
  330. 0, /* rightshift */
  331. 2, /* size (0 = byte, 1 = short, 2 = long) */
  332. 32, /* bitsize */
  333. FALSE, /* pc_relative */
  334. 0, /* bitpos */
  335. complain_overflow_unsigned, /* complain_on_overflow */
  336. bfd_elf_generic_reloc, /* special_function */
  337. AARCH64_R_STR (ABS32), /* name */
  338. FALSE, /* partial_inplace */
  339. 0xffffffff, /* src_mask */
  340. 0xffffffff, /* dst_mask */
  341. FALSE), /* pcrel_offset */
  342. /* .half: (S+A) */
  343. HOWTO (AARCH64_R (ABS16), /* type */
  344. 0, /* rightshift */
  345. 1, /* size (0 = byte, 1 = short, 2 = long) */
  346. 16, /* bitsize */
  347. FALSE, /* pc_relative */
  348. 0, /* bitpos */
  349. complain_overflow_unsigned, /* complain_on_overflow */
  350. bfd_elf_generic_reloc, /* special_function */
  351. AARCH64_R_STR (ABS16), /* name */
  352. FALSE, /* partial_inplace */
  353. 0xffff, /* src_mask */
  354. 0xffff, /* dst_mask */
  355. FALSE), /* pcrel_offset */
  356. /* .xword: (S+A-P) */
  357. HOWTO64 (AARCH64_R (PREL64), /* type */
  358. 0, /* rightshift */
  359. 4, /* size (4 = long long) */
  360. 64, /* bitsize */
  361. TRUE, /* pc_relative */
  362. 0, /* bitpos */
  363. complain_overflow_signed, /* complain_on_overflow */
  364. bfd_elf_generic_reloc, /* special_function */
  365. AARCH64_R_STR (PREL64), /* name */
  366. FALSE, /* partial_inplace */
  367. ALL_ONES, /* src_mask */
  368. ALL_ONES, /* dst_mask */
  369. TRUE), /* pcrel_offset */
  370. /* .word: (S+A-P) */
  371. HOWTO (AARCH64_R (PREL32), /* type */
  372. 0, /* rightshift */
  373. 2, /* size (0 = byte, 1 = short, 2 = long) */
  374. 32, /* bitsize */
  375. TRUE, /* pc_relative */
  376. 0, /* bitpos */
  377. complain_overflow_signed, /* complain_on_overflow */
  378. bfd_elf_generic_reloc, /* special_function */
  379. AARCH64_R_STR (PREL32), /* name */
  380. FALSE, /* partial_inplace */
  381. 0xffffffff, /* src_mask */
  382. 0xffffffff, /* dst_mask */
  383. TRUE), /* pcrel_offset */
  384. /* .half: (S+A-P) */
  385. HOWTO (AARCH64_R (PREL16), /* type */
  386. 0, /* rightshift */
  387. 1, /* size (0 = byte, 1 = short, 2 = long) */
  388. 16, /* bitsize */
  389. TRUE, /* pc_relative */
  390. 0, /* bitpos */
  391. complain_overflow_signed, /* complain_on_overflow */
  392. bfd_elf_generic_reloc, /* special_function */
  393. AARCH64_R_STR (PREL16), /* name */
  394. FALSE, /* partial_inplace */
  395. 0xffff, /* src_mask */
  396. 0xffff, /* dst_mask */
  397. TRUE), /* pcrel_offset */
  398. /* Group relocations to create a 16, 32, 48 or 64 bit
  399. unsigned data or abs address inline. */
  400. /* MOVZ: ((S+A) >> 0) & 0xffff */
  401. HOWTO (AARCH64_R (MOVW_UABS_G0), /* type */
  402. 0, /* rightshift */
  403. 2, /* size (0 = byte, 1 = short, 2 = long) */
  404. 16, /* bitsize */
  405. FALSE, /* pc_relative */
  406. 0, /* bitpos */
  407. complain_overflow_unsigned, /* complain_on_overflow */
  408. bfd_elf_generic_reloc, /* special_function */
  409. AARCH64_R_STR (MOVW_UABS_G0), /* name */
  410. FALSE, /* partial_inplace */
  411. 0xffff, /* src_mask */
  412. 0xffff, /* dst_mask */
  413. FALSE), /* pcrel_offset */
  414. /* MOVK: ((S+A) >> 0) & 0xffff [no overflow check] */
  415. HOWTO (AARCH64_R (MOVW_UABS_G0_NC), /* type */
  416. 0, /* rightshift */
  417. 2, /* size (0 = byte, 1 = short, 2 = long) */
  418. 16, /* bitsize */
  419. FALSE, /* pc_relative */
  420. 0, /* bitpos */
  421. complain_overflow_dont, /* complain_on_overflow */
  422. bfd_elf_generic_reloc, /* special_function */
  423. AARCH64_R_STR (MOVW_UABS_G0_NC), /* name */
  424. FALSE, /* partial_inplace */
  425. 0xffff, /* src_mask */
  426. 0xffff, /* dst_mask */
  427. FALSE), /* pcrel_offset */
  428. /* MOVZ: ((S+A) >> 16) & 0xffff */
  429. HOWTO (AARCH64_R (MOVW_UABS_G1), /* type */
  430. 16, /* rightshift */
  431. 2, /* size (0 = byte, 1 = short, 2 = long) */
  432. 16, /* bitsize */
  433. FALSE, /* pc_relative */
  434. 0, /* bitpos */
  435. complain_overflow_unsigned, /* complain_on_overflow */
  436. bfd_elf_generic_reloc, /* special_function */
  437. AARCH64_R_STR (MOVW_UABS_G1), /* name */
  438. FALSE, /* partial_inplace */
  439. 0xffff, /* src_mask */
  440. 0xffff, /* dst_mask */
  441. FALSE), /* pcrel_offset */
  442. /* MOVK: ((S+A) >> 16) & 0xffff [no overflow check] */
  443. HOWTO64 (AARCH64_R (MOVW_UABS_G1_NC), /* type */
  444. 16, /* rightshift */
  445. 2, /* size (0 = byte, 1 = short, 2 = long) */
  446. 16, /* bitsize */
  447. FALSE, /* pc_relative */
  448. 0, /* bitpos */
  449. complain_overflow_dont, /* complain_on_overflow */
  450. bfd_elf_generic_reloc, /* special_function */
  451. AARCH64_R_STR (MOVW_UABS_G1_NC), /* name */
  452. FALSE, /* partial_inplace */
  453. 0xffff, /* src_mask */
  454. 0xffff, /* dst_mask */
  455. FALSE), /* pcrel_offset */
  456. /* MOVZ: ((S+A) >> 32) & 0xffff */
  457. HOWTO64 (AARCH64_R (MOVW_UABS_G2), /* type */
  458. 32, /* rightshift */
  459. 2, /* size (0 = byte, 1 = short, 2 = long) */
  460. 16, /* bitsize */
  461. FALSE, /* pc_relative */
  462. 0, /* bitpos */
  463. complain_overflow_unsigned, /* complain_on_overflow */
  464. bfd_elf_generic_reloc, /* special_function */
  465. AARCH64_R_STR (MOVW_UABS_G2), /* name */
  466. FALSE, /* partial_inplace */
  467. 0xffff, /* src_mask */
  468. 0xffff, /* dst_mask */
  469. FALSE), /* pcrel_offset */
  470. /* MOVK: ((S+A) >> 32) & 0xffff [no overflow check] */
  471. HOWTO64 (AARCH64_R (MOVW_UABS_G2_NC), /* type */
  472. 32, /* rightshift */
  473. 2, /* size (0 = byte, 1 = short, 2 = long) */
  474. 16, /* bitsize */
  475. FALSE, /* pc_relative */
  476. 0, /* bitpos */
  477. complain_overflow_dont, /* complain_on_overflow */
  478. bfd_elf_generic_reloc, /* special_function */
  479. AARCH64_R_STR (MOVW_UABS_G2_NC), /* name */
  480. FALSE, /* partial_inplace */
  481. 0xffff, /* src_mask */
  482. 0xffff, /* dst_mask */
  483. FALSE), /* pcrel_offset */
  484. /* MOVZ: ((S+A) >> 48) & 0xffff */
  485. HOWTO64 (AARCH64_R (MOVW_UABS_G3), /* type */
  486. 48, /* rightshift */
  487. 2, /* size (0 = byte, 1 = short, 2 = long) */
  488. 16, /* bitsize */
  489. FALSE, /* pc_relative */
  490. 0, /* bitpos */
  491. complain_overflow_unsigned, /* complain_on_overflow */
  492. bfd_elf_generic_reloc, /* special_function */
  493. AARCH64_R_STR (MOVW_UABS_G3), /* name */
  494. FALSE, /* partial_inplace */
  495. 0xffff, /* src_mask */
  496. 0xffff, /* dst_mask */
  497. FALSE), /* pcrel_offset */
  498. /* Group relocations to create high part of a 16, 32, 48 or 64 bit
  499. signed data or abs address inline. Will change instruction
  500. to MOVN or MOVZ depending on sign of calculated value. */
  501. /* MOV[ZN]: ((S+A) >> 0) & 0xffff */
  502. HOWTO (AARCH64_R (MOVW_SABS_G0), /* type */
  503. 0, /* rightshift */
  504. 2, /* size (0 = byte, 1 = short, 2 = long) */
  505. 16, /* bitsize */
  506. FALSE, /* pc_relative */
  507. 0, /* bitpos */
  508. complain_overflow_signed, /* complain_on_overflow */
  509. bfd_elf_generic_reloc, /* special_function */
  510. AARCH64_R_STR (MOVW_SABS_G0), /* name */
  511. FALSE, /* partial_inplace */
  512. 0xffff, /* src_mask */
  513. 0xffff, /* dst_mask */
  514. FALSE), /* pcrel_offset */
  515. /* MOV[ZN]: ((S+A) >> 16) & 0xffff */
  516. HOWTO64 (AARCH64_R (MOVW_SABS_G1), /* type */
  517. 16, /* rightshift */
  518. 2, /* size (0 = byte, 1 = short, 2 = long) */
  519. 16, /* bitsize */
  520. FALSE, /* pc_relative */
  521. 0, /* bitpos */
  522. complain_overflow_signed, /* complain_on_overflow */
  523. bfd_elf_generic_reloc, /* special_function */
  524. AARCH64_R_STR (MOVW_SABS_G1), /* name */
  525. FALSE, /* partial_inplace */
  526. 0xffff, /* src_mask */
  527. 0xffff, /* dst_mask */
  528. FALSE), /* pcrel_offset */
  529. /* MOV[ZN]: ((S+A) >> 32) & 0xffff */
  530. HOWTO64 (AARCH64_R (MOVW_SABS_G2), /* type */
  531. 32, /* rightshift */
  532. 2, /* size (0 = byte, 1 = short, 2 = long) */
  533. 16, /* bitsize */
  534. FALSE, /* pc_relative */
  535. 0, /* bitpos */
  536. complain_overflow_signed, /* complain_on_overflow */
  537. bfd_elf_generic_reloc, /* special_function */
  538. AARCH64_R_STR (MOVW_SABS_G2), /* name */
  539. FALSE, /* partial_inplace */
  540. 0xffff, /* src_mask */
  541. 0xffff, /* dst_mask */
  542. FALSE), /* pcrel_offset */
  543. /* Relocations to generate 19, 21 and 33 bit PC-relative load/store
  544. addresses: PG(x) is (x & ~0xfff). */
  545. /* LD-lit: ((S+A-P) >> 2) & 0x7ffff */
  546. HOWTO (AARCH64_R (LD_PREL_LO19), /* type */
  547. 2, /* rightshift */
  548. 2, /* size (0 = byte, 1 = short, 2 = long) */
  549. 19, /* bitsize */
  550. TRUE, /* pc_relative */
  551. 0, /* bitpos */
  552. complain_overflow_signed, /* complain_on_overflow */
  553. bfd_elf_generic_reloc, /* special_function */
  554. AARCH64_R_STR (LD_PREL_LO19), /* name */
  555. FALSE, /* partial_inplace */
  556. 0x7ffff, /* src_mask */
  557. 0x7ffff, /* dst_mask */
  558. TRUE), /* pcrel_offset */
  559. /* ADR: (S+A-P) & 0x1fffff */
  560. HOWTO (AARCH64_R (ADR_PREL_LO21), /* type */
  561. 0, /* rightshift */
  562. 2, /* size (0 = byte, 1 = short, 2 = long) */
  563. 21, /* bitsize */
  564. TRUE, /* pc_relative */
  565. 0, /* bitpos */
  566. complain_overflow_signed, /* complain_on_overflow */
  567. bfd_elf_generic_reloc, /* special_function */
  568. AARCH64_R_STR (ADR_PREL_LO21), /* name */
  569. FALSE, /* partial_inplace */
  570. 0x1fffff, /* src_mask */
  571. 0x1fffff, /* dst_mask */
  572. TRUE), /* pcrel_offset */
  573. /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
  574. HOWTO (AARCH64_R (ADR_PREL_PG_HI21), /* type */
  575. 12, /* rightshift */
  576. 2, /* size (0 = byte, 1 = short, 2 = long) */
  577. 21, /* bitsize */
  578. TRUE, /* pc_relative */
  579. 0, /* bitpos */
  580. complain_overflow_signed, /* complain_on_overflow */
  581. bfd_elf_generic_reloc, /* special_function */
  582. AARCH64_R_STR (ADR_PREL_PG_HI21), /* name */
  583. FALSE, /* partial_inplace */
  584. 0x1fffff, /* src_mask */
  585. 0x1fffff, /* dst_mask */
  586. TRUE), /* pcrel_offset */
  587. /* ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff [no overflow check] */
  588. HOWTO64 (AARCH64_R (ADR_PREL_PG_HI21_NC), /* type */
  589. 12, /* rightshift */
  590. 2, /* size (0 = byte, 1 = short, 2 = long) */
  591. 21, /* bitsize */
  592. TRUE, /* pc_relative */
  593. 0, /* bitpos */
  594. complain_overflow_dont, /* complain_on_overflow */
  595. bfd_elf_generic_reloc, /* special_function */
  596. AARCH64_R_STR (ADR_PREL_PG_HI21_NC), /* name */
  597. FALSE, /* partial_inplace */
  598. 0x1fffff, /* src_mask */
  599. 0x1fffff, /* dst_mask */
  600. TRUE), /* pcrel_offset */
  601. /* ADD: (S+A) & 0xfff [no overflow check] */
  602. HOWTO (AARCH64_R (ADD_ABS_LO12_NC), /* type */
  603. 0, /* rightshift */
  604. 2, /* size (0 = byte, 1 = short, 2 = long) */
  605. 12, /* bitsize */
  606. FALSE, /* pc_relative */
  607. 10, /* bitpos */
  608. complain_overflow_dont, /* complain_on_overflow */
  609. bfd_elf_generic_reloc, /* special_function */
  610. AARCH64_R_STR (ADD_ABS_LO12_NC), /* name */
  611. FALSE, /* partial_inplace */
  612. 0x3ffc00, /* src_mask */
  613. 0x3ffc00, /* dst_mask */
  614. FALSE), /* pcrel_offset */
  615. /* LD/ST8: (S+A) & 0xfff */
  616. HOWTO (AARCH64_R (LDST8_ABS_LO12_NC), /* type */
  617. 0, /* rightshift */
  618. 2, /* size (0 = byte, 1 = short, 2 = long) */
  619. 12, /* bitsize */
  620. FALSE, /* pc_relative */
  621. 0, /* bitpos */
  622. complain_overflow_dont, /* complain_on_overflow */
  623. bfd_elf_generic_reloc, /* special_function */
  624. AARCH64_R_STR (LDST8_ABS_LO12_NC), /* name */
  625. FALSE, /* partial_inplace */
  626. 0xfff, /* src_mask */
  627. 0xfff, /* dst_mask */
  628. FALSE), /* pcrel_offset */
  629. /* Relocations for control-flow instructions. */
  630. /* TBZ/NZ: ((S+A-P) >> 2) & 0x3fff */
  631. HOWTO (AARCH64_R (TSTBR14), /* type */
  632. 2, /* rightshift */
  633. 2, /* size (0 = byte, 1 = short, 2 = long) */
  634. 14, /* bitsize */
  635. TRUE, /* pc_relative */
  636. 0, /* bitpos */
  637. complain_overflow_signed, /* complain_on_overflow */
  638. bfd_elf_generic_reloc, /* special_function */
  639. AARCH64_R_STR (TSTBR14), /* name */
  640. FALSE, /* partial_inplace */
  641. 0x3fff, /* src_mask */
  642. 0x3fff, /* dst_mask */
  643. TRUE), /* pcrel_offset */
  644. /* B.cond: ((S+A-P) >> 2) & 0x7ffff */
  645. HOWTO (AARCH64_R (CONDBR19), /* type */
  646. 2, /* rightshift */
  647. 2, /* size (0 = byte, 1 = short, 2 = long) */
  648. 19, /* bitsize */
  649. TRUE, /* pc_relative */
  650. 0, /* bitpos */
  651. complain_overflow_signed, /* complain_on_overflow */
  652. bfd_elf_generic_reloc, /* special_function */
  653. AARCH64_R_STR (CONDBR19), /* name */
  654. FALSE, /* partial_inplace */
  655. 0x7ffff, /* src_mask */
  656. 0x7ffff, /* dst_mask */
  657. TRUE), /* pcrel_offset */
  658. /* B: ((S+A-P) >> 2) & 0x3ffffff */
  659. HOWTO (AARCH64_R (JUMP26), /* type */
  660. 2, /* rightshift */
  661. 2, /* size (0 = byte, 1 = short, 2 = long) */
  662. 26, /* bitsize */
  663. TRUE, /* pc_relative */
  664. 0, /* bitpos */
  665. complain_overflow_signed, /* complain_on_overflow */
  666. bfd_elf_generic_reloc, /* special_function */
  667. AARCH64_R_STR (JUMP26), /* name */
  668. FALSE, /* partial_inplace */
  669. 0x3ffffff, /* src_mask */
  670. 0x3ffffff, /* dst_mask */
  671. TRUE), /* pcrel_offset */
  672. /* BL: ((S+A-P) >> 2) & 0x3ffffff */
  673. HOWTO (AARCH64_R (CALL26), /* type */
  674. 2, /* rightshift */
  675. 2, /* size (0 = byte, 1 = short, 2 = long) */
  676. 26, /* bitsize */
  677. TRUE, /* pc_relative */
  678. 0, /* bitpos */
  679. complain_overflow_signed, /* complain_on_overflow */
  680. bfd_elf_generic_reloc, /* special_function */
  681. AARCH64_R_STR (CALL26), /* name */
  682. FALSE, /* partial_inplace */
  683. 0x3ffffff, /* src_mask */
  684. 0x3ffffff, /* dst_mask */
  685. TRUE), /* pcrel_offset */
  686. /* LD/ST16: (S+A) & 0xffe */
  687. HOWTO (AARCH64_R (LDST16_ABS_LO12_NC), /* type */
  688. 1, /* rightshift */
  689. 2, /* size (0 = byte, 1 = short, 2 = long) */
  690. 12, /* bitsize */
  691. FALSE, /* pc_relative */
  692. 0, /* bitpos */
  693. complain_overflow_dont, /* complain_on_overflow */
  694. bfd_elf_generic_reloc, /* special_function */
  695. AARCH64_R_STR (LDST16_ABS_LO12_NC), /* name */
  696. FALSE, /* partial_inplace */
  697. 0xffe, /* src_mask */
  698. 0xffe, /* dst_mask */
  699. FALSE), /* pcrel_offset */
  700. /* LD/ST32: (S+A) & 0xffc */
  701. HOWTO (AARCH64_R (LDST32_ABS_LO12_NC), /* type */
  702. 2, /* rightshift */
  703. 2, /* size (0 = byte, 1 = short, 2 = long) */
  704. 12, /* bitsize */
  705. FALSE, /* pc_relative */
  706. 0, /* bitpos */
  707. complain_overflow_dont, /* complain_on_overflow */
  708. bfd_elf_generic_reloc, /* special_function */
  709. AARCH64_R_STR (LDST32_ABS_LO12_NC), /* name */
  710. FALSE, /* partial_inplace */
  711. 0xffc, /* src_mask */
  712. 0xffc, /* dst_mask */
  713. FALSE), /* pcrel_offset */
  714. /* LD/ST64: (S+A) & 0xff8 */
  715. HOWTO (AARCH64_R (LDST64_ABS_LO12_NC), /* type */
  716. 3, /* rightshift */
  717. 2, /* size (0 = byte, 1 = short, 2 = long) */
  718. 12, /* bitsize */
  719. FALSE, /* pc_relative */
  720. 0, /* bitpos */
  721. complain_overflow_dont, /* complain_on_overflow */
  722. bfd_elf_generic_reloc, /* special_function */
  723. AARCH64_R_STR (LDST64_ABS_LO12_NC), /* name */
  724. FALSE, /* partial_inplace */
  725. 0xff8, /* src_mask */
  726. 0xff8, /* dst_mask */
  727. FALSE), /* pcrel_offset */
  728. /* LD/ST128: (S+A) & 0xff0 */
  729. HOWTO (AARCH64_R (LDST128_ABS_LO12_NC), /* type */
  730. 4, /* rightshift */
  731. 2, /* size (0 = byte, 1 = short, 2 = long) */
  732. 12, /* bitsize */
  733. FALSE, /* pc_relative */
  734. 0, /* bitpos */
  735. complain_overflow_dont, /* complain_on_overflow */
  736. bfd_elf_generic_reloc, /* special_function */
  737. AARCH64_R_STR (LDST128_ABS_LO12_NC), /* name */
  738. FALSE, /* partial_inplace */
  739. 0xff0, /* src_mask */
  740. 0xff0, /* dst_mask */
  741. FALSE), /* pcrel_offset */
  742. /* Set a load-literal immediate field to bits
  743. 0x1FFFFC of G(S)-P */
  744. HOWTO (AARCH64_R (GOT_LD_PREL19), /* type */
  745. 2, /* rightshift */
  746. 2, /* size (0 = byte,1 = short,2 = long) */
  747. 19, /* bitsize */
  748. TRUE, /* pc_relative */
  749. 0, /* bitpos */
  750. complain_overflow_signed, /* complain_on_overflow */
  751. bfd_elf_generic_reloc, /* special_function */
  752. AARCH64_R_STR (GOT_LD_PREL19), /* name */
  753. FALSE, /* partial_inplace */
  754. 0xffffe0, /* src_mask */
  755. 0xffffe0, /* dst_mask */
  756. TRUE), /* pcrel_offset */
  757. /* Get to the page for the GOT entry for the symbol
  758. (G(S) - P) using an ADRP instruction. */
  759. HOWTO (AARCH64_R (ADR_GOT_PAGE), /* type */
  760. 12, /* rightshift */
  761. 2, /* size (0 = byte, 1 = short, 2 = long) */
  762. 21, /* bitsize */
  763. TRUE, /* pc_relative */
  764. 0, /* bitpos */
  765. complain_overflow_dont, /* complain_on_overflow */
  766. bfd_elf_generic_reloc, /* special_function */
  767. AARCH64_R_STR (ADR_GOT_PAGE), /* name */
  768. FALSE, /* partial_inplace */
  769. 0x1fffff, /* src_mask */
  770. 0x1fffff, /* dst_mask */
  771. TRUE), /* pcrel_offset */
  772. /* LD64: GOT offset G(S) & 0xff8 */
  773. HOWTO64 (AARCH64_R (LD64_GOT_LO12_NC), /* type */
  774. 3, /* rightshift */
  775. 2, /* size (0 = byte, 1 = short, 2 = long) */
  776. 12, /* bitsize */
  777. FALSE, /* pc_relative */
  778. 0, /* bitpos */
  779. complain_overflow_dont, /* complain_on_overflow */
  780. bfd_elf_generic_reloc, /* special_function */
  781. AARCH64_R_STR (LD64_GOT_LO12_NC), /* name */
  782. FALSE, /* partial_inplace */
  783. 0xff8, /* src_mask */
  784. 0xff8, /* dst_mask */
  785. FALSE), /* pcrel_offset */
  786. /* LD32: GOT offset G(S) & 0xffc */
  787. HOWTO32 (AARCH64_R (LD32_GOT_LO12_NC), /* type */
  788. 2, /* rightshift */
  789. 2, /* size (0 = byte, 1 = short, 2 = long) */
  790. 12, /* bitsize */
  791. FALSE, /* pc_relative */
  792. 0, /* bitpos */
  793. complain_overflow_dont, /* complain_on_overflow */
  794. bfd_elf_generic_reloc, /* special_function */
  795. AARCH64_R_STR (LD32_GOT_LO12_NC), /* name */
  796. FALSE, /* partial_inplace */
  797. 0xffc, /* src_mask */
  798. 0xffc, /* dst_mask */
  799. FALSE), /* pcrel_offset */
  800. /* Lower 16 bits of GOT offset for the symbol. */
  801. HOWTO64 (AARCH64_R (MOVW_GOTOFF_G0_NC), /* type */
  802. 0, /* rightshift */
  803. 2, /* size (0 = byte, 1 = short, 2 = long) */
  804. 16, /* bitsize */
  805. FALSE, /* pc_relative */
  806. 0, /* bitpos */
  807. complain_overflow_dont, /* complain_on_overflow */
  808. bfd_elf_generic_reloc, /* special_function */
  809. AARCH64_R_STR (MOVW_GOTOFF_G0_NC), /* name */
  810. FALSE, /* partial_inplace */
  811. 0xffff, /* src_mask */
  812. 0xffff, /* dst_mask */
  813. FALSE), /* pcrel_offset */
  814. /* Higher 16 bits of GOT offset for the symbol. */
  815. HOWTO64 (AARCH64_R (MOVW_GOTOFF_G1), /* type */
  816. 16, /* rightshift */
  817. 2, /* size (0 = byte, 1 = short, 2 = long) */
  818. 16, /* bitsize */
  819. FALSE, /* pc_relative */
  820. 0, /* bitpos */
  821. complain_overflow_unsigned, /* complain_on_overflow */
  822. bfd_elf_generic_reloc, /* special_function */
  823. AARCH64_R_STR (MOVW_GOTOFF_G1), /* name */
  824. FALSE, /* partial_inplace */
  825. 0xffff, /* src_mask */
  826. 0xffff, /* dst_mask */
  827. FALSE), /* pcrel_offset */
  828. /* LD64: GOT offset for the symbol. */
  829. HOWTO64 (AARCH64_R (LD64_GOTOFF_LO15), /* type */
  830. 3, /* rightshift */
  831. 2, /* size (0 = byte, 1 = short, 2 = long) */
  832. 12, /* bitsize */
  833. FALSE, /* pc_relative */
  834. 0, /* bitpos */
  835. complain_overflow_unsigned, /* complain_on_overflow */
  836. bfd_elf_generic_reloc, /* special_function */
  837. AARCH64_R_STR (LD64_GOTOFF_LO15), /* name */
  838. FALSE, /* partial_inplace */
  839. 0x7ff8, /* src_mask */
  840. 0x7ff8, /* dst_mask */
  841. FALSE), /* pcrel_offset */
  842. /* LD32: GOT offset to the page address of GOT table.
  843. (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x5ffc. */
  844. HOWTO32 (AARCH64_R (LD32_GOTPAGE_LO14), /* type */
  845. 2, /* rightshift */
  846. 2, /* size (0 = byte, 1 = short, 2 = long) */
  847. 12, /* bitsize */
  848. FALSE, /* pc_relative */
  849. 0, /* bitpos */
  850. complain_overflow_unsigned, /* complain_on_overflow */
  851. bfd_elf_generic_reloc, /* special_function */
  852. AARCH64_R_STR (LD32_GOTPAGE_LO14), /* name */
  853. FALSE, /* partial_inplace */
  854. 0x5ffc, /* src_mask */
  855. 0x5ffc, /* dst_mask */
  856. FALSE), /* pcrel_offset */
  857. /* LD64: GOT offset to the page address of GOT table.
  858. (G(S) - PAGE (_GLOBAL_OFFSET_TABLE_)) & 0x7ff8. */
  859. HOWTO64 (AARCH64_R (LD64_GOTPAGE_LO15), /* type */
  860. 3, /* rightshift */
  861. 2, /* size (0 = byte, 1 = short, 2 = long) */
  862. 12, /* bitsize */
  863. FALSE, /* pc_relative */
  864. 0, /* bitpos */
  865. complain_overflow_unsigned, /* complain_on_overflow */
  866. bfd_elf_generic_reloc, /* special_function */
  867. AARCH64_R_STR (LD64_GOTPAGE_LO15), /* name */
  868. FALSE, /* partial_inplace */
  869. 0x7ff8, /* src_mask */
  870. 0x7ff8, /* dst_mask */
  871. FALSE), /* pcrel_offset */
  872. /* Get to the page for the GOT entry for the symbol
  873. (G(S) - P) using an ADRP instruction. */
  874. HOWTO (AARCH64_R (TLSGD_ADR_PAGE21), /* type */
  875. 12, /* rightshift */
  876. 2, /* size (0 = byte, 1 = short, 2 = long) */
  877. 21, /* bitsize */
  878. TRUE, /* pc_relative */
  879. 0, /* bitpos */
  880. complain_overflow_dont, /* complain_on_overflow */
  881. bfd_elf_generic_reloc, /* special_function */
  882. AARCH64_R_STR (TLSGD_ADR_PAGE21), /* name */
  883. FALSE, /* partial_inplace */
  884. 0x1fffff, /* src_mask */
  885. 0x1fffff, /* dst_mask */
  886. TRUE), /* pcrel_offset */
  887. HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */
  888. 0, /* rightshift */
  889. 2, /* size (0 = byte, 1 = short, 2 = long) */
  890. 21, /* bitsize */
  891. TRUE, /* pc_relative */
  892. 0, /* bitpos */
  893. complain_overflow_dont, /* complain_on_overflow */
  894. bfd_elf_generic_reloc, /* special_function */
  895. AARCH64_R_STR (TLSGD_ADR_PREL21), /* name */
  896. FALSE, /* partial_inplace */
  897. 0x1fffff, /* src_mask */
  898. 0x1fffff, /* dst_mask */
  899. TRUE), /* pcrel_offset */
  900. /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
  901. HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC), /* type */
  902. 0, /* rightshift */
  903. 2, /* size (0 = byte, 1 = short, 2 = long) */
  904. 12, /* bitsize */
  905. FALSE, /* pc_relative */
  906. 0, /* bitpos */
  907. complain_overflow_dont, /* complain_on_overflow */
  908. bfd_elf_generic_reloc, /* special_function */
  909. AARCH64_R_STR (TLSGD_ADD_LO12_NC), /* name */
  910. FALSE, /* partial_inplace */
  911. 0xfff, /* src_mask */
  912. 0xfff, /* dst_mask */
  913. FALSE), /* pcrel_offset */
  914. /* Lower 16 bits of GOT offset to tls_index. */
  915. HOWTO64 (AARCH64_R (TLSGD_MOVW_G0_NC), /* type */
  916. 0, /* rightshift */
  917. 2, /* size (0 = byte, 1 = short, 2 = long) */
  918. 16, /* bitsize */
  919. FALSE, /* pc_relative */
  920. 0, /* bitpos */
  921. complain_overflow_dont, /* complain_on_overflow */
  922. bfd_elf_generic_reloc, /* special_function */
  923. AARCH64_R_STR (TLSGD_MOVW_G0_NC), /* name */
  924. FALSE, /* partial_inplace */
  925. 0xffff, /* src_mask */
  926. 0xffff, /* dst_mask */
  927. FALSE), /* pcrel_offset */
  928. /* Higher 16 bits of GOT offset to tls_index. */
  929. HOWTO64 (AARCH64_R (TLSGD_MOVW_G1), /* type */
  930. 16, /* rightshift */
  931. 2, /* size (0 = byte, 1 = short, 2 = long) */
  932. 16, /* bitsize */
  933. FALSE, /* pc_relative */
  934. 0, /* bitpos */
  935. complain_overflow_unsigned, /* complain_on_overflow */
  936. bfd_elf_generic_reloc, /* special_function */
  937. AARCH64_R_STR (TLSGD_MOVW_G1), /* name */
  938. FALSE, /* partial_inplace */
  939. 0xffff, /* src_mask */
  940. 0xffff, /* dst_mask */
  941. FALSE), /* pcrel_offset */
  942. HOWTO (AARCH64_R (TLSIE_ADR_GOTTPREL_PAGE21), /* type */
  943. 12, /* rightshift */
  944. 2, /* size (0 = byte, 1 = short, 2 = long) */
  945. 21, /* bitsize */
  946. FALSE, /* pc_relative */
  947. 0, /* bitpos */
  948. complain_overflow_dont, /* complain_on_overflow */
  949. bfd_elf_generic_reloc, /* special_function */
  950. AARCH64_R_STR (TLSIE_ADR_GOTTPREL_PAGE21), /* name */
  951. FALSE, /* partial_inplace */
  952. 0x1fffff, /* src_mask */
  953. 0x1fffff, /* dst_mask */
  954. FALSE), /* pcrel_offset */
  955. HOWTO64 (AARCH64_R (TLSIE_LD64_GOTTPREL_LO12_NC), /* type */
  956. 3, /* rightshift */
  957. 2, /* size (0 = byte, 1 = short, 2 = long) */
  958. 12, /* bitsize */
  959. FALSE, /* pc_relative */
  960. 0, /* bitpos */
  961. complain_overflow_dont, /* complain_on_overflow */
  962. bfd_elf_generic_reloc, /* special_function */
  963. AARCH64_R_STR (TLSIE_LD64_GOTTPREL_LO12_NC), /* name */
  964. FALSE, /* partial_inplace */
  965. 0xff8, /* src_mask */
  966. 0xff8, /* dst_mask */
  967. FALSE), /* pcrel_offset */
  968. HOWTO32 (AARCH64_R (TLSIE_LD32_GOTTPREL_LO12_NC), /* type */
  969. 2, /* rightshift */
  970. 2, /* size (0 = byte, 1 = short, 2 = long) */
  971. 12, /* bitsize */
  972. FALSE, /* pc_relative */
  973. 0, /* bitpos */
  974. complain_overflow_dont, /* complain_on_overflow */
  975. bfd_elf_generic_reloc, /* special_function */
  976. AARCH64_R_STR (TLSIE_LD32_GOTTPREL_LO12_NC), /* name */
  977. FALSE, /* partial_inplace */
  978. 0xffc, /* src_mask */
  979. 0xffc, /* dst_mask */
  980. FALSE), /* pcrel_offset */
  981. HOWTO (AARCH64_R (TLSIE_LD_GOTTPREL_PREL19), /* type */
  982. 2, /* rightshift */
  983. 2, /* size (0 = byte, 1 = short, 2 = long) */
  984. 19, /* bitsize */
  985. FALSE, /* pc_relative */
  986. 0, /* bitpos */
  987. complain_overflow_dont, /* complain_on_overflow */
  988. bfd_elf_generic_reloc, /* special_function */
  989. AARCH64_R_STR (TLSIE_LD_GOTTPREL_PREL19), /* name */
  990. FALSE, /* partial_inplace */
  991. 0x1ffffc, /* src_mask */
  992. 0x1ffffc, /* dst_mask */
  993. FALSE), /* pcrel_offset */
  994. HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC), /* type */
  995. 0, /* rightshift */
  996. 2, /* size (0 = byte, 1 = short, 2 = long) */
  997. 16, /* bitsize */
  998. FALSE, /* pc_relative */
  999. 0, /* bitpos */
  1000. complain_overflow_dont, /* complain_on_overflow */
  1001. bfd_elf_generic_reloc, /* special_function */
  1002. AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G0_NC), /* name */
  1003. FALSE, /* partial_inplace */
  1004. 0xffff, /* src_mask */
  1005. 0xffff, /* dst_mask */
  1006. FALSE), /* pcrel_offset */
  1007. HOWTO64 (AARCH64_R (TLSIE_MOVW_GOTTPREL_G1), /* type */
  1008. 16, /* rightshift */
  1009. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1010. 16, /* bitsize */
  1011. FALSE, /* pc_relative */
  1012. 0, /* bitpos */
  1013. complain_overflow_unsigned, /* complain_on_overflow */
  1014. bfd_elf_generic_reloc, /* special_function */
  1015. AARCH64_R_STR (TLSIE_MOVW_GOTTPREL_G1), /* name */
  1016. FALSE, /* partial_inplace */
  1017. 0xffff, /* src_mask */
  1018. 0xffff, /* dst_mask */
  1019. FALSE), /* pcrel_offset */
  1020. /* ADD: bit[23:12] of byte offset to module TLS base address. */
  1021. HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_HI12), /* type */
  1022. 12, /* rightshift */
  1023. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1024. 12, /* bitsize */
  1025. FALSE, /* pc_relative */
  1026. 0, /* bitpos */
  1027. complain_overflow_unsigned, /* complain_on_overflow */
  1028. bfd_elf_generic_reloc, /* special_function */
  1029. AARCH64_R_STR (TLSLD_ADD_DTPREL_HI12), /* name */
  1030. FALSE, /* partial_inplace */
  1031. 0xfff, /* src_mask */
  1032. 0xfff, /* dst_mask */
  1033. FALSE), /* pcrel_offset */
  1034. /* Unsigned 12 bit byte offset to module TLS base address. */
  1035. HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12), /* type */
  1036. 0, /* rightshift */
  1037. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1038. 12, /* bitsize */
  1039. FALSE, /* pc_relative */
  1040. 0, /* bitpos */
  1041. complain_overflow_unsigned, /* complain_on_overflow */
  1042. bfd_elf_generic_reloc, /* special_function */
  1043. AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12), /* name */
  1044. FALSE, /* partial_inplace */
  1045. 0xfff, /* src_mask */
  1046. 0xfff, /* dst_mask */
  1047. FALSE), /* pcrel_offset */
  1048. /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12. */
  1049. HOWTO (AARCH64_R (TLSLD_ADD_DTPREL_LO12_NC), /* type */
  1050. 0, /* rightshift */
  1051. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1052. 12, /* bitsize */
  1053. FALSE, /* pc_relative */
  1054. 0, /* bitpos */
  1055. complain_overflow_dont, /* complain_on_overflow */
  1056. bfd_elf_generic_reloc, /* special_function */
  1057. AARCH64_R_STR (TLSLD_ADD_DTPREL_LO12_NC), /* name */
  1058. FALSE, /* partial_inplace */
  1059. 0xfff, /* src_mask */
  1060. 0xfff, /* dst_mask */
  1061. FALSE), /* pcrel_offset */
  1062. /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
  1063. HOWTO (AARCH64_R (TLSLD_ADD_LO12_NC), /* type */
  1064. 0, /* rightshift */
  1065. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1066. 12, /* bitsize */
  1067. FALSE, /* pc_relative */
  1068. 0, /* bitpos */
  1069. complain_overflow_dont, /* complain_on_overflow */
  1070. bfd_elf_generic_reloc, /* special_function */
  1071. AARCH64_R_STR (TLSLD_ADD_LO12_NC), /* name */
  1072. FALSE, /* partial_inplace */
  1073. 0xfff, /* src_mask */
  1074. 0xfff, /* dst_mask */
  1075. FALSE), /* pcrel_offset */
  1076. /* Get to the page for the GOT entry for the symbol
  1077. (G(S) - P) using an ADRP instruction. */
  1078. HOWTO (AARCH64_R (TLSLD_ADR_PAGE21), /* type */
  1079. 12, /* rightshift */
  1080. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1081. 21, /* bitsize */
  1082. TRUE, /* pc_relative */
  1083. 0, /* bitpos */
  1084. complain_overflow_signed, /* complain_on_overflow */
  1085. bfd_elf_generic_reloc, /* special_function */
  1086. AARCH64_R_STR (TLSLD_ADR_PAGE21), /* name */
  1087. FALSE, /* partial_inplace */
  1088. 0x1fffff, /* src_mask */
  1089. 0x1fffff, /* dst_mask */
  1090. TRUE), /* pcrel_offset */
  1091. HOWTO (AARCH64_R (TLSLD_ADR_PREL21), /* type */
  1092. 0, /* rightshift */
  1093. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1094. 21, /* bitsize */
  1095. TRUE, /* pc_relative */
  1096. 0, /* bitpos */
  1097. complain_overflow_signed, /* complain_on_overflow */
  1098. bfd_elf_generic_reloc, /* special_function */
  1099. AARCH64_R_STR (TLSLD_ADR_PREL21), /* name */
  1100. FALSE, /* partial_inplace */
  1101. 0x1fffff, /* src_mask */
  1102. 0x1fffff, /* dst_mask */
  1103. TRUE), /* pcrel_offset */
  1104. /* LD/ST16: bit[11:1] of byte offset to module TLS base address. */
  1105. HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12), /* type */
  1106. 1, /* rightshift */
  1107. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1108. 11, /* bitsize */
  1109. FALSE, /* pc_relative */
  1110. 10, /* bitpos */
  1111. complain_overflow_unsigned, /* complain_on_overflow */
  1112. bfd_elf_generic_reloc, /* special_function */
  1113. AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12), /* name */
  1114. FALSE, /* partial_inplace */
  1115. 0x1ffc00, /* src_mask */
  1116. 0x1ffc00, /* dst_mask */
  1117. FALSE), /* pcrel_offset */
  1118. /* Same as BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, but no overflow check. */
  1119. HOWTO64 (AARCH64_R (TLSLD_LDST16_DTPREL_LO12_NC), /* type */
  1120. 1, /* rightshift */
  1121. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1122. 11, /* bitsize */
  1123. FALSE, /* pc_relative */
  1124. 10, /* bitpos */
  1125. complain_overflow_dont, /* complain_on_overflow */
  1126. bfd_elf_generic_reloc, /* special_function */
  1127. AARCH64_R_STR (TLSLD_LDST16_DTPREL_LO12_NC), /* name */
  1128. FALSE, /* partial_inplace */
  1129. 0x1ffc00, /* src_mask */
  1130. 0x1ffc00, /* dst_mask */
  1131. FALSE), /* pcrel_offset */
  1132. /* LD/ST32: bit[11:2] of byte offset to module TLS base address. */
  1133. HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12), /* type */
  1134. 2, /* rightshift */
  1135. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1136. 10, /* bitsize */
  1137. FALSE, /* pc_relative */
  1138. 10, /* bitpos */
  1139. complain_overflow_unsigned, /* complain_on_overflow */
  1140. bfd_elf_generic_reloc, /* special_function */
  1141. AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12), /* name */
  1142. FALSE, /* partial_inplace */
  1143. 0x3ffc00, /* src_mask */
  1144. 0x3ffc00, /* dst_mask */
  1145. FALSE), /* pcrel_offset */
  1146. /* Same as BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, but no overflow check. */
  1147. HOWTO64 (AARCH64_R (TLSLD_LDST32_DTPREL_LO12_NC), /* type */
  1148. 2, /* rightshift */
  1149. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1150. 10, /* bitsize */
  1151. FALSE, /* pc_relative */
  1152. 10, /* bitpos */
  1153. complain_overflow_dont, /* complain_on_overflow */
  1154. bfd_elf_generic_reloc, /* special_function */
  1155. AARCH64_R_STR (TLSLD_LDST32_DTPREL_LO12_NC), /* name */
  1156. FALSE, /* partial_inplace */
  1157. 0xffc00, /* src_mask */
  1158. 0xffc00, /* dst_mask */
  1159. FALSE), /* pcrel_offset */
  1160. /* LD/ST64: bit[11:3] of byte offset to module TLS base address. */
  1161. HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12), /* type */
  1162. 3, /* rightshift */
  1163. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1164. 9, /* bitsize */
  1165. FALSE, /* pc_relative */
  1166. 10, /* bitpos */
  1167. complain_overflow_unsigned, /* complain_on_overflow */
  1168. bfd_elf_generic_reloc, /* special_function */
  1169. AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12), /* name */
  1170. FALSE, /* partial_inplace */
  1171. 0x3ffc00, /* src_mask */
  1172. 0x3ffc00, /* dst_mask */
  1173. FALSE), /* pcrel_offset */
  1174. /* Same as BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, but no overflow check. */
  1175. HOWTO64 (AARCH64_R (TLSLD_LDST64_DTPREL_LO12_NC), /* type */
  1176. 3, /* rightshift */
  1177. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1178. 9, /* bitsize */
  1179. FALSE, /* pc_relative */
  1180. 10, /* bitpos */
  1181. complain_overflow_dont, /* complain_on_overflow */
  1182. bfd_elf_generic_reloc, /* special_function */
  1183. AARCH64_R_STR (TLSLD_LDST64_DTPREL_LO12_NC), /* name */
  1184. FALSE, /* partial_inplace */
  1185. 0x7fc00, /* src_mask */
  1186. 0x7fc00, /* dst_mask */
  1187. FALSE), /* pcrel_offset */
  1188. /* LD/ST8: bit[11:0] of byte offset to module TLS base address. */
  1189. HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12), /* type */
  1190. 0, /* rightshift */
  1191. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1192. 12, /* bitsize */
  1193. FALSE, /* pc_relative */
  1194. 10, /* bitpos */
  1195. complain_overflow_unsigned, /* complain_on_overflow */
  1196. bfd_elf_generic_reloc, /* special_function */
  1197. AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12), /* name */
  1198. FALSE, /* partial_inplace */
  1199. 0x3ffc00, /* src_mask */
  1200. 0x3ffc00, /* dst_mask */
  1201. FALSE), /* pcrel_offset */
  1202. /* Same as BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, but no overflow check. */
  1203. HOWTO64 (AARCH64_R (TLSLD_LDST8_DTPREL_LO12_NC), /* type */
  1204. 0, /* rightshift */
  1205. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1206. 12, /* bitsize */
  1207. FALSE, /* pc_relative */
  1208. 10, /* bitpos */
  1209. complain_overflow_dont, /* complain_on_overflow */
  1210. bfd_elf_generic_reloc, /* special_function */
  1211. AARCH64_R_STR (TLSLD_LDST8_DTPREL_LO12_NC), /* name */
  1212. FALSE, /* partial_inplace */
  1213. 0x3ffc00, /* src_mask */
  1214. 0x3ffc00, /* dst_mask */
  1215. FALSE), /* pcrel_offset */
  1216. /* MOVZ: bit[15:0] of byte offset to module TLS base address. */
  1217. HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0), /* type */
  1218. 0, /* rightshift */
  1219. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1220. 16, /* bitsize */
  1221. FALSE, /* pc_relative */
  1222. 0, /* bitpos */
  1223. complain_overflow_unsigned, /* complain_on_overflow */
  1224. bfd_elf_generic_reloc, /* special_function */
  1225. AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0), /* name */
  1226. FALSE, /* partial_inplace */
  1227. 0xffff, /* src_mask */
  1228. 0xffff, /* dst_mask */
  1229. FALSE), /* pcrel_offset */
  1230. /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
  1231. HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G0_NC), /* type */
  1232. 0, /* rightshift */
  1233. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1234. 16, /* bitsize */
  1235. FALSE, /* pc_relative */
  1236. 0, /* bitpos */
  1237. complain_overflow_dont, /* complain_on_overflow */
  1238. bfd_elf_generic_reloc, /* special_function */
  1239. AARCH64_R_STR (TLSLD_MOVW_DTPREL_G0_NC), /* name */
  1240. FALSE, /* partial_inplace */
  1241. 0xffff, /* src_mask */
  1242. 0xffff, /* dst_mask */
  1243. FALSE), /* pcrel_offset */
  1244. /* MOVZ: bit[31:16] of byte offset to module TLS base address. */
  1245. HOWTO (AARCH64_R (TLSLD_MOVW_DTPREL_G1), /* type */
  1246. 16, /* rightshift */
  1247. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1248. 16, /* bitsize */
  1249. FALSE, /* pc_relative */
  1250. 0, /* bitpos */
  1251. complain_overflow_unsigned, /* complain_on_overflow */
  1252. bfd_elf_generic_reloc, /* special_function */
  1253. AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1), /* name */
  1254. FALSE, /* partial_inplace */
  1255. 0xffff, /* src_mask */
  1256. 0xffff, /* dst_mask */
  1257. FALSE), /* pcrel_offset */
  1258. /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
  1259. HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G1_NC), /* type */
  1260. 16, /* rightshift */
  1261. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1262. 16, /* bitsize */
  1263. FALSE, /* pc_relative */
  1264. 0, /* bitpos */
  1265. complain_overflow_dont, /* complain_on_overflow */
  1266. bfd_elf_generic_reloc, /* special_function */
  1267. AARCH64_R_STR (TLSLD_MOVW_DTPREL_G1_NC), /* name */
  1268. FALSE, /* partial_inplace */
  1269. 0xffff, /* src_mask */
  1270. 0xffff, /* dst_mask */
  1271. FALSE), /* pcrel_offset */
  1272. /* MOVZ: bit[47:32] of byte offset to module TLS base address. */
  1273. HOWTO64 (AARCH64_R (TLSLD_MOVW_DTPREL_G2), /* type */
  1274. 32, /* rightshift */
  1275. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1276. 16, /* bitsize */
  1277. FALSE, /* pc_relative */
  1278. 0, /* bitpos */
  1279. complain_overflow_unsigned, /* complain_on_overflow */
  1280. bfd_elf_generic_reloc, /* special_function */
  1281. AARCH64_R_STR (TLSLD_MOVW_DTPREL_G2), /* name */
  1282. FALSE, /* partial_inplace */
  1283. 0xffff, /* src_mask */
  1284. 0xffff, /* dst_mask */
  1285. FALSE), /* pcrel_offset */
  1286. HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G2), /* type */
  1287. 32, /* rightshift */
  1288. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1289. 16, /* bitsize */
  1290. FALSE, /* pc_relative */
  1291. 0, /* bitpos */
  1292. complain_overflow_unsigned, /* complain_on_overflow */
  1293. bfd_elf_generic_reloc, /* special_function */
  1294. AARCH64_R_STR (TLSLE_MOVW_TPREL_G2), /* name */
  1295. FALSE, /* partial_inplace */
  1296. 0xffff, /* src_mask */
  1297. 0xffff, /* dst_mask */
  1298. FALSE), /* pcrel_offset */
  1299. HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G1), /* type */
  1300. 16, /* rightshift */
  1301. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1302. 16, /* bitsize */
  1303. FALSE, /* pc_relative */
  1304. 0, /* bitpos */
  1305. complain_overflow_dont, /* complain_on_overflow */
  1306. bfd_elf_generic_reloc, /* special_function */
  1307. AARCH64_R_STR (TLSLE_MOVW_TPREL_G1), /* name */
  1308. FALSE, /* partial_inplace */
  1309. 0xffff, /* src_mask */
  1310. 0xffff, /* dst_mask */
  1311. FALSE), /* pcrel_offset */
  1312. HOWTO64 (AARCH64_R (TLSLE_MOVW_TPREL_G1_NC), /* type */
  1313. 16, /* rightshift */
  1314. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1315. 16, /* bitsize */
  1316. FALSE, /* pc_relative */
  1317. 0, /* bitpos */
  1318. complain_overflow_dont, /* complain_on_overflow */
  1319. bfd_elf_generic_reloc, /* special_function */
  1320. AARCH64_R_STR (TLSLE_MOVW_TPREL_G1_NC), /* name */
  1321. FALSE, /* partial_inplace */
  1322. 0xffff, /* src_mask */
  1323. 0xffff, /* dst_mask */
  1324. FALSE), /* pcrel_offset */
  1325. HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0), /* type */
  1326. 0, /* rightshift */
  1327. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1328. 16, /* bitsize */
  1329. FALSE, /* pc_relative */
  1330. 0, /* bitpos */
  1331. complain_overflow_dont, /* complain_on_overflow */
  1332. bfd_elf_generic_reloc, /* special_function */
  1333. AARCH64_R_STR (TLSLE_MOVW_TPREL_G0), /* name */
  1334. FALSE, /* partial_inplace */
  1335. 0xffff, /* src_mask */
  1336. 0xffff, /* dst_mask */
  1337. FALSE), /* pcrel_offset */
  1338. HOWTO (AARCH64_R (TLSLE_MOVW_TPREL_G0_NC), /* type */
  1339. 0, /* rightshift */
  1340. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1341. 16, /* bitsize */
  1342. FALSE, /* pc_relative */
  1343. 0, /* bitpos */
  1344. complain_overflow_dont, /* complain_on_overflow */
  1345. bfd_elf_generic_reloc, /* special_function */
  1346. AARCH64_R_STR (TLSLE_MOVW_TPREL_G0_NC), /* name */
  1347. FALSE, /* partial_inplace */
  1348. 0xffff, /* src_mask */
  1349. 0xffff, /* dst_mask */
  1350. FALSE), /* pcrel_offset */
  1351. HOWTO (AARCH64_R (TLSLE_ADD_TPREL_HI12), /* type */
  1352. 12, /* rightshift */
  1353. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1354. 12, /* bitsize */
  1355. FALSE, /* pc_relative */
  1356. 0, /* bitpos */
  1357. complain_overflow_unsigned, /* complain_on_overflow */
  1358. bfd_elf_generic_reloc, /* special_function */
  1359. AARCH64_R_STR (TLSLE_ADD_TPREL_HI12), /* name */
  1360. FALSE, /* partial_inplace */
  1361. 0xfff, /* src_mask */
  1362. 0xfff, /* dst_mask */
  1363. FALSE), /* pcrel_offset */
  1364. HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12), /* type */
  1365. 0, /* rightshift */
  1366. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1367. 12, /* bitsize */
  1368. FALSE, /* pc_relative */
  1369. 0, /* bitpos */
  1370. complain_overflow_unsigned, /* complain_on_overflow */
  1371. bfd_elf_generic_reloc, /* special_function */
  1372. AARCH64_R_STR (TLSLE_ADD_TPREL_LO12), /* name */
  1373. FALSE, /* partial_inplace */
  1374. 0xfff, /* src_mask */
  1375. 0xfff, /* dst_mask */
  1376. FALSE), /* pcrel_offset */
  1377. HOWTO (AARCH64_R (TLSLE_ADD_TPREL_LO12_NC), /* type */
  1378. 0, /* rightshift */
  1379. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1380. 12, /* bitsize */
  1381. FALSE, /* pc_relative */
  1382. 0, /* bitpos */
  1383. complain_overflow_dont, /* complain_on_overflow */
  1384. bfd_elf_generic_reloc, /* special_function */
  1385. AARCH64_R_STR (TLSLE_ADD_TPREL_LO12_NC), /* name */
  1386. FALSE, /* partial_inplace */
  1387. 0xfff, /* src_mask */
  1388. 0xfff, /* dst_mask */
  1389. FALSE), /* pcrel_offset */
  1390. HOWTO (AARCH64_R (TLSDESC_LD_PREL19), /* type */
  1391. 2, /* rightshift */
  1392. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1393. 19, /* bitsize */
  1394. TRUE, /* pc_relative */
  1395. 0, /* bitpos */
  1396. complain_overflow_dont, /* complain_on_overflow */
  1397. bfd_elf_generic_reloc, /* special_function */
  1398. AARCH64_R_STR (TLSDESC_LD_PREL19), /* name */
  1399. FALSE, /* partial_inplace */
  1400. 0x0ffffe0, /* src_mask */
  1401. 0x0ffffe0, /* dst_mask */
  1402. TRUE), /* pcrel_offset */
  1403. HOWTO (AARCH64_R (TLSDESC_ADR_PREL21), /* type */
  1404. 0, /* rightshift */
  1405. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1406. 21, /* bitsize */
  1407. TRUE, /* pc_relative */
  1408. 0, /* bitpos */
  1409. complain_overflow_dont, /* complain_on_overflow */
  1410. bfd_elf_generic_reloc, /* special_function */
  1411. AARCH64_R_STR (TLSDESC_ADR_PREL21), /* name */
  1412. FALSE, /* partial_inplace */
  1413. 0x1fffff, /* src_mask */
  1414. 0x1fffff, /* dst_mask */
  1415. TRUE), /* pcrel_offset */
  1416. /* Get to the page for the GOT entry for the symbol
  1417. (G(S) - P) using an ADRP instruction. */
  1418. HOWTO (AARCH64_R (TLSDESC_ADR_PAGE21), /* type */
  1419. 12, /* rightshift */
  1420. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1421. 21, /* bitsize */
  1422. TRUE, /* pc_relative */
  1423. 0, /* bitpos */
  1424. complain_overflow_dont, /* complain_on_overflow */
  1425. bfd_elf_generic_reloc, /* special_function */
  1426. AARCH64_R_STR (TLSDESC_ADR_PAGE21), /* name */
  1427. FALSE, /* partial_inplace */
  1428. 0x1fffff, /* src_mask */
  1429. 0x1fffff, /* dst_mask */
  1430. TRUE), /* pcrel_offset */
  1431. /* LD64: GOT offset G(S) & 0xff8. */
  1432. HOWTO64 (AARCH64_R (TLSDESC_LD64_LO12_NC), /* type */
  1433. 3, /* rightshift */
  1434. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1435. 12, /* bitsize */
  1436. FALSE, /* pc_relative */
  1437. 0, /* bitpos */
  1438. complain_overflow_dont, /* complain_on_overflow */
  1439. bfd_elf_generic_reloc, /* special_function */
  1440. AARCH64_R_STR (TLSDESC_LD64_LO12_NC), /* name */
  1441. FALSE, /* partial_inplace */
  1442. 0xff8, /* src_mask */
  1443. 0xff8, /* dst_mask */
  1444. FALSE), /* pcrel_offset */
  1445. /* LD32: GOT offset G(S) & 0xffc. */
  1446. HOWTO32 (AARCH64_R (TLSDESC_LD32_LO12_NC), /* type */
  1447. 2, /* rightshift */
  1448. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1449. 12, /* bitsize */
  1450. FALSE, /* pc_relative */
  1451. 0, /* bitpos */
  1452. complain_overflow_dont, /* complain_on_overflow */
  1453. bfd_elf_generic_reloc, /* special_function */
  1454. AARCH64_R_STR (TLSDESC_LD32_LO12_NC), /* name */
  1455. FALSE, /* partial_inplace */
  1456. 0xffc, /* src_mask */
  1457. 0xffc, /* dst_mask */
  1458. FALSE), /* pcrel_offset */
  1459. /* ADD: GOT offset G(S) & 0xfff. */
  1460. HOWTO (AARCH64_R (TLSDESC_ADD_LO12_NC), /* type */
  1461. 0, /* rightshift */
  1462. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1463. 12, /* bitsize */
  1464. FALSE, /* pc_relative */
  1465. 0, /* bitpos */
  1466. complain_overflow_dont, /* complain_on_overflow */
  1467. bfd_elf_generic_reloc, /* special_function */
  1468. AARCH64_R_STR (TLSDESC_ADD_LO12_NC), /* name */
  1469. FALSE, /* partial_inplace */
  1470. 0xfff, /* src_mask */
  1471. 0xfff, /* dst_mask */
  1472. FALSE), /* pcrel_offset */
  1473. HOWTO64 (AARCH64_R (TLSDESC_OFF_G1), /* type */
  1474. 16, /* rightshift */
  1475. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1476. 12, /* bitsize */
  1477. FALSE, /* pc_relative */
  1478. 0, /* bitpos */
  1479. complain_overflow_unsigned, /* complain_on_overflow */
  1480. bfd_elf_generic_reloc, /* special_function */
  1481. AARCH64_R_STR (TLSDESC_OFF_G1), /* name */
  1482. FALSE, /* partial_inplace */
  1483. 0xffff, /* src_mask */
  1484. 0xffff, /* dst_mask */
  1485. FALSE), /* pcrel_offset */
  1486. HOWTO64 (AARCH64_R (TLSDESC_OFF_G0_NC), /* type */
  1487. 0, /* rightshift */
  1488. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1489. 12, /* bitsize */
  1490. FALSE, /* pc_relative */
  1491. 0, /* bitpos */
  1492. complain_overflow_dont, /* complain_on_overflow */
  1493. bfd_elf_generic_reloc, /* special_function */
  1494. AARCH64_R_STR (TLSDESC_OFF_G0_NC), /* name */
  1495. FALSE, /* partial_inplace */
  1496. 0xffff, /* src_mask */
  1497. 0xffff, /* dst_mask */
  1498. FALSE), /* pcrel_offset */
  1499. HOWTO64 (AARCH64_R (TLSDESC_LDR), /* type */
  1500. 0, /* rightshift */
  1501. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1502. 12, /* bitsize */
  1503. FALSE, /* pc_relative */
  1504. 0, /* bitpos */
  1505. complain_overflow_dont, /* complain_on_overflow */
  1506. bfd_elf_generic_reloc, /* special_function */
  1507. AARCH64_R_STR (TLSDESC_LDR), /* name */
  1508. FALSE, /* partial_inplace */
  1509. 0x0, /* src_mask */
  1510. 0x0, /* dst_mask */
  1511. FALSE), /* pcrel_offset */
  1512. HOWTO64 (AARCH64_R (TLSDESC_ADD), /* type */
  1513. 0, /* rightshift */
  1514. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1515. 12, /* bitsize */
  1516. FALSE, /* pc_relative */
  1517. 0, /* bitpos */
  1518. complain_overflow_dont, /* complain_on_overflow */
  1519. bfd_elf_generic_reloc, /* special_function */
  1520. AARCH64_R_STR (TLSDESC_ADD), /* name */
  1521. FALSE, /* partial_inplace */
  1522. 0x0, /* src_mask */
  1523. 0x0, /* dst_mask */
  1524. FALSE), /* pcrel_offset */
  1525. HOWTO (AARCH64_R (TLSDESC_CALL), /* type */
  1526. 0, /* rightshift */
  1527. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1528. 0, /* bitsize */
  1529. FALSE, /* pc_relative */
  1530. 0, /* bitpos */
  1531. complain_overflow_dont, /* complain_on_overflow */
  1532. bfd_elf_generic_reloc, /* special_function */
  1533. AARCH64_R_STR (TLSDESC_CALL), /* name */
  1534. FALSE, /* partial_inplace */
  1535. 0x0, /* src_mask */
  1536. 0x0, /* dst_mask */
  1537. FALSE), /* pcrel_offset */
  1538. HOWTO (AARCH64_R (COPY), /* type */
  1539. 0, /* rightshift */
  1540. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1541. 64, /* bitsize */
  1542. FALSE, /* pc_relative */
  1543. 0, /* bitpos */
  1544. complain_overflow_bitfield, /* complain_on_overflow */
  1545. bfd_elf_generic_reloc, /* special_function */
  1546. AARCH64_R_STR (COPY), /* name */
  1547. TRUE, /* partial_inplace */
  1548. 0xffffffff, /* src_mask */
  1549. 0xffffffff, /* dst_mask */
  1550. FALSE), /* pcrel_offset */
  1551. HOWTO (AARCH64_R (GLOB_DAT), /* type */
  1552. 0, /* rightshift */
  1553. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1554. 64, /* bitsize */
  1555. FALSE, /* pc_relative */
  1556. 0, /* bitpos */
  1557. complain_overflow_bitfield, /* complain_on_overflow */
  1558. bfd_elf_generic_reloc, /* special_function */
  1559. AARCH64_R_STR (GLOB_DAT), /* name */
  1560. TRUE, /* partial_inplace */
  1561. 0xffffffff, /* src_mask */
  1562. 0xffffffff, /* dst_mask */
  1563. FALSE), /* pcrel_offset */
  1564. HOWTO (AARCH64_R (JUMP_SLOT), /* type */
  1565. 0, /* rightshift */
  1566. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1567. 64, /* bitsize */
  1568. FALSE, /* pc_relative */
  1569. 0, /* bitpos */
  1570. complain_overflow_bitfield, /* complain_on_overflow */
  1571. bfd_elf_generic_reloc, /* special_function */
  1572. AARCH64_R_STR (JUMP_SLOT), /* name */
  1573. TRUE, /* partial_inplace */
  1574. 0xffffffff, /* src_mask */
  1575. 0xffffffff, /* dst_mask */
  1576. FALSE), /* pcrel_offset */
  1577. HOWTO (AARCH64_R (RELATIVE), /* type */
  1578. 0, /* rightshift */
  1579. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1580. 64, /* bitsize */
  1581. FALSE, /* pc_relative */
  1582. 0, /* bitpos */
  1583. complain_overflow_bitfield, /* complain_on_overflow */
  1584. bfd_elf_generic_reloc, /* special_function */
  1585. AARCH64_R_STR (RELATIVE), /* name */
  1586. TRUE, /* partial_inplace */
  1587. ALL_ONES, /* src_mask */
  1588. ALL_ONES, /* dst_mask */
  1589. FALSE), /* pcrel_offset */
  1590. HOWTO (AARCH64_R (TLS_DTPMOD), /* type */
  1591. 0, /* rightshift */
  1592. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1593. 64, /* bitsize */
  1594. FALSE, /* pc_relative */
  1595. 0, /* bitpos */
  1596. complain_overflow_dont, /* complain_on_overflow */
  1597. bfd_elf_generic_reloc, /* special_function */
  1598. #if ARCH_SIZE == 64
  1599. AARCH64_R_STR (TLS_DTPMOD64), /* name */
  1600. #else
  1601. AARCH64_R_STR (TLS_DTPMOD), /* name */
  1602. #endif
  1603. FALSE, /* partial_inplace */
  1604. 0, /* src_mask */
  1605. ALL_ONES, /* dst_mask */
  1606. FALSE), /* pc_reloffset */
  1607. HOWTO (AARCH64_R (TLS_DTPREL), /* type */
  1608. 0, /* rightshift */
  1609. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1610. 64, /* bitsize */
  1611. FALSE, /* pc_relative */
  1612. 0, /* bitpos */
  1613. complain_overflow_dont, /* complain_on_overflow */
  1614. bfd_elf_generic_reloc, /* special_function */
  1615. #if ARCH_SIZE == 64
  1616. AARCH64_R_STR (TLS_DTPREL64), /* name */
  1617. #else
  1618. AARCH64_R_STR (TLS_DTPREL), /* name */
  1619. #endif
  1620. FALSE, /* partial_inplace */
  1621. 0, /* src_mask */
  1622. ALL_ONES, /* dst_mask */
  1623. FALSE), /* pcrel_offset */
  1624. HOWTO (AARCH64_R (TLS_TPREL), /* type */
  1625. 0, /* rightshift */
  1626. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1627. 64, /* bitsize */
  1628. FALSE, /* pc_relative */
  1629. 0, /* bitpos */
  1630. complain_overflow_dont, /* complain_on_overflow */
  1631. bfd_elf_generic_reloc, /* special_function */
  1632. #if ARCH_SIZE == 64
  1633. AARCH64_R_STR (TLS_TPREL64), /* name */
  1634. #else
  1635. AARCH64_R_STR (TLS_TPREL), /* name */
  1636. #endif
  1637. FALSE, /* partial_inplace */
  1638. 0, /* src_mask */
  1639. ALL_ONES, /* dst_mask */
  1640. FALSE), /* pcrel_offset */
  1641. HOWTO (AARCH64_R (TLSDESC), /* type */
  1642. 0, /* rightshift */
  1643. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1644. 64, /* bitsize */
  1645. FALSE, /* pc_relative */
  1646. 0, /* bitpos */
  1647. complain_overflow_dont, /* complain_on_overflow */
  1648. bfd_elf_generic_reloc, /* special_function */
  1649. AARCH64_R_STR (TLSDESC), /* name */
  1650. FALSE, /* partial_inplace */
  1651. 0, /* src_mask */
  1652. ALL_ONES, /* dst_mask */
  1653. FALSE), /* pcrel_offset */
  1654. HOWTO (AARCH64_R (IRELATIVE), /* type */
  1655. 0, /* rightshift */
  1656. 2, /* size (0 = byte, 1 = short, 2 = long) */
  1657. 64, /* bitsize */
  1658. FALSE, /* pc_relative */
  1659. 0, /* bitpos */
  1660. complain_overflow_bitfield, /* complain_on_overflow */
  1661. bfd_elf_generic_reloc, /* special_function */
  1662. AARCH64_R_STR (IRELATIVE), /* name */
  1663. FALSE, /* partial_inplace */
  1664. 0, /* src_mask */
  1665. ALL_ONES, /* dst_mask */
  1666. FALSE), /* pcrel_offset */
  1667. EMPTY_HOWTO (0),
  1668. };
  1669. static reloc_howto_type elfNN_aarch64_howto_none =
  1670. HOWTO (R_AARCH64_NONE, /* type */
  1671. 0, /* rightshift */
  1672. 3, /* size (0 = byte, 1 = short, 2 = long) */
  1673. 0, /* bitsize */
  1674. FALSE, /* pc_relative */
  1675. 0, /* bitpos */
  1676. complain_overflow_dont,/* complain_on_overflow */
  1677. bfd_elf_generic_reloc, /* special_function */
  1678. "R_AARCH64_NONE", /* name */
  1679. FALSE, /* partial_inplace */
  1680. 0, /* src_mask */
  1681. 0, /* dst_mask */
  1682. FALSE); /* pcrel_offset */
  1683. /* Given HOWTO, return the bfd internal relocation enumerator. */
  1684. static bfd_reloc_code_real_type
  1685. elfNN_aarch64_bfd_reloc_from_howto (reloc_howto_type *howto)
  1686. {
  1687. const int size
  1688. = (int) ARRAY_SIZE (elfNN_aarch64_howto_table);
  1689. const ptrdiff_t offset
  1690. = howto - elfNN_aarch64_howto_table;
  1691. if (offset > 0 && offset < size - 1)
  1692. return BFD_RELOC_AARCH64_RELOC_START + offset;
  1693. if (howto == &elfNN_aarch64_howto_none)
  1694. return BFD_RELOC_AARCH64_NONE;
  1695. return BFD_RELOC_AARCH64_RELOC_START;
  1696. }
  1697. /* Given R_TYPE, return the bfd internal relocation enumerator. */
  1698. static bfd_reloc_code_real_type
  1699. elfNN_aarch64_bfd_reloc_from_type (unsigned int r_type)
  1700. {
  1701. static bfd_boolean initialized_p = FALSE;
  1702. /* Indexed by R_TYPE, values are offsets in the howto_table. */
  1703. static unsigned int offsets[R_AARCH64_end];
  1704. if (initialized_p == FALSE)
  1705. {
  1706. unsigned int i;
  1707. for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
  1708. if (elfNN_aarch64_howto_table[i].type != 0)
  1709. offsets[elfNN_aarch64_howto_table[i].type] = i;
  1710. initialized_p = TRUE;
  1711. }
  1712. if (r_type == R_AARCH64_NONE || r_type == R_AARCH64_NULL)
  1713. return BFD_RELOC_AARCH64_NONE;
  1714. /* PR 17512: file: b371e70a. */
  1715. if (r_type >= R_AARCH64_end)
  1716. {
  1717. _bfd_error_handler (_("Invalid AArch64 reloc number: %d"), r_type);
  1718. bfd_set_error (bfd_error_bad_value);
  1719. return BFD_RELOC_AARCH64_NONE;
  1720. }
  1721. return BFD_RELOC_AARCH64_RELOC_START + offsets[r_type];
  1722. }
  1723. struct elf_aarch64_reloc_map
  1724. {
  1725. bfd_reloc_code_real_type from;
  1726. bfd_reloc_code_real_type to;
  1727. };
  1728. /* Map bfd generic reloc to AArch64-specific reloc. */
  1729. static const struct elf_aarch64_reloc_map elf_aarch64_reloc_map[] =
  1730. {
  1731. {BFD_RELOC_NONE, BFD_RELOC_AARCH64_NONE},
  1732. /* Basic data relocations. */
  1733. {BFD_RELOC_CTOR, BFD_RELOC_AARCH64_NN},
  1734. {BFD_RELOC_64, BFD_RELOC_AARCH64_64},
  1735. {BFD_RELOC_32, BFD_RELOC_AARCH64_32},
  1736. {BFD_RELOC_16, BFD_RELOC_AARCH64_16},
  1737. {BFD_RELOC_64_PCREL, BFD_RELOC_AARCH64_64_PCREL},
  1738. {BFD_RELOC_32_PCREL, BFD_RELOC_AARCH64_32_PCREL},
  1739. {BFD_RELOC_16_PCREL, BFD_RELOC_AARCH64_16_PCREL},
  1740. };
  1741. /* Given the bfd internal relocation enumerator in CODE, return the
  1742. corresponding howto entry. */
  1743. static reloc_howto_type *
  1744. elfNN_aarch64_howto_from_bfd_reloc (bfd_reloc_code_real_type code)
  1745. {
  1746. unsigned int i;
  1747. /* Convert bfd generic reloc to AArch64-specific reloc. */
  1748. if (code < BFD_RELOC_AARCH64_RELOC_START
  1749. || code > BFD_RELOC_AARCH64_RELOC_END)
  1750. for (i = 0; i < ARRAY_SIZE (elf_aarch64_reloc_map); i++)
  1751. if (elf_aarch64_reloc_map[i].from == code)
  1752. {
  1753. code = elf_aarch64_reloc_map[i].to;
  1754. break;
  1755. }
  1756. if (code > BFD_RELOC_AARCH64_RELOC_START
  1757. && code < BFD_RELOC_AARCH64_RELOC_END)
  1758. if (elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START].type)
  1759. return &elfNN_aarch64_howto_table[code - BFD_RELOC_AARCH64_RELOC_START];
  1760. if (code == BFD_RELOC_AARCH64_NONE)
  1761. return &elfNN_aarch64_howto_none;
  1762. return NULL;
  1763. }
  1764. static reloc_howto_type *
  1765. elfNN_aarch64_howto_from_type (unsigned int r_type)
  1766. {
  1767. bfd_reloc_code_real_type val;
  1768. reloc_howto_type *howto;
  1769. #if ARCH_SIZE == 32
  1770. if (r_type > 256)
  1771. {
  1772. bfd_set_error (bfd_error_bad_value);
  1773. return NULL;
  1774. }
  1775. #endif
  1776. if (r_type == R_AARCH64_NONE)
  1777. return &elfNN_aarch64_howto_none;
  1778. val = elfNN_aarch64_bfd_reloc_from_type (r_type);
  1779. howto = elfNN_aarch64_howto_from_bfd_reloc (val);
  1780. if (howto != NULL)
  1781. return howto;
  1782. bfd_set_error (bfd_error_bad_value);
  1783. return NULL;
  1784. }
  1785. static void
  1786. elfNN_aarch64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *bfd_reloc,
  1787. Elf_Internal_Rela *elf_reloc)
  1788. {
  1789. unsigned int r_type;
  1790. r_type = ELFNN_R_TYPE (elf_reloc->r_info);
  1791. bfd_reloc->howto = elfNN_aarch64_howto_from_type (r_type);
  1792. }
  1793. static reloc_howto_type *
  1794. elfNN_aarch64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1795. bfd_reloc_code_real_type code)
  1796. {
  1797. reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (code);
  1798. if (howto != NULL)
  1799. return howto;
  1800. bfd_set_error (bfd_error_bad_value);
  1801. return NULL;
  1802. }
  1803. static reloc_howto_type *
  1804. elfNN_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1805. const char *r_name)
  1806. {
  1807. unsigned int i;
  1808. for (i = 1; i < ARRAY_SIZE (elfNN_aarch64_howto_table) - 1; ++i)
  1809. if (elfNN_aarch64_howto_table[i].name != NULL
  1810. && strcasecmp (elfNN_aarch64_howto_table[i].name, r_name) == 0)
  1811. return &elfNN_aarch64_howto_table[i];
  1812. return NULL;
  1813. }
  1814. #define TARGET_LITTLE_SYM aarch64_elfNN_le_vec
  1815. #define TARGET_LITTLE_NAME "elfNN-littleaarch64"
  1816. #define TARGET_BIG_SYM aarch64_elfNN_be_vec
  1817. #define TARGET_BIG_NAME "elfNN-bigaarch64"
  1818. /* The linker script knows the section names for placement.
  1819. The entry_names are used to do simple name mangling on the stubs.
  1820. Given a function name, and its type, the stub can be found. The
  1821. name can be changed. The only requirement is the %s be present. */
  1822. #define STUB_ENTRY_NAME "__%s_veneer"
  1823. /* The name of the dynamic interpreter. This is put in the .interp
  1824. section. */
  1825. #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
  1826. #define AARCH64_MAX_FWD_BRANCH_OFFSET \
  1827. (((1 << 25) - 1) << 2)
  1828. #define AARCH64_MAX_BWD_BRANCH_OFFSET \
  1829. (-((1 << 25) << 2))
  1830. #define AARCH64_MAX_ADRP_IMM ((1 << 20) - 1)
  1831. #define AARCH64_MIN_ADRP_IMM (-(1 << 20))
  1832. static int
  1833. aarch64_valid_for_adrp_p (bfd_vma value, bfd_vma place)
  1834. {
  1835. bfd_signed_vma offset = (bfd_signed_vma) (PG (value) - PG (place)) >> 12;
  1836. return offset <= AARCH64_MAX_ADRP_IMM && offset >= AARCH64_MIN_ADRP_IMM;
  1837. }
  1838. static int
  1839. aarch64_valid_branch_p (bfd_vma value, bfd_vma place)
  1840. {
  1841. bfd_signed_vma offset = (bfd_signed_vma) (value - place);
  1842. return (offset <= AARCH64_MAX_FWD_BRANCH_OFFSET
  1843. && offset >= AARCH64_MAX_BWD_BRANCH_OFFSET);
  1844. }
  1845. static const uint32_t aarch64_adrp_branch_stub [] =
  1846. {
  1847. 0x90000010, /* adrp ip0, X */
  1848. /* R_AARCH64_ADR_HI21_PCREL(X) */
  1849. 0x91000210, /* add ip0, ip0, :lo12:X */
  1850. /* R_AARCH64_ADD_ABS_LO12_NC(X) */
  1851. 0xd61f0200, /* br ip0 */
  1852. };
  1853. static const uint32_t aarch64_long_branch_stub[] =
  1854. {
  1855. #if ARCH_SIZE == 64
  1856. 0x58000090, /* ldr ip0, 1f */
  1857. #else
  1858. 0x18000090, /* ldr wip0, 1f */
  1859. #endif
  1860. 0x10000011, /* adr ip1, #0 */
  1861. 0x8b110210, /* add ip0, ip0, ip1 */
  1862. 0xd61f0200, /* br ip0 */
  1863. 0x00000000, /* 1: .xword or .word
  1864. R_AARCH64_PRELNN(X) + 12
  1865. */
  1866. 0x00000000,
  1867. };
  1868. static const uint32_t aarch64_erratum_835769_stub[] =
  1869. {
  1870. 0x00000000, /* Placeholder for multiply accumulate. */
  1871. 0x14000000, /* b <label> */
  1872. };
  1873. static const uint32_t aarch64_erratum_843419_stub[] =
  1874. {
  1875. 0x00000000, /* Placeholder for LDR instruction. */
  1876. 0x14000000, /* b <label> */
  1877. };
  1878. /* Section name for stubs is the associated section name plus this
  1879. string. */
  1880. #define STUB_SUFFIX ".stub"
  1881. enum elf_aarch64_stub_type
  1882. {
  1883. aarch64_stub_none,
  1884. aarch64_stub_adrp_branch,
  1885. aarch64_stub_long_branch,
  1886. aarch64_stub_erratum_835769_veneer,
  1887. aarch64_stub_erratum_843419_veneer,
  1888. };
  1889. struct elf_aarch64_stub_hash_entry
  1890. {
  1891. /* Base hash table entry structure. */
  1892. struct bfd_hash_entry root;
  1893. /* The stub section. */
  1894. asection *stub_sec;
  1895. /* Offset within stub_sec of the beginning of this stub. */
  1896. bfd_vma stub_offset;
  1897. /* Given the symbol's value and its section we can determine its final
  1898. value when building the stubs (so the stub knows where to jump). */
  1899. bfd_vma target_value;
  1900. asection *target_section;
  1901. enum elf_aarch64_stub_type stub_type;
  1902. /* The symbol table entry, if any, that this was derived from. */
  1903. struct elf_aarch64_link_hash_entry *h;
  1904. /* Destination symbol type */
  1905. unsigned char st_type;
  1906. /* Where this stub is being called from, or, in the case of combined
  1907. stub sections, the first input section in the group. */
  1908. asection *id_sec;
  1909. /* The name for the local symbol at the start of this stub. The
  1910. stub name in the hash table has to be unique; this does not, so
  1911. it can be friendlier. */
  1912. char *output_name;
  1913. /* The instruction which caused this stub to be generated (only valid for
  1914. erratum 835769 workaround stubs at present). */
  1915. uint32_t veneered_insn;
  1916. /* In an erratum 843419 workaround stub, the ADRP instruction offset. */
  1917. bfd_vma adrp_offset;
  1918. };
  1919. /* Used to build a map of a section. This is required for mixed-endian
  1920. code/data. */
  1921. typedef struct elf_elf_section_map
  1922. {
  1923. bfd_vma vma;
  1924. char type;
  1925. }
  1926. elf_aarch64_section_map;
  1927. typedef struct _aarch64_elf_section_data
  1928. {
  1929. struct bfd_elf_section_data elf;
  1930. unsigned int mapcount;
  1931. unsigned int mapsize;
  1932. elf_aarch64_section_map *map;
  1933. }
  1934. _aarch64_elf_section_data;
  1935. #define elf_aarch64_section_data(sec) \
  1936. ((_aarch64_elf_section_data *) elf_section_data (sec))
  1937. /* The size of the thread control block which is defined to be two pointers. */
  1938. #define TCB_SIZE (ARCH_SIZE/8)*2
  1939. struct elf_aarch64_local_symbol
  1940. {
  1941. unsigned int got_type;
  1942. bfd_signed_vma got_refcount;
  1943. bfd_vma got_offset;
  1944. /* Offset of the GOTPLT entry reserved for the TLS descriptor. The
  1945. offset is from the end of the jump table and reserved entries
  1946. within the PLTGOT.
  1947. The magic value (bfd_vma) -1 indicates that an offset has not be
  1948. allocated. */
  1949. bfd_vma tlsdesc_got_jump_table_offset;
  1950. };
  1951. struct elf_aarch64_obj_tdata
  1952. {
  1953. struct elf_obj_tdata root;
  1954. /* local symbol descriptors */
  1955. struct elf_aarch64_local_symbol *locals;
  1956. /* Zero to warn when linking objects with incompatible enum sizes. */
  1957. int no_enum_size_warning;
  1958. /* Zero to warn when linking objects with incompatible wchar_t sizes. */
  1959. int no_wchar_size_warning;
  1960. };
  1961. #define elf_aarch64_tdata(bfd) \
  1962. ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
  1963. #define elf_aarch64_locals(bfd) (elf_aarch64_tdata (bfd)->locals)
  1964. #define is_aarch64_elf(bfd) \
  1965. (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
  1966. && elf_tdata (bfd) != NULL \
  1967. && elf_object_id (bfd) == AARCH64_ELF_DATA)
  1968. static bfd_boolean
  1969. elfNN_aarch64_mkobject (bfd *abfd)
  1970. {
  1971. return bfd_elf_allocate_object (abfd, sizeof (struct elf_aarch64_obj_tdata),
  1972. AARCH64_ELF_DATA);
  1973. }
  1974. #define elf_aarch64_hash_entry(ent) \
  1975. ((struct elf_aarch64_link_hash_entry *)(ent))
  1976. #define GOT_UNKNOWN 0
  1977. #define GOT_NORMAL 1
  1978. #define GOT_TLS_GD 2
  1979. #define GOT_TLS_IE 4
  1980. #define GOT_TLSDESC_GD 8
  1981. #define GOT_TLS_GD_ANY_P(type) ((type & GOT_TLS_GD) || (type & GOT_TLSDESC_GD))
  1982. /* AArch64 ELF linker hash entry. */
  1983. struct elf_aarch64_link_hash_entry
  1984. {
  1985. struct elf_link_hash_entry root;
  1986. /* Track dynamic relocs copied for this symbol. */
  1987. struct elf_dyn_relocs *dyn_relocs;
  1988. /* Since PLT entries have variable size, we need to record the
  1989. index into .got.plt instead of recomputing it from the PLT
  1990. offset. */
  1991. bfd_signed_vma plt_got_offset;
  1992. /* Bit mask representing the type of GOT entry(s) if any required by
  1993. this symbol. */
  1994. unsigned int got_type;
  1995. /* A pointer to the most recently used stub hash entry against this
  1996. symbol. */
  1997. struct elf_aarch64_stub_hash_entry *stub_cache;
  1998. /* Offset of the GOTPLT entry reserved for the TLS descriptor. The offset
  1999. is from the end of the jump table and reserved entries within the PLTGOT.
  2000. The magic value (bfd_vma) -1 indicates that an offset has not
  2001. be allocated. */
  2002. bfd_vma tlsdesc_got_jump_table_offset;
  2003. };
  2004. static unsigned int
  2005. elfNN_aarch64_symbol_got_type (struct elf_link_hash_entry *h,
  2006. bfd *abfd,
  2007. unsigned long r_symndx)
  2008. {
  2009. if (h)
  2010. return elf_aarch64_hash_entry (h)->got_type;
  2011. if (! elf_aarch64_locals (abfd))
  2012. return GOT_UNKNOWN;
  2013. return elf_aarch64_locals (abfd)[r_symndx].got_type;
  2014. }
  2015. /* Get the AArch64 elf linker hash table from a link_info structure. */
  2016. #define elf_aarch64_hash_table(info) \
  2017. ((struct elf_aarch64_link_hash_table *) ((info)->hash))
  2018. #define aarch64_stub_hash_lookup(table, string, create, copy) \
  2019. ((struct elf_aarch64_stub_hash_entry *) \
  2020. bfd_hash_lookup ((table), (string), (create), (copy)))
  2021. /* AArch64 ELF linker hash table. */
  2022. struct elf_aarch64_link_hash_table
  2023. {
  2024. /* The main hash table. */
  2025. struct elf_link_hash_table root;
  2026. /* Nonzero to force PIC branch veneers. */
  2027. int pic_veneer;
  2028. /* Fix erratum 835769. */
  2029. int fix_erratum_835769;
  2030. /* Fix erratum 843419. */
  2031. int fix_erratum_843419;
  2032. /* Enable ADRP->ADR rewrite for erratum 843419 workaround. */
  2033. int fix_erratum_843419_adr;
  2034. /* The number of bytes in the initial entry in the PLT. */
  2035. bfd_size_type plt_header_size;
  2036. /* The number of bytes in the subsequent PLT etries. */
  2037. bfd_size_type plt_entry_size;
  2038. /* Short-cuts to get to dynamic linker sections. */
  2039. asection *sdynbss;
  2040. asection *srelbss;
  2041. /* Small local sym cache. */
  2042. struct sym_cache sym_cache;
  2043. /* For convenience in allocate_dynrelocs. */
  2044. bfd *obfd;
  2045. /* The amount of space used by the reserved portion of the sgotplt
  2046. section, plus whatever space is used by the jump slots. */
  2047. bfd_vma sgotplt_jump_table_size;
  2048. /* The stub hash table. */
  2049. struct bfd_hash_table stub_hash_table;
  2050. /* Linker stub bfd. */
  2051. bfd *stub_bfd;
  2052. /* Linker call-backs. */
  2053. asection *(*add_stub_section) (const char *, asection *);
  2054. void (*layout_sections_again) (void);
  2055. /* Array to keep track of which stub sections have been created, and
  2056. information on stub grouping. */
  2057. struct map_stub
  2058. {
  2059. /* This is the section to which stubs in the group will be
  2060. attached. */
  2061. asection *link_sec;
  2062. /* The stub section. */
  2063. asection *stub_sec;
  2064. } *stub_group;
  2065. /* Assorted information used by elfNN_aarch64_size_stubs. */
  2066. unsigned int bfd_count;
  2067. unsigned int top_index;
  2068. asection **input_list;
  2069. /* The offset into splt of the PLT entry for the TLS descriptor
  2070. resolver. Special values are 0, if not necessary (or not found
  2071. to be necessary yet), and -1 if needed but not determined
  2072. yet. */
  2073. bfd_vma tlsdesc_plt;
  2074. /* The GOT offset for the lazy trampoline. Communicated to the
  2075. loader via DT_TLSDESC_GOT. The magic value (bfd_vma) -1
  2076. indicates an offset is not allocated. */
  2077. bfd_vma dt_tlsdesc_got;
  2078. /* Used by local STT_GNU_IFUNC symbols. */
  2079. htab_t loc_hash_table;
  2080. void * loc_hash_memory;
  2081. };
  2082. /* Create an entry in an AArch64 ELF linker hash table. */
  2083. static struct bfd_hash_entry *
  2084. elfNN_aarch64_link_hash_newfunc (struct bfd_hash_entry *entry,
  2085. struct bfd_hash_table *table,
  2086. const char *string)
  2087. {
  2088. struct elf_aarch64_link_hash_entry *ret =
  2089. (struct elf_aarch64_link_hash_entry *) entry;
  2090. /* Allocate the structure if it has not already been allocated by a
  2091. subclass. */
  2092. if (ret == NULL)
  2093. ret = bfd_hash_allocate (table,
  2094. sizeof (struct elf_aarch64_link_hash_entry));
  2095. if (ret == NULL)
  2096. return (struct bfd_hash_entry *) ret;
  2097. /* Call the allocation method of the superclass. */
  2098. ret = ((struct elf_aarch64_link_hash_entry *)
  2099. _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
  2100. table, string));
  2101. if (ret != NULL)
  2102. {
  2103. ret->dyn_relocs = NULL;
  2104. ret->got_type = GOT_UNKNOWN;
  2105. ret->plt_got_offset = (bfd_vma) - 1;
  2106. ret->stub_cache = NULL;
  2107. ret->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
  2108. }
  2109. return (struct bfd_hash_entry *) ret;
  2110. }
  2111. /* Initialize an entry in the stub hash table. */
  2112. static struct bfd_hash_entry *
  2113. stub_hash_newfunc (struct bfd_hash_entry *entry,
  2114. struct bfd_hash_table *table, const char *string)
  2115. {
  2116. /* Allocate the structure if it has not already been allocated by a
  2117. subclass. */
  2118. if (entry == NULL)
  2119. {
  2120. entry = bfd_hash_allocate (table,
  2121. sizeof (struct
  2122. elf_aarch64_stub_hash_entry));
  2123. if (entry == NULL)
  2124. return entry;
  2125. }
  2126. /* Call the allocation method of the superclass. */
  2127. entry = bfd_hash_newfunc (entry, table, string);
  2128. if (entry != NULL)
  2129. {
  2130. struct elf_aarch64_stub_hash_entry *eh;
  2131. /* Initialize the local fields. */
  2132. eh = (struct elf_aarch64_stub_hash_entry *) entry;
  2133. eh->adrp_offset = 0;
  2134. eh->stub_sec = NULL;
  2135. eh->stub_offset = 0;
  2136. eh->target_value = 0;
  2137. eh->target_section = NULL;
  2138. eh->stub_type = aarch64_stub_none;
  2139. eh->h = NULL;
  2140. eh->id_sec = NULL;
  2141. }
  2142. return entry;
  2143. }
  2144. /* Compute a hash of a local hash entry. We use elf_link_hash_entry
  2145. for local symbol so that we can handle local STT_GNU_IFUNC symbols
  2146. as global symbol. We reuse indx and dynstr_index for local symbol
  2147. hash since they aren't used by global symbols in this backend. */
  2148. static hashval_t
  2149. elfNN_aarch64_local_htab_hash (const void *ptr)
  2150. {
  2151. struct elf_link_hash_entry *h
  2152. = (struct elf_link_hash_entry *) ptr;
  2153. return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
  2154. }
  2155. /* Compare local hash entries. */
  2156. static int
  2157. elfNN_aarch64_local_htab_eq (const void *ptr1, const void *ptr2)
  2158. {
  2159. struct elf_link_hash_entry *h1
  2160. = (struct elf_link_hash_entry *) ptr1;
  2161. struct elf_link_hash_entry *h2
  2162. = (struct elf_link_hash_entry *) ptr2;
  2163. return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
  2164. }
  2165. /* Find and/or create a hash entry for local symbol. */
  2166. static struct elf_link_hash_entry *
  2167. elfNN_aarch64_get_local_sym_hash (struct elf_aarch64_link_hash_table *htab,
  2168. bfd *abfd, const Elf_Internal_Rela *rel,
  2169. bfd_boolean create)
  2170. {
  2171. struct elf_aarch64_link_hash_entry e, *ret;
  2172. asection *sec = abfd->sections;
  2173. hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
  2174. ELFNN_R_SYM (rel->r_info));
  2175. void **slot;
  2176. e.root.indx = sec->id;
  2177. e.root.dynstr_index = ELFNN_R_SYM (rel->r_info);
  2178. slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
  2179. create ? INSERT : NO_INSERT);
  2180. if (!slot)
  2181. return NULL;
  2182. if (*slot)
  2183. {
  2184. ret = (struct elf_aarch64_link_hash_entry *) *slot;
  2185. return &ret->root;
  2186. }
  2187. ret = (struct elf_aarch64_link_hash_entry *)
  2188. objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
  2189. sizeof (struct elf_aarch64_link_hash_entry));
  2190. if (ret)
  2191. {
  2192. memset (ret, 0, sizeof (*ret));
  2193. ret->root.indx = sec->id;
  2194. ret->root.dynstr_index = ELFNN_R_SYM (rel->r_info);
  2195. ret->root.dynindx = -1;
  2196. *slot = ret;
  2197. }
  2198. return &ret->root;
  2199. }
  2200. /* Copy the extra info we tack onto an elf_link_hash_entry. */
  2201. static void
  2202. elfNN_aarch64_copy_indirect_symbol (struct bfd_link_info *info,
  2203. struct elf_link_hash_entry *dir,
  2204. struct elf_link_hash_entry *ind)
  2205. {
  2206. struct elf_aarch64_link_hash_entry *edir, *eind;
  2207. edir = (struct elf_aarch64_link_hash_entry *) dir;
  2208. eind = (struct elf_aarch64_link_hash_entry *) ind;
  2209. if (eind->dyn_relocs != NULL)
  2210. {
  2211. if (edir->dyn_relocs != NULL)
  2212. {
  2213. struct elf_dyn_relocs **pp;
  2214. struct elf_dyn_relocs *p;
  2215. /* Add reloc counts against the indirect sym to the direct sym
  2216. list. Merge any entries against the same section. */
  2217. for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
  2218. {
  2219. struct elf_dyn_relocs *q;
  2220. for (q = edir->dyn_relocs; q != NULL; q = q->next)
  2221. if (q->sec == p->sec)
  2222. {
  2223. q->pc_count += p->pc_count;
  2224. q->count += p->count;
  2225. *pp = p->next;
  2226. break;
  2227. }
  2228. if (q == NULL)
  2229. pp = &p->next;
  2230. }
  2231. *pp = edir->dyn_relocs;
  2232. }
  2233. edir->dyn_relocs = eind->dyn_relocs;
  2234. eind->dyn_relocs = NULL;
  2235. }
  2236. if (ind->root.type == bfd_link_hash_indirect)
  2237. {
  2238. /* Copy over PLT info. */
  2239. if (dir->got.refcount <= 0)
  2240. {
  2241. edir->got_type = eind->got_type;
  2242. eind->got_type = GOT_UNKNOWN;
  2243. }
  2244. }
  2245. _bfd_elf_link_hash_copy_indirect (info, dir, ind);
  2246. }
  2247. /* Destroy an AArch64 elf linker hash table. */
  2248. static void
  2249. elfNN_aarch64_link_hash_table_free (bfd *obfd)
  2250. {
  2251. struct elf_aarch64_link_hash_table *ret
  2252. = (struct elf_aarch64_link_hash_table *) obfd->link.hash;
  2253. if (ret->loc_hash_table)
  2254. htab_delete (ret->loc_hash_table);
  2255. if (ret->loc_hash_memory)
  2256. objalloc_free ((struct objalloc *) ret->loc_hash_memory);
  2257. bfd_hash_table_free (&ret->stub_hash_table);
  2258. _bfd_elf_link_hash_table_free (obfd);
  2259. }
  2260. /* Create an AArch64 elf linker hash table. */
  2261. static struct bfd_link_hash_table *
  2262. elfNN_aarch64_link_hash_table_create (bfd *abfd)
  2263. {
  2264. struct elf_aarch64_link_hash_table *ret;
  2265. bfd_size_type amt = sizeof (struct elf_aarch64_link_hash_table);
  2266. ret = bfd_zmalloc (amt);
  2267. if (ret == NULL)
  2268. return NULL;
  2269. if (!_bfd_elf_link_hash_table_init
  2270. (&ret->root, abfd, elfNN_aarch64_link_hash_newfunc,
  2271. sizeof (struct elf_aarch64_link_hash_entry), AARCH64_ELF_DATA))
  2272. {
  2273. free (ret);
  2274. return NULL;
  2275. }
  2276. ret->plt_header_size = PLT_ENTRY_SIZE;
  2277. ret->plt_entry_size = PLT_SMALL_ENTRY_SIZE;
  2278. ret->obfd = abfd;
  2279. ret->dt_tlsdesc_got = (bfd_vma) - 1;
  2280. if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
  2281. sizeof (struct elf_aarch64_stub_hash_entry)))
  2282. {
  2283. _bfd_elf_link_hash_table_free (abfd);
  2284. return NULL;
  2285. }
  2286. ret->loc_hash_table = htab_try_create (1024,
  2287. elfNN_aarch64_local_htab_hash,
  2288. elfNN_aarch64_local_htab_eq,
  2289. NULL);
  2290. ret->loc_hash_memory = objalloc_create ();
  2291. if (!ret->loc_hash_table || !ret->loc_hash_memory)
  2292. {
  2293. elfNN_aarch64_link_hash_table_free (abfd);
  2294. return NULL;
  2295. }
  2296. ret->root.root.hash_table_free = elfNN_aarch64_link_hash_table_free;
  2297. return &ret->root.root;
  2298. }
  2299. static bfd_boolean
  2300. aarch64_relocate (unsigned int r_type, bfd *input_bfd, asection *input_section,
  2301. bfd_vma offset, bfd_vma value)
  2302. {
  2303. reloc_howto_type *howto;
  2304. bfd_vma place;
  2305. howto = elfNN_aarch64_howto_from_type (r_type);
  2306. place = (input_section->output_section->vma + input_section->output_offset
  2307. + offset);
  2308. r_type = elfNN_aarch64_bfd_reloc_from_type (r_type);
  2309. value = _bfd_aarch64_elf_resolve_relocation (r_type, place, value, 0, FALSE);
  2310. return _bfd_aarch64_elf_put_addend (input_bfd,
  2311. input_section->contents + offset, r_type,
  2312. howto, value);
  2313. }
  2314. static enum elf_aarch64_stub_type
  2315. aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
  2316. {
  2317. if (aarch64_valid_for_adrp_p (value, place))
  2318. return aarch64_stub_adrp_branch;
  2319. return aarch64_stub_long_branch;
  2320. }
  2321. /* Determine the type of stub needed, if any, for a call. */
  2322. static enum elf_aarch64_stub_type
  2323. aarch64_type_of_stub (struct bfd_link_info *info,
  2324. asection *input_sec,
  2325. const Elf_Internal_Rela *rel,
  2326. asection *sym_sec,
  2327. unsigned char st_type,
  2328. struct elf_aarch64_link_hash_entry *hash,
  2329. bfd_vma destination)
  2330. {
  2331. bfd_vma location;
  2332. bfd_signed_vma branch_offset;
  2333. unsigned int r_type;
  2334. struct elf_aarch64_link_hash_table *globals;
  2335. enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
  2336. bfd_boolean via_plt_p;
  2337. if (st_type != STT_FUNC
  2338. && (sym_sec != bfd_abs_section_ptr))
  2339. return stub_type;
  2340. globals = elf_aarch64_hash_table (info);
  2341. via_plt_p = (globals->root.splt != NULL && hash != NULL
  2342. && hash->root.plt.offset != (bfd_vma) - 1);
  2343. /* Make sure call to plt stub can fit into the branch range. */
  2344. if (via_plt_p)
  2345. destination = (globals->root.splt->output_section->vma
  2346. + globals->root.splt->output_offset
  2347. + hash->root.plt.offset);
  2348. /* Determine where the call point is. */
  2349. location = (input_sec->output_offset
  2350. + input_sec->output_section->vma + rel->r_offset);
  2351. branch_offset = (bfd_signed_vma) (destination - location);
  2352. r_type = ELFNN_R_TYPE (rel->r_info);
  2353. /* We don't want to redirect any old unconditional jump in this way,
  2354. only one which is being used for a sibcall, where it is
  2355. acceptable for the IP0 and IP1 registers to be clobbered. */
  2356. if ((r_type == AARCH64_R (CALL26) || r_type == AARCH64_R (JUMP26))
  2357. && (branch_offset > AARCH64_MAX_FWD_BRANCH_OFFSET
  2358. || branch_offset < AARCH64_MAX_BWD_BRANCH_OFFSET))
  2359. {
  2360. stub_type = aarch64_stub_long_branch;
  2361. }
  2362. return stub_type;
  2363. }
  2364. /* Build a name for an entry in the stub hash table. */
  2365. static char *
  2366. elfNN_aarch64_stub_name (const asection *input_section,
  2367. const asection *sym_sec,
  2368. const struct elf_aarch64_link_hash_entry *hash,
  2369. const Elf_Internal_Rela *rel)
  2370. {
  2371. char *stub_name;
  2372. bfd_size_type len;
  2373. if (hash)
  2374. {
  2375. len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 16 + 1;
  2376. stub_name = bfd_malloc (len);
  2377. if (stub_name != NULL)
  2378. snprintf (stub_name, len, "%08x_%s+%" BFD_VMA_FMT "x",
  2379. (unsigned int) input_section->id,
  2380. hash->root.root.root.string,
  2381. rel->r_addend);
  2382. }
  2383. else
  2384. {
  2385. len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
  2386. stub_name = bfd_malloc (len);
  2387. if (stub_name != NULL)
  2388. snprintf (stub_name, len, "%08x_%x:%x+%" BFD_VMA_FMT "x",
  2389. (unsigned int) input_section->id,
  2390. (unsigned int) sym_sec->id,
  2391. (unsigned int) ELFNN_R_SYM (rel->r_info),
  2392. rel->r_addend);
  2393. }
  2394. return stub_name;
  2395. }
  2396. /* Look up an entry in the stub hash. Stub entries are cached because
  2397. creating the stub name takes a bit of time. */
  2398. static struct elf_aarch64_stub_hash_entry *
  2399. elfNN_aarch64_get_stub_entry (const asection *input_section,
  2400. const asection *sym_sec,
  2401. struct elf_link_hash_entry *hash,
  2402. const Elf_Internal_Rela *rel,
  2403. struct elf_aarch64_link_hash_table *htab)
  2404. {
  2405. struct elf_aarch64_stub_hash_entry *stub_entry;
  2406. struct elf_aarch64_link_hash_entry *h =
  2407. (struct elf_aarch64_link_hash_entry *) hash;
  2408. const asection *id_sec;
  2409. if ((input_section->flags & SEC_CODE) == 0)
  2410. return NULL;
  2411. /* If this input section is part of a group of sections sharing one
  2412. stub section, then use the id of the first section in the group.
  2413. Stub names need to include a section id, as there may well be
  2414. more than one stub used to reach say, printf, and we need to
  2415. distinguish between them. */
  2416. id_sec = htab->stub_group[input_section->id].link_sec;
  2417. if (h != NULL && h->stub_cache != NULL
  2418. && h->stub_cache->h == h && h->stub_cache->id_sec == id_sec)
  2419. {
  2420. stub_entry = h->stub_cache;
  2421. }
  2422. else
  2423. {
  2424. char *stub_name;
  2425. stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, h, rel);
  2426. if (stub_name == NULL)
  2427. return NULL;
  2428. stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table,
  2429. stub_name, FALSE, FALSE);
  2430. if (h != NULL)
  2431. h->stub_cache = stub_entry;
  2432. free (stub_name);
  2433. }
  2434. return stub_entry;
  2435. }
  2436. /* Create a stub section. */
  2437. static asection *
  2438. _bfd_aarch64_create_stub_section (asection *section,
  2439. struct elf_aarch64_link_hash_table *htab)
  2440. {
  2441. size_t namelen;
  2442. bfd_size_type len;
  2443. char *s_name;
  2444. namelen = strlen (section->name);
  2445. len = namelen + sizeof (STUB_SUFFIX);
  2446. s_name = bfd_alloc (htab->stub_bfd, len);
  2447. if (s_name == NULL)
  2448. return NULL;
  2449. memcpy (s_name, section->name, namelen);
  2450. memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
  2451. return (*htab->add_stub_section) (s_name, section);
  2452. }
  2453. /* Find or create a stub section for a link section.
  2454. Fix or create the stub section used to collect stubs attached to
  2455. the specified link section. */
  2456. static asection *
  2457. _bfd_aarch64_get_stub_for_link_section (asection *link_section,
  2458. struct elf_aarch64_link_hash_table *htab)
  2459. {
  2460. if (htab->stub_group[link_section->id].stub_sec == NULL)
  2461. htab->stub_group[link_section->id].stub_sec
  2462. = _bfd_aarch64_create_stub_section (link_section, htab);
  2463. return htab->stub_group[link_section->id].stub_sec;
  2464. }
  2465. /* Find or create a stub section in the stub group for an input
  2466. section. */
  2467. static asection *
  2468. _bfd_aarch64_create_or_find_stub_sec (asection *section,
  2469. struct elf_aarch64_link_hash_table *htab)
  2470. {
  2471. asection *link_sec = htab->stub_group[section->id].link_sec;
  2472. return _bfd_aarch64_get_stub_for_link_section (link_sec, htab);
  2473. }
  2474. /* Add a new stub entry in the stub group associated with an input
  2475. section to the stub hash. Not all fields of the new stub entry are
  2476. initialised. */
  2477. static struct elf_aarch64_stub_hash_entry *
  2478. _bfd_aarch64_add_stub_entry_in_group (const char *stub_name,
  2479. asection *section,
  2480. struct elf_aarch64_link_hash_table *htab)
  2481. {
  2482. asection *link_sec;
  2483. asection *stub_sec;
  2484. struct elf_aarch64_stub_hash_entry *stub_entry;
  2485. link_sec = htab->stub_group[section->id].link_sec;
  2486. stub_sec = _bfd_aarch64_create_or_find_stub_sec (section, htab);
  2487. /* Enter this entry into the linker stub hash table. */
  2488. stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
  2489. TRUE, FALSE);
  2490. if (stub_entry == NULL)
  2491. {
  2492. (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
  2493. section->owner, stub_name);
  2494. return NULL;
  2495. }
  2496. stub_entry->stub_sec = stub_sec;
  2497. stub_entry->stub_offset = 0;
  2498. stub_entry->id_sec = link_sec;
  2499. return stub_entry;
  2500. }
  2501. /* Add a new stub entry in the final stub section to the stub hash.
  2502. Not all fields of the new stub entry are initialised. */
  2503. static struct elf_aarch64_stub_hash_entry *
  2504. _bfd_aarch64_add_stub_entry_after (const char *stub_name,
  2505. asection *link_section,
  2506. struct elf_aarch64_link_hash_table *htab)
  2507. {
  2508. asection *stub_sec;
  2509. struct elf_aarch64_stub_hash_entry *stub_entry;
  2510. stub_sec = _bfd_aarch64_get_stub_for_link_section (link_section, htab);
  2511. stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
  2512. TRUE, FALSE);
  2513. if (stub_entry == NULL)
  2514. {
  2515. (*_bfd_error_handler) (_("cannot create stub entry %s"), stub_name);
  2516. return NULL;
  2517. }
  2518. stub_entry->stub_sec = stub_sec;
  2519. stub_entry->stub_offset = 0;
  2520. stub_entry->id_sec = link_section;
  2521. return stub_entry;
  2522. }
  2523. static bfd_boolean
  2524. aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
  2525. void *in_arg ATTRIBUTE_UNUSED)
  2526. {
  2527. struct elf_aarch64_stub_hash_entry *stub_entry;
  2528. asection *stub_sec;
  2529. bfd *stub_bfd;
  2530. bfd_byte *loc;
  2531. bfd_vma sym_value;
  2532. bfd_vma veneered_insn_loc;
  2533. bfd_vma veneer_entry_loc;
  2534. bfd_signed_vma branch_offset = 0;
  2535. unsigned int template_size;
  2536. const uint32_t *template;
  2537. unsigned int i;
  2538. /* Massage our args to the form they really have. */
  2539. stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
  2540. stub_sec = stub_entry->stub_sec;
  2541. /* Make a note of the offset within the stubs for this entry. */
  2542. stub_entry->stub_offset = stub_sec->size;
  2543. loc = stub_sec->contents + stub_entry->stub_offset;
  2544. stub_bfd = stub_sec->owner;
  2545. /* This is the address of the stub destination. */
  2546. sym_value = (stub_entry->target_value
  2547. + stub_entry->target_section->output_offset
  2548. + stub_entry->target_section->output_section->vma);
  2549. if (stub_entry->stub_type == aarch64_stub_long_branch)
  2550. {
  2551. bfd_vma place = (stub_entry->stub_offset + stub_sec->output_section->vma
  2552. + stub_sec->output_offset);
  2553. /* See if we can relax the stub. */
  2554. if (aarch64_valid_for_adrp_p (sym_value, place))
  2555. stub_entry->stub_type = aarch64_select_branch_stub (sym_value, place);
  2556. }
  2557. switch (stub_entry->stub_type)
  2558. {
  2559. case aarch64_stub_adrp_branch:
  2560. template = aarch64_adrp_branch_stub;
  2561. template_size = sizeof (aarch64_adrp_branch_stub);
  2562. break;
  2563. case aarch64_stub_long_branch:
  2564. template = aarch64_long_branch_stub;
  2565. template_size = sizeof (aarch64_long_branch_stub);
  2566. break;
  2567. case aarch64_stub_erratum_835769_veneer:
  2568. template = aarch64_erratum_835769_stub;
  2569. template_size = sizeof (aarch64_erratum_835769_stub);
  2570. break;
  2571. case aarch64_stub_erratum_843419_veneer:
  2572. template = aarch64_erratum_843419_stub;
  2573. template_size = sizeof (aarch64_erratum_843419_stub);
  2574. break;
  2575. default:
  2576. abort ();
  2577. }
  2578. for (i = 0; i < (template_size / sizeof template[0]); i++)
  2579. {
  2580. bfd_putl32 (template[i], loc);
  2581. loc += 4;
  2582. }
  2583. template_size = (template_size + 7) & ~7;
  2584. stub_sec->size += template_size;
  2585. switch (stub_entry->stub_type)
  2586. {
  2587. case aarch64_stub_adrp_branch:
  2588. if (aarch64_relocate (AARCH64_R (ADR_PREL_PG_HI21), stub_bfd, stub_sec,
  2589. stub_entry->stub_offset, sym_value))
  2590. /* The stub would not have been relaxed if the offset was out
  2591. of range. */
  2592. BFD_FAIL ();
  2593. if (aarch64_relocate (AARCH64_R (ADD_ABS_LO12_NC), stub_bfd, stub_sec,
  2594. stub_entry->stub_offset + 4, sym_value))
  2595. BFD_FAIL ();
  2596. break;
  2597. case aarch64_stub_long_branch:
  2598. /* We want the value relative to the address 12 bytes back from the
  2599. value itself. */
  2600. if (aarch64_relocate (AARCH64_R (PRELNN), stub_bfd, stub_sec,
  2601. stub_entry->stub_offset + 16, sym_value + 12))
  2602. BFD_FAIL ();
  2603. break;
  2604. case aarch64_stub_erratum_835769_veneer:
  2605. veneered_insn_loc = stub_entry->target_section->output_section->vma
  2606. + stub_entry->target_section->output_offset
  2607. + stub_entry->target_value;
  2608. veneer_entry_loc = stub_entry->stub_sec->output_section->vma
  2609. + stub_entry->stub_sec->output_offset
  2610. + stub_entry->stub_offset;
  2611. branch_offset = veneered_insn_loc - veneer_entry_loc;
  2612. branch_offset >>= 2;
  2613. branch_offset &= 0x3ffffff;
  2614. bfd_putl32 (stub_entry->veneered_insn,
  2615. stub_sec->contents + stub_entry->stub_offset);
  2616. bfd_putl32 (template[1] | branch_offset,
  2617. stub_sec->contents + stub_entry->stub_offset + 4);
  2618. break;
  2619. case aarch64_stub_erratum_843419_veneer:
  2620. if (aarch64_relocate (AARCH64_R (JUMP26), stub_bfd, stub_sec,
  2621. stub_entry->stub_offset + 4, sym_value + 4))
  2622. BFD_FAIL ();
  2623. break;
  2624. default:
  2625. abort ();
  2626. }
  2627. return TRUE;
  2628. }
  2629. /* As above, but don't actually build the stub. Just bump offset so
  2630. we know stub section sizes. */
  2631. static bfd_boolean
  2632. aarch64_size_one_stub (struct bfd_hash_entry *gen_entry,
  2633. void *in_arg ATTRIBUTE_UNUSED)
  2634. {
  2635. struct elf_aarch64_stub_hash_entry *stub_entry;
  2636. int size;
  2637. /* Massage our args to the form they really have. */
  2638. stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
  2639. switch (stub_entry->stub_type)
  2640. {
  2641. case aarch64_stub_adrp_branch:
  2642. size = sizeof (aarch64_adrp_branch_stub);
  2643. break;
  2644. case aarch64_stub_long_branch:
  2645. size = sizeof (aarch64_long_branch_stub);
  2646. break;
  2647. case aarch64_stub_erratum_835769_veneer:
  2648. size = sizeof (aarch64_erratum_835769_stub);
  2649. break;
  2650. case aarch64_stub_erratum_843419_veneer:
  2651. size = sizeof (aarch64_erratum_843419_stub);
  2652. break;
  2653. default:
  2654. abort ();
  2655. }
  2656. size = (size + 7) & ~7;
  2657. stub_entry->stub_sec->size += size;
  2658. return TRUE;
  2659. }
  2660. /* External entry points for sizing and building linker stubs. */
  2661. /* Set up various things so that we can make a list of input sections
  2662. for each output section included in the link. Returns -1 on error,
  2663. 0 when no stubs will be needed, and 1 on success. */
  2664. int
  2665. elfNN_aarch64_setup_section_lists (bfd *output_bfd,
  2666. struct bfd_link_info *info)
  2667. {
  2668. bfd *input_bfd;
  2669. unsigned int bfd_count;
  2670. unsigned int top_id, top_index;
  2671. asection *section;
  2672. asection **input_list, **list;
  2673. bfd_size_type amt;
  2674. struct elf_aarch64_link_hash_table *htab =
  2675. elf_aarch64_hash_table (info);
  2676. if (!is_elf_hash_table (htab))
  2677. return 0;
  2678. /* Count the number of input BFDs and find the top input section id. */
  2679. for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
  2680. input_bfd != NULL; input_bfd = input_bfd->link.next)
  2681. {
  2682. bfd_count += 1;
  2683. for (section = input_bfd->sections;
  2684. section != NULL; section = section->next)
  2685. {
  2686. if (top_id < section->id)
  2687. top_id = section->id;
  2688. }
  2689. }
  2690. htab->bfd_count = bfd_count;
  2691. amt = sizeof (struct map_stub) * (top_id + 1);
  2692. htab->stub_group = bfd_zmalloc (amt);
  2693. if (htab->stub_group == NULL)
  2694. return -1;
  2695. /* We can't use output_bfd->section_count here to find the top output
  2696. section index as some sections may have been removed, and
  2697. _bfd_strip_section_from_output doesn't renumber the indices. */
  2698. for (section = output_bfd->sections, top_index = 0;
  2699. section != NULL; section = section->next)
  2700. {
  2701. if (top_index < section->index)
  2702. top_index = section->index;
  2703. }
  2704. htab->top_index = top_index;
  2705. amt = sizeof (asection *) * (top_index + 1);
  2706. input_list = bfd_malloc (amt);
  2707. htab->input_list = input_list;
  2708. if (input_list == NULL)
  2709. return -1;
  2710. /* For sections we aren't interested in, mark their entries with a
  2711. value we can check later. */
  2712. list = input_list + top_index;
  2713. do
  2714. *list = bfd_abs_section_ptr;
  2715. while (list-- != input_list);
  2716. for (section = output_bfd->sections;
  2717. section != NULL; section = section->next)
  2718. {
  2719. if ((section->flags & SEC_CODE) != 0)
  2720. input_list[section->index] = NULL;
  2721. }
  2722. return 1;
  2723. }
  2724. /* Used by elfNN_aarch64_next_input_section and group_sections. */
  2725. #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
  2726. /* The linker repeatedly calls this function for each input section,
  2727. in the order that input sections are linked into output sections.
  2728. Build lists of input sections to determine groupings between which
  2729. we may insert linker stubs. */
  2730. void
  2731. elfNN_aarch64_next_input_section (struct bfd_link_info *info, asection *isec)
  2732. {
  2733. struct elf_aarch64_link_hash_table *htab =
  2734. elf_aarch64_hash_table (info);
  2735. if (isec->output_section->index <= htab->top_index)
  2736. {
  2737. asection **list = htab->input_list + isec->output_section->index;
  2738. if (*list != bfd_abs_section_ptr)
  2739. {
  2740. /* Steal the link_sec pointer for our list. */
  2741. /* This happens to make the list in reverse order,
  2742. which is what we want. */
  2743. PREV_SEC (isec) = *list;
  2744. *list = isec;
  2745. }
  2746. }
  2747. }
  2748. /* See whether we can group stub sections together. Grouping stub
  2749. sections may result in fewer stubs. More importantly, we need to
  2750. put all .init* and .fini* stubs at the beginning of the .init or
  2751. .fini output sections respectively, because glibc splits the
  2752. _init and _fini functions into multiple parts. Putting a stub in
  2753. the middle of a function is not a good idea. */
  2754. static void
  2755. group_sections (struct elf_aarch64_link_hash_table *htab,
  2756. bfd_size_type stub_group_size,
  2757. bfd_boolean stubs_always_before_branch)
  2758. {
  2759. asection **list = htab->input_list + htab->top_index;
  2760. do
  2761. {
  2762. asection *tail = *list;
  2763. if (tail == bfd_abs_section_ptr)
  2764. continue;
  2765. while (tail != NULL)
  2766. {
  2767. asection *curr;
  2768. asection *prev;
  2769. bfd_size_type total;
  2770. curr = tail;
  2771. total = tail->size;
  2772. while ((prev = PREV_SEC (curr)) != NULL
  2773. && ((total += curr->output_offset - prev->output_offset)
  2774. < stub_group_size))
  2775. curr = prev;
  2776. /* OK, the size from the start of CURR to the end is less
  2777. than stub_group_size and thus can be handled by one stub
  2778. section. (Or the tail section is itself larger than
  2779. stub_group_size, in which case we may be toast.)
  2780. We should really be keeping track of the total size of
  2781. stubs added here, as stubs contribute to the final output
  2782. section size. */
  2783. do
  2784. {
  2785. prev = PREV_SEC (tail);
  2786. /* Set up this stub group. */
  2787. htab->stub_group[tail->id].link_sec = curr;
  2788. }
  2789. while (tail != curr && (tail = prev) != NULL);
  2790. /* But wait, there's more! Input sections up to stub_group_size
  2791. bytes before the stub section can be handled by it too. */
  2792. if (!stubs_always_before_branch)
  2793. {
  2794. total = 0;
  2795. while (prev != NULL
  2796. && ((total += tail->output_offset - prev->output_offset)
  2797. < stub_group_size))
  2798. {
  2799. tail = prev;
  2800. prev = PREV_SEC (tail);
  2801. htab->stub_group[tail->id].link_sec = curr;
  2802. }
  2803. }
  2804. tail = prev;
  2805. }
  2806. }
  2807. while (list-- != htab->input_list);
  2808. free (htab->input_list);
  2809. }
  2810. #undef PREV_SEC
  2811. #define AARCH64_BITS(x, pos, n) (((x) >> (pos)) & ((1 << (n)) - 1))
  2812. #define AARCH64_RT(insn) AARCH64_BITS (insn, 0, 5)
  2813. #define AARCH64_RT2(insn) AARCH64_BITS (insn, 10, 5)
  2814. #define AARCH64_RA(insn) AARCH64_BITS (insn, 10, 5)
  2815. #define AARCH64_RD(insn) AARCH64_BITS (insn, 0, 5)
  2816. #define AARCH64_RN(insn) AARCH64_BITS (insn, 5, 5)
  2817. #define AARCH64_RM(insn) AARCH64_BITS (insn, 16, 5)
  2818. #define AARCH64_MAC(insn) (((insn) & 0xff000000) == 0x9b000000)
  2819. #define AARCH64_BIT(insn, n) AARCH64_BITS (insn, n, 1)
  2820. #define AARCH64_OP31(insn) AARCH64_BITS (insn, 21, 3)
  2821. #define AARCH64_ZR 0x1f
  2822. /* All ld/st ops. See C4-182 of the ARM ARM. The encoding space for
  2823. LD_PCREL, LDST_RO, LDST_UI and LDST_UIMM cover prefetch ops. */
  2824. #define AARCH64_LD(insn) (AARCH64_BIT (insn, 22) == 1)
  2825. #define AARCH64_LDST(insn) (((insn) & 0x0a000000) == 0x08000000)
  2826. #define AARCH64_LDST_EX(insn) (((insn) & 0x3f000000) == 0x08000000)
  2827. #define AARCH64_LDST_PCREL(insn) (((insn) & 0x3b000000) == 0x18000000)
  2828. #define AARCH64_LDST_NAP(insn) (((insn) & 0x3b800000) == 0x28000000)
  2829. #define AARCH64_LDSTP_PI(insn) (((insn) & 0x3b800000) == 0x28800000)
  2830. #define AARCH64_LDSTP_O(insn) (((insn) & 0x3b800000) == 0x29000000)
  2831. #define AARCH64_LDSTP_PRE(insn) (((insn) & 0x3b800000) == 0x29800000)
  2832. #define AARCH64_LDST_UI(insn) (((insn) & 0x3b200c00) == 0x38000000)
  2833. #define AARCH64_LDST_PIIMM(insn) (((insn) & 0x3b200c00) == 0x38000400)
  2834. #define AARCH64_LDST_U(insn) (((insn) & 0x3b200c00) == 0x38000800)
  2835. #define AARCH64_LDST_PREIMM(insn) (((insn) & 0x3b200c00) == 0x38000c00)
  2836. #define AARCH64_LDST_RO(insn) (((insn) & 0x3b200c00) == 0x38200800)
  2837. #define AARCH64_LDST_UIMM(insn) (((insn) & 0x3b000000) == 0x39000000)
  2838. #define AARCH64_LDST_SIMD_M(insn) (((insn) & 0xbfbf0000) == 0x0c000000)
  2839. #define AARCH64_LDST_SIMD_M_PI(insn) (((insn) & 0xbfa00000) == 0x0c800000)
  2840. #define AARCH64_LDST_SIMD_S(insn) (((insn) & 0xbf9f0000) == 0x0d000000)
  2841. #define AARCH64_LDST_SIMD_S_PI(insn) (((insn) & 0xbf800000) == 0x0d800000)
  2842. /* Classify an INSN if it is indeed a load/store.
  2843. Return TRUE if INSN is a LD/ST instruction otherwise return FALSE.
  2844. For scalar LD/ST instructions PAIR is FALSE, RT is returned and RT2
  2845. is set equal to RT.
  2846. For LD/ST pair instructions PAIR is TRUE, RT and RT2 are returned.
  2847. */
  2848. static bfd_boolean
  2849. aarch64_mem_op_p (uint32_t insn, unsigned int *rt, unsigned int *rt2,
  2850. bfd_boolean *pair, bfd_boolean *load)
  2851. {
  2852. uint32_t opcode;
  2853. unsigned int r;
  2854. uint32_t opc = 0;
  2855. uint32_t v = 0;
  2856. uint32_t opc_v = 0;
  2857. /* Bail out quickly if INSN doesn't fall into the the load-store
  2858. encoding space. */
  2859. if (!AARCH64_LDST (insn))
  2860. return FALSE;
  2861. *pair = FALSE;
  2862. *load = FALSE;
  2863. if (AARCH64_LDST_EX (insn))
  2864. {
  2865. *rt = AARCH64_RT (insn);
  2866. *rt2 = *rt;
  2867. if (AARCH64_BIT (insn, 21) == 1)
  2868. {
  2869. *pair = TRUE;
  2870. *rt2 = AARCH64_RT2 (insn);
  2871. }
  2872. *load = AARCH64_LD (insn);
  2873. return TRUE;
  2874. }
  2875. else if (AARCH64_LDST_NAP (insn)
  2876. || AARCH64_LDSTP_PI (insn)
  2877. || AARCH64_LDSTP_O (insn)
  2878. || AARCH64_LDSTP_PRE (insn))
  2879. {
  2880. *pair = TRUE;
  2881. *rt = AARCH64_RT (insn);
  2882. *rt2 = AARCH64_RT2 (insn);
  2883. *load = AARCH64_LD (insn);
  2884. return TRUE;
  2885. }
  2886. else if (AARCH64_LDST_PCREL (insn)
  2887. || AARCH64_LDST_UI (insn)
  2888. || AARCH64_LDST_PIIMM (insn)
  2889. || AARCH64_LDST_U (insn)
  2890. || AARCH64_LDST_PREIMM (insn)
  2891. || AARCH64_LDST_RO (insn)
  2892. || AARCH64_LDST_UIMM (insn))
  2893. {
  2894. *rt = AARCH64_RT (insn);
  2895. *rt2 = *rt;
  2896. if (AARCH64_LDST_PCREL (insn))
  2897. *load = TRUE;
  2898. opc = AARCH64_BITS (insn, 22, 2);
  2899. v = AARCH64_BIT (insn, 26);
  2900. opc_v = opc | (v << 2);
  2901. *load = (opc_v == 1 || opc_v == 2 || opc_v == 3
  2902. || opc_v == 5 || opc_v == 7);
  2903. return TRUE;
  2904. }
  2905. else if (AARCH64_LDST_SIMD_M (insn)
  2906. || AARCH64_LDST_SIMD_M_PI (insn))
  2907. {
  2908. *rt = AARCH64_RT (insn);
  2909. *load = AARCH64_BIT (insn, 22);
  2910. opcode = (insn >> 12) & 0xf;
  2911. switch (opcode)
  2912. {
  2913. case 0:
  2914. case 2:
  2915. *rt2 = *rt + 3;
  2916. break;
  2917. case 4:
  2918. case 6:
  2919. *rt2 = *rt + 2;
  2920. break;
  2921. case 7:
  2922. *rt2 = *rt;
  2923. break;
  2924. case 8:
  2925. case 10:
  2926. *rt2 = *rt + 1;
  2927. break;
  2928. default:
  2929. return FALSE;
  2930. }
  2931. return TRUE;
  2932. }
  2933. else if (AARCH64_LDST_SIMD_S (insn)
  2934. || AARCH64_LDST_SIMD_S_PI (insn))
  2935. {
  2936. *rt = AARCH64_RT (insn);
  2937. r = (insn >> 21) & 1;
  2938. *load = AARCH64_BIT (insn, 22);
  2939. opcode = (insn >> 13) & 0x7;
  2940. switch (opcode)
  2941. {
  2942. case 0:
  2943. case 2:
  2944. case 4:
  2945. *rt2 = *rt + r;
  2946. break;
  2947. case 1:
  2948. case 3:
  2949. case 5:
  2950. *rt2 = *rt + (r == 0 ? 2 : 3);
  2951. break;
  2952. case 6:
  2953. *rt2 = *rt + r;
  2954. break;
  2955. case 7:
  2956. *rt2 = *rt + (r == 0 ? 2 : 3);
  2957. break;
  2958. default:
  2959. return FALSE;
  2960. }
  2961. return TRUE;
  2962. }
  2963. return FALSE;
  2964. }
  2965. /* Return TRUE if INSN is multiply-accumulate. */
  2966. static bfd_boolean
  2967. aarch64_mlxl_p (uint32_t insn)
  2968. {
  2969. uint32_t op31 = AARCH64_OP31 (insn);
  2970. if (AARCH64_MAC (insn)
  2971. && (op31 == 0 || op31 == 1 || op31 == 5)
  2972. /* Exclude MUL instructions which are encoded as a multiple accumulate
  2973. with RA = XZR. */
  2974. && AARCH64_RA (insn) != AARCH64_ZR)
  2975. return TRUE;
  2976. return FALSE;
  2977. }
  2978. /* Some early revisions of the Cortex-A53 have an erratum (835769) whereby
  2979. it is possible for a 64-bit multiply-accumulate instruction to generate an
  2980. incorrect result. The details are quite complex and hard to
  2981. determine statically, since branches in the code may exist in some
  2982. circumstances, but all cases end with a memory (load, store, or
  2983. prefetch) instruction followed immediately by the multiply-accumulate
  2984. operation. We employ a linker patching technique, by moving the potentially
  2985. affected multiply-accumulate instruction into a patch region and replacing
  2986. the original instruction with a branch to the patch. This function checks
  2987. if INSN_1 is the memory operation followed by a multiply-accumulate
  2988. operation (INSN_2). Return TRUE if an erratum sequence is found, FALSE
  2989. if INSN_1 and INSN_2 are safe. */
  2990. static bfd_boolean
  2991. aarch64_erratum_sequence (uint32_t insn_1, uint32_t insn_2)
  2992. {
  2993. uint32_t rt;
  2994. uint32_t rt2;
  2995. uint32_t rn;
  2996. uint32_t rm;
  2997. uint32_t ra;
  2998. bfd_boolean pair;
  2999. bfd_boolean load;
  3000. if (aarch64_mlxl_p (insn_2)
  3001. && aarch64_mem_op_p (insn_1, &rt, &rt2, &pair, &load))
  3002. {
  3003. /* Any SIMD memory op is independent of the subsequent MLA
  3004. by definition of the erratum. */
  3005. if (AARCH64_BIT (insn_1, 26))
  3006. return TRUE;
  3007. /* If not SIMD, check for integer memory ops and MLA relationship. */
  3008. rn = AARCH64_RN (insn_2);
  3009. ra = AARCH64_RA (insn_2);
  3010. rm = AARCH64_RM (insn_2);
  3011. /* If this is a load and there's a true(RAW) dependency, we are safe
  3012. and this is not an erratum sequence. */
  3013. if (load &&
  3014. (rt == rn || rt == rm || rt == ra
  3015. || (pair && (rt2 == rn || rt2 == rm || rt2 == ra))))
  3016. return FALSE;
  3017. /* We conservatively put out stubs for all other cases (including
  3018. writebacks). */
  3019. return TRUE;
  3020. }
  3021. return FALSE;
  3022. }
  3023. /* Used to order a list of mapping symbols by address. */
  3024. static int
  3025. elf_aarch64_compare_mapping (const void *a, const void *b)
  3026. {
  3027. const elf_aarch64_section_map *amap = (const elf_aarch64_section_map *) a;
  3028. const elf_aarch64_section_map *bmap = (const elf_aarch64_section_map *) b;
  3029. if (amap->vma > bmap->vma)
  3030. return 1;
  3031. else if (amap->vma < bmap->vma)
  3032. return -1;
  3033. else if (amap->type > bmap->type)
  3034. /* Ensure results do not depend on the host qsort for objects with
  3035. multiple mapping symbols at the same address by sorting on type
  3036. after vma. */
  3037. return 1;
  3038. else if (amap->type < bmap->type)
  3039. return -1;
  3040. else
  3041. return 0;
  3042. }
  3043. static char *
  3044. _bfd_aarch64_erratum_835769_stub_name (unsigned num_fixes)
  3045. {
  3046. char *stub_name = (char *) bfd_malloc
  3047. (strlen ("__erratum_835769_veneer_") + 16);
  3048. sprintf (stub_name,"__erratum_835769_veneer_%d", num_fixes);
  3049. return stub_name;
  3050. }
  3051. /* Scan for Cortex-A53 erratum 835769 sequence.
  3052. Return TRUE else FALSE on abnormal termination. */
  3053. static bfd_boolean
  3054. _bfd_aarch64_erratum_835769_scan (bfd *input_bfd,
  3055. struct bfd_link_info *info,
  3056. unsigned int *num_fixes_p)
  3057. {
  3058. asection *section;
  3059. struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
  3060. unsigned int num_fixes = *num_fixes_p;
  3061. if (htab == NULL)
  3062. return TRUE;
  3063. for (section = input_bfd->sections;
  3064. section != NULL;
  3065. section = section->next)
  3066. {
  3067. bfd_byte *contents = NULL;
  3068. struct _aarch64_elf_section_data *sec_data;
  3069. unsigned int span;
  3070. if (elf_section_type (section) != SHT_PROGBITS
  3071. || (elf_section_flags (section) & SHF_EXECINSTR) == 0
  3072. || (section->flags & SEC_EXCLUDE) != 0
  3073. || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
  3074. || (section->output_section == bfd_abs_section_ptr))
  3075. continue;
  3076. if (elf_section_data (section)->this_hdr.contents != NULL)
  3077. contents = elf_section_data (section)->this_hdr.contents;
  3078. else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
  3079. return FALSE;
  3080. sec_data = elf_aarch64_section_data (section);
  3081. qsort (sec_data->map, sec_data->mapcount,
  3082. sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
  3083. for (span = 0; span < sec_data->mapcount; span++)
  3084. {
  3085. unsigned int span_start = sec_data->map[span].vma;
  3086. unsigned int span_end = ((span == sec_data->mapcount - 1)
  3087. ? sec_data->map[0].vma + section->size
  3088. : sec_data->map[span + 1].vma);
  3089. unsigned int i;
  3090. char span_type = sec_data->map[span].type;
  3091. if (span_type == 'd')
  3092. continue;
  3093. for (i = span_start; i + 4 < span_end; i += 4)
  3094. {
  3095. uint32_t insn_1 = bfd_getl32 (contents + i);
  3096. uint32_t insn_2 = bfd_getl32 (contents + i + 4);
  3097. if (aarch64_erratum_sequence (insn_1, insn_2))
  3098. {
  3099. struct elf_aarch64_stub_hash_entry *stub_entry;
  3100. char *stub_name = _bfd_aarch64_erratum_835769_stub_name (num_fixes);
  3101. if (! stub_name)
  3102. return FALSE;
  3103. stub_entry = _bfd_aarch64_add_stub_entry_in_group (stub_name,
  3104. section,
  3105. htab);
  3106. if (! stub_entry)
  3107. return FALSE;
  3108. stub_entry->stub_type = aarch64_stub_erratum_835769_veneer;
  3109. stub_entry->target_section = section;
  3110. stub_entry->target_value = i + 4;
  3111. stub_entry->veneered_insn = insn_2;
  3112. stub_entry->output_name = stub_name;
  3113. num_fixes++;
  3114. }
  3115. }
  3116. }
  3117. if (elf_section_data (section)->this_hdr.contents == NULL)
  3118. free (contents);
  3119. }
  3120. *num_fixes_p = num_fixes;
  3121. return TRUE;
  3122. }
  3123. /* Test if instruction INSN is ADRP. */
  3124. static bfd_boolean
  3125. _bfd_aarch64_adrp_p (uint32_t insn)
  3126. {
  3127. return ((insn & 0x9f000000) == 0x90000000);
  3128. }
  3129. /* Helper predicate to look for cortex-a53 erratum 843419 sequence 1. */
  3130. static bfd_boolean
  3131. _bfd_aarch64_erratum_843419_sequence_p (uint32_t insn_1, uint32_t insn_2,
  3132. uint32_t insn_3)
  3133. {
  3134. uint32_t rt;
  3135. uint32_t rt2;
  3136. bfd_boolean pair;
  3137. bfd_boolean load;
  3138. return (aarch64_mem_op_p (insn_2, &rt, &rt2, &pair, &load)
  3139. && (!pair
  3140. || (pair && !load))
  3141. && AARCH64_LDST_UIMM (insn_3)
  3142. && AARCH64_RN (insn_3) == AARCH64_RD (insn_1));
  3143. }
  3144. /* Test for the presence of Cortex-A53 erratum 843419 instruction sequence.
  3145. Return TRUE if section CONTENTS at offset I contains one of the
  3146. erratum 843419 sequences, otherwise return FALSE. If a sequence is
  3147. seen set P_VENEER_I to the offset of the final LOAD/STORE
  3148. instruction in the sequence.
  3149. */
  3150. static bfd_boolean
  3151. _bfd_aarch64_erratum_843419_p (bfd_byte *contents, bfd_vma vma,
  3152. bfd_vma i, bfd_vma span_end,
  3153. bfd_vma *p_veneer_i)
  3154. {
  3155. uint32_t insn_1 = bfd_getl32 (contents + i);
  3156. if (!_bfd_aarch64_adrp_p (insn_1))
  3157. return FALSE;
  3158. if (span_end < i + 12)
  3159. return FALSE;
  3160. uint32_t insn_2 = bfd_getl32 (contents + i + 4);
  3161. uint32_t insn_3 = bfd_getl32 (contents + i + 8);
  3162. if ((vma & 0xfff) != 0xff8 && (vma & 0xfff) != 0xffc)
  3163. return FALSE;
  3164. if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_3))
  3165. {
  3166. *p_veneer_i = i + 8;
  3167. return TRUE;
  3168. }
  3169. if (span_end < i + 16)
  3170. return FALSE;
  3171. uint32_t insn_4 = bfd_getl32 (contents + i + 12);
  3172. if (_bfd_aarch64_erratum_843419_sequence_p (insn_1, insn_2, insn_4))
  3173. {
  3174. *p_veneer_i = i + 12;
  3175. return TRUE;
  3176. }
  3177. return FALSE;
  3178. }
  3179. /* Resize all stub sections. */
  3180. static void
  3181. _bfd_aarch64_resize_stubs (struct elf_aarch64_link_hash_table *htab)
  3182. {
  3183. asection *section;
  3184. /* OK, we've added some stubs. Find out the new size of the
  3185. stub sections. */
  3186. for (section = htab->stub_bfd->sections;
  3187. section != NULL; section = section->next)
  3188. {
  3189. /* Ignore non-stub sections. */
  3190. if (!strstr (section->name, STUB_SUFFIX))
  3191. continue;
  3192. section->size = 0;
  3193. }
  3194. bfd_hash_traverse (&htab->stub_hash_table, aarch64_size_one_stub, htab);
  3195. for (section = htab->stub_bfd->sections;
  3196. section != NULL; section = section->next)
  3197. {
  3198. if (!strstr (section->name, STUB_SUFFIX))
  3199. continue;
  3200. if (section->size)
  3201. section->size += 4;
  3202. /* Ensure all stub sections have a size which is a multiple of
  3203. 4096. This is important in order to ensure that the insertion
  3204. of stub sections does not in itself move existing code around
  3205. in such a way that new errata sequences are created. */
  3206. if (htab->fix_erratum_843419)
  3207. if (section->size)
  3208. section->size = BFD_ALIGN (section->size, 0x1000);
  3209. }
  3210. }
  3211. /* Construct an erratum 843419 workaround stub name.
  3212. */
  3213. static char *
  3214. _bfd_aarch64_erratum_843419_stub_name (asection *input_section,
  3215. bfd_vma offset)
  3216. {
  3217. const bfd_size_type len = 8 + 4 + 1 + 8 + 1 + 16 + 1;
  3218. char *stub_name = bfd_malloc (len);
  3219. if (stub_name != NULL)
  3220. snprintf (stub_name, len, "e843419@%04x_%08x_%" BFD_VMA_FMT "x",
  3221. input_section->owner->id,
  3222. input_section->id,
  3223. offset);
  3224. return stub_name;
  3225. }
  3226. /* Build a stub_entry structure describing an 843419 fixup.
  3227. The stub_entry constructed is populated with the bit pattern INSN
  3228. of the instruction located at OFFSET within input SECTION.
  3229. Returns TRUE on success. */
  3230. static bfd_boolean
  3231. _bfd_aarch64_erratum_843419_fixup (uint32_t insn,
  3232. bfd_vma adrp_offset,
  3233. bfd_vma ldst_offset,
  3234. asection *section,
  3235. struct bfd_link_info *info)
  3236. {
  3237. struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
  3238. char *stub_name;
  3239. struct elf_aarch64_stub_hash_entry *stub_entry;
  3240. stub_name = _bfd_aarch64_erratum_843419_stub_name (section, ldst_offset);
  3241. stub_entry = aarch64_stub_hash_lookup (&htab->stub_hash_table, stub_name,
  3242. FALSE, FALSE);
  3243. if (stub_entry)
  3244. {
  3245. free (stub_name);
  3246. return TRUE;
  3247. }
  3248. /* We always place an 843419 workaround veneer in the stub section
  3249. attached to the input section in which an erratum sequence has
  3250. been found. This ensures that later in the link process (in
  3251. elfNN_aarch64_write_section) when we copy the veneered
  3252. instruction from the input section into the stub section the
  3253. copied instruction will have had any relocations applied to it.
  3254. If we placed workaround veneers in any other stub section then we
  3255. could not assume that all relocations have been processed on the
  3256. corresponding input section at the point we output the stub
  3257. section.
  3258. */
  3259. stub_entry = _bfd_aarch64_add_stub_entry_after (stub_name, section, htab);
  3260. if (stub_entry == NULL)
  3261. {
  3262. free (stub_name);
  3263. return FALSE;
  3264. }
  3265. stub_entry->adrp_offset = adrp_offset;
  3266. stub_entry->target_value = ldst_offset;
  3267. stub_entry->target_section = section;
  3268. stub_entry->stub_type = aarch64_stub_erratum_843419_veneer;
  3269. stub_entry->veneered_insn = insn;
  3270. stub_entry->output_name = stub_name;
  3271. return TRUE;
  3272. }
  3273. /* Scan an input section looking for the signature of erratum 843419.
  3274. Scans input SECTION in INPUT_BFD looking for erratum 843419
  3275. signatures, for each signature found a stub_entry is created
  3276. describing the location of the erratum for subsequent fixup.
  3277. Return TRUE on successful scan, FALSE on failure to scan.
  3278. */
  3279. static bfd_boolean
  3280. _bfd_aarch64_erratum_843419_scan (bfd *input_bfd, asection *section,
  3281. struct bfd_link_info *info)
  3282. {
  3283. struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
  3284. if (htab == NULL)
  3285. return TRUE;
  3286. if (elf_section_type (section) != SHT_PROGBITS
  3287. || (elf_section_flags (section) & SHF_EXECINSTR) == 0
  3288. || (section->flags & SEC_EXCLUDE) != 0
  3289. || (section->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
  3290. || (section->output_section == bfd_abs_section_ptr))
  3291. return TRUE;
  3292. do
  3293. {
  3294. bfd_byte *contents = NULL;
  3295. struct _aarch64_elf_section_data *sec_data;
  3296. unsigned int span;
  3297. if (elf_section_data (section)->this_hdr.contents != NULL)
  3298. contents = elf_section_data (section)->this_hdr.contents;
  3299. else if (! bfd_malloc_and_get_section (input_bfd, section, &contents))
  3300. return FALSE;
  3301. sec_data = elf_aarch64_section_data (section);
  3302. qsort (sec_data->map, sec_data->mapcount,
  3303. sizeof (elf_aarch64_section_map), elf_aarch64_compare_mapping);
  3304. for (span = 0; span < sec_data->mapcount; span++)
  3305. {
  3306. unsigned int span_start = sec_data->map[span].vma;
  3307. unsigned int span_end = ((span == sec_data->mapcount - 1)
  3308. ? sec_data->map[0].vma + section->size
  3309. : sec_data->map[span + 1].vma);
  3310. unsigned int i;
  3311. char span_type = sec_data->map[span].type;
  3312. if (span_type == 'd')
  3313. continue;
  3314. for (i = span_start; i + 8 < span_end; i += 4)
  3315. {
  3316. bfd_vma vma = (section->output_section->vma
  3317. + section->output_offset
  3318. + i);
  3319. bfd_vma veneer_i;
  3320. if (_bfd_aarch64_erratum_843419_p
  3321. (contents, vma, i, span_end, &veneer_i))
  3322. {
  3323. uint32_t insn = bfd_getl32 (contents + veneer_i);
  3324. if (!_bfd_aarch64_erratum_843419_fixup (insn, i, veneer_i,
  3325. section, info))
  3326. return FALSE;
  3327. }
  3328. }
  3329. }
  3330. if (elf_section_data (section)->this_hdr.contents == NULL)
  3331. free (contents);
  3332. }
  3333. while (0);
  3334. return TRUE;
  3335. }
  3336. /* Determine and set the size of the stub section for a final link.
  3337. The basic idea here is to examine all the relocations looking for
  3338. PC-relative calls to a target that is unreachable with a "bl"
  3339. instruction. */
  3340. bfd_boolean
  3341. elfNN_aarch64_size_stubs (bfd *output_bfd,
  3342. bfd *stub_bfd,
  3343. struct bfd_link_info *info,
  3344. bfd_signed_vma group_size,
  3345. asection * (*add_stub_section) (const char *,
  3346. asection *),
  3347. void (*layout_sections_again) (void))
  3348. {
  3349. bfd_size_type stub_group_size;
  3350. bfd_boolean stubs_always_before_branch;
  3351. bfd_boolean stub_changed = FALSE;
  3352. struct elf_aarch64_link_hash_table *htab = elf_aarch64_hash_table (info);
  3353. unsigned int num_erratum_835769_fixes = 0;
  3354. /* Propagate mach to stub bfd, because it may not have been
  3355. finalized when we created stub_bfd. */
  3356. bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
  3357. bfd_get_mach (output_bfd));
  3358. /* Stash our params away. */
  3359. htab->stub_bfd = stub_bfd;
  3360. htab->add_stub_section = add_stub_section;
  3361. htab->layout_sections_again = layout_sections_again;
  3362. stubs_always_before_branch = group_size < 0;
  3363. if (group_size < 0)
  3364. stub_group_size = -group_size;
  3365. else
  3366. stub_group_size = group_size;
  3367. if (stub_group_size == 1)
  3368. {
  3369. /* Default values. */
  3370. /* AArch64 branch range is +-128MB. The value used is 1MB less. */
  3371. stub_group_size = 127 * 1024 * 1024;
  3372. }
  3373. group_sections (htab, stub_group_size, stubs_always_before_branch);
  3374. (*htab->layout_sections_again) ();
  3375. if (htab->fix_erratum_835769)
  3376. {
  3377. bfd *input_bfd;
  3378. for (input_bfd = info->input_bfds;
  3379. input_bfd != NULL; input_bfd = input_bfd->link.next)
  3380. if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info,
  3381. &num_erratum_835769_fixes))
  3382. return FALSE;
  3383. _bfd_aarch64_resize_stubs (htab);
  3384. (*htab->layout_sections_again) ();
  3385. }
  3386. if (htab->fix_erratum_843419)
  3387. {
  3388. bfd *input_bfd;
  3389. for (input_bfd = info->input_bfds;
  3390. input_bfd != NULL;
  3391. input_bfd = input_bfd->link.next)
  3392. {
  3393. asection *section;
  3394. for (section = input_bfd->sections;
  3395. section != NULL;
  3396. section = section->next)
  3397. if (!_bfd_aarch64_erratum_843419_scan (input_bfd, section, info))
  3398. return FALSE;
  3399. }
  3400. _bfd_aarch64_resize_stubs (htab);
  3401. (*htab->layout_sections_again) ();
  3402. }
  3403. while (1)
  3404. {
  3405. bfd *input_bfd;
  3406. for (input_bfd = info->input_bfds;
  3407. input_bfd != NULL; input_bfd = input_bfd->link.next)
  3408. {
  3409. Elf_Internal_Shdr *symtab_hdr;
  3410. asection *section;
  3411. Elf_Internal_Sym *local_syms = NULL;
  3412. /* We'll need the symbol table in a second. */
  3413. symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  3414. if (symtab_hdr->sh_info == 0)
  3415. continue;
  3416. /* Walk over each section attached to the input bfd. */
  3417. for (section = input_bfd->sections;
  3418. section != NULL; section = section->next)
  3419. {
  3420. Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
  3421. /* If there aren't any relocs, then there's nothing more
  3422. to do. */
  3423. if ((section->flags & SEC_RELOC) == 0
  3424. || section->reloc_count == 0
  3425. || (section->flags & SEC_CODE) == 0)
  3426. continue;
  3427. /* If this section is a link-once section that will be
  3428. discarded, then don't create any stubs. */
  3429. if (section->output_section == NULL
  3430. || section->output_section->owner != output_bfd)
  3431. continue;
  3432. /* Get the relocs. */
  3433. internal_relocs
  3434. = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
  3435. NULL, info->keep_memory);
  3436. if (internal_relocs == NULL)
  3437. goto error_ret_free_local;
  3438. /* Now examine each relocation. */
  3439. irela = internal_relocs;
  3440. irelaend = irela + section->reloc_count;
  3441. for (; irela < irelaend; irela++)
  3442. {
  3443. unsigned int r_type, r_indx;
  3444. enum elf_aarch64_stub_type stub_type;
  3445. struct elf_aarch64_stub_hash_entry *stub_entry;
  3446. asection *sym_sec;
  3447. bfd_vma sym_value;
  3448. bfd_vma destination;
  3449. struct elf_aarch64_link_hash_entry *hash;
  3450. const char *sym_name;
  3451. char *stub_name;
  3452. const asection *id_sec;
  3453. unsigned char st_type;
  3454. bfd_size_type len;
  3455. r_type = ELFNN_R_TYPE (irela->r_info);
  3456. r_indx = ELFNN_R_SYM (irela->r_info);
  3457. if (r_type >= (unsigned int) R_AARCH64_end)
  3458. {
  3459. bfd_set_error (bfd_error_bad_value);
  3460. error_ret_free_internal:
  3461. if (elf_section_data (section)->relocs == NULL)
  3462. free (internal_relocs);
  3463. goto error_ret_free_local;
  3464. }
  3465. /* Only look for stubs on unconditional branch and
  3466. branch and link instructions. */
  3467. if (r_type != (unsigned int) AARCH64_R (CALL26)
  3468. && r_type != (unsigned int) AARCH64_R (JUMP26))
  3469. continue;
  3470. /* Now determine the call target, its name, value,
  3471. section. */
  3472. sym_sec = NULL;
  3473. sym_value = 0;
  3474. destination = 0;
  3475. hash = NULL;
  3476. sym_name = NULL;
  3477. if (r_indx < symtab_hdr->sh_info)
  3478. {
  3479. /* It's a local symbol. */
  3480. Elf_Internal_Sym *sym;
  3481. Elf_Internal_Shdr *hdr;
  3482. if (local_syms == NULL)
  3483. {
  3484. local_syms
  3485. = (Elf_Internal_Sym *) symtab_hdr->contents;
  3486. if (local_syms == NULL)
  3487. local_syms
  3488. = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
  3489. symtab_hdr->sh_info, 0,
  3490. NULL, NULL, NULL);
  3491. if (local_syms == NULL)
  3492. goto error_ret_free_internal;
  3493. }
  3494. sym = local_syms + r_indx;
  3495. hdr = elf_elfsections (input_bfd)[sym->st_shndx];
  3496. sym_sec = hdr->bfd_section;
  3497. if (!sym_sec)
  3498. /* This is an undefined symbol. It can never
  3499. be resolved. */
  3500. continue;
  3501. if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
  3502. sym_value = sym->st_value;
  3503. destination = (sym_value + irela->r_addend
  3504. + sym_sec->output_offset
  3505. + sym_sec->output_section->vma);
  3506. st_type = ELF_ST_TYPE (sym->st_info);
  3507. sym_name
  3508. = bfd_elf_string_from_elf_section (input_bfd,
  3509. symtab_hdr->sh_link,
  3510. sym->st_name);
  3511. }
  3512. else
  3513. {
  3514. int e_indx;
  3515. e_indx = r_indx - symtab_hdr->sh_info;
  3516. hash = ((struct elf_aarch64_link_hash_entry *)
  3517. elf_sym_hashes (input_bfd)[e_indx]);
  3518. while (hash->root.root.type == bfd_link_hash_indirect
  3519. || hash->root.root.type == bfd_link_hash_warning)
  3520. hash = ((struct elf_aarch64_link_hash_entry *)
  3521. hash->root.root.u.i.link);
  3522. if (hash->root.root.type == bfd_link_hash_defined
  3523. || hash->root.root.type == bfd_link_hash_defweak)
  3524. {
  3525. struct elf_aarch64_link_hash_table *globals =
  3526. elf_aarch64_hash_table (info);
  3527. sym_sec = hash->root.root.u.def.section;
  3528. sym_value = hash->root.root.u.def.value;
  3529. /* For a destination in a shared library,
  3530. use the PLT stub as target address to
  3531. decide whether a branch stub is
  3532. needed. */
  3533. if (globals->root.splt != NULL && hash != NULL
  3534. && hash->root.plt.offset != (bfd_vma) - 1)
  3535. {
  3536. sym_sec = globals->root.splt;
  3537. sym_value = hash->root.plt.offset;
  3538. if (sym_sec->output_section != NULL)
  3539. destination = (sym_value
  3540. + sym_sec->output_offset
  3541. +
  3542. sym_sec->output_section->vma);
  3543. }
  3544. else if (sym_sec->output_section != NULL)
  3545. destination = (sym_value + irela->r_addend
  3546. + sym_sec->output_offset
  3547. + sym_sec->output_section->vma);
  3548. }
  3549. else if (hash->root.root.type == bfd_link_hash_undefined
  3550. || (hash->root.root.type
  3551. == bfd_link_hash_undefweak))
  3552. {
  3553. /* For a shared library, use the PLT stub as
  3554. target address to decide whether a long
  3555. branch stub is needed.
  3556. For absolute code, they cannot be handled. */
  3557. struct elf_aarch64_link_hash_table *globals =
  3558. elf_aarch64_hash_table (info);
  3559. if (globals->root.splt != NULL && hash != NULL
  3560. && hash->root.plt.offset != (bfd_vma) - 1)
  3561. {
  3562. sym_sec = globals->root.splt;
  3563. sym_value = hash->root.plt.offset;
  3564. if (sym_sec->output_section != NULL)
  3565. destination = (sym_value
  3566. + sym_sec->output_offset
  3567. +
  3568. sym_sec->output_section->vma);
  3569. }
  3570. else
  3571. continue;
  3572. }
  3573. else
  3574. {
  3575. bfd_set_error (bfd_error_bad_value);
  3576. goto error_ret_free_internal;
  3577. }
  3578. st_type = ELF_ST_TYPE (hash->root.type);
  3579. sym_name = hash->root.root.root.string;
  3580. }
  3581. /* Determine what (if any) linker stub is needed. */
  3582. stub_type = aarch64_type_of_stub
  3583. (info, section, irela, sym_sec, st_type, hash, destination);
  3584. if (stub_type == aarch64_stub_none)
  3585. continue;
  3586. /* Support for grouping stub sections. */
  3587. id_sec = htab->stub_group[section->id].link_sec;
  3588. /* Get the name of this stub. */
  3589. stub_name = elfNN_aarch64_stub_name (id_sec, sym_sec, hash,
  3590. irela);
  3591. if (!stub_name)
  3592. goto error_ret_free_internal;
  3593. stub_entry =
  3594. aarch64_stub_hash_lookup (&htab->stub_hash_table,
  3595. stub_name, FALSE, FALSE);
  3596. if (stub_entry != NULL)
  3597. {
  3598. /* The proper stub has already been created. */
  3599. free (stub_name);
  3600. continue;
  3601. }
  3602. stub_entry = _bfd_aarch64_add_stub_entry_in_group
  3603. (stub_name, section, htab);
  3604. if (stub_entry == NULL)
  3605. {
  3606. free (stub_name);
  3607. goto error_ret_free_internal;
  3608. }
  3609. stub_entry->target_value = sym_value;
  3610. stub_entry->target_section = sym_sec;
  3611. stub_entry->stub_type = stub_type;
  3612. stub_entry->h = hash;
  3613. stub_entry->st_type = st_type;
  3614. if (sym_name == NULL)
  3615. sym_name = "unnamed";
  3616. len = sizeof (STUB_ENTRY_NAME) + strlen (sym_name);
  3617. stub_entry->output_name = bfd_alloc (htab->stub_bfd, len);
  3618. if (stub_entry->output_name == NULL)
  3619. {
  3620. free (stub_name);
  3621. goto error_ret_free_internal;
  3622. }
  3623. snprintf (stub_entry->output_name, len, STUB_ENTRY_NAME,
  3624. sym_name);
  3625. stub_changed = TRUE;
  3626. }
  3627. /* We're done with the internal relocs, free them. */
  3628. if (elf_section_data (section)->relocs == NULL)
  3629. free (internal_relocs);
  3630. }
  3631. }
  3632. if (!stub_changed)
  3633. break;
  3634. _bfd_aarch64_resize_stubs (htab);
  3635. /* Ask the linker to do its stuff. */
  3636. (*htab->layout_sections_again) ();
  3637. stub_changed = FALSE;
  3638. }
  3639. return TRUE;
  3640. error_ret_free_local:
  3641. return FALSE;
  3642. }
  3643. /* Build all the stubs associated with the current output file. The
  3644. stubs are kept in a hash table attached to the main linker hash
  3645. table. We also set up the .plt entries for statically linked PIC
  3646. functions here. This function is called via aarch64_elf_finish in the
  3647. linker. */
  3648. bfd_boolean
  3649. elfNN_aarch64_build_stubs (struct bfd_link_info *info)
  3650. {
  3651. asection *stub_sec;
  3652. struct bfd_hash_table *table;
  3653. struct elf_aarch64_link_hash_table *htab;
  3654. htab = elf_aarch64_hash_table (info);
  3655. for (stub_sec = htab->stub_bfd->sections;
  3656. stub_sec != NULL; stub_sec = stub_sec->next)
  3657. {
  3658. bfd_size_type size;
  3659. /* Ignore non-stub sections. */
  3660. if (!strstr (stub_sec->name, STUB_SUFFIX))
  3661. continue;
  3662. /* Allocate memory to hold the linker stubs. */
  3663. size = stub_sec->size;
  3664. stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
  3665. if (stub_sec->contents == NULL && size != 0)
  3666. return FALSE;
  3667. stub_sec->size = 0;
  3668. bfd_putl32 (0x14000000 | (size >> 2), stub_sec->contents);
  3669. stub_sec->size += 4;
  3670. }
  3671. /* Build the stubs as directed by the stub hash table. */
  3672. table = &htab->stub_hash_table;
  3673. bfd_hash_traverse (table, aarch64_build_one_stub, info);
  3674. return TRUE;
  3675. }
  3676. /* Add an entry to the code/data map for section SEC. */
  3677. static void
  3678. elfNN_aarch64_section_map_add (asection *sec, char type, bfd_vma vma)
  3679. {
  3680. struct _aarch64_elf_section_data *sec_data =
  3681. elf_aarch64_section_data (sec);
  3682. unsigned int newidx;
  3683. if (sec_data->map == NULL)
  3684. {
  3685. sec_data->map = bfd_malloc (sizeof (elf_aarch64_section_map));
  3686. sec_data->mapcount = 0;
  3687. sec_data->mapsize = 1;
  3688. }
  3689. newidx = sec_data->mapcount++;
  3690. if (sec_data->mapcount > sec_data->mapsize)
  3691. {
  3692. sec_data->mapsize *= 2;
  3693. sec_data->map = bfd_realloc_or_free
  3694. (sec_data->map, sec_data->mapsize * sizeof (elf_aarch64_section_map));
  3695. }
  3696. if (sec_data->map)
  3697. {
  3698. sec_data->map[newidx].vma = vma;
  3699. sec_data->map[newidx].type = type;
  3700. }
  3701. }
  3702. /* Initialise maps of insn/data for input BFDs. */
  3703. void
  3704. bfd_elfNN_aarch64_init_maps (bfd *abfd)
  3705. {
  3706. Elf_Internal_Sym *isymbuf;
  3707. Elf_Internal_Shdr *hdr;
  3708. unsigned int i, localsyms;
  3709. /* Make sure that we are dealing with an AArch64 elf binary. */
  3710. if (!is_aarch64_elf (abfd))
  3711. return;
  3712. if ((abfd->flags & DYNAMIC) != 0)
  3713. return;
  3714. hdr = &elf_symtab_hdr (abfd);
  3715. localsyms = hdr->sh_info;
  3716. /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
  3717. should contain the number of local symbols, which should come before any
  3718. global symbols. Mapping symbols are always local. */
  3719. isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL, NULL);
  3720. /* No internal symbols read? Skip this BFD. */
  3721. if (isymbuf == NULL)
  3722. return;
  3723. for (i = 0; i < localsyms; i++)
  3724. {
  3725. Elf_Internal_Sym *isym = &isymbuf[i];
  3726. asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  3727. const char *name;
  3728. if (sec != NULL && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
  3729. {
  3730. name = bfd_elf_string_from_elf_section (abfd,
  3731. hdr->sh_link,
  3732. isym->st_name);
  3733. if (bfd_is_aarch64_special_symbol_name
  3734. (name, BFD_AARCH64_SPECIAL_SYM_TYPE_MAP))
  3735. elfNN_aarch64_section_map_add (sec, name[1], isym->st_value);
  3736. }
  3737. }
  3738. }
  3739. /* Set option values needed during linking. */
  3740. void
  3741. bfd_elfNN_aarch64_set_options (struct bfd *output_bfd,
  3742. struct bfd_link_info *link_info,
  3743. int no_enum_warn,
  3744. int no_wchar_warn, int pic_veneer,
  3745. int fix_erratum_835769,
  3746. int fix_erratum_843419)
  3747. {
  3748. struct elf_aarch64_link_hash_table *globals;
  3749. globals = elf_aarch64_hash_table (link_info);
  3750. globals->pic_veneer = pic_veneer;
  3751. globals->fix_erratum_835769 = fix_erratum_835769;
  3752. globals->fix_erratum_843419 = fix_erratum_843419;
  3753. globals->fix_erratum_843419_adr = TRUE;
  3754. BFD_ASSERT (is_aarch64_elf (output_bfd));
  3755. elf_aarch64_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
  3756. elf_aarch64_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
  3757. }
  3758. static bfd_vma
  3759. aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
  3760. struct elf_aarch64_link_hash_table
  3761. *globals, struct bfd_link_info *info,
  3762. bfd_vma value, bfd *output_bfd,
  3763. bfd_boolean *unresolved_reloc_p)
  3764. {
  3765. bfd_vma off = (bfd_vma) - 1;
  3766. asection *basegot = globals->root.sgot;
  3767. bfd_boolean dyn = globals->root.dynamic_sections_created;
  3768. if (h != NULL)
  3769. {
  3770. BFD_ASSERT (basegot != NULL);
  3771. off = h->got.offset;
  3772. BFD_ASSERT (off != (bfd_vma) - 1);
  3773. if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
  3774. || (bfd_link_pic (info)
  3775. && SYMBOL_REFERENCES_LOCAL (info, h))
  3776. || (ELF_ST_VISIBILITY (h->other)
  3777. && h->root.type == bfd_link_hash_undefweak))
  3778. {
  3779. /* This is actually a static link, or it is a -Bsymbolic link
  3780. and the symbol is defined locally. We must initialize this
  3781. entry in the global offset table. Since the offset must
  3782. always be a multiple of 8 (4 in the case of ILP32), we use
  3783. the least significant bit to record whether we have
  3784. initialized it already.
  3785. When doing a dynamic link, we create a .rel(a).got relocation
  3786. entry to initialize the value. This is done in the
  3787. finish_dynamic_symbol routine. */
  3788. if ((off & 1) != 0)
  3789. off &= ~1;
  3790. else
  3791. {
  3792. bfd_put_NN (output_bfd, value, basegot->contents + off);
  3793. h->got.offset |= 1;
  3794. }
  3795. }
  3796. else
  3797. *unresolved_reloc_p = FALSE;
  3798. off = off + basegot->output_section->vma + basegot->output_offset;
  3799. }
  3800. return off;
  3801. }
  3802. /* Change R_TYPE to a more efficient access model where possible,
  3803. return the new reloc type. */
  3804. static bfd_reloc_code_real_type
  3805. aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
  3806. struct elf_link_hash_entry *h)
  3807. {
  3808. bfd_boolean is_local = h == NULL;
  3809. switch (r_type)
  3810. {
  3811. case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
  3812. case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
  3813. return (is_local
  3814. ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
  3815. : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
  3816. case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
  3817. return (is_local
  3818. ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
  3819. : r_type);
  3820. case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
  3821. return (is_local
  3822. ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
  3823. : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
  3824. case BFD_RELOC_AARCH64_TLSDESC_LDR:
  3825. return (is_local
  3826. ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
  3827. : BFD_RELOC_AARCH64_NONE);
  3828. case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
  3829. return (is_local
  3830. ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
  3831. : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC);
  3832. case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
  3833. return (is_local
  3834. ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
  3835. : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1);
  3836. case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
  3837. case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
  3838. return (is_local
  3839. ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
  3840. : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
  3841. case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
  3842. return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
  3843. case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
  3844. return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
  3845. case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
  3846. return r_type;
  3847. case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
  3848. return (is_local
  3849. ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
  3850. : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
  3851. case BFD_RELOC_AARCH64_TLSDESC_ADD:
  3852. case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
  3853. case BFD_RELOC_AARCH64_TLSDESC_CALL:
  3854. /* Instructions with these relocations will become NOPs. */
  3855. return BFD_RELOC_AARCH64_NONE;
  3856. case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
  3857. case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
  3858. case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
  3859. return is_local ? BFD_RELOC_AARCH64_NONE : r_type;
  3860. #if ARCH_SIZE == 64
  3861. case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
  3862. return is_local
  3863. ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
  3864. : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC;
  3865. case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
  3866. return is_local
  3867. ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
  3868. : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1;
  3869. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
  3870. return is_local
  3871. ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
  3872. : r_type;
  3873. #endif
  3874. default:
  3875. break;
  3876. }
  3877. return r_type;
  3878. }
  3879. static unsigned int
  3880. aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
  3881. {
  3882. switch (r_type)
  3883. {
  3884. case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
  3885. case BFD_RELOC_AARCH64_GOT_LD_PREL19:
  3886. case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
  3887. case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
  3888. case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
  3889. case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
  3890. case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
  3891. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
  3892. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
  3893. return GOT_NORMAL;
  3894. case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
  3895. case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
  3896. case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
  3897. case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
  3898. case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
  3899. case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
  3900. case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
  3901. case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
  3902. return GOT_TLS_GD;
  3903. case BFD_RELOC_AARCH64_TLSDESC_ADD:
  3904. case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
  3905. case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
  3906. case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
  3907. case BFD_RELOC_AARCH64_TLSDESC_CALL:
  3908. case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
  3909. case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
  3910. case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
  3911. case BFD_RELOC_AARCH64_TLSDESC_LDR:
  3912. case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
  3913. case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
  3914. return GOT_TLSDESC_GD;
  3915. case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
  3916. case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
  3917. case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
  3918. case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
  3919. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
  3920. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
  3921. return GOT_TLS_IE;
  3922. default:
  3923. break;
  3924. }
  3925. return GOT_UNKNOWN;
  3926. }
  3927. static bfd_boolean
  3928. aarch64_can_relax_tls (bfd *input_bfd,
  3929. struct bfd_link_info *info,
  3930. bfd_reloc_code_real_type r_type,
  3931. struct elf_link_hash_entry *h,
  3932. unsigned long r_symndx)
  3933. {
  3934. unsigned int symbol_got_type;
  3935. unsigned int reloc_got_type;
  3936. if (! IS_AARCH64_TLS_RELAX_RELOC (r_type))
  3937. return FALSE;
  3938. symbol_got_type = elfNN_aarch64_symbol_got_type (h, input_bfd, r_symndx);
  3939. reloc_got_type = aarch64_reloc_got_type (r_type);
  3940. if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type))
  3941. return TRUE;
  3942. if (bfd_link_pic (info))
  3943. return FALSE;
  3944. if (h && h->root.type == bfd_link_hash_undefweak)
  3945. return FALSE;
  3946. return TRUE;
  3947. }
  3948. /* Given the relocation code R_TYPE, return the relaxed bfd reloc
  3949. enumerator. */
  3950. static bfd_reloc_code_real_type
  3951. aarch64_tls_transition (bfd *input_bfd,
  3952. struct bfd_link_info *info,
  3953. unsigned int r_type,
  3954. struct elf_link_hash_entry *h,
  3955. unsigned long r_symndx)
  3956. {
  3957. bfd_reloc_code_real_type bfd_r_type
  3958. = elfNN_aarch64_bfd_reloc_from_type (r_type);
  3959. if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
  3960. return bfd_r_type;
  3961. return aarch64_tls_transition_without_check (bfd_r_type, h);
  3962. }
  3963. /* Return the base VMA address which should be subtracted from real addresses
  3964. when resolving R_AARCH64_TLS_DTPREL relocation. */
  3965. static bfd_vma
  3966. dtpoff_base (struct bfd_link_info *info)
  3967. {
  3968. /* If tls_sec is NULL, we should have signalled an error already. */
  3969. BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL);
  3970. return elf_hash_table (info)->tls_sec->vma;
  3971. }
  3972. /* Return the base VMA address which should be subtracted from real addresses
  3973. when resolving R_AARCH64_TLS_GOTTPREL64 relocations. */
  3974. static bfd_vma
  3975. tpoff_base (struct bfd_link_info *info)
  3976. {
  3977. struct elf_link_hash_table *htab = elf_hash_table (info);
  3978. /* If tls_sec is NULL, we should have signalled an error already. */
  3979. BFD_ASSERT (htab->tls_sec != NULL);
  3980. bfd_vma base = align_power ((bfd_vma) TCB_SIZE,
  3981. htab->tls_sec->alignment_power);
  3982. return htab->tls_sec->vma - base;
  3983. }
  3984. static bfd_vma *
  3985. symbol_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
  3986. unsigned long r_symndx)
  3987. {
  3988. /* Calculate the address of the GOT entry for symbol
  3989. referred to in h. */
  3990. if (h != NULL)
  3991. return &h->got.offset;
  3992. else
  3993. {
  3994. /* local symbol */
  3995. struct elf_aarch64_local_symbol *l;
  3996. l = elf_aarch64_locals (input_bfd);
  3997. return &l[r_symndx].got_offset;
  3998. }
  3999. }
  4000. static void
  4001. symbol_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
  4002. unsigned long r_symndx)
  4003. {
  4004. bfd_vma *p;
  4005. p = symbol_got_offset_ref (input_bfd, h, r_symndx);
  4006. *p |= 1;
  4007. }
  4008. static int
  4009. symbol_got_offset_mark_p (bfd *input_bfd, struct elf_link_hash_entry *h,
  4010. unsigned long r_symndx)
  4011. {
  4012. bfd_vma value;
  4013. value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
  4014. return value & 1;
  4015. }
  4016. static bfd_vma
  4017. symbol_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
  4018. unsigned long r_symndx)
  4019. {
  4020. bfd_vma value;
  4021. value = * symbol_got_offset_ref (input_bfd, h, r_symndx);
  4022. value &= ~1;
  4023. return value;
  4024. }
  4025. static bfd_vma *
  4026. symbol_tlsdesc_got_offset_ref (bfd *input_bfd, struct elf_link_hash_entry *h,
  4027. unsigned long r_symndx)
  4028. {
  4029. /* Calculate the address of the GOT entry for symbol
  4030. referred to in h. */
  4031. if (h != NULL)
  4032. {
  4033. struct elf_aarch64_link_hash_entry *eh;
  4034. eh = (struct elf_aarch64_link_hash_entry *) h;
  4035. return &eh->tlsdesc_got_jump_table_offset;
  4036. }
  4037. else
  4038. {
  4039. /* local symbol */
  4040. struct elf_aarch64_local_symbol *l;
  4041. l = elf_aarch64_locals (input_bfd);
  4042. return &l[r_symndx].tlsdesc_got_jump_table_offset;
  4043. }
  4044. }
  4045. static void
  4046. symbol_tlsdesc_got_offset_mark (bfd *input_bfd, struct elf_link_hash_entry *h,
  4047. unsigned long r_symndx)
  4048. {
  4049. bfd_vma *p;
  4050. p = symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
  4051. *p |= 1;
  4052. }
  4053. static int
  4054. symbol_tlsdesc_got_offset_mark_p (bfd *input_bfd,
  4055. struct elf_link_hash_entry *h,
  4056. unsigned long r_symndx)
  4057. {
  4058. bfd_vma value;
  4059. value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
  4060. return value & 1;
  4061. }
  4062. static bfd_vma
  4063. symbol_tlsdesc_got_offset (bfd *input_bfd, struct elf_link_hash_entry *h,
  4064. unsigned long r_symndx)
  4065. {
  4066. bfd_vma value;
  4067. value = * symbol_tlsdesc_got_offset_ref (input_bfd, h, r_symndx);
  4068. value &= ~1;
  4069. return value;
  4070. }
  4071. /* Data for make_branch_to_erratum_835769_stub(). */
  4072. struct erratum_835769_branch_to_stub_data
  4073. {
  4074. struct bfd_link_info *info;
  4075. asection *output_section;
  4076. bfd_byte *contents;
  4077. };
  4078. /* Helper to insert branches to erratum 835769 stubs in the right
  4079. places for a particular section. */
  4080. static bfd_boolean
  4081. make_branch_to_erratum_835769_stub (struct bfd_hash_entry *gen_entry,
  4082. void *in_arg)
  4083. {
  4084. struct elf_aarch64_stub_hash_entry *stub_entry;
  4085. struct erratum_835769_branch_to_stub_data *data;
  4086. bfd_byte *contents;
  4087. unsigned long branch_insn = 0;
  4088. bfd_vma veneered_insn_loc, veneer_entry_loc;
  4089. bfd_signed_vma branch_offset;
  4090. unsigned int target;
  4091. bfd *abfd;
  4092. stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
  4093. data = (struct erratum_835769_branch_to_stub_data *) in_arg;
  4094. if (stub_entry->target_section != data->output_section
  4095. || stub_entry->stub_type != aarch64_stub_erratum_835769_veneer)
  4096. return TRUE;
  4097. contents = data->contents;
  4098. veneered_insn_loc = stub_entry->target_section->output_section->vma
  4099. + stub_entry->target_section->output_offset
  4100. + stub_entry->target_value;
  4101. veneer_entry_loc = stub_entry->stub_sec->output_section->vma
  4102. + stub_entry->stub_sec->output_offset
  4103. + stub_entry->stub_offset;
  4104. branch_offset = veneer_entry_loc - veneered_insn_loc;
  4105. abfd = stub_entry->target_section->owner;
  4106. if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
  4107. (*_bfd_error_handler)
  4108. (_("%B: error: Erratum 835769 stub out "
  4109. "of range (input file too large)"), abfd);
  4110. target = stub_entry->target_value;
  4111. branch_insn = 0x14000000;
  4112. branch_offset >>= 2;
  4113. branch_offset &= 0x3ffffff;
  4114. branch_insn |= branch_offset;
  4115. bfd_putl32 (branch_insn, &contents[target]);
  4116. return TRUE;
  4117. }
  4118. static bfd_boolean
  4119. _bfd_aarch64_erratum_843419_branch_to_stub (struct bfd_hash_entry *gen_entry,
  4120. void *in_arg)
  4121. {
  4122. struct elf_aarch64_stub_hash_entry *stub_entry
  4123. = (struct elf_aarch64_stub_hash_entry *) gen_entry;
  4124. struct erratum_835769_branch_to_stub_data *data
  4125. = (struct erratum_835769_branch_to_stub_data *) in_arg;
  4126. struct bfd_link_info *info;
  4127. struct elf_aarch64_link_hash_table *htab;
  4128. bfd_byte *contents;
  4129. asection *section;
  4130. bfd *abfd;
  4131. bfd_vma place;
  4132. uint32_t insn;
  4133. info = data->info;
  4134. contents = data->contents;
  4135. section = data->output_section;
  4136. htab = elf_aarch64_hash_table (info);
  4137. if (stub_entry->target_section != section
  4138. || stub_entry->stub_type != aarch64_stub_erratum_843419_veneer)
  4139. return TRUE;
  4140. insn = bfd_getl32 (contents + stub_entry->target_value);
  4141. bfd_putl32 (insn,
  4142. stub_entry->stub_sec->contents + stub_entry->stub_offset);
  4143. place = (section->output_section->vma + section->output_offset
  4144. + stub_entry->adrp_offset);
  4145. insn = bfd_getl32 (contents + stub_entry->adrp_offset);
  4146. if ((insn & AARCH64_ADRP_OP_MASK) != AARCH64_ADRP_OP)
  4147. abort ();
  4148. bfd_signed_vma imm =
  4149. (_bfd_aarch64_sign_extend
  4150. ((bfd_vma) _bfd_aarch64_decode_adrp_imm (insn) << 12, 33)
  4151. - (place & 0xfff));
  4152. if (htab->fix_erratum_843419_adr
  4153. && (imm >= AARCH64_MIN_ADRP_IMM && imm <= AARCH64_MAX_ADRP_IMM))
  4154. {
  4155. insn = (_bfd_aarch64_reencode_adr_imm (AARCH64_ADR_OP, imm)
  4156. | AARCH64_RT (insn));
  4157. bfd_putl32 (insn, contents + stub_entry->adrp_offset);
  4158. }
  4159. else
  4160. {
  4161. bfd_vma veneered_insn_loc;
  4162. bfd_vma veneer_entry_loc;
  4163. bfd_signed_vma branch_offset;
  4164. uint32_t branch_insn;
  4165. veneered_insn_loc = stub_entry->target_section->output_section->vma
  4166. + stub_entry->target_section->output_offset
  4167. + stub_entry->target_value;
  4168. veneer_entry_loc = stub_entry->stub_sec->output_section->vma
  4169. + stub_entry->stub_sec->output_offset
  4170. + stub_entry->stub_offset;
  4171. branch_offset = veneer_entry_loc - veneered_insn_loc;
  4172. abfd = stub_entry->target_section->owner;
  4173. if (!aarch64_valid_branch_p (veneer_entry_loc, veneered_insn_loc))
  4174. (*_bfd_error_handler)
  4175. (_("%B: error: Erratum 843419 stub out "
  4176. "of range (input file too large)"), abfd);
  4177. branch_insn = 0x14000000;
  4178. branch_offset >>= 2;
  4179. branch_offset &= 0x3ffffff;
  4180. branch_insn |= branch_offset;
  4181. bfd_putl32 (branch_insn, contents + stub_entry->target_value);
  4182. }
  4183. return TRUE;
  4184. }
  4185. static bfd_boolean
  4186. elfNN_aarch64_write_section (bfd *output_bfd ATTRIBUTE_UNUSED,
  4187. struct bfd_link_info *link_info,
  4188. asection *sec,
  4189. bfd_byte *contents)
  4190. {
  4191. struct elf_aarch64_link_hash_table *globals =
  4192. elf_aarch64_hash_table (link_info);
  4193. if (globals == NULL)
  4194. return FALSE;
  4195. /* Fix code to point to erratum 835769 stubs. */
  4196. if (globals->fix_erratum_835769)
  4197. {
  4198. struct erratum_835769_branch_to_stub_data data;
  4199. data.info = link_info;
  4200. data.output_section = sec;
  4201. data.contents = contents;
  4202. bfd_hash_traverse (&globals->stub_hash_table,
  4203. make_branch_to_erratum_835769_stub, &data);
  4204. }
  4205. if (globals->fix_erratum_843419)
  4206. {
  4207. struct erratum_835769_branch_to_stub_data data;
  4208. data.info = link_info;
  4209. data.output_section = sec;
  4210. data.contents = contents;
  4211. bfd_hash_traverse (&globals->stub_hash_table,
  4212. _bfd_aarch64_erratum_843419_branch_to_stub, &data);
  4213. }
  4214. return FALSE;
  4215. }
  4216. /* Perform a relocation as part of a final link. */
  4217. static bfd_reloc_status_type
  4218. elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
  4219. bfd *input_bfd,
  4220. bfd *output_bfd,
  4221. asection *input_section,
  4222. bfd_byte *contents,
  4223. Elf_Internal_Rela *rel,
  4224. bfd_vma value,
  4225. struct bfd_link_info *info,
  4226. asection *sym_sec,
  4227. struct elf_link_hash_entry *h,
  4228. bfd_boolean *unresolved_reloc_p,
  4229. bfd_boolean save_addend,
  4230. bfd_vma *saved_addend,
  4231. Elf_Internal_Sym *sym)
  4232. {
  4233. Elf_Internal_Shdr *symtab_hdr;
  4234. unsigned int r_type = howto->type;
  4235. bfd_reloc_code_real_type bfd_r_type
  4236. = elfNN_aarch64_bfd_reloc_from_howto (howto);
  4237. bfd_reloc_code_real_type new_bfd_r_type;
  4238. unsigned long r_symndx;
  4239. bfd_byte *hit_data = contents + rel->r_offset;
  4240. bfd_vma place, off;
  4241. bfd_signed_vma signed_addend;
  4242. struct elf_aarch64_link_hash_table *globals;
  4243. bfd_boolean weak_undef_p;
  4244. asection *base_got;
  4245. globals = elf_aarch64_hash_table (info);
  4246. symtab_hdr = &elf_symtab_hdr (input_bfd);
  4247. BFD_ASSERT (is_aarch64_elf (input_bfd));
  4248. r_symndx = ELFNN_R_SYM (rel->r_info);
  4249. /* It is possible to have linker relaxations on some TLS access
  4250. models. Update our information here. */
  4251. new_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type, h, r_symndx);
  4252. if (new_bfd_r_type != bfd_r_type)
  4253. {
  4254. bfd_r_type = new_bfd_r_type;
  4255. howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
  4256. BFD_ASSERT (howto != NULL);
  4257. r_type = howto->type;
  4258. }
  4259. place = input_section->output_section->vma
  4260. + input_section->output_offset + rel->r_offset;
  4261. /* Get addend, accumulating the addend for consecutive relocs
  4262. which refer to the same offset. */
  4263. signed_addend = saved_addend ? *saved_addend : 0;
  4264. signed_addend += rel->r_addend;
  4265. weak_undef_p = (h ? h->root.type == bfd_link_hash_undefweak
  4266. : bfd_is_und_section (sym_sec));
  4267. /* Since STT_GNU_IFUNC symbol must go through PLT, we handle
  4268. it here if it is defined in a non-shared object. */
  4269. if (h != NULL
  4270. && h->type == STT_GNU_IFUNC
  4271. && h->def_regular)
  4272. {
  4273. asection *plt;
  4274. const char *name;
  4275. bfd_vma addend = 0;
  4276. if ((input_section->flags & SEC_ALLOC) == 0
  4277. || h->plt.offset == (bfd_vma) -1)
  4278. abort ();
  4279. /* STT_GNU_IFUNC symbol must go through PLT. */
  4280. plt = globals->root.splt ? globals->root.splt : globals->root.iplt;
  4281. value = (plt->output_section->vma + plt->output_offset + h->plt.offset);
  4282. switch (bfd_r_type)
  4283. {
  4284. default:
  4285. if (h->root.root.string)
  4286. name = h->root.root.string;
  4287. else
  4288. name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
  4289. NULL);
  4290. (*_bfd_error_handler)
  4291. (_("%B: relocation %s against STT_GNU_IFUNC "
  4292. "symbol `%s' isn't handled by %s"), input_bfd,
  4293. howto->name, name, __FUNCTION__);
  4294. bfd_set_error (bfd_error_bad_value);
  4295. return FALSE;
  4296. case BFD_RELOC_AARCH64_NN:
  4297. if (rel->r_addend != 0)
  4298. {
  4299. if (h->root.root.string)
  4300. name = h->root.root.string;
  4301. else
  4302. name = bfd_elf_sym_name (input_bfd, symtab_hdr,
  4303. sym, NULL);
  4304. (*_bfd_error_handler)
  4305. (_("%B: relocation %s against STT_GNU_IFUNC "
  4306. "symbol `%s' has non-zero addend: %d"),
  4307. input_bfd, howto->name, name, rel->r_addend);
  4308. bfd_set_error (bfd_error_bad_value);
  4309. return FALSE;
  4310. }
  4311. /* Generate dynamic relocation only when there is a
  4312. non-GOT reference in a shared object. */
  4313. if (bfd_link_pic (info) && h->non_got_ref)
  4314. {
  4315. Elf_Internal_Rela outrel;
  4316. asection *sreloc;
  4317. /* Need a dynamic relocation to get the real function
  4318. address. */
  4319. outrel.r_offset = _bfd_elf_section_offset (output_bfd,
  4320. info,
  4321. input_section,
  4322. rel->r_offset);
  4323. if (outrel.r_offset == (bfd_vma) -1
  4324. || outrel.r_offset == (bfd_vma) -2)
  4325. abort ();
  4326. outrel.r_offset += (input_section->output_section->vma
  4327. + input_section->output_offset);
  4328. if (h->dynindx == -1
  4329. || h->forced_local
  4330. || bfd_link_executable (info))
  4331. {
  4332. /* This symbol is resolved locally. */
  4333. outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
  4334. outrel.r_addend = (h->root.u.def.value
  4335. + h->root.u.def.section->output_section->vma
  4336. + h->root.u.def.section->output_offset);
  4337. }
  4338. else
  4339. {
  4340. outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
  4341. outrel.r_addend = 0;
  4342. }
  4343. sreloc = globals->root.irelifunc;
  4344. elf_append_rela (output_bfd, sreloc, &outrel);
  4345. /* If this reloc is against an external symbol, we
  4346. do not want to fiddle with the addend. Otherwise,
  4347. we need to include the symbol value so that it
  4348. becomes an addend for the dynamic reloc. For an
  4349. internal symbol, we have updated addend. */
  4350. return bfd_reloc_ok;
  4351. }
  4352. /* FALLTHROUGH */
  4353. case BFD_RELOC_AARCH64_CALL26:
  4354. case BFD_RELOC_AARCH64_JUMP26:
  4355. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4356. signed_addend,
  4357. weak_undef_p);
  4358. return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
  4359. howto, value);
  4360. case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
  4361. case BFD_RELOC_AARCH64_GOT_LD_PREL19:
  4362. case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
  4363. case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
  4364. case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
  4365. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
  4366. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
  4367. case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
  4368. case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
  4369. base_got = globals->root.sgot;
  4370. off = h->got.offset;
  4371. if (base_got == NULL)
  4372. abort ();
  4373. if (off == (bfd_vma) -1)
  4374. {
  4375. bfd_vma plt_index;
  4376. /* We can't use h->got.offset here to save state, or
  4377. even just remember the offset, as finish_dynamic_symbol
  4378. would use that as offset into .got. */
  4379. if (globals->root.splt != NULL)
  4380. {
  4381. plt_index = ((h->plt.offset - globals->plt_header_size) /
  4382. globals->plt_entry_size);
  4383. off = (plt_index + 3) * GOT_ENTRY_SIZE;
  4384. base_got = globals->root.sgotplt;
  4385. }
  4386. else
  4387. {
  4388. plt_index = h->plt.offset / globals->plt_entry_size;
  4389. off = plt_index * GOT_ENTRY_SIZE;
  4390. base_got = globals->root.igotplt;
  4391. }
  4392. if (h->dynindx == -1
  4393. || h->forced_local
  4394. || info->symbolic)
  4395. {
  4396. /* This references the local definition. We must
  4397. initialize this entry in the global offset table.
  4398. Since the offset must always be a multiple of 8,
  4399. we use the least significant bit to record
  4400. whether we have initialized it already.
  4401. When doing a dynamic link, we create a .rela.got
  4402. relocation entry to initialize the value. This
  4403. is done in the finish_dynamic_symbol routine. */
  4404. if ((off & 1) != 0)
  4405. off &= ~1;
  4406. else
  4407. {
  4408. bfd_put_NN (output_bfd, value,
  4409. base_got->contents + off);
  4410. /* Note that this is harmless as -1 | 1 still is -1. */
  4411. h->got.offset |= 1;
  4412. }
  4413. }
  4414. value = (base_got->output_section->vma
  4415. + base_got->output_offset + off);
  4416. }
  4417. else
  4418. value = aarch64_calculate_got_entry_vma (h, globals, info,
  4419. value, output_bfd,
  4420. unresolved_reloc_p);
  4421. switch (bfd_r_type)
  4422. {
  4423. case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
  4424. case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
  4425. addend = (globals->root.sgot->output_section->vma
  4426. + globals->root.sgot->output_offset);
  4427. break;
  4428. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
  4429. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
  4430. case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
  4431. value = (value - globals->root.sgot->output_section->vma
  4432. - globals->root.sgot->output_offset);
  4433. default:
  4434. break;
  4435. }
  4436. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4437. addend, weak_undef_p);
  4438. return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type, howto, value);
  4439. case BFD_RELOC_AARCH64_ADD_LO12:
  4440. case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
  4441. break;
  4442. }
  4443. }
  4444. switch (bfd_r_type)
  4445. {
  4446. case BFD_RELOC_AARCH64_NONE:
  4447. case BFD_RELOC_AARCH64_TLSDESC_ADD:
  4448. case BFD_RELOC_AARCH64_TLSDESC_CALL:
  4449. case BFD_RELOC_AARCH64_TLSDESC_LDR:
  4450. *unresolved_reloc_p = FALSE;
  4451. return bfd_reloc_ok;
  4452. case BFD_RELOC_AARCH64_NN:
  4453. /* When generating a shared object or relocatable executable, these
  4454. relocations are copied into the output file to be resolved at
  4455. run time. */
  4456. if (((bfd_link_pic (info) == TRUE)
  4457. || globals->root.is_relocatable_executable)
  4458. && (input_section->flags & SEC_ALLOC)
  4459. && (h == NULL
  4460. || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  4461. || h->root.type != bfd_link_hash_undefweak))
  4462. {
  4463. Elf_Internal_Rela outrel;
  4464. bfd_byte *loc;
  4465. bfd_boolean skip, relocate;
  4466. asection *sreloc;
  4467. *unresolved_reloc_p = FALSE;
  4468. skip = FALSE;
  4469. relocate = FALSE;
  4470. outrel.r_addend = signed_addend;
  4471. outrel.r_offset =
  4472. _bfd_elf_section_offset (output_bfd, info, input_section,
  4473. rel->r_offset);
  4474. if (outrel.r_offset == (bfd_vma) - 1)
  4475. skip = TRUE;
  4476. else if (outrel.r_offset == (bfd_vma) - 2)
  4477. {
  4478. skip = TRUE;
  4479. relocate = TRUE;
  4480. }
  4481. outrel.r_offset += (input_section->output_section->vma
  4482. + input_section->output_offset);
  4483. if (skip)
  4484. memset (&outrel, 0, sizeof outrel);
  4485. else if (h != NULL
  4486. && h->dynindx != -1
  4487. && (!bfd_link_pic (info)
  4488. || !SYMBOLIC_BIND (info, h)
  4489. || !h->def_regular))
  4490. outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type);
  4491. else
  4492. {
  4493. int symbol;
  4494. /* On SVR4-ish systems, the dynamic loader cannot
  4495. relocate the text and data segments independently,
  4496. so the symbol does not matter. */
  4497. symbol = 0;
  4498. outrel.r_info = ELFNN_R_INFO (symbol, AARCH64_R (RELATIVE));
  4499. outrel.r_addend += value;
  4500. }
  4501. sreloc = elf_section_data (input_section)->sreloc;
  4502. if (sreloc == NULL || sreloc->contents == NULL)
  4503. return bfd_reloc_notsupported;
  4504. loc = sreloc->contents + sreloc->reloc_count++ * RELOC_SIZE (globals);
  4505. bfd_elfNN_swap_reloca_out (output_bfd, &outrel, loc);
  4506. if (sreloc->reloc_count * RELOC_SIZE (globals) > sreloc->size)
  4507. {
  4508. /* Sanity to check that we have previously allocated
  4509. sufficient space in the relocation section for the
  4510. number of relocations we actually want to emit. */
  4511. abort ();
  4512. }
  4513. /* If this reloc is against an external symbol, we do not want to
  4514. fiddle with the addend. Otherwise, we need to include the symbol
  4515. value so that it becomes an addend for the dynamic reloc. */
  4516. if (!relocate)
  4517. return bfd_reloc_ok;
  4518. return _bfd_final_link_relocate (howto, input_bfd, input_section,
  4519. contents, rel->r_offset, value,
  4520. signed_addend);
  4521. }
  4522. else
  4523. value += signed_addend;
  4524. break;
  4525. case BFD_RELOC_AARCH64_CALL26:
  4526. case BFD_RELOC_AARCH64_JUMP26:
  4527. {
  4528. asection *splt = globals->root.splt;
  4529. bfd_boolean via_plt_p =
  4530. splt != NULL && h != NULL && h->plt.offset != (bfd_vma) - 1;
  4531. /* A call to an undefined weak symbol is converted to a jump to
  4532. the next instruction unless a PLT entry will be created.
  4533. The jump to the next instruction is optimized as a NOP.
  4534. Do the same for local undefined symbols. */
  4535. if (weak_undef_p && ! via_plt_p)
  4536. {
  4537. bfd_putl32 (INSN_NOP, hit_data);
  4538. return bfd_reloc_ok;
  4539. }
  4540. /* If the call goes through a PLT entry, make sure to
  4541. check distance to the right destination address. */
  4542. if (via_plt_p)
  4543. value = (splt->output_section->vma
  4544. + splt->output_offset + h->plt.offset);
  4545. /* Check if a stub has to be inserted because the destination
  4546. is too far away. */
  4547. struct elf_aarch64_stub_hash_entry *stub_entry = NULL;
  4548. if (! aarch64_valid_branch_p (value, place))
  4549. /* The target is out of reach, so redirect the branch to
  4550. the local stub for this function. */
  4551. stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h,
  4552. rel, globals);
  4553. if (stub_entry != NULL)
  4554. value = (stub_entry->stub_offset
  4555. + stub_entry->stub_sec->output_offset
  4556. + stub_entry->stub_sec->output_section->vma);
  4557. }
  4558. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4559. signed_addend, weak_undef_p);
  4560. *unresolved_reloc_p = FALSE;
  4561. break;
  4562. case BFD_RELOC_AARCH64_16_PCREL:
  4563. case BFD_RELOC_AARCH64_32_PCREL:
  4564. case BFD_RELOC_AARCH64_64_PCREL:
  4565. case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
  4566. case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
  4567. case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
  4568. case BFD_RELOC_AARCH64_LD_LO19_PCREL:
  4569. if (bfd_link_pic (info)
  4570. && (input_section->flags & SEC_ALLOC) != 0
  4571. && (input_section->flags & SEC_READONLY) != 0
  4572. && h != NULL
  4573. && !h->def_regular)
  4574. {
  4575. int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
  4576. (*_bfd_error_handler)
  4577. (_("%B: relocation %s against external symbol `%s' can not be used"
  4578. " when making a shared object; recompile with -fPIC"),
  4579. input_bfd, elfNN_aarch64_howto_table[howto_index].name,
  4580. h->root.root.string);
  4581. bfd_set_error (bfd_error_bad_value);
  4582. return FALSE;
  4583. }
  4584. case BFD_RELOC_AARCH64_16:
  4585. #if ARCH_SIZE == 64
  4586. case BFD_RELOC_AARCH64_32:
  4587. #endif
  4588. case BFD_RELOC_AARCH64_ADD_LO12:
  4589. case BFD_RELOC_AARCH64_BRANCH19:
  4590. case BFD_RELOC_AARCH64_LDST128_LO12:
  4591. case BFD_RELOC_AARCH64_LDST16_LO12:
  4592. case BFD_RELOC_AARCH64_LDST32_LO12:
  4593. case BFD_RELOC_AARCH64_LDST64_LO12:
  4594. case BFD_RELOC_AARCH64_LDST8_LO12:
  4595. case BFD_RELOC_AARCH64_MOVW_G0:
  4596. case BFD_RELOC_AARCH64_MOVW_G0_NC:
  4597. case BFD_RELOC_AARCH64_MOVW_G0_S:
  4598. case BFD_RELOC_AARCH64_MOVW_G1:
  4599. case BFD_RELOC_AARCH64_MOVW_G1_NC:
  4600. case BFD_RELOC_AARCH64_MOVW_G1_S:
  4601. case BFD_RELOC_AARCH64_MOVW_G2:
  4602. case BFD_RELOC_AARCH64_MOVW_G2_NC:
  4603. case BFD_RELOC_AARCH64_MOVW_G2_S:
  4604. case BFD_RELOC_AARCH64_MOVW_G3:
  4605. case BFD_RELOC_AARCH64_TSTBR14:
  4606. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4607. signed_addend, weak_undef_p);
  4608. break;
  4609. case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
  4610. case BFD_RELOC_AARCH64_GOT_LD_PREL19:
  4611. case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
  4612. case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
  4613. case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
  4614. case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
  4615. if (globals->root.sgot == NULL)
  4616. BFD_ASSERT (h != NULL);
  4617. if (h != NULL)
  4618. {
  4619. bfd_vma addend = 0;
  4620. value = aarch64_calculate_got_entry_vma (h, globals, info, value,
  4621. output_bfd,
  4622. unresolved_reloc_p);
  4623. if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
  4624. || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
  4625. addend = (globals->root.sgot->output_section->vma
  4626. + globals->root.sgot->output_offset);
  4627. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4628. addend, weak_undef_p);
  4629. }
  4630. else
  4631. {
  4632. bfd_vma addend = 0;
  4633. struct elf_aarch64_local_symbol *locals
  4634. = elf_aarch64_locals (input_bfd);
  4635. if (locals == NULL)
  4636. {
  4637. int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
  4638. (*_bfd_error_handler)
  4639. (_("%B: Local symbol descriptor table be NULL when applying "
  4640. "relocation %s against local symbol"),
  4641. input_bfd, elfNN_aarch64_howto_table[howto_index].name);
  4642. abort ();
  4643. }
  4644. off = symbol_got_offset (input_bfd, h, r_symndx);
  4645. base_got = globals->root.sgot;
  4646. bfd_vma got_entry_addr = (base_got->output_section->vma
  4647. + base_got->output_offset + off);
  4648. if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
  4649. {
  4650. bfd_put_64 (output_bfd, value, base_got->contents + off);
  4651. if (bfd_link_pic (info))
  4652. {
  4653. asection *s;
  4654. Elf_Internal_Rela outrel;
  4655. /* For local symbol, we have done absolute relocation in static
  4656. linking stageh. While for share library, we need to update
  4657. the content of GOT entry according to the share objects
  4658. loading base address. So we need to generate a
  4659. R_AARCH64_RELATIVE reloc for dynamic linker. */
  4660. s = globals->root.srelgot;
  4661. if (s == NULL)
  4662. abort ();
  4663. outrel.r_offset = got_entry_addr;
  4664. outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
  4665. outrel.r_addend = value;
  4666. elf_append_rela (output_bfd, s, &outrel);
  4667. }
  4668. symbol_got_offset_mark (input_bfd, h, r_symndx);
  4669. }
  4670. /* Update the relocation value to GOT entry addr as we have transformed
  4671. the direct data access into indirect data access through GOT. */
  4672. value = got_entry_addr;
  4673. if (bfd_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
  4674. || bfd_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
  4675. addend = base_got->output_section->vma + base_got->output_offset;
  4676. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4677. addend, weak_undef_p);
  4678. }
  4679. break;
  4680. case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
  4681. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
  4682. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
  4683. if (h != NULL)
  4684. value = aarch64_calculate_got_entry_vma (h, globals, info, value,
  4685. output_bfd,
  4686. unresolved_reloc_p);
  4687. else
  4688. {
  4689. struct elf_aarch64_local_symbol *locals
  4690. = elf_aarch64_locals (input_bfd);
  4691. if (locals == NULL)
  4692. {
  4693. int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
  4694. (*_bfd_error_handler)
  4695. (_("%B: Local symbol descriptor table be NULL when applying "
  4696. "relocation %s against local symbol"),
  4697. input_bfd, elfNN_aarch64_howto_table[howto_index].name);
  4698. abort ();
  4699. }
  4700. off = symbol_got_offset (input_bfd, h, r_symndx);
  4701. base_got = globals->root.sgot;
  4702. if (base_got == NULL)
  4703. abort ();
  4704. bfd_vma got_entry_addr = (base_got->output_section->vma
  4705. + base_got->output_offset + off);
  4706. if (!symbol_got_offset_mark_p (input_bfd, h, r_symndx))
  4707. {
  4708. bfd_put_64 (output_bfd, value, base_got->contents + off);
  4709. if (bfd_link_pic (info))
  4710. {
  4711. asection *s;
  4712. Elf_Internal_Rela outrel;
  4713. /* For local symbol, we have done absolute relocation in static
  4714. linking stage. While for share library, we need to update
  4715. the content of GOT entry according to the share objects
  4716. loading base address. So we need to generate a
  4717. R_AARCH64_RELATIVE reloc for dynamic linker. */
  4718. s = globals->root.srelgot;
  4719. if (s == NULL)
  4720. abort ();
  4721. outrel.r_offset = got_entry_addr;
  4722. outrel.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
  4723. outrel.r_addend = value;
  4724. elf_append_rela (output_bfd, s, &outrel);
  4725. }
  4726. symbol_got_offset_mark (input_bfd, h, r_symndx);
  4727. }
  4728. }
  4729. /* Update the relocation value to GOT entry addr as we have transformed
  4730. the direct data access into indirect data access through GOT. */
  4731. value = symbol_got_offset (input_bfd, h, r_symndx);
  4732. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4733. 0, weak_undef_p);
  4734. *unresolved_reloc_p = FALSE;
  4735. break;
  4736. case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
  4737. case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
  4738. case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
  4739. case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
  4740. case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
  4741. case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
  4742. case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
  4743. case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
  4744. case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
  4745. case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
  4746. if (globals->root.sgot == NULL)
  4747. return bfd_reloc_notsupported;
  4748. value = (symbol_got_offset (input_bfd, h, r_symndx)
  4749. + globals->root.sgot->output_section->vma
  4750. + globals->root.sgot->output_offset);
  4751. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4752. 0, weak_undef_p);
  4753. *unresolved_reloc_p = FALSE;
  4754. break;
  4755. case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
  4756. case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
  4757. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
  4758. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
  4759. if (globals->root.sgot == NULL)
  4760. return bfd_reloc_notsupported;
  4761. value = symbol_got_offset (input_bfd, h, r_symndx);
  4762. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4763. 0, weak_undef_p);
  4764. *unresolved_reloc_p = FALSE;
  4765. break;
  4766. case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12:
  4767. case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12:
  4768. case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC:
  4769. case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12:
  4770. case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC:
  4771. case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12:
  4772. case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC:
  4773. case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12:
  4774. case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC:
  4775. case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12:
  4776. case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC:
  4777. case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0:
  4778. case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC:
  4779. case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1:
  4780. case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC:
  4781. case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2:
  4782. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4783. signed_addend - dtpoff_base (info),
  4784. weak_undef_p);
  4785. break;
  4786. case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12:
  4787. case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12:
  4788. case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
  4789. case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0:
  4790. case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC:
  4791. case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
  4792. case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
  4793. case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
  4794. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4795. signed_addend - tpoff_base (info),
  4796. weak_undef_p);
  4797. *unresolved_reloc_p = FALSE;
  4798. break;
  4799. case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
  4800. case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
  4801. case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
  4802. case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
  4803. case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
  4804. case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
  4805. if (globals->root.sgot == NULL)
  4806. return bfd_reloc_notsupported;
  4807. value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
  4808. + globals->root.sgotplt->output_section->vma
  4809. + globals->root.sgotplt->output_offset
  4810. + globals->sgotplt_jump_table_size);
  4811. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4812. 0, weak_undef_p);
  4813. *unresolved_reloc_p = FALSE;
  4814. break;
  4815. case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
  4816. case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
  4817. if (globals->root.sgot == NULL)
  4818. return bfd_reloc_notsupported;
  4819. value = (symbol_tlsdesc_got_offset (input_bfd, h, r_symndx)
  4820. + globals->root.sgotplt->output_section->vma
  4821. + globals->root.sgotplt->output_offset
  4822. + globals->sgotplt_jump_table_size);
  4823. value -= (globals->root.sgot->output_section->vma
  4824. + globals->root.sgot->output_offset);
  4825. value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
  4826. 0, weak_undef_p);
  4827. *unresolved_reloc_p = FALSE;
  4828. break;
  4829. default:
  4830. return bfd_reloc_notsupported;
  4831. }
  4832. if (saved_addend)
  4833. *saved_addend = value;
  4834. /* Only apply the final relocation in a sequence. */
  4835. if (save_addend)
  4836. return bfd_reloc_continue;
  4837. return _bfd_aarch64_elf_put_addend (input_bfd, hit_data, bfd_r_type,
  4838. howto, value);
  4839. }
  4840. /* Handle TLS relaxations. Relaxing is possible for symbols that use
  4841. R_AARCH64_TLSDESC_ADR_{PAGE, LD64_LO12_NC, ADD_LO12_NC} during a static
  4842. link.
  4843. Return bfd_reloc_ok if we're done, bfd_reloc_continue if the caller
  4844. is to then call final_link_relocate. Return other values in the
  4845. case of error. */
  4846. static bfd_reloc_status_type
  4847. elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
  4848. bfd *input_bfd, bfd_byte *contents,
  4849. Elf_Internal_Rela *rel, struct elf_link_hash_entry *h,
  4850. bfd_vma relocation ATTRIBUTE_UNUSED)
  4851. {
  4852. bfd_boolean is_local = h == NULL;
  4853. unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
  4854. unsigned long insn;
  4855. BFD_ASSERT (globals && input_bfd && contents && rel);
  4856. switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
  4857. {
  4858. case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
  4859. case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
  4860. if (is_local)
  4861. {
  4862. /* GD->LE relaxation:
  4863. adrp x0, :tlsgd:var => movz x0, :tprel_g1:var
  4864. or
  4865. adrp x0, :tlsdesc:var => movz x0, :tprel_g1:var
  4866. */
  4867. bfd_putl32 (0xd2a00000, contents + rel->r_offset);
  4868. return bfd_reloc_continue;
  4869. }
  4870. else
  4871. {
  4872. /* GD->IE relaxation:
  4873. adrp x0, :tlsgd:var => adrp x0, :gottprel:var
  4874. or
  4875. adrp x0, :tlsdesc:var => adrp x0, :gottprel:var
  4876. */
  4877. return bfd_reloc_continue;
  4878. }
  4879. case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
  4880. BFD_ASSERT (0);
  4881. break;
  4882. case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
  4883. if (is_local)
  4884. {
  4885. /* Tiny TLSDESC->LE relaxation:
  4886. ldr x1, :tlsdesc:var => movz x0, #:tprel_g1:var
  4887. adr x0, :tlsdesc:var => movk x0, #:tprel_g0_nc:var
  4888. .tlsdesccall var
  4889. blr x1 => nop
  4890. */
  4891. BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
  4892. BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
  4893. rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
  4894. AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
  4895. rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
  4896. bfd_putl32 (0xd2a00000, contents + rel->r_offset);
  4897. bfd_putl32 (0xf2800000, contents + rel->r_offset + 4);
  4898. bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
  4899. return bfd_reloc_continue;
  4900. }
  4901. else
  4902. {
  4903. /* Tiny TLSDESC->IE relaxation:
  4904. ldr x1, :tlsdesc:var => ldr x0, :gottprel:var
  4905. adr x0, :tlsdesc:var => nop
  4906. .tlsdesccall var
  4907. blr x1 => nop
  4908. */
  4909. BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSDESC_ADR_PREL21));
  4910. BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (TLSDESC_CALL));
  4911. rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
  4912. rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
  4913. bfd_putl32 (0x58000000, contents + rel->r_offset);
  4914. bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
  4915. bfd_putl32 (INSN_NOP, contents + rel->r_offset + 8);
  4916. return bfd_reloc_continue;
  4917. }
  4918. case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
  4919. if (is_local)
  4920. {
  4921. /* Tiny GD->LE relaxation:
  4922. adr x0, :tlsgd:var => mrs x1, tpidr_el0
  4923. bl __tls_get_addr => add x0, x1, #:tprel_hi12:x, lsl #12
  4924. nop => add x0, x0, #:tprel_lo12_nc:x
  4925. */
  4926. /* First kill the tls_get_addr reloc on the bl instruction. */
  4927. BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
  4928. bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
  4929. bfd_putl32 (0x91400020, contents + rel->r_offset + 4);
  4930. bfd_putl32 (0x91000000, contents + rel->r_offset + 8);
  4931. rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
  4932. AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
  4933. rel[1].r_offset = rel->r_offset + 8;
  4934. /* Move the current relocation to the second instruction in
  4935. the sequence. */
  4936. rel->r_offset += 4;
  4937. rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
  4938. AARCH64_R (TLSLE_ADD_TPREL_HI12));
  4939. return bfd_reloc_continue;
  4940. }
  4941. else
  4942. {
  4943. /* Tiny GD->IE relaxation:
  4944. adr x0, :tlsgd:var => ldr x0, :gottprel:var
  4945. bl __tls_get_addr => mrs x1, tpidr_el0
  4946. nop => add x0, x0, x1
  4947. */
  4948. /* First kill the tls_get_addr reloc on the bl instruction. */
  4949. BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
  4950. rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
  4951. bfd_putl32 (0x58000000, contents + rel->r_offset);
  4952. bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
  4953. bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
  4954. return bfd_reloc_continue;
  4955. }
  4956. #if ARCH_SIZE == 64
  4957. case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
  4958. BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (TLSGD_MOVW_G0_NC));
  4959. BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset);
  4960. BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26));
  4961. if (is_local)
  4962. {
  4963. /* Large GD->LE relaxation:
  4964. movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32
  4965. movk x0, #:tlsgd_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
  4966. add x0, gp, x0 => movk x0, #:tprel_g0_nc:var
  4967. bl __tls_get_addr => mrs x1, tpidr_el0
  4968. nop => add x0, x0, x1
  4969. */
  4970. rel[2].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
  4971. AARCH64_R (TLSLE_MOVW_TPREL_G0_NC));
  4972. rel[2].r_offset = rel->r_offset + 8;
  4973. bfd_putl32 (0xd2c00000, contents + rel->r_offset + 0);
  4974. bfd_putl32 (0xf2a00000, contents + rel->r_offset + 4);
  4975. bfd_putl32 (0xf2800000, contents + rel->r_offset + 8);
  4976. bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
  4977. bfd_putl32 (0x8b000020, contents + rel->r_offset + 16);
  4978. }
  4979. else
  4980. {
  4981. /* Large GD->IE relaxation:
  4982. movz x0, #:tlsgd_g1:var => movz x0, #:gottprel_g1:var, lsl #16
  4983. movk x0, #:tlsgd_g0_nc:var => movk x0, #:gottprel_g0_nc:var
  4984. add x0, gp, x0 => ldr x0, [gp, x0]
  4985. bl __tls_get_addr => mrs x1, tpidr_el0
  4986. nop => add x0, x0, x1
  4987. */
  4988. rel[2].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
  4989. bfd_putl32 (0xd2a80000, contents + rel->r_offset + 0);
  4990. bfd_putl32 (0x58000000, contents + rel->r_offset + 8);
  4991. bfd_putl32 (0xd53bd041, contents + rel->r_offset + 12);
  4992. bfd_putl32 (0x8b000020, contents + rel->r_offset + 16);
  4993. }
  4994. return bfd_reloc_continue;
  4995. case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
  4996. return bfd_reloc_continue;
  4997. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
  4998. if (is_local)
  4999. {
  5000. /* Large IE->LE relaxation:
  5001. mrs tp, tpidr_el0
  5002. movz tx, #:gottprel_g1:var => movz tx, #:tprel_g2:var, lsl #32
  5003. movk tx, #:gottprel_g0_nc:var => movk tx, #:tprel_g1_nc:var, lsl #16
  5004. ldr tx, [gp, tx] => movk tx, #:tprel_g0_nc:var
  5005. add tx, tx, tp
  5006. */
  5007. uint32_t value;
  5008. BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info)
  5009. == AARCH64_R (TLSIE_MOVW_GOTTPREL_G0_NC));
  5010. BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
  5011. value = (relocation & ~(bfd_vma) 0xffffffff) >> 32;
  5012. insn = bfd_getl32 (contents + rel->r_offset);
  5013. insn &= 0xff80001f;
  5014. insn |= (0x400000 + (value << 5));
  5015. bfd_putl32 (insn, contents + rel->r_offset + 0);
  5016. value = (relocation & (bfd_vma) 0xffff0000) >> 16;
  5017. insn = bfd_getl32 (contents + rel->r_offset + 4);
  5018. insn &= 0xff80001f;
  5019. insn |= (0x200000 + (value << 5));
  5020. bfd_putl32 (insn, contents + rel->r_offset + 4);
  5021. value = relocation & (bfd_vma) 0xffff;
  5022. insn = bfd_getl32 (contents + rel->r_offset + 4);
  5023. insn &= 0xff80001f;
  5024. insn |= (value << 5);
  5025. bfd_putl32 (insn, contents + rel->r_offset + 8);
  5026. /* Relocations are already resolved here. */
  5027. rel->r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
  5028. rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
  5029. return bfd_reloc_ok;
  5030. }
  5031. return bfd_reloc_continue;
  5032. #endif
  5033. case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
  5034. return bfd_reloc_continue;
  5035. case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
  5036. if (is_local)
  5037. {
  5038. /* GD->LE relaxation:
  5039. ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var
  5040. */
  5041. bfd_putl32 (0xf2800000, contents + rel->r_offset);
  5042. return bfd_reloc_continue;
  5043. }
  5044. else
  5045. {
  5046. /* GD->IE relaxation:
  5047. ldr xd, [x0, #:tlsdesc_lo12:var] => ldr x0, [x0, #:gottprel_lo12:var]
  5048. */
  5049. insn = bfd_getl32 (contents + rel->r_offset);
  5050. insn &= 0xffffffe0;
  5051. bfd_putl32 (insn, contents + rel->r_offset);
  5052. return bfd_reloc_continue;
  5053. }
  5054. case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
  5055. if (is_local)
  5056. {
  5057. /* GD->LE relaxation
  5058. add x0, #:tlsgd_lo12:var => movk x0, :tprel_g0_nc:var
  5059. bl __tls_get_addr => mrs x1, tpidr_el0
  5060. nop => add x0, x1, x0
  5061. */
  5062. /* First kill the tls_get_addr reloc on the bl instruction. */
  5063. BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
  5064. rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
  5065. bfd_putl32 (0xf2800000, contents + rel->r_offset);
  5066. bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
  5067. bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
  5068. return bfd_reloc_continue;
  5069. }
  5070. else
  5071. {
  5072. /* GD->IE relaxation
  5073. ADD x0, #:tlsgd_lo12:var => ldr x0, [x0, #:gottprel_lo12:var]
  5074. BL __tls_get_addr => mrs x1, tpidr_el0
  5075. R_AARCH64_CALL26
  5076. NOP => add x0, x1, x0
  5077. */
  5078. BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
  5079. /* Remove the relocation on the BL instruction. */
  5080. rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
  5081. bfd_putl32 (0xf9400000, contents + rel->r_offset);
  5082. /* We choose to fixup the BL and NOP instructions using the
  5083. offset from the second relocation to allow flexibility in
  5084. scheduling instructions between the ADD and BL. */
  5085. bfd_putl32 (0xd53bd041, contents + rel[1].r_offset);
  5086. bfd_putl32 (0x8b000020, contents + rel[1].r_offset + 4);
  5087. return bfd_reloc_continue;
  5088. }
  5089. case BFD_RELOC_AARCH64_TLSDESC_ADD:
  5090. case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
  5091. case BFD_RELOC_AARCH64_TLSDESC_CALL:
  5092. /* GD->IE/LE relaxation:
  5093. add x0, x0, #:tlsdesc_lo12:var => nop
  5094. blr xd => nop
  5095. */
  5096. bfd_putl32 (INSN_NOP, contents + rel->r_offset);
  5097. return bfd_reloc_ok;
  5098. case BFD_RELOC_AARCH64_TLSDESC_LDR:
  5099. if (is_local)
  5100. {
  5101. /* GD->LE relaxation:
  5102. ldr xd, [gp, xn] => movk x0, #:tprel_g0_nc:var
  5103. */
  5104. bfd_putl32 (0xf2800000, contents + rel->r_offset);
  5105. return bfd_reloc_continue;
  5106. }
  5107. else
  5108. {
  5109. /* GD->IE relaxation:
  5110. ldr xd, [gp, xn] => ldr x0, [gp, xn]
  5111. */
  5112. insn = bfd_getl32 (contents + rel->r_offset);
  5113. insn &= 0xffffffe0;
  5114. bfd_putl32 (insn, contents + rel->r_offset);
  5115. return bfd_reloc_ok;
  5116. }
  5117. case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
  5118. /* GD->LE relaxation:
  5119. movk xd, #:tlsdesc_off_g0_nc:var => movk x0, #:tprel_g1_nc:var, lsl #16
  5120. GD->IE relaxation:
  5121. movk xd, #:tlsdesc_off_g0_nc:var => movk xd, #:gottprel_g0_nc:var
  5122. */
  5123. if (is_local)
  5124. bfd_putl32 (0xf2a00000, contents + rel->r_offset);
  5125. return bfd_reloc_continue;
  5126. case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
  5127. if (is_local)
  5128. {
  5129. /* GD->LE relaxation:
  5130. movz xd, #:tlsdesc_off_g1:var => movz x0, #:tprel_g2:var, lsl #32
  5131. */
  5132. bfd_putl32 (0xd2c00000, contents + rel->r_offset);
  5133. return bfd_reloc_continue;
  5134. }
  5135. else
  5136. {
  5137. /* GD->IE relaxation:
  5138. movz xd, #:tlsdesc_off_g1:var => movz xd, #:gottprel_g1:var, lsl #16
  5139. */
  5140. insn = bfd_getl32 (contents + rel->r_offset);
  5141. bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
  5142. return bfd_reloc_continue;
  5143. }
  5144. case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
  5145. /* IE->LE relaxation:
  5146. adrp xd, :gottprel:var => movz xd, :tprel_g1:var
  5147. */
  5148. if (is_local)
  5149. {
  5150. insn = bfd_getl32 (contents + rel->r_offset);
  5151. bfd_putl32 (0xd2a00000 | (insn & 0x1f), contents + rel->r_offset);
  5152. }
  5153. return bfd_reloc_continue;
  5154. case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
  5155. /* IE->LE relaxation:
  5156. ldr xd, [xm, #:gottprel_lo12:var] => movk xd, :tprel_g0_nc:var
  5157. */
  5158. if (is_local)
  5159. {
  5160. insn = bfd_getl32 (contents + rel->r_offset);
  5161. bfd_putl32 (0xf2800000 | (insn & 0x1f), contents + rel->r_offset);
  5162. }
  5163. return bfd_reloc_continue;
  5164. case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
  5165. /* LD->LE relaxation (tiny):
  5166. adr x0, :tlsldm:x => mrs x0, tpidr_el0
  5167. bl __tls_get_addr => add x0, x0, TCB_SIZE
  5168. */
  5169. if (is_local)
  5170. {
  5171. BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
  5172. BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
  5173. /* No need of CALL26 relocation for tls_get_addr. */
  5174. rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
  5175. bfd_putl32 (0xd53bd040, contents + rel->r_offset + 0);
  5176. bfd_putl32 (0x91004000, contents + rel->r_offset + 4);
  5177. return bfd_reloc_ok;
  5178. }
  5179. return bfd_reloc_continue;
  5180. case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
  5181. /* LD->LE relaxation (small):
  5182. adrp x0, :tlsldm:x => mrs x0, tpidr_el0
  5183. */
  5184. if (is_local)
  5185. {
  5186. bfd_putl32 (0xd53bd040, contents + rel->r_offset);
  5187. return bfd_reloc_ok;
  5188. }
  5189. return bfd_reloc_continue;
  5190. case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
  5191. /* LD->LE relaxation (small):
  5192. add x0, #:tlsldm_lo12:x => add x0, x0, TCB_SIZE
  5193. bl __tls_get_addr => nop
  5194. */
  5195. if (is_local)
  5196. {
  5197. BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
  5198. BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
  5199. /* No need of CALL26 relocation for tls_get_addr. */
  5200. rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
  5201. bfd_putl32 (0x91004000, contents + rel->r_offset + 0);
  5202. bfd_putl32 (0xd503201f, contents + rel->r_offset + 4);
  5203. return bfd_reloc_ok;
  5204. }
  5205. return bfd_reloc_continue;
  5206. default:
  5207. return bfd_reloc_continue;
  5208. }
  5209. return bfd_reloc_ok;
  5210. }
  5211. /* Relocate an AArch64 ELF section. */
  5212. static bfd_boolean
  5213. elfNN_aarch64_relocate_section (bfd *output_bfd,
  5214. struct bfd_link_info *info,
  5215. bfd *input_bfd,
  5216. asection *input_section,
  5217. bfd_byte *contents,
  5218. Elf_Internal_Rela *relocs,
  5219. Elf_Internal_Sym *local_syms,
  5220. asection **local_sections)
  5221. {
  5222. Elf_Internal_Shdr *symtab_hdr;
  5223. struct elf_link_hash_entry **sym_hashes;
  5224. Elf_Internal_Rela *rel;
  5225. Elf_Internal_Rela *relend;
  5226. const char *name;
  5227. struct elf_aarch64_link_hash_table *globals;
  5228. bfd_boolean save_addend = FALSE;
  5229. bfd_vma addend = 0;
  5230. globals = elf_aarch64_hash_table (info);
  5231. symtab_hdr = &elf_symtab_hdr (input_bfd);
  5232. sym_hashes = elf_sym_hashes (input_bfd);
  5233. rel = relocs;
  5234. relend = relocs + input_section->reloc_count;
  5235. for (; rel < relend; rel++)
  5236. {
  5237. unsigned int r_type;
  5238. bfd_reloc_code_real_type bfd_r_type;
  5239. bfd_reloc_code_real_type relaxed_bfd_r_type;
  5240. reloc_howto_type *howto;
  5241. unsigned long r_symndx;
  5242. Elf_Internal_Sym *sym;
  5243. asection *sec;
  5244. struct elf_link_hash_entry *h;
  5245. bfd_vma relocation;
  5246. bfd_reloc_status_type r;
  5247. arelent bfd_reloc;
  5248. char sym_type;
  5249. bfd_boolean unresolved_reloc = FALSE;
  5250. char *error_message = NULL;
  5251. r_symndx = ELFNN_R_SYM (rel->r_info);
  5252. r_type = ELFNN_R_TYPE (rel->r_info);
  5253. bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
  5254. howto = bfd_reloc.howto;
  5255. if (howto == NULL)
  5256. {
  5257. (*_bfd_error_handler)
  5258. (_("%B: unrecognized relocation (0x%x) in section `%A'"),
  5259. input_bfd, input_section, r_type);
  5260. return FALSE;
  5261. }
  5262. bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
  5263. h = NULL;
  5264. sym = NULL;
  5265. sec = NULL;
  5266. if (r_symndx < symtab_hdr->sh_info)
  5267. {
  5268. sym = local_syms + r_symndx;
  5269. sym_type = ELFNN_ST_TYPE (sym->st_info);
  5270. sec = local_sections[r_symndx];
  5271. /* An object file might have a reference to a local
  5272. undefined symbol. This is a daft object file, but we
  5273. should at least do something about it. */
  5274. if (r_type != R_AARCH64_NONE && r_type != R_AARCH64_NULL
  5275. && bfd_is_und_section (sec)
  5276. && ELF_ST_BIND (sym->st_info) != STB_WEAK)
  5277. {
  5278. if (!info->callbacks->undefined_symbol
  5279. (info, bfd_elf_string_from_elf_section
  5280. (input_bfd, symtab_hdr->sh_link, sym->st_name),
  5281. input_bfd, input_section, rel->r_offset, TRUE))
  5282. return FALSE;
  5283. }
  5284. relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
  5285. /* Relocate against local STT_GNU_IFUNC symbol. */
  5286. if (!bfd_link_relocatable (info)
  5287. && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
  5288. {
  5289. h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
  5290. rel, FALSE);
  5291. if (h == NULL)
  5292. abort ();
  5293. /* Set STT_GNU_IFUNC symbol value. */
  5294. h->root.u.def.value = sym->st_value;
  5295. h->root.u.def.section = sec;
  5296. }
  5297. }
  5298. else
  5299. {
  5300. bfd_boolean warned, ignored;
  5301. RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
  5302. r_symndx, symtab_hdr, sym_hashes,
  5303. h, sec, relocation,
  5304. unresolved_reloc, warned, ignored);
  5305. sym_type = h->type;
  5306. }
  5307. if (sec != NULL && discarded_section (sec))
  5308. RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
  5309. rel, 1, relend, howto, 0, contents);
  5310. if (bfd_link_relocatable (info))
  5311. continue;
  5312. if (h != NULL)
  5313. name = h->root.root.string;
  5314. else
  5315. {
  5316. name = (bfd_elf_string_from_elf_section
  5317. (input_bfd, symtab_hdr->sh_link, sym->st_name));
  5318. if (name == NULL || *name == '\0')
  5319. name = bfd_section_name (input_bfd, sec);
  5320. }
  5321. if (r_symndx != 0
  5322. && r_type != R_AARCH64_NONE
  5323. && r_type != R_AARCH64_NULL
  5324. && (h == NULL
  5325. || h->root.type == bfd_link_hash_defined
  5326. || h->root.type == bfd_link_hash_defweak)
  5327. && IS_AARCH64_TLS_RELOC (bfd_r_type) != (sym_type == STT_TLS))
  5328. {
  5329. (*_bfd_error_handler)
  5330. ((sym_type == STT_TLS
  5331. ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
  5332. : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
  5333. input_bfd,
  5334. input_section, (long) rel->r_offset, howto->name, name);
  5335. }
  5336. /* We relax only if we can see that there can be a valid transition
  5337. from a reloc type to another.
  5338. We call elfNN_aarch64_final_link_relocate unless we're completely
  5339. done, i.e., the relaxation produced the final output we want. */
  5340. relaxed_bfd_r_type = aarch64_tls_transition (input_bfd, info, r_type,
  5341. h, r_symndx);
  5342. if (relaxed_bfd_r_type != bfd_r_type)
  5343. {
  5344. bfd_r_type = relaxed_bfd_r_type;
  5345. howto = elfNN_aarch64_howto_from_bfd_reloc (bfd_r_type);
  5346. BFD_ASSERT (howto != NULL);
  5347. r_type = howto->type;
  5348. r = elfNN_aarch64_tls_relax (globals, input_bfd, contents, rel, h,
  5349. relocation - tpoff_base (info));
  5350. unresolved_reloc = 0;
  5351. }
  5352. else
  5353. r = bfd_reloc_continue;
  5354. /* There may be multiple consecutive relocations for the
  5355. same offset. In that case we are supposed to treat the
  5356. output of each relocation as the addend for the next. */
  5357. if (rel + 1 < relend
  5358. && rel->r_offset == rel[1].r_offset
  5359. && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NONE
  5360. && ELFNN_R_TYPE (rel[1].r_info) != R_AARCH64_NULL)
  5361. save_addend = TRUE;
  5362. else
  5363. save_addend = FALSE;
  5364. if (r == bfd_reloc_continue)
  5365. r = elfNN_aarch64_final_link_relocate (howto, input_bfd, output_bfd,
  5366. input_section, contents, rel,
  5367. relocation, info, sec,
  5368. h, &unresolved_reloc,
  5369. save_addend, &addend, sym);
  5370. switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
  5371. {
  5372. case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
  5373. case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
  5374. case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
  5375. case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
  5376. case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
  5377. case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
  5378. case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
  5379. case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
  5380. if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
  5381. {
  5382. bfd_boolean need_relocs = FALSE;
  5383. bfd_byte *loc;
  5384. int indx;
  5385. bfd_vma off;
  5386. off = symbol_got_offset (input_bfd, h, r_symndx);
  5387. indx = h && h->dynindx != -1 ? h->dynindx : 0;
  5388. need_relocs =
  5389. (bfd_link_pic (info) || indx != 0) &&
  5390. (h == NULL
  5391. || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  5392. || h->root.type != bfd_link_hash_undefweak);
  5393. BFD_ASSERT (globals->root.srelgot != NULL);
  5394. if (need_relocs)
  5395. {
  5396. Elf_Internal_Rela rela;
  5397. rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPMOD));
  5398. rela.r_addend = 0;
  5399. rela.r_offset = globals->root.sgot->output_section->vma +
  5400. globals->root.sgot->output_offset + off;
  5401. loc = globals->root.srelgot->contents;
  5402. loc += globals->root.srelgot->reloc_count++
  5403. * RELOC_SIZE (htab);
  5404. bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
  5405. bfd_reloc_code_real_type real_type =
  5406. elfNN_aarch64_bfd_reloc_from_type (r_type);
  5407. if (real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
  5408. || real_type == BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
  5409. || real_type == BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC)
  5410. {
  5411. /* For local dynamic, don't generate DTPREL in any case.
  5412. Initialize the DTPREL slot into zero, so we get module
  5413. base address when invoke runtime TLS resolver. */
  5414. bfd_put_NN (output_bfd, 0,
  5415. globals->root.sgot->contents + off
  5416. + GOT_ENTRY_SIZE);
  5417. }
  5418. else if (indx == 0)
  5419. {
  5420. bfd_put_NN (output_bfd,
  5421. relocation - dtpoff_base (info),
  5422. globals->root.sgot->contents + off
  5423. + GOT_ENTRY_SIZE);
  5424. }
  5425. else
  5426. {
  5427. /* This TLS symbol is global. We emit a
  5428. relocation to fixup the tls offset at load
  5429. time. */
  5430. rela.r_info =
  5431. ELFNN_R_INFO (indx, AARCH64_R (TLS_DTPREL));
  5432. rela.r_addend = 0;
  5433. rela.r_offset =
  5434. (globals->root.sgot->output_section->vma
  5435. + globals->root.sgot->output_offset + off
  5436. + GOT_ENTRY_SIZE);
  5437. loc = globals->root.srelgot->contents;
  5438. loc += globals->root.srelgot->reloc_count++
  5439. * RELOC_SIZE (globals);
  5440. bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
  5441. bfd_put_NN (output_bfd, (bfd_vma) 0,
  5442. globals->root.sgot->contents + off
  5443. + GOT_ENTRY_SIZE);
  5444. }
  5445. }
  5446. else
  5447. {
  5448. bfd_put_NN (output_bfd, (bfd_vma) 1,
  5449. globals->root.sgot->contents + off);
  5450. bfd_put_NN (output_bfd,
  5451. relocation - dtpoff_base (info),
  5452. globals->root.sgot->contents + off
  5453. + GOT_ENTRY_SIZE);
  5454. }
  5455. symbol_got_offset_mark (input_bfd, h, r_symndx);
  5456. }
  5457. break;
  5458. case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
  5459. case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
  5460. case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
  5461. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
  5462. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
  5463. if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
  5464. {
  5465. bfd_boolean need_relocs = FALSE;
  5466. bfd_byte *loc;
  5467. int indx;
  5468. bfd_vma off;
  5469. off = symbol_got_offset (input_bfd, h, r_symndx);
  5470. indx = h && h->dynindx != -1 ? h->dynindx : 0;
  5471. need_relocs =
  5472. (bfd_link_pic (info) || indx != 0) &&
  5473. (h == NULL
  5474. || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  5475. || h->root.type != bfd_link_hash_undefweak);
  5476. BFD_ASSERT (globals->root.srelgot != NULL);
  5477. if (need_relocs)
  5478. {
  5479. Elf_Internal_Rela rela;
  5480. if (indx == 0)
  5481. rela.r_addend = relocation - dtpoff_base (info);
  5482. else
  5483. rela.r_addend = 0;
  5484. rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLS_TPREL));
  5485. rela.r_offset = globals->root.sgot->output_section->vma +
  5486. globals->root.sgot->output_offset + off;
  5487. loc = globals->root.srelgot->contents;
  5488. loc += globals->root.srelgot->reloc_count++
  5489. * RELOC_SIZE (htab);
  5490. bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
  5491. bfd_put_NN (output_bfd, rela.r_addend,
  5492. globals->root.sgot->contents + off);
  5493. }
  5494. else
  5495. bfd_put_NN (output_bfd, relocation - tpoff_base (info),
  5496. globals->root.sgot->contents + off);
  5497. symbol_got_offset_mark (input_bfd, h, r_symndx);
  5498. }
  5499. break;
  5500. case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
  5501. case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
  5502. case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
  5503. case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
  5504. case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
  5505. case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
  5506. case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
  5507. if (! symbol_tlsdesc_got_offset_mark_p (input_bfd, h, r_symndx))
  5508. {
  5509. bfd_boolean need_relocs = FALSE;
  5510. int indx = h && h->dynindx != -1 ? h->dynindx : 0;
  5511. bfd_vma off = symbol_tlsdesc_got_offset (input_bfd, h, r_symndx);
  5512. need_relocs = (h == NULL
  5513. || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  5514. || h->root.type != bfd_link_hash_undefweak);
  5515. BFD_ASSERT (globals->root.srelgot != NULL);
  5516. BFD_ASSERT (globals->root.sgot != NULL);
  5517. if (need_relocs)
  5518. {
  5519. bfd_byte *loc;
  5520. Elf_Internal_Rela rela;
  5521. rela.r_info = ELFNN_R_INFO (indx, AARCH64_R (TLSDESC));
  5522. rela.r_addend = 0;
  5523. rela.r_offset = (globals->root.sgotplt->output_section->vma
  5524. + globals->root.sgotplt->output_offset
  5525. + off + globals->sgotplt_jump_table_size);
  5526. if (indx == 0)
  5527. rela.r_addend = relocation - dtpoff_base (info);
  5528. /* Allocate the next available slot in the PLT reloc
  5529. section to hold our R_AARCH64_TLSDESC, the next
  5530. available slot is determined from reloc_count,
  5531. which we step. But note, reloc_count was
  5532. artifically moved down while allocating slots for
  5533. real PLT relocs such that all of the PLT relocs
  5534. will fit above the initial reloc_count and the
  5535. extra stuff will fit below. */
  5536. loc = globals->root.srelplt->contents;
  5537. loc += globals->root.srelplt->reloc_count++
  5538. * RELOC_SIZE (globals);
  5539. bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
  5540. bfd_put_NN (output_bfd, (bfd_vma) 0,
  5541. globals->root.sgotplt->contents + off +
  5542. globals->sgotplt_jump_table_size);
  5543. bfd_put_NN (output_bfd, (bfd_vma) 0,
  5544. globals->root.sgotplt->contents + off +
  5545. globals->sgotplt_jump_table_size +
  5546. GOT_ENTRY_SIZE);
  5547. }
  5548. symbol_tlsdesc_got_offset_mark (input_bfd, h, r_symndx);
  5549. }
  5550. break;
  5551. default:
  5552. break;
  5553. }
  5554. if (!save_addend)
  5555. addend = 0;
  5556. /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
  5557. because such sections are not SEC_ALLOC and thus ld.so will
  5558. not process them. */
  5559. if (unresolved_reloc
  5560. && !((input_section->flags & SEC_DEBUGGING) != 0
  5561. && h->def_dynamic)
  5562. && _bfd_elf_section_offset (output_bfd, info, input_section,
  5563. +rel->r_offset) != (bfd_vma) - 1)
  5564. {
  5565. (*_bfd_error_handler)
  5566. (_
  5567. ("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
  5568. input_bfd, input_section, (long) rel->r_offset, howto->name,
  5569. h->root.root.string);
  5570. return FALSE;
  5571. }
  5572. if (r != bfd_reloc_ok && r != bfd_reloc_continue)
  5573. {
  5574. bfd_reloc_code_real_type real_r_type
  5575. = elfNN_aarch64_bfd_reloc_from_type (r_type);
  5576. switch (r)
  5577. {
  5578. case bfd_reloc_overflow:
  5579. if (!(*info->callbacks->reloc_overflow)
  5580. (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
  5581. input_bfd, input_section, rel->r_offset))
  5582. return FALSE;
  5583. if (real_r_type == BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
  5584. || real_r_type == BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14)
  5585. {
  5586. (*info->callbacks->warning)
  5587. (info,
  5588. _("Too many GOT entries for -fpic, "
  5589. "please recompile with -fPIC"),
  5590. name, input_bfd, input_section, rel->r_offset);
  5591. return FALSE;
  5592. }
  5593. break;
  5594. case bfd_reloc_undefined:
  5595. if (!((*info->callbacks->undefined_symbol)
  5596. (info, name, input_bfd, input_section,
  5597. rel->r_offset, TRUE)))
  5598. return FALSE;
  5599. break;
  5600. case bfd_reloc_outofrange:
  5601. error_message = _("out of range");
  5602. goto common_error;
  5603. case bfd_reloc_notsupported:
  5604. error_message = _("unsupported relocation");
  5605. goto common_error;
  5606. case bfd_reloc_dangerous:
  5607. /* error_message should already be set. */
  5608. goto common_error;
  5609. default:
  5610. error_message = _("unknown error");
  5611. /* Fall through. */
  5612. common_error:
  5613. BFD_ASSERT (error_message != NULL);
  5614. if (!((*info->callbacks->reloc_dangerous)
  5615. (info, error_message, input_bfd, input_section,
  5616. rel->r_offset)))
  5617. return FALSE;
  5618. break;
  5619. }
  5620. }
  5621. }
  5622. return TRUE;
  5623. }
  5624. /* Set the right machine number. */
  5625. static bfd_boolean
  5626. elfNN_aarch64_object_p (bfd *abfd)
  5627. {
  5628. #if ARCH_SIZE == 32
  5629. bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64_ilp32);
  5630. #else
  5631. bfd_default_set_arch_mach (abfd, bfd_arch_aarch64, bfd_mach_aarch64);
  5632. #endif
  5633. return TRUE;
  5634. }
  5635. /* Function to keep AArch64 specific flags in the ELF header. */
  5636. static bfd_boolean
  5637. elfNN_aarch64_set_private_flags (bfd *abfd, flagword flags)
  5638. {
  5639. if (elf_flags_init (abfd) && elf_elfheader (abfd)->e_flags != flags)
  5640. {
  5641. }
  5642. else
  5643. {
  5644. elf_elfheader (abfd)->e_flags = flags;
  5645. elf_flags_init (abfd) = TRUE;
  5646. }
  5647. return TRUE;
  5648. }
  5649. /* Merge backend specific data from an object file to the output
  5650. object file when linking. */
  5651. static bfd_boolean
  5652. elfNN_aarch64_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
  5653. {
  5654. flagword out_flags;
  5655. flagword in_flags;
  5656. bfd_boolean flags_compatible = TRUE;
  5657. asection *sec;
  5658. /* Check if we have the same endianess. */
  5659. if (!_bfd_generic_verify_endian_match (ibfd, obfd))
  5660. return FALSE;
  5661. if (!is_aarch64_elf (ibfd) || !is_aarch64_elf (obfd))
  5662. return TRUE;
  5663. /* The input BFD must have had its flags initialised. */
  5664. /* The following seems bogus to me -- The flags are initialized in
  5665. the assembler but I don't think an elf_flags_init field is
  5666. written into the object. */
  5667. /* BFD_ASSERT (elf_flags_init (ibfd)); */
  5668. in_flags = elf_elfheader (ibfd)->e_flags;
  5669. out_flags = elf_elfheader (obfd)->e_flags;
  5670. if (!elf_flags_init (obfd))
  5671. {
  5672. /* If the input is the default architecture and had the default
  5673. flags then do not bother setting the flags for the output
  5674. architecture, instead allow future merges to do this. If no
  5675. future merges ever set these flags then they will retain their
  5676. uninitialised values, which surprise surprise, correspond
  5677. to the default values. */
  5678. if (bfd_get_arch_info (ibfd)->the_default
  5679. && elf_elfheader (ibfd)->e_flags == 0)
  5680. return TRUE;
  5681. elf_flags_init (obfd) = TRUE;
  5682. elf_elfheader (obfd)->e_flags = in_flags;
  5683. if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
  5684. && bfd_get_arch_info (obfd)->the_default)
  5685. return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
  5686. bfd_get_mach (ibfd));
  5687. return TRUE;
  5688. }
  5689. /* Identical flags must be compatible. */
  5690. if (in_flags == out_flags)
  5691. return TRUE;
  5692. /* Check to see if the input BFD actually contains any sections. If
  5693. not, its flags may not have been initialised either, but it
  5694. cannot actually cause any incompatiblity. Do not short-circuit
  5695. dynamic objects; their section list may be emptied by
  5696. elf_link_add_object_symbols.
  5697. Also check to see if there are no code sections in the input.
  5698. In this case there is no need to check for code specific flags.
  5699. XXX - do we need to worry about floating-point format compatability
  5700. in data sections ? */
  5701. if (!(ibfd->flags & DYNAMIC))
  5702. {
  5703. bfd_boolean null_input_bfd = TRUE;
  5704. bfd_boolean only_data_sections = TRUE;
  5705. for (sec = ibfd->sections; sec != NULL; sec = sec->next)
  5706. {
  5707. if ((bfd_get_section_flags (ibfd, sec)
  5708. & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
  5709. == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
  5710. only_data_sections = FALSE;
  5711. null_input_bfd = FALSE;
  5712. break;
  5713. }
  5714. if (null_input_bfd || only_data_sections)
  5715. return TRUE;
  5716. }
  5717. return flags_compatible;
  5718. }
  5719. /* Display the flags field. */
  5720. static bfd_boolean
  5721. elfNN_aarch64_print_private_bfd_data (bfd *abfd, void *ptr)
  5722. {
  5723. FILE *file = (FILE *) ptr;
  5724. unsigned long flags;
  5725. BFD_ASSERT (abfd != NULL && ptr != NULL);
  5726. /* Print normal ELF private data. */
  5727. _bfd_elf_print_private_bfd_data (abfd, ptr);
  5728. flags = elf_elfheader (abfd)->e_flags;
  5729. /* Ignore init flag - it may not be set, despite the flags field
  5730. containing valid data. */
  5731. /* xgettext:c-format */
  5732. fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
  5733. if (flags)
  5734. fprintf (file, _("<Unrecognised flag bits set>"));
  5735. fputc ('\n', file);
  5736. return TRUE;
  5737. }
  5738. /* Update the got entry reference counts for the section being removed. */
  5739. static bfd_boolean
  5740. elfNN_aarch64_gc_sweep_hook (bfd *abfd,
  5741. struct bfd_link_info *info,
  5742. asection *sec,
  5743. const Elf_Internal_Rela * relocs)
  5744. {
  5745. struct elf_aarch64_link_hash_table *htab;
  5746. Elf_Internal_Shdr *symtab_hdr;
  5747. struct elf_link_hash_entry **sym_hashes;
  5748. struct elf_aarch64_local_symbol *locals;
  5749. const Elf_Internal_Rela *rel, *relend;
  5750. if (bfd_link_relocatable (info))
  5751. return TRUE;
  5752. htab = elf_aarch64_hash_table (info);
  5753. if (htab == NULL)
  5754. return FALSE;
  5755. elf_section_data (sec)->local_dynrel = NULL;
  5756. symtab_hdr = &elf_symtab_hdr (abfd);
  5757. sym_hashes = elf_sym_hashes (abfd);
  5758. locals = elf_aarch64_locals (abfd);
  5759. relend = relocs + sec->reloc_count;
  5760. for (rel = relocs; rel < relend; rel++)
  5761. {
  5762. unsigned long r_symndx;
  5763. unsigned int r_type;
  5764. struct elf_link_hash_entry *h = NULL;
  5765. r_symndx = ELFNN_R_SYM (rel->r_info);
  5766. if (r_symndx >= symtab_hdr->sh_info)
  5767. {
  5768. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  5769. while (h->root.type == bfd_link_hash_indirect
  5770. || h->root.type == bfd_link_hash_warning)
  5771. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  5772. }
  5773. else
  5774. {
  5775. Elf_Internal_Sym *isym;
  5776. /* A local symbol. */
  5777. isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  5778. abfd, r_symndx);
  5779. /* Check relocation against local STT_GNU_IFUNC symbol. */
  5780. if (isym != NULL
  5781. && ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
  5782. {
  5783. h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel, FALSE);
  5784. if (h == NULL)
  5785. abort ();
  5786. }
  5787. }
  5788. if (h)
  5789. {
  5790. struct elf_aarch64_link_hash_entry *eh;
  5791. struct elf_dyn_relocs **pp;
  5792. struct elf_dyn_relocs *p;
  5793. eh = (struct elf_aarch64_link_hash_entry *) h;
  5794. for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
  5795. if (p->sec == sec)
  5796. {
  5797. /* Everything must go for SEC. */
  5798. *pp = p->next;
  5799. break;
  5800. }
  5801. }
  5802. r_type = ELFNN_R_TYPE (rel->r_info);
  5803. switch (aarch64_tls_transition (abfd,info, r_type, h ,r_symndx))
  5804. {
  5805. case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
  5806. case BFD_RELOC_AARCH64_GOT_LD_PREL19:
  5807. case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
  5808. case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
  5809. case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
  5810. case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
  5811. case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
  5812. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
  5813. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
  5814. case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
  5815. case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
  5816. case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
  5817. case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
  5818. case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
  5819. case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
  5820. case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
  5821. case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
  5822. case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
  5823. case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
  5824. case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
  5825. case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
  5826. case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
  5827. case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
  5828. case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
  5829. case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
  5830. case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
  5831. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
  5832. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
  5833. case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
  5834. case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
  5835. case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
  5836. if (h != NULL)
  5837. {
  5838. if (h->got.refcount > 0)
  5839. h->got.refcount -= 1;
  5840. if (h->type == STT_GNU_IFUNC)
  5841. {
  5842. if (h->plt.refcount > 0)
  5843. h->plt.refcount -= 1;
  5844. }
  5845. }
  5846. else if (locals != NULL)
  5847. {
  5848. if (locals[r_symndx].got_refcount > 0)
  5849. locals[r_symndx].got_refcount -= 1;
  5850. }
  5851. break;
  5852. case BFD_RELOC_AARCH64_CALL26:
  5853. case BFD_RELOC_AARCH64_JUMP26:
  5854. /* If this is a local symbol then we resolve it
  5855. directly without creating a PLT entry. */
  5856. if (h == NULL)
  5857. continue;
  5858. if (h->plt.refcount > 0)
  5859. h->plt.refcount -= 1;
  5860. break;
  5861. case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
  5862. case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
  5863. case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
  5864. case BFD_RELOC_AARCH64_MOVW_G0_NC:
  5865. case BFD_RELOC_AARCH64_MOVW_G1_NC:
  5866. case BFD_RELOC_AARCH64_MOVW_G2_NC:
  5867. case BFD_RELOC_AARCH64_MOVW_G3:
  5868. case BFD_RELOC_AARCH64_NN:
  5869. if (h != NULL && bfd_link_executable (info))
  5870. {
  5871. if (h->plt.refcount > 0)
  5872. h->plt.refcount -= 1;
  5873. }
  5874. break;
  5875. default:
  5876. break;
  5877. }
  5878. }
  5879. return TRUE;
  5880. }
  5881. /* Adjust a symbol defined by a dynamic object and referenced by a
  5882. regular object. The current definition is in some section of the
  5883. dynamic object, but we're not including those sections. We have to
  5884. change the definition to something the rest of the link can
  5885. understand. */
  5886. static bfd_boolean
  5887. elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info,
  5888. struct elf_link_hash_entry *h)
  5889. {
  5890. struct elf_aarch64_link_hash_table *htab;
  5891. asection *s;
  5892. /* If this is a function, put it in the procedure linkage table. We
  5893. will fill in the contents of the procedure linkage table later,
  5894. when we know the address of the .got section. */
  5895. if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
  5896. {
  5897. if (h->plt.refcount <= 0
  5898. || (h->type != STT_GNU_IFUNC
  5899. && (SYMBOL_CALLS_LOCAL (info, h)
  5900. || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
  5901. && h->root.type == bfd_link_hash_undefweak))))
  5902. {
  5903. /* This case can occur if we saw a CALL26 reloc in
  5904. an input file, but the symbol wasn't referred to
  5905. by a dynamic object or all references were
  5906. garbage collected. In which case we can end up
  5907. resolving. */
  5908. h->plt.offset = (bfd_vma) - 1;
  5909. h->needs_plt = 0;
  5910. }
  5911. return TRUE;
  5912. }
  5913. else
  5914. /* Otherwise, reset to -1. */
  5915. h->plt.offset = (bfd_vma) - 1;
  5916. /* If this is a weak symbol, and there is a real definition, the
  5917. processor independent code will have arranged for us to see the
  5918. real definition first, and we can just use the same value. */
  5919. if (h->u.weakdef != NULL)
  5920. {
  5921. BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
  5922. || h->u.weakdef->root.type == bfd_link_hash_defweak);
  5923. h->root.u.def.section = h->u.weakdef->root.u.def.section;
  5924. h->root.u.def.value = h->u.weakdef->root.u.def.value;
  5925. if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
  5926. h->non_got_ref = h->u.weakdef->non_got_ref;
  5927. return TRUE;
  5928. }
  5929. /* If we are creating a shared library, we must presume that the
  5930. only references to the symbol are via the global offset table.
  5931. For such cases we need not do anything here; the relocations will
  5932. be handled correctly by relocate_section. */
  5933. if (bfd_link_pic (info))
  5934. return TRUE;
  5935. /* If there are no references to this symbol that do not use the
  5936. GOT, we don't need to generate a copy reloc. */
  5937. if (!h->non_got_ref)
  5938. return TRUE;
  5939. /* If -z nocopyreloc was given, we won't generate them either. */
  5940. if (info->nocopyreloc)
  5941. {
  5942. h->non_got_ref = 0;
  5943. return TRUE;
  5944. }
  5945. /* We must allocate the symbol in our .dynbss section, which will
  5946. become part of the .bss section of the executable. There will be
  5947. an entry for this symbol in the .dynsym section. The dynamic
  5948. object will contain position independent code, so all references
  5949. from the dynamic object to this symbol will go through the global
  5950. offset table. The dynamic linker will use the .dynsym entry to
  5951. determine the address it must put in the global offset table, so
  5952. both the dynamic object and the regular object will refer to the
  5953. same memory location for the variable. */
  5954. htab = elf_aarch64_hash_table (info);
  5955. /* We must generate a R_AARCH64_COPY reloc to tell the dynamic linker
  5956. to copy the initial value out of the dynamic object and into the
  5957. runtime process image. */
  5958. if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
  5959. {
  5960. htab->srelbss->size += RELOC_SIZE (htab);
  5961. h->needs_copy = 1;
  5962. }
  5963. s = htab->sdynbss;
  5964. return _bfd_elf_adjust_dynamic_copy (info, h, s);
  5965. }
  5966. static bfd_boolean
  5967. elfNN_aarch64_allocate_local_symbols (bfd *abfd, unsigned number)
  5968. {
  5969. struct elf_aarch64_local_symbol *locals;
  5970. locals = elf_aarch64_locals (abfd);
  5971. if (locals == NULL)
  5972. {
  5973. locals = (struct elf_aarch64_local_symbol *)
  5974. bfd_zalloc (abfd, number * sizeof (struct elf_aarch64_local_symbol));
  5975. if (locals == NULL)
  5976. return FALSE;
  5977. elf_aarch64_locals (abfd) = locals;
  5978. }
  5979. return TRUE;
  5980. }
  5981. /* Create the .got section to hold the global offset table. */
  5982. static bfd_boolean
  5983. aarch64_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
  5984. {
  5985. const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  5986. flagword flags;
  5987. asection *s;
  5988. struct elf_link_hash_entry *h;
  5989. struct elf_link_hash_table *htab = elf_hash_table (info);
  5990. /* This function may be called more than once. */
  5991. s = bfd_get_linker_section (abfd, ".got");
  5992. if (s != NULL)
  5993. return TRUE;
  5994. flags = bed->dynamic_sec_flags;
  5995. s = bfd_make_section_anyway_with_flags (abfd,
  5996. (bed->rela_plts_and_copies_p
  5997. ? ".rela.got" : ".rel.got"),
  5998. (bed->dynamic_sec_flags
  5999. | SEC_READONLY));
  6000. if (s == NULL
  6001. || ! bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
  6002. return FALSE;
  6003. htab->srelgot = s;
  6004. s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
  6005. if (s == NULL
  6006. || !bfd_set_section_alignment (abfd, s, bed->s->log_file_align))
  6007. return FALSE;
  6008. htab->sgot = s;
  6009. htab->sgot->size += GOT_ENTRY_SIZE;
  6010. if (bed->want_got_sym)
  6011. {
  6012. /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
  6013. (or .got.plt) section. We don't do this in the linker script
  6014. because we don't want to define the symbol if we are not creating
  6015. a global offset table. */
  6016. h = _bfd_elf_define_linkage_sym (abfd, info, s,
  6017. "_GLOBAL_OFFSET_TABLE_");
  6018. elf_hash_table (info)->hgot = h;
  6019. if (h == NULL)
  6020. return FALSE;
  6021. }
  6022. if (bed->want_got_plt)
  6023. {
  6024. s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags);
  6025. if (s == NULL
  6026. || !bfd_set_section_alignment (abfd, s,
  6027. bed->s->log_file_align))
  6028. return FALSE;
  6029. htab->sgotplt = s;
  6030. }
  6031. /* The first bit of the global offset table is the header. */
  6032. s->size += bed->got_header_size;
  6033. return TRUE;
  6034. }
  6035. /* Look through the relocs for a section during the first phase. */
  6036. static bfd_boolean
  6037. elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
  6038. asection *sec, const Elf_Internal_Rela *relocs)
  6039. {
  6040. Elf_Internal_Shdr *symtab_hdr;
  6041. struct elf_link_hash_entry **sym_hashes;
  6042. const Elf_Internal_Rela *rel;
  6043. const Elf_Internal_Rela *rel_end;
  6044. asection *sreloc;
  6045. struct elf_aarch64_link_hash_table *htab;
  6046. if (bfd_link_relocatable (info))
  6047. return TRUE;
  6048. BFD_ASSERT (is_aarch64_elf (abfd));
  6049. htab = elf_aarch64_hash_table (info);
  6050. sreloc = NULL;
  6051. symtab_hdr = &elf_symtab_hdr (abfd);
  6052. sym_hashes = elf_sym_hashes (abfd);
  6053. rel_end = relocs + sec->reloc_count;
  6054. for (rel = relocs; rel < rel_end; rel++)
  6055. {
  6056. struct elf_link_hash_entry *h;
  6057. unsigned long r_symndx;
  6058. unsigned int r_type;
  6059. bfd_reloc_code_real_type bfd_r_type;
  6060. Elf_Internal_Sym *isym;
  6061. r_symndx = ELFNN_R_SYM (rel->r_info);
  6062. r_type = ELFNN_R_TYPE (rel->r_info);
  6063. if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
  6064. {
  6065. (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
  6066. r_symndx);
  6067. return FALSE;
  6068. }
  6069. if (r_symndx < symtab_hdr->sh_info)
  6070. {
  6071. /* A local symbol. */
  6072. isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  6073. abfd, r_symndx);
  6074. if (isym == NULL)
  6075. return FALSE;
  6076. /* Check relocation against local STT_GNU_IFUNC symbol. */
  6077. if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
  6078. {
  6079. h = elfNN_aarch64_get_local_sym_hash (htab, abfd, rel,
  6080. TRUE);
  6081. if (h == NULL)
  6082. return FALSE;
  6083. /* Fake a STT_GNU_IFUNC symbol. */
  6084. h->type = STT_GNU_IFUNC;
  6085. h->def_regular = 1;
  6086. h->ref_regular = 1;
  6087. h->forced_local = 1;
  6088. h->root.type = bfd_link_hash_defined;
  6089. }
  6090. else
  6091. h = NULL;
  6092. }
  6093. else
  6094. {
  6095. h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  6096. while (h->root.type == bfd_link_hash_indirect
  6097. || h->root.type == bfd_link_hash_warning)
  6098. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  6099. /* PR15323, ref flags aren't set for references in the same
  6100. object. */
  6101. h->root.non_ir_ref = 1;
  6102. }
  6103. /* Could be done earlier, if h were already available. */
  6104. bfd_r_type = aarch64_tls_transition (abfd, info, r_type, h, r_symndx);
  6105. if (h != NULL)
  6106. {
  6107. /* Create the ifunc sections for static executables. If we
  6108. never see an indirect function symbol nor we are building
  6109. a static executable, those sections will be empty and
  6110. won't appear in output. */
  6111. switch (bfd_r_type)
  6112. {
  6113. default:
  6114. break;
  6115. case BFD_RELOC_AARCH64_ADD_LO12:
  6116. case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
  6117. case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
  6118. case BFD_RELOC_AARCH64_CALL26:
  6119. case BFD_RELOC_AARCH64_GOT_LD_PREL19:
  6120. case BFD_RELOC_AARCH64_JUMP26:
  6121. case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
  6122. case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
  6123. case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
  6124. case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
  6125. case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
  6126. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
  6127. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
  6128. case BFD_RELOC_AARCH64_NN:
  6129. if (htab->root.dynobj == NULL)
  6130. htab->root.dynobj = abfd;
  6131. if (!_bfd_elf_create_ifunc_sections (htab->root.dynobj, info))
  6132. return FALSE;
  6133. break;
  6134. }
  6135. /* It is referenced by a non-shared object. */
  6136. h->ref_regular = 1;
  6137. h->root.non_ir_ref = 1;
  6138. }
  6139. switch (bfd_r_type)
  6140. {
  6141. case BFD_RELOC_AARCH64_NN:
  6142. /* We don't need to handle relocs into sections not going into
  6143. the "real" output. */
  6144. if ((sec->flags & SEC_ALLOC) == 0)
  6145. break;
  6146. if (h != NULL)
  6147. {
  6148. if (!bfd_link_pic (info))
  6149. h->non_got_ref = 1;
  6150. h->plt.refcount += 1;
  6151. h->pointer_equality_needed = 1;
  6152. }
  6153. /* No need to do anything if we're not creating a shared
  6154. object. */
  6155. if (! bfd_link_pic (info))
  6156. break;
  6157. {
  6158. struct elf_dyn_relocs *p;
  6159. struct elf_dyn_relocs **head;
  6160. /* We must copy these reloc types into the output file.
  6161. Create a reloc section in dynobj and make room for
  6162. this reloc. */
  6163. if (sreloc == NULL)
  6164. {
  6165. if (htab->root.dynobj == NULL)
  6166. htab->root.dynobj = abfd;
  6167. sreloc = _bfd_elf_make_dynamic_reloc_section
  6168. (sec, htab->root.dynobj, LOG_FILE_ALIGN, abfd, /*rela? */ TRUE);
  6169. if (sreloc == NULL)
  6170. return FALSE;
  6171. }
  6172. /* If this is a global symbol, we count the number of
  6173. relocations we need for this symbol. */
  6174. if (h != NULL)
  6175. {
  6176. struct elf_aarch64_link_hash_entry *eh;
  6177. eh = (struct elf_aarch64_link_hash_entry *) h;
  6178. head = &eh->dyn_relocs;
  6179. }
  6180. else
  6181. {
  6182. /* Track dynamic relocs needed for local syms too.
  6183. We really need local syms available to do this
  6184. easily. Oh well. */
  6185. asection *s;
  6186. void **vpp;
  6187. isym = bfd_sym_from_r_symndx (&htab->sym_cache,
  6188. abfd, r_symndx);
  6189. if (isym == NULL)
  6190. return FALSE;
  6191. s = bfd_section_from_elf_index (abfd, isym->st_shndx);
  6192. if (s == NULL)
  6193. s = sec;
  6194. /* Beware of type punned pointers vs strict aliasing
  6195. rules. */
  6196. vpp = &(elf_section_data (s)->local_dynrel);
  6197. head = (struct elf_dyn_relocs **) vpp;
  6198. }
  6199. p = *head;
  6200. if (p == NULL || p->sec != sec)
  6201. {
  6202. bfd_size_type amt = sizeof *p;
  6203. p = ((struct elf_dyn_relocs *)
  6204. bfd_zalloc (htab->root.dynobj, amt));
  6205. if (p == NULL)
  6206. return FALSE;
  6207. p->next = *head;
  6208. *head = p;
  6209. p->sec = sec;
  6210. }
  6211. p->count += 1;
  6212. }
  6213. break;
  6214. /* RR: We probably want to keep a consistency check that
  6215. there are no dangling GOT_PAGE relocs. */
  6216. case BFD_RELOC_AARCH64_ADR_GOT_PAGE:
  6217. case BFD_RELOC_AARCH64_GOT_LD_PREL19:
  6218. case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14:
  6219. case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC:
  6220. case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15:
  6221. case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15:
  6222. case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
  6223. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
  6224. case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
  6225. case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
  6226. case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
  6227. case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
  6228. case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC:
  6229. case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
  6230. case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
  6231. case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
  6232. case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
  6233. case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
  6234. case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
  6235. case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
  6236. case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
  6237. case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
  6238. case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
  6239. case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
  6240. case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
  6241. case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
  6242. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC:
  6243. case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1:
  6244. case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
  6245. case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
  6246. case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
  6247. case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1:
  6248. case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
  6249. case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2:
  6250. {
  6251. unsigned got_type;
  6252. unsigned old_got_type;
  6253. got_type = aarch64_reloc_got_type (bfd_r_type);
  6254. if (h)
  6255. {
  6256. h->got.refcount += 1;
  6257. old_got_type = elf_aarch64_hash_entry (h)->got_type;
  6258. }
  6259. else
  6260. {
  6261. struct elf_aarch64_local_symbol *locals;
  6262. if (!elfNN_aarch64_allocate_local_symbols
  6263. (abfd, symtab_hdr->sh_info))
  6264. return FALSE;
  6265. locals = elf_aarch64_locals (abfd);
  6266. BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
  6267. locals[r_symndx].got_refcount += 1;
  6268. old_got_type = locals[r_symndx].got_type;
  6269. }
  6270. /* If a variable is accessed with both general dynamic TLS
  6271. methods, two slots may be created. */
  6272. if (GOT_TLS_GD_ANY_P (old_got_type) && GOT_TLS_GD_ANY_P (got_type))
  6273. got_type |= old_got_type;
  6274. /* We will already have issued an error message if there
  6275. is a TLS/non-TLS mismatch, based on the symbol type.
  6276. So just combine any TLS types needed. */
  6277. if (old_got_type != GOT_UNKNOWN && old_got_type != GOT_NORMAL
  6278. && got_type != GOT_NORMAL)
  6279. got_type |= old_got_type;
  6280. /* If the symbol is accessed by both IE and GD methods, we
  6281. are able to relax. Turn off the GD flag, without
  6282. messing up with any other kind of TLS types that may be
  6283. involved. */
  6284. if ((got_type & GOT_TLS_IE) && GOT_TLS_GD_ANY_P (got_type))
  6285. got_type &= ~ (GOT_TLSDESC_GD | GOT_TLS_GD);
  6286. if (old_got_type != got_type)
  6287. {
  6288. if (h != NULL)
  6289. elf_aarch64_hash_entry (h)->got_type = got_type;
  6290. else
  6291. {
  6292. struct elf_aarch64_local_symbol *locals;
  6293. locals = elf_aarch64_locals (abfd);
  6294. BFD_ASSERT (r_symndx < symtab_hdr->sh_info);
  6295. locals[r_symndx].got_type = got_type;
  6296. }
  6297. }
  6298. if (htab->root.dynobj == NULL)
  6299. htab->root.dynobj = abfd;
  6300. if (! aarch64_elf_create_got_section (htab->root.dynobj, info))
  6301. return FALSE;
  6302. break;
  6303. }
  6304. case BFD_RELOC_AARCH64_MOVW_G0_NC:
  6305. case BFD_RELOC_AARCH64_MOVW_G1_NC:
  6306. case BFD_RELOC_AARCH64_MOVW_G2_NC:
  6307. case BFD_RELOC_AARCH64_MOVW_G3:
  6308. if (bfd_link_pic (info))
  6309. {
  6310. int howto_index = bfd_r_type - BFD_RELOC_AARCH64_RELOC_START;
  6311. (*_bfd_error_handler)
  6312. (_("%B: relocation %s against `%s' can not be used when making "
  6313. "a shared object; recompile with -fPIC"),
  6314. abfd, elfNN_aarch64_howto_table[howto_index].name,
  6315. (h) ? h->root.root.string : "a local symbol");
  6316. bfd_set_error (bfd_error_bad_value);
  6317. return FALSE;
  6318. }
  6319. case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL:
  6320. case BFD_RELOC_AARCH64_ADR_HI21_PCREL:
  6321. case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
  6322. if (h != NULL && bfd_link_executable (info))
  6323. {
  6324. /* If this reloc is in a read-only section, we might
  6325. need a copy reloc. We can't check reliably at this
  6326. stage whether the section is read-only, as input
  6327. sections have not yet been mapped to output sections.
  6328. Tentatively set the flag for now, and correct in
  6329. adjust_dynamic_symbol. */
  6330. h->non_got_ref = 1;
  6331. h->plt.refcount += 1;
  6332. h->pointer_equality_needed = 1;
  6333. }
  6334. /* FIXME:: RR need to handle these in shared libraries
  6335. and essentially bomb out as these being non-PIC
  6336. relocations in shared libraries. */
  6337. break;
  6338. case BFD_RELOC_AARCH64_CALL26:
  6339. case BFD_RELOC_AARCH64_JUMP26:
  6340. /* If this is a local symbol then we resolve it
  6341. directly without creating a PLT entry. */
  6342. if (h == NULL)
  6343. continue;
  6344. h->needs_plt = 1;
  6345. if (h->plt.refcount <= 0)
  6346. h->plt.refcount = 1;
  6347. else
  6348. h->plt.refcount += 1;
  6349. break;
  6350. default:
  6351. break;
  6352. }
  6353. }
  6354. return TRUE;
  6355. }
  6356. /* Treat mapping symbols as special target symbols. */
  6357. static bfd_boolean
  6358. elfNN_aarch64_is_target_special_symbol (bfd *abfd ATTRIBUTE_UNUSED,
  6359. asymbol *sym)
  6360. {
  6361. return bfd_is_aarch64_special_symbol_name (sym->name,
  6362. BFD_AARCH64_SPECIAL_SYM_TYPE_ANY);
  6363. }
  6364. /* This is a copy of elf_find_function () from elf.c except that
  6365. AArch64 mapping symbols are ignored when looking for function names. */
  6366. static bfd_boolean
  6367. aarch64_elf_find_function (bfd *abfd ATTRIBUTE_UNUSED,
  6368. asymbol **symbols,
  6369. asection *section,
  6370. bfd_vma offset,
  6371. const char **filename_ptr,
  6372. const char **functionname_ptr)
  6373. {
  6374. const char *filename = NULL;
  6375. asymbol *func = NULL;
  6376. bfd_vma low_func = 0;
  6377. asymbol **p;
  6378. for (p = symbols; *p != NULL; p++)
  6379. {
  6380. elf_symbol_type *q;
  6381. q = (elf_symbol_type *) * p;
  6382. switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
  6383. {
  6384. default:
  6385. break;
  6386. case STT_FILE:
  6387. filename = bfd_asymbol_name (&q->symbol);
  6388. break;
  6389. case STT_FUNC:
  6390. case STT_NOTYPE:
  6391. /* Skip mapping symbols. */
  6392. if ((q->symbol.flags & BSF_LOCAL)
  6393. && (bfd_is_aarch64_special_symbol_name
  6394. (q->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)))
  6395. continue;
  6396. /* Fall through. */
  6397. if (bfd_get_section (&q->symbol) == section
  6398. && q->symbol.value >= low_func && q->symbol.value <= offset)
  6399. {
  6400. func = (asymbol *) q;
  6401. low_func = q->symbol.value;
  6402. }
  6403. break;
  6404. }
  6405. }
  6406. if (func == NULL)
  6407. return FALSE;
  6408. if (filename_ptr)
  6409. *filename_ptr = filename;
  6410. if (functionname_ptr)
  6411. *functionname_ptr = bfd_asymbol_name (func);
  6412. return TRUE;
  6413. }
  6414. /* Find the nearest line to a particular section and offset, for error
  6415. reporting. This code is a duplicate of the code in elf.c, except
  6416. that it uses aarch64_elf_find_function. */
  6417. static bfd_boolean
  6418. elfNN_aarch64_find_nearest_line (bfd *abfd,
  6419. asymbol **symbols,
  6420. asection *section,
  6421. bfd_vma offset,
  6422. const char **filename_ptr,
  6423. const char **functionname_ptr,
  6424. unsigned int *line_ptr,
  6425. unsigned int *discriminator_ptr)
  6426. {
  6427. bfd_boolean found = FALSE;
  6428. if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset,
  6429. filename_ptr, functionname_ptr,
  6430. line_ptr, discriminator_ptr,
  6431. dwarf_debug_sections, 0,
  6432. &elf_tdata (abfd)->dwarf2_find_line_info))
  6433. {
  6434. if (!*functionname_ptr)
  6435. aarch64_elf_find_function (abfd, symbols, section, offset,
  6436. *filename_ptr ? NULL : filename_ptr,
  6437. functionname_ptr);
  6438. return TRUE;
  6439. }
  6440. /* Skip _bfd_dwarf1_find_nearest_line since no known AArch64
  6441. toolchain uses DWARF1. */
  6442. if (!_bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
  6443. &found, filename_ptr,
  6444. functionname_ptr, line_ptr,
  6445. &elf_tdata (abfd)->line_info))
  6446. return FALSE;
  6447. if (found && (*functionname_ptr || *line_ptr))
  6448. return TRUE;
  6449. if (symbols == NULL)
  6450. return FALSE;
  6451. if (!aarch64_elf_find_function (abfd, symbols, section, offset,
  6452. filename_ptr, functionname_ptr))
  6453. return FALSE;
  6454. *line_ptr = 0;
  6455. return TRUE;
  6456. }
  6457. static bfd_boolean
  6458. elfNN_aarch64_find_inliner_info (bfd *abfd,
  6459. const char **filename_ptr,
  6460. const char **functionname_ptr,
  6461. unsigned int *line_ptr)
  6462. {
  6463. bfd_boolean found;
  6464. found = _bfd_dwarf2_find_inliner_info
  6465. (abfd, filename_ptr,
  6466. functionname_ptr, line_ptr, &elf_tdata (abfd)->dwarf2_find_line_info);
  6467. return found;
  6468. }
  6469. static void
  6470. elfNN_aarch64_post_process_headers (bfd *abfd,
  6471. struct bfd_link_info *link_info)
  6472. {
  6473. Elf_Internal_Ehdr *i_ehdrp; /* ELF file header, internal form. */
  6474. i_ehdrp = elf_elfheader (abfd);
  6475. i_ehdrp->e_ident[EI_ABIVERSION] = AARCH64_ELF_ABI_VERSION;
  6476. _bfd_elf_post_process_headers (abfd, link_info);
  6477. }
  6478. static enum elf_reloc_type_class
  6479. elfNN_aarch64_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
  6480. const asection *rel_sec ATTRIBUTE_UNUSED,
  6481. const Elf_Internal_Rela *rela)
  6482. {
  6483. switch ((int) ELFNN_R_TYPE (rela->r_info))
  6484. {
  6485. case AARCH64_R (RELATIVE):
  6486. return reloc_class_relative;
  6487. case AARCH64_R (JUMP_SLOT):
  6488. return reloc_class_plt;
  6489. case AARCH64_R (COPY):
  6490. return reloc_class_copy;
  6491. default:
  6492. return reloc_class_normal;
  6493. }
  6494. }
  6495. /* Handle an AArch64 specific section when reading an object file. This is
  6496. called when bfd_section_from_shdr finds a section with an unknown
  6497. type. */
  6498. static bfd_boolean
  6499. elfNN_aarch64_section_from_shdr (bfd *abfd,
  6500. Elf_Internal_Shdr *hdr,
  6501. const char *name, int shindex)
  6502. {
  6503. /* There ought to be a place to keep ELF backend specific flags, but
  6504. at the moment there isn't one. We just keep track of the
  6505. sections by their name, instead. Fortunately, the ABI gives
  6506. names for all the AArch64 specific sections, so we will probably get
  6507. away with this. */
  6508. switch (hdr->sh_type)
  6509. {
  6510. case SHT_AARCH64_ATTRIBUTES:
  6511. break;
  6512. default:
  6513. return FALSE;
  6514. }
  6515. if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
  6516. return FALSE;
  6517. return TRUE;
  6518. }
  6519. /* A structure used to record a list of sections, independently
  6520. of the next and prev fields in the asection structure. */
  6521. typedef struct section_list
  6522. {
  6523. asection *sec;
  6524. struct section_list *next;
  6525. struct section_list *prev;
  6526. }
  6527. section_list;
  6528. /* Unfortunately we need to keep a list of sections for which
  6529. an _aarch64_elf_section_data structure has been allocated. This
  6530. is because it is possible for functions like elfNN_aarch64_write_section
  6531. to be called on a section which has had an elf_data_structure
  6532. allocated for it (and so the used_by_bfd field is valid) but
  6533. for which the AArch64 extended version of this structure - the
  6534. _aarch64_elf_section_data structure - has not been allocated. */
  6535. static section_list *sections_with_aarch64_elf_section_data = NULL;
  6536. static void
  6537. record_section_with_aarch64_elf_section_data (asection *sec)
  6538. {
  6539. struct section_list *entry;
  6540. entry = bfd_malloc (sizeof (*entry));
  6541. if (entry == NULL)
  6542. return;
  6543. entry->sec = sec;
  6544. entry->next = sections_with_aarch64_elf_section_data;
  6545. entry->prev = NULL;
  6546. if (entry->next != NULL)
  6547. entry->next->prev = entry;
  6548. sections_with_aarch64_elf_section_data = entry;
  6549. }
  6550. static struct section_list *
  6551. find_aarch64_elf_section_entry (asection *sec)
  6552. {
  6553. struct section_list *entry;
  6554. static struct section_list *last_entry = NULL;
  6555. /* This is a short cut for the typical case where the sections are added
  6556. to the sections_with_aarch64_elf_section_data list in forward order and
  6557. then looked up here in backwards order. This makes a real difference
  6558. to the ld-srec/sec64k.exp linker test. */
  6559. entry = sections_with_aarch64_elf_section_data;
  6560. if (last_entry != NULL)
  6561. {
  6562. if (last_entry->sec == sec)
  6563. entry = last_entry;
  6564. else if (last_entry->next != NULL && last_entry->next->sec == sec)
  6565. entry = last_entry->next;
  6566. }
  6567. for (; entry; entry = entry->next)
  6568. if (entry->sec == sec)
  6569. break;
  6570. if (entry)
  6571. /* Record the entry prior to this one - it is the entry we are
  6572. most likely to want to locate next time. Also this way if we
  6573. have been called from
  6574. unrecord_section_with_aarch64_elf_section_data () we will not
  6575. be caching a pointer that is about to be freed. */
  6576. last_entry = entry->prev;
  6577. return entry;
  6578. }
  6579. static void
  6580. unrecord_section_with_aarch64_elf_section_data (asection *sec)
  6581. {
  6582. struct section_list *entry;
  6583. entry = find_aarch64_elf_section_entry (sec);
  6584. if (entry)
  6585. {
  6586. if (entry->prev != NULL)
  6587. entry->prev->next = entry->next;
  6588. if (entry->next != NULL)
  6589. entry->next->prev = entry->prev;
  6590. if (entry == sections_with_aarch64_elf_section_data)
  6591. sections_with_aarch64_elf_section_data = entry->next;
  6592. free (entry);
  6593. }
  6594. }
  6595. typedef struct
  6596. {
  6597. void *finfo;
  6598. struct bfd_link_info *info;
  6599. asection *sec;
  6600. int sec_shndx;
  6601. int (*func) (void *, const char *, Elf_Internal_Sym *,
  6602. asection *, struct elf_link_hash_entry *);
  6603. } output_arch_syminfo;
  6604. enum map_symbol_type
  6605. {
  6606. AARCH64_MAP_INSN,
  6607. AARCH64_MAP_DATA
  6608. };
  6609. /* Output a single mapping symbol. */
  6610. static bfd_boolean
  6611. elfNN_aarch64_output_map_sym (output_arch_syminfo *osi,
  6612. enum map_symbol_type type, bfd_vma offset)
  6613. {
  6614. static const char *names[2] = { "$x", "$d" };
  6615. Elf_Internal_Sym sym;
  6616. sym.st_value = (osi->sec->output_section->vma
  6617. + osi->sec->output_offset + offset);
  6618. sym.st_size = 0;
  6619. sym.st_other = 0;
  6620. sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
  6621. sym.st_shndx = osi->sec_shndx;
  6622. return osi->func (osi->finfo, names[type], &sym, osi->sec, NULL) == 1;
  6623. }
  6624. /* Output a single local symbol for a generated stub. */
  6625. static bfd_boolean
  6626. elfNN_aarch64_output_stub_sym (output_arch_syminfo *osi, const char *name,
  6627. bfd_vma offset, bfd_vma size)
  6628. {
  6629. Elf_Internal_Sym sym;
  6630. sym.st_value = (osi->sec->output_section->vma
  6631. + osi->sec->output_offset + offset);
  6632. sym.st_size = size;
  6633. sym.st_other = 0;
  6634. sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
  6635. sym.st_shndx = osi->sec_shndx;
  6636. return osi->func (osi->finfo, name, &sym, osi->sec, NULL) == 1;
  6637. }
  6638. static bfd_boolean
  6639. aarch64_map_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
  6640. {
  6641. struct elf_aarch64_stub_hash_entry *stub_entry;
  6642. asection *stub_sec;
  6643. bfd_vma addr;
  6644. char *stub_name;
  6645. output_arch_syminfo *osi;
  6646. /* Massage our args to the form they really have. */
  6647. stub_entry = (struct elf_aarch64_stub_hash_entry *) gen_entry;
  6648. osi = (output_arch_syminfo *) in_arg;
  6649. stub_sec = stub_entry->stub_sec;
  6650. /* Ensure this stub is attached to the current section being
  6651. processed. */
  6652. if (stub_sec != osi->sec)
  6653. return TRUE;
  6654. addr = (bfd_vma) stub_entry->stub_offset;
  6655. stub_name = stub_entry->output_name;
  6656. switch (stub_entry->stub_type)
  6657. {
  6658. case aarch64_stub_adrp_branch:
  6659. if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
  6660. sizeof (aarch64_adrp_branch_stub)))
  6661. return FALSE;
  6662. if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
  6663. return FALSE;
  6664. break;
  6665. case aarch64_stub_long_branch:
  6666. if (!elfNN_aarch64_output_stub_sym
  6667. (osi, stub_name, addr, sizeof (aarch64_long_branch_stub)))
  6668. return FALSE;
  6669. if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
  6670. return FALSE;
  6671. if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_DATA, addr + 16))
  6672. return FALSE;
  6673. break;
  6674. case aarch64_stub_erratum_835769_veneer:
  6675. if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
  6676. sizeof (aarch64_erratum_835769_stub)))
  6677. return FALSE;
  6678. if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
  6679. return FALSE;
  6680. break;
  6681. case aarch64_stub_erratum_843419_veneer:
  6682. if (!elfNN_aarch64_output_stub_sym (osi, stub_name, addr,
  6683. sizeof (aarch64_erratum_843419_stub)))
  6684. return FALSE;
  6685. if (!elfNN_aarch64_output_map_sym (osi, AARCH64_MAP_INSN, addr))
  6686. return FALSE;
  6687. break;
  6688. default:
  6689. abort ();
  6690. }
  6691. return TRUE;
  6692. }
  6693. /* Output mapping symbols for linker generated sections. */
  6694. static bfd_boolean
  6695. elfNN_aarch64_output_arch_local_syms (bfd *output_bfd,
  6696. struct bfd_link_info *info,
  6697. void *finfo,
  6698. int (*func) (void *, const char *,
  6699. Elf_Internal_Sym *,
  6700. asection *,
  6701. struct elf_link_hash_entry
  6702. *))
  6703. {
  6704. output_arch_syminfo osi;
  6705. struct elf_aarch64_link_hash_table *htab;
  6706. htab = elf_aarch64_hash_table (info);
  6707. osi.finfo = finfo;
  6708. osi.info = info;
  6709. osi.func = func;
  6710. /* Long calls stubs. */
  6711. if (htab->stub_bfd && htab->stub_bfd->sections)
  6712. {
  6713. asection *stub_sec;
  6714. for (stub_sec = htab->stub_bfd->sections;
  6715. stub_sec != NULL; stub_sec = stub_sec->next)
  6716. {
  6717. /* Ignore non-stub sections. */
  6718. if (!strstr (stub_sec->name, STUB_SUFFIX))
  6719. continue;
  6720. osi.sec = stub_sec;
  6721. osi.sec_shndx = _bfd_elf_section_from_bfd_section
  6722. (output_bfd, osi.sec->output_section);
  6723. /* The first instruction in a stub is always a branch. */
  6724. if (!elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0))
  6725. return FALSE;
  6726. bfd_hash_traverse (&htab->stub_hash_table, aarch64_map_one_stub,
  6727. &osi);
  6728. }
  6729. }
  6730. /* Finally, output mapping symbols for the PLT. */
  6731. if (!htab->root.splt || htab->root.splt->size == 0)
  6732. return TRUE;
  6733. osi.sec_shndx = _bfd_elf_section_from_bfd_section
  6734. (output_bfd, htab->root.splt->output_section);
  6735. osi.sec = htab->root.splt;
  6736. elfNN_aarch64_output_map_sym (&osi, AARCH64_MAP_INSN, 0);
  6737. return TRUE;
  6738. }
  6739. /* Allocate target specific section data. */
  6740. static bfd_boolean
  6741. elfNN_aarch64_new_section_hook (bfd *abfd, asection *sec)
  6742. {
  6743. if (!sec->used_by_bfd)
  6744. {
  6745. _aarch64_elf_section_data *sdata;
  6746. bfd_size_type amt = sizeof (*sdata);
  6747. sdata = bfd_zalloc (abfd, amt);
  6748. if (sdata == NULL)
  6749. return FALSE;
  6750. sec->used_by_bfd = sdata;
  6751. }
  6752. record_section_with_aarch64_elf_section_data (sec);
  6753. return _bfd_elf_new_section_hook (abfd, sec);
  6754. }
  6755. static void
  6756. unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED,
  6757. asection *sec,
  6758. void *ignore ATTRIBUTE_UNUSED)
  6759. {
  6760. unrecord_section_with_aarch64_elf_section_data (sec);
  6761. }
  6762. static bfd_boolean
  6763. elfNN_aarch64_close_and_cleanup (bfd *abfd)
  6764. {
  6765. if (abfd->sections)
  6766. bfd_map_over_sections (abfd,
  6767. unrecord_section_via_map_over_sections, NULL);
  6768. return _bfd_elf_close_and_cleanup (abfd);
  6769. }
  6770. static bfd_boolean
  6771. elfNN_aarch64_bfd_free_cached_info (bfd *abfd)
  6772. {
  6773. if (abfd->sections)
  6774. bfd_map_over_sections (abfd,
  6775. unrecord_section_via_map_over_sections, NULL);
  6776. return _bfd_free_cached_info (abfd);
  6777. }
  6778. /* Create dynamic sections. This is different from the ARM backend in that
  6779. the got, plt, gotplt and their relocation sections are all created in the
  6780. standard part of the bfd elf backend. */
  6781. static bfd_boolean
  6782. elfNN_aarch64_create_dynamic_sections (bfd *dynobj,
  6783. struct bfd_link_info *info)
  6784. {
  6785. struct elf_aarch64_link_hash_table *htab;
  6786. /* We need to create .got section. */
  6787. if (!aarch64_elf_create_got_section (dynobj, info))
  6788. return FALSE;
  6789. if (!_bfd_elf_create_dynamic_sections (dynobj, info))
  6790. return FALSE;
  6791. htab = elf_aarch64_hash_table (info);
  6792. htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
  6793. if (!bfd_link_pic (info))
  6794. htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
  6795. if (!htab->sdynbss || (!bfd_link_pic (info) && !htab->srelbss))
  6796. abort ();
  6797. return TRUE;
  6798. }
  6799. /* Allocate space in .plt, .got and associated reloc sections for
  6800. dynamic relocs. */
  6801. static bfd_boolean
  6802. elfNN_aarch64_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
  6803. {
  6804. struct bfd_link_info *info;
  6805. struct elf_aarch64_link_hash_table *htab;
  6806. struct elf_aarch64_link_hash_entry *eh;
  6807. struct elf_dyn_relocs *p;
  6808. /* An example of a bfd_link_hash_indirect symbol is versioned
  6809. symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
  6810. -> __gxx_personality_v0(bfd_link_hash_defined)
  6811. There is no need to process bfd_link_hash_indirect symbols here
  6812. because we will also be presented with the concrete instance of
  6813. the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
  6814. called to copy all relevant data from the generic to the concrete
  6815. symbol instance.
  6816. */
  6817. if (h->root.type == bfd_link_hash_indirect)
  6818. return TRUE;
  6819. if (h->root.type == bfd_link_hash_warning)
  6820. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  6821. info = (struct bfd_link_info *) inf;
  6822. htab = elf_aarch64_hash_table (info);
  6823. /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
  6824. here if it is defined and referenced in a non-shared object. */
  6825. if (h->type == STT_GNU_IFUNC
  6826. && h->def_regular)
  6827. return TRUE;
  6828. else if (htab->root.dynamic_sections_created && h->plt.refcount > 0)
  6829. {
  6830. /* Make sure this symbol is output as a dynamic symbol.
  6831. Undefined weak syms won't yet be marked as dynamic. */
  6832. if (h->dynindx == -1 && !h->forced_local)
  6833. {
  6834. if (!bfd_elf_link_record_dynamic_symbol (info, h))
  6835. return FALSE;
  6836. }
  6837. if (bfd_link_pic (info) || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
  6838. {
  6839. asection *s = htab->root.splt;
  6840. /* If this is the first .plt entry, make room for the special
  6841. first entry. */
  6842. if (s->size == 0)
  6843. s->size += htab->plt_header_size;
  6844. h->plt.offset = s->size;
  6845. /* If this symbol is not defined in a regular file, and we are
  6846. not generating a shared library, then set the symbol to this
  6847. location in the .plt. This is required to make function
  6848. pointers compare as equal between the normal executable and
  6849. the shared library. */
  6850. if (!bfd_link_pic (info) && !h->def_regular)
  6851. {
  6852. h->root.u.def.section = s;
  6853. h->root.u.def.value = h->plt.offset;
  6854. }
  6855. /* Make room for this entry. For now we only create the
  6856. small model PLT entries. We later need to find a way
  6857. of relaxing into these from the large model PLT entries. */
  6858. s->size += PLT_SMALL_ENTRY_SIZE;
  6859. /* We also need to make an entry in the .got.plt section, which
  6860. will be placed in the .got section by the linker script. */
  6861. htab->root.sgotplt->size += GOT_ENTRY_SIZE;
  6862. /* We also need to make an entry in the .rela.plt section. */
  6863. htab->root.srelplt->size += RELOC_SIZE (htab);
  6864. /* We need to ensure that all GOT entries that serve the PLT
  6865. are consecutive with the special GOT slots [0] [1] and
  6866. [2]. Any addtional relocations, such as
  6867. R_AARCH64_TLSDESC, must be placed after the PLT related
  6868. entries. We abuse the reloc_count such that during
  6869. sizing we adjust reloc_count to indicate the number of
  6870. PLT related reserved entries. In subsequent phases when
  6871. filling in the contents of the reloc entries, PLT related
  6872. entries are placed by computing their PLT index (0
  6873. .. reloc_count). While other none PLT relocs are placed
  6874. at the slot indicated by reloc_count and reloc_count is
  6875. updated. */
  6876. htab->root.srelplt->reloc_count++;
  6877. }
  6878. else
  6879. {
  6880. h->plt.offset = (bfd_vma) - 1;
  6881. h->needs_plt = 0;
  6882. }
  6883. }
  6884. else
  6885. {
  6886. h->plt.offset = (bfd_vma) - 1;
  6887. h->needs_plt = 0;
  6888. }
  6889. eh = (struct elf_aarch64_link_hash_entry *) h;
  6890. eh->tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
  6891. if (h->got.refcount > 0)
  6892. {
  6893. bfd_boolean dyn;
  6894. unsigned got_type = elf_aarch64_hash_entry (h)->got_type;
  6895. h->got.offset = (bfd_vma) - 1;
  6896. dyn = htab->root.dynamic_sections_created;
  6897. /* Make sure this symbol is output as a dynamic symbol.
  6898. Undefined weak syms won't yet be marked as dynamic. */
  6899. if (dyn && h->dynindx == -1 && !h->forced_local)
  6900. {
  6901. if (!bfd_elf_link_record_dynamic_symbol (info, h))
  6902. return FALSE;
  6903. }
  6904. if (got_type == GOT_UNKNOWN)
  6905. {
  6906. }
  6907. else if (got_type == GOT_NORMAL)
  6908. {
  6909. h->got.offset = htab->root.sgot->size;
  6910. htab->root.sgot->size += GOT_ENTRY_SIZE;
  6911. if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  6912. || h->root.type != bfd_link_hash_undefweak)
  6913. && (bfd_link_pic (info)
  6914. || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
  6915. {
  6916. htab->root.srelgot->size += RELOC_SIZE (htab);
  6917. }
  6918. }
  6919. else
  6920. {
  6921. int indx;
  6922. if (got_type & GOT_TLSDESC_GD)
  6923. {
  6924. eh->tlsdesc_got_jump_table_offset =
  6925. (htab->root.sgotplt->size
  6926. - aarch64_compute_jump_table_size (htab));
  6927. htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
  6928. h->got.offset = (bfd_vma) - 2;
  6929. }
  6930. if (got_type & GOT_TLS_GD)
  6931. {
  6932. h->got.offset = htab->root.sgot->size;
  6933. htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
  6934. }
  6935. if (got_type & GOT_TLS_IE)
  6936. {
  6937. h->got.offset = htab->root.sgot->size;
  6938. htab->root.sgot->size += GOT_ENTRY_SIZE;
  6939. }
  6940. indx = h && h->dynindx != -1 ? h->dynindx : 0;
  6941. if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
  6942. || h->root.type != bfd_link_hash_undefweak)
  6943. && (bfd_link_pic (info)
  6944. || indx != 0
  6945. || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
  6946. {
  6947. if (got_type & GOT_TLSDESC_GD)
  6948. {
  6949. htab->root.srelplt->size += RELOC_SIZE (htab);
  6950. /* Note reloc_count not incremented here! We have
  6951. already adjusted reloc_count for this relocation
  6952. type. */
  6953. /* TLSDESC PLT is now needed, but not yet determined. */
  6954. htab->tlsdesc_plt = (bfd_vma) - 1;
  6955. }
  6956. if (got_type & GOT_TLS_GD)
  6957. htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
  6958. if (got_type & GOT_TLS_IE)
  6959. htab->root.srelgot->size += RELOC_SIZE (htab);
  6960. }
  6961. }
  6962. }
  6963. else
  6964. {
  6965. h->got.offset = (bfd_vma) - 1;
  6966. }
  6967. if (eh->dyn_relocs == NULL)
  6968. return TRUE;
  6969. /* In the shared -Bsymbolic case, discard space allocated for
  6970. dynamic pc-relative relocs against symbols which turn out to be
  6971. defined in regular objects. For the normal shared case, discard
  6972. space for pc-relative relocs that have become local due to symbol
  6973. visibility changes. */
  6974. if (bfd_link_pic (info))
  6975. {
  6976. /* Relocs that use pc_count are those that appear on a call
  6977. insn, or certain REL relocs that can generated via assembly.
  6978. We want calls to protected symbols to resolve directly to the
  6979. function rather than going via the plt. If people want
  6980. function pointer comparisons to work as expected then they
  6981. should avoid writing weird assembly. */
  6982. if (SYMBOL_CALLS_LOCAL (info, h))
  6983. {
  6984. struct elf_dyn_relocs **pp;
  6985. for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
  6986. {
  6987. p->count -= p->pc_count;
  6988. p->pc_count = 0;
  6989. if (p->count == 0)
  6990. *pp = p->next;
  6991. else
  6992. pp = &p->next;
  6993. }
  6994. }
  6995. /* Also discard relocs on undefined weak syms with non-default
  6996. visibility. */
  6997. if (eh->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak)
  6998. {
  6999. if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
  7000. eh->dyn_relocs = NULL;
  7001. /* Make sure undefined weak symbols are output as a dynamic
  7002. symbol in PIEs. */
  7003. else if (h->dynindx == -1
  7004. && !h->forced_local
  7005. && !bfd_elf_link_record_dynamic_symbol (info, h))
  7006. return FALSE;
  7007. }
  7008. }
  7009. else if (ELIMINATE_COPY_RELOCS)
  7010. {
  7011. /* For the non-shared case, discard space for relocs against
  7012. symbols which turn out to need copy relocs or are not
  7013. dynamic. */
  7014. if (!h->non_got_ref
  7015. && ((h->def_dynamic
  7016. && !h->def_regular)
  7017. || (htab->root.dynamic_sections_created
  7018. && (h->root.type == bfd_link_hash_undefweak
  7019. || h->root.type == bfd_link_hash_undefined))))
  7020. {
  7021. /* Make sure this symbol is output as a dynamic symbol.
  7022. Undefined weak syms won't yet be marked as dynamic. */
  7023. if (h->dynindx == -1
  7024. && !h->forced_local
  7025. && !bfd_elf_link_record_dynamic_symbol (info, h))
  7026. return FALSE;
  7027. /* If that succeeded, we know we'll be keeping all the
  7028. relocs. */
  7029. if (h->dynindx != -1)
  7030. goto keep;
  7031. }
  7032. eh->dyn_relocs = NULL;
  7033. keep:;
  7034. }
  7035. /* Finally, allocate space. */
  7036. for (p = eh->dyn_relocs; p != NULL; p = p->next)
  7037. {
  7038. asection *sreloc;
  7039. sreloc = elf_section_data (p->sec)->sreloc;
  7040. BFD_ASSERT (sreloc != NULL);
  7041. sreloc->size += p->count * RELOC_SIZE (htab);
  7042. }
  7043. return TRUE;
  7044. }
  7045. /* Allocate space in .plt, .got and associated reloc sections for
  7046. ifunc dynamic relocs. */
  7047. static bfd_boolean
  7048. elfNN_aarch64_allocate_ifunc_dynrelocs (struct elf_link_hash_entry *h,
  7049. void *inf)
  7050. {
  7051. struct bfd_link_info *info;
  7052. struct elf_aarch64_link_hash_table *htab;
  7053. struct elf_aarch64_link_hash_entry *eh;
  7054. /* An example of a bfd_link_hash_indirect symbol is versioned
  7055. symbol. For example: __gxx_personality_v0(bfd_link_hash_indirect)
  7056. -> __gxx_personality_v0(bfd_link_hash_defined)
  7057. There is no need to process bfd_link_hash_indirect symbols here
  7058. because we will also be presented with the concrete instance of
  7059. the symbol and elfNN_aarch64_copy_indirect_symbol () will have been
  7060. called to copy all relevant data from the generic to the concrete
  7061. symbol instance.
  7062. */
  7063. if (h->root.type == bfd_link_hash_indirect)
  7064. return TRUE;
  7065. if (h->root.type == bfd_link_hash_warning)
  7066. h = (struct elf_link_hash_entry *) h->root.u.i.link;
  7067. info = (struct bfd_link_info *) inf;
  7068. htab = elf_aarch64_hash_table (info);
  7069. eh = (struct elf_aarch64_link_hash_entry *) h;
  7070. /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
  7071. here if it is defined and referenced in a non-shared object. */
  7072. if (h->type == STT_GNU_IFUNC
  7073. && h->def_regular)
  7074. return _bfd_elf_allocate_ifunc_dyn_relocs (info, h,
  7075. &eh->dyn_relocs,
  7076. htab->plt_entry_size,
  7077. htab->plt_header_size,
  7078. GOT_ENTRY_SIZE);
  7079. return TRUE;
  7080. }
  7081. /* Allocate space in .plt, .got and associated reloc sections for
  7082. local dynamic relocs. */
  7083. static bfd_boolean
  7084. elfNN_aarch64_allocate_local_dynrelocs (void **slot, void *inf)
  7085. {
  7086. struct elf_link_hash_entry *h
  7087. = (struct elf_link_hash_entry *) *slot;
  7088. if (h->type != STT_GNU_IFUNC
  7089. || !h->def_regular
  7090. || !h->ref_regular
  7091. || !h->forced_local
  7092. || h->root.type != bfd_link_hash_defined)
  7093. abort ();
  7094. return elfNN_aarch64_allocate_dynrelocs (h, inf);
  7095. }
  7096. /* Allocate space in .plt, .got and associated reloc sections for
  7097. local ifunc dynamic relocs. */
  7098. static bfd_boolean
  7099. elfNN_aarch64_allocate_local_ifunc_dynrelocs (void **slot, void *inf)
  7100. {
  7101. struct elf_link_hash_entry *h
  7102. = (struct elf_link_hash_entry *) *slot;
  7103. if (h->type != STT_GNU_IFUNC
  7104. || !h->def_regular
  7105. || !h->ref_regular
  7106. || !h->forced_local
  7107. || h->root.type != bfd_link_hash_defined)
  7108. abort ();
  7109. return elfNN_aarch64_allocate_ifunc_dynrelocs (h, inf);
  7110. }
  7111. /* Find any dynamic relocs that apply to read-only sections. */
  7112. static bfd_boolean
  7113. aarch64_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
  7114. {
  7115. struct elf_aarch64_link_hash_entry * eh;
  7116. struct elf_dyn_relocs * p;
  7117. eh = (struct elf_aarch64_link_hash_entry *) h;
  7118. for (p = eh->dyn_relocs; p != NULL; p = p->next)
  7119. {
  7120. asection *s = p->sec;
  7121. if (s != NULL && (s->flags & SEC_READONLY) != 0)
  7122. {
  7123. struct bfd_link_info *info = (struct bfd_link_info *) inf;
  7124. info->flags |= DF_TEXTREL;
  7125. /* Not an error, just cut short the traversal. */
  7126. return FALSE;
  7127. }
  7128. }
  7129. return TRUE;
  7130. }
  7131. /* This is the most important function of all . Innocuosly named
  7132. though ! */
  7133. static bfd_boolean
  7134. elfNN_aarch64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
  7135. struct bfd_link_info *info)
  7136. {
  7137. struct elf_aarch64_link_hash_table *htab;
  7138. bfd *dynobj;
  7139. asection *s;
  7140. bfd_boolean relocs;
  7141. bfd *ibfd;
  7142. htab = elf_aarch64_hash_table ((info));
  7143. dynobj = htab->root.dynobj;
  7144. BFD_ASSERT (dynobj != NULL);
  7145. if (htab->root.dynamic_sections_created)
  7146. {
  7147. if (bfd_link_executable (info) && !info->nointerp)
  7148. {
  7149. s = bfd_get_linker_section (dynobj, ".interp");
  7150. if (s == NULL)
  7151. abort ();
  7152. s->size = sizeof ELF_DYNAMIC_INTERPRETER;
  7153. s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
  7154. }
  7155. }
  7156. /* Set up .got offsets for local syms, and space for local dynamic
  7157. relocs. */
  7158. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  7159. {
  7160. struct elf_aarch64_local_symbol *locals = NULL;
  7161. Elf_Internal_Shdr *symtab_hdr;
  7162. asection *srel;
  7163. unsigned int i;
  7164. if (!is_aarch64_elf (ibfd))
  7165. continue;
  7166. for (s = ibfd->sections; s != NULL; s = s->next)
  7167. {
  7168. struct elf_dyn_relocs *p;
  7169. for (p = (struct elf_dyn_relocs *)
  7170. (elf_section_data (s)->local_dynrel); p != NULL; p = p->next)
  7171. {
  7172. if (!bfd_is_abs_section (p->sec)
  7173. && bfd_is_abs_section (p->sec->output_section))
  7174. {
  7175. /* Input section has been discarded, either because
  7176. it is a copy of a linkonce section or due to
  7177. linker script /DISCARD/, so we'll be discarding
  7178. the relocs too. */
  7179. }
  7180. else if (p->count != 0)
  7181. {
  7182. srel = elf_section_data (p->sec)->sreloc;
  7183. srel->size += p->count * RELOC_SIZE (htab);
  7184. if ((p->sec->output_section->flags & SEC_READONLY) != 0)
  7185. info->flags |= DF_TEXTREL;
  7186. }
  7187. }
  7188. }
  7189. locals = elf_aarch64_locals (ibfd);
  7190. if (!locals)
  7191. continue;
  7192. symtab_hdr = &elf_symtab_hdr (ibfd);
  7193. srel = htab->root.srelgot;
  7194. for (i = 0; i < symtab_hdr->sh_info; i++)
  7195. {
  7196. locals[i].got_offset = (bfd_vma) - 1;
  7197. locals[i].tlsdesc_got_jump_table_offset = (bfd_vma) - 1;
  7198. if (locals[i].got_refcount > 0)
  7199. {
  7200. unsigned got_type = locals[i].got_type;
  7201. if (got_type & GOT_TLSDESC_GD)
  7202. {
  7203. locals[i].tlsdesc_got_jump_table_offset =
  7204. (htab->root.sgotplt->size
  7205. - aarch64_compute_jump_table_size (htab));
  7206. htab->root.sgotplt->size += GOT_ENTRY_SIZE * 2;
  7207. locals[i].got_offset = (bfd_vma) - 2;
  7208. }
  7209. if (got_type & GOT_TLS_GD)
  7210. {
  7211. locals[i].got_offset = htab->root.sgot->size;
  7212. htab->root.sgot->size += GOT_ENTRY_SIZE * 2;
  7213. }
  7214. if (got_type & GOT_TLS_IE
  7215. || got_type & GOT_NORMAL)
  7216. {
  7217. locals[i].got_offset = htab->root.sgot->size;
  7218. htab->root.sgot->size += GOT_ENTRY_SIZE;
  7219. }
  7220. if (got_type == GOT_UNKNOWN)
  7221. {
  7222. }
  7223. if (bfd_link_pic (info))
  7224. {
  7225. if (got_type & GOT_TLSDESC_GD)
  7226. {
  7227. htab->root.srelplt->size += RELOC_SIZE (htab);
  7228. /* Note RELOC_COUNT not incremented here! */
  7229. htab->tlsdesc_plt = (bfd_vma) - 1;
  7230. }
  7231. if (got_type & GOT_TLS_GD)
  7232. htab->root.srelgot->size += RELOC_SIZE (htab) * 2;
  7233. if (got_type & GOT_TLS_IE
  7234. || got_type & GOT_NORMAL)
  7235. htab->root.srelgot->size += RELOC_SIZE (htab);
  7236. }
  7237. }
  7238. else
  7239. {
  7240. locals[i].got_refcount = (bfd_vma) - 1;
  7241. }
  7242. }
  7243. }
  7244. /* Allocate global sym .plt and .got entries, and space for global
  7245. sym dynamic relocs. */
  7246. elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_dynrelocs,
  7247. info);
  7248. /* Allocate global ifunc sym .plt and .got entries, and space for global
  7249. ifunc sym dynamic relocs. */
  7250. elf_link_hash_traverse (&htab->root, elfNN_aarch64_allocate_ifunc_dynrelocs,
  7251. info);
  7252. /* Allocate .plt and .got entries, and space for local symbols. */
  7253. htab_traverse (htab->loc_hash_table,
  7254. elfNN_aarch64_allocate_local_dynrelocs,
  7255. info);
  7256. /* Allocate .plt and .got entries, and space for local ifunc symbols. */
  7257. htab_traverse (htab->loc_hash_table,
  7258. elfNN_aarch64_allocate_local_ifunc_dynrelocs,
  7259. info);
  7260. /* For every jump slot reserved in the sgotplt, reloc_count is
  7261. incremented. However, when we reserve space for TLS descriptors,
  7262. it's not incremented, so in order to compute the space reserved
  7263. for them, it suffices to multiply the reloc count by the jump
  7264. slot size. */
  7265. if (htab->root.srelplt)
  7266. htab->sgotplt_jump_table_size = aarch64_compute_jump_table_size (htab);
  7267. if (htab->tlsdesc_plt)
  7268. {
  7269. if (htab->root.splt->size == 0)
  7270. htab->root.splt->size += PLT_ENTRY_SIZE;
  7271. htab->tlsdesc_plt = htab->root.splt->size;
  7272. htab->root.splt->size += PLT_TLSDESC_ENTRY_SIZE;
  7273. /* If we're not using lazy TLS relocations, don't generate the
  7274. GOT entry required. */
  7275. if (!(info->flags & DF_BIND_NOW))
  7276. {
  7277. htab->dt_tlsdesc_got = htab->root.sgot->size;
  7278. htab->root.sgot->size += GOT_ENTRY_SIZE;
  7279. }
  7280. }
  7281. /* Init mapping symbols information to use later to distingush between
  7282. code and data while scanning for errata. */
  7283. if (htab->fix_erratum_835769 || htab->fix_erratum_843419)
  7284. for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
  7285. {
  7286. if (!is_aarch64_elf (ibfd))
  7287. continue;
  7288. bfd_elfNN_aarch64_init_maps (ibfd);
  7289. }
  7290. /* We now have determined the sizes of the various dynamic sections.
  7291. Allocate memory for them. */
  7292. relocs = FALSE;
  7293. for (s = dynobj->sections; s != NULL; s = s->next)
  7294. {
  7295. if ((s->flags & SEC_LINKER_CREATED) == 0)
  7296. continue;
  7297. if (s == htab->root.splt
  7298. || s == htab->root.sgot
  7299. || s == htab->root.sgotplt
  7300. || s == htab->root.iplt
  7301. || s == htab->root.igotplt || s == htab->sdynbss)
  7302. {
  7303. /* Strip this section if we don't need it; see the
  7304. comment below. */
  7305. }
  7306. else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
  7307. {
  7308. if (s->size != 0 && s != htab->root.srelplt)
  7309. relocs = TRUE;
  7310. /* We use the reloc_count field as a counter if we need
  7311. to copy relocs into the output file. */
  7312. if (s != htab->root.srelplt)
  7313. s->reloc_count = 0;
  7314. }
  7315. else
  7316. {
  7317. /* It's not one of our sections, so don't allocate space. */
  7318. continue;
  7319. }
  7320. if (s->size == 0)
  7321. {
  7322. /* If we don't need this section, strip it from the
  7323. output file. This is mostly to handle .rela.bss and
  7324. .rela.plt. We must create both sections in
  7325. create_dynamic_sections, because they must be created
  7326. before the linker maps input sections to output
  7327. sections. The linker does that before
  7328. adjust_dynamic_symbol is called, and it is that
  7329. function which decides whether anything needs to go
  7330. into these sections. */
  7331. s->flags |= SEC_EXCLUDE;
  7332. continue;
  7333. }
  7334. if ((s->flags & SEC_HAS_CONTENTS) == 0)
  7335. continue;
  7336. /* Allocate memory for the section contents. We use bfd_zalloc
  7337. here in case unused entries are not reclaimed before the
  7338. section's contents are written out. This should not happen,
  7339. but this way if it does, we get a R_AARCH64_NONE reloc instead
  7340. of garbage. */
  7341. s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
  7342. if (s->contents == NULL)
  7343. return FALSE;
  7344. }
  7345. if (htab->root.dynamic_sections_created)
  7346. {
  7347. /* Add some entries to the .dynamic section. We fill in the
  7348. values later, in elfNN_aarch64_finish_dynamic_sections, but we
  7349. must add the entries now so that we get the correct size for
  7350. the .dynamic section. The DT_DEBUG entry is filled in by the
  7351. dynamic linker and used by the debugger. */
  7352. #define add_dynamic_entry(TAG, VAL) \
  7353. _bfd_elf_add_dynamic_entry (info, TAG, VAL)
  7354. if (bfd_link_executable (info))
  7355. {
  7356. if (!add_dynamic_entry (DT_DEBUG, 0))
  7357. return FALSE;
  7358. }
  7359. if (htab->root.splt->size != 0)
  7360. {
  7361. if (!add_dynamic_entry (DT_PLTGOT, 0)
  7362. || !add_dynamic_entry (DT_PLTRELSZ, 0)
  7363. || !add_dynamic_entry (DT_PLTREL, DT_RELA)
  7364. || !add_dynamic_entry (DT_JMPREL, 0))
  7365. return FALSE;
  7366. if (htab->tlsdesc_plt
  7367. && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
  7368. || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
  7369. return FALSE;
  7370. }
  7371. if (relocs)
  7372. {
  7373. if (!add_dynamic_entry (DT_RELA, 0)
  7374. || !add_dynamic_entry (DT_RELASZ, 0)
  7375. || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
  7376. return FALSE;
  7377. /* If any dynamic relocs apply to a read-only section,
  7378. then we need a DT_TEXTREL entry. */
  7379. if ((info->flags & DF_TEXTREL) == 0)
  7380. elf_link_hash_traverse (& htab->root, aarch64_readonly_dynrelocs,
  7381. info);
  7382. if ((info->flags & DF_TEXTREL) != 0)
  7383. {
  7384. if (!add_dynamic_entry (DT_TEXTREL, 0))
  7385. return FALSE;
  7386. }
  7387. }
  7388. }
  7389. #undef add_dynamic_entry
  7390. return TRUE;
  7391. }
  7392. static inline void
  7393. elf_aarch64_update_plt_entry (bfd *output_bfd,
  7394. bfd_reloc_code_real_type r_type,
  7395. bfd_byte *plt_entry, bfd_vma value)
  7396. {
  7397. reloc_howto_type *howto = elfNN_aarch64_howto_from_bfd_reloc (r_type);
  7398. _bfd_aarch64_elf_put_addend (output_bfd, plt_entry, r_type, howto, value);
  7399. }
  7400. static void
  7401. elfNN_aarch64_create_small_pltn_entry (struct elf_link_hash_entry *h,
  7402. struct elf_aarch64_link_hash_table
  7403. *htab, bfd *output_bfd,
  7404. struct bfd_link_info *info)
  7405. {
  7406. bfd_byte *plt_entry;
  7407. bfd_vma plt_index;
  7408. bfd_vma got_offset;
  7409. bfd_vma gotplt_entry_address;
  7410. bfd_vma plt_entry_address;
  7411. Elf_Internal_Rela rela;
  7412. bfd_byte *loc;
  7413. asection *plt, *gotplt, *relplt;
  7414. /* When building a static executable, use .iplt, .igot.plt and
  7415. .rela.iplt sections for STT_GNU_IFUNC symbols. */
  7416. if (htab->root.splt != NULL)
  7417. {
  7418. plt = htab->root.splt;
  7419. gotplt = htab->root.sgotplt;
  7420. relplt = htab->root.srelplt;
  7421. }
  7422. else
  7423. {
  7424. plt = htab->root.iplt;
  7425. gotplt = htab->root.igotplt;
  7426. relplt = htab->root.irelplt;
  7427. }
  7428. /* Get the index in the procedure linkage table which
  7429. corresponds to this symbol. This is the index of this symbol
  7430. in all the symbols for which we are making plt entries. The
  7431. first entry in the procedure linkage table is reserved.
  7432. Get the offset into the .got table of the entry that
  7433. corresponds to this function. Each .got entry is GOT_ENTRY_SIZE
  7434. bytes. The first three are reserved for the dynamic linker.
  7435. For static executables, we don't reserve anything. */
  7436. if (plt == htab->root.splt)
  7437. {
  7438. plt_index = (h->plt.offset - htab->plt_header_size) / htab->plt_entry_size;
  7439. got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
  7440. }
  7441. else
  7442. {
  7443. plt_index = h->plt.offset / htab->plt_entry_size;
  7444. got_offset = plt_index * GOT_ENTRY_SIZE;
  7445. }
  7446. plt_entry = plt->contents + h->plt.offset;
  7447. plt_entry_address = plt->output_section->vma
  7448. + plt->output_offset + h->plt.offset;
  7449. gotplt_entry_address = gotplt->output_section->vma +
  7450. gotplt->output_offset + got_offset;
  7451. /* Copy in the boiler-plate for the PLTn entry. */
  7452. memcpy (plt_entry, elfNN_aarch64_small_plt_entry, PLT_SMALL_ENTRY_SIZE);
  7453. /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
  7454. ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
  7455. elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
  7456. plt_entry,
  7457. PG (gotplt_entry_address) -
  7458. PG (plt_entry_address));
  7459. /* Fill in the lo12 bits for the load from the pltgot. */
  7460. elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
  7461. plt_entry + 4,
  7462. PG_OFFSET (gotplt_entry_address));
  7463. /* Fill in the lo12 bits for the add from the pltgot entry. */
  7464. elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
  7465. plt_entry + 8,
  7466. PG_OFFSET (gotplt_entry_address));
  7467. /* All the GOTPLT Entries are essentially initialized to PLT0. */
  7468. bfd_put_NN (output_bfd,
  7469. plt->output_section->vma + plt->output_offset,
  7470. gotplt->contents + got_offset);
  7471. rela.r_offset = gotplt_entry_address;
  7472. if (h->dynindx == -1
  7473. || ((bfd_link_executable (info)
  7474. || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
  7475. && h->def_regular
  7476. && h->type == STT_GNU_IFUNC))
  7477. {
  7478. /* If an STT_GNU_IFUNC symbol is locally defined, generate
  7479. R_AARCH64_IRELATIVE instead of R_AARCH64_JUMP_SLOT. */
  7480. rela.r_info = ELFNN_R_INFO (0, AARCH64_R (IRELATIVE));
  7481. rela.r_addend = (h->root.u.def.value
  7482. + h->root.u.def.section->output_section->vma
  7483. + h->root.u.def.section->output_offset);
  7484. }
  7485. else
  7486. {
  7487. /* Fill in the entry in the .rela.plt section. */
  7488. rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (JUMP_SLOT));
  7489. rela.r_addend = 0;
  7490. }
  7491. /* Compute the relocation entry to used based on PLT index and do
  7492. not adjust reloc_count. The reloc_count has already been adjusted
  7493. to account for this entry. */
  7494. loc = relplt->contents + plt_index * RELOC_SIZE (htab);
  7495. bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
  7496. }
  7497. /* Size sections even though they're not dynamic. We use it to setup
  7498. _TLS_MODULE_BASE_, if needed. */
  7499. static bfd_boolean
  7500. elfNN_aarch64_always_size_sections (bfd *output_bfd,
  7501. struct bfd_link_info *info)
  7502. {
  7503. asection *tls_sec;
  7504. if (bfd_link_relocatable (info))
  7505. return TRUE;
  7506. tls_sec = elf_hash_table (info)->tls_sec;
  7507. if (tls_sec)
  7508. {
  7509. struct elf_link_hash_entry *tlsbase;
  7510. tlsbase = elf_link_hash_lookup (elf_hash_table (info),
  7511. "_TLS_MODULE_BASE_", TRUE, TRUE, FALSE);
  7512. if (tlsbase)
  7513. {
  7514. struct bfd_link_hash_entry *h = NULL;
  7515. const struct elf_backend_data *bed =
  7516. get_elf_backend_data (output_bfd);
  7517. if (!(_bfd_generic_link_add_one_symbol
  7518. (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
  7519. tls_sec, 0, NULL, FALSE, bed->collect, &h)))
  7520. return FALSE;
  7521. tlsbase->type = STT_TLS;
  7522. tlsbase = (struct elf_link_hash_entry *) h;
  7523. tlsbase->def_regular = 1;
  7524. tlsbase->other = STV_HIDDEN;
  7525. (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
  7526. }
  7527. }
  7528. return TRUE;
  7529. }
  7530. /* Finish up dynamic symbol handling. We set the contents of various
  7531. dynamic sections here. */
  7532. static bfd_boolean
  7533. elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
  7534. struct bfd_link_info *info,
  7535. struct elf_link_hash_entry *h,
  7536. Elf_Internal_Sym *sym)
  7537. {
  7538. struct elf_aarch64_link_hash_table *htab;
  7539. htab = elf_aarch64_hash_table (info);
  7540. if (h->plt.offset != (bfd_vma) - 1)
  7541. {
  7542. asection *plt, *gotplt, *relplt;
  7543. /* This symbol has an entry in the procedure linkage table. Set
  7544. it up. */
  7545. /* When building a static executable, use .iplt, .igot.plt and
  7546. .rela.iplt sections for STT_GNU_IFUNC symbols. */
  7547. if (htab->root.splt != NULL)
  7548. {
  7549. plt = htab->root.splt;
  7550. gotplt = htab->root.sgotplt;
  7551. relplt = htab->root.srelplt;
  7552. }
  7553. else
  7554. {
  7555. plt = htab->root.iplt;
  7556. gotplt = htab->root.igotplt;
  7557. relplt = htab->root.irelplt;
  7558. }
  7559. /* This symbol has an entry in the procedure linkage table. Set
  7560. it up. */
  7561. if ((h->dynindx == -1
  7562. && !((h->forced_local || bfd_link_executable (info))
  7563. && h->def_regular
  7564. && h->type == STT_GNU_IFUNC))
  7565. || plt == NULL
  7566. || gotplt == NULL
  7567. || relplt == NULL)
  7568. abort ();
  7569. elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
  7570. if (!h->def_regular)
  7571. {
  7572. /* Mark the symbol as undefined, rather than as defined in
  7573. the .plt section. */
  7574. sym->st_shndx = SHN_UNDEF;
  7575. /* If the symbol is weak we need to clear the value.
  7576. Otherwise, the PLT entry would provide a definition for
  7577. the symbol even if the symbol wasn't defined anywhere,
  7578. and so the symbol would never be NULL. Leave the value if
  7579. there were any relocations where pointer equality matters
  7580. (this is a clue for the dynamic linker, to make function
  7581. pointer comparisons work between an application and shared
  7582. library). */
  7583. if (!h->ref_regular_nonweak || !h->pointer_equality_needed)
  7584. sym->st_value = 0;
  7585. }
  7586. }
  7587. if (h->got.offset != (bfd_vma) - 1
  7588. && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL)
  7589. {
  7590. Elf_Internal_Rela rela;
  7591. bfd_byte *loc;
  7592. /* This symbol has an entry in the global offset table. Set it
  7593. up. */
  7594. if (htab->root.sgot == NULL || htab->root.srelgot == NULL)
  7595. abort ();
  7596. rela.r_offset = (htab->root.sgot->output_section->vma
  7597. + htab->root.sgot->output_offset
  7598. + (h->got.offset & ~(bfd_vma) 1));
  7599. if (h->def_regular
  7600. && h->type == STT_GNU_IFUNC)
  7601. {
  7602. if (bfd_link_pic (info))
  7603. {
  7604. /* Generate R_AARCH64_GLOB_DAT. */
  7605. goto do_glob_dat;
  7606. }
  7607. else
  7608. {
  7609. asection *plt;
  7610. if (!h->pointer_equality_needed)
  7611. abort ();
  7612. /* For non-shared object, we can't use .got.plt, which
  7613. contains the real function address if we need pointer
  7614. equality. We load the GOT entry with the PLT entry. */
  7615. plt = htab->root.splt ? htab->root.splt : htab->root.iplt;
  7616. bfd_put_NN (output_bfd, (plt->output_section->vma
  7617. + plt->output_offset
  7618. + h->plt.offset),
  7619. htab->root.sgot->contents
  7620. + (h->got.offset & ~(bfd_vma) 1));
  7621. return TRUE;
  7622. }
  7623. }
  7624. else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
  7625. {
  7626. if (!h->def_regular)
  7627. return FALSE;
  7628. BFD_ASSERT ((h->got.offset & 1) != 0);
  7629. rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
  7630. rela.r_addend = (h->root.u.def.value
  7631. + h->root.u.def.section->output_section->vma
  7632. + h->root.u.def.section->output_offset);
  7633. }
  7634. else
  7635. {
  7636. do_glob_dat:
  7637. BFD_ASSERT ((h->got.offset & 1) == 0);
  7638. bfd_put_NN (output_bfd, (bfd_vma) 0,
  7639. htab->root.sgot->contents + h->got.offset);
  7640. rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (GLOB_DAT));
  7641. rela.r_addend = 0;
  7642. }
  7643. loc = htab->root.srelgot->contents;
  7644. loc += htab->root.srelgot->reloc_count++ * RELOC_SIZE (htab);
  7645. bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
  7646. }
  7647. if (h->needs_copy)
  7648. {
  7649. Elf_Internal_Rela rela;
  7650. bfd_byte *loc;
  7651. /* This symbol needs a copy reloc. Set it up. */
  7652. if (h->dynindx == -1
  7653. || (h->root.type != bfd_link_hash_defined
  7654. && h->root.type != bfd_link_hash_defweak)
  7655. || htab->srelbss == NULL)
  7656. abort ();
  7657. rela.r_offset = (h->root.u.def.value
  7658. + h->root.u.def.section->output_section->vma
  7659. + h->root.u.def.section->output_offset);
  7660. rela.r_info = ELFNN_R_INFO (h->dynindx, AARCH64_R (COPY));
  7661. rela.r_addend = 0;
  7662. loc = htab->srelbss->contents;
  7663. loc += htab->srelbss->reloc_count++ * RELOC_SIZE (htab);
  7664. bfd_elfNN_swap_reloca_out (output_bfd, &rela, loc);
  7665. }
  7666. /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. SYM may
  7667. be NULL for local symbols. */
  7668. if (sym != NULL
  7669. && (h == elf_hash_table (info)->hdynamic
  7670. || h == elf_hash_table (info)->hgot))
  7671. sym->st_shndx = SHN_ABS;
  7672. return TRUE;
  7673. }
  7674. /* Finish up local dynamic symbol handling. We set the contents of
  7675. various dynamic sections here. */
  7676. static bfd_boolean
  7677. elfNN_aarch64_finish_local_dynamic_symbol (void **slot, void *inf)
  7678. {
  7679. struct elf_link_hash_entry *h
  7680. = (struct elf_link_hash_entry *) *slot;
  7681. struct bfd_link_info *info
  7682. = (struct bfd_link_info *) inf;
  7683. return elfNN_aarch64_finish_dynamic_symbol (info->output_bfd,
  7684. info, h, NULL);
  7685. }
  7686. static void
  7687. elfNN_aarch64_init_small_plt0_entry (bfd *output_bfd ATTRIBUTE_UNUSED,
  7688. struct elf_aarch64_link_hash_table
  7689. *htab)
  7690. {
  7691. /* Fill in PLT0. Fixme:RR Note this doesn't distinguish between
  7692. small and large plts and at the minute just generates
  7693. the small PLT. */
  7694. /* PLT0 of the small PLT looks like this in ELF64 -
  7695. stp x16, x30, [sp, #-16]! // Save the reloc and lr on stack.
  7696. adrp x16, PLT_GOT + 16 // Get the page base of the GOTPLT
  7697. ldr x17, [x16, #:lo12:PLT_GOT+16] // Load the address of the
  7698. // symbol resolver
  7699. add x16, x16, #:lo12:PLT_GOT+16 // Load the lo12 bits of the
  7700. // GOTPLT entry for this.
  7701. br x17
  7702. PLT0 will be slightly different in ELF32 due to different got entry
  7703. size.
  7704. */
  7705. bfd_vma plt_got_2nd_ent; /* Address of GOT[2]. */
  7706. bfd_vma plt_base;
  7707. memcpy (htab->root.splt->contents, elfNN_aarch64_small_plt0_entry,
  7708. PLT_ENTRY_SIZE);
  7709. elf_section_data (htab->root.splt->output_section)->this_hdr.sh_entsize =
  7710. PLT_ENTRY_SIZE;
  7711. plt_got_2nd_ent = (htab->root.sgotplt->output_section->vma
  7712. + htab->root.sgotplt->output_offset
  7713. + GOT_ENTRY_SIZE * 2);
  7714. plt_base = htab->root.splt->output_section->vma +
  7715. htab->root.splt->output_offset;
  7716. /* Fill in the top 21 bits for this: ADRP x16, PLT_GOT + n * 8.
  7717. ADRP: ((PG(S+A)-PG(P)) >> 12) & 0x1fffff */
  7718. elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADR_HI21_PCREL,
  7719. htab->root.splt->contents + 4,
  7720. PG (plt_got_2nd_ent) - PG (plt_base + 4));
  7721. elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_LDSTNN_LO12,
  7722. htab->root.splt->contents + 8,
  7723. PG_OFFSET (plt_got_2nd_ent));
  7724. elf_aarch64_update_plt_entry (output_bfd, BFD_RELOC_AARCH64_ADD_LO12,
  7725. htab->root.splt->contents + 12,
  7726. PG_OFFSET (plt_got_2nd_ent));
  7727. }
  7728. static bfd_boolean
  7729. elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd,
  7730. struct bfd_link_info *info)
  7731. {
  7732. struct elf_aarch64_link_hash_table *htab;
  7733. bfd *dynobj;
  7734. asection *sdyn;
  7735. htab = elf_aarch64_hash_table (info);
  7736. dynobj = htab->root.dynobj;
  7737. sdyn = bfd_get_linker_section (dynobj, ".dynamic");
  7738. if (htab->root.dynamic_sections_created)
  7739. {
  7740. ElfNN_External_Dyn *dyncon, *dynconend;
  7741. if (sdyn == NULL || htab->root.sgot == NULL)
  7742. abort ();
  7743. dyncon = (ElfNN_External_Dyn *) sdyn->contents;
  7744. dynconend = (ElfNN_External_Dyn *) (sdyn->contents + sdyn->size);
  7745. for (; dyncon < dynconend; dyncon++)
  7746. {
  7747. Elf_Internal_Dyn dyn;
  7748. asection *s;
  7749. bfd_elfNN_swap_dyn_in (dynobj, dyncon, &dyn);
  7750. switch (dyn.d_tag)
  7751. {
  7752. default:
  7753. continue;
  7754. case DT_PLTGOT:
  7755. s = htab->root.sgotplt;
  7756. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
  7757. break;
  7758. case DT_JMPREL:
  7759. dyn.d_un.d_ptr = htab->root.srelplt->output_section->vma;
  7760. break;
  7761. case DT_PLTRELSZ:
  7762. s = htab->root.srelplt;
  7763. dyn.d_un.d_val = s->size;
  7764. break;
  7765. case DT_RELASZ:
  7766. /* The procedure linkage table relocs (DT_JMPREL) should
  7767. not be included in the overall relocs (DT_RELA).
  7768. Therefore, we override the DT_RELASZ entry here to
  7769. make it not include the JMPREL relocs. Since the
  7770. linker script arranges for .rela.plt to follow all
  7771. other relocation sections, we don't have to worry
  7772. about changing the DT_RELA entry. */
  7773. if (htab->root.srelplt != NULL)
  7774. {
  7775. s = htab->root.srelplt;
  7776. dyn.d_un.d_val -= s->size;
  7777. }
  7778. break;
  7779. case DT_TLSDESC_PLT:
  7780. s = htab->root.splt;
  7781. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
  7782. + htab->tlsdesc_plt;
  7783. break;
  7784. case DT_TLSDESC_GOT:
  7785. s = htab->root.sgot;
  7786. dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
  7787. + htab->dt_tlsdesc_got;
  7788. break;
  7789. }
  7790. bfd_elfNN_swap_dyn_out (output_bfd, &dyn, dyncon);
  7791. }
  7792. }
  7793. /* Fill in the special first entry in the procedure linkage table. */
  7794. if (htab->root.splt && htab->root.splt->size > 0)
  7795. {
  7796. elfNN_aarch64_init_small_plt0_entry (output_bfd, htab);
  7797. elf_section_data (htab->root.splt->output_section)->
  7798. this_hdr.sh_entsize = htab->plt_entry_size;
  7799. if (htab->tlsdesc_plt)
  7800. {
  7801. bfd_put_NN (output_bfd, (bfd_vma) 0,
  7802. htab->root.sgot->contents + htab->dt_tlsdesc_got);
  7803. memcpy (htab->root.splt->contents + htab->tlsdesc_plt,
  7804. elfNN_aarch64_tlsdesc_small_plt_entry,
  7805. sizeof (elfNN_aarch64_tlsdesc_small_plt_entry));
  7806. {
  7807. bfd_vma adrp1_addr =
  7808. htab->root.splt->output_section->vma
  7809. + htab->root.splt->output_offset + htab->tlsdesc_plt + 4;
  7810. bfd_vma adrp2_addr = adrp1_addr + 4;
  7811. bfd_vma got_addr =
  7812. htab->root.sgot->output_section->vma
  7813. + htab->root.sgot->output_offset;
  7814. bfd_vma pltgot_addr =
  7815. htab->root.sgotplt->output_section->vma
  7816. + htab->root.sgotplt->output_offset;
  7817. bfd_vma dt_tlsdesc_got = got_addr + htab->dt_tlsdesc_got;
  7818. bfd_byte *plt_entry =
  7819. htab->root.splt->contents + htab->tlsdesc_plt;
  7820. /* adrp x2, DT_TLSDESC_GOT */
  7821. elf_aarch64_update_plt_entry (output_bfd,
  7822. BFD_RELOC_AARCH64_ADR_HI21_PCREL,
  7823. plt_entry + 4,
  7824. (PG (dt_tlsdesc_got)
  7825. - PG (adrp1_addr)));
  7826. /* adrp x3, 0 */
  7827. elf_aarch64_update_plt_entry (output_bfd,
  7828. BFD_RELOC_AARCH64_ADR_HI21_PCREL,
  7829. plt_entry + 8,
  7830. (PG (pltgot_addr)
  7831. - PG (adrp2_addr)));
  7832. /* ldr x2, [x2, #0] */
  7833. elf_aarch64_update_plt_entry (output_bfd,
  7834. BFD_RELOC_AARCH64_LDSTNN_LO12,
  7835. plt_entry + 12,
  7836. PG_OFFSET (dt_tlsdesc_got));
  7837. /* add x3, x3, 0 */
  7838. elf_aarch64_update_plt_entry (output_bfd,
  7839. BFD_RELOC_AARCH64_ADD_LO12,
  7840. plt_entry + 16,
  7841. PG_OFFSET (pltgot_addr));
  7842. }
  7843. }
  7844. }
  7845. if (htab->root.sgotplt)
  7846. {
  7847. if (bfd_is_abs_section (htab->root.sgotplt->output_section))
  7848. {
  7849. (*_bfd_error_handler)
  7850. (_("discarded output section: `%A'"), htab->root.sgotplt);
  7851. return FALSE;
  7852. }
  7853. /* Fill in the first three entries in the global offset table. */
  7854. if (htab->root.sgotplt->size > 0)
  7855. {
  7856. bfd_put_NN (output_bfd, (bfd_vma) 0, htab->root.sgotplt->contents);
  7857. /* Write GOT[1] and GOT[2], needed for the dynamic linker. */
  7858. bfd_put_NN (output_bfd,
  7859. (bfd_vma) 0,
  7860. htab->root.sgotplt->contents + GOT_ENTRY_SIZE);
  7861. bfd_put_NN (output_bfd,
  7862. (bfd_vma) 0,
  7863. htab->root.sgotplt->contents + GOT_ENTRY_SIZE * 2);
  7864. }
  7865. if (htab->root.sgot)
  7866. {
  7867. if (htab->root.sgot->size > 0)
  7868. {
  7869. bfd_vma addr =
  7870. sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0;
  7871. bfd_put_NN (output_bfd, addr, htab->root.sgot->contents);
  7872. }
  7873. }
  7874. elf_section_data (htab->root.sgotplt->output_section)->
  7875. this_hdr.sh_entsize = GOT_ENTRY_SIZE;
  7876. }
  7877. if (htab->root.sgot && htab->root.sgot->size > 0)
  7878. elf_section_data (htab->root.sgot->output_section)->this_hdr.sh_entsize
  7879. = GOT_ENTRY_SIZE;
  7880. /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
  7881. htab_traverse (htab->loc_hash_table,
  7882. elfNN_aarch64_finish_local_dynamic_symbol,
  7883. info);
  7884. return TRUE;
  7885. }
  7886. /* Return address for Ith PLT stub in section PLT, for relocation REL
  7887. or (bfd_vma) -1 if it should not be included. */
  7888. static bfd_vma
  7889. elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
  7890. const arelent *rel ATTRIBUTE_UNUSED)
  7891. {
  7892. return plt->vma + PLT_ENTRY_SIZE + i * PLT_SMALL_ENTRY_SIZE;
  7893. }
  7894. /* We use this so we can override certain functions
  7895. (though currently we don't). */
  7896. const struct elf_size_info elfNN_aarch64_size_info =
  7897. {
  7898. sizeof (ElfNN_External_Ehdr),
  7899. sizeof (ElfNN_External_Phdr),
  7900. sizeof (ElfNN_External_Shdr),
  7901. sizeof (ElfNN_External_Rel),
  7902. sizeof (ElfNN_External_Rela),
  7903. sizeof (ElfNN_External_Sym),
  7904. sizeof (ElfNN_External_Dyn),
  7905. sizeof (Elf_External_Note),
  7906. 4, /* Hash table entry size. */
  7907. 1, /* Internal relocs per external relocs. */
  7908. ARCH_SIZE, /* Arch size. */
  7909. LOG_FILE_ALIGN, /* Log_file_align. */
  7910. ELFCLASSNN, EV_CURRENT,
  7911. bfd_elfNN_write_out_phdrs,
  7912. bfd_elfNN_write_shdrs_and_ehdr,
  7913. bfd_elfNN_checksum_contents,
  7914. bfd_elfNN_write_relocs,
  7915. bfd_elfNN_swap_symbol_in,
  7916. bfd_elfNN_swap_symbol_out,
  7917. bfd_elfNN_slurp_reloc_table,
  7918. bfd_elfNN_slurp_symbol_table,
  7919. bfd_elfNN_swap_dyn_in,
  7920. bfd_elfNN_swap_dyn_out,
  7921. bfd_elfNN_swap_reloc_in,
  7922. bfd_elfNN_swap_reloc_out,
  7923. bfd_elfNN_swap_reloca_in,
  7924. bfd_elfNN_swap_reloca_out
  7925. };
  7926. #define ELF_ARCH bfd_arch_aarch64
  7927. #define ELF_MACHINE_CODE EM_AARCH64
  7928. #define ELF_MAXPAGESIZE 0x10000
  7929. #define ELF_MINPAGESIZE 0x1000
  7930. #define ELF_COMMONPAGESIZE 0x1000
  7931. #define bfd_elfNN_close_and_cleanup \
  7932. elfNN_aarch64_close_and_cleanup
  7933. #define bfd_elfNN_bfd_free_cached_info \
  7934. elfNN_aarch64_bfd_free_cached_info
  7935. #define bfd_elfNN_bfd_is_target_special_symbol \
  7936. elfNN_aarch64_is_target_special_symbol
  7937. #define bfd_elfNN_bfd_link_hash_table_create \
  7938. elfNN_aarch64_link_hash_table_create
  7939. #define bfd_elfNN_bfd_merge_private_bfd_data \
  7940. elfNN_aarch64_merge_private_bfd_data
  7941. #define bfd_elfNN_bfd_print_private_bfd_data \
  7942. elfNN_aarch64_print_private_bfd_data
  7943. #define bfd_elfNN_bfd_reloc_type_lookup \
  7944. elfNN_aarch64_reloc_type_lookup
  7945. #define bfd_elfNN_bfd_reloc_name_lookup \
  7946. elfNN_aarch64_reloc_name_lookup
  7947. #define bfd_elfNN_bfd_set_private_flags \
  7948. elfNN_aarch64_set_private_flags
  7949. #define bfd_elfNN_find_inliner_info \
  7950. elfNN_aarch64_find_inliner_info
  7951. #define bfd_elfNN_find_nearest_line \
  7952. elfNN_aarch64_find_nearest_line
  7953. #define bfd_elfNN_mkobject \
  7954. elfNN_aarch64_mkobject
  7955. #define bfd_elfNN_new_section_hook \
  7956. elfNN_aarch64_new_section_hook
  7957. #define elf_backend_adjust_dynamic_symbol \
  7958. elfNN_aarch64_adjust_dynamic_symbol
  7959. #define elf_backend_always_size_sections \
  7960. elfNN_aarch64_always_size_sections
  7961. #define elf_backend_check_relocs \
  7962. elfNN_aarch64_check_relocs
  7963. #define elf_backend_copy_indirect_symbol \
  7964. elfNN_aarch64_copy_indirect_symbol
  7965. /* Create .dynbss, and .rela.bss sections in DYNOBJ, and set up shortcuts
  7966. to them in our hash. */
  7967. #define elf_backend_create_dynamic_sections \
  7968. elfNN_aarch64_create_dynamic_sections
  7969. #define elf_backend_init_index_section \
  7970. _bfd_elf_init_2_index_sections
  7971. #define elf_backend_finish_dynamic_sections \
  7972. elfNN_aarch64_finish_dynamic_sections
  7973. #define elf_backend_finish_dynamic_symbol \
  7974. elfNN_aarch64_finish_dynamic_symbol
  7975. #define elf_backend_gc_sweep_hook \
  7976. elfNN_aarch64_gc_sweep_hook
  7977. #define elf_backend_object_p \
  7978. elfNN_aarch64_object_p
  7979. #define elf_backend_output_arch_local_syms \
  7980. elfNN_aarch64_output_arch_local_syms
  7981. #define elf_backend_plt_sym_val \
  7982. elfNN_aarch64_plt_sym_val
  7983. #define elf_backend_post_process_headers \
  7984. elfNN_aarch64_post_process_headers
  7985. #define elf_backend_relocate_section \
  7986. elfNN_aarch64_relocate_section
  7987. #define elf_backend_reloc_type_class \
  7988. elfNN_aarch64_reloc_type_class
  7989. #define elf_backend_section_from_shdr \
  7990. elfNN_aarch64_section_from_shdr
  7991. #define elf_backend_size_dynamic_sections \
  7992. elfNN_aarch64_size_dynamic_sections
  7993. #define elf_backend_size_info \
  7994. elfNN_aarch64_size_info
  7995. #define elf_backend_write_section \
  7996. elfNN_aarch64_write_section
  7997. #define elf_backend_can_refcount 1
  7998. #define elf_backend_can_gc_sections 1
  7999. #define elf_backend_plt_readonly 1
  8000. #define elf_backend_want_got_plt 1
  8001. #define elf_backend_want_plt_sym 0
  8002. #define elf_backend_may_use_rel_p 0
  8003. #define elf_backend_may_use_rela_p 1
  8004. #define elf_backend_default_use_rela_p 1
  8005. #define elf_backend_rela_normal 1
  8006. #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3)
  8007. #define elf_backend_default_execstack 0
  8008. #define elf_backend_extern_protected_data 1
  8009. #undef elf_backend_obj_attrs_section
  8010. #define elf_backend_obj_attrs_section ".ARM.attributes"
  8011. #include "elfNN-target.h"