som.c 213 KB

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