elfnn-aarch64.c 309 KB

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