readelf.c 492 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572
  1. /* readelf.c -- display contents of an ELF format file
  2. Copyright (C) 1998-2017 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. #ifdef HAVE_WCHAR_H
  37. #include <wchar.h>
  38. #endif
  39. #if __GNUC__ >= 2
  40. /* Define BFD64 here, even if our default architecture is 32 bit ELF
  41. as this will allow us to read in and parse 64bit and 32bit ELF files.
  42. Only do this if we believe that the compiler can support a 64 bit
  43. data type. For now we only rely on GCC being able to do this. */
  44. #define BFD64
  45. #endif
  46. #include "bfd.h"
  47. #include "bucomm.h"
  48. #include "elfcomm.h"
  49. #include "dwarf.h"
  50. #include "elf/common.h"
  51. #include "elf/external.h"
  52. #include "elf/internal.h"
  53. /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that
  54. we can obtain the H8 reloc numbers. We need these for the
  55. get_reloc_size() function. We include h8.h again after defining
  56. RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */
  57. #include "elf/h8.h"
  58. #undef _ELF_H8_H
  59. /* Undo the effects of #including reloc-macros.h. */
  60. #undef START_RELOC_NUMBERS
  61. #undef RELOC_NUMBER
  62. #undef FAKE_RELOC
  63. #undef EMPTY_RELOC
  64. #undef END_RELOC_NUMBERS
  65. #undef _RELOC_MACROS_H
  66. /* The following headers use the elf/reloc-macros.h file to
  67. automatically generate relocation recognition functions
  68. such as elf_mips_reloc_type() */
  69. #define RELOC_MACROS_GEN_FUNC
  70. #include "elf/aarch64.h"
  71. #include "elf/alpha.h"
  72. #include "elf/arc.h"
  73. #include "elf/arm.h"
  74. #include "elf/avr.h"
  75. #include "elf/bfin.h"
  76. #include "elf/cr16.h"
  77. #include "elf/cris.h"
  78. #include "elf/crx.h"
  79. #include "elf/d10v.h"
  80. #include "elf/d30v.h"
  81. #include "elf/dlx.h"
  82. #include "elf/epiphany.h"
  83. #include "elf/fr30.h"
  84. #include "elf/frv.h"
  85. #include "elf/ft32.h"
  86. #include "elf/h8.h"
  87. #include "elf/hppa.h"
  88. #include "elf/i386.h"
  89. #include "elf/i370.h"
  90. #include "elf/i860.h"
  91. #include "elf/i960.h"
  92. #include "elf/ia64.h"
  93. #include "elf/ip2k.h"
  94. #include "elf/lm32.h"
  95. #include "elf/iq2000.h"
  96. #include "elf/m32c.h"
  97. #include "elf/m32r.h"
  98. #include "elf/m68k.h"
  99. #include "elf/m68hc11.h"
  100. #include "elf/mcore.h"
  101. #include "elf/mep.h"
  102. #include "elf/metag.h"
  103. #include "elf/microblaze.h"
  104. #include "elf/mips.h"
  105. #include "elf/riscv.h"
  106. #include "elf/mmix.h"
  107. #include "elf/mn10200.h"
  108. #include "elf/mn10300.h"
  109. #include "elf/moxie.h"
  110. #include "elf/mt.h"
  111. #include "elf/msp430.h"
  112. #include "elf/nds32.h"
  113. #include "elf/nios2.h"
  114. #include "elf/or1k.h"
  115. #include "elf/pj.h"
  116. #include "elf/ppc.h"
  117. #include "elf/ppc64.h"
  118. #include "elf/pru.h"
  119. #include "elf/rl78.h"
  120. #include "elf/rx.h"
  121. #include "elf/s390.h"
  122. #include "elf/score.h"
  123. #include "elf/sh.h"
  124. #include "elf/sparc.h"
  125. #include "elf/spu.h"
  126. #include "elf/tic6x.h"
  127. #include "elf/tilegx.h"
  128. #include "elf/tilepro.h"
  129. #include "elf/v850.h"
  130. #include "elf/vax.h"
  131. #include "elf/visium.h"
  132. #include "elf/wasm32.h"
  133. #include "elf/x86-64.h"
  134. #include "elf/xc16x.h"
  135. #include "elf/xgate.h"
  136. #include "elf/xstormy16.h"
  137. #include "elf/xtensa.h"
  138. #include "getopt.h"
  139. #include "libiberty.h"
  140. #include "safe-ctype.h"
  141. #include "filenames.h"
  142. #ifndef offsetof
  143. #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
  144. #endif
  145. typedef struct elf_section_list
  146. {
  147. Elf_Internal_Shdr * hdr;
  148. struct elf_section_list * next;
  149. } elf_section_list;
  150. char * program_name = "readelf";
  151. static unsigned long archive_file_offset;
  152. static unsigned long archive_file_size;
  153. static bfd_size_type current_file_size;
  154. static unsigned long dynamic_addr;
  155. static bfd_size_type dynamic_size;
  156. static size_t dynamic_nent;
  157. static char * dynamic_strings;
  158. static unsigned long dynamic_strings_length;
  159. static char * string_table;
  160. static unsigned long string_table_length;
  161. static unsigned long num_dynamic_syms;
  162. static Elf_Internal_Sym * dynamic_symbols;
  163. static Elf_Internal_Syminfo * dynamic_syminfo;
  164. static unsigned long dynamic_syminfo_offset;
  165. static unsigned int dynamic_syminfo_nent;
  166. static char program_interpreter[PATH_MAX];
  167. static bfd_vma dynamic_info[DT_ENCODING];
  168. static bfd_vma dynamic_info_DT_GNU_HASH;
  169. static bfd_vma version_info[16];
  170. static Elf_Internal_Ehdr elf_header;
  171. static Elf_Internal_Shdr * section_headers;
  172. static Elf_Internal_Phdr * program_headers;
  173. static Elf_Internal_Dyn * dynamic_section;
  174. static elf_section_list * symtab_shndx_list;
  175. static bfd_boolean show_name = FALSE;
  176. static bfd_boolean do_dynamic = FALSE;
  177. static bfd_boolean do_syms = FALSE;
  178. static bfd_boolean do_dyn_syms = FALSE;
  179. static bfd_boolean do_reloc = FALSE;
  180. static bfd_boolean do_sections = FALSE;
  181. static bfd_boolean do_section_groups = FALSE;
  182. static bfd_boolean do_section_details = FALSE;
  183. static bfd_boolean do_segments = FALSE;
  184. static bfd_boolean do_unwind = FALSE;
  185. static bfd_boolean do_using_dynamic = FALSE;
  186. static bfd_boolean do_header = FALSE;
  187. static bfd_boolean do_dump = FALSE;
  188. static bfd_boolean do_version = FALSE;
  189. static bfd_boolean do_histogram = FALSE;
  190. static bfd_boolean do_debugging = FALSE;
  191. static bfd_boolean do_arch = FALSE;
  192. static bfd_boolean do_notes = FALSE;
  193. static bfd_boolean do_archive_index = FALSE;
  194. static bfd_boolean is_32bit_elf = FALSE;
  195. static bfd_boolean decompress_dumps = FALSE;
  196. struct group_list
  197. {
  198. struct group_list * next;
  199. unsigned int section_index;
  200. };
  201. struct group
  202. {
  203. struct group_list * root;
  204. unsigned int group_index;
  205. };
  206. static size_t group_count;
  207. static struct group * section_groups;
  208. static struct group ** section_headers_groups;
  209. /* Flag bits indicating particular types of dump. */
  210. #define HEX_DUMP (1 << 0) /* The -x command line switch. */
  211. #define DISASS_DUMP (1 << 1) /* The -i command line switch. */
  212. #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */
  213. #define STRING_DUMP (1 << 3) /* The -p command line switch. */
  214. #define RELOC_DUMP (1 << 4) /* The -R command line switch. */
  215. typedef unsigned char dump_type;
  216. /* A linked list of the section names for which dumps were requested. */
  217. struct dump_list_entry
  218. {
  219. char * name;
  220. dump_type type;
  221. struct dump_list_entry * next;
  222. };
  223. static struct dump_list_entry * dump_sects_byname;
  224. /* A dynamic array of flags indicating for which sections a dump
  225. has been requested via command line switches. */
  226. static dump_type * cmdline_dump_sects = NULL;
  227. static unsigned int num_cmdline_dump_sects = 0;
  228. /* A dynamic array of flags indicating for which sections a dump of
  229. some kind has been requested. It is reset on a per-object file
  230. basis and then initialised from the cmdline_dump_sects array,
  231. the results of interpreting the -w switch, and the
  232. dump_sects_byname list. */
  233. static dump_type * dump_sects = NULL;
  234. static unsigned int num_dump_sects = 0;
  235. /* How to print a vma value. */
  236. typedef enum print_mode
  237. {
  238. HEX,
  239. DEC,
  240. DEC_5,
  241. UNSIGNED,
  242. PREFIX_HEX,
  243. FULL_HEX,
  244. LONG_HEX
  245. }
  246. print_mode;
  247. /* Versioned symbol info. */
  248. enum versioned_symbol_info
  249. {
  250. symbol_undefined,
  251. symbol_hidden,
  252. symbol_public
  253. };
  254. static const char * get_symbol_version_string
  255. (FILE *, bfd_boolean, const char *, unsigned long, unsigned,
  256. Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *);
  257. #define UNKNOWN -1
  258. #define SECTION_NAME(X) \
  259. ((X) == NULL ? _("<none>") \
  260. : string_table == NULL ? _("<no-name>") \
  261. : ((X)->sh_name >= string_table_length ? _("<corrupt>") \
  262. : string_table + (X)->sh_name))
  263. #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
  264. #define GET_ELF_SYMBOLS(file, section, sym_count) \
  265. (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \
  266. : get_64bit_elf_symbols (file, section, sym_count))
  267. #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
  268. /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
  269. already been called and verified that the string exists. */
  270. #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
  271. #define REMOVE_ARCH_BITS(ADDR) \
  272. do \
  273. { \
  274. if (elf_header.e_machine == EM_ARM) \
  275. (ADDR) &= ~1; \
  276. } \
  277. while (0)
  278. /* Retrieve NMEMB structures, each SIZE bytes long from FILE starting at OFFSET +
  279. the offset of the current archive member, if we are examining an archive.
  280. Put the retrieved data into VAR, if it is not NULL. Otherwise allocate a buffer
  281. using malloc and fill that. In either case return the pointer to the start of
  282. the retrieved data or NULL if something went wrong. If something does go wrong
  283. and REASON is not NULL then emit an error message using REASON as part of the
  284. context. */
  285. static void *
  286. get_data (void * var, FILE * file, unsigned long offset, bfd_size_type size,
  287. bfd_size_type nmemb, const char * reason)
  288. {
  289. void * mvar;
  290. bfd_size_type amt = size * nmemb;
  291. if (size == 0 || nmemb == 0)
  292. return NULL;
  293. /* If the size_t type is smaller than the bfd_size_type, eg because
  294. you are building a 32-bit tool on a 64-bit host, then make sure
  295. that when the sizes are cast to (size_t) no information is lost. */
  296. if (sizeof (size_t) < sizeof (bfd_size_type)
  297. && ( (bfd_size_type) ((size_t) size) != size
  298. || (bfd_size_type) ((size_t) nmemb) != nmemb))
  299. {
  300. if (reason)
  301. error (_("Size truncation prevents reading 0x%" BFD_VMA_FMT "x"
  302. " elements of size 0x%" BFD_VMA_FMT "x for %s\n"),
  303. nmemb, size, reason);
  304. return NULL;
  305. }
  306. /* Check for size overflow. */
  307. if (amt < nmemb)
  308. {
  309. if (reason)
  310. error (_("Size overflow prevents reading 0x%" BFD_VMA_FMT "x"
  311. " elements of size 0x%" BFD_VMA_FMT "x for %s\n"),
  312. nmemb, size, reason);
  313. return NULL;
  314. }
  315. /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
  316. attempting to allocate memory when the read is bound to fail. */
  317. if (amt > current_file_size
  318. || offset + archive_file_offset + amt > current_file_size)
  319. {
  320. if (reason)
  321. error (_("Reading 0x%" BFD_VMA_FMT "x"
  322. " bytes extends past end of file for %s\n"),
  323. amt, reason);
  324. return NULL;
  325. }
  326. if (fseek (file, archive_file_offset + offset, SEEK_SET))
  327. {
  328. if (reason)
  329. error (_("Unable to seek to 0x%lx for %s\n"),
  330. archive_file_offset + offset, reason);
  331. return NULL;
  332. }
  333. mvar = var;
  334. if (mvar == NULL)
  335. {
  336. /* Check for overflow. */
  337. if (nmemb < (~(bfd_size_type) 0 - 1) / size)
  338. /* + 1 so that we can '\0' terminate invalid string table sections. */
  339. mvar = malloc ((size_t) amt + 1);
  340. if (mvar == NULL)
  341. {
  342. if (reason)
  343. error (_("Out of memory allocating 0x%" BFD_VMA_FMT "x"
  344. " bytes for %s\n"),
  345. amt, reason);
  346. return NULL;
  347. }
  348. ((char *) mvar)[amt] = '\0';
  349. }
  350. if (fread (mvar, (size_t) size, (size_t) nmemb, file) != nmemb)
  351. {
  352. if (reason)
  353. error (_("Unable to read in 0x%" BFD_VMA_FMT "x bytes of %s\n"),
  354. amt, reason);
  355. if (mvar != var)
  356. free (mvar);
  357. return NULL;
  358. }
  359. return mvar;
  360. }
  361. /* Print a VMA value in the MODE specified.
  362. Returns the number of characters displayed. */
  363. static unsigned int
  364. print_vma (bfd_vma vma, print_mode mode)
  365. {
  366. unsigned int nc = 0;
  367. switch (mode)
  368. {
  369. case FULL_HEX:
  370. nc = printf ("0x");
  371. /* Fall through. */
  372. case LONG_HEX:
  373. #ifdef BFD64
  374. if (is_32bit_elf)
  375. return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
  376. #endif
  377. printf_vma (vma);
  378. return nc + 16;
  379. case DEC_5:
  380. if (vma <= 99999)
  381. return printf ("%5" BFD_VMA_FMT "d", vma);
  382. /* Fall through. */
  383. case PREFIX_HEX:
  384. nc = printf ("0x");
  385. /* Fall through. */
  386. case HEX:
  387. return nc + printf ("%" BFD_VMA_FMT "x", vma);
  388. case DEC:
  389. return printf ("%" BFD_VMA_FMT "d", vma);
  390. case UNSIGNED:
  391. return printf ("%" BFD_VMA_FMT "u", vma);
  392. default:
  393. /* FIXME: Report unrecognised mode ? */
  394. return 0;
  395. }
  396. }
  397. /* Display a symbol on stdout. Handles the display of control characters and
  398. multibye characters (assuming the host environment supports them).
  399. Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true.
  400. If WIDTH is negative then ensure that the output is at least (- WIDTH) characters,
  401. padding as necessary.
  402. Returns the number of emitted characters. */
  403. static unsigned int
  404. print_symbol (signed int width, const char *symbol)
  405. {
  406. bfd_boolean extra_padding = FALSE;
  407. signed int num_printed = 0;
  408. #ifdef HAVE_MBSTATE_T
  409. mbstate_t state;
  410. #endif
  411. unsigned int width_remaining;
  412. if (width < 0)
  413. {
  414. /* Keep the width positive. This helps the code below. */
  415. width = - width;
  416. extra_padding = TRUE;
  417. }
  418. assert (width != 0);
  419. if (do_wide)
  420. /* Set the remaining width to a very large value.
  421. This simplifies the code below. */
  422. width_remaining = INT_MAX;
  423. else
  424. width_remaining = width;
  425. #ifdef HAVE_MBSTATE_T
  426. /* Initialise the multibyte conversion state. */
  427. memset (& state, 0, sizeof (state));
  428. #endif
  429. while (width_remaining)
  430. {
  431. size_t n;
  432. const char c = *symbol++;
  433. if (c == 0)
  434. break;
  435. /* Do not print control characters directly as they can affect terminal
  436. settings. Such characters usually appear in the names generated
  437. by the assembler for local labels. */
  438. if (ISCNTRL (c))
  439. {
  440. if (width_remaining < 2)
  441. break;
  442. printf ("^%c", c + 0x40);
  443. width_remaining -= 2;
  444. num_printed += 2;
  445. }
  446. else if (ISPRINT (c))
  447. {
  448. putchar (c);
  449. width_remaining --;
  450. num_printed ++;
  451. }
  452. else
  453. {
  454. #ifdef HAVE_MBSTATE_T
  455. wchar_t w;
  456. #endif
  457. /* Let printf do the hard work of displaying multibyte characters. */
  458. printf ("%.1s", symbol - 1);
  459. width_remaining --;
  460. num_printed ++;
  461. #ifdef HAVE_MBSTATE_T
  462. /* Try to find out how many bytes made up the character that was
  463. just printed. Advance the symbol pointer past the bytes that
  464. were displayed. */
  465. n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state);
  466. #else
  467. n = 1;
  468. #endif
  469. if (n != (size_t) -1 && n != (size_t) -2 && n > 0)
  470. symbol += (n - 1);
  471. }
  472. }
  473. if (extra_padding && num_printed < width)
  474. {
  475. /* Fill in the remaining spaces. */
  476. printf ("%-*s", width - num_printed, " ");
  477. num_printed = width;
  478. }
  479. return num_printed;
  480. }
  481. /* Returns a pointer to a static buffer containing a printable version of
  482. the given section's name. Like print_symbol, except that it does not try
  483. to print multibyte characters, it just interprets them as hex values. */
  484. static const char *
  485. printable_section_name (const Elf_Internal_Shdr * sec)
  486. {
  487. #define MAX_PRINT_SEC_NAME_LEN 128
  488. static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1];
  489. const char * name = SECTION_NAME (sec);
  490. char * buf = sec_name_buf;
  491. char c;
  492. unsigned int remaining = MAX_PRINT_SEC_NAME_LEN;
  493. while ((c = * name ++) != 0)
  494. {
  495. if (ISCNTRL (c))
  496. {
  497. if (remaining < 2)
  498. break;
  499. * buf ++ = '^';
  500. * buf ++ = c + 0x40;
  501. remaining -= 2;
  502. }
  503. else if (ISPRINT (c))
  504. {
  505. * buf ++ = c;
  506. remaining -= 1;
  507. }
  508. else
  509. {
  510. static char hex[17] = "0123456789ABCDEF";
  511. if (remaining < 4)
  512. break;
  513. * buf ++ = '<';
  514. * buf ++ = hex[(c & 0xf0) >> 4];
  515. * buf ++ = hex[c & 0x0f];
  516. * buf ++ = '>';
  517. remaining -= 4;
  518. }
  519. if (remaining == 0)
  520. break;
  521. }
  522. * buf = 0;
  523. return sec_name_buf;
  524. }
  525. static const char *
  526. printable_section_name_from_index (unsigned long ndx)
  527. {
  528. if (ndx >= elf_header.e_shnum)
  529. return _("<corrupt>");
  530. return printable_section_name (section_headers + ndx);
  531. }
  532. /* Return a pointer to section NAME, or NULL if no such section exists. */
  533. static Elf_Internal_Shdr *
  534. find_section (const char * name)
  535. {
  536. unsigned int i;
  537. for (i = 0; i < elf_header.e_shnum; i++)
  538. if (streq (SECTION_NAME (section_headers + i), name))
  539. return section_headers + i;
  540. return NULL;
  541. }
  542. /* Return a pointer to a section containing ADDR, or NULL if no such
  543. section exists. */
  544. static Elf_Internal_Shdr *
  545. find_section_by_address (bfd_vma addr)
  546. {
  547. unsigned int i;
  548. for (i = 0; i < elf_header.e_shnum; i++)
  549. {
  550. Elf_Internal_Shdr *sec = section_headers + i;
  551. if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size)
  552. return sec;
  553. }
  554. return NULL;
  555. }
  556. static Elf_Internal_Shdr *
  557. find_section_by_type (unsigned int type)
  558. {
  559. unsigned int i;
  560. for (i = 0; i < elf_header.e_shnum; i++)
  561. {
  562. Elf_Internal_Shdr *sec = section_headers + i;
  563. if (sec->sh_type == type)
  564. return sec;
  565. }
  566. return NULL;
  567. }
  568. /* Return a pointer to section NAME, or NULL if no such section exists,
  569. restricted to the list of sections given in SET. */
  570. static Elf_Internal_Shdr *
  571. find_section_in_set (const char * name, unsigned int * set)
  572. {
  573. unsigned int i;
  574. if (set != NULL)
  575. {
  576. while ((i = *set++) > 0)
  577. {
  578. /* See PR 21156 for a reproducer. */
  579. if (i >= elf_header.e_shnum)
  580. continue; /* FIXME: Should we issue an error message ? */
  581. if (streq (SECTION_NAME (section_headers + i), name))
  582. return section_headers + i;
  583. }
  584. }
  585. return find_section (name);
  586. }
  587. /* Read an unsigned LEB128 encoded value from DATA.
  588. Set *LENGTH_RETURN to the number of bytes read. */
  589. static inline unsigned long
  590. read_uleb128 (unsigned char * data,
  591. unsigned int * length_return,
  592. const unsigned char * const end)
  593. {
  594. return read_leb128 (data, length_return, FALSE, end);
  595. }
  596. /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
  597. This OS has so many departures from the ELF standard that we test it at
  598. many places. */
  599. static inline bfd_boolean
  600. is_ia64_vms (void)
  601. {
  602. return elf_header.e_machine == EM_IA_64
  603. && elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS;
  604. }
  605. /* Guess the relocation size commonly used by the specific machines. */
  606. static bfd_boolean
  607. guess_is_rela (unsigned int e_machine)
  608. {
  609. switch (e_machine)
  610. {
  611. /* Targets that use REL relocations. */
  612. case EM_386:
  613. case EM_IAMCU:
  614. case EM_960:
  615. case EM_ARM:
  616. case EM_D10V:
  617. case EM_CYGNUS_D10V:
  618. case EM_DLX:
  619. case EM_MIPS:
  620. case EM_MIPS_RS3_LE:
  621. case EM_CYGNUS_M32R:
  622. case EM_SCORE:
  623. case EM_XGATE:
  624. return FALSE;
  625. /* Targets that use RELA relocations. */
  626. case EM_68K:
  627. case EM_860:
  628. case EM_AARCH64:
  629. case EM_ADAPTEVA_EPIPHANY:
  630. case EM_ALPHA:
  631. case EM_ALTERA_NIOS2:
  632. case EM_ARC:
  633. case EM_ARC_COMPACT:
  634. case EM_ARC_COMPACT2:
  635. case EM_AVR:
  636. case EM_AVR_OLD:
  637. case EM_BLACKFIN:
  638. case EM_CR16:
  639. case EM_CRIS:
  640. case EM_CRX:
  641. case EM_D30V:
  642. case EM_CYGNUS_D30V:
  643. case EM_FR30:
  644. case EM_FT32:
  645. case EM_CYGNUS_FR30:
  646. case EM_CYGNUS_FRV:
  647. case EM_H8S:
  648. case EM_H8_300:
  649. case EM_H8_300H:
  650. case EM_IA_64:
  651. case EM_IP2K:
  652. case EM_IP2K_OLD:
  653. case EM_IQ2000:
  654. case EM_LATTICEMICO32:
  655. case EM_M32C_OLD:
  656. case EM_M32C:
  657. case EM_M32R:
  658. case EM_MCORE:
  659. case EM_CYGNUS_MEP:
  660. case EM_METAG:
  661. case EM_MMIX:
  662. case EM_MN10200:
  663. case EM_CYGNUS_MN10200:
  664. case EM_MN10300:
  665. case EM_CYGNUS_MN10300:
  666. case EM_MOXIE:
  667. case EM_MSP430:
  668. case EM_MSP430_OLD:
  669. case EM_MT:
  670. case EM_NDS32:
  671. case EM_NIOS32:
  672. case EM_OR1K:
  673. case EM_PPC64:
  674. case EM_PPC:
  675. case EM_TI_PRU:
  676. case EM_RISCV:
  677. case EM_RL78:
  678. case EM_RX:
  679. case EM_S390:
  680. case EM_S390_OLD:
  681. case EM_SH:
  682. case EM_SPARC:
  683. case EM_SPARC32PLUS:
  684. case EM_SPARCV9:
  685. case EM_SPU:
  686. case EM_TI_C6000:
  687. case EM_TILEGX:
  688. case EM_TILEPRO:
  689. case EM_V800:
  690. case EM_V850:
  691. case EM_CYGNUS_V850:
  692. case EM_VAX:
  693. case EM_VISIUM:
  694. case EM_X86_64:
  695. case EM_L1OM:
  696. case EM_K1OM:
  697. case EM_XSTORMY16:
  698. case EM_XTENSA:
  699. case EM_XTENSA_OLD:
  700. case EM_MICROBLAZE:
  701. case EM_MICROBLAZE_OLD:
  702. case EM_WEBASSEMBLY:
  703. return TRUE;
  704. case EM_68HC05:
  705. case EM_68HC08:
  706. case EM_68HC11:
  707. case EM_68HC16:
  708. case EM_FX66:
  709. case EM_ME16:
  710. case EM_MMA:
  711. case EM_NCPU:
  712. case EM_NDR1:
  713. case EM_PCP:
  714. case EM_ST100:
  715. case EM_ST19:
  716. case EM_ST7:
  717. case EM_ST9PLUS:
  718. case EM_STARCORE:
  719. case EM_SVX:
  720. case EM_TINYJ:
  721. default:
  722. warn (_("Don't know about relocations on this machine architecture\n"));
  723. return FALSE;
  724. }
  725. }
  726. /* Load RELA type relocations from FILE at REL_OFFSET extending for REL_SIZE bytes.
  727. Returns TRUE upon success, FALSE otherwise. If successful then a
  728. pointer to a malloc'ed buffer containing the relocs is placed in *RELASP,
  729. and the number of relocs loaded is placed in *NRELASP. It is the caller's
  730. responsibility to free the allocated buffer. */
  731. static bfd_boolean
  732. slurp_rela_relocs (FILE * file,
  733. unsigned long rel_offset,
  734. unsigned long rel_size,
  735. Elf_Internal_Rela ** relasp,
  736. unsigned long * nrelasp)
  737. {
  738. Elf_Internal_Rela * relas;
  739. size_t nrelas;
  740. unsigned int i;
  741. if (is_32bit_elf)
  742. {
  743. Elf32_External_Rela * erelas;
  744. erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset, 1,
  745. rel_size, _("32-bit relocation data"));
  746. if (!erelas)
  747. return FALSE;
  748. nrelas = rel_size / sizeof (Elf32_External_Rela);
  749. relas = (Elf_Internal_Rela *) cmalloc (nrelas,
  750. sizeof (Elf_Internal_Rela));
  751. if (relas == NULL)
  752. {
  753. free (erelas);
  754. error (_("out of memory parsing relocs\n"));
  755. return FALSE;
  756. }
  757. for (i = 0; i < nrelas; i++)
  758. {
  759. relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
  760. relas[i].r_info = BYTE_GET (erelas[i].r_info);
  761. relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
  762. }
  763. free (erelas);
  764. }
  765. else
  766. {
  767. Elf64_External_Rela * erelas;
  768. erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset, 1,
  769. rel_size, _("64-bit relocation data"));
  770. if (!erelas)
  771. return FALSE;
  772. nrelas = rel_size / sizeof (Elf64_External_Rela);
  773. relas = (Elf_Internal_Rela *) cmalloc (nrelas,
  774. sizeof (Elf_Internal_Rela));
  775. if (relas == NULL)
  776. {
  777. free (erelas);
  778. error (_("out of memory parsing relocs\n"));
  779. return FALSE;
  780. }
  781. for (i = 0; i < nrelas; i++)
  782. {
  783. relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
  784. relas[i].r_info = BYTE_GET (erelas[i].r_info);
  785. relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend);
  786. /* The #ifdef BFD64 below is to prevent a compile time
  787. warning. We know that if we do not have a 64 bit data
  788. type that we will never execute this code anyway. */
  789. #ifdef BFD64
  790. if (elf_header.e_machine == EM_MIPS
  791. && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
  792. {
  793. /* In little-endian objects, r_info isn't really a
  794. 64-bit little-endian value: it has a 32-bit
  795. little-endian symbol index followed by four
  796. individual byte fields. Reorder INFO
  797. accordingly. */
  798. bfd_vma inf = relas[i].r_info;
  799. inf = (((inf & 0xffffffff) << 32)
  800. | ((inf >> 56) & 0xff)
  801. | ((inf >> 40) & 0xff00)
  802. | ((inf >> 24) & 0xff0000)
  803. | ((inf >> 8) & 0xff000000));
  804. relas[i].r_info = inf;
  805. }
  806. #endif /* BFD64 */
  807. }
  808. free (erelas);
  809. }
  810. *relasp = relas;
  811. *nrelasp = nrelas;
  812. return TRUE;
  813. }
  814. /* Load REL type relocations from FILE at REL_OFFSET extending for REL_SIZE bytes.
  815. Returns TRUE upon success, FALSE otherwise. If successful then a
  816. pointer to a malloc'ed buffer containing the relocs is placed in *RELSP,
  817. and the number of relocs loaded is placed in *NRELSP. It is the caller's
  818. responsibility to free the allocated buffer. */
  819. static bfd_boolean
  820. slurp_rel_relocs (FILE * file,
  821. unsigned long rel_offset,
  822. unsigned long rel_size,
  823. Elf_Internal_Rela ** relsp,
  824. unsigned long * nrelsp)
  825. {
  826. Elf_Internal_Rela * rels;
  827. size_t nrels;
  828. unsigned int i;
  829. if (is_32bit_elf)
  830. {
  831. Elf32_External_Rel * erels;
  832. erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset, 1,
  833. rel_size, _("32-bit relocation data"));
  834. if (!erels)
  835. return FALSE;
  836. nrels = rel_size / sizeof (Elf32_External_Rel);
  837. rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
  838. if (rels == NULL)
  839. {
  840. free (erels);
  841. error (_("out of memory parsing relocs\n"));
  842. return FALSE;
  843. }
  844. for (i = 0; i < nrels; i++)
  845. {
  846. rels[i].r_offset = BYTE_GET (erels[i].r_offset);
  847. rels[i].r_info = BYTE_GET (erels[i].r_info);
  848. rels[i].r_addend = 0;
  849. }
  850. free (erels);
  851. }
  852. else
  853. {
  854. Elf64_External_Rel * erels;
  855. erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset, 1,
  856. rel_size, _("64-bit relocation data"));
  857. if (!erels)
  858. return FALSE;
  859. nrels = rel_size / sizeof (Elf64_External_Rel);
  860. rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela));
  861. if (rels == NULL)
  862. {
  863. free (erels);
  864. error (_("out of memory parsing relocs\n"));
  865. return FALSE;
  866. }
  867. for (i = 0; i < nrels; i++)
  868. {
  869. rels[i].r_offset = BYTE_GET (erels[i].r_offset);
  870. rels[i].r_info = BYTE_GET (erels[i].r_info);
  871. rels[i].r_addend = 0;
  872. /* The #ifdef BFD64 below is to prevent a compile time
  873. warning. We know that if we do not have a 64 bit data
  874. type that we will never execute this code anyway. */
  875. #ifdef BFD64
  876. if (elf_header.e_machine == EM_MIPS
  877. && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
  878. {
  879. /* In little-endian objects, r_info isn't really a
  880. 64-bit little-endian value: it has a 32-bit
  881. little-endian symbol index followed by four
  882. individual byte fields. Reorder INFO
  883. accordingly. */
  884. bfd_vma inf = rels[i].r_info;
  885. inf = (((inf & 0xffffffff) << 32)
  886. | ((inf >> 56) & 0xff)
  887. | ((inf >> 40) & 0xff00)
  888. | ((inf >> 24) & 0xff0000)
  889. | ((inf >> 8) & 0xff000000));
  890. rels[i].r_info = inf;
  891. }
  892. #endif /* BFD64 */
  893. }
  894. free (erels);
  895. }
  896. *relsp = rels;
  897. *nrelsp = nrels;
  898. return TRUE;
  899. }
  900. /* Returns the reloc type extracted from the reloc info field. */
  901. static unsigned int
  902. get_reloc_type (bfd_vma reloc_info)
  903. {
  904. if (is_32bit_elf)
  905. return ELF32_R_TYPE (reloc_info);
  906. switch (elf_header.e_machine)
  907. {
  908. case EM_MIPS:
  909. /* Note: We assume that reloc_info has already been adjusted for us. */
  910. return ELF64_MIPS_R_TYPE (reloc_info);
  911. case EM_SPARCV9:
  912. return ELF64_R_TYPE_ID (reloc_info);
  913. default:
  914. return ELF64_R_TYPE (reloc_info);
  915. }
  916. }
  917. /* Return the symbol index extracted from the reloc info field. */
  918. static bfd_vma
  919. get_reloc_symindex (bfd_vma reloc_info)
  920. {
  921. return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
  922. }
  923. static inline bfd_boolean
  924. uses_msp430x_relocs (void)
  925. {
  926. return
  927. elf_header.e_machine == EM_MSP430 /* Paranoia. */
  928. /* GCC uses osabi == ELFOSBI_STANDALONE. */
  929. && (((elf_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X)
  930. /* TI compiler uses ELFOSABI_NONE. */
  931. || (elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE));
  932. }
  933. /* Display the contents of the relocation data found at the specified
  934. offset. */
  935. static bfd_boolean
  936. dump_relocations (FILE * file,
  937. unsigned long rel_offset,
  938. unsigned long rel_size,
  939. Elf_Internal_Sym * symtab,
  940. unsigned long nsyms,
  941. char * strtab,
  942. unsigned long strtablen,
  943. int is_rela,
  944. bfd_boolean is_dynsym)
  945. {
  946. unsigned long i;
  947. Elf_Internal_Rela * rels;
  948. bfd_boolean res = TRUE;
  949. if (is_rela == UNKNOWN)
  950. is_rela = guess_is_rela (elf_header.e_machine);
  951. if (is_rela)
  952. {
  953. if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
  954. return FALSE;
  955. }
  956. else
  957. {
  958. if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
  959. return FALSE;
  960. }
  961. if (is_32bit_elf)
  962. {
  963. if (is_rela)
  964. {
  965. if (do_wide)
  966. printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
  967. else
  968. printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
  969. }
  970. else
  971. {
  972. if (do_wide)
  973. printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
  974. else
  975. printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
  976. }
  977. }
  978. else
  979. {
  980. if (is_rela)
  981. {
  982. if (do_wide)
  983. printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
  984. else
  985. printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
  986. }
  987. else
  988. {
  989. if (do_wide)
  990. printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
  991. else
  992. printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
  993. }
  994. }
  995. for (i = 0; i < rel_size; i++)
  996. {
  997. const char * rtype;
  998. bfd_vma offset;
  999. bfd_vma inf;
  1000. bfd_vma symtab_index;
  1001. bfd_vma type;
  1002. offset = rels[i].r_offset;
  1003. inf = rels[i].r_info;
  1004. type = get_reloc_type (inf);
  1005. symtab_index = get_reloc_symindex (inf);
  1006. if (is_32bit_elf)
  1007. {
  1008. printf ("%8.8lx %8.8lx ",
  1009. (unsigned long) offset & 0xffffffff,
  1010. (unsigned long) inf & 0xffffffff);
  1011. }
  1012. else
  1013. {
  1014. #if BFD_HOST_64BIT_LONG
  1015. printf (do_wide
  1016. ? "%16.16lx %16.16lx "
  1017. : "%12.12lx %12.12lx ",
  1018. offset, inf);
  1019. #elif BFD_HOST_64BIT_LONG_LONG
  1020. #ifndef __MSVCRT__
  1021. printf (do_wide
  1022. ? "%16.16llx %16.16llx "
  1023. : "%12.12llx %12.12llx ",
  1024. offset, inf);
  1025. #else
  1026. printf (do_wide
  1027. ? "%16.16I64x %16.16I64x "
  1028. : "%12.12I64x %12.12I64x ",
  1029. offset, inf);
  1030. #endif
  1031. #else
  1032. printf (do_wide
  1033. ? "%8.8lx%8.8lx %8.8lx%8.8lx "
  1034. : "%4.4lx%8.8lx %4.4lx%8.8lx ",
  1035. _bfd_int64_high (offset),
  1036. _bfd_int64_low (offset),
  1037. _bfd_int64_high (inf),
  1038. _bfd_int64_low (inf));
  1039. #endif
  1040. }
  1041. switch (elf_header.e_machine)
  1042. {
  1043. default:
  1044. rtype = NULL;
  1045. break;
  1046. case EM_AARCH64:
  1047. rtype = elf_aarch64_reloc_type (type);
  1048. break;
  1049. case EM_M32R:
  1050. case EM_CYGNUS_M32R:
  1051. rtype = elf_m32r_reloc_type (type);
  1052. break;
  1053. case EM_386:
  1054. case EM_IAMCU:
  1055. rtype = elf_i386_reloc_type (type);
  1056. break;
  1057. case EM_68HC11:
  1058. case EM_68HC12:
  1059. rtype = elf_m68hc11_reloc_type (type);
  1060. break;
  1061. case EM_68K:
  1062. rtype = elf_m68k_reloc_type (type);
  1063. break;
  1064. case EM_960:
  1065. rtype = elf_i960_reloc_type (type);
  1066. break;
  1067. case EM_AVR:
  1068. case EM_AVR_OLD:
  1069. rtype = elf_avr_reloc_type (type);
  1070. break;
  1071. case EM_OLD_SPARCV9:
  1072. case EM_SPARC32PLUS:
  1073. case EM_SPARCV9:
  1074. case EM_SPARC:
  1075. rtype = elf_sparc_reloc_type (type);
  1076. break;
  1077. case EM_SPU:
  1078. rtype = elf_spu_reloc_type (type);
  1079. break;
  1080. case EM_V800:
  1081. rtype = v800_reloc_type (type);
  1082. break;
  1083. case EM_V850:
  1084. case EM_CYGNUS_V850:
  1085. rtype = v850_reloc_type (type);
  1086. break;
  1087. case EM_D10V:
  1088. case EM_CYGNUS_D10V:
  1089. rtype = elf_d10v_reloc_type (type);
  1090. break;
  1091. case EM_D30V:
  1092. case EM_CYGNUS_D30V:
  1093. rtype = elf_d30v_reloc_type (type);
  1094. break;
  1095. case EM_DLX:
  1096. rtype = elf_dlx_reloc_type (type);
  1097. break;
  1098. case EM_SH:
  1099. rtype = elf_sh_reloc_type (type);
  1100. break;
  1101. case EM_MN10300:
  1102. case EM_CYGNUS_MN10300:
  1103. rtype = elf_mn10300_reloc_type (type);
  1104. break;
  1105. case EM_MN10200:
  1106. case EM_CYGNUS_MN10200:
  1107. rtype = elf_mn10200_reloc_type (type);
  1108. break;
  1109. case EM_FR30:
  1110. case EM_CYGNUS_FR30:
  1111. rtype = elf_fr30_reloc_type (type);
  1112. break;
  1113. case EM_CYGNUS_FRV:
  1114. rtype = elf_frv_reloc_type (type);
  1115. break;
  1116. case EM_FT32:
  1117. rtype = elf_ft32_reloc_type (type);
  1118. break;
  1119. case EM_MCORE:
  1120. rtype = elf_mcore_reloc_type (type);
  1121. break;
  1122. case EM_MMIX:
  1123. rtype = elf_mmix_reloc_type (type);
  1124. break;
  1125. case EM_MOXIE:
  1126. rtype = elf_moxie_reloc_type (type);
  1127. break;
  1128. case EM_MSP430:
  1129. if (uses_msp430x_relocs ())
  1130. {
  1131. rtype = elf_msp430x_reloc_type (type);
  1132. break;
  1133. }
  1134. /* Fall through. */
  1135. case EM_MSP430_OLD:
  1136. rtype = elf_msp430_reloc_type (type);
  1137. break;
  1138. case EM_NDS32:
  1139. rtype = elf_nds32_reloc_type (type);
  1140. break;
  1141. case EM_PPC:
  1142. rtype = elf_ppc_reloc_type (type);
  1143. break;
  1144. case EM_PPC64:
  1145. rtype = elf_ppc64_reloc_type (type);
  1146. break;
  1147. case EM_MIPS:
  1148. case EM_MIPS_RS3_LE:
  1149. rtype = elf_mips_reloc_type (type);
  1150. break;
  1151. case EM_RISCV:
  1152. rtype = elf_riscv_reloc_type (type);
  1153. break;
  1154. case EM_ALPHA:
  1155. rtype = elf_alpha_reloc_type (type);
  1156. break;
  1157. case EM_ARM:
  1158. rtype = elf_arm_reloc_type (type);
  1159. break;
  1160. case EM_ARC:
  1161. case EM_ARC_COMPACT:
  1162. case EM_ARC_COMPACT2:
  1163. rtype = elf_arc_reloc_type (type);
  1164. break;
  1165. case EM_PARISC:
  1166. rtype = elf_hppa_reloc_type (type);
  1167. break;
  1168. case EM_H8_300:
  1169. case EM_H8_300H:
  1170. case EM_H8S:
  1171. rtype = elf_h8_reloc_type (type);
  1172. break;
  1173. case EM_OR1K:
  1174. rtype = elf_or1k_reloc_type (type);
  1175. break;
  1176. case EM_PJ:
  1177. case EM_PJ_OLD:
  1178. rtype = elf_pj_reloc_type (type);
  1179. break;
  1180. case EM_IA_64:
  1181. rtype = elf_ia64_reloc_type (type);
  1182. break;
  1183. case EM_CRIS:
  1184. rtype = elf_cris_reloc_type (type);
  1185. break;
  1186. case EM_860:
  1187. rtype = elf_i860_reloc_type (type);
  1188. break;
  1189. case EM_X86_64:
  1190. case EM_L1OM:
  1191. case EM_K1OM:
  1192. rtype = elf_x86_64_reloc_type (type);
  1193. break;
  1194. case EM_S370:
  1195. rtype = i370_reloc_type (type);
  1196. break;
  1197. case EM_S390_OLD:
  1198. case EM_S390:
  1199. rtype = elf_s390_reloc_type (type);
  1200. break;
  1201. case EM_SCORE:
  1202. rtype = elf_score_reloc_type (type);
  1203. break;
  1204. case EM_XSTORMY16:
  1205. rtype = elf_xstormy16_reloc_type (type);
  1206. break;
  1207. case EM_CRX:
  1208. rtype = elf_crx_reloc_type (type);
  1209. break;
  1210. case EM_VAX:
  1211. rtype = elf_vax_reloc_type (type);
  1212. break;
  1213. case EM_VISIUM:
  1214. rtype = elf_visium_reloc_type (type);
  1215. break;
  1216. case EM_ADAPTEVA_EPIPHANY:
  1217. rtype = elf_epiphany_reloc_type (type);
  1218. break;
  1219. case EM_IP2K:
  1220. case EM_IP2K_OLD:
  1221. rtype = elf_ip2k_reloc_type (type);
  1222. break;
  1223. case EM_IQ2000:
  1224. rtype = elf_iq2000_reloc_type (type);
  1225. break;
  1226. case EM_XTENSA_OLD:
  1227. case EM_XTENSA:
  1228. rtype = elf_xtensa_reloc_type (type);
  1229. break;
  1230. case EM_LATTICEMICO32:
  1231. rtype = elf_lm32_reloc_type (type);
  1232. break;
  1233. case EM_M32C_OLD:
  1234. case EM_M32C:
  1235. rtype = elf_m32c_reloc_type (type);
  1236. break;
  1237. case EM_MT:
  1238. rtype = elf_mt_reloc_type (type);
  1239. break;
  1240. case EM_BLACKFIN:
  1241. rtype = elf_bfin_reloc_type (type);
  1242. break;
  1243. case EM_CYGNUS_MEP:
  1244. rtype = elf_mep_reloc_type (type);
  1245. break;
  1246. case EM_CR16:
  1247. rtype = elf_cr16_reloc_type (type);
  1248. break;
  1249. case EM_MICROBLAZE:
  1250. case EM_MICROBLAZE_OLD:
  1251. rtype = elf_microblaze_reloc_type (type);
  1252. break;
  1253. case EM_RL78:
  1254. rtype = elf_rl78_reloc_type (type);
  1255. break;
  1256. case EM_RX:
  1257. rtype = elf_rx_reloc_type (type);
  1258. break;
  1259. case EM_METAG:
  1260. rtype = elf_metag_reloc_type (type);
  1261. break;
  1262. case EM_XC16X:
  1263. case EM_C166:
  1264. rtype = elf_xc16x_reloc_type (type);
  1265. break;
  1266. case EM_TI_C6000:
  1267. rtype = elf_tic6x_reloc_type (type);
  1268. break;
  1269. case EM_TILEGX:
  1270. rtype = elf_tilegx_reloc_type (type);
  1271. break;
  1272. case EM_TILEPRO:
  1273. rtype = elf_tilepro_reloc_type (type);
  1274. break;
  1275. case EM_WEBASSEMBLY:
  1276. rtype = elf_wasm32_reloc_type (type);
  1277. break;
  1278. case EM_XGATE:
  1279. rtype = elf_xgate_reloc_type (type);
  1280. break;
  1281. case EM_ALTERA_NIOS2:
  1282. rtype = elf_nios2_reloc_type (type);
  1283. break;
  1284. case EM_TI_PRU:
  1285. rtype = elf_pru_reloc_type (type);
  1286. break;
  1287. }
  1288. if (rtype == NULL)
  1289. printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff);
  1290. else
  1291. printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
  1292. if (elf_header.e_machine == EM_ALPHA
  1293. && rtype != NULL
  1294. && streq (rtype, "R_ALPHA_LITUSE")
  1295. && is_rela)
  1296. {
  1297. switch (rels[i].r_addend)
  1298. {
  1299. case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
  1300. case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
  1301. case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
  1302. case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
  1303. case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
  1304. case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
  1305. case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
  1306. default: rtype = NULL;
  1307. }
  1308. if (rtype)
  1309. printf (" (%s)", rtype);
  1310. else
  1311. {
  1312. putchar (' ');
  1313. printf (_("<unknown addend: %lx>"),
  1314. (unsigned long) rels[i].r_addend);
  1315. res = FALSE;
  1316. }
  1317. }
  1318. else if (symtab_index)
  1319. {
  1320. if (symtab == NULL || symtab_index >= nsyms)
  1321. {
  1322. error (_(" bad symbol index: %08lx in reloc"), (unsigned long) symtab_index);
  1323. res = FALSE;
  1324. }
  1325. else
  1326. {
  1327. Elf_Internal_Sym * psym;
  1328. const char * version_string;
  1329. enum versioned_symbol_info sym_info;
  1330. unsigned short vna_other;
  1331. psym = symtab + symtab_index;
  1332. version_string
  1333. = get_symbol_version_string (file, is_dynsym,
  1334. strtab, strtablen,
  1335. symtab_index,
  1336. psym,
  1337. &sym_info,
  1338. &vna_other);
  1339. printf (" ");
  1340. if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC)
  1341. {
  1342. const char * name;
  1343. unsigned int len;
  1344. unsigned int width = is_32bit_elf ? 8 : 14;
  1345. /* Relocations against GNU_IFUNC symbols do not use the value
  1346. of the symbol as the address to relocate against. Instead
  1347. they invoke the function named by the symbol and use its
  1348. result as the address for relocation.
  1349. To indicate this to the user, do not display the value of
  1350. the symbol in the "Symbols's Value" field. Instead show
  1351. its name followed by () as a hint that the symbol is
  1352. invoked. */
  1353. if (strtab == NULL
  1354. || psym->st_name == 0
  1355. || psym->st_name >= strtablen)
  1356. name = "??";
  1357. else
  1358. name = strtab + psym->st_name;
  1359. len = print_symbol (width, name);
  1360. if (version_string)
  1361. printf (sym_info == symbol_public ? "@@%s" : "@%s",
  1362. version_string);
  1363. printf ("()%-*s", len <= width ? (width + 1) - len : 1, " ");
  1364. }
  1365. else
  1366. {
  1367. print_vma (psym->st_value, LONG_HEX);
  1368. printf (is_32bit_elf ? " " : " ");
  1369. }
  1370. if (psym->st_name == 0)
  1371. {
  1372. const char * sec_name = "<null>";
  1373. char name_buf[40];
  1374. if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
  1375. {
  1376. if (psym->st_shndx < elf_header.e_shnum)
  1377. sec_name = SECTION_NAME (section_headers + psym->st_shndx);
  1378. else if (psym->st_shndx == SHN_ABS)
  1379. sec_name = "ABS";
  1380. else if (psym->st_shndx == SHN_COMMON)
  1381. sec_name = "COMMON";
  1382. else if ((elf_header.e_machine == EM_MIPS
  1383. && psym->st_shndx == SHN_MIPS_SCOMMON)
  1384. || (elf_header.e_machine == EM_TI_C6000
  1385. && psym->st_shndx == SHN_TIC6X_SCOMMON))
  1386. sec_name = "SCOMMON";
  1387. else if (elf_header.e_machine == EM_MIPS
  1388. && psym->st_shndx == SHN_MIPS_SUNDEFINED)
  1389. sec_name = "SUNDEF";
  1390. else if ((elf_header.e_machine == EM_X86_64
  1391. || elf_header.e_machine == EM_L1OM
  1392. || elf_header.e_machine == EM_K1OM)
  1393. && psym->st_shndx == SHN_X86_64_LCOMMON)
  1394. sec_name = "LARGE_COMMON";
  1395. else if (elf_header.e_machine == EM_IA_64
  1396. && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
  1397. && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
  1398. sec_name = "ANSI_COM";
  1399. else if (is_ia64_vms ()
  1400. && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
  1401. sec_name = "VMS_SYMVEC";
  1402. else
  1403. {
  1404. sprintf (name_buf, "<section 0x%x>",
  1405. (unsigned int) psym->st_shndx);
  1406. sec_name = name_buf;
  1407. }
  1408. }
  1409. print_symbol (22, sec_name);
  1410. }
  1411. else if (strtab == NULL)
  1412. printf (_("<string table index: %3ld>"), psym->st_name);
  1413. else if (psym->st_name >= strtablen)
  1414. {
  1415. error (_("<corrupt string table index: %3ld>"), psym->st_name);
  1416. res = FALSE;
  1417. }
  1418. else
  1419. {
  1420. print_symbol (22, strtab + psym->st_name);
  1421. if (version_string)
  1422. printf (sym_info == symbol_public ? "@@%s" : "@%s",
  1423. version_string);
  1424. }
  1425. if (is_rela)
  1426. {
  1427. bfd_vma off = rels[i].r_addend;
  1428. if ((bfd_signed_vma) off < 0)
  1429. printf (" - %" BFD_VMA_FMT "x", - off);
  1430. else
  1431. printf (" + %" BFD_VMA_FMT "x", off);
  1432. }
  1433. }
  1434. }
  1435. else if (is_rela)
  1436. {
  1437. bfd_vma off = rels[i].r_addend;
  1438. printf ("%*c", is_32bit_elf ? 12 : 20, ' ');
  1439. if ((bfd_signed_vma) off < 0)
  1440. printf ("-%" BFD_VMA_FMT "x", - off);
  1441. else
  1442. printf ("%" BFD_VMA_FMT "x", off);
  1443. }
  1444. if (elf_header.e_machine == EM_SPARCV9
  1445. && rtype != NULL
  1446. && streq (rtype, "R_SPARC_OLO10"))
  1447. printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf));
  1448. putchar ('\n');
  1449. #ifdef BFD64
  1450. if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
  1451. {
  1452. bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf);
  1453. bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf);
  1454. const char * rtype2 = elf_mips_reloc_type (type2);
  1455. const char * rtype3 = elf_mips_reloc_type (type3);
  1456. printf (" Type2: ");
  1457. if (rtype2 == NULL)
  1458. printf (_("unrecognized: %-7lx"),
  1459. (unsigned long) type2 & 0xffffffff);
  1460. else
  1461. printf ("%-17.17s", rtype2);
  1462. printf ("\n Type3: ");
  1463. if (rtype3 == NULL)
  1464. printf (_("unrecognized: %-7lx"),
  1465. (unsigned long) type3 & 0xffffffff);
  1466. else
  1467. printf ("%-17.17s", rtype3);
  1468. putchar ('\n');
  1469. }
  1470. #endif /* BFD64 */
  1471. }
  1472. free (rels);
  1473. return res;
  1474. }
  1475. static const char *
  1476. get_mips_dynamic_type (unsigned long type)
  1477. {
  1478. switch (type)
  1479. {
  1480. case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
  1481. case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
  1482. case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
  1483. case DT_MIPS_IVERSION: return "MIPS_IVERSION";
  1484. case DT_MIPS_FLAGS: return "MIPS_FLAGS";
  1485. case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
  1486. case DT_MIPS_MSYM: return "MIPS_MSYM";
  1487. case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
  1488. case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
  1489. case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
  1490. case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
  1491. case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
  1492. case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
  1493. case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
  1494. case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
  1495. case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
  1496. case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
  1497. case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL";
  1498. case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
  1499. case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
  1500. case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
  1501. case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
  1502. case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
  1503. case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
  1504. case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
  1505. case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
  1506. case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
  1507. case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
  1508. case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
  1509. case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
  1510. case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
  1511. case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
  1512. case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
  1513. case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
  1514. case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
  1515. case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
  1516. case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
  1517. case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
  1518. case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
  1519. case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
  1520. case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
  1521. case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
  1522. case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
  1523. case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
  1524. case DT_MIPS_PLTGOT: return "MIPS_PLTGOT";
  1525. case DT_MIPS_RWPLT: return "MIPS_RWPLT";
  1526. default:
  1527. return NULL;
  1528. }
  1529. }
  1530. static const char *
  1531. get_sparc64_dynamic_type (unsigned long type)
  1532. {
  1533. switch (type)
  1534. {
  1535. case DT_SPARC_REGISTER: return "SPARC_REGISTER";
  1536. default:
  1537. return NULL;
  1538. }
  1539. }
  1540. static const char *
  1541. get_ppc_dynamic_type (unsigned long type)
  1542. {
  1543. switch (type)
  1544. {
  1545. case DT_PPC_GOT: return "PPC_GOT";
  1546. case DT_PPC_OPT: return "PPC_OPT";
  1547. default:
  1548. return NULL;
  1549. }
  1550. }
  1551. static const char *
  1552. get_ppc64_dynamic_type (unsigned long type)
  1553. {
  1554. switch (type)
  1555. {
  1556. case DT_PPC64_GLINK: return "PPC64_GLINK";
  1557. case DT_PPC64_OPD: return "PPC64_OPD";
  1558. case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
  1559. case DT_PPC64_OPT: return "PPC64_OPT";
  1560. default:
  1561. return NULL;
  1562. }
  1563. }
  1564. static const char *
  1565. get_parisc_dynamic_type (unsigned long type)
  1566. {
  1567. switch (type)
  1568. {
  1569. case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
  1570. case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
  1571. case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
  1572. case DT_HP_UX10_INIT: return "HP_UX10_INIT";
  1573. case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
  1574. case DT_HP_PREINIT: return "HP_PREINIT";
  1575. case DT_HP_PREINITSZ: return "HP_PREINITSZ";
  1576. case DT_HP_NEEDED: return "HP_NEEDED";
  1577. case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
  1578. case DT_HP_CHECKSUM: return "HP_CHECKSUM";
  1579. case DT_HP_GST_SIZE: return "HP_GST_SIZE";
  1580. case DT_HP_GST_VERSION: return "HP_GST_VERSION";
  1581. case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
  1582. case DT_HP_EPLTREL: return "HP_GST_EPLTREL";
  1583. case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ";
  1584. case DT_HP_FILTERED: return "HP_FILTERED";
  1585. case DT_HP_FILTER_TLS: return "HP_FILTER_TLS";
  1586. case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
  1587. case DT_HP_LAZYLOAD: return "HP_LAZYLOAD";
  1588. case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT";
  1589. case DT_PLT: return "PLT";
  1590. case DT_PLT_SIZE: return "PLT_SIZE";
  1591. case DT_DLT: return "DLT";
  1592. case DT_DLT_SIZE: return "DLT_SIZE";
  1593. default:
  1594. return NULL;
  1595. }
  1596. }
  1597. static const char *
  1598. get_ia64_dynamic_type (unsigned long type)
  1599. {
  1600. switch (type)
  1601. {
  1602. case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
  1603. case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE";
  1604. case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT";
  1605. case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS";
  1606. case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
  1607. case DT_IA_64_VMS_IDENT: return "VMS_IDENT";
  1608. case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT";
  1609. case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT";
  1610. case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT";
  1611. case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT";
  1612. case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED";
  1613. case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT";
  1614. case DT_IA_64_VMS_XLATED: return "VMS_XLATED";
  1615. case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE";
  1616. case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ";
  1617. case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG";
  1618. case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG";
  1619. case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME";
  1620. case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO";
  1621. case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET";
  1622. case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG";
  1623. case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET";
  1624. case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG";
  1625. case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET";
  1626. case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET";
  1627. case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF";
  1628. case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF";
  1629. case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF";
  1630. case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET";
  1631. case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG";
  1632. case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE";
  1633. default:
  1634. return NULL;
  1635. }
  1636. }
  1637. static const char *
  1638. get_solaris_section_type (unsigned long type)
  1639. {
  1640. switch (type)
  1641. {
  1642. case 0x6fffffee: return "SUNW_ancillary";
  1643. case 0x6fffffef: return "SUNW_capchain";
  1644. case 0x6ffffff0: return "SUNW_capinfo";
  1645. case 0x6ffffff1: return "SUNW_symsort";
  1646. case 0x6ffffff2: return "SUNW_tlssort";
  1647. case 0x6ffffff3: return "SUNW_LDYNSYM";
  1648. case 0x6ffffff4: return "SUNW_dof";
  1649. case 0x6ffffff5: return "SUNW_cap";
  1650. case 0x6ffffff6: return "SUNW_SIGNATURE";
  1651. case 0x6ffffff7: return "SUNW_ANNOTATE";
  1652. case 0x6ffffff8: return "SUNW_DEBUGSTR";
  1653. case 0x6ffffff9: return "SUNW_DEBUG";
  1654. case 0x6ffffffa: return "SUNW_move";
  1655. case 0x6ffffffb: return "SUNW_COMDAT";
  1656. case 0x6ffffffc: return "SUNW_syminfo";
  1657. case 0x6ffffffd: return "SUNW_verdef";
  1658. case 0x6ffffffe: return "SUNW_verneed";
  1659. case 0x6fffffff: return "SUNW_versym";
  1660. case 0x70000000: return "SPARC_GOTDATA";
  1661. default: return NULL;
  1662. }
  1663. }
  1664. static const char *
  1665. get_alpha_dynamic_type (unsigned long type)
  1666. {
  1667. switch (type)
  1668. {
  1669. case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
  1670. default: return NULL;
  1671. }
  1672. }
  1673. static const char *
  1674. get_score_dynamic_type (unsigned long type)
  1675. {
  1676. switch (type)
  1677. {
  1678. case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS";
  1679. case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO";
  1680. case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO";
  1681. case DT_SCORE_GOTSYM: return "SCORE_GOTSYM";
  1682. case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO";
  1683. case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO";
  1684. default: return NULL;
  1685. }
  1686. }
  1687. static const char *
  1688. get_tic6x_dynamic_type (unsigned long type)
  1689. {
  1690. switch (type)
  1691. {
  1692. case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET";
  1693. case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET";
  1694. case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE";
  1695. case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE";
  1696. case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
  1697. case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX";
  1698. default: return NULL;
  1699. }
  1700. }
  1701. static const char *
  1702. get_nios2_dynamic_type (unsigned long type)
  1703. {
  1704. switch (type)
  1705. {
  1706. case DT_NIOS2_GP: return "NIOS2_GP";
  1707. default: return NULL;
  1708. }
  1709. }
  1710. static const char *
  1711. get_solaris_dynamic_type (unsigned long type)
  1712. {
  1713. switch (type)
  1714. {
  1715. case 0x6000000d: return "SUNW_AUXILIARY";
  1716. case 0x6000000e: return "SUNW_RTLDINF";
  1717. case 0x6000000f: return "SUNW_FILTER";
  1718. case 0x60000010: return "SUNW_CAP";
  1719. case 0x60000011: return "SUNW_SYMTAB";
  1720. case 0x60000012: return "SUNW_SYMSZ";
  1721. case 0x60000013: return "SUNW_SORTENT";
  1722. case 0x60000014: return "SUNW_SYMSORT";
  1723. case 0x60000015: return "SUNW_SYMSORTSZ";
  1724. case 0x60000016: return "SUNW_TLSSORT";
  1725. case 0x60000017: return "SUNW_TLSSORTSZ";
  1726. case 0x60000018: return "SUNW_CAPINFO";
  1727. case 0x60000019: return "SUNW_STRPAD";
  1728. case 0x6000001a: return "SUNW_CAPCHAIN";
  1729. case 0x6000001b: return "SUNW_LDMACH";
  1730. case 0x6000001d: return "SUNW_CAPCHAINENT";
  1731. case 0x6000001f: return "SUNW_CAPCHAINSZ";
  1732. case 0x60000021: return "SUNW_PARENT";
  1733. case 0x60000023: return "SUNW_ASLR";
  1734. case 0x60000025: return "SUNW_RELAX";
  1735. case 0x60000029: return "SUNW_NXHEAP";
  1736. case 0x6000002b: return "SUNW_NXSTACK";
  1737. case 0x70000001: return "SPARC_REGISTER";
  1738. case 0x7ffffffd: return "AUXILIARY";
  1739. case 0x7ffffffe: return "USED";
  1740. case 0x7fffffff: return "FILTER";
  1741. default: return NULL;
  1742. }
  1743. }
  1744. static const char *
  1745. get_dynamic_type (unsigned long type)
  1746. {
  1747. static char buff[64];
  1748. switch (type)
  1749. {
  1750. case DT_NULL: return "NULL";
  1751. case DT_NEEDED: return "NEEDED";
  1752. case DT_PLTRELSZ: return "PLTRELSZ";
  1753. case DT_PLTGOT: return "PLTGOT";
  1754. case DT_HASH: return "HASH";
  1755. case DT_STRTAB: return "STRTAB";
  1756. case DT_SYMTAB: return "SYMTAB";
  1757. case DT_RELA: return "RELA";
  1758. case DT_RELASZ: return "RELASZ";
  1759. case DT_RELAENT: return "RELAENT";
  1760. case DT_STRSZ: return "STRSZ";
  1761. case DT_SYMENT: return "SYMENT";
  1762. case DT_INIT: return "INIT";
  1763. case DT_FINI: return "FINI";
  1764. case DT_SONAME: return "SONAME";
  1765. case DT_RPATH: return "RPATH";
  1766. case DT_SYMBOLIC: return "SYMBOLIC";
  1767. case DT_REL: return "REL";
  1768. case DT_RELSZ: return "RELSZ";
  1769. case DT_RELENT: return "RELENT";
  1770. case DT_PLTREL: return "PLTREL";
  1771. case DT_DEBUG: return "DEBUG";
  1772. case DT_TEXTREL: return "TEXTREL";
  1773. case DT_JMPREL: return "JMPREL";
  1774. case DT_BIND_NOW: return "BIND_NOW";
  1775. case DT_INIT_ARRAY: return "INIT_ARRAY";
  1776. case DT_FINI_ARRAY: return "FINI_ARRAY";
  1777. case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
  1778. case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
  1779. case DT_RUNPATH: return "RUNPATH";
  1780. case DT_FLAGS: return "FLAGS";
  1781. case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
  1782. case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
  1783. case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX";
  1784. case DT_CHECKSUM: return "CHECKSUM";
  1785. case DT_PLTPADSZ: return "PLTPADSZ";
  1786. case DT_MOVEENT: return "MOVEENT";
  1787. case DT_MOVESZ: return "MOVESZ";
  1788. case DT_FEATURE: return "FEATURE";
  1789. case DT_POSFLAG_1: return "POSFLAG_1";
  1790. case DT_SYMINSZ: return "SYMINSZ";
  1791. case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
  1792. case DT_ADDRRNGLO: return "ADDRRNGLO";
  1793. case DT_CONFIG: return "CONFIG";
  1794. case DT_DEPAUDIT: return "DEPAUDIT";
  1795. case DT_AUDIT: return "AUDIT";
  1796. case DT_PLTPAD: return "PLTPAD";
  1797. case DT_MOVETAB: return "MOVETAB";
  1798. case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
  1799. case DT_VERSYM: return "VERSYM";
  1800. case DT_TLSDESC_GOT: return "TLSDESC_GOT";
  1801. case DT_TLSDESC_PLT: return "TLSDESC_PLT";
  1802. case DT_RELACOUNT: return "RELACOUNT";
  1803. case DT_RELCOUNT: return "RELCOUNT";
  1804. case DT_FLAGS_1: return "FLAGS_1";
  1805. case DT_VERDEF: return "VERDEF";
  1806. case DT_VERDEFNUM: return "VERDEFNUM";
  1807. case DT_VERNEED: return "VERNEED";
  1808. case DT_VERNEEDNUM: return "VERNEEDNUM";
  1809. case DT_AUXILIARY: return "AUXILIARY";
  1810. case DT_USED: return "USED";
  1811. case DT_FILTER: return "FILTER";
  1812. case DT_GNU_PRELINKED: return "GNU_PRELINKED";
  1813. case DT_GNU_CONFLICT: return "GNU_CONFLICT";
  1814. case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
  1815. case DT_GNU_LIBLIST: return "GNU_LIBLIST";
  1816. case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
  1817. case DT_GNU_HASH: return "GNU_HASH";
  1818. default:
  1819. if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
  1820. {
  1821. const char * result;
  1822. switch (elf_header.e_machine)
  1823. {
  1824. case EM_MIPS:
  1825. case EM_MIPS_RS3_LE:
  1826. result = get_mips_dynamic_type (type);
  1827. break;
  1828. case EM_SPARCV9:
  1829. result = get_sparc64_dynamic_type (type);
  1830. break;
  1831. case EM_PPC:
  1832. result = get_ppc_dynamic_type (type);
  1833. break;
  1834. case EM_PPC64:
  1835. result = get_ppc64_dynamic_type (type);
  1836. break;
  1837. case EM_IA_64:
  1838. result = get_ia64_dynamic_type (type);
  1839. break;
  1840. case EM_ALPHA:
  1841. result = get_alpha_dynamic_type (type);
  1842. break;
  1843. case EM_SCORE:
  1844. result = get_score_dynamic_type (type);
  1845. break;
  1846. case EM_TI_C6000:
  1847. result = get_tic6x_dynamic_type (type);
  1848. break;
  1849. case EM_ALTERA_NIOS2:
  1850. result = get_nios2_dynamic_type (type);
  1851. break;
  1852. default:
  1853. if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
  1854. result = get_solaris_dynamic_type (type);
  1855. else
  1856. result = NULL;
  1857. break;
  1858. }
  1859. if (result != NULL)
  1860. return result;
  1861. snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
  1862. }
  1863. else if (((type >= DT_LOOS) && (type <= DT_HIOS))
  1864. || (elf_header.e_machine == EM_PARISC
  1865. && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
  1866. {
  1867. const char * result;
  1868. switch (elf_header.e_machine)
  1869. {
  1870. case EM_PARISC:
  1871. result = get_parisc_dynamic_type (type);
  1872. break;
  1873. case EM_IA_64:
  1874. result = get_ia64_dynamic_type (type);
  1875. break;
  1876. default:
  1877. if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
  1878. result = get_solaris_dynamic_type (type);
  1879. else
  1880. result = NULL;
  1881. break;
  1882. }
  1883. if (result != NULL)
  1884. return result;
  1885. snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
  1886. type);
  1887. }
  1888. else
  1889. snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
  1890. return buff;
  1891. }
  1892. }
  1893. static char *
  1894. get_file_type (unsigned e_type)
  1895. {
  1896. static char buff[32];
  1897. switch (e_type)
  1898. {
  1899. case ET_NONE: return _("NONE (None)");
  1900. case ET_REL: return _("REL (Relocatable file)");
  1901. case ET_EXEC: return _("EXEC (Executable file)");
  1902. case ET_DYN: return _("DYN (Shared object file)");
  1903. case ET_CORE: return _("CORE (Core file)");
  1904. default:
  1905. if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
  1906. snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
  1907. else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
  1908. snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
  1909. else
  1910. snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
  1911. return buff;
  1912. }
  1913. }
  1914. static char *
  1915. get_machine_name (unsigned e_machine)
  1916. {
  1917. static char buff[64]; /* XXX */
  1918. switch (e_machine)
  1919. {
  1920. /* Please keep this switch table sorted by increasing EM_ value. */
  1921. /* 0 */
  1922. case EM_NONE: return _("None");
  1923. case EM_M32: return "WE32100";
  1924. case EM_SPARC: return "Sparc";
  1925. case EM_386: return "Intel 80386";
  1926. case EM_68K: return "MC68000";
  1927. case EM_88K: return "MC88000";
  1928. case EM_IAMCU: return "Intel MCU";
  1929. case EM_860: return "Intel 80860";
  1930. case EM_MIPS: return "MIPS R3000";
  1931. case EM_S370: return "IBM System/370";
  1932. /* 10 */
  1933. case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
  1934. case EM_OLD_SPARCV9: return "Sparc v9 (old)";
  1935. case EM_PARISC: return "HPPA";
  1936. case EM_VPP550: return "Fujitsu VPP500";
  1937. case EM_SPARC32PLUS: return "Sparc v8+" ;
  1938. case EM_960: return "Intel 90860";
  1939. case EM_PPC: return "PowerPC";
  1940. /* 20 */
  1941. case EM_PPC64: return "PowerPC64";
  1942. case EM_S390_OLD:
  1943. case EM_S390: return "IBM S/390";
  1944. case EM_SPU: return "SPU";
  1945. /* 30 */
  1946. case EM_V800: return "Renesas V850 (using RH850 ABI)";
  1947. case EM_FR20: return "Fujitsu FR20";
  1948. case EM_RH32: return "TRW RH32";
  1949. case EM_MCORE: return "MCORE";
  1950. /* 40 */
  1951. case EM_ARM: return "ARM";
  1952. case EM_OLD_ALPHA: return "Digital Alpha (old)";
  1953. case EM_SH: return "Renesas / SuperH SH";
  1954. case EM_SPARCV9: return "Sparc v9";
  1955. case EM_TRICORE: return "Siemens Tricore";
  1956. case EM_ARC: return "ARC";
  1957. case EM_H8_300: return "Renesas H8/300";
  1958. case EM_H8_300H: return "Renesas H8/300H";
  1959. case EM_H8S: return "Renesas H8S";
  1960. case EM_H8_500: return "Renesas H8/500";
  1961. /* 50 */
  1962. case EM_IA_64: return "Intel IA-64";
  1963. case EM_MIPS_X: return "Stanford MIPS-X";
  1964. case EM_COLDFIRE: return "Motorola Coldfire";
  1965. case EM_68HC12: return "Motorola MC68HC12 Microcontroller";
  1966. case EM_MMA: return "Fujitsu Multimedia Accelerator";
  1967. case EM_PCP: return "Siemens PCP";
  1968. case EM_NCPU: return "Sony nCPU embedded RISC processor";
  1969. case EM_NDR1: return "Denso NDR1 microprocesspr";
  1970. case EM_STARCORE: return "Motorola Star*Core processor";
  1971. case EM_ME16: return "Toyota ME16 processor";
  1972. /* 60 */
  1973. case EM_ST100: return "STMicroelectronics ST100 processor";
  1974. case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
  1975. case EM_X86_64: return "Advanced Micro Devices X86-64";
  1976. case EM_PDSP: return "Sony DSP processor";
  1977. case EM_PDP10: return "Digital Equipment Corp. PDP-10";
  1978. case EM_PDP11: return "Digital Equipment Corp. PDP-11";
  1979. case EM_FX66: return "Siemens FX66 microcontroller";
  1980. case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
  1981. case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
  1982. case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
  1983. /* 70 */
  1984. case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
  1985. case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
  1986. case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
  1987. case EM_SVX: return "Silicon Graphics SVx";
  1988. case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
  1989. case EM_VAX: return "Digital VAX";
  1990. case EM_CRIS: return "Axis Communications 32-bit embedded processor";
  1991. case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
  1992. case EM_FIREPATH: return "Element 14 64-bit DSP processor";
  1993. case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
  1994. /* 80 */
  1995. case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
  1996. case EM_HUANY: return "Harvard Universitys's machine-independent object format";
  1997. case EM_PRISM: return "Vitesse Prism";
  1998. case EM_AVR_OLD:
  1999. case EM_AVR: return "Atmel AVR 8-bit microcontroller";
  2000. case EM_CYGNUS_FR30:
  2001. case EM_FR30: return "Fujitsu FR30";
  2002. case EM_CYGNUS_D10V:
  2003. case EM_D10V: return "d10v";
  2004. case EM_CYGNUS_D30V:
  2005. case EM_D30V: return "d30v";
  2006. case EM_CYGNUS_V850:
  2007. case EM_V850: return "Renesas V850";
  2008. case EM_CYGNUS_M32R:
  2009. case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
  2010. case EM_CYGNUS_MN10300:
  2011. case EM_MN10300: return "mn10300";
  2012. /* 90 */
  2013. case EM_CYGNUS_MN10200:
  2014. case EM_MN10200: return "mn10200";
  2015. case EM_PJ: return "picoJava";
  2016. case EM_OR1K: return "OpenRISC 1000";
  2017. case EM_ARC_COMPACT: return "ARCompact";
  2018. case EM_XTENSA_OLD:
  2019. case EM_XTENSA: return "Tensilica Xtensa Processor";
  2020. case EM_VIDEOCORE: return "Alphamosaic VideoCore processor";
  2021. case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor";
  2022. case EM_NS32K: return "National Semiconductor 32000 series";
  2023. case EM_TPC: return "Tenor Network TPC processor";
  2024. case EM_SNP1K: return "Trebia SNP 1000 processor";
  2025. /* 100 */
  2026. case EM_ST200: return "STMicroelectronics ST200 microcontroller";
  2027. case EM_IP2K_OLD:
  2028. case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
  2029. case EM_MAX: return "MAX Processor";
  2030. case EM_CR: return "National Semiconductor CompactRISC";
  2031. case EM_F2MC16: return "Fujitsu F2MC16";
  2032. case EM_MSP430: return "Texas Instruments msp430 microcontroller";
  2033. case EM_BLACKFIN: return "Analog Devices Blackfin";
  2034. case EM_SE_C33: return "S1C33 Family of Seiko Epson processors";
  2035. case EM_SEP: return "Sharp embedded microprocessor";
  2036. case EM_ARCA: return "Arca RISC microprocessor";
  2037. /* 110 */
  2038. case EM_UNICORE: return "Unicore";
  2039. case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU";
  2040. case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor";
  2041. case EM_ALTERA_NIOS2: return "Altera Nios II";
  2042. case EM_CRX: return "National Semiconductor CRX microprocessor";
  2043. case EM_XGATE: return "Motorola XGATE embedded processor";
  2044. case EM_C166:
  2045. case EM_XC16X: return "Infineon Technologies xc16x";
  2046. case EM_M16C: return "Renesas M16C series microprocessors";
  2047. case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller";
  2048. case EM_CE: return "Freescale Communication Engine RISC core";
  2049. /* 120 */
  2050. case EM_M32C: return "Renesas M32c";
  2051. /* 130 */
  2052. case EM_TSK3000: return "Altium TSK3000 core";
  2053. case EM_RS08: return "Freescale RS08 embedded processor";
  2054. case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor";
  2055. case EM_SCORE: return "SUNPLUS S+Core";
  2056. case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor";
  2057. case EM_VIDEOCORE3: return "Broadcom VideoCore III processor";
  2058. case EM_LATTICEMICO32: return "Lattice Mico32";
  2059. case EM_SE_C17: return "Seiko Epson C17 family";
  2060. /* 140 */
  2061. case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family";
  2062. case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family";
  2063. case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family";
  2064. case EM_TI_PRU: return "TI PRU I/O processor";
  2065. /* 160 */
  2066. case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor";
  2067. case EM_CYPRESS_M8C: return "Cypress M8C microprocessor";
  2068. case EM_R32C: return "Renesas R32C series microprocessors";
  2069. case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family";
  2070. case EM_QDSP6: return "QUALCOMM DSP6 Processor";
  2071. case EM_8051: return "Intel 8051 and variants";
  2072. case EM_STXP7X: return "STMicroelectronics STxP7x family";
  2073. case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family";
  2074. case EM_ECOG1X: return "Cyan Technology eCOG1X family";
  2075. case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers";
  2076. /* 170 */
  2077. case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor";
  2078. case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor";
  2079. case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture";
  2080. case EM_RX: return "Renesas RX";
  2081. case EM_METAG: return "Imagination Technologies Meta processor architecture";
  2082. case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture";
  2083. case EM_ECOG16: return "Cyan Technology eCOG16 family";
  2084. case EM_CR16:
  2085. case EM_MICROBLAZE:
  2086. case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze";
  2087. case EM_ETPU: return "Freescale Extended Time Processing Unit";
  2088. case EM_SLE9X: return "Infineon Technologies SLE9X core";
  2089. /* 180 */
  2090. case EM_L1OM: return "Intel L1OM";
  2091. case EM_K1OM: return "Intel K1OM";
  2092. case EM_INTEL182: return "Intel (reserved)";
  2093. case EM_AARCH64: return "AArch64";
  2094. case EM_ARM184: return "ARM (reserved)";
  2095. case EM_AVR32: return "Atmel Corporation 32-bit microprocessor";
  2096. case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller";
  2097. case EM_TILE64: return "Tilera TILE64 multicore architecture family";
  2098. case EM_TILEPRO: return "Tilera TILEPro multicore architecture family";
  2099. /* 190 */
  2100. case EM_CUDA: return "NVIDIA CUDA architecture";
  2101. case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family";
  2102. case EM_CLOUDSHIELD: return "CloudShield architecture family";
  2103. case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family";
  2104. case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family";
  2105. case EM_ARC_COMPACT2: return "ARCv2";
  2106. case EM_OPEN8: return "Open8 8-bit RISC soft processor core";
  2107. case EM_RL78: return "Renesas RL78";
  2108. case EM_VIDEOCORE5: return "Broadcom VideoCore V processor";
  2109. case EM_78K0R: return "Renesas 78K0R";
  2110. /* 200 */
  2111. case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)";
  2112. case EM_BA1: return "Beyond BA1 CPU architecture";
  2113. case EM_BA2: return "Beyond BA2 CPU architecture";
  2114. case EM_XCORE: return "XMOS xCORE processor family";
  2115. case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family";
  2116. /* 210 */
  2117. case EM_KM32: return "KM211 KM32 32-bit processor";
  2118. case EM_KMX32: return "KM211 KMX32 32-bit processor";
  2119. case EM_KMX16: return "KM211 KMX16 16-bit processor";
  2120. case EM_KMX8: return "KM211 KMX8 8-bit processor";
  2121. case EM_KVARC: return "KM211 KVARC processor";
  2122. case EM_CDP: return "Paneve CDP architecture family";
  2123. case EM_COGE: return "Cognitive Smart Memory Processor";
  2124. case EM_COOL: return "Bluechip Systems CoolEngine";
  2125. case EM_NORC: return "Nanoradio Optimized RISC";
  2126. case EM_CSR_KALIMBA: return "CSR Kalimba architecture family";
  2127. /* 220 */
  2128. case EM_Z80: return "Zilog Z80";
  2129. case EM_VISIUM: return "CDS VISIUMcore processor";
  2130. case EM_FT32: return "FTDI Chip FT32";
  2131. case EM_MOXIE: return "Moxie";
  2132. case EM_AMDGPU: return "AMD GPU";
  2133. case EM_RISCV: return "RISC-V";
  2134. case EM_LANAI: return "Lanai 32-bit processor";
  2135. case EM_BPF: return "Linux BPF";
  2136. /* Large numbers... */
  2137. case EM_MT: return "Morpho Techologies MT processor";
  2138. case EM_ALPHA: return "Alpha";
  2139. case EM_WEBASSEMBLY: return "Web Assembly";
  2140. case EM_DLX: return "OpenDLX";
  2141. case EM_XSTORMY16: return "Sanyo XStormy16 CPU core";
  2142. case EM_IQ2000: return "Vitesse IQ2000";
  2143. case EM_M32C_OLD:
  2144. case EM_NIOS32: return "Altera Nios";
  2145. case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine";
  2146. case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY";
  2147. case EM_CYGNUS_FRV: return "Fujitsu FR-V";
  2148. default:
  2149. snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
  2150. return buff;
  2151. }
  2152. }
  2153. static void
  2154. decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[])
  2155. {
  2156. /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some
  2157. other compilers don't a specific architecture type in the e_flags, and
  2158. instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700
  2159. architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS
  2160. architectures.
  2161. Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2,
  2162. but also sets a specific architecture type in the e_flags field.
  2163. However, when decoding the flags we don't worry if we see an
  2164. unexpected pairing, for example EM_ARC_COMPACT machine type, with
  2165. ARCEM architecture type. */
  2166. switch (e_flags & EF_ARC_MACH_MSK)
  2167. {
  2168. /* We only expect these to occur for EM_ARC_COMPACT2. */
  2169. case EF_ARC_CPU_ARCV2EM:
  2170. strcat (buf, ", ARC EM");
  2171. break;
  2172. case EF_ARC_CPU_ARCV2HS:
  2173. strcat (buf, ", ARC HS");
  2174. break;
  2175. /* We only expect these to occur for EM_ARC_COMPACT. */
  2176. case E_ARC_MACH_ARC600:
  2177. strcat (buf, ", ARC600");
  2178. break;
  2179. case E_ARC_MACH_ARC601:
  2180. strcat (buf, ", ARC601");
  2181. break;
  2182. case E_ARC_MACH_ARC700:
  2183. strcat (buf, ", ARC700");
  2184. break;
  2185. /* The only times we should end up here are (a) A corrupt ELF, (b) A
  2186. new ELF with new architecture being read by an old version of
  2187. readelf, or (c) An ELF built with non-GNU compiler that does not
  2188. set the architecture in the e_flags. */
  2189. default:
  2190. if (e_machine == EM_ARC_COMPACT)
  2191. strcat (buf, ", Unknown ARCompact");
  2192. else
  2193. strcat (buf, ", Unknown ARC");
  2194. break;
  2195. }
  2196. switch (e_flags & EF_ARC_OSABI_MSK)
  2197. {
  2198. case E_ARC_OSABI_ORIG:
  2199. strcat (buf, ", (ABI:legacy)");
  2200. break;
  2201. case E_ARC_OSABI_V2:
  2202. strcat (buf, ", (ABI:v2)");
  2203. break;
  2204. /* Only upstream 3.9+ kernels will support ARCv2 ISA. */
  2205. case E_ARC_OSABI_V3:
  2206. strcat (buf, ", v3 no-legacy-syscalls ABI");
  2207. break;
  2208. case E_ARC_OSABI_V4:
  2209. strcat (buf, ", v4 ABI");
  2210. break;
  2211. default:
  2212. strcat (buf, ", unrecognised ARC OSABI flag");
  2213. break;
  2214. }
  2215. }
  2216. static void
  2217. decode_ARM_machine_flags (unsigned e_flags, char buf[])
  2218. {
  2219. unsigned eabi;
  2220. bfd_boolean unknown = FALSE;
  2221. eabi = EF_ARM_EABI_VERSION (e_flags);
  2222. e_flags &= ~ EF_ARM_EABIMASK;
  2223. /* Handle "generic" ARM flags. */
  2224. if (e_flags & EF_ARM_RELEXEC)
  2225. {
  2226. strcat (buf, ", relocatable executable");
  2227. e_flags &= ~ EF_ARM_RELEXEC;
  2228. }
  2229. /* Now handle EABI specific flags. */
  2230. switch (eabi)
  2231. {
  2232. default:
  2233. strcat (buf, ", <unrecognized EABI>");
  2234. if (e_flags)
  2235. unknown = TRUE;
  2236. break;
  2237. case EF_ARM_EABI_VER1:
  2238. strcat (buf, ", Version1 EABI");
  2239. while (e_flags)
  2240. {
  2241. unsigned flag;
  2242. /* Process flags one bit at a time. */
  2243. flag = e_flags & - e_flags;
  2244. e_flags &= ~ flag;
  2245. switch (flag)
  2246. {
  2247. case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
  2248. strcat (buf, ", sorted symbol tables");
  2249. break;
  2250. default:
  2251. unknown = TRUE;
  2252. break;
  2253. }
  2254. }
  2255. break;
  2256. case EF_ARM_EABI_VER2:
  2257. strcat (buf, ", Version2 EABI");
  2258. while (e_flags)
  2259. {
  2260. unsigned flag;
  2261. /* Process flags one bit at a time. */
  2262. flag = e_flags & - e_flags;
  2263. e_flags &= ~ flag;
  2264. switch (flag)
  2265. {
  2266. case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
  2267. strcat (buf, ", sorted symbol tables");
  2268. break;
  2269. case EF_ARM_DYNSYMSUSESEGIDX:
  2270. strcat (buf, ", dynamic symbols use segment index");
  2271. break;
  2272. case EF_ARM_MAPSYMSFIRST:
  2273. strcat (buf, ", mapping symbols precede others");
  2274. break;
  2275. default:
  2276. unknown = TRUE;
  2277. break;
  2278. }
  2279. }
  2280. break;
  2281. case EF_ARM_EABI_VER3:
  2282. strcat (buf, ", Version3 EABI");
  2283. break;
  2284. case EF_ARM_EABI_VER4:
  2285. strcat (buf, ", Version4 EABI");
  2286. while (e_flags)
  2287. {
  2288. unsigned flag;
  2289. /* Process flags one bit at a time. */
  2290. flag = e_flags & - e_flags;
  2291. e_flags &= ~ flag;
  2292. switch (flag)
  2293. {
  2294. case EF_ARM_BE8:
  2295. strcat (buf, ", BE8");
  2296. break;
  2297. case EF_ARM_LE8:
  2298. strcat (buf, ", LE8");
  2299. break;
  2300. default:
  2301. unknown = TRUE;
  2302. break;
  2303. }
  2304. }
  2305. break;
  2306. case EF_ARM_EABI_VER5:
  2307. strcat (buf, ", Version5 EABI");
  2308. while (e_flags)
  2309. {
  2310. unsigned flag;
  2311. /* Process flags one bit at a time. */
  2312. flag = e_flags & - e_flags;
  2313. e_flags &= ~ flag;
  2314. switch (flag)
  2315. {
  2316. case EF_ARM_BE8:
  2317. strcat (buf, ", BE8");
  2318. break;
  2319. case EF_ARM_LE8:
  2320. strcat (buf, ", LE8");
  2321. break;
  2322. case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */
  2323. strcat (buf, ", soft-float ABI");
  2324. break;
  2325. case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */
  2326. strcat (buf, ", hard-float ABI");
  2327. break;
  2328. default:
  2329. unknown = TRUE;
  2330. break;
  2331. }
  2332. }
  2333. break;
  2334. case EF_ARM_EABI_UNKNOWN:
  2335. strcat (buf, ", GNU EABI");
  2336. while (e_flags)
  2337. {
  2338. unsigned flag;
  2339. /* Process flags one bit at a time. */
  2340. flag = e_flags & - e_flags;
  2341. e_flags &= ~ flag;
  2342. switch (flag)
  2343. {
  2344. case EF_ARM_INTERWORK:
  2345. strcat (buf, ", interworking enabled");
  2346. break;
  2347. case EF_ARM_APCS_26:
  2348. strcat (buf, ", uses APCS/26");
  2349. break;
  2350. case EF_ARM_APCS_FLOAT:
  2351. strcat (buf, ", uses APCS/float");
  2352. break;
  2353. case EF_ARM_PIC:
  2354. strcat (buf, ", position independent");
  2355. break;
  2356. case EF_ARM_ALIGN8:
  2357. strcat (buf, ", 8 bit structure alignment");
  2358. break;
  2359. case EF_ARM_NEW_ABI:
  2360. strcat (buf, ", uses new ABI");
  2361. break;
  2362. case EF_ARM_OLD_ABI:
  2363. strcat (buf, ", uses old ABI");
  2364. break;
  2365. case EF_ARM_SOFT_FLOAT:
  2366. strcat (buf, ", software FP");
  2367. break;
  2368. case EF_ARM_VFP_FLOAT:
  2369. strcat (buf, ", VFP");
  2370. break;
  2371. case EF_ARM_MAVERICK_FLOAT:
  2372. strcat (buf, ", Maverick FP");
  2373. break;
  2374. default:
  2375. unknown = TRUE;
  2376. break;
  2377. }
  2378. }
  2379. }
  2380. if (unknown)
  2381. strcat (buf,_(", <unknown>"));
  2382. }
  2383. static void
  2384. decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size)
  2385. {
  2386. --size; /* Leave space for null terminator. */
  2387. switch (e_flags & EF_AVR_MACH)
  2388. {
  2389. case E_AVR_MACH_AVR1:
  2390. strncat (buf, ", avr:1", size);
  2391. break;
  2392. case E_AVR_MACH_AVR2:
  2393. strncat (buf, ", avr:2", size);
  2394. break;
  2395. case E_AVR_MACH_AVR25:
  2396. strncat (buf, ", avr:25", size);
  2397. break;
  2398. case E_AVR_MACH_AVR3:
  2399. strncat (buf, ", avr:3", size);
  2400. break;
  2401. case E_AVR_MACH_AVR31:
  2402. strncat (buf, ", avr:31", size);
  2403. break;
  2404. case E_AVR_MACH_AVR35:
  2405. strncat (buf, ", avr:35", size);
  2406. break;
  2407. case E_AVR_MACH_AVR4:
  2408. strncat (buf, ", avr:4", size);
  2409. break;
  2410. case E_AVR_MACH_AVR5:
  2411. strncat (buf, ", avr:5", size);
  2412. break;
  2413. case E_AVR_MACH_AVR51:
  2414. strncat (buf, ", avr:51", size);
  2415. break;
  2416. case E_AVR_MACH_AVR6:
  2417. strncat (buf, ", avr:6", size);
  2418. break;
  2419. case E_AVR_MACH_AVRTINY:
  2420. strncat (buf, ", avr:100", size);
  2421. break;
  2422. case E_AVR_MACH_XMEGA1:
  2423. strncat (buf, ", avr:101", size);
  2424. break;
  2425. case E_AVR_MACH_XMEGA2:
  2426. strncat (buf, ", avr:102", size);
  2427. break;
  2428. case E_AVR_MACH_XMEGA3:
  2429. strncat (buf, ", avr:103", size);
  2430. break;
  2431. case E_AVR_MACH_XMEGA4:
  2432. strncat (buf, ", avr:104", size);
  2433. break;
  2434. case E_AVR_MACH_XMEGA5:
  2435. strncat (buf, ", avr:105", size);
  2436. break;
  2437. case E_AVR_MACH_XMEGA6:
  2438. strncat (buf, ", avr:106", size);
  2439. break;
  2440. case E_AVR_MACH_XMEGA7:
  2441. strncat (buf, ", avr:107", size);
  2442. break;
  2443. default:
  2444. strncat (buf, ", avr:<unknown>", size);
  2445. break;
  2446. }
  2447. size -= strlen (buf);
  2448. if (e_flags & EF_AVR_LINKRELAX_PREPARED)
  2449. strncat (buf, ", link-relax", size);
  2450. }
  2451. static void
  2452. decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size)
  2453. {
  2454. unsigned abi;
  2455. unsigned arch;
  2456. unsigned config;
  2457. unsigned version;
  2458. bfd_boolean has_fpu = FALSE;
  2459. unsigned int r = 0;
  2460. static const char *ABI_STRINGS[] =
  2461. {
  2462. "ABI v0", /* use r5 as return register; only used in N1213HC */
  2463. "ABI v1", /* use r0 as return register */
  2464. "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */
  2465. "ABI v2fp", /* for FPU */
  2466. "AABI",
  2467. "ABI2 FP+"
  2468. };
  2469. static const char *VER_STRINGS[] =
  2470. {
  2471. "Andes ELF V1.3 or older",
  2472. "Andes ELF V1.3.1",
  2473. "Andes ELF V1.4"
  2474. };
  2475. static const char *ARCH_STRINGS[] =
  2476. {
  2477. "",
  2478. "Andes Star v1.0",
  2479. "Andes Star v2.0",
  2480. "Andes Star v3.0",
  2481. "Andes Star v3.0m"
  2482. };
  2483. abi = EF_NDS_ABI & e_flags;
  2484. arch = EF_NDS_ARCH & e_flags;
  2485. config = EF_NDS_INST & e_flags;
  2486. version = EF_NDS32_ELF_VERSION & e_flags;
  2487. memset (buf, 0, size);
  2488. switch (abi)
  2489. {
  2490. case E_NDS_ABI_V0:
  2491. case E_NDS_ABI_V1:
  2492. case E_NDS_ABI_V2:
  2493. case E_NDS_ABI_V2FP:
  2494. case E_NDS_ABI_AABI:
  2495. case E_NDS_ABI_V2FP_PLUS:
  2496. /* In case there are holes in the array. */
  2497. r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]);
  2498. break;
  2499. default:
  2500. r += snprintf (buf + r, size - r, ", <unrecognized ABI>");
  2501. break;
  2502. }
  2503. switch (version)
  2504. {
  2505. case E_NDS32_ELF_VER_1_2:
  2506. case E_NDS32_ELF_VER_1_3:
  2507. case E_NDS32_ELF_VER_1_4:
  2508. r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]);
  2509. break;
  2510. default:
  2511. r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>");
  2512. break;
  2513. }
  2514. if (E_NDS_ABI_V0 == abi)
  2515. {
  2516. /* OLD ABI; only used in N1213HC, has performance extension 1. */
  2517. r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1");
  2518. if (arch == E_NDS_ARCH_STAR_V1_0)
  2519. r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */
  2520. return;
  2521. }
  2522. switch (arch)
  2523. {
  2524. case E_NDS_ARCH_STAR_V1_0:
  2525. case E_NDS_ARCH_STAR_V2_0:
  2526. case E_NDS_ARCH_STAR_V3_0:
  2527. case E_NDS_ARCH_STAR_V3_M:
  2528. r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]);
  2529. break;
  2530. default:
  2531. r += snprintf (buf + r, size - r, ", <unrecognized architecture>");
  2532. /* ARCH version determines how the e_flags are interpreted.
  2533. If it is unknown, we cannot proceed. */
  2534. return;
  2535. }
  2536. /* Newer ABI; Now handle architecture specific flags. */
  2537. if (arch == E_NDS_ARCH_STAR_V1_0)
  2538. {
  2539. if (config & E_NDS32_HAS_MFUSR_PC_INST)
  2540. r += snprintf (buf + r, size -r, ", MFUSR_PC");
  2541. if (!(config & E_NDS32_HAS_NO_MAC_INST))
  2542. r += snprintf (buf + r, size -r, ", MAC");
  2543. if (config & E_NDS32_HAS_DIV_INST)
  2544. r += snprintf (buf + r, size -r, ", DIV");
  2545. if (config & E_NDS32_HAS_16BIT_INST)
  2546. r += snprintf (buf + r, size -r, ", 16b");
  2547. }
  2548. else
  2549. {
  2550. if (config & E_NDS32_HAS_MFUSR_PC_INST)
  2551. {
  2552. if (version <= E_NDS32_ELF_VER_1_3)
  2553. r += snprintf (buf + r, size -r, ", [B8]");
  2554. else
  2555. r += snprintf (buf + r, size -r, ", EX9");
  2556. }
  2557. if (config & E_NDS32_HAS_MAC_DX_INST)
  2558. r += snprintf (buf + r, size -r, ", MAC_DX");
  2559. if (config & E_NDS32_HAS_DIV_DX_INST)
  2560. r += snprintf (buf + r, size -r, ", DIV_DX");
  2561. if (config & E_NDS32_HAS_16BIT_INST)
  2562. {
  2563. if (version <= E_NDS32_ELF_VER_1_3)
  2564. r += snprintf (buf + r, size -r, ", 16b");
  2565. else
  2566. r += snprintf (buf + r, size -r, ", IFC");
  2567. }
  2568. }
  2569. if (config & E_NDS32_HAS_EXT_INST)
  2570. r += snprintf (buf + r, size -r, ", PERF1");
  2571. if (config & E_NDS32_HAS_EXT2_INST)
  2572. r += snprintf (buf + r, size -r, ", PERF2");
  2573. if (config & E_NDS32_HAS_FPU_INST)
  2574. {
  2575. has_fpu = TRUE;
  2576. r += snprintf (buf + r, size -r, ", FPU_SP");
  2577. }
  2578. if (config & E_NDS32_HAS_FPU_DP_INST)
  2579. {
  2580. has_fpu = TRUE;
  2581. r += snprintf (buf + r, size -r, ", FPU_DP");
  2582. }
  2583. if (config & E_NDS32_HAS_FPU_MAC_INST)
  2584. {
  2585. has_fpu = TRUE;
  2586. r += snprintf (buf + r, size -r, ", FPU_MAC");
  2587. }
  2588. if (has_fpu)
  2589. {
  2590. switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT)
  2591. {
  2592. case E_NDS32_FPU_REG_8SP_4DP:
  2593. r += snprintf (buf + r, size -r, ", FPU_REG:8/4");
  2594. break;
  2595. case E_NDS32_FPU_REG_16SP_8DP:
  2596. r += snprintf (buf + r, size -r, ", FPU_REG:16/8");
  2597. break;
  2598. case E_NDS32_FPU_REG_32SP_16DP:
  2599. r += snprintf (buf + r, size -r, ", FPU_REG:32/16");
  2600. break;
  2601. case E_NDS32_FPU_REG_32SP_32DP:
  2602. r += snprintf (buf + r, size -r, ", FPU_REG:32/32");
  2603. break;
  2604. }
  2605. }
  2606. if (config & E_NDS32_HAS_AUDIO_INST)
  2607. r += snprintf (buf + r, size -r, ", AUDIO");
  2608. if (config & E_NDS32_HAS_STRING_INST)
  2609. r += snprintf (buf + r, size -r, ", STR");
  2610. if (config & E_NDS32_HAS_REDUCED_REGS)
  2611. r += snprintf (buf + r, size -r, ", 16REG");
  2612. if (config & E_NDS32_HAS_VIDEO_INST)
  2613. {
  2614. if (version <= E_NDS32_ELF_VER_1_3)
  2615. r += snprintf (buf + r, size -r, ", VIDEO");
  2616. else
  2617. r += snprintf (buf + r, size -r, ", SATURATION");
  2618. }
  2619. if (config & E_NDS32_HAS_ENCRIPT_INST)
  2620. r += snprintf (buf + r, size -r, ", ENCRP");
  2621. if (config & E_NDS32_HAS_L2C_INST)
  2622. r += snprintf (buf + r, size -r, ", L2C");
  2623. }
  2624. static char *
  2625. get_machine_flags (unsigned e_flags, unsigned e_machine)
  2626. {
  2627. static char buf[1024];
  2628. buf[0] = '\0';
  2629. if (e_flags)
  2630. {
  2631. switch (e_machine)
  2632. {
  2633. default:
  2634. break;
  2635. case EM_ARC_COMPACT2:
  2636. case EM_ARC_COMPACT:
  2637. decode_ARC_machine_flags (e_flags, e_machine, buf);
  2638. break;
  2639. case EM_ARM:
  2640. decode_ARM_machine_flags (e_flags, buf);
  2641. break;
  2642. case EM_AVR:
  2643. decode_AVR_machine_flags (e_flags, buf, sizeof buf);
  2644. break;
  2645. case EM_BLACKFIN:
  2646. if (e_flags & EF_BFIN_PIC)
  2647. strcat (buf, ", PIC");
  2648. if (e_flags & EF_BFIN_FDPIC)
  2649. strcat (buf, ", FDPIC");
  2650. if (e_flags & EF_BFIN_CODE_IN_L1)
  2651. strcat (buf, ", code in L1");
  2652. if (e_flags & EF_BFIN_DATA_IN_L1)
  2653. strcat (buf, ", data in L1");
  2654. break;
  2655. case EM_CYGNUS_FRV:
  2656. switch (e_flags & EF_FRV_CPU_MASK)
  2657. {
  2658. case EF_FRV_CPU_GENERIC:
  2659. break;
  2660. default:
  2661. strcat (buf, ", fr???");
  2662. break;
  2663. case EF_FRV_CPU_FR300:
  2664. strcat (buf, ", fr300");
  2665. break;
  2666. case EF_FRV_CPU_FR400:
  2667. strcat (buf, ", fr400");
  2668. break;
  2669. case EF_FRV_CPU_FR405:
  2670. strcat (buf, ", fr405");
  2671. break;
  2672. case EF_FRV_CPU_FR450:
  2673. strcat (buf, ", fr450");
  2674. break;
  2675. case EF_FRV_CPU_FR500:
  2676. strcat (buf, ", fr500");
  2677. break;
  2678. case EF_FRV_CPU_FR550:
  2679. strcat (buf, ", fr550");
  2680. break;
  2681. case EF_FRV_CPU_SIMPLE:
  2682. strcat (buf, ", simple");
  2683. break;
  2684. case EF_FRV_CPU_TOMCAT:
  2685. strcat (buf, ", tomcat");
  2686. break;
  2687. }
  2688. break;
  2689. case EM_68K:
  2690. if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
  2691. strcat (buf, ", m68000");
  2692. else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
  2693. strcat (buf, ", cpu32");
  2694. else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
  2695. strcat (buf, ", fido_a");
  2696. else
  2697. {
  2698. char const * isa = _("unknown");
  2699. char const * mac = _("unknown mac");
  2700. char const * additional = NULL;
  2701. switch (e_flags & EF_M68K_CF_ISA_MASK)
  2702. {
  2703. case EF_M68K_CF_ISA_A_NODIV:
  2704. isa = "A";
  2705. additional = ", nodiv";
  2706. break;
  2707. case EF_M68K_CF_ISA_A:
  2708. isa = "A";
  2709. break;
  2710. case EF_M68K_CF_ISA_A_PLUS:
  2711. isa = "A+";
  2712. break;
  2713. case EF_M68K_CF_ISA_B_NOUSP:
  2714. isa = "B";
  2715. additional = ", nousp";
  2716. break;
  2717. case EF_M68K_CF_ISA_B:
  2718. isa = "B";
  2719. break;
  2720. case EF_M68K_CF_ISA_C:
  2721. isa = "C";
  2722. break;
  2723. case EF_M68K_CF_ISA_C_NODIV:
  2724. isa = "C";
  2725. additional = ", nodiv";
  2726. break;
  2727. }
  2728. strcat (buf, ", cf, isa ");
  2729. strcat (buf, isa);
  2730. if (additional)
  2731. strcat (buf, additional);
  2732. if (e_flags & EF_M68K_CF_FLOAT)
  2733. strcat (buf, ", float");
  2734. switch (e_flags & EF_M68K_CF_MAC_MASK)
  2735. {
  2736. case 0:
  2737. mac = NULL;
  2738. break;
  2739. case EF_M68K_CF_MAC:
  2740. mac = "mac";
  2741. break;
  2742. case EF_M68K_CF_EMAC:
  2743. mac = "emac";
  2744. break;
  2745. case EF_M68K_CF_EMAC_B:
  2746. mac = "emac_b";
  2747. break;
  2748. }
  2749. if (mac)
  2750. {
  2751. strcat (buf, ", ");
  2752. strcat (buf, mac);
  2753. }
  2754. }
  2755. break;
  2756. case EM_CYGNUS_MEP:
  2757. switch (e_flags & EF_MEP_CPU_MASK)
  2758. {
  2759. case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break;
  2760. case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break;
  2761. case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break;
  2762. case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break;
  2763. case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break;
  2764. case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break;
  2765. default: strcat (buf, _(", <unknown MeP cpu type>")); break;
  2766. }
  2767. switch (e_flags & EF_MEP_COP_MASK)
  2768. {
  2769. case EF_MEP_COP_NONE: break;
  2770. case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break;
  2771. case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break;
  2772. case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break;
  2773. case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break;
  2774. default: strcat (buf, _("<unknown MeP copro type>")); break;
  2775. }
  2776. if (e_flags & EF_MEP_LIBRARY)
  2777. strcat (buf, ", Built for Library");
  2778. if (e_flags & EF_MEP_INDEX_MASK)
  2779. sprintf (buf + strlen (buf), ", Configuration Index: %#x",
  2780. e_flags & EF_MEP_INDEX_MASK);
  2781. if (e_flags & ~ EF_MEP_ALL_FLAGS)
  2782. sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"),
  2783. e_flags & ~ EF_MEP_ALL_FLAGS);
  2784. break;
  2785. case EM_PPC:
  2786. if (e_flags & EF_PPC_EMB)
  2787. strcat (buf, ", emb");
  2788. if (e_flags & EF_PPC_RELOCATABLE)
  2789. strcat (buf, _(", relocatable"));
  2790. if (e_flags & EF_PPC_RELOCATABLE_LIB)
  2791. strcat (buf, _(", relocatable-lib"));
  2792. break;
  2793. case EM_PPC64:
  2794. if (e_flags & EF_PPC64_ABI)
  2795. {
  2796. char abi[] = ", abiv0";
  2797. abi[6] += e_flags & EF_PPC64_ABI;
  2798. strcat (buf, abi);
  2799. }
  2800. break;
  2801. case EM_V800:
  2802. if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI)
  2803. strcat (buf, ", RH850 ABI");
  2804. if (e_flags & EF_V800_850E3)
  2805. strcat (buf, ", V3 architecture");
  2806. if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0)
  2807. strcat (buf, ", FPU not used");
  2808. if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0)
  2809. strcat (buf, ", regmode: COMMON");
  2810. if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0)
  2811. strcat (buf, ", r4 not used");
  2812. if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0)
  2813. strcat (buf, ", r30 not used");
  2814. if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0)
  2815. strcat (buf, ", r5 not used");
  2816. if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0)
  2817. strcat (buf, ", r2 not used");
  2818. for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags))
  2819. {
  2820. switch (e_flags & - e_flags)
  2821. {
  2822. case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break;
  2823. case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break;
  2824. case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break;
  2825. case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break;
  2826. case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break;
  2827. case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break;
  2828. case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break;
  2829. case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break;
  2830. case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break;
  2831. case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break;
  2832. case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break;
  2833. case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break;
  2834. default: break;
  2835. }
  2836. }
  2837. break;
  2838. case EM_V850:
  2839. case EM_CYGNUS_V850:
  2840. switch (e_flags & EF_V850_ARCH)
  2841. {
  2842. case E_V850E3V5_ARCH:
  2843. strcat (buf, ", v850e3v5");
  2844. break;
  2845. case E_V850E2V3_ARCH:
  2846. strcat (buf, ", v850e2v3");
  2847. break;
  2848. case E_V850E2_ARCH:
  2849. strcat (buf, ", v850e2");
  2850. break;
  2851. case E_V850E1_ARCH:
  2852. strcat (buf, ", v850e1");
  2853. break;
  2854. case E_V850E_ARCH:
  2855. strcat (buf, ", v850e");
  2856. break;
  2857. case E_V850_ARCH:
  2858. strcat (buf, ", v850");
  2859. break;
  2860. default:
  2861. strcat (buf, _(", unknown v850 architecture variant"));
  2862. break;
  2863. }
  2864. break;
  2865. case EM_M32R:
  2866. case EM_CYGNUS_M32R:
  2867. if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
  2868. strcat (buf, ", m32r");
  2869. break;
  2870. case EM_MIPS:
  2871. case EM_MIPS_RS3_LE:
  2872. if (e_flags & EF_MIPS_NOREORDER)
  2873. strcat (buf, ", noreorder");
  2874. if (e_flags & EF_MIPS_PIC)
  2875. strcat (buf, ", pic");
  2876. if (e_flags & EF_MIPS_CPIC)
  2877. strcat (buf, ", cpic");
  2878. if (e_flags & EF_MIPS_UCODE)
  2879. strcat (buf, ", ugen_reserved");
  2880. if (e_flags & EF_MIPS_ABI2)
  2881. strcat (buf, ", abi2");
  2882. if (e_flags & EF_MIPS_OPTIONS_FIRST)
  2883. strcat (buf, ", odk first");
  2884. if (e_flags & EF_MIPS_32BITMODE)
  2885. strcat (buf, ", 32bitmode");
  2886. if (e_flags & EF_MIPS_NAN2008)
  2887. strcat (buf, ", nan2008");
  2888. if (e_flags & EF_MIPS_FP64)
  2889. strcat (buf, ", fp64");
  2890. switch ((e_flags & EF_MIPS_MACH))
  2891. {
  2892. case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
  2893. case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
  2894. case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
  2895. case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
  2896. case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
  2897. case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
  2898. case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
  2899. case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
  2900. case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
  2901. case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
  2902. case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
  2903. case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
  2904. case E_MIPS_MACH_LS3A: strcat (buf, ", loongson-3a"); break;
  2905. case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
  2906. case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break;
  2907. case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break;
  2908. case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break;
  2909. case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break;
  2910. case 0:
  2911. /* We simply ignore the field in this case to avoid confusion:
  2912. MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
  2913. extension. */
  2914. break;
  2915. default: strcat (buf, _(", unknown CPU")); break;
  2916. }
  2917. switch ((e_flags & EF_MIPS_ABI))
  2918. {
  2919. case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
  2920. case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
  2921. case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
  2922. case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
  2923. case 0:
  2924. /* We simply ignore the field in this case to avoid confusion:
  2925. MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
  2926. This means it is likely to be an o32 file, but not for
  2927. sure. */
  2928. break;
  2929. default: strcat (buf, _(", unknown ABI")); break;
  2930. }
  2931. if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
  2932. strcat (buf, ", mdmx");
  2933. if (e_flags & EF_MIPS_ARCH_ASE_M16)
  2934. strcat (buf, ", mips16");
  2935. if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS)
  2936. strcat (buf, ", micromips");
  2937. switch ((e_flags & EF_MIPS_ARCH))
  2938. {
  2939. case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
  2940. case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
  2941. case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
  2942. case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
  2943. case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
  2944. case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
  2945. case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
  2946. case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break;
  2947. case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
  2948. case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
  2949. case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break;
  2950. default: strcat (buf, _(", unknown ISA")); break;
  2951. }
  2952. break;
  2953. case EM_NDS32:
  2954. decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
  2955. break;
  2956. case EM_RISCV:
  2957. if (e_flags & EF_RISCV_RVC)
  2958. strcat (buf, ", RVC");
  2959. switch (e_flags & EF_RISCV_FLOAT_ABI)
  2960. {
  2961. case EF_RISCV_FLOAT_ABI_SOFT:
  2962. strcat (buf, ", soft-float ABI");
  2963. break;
  2964. case EF_RISCV_FLOAT_ABI_SINGLE:
  2965. strcat (buf, ", single-float ABI");
  2966. break;
  2967. case EF_RISCV_FLOAT_ABI_DOUBLE:
  2968. strcat (buf, ", double-float ABI");
  2969. break;
  2970. case EF_RISCV_FLOAT_ABI_QUAD:
  2971. strcat (buf, ", quad-float ABI");
  2972. break;
  2973. }
  2974. break;
  2975. case EM_SH:
  2976. switch ((e_flags & EF_SH_MACH_MASK))
  2977. {
  2978. case EF_SH1: strcat (buf, ", sh1"); break;
  2979. case EF_SH2: strcat (buf, ", sh2"); break;
  2980. case EF_SH3: strcat (buf, ", sh3"); break;
  2981. case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
  2982. case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
  2983. case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
  2984. case EF_SH3E: strcat (buf, ", sh3e"); break;
  2985. case EF_SH4: strcat (buf, ", sh4"); break;
  2986. case EF_SH5: strcat (buf, ", sh5"); break;
  2987. case EF_SH2E: strcat (buf, ", sh2e"); break;
  2988. case EF_SH4A: strcat (buf, ", sh4a"); break;
  2989. case EF_SH2A: strcat (buf, ", sh2a"); break;
  2990. case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
  2991. case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
  2992. case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
  2993. case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
  2994. case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
  2995. case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
  2996. case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
  2997. case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
  2998. case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
  2999. default: strcat (buf, _(", unknown ISA")); break;
  3000. }
  3001. if (e_flags & EF_SH_PIC)
  3002. strcat (buf, ", pic");
  3003. if (e_flags & EF_SH_FDPIC)
  3004. strcat (buf, ", fdpic");
  3005. break;
  3006. case EM_OR1K:
  3007. if (e_flags & EF_OR1K_NODELAY)
  3008. strcat (buf, ", no delay");
  3009. break;
  3010. case EM_SPARCV9:
  3011. if (e_flags & EF_SPARC_32PLUS)
  3012. strcat (buf, ", v8+");
  3013. if (e_flags & EF_SPARC_SUN_US1)
  3014. strcat (buf, ", ultrasparcI");
  3015. if (e_flags & EF_SPARC_SUN_US3)
  3016. strcat (buf, ", ultrasparcIII");
  3017. if (e_flags & EF_SPARC_HAL_R1)
  3018. strcat (buf, ", halr1");
  3019. if (e_flags & EF_SPARC_LEDATA)
  3020. strcat (buf, ", ledata");
  3021. if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
  3022. strcat (buf, ", tso");
  3023. if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
  3024. strcat (buf, ", pso");
  3025. if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
  3026. strcat (buf, ", rmo");
  3027. break;
  3028. case EM_PARISC:
  3029. switch (e_flags & EF_PARISC_ARCH)
  3030. {
  3031. case EFA_PARISC_1_0:
  3032. strcpy (buf, ", PA-RISC 1.0");
  3033. break;
  3034. case EFA_PARISC_1_1:
  3035. strcpy (buf, ", PA-RISC 1.1");
  3036. break;
  3037. case EFA_PARISC_2_0:
  3038. strcpy (buf, ", PA-RISC 2.0");
  3039. break;
  3040. default:
  3041. break;
  3042. }
  3043. if (e_flags & EF_PARISC_TRAPNIL)
  3044. strcat (buf, ", trapnil");
  3045. if (e_flags & EF_PARISC_EXT)
  3046. strcat (buf, ", ext");
  3047. if (e_flags & EF_PARISC_LSB)
  3048. strcat (buf, ", lsb");
  3049. if (e_flags & EF_PARISC_WIDE)
  3050. strcat (buf, ", wide");
  3051. if (e_flags & EF_PARISC_NO_KABP)
  3052. strcat (buf, ", no kabp");
  3053. if (e_flags & EF_PARISC_LAZYSWAP)
  3054. strcat (buf, ", lazyswap");
  3055. break;
  3056. case EM_PJ:
  3057. case EM_PJ_OLD:
  3058. if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
  3059. strcat (buf, ", new calling convention");
  3060. if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
  3061. strcat (buf, ", gnu calling convention");
  3062. break;
  3063. case EM_IA_64:
  3064. if ((e_flags & EF_IA_64_ABI64))
  3065. strcat (buf, ", 64-bit");
  3066. else
  3067. strcat (buf, ", 32-bit");
  3068. if ((e_flags & EF_IA_64_REDUCEDFP))
  3069. strcat (buf, ", reduced fp model");
  3070. if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
  3071. strcat (buf, ", no function descriptors, constant gp");
  3072. else if ((e_flags & EF_IA_64_CONS_GP))
  3073. strcat (buf, ", constant gp");
  3074. if ((e_flags & EF_IA_64_ABSOLUTE))
  3075. strcat (buf, ", absolute");
  3076. if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
  3077. {
  3078. if ((e_flags & EF_IA_64_VMS_LINKAGES))
  3079. strcat (buf, ", vms_linkages");
  3080. switch ((e_flags & EF_IA_64_VMS_COMCOD))
  3081. {
  3082. case EF_IA_64_VMS_COMCOD_SUCCESS:
  3083. break;
  3084. case EF_IA_64_VMS_COMCOD_WARNING:
  3085. strcat (buf, ", warning");
  3086. break;
  3087. case EF_IA_64_VMS_COMCOD_ERROR:
  3088. strcat (buf, ", error");
  3089. break;
  3090. case EF_IA_64_VMS_COMCOD_ABORT:
  3091. strcat (buf, ", abort");
  3092. break;
  3093. default:
  3094. warn (_("Unrecognised IA64 VMS Command Code: %x\n"),
  3095. e_flags & EF_IA_64_VMS_COMCOD);
  3096. strcat (buf, ", <unknown>");
  3097. }
  3098. }
  3099. break;
  3100. case EM_VAX:
  3101. if ((e_flags & EF_VAX_NONPIC))
  3102. strcat (buf, ", non-PIC");
  3103. if ((e_flags & EF_VAX_DFLOAT))
  3104. strcat (buf, ", D-Float");
  3105. if ((e_flags & EF_VAX_GFLOAT))
  3106. strcat (buf, ", G-Float");
  3107. break;
  3108. case EM_VISIUM:
  3109. if (e_flags & EF_VISIUM_ARCH_MCM)
  3110. strcat (buf, ", mcm");
  3111. else if (e_flags & EF_VISIUM_ARCH_MCM24)
  3112. strcat (buf, ", mcm24");
  3113. if (e_flags & EF_VISIUM_ARCH_GR6)
  3114. strcat (buf, ", gr6");
  3115. break;
  3116. case EM_RL78:
  3117. switch (e_flags & E_FLAG_RL78_CPU_MASK)
  3118. {
  3119. case E_FLAG_RL78_ANY_CPU: break;
  3120. case E_FLAG_RL78_G10: strcat (buf, ", G10"); break;
  3121. case E_FLAG_RL78_G13: strcat (buf, ", G13"); break;
  3122. case E_FLAG_RL78_G14: strcat (buf, ", G14"); break;
  3123. }
  3124. if (e_flags & E_FLAG_RL78_64BIT_DOUBLES)
  3125. strcat (buf, ", 64-bit doubles");
  3126. break;
  3127. case EM_RX:
  3128. if (e_flags & E_FLAG_RX_64BIT_DOUBLES)
  3129. strcat (buf, ", 64-bit doubles");
  3130. if (e_flags & E_FLAG_RX_DSP)
  3131. strcat (buf, ", dsp");
  3132. if (e_flags & E_FLAG_RX_PID)
  3133. strcat (buf, ", pid");
  3134. if (e_flags & E_FLAG_RX_ABI)
  3135. strcat (buf, ", RX ABI");
  3136. if (e_flags & E_FLAG_RX_SINSNS_SET)
  3137. strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES
  3138. ? ", uses String instructions" : ", bans String instructions");
  3139. if (e_flags & E_FLAG_RX_V2)
  3140. strcat (buf, ", V2");
  3141. break;
  3142. case EM_S390:
  3143. if (e_flags & EF_S390_HIGH_GPRS)
  3144. strcat (buf, ", highgprs");
  3145. break;
  3146. case EM_TI_C6000:
  3147. if ((e_flags & EF_C6000_REL))
  3148. strcat (buf, ", relocatable module");
  3149. break;
  3150. case EM_MSP430:
  3151. strcat (buf, _(": architecture variant: "));
  3152. switch (e_flags & EF_MSP430_MACH)
  3153. {
  3154. case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break;
  3155. case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break;
  3156. case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break;
  3157. case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break;
  3158. case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break;
  3159. case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break;
  3160. case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break;
  3161. case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break;
  3162. case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break;
  3163. case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break;
  3164. case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break;
  3165. case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break;
  3166. case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break;
  3167. case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break;
  3168. case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break;
  3169. default:
  3170. strcat (buf, _(": unknown")); break;
  3171. }
  3172. if (e_flags & ~ EF_MSP430_MACH)
  3173. strcat (buf, _(": unknown extra flag bits also present"));
  3174. }
  3175. }
  3176. return buf;
  3177. }
  3178. static const char *
  3179. get_osabi_name (unsigned int osabi)
  3180. {
  3181. static char buff[32];
  3182. switch (osabi)
  3183. {
  3184. case ELFOSABI_NONE: return "UNIX - System V";
  3185. case ELFOSABI_HPUX: return "UNIX - HP-UX";
  3186. case ELFOSABI_NETBSD: return "UNIX - NetBSD";
  3187. case ELFOSABI_GNU: return "UNIX - GNU";
  3188. case ELFOSABI_SOLARIS: return "UNIX - Solaris";
  3189. case ELFOSABI_AIX: return "UNIX - AIX";
  3190. case ELFOSABI_IRIX: return "UNIX - IRIX";
  3191. case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
  3192. case ELFOSABI_TRU64: return "UNIX - TRU64";
  3193. case ELFOSABI_MODESTO: return "Novell - Modesto";
  3194. case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
  3195. case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
  3196. case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
  3197. case ELFOSABI_AROS: return "AROS";
  3198. case ELFOSABI_FENIXOS: return "FenixOS";
  3199. case ELFOSABI_CLOUDABI: return "Nuxi CloudABI";
  3200. case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS";
  3201. default:
  3202. if (osabi >= 64)
  3203. switch (elf_header.e_machine)
  3204. {
  3205. case EM_ARM:
  3206. switch (osabi)
  3207. {
  3208. case ELFOSABI_ARM: return "ARM";
  3209. default:
  3210. break;
  3211. }
  3212. break;
  3213. case EM_MSP430:
  3214. case EM_MSP430_OLD:
  3215. case EM_VISIUM:
  3216. switch (osabi)
  3217. {
  3218. case ELFOSABI_STANDALONE: return _("Standalone App");
  3219. default:
  3220. break;
  3221. }
  3222. break;
  3223. case EM_TI_C6000:
  3224. switch (osabi)
  3225. {
  3226. case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000");
  3227. case ELFOSABI_C6000_LINUX: return "Linux C6000";
  3228. default:
  3229. break;
  3230. }
  3231. break;
  3232. default:
  3233. break;
  3234. }
  3235. snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
  3236. return buff;
  3237. }
  3238. }
  3239. static const char *
  3240. get_aarch64_segment_type (unsigned long type)
  3241. {
  3242. switch (type)
  3243. {
  3244. case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT";
  3245. default: return NULL;
  3246. }
  3247. }
  3248. static const char *
  3249. get_arm_segment_type (unsigned long type)
  3250. {
  3251. switch (type)
  3252. {
  3253. case PT_ARM_EXIDX: return "EXIDX";
  3254. default: return NULL;
  3255. }
  3256. }
  3257. static const char *
  3258. get_s390_segment_type (unsigned long type)
  3259. {
  3260. switch (type)
  3261. {
  3262. case PT_S390_PGSTE: return "S390_PGSTE";
  3263. default: return NULL;
  3264. }
  3265. }
  3266. static const char *
  3267. get_mips_segment_type (unsigned long type)
  3268. {
  3269. switch (type)
  3270. {
  3271. case PT_MIPS_REGINFO: return "REGINFO";
  3272. case PT_MIPS_RTPROC: return "RTPROC";
  3273. case PT_MIPS_OPTIONS: return "OPTIONS";
  3274. case PT_MIPS_ABIFLAGS: return "ABIFLAGS";
  3275. default: return NULL;
  3276. }
  3277. }
  3278. static const char *
  3279. get_parisc_segment_type (unsigned long type)
  3280. {
  3281. switch (type)
  3282. {
  3283. case PT_HP_TLS: return "HP_TLS";
  3284. case PT_HP_CORE_NONE: return "HP_CORE_NONE";
  3285. case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
  3286. case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
  3287. case PT_HP_CORE_COMM: return "HP_CORE_COMM";
  3288. case PT_HP_CORE_PROC: return "HP_CORE_PROC";
  3289. case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
  3290. case PT_HP_CORE_STACK: return "HP_CORE_STACK";
  3291. case PT_HP_CORE_SHM: return "HP_CORE_SHM";
  3292. case PT_HP_CORE_MMF: return "HP_CORE_MMF";
  3293. case PT_HP_PARALLEL: return "HP_PARALLEL";
  3294. case PT_HP_FASTBIND: return "HP_FASTBIND";
  3295. case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT";
  3296. case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT";
  3297. case PT_HP_STACK: return "HP_STACK";
  3298. case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME";
  3299. case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
  3300. case PT_PARISC_UNWIND: return "PARISC_UNWIND";
  3301. case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER";
  3302. default: return NULL;
  3303. }
  3304. }
  3305. static const char *
  3306. get_ia64_segment_type (unsigned long type)
  3307. {
  3308. switch (type)
  3309. {
  3310. case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
  3311. case PT_IA_64_UNWIND: return "IA_64_UNWIND";
  3312. case PT_HP_TLS: return "HP_TLS";
  3313. case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
  3314. case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
  3315. case PT_IA_64_HP_STACK: return "HP_STACK";
  3316. default: return NULL;
  3317. }
  3318. }
  3319. static const char *
  3320. get_tic6x_segment_type (unsigned long type)
  3321. {
  3322. switch (type)
  3323. {
  3324. case PT_C6000_PHATTR: return "C6000_PHATTR";
  3325. default: return NULL;
  3326. }
  3327. }
  3328. static const char *
  3329. get_solaris_segment_type (unsigned long type)
  3330. {
  3331. switch (type)
  3332. {
  3333. case 0x6464e550: return "PT_SUNW_UNWIND";
  3334. case 0x6474e550: return "PT_SUNW_EH_FRAME";
  3335. case 0x6ffffff7: return "PT_LOSUNW";
  3336. case 0x6ffffffa: return "PT_SUNWBSS";
  3337. case 0x6ffffffb: return "PT_SUNWSTACK";
  3338. case 0x6ffffffc: return "PT_SUNWDTRACE";
  3339. case 0x6ffffffd: return "PT_SUNWCAP";
  3340. case 0x6fffffff: return "PT_HISUNW";
  3341. default: return NULL;
  3342. }
  3343. }
  3344. static const char *
  3345. get_segment_type (unsigned long p_type)
  3346. {
  3347. static char buff[32];
  3348. switch (p_type)
  3349. {
  3350. case PT_NULL: return "NULL";
  3351. case PT_LOAD: return "LOAD";
  3352. case PT_DYNAMIC: return "DYNAMIC";
  3353. case PT_INTERP: return "INTERP";
  3354. case PT_NOTE: return "NOTE";
  3355. case PT_SHLIB: return "SHLIB";
  3356. case PT_PHDR: return "PHDR";
  3357. case PT_TLS: return "TLS";
  3358. case PT_GNU_EH_FRAME: return "GNU_EH_FRAME";
  3359. case PT_GNU_STACK: return "GNU_STACK";
  3360. case PT_GNU_RELRO: return "GNU_RELRO";
  3361. default:
  3362. if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI)
  3363. {
  3364. sprintf (buff, "GNU_MBIND+%#lx",
  3365. p_type - PT_GNU_MBIND_LO);
  3366. }
  3367. else if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
  3368. {
  3369. const char * result;
  3370. switch (elf_header.e_machine)
  3371. {
  3372. case EM_AARCH64:
  3373. result = get_aarch64_segment_type (p_type);
  3374. break;
  3375. case EM_ARM:
  3376. result = get_arm_segment_type (p_type);
  3377. break;
  3378. case EM_MIPS:
  3379. case EM_MIPS_RS3_LE:
  3380. result = get_mips_segment_type (p_type);
  3381. break;
  3382. case EM_PARISC:
  3383. result = get_parisc_segment_type (p_type);
  3384. break;
  3385. case EM_IA_64:
  3386. result = get_ia64_segment_type (p_type);
  3387. break;
  3388. case EM_TI_C6000:
  3389. result = get_tic6x_segment_type (p_type);
  3390. break;
  3391. case EM_S390:
  3392. case EM_S390_OLD:
  3393. result = get_s390_segment_type (p_type);
  3394. break;
  3395. default:
  3396. result = NULL;
  3397. break;
  3398. }
  3399. if (result != NULL)
  3400. return result;
  3401. sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC);
  3402. }
  3403. else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
  3404. {
  3405. const char * result;
  3406. switch (elf_header.e_machine)
  3407. {
  3408. case EM_PARISC:
  3409. result = get_parisc_segment_type (p_type);
  3410. break;
  3411. case EM_IA_64:
  3412. result = get_ia64_segment_type (p_type);
  3413. break;
  3414. default:
  3415. if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
  3416. result = get_solaris_segment_type (p_type);
  3417. else
  3418. result = NULL;
  3419. break;
  3420. }
  3421. if (result != NULL)
  3422. return result;
  3423. sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS);
  3424. }
  3425. else
  3426. snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
  3427. return buff;
  3428. }
  3429. }
  3430. static const char *
  3431. get_arc_section_type_name (unsigned int sh_type)
  3432. {
  3433. switch (sh_type)
  3434. {
  3435. case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES";
  3436. default:
  3437. break;
  3438. }
  3439. return NULL;
  3440. }
  3441. static const char *
  3442. get_mips_section_type_name (unsigned int sh_type)
  3443. {
  3444. switch (sh_type)
  3445. {
  3446. case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
  3447. case SHT_MIPS_MSYM: return "MIPS_MSYM";
  3448. case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
  3449. case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
  3450. case SHT_MIPS_UCODE: return "MIPS_UCODE";
  3451. case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
  3452. case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
  3453. case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
  3454. case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
  3455. case SHT_MIPS_RELD: return "MIPS_RELD";
  3456. case SHT_MIPS_IFACE: return "MIPS_IFACE";
  3457. case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
  3458. case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
  3459. case SHT_MIPS_SHDR: return "MIPS_SHDR";
  3460. case SHT_MIPS_FDESC: return "MIPS_FDESC";
  3461. case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
  3462. case SHT_MIPS_DENSE: return "MIPS_DENSE";
  3463. case SHT_MIPS_PDESC: return "MIPS_PDESC";
  3464. case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
  3465. case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
  3466. case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
  3467. case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
  3468. case SHT_MIPS_LINE: return "MIPS_LINE";
  3469. case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
  3470. case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
  3471. case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
  3472. case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
  3473. case SHT_MIPS_DWARF: return "MIPS_DWARF";
  3474. case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
  3475. case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
  3476. case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
  3477. case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
  3478. case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
  3479. case SHT_MIPS_XLATE: return "MIPS_XLATE";
  3480. case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
  3481. case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
  3482. case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
  3483. case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
  3484. case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
  3485. case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS";
  3486. default:
  3487. break;
  3488. }
  3489. return NULL;
  3490. }
  3491. static const char *
  3492. get_parisc_section_type_name (unsigned int sh_type)
  3493. {
  3494. switch (sh_type)
  3495. {
  3496. case SHT_PARISC_EXT: return "PARISC_EXT";
  3497. case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
  3498. case SHT_PARISC_DOC: return "PARISC_DOC";
  3499. case SHT_PARISC_ANNOT: return "PARISC_ANNOT";
  3500. case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN";
  3501. case SHT_PARISC_STUBS: return "PARISC_STUBS";
  3502. case SHT_PARISC_DLKM: return "PARISC_DLKM";
  3503. default: return NULL;
  3504. }
  3505. }
  3506. static const char *
  3507. get_ia64_section_type_name (unsigned int sh_type)
  3508. {
  3509. /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
  3510. if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
  3511. return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
  3512. switch (sh_type)
  3513. {
  3514. case SHT_IA_64_EXT: return "IA_64_EXT";
  3515. case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
  3516. case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
  3517. case SHT_IA_64_VMS_TRACE: return "VMS_TRACE";
  3518. case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
  3519. case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG";
  3520. case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR";
  3521. case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES";
  3522. case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR";
  3523. case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP";
  3524. default:
  3525. break;
  3526. }
  3527. return NULL;
  3528. }
  3529. static const char *
  3530. get_x86_64_section_type_name (unsigned int sh_type)
  3531. {
  3532. switch (sh_type)
  3533. {
  3534. case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
  3535. default: return NULL;
  3536. }
  3537. }
  3538. static const char *
  3539. get_aarch64_section_type_name (unsigned int sh_type)
  3540. {
  3541. switch (sh_type)
  3542. {
  3543. case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES";
  3544. default: return NULL;
  3545. }
  3546. }
  3547. static const char *
  3548. get_arm_section_type_name (unsigned int sh_type)
  3549. {
  3550. switch (sh_type)
  3551. {
  3552. case SHT_ARM_EXIDX: return "ARM_EXIDX";
  3553. case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP";
  3554. case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES";
  3555. case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY";
  3556. case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION";
  3557. default: return NULL;
  3558. }
  3559. }
  3560. static const char *
  3561. get_tic6x_section_type_name (unsigned int sh_type)
  3562. {
  3563. switch (sh_type)
  3564. {
  3565. case SHT_C6000_UNWIND: return "C6000_UNWIND";
  3566. case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP";
  3567. case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES";
  3568. case SHT_TI_ICODE: return "TI_ICODE";
  3569. case SHT_TI_XREF: return "TI_XREF";
  3570. case SHT_TI_HANDLER: return "TI_HANDLER";
  3571. case SHT_TI_INITINFO: return "TI_INITINFO";
  3572. case SHT_TI_PHATTRS: return "TI_PHATTRS";
  3573. default: return NULL;
  3574. }
  3575. }
  3576. static const char *
  3577. get_msp430x_section_type_name (unsigned int sh_type)
  3578. {
  3579. switch (sh_type)
  3580. {
  3581. case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS";
  3582. case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES";
  3583. case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES";
  3584. default: return NULL;
  3585. }
  3586. }
  3587. static const char *
  3588. get_v850_section_type_name (unsigned int sh_type)
  3589. {
  3590. switch (sh_type)
  3591. {
  3592. case SHT_V850_SCOMMON: return "V850 Small Common";
  3593. case SHT_V850_TCOMMON: return "V850 Tiny Common";
  3594. case SHT_V850_ZCOMMON: return "V850 Zero Common";
  3595. case SHT_RENESAS_IOP: return "RENESAS IOP";
  3596. case SHT_RENESAS_INFO: return "RENESAS INFO";
  3597. default: return NULL;
  3598. }
  3599. }
  3600. static const char *
  3601. get_section_type_name (unsigned int sh_type)
  3602. {
  3603. static char buff[32];
  3604. const char * result;
  3605. switch (sh_type)
  3606. {
  3607. case SHT_NULL: return "NULL";
  3608. case SHT_PROGBITS: return "PROGBITS";
  3609. case SHT_SYMTAB: return "SYMTAB";
  3610. case SHT_STRTAB: return "STRTAB";
  3611. case SHT_RELA: return "RELA";
  3612. case SHT_HASH: return "HASH";
  3613. case SHT_DYNAMIC: return "DYNAMIC";
  3614. case SHT_NOTE: return "NOTE";
  3615. case SHT_NOBITS: return "NOBITS";
  3616. case SHT_REL: return "REL";
  3617. case SHT_SHLIB: return "SHLIB";
  3618. case SHT_DYNSYM: return "DYNSYM";
  3619. case SHT_INIT_ARRAY: return "INIT_ARRAY";
  3620. case SHT_FINI_ARRAY: return "FINI_ARRAY";
  3621. case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
  3622. case SHT_GNU_HASH: return "GNU_HASH";
  3623. case SHT_GROUP: return "GROUP";
  3624. case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
  3625. case SHT_GNU_verdef: return "VERDEF";
  3626. case SHT_GNU_verneed: return "VERNEED";
  3627. case SHT_GNU_versym: return "VERSYM";
  3628. case 0x6ffffff0: return "VERSYM";
  3629. case 0x6ffffffc: return "VERDEF";
  3630. case 0x7ffffffd: return "AUXILIARY";
  3631. case 0x7fffffff: return "FILTER";
  3632. case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
  3633. default:
  3634. if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
  3635. {
  3636. switch (elf_header.e_machine)
  3637. {
  3638. case EM_ARC:
  3639. case EM_ARC_COMPACT:
  3640. case EM_ARC_COMPACT2:
  3641. result = get_arc_section_type_name (sh_type);
  3642. break;
  3643. case EM_MIPS:
  3644. case EM_MIPS_RS3_LE:
  3645. result = get_mips_section_type_name (sh_type);
  3646. break;
  3647. case EM_PARISC:
  3648. result = get_parisc_section_type_name (sh_type);
  3649. break;
  3650. case EM_IA_64:
  3651. result = get_ia64_section_type_name (sh_type);
  3652. break;
  3653. case EM_X86_64:
  3654. case EM_L1OM:
  3655. case EM_K1OM:
  3656. result = get_x86_64_section_type_name (sh_type);
  3657. break;
  3658. case EM_AARCH64:
  3659. result = get_aarch64_section_type_name (sh_type);
  3660. break;
  3661. case EM_ARM:
  3662. result = get_arm_section_type_name (sh_type);
  3663. break;
  3664. case EM_TI_C6000:
  3665. result = get_tic6x_section_type_name (sh_type);
  3666. break;
  3667. case EM_MSP430:
  3668. result = get_msp430x_section_type_name (sh_type);
  3669. break;
  3670. case EM_V800:
  3671. case EM_V850:
  3672. case EM_CYGNUS_V850:
  3673. result = get_v850_section_type_name (sh_type);
  3674. break;
  3675. default:
  3676. result = NULL;
  3677. break;
  3678. }
  3679. if (result != NULL)
  3680. return result;
  3681. sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC);
  3682. }
  3683. else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
  3684. {
  3685. switch (elf_header.e_machine)
  3686. {
  3687. case EM_IA_64:
  3688. result = get_ia64_section_type_name (sh_type);
  3689. break;
  3690. default:
  3691. if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
  3692. result = get_solaris_section_type (sh_type);
  3693. else
  3694. {
  3695. switch (sh_type)
  3696. {
  3697. case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break;
  3698. case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break;
  3699. case SHT_GNU_HASH: result = "GNU_HASH"; break;
  3700. case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break;
  3701. default:
  3702. result = NULL;
  3703. break;
  3704. }
  3705. }
  3706. break;
  3707. }
  3708. if (result != NULL)
  3709. return result;
  3710. sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS);
  3711. }
  3712. else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
  3713. {
  3714. switch (elf_header.e_machine)
  3715. {
  3716. case EM_V800:
  3717. case EM_V850:
  3718. case EM_CYGNUS_V850:
  3719. result = get_v850_section_type_name (sh_type);
  3720. break;
  3721. default:
  3722. result = NULL;
  3723. break;
  3724. }
  3725. if (result != NULL)
  3726. return result;
  3727. sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER);
  3728. }
  3729. else
  3730. /* This message is probably going to be displayed in a 15
  3731. character wide field, so put the hex value first. */
  3732. snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type);
  3733. return buff;
  3734. }
  3735. }
  3736. #define OPTION_DEBUG_DUMP 512
  3737. #define OPTION_DYN_SYMS 513
  3738. #define OPTION_DWARF_DEPTH 514
  3739. #define OPTION_DWARF_START 515
  3740. #define OPTION_DWARF_CHECK 516
  3741. static struct option options[] =
  3742. {
  3743. {"all", no_argument, 0, 'a'},
  3744. {"file-header", no_argument, 0, 'h'},
  3745. {"program-headers", no_argument, 0, 'l'},
  3746. {"headers", no_argument, 0, 'e'},
  3747. {"histogram", no_argument, 0, 'I'},
  3748. {"segments", no_argument, 0, 'l'},
  3749. {"sections", no_argument, 0, 'S'},
  3750. {"section-headers", no_argument, 0, 'S'},
  3751. {"section-groups", no_argument, 0, 'g'},
  3752. {"section-details", no_argument, 0, 't'},
  3753. {"full-section-name",no_argument, 0, 'N'},
  3754. {"symbols", no_argument, 0, 's'},
  3755. {"syms", no_argument, 0, 's'},
  3756. {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS},
  3757. {"relocs", no_argument, 0, 'r'},
  3758. {"notes", no_argument, 0, 'n'},
  3759. {"dynamic", no_argument, 0, 'd'},
  3760. {"arch-specific", no_argument, 0, 'A'},
  3761. {"version-info", no_argument, 0, 'V'},
  3762. {"use-dynamic", no_argument, 0, 'D'},
  3763. {"unwind", no_argument, 0, 'u'},
  3764. {"archive-index", no_argument, 0, 'c'},
  3765. {"hex-dump", required_argument, 0, 'x'},
  3766. {"relocated-dump", required_argument, 0, 'R'},
  3767. {"string-dump", required_argument, 0, 'p'},
  3768. {"decompress", no_argument, 0, 'z'},
  3769. #ifdef SUPPORT_DISASSEMBLY
  3770. {"instruction-dump", required_argument, 0, 'i'},
  3771. #endif
  3772. {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
  3773. {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH},
  3774. {"dwarf-start", required_argument, 0, OPTION_DWARF_START},
  3775. {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
  3776. {"version", no_argument, 0, 'v'},
  3777. {"wide", no_argument, 0, 'W'},
  3778. {"help", no_argument, 0, 'H'},
  3779. {0, no_argument, 0, 0}
  3780. };
  3781. static void
  3782. usage (FILE * stream)
  3783. {
  3784. fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
  3785. fprintf (stream, _(" Display information about the contents of ELF format files\n"));
  3786. fprintf (stream, _(" Options are:\n\
  3787. -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
  3788. -h --file-header Display the ELF file header\n\
  3789. -l --program-headers Display the program headers\n\
  3790. --segments An alias for --program-headers\n\
  3791. -S --section-headers Display the sections' header\n\
  3792. --sections An alias for --section-headers\n\
  3793. -g --section-groups Display the section groups\n\
  3794. -t --section-details Display the section details\n\
  3795. -e --headers Equivalent to: -h -l -S\n\
  3796. -s --syms Display the symbol table\n\
  3797. --symbols An alias for --syms\n\
  3798. --dyn-syms Display the dynamic symbol table\n\
  3799. -n --notes Display the core notes (if present)\n\
  3800. -r --relocs Display the relocations (if present)\n\
  3801. -u --unwind Display the unwind info (if present)\n\
  3802. -d --dynamic Display the dynamic section (if present)\n\
  3803. -V --version-info Display the version sections (if present)\n\
  3804. -A --arch-specific Display architecture specific information (if any)\n\
  3805. -c --archive-index Display the symbol/file index in an archive\n\
  3806. -D --use-dynamic Use the dynamic section info when displaying symbols\n\
  3807. -x --hex-dump=<number|name>\n\
  3808. Dump the contents of section <number|name> as bytes\n\
  3809. -p --string-dump=<number|name>\n\
  3810. Dump the contents of section <number|name> as strings\n\
  3811. -R --relocated-dump=<number|name>\n\
  3812. Dump the contents of section <number|name> as relocated bytes\n\
  3813. -z --decompress Decompress section before dumping it\n\
  3814. -w[lLiaprmfFsoRt] or\n\
  3815. --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\
  3816. =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\
  3817. =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\
  3818. =addr,=cu_index]\n\
  3819. Display the contents of DWARF2 debug sections\n"));
  3820. fprintf (stream, _("\
  3821. --dwarf-depth=N Do not display DIEs at depth N or greater\n\
  3822. --dwarf-start=N Display DIEs starting with N, at the same depth\n\
  3823. or deeper\n"));
  3824. #ifdef SUPPORT_DISASSEMBLY
  3825. fprintf (stream, _("\
  3826. -i --instruction-dump=<number|name>\n\
  3827. Disassemble the contents of section <number|name>\n"));
  3828. #endif
  3829. fprintf (stream, _("\
  3830. -I --histogram Display histogram of bucket list lengths\n\
  3831. -W --wide Allow output width to exceed 80 characters\n\
  3832. @<file> Read options from <file>\n\
  3833. -H --help Display this information\n\
  3834. -v --version Display the version number of readelf\n"));
  3835. if (REPORT_BUGS_TO[0] && stream == stdout)
  3836. fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
  3837. exit (stream == stdout ? 0 : 1);
  3838. }
  3839. /* Record the fact that the user wants the contents of section number
  3840. SECTION to be displayed using the method(s) encoded as flags bits
  3841. in TYPE. Note, TYPE can be zero if we are creating the array for
  3842. the first time. */
  3843. static void
  3844. request_dump_bynumber (unsigned int section, dump_type type)
  3845. {
  3846. if (section >= num_dump_sects)
  3847. {
  3848. dump_type * new_dump_sects;
  3849. new_dump_sects = (dump_type *) calloc (section + 1,
  3850. sizeof (* dump_sects));
  3851. if (new_dump_sects == NULL)
  3852. error (_("Out of memory allocating dump request table.\n"));
  3853. else
  3854. {
  3855. if (dump_sects)
  3856. {
  3857. /* Copy current flag settings. */
  3858. memcpy (new_dump_sects, dump_sects, num_dump_sects * sizeof (* dump_sects));
  3859. free (dump_sects);
  3860. }
  3861. dump_sects = new_dump_sects;
  3862. num_dump_sects = section + 1;
  3863. }
  3864. }
  3865. if (dump_sects)
  3866. dump_sects[section] |= type;
  3867. return;
  3868. }
  3869. /* Request a dump by section name. */
  3870. static void
  3871. request_dump_byname (const char * section, dump_type type)
  3872. {
  3873. struct dump_list_entry * new_request;
  3874. new_request = (struct dump_list_entry *)
  3875. malloc (sizeof (struct dump_list_entry));
  3876. if (!new_request)
  3877. error (_("Out of memory allocating dump request table.\n"));
  3878. new_request->name = strdup (section);
  3879. if (!new_request->name)
  3880. error (_("Out of memory allocating dump request table.\n"));
  3881. new_request->type = type;
  3882. new_request->next = dump_sects_byname;
  3883. dump_sects_byname = new_request;
  3884. }
  3885. static inline void
  3886. request_dump (dump_type type)
  3887. {
  3888. int section;
  3889. char * cp;
  3890. do_dump++;
  3891. section = strtoul (optarg, & cp, 0);
  3892. if (! *cp && section >= 0)
  3893. request_dump_bynumber (section, type);
  3894. else
  3895. request_dump_byname (optarg, type);
  3896. }
  3897. static void
  3898. parse_args (int argc, char ** argv)
  3899. {
  3900. int c;
  3901. if (argc < 2)
  3902. usage (stderr);
  3903. while ((c = getopt_long
  3904. (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
  3905. {
  3906. switch (c)
  3907. {
  3908. case 0:
  3909. /* Long options. */
  3910. break;
  3911. case 'H':
  3912. usage (stdout);
  3913. break;
  3914. case 'a':
  3915. do_syms = TRUE;
  3916. do_reloc = TRUE;
  3917. do_unwind = TRUE;
  3918. do_dynamic = TRUE;
  3919. do_header = TRUE;
  3920. do_sections = TRUE;
  3921. do_section_groups = TRUE;
  3922. do_segments = TRUE;
  3923. do_version = TRUE;
  3924. do_histogram = TRUE;
  3925. do_arch = TRUE;
  3926. do_notes = TRUE;
  3927. break;
  3928. case 'g':
  3929. do_section_groups = TRUE;
  3930. break;
  3931. case 't':
  3932. case 'N':
  3933. do_sections = TRUE;
  3934. do_section_details = TRUE;
  3935. break;
  3936. case 'e':
  3937. do_header = TRUE;
  3938. do_sections = TRUE;
  3939. do_segments = TRUE;
  3940. break;
  3941. case 'A':
  3942. do_arch = TRUE;
  3943. break;
  3944. case 'D':
  3945. do_using_dynamic = TRUE;
  3946. break;
  3947. case 'r':
  3948. do_reloc = TRUE;
  3949. break;
  3950. case 'u':
  3951. do_unwind = TRUE;
  3952. break;
  3953. case 'h':
  3954. do_header = TRUE;
  3955. break;
  3956. case 'l':
  3957. do_segments = TRUE;
  3958. break;
  3959. case 's':
  3960. do_syms = TRUE;
  3961. break;
  3962. case 'S':
  3963. do_sections = TRUE;
  3964. break;
  3965. case 'd':
  3966. do_dynamic = TRUE;
  3967. break;
  3968. case 'I':
  3969. do_histogram = TRUE;
  3970. break;
  3971. case 'n':
  3972. do_notes = TRUE;
  3973. break;
  3974. case 'c':
  3975. do_archive_index = TRUE;
  3976. break;
  3977. case 'x':
  3978. request_dump (HEX_DUMP);
  3979. break;
  3980. case 'p':
  3981. request_dump (STRING_DUMP);
  3982. break;
  3983. case 'R':
  3984. request_dump (RELOC_DUMP);
  3985. break;
  3986. case 'z':
  3987. decompress_dumps = TRUE;
  3988. break;
  3989. case 'w':
  3990. do_dump = TRUE;
  3991. if (optarg == 0)
  3992. {
  3993. do_debugging = TRUE;
  3994. dwarf_select_sections_all ();
  3995. }
  3996. else
  3997. {
  3998. do_debugging = FALSE;
  3999. dwarf_select_sections_by_letters (optarg);
  4000. }
  4001. break;
  4002. case OPTION_DEBUG_DUMP:
  4003. do_dump = TRUE;
  4004. if (optarg == 0)
  4005. do_debugging = TRUE;
  4006. else
  4007. {
  4008. do_debugging = FALSE;
  4009. dwarf_select_sections_by_names (optarg);
  4010. }
  4011. break;
  4012. case OPTION_DWARF_DEPTH:
  4013. {
  4014. char *cp;
  4015. dwarf_cutoff_level = strtoul (optarg, & cp, 0);
  4016. }
  4017. break;
  4018. case OPTION_DWARF_START:
  4019. {
  4020. char *cp;
  4021. dwarf_start_die = strtoul (optarg, & cp, 0);
  4022. }
  4023. break;
  4024. case OPTION_DWARF_CHECK:
  4025. dwarf_check = TRUE;
  4026. break;
  4027. case OPTION_DYN_SYMS:
  4028. do_dyn_syms = TRUE;
  4029. break;
  4030. #ifdef SUPPORT_DISASSEMBLY
  4031. case 'i':
  4032. request_dump (DISASS_DUMP);
  4033. break;
  4034. #endif
  4035. case 'v':
  4036. print_version (program_name);
  4037. break;
  4038. case 'V':
  4039. do_version = TRUE;
  4040. break;
  4041. case 'W':
  4042. do_wide = TRUE;
  4043. break;
  4044. default:
  4045. /* xgettext:c-format */
  4046. error (_("Invalid option '-%c'\n"), c);
  4047. /* Fall through. */
  4048. case '?':
  4049. usage (stderr);
  4050. }
  4051. }
  4052. if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
  4053. && !do_segments && !do_header && !do_dump && !do_version
  4054. && !do_histogram && !do_debugging && !do_arch && !do_notes
  4055. && !do_section_groups && !do_archive_index
  4056. && !do_dyn_syms)
  4057. usage (stderr);
  4058. }
  4059. static const char *
  4060. get_elf_class (unsigned int elf_class)
  4061. {
  4062. static char buff[32];
  4063. switch (elf_class)
  4064. {
  4065. case ELFCLASSNONE: return _("none");
  4066. case ELFCLASS32: return "ELF32";
  4067. case ELFCLASS64: return "ELF64";
  4068. default:
  4069. snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
  4070. return buff;
  4071. }
  4072. }
  4073. static const char *
  4074. get_data_encoding (unsigned int encoding)
  4075. {
  4076. static char buff[32];
  4077. switch (encoding)
  4078. {
  4079. case ELFDATANONE: return _("none");
  4080. case ELFDATA2LSB: return _("2's complement, little endian");
  4081. case ELFDATA2MSB: return _("2's complement, big endian");
  4082. default:
  4083. snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
  4084. return buff;
  4085. }
  4086. }
  4087. /* Decode the data held in 'elf_header'. */
  4088. static bfd_boolean
  4089. process_file_header (void)
  4090. {
  4091. if ( elf_header.e_ident[EI_MAG0] != ELFMAG0
  4092. || elf_header.e_ident[EI_MAG1] != ELFMAG1
  4093. || elf_header.e_ident[EI_MAG2] != ELFMAG2
  4094. || elf_header.e_ident[EI_MAG3] != ELFMAG3)
  4095. {
  4096. error
  4097. (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
  4098. return FALSE;
  4099. }
  4100. init_dwarf_regnames (elf_header.e_machine);
  4101. if (do_header)
  4102. {
  4103. unsigned i;
  4104. printf (_("ELF Header:\n"));
  4105. printf (_(" Magic: "));
  4106. for (i = 0; i < EI_NIDENT; i++)
  4107. printf ("%2.2x ", elf_header.e_ident[i]);
  4108. printf ("\n");
  4109. printf (_(" Class: %s\n"),
  4110. get_elf_class (elf_header.e_ident[EI_CLASS]));
  4111. printf (_(" Data: %s\n"),
  4112. get_data_encoding (elf_header.e_ident[EI_DATA]));
  4113. printf (_(" Version: %d %s\n"),
  4114. elf_header.e_ident[EI_VERSION],
  4115. (elf_header.e_ident[EI_VERSION] == EV_CURRENT
  4116. ? "(current)"
  4117. : (elf_header.e_ident[EI_VERSION] != EV_NONE
  4118. ? _("<unknown: %lx>")
  4119. : "")));
  4120. printf (_(" OS/ABI: %s\n"),
  4121. get_osabi_name (elf_header.e_ident[EI_OSABI]));
  4122. printf (_(" ABI Version: %d\n"),
  4123. elf_header.e_ident[EI_ABIVERSION]);
  4124. printf (_(" Type: %s\n"),
  4125. get_file_type (elf_header.e_type));
  4126. printf (_(" Machine: %s\n"),
  4127. get_machine_name (elf_header.e_machine));
  4128. printf (_(" Version: 0x%lx\n"),
  4129. (unsigned long) elf_header.e_version);
  4130. printf (_(" Entry point address: "));
  4131. print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
  4132. printf (_("\n Start of program headers: "));
  4133. print_vma ((bfd_vma) elf_header.e_phoff, DEC);
  4134. printf (_(" (bytes into file)\n Start of section headers: "));
  4135. print_vma ((bfd_vma) elf_header.e_shoff, DEC);
  4136. printf (_(" (bytes into file)\n"));
  4137. printf (_(" Flags: 0x%lx%s\n"),
  4138. (unsigned long) elf_header.e_flags,
  4139. get_machine_flags (elf_header.e_flags, elf_header.e_machine));
  4140. printf (_(" Size of this header: %ld (bytes)\n"),
  4141. (long) elf_header.e_ehsize);
  4142. printf (_(" Size of program headers: %ld (bytes)\n"),
  4143. (long) elf_header.e_phentsize);
  4144. printf (_(" Number of program headers: %ld"),
  4145. (long) elf_header.e_phnum);
  4146. if (section_headers != NULL
  4147. && elf_header.e_phnum == PN_XNUM
  4148. && section_headers[0].sh_info != 0)
  4149. printf (" (%ld)", (long) section_headers[0].sh_info);
  4150. putc ('\n', stdout);
  4151. printf (_(" Size of section headers: %ld (bytes)\n"),
  4152. (long) elf_header.e_shentsize);
  4153. printf (_(" Number of section headers: %ld"),
  4154. (long) elf_header.e_shnum);
  4155. if (section_headers != NULL && elf_header.e_shnum == SHN_UNDEF)
  4156. printf (" (%ld)", (long) section_headers[0].sh_size);
  4157. putc ('\n', stdout);
  4158. printf (_(" Section header string table index: %ld"),
  4159. (long) elf_header.e_shstrndx);
  4160. if (section_headers != NULL
  4161. && elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
  4162. printf (" (%u)", section_headers[0].sh_link);
  4163. else if (elf_header.e_shstrndx != SHN_UNDEF
  4164. && elf_header.e_shstrndx >= elf_header.e_shnum)
  4165. printf (_(" <corrupt: out of range>"));
  4166. putc ('\n', stdout);
  4167. }
  4168. if (section_headers != NULL)
  4169. {
  4170. if (elf_header.e_phnum == PN_XNUM
  4171. && section_headers[0].sh_info != 0)
  4172. elf_header.e_phnum = section_headers[0].sh_info;
  4173. if (elf_header.e_shnum == SHN_UNDEF)
  4174. elf_header.e_shnum = section_headers[0].sh_size;
  4175. if (elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
  4176. elf_header.e_shstrndx = section_headers[0].sh_link;
  4177. else if (elf_header.e_shstrndx >= elf_header.e_shnum)
  4178. elf_header.e_shstrndx = SHN_UNDEF;
  4179. free (section_headers);
  4180. section_headers = NULL;
  4181. }
  4182. return TRUE;
  4183. }
  4184. static bfd_boolean
  4185. get_32bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
  4186. {
  4187. Elf32_External_Phdr * phdrs;
  4188. Elf32_External_Phdr * external;
  4189. Elf_Internal_Phdr * internal;
  4190. unsigned int i;
  4191. unsigned int size = elf_header.e_phentsize;
  4192. unsigned int num = elf_header.e_phnum;
  4193. /* PR binutils/17531: Cope with unexpected section header sizes. */
  4194. if (size == 0 || num == 0)
  4195. return FALSE;
  4196. if (size < sizeof * phdrs)
  4197. {
  4198. error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
  4199. return FALSE;
  4200. }
  4201. if (size > sizeof * phdrs)
  4202. warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
  4203. phdrs = (Elf32_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
  4204. size, num, _("program headers"));
  4205. if (phdrs == NULL)
  4206. return FALSE;
  4207. for (i = 0, internal = pheaders, external = phdrs;
  4208. i < elf_header.e_phnum;
  4209. i++, internal++, external++)
  4210. {
  4211. internal->p_type = BYTE_GET (external->p_type);
  4212. internal->p_offset = BYTE_GET (external->p_offset);
  4213. internal->p_vaddr = BYTE_GET (external->p_vaddr);
  4214. internal->p_paddr = BYTE_GET (external->p_paddr);
  4215. internal->p_filesz = BYTE_GET (external->p_filesz);
  4216. internal->p_memsz = BYTE_GET (external->p_memsz);
  4217. internal->p_flags = BYTE_GET (external->p_flags);
  4218. internal->p_align = BYTE_GET (external->p_align);
  4219. }
  4220. free (phdrs);
  4221. return TRUE;
  4222. }
  4223. static bfd_boolean
  4224. get_64bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
  4225. {
  4226. Elf64_External_Phdr * phdrs;
  4227. Elf64_External_Phdr * external;
  4228. Elf_Internal_Phdr * internal;
  4229. unsigned int i;
  4230. unsigned int size = elf_header.e_phentsize;
  4231. unsigned int num = elf_header.e_phnum;
  4232. /* PR binutils/17531: Cope with unexpected section header sizes. */
  4233. if (size == 0 || num == 0)
  4234. return FALSE;
  4235. if (size < sizeof * phdrs)
  4236. {
  4237. error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
  4238. return FALSE;
  4239. }
  4240. if (size > sizeof * phdrs)
  4241. warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
  4242. phdrs = (Elf64_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
  4243. size, num, _("program headers"));
  4244. if (!phdrs)
  4245. return FALSE;
  4246. for (i = 0, internal = pheaders, external = phdrs;
  4247. i < elf_header.e_phnum;
  4248. i++, internal++, external++)
  4249. {
  4250. internal->p_type = BYTE_GET (external->p_type);
  4251. internal->p_flags = BYTE_GET (external->p_flags);
  4252. internal->p_offset = BYTE_GET (external->p_offset);
  4253. internal->p_vaddr = BYTE_GET (external->p_vaddr);
  4254. internal->p_paddr = BYTE_GET (external->p_paddr);
  4255. internal->p_filesz = BYTE_GET (external->p_filesz);
  4256. internal->p_memsz = BYTE_GET (external->p_memsz);
  4257. internal->p_align = BYTE_GET (external->p_align);
  4258. }
  4259. free (phdrs);
  4260. return TRUE;
  4261. }
  4262. /* Returns TRUE if the program headers were read into `program_headers'. */
  4263. static bfd_boolean
  4264. get_program_headers (FILE * file)
  4265. {
  4266. Elf_Internal_Phdr * phdrs;
  4267. /* Check cache of prior read. */
  4268. if (program_headers != NULL)
  4269. return TRUE;
  4270. /* Be kind to memory checkers by looking for
  4271. e_phnum values which we know must be invalid. */
  4272. if (elf_header.e_phnum
  4273. * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr))
  4274. >= current_file_size)
  4275. {
  4276. error (_("Too many program headers - %#x - the file is not that big\n"),
  4277. elf_header.e_phnum);
  4278. return FALSE;
  4279. }
  4280. phdrs = (Elf_Internal_Phdr *) cmalloc (elf_header.e_phnum,
  4281. sizeof (Elf_Internal_Phdr));
  4282. if (phdrs == NULL)
  4283. {
  4284. error (_("Out of memory reading %u program headers\n"),
  4285. elf_header.e_phnum);
  4286. return FALSE;
  4287. }
  4288. if (is_32bit_elf
  4289. ? get_32bit_program_headers (file, phdrs)
  4290. : get_64bit_program_headers (file, phdrs))
  4291. {
  4292. program_headers = phdrs;
  4293. return TRUE;
  4294. }
  4295. free (phdrs);
  4296. return FALSE;
  4297. }
  4298. /* Returns TRUE if the program headers were loaded. */
  4299. static bfd_boolean
  4300. process_program_headers (FILE * file)
  4301. {
  4302. Elf_Internal_Phdr * segment;
  4303. unsigned int i;
  4304. Elf_Internal_Phdr * previous_load = NULL;
  4305. if (elf_header.e_phnum == 0)
  4306. {
  4307. /* PR binutils/12467. */
  4308. if (elf_header.e_phoff != 0)
  4309. {
  4310. warn (_("possibly corrupt ELF header - it has a non-zero program"
  4311. " header offset, but no program headers\n"));
  4312. return FALSE;
  4313. }
  4314. else if (do_segments)
  4315. printf (_("\nThere are no program headers in this file.\n"));
  4316. return TRUE;
  4317. }
  4318. if (do_segments && !do_header)
  4319. {
  4320. printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
  4321. printf (_("Entry point "));
  4322. print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
  4323. printf (_("\nThere are %d program headers, starting at offset "),
  4324. elf_header.e_phnum);
  4325. print_vma ((bfd_vma) elf_header.e_phoff, DEC);
  4326. printf ("\n");
  4327. }
  4328. if (! get_program_headers (file))
  4329. return TRUE;
  4330. if (do_segments)
  4331. {
  4332. if (elf_header.e_phnum > 1)
  4333. printf (_("\nProgram Headers:\n"));
  4334. else
  4335. printf (_("\nProgram Headers:\n"));
  4336. if (is_32bit_elf)
  4337. printf
  4338. (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
  4339. else if (do_wide)
  4340. printf
  4341. (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
  4342. else
  4343. {
  4344. printf
  4345. (_(" Type Offset VirtAddr PhysAddr\n"));
  4346. printf
  4347. (_(" FileSiz MemSiz Flags Align\n"));
  4348. }
  4349. }
  4350. dynamic_addr = 0;
  4351. dynamic_size = 0;
  4352. for (i = 0, segment = program_headers;
  4353. i < elf_header.e_phnum;
  4354. i++, segment++)
  4355. {
  4356. if (do_segments)
  4357. {
  4358. printf (" %-14.14s ", get_segment_type (segment->p_type));
  4359. if (is_32bit_elf)
  4360. {
  4361. printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
  4362. printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
  4363. printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
  4364. printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
  4365. printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
  4366. printf ("%c%c%c ",
  4367. (segment->p_flags & PF_R ? 'R' : ' '),
  4368. (segment->p_flags & PF_W ? 'W' : ' '),
  4369. (segment->p_flags & PF_X ? 'E' : ' '));
  4370. printf ("%#lx", (unsigned long) segment->p_align);
  4371. }
  4372. else if (do_wide)
  4373. {
  4374. if ((unsigned long) segment->p_offset == segment->p_offset)
  4375. printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
  4376. else
  4377. {
  4378. print_vma (segment->p_offset, FULL_HEX);
  4379. putchar (' ');
  4380. }
  4381. print_vma (segment->p_vaddr, FULL_HEX);
  4382. putchar (' ');
  4383. print_vma (segment->p_paddr, FULL_HEX);
  4384. putchar (' ');
  4385. if ((unsigned long) segment->p_filesz == segment->p_filesz)
  4386. printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
  4387. else
  4388. {
  4389. print_vma (segment->p_filesz, FULL_HEX);
  4390. putchar (' ');
  4391. }
  4392. if ((unsigned long) segment->p_memsz == segment->p_memsz)
  4393. printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
  4394. else
  4395. {
  4396. print_vma (segment->p_memsz, FULL_HEX);
  4397. }
  4398. printf (" %c%c%c ",
  4399. (segment->p_flags & PF_R ? 'R' : ' '),
  4400. (segment->p_flags & PF_W ? 'W' : ' '),
  4401. (segment->p_flags & PF_X ? 'E' : ' '));
  4402. if ((unsigned long) segment->p_align == segment->p_align)
  4403. printf ("%#lx", (unsigned long) segment->p_align);
  4404. else
  4405. {
  4406. print_vma (segment->p_align, PREFIX_HEX);
  4407. }
  4408. }
  4409. else
  4410. {
  4411. print_vma (segment->p_offset, FULL_HEX);
  4412. putchar (' ');
  4413. print_vma (segment->p_vaddr, FULL_HEX);
  4414. putchar (' ');
  4415. print_vma (segment->p_paddr, FULL_HEX);
  4416. printf ("\n ");
  4417. print_vma (segment->p_filesz, FULL_HEX);
  4418. putchar (' ');
  4419. print_vma (segment->p_memsz, FULL_HEX);
  4420. printf (" %c%c%c ",
  4421. (segment->p_flags & PF_R ? 'R' : ' '),
  4422. (segment->p_flags & PF_W ? 'W' : ' '),
  4423. (segment->p_flags & PF_X ? 'E' : ' '));
  4424. print_vma (segment->p_align, PREFIX_HEX);
  4425. }
  4426. putc ('\n', stdout);
  4427. }
  4428. switch (segment->p_type)
  4429. {
  4430. case PT_LOAD:
  4431. #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially
  4432. required by the ELF standard, several programs, including the Linux
  4433. kernel, make use of non-ordered segments. */
  4434. if (previous_load
  4435. && previous_load->p_vaddr > segment->p_vaddr)
  4436. error (_("LOAD segments must be sorted in order of increasing VirtAddr\n"));
  4437. #endif
  4438. if (segment->p_memsz < segment->p_filesz)
  4439. error (_("the segment's file size is larger than its memory size\n"));
  4440. previous_load = segment;
  4441. break;
  4442. case PT_PHDR:
  4443. /* PR 20815 - Verify that the program header is loaded into memory. */
  4444. if (i > 0 && previous_load != NULL)
  4445. error (_("the PHDR segment must occur before any LOAD segment\n"));
  4446. if (elf_header.e_machine != EM_PARISC)
  4447. {
  4448. unsigned int j;
  4449. for (j = 1; j < elf_header.e_phnum; j++)
  4450. if (program_headers[j].p_vaddr <= segment->p_vaddr
  4451. && (program_headers[j].p_vaddr + program_headers[j].p_memsz)
  4452. >= (segment->p_vaddr + segment->p_filesz))
  4453. break;
  4454. if (j == elf_header.e_phnum)
  4455. error (_("the PHDR segment is not covered by a LOAD segment\n"));
  4456. }
  4457. break;
  4458. case PT_DYNAMIC:
  4459. if (dynamic_addr)
  4460. error (_("more than one dynamic segment\n"));
  4461. /* By default, assume that the .dynamic section is the first
  4462. section in the DYNAMIC segment. */
  4463. dynamic_addr = segment->p_offset;
  4464. dynamic_size = segment->p_filesz;
  4465. /* Try to locate the .dynamic section. If there is
  4466. a section header table, we can easily locate it. */
  4467. if (section_headers != NULL)
  4468. {
  4469. Elf_Internal_Shdr * sec;
  4470. sec = find_section (".dynamic");
  4471. if (sec == NULL || sec->sh_size == 0)
  4472. {
  4473. /* A corresponding .dynamic section is expected, but on
  4474. IA-64/OpenVMS it is OK for it to be missing. */
  4475. if (!is_ia64_vms ())
  4476. error (_("no .dynamic section in the dynamic segment\n"));
  4477. break;
  4478. }
  4479. if (sec->sh_type == SHT_NOBITS)
  4480. {
  4481. dynamic_size = 0;
  4482. break;
  4483. }
  4484. dynamic_addr = sec->sh_offset;
  4485. dynamic_size = sec->sh_size;
  4486. if (dynamic_addr < segment->p_offset
  4487. || dynamic_addr > segment->p_offset + segment->p_filesz)
  4488. warn (_("the .dynamic section is not contained"
  4489. " within the dynamic segment\n"));
  4490. else if (dynamic_addr > segment->p_offset)
  4491. warn (_("the .dynamic section is not the first section"
  4492. " in the dynamic segment.\n"));
  4493. }
  4494. /* PR binutils/17512: Avoid corrupt dynamic section info in the
  4495. segment. Check this after matching against the section headers
  4496. so we don't warn on debuginfo file (which have NOBITS .dynamic
  4497. sections). */
  4498. if (dynamic_addr + dynamic_size >= current_file_size)
  4499. {
  4500. error (_("the dynamic segment offset + size exceeds the size of the file\n"));
  4501. dynamic_addr = dynamic_size = 0;
  4502. }
  4503. break;
  4504. case PT_INTERP:
  4505. if (fseek (file, archive_file_offset + (long) segment->p_offset,
  4506. SEEK_SET))
  4507. error (_("Unable to find program interpreter name\n"));
  4508. else
  4509. {
  4510. char fmt [32];
  4511. int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1);
  4512. if (ret >= (int) sizeof (fmt) || ret < 0)
  4513. error (_("Internal error: failed to create format string to display program interpreter\n"));
  4514. program_interpreter[0] = 0;
  4515. if (fscanf (file, fmt, program_interpreter) <= 0)
  4516. error (_("Unable to read program interpreter name\n"));
  4517. if (do_segments)
  4518. printf (_(" [Requesting program interpreter: %s]\n"),
  4519. program_interpreter);
  4520. }
  4521. break;
  4522. }
  4523. }
  4524. if (do_segments && section_headers != NULL && string_table != NULL)
  4525. {
  4526. printf (_("\n Section to Segment mapping:\n"));
  4527. printf (_(" Segment Sections...\n"));
  4528. for (i = 0; i < elf_header.e_phnum; i++)
  4529. {
  4530. unsigned int j;
  4531. Elf_Internal_Shdr * section;
  4532. segment = program_headers + i;
  4533. section = section_headers + 1;
  4534. printf (" %2.2d ", i);
  4535. for (j = 1; j < elf_header.e_shnum; j++, section++)
  4536. {
  4537. if (!ELF_TBSS_SPECIAL (section, segment)
  4538. && ELF_SECTION_IN_SEGMENT_STRICT (section, segment))
  4539. printf ("%s ", printable_section_name (section));
  4540. }
  4541. putc ('\n',stdout);
  4542. }
  4543. }
  4544. return TRUE;
  4545. }
  4546. /* Find the file offset corresponding to VMA by using the program headers. */
  4547. static long
  4548. offset_from_vma (FILE * file, bfd_vma vma, bfd_size_type size)
  4549. {
  4550. Elf_Internal_Phdr * seg;
  4551. if (! get_program_headers (file))
  4552. {
  4553. warn (_("Cannot interpret virtual addresses without program headers.\n"));
  4554. return (long) vma;
  4555. }
  4556. for (seg = program_headers;
  4557. seg < program_headers + elf_header.e_phnum;
  4558. ++seg)
  4559. {
  4560. if (seg->p_type != PT_LOAD)
  4561. continue;
  4562. if (vma >= (seg->p_vaddr & -seg->p_align)
  4563. && vma + size <= seg->p_vaddr + seg->p_filesz)
  4564. return vma - seg->p_vaddr + seg->p_offset;
  4565. }
  4566. warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
  4567. (unsigned long) vma);
  4568. return (long) vma;
  4569. }
  4570. /* Allocate memory and load the sections headers into the global pointer
  4571. SECTION_HEADERS. If PROBE is true, this is just a probe and we do not
  4572. generate any error messages if the load fails. */
  4573. static bfd_boolean
  4574. get_32bit_section_headers (FILE * file, bfd_boolean probe)
  4575. {
  4576. Elf32_External_Shdr * shdrs;
  4577. Elf_Internal_Shdr * internal;
  4578. unsigned int i;
  4579. unsigned int size = elf_header.e_shentsize;
  4580. unsigned int num = probe ? 1 : elf_header.e_shnum;
  4581. /* PR binutils/17531: Cope with unexpected section header sizes. */
  4582. if (size == 0 || num == 0)
  4583. return FALSE;
  4584. if (size < sizeof * shdrs)
  4585. {
  4586. if (! probe)
  4587. error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
  4588. return FALSE;
  4589. }
  4590. if (!probe && size > sizeof * shdrs)
  4591. warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
  4592. shdrs = (Elf32_External_Shdr *) get_data (NULL, file, elf_header.e_shoff,
  4593. size, num,
  4594. probe ? NULL : _("section headers"));
  4595. if (shdrs == NULL)
  4596. return FALSE;
  4597. if (section_headers != NULL)
  4598. free (section_headers);
  4599. section_headers = (Elf_Internal_Shdr *) cmalloc (num,
  4600. sizeof (Elf_Internal_Shdr));
  4601. if (section_headers == NULL)
  4602. {
  4603. if (!probe)
  4604. error (_("Out of memory reading %u section headers\n"), num);
  4605. return FALSE;
  4606. }
  4607. for (i = 0, internal = section_headers;
  4608. i < num;
  4609. i++, internal++)
  4610. {
  4611. internal->sh_name = BYTE_GET (shdrs[i].sh_name);
  4612. internal->sh_type = BYTE_GET (shdrs[i].sh_type);
  4613. internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
  4614. internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
  4615. internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
  4616. internal->sh_size = BYTE_GET (shdrs[i].sh_size);
  4617. internal->sh_link = BYTE_GET (shdrs[i].sh_link);
  4618. internal->sh_info = BYTE_GET (shdrs[i].sh_info);
  4619. internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
  4620. internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
  4621. if (!probe && internal->sh_link > num)
  4622. warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
  4623. if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
  4624. warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
  4625. }
  4626. free (shdrs);
  4627. return TRUE;
  4628. }
  4629. static bfd_boolean
  4630. get_64bit_section_headers (FILE * file, bfd_boolean probe)
  4631. {
  4632. Elf64_External_Shdr * shdrs;
  4633. Elf_Internal_Shdr * internal;
  4634. unsigned int i;
  4635. unsigned int size = elf_header.e_shentsize;
  4636. unsigned int num = probe ? 1 : elf_header.e_shnum;
  4637. /* PR binutils/17531: Cope with unexpected section header sizes. */
  4638. if (size == 0 || num == 0)
  4639. return FALSE;
  4640. if (size < sizeof * shdrs)
  4641. {
  4642. if (! probe)
  4643. error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n"));
  4644. return FALSE;
  4645. }
  4646. if (! probe && size > sizeof * shdrs)
  4647. warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n"));
  4648. shdrs = (Elf64_External_Shdr *) get_data (NULL, file, elf_header.e_shoff,
  4649. size, num,
  4650. probe ? NULL : _("section headers"));
  4651. if (shdrs == NULL)
  4652. return FALSE;
  4653. if (section_headers != NULL)
  4654. free (section_headers);
  4655. section_headers = (Elf_Internal_Shdr *) cmalloc (num,
  4656. sizeof (Elf_Internal_Shdr));
  4657. if (section_headers == NULL)
  4658. {
  4659. if (! probe)
  4660. error (_("Out of memory reading %u section headers\n"), num);
  4661. return FALSE;
  4662. }
  4663. for (i = 0, internal = section_headers;
  4664. i < num;
  4665. i++, internal++)
  4666. {
  4667. internal->sh_name = BYTE_GET (shdrs[i].sh_name);
  4668. internal->sh_type = BYTE_GET (shdrs[i].sh_type);
  4669. internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
  4670. internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
  4671. internal->sh_size = BYTE_GET (shdrs[i].sh_size);
  4672. internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
  4673. internal->sh_link = BYTE_GET (shdrs[i].sh_link);
  4674. internal->sh_info = BYTE_GET (shdrs[i].sh_info);
  4675. internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
  4676. internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
  4677. if (!probe && internal->sh_link > num)
  4678. warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link);
  4679. if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num)
  4680. warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info);
  4681. }
  4682. free (shdrs);
  4683. return TRUE;
  4684. }
  4685. static Elf_Internal_Sym *
  4686. get_32bit_elf_symbols (FILE * file,
  4687. Elf_Internal_Shdr * section,
  4688. unsigned long * num_syms_return)
  4689. {
  4690. unsigned long number = 0;
  4691. Elf32_External_Sym * esyms = NULL;
  4692. Elf_External_Sym_Shndx * shndx = NULL;
  4693. Elf_Internal_Sym * isyms = NULL;
  4694. Elf_Internal_Sym * psym;
  4695. unsigned int j;
  4696. if (section->sh_size == 0)
  4697. {
  4698. if (num_syms_return != NULL)
  4699. * num_syms_return = 0;
  4700. return NULL;
  4701. }
  4702. /* Run some sanity checks first. */
  4703. if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
  4704. {
  4705. error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
  4706. printable_section_name (section), (unsigned long) section->sh_entsize);
  4707. goto exit_point;
  4708. }
  4709. if (section->sh_size > current_file_size)
  4710. {
  4711. error (_("Section %s has an invalid sh_size of 0x%lx\n"),
  4712. printable_section_name (section), (unsigned long) section->sh_size);
  4713. goto exit_point;
  4714. }
  4715. number = section->sh_size / section->sh_entsize;
  4716. if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1)
  4717. {
  4718. error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
  4719. (unsigned long) section->sh_size,
  4720. printable_section_name (section),
  4721. (unsigned long) section->sh_entsize);
  4722. goto exit_point;
  4723. }
  4724. esyms = (Elf32_External_Sym *) get_data (NULL, file, section->sh_offset, 1,
  4725. section->sh_size, _("symbols"));
  4726. if (esyms == NULL)
  4727. goto exit_point;
  4728. {
  4729. elf_section_list * entry;
  4730. shndx = NULL;
  4731. for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
  4732. if (entry->hdr->sh_link == (unsigned long) (section - section_headers))
  4733. {
  4734. shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file,
  4735. entry->hdr->sh_offset,
  4736. 1, entry->hdr->sh_size,
  4737. _("symbol table section indicies"));
  4738. if (shndx == NULL)
  4739. goto exit_point;
  4740. /* PR17531: file: heap-buffer-overflow */
  4741. else if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
  4742. {
  4743. error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
  4744. printable_section_name (entry->hdr),
  4745. (unsigned long) entry->hdr->sh_size,
  4746. (unsigned long) section->sh_size);
  4747. goto exit_point;
  4748. }
  4749. }
  4750. }
  4751. isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
  4752. if (isyms == NULL)
  4753. {
  4754. error (_("Out of memory reading %lu symbols\n"),
  4755. (unsigned long) number);
  4756. goto exit_point;
  4757. }
  4758. for (j = 0, psym = isyms; j < number; j++, psym++)
  4759. {
  4760. psym->st_name = BYTE_GET (esyms[j].st_name);
  4761. psym->st_value = BYTE_GET (esyms[j].st_value);
  4762. psym->st_size = BYTE_GET (esyms[j].st_size);
  4763. psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
  4764. if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
  4765. psym->st_shndx
  4766. = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
  4767. else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
  4768. psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
  4769. psym->st_info = BYTE_GET (esyms[j].st_info);
  4770. psym->st_other = BYTE_GET (esyms[j].st_other);
  4771. }
  4772. exit_point:
  4773. if (shndx != NULL)
  4774. free (shndx);
  4775. if (esyms != NULL)
  4776. free (esyms);
  4777. if (num_syms_return != NULL)
  4778. * num_syms_return = isyms == NULL ? 0 : number;
  4779. return isyms;
  4780. }
  4781. static Elf_Internal_Sym *
  4782. get_64bit_elf_symbols (FILE * file,
  4783. Elf_Internal_Shdr * section,
  4784. unsigned long * num_syms_return)
  4785. {
  4786. unsigned long number = 0;
  4787. Elf64_External_Sym * esyms = NULL;
  4788. Elf_External_Sym_Shndx * shndx = NULL;
  4789. Elf_Internal_Sym * isyms = NULL;
  4790. Elf_Internal_Sym * psym;
  4791. unsigned int j;
  4792. if (section->sh_size == 0)
  4793. {
  4794. if (num_syms_return != NULL)
  4795. * num_syms_return = 0;
  4796. return NULL;
  4797. }
  4798. /* Run some sanity checks first. */
  4799. if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size)
  4800. {
  4801. error (_("Section %s has an invalid sh_entsize of 0x%lx\n"),
  4802. printable_section_name (section),
  4803. (unsigned long) section->sh_entsize);
  4804. goto exit_point;
  4805. }
  4806. if (section->sh_size > current_file_size)
  4807. {
  4808. error (_("Section %s has an invalid sh_size of 0x%lx\n"),
  4809. printable_section_name (section),
  4810. (unsigned long) section->sh_size);
  4811. goto exit_point;
  4812. }
  4813. number = section->sh_size / section->sh_entsize;
  4814. if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1)
  4815. {
  4816. error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"),
  4817. (unsigned long) section->sh_size,
  4818. printable_section_name (section),
  4819. (unsigned long) section->sh_entsize);
  4820. goto exit_point;
  4821. }
  4822. esyms = (Elf64_External_Sym *) get_data (NULL, file, section->sh_offset, 1,
  4823. section->sh_size, _("symbols"));
  4824. if (!esyms)
  4825. goto exit_point;
  4826. {
  4827. elf_section_list * entry;
  4828. shndx = NULL;
  4829. for (entry = symtab_shndx_list; entry != NULL; entry = entry->next)
  4830. if (entry->hdr->sh_link == (unsigned long) (section - section_headers))
  4831. {
  4832. shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file,
  4833. entry->hdr->sh_offset,
  4834. 1, entry->hdr->sh_size,
  4835. _("symbol table section indicies"));
  4836. if (shndx == NULL)
  4837. goto exit_point;
  4838. /* PR17531: file: heap-buffer-overflow */
  4839. else if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number)
  4840. {
  4841. error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"),
  4842. printable_section_name (entry->hdr),
  4843. (unsigned long) entry->hdr->sh_size,
  4844. (unsigned long) section->sh_size);
  4845. goto exit_point;
  4846. }
  4847. }
  4848. }
  4849. isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym));
  4850. if (isyms == NULL)
  4851. {
  4852. error (_("Out of memory reading %lu symbols\n"),
  4853. (unsigned long) number);
  4854. goto exit_point;
  4855. }
  4856. for (j = 0, psym = isyms; j < number; j++, psym++)
  4857. {
  4858. psym->st_name = BYTE_GET (esyms[j].st_name);
  4859. psym->st_info = BYTE_GET (esyms[j].st_info);
  4860. psym->st_other = BYTE_GET (esyms[j].st_other);
  4861. psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
  4862. if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
  4863. psym->st_shndx
  4864. = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
  4865. else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
  4866. psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
  4867. psym->st_value = BYTE_GET (esyms[j].st_value);
  4868. psym->st_size = BYTE_GET (esyms[j].st_size);
  4869. }
  4870. exit_point:
  4871. if (shndx != NULL)
  4872. free (shndx);
  4873. if (esyms != NULL)
  4874. free (esyms);
  4875. if (num_syms_return != NULL)
  4876. * num_syms_return = isyms == NULL ? 0 : number;
  4877. return isyms;
  4878. }
  4879. static const char *
  4880. get_elf_section_flags (bfd_vma sh_flags)
  4881. {
  4882. static char buff[1024];
  4883. char * p = buff;
  4884. unsigned int field_size = is_32bit_elf ? 8 : 16;
  4885. signed int sindex;
  4886. unsigned int size = sizeof (buff) - (field_size + 4 + 1);
  4887. bfd_vma os_flags = 0;
  4888. bfd_vma proc_flags = 0;
  4889. bfd_vma unknown_flags = 0;
  4890. static const struct
  4891. {
  4892. const char * str;
  4893. unsigned int len;
  4894. }
  4895. flags [] =
  4896. {
  4897. /* 0 */ { STRING_COMMA_LEN ("WRITE") },
  4898. /* 1 */ { STRING_COMMA_LEN ("ALLOC") },
  4899. /* 2 */ { STRING_COMMA_LEN ("EXEC") },
  4900. /* 3 */ { STRING_COMMA_LEN ("MERGE") },
  4901. /* 4 */ { STRING_COMMA_LEN ("STRINGS") },
  4902. /* 5 */ { STRING_COMMA_LEN ("INFO LINK") },
  4903. /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") },
  4904. /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") },
  4905. /* 8 */ { STRING_COMMA_LEN ("GROUP") },
  4906. /* 9 */ { STRING_COMMA_LEN ("TLS") },
  4907. /* IA-64 specific. */
  4908. /* 10 */ { STRING_COMMA_LEN ("SHORT") },
  4909. /* 11 */ { STRING_COMMA_LEN ("NORECOV") },
  4910. /* IA-64 OpenVMS specific. */
  4911. /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") },
  4912. /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") },
  4913. /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") },
  4914. /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") },
  4915. /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") },
  4916. /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") },
  4917. /* Generic. */
  4918. /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") },
  4919. /* SPARC specific. */
  4920. /* 19 */ { STRING_COMMA_LEN ("ORDERED") },
  4921. /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") },
  4922. /* ARM specific. */
  4923. /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") },
  4924. /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") },
  4925. /* 23 */ { STRING_COMMA_LEN ("COMDEF") },
  4926. /* GNU specific. */
  4927. /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") },
  4928. };
  4929. if (do_section_details)
  4930. {
  4931. sprintf (buff, "[%*.*lx]: ",
  4932. field_size, field_size, (unsigned long) sh_flags);
  4933. p += field_size + 4;
  4934. }
  4935. while (sh_flags)
  4936. {
  4937. bfd_vma flag;
  4938. flag = sh_flags & - sh_flags;
  4939. sh_flags &= ~ flag;
  4940. if (do_section_details)
  4941. {
  4942. switch (flag)
  4943. {
  4944. case SHF_WRITE: sindex = 0; break;
  4945. case SHF_ALLOC: sindex = 1; break;
  4946. case SHF_EXECINSTR: sindex = 2; break;
  4947. case SHF_MERGE: sindex = 3; break;
  4948. case SHF_STRINGS: sindex = 4; break;
  4949. case SHF_INFO_LINK: sindex = 5; break;
  4950. case SHF_LINK_ORDER: sindex = 6; break;
  4951. case SHF_OS_NONCONFORMING: sindex = 7; break;
  4952. case SHF_GROUP: sindex = 8; break;
  4953. case SHF_TLS: sindex = 9; break;
  4954. case SHF_EXCLUDE: sindex = 18; break;
  4955. case SHF_COMPRESSED: sindex = 20; break;
  4956. case SHF_GNU_MBIND: sindex = 24; break;
  4957. default:
  4958. sindex = -1;
  4959. switch (elf_header.e_machine)
  4960. {
  4961. case EM_IA_64:
  4962. if (flag == SHF_IA_64_SHORT)
  4963. sindex = 10;
  4964. else if (flag == SHF_IA_64_NORECOV)
  4965. sindex = 11;
  4966. #ifdef BFD64
  4967. else if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
  4968. switch (flag)
  4969. {
  4970. case SHF_IA_64_VMS_GLOBAL: sindex = 12; break;
  4971. case SHF_IA_64_VMS_OVERLAID: sindex = 13; break;
  4972. case SHF_IA_64_VMS_SHARED: sindex = 14; break;
  4973. case SHF_IA_64_VMS_VECTOR: sindex = 15; break;
  4974. case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break;
  4975. case SHF_IA_64_VMS_PROTECTED: sindex = 17; break;
  4976. default: break;
  4977. }
  4978. #endif
  4979. break;
  4980. case EM_386:
  4981. case EM_IAMCU:
  4982. case EM_X86_64:
  4983. case EM_L1OM:
  4984. case EM_K1OM:
  4985. case EM_OLD_SPARCV9:
  4986. case EM_SPARC32PLUS:
  4987. case EM_SPARCV9:
  4988. case EM_SPARC:
  4989. if (flag == SHF_ORDERED)
  4990. sindex = 19;
  4991. break;
  4992. case EM_ARM:
  4993. switch (flag)
  4994. {
  4995. case SHF_ENTRYSECT: sindex = 21; break;
  4996. case SHF_ARM_PURECODE: sindex = 22; break;
  4997. case SHF_COMDEF: sindex = 23; break;
  4998. default: break;
  4999. }
  5000. break;
  5001. default:
  5002. break;
  5003. }
  5004. }
  5005. if (sindex != -1)
  5006. {
  5007. if (p != buff + field_size + 4)
  5008. {
  5009. if (size < (10 + 2))
  5010. {
  5011. warn (_("Internal error: not enough buffer room for section flag info"));
  5012. return _("<unknown>");
  5013. }
  5014. size -= 2;
  5015. *p++ = ',';
  5016. *p++ = ' ';
  5017. }
  5018. size -= flags [sindex].len;
  5019. p = stpcpy (p, flags [sindex].str);
  5020. }
  5021. else if (flag & SHF_MASKOS)
  5022. os_flags |= flag;
  5023. else if (flag & SHF_MASKPROC)
  5024. proc_flags |= flag;
  5025. else
  5026. unknown_flags |= flag;
  5027. }
  5028. else
  5029. {
  5030. switch (flag)
  5031. {
  5032. case SHF_WRITE: *p = 'W'; break;
  5033. case SHF_ALLOC: *p = 'A'; break;
  5034. case SHF_EXECINSTR: *p = 'X'; break;
  5035. case SHF_MERGE: *p = 'M'; break;
  5036. case SHF_STRINGS: *p = 'S'; break;
  5037. case SHF_INFO_LINK: *p = 'I'; break;
  5038. case SHF_LINK_ORDER: *p = 'L'; break;
  5039. case SHF_OS_NONCONFORMING: *p = 'O'; break;
  5040. case SHF_GROUP: *p = 'G'; break;
  5041. case SHF_TLS: *p = 'T'; break;
  5042. case SHF_EXCLUDE: *p = 'E'; break;
  5043. case SHF_COMPRESSED: *p = 'C'; break;
  5044. case SHF_GNU_MBIND: *p = 'D'; break;
  5045. default:
  5046. if ((elf_header.e_machine == EM_X86_64
  5047. || elf_header.e_machine == EM_L1OM
  5048. || elf_header.e_machine == EM_K1OM)
  5049. && flag == SHF_X86_64_LARGE)
  5050. *p = 'l';
  5051. else if (elf_header.e_machine == EM_ARM
  5052. && flag == SHF_ARM_PURECODE)
  5053. *p = 'y';
  5054. else if (flag & SHF_MASKOS)
  5055. {
  5056. *p = 'o';
  5057. sh_flags &= ~ SHF_MASKOS;
  5058. }
  5059. else if (flag & SHF_MASKPROC)
  5060. {
  5061. *p = 'p';
  5062. sh_flags &= ~ SHF_MASKPROC;
  5063. }
  5064. else
  5065. *p = 'x';
  5066. break;
  5067. }
  5068. p++;
  5069. }
  5070. }
  5071. if (do_section_details)
  5072. {
  5073. if (os_flags)
  5074. {
  5075. size -= 5 + field_size;
  5076. if (p != buff + field_size + 4)
  5077. {
  5078. if (size < (2 + 1))
  5079. {
  5080. warn (_("Internal error: not enough buffer room for section flag info"));
  5081. return _("<unknown>");
  5082. }
  5083. size -= 2;
  5084. *p++ = ',';
  5085. *p++ = ' ';
  5086. }
  5087. sprintf (p, "OS (%*.*lx)", field_size, field_size,
  5088. (unsigned long) os_flags);
  5089. p += 5 + field_size;
  5090. }
  5091. if (proc_flags)
  5092. {
  5093. size -= 7 + field_size;
  5094. if (p != buff + field_size + 4)
  5095. {
  5096. if (size < (2 + 1))
  5097. {
  5098. warn (_("Internal error: not enough buffer room for section flag info"));
  5099. return _("<unknown>");
  5100. }
  5101. size -= 2;
  5102. *p++ = ',';
  5103. *p++ = ' ';
  5104. }
  5105. sprintf (p, "PROC (%*.*lx)", field_size, field_size,
  5106. (unsigned long) proc_flags);
  5107. p += 7 + field_size;
  5108. }
  5109. if (unknown_flags)
  5110. {
  5111. size -= 10 + field_size;
  5112. if (p != buff + field_size + 4)
  5113. {
  5114. if (size < (2 + 1))
  5115. {
  5116. warn (_("Internal error: not enough buffer room for section flag info"));
  5117. return _("<unknown>");
  5118. }
  5119. size -= 2;
  5120. *p++ = ',';
  5121. *p++ = ' ';
  5122. }
  5123. sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size,
  5124. (unsigned long) unknown_flags);
  5125. p += 10 + field_size;
  5126. }
  5127. }
  5128. *p = '\0';
  5129. return buff;
  5130. }
  5131. static unsigned int
  5132. get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, bfd_size_type size)
  5133. {
  5134. if (is_32bit_elf)
  5135. {
  5136. Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf;
  5137. if (size < sizeof (* echdr))
  5138. {
  5139. error (_("Compressed section is too small even for a compression header\n"));
  5140. return 0;
  5141. }
  5142. chdr->ch_type = BYTE_GET (echdr->ch_type);
  5143. chdr->ch_size = BYTE_GET (echdr->ch_size);
  5144. chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
  5145. return sizeof (*echdr);
  5146. }
  5147. else
  5148. {
  5149. Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf;
  5150. if (size < sizeof (* echdr))
  5151. {
  5152. error (_("Compressed section is too small even for a compression header\n"));
  5153. return 0;
  5154. }
  5155. chdr->ch_type = BYTE_GET (echdr->ch_type);
  5156. chdr->ch_size = BYTE_GET (echdr->ch_size);
  5157. chdr->ch_addralign = BYTE_GET (echdr->ch_addralign);
  5158. return sizeof (*echdr);
  5159. }
  5160. }
  5161. static bfd_boolean
  5162. process_section_headers (FILE * file)
  5163. {
  5164. Elf_Internal_Shdr * section;
  5165. unsigned int i;
  5166. section_headers = NULL;
  5167. if (elf_header.e_shnum == 0)
  5168. {
  5169. /* PR binutils/12467. */
  5170. if (elf_header.e_shoff != 0)
  5171. {
  5172. warn (_("possibly corrupt ELF file header - it has a non-zero"
  5173. " section header offset, but no section headers\n"));
  5174. return FALSE;
  5175. }
  5176. else if (do_sections)
  5177. printf (_("\nThere are no sections in this file.\n"));
  5178. return TRUE;
  5179. }
  5180. if (do_sections && !do_header)
  5181. printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
  5182. elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
  5183. if (is_32bit_elf)
  5184. {
  5185. if (! get_32bit_section_headers (file, FALSE))
  5186. return FALSE;
  5187. }
  5188. else
  5189. {
  5190. if (! get_64bit_section_headers (file, FALSE))
  5191. return FALSE;
  5192. }
  5193. /* Read in the string table, so that we have names to display. */
  5194. if (elf_header.e_shstrndx != SHN_UNDEF
  5195. && elf_header.e_shstrndx < elf_header.e_shnum)
  5196. {
  5197. section = section_headers + elf_header.e_shstrndx;
  5198. if (section->sh_size != 0)
  5199. {
  5200. string_table = (char *) get_data (NULL, file, section->sh_offset,
  5201. 1, section->sh_size,
  5202. _("string table"));
  5203. string_table_length = string_table != NULL ? section->sh_size : 0;
  5204. }
  5205. }
  5206. /* Scan the sections for the dynamic symbol table
  5207. and dynamic string table and debug sections. */
  5208. dynamic_symbols = NULL;
  5209. dynamic_strings = NULL;
  5210. dynamic_syminfo = NULL;
  5211. symtab_shndx_list = NULL;
  5212. eh_addr_size = is_32bit_elf ? 4 : 8;
  5213. switch (elf_header.e_machine)
  5214. {
  5215. case EM_MIPS:
  5216. case EM_MIPS_RS3_LE:
  5217. /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
  5218. FDE addresses. However, the ABI also has a semi-official ILP32
  5219. variant for which the normal FDE address size rules apply.
  5220. GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
  5221. section, where XX is the size of longs in bits. Unfortunately,
  5222. earlier compilers provided no way of distinguishing ILP32 objects
  5223. from LP64 objects, so if there's any doubt, we should assume that
  5224. the official LP64 form is being used. */
  5225. if ((elf_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
  5226. && find_section (".gcc_compiled_long32") == NULL)
  5227. eh_addr_size = 8;
  5228. break;
  5229. case EM_H8_300:
  5230. case EM_H8_300H:
  5231. switch (elf_header.e_flags & EF_H8_MACH)
  5232. {
  5233. case E_H8_MACH_H8300:
  5234. case E_H8_MACH_H8300HN:
  5235. case E_H8_MACH_H8300SN:
  5236. case E_H8_MACH_H8300SXN:
  5237. eh_addr_size = 2;
  5238. break;
  5239. case E_H8_MACH_H8300H:
  5240. case E_H8_MACH_H8300S:
  5241. case E_H8_MACH_H8300SX:
  5242. eh_addr_size = 4;
  5243. break;
  5244. }
  5245. break;
  5246. case EM_M32C_OLD:
  5247. case EM_M32C:
  5248. switch (elf_header.e_flags & EF_M32C_CPU_MASK)
  5249. {
  5250. case EF_M32C_CPU_M16C:
  5251. eh_addr_size = 2;
  5252. break;
  5253. }
  5254. break;
  5255. }
  5256. #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
  5257. do \
  5258. { \
  5259. bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
  5260. if (section->sh_entsize != expected_entsize) \
  5261. { \
  5262. char buf[40]; \
  5263. sprintf_vma (buf, section->sh_entsize); \
  5264. /* Note: coded this way so that there is a single string for \
  5265. translation. */ \
  5266. error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
  5267. error (_("(Using the expected size of %u for the rest of this dump)\n"), \
  5268. (unsigned) expected_entsize); \
  5269. section->sh_entsize = expected_entsize; \
  5270. } \
  5271. } \
  5272. while (0)
  5273. #define CHECK_ENTSIZE(section, i, type) \
  5274. CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
  5275. sizeof (Elf64_External_##type))
  5276. for (i = 0, section = section_headers;
  5277. i < elf_header.e_shnum;
  5278. i++, section++)
  5279. {
  5280. char * name = SECTION_NAME (section);
  5281. if (section->sh_type == SHT_DYNSYM)
  5282. {
  5283. if (dynamic_symbols != NULL)
  5284. {
  5285. error (_("File contains multiple dynamic symbol tables\n"));
  5286. continue;
  5287. }
  5288. CHECK_ENTSIZE (section, i, Sym);
  5289. dynamic_symbols = GET_ELF_SYMBOLS (file, section, & num_dynamic_syms);
  5290. }
  5291. else if (section->sh_type == SHT_STRTAB
  5292. && streq (name, ".dynstr"))
  5293. {
  5294. if (dynamic_strings != NULL)
  5295. {
  5296. error (_("File contains multiple dynamic string tables\n"));
  5297. continue;
  5298. }
  5299. dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
  5300. 1, section->sh_size,
  5301. _("dynamic strings"));
  5302. dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size;
  5303. }
  5304. else if (section->sh_type == SHT_SYMTAB_SHNDX)
  5305. {
  5306. elf_section_list * entry = xmalloc (sizeof * entry);
  5307. entry->hdr = section;
  5308. entry->next = symtab_shndx_list;
  5309. symtab_shndx_list = entry;
  5310. }
  5311. else if (section->sh_type == SHT_SYMTAB)
  5312. CHECK_ENTSIZE (section, i, Sym);
  5313. else if (section->sh_type == SHT_GROUP)
  5314. CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
  5315. else if (section->sh_type == SHT_REL)
  5316. CHECK_ENTSIZE (section, i, Rel);
  5317. else if (section->sh_type == SHT_RELA)
  5318. CHECK_ENTSIZE (section, i, Rela);
  5319. else if ((do_debugging || do_debug_info || do_debug_abbrevs
  5320. || do_debug_lines || do_debug_pubnames || do_debug_pubtypes
  5321. || do_debug_aranges || do_debug_frames || do_debug_macinfo
  5322. || do_debug_str || do_debug_loc || do_debug_ranges
  5323. || do_debug_addr || do_debug_cu_index)
  5324. && (const_strneq (name, ".debug_")
  5325. || const_strneq (name, ".zdebug_")))
  5326. {
  5327. if (name[1] == 'z')
  5328. name += sizeof (".zdebug_") - 1;
  5329. else
  5330. name += sizeof (".debug_") - 1;
  5331. if (do_debugging
  5332. || (do_debug_info && const_strneq (name, "info"))
  5333. || (do_debug_info && const_strneq (name, "types"))
  5334. || (do_debug_abbrevs && const_strneq (name, "abbrev"))
  5335. || (do_debug_lines && strcmp (name, "line") == 0)
  5336. || (do_debug_lines && const_strneq (name, "line."))
  5337. || (do_debug_pubnames && const_strneq (name, "pubnames"))
  5338. || (do_debug_pubtypes && const_strneq (name, "pubtypes"))
  5339. || (do_debug_pubnames && const_strneq (name, "gnu_pubnames"))
  5340. || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes"))
  5341. || (do_debug_aranges && const_strneq (name, "aranges"))
  5342. || (do_debug_ranges && const_strneq (name, "ranges"))
  5343. || (do_debug_ranges && const_strneq (name, "rnglists"))
  5344. || (do_debug_frames && const_strneq (name, "frame"))
  5345. || (do_debug_macinfo && const_strneq (name, "macinfo"))
  5346. || (do_debug_macinfo && const_strneq (name, "macro"))
  5347. || (do_debug_str && const_strneq (name, "str"))
  5348. || (do_debug_loc && const_strneq (name, "loc"))
  5349. || (do_debug_loc && const_strneq (name, "loclists"))
  5350. || (do_debug_addr && const_strneq (name, "addr"))
  5351. || (do_debug_cu_index && const_strneq (name, "cu_index"))
  5352. || (do_debug_cu_index && const_strneq (name, "tu_index"))
  5353. )
  5354. request_dump_bynumber (i, DEBUG_DUMP);
  5355. }
  5356. /* Linkonce section to be combined with .debug_info at link time. */
  5357. else if ((do_debugging || do_debug_info)
  5358. && const_strneq (name, ".gnu.linkonce.wi."))
  5359. request_dump_bynumber (i, DEBUG_DUMP);
  5360. else if (do_debug_frames && streq (name, ".eh_frame"))
  5361. request_dump_bynumber (i, DEBUG_DUMP);
  5362. else if (do_gdb_index && (streq (name, ".gdb_index")
  5363. || streq (name, ".debug_names")))
  5364. request_dump_bynumber (i, DEBUG_DUMP);
  5365. /* Trace sections for Itanium VMS. */
  5366. else if ((do_debugging || do_trace_info || do_trace_abbrevs
  5367. || do_trace_aranges)
  5368. && const_strneq (name, ".trace_"))
  5369. {
  5370. name += sizeof (".trace_") - 1;
  5371. if (do_debugging
  5372. || (do_trace_info && streq (name, "info"))
  5373. || (do_trace_abbrevs && streq (name, "abbrev"))
  5374. || (do_trace_aranges && streq (name, "aranges"))
  5375. )
  5376. request_dump_bynumber (i, DEBUG_DUMP);
  5377. }
  5378. }
  5379. if (! do_sections)
  5380. return TRUE;
  5381. if (elf_header.e_shnum > 1)
  5382. printf (_("\nSection Headers:\n"));
  5383. else
  5384. printf (_("\nSection Header:\n"));
  5385. if (is_32bit_elf)
  5386. {
  5387. if (do_section_details)
  5388. {
  5389. printf (_(" [Nr] Name\n"));
  5390. printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
  5391. }
  5392. else
  5393. printf
  5394. (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
  5395. }
  5396. else if (do_wide)
  5397. {
  5398. if (do_section_details)
  5399. {
  5400. printf (_(" [Nr] Name\n"));
  5401. printf (_(" Type Address Off Size ES Lk Inf Al\n"));
  5402. }
  5403. else
  5404. printf
  5405. (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
  5406. }
  5407. else
  5408. {
  5409. if (do_section_details)
  5410. {
  5411. printf (_(" [Nr] Name\n"));
  5412. printf (_(" Type Address Offset Link\n"));
  5413. printf (_(" Size EntSize Info Align\n"));
  5414. }
  5415. else
  5416. {
  5417. printf (_(" [Nr] Name Type Address Offset\n"));
  5418. printf (_(" Size EntSize Flags Link Info Align\n"));
  5419. }
  5420. }
  5421. if (do_section_details)
  5422. printf (_(" Flags\n"));
  5423. for (i = 0, section = section_headers;
  5424. i < elf_header.e_shnum;
  5425. i++, section++)
  5426. {
  5427. /* Run some sanity checks on the section header. */
  5428. /* Check the sh_link field. */
  5429. switch (section->sh_type)
  5430. {
  5431. case SHT_SYMTAB_SHNDX:
  5432. case SHT_GROUP:
  5433. case SHT_HASH:
  5434. case SHT_GNU_HASH:
  5435. case SHT_GNU_versym:
  5436. case SHT_REL:
  5437. case SHT_RELA:
  5438. if (section->sh_link < 1
  5439. || section->sh_link >= elf_header.e_shnum
  5440. || (section_headers[section->sh_link].sh_type != SHT_SYMTAB
  5441. && section_headers[section->sh_link].sh_type != SHT_DYNSYM))
  5442. warn (_("[%2u]: Link field (%u) should index a symtab section.\n"),
  5443. i, section->sh_link);
  5444. break;
  5445. case SHT_DYNAMIC:
  5446. case SHT_SYMTAB:
  5447. case SHT_DYNSYM:
  5448. case SHT_GNU_verneed:
  5449. case SHT_GNU_verdef:
  5450. case SHT_GNU_LIBLIST:
  5451. if (section->sh_link < 1
  5452. || section->sh_link >= elf_header.e_shnum
  5453. || section_headers[section->sh_link].sh_type != SHT_STRTAB)
  5454. warn (_("[%2u]: Link field (%u) should index a string section.\n"),
  5455. i, section->sh_link);
  5456. break;
  5457. case SHT_INIT_ARRAY:
  5458. case SHT_FINI_ARRAY:
  5459. case SHT_PREINIT_ARRAY:
  5460. if (section->sh_type < SHT_LOOS && section->sh_link != 0)
  5461. warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
  5462. i, section->sh_link);
  5463. break;
  5464. default:
  5465. /* FIXME: Add support for target specific section types. */
  5466. #if 0 /* Currently we do not check other section types as there are too
  5467. many special cases. Stab sections for example have a type
  5468. of SHT_PROGBITS but an sh_link field that links to the .stabstr
  5469. section. */
  5470. if (section->sh_type < SHT_LOOS && section->sh_link != 0)
  5471. warn (_("[%2u]: Unexpected value (%u) in link field.\n"),
  5472. i, section->sh_link);
  5473. #endif
  5474. break;
  5475. }
  5476. /* Check the sh_info field. */
  5477. switch (section->sh_type)
  5478. {
  5479. case SHT_REL:
  5480. case SHT_RELA:
  5481. if (section->sh_info < 1
  5482. || section->sh_info >= elf_header.e_shnum
  5483. || (section_headers[section->sh_info].sh_type != SHT_PROGBITS
  5484. && section_headers[section->sh_info].sh_type != SHT_NOBITS
  5485. && section_headers[section->sh_info].sh_type != SHT_NOTE
  5486. && section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY
  5487. /* FIXME: Are other section types valid ? */
  5488. && section_headers[section->sh_info].sh_type < SHT_LOOS))
  5489. {
  5490. if (section->sh_info == 0
  5491. && (streq (SECTION_NAME (section), ".rel.dyn")
  5492. || streq (SECTION_NAME (section), ".rela.dyn")))
  5493. /* The .rel.dyn and .rela.dyn sections have an sh_info field
  5494. of zero. The relocations in these sections may apply
  5495. to many different sections. */
  5496. ;
  5497. else
  5498. warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"),
  5499. i, section->sh_info);
  5500. }
  5501. break;
  5502. case SHT_DYNAMIC:
  5503. case SHT_HASH:
  5504. case SHT_SYMTAB_SHNDX:
  5505. case SHT_INIT_ARRAY:
  5506. case SHT_FINI_ARRAY:
  5507. case SHT_PREINIT_ARRAY:
  5508. if (section->sh_info != 0)
  5509. warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
  5510. i, section->sh_info);
  5511. break;
  5512. case SHT_GROUP:
  5513. case SHT_SYMTAB:
  5514. case SHT_DYNSYM:
  5515. /* A symbol index - we assume that it is valid. */
  5516. break;
  5517. default:
  5518. /* FIXME: Add support for target specific section types. */
  5519. if (section->sh_type == SHT_NOBITS)
  5520. /* NOBITS section headers with non-zero sh_info fields can be
  5521. created when a binary is stripped of everything but its debug
  5522. information. The stripped sections have their headers
  5523. preserved but their types set to SHT_NOBITS. So do not check
  5524. this type of section. */
  5525. ;
  5526. else if (section->sh_flags & SHF_INFO_LINK)
  5527. {
  5528. if (section->sh_info < 1 || section->sh_info >= elf_header.e_shnum)
  5529. warn (_("[%2u]: Expected link to another section in info field"), i);
  5530. }
  5531. else if (section->sh_type < SHT_LOOS
  5532. && (section->sh_flags & SHF_GNU_MBIND) == 0
  5533. && section->sh_info != 0)
  5534. warn (_("[%2u]: Unexpected value (%u) in info field.\n"),
  5535. i, section->sh_info);
  5536. break;
  5537. }
  5538. /* Check the sh_size field. */
  5539. if (section->sh_size > current_file_size
  5540. && section->sh_type != SHT_NOBITS
  5541. && section->sh_type != SHT_NULL
  5542. && section->sh_type < SHT_LOOS)
  5543. warn (_("Size of section %u is larger than the entire file!\n"), i);
  5544. printf (" [%2u] ", i);
  5545. if (do_section_details)
  5546. printf ("%s\n ", printable_section_name (section));
  5547. else
  5548. print_symbol (-17, SECTION_NAME (section));
  5549. printf (do_wide ? " %-15s " : " %-15.15s ",
  5550. get_section_type_name (section->sh_type));
  5551. if (is_32bit_elf)
  5552. {
  5553. const char * link_too_big = NULL;
  5554. print_vma (section->sh_addr, LONG_HEX);
  5555. printf ( " %6.6lx %6.6lx %2.2lx",
  5556. (unsigned long) section->sh_offset,
  5557. (unsigned long) section->sh_size,
  5558. (unsigned long) section->sh_entsize);
  5559. if (do_section_details)
  5560. fputs (" ", stdout);
  5561. else
  5562. printf (" %3s ", get_elf_section_flags (section->sh_flags));
  5563. if (section->sh_link >= elf_header.e_shnum)
  5564. {
  5565. link_too_big = "";
  5566. /* The sh_link value is out of range. Normally this indicates
  5567. an error but it can have special values in Solaris binaries. */
  5568. switch (elf_header.e_machine)
  5569. {
  5570. case EM_386:
  5571. case EM_IAMCU:
  5572. case EM_X86_64:
  5573. case EM_L1OM:
  5574. case EM_K1OM:
  5575. case EM_OLD_SPARCV9:
  5576. case EM_SPARC32PLUS:
  5577. case EM_SPARCV9:
  5578. case EM_SPARC:
  5579. if (section->sh_link == (SHN_BEFORE & 0xffff))
  5580. link_too_big = "BEFORE";
  5581. else if (section->sh_link == (SHN_AFTER & 0xffff))
  5582. link_too_big = "AFTER";
  5583. break;
  5584. default:
  5585. break;
  5586. }
  5587. }
  5588. if (do_section_details)
  5589. {
  5590. if (link_too_big != NULL && * link_too_big)
  5591. printf ("<%s> ", link_too_big);
  5592. else
  5593. printf ("%2u ", section->sh_link);
  5594. printf ("%3u %2lu\n", section->sh_info,
  5595. (unsigned long) section->sh_addralign);
  5596. }
  5597. else
  5598. printf ("%2u %3u %2lu\n",
  5599. section->sh_link,
  5600. section->sh_info,
  5601. (unsigned long) section->sh_addralign);
  5602. if (link_too_big && ! * link_too_big)
  5603. warn (_("section %u: sh_link value of %u is larger than the number of sections\n"),
  5604. i, section->sh_link);
  5605. }
  5606. else if (do_wide)
  5607. {
  5608. print_vma (section->sh_addr, LONG_HEX);
  5609. if ((long) section->sh_offset == section->sh_offset)
  5610. printf (" %6.6lx", (unsigned long) section->sh_offset);
  5611. else
  5612. {
  5613. putchar (' ');
  5614. print_vma (section->sh_offset, LONG_HEX);
  5615. }
  5616. if ((unsigned long) section->sh_size == section->sh_size)
  5617. printf (" %6.6lx", (unsigned long) section->sh_size);
  5618. else
  5619. {
  5620. putchar (' ');
  5621. print_vma (section->sh_size, LONG_HEX);
  5622. }
  5623. if ((unsigned long) section->sh_entsize == section->sh_entsize)
  5624. printf (" %2.2lx", (unsigned long) section->sh_entsize);
  5625. else
  5626. {
  5627. putchar (' ');
  5628. print_vma (section->sh_entsize, LONG_HEX);
  5629. }
  5630. if (do_section_details)
  5631. fputs (" ", stdout);
  5632. else
  5633. printf (" %3s ", get_elf_section_flags (section->sh_flags));
  5634. printf ("%2u %3u ", section->sh_link, section->sh_info);
  5635. if ((unsigned long) section->sh_addralign == section->sh_addralign)
  5636. printf ("%2lu\n", (unsigned long) section->sh_addralign);
  5637. else
  5638. {
  5639. print_vma (section->sh_addralign, DEC);
  5640. putchar ('\n');
  5641. }
  5642. }
  5643. else if (do_section_details)
  5644. {
  5645. printf (" %-15.15s ",
  5646. get_section_type_name (section->sh_type));
  5647. print_vma (section->sh_addr, LONG_HEX);
  5648. if ((long) section->sh_offset == section->sh_offset)
  5649. printf (" %16.16lx", (unsigned long) section->sh_offset);
  5650. else
  5651. {
  5652. printf (" ");
  5653. print_vma (section->sh_offset, LONG_HEX);
  5654. }
  5655. printf (" %u\n ", section->sh_link);
  5656. print_vma (section->sh_size, LONG_HEX);
  5657. putchar (' ');
  5658. print_vma (section->sh_entsize, LONG_HEX);
  5659. printf (" %-16u %lu\n",
  5660. section->sh_info,
  5661. (unsigned long) section->sh_addralign);
  5662. }
  5663. else
  5664. {
  5665. putchar (' ');
  5666. print_vma (section->sh_addr, LONG_HEX);
  5667. if ((long) section->sh_offset == section->sh_offset)
  5668. printf (" %8.8lx", (unsigned long) section->sh_offset);
  5669. else
  5670. {
  5671. printf (" ");
  5672. print_vma (section->sh_offset, LONG_HEX);
  5673. }
  5674. printf ("\n ");
  5675. print_vma (section->sh_size, LONG_HEX);
  5676. printf (" ");
  5677. print_vma (section->sh_entsize, LONG_HEX);
  5678. printf (" %3s ", get_elf_section_flags (section->sh_flags));
  5679. printf (" %2u %3u %lu\n",
  5680. section->sh_link,
  5681. section->sh_info,
  5682. (unsigned long) section->sh_addralign);
  5683. }
  5684. if (do_section_details)
  5685. {
  5686. printf (" %s\n", get_elf_section_flags (section->sh_flags));
  5687. if ((section->sh_flags & SHF_COMPRESSED) != 0)
  5688. {
  5689. /* Minimum section size is 12 bytes for 32-bit compression
  5690. header + 12 bytes for compressed data header. */
  5691. unsigned char buf[24];
  5692. assert (sizeof (buf) >= sizeof (Elf64_External_Chdr));
  5693. if (get_data (&buf, (FILE *) file, section->sh_offset, 1,
  5694. sizeof (buf), _("compression header")))
  5695. {
  5696. Elf_Internal_Chdr chdr;
  5697. (void) get_compression_header (&chdr, buf, sizeof (buf));
  5698. if (chdr.ch_type == ELFCOMPRESS_ZLIB)
  5699. printf (" ZLIB, ");
  5700. else
  5701. printf (_(" [<unknown>: 0x%x], "),
  5702. chdr.ch_type);
  5703. print_vma (chdr.ch_size, LONG_HEX);
  5704. printf (", %lu\n", (unsigned long) chdr.ch_addralign);
  5705. }
  5706. }
  5707. }
  5708. }
  5709. if (!do_section_details)
  5710. {
  5711. /* The ordering of the letters shown here matches the ordering of the
  5712. corresponding SHF_xxx values, and hence the order in which these
  5713. letters will be displayed to the user. */
  5714. printf (_("Key to Flags:\n\
  5715. W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\
  5716. L (link order), O (extra OS processing required), G (group), T (TLS),\n\
  5717. C (compressed), x (unknown), o (OS specific), E (exclude),\n "));
  5718. if (elf_header.e_machine == EM_X86_64
  5719. || elf_header.e_machine == EM_L1OM
  5720. || elf_header.e_machine == EM_K1OM)
  5721. printf (_("l (large), "));
  5722. else if (elf_header.e_machine == EM_ARM)
  5723. printf (_("y (purecode), "));
  5724. printf ("p (processor specific)\n");
  5725. }
  5726. return TRUE;
  5727. }
  5728. static const char *
  5729. get_group_flags (unsigned int flags)
  5730. {
  5731. static char buff[128];
  5732. if (flags == 0)
  5733. return "";
  5734. else if (flags == GRP_COMDAT)
  5735. return "COMDAT ";
  5736. snprintf (buff, 14, _("[0x%x: "), flags);
  5737. flags &= ~ GRP_COMDAT;
  5738. if (flags & GRP_MASKOS)
  5739. {
  5740. strcat (buff, "<OS specific>");
  5741. flags &= ~ GRP_MASKOS;
  5742. }
  5743. if (flags & GRP_MASKPROC)
  5744. {
  5745. strcat (buff, "<PROC specific>");
  5746. flags &= ~ GRP_MASKPROC;
  5747. }
  5748. if (flags)
  5749. strcat (buff, "<unknown>");
  5750. strcat (buff, "]");
  5751. return buff;
  5752. }
  5753. static bfd_boolean
  5754. process_section_groups (FILE * file)
  5755. {
  5756. Elf_Internal_Shdr * section;
  5757. unsigned int i;
  5758. struct group * group;
  5759. Elf_Internal_Shdr * symtab_sec;
  5760. Elf_Internal_Shdr * strtab_sec;
  5761. Elf_Internal_Sym * symtab;
  5762. unsigned long num_syms;
  5763. char * strtab;
  5764. size_t strtab_size;
  5765. /* Don't process section groups unless needed. */
  5766. if (!do_unwind && !do_section_groups)
  5767. return TRUE;
  5768. if (elf_header.e_shnum == 0)
  5769. {
  5770. if (do_section_groups)
  5771. printf (_("\nThere are no sections to group in this file.\n"));
  5772. return TRUE;
  5773. }
  5774. if (section_headers == NULL)
  5775. {
  5776. error (_("Section headers are not available!\n"));
  5777. /* PR 13622: This can happen with a corrupt ELF header. */
  5778. return FALSE;
  5779. }
  5780. section_headers_groups = (struct group **) calloc (elf_header.e_shnum,
  5781. sizeof (struct group *));
  5782. if (section_headers_groups == NULL)
  5783. {
  5784. error (_("Out of memory reading %u section group headers\n"),
  5785. elf_header.e_shnum);
  5786. return FALSE;
  5787. }
  5788. /* Scan the sections for the group section. */
  5789. group_count = 0;
  5790. for (i = 0, section = section_headers;
  5791. i < elf_header.e_shnum;
  5792. i++, section++)
  5793. if (section->sh_type == SHT_GROUP)
  5794. group_count++;
  5795. if (group_count == 0)
  5796. {
  5797. if (do_section_groups)
  5798. printf (_("\nThere are no section groups in this file.\n"));
  5799. return TRUE;
  5800. }
  5801. section_groups = (struct group *) calloc (group_count, sizeof (struct group));
  5802. if (section_groups == NULL)
  5803. {
  5804. error (_("Out of memory reading %lu groups\n"),
  5805. (unsigned long) group_count);
  5806. return FALSE;
  5807. }
  5808. symtab_sec = NULL;
  5809. strtab_sec = NULL;
  5810. symtab = NULL;
  5811. num_syms = 0;
  5812. strtab = NULL;
  5813. strtab_size = 0;
  5814. for (i = 0, section = section_headers, group = section_groups;
  5815. i < elf_header.e_shnum;
  5816. i++, section++)
  5817. {
  5818. if (section->sh_type == SHT_GROUP)
  5819. {
  5820. const char * name = printable_section_name (section);
  5821. const char * group_name;
  5822. unsigned char * start;
  5823. unsigned char * indices;
  5824. unsigned int entry, j, size;
  5825. Elf_Internal_Shdr * sec;
  5826. Elf_Internal_Sym * sym;
  5827. /* Get the symbol table. */
  5828. if (section->sh_link >= elf_header.e_shnum
  5829. || ((sec = section_headers + section->sh_link)->sh_type
  5830. != SHT_SYMTAB))
  5831. {
  5832. error (_("Bad sh_link in group section `%s'\n"), name);
  5833. continue;
  5834. }
  5835. if (symtab_sec != sec)
  5836. {
  5837. symtab_sec = sec;
  5838. if (symtab)
  5839. free (symtab);
  5840. symtab = GET_ELF_SYMBOLS (file, symtab_sec, & num_syms);
  5841. }
  5842. if (symtab == NULL)
  5843. {
  5844. error (_("Corrupt header in group section `%s'\n"), name);
  5845. continue;
  5846. }
  5847. if (section->sh_info >= num_syms)
  5848. {
  5849. error (_("Bad sh_info in group section `%s'\n"), name);
  5850. continue;
  5851. }
  5852. sym = symtab + section->sh_info;
  5853. if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
  5854. {
  5855. if (sym->st_shndx == 0
  5856. || sym->st_shndx >= elf_header.e_shnum)
  5857. {
  5858. error (_("Bad sh_info in group section `%s'\n"), name);
  5859. continue;
  5860. }
  5861. group_name = SECTION_NAME (section_headers + sym->st_shndx);
  5862. strtab_sec = NULL;
  5863. if (strtab)
  5864. free (strtab);
  5865. strtab = NULL;
  5866. strtab_size = 0;
  5867. }
  5868. else
  5869. {
  5870. /* Get the string table. */
  5871. if (symtab_sec->sh_link >= elf_header.e_shnum)
  5872. {
  5873. strtab_sec = NULL;
  5874. if (strtab)
  5875. free (strtab);
  5876. strtab = NULL;
  5877. strtab_size = 0;
  5878. }
  5879. else if (strtab_sec
  5880. != (sec = section_headers + symtab_sec->sh_link))
  5881. {
  5882. strtab_sec = sec;
  5883. if (strtab)
  5884. free (strtab);
  5885. strtab = (char *) get_data (NULL, file, strtab_sec->sh_offset,
  5886. 1, strtab_sec->sh_size,
  5887. _("string table"));
  5888. strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
  5889. }
  5890. group_name = sym->st_name < strtab_size
  5891. ? strtab + sym->st_name : _("<corrupt>");
  5892. }
  5893. /* PR 17531: file: loop. */
  5894. if (section->sh_entsize > section->sh_size)
  5895. {
  5896. error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"),
  5897. printable_section_name (section),
  5898. (unsigned long) section->sh_entsize,
  5899. (unsigned long) section->sh_size);
  5900. break;
  5901. }
  5902. start = (unsigned char *) get_data (NULL, file, section->sh_offset,
  5903. 1, section->sh_size,
  5904. _("section data"));
  5905. if (start == NULL)
  5906. continue;
  5907. indices = start;
  5908. size = (section->sh_size / section->sh_entsize) - 1;
  5909. entry = byte_get (indices, 4);
  5910. indices += 4;
  5911. if (do_section_groups)
  5912. {
  5913. printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"),
  5914. get_group_flags (entry), i, name, group_name, size);
  5915. printf (_(" [Index] Name\n"));
  5916. }
  5917. group->group_index = i;
  5918. for (j = 0; j < size; j++)
  5919. {
  5920. struct group_list * g;
  5921. entry = byte_get (indices, 4);
  5922. indices += 4;
  5923. if (entry >= elf_header.e_shnum)
  5924. {
  5925. static unsigned num_group_errors = 0;
  5926. if (num_group_errors ++ < 10)
  5927. {
  5928. error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
  5929. entry, i, elf_header.e_shnum - 1);
  5930. if (num_group_errors == 10)
  5931. warn (_("Futher error messages about overlarge group section indicies suppressed\n"));
  5932. }
  5933. continue;
  5934. }
  5935. if (section_headers_groups [entry] != NULL)
  5936. {
  5937. if (entry)
  5938. {
  5939. static unsigned num_errs = 0;
  5940. if (num_errs ++ < 10)
  5941. {
  5942. error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
  5943. entry, i,
  5944. section_headers_groups [entry]->group_index);
  5945. if (num_errs == 10)
  5946. warn (_("Further error messages about already contained group sections suppressed\n"));
  5947. }
  5948. continue;
  5949. }
  5950. else
  5951. {
  5952. /* Intel C/C++ compiler may put section 0 in a
  5953. section group. We just warn it the first time
  5954. and ignore it afterwards. */
  5955. static bfd_boolean warned = FALSE;
  5956. if (!warned)
  5957. {
  5958. error (_("section 0 in group section [%5u]\n"),
  5959. section_headers_groups [entry]->group_index);
  5960. warned = TRUE;
  5961. }
  5962. }
  5963. }
  5964. section_headers_groups [entry] = group;
  5965. if (do_section_groups)
  5966. {
  5967. sec = section_headers + entry;
  5968. printf (" [%5u] %s\n", entry, printable_section_name (sec));
  5969. }
  5970. g = (struct group_list *) xmalloc (sizeof (struct group_list));
  5971. g->section_index = entry;
  5972. g->next = group->root;
  5973. group->root = g;
  5974. }
  5975. if (start)
  5976. free (start);
  5977. group++;
  5978. }
  5979. }
  5980. if (symtab)
  5981. free (symtab);
  5982. if (strtab)
  5983. free (strtab);
  5984. return TRUE;
  5985. }
  5986. /* Data used to display dynamic fixups. */
  5987. struct ia64_vms_dynfixup
  5988. {
  5989. bfd_vma needed_ident; /* Library ident number. */
  5990. bfd_vma needed; /* Index in the dstrtab of the library name. */
  5991. bfd_vma fixup_needed; /* Index of the library. */
  5992. bfd_vma fixup_rela_cnt; /* Number of fixups. */
  5993. bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */
  5994. };
  5995. /* Data used to display dynamic relocations. */
  5996. struct ia64_vms_dynimgrela
  5997. {
  5998. bfd_vma img_rela_cnt; /* Number of relocations. */
  5999. bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */
  6000. };
  6001. /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared
  6002. library). */
  6003. static bfd_boolean
  6004. dump_ia64_vms_dynamic_fixups (FILE * file,
  6005. struct ia64_vms_dynfixup * fixup,
  6006. const char * strtab,
  6007. unsigned int strtab_sz)
  6008. {
  6009. Elf64_External_VMS_IMAGE_FIXUP * imfs;
  6010. long i;
  6011. const char * lib_name;
  6012. imfs = get_data (NULL, file, dynamic_addr + fixup->fixup_rela_off,
  6013. 1, fixup->fixup_rela_cnt * sizeof (*imfs),
  6014. _("dynamic section image fixups"));
  6015. if (!imfs)
  6016. return FALSE;
  6017. if (fixup->needed < strtab_sz)
  6018. lib_name = strtab + fixup->needed;
  6019. else
  6020. {
  6021. warn (_("corrupt library name index of 0x%lx found in dynamic entry"),
  6022. (unsigned long) fixup->needed);
  6023. lib_name = "???";
  6024. }
  6025. printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"),
  6026. (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident);
  6027. printf
  6028. (_("Seg Offset Type SymVec DataType\n"));
  6029. for (i = 0; i < (long) fixup->fixup_rela_cnt; i++)
  6030. {
  6031. unsigned int type;
  6032. const char *rtype;
  6033. printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
  6034. printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
  6035. type = BYTE_GET (imfs [i].type);
  6036. rtype = elf_ia64_reloc_type (type);
  6037. if (rtype == NULL)
  6038. printf (" 0x%08x ", type);
  6039. else
  6040. printf (" %-32s ", rtype);
  6041. printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
  6042. printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
  6043. }
  6044. free (imfs);
  6045. return TRUE;
  6046. }
  6047. /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */
  6048. static bfd_boolean
  6049. dump_ia64_vms_dynamic_relocs (FILE *file, struct ia64_vms_dynimgrela *imgrela)
  6050. {
  6051. Elf64_External_VMS_IMAGE_RELA *imrs;
  6052. long i;
  6053. imrs = get_data (NULL, file, dynamic_addr + imgrela->img_rela_off,
  6054. 1, imgrela->img_rela_cnt * sizeof (*imrs),
  6055. _("dynamic section image relocations"));
  6056. if (!imrs)
  6057. return FALSE;
  6058. printf (_("\nImage relocs\n"));
  6059. printf
  6060. (_("Seg Offset Type Addend Seg Sym Off\n"));
  6061. for (i = 0; i < (long) imgrela->img_rela_cnt; i++)
  6062. {
  6063. unsigned int type;
  6064. const char *rtype;
  6065. printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg));
  6066. printf ("%08" BFD_VMA_FMT "x ",
  6067. (bfd_vma) BYTE_GET (imrs [i].rela_offset));
  6068. type = BYTE_GET (imrs [i].type);
  6069. rtype = elf_ia64_reloc_type (type);
  6070. if (rtype == NULL)
  6071. printf ("0x%08x ", type);
  6072. else
  6073. printf ("%-31s ", rtype);
  6074. print_vma (BYTE_GET (imrs [i].addend), FULL_HEX);
  6075. printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg));
  6076. printf ("%08" BFD_VMA_FMT "x\n",
  6077. (bfd_vma) BYTE_GET (imrs [i].sym_offset));
  6078. }
  6079. free (imrs);
  6080. return TRUE;
  6081. }
  6082. /* Display IA-64 OpenVMS dynamic relocations and fixups. */
  6083. static bfd_boolean
  6084. process_ia64_vms_dynamic_relocs (FILE *file)
  6085. {
  6086. struct ia64_vms_dynfixup fixup;
  6087. struct ia64_vms_dynimgrela imgrela;
  6088. Elf_Internal_Dyn *entry;
  6089. bfd_vma strtab_off = 0;
  6090. bfd_vma strtab_sz = 0;
  6091. char *strtab = NULL;
  6092. bfd_boolean res = TRUE;
  6093. memset (&fixup, 0, sizeof (fixup));
  6094. memset (&imgrela, 0, sizeof (imgrela));
  6095. /* Note: the order of the entries is specified by the OpenVMS specs. */
  6096. for (entry = dynamic_section;
  6097. entry < dynamic_section + dynamic_nent;
  6098. entry++)
  6099. {
  6100. switch (entry->d_tag)
  6101. {
  6102. case DT_IA_64_VMS_STRTAB_OFFSET:
  6103. strtab_off = entry->d_un.d_val;
  6104. break;
  6105. case DT_STRSZ:
  6106. strtab_sz = entry->d_un.d_val;
  6107. if (strtab == NULL)
  6108. strtab = get_data (NULL, file, dynamic_addr + strtab_off,
  6109. 1, strtab_sz, _("dynamic string section"));
  6110. break;
  6111. case DT_IA_64_VMS_NEEDED_IDENT:
  6112. fixup.needed_ident = entry->d_un.d_val;
  6113. break;
  6114. case DT_NEEDED:
  6115. fixup.needed = entry->d_un.d_val;
  6116. break;
  6117. case DT_IA_64_VMS_FIXUP_NEEDED:
  6118. fixup.fixup_needed = entry->d_un.d_val;
  6119. break;
  6120. case DT_IA_64_VMS_FIXUP_RELA_CNT:
  6121. fixup.fixup_rela_cnt = entry->d_un.d_val;
  6122. break;
  6123. case DT_IA_64_VMS_FIXUP_RELA_OFF:
  6124. fixup.fixup_rela_off = entry->d_un.d_val;
  6125. if (! dump_ia64_vms_dynamic_fixups (file, &fixup, strtab, strtab_sz))
  6126. res = FALSE;
  6127. break;
  6128. case DT_IA_64_VMS_IMG_RELA_CNT:
  6129. imgrela.img_rela_cnt = entry->d_un.d_val;
  6130. break;
  6131. case DT_IA_64_VMS_IMG_RELA_OFF:
  6132. imgrela.img_rela_off = entry->d_un.d_val;
  6133. if (! dump_ia64_vms_dynamic_relocs (file, &imgrela))
  6134. res = FALSE;
  6135. break;
  6136. default:
  6137. break;
  6138. }
  6139. }
  6140. if (strtab != NULL)
  6141. free (strtab);
  6142. return res;
  6143. }
  6144. static struct
  6145. {
  6146. const char * name;
  6147. int reloc;
  6148. int size;
  6149. int rela;
  6150. }
  6151. dynamic_relocations [] =
  6152. {
  6153. { "REL", DT_REL, DT_RELSZ, FALSE },
  6154. { "RELA", DT_RELA, DT_RELASZ, TRUE },
  6155. { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
  6156. };
  6157. /* Process the reloc section. */
  6158. static bfd_boolean
  6159. process_relocs (FILE * file)
  6160. {
  6161. unsigned long rel_size;
  6162. unsigned long rel_offset;
  6163. if (!do_reloc)
  6164. return TRUE;
  6165. if (do_using_dynamic)
  6166. {
  6167. int is_rela;
  6168. const char * name;
  6169. bfd_boolean has_dynamic_reloc;
  6170. unsigned int i;
  6171. has_dynamic_reloc = FALSE;
  6172. for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
  6173. {
  6174. is_rela = dynamic_relocations [i].rela;
  6175. name = dynamic_relocations [i].name;
  6176. rel_size = dynamic_info [dynamic_relocations [i].size];
  6177. rel_offset = dynamic_info [dynamic_relocations [i].reloc];
  6178. if (rel_size)
  6179. has_dynamic_reloc = TRUE;
  6180. if (is_rela == UNKNOWN)
  6181. {
  6182. if (dynamic_relocations [i].reloc == DT_JMPREL)
  6183. switch (dynamic_info[DT_PLTREL])
  6184. {
  6185. case DT_REL:
  6186. is_rela = FALSE;
  6187. break;
  6188. case DT_RELA:
  6189. is_rela = TRUE;
  6190. break;
  6191. }
  6192. }
  6193. if (rel_size)
  6194. {
  6195. printf
  6196. (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
  6197. name, rel_offset, rel_size);
  6198. dump_relocations (file,
  6199. offset_from_vma (file, rel_offset, rel_size),
  6200. rel_size,
  6201. dynamic_symbols, num_dynamic_syms,
  6202. dynamic_strings, dynamic_strings_length,
  6203. is_rela, TRUE /* is_dynamic */);
  6204. }
  6205. }
  6206. if (is_ia64_vms ())
  6207. if (process_ia64_vms_dynamic_relocs (file))
  6208. has_dynamic_reloc = TRUE;
  6209. if (! has_dynamic_reloc)
  6210. printf (_("\nThere are no dynamic relocations in this file.\n"));
  6211. }
  6212. else
  6213. {
  6214. Elf_Internal_Shdr * section;
  6215. unsigned long i;
  6216. bfd_boolean found = FALSE;
  6217. for (i = 0, section = section_headers;
  6218. i < elf_header.e_shnum;
  6219. i++, section++)
  6220. {
  6221. if ( section->sh_type != SHT_RELA
  6222. && section->sh_type != SHT_REL)
  6223. continue;
  6224. rel_offset = section->sh_offset;
  6225. rel_size = section->sh_size;
  6226. if (rel_size)
  6227. {
  6228. Elf_Internal_Shdr * strsec;
  6229. int is_rela;
  6230. printf (_("\nRelocation section "));
  6231. if (string_table == NULL)
  6232. printf ("%d", section->sh_name);
  6233. else
  6234. printf ("'%s'", printable_section_name (section));
  6235. printf (_(" at offset 0x%lx contains %lu entries:\n"),
  6236. rel_offset, (unsigned long) (rel_size / section->sh_entsize));
  6237. is_rela = section->sh_type == SHT_RELA;
  6238. if (section->sh_link != 0
  6239. && section->sh_link < elf_header.e_shnum)
  6240. {
  6241. Elf_Internal_Shdr * symsec;
  6242. Elf_Internal_Sym * symtab;
  6243. unsigned long nsyms;
  6244. unsigned long strtablen = 0;
  6245. char * strtab = NULL;
  6246. symsec = section_headers + section->sh_link;
  6247. if (symsec->sh_type != SHT_SYMTAB
  6248. && symsec->sh_type != SHT_DYNSYM)
  6249. continue;
  6250. symtab = GET_ELF_SYMBOLS (file, symsec, & nsyms);
  6251. if (symtab == NULL)
  6252. continue;
  6253. if (symsec->sh_link != 0
  6254. && symsec->sh_link < elf_header.e_shnum)
  6255. {
  6256. strsec = section_headers + symsec->sh_link;
  6257. strtab = (char *) get_data (NULL, file, strsec->sh_offset,
  6258. 1, strsec->sh_size,
  6259. _("string table"));
  6260. strtablen = strtab == NULL ? 0 : strsec->sh_size;
  6261. }
  6262. dump_relocations (file, rel_offset, rel_size,
  6263. symtab, nsyms, strtab, strtablen,
  6264. is_rela,
  6265. symsec->sh_type == SHT_DYNSYM);
  6266. if (strtab)
  6267. free (strtab);
  6268. free (symtab);
  6269. }
  6270. else
  6271. dump_relocations (file, rel_offset, rel_size,
  6272. NULL, 0, NULL, 0, is_rela,
  6273. FALSE /* is_dynamic */);
  6274. found = TRUE;
  6275. }
  6276. }
  6277. if (! found)
  6278. printf (_("\nThere are no relocations in this file.\n"));
  6279. }
  6280. return TRUE;
  6281. }
  6282. /* An absolute address consists of a section and an offset. If the
  6283. section is NULL, the offset itself is the address, otherwise, the
  6284. address equals to LOAD_ADDRESS(section) + offset. */
  6285. struct absaddr
  6286. {
  6287. unsigned short section;
  6288. bfd_vma offset;
  6289. };
  6290. #define ABSADDR(a) \
  6291. ((a).section \
  6292. ? section_headers [(a).section].sh_addr + (a).offset \
  6293. : (a).offset)
  6294. /* Find the nearest symbol at or below ADDR. Returns the symbol
  6295. name, if found, and the offset from the symbol to ADDR. */
  6296. static void
  6297. find_symbol_for_address (Elf_Internal_Sym * symtab,
  6298. unsigned long nsyms,
  6299. const char * strtab,
  6300. unsigned long strtab_size,
  6301. struct absaddr addr,
  6302. const char ** symname,
  6303. bfd_vma * offset)
  6304. {
  6305. bfd_vma dist = 0x100000;
  6306. Elf_Internal_Sym * sym;
  6307. Elf_Internal_Sym * beg;
  6308. Elf_Internal_Sym * end;
  6309. Elf_Internal_Sym * best = NULL;
  6310. REMOVE_ARCH_BITS (addr.offset);
  6311. beg = symtab;
  6312. end = symtab + nsyms;
  6313. while (beg < end)
  6314. {
  6315. bfd_vma value;
  6316. sym = beg + (end - beg) / 2;
  6317. value = sym->st_value;
  6318. REMOVE_ARCH_BITS (value);
  6319. if (sym->st_name != 0
  6320. && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
  6321. && addr.offset >= value
  6322. && addr.offset - value < dist)
  6323. {
  6324. best = sym;
  6325. dist = addr.offset - value;
  6326. if (!dist)
  6327. break;
  6328. }
  6329. if (addr.offset < value)
  6330. end = sym;
  6331. else
  6332. beg = sym + 1;
  6333. }
  6334. if (best)
  6335. {
  6336. *symname = (best->st_name >= strtab_size
  6337. ? _("<corrupt>") : strtab + best->st_name);
  6338. *offset = dist;
  6339. return;
  6340. }
  6341. *symname = NULL;
  6342. *offset = addr.offset;
  6343. }
  6344. static /* signed */ int
  6345. symcmp (const void *p, const void *q)
  6346. {
  6347. Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p;
  6348. Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q;
  6349. return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0);
  6350. }
  6351. /* Process the unwind section. */
  6352. #include "unwind-ia64.h"
  6353. struct ia64_unw_table_entry
  6354. {
  6355. struct absaddr start;
  6356. struct absaddr end;
  6357. struct absaddr info;
  6358. };
  6359. struct ia64_unw_aux_info
  6360. {
  6361. struct ia64_unw_table_entry * table; /* Unwind table. */
  6362. unsigned long table_len; /* Length of unwind table. */
  6363. unsigned char * info; /* Unwind info. */
  6364. unsigned long info_size; /* Size of unwind info. */
  6365. bfd_vma info_addr; /* Starting address of unwind info. */
  6366. bfd_vma seg_base; /* Starting address of segment. */
  6367. Elf_Internal_Sym * symtab; /* The symbol table. */
  6368. unsigned long nsyms; /* Number of symbols. */
  6369. Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
  6370. unsigned long nfuns; /* Number of entries in funtab. */
  6371. char * strtab; /* The string table. */
  6372. unsigned long strtab_size; /* Size of string table. */
  6373. };
  6374. static bfd_boolean
  6375. dump_ia64_unwind (struct ia64_unw_aux_info * aux)
  6376. {
  6377. struct ia64_unw_table_entry * tp;
  6378. unsigned long j, nfuns;
  6379. int in_body;
  6380. bfd_boolean res = TRUE;
  6381. aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
  6382. for (nfuns = 0, j = 0; j < aux->nsyms; j++)
  6383. if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
  6384. aux->funtab[nfuns++] = aux->symtab[j];
  6385. aux->nfuns = nfuns;
  6386. qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
  6387. for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
  6388. {
  6389. bfd_vma stamp;
  6390. bfd_vma offset;
  6391. const unsigned char * dp;
  6392. const unsigned char * head;
  6393. const unsigned char * end;
  6394. const char * procname;
  6395. find_symbol_for_address (aux->funtab, aux->nfuns, aux->strtab,
  6396. aux->strtab_size, tp->start, &procname, &offset);
  6397. fputs ("\n<", stdout);
  6398. if (procname)
  6399. {
  6400. fputs (procname, stdout);
  6401. if (offset)
  6402. printf ("+%lx", (unsigned long) offset);
  6403. }
  6404. fputs (">: [", stdout);
  6405. print_vma (tp->start.offset, PREFIX_HEX);
  6406. fputc ('-', stdout);
  6407. print_vma (tp->end.offset, PREFIX_HEX);
  6408. printf ("], info at +0x%lx\n",
  6409. (unsigned long) (tp->info.offset - aux->seg_base));
  6410. /* PR 17531: file: 86232b32. */
  6411. if (aux->info == NULL)
  6412. continue;
  6413. /* PR 17531: file: 0997b4d1. */
  6414. if ((ABSADDR (tp->info) - aux->info_addr) >= aux->info_size)
  6415. {
  6416. warn (_("Invalid offset %lx in table entry %ld\n"),
  6417. (long) tp->info.offset, (long) (tp - aux->table));
  6418. res = FALSE;
  6419. continue;
  6420. }
  6421. head = aux->info + (ABSADDR (tp->info) - aux->info_addr);
  6422. stamp = byte_get ((unsigned char *) head, sizeof (stamp));
  6423. printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
  6424. (unsigned) UNW_VER (stamp),
  6425. (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
  6426. UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
  6427. UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
  6428. (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
  6429. if (UNW_VER (stamp) != 1)
  6430. {
  6431. printf (_("\tUnknown version.\n"));
  6432. continue;
  6433. }
  6434. in_body = 0;
  6435. end = head + 8 + eh_addr_size * UNW_LENGTH (stamp);
  6436. /* PR 17531: file: 16ceda89. */
  6437. if (end > aux->info + aux->info_size)
  6438. end = aux->info + aux->info_size;
  6439. for (dp = head + 8; dp < end;)
  6440. dp = unw_decode (dp, in_body, & in_body, end);
  6441. }
  6442. free (aux->funtab);
  6443. return res;
  6444. }
  6445. static bfd_boolean
  6446. slurp_ia64_unwind_table (FILE * file,
  6447. struct ia64_unw_aux_info * aux,
  6448. Elf_Internal_Shdr * sec)
  6449. {
  6450. unsigned long size, nrelas, i;
  6451. Elf_Internal_Phdr * seg;
  6452. struct ia64_unw_table_entry * tep;
  6453. Elf_Internal_Shdr * relsec;
  6454. Elf_Internal_Rela * rela;
  6455. Elf_Internal_Rela * rp;
  6456. unsigned char * table;
  6457. unsigned char * tp;
  6458. Elf_Internal_Sym * sym;
  6459. const char * relname;
  6460. aux->table_len = 0;
  6461. /* First, find the starting address of the segment that includes
  6462. this section: */
  6463. if (elf_header.e_phnum)
  6464. {
  6465. if (! get_program_headers (file))
  6466. return FALSE;
  6467. for (seg = program_headers;
  6468. seg < program_headers + elf_header.e_phnum;
  6469. ++seg)
  6470. {
  6471. if (seg->p_type != PT_LOAD)
  6472. continue;
  6473. if (sec->sh_addr >= seg->p_vaddr
  6474. && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
  6475. {
  6476. aux->seg_base = seg->p_vaddr;
  6477. break;
  6478. }
  6479. }
  6480. }
  6481. /* Second, build the unwind table from the contents of the unwind section: */
  6482. size = sec->sh_size;
  6483. table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size,
  6484. _("unwind table"));
  6485. if (!table)
  6486. return FALSE;
  6487. aux->table_len = size / (3 * eh_addr_size);
  6488. aux->table = (struct ia64_unw_table_entry *)
  6489. xcmalloc (aux->table_len, sizeof (aux->table[0]));
  6490. tep = aux->table;
  6491. for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep)
  6492. {
  6493. tep->start.section = SHN_UNDEF;
  6494. tep->end.section = SHN_UNDEF;
  6495. tep->info.section = SHN_UNDEF;
  6496. tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
  6497. tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
  6498. tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size;
  6499. tep->start.offset += aux->seg_base;
  6500. tep->end.offset += aux->seg_base;
  6501. tep->info.offset += aux->seg_base;
  6502. }
  6503. free (table);
  6504. /* Third, apply any relocations to the unwind table: */
  6505. for (relsec = section_headers;
  6506. relsec < section_headers + elf_header.e_shnum;
  6507. ++relsec)
  6508. {
  6509. if (relsec->sh_type != SHT_RELA
  6510. || relsec->sh_info >= elf_header.e_shnum
  6511. || section_headers + relsec->sh_info != sec)
  6512. continue;
  6513. if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
  6514. & rela, & nrelas))
  6515. {
  6516. free (aux->table);
  6517. aux->table = NULL;
  6518. aux->table_len = 0;
  6519. return FALSE;
  6520. }
  6521. for (rp = rela; rp < rela + nrelas; ++rp)
  6522. {
  6523. relname = elf_ia64_reloc_type (get_reloc_type (rp->r_info));
  6524. sym = aux->symtab + get_reloc_symindex (rp->r_info);
  6525. /* PR 17531: file: 9fa67536. */
  6526. if (relname == NULL)
  6527. {
  6528. warn (_("Skipping unknown relocation type: %u\n"), get_reloc_type (rp->r_info));
  6529. continue;
  6530. }
  6531. if (! const_strneq (relname, "R_IA64_SEGREL"))
  6532. {
  6533. warn (_("Skipping unexpected relocation type: %s\n"), relname);
  6534. continue;
  6535. }
  6536. i = rp->r_offset / (3 * eh_addr_size);
  6537. /* PR 17531: file: 5bc8d9bf. */
  6538. if (i >= aux->table_len)
  6539. {
  6540. warn (_("Skipping reloc with overlarge offset: %lx\n"), i);
  6541. continue;
  6542. }
  6543. switch (rp->r_offset / eh_addr_size % 3)
  6544. {
  6545. case 0:
  6546. aux->table[i].start.section = sym->st_shndx;
  6547. aux->table[i].start.offset = rp->r_addend + sym->st_value;
  6548. break;
  6549. case 1:
  6550. aux->table[i].end.section = sym->st_shndx;
  6551. aux->table[i].end.offset = rp->r_addend + sym->st_value;
  6552. break;
  6553. case 2:
  6554. aux->table[i].info.section = sym->st_shndx;
  6555. aux->table[i].info.offset = rp->r_addend + sym->st_value;
  6556. break;
  6557. default:
  6558. break;
  6559. }
  6560. }
  6561. free (rela);
  6562. }
  6563. return TRUE;
  6564. }
  6565. static bfd_boolean
  6566. ia64_process_unwind (FILE * file)
  6567. {
  6568. Elf_Internal_Shdr * sec;
  6569. Elf_Internal_Shdr * unwsec = NULL;
  6570. Elf_Internal_Shdr * strsec;
  6571. unsigned long i, unwcount = 0, unwstart = 0;
  6572. struct ia64_unw_aux_info aux;
  6573. bfd_boolean res = TRUE;
  6574. memset (& aux, 0, sizeof (aux));
  6575. for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
  6576. {
  6577. if (sec->sh_type == SHT_SYMTAB
  6578. && sec->sh_link < elf_header.e_shnum)
  6579. {
  6580. aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
  6581. strsec = section_headers + sec->sh_link;
  6582. if (aux.strtab != NULL)
  6583. {
  6584. error (_("Multiple auxillary string tables encountered\n"));
  6585. free (aux.strtab);
  6586. res = FALSE;
  6587. }
  6588. aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
  6589. 1, strsec->sh_size,
  6590. _("string table"));
  6591. aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
  6592. }
  6593. else if (sec->sh_type == SHT_IA_64_UNWIND)
  6594. unwcount++;
  6595. }
  6596. if (!unwcount)
  6597. printf (_("\nThere are no unwind sections in this file.\n"));
  6598. while (unwcount-- > 0)
  6599. {
  6600. char * suffix;
  6601. size_t len, len2;
  6602. for (i = unwstart, sec = section_headers + unwstart, unwsec = NULL;
  6603. i < elf_header.e_shnum; ++i, ++sec)
  6604. if (sec->sh_type == SHT_IA_64_UNWIND)
  6605. {
  6606. unwsec = sec;
  6607. break;
  6608. }
  6609. /* We have already counted the number of SHT_IA64_UNWIND
  6610. sections so the loop above should never fail. */
  6611. assert (unwsec != NULL);
  6612. unwstart = i + 1;
  6613. len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
  6614. if ((unwsec->sh_flags & SHF_GROUP) != 0)
  6615. {
  6616. /* We need to find which section group it is in. */
  6617. struct group_list * g;
  6618. if (section_headers_groups == NULL
  6619. || section_headers_groups [i] == NULL)
  6620. i = elf_header.e_shnum;
  6621. else
  6622. {
  6623. g = section_headers_groups [i]->root;
  6624. for (; g != NULL; g = g->next)
  6625. {
  6626. sec = section_headers + g->section_index;
  6627. if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
  6628. break;
  6629. }
  6630. if (g == NULL)
  6631. i = elf_header.e_shnum;
  6632. }
  6633. }
  6634. else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
  6635. {
  6636. /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
  6637. len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
  6638. suffix = SECTION_NAME (unwsec) + len;
  6639. for (i = 0, sec = section_headers; i < elf_header.e_shnum;
  6640. ++i, ++sec)
  6641. if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
  6642. && streq (SECTION_NAME (sec) + len2, suffix))
  6643. break;
  6644. }
  6645. else
  6646. {
  6647. /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
  6648. .IA_64.unwind or BAR -> .IA_64.unwind_info. */
  6649. len = sizeof (ELF_STRING_ia64_unwind) - 1;
  6650. len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
  6651. suffix = "";
  6652. if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
  6653. suffix = SECTION_NAME (unwsec) + len;
  6654. for (i = 0, sec = section_headers; i < elf_header.e_shnum;
  6655. ++i, ++sec)
  6656. if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
  6657. && streq (SECTION_NAME (sec) + len2, suffix))
  6658. break;
  6659. }
  6660. if (i == elf_header.e_shnum)
  6661. {
  6662. printf (_("\nCould not find unwind info section for "));
  6663. if (string_table == NULL)
  6664. printf ("%d", unwsec->sh_name);
  6665. else
  6666. printf ("'%s'", printable_section_name (unwsec));
  6667. }
  6668. else
  6669. {
  6670. aux.info_addr = sec->sh_addr;
  6671. aux.info = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1,
  6672. sec->sh_size,
  6673. _("unwind info"));
  6674. aux.info_size = aux.info == NULL ? 0 : sec->sh_size;
  6675. printf (_("\nUnwind section "));
  6676. if (string_table == NULL)
  6677. printf ("%d", unwsec->sh_name);
  6678. else
  6679. printf ("'%s'", printable_section_name (unwsec));
  6680. printf (_(" at offset 0x%lx contains %lu entries:\n"),
  6681. (unsigned long) unwsec->sh_offset,
  6682. (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
  6683. if (slurp_ia64_unwind_table (file, & aux, unwsec)
  6684. && aux.table_len > 0)
  6685. dump_ia64_unwind (& aux);
  6686. if (aux.table)
  6687. free ((char *) aux.table);
  6688. if (aux.info)
  6689. free ((char *) aux.info);
  6690. aux.table = NULL;
  6691. aux.info = NULL;
  6692. }
  6693. }
  6694. if (aux.symtab)
  6695. free (aux.symtab);
  6696. if (aux.strtab)
  6697. free ((char *) aux.strtab);
  6698. return res;
  6699. }
  6700. struct hppa_unw_table_entry
  6701. {
  6702. struct absaddr start;
  6703. struct absaddr end;
  6704. unsigned int Cannot_unwind:1; /* 0 */
  6705. unsigned int Millicode:1; /* 1 */
  6706. unsigned int Millicode_save_sr0:1; /* 2 */
  6707. unsigned int Region_description:2; /* 3..4 */
  6708. unsigned int reserved1:1; /* 5 */
  6709. unsigned int Entry_SR:1; /* 6 */
  6710. unsigned int Entry_FR:4; /* Number saved 7..10 */
  6711. unsigned int Entry_GR:5; /* Number saved 11..15 */
  6712. unsigned int Args_stored:1; /* 16 */
  6713. unsigned int Variable_Frame:1; /* 17 */
  6714. unsigned int Separate_Package_Body:1; /* 18 */
  6715. unsigned int Frame_Extension_Millicode:1; /* 19 */
  6716. unsigned int Stack_Overflow_Check:1; /* 20 */
  6717. unsigned int Two_Instruction_SP_Increment:1; /* 21 */
  6718. unsigned int Ada_Region:1; /* 22 */
  6719. unsigned int cxx_info:1; /* 23 */
  6720. unsigned int cxx_try_catch:1; /* 24 */
  6721. unsigned int sched_entry_seq:1; /* 25 */
  6722. unsigned int reserved2:1; /* 26 */
  6723. unsigned int Save_SP:1; /* 27 */
  6724. unsigned int Save_RP:1; /* 28 */
  6725. unsigned int Save_MRP_in_frame:1; /* 29 */
  6726. unsigned int extn_ptr_defined:1; /* 30 */
  6727. unsigned int Cleanup_defined:1; /* 31 */
  6728. unsigned int MPE_XL_interrupt_marker:1; /* 0 */
  6729. unsigned int HP_UX_interrupt_marker:1; /* 1 */
  6730. unsigned int Large_frame:1; /* 2 */
  6731. unsigned int Pseudo_SP_Set:1; /* 3 */
  6732. unsigned int reserved4:1; /* 4 */
  6733. unsigned int Total_frame_size:27; /* 5..31 */
  6734. };
  6735. struct hppa_unw_aux_info
  6736. {
  6737. struct hppa_unw_table_entry * table; /* Unwind table. */
  6738. unsigned long table_len; /* Length of unwind table. */
  6739. bfd_vma seg_base; /* Starting address of segment. */
  6740. Elf_Internal_Sym * symtab; /* The symbol table. */
  6741. unsigned long nsyms; /* Number of symbols. */
  6742. Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
  6743. unsigned long nfuns; /* Number of entries in funtab. */
  6744. char * strtab; /* The string table. */
  6745. unsigned long strtab_size; /* Size of string table. */
  6746. };
  6747. static bfd_boolean
  6748. dump_hppa_unwind (struct hppa_unw_aux_info * aux)
  6749. {
  6750. struct hppa_unw_table_entry * tp;
  6751. unsigned long j, nfuns;
  6752. bfd_boolean res = TRUE;
  6753. aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
  6754. for (nfuns = 0, j = 0; j < aux->nsyms; j++)
  6755. if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
  6756. aux->funtab[nfuns++] = aux->symtab[j];
  6757. aux->nfuns = nfuns;
  6758. qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
  6759. for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
  6760. {
  6761. bfd_vma offset;
  6762. const char * procname;
  6763. find_symbol_for_address (aux->funtab, aux->nfuns, aux->strtab,
  6764. aux->strtab_size, tp->start, &procname,
  6765. &offset);
  6766. fputs ("\n<", stdout);
  6767. if (procname)
  6768. {
  6769. fputs (procname, stdout);
  6770. if (offset)
  6771. printf ("+%lx", (unsigned long) offset);
  6772. }
  6773. fputs (">: [", stdout);
  6774. print_vma (tp->start.offset, PREFIX_HEX);
  6775. fputc ('-', stdout);
  6776. print_vma (tp->end.offset, PREFIX_HEX);
  6777. printf ("]\n\t");
  6778. #define PF(_m) if (tp->_m) printf (#_m " ");
  6779. #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
  6780. PF(Cannot_unwind);
  6781. PF(Millicode);
  6782. PF(Millicode_save_sr0);
  6783. /* PV(Region_description); */
  6784. PF(Entry_SR);
  6785. PV(Entry_FR);
  6786. PV(Entry_GR);
  6787. PF(Args_stored);
  6788. PF(Variable_Frame);
  6789. PF(Separate_Package_Body);
  6790. PF(Frame_Extension_Millicode);
  6791. PF(Stack_Overflow_Check);
  6792. PF(Two_Instruction_SP_Increment);
  6793. PF(Ada_Region);
  6794. PF(cxx_info);
  6795. PF(cxx_try_catch);
  6796. PF(sched_entry_seq);
  6797. PF(Save_SP);
  6798. PF(Save_RP);
  6799. PF(Save_MRP_in_frame);
  6800. PF(extn_ptr_defined);
  6801. PF(Cleanup_defined);
  6802. PF(MPE_XL_interrupt_marker);
  6803. PF(HP_UX_interrupt_marker);
  6804. PF(Large_frame);
  6805. PF(Pseudo_SP_Set);
  6806. PV(Total_frame_size);
  6807. #undef PF
  6808. #undef PV
  6809. }
  6810. printf ("\n");
  6811. free (aux->funtab);
  6812. return res;
  6813. }
  6814. static bfd_boolean
  6815. slurp_hppa_unwind_table (FILE * file,
  6816. struct hppa_unw_aux_info * aux,
  6817. Elf_Internal_Shdr * sec)
  6818. {
  6819. unsigned long size, unw_ent_size, nentries, nrelas, i;
  6820. Elf_Internal_Phdr * seg;
  6821. struct hppa_unw_table_entry * tep;
  6822. Elf_Internal_Shdr * relsec;
  6823. Elf_Internal_Rela * rela;
  6824. Elf_Internal_Rela * rp;
  6825. unsigned char * table;
  6826. unsigned char * tp;
  6827. Elf_Internal_Sym * sym;
  6828. const char * relname;
  6829. /* First, find the starting address of the segment that includes
  6830. this section. */
  6831. if (elf_header.e_phnum)
  6832. {
  6833. if (! get_program_headers (file))
  6834. return FALSE;
  6835. for (seg = program_headers;
  6836. seg < program_headers + elf_header.e_phnum;
  6837. ++seg)
  6838. {
  6839. if (seg->p_type != PT_LOAD)
  6840. continue;
  6841. if (sec->sh_addr >= seg->p_vaddr
  6842. && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
  6843. {
  6844. aux->seg_base = seg->p_vaddr;
  6845. break;
  6846. }
  6847. }
  6848. }
  6849. /* Second, build the unwind table from the contents of the unwind
  6850. section. */
  6851. size = sec->sh_size;
  6852. table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size,
  6853. _("unwind table"));
  6854. if (!table)
  6855. return FALSE;
  6856. unw_ent_size = 16;
  6857. nentries = size / unw_ent_size;
  6858. size = unw_ent_size * nentries;
  6859. tep = aux->table = (struct hppa_unw_table_entry *)
  6860. xcmalloc (nentries, sizeof (aux->table[0]));
  6861. for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
  6862. {
  6863. unsigned int tmp1, tmp2;
  6864. tep->start.section = SHN_UNDEF;
  6865. tep->end.section = SHN_UNDEF;
  6866. tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
  6867. tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
  6868. tmp1 = byte_get ((unsigned char *) tp + 8, 4);
  6869. tmp2 = byte_get ((unsigned char *) tp + 12, 4);
  6870. tep->start.offset += aux->seg_base;
  6871. tep->end.offset += aux->seg_base;
  6872. tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
  6873. tep->Millicode = (tmp1 >> 30) & 0x1;
  6874. tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
  6875. tep->Region_description = (tmp1 >> 27) & 0x3;
  6876. tep->reserved1 = (tmp1 >> 26) & 0x1;
  6877. tep->Entry_SR = (tmp1 >> 25) & 0x1;
  6878. tep->Entry_FR = (tmp1 >> 21) & 0xf;
  6879. tep->Entry_GR = (tmp1 >> 16) & 0x1f;
  6880. tep->Args_stored = (tmp1 >> 15) & 0x1;
  6881. tep->Variable_Frame = (tmp1 >> 14) & 0x1;
  6882. tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
  6883. tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
  6884. tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
  6885. tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
  6886. tep->Ada_Region = (tmp1 >> 9) & 0x1;
  6887. tep->cxx_info = (tmp1 >> 8) & 0x1;
  6888. tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
  6889. tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
  6890. tep->reserved2 = (tmp1 >> 5) & 0x1;
  6891. tep->Save_SP = (tmp1 >> 4) & 0x1;
  6892. tep->Save_RP = (tmp1 >> 3) & 0x1;
  6893. tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
  6894. tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
  6895. tep->Cleanup_defined = tmp1 & 0x1;
  6896. tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
  6897. tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
  6898. tep->Large_frame = (tmp2 >> 29) & 0x1;
  6899. tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
  6900. tep->reserved4 = (tmp2 >> 27) & 0x1;
  6901. tep->Total_frame_size = tmp2 & 0x7ffffff;
  6902. }
  6903. free (table);
  6904. /* Third, apply any relocations to the unwind table. */
  6905. for (relsec = section_headers;
  6906. relsec < section_headers + elf_header.e_shnum;
  6907. ++relsec)
  6908. {
  6909. if (relsec->sh_type != SHT_RELA
  6910. || relsec->sh_info >= elf_header.e_shnum
  6911. || section_headers + relsec->sh_info != sec)
  6912. continue;
  6913. if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
  6914. & rela, & nrelas))
  6915. return FALSE;
  6916. for (rp = rela; rp < rela + nrelas; ++rp)
  6917. {
  6918. relname = elf_hppa_reloc_type (get_reloc_type (rp->r_info));
  6919. sym = aux->symtab + get_reloc_symindex (rp->r_info);
  6920. /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
  6921. if (! const_strneq (relname, "R_PARISC_SEGREL"))
  6922. {
  6923. warn (_("Skipping unexpected relocation type %s\n"), relname);
  6924. continue;
  6925. }
  6926. i = rp->r_offset / unw_ent_size;
  6927. switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
  6928. {
  6929. case 0:
  6930. aux->table[i].start.section = sym->st_shndx;
  6931. aux->table[i].start.offset = sym->st_value + rp->r_addend;
  6932. break;
  6933. case 1:
  6934. aux->table[i].end.section = sym->st_shndx;
  6935. aux->table[i].end.offset = sym->st_value + rp->r_addend;
  6936. break;
  6937. default:
  6938. break;
  6939. }
  6940. }
  6941. free (rela);
  6942. }
  6943. aux->table_len = nentries;
  6944. return TRUE;
  6945. }
  6946. static bfd_boolean
  6947. hppa_process_unwind (FILE * file)
  6948. {
  6949. struct hppa_unw_aux_info aux;
  6950. Elf_Internal_Shdr * unwsec = NULL;
  6951. Elf_Internal_Shdr * strsec;
  6952. Elf_Internal_Shdr * sec;
  6953. unsigned long i;
  6954. bfd_boolean res = TRUE;
  6955. if (string_table == NULL)
  6956. return FALSE;
  6957. memset (& aux, 0, sizeof (aux));
  6958. for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
  6959. {
  6960. if (sec->sh_type == SHT_SYMTAB
  6961. && sec->sh_link < elf_header.e_shnum)
  6962. {
  6963. aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
  6964. strsec = section_headers + sec->sh_link;
  6965. if (aux.strtab != NULL)
  6966. {
  6967. error (_("Multiple auxillary string tables encountered\n"));
  6968. free (aux.strtab);
  6969. res = FALSE;
  6970. }
  6971. aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
  6972. 1, strsec->sh_size,
  6973. _("string table"));
  6974. aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
  6975. }
  6976. else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
  6977. unwsec = sec;
  6978. }
  6979. if (!unwsec)
  6980. printf (_("\nThere are no unwind sections in this file.\n"));
  6981. for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
  6982. {
  6983. if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
  6984. {
  6985. printf (_("\nUnwind section '%s' at offset 0x%lx contains %lu entries:\n"),
  6986. printable_section_name (sec),
  6987. (unsigned long) sec->sh_offset,
  6988. (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8)));
  6989. if (! slurp_hppa_unwind_table (file, &aux, sec))
  6990. res = FALSE;
  6991. if (aux.table_len > 0)
  6992. {
  6993. if (! dump_hppa_unwind (&aux))
  6994. res = FALSE;
  6995. }
  6996. if (aux.table)
  6997. free ((char *) aux.table);
  6998. aux.table = NULL;
  6999. }
  7000. }
  7001. if (aux.symtab)
  7002. free (aux.symtab);
  7003. if (aux.strtab)
  7004. free ((char *) aux.strtab);
  7005. return res;
  7006. }
  7007. struct arm_section
  7008. {
  7009. unsigned char * data; /* The unwind data. */
  7010. Elf_Internal_Shdr * sec; /* The cached unwind section header. */
  7011. Elf_Internal_Rela * rela; /* The cached relocations for this section. */
  7012. unsigned long nrelas; /* The number of relocations. */
  7013. unsigned int rel_type; /* REL or RELA ? */
  7014. Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */
  7015. };
  7016. struct arm_unw_aux_info
  7017. {
  7018. FILE * file; /* The file containing the unwind sections. */
  7019. Elf_Internal_Sym * symtab; /* The file's symbol table. */
  7020. unsigned long nsyms; /* Number of symbols. */
  7021. Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */
  7022. unsigned long nfuns; /* Number of these symbols. */
  7023. char * strtab; /* The file's string table. */
  7024. unsigned long strtab_size; /* Size of string table. */
  7025. };
  7026. static const char *
  7027. arm_print_vma_and_name (struct arm_unw_aux_info *aux,
  7028. bfd_vma fn, struct absaddr addr)
  7029. {
  7030. const char *procname;
  7031. bfd_vma sym_offset;
  7032. if (addr.section == SHN_UNDEF)
  7033. addr.offset = fn;
  7034. find_symbol_for_address (aux->funtab, aux->nfuns, aux->strtab,
  7035. aux->strtab_size, addr, &procname,
  7036. &sym_offset);
  7037. print_vma (fn, PREFIX_HEX);
  7038. if (procname)
  7039. {
  7040. fputs (" <", stdout);
  7041. fputs (procname, stdout);
  7042. if (sym_offset)
  7043. printf ("+0x%lx", (unsigned long) sym_offset);
  7044. fputc ('>', stdout);
  7045. }
  7046. return procname;
  7047. }
  7048. static void
  7049. arm_free_section (struct arm_section *arm_sec)
  7050. {
  7051. if (arm_sec->data != NULL)
  7052. free (arm_sec->data);
  7053. if (arm_sec->rela != NULL)
  7054. free (arm_sec->rela);
  7055. }
  7056. /* 1) If SEC does not match the one cached in ARM_SEC, then free the current
  7057. cached section and install SEC instead.
  7058. 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC
  7059. and return its valued in * WORDP, relocating if necessary.
  7060. 3) Update the NEXT_RELA field in ARM_SEC and store the section index and
  7061. relocation's offset in ADDR.
  7062. 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset
  7063. into the string table of the symbol associated with the reloc. If no
  7064. reloc was applied store -1 there.
  7065. 5) Return TRUE upon success, FALSE otherwise. */
  7066. static bfd_boolean
  7067. get_unwind_section_word (struct arm_unw_aux_info * aux,
  7068. struct arm_section * arm_sec,
  7069. Elf_Internal_Shdr * sec,
  7070. bfd_vma word_offset,
  7071. unsigned int * wordp,
  7072. struct absaddr * addr,
  7073. bfd_vma * sym_name)
  7074. {
  7075. Elf_Internal_Rela *rp;
  7076. Elf_Internal_Sym *sym;
  7077. const char * relname;
  7078. unsigned int word;
  7079. bfd_boolean wrapped;
  7080. if (sec == NULL || arm_sec == NULL)
  7081. return FALSE;
  7082. addr->section = SHN_UNDEF;
  7083. addr->offset = 0;
  7084. if (sym_name != NULL)
  7085. *sym_name = (bfd_vma) -1;
  7086. /* If necessary, update the section cache. */
  7087. if (sec != arm_sec->sec)
  7088. {
  7089. Elf_Internal_Shdr *relsec;
  7090. arm_free_section (arm_sec);
  7091. arm_sec->sec = sec;
  7092. arm_sec->data = get_data (NULL, aux->file, sec->sh_offset, 1,
  7093. sec->sh_size, _("unwind data"));
  7094. arm_sec->rela = NULL;
  7095. arm_sec->nrelas = 0;
  7096. for (relsec = section_headers;
  7097. relsec < section_headers + elf_header.e_shnum;
  7098. ++relsec)
  7099. {
  7100. if (relsec->sh_info >= elf_header.e_shnum
  7101. || section_headers + relsec->sh_info != sec
  7102. /* PR 15745: Check the section type as well. */
  7103. || (relsec->sh_type != SHT_REL
  7104. && relsec->sh_type != SHT_RELA))
  7105. continue;
  7106. arm_sec->rel_type = relsec->sh_type;
  7107. if (relsec->sh_type == SHT_REL)
  7108. {
  7109. if (!slurp_rel_relocs (aux->file, relsec->sh_offset,
  7110. relsec->sh_size,
  7111. & arm_sec->rela, & arm_sec->nrelas))
  7112. return FALSE;
  7113. }
  7114. else /* relsec->sh_type == SHT_RELA */
  7115. {
  7116. if (!slurp_rela_relocs (aux->file, relsec->sh_offset,
  7117. relsec->sh_size,
  7118. & arm_sec->rela, & arm_sec->nrelas))
  7119. return FALSE;
  7120. }
  7121. break;
  7122. }
  7123. arm_sec->next_rela = arm_sec->rela;
  7124. }
  7125. /* If there is no unwind data we can do nothing. */
  7126. if (arm_sec->data == NULL)
  7127. return FALSE;
  7128. /* If the offset is invalid then fail. */
  7129. if (/* PR 21343 *//* PR 18879 */
  7130. sec->sh_size < 4
  7131. || word_offset > (sec->sh_size - 4)
  7132. || ((bfd_signed_vma) word_offset) < 0)
  7133. return FALSE;
  7134. /* Get the word at the required offset. */
  7135. word = byte_get (arm_sec->data + word_offset, 4);
  7136. /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */
  7137. if (arm_sec->rela == NULL)
  7138. {
  7139. * wordp = word;
  7140. return TRUE;
  7141. }
  7142. /* Look through the relocs to find the one that applies to the provided offset. */
  7143. wrapped = FALSE;
  7144. for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++)
  7145. {
  7146. bfd_vma prelval, offset;
  7147. if (rp->r_offset > word_offset && !wrapped)
  7148. {
  7149. rp = arm_sec->rela;
  7150. wrapped = TRUE;
  7151. }
  7152. if (rp->r_offset > word_offset)
  7153. break;
  7154. if (rp->r_offset & 3)
  7155. {
  7156. warn (_("Skipping unexpected relocation at offset 0x%lx\n"),
  7157. (unsigned long) rp->r_offset);
  7158. continue;
  7159. }
  7160. if (rp->r_offset < word_offset)
  7161. continue;
  7162. /* PR 17531: file: 027-161405-0.004 */
  7163. if (aux->symtab == NULL)
  7164. continue;
  7165. if (arm_sec->rel_type == SHT_REL)
  7166. {
  7167. offset = word & 0x7fffffff;
  7168. if (offset & 0x40000000)
  7169. offset |= ~ (bfd_vma) 0x7fffffff;
  7170. }
  7171. else if (arm_sec->rel_type == SHT_RELA)
  7172. offset = rp->r_addend;
  7173. else
  7174. {
  7175. error (_("Unknown section relocation type %d encountered\n"),
  7176. arm_sec->rel_type);
  7177. break;
  7178. }
  7179. /* PR 17531 file: 027-1241568-0.004. */
  7180. if (ELF32_R_SYM (rp->r_info) >= aux->nsyms)
  7181. {
  7182. error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"),
  7183. (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms);
  7184. break;
  7185. }
  7186. sym = aux->symtab + ELF32_R_SYM (rp->r_info);
  7187. offset += sym->st_value;
  7188. prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset);
  7189. /* Check that we are processing the expected reloc type. */
  7190. if (elf_header.e_machine == EM_ARM)
  7191. {
  7192. relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info));
  7193. if (relname == NULL)
  7194. {
  7195. warn (_("Skipping unknown ARM relocation type: %d\n"),
  7196. (int) ELF32_R_TYPE (rp->r_info));
  7197. continue;
  7198. }
  7199. if (streq (relname, "R_ARM_NONE"))
  7200. continue;
  7201. if (! streq (relname, "R_ARM_PREL31"))
  7202. {
  7203. warn (_("Skipping unexpected ARM relocation type %s\n"), relname);
  7204. continue;
  7205. }
  7206. }
  7207. else if (elf_header.e_machine == EM_TI_C6000)
  7208. {
  7209. relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info));
  7210. if (relname == NULL)
  7211. {
  7212. warn (_("Skipping unknown C6000 relocation type: %d\n"),
  7213. (int) ELF32_R_TYPE (rp->r_info));
  7214. continue;
  7215. }
  7216. if (streq (relname, "R_C6000_NONE"))
  7217. continue;
  7218. if (! streq (relname, "R_C6000_PREL31"))
  7219. {
  7220. warn (_("Skipping unexpected C6000 relocation type %s\n"), relname);
  7221. continue;
  7222. }
  7223. prelval >>= 1;
  7224. }
  7225. else
  7226. {
  7227. /* This function currently only supports ARM and TI unwinders. */
  7228. warn (_("Only TI and ARM unwinders are currently supported\n"));
  7229. break;
  7230. }
  7231. word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff);
  7232. addr->section = sym->st_shndx;
  7233. addr->offset = offset;
  7234. if (sym_name)
  7235. * sym_name = sym->st_name;
  7236. break;
  7237. }
  7238. *wordp = word;
  7239. arm_sec->next_rela = rp;
  7240. return TRUE;
  7241. }
  7242. static const char *tic6x_unwind_regnames[16] =
  7243. {
  7244. "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3",
  7245. "A14", "A13", "A12", "A11", "A10",
  7246. "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]"
  7247. };
  7248. static void
  7249. decode_tic6x_unwind_regmask (unsigned int mask)
  7250. {
  7251. int i;
  7252. for (i = 12; mask; mask >>= 1, i--)
  7253. {
  7254. if (mask & 1)
  7255. {
  7256. fputs (tic6x_unwind_regnames[i], stdout);
  7257. if (mask > 1)
  7258. fputs (", ", stdout);
  7259. }
  7260. }
  7261. }
  7262. #define ADVANCE \
  7263. if (remaining == 0 && more_words) \
  7264. { \
  7265. data_offset += 4; \
  7266. if (! get_unwind_section_word (aux, data_arm_sec, data_sec, \
  7267. data_offset, & word, & addr, NULL)) \
  7268. return FALSE; \
  7269. remaining = 4; \
  7270. more_words--; \
  7271. } \
  7272. #define GET_OP(OP) \
  7273. ADVANCE; \
  7274. if (remaining) \
  7275. { \
  7276. remaining--; \
  7277. (OP) = word >> 24; \
  7278. word <<= 8; \
  7279. } \
  7280. else \
  7281. { \
  7282. printf (_("[Truncated opcode]\n")); \
  7283. return FALSE; \
  7284. } \
  7285. printf ("0x%02x ", OP)
  7286. static bfd_boolean
  7287. decode_arm_unwind_bytecode (struct arm_unw_aux_info * aux,
  7288. unsigned int word,
  7289. unsigned int remaining,
  7290. unsigned int more_words,
  7291. bfd_vma data_offset,
  7292. Elf_Internal_Shdr * data_sec,
  7293. struct arm_section * data_arm_sec)
  7294. {
  7295. struct absaddr addr;
  7296. bfd_boolean res = TRUE;
  7297. /* Decode the unwinding instructions. */
  7298. while (1)
  7299. {
  7300. unsigned int op, op2;
  7301. ADVANCE;
  7302. if (remaining == 0)
  7303. break;
  7304. remaining--;
  7305. op = word >> 24;
  7306. word <<= 8;
  7307. printf (" 0x%02x ", op);
  7308. if ((op & 0xc0) == 0x00)
  7309. {
  7310. int offset = ((op & 0x3f) << 2) + 4;
  7311. printf (" vsp = vsp + %d", offset);
  7312. }
  7313. else if ((op & 0xc0) == 0x40)
  7314. {
  7315. int offset = ((op & 0x3f) << 2) + 4;
  7316. printf (" vsp = vsp - %d", offset);
  7317. }
  7318. else if ((op & 0xf0) == 0x80)
  7319. {
  7320. GET_OP (op2);
  7321. if (op == 0x80 && op2 == 0)
  7322. printf (_("Refuse to unwind"));
  7323. else
  7324. {
  7325. unsigned int mask = ((op & 0x0f) << 8) | op2;
  7326. bfd_boolean first = TRUE;
  7327. int i;
  7328. printf ("pop {");
  7329. for (i = 0; i < 12; i++)
  7330. if (mask & (1 << i))
  7331. {
  7332. if (first)
  7333. first = FALSE;
  7334. else
  7335. printf (", ");
  7336. printf ("r%d", 4 + i);
  7337. }
  7338. printf ("}");
  7339. }
  7340. }
  7341. else if ((op & 0xf0) == 0x90)
  7342. {
  7343. if (op == 0x9d || op == 0x9f)
  7344. printf (_(" [Reserved]"));
  7345. else
  7346. printf (" vsp = r%d", op & 0x0f);
  7347. }
  7348. else if ((op & 0xf0) == 0xa0)
  7349. {
  7350. int end = 4 + (op & 0x07);
  7351. bfd_boolean first = TRUE;
  7352. int i;
  7353. printf (" pop {");
  7354. for (i = 4; i <= end; i++)
  7355. {
  7356. if (first)
  7357. first = FALSE;
  7358. else
  7359. printf (", ");
  7360. printf ("r%d", i);
  7361. }
  7362. if (op & 0x08)
  7363. {
  7364. if (!first)
  7365. printf (", ");
  7366. printf ("r14");
  7367. }
  7368. printf ("}");
  7369. }
  7370. else if (op == 0xb0)
  7371. printf (_(" finish"));
  7372. else if (op == 0xb1)
  7373. {
  7374. GET_OP (op2);
  7375. if (op2 == 0 || (op2 & 0xf0) != 0)
  7376. printf (_("[Spare]"));
  7377. else
  7378. {
  7379. unsigned int mask = op2 & 0x0f;
  7380. bfd_boolean first = TRUE;
  7381. int i;
  7382. printf ("pop {");
  7383. for (i = 0; i < 12; i++)
  7384. if (mask & (1 << i))
  7385. {
  7386. if (first)
  7387. first = FALSE;
  7388. else
  7389. printf (", ");
  7390. printf ("r%d", i);
  7391. }
  7392. printf ("}");
  7393. }
  7394. }
  7395. else if (op == 0xb2)
  7396. {
  7397. unsigned char buf[9];
  7398. unsigned int i, len;
  7399. unsigned long offset;
  7400. for (i = 0; i < sizeof (buf); i++)
  7401. {
  7402. GET_OP (buf[i]);
  7403. if ((buf[i] & 0x80) == 0)
  7404. break;
  7405. }
  7406. if (i == sizeof (buf))
  7407. {
  7408. error (_("corrupt change to vsp"));
  7409. res = FALSE;
  7410. }
  7411. else
  7412. {
  7413. offset = read_uleb128 (buf, &len, buf + i + 1);
  7414. assert (len == i + 1);
  7415. offset = offset * 4 + 0x204;
  7416. printf ("vsp = vsp + %ld", offset);
  7417. }
  7418. }
  7419. else if (op == 0xb3 || op == 0xc8 || op == 0xc9)
  7420. {
  7421. unsigned int first, last;
  7422. GET_OP (op2);
  7423. first = op2 >> 4;
  7424. last = op2 & 0x0f;
  7425. if (op == 0xc8)
  7426. first = first + 16;
  7427. printf ("pop {D%d", first);
  7428. if (last)
  7429. printf ("-D%d", first + last);
  7430. printf ("}");
  7431. }
  7432. else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0)
  7433. {
  7434. unsigned int count = op & 0x07;
  7435. printf ("pop {D8");
  7436. if (count)
  7437. printf ("-D%d", 8 + count);
  7438. printf ("}");
  7439. }
  7440. else if (op >= 0xc0 && op <= 0xc5)
  7441. {
  7442. unsigned int count = op & 0x07;
  7443. printf (" pop {wR10");
  7444. if (count)
  7445. printf ("-wR%d", 10 + count);
  7446. printf ("}");
  7447. }
  7448. else if (op == 0xc6)
  7449. {
  7450. unsigned int first, last;
  7451. GET_OP (op2);
  7452. first = op2 >> 4;
  7453. last = op2 & 0x0f;
  7454. printf ("pop {wR%d", first);
  7455. if (last)
  7456. printf ("-wR%d", first + last);
  7457. printf ("}");
  7458. }
  7459. else if (op == 0xc7)
  7460. {
  7461. GET_OP (op2);
  7462. if (op2 == 0 || (op2 & 0xf0) != 0)
  7463. printf (_("[Spare]"));
  7464. else
  7465. {
  7466. unsigned int mask = op2 & 0x0f;
  7467. bfd_boolean first = TRUE;
  7468. int i;
  7469. printf ("pop {");
  7470. for (i = 0; i < 4; i++)
  7471. if (mask & (1 << i))
  7472. {
  7473. if (first)
  7474. first = FALSE;
  7475. else
  7476. printf (", ");
  7477. printf ("wCGR%d", i);
  7478. }
  7479. printf ("}");
  7480. }
  7481. }
  7482. else
  7483. {
  7484. printf (_(" [unsupported opcode]"));
  7485. res = FALSE;
  7486. }
  7487. printf ("\n");
  7488. }
  7489. return res;
  7490. }
  7491. static bfd_boolean
  7492. decode_tic6x_unwind_bytecode (struct arm_unw_aux_info * aux,
  7493. unsigned int word,
  7494. unsigned int remaining,
  7495. unsigned int more_words,
  7496. bfd_vma data_offset,
  7497. Elf_Internal_Shdr * data_sec,
  7498. struct arm_section * data_arm_sec)
  7499. {
  7500. struct absaddr addr;
  7501. /* Decode the unwinding instructions. */
  7502. while (1)
  7503. {
  7504. unsigned int op, op2;
  7505. ADVANCE;
  7506. if (remaining == 0)
  7507. break;
  7508. remaining--;
  7509. op = word >> 24;
  7510. word <<= 8;
  7511. printf (" 0x%02x ", op);
  7512. if ((op & 0xc0) == 0x00)
  7513. {
  7514. int offset = ((op & 0x3f) << 3) + 8;
  7515. printf (" sp = sp + %d", offset);
  7516. }
  7517. else if ((op & 0xc0) == 0x80)
  7518. {
  7519. GET_OP (op2);
  7520. if (op == 0x80 && op2 == 0)
  7521. printf (_("Refuse to unwind"));
  7522. else
  7523. {
  7524. unsigned int mask = ((op & 0x1f) << 8) | op2;
  7525. if (op & 0x20)
  7526. printf ("pop compact {");
  7527. else
  7528. printf ("pop {");
  7529. decode_tic6x_unwind_regmask (mask);
  7530. printf("}");
  7531. }
  7532. }
  7533. else if ((op & 0xf0) == 0xc0)
  7534. {
  7535. unsigned int reg;
  7536. unsigned int nregs;
  7537. unsigned int i;
  7538. const char *name;
  7539. struct
  7540. {
  7541. unsigned int offset;
  7542. unsigned int reg;
  7543. } regpos[16];
  7544. /* Scan entire instruction first so that GET_OP output is not
  7545. interleaved with disassembly. */
  7546. nregs = 0;
  7547. for (i = 0; nregs < (op & 0xf); i++)
  7548. {
  7549. GET_OP (op2);
  7550. reg = op2 >> 4;
  7551. if (reg != 0xf)
  7552. {
  7553. regpos[nregs].offset = i * 2;
  7554. regpos[nregs].reg = reg;
  7555. nregs++;
  7556. }
  7557. reg = op2 & 0xf;
  7558. if (reg != 0xf)
  7559. {
  7560. regpos[nregs].offset = i * 2 + 1;
  7561. regpos[nregs].reg = reg;
  7562. nregs++;
  7563. }
  7564. }
  7565. printf (_("pop frame {"));
  7566. reg = nregs - 1;
  7567. for (i = i * 2; i > 0; i--)
  7568. {
  7569. if (regpos[reg].offset == i - 1)
  7570. {
  7571. name = tic6x_unwind_regnames[regpos[reg].reg];
  7572. if (reg > 0)
  7573. reg--;
  7574. }
  7575. else
  7576. name = _("[pad]");
  7577. fputs (name, stdout);
  7578. if (i > 1)
  7579. printf (", ");
  7580. }
  7581. printf ("}");
  7582. }
  7583. else if (op == 0xd0)
  7584. printf (" MOV FP, SP");
  7585. else if (op == 0xd1)
  7586. printf (" __c6xabi_pop_rts");
  7587. else if (op == 0xd2)
  7588. {
  7589. unsigned char buf[9];
  7590. unsigned int i, len;
  7591. unsigned long offset;
  7592. for (i = 0; i < sizeof (buf); i++)
  7593. {
  7594. GET_OP (buf[i]);
  7595. if ((buf[i] & 0x80) == 0)
  7596. break;
  7597. }
  7598. /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */
  7599. if (i == sizeof (buf))
  7600. {
  7601. warn (_("Corrupt stack pointer adjustment detected\n"));
  7602. return FALSE;
  7603. }
  7604. offset = read_uleb128 (buf, &len, buf + i + 1);
  7605. assert (len == i + 1);
  7606. offset = offset * 8 + 0x408;
  7607. printf (_("sp = sp + %ld"), offset);
  7608. }
  7609. else if ((op & 0xf0) == 0xe0)
  7610. {
  7611. if ((op & 0x0f) == 7)
  7612. printf (" RETURN");
  7613. else
  7614. printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]);
  7615. }
  7616. else
  7617. {
  7618. printf (_(" [unsupported opcode]"));
  7619. }
  7620. putchar ('\n');
  7621. }
  7622. return TRUE;
  7623. }
  7624. static bfd_vma
  7625. arm_expand_prel31 (bfd_vma word, bfd_vma where)
  7626. {
  7627. bfd_vma offset;
  7628. offset = word & 0x7fffffff;
  7629. if (offset & 0x40000000)
  7630. offset |= ~ (bfd_vma) 0x7fffffff;
  7631. if (elf_header.e_machine == EM_TI_C6000)
  7632. offset <<= 1;
  7633. return offset + where;
  7634. }
  7635. static bfd_boolean
  7636. decode_arm_unwind (struct arm_unw_aux_info * aux,
  7637. unsigned int word,
  7638. unsigned int remaining,
  7639. bfd_vma data_offset,
  7640. Elf_Internal_Shdr * data_sec,
  7641. struct arm_section * data_arm_sec)
  7642. {
  7643. int per_index;
  7644. unsigned int more_words = 0;
  7645. struct absaddr addr;
  7646. bfd_vma sym_name = (bfd_vma) -1;
  7647. bfd_boolean res = FALSE;
  7648. if (remaining == 0)
  7649. {
  7650. /* Fetch the first word.
  7651. Note - when decoding an object file the address extracted
  7652. here will always be 0. So we also pass in the sym_name
  7653. parameter so that we can find the symbol associated with
  7654. the personality routine. */
  7655. if (! get_unwind_section_word (aux, data_arm_sec, data_sec, data_offset,
  7656. & word, & addr, & sym_name))
  7657. return FALSE;
  7658. remaining = 4;
  7659. }
  7660. if ((word & 0x80000000) == 0)
  7661. {
  7662. /* Expand prel31 for personality routine. */
  7663. bfd_vma fn;
  7664. const char *procname;
  7665. fn = arm_expand_prel31 (word, data_sec->sh_addr + data_offset);
  7666. printf (_(" Personality routine: "));
  7667. if (fn == 0
  7668. && addr.section == SHN_UNDEF && addr.offset == 0
  7669. && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size)
  7670. {
  7671. procname = aux->strtab + sym_name;
  7672. print_vma (fn, PREFIX_HEX);
  7673. if (procname)
  7674. {
  7675. fputs (" <", stdout);
  7676. fputs (procname, stdout);
  7677. fputc ('>', stdout);
  7678. }
  7679. }
  7680. else
  7681. procname = arm_print_vma_and_name (aux, fn, addr);
  7682. fputc ('\n', stdout);
  7683. /* The GCC personality routines use the standard compact
  7684. encoding, starting with one byte giving the number of
  7685. words. */
  7686. if (procname != NULL
  7687. && (const_strneq (procname, "__gcc_personality_v0")
  7688. || const_strneq (procname, "__gxx_personality_v0")
  7689. || const_strneq (procname, "__gcj_personality_v0")
  7690. || const_strneq (procname, "__gnu_objc_personality_v0")))
  7691. {
  7692. remaining = 0;
  7693. more_words = 1;
  7694. ADVANCE;
  7695. if (!remaining)
  7696. {
  7697. printf (_(" [Truncated data]\n"));
  7698. return FALSE;
  7699. }
  7700. more_words = word >> 24;
  7701. word <<= 8;
  7702. remaining--;
  7703. per_index = -1;
  7704. }
  7705. else
  7706. return TRUE;
  7707. }
  7708. else
  7709. {
  7710. /* ARM EHABI Section 6.3:
  7711. An exception-handling table entry for the compact model looks like:
  7712. 31 30-28 27-24 23-0
  7713. -- ----- ----- ----
  7714. 1 0 index Data for personalityRoutine[index] */
  7715. if (elf_header.e_machine == EM_ARM
  7716. && (word & 0x70000000))
  7717. {
  7718. warn (_("Corrupt ARM compact model table entry: %x \n"), word);
  7719. res = FALSE;
  7720. }
  7721. per_index = (word >> 24) & 0x7f;
  7722. printf (_(" Compact model index: %d\n"), per_index);
  7723. if (per_index == 0)
  7724. {
  7725. more_words = 0;
  7726. word <<= 8;
  7727. remaining--;
  7728. }
  7729. else if (per_index < 3)
  7730. {
  7731. more_words = (word >> 16) & 0xff;
  7732. word <<= 16;
  7733. remaining -= 2;
  7734. }
  7735. }
  7736. switch (elf_header.e_machine)
  7737. {
  7738. case EM_ARM:
  7739. if (per_index < 3)
  7740. {
  7741. if (! decode_arm_unwind_bytecode (aux, word, remaining, more_words,
  7742. data_offset, data_sec, data_arm_sec))
  7743. res = FALSE;
  7744. }
  7745. else
  7746. {
  7747. warn (_("Unknown ARM compact model index encountered\n"));
  7748. printf (_(" [reserved]\n"));
  7749. res = FALSE;
  7750. }
  7751. break;
  7752. case EM_TI_C6000:
  7753. if (per_index < 3)
  7754. {
  7755. if (! decode_tic6x_unwind_bytecode (aux, word, remaining, more_words,
  7756. data_offset, data_sec, data_arm_sec))
  7757. res = FALSE;
  7758. }
  7759. else if (per_index < 5)
  7760. {
  7761. if (((word >> 17) & 0x7f) == 0x7f)
  7762. printf (_(" Restore stack from frame pointer\n"));
  7763. else
  7764. printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc);
  7765. printf (_(" Registers restored: "));
  7766. if (per_index == 4)
  7767. printf (" (compact) ");
  7768. decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff);
  7769. putchar ('\n');
  7770. printf (_(" Return register: %s\n"),
  7771. tic6x_unwind_regnames[word & 0xf]);
  7772. }
  7773. else
  7774. printf (_(" [reserved (%d)]\n"), per_index);
  7775. break;
  7776. default:
  7777. error (_("Unsupported architecture type %d encountered when decoding unwind table\n"),
  7778. elf_header.e_machine);
  7779. res = FALSE;
  7780. }
  7781. /* Decode the descriptors. Not implemented. */
  7782. return res;
  7783. }
  7784. static bfd_boolean
  7785. dump_arm_unwind (struct arm_unw_aux_info *aux, Elf_Internal_Shdr *exidx_sec)
  7786. {
  7787. struct arm_section exidx_arm_sec, extab_arm_sec;
  7788. unsigned int i, exidx_len;
  7789. unsigned long j, nfuns;
  7790. bfd_boolean res = TRUE;
  7791. memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec));
  7792. memset (&extab_arm_sec, 0, sizeof (extab_arm_sec));
  7793. exidx_len = exidx_sec->sh_size / 8;
  7794. aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym));
  7795. for (nfuns = 0, j = 0; j < aux->nsyms; j++)
  7796. if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC)
  7797. aux->funtab[nfuns++] = aux->symtab[j];
  7798. aux->nfuns = nfuns;
  7799. qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp);
  7800. for (i = 0; i < exidx_len; i++)
  7801. {
  7802. unsigned int exidx_fn, exidx_entry;
  7803. struct absaddr fn_addr, entry_addr;
  7804. bfd_vma fn;
  7805. fputc ('\n', stdout);
  7806. if (! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec,
  7807. 8 * i, & exidx_fn, & fn_addr, NULL)
  7808. || ! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec,
  7809. 8 * i + 4, & exidx_entry, & entry_addr, NULL))
  7810. {
  7811. free (aux->funtab);
  7812. arm_free_section (& exidx_arm_sec);
  7813. arm_free_section (& extab_arm_sec);
  7814. return FALSE;
  7815. }
  7816. /* ARM EHABI, Section 5:
  7817. An index table entry consists of 2 words.
  7818. The first word contains a prel31 offset to the start of a function, with bit 31 clear. */
  7819. if (exidx_fn & 0x80000000)
  7820. {
  7821. warn (_("corrupt index table entry: %x\n"), exidx_fn);
  7822. res = FALSE;
  7823. }
  7824. fn = arm_expand_prel31 (exidx_fn, exidx_sec->sh_addr + 8 * i);
  7825. arm_print_vma_and_name (aux, fn, fn_addr);
  7826. fputs (": ", stdout);
  7827. if (exidx_entry == 1)
  7828. {
  7829. print_vma (exidx_entry, PREFIX_HEX);
  7830. fputs (" [cantunwind]\n", stdout);
  7831. }
  7832. else if (exidx_entry & 0x80000000)
  7833. {
  7834. print_vma (exidx_entry, PREFIX_HEX);
  7835. fputc ('\n', stdout);
  7836. decode_arm_unwind (aux, exidx_entry, 4, 0, NULL, NULL);
  7837. }
  7838. else
  7839. {
  7840. bfd_vma table, table_offset = 0;
  7841. Elf_Internal_Shdr *table_sec;
  7842. fputs ("@", stdout);
  7843. table = arm_expand_prel31 (exidx_entry, exidx_sec->sh_addr + 8 * i + 4);
  7844. print_vma (table, PREFIX_HEX);
  7845. printf ("\n");
  7846. /* Locate the matching .ARM.extab. */
  7847. if (entry_addr.section != SHN_UNDEF
  7848. && entry_addr.section < elf_header.e_shnum)
  7849. {
  7850. table_sec = section_headers + entry_addr.section;
  7851. table_offset = entry_addr.offset;
  7852. /* PR 18879 */
  7853. if (table_offset > table_sec->sh_size
  7854. || ((bfd_signed_vma) table_offset) < 0)
  7855. {
  7856. warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"),
  7857. (unsigned long) table_offset,
  7858. printable_section_name (table_sec));
  7859. res = FALSE;
  7860. continue;
  7861. }
  7862. }
  7863. else
  7864. {
  7865. table_sec = find_section_by_address (table);
  7866. if (table_sec != NULL)
  7867. table_offset = table - table_sec->sh_addr;
  7868. }
  7869. if (table_sec == NULL)
  7870. {
  7871. warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"),
  7872. (unsigned long) table);
  7873. res = FALSE;
  7874. continue;
  7875. }
  7876. if (! decode_arm_unwind (aux, 0, 0, table_offset, table_sec,
  7877. &extab_arm_sec))
  7878. res = FALSE;
  7879. }
  7880. }
  7881. printf ("\n");
  7882. free (aux->funtab);
  7883. arm_free_section (&exidx_arm_sec);
  7884. arm_free_section (&extab_arm_sec);
  7885. return res;
  7886. }
  7887. /* Used for both ARM and C6X unwinding tables. */
  7888. static bfd_boolean
  7889. arm_process_unwind (FILE *file)
  7890. {
  7891. struct arm_unw_aux_info aux;
  7892. Elf_Internal_Shdr *unwsec = NULL;
  7893. Elf_Internal_Shdr *strsec;
  7894. Elf_Internal_Shdr *sec;
  7895. unsigned long i;
  7896. unsigned int sec_type;
  7897. bfd_boolean res = TRUE;
  7898. switch (elf_header.e_machine)
  7899. {
  7900. case EM_ARM:
  7901. sec_type = SHT_ARM_EXIDX;
  7902. break;
  7903. case EM_TI_C6000:
  7904. sec_type = SHT_C6000_UNWIND;
  7905. break;
  7906. default:
  7907. error (_("Unsupported architecture type %d encountered when processing unwind table\n"),
  7908. elf_header.e_machine);
  7909. return FALSE;
  7910. }
  7911. if (string_table == NULL)
  7912. return FALSE;
  7913. memset (& aux, 0, sizeof (aux));
  7914. aux.file = file;
  7915. for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
  7916. {
  7917. if (sec->sh_type == SHT_SYMTAB && sec->sh_link < elf_header.e_shnum)
  7918. {
  7919. aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms);
  7920. strsec = section_headers + sec->sh_link;
  7921. /* PR binutils/17531 file: 011-12666-0.004. */
  7922. if (aux.strtab != NULL)
  7923. {
  7924. error (_("Multiple string tables found in file.\n"));
  7925. free (aux.strtab);
  7926. res = FALSE;
  7927. }
  7928. aux.strtab = get_data (NULL, file, strsec->sh_offset,
  7929. 1, strsec->sh_size, _("string table"));
  7930. aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
  7931. }
  7932. else if (sec->sh_type == sec_type)
  7933. unwsec = sec;
  7934. }
  7935. if (unwsec == NULL)
  7936. printf (_("\nThere are no unwind sections in this file.\n"));
  7937. else
  7938. for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
  7939. {
  7940. if (sec->sh_type == sec_type)
  7941. {
  7942. printf (_("\nUnwind table index '%s' at offset 0x%lx contains %lu entries:\n"),
  7943. printable_section_name (sec),
  7944. (unsigned long) sec->sh_offset,
  7945. (unsigned long) (sec->sh_size / (2 * eh_addr_size)));
  7946. if (! dump_arm_unwind (&aux, sec))
  7947. res = FALSE;
  7948. }
  7949. }
  7950. if (aux.symtab)
  7951. free (aux.symtab);
  7952. if (aux.strtab)
  7953. free ((char *) aux.strtab);
  7954. return res;
  7955. }
  7956. static bfd_boolean
  7957. process_unwind (FILE * file)
  7958. {
  7959. struct unwind_handler
  7960. {
  7961. unsigned int machtype;
  7962. bfd_boolean (* handler)(FILE *);
  7963. } handlers[] =
  7964. {
  7965. { EM_ARM, arm_process_unwind },
  7966. { EM_IA_64, ia64_process_unwind },
  7967. { EM_PARISC, hppa_process_unwind },
  7968. { EM_TI_C6000, arm_process_unwind },
  7969. { 0, NULL }
  7970. };
  7971. int i;
  7972. if (!do_unwind)
  7973. return TRUE;
  7974. for (i = 0; handlers[i].handler != NULL; i++)
  7975. if (elf_header.e_machine == handlers[i].machtype)
  7976. return handlers[i].handler (file);
  7977. printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"),
  7978. get_machine_name (elf_header.e_machine));
  7979. return TRUE;
  7980. }
  7981. static void
  7982. dynamic_section_mips_val (Elf_Internal_Dyn * entry)
  7983. {
  7984. switch (entry->d_tag)
  7985. {
  7986. case DT_MIPS_FLAGS:
  7987. if (entry->d_un.d_val == 0)
  7988. printf (_("NONE"));
  7989. else
  7990. {
  7991. static const char * opts[] =
  7992. {
  7993. "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
  7994. "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
  7995. "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
  7996. "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
  7997. "RLD_ORDER_SAFE"
  7998. };
  7999. unsigned int cnt;
  8000. bfd_boolean first = TRUE;
  8001. for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt)
  8002. if (entry->d_un.d_val & (1 << cnt))
  8003. {
  8004. printf ("%s%s", first ? "" : " ", opts[cnt]);
  8005. first = FALSE;
  8006. }
  8007. }
  8008. break;
  8009. case DT_MIPS_IVERSION:
  8010. if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
  8011. printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry->d_un.d_val));
  8012. else
  8013. {
  8014. char buf[40];
  8015. sprintf_vma (buf, entry->d_un.d_ptr);
  8016. /* Note: coded this way so that there is a single string for translation. */
  8017. printf (_("<corrupt: %s>"), buf);
  8018. }
  8019. break;
  8020. case DT_MIPS_TIME_STAMP:
  8021. {
  8022. char timebuf[128];
  8023. struct tm * tmp;
  8024. time_t atime = entry->d_un.d_val;
  8025. tmp = gmtime (&atime);
  8026. /* PR 17531: file: 6accc532. */
  8027. if (tmp == NULL)
  8028. snprintf (timebuf, sizeof (timebuf), _("<corrupt>"));
  8029. else
  8030. snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
  8031. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  8032. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  8033. printf (_("Time Stamp: %s"), timebuf);
  8034. }
  8035. break;
  8036. case DT_MIPS_RLD_VERSION:
  8037. case DT_MIPS_LOCAL_GOTNO:
  8038. case DT_MIPS_CONFLICTNO:
  8039. case DT_MIPS_LIBLISTNO:
  8040. case DT_MIPS_SYMTABNO:
  8041. case DT_MIPS_UNREFEXTNO:
  8042. case DT_MIPS_HIPAGENO:
  8043. case DT_MIPS_DELTA_CLASS_NO:
  8044. case DT_MIPS_DELTA_INSTANCE_NO:
  8045. case DT_MIPS_DELTA_RELOC_NO:
  8046. case DT_MIPS_DELTA_SYM_NO:
  8047. case DT_MIPS_DELTA_CLASSSYM_NO:
  8048. case DT_MIPS_COMPACT_SIZE:
  8049. print_vma (entry->d_un.d_val, DEC);
  8050. break;
  8051. default:
  8052. print_vma (entry->d_un.d_ptr, PREFIX_HEX);
  8053. }
  8054. putchar ('\n');
  8055. }
  8056. static void
  8057. dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
  8058. {
  8059. switch (entry->d_tag)
  8060. {
  8061. case DT_HP_DLD_FLAGS:
  8062. {
  8063. static struct
  8064. {
  8065. long int bit;
  8066. const char * str;
  8067. }
  8068. flags[] =
  8069. {
  8070. { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
  8071. { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
  8072. { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
  8073. { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
  8074. { DT_HP_BIND_NOW, "HP_BIND_NOW" },
  8075. { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
  8076. { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
  8077. { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
  8078. { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
  8079. { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
  8080. { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
  8081. { DT_HP_GST, "HP_GST" },
  8082. { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
  8083. { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
  8084. { DT_HP_NODELETE, "HP_NODELETE" },
  8085. { DT_HP_GROUP, "HP_GROUP" },
  8086. { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
  8087. };
  8088. bfd_boolean first = TRUE;
  8089. size_t cnt;
  8090. bfd_vma val = entry->d_un.d_val;
  8091. for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt)
  8092. if (val & flags[cnt].bit)
  8093. {
  8094. if (! first)
  8095. putchar (' ');
  8096. fputs (flags[cnt].str, stdout);
  8097. first = FALSE;
  8098. val ^= flags[cnt].bit;
  8099. }
  8100. if (val != 0 || first)
  8101. {
  8102. if (! first)
  8103. putchar (' ');
  8104. print_vma (val, HEX);
  8105. }
  8106. }
  8107. break;
  8108. default:
  8109. print_vma (entry->d_un.d_ptr, PREFIX_HEX);
  8110. break;
  8111. }
  8112. putchar ('\n');
  8113. }
  8114. #ifdef BFD64
  8115. /* VMS vs Unix time offset and factor. */
  8116. #define VMS_EPOCH_OFFSET 35067168000000000LL
  8117. #define VMS_GRANULARITY_FACTOR 10000000
  8118. /* Display a VMS time in a human readable format. */
  8119. static void
  8120. print_vms_time (bfd_int64_t vmstime)
  8121. {
  8122. struct tm *tm;
  8123. time_t unxtime;
  8124. unxtime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR;
  8125. tm = gmtime (&unxtime);
  8126. printf ("%04u-%02u-%02uT%02u:%02u:%02u",
  8127. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
  8128. tm->tm_hour, tm->tm_min, tm->tm_sec);
  8129. }
  8130. #endif /* BFD64 */
  8131. static void
  8132. dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
  8133. {
  8134. switch (entry->d_tag)
  8135. {
  8136. case DT_IA_64_PLT_RESERVE:
  8137. /* First 3 slots reserved. */
  8138. print_vma (entry->d_un.d_ptr, PREFIX_HEX);
  8139. printf (" -- ");
  8140. print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
  8141. break;
  8142. case DT_IA_64_VMS_LINKTIME:
  8143. #ifdef BFD64
  8144. print_vms_time (entry->d_un.d_val);
  8145. #endif
  8146. break;
  8147. case DT_IA_64_VMS_LNKFLAGS:
  8148. print_vma (entry->d_un.d_ptr, PREFIX_HEX);
  8149. if (entry->d_un.d_val & VMS_LF_CALL_DEBUG)
  8150. printf (" CALL_DEBUG");
  8151. if (entry->d_un.d_val & VMS_LF_NOP0BUFS)
  8152. printf (" NOP0BUFS");
  8153. if (entry->d_un.d_val & VMS_LF_P0IMAGE)
  8154. printf (" P0IMAGE");
  8155. if (entry->d_un.d_val & VMS_LF_MKTHREADS)
  8156. printf (" MKTHREADS");
  8157. if (entry->d_un.d_val & VMS_LF_UPCALLS)
  8158. printf (" UPCALLS");
  8159. if (entry->d_un.d_val & VMS_LF_IMGSTA)
  8160. printf (" IMGSTA");
  8161. if (entry->d_un.d_val & VMS_LF_INITIALIZE)
  8162. printf (" INITIALIZE");
  8163. if (entry->d_un.d_val & VMS_LF_MAIN)
  8164. printf (" MAIN");
  8165. if (entry->d_un.d_val & VMS_LF_EXE_INIT)
  8166. printf (" EXE_INIT");
  8167. if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG)
  8168. printf (" TBK_IN_IMG");
  8169. if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG)
  8170. printf (" DBG_IN_IMG");
  8171. if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF)
  8172. printf (" TBK_IN_DSF");
  8173. if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF)
  8174. printf (" DBG_IN_DSF");
  8175. if (entry->d_un.d_val & VMS_LF_SIGNATURES)
  8176. printf (" SIGNATURES");
  8177. if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF)
  8178. printf (" REL_SEG_OFF");
  8179. break;
  8180. default:
  8181. print_vma (entry->d_un.d_ptr, PREFIX_HEX);
  8182. break;
  8183. }
  8184. putchar ('\n');
  8185. }
  8186. static bfd_boolean
  8187. get_32bit_dynamic_section (FILE * file)
  8188. {
  8189. Elf32_External_Dyn * edyn;
  8190. Elf32_External_Dyn * ext;
  8191. Elf_Internal_Dyn * entry;
  8192. edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr, 1,
  8193. dynamic_size, _("dynamic section"));
  8194. if (!edyn)
  8195. return FALSE;
  8196. /* SGI's ELF has more than one section in the DYNAMIC segment, and we
  8197. might not have the luxury of section headers. Look for the DT_NULL
  8198. terminator to determine the number of entries. */
  8199. for (ext = edyn, dynamic_nent = 0;
  8200. (char *) (ext + 1) <= (char *) edyn + dynamic_size;
  8201. ext++)
  8202. {
  8203. dynamic_nent++;
  8204. if (BYTE_GET (ext->d_tag) == DT_NULL)
  8205. break;
  8206. }
  8207. dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
  8208. sizeof (* entry));
  8209. if (dynamic_section == NULL)
  8210. {
  8211. error (_("Out of memory allocating space for %lu dynamic entries\n"),
  8212. (unsigned long) dynamic_nent);
  8213. free (edyn);
  8214. return FALSE;
  8215. }
  8216. for (ext = edyn, entry = dynamic_section;
  8217. entry < dynamic_section + dynamic_nent;
  8218. ext++, entry++)
  8219. {
  8220. entry->d_tag = BYTE_GET (ext->d_tag);
  8221. entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
  8222. }
  8223. free (edyn);
  8224. return TRUE;
  8225. }
  8226. static bfd_boolean
  8227. get_64bit_dynamic_section (FILE * file)
  8228. {
  8229. Elf64_External_Dyn * edyn;
  8230. Elf64_External_Dyn * ext;
  8231. Elf_Internal_Dyn * entry;
  8232. /* Read in the data. */
  8233. edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr, 1,
  8234. dynamic_size, _("dynamic section"));
  8235. if (!edyn)
  8236. return FALSE;
  8237. /* SGI's ELF has more than one section in the DYNAMIC segment, and we
  8238. might not have the luxury of section headers. Look for the DT_NULL
  8239. terminator to determine the number of entries. */
  8240. for (ext = edyn, dynamic_nent = 0;
  8241. /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */
  8242. (char *) (ext + 1) <= (char *) edyn + dynamic_size;
  8243. ext++)
  8244. {
  8245. dynamic_nent++;
  8246. if (BYTE_GET (ext->d_tag) == DT_NULL)
  8247. break;
  8248. }
  8249. dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent,
  8250. sizeof (* entry));
  8251. if (dynamic_section == NULL)
  8252. {
  8253. error (_("Out of memory allocating space for %lu dynamic entries\n"),
  8254. (unsigned long) dynamic_nent);
  8255. free (edyn);
  8256. return FALSE;
  8257. }
  8258. /* Convert from external to internal formats. */
  8259. for (ext = edyn, entry = dynamic_section;
  8260. entry < dynamic_section + dynamic_nent;
  8261. ext++, entry++)
  8262. {
  8263. entry->d_tag = BYTE_GET (ext->d_tag);
  8264. entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
  8265. }
  8266. free (edyn);
  8267. return TRUE;
  8268. }
  8269. static void
  8270. print_dynamic_flags (bfd_vma flags)
  8271. {
  8272. bfd_boolean first = TRUE;
  8273. while (flags)
  8274. {
  8275. bfd_vma flag;
  8276. flag = flags & - flags;
  8277. flags &= ~ flag;
  8278. if (first)
  8279. first = FALSE;
  8280. else
  8281. putc (' ', stdout);
  8282. switch (flag)
  8283. {
  8284. case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
  8285. case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
  8286. case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
  8287. case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
  8288. case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
  8289. default: fputs (_("unknown"), stdout); break;
  8290. }
  8291. }
  8292. puts ("");
  8293. }
  8294. /* Parse and display the contents of the dynamic section. */
  8295. static bfd_boolean
  8296. process_dynamic_section (FILE * file)
  8297. {
  8298. Elf_Internal_Dyn * entry;
  8299. if (dynamic_size == 0)
  8300. {
  8301. if (do_dynamic)
  8302. printf (_("\nThere is no dynamic section in this file.\n"));
  8303. return TRUE;
  8304. }
  8305. if (is_32bit_elf)
  8306. {
  8307. if (! get_32bit_dynamic_section (file))
  8308. return FALSE;
  8309. }
  8310. else
  8311. {
  8312. if (! get_64bit_dynamic_section (file))
  8313. return FALSE;
  8314. }
  8315. /* Find the appropriate symbol table. */
  8316. if (dynamic_symbols == NULL)
  8317. {
  8318. for (entry = dynamic_section;
  8319. entry < dynamic_section + dynamic_nent;
  8320. ++entry)
  8321. {
  8322. Elf_Internal_Shdr section;
  8323. if (entry->d_tag != DT_SYMTAB)
  8324. continue;
  8325. dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
  8326. /* Since we do not know how big the symbol table is,
  8327. we default to reading in the entire file (!) and
  8328. processing that. This is overkill, I know, but it
  8329. should work. */
  8330. section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
  8331. if ((bfd_size_type) section.sh_offset > current_file_size)
  8332. {
  8333. /* See PR 21379 for a reproducer. */
  8334. error (_("Invalid DT_SYMTAB entry: %lx"), (long) section.sh_offset);
  8335. return FALSE;
  8336. }
  8337. if (archive_file_offset != 0)
  8338. section.sh_size = archive_file_size - section.sh_offset;
  8339. else
  8340. {
  8341. if (fseek (file, 0, SEEK_END))
  8342. error (_("Unable to seek to end of file!\n"));
  8343. section.sh_size = ftell (file) - section.sh_offset;
  8344. }
  8345. if (is_32bit_elf)
  8346. section.sh_entsize = sizeof (Elf32_External_Sym);
  8347. else
  8348. section.sh_entsize = sizeof (Elf64_External_Sym);
  8349. section.sh_name = string_table_length;
  8350. dynamic_symbols = GET_ELF_SYMBOLS (file, &section, & num_dynamic_syms);
  8351. if (num_dynamic_syms < 1)
  8352. {
  8353. error (_("Unable to determine the number of symbols to load\n"));
  8354. continue;
  8355. }
  8356. }
  8357. }
  8358. /* Similarly find a string table. */
  8359. if (dynamic_strings == NULL)
  8360. {
  8361. for (entry = dynamic_section;
  8362. entry < dynamic_section + dynamic_nent;
  8363. ++entry)
  8364. {
  8365. unsigned long offset;
  8366. long str_tab_len;
  8367. if (entry->d_tag != DT_STRTAB)
  8368. continue;
  8369. dynamic_info[DT_STRTAB] = entry->d_un.d_val;
  8370. /* Since we do not know how big the string table is,
  8371. we default to reading in the entire file (!) and
  8372. processing that. This is overkill, I know, but it
  8373. should work. */
  8374. offset = offset_from_vma (file, entry->d_un.d_val, 0);
  8375. if (archive_file_offset != 0)
  8376. str_tab_len = archive_file_size - offset;
  8377. else
  8378. {
  8379. if (fseek (file, 0, SEEK_END))
  8380. error (_("Unable to seek to end of file\n"));
  8381. str_tab_len = ftell (file) - offset;
  8382. }
  8383. if (str_tab_len < 1)
  8384. {
  8385. error
  8386. (_("Unable to determine the length of the dynamic string table\n"));
  8387. continue;
  8388. }
  8389. dynamic_strings = (char *) get_data (NULL, file, offset, 1,
  8390. str_tab_len,
  8391. _("dynamic string table"));
  8392. dynamic_strings_length = dynamic_strings == NULL ? 0 : str_tab_len;
  8393. break;
  8394. }
  8395. }
  8396. /* And find the syminfo section if available. */
  8397. if (dynamic_syminfo == NULL)
  8398. {
  8399. unsigned long syminsz = 0;
  8400. for (entry = dynamic_section;
  8401. entry < dynamic_section + dynamic_nent;
  8402. ++entry)
  8403. {
  8404. if (entry->d_tag == DT_SYMINENT)
  8405. {
  8406. /* Note: these braces are necessary to avoid a syntax
  8407. error from the SunOS4 C compiler. */
  8408. /* PR binutils/17531: A corrupt file can trigger this test.
  8409. So do not use an assert, instead generate an error message. */
  8410. if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val)
  8411. error (_("Bad value (%d) for SYMINENT entry\n"),
  8412. (int) entry->d_un.d_val);
  8413. }
  8414. else if (entry->d_tag == DT_SYMINSZ)
  8415. syminsz = entry->d_un.d_val;
  8416. else if (entry->d_tag == DT_SYMINFO)
  8417. dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
  8418. syminsz);
  8419. }
  8420. if (dynamic_syminfo_offset != 0 && syminsz != 0)
  8421. {
  8422. Elf_External_Syminfo * extsyminfo;
  8423. Elf_External_Syminfo * extsym;
  8424. Elf_Internal_Syminfo * syminfo;
  8425. /* There is a syminfo section. Read the data. */
  8426. extsyminfo = (Elf_External_Syminfo *)
  8427. get_data (NULL, file, dynamic_syminfo_offset, 1, syminsz,
  8428. _("symbol information"));
  8429. if (!extsyminfo)
  8430. return FALSE;
  8431. dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
  8432. if (dynamic_syminfo == NULL)
  8433. {
  8434. error (_("Out of memory allocating %lu byte for dynamic symbol info\n"),
  8435. (unsigned long) syminsz);
  8436. return FALSE;
  8437. }
  8438. dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
  8439. for (syminfo = dynamic_syminfo, extsym = extsyminfo;
  8440. syminfo < dynamic_syminfo + dynamic_syminfo_nent;
  8441. ++syminfo, ++extsym)
  8442. {
  8443. syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
  8444. syminfo->si_flags = BYTE_GET (extsym->si_flags);
  8445. }
  8446. free (extsyminfo);
  8447. }
  8448. }
  8449. if (do_dynamic && dynamic_addr)
  8450. printf (_("\nDynamic section at offset 0x%lx contains %lu entries:\n"),
  8451. dynamic_addr, (unsigned long) dynamic_nent);
  8452. if (do_dynamic)
  8453. printf (_(" Tag Type Name/Value\n"));
  8454. for (entry = dynamic_section;
  8455. entry < dynamic_section + dynamic_nent;
  8456. entry++)
  8457. {
  8458. if (do_dynamic)
  8459. {
  8460. const char * dtype;
  8461. putchar (' ');
  8462. print_vma (entry->d_tag, FULL_HEX);
  8463. dtype = get_dynamic_type (entry->d_tag);
  8464. printf (" (%s)%*s", dtype,
  8465. ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " ");
  8466. }
  8467. switch (entry->d_tag)
  8468. {
  8469. case DT_FLAGS:
  8470. if (do_dynamic)
  8471. print_dynamic_flags (entry->d_un.d_val);
  8472. break;
  8473. case DT_AUXILIARY:
  8474. case DT_FILTER:
  8475. case DT_CONFIG:
  8476. case DT_DEPAUDIT:
  8477. case DT_AUDIT:
  8478. if (do_dynamic)
  8479. {
  8480. switch (entry->d_tag)
  8481. {
  8482. case DT_AUXILIARY:
  8483. printf (_("Auxiliary library"));
  8484. break;
  8485. case DT_FILTER:
  8486. printf (_("Filter library"));
  8487. break;
  8488. case DT_CONFIG:
  8489. printf (_("Configuration file"));
  8490. break;
  8491. case DT_DEPAUDIT:
  8492. printf (_("Dependency audit library"));
  8493. break;
  8494. case DT_AUDIT:
  8495. printf (_("Audit library"));
  8496. break;
  8497. }
  8498. if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
  8499. printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
  8500. else
  8501. {
  8502. printf (": ");
  8503. print_vma (entry->d_un.d_val, PREFIX_HEX);
  8504. putchar ('\n');
  8505. }
  8506. }
  8507. break;
  8508. case DT_FEATURE:
  8509. if (do_dynamic)
  8510. {
  8511. printf (_("Flags:"));
  8512. if (entry->d_un.d_val == 0)
  8513. printf (_(" None\n"));
  8514. else
  8515. {
  8516. unsigned long int val = entry->d_un.d_val;
  8517. if (val & DTF_1_PARINIT)
  8518. {
  8519. printf (" PARINIT");
  8520. val ^= DTF_1_PARINIT;
  8521. }
  8522. if (val & DTF_1_CONFEXP)
  8523. {
  8524. printf (" CONFEXP");
  8525. val ^= DTF_1_CONFEXP;
  8526. }
  8527. if (val != 0)
  8528. printf (" %lx", val);
  8529. puts ("");
  8530. }
  8531. }
  8532. break;
  8533. case DT_POSFLAG_1:
  8534. if (do_dynamic)
  8535. {
  8536. printf (_("Flags:"));
  8537. if (entry->d_un.d_val == 0)
  8538. printf (_(" None\n"));
  8539. else
  8540. {
  8541. unsigned long int val = entry->d_un.d_val;
  8542. if (val & DF_P1_LAZYLOAD)
  8543. {
  8544. printf (" LAZYLOAD");
  8545. val ^= DF_P1_LAZYLOAD;
  8546. }
  8547. if (val & DF_P1_GROUPPERM)
  8548. {
  8549. printf (" GROUPPERM");
  8550. val ^= DF_P1_GROUPPERM;
  8551. }
  8552. if (val != 0)
  8553. printf (" %lx", val);
  8554. puts ("");
  8555. }
  8556. }
  8557. break;
  8558. case DT_FLAGS_1:
  8559. if (do_dynamic)
  8560. {
  8561. printf (_("Flags:"));
  8562. if (entry->d_un.d_val == 0)
  8563. printf (_(" None\n"));
  8564. else
  8565. {
  8566. unsigned long int val = entry->d_un.d_val;
  8567. if (val & DF_1_NOW)
  8568. {
  8569. printf (" NOW");
  8570. val ^= DF_1_NOW;
  8571. }
  8572. if (val & DF_1_GLOBAL)
  8573. {
  8574. printf (" GLOBAL");
  8575. val ^= DF_1_GLOBAL;
  8576. }
  8577. if (val & DF_1_GROUP)
  8578. {
  8579. printf (" GROUP");
  8580. val ^= DF_1_GROUP;
  8581. }
  8582. if (val & DF_1_NODELETE)
  8583. {
  8584. printf (" NODELETE");
  8585. val ^= DF_1_NODELETE;
  8586. }
  8587. if (val & DF_1_LOADFLTR)
  8588. {
  8589. printf (" LOADFLTR");
  8590. val ^= DF_1_LOADFLTR;
  8591. }
  8592. if (val & DF_1_INITFIRST)
  8593. {
  8594. printf (" INITFIRST");
  8595. val ^= DF_1_INITFIRST;
  8596. }
  8597. if (val & DF_1_NOOPEN)
  8598. {
  8599. printf (" NOOPEN");
  8600. val ^= DF_1_NOOPEN;
  8601. }
  8602. if (val & DF_1_ORIGIN)
  8603. {
  8604. printf (" ORIGIN");
  8605. val ^= DF_1_ORIGIN;
  8606. }
  8607. if (val & DF_1_DIRECT)
  8608. {
  8609. printf (" DIRECT");
  8610. val ^= DF_1_DIRECT;
  8611. }
  8612. if (val & DF_1_TRANS)
  8613. {
  8614. printf (" TRANS");
  8615. val ^= DF_1_TRANS;
  8616. }
  8617. if (val & DF_1_INTERPOSE)
  8618. {
  8619. printf (" INTERPOSE");
  8620. val ^= DF_1_INTERPOSE;
  8621. }
  8622. if (val & DF_1_NODEFLIB)
  8623. {
  8624. printf (" NODEFLIB");
  8625. val ^= DF_1_NODEFLIB;
  8626. }
  8627. if (val & DF_1_NODUMP)
  8628. {
  8629. printf (" NODUMP");
  8630. val ^= DF_1_NODUMP;
  8631. }
  8632. if (val & DF_1_CONFALT)
  8633. {
  8634. printf (" CONFALT");
  8635. val ^= DF_1_CONFALT;
  8636. }
  8637. if (val & DF_1_ENDFILTEE)
  8638. {
  8639. printf (" ENDFILTEE");
  8640. val ^= DF_1_ENDFILTEE;
  8641. }
  8642. if (val & DF_1_DISPRELDNE)
  8643. {
  8644. printf (" DISPRELDNE");
  8645. val ^= DF_1_DISPRELDNE;
  8646. }
  8647. if (val & DF_1_DISPRELPND)
  8648. {
  8649. printf (" DISPRELPND");
  8650. val ^= DF_1_DISPRELPND;
  8651. }
  8652. if (val & DF_1_NODIRECT)
  8653. {
  8654. printf (" NODIRECT");
  8655. val ^= DF_1_NODIRECT;
  8656. }
  8657. if (val & DF_1_IGNMULDEF)
  8658. {
  8659. printf (" IGNMULDEF");
  8660. val ^= DF_1_IGNMULDEF;
  8661. }
  8662. if (val & DF_1_NOKSYMS)
  8663. {
  8664. printf (" NOKSYMS");
  8665. val ^= DF_1_NOKSYMS;
  8666. }
  8667. if (val & DF_1_NOHDR)
  8668. {
  8669. printf (" NOHDR");
  8670. val ^= DF_1_NOHDR;
  8671. }
  8672. if (val & DF_1_EDITED)
  8673. {
  8674. printf (" EDITED");
  8675. val ^= DF_1_EDITED;
  8676. }
  8677. if (val & DF_1_NORELOC)
  8678. {
  8679. printf (" NORELOC");
  8680. val ^= DF_1_NORELOC;
  8681. }
  8682. if (val & DF_1_SYMINTPOSE)
  8683. {
  8684. printf (" SYMINTPOSE");
  8685. val ^= DF_1_SYMINTPOSE;
  8686. }
  8687. if (val & DF_1_GLOBAUDIT)
  8688. {
  8689. printf (" GLOBAUDIT");
  8690. val ^= DF_1_GLOBAUDIT;
  8691. }
  8692. if (val & DF_1_SINGLETON)
  8693. {
  8694. printf (" SINGLETON");
  8695. val ^= DF_1_SINGLETON;
  8696. }
  8697. if (val & DF_1_STUB)
  8698. {
  8699. printf (" STUB");
  8700. val ^= DF_1_STUB;
  8701. }
  8702. if (val & DF_1_PIE)
  8703. {
  8704. printf (" PIE");
  8705. val ^= DF_1_PIE;
  8706. }
  8707. if (val != 0)
  8708. printf (" %lx", val);
  8709. puts ("");
  8710. }
  8711. }
  8712. break;
  8713. case DT_PLTREL:
  8714. dynamic_info[entry->d_tag] = entry->d_un.d_val;
  8715. if (do_dynamic)
  8716. puts (get_dynamic_type (entry->d_un.d_val));
  8717. break;
  8718. case DT_NULL :
  8719. case DT_NEEDED :
  8720. case DT_PLTGOT :
  8721. case DT_HASH :
  8722. case DT_STRTAB :
  8723. case DT_SYMTAB :
  8724. case DT_RELA :
  8725. case DT_INIT :
  8726. case DT_FINI :
  8727. case DT_SONAME :
  8728. case DT_RPATH :
  8729. case DT_SYMBOLIC:
  8730. case DT_REL :
  8731. case DT_DEBUG :
  8732. case DT_TEXTREL :
  8733. case DT_JMPREL :
  8734. case DT_RUNPATH :
  8735. dynamic_info[entry->d_tag] = entry->d_un.d_val;
  8736. if (do_dynamic)
  8737. {
  8738. char * name;
  8739. if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
  8740. name = GET_DYNAMIC_NAME (entry->d_un.d_val);
  8741. else
  8742. name = NULL;
  8743. if (name)
  8744. {
  8745. switch (entry->d_tag)
  8746. {
  8747. case DT_NEEDED:
  8748. printf (_("Shared library: [%s]"), name);
  8749. if (streq (name, program_interpreter))
  8750. printf (_(" program interpreter"));
  8751. break;
  8752. case DT_SONAME:
  8753. printf (_("Library soname: [%s]"), name);
  8754. break;
  8755. case DT_RPATH:
  8756. printf (_("Library rpath: [%s]"), name);
  8757. break;
  8758. case DT_RUNPATH:
  8759. printf (_("Library runpath: [%s]"), name);
  8760. break;
  8761. default:
  8762. print_vma (entry->d_un.d_val, PREFIX_HEX);
  8763. break;
  8764. }
  8765. }
  8766. else
  8767. print_vma (entry->d_un.d_val, PREFIX_HEX);
  8768. putchar ('\n');
  8769. }
  8770. break;
  8771. case DT_PLTRELSZ:
  8772. case DT_RELASZ :
  8773. case DT_STRSZ :
  8774. case DT_RELSZ :
  8775. case DT_RELAENT :
  8776. case DT_SYMENT :
  8777. case DT_RELENT :
  8778. dynamic_info[entry->d_tag] = entry->d_un.d_val;
  8779. /* Fall through. */
  8780. case DT_PLTPADSZ:
  8781. case DT_MOVEENT :
  8782. case DT_MOVESZ :
  8783. case DT_INIT_ARRAYSZ:
  8784. case DT_FINI_ARRAYSZ:
  8785. case DT_GNU_CONFLICTSZ:
  8786. case DT_GNU_LIBLISTSZ:
  8787. if (do_dynamic)
  8788. {
  8789. print_vma (entry->d_un.d_val, UNSIGNED);
  8790. printf (_(" (bytes)\n"));
  8791. }
  8792. break;
  8793. case DT_VERDEFNUM:
  8794. case DT_VERNEEDNUM:
  8795. case DT_RELACOUNT:
  8796. case DT_RELCOUNT:
  8797. if (do_dynamic)
  8798. {
  8799. print_vma (entry->d_un.d_val, UNSIGNED);
  8800. putchar ('\n');
  8801. }
  8802. break;
  8803. case DT_SYMINSZ:
  8804. case DT_SYMINENT:
  8805. case DT_SYMINFO:
  8806. case DT_USED:
  8807. case DT_INIT_ARRAY:
  8808. case DT_FINI_ARRAY:
  8809. if (do_dynamic)
  8810. {
  8811. if (entry->d_tag == DT_USED
  8812. && VALID_DYNAMIC_NAME (entry->d_un.d_val))
  8813. {
  8814. char * name = GET_DYNAMIC_NAME (entry->d_un.d_val);
  8815. if (*name)
  8816. {
  8817. printf (_("Not needed object: [%s]\n"), name);
  8818. break;
  8819. }
  8820. }
  8821. print_vma (entry->d_un.d_val, PREFIX_HEX);
  8822. putchar ('\n');
  8823. }
  8824. break;
  8825. case DT_BIND_NOW:
  8826. /* The value of this entry is ignored. */
  8827. if (do_dynamic)
  8828. putchar ('\n');
  8829. break;
  8830. case DT_GNU_PRELINKED:
  8831. if (do_dynamic)
  8832. {
  8833. struct tm * tmp;
  8834. time_t atime = entry->d_un.d_val;
  8835. tmp = gmtime (&atime);
  8836. /* PR 17533 file: 041-1244816-0.004. */
  8837. if (tmp == NULL)
  8838. printf (_("<corrupt time val: %lx"),
  8839. (unsigned long) atime);
  8840. else
  8841. printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
  8842. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  8843. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  8844. }
  8845. break;
  8846. case DT_GNU_HASH:
  8847. dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
  8848. if (do_dynamic)
  8849. {
  8850. print_vma (entry->d_un.d_val, PREFIX_HEX);
  8851. putchar ('\n');
  8852. }
  8853. break;
  8854. default:
  8855. if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
  8856. version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
  8857. entry->d_un.d_val;
  8858. if (do_dynamic)
  8859. {
  8860. switch (elf_header.e_machine)
  8861. {
  8862. case EM_MIPS:
  8863. case EM_MIPS_RS3_LE:
  8864. dynamic_section_mips_val (entry);
  8865. break;
  8866. case EM_PARISC:
  8867. dynamic_section_parisc_val (entry);
  8868. break;
  8869. case EM_IA_64:
  8870. dynamic_section_ia64_val (entry);
  8871. break;
  8872. default:
  8873. print_vma (entry->d_un.d_val, PREFIX_HEX);
  8874. putchar ('\n');
  8875. }
  8876. }
  8877. break;
  8878. }
  8879. }
  8880. return TRUE;
  8881. }
  8882. static char *
  8883. get_ver_flags (unsigned int flags)
  8884. {
  8885. static char buff[32];
  8886. buff[0] = 0;
  8887. if (flags == 0)
  8888. return _("none");
  8889. if (flags & VER_FLG_BASE)
  8890. strcat (buff, "BASE");
  8891. if (flags & VER_FLG_WEAK)
  8892. {
  8893. if (flags & VER_FLG_BASE)
  8894. strcat (buff, " | ");
  8895. strcat (buff, "WEAK");
  8896. }
  8897. if (flags & VER_FLG_INFO)
  8898. {
  8899. if (flags & (VER_FLG_BASE|VER_FLG_WEAK))
  8900. strcat (buff, " | ");
  8901. strcat (buff, "INFO");
  8902. }
  8903. if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
  8904. {
  8905. if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO))
  8906. strcat (buff, " | ");
  8907. strcat (buff, _("<unknown>"));
  8908. }
  8909. return buff;
  8910. }
  8911. /* Display the contents of the version sections. */
  8912. static bfd_boolean
  8913. process_version_sections (FILE * file)
  8914. {
  8915. Elf_Internal_Shdr * section;
  8916. unsigned i;
  8917. bfd_boolean found = FALSE;
  8918. if (! do_version)
  8919. return TRUE;
  8920. for (i = 0, section = section_headers;
  8921. i < elf_header.e_shnum;
  8922. i++, section++)
  8923. {
  8924. switch (section->sh_type)
  8925. {
  8926. case SHT_GNU_verdef:
  8927. {
  8928. Elf_External_Verdef * edefs;
  8929. unsigned long idx;
  8930. unsigned long cnt;
  8931. char * endbuf;
  8932. found = TRUE;
  8933. printf (_("\nVersion definition section '%s' contains %u entries:\n"),
  8934. printable_section_name (section),
  8935. section->sh_info);
  8936. printf (_(" Addr: 0x"));
  8937. printf_vma (section->sh_addr);
  8938. printf (_(" Offset: %#08lx Link: %u (%s)\n"),
  8939. (unsigned long) section->sh_offset, section->sh_link,
  8940. printable_section_name_from_index (section->sh_link));
  8941. edefs = (Elf_External_Verdef *)
  8942. get_data (NULL, file, section->sh_offset, 1,section->sh_size,
  8943. _("version definition section"));
  8944. if (!edefs)
  8945. break;
  8946. endbuf = (char *) edefs + section->sh_size;
  8947. for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
  8948. {
  8949. char * vstart;
  8950. Elf_External_Verdef * edef;
  8951. Elf_Internal_Verdef ent;
  8952. Elf_External_Verdaux * eaux;
  8953. Elf_Internal_Verdaux aux;
  8954. unsigned long isum;
  8955. int j;
  8956. vstart = ((char *) edefs) + idx;
  8957. if (vstart + sizeof (*edef) > endbuf)
  8958. break;
  8959. edef = (Elf_External_Verdef *) vstart;
  8960. ent.vd_version = BYTE_GET (edef->vd_version);
  8961. ent.vd_flags = BYTE_GET (edef->vd_flags);
  8962. ent.vd_ndx = BYTE_GET (edef->vd_ndx);
  8963. ent.vd_cnt = BYTE_GET (edef->vd_cnt);
  8964. ent.vd_hash = BYTE_GET (edef->vd_hash);
  8965. ent.vd_aux = BYTE_GET (edef->vd_aux);
  8966. ent.vd_next = BYTE_GET (edef->vd_next);
  8967. printf (_(" %#06lx: Rev: %d Flags: %s"),
  8968. idx, ent.vd_version, get_ver_flags (ent.vd_flags));
  8969. printf (_(" Index: %d Cnt: %d "),
  8970. ent.vd_ndx, ent.vd_cnt);
  8971. /* Check for overflow. */
  8972. if (ent.vd_aux > (size_t) (endbuf - vstart))
  8973. break;
  8974. vstart += ent.vd_aux;
  8975. if (vstart + sizeof (*eaux) > endbuf)
  8976. break;
  8977. eaux = (Elf_External_Verdaux *) vstart;
  8978. aux.vda_name = BYTE_GET (eaux->vda_name);
  8979. aux.vda_next = BYTE_GET (eaux->vda_next);
  8980. if (VALID_DYNAMIC_NAME (aux.vda_name))
  8981. printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
  8982. else
  8983. printf (_("Name index: %ld\n"), aux.vda_name);
  8984. isum = idx + ent.vd_aux;
  8985. for (j = 1; j < ent.vd_cnt; j++)
  8986. {
  8987. if (aux.vda_next < sizeof (*eaux)
  8988. && !(j == ent.vd_cnt - 1 && aux.vda_next == 0))
  8989. {
  8990. warn (_("Invalid vda_next field of %lx\n"),
  8991. aux.vda_next);
  8992. j = ent.vd_cnt;
  8993. break;
  8994. }
  8995. /* Check for overflow. */
  8996. if (aux.vda_next > (size_t) (endbuf - vstart))
  8997. break;
  8998. isum += aux.vda_next;
  8999. vstart += aux.vda_next;
  9000. if (vstart + sizeof (*eaux) > endbuf)
  9001. break;
  9002. eaux = (Elf_External_Verdaux *) vstart;
  9003. aux.vda_name = BYTE_GET (eaux->vda_name);
  9004. aux.vda_next = BYTE_GET (eaux->vda_next);
  9005. if (VALID_DYNAMIC_NAME (aux.vda_name))
  9006. printf (_(" %#06lx: Parent %d: %s\n"),
  9007. isum, j, GET_DYNAMIC_NAME (aux.vda_name));
  9008. else
  9009. printf (_(" %#06lx: Parent %d, name index: %ld\n"),
  9010. isum, j, aux.vda_name);
  9011. }
  9012. if (j < ent.vd_cnt)
  9013. printf (_(" Version def aux past end of section\n"));
  9014. /* PR 17531:
  9015. file: id:000001,src:000172+005151,op:splice,rep:2. */
  9016. if (ent.vd_next < sizeof (*edef)
  9017. && !(cnt == section->sh_info - 1 && ent.vd_next == 0))
  9018. {
  9019. warn (_("Invalid vd_next field of %lx\n"), ent.vd_next);
  9020. cnt = section->sh_info;
  9021. break;
  9022. }
  9023. if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx)))
  9024. break;
  9025. idx += ent.vd_next;
  9026. }
  9027. if (cnt < section->sh_info)
  9028. printf (_(" Version definition past end of section\n"));
  9029. free (edefs);
  9030. }
  9031. break;
  9032. case SHT_GNU_verneed:
  9033. {
  9034. Elf_External_Verneed * eneed;
  9035. unsigned long idx;
  9036. unsigned long cnt;
  9037. char * endbuf;
  9038. found = TRUE;
  9039. printf (_("\nVersion needs section '%s' contains %u entries:\n"),
  9040. printable_section_name (section), section->sh_info);
  9041. printf (_(" Addr: 0x"));
  9042. printf_vma (section->sh_addr);
  9043. printf (_(" Offset: %#08lx Link: %u (%s)\n"),
  9044. (unsigned long) section->sh_offset, section->sh_link,
  9045. printable_section_name_from_index (section->sh_link));
  9046. eneed = (Elf_External_Verneed *) get_data (NULL, file,
  9047. section->sh_offset, 1,
  9048. section->sh_size,
  9049. _("Version Needs section"));
  9050. if (!eneed)
  9051. break;
  9052. endbuf = (char *) eneed + section->sh_size;
  9053. for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
  9054. {
  9055. Elf_External_Verneed * entry;
  9056. Elf_Internal_Verneed ent;
  9057. unsigned long isum;
  9058. int j;
  9059. char * vstart;
  9060. vstart = ((char *) eneed) + idx;
  9061. if (vstart + sizeof (*entry) > endbuf)
  9062. break;
  9063. entry = (Elf_External_Verneed *) vstart;
  9064. ent.vn_version = BYTE_GET (entry->vn_version);
  9065. ent.vn_cnt = BYTE_GET (entry->vn_cnt);
  9066. ent.vn_file = BYTE_GET (entry->vn_file);
  9067. ent.vn_aux = BYTE_GET (entry->vn_aux);
  9068. ent.vn_next = BYTE_GET (entry->vn_next);
  9069. printf (_(" %#06lx: Version: %d"), idx, ent.vn_version);
  9070. if (VALID_DYNAMIC_NAME (ent.vn_file))
  9071. printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
  9072. else
  9073. printf (_(" File: %lx"), ent.vn_file);
  9074. printf (_(" Cnt: %d\n"), ent.vn_cnt);
  9075. /* Check for overflow. */
  9076. if (ent.vn_aux > (size_t) (endbuf - vstart))
  9077. break;
  9078. vstart += ent.vn_aux;
  9079. for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
  9080. {
  9081. Elf_External_Vernaux * eaux;
  9082. Elf_Internal_Vernaux aux;
  9083. if (vstart + sizeof (*eaux) > endbuf)
  9084. break;
  9085. eaux = (Elf_External_Vernaux *) vstart;
  9086. aux.vna_hash = BYTE_GET (eaux->vna_hash);
  9087. aux.vna_flags = BYTE_GET (eaux->vna_flags);
  9088. aux.vna_other = BYTE_GET (eaux->vna_other);
  9089. aux.vna_name = BYTE_GET (eaux->vna_name);
  9090. aux.vna_next = BYTE_GET (eaux->vna_next);
  9091. if (VALID_DYNAMIC_NAME (aux.vna_name))
  9092. printf (_(" %#06lx: Name: %s"),
  9093. isum, GET_DYNAMIC_NAME (aux.vna_name));
  9094. else
  9095. printf (_(" %#06lx: Name index: %lx"),
  9096. isum, aux.vna_name);
  9097. printf (_(" Flags: %s Version: %d\n"),
  9098. get_ver_flags (aux.vna_flags), aux.vna_other);
  9099. if (aux.vna_next < sizeof (*eaux)
  9100. && !(j == ent.vn_cnt - 1 && aux.vna_next == 0))
  9101. {
  9102. warn (_("Invalid vna_next field of %lx\n"),
  9103. aux.vna_next);
  9104. j = ent.vn_cnt;
  9105. break;
  9106. }
  9107. /* Check for overflow. */
  9108. if (aux.vna_next > (size_t) (endbuf - vstart))
  9109. break;
  9110. isum += aux.vna_next;
  9111. vstart += aux.vna_next;
  9112. }
  9113. if (j < ent.vn_cnt)
  9114. warn (_("Missing Version Needs auxillary information\n"));
  9115. if (ent.vn_next < sizeof (*entry)
  9116. && !(cnt == section->sh_info - 1 && ent.vn_next == 0))
  9117. {
  9118. warn (_("Invalid vn_next field of %lx\n"), ent.vn_next);
  9119. cnt = section->sh_info;
  9120. break;
  9121. }
  9122. if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx)))
  9123. break;
  9124. idx += ent.vn_next;
  9125. }
  9126. if (cnt < section->sh_info)
  9127. warn (_("Missing Version Needs information\n"));
  9128. free (eneed);
  9129. }
  9130. break;
  9131. case SHT_GNU_versym:
  9132. {
  9133. Elf_Internal_Shdr * link_section;
  9134. size_t total;
  9135. unsigned int cnt;
  9136. unsigned char * edata;
  9137. unsigned short * data;
  9138. char * strtab;
  9139. Elf_Internal_Sym * symbols;
  9140. Elf_Internal_Shdr * string_sec;
  9141. unsigned long num_syms;
  9142. long off;
  9143. if (section->sh_link >= elf_header.e_shnum)
  9144. break;
  9145. link_section = section_headers + section->sh_link;
  9146. total = section->sh_size / sizeof (Elf_External_Versym);
  9147. if (link_section->sh_link >= elf_header.e_shnum)
  9148. break;
  9149. found = TRUE;
  9150. symbols = GET_ELF_SYMBOLS (file, link_section, & num_syms);
  9151. if (symbols == NULL)
  9152. break;
  9153. string_sec = section_headers + link_section->sh_link;
  9154. strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1,
  9155. string_sec->sh_size,
  9156. _("version string table"));
  9157. if (!strtab)
  9158. {
  9159. free (symbols);
  9160. break;
  9161. }
  9162. printf (_("\nVersion symbols section '%s' contains %lu entries:\n"),
  9163. printable_section_name (section), (unsigned long) total);
  9164. printf (_(" Addr: "));
  9165. printf_vma (section->sh_addr);
  9166. printf (_(" Offset: %#08lx Link: %u (%s)\n"),
  9167. (unsigned long) section->sh_offset, section->sh_link,
  9168. printable_section_name (link_section));
  9169. off = offset_from_vma (file,
  9170. version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
  9171. total * sizeof (short));
  9172. edata = (unsigned char *) get_data (NULL, file, off, total,
  9173. sizeof (short),
  9174. _("version symbol data"));
  9175. if (!edata)
  9176. {
  9177. free (strtab);
  9178. free (symbols);
  9179. break;
  9180. }
  9181. data = (short unsigned int *) cmalloc (total, sizeof (short));
  9182. for (cnt = total; cnt --;)
  9183. data[cnt] = byte_get (edata + cnt * sizeof (short),
  9184. sizeof (short));
  9185. free (edata);
  9186. for (cnt = 0; cnt < total; cnt += 4)
  9187. {
  9188. int j, nn;
  9189. char *name;
  9190. char *invalid = _("*invalid*");
  9191. printf (" %03x:", cnt);
  9192. for (j = 0; (j < 4) && (cnt + j) < total; ++j)
  9193. switch (data[cnt + j])
  9194. {
  9195. case 0:
  9196. fputs (_(" 0 (*local*) "), stdout);
  9197. break;
  9198. case 1:
  9199. fputs (_(" 1 (*global*) "), stdout);
  9200. break;
  9201. default:
  9202. nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
  9203. data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
  9204. /* If this index value is greater than the size of the symbols
  9205. array, break to avoid an out-of-bounds read. */
  9206. if ((unsigned long)(cnt + j) >= num_syms)
  9207. {
  9208. warn (_("invalid index into symbol array\n"));
  9209. break;
  9210. }
  9211. name = NULL;
  9212. if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
  9213. {
  9214. Elf_Internal_Verneed ivn;
  9215. unsigned long offset;
  9216. offset = offset_from_vma
  9217. (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
  9218. sizeof (Elf_External_Verneed));
  9219. do
  9220. {
  9221. Elf_Internal_Vernaux ivna;
  9222. Elf_External_Verneed evn;
  9223. Elf_External_Vernaux evna;
  9224. unsigned long a_off;
  9225. if (get_data (&evn, file, offset, sizeof (evn), 1,
  9226. _("version need")) == NULL)
  9227. break;
  9228. ivn.vn_aux = BYTE_GET (evn.vn_aux);
  9229. ivn.vn_next = BYTE_GET (evn.vn_next);
  9230. a_off = offset + ivn.vn_aux;
  9231. do
  9232. {
  9233. if (get_data (&evna, file, a_off, sizeof (evna),
  9234. 1, _("version need aux (2)")) == NULL)
  9235. {
  9236. ivna.vna_next = 0;
  9237. ivna.vna_other = 0;
  9238. }
  9239. else
  9240. {
  9241. ivna.vna_next = BYTE_GET (evna.vna_next);
  9242. ivna.vna_other = BYTE_GET (evna.vna_other);
  9243. }
  9244. a_off += ivna.vna_next;
  9245. }
  9246. while (ivna.vna_other != data[cnt + j]
  9247. && ivna.vna_next != 0);
  9248. if (ivna.vna_other == data[cnt + j])
  9249. {
  9250. ivna.vna_name = BYTE_GET (evna.vna_name);
  9251. if (ivna.vna_name >= string_sec->sh_size)
  9252. name = invalid;
  9253. else
  9254. name = strtab + ivna.vna_name;
  9255. break;
  9256. }
  9257. offset += ivn.vn_next;
  9258. }
  9259. while (ivn.vn_next);
  9260. }
  9261. if (data[cnt + j] != 0x8001
  9262. && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
  9263. {
  9264. Elf_Internal_Verdef ivd;
  9265. Elf_External_Verdef evd;
  9266. unsigned long offset;
  9267. offset = offset_from_vma
  9268. (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
  9269. sizeof evd);
  9270. do
  9271. {
  9272. if (get_data (&evd, file, offset, sizeof (evd), 1,
  9273. _("version def")) == NULL)
  9274. {
  9275. ivd.vd_next = 0;
  9276. /* PR 17531: file: 046-1082287-0.004. */
  9277. ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1;
  9278. break;
  9279. }
  9280. else
  9281. {
  9282. ivd.vd_next = BYTE_GET (evd.vd_next);
  9283. ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
  9284. }
  9285. offset += ivd.vd_next;
  9286. }
  9287. while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
  9288. && ivd.vd_next != 0);
  9289. if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
  9290. {
  9291. Elf_External_Verdaux evda;
  9292. Elf_Internal_Verdaux ivda;
  9293. ivd.vd_aux = BYTE_GET (evd.vd_aux);
  9294. if (get_data (&evda, file,
  9295. offset - ivd.vd_next + ivd.vd_aux,
  9296. sizeof (evda), 1,
  9297. _("version def aux")) == NULL)
  9298. break;
  9299. ivda.vda_name = BYTE_GET (evda.vda_name);
  9300. if (ivda.vda_name >= string_sec->sh_size)
  9301. name = invalid;
  9302. else if (name != NULL && name != invalid)
  9303. name = _("*both*");
  9304. else
  9305. name = strtab + ivda.vda_name;
  9306. }
  9307. }
  9308. if (name != NULL)
  9309. nn += printf ("(%s%-*s",
  9310. name,
  9311. 12 - (int) strlen (name),
  9312. ")");
  9313. if (nn < 18)
  9314. printf ("%*c", 18 - nn, ' ');
  9315. }
  9316. putchar ('\n');
  9317. }
  9318. free (data);
  9319. free (strtab);
  9320. free (symbols);
  9321. }
  9322. break;
  9323. default:
  9324. break;
  9325. }
  9326. }
  9327. if (! found)
  9328. printf (_("\nNo version information found in this file.\n"));
  9329. return TRUE;
  9330. }
  9331. static const char *
  9332. get_symbol_binding (unsigned int binding)
  9333. {
  9334. static char buff[32];
  9335. switch (binding)
  9336. {
  9337. case STB_LOCAL: return "LOCAL";
  9338. case STB_GLOBAL: return "GLOBAL";
  9339. case STB_WEAK: return "WEAK";
  9340. default:
  9341. if (binding >= STB_LOPROC && binding <= STB_HIPROC)
  9342. snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
  9343. binding);
  9344. else if (binding >= STB_LOOS && binding <= STB_HIOS)
  9345. {
  9346. if (binding == STB_GNU_UNIQUE
  9347. && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU
  9348. /* GNU is still using the default value 0. */
  9349. || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
  9350. return "UNIQUE";
  9351. snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
  9352. }
  9353. else
  9354. snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
  9355. return buff;
  9356. }
  9357. }
  9358. static const char *
  9359. get_symbol_type (unsigned int type)
  9360. {
  9361. static char buff[32];
  9362. switch (type)
  9363. {
  9364. case STT_NOTYPE: return "NOTYPE";
  9365. case STT_OBJECT: return "OBJECT";
  9366. case STT_FUNC: return "FUNC";
  9367. case STT_SECTION: return "SECTION";
  9368. case STT_FILE: return "FILE";
  9369. case STT_COMMON: return "COMMON";
  9370. case STT_TLS: return "TLS";
  9371. case STT_RELC: return "RELC";
  9372. case STT_SRELC: return "SRELC";
  9373. default:
  9374. if (type >= STT_LOPROC && type <= STT_HIPROC)
  9375. {
  9376. if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
  9377. return "THUMB_FUNC";
  9378. if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
  9379. return "REGISTER";
  9380. if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
  9381. return "PARISC_MILLI";
  9382. snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
  9383. }
  9384. else if (type >= STT_LOOS && type <= STT_HIOS)
  9385. {
  9386. if (elf_header.e_machine == EM_PARISC)
  9387. {
  9388. if (type == STT_HP_OPAQUE)
  9389. return "HP_OPAQUE";
  9390. if (type == STT_HP_STUB)
  9391. return "HP_STUB";
  9392. }
  9393. if (type == STT_GNU_IFUNC
  9394. && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU
  9395. || elf_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD
  9396. /* GNU is still using the default value 0. */
  9397. || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE))
  9398. return "IFUNC";
  9399. snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
  9400. }
  9401. else
  9402. snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
  9403. return buff;
  9404. }
  9405. }
  9406. static const char *
  9407. get_symbol_visibility (unsigned int visibility)
  9408. {
  9409. switch (visibility)
  9410. {
  9411. case STV_DEFAULT: return "DEFAULT";
  9412. case STV_INTERNAL: return "INTERNAL";
  9413. case STV_HIDDEN: return "HIDDEN";
  9414. case STV_PROTECTED: return "PROTECTED";
  9415. default:
  9416. error (_("Unrecognized visibility value: %u"), visibility);
  9417. return _("<unknown>");
  9418. }
  9419. }
  9420. static const char *
  9421. get_solaris_symbol_visibility (unsigned int visibility)
  9422. {
  9423. switch (visibility)
  9424. {
  9425. case 4: return "EXPORTED";
  9426. case 5: return "SINGLETON";
  9427. case 6: return "ELIMINATE";
  9428. default: return get_symbol_visibility (visibility);
  9429. }
  9430. }
  9431. static const char *
  9432. get_mips_symbol_other (unsigned int other)
  9433. {
  9434. switch (other)
  9435. {
  9436. case STO_OPTIONAL: return "OPTIONAL";
  9437. case STO_MIPS_PLT: return "MIPS PLT";
  9438. case STO_MIPS_PIC: return "MIPS PIC";
  9439. case STO_MICROMIPS: return "MICROMIPS";
  9440. case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC";
  9441. case STO_MIPS16: return "MIPS16";
  9442. default: return NULL;
  9443. }
  9444. }
  9445. static const char *
  9446. get_ia64_symbol_other (unsigned int other)
  9447. {
  9448. if (is_ia64_vms ())
  9449. {
  9450. static char res[32];
  9451. res[0] = 0;
  9452. /* Function types is for images and .STB files only. */
  9453. switch (elf_header.e_type)
  9454. {
  9455. case ET_DYN:
  9456. case ET_EXEC:
  9457. switch (VMS_ST_FUNC_TYPE (other))
  9458. {
  9459. case VMS_SFT_CODE_ADDR:
  9460. strcat (res, " CA");
  9461. break;
  9462. case VMS_SFT_SYMV_IDX:
  9463. strcat (res, " VEC");
  9464. break;
  9465. case VMS_SFT_FD:
  9466. strcat (res, " FD");
  9467. break;
  9468. case VMS_SFT_RESERVE:
  9469. strcat (res, " RSV");
  9470. break;
  9471. default:
  9472. warn (_("Unrecognized IA64 VMS ST Function type: %d\n"),
  9473. VMS_ST_FUNC_TYPE (other));
  9474. strcat (res, " <unknown>");
  9475. break;
  9476. }
  9477. break;
  9478. default:
  9479. break;
  9480. }
  9481. switch (VMS_ST_LINKAGE (other))
  9482. {
  9483. case VMS_STL_IGNORE:
  9484. strcat (res, " IGN");
  9485. break;
  9486. case VMS_STL_RESERVE:
  9487. strcat (res, " RSV");
  9488. break;
  9489. case VMS_STL_STD:
  9490. strcat (res, " STD");
  9491. break;
  9492. case VMS_STL_LNK:
  9493. strcat (res, " LNK");
  9494. break;
  9495. default:
  9496. warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"),
  9497. VMS_ST_LINKAGE (other));
  9498. strcat (res, " <unknown>");
  9499. break;
  9500. }
  9501. if (res[0] != 0)
  9502. return res + 1;
  9503. else
  9504. return res;
  9505. }
  9506. return NULL;
  9507. }
  9508. static const char *
  9509. get_ppc64_symbol_other (unsigned int other)
  9510. {
  9511. if (PPC64_LOCAL_ENTRY_OFFSET (other) != 0)
  9512. {
  9513. static char buf[32];
  9514. snprintf (buf, sizeof buf, _("<localentry>: %d"),
  9515. PPC64_LOCAL_ENTRY_OFFSET (other));
  9516. return buf;
  9517. }
  9518. return NULL;
  9519. }
  9520. static const char *
  9521. get_symbol_other (unsigned int other)
  9522. {
  9523. const char * result = NULL;
  9524. static char buff [32];
  9525. if (other == 0)
  9526. return "";
  9527. switch (elf_header.e_machine)
  9528. {
  9529. case EM_MIPS:
  9530. result = get_mips_symbol_other (other);
  9531. break;
  9532. case EM_IA_64:
  9533. result = get_ia64_symbol_other (other);
  9534. break;
  9535. case EM_PPC64:
  9536. result = get_ppc64_symbol_other (other);
  9537. break;
  9538. default:
  9539. result = NULL;
  9540. break;
  9541. }
  9542. if (result)
  9543. return result;
  9544. snprintf (buff, sizeof buff, _("<other>: %x"), other);
  9545. return buff;
  9546. }
  9547. static const char *
  9548. get_symbol_index_type (unsigned int type)
  9549. {
  9550. static char buff[32];
  9551. switch (type)
  9552. {
  9553. case SHN_UNDEF: return "UND";
  9554. case SHN_ABS: return "ABS";
  9555. case SHN_COMMON: return "COM";
  9556. default:
  9557. if (type == SHN_IA_64_ANSI_COMMON
  9558. && elf_header.e_machine == EM_IA_64
  9559. && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
  9560. return "ANSI_COM";
  9561. else if ((elf_header.e_machine == EM_X86_64
  9562. || elf_header.e_machine == EM_L1OM
  9563. || elf_header.e_machine == EM_K1OM)
  9564. && type == SHN_X86_64_LCOMMON)
  9565. return "LARGE_COM";
  9566. else if ((type == SHN_MIPS_SCOMMON
  9567. && elf_header.e_machine == EM_MIPS)
  9568. || (type == SHN_TIC6X_SCOMMON
  9569. && elf_header.e_machine == EM_TI_C6000))
  9570. return "SCOM";
  9571. else if (type == SHN_MIPS_SUNDEFINED
  9572. && elf_header.e_machine == EM_MIPS)
  9573. return "SUND";
  9574. else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
  9575. sprintf (buff, "PRC[0x%04x]", type & 0xffff);
  9576. else if (type >= SHN_LOOS && type <= SHN_HIOS)
  9577. sprintf (buff, "OS [0x%04x]", type & 0xffff);
  9578. else if (type >= SHN_LORESERVE)
  9579. sprintf (buff, "RSV[0x%04x]", type & 0xffff);
  9580. else if (type >= elf_header.e_shnum)
  9581. sprintf (buff, _("bad section index[%3d]"), type);
  9582. else
  9583. sprintf (buff, "%3d", type);
  9584. break;
  9585. }
  9586. return buff;
  9587. }
  9588. static bfd_vma *
  9589. get_dynamic_data (FILE * file, bfd_size_type number, unsigned int ent_size)
  9590. {
  9591. unsigned char * e_data;
  9592. bfd_vma * i_data;
  9593. /* If the size_t type is smaller than the bfd_size_type, eg because
  9594. you are building a 32-bit tool on a 64-bit host, then make sure
  9595. that when (number) is cast to (size_t) no information is lost. */
  9596. if (sizeof (size_t) < sizeof (bfd_size_type)
  9597. && (bfd_size_type) ((size_t) number) != number)
  9598. {
  9599. error (_("Size truncation prevents reading %" BFD_VMA_FMT "u"
  9600. " elements of size %u\n"),
  9601. number, ent_size);
  9602. return NULL;
  9603. }
  9604. /* Be kind to memory chekers (eg valgrind, address sanitizer) by not
  9605. attempting to allocate memory when the read is bound to fail. */
  9606. if (ent_size * number > current_file_size)
  9607. {
  9608. error (_("Invalid number of dynamic entries: %" BFD_VMA_FMT "u\n"),
  9609. number);
  9610. return NULL;
  9611. }
  9612. e_data = (unsigned char *) cmalloc ((size_t) number, ent_size);
  9613. if (e_data == NULL)
  9614. {
  9615. error (_("Out of memory reading %" BFD_VMA_FMT "u dynamic entries\n"),
  9616. number);
  9617. return NULL;
  9618. }
  9619. if (fread (e_data, ent_size, (size_t) number, file) != number)
  9620. {
  9621. error (_("Unable to read in %" BFD_VMA_FMT "u bytes of dynamic data\n"),
  9622. number * ent_size);
  9623. free (e_data);
  9624. return NULL;
  9625. }
  9626. i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data));
  9627. if (i_data == NULL)
  9628. {
  9629. error (_("Out of memory allocating space for %" BFD_VMA_FMT "u"
  9630. " dynamic entries\n"),
  9631. number);
  9632. free (e_data);
  9633. return NULL;
  9634. }
  9635. while (number--)
  9636. i_data[number] = byte_get (e_data + number * ent_size, ent_size);
  9637. free (e_data);
  9638. return i_data;
  9639. }
  9640. static void
  9641. print_dynamic_symbol (bfd_vma si, unsigned long hn)
  9642. {
  9643. Elf_Internal_Sym * psym;
  9644. int n;
  9645. n = print_vma (si, DEC_5);
  9646. if (n < 5)
  9647. fputs (&" "[n], stdout);
  9648. printf (" %3lu: ", hn);
  9649. if (dynamic_symbols == NULL || si >= num_dynamic_syms)
  9650. {
  9651. printf (_("<No info available for dynamic symbol number %lu>\n"),
  9652. (unsigned long) si);
  9653. return;
  9654. }
  9655. psym = dynamic_symbols + si;
  9656. print_vma (psym->st_value, LONG_HEX);
  9657. putchar (' ');
  9658. print_vma (psym->st_size, DEC_5);
  9659. printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
  9660. printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
  9661. if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
  9662. printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
  9663. else
  9664. {
  9665. unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
  9666. printf (" %-7s", get_symbol_visibility (vis));
  9667. /* Check to see if any other bits in the st_other field are set.
  9668. Note - displaying this information disrupts the layout of the
  9669. table being generated, but for the moment this case is very
  9670. rare. */
  9671. if (psym->st_other ^ vis)
  9672. printf (" [%s] ", get_symbol_other (psym->st_other ^ vis));
  9673. }
  9674. printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
  9675. if (VALID_DYNAMIC_NAME (psym->st_name))
  9676. print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
  9677. else
  9678. printf (_(" <corrupt: %14ld>"), psym->st_name);
  9679. putchar ('\n');
  9680. }
  9681. static const char *
  9682. get_symbol_version_string (FILE * file,
  9683. bfd_boolean is_dynsym,
  9684. const char * strtab,
  9685. unsigned long int strtab_size,
  9686. unsigned int si,
  9687. Elf_Internal_Sym * psym,
  9688. enum versioned_symbol_info * sym_info,
  9689. unsigned short * vna_other)
  9690. {
  9691. unsigned char data[2];
  9692. unsigned short vers_data;
  9693. unsigned long offset;
  9694. if (!is_dynsym
  9695. || version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0)
  9696. return NULL;
  9697. offset = offset_from_vma (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
  9698. sizeof data + si * sizeof (vers_data));
  9699. if (get_data (&data, file, offset + si * sizeof (vers_data),
  9700. sizeof (data), 1, _("version data")) == NULL)
  9701. return NULL;
  9702. vers_data = byte_get (data, 2);
  9703. if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data <= 1)
  9704. return NULL;
  9705. /* Usually we'd only see verdef for defined symbols, and verneed for
  9706. undefined symbols. However, symbols defined by the linker in
  9707. .dynbss for variables copied from a shared library in order to
  9708. avoid text relocations are defined yet have verneed. We could
  9709. use a heuristic to detect the special case, for example, check
  9710. for verneed first on symbols defined in SHT_NOBITS sections, but
  9711. it is simpler and more reliable to just look for both verdef and
  9712. verneed. .dynbss might not be mapped to a SHT_NOBITS section. */
  9713. if (psym->st_shndx != SHN_UNDEF
  9714. && vers_data != 0x8001
  9715. && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
  9716. {
  9717. Elf_Internal_Verdef ivd;
  9718. Elf_Internal_Verdaux ivda;
  9719. Elf_External_Verdaux evda;
  9720. unsigned long off;
  9721. off = offset_from_vma (file,
  9722. version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
  9723. sizeof (Elf_External_Verdef));
  9724. do
  9725. {
  9726. Elf_External_Verdef evd;
  9727. if (get_data (&evd, file, off, sizeof (evd), 1,
  9728. _("version def")) == NULL)
  9729. {
  9730. ivd.vd_ndx = 0;
  9731. ivd.vd_aux = 0;
  9732. ivd.vd_next = 0;
  9733. }
  9734. else
  9735. {
  9736. ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
  9737. ivd.vd_aux = BYTE_GET (evd.vd_aux);
  9738. ivd.vd_next = BYTE_GET (evd.vd_next);
  9739. }
  9740. off += ivd.vd_next;
  9741. }
  9742. while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0);
  9743. if (ivd.vd_ndx == (vers_data & VERSYM_VERSION))
  9744. {
  9745. off -= ivd.vd_next;
  9746. off += ivd.vd_aux;
  9747. if (get_data (&evda, file, off, sizeof (evda), 1,
  9748. _("version def aux")) != NULL)
  9749. {
  9750. ivda.vda_name = BYTE_GET (evda.vda_name);
  9751. if (psym->st_name != ivda.vda_name)
  9752. {
  9753. *sym_info = ((vers_data & VERSYM_HIDDEN) != 0
  9754. ? symbol_hidden : symbol_public);
  9755. return (ivda.vda_name < strtab_size
  9756. ? strtab + ivda.vda_name : _("<corrupt>"));
  9757. }
  9758. }
  9759. }
  9760. }
  9761. if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
  9762. {
  9763. Elf_External_Verneed evn;
  9764. Elf_Internal_Verneed ivn;
  9765. Elf_Internal_Vernaux ivna;
  9766. offset = offset_from_vma (file,
  9767. version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
  9768. sizeof evn);
  9769. do
  9770. {
  9771. unsigned long vna_off;
  9772. if (get_data (&evn, file, offset, sizeof (evn), 1,
  9773. _("version need")) == NULL)
  9774. {
  9775. ivna.vna_next = 0;
  9776. ivna.vna_other = 0;
  9777. ivna.vna_name = 0;
  9778. break;
  9779. }
  9780. ivn.vn_aux = BYTE_GET (evn.vn_aux);
  9781. ivn.vn_next = BYTE_GET (evn.vn_next);
  9782. vna_off = offset + ivn.vn_aux;
  9783. do
  9784. {
  9785. Elf_External_Vernaux evna;
  9786. if (get_data (&evna, file, vna_off, sizeof (evna), 1,
  9787. _("version need aux (3)")) == NULL)
  9788. {
  9789. ivna.vna_next = 0;
  9790. ivna.vna_other = 0;
  9791. ivna.vna_name = 0;
  9792. }
  9793. else
  9794. {
  9795. ivna.vna_other = BYTE_GET (evna.vna_other);
  9796. ivna.vna_next = BYTE_GET (evna.vna_next);
  9797. ivna.vna_name = BYTE_GET (evna.vna_name);
  9798. }
  9799. vna_off += ivna.vna_next;
  9800. }
  9801. while (ivna.vna_other != vers_data && ivna.vna_next != 0);
  9802. if (ivna.vna_other == vers_data)
  9803. break;
  9804. offset += ivn.vn_next;
  9805. }
  9806. while (ivn.vn_next != 0);
  9807. if (ivna.vna_other == vers_data)
  9808. {
  9809. *sym_info = symbol_undefined;
  9810. *vna_other = ivna.vna_other;
  9811. return (ivna.vna_name < strtab_size
  9812. ? strtab + ivna.vna_name : _("<corrupt>"));
  9813. }
  9814. }
  9815. return NULL;
  9816. }
  9817. /* Dump the symbol table. */
  9818. static bfd_boolean
  9819. process_symbol_table (FILE * file)
  9820. {
  9821. Elf_Internal_Shdr * section;
  9822. bfd_size_type nbuckets = 0;
  9823. bfd_size_type nchains = 0;
  9824. bfd_vma * buckets = NULL;
  9825. bfd_vma * chains = NULL;
  9826. bfd_vma ngnubuckets = 0;
  9827. bfd_vma * gnubuckets = NULL;
  9828. bfd_vma * gnuchains = NULL;
  9829. bfd_vma gnusymidx = 0;
  9830. bfd_size_type ngnuchains = 0;
  9831. if (!do_syms && !do_dyn_syms && !do_histogram)
  9832. return TRUE;
  9833. if (dynamic_info[DT_HASH]
  9834. && (do_histogram
  9835. || (do_using_dynamic
  9836. && !do_dyn_syms
  9837. && dynamic_strings != NULL)))
  9838. {
  9839. unsigned char nb[8];
  9840. unsigned char nc[8];
  9841. unsigned int hash_ent_size = 4;
  9842. if ((elf_header.e_machine == EM_ALPHA
  9843. || elf_header.e_machine == EM_S390
  9844. || elf_header.e_machine == EM_S390_OLD)
  9845. && elf_header.e_ident[EI_CLASS] == ELFCLASS64)
  9846. hash_ent_size = 8;
  9847. if (fseek (file,
  9848. (archive_file_offset
  9849. + offset_from_vma (file, dynamic_info[DT_HASH],
  9850. sizeof nb + sizeof nc)),
  9851. SEEK_SET))
  9852. {
  9853. error (_("Unable to seek to start of dynamic information\n"));
  9854. goto no_hash;
  9855. }
  9856. if (fread (nb, hash_ent_size, 1, file) != 1)
  9857. {
  9858. error (_("Failed to read in number of buckets\n"));
  9859. goto no_hash;
  9860. }
  9861. if (fread (nc, hash_ent_size, 1, file) != 1)
  9862. {
  9863. error (_("Failed to read in number of chains\n"));
  9864. goto no_hash;
  9865. }
  9866. nbuckets = byte_get (nb, hash_ent_size);
  9867. nchains = byte_get (nc, hash_ent_size);
  9868. buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
  9869. chains = get_dynamic_data (file, nchains, hash_ent_size);
  9870. no_hash:
  9871. if (buckets == NULL || chains == NULL)
  9872. {
  9873. if (do_using_dynamic)
  9874. return FALSE;
  9875. free (buckets);
  9876. free (chains);
  9877. buckets = NULL;
  9878. chains = NULL;
  9879. nbuckets = 0;
  9880. nchains = 0;
  9881. }
  9882. }
  9883. if (dynamic_info_DT_GNU_HASH
  9884. && (do_histogram
  9885. || (do_using_dynamic
  9886. && !do_dyn_syms
  9887. && dynamic_strings != NULL)))
  9888. {
  9889. unsigned char nb[16];
  9890. bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
  9891. bfd_vma buckets_vma;
  9892. if (fseek (file,
  9893. (archive_file_offset
  9894. + offset_from_vma (file, dynamic_info_DT_GNU_HASH,
  9895. sizeof nb)),
  9896. SEEK_SET))
  9897. {
  9898. error (_("Unable to seek to start of dynamic information\n"));
  9899. goto no_gnu_hash;
  9900. }
  9901. if (fread (nb, 16, 1, file) != 1)
  9902. {
  9903. error (_("Failed to read in number of buckets\n"));
  9904. goto no_gnu_hash;
  9905. }
  9906. ngnubuckets = byte_get (nb, 4);
  9907. gnusymidx = byte_get (nb + 4, 4);
  9908. bitmaskwords = byte_get (nb + 8, 4);
  9909. buckets_vma = dynamic_info_DT_GNU_HASH + 16;
  9910. if (is_32bit_elf)
  9911. buckets_vma += bitmaskwords * 4;
  9912. else
  9913. buckets_vma += bitmaskwords * 8;
  9914. if (fseek (file,
  9915. (archive_file_offset
  9916. + offset_from_vma (file, buckets_vma, 4)),
  9917. SEEK_SET))
  9918. {
  9919. error (_("Unable to seek to start of dynamic information\n"));
  9920. goto no_gnu_hash;
  9921. }
  9922. gnubuckets = get_dynamic_data (file, ngnubuckets, 4);
  9923. if (gnubuckets == NULL)
  9924. goto no_gnu_hash;
  9925. for (i = 0; i < ngnubuckets; i++)
  9926. if (gnubuckets[i] != 0)
  9927. {
  9928. if (gnubuckets[i] < gnusymidx)
  9929. return FALSE;
  9930. if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
  9931. maxchain = gnubuckets[i];
  9932. }
  9933. if (maxchain == 0xffffffff)
  9934. goto no_gnu_hash;
  9935. maxchain -= gnusymidx;
  9936. if (fseek (file,
  9937. (archive_file_offset
  9938. + offset_from_vma (file, buckets_vma
  9939. + 4 * (ngnubuckets + maxchain), 4)),
  9940. SEEK_SET))
  9941. {
  9942. error (_("Unable to seek to start of dynamic information\n"));
  9943. goto no_gnu_hash;
  9944. }
  9945. do
  9946. {
  9947. if (fread (nb, 4, 1, file) != 1)
  9948. {
  9949. error (_("Failed to determine last chain length\n"));
  9950. goto no_gnu_hash;
  9951. }
  9952. if (maxchain + 1 == 0)
  9953. goto no_gnu_hash;
  9954. ++maxchain;
  9955. }
  9956. while ((byte_get (nb, 4) & 1) == 0);
  9957. if (fseek (file,
  9958. (archive_file_offset
  9959. + offset_from_vma (file, buckets_vma + 4 * ngnubuckets, 4)),
  9960. SEEK_SET))
  9961. {
  9962. error (_("Unable to seek to start of dynamic information\n"));
  9963. goto no_gnu_hash;
  9964. }
  9965. gnuchains = get_dynamic_data (file, maxchain, 4);
  9966. ngnuchains = maxchain;
  9967. no_gnu_hash:
  9968. if (gnuchains == NULL)
  9969. {
  9970. free (gnubuckets);
  9971. gnubuckets = NULL;
  9972. ngnubuckets = 0;
  9973. if (do_using_dynamic)
  9974. return FALSE;
  9975. }
  9976. }
  9977. if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH)
  9978. && do_syms
  9979. && do_using_dynamic
  9980. && dynamic_strings != NULL
  9981. && dynamic_symbols != NULL)
  9982. {
  9983. unsigned long hn;
  9984. if (dynamic_info[DT_HASH])
  9985. {
  9986. bfd_vma si;
  9987. printf (_("\nSymbol table for image:\n"));
  9988. if (is_32bit_elf)
  9989. printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
  9990. else
  9991. printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
  9992. for (hn = 0; hn < nbuckets; hn++)
  9993. {
  9994. if (! buckets[hn])
  9995. continue;
  9996. for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
  9997. print_dynamic_symbol (si, hn);
  9998. }
  9999. }
  10000. if (dynamic_info_DT_GNU_HASH)
  10001. {
  10002. printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
  10003. if (is_32bit_elf)
  10004. printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
  10005. else
  10006. printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
  10007. for (hn = 0; hn < ngnubuckets; ++hn)
  10008. if (gnubuckets[hn] != 0)
  10009. {
  10010. bfd_vma si = gnubuckets[hn];
  10011. bfd_vma off = si - gnusymidx;
  10012. do
  10013. {
  10014. print_dynamic_symbol (si, hn);
  10015. si++;
  10016. }
  10017. while (off < ngnuchains && (gnuchains[off++] & 1) == 0);
  10018. }
  10019. }
  10020. }
  10021. else if ((do_dyn_syms || (do_syms && !do_using_dynamic))
  10022. && section_headers != NULL)
  10023. {
  10024. unsigned int i;
  10025. for (i = 0, section = section_headers;
  10026. i < elf_header.e_shnum;
  10027. i++, section++)
  10028. {
  10029. unsigned int si;
  10030. char * strtab = NULL;
  10031. unsigned long int strtab_size = 0;
  10032. Elf_Internal_Sym * symtab;
  10033. Elf_Internal_Sym * psym;
  10034. unsigned long num_syms;
  10035. if ((section->sh_type != SHT_SYMTAB
  10036. && section->sh_type != SHT_DYNSYM)
  10037. || (!do_syms
  10038. && section->sh_type == SHT_SYMTAB))
  10039. continue;
  10040. if (section->sh_entsize == 0)
  10041. {
  10042. printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"),
  10043. printable_section_name (section));
  10044. continue;
  10045. }
  10046. printf (_("\nSymbol table '%s' contains %lu entries:\n"),
  10047. printable_section_name (section),
  10048. (unsigned long) (section->sh_size / section->sh_entsize));
  10049. if (is_32bit_elf)
  10050. printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
  10051. else
  10052. printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
  10053. symtab = GET_ELF_SYMBOLS (file, section, & num_syms);
  10054. if (symtab == NULL)
  10055. continue;
  10056. if (section->sh_link == elf_header.e_shstrndx)
  10057. {
  10058. strtab = string_table;
  10059. strtab_size = string_table_length;
  10060. }
  10061. else if (section->sh_link < elf_header.e_shnum)
  10062. {
  10063. Elf_Internal_Shdr * string_sec;
  10064. string_sec = section_headers + section->sh_link;
  10065. strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
  10066. 1, string_sec->sh_size,
  10067. _("string table"));
  10068. strtab_size = strtab != NULL ? string_sec->sh_size : 0;
  10069. }
  10070. for (si = 0, psym = symtab; si < num_syms; si++, psym++)
  10071. {
  10072. const char *version_string;
  10073. enum versioned_symbol_info sym_info;
  10074. unsigned short vna_other;
  10075. printf ("%6d: ", si);
  10076. print_vma (psym->st_value, LONG_HEX);
  10077. putchar (' ');
  10078. print_vma (psym->st_size, DEC_5);
  10079. printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
  10080. printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
  10081. if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS)
  10082. printf (" %-7s", get_solaris_symbol_visibility (psym->st_other));
  10083. else
  10084. {
  10085. unsigned int vis = ELF_ST_VISIBILITY (psym->st_other);
  10086. printf (" %-7s", get_symbol_visibility (vis));
  10087. /* Check to see if any other bits in the st_other field are set.
  10088. Note - displaying this information disrupts the layout of the
  10089. table being generated, but for the moment this case is very rare. */
  10090. if (psym->st_other ^ vis)
  10091. printf (" [%s] ", get_symbol_other (psym->st_other ^ vis));
  10092. }
  10093. printf (" %4s ", get_symbol_index_type (psym->st_shndx));
  10094. print_symbol (25, psym->st_name < strtab_size
  10095. ? strtab + psym->st_name : _("<corrupt>"));
  10096. version_string
  10097. = get_symbol_version_string (file,
  10098. section->sh_type == SHT_DYNSYM,
  10099. strtab, strtab_size, si,
  10100. psym, &sym_info, &vna_other);
  10101. if (version_string)
  10102. {
  10103. if (sym_info == symbol_undefined)
  10104. printf ("@%s (%d)", version_string, vna_other);
  10105. else
  10106. printf (sym_info == symbol_hidden ? "@%s" : "@@%s",
  10107. version_string);
  10108. }
  10109. putchar ('\n');
  10110. if (ELF_ST_BIND (psym->st_info) == STB_LOCAL
  10111. && si >= section->sh_info
  10112. /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */
  10113. && elf_header.e_machine != EM_MIPS
  10114. /* Solaris binaries have been found to violate this requirement as
  10115. well. Not sure if this is a bug or an ABI requirement. */
  10116. && elf_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS)
  10117. warn (_("local symbol %u found at index >= %s's sh_info value of %u\n"),
  10118. si, printable_section_name (section), section->sh_info);
  10119. }
  10120. free (symtab);
  10121. if (strtab != string_table)
  10122. free (strtab);
  10123. }
  10124. }
  10125. else if (do_syms)
  10126. printf
  10127. (_("\nDynamic symbol information is not available for displaying symbols.\n"));
  10128. if (do_histogram && buckets != NULL)
  10129. {
  10130. unsigned long * lengths;
  10131. unsigned long * counts;
  10132. unsigned long hn;
  10133. bfd_vma si;
  10134. unsigned long maxlength = 0;
  10135. unsigned long nzero_counts = 0;
  10136. unsigned long nsyms = 0;
  10137. unsigned long chained;
  10138. printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
  10139. (unsigned long) nbuckets);
  10140. lengths = (unsigned long *) calloc (nbuckets, sizeof (*lengths));
  10141. if (lengths == NULL)
  10142. {
  10143. error (_("Out of memory allocating space for histogram buckets\n"));
  10144. return FALSE;
  10145. }
  10146. printf (_(" Length Number %% of total Coverage\n"));
  10147. for (hn = 0; hn < nbuckets; ++hn)
  10148. {
  10149. for (si = buckets[hn], chained = 0;
  10150. si > 0 && si < nchains && si < nbuckets && chained <= nchains;
  10151. si = chains[si], ++chained)
  10152. {
  10153. ++nsyms;
  10154. if (maxlength < ++lengths[hn])
  10155. ++maxlength;
  10156. }
  10157. /* PR binutils/17531: A corrupt binary could contain broken
  10158. histogram data. Do not go into an infinite loop trying
  10159. to process it. */
  10160. if (chained > nchains)
  10161. {
  10162. error (_("histogram chain is corrupt\n"));
  10163. break;
  10164. }
  10165. }
  10166. counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
  10167. if (counts == NULL)
  10168. {
  10169. free (lengths);
  10170. error (_("Out of memory allocating space for histogram counts\n"));
  10171. return FALSE;
  10172. }
  10173. for (hn = 0; hn < nbuckets; ++hn)
  10174. ++counts[lengths[hn]];
  10175. if (nbuckets > 0)
  10176. {
  10177. unsigned long i;
  10178. printf (" 0 %-10lu (%5.1f%%)\n",
  10179. counts[0], (counts[0] * 100.0) / nbuckets);
  10180. for (i = 1; i <= maxlength; ++i)
  10181. {
  10182. nzero_counts += counts[i] * i;
  10183. printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
  10184. i, counts[i], (counts[i] * 100.0) / nbuckets,
  10185. (nzero_counts * 100.0) / nsyms);
  10186. }
  10187. }
  10188. free (counts);
  10189. free (lengths);
  10190. }
  10191. if (buckets != NULL)
  10192. {
  10193. free (buckets);
  10194. free (chains);
  10195. }
  10196. if (do_histogram && gnubuckets != NULL)
  10197. {
  10198. unsigned long * lengths;
  10199. unsigned long * counts;
  10200. unsigned long hn;
  10201. unsigned long maxlength = 0;
  10202. unsigned long nzero_counts = 0;
  10203. unsigned long nsyms = 0;
  10204. printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
  10205. (unsigned long) ngnubuckets);
  10206. lengths = (unsigned long *) calloc (ngnubuckets, sizeof (*lengths));
  10207. if (lengths == NULL)
  10208. {
  10209. error (_("Out of memory allocating space for gnu histogram buckets\n"));
  10210. return FALSE;
  10211. }
  10212. printf (_(" Length Number %% of total Coverage\n"));
  10213. for (hn = 0; hn < ngnubuckets; ++hn)
  10214. if (gnubuckets[hn] != 0)
  10215. {
  10216. bfd_vma off, length = 1;
  10217. for (off = gnubuckets[hn] - gnusymidx;
  10218. /* PR 17531 file: 010-77222-0.004. */
  10219. off < ngnuchains && (gnuchains[off] & 1) == 0;
  10220. ++off)
  10221. ++length;
  10222. lengths[hn] = length;
  10223. if (length > maxlength)
  10224. maxlength = length;
  10225. nsyms += length;
  10226. }
  10227. counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts));
  10228. if (counts == NULL)
  10229. {
  10230. free (lengths);
  10231. error (_("Out of memory allocating space for gnu histogram counts\n"));
  10232. return FALSE;
  10233. }
  10234. for (hn = 0; hn < ngnubuckets; ++hn)
  10235. ++counts[lengths[hn]];
  10236. if (ngnubuckets > 0)
  10237. {
  10238. unsigned long j;
  10239. printf (" 0 %-10lu (%5.1f%%)\n",
  10240. counts[0], (counts[0] * 100.0) / ngnubuckets);
  10241. for (j = 1; j <= maxlength; ++j)
  10242. {
  10243. nzero_counts += counts[j] * j;
  10244. printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
  10245. j, counts[j], (counts[j] * 100.0) / ngnubuckets,
  10246. (nzero_counts * 100.0) / nsyms);
  10247. }
  10248. }
  10249. free (counts);
  10250. free (lengths);
  10251. free (gnubuckets);
  10252. free (gnuchains);
  10253. }
  10254. return TRUE;
  10255. }
  10256. static bfd_boolean
  10257. process_syminfo (FILE * file ATTRIBUTE_UNUSED)
  10258. {
  10259. unsigned int i;
  10260. if (dynamic_syminfo == NULL
  10261. || !do_dynamic)
  10262. /* No syminfo, this is ok. */
  10263. return TRUE;
  10264. /* There better should be a dynamic symbol section. */
  10265. if (dynamic_symbols == NULL || dynamic_strings == NULL)
  10266. return FALSE;
  10267. if (dynamic_addr)
  10268. printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
  10269. dynamic_syminfo_offset, dynamic_syminfo_nent);
  10270. printf (_(" Num: Name BoundTo Flags\n"));
  10271. for (i = 0; i < dynamic_syminfo_nent; ++i)
  10272. {
  10273. unsigned short int flags = dynamic_syminfo[i].si_flags;
  10274. printf ("%4d: ", i);
  10275. if (i >= num_dynamic_syms)
  10276. printf (_("<corrupt index>"));
  10277. else if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
  10278. print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
  10279. else
  10280. printf (_("<corrupt: %19ld>"), dynamic_symbols[i].st_name);
  10281. putchar (' ');
  10282. switch (dynamic_syminfo[i].si_boundto)
  10283. {
  10284. case SYMINFO_BT_SELF:
  10285. fputs ("SELF ", stdout);
  10286. break;
  10287. case SYMINFO_BT_PARENT:
  10288. fputs ("PARENT ", stdout);
  10289. break;
  10290. default:
  10291. if (dynamic_syminfo[i].si_boundto > 0
  10292. && dynamic_syminfo[i].si_boundto < dynamic_nent
  10293. && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
  10294. {
  10295. print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
  10296. putchar (' ' );
  10297. }
  10298. else
  10299. printf ("%-10d ", dynamic_syminfo[i].si_boundto);
  10300. break;
  10301. }
  10302. if (flags & SYMINFO_FLG_DIRECT)
  10303. printf (" DIRECT");
  10304. if (flags & SYMINFO_FLG_PASSTHRU)
  10305. printf (" PASSTHRU");
  10306. if (flags & SYMINFO_FLG_COPY)
  10307. printf (" COPY");
  10308. if (flags & SYMINFO_FLG_LAZYLOAD)
  10309. printf (" LAZYLOAD");
  10310. puts ("");
  10311. }
  10312. return TRUE;
  10313. }
  10314. #define IN_RANGE(START,END,ADDR,OFF) \
  10315. (((ADDR) >= (START)) && ((ADDR) + (OFF) < (END)))
  10316. /* Check to see if the given reloc needs to be handled in a target specific
  10317. manner. If so then process the reloc and return TRUE otherwise return
  10318. FALSE.
  10319. If called with reloc == NULL, then this is a signal that reloc processing
  10320. for the current section has finished, and any saved state should be
  10321. discarded. */
  10322. static bfd_boolean
  10323. target_specific_reloc_handling (Elf_Internal_Rela * reloc,
  10324. unsigned char * start,
  10325. unsigned char * end,
  10326. Elf_Internal_Sym * symtab,
  10327. unsigned long num_syms)
  10328. {
  10329. unsigned int reloc_type = 0;
  10330. unsigned long sym_index = 0;
  10331. if (reloc)
  10332. {
  10333. reloc_type = get_reloc_type (reloc->r_info);
  10334. sym_index = get_reloc_symindex (reloc->r_info);
  10335. }
  10336. switch (elf_header.e_machine)
  10337. {
  10338. case EM_MSP430:
  10339. case EM_MSP430_OLD:
  10340. {
  10341. static Elf_Internal_Sym * saved_sym = NULL;
  10342. if (reloc == NULL)
  10343. {
  10344. saved_sym = NULL;
  10345. return TRUE;
  10346. }
  10347. switch (reloc_type)
  10348. {
  10349. case 10: /* R_MSP430_SYM_DIFF */
  10350. if (uses_msp430x_relocs ())
  10351. break;
  10352. /* Fall through. */
  10353. case 21: /* R_MSP430X_SYM_DIFF */
  10354. /* PR 21139. */
  10355. if (sym_index >= num_syms)
  10356. error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"),
  10357. sym_index);
  10358. else
  10359. saved_sym = symtab + sym_index;
  10360. return TRUE;
  10361. case 1: /* R_MSP430_32 or R_MSP430_ABS32 */
  10362. case 3: /* R_MSP430_16 or R_MSP430_ABS8 */
  10363. goto handle_sym_diff;
  10364. case 5: /* R_MSP430_16_BYTE */
  10365. case 9: /* R_MSP430_8 */
  10366. if (uses_msp430x_relocs ())
  10367. break;
  10368. goto handle_sym_diff;
  10369. case 2: /* R_MSP430_ABS16 */
  10370. case 15: /* R_MSP430X_ABS16 */
  10371. if (! uses_msp430x_relocs ())
  10372. break;
  10373. goto handle_sym_diff;
  10374. handle_sym_diff:
  10375. if (saved_sym != NULL)
  10376. {
  10377. int reloc_size = reloc_type == 1 ? 4 : 2;
  10378. bfd_vma value;
  10379. if (sym_index >= num_syms)
  10380. error (_("MSP430 reloc contains invalid symbol index %lu\n"),
  10381. sym_index);
  10382. else
  10383. {
  10384. value = reloc->r_addend + (symtab[sym_index].st_value
  10385. - saved_sym->st_value);
  10386. if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
  10387. byte_put (start + reloc->r_offset, value, reloc_size);
  10388. else
  10389. /* PR 21137 */
  10390. error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"),
  10391. (long) reloc->r_offset);
  10392. }
  10393. saved_sym = NULL;
  10394. return TRUE;
  10395. }
  10396. break;
  10397. default:
  10398. if (saved_sym != NULL)
  10399. error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n"));
  10400. break;
  10401. }
  10402. break;
  10403. }
  10404. case EM_MN10300:
  10405. case EM_CYGNUS_MN10300:
  10406. {
  10407. static Elf_Internal_Sym * saved_sym = NULL;
  10408. if (reloc == NULL)
  10409. {
  10410. saved_sym = NULL;
  10411. return TRUE;
  10412. }
  10413. switch (reloc_type)
  10414. {
  10415. case 34: /* R_MN10300_ALIGN */
  10416. return TRUE;
  10417. case 33: /* R_MN10300_SYM_DIFF */
  10418. if (sym_index >= num_syms)
  10419. error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"),
  10420. sym_index);
  10421. else
  10422. saved_sym = symtab + sym_index;
  10423. return TRUE;
  10424. case 1: /* R_MN10300_32 */
  10425. case 2: /* R_MN10300_16 */
  10426. if (saved_sym != NULL)
  10427. {
  10428. int reloc_size = reloc_type == 1 ? 4 : 2;
  10429. bfd_vma value;
  10430. if (sym_index >= num_syms)
  10431. error (_("MN10300 reloc contains invalid symbol index %lu\n"),
  10432. sym_index);
  10433. else
  10434. {
  10435. value = reloc->r_addend + (symtab[sym_index].st_value
  10436. - saved_sym->st_value);
  10437. if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size))
  10438. byte_put (start + reloc->r_offset, value, reloc_size);
  10439. else
  10440. error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"),
  10441. (long) reloc->r_offset);
  10442. }
  10443. saved_sym = NULL;
  10444. return TRUE;
  10445. }
  10446. break;
  10447. default:
  10448. if (saved_sym != NULL)
  10449. error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n"));
  10450. break;
  10451. }
  10452. break;
  10453. }
  10454. case EM_RL78:
  10455. {
  10456. static bfd_vma saved_sym1 = 0;
  10457. static bfd_vma saved_sym2 = 0;
  10458. static bfd_vma value;
  10459. if (reloc == NULL)
  10460. {
  10461. saved_sym1 = saved_sym2 = 0;
  10462. return TRUE;
  10463. }
  10464. switch (reloc_type)
  10465. {
  10466. case 0x80: /* R_RL78_SYM. */
  10467. saved_sym1 = saved_sym2;
  10468. if (sym_index >= num_syms)
  10469. error (_("RL78_SYM reloc contains invalid symbol index %lu\n"),
  10470. sym_index);
  10471. else
  10472. {
  10473. saved_sym2 = symtab[sym_index].st_value;
  10474. saved_sym2 += reloc->r_addend;
  10475. }
  10476. return TRUE;
  10477. case 0x83: /* R_RL78_OPsub. */
  10478. value = saved_sym1 - saved_sym2;
  10479. saved_sym2 = saved_sym1 = 0;
  10480. return TRUE;
  10481. break;
  10482. case 0x41: /* R_RL78_ABS32. */
  10483. if (IN_RANGE (start, end, start + reloc->r_offset, 4))
  10484. byte_put (start + reloc->r_offset, value, 4);
  10485. else
  10486. error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
  10487. (long) reloc->r_offset);
  10488. value = 0;
  10489. return TRUE;
  10490. case 0x43: /* R_RL78_ABS16. */
  10491. if (IN_RANGE (start, end, start + reloc->r_offset, 2))
  10492. byte_put (start + reloc->r_offset, value, 2);
  10493. else
  10494. error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"),
  10495. (long) reloc->r_offset);
  10496. value = 0;
  10497. return TRUE;
  10498. default:
  10499. break;
  10500. }
  10501. break;
  10502. }
  10503. }
  10504. return FALSE;
  10505. }
  10506. /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
  10507. DWARF debug sections. This is a target specific test. Note - we do not
  10508. go through the whole including-target-headers-multiple-times route, (as
  10509. we have already done with <elf/h8.h>) because this would become very
  10510. messy and even then this function would have to contain target specific
  10511. information (the names of the relocs instead of their numeric values).
  10512. FIXME: This is not the correct way to solve this problem. The proper way
  10513. is to have target specific reloc sizing and typing functions created by
  10514. the reloc-macros.h header, in the same way that it already creates the
  10515. reloc naming functions. */
  10516. static bfd_boolean
  10517. is_32bit_abs_reloc (unsigned int reloc_type)
  10518. {
  10519. /* Please keep this table alpha-sorted for ease of visual lookup. */
  10520. switch (elf_header.e_machine)
  10521. {
  10522. case EM_386:
  10523. case EM_IAMCU:
  10524. return reloc_type == 1; /* R_386_32. */
  10525. case EM_68K:
  10526. return reloc_type == 1; /* R_68K_32. */
  10527. case EM_860:
  10528. return reloc_type == 1; /* R_860_32. */
  10529. case EM_960:
  10530. return reloc_type == 2; /* R_960_32. */
  10531. case EM_AARCH64:
  10532. return (reloc_type == 258
  10533. || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */
  10534. case EM_ADAPTEVA_EPIPHANY:
  10535. return reloc_type == 3;
  10536. case EM_ALPHA:
  10537. return reloc_type == 1; /* R_ALPHA_REFLONG. */
  10538. case EM_ARC:
  10539. return reloc_type == 1; /* R_ARC_32. */
  10540. case EM_ARC_COMPACT:
  10541. case EM_ARC_COMPACT2:
  10542. return reloc_type == 4; /* R_ARC_32. */
  10543. case EM_ARM:
  10544. return reloc_type == 2; /* R_ARM_ABS32 */
  10545. case EM_AVR_OLD:
  10546. case EM_AVR:
  10547. return reloc_type == 1;
  10548. case EM_BLACKFIN:
  10549. return reloc_type == 0x12; /* R_byte4_data. */
  10550. case EM_CRIS:
  10551. return reloc_type == 3; /* R_CRIS_32. */
  10552. case EM_CR16:
  10553. return reloc_type == 3; /* R_CR16_NUM32. */
  10554. case EM_CRX:
  10555. return reloc_type == 15; /* R_CRX_NUM32. */
  10556. case EM_CYGNUS_FRV:
  10557. return reloc_type == 1;
  10558. case EM_CYGNUS_D10V:
  10559. case EM_D10V:
  10560. return reloc_type == 6; /* R_D10V_32. */
  10561. case EM_CYGNUS_D30V:
  10562. case EM_D30V:
  10563. return reloc_type == 12; /* R_D30V_32_NORMAL. */
  10564. case EM_DLX:
  10565. return reloc_type == 3; /* R_DLX_RELOC_32. */
  10566. case EM_CYGNUS_FR30:
  10567. case EM_FR30:
  10568. return reloc_type == 3; /* R_FR30_32. */
  10569. case EM_FT32:
  10570. return reloc_type == 1; /* R_FT32_32. */
  10571. case EM_H8S:
  10572. case EM_H8_300:
  10573. case EM_H8_300H:
  10574. return reloc_type == 1; /* R_H8_DIR32. */
  10575. case EM_IA_64:
  10576. return reloc_type == 0x65 /* R_IA64_SECREL32LSB. */
  10577. || reloc_type == 0x25; /* R_IA64_DIR32LSB. */
  10578. case EM_IP2K_OLD:
  10579. case EM_IP2K:
  10580. return reloc_type == 2; /* R_IP2K_32. */
  10581. case EM_IQ2000:
  10582. return reloc_type == 2; /* R_IQ2000_32. */
  10583. case EM_LATTICEMICO32:
  10584. return reloc_type == 3; /* R_LM32_32. */
  10585. case EM_M32C_OLD:
  10586. case EM_M32C:
  10587. return reloc_type == 3; /* R_M32C_32. */
  10588. case EM_M32R:
  10589. return reloc_type == 34; /* R_M32R_32_RELA. */
  10590. case EM_68HC11:
  10591. case EM_68HC12:
  10592. return reloc_type == 6; /* R_M68HC11_32. */
  10593. case EM_MCORE:
  10594. return reloc_type == 1; /* R_MCORE_ADDR32. */
  10595. case EM_CYGNUS_MEP:
  10596. return reloc_type == 4; /* R_MEP_32. */
  10597. case EM_METAG:
  10598. return reloc_type == 2; /* R_METAG_ADDR32. */
  10599. case EM_MICROBLAZE:
  10600. return reloc_type == 1; /* R_MICROBLAZE_32. */
  10601. case EM_MIPS:
  10602. return reloc_type == 2; /* R_MIPS_32. */
  10603. case EM_MMIX:
  10604. return reloc_type == 4; /* R_MMIX_32. */
  10605. case EM_CYGNUS_MN10200:
  10606. case EM_MN10200:
  10607. return reloc_type == 1; /* R_MN10200_32. */
  10608. case EM_CYGNUS_MN10300:
  10609. case EM_MN10300:
  10610. return reloc_type == 1; /* R_MN10300_32. */
  10611. case EM_MOXIE:
  10612. return reloc_type == 1; /* R_MOXIE_32. */
  10613. case EM_MSP430_OLD:
  10614. case EM_MSP430:
  10615. return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */
  10616. case EM_MT:
  10617. return reloc_type == 2; /* R_MT_32. */
  10618. case EM_NDS32:
  10619. return reloc_type == 20; /* R_NDS32_RELA. */
  10620. case EM_ALTERA_NIOS2:
  10621. return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */
  10622. case EM_NIOS32:
  10623. return reloc_type == 1; /* R_NIOS_32. */
  10624. case EM_OR1K:
  10625. return reloc_type == 1; /* R_OR1K_32. */
  10626. case EM_PARISC:
  10627. return (reloc_type == 1 /* R_PARISC_DIR32. */
  10628. || reloc_type == 41); /* R_PARISC_SECREL32. */
  10629. case EM_PJ:
  10630. case EM_PJ_OLD:
  10631. return reloc_type == 1; /* R_PJ_DATA_DIR32. */
  10632. case EM_PPC64:
  10633. return reloc_type == 1; /* R_PPC64_ADDR32. */
  10634. case EM_PPC:
  10635. return reloc_type == 1; /* R_PPC_ADDR32. */
  10636. case EM_TI_PRU:
  10637. return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */
  10638. case EM_RISCV:
  10639. return reloc_type == 1; /* R_RISCV_32. */
  10640. case EM_RL78:
  10641. return reloc_type == 1; /* R_RL78_DIR32. */
  10642. case EM_RX:
  10643. return reloc_type == 1; /* R_RX_DIR32. */
  10644. case EM_S370:
  10645. return reloc_type == 1; /* R_I370_ADDR31. */
  10646. case EM_S390_OLD:
  10647. case EM_S390:
  10648. return reloc_type == 4; /* R_S390_32. */
  10649. case EM_SCORE:
  10650. return reloc_type == 8; /* R_SCORE_ABS32. */
  10651. case EM_SH:
  10652. return reloc_type == 1; /* R_SH_DIR32. */
  10653. case EM_SPARC32PLUS:
  10654. case EM_SPARCV9:
  10655. case EM_SPARC:
  10656. return reloc_type == 3 /* R_SPARC_32. */
  10657. || reloc_type == 23; /* R_SPARC_UA32. */
  10658. case EM_SPU:
  10659. return reloc_type == 6; /* R_SPU_ADDR32 */
  10660. case EM_TI_C6000:
  10661. return reloc_type == 1; /* R_C6000_ABS32. */
  10662. case EM_TILEGX:
  10663. return reloc_type == 2; /* R_TILEGX_32. */
  10664. case EM_TILEPRO:
  10665. return reloc_type == 1; /* R_TILEPRO_32. */
  10666. case EM_CYGNUS_V850:
  10667. case EM_V850:
  10668. return reloc_type == 6; /* R_V850_ABS32. */
  10669. case EM_V800:
  10670. return reloc_type == 0x33; /* R_V810_WORD. */
  10671. case EM_VAX:
  10672. return reloc_type == 1; /* R_VAX_32. */
  10673. case EM_VISIUM:
  10674. return reloc_type == 3; /* R_VISIUM_32. */
  10675. case EM_WEBASSEMBLY:
  10676. return reloc_type == 1; /* R_WASM32_32. */
  10677. case EM_X86_64:
  10678. case EM_L1OM:
  10679. case EM_K1OM:
  10680. return reloc_type == 10; /* R_X86_64_32. */
  10681. case EM_XC16X:
  10682. case EM_C166:
  10683. return reloc_type == 3; /* R_XC16C_ABS_32. */
  10684. case EM_XGATE:
  10685. return reloc_type == 4; /* R_XGATE_32. */
  10686. case EM_XSTORMY16:
  10687. return reloc_type == 1; /* R_XSTROMY16_32. */
  10688. case EM_XTENSA_OLD:
  10689. case EM_XTENSA:
  10690. return reloc_type == 1; /* R_XTENSA_32. */
  10691. default:
  10692. {
  10693. static unsigned int prev_warn = 0;
  10694. /* Avoid repeating the same warning multiple times. */
  10695. if (prev_warn != elf_header.e_machine)
  10696. error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
  10697. elf_header.e_machine);
  10698. prev_warn = elf_header.e_machine;
  10699. return FALSE;
  10700. }
  10701. }
  10702. }
  10703. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  10704. a 32-bit pc-relative RELA relocation used in DWARF debug sections. */
  10705. static bfd_boolean
  10706. is_32bit_pcrel_reloc (unsigned int reloc_type)
  10707. {
  10708. switch (elf_header.e_machine)
  10709. /* Please keep this table alpha-sorted for ease of visual lookup. */
  10710. {
  10711. case EM_386:
  10712. case EM_IAMCU:
  10713. return reloc_type == 2; /* R_386_PC32. */
  10714. case EM_68K:
  10715. return reloc_type == 4; /* R_68K_PC32. */
  10716. case EM_AARCH64:
  10717. return reloc_type == 261; /* R_AARCH64_PREL32 */
  10718. case EM_ADAPTEVA_EPIPHANY:
  10719. return reloc_type == 6;
  10720. case EM_ALPHA:
  10721. return reloc_type == 10; /* R_ALPHA_SREL32. */
  10722. case EM_ARC_COMPACT:
  10723. case EM_ARC_COMPACT2:
  10724. return reloc_type == 49; /* R_ARC_32_PCREL. */
  10725. case EM_ARM:
  10726. return reloc_type == 3; /* R_ARM_REL32 */
  10727. case EM_AVR_OLD:
  10728. case EM_AVR:
  10729. return reloc_type == 36; /* R_AVR_32_PCREL. */
  10730. case EM_MICROBLAZE:
  10731. return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */
  10732. case EM_OR1K:
  10733. return reloc_type == 9; /* R_OR1K_32_PCREL. */
  10734. case EM_PARISC:
  10735. return reloc_type == 9; /* R_PARISC_PCREL32. */
  10736. case EM_PPC:
  10737. return reloc_type == 26; /* R_PPC_REL32. */
  10738. case EM_PPC64:
  10739. return reloc_type == 26; /* R_PPC64_REL32. */
  10740. case EM_S390_OLD:
  10741. case EM_S390:
  10742. return reloc_type == 5; /* R_390_PC32. */
  10743. case EM_SH:
  10744. return reloc_type == 2; /* R_SH_REL32. */
  10745. case EM_SPARC32PLUS:
  10746. case EM_SPARCV9:
  10747. case EM_SPARC:
  10748. return reloc_type == 6; /* R_SPARC_DISP32. */
  10749. case EM_SPU:
  10750. return reloc_type == 13; /* R_SPU_REL32. */
  10751. case EM_TILEGX:
  10752. return reloc_type == 6; /* R_TILEGX_32_PCREL. */
  10753. case EM_TILEPRO:
  10754. return reloc_type == 4; /* R_TILEPRO_32_PCREL. */
  10755. case EM_VISIUM:
  10756. return reloc_type == 6; /* R_VISIUM_32_PCREL */
  10757. case EM_X86_64:
  10758. case EM_L1OM:
  10759. case EM_K1OM:
  10760. return reloc_type == 2; /* R_X86_64_PC32. */
  10761. case EM_XTENSA_OLD:
  10762. case EM_XTENSA:
  10763. return reloc_type == 14; /* R_XTENSA_32_PCREL. */
  10764. default:
  10765. /* Do not abort or issue an error message here. Not all targets use
  10766. pc-relative 32-bit relocs in their DWARF debug information and we
  10767. have already tested for target coverage in is_32bit_abs_reloc. A
  10768. more helpful warning message will be generated by apply_relocations
  10769. anyway, so just return. */
  10770. return FALSE;
  10771. }
  10772. }
  10773. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  10774. a 64-bit absolute RELA relocation used in DWARF debug sections. */
  10775. static bfd_boolean
  10776. is_64bit_abs_reloc (unsigned int reloc_type)
  10777. {
  10778. switch (elf_header.e_machine)
  10779. {
  10780. case EM_AARCH64:
  10781. return reloc_type == 257; /* R_AARCH64_ABS64. */
  10782. case EM_ALPHA:
  10783. return reloc_type == 2; /* R_ALPHA_REFQUAD. */
  10784. case EM_IA_64:
  10785. return reloc_type == 0x27; /* R_IA64_DIR64LSB. */
  10786. case EM_PARISC:
  10787. return reloc_type == 80; /* R_PARISC_DIR64. */
  10788. case EM_PPC64:
  10789. return reloc_type == 38; /* R_PPC64_ADDR64. */
  10790. case EM_RISCV:
  10791. return reloc_type == 2; /* R_RISCV_64. */
  10792. case EM_SPARC32PLUS:
  10793. case EM_SPARCV9:
  10794. case EM_SPARC:
  10795. return reloc_type == 54; /* R_SPARC_UA64. */
  10796. case EM_X86_64:
  10797. case EM_L1OM:
  10798. case EM_K1OM:
  10799. return reloc_type == 1; /* R_X86_64_64. */
  10800. case EM_S390_OLD:
  10801. case EM_S390:
  10802. return reloc_type == 22; /* R_S390_64. */
  10803. case EM_TILEGX:
  10804. return reloc_type == 1; /* R_TILEGX_64. */
  10805. case EM_MIPS:
  10806. return reloc_type == 18; /* R_MIPS_64. */
  10807. default:
  10808. return FALSE;
  10809. }
  10810. }
  10811. /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is
  10812. a 64-bit pc-relative RELA relocation used in DWARF debug sections. */
  10813. static bfd_boolean
  10814. is_64bit_pcrel_reloc (unsigned int reloc_type)
  10815. {
  10816. switch (elf_header.e_machine)
  10817. {
  10818. case EM_AARCH64:
  10819. return reloc_type == 260; /* R_AARCH64_PREL64. */
  10820. case EM_ALPHA:
  10821. return reloc_type == 11; /* R_ALPHA_SREL64. */
  10822. case EM_IA_64:
  10823. return reloc_type == 0x4f; /* R_IA64_PCREL64LSB. */
  10824. case EM_PARISC:
  10825. return reloc_type == 72; /* R_PARISC_PCREL64. */
  10826. case EM_PPC64:
  10827. return reloc_type == 44; /* R_PPC64_REL64. */
  10828. case EM_SPARC32PLUS:
  10829. case EM_SPARCV9:
  10830. case EM_SPARC:
  10831. return reloc_type == 46; /* R_SPARC_DISP64. */
  10832. case EM_X86_64:
  10833. case EM_L1OM:
  10834. case EM_K1OM:
  10835. return reloc_type == 24; /* R_X86_64_PC64. */
  10836. case EM_S390_OLD:
  10837. case EM_S390:
  10838. return reloc_type == 23; /* R_S390_PC64. */
  10839. case EM_TILEGX:
  10840. return reloc_type == 5; /* R_TILEGX_64_PCREL. */
  10841. default:
  10842. return FALSE;
  10843. }
  10844. }
  10845. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  10846. a 24-bit absolute RELA relocation used in DWARF debug sections. */
  10847. static bfd_boolean
  10848. is_24bit_abs_reloc (unsigned int reloc_type)
  10849. {
  10850. switch (elf_header.e_machine)
  10851. {
  10852. case EM_CYGNUS_MN10200:
  10853. case EM_MN10200:
  10854. return reloc_type == 4; /* R_MN10200_24. */
  10855. case EM_FT32:
  10856. return reloc_type == 5; /* R_FT32_20. */
  10857. default:
  10858. return FALSE;
  10859. }
  10860. }
  10861. /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
  10862. a 16-bit absolute RELA relocation used in DWARF debug sections. */
  10863. static bfd_boolean
  10864. is_16bit_abs_reloc (unsigned int reloc_type)
  10865. {
  10866. /* Please keep this table alpha-sorted for ease of visual lookup. */
  10867. switch (elf_header.e_machine)
  10868. {
  10869. case EM_ARC:
  10870. case EM_ARC_COMPACT:
  10871. case EM_ARC_COMPACT2:
  10872. return reloc_type == 2; /* R_ARC_16. */
  10873. case EM_ADAPTEVA_EPIPHANY:
  10874. return reloc_type == 5;
  10875. case EM_AVR_OLD:
  10876. case EM_AVR:
  10877. return reloc_type == 4; /* R_AVR_16. */
  10878. case EM_CYGNUS_D10V:
  10879. case EM_D10V:
  10880. return reloc_type == 3; /* R_D10V_16. */
  10881. case EM_H8S:
  10882. case EM_H8_300:
  10883. case EM_H8_300H:
  10884. return reloc_type == R_H8_DIR16;
  10885. case EM_IP2K_OLD:
  10886. case EM_IP2K:
  10887. return reloc_type == 1; /* R_IP2K_16. */
  10888. case EM_M32C_OLD:
  10889. case EM_M32C:
  10890. return reloc_type == 1; /* R_M32C_16 */
  10891. case EM_CYGNUS_MN10200:
  10892. case EM_MN10200:
  10893. return reloc_type == 2; /* R_MN10200_16. */
  10894. case EM_CYGNUS_MN10300:
  10895. case EM_MN10300:
  10896. return reloc_type == 2; /* R_MN10300_16. */
  10897. case EM_MSP430:
  10898. if (uses_msp430x_relocs ())
  10899. return reloc_type == 2; /* R_MSP430_ABS16. */
  10900. /* Fall through. */
  10901. case EM_MSP430_OLD:
  10902. return reloc_type == 5; /* R_MSP430_16_BYTE. */
  10903. case EM_NDS32:
  10904. return reloc_type == 19; /* R_NDS32_RELA. */
  10905. case EM_ALTERA_NIOS2:
  10906. return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */
  10907. case EM_NIOS32:
  10908. return reloc_type == 9; /* R_NIOS_16. */
  10909. case EM_OR1K:
  10910. return reloc_type == 2; /* R_OR1K_16. */
  10911. case EM_TI_PRU:
  10912. return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */
  10913. case EM_TI_C6000:
  10914. return reloc_type == 2; /* R_C6000_ABS16. */
  10915. case EM_VISIUM:
  10916. return reloc_type == 2; /* R_VISIUM_16. */
  10917. case EM_XC16X:
  10918. case EM_C166:
  10919. return reloc_type == 2; /* R_XC16C_ABS_16. */
  10920. case EM_XGATE:
  10921. return reloc_type == 3; /* R_XGATE_16. */
  10922. default:
  10923. return FALSE;
  10924. }
  10925. }
  10926. /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
  10927. relocation entries (possibly formerly used for SHT_GROUP sections). */
  10928. static bfd_boolean
  10929. is_none_reloc (unsigned int reloc_type)
  10930. {
  10931. switch (elf_header.e_machine)
  10932. {
  10933. case EM_386: /* R_386_NONE. */
  10934. case EM_68K: /* R_68K_NONE. */
  10935. case EM_ADAPTEVA_EPIPHANY:
  10936. case EM_ALPHA: /* R_ALPHA_NONE. */
  10937. case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */
  10938. case EM_ARC: /* R_ARC_NONE. */
  10939. case EM_ARC_COMPACT2: /* R_ARC_NONE. */
  10940. case EM_ARC_COMPACT: /* R_ARC_NONE. */
  10941. case EM_ARM: /* R_ARM_NONE. */
  10942. case EM_C166: /* R_XC16X_NONE. */
  10943. case EM_CRIS: /* R_CRIS_NONE. */
  10944. case EM_FT32: /* R_FT32_NONE. */
  10945. case EM_IA_64: /* R_IA64_NONE. */
  10946. case EM_K1OM: /* R_X86_64_NONE. */
  10947. case EM_L1OM: /* R_X86_64_NONE. */
  10948. case EM_M32R: /* R_M32R_NONE. */
  10949. case EM_MIPS: /* R_MIPS_NONE. */
  10950. case EM_MN10300: /* R_MN10300_NONE. */
  10951. case EM_MOXIE: /* R_MOXIE_NONE. */
  10952. case EM_NIOS32: /* R_NIOS_NONE. */
  10953. case EM_OR1K: /* R_OR1K_NONE. */
  10954. case EM_PARISC: /* R_PARISC_NONE. */
  10955. case EM_PPC64: /* R_PPC64_NONE. */
  10956. case EM_PPC: /* R_PPC_NONE. */
  10957. case EM_RISCV: /* R_RISCV_NONE. */
  10958. case EM_S390: /* R_390_NONE. */
  10959. case EM_S390_OLD:
  10960. case EM_SH: /* R_SH_NONE. */
  10961. case EM_SPARC32PLUS:
  10962. case EM_SPARC: /* R_SPARC_NONE. */
  10963. case EM_SPARCV9:
  10964. case EM_TILEGX: /* R_TILEGX_NONE. */
  10965. case EM_TILEPRO: /* R_TILEPRO_NONE. */
  10966. case EM_TI_C6000:/* R_C6000_NONE. */
  10967. case EM_X86_64: /* R_X86_64_NONE. */
  10968. case EM_XC16X:
  10969. case EM_WEBASSEMBLY: /* R_WASM32_NONE. */
  10970. return reloc_type == 0;
  10971. case EM_AARCH64:
  10972. return reloc_type == 0 || reloc_type == 256;
  10973. case EM_AVR_OLD:
  10974. case EM_AVR:
  10975. return (reloc_type == 0 /* R_AVR_NONE. */
  10976. || reloc_type == 30 /* R_AVR_DIFF8. */
  10977. || reloc_type == 31 /* R_AVR_DIFF16. */
  10978. || reloc_type == 32 /* R_AVR_DIFF32. */);
  10979. case EM_METAG:
  10980. return reloc_type == 3; /* R_METAG_NONE. */
  10981. case EM_NDS32:
  10982. return (reloc_type == 0 /* R_XTENSA_NONE. */
  10983. || reloc_type == 204 /* R_NDS32_DIFF8. */
  10984. || reloc_type == 205 /* R_NDS32_DIFF16. */
  10985. || reloc_type == 206 /* R_NDS32_DIFF32. */
  10986. || reloc_type == 207 /* R_NDS32_ULEB128. */);
  10987. case EM_TI_PRU:
  10988. return (reloc_type == 0 /* R_PRU_NONE. */
  10989. || reloc_type == 65 /* R_PRU_DIFF8. */
  10990. || reloc_type == 66 /* R_PRU_DIFF16. */
  10991. || reloc_type == 67 /* R_PRU_DIFF32. */);
  10992. case EM_XTENSA_OLD:
  10993. case EM_XTENSA:
  10994. return (reloc_type == 0 /* R_XTENSA_NONE. */
  10995. || reloc_type == 17 /* R_XTENSA_DIFF8. */
  10996. || reloc_type == 18 /* R_XTENSA_DIFF16. */
  10997. || reloc_type == 19 /* R_XTENSA_DIFF32. */);
  10998. }
  10999. return FALSE;
  11000. }
  11001. /* Returns TRUE if there is a relocation against
  11002. section NAME at OFFSET bytes. */
  11003. bfd_boolean
  11004. reloc_at (struct dwarf_section * dsec, dwarf_vma offset)
  11005. {
  11006. Elf_Internal_Rela * relocs;
  11007. Elf_Internal_Rela * rp;
  11008. if (dsec == NULL || dsec->reloc_info == NULL)
  11009. return FALSE;
  11010. relocs = (Elf_Internal_Rela *) dsec->reloc_info;
  11011. for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp)
  11012. if (rp->r_offset == offset)
  11013. return TRUE;
  11014. return FALSE;
  11015. }
  11016. /* Apply relocations to a section.
  11017. Returns TRUE upon success, FALSE otherwise.
  11018. If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs.
  11019. It is then the caller's responsibility to free them. NUM_RELOCS_RETURN
  11020. will be set to the number of relocs loaded.
  11021. Note: So far support has been added only for those relocations
  11022. which can be found in debug sections. FIXME: Add support for
  11023. more relocations ? */
  11024. static bfd_boolean
  11025. apply_relocations (void * file,
  11026. const Elf_Internal_Shdr * section,
  11027. unsigned char * start,
  11028. bfd_size_type size,
  11029. void ** relocs_return,
  11030. unsigned long * num_relocs_return)
  11031. {
  11032. Elf_Internal_Shdr * relsec;
  11033. unsigned char * end = start + size;
  11034. bfd_boolean res = TRUE;
  11035. if (relocs_return != NULL)
  11036. {
  11037. * (Elf_Internal_Rela **) relocs_return = NULL;
  11038. * num_relocs_return = 0;
  11039. }
  11040. if (elf_header.e_type != ET_REL)
  11041. /* No relocs to apply. */
  11042. return TRUE;
  11043. /* Find the reloc section associated with the section. */
  11044. for (relsec = section_headers;
  11045. relsec < section_headers + elf_header.e_shnum;
  11046. ++relsec)
  11047. {
  11048. bfd_boolean is_rela;
  11049. unsigned long num_relocs;
  11050. Elf_Internal_Rela * relocs;
  11051. Elf_Internal_Rela * rp;
  11052. Elf_Internal_Shdr * symsec;
  11053. Elf_Internal_Sym * symtab;
  11054. unsigned long num_syms;
  11055. Elf_Internal_Sym * sym;
  11056. if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
  11057. || relsec->sh_info >= elf_header.e_shnum
  11058. || section_headers + relsec->sh_info != section
  11059. || relsec->sh_size == 0
  11060. || relsec->sh_link >= elf_header.e_shnum)
  11061. continue;
  11062. is_rela = relsec->sh_type == SHT_RELA;
  11063. if (is_rela)
  11064. {
  11065. if (!slurp_rela_relocs ((FILE *) file, relsec->sh_offset,
  11066. relsec->sh_size, & relocs, & num_relocs))
  11067. return FALSE;
  11068. }
  11069. else
  11070. {
  11071. if (!slurp_rel_relocs ((FILE *) file, relsec->sh_offset,
  11072. relsec->sh_size, & relocs, & num_relocs))
  11073. return FALSE;
  11074. }
  11075. /* SH uses RELA but uses in place value instead of the addend field. */
  11076. if (elf_header.e_machine == EM_SH)
  11077. is_rela = FALSE;
  11078. symsec = section_headers + relsec->sh_link;
  11079. if (symsec->sh_type != SHT_SYMTAB
  11080. && symsec->sh_type != SHT_DYNSYM)
  11081. return FALSE;
  11082. symtab = GET_ELF_SYMBOLS ((FILE *) file, symsec, & num_syms);
  11083. for (rp = relocs; rp < relocs + num_relocs; ++rp)
  11084. {
  11085. bfd_vma addend;
  11086. unsigned int reloc_type;
  11087. unsigned int reloc_size;
  11088. unsigned char * rloc;
  11089. unsigned long sym_index;
  11090. reloc_type = get_reloc_type (rp->r_info);
  11091. if (target_specific_reloc_handling (rp, start, end, symtab, num_syms))
  11092. continue;
  11093. else if (is_none_reloc (reloc_type))
  11094. continue;
  11095. else if (is_32bit_abs_reloc (reloc_type)
  11096. || is_32bit_pcrel_reloc (reloc_type))
  11097. reloc_size = 4;
  11098. else if (is_64bit_abs_reloc (reloc_type)
  11099. || is_64bit_pcrel_reloc (reloc_type))
  11100. reloc_size = 8;
  11101. else if (is_24bit_abs_reloc (reloc_type))
  11102. reloc_size = 3;
  11103. else if (is_16bit_abs_reloc (reloc_type))
  11104. reloc_size = 2;
  11105. else
  11106. {
  11107. static unsigned int prev_reloc = 0;
  11108. if (reloc_type != prev_reloc)
  11109. warn (_("unable to apply unsupported reloc type %d to section %s\n"),
  11110. reloc_type, printable_section_name (section));
  11111. prev_reloc = reloc_type;
  11112. res = FALSE;
  11113. continue;
  11114. }
  11115. rloc = start + rp->r_offset;
  11116. if ((rloc + reloc_size) > end || (rloc < start))
  11117. {
  11118. warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
  11119. (unsigned long) rp->r_offset,
  11120. printable_section_name (section));
  11121. res = FALSE;
  11122. continue;
  11123. }
  11124. sym_index = (unsigned long) get_reloc_symindex (rp->r_info);
  11125. if (sym_index >= num_syms)
  11126. {
  11127. warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"),
  11128. sym_index, printable_section_name (section));
  11129. res = FALSE;
  11130. continue;
  11131. }
  11132. sym = symtab + sym_index;
  11133. /* If the reloc has a symbol associated with it,
  11134. make sure that it is of an appropriate type.
  11135. Relocations against symbols without type can happen.
  11136. Gcc -feliminate-dwarf2-dups may generate symbols
  11137. without type for debug info.
  11138. Icc generates relocations against function symbols
  11139. instead of local labels.
  11140. Relocations against object symbols can happen, eg when
  11141. referencing a global array. For an example of this see
  11142. the _clz.o binary in libgcc.a. */
  11143. if (sym != symtab
  11144. && ELF_ST_TYPE (sym->st_info) != STT_COMMON
  11145. && ELF_ST_TYPE (sym->st_info) > STT_SECTION)
  11146. {
  11147. warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
  11148. get_symbol_type (ELF_ST_TYPE (sym->st_info)),
  11149. (long int)(rp - relocs),
  11150. printable_section_name (relsec));
  11151. res = FALSE;
  11152. continue;
  11153. }
  11154. addend = 0;
  11155. if (is_rela)
  11156. addend += rp->r_addend;
  11157. /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are
  11158. partial_inplace. */
  11159. if (!is_rela
  11160. || (elf_header.e_machine == EM_XTENSA
  11161. && reloc_type == 1)
  11162. || ((elf_header.e_machine == EM_PJ
  11163. || elf_header.e_machine == EM_PJ_OLD)
  11164. && reloc_type == 1)
  11165. || ((elf_header.e_machine == EM_D30V
  11166. || elf_header.e_machine == EM_CYGNUS_D30V)
  11167. && reloc_type == 12))
  11168. addend += byte_get (rloc, reloc_size);
  11169. if (is_32bit_pcrel_reloc (reloc_type)
  11170. || is_64bit_pcrel_reloc (reloc_type))
  11171. {
  11172. /* On HPPA, all pc-relative relocations are biased by 8. */
  11173. if (elf_header.e_machine == EM_PARISC)
  11174. addend -= 8;
  11175. byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
  11176. reloc_size);
  11177. }
  11178. else
  11179. byte_put (rloc, addend + sym->st_value, reloc_size);
  11180. }
  11181. free (symtab);
  11182. /* Let the target specific reloc processing code know that
  11183. we have finished with these relocs. */
  11184. target_specific_reloc_handling (NULL, NULL, NULL, NULL, 0);
  11185. if (relocs_return)
  11186. {
  11187. * (Elf_Internal_Rela **) relocs_return = relocs;
  11188. * num_relocs_return = num_relocs;
  11189. }
  11190. else
  11191. free (relocs);
  11192. break;
  11193. }
  11194. return res;
  11195. }
  11196. #ifdef SUPPORT_DISASSEMBLY
  11197. static bfd_boolean
  11198. disassemble_section (Elf_Internal_Shdr * section, FILE * file)
  11199. {
  11200. printf (_("\nAssembly dump of section %s\n"), printable_section_name (section));
  11201. /* FIXME: XXX -- to be done --- XXX */
  11202. return TRUE;
  11203. }
  11204. #endif
  11205. /* Reads in the contents of SECTION from FILE, returning a pointer
  11206. to a malloc'ed buffer or NULL if something went wrong. */
  11207. static char *
  11208. get_section_contents (Elf_Internal_Shdr * section, FILE * file)
  11209. {
  11210. bfd_size_type num_bytes;
  11211. num_bytes = section->sh_size;
  11212. if (num_bytes == 0 || section->sh_type == SHT_NOBITS)
  11213. {
  11214. printf (_("\nSection '%s' has no data to dump.\n"),
  11215. printable_section_name (section));
  11216. return NULL;
  11217. }
  11218. return (char *) get_data (NULL, file, section->sh_offset, 1, num_bytes,
  11219. _("section contents"));
  11220. }
  11221. /* Uncompresses a section that was compressed using zlib, in place. */
  11222. static bfd_boolean
  11223. uncompress_section_contents (unsigned char **buffer,
  11224. dwarf_size_type uncompressed_size,
  11225. dwarf_size_type *size)
  11226. {
  11227. dwarf_size_type compressed_size = *size;
  11228. unsigned char * compressed_buffer = *buffer;
  11229. unsigned char * uncompressed_buffer;
  11230. z_stream strm;
  11231. int rc;
  11232. /* It is possible the section consists of several compressed
  11233. buffers concatenated together, so we uncompress in a loop. */
  11234. /* PR 18313: The state field in the z_stream structure is supposed
  11235. to be invisible to the user (ie us), but some compilers will
  11236. still complain about it being used without initialisation. So
  11237. we first zero the entire z_stream structure and then set the fields
  11238. that we need. */
  11239. memset (& strm, 0, sizeof strm);
  11240. strm.avail_in = compressed_size;
  11241. strm.next_in = (Bytef *) compressed_buffer;
  11242. strm.avail_out = uncompressed_size;
  11243. uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
  11244. rc = inflateInit (& strm);
  11245. while (strm.avail_in > 0)
  11246. {
  11247. if (rc != Z_OK)
  11248. goto fail;
  11249. strm.next_out = ((Bytef *) uncompressed_buffer
  11250. + (uncompressed_size - strm.avail_out));
  11251. rc = inflate (&strm, Z_FINISH);
  11252. if (rc != Z_STREAM_END)
  11253. goto fail;
  11254. rc = inflateReset (& strm);
  11255. }
  11256. rc = inflateEnd (& strm);
  11257. if (rc != Z_OK
  11258. || strm.avail_out != 0)
  11259. goto fail;
  11260. *buffer = uncompressed_buffer;
  11261. *size = uncompressed_size;
  11262. return TRUE;
  11263. fail:
  11264. free (uncompressed_buffer);
  11265. /* Indicate decompression failure. */
  11266. *buffer = NULL;
  11267. return FALSE;
  11268. }
  11269. static bfd_boolean
  11270. dump_section_as_strings (Elf_Internal_Shdr * section, FILE * file)
  11271. {
  11272. Elf_Internal_Shdr * relsec;
  11273. bfd_size_type num_bytes;
  11274. unsigned char * data;
  11275. unsigned char * end;
  11276. unsigned char * real_start;
  11277. unsigned char * start;
  11278. bfd_boolean some_strings_shown;
  11279. real_start = start = (unsigned char *) get_section_contents (section,
  11280. file);
  11281. if (start == NULL)
  11282. /* PR 21820: Do not fail if the section was empty. */
  11283. return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
  11284. num_bytes = section->sh_size;
  11285. printf (_("\nString dump of section '%s':\n"), printable_section_name (section));
  11286. if (decompress_dumps)
  11287. {
  11288. dwarf_size_type new_size = num_bytes;
  11289. dwarf_size_type uncompressed_size = 0;
  11290. if ((section->sh_flags & SHF_COMPRESSED) != 0)
  11291. {
  11292. Elf_Internal_Chdr chdr;
  11293. unsigned int compression_header_size
  11294. = get_compression_header (& chdr, (unsigned char *) start,
  11295. num_bytes);
  11296. if (chdr.ch_type != ELFCOMPRESS_ZLIB)
  11297. {
  11298. warn (_("section '%s' has unsupported compress type: %d\n"),
  11299. printable_section_name (section), chdr.ch_type);
  11300. return FALSE;
  11301. }
  11302. else if (chdr.ch_addralign != section->sh_addralign)
  11303. {
  11304. warn (_("compressed section '%s' is corrupted\n"),
  11305. printable_section_name (section));
  11306. return FALSE;
  11307. }
  11308. uncompressed_size = chdr.ch_size;
  11309. start += compression_header_size;
  11310. new_size -= compression_header_size;
  11311. }
  11312. else if (new_size > 12 && streq ((char *) start, "ZLIB"))
  11313. {
  11314. /* Read the zlib header. In this case, it should be "ZLIB"
  11315. followed by the uncompressed section size, 8 bytes in
  11316. big-endian order. */
  11317. uncompressed_size = start[4]; uncompressed_size <<= 8;
  11318. uncompressed_size += start[5]; uncompressed_size <<= 8;
  11319. uncompressed_size += start[6]; uncompressed_size <<= 8;
  11320. uncompressed_size += start[7]; uncompressed_size <<= 8;
  11321. uncompressed_size += start[8]; uncompressed_size <<= 8;
  11322. uncompressed_size += start[9]; uncompressed_size <<= 8;
  11323. uncompressed_size += start[10]; uncompressed_size <<= 8;
  11324. uncompressed_size += start[11];
  11325. start += 12;
  11326. new_size -= 12;
  11327. }
  11328. if (uncompressed_size)
  11329. {
  11330. if (uncompress_section_contents (& start,
  11331. uncompressed_size, & new_size))
  11332. num_bytes = new_size;
  11333. else
  11334. {
  11335. error (_("Unable to decompress section %s\n"),
  11336. printable_section_name (section));
  11337. return FALSE;
  11338. }
  11339. }
  11340. else
  11341. start = real_start;
  11342. }
  11343. /* If the section being dumped has relocations against it the user might
  11344. be expecting these relocations to have been applied. Check for this
  11345. case and issue a warning message in order to avoid confusion.
  11346. FIXME: Maybe we ought to have an option that dumps a section with
  11347. relocs applied ? */
  11348. for (relsec = section_headers;
  11349. relsec < section_headers + elf_header.e_shnum;
  11350. ++relsec)
  11351. {
  11352. if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
  11353. || relsec->sh_info >= elf_header.e_shnum
  11354. || section_headers + relsec->sh_info != section
  11355. || relsec->sh_size == 0
  11356. || relsec->sh_link >= elf_header.e_shnum)
  11357. continue;
  11358. printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
  11359. break;
  11360. }
  11361. data = start;
  11362. end = start + num_bytes;
  11363. some_strings_shown = FALSE;
  11364. while (data < end)
  11365. {
  11366. while (!ISPRINT (* data))
  11367. if (++ data >= end)
  11368. break;
  11369. if (data < end)
  11370. {
  11371. size_t maxlen = end - data;
  11372. #ifndef __MSVCRT__
  11373. /* PR 11128: Use two separate invocations in order to work
  11374. around bugs in the Solaris 8 implementation of printf. */
  11375. printf (" [%6tx] ", data - start);
  11376. #else
  11377. printf (" [%6Ix] ", (size_t) (data - start));
  11378. #endif
  11379. if (maxlen > 0)
  11380. {
  11381. print_symbol ((int) maxlen, (const char *) data);
  11382. putchar ('\n');
  11383. data += strnlen ((const char *) data, maxlen);
  11384. }
  11385. else
  11386. {
  11387. printf (_("<corrupt>\n"));
  11388. data = end;
  11389. }
  11390. some_strings_shown = TRUE;
  11391. }
  11392. }
  11393. if (! some_strings_shown)
  11394. printf (_(" No strings found in this section."));
  11395. free (real_start);
  11396. putchar ('\n');
  11397. return TRUE;
  11398. }
  11399. static bfd_boolean
  11400. dump_section_as_bytes (Elf_Internal_Shdr * section,
  11401. FILE * file,
  11402. bfd_boolean relocate)
  11403. {
  11404. Elf_Internal_Shdr * relsec;
  11405. bfd_size_type bytes;
  11406. bfd_size_type section_size;
  11407. bfd_vma addr;
  11408. unsigned char * data;
  11409. unsigned char * real_start;
  11410. unsigned char * start;
  11411. real_start = start = (unsigned char *) get_section_contents (section, file);
  11412. if (start == NULL)
  11413. /* PR 21820: Do not fail if the section was empty. */
  11414. return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE;
  11415. section_size = section->sh_size;
  11416. printf (_("\nHex dump of section '%s':\n"), printable_section_name (section));
  11417. if (decompress_dumps)
  11418. {
  11419. dwarf_size_type new_size = section_size;
  11420. dwarf_size_type uncompressed_size = 0;
  11421. if ((section->sh_flags & SHF_COMPRESSED) != 0)
  11422. {
  11423. Elf_Internal_Chdr chdr;
  11424. unsigned int compression_header_size
  11425. = get_compression_header (& chdr, start, section_size);
  11426. if (chdr.ch_type != ELFCOMPRESS_ZLIB)
  11427. {
  11428. warn (_("section '%s' has unsupported compress type: %d\n"),
  11429. printable_section_name (section), chdr.ch_type);
  11430. return FALSE;
  11431. }
  11432. else if (chdr.ch_addralign != section->sh_addralign)
  11433. {
  11434. warn (_("compressed section '%s' is corrupted\n"),
  11435. printable_section_name (section));
  11436. return FALSE;
  11437. }
  11438. uncompressed_size = chdr.ch_size;
  11439. start += compression_header_size;
  11440. new_size -= compression_header_size;
  11441. }
  11442. else if (new_size > 12 && streq ((char *) start, "ZLIB"))
  11443. {
  11444. /* Read the zlib header. In this case, it should be "ZLIB"
  11445. followed by the uncompressed section size, 8 bytes in
  11446. big-endian order. */
  11447. uncompressed_size = start[4]; uncompressed_size <<= 8;
  11448. uncompressed_size += start[5]; uncompressed_size <<= 8;
  11449. uncompressed_size += start[6]; uncompressed_size <<= 8;
  11450. uncompressed_size += start[7]; uncompressed_size <<= 8;
  11451. uncompressed_size += start[8]; uncompressed_size <<= 8;
  11452. uncompressed_size += start[9]; uncompressed_size <<= 8;
  11453. uncompressed_size += start[10]; uncompressed_size <<= 8;
  11454. uncompressed_size += start[11];
  11455. start += 12;
  11456. new_size -= 12;
  11457. }
  11458. if (uncompressed_size)
  11459. {
  11460. if (uncompress_section_contents (& start, uncompressed_size,
  11461. & new_size))
  11462. {
  11463. section_size = new_size;
  11464. }
  11465. else
  11466. {
  11467. error (_("Unable to decompress section %s\n"),
  11468. printable_section_name (section));
  11469. /* FIXME: Print the section anyway ? */
  11470. return FALSE;
  11471. }
  11472. }
  11473. else
  11474. start = real_start;
  11475. }
  11476. if (relocate)
  11477. {
  11478. if (! apply_relocations (file, section, start, section_size, NULL, NULL))
  11479. return FALSE;
  11480. }
  11481. else
  11482. {
  11483. /* If the section being dumped has relocations against it the user might
  11484. be expecting these relocations to have been applied. Check for this
  11485. case and issue a warning message in order to avoid confusion.
  11486. FIXME: Maybe we ought to have an option that dumps a section with
  11487. relocs applied ? */
  11488. for (relsec = section_headers;
  11489. relsec < section_headers + elf_header.e_shnum;
  11490. ++relsec)
  11491. {
  11492. if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
  11493. || relsec->sh_info >= elf_header.e_shnum
  11494. || section_headers + relsec->sh_info != section
  11495. || relsec->sh_size == 0
  11496. || relsec->sh_link >= elf_header.e_shnum)
  11497. continue;
  11498. printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
  11499. break;
  11500. }
  11501. }
  11502. addr = section->sh_addr;
  11503. bytes = section_size;
  11504. data = start;
  11505. while (bytes)
  11506. {
  11507. int j;
  11508. int k;
  11509. int lbytes;
  11510. lbytes = (bytes > 16 ? 16 : bytes);
  11511. printf (" 0x%8.8lx ", (unsigned long) addr);
  11512. for (j = 0; j < 16; j++)
  11513. {
  11514. if (j < lbytes)
  11515. printf ("%2.2x", data[j]);
  11516. else
  11517. printf (" ");
  11518. if ((j & 3) == 3)
  11519. printf (" ");
  11520. }
  11521. for (j = 0; j < lbytes; j++)
  11522. {
  11523. k = data[j];
  11524. if (k >= ' ' && k < 0x7f)
  11525. printf ("%c", k);
  11526. else
  11527. printf (".");
  11528. }
  11529. putchar ('\n');
  11530. data += lbytes;
  11531. addr += lbytes;
  11532. bytes -= lbytes;
  11533. }
  11534. free (real_start);
  11535. putchar ('\n');
  11536. return TRUE;
  11537. }
  11538. static bfd_boolean
  11539. load_specific_debug_section (enum dwarf_section_display_enum debug,
  11540. const Elf_Internal_Shdr * sec, void * file)
  11541. {
  11542. struct dwarf_section * section = &debug_displays [debug].section;
  11543. char buf [64];
  11544. /* If it is already loaded, do nothing. */
  11545. if (section->start != NULL)
  11546. return TRUE;
  11547. snprintf (buf, sizeof (buf), _("%s section data"), section->name);
  11548. section->address = sec->sh_addr;
  11549. section->user_data = NULL;
  11550. section->start = (unsigned char *) get_data (NULL, (FILE *) file,
  11551. sec->sh_offset, 1,
  11552. sec->sh_size, buf);
  11553. if (section->start == NULL)
  11554. section->size = 0;
  11555. else
  11556. {
  11557. unsigned char *start = section->start;
  11558. dwarf_size_type size = sec->sh_size;
  11559. dwarf_size_type uncompressed_size = 0;
  11560. if ((sec->sh_flags & SHF_COMPRESSED) != 0)
  11561. {
  11562. Elf_Internal_Chdr chdr;
  11563. unsigned int compression_header_size;
  11564. if (size < (is_32bit_elf
  11565. ? sizeof (Elf32_External_Chdr)
  11566. : sizeof (Elf64_External_Chdr)))
  11567. {
  11568. warn (_("compressed section %s is too small to contain a compression header"),
  11569. section->name);
  11570. return FALSE;
  11571. }
  11572. compression_header_size = get_compression_header (&chdr, start, size);
  11573. if (chdr.ch_type != ELFCOMPRESS_ZLIB)
  11574. {
  11575. warn (_("section '%s' has unsupported compress type: %d\n"),
  11576. section->name, chdr.ch_type);
  11577. return FALSE;
  11578. }
  11579. else if (chdr.ch_addralign != sec->sh_addralign)
  11580. {
  11581. warn (_("compressed section '%s' is corrupted\n"),
  11582. section->name);
  11583. return FALSE;
  11584. }
  11585. uncompressed_size = chdr.ch_size;
  11586. start += compression_header_size;
  11587. size -= compression_header_size;
  11588. }
  11589. else if (size > 12 && streq ((char *) start, "ZLIB"))
  11590. {
  11591. /* Read the zlib header. In this case, it should be "ZLIB"
  11592. followed by the uncompressed section size, 8 bytes in
  11593. big-endian order. */
  11594. uncompressed_size = start[4]; uncompressed_size <<= 8;
  11595. uncompressed_size += start[5]; uncompressed_size <<= 8;
  11596. uncompressed_size += start[6]; uncompressed_size <<= 8;
  11597. uncompressed_size += start[7]; uncompressed_size <<= 8;
  11598. uncompressed_size += start[8]; uncompressed_size <<= 8;
  11599. uncompressed_size += start[9]; uncompressed_size <<= 8;
  11600. uncompressed_size += start[10]; uncompressed_size <<= 8;
  11601. uncompressed_size += start[11];
  11602. start += 12;
  11603. size -= 12;
  11604. }
  11605. if (uncompressed_size)
  11606. {
  11607. if (uncompress_section_contents (&start, uncompressed_size,
  11608. &size))
  11609. {
  11610. /* Free the compressed buffer, update the section buffer
  11611. and the section size if uncompress is successful. */
  11612. free (section->start);
  11613. section->start = start;
  11614. }
  11615. else
  11616. {
  11617. error (_("Unable to decompress section %s\n"),
  11618. printable_section_name (sec));
  11619. return FALSE;
  11620. }
  11621. }
  11622. section->size = size;
  11623. }
  11624. if (section->start == NULL)
  11625. return FALSE;
  11626. if (debug_displays [debug].relocate)
  11627. {
  11628. if (! apply_relocations ((FILE *) file, sec, section->start, section->size,
  11629. & section->reloc_info, & section->num_relocs))
  11630. return FALSE;
  11631. }
  11632. else
  11633. {
  11634. section->reloc_info = NULL;
  11635. section->num_relocs = 0;
  11636. }
  11637. return TRUE;
  11638. }
  11639. /* If this is not NULL, load_debug_section will only look for sections
  11640. within the list of sections given here. */
  11641. static unsigned int * section_subset = NULL;
  11642. bfd_boolean
  11643. load_debug_section (enum dwarf_section_display_enum debug, void * file)
  11644. {
  11645. struct dwarf_section * section = &debug_displays [debug].section;
  11646. Elf_Internal_Shdr * sec;
  11647. /* Locate the debug section. */
  11648. sec = find_section_in_set (section->uncompressed_name, section_subset);
  11649. if (sec != NULL)
  11650. section->name = section->uncompressed_name;
  11651. else
  11652. {
  11653. sec = find_section_in_set (section->compressed_name, section_subset);
  11654. if (sec != NULL)
  11655. section->name = section->compressed_name;
  11656. }
  11657. if (sec == NULL)
  11658. return FALSE;
  11659. /* If we're loading from a subset of sections, and we've loaded
  11660. a section matching this name before, it's likely that it's a
  11661. different one. */
  11662. if (section_subset != NULL)
  11663. free_debug_section (debug);
  11664. return load_specific_debug_section (debug, sec, (FILE *) file);
  11665. }
  11666. void
  11667. free_debug_section (enum dwarf_section_display_enum debug)
  11668. {
  11669. struct dwarf_section * section = &debug_displays [debug].section;
  11670. if (section->start == NULL)
  11671. return;
  11672. free ((char *) section->start);
  11673. section->start = NULL;
  11674. section->address = 0;
  11675. section->size = 0;
  11676. }
  11677. static bfd_boolean
  11678. display_debug_section (int shndx, Elf_Internal_Shdr * section, FILE * file)
  11679. {
  11680. char * name = SECTION_NAME (section);
  11681. const char * print_name = printable_section_name (section);
  11682. bfd_size_type length;
  11683. bfd_boolean result = TRUE;
  11684. int i;
  11685. length = section->sh_size;
  11686. if (length == 0)
  11687. {
  11688. printf (_("\nSection '%s' has no debugging data.\n"), print_name);
  11689. return TRUE;
  11690. }
  11691. if (section->sh_type == SHT_NOBITS)
  11692. {
  11693. /* There is no point in dumping the contents of a debugging section
  11694. which has the NOBITS type - the bits in the file will be random.
  11695. This can happen when a file containing a .eh_frame section is
  11696. stripped with the --only-keep-debug command line option. */
  11697. printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"),
  11698. print_name);
  11699. return FALSE;
  11700. }
  11701. if (const_strneq (name, ".gnu.linkonce.wi."))
  11702. name = ".debug_info";
  11703. /* See if we know how to display the contents of this section. */
  11704. for (i = 0; i < max; i++)
  11705. if (streq (debug_displays[i].section.uncompressed_name, name)
  11706. || (i == line && const_strneq (name, ".debug_line."))
  11707. || streq (debug_displays[i].section.compressed_name, name))
  11708. {
  11709. struct dwarf_section * sec = &debug_displays [i].section;
  11710. int secondary = (section != find_section (name));
  11711. if (secondary)
  11712. free_debug_section ((enum dwarf_section_display_enum) i);
  11713. if (i == line && const_strneq (name, ".debug_line."))
  11714. sec->name = name;
  11715. else if (streq (sec->uncompressed_name, name))
  11716. sec->name = sec->uncompressed_name;
  11717. else
  11718. sec->name = sec->compressed_name;
  11719. if (load_specific_debug_section ((enum dwarf_section_display_enum) i,
  11720. section, file))
  11721. {
  11722. /* If this debug section is part of a CU/TU set in a .dwp file,
  11723. restrict load_debug_section to the sections in that set. */
  11724. section_subset = find_cu_tu_set (file, shndx);
  11725. result &= debug_displays[i].display (sec, file);
  11726. section_subset = NULL;
  11727. if (secondary || (i != info && i != abbrev))
  11728. free_debug_section ((enum dwarf_section_display_enum) i);
  11729. }
  11730. break;
  11731. }
  11732. if (i == max)
  11733. {
  11734. printf (_("Unrecognized debug section: %s\n"), print_name);
  11735. result = FALSE;
  11736. }
  11737. return result;
  11738. }
  11739. /* Set DUMP_SECTS for all sections where dumps were requested
  11740. based on section name. */
  11741. static void
  11742. initialise_dumps_byname (void)
  11743. {
  11744. struct dump_list_entry * cur;
  11745. for (cur = dump_sects_byname; cur; cur = cur->next)
  11746. {
  11747. unsigned int i;
  11748. bfd_boolean any = FALSE;
  11749. for (i = 0; i < elf_header.e_shnum; i++)
  11750. if (streq (SECTION_NAME (section_headers + i), cur->name))
  11751. {
  11752. request_dump_bynumber (i, cur->type);
  11753. any = TRUE;
  11754. }
  11755. if (!any)
  11756. warn (_("Section '%s' was not dumped because it does not exist!\n"),
  11757. cur->name);
  11758. }
  11759. }
  11760. static bfd_boolean
  11761. process_section_contents (FILE * file)
  11762. {
  11763. Elf_Internal_Shdr * section;
  11764. unsigned int i;
  11765. bfd_boolean res = TRUE;
  11766. if (! do_dump)
  11767. return TRUE;
  11768. initialise_dumps_byname ();
  11769. for (i = 0, section = section_headers;
  11770. i < elf_header.e_shnum && i < num_dump_sects;
  11771. i++, section++)
  11772. {
  11773. #ifdef SUPPORT_DISASSEMBLY
  11774. if (dump_sects[i] & DISASS_DUMP)
  11775. disassemble_section (section, file);
  11776. #endif
  11777. if (dump_sects[i] & HEX_DUMP)
  11778. {
  11779. if (! dump_section_as_bytes (section, file, FALSE))
  11780. res = FALSE;
  11781. }
  11782. if (dump_sects[i] & RELOC_DUMP)
  11783. {
  11784. if (! dump_section_as_bytes (section, file, TRUE))
  11785. res = FALSE;
  11786. }
  11787. if (dump_sects[i] & STRING_DUMP)
  11788. {
  11789. if (! dump_section_as_strings (section, file))
  11790. res = FALSE;
  11791. }
  11792. if (dump_sects[i] & DEBUG_DUMP)
  11793. {
  11794. if (! display_debug_section (i, section, file))
  11795. res = FALSE;
  11796. }
  11797. }
  11798. /* Check to see if the user requested a
  11799. dump of a section that does not exist. */
  11800. while (i < num_dump_sects)
  11801. {
  11802. if (dump_sects[i])
  11803. {
  11804. warn (_("Section %d was not dumped because it does not exist!\n"), i);
  11805. res = FALSE;
  11806. }
  11807. i++;
  11808. }
  11809. return res;
  11810. }
  11811. static void
  11812. process_mips_fpe_exception (int mask)
  11813. {
  11814. if (mask)
  11815. {
  11816. bfd_boolean first = TRUE;
  11817. if (mask & OEX_FPU_INEX)
  11818. fputs ("INEX", stdout), first = FALSE;
  11819. if (mask & OEX_FPU_UFLO)
  11820. printf ("%sUFLO", first ? "" : "|"), first = FALSE;
  11821. if (mask & OEX_FPU_OFLO)
  11822. printf ("%sOFLO", first ? "" : "|"), first = FALSE;
  11823. if (mask & OEX_FPU_DIV0)
  11824. printf ("%sDIV0", first ? "" : "|"), first = FALSE;
  11825. if (mask & OEX_FPU_INVAL)
  11826. printf ("%sINVAL", first ? "" : "|");
  11827. }
  11828. else
  11829. fputs ("0", stdout);
  11830. }
  11831. /* Display's the value of TAG at location P. If TAG is
  11832. greater than 0 it is assumed to be an unknown tag, and
  11833. a message is printed to this effect. Otherwise it is
  11834. assumed that a message has already been printed.
  11835. If the bottom bit of TAG is set it assumed to have a
  11836. string value, otherwise it is assumed to have an integer
  11837. value.
  11838. Returns an updated P pointing to the first unread byte
  11839. beyond the end of TAG's value.
  11840. Reads at or beyond END will not be made. */
  11841. static unsigned char *
  11842. display_tag_value (signed int tag,
  11843. unsigned char * p,
  11844. const unsigned char * const end)
  11845. {
  11846. unsigned long val;
  11847. if (tag > 0)
  11848. printf (" Tag_unknown_%d: ", tag);
  11849. if (p >= end)
  11850. {
  11851. warn (_("<corrupt tag>\n"));
  11852. }
  11853. else if (tag & 1)
  11854. {
  11855. /* PR 17531 file: 027-19978-0.004. */
  11856. size_t maxlen = (end - p) - 1;
  11857. putchar ('"');
  11858. if (maxlen > 0)
  11859. {
  11860. print_symbol ((int) maxlen, (const char *) p);
  11861. p += strnlen ((char *) p, maxlen) + 1;
  11862. }
  11863. else
  11864. {
  11865. printf (_("<corrupt string tag>"));
  11866. p = (unsigned char *) end;
  11867. }
  11868. printf ("\"\n");
  11869. }
  11870. else
  11871. {
  11872. unsigned int len;
  11873. val = read_uleb128 (p, &len, end);
  11874. p += len;
  11875. printf ("%ld (0x%lx)\n", val, val);
  11876. }
  11877. assert (p <= end);
  11878. return p;
  11879. }
  11880. /* ARC ABI attributes section. */
  11881. static unsigned char *
  11882. display_arc_attribute (unsigned char * p,
  11883. const unsigned char * const end)
  11884. {
  11885. unsigned int tag;
  11886. unsigned int len;
  11887. unsigned int val;
  11888. tag = read_uleb128 (p, &len, end);
  11889. p += len;
  11890. switch (tag)
  11891. {
  11892. case Tag_ARC_PCS_config:
  11893. val = read_uleb128 (p, &len, end);
  11894. p += len;
  11895. printf (" Tag_ARC_PCS_config: ");
  11896. switch (val)
  11897. {
  11898. case 0:
  11899. printf (_("Absent/Non standard\n"));
  11900. break;
  11901. case 1:
  11902. printf (_("Bare metal/mwdt\n"));
  11903. break;
  11904. case 2:
  11905. printf (_("Bare metal/newlib\n"));
  11906. break;
  11907. case 3:
  11908. printf (_("Linux/uclibc\n"));
  11909. break;
  11910. case 4:
  11911. printf (_("Linux/glibc\n"));
  11912. break;
  11913. default:
  11914. printf (_("Unknown\n"));
  11915. break;
  11916. }
  11917. break;
  11918. case Tag_ARC_CPU_base:
  11919. val = read_uleb128 (p, &len, end);
  11920. p += len;
  11921. printf (" Tag_ARC_CPU_base: ");
  11922. switch (val)
  11923. {
  11924. default:
  11925. case TAG_CPU_NONE:
  11926. printf (_("Absent\n"));
  11927. break;
  11928. case TAG_CPU_ARC6xx:
  11929. printf ("ARC6xx\n");
  11930. break;
  11931. case TAG_CPU_ARC7xx:
  11932. printf ("ARC7xx\n");
  11933. break;
  11934. case TAG_CPU_ARCEM:
  11935. printf ("ARCEM\n");
  11936. break;
  11937. case TAG_CPU_ARCHS:
  11938. printf ("ARCHS\n");
  11939. break;
  11940. }
  11941. break;
  11942. case Tag_ARC_CPU_variation:
  11943. val = read_uleb128 (p, &len, end);
  11944. p += len;
  11945. printf (" Tag_ARC_CPU_variation: ");
  11946. switch (val)
  11947. {
  11948. default:
  11949. if (val > 0 && val < 16)
  11950. printf ("Core%d\n", val);
  11951. else
  11952. printf ("Unknown\n");
  11953. break;
  11954. case 0:
  11955. printf (_("Absent\n"));
  11956. break;
  11957. }
  11958. break;
  11959. case Tag_ARC_CPU_name:
  11960. printf (" Tag_ARC_CPU_name: ");
  11961. p = display_tag_value (-1, p, end);
  11962. break;
  11963. case Tag_ARC_ABI_rf16:
  11964. val = read_uleb128 (p, &len, end);
  11965. p += len;
  11966. printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no"));
  11967. break;
  11968. case Tag_ARC_ABI_osver:
  11969. val = read_uleb128 (p, &len, end);
  11970. p += len;
  11971. printf (" Tag_ARC_ABI_osver: v%d\n", val);
  11972. break;
  11973. case Tag_ARC_ABI_pic:
  11974. case Tag_ARC_ABI_sda:
  11975. val = read_uleb128 (p, &len, end);
  11976. p += len;
  11977. printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: "
  11978. : " Tag_ARC_ABI_pic: ");
  11979. switch (val)
  11980. {
  11981. case 0:
  11982. printf (_("Absent\n"));
  11983. break;
  11984. case 1:
  11985. printf ("MWDT\n");
  11986. break;
  11987. case 2:
  11988. printf ("GNU\n");
  11989. break;
  11990. default:
  11991. printf (_("Unknown\n"));
  11992. break;
  11993. }
  11994. break;
  11995. case Tag_ARC_ABI_tls:
  11996. val = read_uleb128 (p, &len, end);
  11997. p += len;
  11998. printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none");
  11999. break;
  12000. case Tag_ARC_ABI_enumsize:
  12001. val = read_uleb128 (p, &len, end);
  12002. p += len;
  12003. printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") :
  12004. _("smallest"));
  12005. break;
  12006. case Tag_ARC_ABI_exceptions:
  12007. val = read_uleb128 (p, &len, end);
  12008. p += len;
  12009. printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP")
  12010. : _("default"));
  12011. break;
  12012. case Tag_ARC_ABI_double_size:
  12013. val = read_uleb128 (p, &len, end);
  12014. p += len;
  12015. printf (" Tag_ARC_ABI_double_size: %d\n", val);
  12016. break;
  12017. case Tag_ARC_ISA_config:
  12018. printf (" Tag_ARC_ISA_config: ");
  12019. p = display_tag_value (-1, p, end);
  12020. break;
  12021. case Tag_ARC_ISA_apex:
  12022. printf (" Tag_ARC_ISA_apex: ");
  12023. p = display_tag_value (-1, p, end);
  12024. break;
  12025. case Tag_ARC_ISA_mpy_option:
  12026. val = read_uleb128 (p, &len, end);
  12027. p += len;
  12028. printf (" Tag_ARC_ISA_mpy_option: %d\n", val);
  12029. break;
  12030. default:
  12031. return display_tag_value (tag & 1, p, end);
  12032. }
  12033. return p;
  12034. }
  12035. /* ARM EABI attributes section. */
  12036. typedef struct
  12037. {
  12038. unsigned int tag;
  12039. const char * name;
  12040. /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
  12041. unsigned int type;
  12042. const char ** table;
  12043. } arm_attr_public_tag;
  12044. static const char * arm_attr_tag_CPU_arch[] =
  12045. {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
  12046. "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline",
  12047. "v8-M.mainline"};
  12048. static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
  12049. static const char * arm_attr_tag_THUMB_ISA_use[] =
  12050. {"No", "Thumb-1", "Thumb-2", "Yes"};
  12051. static const char * arm_attr_tag_FP_arch[] =
  12052. {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16",
  12053. "FP for ARMv8", "FPv5/FP-D16 for ARMv8"};
  12054. static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
  12055. static const char * arm_attr_tag_Advanced_SIMD_arch[] =
  12056. {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8",
  12057. "NEON for ARMv8.1"};
  12058. static const char * arm_attr_tag_PCS_config[] =
  12059. {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
  12060. "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
  12061. static const char * arm_attr_tag_ABI_PCS_R9_use[] =
  12062. {"V6", "SB", "TLS", "Unused"};
  12063. static const char * arm_attr_tag_ABI_PCS_RW_data[] =
  12064. {"Absolute", "PC-relative", "SB-relative", "None"};
  12065. static const char * arm_attr_tag_ABI_PCS_RO_data[] =
  12066. {"Absolute", "PC-relative", "None"};
  12067. static const char * arm_attr_tag_ABI_PCS_GOT_use[] =
  12068. {"None", "direct", "GOT-indirect"};
  12069. static const char * arm_attr_tag_ABI_PCS_wchar_t[] =
  12070. {"None", "??? 1", "2", "??? 3", "4"};
  12071. static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
  12072. static const char * arm_attr_tag_ABI_FP_denormal[] =
  12073. {"Unused", "Needed", "Sign only"};
  12074. static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
  12075. static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
  12076. static const char * arm_attr_tag_ABI_FP_number_model[] =
  12077. {"Unused", "Finite", "RTABI", "IEEE 754"};
  12078. static const char * arm_attr_tag_ABI_enum_size[] =
  12079. {"Unused", "small", "int", "forced to int"};
  12080. static const char * arm_attr_tag_ABI_HardFP_use[] =
  12081. {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"};
  12082. static const char * arm_attr_tag_ABI_VFP_args[] =
  12083. {"AAPCS", "VFP registers", "custom", "compatible"};
  12084. static const char * arm_attr_tag_ABI_WMMX_args[] =
  12085. {"AAPCS", "WMMX registers", "custom"};
  12086. static const char * arm_attr_tag_ABI_optimization_goals[] =
  12087. {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
  12088. "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
  12089. static const char * arm_attr_tag_ABI_FP_optimization_goals[] =
  12090. {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
  12091. "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
  12092. static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
  12093. static const char * arm_attr_tag_FP_HP_extension[] =
  12094. {"Not Allowed", "Allowed"};
  12095. static const char * arm_attr_tag_ABI_FP_16bit_format[] =
  12096. {"None", "IEEE 754", "Alternative Format"};
  12097. static const char * arm_attr_tag_DSP_extension[] =
  12098. {"Follow architecture", "Allowed"};
  12099. static const char * arm_attr_tag_MPextension_use[] =
  12100. {"Not Allowed", "Allowed"};
  12101. static const char * arm_attr_tag_DIV_use[] =
  12102. {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed",
  12103. "Allowed in v7-A with integer division extension"};
  12104. static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
  12105. static const char * arm_attr_tag_Virtualization_use[] =
  12106. {"Not Allowed", "TrustZone", "Virtualization Extensions",
  12107. "TrustZone and Virtualization Extensions"};
  12108. static const char * arm_attr_tag_MPextension_use_legacy[] =
  12109. {"Not Allowed", "Allowed"};
  12110. #define LOOKUP(id, name) \
  12111. {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
  12112. static arm_attr_public_tag arm_attr_public_tags[] =
  12113. {
  12114. {4, "CPU_raw_name", 1, NULL},
  12115. {5, "CPU_name", 1, NULL},
  12116. LOOKUP(6, CPU_arch),
  12117. {7, "CPU_arch_profile", 0, NULL},
  12118. LOOKUP(8, ARM_ISA_use),
  12119. LOOKUP(9, THUMB_ISA_use),
  12120. LOOKUP(10, FP_arch),
  12121. LOOKUP(11, WMMX_arch),
  12122. LOOKUP(12, Advanced_SIMD_arch),
  12123. LOOKUP(13, PCS_config),
  12124. LOOKUP(14, ABI_PCS_R9_use),
  12125. LOOKUP(15, ABI_PCS_RW_data),
  12126. LOOKUP(16, ABI_PCS_RO_data),
  12127. LOOKUP(17, ABI_PCS_GOT_use),
  12128. LOOKUP(18, ABI_PCS_wchar_t),
  12129. LOOKUP(19, ABI_FP_rounding),
  12130. LOOKUP(20, ABI_FP_denormal),
  12131. LOOKUP(21, ABI_FP_exceptions),
  12132. LOOKUP(22, ABI_FP_user_exceptions),
  12133. LOOKUP(23, ABI_FP_number_model),
  12134. {24, "ABI_align_needed", 0, NULL},
  12135. {25, "ABI_align_preserved", 0, NULL},
  12136. LOOKUP(26, ABI_enum_size),
  12137. LOOKUP(27, ABI_HardFP_use),
  12138. LOOKUP(28, ABI_VFP_args),
  12139. LOOKUP(29, ABI_WMMX_args),
  12140. LOOKUP(30, ABI_optimization_goals),
  12141. LOOKUP(31, ABI_FP_optimization_goals),
  12142. {32, "compatibility", 0, NULL},
  12143. LOOKUP(34, CPU_unaligned_access),
  12144. LOOKUP(36, FP_HP_extension),
  12145. LOOKUP(38, ABI_FP_16bit_format),
  12146. LOOKUP(42, MPextension_use),
  12147. LOOKUP(44, DIV_use),
  12148. LOOKUP(46, DSP_extension),
  12149. {64, "nodefaults", 0, NULL},
  12150. {65, "also_compatible_with", 0, NULL},
  12151. LOOKUP(66, T2EE_use),
  12152. {67, "conformance", 1, NULL},
  12153. LOOKUP(68, Virtualization_use),
  12154. LOOKUP(70, MPextension_use_legacy)
  12155. };
  12156. #undef LOOKUP
  12157. static unsigned char *
  12158. display_arm_attribute (unsigned char * p,
  12159. const unsigned char * const end)
  12160. {
  12161. unsigned int tag;
  12162. unsigned int len;
  12163. unsigned int val;
  12164. arm_attr_public_tag * attr;
  12165. unsigned i;
  12166. unsigned int type;
  12167. tag = read_uleb128 (p, &len, end);
  12168. p += len;
  12169. attr = NULL;
  12170. for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
  12171. {
  12172. if (arm_attr_public_tags[i].tag == tag)
  12173. {
  12174. attr = &arm_attr_public_tags[i];
  12175. break;
  12176. }
  12177. }
  12178. if (attr)
  12179. {
  12180. printf (" Tag_%s: ", attr->name);
  12181. switch (attr->type)
  12182. {
  12183. case 0:
  12184. switch (tag)
  12185. {
  12186. case 7: /* Tag_CPU_arch_profile. */
  12187. val = read_uleb128 (p, &len, end);
  12188. p += len;
  12189. switch (val)
  12190. {
  12191. case 0: printf (_("None\n")); break;
  12192. case 'A': printf (_("Application\n")); break;
  12193. case 'R': printf (_("Realtime\n")); break;
  12194. case 'M': printf (_("Microcontroller\n")); break;
  12195. case 'S': printf (_("Application or Realtime\n")); break;
  12196. default: printf ("??? (%d)\n", val); break;
  12197. }
  12198. break;
  12199. case 24: /* Tag_align_needed. */
  12200. val = read_uleb128 (p, &len, end);
  12201. p += len;
  12202. switch (val)
  12203. {
  12204. case 0: printf (_("None\n")); break;
  12205. case 1: printf (_("8-byte\n")); break;
  12206. case 2: printf (_("4-byte\n")); break;
  12207. case 3: printf ("??? 3\n"); break;
  12208. default:
  12209. if (val <= 12)
  12210. printf (_("8-byte and up to %d-byte extended\n"),
  12211. 1 << val);
  12212. else
  12213. printf ("??? (%d)\n", val);
  12214. break;
  12215. }
  12216. break;
  12217. case 25: /* Tag_align_preserved. */
  12218. val = read_uleb128 (p, &len, end);
  12219. p += len;
  12220. switch (val)
  12221. {
  12222. case 0: printf (_("None\n")); break;
  12223. case 1: printf (_("8-byte, except leaf SP\n")); break;
  12224. case 2: printf (_("8-byte\n")); break;
  12225. case 3: printf ("??? 3\n"); break;
  12226. default:
  12227. if (val <= 12)
  12228. printf (_("8-byte and up to %d-byte extended\n"),
  12229. 1 << val);
  12230. else
  12231. printf ("??? (%d)\n", val);
  12232. break;
  12233. }
  12234. break;
  12235. case 32: /* Tag_compatibility. */
  12236. {
  12237. val = read_uleb128 (p, &len, end);
  12238. p += len;
  12239. printf (_("flag = %d, vendor = "), val);
  12240. if (p < end - 1)
  12241. {
  12242. size_t maxlen = (end - p) - 1;
  12243. print_symbol ((int) maxlen, (const char *) p);
  12244. p += strnlen ((char *) p, maxlen) + 1;
  12245. }
  12246. else
  12247. {
  12248. printf (_("<corrupt>"));
  12249. p = (unsigned char *) end;
  12250. }
  12251. putchar ('\n');
  12252. }
  12253. break;
  12254. case 64: /* Tag_nodefaults. */
  12255. /* PR 17531: file: 001-505008-0.01. */
  12256. if (p < end)
  12257. p++;
  12258. printf (_("True\n"));
  12259. break;
  12260. case 65: /* Tag_also_compatible_with. */
  12261. val = read_uleb128 (p, &len, end);
  12262. p += len;
  12263. if (val == 6 /* Tag_CPU_arch. */)
  12264. {
  12265. val = read_uleb128 (p, &len, end);
  12266. p += len;
  12267. if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
  12268. printf ("??? (%d)\n", val);
  12269. else
  12270. printf ("%s\n", arm_attr_tag_CPU_arch[val]);
  12271. }
  12272. else
  12273. printf ("???\n");
  12274. while (p < end && *(p++) != '\0' /* NUL terminator. */)
  12275. ;
  12276. break;
  12277. default:
  12278. printf (_("<unknown: %d>\n"), tag);
  12279. break;
  12280. }
  12281. return p;
  12282. case 1:
  12283. return display_tag_value (-1, p, end);
  12284. case 2:
  12285. return display_tag_value (0, p, end);
  12286. default:
  12287. assert (attr->type & 0x80);
  12288. val = read_uleb128 (p, &len, end);
  12289. p += len;
  12290. type = attr->type & 0x7f;
  12291. if (val >= type)
  12292. printf ("??? (%d)\n", val);
  12293. else
  12294. printf ("%s\n", attr->table[val]);
  12295. return p;
  12296. }
  12297. }
  12298. return display_tag_value (tag, p, end);
  12299. }
  12300. static unsigned char *
  12301. display_gnu_attribute (unsigned char * p,
  12302. unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const),
  12303. const unsigned char * const end)
  12304. {
  12305. int tag;
  12306. unsigned int len;
  12307. unsigned int val;
  12308. tag = read_uleb128 (p, &len, end);
  12309. p += len;
  12310. /* Tag_compatibility is the only generic GNU attribute defined at
  12311. present. */
  12312. if (tag == 32)
  12313. {
  12314. val = read_uleb128 (p, &len, end);
  12315. p += len;
  12316. printf (_("flag = %d, vendor = "), val);
  12317. if (p == end)
  12318. {
  12319. printf (_("<corrupt>\n"));
  12320. warn (_("corrupt vendor attribute\n"));
  12321. }
  12322. else
  12323. {
  12324. if (p < end - 1)
  12325. {
  12326. size_t maxlen = (end - p) - 1;
  12327. print_symbol ((int) maxlen, (const char *) p);
  12328. p += strnlen ((char *) p, maxlen) + 1;
  12329. }
  12330. else
  12331. {
  12332. printf (_("<corrupt>"));
  12333. p = (unsigned char *) end;
  12334. }
  12335. putchar ('\n');
  12336. }
  12337. return p;
  12338. }
  12339. if ((tag & 2) == 0 && display_proc_gnu_attribute)
  12340. return display_proc_gnu_attribute (p, tag, end);
  12341. return display_tag_value (tag, p, end);
  12342. }
  12343. static unsigned char *
  12344. display_power_gnu_attribute (unsigned char * p,
  12345. unsigned int tag,
  12346. const unsigned char * const end)
  12347. {
  12348. unsigned int len;
  12349. unsigned int val;
  12350. if (tag == Tag_GNU_Power_ABI_FP)
  12351. {
  12352. val = read_uleb128 (p, &len, end);
  12353. p += len;
  12354. printf (" Tag_GNU_Power_ABI_FP: ");
  12355. if (len == 0)
  12356. {
  12357. printf (_("<corrupt>\n"));
  12358. return p;
  12359. }
  12360. if (val > 15)
  12361. printf ("(%#x), ", val);
  12362. switch (val & 3)
  12363. {
  12364. case 0:
  12365. printf (_("unspecified hard/soft float, "));
  12366. break;
  12367. case 1:
  12368. printf (_("hard float, "));
  12369. break;
  12370. case 2:
  12371. printf (_("soft float, "));
  12372. break;
  12373. case 3:
  12374. printf (_("single-precision hard float, "));
  12375. break;
  12376. }
  12377. switch (val & 0xC)
  12378. {
  12379. case 0:
  12380. printf (_("unspecified long double\n"));
  12381. break;
  12382. case 4:
  12383. printf (_("128-bit IBM long double\n"));
  12384. break;
  12385. case 8:
  12386. printf (_("64-bit long double\n"));
  12387. break;
  12388. case 12:
  12389. printf (_("128-bit IEEE long double\n"));
  12390. break;
  12391. }
  12392. return p;
  12393. }
  12394. if (tag == Tag_GNU_Power_ABI_Vector)
  12395. {
  12396. val = read_uleb128 (p, &len, end);
  12397. p += len;
  12398. printf (" Tag_GNU_Power_ABI_Vector: ");
  12399. if (len == 0)
  12400. {
  12401. printf (_("<corrupt>\n"));
  12402. return p;
  12403. }
  12404. if (val > 3)
  12405. printf ("(%#x), ", val);
  12406. switch (val & 3)
  12407. {
  12408. case 0:
  12409. printf (_("unspecified\n"));
  12410. break;
  12411. case 1:
  12412. printf (_("generic\n"));
  12413. break;
  12414. case 2:
  12415. printf ("AltiVec\n");
  12416. break;
  12417. case 3:
  12418. printf ("SPE\n");
  12419. break;
  12420. }
  12421. return p;
  12422. }
  12423. if (tag == Tag_GNU_Power_ABI_Struct_Return)
  12424. {
  12425. val = read_uleb128 (p, &len, end);
  12426. p += len;
  12427. printf (" Tag_GNU_Power_ABI_Struct_Return: ");
  12428. if (len == 0)
  12429. {
  12430. printf (_("<corrupt>\n"));
  12431. return p;
  12432. }
  12433. if (val > 2)
  12434. printf ("(%#x), ", val);
  12435. switch (val & 3)
  12436. {
  12437. case 0:
  12438. printf (_("unspecified\n"));
  12439. break;
  12440. case 1:
  12441. printf ("r3/r4\n");
  12442. break;
  12443. case 2:
  12444. printf (_("memory\n"));
  12445. break;
  12446. case 3:
  12447. printf ("???\n");
  12448. break;
  12449. }
  12450. return p;
  12451. }
  12452. return display_tag_value (tag & 1, p, end);
  12453. }
  12454. static unsigned char *
  12455. display_s390_gnu_attribute (unsigned char * p,
  12456. unsigned int tag,
  12457. const unsigned char * const end)
  12458. {
  12459. unsigned int len;
  12460. int val;
  12461. if (tag == Tag_GNU_S390_ABI_Vector)
  12462. {
  12463. val = read_uleb128 (p, &len, end);
  12464. p += len;
  12465. printf (" Tag_GNU_S390_ABI_Vector: ");
  12466. switch (val)
  12467. {
  12468. case 0:
  12469. printf (_("any\n"));
  12470. break;
  12471. case 1:
  12472. printf (_("software\n"));
  12473. break;
  12474. case 2:
  12475. printf (_("hardware\n"));
  12476. break;
  12477. default:
  12478. printf ("??? (%d)\n", val);
  12479. break;
  12480. }
  12481. return p;
  12482. }
  12483. return display_tag_value (tag & 1, p, end);
  12484. }
  12485. static void
  12486. display_sparc_hwcaps (unsigned int mask)
  12487. {
  12488. if (mask)
  12489. {
  12490. bfd_boolean first = TRUE;
  12491. if (mask & ELF_SPARC_HWCAP_MUL32)
  12492. fputs ("mul32", stdout), first = FALSE;
  12493. if (mask & ELF_SPARC_HWCAP_DIV32)
  12494. printf ("%sdiv32", first ? "" : "|"), first = FALSE;
  12495. if (mask & ELF_SPARC_HWCAP_FSMULD)
  12496. printf ("%sfsmuld", first ? "" : "|"), first = FALSE;
  12497. if (mask & ELF_SPARC_HWCAP_V8PLUS)
  12498. printf ("%sv8plus", first ? "" : "|"), first = FALSE;
  12499. if (mask & ELF_SPARC_HWCAP_POPC)
  12500. printf ("%spopc", first ? "" : "|"), first = FALSE;
  12501. if (mask & ELF_SPARC_HWCAP_VIS)
  12502. printf ("%svis", first ? "" : "|"), first = FALSE;
  12503. if (mask & ELF_SPARC_HWCAP_VIS2)
  12504. printf ("%svis2", first ? "" : "|"), first = FALSE;
  12505. if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT)
  12506. printf ("%sASIBlkInit", first ? "" : "|"), first = FALSE;
  12507. if (mask & ELF_SPARC_HWCAP_FMAF)
  12508. printf ("%sfmaf", first ? "" : "|"), first = FALSE;
  12509. if (mask & ELF_SPARC_HWCAP_VIS3)
  12510. printf ("%svis3", first ? "" : "|"), first = FALSE;
  12511. if (mask & ELF_SPARC_HWCAP_HPC)
  12512. printf ("%shpc", first ? "" : "|"), first = FALSE;
  12513. if (mask & ELF_SPARC_HWCAP_RANDOM)
  12514. printf ("%srandom", first ? "" : "|"), first = FALSE;
  12515. if (mask & ELF_SPARC_HWCAP_TRANS)
  12516. printf ("%strans", first ? "" : "|"), first = FALSE;
  12517. if (mask & ELF_SPARC_HWCAP_FJFMAU)
  12518. printf ("%sfjfmau", first ? "" : "|"), first = FALSE;
  12519. if (mask & ELF_SPARC_HWCAP_IMA)
  12520. printf ("%sima", first ? "" : "|"), first = FALSE;
  12521. if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING)
  12522. printf ("%scspare", first ? "" : "|"), first = FALSE;
  12523. }
  12524. else
  12525. fputc ('0', stdout);
  12526. fputc ('\n', stdout);
  12527. }
  12528. static void
  12529. display_sparc_hwcaps2 (unsigned int mask)
  12530. {
  12531. if (mask)
  12532. {
  12533. bfd_boolean first = TRUE;
  12534. if (mask & ELF_SPARC_HWCAP2_FJATHPLUS)
  12535. fputs ("fjathplus", stdout), first = FALSE;
  12536. if (mask & ELF_SPARC_HWCAP2_VIS3B)
  12537. printf ("%svis3b", first ? "" : "|"), first = FALSE;
  12538. if (mask & ELF_SPARC_HWCAP2_ADP)
  12539. printf ("%sadp", first ? "" : "|"), first = FALSE;
  12540. if (mask & ELF_SPARC_HWCAP2_SPARC5)
  12541. printf ("%ssparc5", first ? "" : "|"), first = FALSE;
  12542. if (mask & ELF_SPARC_HWCAP2_MWAIT)
  12543. printf ("%smwait", first ? "" : "|"), first = FALSE;
  12544. if (mask & ELF_SPARC_HWCAP2_XMPMUL)
  12545. printf ("%sxmpmul", first ? "" : "|"), first = FALSE;
  12546. if (mask & ELF_SPARC_HWCAP2_XMONT)
  12547. printf ("%sxmont2", first ? "" : "|"), first = FALSE;
  12548. if (mask & ELF_SPARC_HWCAP2_NSEC)
  12549. printf ("%snsec", first ? "" : "|"), first = FALSE;
  12550. if (mask & ELF_SPARC_HWCAP2_FJATHHPC)
  12551. printf ("%sfjathhpc", first ? "" : "|"), first = FALSE;
  12552. if (mask & ELF_SPARC_HWCAP2_FJDES)
  12553. printf ("%sfjdes", first ? "" : "|"), first = FALSE;
  12554. if (mask & ELF_SPARC_HWCAP2_FJAES)
  12555. printf ("%sfjaes", first ? "" : "|"), first = FALSE;
  12556. }
  12557. else
  12558. fputc ('0', stdout);
  12559. fputc ('\n', stdout);
  12560. }
  12561. static unsigned char *
  12562. display_sparc_gnu_attribute (unsigned char * p,
  12563. unsigned int tag,
  12564. const unsigned char * const end)
  12565. {
  12566. unsigned int len;
  12567. int val;
  12568. if (tag == Tag_GNU_Sparc_HWCAPS)
  12569. {
  12570. val = read_uleb128 (p, &len, end);
  12571. p += len;
  12572. printf (" Tag_GNU_Sparc_HWCAPS: ");
  12573. display_sparc_hwcaps (val);
  12574. return p;
  12575. }
  12576. if (tag == Tag_GNU_Sparc_HWCAPS2)
  12577. {
  12578. val = read_uleb128 (p, &len, end);
  12579. p += len;
  12580. printf (" Tag_GNU_Sparc_HWCAPS2: ");
  12581. display_sparc_hwcaps2 (val);
  12582. return p;
  12583. }
  12584. return display_tag_value (tag, p, end);
  12585. }
  12586. static void
  12587. print_mips_fp_abi_value (unsigned int val)
  12588. {
  12589. switch (val)
  12590. {
  12591. case Val_GNU_MIPS_ABI_FP_ANY:
  12592. printf (_("Hard or soft float\n"));
  12593. break;
  12594. case Val_GNU_MIPS_ABI_FP_DOUBLE:
  12595. printf (_("Hard float (double precision)\n"));
  12596. break;
  12597. case Val_GNU_MIPS_ABI_FP_SINGLE:
  12598. printf (_("Hard float (single precision)\n"));
  12599. break;
  12600. case Val_GNU_MIPS_ABI_FP_SOFT:
  12601. printf (_("Soft float\n"));
  12602. break;
  12603. case Val_GNU_MIPS_ABI_FP_OLD_64:
  12604. printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n"));
  12605. break;
  12606. case Val_GNU_MIPS_ABI_FP_XX:
  12607. printf (_("Hard float (32-bit CPU, Any FPU)\n"));
  12608. break;
  12609. case Val_GNU_MIPS_ABI_FP_64:
  12610. printf (_("Hard float (32-bit CPU, 64-bit FPU)\n"));
  12611. break;
  12612. case Val_GNU_MIPS_ABI_FP_64A:
  12613. printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n"));
  12614. break;
  12615. case Val_GNU_MIPS_ABI_FP_NAN2008:
  12616. printf (_("NaN 2008 compatibility\n"));
  12617. break;
  12618. default:
  12619. printf ("??? (%d)\n", val);
  12620. break;
  12621. }
  12622. }
  12623. static unsigned char *
  12624. display_mips_gnu_attribute (unsigned char * p,
  12625. unsigned int tag,
  12626. const unsigned char * const end)
  12627. {
  12628. if (tag == Tag_GNU_MIPS_ABI_FP)
  12629. {
  12630. unsigned int len;
  12631. unsigned int val;
  12632. val = read_uleb128 (p, &len, end);
  12633. p += len;
  12634. printf (" Tag_GNU_MIPS_ABI_FP: ");
  12635. print_mips_fp_abi_value (val);
  12636. return p;
  12637. }
  12638. if (tag == Tag_GNU_MIPS_ABI_MSA)
  12639. {
  12640. unsigned int len;
  12641. unsigned int val;
  12642. val = read_uleb128 (p, &len, end);
  12643. p += len;
  12644. printf (" Tag_GNU_MIPS_ABI_MSA: ");
  12645. switch (val)
  12646. {
  12647. case Val_GNU_MIPS_ABI_MSA_ANY:
  12648. printf (_("Any MSA or not\n"));
  12649. break;
  12650. case Val_GNU_MIPS_ABI_MSA_128:
  12651. printf (_("128-bit MSA\n"));
  12652. break;
  12653. default:
  12654. printf ("??? (%d)\n", val);
  12655. break;
  12656. }
  12657. return p;
  12658. }
  12659. return display_tag_value (tag & 1, p, end);
  12660. }
  12661. static unsigned char *
  12662. display_tic6x_attribute (unsigned char * p,
  12663. const unsigned char * const end)
  12664. {
  12665. unsigned int tag;
  12666. unsigned int len;
  12667. int val;
  12668. tag = read_uleb128 (p, &len, end);
  12669. p += len;
  12670. switch (tag)
  12671. {
  12672. case Tag_ISA:
  12673. val = read_uleb128 (p, &len, end);
  12674. p += len;
  12675. printf (" Tag_ISA: ");
  12676. switch (val)
  12677. {
  12678. case C6XABI_Tag_ISA_none:
  12679. printf (_("None\n"));
  12680. break;
  12681. case C6XABI_Tag_ISA_C62X:
  12682. printf ("C62x\n");
  12683. break;
  12684. case C6XABI_Tag_ISA_C67X:
  12685. printf ("C67x\n");
  12686. break;
  12687. case C6XABI_Tag_ISA_C67XP:
  12688. printf ("C67x+\n");
  12689. break;
  12690. case C6XABI_Tag_ISA_C64X:
  12691. printf ("C64x\n");
  12692. break;
  12693. case C6XABI_Tag_ISA_C64XP:
  12694. printf ("C64x+\n");
  12695. break;
  12696. case C6XABI_Tag_ISA_C674X:
  12697. printf ("C674x\n");
  12698. break;
  12699. default:
  12700. printf ("??? (%d)\n", val);
  12701. break;
  12702. }
  12703. return p;
  12704. case Tag_ABI_wchar_t:
  12705. val = read_uleb128 (p, &len, end);
  12706. p += len;
  12707. printf (" Tag_ABI_wchar_t: ");
  12708. switch (val)
  12709. {
  12710. case 0:
  12711. printf (_("Not used\n"));
  12712. break;
  12713. case 1:
  12714. printf (_("2 bytes\n"));
  12715. break;
  12716. case 2:
  12717. printf (_("4 bytes\n"));
  12718. break;
  12719. default:
  12720. printf ("??? (%d)\n", val);
  12721. break;
  12722. }
  12723. return p;
  12724. case Tag_ABI_stack_align_needed:
  12725. val = read_uleb128 (p, &len, end);
  12726. p += len;
  12727. printf (" Tag_ABI_stack_align_needed: ");
  12728. switch (val)
  12729. {
  12730. case 0:
  12731. printf (_("8-byte\n"));
  12732. break;
  12733. case 1:
  12734. printf (_("16-byte\n"));
  12735. break;
  12736. default:
  12737. printf ("??? (%d)\n", val);
  12738. break;
  12739. }
  12740. return p;
  12741. case Tag_ABI_stack_align_preserved:
  12742. val = read_uleb128 (p, &len, end);
  12743. p += len;
  12744. printf (" Tag_ABI_stack_align_preserved: ");
  12745. switch (val)
  12746. {
  12747. case 0:
  12748. printf (_("8-byte\n"));
  12749. break;
  12750. case 1:
  12751. printf (_("16-byte\n"));
  12752. break;
  12753. default:
  12754. printf ("??? (%d)\n", val);
  12755. break;
  12756. }
  12757. return p;
  12758. case Tag_ABI_DSBT:
  12759. val = read_uleb128 (p, &len, end);
  12760. p += len;
  12761. printf (" Tag_ABI_DSBT: ");
  12762. switch (val)
  12763. {
  12764. case 0:
  12765. printf (_("DSBT addressing not used\n"));
  12766. break;
  12767. case 1:
  12768. printf (_("DSBT addressing used\n"));
  12769. break;
  12770. default:
  12771. printf ("??? (%d)\n", val);
  12772. break;
  12773. }
  12774. return p;
  12775. case Tag_ABI_PID:
  12776. val = read_uleb128 (p, &len, end);
  12777. p += len;
  12778. printf (" Tag_ABI_PID: ");
  12779. switch (val)
  12780. {
  12781. case 0:
  12782. printf (_("Data addressing position-dependent\n"));
  12783. break;
  12784. case 1:
  12785. printf (_("Data addressing position-independent, GOT near DP\n"));
  12786. break;
  12787. case 2:
  12788. printf (_("Data addressing position-independent, GOT far from DP\n"));
  12789. break;
  12790. default:
  12791. printf ("??? (%d)\n", val);
  12792. break;
  12793. }
  12794. return p;
  12795. case Tag_ABI_PIC:
  12796. val = read_uleb128 (p, &len, end);
  12797. p += len;
  12798. printf (" Tag_ABI_PIC: ");
  12799. switch (val)
  12800. {
  12801. case 0:
  12802. printf (_("Code addressing position-dependent\n"));
  12803. break;
  12804. case 1:
  12805. printf (_("Code addressing position-independent\n"));
  12806. break;
  12807. default:
  12808. printf ("??? (%d)\n", val);
  12809. break;
  12810. }
  12811. return p;
  12812. case Tag_ABI_array_object_alignment:
  12813. val = read_uleb128 (p, &len, end);
  12814. p += len;
  12815. printf (" Tag_ABI_array_object_alignment: ");
  12816. switch (val)
  12817. {
  12818. case 0:
  12819. printf (_("8-byte\n"));
  12820. break;
  12821. case 1:
  12822. printf (_("4-byte\n"));
  12823. break;
  12824. case 2:
  12825. printf (_("16-byte\n"));
  12826. break;
  12827. default:
  12828. printf ("??? (%d)\n", val);
  12829. break;
  12830. }
  12831. return p;
  12832. case Tag_ABI_array_object_align_expected:
  12833. val = read_uleb128 (p, &len, end);
  12834. p += len;
  12835. printf (" Tag_ABI_array_object_align_expected: ");
  12836. switch (val)
  12837. {
  12838. case 0:
  12839. printf (_("8-byte\n"));
  12840. break;
  12841. case 1:
  12842. printf (_("4-byte\n"));
  12843. break;
  12844. case 2:
  12845. printf (_("16-byte\n"));
  12846. break;
  12847. default:
  12848. printf ("??? (%d)\n", val);
  12849. break;
  12850. }
  12851. return p;
  12852. case Tag_ABI_compatibility:
  12853. {
  12854. val = read_uleb128 (p, &len, end);
  12855. p += len;
  12856. printf (" Tag_ABI_compatibility: ");
  12857. printf (_("flag = %d, vendor = "), val);
  12858. if (p < end - 1)
  12859. {
  12860. size_t maxlen = (end - p) - 1;
  12861. print_symbol ((int) maxlen, (const char *) p);
  12862. p += strnlen ((char *) p, maxlen) + 1;
  12863. }
  12864. else
  12865. {
  12866. printf (_("<corrupt>"));
  12867. p = (unsigned char *) end;
  12868. }
  12869. putchar ('\n');
  12870. return p;
  12871. }
  12872. case Tag_ABI_conformance:
  12873. {
  12874. printf (" Tag_ABI_conformance: \"");
  12875. if (p < end - 1)
  12876. {
  12877. size_t maxlen = (end - p) - 1;
  12878. print_symbol ((int) maxlen, (const char *) p);
  12879. p += strnlen ((char *) p, maxlen) + 1;
  12880. }
  12881. else
  12882. {
  12883. printf (_("<corrupt>"));
  12884. p = (unsigned char *) end;
  12885. }
  12886. printf ("\"\n");
  12887. return p;
  12888. }
  12889. }
  12890. return display_tag_value (tag, p, end);
  12891. }
  12892. static void
  12893. display_raw_attribute (unsigned char * p, unsigned char const * const end)
  12894. {
  12895. unsigned long addr = 0;
  12896. size_t bytes = end - p;
  12897. assert (end > p);
  12898. while (bytes)
  12899. {
  12900. int j;
  12901. int k;
  12902. int lbytes = (bytes > 16 ? 16 : bytes);
  12903. printf (" 0x%8.8lx ", addr);
  12904. for (j = 0; j < 16; j++)
  12905. {
  12906. if (j < lbytes)
  12907. printf ("%2.2x", p[j]);
  12908. else
  12909. printf (" ");
  12910. if ((j & 3) == 3)
  12911. printf (" ");
  12912. }
  12913. for (j = 0; j < lbytes; j++)
  12914. {
  12915. k = p[j];
  12916. if (k >= ' ' && k < 0x7f)
  12917. printf ("%c", k);
  12918. else
  12919. printf (".");
  12920. }
  12921. putchar ('\n');
  12922. p += lbytes;
  12923. bytes -= lbytes;
  12924. addr += lbytes;
  12925. }
  12926. putchar ('\n');
  12927. }
  12928. static unsigned char *
  12929. display_msp430x_attribute (unsigned char * p,
  12930. const unsigned char * const end)
  12931. {
  12932. unsigned int len;
  12933. unsigned int val;
  12934. unsigned int tag;
  12935. tag = read_uleb128 (p, & len, end);
  12936. p += len;
  12937. switch (tag)
  12938. {
  12939. case OFBA_MSPABI_Tag_ISA:
  12940. val = read_uleb128 (p, &len, end);
  12941. p += len;
  12942. printf (" Tag_ISA: ");
  12943. switch (val)
  12944. {
  12945. case 0: printf (_("None\n")); break;
  12946. case 1: printf (_("MSP430\n")); break;
  12947. case 2: printf (_("MSP430X\n")); break;
  12948. default: printf ("??? (%d)\n", val); break;
  12949. }
  12950. break;
  12951. case OFBA_MSPABI_Tag_Code_Model:
  12952. val = read_uleb128 (p, &len, end);
  12953. p += len;
  12954. printf (" Tag_Code_Model: ");
  12955. switch (val)
  12956. {
  12957. case 0: printf (_("None\n")); break;
  12958. case 1: printf (_("Small\n")); break;
  12959. case 2: printf (_("Large\n")); break;
  12960. default: printf ("??? (%d)\n", val); break;
  12961. }
  12962. break;
  12963. case OFBA_MSPABI_Tag_Data_Model:
  12964. val = read_uleb128 (p, &len, end);
  12965. p += len;
  12966. printf (" Tag_Data_Model: ");
  12967. switch (val)
  12968. {
  12969. case 0: printf (_("None\n")); break;
  12970. case 1: printf (_("Small\n")); break;
  12971. case 2: printf (_("Large\n")); break;
  12972. case 3: printf (_("Restricted Large\n")); break;
  12973. default: printf ("??? (%d)\n", val); break;
  12974. }
  12975. break;
  12976. default:
  12977. printf (_(" <unknown tag %d>: "), tag);
  12978. if (tag & 1)
  12979. {
  12980. putchar ('"');
  12981. if (p < end - 1)
  12982. {
  12983. size_t maxlen = (end - p) - 1;
  12984. print_symbol ((int) maxlen, (const char *) p);
  12985. p += strnlen ((char *) p, maxlen) + 1;
  12986. }
  12987. else
  12988. {
  12989. printf (_("<corrupt>"));
  12990. p = (unsigned char *) end;
  12991. }
  12992. printf ("\"\n");
  12993. }
  12994. else
  12995. {
  12996. val = read_uleb128 (p, &len, end);
  12997. p += len;
  12998. printf ("%d (0x%x)\n", val, val);
  12999. }
  13000. break;
  13001. }
  13002. assert (p <= end);
  13003. return p;
  13004. }
  13005. static bfd_boolean
  13006. process_attributes (FILE * file,
  13007. const char * public_name,
  13008. unsigned int proc_type,
  13009. unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const),
  13010. unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const))
  13011. {
  13012. Elf_Internal_Shdr * sect;
  13013. unsigned i;
  13014. bfd_boolean res = TRUE;
  13015. /* Find the section header so that we get the size. */
  13016. for (i = 0, sect = section_headers;
  13017. i < elf_header.e_shnum;
  13018. i++, sect++)
  13019. {
  13020. unsigned char * contents;
  13021. unsigned char * p;
  13022. if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES)
  13023. continue;
  13024. contents = (unsigned char *) get_data (NULL, file, sect->sh_offset, 1,
  13025. sect->sh_size, _("attributes"));
  13026. if (contents == NULL)
  13027. {
  13028. res = FALSE;
  13029. continue;
  13030. }
  13031. p = contents;
  13032. /* The first character is the version of the attributes.
  13033. Currently only version 1, (aka 'A') is recognised here. */
  13034. if (*p != 'A')
  13035. {
  13036. printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p);
  13037. res = FALSE;
  13038. }
  13039. else
  13040. {
  13041. bfd_vma section_len;
  13042. section_len = sect->sh_size - 1;
  13043. p++;
  13044. while (section_len > 0)
  13045. {
  13046. bfd_vma attr_len;
  13047. unsigned int namelen;
  13048. bfd_boolean public_section;
  13049. bfd_boolean gnu_section;
  13050. if (section_len <= 4)
  13051. {
  13052. error (_("Tag section ends prematurely\n"));
  13053. res = FALSE;
  13054. break;
  13055. }
  13056. attr_len = byte_get (p, 4);
  13057. p += 4;
  13058. if (attr_len > section_len)
  13059. {
  13060. error (_("Bad attribute length (%u > %u)\n"),
  13061. (unsigned) attr_len, (unsigned) section_len);
  13062. attr_len = section_len;
  13063. res = FALSE;
  13064. }
  13065. /* PR 17531: file: 001-101425-0.004 */
  13066. else if (attr_len < 5)
  13067. {
  13068. error (_("Attribute length of %u is too small\n"), (unsigned) attr_len);
  13069. res = FALSE;
  13070. break;
  13071. }
  13072. section_len -= attr_len;
  13073. attr_len -= 4;
  13074. namelen = strnlen ((char *) p, attr_len) + 1;
  13075. if (namelen == 0 || namelen >= attr_len)
  13076. {
  13077. error (_("Corrupt attribute section name\n"));
  13078. res = FALSE;
  13079. break;
  13080. }
  13081. printf (_("Attribute Section: "));
  13082. print_symbol (INT_MAX, (const char *) p);
  13083. putchar ('\n');
  13084. if (public_name && streq ((char *) p, public_name))
  13085. public_section = TRUE;
  13086. else
  13087. public_section = FALSE;
  13088. if (streq ((char *) p, "gnu"))
  13089. gnu_section = TRUE;
  13090. else
  13091. gnu_section = FALSE;
  13092. p += namelen;
  13093. attr_len -= namelen;
  13094. while (attr_len > 0 && p < contents + sect->sh_size)
  13095. {
  13096. int tag;
  13097. int val;
  13098. bfd_vma size;
  13099. unsigned char * end;
  13100. /* PR binutils/17531: Safe handling of corrupt files. */
  13101. if (attr_len < 6)
  13102. {
  13103. error (_("Unused bytes at end of section\n"));
  13104. res = FALSE;
  13105. section_len = 0;
  13106. break;
  13107. }
  13108. tag = *(p++);
  13109. size = byte_get (p, 4);
  13110. if (size > attr_len)
  13111. {
  13112. error (_("Bad subsection length (%u > %u)\n"),
  13113. (unsigned) size, (unsigned) attr_len);
  13114. res = FALSE;
  13115. size = attr_len;
  13116. }
  13117. /* PR binutils/17531: Safe handling of corrupt files. */
  13118. if (size < 6)
  13119. {
  13120. error (_("Bad subsection length (%u < 6)\n"),
  13121. (unsigned) size);
  13122. res = FALSE;
  13123. section_len = 0;
  13124. break;
  13125. }
  13126. attr_len -= size;
  13127. end = p + size - 1;
  13128. assert (end <= contents + sect->sh_size);
  13129. p += 4;
  13130. switch (tag)
  13131. {
  13132. case 1:
  13133. printf (_("File Attributes\n"));
  13134. break;
  13135. case 2:
  13136. printf (_("Section Attributes:"));
  13137. goto do_numlist;
  13138. case 3:
  13139. printf (_("Symbol Attributes:"));
  13140. /* Fall through. */
  13141. do_numlist:
  13142. for (;;)
  13143. {
  13144. unsigned int j;
  13145. val = read_uleb128 (p, &j, end);
  13146. p += j;
  13147. if (val == 0)
  13148. break;
  13149. printf (" %d", val);
  13150. }
  13151. printf ("\n");
  13152. break;
  13153. default:
  13154. printf (_("Unknown tag: %d\n"), tag);
  13155. public_section = FALSE;
  13156. break;
  13157. }
  13158. if (public_section && display_pub_attribute != NULL)
  13159. {
  13160. while (p < end)
  13161. p = display_pub_attribute (p, end);
  13162. assert (p == end);
  13163. }
  13164. else if (gnu_section && display_proc_gnu_attribute != NULL)
  13165. {
  13166. while (p < end)
  13167. p = display_gnu_attribute (p,
  13168. display_proc_gnu_attribute,
  13169. end);
  13170. assert (p == end);
  13171. }
  13172. else if (p < end)
  13173. {
  13174. printf (_(" Unknown attribute:\n"));
  13175. display_raw_attribute (p, end);
  13176. p = end;
  13177. }
  13178. else
  13179. attr_len = 0;
  13180. }
  13181. }
  13182. }
  13183. free (contents);
  13184. }
  13185. return res;
  13186. }
  13187. /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT.
  13188. Print the Address, Access and Initial fields of an entry at VMA ADDR
  13189. and return the VMA of the next entry, or -1 if there was a problem.
  13190. Does not read from DATA_END or beyond. */
  13191. static bfd_vma
  13192. print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr,
  13193. unsigned char * data_end)
  13194. {
  13195. printf (" ");
  13196. print_vma (addr, LONG_HEX);
  13197. printf (" ");
  13198. if (addr < pltgot + 0xfff0)
  13199. printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0));
  13200. else
  13201. printf ("%10s", "");
  13202. printf (" ");
  13203. if (data == NULL)
  13204. printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
  13205. else
  13206. {
  13207. bfd_vma entry;
  13208. unsigned char * from = data + addr - pltgot;
  13209. if (from + (is_32bit_elf ? 4 : 8) > data_end)
  13210. {
  13211. warn (_("MIPS GOT entry extends beyond the end of available data\n"));
  13212. printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>"));
  13213. return (bfd_vma) -1;
  13214. }
  13215. else
  13216. {
  13217. entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
  13218. print_vma (entry, LONG_HEX);
  13219. }
  13220. }
  13221. return addr + (is_32bit_elf ? 4 : 8);
  13222. }
  13223. /* DATA points to the contents of a MIPS PLT GOT that starts at VMA
  13224. PLTGOT. Print the Address and Initial fields of an entry at VMA
  13225. ADDR and return the VMA of the next entry. */
  13226. static bfd_vma
  13227. print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
  13228. {
  13229. printf (" ");
  13230. print_vma (addr, LONG_HEX);
  13231. printf (" ");
  13232. if (data == NULL)
  13233. printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>"));
  13234. else
  13235. {
  13236. bfd_vma entry;
  13237. entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8);
  13238. print_vma (entry, LONG_HEX);
  13239. }
  13240. return addr + (is_32bit_elf ? 4 : 8);
  13241. }
  13242. static void
  13243. print_mips_ases (unsigned int mask)
  13244. {
  13245. if (mask & AFL_ASE_DSP)
  13246. fputs ("\n\tDSP ASE", stdout);
  13247. if (mask & AFL_ASE_DSPR2)
  13248. fputs ("\n\tDSP R2 ASE", stdout);
  13249. if (mask & AFL_ASE_DSPR3)
  13250. fputs ("\n\tDSP R3 ASE", stdout);
  13251. if (mask & AFL_ASE_EVA)
  13252. fputs ("\n\tEnhanced VA Scheme", stdout);
  13253. if (mask & AFL_ASE_MCU)
  13254. fputs ("\n\tMCU (MicroController) ASE", stdout);
  13255. if (mask & AFL_ASE_MDMX)
  13256. fputs ("\n\tMDMX ASE", stdout);
  13257. if (mask & AFL_ASE_MIPS3D)
  13258. fputs ("\n\tMIPS-3D ASE", stdout);
  13259. if (mask & AFL_ASE_MT)
  13260. fputs ("\n\tMT ASE", stdout);
  13261. if (mask & AFL_ASE_SMARTMIPS)
  13262. fputs ("\n\tSmartMIPS ASE", stdout);
  13263. if (mask & AFL_ASE_VIRT)
  13264. fputs ("\n\tVZ ASE", stdout);
  13265. if (mask & AFL_ASE_MSA)
  13266. fputs ("\n\tMSA ASE", stdout);
  13267. if (mask & AFL_ASE_MIPS16)
  13268. fputs ("\n\tMIPS16 ASE", stdout);
  13269. if (mask & AFL_ASE_MICROMIPS)
  13270. fputs ("\n\tMICROMIPS ASE", stdout);
  13271. if (mask & AFL_ASE_XPA)
  13272. fputs ("\n\tXPA ASE", stdout);
  13273. if (mask & AFL_ASE_MIPS16E2)
  13274. fputs ("\n\tMIPS16e2 ASE", stdout);
  13275. if (mask == 0)
  13276. fprintf (stdout, "\n\t%s", _("None"));
  13277. else if ((mask & ~AFL_ASE_MASK) != 0)
  13278. fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK);
  13279. }
  13280. static void
  13281. print_mips_isa_ext (unsigned int isa_ext)
  13282. {
  13283. switch (isa_ext)
  13284. {
  13285. case 0:
  13286. fputs (_("None"), stdout);
  13287. break;
  13288. case AFL_EXT_XLR:
  13289. fputs ("RMI XLR", stdout);
  13290. break;
  13291. case AFL_EXT_OCTEON3:
  13292. fputs ("Cavium Networks Octeon3", stdout);
  13293. break;
  13294. case AFL_EXT_OCTEON2:
  13295. fputs ("Cavium Networks Octeon2", stdout);
  13296. break;
  13297. case AFL_EXT_OCTEONP:
  13298. fputs ("Cavium Networks OcteonP", stdout);
  13299. break;
  13300. case AFL_EXT_LOONGSON_3A:
  13301. fputs ("Loongson 3A", stdout);
  13302. break;
  13303. case AFL_EXT_OCTEON:
  13304. fputs ("Cavium Networks Octeon", stdout);
  13305. break;
  13306. case AFL_EXT_5900:
  13307. fputs ("Toshiba R5900", stdout);
  13308. break;
  13309. case AFL_EXT_4650:
  13310. fputs ("MIPS R4650", stdout);
  13311. break;
  13312. case AFL_EXT_4010:
  13313. fputs ("LSI R4010", stdout);
  13314. break;
  13315. case AFL_EXT_4100:
  13316. fputs ("NEC VR4100", stdout);
  13317. break;
  13318. case AFL_EXT_3900:
  13319. fputs ("Toshiba R3900", stdout);
  13320. break;
  13321. case AFL_EXT_10000:
  13322. fputs ("MIPS R10000", stdout);
  13323. break;
  13324. case AFL_EXT_SB1:
  13325. fputs ("Broadcom SB-1", stdout);
  13326. break;
  13327. case AFL_EXT_4111:
  13328. fputs ("NEC VR4111/VR4181", stdout);
  13329. break;
  13330. case AFL_EXT_4120:
  13331. fputs ("NEC VR4120", stdout);
  13332. break;
  13333. case AFL_EXT_5400:
  13334. fputs ("NEC VR5400", stdout);
  13335. break;
  13336. case AFL_EXT_5500:
  13337. fputs ("NEC VR5500", stdout);
  13338. break;
  13339. case AFL_EXT_LOONGSON_2E:
  13340. fputs ("ST Microelectronics Loongson 2E", stdout);
  13341. break;
  13342. case AFL_EXT_LOONGSON_2F:
  13343. fputs ("ST Microelectronics Loongson 2F", stdout);
  13344. break;
  13345. case AFL_EXT_INTERAPTIV_MR2:
  13346. fputs ("Imagination interAptiv MR2", stdout);
  13347. break;
  13348. default:
  13349. fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext);
  13350. }
  13351. }
  13352. static signed int
  13353. get_mips_reg_size (int reg_size)
  13354. {
  13355. return (reg_size == AFL_REG_NONE) ? 0
  13356. : (reg_size == AFL_REG_32) ? 32
  13357. : (reg_size == AFL_REG_64) ? 64
  13358. : (reg_size == AFL_REG_128) ? 128
  13359. : -1;
  13360. }
  13361. static bfd_boolean
  13362. process_mips_specific (FILE * file)
  13363. {
  13364. Elf_Internal_Dyn * entry;
  13365. Elf_Internal_Shdr *sect = NULL;
  13366. size_t liblist_offset = 0;
  13367. size_t liblistno = 0;
  13368. size_t conflictsno = 0;
  13369. size_t options_offset = 0;
  13370. size_t conflicts_offset = 0;
  13371. size_t pltrelsz = 0;
  13372. size_t pltrel = 0;
  13373. bfd_vma pltgot = 0;
  13374. bfd_vma mips_pltgot = 0;
  13375. bfd_vma jmprel = 0;
  13376. bfd_vma local_gotno = 0;
  13377. bfd_vma gotsym = 0;
  13378. bfd_vma symtabno = 0;
  13379. bfd_boolean res = TRUE;
  13380. if (! process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
  13381. display_mips_gnu_attribute))
  13382. res = FALSE;
  13383. sect = find_section (".MIPS.abiflags");
  13384. if (sect != NULL)
  13385. {
  13386. Elf_External_ABIFlags_v0 *abiflags_ext;
  13387. Elf_Internal_ABIFlags_v0 abiflags_in;
  13388. if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size)
  13389. {
  13390. error (_("Corrupt MIPS ABI Flags section.\n"));
  13391. res = FALSE;
  13392. }
  13393. else
  13394. {
  13395. abiflags_ext = get_data (NULL, file, sect->sh_offset, 1,
  13396. sect->sh_size, _("MIPS ABI Flags section"));
  13397. if (abiflags_ext)
  13398. {
  13399. abiflags_in.version = BYTE_GET (abiflags_ext->version);
  13400. abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level);
  13401. abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev);
  13402. abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size);
  13403. abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size);
  13404. abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size);
  13405. abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi);
  13406. abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext);
  13407. abiflags_in.ases = BYTE_GET (abiflags_ext->ases);
  13408. abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1);
  13409. abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2);
  13410. printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version);
  13411. printf ("\nISA: MIPS%d", abiflags_in.isa_level);
  13412. if (abiflags_in.isa_rev > 1)
  13413. printf ("r%d", abiflags_in.isa_rev);
  13414. printf ("\nGPR size: %d",
  13415. get_mips_reg_size (abiflags_in.gpr_size));
  13416. printf ("\nCPR1 size: %d",
  13417. get_mips_reg_size (abiflags_in.cpr1_size));
  13418. printf ("\nCPR2 size: %d",
  13419. get_mips_reg_size (abiflags_in.cpr2_size));
  13420. fputs ("\nFP ABI: ", stdout);
  13421. print_mips_fp_abi_value (abiflags_in.fp_abi);
  13422. fputs ("ISA Extension: ", stdout);
  13423. print_mips_isa_ext (abiflags_in.isa_ext);
  13424. fputs ("\nASEs:", stdout);
  13425. print_mips_ases (abiflags_in.ases);
  13426. printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1);
  13427. printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2);
  13428. fputc ('\n', stdout);
  13429. free (abiflags_ext);
  13430. }
  13431. }
  13432. }
  13433. /* We have a lot of special sections. Thanks SGI! */
  13434. if (dynamic_section == NULL)
  13435. {
  13436. /* No dynamic information available. See if there is static GOT. */
  13437. sect = find_section (".got");
  13438. if (sect != NULL)
  13439. {
  13440. unsigned char *data_end;
  13441. unsigned char *data;
  13442. bfd_vma ent, end;
  13443. int addr_size;
  13444. pltgot = sect->sh_addr;
  13445. ent = pltgot;
  13446. addr_size = (is_32bit_elf ? 4 : 8);
  13447. end = pltgot + sect->sh_size;
  13448. data = (unsigned char *) get_data (NULL, file, sect->sh_offset,
  13449. end - pltgot, 1,
  13450. _("Global Offset Table data"));
  13451. /* PR 12855: Null data is handled gracefully throughout. */
  13452. data_end = data + (end - pltgot);
  13453. printf (_("\nStatic GOT:\n"));
  13454. printf (_(" Canonical gp value: "));
  13455. print_vma (ent + 0x7ff0, LONG_HEX);
  13456. printf ("\n\n");
  13457. /* In a dynamic binary GOT[0] is reserved for the dynamic
  13458. loader to store the lazy resolver pointer, however in
  13459. a static binary it may well have been omitted and GOT
  13460. reduced to a table of addresses.
  13461. PR 21344: Check for the entry being fully available
  13462. before fetching it. */
  13463. if (data
  13464. && data + ent - pltgot + addr_size <= data_end
  13465. && byte_get (data + ent - pltgot, addr_size) == 0)
  13466. {
  13467. printf (_(" Reserved entries:\n"));
  13468. printf (_(" %*s %10s %*s\n"),
  13469. addr_size * 2, _("Address"), _("Access"),
  13470. addr_size * 2, _("Value"));
  13471. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  13472. printf ("\n");
  13473. if (ent == (bfd_vma) -1)
  13474. goto sgot_print_fail;
  13475. /* Check for the MSB of GOT[1] being set, identifying a
  13476. GNU object. This entry will be used by some runtime
  13477. loaders, to store the module pointer. Otherwise this
  13478. is an ordinary local entry.
  13479. PR 21344: Check for the entry being fully available
  13480. before fetching it. */
  13481. if (data
  13482. && data + ent - pltgot + addr_size <= data_end
  13483. && (byte_get (data + ent - pltgot, addr_size)
  13484. >> (addr_size * 8 - 1)) != 0)
  13485. {
  13486. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  13487. printf ("\n");
  13488. if (ent == (bfd_vma) -1)
  13489. goto sgot_print_fail;
  13490. }
  13491. printf ("\n");
  13492. }
  13493. if (data != NULL && ent < end)
  13494. {
  13495. printf (_(" Local entries:\n"));
  13496. printf (" %*s %10s %*s\n",
  13497. addr_size * 2, _("Address"), _("Access"),
  13498. addr_size * 2, _("Value"));
  13499. while (ent < end)
  13500. {
  13501. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  13502. printf ("\n");
  13503. if (ent == (bfd_vma) -1)
  13504. goto sgot_print_fail;
  13505. }
  13506. printf ("\n");
  13507. }
  13508. sgot_print_fail:
  13509. if (data)
  13510. free (data);
  13511. }
  13512. return res;
  13513. }
  13514. for (entry = dynamic_section;
  13515. /* PR 17531 file: 012-50589-0.004. */
  13516. entry < dynamic_section + dynamic_nent && entry->d_tag != DT_NULL;
  13517. ++entry)
  13518. switch (entry->d_tag)
  13519. {
  13520. case DT_MIPS_LIBLIST:
  13521. liblist_offset
  13522. = offset_from_vma (file, entry->d_un.d_val,
  13523. liblistno * sizeof (Elf32_External_Lib));
  13524. break;
  13525. case DT_MIPS_LIBLISTNO:
  13526. liblistno = entry->d_un.d_val;
  13527. break;
  13528. case DT_MIPS_OPTIONS:
  13529. options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
  13530. break;
  13531. case DT_MIPS_CONFLICT:
  13532. conflicts_offset
  13533. = offset_from_vma (file, entry->d_un.d_val,
  13534. conflictsno * sizeof (Elf32_External_Conflict));
  13535. break;
  13536. case DT_MIPS_CONFLICTNO:
  13537. conflictsno = entry->d_un.d_val;
  13538. break;
  13539. case DT_PLTGOT:
  13540. pltgot = entry->d_un.d_ptr;
  13541. break;
  13542. case DT_MIPS_LOCAL_GOTNO:
  13543. local_gotno = entry->d_un.d_val;
  13544. break;
  13545. case DT_MIPS_GOTSYM:
  13546. gotsym = entry->d_un.d_val;
  13547. break;
  13548. case DT_MIPS_SYMTABNO:
  13549. symtabno = entry->d_un.d_val;
  13550. break;
  13551. case DT_MIPS_PLTGOT:
  13552. mips_pltgot = entry->d_un.d_ptr;
  13553. break;
  13554. case DT_PLTREL:
  13555. pltrel = entry->d_un.d_val;
  13556. break;
  13557. case DT_PLTRELSZ:
  13558. pltrelsz = entry->d_un.d_val;
  13559. break;
  13560. case DT_JMPREL:
  13561. jmprel = entry->d_un.d_ptr;
  13562. break;
  13563. default:
  13564. break;
  13565. }
  13566. if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
  13567. {
  13568. Elf32_External_Lib * elib;
  13569. size_t cnt;
  13570. elib = (Elf32_External_Lib *) get_data (NULL, file, liblist_offset,
  13571. liblistno,
  13572. sizeof (Elf32_External_Lib),
  13573. _("liblist section data"));
  13574. if (elib)
  13575. {
  13576. printf (_("\nSection '.liblist' contains %lu entries:\n"),
  13577. (unsigned long) liblistno);
  13578. fputs (_(" Library Time Stamp Checksum Version Flags\n"),
  13579. stdout);
  13580. for (cnt = 0; cnt < liblistno; ++cnt)
  13581. {
  13582. Elf32_Lib liblist;
  13583. time_t atime;
  13584. char timebuf[128];
  13585. struct tm * tmp;
  13586. liblist.l_name = BYTE_GET (elib[cnt].l_name);
  13587. atime = BYTE_GET (elib[cnt].l_time_stamp);
  13588. liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
  13589. liblist.l_version = BYTE_GET (elib[cnt].l_version);
  13590. liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
  13591. tmp = gmtime (&atime);
  13592. snprintf (timebuf, sizeof (timebuf),
  13593. "%04u-%02u-%02uT%02u:%02u:%02u",
  13594. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  13595. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  13596. printf ("%3lu: ", (unsigned long) cnt);
  13597. if (VALID_DYNAMIC_NAME (liblist.l_name))
  13598. print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
  13599. else
  13600. printf (_("<corrupt: %9ld>"), liblist.l_name);
  13601. printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
  13602. liblist.l_version);
  13603. if (liblist.l_flags == 0)
  13604. puts (_(" NONE"));
  13605. else
  13606. {
  13607. static const struct
  13608. {
  13609. const char * name;
  13610. int bit;
  13611. }
  13612. l_flags_vals[] =
  13613. {
  13614. { " EXACT_MATCH", LL_EXACT_MATCH },
  13615. { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
  13616. { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
  13617. { " EXPORTS", LL_EXPORTS },
  13618. { " DELAY_LOAD", LL_DELAY_LOAD },
  13619. { " DELTA", LL_DELTA }
  13620. };
  13621. int flags = liblist.l_flags;
  13622. size_t fcnt;
  13623. for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt)
  13624. if ((flags & l_flags_vals[fcnt].bit) != 0)
  13625. {
  13626. fputs (l_flags_vals[fcnt].name, stdout);
  13627. flags ^= l_flags_vals[fcnt].bit;
  13628. }
  13629. if (flags != 0)
  13630. printf (" %#x", (unsigned int) flags);
  13631. puts ("");
  13632. }
  13633. }
  13634. free (elib);
  13635. }
  13636. else
  13637. res = FALSE;
  13638. }
  13639. if (options_offset != 0)
  13640. {
  13641. Elf_External_Options * eopt;
  13642. Elf_Internal_Options * iopt;
  13643. Elf_Internal_Options * option;
  13644. size_t offset;
  13645. int cnt;
  13646. sect = section_headers;
  13647. /* Find the section header so that we get the size. */
  13648. sect = find_section_by_type (SHT_MIPS_OPTIONS);
  13649. /* PR 17533 file: 012-277276-0.004. */
  13650. if (sect == NULL)
  13651. {
  13652. error (_("No MIPS_OPTIONS header found\n"));
  13653. return FALSE;
  13654. }
  13655. eopt = (Elf_External_Options *) get_data (NULL, file, options_offset, 1,
  13656. sect->sh_size, _("options"));
  13657. if (eopt)
  13658. {
  13659. iopt = (Elf_Internal_Options *)
  13660. cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt));
  13661. if (iopt == NULL)
  13662. {
  13663. error (_("Out of memory allocating space for MIPS options\n"));
  13664. return FALSE;
  13665. }
  13666. offset = cnt = 0;
  13667. option = iopt;
  13668. while (offset <= sect->sh_size - sizeof (* eopt))
  13669. {
  13670. Elf_External_Options * eoption;
  13671. eoption = (Elf_External_Options *) ((char *) eopt + offset);
  13672. option->kind = BYTE_GET (eoption->kind);
  13673. option->size = BYTE_GET (eoption->size);
  13674. option->section = BYTE_GET (eoption->section);
  13675. option->info = BYTE_GET (eoption->info);
  13676. /* PR 17531: file: ffa0fa3b. */
  13677. if (option->size < sizeof (* eopt)
  13678. || offset + option->size > sect->sh_size)
  13679. {
  13680. error (_("Invalid size (%u) for MIPS option\n"), option->size);
  13681. return FALSE;
  13682. }
  13683. offset += option->size;
  13684. ++option;
  13685. ++cnt;
  13686. }
  13687. printf (_("\nSection '%s' contains %d entries:\n"),
  13688. printable_section_name (sect), cnt);
  13689. option = iopt;
  13690. offset = 0;
  13691. while (cnt-- > 0)
  13692. {
  13693. size_t len;
  13694. switch (option->kind)
  13695. {
  13696. case ODK_NULL:
  13697. /* This shouldn't happen. */
  13698. printf (" NULL %d %lx", option->section, option->info);
  13699. break;
  13700. case ODK_REGINFO:
  13701. printf (" REGINFO ");
  13702. if (elf_header.e_machine == EM_MIPS)
  13703. {
  13704. /* 32bit form. */
  13705. Elf32_External_RegInfo * ereg;
  13706. Elf32_RegInfo reginfo;
  13707. ereg = (Elf32_External_RegInfo *) (option + 1);
  13708. reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
  13709. reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
  13710. reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
  13711. reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
  13712. reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
  13713. reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
  13714. printf ("GPR %08lx GP 0x%lx\n",
  13715. reginfo.ri_gprmask,
  13716. (unsigned long) reginfo.ri_gp_value);
  13717. printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
  13718. reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
  13719. reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
  13720. }
  13721. else
  13722. {
  13723. /* 64 bit form. */
  13724. Elf64_External_RegInfo * ereg;
  13725. Elf64_Internal_RegInfo reginfo;
  13726. ereg = (Elf64_External_RegInfo *) (option + 1);
  13727. reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
  13728. reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
  13729. reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
  13730. reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
  13731. reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
  13732. reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
  13733. printf ("GPR %08lx GP 0x",
  13734. reginfo.ri_gprmask);
  13735. printf_vma (reginfo.ri_gp_value);
  13736. printf ("\n");
  13737. printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
  13738. reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
  13739. reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
  13740. }
  13741. ++option;
  13742. continue;
  13743. case ODK_EXCEPTIONS:
  13744. fputs (" EXCEPTIONS fpe_min(", stdout);
  13745. process_mips_fpe_exception (option->info & OEX_FPU_MIN);
  13746. fputs (") fpe_max(", stdout);
  13747. process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
  13748. fputs (")", stdout);
  13749. if (option->info & OEX_PAGE0)
  13750. fputs (" PAGE0", stdout);
  13751. if (option->info & OEX_SMM)
  13752. fputs (" SMM", stdout);
  13753. if (option->info & OEX_FPDBUG)
  13754. fputs (" FPDBUG", stdout);
  13755. if (option->info & OEX_DISMISS)
  13756. fputs (" DISMISS", stdout);
  13757. break;
  13758. case ODK_PAD:
  13759. fputs (" PAD ", stdout);
  13760. if (option->info & OPAD_PREFIX)
  13761. fputs (" PREFIX", stdout);
  13762. if (option->info & OPAD_POSTFIX)
  13763. fputs (" POSTFIX", stdout);
  13764. if (option->info & OPAD_SYMBOL)
  13765. fputs (" SYMBOL", stdout);
  13766. break;
  13767. case ODK_HWPATCH:
  13768. fputs (" HWPATCH ", stdout);
  13769. if (option->info & OHW_R4KEOP)
  13770. fputs (" R4KEOP", stdout);
  13771. if (option->info & OHW_R8KPFETCH)
  13772. fputs (" R8KPFETCH", stdout);
  13773. if (option->info & OHW_R5KEOP)
  13774. fputs (" R5KEOP", stdout);
  13775. if (option->info & OHW_R5KCVTL)
  13776. fputs (" R5KCVTL", stdout);
  13777. break;
  13778. case ODK_FILL:
  13779. fputs (" FILL ", stdout);
  13780. /* XXX Print content of info word? */
  13781. break;
  13782. case ODK_TAGS:
  13783. fputs (" TAGS ", stdout);
  13784. /* XXX Print content of info word? */
  13785. break;
  13786. case ODK_HWAND:
  13787. fputs (" HWAND ", stdout);
  13788. if (option->info & OHWA0_R4KEOP_CHECKED)
  13789. fputs (" R4KEOP_CHECKED", stdout);
  13790. if (option->info & OHWA0_R4KEOP_CLEAN)
  13791. fputs (" R4KEOP_CLEAN", stdout);
  13792. break;
  13793. case ODK_HWOR:
  13794. fputs (" HWOR ", stdout);
  13795. if (option->info & OHWA0_R4KEOP_CHECKED)
  13796. fputs (" R4KEOP_CHECKED", stdout);
  13797. if (option->info & OHWA0_R4KEOP_CLEAN)
  13798. fputs (" R4KEOP_CLEAN", stdout);
  13799. break;
  13800. case ODK_GP_GROUP:
  13801. printf (" GP_GROUP %#06lx self-contained %#06lx",
  13802. option->info & OGP_GROUP,
  13803. (option->info & OGP_SELF) >> 16);
  13804. break;
  13805. case ODK_IDENT:
  13806. printf (" IDENT %#06lx self-contained %#06lx",
  13807. option->info & OGP_GROUP,
  13808. (option->info & OGP_SELF) >> 16);
  13809. break;
  13810. default:
  13811. /* This shouldn't happen. */
  13812. printf (" %3d ??? %d %lx",
  13813. option->kind, option->section, option->info);
  13814. break;
  13815. }
  13816. len = sizeof (* eopt);
  13817. while (len < option->size)
  13818. {
  13819. unsigned char datum = * ((unsigned char *) eopt + offset + len);
  13820. if (ISPRINT (datum))
  13821. printf ("%c", datum);
  13822. else
  13823. printf ("\\%03o", datum);
  13824. len ++;
  13825. }
  13826. fputs ("\n", stdout);
  13827. offset += option->size;
  13828. ++option;
  13829. }
  13830. free (eopt);
  13831. }
  13832. else
  13833. res = FALSE;
  13834. }
  13835. if (conflicts_offset != 0 && conflictsno != 0)
  13836. {
  13837. Elf32_Conflict * iconf;
  13838. size_t cnt;
  13839. if (dynamic_symbols == NULL)
  13840. {
  13841. error (_("conflict list found without a dynamic symbol table\n"));
  13842. return FALSE;
  13843. }
  13844. /* PR 21345 - print a slightly more helpful error message
  13845. if we are sure that the cmalloc will fail. */
  13846. if (conflictsno * sizeof (* iconf) > current_file_size)
  13847. {
  13848. error (_("Overlarge number of conflicts detected: %lx\n"),
  13849. (long) conflictsno);
  13850. return FALSE;
  13851. }
  13852. iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf));
  13853. if (iconf == NULL)
  13854. {
  13855. error (_("Out of memory allocating space for dynamic conflicts\n"));
  13856. return FALSE;
  13857. }
  13858. if (is_32bit_elf)
  13859. {
  13860. Elf32_External_Conflict * econf32;
  13861. econf32 = (Elf32_External_Conflict *)
  13862. get_data (NULL, file, conflicts_offset, conflictsno,
  13863. sizeof (* econf32), _("conflict"));
  13864. if (!econf32)
  13865. return FALSE;
  13866. for (cnt = 0; cnt < conflictsno; ++cnt)
  13867. iconf[cnt] = BYTE_GET (econf32[cnt]);
  13868. free (econf32);
  13869. }
  13870. else
  13871. {
  13872. Elf64_External_Conflict * econf64;
  13873. econf64 = (Elf64_External_Conflict *)
  13874. get_data (NULL, file, conflicts_offset, conflictsno,
  13875. sizeof (* econf64), _("conflict"));
  13876. if (!econf64)
  13877. return FALSE;
  13878. for (cnt = 0; cnt < conflictsno; ++cnt)
  13879. iconf[cnt] = BYTE_GET (econf64[cnt]);
  13880. free (econf64);
  13881. }
  13882. printf (_("\nSection '.conflict' contains %lu entries:\n"),
  13883. (unsigned long) conflictsno);
  13884. puts (_(" Num: Index Value Name"));
  13885. for (cnt = 0; cnt < conflictsno; ++cnt)
  13886. {
  13887. printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
  13888. if (iconf[cnt] >= num_dynamic_syms)
  13889. printf (_("<corrupt symbol index>"));
  13890. else
  13891. {
  13892. Elf_Internal_Sym * psym;
  13893. psym = & dynamic_symbols[iconf[cnt]];
  13894. print_vma (psym->st_value, FULL_HEX);
  13895. putchar (' ');
  13896. if (VALID_DYNAMIC_NAME (psym->st_name))
  13897. print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
  13898. else
  13899. printf (_("<corrupt: %14ld>"), psym->st_name);
  13900. }
  13901. putchar ('\n');
  13902. }
  13903. free (iconf);
  13904. }
  13905. if (pltgot != 0 && local_gotno != 0)
  13906. {
  13907. bfd_vma ent, local_end, global_end;
  13908. size_t i, offset;
  13909. unsigned char * data;
  13910. unsigned char * data_end;
  13911. int addr_size;
  13912. ent = pltgot;
  13913. addr_size = (is_32bit_elf ? 4 : 8);
  13914. local_end = pltgot + local_gotno * addr_size;
  13915. /* PR binutils/17533 file: 012-111227-0.004 */
  13916. if (symtabno < gotsym)
  13917. {
  13918. error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"),
  13919. (unsigned long) gotsym, (unsigned long) symtabno);
  13920. return FALSE;
  13921. }
  13922. global_end = local_end + (symtabno - gotsym) * addr_size;
  13923. /* PR 17531: file: 54c91a34. */
  13924. if (global_end < local_end)
  13925. {
  13926. error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno);
  13927. return FALSE;
  13928. }
  13929. offset = offset_from_vma (file, pltgot, global_end - pltgot);
  13930. data = (unsigned char *) get_data (NULL, file, offset,
  13931. global_end - pltgot, 1,
  13932. _("Global Offset Table data"));
  13933. /* PR 12855: Null data is handled gracefully throughout. */
  13934. data_end = data + (global_end - pltgot);
  13935. printf (_("\nPrimary GOT:\n"));
  13936. printf (_(" Canonical gp value: "));
  13937. print_vma (pltgot + 0x7ff0, LONG_HEX);
  13938. printf ("\n\n");
  13939. printf (_(" Reserved entries:\n"));
  13940. printf (_(" %*s %10s %*s Purpose\n"),
  13941. addr_size * 2, _("Address"), _("Access"),
  13942. addr_size * 2, _("Initial"));
  13943. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  13944. printf (_(" Lazy resolver\n"));
  13945. if (ent == (bfd_vma) -1)
  13946. goto got_print_fail;
  13947. /* Check for the MSB of GOT[1] being set, denoting a GNU object.
  13948. This entry will be used by some runtime loaders, to store the
  13949. module pointer. Otherwise this is an ordinary local entry.
  13950. PR 21344: Check for the entry being fully available before
  13951. fetching it. */
  13952. if (data
  13953. && data + ent - pltgot + addr_size <= data_end
  13954. && (byte_get (data + ent - pltgot, addr_size)
  13955. >> (addr_size * 8 - 1)) != 0)
  13956. {
  13957. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  13958. printf (_(" Module pointer (GNU extension)\n"));
  13959. if (ent == (bfd_vma) -1)
  13960. goto got_print_fail;
  13961. }
  13962. printf ("\n");
  13963. if (data != NULL && ent < local_end)
  13964. {
  13965. printf (_(" Local entries:\n"));
  13966. printf (" %*s %10s %*s\n",
  13967. addr_size * 2, _("Address"), _("Access"),
  13968. addr_size * 2, _("Initial"));
  13969. while (ent < local_end)
  13970. {
  13971. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  13972. printf ("\n");
  13973. if (ent == (bfd_vma) -1)
  13974. goto got_print_fail;
  13975. }
  13976. printf ("\n");
  13977. }
  13978. if (data != NULL && gotsym < symtabno)
  13979. {
  13980. int sym_width;
  13981. printf (_(" Global entries:\n"));
  13982. printf (" %*s %10s %*s %*s %-7s %3s %s\n",
  13983. addr_size * 2, _("Address"),
  13984. _("Access"),
  13985. addr_size * 2, _("Initial"),
  13986. addr_size * 2, _("Sym.Val."),
  13987. _("Type"),
  13988. /* Note for translators: "Ndx" = abbreviated form of "Index". */
  13989. _("Ndx"), _("Name"));
  13990. sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
  13991. for (i = gotsym; i < symtabno; i++)
  13992. {
  13993. ent = print_mips_got_entry (data, pltgot, ent, data_end);
  13994. printf (" ");
  13995. if (dynamic_symbols == NULL)
  13996. printf (_("<no dynamic symbols>"));
  13997. else if (i < num_dynamic_syms)
  13998. {
  13999. Elf_Internal_Sym * psym = dynamic_symbols + i;
  14000. print_vma (psym->st_value, LONG_HEX);
  14001. printf (" %-7s %3s ",
  14002. get_symbol_type (ELF_ST_TYPE (psym->st_info)),
  14003. get_symbol_index_type (psym->st_shndx));
  14004. if (VALID_DYNAMIC_NAME (psym->st_name))
  14005. print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
  14006. else
  14007. printf (_("<corrupt: %14ld>"), psym->st_name);
  14008. }
  14009. else
  14010. printf (_("<symbol index %lu exceeds number of dynamic symbols>"),
  14011. (unsigned long) i);
  14012. printf ("\n");
  14013. if (ent == (bfd_vma) -1)
  14014. break;
  14015. }
  14016. printf ("\n");
  14017. }
  14018. got_print_fail:
  14019. if (data)
  14020. free (data);
  14021. }
  14022. if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0)
  14023. {
  14024. bfd_vma ent, end;
  14025. size_t offset, rel_offset;
  14026. unsigned long count, i;
  14027. unsigned char * data;
  14028. int addr_size, sym_width;
  14029. Elf_Internal_Rela * rels;
  14030. rel_offset = offset_from_vma (file, jmprel, pltrelsz);
  14031. if (pltrel == DT_RELA)
  14032. {
  14033. if (!slurp_rela_relocs (file, rel_offset, pltrelsz, &rels, &count))
  14034. return FALSE;
  14035. }
  14036. else
  14037. {
  14038. if (!slurp_rel_relocs (file, rel_offset, pltrelsz, &rels, &count))
  14039. return FALSE;
  14040. }
  14041. ent = mips_pltgot;
  14042. addr_size = (is_32bit_elf ? 4 : 8);
  14043. end = mips_pltgot + (2 + count) * addr_size;
  14044. offset = offset_from_vma (file, mips_pltgot, end - mips_pltgot);
  14045. data = (unsigned char *) get_data (NULL, file, offset, end - mips_pltgot,
  14046. 1, _("Procedure Linkage Table data"));
  14047. if (data == NULL)
  14048. return FALSE;
  14049. printf ("\nPLT GOT:\n\n");
  14050. printf (_(" Reserved entries:\n"));
  14051. printf (_(" %*s %*s Purpose\n"),
  14052. addr_size * 2, _("Address"), addr_size * 2, _("Initial"));
  14053. ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
  14054. printf (_(" PLT lazy resolver\n"));
  14055. ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
  14056. printf (_(" Module pointer\n"));
  14057. printf ("\n");
  14058. printf (_(" Entries:\n"));
  14059. printf (" %*s %*s %*s %-7s %3s %s\n",
  14060. addr_size * 2, _("Address"),
  14061. addr_size * 2, _("Initial"),
  14062. addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name"));
  14063. sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
  14064. for (i = 0; i < count; i++)
  14065. {
  14066. unsigned long idx = get_reloc_symindex (rels[i].r_info);
  14067. ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
  14068. printf (" ");
  14069. if (idx >= num_dynamic_syms)
  14070. printf (_("<corrupt symbol index: %lu>"), idx);
  14071. else
  14072. {
  14073. Elf_Internal_Sym * psym = dynamic_symbols + idx;
  14074. print_vma (psym->st_value, LONG_HEX);
  14075. printf (" %-7s %3s ",
  14076. get_symbol_type (ELF_ST_TYPE (psym->st_info)),
  14077. get_symbol_index_type (psym->st_shndx));
  14078. if (VALID_DYNAMIC_NAME (psym->st_name))
  14079. print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
  14080. else
  14081. printf (_("<corrupt: %14ld>"), psym->st_name);
  14082. }
  14083. printf ("\n");
  14084. }
  14085. printf ("\n");
  14086. if (data)
  14087. free (data);
  14088. free (rels);
  14089. }
  14090. return res;
  14091. }
  14092. static bfd_boolean
  14093. process_nds32_specific (FILE * file)
  14094. {
  14095. Elf_Internal_Shdr *sect = NULL;
  14096. sect = find_section (".nds32_e_flags");
  14097. if (sect != NULL)
  14098. {
  14099. unsigned int *flag;
  14100. printf ("\nNDS32 elf flags section:\n");
  14101. flag = get_data (NULL, file, sect->sh_offset, 1,
  14102. sect->sh_size, _("NDS32 elf flags section"));
  14103. if (! flag)
  14104. return FALSE;
  14105. switch ((*flag) & 0x3)
  14106. {
  14107. case 0:
  14108. printf ("(VEC_SIZE):\tNo entry.\n");
  14109. break;
  14110. case 1:
  14111. printf ("(VEC_SIZE):\t4 bytes\n");
  14112. break;
  14113. case 2:
  14114. printf ("(VEC_SIZE):\t16 bytes\n");
  14115. break;
  14116. case 3:
  14117. printf ("(VEC_SIZE):\treserved\n");
  14118. break;
  14119. }
  14120. }
  14121. return TRUE;
  14122. }
  14123. static bfd_boolean
  14124. process_gnu_liblist (FILE * file)
  14125. {
  14126. Elf_Internal_Shdr * section;
  14127. Elf_Internal_Shdr * string_sec;
  14128. Elf32_External_Lib * elib;
  14129. char * strtab;
  14130. size_t strtab_size;
  14131. size_t cnt;
  14132. unsigned i;
  14133. bfd_boolean res = TRUE;
  14134. if (! do_arch)
  14135. return TRUE;
  14136. for (i = 0, section = section_headers;
  14137. i < elf_header.e_shnum;
  14138. i++, section++)
  14139. {
  14140. switch (section->sh_type)
  14141. {
  14142. case SHT_GNU_LIBLIST:
  14143. if (section->sh_link >= elf_header.e_shnum)
  14144. break;
  14145. elib = (Elf32_External_Lib *)
  14146. get_data (NULL, file, section->sh_offset, 1, section->sh_size,
  14147. _("liblist section data"));
  14148. if (elib == NULL)
  14149. {
  14150. res = FALSE;
  14151. break;
  14152. }
  14153. string_sec = section_headers + section->sh_link;
  14154. strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1,
  14155. string_sec->sh_size,
  14156. _("liblist string table"));
  14157. if (strtab == NULL
  14158. || section->sh_entsize != sizeof (Elf32_External_Lib))
  14159. {
  14160. free (elib);
  14161. free (strtab);
  14162. res = FALSE;
  14163. break;
  14164. }
  14165. strtab_size = string_sec->sh_size;
  14166. printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
  14167. printable_section_name (section),
  14168. (unsigned long) (section->sh_size / sizeof (Elf32_External_Lib)));
  14169. puts (_(" Library Time Stamp Checksum Version Flags"));
  14170. for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
  14171. ++cnt)
  14172. {
  14173. Elf32_Lib liblist;
  14174. time_t atime;
  14175. char timebuf[128];
  14176. struct tm * tmp;
  14177. liblist.l_name = BYTE_GET (elib[cnt].l_name);
  14178. atime = BYTE_GET (elib[cnt].l_time_stamp);
  14179. liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
  14180. liblist.l_version = BYTE_GET (elib[cnt].l_version);
  14181. liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
  14182. tmp = gmtime (&atime);
  14183. snprintf (timebuf, sizeof (timebuf),
  14184. "%04u-%02u-%02uT%02u:%02u:%02u",
  14185. tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
  14186. tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
  14187. printf ("%3lu: ", (unsigned long) cnt);
  14188. if (do_wide)
  14189. printf ("%-20s", liblist.l_name < strtab_size
  14190. ? strtab + liblist.l_name : _("<corrupt>"));
  14191. else
  14192. printf ("%-20.20s", liblist.l_name < strtab_size
  14193. ? strtab + liblist.l_name : _("<corrupt>"));
  14194. printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
  14195. liblist.l_version, liblist.l_flags);
  14196. }
  14197. free (elib);
  14198. free (strtab);
  14199. }
  14200. }
  14201. return res;
  14202. }
  14203. static const char *
  14204. get_note_type (unsigned e_type)
  14205. {
  14206. static char buff[64];
  14207. if (elf_header.e_type == ET_CORE)
  14208. switch (e_type)
  14209. {
  14210. case NT_AUXV:
  14211. return _("NT_AUXV (auxiliary vector)");
  14212. case NT_PRSTATUS:
  14213. return _("NT_PRSTATUS (prstatus structure)");
  14214. case NT_FPREGSET:
  14215. return _("NT_FPREGSET (floating point registers)");
  14216. case NT_PRPSINFO:
  14217. return _("NT_PRPSINFO (prpsinfo structure)");
  14218. case NT_TASKSTRUCT:
  14219. return _("NT_TASKSTRUCT (task structure)");
  14220. case NT_PRXFPREG:
  14221. return _("NT_PRXFPREG (user_xfpregs structure)");
  14222. case NT_PPC_VMX:
  14223. return _("NT_PPC_VMX (ppc Altivec registers)");
  14224. case NT_PPC_VSX:
  14225. return _("NT_PPC_VSX (ppc VSX registers)");
  14226. case NT_386_TLS:
  14227. return _("NT_386_TLS (x86 TLS information)");
  14228. case NT_386_IOPERM:
  14229. return _("NT_386_IOPERM (x86 I/O permissions)");
  14230. case NT_X86_XSTATE:
  14231. return _("NT_X86_XSTATE (x86 XSAVE extended state)");
  14232. case NT_S390_HIGH_GPRS:
  14233. return _("NT_S390_HIGH_GPRS (s390 upper register halves)");
  14234. case NT_S390_TIMER:
  14235. return _("NT_S390_TIMER (s390 timer register)");
  14236. case NT_S390_TODCMP:
  14237. return _("NT_S390_TODCMP (s390 TOD comparator register)");
  14238. case NT_S390_TODPREG:
  14239. return _("NT_S390_TODPREG (s390 TOD programmable register)");
  14240. case NT_S390_CTRS:
  14241. return _("NT_S390_CTRS (s390 control registers)");
  14242. case NT_S390_PREFIX:
  14243. return _("NT_S390_PREFIX (s390 prefix register)");
  14244. case NT_S390_LAST_BREAK:
  14245. return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
  14246. case NT_S390_SYSTEM_CALL:
  14247. return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
  14248. case NT_S390_TDB:
  14249. return _("NT_S390_TDB (s390 transaction diagnostic block)");
  14250. case NT_S390_VXRS_LOW:
  14251. return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)");
  14252. case NT_S390_VXRS_HIGH:
  14253. return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)");
  14254. case NT_S390_GS_CB:
  14255. return _("NT_S390_GS_CB (s390 guarded-storage registers)");
  14256. case NT_S390_GS_BC:
  14257. return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)");
  14258. case NT_ARM_VFP:
  14259. return _("NT_ARM_VFP (arm VFP registers)");
  14260. case NT_ARM_TLS:
  14261. return _("NT_ARM_TLS (AArch TLS registers)");
  14262. case NT_ARM_HW_BREAK:
  14263. return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
  14264. case NT_ARM_HW_WATCH:
  14265. return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
  14266. case NT_PSTATUS:
  14267. return _("NT_PSTATUS (pstatus structure)");
  14268. case NT_FPREGS:
  14269. return _("NT_FPREGS (floating point registers)");
  14270. case NT_PSINFO:
  14271. return _("NT_PSINFO (psinfo structure)");
  14272. case NT_LWPSTATUS:
  14273. return _("NT_LWPSTATUS (lwpstatus_t structure)");
  14274. case NT_LWPSINFO:
  14275. return _("NT_LWPSINFO (lwpsinfo_t structure)");
  14276. case NT_WIN32PSTATUS:
  14277. return _("NT_WIN32PSTATUS (win32_pstatus structure)");
  14278. case NT_SIGINFO:
  14279. return _("NT_SIGINFO (siginfo_t data)");
  14280. case NT_FILE:
  14281. return _("NT_FILE (mapped files)");
  14282. default:
  14283. break;
  14284. }
  14285. else
  14286. switch (e_type)
  14287. {
  14288. case NT_VERSION:
  14289. return _("NT_VERSION (version)");
  14290. case NT_ARCH:
  14291. return _("NT_ARCH (architecture)");
  14292. case NT_GNU_BUILD_ATTRIBUTE_OPEN:
  14293. return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
  14294. case NT_GNU_BUILD_ATTRIBUTE_FUNC:
  14295. return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
  14296. default:
  14297. break;
  14298. }
  14299. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
  14300. return buff;
  14301. }
  14302. static bfd_boolean
  14303. print_core_note (Elf_Internal_Note *pnote)
  14304. {
  14305. unsigned int addr_size = is_32bit_elf ? 4 : 8;
  14306. bfd_vma count, page_size;
  14307. unsigned char *descdata, *filenames, *descend;
  14308. if (pnote->type != NT_FILE)
  14309. return TRUE;
  14310. #ifndef BFD64
  14311. if (!is_32bit_elf)
  14312. {
  14313. printf (_(" Cannot decode 64-bit note in 32-bit build\n"));
  14314. /* Still "successful". */
  14315. return TRUE;
  14316. }
  14317. #endif
  14318. if (pnote->descsz < 2 * addr_size)
  14319. {
  14320. error (_(" Malformed note - too short for header\n"));
  14321. return FALSE;
  14322. }
  14323. descdata = (unsigned char *) pnote->descdata;
  14324. descend = descdata + pnote->descsz;
  14325. if (descdata[pnote->descsz - 1] != '\0')
  14326. {
  14327. error (_(" Malformed note - does not end with \\0\n"));
  14328. return FALSE;
  14329. }
  14330. count = byte_get (descdata, addr_size);
  14331. descdata += addr_size;
  14332. page_size = byte_get (descdata, addr_size);
  14333. descdata += addr_size;
  14334. if (pnote->descsz < 2 * addr_size + count * 3 * addr_size)
  14335. {
  14336. error (_(" Malformed note - too short for supplied file count\n"));
  14337. return FALSE;
  14338. }
  14339. printf (_(" Page size: "));
  14340. print_vma (page_size, DEC);
  14341. printf ("\n");
  14342. printf (_(" %*s%*s%*s\n"),
  14343. (int) (2 + 2 * addr_size), _("Start"),
  14344. (int) (4 + 2 * addr_size), _("End"),
  14345. (int) (4 + 2 * addr_size), _("Page Offset"));
  14346. filenames = descdata + count * 3 * addr_size;
  14347. while (count-- > 0)
  14348. {
  14349. bfd_vma start, end, file_ofs;
  14350. if (filenames == descend)
  14351. {
  14352. error (_(" Malformed note - filenames end too early\n"));
  14353. return FALSE;
  14354. }
  14355. start = byte_get (descdata, addr_size);
  14356. descdata += addr_size;
  14357. end = byte_get (descdata, addr_size);
  14358. descdata += addr_size;
  14359. file_ofs = byte_get (descdata, addr_size);
  14360. descdata += addr_size;
  14361. printf (" ");
  14362. print_vma (start, FULL_HEX);
  14363. printf (" ");
  14364. print_vma (end, FULL_HEX);
  14365. printf (" ");
  14366. print_vma (file_ofs, FULL_HEX);
  14367. printf ("\n %s\n", filenames);
  14368. filenames += 1 + strlen ((char *) filenames);
  14369. }
  14370. return TRUE;
  14371. }
  14372. static const char *
  14373. get_gnu_elf_note_type (unsigned e_type)
  14374. {
  14375. /* NB/ Keep this switch statement in sync with print_gnu_note (). */
  14376. switch (e_type)
  14377. {
  14378. case NT_GNU_ABI_TAG:
  14379. return _("NT_GNU_ABI_TAG (ABI version tag)");
  14380. case NT_GNU_HWCAP:
  14381. return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)");
  14382. case NT_GNU_BUILD_ID:
  14383. return _("NT_GNU_BUILD_ID (unique build ID bitstring)");
  14384. case NT_GNU_GOLD_VERSION:
  14385. return _("NT_GNU_GOLD_VERSION (gold version)");
  14386. case NT_GNU_PROPERTY_TYPE_0:
  14387. return _("NT_GNU_PROPERTY_TYPE_0");
  14388. case NT_GNU_BUILD_ATTRIBUTE_OPEN:
  14389. return _("NT_GNU_BUILD_ATTRIBUTE_OPEN");
  14390. case NT_GNU_BUILD_ATTRIBUTE_FUNC:
  14391. return _("NT_GNU_BUILD_ATTRIBUTE_FUNC");
  14392. default:
  14393. {
  14394. static char buff[64];
  14395. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
  14396. return buff;
  14397. }
  14398. }
  14399. }
  14400. static void
  14401. decode_x86_isa (unsigned int bitmask)
  14402. {
  14403. while (bitmask)
  14404. {
  14405. unsigned int bit = bitmask & (- bitmask);
  14406. bitmask &= ~ bit;
  14407. switch (bit)
  14408. {
  14409. case GNU_PROPERTY_X86_ISA_1_486: printf ("i486"); break;
  14410. case GNU_PROPERTY_X86_ISA_1_586: printf ("586"); break;
  14411. case GNU_PROPERTY_X86_ISA_1_686: printf ("686"); break;
  14412. case GNU_PROPERTY_X86_ISA_1_SSE: printf ("SSE"); break;
  14413. case GNU_PROPERTY_X86_ISA_1_SSE2: printf ("SSE2"); break;
  14414. case GNU_PROPERTY_X86_ISA_1_SSE3: printf ("SSE3"); break;
  14415. case GNU_PROPERTY_X86_ISA_1_SSSE3: printf ("SSSE3"); break;
  14416. case GNU_PROPERTY_X86_ISA_1_SSE4_1: printf ("SSE4_1"); break;
  14417. case GNU_PROPERTY_X86_ISA_1_SSE4_2: printf ("SSE4_2"); break;
  14418. case GNU_PROPERTY_X86_ISA_1_AVX: printf ("AVX"); break;
  14419. case GNU_PROPERTY_X86_ISA_1_AVX2: printf ("AVX2"); break;
  14420. case GNU_PROPERTY_X86_ISA_1_AVX512F: printf ("AVX512F"); break;
  14421. case GNU_PROPERTY_X86_ISA_1_AVX512CD: printf ("AVX512CD"); break;
  14422. case GNU_PROPERTY_X86_ISA_1_AVX512ER: printf ("AVX512ER"); break;
  14423. case GNU_PROPERTY_X86_ISA_1_AVX512PF: printf ("AVX512PF"); break;
  14424. case GNU_PROPERTY_X86_ISA_1_AVX512VL: printf ("AVX512VL"); break;
  14425. case GNU_PROPERTY_X86_ISA_1_AVX512DQ: printf ("AVX512DQ"); break;
  14426. case GNU_PROPERTY_X86_ISA_1_AVX512BW: printf ("AVX512BW"); break;
  14427. default: printf (_("<unknown: %x>"), bit); break;
  14428. }
  14429. if (bitmask)
  14430. printf (", ");
  14431. }
  14432. }
  14433. static void
  14434. decode_x86_feature (unsigned int type, unsigned int bitmask)
  14435. {
  14436. while (bitmask)
  14437. {
  14438. unsigned int bit = bitmask & (- bitmask);
  14439. bitmask &= ~ bit;
  14440. switch (bit)
  14441. {
  14442. case GNU_PROPERTY_X86_FEATURE_1_IBT:
  14443. switch (type)
  14444. {
  14445. case GNU_PROPERTY_X86_FEATURE_1_AND:
  14446. printf ("IBT");
  14447. break;
  14448. default:
  14449. /* This should never happen. */
  14450. abort ();
  14451. }
  14452. break;
  14453. case GNU_PROPERTY_X86_FEATURE_1_SHSTK:
  14454. switch (type)
  14455. {
  14456. case GNU_PROPERTY_X86_FEATURE_1_AND:
  14457. printf ("SHSTK");
  14458. break;
  14459. default:
  14460. /* This should never happen. */
  14461. abort ();
  14462. }
  14463. break;
  14464. default:
  14465. printf (_("<unknown: %x>"), bit);
  14466. break;
  14467. }
  14468. if (bitmask)
  14469. printf (", ");
  14470. }
  14471. }
  14472. static void
  14473. print_gnu_property_note (Elf_Internal_Note * pnote)
  14474. {
  14475. unsigned char * ptr = (unsigned char *) pnote->descdata;
  14476. unsigned char * ptr_end = ptr + pnote->descsz;
  14477. unsigned int size = is_32bit_elf ? 4 : 8;
  14478. printf (_(" Properties: "));
  14479. if (pnote->descsz < 8 || (pnote->descsz % size) != 0)
  14480. {
  14481. printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz);
  14482. return;
  14483. }
  14484. while (1)
  14485. {
  14486. unsigned int j;
  14487. unsigned int type = byte_get (ptr, 4);
  14488. unsigned int datasz = byte_get (ptr + 4, 4);
  14489. ptr += 8;
  14490. if ((ptr + datasz) > ptr_end)
  14491. {
  14492. printf (_("<corrupt type (%#x) datasz: %#x>\n"),
  14493. type, datasz);
  14494. break;
  14495. }
  14496. if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC)
  14497. {
  14498. if (elf_header.e_machine == EM_X86_64
  14499. || elf_header.e_machine == EM_IAMCU
  14500. || elf_header.e_machine == EM_386)
  14501. {
  14502. switch (type)
  14503. {
  14504. case GNU_PROPERTY_X86_ISA_1_USED:
  14505. printf ("x86 ISA used: ");
  14506. if (datasz != 4)
  14507. printf (_("<corrupt length: %#x> "), datasz);
  14508. else
  14509. decode_x86_isa (byte_get (ptr, 4));
  14510. goto next;
  14511. case GNU_PROPERTY_X86_ISA_1_NEEDED:
  14512. printf ("x86 ISA needed: ");
  14513. if (datasz != 4)
  14514. printf (_("<corrupt length: %#x> "), datasz);
  14515. else
  14516. decode_x86_isa (byte_get (ptr, 4));
  14517. goto next;
  14518. case GNU_PROPERTY_X86_FEATURE_1_AND:
  14519. printf ("x86 feature: ");
  14520. if (datasz != 4)
  14521. printf (_("<corrupt length: %#x> "), datasz);
  14522. else
  14523. decode_x86_feature (type, byte_get (ptr, 4));
  14524. goto next;
  14525. default:
  14526. break;
  14527. }
  14528. }
  14529. }
  14530. else
  14531. {
  14532. switch (type)
  14533. {
  14534. case GNU_PROPERTY_STACK_SIZE:
  14535. printf (_("stack size: "));
  14536. if (datasz != size)
  14537. printf (_("<corrupt length: %#x> "), datasz);
  14538. else
  14539. printf ("%#lx", (unsigned long) byte_get (ptr, size));
  14540. goto next;
  14541. case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
  14542. printf ("no copy on protected ");
  14543. if (datasz)
  14544. printf (_("<corrupt length: %#x> "), datasz);
  14545. goto next;
  14546. default:
  14547. break;
  14548. }
  14549. }
  14550. if (type < GNU_PROPERTY_LOPROC)
  14551. printf (_("<unknown type %#x data: "), type);
  14552. else if (type < GNU_PROPERTY_LOUSER)
  14553. printf (_("<procesor-specific type %#x data: "), type);
  14554. else
  14555. printf (_("<application-specific type %#x data: "), type);
  14556. for (j = 0; j < datasz; ++j)
  14557. printf ("%02x ", ptr[j] & 0xff);
  14558. printf (">");
  14559. next:
  14560. ptr += ((datasz + (size - 1)) & ~ (size - 1));
  14561. if (ptr == ptr_end)
  14562. break;
  14563. else
  14564. {
  14565. if (do_wide)
  14566. printf (", ");
  14567. else
  14568. printf ("\n\t");
  14569. }
  14570. if (ptr > (ptr_end - 8))
  14571. {
  14572. printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz);
  14573. break;
  14574. }
  14575. }
  14576. printf ("\n");
  14577. }
  14578. static bfd_boolean
  14579. print_gnu_note (Elf_Internal_Note *pnote)
  14580. {
  14581. /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */
  14582. switch (pnote->type)
  14583. {
  14584. case NT_GNU_BUILD_ID:
  14585. {
  14586. unsigned long i;
  14587. printf (_(" Build ID: "));
  14588. for (i = 0; i < pnote->descsz; ++i)
  14589. printf ("%02x", pnote->descdata[i] & 0xff);
  14590. printf ("\n");
  14591. }
  14592. break;
  14593. case NT_GNU_ABI_TAG:
  14594. {
  14595. unsigned long os, major, minor, subminor;
  14596. const char *osname;
  14597. /* PR 17531: file: 030-599401-0.004. */
  14598. if (pnote->descsz < 16)
  14599. {
  14600. printf (_(" <corrupt GNU_ABI_TAG>\n"));
  14601. break;
  14602. }
  14603. os = byte_get ((unsigned char *) pnote->descdata, 4);
  14604. major = byte_get ((unsigned char *) pnote->descdata + 4, 4);
  14605. minor = byte_get ((unsigned char *) pnote->descdata + 8, 4);
  14606. subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4);
  14607. switch (os)
  14608. {
  14609. case GNU_ABI_TAG_LINUX:
  14610. osname = "Linux";
  14611. break;
  14612. case GNU_ABI_TAG_HURD:
  14613. osname = "Hurd";
  14614. break;
  14615. case GNU_ABI_TAG_SOLARIS:
  14616. osname = "Solaris";
  14617. break;
  14618. case GNU_ABI_TAG_FREEBSD:
  14619. osname = "FreeBSD";
  14620. break;
  14621. case GNU_ABI_TAG_NETBSD:
  14622. osname = "NetBSD";
  14623. break;
  14624. case GNU_ABI_TAG_SYLLABLE:
  14625. osname = "Syllable";
  14626. break;
  14627. case GNU_ABI_TAG_NACL:
  14628. osname = "NaCl";
  14629. break;
  14630. default:
  14631. osname = "Unknown";
  14632. break;
  14633. }
  14634. printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname,
  14635. major, minor, subminor);
  14636. }
  14637. break;
  14638. case NT_GNU_GOLD_VERSION:
  14639. {
  14640. unsigned long i;
  14641. printf (_(" Version: "));
  14642. for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i)
  14643. printf ("%c", pnote->descdata[i]);
  14644. printf ("\n");
  14645. }
  14646. break;
  14647. case NT_GNU_HWCAP:
  14648. {
  14649. unsigned long num_entries, mask;
  14650. /* Hardware capabilities information. Word 0 is the number of entries.
  14651. Word 1 is a bitmask of enabled entries. The rest of the descriptor
  14652. is a series of entries, where each entry is a single byte followed
  14653. by a nul terminated string. The byte gives the bit number to test
  14654. if enabled in the bitmask. */
  14655. printf (_(" Hardware Capabilities: "));
  14656. if (pnote->descsz < 8)
  14657. {
  14658. error (_("<corrupt GNU_HWCAP>\n"));
  14659. return FALSE;
  14660. }
  14661. num_entries = byte_get ((unsigned char *) pnote->descdata, 4);
  14662. mask = byte_get ((unsigned char *) pnote->descdata + 4, 4);
  14663. printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries, mask);
  14664. /* FIXME: Add code to display the entries... */
  14665. }
  14666. break;
  14667. case NT_GNU_PROPERTY_TYPE_0:
  14668. print_gnu_property_note (pnote);
  14669. break;
  14670. default:
  14671. /* Handle unrecognised types. An error message should have already been
  14672. created by get_gnu_elf_note_type(), so all that we need to do is to
  14673. display the data. */
  14674. {
  14675. unsigned long i;
  14676. printf (_(" Description data: "));
  14677. for (i = 0; i < pnote->descsz; ++i)
  14678. printf ("%02x ", pnote->descdata[i] & 0xff);
  14679. printf ("\n");
  14680. }
  14681. break;
  14682. }
  14683. return TRUE;
  14684. }
  14685. static const char *
  14686. get_v850_elf_note_type (enum v850_notes n_type)
  14687. {
  14688. static char buff[64];
  14689. switch (n_type)
  14690. {
  14691. case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects");
  14692. case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double");
  14693. case V850_NOTE_FPU_INFO: return _("Type of FPU support needed");
  14694. case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions");
  14695. case V850_NOTE_CACHE_INFO: return _("Use of cache");
  14696. case V850_NOTE_MMU_INFO: return _("Use of MMU");
  14697. default:
  14698. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type);
  14699. return buff;
  14700. }
  14701. }
  14702. static bfd_boolean
  14703. print_v850_note (Elf_Internal_Note * pnote)
  14704. {
  14705. unsigned int val;
  14706. if (pnote->descsz != 4)
  14707. return FALSE;
  14708. val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz);
  14709. if (val == 0)
  14710. {
  14711. printf (_("not set\n"));
  14712. return TRUE;
  14713. }
  14714. switch (pnote->type)
  14715. {
  14716. case V850_NOTE_ALIGNMENT:
  14717. switch (val)
  14718. {
  14719. case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return TRUE;
  14720. case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return TRUE;
  14721. }
  14722. break;
  14723. case V850_NOTE_DATA_SIZE:
  14724. switch (val)
  14725. {
  14726. case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return TRUE;
  14727. case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return TRUE;
  14728. }
  14729. break;
  14730. case V850_NOTE_FPU_INFO:
  14731. switch (val)
  14732. {
  14733. case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return TRUE;
  14734. case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return TRUE;
  14735. }
  14736. break;
  14737. case V850_NOTE_MMU_INFO:
  14738. case V850_NOTE_CACHE_INFO:
  14739. case V850_NOTE_SIMD_INFO:
  14740. if (val == EF_RH850_SIMD)
  14741. {
  14742. printf (_("yes\n"));
  14743. return TRUE;
  14744. }
  14745. break;
  14746. default:
  14747. /* An 'unknown note type' message will already have been displayed. */
  14748. break;
  14749. }
  14750. printf (_("unknown value: %x\n"), val);
  14751. return FALSE;
  14752. }
  14753. static bfd_boolean
  14754. process_netbsd_elf_note (Elf_Internal_Note * pnote)
  14755. {
  14756. unsigned int version;
  14757. switch (pnote->type)
  14758. {
  14759. case NT_NETBSD_IDENT:
  14760. version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
  14761. if ((version / 10000) % 100)
  14762. printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
  14763. version, version / 100000000, (version / 1000000) % 100,
  14764. (version / 10000) % 100 > 26 ? "Z" : "",
  14765. 'A' + (version / 10000) % 26);
  14766. else
  14767. printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz,
  14768. version, version / 100000000, (version / 1000000) % 100,
  14769. (version / 100) % 100);
  14770. return TRUE;
  14771. case NT_NETBSD_MARCH:
  14772. printf (" NetBSD\t0x%08lx\tMARCH <%s>\n", pnote->descsz,
  14773. pnote->descdata);
  14774. return TRUE;
  14775. default:
  14776. printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", pnote->descsz,
  14777. pnote->type);
  14778. return FALSE;
  14779. }
  14780. }
  14781. static const char *
  14782. get_freebsd_elfcore_note_type (unsigned e_type)
  14783. {
  14784. switch (e_type)
  14785. {
  14786. case NT_FREEBSD_THRMISC:
  14787. return _("NT_THRMISC (thrmisc structure)");
  14788. case NT_FREEBSD_PROCSTAT_PROC:
  14789. return _("NT_PROCSTAT_PROC (proc data)");
  14790. case NT_FREEBSD_PROCSTAT_FILES:
  14791. return _("NT_PROCSTAT_FILES (files data)");
  14792. case NT_FREEBSD_PROCSTAT_VMMAP:
  14793. return _("NT_PROCSTAT_VMMAP (vmmap data)");
  14794. case NT_FREEBSD_PROCSTAT_GROUPS:
  14795. return _("NT_PROCSTAT_GROUPS (groups data)");
  14796. case NT_FREEBSD_PROCSTAT_UMASK:
  14797. return _("NT_PROCSTAT_UMASK (umask data)");
  14798. case NT_FREEBSD_PROCSTAT_RLIMIT:
  14799. return _("NT_PROCSTAT_RLIMIT (rlimit data)");
  14800. case NT_FREEBSD_PROCSTAT_OSREL:
  14801. return _("NT_PROCSTAT_OSREL (osreldate data)");
  14802. case NT_FREEBSD_PROCSTAT_PSSTRINGS:
  14803. return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)");
  14804. case NT_FREEBSD_PROCSTAT_AUXV:
  14805. return _("NT_PROCSTAT_AUXV (auxv data)");
  14806. }
  14807. return get_note_type (e_type);
  14808. }
  14809. static const char *
  14810. get_netbsd_elfcore_note_type (unsigned e_type)
  14811. {
  14812. static char buff[64];
  14813. if (e_type == NT_NETBSDCORE_PROCINFO)
  14814. {
  14815. /* NetBSD core "procinfo" structure. */
  14816. return _("NetBSD procinfo structure");
  14817. }
  14818. /* As of Jan 2002 there are no other machine-independent notes
  14819. defined for NetBSD core files. If the note type is less
  14820. than the start of the machine-dependent note types, we don't
  14821. understand it. */
  14822. if (e_type < NT_NETBSDCORE_FIRSTMACH)
  14823. {
  14824. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
  14825. return buff;
  14826. }
  14827. switch (elf_header.e_machine)
  14828. {
  14829. /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
  14830. and PT_GETFPREGS == mach+2. */
  14831. case EM_OLD_ALPHA:
  14832. case EM_ALPHA:
  14833. case EM_SPARC:
  14834. case EM_SPARC32PLUS:
  14835. case EM_SPARCV9:
  14836. switch (e_type)
  14837. {
  14838. case NT_NETBSDCORE_FIRSTMACH + 0:
  14839. return _("PT_GETREGS (reg structure)");
  14840. case NT_NETBSDCORE_FIRSTMACH + 2:
  14841. return _("PT_GETFPREGS (fpreg structure)");
  14842. default:
  14843. break;
  14844. }
  14845. break;
  14846. /* On all other arch's, PT_GETREGS == mach+1 and
  14847. PT_GETFPREGS == mach+3. */
  14848. default:
  14849. switch (e_type)
  14850. {
  14851. case NT_NETBSDCORE_FIRSTMACH + 1:
  14852. return _("PT_GETREGS (reg structure)");
  14853. case NT_NETBSDCORE_FIRSTMACH + 3:
  14854. return _("PT_GETFPREGS (fpreg structure)");
  14855. default:
  14856. break;
  14857. }
  14858. }
  14859. snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d",
  14860. e_type - NT_NETBSDCORE_FIRSTMACH);
  14861. return buff;
  14862. }
  14863. static const char *
  14864. get_stapsdt_note_type (unsigned e_type)
  14865. {
  14866. static char buff[64];
  14867. switch (e_type)
  14868. {
  14869. case NT_STAPSDT:
  14870. return _("NT_STAPSDT (SystemTap probe descriptors)");
  14871. default:
  14872. break;
  14873. }
  14874. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
  14875. return buff;
  14876. }
  14877. static bfd_boolean
  14878. print_stapsdt_note (Elf_Internal_Note *pnote)
  14879. {
  14880. int addr_size = is_32bit_elf ? 4 : 8;
  14881. char *data = pnote->descdata;
  14882. char *data_end = pnote->descdata + pnote->descsz;
  14883. bfd_vma pc, base_addr, semaphore;
  14884. char *provider, *probe, *arg_fmt;
  14885. pc = byte_get ((unsigned char *) data, addr_size);
  14886. data += addr_size;
  14887. base_addr = byte_get ((unsigned char *) data, addr_size);
  14888. data += addr_size;
  14889. semaphore = byte_get ((unsigned char *) data, addr_size);
  14890. data += addr_size;
  14891. provider = data;
  14892. data += strlen (data) + 1;
  14893. probe = data;
  14894. data += strlen (data) + 1;
  14895. arg_fmt = data;
  14896. data += strlen (data) + 1;
  14897. printf (_(" Provider: %s\n"), provider);
  14898. printf (_(" Name: %s\n"), probe);
  14899. printf (_(" Location: "));
  14900. print_vma (pc, FULL_HEX);
  14901. printf (_(", Base: "));
  14902. print_vma (base_addr, FULL_HEX);
  14903. printf (_(", Semaphore: "));
  14904. print_vma (semaphore, FULL_HEX);
  14905. printf ("\n");
  14906. printf (_(" Arguments: %s\n"), arg_fmt);
  14907. return data == data_end;
  14908. }
  14909. static const char *
  14910. get_ia64_vms_note_type (unsigned e_type)
  14911. {
  14912. static char buff[64];
  14913. switch (e_type)
  14914. {
  14915. case NT_VMS_MHD:
  14916. return _("NT_VMS_MHD (module header)");
  14917. case NT_VMS_LNM:
  14918. return _("NT_VMS_LNM (language name)");
  14919. case NT_VMS_SRC:
  14920. return _("NT_VMS_SRC (source files)");
  14921. case NT_VMS_TITLE:
  14922. return "NT_VMS_TITLE";
  14923. case NT_VMS_EIDC:
  14924. return _("NT_VMS_EIDC (consistency check)");
  14925. case NT_VMS_FPMODE:
  14926. return _("NT_VMS_FPMODE (FP mode)");
  14927. case NT_VMS_LINKTIME:
  14928. return "NT_VMS_LINKTIME";
  14929. case NT_VMS_IMGNAM:
  14930. return _("NT_VMS_IMGNAM (image name)");
  14931. case NT_VMS_IMGID:
  14932. return _("NT_VMS_IMGID (image id)");
  14933. case NT_VMS_LINKID:
  14934. return _("NT_VMS_LINKID (link id)");
  14935. case NT_VMS_IMGBID:
  14936. return _("NT_VMS_IMGBID (build id)");
  14937. case NT_VMS_GSTNAM:
  14938. return _("NT_VMS_GSTNAM (sym table name)");
  14939. case NT_VMS_ORIG_DYN:
  14940. return "NT_VMS_ORIG_DYN";
  14941. case NT_VMS_PATCHTIME:
  14942. return "NT_VMS_PATCHTIME";
  14943. default:
  14944. snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
  14945. return buff;
  14946. }
  14947. }
  14948. static bfd_boolean
  14949. print_ia64_vms_note (Elf_Internal_Note * pnote)
  14950. {
  14951. switch (pnote->type)
  14952. {
  14953. case NT_VMS_MHD:
  14954. if (pnote->descsz > 36)
  14955. {
  14956. size_t l = strlen (pnote->descdata + 34);
  14957. printf (_(" Creation date : %.17s\n"), pnote->descdata);
  14958. printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17);
  14959. printf (_(" Module name : %s\n"), pnote->descdata + 34);
  14960. printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1);
  14961. }
  14962. else
  14963. printf (_(" Invalid size\n"));
  14964. break;
  14965. case NT_VMS_LNM:
  14966. printf (_(" Language: %s\n"), pnote->descdata);
  14967. break;
  14968. #ifdef BFD64
  14969. case NT_VMS_FPMODE:
  14970. printf (_(" Floating Point mode: "));
  14971. printf ("0x%016" BFD_VMA_FMT "x\n",
  14972. (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8));
  14973. break;
  14974. case NT_VMS_LINKTIME:
  14975. printf (_(" Link time: "));
  14976. print_vms_time
  14977. ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
  14978. printf ("\n");
  14979. break;
  14980. case NT_VMS_PATCHTIME:
  14981. printf (_(" Patch time: "));
  14982. print_vms_time
  14983. ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
  14984. printf ("\n");
  14985. break;
  14986. case NT_VMS_ORIG_DYN:
  14987. printf (_(" Major id: %u, minor id: %u\n"),
  14988. (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
  14989. (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
  14990. printf (_(" Last modified : "));
  14991. print_vms_time
  14992. ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
  14993. printf (_("\n Link flags : "));
  14994. printf ("0x%016" BFD_VMA_FMT "x\n",
  14995. (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8));
  14996. printf (_(" Header flags: 0x%08x\n"),
  14997. (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4));
  14998. printf (_(" Image id : %s\n"), pnote->descdata + 32);
  14999. break;
  15000. #endif
  15001. case NT_VMS_IMGNAM:
  15002. printf (_(" Image name: %s\n"), pnote->descdata);
  15003. break;
  15004. case NT_VMS_GSTNAM:
  15005. printf (_(" Global symbol table name: %s\n"), pnote->descdata);
  15006. break;
  15007. case NT_VMS_IMGID:
  15008. printf (_(" Image id: %s\n"), pnote->descdata);
  15009. break;
  15010. case NT_VMS_LINKID:
  15011. printf (_(" Linker id: %s\n"), pnote->descdata);
  15012. break;
  15013. default:
  15014. return FALSE;
  15015. }
  15016. return TRUE;
  15017. }
  15018. /* Print the name of the symbol associated with a build attribute
  15019. that is attached to address OFFSET. */
  15020. static bfd_boolean
  15021. print_symbol_for_build_attribute (FILE * file,
  15022. unsigned long offset,
  15023. bfd_boolean is_open_attr)
  15024. {
  15025. static FILE * saved_file = NULL;
  15026. static char * strtab;
  15027. static unsigned long strtablen;
  15028. static Elf_Internal_Sym * symtab;
  15029. static unsigned long nsyms;
  15030. Elf_Internal_Sym * saved_sym = NULL;
  15031. Elf_Internal_Sym * sym;
  15032. if (section_headers != NULL
  15033. && (saved_file == NULL || file != saved_file))
  15034. {
  15035. Elf_Internal_Shdr * symsec;
  15036. /* Load the symbol and string sections. */
  15037. for (symsec = section_headers;
  15038. symsec < section_headers + elf_header.e_shnum;
  15039. symsec ++)
  15040. {
  15041. if (symsec->sh_type == SHT_SYMTAB)
  15042. {
  15043. symtab = GET_ELF_SYMBOLS (file, symsec, & nsyms);
  15044. if (symsec->sh_link < elf_header.e_shnum)
  15045. {
  15046. Elf_Internal_Shdr * strtab_sec = section_headers + symsec->sh_link;
  15047. strtab = (char *) get_data (NULL, file, strtab_sec->sh_offset,
  15048. 1, strtab_sec->sh_size,
  15049. _("string table"));
  15050. strtablen = strtab != NULL ? strtab_sec->sh_size : 0;
  15051. }
  15052. }
  15053. }
  15054. saved_file = file;
  15055. }
  15056. if (symtab == NULL || strtab == NULL)
  15057. {
  15058. printf ("\n");
  15059. return FALSE;
  15060. }
  15061. /* Find a symbol whose value matches offset. */
  15062. for (sym = symtab; sym < symtab + nsyms; sym ++)
  15063. if (sym->st_value == offset)
  15064. {
  15065. if (sym->st_name >= strtablen)
  15066. /* Huh ? This should not happen. */
  15067. continue;
  15068. if (strtab[sym->st_name] == 0)
  15069. continue;
  15070. if (is_open_attr)
  15071. {
  15072. /* For OPEN attributes we prefer GLOBAL over LOCAL symbols
  15073. and FILE or OBJECT symbols over NOTYPE symbols. We skip
  15074. FUNC symbols entirely. */
  15075. switch (ELF_ST_TYPE (sym->st_info))
  15076. {
  15077. case STT_FILE:
  15078. saved_sym = sym;
  15079. /* We can stop searching now. */
  15080. sym = symtab + nsyms;
  15081. continue;
  15082. case STT_OBJECT:
  15083. saved_sym = sym;
  15084. continue;
  15085. case STT_FUNC:
  15086. /* Ignore function symbols. */
  15087. continue;
  15088. default:
  15089. break;
  15090. }
  15091. switch (ELF_ST_BIND (sym->st_info))
  15092. {
  15093. case STB_GLOBAL:
  15094. if (saved_sym == NULL
  15095. || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT)
  15096. saved_sym = sym;
  15097. break;
  15098. case STB_LOCAL:
  15099. if (saved_sym == NULL)
  15100. saved_sym = sym;
  15101. break;
  15102. default:
  15103. break;
  15104. }
  15105. }
  15106. else
  15107. {
  15108. if (ELF_ST_TYPE (sym->st_info) != STT_FUNC)
  15109. continue;
  15110. saved_sym = sym;
  15111. break;
  15112. }
  15113. }
  15114. printf (" (%s: %s)\n",
  15115. is_open_attr ? _("file") : _("func"),
  15116. saved_sym ? strtab + saved_sym->st_name : _("<no symbol found>)"));
  15117. return TRUE;
  15118. }
  15119. static bfd_boolean
  15120. print_gnu_build_attribute_description (Elf_Internal_Note * pnote,
  15121. FILE * file)
  15122. {
  15123. static unsigned long global_offset = 0;
  15124. unsigned long offset;
  15125. unsigned int desc_size = is_32bit_elf ? 4 : 8;
  15126. bfd_boolean is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN;
  15127. if (pnote->descsz == 0)
  15128. {
  15129. if (is_open_attr)
  15130. {
  15131. printf (_(" Applies from offset %#lx\n"), global_offset);
  15132. return TRUE;
  15133. }
  15134. else
  15135. {
  15136. printf (_(" Applies to func at %#lx"), global_offset);
  15137. return print_symbol_for_build_attribute (file, global_offset, is_open_attr);
  15138. }
  15139. }
  15140. if (pnote->descsz != desc_size)
  15141. {
  15142. error (_(" <invalid description size: %lx>\n"), pnote->descsz);
  15143. printf (_(" <invalid descsz>"));
  15144. return FALSE;
  15145. }
  15146. offset = byte_get ((unsigned char *) pnote->descdata, desc_size);
  15147. if (is_open_attr)
  15148. {
  15149. printf (_(" Applies from offset %#lx"), offset);
  15150. global_offset = offset;
  15151. }
  15152. else
  15153. {
  15154. printf (_(" Applies to func at %#lx"), offset);
  15155. }
  15156. return print_symbol_for_build_attribute (file, offset, is_open_attr);
  15157. }
  15158. static bfd_boolean
  15159. print_gnu_build_attribute_name (Elf_Internal_Note * pnote)
  15160. {
  15161. static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 };
  15162. static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 };
  15163. static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 };
  15164. char name_type;
  15165. char name_attribute;
  15166. const char * expected_types;
  15167. const char * name = pnote->namedata;
  15168. const char * text;
  15169. signed int left;
  15170. if (name == NULL || pnote->namesz < 2)
  15171. {
  15172. error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz);
  15173. print_symbol (-20, _(" <corrupt name>"));
  15174. return FALSE;
  15175. }
  15176. left = 20;
  15177. /* Version 2 of the spec adds a "GA" prefix to the name field. */
  15178. if (name[0] == 'G' && name[1] == 'A')
  15179. {
  15180. printf ("GA");
  15181. name += 2;
  15182. left -= 2;
  15183. }
  15184. switch ((name_type = * name))
  15185. {
  15186. case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
  15187. case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
  15188. case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
  15189. case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
  15190. printf ("%c", * name);
  15191. left --;
  15192. break;
  15193. default:
  15194. error (_("unrecognised attribute type in name field: %d\n"), name_type);
  15195. print_symbol (-20, _("<unknown name type>"));
  15196. return FALSE;
  15197. }
  15198. ++ name;
  15199. text = NULL;
  15200. switch ((name_attribute = * name))
  15201. {
  15202. case GNU_BUILD_ATTRIBUTE_VERSION:
  15203. text = _("<version>");
  15204. expected_types = string_expected;
  15205. ++ name;
  15206. break;
  15207. case GNU_BUILD_ATTRIBUTE_STACK_PROT:
  15208. text = _("<stack prot>");
  15209. expected_types = "!+*";
  15210. ++ name;
  15211. break;
  15212. case GNU_BUILD_ATTRIBUTE_RELRO:
  15213. text = _("<relro>");
  15214. expected_types = bool_expected;
  15215. ++ name;
  15216. break;
  15217. case GNU_BUILD_ATTRIBUTE_STACK_SIZE:
  15218. text = _("<stack size>");
  15219. expected_types = number_expected;
  15220. ++ name;
  15221. break;
  15222. case GNU_BUILD_ATTRIBUTE_TOOL:
  15223. text = _("<tool>");
  15224. expected_types = string_expected;
  15225. ++ name;
  15226. break;
  15227. case GNU_BUILD_ATTRIBUTE_ABI:
  15228. text = _("<ABI>");
  15229. expected_types = "$*";
  15230. ++ name;
  15231. break;
  15232. case GNU_BUILD_ATTRIBUTE_PIC:
  15233. text = _("<PIC>");
  15234. expected_types = number_expected;
  15235. ++ name;
  15236. break;
  15237. case GNU_BUILD_ATTRIBUTE_SHORT_ENUM:
  15238. text = _("<short enum>");
  15239. expected_types = bool_expected;
  15240. ++ name;
  15241. break;
  15242. default:
  15243. if (ISPRINT (* name))
  15244. {
  15245. int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1;
  15246. if (len > left && ! do_wide)
  15247. len = left;
  15248. printf ("%.*s:", len, name);
  15249. left -= len;
  15250. name += len;
  15251. }
  15252. else
  15253. {
  15254. static char tmpbuf [128];
  15255. error (_("unrecognised byte in name field: %d\n"), * name);
  15256. sprintf (tmpbuf, _("<unknown:_%d>"), * name);
  15257. text = tmpbuf;
  15258. name ++;
  15259. }
  15260. expected_types = "*$!+";
  15261. break;
  15262. }
  15263. if (text)
  15264. left -= printf ("%s", text);
  15265. if (strchr (expected_types, name_type) == NULL)
  15266. warn (_("attribute does not have an expected type (%c)\n"), name_type);
  15267. if ((unsigned long)(name - pnote->namedata) > pnote->namesz)
  15268. {
  15269. error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"),
  15270. (unsigned long) pnote->namesz,
  15271. (long) (name - pnote->namedata));
  15272. return FALSE;
  15273. }
  15274. if (left < 1 && ! do_wide)
  15275. return TRUE;
  15276. switch (name_type)
  15277. {
  15278. case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC:
  15279. {
  15280. unsigned int bytes;
  15281. unsigned long long val = 0;
  15282. unsigned int shift = 0;
  15283. char * decoded = NULL;
  15284. bytes = pnote->namesz - (name - pnote->namedata);
  15285. if (bytes > 0)
  15286. /* The -1 is because the name field is always 0 terminated, and we
  15287. want to be able to ensure that the shift in the while loop below
  15288. will not overflow. */
  15289. -- bytes;
  15290. if (bytes > sizeof (val))
  15291. {
  15292. fprintf (stderr, "namesz %lx name %p namedata %p\n",
  15293. pnote->namesz, name, pnote->namedata);
  15294. error (_("corrupt numeric name field: too many bytes in the value: %x\n"),
  15295. bytes);
  15296. bytes = sizeof (val);
  15297. }
  15298. /* We do not bother to warn if bytes == 0 as this can
  15299. happen with some early versions of the gcc plugin. */
  15300. while (bytes --)
  15301. {
  15302. unsigned long byte = (* name ++) & 0xff;
  15303. val |= byte << shift;
  15304. shift += 8;
  15305. }
  15306. switch (name_attribute)
  15307. {
  15308. case GNU_BUILD_ATTRIBUTE_PIC:
  15309. switch (val)
  15310. {
  15311. case 0: decoded = "static"; break;
  15312. case 1: decoded = "pic"; break;
  15313. case 2: decoded = "PIC"; break;
  15314. case 3: decoded = "pie"; break;
  15315. case 4: decoded = "PIE"; break;
  15316. default: break;
  15317. }
  15318. break;
  15319. case GNU_BUILD_ATTRIBUTE_STACK_PROT:
  15320. switch (val)
  15321. {
  15322. /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */
  15323. case 0: decoded = "off"; break;
  15324. case 1: decoded = "on"; break;
  15325. case 2: decoded = "all"; break;
  15326. case 3: decoded = "strong"; break;
  15327. case 4: decoded = "explicit"; break;
  15328. default: break;
  15329. }
  15330. break;
  15331. default:
  15332. break;
  15333. }
  15334. if (decoded != NULL)
  15335. {
  15336. print_symbol (-left, decoded);
  15337. left = 0;
  15338. }
  15339. else if (val == 0)
  15340. {
  15341. printf ("0x0");
  15342. left -= 3;
  15343. }
  15344. else
  15345. {
  15346. if (do_wide)
  15347. left -= printf ("0x%llx", val);
  15348. else
  15349. left -= printf ("0x%-.*llx", left, val);
  15350. }
  15351. }
  15352. break;
  15353. case GNU_BUILD_ATTRIBUTE_TYPE_STRING:
  15354. left -= print_symbol (- left, name);
  15355. break;
  15356. case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE:
  15357. left -= print_symbol (- left, "true");
  15358. break;
  15359. case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE:
  15360. left -= print_symbol (- left, "false");
  15361. break;
  15362. }
  15363. if (do_wide && left > 0)
  15364. printf ("%-*s", left, " ");
  15365. return TRUE;
  15366. }
  15367. /* Note that by the ELF standard, the name field is already null byte
  15368. terminated, and namesz includes the terminating null byte.
  15369. I.E. the value of namesz for the name "FSF" is 4.
  15370. If the value of namesz is zero, there is no name present. */
  15371. static bfd_boolean
  15372. process_note (Elf_Internal_Note * pnote,
  15373. FILE * file)
  15374. {
  15375. const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
  15376. const char * nt;
  15377. if (pnote->namesz == 0)
  15378. /* If there is no note name, then use the default set of
  15379. note type strings. */
  15380. nt = get_note_type (pnote->type);
  15381. else if (const_strneq (pnote->namedata, "GNU"))
  15382. /* GNU-specific object file notes. */
  15383. nt = get_gnu_elf_note_type (pnote->type);
  15384. else if (const_strneq (pnote->namedata, "FreeBSD"))
  15385. /* FreeBSD-specific core file notes. */
  15386. nt = get_freebsd_elfcore_note_type (pnote->type);
  15387. else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
  15388. /* NetBSD-specific core file notes. */
  15389. nt = get_netbsd_elfcore_note_type (pnote->type);
  15390. else if (const_strneq (pnote->namedata, "NetBSD"))
  15391. /* NetBSD-specific core file notes. */
  15392. return process_netbsd_elf_note (pnote);
  15393. else if (strneq (pnote->namedata, "SPU/", 4))
  15394. {
  15395. /* SPU-specific core file notes. */
  15396. nt = pnote->namedata + 4;
  15397. name = "SPU";
  15398. }
  15399. else if (const_strneq (pnote->namedata, "IPF/VMS"))
  15400. /* VMS/ia64-specific file notes. */
  15401. nt = get_ia64_vms_note_type (pnote->type);
  15402. else if (const_strneq (pnote->namedata, "stapsdt"))
  15403. nt = get_stapsdt_note_type (pnote->type);
  15404. else
  15405. /* Don't recognize this note name; just use the default set of
  15406. note type strings. */
  15407. nt = get_note_type (pnote->type);
  15408. printf (" ");
  15409. if (((const_strneq (pnote->namedata, "GA")
  15410. && strchr ("*$!+", pnote->namedata[2]) != NULL)
  15411. || strchr ("*$!+", pnote->namedata[0]) != NULL)
  15412. && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
  15413. || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
  15414. print_gnu_build_attribute_name (pnote);
  15415. else
  15416. print_symbol (-20, name);
  15417. if (do_wide)
  15418. printf (" 0x%08lx\t%s\t", pnote->descsz, nt);
  15419. else
  15420. printf (" 0x%08lx\t%s\n", pnote->descsz, nt);
  15421. if (const_strneq (pnote->namedata, "IPF/VMS"))
  15422. return print_ia64_vms_note (pnote);
  15423. else if (const_strneq (pnote->namedata, "GNU"))
  15424. return print_gnu_note (pnote);
  15425. else if (const_strneq (pnote->namedata, "stapsdt"))
  15426. return print_stapsdt_note (pnote);
  15427. else if (const_strneq (pnote->namedata, "CORE"))
  15428. return print_core_note (pnote);
  15429. else if (((const_strneq (pnote->namedata, "GA")
  15430. && strchr ("*$!+", pnote->namedata[2]) != NULL)
  15431. || strchr ("*$!+", pnote->namedata[0]) != NULL)
  15432. && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN
  15433. || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC))
  15434. return print_gnu_build_attribute_description (pnote, file);
  15435. if (pnote->descsz)
  15436. {
  15437. unsigned long i;
  15438. printf (_(" description data: "));
  15439. for (i = 0; i < pnote->descsz; i++)
  15440. printf ("%02x ", pnote->descdata[i]);
  15441. }
  15442. if (do_wide)
  15443. printf ("\n");
  15444. return TRUE;
  15445. }
  15446. static bfd_boolean
  15447. process_notes_at (FILE * file,
  15448. Elf_Internal_Shdr * section,
  15449. bfd_vma offset,
  15450. bfd_vma length)
  15451. {
  15452. Elf_External_Note * pnotes;
  15453. Elf_External_Note * external;
  15454. char * end;
  15455. bfd_boolean res = TRUE;
  15456. if (length <= 0)
  15457. return FALSE;
  15458. if (section)
  15459. {
  15460. pnotes = (Elf_External_Note *) get_section_contents (section, file);
  15461. if (pnotes)
  15462. {
  15463. if (! apply_relocations (file, section, (unsigned char *) pnotes, length, NULL, NULL))
  15464. return FALSE;
  15465. }
  15466. }
  15467. else
  15468. pnotes = (Elf_External_Note *) get_data (NULL, file, offset, 1, length,
  15469. _("notes"));
  15470. if (pnotes == NULL)
  15471. return FALSE;
  15472. external = pnotes;
  15473. if (section)
  15474. printf (_("\nDisplaying notes found in: %s\n"), printable_section_name (section));
  15475. else
  15476. printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
  15477. (unsigned long) offset, (unsigned long) length);
  15478. printf (_(" %-20s %10s\tDescription\n"), _("Owner"), _("Data size"));
  15479. end = (char *) pnotes + length;
  15480. while ((char *) external < end)
  15481. {
  15482. Elf_Internal_Note inote;
  15483. size_t min_notesz;
  15484. char *next;
  15485. char * temp = NULL;
  15486. size_t data_remaining = end - (char *) external;
  15487. if (!is_ia64_vms ())
  15488. {
  15489. /* PR binutils/15191
  15490. Make sure that there is enough data to read. */
  15491. min_notesz = offsetof (Elf_External_Note, name);
  15492. if (data_remaining < min_notesz)
  15493. {
  15494. warn (_("Corrupt note: only %d bytes remain, not enough for a full note\n"),
  15495. (int) data_remaining);
  15496. break;
  15497. }
  15498. inote.type = BYTE_GET (external->type);
  15499. inote.namesz = BYTE_GET (external->namesz);
  15500. inote.namedata = external->name;
  15501. inote.descsz = BYTE_GET (external->descsz);
  15502. inote.descdata = inote.namedata + align_power (inote.namesz, 2);
  15503. /* PR 17531: file: 3443835e. */
  15504. if (inote.descdata < (char *) pnotes || inote.descdata > end)
  15505. {
  15506. warn (_("Corrupt note: name size is too big: (got: %lx, expected no more than: %lx)\n"),
  15507. inote.namesz, (long)(end - inote.namedata));
  15508. inote.descdata = inote.namedata;
  15509. inote.namesz = 0;
  15510. }
  15511. inote.descpos = offset + (inote.descdata - (char *) pnotes);
  15512. next = inote.descdata + align_power (inote.descsz, 2);
  15513. }
  15514. else
  15515. {
  15516. Elf64_External_VMS_Note *vms_external;
  15517. /* PR binutils/15191
  15518. Make sure that there is enough data to read. */
  15519. min_notesz = offsetof (Elf64_External_VMS_Note, name);
  15520. if (data_remaining < min_notesz)
  15521. {
  15522. warn (_("Corrupt note: only %d bytes remain, not enough for a full note\n"),
  15523. (int) data_remaining);
  15524. break;
  15525. }
  15526. vms_external = (Elf64_External_VMS_Note *) external;
  15527. inote.type = BYTE_GET (vms_external->type);
  15528. inote.namesz = BYTE_GET (vms_external->namesz);
  15529. inote.namedata = vms_external->name;
  15530. inote.descsz = BYTE_GET (vms_external->descsz);
  15531. inote.descdata = inote.namedata + align_power (inote.namesz, 3);
  15532. inote.descpos = offset + (inote.descdata - (char *) pnotes);
  15533. next = inote.descdata + align_power (inote.descsz, 3);
  15534. }
  15535. if (inote.descdata < (char *) external + min_notesz
  15536. || next < (char *) external + min_notesz
  15537. /* PR binutils/17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */
  15538. || inote.namedata + inote.namesz < inote.namedata
  15539. || inote.descdata + inote.descsz < inote.descdata
  15540. || data_remaining < (size_t)(next - (char *) external))
  15541. {
  15542. warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
  15543. (unsigned long) ((char *) external - (char *) pnotes));
  15544. warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx\n"),
  15545. inote.type, inote.namesz, inote.descsz);
  15546. break;
  15547. }
  15548. external = (Elf_External_Note *) next;
  15549. /* Verify that name is null terminated. It appears that at least
  15550. one version of Linux (RedHat 6.0) generates corefiles that don't
  15551. comply with the ELF spec by failing to include the null byte in
  15552. namesz. */
  15553. if (inote.namedata[inote.namesz - 1] != '\0')
  15554. {
  15555. temp = (char *) malloc (inote.namesz + 1);
  15556. if (temp == NULL)
  15557. {
  15558. error (_("Out of memory allocating space for inote name\n"));
  15559. res = FALSE;
  15560. break;
  15561. }
  15562. memcpy (temp, inote.namedata, inote.namesz);
  15563. temp[inote.namesz] = 0;
  15564. /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
  15565. inote.namedata = temp;
  15566. }
  15567. if (! process_note (& inote, file))
  15568. res = FALSE;
  15569. if (temp != NULL)
  15570. {
  15571. free (temp);
  15572. temp = NULL;
  15573. }
  15574. }
  15575. free (pnotes);
  15576. return res;
  15577. }
  15578. static bfd_boolean
  15579. process_corefile_note_segments (FILE * file)
  15580. {
  15581. Elf_Internal_Phdr * segment;
  15582. unsigned int i;
  15583. bfd_boolean res = TRUE;
  15584. if (! get_program_headers (file))
  15585. return TRUE;
  15586. for (i = 0, segment = program_headers;
  15587. i < elf_header.e_phnum;
  15588. i++, segment++)
  15589. {
  15590. if (segment->p_type == PT_NOTE)
  15591. if (! process_notes_at (file, NULL,
  15592. (bfd_vma) segment->p_offset,
  15593. (bfd_vma) segment->p_filesz))
  15594. res = FALSE;
  15595. }
  15596. return res;
  15597. }
  15598. static bfd_boolean
  15599. process_v850_notes (FILE * file, bfd_vma offset, bfd_vma length)
  15600. {
  15601. Elf_External_Note * pnotes;
  15602. Elf_External_Note * external;
  15603. char * end;
  15604. bfd_boolean res = TRUE;
  15605. if (length <= 0)
  15606. return FALSE;
  15607. pnotes = (Elf_External_Note *) get_data (NULL, file, offset, 1, length,
  15608. _("v850 notes"));
  15609. if (pnotes == NULL)
  15610. return FALSE;
  15611. external = pnotes;
  15612. end = (char*) pnotes + length;
  15613. printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"),
  15614. (unsigned long) offset, (unsigned long) length);
  15615. while ((char *) external + sizeof (Elf_External_Note) < end)
  15616. {
  15617. Elf_External_Note * next;
  15618. Elf_Internal_Note inote;
  15619. inote.type = BYTE_GET (external->type);
  15620. inote.namesz = BYTE_GET (external->namesz);
  15621. inote.namedata = external->name;
  15622. inote.descsz = BYTE_GET (external->descsz);
  15623. inote.descdata = inote.namedata + align_power (inote.namesz, 2);
  15624. inote.descpos = offset + (inote.descdata - (char *) pnotes);
  15625. if (inote.descdata < (char *) pnotes || inote.descdata >= end)
  15626. {
  15627. warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz);
  15628. inote.descdata = inote.namedata;
  15629. inote.namesz = 0;
  15630. }
  15631. next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2));
  15632. if ( ((char *) next > end)
  15633. || ((char *) next < (char *) pnotes))
  15634. {
  15635. warn (_("corrupt descsz found in note at offset 0x%lx\n"),
  15636. (unsigned long) ((char *) external - (char *) pnotes));
  15637. warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
  15638. inote.type, inote.namesz, inote.descsz);
  15639. break;
  15640. }
  15641. external = next;
  15642. /* Prevent out-of-bounds indexing. */
  15643. if ( inote.namedata + inote.namesz > end
  15644. || inote.namedata + inote.namesz < inote.namedata)
  15645. {
  15646. warn (_("corrupt namesz found in note at offset 0x%lx\n"),
  15647. (unsigned long) ((char *) external - (char *) pnotes));
  15648. warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"),
  15649. inote.type, inote.namesz, inote.descsz);
  15650. break;
  15651. }
  15652. printf (" %s: ", get_v850_elf_note_type (inote.type));
  15653. if (! print_v850_note (& inote))
  15654. {
  15655. res = FALSE;
  15656. printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n",
  15657. inote.namesz, inote.descsz);
  15658. }
  15659. }
  15660. free (pnotes);
  15661. return res;
  15662. }
  15663. static bfd_boolean
  15664. process_note_sections (FILE * file)
  15665. {
  15666. Elf_Internal_Shdr * section;
  15667. unsigned long i;
  15668. unsigned int n = 0;
  15669. bfd_boolean res = TRUE;
  15670. for (i = 0, section = section_headers;
  15671. i < elf_header.e_shnum && section != NULL;
  15672. i++, section++)
  15673. {
  15674. if (section->sh_type == SHT_NOTE)
  15675. {
  15676. if (! process_notes_at (file, section,
  15677. (bfd_vma) section->sh_offset,
  15678. (bfd_vma) section->sh_size))
  15679. res = FALSE;
  15680. n++;
  15681. }
  15682. if (( elf_header.e_machine == EM_V800
  15683. || elf_header.e_machine == EM_V850
  15684. || elf_header.e_machine == EM_CYGNUS_V850)
  15685. && section->sh_type == SHT_RENESAS_INFO)
  15686. {
  15687. if (! process_v850_notes (file,
  15688. (bfd_vma) section->sh_offset,
  15689. (bfd_vma) section->sh_size))
  15690. res = FALSE;
  15691. n++;
  15692. }
  15693. }
  15694. if (n == 0)
  15695. /* Try processing NOTE segments instead. */
  15696. return process_corefile_note_segments (file);
  15697. return res;
  15698. }
  15699. static bfd_boolean
  15700. process_notes (FILE * file)
  15701. {
  15702. /* If we have not been asked to display the notes then do nothing. */
  15703. if (! do_notes)
  15704. return TRUE;
  15705. if (elf_header.e_type != ET_CORE)
  15706. return process_note_sections (file);
  15707. /* No program headers means no NOTE segment. */
  15708. if (elf_header.e_phnum > 0)
  15709. return process_corefile_note_segments (file);
  15710. printf (_("No note segments present in the core file.\n"));
  15711. return TRUE;
  15712. }
  15713. static unsigned char *
  15714. display_public_gnu_attributes (unsigned char * start,
  15715. const unsigned char * const end)
  15716. {
  15717. printf (_(" Unknown GNU attribute: %s\n"), start);
  15718. start += strnlen ((char *) start, end - start);
  15719. display_raw_attribute (start, end);
  15720. return (unsigned char *) end;
  15721. }
  15722. static unsigned char *
  15723. display_generic_attribute (unsigned char * start,
  15724. unsigned int tag,
  15725. const unsigned char * const end)
  15726. {
  15727. if (tag == 0)
  15728. return (unsigned char *) end;
  15729. return display_tag_value (tag, start, end);
  15730. }
  15731. static bfd_boolean
  15732. process_arch_specific (FILE * file)
  15733. {
  15734. if (! do_arch)
  15735. return TRUE;
  15736. switch (elf_header.e_machine)
  15737. {
  15738. case EM_ARC:
  15739. case EM_ARC_COMPACT:
  15740. case EM_ARC_COMPACT2:
  15741. return process_attributes (file, "ARC", SHT_ARC_ATTRIBUTES,
  15742. display_arc_attribute,
  15743. display_generic_attribute);
  15744. case EM_ARM:
  15745. return process_attributes (file, "aeabi", SHT_ARM_ATTRIBUTES,
  15746. display_arm_attribute,
  15747. display_generic_attribute);
  15748. case EM_MIPS:
  15749. case EM_MIPS_RS3_LE:
  15750. return process_mips_specific (file);
  15751. case EM_MSP430:
  15752. return process_attributes (file, "mspabi", SHT_MSP430_ATTRIBUTES,
  15753. display_msp430x_attribute,
  15754. display_generic_attribute);
  15755. case EM_NDS32:
  15756. return process_nds32_specific (file);
  15757. case EM_PPC:
  15758. case EM_PPC64:
  15759. return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
  15760. display_power_gnu_attribute);
  15761. case EM_S390:
  15762. case EM_S390_OLD:
  15763. return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
  15764. display_s390_gnu_attribute);
  15765. case EM_SPARC:
  15766. case EM_SPARC32PLUS:
  15767. case EM_SPARCV9:
  15768. return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
  15769. display_sparc_gnu_attribute);
  15770. case EM_TI_C6000:
  15771. return process_attributes (file, "c6xabi", SHT_C6000_ATTRIBUTES,
  15772. display_tic6x_attribute,
  15773. display_generic_attribute);
  15774. default:
  15775. return process_attributes (file, "gnu", SHT_GNU_ATTRIBUTES,
  15776. display_public_gnu_attributes,
  15777. display_generic_attribute);
  15778. }
  15779. }
  15780. static bfd_boolean
  15781. get_file_header (FILE * file)
  15782. {
  15783. /* Read in the identity array. */
  15784. if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
  15785. return FALSE;
  15786. /* Determine how to read the rest of the header. */
  15787. switch (elf_header.e_ident[EI_DATA])
  15788. {
  15789. default:
  15790. case ELFDATANONE:
  15791. case ELFDATA2LSB:
  15792. byte_get = byte_get_little_endian;
  15793. byte_put = byte_put_little_endian;
  15794. break;
  15795. case ELFDATA2MSB:
  15796. byte_get = byte_get_big_endian;
  15797. byte_put = byte_put_big_endian;
  15798. break;
  15799. }
  15800. /* For now we only support 32 bit and 64 bit ELF files. */
  15801. is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
  15802. /* Read in the rest of the header. */
  15803. if (is_32bit_elf)
  15804. {
  15805. Elf32_External_Ehdr ehdr32;
  15806. if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
  15807. return FALSE;
  15808. elf_header.e_type = BYTE_GET (ehdr32.e_type);
  15809. elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
  15810. elf_header.e_version = BYTE_GET (ehdr32.e_version);
  15811. elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
  15812. elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
  15813. elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
  15814. elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
  15815. elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
  15816. elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
  15817. elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
  15818. elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
  15819. elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
  15820. elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
  15821. }
  15822. else
  15823. {
  15824. Elf64_External_Ehdr ehdr64;
  15825. /* If we have been compiled with sizeof (bfd_vma) == 4, then
  15826. we will not be able to cope with the 64bit data found in
  15827. 64 ELF files. Detect this now and abort before we start
  15828. overwriting things. */
  15829. if (sizeof (bfd_vma) < 8)
  15830. {
  15831. error (_("This instance of readelf has been built without support for a\n\
  15832. 64 bit data type and so it cannot read 64 bit ELF files.\n"));
  15833. return FALSE;
  15834. }
  15835. if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
  15836. return FALSE;
  15837. elf_header.e_type = BYTE_GET (ehdr64.e_type);
  15838. elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
  15839. elf_header.e_version = BYTE_GET (ehdr64.e_version);
  15840. elf_header.e_entry = BYTE_GET (ehdr64.e_entry);
  15841. elf_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
  15842. elf_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
  15843. elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
  15844. elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
  15845. elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
  15846. elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
  15847. elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
  15848. elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
  15849. elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
  15850. }
  15851. if (elf_header.e_shoff)
  15852. {
  15853. /* There may be some extensions in the first section header. Don't
  15854. bomb if we can't read it. */
  15855. if (is_32bit_elf)
  15856. get_32bit_section_headers (file, TRUE);
  15857. else
  15858. get_64bit_section_headers (file, TRUE);
  15859. }
  15860. return TRUE;
  15861. }
  15862. /* Process one ELF object file according to the command line options.
  15863. This file may actually be stored in an archive. The file is
  15864. positioned at the start of the ELF object. Returns TRUE if no
  15865. problems were encountered, FALSE otherwise. */
  15866. static bfd_boolean
  15867. process_object (char * file_name, FILE * file)
  15868. {
  15869. unsigned int i;
  15870. bfd_boolean res = TRUE;
  15871. if (! get_file_header (file))
  15872. {
  15873. error (_("%s: Failed to read file header\n"), file_name);
  15874. return FALSE;
  15875. }
  15876. /* Initialise per file variables. */
  15877. for (i = ARRAY_SIZE (version_info); i--;)
  15878. version_info[i] = 0;
  15879. for (i = ARRAY_SIZE (dynamic_info); i--;)
  15880. dynamic_info[i] = 0;
  15881. dynamic_info_DT_GNU_HASH = 0;
  15882. /* Process the file. */
  15883. if (show_name)
  15884. printf (_("\nFile: %s\n"), file_name);
  15885. /* Initialise the dump_sects array from the cmdline_dump_sects array.
  15886. Note we do this even if cmdline_dump_sects is empty because we
  15887. must make sure that the dump_sets array is zeroed out before each
  15888. object file is processed. */
  15889. if (num_dump_sects > num_cmdline_dump_sects)
  15890. memset (dump_sects, 0, num_dump_sects * sizeof (* dump_sects));
  15891. if (num_cmdline_dump_sects > 0)
  15892. {
  15893. if (num_dump_sects == 0)
  15894. /* A sneaky way of allocating the dump_sects array. */
  15895. request_dump_bynumber (num_cmdline_dump_sects, 0);
  15896. assert (num_dump_sects >= num_cmdline_dump_sects);
  15897. memcpy (dump_sects, cmdline_dump_sects,
  15898. num_cmdline_dump_sects * sizeof (* dump_sects));
  15899. }
  15900. if (! process_file_header ())
  15901. return FALSE;
  15902. if (! process_section_headers (file))
  15903. {
  15904. /* Without loaded section headers we cannot process lots of things. */
  15905. do_unwind = do_version = do_dump = do_arch = FALSE;
  15906. if (! do_using_dynamic)
  15907. do_syms = do_dyn_syms = do_reloc = FALSE;
  15908. }
  15909. if (! process_section_groups (file))
  15910. /* Without loaded section groups we cannot process unwind. */
  15911. do_unwind = FALSE;
  15912. if (process_program_headers (file))
  15913. process_dynamic_section (file);
  15914. else
  15915. res = FALSE;
  15916. if (! process_relocs (file))
  15917. res = FALSE;
  15918. if (! process_unwind (file))
  15919. res = FALSE;
  15920. if (! process_symbol_table (file))
  15921. res = FALSE;
  15922. if (! process_syminfo (file))
  15923. res = FALSE;
  15924. if (! process_version_sections (file))
  15925. res = FALSE;
  15926. if (! process_section_contents (file))
  15927. res = FALSE;
  15928. if (! process_notes (file))
  15929. res = FALSE;
  15930. if (! process_gnu_liblist (file))
  15931. res = FALSE;
  15932. if (! process_arch_specific (file))
  15933. res = FALSE;
  15934. if (program_headers)
  15935. {
  15936. free (program_headers);
  15937. program_headers = NULL;
  15938. }
  15939. if (section_headers)
  15940. {
  15941. free (section_headers);
  15942. section_headers = NULL;
  15943. }
  15944. if (string_table)
  15945. {
  15946. free (string_table);
  15947. string_table = NULL;
  15948. string_table_length = 0;
  15949. }
  15950. if (dynamic_strings)
  15951. {
  15952. free (dynamic_strings);
  15953. dynamic_strings = NULL;
  15954. dynamic_strings_length = 0;
  15955. }
  15956. if (dynamic_symbols)
  15957. {
  15958. free (dynamic_symbols);
  15959. dynamic_symbols = NULL;
  15960. num_dynamic_syms = 0;
  15961. }
  15962. if (dynamic_syminfo)
  15963. {
  15964. free (dynamic_syminfo);
  15965. dynamic_syminfo = NULL;
  15966. }
  15967. if (dynamic_section)
  15968. {
  15969. free (dynamic_section);
  15970. dynamic_section = NULL;
  15971. }
  15972. if (section_headers_groups)
  15973. {
  15974. free (section_headers_groups);
  15975. section_headers_groups = NULL;
  15976. }
  15977. if (section_groups)
  15978. {
  15979. struct group_list * g;
  15980. struct group_list * next;
  15981. for (i = 0; i < group_count; i++)
  15982. {
  15983. for (g = section_groups [i].root; g != NULL; g = next)
  15984. {
  15985. next = g->next;
  15986. free (g);
  15987. }
  15988. }
  15989. free (section_groups);
  15990. section_groups = NULL;
  15991. }
  15992. free_debug_memory ();
  15993. return res;
  15994. }
  15995. /* Process an ELF archive.
  15996. On entry the file is positioned just after the ARMAG string.
  15997. Returns TRUE upon success, FALSE otherwise. */
  15998. static bfd_boolean
  15999. process_archive (char * file_name, FILE * file, bfd_boolean is_thin_archive)
  16000. {
  16001. struct archive_info arch;
  16002. struct archive_info nested_arch;
  16003. size_t got;
  16004. bfd_boolean ret = TRUE;
  16005. show_name = TRUE;
  16006. /* The ARCH structure is used to hold information about this archive. */
  16007. arch.file_name = NULL;
  16008. arch.file = NULL;
  16009. arch.index_array = NULL;
  16010. arch.sym_table = NULL;
  16011. arch.longnames = NULL;
  16012. /* The NESTED_ARCH structure is used as a single-item cache of information
  16013. about a nested archive (when members of a thin archive reside within
  16014. another regular archive file). */
  16015. nested_arch.file_name = NULL;
  16016. nested_arch.file = NULL;
  16017. nested_arch.index_array = NULL;
  16018. nested_arch.sym_table = NULL;
  16019. nested_arch.longnames = NULL;
  16020. if (setup_archive (&arch, file_name, file, is_thin_archive, do_archive_index) != 0)
  16021. {
  16022. ret = FALSE;
  16023. goto out;
  16024. }
  16025. if (do_archive_index)
  16026. {
  16027. if (arch.sym_table == NULL)
  16028. error (_("%s: unable to dump the index as none was found\n"), file_name);
  16029. else
  16030. {
  16031. unsigned long i, l;
  16032. unsigned long current_pos;
  16033. printf (_("Index of archive %s: (%lu entries, 0x%lx bytes in the symbol table)\n"),
  16034. file_name, (unsigned long) arch.index_num, arch.sym_size);
  16035. current_pos = ftell (file);
  16036. for (i = l = 0; i < arch.index_num; i++)
  16037. {
  16038. if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1])))
  16039. {
  16040. char * member_name;
  16041. member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch);
  16042. if (member_name != NULL)
  16043. {
  16044. char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name);
  16045. if (qualified_name != NULL)
  16046. {
  16047. printf (_("Contents of binary %s at offset "), qualified_name);
  16048. (void) print_vma (arch.index_array[i], PREFIX_HEX);
  16049. putchar ('\n');
  16050. free (qualified_name);
  16051. }
  16052. }
  16053. }
  16054. if (l >= arch.sym_size)
  16055. {
  16056. error (_("%s: end of the symbol table reached before the end of the index\n"),
  16057. file_name);
  16058. ret = FALSE;
  16059. break;
  16060. }
  16061. /* PR 17531: file: 0b6630b2. */
  16062. printf ("\t%.*s\n", (int) (arch.sym_size - l), arch.sym_table + l);
  16063. l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1;
  16064. }
  16065. if (arch.uses_64bit_indicies)
  16066. l = (l + 7) & ~ 7;
  16067. else
  16068. l += l & 1;
  16069. if (l < arch.sym_size)
  16070. {
  16071. error (_("%s: %ld bytes remain in the symbol table, but without corresponding entries in the index table\n"),
  16072. file_name, arch.sym_size - l);
  16073. ret = FALSE;
  16074. }
  16075. if (fseek (file, current_pos, SEEK_SET) != 0)
  16076. {
  16077. error (_("%s: failed to seek back to start of object files in the archive\n"), file_name);
  16078. ret = FALSE;
  16079. goto out;
  16080. }
  16081. }
  16082. if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
  16083. && !do_segments && !do_header && !do_dump && !do_version
  16084. && !do_histogram && !do_debugging && !do_arch && !do_notes
  16085. && !do_section_groups && !do_dyn_syms)
  16086. {
  16087. ret = TRUE; /* Archive index only. */
  16088. goto out;
  16089. }
  16090. }
  16091. while (1)
  16092. {
  16093. char * name;
  16094. size_t namelen;
  16095. char * qualified_name;
  16096. /* Read the next archive header. */
  16097. if (fseek (file, arch.next_arhdr_offset, SEEK_SET) != 0)
  16098. {
  16099. error (_("%s: failed to seek to next archive header\n"), file_name);
  16100. return FALSE;
  16101. }
  16102. got = fread (&arch.arhdr, 1, sizeof arch.arhdr, file);
  16103. if (got != sizeof arch.arhdr)
  16104. {
  16105. if (got == 0)
  16106. break;
  16107. error (_("%s: failed to read archive header\n"), file_name);
  16108. ret = FALSE;
  16109. break;
  16110. }
  16111. if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
  16112. {
  16113. error (_("%s: did not find a valid archive header\n"), arch.file_name);
  16114. ret = FALSE;
  16115. break;
  16116. }
  16117. arch.next_arhdr_offset += sizeof arch.arhdr;
  16118. archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
  16119. if (archive_file_size & 01)
  16120. ++archive_file_size;
  16121. name = get_archive_member_name (&arch, &nested_arch);
  16122. if (name == NULL)
  16123. {
  16124. error (_("%s: bad archive file name\n"), file_name);
  16125. ret = FALSE;
  16126. break;
  16127. }
  16128. namelen = strlen (name);
  16129. qualified_name = make_qualified_name (&arch, &nested_arch, name);
  16130. if (qualified_name == NULL)
  16131. {
  16132. error (_("%s: bad archive file name\n"), file_name);
  16133. ret = FALSE;
  16134. break;
  16135. }
  16136. if (is_thin_archive && arch.nested_member_origin == 0)
  16137. {
  16138. /* This is a proxy for an external member of a thin archive. */
  16139. FILE * member_file;
  16140. char * member_file_name = adjust_relative_path (file_name, name, namelen);
  16141. if (member_file_name == NULL)
  16142. {
  16143. ret = FALSE;
  16144. break;
  16145. }
  16146. member_file = fopen (member_file_name, "rb");
  16147. if (member_file == NULL)
  16148. {
  16149. error (_("Input file '%s' is not readable.\n"), member_file_name);
  16150. free (member_file_name);
  16151. ret = FALSE;
  16152. break;
  16153. }
  16154. archive_file_offset = arch.nested_member_origin;
  16155. if (! process_object (qualified_name, member_file))
  16156. ret = FALSE;
  16157. fclose (member_file);
  16158. free (member_file_name);
  16159. }
  16160. else if (is_thin_archive)
  16161. {
  16162. /* PR 15140: Allow for corrupt thin archives. */
  16163. if (nested_arch.file == NULL)
  16164. {
  16165. error (_("%s: contains corrupt thin archive: %s\n"),
  16166. file_name, name);
  16167. ret = FALSE;
  16168. break;
  16169. }
  16170. /* This is a proxy for a member of a nested archive. */
  16171. archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;
  16172. /* The nested archive file will have been opened and setup by
  16173. get_archive_member_name. */
  16174. if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0)
  16175. {
  16176. error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name);
  16177. ret = FALSE;
  16178. break;
  16179. }
  16180. if (! process_object (qualified_name, nested_arch.file))
  16181. ret = FALSE;
  16182. }
  16183. else
  16184. {
  16185. archive_file_offset = arch.next_arhdr_offset;
  16186. arch.next_arhdr_offset += archive_file_size;
  16187. if (! process_object (qualified_name, file))
  16188. ret = FALSE;
  16189. }
  16190. if (dump_sects != NULL)
  16191. {
  16192. free (dump_sects);
  16193. dump_sects = NULL;
  16194. num_dump_sects = 0;
  16195. }
  16196. free (qualified_name);
  16197. }
  16198. out:
  16199. if (nested_arch.file != NULL)
  16200. fclose (nested_arch.file);
  16201. release_archive (&nested_arch);
  16202. release_archive (&arch);
  16203. return ret;
  16204. }
  16205. static bfd_boolean
  16206. process_file (char * file_name)
  16207. {
  16208. FILE * file;
  16209. struct stat statbuf;
  16210. char armag[SARMAG];
  16211. bfd_boolean ret = TRUE;
  16212. if (stat (file_name, &statbuf) < 0)
  16213. {
  16214. if (errno == ENOENT)
  16215. error (_("'%s': No such file\n"), file_name);
  16216. else
  16217. error (_("Could not locate '%s'. System error message: %s\n"),
  16218. file_name, strerror (errno));
  16219. return FALSE;
  16220. }
  16221. if (! S_ISREG (statbuf.st_mode))
  16222. {
  16223. error (_("'%s' is not an ordinary file\n"), file_name);
  16224. return FALSE;
  16225. }
  16226. file = fopen (file_name, "rb");
  16227. if (file == NULL)
  16228. {
  16229. error (_("Input file '%s' is not readable.\n"), file_name);
  16230. return FALSE;
  16231. }
  16232. if (fread (armag, SARMAG, 1, file) != 1)
  16233. {
  16234. error (_("%s: Failed to read file's magic number\n"), file_name);
  16235. fclose (file);
  16236. return FALSE;
  16237. }
  16238. current_file_size = (bfd_size_type) statbuf.st_size;
  16239. if (memcmp (armag, ARMAG, SARMAG) == 0)
  16240. {
  16241. if (! process_archive (file_name, file, FALSE))
  16242. ret = FALSE;
  16243. }
  16244. else if (memcmp (armag, ARMAGT, SARMAG) == 0)
  16245. {
  16246. if ( ! process_archive (file_name, file, TRUE))
  16247. ret = FALSE;
  16248. }
  16249. else
  16250. {
  16251. if (do_archive_index)
  16252. error (_("File %s is not an archive so its index cannot be displayed.\n"),
  16253. file_name);
  16254. rewind (file);
  16255. archive_file_size = archive_file_offset = 0;
  16256. if (! process_object (file_name, file))
  16257. ret = FALSE;
  16258. }
  16259. fclose (file);
  16260. current_file_size = 0;
  16261. return ret;
  16262. }
  16263. #ifdef SUPPORT_DISASSEMBLY
  16264. /* Needed by the i386 disassembler. For extra credit, someone could
  16265. fix this so that we insert symbolic addresses here, esp for GOT/PLT
  16266. symbols. */
  16267. void
  16268. print_address (unsigned int addr, FILE * outfile)
  16269. {
  16270. fprintf (outfile,"0x%8.8x", addr);
  16271. }
  16272. /* Needed by the i386 disassembler. */
  16273. void
  16274. db_task_printsym (unsigned int addr)
  16275. {
  16276. print_address (addr, stderr);
  16277. }
  16278. #endif
  16279. int
  16280. main (int argc, char ** argv)
  16281. {
  16282. int err;
  16283. #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
  16284. setlocale (LC_MESSAGES, "");
  16285. #endif
  16286. #if defined (HAVE_SETLOCALE)
  16287. setlocale (LC_CTYPE, "");
  16288. #endif
  16289. bindtextdomain (PACKAGE, LOCALEDIR);
  16290. textdomain (PACKAGE);
  16291. expandargv (&argc, &argv);
  16292. parse_args (argc, argv);
  16293. if (num_dump_sects > 0)
  16294. {
  16295. /* Make a copy of the dump_sects array. */
  16296. cmdline_dump_sects = (dump_type *)
  16297. malloc (num_dump_sects * sizeof (* dump_sects));
  16298. if (cmdline_dump_sects == NULL)
  16299. error (_("Out of memory allocating dump request table.\n"));
  16300. else
  16301. {
  16302. memcpy (cmdline_dump_sects, dump_sects,
  16303. num_dump_sects * sizeof (* dump_sects));
  16304. num_cmdline_dump_sects = num_dump_sects;
  16305. }
  16306. }
  16307. if (optind < (argc - 1))
  16308. show_name = TRUE;
  16309. else if (optind >= argc)
  16310. {
  16311. warn (_("Nothing to do.\n"));
  16312. usage (stderr);
  16313. }
  16314. err = FALSE;
  16315. while (optind < argc)
  16316. if (! process_file (argv[optind++]))
  16317. err = TRUE;
  16318. if (dump_sects != NULL)
  16319. free (dump_sects);
  16320. if (cmdline_dump_sects != NULL)
  16321. free (cmdline_dump_sects);
  16322. return err ? EXIT_FAILURE : EXIT_SUCCESS;
  16323. }