som.c 212 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816
  1. /* bfd back-end for HP PA-RISC SOM objects.
  2. Copyright (C) 1990-2015 Free Software Foundation, Inc.
  3. Contributed by the Center for Software Science at the
  4. University of Utah.
  5. This file is part of BFD, the Binary File Descriptor library.
  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. #include "sysdep.h"
  19. #include "alloca-conf.h"
  20. #include "bfd.h"
  21. #include "libbfd.h"
  22. #include "som.h"
  23. #include "safe-ctype.h"
  24. #include "som/reloc.h"
  25. #include "aout/ar.h"
  26. static bfd_reloc_status_type hppa_som_reloc
  27. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  28. static bfd_boolean som_mkobject (bfd *);
  29. static bfd_boolean som_is_space (asection *);
  30. static bfd_boolean som_is_subspace (asection *);
  31. static int compare_subspaces (const void *, const void *);
  32. static unsigned long som_compute_checksum (struct som_external_header *);
  33. static bfd_boolean som_build_and_write_symbol_table (bfd *);
  34. static unsigned int som_slurp_symbol_table (bfd *);
  35. /* Magic not defined in standard HP-UX header files until 8.0. */
  36. #ifndef CPU_PA_RISC1_0
  37. #define CPU_PA_RISC1_0 0x20B
  38. #endif /* CPU_PA_RISC1_0 */
  39. #ifndef CPU_PA_RISC1_1
  40. #define CPU_PA_RISC1_1 0x210
  41. #endif /* CPU_PA_RISC1_1 */
  42. #ifndef CPU_PA_RISC2_0
  43. #define CPU_PA_RISC2_0 0x214
  44. #endif /* CPU_PA_RISC2_0 */
  45. #ifndef _PA_RISC1_0_ID
  46. #define _PA_RISC1_0_ID CPU_PA_RISC1_0
  47. #endif /* _PA_RISC1_0_ID */
  48. #ifndef _PA_RISC1_1_ID
  49. #define _PA_RISC1_1_ID CPU_PA_RISC1_1
  50. #endif /* _PA_RISC1_1_ID */
  51. #ifndef _PA_RISC2_0_ID
  52. #define _PA_RISC2_0_ID CPU_PA_RISC2_0
  53. #endif /* _PA_RISC2_0_ID */
  54. #ifndef _PA_RISC_MAXID
  55. #define _PA_RISC_MAXID 0x2FF
  56. #endif /* _PA_RISC_MAXID */
  57. #ifndef _PA_RISC_ID
  58. #define _PA_RISC_ID(__m_num) \
  59. (((__m_num) == _PA_RISC1_0_ID) || \
  60. ((__m_num) >= _PA_RISC1_1_ID && (__m_num) <= _PA_RISC_MAXID))
  61. #endif /* _PA_RISC_ID */
  62. /* HIUX in it's infinite stupidity changed the names for several "well
  63. known" constants. Work around such braindamage. Try the HPUX version
  64. first, then the HIUX version, and finally provide a default. */
  65. #ifdef HPUX_AUX_ID
  66. #define EXEC_AUX_ID HPUX_AUX_ID
  67. #endif
  68. #if !defined (EXEC_AUX_ID) && defined (HIUX_AUX_ID)
  69. #define EXEC_AUX_ID HIUX_AUX_ID
  70. #endif
  71. #ifndef EXEC_AUX_ID
  72. #define EXEC_AUX_ID 0
  73. #endif
  74. /* Size (in chars) of the temporary buffers used during fixup and string
  75. table writes. */
  76. #define SOM_TMP_BUFSIZE 8192
  77. /* Size of the hash table in archives. */
  78. #define SOM_LST_HASH_SIZE 31
  79. /* Max number of SOMs to be found in an archive. */
  80. #define SOM_LST_MODULE_LIMIT 1024
  81. /* Generic alignment macro. */
  82. #define SOM_ALIGN(val, alignment) \
  83. (((val) + (alignment) - 1) &~ ((unsigned long) (alignment) - 1))
  84. /* SOM allows any one of the four previous relocations to be reused
  85. with a "R_PREV_FIXUP" relocation entry. Since R_PREV_FIXUP
  86. relocations are always a single byte, using a R_PREV_FIXUP instead
  87. of some multi-byte relocation makes object files smaller.
  88. Note one side effect of using a R_PREV_FIXUP is the relocation that
  89. is being repeated moves to the front of the queue. */
  90. struct reloc_queue
  91. {
  92. unsigned char *reloc;
  93. unsigned int size;
  94. } reloc_queue[4];
  95. /* This fully describes the symbol types which may be attached to
  96. an EXPORT or IMPORT directive. Only SOM uses this formation
  97. (ELF has no need for it). */
  98. typedef enum
  99. {
  100. SYMBOL_TYPE_UNKNOWN,
  101. SYMBOL_TYPE_ABSOLUTE,
  102. SYMBOL_TYPE_CODE,
  103. SYMBOL_TYPE_DATA,
  104. SYMBOL_TYPE_ENTRY,
  105. SYMBOL_TYPE_MILLICODE,
  106. SYMBOL_TYPE_PLABEL,
  107. SYMBOL_TYPE_PRI_PROG,
  108. SYMBOL_TYPE_SEC_PROG,
  109. } pa_symbol_type;
  110. struct section_to_type
  111. {
  112. const char *section;
  113. char type;
  114. };
  115. /* Assorted symbol information that needs to be derived from the BFD symbol
  116. and/or the BFD backend private symbol data. */
  117. struct som_misc_symbol_info
  118. {
  119. unsigned int symbol_type;
  120. unsigned int symbol_scope;
  121. unsigned int arg_reloc;
  122. unsigned int symbol_info;
  123. unsigned int symbol_value;
  124. unsigned int priv_level;
  125. unsigned int secondary_def;
  126. unsigned int is_comdat;
  127. unsigned int is_common;
  128. unsigned int dup_common;
  129. };
  130. /* Map SOM section names to POSIX/BSD single-character symbol types.
  131. This table includes all the standard subspaces as defined in the
  132. current "PRO ABI for PA-RISC Systems", $UNWIND$ which for
  133. some reason was left out, and sections specific to embedded stabs. */
  134. static const struct section_to_type stt[] =
  135. {
  136. {"$TEXT$", 't'},
  137. {"$SHLIB_INFO$", 't'},
  138. {"$MILLICODE$", 't'},
  139. {"$LIT$", 't'},
  140. {"$CODE$", 't'},
  141. {"$UNWIND_START$", 't'},
  142. {"$UNWIND$", 't'},
  143. {"$PRIVATE$", 'd'},
  144. {"$PLT$", 'd'},
  145. {"$SHLIB_DATA$", 'd'},
  146. {"$DATA$", 'd'},
  147. {"$SHORTDATA$", 'g'},
  148. {"$DLT$", 'd'},
  149. {"$GLOBAL$", 'g'},
  150. {"$SHORTBSS$", 's'},
  151. {"$BSS$", 'b'},
  152. {"$GDB_STRINGS$", 'N'},
  153. {"$GDB_SYMBOLS$", 'N'},
  154. {0, 0}
  155. };
  156. /* About the relocation formatting table...
  157. There are 256 entries in the table, one for each possible
  158. relocation opcode available in SOM. We index the table by
  159. the relocation opcode. The names and operations are those
  160. defined by a.out_800 (4).
  161. Right now this table is only used to count and perform minimal
  162. processing on relocation streams so that they can be internalized
  163. into BFD and symbolically printed by utilities. To make actual use
  164. of them would be much more difficult, BFD's concept of relocations
  165. is far too simple to handle SOM relocations. The basic assumption
  166. that a relocation can be completely processed independent of other
  167. relocations before an object file is written is invalid for SOM.
  168. The SOM relocations are meant to be processed as a stream, they
  169. specify copying of data from the input section to the output section
  170. while possibly modifying the data in some manner. They also can
  171. specify that a variable number of zeros or uninitialized data be
  172. inserted on in the output segment at the current offset. Some
  173. relocations specify that some previous relocation be re-applied at
  174. the current location in the input/output sections. And finally a number
  175. of relocations have effects on other sections (R_ENTRY, R_EXIT,
  176. R_UNWIND_AUX and a variety of others). There isn't even enough room
  177. in the BFD relocation data structure to store enough information to
  178. perform all the relocations.
  179. Each entry in the table has three fields.
  180. The first entry is an index into this "class" of relocations. This
  181. index can then be used as a variable within the relocation itself.
  182. The second field is a format string which actually controls processing
  183. of the relocation. It uses a simple postfix machine to do calculations
  184. based on variables/constants found in the string and the relocation
  185. stream.
  186. The third field specifys whether or not this relocation may use
  187. a constant (V) from the previous R_DATA_OVERRIDE rather than a constant
  188. stored in the instruction.
  189. Variables:
  190. L = input space byte count
  191. D = index into class of relocations
  192. M = output space byte count
  193. N = statement number (unused?)
  194. O = stack operation
  195. R = parameter relocation bits
  196. S = symbol index
  197. T = first 32 bits of stack unwind information
  198. U = second 32 bits of stack unwind information
  199. V = a literal constant (usually used in the next relocation)
  200. P = a previous relocation
  201. Lower case letters (starting with 'b') refer to following
  202. bytes in the relocation stream. 'b' is the next 1 byte,
  203. c is the next 2 bytes, d is the next 3 bytes, etc...
  204. This is the variable part of the relocation entries that
  205. makes our life a living hell.
  206. numerical constants are also used in the format string. Note
  207. the constants are represented in decimal.
  208. '+', "*" and "=" represents the obvious postfix operators.
  209. '<' represents a left shift.
  210. Stack Operations:
  211. Parameter Relocation Bits:
  212. Unwind Entries:
  213. Previous Relocations: The index field represents which in the queue
  214. of 4 previous fixups should be re-applied.
  215. Literal Constants: These are generally used to represent addend
  216. parts of relocations when these constants are not stored in the
  217. fields of the instructions themselves. For example the instruction
  218. addil foo-$global$-0x1234 would use an override for "0x1234" rather
  219. than storing it into the addil itself. */
  220. struct fixup_format
  221. {
  222. int D;
  223. const char *format;
  224. };
  225. static const struct fixup_format som_fixup_formats[256] =
  226. {
  227. /* R_NO_RELOCATION. */
  228. { 0, "LD1+4*=" }, /* 0x00 */
  229. { 1, "LD1+4*=" }, /* 0x01 */
  230. { 2, "LD1+4*=" }, /* 0x02 */
  231. { 3, "LD1+4*=" }, /* 0x03 */
  232. { 4, "LD1+4*=" }, /* 0x04 */
  233. { 5, "LD1+4*=" }, /* 0x05 */
  234. { 6, "LD1+4*=" }, /* 0x06 */
  235. { 7, "LD1+4*=" }, /* 0x07 */
  236. { 8, "LD1+4*=" }, /* 0x08 */
  237. { 9, "LD1+4*=" }, /* 0x09 */
  238. { 10, "LD1+4*=" }, /* 0x0a */
  239. { 11, "LD1+4*=" }, /* 0x0b */
  240. { 12, "LD1+4*=" }, /* 0x0c */
  241. { 13, "LD1+4*=" }, /* 0x0d */
  242. { 14, "LD1+4*=" }, /* 0x0e */
  243. { 15, "LD1+4*=" }, /* 0x0f */
  244. { 16, "LD1+4*=" }, /* 0x10 */
  245. { 17, "LD1+4*=" }, /* 0x11 */
  246. { 18, "LD1+4*=" }, /* 0x12 */
  247. { 19, "LD1+4*=" }, /* 0x13 */
  248. { 20, "LD1+4*=" }, /* 0x14 */
  249. { 21, "LD1+4*=" }, /* 0x15 */
  250. { 22, "LD1+4*=" }, /* 0x16 */
  251. { 23, "LD1+4*=" }, /* 0x17 */
  252. { 0, "LD8<b+1+4*=" }, /* 0x18 */
  253. { 1, "LD8<b+1+4*=" }, /* 0x19 */
  254. { 2, "LD8<b+1+4*=" }, /* 0x1a */
  255. { 3, "LD8<b+1+4*=" }, /* 0x1b */
  256. { 0, "LD16<c+1+4*=" }, /* 0x1c */
  257. { 1, "LD16<c+1+4*=" }, /* 0x1d */
  258. { 2, "LD16<c+1+4*=" }, /* 0x1e */
  259. { 0, "Ld1+=" }, /* 0x1f */
  260. /* R_ZEROES. */
  261. { 0, "Lb1+4*=" }, /* 0x20 */
  262. { 1, "Ld1+=" }, /* 0x21 */
  263. /* R_UNINIT. */
  264. { 0, "Lb1+4*=" }, /* 0x22 */
  265. { 1, "Ld1+=" }, /* 0x23 */
  266. /* R_RELOCATION. */
  267. { 0, "L4=" }, /* 0x24 */
  268. /* R_DATA_ONE_SYMBOL. */
  269. { 0, "L4=Sb=" }, /* 0x25 */
  270. { 1, "L4=Sd=" }, /* 0x26 */
  271. /* R_DATA_PLABEL. */
  272. { 0, "L4=Sb=" }, /* 0x27 */
  273. { 1, "L4=Sd=" }, /* 0x28 */
  274. /* R_SPACE_REF. */
  275. { 0, "L4=" }, /* 0x29 */
  276. /* R_REPEATED_INIT. */
  277. { 0, "L4=Mb1+4*=" }, /* 0x2a */
  278. { 1, "Lb4*=Mb1+L*=" }, /* 0x2b */
  279. { 2, "Lb4*=Md1+4*=" }, /* 0x2c */
  280. { 3, "Ld1+=Me1+=" }, /* 0x2d */
  281. { 0, "" }, /* 0x2e */
  282. { 0, "" }, /* 0x2f */
  283. /* R_PCREL_CALL. */
  284. { 0, "L4=RD=Sb=" }, /* 0x30 */
  285. { 1, "L4=RD=Sb=" }, /* 0x31 */
  286. { 2, "L4=RD=Sb=" }, /* 0x32 */
  287. { 3, "L4=RD=Sb=" }, /* 0x33 */
  288. { 4, "L4=RD=Sb=" }, /* 0x34 */
  289. { 5, "L4=RD=Sb=" }, /* 0x35 */
  290. { 6, "L4=RD=Sb=" }, /* 0x36 */
  291. { 7, "L4=RD=Sb=" }, /* 0x37 */
  292. { 8, "L4=RD=Sb=" }, /* 0x38 */
  293. { 9, "L4=RD=Sb=" }, /* 0x39 */
  294. { 0, "L4=RD8<b+=Sb=" }, /* 0x3a */
  295. { 1, "L4=RD8<b+=Sb=" }, /* 0x3b */
  296. { 0, "L4=RD8<b+=Sd=" }, /* 0x3c */
  297. { 1, "L4=RD8<b+=Sd=" }, /* 0x3d */
  298. /* R_SHORT_PCREL_MODE. */
  299. { 0, "" }, /* 0x3e */
  300. /* R_LONG_PCREL_MODE. */
  301. { 0, "" }, /* 0x3f */
  302. /* R_ABS_CALL. */
  303. { 0, "L4=RD=Sb=" }, /* 0x40 */
  304. { 1, "L4=RD=Sb=" }, /* 0x41 */
  305. { 2, "L4=RD=Sb=" }, /* 0x42 */
  306. { 3, "L4=RD=Sb=" }, /* 0x43 */
  307. { 4, "L4=RD=Sb=" }, /* 0x44 */
  308. { 5, "L4=RD=Sb=" }, /* 0x45 */
  309. { 6, "L4=RD=Sb=" }, /* 0x46 */
  310. { 7, "L4=RD=Sb=" }, /* 0x47 */
  311. { 8, "L4=RD=Sb=" }, /* 0x48 */
  312. { 9, "L4=RD=Sb=" }, /* 0x49 */
  313. { 0, "L4=RD8<b+=Sb=" }, /* 0x4a */
  314. { 1, "L4=RD8<b+=Sb=" }, /* 0x4b */
  315. { 0, "L4=RD8<b+=Sd=" }, /* 0x4c */
  316. { 1, "L4=RD8<b+=Sd=" }, /* 0x4d */
  317. /* R_RESERVED. */
  318. { 0, "" }, /* 0x4e */
  319. { 0, "" }, /* 0x4f */
  320. /* R_DP_RELATIVE. */
  321. { 0, "L4=SD=" }, /* 0x50 */
  322. { 1, "L4=SD=" }, /* 0x51 */
  323. { 2, "L4=SD=" }, /* 0x52 */
  324. { 3, "L4=SD=" }, /* 0x53 */
  325. { 4, "L4=SD=" }, /* 0x54 */
  326. { 5, "L4=SD=" }, /* 0x55 */
  327. { 6, "L4=SD=" }, /* 0x56 */
  328. { 7, "L4=SD=" }, /* 0x57 */
  329. { 8, "L4=SD=" }, /* 0x58 */
  330. { 9, "L4=SD=" }, /* 0x59 */
  331. { 10, "L4=SD=" }, /* 0x5a */
  332. { 11, "L4=SD=" }, /* 0x5b */
  333. { 12, "L4=SD=" }, /* 0x5c */
  334. { 13, "L4=SD=" }, /* 0x5d */
  335. { 14, "L4=SD=" }, /* 0x5e */
  336. { 15, "L4=SD=" }, /* 0x5f */
  337. { 16, "L4=SD=" }, /* 0x60 */
  338. { 17, "L4=SD=" }, /* 0x61 */
  339. { 18, "L4=SD=" }, /* 0x62 */
  340. { 19, "L4=SD=" }, /* 0x63 */
  341. { 20, "L4=SD=" }, /* 0x64 */
  342. { 21, "L4=SD=" }, /* 0x65 */
  343. { 22, "L4=SD=" }, /* 0x66 */
  344. { 23, "L4=SD=" }, /* 0x67 */
  345. { 24, "L4=SD=" }, /* 0x68 */
  346. { 25, "L4=SD=" }, /* 0x69 */
  347. { 26, "L4=SD=" }, /* 0x6a */
  348. { 27, "L4=SD=" }, /* 0x6b */
  349. { 28, "L4=SD=" }, /* 0x6c */
  350. { 29, "L4=SD=" }, /* 0x6d */
  351. { 30, "L4=SD=" }, /* 0x6e */
  352. { 31, "L4=SD=" }, /* 0x6f */
  353. { 32, "L4=Sb=" }, /* 0x70 */
  354. { 33, "L4=Sd=" }, /* 0x71 */
  355. /* R_DATA_GPREL. */
  356. { 0, "L4=Sd=" }, /* 0x72 */
  357. /* R_RESERVED. */
  358. { 0, "" }, /* 0x73 */
  359. { 0, "" }, /* 0x74 */
  360. { 0, "" }, /* 0x75 */
  361. { 0, "" }, /* 0x76 */
  362. { 0, "" }, /* 0x77 */
  363. /* R_DLT_REL. */
  364. { 0, "L4=Sb=" }, /* 0x78 */
  365. { 1, "L4=Sd=" }, /* 0x79 */
  366. /* R_RESERVED. */
  367. { 0, "" }, /* 0x7a */
  368. { 0, "" }, /* 0x7b */
  369. { 0, "" }, /* 0x7c */
  370. { 0, "" }, /* 0x7d */
  371. { 0, "" }, /* 0x7e */
  372. { 0, "" }, /* 0x7f */
  373. /* R_CODE_ONE_SYMBOL. */
  374. { 0, "L4=SD=" }, /* 0x80 */
  375. { 1, "L4=SD=" }, /* 0x81 */
  376. { 2, "L4=SD=" }, /* 0x82 */
  377. { 3, "L4=SD=" }, /* 0x83 */
  378. { 4, "L4=SD=" }, /* 0x84 */
  379. { 5, "L4=SD=" }, /* 0x85 */
  380. { 6, "L4=SD=" }, /* 0x86 */
  381. { 7, "L4=SD=" }, /* 0x87 */
  382. { 8, "L4=SD=" }, /* 0x88 */
  383. { 9, "L4=SD=" }, /* 0x89 */
  384. { 10, "L4=SD=" }, /* 0x8q */
  385. { 11, "L4=SD=" }, /* 0x8b */
  386. { 12, "L4=SD=" }, /* 0x8c */
  387. { 13, "L4=SD=" }, /* 0x8d */
  388. { 14, "L4=SD=" }, /* 0x8e */
  389. { 15, "L4=SD=" }, /* 0x8f */
  390. { 16, "L4=SD=" }, /* 0x90 */
  391. { 17, "L4=SD=" }, /* 0x91 */
  392. { 18, "L4=SD=" }, /* 0x92 */
  393. { 19, "L4=SD=" }, /* 0x93 */
  394. { 20, "L4=SD=" }, /* 0x94 */
  395. { 21, "L4=SD=" }, /* 0x95 */
  396. { 22, "L4=SD=" }, /* 0x96 */
  397. { 23, "L4=SD=" }, /* 0x97 */
  398. { 24, "L4=SD=" }, /* 0x98 */
  399. { 25, "L4=SD=" }, /* 0x99 */
  400. { 26, "L4=SD=" }, /* 0x9a */
  401. { 27, "L4=SD=" }, /* 0x9b */
  402. { 28, "L4=SD=" }, /* 0x9c */
  403. { 29, "L4=SD=" }, /* 0x9d */
  404. { 30, "L4=SD=" }, /* 0x9e */
  405. { 31, "L4=SD=" }, /* 0x9f */
  406. { 32, "L4=Sb=" }, /* 0xa0 */
  407. { 33, "L4=Sd=" }, /* 0xa1 */
  408. /* R_RESERVED. */
  409. { 0, "" }, /* 0xa2 */
  410. { 0, "" }, /* 0xa3 */
  411. { 0, "" }, /* 0xa4 */
  412. { 0, "" }, /* 0xa5 */
  413. { 0, "" }, /* 0xa6 */
  414. { 0, "" }, /* 0xa7 */
  415. { 0, "" }, /* 0xa8 */
  416. { 0, "" }, /* 0xa9 */
  417. { 0, "" }, /* 0xaa */
  418. { 0, "" }, /* 0xab */
  419. { 0, "" }, /* 0xac */
  420. { 0, "" }, /* 0xad */
  421. /* R_MILLI_REL. */
  422. { 0, "L4=Sb=" }, /* 0xae */
  423. { 1, "L4=Sd=" }, /* 0xaf */
  424. /* R_CODE_PLABEL. */
  425. { 0, "L4=Sb=" }, /* 0xb0 */
  426. { 1, "L4=Sd=" }, /* 0xb1 */
  427. /* R_BREAKPOINT. */
  428. { 0, "L4=" }, /* 0xb2 */
  429. /* R_ENTRY. */
  430. { 0, "Te=Ue=" }, /* 0xb3 */
  431. { 1, "Uf=" }, /* 0xb4 */
  432. /* R_ALT_ENTRY. */
  433. { 0, "" }, /* 0xb5 */
  434. /* R_EXIT. */
  435. { 0, "" }, /* 0xb6 */
  436. /* R_BEGIN_TRY. */
  437. { 0, "" }, /* 0xb7 */
  438. /* R_END_TRY. */
  439. { 0, "R0=" }, /* 0xb8 */
  440. { 1, "Rb4*=" }, /* 0xb9 */
  441. { 2, "Rd4*=" }, /* 0xba */
  442. /* R_BEGIN_BRTAB. */
  443. { 0, "" }, /* 0xbb */
  444. /* R_END_BRTAB. */
  445. { 0, "" }, /* 0xbc */
  446. /* R_STATEMENT. */
  447. { 0, "Nb=" }, /* 0xbd */
  448. { 1, "Nc=" }, /* 0xbe */
  449. { 2, "Nd=" }, /* 0xbf */
  450. /* R_DATA_EXPR. */
  451. { 0, "L4=" }, /* 0xc0 */
  452. /* R_CODE_EXPR. */
  453. { 0, "L4=" }, /* 0xc1 */
  454. /* R_FSEL. */
  455. { 0, "" }, /* 0xc2 */
  456. /* R_LSEL. */
  457. { 0, "" }, /* 0xc3 */
  458. /* R_RSEL. */
  459. { 0, "" }, /* 0xc4 */
  460. /* R_N_MODE. */
  461. { 0, "" }, /* 0xc5 */
  462. /* R_S_MODE. */
  463. { 0, "" }, /* 0xc6 */
  464. /* R_D_MODE. */
  465. { 0, "" }, /* 0xc7 */
  466. /* R_R_MODE. */
  467. { 0, "" }, /* 0xc8 */
  468. /* R_DATA_OVERRIDE. */
  469. { 0, "V0=" }, /* 0xc9 */
  470. { 1, "Vb=" }, /* 0xca */
  471. { 2, "Vc=" }, /* 0xcb */
  472. { 3, "Vd=" }, /* 0xcc */
  473. { 4, "Ve=" }, /* 0xcd */
  474. /* R_TRANSLATED. */
  475. { 0, "" }, /* 0xce */
  476. /* R_AUX_UNWIND. */
  477. { 0,"Sd=Ve=Ee=" }, /* 0xcf */
  478. /* R_COMP1. */
  479. { 0, "Ob=" }, /* 0xd0 */
  480. /* R_COMP2. */
  481. { 0, "Ob=Sd=" }, /* 0xd1 */
  482. /* R_COMP3. */
  483. { 0, "Ob=Ve=" }, /* 0xd2 */
  484. /* R_PREV_FIXUP. */
  485. { 0, "P" }, /* 0xd3 */
  486. { 1, "P" }, /* 0xd4 */
  487. { 2, "P" }, /* 0xd5 */
  488. { 3, "P" }, /* 0xd6 */
  489. /* R_SEC_STMT. */
  490. { 0, "" }, /* 0xd7 */
  491. /* R_N0SEL. */
  492. { 0, "" }, /* 0xd8 */
  493. /* R_N1SEL. */
  494. { 0, "" }, /* 0xd9 */
  495. /* R_LINETAB. */
  496. { 0, "Eb=Sd=Ve=" }, /* 0xda */
  497. /* R_LINETAB_ESC. */
  498. { 0, "Eb=Mb=" }, /* 0xdb */
  499. /* R_LTP_OVERRIDE. */
  500. { 0, "" }, /* 0xdc */
  501. /* R_COMMENT. */
  502. { 0, "Ob=Vf=" }, /* 0xdd */
  503. /* R_RESERVED. */
  504. { 0, "" }, /* 0xde */
  505. { 0, "" }, /* 0xdf */
  506. { 0, "" }, /* 0xe0 */
  507. { 0, "" }, /* 0xe1 */
  508. { 0, "" }, /* 0xe2 */
  509. { 0, "" }, /* 0xe3 */
  510. { 0, "" }, /* 0xe4 */
  511. { 0, "" }, /* 0xe5 */
  512. { 0, "" }, /* 0xe6 */
  513. { 0, "" }, /* 0xe7 */
  514. { 0, "" }, /* 0xe8 */
  515. { 0, "" }, /* 0xe9 */
  516. { 0, "" }, /* 0xea */
  517. { 0, "" }, /* 0xeb */
  518. { 0, "" }, /* 0xec */
  519. { 0, "" }, /* 0xed */
  520. { 0, "" }, /* 0xee */
  521. { 0, "" }, /* 0xef */
  522. { 0, "" }, /* 0xf0 */
  523. { 0, "" }, /* 0xf1 */
  524. { 0, "" }, /* 0xf2 */
  525. { 0, "" }, /* 0xf3 */
  526. { 0, "" }, /* 0xf4 */
  527. { 0, "" }, /* 0xf5 */
  528. { 0, "" }, /* 0xf6 */
  529. { 0, "" }, /* 0xf7 */
  530. { 0, "" }, /* 0xf8 */
  531. { 0, "" }, /* 0xf9 */
  532. { 0, "" }, /* 0xfa */
  533. { 0, "" }, /* 0xfb */
  534. { 0, "" }, /* 0xfc */
  535. { 0, "" }, /* 0xfd */
  536. { 0, "" }, /* 0xfe */
  537. { 0, "" }, /* 0xff */
  538. };
  539. static const int comp1_opcodes[] =
  540. {
  541. 0x00,
  542. 0x40,
  543. 0x41,
  544. 0x42,
  545. 0x43,
  546. 0x44,
  547. 0x45,
  548. 0x46,
  549. 0x47,
  550. 0x48,
  551. 0x49,
  552. 0x4a,
  553. 0x4b,
  554. 0x60,
  555. 0x80,
  556. 0xa0,
  557. 0xc0,
  558. -1
  559. };
  560. static const int comp2_opcodes[] =
  561. {
  562. 0x00,
  563. 0x80,
  564. 0x82,
  565. 0xc0,
  566. -1
  567. };
  568. static const int comp3_opcodes[] =
  569. {
  570. 0x00,
  571. 0x02,
  572. -1
  573. };
  574. /* These apparently are not in older versions of hpux reloc.h (hpux7). */
  575. /* And these first appeared in hpux10. */
  576. #ifndef R_SHORT_PCREL_MODE
  577. #define NO_PCREL_MODES
  578. #define R_SHORT_PCREL_MODE 0x3e
  579. #endif
  580. #define SOM_HOWTO(TYPE, NAME) \
  581. HOWTO(TYPE, 0, 0, 32, FALSE, 0, 0, hppa_som_reloc, NAME, FALSE, 0, 0, FALSE)
  582. static reloc_howto_type som_hppa_howto_table[] =
  583. {
  584. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  585. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  586. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  587. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  588. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  589. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  590. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  591. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  592. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  593. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  594. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  595. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  596. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  597. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  598. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  599. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  600. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  601. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  602. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  603. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  604. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  605. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  606. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  607. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  608. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  609. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  610. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  611. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  612. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  613. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  614. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  615. SOM_HOWTO (R_NO_RELOCATION, "R_NO_RELOCATION"),
  616. SOM_HOWTO (R_ZEROES, "R_ZEROES"),
  617. SOM_HOWTO (R_ZEROES, "R_ZEROES"),
  618. SOM_HOWTO (R_UNINIT, "R_UNINIT"),
  619. SOM_HOWTO (R_UNINIT, "R_UNINIT"),
  620. SOM_HOWTO (R_RELOCATION, "R_RELOCATION"),
  621. SOM_HOWTO (R_DATA_ONE_SYMBOL, "R_DATA_ONE_SYMBOL"),
  622. SOM_HOWTO (R_DATA_ONE_SYMBOL, "R_DATA_ONE_SYMBOL"),
  623. SOM_HOWTO (R_DATA_PLABEL, "R_DATA_PLABEL"),
  624. SOM_HOWTO (R_DATA_PLABEL, "R_DATA_PLABEL"),
  625. SOM_HOWTO (R_SPACE_REF, "R_SPACE_REF"),
  626. SOM_HOWTO (R_REPEATED_INIT, "REPEATED_INIT"),
  627. SOM_HOWTO (R_REPEATED_INIT, "REPEATED_INIT"),
  628. SOM_HOWTO (R_REPEATED_INIT, "REPEATED_INIT"),
  629. SOM_HOWTO (R_REPEATED_INIT, "REPEATED_INIT"),
  630. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  631. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  632. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  633. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  634. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  635. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  636. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  637. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  638. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  639. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  640. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  641. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  642. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  643. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  644. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  645. SOM_HOWTO (R_PCREL_CALL, "R_PCREL_CALL"),
  646. SOM_HOWTO (R_SHORT_PCREL_MODE, "R_SHORT_PCREL_MODE"),
  647. SOM_HOWTO (R_LONG_PCREL_MODE, "R_LONG_PCREL_MODE"),
  648. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  649. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  650. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  651. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  652. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  653. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  654. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  655. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  656. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  657. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  658. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  659. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  660. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  661. SOM_HOWTO (R_ABS_CALL, "R_ABS_CALL"),
  662. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  663. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  664. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  665. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  666. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  667. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  668. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  669. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  670. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  671. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  672. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  673. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  674. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  675. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  676. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  677. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  678. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  679. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  680. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  681. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  682. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  683. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  684. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  685. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  686. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  687. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  688. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  689. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  690. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  691. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  692. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  693. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  694. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  695. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  696. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  697. SOM_HOWTO (R_DP_RELATIVE, "R_DP_RELATIVE"),
  698. SOM_HOWTO (R_DATA_GPREL, "R_DATA_GPREL"),
  699. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  700. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  701. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  702. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  703. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  704. SOM_HOWTO (R_DLT_REL, "R_DLT_REL"),
  705. SOM_HOWTO (R_DLT_REL, "R_DLT_REL"),
  706. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  707. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  708. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  709. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  710. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  711. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  712. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  713. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  714. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  715. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  716. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  717. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  718. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  719. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  720. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  721. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  722. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  723. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  724. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  725. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  726. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  727. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  728. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  729. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  730. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  731. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  732. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  733. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  734. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  735. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  736. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  737. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  738. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  739. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  740. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  741. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  742. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  743. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  744. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  745. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  746. SOM_HOWTO (R_CODE_ONE_SYMBOL, "R_CODE_ONE_SYMBOL"),
  747. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  748. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  749. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  750. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  751. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  752. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  753. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  754. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  755. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  756. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  757. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  758. SOM_HOWTO (R_MILLI_REL, "R_MILLI_REL"),
  759. SOM_HOWTO (R_MILLI_REL, "R_MILLI_REL"),
  760. SOM_HOWTO (R_CODE_PLABEL, "R_CODE_PLABEL"),
  761. SOM_HOWTO (R_CODE_PLABEL, "R_CODE_PLABEL"),
  762. SOM_HOWTO (R_BREAKPOINT, "R_BREAKPOINT"),
  763. SOM_HOWTO (R_ENTRY, "R_ENTRY"),
  764. SOM_HOWTO (R_ENTRY, "R_ENTRY"),
  765. SOM_HOWTO (R_ALT_ENTRY, "R_ALT_ENTRY"),
  766. SOM_HOWTO (R_EXIT, "R_EXIT"),
  767. SOM_HOWTO (R_BEGIN_TRY, "R_BEGIN_TRY"),
  768. SOM_HOWTO (R_END_TRY, "R_END_TRY"),
  769. SOM_HOWTO (R_END_TRY, "R_END_TRY"),
  770. SOM_HOWTO (R_END_TRY, "R_END_TRY"),
  771. SOM_HOWTO (R_BEGIN_BRTAB, "R_BEGIN_BRTAB"),
  772. SOM_HOWTO (R_END_BRTAB, "R_END_BRTAB"),
  773. SOM_HOWTO (R_STATEMENT, "R_STATEMENT"),
  774. SOM_HOWTO (R_STATEMENT, "R_STATEMENT"),
  775. SOM_HOWTO (R_STATEMENT, "R_STATEMENT"),
  776. SOM_HOWTO (R_DATA_EXPR, "R_DATA_EXPR"),
  777. SOM_HOWTO (R_CODE_EXPR, "R_CODE_EXPR"),
  778. SOM_HOWTO (R_FSEL, "R_FSEL"),
  779. SOM_HOWTO (R_LSEL, "R_LSEL"),
  780. SOM_HOWTO (R_RSEL, "R_RSEL"),
  781. SOM_HOWTO (R_N_MODE, "R_N_MODE"),
  782. SOM_HOWTO (R_S_MODE, "R_S_MODE"),
  783. SOM_HOWTO (R_D_MODE, "R_D_MODE"),
  784. SOM_HOWTO (R_R_MODE, "R_R_MODE"),
  785. SOM_HOWTO (R_DATA_OVERRIDE, "R_DATA_OVERRIDE"),
  786. SOM_HOWTO (R_DATA_OVERRIDE, "R_DATA_OVERRIDE"),
  787. SOM_HOWTO (R_DATA_OVERRIDE, "R_DATA_OVERRIDE"),
  788. SOM_HOWTO (R_DATA_OVERRIDE, "R_DATA_OVERRIDE"),
  789. SOM_HOWTO (R_DATA_OVERRIDE, "R_DATA_OVERRIDE"),
  790. SOM_HOWTO (R_TRANSLATED, "R_TRANSLATED"),
  791. SOM_HOWTO (R_AUX_UNWIND, "R_AUX_UNWIND"),
  792. SOM_HOWTO (R_COMP1, "R_COMP1"),
  793. SOM_HOWTO (R_COMP2, "R_COMP2"),
  794. SOM_HOWTO (R_COMP3, "R_COMP3"),
  795. SOM_HOWTO (R_PREV_FIXUP, "R_PREV_FIXUP"),
  796. SOM_HOWTO (R_PREV_FIXUP, "R_PREV_FIXUP"),
  797. SOM_HOWTO (R_PREV_FIXUP, "R_PREV_FIXUP"),
  798. SOM_HOWTO (R_PREV_FIXUP, "R_PREV_FIXUP"),
  799. SOM_HOWTO (R_SEC_STMT, "R_SEC_STMT"),
  800. SOM_HOWTO (R_N0SEL, "R_N0SEL"),
  801. SOM_HOWTO (R_N1SEL, "R_N1SEL"),
  802. SOM_HOWTO (R_LINETAB, "R_LINETAB"),
  803. SOM_HOWTO (R_LINETAB_ESC, "R_LINETAB_ESC"),
  804. SOM_HOWTO (R_LTP_OVERRIDE, "R_LTP_OVERRIDE"),
  805. SOM_HOWTO (R_COMMENT, "R_COMMENT"),
  806. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  807. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  808. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  809. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  810. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  811. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  812. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  813. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  814. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  815. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  816. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  817. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  818. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  819. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  820. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  821. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  822. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  823. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  824. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  825. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  826. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  827. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  828. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  829. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  830. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  831. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  832. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  833. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  834. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  835. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  836. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  837. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  838. SOM_HOWTO (R_RESERVED, "R_RESERVED"),
  839. SOM_HOWTO (R_RESERVED, "R_RESERVED")
  840. };
  841. /* Initialize the SOM relocation queue. By definition the queue holds
  842. the last four multibyte fixups. */
  843. static void
  844. som_initialize_reloc_queue (struct reloc_queue *queue)
  845. {
  846. queue[0].reloc = NULL;
  847. queue[0].size = 0;
  848. queue[1].reloc = NULL;
  849. queue[1].size = 0;
  850. queue[2].reloc = NULL;
  851. queue[2].size = 0;
  852. queue[3].reloc = NULL;
  853. queue[3].size = 0;
  854. }
  855. /* Insert a new relocation into the relocation queue. */
  856. static void
  857. som_reloc_queue_insert (unsigned char *p,
  858. unsigned int size,
  859. struct reloc_queue *queue)
  860. {
  861. queue[3].reloc = queue[2].reloc;
  862. queue[3].size = queue[2].size;
  863. queue[2].reloc = queue[1].reloc;
  864. queue[2].size = queue[1].size;
  865. queue[1].reloc = queue[0].reloc;
  866. queue[1].size = queue[0].size;
  867. queue[0].reloc = p;
  868. queue[0].size = size;
  869. }
  870. /* When an entry in the relocation queue is reused, the entry moves
  871. to the front of the queue. */
  872. static void
  873. som_reloc_queue_fix (struct reloc_queue *queue, unsigned int idx)
  874. {
  875. if (idx == 0)
  876. return;
  877. if (idx == 1)
  878. {
  879. unsigned char *tmp1 = queue[0].reloc;
  880. unsigned int tmp2 = queue[0].size;
  881. queue[0].reloc = queue[1].reloc;
  882. queue[0].size = queue[1].size;
  883. queue[1].reloc = tmp1;
  884. queue[1].size = tmp2;
  885. return;
  886. }
  887. if (idx == 2)
  888. {
  889. unsigned char *tmp1 = queue[0].reloc;
  890. unsigned int tmp2 = queue[0].size;
  891. queue[0].reloc = queue[2].reloc;
  892. queue[0].size = queue[2].size;
  893. queue[2].reloc = queue[1].reloc;
  894. queue[2].size = queue[1].size;
  895. queue[1].reloc = tmp1;
  896. queue[1].size = tmp2;
  897. return;
  898. }
  899. if (idx == 3)
  900. {
  901. unsigned char *tmp1 = queue[0].reloc;
  902. unsigned int tmp2 = queue[0].size;
  903. queue[0].reloc = queue[3].reloc;
  904. queue[0].size = queue[3].size;
  905. queue[3].reloc = queue[2].reloc;
  906. queue[3].size = queue[2].size;
  907. queue[2].reloc = queue[1].reloc;
  908. queue[2].size = queue[1].size;
  909. queue[1].reloc = tmp1;
  910. queue[1].size = tmp2;
  911. return;
  912. }
  913. abort ();
  914. }
  915. /* Search for a particular relocation in the relocation queue. */
  916. static int
  917. som_reloc_queue_find (unsigned char *p,
  918. unsigned int size,
  919. struct reloc_queue *queue)
  920. {
  921. if (queue[0].reloc && !memcmp (p, queue[0].reloc, size)
  922. && size == queue[0].size)
  923. return 0;
  924. if (queue[1].reloc && !memcmp (p, queue[1].reloc, size)
  925. && size == queue[1].size)
  926. return 1;
  927. if (queue[2].reloc && !memcmp (p, queue[2].reloc, size)
  928. && size == queue[2].size)
  929. return 2;
  930. if (queue[3].reloc && !memcmp (p, queue[3].reloc, size)
  931. && size == queue[3].size)
  932. return 3;
  933. return -1;
  934. }
  935. static unsigned char *
  936. try_prev_fixup (bfd *abfd ATTRIBUTE_UNUSED,
  937. unsigned int *subspace_reloc_sizep,
  938. unsigned char *p,
  939. unsigned int size,
  940. struct reloc_queue *queue)
  941. {
  942. int queue_index = som_reloc_queue_find (p, size, queue);
  943. if (queue_index != -1)
  944. {
  945. /* Found this in a previous fixup. Undo the fixup we
  946. just built and use R_PREV_FIXUP instead. We saved
  947. a total of size - 1 bytes in the fixup stream. */
  948. bfd_put_8 (abfd, R_PREV_FIXUP + queue_index, p);
  949. p += 1;
  950. *subspace_reloc_sizep += 1;
  951. som_reloc_queue_fix (queue, queue_index);
  952. }
  953. else
  954. {
  955. som_reloc_queue_insert (p, size, queue);
  956. *subspace_reloc_sizep += size;
  957. p += size;
  958. }
  959. return p;
  960. }
  961. /* Emit the proper R_NO_RELOCATION fixups to map the next SKIP
  962. bytes without any relocation. Update the size of the subspace
  963. relocation stream via SUBSPACE_RELOC_SIZE_P; also return the
  964. current pointer into the relocation stream. */
  965. static unsigned char *
  966. som_reloc_skip (bfd *abfd,
  967. unsigned int skip,
  968. unsigned char *p,
  969. unsigned int *subspace_reloc_sizep,
  970. struct reloc_queue *queue)
  971. {
  972. /* Use a 4 byte R_NO_RELOCATION entry with a maximal value
  973. then R_PREV_FIXUPs to get the difference down to a
  974. reasonable size. */
  975. if (skip >= 0x1000000)
  976. {
  977. skip -= 0x1000000;
  978. bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
  979. bfd_put_8 (abfd, 0xff, p + 1);
  980. bfd_put_16 (abfd, (bfd_vma) 0xffff, p + 2);
  981. p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
  982. while (skip >= 0x1000000)
  983. {
  984. skip -= 0x1000000;
  985. bfd_put_8 (abfd, R_PREV_FIXUP, p);
  986. p++;
  987. *subspace_reloc_sizep += 1;
  988. /* No need to adjust queue here since we are repeating the
  989. most recent fixup. */
  990. }
  991. }
  992. /* The difference must be less than 0x1000000. Use one
  993. more R_NO_RELOCATION entry to get to the right difference. */
  994. if ((skip & 3) == 0 && skip <= 0xc0000 && skip > 0)
  995. {
  996. /* Difference can be handled in a simple single-byte
  997. R_NO_RELOCATION entry. */
  998. if (skip <= 0x60)
  999. {
  1000. bfd_put_8 (abfd, R_NO_RELOCATION + (skip >> 2) - 1, p);
  1001. *subspace_reloc_sizep += 1;
  1002. p++;
  1003. }
  1004. /* Handle it with a two byte R_NO_RELOCATION entry. */
  1005. else if (skip <= 0x1000)
  1006. {
  1007. bfd_put_8 (abfd, R_NO_RELOCATION + 24 + (((skip >> 2) - 1) >> 8), p);
  1008. bfd_put_8 (abfd, (skip >> 2) - 1, p + 1);
  1009. p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
  1010. }
  1011. /* Handle it with a three byte R_NO_RELOCATION entry. */
  1012. else
  1013. {
  1014. bfd_put_8 (abfd, R_NO_RELOCATION + 28 + (((skip >> 2) - 1) >> 16), p);
  1015. bfd_put_16 (abfd, (bfd_vma) (skip >> 2) - 1, p + 1);
  1016. p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
  1017. }
  1018. }
  1019. /* Ugh. Punt and use a 4 byte entry. */
  1020. else if (skip > 0)
  1021. {
  1022. bfd_put_8 (abfd, R_NO_RELOCATION + 31, p);
  1023. bfd_put_8 (abfd, (skip - 1) >> 16, p + 1);
  1024. bfd_put_16 (abfd, (bfd_vma) skip - 1, p + 2);
  1025. p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
  1026. }
  1027. return p;
  1028. }
  1029. /* Emit the proper R_DATA_OVERRIDE fixups to handle a nonzero addend
  1030. from a BFD relocation. Update the size of the subspace relocation
  1031. stream via SUBSPACE_RELOC_SIZE_P; also return the current pointer
  1032. into the relocation stream. */
  1033. static unsigned char *
  1034. som_reloc_addend (bfd *abfd,
  1035. bfd_vma addend,
  1036. unsigned char *p,
  1037. unsigned int *subspace_reloc_sizep,
  1038. struct reloc_queue *queue)
  1039. {
  1040. if (addend + 0x80 < 0x100)
  1041. {
  1042. bfd_put_8 (abfd, R_DATA_OVERRIDE + 1, p);
  1043. bfd_put_8 (abfd, addend, p + 1);
  1044. p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
  1045. }
  1046. else if (addend + 0x8000 < 0x10000)
  1047. {
  1048. bfd_put_8 (abfd, R_DATA_OVERRIDE + 2, p);
  1049. bfd_put_16 (abfd, addend, p + 1);
  1050. p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
  1051. }
  1052. else if (addend + 0x800000 < 0x1000000)
  1053. {
  1054. bfd_put_8 (abfd, R_DATA_OVERRIDE + 3, p);
  1055. bfd_put_8 (abfd, addend >> 16, p + 1);
  1056. bfd_put_16 (abfd, addend, p + 2);
  1057. p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 4, queue);
  1058. }
  1059. else
  1060. {
  1061. bfd_put_8 (abfd, R_DATA_OVERRIDE + 4, p);
  1062. bfd_put_32 (abfd, addend, p + 1);
  1063. p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
  1064. }
  1065. return p;
  1066. }
  1067. /* Handle a single function call relocation. */
  1068. static unsigned char *
  1069. som_reloc_call (bfd *abfd,
  1070. unsigned char *p,
  1071. unsigned int *subspace_reloc_sizep,
  1072. arelent *bfd_reloc,
  1073. int sym_num,
  1074. struct reloc_queue *queue)
  1075. {
  1076. int arg_bits = HPPA_R_ARG_RELOC (bfd_reloc->addend);
  1077. int rtn_bits = arg_bits & 0x3;
  1078. int type, done = 0;
  1079. /* You'll never believe all this is necessary to handle relocations
  1080. for function calls. Having to compute and pack the argument
  1081. relocation bits is the real nightmare.
  1082. If you're interested in how this works, just forget it. You really
  1083. do not want to know about this braindamage. */
  1084. /* First see if this can be done with a "simple" relocation. Simple
  1085. relocations have a symbol number < 0x100 and have simple encodings
  1086. of argument relocations. */
  1087. if (sym_num < 0x100)
  1088. {
  1089. switch (arg_bits)
  1090. {
  1091. case 0:
  1092. case 1:
  1093. type = 0;
  1094. break;
  1095. case 1 << 8:
  1096. case 1 << 8 | 1:
  1097. type = 1;
  1098. break;
  1099. case 1 << 8 | 1 << 6:
  1100. case 1 << 8 | 1 << 6 | 1:
  1101. type = 2;
  1102. break;
  1103. case 1 << 8 | 1 << 6 | 1 << 4:
  1104. case 1 << 8 | 1 << 6 | 1 << 4 | 1:
  1105. type = 3;
  1106. break;
  1107. case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2:
  1108. case 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2 | 1:
  1109. type = 4;
  1110. break;
  1111. default:
  1112. /* Not one of the easy encodings. This will have to be
  1113. handled by the more complex code below. */
  1114. type = -1;
  1115. break;
  1116. }
  1117. if (type != -1)
  1118. {
  1119. /* Account for the return value too. */
  1120. if (rtn_bits)
  1121. type += 5;
  1122. /* Emit a 2 byte relocation. Then see if it can be handled
  1123. with a relocation which is already in the relocation queue. */
  1124. bfd_put_8 (abfd, bfd_reloc->howto->type + type, p);
  1125. bfd_put_8 (abfd, sym_num, p + 1);
  1126. p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 2, queue);
  1127. done = 1;
  1128. }
  1129. }
  1130. /* If this could not be handled with a simple relocation, then do a hard
  1131. one. Hard relocations occur if the symbol number was too high or if
  1132. the encoding of argument relocation bits is too complex. */
  1133. if (! done)
  1134. {
  1135. /* Don't ask about these magic sequences. I took them straight
  1136. from gas-1.36 which took them from the a.out man page. */
  1137. type = rtn_bits;
  1138. if ((arg_bits >> 6 & 0xf) == 0xe)
  1139. type += 9 * 40;
  1140. else
  1141. type += (3 * (arg_bits >> 8 & 3) + (arg_bits >> 6 & 3)) * 40;
  1142. if ((arg_bits >> 2 & 0xf) == 0xe)
  1143. type += 9 * 4;
  1144. else
  1145. type += (3 * (arg_bits >> 4 & 3) + (arg_bits >> 2 & 3)) * 4;
  1146. /* Output the first two bytes of the relocation. These describe
  1147. the length of the relocation and encoding style. */
  1148. bfd_put_8 (abfd, bfd_reloc->howto->type + 10
  1149. + 2 * (sym_num >= 0x100) + (type >= 0x100),
  1150. p);
  1151. bfd_put_8 (abfd, type, p + 1);
  1152. /* Now output the symbol index and see if this bizarre relocation
  1153. just happened to be in the relocation queue. */
  1154. if (sym_num < 0x100)
  1155. {
  1156. bfd_put_8 (abfd, sym_num, p + 2);
  1157. p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 3, queue);
  1158. }
  1159. else
  1160. {
  1161. bfd_put_8 (abfd, sym_num >> 16, p + 2);
  1162. bfd_put_16 (abfd, (bfd_vma) sym_num, p + 3);
  1163. p = try_prev_fixup (abfd, subspace_reloc_sizep, p, 5, queue);
  1164. }
  1165. }
  1166. return p;
  1167. }
  1168. /* Return the logarithm of X, base 2, considering X unsigned,
  1169. if X is a power of 2. Otherwise, returns -1. */
  1170. static int
  1171. exact_log2 (unsigned int x)
  1172. {
  1173. int log = 0;
  1174. /* Test for 0 or a power of 2. */
  1175. if (x == 0 || x != (x & -x))
  1176. return -1;
  1177. while ((x >>= 1) != 0)
  1178. log++;
  1179. return log;
  1180. }
  1181. static bfd_reloc_status_type
  1182. hppa_som_reloc (bfd *abfd ATTRIBUTE_UNUSED,
  1183. arelent *reloc_entry,
  1184. asymbol *symbol_in ATTRIBUTE_UNUSED,
  1185. void *data ATTRIBUTE_UNUSED,
  1186. asection *input_section,
  1187. bfd *output_bfd,
  1188. char **error_message ATTRIBUTE_UNUSED)
  1189. {
  1190. if (output_bfd)
  1191. reloc_entry->address += input_section->output_offset;
  1192. return bfd_reloc_ok;
  1193. }
  1194. /* Given a generic HPPA relocation type, the instruction format,
  1195. and a field selector, return one or more appropriate SOM relocations. */
  1196. int **
  1197. hppa_som_gen_reloc_type (bfd *abfd,
  1198. int base_type,
  1199. int format,
  1200. enum hppa_reloc_field_selector_type_alt field,
  1201. int sym_diff,
  1202. asymbol *sym)
  1203. {
  1204. int *final_type, **final_types;
  1205. final_types = bfd_alloc (abfd, (bfd_size_type) sizeof (int *) * 6);
  1206. final_type = bfd_alloc (abfd, (bfd_size_type) sizeof (int));
  1207. if (!final_types || !final_type)
  1208. return NULL;
  1209. /* The field selector may require additional relocations to be
  1210. generated. It's impossible to know at this moment if additional
  1211. relocations will be needed, so we make them. The code to actually
  1212. write the relocation/fixup stream is responsible for removing
  1213. any redundant relocations. */
  1214. switch (field)
  1215. {
  1216. case e_fsel:
  1217. case e_psel:
  1218. case e_lpsel:
  1219. case e_rpsel:
  1220. final_types[0] = final_type;
  1221. final_types[1] = NULL;
  1222. final_types[2] = NULL;
  1223. *final_type = base_type;
  1224. break;
  1225. case e_tsel:
  1226. case e_ltsel:
  1227. case e_rtsel:
  1228. final_types[0] = bfd_alloc (abfd, (bfd_size_type) sizeof (int));
  1229. if (!final_types[0])
  1230. return NULL;
  1231. if (field == e_tsel)
  1232. *final_types[0] = R_FSEL;
  1233. else if (field == e_ltsel)
  1234. *final_types[0] = R_LSEL;
  1235. else
  1236. *final_types[0] = R_RSEL;
  1237. final_types[1] = final_type;
  1238. final_types[2] = NULL;
  1239. *final_type = base_type;
  1240. break;
  1241. case e_lssel:
  1242. case e_rssel:
  1243. final_types[0] = bfd_alloc (abfd, (bfd_size_type) sizeof (int));
  1244. if (!final_types[0])
  1245. return NULL;
  1246. *final_types[0] = R_S_MODE;
  1247. final_types[1] = final_type;
  1248. final_types[2] = NULL;
  1249. *final_type = base_type;
  1250. break;
  1251. case e_lsel:
  1252. case e_rsel:
  1253. final_types[0] = bfd_alloc (abfd, (bfd_size_type) sizeof (int));
  1254. if (!final_types[0])
  1255. return NULL;
  1256. *final_types[0] = R_N_MODE;
  1257. final_types[1] = final_type;
  1258. final_types[2] = NULL;
  1259. *final_type = base_type;
  1260. break;
  1261. case e_ldsel:
  1262. case e_rdsel:
  1263. final_types[0] = bfd_alloc (abfd, (bfd_size_type) sizeof (int));
  1264. if (!final_types[0])
  1265. return NULL;
  1266. *final_types[0] = R_D_MODE;
  1267. final_types[1] = final_type;
  1268. final_types[2] = NULL;
  1269. *final_type = base_type;
  1270. break;
  1271. case e_lrsel:
  1272. case e_rrsel:
  1273. final_types[0] = bfd_alloc (abfd, (bfd_size_type) sizeof (int));
  1274. if (!final_types[0])
  1275. return NULL;
  1276. *final_types[0] = R_R_MODE;
  1277. final_types[1] = final_type;
  1278. final_types[2] = NULL;
  1279. *final_type = base_type;
  1280. break;
  1281. case e_nsel:
  1282. final_types[0] = bfd_alloc (abfd, (bfd_size_type) sizeof (int));
  1283. if (!final_types[0])
  1284. return NULL;
  1285. *final_types[0] = R_N1SEL;
  1286. final_types[1] = final_type;
  1287. final_types[2] = NULL;
  1288. *final_type = base_type;
  1289. break;
  1290. case e_nlsel:
  1291. case e_nlrsel:
  1292. final_types[0] = bfd_alloc (abfd, (bfd_size_type) sizeof (int));
  1293. if (!final_types[0])
  1294. return NULL;
  1295. *final_types[0] = R_N0SEL;
  1296. final_types[1] = bfd_alloc (abfd, (bfd_size_type) sizeof (int));
  1297. if (!final_types[1])
  1298. return NULL;
  1299. if (field == e_nlsel)
  1300. *final_types[1] = R_N_MODE;
  1301. else
  1302. *final_types[1] = R_R_MODE;
  1303. final_types[2] = final_type;
  1304. final_types[3] = NULL;
  1305. *final_type = base_type;
  1306. break;
  1307. /* FIXME: These two field selectors are not currently supported. */
  1308. case e_ltpsel:
  1309. case e_rtpsel:
  1310. abort ();
  1311. }
  1312. switch (base_type)
  1313. {
  1314. case R_HPPA:
  1315. /* The difference of two symbols needs *very* special handling. */
  1316. if (sym_diff)
  1317. {
  1318. bfd_size_type amt = sizeof (int);
  1319. final_types[0] = bfd_alloc (abfd, amt);
  1320. final_types[1] = bfd_alloc (abfd, amt);
  1321. final_types[2] = bfd_alloc (abfd, amt);
  1322. final_types[3] = bfd_alloc (abfd, amt);
  1323. if (!final_types[0] || !final_types[1] || !final_types[2])
  1324. return NULL;
  1325. if (field == e_fsel)
  1326. *final_types[0] = R_FSEL;
  1327. else if (field == e_rsel)
  1328. *final_types[0] = R_RSEL;
  1329. else if (field == e_lsel)
  1330. *final_types[0] = R_LSEL;
  1331. *final_types[1] = R_COMP2;
  1332. *final_types[2] = R_COMP2;
  1333. *final_types[3] = R_COMP1;
  1334. final_types[4] = final_type;
  1335. if (format == 32)
  1336. *final_types[4] = R_DATA_EXPR;
  1337. else
  1338. *final_types[4] = R_CODE_EXPR;
  1339. final_types[5] = NULL;
  1340. break;
  1341. }
  1342. /* PLABELs get their own relocation type. */
  1343. else if (field == e_psel
  1344. || field == e_lpsel
  1345. || field == e_rpsel)
  1346. {
  1347. /* A PLABEL relocation that has a size of 32 bits must
  1348. be a R_DATA_PLABEL. All others are R_CODE_PLABELs. */
  1349. if (format == 32)
  1350. *final_type = R_DATA_PLABEL;
  1351. else
  1352. *final_type = R_CODE_PLABEL;
  1353. }
  1354. /* PIC stuff. */
  1355. else if (field == e_tsel
  1356. || field == e_ltsel
  1357. || field == e_rtsel)
  1358. *final_type = R_DLT_REL;
  1359. /* A relocation in the data space is always a full 32bits. */
  1360. else if (format == 32)
  1361. {
  1362. *final_type = R_DATA_ONE_SYMBOL;
  1363. /* If there's no SOM symbol type associated with this BFD
  1364. symbol, then set the symbol type to ST_DATA.
  1365. Only do this if the type is going to default later when
  1366. we write the object file.
  1367. This is done so that the linker never encounters an
  1368. R_DATA_ONE_SYMBOL reloc involving an ST_CODE symbol.
  1369. This allows the compiler to generate exception handling
  1370. tables.
  1371. Note that one day we may need to also emit BEGIN_BRTAB and
  1372. END_BRTAB to prevent the linker from optimizing away insns
  1373. in exception handling regions. */
  1374. if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_UNKNOWN
  1375. && (sym->flags & BSF_SECTION_SYM) == 0
  1376. && (sym->flags & BSF_FUNCTION) == 0
  1377. && ! bfd_is_com_section (sym->section))
  1378. som_symbol_data (sym)->som_type = SYMBOL_TYPE_DATA;
  1379. }
  1380. break;
  1381. case R_HPPA_GOTOFF:
  1382. /* More PLABEL special cases. */
  1383. if (field == e_psel
  1384. || field == e_lpsel
  1385. || field == e_rpsel)
  1386. *final_type = R_DATA_PLABEL;
  1387. else if (field == e_fsel && format == 32)
  1388. *final_type = R_DATA_GPREL;
  1389. break;
  1390. case R_HPPA_COMPLEX:
  1391. /* The difference of two symbols needs *very* special handling. */
  1392. if (sym_diff)
  1393. {
  1394. bfd_size_type amt = sizeof (int);
  1395. final_types[0] = bfd_alloc (abfd, amt);
  1396. final_types[1] = bfd_alloc (abfd, amt);
  1397. final_types[2] = bfd_alloc (abfd, amt);
  1398. final_types[3] = bfd_alloc (abfd, amt);
  1399. if (!final_types[0] || !final_types[1] || !final_types[2])
  1400. return NULL;
  1401. if (field == e_fsel)
  1402. *final_types[0] = R_FSEL;
  1403. else if (field == e_rsel)
  1404. *final_types[0] = R_RSEL;
  1405. else if (field == e_lsel)
  1406. *final_types[0] = R_LSEL;
  1407. *final_types[1] = R_COMP2;
  1408. *final_types[2] = R_COMP2;
  1409. *final_types[3] = R_COMP1;
  1410. final_types[4] = final_type;
  1411. if (format == 32)
  1412. *final_types[4] = R_DATA_EXPR;
  1413. else
  1414. *final_types[4] = R_CODE_EXPR;
  1415. final_types[5] = NULL;
  1416. break;
  1417. }
  1418. else
  1419. break;
  1420. case R_HPPA_NONE:
  1421. case R_HPPA_ABS_CALL:
  1422. /* Right now we can default all these. */
  1423. break;
  1424. case R_HPPA_PCREL_CALL:
  1425. {
  1426. #ifndef NO_PCREL_MODES
  1427. /* If we have short and long pcrel modes, then generate the proper
  1428. mode selector, then the pcrel relocation. Redundant selectors
  1429. will be eliminated as the relocs are sized and emitted. */
  1430. bfd_size_type amt = sizeof (int);
  1431. final_types[0] = bfd_alloc (abfd, amt);
  1432. if (!final_types[0])
  1433. return NULL;
  1434. if (format == 17)
  1435. *final_types[0] = R_SHORT_PCREL_MODE;
  1436. else
  1437. *final_types[0] = R_LONG_PCREL_MODE;
  1438. final_types[1] = final_type;
  1439. final_types[2] = NULL;
  1440. *final_type = base_type;
  1441. #endif
  1442. break;
  1443. }
  1444. }
  1445. return final_types;
  1446. }
  1447. /* Return the address of the correct entry in the PA SOM relocation
  1448. howto table. */
  1449. static reloc_howto_type *
  1450. som_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1451. bfd_reloc_code_real_type code)
  1452. {
  1453. if ((int) code < (int) R_NO_RELOCATION + 255)
  1454. {
  1455. BFD_ASSERT ((int) som_hppa_howto_table[(int) code].type == (int) code);
  1456. return &som_hppa_howto_table[(int) code];
  1457. }
  1458. return NULL;
  1459. }
  1460. static reloc_howto_type *
  1461. som_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1462. const char *r_name)
  1463. {
  1464. unsigned int i;
  1465. for (i = 0;
  1466. i < sizeof (som_hppa_howto_table) / sizeof (som_hppa_howto_table[0]);
  1467. i++)
  1468. if (som_hppa_howto_table[i].name != NULL
  1469. && strcasecmp (som_hppa_howto_table[i].name, r_name) == 0)
  1470. return &som_hppa_howto_table[i];
  1471. return NULL;
  1472. }
  1473. static void
  1474. som_swap_clock_in (struct som_external_clock *src,
  1475. struct som_clock *dst)
  1476. {
  1477. dst->secs = bfd_getb32 (src->secs);
  1478. dst->nanosecs = bfd_getb32 (src->nanosecs);
  1479. }
  1480. static void
  1481. som_swap_clock_out (struct som_clock *src,
  1482. struct som_external_clock *dst)
  1483. {
  1484. bfd_putb32 (src->secs, dst->secs);
  1485. bfd_putb32 (src->nanosecs, dst->nanosecs);
  1486. }
  1487. static void
  1488. som_swap_header_in (struct som_external_header *src,
  1489. struct som_header *dst)
  1490. {
  1491. dst->system_id = bfd_getb16 (src->system_id);
  1492. dst->a_magic = bfd_getb16 (src->a_magic);
  1493. dst->version_id = bfd_getb32 (src->version_id);
  1494. som_swap_clock_in (&src->file_time, &dst->file_time);
  1495. dst->entry_space = bfd_getb32 (src->entry_space);
  1496. dst->entry_subspace = bfd_getb32 (src->entry_subspace);
  1497. dst->entry_offset = bfd_getb32 (src->entry_offset);
  1498. dst->aux_header_location = bfd_getb32 (src->aux_header_location);
  1499. dst->aux_header_size = bfd_getb32 (src->aux_header_size);
  1500. dst->som_length = bfd_getb32 (src->som_length);
  1501. dst->presumed_dp = bfd_getb32 (src->presumed_dp);
  1502. dst->space_location = bfd_getb32 (src->space_location);
  1503. dst->space_total = bfd_getb32 (src->space_total);
  1504. dst->subspace_location = bfd_getb32 (src->subspace_location);
  1505. dst->subspace_total = bfd_getb32 (src->subspace_total);
  1506. dst->loader_fixup_location = bfd_getb32 (src->loader_fixup_location);
  1507. dst->loader_fixup_total = bfd_getb32 (src->loader_fixup_total);
  1508. dst->space_strings_location = bfd_getb32 (src->space_strings_location);
  1509. dst->space_strings_size = bfd_getb32 (src->space_strings_size);
  1510. dst->init_array_location = bfd_getb32 (src->init_array_location);
  1511. dst->init_array_total = bfd_getb32 (src->init_array_total);
  1512. dst->compiler_location = bfd_getb32 (src->compiler_location);
  1513. dst->compiler_total = bfd_getb32 (src->compiler_total);
  1514. dst->symbol_location = bfd_getb32 (src->symbol_location);
  1515. dst->symbol_total = bfd_getb32 (src->symbol_total);
  1516. dst->fixup_request_location = bfd_getb32 (src->fixup_request_location);
  1517. dst->fixup_request_total = bfd_getb32 (src->fixup_request_total);
  1518. dst->symbol_strings_location = bfd_getb32 (src->symbol_strings_location);
  1519. dst->symbol_strings_size = bfd_getb32 (src->symbol_strings_size);
  1520. dst->unloadable_sp_location = bfd_getb32 (src->unloadable_sp_location);
  1521. dst->unloadable_sp_size = bfd_getb32 (src->unloadable_sp_size);
  1522. dst->checksum = bfd_getb32 (src->checksum);
  1523. }
  1524. static void
  1525. som_swap_header_out (struct som_header *src,
  1526. struct som_external_header *dst)
  1527. {
  1528. bfd_putb16 (src->system_id, dst->system_id);
  1529. bfd_putb16 (src->a_magic, dst->a_magic);
  1530. bfd_putb32 (src->version_id, dst->version_id);
  1531. som_swap_clock_out (&src->file_time, &dst->file_time);
  1532. bfd_putb32 (src->entry_space, dst->entry_space);
  1533. bfd_putb32 (src->entry_subspace, dst->entry_subspace);
  1534. bfd_putb32 (src->entry_offset, dst->entry_offset);
  1535. bfd_putb32 (src->aux_header_location, dst->aux_header_location);
  1536. bfd_putb32 (src->aux_header_size, dst->aux_header_size);
  1537. bfd_putb32 (src->som_length, dst->som_length);
  1538. bfd_putb32 (src->presumed_dp, dst->presumed_dp);
  1539. bfd_putb32 (src->space_location, dst->space_location);
  1540. bfd_putb32 (src->space_total, dst->space_total);
  1541. bfd_putb32 (src->subspace_location, dst->subspace_location);
  1542. bfd_putb32 (src->subspace_total, dst->subspace_total);
  1543. bfd_putb32 (src->loader_fixup_location, dst->loader_fixup_location);
  1544. bfd_putb32 (src->loader_fixup_total, dst->loader_fixup_total);
  1545. bfd_putb32 (src->space_strings_location, dst->space_strings_location);
  1546. bfd_putb32 (src->space_strings_size, dst->space_strings_size);
  1547. bfd_putb32 (src->init_array_location, dst->init_array_location);
  1548. bfd_putb32 (src->init_array_total, dst->init_array_total);
  1549. bfd_putb32 (src->compiler_location, dst->compiler_location);
  1550. bfd_putb32 (src->compiler_total, dst->compiler_total);
  1551. bfd_putb32 (src->symbol_location, dst->symbol_location);
  1552. bfd_putb32 (src->symbol_total, dst->symbol_total);
  1553. bfd_putb32 (src->fixup_request_location, dst->fixup_request_location);
  1554. bfd_putb32 (src->fixup_request_total, dst->fixup_request_total);
  1555. bfd_putb32 (src->symbol_strings_location, dst->symbol_strings_location);
  1556. bfd_putb32 (src->symbol_strings_size, dst->symbol_strings_size);
  1557. bfd_putb32 (src->unloadable_sp_location, dst->unloadable_sp_location);
  1558. bfd_putb32 (src->unloadable_sp_size, dst->unloadable_sp_size);
  1559. bfd_putb32 (src->checksum, dst->checksum);
  1560. }
  1561. static void
  1562. som_swap_space_dictionary_in (struct som_external_space_dictionary_record *src,
  1563. struct som_space_dictionary_record *dst)
  1564. {
  1565. unsigned int flags;
  1566. dst->name = bfd_getb32 (src->name);
  1567. flags = bfd_getb32 (src->flags);
  1568. dst->is_loadable = (flags & SOM_SPACE_IS_LOADABLE) != 0;
  1569. dst->is_defined = (flags & SOM_SPACE_IS_DEFINED) != 0;
  1570. dst->is_private = (flags & SOM_SPACE_IS_PRIVATE) != 0;
  1571. dst->has_intermediate_code = (flags & SOM_SPACE_HAS_INTERMEDIATE_CODE) != 0;
  1572. dst->is_tspecific = (flags & SOM_SPACE_IS_TSPECIFIC) != 0;
  1573. dst->reserved = 0;
  1574. dst->sort_key = (flags >> SOM_SPACE_SORT_KEY_SH) & SOM_SPACE_SORT_KEY_MASK;
  1575. dst->reserved2 = 0;
  1576. dst->space_number = bfd_getb32 (src->space_number);
  1577. dst->subspace_index = bfd_getb32 (src->subspace_index);
  1578. dst->subspace_quantity = bfd_getb32 (src->subspace_quantity);
  1579. dst->loader_fix_index = bfd_getb32 (src->loader_fix_index);
  1580. dst->loader_fix_quantity = bfd_getb32 (src->loader_fix_quantity);
  1581. dst->init_pointer_index = bfd_getb32 (src->init_pointer_index);
  1582. dst->init_pointer_quantity = bfd_getb32 (src->init_pointer_quantity);
  1583. }
  1584. static void
  1585. som_swap_space_dictionary_out (struct som_space_dictionary_record *src,
  1586. struct som_external_space_dictionary_record *dst)
  1587. {
  1588. unsigned int flags;
  1589. bfd_putb32 (src->name, dst->name);
  1590. flags = 0;
  1591. if (src->is_loadable)
  1592. flags |= SOM_SPACE_IS_LOADABLE;
  1593. if (src->is_defined)
  1594. flags |= SOM_SPACE_IS_DEFINED;
  1595. if (src->is_private)
  1596. flags |= SOM_SPACE_IS_PRIVATE;
  1597. if (src->has_intermediate_code)
  1598. flags |= SOM_SPACE_HAS_INTERMEDIATE_CODE;
  1599. if (src->is_tspecific)
  1600. flags |= SOM_SPACE_IS_TSPECIFIC;
  1601. flags |= (src->sort_key & SOM_SPACE_SORT_KEY_MASK) << SOM_SPACE_SORT_KEY_SH;
  1602. bfd_putb32 (flags, dst->flags);
  1603. bfd_putb32 (src->space_number, dst->space_number);
  1604. bfd_putb32 (src->subspace_index, dst->subspace_index);
  1605. bfd_putb32 (src->subspace_quantity, dst->subspace_quantity);
  1606. bfd_putb32 (src->loader_fix_index, dst->loader_fix_index);
  1607. bfd_putb32 (src->loader_fix_quantity, dst->loader_fix_quantity);
  1608. bfd_putb32 (src->init_pointer_index, dst->init_pointer_index);
  1609. bfd_putb32 (src->init_pointer_quantity, dst->init_pointer_quantity);
  1610. }
  1611. static void
  1612. som_swap_subspace_dictionary_in
  1613. (struct som_external_subspace_dictionary_record *src,
  1614. struct som_subspace_dictionary_record *dst)
  1615. {
  1616. unsigned int flags;
  1617. dst->space_index = bfd_getb32 (src->space_index);
  1618. flags = bfd_getb32 (src->flags);
  1619. dst->access_control_bits = (flags >> SOM_SUBSPACE_ACCESS_CONTROL_BITS_SH)
  1620. & SOM_SUBSPACE_ACCESS_CONTROL_BITS_MASK;
  1621. dst->memory_resident = (flags & SOM_SUBSPACE_MEMORY_RESIDENT) != 0;
  1622. dst->dup_common = (flags & SOM_SUBSPACE_DUP_COMMON) != 0;
  1623. dst->is_common = (flags & SOM_SUBSPACE_IS_COMMON) != 0;
  1624. dst->is_loadable = (flags & SOM_SUBSPACE_IS_LOADABLE) != 0;
  1625. dst->quadrant = (flags >> SOM_SUBSPACE_QUADRANT_SH)
  1626. & SOM_SUBSPACE_QUADRANT_MASK;
  1627. dst->initially_frozen = (flags & SOM_SUBSPACE_INITIALLY_FROZEN) != 0;
  1628. dst->is_first = (flags & SOM_SUBSPACE_IS_FIRST) != 0;
  1629. dst->code_only = (flags & SOM_SUBSPACE_CODE_ONLY) != 0;
  1630. dst->sort_key = (flags >> SOM_SUBSPACE_SORT_KEY_SH)
  1631. & SOM_SUBSPACE_SORT_KEY_MASK;
  1632. dst->replicate_init = (flags & SOM_SUBSPACE_REPLICATE_INIT) != 0;
  1633. dst->continuation = (flags & SOM_SUBSPACE_CONTINUATION) != 0;
  1634. dst->is_tspecific = (flags & SOM_SUBSPACE_IS_TSPECIFIC) != 0;
  1635. dst->is_comdat = (flags & SOM_SUBSPACE_IS_COMDAT) != 0;
  1636. dst->reserved = 0;
  1637. dst->file_loc_init_value = bfd_getb32 (src->file_loc_init_value);
  1638. dst->initialization_length = bfd_getb32 (src->initialization_length);
  1639. dst->subspace_start = bfd_getb32 (src->subspace_start);
  1640. dst->subspace_length = bfd_getb32 (src->subspace_length);
  1641. dst->alignment = bfd_getb32 (src->alignment);
  1642. dst->name = bfd_getb32 (src->name);
  1643. dst->fixup_request_index = bfd_getb32 (src->fixup_request_index);
  1644. dst->fixup_request_quantity = bfd_getb32 (src->fixup_request_quantity);
  1645. }
  1646. static void
  1647. som_swap_subspace_dictionary_record_out
  1648. (struct som_subspace_dictionary_record *src,
  1649. struct som_external_subspace_dictionary_record *dst)
  1650. {
  1651. unsigned int flags;
  1652. bfd_putb32 (src->space_index, dst->space_index);
  1653. flags = (src->access_control_bits & SOM_SUBSPACE_ACCESS_CONTROL_BITS_MASK)
  1654. << SOM_SUBSPACE_ACCESS_CONTROL_BITS_SH;
  1655. if (src->memory_resident)
  1656. flags |= SOM_SUBSPACE_MEMORY_RESIDENT;
  1657. if (src->dup_common)
  1658. flags |= SOM_SUBSPACE_DUP_COMMON;
  1659. if (src->is_common)
  1660. flags |= SOM_SUBSPACE_IS_COMMON;
  1661. if (src->is_loadable)
  1662. flags |= SOM_SUBSPACE_IS_LOADABLE;
  1663. flags |= (src->quadrant & SOM_SUBSPACE_QUADRANT_MASK)
  1664. << SOM_SUBSPACE_QUADRANT_SH;
  1665. if (src->initially_frozen)
  1666. flags |= SOM_SUBSPACE_INITIALLY_FROZEN;
  1667. if (src->is_first)
  1668. flags |= SOM_SUBSPACE_IS_FIRST;
  1669. if (src->code_only)
  1670. flags |= SOM_SUBSPACE_CODE_ONLY;
  1671. flags |= (src->sort_key & SOM_SUBSPACE_SORT_KEY_MASK)
  1672. << SOM_SUBSPACE_SORT_KEY_SH;
  1673. if (src->replicate_init)
  1674. flags |= SOM_SUBSPACE_REPLICATE_INIT;
  1675. if (src->continuation)
  1676. flags |= SOM_SUBSPACE_CONTINUATION;
  1677. if (src->is_tspecific)
  1678. flags |= SOM_SUBSPACE_IS_TSPECIFIC;
  1679. if (src->is_comdat)
  1680. flags |= SOM_SUBSPACE_IS_COMDAT;
  1681. bfd_putb32 (flags, dst->flags);
  1682. bfd_putb32 (src->file_loc_init_value, dst->file_loc_init_value);
  1683. bfd_putb32 (src->initialization_length, dst->initialization_length);
  1684. bfd_putb32 (src->subspace_start, dst->subspace_start);
  1685. bfd_putb32 (src->subspace_length, dst->subspace_length);
  1686. bfd_putb32 (src->alignment, dst->alignment);
  1687. bfd_putb32 (src->name, dst->name);
  1688. bfd_putb32 (src->fixup_request_index, dst->fixup_request_index);
  1689. bfd_putb32 (src->fixup_request_quantity, dst->fixup_request_quantity);
  1690. }
  1691. static void
  1692. som_swap_aux_id_in (struct som_external_aux_id *src,
  1693. struct som_aux_id *dst)
  1694. {
  1695. unsigned int flags = bfd_getb32 (src->flags);
  1696. dst->mandatory = (flags & SOM_AUX_ID_MANDATORY) != 0;
  1697. dst->copy = (flags & SOM_AUX_ID_COPY) != 0;
  1698. dst->append = (flags & SOM_AUX_ID_APPEND) != 0;
  1699. dst->ignore = (flags & SOM_AUX_ID_IGNORE) != 0;
  1700. dst->type = (flags >> SOM_AUX_ID_TYPE_SH) & SOM_AUX_ID_TYPE_MASK;
  1701. dst->length = bfd_getb32 (src->length);
  1702. }
  1703. static void
  1704. som_swap_aux_id_out (struct som_aux_id *src,
  1705. struct som_external_aux_id *dst)
  1706. {
  1707. unsigned int flags = 0;
  1708. if (src->mandatory)
  1709. flags |= SOM_AUX_ID_MANDATORY;
  1710. if (src->copy)
  1711. flags |= SOM_AUX_ID_COPY;
  1712. if (src->append)
  1713. flags |= SOM_AUX_ID_APPEND;
  1714. if (src->ignore)
  1715. flags |= SOM_AUX_ID_IGNORE;
  1716. flags |= (src->type & SOM_AUX_ID_TYPE_MASK) << SOM_AUX_ID_TYPE_SH;
  1717. bfd_putb32 (flags, dst->flags);
  1718. bfd_putb32 (src->length, dst->length);
  1719. }
  1720. static void
  1721. som_swap_string_auxhdr_out (struct som_string_auxhdr *src,
  1722. struct som_external_string_auxhdr *dst)
  1723. {
  1724. som_swap_aux_id_out (&src->header_id, &dst->header_id);
  1725. bfd_putb32 (src->string_length, dst->string_length);
  1726. }
  1727. static void
  1728. som_swap_compilation_unit_out (struct som_compilation_unit *src,
  1729. struct som_external_compilation_unit *dst)
  1730. {
  1731. bfd_putb32 (src->name.strx, dst->name);
  1732. bfd_putb32 (src->language_name.strx, dst->language_name);
  1733. bfd_putb32 (src->product_id.strx, dst->product_id);
  1734. bfd_putb32 (src->version_id.strx, dst->version_id);
  1735. bfd_putb32 (src->flags, dst->flags);
  1736. som_swap_clock_out (&src->compile_time, &dst->compile_time);
  1737. som_swap_clock_out (&src->source_time, &dst->source_time);
  1738. }
  1739. static void
  1740. som_swap_exec_auxhdr_in (struct som_external_exec_auxhdr *src,
  1741. struct som_exec_auxhdr *dst)
  1742. {
  1743. som_swap_aux_id_in (&src->som_auxhdr, &dst->som_auxhdr);
  1744. dst->exec_tsize = bfd_getb32 (src->exec_tsize);
  1745. dst->exec_tmem = bfd_getb32 (src->exec_tmem);
  1746. dst->exec_tfile = bfd_getb32 (src->exec_tfile);
  1747. dst->exec_dsize = bfd_getb32 (src->exec_dsize);
  1748. dst->exec_dmem = bfd_getb32 (src->exec_dmem);
  1749. dst->exec_dfile = bfd_getb32 (src->exec_dfile);
  1750. dst->exec_bsize = bfd_getb32 (src->exec_bsize);
  1751. dst->exec_entry = bfd_getb32 (src->exec_entry);
  1752. dst->exec_flags = bfd_getb32 (src->exec_flags);
  1753. dst->exec_bfill = bfd_getb32 (src->exec_bfill);
  1754. }
  1755. static void
  1756. som_swap_exec_auxhdr_out (struct som_exec_auxhdr *src,
  1757. struct som_external_exec_auxhdr *dst)
  1758. {
  1759. som_swap_aux_id_out (&src->som_auxhdr, &dst->som_auxhdr);
  1760. bfd_putb32 (src->exec_tsize, dst->exec_tsize);
  1761. bfd_putb32 (src->exec_tmem, dst->exec_tmem);
  1762. bfd_putb32 (src->exec_tfile, dst->exec_tfile);
  1763. bfd_putb32 (src->exec_dsize, dst->exec_dsize);
  1764. bfd_putb32 (src->exec_dmem, dst->exec_dmem);
  1765. bfd_putb32 (src->exec_dfile, dst->exec_dfile);
  1766. bfd_putb32 (src->exec_bsize, dst->exec_bsize);
  1767. bfd_putb32 (src->exec_entry, dst->exec_entry);
  1768. bfd_putb32 (src->exec_flags, dst->exec_flags);
  1769. bfd_putb32 (src->exec_bfill, dst->exec_bfill);
  1770. }
  1771. static void
  1772. som_swap_lst_header_in (struct som_external_lst_header *src,
  1773. struct som_lst_header *dst)
  1774. {
  1775. dst->system_id = bfd_getb16 (src->system_id);
  1776. dst->a_magic = bfd_getb16 (src->a_magic);
  1777. dst->version_id = bfd_getb32 (src->version_id);
  1778. som_swap_clock_in (&src->file_time, &dst->file_time);
  1779. dst->hash_loc = bfd_getb32 (src->hash_loc);
  1780. dst->hash_size = bfd_getb32 (src->hash_size);
  1781. dst->module_count = bfd_getb32 (src->module_count);
  1782. dst->module_limit = bfd_getb32 (src->module_limit);
  1783. dst->dir_loc = bfd_getb32 (src->dir_loc);
  1784. dst->export_loc = bfd_getb32 (src->export_loc);
  1785. dst->export_count = bfd_getb32 (src->export_count);
  1786. dst->import_loc = bfd_getb32 (src->import_loc);
  1787. dst->aux_loc = bfd_getb32 (src->aux_loc);
  1788. dst->aux_size = bfd_getb32 (src->aux_size);
  1789. dst->string_loc = bfd_getb32 (src->string_loc);
  1790. dst->string_size = bfd_getb32 (src->string_size);
  1791. dst->free_list = bfd_getb32 (src->free_list);
  1792. dst->file_end = bfd_getb32 (src->file_end);
  1793. dst->checksum = bfd_getb32 (src->checksum);
  1794. }
  1795. /* Perform some initialization for an object. Save results of this
  1796. initialization in the BFD. */
  1797. static const bfd_target *
  1798. som_object_setup (bfd *abfd,
  1799. struct som_header *file_hdrp,
  1800. struct som_exec_auxhdr *aux_hdrp,
  1801. unsigned long current_offset)
  1802. {
  1803. asection *section;
  1804. /* som_mkobject will set bfd_error if som_mkobject fails. */
  1805. if (! som_mkobject (abfd))
  1806. return NULL;
  1807. /* Set BFD flags based on what information is available in the SOM. */
  1808. abfd->flags = BFD_NO_FLAGS;
  1809. if (file_hdrp->symbol_total)
  1810. abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
  1811. switch (file_hdrp->a_magic)
  1812. {
  1813. case DEMAND_MAGIC:
  1814. abfd->flags |= (D_PAGED | WP_TEXT | EXEC_P);
  1815. break;
  1816. case SHARE_MAGIC:
  1817. abfd->flags |= (WP_TEXT | EXEC_P);
  1818. break;
  1819. case EXEC_MAGIC:
  1820. abfd->flags |= (EXEC_P);
  1821. break;
  1822. case RELOC_MAGIC:
  1823. abfd->flags |= HAS_RELOC;
  1824. break;
  1825. #ifdef SHL_MAGIC
  1826. case SHL_MAGIC:
  1827. #endif
  1828. #ifdef DL_MAGIC
  1829. case DL_MAGIC:
  1830. #endif
  1831. abfd->flags |= DYNAMIC;
  1832. break;
  1833. default:
  1834. break;
  1835. }
  1836. /* Save the auxiliary header. */
  1837. obj_som_exec_hdr (abfd) = aux_hdrp;
  1838. /* Allocate space to hold the saved exec header information. */
  1839. obj_som_exec_data (abfd) = bfd_zalloc (abfd, (bfd_size_type) sizeof (struct som_exec_data));
  1840. if (obj_som_exec_data (abfd) == NULL)
  1841. return NULL;
  1842. /* The braindamaged OSF1 linker switched exec_flags and exec_entry!
  1843. We used to identify OSF1 binaries based on NEW_VERSION_ID, but
  1844. apparently the latest HPUX linker is using NEW_VERSION_ID now.
  1845. It's about time, OSF has used the new id since at least 1992;
  1846. HPUX didn't start till nearly 1995!.
  1847. The new approach examines the entry field for an executable. If
  1848. it is not 4-byte aligned then it's not a proper code address and
  1849. we guess it's really the executable flags. For a main program,
  1850. we also consider zero to be indicative of a buggy linker, since
  1851. that is not a valid entry point. The entry point for a shared
  1852. library, however, can be zero so we do not consider that to be
  1853. indicative of a buggy linker. */
  1854. if (aux_hdrp)
  1855. {
  1856. int found = 0;
  1857. for (section = abfd->sections; section; section = section->next)
  1858. {
  1859. bfd_vma entry;
  1860. if ((section->flags & SEC_CODE) == 0)
  1861. continue;
  1862. entry = aux_hdrp->exec_entry + aux_hdrp->exec_tmem;
  1863. if (entry >= section->vma
  1864. && entry < section->vma + section->size)
  1865. found = 1;
  1866. }
  1867. if ((aux_hdrp->exec_entry == 0 && !(abfd->flags & DYNAMIC))
  1868. || (aux_hdrp->exec_entry & 0x3) != 0
  1869. || ! found)
  1870. {
  1871. bfd_get_start_address (abfd) = aux_hdrp->exec_flags;
  1872. obj_som_exec_data (abfd)->exec_flags = aux_hdrp->exec_entry;
  1873. }
  1874. else
  1875. {
  1876. bfd_get_start_address (abfd) = aux_hdrp->exec_entry + current_offset;
  1877. obj_som_exec_data (abfd)->exec_flags = aux_hdrp->exec_flags;
  1878. }
  1879. }
  1880. obj_som_exec_data (abfd)->version_id = file_hdrp->version_id;
  1881. bfd_default_set_arch_mach (abfd, bfd_arch_hppa, pa10);
  1882. bfd_get_symcount (abfd) = file_hdrp->symbol_total;
  1883. /* Initialize the saved symbol table and string table to NULL.
  1884. Save important offsets and sizes from the SOM header into
  1885. the BFD. */
  1886. obj_som_stringtab (abfd) = NULL;
  1887. obj_som_symtab (abfd) = NULL;
  1888. obj_som_sorted_syms (abfd) = NULL;
  1889. obj_som_stringtab_size (abfd) = file_hdrp->symbol_strings_size;
  1890. obj_som_sym_filepos (abfd) = file_hdrp->symbol_location + current_offset;
  1891. obj_som_str_filepos (abfd) = (file_hdrp->symbol_strings_location
  1892. + current_offset);
  1893. obj_som_reloc_filepos (abfd) = (file_hdrp->fixup_request_location
  1894. + current_offset);
  1895. obj_som_exec_data (abfd)->system_id = file_hdrp->system_id;
  1896. return abfd->xvec;
  1897. }
  1898. /* Convert all of the space and subspace info into BFD sections. Each space
  1899. contains a number of subspaces, which in turn describe the mapping between
  1900. regions of the exec file, and the address space that the program runs in.
  1901. BFD sections which correspond to spaces will overlap the sections for the
  1902. associated subspaces. */
  1903. static bfd_boolean
  1904. setup_sections (bfd *abfd,
  1905. struct som_header *file_hdr,
  1906. unsigned long current_offset)
  1907. {
  1908. char *space_strings;
  1909. unsigned int space_index, i;
  1910. unsigned int total_subspaces = 0;
  1911. asection **subspace_sections = NULL;
  1912. asection *section;
  1913. bfd_size_type amt;
  1914. /* First, read in space names. */
  1915. amt = file_hdr->space_strings_size;
  1916. space_strings = bfd_malloc (amt);
  1917. if (!space_strings && amt != 0)
  1918. goto error_return;
  1919. if (bfd_seek (abfd, current_offset + file_hdr->space_strings_location,
  1920. SEEK_SET) != 0)
  1921. goto error_return;
  1922. if (bfd_bread (space_strings, amt, abfd) != amt)
  1923. goto error_return;
  1924. /* Loop over all of the space dictionaries, building up sections. */
  1925. for (space_index = 0; space_index < file_hdr->space_total; space_index++)
  1926. {
  1927. struct som_space_dictionary_record space;
  1928. struct som_external_space_dictionary_record ext_space;
  1929. char *space_name;
  1930. struct som_external_subspace_dictionary_record ext_subspace;
  1931. struct som_subspace_dictionary_record subspace, save_subspace;
  1932. unsigned int subspace_index;
  1933. asection *space_asect;
  1934. bfd_size_type space_size = 0;
  1935. char *newname;
  1936. /* Read the space dictionary element. */
  1937. if (bfd_seek (abfd,
  1938. (current_offset + file_hdr->space_location
  1939. + space_index * sizeof (ext_space)),
  1940. SEEK_SET) != 0)
  1941. goto error_return;
  1942. amt = sizeof ext_space;
  1943. if (bfd_bread (&ext_space, amt, abfd) != amt)
  1944. goto error_return;
  1945. som_swap_space_dictionary_in (&ext_space, &space);
  1946. /* Setup the space name string. */
  1947. space_name = space.name + space_strings;
  1948. /* Make a section out of it. */
  1949. amt = strlen (space_name) + 1;
  1950. newname = bfd_alloc (abfd, amt);
  1951. if (!newname)
  1952. goto error_return;
  1953. strcpy (newname, space_name);
  1954. space_asect = bfd_make_section_anyway (abfd, newname);
  1955. if (!space_asect)
  1956. goto error_return;
  1957. if (space.is_loadable == 0)
  1958. space_asect->flags |= SEC_DEBUGGING;
  1959. /* Set up all the attributes for the space. */
  1960. if (! bfd_som_set_section_attributes (space_asect, space.is_defined,
  1961. space.is_private, space.sort_key,
  1962. space.space_number))
  1963. goto error_return;
  1964. /* If the space has no subspaces, then we're done. */
  1965. if (space.subspace_quantity == 0)
  1966. continue;
  1967. /* Now, read in the first subspace for this space. */
  1968. if (bfd_seek (abfd,
  1969. (current_offset + file_hdr->subspace_location
  1970. + space.subspace_index * sizeof ext_subspace),
  1971. SEEK_SET) != 0)
  1972. goto error_return;
  1973. amt = sizeof ext_subspace;
  1974. if (bfd_bread (&ext_subspace, amt, abfd) != amt)
  1975. goto error_return;
  1976. /* Seek back to the start of the subspaces for loop below. */
  1977. if (bfd_seek (abfd,
  1978. (current_offset + file_hdr->subspace_location
  1979. + space.subspace_index * sizeof ext_subspace),
  1980. SEEK_SET) != 0)
  1981. goto error_return;
  1982. som_swap_subspace_dictionary_in (&ext_subspace, &subspace);
  1983. /* Setup the start address and file loc from the first subspace
  1984. record. */
  1985. space_asect->vma = subspace.subspace_start;
  1986. space_asect->filepos = subspace.file_loc_init_value + current_offset;
  1987. space_asect->alignment_power = exact_log2 (subspace.alignment);
  1988. if (space_asect->alignment_power == (unsigned) -1)
  1989. goto error_return;
  1990. /* Initialize save_subspace so we can reliably determine if this
  1991. loop placed any useful values into it. */
  1992. memset (&save_subspace, 0, sizeof (save_subspace));
  1993. /* Loop over the rest of the subspaces, building up more sections. */
  1994. for (subspace_index = 0; subspace_index < space.subspace_quantity;
  1995. subspace_index++)
  1996. {
  1997. asection *subspace_asect;
  1998. char *subspace_name;
  1999. /* Read in the next subspace. */
  2000. amt = sizeof ext_subspace;
  2001. if (bfd_bread (&ext_subspace, amt, abfd) != amt)
  2002. goto error_return;
  2003. som_swap_subspace_dictionary_in (&ext_subspace, &subspace);
  2004. /* Setup the subspace name string. */
  2005. subspace_name = subspace.name + space_strings;
  2006. amt = strlen (subspace_name) + 1;
  2007. newname = bfd_alloc (abfd, amt);
  2008. if (!newname)
  2009. goto error_return;
  2010. strcpy (newname, subspace_name);
  2011. /* Make a section out of this subspace. */
  2012. subspace_asect = bfd_make_section_anyway (abfd, newname);
  2013. if (!subspace_asect)
  2014. goto error_return;
  2015. /* Store private information about the section. */
  2016. if (! bfd_som_set_subsection_attributes (subspace_asect, space_asect,
  2017. subspace.access_control_bits,
  2018. subspace.sort_key,
  2019. subspace.quadrant,
  2020. subspace.is_comdat,
  2021. subspace.is_common,
  2022. subspace.dup_common))
  2023. goto error_return;
  2024. /* Keep an easy mapping between subspaces and sections.
  2025. Note we do not necessarily read the subspaces in the
  2026. same order in which they appear in the object file.
  2027. So to make the target index come out correctly, we
  2028. store the location of the subspace header in target
  2029. index, then sort using the location of the subspace
  2030. header as the key. Then we can assign correct
  2031. subspace indices. */
  2032. total_subspaces++;
  2033. subspace_asect->target_index = bfd_tell (abfd) - sizeof (subspace);
  2034. /* Set SEC_READONLY and SEC_CODE/SEC_DATA as specified
  2035. by the access_control_bits in the subspace header. */
  2036. switch (subspace.access_control_bits >> 4)
  2037. {
  2038. /* Readonly data. */
  2039. case 0x0:
  2040. subspace_asect->flags |= SEC_DATA | SEC_READONLY;
  2041. break;
  2042. /* Normal data. */
  2043. case 0x1:
  2044. subspace_asect->flags |= SEC_DATA;
  2045. break;
  2046. /* Readonly code and the gateways.
  2047. Gateways have other attributes which do not map
  2048. into anything BFD knows about. */
  2049. case 0x2:
  2050. case 0x4:
  2051. case 0x5:
  2052. case 0x6:
  2053. case 0x7:
  2054. subspace_asect->flags |= SEC_CODE | SEC_READONLY;
  2055. break;
  2056. /* dynamic (writable) code. */
  2057. case 0x3:
  2058. subspace_asect->flags |= SEC_CODE;
  2059. break;
  2060. }
  2061. if (subspace.is_comdat || subspace.is_common || subspace.dup_common)
  2062. subspace_asect->flags |= SEC_LINK_ONCE;
  2063. if (subspace.subspace_length > 0)
  2064. subspace_asect->flags |= SEC_HAS_CONTENTS;
  2065. if (subspace.is_loadable)
  2066. subspace_asect->flags |= SEC_ALLOC | SEC_LOAD;
  2067. else
  2068. subspace_asect->flags |= SEC_DEBUGGING;
  2069. if (subspace.code_only)
  2070. subspace_asect->flags |= SEC_CODE;
  2071. /* Both file_loc_init_value and initialization_length will
  2072. be zero for a BSS like subspace. */
  2073. if (subspace.file_loc_init_value == 0
  2074. && subspace.initialization_length == 0)
  2075. subspace_asect->flags &= ~(SEC_DATA | SEC_LOAD | SEC_HAS_CONTENTS);
  2076. /* This subspace has relocations.
  2077. The fixup_request_quantity is a byte count for the number of
  2078. entries in the relocation stream; it is not the actual number
  2079. of relocations in the subspace. */
  2080. if (subspace.fixup_request_quantity != 0)
  2081. {
  2082. subspace_asect->flags |= SEC_RELOC;
  2083. subspace_asect->rel_filepos = subspace.fixup_request_index;
  2084. som_section_data (subspace_asect)->reloc_size
  2085. = subspace.fixup_request_quantity;
  2086. /* We can not determine this yet. When we read in the
  2087. relocation table the correct value will be filled in. */
  2088. subspace_asect->reloc_count = (unsigned) -1;
  2089. }
  2090. /* Update save_subspace if appropriate. */
  2091. if (subspace.file_loc_init_value > save_subspace.file_loc_init_value)
  2092. save_subspace = subspace;
  2093. subspace_asect->vma = subspace.subspace_start;
  2094. subspace_asect->size = subspace.subspace_length;
  2095. subspace_asect->filepos = (subspace.file_loc_init_value
  2096. + current_offset);
  2097. subspace_asect->alignment_power = exact_log2 (subspace.alignment);
  2098. if (subspace_asect->alignment_power == (unsigned) -1)
  2099. goto error_return;
  2100. /* Keep track of the accumulated sizes of the sections. */
  2101. space_size += subspace.subspace_length;
  2102. }
  2103. /* This can happen for a .o which defines symbols in otherwise
  2104. empty subspaces. */
  2105. if (!save_subspace.file_loc_init_value)
  2106. space_asect->size = 0;
  2107. else
  2108. {
  2109. if (file_hdr->a_magic != RELOC_MAGIC)
  2110. {
  2111. /* Setup the size for the space section based upon the info
  2112. in the last subspace of the space. */
  2113. space_asect->size = (save_subspace.subspace_start
  2114. - space_asect->vma
  2115. + save_subspace.subspace_length);
  2116. }
  2117. else
  2118. {
  2119. /* The subspace_start field is not initialised in relocatable
  2120. only objects, so it cannot be used for length calculations.
  2121. Instead we use the space_size value which we have been
  2122. accumulating. This isn't an accurate estimate since it
  2123. ignores alignment and ordering issues. */
  2124. space_asect->size = space_size;
  2125. }
  2126. }
  2127. }
  2128. /* Now that we've read in all the subspace records, we need to assign
  2129. a target index to each subspace. */
  2130. amt = total_subspaces;
  2131. amt *= sizeof (asection *);
  2132. subspace_sections = bfd_malloc (amt);
  2133. if (subspace_sections == NULL)
  2134. goto error_return;
  2135. for (i = 0, section = abfd->sections; section; section = section->next)
  2136. {
  2137. if (!som_is_subspace (section))
  2138. continue;
  2139. subspace_sections[i] = section;
  2140. i++;
  2141. }
  2142. qsort (subspace_sections, total_subspaces,
  2143. sizeof (asection *), compare_subspaces);
  2144. /* subspace_sections is now sorted in the order in which the subspaces
  2145. appear in the object file. Assign an index to each one now. */
  2146. for (i = 0; i < total_subspaces; i++)
  2147. subspace_sections[i]->target_index = i;
  2148. if (space_strings != NULL)
  2149. free (space_strings);
  2150. if (subspace_sections != NULL)
  2151. free (subspace_sections);
  2152. return TRUE;
  2153. error_return:
  2154. if (space_strings != NULL)
  2155. free (space_strings);
  2156. if (subspace_sections != NULL)
  2157. free (subspace_sections);
  2158. return FALSE;
  2159. }
  2160. /* Read in a SOM object and make it into a BFD. */
  2161. static const bfd_target *
  2162. som_object_p (bfd *abfd)
  2163. {
  2164. struct som_external_header ext_file_hdr;
  2165. struct som_header file_hdr;
  2166. struct som_exec_auxhdr *aux_hdr_ptr = NULL;
  2167. unsigned long current_offset = 0;
  2168. struct som_external_lst_header ext_lst_header;
  2169. struct som_external_som_entry ext_som_entry;
  2170. bfd_size_type amt;
  2171. unsigned int loc;
  2172. #define ENTRY_SIZE sizeof (struct som_external_som_entry)
  2173. amt = sizeof (struct som_external_header);
  2174. if (bfd_bread (&ext_file_hdr, amt, abfd) != amt)
  2175. {
  2176. if (bfd_get_error () != bfd_error_system_call)
  2177. bfd_set_error (bfd_error_wrong_format);
  2178. return NULL;
  2179. }
  2180. som_swap_header_in (&ext_file_hdr, &file_hdr);
  2181. if (!_PA_RISC_ID (file_hdr.system_id))
  2182. {
  2183. bfd_set_error (bfd_error_wrong_format);
  2184. return NULL;
  2185. }
  2186. switch (file_hdr.a_magic)
  2187. {
  2188. case RELOC_MAGIC:
  2189. case EXEC_MAGIC:
  2190. case SHARE_MAGIC:
  2191. case DEMAND_MAGIC:
  2192. case DL_MAGIC:
  2193. case SHL_MAGIC:
  2194. #ifdef SHARED_MAGIC_CNX
  2195. case SHARED_MAGIC_CNX:
  2196. #endif
  2197. break;
  2198. case EXECLIBMAGIC:
  2199. /* Read the lst header and determine where the SOM directory begins. */
  2200. if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
  2201. {
  2202. if (bfd_get_error () != bfd_error_system_call)
  2203. bfd_set_error (bfd_error_wrong_format);
  2204. return NULL;
  2205. }
  2206. amt = sizeof (struct som_external_lst_header);
  2207. if (bfd_bread (&ext_lst_header, amt, abfd) != amt)
  2208. {
  2209. if (bfd_get_error () != bfd_error_system_call)
  2210. bfd_set_error (bfd_error_wrong_format);
  2211. return NULL;
  2212. }
  2213. /* Position to and read the first directory entry. */
  2214. loc = bfd_getb32 (ext_lst_header.dir_loc);
  2215. if (bfd_seek (abfd, loc, SEEK_SET) != 0)
  2216. {
  2217. if (bfd_get_error () != bfd_error_system_call)
  2218. bfd_set_error (bfd_error_wrong_format);
  2219. return NULL;
  2220. }
  2221. amt = ENTRY_SIZE;
  2222. if (bfd_bread (&ext_som_entry, amt, abfd) != amt)
  2223. {
  2224. if (bfd_get_error () != bfd_error_system_call)
  2225. bfd_set_error (bfd_error_wrong_format);
  2226. return NULL;
  2227. }
  2228. /* Now position to the first SOM. */
  2229. current_offset = bfd_getb32 (ext_som_entry.location);
  2230. if (bfd_seek (abfd, current_offset, SEEK_SET) != 0)
  2231. {
  2232. if (bfd_get_error () != bfd_error_system_call)
  2233. bfd_set_error (bfd_error_wrong_format);
  2234. return NULL;
  2235. }
  2236. /* And finally, re-read the som header. */
  2237. amt = sizeof (struct som_external_header);
  2238. if (bfd_bread (&ext_file_hdr, amt, abfd) != amt)
  2239. {
  2240. if (bfd_get_error () != bfd_error_system_call)
  2241. bfd_set_error (bfd_error_wrong_format);
  2242. return NULL;
  2243. }
  2244. som_swap_header_in (&ext_file_hdr, &file_hdr);
  2245. break;
  2246. default:
  2247. bfd_set_error (bfd_error_wrong_format);
  2248. return NULL;
  2249. }
  2250. if (file_hdr.version_id != OLD_VERSION_ID
  2251. && file_hdr.version_id != NEW_VERSION_ID)
  2252. {
  2253. bfd_set_error (bfd_error_wrong_format);
  2254. return NULL;
  2255. }
  2256. /* If the aux_header_size field in the file header is zero, then this
  2257. object is an incomplete executable (a .o file). Do not try to read
  2258. a non-existant auxiliary header. */
  2259. if (file_hdr.aux_header_size != 0)
  2260. {
  2261. struct som_external_exec_auxhdr ext_exec_auxhdr;
  2262. aux_hdr_ptr = bfd_zalloc (abfd,
  2263. (bfd_size_type) sizeof (*aux_hdr_ptr));
  2264. if (aux_hdr_ptr == NULL)
  2265. return NULL;
  2266. amt = sizeof (struct som_external_exec_auxhdr);
  2267. if (bfd_bread (&ext_exec_auxhdr, amt, abfd) != amt)
  2268. {
  2269. if (bfd_get_error () != bfd_error_system_call)
  2270. bfd_set_error (bfd_error_wrong_format);
  2271. return NULL;
  2272. }
  2273. som_swap_exec_auxhdr_in (&ext_exec_auxhdr, aux_hdr_ptr);
  2274. }
  2275. if (!setup_sections (abfd, &file_hdr, current_offset))
  2276. {
  2277. /* setup_sections does not bubble up a bfd error code. */
  2278. bfd_set_error (bfd_error_bad_value);
  2279. return NULL;
  2280. }
  2281. /* This appears to be a valid SOM object. Do some initialization. */
  2282. return som_object_setup (abfd, &file_hdr, aux_hdr_ptr, current_offset);
  2283. }
  2284. /* Create a SOM object. */
  2285. static bfd_boolean
  2286. som_mkobject (bfd *abfd)
  2287. {
  2288. /* Allocate memory to hold backend information. */
  2289. abfd->tdata.som_data = bfd_zalloc (abfd, (bfd_size_type) sizeof (struct som_data_struct));
  2290. if (abfd->tdata.som_data == NULL)
  2291. return FALSE;
  2292. return TRUE;
  2293. }
  2294. /* Initialize some information in the file header. This routine makes
  2295. not attempt at doing the right thing for a full executable; it
  2296. is only meant to handle relocatable objects. */
  2297. static bfd_boolean
  2298. som_prep_headers (bfd *abfd)
  2299. {
  2300. struct som_header *file_hdr;
  2301. asection *section;
  2302. bfd_size_type amt = sizeof (struct som_header);
  2303. /* Make and attach a file header to the BFD. */
  2304. file_hdr = bfd_zalloc (abfd, amt);
  2305. if (file_hdr == NULL)
  2306. return FALSE;
  2307. obj_som_file_hdr (abfd) = file_hdr;
  2308. if (abfd->flags & (EXEC_P | DYNAMIC))
  2309. {
  2310. /* Make and attach an exec header to the BFD. */
  2311. amt = sizeof (struct som_exec_auxhdr);
  2312. obj_som_exec_hdr (abfd) = bfd_zalloc (abfd, amt);
  2313. if (obj_som_exec_hdr (abfd) == NULL)
  2314. return FALSE;
  2315. if (abfd->flags & D_PAGED)
  2316. file_hdr->a_magic = DEMAND_MAGIC;
  2317. else if (abfd->flags & WP_TEXT)
  2318. file_hdr->a_magic = SHARE_MAGIC;
  2319. #ifdef SHL_MAGIC
  2320. else if (abfd->flags & DYNAMIC)
  2321. file_hdr->a_magic = SHL_MAGIC;
  2322. #endif
  2323. else
  2324. file_hdr->a_magic = EXEC_MAGIC;
  2325. }
  2326. else
  2327. file_hdr->a_magic = RELOC_MAGIC;
  2328. /* These fields are optional, and embedding timestamps is not always
  2329. a wise thing to do, it makes comparing objects during a multi-stage
  2330. bootstrap difficult. */
  2331. file_hdr->file_time.secs = 0;
  2332. file_hdr->file_time.nanosecs = 0;
  2333. file_hdr->entry_space = 0;
  2334. file_hdr->entry_subspace = 0;
  2335. file_hdr->entry_offset = 0;
  2336. file_hdr->presumed_dp = 0;
  2337. /* Now iterate over the sections translating information from
  2338. BFD sections to SOM spaces/subspaces. */
  2339. for (section = abfd->sections; section != NULL; section = section->next)
  2340. {
  2341. /* Ignore anything which has not been marked as a space or
  2342. subspace. */
  2343. if (!som_is_space (section) && !som_is_subspace (section))
  2344. continue;
  2345. if (som_is_space (section))
  2346. {
  2347. /* Allocate space for the space dictionary. */
  2348. amt = sizeof (struct som_space_dictionary_record);
  2349. som_section_data (section)->space_dict = bfd_zalloc (abfd, amt);
  2350. if (som_section_data (section)->space_dict == NULL)
  2351. return FALSE;
  2352. /* Set space attributes. Note most attributes of SOM spaces
  2353. are set based on the subspaces it contains. */
  2354. som_section_data (section)->space_dict->loader_fix_index = -1;
  2355. som_section_data (section)->space_dict->init_pointer_index = -1;
  2356. /* Set more attributes that were stuffed away in private data. */
  2357. som_section_data (section)->space_dict->sort_key =
  2358. som_section_data (section)->copy_data->sort_key;
  2359. som_section_data (section)->space_dict->is_defined =
  2360. som_section_data (section)->copy_data->is_defined;
  2361. som_section_data (section)->space_dict->is_private =
  2362. som_section_data (section)->copy_data->is_private;
  2363. som_section_data (section)->space_dict->space_number =
  2364. som_section_data (section)->copy_data->space_number;
  2365. }
  2366. else
  2367. {
  2368. /* Allocate space for the subspace dictionary. */
  2369. amt = sizeof (struct som_subspace_dictionary_record);
  2370. som_section_data (section)->subspace_dict = bfd_zalloc (abfd, amt);
  2371. if (som_section_data (section)->subspace_dict == NULL)
  2372. return FALSE;
  2373. /* Set subspace attributes. Basic stuff is done here, additional
  2374. attributes are filled in later as more information becomes
  2375. available. */
  2376. if (section->flags & SEC_ALLOC)
  2377. som_section_data (section)->subspace_dict->is_loadable = 1;
  2378. if (section->flags & SEC_CODE)
  2379. som_section_data (section)->subspace_dict->code_only = 1;
  2380. som_section_data (section)->subspace_dict->subspace_start =
  2381. section->vma;
  2382. som_section_data (section)->subspace_dict->subspace_length =
  2383. section->size;
  2384. som_section_data (section)->subspace_dict->initialization_length =
  2385. section->size;
  2386. som_section_data (section)->subspace_dict->alignment =
  2387. 1 << section->alignment_power;
  2388. /* Set more attributes that were stuffed away in private data. */
  2389. som_section_data (section)->subspace_dict->sort_key =
  2390. som_section_data (section)->copy_data->sort_key;
  2391. som_section_data (section)->subspace_dict->access_control_bits =
  2392. som_section_data (section)->copy_data->access_control_bits;
  2393. som_section_data (section)->subspace_dict->quadrant =
  2394. som_section_data (section)->copy_data->quadrant;
  2395. som_section_data (section)->subspace_dict->is_comdat =
  2396. som_section_data (section)->copy_data->is_comdat;
  2397. som_section_data (section)->subspace_dict->is_common =
  2398. som_section_data (section)->copy_data->is_common;
  2399. som_section_data (section)->subspace_dict->dup_common =
  2400. som_section_data (section)->copy_data->dup_common;
  2401. }
  2402. }
  2403. return TRUE;
  2404. }
  2405. /* Return TRUE if the given section is a SOM space, FALSE otherwise. */
  2406. static bfd_boolean
  2407. som_is_space (asection *section)
  2408. {
  2409. /* If no copy data is available, then it's neither a space nor a
  2410. subspace. */
  2411. if (som_section_data (section)->copy_data == NULL)
  2412. return FALSE;
  2413. /* If the containing space isn't the same as the given section,
  2414. then this isn't a space. */
  2415. if (som_section_data (section)->copy_data->container != section
  2416. && (som_section_data (section)->copy_data->container->output_section
  2417. != section))
  2418. return FALSE;
  2419. /* OK. Must be a space. */
  2420. return TRUE;
  2421. }
  2422. /* Return TRUE if the given section is a SOM subspace, FALSE otherwise. */
  2423. static bfd_boolean
  2424. som_is_subspace (asection *section)
  2425. {
  2426. /* If no copy data is available, then it's neither a space nor a
  2427. subspace. */
  2428. if (som_section_data (section)->copy_data == NULL)
  2429. return FALSE;
  2430. /* If the containing space is the same as the given section,
  2431. then this isn't a subspace. */
  2432. if (som_section_data (section)->copy_data->container == section
  2433. || (som_section_data (section)->copy_data->container->output_section
  2434. == section))
  2435. return FALSE;
  2436. /* OK. Must be a subspace. */
  2437. return TRUE;
  2438. }
  2439. /* Return TRUE if the given space contains the given subspace. It
  2440. is safe to assume space really is a space, and subspace really
  2441. is a subspace. */
  2442. static bfd_boolean
  2443. som_is_container (asection *space, asection *subspace)
  2444. {
  2445. return (som_section_data (subspace)->copy_data->container == space)
  2446. || (som_section_data (subspace)->copy_data->container->output_section
  2447. == space);
  2448. }
  2449. /* Count and return the number of spaces attached to the given BFD. */
  2450. static unsigned long
  2451. som_count_spaces (bfd *abfd)
  2452. {
  2453. int count = 0;
  2454. asection *section;
  2455. for (section = abfd->sections; section != NULL; section = section->next)
  2456. count += som_is_space (section);
  2457. return count;
  2458. }
  2459. /* Count the number of subspaces attached to the given BFD. */
  2460. static unsigned long
  2461. som_count_subspaces (bfd *abfd)
  2462. {
  2463. int count = 0;
  2464. asection *section;
  2465. for (section = abfd->sections; section != NULL; section = section->next)
  2466. count += som_is_subspace (section);
  2467. return count;
  2468. }
  2469. /* Return -1, 0, 1 indicating the relative ordering of sym1 and sym2.
  2470. We desire symbols to be ordered starting with the symbol with the
  2471. highest relocation count down to the symbol with the lowest relocation
  2472. count. Doing so compacts the relocation stream. */
  2473. static int
  2474. compare_syms (const void *arg1, const void *arg2)
  2475. {
  2476. asymbol **sym1 = (asymbol **) arg1;
  2477. asymbol **sym2 = (asymbol **) arg2;
  2478. unsigned int count1, count2;
  2479. /* Get relocation count for each symbol. Note that the count
  2480. is stored in the udata pointer for section symbols! */
  2481. if ((*sym1)->flags & BSF_SECTION_SYM)
  2482. count1 = (*sym1)->udata.i;
  2483. else
  2484. count1 = som_symbol_data (*sym1)->reloc_count;
  2485. if ((*sym2)->flags & BSF_SECTION_SYM)
  2486. count2 = (*sym2)->udata.i;
  2487. else
  2488. count2 = som_symbol_data (*sym2)->reloc_count;
  2489. /* Return the appropriate value. */
  2490. if (count1 < count2)
  2491. return 1;
  2492. else if (count1 > count2)
  2493. return -1;
  2494. return 0;
  2495. }
  2496. /* Return -1, 0, 1 indicating the relative ordering of subspace1
  2497. and subspace. */
  2498. static int
  2499. compare_subspaces (const void *arg1, const void *arg2)
  2500. {
  2501. asection **subspace1 = (asection **) arg1;
  2502. asection **subspace2 = (asection **) arg2;
  2503. if ((*subspace1)->target_index < (*subspace2)->target_index)
  2504. return -1;
  2505. else if ((*subspace2)->target_index < (*subspace1)->target_index)
  2506. return 1;
  2507. else
  2508. return 0;
  2509. }
  2510. /* Perform various work in preparation for emitting the fixup stream. */
  2511. static void
  2512. som_prep_for_fixups (bfd *abfd, asymbol **syms, unsigned long num_syms)
  2513. {
  2514. unsigned long i;
  2515. asection *section;
  2516. asymbol **sorted_syms;
  2517. bfd_size_type amt;
  2518. /* Most SOM relocations involving a symbol have a length which is
  2519. dependent on the index of the symbol. So symbols which are
  2520. used often in relocations should have a small index. */
  2521. /* First initialize the counters for each symbol. */
  2522. for (i = 0; i < num_syms; i++)
  2523. {
  2524. /* Handle a section symbol; these have no pointers back to the
  2525. SOM symbol info. So we just use the udata field to hold the
  2526. relocation count. */
  2527. if (som_symbol_data (syms[i]) == NULL
  2528. || syms[i]->flags & BSF_SECTION_SYM)
  2529. {
  2530. syms[i]->flags |= BSF_SECTION_SYM;
  2531. syms[i]->udata.i = 0;
  2532. }
  2533. else
  2534. som_symbol_data (syms[i])->reloc_count = 0;
  2535. }
  2536. /* Now that the counters are initialized, make a weighted count
  2537. of how often a given symbol is used in a relocation. */
  2538. for (section = abfd->sections; section != NULL; section = section->next)
  2539. {
  2540. int j;
  2541. /* Does this section have any relocations? */
  2542. if ((int) section->reloc_count <= 0)
  2543. continue;
  2544. /* Walk through each relocation for this section. */
  2545. for (j = 1; j < (int) section->reloc_count; j++)
  2546. {
  2547. arelent *reloc = section->orelocation[j];
  2548. int scale;
  2549. /* A relocation against a symbol in the *ABS* section really
  2550. does not have a symbol. Likewise if the symbol isn't associated
  2551. with any section. */
  2552. if (reloc->sym_ptr_ptr == NULL
  2553. || bfd_is_abs_section ((*reloc->sym_ptr_ptr)->section))
  2554. continue;
  2555. /* Scaling to encourage symbols involved in R_DP_RELATIVE
  2556. and R_CODE_ONE_SYMBOL relocations to come first. These
  2557. two relocations have single byte versions if the symbol
  2558. index is very small. */
  2559. if (reloc->howto->type == R_DP_RELATIVE
  2560. || reloc->howto->type == R_CODE_ONE_SYMBOL)
  2561. scale = 2;
  2562. else
  2563. scale = 1;
  2564. /* Handle section symbols by storing the count in the udata
  2565. field. It will not be used and the count is very important
  2566. for these symbols. */
  2567. if ((*reloc->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
  2568. {
  2569. (*reloc->sym_ptr_ptr)->udata.i =
  2570. (*reloc->sym_ptr_ptr)->udata.i + scale;
  2571. continue;
  2572. }
  2573. /* A normal symbol. Increment the count. */
  2574. som_symbol_data (*reloc->sym_ptr_ptr)->reloc_count += scale;
  2575. }
  2576. }
  2577. /* Sort a copy of the symbol table, rather than the canonical
  2578. output symbol table. */
  2579. amt = num_syms;
  2580. amt *= sizeof (asymbol *);
  2581. sorted_syms = bfd_zalloc (abfd, amt);
  2582. memcpy (sorted_syms, syms, num_syms * sizeof (asymbol *));
  2583. qsort (sorted_syms, num_syms, sizeof (asymbol *), compare_syms);
  2584. obj_som_sorted_syms (abfd) = sorted_syms;
  2585. /* Compute the symbol indexes, they will be needed by the relocation
  2586. code. */
  2587. for (i = 0; i < num_syms; i++)
  2588. {
  2589. /* A section symbol. Again, there is no pointer to backend symbol
  2590. information, so we reuse the udata field again. */
  2591. if (sorted_syms[i]->flags & BSF_SECTION_SYM)
  2592. sorted_syms[i]->udata.i = i;
  2593. else
  2594. som_symbol_data (sorted_syms[i])->index = i;
  2595. }
  2596. }
  2597. static bfd_boolean
  2598. som_write_fixups (bfd *abfd,
  2599. unsigned long current_offset,
  2600. unsigned int *total_reloc_sizep)
  2601. {
  2602. unsigned int i, j;
  2603. /* Chunk of memory that we can use as buffer space, then throw
  2604. away. */
  2605. unsigned char tmp_space[SOM_TMP_BUFSIZE];
  2606. unsigned char *p;
  2607. unsigned int total_reloc_size = 0;
  2608. unsigned int subspace_reloc_size = 0;
  2609. unsigned int num_spaces = obj_som_file_hdr (abfd)->space_total;
  2610. asection *section = abfd->sections;
  2611. bfd_size_type amt;
  2612. memset (tmp_space, 0, SOM_TMP_BUFSIZE);
  2613. p = tmp_space;
  2614. /* All the fixups for a particular subspace are emitted in a single
  2615. stream. All the subspaces for a particular space are emitted
  2616. as a single stream.
  2617. So, to get all the locations correct one must iterate through all the
  2618. spaces, for each space iterate through its subspaces and output a
  2619. fixups stream. */
  2620. for (i = 0; i < num_spaces; i++)
  2621. {
  2622. asection *subsection;
  2623. /* Find a space. */
  2624. while (!som_is_space (section))
  2625. section = section->next;
  2626. /* Now iterate through each of its subspaces. */
  2627. for (subsection = abfd->sections;
  2628. subsection != NULL;
  2629. subsection = subsection->next)
  2630. {
  2631. int reloc_offset;
  2632. unsigned int current_rounding_mode;
  2633. #ifndef NO_PCREL_MODES
  2634. unsigned int current_call_mode;
  2635. #endif
  2636. /* Find a subspace of this space. */
  2637. if (!som_is_subspace (subsection)
  2638. || !som_is_container (section, subsection))
  2639. continue;
  2640. /* If this subspace does not have real data, then we are
  2641. finished with it. */
  2642. if ((subsection->flags & SEC_HAS_CONTENTS) == 0)
  2643. {
  2644. som_section_data (subsection)->subspace_dict->fixup_request_index
  2645. = -1;
  2646. continue;
  2647. }
  2648. /* This subspace has some relocations. Put the relocation stream
  2649. index into the subspace record. */
  2650. som_section_data (subsection)->subspace_dict->fixup_request_index
  2651. = total_reloc_size;
  2652. /* To make life easier start over with a clean slate for
  2653. each subspace. Seek to the start of the relocation stream
  2654. for this subspace in preparation for writing out its fixup
  2655. stream. */
  2656. if (bfd_seek (abfd, current_offset + total_reloc_size, SEEK_SET) != 0)
  2657. return FALSE;
  2658. /* Buffer space has already been allocated. Just perform some
  2659. initialization here. */
  2660. p = tmp_space;
  2661. subspace_reloc_size = 0;
  2662. reloc_offset = 0;
  2663. som_initialize_reloc_queue (reloc_queue);
  2664. current_rounding_mode = R_N_MODE;
  2665. #ifndef NO_PCREL_MODES
  2666. current_call_mode = R_SHORT_PCREL_MODE;
  2667. #endif
  2668. /* Translate each BFD relocation into one or more SOM
  2669. relocations. */
  2670. for (j = 0; j < subsection->reloc_count; j++)
  2671. {
  2672. arelent *bfd_reloc = subsection->orelocation[j];
  2673. unsigned int skip;
  2674. int sym_num;
  2675. /* Get the symbol number. Remember it's stored in a
  2676. special place for section symbols. */
  2677. if ((*bfd_reloc->sym_ptr_ptr)->flags & BSF_SECTION_SYM)
  2678. sym_num = (*bfd_reloc->sym_ptr_ptr)->udata.i;
  2679. else
  2680. sym_num = som_symbol_data (*bfd_reloc->sym_ptr_ptr)->index;
  2681. /* If there is not enough room for the next couple relocations,
  2682. then dump the current buffer contents now. Also reinitialize
  2683. the relocation queue.
  2684. No single BFD relocation could ever translate into more
  2685. than 100 bytes of SOM relocations (20bytes is probably the
  2686. upper limit, but leave lots of space for growth). */
  2687. if (p - tmp_space + 100 > SOM_TMP_BUFSIZE)
  2688. {
  2689. amt = p - tmp_space;
  2690. if (bfd_bwrite ((void *) tmp_space, amt, abfd) != amt)
  2691. return FALSE;
  2692. p = tmp_space;
  2693. som_initialize_reloc_queue (reloc_queue);
  2694. }
  2695. /* Emit R_NO_RELOCATION fixups to map any bytes which were
  2696. skipped. */
  2697. skip = bfd_reloc->address - reloc_offset;
  2698. p = som_reloc_skip (abfd, skip, p,
  2699. &subspace_reloc_size, reloc_queue);
  2700. /* Update reloc_offset for the next iteration.
  2701. Many relocations do not consume input bytes. They
  2702. are markers, or set state necessary to perform some
  2703. later relocation. */
  2704. switch (bfd_reloc->howto->type)
  2705. {
  2706. case R_ENTRY:
  2707. case R_ALT_ENTRY:
  2708. case R_EXIT:
  2709. case R_N_MODE:
  2710. case R_S_MODE:
  2711. case R_D_MODE:
  2712. case R_R_MODE:
  2713. case R_FSEL:
  2714. case R_LSEL:
  2715. case R_RSEL:
  2716. case R_COMP1:
  2717. case R_COMP2:
  2718. case R_BEGIN_BRTAB:
  2719. case R_END_BRTAB:
  2720. case R_BEGIN_TRY:
  2721. case R_END_TRY:
  2722. case R_N0SEL:
  2723. case R_N1SEL:
  2724. #ifndef NO_PCREL_MODES
  2725. case R_SHORT_PCREL_MODE:
  2726. case R_LONG_PCREL_MODE:
  2727. #endif
  2728. reloc_offset = bfd_reloc->address;
  2729. break;
  2730. default:
  2731. reloc_offset = bfd_reloc->address + 4;
  2732. break;
  2733. }
  2734. /* Now the actual relocation we care about. */
  2735. switch (bfd_reloc->howto->type)
  2736. {
  2737. case R_PCREL_CALL:
  2738. case R_ABS_CALL:
  2739. p = som_reloc_call (abfd, p, &subspace_reloc_size,
  2740. bfd_reloc, sym_num, reloc_queue);
  2741. break;
  2742. case R_CODE_ONE_SYMBOL:
  2743. case R_DP_RELATIVE:
  2744. /* Account for any addend. */
  2745. if (bfd_reloc->addend)
  2746. p = som_reloc_addend (abfd, bfd_reloc->addend, p,
  2747. &subspace_reloc_size, reloc_queue);
  2748. if (sym_num < 0x20)
  2749. {
  2750. bfd_put_8 (abfd, bfd_reloc->howto->type + sym_num, p);
  2751. subspace_reloc_size += 1;
  2752. p += 1;
  2753. }
  2754. else if (sym_num < 0x100)
  2755. {
  2756. bfd_put_8 (abfd, bfd_reloc->howto->type + 32, p);
  2757. bfd_put_8 (abfd, sym_num, p + 1);
  2758. p = try_prev_fixup (abfd, &subspace_reloc_size, p,
  2759. 2, reloc_queue);
  2760. }
  2761. else if (sym_num < 0x10000000)
  2762. {
  2763. bfd_put_8 (abfd, bfd_reloc->howto->type + 33, p);
  2764. bfd_put_8 (abfd, sym_num >> 16, p + 1);
  2765. bfd_put_16 (abfd, (bfd_vma) sym_num, p + 2);
  2766. p = try_prev_fixup (abfd, &subspace_reloc_size,
  2767. p, 4, reloc_queue);
  2768. }
  2769. else
  2770. abort ();
  2771. break;
  2772. case R_DATA_GPREL:
  2773. /* Account for any addend. */
  2774. if (bfd_reloc->addend)
  2775. p = som_reloc_addend (abfd, bfd_reloc->addend, p,
  2776. &subspace_reloc_size, reloc_queue);
  2777. if (sym_num < 0x10000000)
  2778. {
  2779. bfd_put_8 (abfd, bfd_reloc->howto->type, p);
  2780. bfd_put_8 (abfd, sym_num >> 16, p + 1);
  2781. bfd_put_16 (abfd, (bfd_vma) sym_num, p + 2);
  2782. p = try_prev_fixup (abfd, &subspace_reloc_size,
  2783. p, 4, reloc_queue);
  2784. }
  2785. else
  2786. abort ();
  2787. break;
  2788. case R_DATA_ONE_SYMBOL:
  2789. case R_DATA_PLABEL:
  2790. case R_CODE_PLABEL:
  2791. case R_DLT_REL:
  2792. /* Account for any addend using R_DATA_OVERRIDE. */
  2793. if (bfd_reloc->howto->type != R_DATA_ONE_SYMBOL
  2794. && bfd_reloc->addend)
  2795. p = som_reloc_addend (abfd, bfd_reloc->addend, p,
  2796. &subspace_reloc_size, reloc_queue);
  2797. if (sym_num < 0x100)
  2798. {
  2799. bfd_put_8 (abfd, bfd_reloc->howto->type, p);
  2800. bfd_put_8 (abfd, sym_num, p + 1);
  2801. p = try_prev_fixup (abfd, &subspace_reloc_size, p,
  2802. 2, reloc_queue);
  2803. }
  2804. else if (sym_num < 0x10000000)
  2805. {
  2806. bfd_put_8 (abfd, bfd_reloc->howto->type + 1, p);
  2807. bfd_put_8 (abfd, sym_num >> 16, p + 1);
  2808. bfd_put_16 (abfd, (bfd_vma) sym_num, p + 2);
  2809. p = try_prev_fixup (abfd, &subspace_reloc_size,
  2810. p, 4, reloc_queue);
  2811. }
  2812. else
  2813. abort ();
  2814. break;
  2815. case R_ENTRY:
  2816. {
  2817. unsigned int tmp;
  2818. arelent *tmp_reloc = NULL;
  2819. bfd_put_8 (abfd, R_ENTRY, p);
  2820. /* R_ENTRY relocations have 64 bits of associated
  2821. data. Unfortunately the addend field of a bfd
  2822. relocation is only 32 bits. So, we split up
  2823. the 64bit unwind information and store part in
  2824. the R_ENTRY relocation, and the rest in the R_EXIT
  2825. relocation. */
  2826. bfd_put_32 (abfd, bfd_reloc->addend, p + 1);
  2827. /* Find the next R_EXIT relocation. */
  2828. for (tmp = j; tmp < subsection->reloc_count; tmp++)
  2829. {
  2830. tmp_reloc = subsection->orelocation[tmp];
  2831. if (tmp_reloc->howto->type == R_EXIT)
  2832. break;
  2833. }
  2834. if (tmp == subsection->reloc_count)
  2835. abort ();
  2836. bfd_put_32 (abfd, tmp_reloc->addend, p + 5);
  2837. p = try_prev_fixup (abfd, &subspace_reloc_size,
  2838. p, 9, reloc_queue);
  2839. break;
  2840. }
  2841. case R_N_MODE:
  2842. case R_S_MODE:
  2843. case R_D_MODE:
  2844. case R_R_MODE:
  2845. /* If this relocation requests the current rounding
  2846. mode, then it is redundant. */
  2847. if (bfd_reloc->howto->type != current_rounding_mode)
  2848. {
  2849. bfd_put_8 (abfd, bfd_reloc->howto->type, p);
  2850. subspace_reloc_size += 1;
  2851. p += 1;
  2852. current_rounding_mode = bfd_reloc->howto->type;
  2853. }
  2854. break;
  2855. #ifndef NO_PCREL_MODES
  2856. case R_LONG_PCREL_MODE:
  2857. case R_SHORT_PCREL_MODE:
  2858. if (bfd_reloc->howto->type != current_call_mode)
  2859. {
  2860. bfd_put_8 (abfd, bfd_reloc->howto->type, p);
  2861. subspace_reloc_size += 1;
  2862. p += 1;
  2863. current_call_mode = bfd_reloc->howto->type;
  2864. }
  2865. break;
  2866. #endif
  2867. case R_EXIT:
  2868. case R_ALT_ENTRY:
  2869. case R_FSEL:
  2870. case R_LSEL:
  2871. case R_RSEL:
  2872. case R_BEGIN_BRTAB:
  2873. case R_END_BRTAB:
  2874. case R_BEGIN_TRY:
  2875. case R_N0SEL:
  2876. case R_N1SEL:
  2877. bfd_put_8 (abfd, bfd_reloc->howto->type, p);
  2878. subspace_reloc_size += 1;
  2879. p += 1;
  2880. break;
  2881. case R_END_TRY:
  2882. /* The end of an exception handling region. The reloc's
  2883. addend contains the offset of the exception handling
  2884. code. */
  2885. if (bfd_reloc->addend == 0)
  2886. bfd_put_8 (abfd, bfd_reloc->howto->type, p);
  2887. else if (bfd_reloc->addend < 1024)
  2888. {
  2889. bfd_put_8 (abfd, bfd_reloc->howto->type + 1, p);
  2890. bfd_put_8 (abfd, bfd_reloc->addend / 4, p + 1);
  2891. p = try_prev_fixup (abfd, &subspace_reloc_size,
  2892. p, 2, reloc_queue);
  2893. }
  2894. else
  2895. {
  2896. bfd_put_8 (abfd, bfd_reloc->howto->type + 2, p);
  2897. bfd_put_8 (abfd, (bfd_reloc->addend / 4) >> 16, p + 1);
  2898. bfd_put_16 (abfd, bfd_reloc->addend / 4, p + 2);
  2899. p = try_prev_fixup (abfd, &subspace_reloc_size,
  2900. p, 4, reloc_queue);
  2901. }
  2902. break;
  2903. case R_COMP1:
  2904. /* The only time we generate R_COMP1, R_COMP2 and
  2905. R_CODE_EXPR relocs is for the difference of two
  2906. symbols. Hence we can cheat here. */
  2907. bfd_put_8 (abfd, bfd_reloc->howto->type, p);
  2908. bfd_put_8 (abfd, 0x44, p + 1);
  2909. p = try_prev_fixup (abfd, &subspace_reloc_size,
  2910. p, 2, reloc_queue);
  2911. break;
  2912. case R_COMP2:
  2913. /* The only time we generate R_COMP1, R_COMP2 and
  2914. R_CODE_EXPR relocs is for the difference of two
  2915. symbols. Hence we can cheat here. */
  2916. bfd_put_8 (abfd, bfd_reloc->howto->type, p);
  2917. bfd_put_8 (abfd, 0x80, p + 1);
  2918. bfd_put_8 (abfd, sym_num >> 16, p + 2);
  2919. bfd_put_16 (abfd, (bfd_vma) sym_num, p + 3);
  2920. p = try_prev_fixup (abfd, &subspace_reloc_size,
  2921. p, 5, reloc_queue);
  2922. break;
  2923. case R_CODE_EXPR:
  2924. case R_DATA_EXPR:
  2925. /* The only time we generate R_COMP1, R_COMP2 and
  2926. R_CODE_EXPR relocs is for the difference of two
  2927. symbols. Hence we can cheat here. */
  2928. bfd_put_8 (abfd, bfd_reloc->howto->type, p);
  2929. subspace_reloc_size += 1;
  2930. p += 1;
  2931. break;
  2932. /* Put a "R_RESERVED" relocation in the stream if
  2933. we hit something we do not understand. The linker
  2934. will complain loudly if this ever happens. */
  2935. default:
  2936. bfd_put_8 (abfd, 0xff, p);
  2937. subspace_reloc_size += 1;
  2938. p += 1;
  2939. break;
  2940. }
  2941. }
  2942. /* Last BFD relocation for a subspace has been processed.
  2943. Map the rest of the subspace with R_NO_RELOCATION fixups. */
  2944. p = som_reloc_skip (abfd, subsection->size - reloc_offset,
  2945. p, &subspace_reloc_size, reloc_queue);
  2946. /* Scribble out the relocations. */
  2947. amt = p - tmp_space;
  2948. if (bfd_bwrite ((void *) tmp_space, amt, abfd) != amt)
  2949. return FALSE;
  2950. p = tmp_space;
  2951. total_reloc_size += subspace_reloc_size;
  2952. som_section_data (subsection)->subspace_dict->fixup_request_quantity
  2953. = subspace_reloc_size;
  2954. }
  2955. section = section->next;
  2956. }
  2957. *total_reloc_sizep = total_reloc_size;
  2958. return TRUE;
  2959. }
  2960. /* Write out the space/subspace string table. */
  2961. static bfd_boolean
  2962. som_write_space_strings (bfd *abfd,
  2963. unsigned long current_offset,
  2964. unsigned int *string_sizep)
  2965. {
  2966. /* Chunk of memory that we can use as buffer space, then throw
  2967. away. */
  2968. size_t tmp_space_size = SOM_TMP_BUFSIZE;
  2969. char *tmp_space = alloca (tmp_space_size);
  2970. char *p = tmp_space;
  2971. unsigned int strings_size = 0;
  2972. asection *section;
  2973. bfd_size_type amt;
  2974. /* Seek to the start of the space strings in preparation for writing
  2975. them out. */
  2976. if (bfd_seek (abfd, (file_ptr) current_offset, SEEK_SET) != 0)
  2977. return FALSE;
  2978. /* Walk through all the spaces and subspaces (order is not important)
  2979. building up and writing string table entries for their names. */
  2980. for (section = abfd->sections; section != NULL; section = section->next)
  2981. {
  2982. size_t length;
  2983. /* Only work with space/subspaces; avoid any other sections
  2984. which might have been made (.text for example). */
  2985. if (!som_is_space (section) && !som_is_subspace (section))
  2986. continue;
  2987. /* Get the length of the space/subspace name. */
  2988. length = strlen (section->name);
  2989. /* If there is not enough room for the next entry, then dump the
  2990. current buffer contents now and maybe allocate a larger
  2991. buffer. Each entry will take 4 bytes to hold the string
  2992. length + the string itself + null terminator. */
  2993. if (p - tmp_space + 5 + length > tmp_space_size)
  2994. {
  2995. /* Flush buffer before refilling or reallocating. */
  2996. amt = p - tmp_space;
  2997. if (bfd_bwrite ((void *) &tmp_space[0], amt, abfd) != amt)
  2998. return FALSE;
  2999. /* Reallocate if now empty buffer still too small. */
  3000. if (5 + length > tmp_space_size)
  3001. {
  3002. /* Ensure a minimum growth factor to avoid O(n**2) space
  3003. consumption for n strings. The optimal minimum
  3004. factor seems to be 2, as no other value can guarantee
  3005. wasting less than 50% space. (Note that we cannot
  3006. deallocate space allocated by `alloca' without
  3007. returning from this function.) The same technique is
  3008. used a few more times below when a buffer is
  3009. reallocated. */
  3010. if (2 * tmp_space_size < length + 5)
  3011. tmp_space_size = length + 5;
  3012. else
  3013. tmp_space_size = 2 * tmp_space_size;
  3014. tmp_space = alloca (tmp_space_size);
  3015. }
  3016. /* Reset to beginning of the (possibly new) buffer space. */
  3017. p = tmp_space;
  3018. }
  3019. /* First element in a string table entry is the length of the
  3020. string. Alignment issues are already handled. */
  3021. bfd_put_32 (abfd, (bfd_vma) length, p);
  3022. p += 4;
  3023. strings_size += 4;
  3024. /* Record the index in the space/subspace records. */
  3025. if (som_is_space (section))
  3026. som_section_data (section)->space_dict->name = strings_size;
  3027. else
  3028. som_section_data (section)->subspace_dict->name = strings_size;
  3029. /* Next comes the string itself + a null terminator. */
  3030. strcpy (p, section->name);
  3031. p += length + 1;
  3032. strings_size += length + 1;
  3033. /* Always align up to the next word boundary. */
  3034. while (strings_size % 4)
  3035. {
  3036. bfd_put_8 (abfd, 0, p);
  3037. p++;
  3038. strings_size++;
  3039. }
  3040. }
  3041. /* Done with the space/subspace strings. Write out any information
  3042. contained in a partial block. */
  3043. amt = p - tmp_space;
  3044. if (bfd_bwrite ((void *) &tmp_space[0], amt, abfd) != amt)
  3045. return FALSE;
  3046. *string_sizep = strings_size;
  3047. return TRUE;
  3048. }
  3049. /* Write out the symbol string table. */
  3050. static bfd_boolean
  3051. som_write_symbol_strings (bfd *abfd,
  3052. unsigned long current_offset,
  3053. asymbol **syms,
  3054. unsigned int num_syms,
  3055. unsigned int *string_sizep,
  3056. struct som_compilation_unit *compilation_unit)
  3057. {
  3058. unsigned int i;
  3059. /* Chunk of memory that we can use as buffer space, then throw
  3060. away. */
  3061. size_t tmp_space_size = SOM_TMP_BUFSIZE;
  3062. char *tmp_space = alloca (tmp_space_size);
  3063. char *p = tmp_space;
  3064. unsigned int strings_size = 0;
  3065. bfd_size_type amt;
  3066. /* This gets a bit gruesome because of the compilation unit. The
  3067. strings within the compilation unit are part of the symbol
  3068. strings, but don't have symbol_dictionary entries. So, manually
  3069. write them and update the compilation unit header. On input, the
  3070. compilation unit header contains local copies of the strings.
  3071. Move them aside. */
  3072. /* Seek to the start of the space strings in preparation for writing
  3073. them out. */
  3074. if (bfd_seek (abfd, (file_ptr) current_offset, SEEK_SET) != 0)
  3075. return FALSE;
  3076. if (compilation_unit)
  3077. {
  3078. for (i = 0; i < 4; i++)
  3079. {
  3080. struct som_name_pt *name;
  3081. size_t length;
  3082. switch (i)
  3083. {
  3084. case 0:
  3085. name = &compilation_unit->name;
  3086. break;
  3087. case 1:
  3088. name = &compilation_unit->language_name;
  3089. break;
  3090. case 2:
  3091. name = &compilation_unit->product_id;
  3092. break;
  3093. case 3:
  3094. name = &compilation_unit->version_id;
  3095. break;
  3096. default:
  3097. abort ();
  3098. }
  3099. length = strlen (name->name);
  3100. /* If there is not enough room for the next entry, then dump
  3101. the current buffer contents now and maybe allocate a
  3102. larger buffer. */
  3103. if (p - tmp_space + 5 + length > tmp_space_size)
  3104. {
  3105. /* Flush buffer before refilling or reallocating. */
  3106. amt = p - tmp_space;
  3107. if (bfd_bwrite ((void *) &tmp_space[0], amt, abfd) != amt)
  3108. return FALSE;
  3109. /* Reallocate if now empty buffer still too small. */
  3110. if (5 + length > tmp_space_size)
  3111. {
  3112. /* See alloca above for discussion of new size. */
  3113. if (2 * tmp_space_size < 5 + length)
  3114. tmp_space_size = 5 + length;
  3115. else
  3116. tmp_space_size = 2 * tmp_space_size;
  3117. tmp_space = alloca (tmp_space_size);
  3118. }
  3119. /* Reset to beginning of the (possibly new) buffer
  3120. space. */
  3121. p = tmp_space;
  3122. }
  3123. /* First element in a string table entry is the length of
  3124. the string. This must always be 4 byte aligned. This is
  3125. also an appropriate time to fill in the string index
  3126. field in the symbol table entry. */
  3127. bfd_put_32 (abfd, (bfd_vma) length, p);
  3128. strings_size += 4;
  3129. p += 4;
  3130. /* Next comes the string itself + a null terminator. */
  3131. strcpy (p, name->name);
  3132. name->strx = strings_size;
  3133. p += length + 1;
  3134. strings_size += length + 1;
  3135. /* Always align up to the next word boundary. */
  3136. while (strings_size % 4)
  3137. {
  3138. bfd_put_8 (abfd, 0, p);
  3139. strings_size++;
  3140. p++;
  3141. }
  3142. }
  3143. }
  3144. for (i = 0; i < num_syms; i++)
  3145. {
  3146. size_t length = strlen (syms[i]->name);
  3147. /* If there is not enough room for the next entry, then dump the
  3148. current buffer contents now and maybe allocate a larger buffer. */
  3149. if (p - tmp_space + 5 + length > tmp_space_size)
  3150. {
  3151. /* Flush buffer before refilling or reallocating. */
  3152. amt = p - tmp_space;
  3153. if (bfd_bwrite ((void *) &tmp_space[0], amt, abfd) != amt)
  3154. return FALSE;
  3155. /* Reallocate if now empty buffer still too small. */
  3156. if (5 + length > tmp_space_size)
  3157. {
  3158. /* See alloca above for discussion of new size. */
  3159. if (2 * tmp_space_size < 5 + length)
  3160. tmp_space_size = 5 + length;
  3161. else
  3162. tmp_space_size = 2 * tmp_space_size;
  3163. tmp_space = alloca (tmp_space_size);
  3164. }
  3165. /* Reset to beginning of the (possibly new) buffer space. */
  3166. p = tmp_space;
  3167. }
  3168. /* First element in a string table entry is the length of the
  3169. string. This must always be 4 byte aligned. This is also
  3170. an appropriate time to fill in the string index field in the
  3171. symbol table entry. */
  3172. bfd_put_32 (abfd, (bfd_vma) length, p);
  3173. strings_size += 4;
  3174. p += 4;
  3175. /* Next comes the string itself + a null terminator. */
  3176. strcpy (p, syms[i]->name);
  3177. som_symbol_data (syms[i])->stringtab_offset = strings_size;
  3178. p += length + 1;
  3179. strings_size += length + 1;
  3180. /* Always align up to the next word boundary. */
  3181. while (strings_size % 4)
  3182. {
  3183. bfd_put_8 (abfd, 0, p);
  3184. strings_size++;
  3185. p++;
  3186. }
  3187. }
  3188. /* Scribble out any partial block. */
  3189. amt = p - tmp_space;
  3190. if (bfd_bwrite ((void *) &tmp_space[0], amt, abfd) != amt)
  3191. return FALSE;
  3192. *string_sizep = strings_size;
  3193. return TRUE;
  3194. }
  3195. /* Compute variable information to be placed in the SOM headers,
  3196. space/subspace dictionaries, relocation streams, etc. Begin
  3197. writing parts of the object file. */
  3198. static bfd_boolean
  3199. som_begin_writing (bfd *abfd)
  3200. {
  3201. unsigned long current_offset = 0;
  3202. unsigned int strings_size = 0;
  3203. unsigned long num_spaces, num_subspaces, i;
  3204. asection *section;
  3205. unsigned int total_subspaces = 0;
  3206. struct som_exec_auxhdr *exec_header = NULL;
  3207. /* The file header will always be first in an object file,
  3208. everything else can be in random locations. To keep things
  3209. "simple" BFD will lay out the object file in the manner suggested
  3210. by the PRO ABI for PA-RISC Systems. */
  3211. /* Before any output can really begin offsets for all the major
  3212. portions of the object file must be computed. So, starting
  3213. with the initial file header compute (and sometimes write)
  3214. each portion of the object file. */
  3215. /* Make room for the file header, it's contents are not complete
  3216. yet, so it can not be written at this time. */
  3217. current_offset += sizeof (struct som_external_header);
  3218. /* Any auxiliary headers will follow the file header. Right now
  3219. we support only the copyright and version headers. */
  3220. obj_som_file_hdr (abfd)->aux_header_location = current_offset;
  3221. obj_som_file_hdr (abfd)->aux_header_size = 0;
  3222. if (abfd->flags & (EXEC_P | DYNAMIC))
  3223. {
  3224. /* Parts of the exec header will be filled in later, so
  3225. delay writing the header itself. Fill in the defaults,
  3226. and write it later. */
  3227. current_offset += sizeof (struct som_external_exec_auxhdr);
  3228. obj_som_file_hdr (abfd)->aux_header_size
  3229. += sizeof (struct som_external_exec_auxhdr);
  3230. exec_header = obj_som_exec_hdr (abfd);
  3231. exec_header->som_auxhdr.type = EXEC_AUX_ID;
  3232. exec_header->som_auxhdr.length = 40;
  3233. }
  3234. if (obj_som_version_hdr (abfd) != NULL)
  3235. {
  3236. struct som_external_string_auxhdr ext_string_auxhdr;
  3237. bfd_size_type len;
  3238. if (bfd_seek (abfd, (file_ptr) current_offset, SEEK_SET) != 0)
  3239. return FALSE;
  3240. /* Write the aux_id structure and the string length. */
  3241. len = sizeof (struct som_external_string_auxhdr);
  3242. obj_som_file_hdr (abfd)->aux_header_size += len;
  3243. current_offset += len;
  3244. som_swap_string_auxhdr_out
  3245. (obj_som_version_hdr (abfd), &ext_string_auxhdr);
  3246. if (bfd_bwrite (&ext_string_auxhdr, len, abfd) != len)
  3247. return FALSE;
  3248. /* Write the version string. */
  3249. len = obj_som_version_hdr (abfd)->header_id.length - 4;
  3250. obj_som_file_hdr (abfd)->aux_header_size += len;
  3251. current_offset += len;
  3252. if (bfd_bwrite ((void *) obj_som_version_hdr (abfd)->string, len, abfd)
  3253. != len)
  3254. return FALSE;
  3255. }
  3256. if (obj_som_copyright_hdr (abfd) != NULL)
  3257. {
  3258. struct som_external_string_auxhdr ext_string_auxhdr;
  3259. bfd_size_type len;
  3260. if (bfd_seek (abfd, (file_ptr) current_offset, SEEK_SET) != 0)
  3261. return FALSE;
  3262. /* Write the aux_id structure and the string length. */
  3263. len = sizeof (struct som_external_string_auxhdr);
  3264. obj_som_file_hdr (abfd)->aux_header_size += len;
  3265. current_offset += len;
  3266. som_swap_string_auxhdr_out
  3267. (obj_som_copyright_hdr (abfd), &ext_string_auxhdr);
  3268. if (bfd_bwrite (&ext_string_auxhdr, len, abfd) != len)
  3269. return FALSE;
  3270. /* Write the copyright string. */
  3271. len = obj_som_copyright_hdr (abfd)->header_id.length - 4;
  3272. obj_som_file_hdr (abfd)->aux_header_size += len;
  3273. current_offset += len;
  3274. if (bfd_bwrite ((void *) obj_som_copyright_hdr (abfd)->string, len, abfd)
  3275. != len)
  3276. return FALSE;
  3277. }
  3278. /* Next comes the initialization pointers; we have no initialization
  3279. pointers, so current offset does not change. */
  3280. obj_som_file_hdr (abfd)->init_array_location = current_offset;
  3281. obj_som_file_hdr (abfd)->init_array_total = 0;
  3282. /* Next are the space records. These are fixed length records.
  3283. Count the number of spaces to determine how much room is needed
  3284. in the object file for the space records.
  3285. The names of the spaces are stored in a separate string table,
  3286. and the index for each space into the string table is computed
  3287. below. Therefore, it is not possible to write the space headers
  3288. at this time. */
  3289. num_spaces = som_count_spaces (abfd);
  3290. obj_som_file_hdr (abfd)->space_location = current_offset;
  3291. obj_som_file_hdr (abfd)->space_total = num_spaces;
  3292. current_offset +=
  3293. num_spaces * sizeof (struct som_external_space_dictionary_record);
  3294. /* Next are the subspace records. These are fixed length records.
  3295. Count the number of subspaes to determine how much room is needed
  3296. in the object file for the subspace records.
  3297. A variety if fields in the subspace record are still unknown at
  3298. this time (index into string table, fixup stream location/size, etc). */
  3299. num_subspaces = som_count_subspaces (abfd);
  3300. obj_som_file_hdr (abfd)->subspace_location = current_offset;
  3301. obj_som_file_hdr (abfd)->subspace_total = num_subspaces;
  3302. current_offset
  3303. += num_subspaces * sizeof (struct som_external_subspace_dictionary_record);
  3304. /* Next is the string table for the space/subspace names. We will
  3305. build and write the string table on the fly. At the same time
  3306. we will fill in the space/subspace name index fields. */
  3307. /* The string table needs to be aligned on a word boundary. */
  3308. if (current_offset % 4)
  3309. current_offset += (4 - (current_offset % 4));
  3310. /* Mark the offset of the space/subspace string table in the
  3311. file header. */
  3312. obj_som_file_hdr (abfd)->space_strings_location = current_offset;
  3313. /* Scribble out the space strings. */
  3314. if (! som_write_space_strings (abfd, current_offset, &strings_size))
  3315. return FALSE;
  3316. /* Record total string table size in the header and update the
  3317. current offset. */
  3318. obj_som_file_hdr (abfd)->space_strings_size = strings_size;
  3319. current_offset += strings_size;
  3320. /* Next is the compilation unit. */
  3321. obj_som_file_hdr (abfd)->compiler_location = current_offset;
  3322. obj_som_file_hdr (abfd)->compiler_total = 0;
  3323. if (obj_som_compilation_unit (abfd))
  3324. {
  3325. obj_som_file_hdr (abfd)->compiler_total = 1;
  3326. current_offset += sizeof (struct som_external_compilation_unit);
  3327. }
  3328. /* Now compute the file positions for the loadable subspaces, taking
  3329. care to make sure everything stays properly aligned. */
  3330. section = abfd->sections;
  3331. for (i = 0; i < num_spaces; i++)
  3332. {
  3333. asection *subsection;
  3334. int first_subspace;
  3335. unsigned int subspace_offset = 0;
  3336. /* Find a space. */
  3337. while (!som_is_space (section))
  3338. section = section->next;
  3339. first_subspace = 1;
  3340. /* Now look for all its subspaces. */
  3341. for (subsection = abfd->sections;
  3342. subsection != NULL;
  3343. subsection = subsection->next)
  3344. {
  3345. if (!som_is_subspace (subsection)
  3346. || !som_is_container (section, subsection)
  3347. || (subsection->flags & SEC_ALLOC) == 0)
  3348. continue;
  3349. /* If this is the first subspace in the space, and we are
  3350. building an executable, then take care to make sure all
  3351. the alignments are correct and update the exec header. */
  3352. if (first_subspace
  3353. && (abfd->flags & (EXEC_P | DYNAMIC)))
  3354. {
  3355. /* Demand paged executables have each space aligned to a
  3356. page boundary. Sharable executables (write-protected
  3357. text) have just the private (aka data & bss) space aligned
  3358. to a page boundary. Ugh. Not true for HPUX.
  3359. The HPUX kernel requires the text to always be page aligned
  3360. within the file regardless of the executable's type. */
  3361. if (abfd->flags & (D_PAGED | DYNAMIC)
  3362. || (subsection->flags & SEC_CODE)
  3363. || ((abfd->flags & WP_TEXT)
  3364. && (subsection->flags & SEC_DATA)))
  3365. current_offset = SOM_ALIGN (current_offset, PA_PAGESIZE);
  3366. /* Update the exec header. */
  3367. if (subsection->flags & SEC_CODE && exec_header->exec_tfile == 0)
  3368. {
  3369. exec_header->exec_tmem = section->vma;
  3370. exec_header->exec_tfile = current_offset;
  3371. }
  3372. if (subsection->flags & SEC_DATA && exec_header->exec_dfile == 0)
  3373. {
  3374. exec_header->exec_dmem = section->vma;
  3375. exec_header->exec_dfile = current_offset;
  3376. }
  3377. /* Keep track of exactly where we are within a particular
  3378. space. This is necessary as the braindamaged HPUX
  3379. loader will create holes between subspaces *and*
  3380. subspace alignments are *NOT* preserved. What a crock. */
  3381. subspace_offset = subsection->vma;
  3382. /* Only do this for the first subspace within each space. */
  3383. first_subspace = 0;
  3384. }
  3385. else if (abfd->flags & (EXEC_P | DYNAMIC))
  3386. {
  3387. /* The braindamaged HPUX loader may have created a hole
  3388. between two subspaces. It is *not* sufficient to use
  3389. the alignment specifications within the subspaces to
  3390. account for these holes -- I've run into at least one
  3391. case where the loader left one code subspace unaligned
  3392. in a final executable.
  3393. To combat this we keep a current offset within each space,
  3394. and use the subspace vma fields to detect and preserve
  3395. holes. What a crock!
  3396. ps. This is not necessary for unloadable space/subspaces. */
  3397. current_offset += subsection->vma - subspace_offset;
  3398. if (subsection->flags & SEC_CODE)
  3399. exec_header->exec_tsize += subsection->vma - subspace_offset;
  3400. else
  3401. exec_header->exec_dsize += subsection->vma - subspace_offset;
  3402. subspace_offset += subsection->vma - subspace_offset;
  3403. }
  3404. subsection->target_index = total_subspaces++;
  3405. /* This is real data to be loaded from the file. */
  3406. if (subsection->flags & SEC_LOAD)
  3407. {
  3408. /* Update the size of the code & data. */
  3409. if (abfd->flags & (EXEC_P | DYNAMIC)
  3410. && subsection->flags & SEC_CODE)
  3411. exec_header->exec_tsize += subsection->size;
  3412. else if (abfd->flags & (EXEC_P | DYNAMIC)
  3413. && subsection->flags & SEC_DATA)
  3414. exec_header->exec_dsize += subsection->size;
  3415. som_section_data (subsection)->subspace_dict->file_loc_init_value
  3416. = current_offset;
  3417. subsection->filepos = current_offset;
  3418. current_offset += subsection->size;
  3419. subspace_offset += subsection->size;
  3420. }
  3421. /* Looks like uninitialized data. */
  3422. else
  3423. {
  3424. /* Update the size of the bss section. */
  3425. if (abfd->flags & (EXEC_P | DYNAMIC))
  3426. exec_header->exec_bsize += subsection->size;
  3427. som_section_data (subsection)->subspace_dict->file_loc_init_value
  3428. = 0;
  3429. som_section_data (subsection)->subspace_dict->
  3430. initialization_length = 0;
  3431. }
  3432. }
  3433. /* Goto the next section. */
  3434. section = section->next;
  3435. }
  3436. /* Finally compute the file positions for unloadable subspaces.
  3437. If building an executable, start the unloadable stuff on its
  3438. own page. */
  3439. if (abfd->flags & (EXEC_P | DYNAMIC))
  3440. current_offset = SOM_ALIGN (current_offset, PA_PAGESIZE);
  3441. obj_som_file_hdr (abfd)->unloadable_sp_location = current_offset;
  3442. section = abfd->sections;
  3443. for (i = 0; i < num_spaces; i++)
  3444. {
  3445. asection *subsection;
  3446. /* Find a space. */
  3447. while (!som_is_space (section))
  3448. section = section->next;
  3449. if (abfd->flags & (EXEC_P | DYNAMIC))
  3450. current_offset = SOM_ALIGN (current_offset, PA_PAGESIZE);
  3451. /* Now look for all its subspaces. */
  3452. for (subsection = abfd->sections;
  3453. subsection != NULL;
  3454. subsection = subsection->next)
  3455. {
  3456. if (!som_is_subspace (subsection)
  3457. || !som_is_container (section, subsection)
  3458. || (subsection->flags & SEC_ALLOC) != 0)
  3459. continue;
  3460. subsection->target_index = total_subspaces++;
  3461. /* This is real data to be loaded from the file. */
  3462. if ((subsection->flags & SEC_LOAD) == 0)
  3463. {
  3464. som_section_data (subsection)->subspace_dict->file_loc_init_value
  3465. = current_offset;
  3466. subsection->filepos = current_offset;
  3467. current_offset += subsection->size;
  3468. }
  3469. /* Looks like uninitialized data. */
  3470. else
  3471. {
  3472. som_section_data (subsection)->subspace_dict->file_loc_init_value
  3473. = 0;
  3474. som_section_data (subsection)->subspace_dict->
  3475. initialization_length = subsection->size;
  3476. }
  3477. }
  3478. /* Goto the next section. */
  3479. section = section->next;
  3480. }
  3481. /* If building an executable, then make sure to seek to and write
  3482. one byte at the end of the file to make sure any necessary
  3483. zeros are filled in. Ugh. */
  3484. if (abfd->flags & (EXEC_P | DYNAMIC))
  3485. current_offset = SOM_ALIGN (current_offset, PA_PAGESIZE);
  3486. if (bfd_seek (abfd, (file_ptr) current_offset - 1, SEEK_SET) != 0)
  3487. return FALSE;
  3488. if (bfd_bwrite ((void *) "", (bfd_size_type) 1, abfd) != 1)
  3489. return FALSE;
  3490. obj_som_file_hdr (abfd)->unloadable_sp_size
  3491. = current_offset - obj_som_file_hdr (abfd)->unloadable_sp_location;
  3492. /* Loader fixups are not supported in any way shape or form. */
  3493. obj_som_file_hdr (abfd)->loader_fixup_location = 0;
  3494. obj_som_file_hdr (abfd)->loader_fixup_total = 0;
  3495. /* Done. Store the total size of the SOM so far. */
  3496. obj_som_file_hdr (abfd)->som_length = current_offset;
  3497. return TRUE;
  3498. }
  3499. /* Finally, scribble out the various headers to the disk. */
  3500. static bfd_boolean
  3501. som_finish_writing (bfd *abfd)
  3502. {
  3503. int num_spaces = som_count_spaces (abfd);
  3504. asymbol **syms = bfd_get_outsymbols (abfd);
  3505. int i, num_syms;
  3506. int subspace_index = 0;
  3507. file_ptr location;
  3508. asection *section;
  3509. unsigned long current_offset;
  3510. unsigned int strings_size, total_reloc_size;
  3511. bfd_size_type amt;
  3512. struct som_external_header ext_header;
  3513. /* We must set up the version identifier here as objcopy/strip copy
  3514. private BFD data too late for us to handle this in som_begin_writing. */
  3515. if (obj_som_exec_data (abfd)
  3516. && obj_som_exec_data (abfd)->version_id)
  3517. obj_som_file_hdr (abfd)->version_id = obj_som_exec_data (abfd)->version_id;
  3518. else
  3519. obj_som_file_hdr (abfd)->version_id = NEW_VERSION_ID;
  3520. /* Next is the symbol table. These are fixed length records.
  3521. Count the number of symbols to determine how much room is needed
  3522. in the object file for the symbol table.
  3523. The names of the symbols are stored in a separate string table,
  3524. and the index for each symbol name into the string table is computed
  3525. below. Therefore, it is not possible to write the symbol table
  3526. at this time.
  3527. These used to be output before the subspace contents, but they
  3528. were moved here to work around a stupid bug in the hpux linker
  3529. (fixed in hpux10). */
  3530. current_offset = obj_som_file_hdr (abfd)->som_length;
  3531. /* Make sure we're on a word boundary. */
  3532. if (current_offset % 4)
  3533. current_offset += (4 - (current_offset % 4));
  3534. num_syms = bfd_get_symcount (abfd);
  3535. obj_som_file_hdr (abfd)->symbol_location = current_offset;
  3536. obj_som_file_hdr (abfd)->symbol_total = num_syms;
  3537. current_offset +=
  3538. num_syms * sizeof (struct som_external_symbol_dictionary_record);
  3539. /* Next are the symbol strings.
  3540. Align them to a word boundary. */
  3541. if (current_offset % 4)
  3542. current_offset += (4 - (current_offset % 4));
  3543. obj_som_file_hdr (abfd)->symbol_strings_location = current_offset;
  3544. /* Scribble out the symbol strings. */
  3545. if (! som_write_symbol_strings (abfd, current_offset, syms,
  3546. num_syms, &strings_size,
  3547. obj_som_compilation_unit (abfd)))
  3548. return FALSE;
  3549. /* Record total string table size in header and update the
  3550. current offset. */
  3551. obj_som_file_hdr (abfd)->symbol_strings_size = strings_size;
  3552. current_offset += strings_size;
  3553. /* Do prep work before handling fixups. */
  3554. som_prep_for_fixups (abfd,
  3555. bfd_get_outsymbols (abfd),
  3556. bfd_get_symcount (abfd));
  3557. /* At the end of the file is the fixup stream which starts on a
  3558. word boundary. */
  3559. if (current_offset % 4)
  3560. current_offset += (4 - (current_offset % 4));
  3561. obj_som_file_hdr (abfd)->fixup_request_location = current_offset;
  3562. /* Write the fixups and update fields in subspace headers which
  3563. relate to the fixup stream. */
  3564. if (! som_write_fixups (abfd, current_offset, &total_reloc_size))
  3565. return FALSE;
  3566. /* Record the total size of the fixup stream in the file header. */
  3567. obj_som_file_hdr (abfd)->fixup_request_total = total_reloc_size;
  3568. /* Done. Store the total size of the SOM. */
  3569. obj_som_file_hdr (abfd)->som_length = current_offset + total_reloc_size;
  3570. /* Now that the symbol table information is complete, build and
  3571. write the symbol table. */
  3572. if (! som_build_and_write_symbol_table (abfd))
  3573. return FALSE;
  3574. /* Subspaces are written first so that we can set up information
  3575. about them in their containing spaces as the subspace is written. */
  3576. /* Seek to the start of the subspace dictionary records. */
  3577. location = obj_som_file_hdr (abfd)->subspace_location;
  3578. if (bfd_seek (abfd, location, SEEK_SET) != 0)
  3579. return FALSE;
  3580. section = abfd->sections;
  3581. /* Now for each loadable space write out records for its subspaces. */
  3582. for (i = 0; i < num_spaces; i++)
  3583. {
  3584. asection *subsection;
  3585. /* Find a space. */
  3586. while (!som_is_space (section))
  3587. section = section->next;
  3588. /* Now look for all its subspaces. */
  3589. for (subsection = abfd->sections;
  3590. subsection != NULL;
  3591. subsection = subsection->next)
  3592. {
  3593. struct som_external_subspace_dictionary_record ext_subspace_dict;
  3594. /* Skip any section which does not correspond to a space
  3595. or subspace. Or does not have SEC_ALLOC set (and therefore
  3596. has no real bits on the disk). */
  3597. if (!som_is_subspace (subsection)
  3598. || !som_is_container (section, subsection)
  3599. || (subsection->flags & SEC_ALLOC) == 0)
  3600. continue;
  3601. /* If this is the first subspace for this space, then save
  3602. the index of the subspace in its containing space. Also
  3603. set "is_loadable" in the containing space. */
  3604. if (som_section_data (section)->space_dict->subspace_quantity == 0)
  3605. {
  3606. som_section_data (section)->space_dict->is_loadable = 1;
  3607. som_section_data (section)->space_dict->subspace_index
  3608. = subspace_index;
  3609. }
  3610. /* Increment the number of subspaces seen and the number of
  3611. subspaces contained within the current space. */
  3612. subspace_index++;
  3613. som_section_data (section)->space_dict->subspace_quantity++;
  3614. /* Mark the index of the current space within the subspace's
  3615. dictionary record. */
  3616. som_section_data (subsection)->subspace_dict->space_index = i;
  3617. /* Dump the current subspace header. */
  3618. som_swap_subspace_dictionary_record_out
  3619. (som_section_data (subsection)->subspace_dict, &ext_subspace_dict);
  3620. amt = sizeof (struct som_subspace_dictionary_record);
  3621. if (bfd_bwrite (&ext_subspace_dict, amt, abfd) != amt)
  3622. return FALSE;
  3623. }
  3624. /* Goto the next section. */
  3625. section = section->next;
  3626. }
  3627. /* Now repeat the process for unloadable subspaces. */
  3628. section = abfd->sections;
  3629. /* Now for each space write out records for its subspaces. */
  3630. for (i = 0; i < num_spaces; i++)
  3631. {
  3632. asection *subsection;
  3633. /* Find a space. */
  3634. while (!som_is_space (section))
  3635. section = section->next;
  3636. /* Now look for all its subspaces. */
  3637. for (subsection = abfd->sections;
  3638. subsection != NULL;
  3639. subsection = subsection->next)
  3640. {
  3641. struct som_external_subspace_dictionary_record ext_subspace_dict;
  3642. /* Skip any section which does not correspond to a space or
  3643. subspace, or which SEC_ALLOC set (and therefore handled
  3644. in the loadable spaces/subspaces code above). */
  3645. if (!som_is_subspace (subsection)
  3646. || !som_is_container (section, subsection)
  3647. || (subsection->flags & SEC_ALLOC) != 0)
  3648. continue;
  3649. /* If this is the first subspace for this space, then save
  3650. the index of the subspace in its containing space. Clear
  3651. "is_loadable". */
  3652. if (som_section_data (section)->space_dict->subspace_quantity == 0)
  3653. {
  3654. som_section_data (section)->space_dict->is_loadable = 0;
  3655. som_section_data (section)->space_dict->subspace_index
  3656. = subspace_index;
  3657. }
  3658. /* Increment the number of subspaces seen and the number of
  3659. subspaces contained within the current space. */
  3660. som_section_data (section)->space_dict->subspace_quantity++;
  3661. subspace_index++;
  3662. /* Mark the index of the current space within the subspace's
  3663. dictionary record. */
  3664. som_section_data (subsection)->subspace_dict->space_index = i;
  3665. /* Dump this subspace header. */
  3666. som_swap_subspace_dictionary_record_out
  3667. (som_section_data (subsection)->subspace_dict, &ext_subspace_dict);
  3668. amt = sizeof (struct som_subspace_dictionary_record);
  3669. if (bfd_bwrite (&ext_subspace_dict, amt, abfd) != amt)
  3670. return FALSE;
  3671. }
  3672. /* Goto the next section. */
  3673. section = section->next;
  3674. }
  3675. /* All the subspace dictionary records are written, and all the
  3676. fields are set up in the space dictionary records.
  3677. Seek to the right location and start writing the space
  3678. dictionary records. */
  3679. location = obj_som_file_hdr (abfd)->space_location;
  3680. if (bfd_seek (abfd, location, SEEK_SET) != 0)
  3681. return FALSE;
  3682. section = abfd->sections;
  3683. for (i = 0; i < num_spaces; i++)
  3684. {
  3685. struct som_external_space_dictionary_record ext_space_dict;
  3686. /* Find a space. */
  3687. while (!som_is_space (section))
  3688. section = section->next;
  3689. /* Dump its header. */
  3690. som_swap_space_dictionary_out (som_section_data (section)->space_dict,
  3691. &ext_space_dict);
  3692. amt = sizeof (struct som_external_space_dictionary_record);
  3693. if (bfd_bwrite (&ext_space_dict, amt, abfd) != amt)
  3694. return FALSE;
  3695. /* Goto the next section. */
  3696. section = section->next;
  3697. }
  3698. /* Write the compilation unit record if there is one. */
  3699. if (obj_som_compilation_unit (abfd))
  3700. {
  3701. struct som_external_compilation_unit ext_comp_unit;
  3702. location = obj_som_file_hdr (abfd)->compiler_location;
  3703. if (bfd_seek (abfd, location, SEEK_SET) != 0)
  3704. return FALSE;
  3705. som_swap_compilation_unit_out
  3706. (obj_som_compilation_unit (abfd), &ext_comp_unit);
  3707. amt = sizeof (struct som_external_compilation_unit);
  3708. if (bfd_bwrite (&ext_comp_unit, amt, abfd) != amt)
  3709. return FALSE;
  3710. }
  3711. /* Setting of the system_id has to happen very late now that copying of
  3712. BFD private data happens *after* section contents are set. */
  3713. if (abfd->flags & (EXEC_P | DYNAMIC))
  3714. obj_som_file_hdr (abfd)->system_id = obj_som_exec_data (abfd)->system_id;
  3715. else if (bfd_get_mach (abfd) == pa20)
  3716. obj_som_file_hdr (abfd)->system_id = CPU_PA_RISC2_0;
  3717. else if (bfd_get_mach (abfd) == pa11)
  3718. obj_som_file_hdr (abfd)->system_id = CPU_PA_RISC1_1;
  3719. else
  3720. obj_som_file_hdr (abfd)->system_id = CPU_PA_RISC1_0;
  3721. /* Swap and compute the checksum for the file header just before writing
  3722. the header to disk. */
  3723. som_swap_header_out (obj_som_file_hdr (abfd), &ext_header);
  3724. bfd_putb32 (som_compute_checksum (&ext_header), ext_header.checksum);
  3725. /* Only thing left to do is write out the file header. It is always
  3726. at location zero. Seek there and write it. */
  3727. if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
  3728. return FALSE;
  3729. amt = sizeof (struct som_external_header);
  3730. if (bfd_bwrite (&ext_header, amt, abfd) != amt)
  3731. return FALSE;
  3732. /* Now write the exec header. */
  3733. if (abfd->flags & (EXEC_P | DYNAMIC))
  3734. {
  3735. long tmp, som_length;
  3736. struct som_exec_auxhdr *exec_header;
  3737. struct som_external_exec_auxhdr ext_exec_header;
  3738. exec_header = obj_som_exec_hdr (abfd);
  3739. exec_header->exec_entry = bfd_get_start_address (abfd);
  3740. exec_header->exec_flags = obj_som_exec_data (abfd)->exec_flags;
  3741. /* Oh joys. Ram some of the BSS data into the DATA section
  3742. to be compatible with how the hp linker makes objects
  3743. (saves memory space). */
  3744. tmp = exec_header->exec_dsize;
  3745. tmp = SOM_ALIGN (tmp, PA_PAGESIZE);
  3746. exec_header->exec_bsize -= (tmp - exec_header->exec_dsize);
  3747. if (exec_header->exec_bsize < 0)
  3748. exec_header->exec_bsize = 0;
  3749. exec_header->exec_dsize = tmp;
  3750. /* Now perform some sanity checks. The idea is to catch bogons now and
  3751. inform the user, instead of silently generating a bogus file. */
  3752. som_length = obj_som_file_hdr (abfd)->som_length;
  3753. if (exec_header->exec_tfile + exec_header->exec_tsize > som_length
  3754. || exec_header->exec_dfile + exec_header->exec_dsize > som_length)
  3755. {
  3756. bfd_set_error (bfd_error_bad_value);
  3757. return FALSE;
  3758. }
  3759. som_swap_exec_auxhdr_out (exec_header, &ext_exec_header);
  3760. if (bfd_seek (abfd, obj_som_file_hdr (abfd)->aux_header_location,
  3761. SEEK_SET) != 0)
  3762. return FALSE;
  3763. amt = sizeof (ext_exec_header);
  3764. if (bfd_bwrite (&ext_exec_header, amt, abfd) != amt)
  3765. return FALSE;
  3766. }
  3767. return TRUE;
  3768. }
  3769. /* Compute and return the checksum for a SOM file header. */
  3770. static unsigned long
  3771. som_compute_checksum (struct som_external_header *hdr)
  3772. {
  3773. unsigned long checksum, count, i;
  3774. unsigned long *buffer = (unsigned long *) hdr;
  3775. checksum = 0;
  3776. count = sizeof (struct som_external_header) / 4;
  3777. for (i = 0; i < count; i++)
  3778. checksum ^= *(buffer + i);
  3779. return checksum;
  3780. }
  3781. static void
  3782. som_bfd_derive_misc_symbol_info (bfd *abfd ATTRIBUTE_UNUSED,
  3783. asymbol *sym,
  3784. struct som_misc_symbol_info *info)
  3785. {
  3786. /* Initialize. */
  3787. memset (info, 0, sizeof (struct som_misc_symbol_info));
  3788. /* The HP SOM linker requires detailed type information about
  3789. all symbols (including undefined symbols!). Unfortunately,
  3790. the type specified in an import/export statement does not
  3791. always match what the linker wants. Severe braindamage. */
  3792. /* Section symbols will not have a SOM symbol type assigned to
  3793. them yet. Assign all section symbols type ST_DATA. */
  3794. if (sym->flags & BSF_SECTION_SYM)
  3795. info->symbol_type = ST_DATA;
  3796. else
  3797. {
  3798. /* For BFD style common, the linker will choke unless we set the
  3799. type and scope to ST_STORAGE and SS_UNSAT, respectively. */
  3800. if (bfd_is_com_section (sym->section))
  3801. {
  3802. info->symbol_type = ST_STORAGE;
  3803. info->symbol_scope = SS_UNSAT;
  3804. }
  3805. /* It is possible to have a symbol without an associated
  3806. type. This happens if the user imported the symbol
  3807. without a type and the symbol was never defined
  3808. locally. If BSF_FUNCTION is set for this symbol, then
  3809. assign it type ST_CODE (the HP linker requires undefined
  3810. external functions to have type ST_CODE rather than ST_ENTRY). */
  3811. else if ((som_symbol_data (sym)->som_type == SYMBOL_TYPE_UNKNOWN
  3812. || som_symbol_data (sym)->som_type == SYMBOL_TYPE_CODE)
  3813. && bfd_is_und_section (sym->section)
  3814. && sym->flags & BSF_FUNCTION)
  3815. info->symbol_type = ST_CODE;
  3816. /* Handle function symbols which were defined in this file.
  3817. They should have type ST_ENTRY. Also retrieve the argument
  3818. relocation bits from the SOM backend information. */
  3819. else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_ENTRY
  3820. || (som_symbol_data (sym)->som_type == SYMBOL_TYPE_CODE
  3821. && (sym->flags & BSF_FUNCTION))
  3822. || (som_symbol_data (sym)->som_type == SYMBOL_TYPE_UNKNOWN
  3823. && (sym->flags & BSF_FUNCTION)))
  3824. {
  3825. info->symbol_type = ST_ENTRY;
  3826. info->arg_reloc = som_symbol_data (sym)->tc_data.ap.hppa_arg_reloc;
  3827. info->priv_level= som_symbol_data (sym)->tc_data.ap.hppa_priv_level;
  3828. }
  3829. /* For unknown symbols set the symbol's type based on the symbol's
  3830. section (ST_DATA for DATA sections, ST_CODE for CODE sections). */
  3831. else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_UNKNOWN)
  3832. {
  3833. if (bfd_is_abs_section (sym->section))
  3834. info->symbol_type = ST_ABSOLUTE;
  3835. else if (sym->section->flags & SEC_CODE)
  3836. info->symbol_type = ST_CODE;
  3837. else
  3838. info->symbol_type = ST_DATA;
  3839. }
  3840. /* From now on it's a very simple mapping. */
  3841. else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_ABSOLUTE)
  3842. info->symbol_type = ST_ABSOLUTE;
  3843. else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_CODE)
  3844. info->symbol_type = ST_CODE;
  3845. else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_DATA)
  3846. info->symbol_type = ST_DATA;
  3847. else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_MILLICODE)
  3848. info->symbol_type = ST_MILLICODE;
  3849. else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_PLABEL)
  3850. info->symbol_type = ST_PLABEL;
  3851. else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_PRI_PROG)
  3852. info->symbol_type = ST_PRI_PROG;
  3853. else if (som_symbol_data (sym)->som_type == SYMBOL_TYPE_SEC_PROG)
  3854. info->symbol_type = ST_SEC_PROG;
  3855. }
  3856. /* Now handle the symbol's scope. Exported data which is not
  3857. in the common section has scope SS_UNIVERSAL. Note scope
  3858. of common symbols was handled earlier! */
  3859. if (bfd_is_com_section (sym->section))
  3860. ;
  3861. else if (bfd_is_und_section (sym->section))
  3862. info->symbol_scope = SS_UNSAT;
  3863. else if (sym->flags & (BSF_EXPORT | BSF_WEAK))
  3864. info->symbol_scope = SS_UNIVERSAL;
  3865. /* Anything else which is not in the common section has scope
  3866. SS_LOCAL. */
  3867. else
  3868. info->symbol_scope = SS_LOCAL;
  3869. /* Now set the symbol_info field. It has no real meaning
  3870. for undefined or common symbols, but the HP linker will
  3871. choke if it's not set to some "reasonable" value. We
  3872. use zero as a reasonable value. */
  3873. if (bfd_is_com_section (sym->section)
  3874. || bfd_is_und_section (sym->section)
  3875. || bfd_is_abs_section (sym->section))
  3876. info->symbol_info = 0;
  3877. /* For all other symbols, the symbol_info field contains the
  3878. subspace index of the space this symbol is contained in. */
  3879. else
  3880. info->symbol_info = sym->section->target_index;
  3881. /* Set the symbol's value. */
  3882. info->symbol_value = sym->value + sym->section->vma;
  3883. /* The secondary_def field is for "weak" symbols. */
  3884. if (sym->flags & BSF_WEAK)
  3885. info->secondary_def = TRUE;
  3886. else
  3887. info->secondary_def = FALSE;
  3888. /* The is_comdat, is_common and dup_common fields provide various
  3889. flavors of common.
  3890. For data symbols, setting IS_COMMON provides Fortran style common
  3891. (duplicate definitions and overlapped initialization). Setting both
  3892. IS_COMMON and DUP_COMMON provides Cobol style common (duplicate
  3893. definitions as long as they are all the same length). In a shared
  3894. link data symbols retain their IS_COMMON and DUP_COMMON flags.
  3895. An IS_COMDAT data symbol is similar to a IS_COMMON | DUP_COMMON
  3896. symbol except in that it loses its IS_COMDAT flag in a shared link.
  3897. For code symbols, IS_COMDAT and DUP_COMMON have effect. Universal
  3898. DUP_COMMON code symbols are not exported from shared libraries.
  3899. IS_COMDAT symbols are exported but they lose their IS_COMDAT flag.
  3900. We take a simplified approach to setting the is_comdat, is_common
  3901. and dup_common flags in symbols based on the flag settings of their
  3902. subspace. This avoids having to add directives like `.comdat' but
  3903. the linker behavior is probably undefined if there is more than one
  3904. universal symbol (comdat key sysmbol) in a subspace.
  3905. The behavior of these flags is not well documentmented, so there
  3906. may be bugs and some surprising interactions with other flags. */
  3907. if (som_section_data (sym->section)
  3908. && som_section_data (sym->section)->subspace_dict
  3909. && info->symbol_scope == SS_UNIVERSAL
  3910. && (info->symbol_type == ST_ENTRY
  3911. || info->symbol_type == ST_CODE
  3912. || info->symbol_type == ST_DATA))
  3913. {
  3914. info->is_comdat
  3915. = som_section_data (sym->section)->subspace_dict->is_comdat;
  3916. info->is_common
  3917. = som_section_data (sym->section)->subspace_dict->is_common;
  3918. info->dup_common
  3919. = som_section_data (sym->section)->subspace_dict->dup_common;
  3920. }
  3921. }
  3922. /* Build and write, in one big chunk, the entire symbol table for
  3923. this BFD. */
  3924. static bfd_boolean
  3925. som_build_and_write_symbol_table (bfd *abfd)
  3926. {
  3927. unsigned int num_syms = bfd_get_symcount (abfd);
  3928. file_ptr symtab_location = obj_som_file_hdr (abfd)->symbol_location;
  3929. asymbol **bfd_syms = obj_som_sorted_syms (abfd);
  3930. struct som_external_symbol_dictionary_record *som_symtab = NULL;
  3931. unsigned int i;
  3932. bfd_size_type symtab_size;
  3933. /* Compute total symbol table size and allocate a chunk of memory
  3934. to hold the symbol table as we build it. */
  3935. symtab_size = num_syms;
  3936. symtab_size *= sizeof (struct som_external_symbol_dictionary_record);
  3937. som_symtab = bfd_zmalloc (symtab_size);
  3938. if (som_symtab == NULL && symtab_size != 0)
  3939. goto error_return;
  3940. /* Walk over each symbol. */
  3941. for (i = 0; i < num_syms; i++)
  3942. {
  3943. struct som_misc_symbol_info info;
  3944. unsigned int flags;
  3945. /* This is really an index into the symbol strings table.
  3946. By the time we get here, the index has already been
  3947. computed and stored into the name field in the BFD symbol. */
  3948. bfd_putb32 (som_symbol_data (bfd_syms[i])->stringtab_offset,
  3949. som_symtab[i].name);
  3950. /* Derive SOM information from the BFD symbol. */
  3951. som_bfd_derive_misc_symbol_info (abfd, bfd_syms[i], &info);
  3952. /* Now use it. */
  3953. flags = (info.symbol_type << SOM_SYMBOL_TYPE_SH)
  3954. | (info.symbol_scope << SOM_SYMBOL_SCOPE_SH)
  3955. | (info.arg_reloc << SOM_SYMBOL_ARG_RELOC_SH)
  3956. | (3 << SOM_SYMBOL_XLEAST_SH)
  3957. | (info.secondary_def ? SOM_SYMBOL_SECONDARY_DEF : 0)
  3958. | (info.is_common ? SOM_SYMBOL_IS_COMMON : 0)
  3959. | (info.dup_common ? SOM_SYMBOL_DUP_COMMON : 0);
  3960. bfd_putb32 (flags, som_symtab[i].flags);
  3961. flags = (info.symbol_info << SOM_SYMBOL_SYMBOL_INFO_SH)
  3962. | (info.is_comdat ? SOM_SYMBOL_IS_COMDAT : 0);
  3963. bfd_putb32 (flags, som_symtab[i].info);
  3964. bfd_putb32 (info.symbol_value | info.priv_level,
  3965. som_symtab[i].symbol_value);
  3966. }
  3967. /* Everything is ready, seek to the right location and
  3968. scribble out the symbol table. */
  3969. if (bfd_seek (abfd, symtab_location, SEEK_SET) != 0)
  3970. return FALSE;
  3971. if (bfd_bwrite ((void *) som_symtab, symtab_size, abfd) != symtab_size)
  3972. goto error_return;
  3973. if (som_symtab != NULL)
  3974. free (som_symtab);
  3975. return TRUE;
  3976. error_return:
  3977. if (som_symtab != NULL)
  3978. free (som_symtab);
  3979. return FALSE;
  3980. }
  3981. /* Write an object in SOM format. */
  3982. static bfd_boolean
  3983. som_write_object_contents (bfd *abfd)
  3984. {
  3985. if (! abfd->output_has_begun)
  3986. {
  3987. /* Set up fixed parts of the file, space, and subspace headers.
  3988. Notify the world that output has begun. */
  3989. som_prep_headers (abfd);
  3990. abfd->output_has_begun = TRUE;
  3991. /* Start writing the object file. This include all the string
  3992. tables, fixup streams, and other portions of the object file. */
  3993. som_begin_writing (abfd);
  3994. }
  3995. return som_finish_writing (abfd);
  3996. }
  3997. /* Read and save the string table associated with the given BFD. */
  3998. static bfd_boolean
  3999. som_slurp_string_table (bfd *abfd)
  4000. {
  4001. char *stringtab;
  4002. bfd_size_type amt;
  4003. /* Use the saved version if its available. */
  4004. if (obj_som_stringtab (abfd) != NULL)
  4005. return TRUE;
  4006. /* I don't think this can currently happen, and I'm not sure it should
  4007. really be an error, but it's better than getting unpredictable results
  4008. from the host's malloc when passed a size of zero. */
  4009. if (obj_som_stringtab_size (abfd) == 0)
  4010. {
  4011. bfd_set_error (bfd_error_no_symbols);
  4012. return FALSE;
  4013. }
  4014. /* Allocate and read in the string table. */
  4015. amt = obj_som_stringtab_size (abfd);
  4016. stringtab = bfd_zmalloc (amt);
  4017. if (stringtab == NULL)
  4018. return FALSE;
  4019. if (bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET) != 0)
  4020. return FALSE;
  4021. if (bfd_bread (stringtab, amt, abfd) != amt)
  4022. return FALSE;
  4023. /* Save our results and return success. */
  4024. obj_som_stringtab (abfd) = stringtab;
  4025. return TRUE;
  4026. }
  4027. /* Return the amount of data (in bytes) required to hold the symbol
  4028. table for this object. */
  4029. static long
  4030. som_get_symtab_upper_bound (bfd *abfd)
  4031. {
  4032. if (!som_slurp_symbol_table (abfd))
  4033. return -1;
  4034. return (bfd_get_symcount (abfd) + 1) * sizeof (asymbol *);
  4035. }
  4036. /* Convert from a SOM subspace index to a BFD section. */
  4037. asection *
  4038. bfd_section_from_som_symbol
  4039. (bfd *abfd, struct som_external_symbol_dictionary_record *symbol)
  4040. {
  4041. asection *section;
  4042. unsigned int flags = bfd_getb32 (symbol->flags);
  4043. unsigned int symbol_type = (flags >> SOM_SYMBOL_TYPE_SH) & SOM_SYMBOL_TYPE_MASK;
  4044. /* The meaning of the symbol_info field changes for functions
  4045. within executables. So only use the quick symbol_info mapping for
  4046. incomplete objects and non-function symbols in executables. */
  4047. if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0
  4048. || (symbol_type != ST_ENTRY
  4049. && symbol_type != ST_PRI_PROG
  4050. && symbol_type != ST_SEC_PROG
  4051. && symbol_type != ST_MILLICODE))
  4052. {
  4053. int idx = (bfd_getb32 (symbol->info) >> SOM_SYMBOL_SYMBOL_INFO_SH)
  4054. & SOM_SYMBOL_SYMBOL_INFO_MASK;
  4055. for (section = abfd->sections; section != NULL; section = section->next)
  4056. if (section->target_index == idx && som_is_subspace (section))
  4057. return section;
  4058. }
  4059. else
  4060. {
  4061. unsigned int value = bfd_getb32 (symbol->symbol_value);
  4062. /* For executables we will have to use the symbol's address and
  4063. find out what section would contain that address. Yuk. */
  4064. for (section = abfd->sections; section; section = section->next)
  4065. if (value >= section->vma
  4066. && value <= section->vma + section->size
  4067. && som_is_subspace (section))
  4068. return section;
  4069. }
  4070. /* Could be a symbol from an external library (such as an OMOS
  4071. shared library). Don't abort. */
  4072. return bfd_abs_section_ptr;
  4073. }
  4074. /* Read and save the symbol table associated with the given BFD. */
  4075. static unsigned int
  4076. som_slurp_symbol_table (bfd *abfd)
  4077. {
  4078. int symbol_count = bfd_get_symcount (abfd);
  4079. int symsize = sizeof (struct som_external_symbol_dictionary_record);
  4080. char *stringtab;
  4081. struct som_external_symbol_dictionary_record *buf = NULL, *bufp, *endbufp;
  4082. som_symbol_type *sym, *symbase;
  4083. bfd_size_type amt;
  4084. /* Return saved value if it exists. */
  4085. if (obj_som_symtab (abfd) != NULL)
  4086. goto successful_return;
  4087. /* Special case. This is *not* an error. */
  4088. if (symbol_count == 0)
  4089. goto successful_return;
  4090. if (!som_slurp_string_table (abfd))
  4091. goto error_return;
  4092. stringtab = obj_som_stringtab (abfd);
  4093. amt = symbol_count;
  4094. amt *= sizeof (som_symbol_type);
  4095. symbase = bfd_zmalloc (amt);
  4096. if (symbase == NULL)
  4097. goto error_return;
  4098. /* Read in the external SOM representation. */
  4099. amt = symbol_count;
  4100. amt *= symsize;
  4101. buf = bfd_malloc (amt);
  4102. if (buf == NULL && amt != 0)
  4103. goto error_return;
  4104. if (bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET) != 0)
  4105. goto error_return;
  4106. if (bfd_bread (buf, amt, abfd) != amt)
  4107. goto error_return;
  4108. /* Iterate over all the symbols and internalize them. */
  4109. endbufp = buf + symbol_count;
  4110. for (bufp = buf, sym = symbase; bufp < endbufp; ++bufp)
  4111. {
  4112. unsigned int flags = bfd_getb32 (bufp->flags);
  4113. unsigned int symbol_type =
  4114. (flags >> SOM_SYMBOL_TYPE_SH) & SOM_SYMBOL_TYPE_MASK;
  4115. unsigned int symbol_scope =
  4116. (flags >> SOM_SYMBOL_SCOPE_SH) & SOM_SYMBOL_SCOPE_MASK;
  4117. /* I don't think we care about these. */
  4118. if (symbol_type == ST_SYM_EXT || symbol_type == ST_ARG_EXT)
  4119. continue;
  4120. /* Set some private data we care about. */
  4121. if (symbol_type == ST_NULL)
  4122. som_symbol_data (sym)->som_type = SYMBOL_TYPE_UNKNOWN;
  4123. else if (symbol_type == ST_ABSOLUTE)
  4124. som_symbol_data (sym)->som_type = SYMBOL_TYPE_ABSOLUTE;
  4125. else if (symbol_type == ST_DATA)
  4126. som_symbol_data (sym)->som_type = SYMBOL_TYPE_DATA;
  4127. else if (symbol_type == ST_CODE)
  4128. som_symbol_data (sym)->som_type = SYMBOL_TYPE_CODE;
  4129. else if (symbol_type == ST_PRI_PROG)
  4130. som_symbol_data (sym)->som_type = SYMBOL_TYPE_PRI_PROG;
  4131. else if (symbol_type == ST_SEC_PROG)
  4132. som_symbol_data (sym)->som_type = SYMBOL_TYPE_SEC_PROG;
  4133. else if (symbol_type == ST_ENTRY)
  4134. som_symbol_data (sym)->som_type = SYMBOL_TYPE_ENTRY;
  4135. else if (symbol_type == ST_MILLICODE)
  4136. som_symbol_data (sym)->som_type = SYMBOL_TYPE_MILLICODE;
  4137. else if (symbol_type == ST_PLABEL)
  4138. som_symbol_data (sym)->som_type = SYMBOL_TYPE_PLABEL;
  4139. else
  4140. som_symbol_data (sym)->som_type = SYMBOL_TYPE_UNKNOWN;
  4141. som_symbol_data (sym)->tc_data.ap.hppa_arg_reloc =
  4142. (flags >> SOM_SYMBOL_ARG_RELOC_SH) & SOM_SYMBOL_ARG_RELOC_MASK;
  4143. /* Some reasonable defaults. */
  4144. sym->symbol.the_bfd = abfd;
  4145. sym->symbol.name = bfd_getb32 (bufp->name) + stringtab;
  4146. sym->symbol.value = bfd_getb32 (bufp->symbol_value);
  4147. sym->symbol.section = 0;
  4148. sym->symbol.flags = 0;
  4149. switch (symbol_type)
  4150. {
  4151. case ST_ENTRY:
  4152. case ST_MILLICODE:
  4153. sym->symbol.flags |= BSF_FUNCTION;
  4154. som_symbol_data (sym)->tc_data.ap.hppa_priv_level =
  4155. sym->symbol.value & 0x3;
  4156. sym->symbol.value &= ~0x3;
  4157. break;
  4158. case ST_STUB:
  4159. case ST_CODE:
  4160. case ST_PRI_PROG:
  4161. case ST_SEC_PROG:
  4162. som_symbol_data (sym)->tc_data.ap.hppa_priv_level =
  4163. sym->symbol.value & 0x3;
  4164. sym->symbol.value &= ~0x3;
  4165. /* If the symbol's scope is SS_UNSAT, then these are
  4166. undefined function symbols. */
  4167. if (symbol_scope == SS_UNSAT)
  4168. sym->symbol.flags |= BSF_FUNCTION;
  4169. default:
  4170. break;
  4171. }
  4172. /* Handle scoping and section information. */
  4173. switch (symbol_scope)
  4174. {
  4175. /* symbol_info field is undefined for SS_EXTERNAL and SS_UNSAT symbols,
  4176. so the section associated with this symbol can't be known. */
  4177. case SS_EXTERNAL:
  4178. if (symbol_type != ST_STORAGE)
  4179. sym->symbol.section = bfd_und_section_ptr;
  4180. else
  4181. sym->symbol.section = bfd_com_section_ptr;
  4182. sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
  4183. break;
  4184. case SS_UNSAT:
  4185. if (symbol_type != ST_STORAGE)
  4186. sym->symbol.section = bfd_und_section_ptr;
  4187. else
  4188. sym->symbol.section = bfd_com_section_ptr;
  4189. break;
  4190. case SS_UNIVERSAL:
  4191. sym->symbol.flags |= (BSF_EXPORT | BSF_GLOBAL);
  4192. sym->symbol.section = bfd_section_from_som_symbol (abfd, bufp);
  4193. sym->symbol.value -= sym->symbol.section->vma;
  4194. break;
  4195. case SS_LOCAL:
  4196. sym->symbol.flags |= BSF_LOCAL;
  4197. sym->symbol.section = bfd_section_from_som_symbol (abfd, bufp);
  4198. sym->symbol.value -= sym->symbol.section->vma;
  4199. break;
  4200. }
  4201. /* Check for a weak symbol. */
  4202. if (flags & SOM_SYMBOL_SECONDARY_DEF)
  4203. sym->symbol.flags |= BSF_WEAK;
  4204. /* Mark section symbols and symbols used by the debugger.
  4205. Note $START$ is a magic code symbol, NOT a section symbol. */
  4206. if (sym->symbol.name[0] == '$'
  4207. && sym->symbol.name[strlen (sym->symbol.name) - 1] == '$'
  4208. && !strcmp (sym->symbol.name, sym->symbol.section->name))
  4209. sym->symbol.flags |= BSF_SECTION_SYM;
  4210. else if (CONST_STRNEQ (sym->symbol.name, "L$0\002"))
  4211. {
  4212. sym->symbol.flags |= BSF_SECTION_SYM;
  4213. sym->symbol.name = sym->symbol.section->name;
  4214. }
  4215. else if (CONST_STRNEQ (sym->symbol.name, "L$0\001"))
  4216. sym->symbol.flags |= BSF_DEBUGGING;
  4217. /* Note increment at bottom of loop, since we skip some symbols
  4218. we can not include it as part of the for statement. */
  4219. sym++;
  4220. }
  4221. /* We modify the symbol count to record the number of BFD symbols we
  4222. created. */
  4223. bfd_get_symcount (abfd) = sym - symbase;
  4224. /* Save our results and return success. */
  4225. obj_som_symtab (abfd) = symbase;
  4226. successful_return:
  4227. if (buf != NULL)
  4228. free (buf);
  4229. return (TRUE);
  4230. error_return:
  4231. if (buf != NULL)
  4232. free (buf);
  4233. return FALSE;
  4234. }
  4235. /* Canonicalize a SOM symbol table. Return the number of entries
  4236. in the symbol table. */
  4237. static long
  4238. som_canonicalize_symtab (bfd *abfd, asymbol **location)
  4239. {
  4240. int i;
  4241. som_symbol_type *symbase;
  4242. if (!som_slurp_symbol_table (abfd))
  4243. return -1;
  4244. i = bfd_get_symcount (abfd);
  4245. symbase = obj_som_symtab (abfd);
  4246. for (; i > 0; i--, location++, symbase++)
  4247. *location = &symbase->symbol;
  4248. /* Final null pointer. */
  4249. *location = 0;
  4250. return (bfd_get_symcount (abfd));
  4251. }
  4252. /* Make a SOM symbol. There is nothing special to do here. */
  4253. static asymbol *
  4254. som_make_empty_symbol (bfd *abfd)
  4255. {
  4256. bfd_size_type amt = sizeof (som_symbol_type);
  4257. som_symbol_type *new_symbol_type = bfd_zalloc (abfd, amt);
  4258. if (new_symbol_type == NULL)
  4259. return NULL;
  4260. new_symbol_type->symbol.the_bfd = abfd;
  4261. return &new_symbol_type->symbol;
  4262. }
  4263. /* Print symbol information. */
  4264. static void
  4265. som_print_symbol (bfd *abfd,
  4266. void *afile,
  4267. asymbol *symbol,
  4268. bfd_print_symbol_type how)
  4269. {
  4270. FILE *file = (FILE *) afile;
  4271. switch (how)
  4272. {
  4273. case bfd_print_symbol_name:
  4274. fprintf (file, "%s", symbol->name);
  4275. break;
  4276. case bfd_print_symbol_more:
  4277. fprintf (file, "som ");
  4278. fprintf_vma (file, symbol->value);
  4279. fprintf (file, " %lx", (long) symbol->flags);
  4280. break;
  4281. case bfd_print_symbol_all:
  4282. {
  4283. const char *section_name;
  4284. section_name = symbol->section ? symbol->section->name : "(*none*)";
  4285. bfd_print_symbol_vandf (abfd, (void *) file, symbol);
  4286. fprintf (file, " %s\t%s", section_name, symbol->name);
  4287. break;
  4288. }
  4289. }
  4290. }
  4291. static bfd_boolean
  4292. som_bfd_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED,
  4293. const char *name)
  4294. {
  4295. return name[0] == 'L' && name[1] == '$';
  4296. }
  4297. /* Count or process variable-length SOM fixup records.
  4298. To avoid code duplication we use this code both to compute the number
  4299. of relocations requested by a stream, and to internalize the stream.
  4300. When computing the number of relocations requested by a stream the
  4301. variables rptr, section, and symbols have no meaning.
  4302. Return the number of relocations requested by the fixup stream. When
  4303. not just counting
  4304. This needs at least two or three more passes to get it cleaned up. */
  4305. static unsigned int
  4306. som_set_reloc_info (unsigned char *fixup,
  4307. unsigned int end,
  4308. arelent *internal_relocs,
  4309. asection *section,
  4310. asymbol **symbols,
  4311. bfd_boolean just_count)
  4312. {
  4313. unsigned int op, varname, deallocate_contents = 0;
  4314. unsigned char *end_fixups = &fixup[end];
  4315. const struct fixup_format *fp;
  4316. const char *cp;
  4317. unsigned char *save_fixup;
  4318. int variables[26], stack[20], c, v, count, prev_fixup, *sp, saved_unwind_bits;
  4319. const int *subop;
  4320. arelent *rptr = internal_relocs;
  4321. unsigned int offset = 0;
  4322. #define var(c) variables[(c) - 'A']
  4323. #define push(v) (*sp++ = (v))
  4324. #define pop() (*--sp)
  4325. #define emptystack() (sp == stack)
  4326. som_initialize_reloc_queue (reloc_queue);
  4327. memset (variables, 0, sizeof (variables));
  4328. memset (stack, 0, sizeof (stack));
  4329. count = 0;
  4330. prev_fixup = 0;
  4331. saved_unwind_bits = 0;
  4332. sp = stack;
  4333. while (fixup < end_fixups)
  4334. {
  4335. /* Save pointer to the start of this fixup. We'll use
  4336. it later to determine if it is necessary to put this fixup
  4337. on the queue. */
  4338. save_fixup = fixup;
  4339. /* Get the fixup code and its associated format. */
  4340. op = *fixup++;
  4341. fp = &som_fixup_formats[op];
  4342. /* Handle a request for a previous fixup. */
  4343. if (*fp->format == 'P')
  4344. {
  4345. /* Get pointer to the beginning of the prev fixup, move
  4346. the repeated fixup to the head of the queue. */
  4347. fixup = reloc_queue[fp->D].reloc;
  4348. som_reloc_queue_fix (reloc_queue, fp->D);
  4349. prev_fixup = 1;
  4350. /* Get the fixup code and its associated format. */
  4351. op = *fixup++;
  4352. fp = &som_fixup_formats[op];
  4353. }
  4354. /* If this fixup will be passed to BFD, set some reasonable defaults. */
  4355. if (! just_count
  4356. && som_hppa_howto_table[op].type != R_NO_RELOCATION
  4357. && som_hppa_howto_table[op].type != R_DATA_OVERRIDE)
  4358. {
  4359. rptr->address = offset;
  4360. rptr->howto = &som_hppa_howto_table[op];
  4361. rptr->addend = 0;
  4362. rptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
  4363. }
  4364. /* Set default input length to 0. Get the opcode class index
  4365. into D. */
  4366. var ('L') = 0;
  4367. var ('D') = fp->D;
  4368. var ('U') = saved_unwind_bits;
  4369. /* Get the opcode format. */
  4370. cp = fp->format;
  4371. /* Process the format string. Parsing happens in two phases,
  4372. parse RHS, then assign to LHS. Repeat until no more
  4373. characters in the format string. */
  4374. while (*cp)
  4375. {
  4376. /* The variable this pass is going to compute a value for. */
  4377. varname = *cp++;
  4378. /* Start processing RHS. Continue until a NULL or '=' is found. */
  4379. do
  4380. {
  4381. c = *cp++;
  4382. /* If this is a variable, push it on the stack. */
  4383. if (ISUPPER (c))
  4384. push (var (c));
  4385. /* If this is a lower case letter, then it represents
  4386. additional data from the fixup stream to be pushed onto
  4387. the stack. */
  4388. else if (ISLOWER (c))
  4389. {
  4390. int bits = (c - 'a') * 8;
  4391. for (v = 0; c > 'a'; --c)
  4392. v = (v << 8) | *fixup++;
  4393. if (varname == 'V')
  4394. v = sign_extend (v, bits);
  4395. push (v);
  4396. }
  4397. /* A decimal constant. Push it on the stack. */
  4398. else if (ISDIGIT (c))
  4399. {
  4400. v = c - '0';
  4401. while (ISDIGIT (*cp))
  4402. v = (v * 10) + (*cp++ - '0');
  4403. push (v);
  4404. }
  4405. else
  4406. /* An operator. Pop two two values from the stack and
  4407. use them as operands to the given operation. Push
  4408. the result of the operation back on the stack. */
  4409. switch (c)
  4410. {
  4411. case '+':
  4412. v = pop ();
  4413. v += pop ();
  4414. push (v);
  4415. break;
  4416. case '*':
  4417. v = pop ();
  4418. v *= pop ();
  4419. push (v);
  4420. break;
  4421. case '<':
  4422. v = pop ();
  4423. v = pop () << v;
  4424. push (v);
  4425. break;
  4426. default:
  4427. abort ();
  4428. }
  4429. }
  4430. while (*cp && *cp != '=');
  4431. /* Move over the equal operator. */
  4432. cp++;
  4433. /* Pop the RHS off the stack. */
  4434. c = pop ();
  4435. /* Perform the assignment. */
  4436. var (varname) = c;
  4437. /* Handle side effects. and special 'O' stack cases. */
  4438. switch (varname)
  4439. {
  4440. /* Consume some bytes from the input space. */
  4441. case 'L':
  4442. offset += c;
  4443. break;
  4444. /* A symbol to use in the relocation. Make a note
  4445. of this if we are not just counting. */
  4446. case 'S':
  4447. if (! just_count)
  4448. rptr->sym_ptr_ptr = &symbols[c];
  4449. break;
  4450. /* Argument relocation bits for a function call. */
  4451. case 'R':
  4452. if (! just_count)
  4453. {
  4454. unsigned int tmp = var ('R');
  4455. rptr->addend = 0;
  4456. if ((som_hppa_howto_table[op].type == R_PCREL_CALL
  4457. && R_PCREL_CALL + 10 > op)
  4458. || (som_hppa_howto_table[op].type == R_ABS_CALL
  4459. && R_ABS_CALL + 10 > op))
  4460. {
  4461. /* Simple encoding. */
  4462. if (tmp > 4)
  4463. {
  4464. tmp -= 5;
  4465. rptr->addend |= 1;
  4466. }
  4467. if (tmp == 4)
  4468. rptr->addend |= 1 << 8 | 1 << 6 | 1 << 4 | 1 << 2;
  4469. else if (tmp == 3)
  4470. rptr->addend |= 1 << 8 | 1 << 6 | 1 << 4;
  4471. else if (tmp == 2)
  4472. rptr->addend |= 1 << 8 | 1 << 6;
  4473. else if (tmp == 1)
  4474. rptr->addend |= 1 << 8;
  4475. }
  4476. else
  4477. {
  4478. unsigned int tmp1, tmp2;
  4479. /* First part is easy -- low order two bits are
  4480. directly copied, then shifted away. */
  4481. rptr->addend = tmp & 0x3;
  4482. tmp >>= 2;
  4483. /* Diving the result by 10 gives us the second
  4484. part. If it is 9, then the first two words
  4485. are a double precision paramater, else it is
  4486. 3 * the first arg bits + the 2nd arg bits. */
  4487. tmp1 = tmp / 10;
  4488. tmp -= tmp1 * 10;
  4489. if (tmp1 == 9)
  4490. rptr->addend += (0xe << 6);
  4491. else
  4492. {
  4493. /* Get the two pieces. */
  4494. tmp2 = tmp1 / 3;
  4495. tmp1 -= tmp2 * 3;
  4496. /* Put them in the addend. */
  4497. rptr->addend += (tmp2 << 8) + (tmp1 << 6);
  4498. }
  4499. /* What's left is the third part. It's unpacked
  4500. just like the second. */
  4501. if (tmp == 9)
  4502. rptr->addend += (0xe << 2);
  4503. else
  4504. {
  4505. tmp2 = tmp / 3;
  4506. tmp -= tmp2 * 3;
  4507. rptr->addend += (tmp2 << 4) + (tmp << 2);
  4508. }
  4509. }
  4510. rptr->addend = HPPA_R_ADDEND (rptr->addend, 0);
  4511. }
  4512. break;
  4513. /* Handle the linker expression stack. */
  4514. case 'O':
  4515. switch (op)
  4516. {
  4517. case R_COMP1:
  4518. subop = comp1_opcodes;
  4519. break;
  4520. case R_COMP2:
  4521. subop = comp2_opcodes;
  4522. break;
  4523. case R_COMP3:
  4524. subop = comp3_opcodes;
  4525. break;
  4526. default:
  4527. abort ();
  4528. }
  4529. while (*subop <= (unsigned char) c)
  4530. ++subop;
  4531. --subop;
  4532. break;
  4533. /* The lower 32unwind bits must be persistent. */
  4534. case 'U':
  4535. saved_unwind_bits = var ('U');
  4536. break;
  4537. default:
  4538. break;
  4539. }
  4540. }
  4541. /* If we used a previous fixup, clean up after it. */
  4542. if (prev_fixup)
  4543. {
  4544. fixup = save_fixup + 1;
  4545. prev_fixup = 0;
  4546. }
  4547. /* Queue it. */
  4548. else if (fixup > save_fixup + 1)
  4549. som_reloc_queue_insert (save_fixup, fixup - save_fixup, reloc_queue);
  4550. /* We do not pass R_DATA_OVERRIDE or R_NO_RELOCATION
  4551. fixups to BFD. */
  4552. if (som_hppa_howto_table[op].type != R_DATA_OVERRIDE
  4553. && som_hppa_howto_table[op].type != R_NO_RELOCATION)
  4554. {
  4555. /* Done with a single reloction. Loop back to the top. */
  4556. if (! just_count)
  4557. {
  4558. if (som_hppa_howto_table[op].type == R_ENTRY)
  4559. rptr->addend = var ('T');
  4560. else if (som_hppa_howto_table[op].type == R_EXIT)
  4561. rptr->addend = var ('U');
  4562. else if (som_hppa_howto_table[op].type == R_PCREL_CALL
  4563. || som_hppa_howto_table[op].type == R_ABS_CALL)
  4564. ;
  4565. else if (som_hppa_howto_table[op].type == R_DATA_ONE_SYMBOL)
  4566. {
  4567. /* Try what was specified in R_DATA_OVERRIDE first
  4568. (if anything). Then the hard way using the
  4569. section contents. */
  4570. rptr->addend = var ('V');
  4571. if (rptr->addend == 0 && !section->contents)
  4572. {
  4573. /* Got to read the damn contents first. We don't
  4574. bother saving the contents (yet). Add it one
  4575. day if the need arises. */
  4576. bfd_byte *contents;
  4577. if (!bfd_malloc_and_get_section (section->owner, section,
  4578. &contents))
  4579. {
  4580. if (contents != NULL)
  4581. free (contents);
  4582. return (unsigned) -1;
  4583. }
  4584. section->contents = contents;
  4585. deallocate_contents = 1;
  4586. }
  4587. else if (rptr->addend == 0)
  4588. rptr->addend = bfd_get_32 (section->owner,
  4589. (section->contents
  4590. + offset - var ('L')));
  4591. }
  4592. else
  4593. rptr->addend = var ('V');
  4594. rptr++;
  4595. }
  4596. count++;
  4597. /* Now that we've handled a "full" relocation, reset
  4598. some state. */
  4599. memset (variables, 0, sizeof (variables));
  4600. memset (stack, 0, sizeof (stack));
  4601. }
  4602. }
  4603. if (deallocate_contents)
  4604. free (section->contents);
  4605. return count;
  4606. #undef var
  4607. #undef push
  4608. #undef pop
  4609. #undef emptystack
  4610. }
  4611. /* Read in the relocs (aka fixups in SOM terms) for a section.
  4612. som_get_reloc_upper_bound calls this routine with JUST_COUNT
  4613. set to TRUE to indicate it only needs a count of the number
  4614. of actual relocations. */
  4615. static bfd_boolean
  4616. som_slurp_reloc_table (bfd *abfd,
  4617. asection *section,
  4618. asymbol **symbols,
  4619. bfd_boolean just_count)
  4620. {
  4621. unsigned char *external_relocs;
  4622. unsigned int fixup_stream_size;
  4623. arelent *internal_relocs;
  4624. unsigned int num_relocs;
  4625. bfd_size_type amt;
  4626. fixup_stream_size = som_section_data (section)->reloc_size;
  4627. /* If there were no relocations, then there is nothing to do. */
  4628. if (section->reloc_count == 0)
  4629. return TRUE;
  4630. /* If reloc_count is -1, then the relocation stream has not been
  4631. parsed. We must do so now to know how many relocations exist. */
  4632. if (section->reloc_count == (unsigned) -1)
  4633. {
  4634. amt = fixup_stream_size;
  4635. external_relocs = bfd_malloc (amt);
  4636. if (external_relocs == NULL)
  4637. return FALSE;
  4638. /* Read in the external forms. */
  4639. if (bfd_seek (abfd,
  4640. obj_som_reloc_filepos (abfd) + section->rel_filepos,
  4641. SEEK_SET)
  4642. != 0)
  4643. return FALSE;
  4644. if (bfd_bread (external_relocs, amt, abfd) != amt)
  4645. return FALSE;
  4646. /* Let callers know how many relocations found.
  4647. also save the relocation stream as we will
  4648. need it again. */
  4649. section->reloc_count = som_set_reloc_info (external_relocs,
  4650. fixup_stream_size,
  4651. NULL, NULL, NULL, TRUE);
  4652. som_section_data (section)->reloc_stream = external_relocs;
  4653. }
  4654. /* If the caller only wanted a count, then return now. */
  4655. if (just_count)
  4656. return TRUE;
  4657. num_relocs = section->reloc_count;
  4658. external_relocs = som_section_data (section)->reloc_stream;
  4659. /* Return saved information about the relocations if it is available. */
  4660. if (section->relocation != NULL)
  4661. return TRUE;
  4662. amt = num_relocs;
  4663. amt *= sizeof (arelent);
  4664. internal_relocs = bfd_zalloc (abfd, (amt));
  4665. if (internal_relocs == NULL)
  4666. return FALSE;
  4667. /* Process and internalize the relocations. */
  4668. som_set_reloc_info (external_relocs, fixup_stream_size,
  4669. internal_relocs, section, symbols, FALSE);
  4670. /* We're done with the external relocations. Free them. */
  4671. free (external_relocs);
  4672. som_section_data (section)->reloc_stream = NULL;
  4673. /* Save our results and return success. */
  4674. section->relocation = internal_relocs;
  4675. return TRUE;
  4676. }
  4677. /* Return the number of bytes required to store the relocation
  4678. information associated with the given section. */
  4679. static long
  4680. som_get_reloc_upper_bound (bfd *abfd, sec_ptr asect)
  4681. {
  4682. /* If section has relocations, then read in the relocation stream
  4683. and parse it to determine how many relocations exist. */
  4684. if (asect->flags & SEC_RELOC)
  4685. {
  4686. if (! som_slurp_reloc_table (abfd, asect, NULL, TRUE))
  4687. return -1;
  4688. return (asect->reloc_count + 1) * sizeof (arelent *);
  4689. }
  4690. /* There are no relocations. Return enough space to hold the
  4691. NULL pointer which will be installed if som_canonicalize_reloc
  4692. is called. */
  4693. return sizeof (arelent *);
  4694. }
  4695. /* Convert relocations from SOM (external) form into BFD internal
  4696. form. Return the number of relocations. */
  4697. static long
  4698. som_canonicalize_reloc (bfd *abfd,
  4699. sec_ptr section,
  4700. arelent **relptr,
  4701. asymbol **symbols)
  4702. {
  4703. arelent *tblptr;
  4704. int count;
  4705. if (! som_slurp_reloc_table (abfd, section, symbols, FALSE))
  4706. return -1;
  4707. count = section->reloc_count;
  4708. tblptr = section->relocation;
  4709. while (count--)
  4710. *relptr++ = tblptr++;
  4711. *relptr = NULL;
  4712. return section->reloc_count;
  4713. }
  4714. extern const bfd_target hppa_som_vec;
  4715. /* A hook to set up object file dependent section information. */
  4716. static bfd_boolean
  4717. som_new_section_hook (bfd *abfd, asection *newsect)
  4718. {
  4719. if (!newsect->used_by_bfd)
  4720. {
  4721. bfd_size_type amt = sizeof (struct som_section_data_struct);
  4722. newsect->used_by_bfd = bfd_zalloc (abfd, amt);
  4723. if (!newsect->used_by_bfd)
  4724. return FALSE;
  4725. }
  4726. newsect->alignment_power = 3;
  4727. /* We allow more than three sections internally. */
  4728. return _bfd_generic_new_section_hook (abfd, newsect);
  4729. }
  4730. /* Copy any private info we understand from the input symbol
  4731. to the output symbol. */
  4732. static bfd_boolean
  4733. som_bfd_copy_private_symbol_data (bfd *ibfd,
  4734. asymbol *isymbol,
  4735. bfd *obfd,
  4736. asymbol *osymbol)
  4737. {
  4738. struct som_symbol *input_symbol = (struct som_symbol *) isymbol;
  4739. struct som_symbol *output_symbol = (struct som_symbol *) osymbol;
  4740. /* One day we may try to grok other private data. */
  4741. if (ibfd->xvec->flavour != bfd_target_som_flavour
  4742. || obfd->xvec->flavour != bfd_target_som_flavour)
  4743. return FALSE;
  4744. /* The only private information we need to copy is the argument relocation
  4745. bits. */
  4746. output_symbol->tc_data.ap.hppa_arg_reloc =
  4747. input_symbol->tc_data.ap.hppa_arg_reloc;
  4748. return TRUE;
  4749. }
  4750. /* Copy any private info we understand from the input section
  4751. to the output section. */
  4752. static bfd_boolean
  4753. som_bfd_copy_private_section_data (bfd *ibfd,
  4754. asection *isection,
  4755. bfd *obfd,
  4756. asection *osection)
  4757. {
  4758. bfd_size_type amt;
  4759. /* One day we may try to grok other private data. */
  4760. if (ibfd->xvec->flavour != bfd_target_som_flavour
  4761. || obfd->xvec->flavour != bfd_target_som_flavour
  4762. || (!som_is_space (isection) && !som_is_subspace (isection)))
  4763. return TRUE;
  4764. amt = sizeof (struct som_copyable_section_data_struct);
  4765. som_section_data (osection)->copy_data = bfd_zalloc (obfd, amt);
  4766. if (som_section_data (osection)->copy_data == NULL)
  4767. return FALSE;
  4768. memcpy (som_section_data (osection)->copy_data,
  4769. som_section_data (isection)->copy_data,
  4770. sizeof (struct som_copyable_section_data_struct));
  4771. /* Reparent if necessary. */
  4772. if (som_section_data (osection)->copy_data->container)
  4773. som_section_data (osection)->copy_data->container =
  4774. som_section_data (osection)->copy_data->container->output_section;
  4775. return TRUE;
  4776. }
  4777. /* Copy any private info we understand from the input bfd
  4778. to the output bfd. */
  4779. static bfd_boolean
  4780. som_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
  4781. {
  4782. /* One day we may try to grok other private data. */
  4783. if (ibfd->xvec->flavour != bfd_target_som_flavour
  4784. || obfd->xvec->flavour != bfd_target_som_flavour)
  4785. return TRUE;
  4786. /* Allocate some memory to hold the data we need. */
  4787. obj_som_exec_data (obfd) = bfd_zalloc (obfd, (bfd_size_type) sizeof (struct som_exec_data));
  4788. if (obj_som_exec_data (obfd) == NULL)
  4789. return FALSE;
  4790. /* Now copy the data. */
  4791. memcpy (obj_som_exec_data (obfd), obj_som_exec_data (ibfd),
  4792. sizeof (struct som_exec_data));
  4793. return TRUE;
  4794. }
  4795. /* Display the SOM header. */
  4796. static bfd_boolean
  4797. som_bfd_print_private_bfd_data (bfd *abfd, void *farg)
  4798. {
  4799. struct som_exec_auxhdr *exec_header;
  4800. struct som_aux_id* auxhdr;
  4801. FILE *f;
  4802. f = (FILE *) farg;
  4803. exec_header = obj_som_exec_hdr (abfd);
  4804. if (exec_header)
  4805. {
  4806. fprintf (f, _("\nExec Auxiliary Header\n"));
  4807. fprintf (f, " flags ");
  4808. auxhdr = &exec_header->som_auxhdr;
  4809. if (auxhdr->mandatory)
  4810. fprintf (f, "mandatory ");
  4811. if (auxhdr->copy)
  4812. fprintf (f, "copy ");
  4813. if (auxhdr->append)
  4814. fprintf (f, "append ");
  4815. if (auxhdr->ignore)
  4816. fprintf (f, "ignore ");
  4817. fprintf (f, "\n");
  4818. fprintf (f, " type %#x\n", auxhdr->type);
  4819. fprintf (f, " length %#x\n", auxhdr->length);
  4820. /* Note that, depending on the HP-UX version, the following fields can be
  4821. either ints, or longs. */
  4822. fprintf (f, " text size %#lx\n", (long) exec_header->exec_tsize);
  4823. fprintf (f, " text memory offset %#lx\n", (long) exec_header->exec_tmem);
  4824. fprintf (f, " text file offset %#lx\n", (long) exec_header->exec_tfile);
  4825. fprintf (f, " data size %#lx\n", (long) exec_header->exec_dsize);
  4826. fprintf (f, " data memory offset %#lx\n", (long) exec_header->exec_dmem);
  4827. fprintf (f, " data file offset %#lx\n", (long) exec_header->exec_dfile);
  4828. fprintf (f, " bss size %#lx\n", (long) exec_header->exec_bsize);
  4829. fprintf (f, " entry point %#lx\n", (long) exec_header->exec_entry);
  4830. fprintf (f, " loader flags %#lx\n", (long) exec_header->exec_flags);
  4831. fprintf (f, " bss initializer %#lx\n", (long) exec_header->exec_bfill);
  4832. }
  4833. return TRUE;
  4834. }
  4835. /* Set backend info for sections which can not be described
  4836. in the BFD data structures. */
  4837. bfd_boolean
  4838. bfd_som_set_section_attributes (asection *section,
  4839. int defined,
  4840. int private,
  4841. unsigned int sort_key,
  4842. int spnum)
  4843. {
  4844. /* Allocate memory to hold the magic information. */
  4845. if (som_section_data (section)->copy_data == NULL)
  4846. {
  4847. bfd_size_type amt = sizeof (struct som_copyable_section_data_struct);
  4848. som_section_data (section)->copy_data = bfd_zalloc (section->owner, amt);
  4849. if (som_section_data (section)->copy_data == NULL)
  4850. return FALSE;
  4851. }
  4852. som_section_data (section)->copy_data->sort_key = sort_key;
  4853. som_section_data (section)->copy_data->is_defined = defined;
  4854. som_section_data (section)->copy_data->is_private = private;
  4855. som_section_data (section)->copy_data->container = section;
  4856. som_section_data (section)->copy_data->space_number = spnum;
  4857. return TRUE;
  4858. }
  4859. /* Set backend info for subsections which can not be described
  4860. in the BFD data structures. */
  4861. bfd_boolean
  4862. bfd_som_set_subsection_attributes (asection *section,
  4863. asection *container,
  4864. int access_ctr,
  4865. unsigned int sort_key,
  4866. int quadrant,
  4867. int comdat,
  4868. int common,
  4869. int dup_common)
  4870. {
  4871. /* Allocate memory to hold the magic information. */
  4872. if (som_section_data (section)->copy_data == NULL)
  4873. {
  4874. bfd_size_type amt = sizeof (struct som_copyable_section_data_struct);
  4875. som_section_data (section)->copy_data = bfd_zalloc (section->owner, amt);
  4876. if (som_section_data (section)->copy_data == NULL)
  4877. return FALSE;
  4878. }
  4879. som_section_data (section)->copy_data->sort_key = sort_key;
  4880. som_section_data (section)->copy_data->access_control_bits = access_ctr;
  4881. som_section_data (section)->copy_data->quadrant = quadrant;
  4882. som_section_data (section)->copy_data->container = container;
  4883. som_section_data (section)->copy_data->is_comdat = comdat;
  4884. som_section_data (section)->copy_data->is_common = common;
  4885. som_section_data (section)->copy_data->dup_common = dup_common;
  4886. return TRUE;
  4887. }
  4888. /* Set the full SOM symbol type. SOM needs far more symbol information
  4889. than any other object file format I'm aware of. It is mandatory
  4890. to be able to know if a symbol is an entry point, millicode, data,
  4891. code, absolute, storage request, or procedure label. If you get
  4892. the symbol type wrong your program will not link. */
  4893. void
  4894. bfd_som_set_symbol_type (asymbol *symbol, unsigned int type)
  4895. {
  4896. som_symbol_data (symbol)->som_type = type;
  4897. }
  4898. /* Attach an auxiliary header to the BFD backend so that it may be
  4899. written into the object file. */
  4900. bfd_boolean
  4901. bfd_som_attach_aux_hdr (bfd *abfd, int type, char *string)
  4902. {
  4903. bfd_size_type amt;
  4904. if (type == VERSION_AUX_ID)
  4905. {
  4906. size_t len = strlen (string);
  4907. int pad = 0;
  4908. if (len % 4)
  4909. pad = (4 - (len % 4));
  4910. amt = sizeof (struct som_string_auxhdr) + len + pad;
  4911. obj_som_version_hdr (abfd) = bfd_zalloc (abfd, amt);
  4912. if (!obj_som_version_hdr (abfd))
  4913. return FALSE;
  4914. obj_som_version_hdr (abfd)->header_id.type = VERSION_AUX_ID;
  4915. obj_som_version_hdr (abfd)->header_id.length = 4 + len + pad;
  4916. obj_som_version_hdr (abfd)->string_length = len;
  4917. memcpy (obj_som_version_hdr (abfd)->string, string, len);
  4918. memset (obj_som_version_hdr (abfd)->string + len, 0, pad);
  4919. }
  4920. else if (type == COPYRIGHT_AUX_ID)
  4921. {
  4922. int len = strlen (string);
  4923. int pad = 0;
  4924. if (len % 4)
  4925. pad = (4 - (len % 4));
  4926. amt = sizeof (struct som_string_auxhdr) + len + pad;
  4927. obj_som_copyright_hdr (abfd) = bfd_zalloc (abfd, amt);
  4928. if (!obj_som_copyright_hdr (abfd))
  4929. return FALSE;
  4930. obj_som_copyright_hdr (abfd)->header_id.type = COPYRIGHT_AUX_ID;
  4931. obj_som_copyright_hdr (abfd)->header_id.length = len + pad + 4;
  4932. obj_som_copyright_hdr (abfd)->string_length = len;
  4933. memcpy (obj_som_copyright_hdr (abfd)->string, string, len);
  4934. memset (obj_som_copyright_hdr (abfd)->string + len, 0, pad);
  4935. }
  4936. return TRUE;
  4937. }
  4938. /* Attach a compilation unit header to the BFD backend so that it may be
  4939. written into the object file. */
  4940. bfd_boolean
  4941. bfd_som_attach_compilation_unit (bfd *abfd,
  4942. const char *name,
  4943. const char *language_name,
  4944. const char *product_id,
  4945. const char *version_id)
  4946. {
  4947. struct som_compilation_unit *n;
  4948. n = (struct som_compilation_unit *) bfd_zalloc
  4949. (abfd, (bfd_size_type) sizeof (*n));
  4950. if (n == NULL)
  4951. return FALSE;
  4952. #define STRDUP(f) \
  4953. if (f != NULL) \
  4954. { \
  4955. n->f.name = bfd_alloc (abfd, (bfd_size_type) strlen (f) + 1); \
  4956. if (n->f.name == NULL) \
  4957. return FALSE; \
  4958. strcpy (n->f.name, f); \
  4959. }
  4960. STRDUP (name);
  4961. STRDUP (language_name);
  4962. STRDUP (product_id);
  4963. STRDUP (version_id);
  4964. #undef STRDUP
  4965. obj_som_compilation_unit (abfd) = n;
  4966. return TRUE;
  4967. }
  4968. static bfd_boolean
  4969. som_get_section_contents (bfd *abfd,
  4970. sec_ptr section,
  4971. void *location,
  4972. file_ptr offset,
  4973. bfd_size_type count)
  4974. {
  4975. if (count == 0 || ((section->flags & SEC_HAS_CONTENTS) == 0))
  4976. return TRUE;
  4977. if ((bfd_size_type) (offset+count) > section->size
  4978. || bfd_seek (abfd, (file_ptr) (section->filepos + offset), SEEK_SET) != 0
  4979. || bfd_bread (location, count, abfd) != count)
  4980. return FALSE; /* On error. */
  4981. return TRUE;
  4982. }
  4983. static bfd_boolean
  4984. som_set_section_contents (bfd *abfd,
  4985. sec_ptr section,
  4986. const void *location,
  4987. file_ptr offset,
  4988. bfd_size_type count)
  4989. {
  4990. if (! abfd->output_has_begun)
  4991. {
  4992. /* Set up fixed parts of the file, space, and subspace headers.
  4993. Notify the world that output has begun. */
  4994. som_prep_headers (abfd);
  4995. abfd->output_has_begun = TRUE;
  4996. /* Start writing the object file. This include all the string
  4997. tables, fixup streams, and other portions of the object file. */
  4998. som_begin_writing (abfd);
  4999. }
  5000. /* Only write subspaces which have "real" contents (eg. the contents
  5001. are not generated at run time by the OS). */
  5002. if (!som_is_subspace (section)
  5003. || ((section->flags & SEC_HAS_CONTENTS) == 0))
  5004. return TRUE;
  5005. /* Seek to the proper offset within the object file and write the
  5006. data. */
  5007. offset += som_section_data (section)->subspace_dict->file_loc_init_value;
  5008. if (bfd_seek (abfd, offset, SEEK_SET) != 0)
  5009. return FALSE;
  5010. if (bfd_bwrite (location, count, abfd) != count)
  5011. return FALSE;
  5012. return TRUE;
  5013. }
  5014. static bfd_boolean
  5015. som_set_arch_mach (bfd *abfd,
  5016. enum bfd_architecture arch,
  5017. unsigned long machine)
  5018. {
  5019. /* Allow any architecture to be supported by the SOM backend. */
  5020. return bfd_default_set_arch_mach (abfd, arch, machine);
  5021. }
  5022. static bfd_boolean
  5023. som_find_nearest_line (bfd *abfd,
  5024. asymbol **symbols,
  5025. asection *section,
  5026. bfd_vma offset,
  5027. const char **filename_ptr,
  5028. const char **functionname_ptr,
  5029. unsigned int *line_ptr,
  5030. unsigned int *discriminator_ptr)
  5031. {
  5032. bfd_boolean found;
  5033. asymbol *func;
  5034. bfd_vma low_func;
  5035. asymbol **p;
  5036. if (discriminator_ptr)
  5037. *discriminator_ptr = 0;
  5038. if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
  5039. & found, filename_ptr,
  5040. functionname_ptr, line_ptr,
  5041. & somdata (abfd).line_info))
  5042. return FALSE;
  5043. if (found)
  5044. return TRUE;
  5045. if (symbols == NULL)
  5046. return FALSE;
  5047. /* Fallback: find function name from symbols table. */
  5048. func = NULL;
  5049. low_func = 0;
  5050. for (p = symbols; *p != NULL; p++)
  5051. {
  5052. som_symbol_type *q = (som_symbol_type *) *p;
  5053. if (q->som_type == SYMBOL_TYPE_ENTRY
  5054. && q->symbol.section == section
  5055. && q->symbol.value >= low_func
  5056. && q->symbol.value <= offset)
  5057. {
  5058. func = (asymbol *) q;
  5059. low_func = q->symbol.value;
  5060. }
  5061. }
  5062. if (func == NULL)
  5063. return FALSE;
  5064. *filename_ptr = NULL;
  5065. *functionname_ptr = bfd_asymbol_name (func);
  5066. *line_ptr = 0;
  5067. return TRUE;
  5068. }
  5069. static int
  5070. som_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
  5071. struct bfd_link_info *info ATTRIBUTE_UNUSED)
  5072. {
  5073. (*_bfd_error_handler) (_("som_sizeof_headers unimplemented"));
  5074. abort ();
  5075. return 0;
  5076. }
  5077. /* Return the single-character symbol type corresponding to
  5078. SOM section S, or '?' for an unknown SOM section. */
  5079. static char
  5080. som_section_type (const char *s)
  5081. {
  5082. const struct section_to_type *t;
  5083. for (t = &stt[0]; t->section; t++)
  5084. if (!strcmp (s, t->section))
  5085. return t->type;
  5086. return '?';
  5087. }
  5088. static int
  5089. som_decode_symclass (asymbol *symbol)
  5090. {
  5091. char c;
  5092. if (bfd_is_com_section (symbol->section))
  5093. return 'C';
  5094. if (bfd_is_und_section (symbol->section))
  5095. {
  5096. if (symbol->flags & BSF_WEAK)
  5097. {
  5098. /* If weak, determine if it's specifically an object
  5099. or non-object weak. */
  5100. if (symbol->flags & BSF_OBJECT)
  5101. return 'v';
  5102. else
  5103. return 'w';
  5104. }
  5105. else
  5106. return 'U';
  5107. }
  5108. if (bfd_is_ind_section (symbol->section))
  5109. return 'I';
  5110. if (symbol->flags & BSF_WEAK)
  5111. {
  5112. /* If weak, determine if it's specifically an object
  5113. or non-object weak. */
  5114. if (symbol->flags & BSF_OBJECT)
  5115. return 'V';
  5116. else
  5117. return 'W';
  5118. }
  5119. if (!(symbol->flags & (BSF_GLOBAL | BSF_LOCAL)))
  5120. return '?';
  5121. if (bfd_is_abs_section (symbol->section)
  5122. || (som_symbol_data (symbol) != NULL
  5123. && som_symbol_data (symbol)->som_type == SYMBOL_TYPE_ABSOLUTE))
  5124. c = 'a';
  5125. else if (symbol->section)
  5126. c = som_section_type (symbol->section->name);
  5127. else
  5128. return '?';
  5129. if (symbol->flags & BSF_GLOBAL)
  5130. c = TOUPPER (c);
  5131. return c;
  5132. }
  5133. /* Return information about SOM symbol SYMBOL in RET. */
  5134. static void
  5135. som_get_symbol_info (bfd *ignore_abfd ATTRIBUTE_UNUSED,
  5136. asymbol *symbol,
  5137. symbol_info *ret)
  5138. {
  5139. ret->type = som_decode_symclass (symbol);
  5140. if (ret->type != 'U')
  5141. ret->value = symbol->value + symbol->section->vma;
  5142. else
  5143. ret->value = 0;
  5144. ret->name = symbol->name;
  5145. }
  5146. /* Count the number of symbols in the archive symbol table. Necessary
  5147. so that we can allocate space for all the carsyms at once. */
  5148. static bfd_boolean
  5149. som_bfd_count_ar_symbols (bfd *abfd,
  5150. struct som_lst_header *lst_header,
  5151. symindex *count)
  5152. {
  5153. unsigned int i;
  5154. unsigned char *hash_table;
  5155. bfd_size_type amt;
  5156. file_ptr lst_filepos;
  5157. lst_filepos = bfd_tell (abfd) - sizeof (struct som_external_lst_header);
  5158. amt = lst_header->hash_size * 4;
  5159. hash_table = bfd_malloc (amt);
  5160. if (hash_table == NULL && amt != 0)
  5161. goto error_return;
  5162. /* Don't forget to initialize the counter! */
  5163. *count = 0;
  5164. /* Read in the hash table. The has table is an array of 32bit file offsets
  5165. which point to the hash chains. */
  5166. if (bfd_bread ((void *) hash_table, amt, abfd) != amt)
  5167. goto error_return;
  5168. /* Walk each chain counting the number of symbols found on that particular
  5169. chain. */
  5170. for (i = 0; i < lst_header->hash_size; i++)
  5171. {
  5172. struct som_external_lst_symbol_record ext_lst_symbol;
  5173. unsigned int hash_val = bfd_getb32 (hash_table + 4 * i);
  5174. /* An empty chain has zero as it's file offset. */
  5175. if (hash_val == 0)
  5176. continue;
  5177. /* Seek to the first symbol in this hash chain. */
  5178. if (bfd_seek (abfd, lst_filepos + hash_val, SEEK_SET) != 0)
  5179. goto error_return;
  5180. /* Read in this symbol and update the counter. */
  5181. amt = sizeof (ext_lst_symbol);
  5182. if (bfd_bread ((void *) &ext_lst_symbol, amt, abfd) != amt)
  5183. goto error_return;
  5184. (*count)++;
  5185. /* Now iterate through the rest of the symbols on this chain. */
  5186. while (1)
  5187. {
  5188. unsigned int next_entry = bfd_getb32 (ext_lst_symbol.next_entry);
  5189. if (next_entry == 0)
  5190. break;
  5191. /* Seek to the next symbol. */
  5192. if (bfd_seek (abfd, lst_filepos + next_entry, SEEK_SET) != 0)
  5193. goto error_return;
  5194. /* Read the symbol in and update the counter. */
  5195. amt = sizeof (ext_lst_symbol);
  5196. if (bfd_bread ((void *) &ext_lst_symbol, amt, abfd) != amt)
  5197. goto error_return;
  5198. (*count)++;
  5199. }
  5200. }
  5201. if (hash_table != NULL)
  5202. free (hash_table);
  5203. return TRUE;
  5204. error_return:
  5205. if (hash_table != NULL)
  5206. free (hash_table);
  5207. return FALSE;
  5208. }
  5209. /* Fill in the canonical archive symbols (SYMS) from the archive described
  5210. by ABFD and LST_HEADER. */
  5211. static bfd_boolean
  5212. som_bfd_fill_in_ar_symbols (bfd *abfd,
  5213. struct som_lst_header *lst_header,
  5214. carsym **syms)
  5215. {
  5216. unsigned int i;
  5217. carsym *set = syms[0];
  5218. unsigned char *hash_table;
  5219. struct som_external_som_entry *som_dict = NULL;
  5220. bfd_size_type amt;
  5221. file_ptr lst_filepos;
  5222. unsigned int string_loc;
  5223. lst_filepos = bfd_tell (abfd) - sizeof (struct som_external_lst_header);
  5224. amt = lst_header->hash_size * 4;
  5225. hash_table = bfd_malloc (amt);
  5226. if (hash_table == NULL && amt != 0)
  5227. goto error_return;
  5228. /* Read in the hash table. The has table is an array of 32bit file offsets
  5229. which point to the hash chains. */
  5230. if (bfd_bread ((void *) hash_table, amt, abfd) != amt)
  5231. goto error_return;
  5232. /* Seek to and read in the SOM dictionary. We will need this to fill
  5233. in the carsym's filepos field. */
  5234. if (bfd_seek (abfd, lst_filepos + lst_header->dir_loc, SEEK_SET) != 0)
  5235. goto error_return;
  5236. amt = lst_header->module_count * sizeof (struct som_external_som_entry);
  5237. som_dict = bfd_malloc (amt);
  5238. if (som_dict == NULL && amt != 0)
  5239. goto error_return;
  5240. if (bfd_bread ((void *) som_dict, amt, abfd) != amt)
  5241. goto error_return;
  5242. string_loc = lst_header->string_loc;
  5243. /* Walk each chain filling in the carsyms as we go along. */
  5244. for (i = 0; i < lst_header->hash_size; i++)
  5245. {
  5246. struct som_external_lst_symbol_record lst_symbol;
  5247. unsigned int hash_val;
  5248. unsigned int len;
  5249. unsigned char ext_len[4];
  5250. /* An empty chain has zero as it's file offset. */
  5251. hash_val = bfd_getb32 (hash_table + 4 * i);
  5252. if (hash_val == 0)
  5253. continue;
  5254. /* Seek to and read the first symbol on the chain. */
  5255. if (bfd_seek (abfd, lst_filepos + hash_val, SEEK_SET) != 0)
  5256. goto error_return;
  5257. amt = sizeof (lst_symbol);
  5258. if (bfd_bread ((void *) &lst_symbol, amt, abfd) != amt)
  5259. goto error_return;
  5260. /* Get the name of the symbol, first get the length which is stored
  5261. as a 32bit integer just before the symbol.
  5262. One might ask why we don't just read in the entire string table
  5263. and index into it. Well, according to the SOM ABI the string
  5264. index can point *anywhere* in the archive to save space, so just
  5265. using the string table would not be safe. */
  5266. if (bfd_seek (abfd, (lst_filepos + string_loc
  5267. + bfd_getb32 (lst_symbol.name) - 4), SEEK_SET) != 0)
  5268. goto error_return;
  5269. if (bfd_bread (&ext_len, (bfd_size_type) 4, abfd) != 4)
  5270. goto error_return;
  5271. len = bfd_getb32 (ext_len);
  5272. /* Allocate space for the name and null terminate it too. */
  5273. set->name = bfd_zalloc (abfd, (bfd_size_type) len + 1);
  5274. if (!set->name)
  5275. goto error_return;
  5276. if (bfd_bread (set->name, (bfd_size_type) len, abfd) != len)
  5277. goto error_return;
  5278. set->name[len] = 0;
  5279. /* Fill in the file offset. Note that the "location" field points
  5280. to the SOM itself, not the ar_hdr in front of it. */
  5281. set->file_offset =
  5282. bfd_getb32 (som_dict[bfd_getb32 (lst_symbol.som_index)].location)
  5283. - sizeof (struct ar_hdr);
  5284. /* Go to the next symbol. */
  5285. set++;
  5286. /* Iterate through the rest of the chain. */
  5287. while (1)
  5288. {
  5289. unsigned int next_entry = bfd_getb32 (lst_symbol.next_entry);
  5290. if (next_entry == 0)
  5291. break;
  5292. /* Seek to the next symbol and read it in. */
  5293. if (bfd_seek (abfd, lst_filepos + next_entry, SEEK_SET) != 0)
  5294. goto error_return;
  5295. amt = sizeof (lst_symbol);
  5296. if (bfd_bread ((void *) &lst_symbol, amt, abfd) != amt)
  5297. goto error_return;
  5298. /* Seek to the name length & string and read them in. */
  5299. if (bfd_seek (abfd, lst_filepos + string_loc
  5300. + bfd_getb32 (lst_symbol.name) - 4, SEEK_SET) != 0)
  5301. goto error_return;
  5302. if (bfd_bread (&ext_len, (bfd_size_type) 4, abfd) != 4)
  5303. goto error_return;
  5304. len = bfd_getb32 (ext_len);
  5305. /* Allocate space for the name and null terminate it too. */
  5306. set->name = bfd_zalloc (abfd, (bfd_size_type) len + 1);
  5307. if (!set->name)
  5308. goto error_return;
  5309. if (bfd_bread (set->name, (bfd_size_type) len, abfd) != len)
  5310. goto error_return;
  5311. set->name[len] = 0;
  5312. /* Fill in the file offset. Note that the "location" field points
  5313. to the SOM itself, not the ar_hdr in front of it. */
  5314. set->file_offset =
  5315. bfd_getb32 (som_dict[bfd_getb32 (lst_symbol.som_index)].location)
  5316. - sizeof (struct ar_hdr);
  5317. /* Go on to the next symbol. */
  5318. set++;
  5319. }
  5320. }
  5321. /* If we haven't died by now, then we successfully read the entire
  5322. archive symbol table. */
  5323. if (hash_table != NULL)
  5324. free (hash_table);
  5325. if (som_dict != NULL)
  5326. free (som_dict);
  5327. return TRUE;
  5328. error_return:
  5329. if (hash_table != NULL)
  5330. free (hash_table);
  5331. if (som_dict != NULL)
  5332. free (som_dict);
  5333. return FALSE;
  5334. }
  5335. /* Read in the LST from the archive. */
  5336. static bfd_boolean
  5337. som_slurp_armap (bfd *abfd)
  5338. {
  5339. struct som_external_lst_header ext_lst_header;
  5340. struct som_lst_header lst_header;
  5341. struct ar_hdr ar_header;
  5342. unsigned int parsed_size;
  5343. struct artdata *ardata = bfd_ardata (abfd);
  5344. char nextname[17];
  5345. bfd_size_type amt = 16;
  5346. int i = bfd_bread ((void *) nextname, amt, abfd);
  5347. /* Special cases. */
  5348. if (i == 0)
  5349. return TRUE;
  5350. if (i != 16)
  5351. return FALSE;
  5352. if (bfd_seek (abfd, (file_ptr) -16, SEEK_CUR) != 0)
  5353. return FALSE;
  5354. /* For archives without .o files there is no symbol table. */
  5355. if (! CONST_STRNEQ (nextname, "/ "))
  5356. {
  5357. bfd_has_map (abfd) = FALSE;
  5358. return TRUE;
  5359. }
  5360. /* Read in and sanity check the archive header. */
  5361. amt = sizeof (struct ar_hdr);
  5362. if (bfd_bread ((void *) &ar_header, amt, abfd) != amt)
  5363. return FALSE;
  5364. if (strncmp (ar_header.ar_fmag, ARFMAG, 2))
  5365. {
  5366. bfd_set_error (bfd_error_malformed_archive);
  5367. return FALSE;
  5368. }
  5369. /* How big is the archive symbol table entry? */
  5370. errno = 0;
  5371. parsed_size = strtol (ar_header.ar_size, NULL, 10);
  5372. if (errno != 0)
  5373. {
  5374. bfd_set_error (bfd_error_malformed_archive);
  5375. return FALSE;
  5376. }
  5377. /* Save off the file offset of the first real user data. */
  5378. ardata->first_file_filepos = bfd_tell (abfd) + parsed_size;
  5379. /* Read in the library symbol table. We'll make heavy use of this
  5380. in just a minute. */
  5381. amt = sizeof (struct som_external_lst_header);
  5382. if (bfd_bread ((void *) &ext_lst_header, amt, abfd) != amt)
  5383. return FALSE;
  5384. som_swap_lst_header_in (&ext_lst_header, &lst_header);
  5385. /* Sanity check. */
  5386. if (lst_header.a_magic != LIBMAGIC)
  5387. {
  5388. bfd_set_error (bfd_error_malformed_archive);
  5389. return FALSE;
  5390. }
  5391. /* Count the number of symbols in the library symbol table. */
  5392. if (! som_bfd_count_ar_symbols (abfd, &lst_header, &ardata->symdef_count))
  5393. return FALSE;
  5394. /* Get back to the start of the library symbol table. */
  5395. if (bfd_seek (abfd, (ardata->first_file_filepos - parsed_size
  5396. + sizeof (struct som_external_lst_header)),
  5397. SEEK_SET) != 0)
  5398. return FALSE;
  5399. /* Initialize the cache and allocate space for the library symbols. */
  5400. ardata->cache = 0;
  5401. amt = ardata->symdef_count;
  5402. amt *= sizeof (carsym);
  5403. ardata->symdefs = bfd_alloc (abfd, amt);
  5404. if (!ardata->symdefs)
  5405. return FALSE;
  5406. /* Now fill in the canonical archive symbols. */
  5407. if (! som_bfd_fill_in_ar_symbols (abfd, &lst_header, &ardata->symdefs))
  5408. return FALSE;
  5409. /* Seek back to the "first" file in the archive. Note the "first"
  5410. file may be the extended name table. */
  5411. if (bfd_seek (abfd, ardata->first_file_filepos, SEEK_SET) != 0)
  5412. return FALSE;
  5413. /* Notify the generic archive code that we have a symbol map. */
  5414. bfd_has_map (abfd) = TRUE;
  5415. return TRUE;
  5416. }
  5417. /* Begin preparing to write a SOM library symbol table.
  5418. As part of the prep work we need to determine the number of symbols
  5419. and the size of the associated string section. */
  5420. static bfd_boolean
  5421. som_bfd_prep_for_ar_write (bfd *abfd,
  5422. unsigned int *num_syms,
  5423. unsigned int *stringsize)
  5424. {
  5425. bfd *curr_bfd = abfd->archive_head;
  5426. /* Some initialization. */
  5427. *num_syms = 0;
  5428. *stringsize = 0;
  5429. /* Iterate over each BFD within this archive. */
  5430. while (curr_bfd != NULL)
  5431. {
  5432. unsigned int curr_count, i;
  5433. som_symbol_type *sym;
  5434. /* Don't bother for non-SOM objects. */
  5435. if (curr_bfd->format != bfd_object
  5436. || curr_bfd->xvec->flavour != bfd_target_som_flavour)
  5437. {
  5438. curr_bfd = curr_bfd->archive_next;
  5439. continue;
  5440. }
  5441. /* Make sure the symbol table has been read, then snag a pointer
  5442. to it. It's a little slimey to grab the symbols via obj_som_symtab,
  5443. but doing so avoids allocating lots of extra memory. */
  5444. if (! som_slurp_symbol_table (curr_bfd))
  5445. return FALSE;
  5446. sym = obj_som_symtab (curr_bfd);
  5447. curr_count = bfd_get_symcount (curr_bfd);
  5448. /* Examine each symbol to determine if it belongs in the
  5449. library symbol table. */
  5450. for (i = 0; i < curr_count; i++, sym++)
  5451. {
  5452. struct som_misc_symbol_info info;
  5453. /* Derive SOM information from the BFD symbol. */
  5454. som_bfd_derive_misc_symbol_info (curr_bfd, &sym->symbol, &info);
  5455. /* Should we include this symbol? */
  5456. if (info.symbol_type == ST_NULL
  5457. || info.symbol_type == ST_SYM_EXT
  5458. || info.symbol_type == ST_ARG_EXT)
  5459. continue;
  5460. /* Only global symbols and unsatisfied commons. */
  5461. if (info.symbol_scope != SS_UNIVERSAL
  5462. && info.symbol_type != ST_STORAGE)
  5463. continue;
  5464. /* Do no include undefined symbols. */
  5465. if (bfd_is_und_section (sym->symbol.section))
  5466. continue;
  5467. /* Bump the various counters, being careful to honor
  5468. alignment considerations in the string table. */
  5469. (*num_syms)++;
  5470. *stringsize += strlen (sym->symbol.name) + 5;
  5471. while (*stringsize % 4)
  5472. (*stringsize)++;
  5473. }
  5474. curr_bfd = curr_bfd->archive_next;
  5475. }
  5476. return TRUE;
  5477. }
  5478. /* Hash a symbol name based on the hashing algorithm presented in the
  5479. SOM ABI. */
  5480. static unsigned int
  5481. som_bfd_ar_symbol_hash (asymbol *symbol)
  5482. {
  5483. unsigned int len = strlen (symbol->name);
  5484. /* Names with length 1 are special. */
  5485. if (len == 1)
  5486. return 0x1000100 | (symbol->name[0] << 16) | symbol->name[0];
  5487. return ((len & 0x7f) << 24) | (symbol->name[1] << 16)
  5488. | (symbol->name[len - 2] << 8) | symbol->name[len - 1];
  5489. }
  5490. /* Do the bulk of the work required to write the SOM library
  5491. symbol table. */
  5492. static bfd_boolean
  5493. som_bfd_ar_write_symbol_stuff (bfd *abfd,
  5494. unsigned int nsyms,
  5495. unsigned int string_size,
  5496. struct som_external_lst_header lst,
  5497. unsigned elength)
  5498. {
  5499. char *strings = NULL, *p;
  5500. struct som_external_lst_symbol_record *lst_syms = NULL, *curr_lst_sym;
  5501. bfd *curr_bfd;
  5502. unsigned char *hash_table = NULL;
  5503. struct som_external_som_entry *som_dict = NULL;
  5504. struct som_external_lst_symbol_record **last_hash_entry = NULL;
  5505. unsigned int curr_som_offset, som_index = 0;
  5506. bfd_size_type amt;
  5507. unsigned int module_count;
  5508. unsigned int hash_size;
  5509. hash_size = bfd_getb32 (lst.hash_size);
  5510. amt = hash_size * 4;
  5511. hash_table = bfd_zmalloc (amt);
  5512. if (hash_table == NULL && hash_size != 0)
  5513. goto error_return;
  5514. module_count = bfd_getb32 (lst.module_count);
  5515. amt = module_count * sizeof (struct som_external_som_entry);
  5516. som_dict = bfd_zmalloc (amt);
  5517. if (som_dict == NULL && module_count != 0)
  5518. goto error_return;
  5519. amt = hash_size * sizeof (struct som_external_lst_symbol_record *);
  5520. last_hash_entry = bfd_zmalloc (amt);
  5521. if (last_hash_entry == NULL && hash_size != 0)
  5522. goto error_return;
  5523. /* Symbols have som_index fields, so we have to keep track of the
  5524. index of each SOM in the archive.
  5525. The SOM dictionary has (among other things) the absolute file
  5526. position for the SOM which a particular dictionary entry
  5527. describes. We have to compute that information as we iterate
  5528. through the SOMs/symbols. */
  5529. som_index = 0;
  5530. /* We add in the size of the archive header twice as the location
  5531. in the SOM dictionary is the actual offset of the SOM, not the
  5532. archive header before the SOM. */
  5533. curr_som_offset = 8 + 2 * sizeof (struct ar_hdr) + bfd_getb32 (lst.file_end);
  5534. /* Make room for the archive header and the contents of the
  5535. extended string table. Note that elength includes the size
  5536. of the archive header for the extended name table! */
  5537. if (elength)
  5538. curr_som_offset += elength;
  5539. /* Make sure we're properly aligned. */
  5540. curr_som_offset = (curr_som_offset + 0x1) & ~0x1;
  5541. /* FIXME should be done with buffers just like everything else... */
  5542. amt = nsyms;
  5543. amt *= sizeof (struct som_external_lst_symbol_record);
  5544. lst_syms = bfd_malloc (amt);
  5545. if (lst_syms == NULL && nsyms != 0)
  5546. goto error_return;
  5547. strings = bfd_malloc ((bfd_size_type) string_size);
  5548. if (strings == NULL && string_size != 0)
  5549. goto error_return;
  5550. p = strings;
  5551. curr_lst_sym = lst_syms;
  5552. curr_bfd = abfd->archive_head;
  5553. while (curr_bfd != NULL)
  5554. {
  5555. unsigned int curr_count, i;
  5556. som_symbol_type *sym;
  5557. /* Don't bother for non-SOM objects. */
  5558. if (curr_bfd->format != bfd_object
  5559. || curr_bfd->xvec->flavour != bfd_target_som_flavour)
  5560. {
  5561. curr_bfd = curr_bfd->archive_next;
  5562. continue;
  5563. }
  5564. /* Make sure the symbol table has been read, then snag a pointer
  5565. to it. It's a little slimey to grab the symbols via obj_som_symtab,
  5566. but doing so avoids allocating lots of extra memory. */
  5567. if (! som_slurp_symbol_table (curr_bfd))
  5568. goto error_return;
  5569. sym = obj_som_symtab (curr_bfd);
  5570. curr_count = bfd_get_symcount (curr_bfd);
  5571. for (i = 0; i < curr_count; i++, sym++)
  5572. {
  5573. struct som_misc_symbol_info info;
  5574. struct som_external_lst_symbol_record *last;
  5575. unsigned int symbol_pos;
  5576. unsigned int slen;
  5577. unsigned int symbol_key;
  5578. unsigned int flags;
  5579. /* Derive SOM information from the BFD symbol. */
  5580. som_bfd_derive_misc_symbol_info (curr_bfd, &sym->symbol, &info);
  5581. /* Should we include this symbol? */
  5582. if (info.symbol_type == ST_NULL
  5583. || info.symbol_type == ST_SYM_EXT
  5584. || info.symbol_type == ST_ARG_EXT)
  5585. continue;
  5586. /* Only global symbols and unsatisfied commons. */
  5587. if (info.symbol_scope != SS_UNIVERSAL
  5588. && info.symbol_type != ST_STORAGE)
  5589. continue;
  5590. /* Do no include undefined symbols. */
  5591. if (bfd_is_und_section (sym->symbol.section))
  5592. continue;
  5593. /* If this is the first symbol from this SOM, then update
  5594. the SOM dictionary too. */
  5595. if (bfd_getb32 (som_dict[som_index].location) == 0)
  5596. {
  5597. bfd_putb32 (curr_som_offset, som_dict[som_index].location);
  5598. bfd_putb32 (arelt_size (curr_bfd), som_dict[som_index].length);
  5599. }
  5600. symbol_key = som_bfd_ar_symbol_hash (&sym->symbol);
  5601. /* Fill in the lst symbol record. */
  5602. flags = 0;
  5603. if (info.secondary_def)
  5604. flags |= LST_SYMBOL_SECONDARY_DEF;
  5605. flags |= info.symbol_type << LST_SYMBOL_SYMBOL_TYPE_SH;
  5606. flags |= info.symbol_scope << LST_SYMBOL_SYMBOL_SCOPE_SH;
  5607. if (bfd_is_com_section (sym->symbol.section))
  5608. flags |= LST_SYMBOL_IS_COMMON;
  5609. if (info.dup_common)
  5610. flags |= LST_SYMBOL_DUP_COMMON;
  5611. flags |= 3 << LST_SYMBOL_XLEAST_SH;
  5612. flags |= info.arg_reloc << LST_SYMBOL_ARG_RELOC_SH;
  5613. bfd_putb32 (flags, curr_lst_sym->flags);
  5614. bfd_putb32 (p - strings + 4, curr_lst_sym->name);
  5615. bfd_putb32 (0, curr_lst_sym->qualifier_name);
  5616. bfd_putb32 (info.symbol_info, curr_lst_sym->symbol_info);
  5617. bfd_putb32 (info.symbol_value | info.priv_level,
  5618. curr_lst_sym->symbol_value);
  5619. bfd_putb32 (0, curr_lst_sym->symbol_descriptor);
  5620. curr_lst_sym->reserved = 0;
  5621. bfd_putb32 (som_index, curr_lst_sym->som_index);
  5622. bfd_putb32 (symbol_key, curr_lst_sym->symbol_key);
  5623. bfd_putb32 (0, curr_lst_sym->next_entry);
  5624. /* Insert into the hash table. */
  5625. symbol_pos =
  5626. (curr_lst_sym - lst_syms)
  5627. * sizeof (struct som_external_lst_symbol_record)
  5628. + hash_size * 4
  5629. + module_count * sizeof (struct som_external_som_entry)
  5630. + sizeof (struct som_external_lst_header);
  5631. last = last_hash_entry[symbol_key % hash_size];
  5632. if (last != NULL)
  5633. {
  5634. /* There is already something at the head of this hash chain,
  5635. so tack this symbol onto the end of the chain. */
  5636. bfd_putb32 (symbol_pos, last->next_entry);
  5637. }
  5638. else
  5639. /* First entry in this hash chain. */
  5640. bfd_putb32 (symbol_pos, hash_table + 4 * (symbol_key % hash_size));
  5641. /* Keep track of the last symbol we added to this chain so we can
  5642. easily update its next_entry pointer. */
  5643. last_hash_entry[symbol_key % hash_size] = curr_lst_sym;
  5644. /* Update the string table. */
  5645. slen = strlen (sym->symbol.name);
  5646. bfd_put_32 (abfd, slen, p);
  5647. p += 4;
  5648. slen++; /* Nul terminator. */
  5649. memcpy (p, sym->symbol.name, slen);
  5650. p += slen;
  5651. while (slen % 4)
  5652. {
  5653. bfd_put_8 (abfd, 0, p);
  5654. p++;
  5655. slen++;
  5656. }
  5657. BFD_ASSERT (p <= strings + string_size);
  5658. /* Head to the next symbol. */
  5659. curr_lst_sym++;
  5660. }
  5661. /* Keep track of where each SOM will finally reside; then look
  5662. at the next BFD. */
  5663. curr_som_offset += arelt_size (curr_bfd) + sizeof (struct ar_hdr);
  5664. /* A particular object in the archive may have an odd length; the
  5665. linker requires objects begin on an even boundary. So round
  5666. up the current offset as necessary. */
  5667. curr_som_offset = (curr_som_offset + 0x1) &~ (unsigned) 1;
  5668. curr_bfd = curr_bfd->archive_next;
  5669. som_index++;
  5670. }
  5671. /* Now scribble out the hash table. */
  5672. amt = hash_size * 4;
  5673. if (bfd_bwrite ((void *) hash_table, amt, abfd) != amt)
  5674. goto error_return;
  5675. /* Then the SOM dictionary. */
  5676. amt = module_count * sizeof (struct som_external_som_entry);
  5677. if (bfd_bwrite ((void *) som_dict, amt, abfd) != amt)
  5678. goto error_return;
  5679. /* The library symbols. */
  5680. amt = nsyms * sizeof (struct som_external_lst_symbol_record);
  5681. if (bfd_bwrite ((void *) lst_syms, amt, abfd) != amt)
  5682. goto error_return;
  5683. /* And finally the strings. */
  5684. amt = string_size;
  5685. if (bfd_bwrite ((void *) strings, amt, abfd) != amt)
  5686. goto error_return;
  5687. if (hash_table != NULL)
  5688. free (hash_table);
  5689. if (som_dict != NULL)
  5690. free (som_dict);
  5691. if (last_hash_entry != NULL)
  5692. free (last_hash_entry);
  5693. if (lst_syms != NULL)
  5694. free (lst_syms);
  5695. if (strings != NULL)
  5696. free (strings);
  5697. return TRUE;
  5698. error_return:
  5699. if (hash_table != NULL)
  5700. free (hash_table);
  5701. if (som_dict != NULL)
  5702. free (som_dict);
  5703. if (last_hash_entry != NULL)
  5704. free (last_hash_entry);
  5705. if (lst_syms != NULL)
  5706. free (lst_syms);
  5707. if (strings != NULL)
  5708. free (strings);
  5709. return FALSE;
  5710. }
  5711. /* Write out the LST for the archive.
  5712. You'll never believe this is really how armaps are handled in SOM... */
  5713. static bfd_boolean
  5714. som_write_armap (bfd *abfd,
  5715. unsigned int elength,
  5716. struct orl *map ATTRIBUTE_UNUSED,
  5717. unsigned int orl_count ATTRIBUTE_UNUSED,
  5718. int stridx ATTRIBUTE_UNUSED)
  5719. {
  5720. bfd *curr_bfd;
  5721. struct stat statbuf;
  5722. unsigned int i, lst_size, nsyms, stringsize;
  5723. struct ar_hdr hdr;
  5724. struct som_external_lst_header lst;
  5725. unsigned char *p;
  5726. bfd_size_type amt;
  5727. unsigned int csum;
  5728. unsigned int module_count;
  5729. /* We'll use this for the archive's date and mode later. */
  5730. if (stat (abfd->filename, &statbuf) != 0)
  5731. {
  5732. bfd_set_error (bfd_error_system_call);
  5733. return FALSE;
  5734. }
  5735. /* Fudge factor. */
  5736. bfd_ardata (abfd)->armap_timestamp = statbuf.st_mtime + 60;
  5737. /* Account for the lst header first. */
  5738. lst_size = sizeof (struct som_external_lst_header);
  5739. /* Start building the LST header. */
  5740. /* FIXME: Do we need to examine each element to determine the
  5741. largest id number? */
  5742. bfd_putb16 (CPU_PA_RISC1_0, &lst.system_id);
  5743. bfd_putb16 (LIBMAGIC, &lst.a_magic);
  5744. bfd_putb32 (VERSION_ID, &lst.version_id);
  5745. bfd_putb32 (0, &lst.file_time.secs);
  5746. bfd_putb32 (0, &lst.file_time.nanosecs);
  5747. bfd_putb32 (lst_size, &lst.hash_loc);
  5748. bfd_putb32 (SOM_LST_HASH_SIZE, &lst.hash_size);
  5749. /* Hash table is a SOM_LST_HASH_SIZE 32bit offsets. */
  5750. lst_size += 4 * SOM_LST_HASH_SIZE;
  5751. /* We need to count the number of SOMs in this archive. */
  5752. curr_bfd = abfd->archive_head;
  5753. module_count = 0;
  5754. while (curr_bfd != NULL)
  5755. {
  5756. /* Only true SOM objects count. */
  5757. if (curr_bfd->format == bfd_object
  5758. && curr_bfd->xvec->flavour == bfd_target_som_flavour)
  5759. module_count++;
  5760. curr_bfd = curr_bfd->archive_next;
  5761. }
  5762. bfd_putb32 (module_count, &lst.module_count);
  5763. bfd_putb32 (module_count, &lst.module_limit);
  5764. bfd_putb32 (lst_size, &lst.dir_loc);
  5765. lst_size += sizeof (struct som_external_som_entry) * module_count;
  5766. /* We don't support import/export tables, auxiliary headers,
  5767. or free lists yet. Make the linker work a little harder
  5768. to make our life easier. */
  5769. bfd_putb32 (0, &lst.export_loc);
  5770. bfd_putb32 (0, &lst.export_count);
  5771. bfd_putb32 (0, &lst.import_loc);
  5772. bfd_putb32 (0, &lst.aux_loc);
  5773. bfd_putb32 (0, &lst.aux_size);
  5774. /* Count how many symbols we will have on the hash chains and the
  5775. size of the associated string table. */
  5776. if (! som_bfd_prep_for_ar_write (abfd, &nsyms, &stringsize))
  5777. return FALSE;
  5778. lst_size += sizeof (struct som_external_lst_symbol_record) * nsyms;
  5779. /* For the string table. One day we might actually use this info
  5780. to avoid small seeks/reads when reading archives. */
  5781. bfd_putb32 (lst_size, &lst.string_loc);
  5782. bfd_putb32 (stringsize, &lst.string_size);
  5783. lst_size += stringsize;
  5784. /* SOM ABI says this must be zero. */
  5785. bfd_putb32 (0, &lst.free_list);
  5786. bfd_putb32 (lst_size, &lst.file_end);
  5787. /* Compute the checksum. Must happen after the entire lst header
  5788. has filled in. */
  5789. p = (unsigned char *) &lst;
  5790. csum = 0;
  5791. for (i = 0; i < sizeof (struct som_external_lst_header) - sizeof (int);
  5792. i += 4)
  5793. csum ^= bfd_getb32 (&p[i]);
  5794. bfd_putb32 (csum, &lst.checksum);
  5795. sprintf (hdr.ar_name, "/ ");
  5796. _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%-12ld",
  5797. bfd_ardata (abfd)->armap_timestamp);
  5798. _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld",
  5799. statbuf.st_uid);
  5800. _bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld",
  5801. statbuf.st_gid);
  5802. _bfd_ar_spacepad (hdr.ar_mode, sizeof (hdr.ar_mode), "%-8o",
  5803. (unsigned int)statbuf.st_mode);
  5804. _bfd_ar_spacepad (hdr.ar_size, sizeof (hdr.ar_size), "%-10d",
  5805. (int) lst_size);
  5806. hdr.ar_fmag[0] = '`';
  5807. hdr.ar_fmag[1] = '\012';
  5808. /* Turn any nulls into spaces. */
  5809. for (i = 0; i < sizeof (struct ar_hdr); i++)
  5810. if (((char *) (&hdr))[i] == '\0')
  5811. (((char *) (&hdr))[i]) = ' ';
  5812. /* Scribble out the ar header. */
  5813. amt = sizeof (struct ar_hdr);
  5814. if (bfd_bwrite ((void *) &hdr, amt, abfd) != amt)
  5815. return FALSE;
  5816. /* Now scribble out the lst header. */
  5817. amt = sizeof (struct som_external_lst_header);
  5818. if (bfd_bwrite ((void *) &lst, amt, abfd) != amt)
  5819. return FALSE;
  5820. /* Build and write the armap. */
  5821. if (!som_bfd_ar_write_symbol_stuff (abfd, nsyms, stringsize, lst, elength))
  5822. return FALSE;
  5823. /* Done. */
  5824. return TRUE;
  5825. }
  5826. /* Free all information we have cached for this BFD. We can always
  5827. read it again later if we need it. */
  5828. static bfd_boolean
  5829. som_bfd_free_cached_info (bfd *abfd)
  5830. {
  5831. asection *o;
  5832. if (bfd_get_format (abfd) != bfd_object)
  5833. return TRUE;
  5834. #define FREE(x) if (x != NULL) { free (x); x = NULL; }
  5835. /* Free the native string and symbol tables. */
  5836. FREE (obj_som_symtab (abfd));
  5837. FREE (obj_som_stringtab (abfd));
  5838. for (o = abfd->sections; o != NULL; o = o->next)
  5839. {
  5840. /* Free the native relocations. */
  5841. o->reloc_count = (unsigned) -1;
  5842. FREE (som_section_data (o)->reloc_stream);
  5843. /* Do not free the generic relocations as they are objalloc'ed. */
  5844. }
  5845. #undef FREE
  5846. return TRUE;
  5847. }
  5848. /* End of miscellaneous support functions. */
  5849. /* Linker support functions. */
  5850. static bfd_boolean
  5851. som_bfd_link_split_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
  5852. {
  5853. return som_is_subspace (sec) && sec->size > 240000;
  5854. }
  5855. #define som_find_line _bfd_nosymbols_find_line
  5856. #define som_get_symbol_version_string _bfd_nosymbols_get_symbol_version_string
  5857. #define som_close_and_cleanup som_bfd_free_cached_info
  5858. #define som_read_ar_hdr _bfd_generic_read_ar_hdr
  5859. #define som_write_ar_hdr _bfd_generic_write_ar_hdr
  5860. #define som_openr_next_archived_file bfd_generic_openr_next_archived_file
  5861. #define som_get_elt_at_index _bfd_generic_get_elt_at_index
  5862. #define som_generic_stat_arch_elt bfd_generic_stat_arch_elt
  5863. #define som_truncate_arname bfd_bsd_truncate_arname
  5864. #define som_slurp_extended_name_table _bfd_slurp_extended_name_table
  5865. #define som_construct_extended_name_table _bfd_archive_coff_construct_extended_name_table
  5866. #define som_update_armap_timestamp bfd_true
  5867. #define som_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
  5868. #define som_get_lineno _bfd_nosymbols_get_lineno
  5869. #define som_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  5870. #define som_read_minisymbols _bfd_generic_read_minisymbols
  5871. #define som_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
  5872. #define som_get_section_contents_in_window _bfd_generic_get_section_contents_in_window
  5873. #define som_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
  5874. #define som_bfd_relax_section bfd_generic_relax_section
  5875. #define som_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
  5876. #define som_bfd_link_add_symbols _bfd_generic_link_add_symbols
  5877. #define som_bfd_link_just_syms _bfd_generic_link_just_syms
  5878. #define som_bfd_copy_link_hash_symbol_type \
  5879. _bfd_generic_copy_link_hash_symbol_type
  5880. #define som_bfd_final_link _bfd_generic_final_link
  5881. #define som_bfd_gc_sections bfd_generic_gc_sections
  5882. #define som_bfd_lookup_section_flags bfd_generic_lookup_section_flags
  5883. #define som_bfd_merge_sections bfd_generic_merge_sections
  5884. #define som_bfd_is_group_section bfd_generic_is_group_section
  5885. #define som_bfd_discard_group bfd_generic_discard_group
  5886. #define som_section_already_linked _bfd_generic_section_already_linked
  5887. #define som_bfd_define_common_symbol bfd_generic_define_common_symbol
  5888. #define som_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
  5889. #define som_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
  5890. #define som_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
  5891. #define som_find_inliner_info _bfd_nosymbols_find_inliner_info
  5892. const bfd_target hppa_som_vec =
  5893. {
  5894. "som", /* Name. */
  5895. bfd_target_som_flavour,
  5896. BFD_ENDIAN_BIG, /* Target byte order. */
  5897. BFD_ENDIAN_BIG, /* Target headers byte order. */
  5898. (HAS_RELOC | EXEC_P | /* Object flags. */
  5899. HAS_LINENO | HAS_DEBUG |
  5900. HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED | DYNAMIC),
  5901. (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS | SEC_LINK_ONCE
  5902. | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* Section flags. */
  5903. /* Leading_symbol_char: is the first char of a user symbol
  5904. predictable, and if so what is it. */
  5905. 0,
  5906. '/', /* AR_pad_char. */
  5907. 14, /* AR_max_namelen. */
  5908. 0, /* match priority. */
  5909. bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  5910. bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  5911. bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Data. */
  5912. bfd_getb64, bfd_getb_signed_64, bfd_putb64,
  5913. bfd_getb32, bfd_getb_signed_32, bfd_putb32,
  5914. bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* Headers. */
  5915. {_bfd_dummy_target,
  5916. som_object_p, /* bfd_check_format. */
  5917. bfd_generic_archive_p,
  5918. _bfd_dummy_target
  5919. },
  5920. {
  5921. bfd_false,
  5922. som_mkobject,
  5923. _bfd_generic_mkarchive,
  5924. bfd_false
  5925. },
  5926. {
  5927. bfd_false,
  5928. som_write_object_contents,
  5929. _bfd_write_archive_contents,
  5930. bfd_false,
  5931. },
  5932. #undef som
  5933. BFD_JUMP_TABLE_GENERIC (som),
  5934. BFD_JUMP_TABLE_COPY (som),
  5935. BFD_JUMP_TABLE_CORE (_bfd_nocore),
  5936. BFD_JUMP_TABLE_ARCHIVE (som),
  5937. BFD_JUMP_TABLE_SYMBOLS (som),
  5938. BFD_JUMP_TABLE_RELOCS (som),
  5939. BFD_JUMP_TABLE_WRITE (som),
  5940. BFD_JUMP_TABLE_LINK (som),
  5941. BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  5942. NULL,
  5943. NULL
  5944. };