readelf.c 610 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847
  1. /* readelf.c -- display contents of an ELF format file
  2. Copyright (C) 1998-2022 Free Software Foundation, Inc.
  3. Originally developed by Eric Youngdale <eric@andante.jic.com>
  4. Modifications by Nick Clifton <nickc@redhat.com>
  5. This file is part of GNU Binutils.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  17. 02110-1301, USA. */
  18. /* The difference between readelf and objdump:
  19. Both programs are capable of displaying the contents of ELF format files,
  20. so why does the binutils project have two file dumpers ?
  21. The reason is that objdump sees an ELF file through a BFD filter of the
  22. world; if BFD has a bug where, say, it disagrees about a machine constant
  23. in e_flags, then the odds are good that it will remain internally
  24. consistent. The linker sees it the BFD way, objdump sees it the BFD way,
  25. GAS sees it the BFD way. There was need for a tool to go find out what
  26. the file actually says.
  27. This is why the readelf program does not link against the BFD library - it
  28. exists as an independent program to help verify the correct working of BFD.
  29. There is also the case that readelf can provide more information about an
  30. ELF file than is provided by objdump. In particular it can display DWARF
  31. debugging information which (at the moment) objdump cannot. */
  32. #include "sysdep.h"
  33. #include <assert.h>
  34. #include <time.h>
  35. #include <zlib.h>
  36. #include <wchar.h>
  37. #if defined HAVE_MSGPACK
  38. #include <msgpack.h>
  39. #endif
  40. #if __GNUC__ >= 2
  41. /* Define BFD64 here, even if our default architecture is 32 bit ELF
  42. as this will allow us to read in and parse 64bit and 32bit ELF files.
  43. Only do this if we believe that the compiler can support a 64 bit
  44. data type. For now we only rely on GCC being able to do this. */
  45. #define BFD64
  46. #endif
  47. #include "bfd.h"
  48. #include "bucomm.h"
  49. #include "elfcomm.h"
  50. #include "demanguse.h"
  51. #include "dwarf.h"
  52. #include "ctf-api.h"
  53. #include "demangle.h"
  54. #include "elf/common.h"
  55. #include "elf/external.h"
  56. #include "elf/internal.h"
  57. /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
  58. we can obtain the H8 reloc numbers. We need these for the
  59. get_reloc_size() function. We include h8.h again after defining
  60. RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
  61. #include "elf/h8.h"
  62. #undef _ELF_H8_H
  63. /* Undo the effects of #including reloc-macros.h. */
  64. #undef START_RELOC_NUMBERS
  65. #undef RELOC_NUMBER
  66. #undef FAKE_RELOC
  67. #undef EMPTY_RELOC
  68. #undef END_RELOC_NUMBERS
  69. #undef _RELOC_MACROS_H
  70. /* The following headers use the elf/reloc-macros.h file to
  71. automatically generate relocation recognition functions
  72. such as elf_mips_reloc_type() */
  73. #define RELOC_MACROS_GEN_FUNC
  74. #include "elf/aarch64.h"
  75. #include "elf/alpha.h"
  76. #include "elf/amdgpu.h"
  77. #include "elf/arc.h"
  78. #include "elf/arm.h"
  79. #include "elf/avr.h"
  80. #include "elf/bfin.h"
  81. #include "elf/cr16.h"
  82. #include "elf/cris.h"
  83. #include "elf/crx.h"
  84. #include "elf/csky.h"
  85. #include "elf/d10v.h"
  86. #include "elf/d30v.h"
  87. #include "elf/dlx.h"
  88. #include "elf/bpf.h"
  89. #include "elf/epiphany.h"
  90. #include "elf/fr30.h"
  91. #include "elf/frv.h"
  92. #include "elf/ft32.h"
  93. #include "elf/h8.h"
  94. #include "elf/hppa.h"
  95. #include "elf/i386.h"
  96. #include "elf/i370.h"
  97. #include "elf/i860.h"
  98. #include "elf/i960.h"
  99. #include "elf/ia64.h"
  100. #include "elf/ip2k.h"
  101. #include "elf/lm32.h"
  102. #include "elf/iq2000.h"
  103. #include "elf/m32c.h"
  104. #include "elf/m32r.h"
  105. #include "elf/m68k.h"
  106. #include "elf/m68hc11.h"
  107. #include "elf/s12z.h"
  108. #include "elf/mcore.h"
  109. #include "elf/mep.h"
  110. #include "elf/metag.h"
  111. #include "elf/microblaze.h"
  112. #include "elf/mips.h"
  113. #include "elf/mmix.h"
  114. #include "elf/mn10200.h"
  115. #include "elf/mn10300.h"
  116. #include "elf/moxie.h"
  117. #include "elf/mt.h"
  118. #include "elf/msp430.h"
  119. #include "elf/nds32.h"
  120. #include "elf/nfp.h"
  121. #include "elf/nios2.h"
  122. #include "elf/or1k.h"
  123. #include "elf/pj.h"
  124. #include "elf/ppc.h"
  125. #include "elf/ppc64.h"
  126. #include "elf/pru.h"
  127. #include "elf/riscv.h"
  128. #include "elf/rl78.h"
  129. #include "elf/rx.h"
  130. #include "elf/s390.h"
  131. #include "elf/score.h"
  132. #include "elf/sh.h"
  133. #include "elf/sparc.h"
  134. #include "elf/spu.h"
  135. #include "elf/tic6x.h"
  136. #include "elf/tilegx.h"
  137. #include "elf/tilepro.h"
  138. #include "elf/v850.h"
  139. #include "elf/vax.h"
  140. #include "elf/visium.h"
  141. #include "elf/wasm32.h"
  142. #include "elf/x86-64.h"
  143. #include "elf/xc16x.h"
  144. #include "elf/xgate.h"
  145. #include "elf/xstormy16.h"
  146. #include "elf/xtensa.h"
  147. #include "elf/z80.h"
  148. #include "elf/loongarch.h"
  149. #include "getopt.h"
  150. #include "libiberty.h"
  151. #include "safe-ctype.h"
  152. #include "filenames.h"
  153. #ifndef offsetof
  154. #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
  155. #endif
  156. typedef struct elf_section_list
  157. {
  158. Elf_Internal_Shdr * hdr;
  159. struct elf_section_list * next;
  160. } elf_section_list;
  161. /* Flag bits indicating particular types of dump. */
  162. #define HEX_DUMP (1 << 0) /* The -x command line switch. */
  163. #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
  164. #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
  165. #define STRING_DUMP (1 << 3) /* The -p command line switch. */
  166. #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
  167. #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */
  168. typedef unsigned char dump_type;
  169. /* A linked list of the section names for which dumps were requested. */
  170. struct dump_list_entry
  171. {
  172. char * name;
  173. dump_type type;
  174. struct dump_list_entry * next;
  175. };
  176. /* A dynamic array of flags indicating for which sections a dump
  177. has been requested via command line switches. */
  178. struct dump_data
  179. {
  180. dump_type * dump_sects;
  181. unsigned int num_dump_sects;
  182. };
  183. static struct dump_data cmdline;
  184. static struct dump_list_entry * dump_sects_byname;
  185. char * program_name = "readelf";
  186. static bool show_name = false;
  187. static bool do_dynamic = false;
  188. static bool do_syms = false;
  189. static bool do_dyn_syms = false;
  190. static bool do_lto_syms = false;
  191. static bool do_reloc = false;
  192. static bool do_sections = false;
  193. static bool do_section_groups = false;
  194. static bool do_section_details = false;
  195. static bool do_segments = false;
  196. static bool do_unwind = false;
  197. static bool do_using_dynamic = false;
  198. static bool do_header = false;
  199. static bool do_dump = false;
  200. static bool do_version = false;
  201. static bool do_histogram = false;
  202. static bool do_debugging = false;
  203. static bool do_ctf = false;
  204. static bool do_arch = false;
  205. static bool do_notes = false;
  206. static bool do_archive_index = false;
  207. static bool check_all = false;
  208. static bool is_32bit_elf = false;
  209. static bool decompress_dumps = false;
  210. static bool do_not_show_symbol_truncation = false;
  211. static bool do_demangle = false; /* Pretty print C++ symbol names. */
  212. static bool process_links = false;
  213. static bool dump_any_debugging = false;
  214. static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
  215. static int sym_base = 0;
  216. static char *dump_ctf_parent_name;
  217. static char *dump_ctf_symtab_name;
  218. static char *dump_ctf_strtab_name;
  219. struct group_list
  220. {
  221. struct group_list * next;
  222. unsigned int section_index;
  223. };
  224. struct group
  225. {
  226. struct group_list * root;
  227. unsigned int group_index;
  228. };
  229. typedef struct filedata
  230. {
  231. const char * file_name;
  232. bool is_separate;
  233. FILE * handle;
  234. bfd_size_type file_size;
  235. Elf_Internal_Ehdr file_header;
  236. unsigned long archive_file_offset;
  237. unsigned long archive_file_size;
  238. /* Everything below this point is cleared out by free_filedata. */
  239. Elf_Internal_Shdr * section_headers;
  240. Elf_Internal_Phdr * program_headers;
  241. char * string_table;
  242. unsigned long string_table_length;
  243. unsigned long dynamic_addr;
  244. bfd_size_type dynamic_size;
  245. size_t dynamic_nent;
  246. Elf_Internal_Dyn * dynamic_section;
  247. Elf_Internal_Shdr * dynamic_strtab_section;
  248. char * dynamic_strings;
  249. unsigned long dynamic_strings_length;
  250. Elf_Internal_Shdr * dynamic_symtab_section;
  251. unsigned long num_dynamic_syms;
  252. Elf_Internal_Sym * dynamic_symbols;
  253. bfd_vma version_info[16];
  254. unsigned int dynamic_syminfo_nent;
  255. Elf_Internal_Syminfo * dynamic_syminfo;
  256. unsigned long dynamic_syminfo_offset;
  257. bfd_size_type nbuckets;
  258. bfd_size_type nchains;
  259. bfd_vma * buckets;
  260. bfd_vma * chains;
  261. bfd_size_type ngnubuckets;
  262. bfd_size_type ngnuchains;
  263. bfd_vma * gnubuckets;
  264. bfd_vma * gnuchains;
  265. bfd_vma * mipsxlat;
  266. bfd_vma gnusymidx;
  267. char * program_interpreter;
  268. bfd_vma dynamic_info[DT_ENCODING];
  269. bfd_vma dynamic_info_DT_GNU_HASH;
  270. bfd_vma dynamic_info_DT_MIPS_XHASH;
  271. elf_section_list * symtab_shndx_list;
  272. size_t group_count;
  273. struct group * section_groups;
  274. struct group ** section_headers_groups;
  275. /* A dynamic array of flags indicating for which sections a dump of
  276. some kind has been requested. It is reset on a per-object file
  277. basis and then initialised from the cmdline_dump_sects array,
  278. the results of interpreting the -w switch, and the
  279. dump_sects_byname list. */
  280. struct dump_data dump;
  281. } Filedata;
  282. /* How to print a vma value. */
  283. typedef enum print_mode
  284. {
  285. HEX,
  286. HEX_5,
  287. DEC,
  288. DEC_5,
  289. UNSIGNED,
  290. UNSIGNED_5,
  291. PREFIX_HEX,
  292. PREFIX_HEX_5,
  293. FULL_HEX,
  294. LONG_HEX,
  295. OCTAL,
  296. OCTAL_5
  297. }
  298. print_mode;
  299. typedef enum unicode_display_type
  300. {
  301. unicode_default = 0,
  302. unicode_locale,
  303. unicode_escape,
  304. unicode_hex,
  305. unicode_highlight,
  306. unicode_invalid
  307. } unicode_display_type;
  308. static unicode_display_type unicode_display = unicode_default;
  309. typedef enum
  310. {
  311. reltype_unknown,
  312. reltype_rel,
  313. reltype_rela,
  314. reltype_relr
  315. } relocation_type;
  316. /* Versioned symbol info. */
  317. enum versioned_symbol_info
  318. {
  319. symbol_undefined,
  320. symbol_hidden,
  321. symbol_public
  322. };
  323. static const char * get_symbol_version_string
  324. (Filedata *, bool, const char *, unsigned long, unsigned,
  325. Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *);
  326. #define UNKNOWN -1
  327. static inline const char *
  328. section_name (const Filedata *filedata, const Elf_Internal_Shdr *hdr)
  329. {
  330. return filedata->string_table + hdr->sh_name;
  331. }
  332. static inline bool
  333. section_name_valid (const Filedata *filedata, const Elf_Internal_Shdr *hdr)
  334. {
  335. return (hdr != NULL
  336. && filedata->string_table != NULL
  337. && hdr->sh_name < filedata->string_table_length);
  338. }
  339. static inline const char *
  340. section_name_print (const Filedata *filedata, const Elf_Internal_Shdr *hdr)
  341. {
  342. if (hdr == NULL)
  343. return _("<none>");
  344. if (filedata->string_table == NULL)
  345. return _("<no-strings>");
  346. if (hdr->sh_name >= filedata->string_table_length)
  347. return _("<corrupt>");
  348. return section_name (filedata, hdr);
  349. }
  350. #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
  351. static inline bool
  352. valid_symbol_name (const char *strtab, size_t strtab_size, uint64_t offset)
  353. {
  354. return strtab != NULL && offset < strtab_size;
  355. }
  356. static inline bool
  357. valid_dynamic_name (const Filedata *filedata, uint64_t offset)
  358. {
  359. return valid_symbol_name (filedata->dynamic_strings,
  360. filedata->dynamic_strings_length, offset);
  361. }
  362. /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
  363. already been called and verified that the string exists. */
  364. static inline const char *
  365. get_dynamic_name (const Filedata *filedata, size_t offset)
  366. {
  367. return filedata->dynamic_strings + offset;
  368. }
  369. #define REMOVE_ARCH_BITS(ADDR) \
  370. do \
  371. { \
  372. if (filedata->file_header.e_machine == EM_ARM) \
  373. (ADDR) &= ~1; \
  374. } \
  375. while (0)
  376. /* Get the correct GNU hash section name. */
  377. #define GNU_HASH_SECTION_NAME(filedata) \
  378. filedata->dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash"
  379. /* Print a BFD_VMA to an internal buffer, for use in error messages.
  380. BFD_FMA_FMT can't be used in translated strings. */
  381. static const char *
  382. bfd_vmatoa (char *fmtch, bfd_vma value)
  383. {
  384. /* bfd_vmatoa is used more then once in a printf call for output.
  385. Cycle through an array of buffers. */
  386. static int buf_pos = 0;
  387. static struct bfd_vmatoa_buf
  388. {
  389. char place[64];
  390. } buf[4];
  391. char *ret;
  392. char fmt[32];
  393. ret = buf[buf_pos++].place;
  394. buf_pos %= ARRAY_SIZE (buf);
  395. sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
  396. snprintf (ret, sizeof (buf[0].place), fmt, value);
  397. return ret;
  398. }
  399. /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at
  400. OFFSET + the offset of the current archive member, if we are examining an
  401. archive. Put the retrieved data into VAR, if it is not NULL. Otherwise
  402. allocate a buffer using malloc and fill that. In either case return the
  403. pointer to the start of the retrieved data or NULL if something went wrong.
  404. If something does go wrong and REASON is not NULL then emit an error
  405. message using REASON as part of the context. */
  406. static void *
  407. get_data (void * var,
  408. Filedata * filedata,
  409. unsigned long offset,
  410. bfd_size_type size,
  411. bfd_size_type nmemb,
  412. const char * reason)
  413. {
  414. void * mvar;
  415. bfd_size_type amt = size * nmemb;
  416. if (size == 0 || nmemb == 0)
  417. return NULL;
  418. /* If the size_t type is smaller than the bfd_size_type, eg because
  419. you are building a 32-bit tool on a 64-bit host, then make sure
  420. that when the sizes are cast to (size_t) no information is lost. */
  421. if ((size_t) size != size
  422. || (size_t) nmemb != nmemb
  423. || (size_t) amt != amt)
  424. {
  425. if (reason)
  426. error (_("Size truncation prevents reading %s"
  427. " elements of size %s for %s\n"),
  428. bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
  429. return NULL;
  430. }
  431. /* Check for size overflow. */
  432. if (amt / size != nmemb || (size_t) amt + 1 == 0)
  433. {
  434. if (reason)
  435. error (_("Size overflow prevents reading %s"
  436. " elements of size %s for %s\n"),
  437. bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason);
  438. return NULL;
  439. }
  440. /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
  441. attempting to allocate memory when the read is bound to fail. */
  442. if (filedata->archive_file_offset > filedata->file_size
  443. || offset > filedata->file_size - filedata->archive_file_offset
  444. || amt > filedata->file_size - filedata->archive_file_offset - offset)
  445. {
  446. if (reason)
  447. error (_("Reading %s bytes extends past end of file for %s\n"),
  448. bfd_vmatoa ("u", amt), reason);
  449. return NULL;
  450. }
  451. if (fseek (filedata->handle, filedata->archive_file_offset + offset,
  452. SEEK_SET))
  453. {
  454. if (reason)
  455. error (_("Unable to seek to 0x%lx for %s\n"),
  456. filedata->archive_file_offset + offset, reason);
  457. return NULL;
  458. }
  459. mvar = var;
  460. if (mvar == NULL)
  461. {
  462. /* + 1 so that we can '\0' terminate invalid string table sections. */
  463. mvar = malloc ((size_t) amt + 1);
  464. if (mvar == NULL)
  465. {
  466. if (reason)
  467. error (_("Out of memory allocating %s bytes for %s\n"),
  468. bfd_vmatoa ("u", amt), reason);
  469. return NULL;
  470. }
  471. ((char *) mvar)[amt] = '\0';
  472. }
  473. if (fread (mvar, (size_t) size, (size_t) nmemb, filedata->handle) != nmemb)
  474. {
  475. if (reason)
  476. error (_("Unable to read in %s bytes of %s\n"),
  477. bfd_vmatoa ("u", amt), reason);
  478. if (mvar != var)
  479. free (mvar);
  480. return NULL;
  481. }
  482. return mvar;
  483. }
  484. /* Print a VMA value in the MODE specified.
  485. Returns the number of characters displayed. */
  486. static unsigned int
  487. print_vma (bfd_vma vma, print_mode mode)
  488. {
  489. unsigned int nc = 0;
  490. switch (mode)
  491. {
  492. case FULL_HEX:
  493. nc = printf ("0x");
  494. /* Fall through. */
  495. case LONG_HEX:
  496. #ifdef BFD64
  497. if (is_32bit_elf)
  498. return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
  499. #endif
  500. printf_vma (vma);
  501. return nc + 16;
  502. case DEC_5:
  503. if (vma <= 99999)
  504. return printf ("%5" BFD_VMA_FMT "d", vma);
  505. /* Fall through. */
  506. case PREFIX_HEX:
  507. nc = printf ("0x");
  508. /* Fall through. */
  509. case HEX:
  510. return nc + printf ("%" BFD_VMA_FMT "x", vma);
  511. case PREFIX_HEX_5:
  512. nc = printf ("0x");
  513. /* Fall through. */
  514. case HEX_5:
  515. return nc + printf ("%05" BFD_VMA_FMT "x", vma);
  516. case DEC:
  517. return printf ("%" BFD_VMA_FMT "d", vma);
  518. case UNSIGNED:
  519. return printf ("%" BFD_VMA_FMT "u", vma);
  520. case UNSIGNED_5:
  521. return printf ("%5" BFD_VMA_FMT "u", vma);
  522. case OCTAL:
  523. return printf ("%" BFD_VMA_FMT "o", vma);
  524. case OCTAL_5:
  525. return printf ("%5" BFD_VMA_FMT "o", vma);
  526. default:
  527. /* FIXME: Report unrecognised mode ? */
  528. return 0;
  529. }
  530. }
  531. /* Display a symbol on stdout. Handles the display of control characters and
  532. multibye characters (assuming the host environment supports them).
  533. Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
  534. If truncation will happen and do_not_show_symbol_truncation is FALSE then display
  535. abs(WIDTH) - 5 characters followed by "[...]".
  536. If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
  537. padding as necessary.
  538. Returns the number of emitted characters. */
  539. static unsigned int
  540. print_symbol (signed int width, const char * symbol)
  541. {
  542. bool extra_padding = false;
  543. bool do_dots = false;
  544. signed int num_printed = 0;
  545. #ifdef HAVE_MBSTATE_T
  546. mbstate_t state;
  547. #endif
  548. unsigned int width_remaining;
  549. const void * alloced_symbol = NULL;
  550. if (width < 0)
  551. {
  552. /* Keep the width positive. This helps the code below. */
  553. width = - width;
  554. extra_padding = true;
  555. }
  556. else if (width == 0)
  557. return 0;
  558. if (do_wide)
  559. /* Set the remaining width to a very large value.
  560. This simplifies the code below. */
  561. width_remaining = INT_MAX;
  562. else
  563. {
  564. width_remaining = width;
  565. if (! do_not_show_symbol_truncation
  566. && (int) strlen (symbol) > width)
  567. {
  568. width_remaining -= 5;
  569. if ((int) width_remaining < 0)
  570. width_remaining = 0;
  571. do_dots = true;
  572. }
  573. }
  574. #ifdef HAVE_MBSTATE_T
  575. /* Initialise the multibyte conversion state. */
  576. memset (& state, 0, sizeof (state));
  577. #endif
  578. if (do_demangle && *symbol)
  579. {
  580. const char * res = cplus_demangle (symbol, demangle_flags);
  581. if (res != NULL)
  582. alloced_symbol = symbol = res;
  583. }
  584. while (width_remaining)
  585. {
  586. size_t n;
  587. const char c = *symbol++;
  588. if (c == 0)
  589. break;
  590. if (ISPRINT (c))
  591. {
  592. putchar (c);
  593. width_remaining --;
  594. num_printed ++;
  595. }
  596. else if (ISCNTRL (c))
  597. {
  598. /* Do not print control characters directly as they can affect terminal
  599. settings. Such characters usually appear in the names generated
  600. by the assembler for local labels. */
  601. if (width_remaining < 2)
  602. break;
  603. printf ("^%c", c + 0x40);
  604. width_remaining -= 2;
  605. num_printed += 2;
  606. }
  607. else if (c == 0x7f)
  608. {
  609. if (width_remaining < 5)
  610. break;
  611. printf ("<DEL>");
  612. width_remaining -= 5;
  613. num_printed += 5;
  614. }
  615. else if (unicode_display != unicode_locale
  616. && unicode_display != unicode_default)
  617. {
  618. /* Display unicode characters as something else. */
  619. unsigned char bytes[4];
  620. bool is_utf8;
  621. unsigned int nbytes;
  622. bytes[0] = c;
  623. if (bytes[0] < 0xc0)
  624. {
  625. nbytes = 1;
  626. is_utf8 = false;
  627. }
  628. else
  629. {
  630. bytes[1] = *symbol++;
  631. if ((bytes[1] & 0xc0) != 0x80)
  632. {
  633. is_utf8 = false;
  634. /* Do not consume this character. It may only
  635. be the first byte in the sequence that was
  636. corrupt. */
  637. --symbol;
  638. nbytes = 1;
  639. }
  640. else if ((bytes[0] & 0x20) == 0)
  641. {
  642. is_utf8 = true;
  643. nbytes = 2;
  644. }
  645. else
  646. {
  647. bytes[2] = *symbol++;
  648. if ((bytes[2] & 0xc0) != 0x80)
  649. {
  650. is_utf8 = false;
  651. symbol -= 2;
  652. nbytes = 1;
  653. }
  654. else if ((bytes[0] & 0x10) == 0)
  655. {
  656. is_utf8 = true;
  657. nbytes = 3;
  658. }
  659. else
  660. {
  661. bytes[3] = *symbol++;
  662. nbytes = 4;
  663. if ((bytes[3] & 0xc0) != 0x80)
  664. {
  665. is_utf8 = false;
  666. symbol -= 3;
  667. nbytes = 1;
  668. }
  669. else
  670. is_utf8 = true;
  671. }
  672. }
  673. }
  674. if (unicode_display == unicode_invalid)
  675. is_utf8 = false;
  676. if (unicode_display == unicode_hex || ! is_utf8)
  677. {
  678. unsigned int i;
  679. if (width_remaining < (nbytes * 2) + 2)
  680. break;
  681. putchar (is_utf8 ? '<' : '{');
  682. printf ("0x");
  683. for (i = 0; i < nbytes; i++)
  684. printf ("%02x", bytes[i]);
  685. putchar (is_utf8 ? '>' : '}');
  686. }
  687. else
  688. {
  689. if (unicode_display == unicode_highlight && isatty (1))
  690. printf ("\x1B[31;47m"); /* Red. */
  691. switch (nbytes)
  692. {
  693. case 2:
  694. if (width_remaining < 6)
  695. break;
  696. printf ("\\u%02x%02x",
  697. (bytes[0] & 0x1c) >> 2,
  698. ((bytes[0] & 0x03) << 6) | (bytes[1] & 0x3f));
  699. break;
  700. case 3:
  701. if (width_remaining < 6)
  702. break;
  703. printf ("\\u%02x%02x",
  704. ((bytes[0] & 0x0f) << 4) | ((bytes[1] & 0x3c) >> 2),
  705. ((bytes[1] & 0x03) << 6) | (bytes[2] & 0x3f));
  706. break;
  707. case 4:
  708. if (width_remaining < 8)
  709. break;
  710. printf ("\\u%02x%02x%02x",
  711. ((bytes[0] & 0x07) << 6) | ((bytes[1] & 0x3c) >> 2),
  712. ((bytes[1] & 0x03) << 6) | ((bytes[2] & 0x3c) >> 2),
  713. ((bytes[2] & 0x03) << 6) | (bytes[3] & 0x3f));
  714. break;
  715. default:
  716. /* URG. */
  717. break;
  718. }
  719. if (unicode_display == unicode_highlight && isatty (1))
  720. printf ("\033[0m"); /* Default colour. */
  721. }
  722. if (bytes[nbytes - 1] == 0)
  723. break;
  724. }
  725. else
  726. {
  727. #ifdef HAVE_MBSTATE_T
  728. wchar_t w;
  729. #endif
  730. /* Let printf do the hard work of displaying multibyte characters. */
  731. printf ("%.1s", symbol - 1);
  732. width_remaining --;
  733. num_printed ++;
  734. #ifdef HAVE_MBSTATE_T
  735. /* Try to find out how many bytes made up the character that was
  736. just printed. Advance the symbol pointer past the bytes that
  737. were displayed. */
  738. n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state);
  739. #else
  740. n = 1;
  741. #endif
  742. if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
  743. symbol += (n - 1);
  744. }
  745. }
  746. if (do_dots)
  747. num_printed += printf ("[...]");
  748. if (extra_padding && num_printed < width)
  749. {
  750. /* Fill in the remaining spaces. */
  751. printf ("%-*s", width - num_printed, " ");
  752. num_printed = width;
  753. }
  754. free ((void *) alloced_symbol);
  755. return num_printed;
  756. }
  757. /* Returns a pointer to a static buffer containing a printable version of
  758. the given section's name. Like print_symbol, except that it does not try
  759. to print multibyte characters, it just interprets them as hex values. */
  760. static const char *
  761. printable_section_name (Filedata * filedata, const Elf_Internal_Shdr * sec)
  762. {
  763. #define MAX_PRINT_SEC_NAME_LEN 256
  764. static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1];
  765. const char * name = section_name_print (filedata, sec);
  766. char * buf = sec_name_buf;
  767. char c;
  768. unsigned int remaining = MAX_PRINT_SEC_NAME_LEN;
  769. while ((c = * name ++) != 0)
  770. {
  771. if (ISCNTRL (c))
  772. {
  773. if (remaining < 2)
  774. break;
  775. * buf ++ = '^';
  776. * buf ++ = c + 0x40;
  777. remaining -= 2;
  778. }
  779. else if (ISPRINT (c))
  780. {
  781. * buf ++ = c;
  782. remaining -= 1;
  783. }
  784. else
  785. {
  786. static char hex[17] = "0123456789ABCDEF";
  787. if (remaining < 4)
  788. break;
  789. * buf ++ = '<';
  790. * buf ++ = hex[(c & 0xf0) >> 4];
  791. * buf ++ = hex[c & 0x0f];
  792. * buf ++ = '>';
  793. remaining -= 4;
  794. }
  795. if (remaining == 0)
  796. break;
  797. }
  798. * buf = 0;
  799. return sec_name_buf;
  800. }
  801. static const char *
  802. printable_section_name_from_index (Filedata * filedata, unsigned long ndx)
  803. {
  804. if (ndx >= filedata->file_header.e_shnum)
  805. return _("<corrupt>");
  806. return printable_section_name (filedata, filedata->section_headers + ndx);
  807. }
  808. /* Return a pointer to section NAME, or NULL if no such section exists. */
  809. static Elf_Internal_Shdr *
  810. find_section (Filedata * filedata, const char * name)
  811. {
  812. unsigned int i;
  813. if (filedata->section_headers == NULL)
  814. return NULL;
  815. for (i = 0; i < filedata->file_header.e_shnum; i++)
  816. if (section_name_valid (filedata, filedata->section_headers + i)
  817. && streq (section_name (filedata, filedata->section_headers + i),
  818. name))
  819. return filedata->section_headers + i;
  820. return NULL;
  821. }
  822. /* Return a pointer to a section containing ADDR, or NULL if no such
  823. section exists. */
  824. static Elf_Internal_Shdr *
  825. find_section_by_address (Filedata * filedata, bfd_vma addr)
  826. {
  827. unsigned int i;
  828. if (filedata->section_headers == NULL)
  829. return NULL;
  830. for (i = 0; i < filedata->file_header.e_shnum; i++)
  831. {
  832. Elf_Internal_Shdr *sec = filedata->section_headers + i;
  833. if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size)
  834. return sec;
  835. }
  836. return NULL;
  837. }
  838. static Elf_Internal_Shdr *
  839. find_section_by_type (Filedata * filedata, unsigned int type)
  840. {
  841. unsigned int i;
  842. if (filedata->section_headers == NULL)
  843. return NULL;
  844. for (i = 0; i < filedata->file_header.e_shnum; i++)
  845. {
  846. Elf_Internal_Shdr *sec = filedata->section_headers + i;
  847. if (sec->sh_type == type)
  848. return sec;
  849. }
  850. return NULL;
  851. }
  852. /* Return a pointer to section NAME, or NULL if no such section exists,
  853. restricted to the list of sections given in SET. */
  854. static Elf_Internal_Shdr *
  855. find_section_in_set (Filedata * filedata, const char * name, unsigned int * set)
  856. {
  857. unsigned int i;
  858. if (filedata->section_headers == NULL)
  859. return NULL;
  860. if (set != NULL)
  861. {
  862. while ((i = *set++) > 0)
  863. {
  864. /* See PR 21156 for a reproducer. */
  865. if (i >= filedata->file_header.e_shnum)
  866. continue; /* FIXME: Should we issue an error message ? */
  867. if (section_name_valid (filedata, filedata->section_headers + i)
  868. && streq (section_name (filedata, filedata->section_headers + i),
  869. name))
  870. return filedata->section_headers + i;
  871. }
  872. }
  873. return find_section (filedata, name);
  874. }
  875. /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
  876. This OS has so many departures from the ELF standard that we test it at
  877. many places. */
  878. static inline bool
  879. is_ia64_vms (Filedata * filedata)
  880. {
  881. return filedata->file_header.e_machine == EM_IA_64
  882. && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS;
  883. }
  884. /* Guess the relocation size commonly used by the specific machines. */
  885. static bool
  886. guess_is_rela (unsigned int e_machine)
  887. {
  888. switch (e_machine)
  889. {
  890. /* Targets that use REL relocations. */
  891. case EM_386:
  892. case EM_IAMCU:
  893. case EM_960:
  894. case EM_ARM:
  895. case EM_D10V:
  896. case EM_CYGNUS_D10V:
  897. case EM_DLX:
  898. case EM_MIPS:
  899. case EM_MIPS_RS3_LE:
  900. case EM_CYGNUS_M32R:
  901. case EM_SCORE:
  902. case EM_XGATE:
  903. case EM_NFP:
  904. case EM_BPF:
  905. return false;
  906. /* Targets that use RELA relocations. */
  907. case EM_68K:
  908. case EM_860:
  909. case EM_AARCH64:
  910. case EM_ADAPTEVA_EPIPHANY:
  911. case EM_ALPHA:
  912. case EM_ALTERA_NIOS2:
  913. case EM_ARC:
  914. case EM_ARC_COMPACT:
  915. case EM_ARC_COMPACT2:
  916. case EM_AVR:
  917. case EM_AVR_OLD:
  918. case EM_BLACKFIN:
  919. case EM_CR16:
  920. case EM_CRIS:
  921. case EM_CRX:
  922. case EM_CSKY:
  923. case EM_D30V:
  924. case EM_CYGNUS_D30V:
  925. case EM_FR30:
  926. case EM_FT32:
  927. case EM_CYGNUS_FR30:
  928. case EM_CYGNUS_FRV:
  929. case EM_H8S:
  930. case EM_H8_300:
  931. case EM_H8_300H:
  932. case EM_IA_64:
  933. case EM_IP2K:
  934. case EM_IP2K_OLD:
  935. case EM_IQ2000:
  936. case EM_LATTICEMICO32:
  937. case EM_M32C_OLD:
  938. case EM_M32C:
  939. case EM_M32R:
  940. case EM_MCORE:
  941. case EM_CYGNUS_MEP:
  942. case EM_METAG:
  943. case EM_MMIX:
  944. case EM_MN10200:
  945. case EM_CYGNUS_MN10200:
  946. case EM_MN10300:
  947. case EM_CYGNUS_MN10300:
  948. case EM_MOXIE:
  949. case EM_MSP430:
  950. case EM_MSP430_OLD:
  951. case EM_MT:
  952. case EM_NDS32:
  953. case EM_NIOS32:
  954. case EM_OR1K:
  955. case EM_PPC64:
  956. case EM_PPC:
  957. case EM_TI_PRU:
  958. case EM_RISCV:
  959. case EM_RL78:
  960. case EM_RX:
  961. case EM_S390:
  962. case EM_S390_OLD:
  963. case EM_SH:
  964. case EM_SPARC:
  965. case EM_SPARC32PLUS:
  966. case EM_SPARCV9:
  967. case EM_SPU:
  968. case EM_TI_C6000:
  969. case EM_TILEGX:
  970. case EM_TILEPRO:
  971. case EM_V800:
  972. case EM_V850:
  973. case EM_CYGNUS_V850:
  974. case EM_VAX:
  975. case EM_VISIUM:
  976. case EM_X86_64:
  977. case EM_L1OM:
  978. case EM_K1OM:
  979. case EM_XSTORMY16:
  980. case EM_XTENSA:
  981. case EM_XTENSA_OLD:
  982. case EM_MICROBLAZE:
  983. case EM_MICROBLAZE_OLD:
  984. case EM_WEBASSEMBLY:
  985. return true;
  986. case EM_68HC05:
  987. case EM_68HC08:
  988. case EM_68HC11:
  989. case EM_68HC16:
  990. case EM_FX66:
  991. case EM_ME16:
  992. case EM_MMA:
  993. case EM_NCPU:
  994. case EM_NDR1:
  995. case EM_PCP:
  996. case EM_ST100:
  997. case EM_ST19:
  998. case EM_ST7:
  999. case EM_ST9PLUS:
  1000. case EM_STARCORE:
  1001. case EM_SVX:
  1002. case EM_TINYJ:
  1003. default:
  1004. warn (_("Don't know about relocations on this machine architecture\n"));
  1005. return false;
  1006. }
  1007. }
  1008. /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
  1009. Returns TRUE upon success, FALSE otherwise. If successful then a
  1010. pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
  1011. and the number of relocs loaded is placed in *NRELASP. It is the caller's
  1012. responsibility to free the allocated buffer. */
  1013. static bool
  1014. slurp_rela_relocs (Filedata * filedata,
  1015. unsigned long rel_offset,
  1016. unsigned long rel_size,
  1017. Elf_Internal_Rela ** relasp,
  1018. unsigned long * nrelasp)
  1019. {
  1020. Elf_Internal_Rela * relas;
  1021. size_t nrelas;
  1022. unsigned int i;
  1023. if (is_32bit_elf)
  1024. {
  1025. Elf32_External_Rela * erelas;
  1026. erelas = (Elf32_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
  1027. rel_size, _("32-bit relocation data"));
  1028. if (!erelas)
  1029. return false;
  1030. nrelas = rel_size / sizeof (Elf32_External_Rela);
  1031. relas = (Elf_Internal_Rela *) cmalloc (nrelas,
  1032. sizeof (Elf_Internal_Rela));
  1033. if (relas == NULL)
  1034. {
  1035. free (erelas);
  1036. error (_("out of memory parsing relocs\n"));
  1037. return false;
  1038. }
  1039. for (i = 0; i < nrelas; i++)
  1040. {
  1041. relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
  1042. relas[i].r_info = BYTE_GET (erelas[i].r_info);
  1043. relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
  1044. }
  1045. free (erelas);
  1046. }
  1047. else
  1048. {
  1049. Elf64_External_Rela * erelas;
  1050. erelas = (Elf64_External_Rela *) get_data (NULL, filedata, rel_offset, 1,
  1051. rel_size, _("64-bit relocation data"));
  1052. if (!erelas)
  1053. return false;
  1054. nrelas = rel_size / sizeof (Elf64_External_Rela);
  1055. relas = (Elf_Internal_Rela *) cmalloc (nrelas,
  1056. sizeof (Elf_Internal_Rela));
  1057. if (relas == NULL)
  1058. {
  1059. free (erelas);
  1060. error (_("out of memory parsing relocs\n"));
  1061. return false;
  1062. }
  1063. for (i = 0; i < nrelas; i++)
  1064. {
  1065. relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
  1066. relas[i].r_info = BYTE_GET (erelas[i].r_info);
  1067. relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
  1068. /* The #ifdef BFD64 below is to prevent a compile time
  1069. warning. We know that if we do not have a 64 bit data
  1070. type that we will never execute this code anyway. */
  1071. #ifdef BFD64
  1072. if (filedata->file_header.e_machine == EM_MIPS
  1073. && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
  1074. {
  1075. /* In little-endian objects, r_info isn't really a
  1076. 64-bit little-endian value: it has a 32-bit
  1077. little-endian symbol index followed by four
  1078. individual byte fields. Reorder INFO
  1079. accordingly. */
  1080. bfd_vma inf = relas[i].r_info;
  1081. inf = (((inf & 0xffffffff) << 32)
  1082. | ((inf >> 56) & 0xff)
  1083. | ((inf >> 40) & 0xff00)
  1084. | ((inf >> 24) & 0xff0000)
  1085. | ((inf >> 8) & 0xff000000));
  1086. relas[i].r_info = inf;
  1087. }
  1088. #endif /* BFD64 */
  1089. }
  1090. free (erelas);
  1091. }
  1092. *relasp = relas;
  1093. *nrelasp = nrelas;
  1094. return true;
  1095. }
  1096. /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes.
  1097. Returns TRUE upon success, FALSE otherwise. If successful then a
  1098. pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
  1099. and the number of relocs loaded is placed in *NRELSP. It is the caller's
  1100. responsibility to free the allocated buffer. */
  1101. static bool
  1102. slurp_rel_relocs (Filedata * filedata,
  1103. unsigned long rel_offset,
  1104. unsigned long rel_size,
  1105. Elf_Internal_Rela ** relsp,
  1106. unsigned long * nrelsp)
  1107. {
  1108. Elf_Internal_Rela * rels;
  1109. size_t nrels;
  1110. unsigned int i;
  1111. if (is_32bit_elf)
  1112. {
  1113. Elf32_External_Rel * erels;
  1114. erels = (Elf32_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
  1115. rel_size, _("32-bit relocation data"));
  1116. if (!erels)
  1117. return false;
  1118. nrels = rel_size / sizeof (Elf32_External_Rel);
  1119. rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
  1120. if (rels == NULL)
  1121. {
  1122. free (erels);
  1123. error (_("out of memory parsing relocs\n"));
  1124. return false;
  1125. }
  1126. for (i = 0; i < nrels; i++)
  1127. {
  1128. rels[i].r_offset = BYTE_GET (erels[i].r_offset);
  1129. rels[i].r_info = BYTE_GET (erels[i].r_info);
  1130. rels[i].r_addend = 0;
  1131. }
  1132. free (erels);
  1133. }
  1134. else
  1135. {
  1136. Elf64_External_Rel * erels;
  1137. erels = (Elf64_External_Rel *) get_data (NULL, filedata, rel_offset, 1,
  1138. rel_size, _("64-bit relocation data"));
  1139. if (!erels)
  1140. return false;
  1141. nrels = rel_size / sizeof (Elf64_External_Rel);
  1142. rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
  1143. if (rels == NULL)
  1144. {
  1145. free (erels);
  1146. error (_("out of memory parsing relocs\n"));
  1147. return false;
  1148. }
  1149. for (i = 0; i < nrels; i++)
  1150. {
  1151. rels[i].r_offset = BYTE_GET (erels[i].r_offset);
  1152. rels[i].r_info = BYTE_GET (erels[i].r_info);
  1153. rels[i].r_addend = 0;
  1154. /* The #ifdef BFD64 below is to prevent a compile time
  1155. warning. We know that if we do not have a 64 bit data
  1156. type that we will never execute this code anyway. */
  1157. #ifdef BFD64
  1158. if (filedata->file_header.e_machine == EM_MIPS
  1159. && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB)
  1160. {
  1161. /* In little-endian objects, r_info isn't really a
  1162. 64-bit little-endian value: it has a 32-bit
  1163. little-endian symbol index followed by four
  1164. individual byte fields. Reorder INFO
  1165. accordingly. */
  1166. bfd_vma inf = rels[i].r_info;
  1167. inf = (((inf & 0xffffffff) << 32)
  1168. | ((inf >> 56) & 0xff)
  1169. | ((inf >> 40) & 0xff00)
  1170. | ((inf >> 24) & 0xff0000)
  1171. | ((inf >> 8) & 0xff000000));
  1172. rels[i].r_info = inf;
  1173. }
  1174. #endif /* BFD64 */
  1175. }
  1176. free (erels);
  1177. }
  1178. *relsp = rels;
  1179. *nrelsp = nrels;
  1180. return true;
  1181. }
  1182. static bool
  1183. slurp_relr_relocs (Filedata * filedata,
  1184. unsigned long relr_offset,
  1185. unsigned long relr_size,
  1186. bfd_vma ** relrsp,
  1187. unsigned long * nrelrsp)
  1188. {
  1189. void *relrs;
  1190. size_t size = 0, nentries, i;
  1191. bfd_vma base = 0, addr, entry;
  1192. relrs = get_data (NULL, filedata, relr_offset, 1, relr_size,
  1193. _("RELR relocation data"));
  1194. if (!relrs)
  1195. return false;
  1196. if (is_32bit_elf)
  1197. nentries = relr_size / sizeof (Elf32_External_Relr);
  1198. else
  1199. nentries = relr_size / sizeof (Elf64_External_Relr);
  1200. for (i = 0; i < nentries; i++)
  1201. {
  1202. if (is_32bit_elf)
  1203. entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data);
  1204. else
  1205. entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
  1206. if ((entry & 1) == 0)
  1207. size++;
  1208. else
  1209. while ((entry >>= 1) != 0)
  1210. if ((entry & 1) == 1)
  1211. size++;
  1212. }
  1213. *relrsp = (bfd_vma *) xmalloc (size * sizeof (bfd_vma));
  1214. if (*relrsp == NULL)
  1215. {
  1216. free (relrs);
  1217. error (_("out of memory parsing relocs\n"));
  1218. return false;
  1219. }
  1220. size = 0;
  1221. for (i = 0; i < nentries; i++)
  1222. {
  1223. const bfd_vma entry_bytes = is_32bit_elf ? 4 : 8;
  1224. if (is_32bit_elf)
  1225. entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data);
  1226. else
  1227. entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
  1228. if ((entry & 1) == 0)
  1229. {
  1230. (*relrsp)[size++] = entry;
  1231. base = entry + entry_bytes;
  1232. }
  1233. else
  1234. {
  1235. for (addr = base; (entry >>= 1) != 0; addr += entry_bytes)
  1236. if ((entry & 1) != 0)
  1237. (*relrsp)[size++] = addr;
  1238. base += entry_bytes * (entry_bytes * CHAR_BIT - 1);
  1239. }
  1240. }
  1241. *nrelrsp = size;
  1242. free (relrs);
  1243. return true;
  1244. }
  1245. /* Returns the reloc type extracted from the reloc info field. */
  1246. static unsigned int
  1247. get_reloc_type (Filedata * filedata, bfd_vma reloc_info)
  1248. {
  1249. if (is_32bit_elf)
  1250. return ELF32_R_TYPE (reloc_info);
  1251. switch (filedata->file_header.e_machine)
  1252. {
  1253. case EM_MIPS:
  1254. /* Note: We assume that reloc_info has already been adjusted for us. */
  1255. return ELF64_MIPS_R_TYPE (reloc_info);
  1256. case EM_SPARCV9:
  1257. return ELF64_R_TYPE_ID (reloc_info);
  1258. default:
  1259. return ELF64_R_TYPE (reloc_info);
  1260. }
  1261. }
  1262. /* Return the symbol index extracted from the reloc info field. */
  1263. static bfd_vma
  1264. get_reloc_symindex (bfd_vma reloc_info)
  1265. {
  1266. return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
  1267. }
  1268. static inline bool
  1269. uses_msp430x_relocs (Filedata * filedata)
  1270. {
  1271. return
  1272. filedata->file_header.e_machine == EM_MSP430 /* Paranoia. */
  1273. /* GCC uses osabi == ELFOSBI_STANDALONE. */
  1274. && (((filedata->file_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X)
  1275. /* TI compiler uses ELFOSABI_NONE. */
  1276. || (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE));
  1277. }
  1278. /* Display the contents of the relocation data found at the specified
  1279. offset. */
  1280. static bool
  1281. dump_relocations (Filedata * filedata,
  1282. unsigned long rel_offset,
  1283. unsigned long rel_size,
  1284. Elf_Internal_Sym * symtab,
  1285. unsigned long nsyms,
  1286. char * strtab,
  1287. unsigned long strtablen,
  1288. relocation_type rel_type,
  1289. bool is_dynsym)
  1290. {
  1291. unsigned long i;
  1292. Elf_Internal_Rela * rels;
  1293. bool res = true;
  1294. if (rel_type == reltype_unknown)
  1295. rel_type = guess_is_rela (filedata->file_header.e_machine) ? reltype_rela : reltype_rel;
  1296. if (rel_type == reltype_rela)
  1297. {
  1298. if (!slurp_rela_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
  1299. return false;
  1300. }
  1301. else if (rel_type == reltype_rel)
  1302. {
  1303. if (!slurp_rel_relocs (filedata, rel_offset, rel_size, &rels, &rel_size))
  1304. return false;
  1305. }
  1306. else if (rel_type == reltype_relr)
  1307. {
  1308. bfd_vma * relrs;
  1309. const char *format
  1310. = is_32bit_elf ? "%08" BFD_VMA_FMT "x\n" : "%016" BFD_VMA_FMT "x\n";
  1311. if (!slurp_relr_relocs (filedata, rel_offset, rel_size, &relrs,
  1312. &rel_size))
  1313. return false;
  1314. printf (ngettext (" %lu offset\n", " %lu offsets\n", rel_size), rel_size);
  1315. for (i = 0; i < rel_size; i++)
  1316. printf (format, relrs[i]);
  1317. free (relrs);
  1318. return true;
  1319. }
  1320. if (is_32bit_elf)
  1321. {
  1322. if (rel_type == reltype_rela)
  1323. {
  1324. if (do_wide)
  1325. printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
  1326. else
  1327. printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
  1328. }
  1329. else
  1330. {
  1331. if (do_wide)
  1332. printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
  1333. else
  1334. printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
  1335. }
  1336. }
  1337. else
  1338. {
  1339. if (rel_type == reltype_rela)
  1340. {
  1341. if (do_wide)
  1342. printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
  1343. else
  1344. printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
  1345. }
  1346. else
  1347. {
  1348. if (do_wide)
  1349. printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
  1350. else
  1351. printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
  1352. }
  1353. }
  1354. for (i = 0; i < rel_size; i++)
  1355. {
  1356. const char * rtype;
  1357. bfd_vma offset;
  1358. bfd_vma inf;
  1359. bfd_vma symtab_index;
  1360. bfd_vma type;
  1361. offset = rels[i].r_offset;
  1362. inf = rels[i].r_info;
  1363. type = get_reloc_type (filedata, inf);
  1364. symtab_index = get_reloc_symindex (inf);
  1365. if (is_32bit_elf)
  1366. {
  1367. printf ("%8.8lx %8.8lx ",
  1368. (unsigned long) offset & 0xffffffff,
  1369. (unsigned long) inf & 0xffffffff);
  1370. }
  1371. else
  1372. {
  1373. printf (do_wide
  1374. ? "%16.16" BFD_VMA_FMT "x %16.16" BFD_VMA_FMT "x "
  1375. : "%12.12" BFD_VMA_FMT "x %12.12" BFD_VMA_FMT "x ",
  1376. offset, inf);
  1377. }
  1378. switch (filedata->file_header.e_machine)
  1379. {
  1380. default:
  1381. rtype = NULL;
  1382. break;
  1383. case EM_AARCH64:
  1384. rtype = elf_aarch64_reloc_type (type);
  1385. break;
  1386. case EM_M32R:
  1387. case EM_CYGNUS_M32R:
  1388. rtype = elf_m32r_reloc_type (type);
  1389. break;
  1390. case EM_386:
  1391. case EM_IAMCU:
  1392. rtype = elf_i386_reloc_type (type);
  1393. break;
  1394. case EM_68HC11:
  1395. case EM_68HC12:
  1396. rtype = elf_m68hc11_reloc_type (type);
  1397. break;
  1398. case EM_S12Z:
  1399. rtype = elf_s12z_reloc_type (type);
  1400. break;
  1401. case EM_68K:
  1402. rtype = elf_m68k_reloc_type (type);
  1403. break;
  1404. case EM_960:
  1405. rtype = elf_i960_reloc_type (type);
  1406. break;
  1407. case EM_AVR:
  1408. case EM_AVR_OLD:
  1409. rtype = elf_avr_reloc_type (type);
  1410. break;
  1411. case EM_OLD_SPARCV9:
  1412. case EM_SPARC32PLUS:
  1413. case EM_SPARCV9:
  1414. case EM_SPARC:
  1415. rtype = elf_sparc_reloc_type (type);
  1416. break;
  1417. case EM_SPU:
  1418. rtype = elf_spu_reloc_type (type);
  1419. break;
  1420. case EM_V800:
  1421. rtype = v800_reloc_type (type);
  1422. break;
  1423. case EM_V850:
  1424. case EM_CYGNUS_V850:
  1425. rtype = v850_reloc_type (type);
  1426. break;
  1427. case EM_D10V:
  1428. case EM_CYGNUS_D10V:
  1429. rtype = elf_d10v_reloc_type (type);
  1430. break;
  1431. case EM_D30V:
  1432. case EM_CYGNUS_D30V:
  1433. rtype = elf_d30v_reloc_type (type);
  1434. break;
  1435. case EM_DLX:
  1436. rtype = elf_dlx_reloc_type (type);
  1437. break;
  1438. case EM_SH:
  1439. rtype = elf_sh_reloc_type (type);
  1440. break;
  1441. case EM_MN10300:
  1442. case EM_CYGNUS_MN10300:
  1443. rtype = elf_mn10300_reloc_type (type);
  1444. break;
  1445. case EM_MN10200:
  1446. case EM_CYGNUS_MN10200:
  1447. rtype = elf_mn10200_reloc_type (type);
  1448. break;
  1449. case EM_FR30:
  1450. case EM_CYGNUS_FR30:
  1451. rtype = elf_fr30_reloc_type (type);
  1452. break;
  1453. case EM_CYGNUS_FRV:
  1454. rtype = elf_frv_reloc_type (type);
  1455. break;
  1456. case EM_CSKY:
  1457. rtype = elf_csky_reloc_type (type);
  1458. break;
  1459. case EM_FT32:
  1460. rtype = elf_ft32_reloc_type (type);
  1461. break;
  1462. case EM_MCORE:
  1463. rtype = elf_mcore_reloc_type (type);
  1464. break;
  1465. case EM_MMIX:
  1466. rtype = elf_mmix_reloc_type (type);
  1467. break;
  1468. case EM_MOXIE:
  1469. rtype = elf_moxie_reloc_type (type);
  1470. break;
  1471. case EM_MSP430:
  1472. if (uses_msp430x_relocs (filedata))
  1473. {
  1474. rtype = elf_msp430x_reloc_type (type);
  1475. break;
  1476. }
  1477. /* Fall through. */
  1478. case EM_MSP430_OLD:
  1479. rtype = elf_msp430_reloc_type (type);
  1480. break;
  1481. case EM_NDS32:
  1482. rtype = elf_nds32_reloc_type (type);
  1483. break;
  1484. case EM_PPC:
  1485. rtype = elf_ppc_reloc_type (type);
  1486. break;
  1487. case EM_PPC64:
  1488. rtype = elf_ppc64_reloc_type (type);
  1489. break;
  1490. case EM_MIPS:
  1491. case EM_MIPS_RS3_LE:
  1492. rtype = elf_mips_reloc_type (type);
  1493. break;
  1494. case EM_RISCV:
  1495. rtype = elf_riscv_reloc_type (type);
  1496. break;
  1497. case EM_ALPHA:
  1498. rtype = elf_alpha_reloc_type (type);
  1499. break;
  1500. case EM_ARM:
  1501. rtype = elf_arm_reloc_type (type);
  1502. break;
  1503. case EM_ARC:
  1504. case EM_ARC_COMPACT:
  1505. case EM_ARC_COMPACT2:
  1506. rtype = elf_arc_reloc_type (type);
  1507. break;
  1508. case EM_PARISC:
  1509. rtype = elf_hppa_reloc_type (type);
  1510. break;
  1511. case EM_H8_300:
  1512. case EM_H8_300H:
  1513. case EM_H8S:
  1514. rtype = elf_h8_reloc_type (type);
  1515. break;
  1516. case EM_OR1K:
  1517. rtype = elf_or1k_reloc_type (type);
  1518. break;
  1519. case EM_PJ:
  1520. case EM_PJ_OLD:
  1521. rtype = elf_pj_reloc_type (type);
  1522. break;
  1523. case EM_IA_64:
  1524. rtype = elf_ia64_reloc_type (type);
  1525. break;
  1526. case EM_CRIS:
  1527. rtype = elf_cris_reloc_type (type);
  1528. break;
  1529. case EM_860:
  1530. rtype = elf_i860_reloc_type (type);
  1531. break;
  1532. case EM_X86_64:
  1533. case EM_L1OM:
  1534. case EM_K1OM:
  1535. rtype = elf_x86_64_reloc_type (type);
  1536. break;
  1537. case EM_S370:
  1538. rtype = i370_reloc_type (type);
  1539. break;
  1540. case EM_S390_OLD:
  1541. case EM_S390:
  1542. rtype = elf_s390_reloc_type (type);
  1543. break;
  1544. case EM_SCORE:
  1545. rtype = elf_score_reloc_type (type);
  1546. break;
  1547. case EM_XSTORMY16:
  1548. rtype = elf_xstormy16_reloc_type (type);
  1549. break;
  1550. case EM_CRX:
  1551. rtype = elf_crx_reloc_type (type);
  1552. break;
  1553. case EM_VAX:
  1554. rtype = elf_vax_reloc_type (type);
  1555. break;
  1556. case EM_VISIUM:
  1557. rtype = elf_visium_reloc_type (type);
  1558. break;
  1559. case EM_BPF:
  1560. rtype = elf_bpf_reloc_type (type);
  1561. break;
  1562. case EM_ADAPTEVA_EPIPHANY:
  1563. rtype = elf_epiphany_reloc_type (type);
  1564. break;
  1565. case EM_IP2K:
  1566. case EM_IP2K_OLD:
  1567. rtype = elf_ip2k_reloc_type (type);
  1568. break;
  1569. case EM_IQ2000:
  1570. rtype = elf_iq2000_reloc_type (type);
  1571. break;
  1572. case EM_XTENSA_OLD:
  1573. case EM_XTENSA:
  1574. rtype = elf_xtensa_reloc_type (type);
  1575. break;
  1576. case EM_LATTICEMICO32:
  1577. rtype = elf_lm32_reloc_type (type);
  1578. break;
  1579. case EM_M32C_OLD:
  1580. case EM_M32C:
  1581. rtype = elf_m32c_reloc_type (type);
  1582. break;
  1583. case EM_MT:
  1584. rtype = elf_mt_reloc_type (type);
  1585. break;
  1586. case EM_BLACKFIN:
  1587. rtype = elf_bfin_reloc_type (type);
  1588. break;
  1589. case EM_CYGNUS_MEP:
  1590. rtype = elf_mep_reloc_type (type);
  1591. break;
  1592. case EM_CR16:
  1593. rtype = elf_cr16_reloc_type (type);
  1594. break;
  1595. case EM_MICROBLAZE:
  1596. case EM_MICROBLAZE_OLD:
  1597. rtype = elf_microblaze_reloc_type (type);
  1598. break;
  1599. case EM_RL78:
  1600. rtype = elf_rl78_reloc_type (type);
  1601. break;
  1602. case EM_RX:
  1603. rtype = elf_rx_reloc_type (type);
  1604. break;
  1605. case EM_METAG:
  1606. rtype = elf_metag_reloc_type (type);
  1607. break;
  1608. case EM_XC16X:
  1609. case EM_C166:
  1610. rtype = elf_xc16x_reloc_type (type);
  1611. break;
  1612. case EM_TI_C6000:
  1613. rtype = elf_tic6x_reloc_type (type);
  1614. break;
  1615. case EM_TILEGX:
  1616. rtype = elf_tilegx_reloc_type (type);
  1617. break;
  1618. case EM_TILEPRO:
  1619. rtype = elf_tilepro_reloc_type (type);
  1620. break;
  1621. case EM_WEBASSEMBLY:
  1622. rtype = elf_wasm32_reloc_type (type);
  1623. break;
  1624. case EM_XGATE:
  1625. rtype = elf_xgate_reloc_type (type);
  1626. break;
  1627. case EM_ALTERA_NIOS2:
  1628. rtype = elf_nios2_reloc_type (type);
  1629. break;
  1630. case EM_TI_PRU:
  1631. rtype = elf_pru_reloc_type (type);
  1632. break;
  1633. case EM_NFP:
  1634. if (EF_NFP_MACH (filedata->file_header.e_flags) == E_NFP_MACH_3200)
  1635. rtype = elf_nfp3200_reloc_type (type);
  1636. else
  1637. rtype = elf_nfp_reloc_type (type);
  1638. break;
  1639. case EM_Z80:
  1640. rtype = elf_z80_reloc_type (type);
  1641. break;
  1642. case EM_LOONGARCH:
  1643. rtype = elf_loongarch_reloc_type (type);
  1644. break;
  1645. case EM_AMDGPU:
  1646. rtype = elf_amdgpu_reloc_type (type);
  1647. break;
  1648. }
  1649. if (rtype == NULL)
  1650. printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
  1651. else
  1652. printf (do_wide ? "%-22s" : "%-17.17s", rtype);
  1653. if (filedata->file_header.e_machine == EM_ALPHA
  1654. && rtype != NULL
  1655. && streq (rtype, "R_ALPHA_LITUSE")
  1656. && rel_type == reltype_rela)
  1657. {
  1658. switch (rels[i].r_addend)
  1659. {
  1660. case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
  1661. case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
  1662. case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
  1663. case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
  1664. case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
  1665. case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
  1666. case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
  1667. default: rtype = NULL;
  1668. }
  1669. if (rtype)
  1670. printf (" (%s)", rtype);
  1671. else
  1672. {
  1673. putchar (' ');
  1674. printf (_("<unknown addend: %lx>"),
  1675. (unsigned long) rels[i].r_addend);
  1676. res = false;
  1677. }
  1678. }
  1679. else if (symtab_index)
  1680. {
  1681. if (symtab == NULL || symtab_index >= nsyms)
  1682. {
  1683. error (_(" bad symbol index: %08lx in reloc\n"),
  1684. (unsigned long) symtab_index);
  1685. res = false;
  1686. }
  1687. else
  1688. {
  1689. Elf_Internal_Sym * psym;
  1690. const char * version_string;
  1691. enum versioned_symbol_info sym_info;
  1692. unsigned short vna_other;
  1693. psym = symtab + symtab_index;
  1694. version_string
  1695. = get_symbol_version_string (filedata, is_dynsym,
  1696. strtab, strtablen,
  1697. symtab_index,
  1698. psym,
  1699. &sym_info,
  1700. &vna_other);
  1701. printf (" ");
  1702. if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
  1703. {
  1704. const char * name;
  1705. unsigned int len;
  1706. unsigned int width = is_32bit_elf ? 8 : 14;
  1707. /* Relocations against GNU_IFUNC symbols do not use the value
  1708. of the symbol as the address to relocate against. Instead
  1709. they invoke the function named by the symbol and use its
  1710. result as the address for relocation.
  1711. To indicate this to the user, do not display the value of
  1712. the symbol in the "Symbols's Value" field. Instead show
  1713. its name followed by () as a hint that the symbol is
  1714. invoked. */
  1715. if (strtab == NULL
  1716. || psym->st_name == 0
  1717. || psym->st_name >= strtablen)
  1718. name = "??";
  1719. else
  1720. name = strtab + psym->st_name;
  1721. len = print_symbol (width, name);
  1722. if (version_string)
  1723. printf (sym_info == symbol_public ? "@@%s" : "@%s",
  1724. version_string);
  1725. printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
  1726. }
  1727. else
  1728. {
  1729. print_vma (psym->st_value, LONG_HEX);
  1730. printf (is_32bit_elf ? " " : " ");
  1731. }
  1732. if (psym->st_name == 0)
  1733. {
  1734. const char * sec_name = "<null>";
  1735. char name_buf[40];
  1736. if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
  1737. {
  1738. if (psym->st_shndx < filedata->file_header.e_shnum
  1739. && filedata->section_headers != NULL)
  1740. sec_name = section_name_print (filedata,
  1741. filedata->section_headers
  1742. + psym->st_shndx);
  1743. else if (psym->st_shndx == SHN_ABS)
  1744. sec_name = "ABS";
  1745. else if (psym->st_shndx == SHN_COMMON)
  1746. sec_name = "COMMON";
  1747. else if ((filedata->file_header.e_machine == EM_MIPS
  1748. && psym->st_shndx == SHN_MIPS_SCOMMON)
  1749. || (filedata->file_header.e_machine == EM_TI_C6000
  1750. && psym->st_shndx == SHN_TIC6X_SCOMMON))
  1751. sec_name = "SCOMMON";
  1752. else if (filedata->file_header.e_machine == EM_MIPS
  1753. && psym->st_shndx == SHN_MIPS_SUNDEFINED)
  1754. sec_name = "SUNDEF";
  1755. else if ((filedata->file_header.e_machine == EM_X86_64
  1756. || filedata->file_header.e_machine == EM_L1OM
  1757. || filedata->file_header.e_machine == EM_K1OM)
  1758. && psym->st_shndx == SHN_X86_64_LCOMMON)
  1759. sec_name = "LARGE_COMMON";
  1760. else if (filedata->file_header.e_machine == EM_IA_64
  1761. && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
  1762. && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
  1763. sec_name = "ANSI_COM";
  1764. else if (is_ia64_vms (filedata)
  1765. && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
  1766. sec_name = "VMS_SYMVEC";
  1767. else
  1768. {
  1769. sprintf (name_buf, "<section 0x%x>",
  1770. (unsigned int) psym->st_shndx);
  1771. sec_name = name_buf;
  1772. }
  1773. }
  1774. print_symbol (22, sec_name);
  1775. }
  1776. else if (strtab == NULL)
  1777. printf (_("<string table index: %3ld>"), psym->st_name);
  1778. else if (psym->st_name >= strtablen)
  1779. {
  1780. error (_("<corrupt string table index: %3ld>\n"),
  1781. psym->st_name);
  1782. res = false;
  1783. }
  1784. else
  1785. {
  1786. print_symbol (22, strtab + psym->st_name);
  1787. if (version_string)
  1788. printf (sym_info == symbol_public ? "@@%s" : "@%s",
  1789. version_string);
  1790. }
  1791. if (rel_type == reltype_rela)
  1792. {
  1793. bfd_vma off = rels[i].r_addend;
  1794. if ((bfd_signed_vma) off < 0)
  1795. printf (" - %" BFD_VMA_FMT "x", - off);
  1796. else
  1797. printf (" + %" BFD_VMA_FMT "x", off);
  1798. }
  1799. }
  1800. }
  1801. else if (rel_type == reltype_rela)
  1802. {
  1803. bfd_vma off = rels[i].r_addend;
  1804. printf ("%*c", is_32bit_elf ? 12 : 20, ' ');
  1805. if ((bfd_signed_vma) off < 0)
  1806. printf ("-%" BFD_VMA_FMT "x", - off);
  1807. else
  1808. printf ("%" BFD_VMA_FMT "x", off);
  1809. }
  1810. if (filedata->file_header.e_machine == EM_SPARCV9
  1811. && rtype != NULL
  1812. && streq (rtype, "R_SPARC_OLO10"))
  1813. printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf));
  1814. putchar ('\n');
  1815. #ifdef BFD64
  1816. if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS)
  1817. {
  1818. bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf);
  1819. bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf);
  1820. const char * rtype2 = elf_mips_reloc_type (type2);
  1821. const char * rtype3 = elf_mips_reloc_type (type3);
  1822. printf (" Type2: ");
  1823. if (rtype2 == NULL)
  1824. printf (_("unrecognized: %-7lx"),
  1825. (unsigned long) type2 & 0xffffffff);
  1826. else
  1827. printf ("%-17.17s", rtype2);
  1828. printf ("\n Type3: ");
  1829. if (rtype3 == NULL)
  1830. printf (_("unrecognized: %-7lx"),
  1831. (unsigned long) type3 & 0xffffffff);
  1832. else
  1833. printf ("%-17.17s", rtype3);
  1834. putchar ('\n');
  1835. }
  1836. #endif /* BFD64 */
  1837. }
  1838. free (rels);
  1839. return res;
  1840. }
  1841. static const char *
  1842. get_aarch64_dynamic_type (unsigned long type)
  1843. {
  1844. switch (type)
  1845. {
  1846. case DT_AARCH64_BTI_PLT: return "AARCH64_BTI_PLT";
  1847. case DT_AARCH64_PAC_PLT: return "AARCH64_PAC_PLT";
  1848. case DT_AARCH64_VARIANT_PCS: return "AARCH64_VARIANT_PCS";
  1849. default:
  1850. return NULL;
  1851. }
  1852. }
  1853. static const char *
  1854. get_mips_dynamic_type (unsigned long type)
  1855. {
  1856. switch (type)
  1857. {
  1858. case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
  1859. case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
  1860. case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
  1861. case DT_MIPS_IVERSION: return "MIPS_IVERSION";
  1862. case DT_MIPS_FLAGS: return "MIPS_FLAGS";
  1863. case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
  1864. case DT_MIPS_MSYM: return "MIPS_MSYM";
  1865. case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
  1866. case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
  1867. case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
  1868. case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
  1869. case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
  1870. case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
  1871. case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
  1872. case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
  1873. case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
  1874. case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
  1875. case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL";
  1876. case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
  1877. case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
  1878. case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
  1879. case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
  1880. case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
  1881. case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
  1882. case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
  1883. case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
  1884. case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
  1885. case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
  1886. case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
  1887. case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
  1888. case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
  1889. case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
  1890. case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
  1891. case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
  1892. case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
  1893. case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
  1894. case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
  1895. case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
  1896. case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
  1897. case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
  1898. case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
  1899. case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
  1900. case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
  1901. case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
  1902. case DT_MIPS_PLTGOT: return "MIPS_PLTGOT";
  1903. case DT_MIPS_RWPLT: return "MIPS_RWPLT";
  1904. case DT_MIPS_XHASH: return "MIPS_XHASH";
  1905. default:
  1906. return NULL;
  1907. }
  1908. }
  1909. static const char *
  1910. get_sparc64_dynamic_type (unsigned long type)
  1911. {
  1912. switch (type)
  1913. {
  1914. case DT_SPARC_REGISTER: return "SPARC_REGISTER";
  1915. default:
  1916. return NULL;
  1917. }
  1918. }
  1919. static const char *
  1920. get_ppc_dynamic_type (unsigned long type)
  1921. {
  1922. switch (type)
  1923. {
  1924. case DT_PPC_GOT: return "PPC_GOT";
  1925. case DT_PPC_OPT: return "PPC_OPT";
  1926. default:
  1927. return NULL;
  1928. }
  1929. }
  1930. static const char *
  1931. get_ppc64_dynamic_type (unsigned long type)
  1932. {
  1933. switch (type)
  1934. {
  1935. case DT_PPC64_GLINK: return "PPC64_GLINK";
  1936. case DT_PPC64_OPD: return "PPC64_OPD";
  1937. case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
  1938. case DT_PPC64_OPT: return "PPC64_OPT";
  1939. default:
  1940. return NULL;
  1941. }
  1942. }
  1943. static const char *
  1944. get_parisc_dynamic_type (unsigned long type)
  1945. {
  1946. switch (type)
  1947. {
  1948. case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
  1949. case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
  1950. case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
  1951. case DT_HP_UX10_INIT: return "HP_UX10_INIT";
  1952. case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
  1953. case DT_HP_PREINIT: return "HP_PREINIT";
  1954. case DT_HP_PREINITSZ: return "HP_PREINITSZ";
  1955. case DT_HP_NEEDED: return "HP_NEEDED";
  1956. case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
  1957. case DT_HP_CHECKSUM: return "HP_CHECKSUM";
  1958. case DT_HP_GST_SIZE: return "HP_GST_SIZE";
  1959. case DT_HP_GST_VERSION: return "HP_GST_VERSION";
  1960. case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
  1961. case DT_HP_EPLTREL: return "HP_GST_EPLTREL";
  1962. case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ";
  1963. case DT_HP_FILTERED: return "HP_FILTERED";
  1964. case DT_HP_FILTER_TLS: return "HP_FILTER_TLS";
  1965. case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
  1966. case DT_HP_LAZYLOAD: return "HP_LAZYLOAD";
  1967. case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT";
  1968. case DT_PLT: return "PLT";
  1969. case DT_PLT_SIZE: return "PLT_SIZE";
  1970. case DT_DLT: return "DLT";
  1971. case DT_DLT_SIZE: return "DLT_SIZE";
  1972. default:
  1973. return NULL;
  1974. }
  1975. }
  1976. static const char *
  1977. get_ia64_dynamic_type (unsigned long type)
  1978. {
  1979. switch (type)
  1980. {
  1981. case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
  1982. case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE";
  1983. case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT";
  1984. case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS";
  1985. case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
  1986. case DT_IA_64_VMS_IDENT: return "VMS_IDENT";
  1987. case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT";
  1988. case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT";
  1989. case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT";
  1990. case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT";
  1991. case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED";
  1992. case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT";
  1993. case DT_IA_64_VMS_XLATED: return "VMS_XLATED";
  1994. case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE";
  1995. case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ";
  1996. case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG";
  1997. case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG";
  1998. case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME";
  1999. case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO";
  2000. case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET";
  2001. case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG";
  2002. case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET";
  2003. case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG";
  2004. case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET";
  2005. case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET";
  2006. case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF";
  2007. case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF";
  2008. case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF";
  2009. case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET";
  2010. case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG";
  2011. case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE";
  2012. default:
  2013. return NULL;
  2014. }
  2015. }
  2016. static const char *
  2017. get_solaris_section_type (unsigned long type)
  2018. {
  2019. switch (type)
  2020. {
  2021. case 0x6fffffee: return "SUNW_ancillary";
  2022. case 0x6fffffef: return "SUNW_capchain";
  2023. case 0x6ffffff0: return "SUNW_capinfo";
  2024. case 0x6ffffff1: return "SUNW_symsort";
  2025. case 0x6ffffff2: return "SUNW_tlssort";
  2026. case 0x6ffffff3: return "SUNW_LDYNSYM";
  2027. case 0x6ffffff4: return "SUNW_dof";
  2028. case 0x6ffffff5: return "SUNW_cap";
  2029. case 0x6ffffff6: return "SUNW_SIGNATURE";
  2030. case 0x6ffffff7: return "SUNW_ANNOTATE";
  2031. case 0x6ffffff8: return "SUNW_DEBUGSTR";
  2032. case 0x6ffffff9: return "SUNW_DEBUG";
  2033. case 0x6ffffffa: return "SUNW_move";
  2034. case 0x6ffffffb: return "SUNW_COMDAT";
  2035. case 0x6ffffffc: return "SUNW_syminfo";
  2036. case 0x6ffffffd: return "SUNW_verdef";
  2037. case 0x6ffffffe: return "SUNW_verneed";
  2038. case 0x6fffffff: return "SUNW_versym";
  2039. case 0x70000000: return "SPARC_GOTDATA";
  2040. default: return NULL;
  2041. }
  2042. }
  2043. static const char *
  2044. get_alpha_dynamic_type (unsigned long type)
  2045. {
  2046. switch (type)
  2047. {
  2048. case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
  2049. default: return NULL;
  2050. }
  2051. }
  2052. static const char *
  2053. get_score_dynamic_type (unsigned long type)
  2054. {
  2055. switch (type)
  2056. {
  2057. case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
  2058. case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO";
  2059. case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO";
  2060. case DT_SCORE_GOTSYM: return "SCORE_GOTSYM";
  2061. case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO";
  2062. case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO";
  2063. default: return NULL;
  2064. }
  2065. }
  2066. static const char *
  2067. get_tic6x_dynamic_type (unsigned long type)
  2068. {
  2069. switch (type)
  2070. {
  2071. case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET";
  2072. case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET";
  2073. case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE";
  2074. case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE";
  2075. case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
  2076. case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX";
  2077. default: return NULL;
  2078. }
  2079. }
  2080. static const char *
  2081. get_nios2_dynamic_type (unsigned long type)
  2082. {
  2083. switch (type)
  2084. {
  2085. case DT_NIOS2_GP: return "NIOS2_GP";
  2086. default: return NULL;
  2087. }
  2088. }
  2089. static const char *
  2090. get_solaris_dynamic_type (unsigned long type)
  2091. {
  2092. switch (type)
  2093. {
  2094. case 0x6000000d: return "SUNW_AUXILIARY";
  2095. case 0x6000000e: return "SUNW_RTLDINF";
  2096. case 0x6000000f: return "SUNW_FILTER";
  2097. case 0x60000010: return "SUNW_CAP";
  2098. case 0x60000011: return "SUNW_SYMTAB";
  2099. case 0x60000012: return "SUNW_SYMSZ";
  2100. case 0x60000013: return "SUNW_SORTENT";
  2101. case 0x60000014: return "SUNW_SYMSORT";
  2102. case 0x60000015: return "SUNW_SYMSORTSZ";
  2103. case 0x60000016: return "SUNW_TLSSORT";
  2104. case 0x60000017: return "SUNW_TLSSORTSZ";
  2105. case 0x60000018: return "SUNW_CAPINFO";
  2106. case 0x60000019: return "SUNW_STRPAD";
  2107. case 0x6000001a: return "SUNW_CAPCHAIN";
  2108. case 0x6000001b: return "SUNW_LDMACH";
  2109. case 0x6000001d: return "SUNW_CAPCHAINENT";
  2110. case 0x6000001f: return "SUNW_CAPCHAINSZ";
  2111. case 0x60000021: return "SUNW_PARENT";
  2112. case 0x60000023: return "SUNW_ASLR";
  2113. case 0x60000025: return "SUNW_RELAX";
  2114. case 0x60000029: return "SUNW_NXHEAP";
  2115. case 0x6000002b: return "SUNW_NXSTACK";
  2116. case 0x70000001: return "SPARC_REGISTER";
  2117. case 0x7ffffffd: return "AUXILIARY";
  2118. case 0x7ffffffe: return "USED";
  2119. case 0x7fffffff: return "FILTER";
  2120. default: return NULL;
  2121. }
  2122. }
  2123. static const char *
  2124. get_riscv_dynamic_type (unsigned long type)
  2125. {
  2126. switch (type)
  2127. {
  2128. case DT_RISCV_VARIANT_CC: return "RISCV_VARIANT_CC";
  2129. default:
  2130. return NULL;
  2131. }
  2132. }
  2133. static const char *
  2134. get_dynamic_type (Filedata * filedata, unsigned long type)
  2135. {
  2136. static char buff[64];
  2137. switch (type)
  2138. {
  2139. case DT_NULL: return "NULL";
  2140. case DT_NEEDED: return "NEEDED";
  2141. case DT_PLTRELSZ: return "PLTRELSZ";
  2142. case DT_PLTGOT: return "PLTGOT";
  2143. case DT_HASH: return "HASH";
  2144. case DT_STRTAB: return "STRTAB";
  2145. case DT_SYMTAB: return "SYMTAB";
  2146. case DT_RELA: return "RELA";
  2147. case DT_RELASZ: return "RELASZ";
  2148. case DT_RELAENT: return "RELAENT";
  2149. case DT_STRSZ: return "STRSZ";
  2150. case DT_SYMENT: return "SYMENT";
  2151. case DT_INIT: return "INIT";
  2152. case DT_FINI: return "FINI";
  2153. case DT_SONAME: return "SONAME";
  2154. case DT_RPATH: return "RPATH";
  2155. case DT_SYMBOLIC: return "SYMBOLIC";
  2156. case DT_REL: return "REL";
  2157. case DT_RELSZ: return "RELSZ";
  2158. case DT_RELENT: return "RELENT";
  2159. case DT_RELR: return "RELR";
  2160. case DT_RELRSZ: return "RELRSZ";
  2161. case DT_RELRENT: return "RELRENT";
  2162. case DT_PLTREL: return "PLTREL";
  2163. case DT_DEBUG: return "DEBUG";
  2164. case DT_TEXTREL: return "TEXTREL";
  2165. case DT_JMPREL: return "JMPREL";
  2166. case DT_BIND_NOW: return "BIND_NOW";
  2167. case DT_INIT_ARRAY: return "INIT_ARRAY";
  2168. case DT_FINI_ARRAY: return "FINI_ARRAY";
  2169. case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
  2170. case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
  2171. case DT_RUNPATH: return "RUNPATH";
  2172. case DT_FLAGS: return "FLAGS";
  2173. case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
  2174. case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
  2175. case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX";
  2176. case DT_CHECKSUM: return "CHECKSUM";
  2177. case DT_PLTPADSZ: return "PLTPADSZ";
  2178. case DT_MOVEENT: return "MOVEENT";
  2179. case DT_MOVESZ: return "MOVESZ";
  2180. case DT_FEATURE: return "FEATURE";
  2181. case DT_POSFLAG_1: return "POSFLAG_1";
  2182. case DT_SYMINSZ: return "SYMINSZ";
  2183. case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
  2184. case DT_ADDRRNGLO: return "ADDRRNGLO";
  2185. case DT_CONFIG: return "CONFIG";
  2186. case DT_DEPAUDIT: return "DEPAUDIT";
  2187. case DT_AUDIT: return "AUDIT";
  2188. case DT_PLTPAD: return "PLTPAD";
  2189. case DT_MOVETAB: return "MOVETAB";
  2190. case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
  2191. case DT_VERSYM: return "VERSYM";
  2192. case DT_TLSDESC_GOT: return "TLSDESC_GOT";
  2193. case DT_TLSDESC_PLT: return "TLSDESC_PLT";
  2194. case DT_RELACOUNT: return "RELACOUNT";
  2195. case DT_RELCOUNT: return "RELCOUNT";
  2196. case DT_FLAGS_1: return "FLAGS_1";
  2197. case DT_VERDEF: return "VERDEF";
  2198. case DT_VERDEFNUM: return "VERDEFNUM";
  2199. case DT_VERNEED: return "VERNEED";
  2200. case DT_VERNEEDNUM: return "VERNEEDNUM";
  2201. case DT_AUXILIARY: return "AUXILIARY";
  2202. case DT_USED: return "USED";
  2203. case DT_FILTER: return "FILTER";
  2204. case DT_GNU_PRELINKED: return "GNU_PRELINKED";
  2205. case DT_GNU_CONFLICT: return "GNU_CONFLICT";
  2206. case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
  2207. case DT_GNU_LIBLIST: return "GNU_LIBLIST";
  2208. case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
  2209. case DT_GNU_HASH: return "GNU_HASH";
  2210. case DT_GNU_FLAGS_1: return "GNU_FLAGS_1";
  2211. default:
  2212. if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
  2213. {
  2214. const char * result;
  2215. switch (filedata->file_header.e_machine)
  2216. {
  2217. case EM_AARCH64:
  2218. result = get_aarch64_dynamic_type (type);
  2219. break;
  2220. case EM_MIPS:
  2221. case EM_MIPS_RS3_LE:
  2222. result = get_mips_dynamic_type (type);
  2223. break;
  2224. case EM_SPARCV9:
  2225. result = get_sparc64_dynamic_type (type);
  2226. break;
  2227. case EM_PPC:
  2228. result = get_ppc_dynamic_type (type);
  2229. break;
  2230. case EM_PPC64:
  2231. result = get_ppc64_dynamic_type (type);
  2232. break;
  2233. case EM_IA_64:
  2234. result = get_ia64_dynamic_type (type);
  2235. break;
  2236. case EM_ALPHA:
  2237. result = get_alpha_dynamic_type (type);
  2238. break;
  2239. case EM_SCORE:
  2240. result = get_score_dynamic_type (type);
  2241. break;
  2242. case EM_TI_C6000:
  2243. result = get_tic6x_dynamic_type (type);
  2244. break;
  2245. case EM_ALTERA_NIOS2:
  2246. result = get_nios2_dynamic_type (type);
  2247. break;
  2248. case EM_RISCV:
  2249. result = get_riscv_dynamic_type (type);
  2250. break;
  2251. default:
  2252. if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
  2253. result = get_solaris_dynamic_type (type);
  2254. else
  2255. result = NULL;
  2256. break;
  2257. }
  2258. if (result != NULL)
  2259. return result;
  2260. snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
  2261. }
  2262. else if (((type >= DT_LOOS) && (type <= DT_HIOS))
  2263. || (filedata->file_header.e_machine == EM_PARISC
  2264. && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
  2265. {
  2266. const char * result;
  2267. switch (filedata->file_header.e_machine)
  2268. {
  2269. case EM_PARISC:
  2270. result = get_parisc_dynamic_type (type);
  2271. break;
  2272. case EM_IA_64:
  2273. result = get_ia64_dynamic_type (type);
  2274. break;
  2275. default:
  2276. if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
  2277. result = get_solaris_dynamic_type (type);
  2278. else
  2279. result = NULL;
  2280. break;
  2281. }
  2282. if (result != NULL)
  2283. return result;
  2284. snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
  2285. type);
  2286. }
  2287. else
  2288. snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
  2289. return buff;
  2290. }
  2291. }
  2292. static bool get_program_headers (Filedata *);
  2293. static bool get_dynamic_section (Filedata *);
  2294. static void
  2295. locate_dynamic_section (Filedata *filedata)
  2296. {
  2297. unsigned long dynamic_addr = 0;
  2298. bfd_size_type dynamic_size = 0;
  2299. if (filedata->file_header.e_phnum != 0
  2300. && get_program_headers (filedata))
  2301. {
  2302. Elf_Internal_Phdr *segment;
  2303. unsigned int i;
  2304. for (i = 0, segment = filedata->program_headers;
  2305. i < filedata->file_header.e_phnum;
  2306. i++, segment++)
  2307. {
  2308. if (segment->p_type == PT_DYNAMIC)
  2309. {
  2310. dynamic_addr = segment->p_offset;
  2311. dynamic_size = segment->p_filesz;
  2312. if (filedata->section_headers != NULL)
  2313. {
  2314. Elf_Internal_Shdr *sec;
  2315. sec = find_section (filedata, ".dynamic");
  2316. if (sec != NULL)
  2317. {
  2318. if (sec->sh_size == 0
  2319. || sec->sh_type == SHT_NOBITS)
  2320. {
  2321. dynamic_addr = 0;
  2322. dynamic_size = 0;
  2323. }
  2324. else
  2325. {
  2326. dynamic_addr = sec->sh_offset;
  2327. dynamic_size = sec->sh_size;
  2328. }
  2329. }
  2330. }
  2331. if (dynamic_addr > filedata->file_size
  2332. || (dynamic_size > filedata->file_size - dynamic_addr))
  2333. {
  2334. dynamic_addr = 0;
  2335. dynamic_size = 0;
  2336. }
  2337. break;
  2338. }
  2339. }
  2340. }
  2341. filedata->dynamic_addr = dynamic_addr;
  2342. filedata->dynamic_size = dynamic_size ? dynamic_size : 1;
  2343. }
  2344. static bool
  2345. is_pie (Filedata *filedata)
  2346. {
  2347. Elf_Internal_Dyn *entry;
  2348. if (filedata->dynamic_size == 0)
  2349. locate_dynamic_section (filedata);
  2350. if (filedata->dynamic_size <= 1)
  2351. return false;
  2352. if (!get_dynamic_section (filedata))
  2353. return false;
  2354. for (entry = filedata->dynamic_section;
  2355. entry < filedata->dynamic_section + filedata->dynamic_nent;
  2356. entry++)
  2357. {
  2358. if (entry->d_tag == DT_FLAGS_1)
  2359. {
  2360. if ((entry->d_un.d_val & DF_1_PIE) != 0)
  2361. return true;
  2362. break;
  2363. }
  2364. }
  2365. return false;
  2366. }
  2367. static char *
  2368. get_file_type (Filedata *filedata)
  2369. {
  2370. unsigned e_type = filedata->file_header.e_type;
  2371. static char buff[64];
  2372. switch (e_type)
  2373. {
  2374. case ET_NONE: return _("NONE (None)");
  2375. case ET_REL: return _("REL (Relocatable file)");
  2376. case ET_EXEC: return _("EXEC (Executable file)");
  2377. case ET_DYN:
  2378. if (is_pie (filedata))
  2379. return _("DYN (Position-Independent Executable file)");
  2380. else
  2381. return _("DYN (Shared object file)");
  2382. case ET_CORE: return _("CORE (Core file)");
  2383. default:
  2384. if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
  2385. snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
  2386. else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
  2387. snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
  2388. else
  2389. snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
  2390. return buff;
  2391. }
  2392. }
  2393. static char *
  2394. get_machine_name (unsigned e_machine)
  2395. {
  2396. static char buff[64]; /* XXX */
  2397. switch (e_machine)
  2398. {
  2399. /* Please keep this switch table sorted by increasing EM_ value. */
  2400. /* 0 */
  2401. case EM_NONE: return _("None");
  2402. case EM_M32: return "WE32100";
  2403. case EM_SPARC: return "Sparc";
  2404. case EM_386: return "Intel 80386";
  2405. case EM_68K: return "MC68000";
  2406. case EM_88K: return "MC88000";
  2407. case EM_IAMCU: return "Intel MCU";
  2408. case EM_860: return "Intel 80860";
  2409. case EM_MIPS: return "MIPS R3000";
  2410. case EM_S370: return "IBM System/370";
  2411. /* 10 */
  2412. case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
  2413. case EM_OLD_SPARCV9: return "Sparc v9 (old)";
  2414. case EM_PARISC: return "HPPA";
  2415. case EM_VPP550: return "Fujitsu VPP500";
  2416. case EM_SPARC32PLUS: return "Sparc v8+" ;
  2417. case EM_960: return "Intel 80960";
  2418. case EM_PPC: return "PowerPC";
  2419. /* 20 */
  2420. case EM_PPC64: return "PowerPC64";
  2421. case EM_S390_OLD:
  2422. case EM_S390: return "IBM S/390";
  2423. case EM_SPU: return "SPU";
  2424. /* 30 */
  2425. case EM_V800: return "Renesas V850 (using RH850 ABI)";
  2426. case EM_FR20: return "Fujitsu FR20";
  2427. case EM_RH32: return "TRW RH32";
  2428. case EM_MCORE: return "MCORE";
  2429. /* 40 */
  2430. case EM_ARM: return "ARM";
  2431. case EM_OLD_ALPHA: return "Digital Alpha (old)";
  2432. case EM_SH: return "Renesas / SuperH SH";
  2433. case EM_SPARCV9: return "Sparc v9";
  2434. case EM_TRICORE: return "Siemens Tricore";
  2435. case EM_ARC: return "ARC";
  2436. case EM_H8_300: return "Renesas H8/300";
  2437. case EM_H8_300H: return "Renesas H8/300H";
  2438. case EM_H8S: return "Renesas H8S";
  2439. case EM_H8_500: return "Renesas H8/500";
  2440. /* 50 */
  2441. case EM_IA_64: return "Intel IA-64";
  2442. case EM_MIPS_X: return "Stanford MIPS-X";
  2443. case EM_COLDFIRE: return "Motorola Coldfire";
  2444. case EM_68HC12: return "Motorola MC68HC12 Microcontroller";
  2445. case EM_MMA: return "Fujitsu Multimedia Accelerator";
  2446. case EM_PCP: return "Siemens PCP";
  2447. case EM_NCPU: return "Sony nCPU embedded RISC processor";
  2448. case EM_NDR1: return "Denso NDR1 microprocesspr";
  2449. case EM_STARCORE: return "Motorola Star*Core processor";
  2450. case EM_ME16: return "Toyota ME16 processor";
  2451. /* 60 */
  2452. case EM_ST100: return "STMicroelectronics ST100 processor";
  2453. case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
  2454. case EM_X86_64: return "Advanced Micro Devices X86-64";
  2455. case EM_PDSP: return "Sony DSP processor";
  2456. case EM_PDP10: return "Digital Equipment Corp. PDP-10";
  2457. case EM_PDP11: return "Digital Equipment Corp. PDP-11";
  2458. case EM_FX66: return "Siemens FX66 microcontroller";
  2459. case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
  2460. case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
  2461. case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
  2462. /* 70 */
  2463. case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
  2464. case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
  2465. case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
  2466. case EM_SVX: return "Silicon Graphics SVx";
  2467. case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
  2468. case EM_VAX: return "Digital VAX";
  2469. case EM_CRIS: return "Axis Communications 32-bit embedded processor";
  2470. case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
  2471. case EM_FIREPATH: return "Element 14 64-bit DSP processor";
  2472. case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
  2473. /* 80 */
  2474. case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
  2475. case EM_HUANY: return "Harvard Universitys's machine-independent object format";
  2476. case EM_PRISM: return "Vitesse Prism";
  2477. case EM_AVR_OLD:
  2478. case EM_AVR: return "Atmel AVR 8-bit microcontroller";
  2479. case EM_CYGNUS_FR30:
  2480. case EM_FR30: return "Fujitsu FR30";
  2481. case EM_CYGNUS_D10V:
  2482. case EM_D10V: return "d10v";
  2483. case EM_CYGNUS_D30V:
  2484. case EM_D30V: return "d30v";
  2485. case EM_CYGNUS_V850:
  2486. case EM_V850: return "Renesas V850";
  2487. case EM_CYGNUS_M32R:
  2488. case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
  2489. case EM_CYGNUS_MN10300:
  2490. case EM_MN10300: return "mn10300";
  2491. /* 90 */
  2492. case EM_CYGNUS_MN10200:
  2493. case EM_MN10200: return "mn10200";
  2494. case EM_PJ: return "picoJava";
  2495. case EM_OR1K: return "OpenRISC 1000";
  2496. case EM_ARC_COMPACT: return "ARCompact";
  2497. case EM_XTENSA_OLD:
  2498. case EM_XTENSA: return "Tensilica Xtensa Processor";
  2499. case EM_VIDEOCORE: return "Alphamosaic VideoCore processor";
  2500. case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor";
  2501. case EM_NS32K: return "National Semiconductor 32000 series";
  2502. case EM_TPC: return "Tenor Network TPC processor";
  2503. case EM_SNP1K: return "Trebia SNP 1000 processor";
  2504. /* 100 */
  2505. case EM_ST200: return "STMicroelectronics ST200 microcontroller";
  2506. case EM_IP2K_OLD:
  2507. case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
  2508. case EM_MAX: return "MAX Processor";
  2509. case EM_CR: return "National Semiconductor CompactRISC";
  2510. case EM_F2MC16: return "Fujitsu F2MC16";
  2511. case EM_MSP430: return "Texas Instruments msp430 microcontroller";
  2512. case EM_BLACKFIN: return "Analog Devices Blackfin";
  2513. case EM_SE_C33: return "S1C33 Family of Seiko Epson processors";
  2514. case EM_SEP: return "Sharp embedded microprocessor";
  2515. case EM_ARCA: return "Arca RISC microprocessor";
  2516. /* 110 */
  2517. case EM_UNICORE: return "Unicore";
  2518. case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU";
  2519. case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor";
  2520. case EM_ALTERA_NIOS2: return "Altera Nios II";
  2521. case EM_CRX: return "National Semiconductor CRX microprocessor";
  2522. case EM_XGATE: return "Motorola XGATE embedded processor";
  2523. case EM_C166:
  2524. case EM_XC16X: return "Infineon Technologies xc16x";
  2525. case EM_M16C: return "Renesas M16C series microprocessors";
  2526. case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller";
  2527. case EM_CE: return "Freescale Communication Engine RISC core";
  2528. /* 120 */
  2529. case EM_M32C: return "Renesas M32c";
  2530. /* 130 */
  2531. case EM_TSK3000: return "Altium TSK3000 core";
  2532. case EM_RS08: return "Freescale RS08 embedded processor";
  2533. case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor";
  2534. case EM_SCORE: return "SUNPLUS S+Core";
  2535. case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor";
  2536. case EM_VIDEOCORE3: return "Broadcom VideoCore III processor";
  2537. case EM_LATTICEMICO32: return "Lattice Mico32";
  2538. case EM_SE_C17: return "Seiko Epson C17 family";
  2539. /* 140 */
  2540. case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family";
  2541. case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family";
  2542. case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family";
  2543. case EM_TI_PRU: return "TI PRU I/O processor";
  2544. /* 160 */
  2545. case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor";
  2546. case EM_CYPRESS_M8C: return "Cypress M8C microprocessor";
  2547. case EM_R32C: return "Renesas R32C series microprocessors";
  2548. case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family";
  2549. case EM_QDSP6: return "QUALCOMM DSP6 Processor";
  2550. case EM_8051: return "Intel 8051 and variants";
  2551. case EM_STXP7X: return "STMicroelectronics STxP7x family";
  2552. case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family";
  2553. case EM_ECOG1X: return "Cyan Technology eCOG1X family";
  2554. case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
  2555. /* 170 */
  2556. case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor";
  2557. case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor";
  2558. case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture";
  2559. case EM_RX: return "Renesas RX";
  2560. case EM_METAG: return "Imagination Technologies Meta processor architecture";
  2561. case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture";
  2562. case EM_ECOG16: return "Cyan Technology eCOG16 family";
  2563. case EM_CR16:
  2564. case EM_MICROBLAZE:
  2565. case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze";
  2566. case EM_ETPU: return "Freescale Extended Time Processing Unit";
  2567. case EM_SLE9X: return "Infineon Technologies SLE9X core";
  2568. /* 180 */
  2569. case EM_L1OM: return "Intel L1OM";
  2570. case EM_K1OM: return "Intel K1OM";
  2571. case EM_INTEL182: return "Intel (reserved)";
  2572. case EM_AARCH64: return "AArch64";
  2573. case EM_ARM184: return "ARM (reserved)";
  2574. case EM_AVR32: return "Atmel Corporation 32-bit microprocessor";
  2575. case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller";
  2576. case EM_TILE64: return "Tilera TILE64 multicore architecture family";
  2577. case EM_TILEPRO: return "Tilera TILEPro multicore architecture family";
  2578. /* 190 */
  2579. case EM_CUDA: return "NVIDIA CUDA architecture";
  2580. case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family";
  2581. case EM_CLOUDSHIELD: return "CloudShield architecture family";
  2582. case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family";
  2583. case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family";
  2584. case EM_ARC_COMPACT2: return "ARCv2";
  2585. case EM_OPEN8: return "Open8 8-bit RISC soft processor core";
  2586. case EM_RL78: return "Renesas RL78";
  2587. case EM_VIDEOCORE5: return "Broadcom VideoCore V processor";
  2588. case EM_78K0R: return "Renesas 78K0R";
  2589. /* 200 */
  2590. case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)";
  2591. case EM_BA1: return "Beyond BA1 CPU architecture";
  2592. case EM_BA2: return "Beyond BA2 CPU architecture";
  2593. case EM_XCORE: return "XMOS xCORE processor family";
  2594. case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family";
  2595. case EM_INTELGT: return "Intel Graphics Technology";
  2596. /* 210 */
  2597. case EM_KM32: return "KM211 KM32 32-bit processor";
  2598. case EM_KMX32: return "KM211 KMX32 32-bit processor";
  2599. case EM_KMX16: return "KM211 KMX16 16-bit processor";
  2600. case EM_KMX8: return "KM211 KMX8 8-bit processor";
  2601. case EM_KVARC: return "KM211 KVARC processor";
  2602. case EM_CDP: return "Paneve CDP architecture family";
  2603. case EM_COGE: return "Cognitive Smart Memory Processor";
  2604. case EM_COOL: return "Bluechip Systems CoolEngine";
  2605. case EM_NORC: return "Nanoradio Optimized RISC";
  2606. case EM_CSR_KALIMBA: return "CSR Kalimba architecture family";
  2607. /* 220 */
  2608. case EM_Z80: return "Zilog Z80";
  2609. case EM_VISIUM: return "CDS VISIUMcore processor";
  2610. case EM_FT32: return "FTDI Chip FT32";
  2611. case EM_MOXIE: return "Moxie";
  2612. case EM_AMDGPU: return "AMD GPU";
  2613. /* 230 (all reserved) */
  2614. /* 240 */
  2615. case EM_RISCV: return "RISC-V";
  2616. case EM_LANAI: return "Lanai 32-bit processor";
  2617. case EM_CEVA: return "CEVA Processor Architecture Family";
  2618. case EM_CEVA_X2: return "CEVA X2 Processor Family";
  2619. case EM_BPF: return "Linux BPF";
  2620. case EM_GRAPHCORE_IPU: return "Graphcore Intelligent Processing Unit";
  2621. case EM_IMG1: return "Imagination Technologies";
  2622. /* 250 */
  2623. case EM_NFP: return "Netronome Flow Processor";
  2624. case EM_VE: return "NEC Vector Engine";
  2625. case EM_CSKY: return "C-SKY";
  2626. case EM_ARC_COMPACT3_64: return "Synopsys ARCv2.3 64-bit";
  2627. case EM_MCS6502: return "MOS Technology MCS 6502 processor";
  2628. case EM_ARC_COMPACT3: return "Synopsys ARCv2.3 32-bit";
  2629. case EM_KVX: return "Kalray VLIW core of the MPPA processor family";
  2630. case EM_65816: return "WDC 65816/65C816";
  2631. case EM_LOONGARCH: return "LoongArch";
  2632. case EM_KF32: return "ChipON KungFu32";
  2633. /* Large numbers... */
  2634. case EM_MT: return "Morpho Techologies MT processor";
  2635. case EM_ALPHA: return "Alpha";
  2636. case EM_WEBASSEMBLY: return "Web Assembly";
  2637. case EM_DLX: return "OpenDLX";
  2638. case EM_XSTORMY16: return "Sanyo XStormy16 CPU core";
  2639. case EM_IQ2000: return "Vitesse IQ2000";
  2640. case EM_M32C_OLD:
  2641. case EM_NIOS32: return "Altera Nios";
  2642. case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine";
  2643. case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY";
  2644. case EM_CYGNUS_FRV: return "Fujitsu FR-V";
  2645. case EM_S12Z: return "Freescale S12Z";
  2646. default:
  2647. snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
  2648. return buff;
  2649. }
  2650. }
  2651. static void
  2652. decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[])
  2653. {
  2654. /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
  2655. other compilers don't specify an architecture type in the e_flags, and
  2656. instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
  2657. architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
  2658. architectures.
  2659. Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
  2660. but also sets a specific architecture type in the e_flags field.
  2661. However, when decoding the flags we don't worry if we see an
  2662. unexpected pairing, for example EM_ARC_COMPACT machine type, with
  2663. ARCEM architecture type. */
  2664. switch (e_flags & EF_ARC_MACH_MSK)
  2665. {
  2666. /* We only expect these to occur for EM_ARC_COMPACT2. */
  2667. case EF_ARC_CPU_ARCV2EM:
  2668. strcat (buf, ", ARC EM");
  2669. break;
  2670. case EF_ARC_CPU_ARCV2HS:
  2671. strcat (buf, ", ARC HS");
  2672. break;
  2673. /* We only expect these to occur for EM_ARC_COMPACT. */
  2674. case E_ARC_MACH_ARC600:
  2675. strcat (buf, ", ARC600");
  2676. break;
  2677. case E_ARC_MACH_ARC601:
  2678. strcat (buf, ", ARC601");
  2679. break;
  2680. case E_ARC_MACH_ARC700:
  2681. strcat (buf, ", ARC700");
  2682. break;
  2683. /* The only times we should end up here are (a) A corrupt ELF, (b) A
  2684. new ELF with new architecture being read by an old version of
  2685. readelf, or (c) An ELF built with non-GNU compiler that does not
  2686. set the architecture in the e_flags. */
  2687. default:
  2688. if (e_machine == EM_ARC_COMPACT)
  2689. strcat (buf, ", Unknown ARCompact");
  2690. else
  2691. strcat (buf, ", Unknown ARC");
  2692. break;
  2693. }
  2694. switch (e_flags & EF_ARC_OSABI_MSK)
  2695. {
  2696. case E_ARC_OSABI_ORIG:
  2697. strcat (buf, ", (ABI:legacy)");
  2698. break;
  2699. case E_ARC_OSABI_V2:
  2700. strcat (buf, ", (ABI:v2)");
  2701. break;
  2702. /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
  2703. case E_ARC_OSABI_V3:
  2704. strcat (buf, ", v3 no-legacy-syscalls ABI");
  2705. break;
  2706. case E_ARC_OSABI_V4:
  2707. strcat (buf, ", v4 ABI");
  2708. break;
  2709. default:
  2710. strcat (buf, ", unrecognised ARC OSABI flag");
  2711. break;
  2712. }
  2713. }
  2714. static void
  2715. decode_ARM_machine_flags (unsigned e_flags, char buf[])
  2716. {
  2717. unsigned eabi;
  2718. bool unknown = false;
  2719. eabi = EF_ARM_EABI_VERSION (e_flags);
  2720. e_flags &= ~ EF_ARM_EABIMASK;
  2721. /* Handle "generic" ARM flags. */
  2722. if (e_flags & EF_ARM_RELEXEC)
  2723. {
  2724. strcat (buf, ", relocatable executable");
  2725. e_flags &= ~ EF_ARM_RELEXEC;
  2726. }
  2727. if (e_flags & EF_ARM_PIC)
  2728. {
  2729. strcat (buf, ", position independent");
  2730. e_flags &= ~ EF_ARM_PIC;
  2731. }
  2732. /* Now handle EABI specific flags. */
  2733. switch (eabi)
  2734. {
  2735. default:
  2736. strcat (buf, ", <unrecognized EABI>");
  2737. if (e_flags)
  2738. unknown = true;
  2739. break;
  2740. case EF_ARM_EABI_VER1:
  2741. strcat (buf, ", Version1 EABI");
  2742. while (e_flags)
  2743. {
  2744. unsigned flag;
  2745. /* Process flags one bit at a time. */
  2746. flag = e_flags & - e_flags;
  2747. e_flags &= ~ flag;
  2748. switch (flag)
  2749. {
  2750. case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
  2751. strcat (buf, ", sorted symbol tables");
  2752. break;
  2753. default:
  2754. unknown = true;
  2755. break;
  2756. }
  2757. }
  2758. break;
  2759. case EF_ARM_EABI_VER2:
  2760. strcat (buf, ", Version2 EABI");
  2761. while (e_flags)
  2762. {
  2763. unsigned flag;
  2764. /* Process flags one bit at a time. */
  2765. flag = e_flags & - e_flags;
  2766. e_flags &= ~ flag;
  2767. switch (flag)
  2768. {
  2769. case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
  2770. strcat (buf, ", sorted symbol tables");
  2771. break;
  2772. case EF_ARM_DYNSYMSUSESEGIDX:
  2773. strcat (buf, ", dynamic symbols use segment index");
  2774. break;
  2775. case EF_ARM_MAPSYMSFIRST:
  2776. strcat (buf, ", mapping symbols precede others");
  2777. break;
  2778. default:
  2779. unknown = true;
  2780. break;
  2781. }
  2782. }
  2783. break;
  2784. case EF_ARM_EABI_VER3:
  2785. strcat (buf, ", Version3 EABI");
  2786. break;
  2787. case EF_ARM_EABI_VER4:
  2788. strcat (buf, ", Version4 EABI");
  2789. while (e_flags)
  2790. {
  2791. unsigned flag;
  2792. /* Process flags one bit at a time. */
  2793. flag = e_flags & - e_flags;
  2794. e_flags &= ~ flag;
  2795. switch (flag)
  2796. {
  2797. case EF_ARM_BE8:
  2798. strcat (buf, ", BE8");
  2799. break;
  2800. case EF_ARM_LE8:
  2801. strcat (buf, ", LE8");
  2802. break;
  2803. default:
  2804. unknown = true;
  2805. break;
  2806. }
  2807. }
  2808. break;
  2809. case EF_ARM_EABI_VER5:
  2810. strcat (buf, ", Version5 EABI");
  2811. while (e_flags)
  2812. {
  2813. unsigned flag;
  2814. /* Process flags one bit at a time. */
  2815. flag = e_flags & - e_flags;
  2816. e_flags &= ~ flag;
  2817. switch (flag)
  2818. {
  2819. case EF_ARM_BE8:
  2820. strcat (buf, ", BE8");
  2821. break;
  2822. case EF_ARM_LE8:
  2823. strcat (buf, ", LE8");
  2824. break;
  2825. case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */
  2826. strcat (buf, ", soft-float ABI");
  2827. break;
  2828. case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */
  2829. strcat (buf, ", hard-float ABI");
  2830. break;
  2831. default:
  2832. unknown = true;
  2833. break;
  2834. }
  2835. }
  2836. break;
  2837. case EF_ARM_EABI_UNKNOWN:
  2838. strcat (buf, ", GNU EABI");
  2839. while (e_flags)
  2840. {
  2841. unsigned flag;
  2842. /* Process flags one bit at a time. */
  2843. flag = e_flags & - e_flags;
  2844. e_flags &= ~ flag;
  2845. switch (flag)
  2846. {
  2847. case EF_ARM_INTERWORK:
  2848. strcat (buf, ", interworking enabled");
  2849. break;
  2850. case EF_ARM_APCS_26:
  2851. strcat (buf, ", uses APCS/26");
  2852. break;
  2853. case EF_ARM_APCS_FLOAT:
  2854. strcat (buf, ", uses APCS/float");
  2855. break;
  2856. case EF_ARM_PIC:
  2857. strcat (buf, ", position independent");
  2858. break;
  2859. case EF_ARM_ALIGN8:
  2860. strcat (buf, ", 8 bit structure alignment");
  2861. break;
  2862. case EF_ARM_NEW_ABI:
  2863. strcat (buf, ", uses new ABI");
  2864. break;
  2865. case EF_ARM_OLD_ABI:
  2866. strcat (buf, ", uses old ABI");
  2867. break;
  2868. case EF_ARM_SOFT_FLOAT:
  2869. strcat (buf, ", software FP");
  2870. break;
  2871. case EF_ARM_VFP_FLOAT:
  2872. strcat (buf, ", VFP");
  2873. break;
  2874. case EF_ARM_MAVERICK_FLOAT:
  2875. strcat (buf, ", Maverick FP");
  2876. break;
  2877. default:
  2878. unknown = true;
  2879. break;
  2880. }
  2881. }
  2882. }
  2883. if (unknown)
  2884. strcat (buf,_(", <unknown>"));
  2885. }
  2886. static void
  2887. decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size)
  2888. {
  2889. --size; /* Leave space for null terminator. */
  2890. switch (e_flags & EF_AVR_MACH)
  2891. {
  2892. case E_AVR_MACH_AVR1:
  2893. strncat (buf, ", avr:1", size);
  2894. break;
  2895. case E_AVR_MACH_AVR2:
  2896. strncat (buf, ", avr:2", size);
  2897. break;
  2898. case E_AVR_MACH_AVR25:
  2899. strncat (buf, ", avr:25", size);
  2900. break;
  2901. case E_AVR_MACH_AVR3:
  2902. strncat (buf, ", avr:3", size);
  2903. break;
  2904. case E_AVR_MACH_AVR31:
  2905. strncat (buf, ", avr:31", size);
  2906. break;
  2907. case E_AVR_MACH_AVR35:
  2908. strncat (buf, ", avr:35", size);
  2909. break;
  2910. case E_AVR_MACH_AVR4:
  2911. strncat (buf, ", avr:4", size);
  2912. break;
  2913. case E_AVR_MACH_AVR5:
  2914. strncat (buf, ", avr:5", size);
  2915. break;
  2916. case E_AVR_MACH_AVR51:
  2917. strncat (buf, ", avr:51", size);
  2918. break;
  2919. case E_AVR_MACH_AVR6:
  2920. strncat (buf, ", avr:6", size);
  2921. break;
  2922. case E_AVR_MACH_AVRTINY:
  2923. strncat (buf, ", avr:100", size);
  2924. break;
  2925. case E_AVR_MACH_XMEGA1:
  2926. strncat (buf, ", avr:101", size);
  2927. break;
  2928. case E_AVR_MACH_XMEGA2:
  2929. strncat (buf, ", avr:102", size);
  2930. break;
  2931. case E_AVR_MACH_XMEGA3:
  2932. strncat (buf, ", avr:103", size);
  2933. break;
  2934. case E_AVR_MACH_XMEGA4:
  2935. strncat (buf, ", avr:104", size);
  2936. break;
  2937. case E_AVR_MACH_XMEGA5:
  2938. strncat (buf, ", avr:105", size);
  2939. break;
  2940. case E_AVR_MACH_XMEGA6:
  2941. strncat (buf, ", avr:106", size);
  2942. break;
  2943. case E_AVR_MACH_XMEGA7:
  2944. strncat (buf, ", avr:107", size);
  2945. break;
  2946. default:
  2947. strncat (buf, ", avr:<unknown>", size);
  2948. break;
  2949. }
  2950. size -= strlen (buf);
  2951. if (e_flags & EF_AVR_LINKRELAX_PREPARED)
  2952. strncat (buf, ", link-relax", size);
  2953. }
  2954. static void
  2955. decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size)
  2956. {
  2957. unsigned abi;
  2958. unsigned arch;
  2959. unsigned config;
  2960. unsigned version;
  2961. bool has_fpu = false;
  2962. unsigned int r = 0;
  2963. static const char *ABI_STRINGS[] =
  2964. {
  2965. "ABI v0", /* use r5 as return register; only used in N1213HC */
  2966. "ABI v1", /* use r0 as return register */
  2967. "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
  2968. "ABI v2fp", /* for FPU */
  2969. "AABI",
  2970. "ABI2 FP+"
  2971. };
  2972. static const char *VER_STRINGS[] =
  2973. {
  2974. "Andes ELF V1.3 or older",
  2975. "Andes ELF V1.3.1",
  2976. "Andes ELF V1.4"
  2977. };
  2978. static const char *ARCH_STRINGS[] =
  2979. {
  2980. "",
  2981. "Andes Star v1.0",
  2982. "Andes Star v2.0",
  2983. "Andes Star v3.0",
  2984. "Andes Star v3.0m"
  2985. };
  2986. abi = EF_NDS_ABI & e_flags;
  2987. arch = EF_NDS_ARCH & e_flags;
  2988. config = EF_NDS_INST & e_flags;
  2989. version = EF_NDS32_ELF_VERSION & e_flags;
  2990. memset (buf, 0, size);
  2991. switch (abi)
  2992. {
  2993. case E_NDS_ABI_V0:
  2994. case E_NDS_ABI_V1:
  2995. case E_NDS_ABI_V2:
  2996. case E_NDS_ABI_V2FP:
  2997. case E_NDS_ABI_AABI:
  2998. case E_NDS_ABI_V2FP_PLUS:
  2999. /* In case there are holes in the array. */
  3000. r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]);
  3001. break;
  3002. default:
  3003. r += snprintf (buf + r, size - r, ", <unrecognized ABI>");
  3004. break;
  3005. }
  3006. switch (version)
  3007. {
  3008. case E_NDS32_ELF_VER_1_2:
  3009. case E_NDS32_ELF_VER_1_3:
  3010. case E_NDS32_ELF_VER_1_4:
  3011. r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]);
  3012. break;
  3013. default:
  3014. r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>");
  3015. break;
  3016. }
  3017. if (E_NDS_ABI_V0 == abi)
  3018. {
  3019. /* OLD ABI; only used in N1213HC, has performance extension 1. */
  3020. r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1");
  3021. if (arch == E_NDS_ARCH_STAR_V1_0)
  3022. r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */
  3023. return;
  3024. }
  3025. switch (arch)
  3026. {
  3027. case E_NDS_ARCH_STAR_V1_0:
  3028. case E_NDS_ARCH_STAR_V2_0:
  3029. case E_NDS_ARCH_STAR_V3_0:
  3030. case E_NDS_ARCH_STAR_V3_M:
  3031. r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]);
  3032. break;
  3033. default:
  3034. r += snprintf (buf + r, size - r, ", <unrecognized architecture>");
  3035. /* ARCH version determines how the e_flags are interpreted.
  3036. If it is unknown, we cannot proceed. */
  3037. return;
  3038. }
  3039. /* Newer ABI; Now handle architecture specific flags. */
  3040. if (arch == E_NDS_ARCH_STAR_V1_0)
  3041. {
  3042. if (config & E_NDS32_HAS_MFUSR_PC_INST)
  3043. r += snprintf (buf + r, size -r, ", MFUSR_PC");
  3044. if (!(config & E_NDS32_HAS_NO_MAC_INST))
  3045. r += snprintf (buf + r, size -r, ", MAC");
  3046. if (config & E_NDS32_HAS_DIV_INST)
  3047. r += snprintf (buf + r, size -r, ", DIV");
  3048. if (config & E_NDS32_HAS_16BIT_INST)
  3049. r += snprintf (buf + r, size -r, ", 16b");
  3050. }
  3051. else
  3052. {
  3053. if (config & E_NDS32_HAS_MFUSR_PC_INST)
  3054. {
  3055. if (version <= E_NDS32_ELF_VER_1_3)
  3056. r += snprintf (buf + r, size -r, ", [B8]");
  3057. else
  3058. r += snprintf (buf + r, size -r, ", EX9");
  3059. }
  3060. if (config & E_NDS32_HAS_MAC_DX_INST)
  3061. r += snprintf (buf + r, size -r, ", MAC_DX");
  3062. if (config & E_NDS32_HAS_DIV_DX_INST)
  3063. r += snprintf (buf + r, size -r, ", DIV_DX");
  3064. if (config & E_NDS32_HAS_16BIT_INST)
  3065. {
  3066. if (version <= E_NDS32_ELF_VER_1_3)
  3067. r += snprintf (buf + r, size -r, ", 16b");
  3068. else
  3069. r += snprintf (buf + r, size -r, ", IFC");
  3070. }
  3071. }
  3072. if (config & E_NDS32_HAS_EXT_INST)
  3073. r += snprintf (buf + r, size -r, ", PERF1");
  3074. if (config & E_NDS32_HAS_EXT2_INST)
  3075. r += snprintf (buf + r, size -r, ", PERF2");
  3076. if (config & E_NDS32_HAS_FPU_INST)
  3077. {
  3078. has_fpu = true;
  3079. r += snprintf (buf + r, size -r, ", FPU_SP");
  3080. }
  3081. if (config & E_NDS32_HAS_FPU_DP_INST)
  3082. {
  3083. has_fpu = true;
  3084. r += snprintf (buf + r, size -r, ", FPU_DP");
  3085. }
  3086. if (config & E_NDS32_HAS_FPU_MAC_INST)
  3087. {
  3088. has_fpu = true;
  3089. r += snprintf (buf + r, size -r, ", FPU_MAC");
  3090. }
  3091. if (has_fpu)
  3092. {
  3093. switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT)
  3094. {
  3095. case E_NDS32_FPU_REG_8SP_4DP:
  3096. r += snprintf (buf + r, size -r, ", FPU_REG:8/4");
  3097. break;
  3098. case E_NDS32_FPU_REG_16SP_8DP:
  3099. r += snprintf (buf + r, size -r, ", FPU_REG:16/8");
  3100. break;
  3101. case E_NDS32_FPU_REG_32SP_16DP:
  3102. r += snprintf (buf + r, size -r, ", FPU_REG:32/16");
  3103. break;
  3104. case E_NDS32_FPU_REG_32SP_32DP:
  3105. r += snprintf (buf + r, size -r, ", FPU_REG:32/32");
  3106. break;
  3107. }
  3108. }
  3109. if (config & E_NDS32_HAS_AUDIO_INST)
  3110. r += snprintf (buf + r, size -r, ", AUDIO");
  3111. if (config & E_NDS32_HAS_STRING_INST)
  3112. r += snprintf (buf + r, size -r, ", STR");
  3113. if (config & E_NDS32_HAS_REDUCED_REGS)
  3114. r += snprintf (buf + r, size -r, ", 16REG");
  3115. if (config & E_NDS32_HAS_VIDEO_INST)
  3116. {
  3117. if (version <= E_NDS32_ELF_VER_1_3)
  3118. r += snprintf (buf + r, size -r, ", VIDEO");
  3119. else
  3120. r += snprintf (buf + r, size -r, ", SATURATION");
  3121. }
  3122. if (config & E_NDS32_HAS_ENCRIPT_INST)
  3123. r += snprintf (buf + r, size -r, ", ENCRP");
  3124. if (config & E_NDS32_HAS_L2C_INST)
  3125. r += snprintf (buf + r, size -r, ", L2C");
  3126. }
  3127. static void
  3128. decode_AMDGPU_machine_flags (Filedata *filedata, unsigned int e_flags,
  3129. char *buf)
  3130. {
  3131. unsigned char *e_ident = filedata->file_header.e_ident;
  3132. unsigned char osabi = e_ident[EI_OSABI];
  3133. unsigned char abiversion = e_ident[EI_ABIVERSION];
  3134. unsigned int mach;
  3135. /* HSA OS ABI v2 used a different encoding, but we don't need to support it,
  3136. it has been deprecated for a while.
  3137. The PAL, MESA3D and NONE OS ABIs are not properly versioned, at the time
  3138. of writing, they use the same flags as HSA v3, so the code below uses that
  3139. assumption. */
  3140. if (osabi == ELFOSABI_AMDGPU_HSA && abiversion < ELFABIVERSION_AMDGPU_HSA_V3)
  3141. return;
  3142. mach = e_flags & EF_AMDGPU_MACH;
  3143. switch (mach)
  3144. {
  3145. #define AMDGPU_CASE(code, string) \
  3146. case code: strcat (buf, ", " string); break;
  3147. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX600, "gfx600")
  3148. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX601, "gfx601")
  3149. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX700, "gfx700")
  3150. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX701, "gfx701")
  3151. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX702, "gfx702")
  3152. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX703, "gfx703")
  3153. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX704, "gfx704")
  3154. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX801, "gfx801")
  3155. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX802, "gfx802")
  3156. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX803, "gfx803")
  3157. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX810, "gfx810")
  3158. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX900, "gfx900")
  3159. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX902, "gfx902")
  3160. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX904, "gfx904")
  3161. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX906, "gfx906")
  3162. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX908, "gfx908")
  3163. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX909, "gfx909")
  3164. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90C, "gfx90c")
  3165. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1010, "gfx1010")
  3166. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1011, "gfx1011")
  3167. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1012, "gfx1012")
  3168. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1030, "gfx1030")
  3169. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1031, "gfx1031")
  3170. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1032, "gfx1032")
  3171. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1033, "gfx1033")
  3172. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX602, "gfx602")
  3173. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX705, "gfx705")
  3174. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX805, "gfx805")
  3175. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1035, "gfx1035")
  3176. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1034, "gfx1034")
  3177. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX90A, "gfx90a")
  3178. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX940, "gfx940")
  3179. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1013, "gfx1013")
  3180. AMDGPU_CASE (EF_AMDGPU_MACH_AMDGCN_GFX1036, "gfx1036")
  3181. default:
  3182. sprintf (buf, _(", <unknown AMDGPU GPU type: %#x>"), mach);
  3183. break;
  3184. #undef AMDGPU_CASE
  3185. }
  3186. buf += strlen (buf);
  3187. e_flags &= ~EF_AMDGPU_MACH;
  3188. if ((osabi == ELFOSABI_AMDGPU_HSA
  3189. && abiversion == ELFABIVERSION_AMDGPU_HSA_V3)
  3190. || osabi != ELFOSABI_AMDGPU_HSA)
  3191. {
  3192. /* For HSA v3 and other OS ABIs. */
  3193. if (e_flags & EF_AMDGPU_FEATURE_XNACK_V3)
  3194. {
  3195. strcat (buf, ", xnack on");
  3196. buf += strlen (buf);
  3197. e_flags &= ~EF_AMDGPU_FEATURE_XNACK_V3;
  3198. }
  3199. if (e_flags & EF_AMDGPU_FEATURE_SRAMECC_V3)
  3200. {
  3201. strcat (buf, ", sramecc on");
  3202. buf += strlen (buf);
  3203. e_flags &= ~EF_AMDGPU_FEATURE_SRAMECC_V3;
  3204. }
  3205. }
  3206. else
  3207. {
  3208. /* For HSA v4+. */
  3209. int xnack, sramecc;
  3210. xnack = e_flags & EF_AMDGPU_FEATURE_XNACK_V4;
  3211. switch (xnack)
  3212. {
  3213. case EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4:
  3214. break;
  3215. case EF_AMDGPU_FEATURE_XNACK_ANY_V4:
  3216. strcat (buf, ", xnack any");
  3217. break;
  3218. case EF_AMDGPU_FEATURE_XNACK_OFF_V4:
  3219. strcat (buf, ", xnack off");
  3220. break;
  3221. case EF_AMDGPU_FEATURE_XNACK_ON_V4:
  3222. strcat (buf, ", xnack on");
  3223. break;
  3224. default:
  3225. sprintf (buf, _(", <unknown xnack value: %#x>"), xnack);
  3226. break;
  3227. }
  3228. buf += strlen (buf);
  3229. e_flags &= ~EF_AMDGPU_FEATURE_XNACK_V4;
  3230. sramecc = e_flags & EF_AMDGPU_FEATURE_SRAMECC_V4;
  3231. switch (sramecc)
  3232. {
  3233. case EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4:
  3234. break;
  3235. case EF_AMDGPU_FEATURE_SRAMECC_ANY_V4:
  3236. strcat (buf, ", sramecc any");
  3237. break;
  3238. case EF_AMDGPU_FEATURE_SRAMECC_OFF_V4:
  3239. strcat (buf, ", sramecc off");
  3240. break;
  3241. case EF_AMDGPU_FEATURE_SRAMECC_ON_V4:
  3242. strcat (buf, ", sramecc on");
  3243. break;
  3244. default:
  3245. sprintf (buf, _(", <unknown sramecc value: %#x>"), sramecc);
  3246. break;
  3247. }
  3248. buf += strlen (buf);
  3249. e_flags &= ~EF_AMDGPU_FEATURE_SRAMECC_V4;
  3250. }
  3251. if (e_flags != 0)
  3252. sprintf (buf, _(", unknown flags bits: %#x"), e_flags);
  3253. }
  3254. static char *
  3255. get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine)
  3256. {
  3257. static char buf[1024];
  3258. buf[0] = '\0';
  3259. if (e_flags)
  3260. {
  3261. switch (e_machine)
  3262. {
  3263. default:
  3264. break;
  3265. case EM_ARC_COMPACT2:
  3266. case EM_ARC_COMPACT:
  3267. decode_ARC_machine_flags (e_flags, e_machine, buf);
  3268. break;
  3269. case EM_ARM:
  3270. decode_ARM_machine_flags (e_flags, buf);
  3271. break;
  3272. case EM_AVR:
  3273. decode_AVR_machine_flags (e_flags, buf, sizeof buf);
  3274. break;
  3275. case EM_BLACKFIN:
  3276. if (e_flags & EF_BFIN_PIC)
  3277. strcat (buf, ", PIC");
  3278. if (e_flags & EF_BFIN_FDPIC)
  3279. strcat (buf, ", FDPIC");
  3280. if (e_flags & EF_BFIN_CODE_IN_L1)
  3281. strcat (buf, ", code in L1");
  3282. if (e_flags & EF_BFIN_DATA_IN_L1)
  3283. strcat (buf, ", data in L1");
  3284. break;
  3285. case EM_CYGNUS_FRV:
  3286. switch (e_flags & EF_FRV_CPU_MASK)
  3287. {
  3288. case EF_FRV_CPU_GENERIC:
  3289. break;
  3290. default:
  3291. strcat (buf, ", fr???");
  3292. break;
  3293. case EF_FRV_CPU_FR300:
  3294. strcat (buf, ", fr300");
  3295. break;
  3296. case EF_FRV_CPU_FR400:
  3297. strcat (buf, ", fr400");
  3298. break;
  3299. case EF_FRV_CPU_FR405:
  3300. strcat (buf, ", fr405");
  3301. break;
  3302. case EF_FRV_CPU_FR450:
  3303. strcat (buf, ", fr450");
  3304. break;
  3305. case EF_FRV_CPU_FR500:
  3306. strcat (buf, ", fr500");
  3307. break;
  3308. case EF_FRV_CPU_FR550:
  3309. strcat (buf, ", fr550");
  3310. break;
  3311. case EF_FRV_CPU_SIMPLE:
  3312. strcat (buf, ", simple");
  3313. break;
  3314. case EF_FRV_CPU_TOMCAT:
  3315. strcat (buf, ", tomcat");
  3316. break;
  3317. }
  3318. break;
  3319. case EM_68K:
  3320. if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
  3321. strcat (buf, ", m68000");
  3322. else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
  3323. strcat (buf, ", cpu32");
  3324. else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
  3325. strcat (buf, ", fido_a");
  3326. else
  3327. {
  3328. char const * isa = _("unknown");
  3329. char const * mac = _("unknown mac");
  3330. char const * additional = NULL;
  3331. switch (e_flags & EF_M68K_CF_ISA_MASK)
  3332. {
  3333. case EF_M68K_CF_ISA_A_NODIV:
  3334. isa = "A";
  3335. additional = ", nodiv";
  3336. break;
  3337. case EF_M68K_CF_ISA_A:
  3338. isa = "A";
  3339. break;
  3340. case EF_M68K_CF_ISA_A_PLUS:
  3341. isa = "A+";
  3342. break;
  3343. case EF_M68K_CF_ISA_B_NOUSP:
  3344. isa = "B";
  3345. additional = ", nousp";
  3346. break;
  3347. case EF_M68K_CF_ISA_B:
  3348. isa = "B";
  3349. break;
  3350. case EF_M68K_CF_ISA_C:
  3351. isa = "C";
  3352. break;
  3353. case EF_M68K_CF_ISA_C_NODIV:
  3354. isa = "C";
  3355. additional = ", nodiv";
  3356. break;
  3357. }
  3358. strcat (buf, ", cf, isa ");
  3359. strcat (buf, isa);
  3360. if (additional)
  3361. strcat (buf, additional);
  3362. if (e_flags & EF_M68K_CF_FLOAT)
  3363. strcat (buf, ", float");
  3364. switch (e_flags & EF_M68K_CF_MAC_MASK)
  3365. {
  3366. case 0:
  3367. mac = NULL;
  3368. break;
  3369. case EF_M68K_CF_MAC:
  3370. mac = "mac";
  3371. break;
  3372. case EF_M68K_CF_EMAC:
  3373. mac = "emac";
  3374. break;
  3375. case EF_M68K_CF_EMAC_B:
  3376. mac = "emac_b";
  3377. break;
  3378. }
  3379. if (mac)
  3380. {
  3381. strcat (buf, ", ");
  3382. strcat (buf, mac);
  3383. }
  3384. }
  3385. break;
  3386. case EM_AMDGPU:
  3387. decode_AMDGPU_machine_flags (filedata, e_flags, buf);
  3388. break;
  3389. case EM_CYGNUS_MEP:
  3390. switch (e_flags & EF_MEP_CPU_MASK)
  3391. {
  3392. case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break;
  3393. case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break;
  3394. case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break;
  3395. case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break;
  3396. case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break;
  3397. case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break;
  3398. default: strcat (buf, _(", <unknown MeP cpu type>")); break;
  3399. }
  3400. switch (e_flags & EF_MEP_COP_MASK)
  3401. {
  3402. case EF_MEP_COP_NONE: break;
  3403. case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break;
  3404. case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break;
  3405. case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break;
  3406. case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break;
  3407. default: strcat (buf, _("<unknown MeP copro type>")); break;
  3408. }
  3409. if (e_flags & EF_MEP_LIBRARY)
  3410. strcat (buf, ", Built for Library");
  3411. if (e_flags & EF_MEP_INDEX_MASK)
  3412. sprintf (buf + strlen (buf), ", Configuration Index: %#x",
  3413. e_flags & EF_MEP_INDEX_MASK);
  3414. if (e_flags & ~ EF_MEP_ALL_FLAGS)
  3415. sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"),
  3416. e_flags & ~ EF_MEP_ALL_FLAGS);
  3417. break;
  3418. case EM_PPC:
  3419. if (e_flags & EF_PPC_EMB)
  3420. strcat (buf, ", emb");
  3421. if (e_flags & EF_PPC_RELOCATABLE)
  3422. strcat (buf, _(", relocatable"));
  3423. if (e_flags & EF_PPC_RELOCATABLE_LIB)
  3424. strcat (buf, _(", relocatable-lib"));
  3425. break;
  3426. case EM_PPC64:
  3427. if (e_flags & EF_PPC64_ABI)
  3428. {
  3429. char abi[] = ", abiv0";
  3430. abi[6] += e_flags & EF_PPC64_ABI;
  3431. strcat (buf, abi);
  3432. }
  3433. break;
  3434. case EM_V800:
  3435. if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI)
  3436. strcat (buf, ", RH850 ABI");
  3437. if (e_flags & EF_V800_850E3)
  3438. strcat (buf, ", V3 architecture");
  3439. if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0)
  3440. strcat (buf, ", FPU not used");
  3441. if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0)
  3442. strcat (buf, ", regmode: COMMON");
  3443. if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0)
  3444. strcat (buf, ", r4 not used");
  3445. if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0)
  3446. strcat (buf, ", r30 not used");
  3447. if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0)
  3448. strcat (buf, ", r5 not used");
  3449. if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0)
  3450. strcat (buf, ", r2 not used");
  3451. for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags))
  3452. {
  3453. switch (e_flags & - e_flags)
  3454. {
  3455. case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break;
  3456. case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break;
  3457. case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break;
  3458. case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break;
  3459. case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break;
  3460. case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break;
  3461. case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break;
  3462. case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break;
  3463. case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break;
  3464. case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break;
  3465. case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break;
  3466. case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break;
  3467. default: break;
  3468. }
  3469. }
  3470. break;
  3471. case EM_V850:
  3472. case EM_CYGNUS_V850:
  3473. switch (e_flags & EF_V850_ARCH)
  3474. {
  3475. case E_V850E3V5_ARCH:
  3476. strcat (buf, ", v850e3v5");
  3477. break;
  3478. case E_V850E2V3_ARCH:
  3479. strcat (buf, ", v850e2v3");
  3480. break;
  3481. case E_V850E2_ARCH:
  3482. strcat (buf, ", v850e2");
  3483. break;
  3484. case E_V850E1_ARCH:
  3485. strcat (buf, ", v850e1");
  3486. break;
  3487. case E_V850E_ARCH:
  3488. strcat (buf, ", v850e");
  3489. break;
  3490. case E_V850_ARCH:
  3491. strcat (buf, ", v850");
  3492. break;
  3493. default:
  3494. strcat (buf, _(", unknown v850 architecture variant"));
  3495. break;
  3496. }
  3497. break;
  3498. case EM_M32R:
  3499. case EM_CYGNUS_M32R:
  3500. if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
  3501. strcat (buf, ", m32r");
  3502. break;
  3503. case EM_MIPS:
  3504. case EM_MIPS_RS3_LE:
  3505. if (e_flags & EF_MIPS_NOREORDER)
  3506. strcat (buf, ", noreorder");
  3507. if (e_flags & EF_MIPS_PIC)
  3508. strcat (buf, ", pic");
  3509. if (e_flags & EF_MIPS_CPIC)
  3510. strcat (buf, ", cpic");
  3511. if (e_flags & EF_MIPS_UCODE)
  3512. strcat (buf, ", ugen_reserved");
  3513. if (e_flags & EF_MIPS_ABI2)
  3514. strcat (buf, ", abi2");
  3515. if (e_flags & EF_MIPS_OPTIONS_FIRST)
  3516. strcat (buf, ", odk first");
  3517. if (e_flags & EF_MIPS_32BITMODE)
  3518. strcat (buf, ", 32bitmode");
  3519. if (e_flags & EF_MIPS_NAN2008)
  3520. strcat (buf, ", nan2008");
  3521. if (e_flags & EF_MIPS_FP64)
  3522. strcat (buf, ", fp64");
  3523. switch ((e_flags & EF_MIPS_MACH))
  3524. {
  3525. case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
  3526. case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
  3527. case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
  3528. case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
  3529. case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
  3530. case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
  3531. case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
  3532. case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
  3533. case E_MIPS_MACH_5900: strcat (buf, ", 5900"); break;
  3534. case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
  3535. case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
  3536. case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
  3537. case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
  3538. case E_MIPS_MACH_GS464: strcat (buf, ", gs464"); break;
  3539. case E_MIPS_MACH_GS464E: strcat (buf, ", gs464e"); break;
  3540. case E_MIPS_MACH_GS264E: strcat (buf, ", gs264e"); break;
  3541. case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
  3542. case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break;
  3543. case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break;
  3544. case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break;
  3545. case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break;
  3546. case 0:
  3547. /* We simply ignore the field in this case to avoid confusion:
  3548. MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
  3549. extension. */
  3550. break;
  3551. default: strcat (buf, _(", unknown CPU")); break;
  3552. }
  3553. switch ((e_flags & EF_MIPS_ABI))
  3554. {
  3555. case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
  3556. case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
  3557. case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
  3558. case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
  3559. case 0:
  3560. /* We simply ignore the field in this case to avoid confusion:
  3561. MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
  3562. This means it is likely to be an o32 file, but not for
  3563. sure. */
  3564. break;
  3565. default: strcat (buf, _(", unknown ABI")); break;
  3566. }
  3567. if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
  3568. strcat (buf, ", mdmx");
  3569. if (e_flags & EF_MIPS_ARCH_ASE_M16)
  3570. strcat (buf, ", mips16");
  3571. if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
  3572. strcat (buf, ", micromips");
  3573. switch ((e_flags & EF_MIPS_ARCH))
  3574. {
  3575. case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
  3576. case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
  3577. case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
  3578. case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
  3579. case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
  3580. case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
  3581. case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
  3582. case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break;
  3583. case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
  3584. case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
  3585. case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break;
  3586. default: strcat (buf, _(", unknown ISA")); break;
  3587. }
  3588. break;
  3589. case EM_NDS32:
  3590. decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
  3591. break;
  3592. case EM_NFP:
  3593. switch (EF_NFP_MACH (e_flags))
  3594. {
  3595. case E_NFP_MACH_3200:
  3596. strcat (buf, ", NFP-32xx");
  3597. break;
  3598. case E_NFP_MACH_6000:
  3599. strcat (buf, ", NFP-6xxx");
  3600. break;
  3601. }
  3602. break;
  3603. case EM_RISCV:
  3604. if (e_flags & EF_RISCV_RVC)
  3605. strcat (buf, ", RVC");
  3606. if (e_flags & EF_RISCV_RVE)
  3607. strcat (buf, ", RVE");
  3608. switch (e_flags & EF_RISCV_FLOAT_ABI)
  3609. {
  3610. case EF_RISCV_FLOAT_ABI_SOFT:
  3611. strcat (buf, ", soft-float ABI");
  3612. break;
  3613. case EF_RISCV_FLOAT_ABI_SINGLE:
  3614. strcat (buf, ", single-float ABI");
  3615. break;
  3616. case EF_RISCV_FLOAT_ABI_DOUBLE:
  3617. strcat (buf, ", double-float ABI");
  3618. break;
  3619. case EF_RISCV_FLOAT_ABI_QUAD:
  3620. strcat (buf, ", quad-float ABI");
  3621. break;
  3622. }
  3623. break;
  3624. case EM_SH:
  3625. switch ((e_flags & EF_SH_MACH_MASK))
  3626. {
  3627. case EF_SH1: strcat (buf, ", sh1"); break;
  3628. case EF_SH2: strcat (buf, ", sh2"); break;
  3629. case EF_SH3: strcat (buf, ", sh3"); break;
  3630. case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
  3631. case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
  3632. case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
  3633. case EF_SH3E: strcat (buf, ", sh3e"); break;
  3634. case EF_SH4: strcat (buf, ", sh4"); break;
  3635. case EF_SH5: strcat (buf, ", sh5"); break;
  3636. case EF_SH2E: strcat (buf, ", sh2e"); break;
  3637. case EF_SH4A: strcat (buf, ", sh4a"); break;
  3638. case EF_SH2A: strcat (buf, ", sh2a"); break;
  3639. case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
  3640. case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
  3641. case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
  3642. case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
  3643. case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
  3644. case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
  3645. case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
  3646. case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
  3647. case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
  3648. default: strcat (buf, _(", unknown ISA")); break;
  3649. }
  3650. if (e_flags & EF_SH_PIC)
  3651. strcat (buf, ", pic");
  3652. if (e_flags & EF_SH_FDPIC)
  3653. strcat (buf, ", fdpic");
  3654. break;
  3655. case EM_OR1K:
  3656. if (e_flags & EF_OR1K_NODELAY)
  3657. strcat (buf, ", no delay");
  3658. break;
  3659. case EM_SPARCV9:
  3660. if (e_flags & EF_SPARC_32PLUS)
  3661. strcat (buf, ", v8+");
  3662. if (e_flags & EF_SPARC_SUN_US1)
  3663. strcat (buf, ", ultrasparcI");
  3664. if (e_flags & EF_SPARC_SUN_US3)
  3665. strcat (buf, ", ultrasparcIII");
  3666. if (e_flags & EF_SPARC_HAL_R1)
  3667. strcat (buf, ", halr1");
  3668. if (e_flags & EF_SPARC_LEDATA)
  3669. strcat (buf, ", ledata");
  3670. if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
  3671. strcat (buf, ", tso");
  3672. if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
  3673. strcat (buf, ", pso");
  3674. if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
  3675. strcat (buf, ", rmo");
  3676. break;
  3677. case EM_PARISC:
  3678. switch (e_flags & EF_PARISC_ARCH)
  3679. {
  3680. case EFA_PARISC_1_0:
  3681. strcpy (buf, ", PA-RISC 1.0");
  3682. break;
  3683. case EFA_PARISC_1_1:
  3684. strcpy (buf, ", PA-RISC 1.1");
  3685. break;
  3686. case EFA_PARISC_2_0:
  3687. strcpy (buf, ", PA-RISC 2.0");
  3688. break;
  3689. default:
  3690. break;
  3691. }
  3692. if (e_flags & EF_PARISC_TRAPNIL)
  3693. strcat (buf, ", trapnil");
  3694. if (e_flags & EF_PARISC_EXT)
  3695. strcat (buf, ", ext");
  3696. if (e_flags & EF_PARISC_LSB)
  3697. strcat (buf, ", lsb");
  3698. if (e_flags & EF_PARISC_WIDE)
  3699. strcat (buf, ", wide");
  3700. if (e_flags & EF_PARISC_NO_KABP)
  3701. strcat (buf, ", no kabp");
  3702. if (e_flags & EF_PARISC_LAZYSWAP)
  3703. strcat (buf, ", lazyswap");
  3704. break;
  3705. case EM_PJ:
  3706. case EM_PJ_OLD:
  3707. if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
  3708. strcat (buf, ", new calling convention");
  3709. if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
  3710. strcat (buf, ", gnu calling convention");
  3711. break;
  3712. case EM_IA_64:
  3713. if ((e_flags & EF_IA_64_ABI64))
  3714. strcat (buf, ", 64-bit");
  3715. else
  3716. strcat (buf, ", 32-bit");
  3717. if ((e_flags & EF_IA_64_REDUCEDFP))
  3718. strcat (buf, ", reduced fp model");
  3719. if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
  3720. strcat (buf, ", no function descriptors, constant gp");
  3721. else if ((e_flags & EF_IA_64_CONS_GP))
  3722. strcat (buf, ", constant gp");
  3723. if ((e_flags & EF_IA_64_ABSOLUTE))
  3724. strcat (buf, ", absolute");
  3725. if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
  3726. {
  3727. if ((e_flags & EF_IA_64_VMS_LINKAGES))
  3728. strcat (buf, ", vms_linkages");
  3729. switch ((e_flags & EF_IA_64_VMS_COMCOD))
  3730. {
  3731. case EF_IA_64_VMS_COMCOD_SUCCESS:
  3732. break;
  3733. case EF_IA_64_VMS_COMCOD_WARNING:
  3734. strcat (buf, ", warning");
  3735. break;
  3736. case EF_IA_64_VMS_COMCOD_ERROR:
  3737. strcat (buf, ", error");
  3738. break;
  3739. case EF_IA_64_VMS_COMCOD_ABORT:
  3740. strcat (buf, ", abort");
  3741. break;
  3742. default:
  3743. warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
  3744. e_flags & EF_IA_64_VMS_COMCOD);
  3745. strcat (buf, ", <unknown>");
  3746. }
  3747. }
  3748. break;
  3749. case EM_VAX:
  3750. if ((e_flags & EF_VAX_NONPIC))
  3751. strcat (buf, ", non-PIC");
  3752. if ((e_flags & EF_VAX_DFLOAT))
  3753. strcat (buf, ", D-Float");
  3754. if ((e_flags & EF_VAX_GFLOAT))
  3755. strcat (buf, ", G-Float");
  3756. break;
  3757. case EM_VISIUM:
  3758. if (e_flags & EF_VISIUM_ARCH_MCM)
  3759. strcat (buf, ", mcm");
  3760. else if (e_flags & EF_VISIUM_ARCH_MCM24)
  3761. strcat (buf, ", mcm24");
  3762. if (e_flags & EF_VISIUM_ARCH_GR6)
  3763. strcat (buf, ", gr6");
  3764. break;
  3765. case EM_RL78:
  3766. switch (e_flags & E_FLAG_RL78_CPU_MASK)
  3767. {
  3768. case E_FLAG_RL78_ANY_CPU: break;
  3769. case E_FLAG_RL78_G10: strcat (buf, ", G10"); break;
  3770. case E_FLAG_RL78_G13: strcat (buf, ", G13"); break;
  3771. case E_FLAG_RL78_G14: strcat (buf, ", G14"); break;
  3772. }
  3773. if (e_flags & E_FLAG_RL78_64BIT_DOUBLES)
  3774. strcat (buf, ", 64-bit doubles");
  3775. break;
  3776. case EM_RX:
  3777. if (e_flags & E_FLAG_RX_64BIT_DOUBLES)
  3778. strcat (buf, ", 64-bit doubles");
  3779. if (e_flags & E_FLAG_RX_DSP)
  3780. strcat (buf, ", dsp");
  3781. if (e_flags & E_FLAG_RX_PID)
  3782. strcat (buf, ", pid");
  3783. if (e_flags & E_FLAG_RX_ABI)
  3784. strcat (buf, ", RX ABI");
  3785. if (e_flags & E_FLAG_RX_SINSNS_SET)
  3786. strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES
  3787. ? ", uses String instructions" : ", bans String instructions");
  3788. if (e_flags & E_FLAG_RX_V2)
  3789. strcat (buf, ", V2");
  3790. if (e_flags & E_FLAG_RX_V3)
  3791. strcat (buf, ", V3");
  3792. break;
  3793. case EM_S390:
  3794. if (e_flags & EF_S390_HIGH_GPRS)
  3795. strcat (buf, ", highgprs");
  3796. break;
  3797. case EM_TI_C6000:
  3798. if ((e_flags & EF_C6000_REL))
  3799. strcat (buf, ", relocatable module");
  3800. break;
  3801. case EM_MSP430:
  3802. strcat (buf, _(": architecture variant: "));
  3803. switch (e_flags & EF_MSP430_MACH)
  3804. {
  3805. case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break;
  3806. case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break;
  3807. case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break;
  3808. case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break;
  3809. case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break;
  3810. case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break;
  3811. case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break;
  3812. case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break;
  3813. case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break;
  3814. case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break;
  3815. case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break;
  3816. case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break;
  3817. case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break;
  3818. case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break;
  3819. case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break;
  3820. default:
  3821. strcat (buf, _(": unknown")); break;
  3822. }
  3823. if (e_flags & ~ EF_MSP430_MACH)
  3824. strcat (buf, _(": unknown extra flag bits also present"));
  3825. break;
  3826. case EM_Z80:
  3827. switch (e_flags & EF_Z80_MACH_MSK)
  3828. {
  3829. case EF_Z80_MACH_Z80: strcat (buf, ", Z80"); break;
  3830. case EF_Z80_MACH_Z180: strcat (buf, ", Z180"); break;
  3831. case EF_Z80_MACH_R800: strcat (buf, ", R800"); break;
  3832. case EF_Z80_MACH_EZ80_Z80: strcat (buf, ", EZ80"); break;
  3833. case EF_Z80_MACH_EZ80_ADL: strcat (buf, ", EZ80, ADL"); break;
  3834. case EF_Z80_MACH_GBZ80: strcat (buf, ", GBZ80"); break;
  3835. case EF_Z80_MACH_Z80N: strcat (buf, ", Z80N"); break;
  3836. default:
  3837. strcat (buf, _(", unknown")); break;
  3838. }
  3839. break;
  3840. case EM_LOONGARCH:
  3841. if (EF_LOONGARCH_IS_LP64 (e_flags))
  3842. strcat (buf, ", LP64");
  3843. else if (EF_LOONGARCH_IS_ILP32 (e_flags))
  3844. strcat (buf, ", ILP32");
  3845. if (EF_LOONGARCH_IS_SOFT_FLOAT (e_flags))
  3846. strcat (buf, ", SOFT-FLOAT");
  3847. else if (EF_LOONGARCH_IS_SINGLE_FLOAT (e_flags))
  3848. strcat (buf, ", SINGLE-FLOAT");
  3849. else if (EF_LOONGARCH_IS_DOUBLE_FLOAT (e_flags))
  3850. strcat (buf, ", DOUBLE-FLOAT");
  3851. break;
  3852. }
  3853. }
  3854. return buf;
  3855. }
  3856. static const char *
  3857. get_osabi_name (Filedata * filedata, unsigned int osabi)
  3858. {
  3859. static char buff[32];
  3860. switch (osabi)
  3861. {
  3862. case ELFOSABI_NONE: return "UNIX - System V";
  3863. case ELFOSABI_HPUX: return "UNIX - HP-UX";
  3864. case ELFOSABI_NETBSD: return "UNIX - NetBSD";
  3865. case ELFOSABI_GNU: return "UNIX - GNU";
  3866. case ELFOSABI_SOLARIS: return "UNIX - Solaris";
  3867. case ELFOSABI_AIX: return "UNIX - AIX";
  3868. case ELFOSABI_IRIX: return "UNIX - IRIX";
  3869. case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
  3870. case ELFOSABI_TRU64: return "UNIX - TRU64";
  3871. case ELFOSABI_MODESTO: return "Novell - Modesto";
  3872. case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
  3873. case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
  3874. case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
  3875. case ELFOSABI_AROS: return "AROS";
  3876. case ELFOSABI_FENIXOS: return "FenixOS";
  3877. case ELFOSABI_CLOUDABI: return "Nuxi CloudABI";
  3878. case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS";
  3879. default:
  3880. if (osabi >= 64)
  3881. switch (filedata->file_header.e_machine)
  3882. {
  3883. case EM_AMDGPU:
  3884. switch (osabi)
  3885. {
  3886. case ELFOSABI_AMDGPU_HSA: return "AMD HSA";
  3887. case ELFOSABI_AMDGPU_PAL: return "AMD PAL";
  3888. case ELFOSABI_AMDGPU_MESA3D: return "AMD Mesa3D";
  3889. default:
  3890. break;
  3891. }
  3892. break;
  3893. case EM_ARM:
  3894. switch (osabi)
  3895. {
  3896. case ELFOSABI_ARM: return "ARM";
  3897. case ELFOSABI_ARM_FDPIC: return "ARM FDPIC";
  3898. default:
  3899. break;
  3900. }
  3901. break;
  3902. case EM_MSP430:
  3903. case EM_MSP430_OLD:
  3904. case EM_VISIUM:
  3905. switch (osabi)
  3906. {
  3907. case ELFOSABI_STANDALONE: return _("Standalone App");
  3908. default:
  3909. break;
  3910. }
  3911. break;
  3912. case EM_TI_C6000:
  3913. switch (osabi)
  3914. {
  3915. case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000");
  3916. case ELFOSABI_C6000_LINUX: return "Linux C6000";
  3917. default:
  3918. break;
  3919. }
  3920. break;
  3921. default:
  3922. break;
  3923. }
  3924. snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
  3925. return buff;
  3926. }
  3927. }
  3928. static const char *
  3929. get_aarch64_segment_type (unsigned long type)
  3930. {
  3931. switch (type)
  3932. {
  3933. case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT";
  3934. default: return NULL;
  3935. }
  3936. }
  3937. static const char *
  3938. get_arm_segment_type (unsigned long type)
  3939. {
  3940. switch (type)
  3941. {
  3942. case PT_ARM_EXIDX: return "EXIDX";
  3943. default: return NULL;
  3944. }
  3945. }
  3946. static const char *
  3947. get_s390_segment_type (unsigned long type)
  3948. {
  3949. switch (type)
  3950. {
  3951. case PT_S390_PGSTE: return "S390_PGSTE";
  3952. default: return NULL;
  3953. }
  3954. }
  3955. static const char *
  3956. get_mips_segment_type (unsigned long type)
  3957. {
  3958. switch (type)
  3959. {
  3960. case PT_MIPS_REGINFO: return "REGINFO";
  3961. case PT_MIPS_RTPROC: return "RTPROC";
  3962. case PT_MIPS_OPTIONS: return "OPTIONS";
  3963. case PT_MIPS_ABIFLAGS: return "ABIFLAGS";
  3964. default: return NULL;
  3965. }
  3966. }
  3967. static const char *
  3968. get_parisc_segment_type (unsigned long type)
  3969. {
  3970. switch (type)
  3971. {
  3972. case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
  3973. case PT_PARISC_UNWIND: return "PARISC_UNWIND";
  3974. case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER";
  3975. default: return NULL;
  3976. }
  3977. }
  3978. static const char *
  3979. get_ia64_segment_type (unsigned long type)
  3980. {
  3981. switch (type)
  3982. {
  3983. case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
  3984. case PT_IA_64_UNWIND: return "IA_64_UNWIND";
  3985. default: return NULL;
  3986. }
  3987. }
  3988. static const char *
  3989. get_tic6x_segment_type (unsigned long type)
  3990. {
  3991. switch (type)
  3992. {
  3993. case PT_C6000_PHATTR: return "C6000_PHATTR";
  3994. default: return NULL;
  3995. }
  3996. }
  3997. static const char *
  3998. get_riscv_segment_type (unsigned long type)
  3999. {
  4000. switch (type)
  4001. {
  4002. case PT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES";
  4003. default: return NULL;
  4004. }
  4005. }
  4006. static const char *
  4007. get_hpux_segment_type (unsigned long type, unsigned e_machine)
  4008. {
  4009. if (e_machine == EM_PARISC)
  4010. switch (type)
  4011. {
  4012. case PT_HP_TLS: return "HP_TLS";
  4013. case PT_HP_CORE_NONE: return "HP_CORE_NONE";
  4014. case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
  4015. case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
  4016. case PT_HP_CORE_COMM: return "HP_CORE_COMM";
  4017. case PT_HP_CORE_PROC: return "HP_CORE_PROC";
  4018. case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
  4019. case PT_HP_CORE_STACK: return "HP_CORE_STACK";
  4020. case PT_HP_CORE_SHM: return "HP_CORE_SHM";
  4021. case PT_HP_CORE_MMF: return "HP_CORE_MMF";
  4022. case PT_HP_PARALLEL: return "HP_PARALLEL";
  4023. case PT_HP_FASTBIND: return "HP_FASTBIND";
  4024. case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT";
  4025. case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT";
  4026. case PT_HP_STACK: return "HP_STACK";
  4027. case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME";
  4028. default: return NULL;
  4029. }
  4030. if (e_machine == EM_IA_64)
  4031. switch (type)
  4032. {
  4033. case PT_HP_TLS: return "HP_TLS";
  4034. case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
  4035. case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
  4036. case PT_IA_64_HP_STACK: return "HP_STACK";
  4037. default: return NULL;
  4038. }
  4039. return NULL;
  4040. }
  4041. static const char *
  4042. get_solaris_segment_type (unsigned long type)
  4043. {
  4044. switch (type)
  4045. {
  4046. case 0x6464e550: return "PT_SUNW_UNWIND";
  4047. case 0x6474e550: return "PT_SUNW_EH_FRAME";
  4048. case 0x6ffffff7: return "PT_LOSUNW";
  4049. case 0x6ffffffa: return "PT_SUNWBSS";
  4050. case 0x6ffffffb: return "PT_SUNWSTACK";
  4051. case 0x6ffffffc: return "PT_SUNWDTRACE";
  4052. case 0x6ffffffd: return "PT_SUNWCAP";
  4053. case 0x6fffffff: return "PT_HISUNW";
  4054. default: return NULL;
  4055. }
  4056. }
  4057. static const char *
  4058. get_segment_type (Filedata * filedata, unsigned long p_type)
  4059. {
  4060. static char buff[32];
  4061. switch (p_type)
  4062. {
  4063. case PT_NULL: return "NULL";
  4064. case PT_LOAD: return "LOAD";
  4065. case PT_DYNAMIC: return "DYNAMIC";
  4066. case PT_INTERP: return "INTERP";
  4067. case PT_NOTE: return "NOTE";
  4068. case PT_SHLIB: return "SHLIB";
  4069. case PT_PHDR: return "PHDR";
  4070. case PT_TLS: return "TLS";
  4071. case PT_GNU_EH_FRAME: return "GNU_EH_FRAME";
  4072. case PT_GNU_STACK: return "GNU_STACK";
  4073. case PT_GNU_RELRO: return "GNU_RELRO";
  4074. case PT_GNU_PROPERTY: return "GNU_PROPERTY";
  4075. case PT_OPENBSD_RANDOMIZE: return "OPENBSD_RANDOMIZE";
  4076. case PT_OPENBSD_WXNEEDED: return "OPENBSD_WXNEEDED";
  4077. case PT_OPENBSD_BOOTDATA: return "OPENBSD_BOOTDATA";
  4078. default:
  4079. if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
  4080. {
  4081. const char * result;
  4082. switch (filedata->file_header.e_machine)
  4083. {
  4084. case EM_AARCH64:
  4085. result = get_aarch64_segment_type (p_type);
  4086. break;
  4087. case EM_ARM:
  4088. result = get_arm_segment_type (p_type);
  4089. break;
  4090. case EM_MIPS:
  4091. case EM_MIPS_RS3_LE:
  4092. result = get_mips_segment_type (p_type);
  4093. break;
  4094. case EM_PARISC:
  4095. result = get_parisc_segment_type (p_type);
  4096. break;
  4097. case EM_IA_64:
  4098. result = get_ia64_segment_type (p_type);
  4099. break;
  4100. case EM_TI_C6000:
  4101. result = get_tic6x_segment_type (p_type);
  4102. break;
  4103. case EM_S390:
  4104. case EM_S390_OLD:
  4105. result = get_s390_segment_type (p_type);
  4106. break;
  4107. case EM_RISCV:
  4108. result = get_riscv_segment_type (p_type);
  4109. break;
  4110. default:
  4111. result = NULL;
  4112. break;
  4113. }
  4114. if (result != NULL)
  4115. return result;
  4116. sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC);
  4117. }
  4118. else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
  4119. {
  4120. const char * result = NULL;
  4121. switch (filedata->file_header.e_ident[EI_OSABI])
  4122. {
  4123. case ELFOSABI_GNU:
  4124. case ELFOSABI_FREEBSD:
  4125. if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI)
  4126. {
  4127. sprintf (buff, "GNU_MBIND+%#lx", p_type - PT_GNU_MBIND_LO);
  4128. result = buff;
  4129. }
  4130. break;
  4131. case ELFOSABI_HPUX:
  4132. result = get_hpux_segment_type (p_type,
  4133. filedata->file_header.e_machine);
  4134. break;
  4135. case ELFOSABI_SOLARIS:
  4136. result = get_solaris_segment_type (p_type);
  4137. break;
  4138. default:
  4139. break;
  4140. }
  4141. if (result != NULL)
  4142. return result;
  4143. sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS);
  4144. }
  4145. else
  4146. snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
  4147. return buff;
  4148. }
  4149. }
  4150. static const char *
  4151. get_arc_section_type_name (unsigned int sh_type)
  4152. {
  4153. switch (sh_type)
  4154. {
  4155. case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES";
  4156. default:
  4157. break;
  4158. }
  4159. return NULL;
  4160. }
  4161. static const char *
  4162. get_mips_section_type_name (unsigned int sh_type)
  4163. {
  4164. switch (sh_type)
  4165. {
  4166. case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
  4167. case SHT_MIPS_MSYM: return "MIPS_MSYM";
  4168. case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
  4169. case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
  4170. case SHT_MIPS_UCODE: return "MIPS_UCODE";
  4171. case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
  4172. case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
  4173. case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
  4174. case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
  4175. case SHT_MIPS_RELD: return "MIPS_RELD";
  4176. case SHT_MIPS_IFACE: return "MIPS_IFACE";
  4177. case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
  4178. case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
  4179. case SHT_MIPS_SHDR: return "MIPS_SHDR";
  4180. case SHT_MIPS_FDESC: return "MIPS_FDESC";
  4181. case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
  4182. case SHT_MIPS_DENSE: return "MIPS_DENSE";
  4183. case SHT_MIPS_PDESC: return "MIPS_PDESC";
  4184. case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
  4185. case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
  4186. case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
  4187. case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
  4188. case SHT_MIPS_LINE: return "MIPS_LINE";
  4189. case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
  4190. case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
  4191. case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
  4192. case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
  4193. case SHT_MIPS_DWARF: return "MIPS_DWARF";
  4194. case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
  4195. case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
  4196. case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
  4197. case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
  4198. case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
  4199. case SHT_MIPS_XLATE: return "MIPS_XLATE";
  4200. case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
  4201. case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
  4202. case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
  4203. case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
  4204. case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
  4205. case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS";
  4206. case SHT_MIPS_XHASH: return "MIPS_XHASH";
  4207. default:
  4208. break;
  4209. }
  4210. return NULL;
  4211. }
  4212. static const char *
  4213. get_parisc_section_type_name (unsigned int sh_type)
  4214. {
  4215. switch (sh_type)
  4216. {
  4217. case SHT_PARISC_EXT: return "PARISC_EXT";
  4218. case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
  4219. case SHT_PARISC_DOC: return "PARISC_DOC";
  4220. case SHT_PARISC_ANNOT: return "PARISC_ANNOT";
  4221. case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN";
  4222. case SHT_PARISC_STUBS: return "PARISC_STUBS";
  4223. case SHT_PARISC_DLKM: return "PARISC_DLKM";
  4224. default: return NULL;
  4225. }
  4226. }
  4227. static const char *
  4228. get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type)
  4229. {
  4230. /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
  4231. if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
  4232. return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16);
  4233. switch (sh_type)
  4234. {
  4235. case SHT_IA_64_EXT: return "IA_64_EXT";
  4236. case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
  4237. case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
  4238. case SHT_IA_64_VMS_TRACE: return "VMS_TRACE";
  4239. case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
  4240. case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG";
  4241. case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR";
  4242. case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES";
  4243. case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR";
  4244. case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP";
  4245. default:
  4246. break;
  4247. }
  4248. return NULL;
  4249. }
  4250. static const char *
  4251. get_x86_64_section_type_name (unsigned int sh_type)
  4252. {
  4253. switch (sh_type)
  4254. {
  4255. case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
  4256. default: return NULL;
  4257. }
  4258. }
  4259. static const char *
  4260. get_aarch64_section_type_name (unsigned int sh_type)
  4261. {
  4262. switch (sh_type)
  4263. {
  4264. case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES";
  4265. default: return NULL;
  4266. }
  4267. }
  4268. static const char *
  4269. get_arm_section_type_name (unsigned int sh_type)
  4270. {
  4271. switch (sh_type)
  4272. {
  4273. case SHT_ARM_EXIDX: return "ARM_EXIDX";
  4274. case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP";
  4275. case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES";
  4276. case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY";
  4277. case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION";
  4278. default: return NULL;
  4279. }
  4280. }
  4281. static const char *
  4282. get_tic6x_section_type_name (unsigned int sh_type)
  4283. {
  4284. switch (sh_type)
  4285. {
  4286. case SHT_C6000_UNWIND: return "C6000_UNWIND";
  4287. case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
  4288. case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES";
  4289. case SHT_TI_ICODE: return "TI_ICODE";
  4290. case SHT_TI_XREF: return "TI_XREF";
  4291. case SHT_TI_HANDLER: return "TI_HANDLER";
  4292. case SHT_TI_INITINFO: return "TI_INITINFO";
  4293. case SHT_TI_PHATTRS: return "TI_PHATTRS";
  4294. default: return NULL;
  4295. }
  4296. }
  4297. static const char *
  4298. get_msp430_section_type_name (unsigned int sh_type)
  4299. {
  4300. switch (sh_type)
  4301. {
  4302. case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS";
  4303. case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES";
  4304. case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES";
  4305. default: return NULL;
  4306. }
  4307. }
  4308. static const char *
  4309. get_nfp_section_type_name (unsigned int sh_type)
  4310. {
  4311. switch (sh_type)
  4312. {
  4313. case SHT_NFP_MECONFIG: return "NFP_MECONFIG";
  4314. case SHT_NFP_INITREG: return "NFP_INITREG";
  4315. case SHT_NFP_UDEBUG: return "NFP_UDEBUG";
  4316. default: return NULL;
  4317. }
  4318. }
  4319. static const char *
  4320. get_v850_section_type_name (unsigned int sh_type)
  4321. {
  4322. switch (sh_type)
  4323. {
  4324. case SHT_V850_SCOMMON: return "V850 Small Common";
  4325. case SHT_V850_TCOMMON: return "V850 Tiny Common";
  4326. case SHT_V850_ZCOMMON: return "V850 Zero Common";
  4327. case SHT_RENESAS_IOP: return "RENESAS IOP";
  4328. case SHT_RENESAS_INFO: return "RENESAS INFO";
  4329. default: return NULL;
  4330. }
  4331. }
  4332. static const char *
  4333. get_riscv_section_type_name (unsigned int sh_type)
  4334. {
  4335. switch (sh_type)
  4336. {
  4337. case SHT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES";
  4338. default: return NULL;
  4339. }
  4340. }
  4341. static const char *
  4342. get_csky_section_type_name (unsigned int sh_type)
  4343. {
  4344. switch (sh_type)
  4345. {
  4346. case SHT_CSKY_ATTRIBUTES: return "CSKY_ATTRIBUTES";
  4347. default: return NULL;
  4348. }
  4349. }
  4350. static const char *
  4351. get_section_type_name (Filedata * filedata, unsigned int sh_type)
  4352. {
  4353. static char buff[32];
  4354. const char * result;
  4355. switch (sh_type)
  4356. {
  4357. case SHT_NULL: return "NULL";
  4358. case SHT_PROGBITS: return "PROGBITS";
  4359. case SHT_SYMTAB: return "SYMTAB";
  4360. case SHT_STRTAB: return "STRTAB";
  4361. case SHT_RELA: return "RELA";
  4362. case SHT_RELR: return "RELR";
  4363. case SHT_HASH: return "HASH";
  4364. case SHT_DYNAMIC: return "DYNAMIC";
  4365. case SHT_NOTE: return "NOTE";
  4366. case SHT_NOBITS: return "NOBITS";
  4367. case SHT_REL: return "REL";
  4368. case SHT_SHLIB: return "SHLIB";
  4369. case SHT_DYNSYM: return "DYNSYM";
  4370. case SHT_INIT_ARRAY: return "INIT_ARRAY";
  4371. case SHT_FINI_ARRAY: return "FINI_ARRAY";
  4372. case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
  4373. case SHT_GNU_HASH: return "GNU_HASH";
  4374. case SHT_GROUP: return "GROUP";
  4375. case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES";
  4376. case SHT_GNU_verdef: return "VERDEF";
  4377. case SHT_GNU_verneed: return "VERNEED";
  4378. case SHT_GNU_versym: return "VERSYM";
  4379. case 0x6ffffff0: return "VERSYM";
  4380. case 0x6ffffffc: return "VERDEF";
  4381. case 0x7ffffffd: return "AUXILIARY";
  4382. case 0x7fffffff: return "FILTER";
  4383. case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
  4384. default:
  4385. if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
  4386. {
  4387. switch (filedata->file_header.e_machine)
  4388. {
  4389. case EM_ARC:
  4390. case EM_ARC_COMPACT:
  4391. case EM_ARC_COMPACT2:
  4392. result = get_arc_section_type_name (sh_type);
  4393. break;
  4394. case EM_MIPS:
  4395. case EM_MIPS_RS3_LE:
  4396. result = get_mips_section_type_name (sh_type);
  4397. break;
  4398. case EM_PARISC:
  4399. result = get_parisc_section_type_name (sh_type);
  4400. break;
  4401. case EM_IA_64:
  4402. result = get_ia64_section_type_name (filedata, sh_type);
  4403. break;
  4404. case EM_X86_64:
  4405. case EM_L1OM:
  4406. case EM_K1OM:
  4407. result = get_x86_64_section_type_name (sh_type);
  4408. break;
  4409. case EM_AARCH64:
  4410. result = get_aarch64_section_type_name (sh_type);
  4411. break;
  4412. case EM_ARM:
  4413. result = get_arm_section_type_name (sh_type);
  4414. break;
  4415. case EM_TI_C6000:
  4416. result = get_tic6x_section_type_name (sh_type);
  4417. break;
  4418. case EM_MSP430:
  4419. result = get_msp430_section_type_name (sh_type);
  4420. break;
  4421. case EM_NFP:
  4422. result = get_nfp_section_type_name (sh_type);
  4423. break;
  4424. case EM_V800:
  4425. case EM_V850:
  4426. case EM_CYGNUS_V850:
  4427. result = get_v850_section_type_name (sh_type);
  4428. break;
  4429. case EM_RISCV:
  4430. result = get_riscv_section_type_name (sh_type);
  4431. break;
  4432. case EM_CSKY:
  4433. result = get_csky_section_type_name (sh_type);
  4434. break;
  4435. default:
  4436. result = NULL;
  4437. break;
  4438. }
  4439. if (result != NULL)
  4440. return result;
  4441. sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC);
  4442. }
  4443. else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
  4444. {
  4445. switch (filedata->file_header.e_machine)
  4446. {
  4447. case EM_IA_64:
  4448. result = get_ia64_section_type_name (filedata, sh_type);
  4449. break;
  4450. default:
  4451. if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
  4452. result = get_solaris_section_type (sh_type);
  4453. else
  4454. {
  4455. switch (sh_type)
  4456. {
  4457. case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break;
  4458. case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break;
  4459. case SHT_GNU_HASH: result = "GNU_HASH"; break;
  4460. case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break;
  4461. default:
  4462. result = NULL;
  4463. break;
  4464. }
  4465. }
  4466. break;
  4467. }
  4468. if (result != NULL)
  4469. return result;
  4470. sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS);
  4471. }
  4472. else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
  4473. {
  4474. switch (filedata->file_header.e_machine)
  4475. {
  4476. case EM_V800:
  4477. case EM_V850:
  4478. case EM_CYGNUS_V850:
  4479. result = get_v850_section_type_name (sh_type);
  4480. break;
  4481. default:
  4482. result = NULL;
  4483. break;
  4484. }
  4485. if (result != NULL)
  4486. return result;
  4487. sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER);
  4488. }
  4489. else
  4490. /* This message is probably going to be displayed in a 15
  4491. character wide field, so put the hex value first. */
  4492. snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type);
  4493. return buff;
  4494. }
  4495. }
  4496. enum long_option_values
  4497. {
  4498. OPTION_DEBUG_DUMP = 512,
  4499. OPTION_DYN_SYMS,
  4500. OPTION_LTO_SYMS,
  4501. OPTION_DWARF_DEPTH,
  4502. OPTION_DWARF_START,
  4503. OPTION_DWARF_CHECK,
  4504. OPTION_CTF_DUMP,
  4505. OPTION_CTF_PARENT,
  4506. OPTION_CTF_SYMBOLS,
  4507. OPTION_CTF_STRINGS,
  4508. OPTION_WITH_SYMBOL_VERSIONS,
  4509. OPTION_RECURSE_LIMIT,
  4510. OPTION_NO_RECURSE_LIMIT,
  4511. OPTION_NO_DEMANGLING,
  4512. OPTION_SYM_BASE
  4513. };
  4514. static struct option options[] =
  4515. {
  4516. /* Note - This table is alpha-sorted on the 'val'
  4517. field in order to make adding new options easier. */
  4518. {"arch-specific", no_argument, 0, 'A'},
  4519. {"all", no_argument, 0, 'a'},
  4520. {"demangle", optional_argument, 0, 'C'},
  4521. {"archive-index", no_argument, 0, 'c'},
  4522. {"use-dynamic", no_argument, 0, 'D'},
  4523. {"dynamic", no_argument, 0, 'd'},
  4524. {"headers", no_argument, 0, 'e'},
  4525. {"section-groups", no_argument, 0, 'g'},
  4526. {"help", no_argument, 0, 'H'},
  4527. {"file-header", no_argument, 0, 'h'},
  4528. {"histogram", no_argument, 0, 'I'},
  4529. {"lint", no_argument, 0, 'L'},
  4530. {"enable-checks", no_argument, 0, 'L'},
  4531. {"program-headers", no_argument, 0, 'l'},
  4532. {"segments", no_argument, 0, 'l'},
  4533. {"full-section-name",no_argument, 0, 'N'},
  4534. {"notes", no_argument, 0, 'n'},
  4535. {"process-links", no_argument, 0, 'P'},
  4536. {"string-dump", required_argument, 0, 'p'},
  4537. {"relocated-dump", required_argument, 0, 'R'},
  4538. {"relocs", no_argument, 0, 'r'},
  4539. {"section-headers", no_argument, 0, 'S'},
  4540. {"sections", no_argument, 0, 'S'},
  4541. {"symbols", no_argument, 0, 's'},
  4542. {"syms", no_argument, 0, 's'},
  4543. {"silent-truncation",no_argument, 0, 'T'},
  4544. {"section-details", no_argument, 0, 't'},
  4545. {"unicode", required_argument, NULL, 'U'},
  4546. {"unwind", no_argument, 0, 'u'},
  4547. {"version-info", no_argument, 0, 'V'},
  4548. {"version", no_argument, 0, 'v'},
  4549. {"wide", no_argument, 0, 'W'},
  4550. {"hex-dump", required_argument, 0, 'x'},
  4551. {"decompress", no_argument, 0, 'z'},
  4552. {"no-demangle", no_argument, 0, OPTION_NO_DEMANGLING},
  4553. {"recurse-limit", no_argument, NULL, OPTION_RECURSE_LIMIT},
  4554. {"no-recurse-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT},
  4555. {"no-recursion-limit", no_argument, NULL, OPTION_NO_RECURSE_LIMIT},
  4556. {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS},
  4557. {"lto-syms", no_argument, 0, OPTION_LTO_SYMS},
  4558. {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
  4559. {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
  4560. {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
  4561. {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
  4562. #ifdef ENABLE_LIBCTF
  4563. {"ctf", required_argument, 0, OPTION_CTF_DUMP},
  4564. {"ctf-symbols", required_argument, 0, OPTION_CTF_SYMBOLS},
  4565. {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS},
  4566. {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT},
  4567. #endif
  4568. {"sym-base", optional_argument, 0, OPTION_SYM_BASE},
  4569. {0, no_argument, 0, 0}
  4570. };
  4571. static void
  4572. usage (FILE * stream)
  4573. {
  4574. fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
  4575. fprintf (stream, _(" Display information about the contents of ELF format files\n"));
  4576. fprintf (stream, _(" Options are:\n"));
  4577. fprintf (stream, _("\
  4578. -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n"));
  4579. fprintf (stream, _("\
  4580. -h --file-header Display the ELF file header\n"));
  4581. fprintf (stream, _("\
  4582. -l --program-headers Display the program headers\n"));
  4583. fprintf (stream, _("\
  4584. --segments An alias for --program-headers\n"));
  4585. fprintf (stream, _("\
  4586. -S --section-headers Display the sections' header\n"));
  4587. fprintf (stream, _("\
  4588. --sections An alias for --section-headers\n"));
  4589. fprintf (stream, _("\
  4590. -g --section-groups Display the section groups\n"));
  4591. fprintf (stream, _("\
  4592. -t --section-details Display the section details\n"));
  4593. fprintf (stream, _("\
  4594. -e --headers Equivalent to: -h -l -S\n"));
  4595. fprintf (stream, _("\
  4596. -s --syms Display the symbol table\n"));
  4597. fprintf (stream, _("\
  4598. --symbols An alias for --syms\n"));
  4599. fprintf (stream, _("\
  4600. --dyn-syms Display the dynamic symbol table\n"));
  4601. fprintf (stream, _("\
  4602. --lto-syms Display LTO symbol tables\n"));
  4603. fprintf (stream, _("\
  4604. --sym-base=[0|8|10|16] \n\
  4605. Force base for symbol sizes. The options are \n\
  4606. mixed (the default), octal, decimal, hexadecimal.\n"));
  4607. fprintf (stream, _("\
  4608. -C --demangle[=STYLE] Decode mangled/processed symbol names\n"));
  4609. display_demangler_styles (stream, _("\
  4610. STYLE can be "));
  4611. fprintf (stream, _("\
  4612. --no-demangle Do not demangle low-level symbol names. (default)\n"));
  4613. fprintf (stream, _("\
  4614. --recurse-limit Enable a demangling recursion limit. (default)\n"));
  4615. fprintf (stream, _("\
  4616. --no-recurse-limit Disable a demangling recursion limit\n"));
  4617. fprintf (stream, _("\
  4618. -U[dlexhi] --unicode=[default|locale|escape|hex|highlight|invalid]\n\
  4619. Display unicode characters as determined by the current locale\n\
  4620. (default), escape sequences, \"<hex sequences>\", highlighted\n\
  4621. escape sequences, or treat them as invalid and display as\n\
  4622. \"{hex sequences}\"\n"));
  4623. fprintf (stream, _("\
  4624. -n --notes Display the core notes (if present)\n"));
  4625. fprintf (stream, _("\
  4626. -r --relocs Display the relocations (if present)\n"));
  4627. fprintf (stream, _("\
  4628. -u --unwind Display the unwind info (if present)\n"));
  4629. fprintf (stream, _("\
  4630. -d --dynamic Display the dynamic section (if present)\n"));
  4631. fprintf (stream, _("\
  4632. -V --version-info Display the version sections (if present)\n"));
  4633. fprintf (stream, _("\
  4634. -A --arch-specific Display architecture specific information (if any)\n"));
  4635. fprintf (stream, _("\
  4636. -c --archive-index Display the symbol/file index in an archive\n"));
  4637. fprintf (stream, _("\
  4638. -D --use-dynamic Use the dynamic section info when displaying symbols\n"));
  4639. fprintf (stream, _("\
  4640. -L --lint|--enable-checks\n\
  4641. Display warning messages for possible problems\n"));
  4642. fprintf (stream, _("\
  4643. -x --hex-dump=<number|name>\n\
  4644. Dump the contents of section <number|name> as bytes\n"));
  4645. fprintf (stream, _("\
  4646. -p --string-dump=<number|name>\n\
  4647. Dump the contents of section <number|name> as strings\n"));
  4648. fprintf (stream, _("\
  4649. -R --relocated-dump=<number|name>\n\
  4650. Dump the relocated contents of section <number|name>\n"));
  4651. fprintf (stream, _("\
  4652. -z --decompress Decompress section before dumping it\n"));
  4653. fprintf (stream, _("\
  4654. -w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,\n\
  4655. f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,\n\
  4656. m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,\n\
  4657. s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,\n\
  4658. U/=trace_info]\n\
  4659. Display the contents of DWARF debug sections\n"));
  4660. fprintf (stream, _("\
  4661. -wk --debug-dump=links Display the contents of sections that link to separate\n\
  4662. debuginfo files\n"));
  4663. fprintf (stream, _("\
  4664. -P --process-links Display the contents of non-debug sections in separate\n\
  4665. debuginfo files. (Implies -wK)\n"));
  4666. #if DEFAULT_FOR_FOLLOW_LINKS
  4667. fprintf (stream, _("\
  4668. -wK --debug-dump=follow-links\n\
  4669. Follow links to separate debug info files (default)\n"));
  4670. fprintf (stream, _("\
  4671. -wN --debug-dump=no-follow-links\n\
  4672. Do not follow links to separate debug info files\n"));
  4673. #else
  4674. fprintf (stream, _("\
  4675. -wK --debug-dump=follow-links\n\
  4676. Follow links to separate debug info files\n"));
  4677. fprintf (stream, _("\
  4678. -wN --debug-dump=no-follow-links\n\
  4679. Do not follow links to separate debug info files\n\
  4680. (default)\n"));
  4681. #endif
  4682. #if HAVE_LIBDEBUGINFOD
  4683. fprintf (stream, _("\
  4684. -wD --debug-dump=use-debuginfod\n\
  4685. When following links, also query debuginfod servers (default)\n"));
  4686. fprintf (stream, _("\
  4687. -wE --debug-dump=do-not-use-debuginfod\n\
  4688. When following links, do not query debuginfod servers\n"));
  4689. #endif
  4690. fprintf (stream, _("\
  4691. --dwarf-depth=N Do not display DIEs at depth N or greater\n"));
  4692. fprintf (stream, _("\
  4693. --dwarf-start=N Display DIEs starting at offset N\n"));
  4694. #ifdef ENABLE_LIBCTF
  4695. fprintf (stream, _("\
  4696. --ctf=<number|name> Display CTF info from section <number|name>\n"));
  4697. fprintf (stream, _("\
  4698. --ctf-parent=<name> Use CTF archive member <name> as the CTF parent\n"));
  4699. fprintf (stream, _("\
  4700. --ctf-symbols=<number|name>\n\
  4701. Use section <number|name> as the CTF external symtab\n"));
  4702. fprintf (stream, _("\
  4703. --ctf-strings=<number|name>\n\
  4704. Use section <number|name> as the CTF external strtab\n"));
  4705. #endif
  4706. #ifdef SUPPORT_DISASSEMBLY
  4707. fprintf (stream, _("\
  4708. -i --instruction-dump=<number|name>\n\
  4709. Disassemble the contents of section <number|name>\n"));
  4710. #endif
  4711. fprintf (stream, _("\
  4712. -I --histogram Display histogram of bucket list lengths\n"));
  4713. fprintf (stream, _("\
  4714. -W --wide Allow output width to exceed 80 characters\n"));
  4715. fprintf (stream, _("\
  4716. -T --silent-truncation If a symbol name is truncated, do not add [...] suffix\n"));
  4717. fprintf (stream, _("\
  4718. @<file> Read options from <file>\n"));
  4719. fprintf (stream, _("\
  4720. -H --help Display this information\n"));
  4721. fprintf (stream, _("\
  4722. -v --version Display the version number of readelf\n"));
  4723. if (REPORT_BUGS_TO[0] && stream == stdout)
  4724. fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
  4725. exit (stream == stdout ? 0 : 1);
  4726. }
  4727. /* Record the fact that the user wants the contents of section number
  4728. SECTION to be displayed using the method(s) encoded as flags bits
  4729. in TYPE. Note, TYPE can be zero if we are creating the array for
  4730. the first time. */
  4731. static void
  4732. request_dump_bynumber (struct dump_data *dumpdata,
  4733. unsigned int section, dump_type type)
  4734. {
  4735. if (section >= dumpdata->num_dump_sects)
  4736. {
  4737. dump_type * new_dump_sects;
  4738. new_dump_sects = (dump_type *) calloc (section + 1,
  4739. sizeof (* new_dump_sects));
  4740. if (new_dump_sects == NULL)
  4741. error (_("Out of memory allocating dump request table.\n"));
  4742. else
  4743. {
  4744. if (dumpdata->dump_sects)
  4745. {
  4746. /* Copy current flag settings. */
  4747. memcpy (new_dump_sects, dumpdata->dump_sects,
  4748. dumpdata->num_dump_sects * sizeof (* new_dump_sects));
  4749. free (dumpdata->dump_sects);
  4750. }
  4751. dumpdata->dump_sects = new_dump_sects;
  4752. dumpdata->num_dump_sects = section + 1;
  4753. }
  4754. }
  4755. if (dumpdata->dump_sects)
  4756. dumpdata->dump_sects[section] |= type;
  4757. }
  4758. /* Request a dump by section name. */
  4759. static void
  4760. request_dump_byname (const char * section, dump_type type)
  4761. {
  4762. struct dump_list_entry * new_request;
  4763. new_request = (struct dump_list_entry *)
  4764. malloc (sizeof (struct dump_list_entry));
  4765. if (!new_request)
  4766. error (_("Out of memory allocating dump request table.\n"));
  4767. new_request->name = strdup (section);
  4768. if (!new_request->name)
  4769. error (_("Out of memory allocating dump request table.\n"));
  4770. new_request->type = type;
  4771. new_request->next = dump_sects_byname;
  4772. dump_sects_byname = new_request;
  4773. }
  4774. static inline void
  4775. request_dump (struct dump_data *dumpdata, dump_type type)
  4776. {
  4777. int section;
  4778. char * cp;
  4779. do_dump = true;
  4780. section = strtoul (optarg, & cp, 0);
  4781. if (! *cp && section >= 0)
  4782. request_dump_bynumber (dumpdata, section, type);
  4783. else
  4784. request_dump_byname (optarg, type);
  4785. }
  4786. static void
  4787. parse_args (struct dump_data *dumpdata, int argc, char ** argv)
  4788. {
  4789. int c;
  4790. if (argc < 2)
  4791. usage (stderr);
  4792. while ((c = getopt_long
  4793. (argc, argv, "ACDHILNPR:STU:VWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
  4794. {
  4795. switch (c)
  4796. {
  4797. case 0:
  4798. /* Long options. */
  4799. break;
  4800. case 'H':
  4801. usage (stdout);
  4802. break;
  4803. case 'a':
  4804. do_syms = true;
  4805. do_reloc = true;
  4806. do_unwind = true;
  4807. do_dynamic = true;
  4808. do_header = true;
  4809. do_sections = true;
  4810. do_section_groups = true;
  4811. do_segments = true;
  4812. do_version = true;
  4813. do_histogram = true;
  4814. do_arch = true;
  4815. do_notes = true;
  4816. break;
  4817. case 'g':
  4818. do_section_groups = true;
  4819. break;
  4820. case 't':
  4821. case 'N':
  4822. do_sections = true;
  4823. do_section_details = true;
  4824. break;
  4825. case 'e':
  4826. do_header = true;
  4827. do_sections = true;
  4828. do_segments = true;
  4829. break;
  4830. case 'A':
  4831. do_arch = true;
  4832. break;
  4833. case 'D':
  4834. do_using_dynamic = true;
  4835. break;
  4836. case 'r':
  4837. do_reloc = true;
  4838. break;
  4839. case 'u':
  4840. do_unwind = true;
  4841. break;
  4842. case 'h':
  4843. do_header = true;
  4844. break;
  4845. case 'l':
  4846. do_segments = true;
  4847. break;
  4848. case 's':
  4849. do_syms = true;
  4850. break;
  4851. case 'S':
  4852. do_sections = true;
  4853. break;
  4854. case 'd':
  4855. do_dynamic = true;
  4856. break;
  4857. case 'I':
  4858. do_histogram = true;
  4859. break;
  4860. case 'n':
  4861. do_notes = true;
  4862. break;
  4863. case 'c':
  4864. do_archive_index = true;
  4865. break;
  4866. case 'L':
  4867. do_checks = true;
  4868. break;
  4869. case 'P':
  4870. process_links = true;
  4871. do_follow_links = true;
  4872. dump_any_debugging = true;
  4873. break;
  4874. case 'x':
  4875. request_dump (dumpdata, HEX_DUMP);
  4876. break;
  4877. case 'p':
  4878. request_dump (dumpdata, STRING_DUMP);
  4879. break;
  4880. case 'R':
  4881. request_dump (dumpdata, RELOC_DUMP);
  4882. break;
  4883. case 'z':
  4884. decompress_dumps = true;
  4885. break;
  4886. case 'w':
  4887. do_dump = true;
  4888. dump_any_debugging = true;
  4889. if (optarg == NULL)
  4890. {
  4891. do_debugging = true;
  4892. dwarf_select_sections_all ();
  4893. }
  4894. else
  4895. {
  4896. do_debugging = false;
  4897. dwarf_select_sections_by_letters (optarg);
  4898. }
  4899. break;
  4900. case OPTION_DEBUG_DUMP:
  4901. do_dump = true;
  4902. dump_any_debugging = true;
  4903. if (optarg == NULL)
  4904. {
  4905. do_debugging = true;
  4906. dwarf_select_sections_all ();
  4907. }
  4908. else
  4909. {
  4910. do_debugging = false;
  4911. dwarf_select_sections_by_names (optarg);
  4912. }
  4913. break;
  4914. case OPTION_DWARF_DEPTH:
  4915. {
  4916. char *cp;
  4917. dwarf_cutoff_level = strtoul (optarg, & cp, 0);
  4918. }
  4919. break;
  4920. case OPTION_DWARF_START:
  4921. {
  4922. char *cp;
  4923. dwarf_start_die = strtoul (optarg, & cp, 0);
  4924. }
  4925. break;
  4926. case OPTION_DWARF_CHECK:
  4927. dwarf_check = true;
  4928. break;
  4929. case OPTION_CTF_DUMP:
  4930. do_ctf = true;
  4931. request_dump (dumpdata, CTF_DUMP);
  4932. break;
  4933. case OPTION_CTF_SYMBOLS:
  4934. free (dump_ctf_symtab_name);
  4935. dump_ctf_symtab_name = strdup (optarg);
  4936. break;
  4937. case OPTION_CTF_STRINGS:
  4938. free (dump_ctf_strtab_name);
  4939. dump_ctf_strtab_name = strdup (optarg);
  4940. break;
  4941. case OPTION_CTF_PARENT:
  4942. free (dump_ctf_parent_name);
  4943. dump_ctf_parent_name = strdup (optarg);
  4944. break;
  4945. case OPTION_DYN_SYMS:
  4946. do_dyn_syms = true;
  4947. break;
  4948. case OPTION_LTO_SYMS:
  4949. do_lto_syms = true;
  4950. break;
  4951. #ifdef SUPPORT_DISASSEMBLY
  4952. case 'i':
  4953. request_dump (dumpdata, DISASS_DUMP);
  4954. break;
  4955. #endif
  4956. case 'v':
  4957. print_version (program_name);
  4958. break;
  4959. case 'V':
  4960. do_version = true;
  4961. break;
  4962. case 'W':
  4963. do_wide = true;
  4964. break;
  4965. case 'T':
  4966. do_not_show_symbol_truncation = true;
  4967. break;
  4968. case 'C':
  4969. do_demangle = true;
  4970. if (optarg != NULL)
  4971. {
  4972. enum demangling_styles style;
  4973. style = cplus_demangle_name_to_style (optarg);
  4974. if (style == unknown_demangling)
  4975. error (_("unknown demangling style `%s'"), optarg);
  4976. cplus_demangle_set_style (style);
  4977. }
  4978. break;
  4979. case OPTION_NO_DEMANGLING:
  4980. do_demangle = false;
  4981. break;
  4982. case OPTION_RECURSE_LIMIT:
  4983. demangle_flags &= ~ DMGL_NO_RECURSE_LIMIT;
  4984. break;
  4985. case OPTION_NO_RECURSE_LIMIT:
  4986. demangle_flags |= DMGL_NO_RECURSE_LIMIT;
  4987. break;
  4988. case OPTION_WITH_SYMBOL_VERSIONS:
  4989. /* Ignored for backward compatibility. */
  4990. break;
  4991. case 'U':
  4992. if (optarg == NULL)
  4993. error (_("Missing arg to -U/--unicode")); /* Can this happen ? */
  4994. else if (streq (optarg, "default") || streq (optarg, "d"))
  4995. unicode_display = unicode_default;
  4996. else if (streq (optarg, "locale") || streq (optarg, "l"))
  4997. unicode_display = unicode_locale;
  4998. else if (streq (optarg, "escape") || streq (optarg, "e"))
  4999. unicode_display = unicode_escape;
  5000. else if (streq (optarg, "invalid") || streq (optarg, "i"))
  5001. unicode_display = unicode_invalid;
  5002. else if (streq (optarg, "hex") || streq (optarg, "x"))
  5003. unicode_display = unicode_hex;
  5004. else if (streq (optarg, "highlight") || streq (optarg, "h"))
  5005. unicode_display = unicode_highlight;
  5006. else
  5007. error (_("invalid argument to -U/--unicode: %s"), optarg);
  5008. break;
  5009. case OPTION_SYM_BASE:
  5010. sym_base = 0;
  5011. if (optarg != NULL)
  5012. {
  5013. sym_base = strtoul (optarg, NULL, 0);
  5014. switch (sym_base)
  5015. {
  5016. case 0:
  5017. case 8:
  5018. case 10:
  5019. case 16:
  5020. break;
  5021. default:
  5022. sym_base = 0;
  5023. break;
  5024. }
  5025. }
  5026. break;
  5027. default:
  5028. /* xgettext:c-format */
  5029. error (_("Invalid option '-%c'\n"), c);
  5030. /* Fall through. */
  5031. case '?':
  5032. usage (stderr);
  5033. }
  5034. }
  5035. if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
  5036. && !do_segments && !do_header && !do_dump && !do_version
  5037. && !do_histogram && !do_debugging && !do_arch && !do_notes
  5038. && !do_section_groups && !do_archive_index
  5039. && !do_dyn_syms && !do_lto_syms)
  5040. {
  5041. if (do_checks)
  5042. {
  5043. check_all = true;
  5044. do_dynamic = do_syms = do_reloc = do_unwind = do_sections = true;
  5045. do_segments = do_header = do_dump = do_version = true;
  5046. do_histogram = do_debugging = do_arch = do_notes = true;
  5047. do_section_groups = do_archive_index = do_dyn_syms = true;
  5048. do_lto_syms = true;
  5049. }
  5050. else
  5051. usage (stderr);
  5052. }
  5053. }
  5054. static const char *
  5055. get_elf_class (unsigned int elf_class)
  5056. {
  5057. static char buff[32];
  5058. switch (elf_class)
  5059. {
  5060. case ELFCLASSNONE: return _("none");
  5061. case ELFCLASS32: return "ELF32";
  5062. case ELFCLASS64: return "ELF64";
  5063. default:
  5064. snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
  5065. return buff;
  5066. }
  5067. }
  5068. static const char *
  5069. get_data_encoding (unsigned int encoding)
  5070. {
  5071. static char buff[32];
  5072. switch (encoding)
  5073. {
  5074. case ELFDATANONE: return _("none");
  5075. case ELFDATA2LSB: return _("2's complement, little endian");
  5076. case ELFDATA2MSB: return _("2's complement, big endian");
  5077. default:
  5078. snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
  5079. return buff;
  5080. }
  5081. }
  5082. /* Decode the data held in 'filedata->file_header'. */
  5083. static bool
  5084. process_file_header (Filedata * filedata)
  5085. {
  5086. Elf_Internal_Ehdr * header = & filedata->file_header;
  5087. if ( header->e_ident[EI_MAG0] != ELFMAG0
  5088. || header->e_ident[EI_MAG1] != ELFMAG1
  5089. || header->e_ident[EI_MAG2] != ELFMAG2
  5090. || header->e_ident[EI_MAG3] != ELFMAG3)
  5091. {
  5092. error
  5093. (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
  5094. return false;
  5095. }
  5096. if (! filedata->is_separate)
  5097. init_dwarf_regnames_by_elf_machine_code (header->e_machine);
  5098. if (do_header)
  5099. {
  5100. unsigned i;
  5101. if (filedata->is_separate)
  5102. printf (_("ELF Header in linked file '%s':\n"), filedata->file_name);
  5103. else
  5104. printf (_("ELF Header:\n"));
  5105. printf (_(" Magic: "));
  5106. for (i = 0; i < EI_NIDENT; i++)
  5107. printf ("%2.2x ", header->e_ident[i]);
  5108. printf ("\n");
  5109. printf (_(" Class: %s\n"),
  5110. get_elf_class (header->e_ident[EI_CLASS]));
  5111. printf (_(" Data: %s\n"),
  5112. get_data_encoding (header->e_ident[EI_DATA]));
  5113. printf (_(" Version: %d%s\n"),
  5114. header->e_ident[EI_VERSION],
  5115. (header->e_ident[EI_VERSION] == EV_CURRENT
  5116. ? _(" (current)")
  5117. : (header->e_ident[EI_VERSION] != EV_NONE
  5118. ? _(" <unknown>")
  5119. : "")));
  5120. printf (_(" OS/ABI: %s\n"),
  5121. get_osabi_name (filedata, header->e_ident[EI_OSABI]));
  5122. printf (_(" ABI Version: %d\n"),
  5123. header->e_ident[EI_ABIVERSION]);
  5124. printf (_(" Type: %s\n"),
  5125. get_file_type (filedata));
  5126. printf (_(" Machine: %s\n"),
  5127. get_machine_name (header->e_machine));
  5128. printf (_(" Version: 0x%lx\n"),
  5129. header->e_version);
  5130. printf (_(" Entry point address: "));
  5131. print_vma (header->e_entry, PREFIX_HEX);
  5132. printf (_("\n Start of program headers: "));
  5133. print_vma (header->e_phoff, DEC);
  5134. printf (_(" (bytes into file)\n Start of section headers: "));
  5135. print_vma (header->e_shoff, DEC);
  5136. printf (_(" (bytes into file)\n"));
  5137. printf (_(" Flags: 0x%lx%s\n"),
  5138. header->e_flags,
  5139. get_machine_flags (filedata, header->e_flags, header->e_machine));
  5140. printf (_(" Size of this header: %u (bytes)\n"),
  5141. header->e_ehsize);
  5142. printf (_(" Size of program headers: %u (bytes)\n"),
  5143. header->e_phentsize);
  5144. printf (_(" Number of program headers: %u"),
  5145. header->e_phnum);
  5146. if (filedata->section_headers != NULL
  5147. && header->e_phnum == PN_XNUM
  5148. && filedata->section_headers[0].sh_info != 0)
  5149. printf (" (%u)", filedata->section_headers[0].sh_info);
  5150. putc ('\n', stdout);
  5151. printf (_(" Size of section headers: %u (bytes)\n"),
  5152. header->e_shentsize);
  5153. printf (_(" Number of section headers: %u"),
  5154. header->e_shnum);
  5155. if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF)
  5156. {
  5157. header->e_shnum = filedata->section_headers[0].sh_size;
  5158. printf (" (%u)", header->e_shnum);
  5159. }
  5160. putc ('\n', stdout);
  5161. printf (_(" Section header string table index: %u"),
  5162. header->e_shstrndx);
  5163. if (filedata->section_headers != NULL
  5164. && header->e_shstrndx == (SHN_XINDEX & 0xffff))
  5165. {
  5166. header->e_shstrndx = filedata->section_headers[0].sh_link;
  5167. printf (" (%u)", header->e_shstrndx);
  5168. }
  5169. if (header->e_shstrndx != SHN_UNDEF
  5170. && header->e_shstrndx >= header->e_shnum)
  5171. {
  5172. header->e_shstrndx = SHN_UNDEF;
  5173. printf (_(" <corrupt: out of range>"));
  5174. }
  5175. putc ('\n', stdout);
  5176. }
  5177. if (filedata->section_headers != NULL)
  5178. {
  5179. if (header->e_phnum == PN_XNUM
  5180. && filedata->section_headers[0].sh_info != 0)
  5181. {
  5182. /* Throw away any cached read of PN_XNUM headers. */
  5183. free (filedata->program_headers);
  5184. filedata->program_headers = NULL;
  5185. header->e_phnum = filedata->section_headers[0].sh_info;
  5186. }
  5187. if (header->e_shnum == SHN_UNDEF)
  5188. header->e_shnum = filedata->section_headers[0].sh_size;
  5189. if (header->e_shstrndx == (SHN_XINDEX & 0xffff))
  5190. header->e_shstrndx = filedata->section_headers[0].sh_link;
  5191. if (header->e_shstrndx >= header->e_shnum)
  5192. header->e_shstrndx = SHN_UNDEF;
  5193. }
  5194. return true;
  5195. }
  5196. /* Read in the program headers from FILEDATA and store them in PHEADERS.
  5197. Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */
  5198. static bool
  5199. get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
  5200. {
  5201. Elf32_External_Phdr * phdrs;
  5202. Elf32_External_Phdr * external;
  5203. Elf_Internal_Phdr * internal;
  5204. unsigned int i;
  5205. unsigned int size = filedata->file_header.e_phentsize;
  5206. unsigned int num = filedata->file_header.e_phnum;
  5207. /* PR binutils/17531: Cope with unexpected section header sizes. */
  5208. if (size == 0 || num == 0)
  5209. return false;
  5210. if (size < sizeof * phdrs)
  5211. {
  5212. error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
  5213. return false;
  5214. }
  5215. if (size > sizeof * phdrs)
  5216. warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
  5217. phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
  5218. size, num, _("program headers"));
  5219. if (phdrs == NULL)
  5220. return false;
  5221. for (i = 0, internal = pheaders, external = phdrs;
  5222. i < filedata->file_header.e_phnum;
  5223. i++, internal++, external++)
  5224. {
  5225. internal->p_type = BYTE_GET (external->p_type);
  5226. internal->p_offset = BYTE_GET (external->p_offset);
  5227. internal->p_vaddr = BYTE_GET (external->p_vaddr);
  5228. internal->p_paddr = BYTE_GET (external->p_paddr);
  5229. internal->p_filesz = BYTE_GET (external->p_filesz);
  5230. internal->p_memsz = BYTE_GET (external->p_memsz);
  5231. internal->p_flags = BYTE_GET (external->p_flags);
  5232. internal->p_align = BYTE_GET (external->p_align);
  5233. }
  5234. free (phdrs);
  5235. return true;
  5236. }
  5237. /* Read in the program headers from FILEDATA and store them in PHEADERS.
  5238. Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */
  5239. static bool
  5240. get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders)
  5241. {
  5242. Elf64_External_Phdr * phdrs;
  5243. Elf64_External_Phdr * external;
  5244. Elf_Internal_Phdr * internal;
  5245. unsigned int i;
  5246. unsigned int size = filedata->file_header.e_phentsize;
  5247. unsigned int num = filedata->file_header.e_phnum;
  5248. /* PR binutils/17531: Cope with unexpected section header sizes. */
  5249. if (size == 0 || num == 0)
  5250. return false;
  5251. if (size < sizeof * phdrs)
  5252. {
  5253. error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
  5254. return false;
  5255. }
  5256. if (size > sizeof * phdrs)
  5257. warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
  5258. phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff,
  5259. size, num, _("program headers"));
  5260. if (!phdrs)
  5261. return false;
  5262. for (i = 0, internal = pheaders, external = phdrs;
  5263. i < filedata->file_header.e_phnum;
  5264. i++, internal++, external++)
  5265. {
  5266. internal->p_type = BYTE_GET (external->p_type);
  5267. internal->p_flags = BYTE_GET (external->p_flags);
  5268. internal->p_offset = BYTE_GET (external->p_offset);
  5269. internal->p_vaddr = BYTE_GET (external->p_vaddr);
  5270. internal->p_paddr = BYTE_GET (external->p_paddr);
  5271. internal->p_filesz = BYTE_GET (external->p_filesz);
  5272. internal->p_memsz = BYTE_GET (external->p_memsz);
  5273. internal->p_align = BYTE_GET (external->p_align);
  5274. }
  5275. free (phdrs);
  5276. return true;
  5277. }
  5278. /* Returns TRUE if the program headers were read into `program_headers'. */
  5279. static bool
  5280. get_program_headers (Filedata * filedata)
  5281. {
  5282. Elf_Internal_Phdr * phdrs;
  5283. /* Check cache of prior read. */
  5284. if (filedata->program_headers != NULL)
  5285. return true;
  5286. /* Be kind to memory checkers by looking for
  5287. e_phnum values which we know must be invalid. */
  5288. if (filedata->file_header.e_phnum
  5289. * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr))
  5290. >= filedata->file_size)
  5291. {
  5292. error (_("Too many program headers - %#x - the file is not that big\n"),
  5293. filedata->file_header.e_phnum);
  5294. return false;
  5295. }
  5296. phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum,
  5297. sizeof (Elf_Internal_Phdr));
  5298. if (phdrs == NULL)
  5299. {
  5300. error (_("Out of memory reading %u program headers\n"),
  5301. filedata->file_header.e_phnum);
  5302. return false;
  5303. }
  5304. if (is_32bit_elf
  5305. ? get_32bit_program_headers (filedata, phdrs)
  5306. : get_64bit_program_headers (filedata, phdrs))
  5307. {
  5308. filedata->program_headers = phdrs;
  5309. return true;
  5310. }
  5311. free (phdrs);
  5312. return false;
  5313. }
  5314. /* Print program header info and locate dynamic section. */
  5315. static void
  5316. process_program_headers (Filedata * filedata)
  5317. {
  5318. Elf_Internal_Phdr * segment;
  5319. unsigned int i;
  5320. Elf_Internal_Phdr * previous_load = NULL;
  5321. if (filedata->file_header.e_phnum == 0)
  5322. {
  5323. /* PR binutils/12467. */
  5324. if (filedata->file_header.e_phoff != 0)
  5325. warn (_("possibly corrupt ELF header - it has a non-zero program"
  5326. " header offset, but no program headers\n"));
  5327. else if (do_segments)
  5328. {
  5329. if (filedata->is_separate)
  5330. printf (_("\nThere are no program headers in linked file '%s'.\n"),
  5331. filedata->file_name);
  5332. else
  5333. printf (_("\nThere are no program headers in this file.\n"));
  5334. }
  5335. goto no_headers;
  5336. }
  5337. if (do_segments && !do_header)
  5338. {
  5339. if (filedata->is_separate)
  5340. printf ("\nIn linked file '%s' the ELF file type is %s\n",
  5341. filedata->file_name, get_file_type (filedata));
  5342. else
  5343. printf (_("\nElf file type is %s\n"), get_file_type (filedata));
  5344. printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata->file_header.e_entry));
  5345. printf (ngettext ("There is %d program header, starting at offset %s\n",
  5346. "There are %d program headers, starting at offset %s\n",
  5347. filedata->file_header.e_phnum),
  5348. filedata->file_header.e_phnum,
  5349. bfd_vmatoa ("u", filedata->file_header.e_phoff));
  5350. }
  5351. if (! get_program_headers (filedata))
  5352. goto no_headers;
  5353. if (do_segments)
  5354. {
  5355. if (filedata->file_header.e_phnum > 1)
  5356. printf (_("\nProgram Headers:\n"));
  5357. else
  5358. printf (_("\nProgram Headers:\n"));
  5359. if (is_32bit_elf)
  5360. printf
  5361. (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
  5362. else if (do_wide)
  5363. printf
  5364. (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
  5365. else
  5366. {
  5367. printf
  5368. (_(" Type Offset VirtAddr PhysAddr\n"));
  5369. printf
  5370. (_(" FileSiz MemSiz Flags Align\n"));
  5371. }
  5372. }
  5373. unsigned long dynamic_addr = 0;
  5374. bfd_size_type dynamic_size = 0;
  5375. for (i = 0, segment = filedata->program_headers;
  5376. i < filedata->file_header.e_phnum;
  5377. i++, segment++)
  5378. {
  5379. if (do_segments)
  5380. {
  5381. printf (" %-14.14s ", get_segment_type (filedata, segment->p_type));
  5382. if (is_32bit_elf)
  5383. {
  5384. printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
  5385. printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
  5386. printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
  5387. printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
  5388. printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
  5389. printf ("%c%c%c ",
  5390. (segment->p_flags & PF_R ? 'R' : ' '),
  5391. (segment->p_flags & PF_W ? 'W' : ' '),
  5392. (segment->p_flags & PF_X ? 'E' : ' '));
  5393. printf ("%#lx", (unsigned long) segment->p_align);
  5394. }
  5395. else if (do_wide)
  5396. {
  5397. if ((unsigned long) segment->p_offset == segment->p_offset)
  5398. printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
  5399. else
  5400. {
  5401. print_vma (segment->p_offset, FULL_HEX);
  5402. putchar (' ');
  5403. }
  5404. print_vma (segment->p_vaddr, FULL_HEX);
  5405. putchar (' ');
  5406. print_vma (segment->p_paddr, FULL_HEX);
  5407. putchar (' ');
  5408. if ((unsigned long) segment->p_filesz == segment->p_filesz)
  5409. printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
  5410. else
  5411. {
  5412. print_vma (segment->p_filesz, FULL_HEX);
  5413. putchar (' ');
  5414. }
  5415. if ((unsigned long) segment->p_memsz == segment->p_memsz)
  5416. printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
  5417. else
  5418. {
  5419. print_vma (segment->p_memsz, FULL_HEX);
  5420. }
  5421. printf (" %c%c%c ",
  5422. (segment->p_flags & PF_R ? 'R' : ' '),
  5423. (segment->p_flags & PF_W ? 'W' : ' '),
  5424. (segment->p_flags & PF_X ? 'E' : ' '));
  5425. if ((unsigned long) segment->p_align == segment->p_align)
  5426. printf ("%#lx", (unsigned long) segment->p_align);
  5427. else
  5428. {
  5429. print_vma (segment->p_align, PREFIX_HEX);
  5430. }
  5431. }
  5432. else
  5433. {
  5434. print_vma (segment->p_offset, FULL_HEX);
  5435. putchar (' ');
  5436. print_vma (segment->p_vaddr, FULL_HEX);
  5437. putchar (' ');
  5438. print_vma (segment->p_paddr, FULL_HEX);
  5439. printf ("\n ");
  5440. print_vma (segment->p_filesz, FULL_HEX);
  5441. putchar (' ');
  5442. print_vma (segment->p_memsz, FULL_HEX);
  5443. printf (" %c%c%c ",
  5444. (segment->p_flags & PF_R ? 'R' : ' '),
  5445. (segment->p_flags & PF_W ? 'W' : ' '),
  5446. (segment->p_flags & PF_X ? 'E' : ' '));
  5447. print_vma (segment->p_align, PREFIX_HEX);
  5448. }
  5449. putc ('\n', stdout);
  5450. }
  5451. switch (segment->p_type)
  5452. {
  5453. case PT_LOAD:
  5454. #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
  5455. required by the ELF standard, several programs, including the Linux
  5456. kernel, make use of non-ordered segments. */
  5457. if (previous_load
  5458. && previous_load->p_vaddr > segment->p_vaddr)
  5459. error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
  5460. #endif
  5461. if (segment->p_memsz < segment->p_filesz)
  5462. error (_("the segment's file size is larger than its memory size\n"));
  5463. previous_load = segment;
  5464. break;
  5465. case PT_PHDR:
  5466. /* PR 20815 - Verify that the program header is loaded into memory. */
  5467. if (i > 0 && previous_load != NULL)
  5468. error (_("the PHDR segment must occur before any LOAD segment\n"));
  5469. if (filedata->file_header.e_machine != EM_PARISC)
  5470. {
  5471. unsigned int j;
  5472. for (j = 1; j < filedata->file_header.e_phnum; j++)
  5473. {
  5474. Elf_Internal_Phdr *load = filedata->program_headers + j;
  5475. if (load->p_type == PT_LOAD
  5476. && load->p_offset <= segment->p_offset
  5477. && (load->p_offset + load->p_filesz
  5478. >= segment->p_offset + segment->p_filesz)
  5479. && load->p_vaddr <= segment->p_vaddr
  5480. && (load->p_vaddr + load->p_filesz
  5481. >= segment->p_vaddr + segment->p_filesz))
  5482. break;
  5483. }
  5484. if (j == filedata->file_header.e_phnum)
  5485. error (_("the PHDR segment is not covered by a LOAD segment\n"));
  5486. }
  5487. break;
  5488. case PT_DYNAMIC:
  5489. if (dynamic_addr)
  5490. error (_("more than one dynamic segment\n"));
  5491. /* By default, assume that the .dynamic section is the first
  5492. section in the DYNAMIC segment. */
  5493. dynamic_addr = segment->p_offset;
  5494. dynamic_size = segment->p_filesz;
  5495. /* Try to locate the .dynamic section. If there is
  5496. a section header table, we can easily locate it. */
  5497. if (filedata->section_headers != NULL)
  5498. {
  5499. Elf_Internal_Shdr * sec;
  5500. sec = find_section (filedata, ".dynamic");
  5501. if (sec == NULL || sec->sh_size == 0)
  5502. {
  5503. /* A corresponding .dynamic section is expected, but on
  5504. IA-64/OpenVMS it is OK for it to be missing. */
  5505. if (!is_ia64_vms (filedata))
  5506. error (_("no .dynamic section in the dynamic segment\n"));
  5507. break;
  5508. }
  5509. if (sec->sh_type == SHT_NOBITS)
  5510. {
  5511. dynamic_addr = 0;
  5512. dynamic_size = 0;
  5513. break;
  5514. }
  5515. dynamic_addr = sec->sh_offset;
  5516. dynamic_size = sec->sh_size;
  5517. /* The PT_DYNAMIC segment, which is used by the run-time
  5518. loader, should exactly match the .dynamic section. */
  5519. if (do_checks
  5520. && (dynamic_addr != segment->p_offset
  5521. || dynamic_size != segment->p_filesz))
  5522. warn (_("\
  5523. the .dynamic section is not the same as the dynamic segment\n"));
  5524. }
  5525. /* PR binutils/17512: Avoid corrupt dynamic section info in the
  5526. segment. Check this after matching against the section headers
  5527. so we don't warn on debuginfo file (which have NOBITS .dynamic
  5528. sections). */
  5529. if (dynamic_addr > filedata->file_size
  5530. || (dynamic_size > filedata->file_size - dynamic_addr))
  5531. {
  5532. error (_("the dynamic segment offset + size exceeds the size of the file\n"));
  5533. dynamic_addr = 0;
  5534. dynamic_size = 0;
  5535. }
  5536. break;
  5537. case PT_INTERP:
  5538. if (segment->p_offset >= filedata->file_size
  5539. || segment->p_filesz > filedata->file_size - segment->p_offset
  5540. || segment->p_filesz - 1 >= (size_t) -2
  5541. || fseek (filedata->handle,
  5542. filedata->archive_file_offset + (long) segment->p_offset,
  5543. SEEK_SET))
  5544. error (_("Unable to find program interpreter name\n"));
  5545. else
  5546. {
  5547. size_t len = segment->p_filesz;
  5548. free (filedata->program_interpreter);
  5549. filedata->program_interpreter = xmalloc (len + 1);
  5550. len = fread (filedata->program_interpreter, 1, len,
  5551. filedata->handle);
  5552. filedata->program_interpreter[len] = 0;
  5553. if (do_segments)
  5554. printf (_(" [Requesting program interpreter: %s]\n"),
  5555. filedata->program_interpreter);
  5556. }
  5557. break;
  5558. }
  5559. }
  5560. if (do_segments
  5561. && filedata->section_headers != NULL
  5562. && filedata->string_table != NULL)
  5563. {
  5564. printf (_("\n Section to Segment mapping:\n"));
  5565. printf (_(" Segment Sections...\n"));
  5566. for (i = 0; i < filedata->file_header.e_phnum; i++)
  5567. {
  5568. unsigned int j;
  5569. Elf_Internal_Shdr * section;
  5570. segment = filedata->program_headers + i;
  5571. section = filedata->section_headers + 1;
  5572. printf (" %2.2d ", i);
  5573. for (j = 1; j < filedata->file_header.e_shnum; j++, section++)
  5574. {
  5575. if (!ELF_TBSS_SPECIAL (section, segment)
  5576. && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
  5577. printf ("%s ", printable_section_name (filedata, section));
  5578. }
  5579. putc ('\n',stdout);
  5580. }
  5581. }
  5582. filedata->dynamic_addr = dynamic_addr;
  5583. filedata->dynamic_size = dynamic_size ? dynamic_size : 1;
  5584. return;
  5585. no_headers:
  5586. filedata->dynamic_addr = 0;
  5587. filedata->dynamic_size = 1;
  5588. }
  5589. /* Find the file offset corresponding to VMA by using the program headers. */
  5590. static long
  5591. offset_from_vma (Filedata * filedata, bfd_vma vma, bfd_size_type size)
  5592. {
  5593. Elf_Internal_Phdr * seg;
  5594. if (! get_program_headers (filedata))
  5595. {
  5596. warn (_("Cannot interpret virtual addresses without program headers.\n"));
  5597. return (long) vma;
  5598. }
  5599. for (seg = filedata->program_headers;
  5600. seg < filedata->program_headers + filedata->file_header.e_phnum;
  5601. ++seg)
  5602. {
  5603. if (seg->p_type != PT_LOAD)
  5604. continue;
  5605. if (vma >= (seg->p_vaddr & -seg->p_align)
  5606. && vma + size <= seg->p_vaddr + seg->p_filesz)
  5607. return vma - seg->p_vaddr + seg->p_offset;
  5608. }
  5609. warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
  5610. (unsigned long) vma);
  5611. return (long) vma;
  5612. }
  5613. /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers.
  5614. If PROBE is true, this is just a probe and we do not generate any error
  5615. messages if the load fails. */
  5616. static bool
  5617. get_32bit_section_headers (Filedata * filedata, bool probe)
  5618. {
  5619. Elf32_External_Shdr * shdrs;
  5620. Elf_Internal_Shdr * internal;
  5621. unsigned int i;
  5622. unsigned int size = filedata->file_header.e_shentsize;
  5623. unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
  5624. /* PR binutils/17531: Cope with unexpected section header sizes. */
  5625. if (size == 0 || num == 0)
  5626. return false;
  5627. if (size < sizeof * shdrs)
  5628. {
  5629. if (! probe)
  5630. error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
  5631. return false;
  5632. }
  5633. if (!probe && size > sizeof * shdrs)
  5634. warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
  5635. shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff,
  5636. size, num,
  5637. probe ? NULL : _("section headers"));
  5638. if (shdrs == NULL)
  5639. return false;
  5640. filedata->section_headers = (Elf_Internal_Shdr *)
  5641. cmalloc (num, sizeof (Elf_Internal_Shdr));
  5642. if (filedata->section_headers == NULL)
  5643. {
  5644. if (!probe)
  5645. error (_("Out of memory reading %u section headers\n"), num);
  5646. free (shdrs);
  5647. return false;
  5648. }
  5649. for (i = 0, internal = filedata->section_headers;
  5650. i < num;
  5651. i++, internal++)
  5652. {
  5653. internal->sh_name = BYTE_GET (shdrs[i].sh_name);
  5654. internal->sh_type = BYTE_GET (shdrs[i].sh_type);
  5655. internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
  5656. internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
  5657. internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
  5658. internal->sh_size = BYTE_GET (shdrs[i].sh_size);
  5659. internal->sh_link = BYTE_GET (shdrs[i].sh_link);
  5660. internal->sh_info = BYTE_GET (shdrs[i].sh_info);
  5661. internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
  5662. internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
  5663. if (!probe && internal->sh_link > num)
  5664. warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
  5665. if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
  5666. warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
  5667. }
  5668. free (shdrs);
  5669. return true;
  5670. }
  5671. /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */
  5672. static bool
  5673. get_64bit_section_headers (Filedata * filedata, bool probe)
  5674. {
  5675. Elf64_External_Shdr * shdrs;
  5676. Elf_Internal_Shdr * internal;
  5677. unsigned int i;
  5678. unsigned int size = filedata->file_header.e_shentsize;
  5679. unsigned int num = probe ? 1 : filedata->file_header.e_shnum;
  5680. /* PR binutils/17531: Cope with unexpected section header sizes. */
  5681. if (size == 0 || num == 0)
  5682. return false;
  5683. if (size < sizeof * shdrs)
  5684. {
  5685. if (! probe)
  5686. error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
  5687. return false;
  5688. }
  5689. if (! probe && size > sizeof * shdrs)
  5690. warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
  5691. shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata,
  5692. filedata->file_header.e_shoff,
  5693. size, num,
  5694. probe ? NULL : _("section headers"));
  5695. if (shdrs == NULL)
  5696. return false;
  5697. filedata->section_headers = (Elf_Internal_Shdr *)
  5698. cmalloc (num, sizeof (Elf_Internal_Shdr));
  5699. if (filedata->section_headers == NULL)
  5700. {
  5701. if (! probe)
  5702. error (_("Out of memory reading %u section headers\n"), num);
  5703. free (shdrs);
  5704. return false;
  5705. }
  5706. for (i = 0, internal = filedata->section_headers;
  5707. i < num;
  5708. i++, internal++)
  5709. {
  5710. internal->sh_name = BYTE_GET (shdrs[i].sh_name);
  5711. internal->sh_type = BYTE_GET (shdrs[i].sh_type);
  5712. internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
  5713. internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
  5714. internal->sh_size = BYTE_GET (shdrs[i].sh_size);
  5715. internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
  5716. internal->sh_link = BYTE_GET (shdrs[i].sh_link);
  5717. internal->sh_info = BYTE_GET (shdrs[i].sh_info);
  5718. internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
  5719. internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
  5720. if (!probe && internal->sh_link > num)
  5721. warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
  5722. if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
  5723. warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
  5724. }
  5725. free (shdrs);
  5726. return true;
  5727. }
  5728. static bool
  5729. get_section_headers (Filedata *filedata, bool probe)
  5730. {
  5731. if (filedata->section_headers != NULL)
  5732. return true;
  5733. if (is_32bit_elf)
  5734. return get_32bit_section_headers (filedata, probe);
  5735. else
  5736. return get_64bit_section_headers (filedata, probe);
  5737. }
  5738. static Elf_Internal_Sym *
  5739. get_32bit_elf_symbols (Filedata * filedata,
  5740. Elf_Internal_Shdr * section,
  5741. unsigned long * num_syms_return)
  5742. {
  5743. unsigned long number = 0;
  5744. Elf32_External_Sym * esyms = NULL;
  5745. Elf_External_Sym_Shndx * shndx = NULL;
  5746. Elf_Internal_Sym * isyms = NULL;
  5747. Elf_Internal_Sym * psym;
  5748. unsigned int j;
  5749. elf_section_list * entry;
  5750. if (section->sh_size == 0)
  5751. {
  5752. if (num_syms_return != NULL)
  5753. * num_syms_return = 0;
  5754. return NULL;
  5755. }
  5756. /* Run some sanity checks first. */
  5757. if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
  5758. {
  5759. error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
  5760. printable_section_name (filedata, section),
  5761. (unsigned long) section->sh_entsize);
  5762. goto exit_point;
  5763. }
  5764. if (section->sh_size > filedata->file_size)
  5765. {
  5766. error (_("Section %s has an invalid sh_size of 0x%lx\n"),
  5767. printable_section_name (filedata, section),
  5768. (unsigned long) section->sh_size);
  5769. goto exit_point;
  5770. }
  5771. number = section->sh_size / section->sh_entsize;
  5772. if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1)
  5773. {
  5774. error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
  5775. (unsigned long) section->sh_size,
  5776. printable_section_name (filedata, section),
  5777. (unsigned long) section->sh_entsize);
  5778. goto exit_point;
  5779. }
  5780. esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
  5781. section->sh_size, _("symbols"));
  5782. if (esyms == NULL)
  5783. goto exit_point;
  5784. shndx = NULL;
  5785. for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next)
  5786. {
  5787. if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers))
  5788. continue;
  5789. if (shndx != NULL)
  5790. {
  5791. error (_("Multiple symbol table index sections associated with the same symbol section\n"));
  5792. free (shndx);
  5793. }
  5794. shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
  5795. entry->hdr->sh_offset,
  5796. 1, entry->hdr->sh_size,
  5797. _("symbol table section indices"));
  5798. if (shndx == NULL)
  5799. goto exit_point;
  5800. /* PR17531: file: heap-buffer-overflow */
  5801. if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
  5802. {
  5803. error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
  5804. printable_section_name (filedata, entry->hdr),
  5805. (unsigned long) entry->hdr->sh_size,
  5806. (unsigned long) section->sh_size);
  5807. goto exit_point;
  5808. }
  5809. }
  5810. isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
  5811. if (isyms == NULL)
  5812. {
  5813. error (_("Out of memory reading %lu symbols\n"),
  5814. (unsigned long) number);
  5815. goto exit_point;
  5816. }
  5817. for (j = 0, psym = isyms; j < number; j++, psym++)
  5818. {
  5819. psym->st_name = BYTE_GET (esyms[j].st_name);
  5820. psym->st_value = BYTE_GET (esyms[j].st_value);
  5821. psym->st_size = BYTE_GET (esyms[j].st_size);
  5822. psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
  5823. if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
  5824. psym->st_shndx
  5825. = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
  5826. else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
  5827. psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
  5828. psym->st_info = BYTE_GET (esyms[j].st_info);
  5829. psym->st_other = BYTE_GET (esyms[j].st_other);
  5830. }
  5831. exit_point:
  5832. free (shndx);
  5833. free (esyms);
  5834. if (num_syms_return != NULL)
  5835. * num_syms_return = isyms == NULL ? 0 : number;
  5836. return isyms;
  5837. }
  5838. static Elf_Internal_Sym *
  5839. get_64bit_elf_symbols (Filedata * filedata,
  5840. Elf_Internal_Shdr * section,
  5841. unsigned long * num_syms_return)
  5842. {
  5843. unsigned long number = 0;
  5844. Elf64_External_Sym * esyms = NULL;
  5845. Elf_External_Sym_Shndx * shndx = NULL;
  5846. Elf_Internal_Sym * isyms = NULL;
  5847. Elf_Internal_Sym * psym;
  5848. unsigned int j;
  5849. elf_section_list * entry;
  5850. if (section->sh_size == 0)
  5851. {
  5852. if (num_syms_return != NULL)
  5853. * num_syms_return = 0;
  5854. return NULL;
  5855. }
  5856. /* Run some sanity checks first. */
  5857. if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
  5858. {
  5859. error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
  5860. printable_section_name (filedata, section),
  5861. (unsigned long) section->sh_entsize);
  5862. goto exit_point;
  5863. }
  5864. if (section->sh_size > filedata->file_size)
  5865. {
  5866. error (_("Section %s has an invalid sh_size of 0x%lx\n"),
  5867. printable_section_name (filedata, section),
  5868. (unsigned long) section->sh_size);
  5869. goto exit_point;
  5870. }
  5871. number = section->sh_size / section->sh_entsize;
  5872. if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1)
  5873. {
  5874. error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
  5875. (unsigned long) section->sh_size,
  5876. printable_section_name (filedata, section),
  5877. (unsigned long) section->sh_entsize);
  5878. goto exit_point;
  5879. }
  5880. esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1,
  5881. section->sh_size, _("symbols"));
  5882. if (!esyms)
  5883. goto exit_point;
  5884. shndx = NULL;
  5885. for (entry = filedata->symtab_shndx_list; entry != NULL; entry = entry->next)
  5886. {
  5887. if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers))
  5888. continue;
  5889. if (shndx != NULL)
  5890. {
  5891. error (_("Multiple symbol table index sections associated with the same symbol section\n"));
  5892. free (shndx);
  5893. }
  5894. shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
  5895. entry->hdr->sh_offset,
  5896. 1, entry->hdr->sh_size,
  5897. _("symbol table section indices"));
  5898. if (shndx == NULL)
  5899. goto exit_point;
  5900. /* PR17531: file: heap-buffer-overflow */
  5901. if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
  5902. {
  5903. error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
  5904. printable_section_name (filedata, entry->hdr),
  5905. (unsigned long) entry->hdr->sh_size,
  5906. (unsigned long) section->sh_size);
  5907. goto exit_point;
  5908. }
  5909. }
  5910. isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
  5911. if (isyms == NULL)
  5912. {
  5913. error (_("Out of memory reading %lu symbols\n"),
  5914. (unsigned long) number);
  5915. goto exit_point;
  5916. }
  5917. for (j = 0, psym = isyms; j < number; j++, psym++)
  5918. {
  5919. psym->st_name = BYTE_GET (esyms[j].st_name);
  5920. psym->st_info = BYTE_GET (esyms[j].st_info);
  5921. psym->st_other = BYTE_GET (esyms[j].st_other);
  5922. psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
  5923. if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
  5924. psym->st_shndx
  5925. = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
  5926. else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
  5927. psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
  5928. psym->st_value = BYTE_GET (esyms[j].st_value);
  5929. psym->st_size = BYTE_GET (esyms[j].st_size);
  5930. }
  5931. exit_point:
  5932. free (shndx);
  5933. free (esyms);
  5934. if (num_syms_return != NULL)
  5935. * num_syms_return = isyms == NULL ? 0 : number;
  5936. return isyms;
  5937. }
  5938. static Elf_Internal_Sym *
  5939. get_elf_symbols (Filedata *filedata,
  5940. Elf_Internal_Shdr *section,
  5941. unsigned long *num_syms_return)
  5942. {
  5943. if (is_32bit_elf)
  5944. return get_32bit_elf_symbols (filedata, section, num_syms_return);
  5945. else
  5946. return get_64bit_elf_symbols (filedata, section, num_syms_return);
  5947. }
  5948. static const char *
  5949. get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
  5950. {
  5951. static char buff[1024];
  5952. char * p = buff;
  5953. unsigned int field_size = is_32bit_elf ? 8 : 16;
  5954. signed int sindex;
  5955. unsigned int size = sizeof (buff) - (field_size + 4 + 1);
  5956. bfd_vma os_flags = 0;
  5957. bfd_vma proc_flags = 0;
  5958. bfd_vma unknown_flags = 0;
  5959. static const struct
  5960. {
  5961. const char * str;
  5962. unsigned int len;
  5963. }
  5964. flags [] =
  5965. {
  5966. /* 0 */ { STRING_COMMA_LEN ("WRITE") },
  5967. /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
  5968. /* 2 */ { STRING_COMMA_LEN ("EXEC") },
  5969. /* 3 */ { STRING_COMMA_LEN ("MERGE") },
  5970. /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
  5971. /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
  5972. /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
  5973. /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
  5974. /* 8 */ { STRING_COMMA_LEN ("GROUP") },
  5975. /* 9 */ { STRING_COMMA_LEN ("TLS") },
  5976. /* IA-64 specific. */
  5977. /* 10 */ { STRING_COMMA_LEN ("SHORT") },
  5978. /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
  5979. /* IA-64 OpenVMS specific. */
  5980. /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
  5981. /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
  5982. /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
  5983. /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
  5984. /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
  5985. /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
  5986. /* Generic. */
  5987. /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
  5988. /* SPARC specific. */
  5989. /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
  5990. /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
  5991. /* ARM specific. */
  5992. /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
  5993. /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
  5994. /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
  5995. /* GNU specific. */
  5996. /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
  5997. /* VLE specific. */
  5998. /* 25 */ { STRING_COMMA_LEN ("VLE") },
  5999. /* GNU specific. */
  6000. /* 26 */ { STRING_COMMA_LEN ("GNU_RETAIN") },
  6001. };
  6002. if (do_section_details)
  6003. {
  6004. sprintf (buff, "[%*.*lx]: ",
  6005. field_size, field_size, (unsigned long) sh_flags);
  6006. p += field_size + 4;
  6007. }
  6008. while (sh_flags)
  6009. {
  6010. bfd_vma flag;
  6011. flag = sh_flags & - sh_flags;
  6012. sh_flags &= ~ flag;
  6013. if (do_section_details)
  6014. {
  6015. switch (flag)
  6016. {
  6017. case SHF_WRITE: sindex = 0; break;
  6018. case SHF_ALLOC: sindex = 1; break;
  6019. case SHF_EXECINSTR: sindex = 2; break;
  6020. case SHF_MERGE: sindex = 3; break;
  6021. case SHF_STRINGS: sindex = 4; break;
  6022. case SHF_INFO_LINK: sindex = 5; break;
  6023. case SHF_LINK_ORDER: sindex = 6; break;
  6024. case SHF_OS_NONCONFORMING: sindex = 7; break;
  6025. case SHF_GROUP: sindex = 8; break;
  6026. case SHF_TLS: sindex = 9; break;
  6027. case SHF_EXCLUDE: sindex = 18; break;
  6028. case SHF_COMPRESSED: sindex = 20; break;
  6029. default:
  6030. sindex = -1;
  6031. switch (filedata->file_header.e_machine)
  6032. {
  6033. case EM_IA_64:
  6034. if (flag == SHF_IA_64_SHORT)
  6035. sindex = 10;
  6036. else if (flag == SHF_IA_64_NORECOV)
  6037. sindex = 11;
  6038. #ifdef BFD64
  6039. else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
  6040. switch (flag)
  6041. {
  6042. case SHF_IA_64_VMS_GLOBAL: sindex = 12; break;
  6043. case SHF_IA_64_VMS_OVERLAID: sindex = 13; break;
  6044. case SHF_IA_64_VMS_SHARED: sindex = 14; break;
  6045. case SHF_IA_64_VMS_VECTOR: sindex = 15; break;
  6046. case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break;
  6047. case SHF_IA_64_VMS_PROTECTED: sindex = 17; break;
  6048. default: break;
  6049. }
  6050. #endif
  6051. break;
  6052. case EM_386:
  6053. case EM_IAMCU:
  6054. case EM_X86_64:
  6055. case EM_L1OM:
  6056. case EM_K1OM:
  6057. case EM_OLD_SPARCV9:
  6058. case EM_SPARC32PLUS:
  6059. case EM_SPARCV9:
  6060. case EM_SPARC:
  6061. if (flag == SHF_ORDERED)
  6062. sindex = 19;
  6063. break;
  6064. case EM_ARM:
  6065. switch (flag)
  6066. {
  6067. case SHF_ENTRYSECT: sindex = 21; break;
  6068. case SHF_ARM_PURECODE: sindex = 22; break;
  6069. case SHF_COMDEF: sindex = 23; break;
  6070. default: break;
  6071. }
  6072. break;
  6073. case EM_PPC:
  6074. if (flag == SHF_PPC_VLE)
  6075. sindex = 25;
  6076. break;
  6077. default:
  6078. break;
  6079. }
  6080. switch (filedata->file_header.e_ident[EI_OSABI])
  6081. {
  6082. case ELFOSABI_GNU:
  6083. case ELFOSABI_FREEBSD:
  6084. if (flag == SHF_GNU_RETAIN)
  6085. sindex = 26;
  6086. /* Fall through */
  6087. case ELFOSABI_NONE:
  6088. if (flag == SHF_GNU_MBIND)
  6089. /* We should not recognize SHF_GNU_MBIND for
  6090. ELFOSABI_NONE, but binutils as of 2019-07-23 did
  6091. not set the EI_OSABI header byte. */
  6092. sindex = 24;
  6093. break;
  6094. default:
  6095. break;
  6096. }
  6097. break;
  6098. }
  6099. if (sindex != -1)
  6100. {
  6101. if (p != buff + field_size + 4)
  6102. {
  6103. if (size < (10 + 2))
  6104. {
  6105. warn (_("Internal error: not enough buffer room for section flag info"));
  6106. return _("<unknown>");
  6107. }
  6108. size -= 2;
  6109. *p++ = ',';
  6110. *p++ = ' ';
  6111. }
  6112. size -= flags [sindex].len;
  6113. p = stpcpy (p, flags [sindex].str);
  6114. }
  6115. else if (flag & SHF_MASKOS)
  6116. os_flags |= flag;
  6117. else if (flag & SHF_MASKPROC)
  6118. proc_flags |= flag;
  6119. else
  6120. unknown_flags |= flag;
  6121. }
  6122. else
  6123. {
  6124. switch (flag)
  6125. {
  6126. case SHF_WRITE: *p = 'W'; break;
  6127. case SHF_ALLOC: *p = 'A'; break;
  6128. case SHF_EXECINSTR: *p = 'X'; break;
  6129. case SHF_MERGE: *p = 'M'; break;
  6130. case SHF_STRINGS: *p = 'S'; break;
  6131. case SHF_INFO_LINK: *p = 'I'; break;
  6132. case SHF_LINK_ORDER: *p = 'L'; break;
  6133. case SHF_OS_NONCONFORMING: *p = 'O'; break;
  6134. case SHF_GROUP: *p = 'G'; break;
  6135. case SHF_TLS: *p = 'T'; break;
  6136. case SHF_EXCLUDE: *p = 'E'; break;
  6137. case SHF_COMPRESSED: *p = 'C'; break;
  6138. default:
  6139. if ((filedata->file_header.e_machine == EM_X86_64
  6140. || filedata->file_header.e_machine == EM_L1OM
  6141. || filedata->file_header.e_machine == EM_K1OM)
  6142. && flag == SHF_X86_64_LARGE)
  6143. *p = 'l';
  6144. else if (filedata->file_header.e_machine == EM_ARM
  6145. && flag == SHF_ARM_PURECODE)
  6146. *p = 'y';
  6147. else if (filedata->file_header.e_machine == EM_PPC
  6148. && flag == SHF_PPC_VLE)
  6149. *p = 'v';
  6150. else if (flag & SHF_MASKOS)
  6151. {
  6152. switch (filedata->file_header.e_ident[EI_OSABI])
  6153. {
  6154. case ELFOSABI_GNU:
  6155. case ELFOSABI_FREEBSD:
  6156. if (flag == SHF_GNU_RETAIN)
  6157. {
  6158. *p = 'R';
  6159. break;
  6160. }
  6161. /* Fall through */
  6162. case ELFOSABI_NONE:
  6163. if (flag == SHF_GNU_MBIND)
  6164. {
  6165. /* We should not recognize SHF_GNU_MBIND for
  6166. ELFOSABI_NONE, but binutils as of 2019-07-23 did
  6167. not set the EI_OSABI header byte. */
  6168. *p = 'D';
  6169. break;
  6170. }
  6171. /* Fall through */
  6172. default:
  6173. *p = 'o';
  6174. sh_flags &= ~SHF_MASKOS;
  6175. break;
  6176. }
  6177. }
  6178. else if (flag & SHF_MASKPROC)
  6179. {
  6180. *p = 'p';
  6181. sh_flags &= ~ SHF_MASKPROC;
  6182. }
  6183. else
  6184. *p = 'x';
  6185. break;
  6186. }
  6187. p++;
  6188. }
  6189. }
  6190. if (do_section_details)
  6191. {
  6192. if (os_flags)
  6193. {
  6194. size -= 5 + field_size;
  6195. if (p != buff + field_size + 4)
  6196. {
  6197. if (size < (2 + 1))
  6198. {
  6199. warn (_("Internal error: not enough buffer room for section flag info"));
  6200. return _("<unknown>");
  6201. }
  6202. size -= 2;
  6203. *p++ = ',';
  6204. *p++ = ' ';
  6205. }
  6206. sprintf (p, "OS (%*.*lx)", field_size, field_size,
  6207. (unsigned long) os_flags);
  6208. p += 5 + field_size;
  6209. }
  6210. if (proc_flags)
  6211. {
  6212. size -= 7 + field_size;
  6213. if (p != buff + field_size + 4)
  6214. {
  6215. if (size < (2 + 1))
  6216. {
  6217. warn (_("Internal error: not enough buffer room for section flag info"));
  6218. return _("<unknown>");
  6219. }
  6220. size -= 2;
  6221. *p++ = ',';
  6222. *p++ = ' ';
  6223. }
  6224. sprintf (p, "PROC (%*.*lx)", field_size, field_size,
  6225. (unsigned long) proc_flags);
  6226. p += 7 + field_size;
  6227. }
  6228. if (unknown_flags)
  6229. {
  6230. size -= 10 + field_size;
  6231. if (p != buff + field_size + 4)
  6232. {
  6233. if (size < (2 + 1))
  6234. {
  6235. warn (_("Internal error: not enough buffer room for section flag info"));
  6236. return _("<unknown>");
  6237. }
  6238. size -= 2;
  6239. *p++ = ',';
  6240. *p++ = ' ';
  6241. }
  6242. sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size,
  6243. (unsigned long) unknown_flags);
  6244. p += 10 + field_size;
  6245. }
  6246. }
  6247. *p = '\0';
  6248. return buff;
  6249. }
  6250. static unsigned int ATTRIBUTE_WARN_UNUSED_RESULT
  6251. get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, bfd_size_type size)
  6252. {
  6253. if (is_32bit_elf)
  6254. {
  6255. Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf;
  6256. if (size < sizeof (* echdr))
  6257. {
  6258. error (_("Compressed section is too small even for a compression header\n"));
  6259. return 0;
  6260. }
  6261. chdr->ch_type = BYTE_GET (echdr->ch_type);
  6262. chdr->ch_size = BYTE_GET (echdr->ch_size);
  6263. chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
  6264. return sizeof (*echdr);
  6265. }
  6266. else
  6267. {
  6268. Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf;
  6269. if (size < sizeof (* echdr))
  6270. {
  6271. error (_("Compressed section is too small even for a compression header\n"));
  6272. return 0;
  6273. }
  6274. chdr->ch_type = BYTE_GET (echdr->ch_type);
  6275. chdr->ch_size = BYTE_GET (echdr->ch_size);
  6276. chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
  6277. return sizeof (*echdr);
  6278. }
  6279. }
  6280. static bool
  6281. process_section_headers (Filedata * filedata)
  6282. {
  6283. Elf_Internal_Shdr * section;
  6284. unsigned int i;
  6285. if (filedata->file_header.e_shnum == 0)
  6286. {
  6287. /* PR binutils/12467. */
  6288. if (filedata->file_header.e_shoff != 0)
  6289. {
  6290. warn (_("possibly corrupt ELF file header - it has a non-zero"
  6291. " section header offset, but no section headers\n"));
  6292. return false;
  6293. }
  6294. else if (do_sections)
  6295. printf (_("\nThere are no sections in this file.\n"));
  6296. return true;
  6297. }
  6298. if (do_sections && !do_header)
  6299. {
  6300. if (filedata->is_separate && process_links)
  6301. printf (_("In linked file '%s': "), filedata->file_name);
  6302. if (! filedata->is_separate || process_links)
  6303. printf (ngettext ("There is %d section header, "
  6304. "starting at offset 0x%lx:\n",
  6305. "There are %d section headers, "
  6306. "starting at offset 0x%lx:\n",
  6307. filedata->file_header.e_shnum),
  6308. filedata->file_header.e_shnum,
  6309. (unsigned long) filedata->file_header.e_shoff);
  6310. }
  6311. if (!get_section_headers (filedata, false))
  6312. return false;
  6313. /* Read in the string table, so that we have names to display. */
  6314. if (filedata->file_header.e_shstrndx != SHN_UNDEF
  6315. && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
  6316. {
  6317. section = filedata->section_headers + filedata->file_header.e_shstrndx;
  6318. if (section->sh_size != 0)
  6319. {
  6320. filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset,
  6321. 1, section->sh_size,
  6322. _("string table"));
  6323. filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0;
  6324. }
  6325. }
  6326. /* Scan the sections for the dynamic symbol table
  6327. and dynamic string table and debug sections. */
  6328. eh_addr_size = is_32bit_elf ? 4 : 8;
  6329. switch (filedata->file_header.e_machine)
  6330. {
  6331. case EM_MIPS:
  6332. case EM_MIPS_RS3_LE:
  6333. /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
  6334. FDE addresses. However, the ABI also has a semi-official ILP32
  6335. variant for which the normal FDE address size rules apply.
  6336. GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
  6337. section, where XX is the size of longs in bits. Unfortunately,
  6338. earlier compilers provided no way of distinguishing ILP32 objects
  6339. from LP64 objects, so if there's any doubt, we should assume that
  6340. the official LP64 form is being used. */
  6341. if ((filedata->file_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
  6342. && find_section (filedata, ".gcc_compiled_long32") == NULL)
  6343. eh_addr_size = 8;
  6344. break;
  6345. case EM_H8_300:
  6346. case EM_H8_300H:
  6347. switch (filedata->file_header.e_flags & EF_H8_MACH)
  6348. {
  6349. case E_H8_MACH_H8300:
  6350. case E_H8_MACH_H8300HN:
  6351. case E_H8_MACH_H8300SN:
  6352. case E_H8_MACH_H8300SXN:
  6353. eh_addr_size = 2;
  6354. break;
  6355. case E_H8_MACH_H8300H:
  6356. case E_H8_MACH_H8300S:
  6357. case E_H8_MACH_H8300SX:
  6358. eh_addr_size = 4;
  6359. break;
  6360. }
  6361. break;
  6362. case EM_M32C_OLD:
  6363. case EM_M32C:
  6364. switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK)
  6365. {
  6366. case EF_M32C_CPU_M16C:
  6367. eh_addr_size = 2;
  6368. break;
  6369. }
  6370. break;
  6371. }
  6372. #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
  6373. do \
  6374. { \
  6375. bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
  6376. if (section->sh_entsize != expected_entsize) \
  6377. { \
  6378. char buf[40]; \
  6379. sprintf_vma (buf, section->sh_entsize); \
  6380. /* Note: coded this way so that there is a single string for \
  6381. translation. */ \
  6382. error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
  6383. error (_("(Using the expected size of %u for the rest of this dump)\n"), \
  6384. (unsigned) expected_entsize); \
  6385. section->sh_entsize = expected_entsize; \
  6386. } \
  6387. } \
  6388. while (0)
  6389. #define CHECK_ENTSIZE(section, i, type) \
  6390. CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
  6391. sizeof (Elf64_External_##type))
  6392. for (i = 0, section = filedata->section_headers;
  6393. i < filedata->file_header.e_shnum;
  6394. i++, section++)
  6395. {
  6396. const char *name = section_name_print (filedata, section);
  6397. /* Run some sanity checks on the headers and
  6398. possibly fill in some file data as well. */
  6399. switch (section->sh_type)
  6400. {
  6401. case SHT_DYNSYM:
  6402. if (filedata->dynamic_symbols != NULL)
  6403. {
  6404. error (_("File contains multiple dynamic symbol tables\n"));
  6405. continue;
  6406. }
  6407. CHECK_ENTSIZE (section, i, Sym);
  6408. filedata->dynamic_symbols
  6409. = get_elf_symbols (filedata, section, &filedata->num_dynamic_syms);
  6410. filedata->dynamic_symtab_section = section;
  6411. break;
  6412. case SHT_STRTAB:
  6413. if (streq (name, ".dynstr"))
  6414. {
  6415. if (filedata->dynamic_strings != NULL)
  6416. {
  6417. error (_("File contains multiple dynamic string tables\n"));
  6418. continue;
  6419. }
  6420. filedata->dynamic_strings
  6421. = (char *) get_data (NULL, filedata, section->sh_offset,
  6422. 1, section->sh_size, _("dynamic strings"));
  6423. filedata->dynamic_strings_length
  6424. = filedata->dynamic_strings == NULL ? 0 : section->sh_size;
  6425. filedata->dynamic_strtab_section = section;
  6426. }
  6427. break;
  6428. case SHT_SYMTAB_SHNDX:
  6429. {
  6430. elf_section_list * entry = xmalloc (sizeof * entry);
  6431. entry->hdr = section;
  6432. entry->next = filedata->symtab_shndx_list;
  6433. filedata->symtab_shndx_list = entry;
  6434. }
  6435. break;
  6436. case SHT_SYMTAB:
  6437. CHECK_ENTSIZE (section, i, Sym);
  6438. break;
  6439. case SHT_GROUP:
  6440. CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
  6441. break;
  6442. case SHT_REL:
  6443. CHECK_ENTSIZE (section, i, Rel);
  6444. if (do_checks && section->sh_size == 0)
  6445. warn (_("Section '%s': zero-sized relocation section\n"), name);
  6446. break;
  6447. case SHT_RELA:
  6448. CHECK_ENTSIZE (section, i, Rela);
  6449. if (do_checks && section->sh_size == 0)
  6450. warn (_("Section '%s': zero-sized relocation section\n"), name);
  6451. break;
  6452. case SHT_RELR:
  6453. CHECK_ENTSIZE (section, i, Relr);
  6454. break;
  6455. case SHT_NOTE:
  6456. case SHT_PROGBITS:
  6457. /* Having a zero sized section is not illegal according to the
  6458. ELF standard, but it might be an indication that something
  6459. is wrong. So issue a warning if we are running in lint mode. */
  6460. if (do_checks && section->sh_size == 0)
  6461. warn (_("Section '%s': has a size of zero - is this intended ?\n"), name);
  6462. break;
  6463. default:
  6464. break;
  6465. }
  6466. if ((do_debugging || do_debug_info || do_debug_abbrevs
  6467. || do_debug_lines || do_debug_pubnames || do_debug_pubtypes
  6468. || do_debug_aranges || do_debug_frames || do_debug_macinfo
  6469. || do_debug_str || do_debug_str_offsets || do_debug_loc
  6470. || do_debug_ranges
  6471. || do_debug_addr || do_debug_cu_index || do_debug_links)
  6472. && (startswith (name, ".debug_")
  6473. || startswith (name, ".zdebug_")))
  6474. {
  6475. if (name[1] == 'z')
  6476. name += sizeof (".zdebug_") - 1;
  6477. else
  6478. name += sizeof (".debug_") - 1;
  6479. if (do_debugging
  6480. || (do_debug_info && startswith (name, "info"))
  6481. || (do_debug_info && startswith (name, "types"))
  6482. || (do_debug_abbrevs && startswith (name, "abbrev"))
  6483. || (do_debug_lines && strcmp (name, "line") == 0)
  6484. || (do_debug_lines && startswith (name, "line."))
  6485. || (do_debug_pubnames && startswith (name, "pubnames"))
  6486. || (do_debug_pubtypes && startswith (name, "pubtypes"))
  6487. || (do_debug_pubnames && startswith (name, "gnu_pubnames"))
  6488. || (do_debug_pubtypes && startswith (name, "gnu_pubtypes"))
  6489. || (do_debug_aranges && startswith (name, "aranges"))
  6490. || (do_debug_ranges && startswith (name, "ranges"))
  6491. || (do_debug_ranges && startswith (name, "rnglists"))
  6492. || (do_debug_frames && startswith (name, "frame"))
  6493. || (do_debug_macinfo && startswith (name, "macinfo"))
  6494. || (do_debug_macinfo && startswith (name, "macro"))
  6495. || (do_debug_str && startswith (name, "str"))
  6496. || (do_debug_links && startswith (name, "sup"))
  6497. || (do_debug_str_offsets && startswith (name, "str_offsets"))
  6498. || (do_debug_loc && startswith (name, "loc"))
  6499. || (do_debug_loc && startswith (name, "loclists"))
  6500. || (do_debug_addr && startswith (name, "addr"))
  6501. || (do_debug_cu_index && startswith (name, "cu_index"))
  6502. || (do_debug_cu_index && startswith (name, "tu_index"))
  6503. )
  6504. request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
  6505. }
  6506. /* Linkonce section to be combined with .debug_info at link time. */
  6507. else if ((do_debugging || do_debug_info)
  6508. && startswith (name, ".gnu.linkonce.wi."))
  6509. request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
  6510. else if (do_debug_frames && streq (name, ".eh_frame"))
  6511. request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
  6512. else if (do_gdb_index && (streq (name, ".gdb_index")
  6513. || streq (name, ".debug_names")))
  6514. request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
  6515. /* Trace sections for Itanium VMS. */
  6516. else if ((do_debugging || do_trace_info || do_trace_abbrevs
  6517. || do_trace_aranges)
  6518. && startswith (name, ".trace_"))
  6519. {
  6520. name += sizeof (".trace_") - 1;
  6521. if (do_debugging
  6522. || (do_trace_info && streq (name, "info"))
  6523. || (do_trace_abbrevs && streq (name, "abbrev"))
  6524. || (do_trace_aranges && streq (name, "aranges"))
  6525. )
  6526. request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
  6527. }
  6528. else if ((do_debugging || do_debug_links)
  6529. && (startswith (name, ".gnu_debuglink")
  6530. || startswith (name, ".gnu_debugaltlink")))
  6531. request_dump_bynumber (&filedata->dump, i, DEBUG_DUMP);
  6532. }
  6533. if (! do_sections)
  6534. return true;
  6535. if (filedata->is_separate && ! process_links)
  6536. return true;
  6537. if (filedata->is_separate)
  6538. printf (_("\nSection Headers in linked file '%s':\n"), filedata->file_name);
  6539. else if (filedata->file_header.e_shnum > 1)
  6540. printf (_("\nSection Headers:\n"));
  6541. else
  6542. printf (_("\nSection Header:\n"));
  6543. if (is_32bit_elf)
  6544. {
  6545. if (do_section_details)
  6546. {
  6547. printf (_(" [Nr] Name\n"));
  6548. printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
  6549. }
  6550. else
  6551. printf
  6552. (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
  6553. }
  6554. else if (do_wide)
  6555. {
  6556. if (do_section_details)
  6557. {
  6558. printf (_(" [Nr] Name\n"));
  6559. printf (_(" Type Address Off Size ES Lk Inf Al\n"));
  6560. }
  6561. else
  6562. printf
  6563. (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
  6564. }
  6565. else
  6566. {
  6567. if (do_section_details)
  6568. {
  6569. printf (_(" [Nr] Name\n"));
  6570. printf (_(" Type Address Offset Link\n"));
  6571. printf (_(" Size EntSize Info Align\n"));
  6572. }
  6573. else
  6574. {
  6575. printf (_(" [Nr] Name Type Address Offset\n"));
  6576. printf (_(" Size EntSize Flags Link Info Align\n"));
  6577. }
  6578. }
  6579. if (do_section_details)
  6580. printf (_(" Flags\n"));
  6581. for (i = 0, section = filedata->section_headers;
  6582. i < filedata->file_header.e_shnum;
  6583. i++, section++)
  6584. {
  6585. /* Run some sanity checks on the section header. */
  6586. /* Check the sh_link field. */
  6587. switch (section->sh_type)
  6588. {
  6589. case SHT_REL:
  6590. case SHT_RELA:
  6591. if (section->sh_link == 0
  6592. && (filedata->file_header.e_type == ET_EXEC
  6593. || filedata->file_header.e_type == ET_DYN))
  6594. /* A dynamic relocation section where all entries use a
  6595. zero symbol index need not specify a symtab section. */
  6596. break;
  6597. /* Fall through. */
  6598. case SHT_SYMTAB_SHNDX:
  6599. case SHT_GROUP:
  6600. case SHT_HASH:
  6601. case SHT_GNU_HASH:
  6602. case SHT_GNU_versym:
  6603. if (section->sh_link == 0
  6604. || section->sh_link >= filedata->file_header.e_shnum
  6605. || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB
  6606. && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM))
  6607. warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
  6608. i, section->sh_link);
  6609. break;
  6610. case SHT_DYNAMIC:
  6611. case SHT_SYMTAB:
  6612. case SHT_DYNSYM:
  6613. case SHT_GNU_verneed:
  6614. case SHT_GNU_verdef:
  6615. case SHT_GNU_LIBLIST:
  6616. if (section->sh_link == 0
  6617. || section->sh_link >= filedata->file_header.e_shnum
  6618. || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB)
  6619. warn (_("[%2u]: Link field (%u) should index a string section.\n"),
  6620. i, section->sh_link);
  6621. break;
  6622. case SHT_INIT_ARRAY:
  6623. case SHT_FINI_ARRAY:
  6624. case SHT_PREINIT_ARRAY:
  6625. if (section->sh_type < SHT_LOOS && section->sh_link != 0)
  6626. warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
  6627. i, section->sh_link);
  6628. break;
  6629. default:
  6630. /* FIXME: Add support for target specific section types. */
  6631. #if 0 /* Currently we do not check other section types as there are too
  6632. many special cases. Stab sections for example have a type
  6633. of SHT_PROGBITS but an sh_link field that links to the .stabstr
  6634. section. */
  6635. if (section->sh_type < SHT_LOOS && section->sh_link != 0)
  6636. warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
  6637. i, section->sh_link);
  6638. #endif
  6639. break;
  6640. }
  6641. /* Check the sh_info field. */
  6642. switch (section->sh_type)
  6643. {
  6644. case SHT_REL:
  6645. case SHT_RELA:
  6646. if (section->sh_info == 0
  6647. && (filedata->file_header.e_type == ET_EXEC
  6648. || filedata->file_header.e_type == ET_DYN))
  6649. /* Dynamic relocations apply to segments, so they do not
  6650. need to specify the section they relocate. */
  6651. break;
  6652. if (section->sh_info == 0
  6653. || section->sh_info >= filedata->file_header.e_shnum
  6654. || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS
  6655. && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS
  6656. && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE
  6657. && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY
  6658. && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY
  6659. && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY
  6660. /* FIXME: Are other section types valid ? */
  6661. && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS))
  6662. warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
  6663. i, section->sh_info);
  6664. break;
  6665. case SHT_DYNAMIC:
  6666. case SHT_HASH:
  6667. case SHT_SYMTAB_SHNDX:
  6668. case SHT_INIT_ARRAY:
  6669. case SHT_FINI_ARRAY:
  6670. case SHT_PREINIT_ARRAY:
  6671. if (section->sh_info != 0)
  6672. warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
  6673. i, section->sh_info);
  6674. break;
  6675. case SHT_GROUP:
  6676. case SHT_SYMTAB:
  6677. case SHT_DYNSYM:
  6678. /* A symbol index - we assume that it is valid. */
  6679. break;
  6680. default:
  6681. /* FIXME: Add support for target specific section types. */
  6682. if (section->sh_type == SHT_NOBITS)
  6683. /* NOBITS section headers with non-zero sh_info fields can be
  6684. created when a binary is stripped of everything but its debug
  6685. information. The stripped sections have their headers
  6686. preserved but their types set to SHT_NOBITS. So do not check
  6687. this type of section. */
  6688. ;
  6689. else if (section->sh_flags & SHF_INFO_LINK)
  6690. {
  6691. if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum)
  6692. warn (_("[%2u]: Expected link to another section in info field"), i);
  6693. }
  6694. else if (section->sh_type < SHT_LOOS
  6695. && (section->sh_flags & SHF_GNU_MBIND) == 0
  6696. && section->sh_info != 0)
  6697. warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
  6698. i, section->sh_info);
  6699. break;
  6700. }
  6701. /* Check the sh_size field. */
  6702. if (section->sh_size > filedata->file_size
  6703. && section->sh_type != SHT_NOBITS
  6704. && section->sh_type != SHT_NULL
  6705. && section->sh_type < SHT_LOOS)
  6706. warn (_("Size of section %u is larger than the entire file!\n"), i);
  6707. printf (" [%2u] ", i);
  6708. if (do_section_details)
  6709. printf ("%s\n ", printable_section_name (filedata, section));
  6710. else
  6711. print_symbol (-17, section_name_print (filedata, section));
  6712. printf (do_wide ? " %-15s " : " %-15.15s ",
  6713. get_section_type_name (filedata, section->sh_type));
  6714. if (is_32bit_elf)
  6715. {
  6716. const char * link_too_big = NULL;
  6717. print_vma (section->sh_addr, LONG_HEX);
  6718. printf ( " %6.6lx %6.6lx %2.2lx",
  6719. (unsigned long) section->sh_offset,
  6720. (unsigned long) section->sh_size,
  6721. (unsigned long) section->sh_entsize);
  6722. if (do_section_details)
  6723. fputs (" ", stdout);
  6724. else
  6725. printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
  6726. if (section->sh_link >= filedata->file_header.e_shnum)
  6727. {
  6728. link_too_big = "";
  6729. /* The sh_link value is out of range. Normally this indicates
  6730. an error but it can have special values in Solaris binaries. */
  6731. switch (filedata->file_header.e_machine)
  6732. {
  6733. case EM_386:
  6734. case EM_IAMCU:
  6735. case EM_X86_64:
  6736. case EM_L1OM:
  6737. case EM_K1OM:
  6738. case EM_OLD_SPARCV9:
  6739. case EM_SPARC32PLUS:
  6740. case EM_SPARCV9:
  6741. case EM_SPARC:
  6742. if (section->sh_link == (SHN_BEFORE & 0xffff))
  6743. link_too_big = "BEFORE";
  6744. else if (section->sh_link == (SHN_AFTER & 0xffff))
  6745. link_too_big = "AFTER";
  6746. break;
  6747. default:
  6748. break;
  6749. }
  6750. }
  6751. if (do_section_details)
  6752. {
  6753. if (link_too_big != NULL && * link_too_big)
  6754. printf ("<%s> ", link_too_big);
  6755. else
  6756. printf ("%2u ", section->sh_link);
  6757. printf ("%3u %2lu\n", section->sh_info,
  6758. (unsigned long) section->sh_addralign);
  6759. }
  6760. else
  6761. printf ("%2u %3u %2lu\n",
  6762. section->sh_link,
  6763. section->sh_info,
  6764. (unsigned long) section->sh_addralign);
  6765. if (link_too_big && ! * link_too_big)
  6766. warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
  6767. i, section->sh_link);
  6768. }
  6769. else if (do_wide)
  6770. {
  6771. print_vma (section->sh_addr, LONG_HEX);
  6772. if ((long) section->sh_offset == section->sh_offset)
  6773. printf (" %6.6lx", (unsigned long) section->sh_offset);
  6774. else
  6775. {
  6776. putchar (' ');
  6777. print_vma (section->sh_offset, LONG_HEX);
  6778. }
  6779. if ((unsigned long) section->sh_size == section->sh_size)
  6780. printf (" %6.6lx", (unsigned long) section->sh_size);
  6781. else
  6782. {
  6783. putchar (' ');
  6784. print_vma (section->sh_size, LONG_HEX);
  6785. }
  6786. if ((unsigned long) section->sh_entsize == section->sh_entsize)
  6787. printf (" %2.2lx", (unsigned long) section->sh_entsize);
  6788. else
  6789. {
  6790. putchar (' ');
  6791. print_vma (section->sh_entsize, LONG_HEX);
  6792. }
  6793. if (do_section_details)
  6794. fputs (" ", stdout);
  6795. else
  6796. printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
  6797. printf ("%2u %3u ", section->sh_link, section->sh_info);
  6798. if ((unsigned long) section->sh_addralign == section->sh_addralign)
  6799. printf ("%2lu\n", (unsigned long) section->sh_addralign);
  6800. else
  6801. {
  6802. print_vma (section->sh_addralign, DEC);
  6803. putchar ('\n');
  6804. }
  6805. }
  6806. else if (do_section_details)
  6807. {
  6808. putchar (' ');
  6809. print_vma (section->sh_addr, LONG_HEX);
  6810. if ((long) section->sh_offset == section->sh_offset)
  6811. printf (" %16.16lx", (unsigned long) section->sh_offset);
  6812. else
  6813. {
  6814. printf (" ");
  6815. print_vma (section->sh_offset, LONG_HEX);
  6816. }
  6817. printf (" %u\n ", section->sh_link);
  6818. print_vma (section->sh_size, LONG_HEX);
  6819. putchar (' ');
  6820. print_vma (section->sh_entsize, LONG_HEX);
  6821. printf (" %-16u %lu\n",
  6822. section->sh_info,
  6823. (unsigned long) section->sh_addralign);
  6824. }
  6825. else
  6826. {
  6827. putchar (' ');
  6828. print_vma (section->sh_addr, LONG_HEX);
  6829. if ((long) section->sh_offset == section->sh_offset)
  6830. printf (" %8.8lx", (unsigned long) section->sh_offset);
  6831. else
  6832. {
  6833. printf (" ");
  6834. print_vma (section->sh_offset, LONG_HEX);
  6835. }
  6836. printf ("\n ");
  6837. print_vma (section->sh_size, LONG_HEX);
  6838. printf (" ");
  6839. print_vma (section->sh_entsize, LONG_HEX);
  6840. printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags));
  6841. printf (" %2u %3u %lu\n",
  6842. section->sh_link,
  6843. section->sh_info,
  6844. (unsigned long) section->sh_addralign);
  6845. }
  6846. if (do_section_details)
  6847. {
  6848. printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags));
  6849. if ((section->sh_flags & SHF_COMPRESSED) != 0)
  6850. {
  6851. /* Minimum section size is 12 bytes for 32-bit compression
  6852. header + 12 bytes for compressed data header. */
  6853. unsigned char buf[24];
  6854. assert (sizeof (buf) >= sizeof (Elf64_External_Chdr));
  6855. if (get_data (&buf, filedata, section->sh_offset, 1,
  6856. sizeof (buf), _("compression header")))
  6857. {
  6858. Elf_Internal_Chdr chdr;
  6859. if (get_compression_header (&chdr, buf, sizeof (buf)) == 0)
  6860. printf (_(" [<corrupt>]\n"));
  6861. else
  6862. {
  6863. if (chdr.ch_type == ELFCOMPRESS_ZLIB)
  6864. printf (" ZLIB, ");
  6865. else
  6866. printf (_(" [<unknown>: 0x%x], "),
  6867. chdr.ch_type);
  6868. print_vma (chdr.ch_size, LONG_HEX);
  6869. printf (", %lu\n", (unsigned long) chdr.ch_addralign);
  6870. }
  6871. }
  6872. }
  6873. }
  6874. }
  6875. if (!do_section_details)
  6876. {
  6877. /* The ordering of the letters shown here matches the ordering of the
  6878. corresponding SHF_xxx values, and hence the order in which these
  6879. letters will be displayed to the user. */
  6880. printf (_("Key to Flags:\n\
  6881. W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
  6882. L (link order), O (extra OS processing required), G (group), T (TLS),\n\
  6883. C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
  6884. switch (filedata->file_header.e_ident[EI_OSABI])
  6885. {
  6886. case ELFOSABI_GNU:
  6887. case ELFOSABI_FREEBSD:
  6888. printf (_("R (retain), "));
  6889. /* Fall through */
  6890. case ELFOSABI_NONE:
  6891. printf (_("D (mbind), "));
  6892. break;
  6893. default:
  6894. break;
  6895. }
  6896. if (filedata->file_header.e_machine == EM_X86_64
  6897. || filedata->file_header.e_machine == EM_L1OM
  6898. || filedata->file_header.e_machine == EM_K1OM)
  6899. printf (_("l (large), "));
  6900. else if (filedata->file_header.e_machine == EM_ARM)
  6901. printf (_("y (purecode), "));
  6902. else if (filedata->file_header.e_machine == EM_PPC)
  6903. printf (_("v (VLE), "));
  6904. printf ("p (processor specific)\n");
  6905. }
  6906. return true;
  6907. }
  6908. static bool
  6909. get_symtab (Filedata *filedata, Elf_Internal_Shdr *symsec,
  6910. Elf_Internal_Sym **symtab, unsigned long *nsyms,
  6911. char **strtab, unsigned long *strtablen)
  6912. {
  6913. *strtab = NULL;
  6914. *strtablen = 0;
  6915. *symtab = get_elf_symbols (filedata, symsec, nsyms);
  6916. if (*symtab == NULL)
  6917. return false;
  6918. if (symsec->sh_link != 0)
  6919. {
  6920. Elf_Internal_Shdr *strsec;
  6921. if (symsec->sh_link >= filedata->file_header.e_shnum)
  6922. {
  6923. error (_("Bad sh_link in symbol table section\n"));
  6924. free (*symtab);
  6925. *symtab = NULL;
  6926. *nsyms = 0;
  6927. return false;
  6928. }
  6929. strsec = filedata->section_headers + symsec->sh_link;
  6930. *strtab = (char *) get_data (NULL, filedata, strsec->sh_offset,
  6931. 1, strsec->sh_size, _("string table"));
  6932. if (*strtab == NULL)
  6933. {
  6934. free (*symtab);
  6935. *symtab = NULL;
  6936. *nsyms = 0;
  6937. return false;
  6938. }
  6939. *strtablen = strsec->sh_size;
  6940. }
  6941. return true;
  6942. }
  6943. static const char *
  6944. get_group_flags (unsigned int flags)
  6945. {
  6946. static char buff[128];
  6947. if (flags == 0)
  6948. return "";
  6949. else if (flags == GRP_COMDAT)
  6950. return "COMDAT ";
  6951. snprintf (buff, sizeof buff, "[0x%x: %s%s%s]",
  6952. flags,
  6953. flags & GRP_MASKOS ? _("<OS specific>") : "",
  6954. flags & GRP_MASKPROC ? _("<PROC specific>") : "",
  6955. (flags & ~(GRP_COMDAT | GRP_MASKOS | GRP_MASKPROC)
  6956. ? _("<unknown>") : ""));
  6957. return buff;
  6958. }
  6959. static bool
  6960. process_section_groups (Filedata * filedata)
  6961. {
  6962. Elf_Internal_Shdr * section;
  6963. unsigned int i;
  6964. struct group * group;
  6965. Elf_Internal_Shdr * symtab_sec;
  6966. Elf_Internal_Shdr * strtab_sec;
  6967. Elf_Internal_Sym * symtab;
  6968. unsigned long num_syms;
  6969. char * strtab;
  6970. size_t strtab_size;
  6971. /* Don't process section groups unless needed. */
  6972. if (!do_unwind && !do_section_groups)
  6973. return true;
  6974. if (filedata->file_header.e_shnum == 0)
  6975. {
  6976. if (do_section_groups)
  6977. {
  6978. if (filedata->is_separate)
  6979. printf (_("\nThere are no sections group in linked file '%s'.\n"),
  6980. filedata->file_name);
  6981. else
  6982. printf (_("\nThere are no section groups in this file.\n"));
  6983. }
  6984. return true;
  6985. }
  6986. if (filedata->section_headers == NULL)
  6987. {
  6988. error (_("Section headers are not available!\n"));
  6989. /* PR 13622: This can happen with a corrupt ELF header. */
  6990. return false;
  6991. }
  6992. filedata->section_headers_groups
  6993. = (struct group **) calloc (filedata->file_header.e_shnum,
  6994. sizeof (struct group *));
  6995. if (filedata->section_headers_groups == NULL)
  6996. {
  6997. error (_("Out of memory reading %u section group headers\n"),
  6998. filedata->file_header.e_shnum);
  6999. return false;
  7000. }
  7001. /* Scan the sections for the group section. */
  7002. filedata->group_count = 0;
  7003. for (i = 0, section = filedata->section_headers;
  7004. i < filedata->file_header.e_shnum;
  7005. i++, section++)
  7006. if (section->sh_type == SHT_GROUP)
  7007. filedata->group_count++;
  7008. if (filedata->group_count == 0)
  7009. {
  7010. if (do_section_groups)
  7011. {
  7012. if (filedata->is_separate)
  7013. printf (_("\nThere are no section groups in linked file '%s'.\n"),
  7014. filedata->file_name);
  7015. else
  7016. printf (_("\nThere are no section groups in this file.\n"));
  7017. }
  7018. return true;
  7019. }
  7020. filedata->section_groups = (struct group *) calloc (filedata->group_count,
  7021. sizeof (struct group));
  7022. if (filedata->section_groups == NULL)
  7023. {
  7024. error (_("Out of memory reading %lu groups\n"),
  7025. (unsigned long) filedata->group_count);
  7026. return false;
  7027. }
  7028. symtab_sec = NULL;
  7029. strtab_sec = NULL;
  7030. symtab = NULL;
  7031. num_syms = 0;
  7032. strtab = NULL;
  7033. strtab_size = 0;
  7034. if (filedata->is_separate)
  7035. printf (_("Section groups in linked file '%s'\n"), filedata->file_name);
  7036. for (i = 0, section = filedata->section_headers, group = filedata->section_groups;
  7037. i < filedata->file_header.e_shnum;
  7038. i++, section++)
  7039. {
  7040. if (section->sh_type == SHT_GROUP)
  7041. {
  7042. const char * name = printable_section_name (filedata, section);
  7043. const char * group_name;
  7044. unsigned char * start;
  7045. unsigned char * indices;
  7046. unsigned int entry, j, size;
  7047. Elf_Internal_Shdr * sec;
  7048. Elf_Internal_Sym * sym;
  7049. /* Get the symbol table. */
  7050. if (section->sh_link >= filedata->file_header.e_shnum
  7051. || ((sec = filedata->section_headers + section->sh_link)->sh_type
  7052. != SHT_SYMTAB))
  7053. {
  7054. error (_("Bad sh_link in group section `%s'\n"), name);
  7055. continue;
  7056. }
  7057. if (symtab_sec != sec)
  7058. {
  7059. symtab_sec = sec;
  7060. free (symtab);
  7061. symtab = get_elf_symbols (filedata, symtab_sec, & num_syms);
  7062. }
  7063. if (symtab == NULL)
  7064. {
  7065. error (_("Corrupt header in group section `%s'\n"), name);
  7066. continue;
  7067. }
  7068. if (section->sh_info >= num_syms)
  7069. {
  7070. error (_("Bad sh_info in group section `%s'\n"), name);
  7071. continue;
  7072. }
  7073. sym = symtab + section->sh_info;
  7074. if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
  7075. {
  7076. if (sym->st_shndx == 0
  7077. || sym->st_shndx >= filedata->file_header.e_shnum)
  7078. {
  7079. error (_("Bad sh_info in group section `%s'\n"), name);
  7080. continue;
  7081. }
  7082. group_name = section_name_print (filedata,
  7083. filedata->section_headers
  7084. + sym->st_shndx);
  7085. strtab_sec = NULL;
  7086. free (strtab);
  7087. strtab = NULL;
  7088. strtab_size = 0;
  7089. }
  7090. else
  7091. {
  7092. /* Get the string table. */
  7093. if (symtab_sec->sh_link >= filedata->file_header.e_shnum)
  7094. {
  7095. strtab_sec = NULL;
  7096. free (strtab);
  7097. strtab = NULL;
  7098. strtab_size = 0;
  7099. }
  7100. else if (strtab_sec
  7101. != (sec = filedata->section_headers + symtab_sec->sh_link))
  7102. {
  7103. strtab_sec = sec;
  7104. free (strtab);
  7105. strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset,
  7106. 1, strtab_sec->sh_size,
  7107. _("string table"));
  7108. strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
  7109. }
  7110. group_name = sym->st_name < strtab_size
  7111. ? strtab + sym->st_name : _("<corrupt>");
  7112. }
  7113. /* PR 17531: file: loop. */
  7114. if (section->sh_entsize > section->sh_size)
  7115. {
  7116. error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
  7117. printable_section_name (filedata, section),
  7118. (unsigned long) section->sh_entsize,
  7119. (unsigned long) section->sh_size);
  7120. continue;
  7121. }
  7122. start = (unsigned char *) get_data (NULL, filedata, section->sh_offset,
  7123. 1, section->sh_size,
  7124. _("section data"));
  7125. if (start == NULL)
  7126. continue;
  7127. indices = start;
  7128. size = (section->sh_size / section->sh_entsize) - 1;
  7129. entry = byte_get (indices, 4);
  7130. indices += 4;
  7131. if (do_section_groups)
  7132. {
  7133. printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
  7134. get_group_flags (entry), i, name, group_name, size);
  7135. printf (_(" [Index] Name\n"));
  7136. }
  7137. group->group_index = i;
  7138. for (j = 0; j < size; j++)
  7139. {
  7140. struct group_list * g;
  7141. entry = byte_get (indices, 4);
  7142. indices += 4;
  7143. if (entry >= filedata->file_header.e_shnum)
  7144. {
  7145. static unsigned num_group_errors = 0;
  7146. if (num_group_errors ++ < 10)
  7147. {
  7148. error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
  7149. entry, i, filedata->file_header.e_shnum - 1);
  7150. if (num_group_errors == 10)
  7151. warn (_("Further error messages about overlarge group section indices suppressed\n"));
  7152. }
  7153. continue;
  7154. }
  7155. if (filedata->section_headers_groups [entry] != NULL)
  7156. {
  7157. if (entry)
  7158. {
  7159. static unsigned num_errs = 0;
  7160. if (num_errs ++ < 10)
  7161. {
  7162. error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
  7163. entry, i,
  7164. filedata->section_headers_groups [entry]->group_index);
  7165. if (num_errs == 10)
  7166. warn (_("Further error messages about already contained group sections suppressed\n"));
  7167. }
  7168. continue;
  7169. }
  7170. else
  7171. {
  7172. /* Intel C/C++ compiler may put section 0 in a
  7173. section group. We just warn it the first time
  7174. and ignore it afterwards. */
  7175. static bool warned = false;
  7176. if (!warned)
  7177. {
  7178. error (_("section 0 in group section [%5u]\n"),
  7179. filedata->section_headers_groups [entry]->group_index);
  7180. warned = true;
  7181. }
  7182. }
  7183. }
  7184. filedata->section_headers_groups [entry] = group;
  7185. if (do_section_groups)
  7186. {
  7187. sec = filedata->section_headers + entry;
  7188. printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec));
  7189. }
  7190. g = (struct group_list *) xmalloc (sizeof (struct group_list));
  7191. g->section_index = entry;
  7192. g->next = group->root;
  7193. group->root = g;
  7194. }
  7195. free (start);
  7196. group++;
  7197. }
  7198. }
  7199. free (symtab);
  7200. free (strtab);
  7201. return true;
  7202. }
  7203. /* Data used to display dynamic fixups. */
  7204. struct ia64_vms_dynfixup
  7205. {
  7206. bfd_vma needed_ident; /* Library ident number. */
  7207. bfd_vma needed; /* Index in the dstrtab of the library name. */
  7208. bfd_vma fixup_needed; /* Index of the library. */
  7209. bfd_vma fixup_rela_cnt; /* Number of fixups. */
  7210. bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */
  7211. };
  7212. /* Data used to display dynamic relocations. */
  7213. struct ia64_vms_dynimgrela
  7214. {
  7215. bfd_vma img_rela_cnt; /* Number of relocations. */
  7216. bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */
  7217. };
  7218. /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
  7219. library). */
  7220. static bool
  7221. dump_ia64_vms_dynamic_fixups (Filedata * filedata,
  7222. struct ia64_vms_dynfixup * fixup,
  7223. const char * strtab,
  7224. unsigned int strtab_sz)
  7225. {
  7226. Elf64_External_VMS_IMAGE_FIXUP * imfs;
  7227. long i;
  7228. const char * lib_name;
  7229. imfs = get_data (NULL, filedata,
  7230. filedata->dynamic_addr + fixup->fixup_rela_off,
  7231. sizeof (*imfs), fixup->fixup_rela_cnt,
  7232. _("dynamic section image fixups"));
  7233. if (!imfs)
  7234. return false;
  7235. if (fixup->needed < strtab_sz)
  7236. lib_name = strtab + fixup->needed;
  7237. else
  7238. {
  7239. warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
  7240. (unsigned long) fixup->needed);
  7241. lib_name = "???";
  7242. }
  7243. printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
  7244. (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
  7245. printf
  7246. (_("Seg Offset Type SymVec DataType\n"));
  7247. for (i = 0; i < (long) fixup->fixup_rela_cnt; i++)
  7248. {
  7249. unsigned int type;
  7250. const char *rtype;
  7251. printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
  7252. printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
  7253. type = BYTE_GET (imfs [i].type);
  7254. rtype = elf_ia64_reloc_type (type);
  7255. if (rtype == NULL)
  7256. printf (" 0x%08x ", type);
  7257. else
  7258. printf (" %-32s ", rtype);
  7259. printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
  7260. printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
  7261. }
  7262. free (imfs);
  7263. return true;
  7264. }
  7265. /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
  7266. static bool
  7267. dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela)
  7268. {
  7269. Elf64_External_VMS_IMAGE_RELA *imrs;
  7270. long i;
  7271. imrs = get_data (NULL, filedata,
  7272. filedata->dynamic_addr + imgrela->img_rela_off,
  7273. sizeof (*imrs), imgrela->img_rela_cnt,
  7274. _("dynamic section image relocations"));
  7275. if (!imrs)
  7276. return false;
  7277. printf (_("\nImage relocs\n"));
  7278. printf
  7279. (_("Seg Offset Type Addend Seg Sym Off\n"));
  7280. for (i = 0; i < (long) imgrela->img_rela_cnt; i++)
  7281. {
  7282. unsigned int type;
  7283. const char *rtype;
  7284. printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg));
  7285. printf ("%08" BFD_VMA_FMT "x ",
  7286. (bfd_vma) BYTE_GET (imrs [i].rela_offset));
  7287. type = BYTE_GET (imrs [i].type);
  7288. rtype = elf_ia64_reloc_type (type);
  7289. if (rtype == NULL)
  7290. printf ("0x%08x ", type);
  7291. else
  7292. printf ("%-31s ", rtype);
  7293. print_vma (BYTE_GET (imrs [i].addend), FULL_HEX);
  7294. printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg));
  7295. printf ("%08" BFD_VMA_FMT "x\n",
  7296. (bfd_vma) BYTE_GET (imrs [i].sym_offset));
  7297. }
  7298. free (imrs);
  7299. return true;
  7300. }
  7301. /* Display IA-64 OpenVMS dynamic relocations and fixups. */
  7302. static bool
  7303. process_ia64_vms_dynamic_relocs (Filedata * filedata)
  7304. {
  7305. struct ia64_vms_dynfixup fixup;
  7306. struct ia64_vms_dynimgrela imgrela;
  7307. Elf_Internal_Dyn *entry;
  7308. bfd_vma strtab_off = 0;
  7309. bfd_vma strtab_sz = 0;
  7310. char *strtab = NULL;
  7311. bool res = true;
  7312. memset (&fixup, 0, sizeof (fixup));
  7313. memset (&imgrela, 0, sizeof (imgrela));
  7314. /* Note: the order of the entries is specified by the OpenVMS specs. */
  7315. for (entry = filedata->dynamic_section;
  7316. entry < filedata->dynamic_section + filedata->dynamic_nent;
  7317. entry++)
  7318. {
  7319. switch (entry->d_tag)
  7320. {
  7321. case DT_IA_64_VMS_STRTAB_OFFSET:
  7322. strtab_off = entry->d_un.d_val;
  7323. break;
  7324. case DT_STRSZ:
  7325. strtab_sz = entry->d_un.d_val;
  7326. if (strtab == NULL)
  7327. strtab = get_data (NULL, filedata,
  7328. filedata->dynamic_addr + strtab_off,
  7329. 1, strtab_sz, _("dynamic string section"));
  7330. if (strtab == NULL)
  7331. strtab_sz = 0;
  7332. break;
  7333. case DT_IA_64_VMS_NEEDED_IDENT:
  7334. fixup.needed_ident = entry->d_un.d_val;
  7335. break;
  7336. case DT_NEEDED:
  7337. fixup.needed = entry->d_un.d_val;
  7338. break;
  7339. case DT_IA_64_VMS_FIXUP_NEEDED:
  7340. fixup.fixup_needed = entry->d_un.d_val;
  7341. break;
  7342. case DT_IA_64_VMS_FIXUP_RELA_CNT:
  7343. fixup.fixup_rela_cnt = entry->d_un.d_val;
  7344. break;
  7345. case DT_IA_64_VMS_FIXUP_RELA_OFF:
  7346. fixup.fixup_rela_off = entry->d_un.d_val;
  7347. if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz))
  7348. res = false;
  7349. break;
  7350. case DT_IA_64_VMS_IMG_RELA_CNT:
  7351. imgrela.img_rela_cnt = entry->d_un.d_val;
  7352. break;
  7353. case DT_IA_64_VMS_IMG_RELA_OFF:
  7354. imgrela.img_rela_off = entry->d_un.d_val;
  7355. if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela))
  7356. res = false;
  7357. break;
  7358. default:
  7359. break;
  7360. }
  7361. }
  7362. free (strtab);
  7363. return res;
  7364. }
  7365. static struct
  7366. {
  7367. const char * name;
  7368. int reloc;
  7369. int size;
  7370. relocation_type rel_type;
  7371. }
  7372. dynamic_relocations [] =
  7373. {
  7374. { "REL", DT_REL, DT_RELSZ, reltype_rel },
  7375. { "RELA", DT_RELA, DT_RELASZ, reltype_rela },
  7376. { "RELR", DT_RELR, DT_RELRSZ, reltype_relr },
  7377. { "PLT", DT_JMPREL, DT_PLTRELSZ, reltype_unknown }
  7378. };
  7379. /* Process the reloc section. */
  7380. static bool
  7381. process_relocs (Filedata * filedata)
  7382. {
  7383. unsigned long rel_size;
  7384. unsigned long rel_offset;
  7385. if (!do_reloc)
  7386. return true;
  7387. if (do_using_dynamic)
  7388. {
  7389. relocation_type rel_type;
  7390. const char * name;
  7391. bool has_dynamic_reloc;
  7392. unsigned int i;
  7393. has_dynamic_reloc = false;
  7394. for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
  7395. {
  7396. rel_type = dynamic_relocations [i].rel_type;
  7397. name = dynamic_relocations [i].name;
  7398. rel_size = filedata->dynamic_info[dynamic_relocations [i].size];
  7399. rel_offset = filedata->dynamic_info[dynamic_relocations [i].reloc];
  7400. if (rel_size)
  7401. has_dynamic_reloc = true;
  7402. if (rel_type == reltype_unknown)
  7403. {
  7404. if (dynamic_relocations [i].reloc == DT_JMPREL)
  7405. switch (filedata->dynamic_info[DT_PLTREL])
  7406. {
  7407. case DT_REL:
  7408. rel_type = reltype_rel;
  7409. break;
  7410. case DT_RELA:
  7411. rel_type = reltype_rela;
  7412. break;
  7413. }
  7414. }
  7415. if (rel_size)
  7416. {
  7417. if (filedata->is_separate)
  7418. printf
  7419. (_("\nIn linked file '%s' section '%s' at offset 0x%lx contains %ld bytes:\n"),
  7420. filedata->file_name, name, rel_offset, rel_size);
  7421. else
  7422. printf
  7423. (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
  7424. name, rel_offset, rel_size);
  7425. dump_relocations (filedata,
  7426. offset_from_vma (filedata, rel_offset, rel_size),
  7427. rel_size,
  7428. filedata->dynamic_symbols,
  7429. filedata->num_dynamic_syms,
  7430. filedata->dynamic_strings,
  7431. filedata->dynamic_strings_length,
  7432. rel_type, true /* is_dynamic */);
  7433. }
  7434. }
  7435. if (is_ia64_vms (filedata))
  7436. if (process_ia64_vms_dynamic_relocs (filedata))
  7437. has_dynamic_reloc = true;
  7438. if (! has_dynamic_reloc)
  7439. {
  7440. if (filedata->is_separate)
  7441. printf (_("\nThere are no dynamic relocations in linked file '%s'.\n"),
  7442. filedata->file_name);
  7443. else
  7444. printf (_("\nThere are no dynamic relocations in this file.\n"));
  7445. }
  7446. }
  7447. else
  7448. {
  7449. Elf_Internal_Shdr * section;
  7450. unsigned long i;
  7451. bool found = false;
  7452. for (i = 0, section = filedata->section_headers;
  7453. i < filedata->file_header.e_shnum;
  7454. i++, section++)
  7455. {
  7456. if ( section->sh_type != SHT_RELA
  7457. && section->sh_type != SHT_REL
  7458. && section->sh_type != SHT_RELR)
  7459. continue;
  7460. rel_offset = section->sh_offset;
  7461. rel_size = section->sh_size;
  7462. if (rel_size)
  7463. {
  7464. relocation_type rel_type;
  7465. unsigned long num_rela;
  7466. if (filedata->is_separate)
  7467. printf (_("\nIn linked file '%s' relocation section "),
  7468. filedata->file_name);
  7469. else
  7470. printf (_("\nRelocation section "));
  7471. if (filedata->string_table == NULL)
  7472. printf ("%d", section->sh_name);
  7473. else
  7474. printf ("'%s'", printable_section_name (filedata, section));
  7475. num_rela = rel_size / section->sh_entsize;
  7476. printf (ngettext (" at offset 0x%lx contains %lu entry:\n",
  7477. " at offset 0x%lx contains %lu entries:\n",
  7478. num_rela),
  7479. rel_offset, num_rela);
  7480. rel_type = section->sh_type == SHT_RELA ? reltype_rela :
  7481. section->sh_type == SHT_REL ? reltype_rel : reltype_relr;
  7482. if (section->sh_link != 0
  7483. && section->sh_link < filedata->file_header.e_shnum)
  7484. {
  7485. Elf_Internal_Shdr * symsec;
  7486. Elf_Internal_Sym * symtab;
  7487. unsigned long nsyms;
  7488. unsigned long strtablen = 0;
  7489. char * strtab = NULL;
  7490. symsec = filedata->section_headers + section->sh_link;
  7491. if (symsec->sh_type != SHT_SYMTAB
  7492. && symsec->sh_type != SHT_DYNSYM)
  7493. continue;
  7494. if (!get_symtab (filedata, symsec,
  7495. &symtab, &nsyms, &strtab, &strtablen))
  7496. continue;
  7497. dump_relocations (filedata, rel_offset, rel_size,
  7498. symtab, nsyms, strtab, strtablen,
  7499. rel_type,
  7500. symsec->sh_type == SHT_DYNSYM);
  7501. free (strtab);
  7502. free (symtab);
  7503. }
  7504. else
  7505. dump_relocations (filedata, rel_offset, rel_size,
  7506. NULL, 0, NULL, 0, rel_type, false /* is_dynamic */);
  7507. found = true;
  7508. }
  7509. }
  7510. if (! found)
  7511. {
  7512. /* Users sometimes forget the -D option, so try to be helpful. */
  7513. for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
  7514. {
  7515. if (filedata->dynamic_info[dynamic_relocations [i].size])
  7516. {
  7517. if (filedata->is_separate)
  7518. printf (_("\nThere are no static relocations in linked file '%s'."),
  7519. filedata->file_name);
  7520. else
  7521. printf (_("\nThere are no static relocations in this file."));
  7522. printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n"));
  7523. break;
  7524. }
  7525. }
  7526. if (i == ARRAY_SIZE (dynamic_relocations))
  7527. {
  7528. if (filedata->is_separate)
  7529. printf (_("\nThere are no relocations in linked file '%s'.\n"),
  7530. filedata->file_name);
  7531. else
  7532. printf (_("\nThere are no relocations in this file.\n"));
  7533. }
  7534. }
  7535. }
  7536. return true;
  7537. }
  7538. /* An absolute address consists of a section and an offset. If the
  7539. section is NULL, the offset itself is the address, otherwise, the
  7540. address equals to LOAD_ADDRESS(section) + offset. */
  7541. struct absaddr
  7542. {
  7543. unsigned short section;
  7544. bfd_vma offset;
  7545. };
  7546. /* Find the nearest symbol at or below ADDR. Returns the symbol
  7547. name, if found, and the offset from the symbol to ADDR. */
  7548. static void
  7549. find_symbol_for_address (Filedata * filedata,
  7550. Elf_Internal_Sym * symtab,
  7551. unsigned long nsyms,
  7552. const char * strtab,
  7553. unsigned long strtab_size,
  7554. struct absaddr addr,
  7555. const char ** symname,
  7556. bfd_vma * offset)
  7557. {
  7558. bfd_vma dist = 0x100000;
  7559. Elf_Internal_Sym * sym;
  7560. Elf_Internal_Sym * beg;
  7561. Elf_Internal_Sym * end;
  7562. Elf_Internal_Sym * best = NULL;
  7563. REMOVE_ARCH_BITS (addr.offset);
  7564. beg = symtab;
  7565. end = symtab + nsyms;
  7566. while (beg < end)
  7567. {
  7568. bfd_vma value;
  7569. sym = beg + (end - beg) / 2;
  7570. value = sym->st_value;
  7571. REMOVE_ARCH_BITS (value);
  7572. if (sym->st_name != 0
  7573. && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
  7574. && addr.offset >= value
  7575. && addr.offset - value < dist)
  7576. {
  7577. best = sym;
  7578. dist = addr.offset - value;
  7579. if (!dist)
  7580. break;
  7581. }
  7582. if (addr.offset < value)
  7583. end = sym;
  7584. else
  7585. beg = sym + 1;
  7586. }
  7587. if (best)
  7588. {
  7589. *symname = (best->st_name >= strtab_size
  7590. ? _("<corrupt>") : strtab + best->st_name);
  7591. *offset = dist;
  7592. return;
  7593. }
  7594. *symname = NULL;
  7595. *offset = addr.offset;
  7596. }
  7597. static /* signed */ int
  7598. symcmp (const void *p, const void *q)
  7599. {
  7600. Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p;
  7601. Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q;
  7602. return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0);
  7603. }
  7604. /* Process the unwind section. */
  7605. #include "unwind-ia64.h"
  7606. struct ia64_unw_table_entry
  7607. {
  7608. struct absaddr start;
  7609. struct absaddr end;
  7610. struct absaddr info;
  7611. };
  7612. struct ia64_unw_aux_info
  7613. {
  7614. struct ia64_unw_table_entry * table; /* Unwind table. */
  7615. unsigned long table_len; /* Length of unwind table. */
  7616. unsigned char * info; /* Unwind info. */
  7617. unsigned long info_size; /* Size of unwind info. */
  7618. bfd_vma info_addr; /* Starting address of unwind info. */
  7619. bfd_vma seg_base; /* Starting address of segment. */
  7620. Elf_Internal_Sym * symtab; /* The symbol table. */
  7621. unsigned long nsyms; /* Number of symbols. */
  7622. Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
  7623. unsigned long nfuns; /* Number of entries in funtab. */
  7624. char * strtab; /* The string table. */
  7625. unsigned long strtab_size; /* Size of string table. */
  7626. };
  7627. static bool
  7628. dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux)
  7629. {
  7630. struct ia64_unw_table_entry * tp;
  7631. unsigned long j, nfuns;
  7632. int in_body;
  7633. bool res = true;
  7634. aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
  7635. for (nfuns = 0, j = 0; j < aux->nsyms; j++)
  7636. if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
  7637. aux->funtab[nfuns++] = aux->symtab[j];
  7638. aux->nfuns = nfuns;
  7639. qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
  7640. for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
  7641. {
  7642. bfd_vma stamp;
  7643. bfd_vma offset;
  7644. const unsigned char * dp;
  7645. const unsigned char * head;
  7646. const unsigned char * end;
  7647. const char * procname;
  7648. find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
  7649. aux->strtab_size, tp->start, &procname, &offset);
  7650. fputs ("\n<", stdout);
  7651. if (procname)
  7652. {
  7653. fputs (procname, stdout);
  7654. if (offset)
  7655. printf ("+%lx", (unsigned long) offset);
  7656. }
  7657. fputs (">: [", stdout);
  7658. print_vma (tp->start.offset, PREFIX_HEX);
  7659. fputc ('-', stdout);
  7660. print_vma (tp->end.offset, PREFIX_HEX);
  7661. printf ("], info at +0x%lx\n",
  7662. (unsigned long) (tp->info.offset - aux->seg_base));
  7663. /* PR 17531: file: 86232b32. */
  7664. if (aux->info == NULL)
  7665. continue;
  7666. offset = tp->info.offset;
  7667. if (tp->info.section)
  7668. {
  7669. if (tp->info.section >= filedata->file_header.e_shnum)
  7670. {
  7671. warn (_("Invalid section %u in table entry %ld\n"),
  7672. tp->info.section, (long) (tp - aux->table));
  7673. res = false;
  7674. continue;
  7675. }
  7676. offset += filedata->section_headers[tp->info.section].sh_addr;
  7677. }
  7678. offset -= aux->info_addr;
  7679. /* PR 17531: file: 0997b4d1. */
  7680. if (offset >= aux->info_size
  7681. || aux->info_size - offset < 8)
  7682. {
  7683. warn (_("Invalid offset %lx in table entry %ld\n"),
  7684. (long) tp->info.offset, (long) (tp - aux->table));
  7685. res = false;
  7686. continue;
  7687. }
  7688. head = aux->info + offset;
  7689. stamp = byte_get ((unsigned char *) head, sizeof (stamp));
  7690. printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
  7691. (unsigned) UNW_VER (stamp),
  7692. (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
  7693. UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
  7694. UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
  7695. (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
  7696. if (UNW_VER (stamp) != 1)
  7697. {
  7698. printf (_("\tUnknown version.\n"));
  7699. continue;
  7700. }
  7701. in_body = 0;
  7702. end = head + 8 + eh_addr_size * UNW_LENGTH (stamp);
  7703. /* PR 17531: file: 16ceda89. */
  7704. if (end > aux->info + aux->info_size)
  7705. end = aux->info + aux->info_size;
  7706. for (dp = head + 8; dp < end;)
  7707. dp = unw_decode (dp, in_body, & in_body, end);
  7708. }
  7709. free (aux->funtab);
  7710. return res;
  7711. }
  7712. static bool
  7713. slurp_ia64_unwind_table (Filedata * filedata,
  7714. struct ia64_unw_aux_info * aux,
  7715. Elf_Internal_Shdr * sec)
  7716. {
  7717. unsigned long size, nrelas, i;
  7718. Elf_Internal_Phdr * seg;
  7719. struct ia64_unw_table_entry * tep;
  7720. Elf_Internal_Shdr * relsec;
  7721. Elf_Internal_Rela * rela;
  7722. Elf_Internal_Rela * rp;
  7723. unsigned char * table;
  7724. unsigned char * tp;
  7725. Elf_Internal_Sym * sym;
  7726. const char * relname;
  7727. aux->table_len = 0;
  7728. /* First, find the starting address of the segment that includes
  7729. this section: */
  7730. if (filedata->file_header.e_phnum)
  7731. {
  7732. if (! get_program_headers (filedata))
  7733. return false;
  7734. for (seg = filedata->program_headers;
  7735. seg < filedata->program_headers + filedata->file_header.e_phnum;
  7736. ++seg)
  7737. {
  7738. if (seg->p_type != PT_LOAD)
  7739. continue;
  7740. if (sec->sh_addr >= seg->p_vaddr
  7741. && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
  7742. {
  7743. aux->seg_base = seg->p_vaddr;
  7744. break;
  7745. }
  7746. }
  7747. }
  7748. /* Second, build the unwind table from the contents of the unwind section: */
  7749. size = sec->sh_size;
  7750. table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
  7751. _("unwind table"));
  7752. if (!table)
  7753. return false;
  7754. aux->table_len = size / (3 * eh_addr_size);
  7755. aux->table = (struct ia64_unw_table_entry *)
  7756. xcmalloc (aux->table_len, sizeof (aux->table[0]));
  7757. tep = aux->table;
  7758. for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep)
  7759. {
  7760. tep->start.section = SHN_UNDEF;
  7761. tep->end.section = SHN_UNDEF;
  7762. tep->info.section = SHN_UNDEF;
  7763. tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
  7764. tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
  7765. tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
  7766. tep->start.offset += aux->seg_base;
  7767. tep->end.offset += aux->seg_base;
  7768. tep->info.offset += aux->seg_base;
  7769. }
  7770. free (table);
  7771. /* Third, apply any relocations to the unwind table: */
  7772. for (relsec = filedata->section_headers;
  7773. relsec < filedata->section_headers + filedata->file_header.e_shnum;
  7774. ++relsec)
  7775. {
  7776. if (relsec->sh_type != SHT_RELA
  7777. || relsec->sh_info >= filedata->file_header.e_shnum
  7778. || filedata->section_headers + relsec->sh_info != sec)
  7779. continue;
  7780. if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
  7781. & rela, & nrelas))
  7782. {
  7783. free (aux->table);
  7784. aux->table = NULL;
  7785. aux->table_len = 0;
  7786. return false;
  7787. }
  7788. for (rp = rela; rp < rela + nrelas; ++rp)
  7789. {
  7790. unsigned int sym_ndx;
  7791. unsigned int r_type = get_reloc_type (filedata, rp->r_info);
  7792. relname = elf_ia64_reloc_type (r_type);
  7793. /* PR 17531: file: 9fa67536. */
  7794. if (relname == NULL)
  7795. {
  7796. warn (_("Skipping unknown relocation type: %u\n"), r_type);
  7797. continue;
  7798. }
  7799. if (! startswith (relname, "R_IA64_SEGREL"))
  7800. {
  7801. warn (_("Skipping unexpected relocation type: %s\n"), relname);
  7802. continue;
  7803. }
  7804. i = rp->r_offset / (3 * eh_addr_size);
  7805. /* PR 17531: file: 5bc8d9bf. */
  7806. if (i >= aux->table_len)
  7807. {
  7808. warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
  7809. continue;
  7810. }
  7811. sym_ndx = get_reloc_symindex (rp->r_info);
  7812. if (sym_ndx >= aux->nsyms)
  7813. {
  7814. warn (_("Skipping reloc with invalid symbol index: %u\n"),
  7815. sym_ndx);
  7816. continue;
  7817. }
  7818. sym = aux->symtab + sym_ndx;
  7819. switch (rp->r_offset / eh_addr_size % 3)
  7820. {
  7821. case 0:
  7822. aux->table[i].start.section = sym->st_shndx;
  7823. aux->table[i].start.offset = rp->r_addend + sym->st_value;
  7824. break;
  7825. case 1:
  7826. aux->table[i].end.section = sym->st_shndx;
  7827. aux->table[i].end.offset = rp->r_addend + sym->st_value;
  7828. break;
  7829. case 2:
  7830. aux->table[i].info.section = sym->st_shndx;
  7831. aux->table[i].info.offset = rp->r_addend + sym->st_value;
  7832. break;
  7833. default:
  7834. break;
  7835. }
  7836. }
  7837. free (rela);
  7838. }
  7839. return true;
  7840. }
  7841. static bool
  7842. ia64_process_unwind (Filedata * filedata)
  7843. {
  7844. Elf_Internal_Shdr * sec;
  7845. Elf_Internal_Shdr * unwsec = NULL;
  7846. unsigned long i, unwcount = 0, unwstart = 0;
  7847. struct ia64_unw_aux_info aux;
  7848. bool res = true;
  7849. memset (& aux, 0, sizeof (aux));
  7850. for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
  7851. {
  7852. if (sec->sh_type == SHT_SYMTAB)
  7853. {
  7854. if (aux.symtab)
  7855. {
  7856. error (_("Multiple symbol tables encountered\n"));
  7857. free (aux.symtab);
  7858. aux.symtab = NULL;
  7859. free (aux.strtab);
  7860. aux.strtab = NULL;
  7861. }
  7862. if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms,
  7863. &aux.strtab, &aux.strtab_size))
  7864. return false;
  7865. }
  7866. else if (sec->sh_type == SHT_IA_64_UNWIND)
  7867. unwcount++;
  7868. }
  7869. if (!unwcount)
  7870. printf (_("\nThere are no unwind sections in this file.\n"));
  7871. while (unwcount-- > 0)
  7872. {
  7873. const char *suffix;
  7874. size_t len, len2;
  7875. for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL;
  7876. i < filedata->file_header.e_shnum; ++i, ++sec)
  7877. if (sec->sh_type == SHT_IA_64_UNWIND)
  7878. {
  7879. unwsec = sec;
  7880. break;
  7881. }
  7882. /* We have already counted the number of SHT_IA64_UNWIND
  7883. sections so the loop above should never fail. */
  7884. assert (unwsec != NULL);
  7885. unwstart = i + 1;
  7886. len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
  7887. if ((unwsec->sh_flags & SHF_GROUP) != 0)
  7888. {
  7889. /* We need to find which section group it is in. */
  7890. struct group_list * g;
  7891. if (filedata->section_headers_groups == NULL
  7892. || filedata->section_headers_groups[i] == NULL)
  7893. i = filedata->file_header.e_shnum;
  7894. else
  7895. {
  7896. g = filedata->section_headers_groups[i]->root;
  7897. for (; g != NULL; g = g->next)
  7898. {
  7899. sec = filedata->section_headers + g->section_index;
  7900. if (section_name_valid (filedata, sec)
  7901. && streq (section_name (filedata, sec),
  7902. ELF_STRING_ia64_unwind_info))
  7903. break;
  7904. }
  7905. if (g == NULL)
  7906. i = filedata->file_header.e_shnum;
  7907. }
  7908. }
  7909. else if (section_name_valid (filedata, unwsec)
  7910. && startswith (section_name (filedata, unwsec),
  7911. ELF_STRING_ia64_unwind_once))
  7912. {
  7913. /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
  7914. len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
  7915. suffix = section_name (filedata, unwsec) + len;
  7916. for (i = 0, sec = filedata->section_headers;
  7917. i < filedata->file_header.e_shnum;
  7918. ++i, ++sec)
  7919. if (section_name_valid (filedata, sec)
  7920. && startswith (section_name (filedata, sec),
  7921. ELF_STRING_ia64_unwind_info_once)
  7922. && streq (section_name (filedata, sec) + len2, suffix))
  7923. break;
  7924. }
  7925. else
  7926. {
  7927. /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
  7928. .IA_64.unwind or BAR -> .IA_64.unwind_info. */
  7929. len = sizeof (ELF_STRING_ia64_unwind) - 1;
  7930. len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
  7931. suffix = "";
  7932. if (section_name_valid (filedata, unwsec)
  7933. && startswith (section_name (filedata, unwsec),
  7934. ELF_STRING_ia64_unwind))
  7935. suffix = section_name (filedata, unwsec) + len;
  7936. for (i = 0, sec = filedata->section_headers;
  7937. i < filedata->file_header.e_shnum;
  7938. ++i, ++sec)
  7939. if (section_name_valid (filedata, sec)
  7940. && startswith (section_name (filedata, sec),
  7941. ELF_STRING_ia64_unwind_info)
  7942. && streq (section_name (filedata, sec) + len2, suffix))
  7943. break;
  7944. }
  7945. if (i == filedata->file_header.e_shnum)
  7946. {
  7947. printf (_("\nCould not find unwind info section for "));
  7948. if (filedata->string_table == NULL)
  7949. printf ("%d", unwsec->sh_name);
  7950. else
  7951. printf ("'%s'", printable_section_name (filedata, unwsec));
  7952. }
  7953. else
  7954. {
  7955. aux.info_addr = sec->sh_addr;
  7956. aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1,
  7957. sec->sh_size,
  7958. _("unwind info"));
  7959. aux.info_size = aux.info == NULL ? 0 : sec->sh_size;
  7960. printf (_("\nUnwind section "));
  7961. if (filedata->string_table == NULL)
  7962. printf ("%d", unwsec->sh_name);
  7963. else
  7964. printf ("'%s'", printable_section_name (filedata, unwsec));
  7965. printf (_(" at offset 0x%lx contains %lu entries:\n"),
  7966. (unsigned long) unwsec->sh_offset,
  7967. (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
  7968. if (slurp_ia64_unwind_table (filedata, & aux, unwsec)
  7969. && aux.table_len > 0)
  7970. dump_ia64_unwind (filedata, & aux);
  7971. free ((char *) aux.table);
  7972. free ((char *) aux.info);
  7973. aux.table = NULL;
  7974. aux.info = NULL;
  7975. }
  7976. }
  7977. free (aux.symtab);
  7978. free ((char *) aux.strtab);
  7979. return res;
  7980. }
  7981. struct hppa_unw_table_entry
  7982. {
  7983. struct absaddr start;
  7984. struct absaddr end;
  7985. unsigned int Cannot_unwind:1; /* 0 */
  7986. unsigned int Millicode:1; /* 1 */
  7987. unsigned int Millicode_save_sr0:1; /* 2 */
  7988. unsigned int Region_description:2; /* 3..4 */
  7989. unsigned int reserved1:1; /* 5 */
  7990. unsigned int Entry_SR:1; /* 6 */
  7991. unsigned int Entry_FR:4; /* Number saved 7..10 */
  7992. unsigned int Entry_GR:5; /* Number saved 11..15 */
  7993. unsigned int Args_stored:1; /* 16 */
  7994. unsigned int Variable_Frame:1; /* 17 */
  7995. unsigned int Separate_Package_Body:1; /* 18 */
  7996. unsigned int Frame_Extension_Millicode:1; /* 19 */
  7997. unsigned int Stack_Overflow_Check:1; /* 20 */
  7998. unsigned int Two_Instruction_SP_Increment:1; /* 21 */
  7999. unsigned int Ada_Region:1; /* 22 */
  8000. unsigned int cxx_info:1; /* 23 */
  8001. unsigned int cxx_try_catch:1; /* 24 */
  8002. unsigned int sched_entry_seq:1; /* 25 */
  8003. unsigned int reserved2:1; /* 26 */
  8004. unsigned int Save_SP:1; /* 27 */
  8005. unsigned int Save_RP:1; /* 28 */
  8006. unsigned int Save_MRP_in_frame:1; /* 29 */
  8007. unsigned int extn_ptr_defined:1; /* 30 */
  8008. unsigned int Cleanup_defined:1; /* 31 */
  8009. unsigned int MPE_XL_interrupt_marker:1; /* 0 */
  8010. unsigned int HP_UX_interrupt_marker:1; /* 1 */
  8011. unsigned int Large_frame:1; /* 2 */
  8012. unsigned int Pseudo_SP_Set:1; /* 3 */
  8013. unsigned int reserved4:1; /* 4 */
  8014. unsigned int Total_frame_size:27; /* 5..31 */
  8015. };
  8016. struct hppa_unw_aux_info
  8017. {
  8018. struct hppa_unw_table_entry * table; /* Unwind table. */
  8019. unsigned long table_len; /* Length of unwind table. */
  8020. bfd_vma seg_base; /* Starting address of segment. */
  8021. Elf_Internal_Sym * symtab; /* The symbol table. */
  8022. unsigned long nsyms; /* Number of symbols. */
  8023. Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
  8024. unsigned long nfuns; /* Number of entries in funtab. */
  8025. char * strtab; /* The string table. */
  8026. unsigned long strtab_size; /* Size of string table. */
  8027. };
  8028. static bool
  8029. dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux)
  8030. {
  8031. struct hppa_unw_table_entry * tp;
  8032. unsigned long j, nfuns;
  8033. bool res = true;
  8034. aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
  8035. for (nfuns = 0, j = 0; j < aux->nsyms; j++)
  8036. if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
  8037. aux->funtab[nfuns++] = aux->symtab[j];
  8038. aux->nfuns = nfuns;
  8039. qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
  8040. for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
  8041. {
  8042. bfd_vma offset;
  8043. const char * procname;
  8044. find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
  8045. aux->strtab_size, tp->start, &procname,
  8046. &offset);
  8047. fputs ("\n<", stdout);
  8048. if (procname)
  8049. {
  8050. fputs (procname, stdout);
  8051. if (offset)
  8052. printf ("+%lx", (unsigned long) offset);
  8053. }
  8054. fputs (">: [", stdout);
  8055. print_vma (tp->start.offset, PREFIX_HEX);
  8056. fputc ('-', stdout);
  8057. print_vma (tp->end.offset, PREFIX_HEX);
  8058. printf ("]\n\t");
  8059. #define PF(_m) if (tp->_m) printf (#_m " ");
  8060. #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
  8061. PF(Cannot_unwind);
  8062. PF(Millicode);
  8063. PF(Millicode_save_sr0);
  8064. /* PV(Region_description); */
  8065. PF(Entry_SR);
  8066. PV(Entry_FR);
  8067. PV(Entry_GR);
  8068. PF(Args_stored);
  8069. PF(Variable_Frame);
  8070. PF(Separate_Package_Body);
  8071. PF(Frame_Extension_Millicode);
  8072. PF(Stack_Overflow_Check);
  8073. PF(Two_Instruction_SP_Increment);
  8074. PF(Ada_Region);
  8075. PF(cxx_info);
  8076. PF(cxx_try_catch);
  8077. PF(sched_entry_seq);
  8078. PF(Save_SP);
  8079. PF(Save_RP);
  8080. PF(Save_MRP_in_frame);
  8081. PF(extn_ptr_defined);
  8082. PF(Cleanup_defined);
  8083. PF(MPE_XL_interrupt_marker);
  8084. PF(HP_UX_interrupt_marker);
  8085. PF(Large_frame);
  8086. PF(Pseudo_SP_Set);
  8087. PV(Total_frame_size);
  8088. #undef PF
  8089. #undef PV
  8090. }
  8091. printf ("\n");
  8092. free (aux->funtab);
  8093. return res;
  8094. }
  8095. static bool
  8096. slurp_hppa_unwind_table (Filedata * filedata,
  8097. struct hppa_unw_aux_info * aux,
  8098. Elf_Internal_Shdr * sec)
  8099. {
  8100. unsigned long size, unw_ent_size, nentries, nrelas, i;
  8101. Elf_Internal_Phdr * seg;
  8102. struct hppa_unw_table_entry * tep;
  8103. Elf_Internal_Shdr * relsec;
  8104. Elf_Internal_Rela * rela;
  8105. Elf_Internal_Rela * rp;
  8106. unsigned char * table;
  8107. unsigned char * tp;
  8108. Elf_Internal_Sym * sym;
  8109. const char * relname;
  8110. /* First, find the starting address of the segment that includes
  8111. this section. */
  8112. if (filedata->file_header.e_phnum)
  8113. {
  8114. if (! get_program_headers (filedata))
  8115. return false;
  8116. for (seg = filedata->program_headers;
  8117. seg < filedata->program_headers + filedata->file_header.e_phnum;
  8118. ++seg)
  8119. {
  8120. if (seg->p_type != PT_LOAD)
  8121. continue;
  8122. if (sec->sh_addr >= seg->p_vaddr
  8123. && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
  8124. {
  8125. aux->seg_base = seg->p_vaddr;
  8126. break;
  8127. }
  8128. }
  8129. }
  8130. /* Second, build the unwind table from the contents of the unwind
  8131. section. */
  8132. size = sec->sh_size;
  8133. table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size,
  8134. _("unwind table"));
  8135. if (!table)
  8136. return false;
  8137. unw_ent_size = 16;
  8138. nentries = size / unw_ent_size;
  8139. size = unw_ent_size * nentries;
  8140. aux->table_len = nentries;
  8141. tep = aux->table = (struct hppa_unw_table_entry *)
  8142. xcmalloc (nentries, sizeof (aux->table[0]));
  8143. for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
  8144. {
  8145. unsigned int tmp1, tmp2;
  8146. tep->start.section = SHN_UNDEF;
  8147. tep->end.section = SHN_UNDEF;
  8148. tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
  8149. tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
  8150. tmp1 = byte_get ((unsigned char *) tp + 8, 4);
  8151. tmp2 = byte_get ((unsigned char *) tp + 12, 4);
  8152. tep->start.offset += aux->seg_base;
  8153. tep->end.offset += aux->seg_base;
  8154. tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
  8155. tep->Millicode = (tmp1 >> 30) & 0x1;
  8156. tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
  8157. tep->Region_description = (tmp1 >> 27) & 0x3;
  8158. tep->reserved1 = (tmp1 >> 26) & 0x1;
  8159. tep->Entry_SR = (tmp1 >> 25) & 0x1;
  8160. tep->Entry_FR = (tmp1 >> 21) & 0xf;
  8161. tep->Entry_GR = (tmp1 >> 16) & 0x1f;
  8162. tep->Args_stored = (tmp1 >> 15) & 0x1;
  8163. tep->Variable_Frame = (tmp1 >> 14) & 0x1;
  8164. tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
  8165. tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
  8166. tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
  8167. tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
  8168. tep->Ada_Region = (tmp1 >> 9) & 0x1;
  8169. tep->cxx_info = (tmp1 >> 8) & 0x1;
  8170. tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
  8171. tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
  8172. tep->reserved2 = (tmp1 >> 5) & 0x1;
  8173. tep->Save_SP = (tmp1 >> 4) & 0x1;
  8174. tep->Save_RP = (tmp1 >> 3) & 0x1;
  8175. tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
  8176. tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
  8177. tep->Cleanup_defined = tmp1 & 0x1;
  8178. tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
  8179. tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
  8180. tep->Large_frame = (tmp2 >> 29) & 0x1;
  8181. tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
  8182. tep->reserved4 = (tmp2 >> 27) & 0x1;
  8183. tep->Total_frame_size = tmp2 & 0x7ffffff;
  8184. }
  8185. free (table);
  8186. /* Third, apply any relocations to the unwind table. */
  8187. for (relsec = filedata->section_headers;
  8188. relsec < filedata->section_headers + filedata->file_header.e_shnum;
  8189. ++relsec)
  8190. {
  8191. if (relsec->sh_type != SHT_RELA
  8192. || relsec->sh_info >= filedata->file_header.e_shnum
  8193. || filedata->section_headers + relsec->sh_info != sec)
  8194. continue;
  8195. if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size,
  8196. & rela, & nrelas))
  8197. return false;
  8198. for (rp = rela; rp < rela + nrelas; ++rp)
  8199. {
  8200. unsigned int sym_ndx;
  8201. unsigned int r_type = get_reloc_type (filedata, rp->r_info);
  8202. relname = elf_hppa_reloc_type (r_type);
  8203. if (relname == NULL)
  8204. {
  8205. warn (_("Skipping unknown relocation type: %u\n"), r_type);
  8206. continue;
  8207. }
  8208. /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
  8209. if (! startswith (relname, "R_PARISC_SEGREL"))
  8210. {
  8211. warn (_("Skipping unexpected relocation type: %s\n"), relname);
  8212. continue;
  8213. }
  8214. i = rp->r_offset / unw_ent_size;
  8215. if (i >= aux->table_len)
  8216. {
  8217. warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
  8218. continue;
  8219. }
  8220. sym_ndx = get_reloc_symindex (rp->r_info);
  8221. if (sym_ndx >= aux->nsyms)
  8222. {
  8223. warn (_("Skipping reloc with invalid symbol index: %u\n"),
  8224. sym_ndx);
  8225. continue;
  8226. }
  8227. sym = aux->symtab + sym_ndx;
  8228. switch ((rp->r_offset % unw_ent_size) / 4)
  8229. {
  8230. case 0:
  8231. aux->table[i].start.section = sym->st_shndx;
  8232. aux->table[i].start.offset = sym->st_value + rp->r_addend;
  8233. break;
  8234. case 1:
  8235. aux->table[i].end.section = sym->st_shndx;
  8236. aux->table[i].end.offset = sym->st_value + rp->r_addend;
  8237. break;
  8238. default:
  8239. break;
  8240. }
  8241. }
  8242. free (rela);
  8243. }
  8244. return true;
  8245. }
  8246. static bool
  8247. hppa_process_unwind (Filedata * filedata)
  8248. {
  8249. struct hppa_unw_aux_info aux;
  8250. Elf_Internal_Shdr * unwsec = NULL;
  8251. Elf_Internal_Shdr * sec;
  8252. unsigned long i;
  8253. bool res = true;
  8254. if (filedata->string_table == NULL)
  8255. return false;
  8256. memset (& aux, 0, sizeof (aux));
  8257. for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
  8258. {
  8259. if (sec->sh_type == SHT_SYMTAB)
  8260. {
  8261. if (aux.symtab)
  8262. {
  8263. error (_("Multiple symbol tables encountered\n"));
  8264. free (aux.symtab);
  8265. aux.symtab = NULL;
  8266. free (aux.strtab);
  8267. aux.strtab = NULL;
  8268. }
  8269. if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms,
  8270. &aux.strtab, &aux.strtab_size))
  8271. return false;
  8272. }
  8273. else if (section_name_valid (filedata, sec)
  8274. && streq (section_name (filedata, sec), ".PARISC.unwind"))
  8275. unwsec = sec;
  8276. }
  8277. if (!unwsec)
  8278. printf (_("\nThere are no unwind sections in this file.\n"));
  8279. for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
  8280. {
  8281. if (section_name_valid (filedata, sec)
  8282. && streq (section_name (filedata, sec), ".PARISC.unwind"))
  8283. {
  8284. unsigned long num_unwind = sec->sh_size / 16;
  8285. printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
  8286. "contains %lu entry:\n",
  8287. "\nUnwind section '%s' at offset 0x%lx "
  8288. "contains %lu entries:\n",
  8289. num_unwind),
  8290. printable_section_name (filedata, sec),
  8291. (unsigned long) sec->sh_offset,
  8292. num_unwind);
  8293. if (! slurp_hppa_unwind_table (filedata, &aux, sec))
  8294. res = false;
  8295. if (res && aux.table_len > 0)
  8296. {
  8297. if (! dump_hppa_unwind (filedata, &aux))
  8298. res = false;
  8299. }
  8300. free ((char *) aux.table);
  8301. aux.table = NULL;
  8302. }
  8303. }
  8304. free (aux.symtab);
  8305. free ((char *) aux.strtab);
  8306. return res;
  8307. }
  8308. struct arm_section
  8309. {
  8310. unsigned char * data; /* The unwind data. */
  8311. Elf_Internal_Shdr * sec; /* The cached unwind section header. */
  8312. Elf_Internal_Rela * rela; /* The cached relocations for this section. */
  8313. unsigned long nrelas; /* The number of relocations. */
  8314. unsigned int rel_type; /* REL or RELA ? */
  8315. Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */
  8316. };
  8317. struct arm_unw_aux_info
  8318. {
  8319. Filedata * filedata; /* The file containing the unwind sections. */
  8320. Elf_Internal_Sym * symtab; /* The file's symbol table. */
  8321. unsigned long nsyms; /* Number of symbols. */
  8322. Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
  8323. unsigned long nfuns; /* Number of these symbols. */
  8324. char * strtab; /* The file's string table. */
  8325. unsigned long strtab_size; /* Size of string table. */
  8326. };
  8327. static const char *
  8328. arm_print_vma_and_name (Filedata * filedata,
  8329. struct arm_unw_aux_info * aux,
  8330. bfd_vma fn,
  8331. struct absaddr addr)
  8332. {
  8333. const char *procname;
  8334. bfd_vma sym_offset;
  8335. if (addr.section == SHN_UNDEF)
  8336. addr.offset = fn;
  8337. find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab,
  8338. aux->strtab_size, addr, &procname,
  8339. &sym_offset);
  8340. print_vma (fn, PREFIX_HEX);
  8341. if (procname)
  8342. {
  8343. fputs (" <", stdout);
  8344. fputs (procname, stdout);
  8345. if (sym_offset)
  8346. printf ("+0x%lx", (unsigned long) sym_offset);
  8347. fputc ('>', stdout);
  8348. }
  8349. return procname;
  8350. }
  8351. static void
  8352. arm_free_section (struct arm_section *arm_sec)
  8353. {
  8354. free (arm_sec->data);
  8355. free (arm_sec->rela);
  8356. }
  8357. /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
  8358. cached section and install SEC instead.
  8359. 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
  8360. and return its valued in * WORDP, relocating if necessary.
  8361. 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
  8362. relocation's offset in ADDR.
  8363. 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
  8364. into the string table of the symbol associated with the reloc. If no
  8365. reloc was applied store -1 there.
  8366. 5) Return TRUE upon success, FALSE otherwise. */
  8367. static bool
  8368. get_unwind_section_word (Filedata * filedata,
  8369. struct arm_unw_aux_info * aux,
  8370. struct arm_section * arm_sec,
  8371. Elf_Internal_Shdr * sec,
  8372. bfd_vma word_offset,
  8373. unsigned int * wordp,
  8374. struct absaddr * addr,
  8375. bfd_vma * sym_name)
  8376. {
  8377. Elf_Internal_Rela *rp;
  8378. Elf_Internal_Sym *sym;
  8379. const char * relname;
  8380. unsigned int word;
  8381. bool wrapped;
  8382. if (sec == NULL || arm_sec == NULL)
  8383. return false;
  8384. addr->section = SHN_UNDEF;
  8385. addr->offset = 0;
  8386. if (sym_name != NULL)
  8387. *sym_name = (bfd_vma) -1;
  8388. /* If necessary, update the section cache. */
  8389. if (sec != arm_sec->sec)
  8390. {
  8391. Elf_Internal_Shdr *relsec;
  8392. arm_free_section (arm_sec);
  8393. arm_sec->sec = sec;
  8394. arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1,
  8395. sec->sh_size, _("unwind data"));
  8396. arm_sec->rela = NULL;
  8397. arm_sec->nrelas = 0;
  8398. for (relsec = filedata->section_headers;
  8399. relsec < filedata->section_headers + filedata->file_header.e_shnum;
  8400. ++relsec)
  8401. {
  8402. if (relsec->sh_info >= filedata->file_header.e_shnum
  8403. || filedata->section_headers + relsec->sh_info != sec
  8404. /* PR 15745: Check the section type as well. */
  8405. || (relsec->sh_type != SHT_REL
  8406. && relsec->sh_type != SHT_RELA))
  8407. continue;
  8408. arm_sec->rel_type = relsec->sh_type;
  8409. if (relsec->sh_type == SHT_REL)
  8410. {
  8411. if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset,
  8412. relsec->sh_size,
  8413. & arm_sec->rela, & arm_sec->nrelas))
  8414. return false;
  8415. }
  8416. else /* relsec->sh_type == SHT_RELA */
  8417. {
  8418. if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset,
  8419. relsec->sh_size,
  8420. & arm_sec->rela, & arm_sec->nrelas))
  8421. return false;
  8422. }
  8423. break;
  8424. }
  8425. arm_sec->next_rela = arm_sec->rela;
  8426. }
  8427. /* If there is no unwind data we can do nothing. */
  8428. if (arm_sec->data == NULL)
  8429. return false;
  8430. /* If the offset is invalid then fail. */
  8431. if (/* PR 21343 *//* PR 18879 */
  8432. sec->sh_size < 4
  8433. || word_offset > (sec->sh_size - 4)
  8434. || ((bfd_signed_vma) word_offset) < 0)
  8435. return false;
  8436. /* Get the word at the required offset. */
  8437. word = byte_get (arm_sec->data + word_offset, 4);
  8438. /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
  8439. if (arm_sec->rela == NULL)
  8440. {
  8441. * wordp = word;
  8442. return true;
  8443. }
  8444. /* Look through the relocs to find the one that applies to the provided offset. */
  8445. wrapped = false;
  8446. for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++)
  8447. {
  8448. bfd_vma prelval, offset;
  8449. if (rp->r_offset > word_offset && !wrapped)
  8450. {
  8451. rp = arm_sec->rela;
  8452. wrapped = true;
  8453. }
  8454. if (rp->r_offset > word_offset)
  8455. break;
  8456. if (rp->r_offset & 3)
  8457. {
  8458. warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
  8459. (unsigned long) rp->r_offset);
  8460. continue;
  8461. }
  8462. if (rp->r_offset < word_offset)
  8463. continue;
  8464. /* PR 17531: file: 027-161405-0.004 */
  8465. if (aux->symtab == NULL)
  8466. continue;
  8467. if (arm_sec->rel_type == SHT_REL)
  8468. {
  8469. offset = word & 0x7fffffff;
  8470. if (offset & 0x40000000)
  8471. offset |= ~ (bfd_vma) 0x7fffffff;
  8472. }
  8473. else if (arm_sec->rel_type == SHT_RELA)
  8474. offset = rp->r_addend;
  8475. else
  8476. {
  8477. error (_("Unknown section relocation type %d encountered\n"),
  8478. arm_sec->rel_type);
  8479. break;
  8480. }
  8481. /* PR 17531 file: 027-1241568-0.004. */
  8482. if (ELF32_R_SYM (rp->r_info) >= aux->nsyms)
  8483. {
  8484. error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
  8485. (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms);
  8486. break;
  8487. }
  8488. sym = aux->symtab + ELF32_R_SYM (rp->r_info);
  8489. offset += sym->st_value;
  8490. prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset);
  8491. /* Check that we are processing the expected reloc type. */
  8492. if (filedata->file_header.e_machine == EM_ARM)
  8493. {
  8494. relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info));
  8495. if (relname == NULL)
  8496. {
  8497. warn (_("Skipping unknown ARM relocation type: %d\n"),
  8498. (int) ELF32_R_TYPE (rp->r_info));
  8499. continue;
  8500. }
  8501. if (streq (relname, "R_ARM_NONE"))
  8502. continue;
  8503. if (! streq (relname, "R_ARM_PREL31"))
  8504. {
  8505. warn (_("Skipping unexpected ARM relocation type %s\n"), relname);
  8506. continue;
  8507. }
  8508. }
  8509. else if (filedata->file_header.e_machine == EM_TI_C6000)
  8510. {
  8511. relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info));
  8512. if (relname == NULL)
  8513. {
  8514. warn (_("Skipping unknown C6000 relocation type: %d\n"),
  8515. (int) ELF32_R_TYPE (rp->r_info));
  8516. continue;
  8517. }
  8518. if (streq (relname, "R_C6000_NONE"))
  8519. continue;
  8520. if (! streq (relname, "R_C6000_PREL31"))
  8521. {
  8522. warn (_("Skipping unexpected C6000 relocation type %s\n"), relname);
  8523. continue;
  8524. }
  8525. prelval >>= 1;
  8526. }
  8527. else
  8528. {
  8529. /* This function currently only supports ARM and TI unwinders. */
  8530. warn (_("Only TI and ARM unwinders are currently supported\n"));
  8531. break;
  8532. }
  8533. word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff);
  8534. addr->section = sym->st_shndx;
  8535. addr->offset = offset;
  8536. if (sym_name)
  8537. * sym_name = sym->st_name;
  8538. break;
  8539. }
  8540. *wordp = word;
  8541. arm_sec->next_rela = rp;
  8542. return true;
  8543. }
  8544. static const char *tic6x_unwind_regnames[16] =
  8545. {
  8546. "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
  8547. "A14", "A13", "A12", "A11", "A10",
  8548. "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
  8549. };
  8550. static void
  8551. decode_tic6x_unwind_regmask (unsigned int mask)
  8552. {
  8553. int i;
  8554. for (i = 12; mask; mask >>= 1, i--)
  8555. {
  8556. if (mask & 1)
  8557. {
  8558. fputs (tic6x_unwind_regnames[i], stdout);
  8559. if (mask > 1)
  8560. fputs (", ", stdout);
  8561. }
  8562. }
  8563. }
  8564. #define ADVANCE \
  8565. if (remaining == 0 && more_words) \
  8566. { \
  8567. data_offset += 4; \
  8568. if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \
  8569. data_offset, & word, & addr, NULL)) \
  8570. return false; \
  8571. remaining = 4; \
  8572. more_words--; \
  8573. } \
  8574. #define GET_OP(OP) \
  8575. ADVANCE; \
  8576. if (remaining) \
  8577. { \
  8578. remaining--; \
  8579. (OP) = word >> 24; \
  8580. word <<= 8; \
  8581. } \
  8582. else \
  8583. { \
  8584. printf (_("[Truncated opcode]\n")); \
  8585. return false; \
  8586. } \
  8587. printf ("0x%02x ", OP)
  8588. static bool
  8589. decode_arm_unwind_bytecode (Filedata * filedata,
  8590. struct arm_unw_aux_info * aux,
  8591. unsigned int word,
  8592. unsigned int remaining,
  8593. unsigned int more_words,
  8594. bfd_vma data_offset,
  8595. Elf_Internal_Shdr * data_sec,
  8596. struct arm_section * data_arm_sec)
  8597. {
  8598. struct absaddr addr;
  8599. bool res = true;
  8600. /* Decode the unwinding instructions. */
  8601. while (1)
  8602. {
  8603. unsigned int op, op2;
  8604. ADVANCE;
  8605. if (remaining == 0)
  8606. break;
  8607. remaining--;
  8608. op = word >> 24;
  8609. word <<= 8;
  8610. printf (" 0x%02x ", op);
  8611. if ((op & 0xc0) == 0x00)
  8612. {
  8613. int offset = ((op & 0x3f) << 2) + 4;
  8614. printf (" vsp = vsp + %d", offset);
  8615. }
  8616. else if ((op & 0xc0) == 0x40)
  8617. {
  8618. int offset = ((op & 0x3f) << 2) + 4;
  8619. printf (" vsp = vsp - %d", offset);
  8620. }
  8621. else if ((op & 0xf0) == 0x80)
  8622. {
  8623. GET_OP (op2);
  8624. if (op == 0x80 && op2 == 0)
  8625. printf (_("Refuse to unwind"));
  8626. else
  8627. {
  8628. unsigned int mask = ((op & 0x0f) << 8) | op2;
  8629. bool first = true;
  8630. int i;
  8631. printf ("pop {");
  8632. for (i = 0; i < 12; i++)
  8633. if (mask & (1 << i))
  8634. {
  8635. if (first)
  8636. first = false;
  8637. else
  8638. printf (", ");
  8639. printf ("r%d", 4 + i);
  8640. }
  8641. printf ("}");
  8642. }
  8643. }
  8644. else if ((op & 0xf0) == 0x90)
  8645. {
  8646. if (op == 0x9d || op == 0x9f)
  8647. printf (_(" [Reserved]"));
  8648. else
  8649. printf (" vsp = r%d", op & 0x0f);
  8650. }
  8651. else if ((op & 0xf0) == 0xa0)
  8652. {
  8653. int end = 4 + (op & 0x07);
  8654. bool first = true;
  8655. int i;
  8656. printf (" pop {");
  8657. for (i = 4; i <= end; i++)
  8658. {
  8659. if (first)
  8660. first = false;
  8661. else
  8662. printf (", ");
  8663. printf ("r%d", i);
  8664. }
  8665. if (op & 0x08)
  8666. {
  8667. if (!first)
  8668. printf (", ");
  8669. printf ("r14");
  8670. }
  8671. printf ("}");
  8672. }
  8673. else if (op == 0xb0)
  8674. printf (_(" finish"));
  8675. else if (op == 0xb1)
  8676. {
  8677. GET_OP (op2);
  8678. if (op2 == 0 || (op2 & 0xf0) != 0)
  8679. printf (_("[Spare]"));
  8680. else
  8681. {
  8682. unsigned int mask = op2 & 0x0f;
  8683. bool first = true;
  8684. int i;
  8685. printf ("pop {");
  8686. for (i = 0; i < 12; i++)
  8687. if (mask & (1 << i))
  8688. {
  8689. if (first)
  8690. first = false;
  8691. else
  8692. printf (", ");
  8693. printf ("r%d", i);
  8694. }
  8695. printf ("}");
  8696. }
  8697. }
  8698. else if (op == 0xb2)
  8699. {
  8700. unsigned char buf[9];
  8701. unsigned int i, len;
  8702. unsigned long offset;
  8703. for (i = 0; i < sizeof (buf); i++)
  8704. {
  8705. GET_OP (buf[i]);
  8706. if ((buf[i] & 0x80) == 0)
  8707. break;
  8708. }
  8709. if (i == sizeof (buf))
  8710. {
  8711. error (_("corrupt change to vsp\n"));
  8712. res = false;
  8713. }
  8714. else
  8715. {
  8716. offset = read_leb128 (buf, buf + i + 1, false, &len, NULL);
  8717. assert (len == i + 1);
  8718. offset = offset * 4 + 0x204;
  8719. printf ("vsp = vsp + %ld", offset);
  8720. }
  8721. }
  8722. else if (op == 0xb3 || op == 0xc8 || op == 0xc9)
  8723. {
  8724. unsigned int first, last;
  8725. GET_OP (op2);
  8726. first = op2 >> 4;
  8727. last = op2 & 0x0f;
  8728. if (op == 0xc8)
  8729. first = first + 16;
  8730. printf ("pop {D%d", first);
  8731. if (last)
  8732. printf ("-D%d", first + last);
  8733. printf ("}");
  8734. }
  8735. else if (op == 0xb4)
  8736. printf (_(" pop {ra_auth_code}"));
  8737. else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0)
  8738. {
  8739. unsigned int count = op & 0x07;
  8740. printf ("pop {D8");
  8741. if (count)
  8742. printf ("-D%d", 8 + count);
  8743. printf ("}");
  8744. }
  8745. else if (op >= 0xc0 && op <= 0xc5)
  8746. {
  8747. unsigned int count = op & 0x07;
  8748. printf (" pop {wR10");
  8749. if (count)
  8750. printf ("-wR%d", 10 + count);
  8751. printf ("}");
  8752. }
  8753. else if (op == 0xc6)
  8754. {
  8755. unsigned int first, last;
  8756. GET_OP (op2);
  8757. first = op2 >> 4;
  8758. last = op2 & 0x0f;
  8759. printf ("pop {wR%d", first);
  8760. if (last)
  8761. printf ("-wR%d", first + last);
  8762. printf ("}");
  8763. }
  8764. else if (op == 0xc7)
  8765. {
  8766. GET_OP (op2);
  8767. if (op2 == 0 || (op2 & 0xf0) != 0)
  8768. printf (_("[Spare]"));
  8769. else
  8770. {
  8771. unsigned int mask = op2 & 0x0f;
  8772. bool first = true;
  8773. int i;
  8774. printf ("pop {");
  8775. for (i = 0; i < 4; i++)
  8776. if (mask & (1 << i))
  8777. {
  8778. if (first)
  8779. first = false;
  8780. else
  8781. printf (", ");
  8782. printf ("wCGR%d", i);
  8783. }
  8784. printf ("}");
  8785. }
  8786. }
  8787. else
  8788. {
  8789. printf (_(" [unsupported opcode]"));
  8790. res = false;
  8791. }
  8792. printf ("\n");
  8793. }
  8794. return res;
  8795. }
  8796. static bool
  8797. decode_tic6x_unwind_bytecode (Filedata * filedata,
  8798. struct arm_unw_aux_info * aux,
  8799. unsigned int word,
  8800. unsigned int remaining,
  8801. unsigned int more_words,
  8802. bfd_vma data_offset,
  8803. Elf_Internal_Shdr * data_sec,
  8804. struct arm_section * data_arm_sec)
  8805. {
  8806. struct absaddr addr;
  8807. /* Decode the unwinding instructions. */
  8808. while (1)
  8809. {
  8810. unsigned int op, op2;
  8811. ADVANCE;
  8812. if (remaining == 0)
  8813. break;
  8814. remaining--;
  8815. op = word >> 24;
  8816. word <<= 8;
  8817. printf (" 0x%02x ", op);
  8818. if ((op & 0xc0) == 0x00)
  8819. {
  8820. int offset = ((op & 0x3f) << 3) + 8;
  8821. printf (" sp = sp + %d", offset);
  8822. }
  8823. else if ((op & 0xc0) == 0x80)
  8824. {
  8825. GET_OP (op2);
  8826. if (op == 0x80 && op2 == 0)
  8827. printf (_("Refuse to unwind"));
  8828. else
  8829. {
  8830. unsigned int mask = ((op & 0x1f) << 8) | op2;
  8831. if (op & 0x20)
  8832. printf ("pop compact {");
  8833. else
  8834. printf ("pop {");
  8835. decode_tic6x_unwind_regmask (mask);
  8836. printf("}");
  8837. }
  8838. }
  8839. else if ((op & 0xf0) == 0xc0)
  8840. {
  8841. unsigned int reg;
  8842. unsigned int nregs;
  8843. unsigned int i;
  8844. const char *name;
  8845. struct
  8846. {
  8847. unsigned int offset;
  8848. unsigned int reg;
  8849. } regpos[16];
  8850. /* Scan entire instruction first so that GET_OP output is not
  8851. interleaved with disassembly. */
  8852. nregs = 0;
  8853. for (i = 0; nregs < (op & 0xf); i++)
  8854. {
  8855. GET_OP (op2);
  8856. reg = op2 >> 4;
  8857. if (reg != 0xf)
  8858. {
  8859. regpos[nregs].offset = i * 2;
  8860. regpos[nregs].reg = reg;
  8861. nregs++;
  8862. }
  8863. reg = op2 & 0xf;
  8864. if (reg != 0xf)
  8865. {
  8866. regpos[nregs].offset = i * 2 + 1;
  8867. regpos[nregs].reg = reg;
  8868. nregs++;
  8869. }
  8870. }
  8871. printf (_("pop frame {"));
  8872. if (nregs == 0)
  8873. {
  8874. printf (_("*corrupt* - no registers specified"));
  8875. }
  8876. else
  8877. {
  8878. reg = nregs - 1;
  8879. for (i = i * 2; i > 0; i--)
  8880. {
  8881. if (regpos[reg].offset == i - 1)
  8882. {
  8883. name = tic6x_unwind_regnames[regpos[reg].reg];
  8884. if (reg > 0)
  8885. reg--;
  8886. }
  8887. else
  8888. name = _("[pad]");
  8889. fputs (name, stdout);
  8890. if (i > 1)
  8891. printf (", ");
  8892. }
  8893. }
  8894. printf ("}");
  8895. }
  8896. else if (op == 0xd0)
  8897. printf (" MOV FP, SP");
  8898. else if (op == 0xd1)
  8899. printf (" __c6xabi_pop_rts");
  8900. else if (op == 0xd2)
  8901. {
  8902. unsigned char buf[9];
  8903. unsigned int i, len;
  8904. unsigned long offset;
  8905. for (i = 0; i < sizeof (buf); i++)
  8906. {
  8907. GET_OP (buf[i]);
  8908. if ((buf[i] & 0x80) == 0)
  8909. break;
  8910. }
  8911. /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
  8912. if (i == sizeof (buf))
  8913. {
  8914. warn (_("Corrupt stack pointer adjustment detected\n"));
  8915. return false;
  8916. }
  8917. offset = read_leb128 (buf, buf + i + 1, false, &len, NULL);
  8918. assert (len == i + 1);
  8919. offset = offset * 8 + 0x408;
  8920. printf (_("sp = sp + %ld"), offset);
  8921. }
  8922. else if ((op & 0xf0) == 0xe0)
  8923. {
  8924. if ((op & 0x0f) == 7)
  8925. printf (" RETURN");
  8926. else
  8927. printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]);
  8928. }
  8929. else
  8930. {
  8931. printf (_(" [unsupported opcode]"));
  8932. }
  8933. putchar ('\n');
  8934. }
  8935. return true;
  8936. }
  8937. static bfd_vma
  8938. arm_expand_prel31 (Filedata * filedata, bfd_vma word, bfd_vma where)
  8939. {
  8940. bfd_vma offset;
  8941. offset = word & 0x7fffffff;
  8942. if (offset & 0x40000000)
  8943. offset |= ~ (bfd_vma) 0x7fffffff;
  8944. if (filedata->file_header.e_machine == EM_TI_C6000)
  8945. offset <<= 1;
  8946. return offset + where;
  8947. }
  8948. static bool
  8949. decode_arm_unwind (Filedata * filedata,
  8950. struct arm_unw_aux_info * aux,
  8951. unsigned int word,
  8952. unsigned int remaining,
  8953. bfd_vma data_offset,
  8954. Elf_Internal_Shdr * data_sec,
  8955. struct arm_section * data_arm_sec)
  8956. {
  8957. int per_index;
  8958. unsigned int more_words = 0;
  8959. struct absaddr addr;
  8960. bfd_vma sym_name = (bfd_vma) -1;
  8961. bool res = true;
  8962. if (remaining == 0)
  8963. {
  8964. /* Fetch the first word.
  8965. Note - when decoding an object file the address extracted
  8966. here will always be 0. So we also pass in the sym_name
  8967. parameter so that we can find the symbol associated with
  8968. the personality routine. */
  8969. if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset,
  8970. & word, & addr, & sym_name))
  8971. return false;
  8972. remaining = 4;
  8973. }
  8974. else
  8975. {
  8976. addr.section = SHN_UNDEF;
  8977. addr.offset = 0;
  8978. }
  8979. if ((word & 0x80000000) == 0)
  8980. {
  8981. /* Expand prel31 for personality routine. */
  8982. bfd_vma fn;
  8983. const char *procname;
  8984. fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset);
  8985. printf (_(" Personality routine: "));
  8986. if (fn == 0
  8987. && addr.section == SHN_UNDEF && addr.offset == 0
  8988. && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size)
  8989. {
  8990. procname = aux->strtab + sym_name;
  8991. print_vma (fn, PREFIX_HEX);
  8992. if (procname)
  8993. {
  8994. fputs (" <", stdout);
  8995. fputs (procname, stdout);
  8996. fputc ('>', stdout);
  8997. }
  8998. }
  8999. else
  9000. procname = arm_print_vma_and_name (filedata, aux, fn, addr);
  9001. fputc ('\n', stdout);
  9002. /* The GCC personality routines use the standard compact
  9003. encoding, starting with one byte giving the number of
  9004. words. */
  9005. if (procname != NULL
  9006. && (startswith (procname, "__gcc_personality_v0")
  9007. || startswith (procname, "__gxx_personality_v0")
  9008. || startswith (procname, "__gcj_personality_v0")
  9009. || startswith (procname, "__gnu_objc_personality_v0")))
  9010. {
  9011. remaining = 0;
  9012. more_words = 1;
  9013. ADVANCE;
  9014. if (!remaining)
  9015. {
  9016. printf (_(" [Truncated data]\n"));
  9017. return false;
  9018. }
  9019. more_words = word >> 24;
  9020. word <<= 8;
  9021. remaining--;
  9022. per_index = -1;
  9023. }
  9024. else
  9025. return true;
  9026. }
  9027. else
  9028. {
  9029. /* ARM EHABI Section 6.3:
  9030. An exception-handling table entry for the compact model looks like:
  9031. 31 30-28 27-24 23-0
  9032. -- ----- ----- ----
  9033. 1 0 index Data for personalityRoutine[index] */
  9034. if (filedata->file_header.e_machine == EM_ARM
  9035. && (word & 0x70000000))
  9036. {
  9037. warn (_("Corrupt ARM compact model table entry: %x \n"), word);
  9038. res = false;
  9039. }
  9040. per_index = (word >> 24) & 0x7f;
  9041. printf (_(" Compact model index: %d\n"), per_index);
  9042. if (per_index == 0)
  9043. {
  9044. more_words = 0;
  9045. word <<= 8;
  9046. remaining--;
  9047. }
  9048. else if (per_index < 3)
  9049. {
  9050. more_words = (word >> 16) & 0xff;
  9051. word <<= 16;
  9052. remaining -= 2;
  9053. }
  9054. }
  9055. switch (filedata->file_header.e_machine)
  9056. {
  9057. case EM_ARM:
  9058. if (per_index < 3)
  9059. {
  9060. if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words,
  9061. data_offset, data_sec, data_arm_sec))
  9062. res = false;
  9063. }
  9064. else
  9065. {
  9066. warn (_("Unknown ARM compact model index encountered\n"));
  9067. printf (_(" [reserved]\n"));
  9068. res = false;
  9069. }
  9070. break;
  9071. case EM_TI_C6000:
  9072. if (per_index < 3)
  9073. {
  9074. if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words,
  9075. data_offset, data_sec, data_arm_sec))
  9076. res = false;
  9077. }
  9078. else if (per_index < 5)
  9079. {
  9080. if (((word >> 17) & 0x7f) == 0x7f)
  9081. printf (_(" Restore stack from frame pointer\n"));
  9082. else
  9083. printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc);
  9084. printf (_(" Registers restored: "));
  9085. if (per_index == 4)
  9086. printf (" (compact) ");
  9087. decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff);
  9088. putchar ('\n');
  9089. printf (_(" Return register: %s\n"),
  9090. tic6x_unwind_regnames[word & 0xf]);
  9091. }
  9092. else
  9093. printf (_(" [reserved (%d)]\n"), per_index);
  9094. break;
  9095. default:
  9096. error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
  9097. filedata->file_header.e_machine);
  9098. res = false;
  9099. }
  9100. /* Decode the descriptors. Not implemented. */
  9101. return res;
  9102. }
  9103. static bool
  9104. dump_arm_unwind (Filedata * filedata,
  9105. struct arm_unw_aux_info * aux,
  9106. Elf_Internal_Shdr * exidx_sec)
  9107. {
  9108. struct arm_section exidx_arm_sec, extab_arm_sec;
  9109. unsigned int i, exidx_len;
  9110. unsigned long j, nfuns;
  9111. bool res = true;
  9112. memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec));
  9113. memset (&extab_arm_sec, 0, sizeof (extab_arm_sec));
  9114. exidx_len = exidx_sec->sh_size / 8;
  9115. aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
  9116. for (nfuns = 0, j = 0; j < aux->nsyms; j++)
  9117. if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
  9118. aux->funtab[nfuns++] = aux->symtab[j];
  9119. aux->nfuns = nfuns;
  9120. qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
  9121. for (i = 0; i < exidx_len; i++)
  9122. {
  9123. unsigned int exidx_fn, exidx_entry;
  9124. struct absaddr fn_addr, entry_addr;
  9125. bfd_vma fn;
  9126. fputc ('\n', stdout);
  9127. if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
  9128. 8 * i, & exidx_fn, & fn_addr, NULL)
  9129. || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec,
  9130. 8 * i + 4, & exidx_entry, & entry_addr, NULL))
  9131. {
  9132. free (aux->funtab);
  9133. arm_free_section (& exidx_arm_sec);
  9134. arm_free_section (& extab_arm_sec);
  9135. return false;
  9136. }
  9137. /* ARM EHABI, Section 5:
  9138. An index table entry consists of 2 words.
  9139. The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
  9140. if (exidx_fn & 0x80000000)
  9141. {
  9142. warn (_("corrupt index table entry: %x\n"), exidx_fn);
  9143. res = false;
  9144. }
  9145. fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i);
  9146. arm_print_vma_and_name (filedata, aux, fn, fn_addr);
  9147. fputs (": ", stdout);
  9148. if (exidx_entry == 1)
  9149. {
  9150. print_vma (exidx_entry, PREFIX_HEX);
  9151. fputs (" [cantunwind]\n", stdout);
  9152. }
  9153. else if (exidx_entry & 0x80000000)
  9154. {
  9155. print_vma (exidx_entry, PREFIX_HEX);
  9156. fputc ('\n', stdout);
  9157. decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL);
  9158. }
  9159. else
  9160. {
  9161. bfd_vma table, table_offset = 0;
  9162. Elf_Internal_Shdr *table_sec;
  9163. fputs ("@", stdout);
  9164. table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4);
  9165. print_vma (table, PREFIX_HEX);
  9166. printf ("\n");
  9167. /* Locate the matching .ARM.extab. */
  9168. if (entry_addr.section != SHN_UNDEF
  9169. && entry_addr.section < filedata->file_header.e_shnum)
  9170. {
  9171. table_sec = filedata->section_headers + entry_addr.section;
  9172. table_offset = entry_addr.offset;
  9173. /* PR 18879 */
  9174. if (table_offset > table_sec->sh_size
  9175. || ((bfd_signed_vma) table_offset) < 0)
  9176. {
  9177. warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
  9178. (unsigned long) table_offset,
  9179. printable_section_name (filedata, table_sec));
  9180. res = false;
  9181. continue;
  9182. }
  9183. }
  9184. else
  9185. {
  9186. table_sec = find_section_by_address (filedata, table);
  9187. if (table_sec != NULL)
  9188. table_offset = table - table_sec->sh_addr;
  9189. }
  9190. if (table_sec == NULL)
  9191. {
  9192. warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
  9193. (unsigned long) table);
  9194. res = false;
  9195. continue;
  9196. }
  9197. if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec,
  9198. &extab_arm_sec))
  9199. res = false;
  9200. }
  9201. }
  9202. printf ("\n");
  9203. free (aux->funtab);
  9204. arm_free_section (&exidx_arm_sec);
  9205. arm_free_section (&extab_arm_sec);
  9206. return res;
  9207. }
  9208. /* Used for both ARM and C6X unwinding tables. */
  9209. static bool
  9210. arm_process_unwind (Filedata * filedata)
  9211. {
  9212. struct arm_unw_aux_info aux;
  9213. Elf_Internal_Shdr *unwsec = NULL;
  9214. Elf_Internal_Shdr *sec;
  9215. unsigned long i;
  9216. unsigned int sec_type;
  9217. bool res = true;
  9218. switch (filedata->file_header.e_machine)
  9219. {
  9220. case EM_ARM:
  9221. sec_type = SHT_ARM_EXIDX;
  9222. break;
  9223. case EM_TI_C6000:
  9224. sec_type = SHT_C6000_UNWIND;
  9225. break;
  9226. default:
  9227. error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
  9228. filedata->file_header.e_machine);
  9229. return false;
  9230. }
  9231. if (filedata->string_table == NULL)
  9232. return false;
  9233. memset (& aux, 0, sizeof (aux));
  9234. aux.filedata = filedata;
  9235. for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
  9236. {
  9237. if (sec->sh_type == SHT_SYMTAB)
  9238. {
  9239. if (aux.symtab)
  9240. {
  9241. error (_("Multiple symbol tables encountered\n"));
  9242. free (aux.symtab);
  9243. aux.symtab = NULL;
  9244. free (aux.strtab);
  9245. aux.strtab = NULL;
  9246. }
  9247. if (!get_symtab (filedata, sec, &aux.symtab, &aux.nsyms,
  9248. &aux.strtab, &aux.strtab_size))
  9249. return false;
  9250. }
  9251. else if (sec->sh_type == sec_type)
  9252. unwsec = sec;
  9253. }
  9254. if (unwsec == NULL)
  9255. printf (_("\nThere are no unwind sections in this file.\n"));
  9256. else
  9257. for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec)
  9258. {
  9259. if (sec->sh_type == sec_type)
  9260. {
  9261. unsigned long num_unwind = sec->sh_size / (2 * eh_addr_size);
  9262. printf (ngettext ("\nUnwind section '%s' at offset 0x%lx "
  9263. "contains %lu entry:\n",
  9264. "\nUnwind section '%s' at offset 0x%lx "
  9265. "contains %lu entries:\n",
  9266. num_unwind),
  9267. printable_section_name (filedata, sec),
  9268. (unsigned long) sec->sh_offset,
  9269. num_unwind);
  9270. if (! dump_arm_unwind (filedata, &aux, sec))
  9271. res = false;
  9272. }
  9273. }
  9274. free (aux.symtab);
  9275. free ((char *) aux.strtab);
  9276. return res;
  9277. }
  9278. static bool
  9279. no_processor_specific_unwind (Filedata * filedata ATTRIBUTE_UNUSED)
  9280. {
  9281. printf (_("No processor specific unwind information to decode\n"));
  9282. return true;
  9283. }
  9284. static bool
  9285. process_unwind (Filedata * filedata)
  9286. {
  9287. struct unwind_handler
  9288. {
  9289. unsigned int machtype;
  9290. bool (* handler)(Filedata *);
  9291. } handlers[] =
  9292. {
  9293. { EM_ARM, arm_process_unwind },
  9294. { EM_IA_64, ia64_process_unwind },
  9295. { EM_PARISC, hppa_process_unwind },
  9296. { EM_TI_C6000, arm_process_unwind },
  9297. { EM_386, no_processor_specific_unwind },
  9298. { EM_X86_64, no_processor_specific_unwind },
  9299. { 0, NULL }
  9300. };
  9301. int i;
  9302. if (!do_unwind)
  9303. return true;
  9304. for (i = 0; handlers[i].handler != NULL; i++)
  9305. if (filedata->file_header.e_machine == handlers[i].machtype)
  9306. return handlers[i].handler (filedata);
  9307. printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
  9308. get_machine_name (filedata->file_header.e_machine));
  9309. return true;
  9310. }
  9311. static void
  9312. dynamic_section_aarch64_val (Elf_Internal_Dyn * entry)
  9313. {
  9314. switch (entry->d_tag)
  9315. {
  9316. case DT_AARCH64_BTI_PLT:
  9317. case DT_AARCH64_PAC_PLT:
  9318. break;
  9319. default:
  9320. print_vma (entry->d_un.d_ptr, PREFIX_HEX);
  9321. break;
  9322. }
  9323. putchar ('\n');
  9324. }
  9325. static void
  9326. dynamic_section_mips_val (Filedata * filedata, Elf_Internal_Dyn * entry)
  9327. {
  9328. switch (entry->d_tag)
  9329. {
  9330. case DT_MIPS_FLAGS:
  9331. if (entry->d_un.d_val == 0)
  9332. printf (_("NONE"));
  9333. else
  9334. {
  9335. static const char * opts[] =
  9336. {
  9337. "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
  9338. "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
  9339. "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
  9340. "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
  9341. "RLD_ORDER_SAFE"
  9342. };
  9343. unsigned int cnt;
  9344. bool first = true;
  9345. for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
  9346. if (entry->d_un.d_val & (1 << cnt))
  9347. {
  9348. printf ("%s%s", first ? "" : " ", opts[cnt]);
  9349. first = false;
  9350. }
  9351. }
  9352. break;
  9353. case DT_MIPS_IVERSION:
  9354. if (valid_dynamic_name (filedata, entry->d_un.d_val))
  9355. printf (_("Interface Version: %s"),
  9356. get_dynamic_name (filedata, entry->d_un.d_val));
  9357. else
  9358. {
  9359. char buf[40];
  9360. sprintf_vma (buf, entry->d_un.d_ptr);
  9361. /* Note: coded this way so that there is a single string for translation. */
  9362. printf (_("<corrupt: %s>"), buf);
  9363. }
  9364. break;
  9365. case DT_MIPS_TIME_STAMP:
  9366. {
  9367. char timebuf[128];
  9368. struct tm * tmp;
  9369. time_t atime = entry->d_un.d_val;
  9370. tmp = gmtime (&atime);
  9371. /* PR 17531: file: 6accc532. */
  9372. if (tmp == NULL)
  9373. snprintf (timebuf, sizeof (timebuf), _("<corrupt>"));
  9374. else
  9375. snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
  9376. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  9377. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  9378. printf (_("Time Stamp: %s"), timebuf);
  9379. }
  9380. break;
  9381. case DT_MIPS_RLD_VERSION:
  9382. case DT_MIPS_LOCAL_GOTNO:
  9383. case DT_MIPS_CONFLICTNO:
  9384. case DT_MIPS_LIBLISTNO:
  9385. case DT_MIPS_SYMTABNO:
  9386. case DT_MIPS_UNREFEXTNO:
  9387. case DT_MIPS_HIPAGENO:
  9388. case DT_MIPS_DELTA_CLASS_NO:
  9389. case DT_MIPS_DELTA_INSTANCE_NO:
  9390. case DT_MIPS_DELTA_RELOC_NO:
  9391. case DT_MIPS_DELTA_SYM_NO:
  9392. case DT_MIPS_DELTA_CLASSSYM_NO:
  9393. case DT_MIPS_COMPACT_SIZE:
  9394. print_vma (entry->d_un.d_val, DEC);
  9395. break;
  9396. case DT_MIPS_XHASH:
  9397. filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val;
  9398. filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
  9399. /* Falls through. */
  9400. default:
  9401. print_vma (entry->d_un.d_ptr, PREFIX_HEX);
  9402. }
  9403. putchar ('\n');
  9404. }
  9405. static void
  9406. dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
  9407. {
  9408. switch (entry->d_tag)
  9409. {
  9410. case DT_HP_DLD_FLAGS:
  9411. {
  9412. static struct
  9413. {
  9414. long int bit;
  9415. const char * str;
  9416. }
  9417. flags[] =
  9418. {
  9419. { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
  9420. { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
  9421. { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
  9422. { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
  9423. { DT_HP_BIND_NOW, "HP_BIND_NOW" },
  9424. { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
  9425. { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
  9426. { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
  9427. { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
  9428. { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
  9429. { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
  9430. { DT_HP_GST, "HP_GST" },
  9431. { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
  9432. { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
  9433. { DT_HP_NODELETE, "HP_NODELETE" },
  9434. { DT_HP_GROUP, "HP_GROUP" },
  9435. { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
  9436. };
  9437. bool first = true;
  9438. size_t cnt;
  9439. bfd_vma val = entry->d_un.d_val;
  9440. for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
  9441. if (val & flags[cnt].bit)
  9442. {
  9443. if (! first)
  9444. putchar (' ');
  9445. fputs (flags[cnt].str, stdout);
  9446. first = false;
  9447. val ^= flags[cnt].bit;
  9448. }
  9449. if (val != 0 || first)
  9450. {
  9451. if (! first)
  9452. putchar (' ');
  9453. print_vma (val, HEX);
  9454. }
  9455. }
  9456. break;
  9457. default:
  9458. print_vma (entry->d_un.d_ptr, PREFIX_HEX);
  9459. break;
  9460. }
  9461. putchar ('\n');
  9462. }
  9463. #ifdef BFD64
  9464. /* VMS vs Unix time offset and factor. */
  9465. #define VMS_EPOCH_OFFSET 35067168000000000LL
  9466. #define VMS_GRANULARITY_FACTOR 10000000
  9467. #ifndef INT64_MIN
  9468. #define INT64_MIN (-9223372036854775807LL - 1)
  9469. #endif
  9470. /* Display a VMS time in a human readable format. */
  9471. static void
  9472. print_vms_time (bfd_int64_t vmstime)
  9473. {
  9474. struct tm *tm = NULL;
  9475. time_t unxtime;
  9476. if (vmstime >= INT64_MIN + VMS_EPOCH_OFFSET)
  9477. {
  9478. vmstime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR;
  9479. unxtime = vmstime;
  9480. if (unxtime == vmstime)
  9481. tm = gmtime (&unxtime);
  9482. }
  9483. if (tm != NULL)
  9484. printf ("%04u-%02u-%02uT%02u:%02u:%02u",
  9485. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
  9486. tm->tm_hour, tm->tm_min, tm->tm_sec);
  9487. }
  9488. #endif /* BFD64 */
  9489. static void
  9490. dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
  9491. {
  9492. switch (entry->d_tag)
  9493. {
  9494. case DT_IA_64_PLT_RESERVE:
  9495. /* First 3 slots reserved. */
  9496. print_vma (entry->d_un.d_ptr, PREFIX_HEX);
  9497. printf (" -- ");
  9498. print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
  9499. break;
  9500. case DT_IA_64_VMS_LINKTIME:
  9501. #ifdef BFD64
  9502. print_vms_time (entry->d_un.d_val);
  9503. #endif
  9504. break;
  9505. case DT_IA_64_VMS_LNKFLAGS:
  9506. print_vma (entry->d_un.d_ptr, PREFIX_HEX);
  9507. if (entry->d_un.d_val & VMS_LF_CALL_DEBUG)
  9508. printf (" CALL_DEBUG");
  9509. if (entry->d_un.d_val & VMS_LF_NOP0BUFS)
  9510. printf (" NOP0BUFS");
  9511. if (entry->d_un.d_val & VMS_LF_P0IMAGE)
  9512. printf (" P0IMAGE");
  9513. if (entry->d_un.d_val & VMS_LF_MKTHREADS)
  9514. printf (" MKTHREADS");
  9515. if (entry->d_un.d_val & VMS_LF_UPCALLS)
  9516. printf (" UPCALLS");
  9517. if (entry->d_un.d_val & VMS_LF_IMGSTA)
  9518. printf (" IMGSTA");
  9519. if (entry->d_un.d_val & VMS_LF_INITIALIZE)
  9520. printf (" INITIALIZE");
  9521. if (entry->d_un.d_val & VMS_LF_MAIN)
  9522. printf (" MAIN");
  9523. if (entry->d_un.d_val & VMS_LF_EXE_INIT)
  9524. printf (" EXE_INIT");
  9525. if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG)
  9526. printf (" TBK_IN_IMG");
  9527. if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG)
  9528. printf (" DBG_IN_IMG");
  9529. if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF)
  9530. printf (" TBK_IN_DSF");
  9531. if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF)
  9532. printf (" DBG_IN_DSF");
  9533. if (entry->d_un.d_val & VMS_LF_SIGNATURES)
  9534. printf (" SIGNATURES");
  9535. if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF)
  9536. printf (" REL_SEG_OFF");
  9537. break;
  9538. default:
  9539. print_vma (entry->d_un.d_ptr, PREFIX_HEX);
  9540. break;
  9541. }
  9542. putchar ('\n');
  9543. }
  9544. static bool
  9545. get_32bit_dynamic_section (Filedata * filedata)
  9546. {
  9547. Elf32_External_Dyn * edyn;
  9548. Elf32_External_Dyn * ext;
  9549. Elf_Internal_Dyn * entry;
  9550. edyn = (Elf32_External_Dyn *) get_data (NULL, filedata,
  9551. filedata->dynamic_addr, 1,
  9552. filedata->dynamic_size,
  9553. _("dynamic section"));
  9554. if (!edyn)
  9555. return false;
  9556. /* SGI's ELF has more than one section in the DYNAMIC segment, and we
  9557. might not have the luxury of section headers. Look for the DT_NULL
  9558. terminator to determine the number of entries. */
  9559. for (ext = edyn, filedata->dynamic_nent = 0;
  9560. (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size;
  9561. ext++)
  9562. {
  9563. filedata->dynamic_nent++;
  9564. if (BYTE_GET (ext->d_tag) == DT_NULL)
  9565. break;
  9566. }
  9567. filedata->dynamic_section
  9568. = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry));
  9569. if (filedata->dynamic_section == NULL)
  9570. {
  9571. error (_("Out of memory allocating space for %lu dynamic entries\n"),
  9572. (unsigned long) filedata->dynamic_nent);
  9573. free (edyn);
  9574. return false;
  9575. }
  9576. for (ext = edyn, entry = filedata->dynamic_section;
  9577. entry < filedata->dynamic_section + filedata->dynamic_nent;
  9578. ext++, entry++)
  9579. {
  9580. entry->d_tag = BYTE_GET (ext->d_tag);
  9581. entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
  9582. }
  9583. free (edyn);
  9584. return true;
  9585. }
  9586. static bool
  9587. get_64bit_dynamic_section (Filedata * filedata)
  9588. {
  9589. Elf64_External_Dyn * edyn;
  9590. Elf64_External_Dyn * ext;
  9591. Elf_Internal_Dyn * entry;
  9592. /* Read in the data. */
  9593. edyn = (Elf64_External_Dyn *) get_data (NULL, filedata,
  9594. filedata->dynamic_addr, 1,
  9595. filedata->dynamic_size,
  9596. _("dynamic section"));
  9597. if (!edyn)
  9598. return false;
  9599. /* SGI's ELF has more than one section in the DYNAMIC segment, and we
  9600. might not have the luxury of section headers. Look for the DT_NULL
  9601. terminator to determine the number of entries. */
  9602. for (ext = edyn, filedata->dynamic_nent = 0;
  9603. /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
  9604. (char *) (ext + 1) <= (char *) edyn + filedata->dynamic_size;
  9605. ext++)
  9606. {
  9607. filedata->dynamic_nent++;
  9608. if (BYTE_GET (ext->d_tag) == DT_NULL)
  9609. break;
  9610. }
  9611. filedata->dynamic_section
  9612. = (Elf_Internal_Dyn *) cmalloc (filedata->dynamic_nent, sizeof (* entry));
  9613. if (filedata->dynamic_section == NULL)
  9614. {
  9615. error (_("Out of memory allocating space for %lu dynamic entries\n"),
  9616. (unsigned long) filedata->dynamic_nent);
  9617. free (edyn);
  9618. return false;
  9619. }
  9620. /* Convert from external to internal formats. */
  9621. for (ext = edyn, entry = filedata->dynamic_section;
  9622. entry < filedata->dynamic_section + filedata->dynamic_nent;
  9623. ext++, entry++)
  9624. {
  9625. entry->d_tag = BYTE_GET (ext->d_tag);
  9626. entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
  9627. }
  9628. free (edyn);
  9629. return true;
  9630. }
  9631. static bool
  9632. get_dynamic_section (Filedata *filedata)
  9633. {
  9634. if (filedata->dynamic_section)
  9635. return true;
  9636. if (is_32bit_elf)
  9637. return get_32bit_dynamic_section (filedata);
  9638. else
  9639. return get_64bit_dynamic_section (filedata);
  9640. }
  9641. static void
  9642. print_dynamic_flags (bfd_vma flags)
  9643. {
  9644. bool first = true;
  9645. while (flags)
  9646. {
  9647. bfd_vma flag;
  9648. flag = flags & - flags;
  9649. flags &= ~ flag;
  9650. if (first)
  9651. first = false;
  9652. else
  9653. putc (' ', stdout);
  9654. switch (flag)
  9655. {
  9656. case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
  9657. case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
  9658. case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
  9659. case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
  9660. case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
  9661. default: fputs (_("unknown"), stdout); break;
  9662. }
  9663. }
  9664. puts ("");
  9665. }
  9666. static bfd_vma *
  9667. get_dynamic_data (Filedata * filedata, bfd_size_type number, unsigned int ent_size)
  9668. {
  9669. unsigned char * e_data;
  9670. bfd_vma * i_data;
  9671. /* If the size_t type is smaller than the bfd_size_type, eg because
  9672. you are building a 32-bit tool on a 64-bit host, then make sure
  9673. that when (number) is cast to (size_t) no information is lost. */
  9674. if (sizeof (size_t) < sizeof (bfd_size_type)
  9675. && (bfd_size_type) ((size_t) number) != number)
  9676. {
  9677. error (_("Size truncation prevents reading %s elements of size %u\n"),
  9678. bfd_vmatoa ("u", number), ent_size);
  9679. return NULL;
  9680. }
  9681. /* Be kind to memory checkers (eg valgrind, address sanitizer) by not
  9682. attempting to allocate memory when the read is bound to fail. */
  9683. if (ent_size * number > filedata->file_size)
  9684. {
  9685. error (_("Invalid number of dynamic entries: %s\n"),
  9686. bfd_vmatoa ("u", number));
  9687. return NULL;
  9688. }
  9689. e_data = (unsigned char *) cmalloc ((size_t) number, ent_size);
  9690. if (e_data == NULL)
  9691. {
  9692. error (_("Out of memory reading %s dynamic entries\n"),
  9693. bfd_vmatoa ("u", number));
  9694. return NULL;
  9695. }
  9696. if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number)
  9697. {
  9698. error (_("Unable to read in %s bytes of dynamic data\n"),
  9699. bfd_vmatoa ("u", number * ent_size));
  9700. free (e_data);
  9701. return NULL;
  9702. }
  9703. i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data));
  9704. if (i_data == NULL)
  9705. {
  9706. error (_("Out of memory allocating space for %s dynamic entries\n"),
  9707. bfd_vmatoa ("u", number));
  9708. free (e_data);
  9709. return NULL;
  9710. }
  9711. while (number--)
  9712. i_data[number] = byte_get (e_data + number * ent_size, ent_size);
  9713. free (e_data);
  9714. return i_data;
  9715. }
  9716. static unsigned long
  9717. get_num_dynamic_syms (Filedata * filedata)
  9718. {
  9719. unsigned long num_of_syms = 0;
  9720. if (!do_histogram && (!do_using_dynamic || do_dyn_syms))
  9721. return num_of_syms;
  9722. if (filedata->dynamic_info[DT_HASH])
  9723. {
  9724. unsigned char nb[8];
  9725. unsigned char nc[8];
  9726. unsigned int hash_ent_size = 4;
  9727. if ((filedata->file_header.e_machine == EM_ALPHA
  9728. || filedata->file_header.e_machine == EM_S390
  9729. || filedata->file_header.e_machine == EM_S390_OLD)
  9730. && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64)
  9731. hash_ent_size = 8;
  9732. if (fseek (filedata->handle,
  9733. (filedata->archive_file_offset
  9734. + offset_from_vma (filedata, filedata->dynamic_info[DT_HASH],
  9735. sizeof nb + sizeof nc)),
  9736. SEEK_SET))
  9737. {
  9738. error (_("Unable to seek to start of dynamic information\n"));
  9739. goto no_hash;
  9740. }
  9741. if (fread (nb, hash_ent_size, 1, filedata->handle) != 1)
  9742. {
  9743. error (_("Failed to read in number of buckets\n"));
  9744. goto no_hash;
  9745. }
  9746. if (fread (nc, hash_ent_size, 1, filedata->handle) != 1)
  9747. {
  9748. error (_("Failed to read in number of chains\n"));
  9749. goto no_hash;
  9750. }
  9751. filedata->nbuckets = byte_get (nb, hash_ent_size);
  9752. filedata->nchains = byte_get (nc, hash_ent_size);
  9753. if (filedata->nbuckets != 0 && filedata->nchains != 0)
  9754. {
  9755. filedata->buckets = get_dynamic_data (filedata, filedata->nbuckets,
  9756. hash_ent_size);
  9757. filedata->chains = get_dynamic_data (filedata, filedata->nchains,
  9758. hash_ent_size);
  9759. if (filedata->buckets != NULL && filedata->chains != NULL)
  9760. num_of_syms = filedata->nchains;
  9761. }
  9762. no_hash:
  9763. if (num_of_syms == 0)
  9764. {
  9765. free (filedata->buckets);
  9766. filedata->buckets = NULL;
  9767. free (filedata->chains);
  9768. filedata->chains = NULL;
  9769. filedata->nbuckets = 0;
  9770. }
  9771. }
  9772. if (filedata->dynamic_info_DT_GNU_HASH)
  9773. {
  9774. unsigned char nb[16];
  9775. bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
  9776. bfd_vma buckets_vma;
  9777. unsigned long hn;
  9778. if (fseek (filedata->handle,
  9779. (filedata->archive_file_offset
  9780. + offset_from_vma (filedata,
  9781. filedata->dynamic_info_DT_GNU_HASH,
  9782. sizeof nb)),
  9783. SEEK_SET))
  9784. {
  9785. error (_("Unable to seek to start of dynamic information\n"));
  9786. goto no_gnu_hash;
  9787. }
  9788. if (fread (nb, 16, 1, filedata->handle) != 1)
  9789. {
  9790. error (_("Failed to read in number of buckets\n"));
  9791. goto no_gnu_hash;
  9792. }
  9793. filedata->ngnubuckets = byte_get (nb, 4);
  9794. filedata->gnusymidx = byte_get (nb + 4, 4);
  9795. bitmaskwords = byte_get (nb + 8, 4);
  9796. buckets_vma = filedata->dynamic_info_DT_GNU_HASH + 16;
  9797. if (is_32bit_elf)
  9798. buckets_vma += bitmaskwords * 4;
  9799. else
  9800. buckets_vma += bitmaskwords * 8;
  9801. if (fseek (filedata->handle,
  9802. (filedata->archive_file_offset
  9803. + offset_from_vma (filedata, buckets_vma, 4)),
  9804. SEEK_SET))
  9805. {
  9806. error (_("Unable to seek to start of dynamic information\n"));
  9807. goto no_gnu_hash;
  9808. }
  9809. filedata->gnubuckets
  9810. = get_dynamic_data (filedata, filedata->ngnubuckets, 4);
  9811. if (filedata->gnubuckets == NULL)
  9812. goto no_gnu_hash;
  9813. for (i = 0; i < filedata->ngnubuckets; i++)
  9814. if (filedata->gnubuckets[i] != 0)
  9815. {
  9816. if (filedata->gnubuckets[i] < filedata->gnusymidx)
  9817. goto no_gnu_hash;
  9818. if (maxchain == 0xffffffff || filedata->gnubuckets[i] > maxchain)
  9819. maxchain = filedata->gnubuckets[i];
  9820. }
  9821. if (maxchain == 0xffffffff)
  9822. goto no_gnu_hash;
  9823. maxchain -= filedata->gnusymidx;
  9824. if (fseek (filedata->handle,
  9825. (filedata->archive_file_offset
  9826. + offset_from_vma (filedata,
  9827. buckets_vma + 4 * (filedata->ngnubuckets
  9828. + maxchain),
  9829. 4)),
  9830. SEEK_SET))
  9831. {
  9832. error (_("Unable to seek to start of dynamic information\n"));
  9833. goto no_gnu_hash;
  9834. }
  9835. do
  9836. {
  9837. if (fread (nb, 4, 1, filedata->handle) != 1)
  9838. {
  9839. error (_("Failed to determine last chain length\n"));
  9840. goto no_gnu_hash;
  9841. }
  9842. if (maxchain + 1 == 0)
  9843. goto no_gnu_hash;
  9844. ++maxchain;
  9845. }
  9846. while ((byte_get (nb, 4) & 1) == 0);
  9847. if (fseek (filedata->handle,
  9848. (filedata->archive_file_offset
  9849. + offset_from_vma (filedata, (buckets_vma
  9850. + 4 * filedata->ngnubuckets),
  9851. 4)),
  9852. SEEK_SET))
  9853. {
  9854. error (_("Unable to seek to start of dynamic information\n"));
  9855. goto no_gnu_hash;
  9856. }
  9857. filedata->gnuchains = get_dynamic_data (filedata, maxchain, 4);
  9858. filedata->ngnuchains = maxchain;
  9859. if (filedata->gnuchains == NULL)
  9860. goto no_gnu_hash;
  9861. if (filedata->dynamic_info_DT_MIPS_XHASH)
  9862. {
  9863. if (fseek (filedata->handle,
  9864. (filedata->archive_file_offset
  9865. + offset_from_vma (filedata, (buckets_vma
  9866. + 4 * (filedata->ngnubuckets
  9867. + maxchain)), 4)),
  9868. SEEK_SET))
  9869. {
  9870. error (_("Unable to seek to start of dynamic information\n"));
  9871. goto no_gnu_hash;
  9872. }
  9873. filedata->mipsxlat = get_dynamic_data (filedata, maxchain, 4);
  9874. if (filedata->mipsxlat == NULL)
  9875. goto no_gnu_hash;
  9876. }
  9877. for (hn = 0; hn < filedata->ngnubuckets; ++hn)
  9878. if (filedata->gnubuckets[hn] != 0)
  9879. {
  9880. bfd_vma si = filedata->gnubuckets[hn];
  9881. bfd_vma off = si - filedata->gnusymidx;
  9882. do
  9883. {
  9884. if (filedata->dynamic_info_DT_MIPS_XHASH)
  9885. {
  9886. if (off < filedata->ngnuchains
  9887. && filedata->mipsxlat[off] >= num_of_syms)
  9888. num_of_syms = filedata->mipsxlat[off] + 1;
  9889. }
  9890. else
  9891. {
  9892. if (si >= num_of_syms)
  9893. num_of_syms = si + 1;
  9894. }
  9895. si++;
  9896. }
  9897. while (off < filedata->ngnuchains
  9898. && (filedata->gnuchains[off++] & 1) == 0);
  9899. }
  9900. if (num_of_syms == 0)
  9901. {
  9902. no_gnu_hash:
  9903. free (filedata->mipsxlat);
  9904. filedata->mipsxlat = NULL;
  9905. free (filedata->gnuchains);
  9906. filedata->gnuchains = NULL;
  9907. free (filedata->gnubuckets);
  9908. filedata->gnubuckets = NULL;
  9909. filedata->ngnubuckets = 0;
  9910. filedata->ngnuchains = 0;
  9911. }
  9912. }
  9913. return num_of_syms;
  9914. }
  9915. /* Parse and display the contents of the dynamic section. */
  9916. static bool
  9917. process_dynamic_section (Filedata * filedata)
  9918. {
  9919. Elf_Internal_Dyn * entry;
  9920. if (filedata->dynamic_size <= 1)
  9921. {
  9922. if (do_dynamic)
  9923. {
  9924. if (filedata->is_separate)
  9925. printf (_("\nThere is no dynamic section in linked file '%s'.\n"),
  9926. filedata->file_name);
  9927. else
  9928. printf (_("\nThere is no dynamic section in this file.\n"));
  9929. }
  9930. return true;
  9931. }
  9932. if (!get_dynamic_section (filedata))
  9933. return false;
  9934. /* Find the appropriate symbol table. */
  9935. if (filedata->dynamic_symbols == NULL || do_histogram)
  9936. {
  9937. unsigned long num_of_syms;
  9938. for (entry = filedata->dynamic_section;
  9939. entry < filedata->dynamic_section + filedata->dynamic_nent;
  9940. ++entry)
  9941. if (entry->d_tag == DT_SYMTAB)
  9942. filedata->dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
  9943. else if (entry->d_tag == DT_SYMENT)
  9944. filedata->dynamic_info[DT_SYMENT] = entry->d_un.d_val;
  9945. else if (entry->d_tag == DT_HASH)
  9946. filedata->dynamic_info[DT_HASH] = entry->d_un.d_val;
  9947. else if (entry->d_tag == DT_GNU_HASH)
  9948. filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
  9949. else if ((filedata->file_header.e_machine == EM_MIPS
  9950. || filedata->file_header.e_machine == EM_MIPS_RS3_LE)
  9951. && entry->d_tag == DT_MIPS_XHASH)
  9952. {
  9953. filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val;
  9954. filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
  9955. }
  9956. num_of_syms = get_num_dynamic_syms (filedata);
  9957. if (num_of_syms != 0
  9958. && filedata->dynamic_symbols == NULL
  9959. && filedata->dynamic_info[DT_SYMTAB]
  9960. && filedata->dynamic_info[DT_SYMENT])
  9961. {
  9962. Elf_Internal_Phdr *seg;
  9963. bfd_vma vma = filedata->dynamic_info[DT_SYMTAB];
  9964. if (! get_program_headers (filedata))
  9965. {
  9966. error (_("Cannot interpret virtual addresses "
  9967. "without program headers.\n"));
  9968. return false;
  9969. }
  9970. for (seg = filedata->program_headers;
  9971. seg < filedata->program_headers + filedata->file_header.e_phnum;
  9972. ++seg)
  9973. {
  9974. if (seg->p_type != PT_LOAD)
  9975. continue;
  9976. if (seg->p_offset + seg->p_filesz > filedata->file_size)
  9977. {
  9978. /* See PR 21379 for a reproducer. */
  9979. error (_("Invalid PT_LOAD entry\n"));
  9980. return false;
  9981. }
  9982. if (vma >= (seg->p_vaddr & -seg->p_align)
  9983. && vma < seg->p_vaddr + seg->p_filesz)
  9984. {
  9985. /* Since we do not know how big the symbol table is,
  9986. we default to reading in up to the end of PT_LOAD
  9987. segment and processing that. This is overkill, I
  9988. know, but it should work. */
  9989. Elf_Internal_Shdr section;
  9990. section.sh_offset = (vma - seg->p_vaddr
  9991. + seg->p_offset);
  9992. section.sh_size = (num_of_syms
  9993. * filedata->dynamic_info[DT_SYMENT]);
  9994. section.sh_entsize = filedata->dynamic_info[DT_SYMENT];
  9995. if (do_checks
  9996. && filedata->dynamic_symtab_section != NULL
  9997. && ((filedata->dynamic_symtab_section->sh_offset
  9998. != section.sh_offset)
  9999. || (filedata->dynamic_symtab_section->sh_size
  10000. != section.sh_size)
  10001. || (filedata->dynamic_symtab_section->sh_entsize
  10002. != section.sh_entsize)))
  10003. warn (_("\
  10004. the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
  10005. section.sh_name = filedata->string_table_length;
  10006. filedata->dynamic_symbols
  10007. = get_elf_symbols (filedata, &section,
  10008. &filedata->num_dynamic_syms);
  10009. if (filedata->dynamic_symbols == NULL
  10010. || filedata->num_dynamic_syms != num_of_syms)
  10011. {
  10012. error (_("Corrupt DT_SYMTAB dynamic entry\n"));
  10013. return false;
  10014. }
  10015. break;
  10016. }
  10017. }
  10018. }
  10019. }
  10020. /* Similarly find a string table. */
  10021. if (filedata->dynamic_strings == NULL)
  10022. for (entry = filedata->dynamic_section;
  10023. entry < filedata->dynamic_section + filedata->dynamic_nent;
  10024. ++entry)
  10025. {
  10026. if (entry->d_tag == DT_STRTAB)
  10027. filedata->dynamic_info[DT_STRTAB] = entry->d_un.d_val;
  10028. if (entry->d_tag == DT_STRSZ)
  10029. filedata->dynamic_info[DT_STRSZ] = entry->d_un.d_val;
  10030. if (filedata->dynamic_info[DT_STRTAB]
  10031. && filedata->dynamic_info[DT_STRSZ])
  10032. {
  10033. unsigned long offset;
  10034. bfd_size_type str_tab_len = filedata->dynamic_info[DT_STRSZ];
  10035. offset = offset_from_vma (filedata,
  10036. filedata->dynamic_info[DT_STRTAB],
  10037. str_tab_len);
  10038. if (do_checks
  10039. && filedata->dynamic_strtab_section
  10040. && ((filedata->dynamic_strtab_section->sh_offset
  10041. != (file_ptr) offset)
  10042. || (filedata->dynamic_strtab_section->sh_size
  10043. != str_tab_len)))
  10044. warn (_("\
  10045. the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
  10046. filedata->dynamic_strings
  10047. = (char *) get_data (NULL, filedata, offset, 1, str_tab_len,
  10048. _("dynamic string table"));
  10049. if (filedata->dynamic_strings == NULL)
  10050. {
  10051. error (_("Corrupt DT_STRTAB dynamic entry\n"));
  10052. break;
  10053. }
  10054. filedata->dynamic_strings_length = str_tab_len;
  10055. break;
  10056. }
  10057. }
  10058. /* And find the syminfo section if available. */
  10059. if (filedata->dynamic_syminfo == NULL)
  10060. {
  10061. unsigned long syminsz = 0;
  10062. for (entry = filedata->dynamic_section;
  10063. entry < filedata->dynamic_section + filedata->dynamic_nent;
  10064. ++entry)
  10065. {
  10066. if (entry->d_tag == DT_SYMINENT)
  10067. {
  10068. /* Note: these braces are necessary to avoid a syntax
  10069. error from the SunOS4 C compiler. */
  10070. /* PR binutils/17531: A corrupt file can trigger this test.
  10071. So do not use an assert, instead generate an error message. */
  10072. if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val)
  10073. error (_("Bad value (%d) for SYMINENT entry\n"),
  10074. (int) entry->d_un.d_val);
  10075. }
  10076. else if (entry->d_tag == DT_SYMINSZ)
  10077. syminsz = entry->d_un.d_val;
  10078. else if (entry->d_tag == DT_SYMINFO)
  10079. filedata->dynamic_syminfo_offset
  10080. = offset_from_vma (filedata, entry->d_un.d_val, syminsz);
  10081. }
  10082. if (filedata->dynamic_syminfo_offset != 0 && syminsz != 0)
  10083. {
  10084. Elf_External_Syminfo * extsyminfo;
  10085. Elf_External_Syminfo * extsym;
  10086. Elf_Internal_Syminfo * syminfo;
  10087. /* There is a syminfo section. Read the data. */
  10088. extsyminfo = (Elf_External_Syminfo *)
  10089. get_data (NULL, filedata, filedata->dynamic_syminfo_offset,
  10090. 1, syminsz, _("symbol information"));
  10091. if (!extsyminfo)
  10092. return false;
  10093. if (filedata->dynamic_syminfo != NULL)
  10094. {
  10095. error (_("Multiple dynamic symbol information sections found\n"));
  10096. free (filedata->dynamic_syminfo);
  10097. }
  10098. filedata->dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
  10099. if (filedata->dynamic_syminfo == NULL)
  10100. {
  10101. error (_("Out of memory allocating %lu bytes "
  10102. "for dynamic symbol info\n"),
  10103. (unsigned long) syminsz);
  10104. return false;
  10105. }
  10106. filedata->dynamic_syminfo_nent
  10107. = syminsz / sizeof (Elf_External_Syminfo);
  10108. for (syminfo = filedata->dynamic_syminfo, extsym = extsyminfo;
  10109. syminfo < (filedata->dynamic_syminfo
  10110. + filedata->dynamic_syminfo_nent);
  10111. ++syminfo, ++extsym)
  10112. {
  10113. syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
  10114. syminfo->si_flags = BYTE_GET (extsym->si_flags);
  10115. }
  10116. free (extsyminfo);
  10117. }
  10118. }
  10119. if (do_dynamic && filedata->dynamic_addr)
  10120. {
  10121. if (filedata->is_separate)
  10122. printf (ngettext ("\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entry:\n",
  10123. "\nIn linked file '%s' the dynamic section at offset 0x%lx contains %lu entries:\n",
  10124. (unsigned long) filedata->dynamic_nent),
  10125. filedata->file_name,
  10126. filedata->dynamic_addr,
  10127. (unsigned long) filedata->dynamic_nent);
  10128. else
  10129. printf (ngettext ("\nDynamic section at offset 0x%lx contains %lu entry:\n",
  10130. "\nDynamic section at offset 0x%lx contains %lu entries:\n",
  10131. (unsigned long) filedata->dynamic_nent),
  10132. filedata->dynamic_addr,
  10133. (unsigned long) filedata->dynamic_nent);
  10134. }
  10135. if (do_dynamic)
  10136. printf (_(" Tag Type Name/Value\n"));
  10137. for (entry = filedata->dynamic_section;
  10138. entry < filedata->dynamic_section + filedata->dynamic_nent;
  10139. entry++)
  10140. {
  10141. if (do_dynamic)
  10142. {
  10143. const char * dtype;
  10144. putchar (' ');
  10145. print_vma (entry->d_tag, FULL_HEX);
  10146. dtype = get_dynamic_type (filedata, entry->d_tag);
  10147. printf (" (%s)%*s", dtype,
  10148. ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " ");
  10149. }
  10150. switch (entry->d_tag)
  10151. {
  10152. case DT_FLAGS:
  10153. if (do_dynamic)
  10154. print_dynamic_flags (entry->d_un.d_val);
  10155. break;
  10156. case DT_AUXILIARY:
  10157. case DT_FILTER:
  10158. case DT_CONFIG:
  10159. case DT_DEPAUDIT:
  10160. case DT_AUDIT:
  10161. if (do_dynamic)
  10162. {
  10163. switch (entry->d_tag)
  10164. {
  10165. case DT_AUXILIARY:
  10166. printf (_("Auxiliary library"));
  10167. break;
  10168. case DT_FILTER:
  10169. printf (_("Filter library"));
  10170. break;
  10171. case DT_CONFIG:
  10172. printf (_("Configuration file"));
  10173. break;
  10174. case DT_DEPAUDIT:
  10175. printf (_("Dependency audit library"));
  10176. break;
  10177. case DT_AUDIT:
  10178. printf (_("Audit library"));
  10179. break;
  10180. }
  10181. if (valid_dynamic_name (filedata, entry->d_un.d_val))
  10182. printf (": [%s]\n",
  10183. get_dynamic_name (filedata, entry->d_un.d_val));
  10184. else
  10185. {
  10186. printf (": ");
  10187. print_vma (entry->d_un.d_val, PREFIX_HEX);
  10188. putchar ('\n');
  10189. }
  10190. }
  10191. break;
  10192. case DT_FEATURE:
  10193. if (do_dynamic)
  10194. {
  10195. printf (_("Flags:"));
  10196. if (entry->d_un.d_val == 0)
  10197. printf (_(" None\n"));
  10198. else
  10199. {
  10200. unsigned long int val = entry->d_un.d_val;
  10201. if (val & DTF_1_PARINIT)
  10202. {
  10203. printf (" PARINIT");
  10204. val ^= DTF_1_PARINIT;
  10205. }
  10206. if (val & DTF_1_CONFEXP)
  10207. {
  10208. printf (" CONFEXP");
  10209. val ^= DTF_1_CONFEXP;
  10210. }
  10211. if (val != 0)
  10212. printf (" %lx", val);
  10213. puts ("");
  10214. }
  10215. }
  10216. break;
  10217. case DT_POSFLAG_1:
  10218. if (do_dynamic)
  10219. {
  10220. printf (_("Flags:"));
  10221. if (entry->d_un.d_val == 0)
  10222. printf (_(" None\n"));
  10223. else
  10224. {
  10225. unsigned long int val = entry->d_un.d_val;
  10226. if (val & DF_P1_LAZYLOAD)
  10227. {
  10228. printf (" LAZYLOAD");
  10229. val ^= DF_P1_LAZYLOAD;
  10230. }
  10231. if (val & DF_P1_GROUPPERM)
  10232. {
  10233. printf (" GROUPPERM");
  10234. val ^= DF_P1_GROUPPERM;
  10235. }
  10236. if (val != 0)
  10237. printf (" %lx", val);
  10238. puts ("");
  10239. }
  10240. }
  10241. break;
  10242. case DT_FLAGS_1:
  10243. if (do_dynamic)
  10244. {
  10245. printf (_("Flags:"));
  10246. if (entry->d_un.d_val == 0)
  10247. printf (_(" None\n"));
  10248. else
  10249. {
  10250. unsigned long int val = entry->d_un.d_val;
  10251. if (val & DF_1_NOW)
  10252. {
  10253. printf (" NOW");
  10254. val ^= DF_1_NOW;
  10255. }
  10256. if (val & DF_1_GLOBAL)
  10257. {
  10258. printf (" GLOBAL");
  10259. val ^= DF_1_GLOBAL;
  10260. }
  10261. if (val & DF_1_GROUP)
  10262. {
  10263. printf (" GROUP");
  10264. val ^= DF_1_GROUP;
  10265. }
  10266. if (val & DF_1_NODELETE)
  10267. {
  10268. printf (" NODELETE");
  10269. val ^= DF_1_NODELETE;
  10270. }
  10271. if (val & DF_1_LOADFLTR)
  10272. {
  10273. printf (" LOADFLTR");
  10274. val ^= DF_1_LOADFLTR;
  10275. }
  10276. if (val & DF_1_INITFIRST)
  10277. {
  10278. printf (" INITFIRST");
  10279. val ^= DF_1_INITFIRST;
  10280. }
  10281. if (val & DF_1_NOOPEN)
  10282. {
  10283. printf (" NOOPEN");
  10284. val ^= DF_1_NOOPEN;
  10285. }
  10286. if (val & DF_1_ORIGIN)
  10287. {
  10288. printf (" ORIGIN");
  10289. val ^= DF_1_ORIGIN;
  10290. }
  10291. if (val & DF_1_DIRECT)
  10292. {
  10293. printf (" DIRECT");
  10294. val ^= DF_1_DIRECT;
  10295. }
  10296. if (val & DF_1_TRANS)
  10297. {
  10298. printf (" TRANS");
  10299. val ^= DF_1_TRANS;
  10300. }
  10301. if (val & DF_1_INTERPOSE)
  10302. {
  10303. printf (" INTERPOSE");
  10304. val ^= DF_1_INTERPOSE;
  10305. }
  10306. if (val & DF_1_NODEFLIB)
  10307. {
  10308. printf (" NODEFLIB");
  10309. val ^= DF_1_NODEFLIB;
  10310. }
  10311. if (val & DF_1_NODUMP)
  10312. {
  10313. printf (" NODUMP");
  10314. val ^= DF_1_NODUMP;
  10315. }
  10316. if (val & DF_1_CONFALT)
  10317. {
  10318. printf (" CONFALT");
  10319. val ^= DF_1_CONFALT;
  10320. }
  10321. if (val & DF_1_ENDFILTEE)
  10322. {
  10323. printf (" ENDFILTEE");
  10324. val ^= DF_1_ENDFILTEE;
  10325. }
  10326. if (val & DF_1_DISPRELDNE)
  10327. {
  10328. printf (" DISPRELDNE");
  10329. val ^= DF_1_DISPRELDNE;
  10330. }
  10331. if (val & DF_1_DISPRELPND)
  10332. {
  10333. printf (" DISPRELPND");
  10334. val ^= DF_1_DISPRELPND;
  10335. }
  10336. if (val & DF_1_NODIRECT)
  10337. {
  10338. printf (" NODIRECT");
  10339. val ^= DF_1_NODIRECT;
  10340. }
  10341. if (val & DF_1_IGNMULDEF)
  10342. {
  10343. printf (" IGNMULDEF");
  10344. val ^= DF_1_IGNMULDEF;
  10345. }
  10346. if (val & DF_1_NOKSYMS)
  10347. {
  10348. printf (" NOKSYMS");
  10349. val ^= DF_1_NOKSYMS;
  10350. }
  10351. if (val & DF_1_NOHDR)
  10352. {
  10353. printf (" NOHDR");
  10354. val ^= DF_1_NOHDR;
  10355. }
  10356. if (val & DF_1_EDITED)
  10357. {
  10358. printf (" EDITED");
  10359. val ^= DF_1_EDITED;
  10360. }
  10361. if (val & DF_1_NORELOC)
  10362. {
  10363. printf (" NORELOC");
  10364. val ^= DF_1_NORELOC;
  10365. }
  10366. if (val & DF_1_SYMINTPOSE)
  10367. {
  10368. printf (" SYMINTPOSE");
  10369. val ^= DF_1_SYMINTPOSE;
  10370. }
  10371. if (val & DF_1_GLOBAUDIT)
  10372. {
  10373. printf (" GLOBAUDIT");
  10374. val ^= DF_1_GLOBAUDIT;
  10375. }
  10376. if (val & DF_1_SINGLETON)
  10377. {
  10378. printf (" SINGLETON");
  10379. val ^= DF_1_SINGLETON;
  10380. }
  10381. if (val & DF_1_STUB)
  10382. {
  10383. printf (" STUB");
  10384. val ^= DF_1_STUB;
  10385. }
  10386. if (val & DF_1_PIE)
  10387. {
  10388. printf (" PIE");
  10389. val ^= DF_1_PIE;
  10390. }
  10391. if (val & DF_1_KMOD)
  10392. {
  10393. printf (" KMOD");
  10394. val ^= DF_1_KMOD;
  10395. }
  10396. if (val & DF_1_WEAKFILTER)
  10397. {
  10398. printf (" WEAKFILTER");
  10399. val ^= DF_1_WEAKFILTER;
  10400. }
  10401. if (val & DF_1_NOCOMMON)
  10402. {
  10403. printf (" NOCOMMON");
  10404. val ^= DF_1_NOCOMMON;
  10405. }
  10406. if (val != 0)
  10407. printf (" %lx", val);
  10408. puts ("");
  10409. }
  10410. }
  10411. break;
  10412. case DT_PLTREL:
  10413. filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val;
  10414. if (do_dynamic)
  10415. puts (get_dynamic_type (filedata, entry->d_un.d_val));
  10416. break;
  10417. case DT_NULL :
  10418. case DT_NEEDED :
  10419. case DT_PLTGOT :
  10420. case DT_HASH :
  10421. case DT_STRTAB :
  10422. case DT_SYMTAB :
  10423. case DT_RELA :
  10424. case DT_INIT :
  10425. case DT_FINI :
  10426. case DT_SONAME :
  10427. case DT_RPATH :
  10428. case DT_SYMBOLIC:
  10429. case DT_REL :
  10430. case DT_RELR :
  10431. case DT_DEBUG :
  10432. case DT_TEXTREL :
  10433. case DT_JMPREL :
  10434. case DT_RUNPATH :
  10435. filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val;
  10436. if (do_dynamic)
  10437. {
  10438. const char *name;
  10439. if (valid_dynamic_name (filedata, entry->d_un.d_val))
  10440. name = get_dynamic_name (filedata, entry->d_un.d_val);
  10441. else
  10442. name = NULL;
  10443. if (name)
  10444. {
  10445. switch (entry->d_tag)
  10446. {
  10447. case DT_NEEDED:
  10448. printf (_("Shared library: [%s]"), name);
  10449. if (filedata->program_interpreter
  10450. && streq (name, filedata->program_interpreter))
  10451. printf (_(" program interpreter"));
  10452. break;
  10453. case DT_SONAME:
  10454. printf (_("Library soname: [%s]"), name);
  10455. break;
  10456. case DT_RPATH:
  10457. printf (_("Library rpath: [%s]"), name);
  10458. break;
  10459. case DT_RUNPATH:
  10460. printf (_("Library runpath: [%s]"), name);
  10461. break;
  10462. default:
  10463. print_vma (entry->d_un.d_val, PREFIX_HEX);
  10464. break;
  10465. }
  10466. }
  10467. else
  10468. print_vma (entry->d_un.d_val, PREFIX_HEX);
  10469. putchar ('\n');
  10470. }
  10471. break;
  10472. case DT_PLTRELSZ:
  10473. case DT_RELASZ :
  10474. case DT_STRSZ :
  10475. case DT_RELSZ :
  10476. case DT_RELAENT :
  10477. case DT_RELRENT :
  10478. case DT_RELRSZ :
  10479. case DT_SYMENT :
  10480. case DT_RELENT :
  10481. filedata->dynamic_info[entry->d_tag] = entry->d_un.d_val;
  10482. /* Fall through. */
  10483. case DT_PLTPADSZ:
  10484. case DT_MOVEENT :
  10485. case DT_MOVESZ :
  10486. case DT_PREINIT_ARRAYSZ:
  10487. case DT_INIT_ARRAYSZ:
  10488. case DT_FINI_ARRAYSZ:
  10489. case DT_GNU_CONFLICTSZ:
  10490. case DT_GNU_LIBLISTSZ:
  10491. if (do_dynamic)
  10492. {
  10493. print_vma (entry->d_un.d_val, UNSIGNED);
  10494. printf (_(" (bytes)\n"));
  10495. }
  10496. break;
  10497. case DT_VERDEFNUM:
  10498. case DT_VERNEEDNUM:
  10499. case DT_RELACOUNT:
  10500. case DT_RELCOUNT:
  10501. if (do_dynamic)
  10502. {
  10503. print_vma (entry->d_un.d_val, UNSIGNED);
  10504. putchar ('\n');
  10505. }
  10506. break;
  10507. case DT_SYMINSZ:
  10508. case DT_SYMINENT:
  10509. case DT_SYMINFO:
  10510. case DT_USED:
  10511. case DT_INIT_ARRAY:
  10512. case DT_FINI_ARRAY:
  10513. if (do_dynamic)
  10514. {
  10515. if (entry->d_tag == DT_USED
  10516. && valid_dynamic_name (filedata, entry->d_un.d_val))
  10517. {
  10518. const char *name
  10519. = get_dynamic_name (filedata, entry->d_un.d_val);
  10520. if (*name)
  10521. {
  10522. printf (_("Not needed object: [%s]\n"), name);
  10523. break;
  10524. }
  10525. }
  10526. print_vma (entry->d_un.d_val, PREFIX_HEX);
  10527. putchar ('\n');
  10528. }
  10529. break;
  10530. case DT_BIND_NOW:
  10531. /* The value of this entry is ignored. */
  10532. if (do_dynamic)
  10533. putchar ('\n');
  10534. break;
  10535. case DT_GNU_PRELINKED:
  10536. if (do_dynamic)
  10537. {
  10538. struct tm * tmp;
  10539. time_t atime = entry->d_un.d_val;
  10540. tmp = gmtime (&atime);
  10541. /* PR 17533 file: 041-1244816-0.004. */
  10542. if (tmp == NULL)
  10543. printf (_("<corrupt time val: %lx"),
  10544. (unsigned long) atime);
  10545. else
  10546. printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
  10547. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  10548. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  10549. }
  10550. break;
  10551. case DT_GNU_HASH:
  10552. filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
  10553. if (do_dynamic)
  10554. {
  10555. print_vma (entry->d_un.d_val, PREFIX_HEX);
  10556. putchar ('\n');
  10557. }
  10558. break;
  10559. case DT_GNU_FLAGS_1:
  10560. if (do_dynamic)
  10561. {
  10562. printf (_("Flags:"));
  10563. if (entry->d_un.d_val == 0)
  10564. printf (_(" None\n"));
  10565. else
  10566. {
  10567. unsigned long int val = entry->d_un.d_val;
  10568. if (val & DF_GNU_1_UNIQUE)
  10569. {
  10570. printf (" UNIQUE");
  10571. val ^= DF_GNU_1_UNIQUE;
  10572. }
  10573. if (val != 0)
  10574. printf (" %lx", val);
  10575. puts ("");
  10576. }
  10577. }
  10578. break;
  10579. default:
  10580. if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
  10581. filedata->version_info[DT_VERSIONTAGIDX (entry->d_tag)]
  10582. = entry->d_un.d_val;
  10583. if (do_dynamic)
  10584. {
  10585. switch (filedata->file_header.e_machine)
  10586. {
  10587. case EM_AARCH64:
  10588. dynamic_section_aarch64_val (entry);
  10589. break;
  10590. case EM_MIPS:
  10591. case EM_MIPS_RS3_LE:
  10592. dynamic_section_mips_val (filedata, entry);
  10593. break;
  10594. case EM_PARISC:
  10595. dynamic_section_parisc_val (entry);
  10596. break;
  10597. case EM_IA_64:
  10598. dynamic_section_ia64_val (entry);
  10599. break;
  10600. default:
  10601. print_vma (entry->d_un.d_val, PREFIX_HEX);
  10602. putchar ('\n');
  10603. }
  10604. }
  10605. break;
  10606. }
  10607. }
  10608. return true;
  10609. }
  10610. static char *
  10611. get_ver_flags (unsigned int flags)
  10612. {
  10613. static char buff[128];
  10614. buff[0] = 0;
  10615. if (flags == 0)
  10616. return _("none");
  10617. if (flags & VER_FLG_BASE)
  10618. strcat (buff, "BASE");
  10619. if (flags & VER_FLG_WEAK)
  10620. {
  10621. if (flags & VER_FLG_BASE)
  10622. strcat (buff, " | ");
  10623. strcat (buff, "WEAK");
  10624. }
  10625. if (flags & VER_FLG_INFO)
  10626. {
  10627. if (flags & (VER_FLG_BASE|VER_FLG_WEAK))
  10628. strcat (buff, " | ");
  10629. strcat (buff, "INFO");
  10630. }
  10631. if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
  10632. {
  10633. if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
  10634. strcat (buff, " | ");
  10635. strcat (buff, _("<unknown>"));
  10636. }
  10637. return buff;
  10638. }
  10639. /* Display the contents of the version sections. */
  10640. static bool
  10641. process_version_sections (Filedata * filedata)
  10642. {
  10643. Elf_Internal_Shdr * section;
  10644. unsigned i;
  10645. bool found = false;
  10646. if (! do_version)
  10647. return true;
  10648. for (i = 0, section = filedata->section_headers;
  10649. i < filedata->file_header.e_shnum;
  10650. i++, section++)
  10651. {
  10652. switch (section->sh_type)
  10653. {
  10654. case SHT_GNU_verdef:
  10655. {
  10656. Elf_External_Verdef * edefs;
  10657. unsigned long idx;
  10658. unsigned long cnt;
  10659. char * endbuf;
  10660. found = true;
  10661. if (filedata->is_separate)
  10662. printf (ngettext ("\nIn linked file '%s' the version definition section '%s' contains %u entry:\n",
  10663. "\nIn linked file '%s' the version definition section '%s' contains %u entries:\n",
  10664. section->sh_info),
  10665. filedata->file_name,
  10666. printable_section_name (filedata, section),
  10667. section->sh_info);
  10668. else
  10669. printf (ngettext ("\nVersion definition section '%s' "
  10670. "contains %u entry:\n",
  10671. "\nVersion definition section '%s' "
  10672. "contains %u entries:\n",
  10673. section->sh_info),
  10674. printable_section_name (filedata, section),
  10675. section->sh_info);
  10676. printf (_(" Addr: 0x"));
  10677. printf_vma (section->sh_addr);
  10678. printf (_(" Offset: %#08lx Link: %u (%s)\n"),
  10679. (unsigned long) section->sh_offset, section->sh_link,
  10680. printable_section_name_from_index (filedata, section->sh_link));
  10681. edefs = (Elf_External_Verdef *)
  10682. get_data (NULL, filedata, section->sh_offset, 1,section->sh_size,
  10683. _("version definition section"));
  10684. if (!edefs)
  10685. break;
  10686. endbuf = (char *) edefs + section->sh_size;
  10687. for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
  10688. {
  10689. char * vstart;
  10690. Elf_External_Verdef * edef;
  10691. Elf_Internal_Verdef ent;
  10692. Elf_External_Verdaux * eaux;
  10693. Elf_Internal_Verdaux aux;
  10694. unsigned long isum;
  10695. int j;
  10696. vstart = ((char *) edefs) + idx;
  10697. if (vstart + sizeof (*edef) > endbuf)
  10698. break;
  10699. edef = (Elf_External_Verdef *) vstart;
  10700. ent.vd_version = BYTE_GET (edef->vd_version);
  10701. ent.vd_flags = BYTE_GET (edef->vd_flags);
  10702. ent.vd_ndx = BYTE_GET (edef->vd_ndx);
  10703. ent.vd_cnt = BYTE_GET (edef->vd_cnt);
  10704. ent.vd_hash = BYTE_GET (edef->vd_hash);
  10705. ent.vd_aux = BYTE_GET (edef->vd_aux);
  10706. ent.vd_next = BYTE_GET (edef->vd_next);
  10707. printf (_(" %#06lx: Rev: %d Flags: %s"),
  10708. idx, ent.vd_version, get_ver_flags (ent.vd_flags));
  10709. printf (_(" Index: %d Cnt: %d "),
  10710. ent.vd_ndx, ent.vd_cnt);
  10711. /* Check for overflow. */
  10712. if (ent.vd_aux > (size_t) (endbuf - vstart))
  10713. break;
  10714. vstart += ent.vd_aux;
  10715. if (vstart + sizeof (*eaux) > endbuf)
  10716. break;
  10717. eaux = (Elf_External_Verdaux *) vstart;
  10718. aux.vda_name = BYTE_GET (eaux->vda_name);
  10719. aux.vda_next = BYTE_GET (eaux->vda_next);
  10720. if (valid_dynamic_name (filedata, aux.vda_name))
  10721. printf (_("Name: %s\n"),
  10722. get_dynamic_name (filedata, aux.vda_name));
  10723. else
  10724. printf (_("Name index: %ld\n"), aux.vda_name);
  10725. isum = idx + ent.vd_aux;
  10726. for (j = 1; j < ent.vd_cnt; j++)
  10727. {
  10728. if (aux.vda_next < sizeof (*eaux)
  10729. && !(j == ent.vd_cnt - 1 && aux.vda_next == 0))
  10730. {
  10731. warn (_("Invalid vda_next field of %lx\n"),
  10732. aux.vda_next);
  10733. j = ent.vd_cnt;
  10734. break;
  10735. }
  10736. /* Check for overflow. */
  10737. if (aux.vda_next > (size_t) (endbuf - vstart))
  10738. break;
  10739. isum += aux.vda_next;
  10740. vstart += aux.vda_next;
  10741. if (vstart + sizeof (*eaux) > endbuf)
  10742. break;
  10743. eaux = (Elf_External_Verdaux *) vstart;
  10744. aux.vda_name = BYTE_GET (eaux->vda_name);
  10745. aux.vda_next = BYTE_GET (eaux->vda_next);
  10746. if (valid_dynamic_name (filedata, aux.vda_name))
  10747. printf (_(" %#06lx: Parent %d: %s\n"),
  10748. isum, j,
  10749. get_dynamic_name (filedata, aux.vda_name));
  10750. else
  10751. printf (_(" %#06lx: Parent %d, name index: %ld\n"),
  10752. isum, j, aux.vda_name);
  10753. }
  10754. if (j < ent.vd_cnt)
  10755. printf (_(" Version def aux past end of section\n"));
  10756. /* PR 17531:
  10757. file: id:000001,src:000172+005151,op:splice,rep:2. */
  10758. if (ent.vd_next < sizeof (*edef)
  10759. && !(cnt == section->sh_info - 1 && ent.vd_next == 0))
  10760. {
  10761. warn (_("Invalid vd_next field of %lx\n"), ent.vd_next);
  10762. cnt = section->sh_info;
  10763. break;
  10764. }
  10765. if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx)))
  10766. break;
  10767. idx += ent.vd_next;
  10768. }
  10769. if (cnt < section->sh_info)
  10770. printf (_(" Version definition past end of section\n"));
  10771. free (edefs);
  10772. }
  10773. break;
  10774. case SHT_GNU_verneed:
  10775. {
  10776. Elf_External_Verneed * eneed;
  10777. unsigned long idx;
  10778. unsigned long cnt;
  10779. char * endbuf;
  10780. found = true;
  10781. if (filedata->is_separate)
  10782. printf (ngettext ("\nIn linked file '%s' the version needs section '%s' contains %u entry:\n",
  10783. "\nIn linked file '%s' the version needs section '%s' contains %u entries:\n",
  10784. section->sh_info),
  10785. filedata->file_name,
  10786. printable_section_name (filedata, section),
  10787. section->sh_info);
  10788. else
  10789. printf (ngettext ("\nVersion needs section '%s' "
  10790. "contains %u entry:\n",
  10791. "\nVersion needs section '%s' "
  10792. "contains %u entries:\n",
  10793. section->sh_info),
  10794. printable_section_name (filedata, section),
  10795. section->sh_info);
  10796. printf (_(" Addr: 0x"));
  10797. printf_vma (section->sh_addr);
  10798. printf (_(" Offset: %#08lx Link: %u (%s)\n"),
  10799. (unsigned long) section->sh_offset, section->sh_link,
  10800. printable_section_name_from_index (filedata, section->sh_link));
  10801. eneed = (Elf_External_Verneed *) get_data (NULL, filedata,
  10802. section->sh_offset, 1,
  10803. section->sh_size,
  10804. _("Version Needs section"));
  10805. if (!eneed)
  10806. break;
  10807. endbuf = (char *) eneed + section->sh_size;
  10808. for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
  10809. {
  10810. Elf_External_Verneed * entry;
  10811. Elf_Internal_Verneed ent;
  10812. unsigned long isum;
  10813. int j;
  10814. char * vstart;
  10815. vstart = ((char *) eneed) + idx;
  10816. if (vstart + sizeof (*entry) > endbuf)
  10817. break;
  10818. entry = (Elf_External_Verneed *) vstart;
  10819. ent.vn_version = BYTE_GET (entry->vn_version);
  10820. ent.vn_cnt = BYTE_GET (entry->vn_cnt);
  10821. ent.vn_file = BYTE_GET (entry->vn_file);
  10822. ent.vn_aux = BYTE_GET (entry->vn_aux);
  10823. ent.vn_next = BYTE_GET (entry->vn_next);
  10824. printf (_(" %#06lx: Version: %d"), idx, ent.vn_version);
  10825. if (valid_dynamic_name (filedata, ent.vn_file))
  10826. printf (_(" File: %s"),
  10827. get_dynamic_name (filedata, ent.vn_file));
  10828. else
  10829. printf (_(" File: %lx"), ent.vn_file);
  10830. printf (_(" Cnt: %d\n"), ent.vn_cnt);
  10831. /* Check for overflow. */
  10832. if (ent.vn_aux > (size_t) (endbuf - vstart))
  10833. break;
  10834. vstart += ent.vn_aux;
  10835. for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
  10836. {
  10837. Elf_External_Vernaux * eaux;
  10838. Elf_Internal_Vernaux aux;
  10839. if (vstart + sizeof (*eaux) > endbuf)
  10840. break;
  10841. eaux = (Elf_External_Vernaux *) vstart;
  10842. aux.vna_hash = BYTE_GET (eaux->vna_hash);
  10843. aux.vna_flags = BYTE_GET (eaux->vna_flags);
  10844. aux.vna_other = BYTE_GET (eaux->vna_other);
  10845. aux.vna_name = BYTE_GET (eaux->vna_name);
  10846. aux.vna_next = BYTE_GET (eaux->vna_next);
  10847. if (valid_dynamic_name (filedata, aux.vna_name))
  10848. printf (_(" %#06lx: Name: %s"),
  10849. isum, get_dynamic_name (filedata, aux.vna_name));
  10850. else
  10851. printf (_(" %#06lx: Name index: %lx"),
  10852. isum, aux.vna_name);
  10853. printf (_(" Flags: %s Version: %d\n"),
  10854. get_ver_flags (aux.vna_flags), aux.vna_other);
  10855. if (aux.vna_next < sizeof (*eaux)
  10856. && !(j == ent.vn_cnt - 1 && aux.vna_next == 0))
  10857. {
  10858. warn (_("Invalid vna_next field of %lx\n"),
  10859. aux.vna_next);
  10860. j = ent.vn_cnt;
  10861. break;
  10862. }
  10863. /* Check for overflow. */
  10864. if (aux.vna_next > (size_t) (endbuf - vstart))
  10865. break;
  10866. isum += aux.vna_next;
  10867. vstart += aux.vna_next;
  10868. }
  10869. if (j < ent.vn_cnt)
  10870. warn (_("Missing Version Needs auxiliary information\n"));
  10871. if (ent.vn_next < sizeof (*entry)
  10872. && !(cnt == section->sh_info - 1 && ent.vn_next == 0))
  10873. {
  10874. warn (_("Invalid vn_next field of %lx\n"), ent.vn_next);
  10875. cnt = section->sh_info;
  10876. break;
  10877. }
  10878. if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx)))
  10879. break;
  10880. idx += ent.vn_next;
  10881. }
  10882. if (cnt < section->sh_info)
  10883. warn (_("Missing Version Needs information\n"));
  10884. free (eneed);
  10885. }
  10886. break;
  10887. case SHT_GNU_versym:
  10888. {
  10889. Elf_Internal_Shdr * link_section;
  10890. size_t total;
  10891. unsigned int cnt;
  10892. unsigned char * edata;
  10893. unsigned short * data;
  10894. char * strtab;
  10895. Elf_Internal_Sym * symbols;
  10896. Elf_Internal_Shdr * string_sec;
  10897. unsigned long num_syms;
  10898. long off;
  10899. if (section->sh_link >= filedata->file_header.e_shnum)
  10900. break;
  10901. link_section = filedata->section_headers + section->sh_link;
  10902. total = section->sh_size / sizeof (Elf_External_Versym);
  10903. if (link_section->sh_link >= filedata->file_header.e_shnum)
  10904. break;
  10905. found = true;
  10906. symbols = get_elf_symbols (filedata, link_section, & num_syms);
  10907. if (symbols == NULL)
  10908. break;
  10909. string_sec = filedata->section_headers + link_section->sh_link;
  10910. strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
  10911. string_sec->sh_size,
  10912. _("version string table"));
  10913. if (!strtab)
  10914. {
  10915. free (symbols);
  10916. break;
  10917. }
  10918. if (filedata->is_separate)
  10919. printf (ngettext ("\nIn linked file '%s' the version symbols section '%s' contains %lu entry:\n",
  10920. "\nIn linked file '%s' the version symbols section '%s' contains %lu entries:\n",
  10921. total),
  10922. filedata->file_name,
  10923. printable_section_name (filedata, section),
  10924. (unsigned long) total);
  10925. else
  10926. printf (ngettext ("\nVersion symbols section '%s' "
  10927. "contains %lu entry:\n",
  10928. "\nVersion symbols section '%s' "
  10929. "contains %lu entries:\n",
  10930. total),
  10931. printable_section_name (filedata, section),
  10932. (unsigned long) total);
  10933. printf (_(" Addr: 0x"));
  10934. printf_vma (section->sh_addr);
  10935. printf (_(" Offset: %#08lx Link: %u (%s)\n"),
  10936. (unsigned long) section->sh_offset, section->sh_link,
  10937. printable_section_name (filedata, link_section));
  10938. off = offset_from_vma (filedata,
  10939. filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
  10940. total * sizeof (short));
  10941. edata = (unsigned char *) get_data (NULL, filedata, off,
  10942. sizeof (short), total,
  10943. _("version symbol data"));
  10944. if (!edata)
  10945. {
  10946. free (strtab);
  10947. free (symbols);
  10948. break;
  10949. }
  10950. data = (short unsigned int *) cmalloc (total, sizeof (short));
  10951. for (cnt = total; cnt --;)
  10952. data[cnt] = byte_get (edata + cnt * sizeof (short),
  10953. sizeof (short));
  10954. free (edata);
  10955. for (cnt = 0; cnt < total; cnt += 4)
  10956. {
  10957. int j, nn;
  10958. char *name;
  10959. char *invalid = _("*invalid*");
  10960. printf (" %03x:", cnt);
  10961. for (j = 0; (j < 4) && (cnt + j) < total; ++j)
  10962. switch (data[cnt + j])
  10963. {
  10964. case 0:
  10965. fputs (_(" 0 (*local*) "), stdout);
  10966. break;
  10967. case 1:
  10968. fputs (_(" 1 (*global*) "), stdout);
  10969. break;
  10970. default:
  10971. nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
  10972. data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
  10973. /* If this index value is greater than the size of the symbols
  10974. array, break to avoid an out-of-bounds read. */
  10975. if ((unsigned long)(cnt + j) >= num_syms)
  10976. {
  10977. warn (_("invalid index into symbol array\n"));
  10978. break;
  10979. }
  10980. name = NULL;
  10981. if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
  10982. {
  10983. Elf_Internal_Verneed ivn;
  10984. unsigned long offset;
  10985. offset = offset_from_vma
  10986. (filedata,
  10987. filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
  10988. sizeof (Elf_External_Verneed));
  10989. do
  10990. {
  10991. Elf_Internal_Vernaux ivna;
  10992. Elf_External_Verneed evn;
  10993. Elf_External_Vernaux evna;
  10994. unsigned long a_off;
  10995. if (get_data (&evn, filedata, offset, sizeof (evn), 1,
  10996. _("version need")) == NULL)
  10997. break;
  10998. ivn.vn_aux = BYTE_GET (evn.vn_aux);
  10999. ivn.vn_next = BYTE_GET (evn.vn_next);
  11000. a_off = offset + ivn.vn_aux;
  11001. do
  11002. {
  11003. if (get_data (&evna, filedata, a_off, sizeof (evna),
  11004. 1, _("version need aux (2)")) == NULL)
  11005. {
  11006. ivna.vna_next = 0;
  11007. ivna.vna_other = 0;
  11008. }
  11009. else
  11010. {
  11011. ivna.vna_next = BYTE_GET (evna.vna_next);
  11012. ivna.vna_other = BYTE_GET (evna.vna_other);
  11013. }
  11014. a_off += ivna.vna_next;
  11015. }
  11016. while (ivna.vna_other != data[cnt + j]
  11017. && ivna.vna_next != 0);
  11018. if (ivna.vna_other == data[cnt + j])
  11019. {
  11020. ivna.vna_name = BYTE_GET (evna.vna_name);
  11021. if (ivna.vna_name >= string_sec->sh_size)
  11022. name = invalid;
  11023. else
  11024. name = strtab + ivna.vna_name;
  11025. break;
  11026. }
  11027. offset += ivn.vn_next;
  11028. }
  11029. while (ivn.vn_next);
  11030. }
  11031. if (data[cnt + j] != 0x8001
  11032. && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
  11033. {
  11034. Elf_Internal_Verdef ivd;
  11035. Elf_External_Verdef evd;
  11036. unsigned long offset;
  11037. offset = offset_from_vma
  11038. (filedata,
  11039. filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
  11040. sizeof evd);
  11041. do
  11042. {
  11043. if (get_data (&evd, filedata, offset, sizeof (evd), 1,
  11044. _("version def")) == NULL)
  11045. {
  11046. ivd.vd_next = 0;
  11047. /* PR 17531: file: 046-1082287-0.004. */
  11048. ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1;
  11049. break;
  11050. }
  11051. else
  11052. {
  11053. ivd.vd_next = BYTE_GET (evd.vd_next);
  11054. ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
  11055. }
  11056. offset += ivd.vd_next;
  11057. }
  11058. while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
  11059. && ivd.vd_next != 0);
  11060. if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
  11061. {
  11062. Elf_External_Verdaux evda;
  11063. Elf_Internal_Verdaux ivda;
  11064. ivd.vd_aux = BYTE_GET (evd.vd_aux);
  11065. if (get_data (&evda, filedata,
  11066. offset - ivd.vd_next + ivd.vd_aux,
  11067. sizeof (evda), 1,
  11068. _("version def aux")) == NULL)
  11069. break;
  11070. ivda.vda_name = BYTE_GET (evda.vda_name);
  11071. if (ivda.vda_name >= string_sec->sh_size)
  11072. name = invalid;
  11073. else if (name != NULL && name != invalid)
  11074. name = _("*both*");
  11075. else
  11076. name = strtab + ivda.vda_name;
  11077. }
  11078. }
  11079. if (name != NULL)
  11080. nn += printf ("(%s%-*s",
  11081. name,
  11082. 12 - (int) strlen (name),
  11083. ")");
  11084. if (nn < 18)
  11085. printf ("%*c", 18 - nn, ' ');
  11086. }
  11087. putchar ('\n');
  11088. }
  11089. free (data);
  11090. free (strtab);
  11091. free (symbols);
  11092. }
  11093. break;
  11094. default:
  11095. break;
  11096. }
  11097. }
  11098. if (! found)
  11099. {
  11100. if (filedata->is_separate)
  11101. printf (_("\nNo version information found in linked file '%s'.\n"),
  11102. filedata->file_name);
  11103. else
  11104. printf (_("\nNo version information found in this file.\n"));
  11105. }
  11106. return true;
  11107. }
  11108. static const char *
  11109. get_symbol_binding (Filedata * filedata, unsigned int binding)
  11110. {
  11111. static char buff[64];
  11112. switch (binding)
  11113. {
  11114. case STB_LOCAL: return "LOCAL";
  11115. case STB_GLOBAL: return "GLOBAL";
  11116. case STB_WEAK: return "WEAK";
  11117. default:
  11118. if (binding >= STB_LOPROC && binding <= STB_HIPROC)
  11119. snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
  11120. binding);
  11121. else if (binding >= STB_LOOS && binding <= STB_HIOS)
  11122. {
  11123. if (binding == STB_GNU_UNIQUE
  11124. && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU)
  11125. return "UNIQUE";
  11126. snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
  11127. }
  11128. else
  11129. snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
  11130. return buff;
  11131. }
  11132. }
  11133. static const char *
  11134. get_symbol_type (Filedata * filedata, unsigned int type)
  11135. {
  11136. static char buff[64];
  11137. switch (type)
  11138. {
  11139. case STT_NOTYPE: return "NOTYPE";
  11140. case STT_OBJECT: return "OBJECT";
  11141. case STT_FUNC: return "FUNC";
  11142. case STT_SECTION: return "SECTION";
  11143. case STT_FILE: return "FILE";
  11144. case STT_COMMON: return "COMMON";
  11145. case STT_TLS: return "TLS";
  11146. case STT_RELC: return "RELC";
  11147. case STT_SRELC: return "SRELC";
  11148. default:
  11149. if (type >= STT_LOPROC && type <= STT_HIPROC)
  11150. {
  11151. if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
  11152. return "THUMB_FUNC";
  11153. if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
  11154. return "REGISTER";
  11155. if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
  11156. return "PARISC_MILLI";
  11157. snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
  11158. }
  11159. else if (type >= STT_LOOS && type <= STT_HIOS)
  11160. {
  11161. if (filedata->file_header.e_machine == EM_PARISC)
  11162. {
  11163. if (type == STT_HP_OPAQUE)
  11164. return "HP_OPAQUE";
  11165. if (type == STT_HP_STUB)
  11166. return "HP_STUB";
  11167. }
  11168. if (type == STT_GNU_IFUNC
  11169. && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU
  11170. || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD))
  11171. return "IFUNC";
  11172. snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
  11173. }
  11174. else
  11175. snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
  11176. return buff;
  11177. }
  11178. }
  11179. static const char *
  11180. get_symbol_visibility (unsigned int visibility)
  11181. {
  11182. switch (visibility)
  11183. {
  11184. case STV_DEFAULT: return "DEFAULT";
  11185. case STV_INTERNAL: return "INTERNAL";
  11186. case STV_HIDDEN: return "HIDDEN";
  11187. case STV_PROTECTED: return "PROTECTED";
  11188. default:
  11189. error (_("Unrecognized visibility value: %u\n"), visibility);
  11190. return _("<unknown>");
  11191. }
  11192. }
  11193. static const char *
  11194. get_alpha_symbol_other (unsigned int other)
  11195. {
  11196. switch (other)
  11197. {
  11198. case STO_ALPHA_NOPV: return "NOPV";
  11199. case STO_ALPHA_STD_GPLOAD: return "STD GPLOAD";
  11200. default:
  11201. error (_("Unrecognized alpha specific other value: %u\n"), other);
  11202. return _("<unknown>");
  11203. }
  11204. }
  11205. static const char *
  11206. get_solaris_symbol_visibility (unsigned int visibility)
  11207. {
  11208. switch (visibility)
  11209. {
  11210. case 4: return "EXPORTED";
  11211. case 5: return "SINGLETON";
  11212. case 6: return "ELIMINATE";
  11213. default: return get_symbol_visibility (visibility);
  11214. }
  11215. }
  11216. static const char *
  11217. get_aarch64_symbol_other (unsigned int other)
  11218. {
  11219. static char buf[32];
  11220. if (other & STO_AARCH64_VARIANT_PCS)
  11221. {
  11222. other &= ~STO_AARCH64_VARIANT_PCS;
  11223. if (other == 0)
  11224. return "VARIANT_PCS";
  11225. snprintf (buf, sizeof buf, "VARIANT_PCS | %x", other);
  11226. return buf;
  11227. }
  11228. return NULL;
  11229. }
  11230. static const char *
  11231. get_mips_symbol_other (unsigned int other)
  11232. {
  11233. switch (other)
  11234. {
  11235. case STO_OPTIONAL: return "OPTIONAL";
  11236. case STO_MIPS_PLT: return "MIPS PLT";
  11237. case STO_MIPS_PIC: return "MIPS PIC";
  11238. case STO_MICROMIPS: return "MICROMIPS";
  11239. case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC";
  11240. case STO_MIPS16: return "MIPS16";
  11241. default: return NULL;
  11242. }
  11243. }
  11244. static const char *
  11245. get_ia64_symbol_other (Filedata * filedata, unsigned int other)
  11246. {
  11247. if (is_ia64_vms (filedata))
  11248. {
  11249. static char res[32];
  11250. res[0] = 0;
  11251. /* Function types is for images and .STB files only. */
  11252. switch (filedata->file_header.e_type)
  11253. {
  11254. case ET_DYN:
  11255. case ET_EXEC:
  11256. switch (VMS_ST_FUNC_TYPE (other))
  11257. {
  11258. case VMS_SFT_CODE_ADDR:
  11259. strcat (res, " CA");
  11260. break;
  11261. case VMS_SFT_SYMV_IDX:
  11262. strcat (res, " VEC");
  11263. break;
  11264. case VMS_SFT_FD:
  11265. strcat (res, " FD");
  11266. break;
  11267. case VMS_SFT_RESERVE:
  11268. strcat (res, " RSV");
  11269. break;
  11270. default:
  11271. warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
  11272. VMS_ST_FUNC_TYPE (other));
  11273. strcat (res, " <unknown>");
  11274. break;
  11275. }
  11276. break;
  11277. default:
  11278. break;
  11279. }
  11280. switch (VMS_ST_LINKAGE (other))
  11281. {
  11282. case VMS_STL_IGNORE:
  11283. strcat (res, " IGN");
  11284. break;
  11285. case VMS_STL_RESERVE:
  11286. strcat (res, " RSV");
  11287. break;
  11288. case VMS_STL_STD:
  11289. strcat (res, " STD");
  11290. break;
  11291. case VMS_STL_LNK:
  11292. strcat (res, " LNK");
  11293. break;
  11294. default:
  11295. warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
  11296. VMS_ST_LINKAGE (other));
  11297. strcat (res, " <unknown>");
  11298. break;
  11299. }
  11300. if (res[0] != 0)
  11301. return res + 1;
  11302. else
  11303. return res;
  11304. }
  11305. return NULL;
  11306. }
  11307. static const char *
  11308. get_ppc64_symbol_other (unsigned int other)
  11309. {
  11310. if ((other & ~STO_PPC64_LOCAL_MASK) != 0)
  11311. return NULL;
  11312. other >>= STO_PPC64_LOCAL_BIT;
  11313. if (other <= 6)
  11314. {
  11315. static char buf[64];
  11316. if (other >= 2)
  11317. other = ppc64_decode_local_entry (other);
  11318. snprintf (buf, sizeof buf, _("<localentry>: %d"), other);
  11319. return buf;
  11320. }
  11321. return NULL;
  11322. }
  11323. static const char *
  11324. get_riscv_symbol_other (unsigned int other)
  11325. {
  11326. static char buf[32];
  11327. buf[0] = 0;
  11328. if (other & STO_RISCV_VARIANT_CC)
  11329. {
  11330. strcat (buf, _(" VARIANT_CC"));
  11331. other &= ~STO_RISCV_VARIANT_CC;
  11332. }
  11333. if (other != 0)
  11334. snprintf (buf, sizeof buf, " %x", other);
  11335. if (buf[0] != 0)
  11336. return buf + 1;
  11337. else
  11338. return buf;
  11339. }
  11340. static const char *
  11341. get_symbol_other (Filedata * filedata, unsigned int other)
  11342. {
  11343. const char * result = NULL;
  11344. static char buff [64];
  11345. if (other == 0)
  11346. return "";
  11347. switch (filedata->file_header.e_machine)
  11348. {
  11349. case EM_ALPHA:
  11350. result = get_alpha_symbol_other (other);
  11351. break;
  11352. case EM_AARCH64:
  11353. result = get_aarch64_symbol_other (other);
  11354. break;
  11355. case EM_MIPS:
  11356. result = get_mips_symbol_other (other);
  11357. break;
  11358. case EM_IA_64:
  11359. result = get_ia64_symbol_other (filedata, other);
  11360. break;
  11361. case EM_PPC64:
  11362. result = get_ppc64_symbol_other (other);
  11363. break;
  11364. case EM_RISCV:
  11365. result = get_riscv_symbol_other (other);
  11366. break;
  11367. default:
  11368. result = NULL;
  11369. break;
  11370. }
  11371. if (result)
  11372. return result;
  11373. snprintf (buff, sizeof buff, _("<other>: %x"), other);
  11374. return buff;
  11375. }
  11376. static const char *
  11377. get_symbol_index_type (Filedata * filedata, unsigned int type)
  11378. {
  11379. static char buff[32];
  11380. switch (type)
  11381. {
  11382. case SHN_UNDEF: return "UND";
  11383. case SHN_ABS: return "ABS";
  11384. case SHN_COMMON: return "COM";
  11385. default:
  11386. if (type == SHN_IA_64_ANSI_COMMON
  11387. && filedata->file_header.e_machine == EM_IA_64
  11388. && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
  11389. return "ANSI_COM";
  11390. else if ((filedata->file_header.e_machine == EM_X86_64
  11391. || filedata->file_header.e_machine == EM_L1OM
  11392. || filedata->file_header.e_machine == EM_K1OM)
  11393. && type == SHN_X86_64_LCOMMON)
  11394. return "LARGE_COM";
  11395. else if ((type == SHN_MIPS_SCOMMON
  11396. && filedata->file_header.e_machine == EM_MIPS)
  11397. || (type == SHN_TIC6X_SCOMMON
  11398. && filedata->file_header.e_machine == EM_TI_C6000))
  11399. return "SCOM";
  11400. else if (type == SHN_MIPS_SUNDEFINED
  11401. && filedata->file_header.e_machine == EM_MIPS)
  11402. return "SUND";
  11403. else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
  11404. sprintf (buff, "PRC[0x%04x]", type & 0xffff);
  11405. else if (type >= SHN_LOOS && type <= SHN_HIOS)
  11406. sprintf (buff, "OS [0x%04x]", type & 0xffff);
  11407. else if (type >= SHN_LORESERVE)
  11408. sprintf (buff, "RSV[0x%04x]", type & 0xffff);
  11409. else if (filedata->file_header.e_shnum != 0
  11410. && type >= filedata->file_header.e_shnum)
  11411. sprintf (buff, _("bad section index[%3d]"), type);
  11412. else
  11413. sprintf (buff, "%3d", type);
  11414. break;
  11415. }
  11416. return buff;
  11417. }
  11418. static const char *
  11419. get_symbol_version_string (Filedata * filedata,
  11420. bool is_dynsym,
  11421. const char * strtab,
  11422. unsigned long int strtab_size,
  11423. unsigned int si,
  11424. Elf_Internal_Sym * psym,
  11425. enum versioned_symbol_info * sym_info,
  11426. unsigned short * vna_other)
  11427. {
  11428. unsigned char data[2];
  11429. unsigned short vers_data;
  11430. unsigned long offset;
  11431. unsigned short max_vd_ndx;
  11432. if (!is_dynsym
  11433. || filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0)
  11434. return NULL;
  11435. offset = offset_from_vma (filedata,
  11436. filedata->version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
  11437. sizeof data + si * sizeof (vers_data));
  11438. if (get_data (&data, filedata, offset + si * sizeof (vers_data),
  11439. sizeof (data), 1, _("version data")) == NULL)
  11440. return NULL;
  11441. vers_data = byte_get (data, 2);
  11442. if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0)
  11443. return NULL;
  11444. *sym_info = (vers_data & VERSYM_HIDDEN) != 0 ? symbol_hidden : symbol_public;
  11445. max_vd_ndx = 0;
  11446. /* Usually we'd only see verdef for defined symbols, and verneed for
  11447. undefined symbols. However, symbols defined by the linker in
  11448. .dynbss for variables copied from a shared library in order to
  11449. avoid text relocations are defined yet have verneed. We could
  11450. use a heuristic to detect the special case, for example, check
  11451. for verneed first on symbols defined in SHT_NOBITS sections, but
  11452. it is simpler and more reliable to just look for both verdef and
  11453. verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
  11454. if (psym->st_shndx != SHN_UNDEF
  11455. && vers_data != 0x8001
  11456. && filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
  11457. {
  11458. Elf_Internal_Verdef ivd;
  11459. Elf_Internal_Verdaux ivda;
  11460. Elf_External_Verdaux evda;
  11461. unsigned long off;
  11462. off = offset_from_vma (filedata,
  11463. filedata->version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
  11464. sizeof (Elf_External_Verdef));
  11465. do
  11466. {
  11467. Elf_External_Verdef evd;
  11468. if (get_data (&evd, filedata, off, sizeof (evd), 1,
  11469. _("version def")) == NULL)
  11470. {
  11471. ivd.vd_ndx = 0;
  11472. ivd.vd_aux = 0;
  11473. ivd.vd_next = 0;
  11474. ivd.vd_flags = 0;
  11475. }
  11476. else
  11477. {
  11478. ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
  11479. ivd.vd_aux = BYTE_GET (evd.vd_aux);
  11480. ivd.vd_next = BYTE_GET (evd.vd_next);
  11481. ivd.vd_flags = BYTE_GET (evd.vd_flags);
  11482. }
  11483. if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx)
  11484. max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION;
  11485. off += ivd.vd_next;
  11486. }
  11487. while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0);
  11488. if (ivd.vd_ndx == (vers_data & VERSYM_VERSION))
  11489. {
  11490. if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE)
  11491. return NULL;
  11492. off -= ivd.vd_next;
  11493. off += ivd.vd_aux;
  11494. if (get_data (&evda, filedata, off, sizeof (evda), 1,
  11495. _("version def aux")) != NULL)
  11496. {
  11497. ivda.vda_name = BYTE_GET (evda.vda_name);
  11498. if (psym->st_name != ivda.vda_name)
  11499. return (ivda.vda_name < strtab_size
  11500. ? strtab + ivda.vda_name : _("<corrupt>"));
  11501. }
  11502. }
  11503. }
  11504. if (filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
  11505. {
  11506. Elf_External_Verneed evn;
  11507. Elf_Internal_Verneed ivn;
  11508. Elf_Internal_Vernaux ivna;
  11509. offset = offset_from_vma (filedata,
  11510. filedata->version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
  11511. sizeof evn);
  11512. do
  11513. {
  11514. unsigned long vna_off;
  11515. if (get_data (&evn, filedata, offset, sizeof (evn), 1,
  11516. _("version need")) == NULL)
  11517. {
  11518. ivna.vna_next = 0;
  11519. ivna.vna_other = 0;
  11520. ivna.vna_name = 0;
  11521. break;
  11522. }
  11523. ivn.vn_aux = BYTE_GET (evn.vn_aux);
  11524. ivn.vn_next = BYTE_GET (evn.vn_next);
  11525. vna_off = offset + ivn.vn_aux;
  11526. do
  11527. {
  11528. Elf_External_Vernaux evna;
  11529. if (get_data (&evna, filedata, vna_off, sizeof (evna), 1,
  11530. _("version need aux (3)")) == NULL)
  11531. {
  11532. ivna.vna_next = 0;
  11533. ivna.vna_other = 0;
  11534. ivna.vna_name = 0;
  11535. }
  11536. else
  11537. {
  11538. ivna.vna_other = BYTE_GET (evna.vna_other);
  11539. ivna.vna_next = BYTE_GET (evna.vna_next);
  11540. ivna.vna_name = BYTE_GET (evna.vna_name);
  11541. }
  11542. vna_off += ivna.vna_next;
  11543. }
  11544. while (ivna.vna_other != vers_data && ivna.vna_next != 0);
  11545. if (ivna.vna_other == vers_data)
  11546. break;
  11547. offset += ivn.vn_next;
  11548. }
  11549. while (ivn.vn_next != 0);
  11550. if (ivna.vna_other == vers_data)
  11551. {
  11552. *sym_info = symbol_undefined;
  11553. *vna_other = ivna.vna_other;
  11554. return (ivna.vna_name < strtab_size
  11555. ? strtab + ivna.vna_name : _("<corrupt>"));
  11556. }
  11557. else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1)
  11558. && (vers_data & VERSYM_VERSION) > max_vd_ndx)
  11559. return _("<corrupt>");
  11560. }
  11561. return NULL;
  11562. }
  11563. /* Display a symbol size on stdout. Format is based on --sym-base setting. */
  11564. static unsigned int
  11565. print_dynamic_symbol_size (bfd_vma vma, int base)
  11566. {
  11567. switch (base)
  11568. {
  11569. case 8:
  11570. return print_vma (vma, OCTAL_5);
  11571. case 10:
  11572. return print_vma (vma, UNSIGNED_5);
  11573. case 16:
  11574. return print_vma (vma, PREFIX_HEX_5);
  11575. case 0:
  11576. default:
  11577. return print_vma (vma, DEC_5);
  11578. }
  11579. }
  11580. static void
  11581. print_dynamic_symbol (Filedata *filedata, unsigned long si,
  11582. Elf_Internal_Sym *symtab,
  11583. Elf_Internal_Shdr *section,
  11584. char *strtab, size_t strtab_size)
  11585. {
  11586. const char *version_string;
  11587. enum versioned_symbol_info sym_info;
  11588. unsigned short vna_other;
  11589. bool is_valid;
  11590. const char * sstr;
  11591. Elf_Internal_Sym *psym = symtab + si;
  11592. printf ("%6ld: ", si);
  11593. print_vma (psym->st_value, LONG_HEX);
  11594. putchar (' ');
  11595. print_dynamic_symbol_size (psym->st_size, sym_base);
  11596. printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)));
  11597. printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info)));
  11598. if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
  11599. printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
  11600. else
  11601. {
  11602. unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
  11603. printf (" %-7s", get_symbol_visibility (vis));
  11604. /* Check to see if any other bits in the st_other field are set.
  11605. Note - displaying this information disrupts the layout of the
  11606. table being generated, but for the moment this case is very rare. */
  11607. if (psym->st_other ^ vis)
  11608. printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis));
  11609. }
  11610. printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx));
  11611. if (ELF_ST_TYPE (psym->st_info) == STT_SECTION
  11612. && psym->st_shndx < filedata->file_header.e_shnum
  11613. && filedata->section_headers != NULL
  11614. && psym->st_name == 0)
  11615. {
  11616. is_valid
  11617. = section_name_valid (filedata,
  11618. filedata->section_headers + psym->st_shndx);
  11619. sstr = is_valid ?
  11620. section_name_print (filedata,
  11621. filedata->section_headers + psym->st_shndx)
  11622. : _("<corrupt>");
  11623. }
  11624. else
  11625. {
  11626. is_valid = valid_symbol_name (strtab, strtab_size, psym->st_name);
  11627. sstr = is_valid ? strtab + psym->st_name : _("<corrupt>");
  11628. }
  11629. version_string
  11630. = get_symbol_version_string (filedata,
  11631. (section == NULL
  11632. || section->sh_type == SHT_DYNSYM),
  11633. strtab, strtab_size, si,
  11634. psym, &sym_info, &vna_other);
  11635. int len_avail = 21;
  11636. if (! do_wide && version_string != NULL)
  11637. {
  11638. char buffer[16];
  11639. len_avail -= 1 + strlen (version_string);
  11640. if (sym_info == symbol_undefined)
  11641. len_avail -= sprintf (buffer," (%d)", vna_other);
  11642. else if (sym_info != symbol_hidden)
  11643. len_avail -= 1;
  11644. }
  11645. print_symbol (len_avail, sstr);
  11646. if (version_string)
  11647. {
  11648. if (sym_info == symbol_undefined)
  11649. printf ("@%s (%d)", version_string, vna_other);
  11650. else
  11651. printf (sym_info == symbol_hidden ? "@%s" : "@@%s",
  11652. version_string);
  11653. }
  11654. putchar ('\n');
  11655. if (ELF_ST_BIND (psym->st_info) == STB_LOCAL
  11656. && section != NULL
  11657. && si >= section->sh_info
  11658. /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
  11659. && filedata->file_header.e_machine != EM_MIPS
  11660. /* Solaris binaries have been found to violate this requirement as
  11661. well. Not sure if this is a bug or an ABI requirement. */
  11662. && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS)
  11663. warn (_("local symbol %lu found at index >= %s's sh_info value of %u\n"),
  11664. si, printable_section_name (filedata, section), section->sh_info);
  11665. }
  11666. static const char *
  11667. get_lto_kind (unsigned int kind)
  11668. {
  11669. switch (kind)
  11670. {
  11671. case 0: return "DEF";
  11672. case 1: return "WEAKDEF";
  11673. case 2: return "UNDEF";
  11674. case 3: return "WEAKUNDEF";
  11675. case 4: return "COMMON";
  11676. default:
  11677. break;
  11678. }
  11679. static char buffer[30];
  11680. error (_("Unknown LTO symbol definition encountered: %u\n"), kind);
  11681. sprintf (buffer, "<unknown: %u>", kind);
  11682. return buffer;
  11683. }
  11684. static const char *
  11685. get_lto_visibility (unsigned int visibility)
  11686. {
  11687. switch (visibility)
  11688. {
  11689. case 0: return "DEFAULT";
  11690. case 1: return "PROTECTED";
  11691. case 2: return "INTERNAL";
  11692. case 3: return "HIDDEN";
  11693. default:
  11694. break;
  11695. }
  11696. static char buffer[30];
  11697. error (_("Unknown LTO symbol visibility encountered: %u\n"), visibility);
  11698. sprintf (buffer, "<unknown: %u>", visibility);
  11699. return buffer;
  11700. }
  11701. static const char *
  11702. get_lto_sym_type (unsigned int sym_type)
  11703. {
  11704. switch (sym_type)
  11705. {
  11706. case 0: return "UNKNOWN";
  11707. case 1: return "FUNCTION";
  11708. case 2: return "VARIABLE";
  11709. default:
  11710. break;
  11711. }
  11712. static char buffer[30];
  11713. error (_("Unknown LTO symbol type encountered: %u\n"), sym_type);
  11714. sprintf (buffer, "<unknown: %u>", sym_type);
  11715. return buffer;
  11716. }
  11717. /* Display an LTO format symbol table.
  11718. FIXME: The format of LTO symbol tables is not formalized.
  11719. So this code could need changing in the future. */
  11720. static bool
  11721. display_lto_symtab (Filedata * filedata,
  11722. Elf_Internal_Shdr * section)
  11723. {
  11724. if (section->sh_size == 0)
  11725. {
  11726. if (filedata->is_separate)
  11727. printf (_("\nThe LTO Symbol table section '%s' in linked file '%s' is empty!\n"),
  11728. printable_section_name (filedata, section),
  11729. filedata->file_name);
  11730. else
  11731. printf (_("\nLTO Symbol table '%s' is empty!\n"),
  11732. printable_section_name (filedata, section));
  11733. return true;
  11734. }
  11735. if (section->sh_size > filedata->file_size)
  11736. {
  11737. error (_("Section %s has an invalid sh_size of 0x%lx\n"),
  11738. printable_section_name (filedata, section),
  11739. (unsigned long) section->sh_size);
  11740. return false;
  11741. }
  11742. void * alloced_data = get_data (NULL, filedata, section->sh_offset,
  11743. section->sh_size, 1, _("LTO symbols"));
  11744. if (alloced_data == NULL)
  11745. return false;
  11746. /* Look for extended data for the symbol table. */
  11747. Elf_Internal_Shdr * ext;
  11748. void * ext_data_orig = NULL;
  11749. char * ext_data = NULL;
  11750. char * ext_data_end = NULL;
  11751. char * ext_name = NULL;
  11752. if (asprintf (& ext_name, ".gnu.lto_.ext_symtab.%s",
  11753. (section_name (filedata, section)
  11754. + sizeof (".gnu.lto_.symtab.") - 1)) > 0
  11755. && ext_name != NULL /* Paranoia. */
  11756. && (ext = find_section (filedata, ext_name)) != NULL)
  11757. {
  11758. if (ext->sh_size < 3)
  11759. error (_("LTO Symbol extension table '%s' is empty!\n"),
  11760. printable_section_name (filedata, ext));
  11761. else
  11762. {
  11763. ext_data_orig = ext_data = get_data (NULL, filedata, ext->sh_offset,
  11764. ext->sh_size, 1,
  11765. _("LTO ext symbol data"));
  11766. if (ext_data != NULL)
  11767. {
  11768. ext_data_end = ext_data + ext->sh_size;
  11769. if (* ext_data++ != 1)
  11770. error (_("Unexpected version number in symbol extension table\n"));
  11771. }
  11772. }
  11773. }
  11774. const unsigned char * data = (const unsigned char *) alloced_data;
  11775. const unsigned char * end = data + section->sh_size;
  11776. if (filedata->is_separate)
  11777. printf (_("\nIn linked file '%s': "), filedata->file_name);
  11778. else
  11779. printf ("\n");
  11780. if (ext_data_orig != NULL)
  11781. {
  11782. if (do_wide)
  11783. printf (_("LTO Symbol table '%s' and extension table '%s' contain:\n"),
  11784. printable_section_name (filedata, section),
  11785. printable_section_name (filedata, ext));
  11786. else
  11787. {
  11788. printf (_("LTO Symbol table '%s'\n"),
  11789. printable_section_name (filedata, section));
  11790. printf (_(" and extension table '%s' contain:\n"),
  11791. printable_section_name (filedata, ext));
  11792. }
  11793. }
  11794. else
  11795. printf (_("LTO Symbol table '%s' contains:\n"),
  11796. printable_section_name (filedata, section));
  11797. /* FIXME: Add a wide version. */
  11798. if (ext_data_orig != NULL)
  11799. printf (_(" Comdat_Key Kind Visibility Size Slot Type Section Name\n"));
  11800. else
  11801. printf (_(" Comdat_Key Kind Visibility Size Slot Name\n"));
  11802. /* FIXME: We do not handle style prefixes. */
  11803. while (data < end)
  11804. {
  11805. const unsigned char * sym_name = data;
  11806. data += strnlen ((const char *) sym_name, end - data) + 1;
  11807. if (data >= end)
  11808. goto fail;
  11809. const unsigned char * comdat_key = data;
  11810. data += strnlen ((const char *) comdat_key, end - data) + 1;
  11811. if (data >= end)
  11812. goto fail;
  11813. if (data + 2 + 8 + 4 > end)
  11814. goto fail;
  11815. unsigned int kind = *data++;
  11816. unsigned int visibility = *data++;
  11817. elf_vma size = byte_get (data, 8);
  11818. data += 8;
  11819. elf_vma slot = byte_get (data, 4);
  11820. data += 4;
  11821. if (ext_data != NULL)
  11822. {
  11823. if (ext_data < (ext_data_end - 1))
  11824. {
  11825. unsigned int sym_type = * ext_data ++;
  11826. unsigned int sec_kind = * ext_data ++;
  11827. printf (" %10s %10s %11s %08lx %08lx %9s %08lx _",
  11828. * comdat_key == 0 ? "-" : (char *) comdat_key,
  11829. get_lto_kind (kind),
  11830. get_lto_visibility (visibility),
  11831. (long) size,
  11832. (long) slot,
  11833. get_lto_sym_type (sym_type),
  11834. (long) sec_kind);
  11835. print_symbol (6, (const char *) sym_name);
  11836. }
  11837. else
  11838. {
  11839. error (_("Ran out of LTO symbol extension data\n"));
  11840. ext_data = NULL;
  11841. /* FIXME: return FAIL result ? */
  11842. }
  11843. }
  11844. else
  11845. {
  11846. printf (" %10s %10s %11s %08lx %08lx _",
  11847. * comdat_key == 0 ? "-" : (char *) comdat_key,
  11848. get_lto_kind (kind),
  11849. get_lto_visibility (visibility),
  11850. (long) size,
  11851. (long) slot);
  11852. print_symbol (21, (const char *) sym_name);
  11853. }
  11854. putchar ('\n');
  11855. }
  11856. if (ext_data != NULL && ext_data < ext_data_end)
  11857. {
  11858. error (_("Data remains in the LTO symbol extension table\n"));
  11859. goto fail;
  11860. }
  11861. free (alloced_data);
  11862. free (ext_data_orig);
  11863. free (ext_name);
  11864. return true;
  11865. fail:
  11866. error (_("Buffer overrun encountered whilst decoding LTO symbol table\n"));
  11867. free (alloced_data);
  11868. free (ext_data_orig);
  11869. free (ext_name);
  11870. return false;
  11871. }
  11872. /* Display LTO symbol tables. */
  11873. static bool
  11874. process_lto_symbol_tables (Filedata * filedata)
  11875. {
  11876. Elf_Internal_Shdr * section;
  11877. unsigned int i;
  11878. bool res = true;
  11879. if (!do_lto_syms)
  11880. return true;
  11881. if (filedata->section_headers == NULL)
  11882. return true;
  11883. for (i = 0, section = filedata->section_headers;
  11884. i < filedata->file_header.e_shnum;
  11885. i++, section++)
  11886. if (section_name_valid (filedata, section)
  11887. && startswith (section_name (filedata, section), ".gnu.lto_.symtab."))
  11888. res &= display_lto_symtab (filedata, section);
  11889. return res;
  11890. }
  11891. /* Dump the symbol table. */
  11892. static bool
  11893. process_symbol_table (Filedata * filedata)
  11894. {
  11895. Elf_Internal_Shdr * section;
  11896. if (!do_syms && !do_dyn_syms && !do_histogram)
  11897. return true;
  11898. if ((filedata->dynamic_info[DT_HASH] || filedata->dynamic_info_DT_GNU_HASH)
  11899. && do_syms
  11900. && do_using_dynamic
  11901. && filedata->dynamic_strings != NULL
  11902. && filedata->dynamic_symbols != NULL)
  11903. {
  11904. unsigned long si;
  11905. if (filedata->is_separate)
  11906. {
  11907. printf (ngettext ("\nIn linked file '%s' the dynamic symbol table contains %lu entry:\n",
  11908. "\nIn linked file '%s' the dynamic symbol table contains %lu entries:\n",
  11909. filedata->num_dynamic_syms),
  11910. filedata->file_name,
  11911. filedata->num_dynamic_syms);
  11912. }
  11913. else
  11914. {
  11915. printf (ngettext ("\nSymbol table for image contains %lu entry:\n",
  11916. "\nSymbol table for image contains %lu entries:\n",
  11917. filedata->num_dynamic_syms),
  11918. filedata->num_dynamic_syms);
  11919. }
  11920. if (is_32bit_elf)
  11921. printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
  11922. else
  11923. printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
  11924. for (si = 0; si < filedata->num_dynamic_syms; si++)
  11925. print_dynamic_symbol (filedata, si, filedata->dynamic_symbols, NULL,
  11926. filedata->dynamic_strings,
  11927. filedata->dynamic_strings_length);
  11928. }
  11929. else if ((do_dyn_syms || (do_syms && !do_using_dynamic))
  11930. && filedata->section_headers != NULL)
  11931. {
  11932. unsigned int i;
  11933. for (i = 0, section = filedata->section_headers;
  11934. i < filedata->file_header.e_shnum;
  11935. i++, section++)
  11936. {
  11937. char * strtab = NULL;
  11938. unsigned long int strtab_size = 0;
  11939. Elf_Internal_Sym * symtab;
  11940. unsigned long si, num_syms;
  11941. if ((section->sh_type != SHT_SYMTAB
  11942. && section->sh_type != SHT_DYNSYM)
  11943. || (!do_syms
  11944. && section->sh_type == SHT_SYMTAB))
  11945. continue;
  11946. if (section->sh_entsize == 0)
  11947. {
  11948. printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
  11949. printable_section_name (filedata, section));
  11950. continue;
  11951. }
  11952. num_syms = section->sh_size / section->sh_entsize;
  11953. if (filedata->is_separate)
  11954. printf (ngettext ("\nIn linked file '%s' symbol section '%s' contains %lu entry:\n",
  11955. "\nIn linked file '%s' symbol section '%s' contains %lu entries:\n",
  11956. num_syms),
  11957. filedata->file_name,
  11958. printable_section_name (filedata, section),
  11959. num_syms);
  11960. else
  11961. printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n",
  11962. "\nSymbol table '%s' contains %lu entries:\n",
  11963. num_syms),
  11964. printable_section_name (filedata, section),
  11965. num_syms);
  11966. if (is_32bit_elf)
  11967. printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
  11968. else
  11969. printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
  11970. symtab = get_elf_symbols (filedata, section, & num_syms);
  11971. if (symtab == NULL)
  11972. continue;
  11973. if (section->sh_link == filedata->file_header.e_shstrndx)
  11974. {
  11975. strtab = filedata->string_table;
  11976. strtab_size = filedata->string_table_length;
  11977. }
  11978. else if (section->sh_link < filedata->file_header.e_shnum)
  11979. {
  11980. Elf_Internal_Shdr * string_sec;
  11981. string_sec = filedata->section_headers + section->sh_link;
  11982. strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset,
  11983. 1, string_sec->sh_size,
  11984. _("string table"));
  11985. strtab_size = strtab != NULL ? string_sec->sh_size : 0;
  11986. }
  11987. for (si = 0; si < num_syms; si++)
  11988. print_dynamic_symbol (filedata, si, symtab, section,
  11989. strtab, strtab_size);
  11990. free (symtab);
  11991. if (strtab != filedata->string_table)
  11992. free (strtab);
  11993. }
  11994. }
  11995. else if (do_syms)
  11996. printf
  11997. (_("\nDynamic symbol information is not available for displaying symbols.\n"));
  11998. if (do_histogram && filedata->buckets != NULL)
  11999. {
  12000. unsigned long * lengths;
  12001. unsigned long * counts;
  12002. unsigned long hn;
  12003. bfd_vma si;
  12004. unsigned long maxlength = 0;
  12005. unsigned long nzero_counts = 0;
  12006. unsigned long nsyms = 0;
  12007. char *visited;
  12008. printf (ngettext ("\nHistogram for bucket list length "
  12009. "(total of %lu bucket):\n",
  12010. "\nHistogram for bucket list length "
  12011. "(total of %lu buckets):\n",
  12012. (unsigned long) filedata->nbuckets),
  12013. (unsigned long) filedata->nbuckets);
  12014. lengths = (unsigned long *) calloc (filedata->nbuckets,
  12015. sizeof (*lengths));
  12016. if (lengths == NULL)
  12017. {
  12018. error (_("Out of memory allocating space for histogram buckets\n"));
  12019. goto err_out;
  12020. }
  12021. visited = xcmalloc (filedata->nchains, 1);
  12022. memset (visited, 0, filedata->nchains);
  12023. printf (_(" Length Number %% of total Coverage\n"));
  12024. for (hn = 0; hn < filedata->nbuckets; ++hn)
  12025. {
  12026. for (si = filedata->buckets[hn]; si > 0; si = filedata->chains[si])
  12027. {
  12028. ++nsyms;
  12029. if (maxlength < ++lengths[hn])
  12030. ++maxlength;
  12031. if (si >= filedata->nchains || visited[si])
  12032. {
  12033. error (_("histogram chain is corrupt\n"));
  12034. break;
  12035. }
  12036. visited[si] = 1;
  12037. }
  12038. }
  12039. free (visited);
  12040. counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
  12041. if (counts == NULL)
  12042. {
  12043. free (lengths);
  12044. error (_("Out of memory allocating space for histogram counts\n"));
  12045. goto err_out;
  12046. }
  12047. for (hn = 0; hn < filedata->nbuckets; ++hn)
  12048. ++counts[lengths[hn]];
  12049. if (filedata->nbuckets > 0)
  12050. {
  12051. unsigned long i;
  12052. printf (" 0 %-10lu (%5.1f%%)\n",
  12053. counts[0], (counts[0] * 100.0) / filedata->nbuckets);
  12054. for (i = 1; i <= maxlength; ++i)
  12055. {
  12056. nzero_counts += counts[i] * i;
  12057. printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
  12058. i, counts[i], (counts[i] * 100.0) / filedata->nbuckets,
  12059. (nzero_counts * 100.0) / nsyms);
  12060. }
  12061. }
  12062. free (counts);
  12063. free (lengths);
  12064. }
  12065. free (filedata->buckets);
  12066. filedata->buckets = NULL;
  12067. filedata->nbuckets = 0;
  12068. free (filedata->chains);
  12069. filedata->chains = NULL;
  12070. if (do_histogram && filedata->gnubuckets != NULL)
  12071. {
  12072. unsigned long * lengths;
  12073. unsigned long * counts;
  12074. unsigned long hn;
  12075. unsigned long maxlength = 0;
  12076. unsigned long nzero_counts = 0;
  12077. unsigned long nsyms = 0;
  12078. printf (ngettext ("\nHistogram for `%s' bucket list length "
  12079. "(total of %lu bucket):\n",
  12080. "\nHistogram for `%s' bucket list length "
  12081. "(total of %lu buckets):\n",
  12082. (unsigned long) filedata->ngnubuckets),
  12083. GNU_HASH_SECTION_NAME (filedata),
  12084. (unsigned long) filedata->ngnubuckets);
  12085. lengths = (unsigned long *) calloc (filedata->ngnubuckets,
  12086. sizeof (*lengths));
  12087. if (lengths == NULL)
  12088. {
  12089. error (_("Out of memory allocating space for gnu histogram buckets\n"));
  12090. goto err_out;
  12091. }
  12092. printf (_(" Length Number %% of total Coverage\n"));
  12093. for (hn = 0; hn < filedata->ngnubuckets; ++hn)
  12094. if (filedata->gnubuckets[hn] != 0)
  12095. {
  12096. bfd_vma off, length = 1;
  12097. for (off = filedata->gnubuckets[hn] - filedata->gnusymidx;
  12098. /* PR 17531 file: 010-77222-0.004. */
  12099. off < filedata->ngnuchains
  12100. && (filedata->gnuchains[off] & 1) == 0;
  12101. ++off)
  12102. ++length;
  12103. lengths[hn] = length;
  12104. if (length > maxlength)
  12105. maxlength = length;
  12106. nsyms += length;
  12107. }
  12108. counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
  12109. if (counts == NULL)
  12110. {
  12111. free (lengths);
  12112. error (_("Out of memory allocating space for gnu histogram counts\n"));
  12113. goto err_out;
  12114. }
  12115. for (hn = 0; hn < filedata->ngnubuckets; ++hn)
  12116. ++counts[lengths[hn]];
  12117. if (filedata->ngnubuckets > 0)
  12118. {
  12119. unsigned long j;
  12120. printf (" 0 %-10lu (%5.1f%%)\n",
  12121. counts[0], (counts[0] * 100.0) / filedata->ngnubuckets);
  12122. for (j = 1; j <= maxlength; ++j)
  12123. {
  12124. nzero_counts += counts[j] * j;
  12125. printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
  12126. j, counts[j], (counts[j] * 100.0) / filedata->ngnubuckets,
  12127. (nzero_counts * 100.0) / nsyms);
  12128. }
  12129. }
  12130. free (counts);
  12131. free (lengths);
  12132. }
  12133. free (filedata->gnubuckets);
  12134. filedata->gnubuckets = NULL;
  12135. filedata->ngnubuckets = 0;
  12136. free (filedata->gnuchains);
  12137. filedata->gnuchains = NULL;
  12138. filedata->ngnuchains = 0;
  12139. free (filedata->mipsxlat);
  12140. filedata->mipsxlat = NULL;
  12141. return true;
  12142. err_out:
  12143. free (filedata->gnubuckets);
  12144. filedata->gnubuckets = NULL;
  12145. filedata->ngnubuckets = 0;
  12146. free (filedata->gnuchains);
  12147. filedata->gnuchains = NULL;
  12148. filedata->ngnuchains = 0;
  12149. free (filedata->mipsxlat);
  12150. filedata->mipsxlat = NULL;
  12151. free (filedata->buckets);
  12152. filedata->buckets = NULL;
  12153. filedata->nbuckets = 0;
  12154. free (filedata->chains);
  12155. filedata->chains = NULL;
  12156. return false;
  12157. }
  12158. static bool
  12159. process_syminfo (Filedata * filedata)
  12160. {
  12161. unsigned int i;
  12162. if (filedata->dynamic_syminfo == NULL
  12163. || !do_dynamic)
  12164. /* No syminfo, this is ok. */
  12165. return true;
  12166. /* There better should be a dynamic symbol section. */
  12167. if (filedata->dynamic_symbols == NULL || filedata->dynamic_strings == NULL)
  12168. return false;
  12169. if (filedata->is_separate)
  12170. printf (ngettext ("\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entry:\n",
  12171. "\nIn linked file '%s: the dynamic info segment at offset 0x%lx contains %d entries:\n",
  12172. filedata->dynamic_syminfo_nent),
  12173. filedata->file_name,
  12174. filedata->dynamic_syminfo_offset,
  12175. filedata->dynamic_syminfo_nent);
  12176. else
  12177. printf (ngettext ("\nDynamic info segment at offset 0x%lx "
  12178. "contains %d entry:\n",
  12179. "\nDynamic info segment at offset 0x%lx "
  12180. "contains %d entries:\n",
  12181. filedata->dynamic_syminfo_nent),
  12182. filedata->dynamic_syminfo_offset,
  12183. filedata->dynamic_syminfo_nent);
  12184. printf (_(" Num: Name BoundTo Flags\n"));
  12185. for (i = 0; i < filedata->dynamic_syminfo_nent; ++i)
  12186. {
  12187. unsigned short int flags = filedata->dynamic_syminfo[i].si_flags;
  12188. printf ("%4d: ", i);
  12189. if (i >= filedata->num_dynamic_syms)
  12190. printf (_("<corrupt index>"));
  12191. else if (valid_dynamic_name (filedata, filedata->dynamic_symbols[i].st_name))
  12192. print_symbol (30, get_dynamic_name (filedata,
  12193. filedata->dynamic_symbols[i].st_name));
  12194. else
  12195. printf (_("<corrupt: %19ld>"), filedata->dynamic_symbols[i].st_name);
  12196. putchar (' ');
  12197. switch (filedata->dynamic_syminfo[i].si_boundto)
  12198. {
  12199. case SYMINFO_BT_SELF:
  12200. fputs ("SELF ", stdout);
  12201. break;
  12202. case SYMINFO_BT_PARENT:
  12203. fputs ("PARENT ", stdout);
  12204. break;
  12205. default:
  12206. if (filedata->dynamic_syminfo[i].si_boundto > 0
  12207. && filedata->dynamic_syminfo[i].si_boundto < filedata->dynamic_nent
  12208. && valid_dynamic_name (filedata,
  12209. filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val))
  12210. {
  12211. print_symbol (10, get_dynamic_name (filedata,
  12212. filedata->dynamic_section[filedata->dynamic_syminfo[i].si_boundto].d_un.d_val));
  12213. putchar (' ' );
  12214. }
  12215. else
  12216. printf ("%-10d ", filedata->dynamic_syminfo[i].si_boundto);
  12217. break;
  12218. }
  12219. if (flags & SYMINFO_FLG_DIRECT)
  12220. printf (" DIRECT");
  12221. if (flags & SYMINFO_FLG_PASSTHRU)
  12222. printf (" PASSTHRU");
  12223. if (flags & SYMINFO_FLG_COPY)
  12224. printf (" COPY");
  12225. if (flags & SYMINFO_FLG_LAZYLOAD)
  12226. printf (" LAZYLOAD");
  12227. puts ("");
  12228. }
  12229. return true;
  12230. }
  12231. /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM
  12232. is contained by the region START .. END. The types of ADDR, START
  12233. and END should all be the same. Note both ADDR + NELEM and END
  12234. point to just beyond the end of the regions that are being tested. */
  12235. #define IN_RANGE(START,END,ADDR,NELEM) \
  12236. (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END)))
  12237. /* Check to see if the given reloc needs to be handled in a target specific
  12238. manner. If so then process the reloc and return TRUE otherwise return
  12239. FALSE.
  12240. If called with reloc == NULL, then this is a signal that reloc processing
  12241. for the current section has finished, and any saved state should be
  12242. discarded. */
  12243. static bool
  12244. target_specific_reloc_handling (Filedata * filedata,
  12245. Elf_Internal_Rela * reloc,
  12246. unsigned char * start,
  12247. unsigned char * end,
  12248. Elf_Internal_Sym * symtab,
  12249. unsigned long num_syms)
  12250. {
  12251. unsigned int reloc_type = 0;
  12252. unsigned long sym_index = 0;
  12253. if (reloc)
  12254. {
  12255. reloc_type = get_reloc_type (filedata, reloc->r_info);
  12256. sym_index = get_reloc_symindex (reloc->r_info);
  12257. }
  12258. switch (filedata->file_header.e_machine)
  12259. {
  12260. case EM_MSP430:
  12261. case EM_MSP430_OLD:
  12262. {
  12263. static Elf_Internal_Sym * saved_sym = NULL;
  12264. if (reloc == NULL)
  12265. {
  12266. saved_sym = NULL;
  12267. return true;
  12268. }
  12269. switch (reloc_type)
  12270. {
  12271. case 10: /* R_MSP430_SYM_DIFF */
  12272. case 12: /* R_MSP430_GNU_SUB_ULEB128 */
  12273. if (uses_msp430x_relocs (filedata))
  12274. break;
  12275. /* Fall through. */
  12276. case 21: /* R_MSP430X_SYM_DIFF */
  12277. case 23: /* R_MSP430X_GNU_SUB_ULEB128 */
  12278. /* PR 21139. */
  12279. if (sym_index >= num_syms)
  12280. error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
  12281. sym_index);
  12282. else
  12283. saved_sym = symtab + sym_index;
  12284. return true;
  12285. case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
  12286. case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
  12287. goto handle_sym_diff;
  12288. case 5: /* R_MSP430_16_BYTE */
  12289. case 9: /* R_MSP430_8 */
  12290. case 11: /* R_MSP430_GNU_SET_ULEB128 */
  12291. if (uses_msp430x_relocs (filedata))
  12292. break;
  12293. goto handle_sym_diff;
  12294. case 2: /* R_MSP430_ABS16 */
  12295. case 15: /* R_MSP430X_ABS16 */
  12296. case 22: /* R_MSP430X_GNU_SET_ULEB128 */
  12297. if (! uses_msp430x_relocs (filedata))
  12298. break;
  12299. goto handle_sym_diff;
  12300. handle_sym_diff:
  12301. if (saved_sym != NULL)
  12302. {
  12303. bfd_vma value;
  12304. unsigned int reloc_size = 0;
  12305. int leb_ret = 0;
  12306. switch (reloc_type)
  12307. {
  12308. case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
  12309. reloc_size = 4;
  12310. break;
  12311. case 11: /* R_MSP430_GNU_SET_ULEB128 */
  12312. case 22: /* R_MSP430X_GNU_SET_ULEB128 */
  12313. if (reloc->r_offset < (size_t) (end - start))
  12314. read_leb128 (start + reloc->r_offset, end, false,
  12315. &reloc_size, &leb_ret);
  12316. break;
  12317. default:
  12318. reloc_size = 2;
  12319. break;
  12320. }
  12321. if (leb_ret != 0 || reloc_size == 0 || reloc_size > 8)
  12322. error (_("MSP430 ULEB128 field at 0x%lx contains invalid "
  12323. "ULEB128 value\n"),
  12324. (long) reloc->r_offset);
  12325. else if (sym_index >= num_syms)
  12326. error (_("MSP430 reloc contains invalid symbol index %lu\n"),
  12327. sym_index);
  12328. else
  12329. {
  12330. value = reloc->r_addend + (symtab[sym_index].st_value
  12331. - saved_sym->st_value);
  12332. if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
  12333. byte_put (start + reloc->r_offset, value, reloc_size);
  12334. else
  12335. /* PR 21137 */
  12336. error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
  12337. (long) reloc->r_offset);
  12338. }
  12339. saved_sym = NULL;
  12340. return true;
  12341. }
  12342. break;
  12343. default:
  12344. if (saved_sym != NULL)
  12345. error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
  12346. break;
  12347. }
  12348. break;
  12349. }
  12350. case EM_MN10300:
  12351. case EM_CYGNUS_MN10300:
  12352. {
  12353. static Elf_Internal_Sym * saved_sym = NULL;
  12354. if (reloc == NULL)
  12355. {
  12356. saved_sym = NULL;
  12357. return true;
  12358. }
  12359. switch (reloc_type)
  12360. {
  12361. case 34: /* R_MN10300_ALIGN */
  12362. return true;
  12363. case 33: /* R_MN10300_SYM_DIFF */
  12364. if (sym_index >= num_syms)
  12365. error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
  12366. sym_index);
  12367. else
  12368. saved_sym = symtab + sym_index;
  12369. return true;
  12370. case 1: /* R_MN10300_32 */
  12371. case 2: /* R_MN10300_16 */
  12372. if (saved_sym != NULL)
  12373. {
  12374. int reloc_size = reloc_type == 1 ? 4 : 2;
  12375. bfd_vma value;
  12376. if (sym_index >= num_syms)
  12377. error (_("MN10300 reloc contains invalid symbol index %lu\n"),
  12378. sym_index);
  12379. else
  12380. {
  12381. value = reloc->r_addend + (symtab[sym_index].st_value
  12382. - saved_sym->st_value);
  12383. if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
  12384. byte_put (start + reloc->r_offset, value, reloc_size);
  12385. else
  12386. error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
  12387. (long) reloc->r_offset);
  12388. }
  12389. saved_sym = NULL;
  12390. return true;
  12391. }
  12392. break;
  12393. default:
  12394. if (saved_sym != NULL)
  12395. error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
  12396. break;
  12397. }
  12398. break;
  12399. }
  12400. case EM_RL78:
  12401. {
  12402. static bfd_vma saved_sym1 = 0;
  12403. static bfd_vma saved_sym2 = 0;
  12404. static bfd_vma value;
  12405. if (reloc == NULL)
  12406. {
  12407. saved_sym1 = saved_sym2 = 0;
  12408. return true;
  12409. }
  12410. switch (reloc_type)
  12411. {
  12412. case 0x80: /* R_RL78_SYM. */
  12413. saved_sym1 = saved_sym2;
  12414. if (sym_index >= num_syms)
  12415. error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
  12416. sym_index);
  12417. else
  12418. {
  12419. saved_sym2 = symtab[sym_index].st_value;
  12420. saved_sym2 += reloc->r_addend;
  12421. }
  12422. return true;
  12423. case 0x83: /* R_RL78_OPsub. */
  12424. value = saved_sym1 - saved_sym2;
  12425. saved_sym2 = saved_sym1 = 0;
  12426. return true;
  12427. break;
  12428. case 0x41: /* R_RL78_ABS32. */
  12429. if (IN_RANGE (start, end, start + reloc->r_offset, 4))
  12430. byte_put (start + reloc->r_offset, value, 4);
  12431. else
  12432. error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
  12433. (long) reloc->r_offset);
  12434. value = 0;
  12435. return true;
  12436. case 0x43: /* R_RL78_ABS16. */
  12437. if (IN_RANGE (start, end, start + reloc->r_offset, 2))
  12438. byte_put (start + reloc->r_offset, value, 2);
  12439. else
  12440. error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
  12441. (long) reloc->r_offset);
  12442. value = 0;
  12443. return true;
  12444. default:
  12445. break;
  12446. }
  12447. break;
  12448. }
  12449. }
  12450. return false;
  12451. }
  12452. /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
  12453. DWARF debug sections. This is a target specific test. Note - we do not
  12454. go through the whole including-target-headers-multiple-times route, (as
  12455. we have already done with <elf/h8.h>) because this would become very
  12456. messy and even then this function would have to contain target specific
  12457. information (the names of the relocs instead of their numeric values).
  12458. FIXME: This is not the correct way to solve this problem. The proper way
  12459. is to have target specific reloc sizing and typing functions created by
  12460. the reloc-macros.h header, in the same way that it already creates the
  12461. reloc naming functions. */
  12462. static bool
  12463. is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
  12464. {
  12465. /* Please keep this table alpha-sorted for ease of visual lookup. */
  12466. switch (filedata->file_header.e_machine)
  12467. {
  12468. case EM_386:
  12469. case EM_IAMCU:
  12470. return reloc_type == 1; /* R_386_32. */
  12471. case EM_68K:
  12472. return reloc_type == 1; /* R_68K_32. */
  12473. case EM_860:
  12474. return reloc_type == 1; /* R_860_32. */
  12475. case EM_960:
  12476. return reloc_type == 2; /* R_960_32. */
  12477. case EM_AARCH64:
  12478. return (reloc_type == 258
  12479. || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
  12480. case EM_BPF:
  12481. return reloc_type == 11; /* R_BPF_DATA_32 */
  12482. case EM_ADAPTEVA_EPIPHANY:
  12483. return reloc_type == 3;
  12484. case EM_ALPHA:
  12485. return reloc_type == 1; /* R_ALPHA_REFLONG. */
  12486. case EM_ARC:
  12487. return reloc_type == 1; /* R_ARC_32. */
  12488. case EM_ARC_COMPACT:
  12489. case EM_ARC_COMPACT2:
  12490. return reloc_type == 4; /* R_ARC_32. */
  12491. case EM_ARM:
  12492. return reloc_type == 2; /* R_ARM_ABS32 */
  12493. case EM_AVR_OLD:
  12494. case EM_AVR:
  12495. return reloc_type == 1;
  12496. case EM_BLACKFIN:
  12497. return reloc_type == 0x12; /* R_byte4_data. */
  12498. case EM_CRIS:
  12499. return reloc_type == 3; /* R_CRIS_32. */
  12500. case EM_CR16:
  12501. return reloc_type == 3; /* R_CR16_NUM32. */
  12502. case EM_CRX:
  12503. return reloc_type == 15; /* R_CRX_NUM32. */
  12504. case EM_CSKY:
  12505. return reloc_type == 1; /* R_CKCORE_ADDR32. */
  12506. case EM_CYGNUS_FRV:
  12507. return reloc_type == 1;
  12508. case EM_CYGNUS_D10V:
  12509. case EM_D10V:
  12510. return reloc_type == 6; /* R_D10V_32. */
  12511. case EM_CYGNUS_D30V:
  12512. case EM_D30V:
  12513. return reloc_type == 12; /* R_D30V_32_NORMAL. */
  12514. case EM_DLX:
  12515. return reloc_type == 3; /* R_DLX_RELOC_32. */
  12516. case EM_CYGNUS_FR30:
  12517. case EM_FR30:
  12518. return reloc_type == 3; /* R_FR30_32. */
  12519. case EM_FT32:
  12520. return reloc_type == 1; /* R_FT32_32. */
  12521. case EM_H8S:
  12522. case EM_H8_300:
  12523. case EM_H8_300H:
  12524. return reloc_type == 1; /* R_H8_DIR32. */
  12525. case EM_IA_64:
  12526. return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */
  12527. || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */
  12528. || reloc_type == 0x24 /* R_IA64_DIR32MSB. */
  12529. || reloc_type == 0x25 /* R_IA64_DIR32LSB. */);
  12530. case EM_IP2K_OLD:
  12531. case EM_IP2K:
  12532. return reloc_type == 2; /* R_IP2K_32. */
  12533. case EM_IQ2000:
  12534. return reloc_type == 2; /* R_IQ2000_32. */
  12535. case EM_LATTICEMICO32:
  12536. return reloc_type == 3; /* R_LM32_32. */
  12537. case EM_LOONGARCH:
  12538. return reloc_type == 1; /* R_LARCH_32. */
  12539. case EM_M32C_OLD:
  12540. case EM_M32C:
  12541. return reloc_type == 3; /* R_M32C_32. */
  12542. case EM_M32R:
  12543. return reloc_type == 34; /* R_M32R_32_RELA. */
  12544. case EM_68HC11:
  12545. case EM_68HC12:
  12546. return reloc_type == 6; /* R_M68HC11_32. */
  12547. case EM_S12Z:
  12548. return reloc_type == 7 || /* R_S12Z_EXT32 */
  12549. reloc_type == 6; /* R_S12Z_CW32. */
  12550. case EM_MCORE:
  12551. return reloc_type == 1; /* R_MCORE_ADDR32. */
  12552. case EM_CYGNUS_MEP:
  12553. return reloc_type == 4; /* R_MEP_32. */
  12554. case EM_METAG:
  12555. return reloc_type == 2; /* R_METAG_ADDR32. */
  12556. case EM_MICROBLAZE:
  12557. return reloc_type == 1; /* R_MICROBLAZE_32. */
  12558. case EM_MIPS:
  12559. return reloc_type == 2; /* R_MIPS_32. */
  12560. case EM_MMIX:
  12561. return reloc_type == 4; /* R_MMIX_32. */
  12562. case EM_CYGNUS_MN10200:
  12563. case EM_MN10200:
  12564. return reloc_type == 1; /* R_MN10200_32. */
  12565. case EM_CYGNUS_MN10300:
  12566. case EM_MN10300:
  12567. return reloc_type == 1; /* R_MN10300_32. */
  12568. case EM_MOXIE:
  12569. return reloc_type == 1; /* R_MOXIE_32. */
  12570. case EM_MSP430_OLD:
  12571. case EM_MSP430:
  12572. return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */
  12573. case EM_MT:
  12574. return reloc_type == 2; /* R_MT_32. */
  12575. case EM_NDS32:
  12576. return reloc_type == 20; /* R_NDS32_32_RELA. */
  12577. case EM_ALTERA_NIOS2:
  12578. return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */
  12579. case EM_NIOS32:
  12580. return reloc_type == 1; /* R_NIOS_32. */
  12581. case EM_OR1K:
  12582. return reloc_type == 1; /* R_OR1K_32. */
  12583. case EM_PARISC:
  12584. return (reloc_type == 1 /* R_PARISC_DIR32. */
  12585. || reloc_type == 2 /* R_PARISC_DIR21L. */
  12586. || reloc_type == 41); /* R_PARISC_SECREL32. */
  12587. case EM_PJ:
  12588. case EM_PJ_OLD:
  12589. return reloc_type == 1; /* R_PJ_DATA_DIR32. */
  12590. case EM_PPC64:
  12591. return reloc_type == 1; /* R_PPC64_ADDR32. */
  12592. case EM_PPC:
  12593. return reloc_type == 1; /* R_PPC_ADDR32. */
  12594. case EM_TI_PRU:
  12595. return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */
  12596. case EM_RISCV:
  12597. return reloc_type == 1; /* R_RISCV_32. */
  12598. case EM_RL78:
  12599. return reloc_type == 1; /* R_RL78_DIR32. */
  12600. case EM_RX:
  12601. return reloc_type == 1; /* R_RX_DIR32. */
  12602. case EM_S370:
  12603. return reloc_type == 1; /* R_I370_ADDR31. */
  12604. case EM_S390_OLD:
  12605. case EM_S390:
  12606. return reloc_type == 4; /* R_S390_32. */
  12607. case EM_SCORE:
  12608. return reloc_type == 8; /* R_SCORE_ABS32. */
  12609. case EM_SH:
  12610. return reloc_type == 1; /* R_SH_DIR32. */
  12611. case EM_SPARC32PLUS:
  12612. case EM_SPARCV9:
  12613. case EM_SPARC:
  12614. return reloc_type == 3 /* R_SPARC_32. */
  12615. || reloc_type == 23; /* R_SPARC_UA32. */
  12616. case EM_SPU:
  12617. return reloc_type == 6; /* R_SPU_ADDR32 */
  12618. case EM_TI_C6000:
  12619. return reloc_type == 1; /* R_C6000_ABS32. */
  12620. case EM_TILEGX:
  12621. return reloc_type == 2; /* R_TILEGX_32. */
  12622. case EM_TILEPRO:
  12623. return reloc_type == 1; /* R_TILEPRO_32. */
  12624. case EM_CYGNUS_V850:
  12625. case EM_V850:
  12626. return reloc_type == 6; /* R_V850_ABS32. */
  12627. case EM_V800:
  12628. return reloc_type == 0x33; /* R_V810_WORD. */
  12629. case EM_VAX:
  12630. return reloc_type == 1; /* R_VAX_32. */
  12631. case EM_VISIUM:
  12632. return reloc_type == 3; /* R_VISIUM_32. */
  12633. case EM_WEBASSEMBLY:
  12634. return reloc_type == 1; /* R_WASM32_32. */
  12635. case EM_X86_64:
  12636. case EM_L1OM:
  12637. case EM_K1OM:
  12638. return reloc_type == 10; /* R_X86_64_32. */
  12639. case EM_XC16X:
  12640. case EM_C166:
  12641. return reloc_type == 3; /* R_XC16C_ABS_32. */
  12642. case EM_XGATE:
  12643. return reloc_type == 4; /* R_XGATE_32. */
  12644. case EM_XSTORMY16:
  12645. return reloc_type == 1; /* R_XSTROMY16_32. */
  12646. case EM_XTENSA_OLD:
  12647. case EM_XTENSA:
  12648. return reloc_type == 1; /* R_XTENSA_32. */
  12649. case EM_Z80:
  12650. return reloc_type == 6; /* R_Z80_32. */
  12651. default:
  12652. {
  12653. static unsigned int prev_warn = 0;
  12654. /* Avoid repeating the same warning multiple times. */
  12655. if (prev_warn != filedata->file_header.e_machine)
  12656. error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
  12657. filedata->file_header.e_machine);
  12658. prev_warn = filedata->file_header.e_machine;
  12659. return false;
  12660. }
  12661. }
  12662. }
  12663. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  12664. a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
  12665. static bool
  12666. is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
  12667. {
  12668. switch (filedata->file_header.e_machine)
  12669. /* Please keep this table alpha-sorted for ease of visual lookup. */
  12670. {
  12671. case EM_386:
  12672. case EM_IAMCU:
  12673. return reloc_type == 2; /* R_386_PC32. */
  12674. case EM_68K:
  12675. return reloc_type == 4; /* R_68K_PC32. */
  12676. case EM_AARCH64:
  12677. return reloc_type == 261; /* R_AARCH64_PREL32 */
  12678. case EM_ADAPTEVA_EPIPHANY:
  12679. return reloc_type == 6;
  12680. case EM_ALPHA:
  12681. return reloc_type == 10; /* R_ALPHA_SREL32. */
  12682. case EM_ARC_COMPACT:
  12683. case EM_ARC_COMPACT2:
  12684. return reloc_type == 49; /* R_ARC_32_PCREL. */
  12685. case EM_ARM:
  12686. return reloc_type == 3; /* R_ARM_REL32 */
  12687. case EM_AVR_OLD:
  12688. case EM_AVR:
  12689. return reloc_type == 36; /* R_AVR_32_PCREL. */
  12690. case EM_MICROBLAZE:
  12691. return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */
  12692. case EM_OR1K:
  12693. return reloc_type == 9; /* R_OR1K_32_PCREL. */
  12694. case EM_PARISC:
  12695. return reloc_type == 9; /* R_PARISC_PCREL32. */
  12696. case EM_PPC:
  12697. return reloc_type == 26; /* R_PPC_REL32. */
  12698. case EM_PPC64:
  12699. return reloc_type == 26; /* R_PPC64_REL32. */
  12700. case EM_RISCV:
  12701. return reloc_type == 57; /* R_RISCV_32_PCREL. */
  12702. case EM_S390_OLD:
  12703. case EM_S390:
  12704. return reloc_type == 5; /* R_390_PC32. */
  12705. case EM_SH:
  12706. return reloc_type == 2; /* R_SH_REL32. */
  12707. case EM_SPARC32PLUS:
  12708. case EM_SPARCV9:
  12709. case EM_SPARC:
  12710. return reloc_type == 6; /* R_SPARC_DISP32. */
  12711. case EM_SPU:
  12712. return reloc_type == 13; /* R_SPU_REL32. */
  12713. case EM_TILEGX:
  12714. return reloc_type == 6; /* R_TILEGX_32_PCREL. */
  12715. case EM_TILEPRO:
  12716. return reloc_type == 4; /* R_TILEPRO_32_PCREL. */
  12717. case EM_VISIUM:
  12718. return reloc_type == 6; /* R_VISIUM_32_PCREL */
  12719. case EM_X86_64:
  12720. case EM_L1OM:
  12721. case EM_K1OM:
  12722. return reloc_type == 2; /* R_X86_64_PC32. */
  12723. case EM_VAX:
  12724. return reloc_type == 4; /* R_VAX_PCREL32. */
  12725. case EM_XTENSA_OLD:
  12726. case EM_XTENSA:
  12727. return reloc_type == 14; /* R_XTENSA_32_PCREL. */
  12728. default:
  12729. /* Do not abort or issue an error message here. Not all targets use
  12730. pc-relative 32-bit relocs in their DWARF debug information and we
  12731. have already tested for target coverage in is_32bit_abs_reloc. A
  12732. more helpful warning message will be generated by apply_relocations
  12733. anyway, so just return. */
  12734. return false;
  12735. }
  12736. }
  12737. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  12738. a 64-bit absolute RELA relocation used in DWARF debug sections. */
  12739. static bool
  12740. is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
  12741. {
  12742. switch (filedata->file_header.e_machine)
  12743. {
  12744. case EM_AARCH64:
  12745. return reloc_type == 257; /* R_AARCH64_ABS64. */
  12746. case EM_ALPHA:
  12747. return reloc_type == 2; /* R_ALPHA_REFQUAD. */
  12748. case EM_IA_64:
  12749. return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */
  12750. || reloc_type == 0x27 /* R_IA64_DIR64LSB. */);
  12751. case EM_LOONGARCH:
  12752. return reloc_type == 2; /* R_LARCH_64 */
  12753. case EM_PARISC:
  12754. return reloc_type == 80; /* R_PARISC_DIR64. */
  12755. case EM_PPC64:
  12756. return reloc_type == 38; /* R_PPC64_ADDR64. */
  12757. case EM_RISCV:
  12758. return reloc_type == 2; /* R_RISCV_64. */
  12759. case EM_SPARC32PLUS:
  12760. case EM_SPARCV9:
  12761. case EM_SPARC:
  12762. return reloc_type == 32 /* R_SPARC_64. */
  12763. || reloc_type == 54; /* R_SPARC_UA64. */
  12764. case EM_X86_64:
  12765. case EM_L1OM:
  12766. case EM_K1OM:
  12767. return reloc_type == 1; /* R_X86_64_64. */
  12768. case EM_S390_OLD:
  12769. case EM_S390:
  12770. return reloc_type == 22; /* R_S390_64. */
  12771. case EM_TILEGX:
  12772. return reloc_type == 1; /* R_TILEGX_64. */
  12773. case EM_MIPS:
  12774. return reloc_type == 18; /* R_MIPS_64. */
  12775. default:
  12776. return false;
  12777. }
  12778. }
  12779. /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
  12780. a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
  12781. static bool
  12782. is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type)
  12783. {
  12784. switch (filedata->file_header.e_machine)
  12785. {
  12786. case EM_AARCH64:
  12787. return reloc_type == 260; /* R_AARCH64_PREL64. */
  12788. case EM_ALPHA:
  12789. return reloc_type == 11; /* R_ALPHA_SREL64. */
  12790. case EM_IA_64:
  12791. return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */
  12792. || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */);
  12793. case EM_PARISC:
  12794. return reloc_type == 72; /* R_PARISC_PCREL64. */
  12795. case EM_PPC64:
  12796. return reloc_type == 44; /* R_PPC64_REL64. */
  12797. case EM_SPARC32PLUS:
  12798. case EM_SPARCV9:
  12799. case EM_SPARC:
  12800. return reloc_type == 46; /* R_SPARC_DISP64. */
  12801. case EM_X86_64:
  12802. case EM_L1OM:
  12803. case EM_K1OM:
  12804. return reloc_type == 24; /* R_X86_64_PC64. */
  12805. case EM_S390_OLD:
  12806. case EM_S390:
  12807. return reloc_type == 23; /* R_S390_PC64. */
  12808. case EM_TILEGX:
  12809. return reloc_type == 5; /* R_TILEGX_64_PCREL. */
  12810. default:
  12811. return false;
  12812. }
  12813. }
  12814. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  12815. a 24-bit absolute RELA relocation used in DWARF debug sections. */
  12816. static bool
  12817. is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
  12818. {
  12819. switch (filedata->file_header.e_machine)
  12820. {
  12821. case EM_CYGNUS_MN10200:
  12822. case EM_MN10200:
  12823. return reloc_type == 4; /* R_MN10200_24. */
  12824. case EM_FT32:
  12825. return reloc_type == 5; /* R_FT32_20. */
  12826. case EM_Z80:
  12827. return reloc_type == 5; /* R_Z80_24. */
  12828. default:
  12829. return false;
  12830. }
  12831. }
  12832. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  12833. a 16-bit absolute RELA relocation used in DWARF debug sections. */
  12834. static bool
  12835. is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
  12836. {
  12837. /* Please keep this table alpha-sorted for ease of visual lookup. */
  12838. switch (filedata->file_header.e_machine)
  12839. {
  12840. case EM_ARC:
  12841. case EM_ARC_COMPACT:
  12842. case EM_ARC_COMPACT2:
  12843. return reloc_type == 2; /* R_ARC_16. */
  12844. case EM_ADAPTEVA_EPIPHANY:
  12845. return reloc_type == 5;
  12846. case EM_AVR_OLD:
  12847. case EM_AVR:
  12848. return reloc_type == 4; /* R_AVR_16. */
  12849. case EM_CYGNUS_D10V:
  12850. case EM_D10V:
  12851. return reloc_type == 3; /* R_D10V_16. */
  12852. case EM_FT32:
  12853. return reloc_type == 2; /* R_FT32_16. */
  12854. case EM_H8S:
  12855. case EM_H8_300:
  12856. case EM_H8_300H:
  12857. return reloc_type == R_H8_DIR16;
  12858. case EM_IP2K_OLD:
  12859. case EM_IP2K:
  12860. return reloc_type == 1; /* R_IP2K_16. */
  12861. case EM_M32C_OLD:
  12862. case EM_M32C:
  12863. return reloc_type == 1; /* R_M32C_16 */
  12864. case EM_CYGNUS_MN10200:
  12865. case EM_MN10200:
  12866. return reloc_type == 2; /* R_MN10200_16. */
  12867. case EM_CYGNUS_MN10300:
  12868. case EM_MN10300:
  12869. return reloc_type == 2; /* R_MN10300_16. */
  12870. case EM_MSP430:
  12871. if (uses_msp430x_relocs (filedata))
  12872. return reloc_type == 2; /* R_MSP430_ABS16. */
  12873. /* Fall through. */
  12874. case EM_MSP430_OLD:
  12875. return reloc_type == 5; /* R_MSP430_16_BYTE. */
  12876. case EM_NDS32:
  12877. return reloc_type == 19; /* R_NDS32_16_RELA. */
  12878. case EM_ALTERA_NIOS2:
  12879. return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */
  12880. case EM_NIOS32:
  12881. return reloc_type == 9; /* R_NIOS_16. */
  12882. case EM_OR1K:
  12883. return reloc_type == 2; /* R_OR1K_16. */
  12884. case EM_RISCV:
  12885. return reloc_type == 55; /* R_RISCV_SET16. */
  12886. case EM_TI_PRU:
  12887. return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */
  12888. case EM_TI_C6000:
  12889. return reloc_type == 2; /* R_C6000_ABS16. */
  12890. case EM_VISIUM:
  12891. return reloc_type == 2; /* R_VISIUM_16. */
  12892. case EM_XC16X:
  12893. case EM_C166:
  12894. return reloc_type == 2; /* R_XC16C_ABS_16. */
  12895. case EM_XGATE:
  12896. return reloc_type == 3; /* R_XGATE_16. */
  12897. case EM_Z80:
  12898. return reloc_type == 4; /* R_Z80_16. */
  12899. default:
  12900. return false;
  12901. }
  12902. }
  12903. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  12904. a 8-bit absolute RELA relocation used in DWARF debug sections. */
  12905. static bool
  12906. is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
  12907. {
  12908. switch (filedata->file_header.e_machine)
  12909. {
  12910. case EM_RISCV:
  12911. return reloc_type == 54; /* R_RISCV_SET8. */
  12912. case EM_Z80:
  12913. return reloc_type == 1; /* R_Z80_8. */
  12914. default:
  12915. return false;
  12916. }
  12917. }
  12918. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  12919. a 6-bit absolute RELA relocation used in DWARF debug sections. */
  12920. static bool
  12921. is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
  12922. {
  12923. switch (filedata->file_header.e_machine)
  12924. {
  12925. case EM_RISCV:
  12926. return reloc_type == 53; /* R_RISCV_SET6. */
  12927. default:
  12928. return false;
  12929. }
  12930. }
  12931. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  12932. a 32-bit inplace add RELA relocation used in DWARF debug sections. */
  12933. static bool
  12934. is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
  12935. {
  12936. /* Please keep this table alpha-sorted for ease of visual lookup. */
  12937. switch (filedata->file_header.e_machine)
  12938. {
  12939. case EM_RISCV:
  12940. return reloc_type == 35; /* R_RISCV_ADD32. */
  12941. default:
  12942. return false;
  12943. }
  12944. }
  12945. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  12946. a 32-bit inplace sub RELA relocation used in DWARF debug sections. */
  12947. static bool
  12948. is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
  12949. {
  12950. /* Please keep this table alpha-sorted for ease of visual lookup. */
  12951. switch (filedata->file_header.e_machine)
  12952. {
  12953. case EM_RISCV:
  12954. return reloc_type == 39; /* R_RISCV_SUB32. */
  12955. default:
  12956. return false;
  12957. }
  12958. }
  12959. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  12960. a 64-bit inplace add RELA relocation used in DWARF debug sections. */
  12961. static bool
  12962. is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
  12963. {
  12964. /* Please keep this table alpha-sorted for ease of visual lookup. */
  12965. switch (filedata->file_header.e_machine)
  12966. {
  12967. case EM_RISCV:
  12968. return reloc_type == 36; /* R_RISCV_ADD64. */
  12969. default:
  12970. return false;
  12971. }
  12972. }
  12973. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  12974. a 64-bit inplace sub RELA relocation used in DWARF debug sections. */
  12975. static bool
  12976. is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
  12977. {
  12978. /* Please keep this table alpha-sorted for ease of visual lookup. */
  12979. switch (filedata->file_header.e_machine)
  12980. {
  12981. case EM_RISCV:
  12982. return reloc_type == 40; /* R_RISCV_SUB64. */
  12983. default:
  12984. return false;
  12985. }
  12986. }
  12987. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  12988. a 16-bit inplace add RELA relocation used in DWARF debug sections. */
  12989. static bool
  12990. is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
  12991. {
  12992. /* Please keep this table alpha-sorted for ease of visual lookup. */
  12993. switch (filedata->file_header.e_machine)
  12994. {
  12995. case EM_RISCV:
  12996. return reloc_type == 34; /* R_RISCV_ADD16. */
  12997. default:
  12998. return false;
  12999. }
  13000. }
  13001. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  13002. a 16-bit inplace sub RELA relocation used in DWARF debug sections. */
  13003. static bool
  13004. is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
  13005. {
  13006. /* Please keep this table alpha-sorted for ease of visual lookup. */
  13007. switch (filedata->file_header.e_machine)
  13008. {
  13009. case EM_RISCV:
  13010. return reloc_type == 38; /* R_RISCV_SUB16. */
  13011. default:
  13012. return false;
  13013. }
  13014. }
  13015. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  13016. a 8-bit inplace add RELA relocation used in DWARF debug sections. */
  13017. static bool
  13018. is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type)
  13019. {
  13020. /* Please keep this table alpha-sorted for ease of visual lookup. */
  13021. switch (filedata->file_header.e_machine)
  13022. {
  13023. case EM_RISCV:
  13024. return reloc_type == 33; /* R_RISCV_ADD8. */
  13025. default:
  13026. return false;
  13027. }
  13028. }
  13029. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  13030. a 8-bit inplace sub RELA relocation used in DWARF debug sections. */
  13031. static bool
  13032. is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
  13033. {
  13034. /* Please keep this table alpha-sorted for ease of visual lookup. */
  13035. switch (filedata->file_header.e_machine)
  13036. {
  13037. case EM_RISCV:
  13038. return reloc_type == 37; /* R_RISCV_SUB8. */
  13039. default:
  13040. return false;
  13041. }
  13042. }
  13043. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  13044. a 6-bit inplace sub RELA relocation used in DWARF debug sections. */
  13045. static bool
  13046. is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
  13047. {
  13048. switch (filedata->file_header.e_machine)
  13049. {
  13050. case EM_RISCV:
  13051. return reloc_type == 52; /* R_RISCV_SUB6. */
  13052. default:
  13053. return false;
  13054. }
  13055. }
  13056. /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
  13057. relocation entries (possibly formerly used for SHT_GROUP sections). */
  13058. static bool
  13059. is_none_reloc (Filedata * filedata, unsigned int reloc_type)
  13060. {
  13061. switch (filedata->file_header.e_machine)
  13062. {
  13063. case EM_386: /* R_386_NONE. */
  13064. case EM_68K: /* R_68K_NONE. */
  13065. case EM_ADAPTEVA_EPIPHANY:
  13066. case EM_ALPHA: /* R_ALPHA_NONE. */
  13067. case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */
  13068. case EM_ARC: /* R_ARC_NONE. */
  13069. case EM_ARC_COMPACT2: /* R_ARC_NONE. */
  13070. case EM_ARC_COMPACT: /* R_ARC_NONE. */
  13071. case EM_ARM: /* R_ARM_NONE. */
  13072. case EM_C166: /* R_XC16X_NONE. */
  13073. case EM_CRIS: /* R_CRIS_NONE. */
  13074. case EM_FT32: /* R_FT32_NONE. */
  13075. case EM_IA_64: /* R_IA64_NONE. */
  13076. case EM_K1OM: /* R_X86_64_NONE. */
  13077. case EM_L1OM: /* R_X86_64_NONE. */
  13078. case EM_M32R: /* R_M32R_NONE. */
  13079. case EM_MIPS: /* R_MIPS_NONE. */
  13080. case EM_MN10300: /* R_MN10300_NONE. */
  13081. case EM_MOXIE: /* R_MOXIE_NONE. */
  13082. case EM_NIOS32: /* R_NIOS_NONE. */
  13083. case EM_OR1K: /* R_OR1K_NONE. */
  13084. case EM_PARISC: /* R_PARISC_NONE. */
  13085. case EM_PPC64: /* R_PPC64_NONE. */
  13086. case EM_PPC: /* R_PPC_NONE. */
  13087. case EM_RISCV: /* R_RISCV_NONE. */
  13088. case EM_S390: /* R_390_NONE. */
  13089. case EM_S390_OLD:
  13090. case EM_SH: /* R_SH_NONE. */
  13091. case EM_SPARC32PLUS:
  13092. case EM_SPARC: /* R_SPARC_NONE. */
  13093. case EM_SPARCV9:
  13094. case EM_TILEGX: /* R_TILEGX_NONE. */
  13095. case EM_TILEPRO: /* R_TILEPRO_NONE. */
  13096. case EM_TI_C6000:/* R_C6000_NONE. */
  13097. case EM_X86_64: /* R_X86_64_NONE. */
  13098. case EM_XC16X:
  13099. case EM_Z80: /* R_Z80_NONE. */
  13100. case EM_WEBASSEMBLY: /* R_WASM32_NONE. */
  13101. return reloc_type == 0;
  13102. case EM_AARCH64:
  13103. return reloc_type == 0 || reloc_type == 256;
  13104. case EM_AVR_OLD:
  13105. case EM_AVR:
  13106. return (reloc_type == 0 /* R_AVR_NONE. */
  13107. || reloc_type == 30 /* R_AVR_DIFF8. */
  13108. || reloc_type == 31 /* R_AVR_DIFF16. */
  13109. || reloc_type == 32 /* R_AVR_DIFF32. */);
  13110. case EM_METAG:
  13111. return reloc_type == 3; /* R_METAG_NONE. */
  13112. case EM_NDS32:
  13113. return (reloc_type == 0 /* R_NDS32_NONE. */
  13114. || reloc_type == 205 /* R_NDS32_DIFF8. */
  13115. || reloc_type == 206 /* R_NDS32_DIFF16. */
  13116. || reloc_type == 207 /* R_NDS32_DIFF32. */
  13117. || reloc_type == 208 /* R_NDS32_DIFF_ULEB128. */);
  13118. case EM_TI_PRU:
  13119. return (reloc_type == 0 /* R_PRU_NONE. */
  13120. || reloc_type == 65 /* R_PRU_DIFF8. */
  13121. || reloc_type == 66 /* R_PRU_DIFF16. */
  13122. || reloc_type == 67 /* R_PRU_DIFF32. */);
  13123. case EM_XTENSA_OLD:
  13124. case EM_XTENSA:
  13125. return (reloc_type == 0 /* R_XTENSA_NONE. */
  13126. || reloc_type == 17 /* R_XTENSA_DIFF8. */
  13127. || reloc_type == 18 /* R_XTENSA_DIFF16. */
  13128. || reloc_type == 19 /* R_XTENSA_DIFF32. */
  13129. || reloc_type == 57 /* R_XTENSA_PDIFF8. */
  13130. || reloc_type == 58 /* R_XTENSA_PDIFF16. */
  13131. || reloc_type == 59 /* R_XTENSA_PDIFF32. */
  13132. || reloc_type == 60 /* R_XTENSA_NDIFF8. */
  13133. || reloc_type == 61 /* R_XTENSA_NDIFF16. */
  13134. || reloc_type == 62 /* R_XTENSA_NDIFF32. */);
  13135. }
  13136. return false;
  13137. }
  13138. /* Returns TRUE if there is a relocation against
  13139. section NAME at OFFSET bytes. */
  13140. bool
  13141. reloc_at (struct dwarf_section * dsec, dwarf_vma offset)
  13142. {
  13143. Elf_Internal_Rela * relocs;
  13144. Elf_Internal_Rela * rp;
  13145. if (dsec == NULL || dsec->reloc_info == NULL)
  13146. return false;
  13147. relocs = (Elf_Internal_Rela *) dsec->reloc_info;
  13148. for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp)
  13149. if (rp->r_offset == offset)
  13150. return true;
  13151. return false;
  13152. }
  13153. /* Apply relocations to a section.
  13154. Returns TRUE upon success, FALSE otherwise.
  13155. If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
  13156. It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
  13157. will be set to the number of relocs loaded.
  13158. Note: So far support has been added only for those relocations
  13159. which can be found in debug sections. FIXME: Add support for
  13160. more relocations ? */
  13161. static bool
  13162. apply_relocations (Filedata * filedata,
  13163. const Elf_Internal_Shdr * section,
  13164. unsigned char * start,
  13165. bfd_size_type size,
  13166. void ** relocs_return,
  13167. unsigned long * num_relocs_return)
  13168. {
  13169. Elf_Internal_Shdr * relsec;
  13170. unsigned char * end = start + size;
  13171. if (relocs_return != NULL)
  13172. {
  13173. * (Elf_Internal_Rela **) relocs_return = NULL;
  13174. * num_relocs_return = 0;
  13175. }
  13176. if (filedata->file_header.e_type != ET_REL)
  13177. /* No relocs to apply. */
  13178. return true;
  13179. /* Find the reloc section associated with the section. */
  13180. for (relsec = filedata->section_headers;
  13181. relsec < filedata->section_headers + filedata->file_header.e_shnum;
  13182. ++relsec)
  13183. {
  13184. bool is_rela;
  13185. unsigned long num_relocs;
  13186. Elf_Internal_Rela * relocs;
  13187. Elf_Internal_Rela * rp;
  13188. Elf_Internal_Shdr * symsec;
  13189. Elf_Internal_Sym * symtab;
  13190. unsigned long num_syms;
  13191. Elf_Internal_Sym * sym;
  13192. if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
  13193. || relsec->sh_info >= filedata->file_header.e_shnum
  13194. || filedata->section_headers + relsec->sh_info != section
  13195. || relsec->sh_size == 0
  13196. || relsec->sh_link >= filedata->file_header.e_shnum)
  13197. continue;
  13198. symsec = filedata->section_headers + relsec->sh_link;
  13199. if (symsec->sh_type != SHT_SYMTAB
  13200. && symsec->sh_type != SHT_DYNSYM)
  13201. return false;
  13202. is_rela = relsec->sh_type == SHT_RELA;
  13203. if (is_rela)
  13204. {
  13205. if (!slurp_rela_relocs (filedata, relsec->sh_offset,
  13206. relsec->sh_size, & relocs, & num_relocs))
  13207. return false;
  13208. }
  13209. else
  13210. {
  13211. if (!slurp_rel_relocs (filedata, relsec->sh_offset,
  13212. relsec->sh_size, & relocs, & num_relocs))
  13213. return false;
  13214. }
  13215. /* SH uses RELA but uses in place value instead of the addend field. */
  13216. if (filedata->file_header.e_machine == EM_SH)
  13217. is_rela = false;
  13218. symtab = get_elf_symbols (filedata, symsec, & num_syms);
  13219. for (rp = relocs; rp < relocs + num_relocs; ++rp)
  13220. {
  13221. bfd_vma addend;
  13222. unsigned int reloc_type;
  13223. unsigned int reloc_size;
  13224. bool reloc_inplace = false;
  13225. bool reloc_subtract = false;
  13226. unsigned char *rloc;
  13227. unsigned long sym_index;
  13228. reloc_type = get_reloc_type (filedata, rp->r_info);
  13229. if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms))
  13230. continue;
  13231. else if (is_none_reloc (filedata, reloc_type))
  13232. continue;
  13233. else if (is_32bit_abs_reloc (filedata, reloc_type)
  13234. || is_32bit_pcrel_reloc (filedata, reloc_type))
  13235. reloc_size = 4;
  13236. else if (is_64bit_abs_reloc (filedata, reloc_type)
  13237. || is_64bit_pcrel_reloc (filedata, reloc_type))
  13238. reloc_size = 8;
  13239. else if (is_24bit_abs_reloc (filedata, reloc_type))
  13240. reloc_size = 3;
  13241. else if (is_16bit_abs_reloc (filedata, reloc_type))
  13242. reloc_size = 2;
  13243. else if (is_8bit_abs_reloc (filedata, reloc_type)
  13244. || is_6bit_abs_reloc (filedata, reloc_type))
  13245. reloc_size = 1;
  13246. else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata,
  13247. reloc_type))
  13248. || is_32bit_inplace_add_reloc (filedata, reloc_type))
  13249. {
  13250. reloc_size = 4;
  13251. reloc_inplace = true;
  13252. }
  13253. else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata,
  13254. reloc_type))
  13255. || is_64bit_inplace_add_reloc (filedata, reloc_type))
  13256. {
  13257. reloc_size = 8;
  13258. reloc_inplace = true;
  13259. }
  13260. else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata,
  13261. reloc_type))
  13262. || is_16bit_inplace_add_reloc (filedata, reloc_type))
  13263. {
  13264. reloc_size = 2;
  13265. reloc_inplace = true;
  13266. }
  13267. else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata,
  13268. reloc_type))
  13269. || is_8bit_inplace_add_reloc (filedata, reloc_type))
  13270. {
  13271. reloc_size = 1;
  13272. reloc_inplace = true;
  13273. }
  13274. else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata,
  13275. reloc_type)))
  13276. {
  13277. reloc_size = 1;
  13278. reloc_inplace = true;
  13279. }
  13280. else
  13281. {
  13282. static unsigned int prev_reloc = 0;
  13283. if (reloc_type != prev_reloc)
  13284. warn (_("unable to apply unsupported reloc type %d to section %s\n"),
  13285. reloc_type, printable_section_name (filedata, section));
  13286. prev_reloc = reloc_type;
  13287. continue;
  13288. }
  13289. rloc = start + rp->r_offset;
  13290. if (!IN_RANGE (start, end, rloc, reloc_size))
  13291. {
  13292. warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
  13293. (unsigned long) rp->r_offset,
  13294. printable_section_name (filedata, section));
  13295. continue;
  13296. }
  13297. sym_index = (unsigned long) get_reloc_symindex (rp->r_info);
  13298. if (sym_index >= num_syms)
  13299. {
  13300. warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
  13301. sym_index, printable_section_name (filedata, section));
  13302. continue;
  13303. }
  13304. sym = symtab + sym_index;
  13305. /* If the reloc has a symbol associated with it,
  13306. make sure that it is of an appropriate type.
  13307. Relocations against symbols without type can happen.
  13308. Gcc -feliminate-dwarf2-dups may generate symbols
  13309. without type for debug info.
  13310. Icc generates relocations against function symbols
  13311. instead of local labels.
  13312. Relocations against object symbols can happen, eg when
  13313. referencing a global array. For an example of this see
  13314. the _clz.o binary in libgcc.a. */
  13315. if (sym != symtab
  13316. && ELF_ST_TYPE (sym->st_info) != STT_COMMON
  13317. && ELF_ST_TYPE (sym->st_info) > STT_SECTION)
  13318. {
  13319. warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"),
  13320. get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)),
  13321. printable_section_name (filedata, relsec),
  13322. (long int)(rp - relocs));
  13323. continue;
  13324. }
  13325. addend = 0;
  13326. if (is_rela)
  13327. addend += rp->r_addend;
  13328. /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
  13329. partial_inplace. */
  13330. if (!is_rela
  13331. || (filedata->file_header.e_machine == EM_XTENSA
  13332. && reloc_type == 1)
  13333. || ((filedata->file_header.e_machine == EM_PJ
  13334. || filedata->file_header.e_machine == EM_PJ_OLD)
  13335. && reloc_type == 1)
  13336. || ((filedata->file_header.e_machine == EM_D30V
  13337. || filedata->file_header.e_machine == EM_CYGNUS_D30V)
  13338. && reloc_type == 12)
  13339. || reloc_inplace)
  13340. {
  13341. if (is_6bit_inplace_sub_reloc (filedata, reloc_type))
  13342. addend += byte_get (rloc, reloc_size) & 0x3f;
  13343. else
  13344. addend += byte_get (rloc, reloc_size);
  13345. }
  13346. if (is_32bit_pcrel_reloc (filedata, reloc_type)
  13347. || is_64bit_pcrel_reloc (filedata, reloc_type))
  13348. {
  13349. /* On HPPA, all pc-relative relocations are biased by 8. */
  13350. if (filedata->file_header.e_machine == EM_PARISC)
  13351. addend -= 8;
  13352. byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
  13353. reloc_size);
  13354. }
  13355. else if (is_6bit_abs_reloc (filedata, reloc_type)
  13356. || is_6bit_inplace_sub_reloc (filedata, reloc_type))
  13357. {
  13358. if (reloc_subtract)
  13359. addend -= sym->st_value;
  13360. else
  13361. addend += sym->st_value;
  13362. addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0);
  13363. byte_put (rloc, addend, reloc_size);
  13364. }
  13365. else if (reloc_subtract)
  13366. byte_put (rloc, addend - sym->st_value, reloc_size);
  13367. else
  13368. byte_put (rloc, addend + sym->st_value, reloc_size);
  13369. }
  13370. free (symtab);
  13371. /* Let the target specific reloc processing code know that
  13372. we have finished with these relocs. */
  13373. target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0);
  13374. if (relocs_return)
  13375. {
  13376. * (Elf_Internal_Rela **) relocs_return = relocs;
  13377. * num_relocs_return = num_relocs;
  13378. }
  13379. else
  13380. free (relocs);
  13381. break;
  13382. }
  13383. return true;
  13384. }
  13385. #ifdef SUPPORT_DISASSEMBLY
  13386. static bool
  13387. disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata)
  13388. {
  13389. printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section));
  13390. /* FIXME: XXX -- to be done --- XXX */
  13391. return true;
  13392. }
  13393. #endif
  13394. /* Reads in the contents of SECTION from FILE, returning a pointer
  13395. to a malloc'ed buffer or NULL if something went wrong. */
  13396. static char *
  13397. get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata)
  13398. {
  13399. bfd_size_type num_bytes = section->sh_size;
  13400. if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
  13401. {
  13402. printf (_("Section '%s' has no data to dump.\n"),
  13403. printable_section_name (filedata, section));
  13404. return NULL;
  13405. }
  13406. return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes,
  13407. _("section contents"));
  13408. }
  13409. /* Uncompresses a section that was compressed using zlib, in place. */
  13410. static bool
  13411. uncompress_section_contents (unsigned char ** buffer,
  13412. dwarf_size_type uncompressed_size,
  13413. dwarf_size_type * size)
  13414. {
  13415. dwarf_size_type compressed_size = *size;
  13416. unsigned char * compressed_buffer = *buffer;
  13417. unsigned char * uncompressed_buffer;
  13418. z_stream strm;
  13419. int rc;
  13420. /* It is possible the section consists of several compressed
  13421. buffers concatenated together, so we uncompress in a loop. */
  13422. /* PR 18313: The state field in the z_stream structure is supposed
  13423. to be invisible to the user (ie us), but some compilers will
  13424. still complain about it being used without initialisation. So
  13425. we first zero the entire z_stream structure and then set the fields
  13426. that we need. */
  13427. memset (& strm, 0, sizeof strm);
  13428. strm.avail_in = compressed_size;
  13429. strm.next_in = (Bytef *) compressed_buffer;
  13430. strm.avail_out = uncompressed_size;
  13431. uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
  13432. rc = inflateInit (& strm);
  13433. while (strm.avail_in > 0)
  13434. {
  13435. if (rc != Z_OK)
  13436. break;
  13437. strm.next_out = ((Bytef *) uncompressed_buffer
  13438. + (uncompressed_size - strm.avail_out));
  13439. rc = inflate (&strm, Z_FINISH);
  13440. if (rc != Z_STREAM_END)
  13441. break;
  13442. rc = inflateReset (& strm);
  13443. }
  13444. if (inflateEnd (& strm) != Z_OK
  13445. || rc != Z_OK
  13446. || strm.avail_out != 0)
  13447. goto fail;
  13448. *buffer = uncompressed_buffer;
  13449. *size = uncompressed_size;
  13450. return true;
  13451. fail:
  13452. free (uncompressed_buffer);
  13453. /* Indicate decompression failure. */
  13454. *buffer = NULL;
  13455. return false;
  13456. }
  13457. static bool
  13458. dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata)
  13459. {
  13460. Elf_Internal_Shdr *relsec;
  13461. bfd_size_type num_bytes;
  13462. unsigned char *data;
  13463. unsigned char *end;
  13464. unsigned char *real_start;
  13465. unsigned char *start;
  13466. bool some_strings_shown;
  13467. real_start = start = (unsigned char *) get_section_contents (section, filedata);
  13468. if (start == NULL)
  13469. /* PR 21820: Do not fail if the section was empty. */
  13470. return section->sh_size == 0 || section->sh_type == SHT_NOBITS;
  13471. num_bytes = section->sh_size;
  13472. if (filedata->is_separate)
  13473. printf (_("\nString dump of section '%s' in linked file %s:\n"),
  13474. printable_section_name (filedata, section),
  13475. filedata->file_name);
  13476. else
  13477. printf (_("\nString dump of section '%s':\n"),
  13478. printable_section_name (filedata, section));
  13479. if (decompress_dumps)
  13480. {
  13481. dwarf_size_type new_size = num_bytes;
  13482. dwarf_size_type uncompressed_size = 0;
  13483. if ((section->sh_flags & SHF_COMPRESSED) != 0)
  13484. {
  13485. Elf_Internal_Chdr chdr;
  13486. unsigned int compression_header_size
  13487. = get_compression_header (& chdr, (unsigned char *) start,
  13488. num_bytes);
  13489. if (compression_header_size == 0)
  13490. /* An error message will have already been generated
  13491. by get_compression_header. */
  13492. goto error_out;
  13493. if (chdr.ch_type != ELFCOMPRESS_ZLIB)
  13494. {
  13495. warn (_("section '%s' has unsupported compress type: %d\n"),
  13496. printable_section_name (filedata, section), chdr.ch_type);
  13497. goto error_out;
  13498. }
  13499. uncompressed_size = chdr.ch_size;
  13500. start += compression_header_size;
  13501. new_size -= compression_header_size;
  13502. }
  13503. else if (new_size > 12 && streq ((char *) start, "ZLIB"))
  13504. {
  13505. /* Read the zlib header. In this case, it should be "ZLIB"
  13506. followed by the uncompressed section size, 8 bytes in
  13507. big-endian order. */
  13508. uncompressed_size = start[4]; uncompressed_size <<= 8;
  13509. uncompressed_size += start[5]; uncompressed_size <<= 8;
  13510. uncompressed_size += start[6]; uncompressed_size <<= 8;
  13511. uncompressed_size += start[7]; uncompressed_size <<= 8;
  13512. uncompressed_size += start[8]; uncompressed_size <<= 8;
  13513. uncompressed_size += start[9]; uncompressed_size <<= 8;
  13514. uncompressed_size += start[10]; uncompressed_size <<= 8;
  13515. uncompressed_size += start[11];
  13516. start += 12;
  13517. new_size -= 12;
  13518. }
  13519. if (uncompressed_size)
  13520. {
  13521. if (uncompress_section_contents (& start,
  13522. uncompressed_size, & new_size))
  13523. num_bytes = new_size;
  13524. else
  13525. {
  13526. error (_("Unable to decompress section %s\n"),
  13527. printable_section_name (filedata, section));
  13528. goto error_out;
  13529. }
  13530. }
  13531. else
  13532. start = real_start;
  13533. }
  13534. /* If the section being dumped has relocations against it the user might
  13535. be expecting these relocations to have been applied. Check for this
  13536. case and issue a warning message in order to avoid confusion.
  13537. FIXME: Maybe we ought to have an option that dumps a section with
  13538. relocs applied ? */
  13539. for (relsec = filedata->section_headers;
  13540. relsec < filedata->section_headers + filedata->file_header.e_shnum;
  13541. ++relsec)
  13542. {
  13543. if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
  13544. || relsec->sh_info >= filedata->file_header.e_shnum
  13545. || filedata->section_headers + relsec->sh_info != section
  13546. || relsec->sh_size == 0
  13547. || relsec->sh_link >= filedata->file_header.e_shnum)
  13548. continue;
  13549. printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
  13550. break;
  13551. }
  13552. data = start;
  13553. end = start + num_bytes;
  13554. some_strings_shown = false;
  13555. #ifdef HAVE_MBSTATE_T
  13556. mbstate_t state;
  13557. /* Initialise the multibyte conversion state. */
  13558. memset (& state, 0, sizeof (state));
  13559. #endif
  13560. bool continuing = false;
  13561. while (data < end)
  13562. {
  13563. while (!ISPRINT (* data))
  13564. if (++ data >= end)
  13565. break;
  13566. if (data < end)
  13567. {
  13568. size_t maxlen = end - data;
  13569. if (continuing)
  13570. {
  13571. printf (" ");
  13572. continuing = false;
  13573. }
  13574. else
  13575. {
  13576. printf (" [%6lx] ", (unsigned long) (data - start));
  13577. }
  13578. if (maxlen > 0)
  13579. {
  13580. char c = 0;
  13581. while (maxlen)
  13582. {
  13583. c = *data++;
  13584. if (c == 0)
  13585. break;
  13586. /* PR 25543: Treat new-lines as string-ending characters. */
  13587. if (c == '\n')
  13588. {
  13589. printf ("\\n\n");
  13590. if (*data != 0)
  13591. continuing = true;
  13592. break;
  13593. }
  13594. /* Do not print control characters directly as they can affect terminal
  13595. settings. Such characters usually appear in the names generated
  13596. by the assembler for local labels. */
  13597. if (ISCNTRL (c))
  13598. {
  13599. printf ("^%c", c + 0x40);
  13600. }
  13601. else if (ISPRINT (c))
  13602. {
  13603. putchar (c);
  13604. }
  13605. else
  13606. {
  13607. size_t n;
  13608. #ifdef HAVE_MBSTATE_T
  13609. wchar_t w;
  13610. #endif
  13611. /* Let printf do the hard work of displaying multibyte characters. */
  13612. printf ("%.1s", data - 1);
  13613. #ifdef HAVE_MBSTATE_T
  13614. /* Try to find out how many bytes made up the character that was
  13615. just printed. Advance the symbol pointer past the bytes that
  13616. were displayed. */
  13617. n = mbrtowc (& w, (char *)(data - 1), MB_CUR_MAX, & state);
  13618. #else
  13619. n = 1;
  13620. #endif
  13621. if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
  13622. data += (n - 1);
  13623. }
  13624. }
  13625. if (c != '\n')
  13626. putchar ('\n');
  13627. }
  13628. else
  13629. {
  13630. printf (_("<corrupt>\n"));
  13631. data = end;
  13632. }
  13633. some_strings_shown = true;
  13634. }
  13635. }
  13636. if (! some_strings_shown)
  13637. printf (_(" No strings found in this section."));
  13638. free (real_start);
  13639. putchar ('\n');
  13640. return true;
  13641. error_out:
  13642. free (real_start);
  13643. return false;
  13644. }
  13645. static bool
  13646. dump_section_as_bytes (Elf_Internal_Shdr *section,
  13647. Filedata *filedata,
  13648. bool relocate)
  13649. {
  13650. Elf_Internal_Shdr * relsec;
  13651. bfd_size_type bytes;
  13652. bfd_size_type section_size;
  13653. bfd_vma addr;
  13654. unsigned char * data;
  13655. unsigned char * real_start;
  13656. unsigned char * start;
  13657. real_start = start = (unsigned char *) get_section_contents (section, filedata);
  13658. if (start == NULL)
  13659. /* PR 21820: Do not fail if the section was empty. */
  13660. return section->sh_size == 0 || section->sh_type == SHT_NOBITS;
  13661. section_size = section->sh_size;
  13662. if (filedata->is_separate)
  13663. printf (_("\nHex dump of section '%s' in linked file %s:\n"),
  13664. printable_section_name (filedata, section),
  13665. filedata->file_name);
  13666. else
  13667. printf (_("\nHex dump of section '%s':\n"),
  13668. printable_section_name (filedata, section));
  13669. if (decompress_dumps)
  13670. {
  13671. dwarf_size_type new_size = section_size;
  13672. dwarf_size_type uncompressed_size = 0;
  13673. if ((section->sh_flags & SHF_COMPRESSED) != 0)
  13674. {
  13675. Elf_Internal_Chdr chdr;
  13676. unsigned int compression_header_size
  13677. = get_compression_header (& chdr, start, section_size);
  13678. if (compression_header_size == 0)
  13679. /* An error message will have already been generated
  13680. by get_compression_header. */
  13681. goto error_out;
  13682. if (chdr.ch_type != ELFCOMPRESS_ZLIB)
  13683. {
  13684. warn (_("section '%s' has unsupported compress type: %d\n"),
  13685. printable_section_name (filedata, section), chdr.ch_type);
  13686. goto error_out;
  13687. }
  13688. uncompressed_size = chdr.ch_size;
  13689. start += compression_header_size;
  13690. new_size -= compression_header_size;
  13691. }
  13692. else if (new_size > 12 && streq ((char *) start, "ZLIB"))
  13693. {
  13694. /* Read the zlib header. In this case, it should be "ZLIB"
  13695. followed by the uncompressed section size, 8 bytes in
  13696. big-endian order. */
  13697. uncompressed_size = start[4]; uncompressed_size <<= 8;
  13698. uncompressed_size += start[5]; uncompressed_size <<= 8;
  13699. uncompressed_size += start[6]; uncompressed_size <<= 8;
  13700. uncompressed_size += start[7]; uncompressed_size <<= 8;
  13701. uncompressed_size += start[8]; uncompressed_size <<= 8;
  13702. uncompressed_size += start[9]; uncompressed_size <<= 8;
  13703. uncompressed_size += start[10]; uncompressed_size <<= 8;
  13704. uncompressed_size += start[11];
  13705. start += 12;
  13706. new_size -= 12;
  13707. }
  13708. if (uncompressed_size)
  13709. {
  13710. if (uncompress_section_contents (& start, uncompressed_size,
  13711. & new_size))
  13712. {
  13713. section_size = new_size;
  13714. }
  13715. else
  13716. {
  13717. error (_("Unable to decompress section %s\n"),
  13718. printable_section_name (filedata, section));
  13719. /* FIXME: Print the section anyway ? */
  13720. goto error_out;
  13721. }
  13722. }
  13723. else
  13724. start = real_start;
  13725. }
  13726. if (relocate)
  13727. {
  13728. if (! apply_relocations (filedata, section, start, section_size, NULL, NULL))
  13729. goto error_out;
  13730. }
  13731. else
  13732. {
  13733. /* If the section being dumped has relocations against it the user might
  13734. be expecting these relocations to have been applied. Check for this
  13735. case and issue a warning message in order to avoid confusion.
  13736. FIXME: Maybe we ought to have an option that dumps a section with
  13737. relocs applied ? */
  13738. for (relsec = filedata->section_headers;
  13739. relsec < filedata->section_headers + filedata->file_header.e_shnum;
  13740. ++relsec)
  13741. {
  13742. if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
  13743. || relsec->sh_info >= filedata->file_header.e_shnum
  13744. || filedata->section_headers + relsec->sh_info != section
  13745. || relsec->sh_size == 0
  13746. || relsec->sh_link >= filedata->file_header.e_shnum)
  13747. continue;
  13748. printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
  13749. break;
  13750. }
  13751. }
  13752. addr = section->sh_addr;
  13753. bytes = section_size;
  13754. data = start;
  13755. while (bytes)
  13756. {
  13757. int j;
  13758. int k;
  13759. int lbytes;
  13760. lbytes = (bytes > 16 ? 16 : bytes);
  13761. printf (" 0x%8.8lx ", (unsigned long) addr);
  13762. for (j = 0; j < 16; j++)
  13763. {
  13764. if (j < lbytes)
  13765. printf ("%2.2x", data[j]);
  13766. else
  13767. printf (" ");
  13768. if ((j & 3) == 3)
  13769. printf (" ");
  13770. }
  13771. for (j = 0; j < lbytes; j++)
  13772. {
  13773. k = data[j];
  13774. if (k >= ' ' && k < 0x7f)
  13775. printf ("%c", k);
  13776. else
  13777. printf (".");
  13778. }
  13779. putchar ('\n');
  13780. data += lbytes;
  13781. addr += lbytes;
  13782. bytes -= lbytes;
  13783. }
  13784. free (real_start);
  13785. putchar ('\n');
  13786. return true;
  13787. error_out:
  13788. free (real_start);
  13789. return false;
  13790. }
  13791. #ifdef ENABLE_LIBCTF
  13792. static ctf_sect_t *
  13793. shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata)
  13794. {
  13795. buf->cts_name = section_name_print (filedata, shdr);
  13796. buf->cts_size = shdr->sh_size;
  13797. buf->cts_entsize = shdr->sh_entsize;
  13798. return buf;
  13799. }
  13800. /* Formatting callback function passed to ctf_dump. Returns either the pointer
  13801. it is passed, or a pointer to newly-allocated storage, in which case
  13802. dump_ctf() will free it when it no longer needs it. */
  13803. static char *
  13804. dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED,
  13805. char *s, void *arg)
  13806. {
  13807. const char *blanks = arg;
  13808. char *new_s;
  13809. if (asprintf (&new_s, "%s%s", blanks, s) < 0)
  13810. return s;
  13811. return new_s;
  13812. }
  13813. /* Dump CTF errors/warnings. */
  13814. static void
  13815. dump_ctf_errs (ctf_dict_t *fp)
  13816. {
  13817. ctf_next_t *it = NULL;
  13818. char *errtext;
  13819. int is_warning;
  13820. int err;
  13821. /* Dump accumulated errors and warnings. */
  13822. while ((errtext = ctf_errwarning_next (fp, &it, &is_warning, &err)) != NULL)
  13823. {
  13824. error (_("%s: %s"), is_warning ? _("warning"): _("error"),
  13825. errtext);
  13826. free (errtext);
  13827. }
  13828. if (err != ECTF_NEXT_END)
  13829. error (_("CTF error: cannot get CTF errors: `%s'"), ctf_errmsg (err));
  13830. }
  13831. /* Dump one CTF archive member. */
  13832. static void
  13833. dump_ctf_archive_member (ctf_dict_t *ctf, const char *name, ctf_dict_t *parent,
  13834. size_t member)
  13835. {
  13836. const char *things[] = {"Header", "Labels", "Data objects",
  13837. "Function objects", "Variables", "Types", "Strings",
  13838. ""};
  13839. const char **thing;
  13840. size_t i;
  13841. /* Don't print out the name of the default-named archive member if it appears
  13842. first in the list. The name .ctf appears everywhere, even for things that
  13843. aren't really archives, so printing it out is liable to be confusing; also,
  13844. the common case by far is for only one archive member to exist, and hiding
  13845. it in that case seems worthwhile. */
  13846. if (strcmp (name, ".ctf") != 0 || member != 0)
  13847. printf (_("\nCTF archive member: %s:\n"), name);
  13848. if (ctf_parent_name (ctf) != NULL)
  13849. ctf_import (ctf, parent);
  13850. for (i = 0, thing = things; *thing[0]; thing++, i++)
  13851. {
  13852. ctf_dump_state_t *s = NULL;
  13853. char *item;
  13854. printf ("\n %s:\n", *thing);
  13855. while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines,
  13856. (void *) " ")) != NULL)
  13857. {
  13858. printf ("%s\n", item);
  13859. free (item);
  13860. }
  13861. if (ctf_errno (ctf))
  13862. {
  13863. error (_("Iteration failed: %s, %s\n"), *thing,
  13864. ctf_errmsg (ctf_errno (ctf)));
  13865. break;
  13866. }
  13867. }
  13868. dump_ctf_errs (ctf);
  13869. }
  13870. static bool
  13871. dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
  13872. {
  13873. Elf_Internal_Shdr * symtab_sec = NULL;
  13874. Elf_Internal_Shdr * strtab_sec = NULL;
  13875. void * data = NULL;
  13876. void * symdata = NULL;
  13877. void * strdata = NULL;
  13878. ctf_sect_t ctfsect, symsect, strsect;
  13879. ctf_sect_t * symsectp = NULL;
  13880. ctf_sect_t * strsectp = NULL;
  13881. ctf_archive_t * ctfa = NULL;
  13882. ctf_dict_t * parent = NULL;
  13883. ctf_dict_t * fp;
  13884. ctf_next_t *i = NULL;
  13885. const char *name;
  13886. size_t member = 0;
  13887. int err;
  13888. bool ret = false;
  13889. shdr_to_ctf_sect (&ctfsect, section, filedata);
  13890. data = get_section_contents (section, filedata);
  13891. ctfsect.cts_data = data;
  13892. if (!dump_ctf_symtab_name)
  13893. dump_ctf_symtab_name = strdup (".dynsym");
  13894. if (!dump_ctf_strtab_name)
  13895. dump_ctf_strtab_name = strdup (".dynstr");
  13896. if (dump_ctf_symtab_name && dump_ctf_symtab_name[0] != 0)
  13897. {
  13898. if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL)
  13899. {
  13900. error (_("No symbol section named %s\n"), dump_ctf_symtab_name);
  13901. goto fail;
  13902. }
  13903. if ((symdata = (void *) get_data (NULL, filedata,
  13904. symtab_sec->sh_offset, 1,
  13905. symtab_sec->sh_size,
  13906. _("symbols"))) == NULL)
  13907. goto fail;
  13908. symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata);
  13909. symsect.cts_data = symdata;
  13910. }
  13911. if (dump_ctf_strtab_name && dump_ctf_strtab_name[0] != 0)
  13912. {
  13913. if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL)
  13914. {
  13915. error (_("No string table section named %s\n"),
  13916. dump_ctf_strtab_name);
  13917. goto fail;
  13918. }
  13919. if ((strdata = (void *) get_data (NULL, filedata,
  13920. strtab_sec->sh_offset, 1,
  13921. strtab_sec->sh_size,
  13922. _("strings"))) == NULL)
  13923. goto fail;
  13924. strsectp = shdr_to_ctf_sect (&strsect, strtab_sec, filedata);
  13925. strsect.cts_data = strdata;
  13926. }
  13927. /* Load the CTF file and dump it. It may be a raw CTF section, or an archive:
  13928. libctf papers over the difference, so we can pretend it is always an
  13929. archive. */
  13930. if ((ctfa = ctf_arc_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL)
  13931. {
  13932. dump_ctf_errs (NULL);
  13933. error (_("CTF open failure: %s\n"), ctf_errmsg (err));
  13934. goto fail;
  13935. }
  13936. ctf_arc_symsect_endianness (ctfa, filedata->file_header.e_ident[EI_DATA]
  13937. != ELFDATA2MSB);
  13938. /* Preload the parent dict, since it will need to be imported into every
  13939. child in turn. */
  13940. if ((parent = ctf_dict_open (ctfa, dump_ctf_parent_name, &err)) == NULL)
  13941. {
  13942. dump_ctf_errs (NULL);
  13943. error (_("CTF open failure: %s\n"), ctf_errmsg (err));
  13944. goto fail;
  13945. }
  13946. ret = true;
  13947. if (filedata->is_separate)
  13948. printf (_("\nDump of CTF section '%s' in linked file %s:\n"),
  13949. printable_section_name (filedata, section),
  13950. filedata->file_name);
  13951. else
  13952. printf (_("\nDump of CTF section '%s':\n"),
  13953. printable_section_name (filedata, section));
  13954. while ((fp = ctf_archive_next (ctfa, &i, &name, 0, &err)) != NULL)
  13955. dump_ctf_archive_member (fp, name, parent, member++);
  13956. if (err != ECTF_NEXT_END)
  13957. {
  13958. dump_ctf_errs (NULL);
  13959. error (_("CTF member open failure: %s\n"), ctf_errmsg (err));
  13960. ret = false;
  13961. }
  13962. fail:
  13963. ctf_dict_close (parent);
  13964. ctf_close (ctfa);
  13965. free (data);
  13966. free (symdata);
  13967. free (strdata);
  13968. return ret;
  13969. }
  13970. #endif
  13971. static bool
  13972. load_specific_debug_section (enum dwarf_section_display_enum debug,
  13973. const Elf_Internal_Shdr * sec,
  13974. void * data)
  13975. {
  13976. struct dwarf_section * section = &debug_displays [debug].section;
  13977. char buf [64];
  13978. Filedata * filedata = (Filedata *) data;
  13979. if (section->start != NULL)
  13980. {
  13981. /* If it is already loaded, do nothing. */
  13982. if (streq (section->filename, filedata->file_name))
  13983. return true;
  13984. free (section->start);
  13985. }
  13986. snprintf (buf, sizeof (buf), _("%s section data"), section->name);
  13987. section->address = sec->sh_addr;
  13988. section->filename = filedata->file_name;
  13989. section->start = (unsigned char *) get_data (NULL, filedata,
  13990. sec->sh_offset, 1,
  13991. sec->sh_size, buf);
  13992. if (section->start == NULL)
  13993. section->size = 0;
  13994. else
  13995. {
  13996. unsigned char *start = section->start;
  13997. dwarf_size_type size = sec->sh_size;
  13998. dwarf_size_type uncompressed_size = 0;
  13999. if ((sec->sh_flags & SHF_COMPRESSED) != 0)
  14000. {
  14001. Elf_Internal_Chdr chdr;
  14002. unsigned int compression_header_size;
  14003. if (size < (is_32bit_elf
  14004. ? sizeof (Elf32_External_Chdr)
  14005. : sizeof (Elf64_External_Chdr)))
  14006. {
  14007. warn (_("compressed section %s is too small to contain a compression header\n"),
  14008. section->name);
  14009. return false;
  14010. }
  14011. compression_header_size = get_compression_header (&chdr, start, size);
  14012. if (compression_header_size == 0)
  14013. /* An error message will have already been generated
  14014. by get_compression_header. */
  14015. return false;
  14016. if (chdr.ch_type != ELFCOMPRESS_ZLIB)
  14017. {
  14018. warn (_("section '%s' has unsupported compress type: %d\n"),
  14019. section->name, chdr.ch_type);
  14020. return false;
  14021. }
  14022. uncompressed_size = chdr.ch_size;
  14023. start += compression_header_size;
  14024. size -= compression_header_size;
  14025. }
  14026. else if (size > 12 && streq ((char *) start, "ZLIB"))
  14027. {
  14028. /* Read the zlib header. In this case, it should be "ZLIB"
  14029. followed by the uncompressed section size, 8 bytes in
  14030. big-endian order. */
  14031. uncompressed_size = start[4]; uncompressed_size <<= 8;
  14032. uncompressed_size += start[5]; uncompressed_size <<= 8;
  14033. uncompressed_size += start[6]; uncompressed_size <<= 8;
  14034. uncompressed_size += start[7]; uncompressed_size <<= 8;
  14035. uncompressed_size += start[8]; uncompressed_size <<= 8;
  14036. uncompressed_size += start[9]; uncompressed_size <<= 8;
  14037. uncompressed_size += start[10]; uncompressed_size <<= 8;
  14038. uncompressed_size += start[11];
  14039. start += 12;
  14040. size -= 12;
  14041. }
  14042. if (uncompressed_size)
  14043. {
  14044. if (uncompress_section_contents (&start, uncompressed_size,
  14045. &size))
  14046. {
  14047. /* Free the compressed buffer, update the section buffer
  14048. and the section size if uncompress is successful. */
  14049. free (section->start);
  14050. section->start = start;
  14051. }
  14052. else
  14053. {
  14054. error (_("Unable to decompress section %s\n"),
  14055. printable_section_name (filedata, sec));
  14056. return false;
  14057. }
  14058. }
  14059. section->size = size;
  14060. }
  14061. if (section->start == NULL)
  14062. return false;
  14063. if (debug_displays [debug].relocate)
  14064. {
  14065. if (! apply_relocations (filedata, sec, section->start, section->size,
  14066. & section->reloc_info, & section->num_relocs))
  14067. return false;
  14068. }
  14069. else
  14070. {
  14071. section->reloc_info = NULL;
  14072. section->num_relocs = 0;
  14073. }
  14074. return true;
  14075. }
  14076. #if HAVE_LIBDEBUGINFOD
  14077. /* Return a hex string representation of the build-id. */
  14078. unsigned char *
  14079. get_build_id (void * data)
  14080. {
  14081. Filedata * filedata = (Filedata *) data;
  14082. Elf_Internal_Shdr * shdr;
  14083. unsigned long i;
  14084. /* Iterate through notes to find note.gnu.build-id.
  14085. FIXME: Only the first note in any note section is examined. */
  14086. for (i = 0, shdr = filedata->section_headers;
  14087. i < filedata->file_header.e_shnum && shdr != NULL;
  14088. i++, shdr++)
  14089. {
  14090. if (shdr->sh_type != SHT_NOTE)
  14091. continue;
  14092. char * next;
  14093. char * end;
  14094. size_t data_remaining;
  14095. size_t min_notesz;
  14096. Elf_External_Note * enote;
  14097. Elf_Internal_Note inote;
  14098. bfd_vma offset = shdr->sh_offset;
  14099. bfd_vma align = shdr->sh_addralign;
  14100. bfd_vma length = shdr->sh_size;
  14101. enote = (Elf_External_Note *) get_section_contents (shdr, filedata);
  14102. if (enote == NULL)
  14103. continue;
  14104. if (align < 4)
  14105. align = 4;
  14106. else if (align != 4 && align != 8)
  14107. {
  14108. free (enote);
  14109. continue;
  14110. }
  14111. end = (char *) enote + length;
  14112. data_remaining = end - (char *) enote;
  14113. if (!is_ia64_vms (filedata))
  14114. {
  14115. min_notesz = offsetof (Elf_External_Note, name);
  14116. if (data_remaining < min_notesz)
  14117. {
  14118. warn (_("\
  14119. malformed note encountered in section %s whilst scanning for build-id note\n"),
  14120. printable_section_name (filedata, shdr));
  14121. free (enote);
  14122. continue;
  14123. }
  14124. data_remaining -= min_notesz;
  14125. inote.type = BYTE_GET (enote->type);
  14126. inote.namesz = BYTE_GET (enote->namesz);
  14127. inote.namedata = enote->name;
  14128. inote.descsz = BYTE_GET (enote->descsz);
  14129. inote.descdata = ((char *) enote
  14130. + ELF_NOTE_DESC_OFFSET (inote.namesz, align));
  14131. inote.descpos = offset + (inote.descdata - (char *) enote);
  14132. next = ((char *) enote
  14133. + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align));
  14134. }
  14135. else
  14136. {
  14137. Elf64_External_VMS_Note *vms_enote;
  14138. /* PR binutils/15191
  14139. Make sure that there is enough data to read. */
  14140. min_notesz = offsetof (Elf64_External_VMS_Note, name);
  14141. if (data_remaining < min_notesz)
  14142. {
  14143. warn (_("\
  14144. malformed note encountered in section %s whilst scanning for build-id note\n"),
  14145. printable_section_name (filedata, shdr));
  14146. free (enote);
  14147. continue;
  14148. }
  14149. data_remaining -= min_notesz;
  14150. vms_enote = (Elf64_External_VMS_Note *) enote;
  14151. inote.type = BYTE_GET (vms_enote->type);
  14152. inote.namesz = BYTE_GET (vms_enote->namesz);
  14153. inote.namedata = vms_enote->name;
  14154. inote.descsz = BYTE_GET (vms_enote->descsz);
  14155. inote.descdata = inote.namedata + align_power (inote.namesz, 3);
  14156. inote.descpos = offset + (inote.descdata - (char *) enote);
  14157. next = inote.descdata + align_power (inote.descsz, 3);
  14158. }
  14159. /* Skip malformed notes. */
  14160. if ((size_t) (inote.descdata - inote.namedata) < inote.namesz
  14161. || (size_t) (inote.descdata - inote.namedata) > data_remaining
  14162. || (size_t) (next - inote.descdata) < inote.descsz
  14163. || ((size_t) (next - inote.descdata)
  14164. > data_remaining - (size_t) (inote.descdata - inote.namedata)))
  14165. {
  14166. warn (_("\
  14167. malformed note encountered in section %s whilst scanning for build-id note\n"),
  14168. printable_section_name (filedata, shdr));
  14169. free (enote);
  14170. continue;
  14171. }
  14172. /* Check if this is the build-id note. If so then convert the build-id
  14173. bytes to a hex string. */
  14174. if (inote.namesz > 0
  14175. && startswith (inote.namedata, "GNU")
  14176. && inote.type == NT_GNU_BUILD_ID)
  14177. {
  14178. unsigned long j;
  14179. char * build_id;
  14180. build_id = malloc (inote.descsz * 2 + 1);
  14181. if (build_id == NULL)
  14182. {
  14183. free (enote);
  14184. return NULL;
  14185. }
  14186. for (j = 0; j < inote.descsz; ++j)
  14187. sprintf (build_id + (j * 2), "%02x", inote.descdata[j] & 0xff);
  14188. build_id[inote.descsz * 2] = '\0';
  14189. free (enote);
  14190. return (unsigned char *) build_id;
  14191. }
  14192. free (enote);
  14193. }
  14194. return NULL;
  14195. }
  14196. #endif /* HAVE_LIBDEBUGINFOD */
  14197. /* If this is not NULL, load_debug_section will only look for sections
  14198. within the list of sections given here. */
  14199. static unsigned int * section_subset = NULL;
  14200. bool
  14201. load_debug_section (enum dwarf_section_display_enum debug, void * data)
  14202. {
  14203. struct dwarf_section * section = &debug_displays [debug].section;
  14204. Elf_Internal_Shdr * sec;
  14205. Filedata * filedata = (Filedata *) data;
  14206. if (!dump_any_debugging)
  14207. return false;
  14208. /* Without section headers we cannot find any sections. */
  14209. if (filedata->section_headers == NULL)
  14210. return false;
  14211. if (filedata->string_table == NULL
  14212. && filedata->file_header.e_shstrndx != SHN_UNDEF
  14213. && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum)
  14214. {
  14215. Elf_Internal_Shdr * strs;
  14216. /* Read in the string table, so that we have section names to scan. */
  14217. strs = filedata->section_headers + filedata->file_header.e_shstrndx;
  14218. if (strs != NULL && strs->sh_size != 0)
  14219. {
  14220. filedata->string_table
  14221. = (char *) get_data (NULL, filedata, strs->sh_offset,
  14222. 1, strs->sh_size, _("string table"));
  14223. filedata->string_table_length
  14224. = filedata->string_table != NULL ? strs->sh_size : 0;
  14225. }
  14226. }
  14227. /* Locate the debug section. */
  14228. sec = find_section_in_set (filedata, section->uncompressed_name, section_subset);
  14229. if (sec != NULL)
  14230. section->name = section->uncompressed_name;
  14231. else
  14232. {
  14233. sec = find_section_in_set (filedata, section->compressed_name, section_subset);
  14234. if (sec != NULL)
  14235. section->name = section->compressed_name;
  14236. }
  14237. if (sec == NULL)
  14238. return false;
  14239. /* If we're loading from a subset of sections, and we've loaded
  14240. a section matching this name before, it's likely that it's a
  14241. different one. */
  14242. if (section_subset != NULL)
  14243. free_debug_section (debug);
  14244. return load_specific_debug_section (debug, sec, data);
  14245. }
  14246. void
  14247. free_debug_section (enum dwarf_section_display_enum debug)
  14248. {
  14249. struct dwarf_section * section = &debug_displays [debug].section;
  14250. if (section->start == NULL)
  14251. return;
  14252. free ((char *) section->start);
  14253. section->start = NULL;
  14254. section->address = 0;
  14255. section->size = 0;
  14256. free (section->reloc_info);
  14257. section->reloc_info = NULL;
  14258. section->num_relocs = 0;
  14259. }
  14260. static bool
  14261. display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata)
  14262. {
  14263. const char *name = (section_name_valid (filedata, section)
  14264. ? section_name (filedata, section) : "");
  14265. const char *print_name = printable_section_name (filedata, section);
  14266. bfd_size_type length;
  14267. bool result = true;
  14268. int i;
  14269. length = section->sh_size;
  14270. if (length == 0)
  14271. {
  14272. printf (_("\nSection '%s' has no debugging data.\n"), print_name);
  14273. return true;
  14274. }
  14275. if (section->sh_type == SHT_NOBITS)
  14276. {
  14277. /* There is no point in dumping the contents of a debugging section
  14278. which has the NOBITS type - the bits in the file will be random.
  14279. This can happen when a file containing a .eh_frame section is
  14280. stripped with the --only-keep-debug command line option. */
  14281. printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
  14282. print_name);
  14283. return false;
  14284. }
  14285. if (startswith (name, ".gnu.linkonce.wi."))
  14286. name = ".debug_info";
  14287. /* See if we know how to display the contents of this section. */
  14288. for (i = 0; i < max; i++)
  14289. {
  14290. enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i;
  14291. struct dwarf_section_display * display = debug_displays + i;
  14292. struct dwarf_section * sec = & display->section;
  14293. if (streq (sec->uncompressed_name, name)
  14294. || (id == line && startswith (name, ".debug_line."))
  14295. || streq (sec->compressed_name, name))
  14296. {
  14297. bool secondary = (section != find_section (filedata, name));
  14298. if (secondary)
  14299. free_debug_section (id);
  14300. if (i == line && startswith (name, ".debug_line."))
  14301. sec->name = name;
  14302. else if (streq (sec->uncompressed_name, name))
  14303. sec->name = sec->uncompressed_name;
  14304. else
  14305. sec->name = sec->compressed_name;
  14306. if (load_specific_debug_section (id, section, filedata))
  14307. {
  14308. /* If this debug section is part of a CU/TU set in a .dwp file,
  14309. restrict load_debug_section to the sections in that set. */
  14310. section_subset = find_cu_tu_set (filedata, shndx);
  14311. result &= display->display (sec, filedata);
  14312. section_subset = NULL;
  14313. if (secondary || (id != info && id != abbrev && id != debug_addr))
  14314. free_debug_section (id);
  14315. }
  14316. break;
  14317. }
  14318. }
  14319. if (i == max)
  14320. {
  14321. printf (_("Unrecognized debug section: %s\n"), print_name);
  14322. result = false;
  14323. }
  14324. return result;
  14325. }
  14326. /* Set DUMP_SECTS for all sections where dumps were requested
  14327. based on section name. */
  14328. static void
  14329. initialise_dumps_byname (Filedata * filedata)
  14330. {
  14331. struct dump_list_entry * cur;
  14332. for (cur = dump_sects_byname; cur; cur = cur->next)
  14333. {
  14334. unsigned int i;
  14335. bool any = false;
  14336. for (i = 0; i < filedata->file_header.e_shnum; i++)
  14337. if (section_name_valid (filedata, filedata->section_headers + i)
  14338. && streq (section_name (filedata, filedata->section_headers + i),
  14339. cur->name))
  14340. {
  14341. request_dump_bynumber (&filedata->dump, i, cur->type);
  14342. any = true;
  14343. }
  14344. if (!any && !filedata->is_separate)
  14345. warn (_("Section '%s' was not dumped because it does not exist\n"),
  14346. cur->name);
  14347. }
  14348. }
  14349. static bool
  14350. process_section_contents (Filedata * filedata)
  14351. {
  14352. Elf_Internal_Shdr * section;
  14353. unsigned int i;
  14354. bool res = true;
  14355. if (! do_dump)
  14356. return true;
  14357. initialise_dumps_byname (filedata);
  14358. for (i = 0, section = filedata->section_headers;
  14359. i < filedata->file_header.e_shnum && i < filedata->dump.num_dump_sects;
  14360. i++, section++)
  14361. {
  14362. dump_type dump = filedata->dump.dump_sects[i];
  14363. if (filedata->is_separate && ! process_links)
  14364. dump &= DEBUG_DUMP;
  14365. #ifdef SUPPORT_DISASSEMBLY
  14366. if (dump & DISASS_DUMP)
  14367. {
  14368. if (! disassemble_section (section, filedata))
  14369. res = false;
  14370. }
  14371. #endif
  14372. if (dump & HEX_DUMP)
  14373. {
  14374. if (! dump_section_as_bytes (section, filedata, false))
  14375. res = false;
  14376. }
  14377. if (dump & RELOC_DUMP)
  14378. {
  14379. if (! dump_section_as_bytes (section, filedata, true))
  14380. res = false;
  14381. }
  14382. if (dump & STRING_DUMP)
  14383. {
  14384. if (! dump_section_as_strings (section, filedata))
  14385. res = false;
  14386. }
  14387. if (dump & DEBUG_DUMP)
  14388. {
  14389. if (! display_debug_section (i, section, filedata))
  14390. res = false;
  14391. }
  14392. #ifdef ENABLE_LIBCTF
  14393. if (dump & CTF_DUMP)
  14394. {
  14395. if (! dump_section_as_ctf (section, filedata))
  14396. res = false;
  14397. }
  14398. #endif
  14399. }
  14400. if (! filedata->is_separate)
  14401. {
  14402. /* Check to see if the user requested a
  14403. dump of a section that does not exist. */
  14404. for (; i < filedata->dump.num_dump_sects; i++)
  14405. if (filedata->dump.dump_sects[i])
  14406. {
  14407. warn (_("Section %d was not dumped because it does not exist!\n"), i);
  14408. res = false;
  14409. }
  14410. }
  14411. return res;
  14412. }
  14413. static void
  14414. process_mips_fpe_exception (int mask)
  14415. {
  14416. if (mask)
  14417. {
  14418. bool first = true;
  14419. if (mask & OEX_FPU_INEX)
  14420. fputs ("INEX", stdout), first = false;
  14421. if (mask & OEX_FPU_UFLO)
  14422. printf ("%sUFLO", first ? "" : "|"), first = false;
  14423. if (mask & OEX_FPU_OFLO)
  14424. printf ("%sOFLO", first ? "" : "|"), first = false;
  14425. if (mask & OEX_FPU_DIV0)
  14426. printf ("%sDIV0", first ? "" : "|"), first = false;
  14427. if (mask & OEX_FPU_INVAL)
  14428. printf ("%sINVAL", first ? "" : "|");
  14429. }
  14430. else
  14431. fputs ("0", stdout);
  14432. }
  14433. /* Display's the value of TAG at location P. If TAG is
  14434. greater than 0 it is assumed to be an unknown tag, and
  14435. a message is printed to this effect. Otherwise it is
  14436. assumed that a message has already been printed.
  14437. If the bottom bit of TAG is set it assumed to have a
  14438. string value, otherwise it is assumed to have an integer
  14439. value.
  14440. Returns an updated P pointing to the first unread byte
  14441. beyond the end of TAG's value.
  14442. Reads at or beyond END will not be made. */
  14443. static unsigned char *
  14444. display_tag_value (signed int tag,
  14445. unsigned char * p,
  14446. const unsigned char * const end)
  14447. {
  14448. unsigned long val;
  14449. if (tag > 0)
  14450. printf (" Tag_unknown_%d: ", tag);
  14451. if (p >= end)
  14452. {
  14453. warn (_("<corrupt tag>\n"));
  14454. }
  14455. else if (tag & 1)
  14456. {
  14457. /* PR 17531 file: 027-19978-0.004. */
  14458. size_t maxlen = (end - p) - 1;
  14459. putchar ('"');
  14460. if (maxlen > 0)
  14461. {
  14462. print_symbol ((int) maxlen, (const char *) p);
  14463. p += strnlen ((char *) p, maxlen) + 1;
  14464. }
  14465. else
  14466. {
  14467. printf (_("<corrupt string tag>"));
  14468. p = (unsigned char *) end;
  14469. }
  14470. printf ("\"\n");
  14471. }
  14472. else
  14473. {
  14474. READ_ULEB (val, p, end);
  14475. printf ("%ld (0x%lx)\n", val, val);
  14476. }
  14477. assert (p <= end);
  14478. return p;
  14479. }
  14480. /* ARC ABI attributes section. */
  14481. static unsigned char *
  14482. display_arc_attribute (unsigned char * p,
  14483. const unsigned char * const end)
  14484. {
  14485. unsigned int tag;
  14486. unsigned int val;
  14487. READ_ULEB (tag, p, end);
  14488. switch (tag)
  14489. {
  14490. case Tag_ARC_PCS_config:
  14491. READ_ULEB (val, p, end);
  14492. printf (" Tag_ARC_PCS_config: ");
  14493. switch (val)
  14494. {
  14495. case 0:
  14496. printf (_("Absent/Non standard\n"));
  14497. break;
  14498. case 1:
  14499. printf (_("Bare metal/mwdt\n"));
  14500. break;
  14501. case 2:
  14502. printf (_("Bare metal/newlib\n"));
  14503. break;
  14504. case 3:
  14505. printf (_("Linux/uclibc\n"));
  14506. break;
  14507. case 4:
  14508. printf (_("Linux/glibc\n"));
  14509. break;
  14510. default:
  14511. printf (_("Unknown\n"));
  14512. break;
  14513. }
  14514. break;
  14515. case Tag_ARC_CPU_base:
  14516. READ_ULEB (val, p, end);
  14517. printf (" Tag_ARC_CPU_base: ");
  14518. switch (val)
  14519. {
  14520. default:
  14521. case TAG_CPU_NONE:
  14522. printf (_("Absent\n"));
  14523. break;
  14524. case TAG_CPU_ARC6xx:
  14525. printf ("ARC6xx\n");
  14526. break;
  14527. case TAG_CPU_ARC7xx:
  14528. printf ("ARC7xx\n");
  14529. break;
  14530. case TAG_CPU_ARCEM:
  14531. printf ("ARCEM\n");
  14532. break;
  14533. case TAG_CPU_ARCHS:
  14534. printf ("ARCHS\n");
  14535. break;
  14536. }
  14537. break;
  14538. case Tag_ARC_CPU_variation:
  14539. READ_ULEB (val, p, end);
  14540. printf (" Tag_ARC_CPU_variation: ");
  14541. switch (val)
  14542. {
  14543. default:
  14544. if (val > 0 && val < 16)
  14545. printf ("Core%d\n", val);
  14546. else
  14547. printf ("Unknown\n");
  14548. break;
  14549. case 0:
  14550. printf (_("Absent\n"));
  14551. break;
  14552. }
  14553. break;
  14554. case Tag_ARC_CPU_name:
  14555. printf (" Tag_ARC_CPU_name: ");
  14556. p = display_tag_value (-1, p, end);
  14557. break;
  14558. case Tag_ARC_ABI_rf16:
  14559. READ_ULEB (val, p, end);
  14560. printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no"));
  14561. break;
  14562. case Tag_ARC_ABI_osver:
  14563. READ_ULEB (val, p, end);
  14564. printf (" Tag_ARC_ABI_osver: v%d\n", val);
  14565. break;
  14566. case Tag_ARC_ABI_pic:
  14567. case Tag_ARC_ABI_sda:
  14568. READ_ULEB (val, p, end);
  14569. printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: "
  14570. : " Tag_ARC_ABI_pic: ");
  14571. switch (val)
  14572. {
  14573. case 0:
  14574. printf (_("Absent\n"));
  14575. break;
  14576. case 1:
  14577. printf ("MWDT\n");
  14578. break;
  14579. case 2:
  14580. printf ("GNU\n");
  14581. break;
  14582. default:
  14583. printf (_("Unknown\n"));
  14584. break;
  14585. }
  14586. break;
  14587. case Tag_ARC_ABI_tls:
  14588. READ_ULEB (val, p, end);
  14589. printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none");
  14590. break;
  14591. case Tag_ARC_ABI_enumsize:
  14592. READ_ULEB (val, p, end);
  14593. printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") :
  14594. _("smallest"));
  14595. break;
  14596. case Tag_ARC_ABI_exceptions:
  14597. READ_ULEB (val, p, end);
  14598. printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP")
  14599. : _("default"));
  14600. break;
  14601. case Tag_ARC_ABI_double_size:
  14602. READ_ULEB (val, p, end);
  14603. printf (" Tag_ARC_ABI_double_size: %d\n", val);
  14604. break;
  14605. case Tag_ARC_ISA_config:
  14606. printf (" Tag_ARC_ISA_config: ");
  14607. p = display_tag_value (-1, p, end);
  14608. break;
  14609. case Tag_ARC_ISA_apex:
  14610. printf (" Tag_ARC_ISA_apex: ");
  14611. p = display_tag_value (-1, p, end);
  14612. break;
  14613. case Tag_ARC_ISA_mpy_option:
  14614. READ_ULEB (val, p, end);
  14615. printf (" Tag_ARC_ISA_mpy_option: %d\n", val);
  14616. break;
  14617. case Tag_ARC_ATR_version:
  14618. READ_ULEB (val, p, end);
  14619. printf (" Tag_ARC_ATR_version: %d\n", val);
  14620. break;
  14621. default:
  14622. return display_tag_value (tag & 1, p, end);
  14623. }
  14624. return p;
  14625. }
  14626. /* ARM EABI attributes section. */
  14627. typedef struct
  14628. {
  14629. unsigned int tag;
  14630. const char * name;
  14631. /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
  14632. unsigned int type;
  14633. const char *const *table;
  14634. } arm_attr_public_tag;
  14635. static const char *const arm_attr_tag_CPU_arch[] =
  14636. {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
  14637. "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
  14638. "v8-M.mainline", "v8.1-A", "v8.2-A", "v8.3-A",
  14639. "v8.1-M.mainline", "v9"};
  14640. static const char *const arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
  14641. static const char *const arm_attr_tag_THUMB_ISA_use[] =
  14642. {"No", "Thumb-1", "Thumb-2", "Yes"};
  14643. static const char *const arm_attr_tag_FP_arch[] =
  14644. {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
  14645. "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
  14646. static const char *const arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
  14647. static const char *const arm_attr_tag_Advanced_SIMD_arch[] =
  14648. {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
  14649. "NEON for ARMv8.1"};
  14650. static const char *const arm_attr_tag_PCS_config[] =
  14651. {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
  14652. "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
  14653. static const char *const arm_attr_tag_ABI_PCS_R9_use[] =
  14654. {"V6", "SB", "TLS", "Unused"};
  14655. static const char *const arm_attr_tag_ABI_PCS_RW_data[] =
  14656. {"Absolute", "PC-relative", "SB-relative", "None"};
  14657. static const char *const arm_attr_tag_ABI_PCS_RO_data[] =
  14658. {"Absolute", "PC-relative", "None"};
  14659. static const char *const arm_attr_tag_ABI_PCS_GOT_use[] =
  14660. {"None", "direct", "GOT-indirect"};
  14661. static const char *const arm_attr_tag_ABI_PCS_wchar_t[] =
  14662. {"None", "??? 1", "2", "??? 3", "4"};
  14663. static const char *const arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
  14664. static const char *const arm_attr_tag_ABI_FP_denormal[] =
  14665. {"Unused", "Needed", "Sign only"};
  14666. static const char *const arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
  14667. static const char *const arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
  14668. static const char *const arm_attr_tag_ABI_FP_number_model[] =
  14669. {"Unused", "Finite", "RTABI", "IEEE 754"};
  14670. static const char *const arm_attr_tag_ABI_enum_size[] =
  14671. {"Unused", "small", "int", "forced to int"};
  14672. static const char *const arm_attr_tag_ABI_HardFP_use[] =
  14673. {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
  14674. static const char *const arm_attr_tag_ABI_VFP_args[] =
  14675. {"AAPCS", "VFP registers", "custom", "compatible"};
  14676. static const char *const arm_attr_tag_ABI_WMMX_args[] =
  14677. {"AAPCS", "WMMX registers", "custom"};
  14678. static const char *const arm_attr_tag_ABI_optimization_goals[] =
  14679. {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
  14680. "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
  14681. static const char *const arm_attr_tag_ABI_FP_optimization_goals[] =
  14682. {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
  14683. "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
  14684. static const char *const arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
  14685. static const char *const arm_attr_tag_FP_HP_extension[] =
  14686. {"Not Allowed", "Allowed"};
  14687. static const char *const arm_attr_tag_ABI_FP_16bit_format[] =
  14688. {"None", "IEEE 754", "Alternative Format"};
  14689. static const char *const arm_attr_tag_DSP_extension[] =
  14690. {"Follow architecture", "Allowed"};
  14691. static const char *const arm_attr_tag_MPextension_use[] =
  14692. {"Not Allowed", "Allowed"};
  14693. static const char *const arm_attr_tag_DIV_use[] =
  14694. {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
  14695. "Allowed in v7-A with integer division extension"};
  14696. static const char *const arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
  14697. static const char *const arm_attr_tag_Virtualization_use[] =
  14698. {"Not Allowed", "TrustZone", "Virtualization Extensions",
  14699. "TrustZone and Virtualization Extensions"};
  14700. static const char *const arm_attr_tag_MPextension_use_legacy[] =
  14701. {"Not Allowed", "Allowed"};
  14702. static const char *const arm_attr_tag_MVE_arch[] =
  14703. {"No MVE", "MVE Integer only", "MVE Integer and FP"};
  14704. static const char * arm_attr_tag_PAC_extension[] =
  14705. {"No PAC/AUT instructions",
  14706. "PAC/AUT instructions permitted in the NOP space",
  14707. "PAC/AUT instructions permitted in the NOP and in the non-NOP space"};
  14708. static const char * arm_attr_tag_BTI_extension[] =
  14709. {"BTI instructions not permitted",
  14710. "BTI instructions permitted in the NOP space",
  14711. "BTI instructions permitted in the NOP and in the non-NOP space"};
  14712. static const char * arm_attr_tag_BTI_use[] =
  14713. {"Compiled without branch target enforcement",
  14714. "Compiled with branch target enforcement"};
  14715. static const char * arm_attr_tag_PACRET_use[] =
  14716. {"Compiled without return address signing and authentication",
  14717. "Compiled with return address signing and authentication"};
  14718. #define LOOKUP(id, name) \
  14719. {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
  14720. static arm_attr_public_tag arm_attr_public_tags[] =
  14721. {
  14722. {4, "CPU_raw_name", 1, NULL},
  14723. {5, "CPU_name", 1, NULL},
  14724. LOOKUP(6, CPU_arch),
  14725. {7, "CPU_arch_profile", 0, NULL},
  14726. LOOKUP(8, ARM_ISA_use),
  14727. LOOKUP(9, THUMB_ISA_use),
  14728. LOOKUP(10, FP_arch),
  14729. LOOKUP(11, WMMX_arch),
  14730. LOOKUP(12, Advanced_SIMD_arch),
  14731. LOOKUP(13, PCS_config),
  14732. LOOKUP(14, ABI_PCS_R9_use),
  14733. LOOKUP(15, ABI_PCS_RW_data),
  14734. LOOKUP(16, ABI_PCS_RO_data),
  14735. LOOKUP(17, ABI_PCS_GOT_use),
  14736. LOOKUP(18, ABI_PCS_wchar_t),
  14737. LOOKUP(19, ABI_FP_rounding),
  14738. LOOKUP(20, ABI_FP_denormal),
  14739. LOOKUP(21, ABI_FP_exceptions),
  14740. LOOKUP(22, ABI_FP_user_exceptions),
  14741. LOOKUP(23, ABI_FP_number_model),
  14742. {24, "ABI_align_needed", 0, NULL},
  14743. {25, "ABI_align_preserved", 0, NULL},
  14744. LOOKUP(26, ABI_enum_size),
  14745. LOOKUP(27, ABI_HardFP_use),
  14746. LOOKUP(28, ABI_VFP_args),
  14747. LOOKUP(29, ABI_WMMX_args),
  14748. LOOKUP(30, ABI_optimization_goals),
  14749. LOOKUP(31, ABI_FP_optimization_goals),
  14750. {32, "compatibility", 0, NULL},
  14751. LOOKUP(34, CPU_unaligned_access),
  14752. LOOKUP(36, FP_HP_extension),
  14753. LOOKUP(38, ABI_FP_16bit_format),
  14754. LOOKUP(42, MPextension_use),
  14755. LOOKUP(44, DIV_use),
  14756. LOOKUP(46, DSP_extension),
  14757. LOOKUP(48, MVE_arch),
  14758. LOOKUP(50, PAC_extension),
  14759. LOOKUP(52, BTI_extension),
  14760. LOOKUP(74, BTI_use),
  14761. LOOKUP(76, PACRET_use),
  14762. {64, "nodefaults", 0, NULL},
  14763. {65, "also_compatible_with", 0, NULL},
  14764. LOOKUP(66, T2EE_use),
  14765. {67, "conformance", 1, NULL},
  14766. LOOKUP(68, Virtualization_use),
  14767. LOOKUP(70, MPextension_use_legacy)
  14768. };
  14769. #undef LOOKUP
  14770. static unsigned char *
  14771. display_arm_attribute (unsigned char * p,
  14772. const unsigned char * const end)
  14773. {
  14774. unsigned int tag;
  14775. unsigned int val;
  14776. arm_attr_public_tag * attr;
  14777. unsigned i;
  14778. unsigned int type;
  14779. READ_ULEB (tag, p, end);
  14780. attr = NULL;
  14781. for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
  14782. {
  14783. if (arm_attr_public_tags[i].tag == tag)
  14784. {
  14785. attr = &arm_attr_public_tags[i];
  14786. break;
  14787. }
  14788. }
  14789. if (attr)
  14790. {
  14791. printf (" Tag_%s: ", attr->name);
  14792. switch (attr->type)
  14793. {
  14794. case 0:
  14795. switch (tag)
  14796. {
  14797. case 7: /* Tag_CPU_arch_profile. */
  14798. READ_ULEB (val, p, end);
  14799. switch (val)
  14800. {
  14801. case 0: printf (_("None\n")); break;
  14802. case 'A': printf (_("Application\n")); break;
  14803. case 'R': printf (_("Realtime\n")); break;
  14804. case 'M': printf (_("Microcontroller\n")); break;
  14805. case 'S': printf (_("Application or Realtime\n")); break;
  14806. default: printf ("??? (%d)\n", val); break;
  14807. }
  14808. break;
  14809. case 24: /* Tag_align_needed. */
  14810. READ_ULEB (val, p, end);
  14811. switch (val)
  14812. {
  14813. case 0: printf (_("None\n")); break;
  14814. case 1: printf (_("8-byte\n")); break;
  14815. case 2: printf (_("4-byte\n")); break;
  14816. case 3: printf ("??? 3\n"); break;
  14817. default:
  14818. if (val <= 12)
  14819. printf (_("8-byte and up to %d-byte extended\n"),
  14820. 1 << val);
  14821. else
  14822. printf ("??? (%d)\n", val);
  14823. break;
  14824. }
  14825. break;
  14826. case 25: /* Tag_align_preserved. */
  14827. READ_ULEB (val, p, end);
  14828. switch (val)
  14829. {
  14830. case 0: printf (_("None\n")); break;
  14831. case 1: printf (_("8-byte, except leaf SP\n")); break;
  14832. case 2: printf (_("8-byte\n")); break;
  14833. case 3: printf ("??? 3\n"); break;
  14834. default:
  14835. if (val <= 12)
  14836. printf (_("8-byte and up to %d-byte extended\n"),
  14837. 1 << val);
  14838. else
  14839. printf ("??? (%d)\n", val);
  14840. break;
  14841. }
  14842. break;
  14843. case 32: /* Tag_compatibility. */
  14844. {
  14845. READ_ULEB (val, p, end);
  14846. printf (_("flag = %d, vendor = "), val);
  14847. if (p < end - 1)
  14848. {
  14849. size_t maxlen = (end - p) - 1;
  14850. print_symbol ((int) maxlen, (const char *) p);
  14851. p += strnlen ((char *) p, maxlen) + 1;
  14852. }
  14853. else
  14854. {
  14855. printf (_("<corrupt>"));
  14856. p = (unsigned char *) end;
  14857. }
  14858. putchar ('\n');
  14859. }
  14860. break;
  14861. case 64: /* Tag_nodefaults. */
  14862. /* PR 17531: file: 001-505008-0.01. */
  14863. if (p < end)
  14864. p++;
  14865. printf (_("True\n"));
  14866. break;
  14867. case 65: /* Tag_also_compatible_with. */
  14868. READ_ULEB (val, p, end);
  14869. if (val == 6 /* Tag_CPU_arch. */)
  14870. {
  14871. READ_ULEB (val, p, end);
  14872. if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
  14873. printf ("??? (%d)\n", val);
  14874. else
  14875. printf ("%s\n", arm_attr_tag_CPU_arch[val]);
  14876. }
  14877. else
  14878. printf ("???\n");
  14879. while (p < end && *(p++) != '\0' /* NUL terminator. */)
  14880. ;
  14881. break;
  14882. default:
  14883. printf (_("<unknown: %d>\n"), tag);
  14884. break;
  14885. }
  14886. return p;
  14887. case 1:
  14888. return display_tag_value (-1, p, end);
  14889. case 2:
  14890. return display_tag_value (0, p, end);
  14891. default:
  14892. assert (attr->type & 0x80);
  14893. READ_ULEB (val, p, end);
  14894. type = attr->type & 0x7f;
  14895. if (val >= type)
  14896. printf ("??? (%d)\n", val);
  14897. else
  14898. printf ("%s\n", attr->table[val]);
  14899. return p;
  14900. }
  14901. }
  14902. return display_tag_value (tag, p, end);
  14903. }
  14904. static unsigned char *
  14905. display_gnu_attribute (unsigned char * p,
  14906. unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const),
  14907. const unsigned char * const end)
  14908. {
  14909. unsigned int tag;
  14910. unsigned int val;
  14911. READ_ULEB (tag, p, end);
  14912. /* Tag_compatibility is the only generic GNU attribute defined at
  14913. present. */
  14914. if (tag == 32)
  14915. {
  14916. READ_ULEB (val, p, end);
  14917. printf (_("flag = %d, vendor = "), val);
  14918. if (p == end)
  14919. {
  14920. printf (_("<corrupt>\n"));
  14921. warn (_("corrupt vendor attribute\n"));
  14922. }
  14923. else
  14924. {
  14925. if (p < end - 1)
  14926. {
  14927. size_t maxlen = (end - p) - 1;
  14928. print_symbol ((int) maxlen, (const char *) p);
  14929. p += strnlen ((char *) p, maxlen) + 1;
  14930. }
  14931. else
  14932. {
  14933. printf (_("<corrupt>"));
  14934. p = (unsigned char *) end;
  14935. }
  14936. putchar ('\n');
  14937. }
  14938. return p;
  14939. }
  14940. if ((tag & 2) == 0 && display_proc_gnu_attribute)
  14941. return display_proc_gnu_attribute (p, tag, end);
  14942. return display_tag_value (tag, p, end);
  14943. }
  14944. static unsigned char *
  14945. display_m68k_gnu_attribute (unsigned char * p,
  14946. unsigned int tag,
  14947. const unsigned char * const end)
  14948. {
  14949. unsigned int val;
  14950. if (tag == Tag_GNU_M68K_ABI_FP)
  14951. {
  14952. printf (" Tag_GNU_M68K_ABI_FP: ");
  14953. if (p == end)
  14954. {
  14955. printf (_("<corrupt>\n"));
  14956. return p;
  14957. }
  14958. READ_ULEB (val, p, end);
  14959. if (val > 3)
  14960. printf ("(%#x), ", val);
  14961. switch (val & 3)
  14962. {
  14963. case 0:
  14964. printf (_("unspecified hard/soft float\n"));
  14965. break;
  14966. case 1:
  14967. printf (_("hard float\n"));
  14968. break;
  14969. case 2:
  14970. printf (_("soft float\n"));
  14971. break;
  14972. }
  14973. return p;
  14974. }
  14975. return display_tag_value (tag & 1, p, end);
  14976. }
  14977. static unsigned char *
  14978. display_power_gnu_attribute (unsigned char * p,
  14979. unsigned int tag,
  14980. const unsigned char * const end)
  14981. {
  14982. unsigned int val;
  14983. if (tag == Tag_GNU_Power_ABI_FP)
  14984. {
  14985. printf (" Tag_GNU_Power_ABI_FP: ");
  14986. if (p == end)
  14987. {
  14988. printf (_("<corrupt>\n"));
  14989. return p;
  14990. }
  14991. READ_ULEB (val, p, end);
  14992. if (val > 15)
  14993. printf ("(%#x), ", val);
  14994. switch (val & 3)
  14995. {
  14996. case 0:
  14997. printf (_("unspecified hard/soft float, "));
  14998. break;
  14999. case 1:
  15000. printf (_("hard float, "));
  15001. break;
  15002. case 2:
  15003. printf (_("soft float, "));
  15004. break;
  15005. case 3:
  15006. printf (_("single-precision hard float, "));
  15007. break;
  15008. }
  15009. switch (val & 0xC)
  15010. {
  15011. case 0:
  15012. printf (_("unspecified long double\n"));
  15013. break;
  15014. case 4:
  15015. printf (_("128-bit IBM long double\n"));
  15016. break;
  15017. case 8:
  15018. printf (_("64-bit long double\n"));
  15019. break;
  15020. case 12:
  15021. printf (_("128-bit IEEE long double\n"));
  15022. break;
  15023. }
  15024. return p;
  15025. }
  15026. if (tag == Tag_GNU_Power_ABI_Vector)
  15027. {
  15028. printf (" Tag_GNU_Power_ABI_Vector: ");
  15029. if (p == end)
  15030. {
  15031. printf (_("<corrupt>\n"));
  15032. return p;
  15033. }
  15034. READ_ULEB (val, p, end);
  15035. if (val > 3)
  15036. printf ("(%#x), ", val);
  15037. switch (val & 3)
  15038. {
  15039. case 0:
  15040. printf (_("unspecified\n"));
  15041. break;
  15042. case 1:
  15043. printf (_("generic\n"));
  15044. break;
  15045. case 2:
  15046. printf ("AltiVec\n");
  15047. break;
  15048. case 3:
  15049. printf ("SPE\n");
  15050. break;
  15051. }
  15052. return p;
  15053. }
  15054. if (tag == Tag_GNU_Power_ABI_Struct_Return)
  15055. {
  15056. printf (" Tag_GNU_Power_ABI_Struct_Return: ");
  15057. if (p == end)
  15058. {
  15059. printf (_("<corrupt>\n"));
  15060. return p;
  15061. }
  15062. READ_ULEB (val, p, end);
  15063. if (val > 2)
  15064. printf ("(%#x), ", val);
  15065. switch (val & 3)
  15066. {
  15067. case 0:
  15068. printf (_("unspecified\n"));
  15069. break;
  15070. case 1:
  15071. printf ("r3/r4\n");
  15072. break;
  15073. case 2:
  15074. printf (_("memory\n"));
  15075. break;
  15076. case 3:
  15077. printf ("???\n");
  15078. break;
  15079. }
  15080. return p;
  15081. }
  15082. return display_tag_value (tag & 1, p, end);
  15083. }
  15084. static unsigned char *
  15085. display_s390_gnu_attribute (unsigned char * p,
  15086. unsigned int tag,
  15087. const unsigned char * const end)
  15088. {
  15089. unsigned int val;
  15090. if (tag == Tag_GNU_S390_ABI_Vector)
  15091. {
  15092. printf (" Tag_GNU_S390_ABI_Vector: ");
  15093. READ_ULEB (val, p, end);
  15094. switch (val)
  15095. {
  15096. case 0:
  15097. printf (_("any\n"));
  15098. break;
  15099. case 1:
  15100. printf (_("software\n"));
  15101. break;
  15102. case 2:
  15103. printf (_("hardware\n"));
  15104. break;
  15105. default:
  15106. printf ("??? (%d)\n", val);
  15107. break;
  15108. }
  15109. return p;
  15110. }
  15111. return display_tag_value (tag & 1, p, end);
  15112. }
  15113. static void
  15114. display_sparc_hwcaps (unsigned int mask)
  15115. {
  15116. if (mask)
  15117. {
  15118. bool first = true;
  15119. if (mask & ELF_SPARC_HWCAP_MUL32)
  15120. fputs ("mul32", stdout), first = false;
  15121. if (mask & ELF_SPARC_HWCAP_DIV32)
  15122. printf ("%sdiv32", first ? "" : "|"), first = false;
  15123. if (mask & ELF_SPARC_HWCAP_FSMULD)
  15124. printf ("%sfsmuld", first ? "" : "|"), first = false;
  15125. if (mask & ELF_SPARC_HWCAP_V8PLUS)
  15126. printf ("%sv8plus", first ? "" : "|"), first = false;
  15127. if (mask & ELF_SPARC_HWCAP_POPC)
  15128. printf ("%spopc", first ? "" : "|"), first = false;
  15129. if (mask & ELF_SPARC_HWCAP_VIS)
  15130. printf ("%svis", first ? "" : "|"), first = false;
  15131. if (mask & ELF_SPARC_HWCAP_VIS2)
  15132. printf ("%svis2", first ? "" : "|"), first = false;
  15133. if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT)
  15134. printf ("%sASIBlkInit", first ? "" : "|"), first = false;
  15135. if (mask & ELF_SPARC_HWCAP_FMAF)
  15136. printf ("%sfmaf", first ? "" : "|"), first = false;
  15137. if (mask & ELF_SPARC_HWCAP_VIS3)
  15138. printf ("%svis3", first ? "" : "|"), first = false;
  15139. if (mask & ELF_SPARC_HWCAP_HPC)
  15140. printf ("%shpc", first ? "" : "|"), first = false;
  15141. if (mask & ELF_SPARC_HWCAP_RANDOM)
  15142. printf ("%srandom", first ? "" : "|"), first = false;
  15143. if (mask & ELF_SPARC_HWCAP_TRANS)
  15144. printf ("%strans", first ? "" : "|"), first = false;
  15145. if (mask & ELF_SPARC_HWCAP_FJFMAU)
  15146. printf ("%sfjfmau", first ? "" : "|"), first = false;
  15147. if (mask & ELF_SPARC_HWCAP_IMA)
  15148. printf ("%sima", first ? "" : "|"), first = false;
  15149. if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING)
  15150. printf ("%scspare", first ? "" : "|"), first = false;
  15151. }
  15152. else
  15153. fputc ('0', stdout);
  15154. fputc ('\n', stdout);
  15155. }
  15156. static void
  15157. display_sparc_hwcaps2 (unsigned int mask)
  15158. {
  15159. if (mask)
  15160. {
  15161. bool first = true;
  15162. if (mask & ELF_SPARC_HWCAP2_FJATHPLUS)
  15163. fputs ("fjathplus", stdout), first = false;
  15164. if (mask & ELF_SPARC_HWCAP2_VIS3B)
  15165. printf ("%svis3b", first ? "" : "|"), first = false;
  15166. if (mask & ELF_SPARC_HWCAP2_ADP)
  15167. printf ("%sadp", first ? "" : "|"), first = false;
  15168. if (mask & ELF_SPARC_HWCAP2_SPARC5)
  15169. printf ("%ssparc5", first ? "" : "|"), first = false;
  15170. if (mask & ELF_SPARC_HWCAP2_MWAIT)
  15171. printf ("%smwait", first ? "" : "|"), first = false;
  15172. if (mask & ELF_SPARC_HWCAP2_XMPMUL)
  15173. printf ("%sxmpmul", first ? "" : "|"), first = false;
  15174. if (mask & ELF_SPARC_HWCAP2_XMONT)
  15175. printf ("%sxmont2", first ? "" : "|"), first = false;
  15176. if (mask & ELF_SPARC_HWCAP2_NSEC)
  15177. printf ("%snsec", first ? "" : "|"), first = false;
  15178. if (mask & ELF_SPARC_HWCAP2_FJATHHPC)
  15179. printf ("%sfjathhpc", first ? "" : "|"), first = false;
  15180. if (mask & ELF_SPARC_HWCAP2_FJDES)
  15181. printf ("%sfjdes", first ? "" : "|"), first = false;
  15182. if (mask & ELF_SPARC_HWCAP2_FJAES)
  15183. printf ("%sfjaes", first ? "" : "|"), first = false;
  15184. }
  15185. else
  15186. fputc ('0', stdout);
  15187. fputc ('\n', stdout);
  15188. }
  15189. static unsigned char *
  15190. display_sparc_gnu_attribute (unsigned char * p,
  15191. unsigned int tag,
  15192. const unsigned char * const end)
  15193. {
  15194. unsigned int val;
  15195. if (tag == Tag_GNU_Sparc_HWCAPS)
  15196. {
  15197. READ_ULEB (val, p, end);
  15198. printf (" Tag_GNU_Sparc_HWCAPS: ");
  15199. display_sparc_hwcaps (val);
  15200. return p;
  15201. }
  15202. if (tag == Tag_GNU_Sparc_HWCAPS2)
  15203. {
  15204. READ_ULEB (val, p, end);
  15205. printf (" Tag_GNU_Sparc_HWCAPS2: ");
  15206. display_sparc_hwcaps2 (val);
  15207. return p;
  15208. }
  15209. return display_tag_value (tag, p, end);
  15210. }
  15211. static void
  15212. print_mips_fp_abi_value (unsigned int val)
  15213. {
  15214. switch (val)
  15215. {
  15216. case Val_GNU_MIPS_ABI_FP_ANY:
  15217. printf (_("Hard or soft float\n"));
  15218. break;
  15219. case Val_GNU_MIPS_ABI_FP_DOUBLE:
  15220. printf (_("Hard float (double precision)\n"));
  15221. break;
  15222. case Val_GNU_MIPS_ABI_FP_SINGLE:
  15223. printf (_("Hard float (single precision)\n"));
  15224. break;
  15225. case Val_GNU_MIPS_ABI_FP_SOFT:
  15226. printf (_("Soft float\n"));
  15227. break;
  15228. case Val_GNU_MIPS_ABI_FP_OLD_64:
  15229. printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
  15230. break;
  15231. case Val_GNU_MIPS_ABI_FP_XX:
  15232. printf (_("Hard float (32-bit CPU, Any FPU)\n"));
  15233. break;
  15234. case Val_GNU_MIPS_ABI_FP_64:
  15235. printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
  15236. break;
  15237. case Val_GNU_MIPS_ABI_FP_64A:
  15238. printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
  15239. break;
  15240. case Val_GNU_MIPS_ABI_FP_NAN2008:
  15241. printf (_("NaN 2008 compatibility\n"));
  15242. break;
  15243. default:
  15244. printf ("??? (%d)\n", val);
  15245. break;
  15246. }
  15247. }
  15248. static unsigned char *
  15249. display_mips_gnu_attribute (unsigned char * p,
  15250. unsigned int tag,
  15251. const unsigned char * const end)
  15252. {
  15253. if (tag == Tag_GNU_MIPS_ABI_FP)
  15254. {
  15255. unsigned int val;
  15256. printf (" Tag_GNU_MIPS_ABI_FP: ");
  15257. READ_ULEB (val, p, end);
  15258. print_mips_fp_abi_value (val);
  15259. return p;
  15260. }
  15261. if (tag == Tag_GNU_MIPS_ABI_MSA)
  15262. {
  15263. unsigned int val;
  15264. printf (" Tag_GNU_MIPS_ABI_MSA: ");
  15265. READ_ULEB (val, p, end);
  15266. switch (val)
  15267. {
  15268. case Val_GNU_MIPS_ABI_MSA_ANY:
  15269. printf (_("Any MSA or not\n"));
  15270. break;
  15271. case Val_GNU_MIPS_ABI_MSA_128:
  15272. printf (_("128-bit MSA\n"));
  15273. break;
  15274. default:
  15275. printf ("??? (%d)\n", val);
  15276. break;
  15277. }
  15278. return p;
  15279. }
  15280. return display_tag_value (tag & 1, p, end);
  15281. }
  15282. static unsigned char *
  15283. display_tic6x_attribute (unsigned char * p,
  15284. const unsigned char * const end)
  15285. {
  15286. unsigned int tag;
  15287. unsigned int val;
  15288. READ_ULEB (tag, p, end);
  15289. switch (tag)
  15290. {
  15291. case Tag_ISA:
  15292. printf (" Tag_ISA: ");
  15293. READ_ULEB (val, p, end);
  15294. switch (val)
  15295. {
  15296. case C6XABI_Tag_ISA_none:
  15297. printf (_("None\n"));
  15298. break;
  15299. case C6XABI_Tag_ISA_C62X:
  15300. printf ("C62x\n");
  15301. break;
  15302. case C6XABI_Tag_ISA_C67X:
  15303. printf ("C67x\n");
  15304. break;
  15305. case C6XABI_Tag_ISA_C67XP:
  15306. printf ("C67x+\n");
  15307. break;
  15308. case C6XABI_Tag_ISA_C64X:
  15309. printf ("C64x\n");
  15310. break;
  15311. case C6XABI_Tag_ISA_C64XP:
  15312. printf ("C64x+\n");
  15313. break;
  15314. case C6XABI_Tag_ISA_C674X:
  15315. printf ("C674x\n");
  15316. break;
  15317. default:
  15318. printf ("??? (%d)\n", val);
  15319. break;
  15320. }
  15321. return p;
  15322. case Tag_ABI_wchar_t:
  15323. printf (" Tag_ABI_wchar_t: ");
  15324. READ_ULEB (val, p, end);
  15325. switch (val)
  15326. {
  15327. case 0:
  15328. printf (_("Not used\n"));
  15329. break;
  15330. case 1:
  15331. printf (_("2 bytes\n"));
  15332. break;
  15333. case 2:
  15334. printf (_("4 bytes\n"));
  15335. break;
  15336. default:
  15337. printf ("??? (%d)\n", val);
  15338. break;
  15339. }
  15340. return p;
  15341. case Tag_ABI_stack_align_needed:
  15342. printf (" Tag_ABI_stack_align_needed: ");
  15343. READ_ULEB (val, p, end);
  15344. switch (val)
  15345. {
  15346. case 0:
  15347. printf (_("8-byte\n"));
  15348. break;
  15349. case 1:
  15350. printf (_("16-byte\n"));
  15351. break;
  15352. default:
  15353. printf ("??? (%d)\n", val);
  15354. break;
  15355. }
  15356. return p;
  15357. case Tag_ABI_stack_align_preserved:
  15358. READ_ULEB (val, p, end);
  15359. printf (" Tag_ABI_stack_align_preserved: ");
  15360. switch (val)
  15361. {
  15362. case 0:
  15363. printf (_("8-byte\n"));
  15364. break;
  15365. case 1:
  15366. printf (_("16-byte\n"));
  15367. break;
  15368. default:
  15369. printf ("??? (%d)\n", val);
  15370. break;
  15371. }
  15372. return p;
  15373. case Tag_ABI_DSBT:
  15374. READ_ULEB (val, p, end);
  15375. printf (" Tag_ABI_DSBT: ");
  15376. switch (val)
  15377. {
  15378. case 0:
  15379. printf (_("DSBT addressing not used\n"));
  15380. break;
  15381. case 1:
  15382. printf (_("DSBT addressing used\n"));
  15383. break;
  15384. default:
  15385. printf ("??? (%d)\n", val);
  15386. break;
  15387. }
  15388. return p;
  15389. case Tag_ABI_PID:
  15390. READ_ULEB (val, p, end);
  15391. printf (" Tag_ABI_PID: ");
  15392. switch (val)
  15393. {
  15394. case 0:
  15395. printf (_("Data addressing position-dependent\n"));
  15396. break;
  15397. case 1:
  15398. printf (_("Data addressing position-independent, GOT near DP\n"));
  15399. break;
  15400. case 2:
  15401. printf (_("Data addressing position-independent, GOT far from DP\n"));
  15402. break;
  15403. default:
  15404. printf ("??? (%d)\n", val);
  15405. break;
  15406. }
  15407. return p;
  15408. case Tag_ABI_PIC:
  15409. READ_ULEB (val, p, end);
  15410. printf (" Tag_ABI_PIC: ");
  15411. switch (val)
  15412. {
  15413. case 0:
  15414. printf (_("Code addressing position-dependent\n"));
  15415. break;
  15416. case 1:
  15417. printf (_("Code addressing position-independent\n"));
  15418. break;
  15419. default:
  15420. printf ("??? (%d)\n", val);
  15421. break;
  15422. }
  15423. return p;
  15424. case Tag_ABI_array_object_alignment:
  15425. READ_ULEB (val, p, end);
  15426. printf (" Tag_ABI_array_object_alignment: ");
  15427. switch (val)
  15428. {
  15429. case 0:
  15430. printf (_("8-byte\n"));
  15431. break;
  15432. case 1:
  15433. printf (_("4-byte\n"));
  15434. break;
  15435. case 2:
  15436. printf (_("16-byte\n"));
  15437. break;
  15438. default:
  15439. printf ("??? (%d)\n", val);
  15440. break;
  15441. }
  15442. return p;
  15443. case Tag_ABI_array_object_align_expected:
  15444. READ_ULEB (val, p, end);
  15445. printf (" Tag_ABI_array_object_align_expected: ");
  15446. switch (val)
  15447. {
  15448. case 0:
  15449. printf (_("8-byte\n"));
  15450. break;
  15451. case 1:
  15452. printf (_("4-byte\n"));
  15453. break;
  15454. case 2:
  15455. printf (_("16-byte\n"));
  15456. break;
  15457. default:
  15458. printf ("??? (%d)\n", val);
  15459. break;
  15460. }
  15461. return p;
  15462. case Tag_ABI_compatibility:
  15463. {
  15464. READ_ULEB (val, p, end);
  15465. printf (" Tag_ABI_compatibility: ");
  15466. printf (_("flag = %d, vendor = "), val);
  15467. if (p < end - 1)
  15468. {
  15469. size_t maxlen = (end - p) - 1;
  15470. print_symbol ((int) maxlen, (const char *) p);
  15471. p += strnlen ((char *) p, maxlen) + 1;
  15472. }
  15473. else
  15474. {
  15475. printf (_("<corrupt>"));
  15476. p = (unsigned char *) end;
  15477. }
  15478. putchar ('\n');
  15479. return p;
  15480. }
  15481. case Tag_ABI_conformance:
  15482. {
  15483. printf (" Tag_ABI_conformance: \"");
  15484. if (p < end - 1)
  15485. {
  15486. size_t maxlen = (end - p) - 1;
  15487. print_symbol ((int) maxlen, (const char *) p);
  15488. p += strnlen ((char *) p, maxlen) + 1;
  15489. }
  15490. else
  15491. {
  15492. printf (_("<corrupt>"));
  15493. p = (unsigned char *) end;
  15494. }
  15495. printf ("\"\n");
  15496. return p;
  15497. }
  15498. }
  15499. return display_tag_value (tag, p, end);
  15500. }
  15501. static void
  15502. display_raw_attribute (unsigned char * p, unsigned char const * const end)
  15503. {
  15504. unsigned long addr = 0;
  15505. size_t bytes = end - p;
  15506. assert (end >= p);
  15507. while (bytes)
  15508. {
  15509. int j;
  15510. int k;
  15511. int lbytes = (bytes > 16 ? 16 : bytes);
  15512. printf (" 0x%8.8lx ", addr);
  15513. for (j = 0; j < 16; j++)
  15514. {
  15515. if (j < lbytes)
  15516. printf ("%2.2x", p[j]);
  15517. else
  15518. printf (" ");
  15519. if ((j & 3) == 3)
  15520. printf (" ");
  15521. }
  15522. for (j = 0; j < lbytes; j++)
  15523. {
  15524. k = p[j];
  15525. if (k >= ' ' && k < 0x7f)
  15526. printf ("%c", k);
  15527. else
  15528. printf (".");
  15529. }
  15530. putchar ('\n');
  15531. p += lbytes;
  15532. bytes -= lbytes;
  15533. addr += lbytes;
  15534. }
  15535. putchar ('\n');
  15536. }
  15537. static unsigned char *
  15538. display_msp430_attribute (unsigned char * p,
  15539. const unsigned char * const end)
  15540. {
  15541. unsigned int val;
  15542. unsigned int tag;
  15543. READ_ULEB (tag, p, end);
  15544. switch (tag)
  15545. {
  15546. case OFBA_MSPABI_Tag_ISA:
  15547. printf (" Tag_ISA: ");
  15548. READ_ULEB (val, p, end);
  15549. switch (val)
  15550. {
  15551. case 0: printf (_("None\n")); break;
  15552. case 1: printf (_("MSP430\n")); break;
  15553. case 2: printf (_("MSP430X\n")); break;
  15554. default: printf ("??? (%d)\n", val); break;
  15555. }
  15556. break;
  15557. case OFBA_MSPABI_Tag_Code_Model:
  15558. printf (" Tag_Code_Model: ");
  15559. READ_ULEB (val, p, end);
  15560. switch (val)
  15561. {
  15562. case 0: printf (_("None\n")); break;
  15563. case 1: printf (_("Small\n")); break;
  15564. case 2: printf (_("Large\n")); break;
  15565. default: printf ("??? (%d)\n", val); break;
  15566. }
  15567. break;
  15568. case OFBA_MSPABI_Tag_Data_Model:
  15569. printf (" Tag_Data_Model: ");
  15570. READ_ULEB (val, p, end);
  15571. switch (val)
  15572. {
  15573. case 0: printf (_("None\n")); break;
  15574. case 1: printf (_("Small\n")); break;
  15575. case 2: printf (_("Large\n")); break;
  15576. case 3: printf (_("Restricted Large\n")); break;
  15577. default: printf ("??? (%d)\n", val); break;
  15578. }
  15579. break;
  15580. default:
  15581. printf (_(" <unknown tag %d>: "), tag);
  15582. if (tag & 1)
  15583. {
  15584. putchar ('"');
  15585. if (p < end - 1)
  15586. {
  15587. size_t maxlen = (end - p) - 1;
  15588. print_symbol ((int) maxlen, (const char *) p);
  15589. p += strnlen ((char *) p, maxlen) + 1;
  15590. }
  15591. else
  15592. {
  15593. printf (_("<corrupt>"));
  15594. p = (unsigned char *) end;
  15595. }
  15596. printf ("\"\n");
  15597. }
  15598. else
  15599. {
  15600. READ_ULEB (val, p, end);
  15601. printf ("%d (0x%x)\n", val, val);
  15602. }
  15603. break;
  15604. }
  15605. assert (p <= end);
  15606. return p;
  15607. }
  15608. static unsigned char *
  15609. display_msp430_gnu_attribute (unsigned char * p,
  15610. unsigned int tag,
  15611. const unsigned char * const end)
  15612. {
  15613. if (tag == Tag_GNU_MSP430_Data_Region)
  15614. {
  15615. unsigned int val;
  15616. printf (" Tag_GNU_MSP430_Data_Region: ");
  15617. READ_ULEB (val, p, end);
  15618. switch (val)
  15619. {
  15620. case Val_GNU_MSP430_Data_Region_Any:
  15621. printf (_("Any Region\n"));
  15622. break;
  15623. case Val_GNU_MSP430_Data_Region_Lower:
  15624. printf (_("Lower Region Only\n"));
  15625. break;
  15626. default:
  15627. printf ("??? (%u)\n", val);
  15628. }
  15629. return p;
  15630. }
  15631. return display_tag_value (tag & 1, p, end);
  15632. }
  15633. struct riscv_attr_tag_t {
  15634. const char *name;
  15635. unsigned int tag;
  15636. };
  15637. static struct riscv_attr_tag_t riscv_attr_tag[] =
  15638. {
  15639. #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag}
  15640. T(arch),
  15641. T(priv_spec),
  15642. T(priv_spec_minor),
  15643. T(priv_spec_revision),
  15644. T(unaligned_access),
  15645. T(stack_align),
  15646. #undef T
  15647. };
  15648. static unsigned char *
  15649. display_riscv_attribute (unsigned char *p,
  15650. const unsigned char * const end)
  15651. {
  15652. unsigned int val;
  15653. unsigned int tag;
  15654. struct riscv_attr_tag_t *attr = NULL;
  15655. unsigned i;
  15656. READ_ULEB (tag, p, end);
  15657. /* Find the name of attribute. */
  15658. for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++)
  15659. {
  15660. if (riscv_attr_tag[i].tag == tag)
  15661. {
  15662. attr = &riscv_attr_tag[i];
  15663. break;
  15664. }
  15665. }
  15666. if (attr)
  15667. printf (" %s: ", attr->name);
  15668. else
  15669. return display_tag_value (tag, p, end);
  15670. switch (tag)
  15671. {
  15672. case Tag_RISCV_priv_spec:
  15673. case Tag_RISCV_priv_spec_minor:
  15674. case Tag_RISCV_priv_spec_revision:
  15675. READ_ULEB (val, p, end);
  15676. printf (_("%u\n"), val);
  15677. break;
  15678. case Tag_RISCV_unaligned_access:
  15679. READ_ULEB (val, p, end);
  15680. switch (val)
  15681. {
  15682. case 0:
  15683. printf (_("No unaligned access\n"));
  15684. break;
  15685. case 1:
  15686. printf (_("Unaligned access\n"));
  15687. break;
  15688. }
  15689. break;
  15690. case Tag_RISCV_stack_align:
  15691. READ_ULEB (val, p, end);
  15692. printf (_("%u-bytes\n"), val);
  15693. break;
  15694. case Tag_RISCV_arch:
  15695. p = display_tag_value (-1, p, end);
  15696. break;
  15697. default:
  15698. return display_tag_value (tag, p, end);
  15699. }
  15700. return p;
  15701. }
  15702. static unsigned char *
  15703. display_csky_attribute (unsigned char * p,
  15704. const unsigned char * const end)
  15705. {
  15706. unsigned int tag;
  15707. unsigned int val;
  15708. READ_ULEB (tag, p, end);
  15709. if (tag >= Tag_CSKY_MAX)
  15710. {
  15711. return display_tag_value (-1, p, end);
  15712. }
  15713. switch (tag)
  15714. {
  15715. case Tag_CSKY_ARCH_NAME:
  15716. printf (" Tag_CSKY_ARCH_NAME:\t\t");
  15717. return display_tag_value (-1, p, end);
  15718. case Tag_CSKY_CPU_NAME:
  15719. printf (" Tag_CSKY_CPU_NAME:\t\t");
  15720. return display_tag_value (-1, p, end);
  15721. case Tag_CSKY_ISA_FLAGS:
  15722. printf (" Tag_CSKY_ISA_FLAGS:\t\t");
  15723. return display_tag_value (0, p, end);
  15724. case Tag_CSKY_ISA_EXT_FLAGS:
  15725. printf (" Tag_CSKY_ISA_EXT_FLAGS:\t");
  15726. return display_tag_value (0, p, end);
  15727. case Tag_CSKY_DSP_VERSION:
  15728. printf (" Tag_CSKY_DSP_VERSION:\t\t");
  15729. READ_ULEB (val, p, end);
  15730. if (val == VAL_CSKY_DSP_VERSION_EXTENSION)
  15731. printf ("DSP Extension\n");
  15732. else if (val == VAL_CSKY_DSP_VERSION_2)
  15733. printf ("DSP 2.0\n");
  15734. break;
  15735. case Tag_CSKY_VDSP_VERSION:
  15736. printf (" Tag_CSKY_VDSP_VERSION:\t");
  15737. READ_ULEB (val, p, end);
  15738. printf ("VDSP Version %d\n", val);
  15739. break;
  15740. case Tag_CSKY_FPU_VERSION:
  15741. printf (" Tag_CSKY_FPU_VERSION:\t\t");
  15742. READ_ULEB (val, p, end);
  15743. if (val == VAL_CSKY_FPU_VERSION_1)
  15744. printf ("ABIV1 FPU Version 1\n");
  15745. else if (val == VAL_CSKY_FPU_VERSION_2)
  15746. printf ("FPU Version 2\n");
  15747. break;
  15748. case Tag_CSKY_FPU_ABI:
  15749. printf (" Tag_CSKY_FPU_ABI:\t\t");
  15750. READ_ULEB (val, p, end);
  15751. if (val == VAL_CSKY_FPU_ABI_HARD)
  15752. printf ("Hard\n");
  15753. else if (val == VAL_CSKY_FPU_ABI_SOFTFP)
  15754. printf ("SoftFP\n");
  15755. else if (val == VAL_CSKY_FPU_ABI_SOFT)
  15756. printf ("Soft\n");
  15757. break;
  15758. case Tag_CSKY_FPU_ROUNDING:
  15759. READ_ULEB (val, p, end);
  15760. if (val == 1)
  15761. {
  15762. printf (" Tag_CSKY_FPU_ROUNDING:\t");
  15763. printf ("Needed\n");
  15764. }
  15765. break;
  15766. case Tag_CSKY_FPU_DENORMAL:
  15767. READ_ULEB (val, p, end);
  15768. if (val == 1)
  15769. {
  15770. printf (" Tag_CSKY_FPU_DENORMAL:\t");
  15771. printf ("Needed\n");
  15772. }
  15773. break;
  15774. case Tag_CSKY_FPU_Exception:
  15775. READ_ULEB (val, p, end);
  15776. if (val == 1)
  15777. {
  15778. printf (" Tag_CSKY_FPU_Exception:\t");
  15779. printf ("Needed\n");
  15780. }
  15781. break;
  15782. case Tag_CSKY_FPU_NUMBER_MODULE:
  15783. printf (" Tag_CSKY_FPU_NUMBER_MODULE:\t");
  15784. return display_tag_value (-1, p, end);
  15785. case Tag_CSKY_FPU_HARDFP:
  15786. printf (" Tag_CSKY_FPU_HARDFP:\t\t");
  15787. READ_ULEB (val, p, end);
  15788. if (val & VAL_CSKY_FPU_HARDFP_HALF)
  15789. printf (" Half");
  15790. if (val & VAL_CSKY_FPU_HARDFP_SINGLE)
  15791. printf (" Single");
  15792. if (val & VAL_CSKY_FPU_HARDFP_DOUBLE)
  15793. printf (" Double");
  15794. printf ("\n");
  15795. break;
  15796. default:
  15797. return display_tag_value (tag, p, end);
  15798. }
  15799. return p;
  15800. }
  15801. static bool
  15802. process_attributes (Filedata * filedata,
  15803. const char * public_name,
  15804. unsigned int proc_type,
  15805. unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),
  15806. unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const))
  15807. {
  15808. Elf_Internal_Shdr * sect;
  15809. unsigned i;
  15810. bool res = true;
  15811. /* Find the section header so that we get the size. */
  15812. for (i = 0, sect = filedata->section_headers;
  15813. i < filedata->file_header.e_shnum;
  15814. i++, sect++)
  15815. {
  15816. unsigned char * contents;
  15817. unsigned char * p;
  15818. if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
  15819. continue;
  15820. contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1,
  15821. sect->sh_size, _("attributes"));
  15822. if (contents == NULL)
  15823. {
  15824. res = false;
  15825. continue;
  15826. }
  15827. p = contents;
  15828. /* The first character is the version of the attributes.
  15829. Currently only version 1, (aka 'A') is recognised here. */
  15830. if (*p != 'A')
  15831. {
  15832. printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p);
  15833. res = false;
  15834. }
  15835. else
  15836. {
  15837. bfd_vma section_len;
  15838. section_len = sect->sh_size - 1;
  15839. p++;
  15840. while (section_len > 0)
  15841. {
  15842. bfd_vma attr_len;
  15843. unsigned int namelen;
  15844. bool public_section;
  15845. bool gnu_section;
  15846. if (section_len <= 4)
  15847. {
  15848. error (_("Tag section ends prematurely\n"));
  15849. res = false;
  15850. break;
  15851. }
  15852. attr_len = byte_get (p, 4);
  15853. p += 4;
  15854. if (attr_len > section_len)
  15855. {
  15856. error (_("Bad attribute length (%u > %u)\n"),
  15857. (unsigned) attr_len, (unsigned) section_len);
  15858. attr_len = section_len;
  15859. res = false;
  15860. }
  15861. /* PR 17531: file: 001-101425-0.004 */
  15862. else if (attr_len < 5)
  15863. {
  15864. error (_("Attribute length of %u is too small\n"), (unsigned) attr_len);
  15865. res = false;
  15866. break;
  15867. }
  15868. section_len -= attr_len;
  15869. attr_len -= 4;
  15870. namelen = strnlen ((char *) p, attr_len) + 1;
  15871. if (namelen == 0 || namelen >= attr_len)
  15872. {
  15873. error (_("Corrupt attribute section name\n"));
  15874. res = false;
  15875. break;
  15876. }
  15877. printf (_("Attribute Section: "));
  15878. print_symbol (INT_MAX, (const char *) p);
  15879. putchar ('\n');
  15880. if (public_name && streq ((char *) p, public_name))
  15881. public_section = true;
  15882. else
  15883. public_section = false;
  15884. if (streq ((char *) p, "gnu"))
  15885. gnu_section = true;
  15886. else
  15887. gnu_section = false;
  15888. p += namelen;
  15889. attr_len -= namelen;
  15890. while (attr_len > 0 && p < contents + sect->sh_size)
  15891. {
  15892. int tag;
  15893. unsigned int val;
  15894. bfd_vma size;
  15895. unsigned char * end;
  15896. /* PR binutils/17531: Safe handling of corrupt files. */
  15897. if (attr_len < 6)
  15898. {
  15899. error (_("Unused bytes at end of section\n"));
  15900. res = false;
  15901. section_len = 0;
  15902. break;
  15903. }
  15904. tag = *(p++);
  15905. size = byte_get (p, 4);
  15906. if (size > attr_len)
  15907. {
  15908. error (_("Bad subsection length (%u > %u)\n"),
  15909. (unsigned) size, (unsigned) attr_len);
  15910. res = false;
  15911. size = attr_len;
  15912. }
  15913. /* PR binutils/17531: Safe handling of corrupt files. */
  15914. if (size < 6)
  15915. {
  15916. error (_("Bad subsection length (%u < 6)\n"),
  15917. (unsigned) size);
  15918. res = false;
  15919. section_len = 0;
  15920. break;
  15921. }
  15922. attr_len -= size;
  15923. end = p + size - 1;
  15924. assert (end <= contents + sect->sh_size);
  15925. p += 4;
  15926. switch (tag)
  15927. {
  15928. case 1:
  15929. printf (_("File Attributes\n"));
  15930. break;
  15931. case 2:
  15932. printf (_("Section Attributes:"));
  15933. goto do_numlist;
  15934. case 3:
  15935. printf (_("Symbol Attributes:"));
  15936. /* Fall through. */
  15937. do_numlist:
  15938. for (;;)
  15939. {
  15940. READ_ULEB (val, p, end);
  15941. if (val == 0)
  15942. break;
  15943. printf (" %d", val);
  15944. }
  15945. printf ("\n");
  15946. break;
  15947. default:
  15948. printf (_("Unknown tag: %d\n"), tag);
  15949. public_section = false;
  15950. break;
  15951. }
  15952. if (public_section && display_pub_attribute != NULL)
  15953. {
  15954. while (p < end)
  15955. p = display_pub_attribute (p, end);
  15956. assert (p == end);
  15957. }
  15958. else if (gnu_section && display_proc_gnu_attribute != NULL)
  15959. {
  15960. while (p < end)
  15961. p = display_gnu_attribute (p,
  15962. display_proc_gnu_attribute,
  15963. end);
  15964. assert (p == end);
  15965. }
  15966. else if (p < end)
  15967. {
  15968. printf (_(" Unknown attribute:\n"));
  15969. display_raw_attribute (p, end);
  15970. p = end;
  15971. }
  15972. else
  15973. attr_len = 0;
  15974. }
  15975. }
  15976. }
  15977. free (contents);
  15978. }
  15979. return res;
  15980. }
  15981. /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
  15982. Print the Address, Access and Initial fields of an entry at VMA ADDR
  15983. and return the VMA of the next entry, or -1 if there was a problem.
  15984. Does not read from DATA_END or beyond. */
  15985. static bfd_vma
  15986. print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr,
  15987. unsigned char * data_end)
  15988. {
  15989. printf (" ");
  15990. print_vma (addr, LONG_HEX);
  15991. printf (" ");
  15992. if (addr < pltgot + 0xfff0)
  15993. printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
  15994. else
  15995. printf ("%10s", "");
  15996. printf (" ");
  15997. if (data == NULL)
  15998. printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
  15999. else
  16000. {
  16001. bfd_vma entry;
  16002. unsigned char * from = data + addr - pltgot;
  16003. if (from + (is_32bit_elf ? 4 : 8) > data_end)
  16004. {
  16005. warn (_("MIPS GOT entry extends beyond the end of available data\n"));
  16006. printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>"));
  16007. return (bfd_vma) -1;
  16008. }
  16009. else
  16010. {
  16011. entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
  16012. print_vma (entry, LONG_HEX);
  16013. }
  16014. }
  16015. return addr + (is_32bit_elf ? 4 : 8);
  16016. }
  16017. /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
  16018. PLTGOT. Print the Address and Initial fields of an entry at VMA
  16019. ADDR and return the VMA of the next entry. */
  16020. static bfd_vma
  16021. print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
  16022. {
  16023. printf (" ");
  16024. print_vma (addr, LONG_HEX);
  16025. printf (" ");
  16026. if (data == NULL)
  16027. printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
  16028. else
  16029. {
  16030. bfd_vma entry;
  16031. entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
  16032. print_vma (entry, LONG_HEX);
  16033. }
  16034. return addr + (is_32bit_elf ? 4 : 8);
  16035. }
  16036. static void
  16037. print_mips_ases (unsigned int mask)
  16038. {
  16039. if (mask & AFL_ASE_DSP)
  16040. fputs ("\n\tDSP ASE", stdout);
  16041. if (mask & AFL_ASE_DSPR2)
  16042. fputs ("\n\tDSP R2 ASE", stdout);
  16043. if (mask & AFL_ASE_DSPR3)
  16044. fputs ("\n\tDSP R3 ASE", stdout);
  16045. if (mask & AFL_ASE_EVA)
  16046. fputs ("\n\tEnhanced VA Scheme", stdout);
  16047. if (mask & AFL_ASE_MCU)
  16048. fputs ("\n\tMCU (MicroController) ASE", stdout);
  16049. if (mask & AFL_ASE_MDMX)
  16050. fputs ("\n\tMDMX ASE", stdout);
  16051. if (mask & AFL_ASE_MIPS3D)
  16052. fputs ("\n\tMIPS-3D ASE", stdout);
  16053. if (mask & AFL_ASE_MT)
  16054. fputs ("\n\tMT ASE", stdout);
  16055. if (mask & AFL_ASE_SMARTMIPS)
  16056. fputs ("\n\tSmartMIPS ASE", stdout);
  16057. if (mask & AFL_ASE_VIRT)
  16058. fputs ("\n\tVZ ASE", stdout);
  16059. if (mask & AFL_ASE_MSA)
  16060. fputs ("\n\tMSA ASE", stdout);
  16061. if (mask & AFL_ASE_MIPS16)
  16062. fputs ("\n\tMIPS16 ASE", stdout);
  16063. if (mask & AFL_ASE_MICROMIPS)
  16064. fputs ("\n\tMICROMIPS ASE", stdout);
  16065. if (mask & AFL_ASE_XPA)
  16066. fputs ("\n\tXPA ASE", stdout);
  16067. if (mask & AFL_ASE_MIPS16E2)
  16068. fputs ("\n\tMIPS16e2 ASE", stdout);
  16069. if (mask & AFL_ASE_CRC)
  16070. fputs ("\n\tCRC ASE", stdout);
  16071. if (mask & AFL_ASE_GINV)
  16072. fputs ("\n\tGINV ASE", stdout);
  16073. if (mask & AFL_ASE_LOONGSON_MMI)
  16074. fputs ("\n\tLoongson MMI ASE", stdout);
  16075. if (mask & AFL_ASE_LOONGSON_CAM)
  16076. fputs ("\n\tLoongson CAM ASE", stdout);
  16077. if (mask & AFL_ASE_LOONGSON_EXT)
  16078. fputs ("\n\tLoongson EXT ASE", stdout);
  16079. if (mask & AFL_ASE_LOONGSON_EXT2)
  16080. fputs ("\n\tLoongson EXT2 ASE", stdout);
  16081. if (mask == 0)
  16082. fprintf (stdout, "\n\t%s", _("None"));
  16083. else if ((mask & ~AFL_ASE_MASK) != 0)
  16084. fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK);
  16085. }
  16086. static void
  16087. print_mips_isa_ext (unsigned int isa_ext)
  16088. {
  16089. switch (isa_ext)
  16090. {
  16091. case 0:
  16092. fputs (_("None"), stdout);
  16093. break;
  16094. case AFL_EXT_XLR:
  16095. fputs ("RMI XLR", stdout);
  16096. break;
  16097. case AFL_EXT_OCTEON3:
  16098. fputs ("Cavium Networks Octeon3", stdout);
  16099. break;
  16100. case AFL_EXT_OCTEON2:
  16101. fputs ("Cavium Networks Octeon2", stdout);
  16102. break;
  16103. case AFL_EXT_OCTEONP:
  16104. fputs ("Cavium Networks OcteonP", stdout);
  16105. break;
  16106. case AFL_EXT_OCTEON:
  16107. fputs ("Cavium Networks Octeon", stdout);
  16108. break;
  16109. case AFL_EXT_5900:
  16110. fputs ("Toshiba R5900", stdout);
  16111. break;
  16112. case AFL_EXT_4650:
  16113. fputs ("MIPS R4650", stdout);
  16114. break;
  16115. case AFL_EXT_4010:
  16116. fputs ("LSI R4010", stdout);
  16117. break;
  16118. case AFL_EXT_4100:
  16119. fputs ("NEC VR4100", stdout);
  16120. break;
  16121. case AFL_EXT_3900:
  16122. fputs ("Toshiba R3900", stdout);
  16123. break;
  16124. case AFL_EXT_10000:
  16125. fputs ("MIPS R10000", stdout);
  16126. break;
  16127. case AFL_EXT_SB1:
  16128. fputs ("Broadcom SB-1", stdout);
  16129. break;
  16130. case AFL_EXT_4111:
  16131. fputs ("NEC VR4111/VR4181", stdout);
  16132. break;
  16133. case AFL_EXT_4120:
  16134. fputs ("NEC VR4120", stdout);
  16135. break;
  16136. case AFL_EXT_5400:
  16137. fputs ("NEC VR5400", stdout);
  16138. break;
  16139. case AFL_EXT_5500:
  16140. fputs ("NEC VR5500", stdout);
  16141. break;
  16142. case AFL_EXT_LOONGSON_2E:
  16143. fputs ("ST Microelectronics Loongson 2E", stdout);
  16144. break;
  16145. case AFL_EXT_LOONGSON_2F:
  16146. fputs ("ST Microelectronics Loongson 2F", stdout);
  16147. break;
  16148. case AFL_EXT_INTERAPTIV_MR2:
  16149. fputs ("Imagination interAptiv MR2", stdout);
  16150. break;
  16151. default:
  16152. fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext);
  16153. }
  16154. }
  16155. static signed int
  16156. get_mips_reg_size (int reg_size)
  16157. {
  16158. return (reg_size == AFL_REG_NONE) ? 0
  16159. : (reg_size == AFL_REG_32) ? 32
  16160. : (reg_size == AFL_REG_64) ? 64
  16161. : (reg_size == AFL_REG_128) ? 128
  16162. : -1;
  16163. }
  16164. static bool
  16165. process_mips_specific (Filedata * filedata)
  16166. {
  16167. Elf_Internal_Dyn * entry;
  16168. Elf_Internal_Shdr *sect = NULL;
  16169. size_t liblist_offset = 0;
  16170. size_t liblistno = 0;
  16171. size_t conflictsno = 0;
  16172. size_t options_offset = 0;
  16173. size_t conflicts_offset = 0;
  16174. size_t pltrelsz = 0;
  16175. size_t pltrel = 0;
  16176. bfd_vma pltgot = 0;
  16177. bfd_vma mips_pltgot = 0;
  16178. bfd_vma jmprel = 0;
  16179. bfd_vma local_gotno = 0;
  16180. bfd_vma gotsym = 0;
  16181. bfd_vma symtabno = 0;
  16182. bool res = true;
  16183. if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
  16184. display_mips_gnu_attribute))
  16185. res = false;
  16186. sect = find_section (filedata, ".MIPS.abiflags");
  16187. if (sect != NULL)
  16188. {
  16189. Elf_External_ABIFlags_v0 *abiflags_ext;
  16190. Elf_Internal_ABIFlags_v0 abiflags_in;
  16191. if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
  16192. {
  16193. error (_("Corrupt MIPS ABI Flags section.\n"));
  16194. res = false;
  16195. }
  16196. else
  16197. {
  16198. abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1,
  16199. sect->sh_size, _("MIPS ABI Flags section"));
  16200. if (abiflags_ext)
  16201. {
  16202. abiflags_in.version = BYTE_GET (abiflags_ext->version);
  16203. abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
  16204. abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
  16205. abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
  16206. abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
  16207. abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
  16208. abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
  16209. abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
  16210. abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
  16211. abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
  16212. abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
  16213. printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
  16214. printf ("\nISA: MIPS%d", abiflags_in.isa_level);
  16215. if (abiflags_in.isa_rev > 1)
  16216. printf ("r%d", abiflags_in.isa_rev);
  16217. printf ("\nGPR size: %d",
  16218. get_mips_reg_size (abiflags_in.gpr_size));
  16219. printf ("\nCPR1 size: %d",
  16220. get_mips_reg_size (abiflags_in.cpr1_size));
  16221. printf ("\nCPR2 size: %d",
  16222. get_mips_reg_size (abiflags_in.cpr2_size));
  16223. fputs ("\nFP ABI: ", stdout);
  16224. print_mips_fp_abi_value (abiflags_in.fp_abi);
  16225. fputs ("ISA Extension: ", stdout);
  16226. print_mips_isa_ext (abiflags_in.isa_ext);
  16227. fputs ("\nASEs:", stdout);
  16228. print_mips_ases (abiflags_in.ases);
  16229. printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
  16230. printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
  16231. fputc ('\n', stdout);
  16232. free (abiflags_ext);
  16233. }
  16234. }
  16235. }
  16236. /* We have a lot of special sections. Thanks SGI! */
  16237. if (filedata->dynamic_section == NULL)
  16238. {
  16239. /* No dynamic information available. See if there is static GOT. */
  16240. sect = find_section (filedata, ".got");
  16241. if (sect != NULL)
  16242. {
  16243. unsigned char *data_end;
  16244. unsigned char *data;
  16245. bfd_vma ent, end;
  16246. int addr_size;
  16247. pltgot = sect->sh_addr;
  16248. ent = pltgot;
  16249. addr_size = (is_32bit_elf ? 4 : 8);
  16250. end = pltgot + sect->sh_size;
  16251. data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset,
  16252. end - pltgot, 1,
  16253. _("Global Offset Table data"));
  16254. /* PR 12855: Null data is handled gracefully throughout. */
  16255. data_end = data + (end - pltgot);
  16256. printf (_("\nStatic GOT:\n"));
  16257. printf (_(" Canonical gp value: "));
  16258. print_vma (ent + 0x7ff0, LONG_HEX);
  16259. printf ("\n\n");
  16260. /* In a dynamic binary GOT[0] is reserved for the dynamic
  16261. loader to store the lazy resolver pointer, however in
  16262. a static binary it may well have been omitted and GOT
  16263. reduced to a table of addresses.
  16264. PR 21344: Check for the entry being fully available
  16265. before fetching it. */
  16266. if (data
  16267. && data + ent - pltgot + addr_size <= data_end
  16268. && byte_get (data + ent - pltgot, addr_size) == 0)
  16269. {
  16270. printf (_(" Reserved entries:\n"));
  16271. printf (_(" %*s %10s %*s\n"),
  16272. addr_size * 2, _("Address"), _("Access"),
  16273. addr_size * 2, _("Value"));
  16274. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  16275. printf ("\n");
  16276. if (ent == (bfd_vma) -1)
  16277. goto sgot_print_fail;
  16278. /* Check for the MSB of GOT[1] being set, identifying a
  16279. GNU object. This entry will be used by some runtime
  16280. loaders, to store the module pointer. Otherwise this
  16281. is an ordinary local entry.
  16282. PR 21344: Check for the entry being fully available
  16283. before fetching it. */
  16284. if (data
  16285. && data + ent - pltgot + addr_size <= data_end
  16286. && (byte_get (data + ent - pltgot, addr_size)
  16287. >> (addr_size * 8 - 1)) != 0)
  16288. {
  16289. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  16290. printf ("\n");
  16291. if (ent == (bfd_vma) -1)
  16292. goto sgot_print_fail;
  16293. }
  16294. printf ("\n");
  16295. }
  16296. if (data != NULL && ent < end)
  16297. {
  16298. printf (_(" Local entries:\n"));
  16299. printf (" %*s %10s %*s\n",
  16300. addr_size * 2, _("Address"), _("Access"),
  16301. addr_size * 2, _("Value"));
  16302. while (ent < end)
  16303. {
  16304. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  16305. printf ("\n");
  16306. if (ent == (bfd_vma) -1)
  16307. goto sgot_print_fail;
  16308. }
  16309. printf ("\n");
  16310. }
  16311. sgot_print_fail:
  16312. free (data);
  16313. }
  16314. return res;
  16315. }
  16316. for (entry = filedata->dynamic_section;
  16317. /* PR 17531 file: 012-50589-0.004. */
  16318. (entry < filedata->dynamic_section + filedata->dynamic_nent
  16319. && entry->d_tag != DT_NULL);
  16320. ++entry)
  16321. switch (entry->d_tag)
  16322. {
  16323. case DT_MIPS_LIBLIST:
  16324. liblist_offset
  16325. = offset_from_vma (filedata, entry->d_un.d_val,
  16326. liblistno * sizeof (Elf32_External_Lib));
  16327. break;
  16328. case DT_MIPS_LIBLISTNO:
  16329. liblistno = entry->d_un.d_val;
  16330. break;
  16331. case DT_MIPS_OPTIONS:
  16332. options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0);
  16333. break;
  16334. case DT_MIPS_CONFLICT:
  16335. conflicts_offset
  16336. = offset_from_vma (filedata, entry->d_un.d_val,
  16337. conflictsno * sizeof (Elf32_External_Conflict));
  16338. break;
  16339. case DT_MIPS_CONFLICTNO:
  16340. conflictsno = entry->d_un.d_val;
  16341. break;
  16342. case DT_PLTGOT:
  16343. pltgot = entry->d_un.d_ptr;
  16344. break;
  16345. case DT_MIPS_LOCAL_GOTNO:
  16346. local_gotno = entry->d_un.d_val;
  16347. break;
  16348. case DT_MIPS_GOTSYM:
  16349. gotsym = entry->d_un.d_val;
  16350. break;
  16351. case DT_MIPS_SYMTABNO:
  16352. symtabno = entry->d_un.d_val;
  16353. break;
  16354. case DT_MIPS_PLTGOT:
  16355. mips_pltgot = entry->d_un.d_ptr;
  16356. break;
  16357. case DT_PLTREL:
  16358. pltrel = entry->d_un.d_val;
  16359. break;
  16360. case DT_PLTRELSZ:
  16361. pltrelsz = entry->d_un.d_val;
  16362. break;
  16363. case DT_JMPREL:
  16364. jmprel = entry->d_un.d_ptr;
  16365. break;
  16366. default:
  16367. break;
  16368. }
  16369. if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
  16370. {
  16371. Elf32_External_Lib * elib;
  16372. size_t cnt;
  16373. elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset,
  16374. sizeof (Elf32_External_Lib),
  16375. liblistno,
  16376. _("liblist section data"));
  16377. if (elib)
  16378. {
  16379. printf (ngettext ("\nSection '.liblist' contains %lu entry:\n",
  16380. "\nSection '.liblist' contains %lu entries:\n",
  16381. (unsigned long) liblistno),
  16382. (unsigned long) liblistno);
  16383. fputs (_(" Library Time Stamp Checksum Version Flags\n"),
  16384. stdout);
  16385. for (cnt = 0; cnt < liblistno; ++cnt)
  16386. {
  16387. Elf32_Lib liblist;
  16388. time_t atime;
  16389. char timebuf[128];
  16390. struct tm * tmp;
  16391. liblist.l_name = BYTE_GET (elib[cnt].l_name);
  16392. atime = BYTE_GET (elib[cnt].l_time_stamp);
  16393. liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
  16394. liblist.l_version = BYTE_GET (elib[cnt].l_version);
  16395. liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
  16396. tmp = gmtime (&atime);
  16397. snprintf (timebuf, sizeof (timebuf),
  16398. "%04u-%02u-%02uT%02u:%02u:%02u",
  16399. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  16400. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  16401. printf ("%3lu: ", (unsigned long) cnt);
  16402. if (valid_dynamic_name (filedata, liblist.l_name))
  16403. print_symbol (20, get_dynamic_name (filedata, liblist.l_name));
  16404. else
  16405. printf (_("<corrupt: %9ld>"), liblist.l_name);
  16406. printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
  16407. liblist.l_version);
  16408. if (liblist.l_flags == 0)
  16409. puts (_(" NONE"));
  16410. else
  16411. {
  16412. static const struct
  16413. {
  16414. const char * name;
  16415. int bit;
  16416. }
  16417. l_flags_vals[] =
  16418. {
  16419. { " EXACT_MATCH", LL_EXACT_MATCH },
  16420. { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
  16421. { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
  16422. { " EXPORTS", LL_EXPORTS },
  16423. { " DELAY_LOAD", LL_DELAY_LOAD },
  16424. { " DELTA", LL_DELTA }
  16425. };
  16426. int flags = liblist.l_flags;
  16427. size_t fcnt;
  16428. for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
  16429. if ((flags & l_flags_vals[fcnt].bit) != 0)
  16430. {
  16431. fputs (l_flags_vals[fcnt].name, stdout);
  16432. flags ^= l_flags_vals[fcnt].bit;
  16433. }
  16434. if (flags != 0)
  16435. printf (" %#x", (unsigned int) flags);
  16436. puts ("");
  16437. }
  16438. }
  16439. free (elib);
  16440. }
  16441. else
  16442. res = false;
  16443. }
  16444. if (options_offset != 0)
  16445. {
  16446. Elf_External_Options * eopt;
  16447. size_t offset;
  16448. int cnt;
  16449. /* Find the section header so that we get the size. */
  16450. sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS);
  16451. /* PR 17533 file: 012-277276-0.004. */
  16452. if (sect == NULL)
  16453. {
  16454. error (_("No MIPS_OPTIONS header found\n"));
  16455. return false;
  16456. }
  16457. /* PR 24243 */
  16458. if (sect->sh_size < sizeof (* eopt))
  16459. {
  16460. error (_("The MIPS options section is too small.\n"));
  16461. return false;
  16462. }
  16463. eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1,
  16464. sect->sh_size, _("options"));
  16465. if (eopt)
  16466. {
  16467. Elf_Internal_Options option;
  16468. offset = cnt = 0;
  16469. while (offset <= sect->sh_size - sizeof (* eopt))
  16470. {
  16471. Elf_External_Options * eoption;
  16472. unsigned int optsize;
  16473. eoption = (Elf_External_Options *) ((char *) eopt + offset);
  16474. optsize = BYTE_GET (eoption->size);
  16475. /* PR 17531: file: ffa0fa3b. */
  16476. if (optsize < sizeof (* eopt)
  16477. || optsize > sect->sh_size - offset)
  16478. {
  16479. error (_("Invalid size (%u) for MIPS option\n"),
  16480. optsize);
  16481. free (eopt);
  16482. return false;
  16483. }
  16484. offset += optsize;
  16485. ++cnt;
  16486. }
  16487. printf (ngettext ("\nSection '%s' contains %d entry:\n",
  16488. "\nSection '%s' contains %d entries:\n",
  16489. cnt),
  16490. printable_section_name (filedata, sect), cnt);
  16491. offset = 0;
  16492. while (cnt-- > 0)
  16493. {
  16494. size_t len;
  16495. Elf_External_Options * eoption;
  16496. eoption = (Elf_External_Options *) ((char *) eopt + offset);
  16497. option.kind = BYTE_GET (eoption->kind);
  16498. option.size = BYTE_GET (eoption->size);
  16499. option.section = BYTE_GET (eoption->section);
  16500. option.info = BYTE_GET (eoption->info);
  16501. switch (option.kind)
  16502. {
  16503. case ODK_NULL:
  16504. /* This shouldn't happen. */
  16505. printf (" NULL %" PRId16 " %" PRIx32,
  16506. option.section, option.info);
  16507. break;
  16508. case ODK_REGINFO:
  16509. printf (" REGINFO ");
  16510. if (filedata->file_header.e_machine == EM_MIPS)
  16511. {
  16512. Elf32_External_RegInfo * ereg;
  16513. Elf32_RegInfo reginfo;
  16514. /* 32bit form. */
  16515. if (option.size < (sizeof (Elf_External_Options)
  16516. + sizeof (Elf32_External_RegInfo)))
  16517. {
  16518. printf (_("<corrupt>\n"));
  16519. error (_("Truncated MIPS REGINFO option\n"));
  16520. cnt = 0;
  16521. break;
  16522. }
  16523. ereg = (Elf32_External_RegInfo *) (eoption + 1);
  16524. reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
  16525. reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
  16526. reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
  16527. reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
  16528. reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
  16529. reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
  16530. printf ("GPR %08" PRIx32 " GP 0x%" PRIx32 "\n",
  16531. reginfo.ri_gprmask, reginfo.ri_gp_value);
  16532. printf (" "
  16533. " CPR0 %08" PRIx32 " CPR1 %08" PRIx32
  16534. " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n",
  16535. reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
  16536. reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
  16537. }
  16538. else
  16539. {
  16540. /* 64 bit form. */
  16541. Elf64_External_RegInfo * ereg;
  16542. Elf64_Internal_RegInfo reginfo;
  16543. if (option.size < (sizeof (Elf_External_Options)
  16544. + sizeof (Elf64_External_RegInfo)))
  16545. {
  16546. printf (_("<corrupt>\n"));
  16547. error (_("Truncated MIPS REGINFO option\n"));
  16548. cnt = 0;
  16549. break;
  16550. }
  16551. ereg = (Elf64_External_RegInfo *) (eoption + 1);
  16552. reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
  16553. reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
  16554. reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
  16555. reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
  16556. reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
  16557. reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
  16558. printf ("GPR %08" PRIx32 " GP 0x%" PRIx64 "\n",
  16559. reginfo.ri_gprmask, reginfo.ri_gp_value);
  16560. printf (" "
  16561. " CPR0 %08" PRIx32 " CPR1 %08" PRIx32
  16562. " CPR2 %08" PRIx32 " CPR3 %08" PRIx32 "\n",
  16563. reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
  16564. reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
  16565. }
  16566. offset += option.size;
  16567. continue;
  16568. case ODK_EXCEPTIONS:
  16569. fputs (" EXCEPTIONS fpe_min(", stdout);
  16570. process_mips_fpe_exception (option.info & OEX_FPU_MIN);
  16571. fputs (") fpe_max(", stdout);
  16572. process_mips_fpe_exception ((option.info & OEX_FPU_MAX) >> 8);
  16573. fputs (")", stdout);
  16574. if (option.info & OEX_PAGE0)
  16575. fputs (" PAGE0", stdout);
  16576. if (option.info & OEX_SMM)
  16577. fputs (" SMM", stdout);
  16578. if (option.info & OEX_FPDBUG)
  16579. fputs (" FPDBUG", stdout);
  16580. if (option.info & OEX_DISMISS)
  16581. fputs (" DISMISS", stdout);
  16582. break;
  16583. case ODK_PAD:
  16584. fputs (" PAD ", stdout);
  16585. if (option.info & OPAD_PREFIX)
  16586. fputs (" PREFIX", stdout);
  16587. if (option.info & OPAD_POSTFIX)
  16588. fputs (" POSTFIX", stdout);
  16589. if (option.info & OPAD_SYMBOL)
  16590. fputs (" SYMBOL", stdout);
  16591. break;
  16592. case ODK_HWPATCH:
  16593. fputs (" HWPATCH ", stdout);
  16594. if (option.info & OHW_R4KEOP)
  16595. fputs (" R4KEOP", stdout);
  16596. if (option.info & OHW_R8KPFETCH)
  16597. fputs (" R8KPFETCH", stdout);
  16598. if (option.info & OHW_R5KEOP)
  16599. fputs (" R5KEOP", stdout);
  16600. if (option.info & OHW_R5KCVTL)
  16601. fputs (" R5KCVTL", stdout);
  16602. break;
  16603. case ODK_FILL:
  16604. fputs (" FILL ", stdout);
  16605. /* XXX Print content of info word? */
  16606. break;
  16607. case ODK_TAGS:
  16608. fputs (" TAGS ", stdout);
  16609. /* XXX Print content of info word? */
  16610. break;
  16611. case ODK_HWAND:
  16612. fputs (" HWAND ", stdout);
  16613. if (option.info & OHWA0_R4KEOP_CHECKED)
  16614. fputs (" R4KEOP_CHECKED", stdout);
  16615. if (option.info & OHWA0_R4KEOP_CLEAN)
  16616. fputs (" R4KEOP_CLEAN", stdout);
  16617. break;
  16618. case ODK_HWOR:
  16619. fputs (" HWOR ", stdout);
  16620. if (option.info & OHWA0_R4KEOP_CHECKED)
  16621. fputs (" R4KEOP_CHECKED", stdout);
  16622. if (option.info & OHWA0_R4KEOP_CLEAN)
  16623. fputs (" R4KEOP_CLEAN", stdout);
  16624. break;
  16625. case ODK_GP_GROUP:
  16626. printf (" GP_GROUP %#06x self-contained %#06x",
  16627. option.info & OGP_GROUP,
  16628. (option.info & OGP_SELF) >> 16);
  16629. break;
  16630. case ODK_IDENT:
  16631. printf (" IDENT %#06x self-contained %#06x",
  16632. option.info & OGP_GROUP,
  16633. (option.info & OGP_SELF) >> 16);
  16634. break;
  16635. default:
  16636. /* This shouldn't happen. */
  16637. printf (" %3d ??? %" PRId16 " %" PRIx32,
  16638. option.kind, option.section, option.info);
  16639. break;
  16640. }
  16641. len = sizeof (* eopt);
  16642. while (len < option.size)
  16643. {
  16644. unsigned char datum = *((unsigned char *) eoption + len);
  16645. if (ISPRINT (datum))
  16646. printf ("%c", datum);
  16647. else
  16648. printf ("\\%03o", datum);
  16649. len ++;
  16650. }
  16651. fputs ("\n", stdout);
  16652. offset += option.size;
  16653. }
  16654. free (eopt);
  16655. }
  16656. else
  16657. res = false;
  16658. }
  16659. if (conflicts_offset != 0 && conflictsno != 0)
  16660. {
  16661. Elf32_Conflict * iconf;
  16662. size_t cnt;
  16663. if (filedata->dynamic_symbols == NULL)
  16664. {
  16665. error (_("conflict list found without a dynamic symbol table\n"));
  16666. return false;
  16667. }
  16668. /* PR 21345 - print a slightly more helpful error message
  16669. if we are sure that the cmalloc will fail. */
  16670. if (conflictsno > filedata->file_size / sizeof (* iconf))
  16671. {
  16672. error (_("Overlarge number of conflicts detected: %lx\n"),
  16673. (long) conflictsno);
  16674. return false;
  16675. }
  16676. iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf));
  16677. if (iconf == NULL)
  16678. {
  16679. error (_("Out of memory allocating space for dynamic conflicts\n"));
  16680. return false;
  16681. }
  16682. if (is_32bit_elf)
  16683. {
  16684. Elf32_External_Conflict * econf32;
  16685. econf32 = (Elf32_External_Conflict *)
  16686. get_data (NULL, filedata, conflicts_offset,
  16687. sizeof (*econf32), conflictsno, _("conflict"));
  16688. if (!econf32)
  16689. {
  16690. free (iconf);
  16691. return false;
  16692. }
  16693. for (cnt = 0; cnt < conflictsno; ++cnt)
  16694. iconf[cnt] = BYTE_GET (econf32[cnt]);
  16695. free (econf32);
  16696. }
  16697. else
  16698. {
  16699. Elf64_External_Conflict * econf64;
  16700. econf64 = (Elf64_External_Conflict *)
  16701. get_data (NULL, filedata, conflicts_offset,
  16702. sizeof (*econf64), conflictsno, _("conflict"));
  16703. if (!econf64)
  16704. {
  16705. free (iconf);
  16706. return false;
  16707. }
  16708. for (cnt = 0; cnt < conflictsno; ++cnt)
  16709. iconf[cnt] = BYTE_GET (econf64[cnt]);
  16710. free (econf64);
  16711. }
  16712. printf (ngettext ("\nSection '.conflict' contains %lu entry:\n",
  16713. "\nSection '.conflict' contains %lu entries:\n",
  16714. (unsigned long) conflictsno),
  16715. (unsigned long) conflictsno);
  16716. puts (_(" Num: Index Value Name"));
  16717. for (cnt = 0; cnt < conflictsno; ++cnt)
  16718. {
  16719. printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
  16720. if (iconf[cnt] >= filedata->num_dynamic_syms)
  16721. printf (_("<corrupt symbol index>"));
  16722. else
  16723. {
  16724. Elf_Internal_Sym * psym;
  16725. psym = & filedata->dynamic_symbols[iconf[cnt]];
  16726. print_vma (psym->st_value, FULL_HEX);
  16727. putchar (' ');
  16728. if (valid_dynamic_name (filedata, psym->st_name))
  16729. print_symbol (25, get_dynamic_name (filedata, psym->st_name));
  16730. else
  16731. printf (_("<corrupt: %14ld>"), psym->st_name);
  16732. }
  16733. putchar ('\n');
  16734. }
  16735. free (iconf);
  16736. }
  16737. if (pltgot != 0 && local_gotno != 0)
  16738. {
  16739. bfd_vma ent, local_end, global_end;
  16740. size_t i, offset;
  16741. unsigned char * data;
  16742. unsigned char * data_end;
  16743. int addr_size;
  16744. ent = pltgot;
  16745. addr_size = (is_32bit_elf ? 4 : 8);
  16746. local_end = pltgot + local_gotno * addr_size;
  16747. /* PR binutils/17533 file: 012-111227-0.004 */
  16748. if (symtabno < gotsym)
  16749. {
  16750. error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
  16751. (unsigned long) gotsym, (unsigned long) symtabno);
  16752. return false;
  16753. }
  16754. global_end = local_end + (symtabno - gotsym) * addr_size;
  16755. /* PR 17531: file: 54c91a34. */
  16756. if (global_end < local_end)
  16757. {
  16758. error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno);
  16759. return false;
  16760. }
  16761. offset = offset_from_vma (filedata, pltgot, global_end - pltgot);
  16762. data = (unsigned char *) get_data (NULL, filedata, offset,
  16763. global_end - pltgot, 1,
  16764. _("Global Offset Table data"));
  16765. /* PR 12855: Null data is handled gracefully throughout. */
  16766. data_end = data + (global_end - pltgot);
  16767. printf (_("\nPrimary GOT:\n"));
  16768. printf (_(" Canonical gp value: "));
  16769. print_vma (pltgot + 0x7ff0, LONG_HEX);
  16770. printf ("\n\n");
  16771. printf (_(" Reserved entries:\n"));
  16772. printf (_(" %*s %10s %*s Purpose\n"),
  16773. addr_size * 2, _("Address"), _("Access"),
  16774. addr_size * 2, _("Initial"));
  16775. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  16776. printf (_(" Lazy resolver\n"));
  16777. if (ent == (bfd_vma) -1)
  16778. goto got_print_fail;
  16779. /* Check for the MSB of GOT[1] being set, denoting a GNU object.
  16780. This entry will be used by some runtime loaders, to store the
  16781. module pointer. Otherwise this is an ordinary local entry.
  16782. PR 21344: Check for the entry being fully available before
  16783. fetching it. */
  16784. if (data
  16785. && data + ent - pltgot + addr_size <= data_end
  16786. && (byte_get (data + ent - pltgot, addr_size)
  16787. >> (addr_size * 8 - 1)) != 0)
  16788. {
  16789. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  16790. printf (_(" Module pointer (GNU extension)\n"));
  16791. if (ent == (bfd_vma) -1)
  16792. goto got_print_fail;
  16793. }
  16794. printf ("\n");
  16795. if (data != NULL && ent < local_end)
  16796. {
  16797. printf (_(" Local entries:\n"));
  16798. printf (" %*s %10s %*s\n",
  16799. addr_size * 2, _("Address"), _("Access"),
  16800. addr_size * 2, _("Initial"));
  16801. while (ent < local_end)
  16802. {
  16803. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  16804. printf ("\n");
  16805. if (ent == (bfd_vma) -1)
  16806. goto got_print_fail;
  16807. }
  16808. printf ("\n");
  16809. }
  16810. if (data != NULL && gotsym < symtabno)
  16811. {
  16812. int sym_width;
  16813. printf (_(" Global entries:\n"));
  16814. printf (" %*s %10s %*s %*s %-7s %3s %s\n",
  16815. addr_size * 2, _("Address"),
  16816. _("Access"),
  16817. addr_size * 2, _("Initial"),
  16818. addr_size * 2, _("Sym.Val."),
  16819. _("Type"),
  16820. /* Note for translators: "Ndx" = abbreviated form of "Index". */
  16821. _("Ndx"), _("Name"));
  16822. sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
  16823. for (i = gotsym; i < symtabno; i++)
  16824. {
  16825. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  16826. printf (" ");
  16827. if (filedata->dynamic_symbols == NULL)
  16828. printf (_("<no dynamic symbols>"));
  16829. else if (i < filedata->num_dynamic_syms)
  16830. {
  16831. Elf_Internal_Sym * psym = filedata->dynamic_symbols + i;
  16832. print_vma (psym->st_value, LONG_HEX);
  16833. printf (" %-7s %3s ",
  16834. get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
  16835. get_symbol_index_type (filedata, psym->st_shndx));
  16836. if (valid_dynamic_name (filedata, psym->st_name))
  16837. print_symbol (sym_width,
  16838. get_dynamic_name (filedata, psym->st_name));
  16839. else
  16840. printf (_("<corrupt: %14ld>"), psym->st_name);
  16841. }
  16842. else
  16843. printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
  16844. (unsigned long) i);
  16845. printf ("\n");
  16846. if (ent == (bfd_vma) -1)
  16847. break;
  16848. }
  16849. printf ("\n");
  16850. }
  16851. got_print_fail:
  16852. free (data);
  16853. }
  16854. if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
  16855. {
  16856. bfd_vma ent, end;
  16857. size_t offset, rel_offset;
  16858. unsigned long count, i;
  16859. unsigned char * data;
  16860. int addr_size, sym_width;
  16861. Elf_Internal_Rela * rels;
  16862. rel_offset = offset_from_vma (filedata, jmprel, pltrelsz);
  16863. if (pltrel == DT_RELA)
  16864. {
  16865. if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
  16866. return false;
  16867. }
  16868. else
  16869. {
  16870. if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count))
  16871. return false;
  16872. }
  16873. ent = mips_pltgot;
  16874. addr_size = (is_32bit_elf ? 4 : 8);
  16875. end = mips_pltgot + (2 + count) * addr_size;
  16876. offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot);
  16877. data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot,
  16878. 1, _("Procedure Linkage Table data"));
  16879. if (data == NULL)
  16880. {
  16881. free (rels);
  16882. return false;
  16883. }
  16884. printf ("\nPLT GOT:\n\n");
  16885. printf (_(" Reserved entries:\n"));
  16886. printf (_(" %*s %*s Purpose\n"),
  16887. addr_size * 2, _("Address"), addr_size * 2, _("Initial"));
  16888. ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
  16889. printf (_(" PLT lazy resolver\n"));
  16890. ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
  16891. printf (_(" Module pointer\n"));
  16892. printf ("\n");
  16893. printf (_(" Entries:\n"));
  16894. printf (" %*s %*s %*s %-7s %3s %s\n",
  16895. addr_size * 2, _("Address"),
  16896. addr_size * 2, _("Initial"),
  16897. addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
  16898. sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
  16899. for (i = 0; i < count; i++)
  16900. {
  16901. unsigned long idx = get_reloc_symindex (rels[i].r_info);
  16902. ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
  16903. printf (" ");
  16904. if (idx >= filedata->num_dynamic_syms)
  16905. printf (_("<corrupt symbol index: %lu>"), idx);
  16906. else
  16907. {
  16908. Elf_Internal_Sym * psym = filedata->dynamic_symbols + idx;
  16909. print_vma (psym->st_value, LONG_HEX);
  16910. printf (" %-7s %3s ",
  16911. get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)),
  16912. get_symbol_index_type (filedata, psym->st_shndx));
  16913. if (valid_dynamic_name (filedata, psym->st_name))
  16914. print_symbol (sym_width,
  16915. get_dynamic_name (filedata, psym->st_name));
  16916. else
  16917. printf (_("<corrupt: %14ld>"), psym->st_name);
  16918. }
  16919. printf ("\n");
  16920. }
  16921. printf ("\n");
  16922. free (data);
  16923. free (rels);
  16924. }
  16925. return res;
  16926. }
  16927. static bool
  16928. process_nds32_specific (Filedata * filedata)
  16929. {
  16930. Elf_Internal_Shdr *sect = NULL;
  16931. sect = find_section (filedata, ".nds32_e_flags");
  16932. if (sect != NULL && sect->sh_size >= 4)
  16933. {
  16934. unsigned char *buf;
  16935. unsigned int flag;
  16936. printf ("\nNDS32 elf flags section:\n");
  16937. buf = get_data (NULL, filedata, sect->sh_offset, 1, 4,
  16938. _("NDS32 elf flags section"));
  16939. if (buf == NULL)
  16940. return false;
  16941. flag = byte_get (buf, 4);
  16942. free (buf);
  16943. switch (flag & 0x3)
  16944. {
  16945. case 0:
  16946. printf ("(VEC_SIZE):\tNo entry.\n");
  16947. break;
  16948. case 1:
  16949. printf ("(VEC_SIZE):\t4 bytes\n");
  16950. break;
  16951. case 2:
  16952. printf ("(VEC_SIZE):\t16 bytes\n");
  16953. break;
  16954. case 3:
  16955. printf ("(VEC_SIZE):\treserved\n");
  16956. break;
  16957. }
  16958. }
  16959. return true;
  16960. }
  16961. static bool
  16962. process_gnu_liblist (Filedata * filedata)
  16963. {
  16964. Elf_Internal_Shdr * section;
  16965. Elf_Internal_Shdr * string_sec;
  16966. Elf32_External_Lib * elib;
  16967. char * strtab;
  16968. size_t strtab_size;
  16969. size_t cnt;
  16970. unsigned long num_liblist;
  16971. unsigned i;
  16972. bool res = true;
  16973. if (! do_arch)
  16974. return true;
  16975. for (i = 0, section = filedata->section_headers;
  16976. i < filedata->file_header.e_shnum;
  16977. i++, section++)
  16978. {
  16979. switch (section->sh_type)
  16980. {
  16981. case SHT_GNU_LIBLIST:
  16982. if (section->sh_link >= filedata->file_header.e_shnum)
  16983. break;
  16984. elib = (Elf32_External_Lib *)
  16985. get_data (NULL, filedata, section->sh_offset, 1, section->sh_size,
  16986. _("liblist section data"));
  16987. if (elib == NULL)
  16988. {
  16989. res = false;
  16990. break;
  16991. }
  16992. string_sec = filedata->section_headers + section->sh_link;
  16993. strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1,
  16994. string_sec->sh_size,
  16995. _("liblist string table"));
  16996. if (strtab == NULL
  16997. || section->sh_entsize != sizeof (Elf32_External_Lib))
  16998. {
  16999. free (elib);
  17000. free (strtab);
  17001. res = false;
  17002. break;
  17003. }
  17004. strtab_size = string_sec->sh_size;
  17005. num_liblist = section->sh_size / sizeof (Elf32_External_Lib);
  17006. printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n",
  17007. "\nLibrary list section '%s' contains %lu entries:\n",
  17008. num_liblist),
  17009. printable_section_name (filedata, section),
  17010. num_liblist);
  17011. puts (_(" Library Time Stamp Checksum Version Flags"));
  17012. for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
  17013. ++cnt)
  17014. {
  17015. Elf32_Lib liblist;
  17016. time_t atime;
  17017. char timebuf[128];
  17018. struct tm * tmp;
  17019. liblist.l_name = BYTE_GET (elib[cnt].l_name);
  17020. atime = BYTE_GET (elib[cnt].l_time_stamp);
  17021. liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
  17022. liblist.l_version = BYTE_GET (elib[cnt].l_version);
  17023. liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
  17024. tmp = gmtime (&atime);
  17025. snprintf (timebuf, sizeof (timebuf),
  17026. "%04u-%02u-%02uT%02u:%02u:%02u",
  17027. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  17028. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  17029. printf ("%3lu: ", (unsigned long) cnt);
  17030. if (do_wide)
  17031. printf ("%-20s", liblist.l_name < strtab_size
  17032. ? strtab + liblist.l_name : _("<corrupt>"));
  17033. else
  17034. printf ("%-20.20s", liblist.l_name < strtab_size
  17035. ? strtab + liblist.l_name : _("<corrupt>"));
  17036. printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
  17037. liblist.l_version, liblist.l_flags);
  17038. }
  17039. free (elib);
  17040. free (strtab);
  17041. }
  17042. }
  17043. return res;
  17044. }
  17045. static const char *
  17046. get_note_type (Filedata * filedata, unsigned e_type)
  17047. {
  17048. static char buff[64];
  17049. if (filedata->file_header.e_type == ET_CORE)
  17050. switch (e_type)
  17051. {
  17052. case NT_AUXV:
  17053. return _("NT_AUXV (auxiliary vector)");
  17054. case NT_PRSTATUS:
  17055. return _("NT_PRSTATUS (prstatus structure)");
  17056. case NT_FPREGSET:
  17057. return _("NT_FPREGSET (floating point registers)");
  17058. case NT_PRPSINFO:
  17059. return _("NT_PRPSINFO (prpsinfo structure)");
  17060. case NT_TASKSTRUCT:
  17061. return _("NT_TASKSTRUCT (task structure)");
  17062. case NT_GDB_TDESC:
  17063. return _("NT_GDB_TDESC (GDB XML target description)");
  17064. case NT_PRXFPREG:
  17065. return _("NT_PRXFPREG (user_xfpregs structure)");
  17066. case NT_PPC_VMX:
  17067. return _("NT_PPC_VMX (ppc Altivec registers)");
  17068. case NT_PPC_VSX:
  17069. return _("NT_PPC_VSX (ppc VSX registers)");
  17070. case NT_PPC_TAR:
  17071. return _("NT_PPC_TAR (ppc TAR register)");
  17072. case NT_PPC_PPR:
  17073. return _("NT_PPC_PPR (ppc PPR register)");
  17074. case NT_PPC_DSCR:
  17075. return _("NT_PPC_DSCR (ppc DSCR register)");
  17076. case NT_PPC_EBB:
  17077. return _("NT_PPC_EBB (ppc EBB registers)");
  17078. case NT_PPC_PMU:
  17079. return _("NT_PPC_PMU (ppc PMU registers)");
  17080. case NT_PPC_TM_CGPR:
  17081. return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)");
  17082. case NT_PPC_TM_CFPR:
  17083. return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)");
  17084. case NT_PPC_TM_CVMX:
  17085. return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
  17086. case NT_PPC_TM_CVSX:
  17087. return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
  17088. case NT_PPC_TM_SPR:
  17089. return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
  17090. case NT_PPC_TM_CTAR:
  17091. return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)");
  17092. case NT_PPC_TM_CPPR:
  17093. return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)");
  17094. case NT_PPC_TM_CDSCR:
  17095. return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)");
  17096. case NT_386_TLS:
  17097. return _("NT_386_TLS (x86 TLS information)");
  17098. case NT_386_IOPERM:
  17099. return _("NT_386_IOPERM (x86 I/O permissions)");
  17100. case NT_X86_XSTATE:
  17101. return _("NT_X86_XSTATE (x86 XSAVE extended state)");
  17102. case NT_X86_CET:
  17103. return _("NT_X86_CET (x86 CET state)");
  17104. case NT_S390_HIGH_GPRS:
  17105. return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
  17106. case NT_S390_TIMER:
  17107. return _("NT_S390_TIMER (s390 timer register)");
  17108. case NT_S390_TODCMP:
  17109. return _("NT_S390_TODCMP (s390 TOD comparator register)");
  17110. case NT_S390_TODPREG:
  17111. return _("NT_S390_TODPREG (s390 TOD programmable register)");
  17112. case NT_S390_CTRS:
  17113. return _("NT_S390_CTRS (s390 control registers)");
  17114. case NT_S390_PREFIX:
  17115. return _("NT_S390_PREFIX (s390 prefix register)");
  17116. case NT_S390_LAST_BREAK:
  17117. return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
  17118. case NT_S390_SYSTEM_CALL:
  17119. return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
  17120. case NT_S390_TDB:
  17121. return _("NT_S390_TDB (s390 transaction diagnostic block)");
  17122. case NT_S390_VXRS_LOW:
  17123. return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
  17124. case NT_S390_VXRS_HIGH:
  17125. return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
  17126. case NT_S390_GS_CB:
  17127. return _("NT_S390_GS_CB (s390 guarded-storage registers)");
  17128. case NT_S390_GS_BC:
  17129. return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
  17130. case NT_ARM_VFP:
  17131. return _("NT_ARM_VFP (arm VFP registers)");
  17132. case NT_ARM_TLS:
  17133. return _("NT_ARM_TLS (AArch TLS registers)");
  17134. case NT_ARM_HW_BREAK:
  17135. return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
  17136. case NT_ARM_HW_WATCH:
  17137. return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
  17138. case NT_ARM_SYSTEM_CALL:
  17139. return _("NT_ARM_SYSTEM_CALL (AArch system call number)");
  17140. case NT_ARM_SVE:
  17141. return _("NT_ARM_SVE (AArch SVE registers)");
  17142. case NT_ARM_PAC_MASK:
  17143. return _("NT_ARM_PAC_MASK (AArch pointer authentication code masks)");
  17144. case NT_ARM_PACA_KEYS:
  17145. return _("NT_ARM_PACA_KEYS (ARM pointer authentication address keys)");
  17146. case NT_ARM_PACG_KEYS:
  17147. return _("NT_ARM_PACG_KEYS (ARM pointer authentication generic keys)");
  17148. case NT_ARM_TAGGED_ADDR_CTRL:
  17149. return _("NT_ARM_TAGGED_ADDR_CTRL (AArch tagged address control)");
  17150. case NT_ARM_PAC_ENABLED_KEYS:
  17151. return _("NT_ARM_PAC_ENABLED_KEYS (AArch64 pointer authentication enabled keys)");
  17152. case NT_ARC_V2:
  17153. return _("NT_ARC_V2 (ARC HS accumulator/extra registers)");
  17154. case NT_RISCV_CSR:
  17155. return _("NT_RISCV_CSR (RISC-V control and status registers)");
  17156. case NT_PSTATUS:
  17157. return _("NT_PSTATUS (pstatus structure)");
  17158. case NT_FPREGS:
  17159. return _("NT_FPREGS (floating point registers)");
  17160. case NT_PSINFO:
  17161. return _("NT_PSINFO (psinfo structure)");
  17162. case NT_LWPSTATUS:
  17163. return _("NT_LWPSTATUS (lwpstatus_t structure)");
  17164. case NT_LWPSINFO:
  17165. return _("NT_LWPSINFO (lwpsinfo_t structure)");
  17166. case NT_WIN32PSTATUS:
  17167. return _("NT_WIN32PSTATUS (win32_pstatus structure)");
  17168. case NT_SIGINFO:
  17169. return _("NT_SIGINFO (siginfo_t data)");
  17170. case NT_FILE:
  17171. return _("NT_FILE (mapped files)");
  17172. default:
  17173. break;
  17174. }
  17175. else
  17176. switch (e_type)
  17177. {
  17178. case NT_VERSION:
  17179. return _("NT_VERSION (version)");
  17180. case NT_ARCH:
  17181. return _("NT_ARCH (architecture)");
  17182. case NT_GNU_BUILD_ATTRIBUTE_OPEN:
  17183. return _("OPEN");
  17184. case NT_GNU_BUILD_ATTRIBUTE_FUNC:
  17185. return _("func");
  17186. case NT_GO_BUILDID:
  17187. return _("GO BUILDID");
  17188. case FDO_PACKAGING_METADATA:
  17189. return _("FDO_PACKAGING_METADATA");
  17190. default:
  17191. break;
  17192. }
  17193. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
  17194. return buff;
  17195. }
  17196. static bool
  17197. print_core_note (Elf_Internal_Note *pnote)
  17198. {
  17199. unsigned int addr_size = is_32bit_elf ? 4 : 8;
  17200. bfd_vma count, page_size;
  17201. unsigned char *descdata, *filenames, *descend;
  17202. if (pnote->type != NT_FILE)
  17203. {
  17204. if (do_wide)
  17205. printf ("\n");
  17206. return true;
  17207. }
  17208. #ifndef BFD64
  17209. if (!is_32bit_elf)
  17210. {
  17211. printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
  17212. /* Still "successful". */
  17213. return true;
  17214. }
  17215. #endif
  17216. if (pnote->descsz < 2 * addr_size)
  17217. {
  17218. error (_(" Malformed note - too short for header\n"));
  17219. return false;
  17220. }
  17221. descdata = (unsigned char *) pnote->descdata;
  17222. descend = descdata + pnote->descsz;
  17223. if (descdata[pnote->descsz - 1] != '\0')
  17224. {
  17225. error (_(" Malformed note - does not end with \\0\n"));
  17226. return false;
  17227. }
  17228. count = byte_get (descdata, addr_size);
  17229. descdata += addr_size;
  17230. page_size = byte_get (descdata, addr_size);
  17231. descdata += addr_size;
  17232. if (count > ((bfd_vma) -1 - 2 * addr_size) / (3 * addr_size)
  17233. || pnote->descsz < 2 * addr_size + count * 3 * addr_size)
  17234. {
  17235. error (_(" Malformed note - too short for supplied file count\n"));
  17236. return false;
  17237. }
  17238. printf (_(" Page size: "));
  17239. print_vma (page_size, DEC);
  17240. printf ("\n");
  17241. printf (_(" %*s%*s%*s\n"),
  17242. (int) (2 + 2 * addr_size), _("Start"),
  17243. (int) (4 + 2 * addr_size), _("End"),
  17244. (int) (4 + 2 * addr_size), _("Page Offset"));
  17245. filenames = descdata + count * 3 * addr_size;
  17246. while (count-- > 0)
  17247. {
  17248. bfd_vma start, end, file_ofs;
  17249. if (filenames == descend)
  17250. {
  17251. error (_(" Malformed note - filenames end too early\n"));
  17252. return false;
  17253. }
  17254. start = byte_get (descdata, addr_size);
  17255. descdata += addr_size;
  17256. end = byte_get (descdata, addr_size);
  17257. descdata += addr_size;
  17258. file_ofs = byte_get (descdata, addr_size);
  17259. descdata += addr_size;
  17260. printf (" ");
  17261. print_vma (start, FULL_HEX);
  17262. printf (" ");
  17263. print_vma (end, FULL_HEX);
  17264. printf (" ");
  17265. print_vma (file_ofs, FULL_HEX);
  17266. printf ("\n %s\n", filenames);
  17267. filenames += 1 + strlen ((char *) filenames);
  17268. }
  17269. return true;
  17270. }
  17271. static const char *
  17272. get_gnu_elf_note_type (unsigned e_type)
  17273. {
  17274. /* NB/ Keep this switch statement in sync with print_gnu_note (). */
  17275. switch (e_type)
  17276. {
  17277. case NT_GNU_ABI_TAG:
  17278. return _("NT_GNU_ABI_TAG (ABI version tag)");
  17279. case NT_GNU_HWCAP:
  17280. return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
  17281. case NT_GNU_BUILD_ID:
  17282. return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
  17283. case NT_GNU_GOLD_VERSION:
  17284. return _("NT_GNU_GOLD_VERSION (gold version)");
  17285. case NT_GNU_PROPERTY_TYPE_0:
  17286. return _("NT_GNU_PROPERTY_TYPE_0");
  17287. case NT_GNU_BUILD_ATTRIBUTE_OPEN:
  17288. return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
  17289. case NT_GNU_BUILD_ATTRIBUTE_FUNC:
  17290. return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
  17291. default:
  17292. {
  17293. static char buff[64];
  17294. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
  17295. return buff;
  17296. }
  17297. }
  17298. }
  17299. static void
  17300. decode_x86_compat_isa (unsigned int bitmask)
  17301. {
  17302. while (bitmask)
  17303. {
  17304. unsigned int bit = bitmask & (- bitmask);
  17305. bitmask &= ~ bit;
  17306. switch (bit)
  17307. {
  17308. case GNU_PROPERTY_X86_COMPAT_ISA_1_486:
  17309. printf ("i486");
  17310. break;
  17311. case GNU_PROPERTY_X86_COMPAT_ISA_1_586:
  17312. printf ("586");
  17313. break;
  17314. case GNU_PROPERTY_X86_COMPAT_ISA_1_686:
  17315. printf ("686");
  17316. break;
  17317. case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE:
  17318. printf ("SSE");
  17319. break;
  17320. case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2:
  17321. printf ("SSE2");
  17322. break;
  17323. case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3:
  17324. printf ("SSE3");
  17325. break;
  17326. case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3:
  17327. printf ("SSSE3");
  17328. break;
  17329. case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1:
  17330. printf ("SSE4_1");
  17331. break;
  17332. case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2:
  17333. printf ("SSE4_2");
  17334. break;
  17335. case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX:
  17336. printf ("AVX");
  17337. break;
  17338. case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2:
  17339. printf ("AVX2");
  17340. break;
  17341. case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F:
  17342. printf ("AVX512F");
  17343. break;
  17344. case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD:
  17345. printf ("AVX512CD");
  17346. break;
  17347. case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER:
  17348. printf ("AVX512ER");
  17349. break;
  17350. case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF:
  17351. printf ("AVX512PF");
  17352. break;
  17353. case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL:
  17354. printf ("AVX512VL");
  17355. break;
  17356. case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ:
  17357. printf ("AVX512DQ");
  17358. break;
  17359. case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW:
  17360. printf ("AVX512BW");
  17361. break;
  17362. default:
  17363. printf (_("<unknown: %x>"), bit);
  17364. break;
  17365. }
  17366. if (bitmask)
  17367. printf (", ");
  17368. }
  17369. }
  17370. static void
  17371. decode_x86_compat_2_isa (unsigned int bitmask)
  17372. {
  17373. if (!bitmask)
  17374. {
  17375. printf (_("<None>"));
  17376. return;
  17377. }
  17378. while (bitmask)
  17379. {
  17380. unsigned int bit = bitmask & (- bitmask);
  17381. bitmask &= ~ bit;
  17382. switch (bit)
  17383. {
  17384. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_CMOV:
  17385. printf ("CMOV");
  17386. break;
  17387. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE:
  17388. printf ("SSE");
  17389. break;
  17390. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE2:
  17391. printf ("SSE2");
  17392. break;
  17393. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE3:
  17394. printf ("SSE3");
  17395. break;
  17396. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSSE3:
  17397. printf ("SSSE3");
  17398. break;
  17399. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_1:
  17400. printf ("SSE4_1");
  17401. break;
  17402. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_SSE4_2:
  17403. printf ("SSE4_2");
  17404. break;
  17405. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX:
  17406. printf ("AVX");
  17407. break;
  17408. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX2:
  17409. printf ("AVX2");
  17410. break;
  17411. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_FMA:
  17412. printf ("FMA");
  17413. break;
  17414. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512F:
  17415. printf ("AVX512F");
  17416. break;
  17417. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512CD:
  17418. printf ("AVX512CD");
  17419. break;
  17420. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512ER:
  17421. printf ("AVX512ER");
  17422. break;
  17423. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512PF:
  17424. printf ("AVX512PF");
  17425. break;
  17426. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512VL:
  17427. printf ("AVX512VL");
  17428. break;
  17429. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512DQ:
  17430. printf ("AVX512DQ");
  17431. break;
  17432. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512BW:
  17433. printf ("AVX512BW");
  17434. break;
  17435. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4FMAPS:
  17436. printf ("AVX512_4FMAPS");
  17437. break;
  17438. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_4VNNIW:
  17439. printf ("AVX512_4VNNIW");
  17440. break;
  17441. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BITALG:
  17442. printf ("AVX512_BITALG");
  17443. break;
  17444. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_IFMA:
  17445. printf ("AVX512_IFMA");
  17446. break;
  17447. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI:
  17448. printf ("AVX512_VBMI");
  17449. break;
  17450. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VBMI2:
  17451. printf ("AVX512_VBMI2");
  17452. break;
  17453. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_VNNI:
  17454. printf ("AVX512_VNNI");
  17455. break;
  17456. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_AVX512_BF16:
  17457. printf ("AVX512_BF16");
  17458. break;
  17459. default:
  17460. printf (_("<unknown: %x>"), bit);
  17461. break;
  17462. }
  17463. if (bitmask)
  17464. printf (", ");
  17465. }
  17466. }
  17467. static const char *
  17468. get_amdgpu_elf_note_type (unsigned int e_type)
  17469. {
  17470. switch (e_type)
  17471. {
  17472. case NT_AMDGPU_METADATA:
  17473. return _("NT_AMDGPU_METADATA (code object metadata)");
  17474. default:
  17475. {
  17476. static char buf[64];
  17477. snprintf (buf, sizeof (buf), _("Unknown note type: (0x%08x)"), e_type);
  17478. return buf;
  17479. }
  17480. }
  17481. }
  17482. static void
  17483. decode_x86_isa (unsigned int bitmask)
  17484. {
  17485. while (bitmask)
  17486. {
  17487. unsigned int bit = bitmask & (- bitmask);
  17488. bitmask &= ~ bit;
  17489. switch (bit)
  17490. {
  17491. case GNU_PROPERTY_X86_ISA_1_BASELINE:
  17492. printf ("x86-64-baseline");
  17493. break;
  17494. case GNU_PROPERTY_X86_ISA_1_V2:
  17495. printf ("x86-64-v2");
  17496. break;
  17497. case GNU_PROPERTY_X86_ISA_1_V3:
  17498. printf ("x86-64-v3");
  17499. break;
  17500. case GNU_PROPERTY_X86_ISA_1_V4:
  17501. printf ("x86-64-v4");
  17502. break;
  17503. default:
  17504. printf (_("<unknown: %x>"), bit);
  17505. break;
  17506. }
  17507. if (bitmask)
  17508. printf (", ");
  17509. }
  17510. }
  17511. static void
  17512. decode_x86_feature_1 (unsigned int bitmask)
  17513. {
  17514. if (!bitmask)
  17515. {
  17516. printf (_("<None>"));
  17517. return;
  17518. }
  17519. while (bitmask)
  17520. {
  17521. unsigned int bit = bitmask & (- bitmask);
  17522. bitmask &= ~ bit;
  17523. switch (bit)
  17524. {
  17525. case GNU_PROPERTY_X86_FEATURE_1_IBT:
  17526. printf ("IBT");
  17527. break;
  17528. case GNU_PROPERTY_X86_FEATURE_1_SHSTK:
  17529. printf ("SHSTK");
  17530. break;
  17531. case GNU_PROPERTY_X86_FEATURE_1_LAM_U48:
  17532. printf ("LAM_U48");
  17533. break;
  17534. case GNU_PROPERTY_X86_FEATURE_1_LAM_U57:
  17535. printf ("LAM_U57");
  17536. break;
  17537. default:
  17538. printf (_("<unknown: %x>"), bit);
  17539. break;
  17540. }
  17541. if (bitmask)
  17542. printf (", ");
  17543. }
  17544. }
  17545. static void
  17546. decode_x86_feature_2 (unsigned int bitmask)
  17547. {
  17548. if (!bitmask)
  17549. {
  17550. printf (_("<None>"));
  17551. return;
  17552. }
  17553. while (bitmask)
  17554. {
  17555. unsigned int bit = bitmask & (- bitmask);
  17556. bitmask &= ~ bit;
  17557. switch (bit)
  17558. {
  17559. case GNU_PROPERTY_X86_FEATURE_2_X86:
  17560. printf ("x86");
  17561. break;
  17562. case GNU_PROPERTY_X86_FEATURE_2_X87:
  17563. printf ("x87");
  17564. break;
  17565. case GNU_PROPERTY_X86_FEATURE_2_MMX:
  17566. printf ("MMX");
  17567. break;
  17568. case GNU_PROPERTY_X86_FEATURE_2_XMM:
  17569. printf ("XMM");
  17570. break;
  17571. case GNU_PROPERTY_X86_FEATURE_2_YMM:
  17572. printf ("YMM");
  17573. break;
  17574. case GNU_PROPERTY_X86_FEATURE_2_ZMM:
  17575. printf ("ZMM");
  17576. break;
  17577. case GNU_PROPERTY_X86_FEATURE_2_TMM:
  17578. printf ("TMM");
  17579. break;
  17580. case GNU_PROPERTY_X86_FEATURE_2_MASK:
  17581. printf ("MASK");
  17582. break;
  17583. case GNU_PROPERTY_X86_FEATURE_2_FXSR:
  17584. printf ("FXSR");
  17585. break;
  17586. case GNU_PROPERTY_X86_FEATURE_2_XSAVE:
  17587. printf ("XSAVE");
  17588. break;
  17589. case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT:
  17590. printf ("XSAVEOPT");
  17591. break;
  17592. case GNU_PROPERTY_X86_FEATURE_2_XSAVEC:
  17593. printf ("XSAVEC");
  17594. break;
  17595. default:
  17596. printf (_("<unknown: %x>"), bit);
  17597. break;
  17598. }
  17599. if (bitmask)
  17600. printf (", ");
  17601. }
  17602. }
  17603. static void
  17604. decode_aarch64_feature_1_and (unsigned int bitmask)
  17605. {
  17606. while (bitmask)
  17607. {
  17608. unsigned int bit = bitmask & (- bitmask);
  17609. bitmask &= ~ bit;
  17610. switch (bit)
  17611. {
  17612. case GNU_PROPERTY_AARCH64_FEATURE_1_BTI:
  17613. printf ("BTI");
  17614. break;
  17615. case GNU_PROPERTY_AARCH64_FEATURE_1_PAC:
  17616. printf ("PAC");
  17617. break;
  17618. default:
  17619. printf (_("<unknown: %x>"), bit);
  17620. break;
  17621. }
  17622. if (bitmask)
  17623. printf (", ");
  17624. }
  17625. }
  17626. static void
  17627. decode_1_needed (unsigned int bitmask)
  17628. {
  17629. while (bitmask)
  17630. {
  17631. unsigned int bit = bitmask & (- bitmask);
  17632. bitmask &= ~ bit;
  17633. switch (bit)
  17634. {
  17635. case GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS:
  17636. printf ("indirect external access");
  17637. break;
  17638. default:
  17639. printf (_("<unknown: %x>"), bit);
  17640. break;
  17641. }
  17642. if (bitmask)
  17643. printf (", ");
  17644. }
  17645. }
  17646. static void
  17647. print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote)
  17648. {
  17649. unsigned char * ptr = (unsigned char *) pnote->descdata;
  17650. unsigned char * ptr_end = ptr + pnote->descsz;
  17651. unsigned int size = is_32bit_elf ? 4 : 8;
  17652. printf (_(" Properties: "));
  17653. if (pnote->descsz < 8 || (pnote->descsz % size) != 0)
  17654. {
  17655. printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz);
  17656. return;
  17657. }
  17658. while (ptr < ptr_end)
  17659. {
  17660. unsigned int j;
  17661. unsigned int type;
  17662. unsigned int datasz;
  17663. if ((size_t) (ptr_end - ptr) < 8)
  17664. {
  17665. printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz);
  17666. break;
  17667. }
  17668. type = byte_get (ptr, 4);
  17669. datasz = byte_get (ptr + 4, 4);
  17670. ptr += 8;
  17671. if (datasz > (size_t) (ptr_end - ptr))
  17672. {
  17673. printf (_("<corrupt type (%#x) datasz: %#x>\n"),
  17674. type, datasz);
  17675. break;
  17676. }
  17677. if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC)
  17678. {
  17679. if (filedata->file_header.e_machine == EM_X86_64
  17680. || filedata->file_header.e_machine == EM_IAMCU
  17681. || filedata->file_header.e_machine == EM_386)
  17682. {
  17683. unsigned int bitmask;
  17684. if (datasz == 4)
  17685. bitmask = byte_get (ptr, 4);
  17686. else
  17687. bitmask = 0;
  17688. switch (type)
  17689. {
  17690. case GNU_PROPERTY_X86_ISA_1_USED:
  17691. if (datasz != 4)
  17692. printf (_("x86 ISA used: <corrupt length: %#x> "),
  17693. datasz);
  17694. else
  17695. {
  17696. printf ("x86 ISA used: ");
  17697. decode_x86_isa (bitmask);
  17698. }
  17699. goto next;
  17700. case GNU_PROPERTY_X86_ISA_1_NEEDED:
  17701. if (datasz != 4)
  17702. printf (_("x86 ISA needed: <corrupt length: %#x> "),
  17703. datasz);
  17704. else
  17705. {
  17706. printf ("x86 ISA needed: ");
  17707. decode_x86_isa (bitmask);
  17708. }
  17709. goto next;
  17710. case GNU_PROPERTY_X86_FEATURE_1_AND:
  17711. if (datasz != 4)
  17712. printf (_("x86 feature: <corrupt length: %#x> "),
  17713. datasz);
  17714. else
  17715. {
  17716. printf ("x86 feature: ");
  17717. decode_x86_feature_1 (bitmask);
  17718. }
  17719. goto next;
  17720. case GNU_PROPERTY_X86_FEATURE_2_USED:
  17721. if (datasz != 4)
  17722. printf (_("x86 feature used: <corrupt length: %#x> "),
  17723. datasz);
  17724. else
  17725. {
  17726. printf ("x86 feature used: ");
  17727. decode_x86_feature_2 (bitmask);
  17728. }
  17729. goto next;
  17730. case GNU_PROPERTY_X86_FEATURE_2_NEEDED:
  17731. if (datasz != 4)
  17732. printf (_("x86 feature needed: <corrupt length: %#x> "), datasz);
  17733. else
  17734. {
  17735. printf ("x86 feature needed: ");
  17736. decode_x86_feature_2 (bitmask);
  17737. }
  17738. goto next;
  17739. case GNU_PROPERTY_X86_COMPAT_ISA_1_USED:
  17740. if (datasz != 4)
  17741. printf (_("x86 ISA used: <corrupt length: %#x> "),
  17742. datasz);
  17743. else
  17744. {
  17745. printf ("x86 ISA used: ");
  17746. decode_x86_compat_isa (bitmask);
  17747. }
  17748. goto next;
  17749. case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED:
  17750. if (datasz != 4)
  17751. printf (_("x86 ISA needed: <corrupt length: %#x> "),
  17752. datasz);
  17753. else
  17754. {
  17755. printf ("x86 ISA needed: ");
  17756. decode_x86_compat_isa (bitmask);
  17757. }
  17758. goto next;
  17759. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED:
  17760. if (datasz != 4)
  17761. printf (_("x86 ISA used: <corrupt length: %#x> "),
  17762. datasz);
  17763. else
  17764. {
  17765. printf ("x86 ISA used: ");
  17766. decode_x86_compat_2_isa (bitmask);
  17767. }
  17768. goto next;
  17769. case GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED:
  17770. if (datasz != 4)
  17771. printf (_("x86 ISA needed: <corrupt length: %#x> "),
  17772. datasz);
  17773. else
  17774. {
  17775. printf ("x86 ISA needed: ");
  17776. decode_x86_compat_2_isa (bitmask);
  17777. }
  17778. goto next;
  17779. default:
  17780. break;
  17781. }
  17782. }
  17783. else if (filedata->file_header.e_machine == EM_AARCH64)
  17784. {
  17785. if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
  17786. {
  17787. printf ("AArch64 feature: ");
  17788. if (datasz != 4)
  17789. printf (_("<corrupt length: %#x> "), datasz);
  17790. else
  17791. decode_aarch64_feature_1_and (byte_get (ptr, 4));
  17792. goto next;
  17793. }
  17794. }
  17795. }
  17796. else
  17797. {
  17798. switch (type)
  17799. {
  17800. case GNU_PROPERTY_STACK_SIZE:
  17801. printf (_("stack size: "));
  17802. if (datasz != size)
  17803. printf (_("<corrupt length: %#x> "), datasz);
  17804. else
  17805. printf ("%#lx", (unsigned long) byte_get (ptr, size));
  17806. goto next;
  17807. case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
  17808. printf ("no copy on protected ");
  17809. if (datasz)
  17810. printf (_("<corrupt length: %#x> "), datasz);
  17811. goto next;
  17812. default:
  17813. if ((type >= GNU_PROPERTY_UINT32_AND_LO
  17814. && type <= GNU_PROPERTY_UINT32_AND_HI)
  17815. || (type >= GNU_PROPERTY_UINT32_OR_LO
  17816. && type <= GNU_PROPERTY_UINT32_OR_HI))
  17817. {
  17818. switch (type)
  17819. {
  17820. case GNU_PROPERTY_1_NEEDED:
  17821. if (datasz != 4)
  17822. printf (_("1_needed: <corrupt length: %#x> "),
  17823. datasz);
  17824. else
  17825. {
  17826. unsigned int bitmask = byte_get (ptr, 4);
  17827. printf ("1_needed: ");
  17828. decode_1_needed (bitmask);
  17829. }
  17830. goto next;
  17831. default:
  17832. break;
  17833. }
  17834. if (type <= GNU_PROPERTY_UINT32_AND_HI)
  17835. printf (_("UINT32_AND (%#x): "), type);
  17836. else
  17837. printf (_("UINT32_OR (%#x): "), type);
  17838. if (datasz != 4)
  17839. printf (_("<corrupt length: %#x> "), datasz);
  17840. else
  17841. printf ("%#x", (unsigned int) byte_get (ptr, 4));
  17842. goto next;
  17843. }
  17844. break;
  17845. }
  17846. }
  17847. if (type < GNU_PROPERTY_LOPROC)
  17848. printf (_("<unknown type %#x data: "), type);
  17849. else if (type < GNU_PROPERTY_LOUSER)
  17850. printf (_("<processor-specific type %#x data: "), type);
  17851. else
  17852. printf (_("<application-specific type %#x data: "), type);
  17853. for (j = 0; j < datasz; ++j)
  17854. printf ("%02x ", ptr[j] & 0xff);
  17855. printf (">");
  17856. next:
  17857. ptr += ((datasz + (size - 1)) & ~ (size - 1));
  17858. if (ptr == ptr_end)
  17859. break;
  17860. if (do_wide)
  17861. printf (", ");
  17862. else
  17863. printf ("\n\t");
  17864. }
  17865. printf ("\n");
  17866. }
  17867. static bool
  17868. print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote)
  17869. {
  17870. /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
  17871. switch (pnote->type)
  17872. {
  17873. case NT_GNU_BUILD_ID:
  17874. {
  17875. unsigned long i;
  17876. printf (_(" Build ID: "));
  17877. for (i = 0; i < pnote->descsz; ++i)
  17878. printf ("%02x", pnote->descdata[i] & 0xff);
  17879. printf ("\n");
  17880. }
  17881. break;
  17882. case NT_GNU_ABI_TAG:
  17883. {
  17884. unsigned long os, major, minor, subminor;
  17885. const char *osname;
  17886. /* PR 17531: file: 030-599401-0.004. */
  17887. if (pnote->descsz < 16)
  17888. {
  17889. printf (_(" <corrupt GNU_ABI_TAG>\n"));
  17890. break;
  17891. }
  17892. os = byte_get ((unsigned char *) pnote->descdata, 4);
  17893. major = byte_get ((unsigned char *) pnote->descdata + 4, 4);
  17894. minor = byte_get ((unsigned char *) pnote->descdata + 8, 4);
  17895. subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4);
  17896. switch (os)
  17897. {
  17898. case GNU_ABI_TAG_LINUX:
  17899. osname = "Linux";
  17900. break;
  17901. case GNU_ABI_TAG_HURD:
  17902. osname = "Hurd";
  17903. break;
  17904. case GNU_ABI_TAG_SOLARIS:
  17905. osname = "Solaris";
  17906. break;
  17907. case GNU_ABI_TAG_FREEBSD:
  17908. osname = "FreeBSD";
  17909. break;
  17910. case GNU_ABI_TAG_NETBSD:
  17911. osname = "NetBSD";
  17912. break;
  17913. case GNU_ABI_TAG_SYLLABLE:
  17914. osname = "Syllable";
  17915. break;
  17916. case GNU_ABI_TAG_NACL:
  17917. osname = "NaCl";
  17918. break;
  17919. default:
  17920. osname = "Unknown";
  17921. break;
  17922. }
  17923. printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname,
  17924. major, minor, subminor);
  17925. }
  17926. break;
  17927. case NT_GNU_GOLD_VERSION:
  17928. {
  17929. unsigned long i;
  17930. printf (_(" Version: "));
  17931. for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
  17932. printf ("%c", pnote->descdata[i]);
  17933. printf ("\n");
  17934. }
  17935. break;
  17936. case NT_GNU_HWCAP:
  17937. {
  17938. unsigned long num_entries, mask;
  17939. /* Hardware capabilities information. Word 0 is the number of entries.
  17940. Word 1 is a bitmask of enabled entries. The rest of the descriptor
  17941. is a series of entries, where each entry is a single byte followed
  17942. by a nul terminated string. The byte gives the bit number to test
  17943. if enabled in the bitmask. */
  17944. printf (_(" Hardware Capabilities: "));
  17945. if (pnote->descsz < 8)
  17946. {
  17947. error (_("<corrupt GNU_HWCAP>\n"));
  17948. return false;
  17949. }
  17950. num_entries = byte_get ((unsigned char *) pnote->descdata, 4);
  17951. mask = byte_get ((unsigned char *) pnote->descdata + 4, 4);
  17952. printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries, mask);
  17953. /* FIXME: Add code to display the entries... */
  17954. }
  17955. break;
  17956. case NT_GNU_PROPERTY_TYPE_0:
  17957. print_gnu_property_note (filedata, pnote);
  17958. break;
  17959. default:
  17960. /* Handle unrecognised types. An error message should have already been
  17961. created by get_gnu_elf_note_type(), so all that we need to do is to
  17962. display the data. */
  17963. {
  17964. unsigned long i;
  17965. printf (_(" Description data: "));
  17966. for (i = 0; i < pnote->descsz; ++i)
  17967. printf ("%02x ", pnote->descdata[i] & 0xff);
  17968. printf ("\n");
  17969. }
  17970. break;
  17971. }
  17972. return true;
  17973. }
  17974. static const char *
  17975. get_v850_elf_note_type (enum v850_notes n_type)
  17976. {
  17977. static char buff[64];
  17978. switch (n_type)
  17979. {
  17980. case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects");
  17981. case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double");
  17982. case V850_NOTE_FPU_INFO: return _("Type of FPU support needed");
  17983. case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions");
  17984. case V850_NOTE_CACHE_INFO: return _("Use of cache");
  17985. case V850_NOTE_MMU_INFO: return _("Use of MMU");
  17986. default:
  17987. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type);
  17988. return buff;
  17989. }
  17990. }
  17991. static bool
  17992. print_v850_note (Elf_Internal_Note * pnote)
  17993. {
  17994. unsigned int val;
  17995. if (pnote->descsz != 4)
  17996. return false;
  17997. val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz);
  17998. if (val == 0)
  17999. {
  18000. printf (_("not set\n"));
  18001. return true;
  18002. }
  18003. switch (pnote->type)
  18004. {
  18005. case V850_NOTE_ALIGNMENT:
  18006. switch (val)
  18007. {
  18008. case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return true;
  18009. case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return true;
  18010. }
  18011. break;
  18012. case V850_NOTE_DATA_SIZE:
  18013. switch (val)
  18014. {
  18015. case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return true;
  18016. case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return true;
  18017. }
  18018. break;
  18019. case V850_NOTE_FPU_INFO:
  18020. switch (val)
  18021. {
  18022. case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return true;
  18023. case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return true;
  18024. }
  18025. break;
  18026. case V850_NOTE_MMU_INFO:
  18027. case V850_NOTE_CACHE_INFO:
  18028. case V850_NOTE_SIMD_INFO:
  18029. if (val == EF_RH850_SIMD)
  18030. {
  18031. printf (_("yes\n"));
  18032. return true;
  18033. }
  18034. break;
  18035. default:
  18036. /* An 'unknown note type' message will already have been displayed. */
  18037. break;
  18038. }
  18039. printf (_("unknown value: %x\n"), val);
  18040. return false;
  18041. }
  18042. static bool
  18043. process_netbsd_elf_note (Elf_Internal_Note * pnote)
  18044. {
  18045. unsigned int version;
  18046. switch (pnote->type)
  18047. {
  18048. case NT_NETBSD_IDENT:
  18049. if (pnote->descsz < 1)
  18050. break;
  18051. version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
  18052. if ((version / 10000) % 100)
  18053. printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
  18054. version, version / 100000000, (version / 1000000) % 100,
  18055. (version / 10000) % 100 > 26 ? "Z" : "",
  18056. 'A' + (version / 10000) % 26);
  18057. else
  18058. printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz,
  18059. version, version / 100000000, (version / 1000000) % 100,
  18060. (version / 100) % 100);
  18061. return true;
  18062. case NT_NETBSD_MARCH:
  18063. printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote->descsz,
  18064. pnote->descdata);
  18065. return true;
  18066. case NT_NETBSD_PAX:
  18067. if (pnote->descsz < 1)
  18068. break;
  18069. version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
  18070. printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz,
  18071. ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""),
  18072. ((version & NT_NETBSD_PAX_NOMPROTECT) ? "-mprotect" : ""),
  18073. ((version & NT_NETBSD_PAX_GUARD) ? "+guard" : ""),
  18074. ((version & NT_NETBSD_PAX_NOGUARD) ? "-guard" : ""),
  18075. ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""),
  18076. ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : ""));
  18077. return true;
  18078. }
  18079. printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
  18080. pnote->descsz, pnote->type);
  18081. return false;
  18082. }
  18083. static const char *
  18084. get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
  18085. {
  18086. switch (e_type)
  18087. {
  18088. case NT_FREEBSD_THRMISC:
  18089. return _("NT_THRMISC (thrmisc structure)");
  18090. case NT_FREEBSD_PROCSTAT_PROC:
  18091. return _("NT_PROCSTAT_PROC (proc data)");
  18092. case NT_FREEBSD_PROCSTAT_FILES:
  18093. return _("NT_PROCSTAT_FILES (files data)");
  18094. case NT_FREEBSD_PROCSTAT_VMMAP:
  18095. return _("NT_PROCSTAT_VMMAP (vmmap data)");
  18096. case NT_FREEBSD_PROCSTAT_GROUPS:
  18097. return _("NT_PROCSTAT_GROUPS (groups data)");
  18098. case NT_FREEBSD_PROCSTAT_UMASK:
  18099. return _("NT_PROCSTAT_UMASK (umask data)");
  18100. case NT_FREEBSD_PROCSTAT_RLIMIT:
  18101. return _("NT_PROCSTAT_RLIMIT (rlimit data)");
  18102. case NT_FREEBSD_PROCSTAT_OSREL:
  18103. return _("NT_PROCSTAT_OSREL (osreldate data)");
  18104. case NT_FREEBSD_PROCSTAT_PSSTRINGS:
  18105. return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
  18106. case NT_FREEBSD_PROCSTAT_AUXV:
  18107. return _("NT_PROCSTAT_AUXV (auxv data)");
  18108. case NT_FREEBSD_PTLWPINFO:
  18109. return _("NT_PTLWPINFO (ptrace_lwpinfo structure)");
  18110. case NT_FREEBSD_X86_SEGBASES:
  18111. return _("NT_X86_SEGBASES (x86 segment base registers)");
  18112. }
  18113. return get_note_type (filedata, e_type);
  18114. }
  18115. static const char *
  18116. get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
  18117. {
  18118. static char buff[64];
  18119. switch (e_type)
  18120. {
  18121. case NT_NETBSDCORE_PROCINFO:
  18122. /* NetBSD core "procinfo" structure. */
  18123. return _("NetBSD procinfo structure");
  18124. case NT_NETBSDCORE_AUXV:
  18125. return _("NetBSD ELF auxiliary vector data");
  18126. case NT_NETBSDCORE_LWPSTATUS:
  18127. return _("PT_LWPSTATUS (ptrace_lwpstatus structure)");
  18128. default:
  18129. /* As of Jan 2020 there are no other machine-independent notes
  18130. defined for NetBSD core files. If the note type is less
  18131. than the start of the machine-dependent note types, we don't
  18132. understand it. */
  18133. if (e_type < NT_NETBSDCORE_FIRSTMACH)
  18134. {
  18135. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
  18136. return buff;
  18137. }
  18138. break;
  18139. }
  18140. switch (filedata->file_header.e_machine)
  18141. {
  18142. /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
  18143. and PT_GETFPREGS == mach+2. */
  18144. case EM_OLD_ALPHA:
  18145. case EM_ALPHA:
  18146. case EM_SPARC:
  18147. case EM_SPARC32PLUS:
  18148. case EM_SPARCV9:
  18149. switch (e_type)
  18150. {
  18151. case NT_NETBSDCORE_FIRSTMACH + 0:
  18152. return _("PT_GETREGS (reg structure)");
  18153. case NT_NETBSDCORE_FIRSTMACH + 2:
  18154. return _("PT_GETFPREGS (fpreg structure)");
  18155. default:
  18156. break;
  18157. }
  18158. break;
  18159. /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5.
  18160. There's also old PT___GETREGS40 == mach + 1 for old reg
  18161. structure which lacks GBR. */
  18162. case EM_SH:
  18163. switch (e_type)
  18164. {
  18165. case NT_NETBSDCORE_FIRSTMACH + 1:
  18166. return _("PT___GETREGS40 (old reg structure)");
  18167. case NT_NETBSDCORE_FIRSTMACH + 3:
  18168. return _("PT_GETREGS (reg structure)");
  18169. case NT_NETBSDCORE_FIRSTMACH + 5:
  18170. return _("PT_GETFPREGS (fpreg structure)");
  18171. default:
  18172. break;
  18173. }
  18174. break;
  18175. /* On all other arch's, PT_GETREGS == mach+1 and
  18176. PT_GETFPREGS == mach+3. */
  18177. default:
  18178. switch (e_type)
  18179. {
  18180. case NT_NETBSDCORE_FIRSTMACH + 1:
  18181. return _("PT_GETREGS (reg structure)");
  18182. case NT_NETBSDCORE_FIRSTMACH + 3:
  18183. return _("PT_GETFPREGS (fpreg structure)");
  18184. default:
  18185. break;
  18186. }
  18187. }
  18188. snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d",
  18189. e_type - NT_NETBSDCORE_FIRSTMACH);
  18190. return buff;
  18191. }
  18192. static const char *
  18193. get_openbsd_elfcore_note_type (Filedata * filedata, unsigned e_type)
  18194. {
  18195. switch (e_type)
  18196. {
  18197. case NT_OPENBSD_PROCINFO:
  18198. return _("OpenBSD procinfo structure");
  18199. case NT_OPENBSD_AUXV:
  18200. return _("OpenBSD ELF auxiliary vector data");
  18201. case NT_OPENBSD_REGS:
  18202. return _("OpenBSD regular registers");
  18203. case NT_OPENBSD_FPREGS:
  18204. return _("OpenBSD floating point registers");
  18205. case NT_OPENBSD_WCOOKIE:
  18206. return _("OpenBSD window cookie");
  18207. }
  18208. return get_note_type (filedata, e_type);
  18209. }
  18210. static const char *
  18211. get_stapsdt_note_type (unsigned e_type)
  18212. {
  18213. static char buff[64];
  18214. switch (e_type)
  18215. {
  18216. case NT_STAPSDT:
  18217. return _("NT_STAPSDT (SystemTap probe descriptors)");
  18218. default:
  18219. break;
  18220. }
  18221. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
  18222. return buff;
  18223. }
  18224. static bool
  18225. print_stapsdt_note (Elf_Internal_Note *pnote)
  18226. {
  18227. size_t len, maxlen;
  18228. unsigned long addr_size = is_32bit_elf ? 4 : 8;
  18229. char *data = pnote->descdata;
  18230. char *data_end = pnote->descdata + pnote->descsz;
  18231. bfd_vma pc, base_addr, semaphore;
  18232. char *provider, *probe, *arg_fmt;
  18233. if (pnote->descsz < (addr_size * 3))
  18234. goto stapdt_note_too_small;
  18235. pc = byte_get ((unsigned char *) data, addr_size);
  18236. data += addr_size;
  18237. base_addr = byte_get ((unsigned char *) data, addr_size);
  18238. data += addr_size;
  18239. semaphore = byte_get ((unsigned char *) data, addr_size);
  18240. data += addr_size;
  18241. if (data >= data_end)
  18242. goto stapdt_note_too_small;
  18243. maxlen = data_end - data;
  18244. len = strnlen (data, maxlen);
  18245. if (len < maxlen)
  18246. {
  18247. provider = data;
  18248. data += len + 1;
  18249. }
  18250. else
  18251. goto stapdt_note_too_small;
  18252. if (data >= data_end)
  18253. goto stapdt_note_too_small;
  18254. maxlen = data_end - data;
  18255. len = strnlen (data, maxlen);
  18256. if (len < maxlen)
  18257. {
  18258. probe = data;
  18259. data += len + 1;
  18260. }
  18261. else
  18262. goto stapdt_note_too_small;
  18263. if (data >= data_end)
  18264. goto stapdt_note_too_small;
  18265. maxlen = data_end - data;
  18266. len = strnlen (data, maxlen);
  18267. if (len < maxlen)
  18268. {
  18269. arg_fmt = data;
  18270. data += len + 1;
  18271. }
  18272. else
  18273. goto stapdt_note_too_small;
  18274. printf (_(" Provider: %s\n"), provider);
  18275. printf (_(" Name: %s\n"), probe);
  18276. printf (_(" Location: "));
  18277. print_vma (pc, FULL_HEX);
  18278. printf (_(", Base: "));
  18279. print_vma (base_addr, FULL_HEX);
  18280. printf (_(", Semaphore: "));
  18281. print_vma (semaphore, FULL_HEX);
  18282. printf ("\n");
  18283. printf (_(" Arguments: %s\n"), arg_fmt);
  18284. return data == data_end;
  18285. stapdt_note_too_small:
  18286. printf (_(" <corrupt - note is too small>\n"));
  18287. error (_("corrupt stapdt note - the data size is too small\n"));
  18288. return false;
  18289. }
  18290. static bool
  18291. print_fdo_note (Elf_Internal_Note * pnote)
  18292. {
  18293. if (pnote->descsz > 0 && pnote->type == FDO_PACKAGING_METADATA)
  18294. {
  18295. printf (_(" Packaging Metadata: %.*s\n"), (int) pnote->descsz, pnote->descdata);
  18296. return true;
  18297. }
  18298. return false;
  18299. }
  18300. static const char *
  18301. get_ia64_vms_note_type (unsigned e_type)
  18302. {
  18303. static char buff[64];
  18304. switch (e_type)
  18305. {
  18306. case NT_VMS_MHD:
  18307. return _("NT_VMS_MHD (module header)");
  18308. case NT_VMS_LNM:
  18309. return _("NT_VMS_LNM (language name)");
  18310. case NT_VMS_SRC:
  18311. return _("NT_VMS_SRC (source files)");
  18312. case NT_VMS_TITLE:
  18313. return "NT_VMS_TITLE";
  18314. case NT_VMS_EIDC:
  18315. return _("NT_VMS_EIDC (consistency check)");
  18316. case NT_VMS_FPMODE:
  18317. return _("NT_VMS_FPMODE (FP mode)");
  18318. case NT_VMS_LINKTIME:
  18319. return "NT_VMS_LINKTIME";
  18320. case NT_VMS_IMGNAM:
  18321. return _("NT_VMS_IMGNAM (image name)");
  18322. case NT_VMS_IMGID:
  18323. return _("NT_VMS_IMGID (image id)");
  18324. case NT_VMS_LINKID:
  18325. return _("NT_VMS_LINKID (link id)");
  18326. case NT_VMS_IMGBID:
  18327. return _("NT_VMS_IMGBID (build id)");
  18328. case NT_VMS_GSTNAM:
  18329. return _("NT_VMS_GSTNAM (sym table name)");
  18330. case NT_VMS_ORIG_DYN:
  18331. return "NT_VMS_ORIG_DYN";
  18332. case NT_VMS_PATCHTIME:
  18333. return "NT_VMS_PATCHTIME";
  18334. default:
  18335. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
  18336. return buff;
  18337. }
  18338. }
  18339. static bool
  18340. print_ia64_vms_note (Elf_Internal_Note * pnote)
  18341. {
  18342. int maxlen = pnote->descsz;
  18343. if (maxlen < 2 || (unsigned long) maxlen != pnote->descsz)
  18344. goto desc_size_fail;
  18345. switch (pnote->type)
  18346. {
  18347. case NT_VMS_MHD:
  18348. if (maxlen <= 36)
  18349. goto desc_size_fail;
  18350. int l = (int) strnlen (pnote->descdata + 34, maxlen - 34);
  18351. printf (_(" Creation date : %.17s\n"), pnote->descdata);
  18352. printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17);
  18353. if (l + 34 < maxlen)
  18354. {
  18355. printf (_(" Module name : %s\n"), pnote->descdata + 34);
  18356. if (l + 35 < maxlen)
  18357. printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1);
  18358. else
  18359. printf (_(" Module version : <missing>\n"));
  18360. }
  18361. else
  18362. {
  18363. printf (_(" Module name : <missing>\n"));
  18364. printf (_(" Module version : <missing>\n"));
  18365. }
  18366. break;
  18367. case NT_VMS_LNM:
  18368. printf (_(" Language: %.*s\n"), maxlen, pnote->descdata);
  18369. break;
  18370. #ifdef BFD64
  18371. case NT_VMS_FPMODE:
  18372. printf (_(" Floating Point mode: "));
  18373. if (maxlen < 8)
  18374. goto desc_size_fail;
  18375. /* FIXME: Generate an error if descsz > 8 ? */
  18376. printf ("0x%016" BFD_VMA_FMT "x\n",
  18377. (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8));
  18378. break;
  18379. case NT_VMS_LINKTIME:
  18380. printf (_(" Link time: "));
  18381. if (maxlen < 8)
  18382. goto desc_size_fail;
  18383. /* FIXME: Generate an error if descsz > 8 ? */
  18384. print_vms_time
  18385. ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
  18386. printf ("\n");
  18387. break;
  18388. case NT_VMS_PATCHTIME:
  18389. printf (_(" Patch time: "));
  18390. if (maxlen < 8)
  18391. goto desc_size_fail;
  18392. /* FIXME: Generate an error if descsz > 8 ? */
  18393. print_vms_time
  18394. ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
  18395. printf ("\n");
  18396. break;
  18397. case NT_VMS_ORIG_DYN:
  18398. if (maxlen < 34)
  18399. goto desc_size_fail;
  18400. printf (_(" Major id: %u, minor id: %u\n"),
  18401. (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
  18402. (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
  18403. printf (_(" Last modified : "));
  18404. print_vms_time
  18405. ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
  18406. printf (_("\n Link flags : "));
  18407. printf ("0x%016" BFD_VMA_FMT "x\n",
  18408. (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8));
  18409. printf (_(" Header flags: 0x%08x\n"),
  18410. (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4));
  18411. printf (_(" Image id : %.*s\n"), maxlen - 32, pnote->descdata + 32);
  18412. break;
  18413. #endif
  18414. case NT_VMS_IMGNAM:
  18415. printf (_(" Image name: %.*s\n"), maxlen, pnote->descdata);
  18416. break;
  18417. case NT_VMS_GSTNAM:
  18418. printf (_(" Global symbol table name: %.*s\n"), maxlen, pnote->descdata);
  18419. break;
  18420. case NT_VMS_IMGID:
  18421. printf (_(" Image id: %.*s\n"), maxlen, pnote->descdata);
  18422. break;
  18423. case NT_VMS_LINKID:
  18424. printf (_(" Linker id: %.*s\n"), maxlen, pnote->descdata);
  18425. break;
  18426. default:
  18427. return false;
  18428. }
  18429. return true;
  18430. desc_size_fail:
  18431. printf (_(" <corrupt - data size is too small>\n"));
  18432. error (_("corrupt IA64 note: data size is too small\n"));
  18433. return false;
  18434. }
  18435. struct build_attr_cache {
  18436. Filedata *filedata;
  18437. char *strtab;
  18438. unsigned long strtablen;
  18439. Elf_Internal_Sym *symtab;
  18440. unsigned long nsyms;
  18441. } ba_cache;
  18442. /* Find the symbol associated with a build attribute that is attached
  18443. to address OFFSET. If PNAME is non-NULL then store the name of
  18444. the symbol (if found) in the provided pointer, Returns NULL if a
  18445. symbol could not be found. */
  18446. static Elf_Internal_Sym *
  18447. get_symbol_for_build_attribute (Filedata *filedata,
  18448. unsigned long offset,
  18449. bool is_open_attr,
  18450. const char **pname)
  18451. {
  18452. Elf_Internal_Sym *saved_sym = NULL;
  18453. Elf_Internal_Sym *sym;
  18454. if (filedata->section_headers != NULL
  18455. && (ba_cache.filedata == NULL || filedata != ba_cache.filedata))
  18456. {
  18457. Elf_Internal_Shdr * symsec;
  18458. free (ba_cache.strtab);
  18459. ba_cache.strtab = NULL;
  18460. free (ba_cache.symtab);
  18461. ba_cache.symtab = NULL;
  18462. /* Load the symbol and string sections. */
  18463. for (symsec = filedata->section_headers;
  18464. symsec < filedata->section_headers + filedata->file_header.e_shnum;
  18465. symsec ++)
  18466. {
  18467. if (symsec->sh_type == SHT_SYMTAB
  18468. && get_symtab (filedata, symsec,
  18469. &ba_cache.symtab, &ba_cache.nsyms,
  18470. &ba_cache.strtab, &ba_cache.strtablen))
  18471. break;
  18472. }
  18473. ba_cache.filedata = filedata;
  18474. }
  18475. if (ba_cache.symtab == NULL)
  18476. return NULL;
  18477. /* Find a symbol whose value matches offset. */
  18478. for (sym = ba_cache.symtab; sym < ba_cache.symtab + ba_cache.nsyms; sym ++)
  18479. if (sym->st_value == offset)
  18480. {
  18481. if (sym->st_name >= ba_cache.strtablen)
  18482. /* Huh ? This should not happen. */
  18483. continue;
  18484. if (ba_cache.strtab[sym->st_name] == 0)
  18485. continue;
  18486. /* The AArch64, ARM and RISC-V architectures define mapping symbols
  18487. (eg $d, $x, $t) which we want to ignore. */
  18488. if (ba_cache.strtab[sym->st_name] == '$'
  18489. && ba_cache.strtab[sym->st_name + 1] != 0
  18490. && ba_cache.strtab[sym->st_name + 2] == 0)
  18491. continue;
  18492. if (is_open_attr)
  18493. {
  18494. /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
  18495. and FILE or OBJECT symbols over NOTYPE symbols. We skip
  18496. FUNC symbols entirely. */
  18497. switch (ELF_ST_TYPE (sym->st_info))
  18498. {
  18499. case STT_OBJECT:
  18500. case STT_FILE:
  18501. saved_sym = sym;
  18502. if (sym->st_size)
  18503. {
  18504. /* If the symbol has a size associated
  18505. with it then we can stop searching. */
  18506. sym = ba_cache.symtab + ba_cache.nsyms;
  18507. }
  18508. continue;
  18509. case STT_FUNC:
  18510. /* Ignore function symbols. */
  18511. continue;
  18512. default:
  18513. break;
  18514. }
  18515. switch (ELF_ST_BIND (sym->st_info))
  18516. {
  18517. case STB_GLOBAL:
  18518. if (saved_sym == NULL
  18519. || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT)
  18520. saved_sym = sym;
  18521. break;
  18522. case STB_LOCAL:
  18523. if (saved_sym == NULL)
  18524. saved_sym = sym;
  18525. break;
  18526. default:
  18527. break;
  18528. }
  18529. }
  18530. else
  18531. {
  18532. if (ELF_ST_TYPE (sym->st_info) != STT_FUNC)
  18533. continue;
  18534. saved_sym = sym;
  18535. break;
  18536. }
  18537. }
  18538. if (saved_sym && pname)
  18539. * pname = ba_cache.strtab + saved_sym->st_name;
  18540. return saved_sym;
  18541. }
  18542. /* Returns true iff addr1 and addr2 are in the same section. */
  18543. static bool
  18544. same_section (Filedata * filedata, unsigned long addr1, unsigned long addr2)
  18545. {
  18546. Elf_Internal_Shdr * a1;
  18547. Elf_Internal_Shdr * a2;
  18548. a1 = find_section_by_address (filedata, addr1);
  18549. a2 = find_section_by_address (filedata, addr2);
  18550. return a1 == a2 && a1 != NULL;
  18551. }
  18552. static bool
  18553. print_gnu_build_attribute_description (Elf_Internal_Note * pnote,
  18554. Filedata * filedata)
  18555. {
  18556. static unsigned long global_offset = 0;
  18557. static unsigned long global_end = 0;
  18558. static unsigned long func_offset = 0;
  18559. static unsigned long func_end = 0;
  18560. Elf_Internal_Sym *sym;
  18561. const char *name;
  18562. unsigned long start;
  18563. unsigned long end;
  18564. bool is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN;
  18565. switch (pnote->descsz)
  18566. {
  18567. case 0:
  18568. /* A zero-length description means that the range of
  18569. the previous note of the same type should be used. */
  18570. if (is_open_attr)
  18571. {
  18572. if (global_end > global_offset)
  18573. printf (_(" Applies to region from %#lx to %#lx\n"),
  18574. global_offset, global_end);
  18575. else
  18576. printf (_(" Applies to region from %#lx\n"), global_offset);
  18577. }
  18578. else
  18579. {
  18580. if (func_end > func_offset)
  18581. printf (_(" Applies to region from %#lx to %#lx\n"), func_offset, func_end);
  18582. else
  18583. printf (_(" Applies to region from %#lx\n"), func_offset);
  18584. }
  18585. return true;
  18586. case 4:
  18587. start = byte_get ((unsigned char *) pnote->descdata, 4);
  18588. end = 0;
  18589. break;
  18590. case 8:
  18591. start = byte_get ((unsigned char *) pnote->descdata, 4);
  18592. end = byte_get ((unsigned char *) pnote->descdata + 4, 4);
  18593. break;
  18594. case 16:
  18595. start = byte_get ((unsigned char *) pnote->descdata, 8);
  18596. end = byte_get ((unsigned char *) pnote->descdata + 8, 8);
  18597. break;
  18598. default:
  18599. error (_(" <invalid description size: %lx>\n"), pnote->descsz);
  18600. printf (_(" <invalid descsz>"));
  18601. return false;
  18602. }
  18603. name = NULL;
  18604. sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name);
  18605. /* As of version 5 of the annobin plugin, filename symbols are biased by 2
  18606. in order to avoid them being confused with the start address of the
  18607. first function in the file... */
  18608. if (sym == NULL && is_open_attr)
  18609. sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr,
  18610. & name);
  18611. if (end == 0 && sym != NULL && sym->st_size > 0)
  18612. end = start + sym->st_size;
  18613. if (is_open_attr)
  18614. {
  18615. /* FIXME: Need to properly allow for section alignment.
  18616. 16 is just the alignment used on x86_64. */
  18617. if (global_end > 0
  18618. && start > BFD_ALIGN (global_end, 16)
  18619. /* Build notes are not guaranteed to be organised in order of
  18620. increasing address, but we should find the all of the notes
  18621. for one section in the same place. */
  18622. && same_section (filedata, start, global_end))
  18623. warn (_("Gap in build notes detected from %#lx to %#lx\n"),
  18624. global_end + 1, start - 1);
  18625. printf (_(" Applies to region from %#lx"), start);
  18626. global_offset = start;
  18627. if (end)
  18628. {
  18629. printf (_(" to %#lx"), end);
  18630. global_end = end;
  18631. }
  18632. }
  18633. else
  18634. {
  18635. printf (_(" Applies to region from %#lx"), start);
  18636. func_offset = start;
  18637. if (end)
  18638. {
  18639. printf (_(" to %#lx"), end);
  18640. func_end = end;
  18641. }
  18642. }
  18643. if (sym && name)
  18644. printf (_(" (%s)"), name);
  18645. printf ("\n");
  18646. return true;
  18647. }
  18648. static bool
  18649. print_gnu_build_attribute_name (Elf_Internal_Note * pnote)
  18650. {
  18651. static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 };
  18652. static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 };
  18653. static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 };
  18654. char name_type;
  18655. char name_attribute;
  18656. const char * expected_types;
  18657. const char * name = pnote->namedata;
  18658. const char * text;
  18659. signed int left;
  18660. if (name == NULL || pnote->namesz < 2)
  18661. {
  18662. error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
  18663. print_symbol (-20, _(" <corrupt name>"));
  18664. return false;
  18665. }
  18666. if (do_wide)
  18667. left = 28;
  18668. else
  18669. left = 20;
  18670. /* Version 2 of the spec adds a "GA" prefix to the name field. */
  18671. if (name[0] == 'G' && name[1] == 'A')
  18672. {
  18673. if (pnote->namesz < 4)
  18674. {
  18675. error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
  18676. print_symbol (-20, _(" <corrupt name>"));
  18677. return false;
  18678. }
  18679. printf ("GA");
  18680. name += 2;
  18681. left -= 2;
  18682. }
  18683. switch ((name_type = * name))
  18684. {
  18685. case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
  18686. case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
  18687. case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
  18688. case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
  18689. printf ("%c", * name);
  18690. left --;
  18691. break;
  18692. default:
  18693. error (_("unrecognised attribute type in name field: %d\n"), name_type);
  18694. print_symbol (-20, _("<unknown name type>"));
  18695. return false;
  18696. }
  18697. ++ name;
  18698. text = NULL;
  18699. switch ((name_attribute = * name))
  18700. {
  18701. case GNU_BUILD_ATTRIBUTE_VERSION:
  18702. text = _("<version>");
  18703. expected_types = string_expected;
  18704. ++ name;
  18705. break;
  18706. case GNU_BUILD_ATTRIBUTE_STACK_PROT:
  18707. text = _("<stack prot>");
  18708. expected_types = "!+*";
  18709. ++ name;
  18710. break;
  18711. case GNU_BUILD_ATTRIBUTE_RELRO:
  18712. text = _("<relro>");
  18713. expected_types = bool_expected;
  18714. ++ name;
  18715. break;
  18716. case GNU_BUILD_ATTRIBUTE_STACK_SIZE:
  18717. text = _("<stack size>");
  18718. expected_types = number_expected;
  18719. ++ name;
  18720. break;
  18721. case GNU_BUILD_ATTRIBUTE_TOOL:
  18722. text = _("<tool>");
  18723. expected_types = string_expected;
  18724. ++ name;
  18725. break;
  18726. case GNU_BUILD_ATTRIBUTE_ABI:
  18727. text = _("<ABI>");
  18728. expected_types = "$*";
  18729. ++ name;
  18730. break;
  18731. case GNU_BUILD_ATTRIBUTE_PIC:
  18732. text = _("<PIC>");
  18733. expected_types = number_expected;
  18734. ++ name;
  18735. break;
  18736. case GNU_BUILD_ATTRIBUTE_SHORT_ENUM:
  18737. text = _("<short enum>");
  18738. expected_types = bool_expected;
  18739. ++ name;
  18740. break;
  18741. default:
  18742. if (ISPRINT (* name))
  18743. {
  18744. int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1;
  18745. if (len > left && ! do_wide)
  18746. len = left;
  18747. printf ("%.*s:", len, name);
  18748. left -= len;
  18749. name += len;
  18750. }
  18751. else
  18752. {
  18753. static char tmpbuf [128];
  18754. error (_("unrecognised byte in name field: %d\n"), * name);
  18755. sprintf (tmpbuf, _("<unknown:_%d>"), * name);
  18756. text = tmpbuf;
  18757. name ++;
  18758. }
  18759. expected_types = "*$!+";
  18760. break;
  18761. }
  18762. if (text)
  18763. left -= printf ("%s", text);
  18764. if (strchr (expected_types, name_type) == NULL)
  18765. warn (_("attribute does not have an expected type (%c)\n"), name_type);
  18766. if ((unsigned long)(name - pnote->namedata) > pnote->namesz)
  18767. {
  18768. error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
  18769. (unsigned long) pnote->namesz,
  18770. (long) (name - pnote->namedata));
  18771. return false;
  18772. }
  18773. if (left < 1 && ! do_wide)
  18774. return true;
  18775. switch (name_type)
  18776. {
  18777. case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
  18778. {
  18779. unsigned int bytes;
  18780. unsigned long long val = 0;
  18781. unsigned int shift = 0;
  18782. char * decoded = NULL;
  18783. bytes = pnote->namesz - (name - pnote->namedata);
  18784. if (bytes > 0)
  18785. /* The -1 is because the name field is always 0 terminated, and we
  18786. want to be able to ensure that the shift in the while loop below
  18787. will not overflow. */
  18788. -- bytes;
  18789. if (bytes > sizeof (val))
  18790. {
  18791. error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
  18792. bytes);
  18793. bytes = sizeof (val);
  18794. }
  18795. /* We do not bother to warn if bytes == 0 as this can
  18796. happen with some early versions of the gcc plugin. */
  18797. while (bytes --)
  18798. {
  18799. unsigned long long byte = *name++ & 0xff;
  18800. val |= byte << shift;
  18801. shift += 8;
  18802. }
  18803. switch (name_attribute)
  18804. {
  18805. case GNU_BUILD_ATTRIBUTE_PIC:
  18806. switch (val)
  18807. {
  18808. case 0: decoded = "static"; break;
  18809. case 1: decoded = "pic"; break;
  18810. case 2: decoded = "PIC"; break;
  18811. case 3: decoded = "pie"; break;
  18812. case 4: decoded = "PIE"; break;
  18813. default: break;
  18814. }
  18815. break;
  18816. case GNU_BUILD_ATTRIBUTE_STACK_PROT:
  18817. switch (val)
  18818. {
  18819. /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
  18820. case 0: decoded = "off"; break;
  18821. case 1: decoded = "on"; break;
  18822. case 2: decoded = "all"; break;
  18823. case 3: decoded = "strong"; break;
  18824. case 4: decoded = "explicit"; break;
  18825. default: break;
  18826. }
  18827. break;
  18828. default:
  18829. break;
  18830. }
  18831. if (decoded != NULL)
  18832. {
  18833. print_symbol (-left, decoded);
  18834. left = 0;
  18835. }
  18836. else if (val == 0)
  18837. {
  18838. printf ("0x0");
  18839. left -= 3;
  18840. }
  18841. else
  18842. {
  18843. if (do_wide)
  18844. left -= printf ("0x%llx", val);
  18845. else
  18846. left -= printf ("0x%-.*llx", left, val);
  18847. }
  18848. }
  18849. break;
  18850. case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
  18851. left -= print_symbol (- left, name);
  18852. break;
  18853. case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
  18854. left -= print_symbol (- left, "true");
  18855. break;
  18856. case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
  18857. left -= print_symbol (- left, "false");
  18858. break;
  18859. }
  18860. if (do_wide && left > 0)
  18861. printf ("%-*s", left, " ");
  18862. return true;
  18863. }
  18864. /* Print the contents of PNOTE as hex. */
  18865. static void
  18866. print_note_contents_hex (Elf_Internal_Note *pnote)
  18867. {
  18868. if (pnote->descsz)
  18869. {
  18870. unsigned long i;
  18871. printf (_(" description data: "));
  18872. for (i = 0; i < pnote->descsz; i++)
  18873. printf ("%02x ", pnote->descdata[i] & 0xff);
  18874. if (!do_wide)
  18875. printf ("\n");
  18876. }
  18877. if (do_wide)
  18878. printf ("\n");
  18879. }
  18880. #if defined HAVE_MSGPACK
  18881. static void
  18882. print_indents (int n)
  18883. {
  18884. printf (" ");
  18885. for (int i = 0; i < n; i++)
  18886. printf (" ");
  18887. }
  18888. /* Print OBJ in human-readable form. */
  18889. static void
  18890. dump_msgpack_obj (const msgpack_object *obj, int indent)
  18891. {
  18892. switch (obj->type)
  18893. {
  18894. case MSGPACK_OBJECT_NIL:
  18895. printf ("(nil)");
  18896. break;
  18897. case MSGPACK_OBJECT_BOOLEAN:
  18898. printf ("%s", obj->via.boolean ? "true" : "false");
  18899. break;
  18900. case MSGPACK_OBJECT_POSITIVE_INTEGER:
  18901. printf ("%" PRIu64, obj->via.u64);
  18902. break;
  18903. case MSGPACK_OBJECT_NEGATIVE_INTEGER:
  18904. printf ("%" PRIi64, obj->via.i64);
  18905. break;
  18906. case MSGPACK_OBJECT_FLOAT32:
  18907. case MSGPACK_OBJECT_FLOAT64:
  18908. printf ("%f", obj->via.f64);
  18909. break;
  18910. case MSGPACK_OBJECT_STR:
  18911. printf ("\"%.*s\"", obj->via.str.size, obj->via.str.ptr);
  18912. break;
  18913. case MSGPACK_OBJECT_ARRAY:
  18914. {
  18915. const msgpack_object_array *array = &obj->via.array;
  18916. printf ("[\n");
  18917. ++indent;
  18918. for (uint32_t i = 0; i < array->size; ++i)
  18919. {
  18920. const msgpack_object *item = &array->ptr[i];
  18921. print_indents (indent);
  18922. dump_msgpack_obj (item, indent);
  18923. printf (",\n");
  18924. }
  18925. --indent;
  18926. print_indents (indent);
  18927. printf ("]");
  18928. break;
  18929. }
  18930. break;
  18931. case MSGPACK_OBJECT_MAP:
  18932. {
  18933. const msgpack_object_map *map = &obj->via.map;
  18934. printf ("{\n");
  18935. ++indent;
  18936. for (uint32_t i = 0; i < map->size; ++i)
  18937. {
  18938. const msgpack_object_kv *kv = &map->ptr[i];
  18939. const msgpack_object *key = &kv->key;
  18940. const msgpack_object *val = &kv->val;
  18941. print_indents (indent);
  18942. dump_msgpack_obj (key, indent);
  18943. printf (": ");
  18944. dump_msgpack_obj (val, indent);
  18945. printf (",\n");
  18946. }
  18947. --indent;
  18948. print_indents (indent);
  18949. printf ("}");
  18950. break;
  18951. }
  18952. case MSGPACK_OBJECT_BIN:
  18953. printf ("(bin)");
  18954. break;
  18955. case MSGPACK_OBJECT_EXT:
  18956. printf ("(ext)");
  18957. break;
  18958. }
  18959. }
  18960. static void
  18961. dump_msgpack (const msgpack_unpacked *msg)
  18962. {
  18963. print_indents (0);
  18964. dump_msgpack_obj (&msg->data, 0);
  18965. printf ("\n");
  18966. }
  18967. #endif /* defined HAVE_MSGPACK */
  18968. static bool
  18969. print_amdgpu_note (Elf_Internal_Note *pnote)
  18970. {
  18971. #if defined HAVE_MSGPACK
  18972. /* If msgpack is available, decode and dump the note's content. */
  18973. bool ret;
  18974. msgpack_unpacked msg;
  18975. msgpack_unpack_return msgpack_ret;
  18976. assert (pnote->type == NT_AMDGPU_METADATA);
  18977. msgpack_unpacked_init (&msg);
  18978. msgpack_ret = msgpack_unpack_next (&msg, pnote->descdata, pnote->descsz,
  18979. NULL);
  18980. switch (msgpack_ret)
  18981. {
  18982. case MSGPACK_UNPACK_SUCCESS:
  18983. dump_msgpack (&msg);
  18984. ret = true;
  18985. break;
  18986. default:
  18987. error (_("failed to unpack msgpack contents in NT_AMDGPU_METADATA note"));
  18988. ret = false;
  18989. break;
  18990. }
  18991. msgpack_unpacked_destroy (&msg);
  18992. return ret;
  18993. #else
  18994. /* msgpack is not available, dump contents as hex. */
  18995. print_note_contents_hex (pnote);
  18996. return true;
  18997. #endif
  18998. }
  18999. /* Note that by the ELF standard, the name field is already null byte
  19000. terminated, and namesz includes the terminating null byte.
  19001. I.E. the value of namesz for the name "FSF" is 4.
  19002. If the value of namesz is zero, there is no name present. */
  19003. static bool
  19004. process_note (Elf_Internal_Note * pnote,
  19005. Filedata * filedata)
  19006. {
  19007. const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
  19008. const char * nt;
  19009. if (pnote->namesz == 0)
  19010. /* If there is no note name, then use the default set of
  19011. note type strings. */
  19012. nt = get_note_type (filedata, pnote->type);
  19013. else if (startswith (pnote->namedata, "GNU"))
  19014. /* GNU-specific object file notes. */
  19015. nt = get_gnu_elf_note_type (pnote->type);
  19016. else if (startswith (pnote->namedata, "AMDGPU"))
  19017. /* AMDGPU-specific object file notes. */
  19018. nt = get_amdgpu_elf_note_type (pnote->type);
  19019. else if (startswith (pnote->namedata, "FreeBSD"))
  19020. /* FreeBSD-specific core file notes. */
  19021. nt = get_freebsd_elfcore_note_type (filedata, pnote->type);
  19022. else if (startswith (pnote->namedata, "NetBSD-CORE"))
  19023. /* NetBSD-specific core file notes. */
  19024. nt = get_netbsd_elfcore_note_type (filedata, pnote->type);
  19025. else if (startswith (pnote->namedata, "NetBSD"))
  19026. /* NetBSD-specific core file notes. */
  19027. return process_netbsd_elf_note (pnote);
  19028. else if (startswith (pnote->namedata, "PaX"))
  19029. /* NetBSD-specific core file notes. */
  19030. return process_netbsd_elf_note (pnote);
  19031. else if (startswith (pnote->namedata, "OpenBSD"))
  19032. /* OpenBSD-specific core file notes. */
  19033. nt = get_openbsd_elfcore_note_type (filedata, pnote->type);
  19034. else if (startswith (pnote->namedata, "SPU/"))
  19035. {
  19036. /* SPU-specific core file notes. */
  19037. nt = pnote->namedata + 4;
  19038. name = "SPU";
  19039. }
  19040. else if (startswith (pnote->namedata, "IPF/VMS"))
  19041. /* VMS/ia64-specific file notes. */
  19042. nt = get_ia64_vms_note_type (pnote->type);
  19043. else if (startswith (pnote->namedata, "stapsdt"))
  19044. nt = get_stapsdt_note_type (pnote->type);
  19045. else
  19046. /* Don't recognize this note name; just use the default set of
  19047. note type strings. */
  19048. nt = get_note_type (filedata, pnote->type);
  19049. printf (" ");
  19050. if (((startswith (pnote->namedata, "GA")
  19051. && strchr ("*$!+", pnote->namedata[2]) != NULL)
  19052. || strchr ("*$!+", pnote->namedata[0]) != NULL)
  19053. && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
  19054. || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
  19055. print_gnu_build_attribute_name (pnote);
  19056. else
  19057. print_symbol (-20, name);
  19058. if (do_wide)
  19059. printf (" 0x%08lx\t%s\t", pnote->descsz, nt);
  19060. else
  19061. printf (" 0x%08lx\t%s\n", pnote->descsz, nt);
  19062. if (startswith (pnote->namedata, "IPF/VMS"))
  19063. return print_ia64_vms_note (pnote);
  19064. else if (startswith (pnote->namedata, "GNU"))
  19065. return print_gnu_note (filedata, pnote);
  19066. else if (startswith (pnote->namedata, "stapsdt"))
  19067. return print_stapsdt_note (pnote);
  19068. else if (startswith (pnote->namedata, "CORE"))
  19069. return print_core_note (pnote);
  19070. else if (startswith (pnote->namedata, "FDO"))
  19071. return print_fdo_note (pnote);
  19072. else if (((startswith (pnote->namedata, "GA")
  19073. && strchr ("*$!+", pnote->namedata[2]) != NULL)
  19074. || strchr ("*$!+", pnote->namedata[0]) != NULL)
  19075. && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
  19076. || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
  19077. return print_gnu_build_attribute_description (pnote, filedata);
  19078. else if (startswith (pnote->namedata, "AMDGPU")
  19079. && pnote->type == NT_AMDGPU_METADATA)
  19080. return print_amdgpu_note (pnote);
  19081. print_note_contents_hex (pnote);
  19082. return true;
  19083. }
  19084. static bool
  19085. process_notes_at (Filedata * filedata,
  19086. Elf_Internal_Shdr * section,
  19087. bfd_vma offset,
  19088. bfd_vma length,
  19089. bfd_vma align)
  19090. {
  19091. Elf_External_Note *pnotes;
  19092. Elf_External_Note *external;
  19093. char *end;
  19094. bool res = true;
  19095. if (length <= 0)
  19096. return false;
  19097. if (section)
  19098. {
  19099. pnotes = (Elf_External_Note *) get_section_contents (section, filedata);
  19100. if (pnotes)
  19101. {
  19102. if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL))
  19103. {
  19104. free (pnotes);
  19105. return false;
  19106. }
  19107. }
  19108. }
  19109. else
  19110. pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
  19111. _("notes"));
  19112. if (pnotes == NULL)
  19113. return false;
  19114. external = pnotes;
  19115. if (filedata->is_separate)
  19116. printf (_("In linked file '%s': "), filedata->file_name);
  19117. else
  19118. printf ("\n");
  19119. if (section)
  19120. printf (_("Displaying notes found in: %s\n"), printable_section_name (filedata, section));
  19121. else
  19122. printf (_("Displaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
  19123. (unsigned long) offset, (unsigned long) length);
  19124. /* NB: Some note sections may have alignment value of 0 or 1. gABI
  19125. specifies that notes should be aligned to 4 bytes in 32-bit
  19126. objects and to 8 bytes in 64-bit objects. As a Linux extension,
  19127. we also support 4 byte alignment in 64-bit objects. If section
  19128. alignment is less than 4, we treate alignment as 4 bytes. */
  19129. if (align < 4)
  19130. align = 4;
  19131. else if (align != 4 && align != 8)
  19132. {
  19133. warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"),
  19134. (long) align);
  19135. free (pnotes);
  19136. return false;
  19137. }
  19138. printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size"));
  19139. end = (char *) pnotes + length;
  19140. while ((char *) external < end)
  19141. {
  19142. Elf_Internal_Note inote;
  19143. size_t min_notesz;
  19144. char * next;
  19145. char * temp = NULL;
  19146. size_t data_remaining = end - (char *) external;
  19147. if (!is_ia64_vms (filedata))
  19148. {
  19149. /* PR binutils/15191
  19150. Make sure that there is enough data to read. */
  19151. min_notesz = offsetof (Elf_External_Note, name);
  19152. if (data_remaining < min_notesz)
  19153. {
  19154. warn (ngettext ("Corrupt note: only %ld byte remains, "
  19155. "not enough for a full note\n",
  19156. "Corrupt note: only %ld bytes remain, "
  19157. "not enough for a full note\n",
  19158. data_remaining),
  19159. (long) data_remaining);
  19160. break;
  19161. }
  19162. data_remaining -= min_notesz;
  19163. inote.type = BYTE_GET (external->type);
  19164. inote.namesz = BYTE_GET (external->namesz);
  19165. inote.namedata = external->name;
  19166. inote.descsz = BYTE_GET (external->descsz);
  19167. inote.descdata = ((char *) external
  19168. + ELF_NOTE_DESC_OFFSET (inote.namesz, align));
  19169. inote.descpos = offset + (inote.descdata - (char *) pnotes);
  19170. next = ((char *) external
  19171. + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align));
  19172. }
  19173. else
  19174. {
  19175. Elf64_External_VMS_Note *vms_external;
  19176. /* PR binutils/15191
  19177. Make sure that there is enough data to read. */
  19178. min_notesz = offsetof (Elf64_External_VMS_Note, name);
  19179. if (data_remaining < min_notesz)
  19180. {
  19181. warn (ngettext ("Corrupt note: only %ld byte remains, "
  19182. "not enough for a full note\n",
  19183. "Corrupt note: only %ld bytes remain, "
  19184. "not enough for a full note\n",
  19185. data_remaining),
  19186. (long) data_remaining);
  19187. break;
  19188. }
  19189. data_remaining -= min_notesz;
  19190. vms_external = (Elf64_External_VMS_Note *) external;
  19191. inote.type = BYTE_GET (vms_external->type);
  19192. inote.namesz = BYTE_GET (vms_external->namesz);
  19193. inote.namedata = vms_external->name;
  19194. inote.descsz = BYTE_GET (vms_external->descsz);
  19195. inote.descdata = inote.namedata + align_power (inote.namesz, 3);
  19196. inote.descpos = offset + (inote.descdata - (char *) pnotes);
  19197. next = inote.descdata + align_power (inote.descsz, 3);
  19198. }
  19199. /* PR 17531: file: 3443835e. */
  19200. /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
  19201. if ((size_t) (inote.descdata - inote.namedata) < inote.namesz
  19202. || (size_t) (inote.descdata - inote.namedata) > data_remaining
  19203. || (size_t) (next - inote.descdata) < inote.descsz
  19204. || ((size_t) (next - inote.descdata)
  19205. > data_remaining - (size_t) (inote.descdata - inote.namedata)))
  19206. {
  19207. warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
  19208. (unsigned long) ((char *) external - (char *) pnotes));
  19209. warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"),
  19210. inote.type, inote.namesz, inote.descsz, (int) align);
  19211. break;
  19212. }
  19213. external = (Elf_External_Note *) next;
  19214. /* Verify that name is null terminated. It appears that at least
  19215. one version of Linux (RedHat 6.0) generates corefiles that don't
  19216. comply with the ELF spec by failing to include the null byte in
  19217. namesz. */
  19218. if (inote.namesz > 0 && inote.namedata[inote.namesz - 1] != '\0')
  19219. {
  19220. if ((size_t) (inote.descdata - inote.namedata) == inote.namesz)
  19221. {
  19222. temp = (char *) malloc (inote.namesz + 1);
  19223. if (temp == NULL)
  19224. {
  19225. error (_("Out of memory allocating space for inote name\n"));
  19226. res = false;
  19227. break;
  19228. }
  19229. memcpy (temp, inote.namedata, inote.namesz);
  19230. inote.namedata = temp;
  19231. }
  19232. inote.namedata[inote.namesz] = 0;
  19233. }
  19234. if (! process_note (& inote, filedata))
  19235. res = false;
  19236. free (temp);
  19237. temp = NULL;
  19238. }
  19239. free (pnotes);
  19240. return res;
  19241. }
  19242. static bool
  19243. process_corefile_note_segments (Filedata * filedata)
  19244. {
  19245. Elf_Internal_Phdr *segment;
  19246. unsigned int i;
  19247. bool res = true;
  19248. if (! get_program_headers (filedata))
  19249. return true;
  19250. for (i = 0, segment = filedata->program_headers;
  19251. i < filedata->file_header.e_phnum;
  19252. i++, segment++)
  19253. {
  19254. if (segment->p_type == PT_NOTE)
  19255. if (! process_notes_at (filedata, NULL,
  19256. (bfd_vma) segment->p_offset,
  19257. (bfd_vma) segment->p_filesz,
  19258. (bfd_vma) segment->p_align))
  19259. res = false;
  19260. }
  19261. return res;
  19262. }
  19263. static bool
  19264. process_v850_notes (Filedata * filedata, bfd_vma offset, bfd_vma length)
  19265. {
  19266. Elf_External_Note * pnotes;
  19267. Elf_External_Note * external;
  19268. char * end;
  19269. bool res = true;
  19270. if (length <= 0)
  19271. return false;
  19272. pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length,
  19273. _("v850 notes"));
  19274. if (pnotes == NULL)
  19275. return false;
  19276. external = pnotes;
  19277. end = (char*) pnotes + length;
  19278. printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
  19279. (unsigned long) offset, (unsigned long) length);
  19280. while ((char *) external + sizeof (Elf_External_Note) < end)
  19281. {
  19282. Elf_External_Note * next;
  19283. Elf_Internal_Note inote;
  19284. inote.type = BYTE_GET (external->type);
  19285. inote.namesz = BYTE_GET (external->namesz);
  19286. inote.namedata = external->name;
  19287. inote.descsz = BYTE_GET (external->descsz);
  19288. inote.descdata = inote.namedata + align_power (inote.namesz, 2);
  19289. inote.descpos = offset + (inote.descdata - (char *) pnotes);
  19290. if (inote.descdata < (char *) pnotes || inote.descdata >= end)
  19291. {
  19292. warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz);
  19293. inote.descdata = inote.namedata;
  19294. inote.namesz = 0;
  19295. }
  19296. next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2));
  19297. if ( ((char *) next > end)
  19298. || ((char *) next < (char *) pnotes))
  19299. {
  19300. warn (_("corrupt descsz found in note at offset 0x%lx\n"),
  19301. (unsigned long) ((char *) external - (char *) pnotes));
  19302. warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
  19303. inote.type, inote.namesz, inote.descsz);
  19304. break;
  19305. }
  19306. external = next;
  19307. /* Prevent out-of-bounds indexing. */
  19308. if ( inote.namedata + inote.namesz > end
  19309. || inote.namedata + inote.namesz < inote.namedata)
  19310. {
  19311. warn (_("corrupt namesz found in note at offset 0x%lx\n"),
  19312. (unsigned long) ((char *) external - (char *) pnotes));
  19313. warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
  19314. inote.type, inote.namesz, inote.descsz);
  19315. break;
  19316. }
  19317. printf (" %s: ", get_v850_elf_note_type (inote.type));
  19318. if (! print_v850_note (& inote))
  19319. {
  19320. res = false;
  19321. printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
  19322. inote.namesz, inote.descsz);
  19323. }
  19324. }
  19325. free (pnotes);
  19326. return res;
  19327. }
  19328. static bool
  19329. process_note_sections (Filedata * filedata)
  19330. {
  19331. Elf_Internal_Shdr *section;
  19332. unsigned long i;
  19333. unsigned int n = 0;
  19334. bool res = true;
  19335. for (i = 0, section = filedata->section_headers;
  19336. i < filedata->file_header.e_shnum && section != NULL;
  19337. i++, section++)
  19338. {
  19339. if (section->sh_type == SHT_NOTE)
  19340. {
  19341. if (! process_notes_at (filedata, section,
  19342. (bfd_vma) section->sh_offset,
  19343. (bfd_vma) section->sh_size,
  19344. (bfd_vma) section->sh_addralign))
  19345. res = false;
  19346. n++;
  19347. }
  19348. if (( filedata->file_header.e_machine == EM_V800
  19349. || filedata->file_header.e_machine == EM_V850
  19350. || filedata->file_header.e_machine == EM_CYGNUS_V850)
  19351. && section->sh_type == SHT_RENESAS_INFO)
  19352. {
  19353. if (! process_v850_notes (filedata,
  19354. (bfd_vma) section->sh_offset,
  19355. (bfd_vma) section->sh_size))
  19356. res = false;
  19357. n++;
  19358. }
  19359. }
  19360. if (n == 0)
  19361. /* Try processing NOTE segments instead. */
  19362. return process_corefile_note_segments (filedata);
  19363. return res;
  19364. }
  19365. static bool
  19366. process_notes (Filedata * filedata)
  19367. {
  19368. /* If we have not been asked to display the notes then do nothing. */
  19369. if (! do_notes)
  19370. return true;
  19371. if (filedata->file_header.e_type != ET_CORE)
  19372. return process_note_sections (filedata);
  19373. /* No program headers means no NOTE segment. */
  19374. if (filedata->file_header.e_phnum > 0)
  19375. return process_corefile_note_segments (filedata);
  19376. if (filedata->is_separate)
  19377. printf (_("No notes found in linked file '%s'.\n"),
  19378. filedata->file_name);
  19379. else
  19380. printf (_("No notes found file.\n"));
  19381. return true;
  19382. }
  19383. static unsigned char *
  19384. display_public_gnu_attributes (unsigned char * start,
  19385. const unsigned char * const end)
  19386. {
  19387. printf (_(" Unknown GNU attribute: %s\n"), start);
  19388. start += strnlen ((char *) start, end - start);
  19389. display_raw_attribute (start, end);
  19390. return (unsigned char *) end;
  19391. }
  19392. static unsigned char *
  19393. display_generic_attribute (unsigned char * start,
  19394. unsigned int tag,
  19395. const unsigned char * const end)
  19396. {
  19397. if (tag == 0)
  19398. return (unsigned char *) end;
  19399. return display_tag_value (tag, start, end);
  19400. }
  19401. static bool
  19402. process_arch_specific (Filedata * filedata)
  19403. {
  19404. if (! do_arch)
  19405. return true;
  19406. switch (filedata->file_header.e_machine)
  19407. {
  19408. case EM_ARC:
  19409. case EM_ARC_COMPACT:
  19410. case EM_ARC_COMPACT2:
  19411. return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES,
  19412. display_arc_attribute,
  19413. display_generic_attribute);
  19414. case EM_ARM:
  19415. return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES,
  19416. display_arm_attribute,
  19417. display_generic_attribute);
  19418. case EM_MIPS:
  19419. case EM_MIPS_RS3_LE:
  19420. return process_mips_specific (filedata);
  19421. case EM_MSP430:
  19422. return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES,
  19423. display_msp430_attribute,
  19424. display_msp430_gnu_attribute);
  19425. case EM_RISCV:
  19426. return process_attributes (filedata, "riscv", SHT_RISCV_ATTRIBUTES,
  19427. display_riscv_attribute,
  19428. display_generic_attribute);
  19429. case EM_NDS32:
  19430. return process_nds32_specific (filedata);
  19431. case EM_68K:
  19432. return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
  19433. display_m68k_gnu_attribute);
  19434. case EM_PPC:
  19435. case EM_PPC64:
  19436. return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
  19437. display_power_gnu_attribute);
  19438. case EM_S390:
  19439. case EM_S390_OLD:
  19440. return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
  19441. display_s390_gnu_attribute);
  19442. case EM_SPARC:
  19443. case EM_SPARC32PLUS:
  19444. case EM_SPARCV9:
  19445. return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL,
  19446. display_sparc_gnu_attribute);
  19447. case EM_TI_C6000:
  19448. return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES,
  19449. display_tic6x_attribute,
  19450. display_generic_attribute);
  19451. case EM_CSKY:
  19452. return process_attributes (filedata, "csky", SHT_CSKY_ATTRIBUTES,
  19453. display_csky_attribute, NULL);
  19454. default:
  19455. return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES,
  19456. display_public_gnu_attributes,
  19457. display_generic_attribute);
  19458. }
  19459. }
  19460. static bool
  19461. get_file_header (Filedata * filedata)
  19462. {
  19463. /* Read in the identity array. */
  19464. if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1)
  19465. return false;
  19466. /* Determine how to read the rest of the header. */
  19467. switch (filedata->file_header.e_ident[EI_DATA])
  19468. {
  19469. default:
  19470. case ELFDATANONE:
  19471. case ELFDATA2LSB:
  19472. byte_get = byte_get_little_endian;
  19473. byte_put = byte_put_little_endian;
  19474. break;
  19475. case ELFDATA2MSB:
  19476. byte_get = byte_get_big_endian;
  19477. byte_put = byte_put_big_endian;
  19478. break;
  19479. }
  19480. /* For now we only support 32 bit and 64 bit ELF files. */
  19481. is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64);
  19482. /* Read in the rest of the header. */
  19483. if (is_32bit_elf)
  19484. {
  19485. Elf32_External_Ehdr ehdr32;
  19486. if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1)
  19487. return false;
  19488. filedata->file_header.e_type = BYTE_GET (ehdr32.e_type);
  19489. filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine);
  19490. filedata->file_header.e_version = BYTE_GET (ehdr32.e_version);
  19491. filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry);
  19492. filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
  19493. filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
  19494. filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags);
  19495. filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
  19496. filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
  19497. filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
  19498. filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
  19499. filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
  19500. filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
  19501. }
  19502. else
  19503. {
  19504. Elf64_External_Ehdr ehdr64;
  19505. /* If we have been compiled with sizeof (bfd_vma) == 4, then
  19506. we will not be able to cope with the 64bit data found in
  19507. 64 ELF files. Detect this now and abort before we start
  19508. overwriting things. */
  19509. if (sizeof (bfd_vma) < 8)
  19510. {
  19511. error (_("This instance of readelf has been built without support for a\n\
  19512. 64 bit data type and so it cannot read 64 bit ELF files.\n"));
  19513. return false;
  19514. }
  19515. if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1)
  19516. return false;
  19517. filedata->file_header.e_type = BYTE_GET (ehdr64.e_type);
  19518. filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine);
  19519. filedata->file_header.e_version = BYTE_GET (ehdr64.e_version);
  19520. filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry);
  19521. filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
  19522. filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
  19523. filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags);
  19524. filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
  19525. filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
  19526. filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
  19527. filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
  19528. filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
  19529. filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
  19530. }
  19531. return true;
  19532. }
  19533. static void
  19534. free_filedata (Filedata *filedata)
  19535. {
  19536. free (filedata->program_interpreter);
  19537. free (filedata->program_headers);
  19538. free (filedata->section_headers);
  19539. free (filedata->string_table);
  19540. free (filedata->dump.dump_sects);
  19541. free (filedata->dynamic_strings);
  19542. free (filedata->dynamic_symbols);
  19543. free (filedata->dynamic_syminfo);
  19544. free (filedata->dynamic_section);
  19545. while (filedata->symtab_shndx_list != NULL)
  19546. {
  19547. elf_section_list *next = filedata->symtab_shndx_list->next;
  19548. free (filedata->symtab_shndx_list);
  19549. filedata->symtab_shndx_list = next;
  19550. }
  19551. free (filedata->section_headers_groups);
  19552. if (filedata->section_groups)
  19553. {
  19554. size_t i;
  19555. struct group_list * g;
  19556. struct group_list * next;
  19557. for (i = 0; i < filedata->group_count; i++)
  19558. {
  19559. for (g = filedata->section_groups [i].root; g != NULL; g = next)
  19560. {
  19561. next = g->next;
  19562. free (g);
  19563. }
  19564. }
  19565. free (filedata->section_groups);
  19566. }
  19567. memset (&filedata->section_headers, 0,
  19568. sizeof (Filedata) - offsetof (Filedata, section_headers));
  19569. }
  19570. static void
  19571. close_file (Filedata * filedata)
  19572. {
  19573. if (filedata)
  19574. {
  19575. if (filedata->handle)
  19576. fclose (filedata->handle);
  19577. free (filedata);
  19578. }
  19579. }
  19580. void
  19581. close_debug_file (void * data)
  19582. {
  19583. free_filedata ((Filedata *) data);
  19584. close_file ((Filedata *) data);
  19585. }
  19586. static Filedata *
  19587. open_file (const char * pathname, bool is_separate)
  19588. {
  19589. struct stat statbuf;
  19590. Filedata * filedata = NULL;
  19591. if (stat (pathname, & statbuf) < 0
  19592. || ! S_ISREG (statbuf.st_mode))
  19593. goto fail;
  19594. filedata = calloc (1, sizeof * filedata);
  19595. if (filedata == NULL)
  19596. goto fail;
  19597. filedata->handle = fopen (pathname, "rb");
  19598. if (filedata->handle == NULL)
  19599. goto fail;
  19600. filedata->file_size = (bfd_size_type) statbuf.st_size;
  19601. filedata->file_name = pathname;
  19602. filedata->is_separate = is_separate;
  19603. if (! get_file_header (filedata))
  19604. goto fail;
  19605. if (!get_section_headers (filedata, false))
  19606. goto fail;
  19607. return filedata;
  19608. fail:
  19609. if (filedata)
  19610. {
  19611. if (filedata->handle)
  19612. fclose (filedata->handle);
  19613. free (filedata);
  19614. }
  19615. return NULL;
  19616. }
  19617. void *
  19618. open_debug_file (const char * pathname)
  19619. {
  19620. return open_file (pathname, true);
  19621. }
  19622. static void
  19623. initialise_dump_sects (Filedata * filedata)
  19624. {
  19625. /* Initialise the dump_sects array from the cmdline_dump_sects array.
  19626. Note we do this even if cmdline_dump_sects is empty because we
  19627. must make sure that the dump_sets array is zeroed out before each
  19628. object file is processed. */
  19629. if (filedata->dump.num_dump_sects > cmdline.num_dump_sects)
  19630. memset (filedata->dump.dump_sects, 0,
  19631. filedata->dump.num_dump_sects * sizeof (*filedata->dump.dump_sects));
  19632. if (cmdline.num_dump_sects > 0)
  19633. {
  19634. if (filedata->dump.num_dump_sects == 0)
  19635. /* A sneaky way of allocating the dump_sects array. */
  19636. request_dump_bynumber (&filedata->dump, cmdline.num_dump_sects, 0);
  19637. assert (filedata->dump.num_dump_sects >= cmdline.num_dump_sects);
  19638. memcpy (filedata->dump.dump_sects, cmdline.dump_sects,
  19639. cmdline.num_dump_sects * sizeof (*filedata->dump.dump_sects));
  19640. }
  19641. }
  19642. /* Process one ELF object file according to the command line options.
  19643. This file may actually be stored in an archive. The file is
  19644. positioned at the start of the ELF object. Returns TRUE if no
  19645. problems were encountered, FALSE otherwise. */
  19646. static bool
  19647. process_object (Filedata * filedata)
  19648. {
  19649. bool have_separate_files;
  19650. unsigned int i;
  19651. bool res;
  19652. if (! get_file_header (filedata))
  19653. {
  19654. error (_("%s: Failed to read file header\n"), filedata->file_name);
  19655. return false;
  19656. }
  19657. /* Initialise per file variables. */
  19658. for (i = ARRAY_SIZE (filedata->version_info); i--;)
  19659. filedata->version_info[i] = 0;
  19660. for (i = ARRAY_SIZE (filedata->dynamic_info); i--;)
  19661. filedata->dynamic_info[i] = 0;
  19662. filedata->dynamic_info_DT_GNU_HASH = 0;
  19663. filedata->dynamic_info_DT_MIPS_XHASH = 0;
  19664. /* Process the file. */
  19665. if (show_name)
  19666. printf (_("\nFile: %s\n"), filedata->file_name);
  19667. initialise_dump_sects (filedata);
  19668. /* There may be some extensions in the first section header. Don't
  19669. bomb if we can't read it. */
  19670. get_section_headers (filedata, true);
  19671. if (! process_file_header (filedata))
  19672. {
  19673. res = false;
  19674. goto out;
  19675. }
  19676. /* Throw away the single section header read above, so that we
  19677. re-read the entire set. */
  19678. free (filedata->section_headers);
  19679. filedata->section_headers = NULL;
  19680. if (! process_section_headers (filedata))
  19681. {
  19682. /* Without loaded section headers we cannot process lots of things. */
  19683. do_unwind = do_version = do_dump = do_arch = false;
  19684. if (! do_using_dynamic)
  19685. do_syms = do_dyn_syms = do_reloc = false;
  19686. }
  19687. if (! process_section_groups (filedata))
  19688. /* Without loaded section groups we cannot process unwind. */
  19689. do_unwind = false;
  19690. process_program_headers (filedata);
  19691. res = process_dynamic_section (filedata);
  19692. if (! process_relocs (filedata))
  19693. res = false;
  19694. if (! process_unwind (filedata))
  19695. res = false;
  19696. if (! process_symbol_table (filedata))
  19697. res = false;
  19698. if (! process_lto_symbol_tables (filedata))
  19699. res = false;
  19700. if (! process_syminfo (filedata))
  19701. res = false;
  19702. if (! process_version_sections (filedata))
  19703. res = false;
  19704. if (filedata->file_header.e_shstrndx != SHN_UNDEF)
  19705. have_separate_files = load_separate_debug_files (filedata, filedata->file_name);
  19706. else
  19707. have_separate_files = false;
  19708. if (! process_section_contents (filedata))
  19709. res = false;
  19710. if (have_separate_files)
  19711. {
  19712. separate_info * d;
  19713. for (d = first_separate_info; d != NULL; d = d->next)
  19714. {
  19715. initialise_dump_sects (d->handle);
  19716. if (process_links && ! process_file_header (d->handle))
  19717. res = false;
  19718. else if (! process_section_headers (d->handle))
  19719. res = false;
  19720. else if (! process_section_contents (d->handle))
  19721. res = false;
  19722. else if (process_links)
  19723. {
  19724. if (! process_section_groups (d->handle))
  19725. res = false;
  19726. process_program_headers (d->handle);
  19727. if (! process_dynamic_section (d->handle))
  19728. res = false;
  19729. if (! process_relocs (d->handle))
  19730. res = false;
  19731. if (! process_unwind (d->handle))
  19732. res = false;
  19733. if (! process_symbol_table (d->handle))
  19734. res = false;
  19735. if (! process_lto_symbol_tables (d->handle))
  19736. res = false;
  19737. if (! process_syminfo (d->handle))
  19738. res = false;
  19739. if (! process_version_sections (d->handle))
  19740. res = false;
  19741. if (! process_notes (d->handle))
  19742. res = false;
  19743. }
  19744. }
  19745. /* The file handles are closed by the call to free_debug_memory() below. */
  19746. }
  19747. if (! process_notes (filedata))
  19748. res = false;
  19749. if (! process_gnu_liblist (filedata))
  19750. res = false;
  19751. if (! process_arch_specific (filedata))
  19752. res = false;
  19753. out:
  19754. free_filedata (filedata);
  19755. free_debug_memory ();
  19756. return res;
  19757. }
  19758. /* Process an ELF archive.
  19759. On entry the file is positioned just after the ARMAG string.
  19760. Returns TRUE upon success, FALSE otherwise. */
  19761. static bool
  19762. process_archive (Filedata * filedata, bool is_thin_archive)
  19763. {
  19764. struct archive_info arch;
  19765. struct archive_info nested_arch;
  19766. size_t got;
  19767. bool ret = true;
  19768. show_name = true;
  19769. /* The ARCH structure is used to hold information about this archive. */
  19770. arch.file_name = NULL;
  19771. arch.file = NULL;
  19772. arch.index_array = NULL;
  19773. arch.sym_table = NULL;
  19774. arch.longnames = NULL;
  19775. /* The NESTED_ARCH structure is used as a single-item cache of information
  19776. about a nested archive (when members of a thin archive reside within
  19777. another regular archive file). */
  19778. nested_arch.file_name = NULL;
  19779. nested_arch.file = NULL;
  19780. nested_arch.index_array = NULL;
  19781. nested_arch.sym_table = NULL;
  19782. nested_arch.longnames = NULL;
  19783. if (setup_archive (&arch, filedata->file_name, filedata->handle,
  19784. filedata->file_size, is_thin_archive,
  19785. do_archive_index) != 0)
  19786. {
  19787. ret = false;
  19788. goto out;
  19789. }
  19790. if (do_archive_index)
  19791. {
  19792. if (arch.sym_table == NULL)
  19793. error (_("%s: unable to dump the index as none was found\n"),
  19794. filedata->file_name);
  19795. else
  19796. {
  19797. unsigned long i, l;
  19798. unsigned long current_pos;
  19799. printf (_("Index of archive %s: (%lu entries, 0x%lx bytes "
  19800. "in the symbol table)\n"),
  19801. filedata->file_name, (unsigned long) arch.index_num,
  19802. arch.sym_size);
  19803. current_pos = ftell (filedata->handle);
  19804. for (i = l = 0; i < arch.index_num; i++)
  19805. {
  19806. if (i == 0
  19807. || (i > 0 && arch.index_array[i] != arch.index_array[i - 1]))
  19808. {
  19809. char * member_name
  19810. = get_archive_member_name_at (&arch, arch.index_array[i],
  19811. &nested_arch);
  19812. if (member_name != NULL)
  19813. {
  19814. char * qualified_name
  19815. = make_qualified_name (&arch, &nested_arch,
  19816. member_name);
  19817. if (qualified_name != NULL)
  19818. {
  19819. printf (_("Contents of binary %s at offset "),
  19820. qualified_name);
  19821. (void) print_vma (arch.index_array[i], PREFIX_HEX);
  19822. putchar ('\n');
  19823. free (qualified_name);
  19824. }
  19825. free (member_name);
  19826. }
  19827. }
  19828. if (l >= arch.sym_size)
  19829. {
  19830. error (_("%s: end of the symbol table reached "
  19831. "before the end of the index\n"),
  19832. filedata->file_name);
  19833. ret = false;
  19834. break;
  19835. }
  19836. /* PR 17531: file: 0b6630b2. */
  19837. printf ("\t%.*s\n",
  19838. (int) (arch.sym_size - l), arch.sym_table + l);
  19839. l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1;
  19840. }
  19841. if (arch.uses_64bit_indices)
  19842. l = (l + 7) & ~ 7;
  19843. else
  19844. l += l & 1;
  19845. if (l < arch.sym_size)
  19846. {
  19847. error (ngettext ("%s: %ld byte remains in the symbol table, "
  19848. "but without corresponding entries in "
  19849. "the index table\n",
  19850. "%s: %ld bytes remain in the symbol table, "
  19851. "but without corresponding entries in "
  19852. "the index table\n",
  19853. arch.sym_size - l),
  19854. filedata->file_name, arch.sym_size - l);
  19855. ret = false;
  19856. }
  19857. if (fseek (filedata->handle, current_pos, SEEK_SET) != 0)
  19858. {
  19859. error (_("%s: failed to seek back to start of object files "
  19860. "in the archive\n"),
  19861. filedata->file_name);
  19862. ret = false;
  19863. goto out;
  19864. }
  19865. }
  19866. if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
  19867. && !do_segments && !do_header && !do_dump && !do_version
  19868. && !do_histogram && !do_debugging && !do_arch && !do_notes
  19869. && !do_section_groups && !do_dyn_syms)
  19870. {
  19871. ret = true; /* Archive index only. */
  19872. goto out;
  19873. }
  19874. }
  19875. while (1)
  19876. {
  19877. char * name;
  19878. size_t namelen;
  19879. char * qualified_name;
  19880. /* Read the next archive header. */
  19881. if (fseek (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0)
  19882. {
  19883. error (_("%s: failed to seek to next archive header\n"),
  19884. arch.file_name);
  19885. ret = false;
  19886. break;
  19887. }
  19888. got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle);
  19889. if (got != sizeof arch.arhdr)
  19890. {
  19891. if (got == 0)
  19892. break;
  19893. /* PR 24049 - we cannot use filedata->file_name as this will
  19894. have already been freed. */
  19895. error (_("%s: failed to read archive header\n"), arch.file_name);
  19896. ret = false;
  19897. break;
  19898. }
  19899. if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
  19900. {
  19901. error (_("%s: did not find a valid archive header\n"),
  19902. arch.file_name);
  19903. ret = false;
  19904. break;
  19905. }
  19906. arch.next_arhdr_offset += sizeof arch.arhdr;
  19907. filedata->archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
  19908. name = get_archive_member_name (&arch, &nested_arch);
  19909. if (name == NULL)
  19910. {
  19911. error (_("%s: bad archive file name\n"), arch.file_name);
  19912. ret = false;
  19913. break;
  19914. }
  19915. namelen = strlen (name);
  19916. qualified_name = make_qualified_name (&arch, &nested_arch, name);
  19917. if (qualified_name == NULL)
  19918. {
  19919. error (_("%s: bad archive file name\n"), arch.file_name);
  19920. free (name);
  19921. ret = false;
  19922. break;
  19923. }
  19924. if (is_thin_archive && arch.nested_member_origin == 0)
  19925. {
  19926. /* This is a proxy for an external member of a thin archive. */
  19927. Filedata * member_filedata;
  19928. char * member_file_name = adjust_relative_path
  19929. (filedata->file_name, name, namelen);
  19930. free (name);
  19931. if (member_file_name == NULL)
  19932. {
  19933. free (qualified_name);
  19934. ret = false;
  19935. break;
  19936. }
  19937. member_filedata = open_file (member_file_name, false);
  19938. if (member_filedata == NULL)
  19939. {
  19940. error (_("Input file '%s' is not readable.\n"), member_file_name);
  19941. free (member_file_name);
  19942. free (qualified_name);
  19943. ret = false;
  19944. break;
  19945. }
  19946. filedata->archive_file_offset = arch.nested_member_origin;
  19947. member_filedata->file_name = qualified_name;
  19948. /* The call to process_object() expects the file to be at the beginning. */
  19949. rewind (member_filedata->handle);
  19950. if (! process_object (member_filedata))
  19951. ret = false;
  19952. close_file (member_filedata);
  19953. free (member_file_name);
  19954. }
  19955. else if (is_thin_archive)
  19956. {
  19957. Filedata thin_filedata;
  19958. memset (&thin_filedata, 0, sizeof (thin_filedata));
  19959. /* PR 15140: Allow for corrupt thin archives. */
  19960. if (nested_arch.file == NULL)
  19961. {
  19962. error (_("%s: contains corrupt thin archive: %s\n"),
  19963. qualified_name, name);
  19964. free (qualified_name);
  19965. free (name);
  19966. ret = false;
  19967. break;
  19968. }
  19969. free (name);
  19970. /* This is a proxy for a member of a nested archive. */
  19971. filedata->archive_file_offset
  19972. = arch.nested_member_origin + sizeof arch.arhdr;
  19973. /* The nested archive file will have been opened and setup by
  19974. get_archive_member_name. */
  19975. if (fseek (nested_arch.file, filedata->archive_file_offset,
  19976. SEEK_SET) != 0)
  19977. {
  19978. error (_("%s: failed to seek to archive member.\n"),
  19979. nested_arch.file_name);
  19980. free (qualified_name);
  19981. ret = false;
  19982. break;
  19983. }
  19984. thin_filedata.handle = nested_arch.file;
  19985. thin_filedata.file_name = qualified_name;
  19986. if (! process_object (& thin_filedata))
  19987. ret = false;
  19988. }
  19989. else
  19990. {
  19991. free (name);
  19992. filedata->archive_file_offset = arch.next_arhdr_offset;
  19993. filedata->file_name = qualified_name;
  19994. if (! process_object (filedata))
  19995. ret = false;
  19996. arch.next_arhdr_offset += (filedata->archive_file_size + 1) & -2;
  19997. /* Stop looping with "negative" archive_file_size. */
  19998. if (arch.next_arhdr_offset < filedata->archive_file_size)
  19999. arch.next_arhdr_offset = -1ul;
  20000. }
  20001. free (qualified_name);
  20002. }
  20003. out:
  20004. if (nested_arch.file != NULL)
  20005. fclose (nested_arch.file);
  20006. release_archive (&nested_arch);
  20007. release_archive (&arch);
  20008. return ret;
  20009. }
  20010. static bool
  20011. process_file (char * file_name)
  20012. {
  20013. Filedata * filedata = NULL;
  20014. struct stat statbuf;
  20015. char armag[SARMAG];
  20016. bool ret = true;
  20017. if (stat (file_name, &statbuf) < 0)
  20018. {
  20019. if (errno == ENOENT)
  20020. error (_("'%s': No such file\n"), file_name);
  20021. else
  20022. error (_("Could not locate '%s'. System error message: %s\n"),
  20023. file_name, strerror (errno));
  20024. return false;
  20025. }
  20026. if (! S_ISREG (statbuf.st_mode))
  20027. {
  20028. error (_("'%s' is not an ordinary file\n"), file_name);
  20029. return false;
  20030. }
  20031. filedata = calloc (1, sizeof * filedata);
  20032. if (filedata == NULL)
  20033. {
  20034. error (_("Out of memory allocating file data structure\n"));
  20035. return false;
  20036. }
  20037. filedata->file_name = file_name;
  20038. filedata->handle = fopen (file_name, "rb");
  20039. if (filedata->handle == NULL)
  20040. {
  20041. error (_("Input file '%s' is not readable.\n"), file_name);
  20042. free (filedata);
  20043. return false;
  20044. }
  20045. if (fread (armag, SARMAG, 1, filedata->handle) != 1)
  20046. {
  20047. error (_("%s: Failed to read file's magic number\n"), file_name);
  20048. fclose (filedata->handle);
  20049. free (filedata);
  20050. return false;
  20051. }
  20052. filedata->file_size = (bfd_size_type) statbuf.st_size;
  20053. filedata->is_separate = false;
  20054. if (memcmp (armag, ARMAG, SARMAG) == 0)
  20055. {
  20056. if (! process_archive (filedata, false))
  20057. ret = false;
  20058. }
  20059. else if (memcmp (armag, ARMAGT, SARMAG) == 0)
  20060. {
  20061. if ( ! process_archive (filedata, true))
  20062. ret = false;
  20063. }
  20064. else
  20065. {
  20066. if (do_archive_index && !check_all)
  20067. error (_("File %s is not an archive so its index cannot be displayed.\n"),
  20068. file_name);
  20069. rewind (filedata->handle);
  20070. filedata->archive_file_size = filedata->archive_file_offset = 0;
  20071. if (! process_object (filedata))
  20072. ret = false;
  20073. }
  20074. fclose (filedata->handle);
  20075. free (filedata->section_headers);
  20076. free (filedata->program_headers);
  20077. free (filedata->string_table);
  20078. free (filedata->dump.dump_sects);
  20079. free (filedata);
  20080. free (ba_cache.strtab);
  20081. ba_cache.strtab = NULL;
  20082. free (ba_cache.symtab);
  20083. ba_cache.symtab = NULL;
  20084. ba_cache.filedata = NULL;
  20085. return ret;
  20086. }
  20087. #ifdef SUPPORT_DISASSEMBLY
  20088. /* Needed by the i386 disassembler. For extra credit, someone could
  20089. fix this so that we insert symbolic addresses here, esp for GOT/PLT
  20090. symbols. */
  20091. void
  20092. print_address (unsigned int addr, FILE * outfile)
  20093. {
  20094. fprintf (outfile,"0x%8.8x", addr);
  20095. }
  20096. /* Needed by the i386 disassembler. */
  20097. void
  20098. db_task_printsym (unsigned int addr)
  20099. {
  20100. print_address (addr, stderr);
  20101. }
  20102. #endif
  20103. int
  20104. main (int argc, char ** argv)
  20105. {
  20106. int err;
  20107. #ifdef HAVE_LC_MESSAGES
  20108. setlocale (LC_MESSAGES, "");
  20109. #endif
  20110. setlocale (LC_CTYPE, "");
  20111. bindtextdomain (PACKAGE, LOCALEDIR);
  20112. textdomain (PACKAGE);
  20113. expandargv (&argc, &argv);
  20114. parse_args (& cmdline, argc, argv);
  20115. if (optind < (argc - 1))
  20116. /* When displaying information for more than one file,
  20117. prefix the information with the file name. */
  20118. show_name = true;
  20119. else if (optind >= argc)
  20120. {
  20121. /* Ensure that the warning is always displayed. */
  20122. do_checks = true;
  20123. warn (_("Nothing to do.\n"));
  20124. usage (stderr);
  20125. }
  20126. err = false;
  20127. while (optind < argc)
  20128. if (! process_file (argv[optind++]))
  20129. err = true;
  20130. free (cmdline.dump_sects);
  20131. free (dump_ctf_symtab_name);
  20132. free (dump_ctf_strtab_name);
  20133. free (dump_ctf_parent_name);
  20134. return err ? EXIT_FAILURE : EXIT_SUCCESS;
  20135. }