coffcode.h 176 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178
  1. /* Support for the generic parts of most COFF variants, for BFD.
  2. Copyright (C) 1990-2015 Free Software Foundation, Inc.
  3. Written by Cygnus Support.
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. /* Most of this hacked by Steve Chamberlain,
  18. sac@cygnus.com. */
  19. /*
  20. SECTION
  21. coff backends
  22. BFD supports a number of different flavours of coff format.
  23. The major differences between formats are the sizes and
  24. alignments of fields in structures on disk, and the occasional
  25. extra field.
  26. Coff in all its varieties is implemented with a few common
  27. files and a number of implementation specific files. For
  28. example, The 88k bcs coff format is implemented in the file
  29. @file{coff-m88k.c}. This file @code{#include}s
  30. @file{coff/m88k.h} which defines the external structure of the
  31. coff format for the 88k, and @file{coff/internal.h} which
  32. defines the internal structure. @file{coff-m88k.c} also
  33. defines the relocations used by the 88k format
  34. @xref{Relocations}.
  35. The Intel i960 processor version of coff is implemented in
  36. @file{coff-i960.c}. This file has the same structure as
  37. @file{coff-m88k.c}, except that it includes @file{coff/i960.h}
  38. rather than @file{coff-m88k.h}.
  39. SUBSECTION
  40. Porting to a new version of coff
  41. The recommended method is to select from the existing
  42. implementations the version of coff which is most like the one
  43. you want to use. For example, we'll say that i386 coff is
  44. the one you select, and that your coff flavour is called foo.
  45. Copy @file{i386coff.c} to @file{foocoff.c}, copy
  46. @file{../include/coff/i386.h} to @file{../include/coff/foo.h},
  47. and add the lines to @file{targets.c} and @file{Makefile.in}
  48. so that your new back end is used. Alter the shapes of the
  49. structures in @file{../include/coff/foo.h} so that they match
  50. what you need. You will probably also have to add
  51. @code{#ifdef}s to the code in @file{coff/internal.h} and
  52. @file{coffcode.h} if your version of coff is too wild.
  53. You can verify that your new BFD backend works quite simply by
  54. building @file{objdump} from the @file{binutils} directory,
  55. and making sure that its version of what's going on and your
  56. host system's idea (assuming it has the pretty standard coff
  57. dump utility, usually called @code{att-dump} or just
  58. @code{dump}) are the same. Then clean up your code, and send
  59. what you've done to Cygnus. Then your stuff will be in the
  60. next release, and you won't have to keep integrating it.
  61. SUBSECTION
  62. How the coff backend works
  63. SUBSUBSECTION
  64. File layout
  65. The Coff backend is split into generic routines that are
  66. applicable to any Coff target and routines that are specific
  67. to a particular target. The target-specific routines are
  68. further split into ones which are basically the same for all
  69. Coff targets except that they use the external symbol format
  70. or use different values for certain constants.
  71. The generic routines are in @file{coffgen.c}. These routines
  72. work for any Coff target. They use some hooks into the target
  73. specific code; the hooks are in a @code{bfd_coff_backend_data}
  74. structure, one of which exists for each target.
  75. The essentially similar target-specific routines are in
  76. @file{coffcode.h}. This header file includes executable C code.
  77. The various Coff targets first include the appropriate Coff
  78. header file, make any special defines that are needed, and
  79. then include @file{coffcode.h}.
  80. Some of the Coff targets then also have additional routines in
  81. the target source file itself.
  82. For example, @file{coff-i960.c} includes
  83. @file{coff/internal.h} and @file{coff/i960.h}. It then
  84. defines a few constants, such as @code{I960}, and includes
  85. @file{coffcode.h}. Since the i960 has complex relocation
  86. types, @file{coff-i960.c} also includes some code to
  87. manipulate the i960 relocs. This code is not in
  88. @file{coffcode.h} because it would not be used by any other
  89. target.
  90. SUBSUBSECTION
  91. Coff long section names
  92. In the standard Coff object format, section names are limited to
  93. the eight bytes available in the @code{s_name} field of the
  94. @code{SCNHDR} section header structure. The format requires the
  95. field to be NUL-padded, but not necessarily NUL-terminated, so
  96. the longest section names permitted are a full eight characters.
  97. The Microsoft PE variants of the Coff object file format add
  98. an extension to support the use of long section names. This
  99. extension is defined in section 4 of the Microsoft PE/COFF
  100. specification (rev 8.1). If a section name is too long to fit
  101. into the section header's @code{s_name} field, it is instead
  102. placed into the string table, and the @code{s_name} field is
  103. filled with a slash ("/") followed by the ASCII decimal
  104. representation of the offset of the full name relative to the
  105. string table base.
  106. Note that this implies that the extension can only be used in object
  107. files, as executables do not contain a string table. The standard
  108. specifies that long section names from objects emitted into executable
  109. images are to be truncated.
  110. However, as a GNU extension, BFD can generate executable images
  111. that contain a string table and long section names. This
  112. would appear to be technically valid, as the standard only says
  113. that Coff debugging information is deprecated, not forbidden,
  114. and in practice it works, although some tools that parse PE files
  115. expecting the MS standard format may become confused; @file{PEview} is
  116. one known example.
  117. The functionality is supported in BFD by code implemented under
  118. the control of the macro @code{COFF_LONG_SECTION_NAMES}. If not
  119. defined, the format does not support long section names in any way.
  120. If defined, it is used to initialise a flag,
  121. @code{_bfd_coff_long_section_names}, and a hook function pointer,
  122. @code{_bfd_coff_set_long_section_names}, in the Coff backend data
  123. structure. The flag controls the generation of long section names
  124. in output BFDs at runtime; if it is false, as it will be by default
  125. when generating an executable image, long section names are truncated;
  126. if true, the long section names extension is employed. The hook
  127. points to a function that allows the value of the flag to be altered
  128. at runtime, on formats that support long section names at all; on
  129. other formats it points to a stub that returns an error indication.
  130. With input BFDs, the flag is set according to whether any long section
  131. names are detected while reading the section headers. For a completely
  132. new BFD, the flag is set to the default for the target format. This
  133. information can be used by a client of the BFD library when deciding
  134. what output format to generate, and means that a BFD that is opened
  135. for read and subsequently converted to a writeable BFD and modified
  136. in-place will retain whatever format it had on input.
  137. If @code{COFF_LONG_SECTION_NAMES} is simply defined (blank), or is
  138. defined to the value "1", then long section names are enabled by
  139. default; if it is defined to the value zero, they are disabled by
  140. default (but still accepted in input BFDs). The header @file{coffcode.h}
  141. defines a macro, @code{COFF_DEFAULT_LONG_SECTION_NAMES}, which is
  142. used in the backends to initialise the backend data structure fields
  143. appropriately; see the comments for further detail.
  144. SUBSUBSECTION
  145. Bit twiddling
  146. Each flavour of coff supported in BFD has its own header file
  147. describing the external layout of the structures. There is also
  148. an internal description of the coff layout, in
  149. @file{coff/internal.h}. A major function of the
  150. coff backend is swapping the bytes and twiddling the bits to
  151. translate the external form of the structures into the normal
  152. internal form. This is all performed in the
  153. @code{bfd_swap}_@i{thing}_@i{direction} routines. Some
  154. elements are different sizes between different versions of
  155. coff; it is the duty of the coff version specific include file
  156. to override the definitions of various packing routines in
  157. @file{coffcode.h}. E.g., the size of line number entry in coff is
  158. sometimes 16 bits, and sometimes 32 bits. @code{#define}ing
  159. @code{PUT_LNSZ_LNNO} and @code{GET_LNSZ_LNNO} will select the
  160. correct one. No doubt, some day someone will find a version of
  161. coff which has a varying field size not catered to at the
  162. moment. To port BFD, that person will have to add more @code{#defines}.
  163. Three of the bit twiddling routines are exported to
  164. @code{gdb}; @code{coff_swap_aux_in}, @code{coff_swap_sym_in}
  165. and @code{coff_swap_lineno_in}. @code{GDB} reads the symbol
  166. table on its own, but uses BFD to fix things up. More of the
  167. bit twiddlers are exported for @code{gas};
  168. @code{coff_swap_aux_out}, @code{coff_swap_sym_out},
  169. @code{coff_swap_lineno_out}, @code{coff_swap_reloc_out},
  170. @code{coff_swap_filehdr_out}, @code{coff_swap_aouthdr_out},
  171. @code{coff_swap_scnhdr_out}. @code{Gas} currently keeps track
  172. of all the symbol table and reloc drudgery itself, thereby
  173. saving the internal BFD overhead, but uses BFD to swap things
  174. on the way out, making cross ports much safer. Doing so also
  175. allows BFD (and thus the linker) to use the same header files
  176. as @code{gas}, which makes one avenue to disaster disappear.
  177. SUBSUBSECTION
  178. Symbol reading
  179. The simple canonical form for symbols used by BFD is not rich
  180. enough to keep all the information available in a coff symbol
  181. table. The back end gets around this problem by keeping the original
  182. symbol table around, "behind the scenes".
  183. When a symbol table is requested (through a call to
  184. @code{bfd_canonicalize_symtab}), a request gets through to
  185. @code{coff_get_normalized_symtab}. This reads the symbol table from
  186. the coff file and swaps all the structures inside into the
  187. internal form. It also fixes up all the pointers in the table
  188. (represented in the file by offsets from the first symbol in
  189. the table) into physical pointers to elements in the new
  190. internal table. This involves some work since the meanings of
  191. fields change depending upon context: a field that is a
  192. pointer to another structure in the symbol table at one moment
  193. may be the size in bytes of a structure at the next. Another
  194. pass is made over the table. All symbols which mark file names
  195. (<<C_FILE>> symbols) are modified so that the internal
  196. string points to the value in the auxent (the real filename)
  197. rather than the normal text associated with the symbol
  198. (@code{".file"}).
  199. At this time the symbol names are moved around. Coff stores
  200. all symbols less than nine characters long physically
  201. within the symbol table; longer strings are kept at the end of
  202. the file in the string table. This pass moves all strings
  203. into memory and replaces them with pointers to the strings.
  204. The symbol table is massaged once again, this time to create
  205. the canonical table used by the BFD application. Each symbol
  206. is inspected in turn, and a decision made (using the
  207. @code{sclass} field) about the various flags to set in the
  208. @code{asymbol}. @xref{Symbols}. The generated canonical table
  209. shares strings with the hidden internal symbol table.
  210. Any linenumbers are read from the coff file too, and attached
  211. to the symbols which own the functions the linenumbers belong to.
  212. SUBSUBSECTION
  213. Symbol writing
  214. Writing a symbol to a coff file which didn't come from a coff
  215. file will lose any debugging information. The @code{asymbol}
  216. structure remembers the BFD from which the symbol was taken, and on
  217. output the back end makes sure that the same destination target as
  218. source target is present.
  219. When the symbols have come from a coff file then all the
  220. debugging information is preserved.
  221. Symbol tables are provided for writing to the back end in a
  222. vector of pointers to pointers. This allows applications like
  223. the linker to accumulate and output large symbol tables
  224. without having to do too much byte copying.
  225. This function runs through the provided symbol table and
  226. patches each symbol marked as a file place holder
  227. (@code{C_FILE}) to point to the next file place holder in the
  228. list. It also marks each @code{offset} field in the list with
  229. the offset from the first symbol of the current symbol.
  230. Another function of this procedure is to turn the canonical
  231. value form of BFD into the form used by coff. Internally, BFD
  232. expects symbol values to be offsets from a section base; so a
  233. symbol physically at 0x120, but in a section starting at
  234. 0x100, would have the value 0x20. Coff expects symbols to
  235. contain their final value, so symbols have their values
  236. changed at this point to reflect their sum with their owning
  237. section. This transformation uses the
  238. <<output_section>> field of the @code{asymbol}'s
  239. @code{asection} @xref{Sections}.
  240. o <<coff_mangle_symbols>>
  241. This routine runs though the provided symbol table and uses
  242. the offsets generated by the previous pass and the pointers
  243. generated when the symbol table was read in to create the
  244. structured hierarchy required by coff. It changes each pointer
  245. to a symbol into the index into the symbol table of the asymbol.
  246. o <<coff_write_symbols>>
  247. This routine runs through the symbol table and patches up the
  248. symbols from their internal form into the coff way, calls the
  249. bit twiddlers, and writes out the table to the file.
  250. */
  251. /*
  252. INTERNAL_DEFINITION
  253. coff_symbol_type
  254. DESCRIPTION
  255. The hidden information for an <<asymbol>> is described in a
  256. <<combined_entry_type>>:
  257. CODE_FRAGMENT
  258. .
  259. .typedef struct coff_ptr_struct
  260. .{
  261. . {* Remembers the offset from the first symbol in the file for
  262. . this symbol. Generated by coff_renumber_symbols. *}
  263. . unsigned int offset;
  264. .
  265. . {* Should the value of this symbol be renumbered. Used for
  266. . XCOFF C_BSTAT symbols. Set by coff_slurp_symbol_table. *}
  267. . unsigned int fix_value : 1;
  268. .
  269. . {* Should the tag field of this symbol be renumbered.
  270. . Created by coff_pointerize_aux. *}
  271. . unsigned int fix_tag : 1;
  272. .
  273. . {* Should the endidx field of this symbol be renumbered.
  274. . Created by coff_pointerize_aux. *}
  275. . unsigned int fix_end : 1;
  276. .
  277. . {* Should the x_csect.x_scnlen field be renumbered.
  278. . Created by coff_pointerize_aux. *}
  279. . unsigned int fix_scnlen : 1;
  280. .
  281. . {* Fix up an XCOFF C_BINCL/C_EINCL symbol. The value is the
  282. . index into the line number entries. Set by coff_slurp_symbol_table. *}
  283. . unsigned int fix_line : 1;
  284. .
  285. . {* The container for the symbol structure as read and translated
  286. . from the file. *}
  287. . union
  288. . {
  289. . union internal_auxent auxent;
  290. . struct internal_syment syment;
  291. . } u;
  292. .
  293. . {* Selector for the union above. *}
  294. . bfd_boolean is_sym;
  295. .} combined_entry_type;
  296. .
  297. .
  298. .{* Each canonical asymbol really looks like this: *}
  299. .
  300. .typedef struct coff_symbol_struct
  301. .{
  302. . {* The actual symbol which the rest of BFD works with *}
  303. . asymbol symbol;
  304. .
  305. . {* A pointer to the hidden information for this symbol *}
  306. . combined_entry_type *native;
  307. .
  308. . {* A pointer to the linenumber information for this symbol *}
  309. . struct lineno_cache_entry *lineno;
  310. .
  311. . {* Have the line numbers been relocated yet ? *}
  312. . bfd_boolean done_lineno;
  313. .} coff_symbol_type;
  314. */
  315. #include "libiberty.h"
  316. #ifdef COFF_WITH_PE
  317. #include "peicode.h"
  318. #else
  319. #include "coffswap.h"
  320. #endif
  321. #define STRING_SIZE_SIZE 4
  322. #define DOT_DEBUG ".debug"
  323. #define DOT_ZDEBUG ".zdebug"
  324. #define GNU_LINKONCE_WI ".gnu.linkonce.wi."
  325. #define GNU_LINKONCE_WT ".gnu.linkonce.wt."
  326. #define DOT_RELOC ".reloc"
  327. #if defined (COFF_LONG_SECTION_NAMES)
  328. /* Needed to expand the inputs to BLANKOR1TOODD. */
  329. #define COFFLONGSECTIONCATHELPER(x,y) x ## y
  330. /* If the input macro Y is blank or '1', return an odd number; if it is
  331. '0', return an even number. Result undefined in all other cases. */
  332. #define BLANKOR1TOODD(y) COFFLONGSECTIONCATHELPER(1,y)
  333. /* Defined to numerical 0 or 1 according to whether generation of long
  334. section names is disabled or enabled by default. */
  335. #define COFF_ENABLE_LONG_SECTION_NAMES (BLANKOR1TOODD(COFF_LONG_SECTION_NAMES) & 1)
  336. /* Where long section names are supported, we allow them to be enabled
  337. and disabled at runtime, so select an appropriate hook function for
  338. _bfd_coff_set_long_section_names. */
  339. #define COFF_LONG_SECTION_NAMES_SETTER bfd_coff_set_long_section_names_allowed
  340. #else /* !defined (COFF_LONG_SECTION_NAMES) */
  341. /* If long section names are not supported, this stub disallows any
  342. attempt to enable them at run-time. */
  343. #define COFF_LONG_SECTION_NAMES_SETTER bfd_coff_set_long_section_names_disallowed
  344. #endif /* defined (COFF_LONG_SECTION_NAMES) */
  345. /* Define a macro that can be used to initialise both the fields relating
  346. to long section names in the backend data struct simultaneously. */
  347. #if COFF_ENABLE_LONG_SECTION_NAMES
  348. #define COFF_DEFAULT_LONG_SECTION_NAMES (TRUE), COFF_LONG_SECTION_NAMES_SETTER
  349. #else /* !COFF_ENABLE_LONG_SECTION_NAMES */
  350. #define COFF_DEFAULT_LONG_SECTION_NAMES (FALSE), COFF_LONG_SECTION_NAMES_SETTER
  351. #endif /* COFF_ENABLE_LONG_SECTION_NAMES */
  352. #if defined (COFF_LONG_SECTION_NAMES)
  353. static bfd_boolean bfd_coff_set_long_section_names_allowed
  354. (bfd *, int);
  355. #else /* !defined (COFF_LONG_SECTION_NAMES) */
  356. static bfd_boolean bfd_coff_set_long_section_names_disallowed
  357. (bfd *, int);
  358. #endif /* defined (COFF_LONG_SECTION_NAMES) */
  359. static long sec_to_styp_flags
  360. (const char *, flagword);
  361. static bfd_boolean styp_to_sec_flags
  362. (bfd *, void *, const char *, asection *, flagword *);
  363. static bfd_boolean coff_bad_format_hook
  364. (bfd *, void *);
  365. static void coff_set_custom_section_alignment
  366. (bfd *, asection *, const struct coff_section_alignment_entry *,
  367. const unsigned int);
  368. static bfd_boolean coff_new_section_hook
  369. (bfd *, asection *);
  370. static bfd_boolean coff_set_arch_mach_hook
  371. (bfd *, void *);
  372. static bfd_boolean coff_write_relocs
  373. (bfd *, int);
  374. static bfd_boolean coff_set_flags
  375. (bfd *, unsigned int *, unsigned short *);
  376. static bfd_boolean coff_set_arch_mach
  377. (bfd *, enum bfd_architecture, unsigned long) ATTRIBUTE_UNUSED;
  378. static bfd_boolean coff_compute_section_file_positions
  379. (bfd *);
  380. static bfd_boolean coff_write_object_contents
  381. (bfd *) ATTRIBUTE_UNUSED;
  382. static bfd_boolean coff_set_section_contents
  383. (bfd *, asection *, const void *, file_ptr, bfd_size_type);
  384. static void * buy_and_read
  385. (bfd *, file_ptr, bfd_size_type);
  386. static bfd_boolean coff_slurp_line_table
  387. (bfd *, asection *);
  388. static bfd_boolean coff_slurp_symbol_table
  389. (bfd *);
  390. static enum coff_symbol_classification coff_classify_symbol
  391. (bfd *, struct internal_syment *);
  392. static bfd_boolean coff_slurp_reloc_table
  393. (bfd *, asection *, asymbol **);
  394. static long coff_canonicalize_reloc
  395. (bfd *, asection *, arelent **, asymbol **);
  396. #ifndef coff_mkobject_hook
  397. static void * coff_mkobject_hook
  398. (bfd *, void *, void *);
  399. #endif
  400. #ifdef COFF_WITH_PE
  401. static flagword handle_COMDAT
  402. (bfd *, flagword, void *, const char *, asection *);
  403. #endif
  404. #ifdef COFF_IMAGE_WITH_PE
  405. static bfd_boolean coff_read_word
  406. (bfd *, unsigned int *);
  407. static unsigned int coff_compute_checksum
  408. (bfd *);
  409. static bfd_boolean coff_apply_checksum
  410. (bfd *);
  411. #endif
  412. #ifdef TICOFF
  413. static bfd_boolean ticoff0_bad_format_hook
  414. (bfd *, void * );
  415. static bfd_boolean ticoff1_bad_format_hook
  416. (bfd *, void * );
  417. #endif
  418. /* void warning(); */
  419. #if defined (COFF_LONG_SECTION_NAMES)
  420. static bfd_boolean
  421. bfd_coff_set_long_section_names_allowed (bfd *abfd, int enable)
  422. {
  423. coff_backend_info (abfd)->_bfd_coff_long_section_names = enable;
  424. return TRUE;
  425. }
  426. #else /* !defined (COFF_LONG_SECTION_NAMES) */
  427. static bfd_boolean
  428. bfd_coff_set_long_section_names_disallowed (bfd *abfd, int enable)
  429. {
  430. (void) abfd;
  431. (void) enable;
  432. return FALSE;
  433. }
  434. #endif /* defined (COFF_LONG_SECTION_NAMES) */
  435. /* Return a word with STYP_* (scnhdr.s_flags) flags set to represent
  436. the incoming SEC_* flags. The inverse of this function is
  437. styp_to_sec_flags(). NOTE: If you add to/change this routine, you
  438. should probably mirror the changes in styp_to_sec_flags(). */
  439. #ifndef COFF_WITH_PE
  440. /* Macros for setting debugging flags. */
  441. #ifdef STYP_DEBUG
  442. #define STYP_XCOFF_DEBUG STYP_DEBUG
  443. #else
  444. #define STYP_XCOFF_DEBUG STYP_INFO
  445. #endif
  446. #ifdef COFF_ALIGN_IN_S_FLAGS
  447. #define STYP_DEBUG_INFO STYP_DSECT
  448. #else
  449. #define STYP_DEBUG_INFO STYP_INFO
  450. #endif
  451. static long
  452. sec_to_styp_flags (const char *sec_name, flagword sec_flags)
  453. {
  454. long styp_flags = 0;
  455. if (!strcmp (sec_name, _TEXT))
  456. {
  457. styp_flags = STYP_TEXT;
  458. }
  459. else if (!strcmp (sec_name, _DATA))
  460. {
  461. styp_flags = STYP_DATA;
  462. }
  463. else if (!strcmp (sec_name, _BSS))
  464. {
  465. styp_flags = STYP_BSS;
  466. #ifdef _COMMENT
  467. }
  468. else if (!strcmp (sec_name, _COMMENT))
  469. {
  470. styp_flags = STYP_INFO;
  471. #endif /* _COMMENT */
  472. #ifdef _LIB
  473. }
  474. else if (!strcmp (sec_name, _LIB))
  475. {
  476. styp_flags = STYP_LIB;
  477. #endif /* _LIB */
  478. #ifdef _LIT
  479. }
  480. else if (!strcmp (sec_name, _LIT))
  481. {
  482. styp_flags = STYP_LIT;
  483. #endif /* _LIT */
  484. }
  485. else if (CONST_STRNEQ (sec_name, DOT_DEBUG)
  486. || CONST_STRNEQ (sec_name, DOT_ZDEBUG))
  487. {
  488. /* Handle the XCOFF debug section and DWARF2 debug sections. */
  489. if (!sec_name[6])
  490. styp_flags = STYP_XCOFF_DEBUG;
  491. else
  492. styp_flags = STYP_DEBUG_INFO;
  493. }
  494. else if (CONST_STRNEQ (sec_name, ".stab"))
  495. {
  496. styp_flags = STYP_DEBUG_INFO;
  497. }
  498. #ifdef COFF_LONG_SECTION_NAMES
  499. else if (CONST_STRNEQ (sec_name, GNU_LINKONCE_WI)
  500. || CONST_STRNEQ (sec_name, GNU_LINKONCE_WT))
  501. {
  502. styp_flags = STYP_DEBUG_INFO;
  503. }
  504. #endif
  505. #ifdef RS6000COFF_C
  506. else if (!strcmp (sec_name, _PAD))
  507. {
  508. styp_flags = STYP_PAD;
  509. }
  510. else if (!strcmp (sec_name, _LOADER))
  511. {
  512. styp_flags = STYP_LOADER;
  513. }
  514. else if (!strcmp (sec_name, _EXCEPT))
  515. {
  516. styp_flags = STYP_EXCEPT;
  517. }
  518. else if (!strcmp (sec_name, _TYPCHK))
  519. {
  520. styp_flags = STYP_TYPCHK;
  521. }
  522. else if (sec_flags & SEC_DEBUGGING)
  523. {
  524. int i;
  525. for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
  526. if (!strcmp (sec_name, xcoff_dwsect_names[i].name))
  527. {
  528. styp_flags = STYP_DWARF | xcoff_dwsect_names[i].flag;
  529. break;
  530. }
  531. }
  532. #endif
  533. /* Try and figure out what it should be */
  534. else if (sec_flags & SEC_CODE)
  535. {
  536. styp_flags = STYP_TEXT;
  537. }
  538. else if (sec_flags & SEC_DATA)
  539. {
  540. styp_flags = STYP_DATA;
  541. }
  542. else if (sec_flags & SEC_READONLY)
  543. {
  544. #ifdef STYP_LIT /* 29k readonly text/data section */
  545. styp_flags = STYP_LIT;
  546. #else
  547. styp_flags = STYP_TEXT;
  548. #endif /* STYP_LIT */
  549. }
  550. else if (sec_flags & SEC_LOAD)
  551. {
  552. styp_flags = STYP_TEXT;
  553. }
  554. else if (sec_flags & SEC_ALLOC)
  555. {
  556. styp_flags = STYP_BSS;
  557. }
  558. #ifdef STYP_CLINK
  559. if (sec_flags & SEC_TIC54X_CLINK)
  560. styp_flags |= STYP_CLINK;
  561. #endif
  562. #ifdef STYP_BLOCK
  563. if (sec_flags & SEC_TIC54X_BLOCK)
  564. styp_flags |= STYP_BLOCK;
  565. #endif
  566. #ifdef STYP_NOLOAD
  567. if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
  568. styp_flags |= STYP_NOLOAD;
  569. #endif
  570. return styp_flags;
  571. }
  572. #else /* COFF_WITH_PE */
  573. /* The PE version; see above for the general comments. The non-PE
  574. case seems to be more guessing, and breaks PE format; specifically,
  575. .rdata is readonly, but it sure ain't text. Really, all this
  576. should be set up properly in gas (or whatever assembler is in use),
  577. and honor whatever objcopy/strip, etc. sent us as input. */
  578. static long
  579. sec_to_styp_flags (const char *sec_name, flagword sec_flags)
  580. {
  581. long styp_flags = 0;
  582. bfd_boolean is_dbg = FALSE;
  583. if (CONST_STRNEQ (sec_name, DOT_DEBUG)
  584. || CONST_STRNEQ (sec_name, DOT_ZDEBUG)
  585. #ifdef COFF_LONG_SECTION_NAMES
  586. || CONST_STRNEQ (sec_name, GNU_LINKONCE_WI)
  587. || CONST_STRNEQ (sec_name, GNU_LINKONCE_WT)
  588. #endif
  589. || CONST_STRNEQ (sec_name, ".stab"))
  590. is_dbg = TRUE;
  591. /* caution: there are at least three groups of symbols that have
  592. very similar bits and meanings: IMAGE_SCN*, SEC_*, and STYP_*.
  593. SEC_* are the BFD internal flags, used for generic BFD
  594. information. STYP_* are the COFF section flags which appear in
  595. COFF files. IMAGE_SCN_* are the PE section flags which appear in
  596. PE files. The STYP_* flags and the IMAGE_SCN_* flags overlap,
  597. but there are more IMAGE_SCN_* flags. */
  598. /* FIXME: There is no gas syntax to specify the debug section flag. */
  599. if (is_dbg)
  600. {
  601. sec_flags &= (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
  602. | SEC_LINK_DUPLICATES_SAME_CONTENTS
  603. | SEC_LINK_DUPLICATES_SAME_SIZE);
  604. sec_flags |= SEC_DEBUGGING | SEC_READONLY;
  605. }
  606. /* skip LOAD */
  607. /* READONLY later */
  608. /* skip RELOC */
  609. if ((sec_flags & SEC_CODE) != 0)
  610. styp_flags |= IMAGE_SCN_CNT_CODE;
  611. if ((sec_flags & (SEC_DATA | SEC_DEBUGGING)) != 0)
  612. styp_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
  613. if ((sec_flags & SEC_ALLOC) != 0 && (sec_flags & SEC_LOAD) == 0)
  614. styp_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA; /* ==STYP_BSS */
  615. /* skip ROM */
  616. /* skip constRUCTOR */
  617. /* skip CONTENTS */
  618. if ((sec_flags & SEC_IS_COMMON) != 0)
  619. styp_flags |= IMAGE_SCN_LNK_COMDAT;
  620. if ((sec_flags & SEC_DEBUGGING) != 0)
  621. styp_flags |= IMAGE_SCN_MEM_DISCARDABLE;
  622. if ((sec_flags & SEC_EXCLUDE) != 0 && !is_dbg)
  623. styp_flags |= IMAGE_SCN_LNK_REMOVE;
  624. if ((sec_flags & SEC_NEVER_LOAD) != 0 && !is_dbg)
  625. styp_flags |= IMAGE_SCN_LNK_REMOVE;
  626. /* skip IN_MEMORY */
  627. /* skip SORT */
  628. if (sec_flags & SEC_LINK_ONCE)
  629. styp_flags |= IMAGE_SCN_LNK_COMDAT;
  630. if ((sec_flags
  631. & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS
  632. | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0)
  633. styp_flags |= IMAGE_SCN_LNK_COMDAT;
  634. /* skip LINKER_CREATED */
  635. if ((sec_flags & SEC_COFF_NOREAD) == 0)
  636. styp_flags |= IMAGE_SCN_MEM_READ; /* Invert NOREAD for read. */
  637. if ((sec_flags & SEC_READONLY) == 0)
  638. styp_flags |= IMAGE_SCN_MEM_WRITE; /* Invert READONLY for write. */
  639. if (sec_flags & SEC_CODE)
  640. styp_flags |= IMAGE_SCN_MEM_EXECUTE; /* CODE->EXECUTE. */
  641. if (sec_flags & SEC_COFF_SHARED)
  642. styp_flags |= IMAGE_SCN_MEM_SHARED; /* Shared remains meaningful. */
  643. return styp_flags;
  644. }
  645. #endif /* COFF_WITH_PE */
  646. /* Return a word with SEC_* flags set to represent the incoming STYP_*
  647. flags (from scnhdr.s_flags). The inverse of this function is
  648. sec_to_styp_flags(). NOTE: If you add to/change this routine, you
  649. should probably mirror the changes in sec_to_styp_flags(). */
  650. #ifndef COFF_WITH_PE
  651. static bfd_boolean
  652. styp_to_sec_flags (bfd *abfd ATTRIBUTE_UNUSED,
  653. void * hdr,
  654. const char *name,
  655. asection *section ATTRIBUTE_UNUSED,
  656. flagword *flags_ptr)
  657. {
  658. struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
  659. long styp_flags = internal_s->s_flags;
  660. flagword sec_flags = 0;
  661. #ifdef STYP_BLOCK
  662. if (styp_flags & STYP_BLOCK)
  663. sec_flags |= SEC_TIC54X_BLOCK;
  664. #endif
  665. #ifdef STYP_CLINK
  666. if (styp_flags & STYP_CLINK)
  667. sec_flags |= SEC_TIC54X_CLINK;
  668. #endif
  669. #ifdef STYP_NOLOAD
  670. if (styp_flags & STYP_NOLOAD)
  671. sec_flags |= SEC_NEVER_LOAD;
  672. #endif /* STYP_NOLOAD */
  673. /* For 386 COFF, at least, an unloadable text or data section is
  674. actually a shared library section. */
  675. if (styp_flags & STYP_TEXT)
  676. {
  677. if (sec_flags & SEC_NEVER_LOAD)
  678. sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
  679. else
  680. sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
  681. }
  682. else if (styp_flags & STYP_DATA)
  683. {
  684. if (sec_flags & SEC_NEVER_LOAD)
  685. sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
  686. else
  687. sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
  688. }
  689. else if (styp_flags & STYP_BSS)
  690. {
  691. #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
  692. if (sec_flags & SEC_NEVER_LOAD)
  693. sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
  694. else
  695. #endif
  696. sec_flags |= SEC_ALLOC;
  697. }
  698. else if (styp_flags & STYP_INFO)
  699. {
  700. /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
  701. defined. coff_compute_section_file_positions uses
  702. COFF_PAGE_SIZE to ensure that the low order bits of the
  703. section VMA and the file offset match. If we don't know
  704. COFF_PAGE_SIZE, we can't ensure the correct correspondence,
  705. and demand page loading of the file will fail. */
  706. #if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
  707. sec_flags |= SEC_DEBUGGING;
  708. #endif
  709. }
  710. else if (styp_flags & STYP_PAD)
  711. sec_flags = 0;
  712. #ifdef RS6000COFF_C
  713. else if (styp_flags & STYP_EXCEPT)
  714. sec_flags |= SEC_LOAD;
  715. else if (styp_flags & STYP_LOADER)
  716. sec_flags |= SEC_LOAD;
  717. else if (styp_flags & STYP_TYPCHK)
  718. sec_flags |= SEC_LOAD;
  719. else if (styp_flags & STYP_DWARF)
  720. sec_flags |= SEC_DEBUGGING;
  721. #endif
  722. else if (strcmp (name, _TEXT) == 0)
  723. {
  724. if (sec_flags & SEC_NEVER_LOAD)
  725. sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
  726. else
  727. sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
  728. }
  729. else if (strcmp (name, _DATA) == 0)
  730. {
  731. if (sec_flags & SEC_NEVER_LOAD)
  732. sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
  733. else
  734. sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
  735. }
  736. else if (strcmp (name, _BSS) == 0)
  737. {
  738. #ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
  739. if (sec_flags & SEC_NEVER_LOAD)
  740. sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
  741. else
  742. #endif
  743. sec_flags |= SEC_ALLOC;
  744. }
  745. else if (CONST_STRNEQ (name, DOT_DEBUG)
  746. || CONST_STRNEQ (name, DOT_ZDEBUG)
  747. #ifdef _COMMENT
  748. || strcmp (name, _COMMENT) == 0
  749. #endif
  750. #ifdef COFF_LONG_SECTION_NAMES
  751. || CONST_STRNEQ (name, GNU_LINKONCE_WI)
  752. || CONST_STRNEQ (name, GNU_LINKONCE_WT)
  753. #endif
  754. || CONST_STRNEQ (name, ".stab"))
  755. {
  756. #ifdef COFF_PAGE_SIZE
  757. sec_flags |= SEC_DEBUGGING;
  758. #endif
  759. }
  760. #ifdef _LIB
  761. else if (strcmp (name, _LIB) == 0)
  762. ;
  763. #endif
  764. #ifdef _LIT
  765. else if (strcmp (name, _LIT) == 0)
  766. sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
  767. #endif
  768. else
  769. sec_flags |= SEC_ALLOC | SEC_LOAD;
  770. #ifdef STYP_LIT /* A29k readonly text/data section type. */
  771. if ((styp_flags & STYP_LIT) == STYP_LIT)
  772. sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
  773. #endif /* STYP_LIT */
  774. #ifdef STYP_OTHER_LOAD /* Other loaded sections. */
  775. if (styp_flags & STYP_OTHER_LOAD)
  776. sec_flags = (SEC_LOAD | SEC_ALLOC);
  777. #endif /* STYP_SDATA */
  778. #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
  779. /* As a GNU extension, if the name begins with .gnu.linkonce, we
  780. only link a single copy of the section. This is used to support
  781. g++. g++ will emit each template expansion in its own section.
  782. The symbols will be defined as weak, so that multiple definitions
  783. are permitted. The GNU linker extension is to actually discard
  784. all but one of the sections. */
  785. if (CONST_STRNEQ (name, ".gnu.linkonce"))
  786. sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
  787. #endif
  788. if (flags_ptr == NULL)
  789. return FALSE;
  790. * flags_ptr = sec_flags;
  791. return TRUE;
  792. }
  793. #else /* COFF_WITH_PE */
  794. static flagword
  795. handle_COMDAT (bfd * abfd,
  796. flagword sec_flags,
  797. void * hdr,
  798. const char *name,
  799. asection *section)
  800. {
  801. struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
  802. bfd_byte *esymstart, *esym, *esymend;
  803. int seen_state = 0;
  804. char *target_name = NULL;
  805. sec_flags |= SEC_LINK_ONCE;
  806. /* Unfortunately, the PE format stores essential information in
  807. the symbol table, of all places. We need to extract that
  808. information now, so that objdump and the linker will know how
  809. to handle the section without worrying about the symbols. We
  810. can't call slurp_symtab, because the linker doesn't want the
  811. swapped symbols. */
  812. /* COMDAT sections are special. The first symbol is the section
  813. symbol, which tells what kind of COMDAT section it is. The
  814. second symbol is the "comdat symbol" - the one with the
  815. unique name. GNU uses the section symbol for the unique
  816. name; MS uses ".text" for every comdat section. Sigh. - DJ */
  817. /* This is not mirrored in sec_to_styp_flags(), but there
  818. doesn't seem to be a need to, either, and it would at best be
  819. rather messy. */
  820. if (! _bfd_coff_get_external_symbols (abfd))
  821. return sec_flags;
  822. esymstart = esym = (bfd_byte *) obj_coff_external_syms (abfd);
  823. esymend = esym + obj_raw_syment_count (abfd) * bfd_coff_symesz (abfd);
  824. while (esym < esymend)
  825. {
  826. struct internal_syment isym;
  827. char buf[SYMNMLEN + 1];
  828. const char *symname;
  829. bfd_coff_swap_sym_in (abfd, esym, & isym);
  830. BFD_ASSERT (sizeof (internal_s->s_name) <= SYMNMLEN);
  831. if (isym.n_scnum == section->target_index)
  832. {
  833. /* According to the MSVC documentation, the first
  834. TWO entries with the section # are both of
  835. interest to us. The first one is the "section
  836. symbol" (section name). The second is the comdat
  837. symbol name. Here, we've found the first
  838. qualifying entry; we distinguish it from the
  839. second with a state flag.
  840. In the case of gas-generated (at least until that
  841. is fixed) .o files, it isn't necessarily the
  842. second one. It may be some other later symbol.
  843. Since gas also doesn't follow MS conventions and
  844. emits the section similar to .text$<name>, where
  845. <something> is the name we're looking for, we
  846. distinguish the two as follows:
  847. If the section name is simply a section name (no
  848. $) we presume it's MS-generated, and look at
  849. precisely the second symbol for the comdat name.
  850. If the section name has a $, we assume it's
  851. gas-generated, and look for <something> (whatever
  852. follows the $) as the comdat symbol. */
  853. /* All 3 branches use this. */
  854. symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
  855. /* PR 17512 file: 078-11867-0.004 */
  856. if (symname == NULL)
  857. {
  858. _bfd_error_handler (_("%B: unable to load COMDAT section name"), abfd);
  859. break;
  860. }
  861. switch (seen_state)
  862. {
  863. case 0:
  864. {
  865. /* The first time we've seen the symbol. */
  866. union internal_auxent aux;
  867. /* If it isn't the stuff we're expecting, die;
  868. The MS documentation is vague, but it
  869. appears that the second entry serves BOTH
  870. as the comdat symbol and the defining
  871. symbol record (either C_STAT or C_EXT,
  872. possibly with an aux entry with debug
  873. information if it's a function.) It
  874. appears the only way to find the second one
  875. is to count. (On Intel, they appear to be
  876. adjacent, but on Alpha, they have been
  877. found separated.)
  878. Here, we think we've found the first one,
  879. but there's some checking we can do to be
  880. sure. */
  881. if (! ((isym.n_sclass == C_STAT
  882. || isym.n_sclass == C_EXT)
  883. && BTYPE (isym.n_type) == T_NULL
  884. && isym.n_value == 0))
  885. abort ();
  886. /* FIXME LATER: MSVC generates section names
  887. like .text for comdats. Gas generates
  888. names like .text$foo__Fv (in the case of a
  889. function). See comment above for more. */
  890. if (isym.n_sclass == C_STAT && strcmp (name, symname) != 0)
  891. _bfd_error_handler (_("%B: warning: COMDAT symbol '%s' does not match section name '%s'"),
  892. abfd, symname, name);
  893. seen_state = 1;
  894. /* PR 17512: file: e2cfe54f. */
  895. if (esym + bfd_coff_symesz (abfd) >= esymend)
  896. {
  897. _bfd_error_handler (_("%B: warning: No symbol for section '%s' found"),
  898. abfd, symname);
  899. break;
  900. }
  901. /* This is the section symbol. */
  902. bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
  903. isym.n_type, isym.n_sclass,
  904. 0, isym.n_numaux, & aux);
  905. target_name = strchr (name, '$');
  906. if (target_name != NULL)
  907. {
  908. /* Gas mode. */
  909. seen_state = 2;
  910. /* Skip the `$'. */
  911. target_name += 1;
  912. }
  913. /* FIXME: Microsoft uses NODUPLICATES and
  914. ASSOCIATIVE, but gnu uses ANY and
  915. SAME_SIZE. Unfortunately, gnu doesn't do
  916. the comdat symbols right. So, until we can
  917. fix it to do the right thing, we are
  918. temporarily disabling comdats for the MS
  919. types (they're used in DLLs and C++, but we
  920. don't support *their* C++ libraries anyway
  921. - DJ. */
  922. /* Cygwin does not follow the MS style, and
  923. uses ANY and SAME_SIZE where NODUPLICATES
  924. and ASSOCIATIVE should be used. For
  925. Interix, we just do the right thing up
  926. front. */
  927. switch (aux.x_scn.x_comdat)
  928. {
  929. case IMAGE_COMDAT_SELECT_NODUPLICATES:
  930. #ifdef STRICT_PE_FORMAT
  931. sec_flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
  932. #else
  933. sec_flags &= ~SEC_LINK_ONCE;
  934. #endif
  935. break;
  936. case IMAGE_COMDAT_SELECT_ANY:
  937. sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
  938. break;
  939. case IMAGE_COMDAT_SELECT_SAME_SIZE:
  940. sec_flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
  941. break;
  942. case IMAGE_COMDAT_SELECT_EXACT_MATCH:
  943. /* Not yet fully implemented ??? */
  944. sec_flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
  945. break;
  946. /* debug$S gets this case; other
  947. implications ??? */
  948. /* There may be no symbol... we'll search
  949. the whole table... Is this the right
  950. place to play this game? Or should we do
  951. it when reading it in. */
  952. case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
  953. #ifdef STRICT_PE_FORMAT
  954. /* FIXME: This is not currently implemented. */
  955. sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
  956. #else
  957. sec_flags &= ~SEC_LINK_ONCE;
  958. #endif
  959. break;
  960. default: /* 0 means "no symbol" */
  961. /* debug$F gets this case; other
  962. implications ??? */
  963. sec_flags |= SEC_LINK_DUPLICATES_DISCARD;
  964. break;
  965. }
  966. }
  967. break;
  968. case 2:
  969. /* Gas mode: the first matching on partial name. */
  970. #ifndef TARGET_UNDERSCORE
  971. #define TARGET_UNDERSCORE 0
  972. #endif
  973. /* Is this the name we're looking for ? */
  974. if (strcmp (target_name,
  975. symname + (TARGET_UNDERSCORE ? 1 : 0)) != 0)
  976. {
  977. /* Not the name we're looking for */
  978. esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd);
  979. continue;
  980. }
  981. /* Fall through. */
  982. case 1:
  983. /* MSVC mode: the lexically second symbol (or
  984. drop through from the above). */
  985. {
  986. char *newname;
  987. bfd_size_type amt;
  988. /* This must the second symbol with the
  989. section #. It is the actual symbol name.
  990. Intel puts the two adjacent, but Alpha (at
  991. least) spreads them out. */
  992. amt = sizeof (struct coff_comdat_info);
  993. coff_section_data (abfd, section)->comdat
  994. = (struct coff_comdat_info *) bfd_alloc (abfd, amt);
  995. if (coff_section_data (abfd, section)->comdat == NULL)
  996. abort ();
  997. coff_section_data (abfd, section)->comdat->symbol =
  998. (esym - esymstart) / bfd_coff_symesz (abfd);
  999. amt = strlen (symname) + 1;
  1000. newname = (char *) bfd_alloc (abfd, amt);
  1001. if (newname == NULL)
  1002. abort ();
  1003. strcpy (newname, symname);
  1004. coff_section_data (abfd, section)->comdat->name
  1005. = newname;
  1006. }
  1007. goto breakloop;
  1008. }
  1009. }
  1010. esym += (isym.n_numaux + 1) * bfd_coff_symesz (abfd);
  1011. }
  1012. breakloop:
  1013. return sec_flags;
  1014. }
  1015. /* The PE version; see above for the general comments.
  1016. Since to set the SEC_LINK_ONCE and associated flags, we have to
  1017. look at the symbol table anyway, we return the symbol table index
  1018. of the symbol being used as the COMDAT symbol. This is admittedly
  1019. ugly, but there's really nowhere else that we have access to the
  1020. required information. FIXME: Is the COMDAT symbol index used for
  1021. any purpose other than objdump? */
  1022. static bfd_boolean
  1023. styp_to_sec_flags (bfd *abfd,
  1024. void * hdr,
  1025. const char *name,
  1026. asection *section,
  1027. flagword *flags_ptr)
  1028. {
  1029. struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
  1030. unsigned long styp_flags = internal_s->s_flags;
  1031. flagword sec_flags;
  1032. bfd_boolean result = TRUE;
  1033. bfd_boolean is_dbg = FALSE;
  1034. if (CONST_STRNEQ (name, DOT_DEBUG)
  1035. || CONST_STRNEQ (name, DOT_ZDEBUG)
  1036. #ifdef COFF_LONG_SECTION_NAMES
  1037. || CONST_STRNEQ (name, GNU_LINKONCE_WI)
  1038. || CONST_STRNEQ (name, GNU_LINKONCE_WT)
  1039. #endif
  1040. || CONST_STRNEQ (name, ".stab"))
  1041. is_dbg = TRUE;
  1042. /* Assume read only unless IMAGE_SCN_MEM_WRITE is specified. */
  1043. sec_flags = SEC_READONLY;
  1044. /* If section disallows read, then set the NOREAD flag. */
  1045. if ((styp_flags & IMAGE_SCN_MEM_READ) == 0)
  1046. sec_flags |= SEC_COFF_NOREAD;
  1047. /* Process each flag bit in styp_flags in turn. */
  1048. while (styp_flags)
  1049. {
  1050. unsigned long flag = styp_flags & - styp_flags;
  1051. char * unhandled = NULL;
  1052. styp_flags &= ~ flag;
  1053. /* We infer from the distinct read/write/execute bits the settings
  1054. of some of the bfd flags; the actual values, should we need them,
  1055. are also in pei_section_data (abfd, section)->pe_flags. */
  1056. switch (flag)
  1057. {
  1058. case STYP_DSECT:
  1059. unhandled = "STYP_DSECT";
  1060. break;
  1061. case STYP_GROUP:
  1062. unhandled = "STYP_GROUP";
  1063. break;
  1064. case STYP_COPY:
  1065. unhandled = "STYP_COPY";
  1066. break;
  1067. case STYP_OVER:
  1068. unhandled = "STYP_OVER";
  1069. break;
  1070. #ifdef SEC_NEVER_LOAD
  1071. case STYP_NOLOAD:
  1072. sec_flags |= SEC_NEVER_LOAD;
  1073. break;
  1074. #endif
  1075. case IMAGE_SCN_MEM_READ:
  1076. sec_flags &= ~SEC_COFF_NOREAD;
  1077. break;
  1078. case IMAGE_SCN_TYPE_NO_PAD:
  1079. /* Skip. */
  1080. break;
  1081. case IMAGE_SCN_LNK_OTHER:
  1082. unhandled = "IMAGE_SCN_LNK_OTHER";
  1083. break;
  1084. case IMAGE_SCN_MEM_NOT_CACHED:
  1085. unhandled = "IMAGE_SCN_MEM_NOT_CACHED";
  1086. break;
  1087. case IMAGE_SCN_MEM_NOT_PAGED:
  1088. /* Generate a warning message rather using the 'unhandled'
  1089. variable as this will allow some .sys files generate by
  1090. other toolchains to be processed. See bugzilla issue 196. */
  1091. _bfd_error_handler (_("%B: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section %s"),
  1092. abfd, name);
  1093. break;
  1094. case IMAGE_SCN_MEM_EXECUTE:
  1095. sec_flags |= SEC_CODE;
  1096. break;
  1097. case IMAGE_SCN_MEM_WRITE:
  1098. sec_flags &= ~ SEC_READONLY;
  1099. break;
  1100. case IMAGE_SCN_MEM_DISCARDABLE:
  1101. /* The MS PE spec says that debug sections are DISCARDABLE,
  1102. but the presence of a DISCARDABLE flag does not necessarily
  1103. mean that a given section contains debug information. Thus
  1104. we only set the SEC_DEBUGGING flag on sections that we
  1105. recognise as containing debug information. */
  1106. if (is_dbg
  1107. #ifdef _COMMENT
  1108. || strcmp (name, _COMMENT) == 0
  1109. #endif
  1110. )
  1111. {
  1112. sec_flags |= SEC_DEBUGGING | SEC_READONLY;
  1113. }
  1114. break;
  1115. case IMAGE_SCN_MEM_SHARED:
  1116. sec_flags |= SEC_COFF_SHARED;
  1117. break;
  1118. case IMAGE_SCN_LNK_REMOVE:
  1119. if (!is_dbg)
  1120. sec_flags |= SEC_EXCLUDE;
  1121. break;
  1122. case IMAGE_SCN_CNT_CODE:
  1123. sec_flags |= SEC_CODE | SEC_ALLOC | SEC_LOAD;
  1124. break;
  1125. case IMAGE_SCN_CNT_INITIALIZED_DATA:
  1126. if (is_dbg)
  1127. sec_flags |= SEC_DEBUGGING;
  1128. else
  1129. sec_flags |= SEC_DATA | SEC_ALLOC | SEC_LOAD;
  1130. break;
  1131. case IMAGE_SCN_CNT_UNINITIALIZED_DATA:
  1132. sec_flags |= SEC_ALLOC;
  1133. break;
  1134. case IMAGE_SCN_LNK_INFO:
  1135. /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
  1136. defined. coff_compute_section_file_positions uses
  1137. COFF_PAGE_SIZE to ensure that the low order bits of the
  1138. section VMA and the file offset match. If we don't know
  1139. COFF_PAGE_SIZE, we can't ensure the correct correspondence,
  1140. and demand page loading of the file will fail. */
  1141. #ifdef COFF_PAGE_SIZE
  1142. sec_flags |= SEC_DEBUGGING;
  1143. #endif
  1144. break;
  1145. case IMAGE_SCN_LNK_COMDAT:
  1146. /* COMDAT gets very special treatment. */
  1147. sec_flags = handle_COMDAT (abfd, sec_flags, hdr, name, section);
  1148. break;
  1149. default:
  1150. /* Silently ignore for now. */
  1151. break;
  1152. }
  1153. /* If the section flag was not handled, report it here. */
  1154. if (unhandled != NULL)
  1155. {
  1156. (*_bfd_error_handler)
  1157. (_("%B (%s): Section flag %s (0x%x) ignored"),
  1158. abfd, name, unhandled, flag);
  1159. result = FALSE;
  1160. }
  1161. }
  1162. #if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
  1163. /* As a GNU extension, if the name begins with .gnu.linkonce, we
  1164. only link a single copy of the section. This is used to support
  1165. g++. g++ will emit each template expansion in its own section.
  1166. The symbols will be defined as weak, so that multiple definitions
  1167. are permitted. The GNU linker extension is to actually discard
  1168. all but one of the sections. */
  1169. if (CONST_STRNEQ (name, ".gnu.linkonce"))
  1170. sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
  1171. #endif
  1172. if (flags_ptr)
  1173. * flags_ptr = sec_flags;
  1174. return result;
  1175. }
  1176. #endif /* COFF_WITH_PE */
  1177. #define get_index(symbol) ((symbol)->udata.i)
  1178. /*
  1179. INTERNAL_DEFINITION
  1180. bfd_coff_backend_data
  1181. CODE_FRAGMENT
  1182. .{* COFF symbol classifications. *}
  1183. .
  1184. .enum coff_symbol_classification
  1185. .{
  1186. . {* Global symbol. *}
  1187. . COFF_SYMBOL_GLOBAL,
  1188. . {* Common symbol. *}
  1189. . COFF_SYMBOL_COMMON,
  1190. . {* Undefined symbol. *}
  1191. . COFF_SYMBOL_UNDEFINED,
  1192. . {* Local symbol. *}
  1193. . COFF_SYMBOL_LOCAL,
  1194. . {* PE section symbol. *}
  1195. . COFF_SYMBOL_PE_SECTION
  1196. .};
  1197. .
  1198. .typedef asection * (*coff_gc_mark_hook_fn)
  1199. . (asection *, struct bfd_link_info *, struct internal_reloc *,
  1200. . struct coff_link_hash_entry *, struct internal_syment *);
  1201. .
  1202. Special entry points for gdb to swap in coff symbol table parts:
  1203. .typedef struct
  1204. .{
  1205. . void (*_bfd_coff_swap_aux_in)
  1206. . (bfd *, void *, int, int, int, int, void *);
  1207. .
  1208. . void (*_bfd_coff_swap_sym_in)
  1209. . (bfd *, void *, void *);
  1210. .
  1211. . void (*_bfd_coff_swap_lineno_in)
  1212. . (bfd *, void *, void *);
  1213. .
  1214. . unsigned int (*_bfd_coff_swap_aux_out)
  1215. . (bfd *, void *, int, int, int, int, void *);
  1216. .
  1217. . unsigned int (*_bfd_coff_swap_sym_out)
  1218. . (bfd *, void *, void *);
  1219. .
  1220. . unsigned int (*_bfd_coff_swap_lineno_out)
  1221. . (bfd *, void *, void *);
  1222. .
  1223. . unsigned int (*_bfd_coff_swap_reloc_out)
  1224. . (bfd *, void *, void *);
  1225. .
  1226. . unsigned int (*_bfd_coff_swap_filehdr_out)
  1227. . (bfd *, void *, void *);
  1228. .
  1229. . unsigned int (*_bfd_coff_swap_aouthdr_out)
  1230. . (bfd *, void *, void *);
  1231. .
  1232. . unsigned int (*_bfd_coff_swap_scnhdr_out)
  1233. . (bfd *, void *, void *);
  1234. .
  1235. . unsigned int _bfd_filhsz;
  1236. . unsigned int _bfd_aoutsz;
  1237. . unsigned int _bfd_scnhsz;
  1238. . unsigned int _bfd_symesz;
  1239. . unsigned int _bfd_auxesz;
  1240. . unsigned int _bfd_relsz;
  1241. . unsigned int _bfd_linesz;
  1242. . unsigned int _bfd_filnmlen;
  1243. . bfd_boolean _bfd_coff_long_filenames;
  1244. .
  1245. . bfd_boolean _bfd_coff_long_section_names;
  1246. . bfd_boolean (*_bfd_coff_set_long_section_names)
  1247. . (bfd *, int);
  1248. .
  1249. . unsigned int _bfd_coff_default_section_alignment_power;
  1250. . bfd_boolean _bfd_coff_force_symnames_in_strings;
  1251. . unsigned int _bfd_coff_debug_string_prefix_length;
  1252. . unsigned int _bfd_coff_max_nscns;
  1253. .
  1254. . void (*_bfd_coff_swap_filehdr_in)
  1255. . (bfd *, void *, void *);
  1256. .
  1257. . void (*_bfd_coff_swap_aouthdr_in)
  1258. . (bfd *, void *, void *);
  1259. .
  1260. . void (*_bfd_coff_swap_scnhdr_in)
  1261. . (bfd *, void *, void *);
  1262. .
  1263. . void (*_bfd_coff_swap_reloc_in)
  1264. . (bfd *abfd, void *, void *);
  1265. .
  1266. . bfd_boolean (*_bfd_coff_bad_format_hook)
  1267. . (bfd *, void *);
  1268. .
  1269. . bfd_boolean (*_bfd_coff_set_arch_mach_hook)
  1270. . (bfd *, void *);
  1271. .
  1272. . void * (*_bfd_coff_mkobject_hook)
  1273. . (bfd *, void *, void *);
  1274. .
  1275. . bfd_boolean (*_bfd_styp_to_sec_flags_hook)
  1276. . (bfd *, void *, const char *, asection *, flagword *);
  1277. .
  1278. . void (*_bfd_set_alignment_hook)
  1279. . (bfd *, asection *, void *);
  1280. .
  1281. . bfd_boolean (*_bfd_coff_slurp_symbol_table)
  1282. . (bfd *);
  1283. .
  1284. . bfd_boolean (*_bfd_coff_symname_in_debug)
  1285. . (bfd *, struct internal_syment *);
  1286. .
  1287. . bfd_boolean (*_bfd_coff_pointerize_aux_hook)
  1288. . (bfd *, combined_entry_type *, combined_entry_type *,
  1289. . unsigned int, combined_entry_type *);
  1290. .
  1291. . bfd_boolean (*_bfd_coff_print_aux)
  1292. . (bfd *, FILE *, combined_entry_type *, combined_entry_type *,
  1293. . combined_entry_type *, unsigned int);
  1294. .
  1295. . void (*_bfd_coff_reloc16_extra_cases)
  1296. . (bfd *, struct bfd_link_info *, struct bfd_link_order *, arelent *,
  1297. . bfd_byte *, unsigned int *, unsigned int *);
  1298. .
  1299. . int (*_bfd_coff_reloc16_estimate)
  1300. . (bfd *, asection *, arelent *, unsigned int,
  1301. . struct bfd_link_info *);
  1302. .
  1303. . enum coff_symbol_classification (*_bfd_coff_classify_symbol)
  1304. . (bfd *, struct internal_syment *);
  1305. .
  1306. . bfd_boolean (*_bfd_coff_compute_section_file_positions)
  1307. . (bfd *);
  1308. .
  1309. . bfd_boolean (*_bfd_coff_start_final_link)
  1310. . (bfd *, struct bfd_link_info *);
  1311. .
  1312. . bfd_boolean (*_bfd_coff_relocate_section)
  1313. . (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
  1314. . struct internal_reloc *, struct internal_syment *, asection **);
  1315. .
  1316. . reloc_howto_type *(*_bfd_coff_rtype_to_howto)
  1317. . (bfd *, asection *, struct internal_reloc *,
  1318. . struct coff_link_hash_entry *, struct internal_syment *,
  1319. . bfd_vma *);
  1320. .
  1321. . bfd_boolean (*_bfd_coff_adjust_symndx)
  1322. . (bfd *, struct bfd_link_info *, bfd *, asection *,
  1323. . struct internal_reloc *, bfd_boolean *);
  1324. .
  1325. . bfd_boolean (*_bfd_coff_link_add_one_symbol)
  1326. . (struct bfd_link_info *, bfd *, const char *, flagword,
  1327. . asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean,
  1328. . struct bfd_link_hash_entry **);
  1329. .
  1330. . bfd_boolean (*_bfd_coff_link_output_has_begun)
  1331. . (bfd *, struct coff_final_link_info *);
  1332. .
  1333. . bfd_boolean (*_bfd_coff_final_link_postscript)
  1334. . (bfd *, struct coff_final_link_info *);
  1335. .
  1336. . bfd_boolean (*_bfd_coff_print_pdata)
  1337. . (bfd *, void *);
  1338. .
  1339. .} bfd_coff_backend_data;
  1340. .
  1341. .#define coff_backend_info(abfd) \
  1342. . ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
  1343. .
  1344. .#define bfd_coff_swap_aux_in(a,e,t,c,ind,num,i) \
  1345. . ((coff_backend_info (a)->_bfd_coff_swap_aux_in) (a,e,t,c,ind,num,i))
  1346. .
  1347. .#define bfd_coff_swap_sym_in(a,e,i) \
  1348. . ((coff_backend_info (a)->_bfd_coff_swap_sym_in) (a,e,i))
  1349. .
  1350. .#define bfd_coff_swap_lineno_in(a,e,i) \
  1351. . ((coff_backend_info ( a)->_bfd_coff_swap_lineno_in) (a,e,i))
  1352. .
  1353. .#define bfd_coff_swap_reloc_out(abfd, i, o) \
  1354. . ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_out) (abfd, i, o))
  1355. .
  1356. .#define bfd_coff_swap_lineno_out(abfd, i, o) \
  1357. . ((coff_backend_info (abfd)->_bfd_coff_swap_lineno_out) (abfd, i, o))
  1358. .
  1359. .#define bfd_coff_swap_aux_out(a,i,t,c,ind,num,o) \
  1360. . ((coff_backend_info (a)->_bfd_coff_swap_aux_out) (a,i,t,c,ind,num,o))
  1361. .
  1362. .#define bfd_coff_swap_sym_out(abfd, i,o) \
  1363. . ((coff_backend_info (abfd)->_bfd_coff_swap_sym_out) (abfd, i, o))
  1364. .
  1365. .#define bfd_coff_swap_scnhdr_out(abfd, i,o) \
  1366. . ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_out) (abfd, i, o))
  1367. .
  1368. .#define bfd_coff_swap_filehdr_out(abfd, i,o) \
  1369. . ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_out) (abfd, i, o))
  1370. .
  1371. .#define bfd_coff_swap_aouthdr_out(abfd, i,o) \
  1372. . ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_out) (abfd, i, o))
  1373. .
  1374. .#define bfd_coff_filhsz(abfd) (coff_backend_info (abfd)->_bfd_filhsz)
  1375. .#define bfd_coff_aoutsz(abfd) (coff_backend_info (abfd)->_bfd_aoutsz)
  1376. .#define bfd_coff_scnhsz(abfd) (coff_backend_info (abfd)->_bfd_scnhsz)
  1377. .#define bfd_coff_symesz(abfd) (coff_backend_info (abfd)->_bfd_symesz)
  1378. .#define bfd_coff_auxesz(abfd) (coff_backend_info (abfd)->_bfd_auxesz)
  1379. .#define bfd_coff_relsz(abfd) (coff_backend_info (abfd)->_bfd_relsz)
  1380. .#define bfd_coff_linesz(abfd) (coff_backend_info (abfd)->_bfd_linesz)
  1381. .#define bfd_coff_filnmlen(abfd) (coff_backend_info (abfd)->_bfd_filnmlen)
  1382. .#define bfd_coff_long_filenames(abfd) \
  1383. . (coff_backend_info (abfd)->_bfd_coff_long_filenames)
  1384. .#define bfd_coff_long_section_names(abfd) \
  1385. . (coff_backend_info (abfd)->_bfd_coff_long_section_names)
  1386. .#define bfd_coff_set_long_section_names(abfd, enable) \
  1387. . ((coff_backend_info (abfd)->_bfd_coff_set_long_section_names) (abfd, enable))
  1388. .#define bfd_coff_default_section_alignment_power(abfd) \
  1389. . (coff_backend_info (abfd)->_bfd_coff_default_section_alignment_power)
  1390. .#define bfd_coff_max_nscns(abfd) \
  1391. . (coff_backend_info (abfd)->_bfd_coff_max_nscns)
  1392. .
  1393. .#define bfd_coff_swap_filehdr_in(abfd, i,o) \
  1394. . ((coff_backend_info (abfd)->_bfd_coff_swap_filehdr_in) (abfd, i, o))
  1395. .
  1396. .#define bfd_coff_swap_aouthdr_in(abfd, i,o) \
  1397. . ((coff_backend_info (abfd)->_bfd_coff_swap_aouthdr_in) (abfd, i, o))
  1398. .
  1399. .#define bfd_coff_swap_scnhdr_in(abfd, i,o) \
  1400. . ((coff_backend_info (abfd)->_bfd_coff_swap_scnhdr_in) (abfd, i, o))
  1401. .
  1402. .#define bfd_coff_swap_reloc_in(abfd, i, o) \
  1403. . ((coff_backend_info (abfd)->_bfd_coff_swap_reloc_in) (abfd, i, o))
  1404. .
  1405. .#define bfd_coff_bad_format_hook(abfd, filehdr) \
  1406. . ((coff_backend_info (abfd)->_bfd_coff_bad_format_hook) (abfd, filehdr))
  1407. .
  1408. .#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
  1409. . ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
  1410. .#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
  1411. . ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook)\
  1412. . (abfd, filehdr, aouthdr))
  1413. .
  1414. .#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr, name, section, flags_ptr)\
  1415. . ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook)\
  1416. . (abfd, scnhdr, name, section, flags_ptr))
  1417. .
  1418. .#define bfd_coff_set_alignment_hook(abfd, sec, scnhdr)\
  1419. . ((coff_backend_info (abfd)->_bfd_set_alignment_hook) (abfd, sec, scnhdr))
  1420. .
  1421. .#define bfd_coff_slurp_symbol_table(abfd)\
  1422. . ((coff_backend_info (abfd)->_bfd_coff_slurp_symbol_table) (abfd))
  1423. .
  1424. .#define bfd_coff_symname_in_debug(abfd, sym)\
  1425. . ((coff_backend_info (abfd)->_bfd_coff_symname_in_debug) (abfd, sym))
  1426. .
  1427. .#define bfd_coff_force_symnames_in_strings(abfd)\
  1428. . (coff_backend_info (abfd)->_bfd_coff_force_symnames_in_strings)
  1429. .
  1430. .#define bfd_coff_debug_string_prefix_length(abfd)\
  1431. . (coff_backend_info (abfd)->_bfd_coff_debug_string_prefix_length)
  1432. .
  1433. .#define bfd_coff_print_aux(abfd, file, base, symbol, aux, indaux)\
  1434. . ((coff_backend_info (abfd)->_bfd_coff_print_aux)\
  1435. . (abfd, file, base, symbol, aux, indaux))
  1436. .
  1437. .#define bfd_coff_reloc16_extra_cases(abfd, link_info, link_order,\
  1438. . reloc, data, src_ptr, dst_ptr)\
  1439. . ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
  1440. . (abfd, link_info, link_order, reloc, data, src_ptr, dst_ptr))
  1441. .
  1442. .#define bfd_coff_reloc16_estimate(abfd, section, reloc, shrink, link_info)\
  1443. . ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
  1444. . (abfd, section, reloc, shrink, link_info))
  1445. .
  1446. .#define bfd_coff_classify_symbol(abfd, sym)\
  1447. . ((coff_backend_info (abfd)->_bfd_coff_classify_symbol)\
  1448. . (abfd, sym))
  1449. .
  1450. .#define bfd_coff_compute_section_file_positions(abfd)\
  1451. . ((coff_backend_info (abfd)->_bfd_coff_compute_section_file_positions)\
  1452. . (abfd))
  1453. .
  1454. .#define bfd_coff_start_final_link(obfd, info)\
  1455. . ((coff_backend_info (obfd)->_bfd_coff_start_final_link)\
  1456. . (obfd, info))
  1457. .#define bfd_coff_relocate_section(obfd,info,ibfd,o,con,rel,isyms,secs)\
  1458. . ((coff_backend_info (ibfd)->_bfd_coff_relocate_section)\
  1459. . (obfd, info, ibfd, o, con, rel, isyms, secs))
  1460. .#define bfd_coff_rtype_to_howto(abfd, sec, rel, h, sym, addendp)\
  1461. . ((coff_backend_info (abfd)->_bfd_coff_rtype_to_howto)\
  1462. . (abfd, sec, rel, h, sym, addendp))
  1463. .#define bfd_coff_adjust_symndx(obfd, info, ibfd, sec, rel, adjustedp)\
  1464. . ((coff_backend_info (abfd)->_bfd_coff_adjust_symndx)\
  1465. . (obfd, info, ibfd, sec, rel, adjustedp))
  1466. .#define bfd_coff_link_add_one_symbol(info, abfd, name, flags, section,\
  1467. . value, string, cp, coll, hashp)\
  1468. . ((coff_backend_info (abfd)->_bfd_coff_link_add_one_symbol)\
  1469. . (info, abfd, name, flags, section, value, string, cp, coll, hashp))
  1470. .
  1471. .#define bfd_coff_link_output_has_begun(a,p) \
  1472. . ((coff_backend_info (a)->_bfd_coff_link_output_has_begun) (a, p))
  1473. .#define bfd_coff_final_link_postscript(a,p) \
  1474. . ((coff_backend_info (a)->_bfd_coff_final_link_postscript) (a, p))
  1475. .
  1476. .#define bfd_coff_have_print_pdata(a) \
  1477. . (coff_backend_info (a)->_bfd_coff_print_pdata)
  1478. .#define bfd_coff_print_pdata(a,p) \
  1479. . ((coff_backend_info (a)->_bfd_coff_print_pdata) (a, p))
  1480. .
  1481. .{* Macro: Returns true if the bfd is a PE executable as opposed to a
  1482. . PE object file. *}
  1483. .#define bfd_pei_p(abfd) \
  1484. . (CONST_STRNEQ ((abfd)->xvec->name, "pei-"))
  1485. */
  1486. /* See whether the magic number matches. */
  1487. static bfd_boolean
  1488. coff_bad_format_hook (bfd * abfd ATTRIBUTE_UNUSED, void * filehdr)
  1489. {
  1490. struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
  1491. if (BADMAG (*internal_f))
  1492. return FALSE;
  1493. /* If the optional header is NULL or not the correct size then
  1494. quit; the only difference I can see between m88k dgux headers (MC88DMAGIC)
  1495. and Intel 960 readwrite headers (I960WRMAGIC) is that the
  1496. optional header is of a different size.
  1497. But the mips keeps extra stuff in it's opthdr, so dont check
  1498. when doing that. */
  1499. #if defined(M88) || defined(I960)
  1500. if (internal_f->f_opthdr != 0 && bfd_coff_aoutsz (abfd) != internal_f->f_opthdr)
  1501. return FALSE;
  1502. #endif
  1503. return TRUE;
  1504. }
  1505. #ifdef TICOFF
  1506. static bfd_boolean
  1507. ticoff0_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
  1508. {
  1509. struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
  1510. if (COFF0_BADMAG (*internal_f))
  1511. return FALSE;
  1512. return TRUE;
  1513. }
  1514. #endif
  1515. #ifdef TICOFF
  1516. static bfd_boolean
  1517. ticoff1_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void * filehdr)
  1518. {
  1519. struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
  1520. if (COFF1_BADMAG (*internal_f))
  1521. return FALSE;
  1522. return TRUE;
  1523. }
  1524. #endif
  1525. /* Check whether this section uses an alignment other than the
  1526. default. */
  1527. static void
  1528. coff_set_custom_section_alignment (bfd *abfd ATTRIBUTE_UNUSED,
  1529. asection *section,
  1530. const struct coff_section_alignment_entry *alignment_table,
  1531. const unsigned int table_size)
  1532. {
  1533. const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
  1534. unsigned int i;
  1535. for (i = 0; i < table_size; ++i)
  1536. {
  1537. const char *secname = bfd_get_section_name (abfd, section);
  1538. if (alignment_table[i].comparison_length == (unsigned int) -1
  1539. ? strcmp (alignment_table[i].name, secname) == 0
  1540. : strncmp (alignment_table[i].name, secname,
  1541. alignment_table[i].comparison_length) == 0)
  1542. break;
  1543. }
  1544. if (i >= table_size)
  1545. return;
  1546. if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
  1547. && default_alignment < alignment_table[i].default_alignment_min)
  1548. return;
  1549. if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
  1550. #if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
  1551. && default_alignment > alignment_table[i].default_alignment_max
  1552. #endif
  1553. )
  1554. return;
  1555. section->alignment_power = alignment_table[i].alignment_power;
  1556. }
  1557. /* Custom section alignment records. */
  1558. static const struct coff_section_alignment_entry
  1559. coff_section_alignment_table[] =
  1560. {
  1561. #ifdef COFF_SECTION_ALIGNMENT_ENTRIES
  1562. COFF_SECTION_ALIGNMENT_ENTRIES,
  1563. #endif
  1564. /* There must not be any gaps between .stabstr sections. */
  1565. { COFF_SECTION_NAME_PARTIAL_MATCH (".stabstr"),
  1566. 1, COFF_ALIGNMENT_FIELD_EMPTY, 0 },
  1567. /* The .stab section must be aligned to 2**2 at most, to avoid gaps. */
  1568. { COFF_SECTION_NAME_PARTIAL_MATCH (".stab"),
  1569. 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
  1570. /* Similarly for the .ctors and .dtors sections. */
  1571. { COFF_SECTION_NAME_EXACT_MATCH (".ctors"),
  1572. 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 },
  1573. { COFF_SECTION_NAME_EXACT_MATCH (".dtors"),
  1574. 3, COFF_ALIGNMENT_FIELD_EMPTY, 2 }
  1575. };
  1576. static const unsigned int coff_section_alignment_table_size =
  1577. sizeof coff_section_alignment_table / sizeof coff_section_alignment_table[0];
  1578. /* Initialize a section structure with information peculiar to this
  1579. particular implementation of COFF. */
  1580. static bfd_boolean
  1581. coff_new_section_hook (bfd * abfd, asection * section)
  1582. {
  1583. combined_entry_type *native;
  1584. bfd_size_type amt;
  1585. unsigned char sclass = C_STAT;
  1586. section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
  1587. #ifdef RS6000COFF_C
  1588. if (bfd_xcoff_text_align_power (abfd) != 0
  1589. && strcmp (bfd_get_section_name (abfd, section), ".text") == 0)
  1590. section->alignment_power = bfd_xcoff_text_align_power (abfd);
  1591. else if (bfd_xcoff_data_align_power (abfd) != 0
  1592. && strcmp (bfd_get_section_name (abfd, section), ".data") == 0)
  1593. section->alignment_power = bfd_xcoff_data_align_power (abfd);
  1594. else
  1595. {
  1596. int i;
  1597. for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
  1598. if (strcmp (bfd_get_section_name (abfd, section),
  1599. xcoff_dwsect_names[i].name) == 0)
  1600. {
  1601. section->alignment_power = 0;
  1602. sclass = C_DWARF;
  1603. break;
  1604. }
  1605. }
  1606. #endif
  1607. /* Set up the section symbol. */
  1608. if (!_bfd_generic_new_section_hook (abfd, section))
  1609. return FALSE;
  1610. /* Allocate aux records for section symbols, to store size and
  1611. related info.
  1612. @@ The 10 is a guess at a plausible maximum number of aux entries
  1613. (but shouldn't be a constant). */
  1614. amt = sizeof (combined_entry_type) * 10;
  1615. native = (combined_entry_type *) bfd_zalloc (abfd, amt);
  1616. if (native == NULL)
  1617. return FALSE;
  1618. /* We don't need to set up n_name, n_value, or n_scnum in the native
  1619. symbol information, since they'll be overridden by the BFD symbol
  1620. anyhow. However, we do need to set the type and storage class,
  1621. in case this symbol winds up getting written out. The value 0
  1622. for n_numaux is already correct. */
  1623. native->is_sym = TRUE;
  1624. native->u.syment.n_type = T_NULL;
  1625. native->u.syment.n_sclass = sclass;
  1626. coffsymbol (section->symbol)->native = native;
  1627. coff_set_custom_section_alignment (abfd, section,
  1628. coff_section_alignment_table,
  1629. coff_section_alignment_table_size);
  1630. return TRUE;
  1631. }
  1632. #ifdef COFF_ALIGN_IN_SECTION_HEADER
  1633. /* Set the alignment of a BFD section. */
  1634. static void
  1635. coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
  1636. asection * section,
  1637. void * scnhdr)
  1638. {
  1639. struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
  1640. unsigned int i;
  1641. #ifdef I960
  1642. /* Extract ALIGN from 2**ALIGN stored in section header. */
  1643. for (i = 0; i < 32; i++)
  1644. if ((1 << i) >= hdr->s_align)
  1645. break;
  1646. #endif
  1647. #ifdef TIC80COFF
  1648. /* TI tools puts the alignment power in bits 8-11. */
  1649. i = (hdr->s_flags >> 8) & 0xF ;
  1650. #endif
  1651. #ifdef COFF_DECODE_ALIGNMENT
  1652. i = COFF_DECODE_ALIGNMENT(hdr->s_flags);
  1653. #endif
  1654. section->alignment_power = i;
  1655. #ifdef coff_set_section_load_page
  1656. coff_set_section_load_page (section, hdr->s_page);
  1657. #endif
  1658. }
  1659. #else /* ! COFF_ALIGN_IN_SECTION_HEADER */
  1660. #ifdef COFF_WITH_PE
  1661. static void
  1662. coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
  1663. asection * section,
  1664. void * scnhdr)
  1665. {
  1666. struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
  1667. bfd_size_type amt;
  1668. unsigned int alignment_power_const
  1669. = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
  1670. switch (alignment_power_const)
  1671. {
  1672. case IMAGE_SCN_ALIGN_8192BYTES:
  1673. case IMAGE_SCN_ALIGN_4096BYTES:
  1674. case IMAGE_SCN_ALIGN_2048BYTES:
  1675. case IMAGE_SCN_ALIGN_1024BYTES:
  1676. case IMAGE_SCN_ALIGN_512BYTES:
  1677. case IMAGE_SCN_ALIGN_256BYTES:
  1678. case IMAGE_SCN_ALIGN_128BYTES:
  1679. case IMAGE_SCN_ALIGN_64BYTES:
  1680. case IMAGE_SCN_ALIGN_32BYTES:
  1681. case IMAGE_SCN_ALIGN_16BYTES:
  1682. case IMAGE_SCN_ALIGN_8BYTES:
  1683. case IMAGE_SCN_ALIGN_4BYTES:
  1684. case IMAGE_SCN_ALIGN_2BYTES:
  1685. case IMAGE_SCN_ALIGN_1BYTES:
  1686. section->alignment_power
  1687. = IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
  1688. break;
  1689. default:
  1690. break;
  1691. }
  1692. /* In a PE image file, the s_paddr field holds the virtual size of a
  1693. section, while the s_size field holds the raw size. We also keep
  1694. the original section flag value, since not every bit can be
  1695. mapped onto a generic BFD section bit. */
  1696. if (coff_section_data (abfd, section) == NULL)
  1697. {
  1698. amt = sizeof (struct coff_section_tdata);
  1699. section->used_by_bfd = bfd_zalloc (abfd, amt);
  1700. if (section->used_by_bfd == NULL)
  1701. /* FIXME: Return error. */
  1702. abort ();
  1703. }
  1704. if (pei_section_data (abfd, section) == NULL)
  1705. {
  1706. amt = sizeof (struct pei_section_tdata);
  1707. coff_section_data (abfd, section)->tdata = bfd_zalloc (abfd, amt);
  1708. if (coff_section_data (abfd, section)->tdata == NULL)
  1709. /* FIXME: Return error. */
  1710. abort ();
  1711. }
  1712. pei_section_data (abfd, section)->virt_size = hdr->s_paddr;
  1713. pei_section_data (abfd, section)->pe_flags = hdr->s_flags;
  1714. section->lma = hdr->s_vaddr;
  1715. /* Check for extended relocs. */
  1716. if (hdr->s_flags & IMAGE_SCN_LNK_NRELOC_OVFL)
  1717. {
  1718. struct external_reloc dst;
  1719. struct internal_reloc n;
  1720. file_ptr oldpos = bfd_tell (abfd);
  1721. bfd_size_type relsz = bfd_coff_relsz (abfd);
  1722. if (bfd_seek (abfd, (file_ptr) hdr->s_relptr, 0) != 0)
  1723. return;
  1724. if (bfd_bread (& dst, relsz, abfd) != relsz)
  1725. return;
  1726. coff_swap_reloc_in (abfd, &dst, &n);
  1727. if (bfd_seek (abfd, oldpos, 0) != 0)
  1728. return;
  1729. section->reloc_count = hdr->s_nreloc = n.r_vaddr - 1;
  1730. section->rel_filepos += relsz;
  1731. }
  1732. else if (hdr->s_nreloc == 0xffff)
  1733. (*_bfd_error_handler)
  1734. ("%s: warning: claims to have 0xffff relocs, without overflow",
  1735. bfd_get_filename (abfd));
  1736. }
  1737. #undef ALIGN_SET
  1738. #undef ELIFALIGN_SET
  1739. #else /* ! COFF_WITH_PE */
  1740. #ifdef RS6000COFF_C
  1741. /* We grossly abuse this function to handle XCOFF overflow headers.
  1742. When we see one, we correct the reloc and line number counts in the
  1743. real header, and remove the section we just created. */
  1744. static void
  1745. coff_set_alignment_hook (bfd *abfd, asection *section, void * scnhdr)
  1746. {
  1747. struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
  1748. asection *real_sec;
  1749. if ((hdr->s_flags & STYP_OVRFLO) == 0)
  1750. return;
  1751. real_sec = coff_section_from_bfd_index (abfd, (int) hdr->s_nreloc);
  1752. if (real_sec == NULL)
  1753. return;
  1754. real_sec->reloc_count = hdr->s_paddr;
  1755. real_sec->lineno_count = hdr->s_vaddr;
  1756. if (!bfd_section_removed_from_list (abfd, section))
  1757. {
  1758. bfd_section_list_remove (abfd, section);
  1759. --abfd->section_count;
  1760. }
  1761. }
  1762. #else /* ! RS6000COFF_C */
  1763. #define coff_set_alignment_hook \
  1764. ((void (*) (bfd *, asection *, void *)) bfd_void)
  1765. #endif /* ! RS6000COFF_C */
  1766. #endif /* ! COFF_WITH_PE */
  1767. #endif /* ! COFF_ALIGN_IN_SECTION_HEADER */
  1768. #ifndef coff_mkobject
  1769. static bfd_boolean
  1770. coff_mkobject (bfd * abfd)
  1771. {
  1772. coff_data_type *coff;
  1773. bfd_size_type amt = sizeof (coff_data_type);
  1774. abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
  1775. if (abfd->tdata.coff_obj_data == NULL)
  1776. return FALSE;
  1777. coff = coff_data (abfd);
  1778. coff->symbols = NULL;
  1779. coff->conversion_table = NULL;
  1780. coff->raw_syments = NULL;
  1781. coff->relocbase = 0;
  1782. coff->local_toc_sym_map = 0;
  1783. /* make_abs_section(abfd);*/
  1784. return TRUE;
  1785. }
  1786. #endif
  1787. /* Create the COFF backend specific information. */
  1788. #ifndef coff_mkobject_hook
  1789. static void *
  1790. coff_mkobject_hook (bfd * abfd,
  1791. void * filehdr,
  1792. void * aouthdr ATTRIBUTE_UNUSED)
  1793. {
  1794. struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
  1795. coff_data_type *coff;
  1796. if (! coff_mkobject (abfd))
  1797. return NULL;
  1798. coff = coff_data (abfd);
  1799. coff->sym_filepos = internal_f->f_symptr;
  1800. /* These members communicate important constants about the symbol
  1801. table to GDB's symbol-reading code. These `constants'
  1802. unfortunately vary among coff implementations... */
  1803. coff->local_n_btmask = N_BTMASK;
  1804. coff->local_n_btshft = N_BTSHFT;
  1805. coff->local_n_tmask = N_TMASK;
  1806. coff->local_n_tshift = N_TSHIFT;
  1807. coff->local_symesz = bfd_coff_symesz (abfd);
  1808. coff->local_auxesz = bfd_coff_auxesz (abfd);
  1809. coff->local_linesz = bfd_coff_linesz (abfd);
  1810. coff->timestamp = internal_f->f_timdat;
  1811. obj_raw_syment_count (abfd) =
  1812. obj_conv_table_size (abfd) =
  1813. internal_f->f_nsyms;
  1814. #ifdef RS6000COFF_C
  1815. if ((internal_f->f_flags & F_SHROBJ) != 0)
  1816. abfd->flags |= DYNAMIC;
  1817. if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
  1818. {
  1819. struct internal_aouthdr *internal_a =
  1820. (struct internal_aouthdr *) aouthdr;
  1821. struct xcoff_tdata *xcoff;
  1822. xcoff = xcoff_data (abfd);
  1823. # ifdef U803XTOCMAGIC
  1824. xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
  1825. # else
  1826. xcoff->xcoff64 = 0;
  1827. # endif
  1828. xcoff->full_aouthdr = TRUE;
  1829. xcoff->toc = internal_a->o_toc;
  1830. xcoff->sntoc = internal_a->o_sntoc;
  1831. xcoff->snentry = internal_a->o_snentry;
  1832. bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
  1833. bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
  1834. xcoff->modtype = internal_a->o_modtype;
  1835. xcoff->cputype = internal_a->o_cputype;
  1836. xcoff->maxdata = internal_a->o_maxdata;
  1837. xcoff->maxstack = internal_a->o_maxstack;
  1838. }
  1839. #endif
  1840. #ifdef ARM
  1841. /* Set the flags field from the COFF header read in. */
  1842. if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
  1843. coff->flags = 0;
  1844. #endif
  1845. #ifdef COFF_WITH_PE
  1846. /* FIXME: I'm not sure this is ever executed, since peicode.h
  1847. defines coff_mkobject_hook. */
  1848. if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
  1849. abfd->flags |= HAS_DEBUG;
  1850. #endif
  1851. if ((internal_f->f_flags & F_GO32STUB) != 0)
  1852. {
  1853. coff->go32stub = (char *) bfd_alloc (abfd, (bfd_size_type) GO32_STUBSIZE);
  1854. if (coff->go32stub == NULL)
  1855. return NULL;
  1856. }
  1857. if (coff->go32stub != NULL)
  1858. memcpy (coff->go32stub, internal_f->go32stub, GO32_STUBSIZE);
  1859. return coff;
  1860. }
  1861. #endif
  1862. /* Determine the machine architecture and type. FIXME: This is target
  1863. dependent because the magic numbers are defined in the target
  1864. dependent header files. But there is no particular need for this.
  1865. If the magic numbers were moved to a separate file, this function
  1866. would be target independent and would also be much more successful
  1867. at linking together COFF files for different architectures. */
  1868. static bfd_boolean
  1869. coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
  1870. {
  1871. unsigned long machine;
  1872. enum bfd_architecture arch;
  1873. struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
  1874. /* Zero selects the default machine for an arch. */
  1875. machine = 0;
  1876. switch (internal_f->f_magic)
  1877. {
  1878. #ifdef PPCMAGIC
  1879. case PPCMAGIC:
  1880. arch = bfd_arch_powerpc;
  1881. break;
  1882. #endif
  1883. #ifdef I386MAGIC
  1884. case I386MAGIC:
  1885. case I386PTXMAGIC:
  1886. case I386AIXMAGIC: /* Danbury PS/2 AIX C Compiler. */
  1887. case LYNXCOFFMAGIC: /* Shadows the m68k Lynx number below, sigh. */
  1888. arch = bfd_arch_i386;
  1889. break;
  1890. #endif
  1891. #ifdef AMD64MAGIC
  1892. case AMD64MAGIC:
  1893. arch = bfd_arch_i386;
  1894. machine = bfd_mach_x86_64;
  1895. break;
  1896. #endif
  1897. #ifdef IA64MAGIC
  1898. case IA64MAGIC:
  1899. arch = bfd_arch_ia64;
  1900. break;
  1901. #endif
  1902. #ifdef ARMMAGIC
  1903. case ARMMAGIC:
  1904. case ARMPEMAGIC:
  1905. case THUMBPEMAGIC:
  1906. arch = bfd_arch_arm;
  1907. machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
  1908. if (machine == bfd_mach_arm_unknown)
  1909. {
  1910. switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
  1911. {
  1912. case F_ARM_2: machine = bfd_mach_arm_2; break;
  1913. case F_ARM_2a: machine = bfd_mach_arm_2a; break;
  1914. case F_ARM_3: machine = bfd_mach_arm_3; break;
  1915. default:
  1916. case F_ARM_3M: machine = bfd_mach_arm_3M; break;
  1917. case F_ARM_4: machine = bfd_mach_arm_4; break;
  1918. case F_ARM_4T: machine = bfd_mach_arm_4T; break;
  1919. /* The COFF header does not have enough bits available
  1920. to cover all the different ARM architectures. So
  1921. we interpret F_ARM_5, the highest flag value to mean
  1922. "the highest ARM architecture known to BFD" which is
  1923. currently the XScale. */
  1924. case F_ARM_5: machine = bfd_mach_arm_XScale; break;
  1925. }
  1926. }
  1927. break;
  1928. #endif
  1929. #ifdef MC68MAGIC
  1930. case MC68MAGIC:
  1931. case M68MAGIC:
  1932. #ifdef MC68KBCSMAGIC
  1933. case MC68KBCSMAGIC:
  1934. #endif
  1935. #ifdef APOLLOM68KMAGIC
  1936. case APOLLOM68KMAGIC:
  1937. #endif
  1938. #ifdef LYNXCOFFMAGIC
  1939. case LYNXCOFFMAGIC:
  1940. #endif
  1941. arch = bfd_arch_m68k;
  1942. machine = bfd_mach_m68020;
  1943. break;
  1944. #endif
  1945. #ifdef MC88MAGIC
  1946. case MC88MAGIC:
  1947. case MC88DMAGIC:
  1948. case MC88OMAGIC:
  1949. arch = bfd_arch_m88k;
  1950. machine = 88100;
  1951. break;
  1952. #endif
  1953. #ifdef Z80MAGIC
  1954. case Z80MAGIC:
  1955. arch = bfd_arch_z80;
  1956. switch (internal_f->f_flags & F_MACHMASK)
  1957. {
  1958. case 0:
  1959. case bfd_mach_z80strict << 12:
  1960. case bfd_mach_z80 << 12:
  1961. case bfd_mach_z80full << 12:
  1962. case bfd_mach_r800 << 12:
  1963. machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
  1964. break;
  1965. default:
  1966. return FALSE;
  1967. }
  1968. break;
  1969. #endif
  1970. #ifdef Z8KMAGIC
  1971. case Z8KMAGIC:
  1972. arch = bfd_arch_z8k;
  1973. switch (internal_f->f_flags & F_MACHMASK)
  1974. {
  1975. case F_Z8001:
  1976. machine = bfd_mach_z8001;
  1977. break;
  1978. case F_Z8002:
  1979. machine = bfd_mach_z8002;
  1980. break;
  1981. default:
  1982. return FALSE;
  1983. }
  1984. break;
  1985. #endif
  1986. #ifdef I860
  1987. case I860MAGIC:
  1988. arch = bfd_arch_i860;
  1989. break;
  1990. #endif
  1991. #ifdef I960
  1992. #ifdef I960ROMAGIC
  1993. case I960ROMAGIC:
  1994. case I960RWMAGIC:
  1995. arch = bfd_arch_i960;
  1996. switch (F_I960TYPE & internal_f->f_flags)
  1997. {
  1998. default:
  1999. case F_I960CORE:
  2000. machine = bfd_mach_i960_core;
  2001. break;
  2002. case F_I960KB:
  2003. machine = bfd_mach_i960_kb_sb;
  2004. break;
  2005. case F_I960MC:
  2006. machine = bfd_mach_i960_mc;
  2007. break;
  2008. case F_I960XA:
  2009. machine = bfd_mach_i960_xa;
  2010. break;
  2011. case F_I960CA:
  2012. machine = bfd_mach_i960_ca;
  2013. break;
  2014. case F_I960KA:
  2015. machine = bfd_mach_i960_ka_sa;
  2016. break;
  2017. case F_I960JX:
  2018. machine = bfd_mach_i960_jx;
  2019. break;
  2020. case F_I960HX:
  2021. machine = bfd_mach_i960_hx;
  2022. break;
  2023. }
  2024. break;
  2025. #endif
  2026. #endif
  2027. #ifdef RS6000COFF_C
  2028. #ifdef XCOFF64
  2029. case U64_TOCMAGIC:
  2030. case U803XTOCMAGIC:
  2031. #else
  2032. case U802ROMAGIC:
  2033. case U802WRMAGIC:
  2034. case U802TOCMAGIC:
  2035. #endif
  2036. {
  2037. int cputype;
  2038. if (xcoff_data (abfd)->cputype != -1)
  2039. cputype = xcoff_data (abfd)->cputype & 0xff;
  2040. else
  2041. {
  2042. /* We did not get a value from the a.out header. If the
  2043. file has not been stripped, we may be able to get the
  2044. architecture information from the first symbol, if it
  2045. is a .file symbol. */
  2046. if (obj_raw_syment_count (abfd) == 0)
  2047. cputype = 0;
  2048. else
  2049. {
  2050. bfd_byte *buf;
  2051. struct internal_syment sym;
  2052. bfd_size_type amt = bfd_coff_symesz (abfd);
  2053. buf = bfd_malloc (amt);
  2054. if (buf == NULL)
  2055. return FALSE;
  2056. if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
  2057. || bfd_bread (buf, amt, abfd) != amt)
  2058. {
  2059. free (buf);
  2060. return FALSE;
  2061. }
  2062. bfd_coff_swap_sym_in (abfd, buf, & sym);
  2063. if (sym.n_sclass == C_FILE)
  2064. cputype = sym.n_type & 0xff;
  2065. else
  2066. cputype = 0;
  2067. free (buf);
  2068. }
  2069. }
  2070. /* FIXME: We don't handle all cases here. */
  2071. switch (cputype)
  2072. {
  2073. default:
  2074. case 0:
  2075. arch = bfd_xcoff_architecture (abfd);
  2076. machine = bfd_xcoff_machine (abfd);
  2077. break;
  2078. case 1:
  2079. arch = bfd_arch_powerpc;
  2080. machine = bfd_mach_ppc_601;
  2081. break;
  2082. case 2: /* 64 bit PowerPC */
  2083. arch = bfd_arch_powerpc;
  2084. machine = bfd_mach_ppc_620;
  2085. break;
  2086. case 3:
  2087. arch = bfd_arch_powerpc;
  2088. machine = bfd_mach_ppc;
  2089. break;
  2090. case 4:
  2091. arch = bfd_arch_rs6000;
  2092. machine = bfd_mach_rs6k;
  2093. break;
  2094. }
  2095. }
  2096. break;
  2097. #endif
  2098. #ifdef WE32KMAGIC
  2099. case WE32KMAGIC:
  2100. arch = bfd_arch_we32k;
  2101. break;
  2102. #endif
  2103. #ifdef H8300MAGIC
  2104. case H8300MAGIC:
  2105. arch = bfd_arch_h8300;
  2106. machine = bfd_mach_h8300;
  2107. /* !! FIXME this probably isn't the right place for this. */
  2108. abfd->flags |= BFD_IS_RELAXABLE;
  2109. break;
  2110. #endif
  2111. #ifdef H8300HMAGIC
  2112. case H8300HMAGIC:
  2113. arch = bfd_arch_h8300;
  2114. machine = bfd_mach_h8300h;
  2115. /* !! FIXME this probably isn't the right place for this. */
  2116. abfd->flags |= BFD_IS_RELAXABLE;
  2117. break;
  2118. #endif
  2119. #ifdef H8300SMAGIC
  2120. case H8300SMAGIC:
  2121. arch = bfd_arch_h8300;
  2122. machine = bfd_mach_h8300s;
  2123. /* !! FIXME this probably isn't the right place for this. */
  2124. abfd->flags |= BFD_IS_RELAXABLE;
  2125. break;
  2126. #endif
  2127. #ifdef H8300HNMAGIC
  2128. case H8300HNMAGIC:
  2129. arch = bfd_arch_h8300;
  2130. machine = bfd_mach_h8300hn;
  2131. /* !! FIXME this probably isn't the right place for this. */
  2132. abfd->flags |= BFD_IS_RELAXABLE;
  2133. break;
  2134. #endif
  2135. #ifdef H8300SNMAGIC
  2136. case H8300SNMAGIC:
  2137. arch = bfd_arch_h8300;
  2138. machine = bfd_mach_h8300sn;
  2139. /* !! FIXME this probably isn't the right place for this. */
  2140. abfd->flags |= BFD_IS_RELAXABLE;
  2141. break;
  2142. #endif
  2143. #ifdef SH_ARCH_MAGIC_BIG
  2144. case SH_ARCH_MAGIC_BIG:
  2145. case SH_ARCH_MAGIC_LITTLE:
  2146. #ifdef COFF_WITH_PE
  2147. case SH_ARCH_MAGIC_WINCE:
  2148. #endif
  2149. arch = bfd_arch_sh;
  2150. break;
  2151. #endif
  2152. #ifdef MIPS_ARCH_MAGIC_WINCE
  2153. case MIPS_ARCH_MAGIC_WINCE:
  2154. arch = bfd_arch_mips;
  2155. break;
  2156. #endif
  2157. #ifdef H8500MAGIC
  2158. case H8500MAGIC:
  2159. arch = bfd_arch_h8500;
  2160. break;
  2161. #endif
  2162. #ifdef SPARCMAGIC
  2163. case SPARCMAGIC:
  2164. #ifdef LYNXCOFFMAGIC
  2165. case LYNXCOFFMAGIC:
  2166. #endif
  2167. arch = bfd_arch_sparc;
  2168. break;
  2169. #endif
  2170. #ifdef TIC30MAGIC
  2171. case TIC30MAGIC:
  2172. arch = bfd_arch_tic30;
  2173. break;
  2174. #endif
  2175. #ifdef TICOFF0MAGIC
  2176. #ifdef TICOFF_TARGET_ARCH
  2177. /* This TI COFF section should be used by all new TI COFF v0 targets. */
  2178. case TICOFF0MAGIC:
  2179. arch = TICOFF_TARGET_ARCH;
  2180. machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
  2181. break;
  2182. #endif
  2183. #endif
  2184. #ifdef TICOFF1MAGIC
  2185. /* This TI COFF section should be used by all new TI COFF v1/2 targets. */
  2186. /* TI COFF1 and COFF2 use the target_id field to specify which arch. */
  2187. case TICOFF1MAGIC:
  2188. case TICOFF2MAGIC:
  2189. switch (internal_f->f_target_id)
  2190. {
  2191. #ifdef TI_TARGET_ID
  2192. case TI_TARGET_ID:
  2193. arch = TICOFF_TARGET_ARCH;
  2194. machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
  2195. break;
  2196. #endif
  2197. default:
  2198. arch = bfd_arch_obscure;
  2199. (*_bfd_error_handler)
  2200. (_("Unrecognized TI COFF target id '0x%x'"),
  2201. internal_f->f_target_id);
  2202. break;
  2203. }
  2204. break;
  2205. #endif
  2206. #ifdef TIC80_ARCH_MAGIC
  2207. case TIC80_ARCH_MAGIC:
  2208. arch = bfd_arch_tic80;
  2209. break;
  2210. #endif
  2211. #ifdef MCOREMAGIC
  2212. case MCOREMAGIC:
  2213. arch = bfd_arch_mcore;
  2214. break;
  2215. #endif
  2216. #ifdef W65MAGIC
  2217. case W65MAGIC:
  2218. arch = bfd_arch_w65;
  2219. break;
  2220. #endif
  2221. default: /* Unreadable input file type. */
  2222. arch = bfd_arch_obscure;
  2223. break;
  2224. }
  2225. bfd_default_set_arch_mach (abfd, arch, machine);
  2226. return TRUE;
  2227. }
  2228. #ifdef SYMNAME_IN_DEBUG
  2229. static bfd_boolean
  2230. symname_in_debug_hook (bfd * abfd ATTRIBUTE_UNUSED, struct internal_syment *sym)
  2231. {
  2232. return SYMNAME_IN_DEBUG (sym) != 0;
  2233. }
  2234. #else
  2235. #define symname_in_debug_hook \
  2236. (bfd_boolean (*) (bfd *, struct internal_syment *)) bfd_false
  2237. #endif
  2238. #ifdef RS6000COFF_C
  2239. #ifdef XCOFF64
  2240. #define FORCE_SYMNAMES_IN_STRINGS
  2241. #endif
  2242. /* Handle the csect auxent of a C_EXT, C_AIX_WEAKEXT or C_HIDEXT symbol. */
  2243. static bfd_boolean
  2244. coff_pointerize_aux_hook (bfd *abfd ATTRIBUTE_UNUSED,
  2245. combined_entry_type *table_base,
  2246. combined_entry_type *symbol,
  2247. unsigned int indaux,
  2248. combined_entry_type *aux)
  2249. {
  2250. BFD_ASSERT (symbol->is_sym);
  2251. int n_sclass = symbol->u.syment.n_sclass;
  2252. if (CSECT_SYM_P (n_sclass)
  2253. && indaux + 1 == symbol->u.syment.n_numaux)
  2254. {
  2255. BFD_ASSERT (! aux->is_sym);
  2256. if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) == XTY_LD)
  2257. {
  2258. aux->u.auxent.x_csect.x_scnlen.p =
  2259. table_base + aux->u.auxent.x_csect.x_scnlen.l;
  2260. aux->fix_scnlen = 1;
  2261. }
  2262. /* Return TRUE to indicate that the caller should not do any
  2263. further work on this auxent. */
  2264. return TRUE;
  2265. }
  2266. /* Return FALSE to indicate that this auxent should be handled by
  2267. the caller. */
  2268. return FALSE;
  2269. }
  2270. #else
  2271. #ifdef I960
  2272. /* We don't want to pointerize bal entries. */
  2273. static bfd_boolean
  2274. coff_pointerize_aux_hook (bfd *abfd ATTRIBUTE_UNUSED,
  2275. combined_entry_type *table_base ATTRIBUTE_UNUSED,
  2276. combined_entry_type *symbol,
  2277. unsigned int indaux,
  2278. combined_entry_type *aux ATTRIBUTE_UNUSED)
  2279. {
  2280. /* Return TRUE if we don't want to pointerize this aux entry, which
  2281. is the case for the lastfirst aux entry for a C_LEAFPROC symbol. */
  2282. return (indaux == 1
  2283. && symbol->is_sym
  2284. && (symbol->u.syment.n_sclass == C_LEAFPROC
  2285. || symbol->u.syment.n_sclass == C_LEAFSTAT
  2286. || symbol->u.syment.n_sclass == C_LEAFEXT));
  2287. }
  2288. #else /* ! I960 */
  2289. #define coff_pointerize_aux_hook 0
  2290. #endif /* ! I960 */
  2291. #endif /* ! RS6000COFF_C */
  2292. /* Print an aux entry. This returns TRUE if it has printed it. */
  2293. static bfd_boolean
  2294. coff_print_aux (bfd *abfd ATTRIBUTE_UNUSED,
  2295. FILE *file ATTRIBUTE_UNUSED,
  2296. combined_entry_type *table_base ATTRIBUTE_UNUSED,
  2297. combined_entry_type *symbol ATTRIBUTE_UNUSED,
  2298. combined_entry_type *aux ATTRIBUTE_UNUSED,
  2299. unsigned int indaux ATTRIBUTE_UNUSED)
  2300. {
  2301. BFD_ASSERT (symbol->is_sym);
  2302. BFD_ASSERT (! aux->is_sym);
  2303. #ifdef RS6000COFF_C
  2304. if (CSECT_SYM_P (symbol->u.syment.n_sclass)
  2305. && indaux + 1 == symbol->u.syment.n_numaux)
  2306. {
  2307. /* This is a csect entry. */
  2308. fprintf (file, "AUX ");
  2309. if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD)
  2310. {
  2311. BFD_ASSERT (! aux->fix_scnlen);
  2312. #ifdef XCOFF64
  2313. fprintf (file, "val %5lld",
  2314. (long long) aux->u.auxent.x_csect.x_scnlen.l);
  2315. #else
  2316. fprintf (file, "val %5ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
  2317. #endif
  2318. }
  2319. else
  2320. {
  2321. fprintf (file, "indx ");
  2322. if (! aux->fix_scnlen)
  2323. #ifdef XCOFF64
  2324. fprintf (file, "%4lld",
  2325. (long long) aux->u.auxent.x_csect.x_scnlen.l);
  2326. #else
  2327. fprintf (file, "%4ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
  2328. #endif
  2329. else
  2330. fprintf (file, "%4ld",
  2331. (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base));
  2332. }
  2333. fprintf (file,
  2334. " prmhsh %ld snhsh %u typ %d algn %d clss %u stb %ld snstb %u",
  2335. aux->u.auxent.x_csect.x_parmhash,
  2336. (unsigned int) aux->u.auxent.x_csect.x_snhash,
  2337. SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp),
  2338. SMTYP_ALIGN (aux->u.auxent.x_csect.x_smtyp),
  2339. (unsigned int) aux->u.auxent.x_csect.x_smclas,
  2340. aux->u.auxent.x_csect.x_stab,
  2341. (unsigned int) aux->u.auxent.x_csect.x_snstab);
  2342. return TRUE;
  2343. }
  2344. #endif
  2345. /* Return FALSE to indicate that no special action was taken. */
  2346. return FALSE;
  2347. }
  2348. /*
  2349. SUBSUBSECTION
  2350. Writing relocations
  2351. To write relocations, the back end steps though the
  2352. canonical relocation table and create an
  2353. @code{internal_reloc}. The symbol index to use is removed from
  2354. the @code{offset} field in the symbol table supplied. The
  2355. address comes directly from the sum of the section base
  2356. address and the relocation offset; the type is dug directly
  2357. from the howto field. Then the @code{internal_reloc} is
  2358. swapped into the shape of an @code{external_reloc} and written
  2359. out to disk.
  2360. */
  2361. #ifdef TARG_AUX
  2362. /* AUX's ld wants relocations to be sorted. */
  2363. static int
  2364. compare_arelent_ptr (const void * x, const void * y)
  2365. {
  2366. const arelent **a = (const arelent **) x;
  2367. const arelent **b = (const arelent **) y;
  2368. bfd_size_type aadr = (*a)->address;
  2369. bfd_size_type badr = (*b)->address;
  2370. return (aadr < badr ? -1 : badr < aadr ? 1 : 0);
  2371. }
  2372. #endif /* TARG_AUX */
  2373. static bfd_boolean
  2374. coff_write_relocs (bfd * abfd, int first_undef)
  2375. {
  2376. asection *s;
  2377. for (s = abfd->sections; s != NULL; s = s->next)
  2378. {
  2379. unsigned int i;
  2380. struct external_reloc dst;
  2381. arelent **p;
  2382. #ifndef TARG_AUX
  2383. p = s->orelocation;
  2384. #else
  2385. {
  2386. /* Sort relocations before we write them out. */
  2387. bfd_size_type amt;
  2388. amt = s->reloc_count;
  2389. amt *= sizeof (arelent *);
  2390. p = bfd_malloc (amt);
  2391. if (p == NULL)
  2392. {
  2393. if (s->reloc_count > 0)
  2394. return FALSE;
  2395. }
  2396. else
  2397. {
  2398. memcpy (p, s->orelocation, (size_t) amt);
  2399. qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
  2400. }
  2401. }
  2402. #endif
  2403. if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
  2404. return FALSE;
  2405. #ifdef COFF_WITH_PE
  2406. if (obj_pe (abfd) && s->reloc_count >= 0xffff)
  2407. {
  2408. /* Encode real count here as first reloc. */
  2409. struct internal_reloc n;
  2410. memset (& n, 0, sizeof (n));
  2411. /* Add one to count *this* reloc (grr). */
  2412. n.r_vaddr = s->reloc_count + 1;
  2413. coff_swap_reloc_out (abfd, &n, &dst);
  2414. if (bfd_bwrite (& dst, (bfd_size_type) bfd_coff_relsz (abfd),
  2415. abfd) != bfd_coff_relsz (abfd))
  2416. return FALSE;
  2417. }
  2418. #endif
  2419. for (i = 0; i < s->reloc_count; i++)
  2420. {
  2421. struct internal_reloc n;
  2422. arelent *q = p[i];
  2423. memset (& n, 0, sizeof (n));
  2424. /* Now we've renumbered the symbols we know where the
  2425. undefined symbols live in the table. Check the reloc
  2426. entries for symbols who's output bfd isn't the right one.
  2427. This is because the symbol was undefined (which means
  2428. that all the pointers are never made to point to the same
  2429. place). This is a bad thing,'cause the symbols attached
  2430. to the output bfd are indexed, so that the relocation
  2431. entries know which symbol index they point to. So we
  2432. have to look up the output symbol here. */
  2433. if (q->sym_ptr_ptr[0] != NULL && q->sym_ptr_ptr[0]->the_bfd != abfd)
  2434. {
  2435. int j;
  2436. const char *sname = q->sym_ptr_ptr[0]->name;
  2437. asymbol **outsyms = abfd->outsymbols;
  2438. for (j = first_undef; outsyms[j]; j++)
  2439. {
  2440. const char *intable = outsyms[j]->name;
  2441. if (strcmp (intable, sname) == 0)
  2442. {
  2443. /* Got a hit, so repoint the reloc. */
  2444. q->sym_ptr_ptr = outsyms + j;
  2445. break;
  2446. }
  2447. }
  2448. }
  2449. n.r_vaddr = q->address + s->vma;
  2450. #ifdef R_IHCONST
  2451. /* The 29k const/consth reloc pair is a real kludge. The consth
  2452. part doesn't have a symbol; it has an offset. So rebuilt
  2453. that here. */
  2454. if (q->howto->type == R_IHCONST)
  2455. n.r_symndx = q->addend;
  2456. else
  2457. #endif
  2458. if (q->sym_ptr_ptr && q->sym_ptr_ptr[0] != NULL)
  2459. {
  2460. #ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
  2461. if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
  2462. #else
  2463. if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
  2464. && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
  2465. #endif
  2466. /* This is a relocation relative to the absolute symbol. */
  2467. n.r_symndx = -1;
  2468. else
  2469. {
  2470. n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
  2471. /* Check to see if the symbol reloc points to a symbol
  2472. we don't have in our symbol table. */
  2473. if (n.r_symndx > obj_conv_table_size (abfd))
  2474. {
  2475. bfd_set_error (bfd_error_bad_value);
  2476. _bfd_error_handler (_("%B: reloc against a non-existant symbol index: %ld"),
  2477. abfd, n.r_symndx);
  2478. return FALSE;
  2479. }
  2480. }
  2481. }
  2482. #ifdef SWAP_OUT_RELOC_OFFSET
  2483. n.r_offset = q->addend;
  2484. #endif
  2485. #ifdef SELECT_RELOC
  2486. /* Work out reloc type from what is required. */
  2487. SELECT_RELOC (n, q->howto);
  2488. #else
  2489. n.r_type = q->howto->type;
  2490. #endif
  2491. coff_swap_reloc_out (abfd, &n, &dst);
  2492. if (bfd_bwrite (& dst, (bfd_size_type) bfd_coff_relsz (abfd),
  2493. abfd) != bfd_coff_relsz (abfd))
  2494. return FALSE;
  2495. }
  2496. #ifdef TARG_AUX
  2497. if (p != NULL)
  2498. free (p);
  2499. #endif
  2500. }
  2501. return TRUE;
  2502. }
  2503. /* Set flags and magic number of a coff file from architecture and machine
  2504. type. Result is TRUE if we can represent the arch&type, FALSE if not. */
  2505. static bfd_boolean
  2506. coff_set_flags (bfd * abfd,
  2507. unsigned int *magicp ATTRIBUTE_UNUSED,
  2508. unsigned short *flagsp ATTRIBUTE_UNUSED)
  2509. {
  2510. switch (bfd_get_arch (abfd))
  2511. {
  2512. #ifdef Z80MAGIC
  2513. case bfd_arch_z80:
  2514. *magicp = Z80MAGIC;
  2515. switch (bfd_get_mach (abfd))
  2516. {
  2517. case 0:
  2518. case bfd_mach_z80strict:
  2519. case bfd_mach_z80:
  2520. case bfd_mach_z80full:
  2521. case bfd_mach_r800:
  2522. *flagsp = bfd_get_mach (abfd) << 12;
  2523. break;
  2524. default:
  2525. return FALSE;
  2526. }
  2527. return TRUE;
  2528. #endif
  2529. #ifdef Z8KMAGIC
  2530. case bfd_arch_z8k:
  2531. *magicp = Z8KMAGIC;
  2532. switch (bfd_get_mach (abfd))
  2533. {
  2534. case bfd_mach_z8001: *flagsp = F_Z8001; break;
  2535. case bfd_mach_z8002: *flagsp = F_Z8002; break;
  2536. default: return FALSE;
  2537. }
  2538. return TRUE;
  2539. #endif
  2540. #ifdef I960ROMAGIC
  2541. case bfd_arch_i960:
  2542. {
  2543. unsigned flags;
  2544. *magicp = I960ROMAGIC;
  2545. switch (bfd_get_mach (abfd))
  2546. {
  2547. case bfd_mach_i960_core: flags = F_I960CORE; break;
  2548. case bfd_mach_i960_kb_sb: flags = F_I960KB; break;
  2549. case bfd_mach_i960_mc: flags = F_I960MC; break;
  2550. case bfd_mach_i960_xa: flags = F_I960XA; break;
  2551. case bfd_mach_i960_ca: flags = F_I960CA; break;
  2552. case bfd_mach_i960_ka_sa: flags = F_I960KA; break;
  2553. case bfd_mach_i960_jx: flags = F_I960JX; break;
  2554. case bfd_mach_i960_hx: flags = F_I960HX; break;
  2555. default: return FALSE;
  2556. }
  2557. *flagsp = flags;
  2558. return TRUE;
  2559. }
  2560. break;
  2561. #endif
  2562. #ifdef TIC30MAGIC
  2563. case bfd_arch_tic30:
  2564. *magicp = TIC30MAGIC;
  2565. return TRUE;
  2566. #endif
  2567. #ifdef TICOFF_DEFAULT_MAGIC
  2568. case TICOFF_TARGET_ARCH:
  2569. /* If there's no indication of which version we want, use the default. */
  2570. if (!abfd->xvec )
  2571. *magicp = TICOFF_DEFAULT_MAGIC;
  2572. else
  2573. {
  2574. /* We may want to output in a different COFF version. */
  2575. switch (abfd->xvec->name[4])
  2576. {
  2577. case '0':
  2578. *magicp = TICOFF0MAGIC;
  2579. break;
  2580. case '1':
  2581. *magicp = TICOFF1MAGIC;
  2582. break;
  2583. case '2':
  2584. *magicp = TICOFF2MAGIC;
  2585. break;
  2586. default:
  2587. return FALSE;
  2588. }
  2589. }
  2590. TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
  2591. return TRUE;
  2592. #endif
  2593. #ifdef TIC80_ARCH_MAGIC
  2594. case bfd_arch_tic80:
  2595. *magicp = TIC80_ARCH_MAGIC;
  2596. return TRUE;
  2597. #endif
  2598. #ifdef ARMMAGIC
  2599. case bfd_arch_arm:
  2600. #ifdef ARM_WINCE
  2601. * magicp = ARMPEMAGIC;
  2602. #else
  2603. * magicp = ARMMAGIC;
  2604. #endif
  2605. * flagsp = 0;
  2606. if (APCS_SET (abfd))
  2607. {
  2608. if (APCS_26_FLAG (abfd))
  2609. * flagsp |= F_APCS26;
  2610. if (APCS_FLOAT_FLAG (abfd))
  2611. * flagsp |= F_APCS_FLOAT;
  2612. if (PIC_FLAG (abfd))
  2613. * flagsp |= F_PIC;
  2614. }
  2615. if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
  2616. * flagsp |= F_INTERWORK;
  2617. switch (bfd_get_mach (abfd))
  2618. {
  2619. case bfd_mach_arm_2: * flagsp |= F_ARM_2; break;
  2620. case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
  2621. case bfd_mach_arm_3: * flagsp |= F_ARM_3; break;
  2622. case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
  2623. case bfd_mach_arm_4: * flagsp |= F_ARM_4; break;
  2624. case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
  2625. case bfd_mach_arm_5: * flagsp |= F_ARM_5; break;
  2626. /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
  2627. See also the comment in coff_set_arch_mach_hook(). */
  2628. case bfd_mach_arm_5T: * flagsp |= F_ARM_5; break;
  2629. case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
  2630. case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
  2631. }
  2632. return TRUE;
  2633. #endif
  2634. #ifdef PPCMAGIC
  2635. case bfd_arch_powerpc:
  2636. *magicp = PPCMAGIC;
  2637. return TRUE;
  2638. #endif
  2639. #if defined(I386MAGIC) || defined(AMD64MAGIC)
  2640. case bfd_arch_i386:
  2641. #if defined(I386MAGIC)
  2642. *magicp = I386MAGIC;
  2643. #endif
  2644. #if defined LYNXOS
  2645. /* Just overwrite the usual value if we're doing Lynx. */
  2646. *magicp = LYNXCOFFMAGIC;
  2647. #endif
  2648. #if defined AMD64MAGIC
  2649. *magicp = AMD64MAGIC;
  2650. #endif
  2651. return TRUE;
  2652. #endif
  2653. #ifdef I860MAGIC
  2654. case bfd_arch_i860:
  2655. *magicp = I860MAGIC;
  2656. return TRUE;
  2657. #endif
  2658. #ifdef IA64MAGIC
  2659. case bfd_arch_ia64:
  2660. *magicp = IA64MAGIC;
  2661. return TRUE;
  2662. #endif
  2663. #ifdef MC68MAGIC
  2664. case bfd_arch_m68k:
  2665. #ifdef APOLLOM68KMAGIC
  2666. *magicp = APOLLO_COFF_VERSION_NUMBER;
  2667. #else
  2668. /* NAMES_HAVE_UNDERSCORE may be defined by coff-u68k.c. */
  2669. #ifdef NAMES_HAVE_UNDERSCORE
  2670. *magicp = MC68KBCSMAGIC;
  2671. #else
  2672. *magicp = MC68MAGIC;
  2673. #endif
  2674. #endif
  2675. #ifdef LYNXOS
  2676. /* Just overwrite the usual value if we're doing Lynx. */
  2677. *magicp = LYNXCOFFMAGIC;
  2678. #endif
  2679. return TRUE;
  2680. #endif
  2681. #ifdef MC88MAGIC
  2682. case bfd_arch_m88k:
  2683. *magicp = MC88OMAGIC;
  2684. return TRUE;
  2685. #endif
  2686. #ifdef H8300MAGIC
  2687. case bfd_arch_h8300:
  2688. switch (bfd_get_mach (abfd))
  2689. {
  2690. case bfd_mach_h8300: *magicp = H8300MAGIC; return TRUE;
  2691. case bfd_mach_h8300h: *magicp = H8300HMAGIC; return TRUE;
  2692. case bfd_mach_h8300s: *magicp = H8300SMAGIC; return TRUE;
  2693. case bfd_mach_h8300hn: *magicp = H8300HNMAGIC; return TRUE;
  2694. case bfd_mach_h8300sn: *magicp = H8300SNMAGIC; return TRUE;
  2695. default: break;
  2696. }
  2697. break;
  2698. #endif
  2699. #ifdef SH_ARCH_MAGIC_BIG
  2700. case bfd_arch_sh:
  2701. #ifdef COFF_IMAGE_WITH_PE
  2702. *magicp = SH_ARCH_MAGIC_WINCE;
  2703. #else
  2704. if (bfd_big_endian (abfd))
  2705. *magicp = SH_ARCH_MAGIC_BIG;
  2706. else
  2707. *magicp = SH_ARCH_MAGIC_LITTLE;
  2708. #endif
  2709. return TRUE;
  2710. #endif
  2711. #ifdef MIPS_ARCH_MAGIC_WINCE
  2712. case bfd_arch_mips:
  2713. *magicp = MIPS_ARCH_MAGIC_WINCE;
  2714. return TRUE;
  2715. #endif
  2716. #ifdef SPARCMAGIC
  2717. case bfd_arch_sparc:
  2718. *magicp = SPARCMAGIC;
  2719. #ifdef LYNXOS
  2720. /* Just overwrite the usual value if we're doing Lynx. */
  2721. *magicp = LYNXCOFFMAGIC;
  2722. #endif
  2723. return TRUE;
  2724. #endif
  2725. #ifdef H8500MAGIC
  2726. case bfd_arch_h8500:
  2727. *magicp = H8500MAGIC;
  2728. return TRUE;
  2729. break;
  2730. #endif
  2731. #ifdef WE32KMAGIC
  2732. case bfd_arch_we32k:
  2733. *magicp = WE32KMAGIC;
  2734. return TRUE;
  2735. #endif
  2736. #ifdef RS6000COFF_C
  2737. case bfd_arch_rs6000:
  2738. #ifndef PPCMAGIC
  2739. case bfd_arch_powerpc:
  2740. #endif
  2741. BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
  2742. *magicp = bfd_xcoff_magic_number (abfd);
  2743. return TRUE;
  2744. #endif
  2745. #ifdef MCOREMAGIC
  2746. case bfd_arch_mcore:
  2747. * magicp = MCOREMAGIC;
  2748. return TRUE;
  2749. #endif
  2750. #ifdef W65MAGIC
  2751. case bfd_arch_w65:
  2752. *magicp = W65MAGIC;
  2753. return TRUE;
  2754. #endif
  2755. default: /* Unknown architecture. */
  2756. /* Fall through to "return FALSE" below, to avoid
  2757. "statement never reached" errors on the one below. */
  2758. break;
  2759. }
  2760. return FALSE;
  2761. }
  2762. static bfd_boolean
  2763. coff_set_arch_mach (bfd * abfd,
  2764. enum bfd_architecture arch,
  2765. unsigned long machine)
  2766. {
  2767. unsigned dummy1;
  2768. unsigned short dummy2;
  2769. if (! bfd_default_set_arch_mach (abfd, arch, machine))
  2770. return FALSE;
  2771. if (arch != bfd_arch_unknown
  2772. && ! coff_set_flags (abfd, &dummy1, &dummy2))
  2773. return FALSE; /* We can't represent this type. */
  2774. return TRUE; /* We're easy... */
  2775. }
  2776. #ifdef COFF_IMAGE_WITH_PE
  2777. /* This is used to sort sections by VMA, as required by PE image
  2778. files. */
  2779. static int
  2780. sort_by_secaddr (const void * arg1, const void * arg2)
  2781. {
  2782. const asection *a = *(const asection **) arg1;
  2783. const asection *b = *(const asection **) arg2;
  2784. if (a->vma < b->vma)
  2785. return -1;
  2786. else if (a->vma > b->vma)
  2787. return 1;
  2788. return 0;
  2789. }
  2790. #endif /* COFF_IMAGE_WITH_PE */
  2791. /* Calculate the file position for each section. */
  2792. #ifndef I960
  2793. #define ALIGN_SECTIONS_IN_FILE
  2794. #endif
  2795. #if defined(TIC80COFF) || defined(TICOFF)
  2796. #undef ALIGN_SECTIONS_IN_FILE
  2797. #endif
  2798. static bfd_boolean
  2799. coff_compute_section_file_positions (bfd * abfd)
  2800. {
  2801. asection *current;
  2802. file_ptr sofar = bfd_coff_filhsz (abfd);
  2803. bfd_boolean align_adjust;
  2804. unsigned int target_index;
  2805. #ifdef ALIGN_SECTIONS_IN_FILE
  2806. asection *previous = NULL;
  2807. file_ptr old_sofar;
  2808. #endif
  2809. #ifdef COFF_IMAGE_WITH_PE
  2810. int page_size;
  2811. if (coff_data (abfd)->link_info
  2812. || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment))
  2813. {
  2814. page_size = pe_data (abfd)->pe_opthdr.FileAlignment;
  2815. /* If no file alignment has been set, default to one.
  2816. This repairs 'ld -r' for arm-wince-pe target. */
  2817. if (page_size == 0)
  2818. page_size = 1;
  2819. /* PR 17512: file: 0ac816d3. */
  2820. if (page_size < 0)
  2821. {
  2822. bfd_set_error (bfd_error_file_too_big);
  2823. (*_bfd_error_handler)
  2824. (_("%B: page size is too large (0x%x)"), abfd, page_size);
  2825. return FALSE;
  2826. }
  2827. }
  2828. else
  2829. page_size = PE_DEF_FILE_ALIGNMENT;
  2830. #else
  2831. #ifdef COFF_PAGE_SIZE
  2832. int page_size = COFF_PAGE_SIZE;
  2833. #endif
  2834. #endif
  2835. #ifdef RS6000COFF_C
  2836. /* On XCOFF, if we have symbols, set up the .debug section. */
  2837. if (bfd_get_symcount (abfd) > 0)
  2838. {
  2839. bfd_size_type sz;
  2840. bfd_size_type i, symcount;
  2841. asymbol **symp;
  2842. sz = 0;
  2843. symcount = bfd_get_symcount (abfd);
  2844. for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
  2845. {
  2846. coff_symbol_type *cf;
  2847. cf = coff_symbol_from (*symp);
  2848. if (cf != NULL
  2849. && cf->native != NULL
  2850. && cf->native->is_sym
  2851. && SYMNAME_IN_DEBUG (&cf->native->u.syment))
  2852. {
  2853. size_t len;
  2854. len = strlen (bfd_asymbol_name (*symp));
  2855. if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
  2856. sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
  2857. }
  2858. }
  2859. if (sz > 0)
  2860. {
  2861. asection *dsec;
  2862. dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
  2863. if (dsec == NULL)
  2864. abort ();
  2865. dsec->size = sz;
  2866. dsec->flags |= SEC_HAS_CONTENTS;
  2867. }
  2868. }
  2869. #endif
  2870. if (bfd_get_start_address (abfd))
  2871. /* A start address may have been added to the original file. In this
  2872. case it will need an optional header to record it. */
  2873. abfd->flags |= EXEC_P;
  2874. if (abfd->flags & EXEC_P)
  2875. sofar += bfd_coff_aoutsz (abfd);
  2876. #ifdef RS6000COFF_C
  2877. else if (xcoff_data (abfd)->full_aouthdr)
  2878. sofar += bfd_coff_aoutsz (abfd);
  2879. else
  2880. sofar += SMALL_AOUTSZ;
  2881. #endif
  2882. sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
  2883. #ifdef RS6000COFF_C
  2884. /* XCOFF handles overflows in the reloc and line number count fields
  2885. by allocating a new section header to hold the correct counts. */
  2886. for (current = abfd->sections; current != NULL; current = current->next)
  2887. if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
  2888. sofar += bfd_coff_scnhsz (abfd);
  2889. #endif
  2890. #ifdef COFF_IMAGE_WITH_PE
  2891. {
  2892. /* PE requires the sections to be in memory order when listed in
  2893. the section headers. It also does not like empty loadable
  2894. sections. The sections apparently do not have to be in the
  2895. right order in the image file itself, but we do need to get the
  2896. target_index values right. */
  2897. unsigned int count;
  2898. asection **section_list;
  2899. unsigned int i;
  2900. bfd_size_type amt;
  2901. #ifdef COFF_PAGE_SIZE
  2902. /* Clear D_PAGED if section alignment is smaller than
  2903. COFF_PAGE_SIZE. */
  2904. if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE)
  2905. abfd->flags &= ~D_PAGED;
  2906. #endif
  2907. count = 0;
  2908. for (current = abfd->sections; current != NULL; current = current->next)
  2909. ++count;
  2910. /* We allocate an extra cell to simplify the final loop. */
  2911. amt = sizeof (struct asection *) * (count + 1);
  2912. section_list = (asection **) bfd_malloc (amt);
  2913. if (section_list == NULL)
  2914. return FALSE;
  2915. i = 0;
  2916. for (current = abfd->sections; current != NULL; current = current->next)
  2917. {
  2918. section_list[i] = current;
  2919. ++i;
  2920. }
  2921. section_list[i] = NULL;
  2922. qsort (section_list, count, sizeof (asection *), sort_by_secaddr);
  2923. /* Rethread the linked list into sorted order; at the same time,
  2924. assign target_index values. */
  2925. target_index = 1;
  2926. abfd->sections = NULL;
  2927. abfd->section_last = NULL;
  2928. for (i = 0; i < count; i++)
  2929. {
  2930. current = section_list[i];
  2931. bfd_section_list_append (abfd, current);
  2932. /* Later, if the section has zero size, we'll be throwing it
  2933. away, so we don't want to number it now. Note that having
  2934. a zero size and having real contents are different
  2935. concepts: .bss has no contents, but (usually) non-zero
  2936. size. */
  2937. if (current->size == 0)
  2938. {
  2939. /* Discard. However, it still might have (valid) symbols
  2940. in it, so arbitrarily set it to section 1 (indexing is
  2941. 1-based here; usually .text). __end__ and other
  2942. contents of .endsection really have this happen.
  2943. FIXME: This seems somewhat dubious. */
  2944. current->target_index = 1;
  2945. }
  2946. else
  2947. current->target_index = target_index++;
  2948. }
  2949. free (section_list);
  2950. }
  2951. #else /* ! COFF_IMAGE_WITH_PE */
  2952. {
  2953. /* Set the target_index field. */
  2954. target_index = 1;
  2955. for (current = abfd->sections; current != NULL; current = current->next)
  2956. current->target_index = target_index++;
  2957. }
  2958. #endif /* ! COFF_IMAGE_WITH_PE */
  2959. if (target_index >= bfd_coff_max_nscns (abfd))
  2960. {
  2961. bfd_set_error (bfd_error_file_too_big);
  2962. (*_bfd_error_handler)
  2963. (_("%B: too many sections (%d)"), abfd, target_index);
  2964. return FALSE;
  2965. }
  2966. align_adjust = FALSE;
  2967. for (current = abfd->sections;
  2968. current != NULL;
  2969. current = current->next)
  2970. {
  2971. #ifdef COFF_IMAGE_WITH_PE
  2972. /* With PE we have to pad each section to be a multiple of its
  2973. page size too, and remember both sizes. */
  2974. if (coff_section_data (abfd, current) == NULL)
  2975. {
  2976. bfd_size_type amt = sizeof (struct coff_section_tdata);
  2977. current->used_by_bfd = bfd_zalloc (abfd, amt);
  2978. if (current->used_by_bfd == NULL)
  2979. return FALSE;
  2980. }
  2981. if (pei_section_data (abfd, current) == NULL)
  2982. {
  2983. bfd_size_type amt = sizeof (struct pei_section_tdata);
  2984. coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
  2985. if (coff_section_data (abfd, current)->tdata == NULL)
  2986. return FALSE;
  2987. }
  2988. if (pei_section_data (abfd, current)->virt_size == 0)
  2989. pei_section_data (abfd, current)->virt_size = current->size;
  2990. #endif
  2991. /* Only deal with sections which have contents. */
  2992. if (!(current->flags & SEC_HAS_CONTENTS))
  2993. continue;
  2994. current->rawsize = current->size;
  2995. #ifdef COFF_IMAGE_WITH_PE
  2996. /* Make sure we skip empty sections in a PE image. */
  2997. if (current->size == 0)
  2998. continue;
  2999. #endif
  3000. /* Align the sections in the file to the same boundary on
  3001. which they are aligned in virtual memory. I960 doesn't
  3002. do this (FIXME) so we can stay in sync with Intel. 960
  3003. doesn't yet page from files... */
  3004. #ifdef ALIGN_SECTIONS_IN_FILE
  3005. if ((abfd->flags & EXEC_P) != 0)
  3006. {
  3007. /* Make sure this section is aligned on the right boundary - by
  3008. padding the previous section up if necessary. */
  3009. old_sofar = sofar;
  3010. sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
  3011. #ifdef RS6000COFF_C
  3012. /* Make sure the file offset and the vma of .text/.data are at the
  3013. same page offset, so that the file can be mmap'ed without being
  3014. relocated. Failing that, AIX is able to load and execute the
  3015. program, but it will be silently relocated (possible as
  3016. executables are PIE). But the relocation is slightly costly and
  3017. complexify the use of addr2line or gdb. So better to avoid it,
  3018. like does the native linker. Usually gnu ld makes sure that
  3019. the vma of .text is the file offset so this issue shouldn't
  3020. appear unless you are stripping such an executable.
  3021. AIX loader checks the text section alignment of (vma - filepos),
  3022. and the native linker doesn't try to align the text sections.
  3023. For example:
  3024. 0 .text 000054cc 10000128 10000128 00000128 2**5
  3025. CONTENTS, ALLOC, LOAD, CODE
  3026. */
  3027. if (!strcmp (current->name, _TEXT)
  3028. || !strcmp (current->name, _DATA))
  3029. {
  3030. bfd_vma align = 4096;
  3031. bfd_vma sofar_off = sofar % align;
  3032. bfd_vma vma_off = current->vma % align;
  3033. if (vma_off > sofar_off)
  3034. sofar += vma_off - sofar_off;
  3035. else if (vma_off < sofar_off)
  3036. sofar += align + vma_off - sofar_off;
  3037. }
  3038. #endif
  3039. if (previous != NULL)
  3040. previous->size += sofar - old_sofar;
  3041. }
  3042. #endif
  3043. /* In demand paged files the low order bits of the file offset
  3044. must match the low order bits of the virtual address. */
  3045. #ifdef COFF_PAGE_SIZE
  3046. if ((abfd->flags & D_PAGED) != 0
  3047. && (current->flags & SEC_ALLOC) != 0)
  3048. sofar += (current->vma - (bfd_vma) sofar) % page_size;
  3049. #endif
  3050. current->filepos = sofar;
  3051. #ifdef COFF_IMAGE_WITH_PE
  3052. /* Set the padded size. */
  3053. current->size = (current->size + page_size - 1) & -page_size;
  3054. #endif
  3055. sofar += current->size;
  3056. #ifdef ALIGN_SECTIONS_IN_FILE
  3057. /* Make sure that this section is of the right size too. */
  3058. if ((abfd->flags & EXEC_P) == 0)
  3059. {
  3060. bfd_size_type old_size;
  3061. old_size = current->size;
  3062. current->size = BFD_ALIGN (current->size,
  3063. 1 << current->alignment_power);
  3064. align_adjust = current->size != old_size;
  3065. sofar += current->size - old_size;
  3066. }
  3067. else
  3068. {
  3069. old_sofar = sofar;
  3070. sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
  3071. align_adjust = sofar != old_sofar;
  3072. current->size += sofar - old_sofar;
  3073. }
  3074. #endif
  3075. #ifdef COFF_IMAGE_WITH_PE
  3076. /* For PE we need to make sure we pad out to the aligned
  3077. size, in case the caller only writes out data to the
  3078. unaligned size. */
  3079. if (pei_section_data (abfd, current)->virt_size < current->size)
  3080. align_adjust = TRUE;
  3081. #endif
  3082. #ifdef _LIB
  3083. /* Force .lib sections to start at zero. The vma is then
  3084. incremented in coff_set_section_contents. This is right for
  3085. SVR3.2. */
  3086. if (strcmp (current->name, _LIB) == 0)
  3087. (void) bfd_set_section_vma (abfd, current, 0);
  3088. #endif
  3089. #ifdef ALIGN_SECTIONS_IN_FILE
  3090. previous = current;
  3091. #endif
  3092. }
  3093. /* It is now safe to write to the output file. If we needed an
  3094. alignment adjustment for the last section, then make sure that
  3095. there is a byte at offset sofar. If there are no symbols and no
  3096. relocs, then nothing follows the last section. If we don't force
  3097. the last byte out, then the file may appear to be truncated. */
  3098. if (align_adjust)
  3099. {
  3100. bfd_byte b;
  3101. b = 0;
  3102. if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
  3103. || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
  3104. return FALSE;
  3105. }
  3106. /* Make sure the relocations are aligned. We don't need to make
  3107. sure that this byte exists, because it will only matter if there
  3108. really are relocs. */
  3109. sofar = BFD_ALIGN (sofar, 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);
  3110. obj_relocbase (abfd) = sofar;
  3111. abfd->output_has_begun = TRUE;
  3112. return TRUE;
  3113. }
  3114. #ifdef COFF_IMAGE_WITH_PE
  3115. static unsigned int pelength;
  3116. static unsigned int peheader;
  3117. static bfd_boolean
  3118. coff_read_word (bfd *abfd, unsigned int *value)
  3119. {
  3120. unsigned char b[2];
  3121. int status;
  3122. status = bfd_bread (b, (bfd_size_type) 2, abfd);
  3123. if (status < 1)
  3124. {
  3125. *value = 0;
  3126. return FALSE;
  3127. }
  3128. if (status == 1)
  3129. *value = (unsigned int) b[0];
  3130. else
  3131. *value = (unsigned int) (b[0] + (b[1] << 8));
  3132. pelength += (unsigned int) status;
  3133. return TRUE;
  3134. }
  3135. static unsigned int
  3136. coff_compute_checksum (bfd *abfd)
  3137. {
  3138. bfd_boolean more_data;
  3139. file_ptr filepos;
  3140. unsigned int value;
  3141. unsigned int total;
  3142. total = 0;
  3143. pelength = 0;
  3144. filepos = (file_ptr) 0;
  3145. do
  3146. {
  3147. if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
  3148. return 0;
  3149. more_data = coff_read_word (abfd, &value);
  3150. total += value;
  3151. total = 0xffff & (total + (total >> 0x10));
  3152. filepos += 2;
  3153. }
  3154. while (more_data);
  3155. return (0xffff & (total + (total >> 0x10)));
  3156. }
  3157. static bfd_boolean
  3158. coff_apply_checksum (bfd *abfd)
  3159. {
  3160. unsigned int computed;
  3161. unsigned int checksum = 0;
  3162. if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0)
  3163. return FALSE;
  3164. if (!coff_read_word (abfd, &peheader))
  3165. return FALSE;
  3166. if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
  3167. return FALSE;
  3168. checksum = 0;
  3169. bfd_bwrite (&checksum, (bfd_size_type) 4, abfd);
  3170. if (bfd_seek (abfd, peheader, SEEK_SET) != 0)
  3171. return FALSE;
  3172. computed = coff_compute_checksum (abfd);
  3173. checksum = computed + pelength;
  3174. if (bfd_seek (abfd, peheader + 0x58, SEEK_SET) != 0)
  3175. return FALSE;
  3176. bfd_bwrite (&checksum, (bfd_size_type) 4, abfd);
  3177. return TRUE;
  3178. }
  3179. #endif /* COFF_IMAGE_WITH_PE */
  3180. static bfd_boolean
  3181. coff_write_object_contents (bfd * abfd)
  3182. {
  3183. asection *current;
  3184. bfd_boolean hasrelocs = FALSE;
  3185. bfd_boolean haslinno = FALSE;
  3186. #ifdef COFF_IMAGE_WITH_PE
  3187. bfd_boolean hasdebug = FALSE;
  3188. #endif
  3189. file_ptr scn_base;
  3190. file_ptr reloc_base;
  3191. file_ptr lineno_base;
  3192. file_ptr sym_base;
  3193. unsigned long reloc_size = 0, reloc_count = 0;
  3194. unsigned long lnno_size = 0;
  3195. bfd_boolean long_section_names;
  3196. asection *text_sec = NULL;
  3197. asection *data_sec = NULL;
  3198. asection *bss_sec = NULL;
  3199. struct internal_filehdr internal_f;
  3200. struct internal_aouthdr internal_a;
  3201. #ifdef COFF_LONG_SECTION_NAMES
  3202. size_t string_size = STRING_SIZE_SIZE;
  3203. #endif
  3204. bfd_set_error (bfd_error_system_call);
  3205. /* Make a pass through the symbol table to count line number entries and
  3206. put them into the correct asections. */
  3207. lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
  3208. if (! abfd->output_has_begun)
  3209. {
  3210. if (! coff_compute_section_file_positions (abfd))
  3211. return FALSE;
  3212. }
  3213. reloc_base = obj_relocbase (abfd);
  3214. /* Work out the size of the reloc and linno areas. */
  3215. for (current = abfd->sections; current != NULL; current =
  3216. current->next)
  3217. {
  3218. #ifdef COFF_WITH_PE
  3219. /* We store the actual reloc count in the first reloc's addr. */
  3220. if (obj_pe (abfd) && current->reloc_count >= 0xffff)
  3221. reloc_count ++;
  3222. #endif
  3223. reloc_count += current->reloc_count;
  3224. }
  3225. reloc_size = reloc_count * bfd_coff_relsz (abfd);
  3226. lineno_base = reloc_base + reloc_size;
  3227. sym_base = lineno_base + lnno_size;
  3228. /* Indicate in each section->line_filepos its actual file address. */
  3229. for (current = abfd->sections; current != NULL; current =
  3230. current->next)
  3231. {
  3232. if (current->lineno_count)
  3233. {
  3234. current->line_filepos = lineno_base;
  3235. current->moving_line_filepos = lineno_base;
  3236. lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
  3237. }
  3238. else
  3239. current->line_filepos = 0;
  3240. if (current->reloc_count)
  3241. {
  3242. current->rel_filepos = reloc_base;
  3243. reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
  3244. #ifdef COFF_WITH_PE
  3245. /* Extra reloc to hold real count. */
  3246. if (obj_pe (abfd) && current->reloc_count >= 0xffff)
  3247. reloc_base += bfd_coff_relsz (abfd);
  3248. #endif
  3249. }
  3250. else
  3251. current->rel_filepos = 0;
  3252. }
  3253. /* Write section headers to the file. */
  3254. internal_f.f_nscns = 0;
  3255. if ((abfd->flags & EXEC_P) != 0)
  3256. scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
  3257. else
  3258. {
  3259. scn_base = bfd_coff_filhsz (abfd);
  3260. #ifdef RS6000COFF_C
  3261. #ifndef XCOFF64
  3262. if (xcoff_data (abfd)->full_aouthdr)
  3263. scn_base += bfd_coff_aoutsz (abfd);
  3264. else
  3265. scn_base += SMALL_AOUTSZ;
  3266. #endif
  3267. #endif
  3268. }
  3269. if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
  3270. return FALSE;
  3271. long_section_names = FALSE;
  3272. for (current = abfd->sections;
  3273. current != NULL;
  3274. current = current->next)
  3275. {
  3276. struct internal_scnhdr section;
  3277. #ifdef COFF_IMAGE_WITH_PE
  3278. bfd_boolean is_reloc_section = FALSE;
  3279. if (strcmp (current->name, DOT_RELOC) == 0)
  3280. {
  3281. is_reloc_section = TRUE;
  3282. hasrelocs = TRUE;
  3283. pe_data (abfd)->has_reloc_section = 1;
  3284. }
  3285. #endif
  3286. internal_f.f_nscns++;
  3287. strncpy (section.s_name, current->name, SCNNMLEN);
  3288. #ifdef COFF_LONG_SECTION_NAMES
  3289. /* Handle long section names as in PE. This must be compatible
  3290. with the code in coff_write_symbols and _bfd_coff_final_link. */
  3291. if (bfd_coff_long_section_names (abfd))
  3292. {
  3293. size_t len;
  3294. len = strlen (current->name);
  3295. if (len > SCNNMLEN)
  3296. {
  3297. /* The s_name field is defined to be NUL-padded but need not be
  3298. NUL-terminated. We use a temporary buffer so that we can still
  3299. sprintf all eight chars without splatting a terminating NUL
  3300. over the first byte of the following member (s_paddr). */
  3301. char s_name_buf[SCNNMLEN + 1];
  3302. /* An inherent limitation of the /nnnnnnn notation used to indicate
  3303. the offset of the long name in the string table is that we
  3304. cannot address entries beyone the ten million byte boundary. */
  3305. if (string_size >= 10000000)
  3306. {
  3307. bfd_set_error (bfd_error_file_too_big);
  3308. (*_bfd_error_handler)
  3309. (_("%B: section %s: string table overflow at offset %ld"),
  3310. abfd, current->name, string_size);
  3311. return FALSE;
  3312. }
  3313. /* snprintf not strictly necessary now we've verified the value
  3314. has less than eight ASCII digits, but never mind. */
  3315. snprintf (s_name_buf, SCNNMLEN + 1, "/%lu", (unsigned long) string_size);
  3316. /* Then strncpy takes care of any padding for us. */
  3317. strncpy (section.s_name, s_name_buf, SCNNMLEN);
  3318. string_size += len + 1;
  3319. long_section_names = TRUE;
  3320. }
  3321. }
  3322. #endif
  3323. #ifdef _LIB
  3324. /* Always set s_vaddr of .lib to 0. This is right for SVR3.2
  3325. Ian Taylor <ian@cygnus.com>. */
  3326. if (strcmp (current->name, _LIB) == 0)
  3327. section.s_vaddr = 0;
  3328. else
  3329. #endif
  3330. section.s_vaddr = current->vma;
  3331. section.s_paddr = current->lma;
  3332. section.s_size = current->size;
  3333. #ifdef coff_get_section_load_page
  3334. section.s_page = coff_get_section_load_page (current);
  3335. #else
  3336. section.s_page = 0;
  3337. #endif
  3338. #ifdef COFF_WITH_PE
  3339. section.s_paddr = 0;
  3340. #endif
  3341. #ifdef COFF_IMAGE_WITH_PE
  3342. /* Reminder: s_paddr holds the virtual size of the section. */
  3343. if (coff_section_data (abfd, current) != NULL
  3344. && pei_section_data (abfd, current) != NULL)
  3345. section.s_paddr = pei_section_data (abfd, current)->virt_size;
  3346. else
  3347. section.s_paddr = 0;
  3348. #endif
  3349. /* If this section has no size or is unloadable then the scnptr
  3350. will be 0 too. */
  3351. if (current->size == 0
  3352. || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
  3353. section.s_scnptr = 0;
  3354. else
  3355. section.s_scnptr = current->filepos;
  3356. section.s_relptr = current->rel_filepos;
  3357. section.s_lnnoptr = current->line_filepos;
  3358. section.s_nreloc = current->reloc_count;
  3359. section.s_nlnno = current->lineno_count;
  3360. #ifndef COFF_IMAGE_WITH_PE
  3361. /* In PEI, relocs come in the .reloc section. */
  3362. if (current->reloc_count != 0)
  3363. hasrelocs = TRUE;
  3364. #endif
  3365. if (current->lineno_count != 0)
  3366. haslinno = TRUE;
  3367. #ifdef COFF_IMAGE_WITH_PE
  3368. if ((current->flags & SEC_DEBUGGING) != 0
  3369. && ! is_reloc_section)
  3370. hasdebug = TRUE;
  3371. #endif
  3372. #ifdef RS6000COFF_C
  3373. #ifndef XCOFF64
  3374. /* Indicate the use of an XCOFF overflow section header. */
  3375. if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
  3376. {
  3377. section.s_nreloc = 0xffff;
  3378. section.s_nlnno = 0xffff;
  3379. }
  3380. #endif
  3381. #endif
  3382. section.s_flags = sec_to_styp_flags (current->name, current->flags);
  3383. if (!strcmp (current->name, _TEXT))
  3384. text_sec = current;
  3385. else if (!strcmp (current->name, _DATA))
  3386. data_sec = current;
  3387. else if (!strcmp (current->name, _BSS))
  3388. bss_sec = current;
  3389. #ifdef I960
  3390. section.s_align = (current->alignment_power
  3391. ? 1 << current->alignment_power
  3392. : 0);
  3393. #endif
  3394. #ifdef TIC80COFF
  3395. /* TI COFF puts the alignment power in bits 8-11 of the flags. */
  3396. section.s_flags |= (current->alignment_power & 0xF) << 8;
  3397. #endif
  3398. #ifdef COFF_ENCODE_ALIGNMENT
  3399. COFF_ENCODE_ALIGNMENT(section, current->alignment_power);
  3400. #endif
  3401. #ifdef COFF_IMAGE_WITH_PE
  3402. /* Suppress output of the sections if they are null. ld
  3403. includes the bss and data sections even if there is no size
  3404. assigned to them. NT loader doesn't like it if these section
  3405. headers are included if the sections themselves are not
  3406. needed. See also coff_compute_section_file_positions. */
  3407. if (section.s_size == 0)
  3408. internal_f.f_nscns--;
  3409. else
  3410. #endif
  3411. {
  3412. SCNHDR buff;
  3413. bfd_size_type amt = bfd_coff_scnhsz (abfd);
  3414. if (coff_swap_scnhdr_out (abfd, &section, &buff) == 0
  3415. || bfd_bwrite (& buff, amt, abfd) != amt)
  3416. return FALSE;
  3417. }
  3418. #ifdef COFF_WITH_PE
  3419. /* PE stores COMDAT section information in the symbol table. If
  3420. this section is supposed to have some COMDAT info, track down
  3421. the symbol in the symbol table and modify it. */
  3422. if ((current->flags & SEC_LINK_ONCE) != 0)
  3423. {
  3424. unsigned int i, count;
  3425. asymbol **psym;
  3426. coff_symbol_type *csym = NULL;
  3427. asymbol **psymsec;
  3428. psymsec = NULL;
  3429. count = bfd_get_symcount (abfd);
  3430. for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
  3431. {
  3432. if ((*psym)->section != current)
  3433. continue;
  3434. /* Remember the location of the first symbol in this
  3435. section. */
  3436. if (psymsec == NULL)
  3437. psymsec = psym;
  3438. /* See if this is the section symbol. */
  3439. if (strcmp ((*psym)->name, current->name) == 0)
  3440. {
  3441. csym = coff_symbol_from (*psym);
  3442. if (csym == NULL
  3443. || csym->native == NULL
  3444. || ! csym->native->is_sym
  3445. || csym->native->u.syment.n_numaux < 1
  3446. || csym->native->u.syment.n_sclass != C_STAT
  3447. || csym->native->u.syment.n_type != T_NULL)
  3448. continue;
  3449. /* Here *PSYM is the section symbol for CURRENT. */
  3450. break;
  3451. }
  3452. }
  3453. /* Did we find it?
  3454. Note that we might not if we're converting the file from
  3455. some other object file format. */
  3456. if (i < count)
  3457. {
  3458. combined_entry_type *aux;
  3459. /* We don't touch the x_checksum field. The
  3460. x_associated field is not currently supported. */
  3461. aux = csym->native + 1;
  3462. BFD_ASSERT (! aux->is_sym);
  3463. switch (current->flags & SEC_LINK_DUPLICATES)
  3464. {
  3465. case SEC_LINK_DUPLICATES_DISCARD:
  3466. aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
  3467. break;
  3468. case SEC_LINK_DUPLICATES_ONE_ONLY:
  3469. aux->u.auxent.x_scn.x_comdat =
  3470. IMAGE_COMDAT_SELECT_NODUPLICATES;
  3471. break;
  3472. case SEC_LINK_DUPLICATES_SAME_SIZE:
  3473. aux->u.auxent.x_scn.x_comdat =
  3474. IMAGE_COMDAT_SELECT_SAME_SIZE;
  3475. break;
  3476. case SEC_LINK_DUPLICATES_SAME_CONTENTS:
  3477. aux->u.auxent.x_scn.x_comdat =
  3478. IMAGE_COMDAT_SELECT_EXACT_MATCH;
  3479. break;
  3480. }
  3481. /* The COMDAT symbol must be the first symbol from this
  3482. section in the symbol table. In order to make this
  3483. work, we move the COMDAT symbol before the first
  3484. symbol we found in the search above. It's OK to
  3485. rearrange the symbol table at this point, because
  3486. coff_renumber_symbols is going to rearrange it
  3487. further and fix up all the aux entries. */
  3488. if (psym != psymsec)
  3489. {
  3490. asymbol *hold;
  3491. asymbol **pcopy;
  3492. hold = *psym;
  3493. for (pcopy = psym; pcopy > psymsec; pcopy--)
  3494. pcopy[0] = pcopy[-1];
  3495. *psymsec = hold;
  3496. }
  3497. }
  3498. }
  3499. #endif /* COFF_WITH_PE */
  3500. }
  3501. #ifdef RS6000COFF_C
  3502. #ifndef XCOFF64
  3503. /* XCOFF handles overflows in the reloc and line number count fields
  3504. by creating a new section header to hold the correct values. */
  3505. for (current = abfd->sections; current != NULL; current = current->next)
  3506. {
  3507. if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
  3508. {
  3509. struct internal_scnhdr scnhdr;
  3510. SCNHDR buff;
  3511. bfd_size_type amt;
  3512. internal_f.f_nscns++;
  3513. memcpy (scnhdr.s_name, ".ovrflo", 8);
  3514. scnhdr.s_paddr = current->reloc_count;
  3515. scnhdr.s_vaddr = current->lineno_count;
  3516. scnhdr.s_size = 0;
  3517. scnhdr.s_scnptr = 0;
  3518. scnhdr.s_relptr = current->rel_filepos;
  3519. scnhdr.s_lnnoptr = current->line_filepos;
  3520. scnhdr.s_nreloc = current->target_index;
  3521. scnhdr.s_nlnno = current->target_index;
  3522. scnhdr.s_flags = STYP_OVRFLO;
  3523. amt = bfd_coff_scnhsz (abfd);
  3524. if (coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
  3525. || bfd_bwrite (& buff, amt, abfd) != amt)
  3526. return FALSE;
  3527. }
  3528. }
  3529. #endif
  3530. #endif
  3531. /* OK, now set up the filehdr... */
  3532. /* Don't include the internal abs section in the section count */
  3533. /* We will NOT put a fucking timestamp in the header here. Every time you
  3534. put it back, I will come in and take it out again. I'm sorry. This
  3535. field does not belong here. We fill it with a 0 so it compares the
  3536. same but is not a reasonable time. -- gnu@cygnus.com */
  3537. internal_f.f_timdat = 0;
  3538. internal_f.f_flags = 0;
  3539. if (abfd->flags & EXEC_P)
  3540. internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
  3541. else
  3542. {
  3543. internal_f.f_opthdr = 0;
  3544. #ifdef RS6000COFF_C
  3545. #ifndef XCOFF64
  3546. if (xcoff_data (abfd)->full_aouthdr)
  3547. internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
  3548. else
  3549. internal_f.f_opthdr = SMALL_AOUTSZ;
  3550. #endif
  3551. #endif
  3552. }
  3553. if (!hasrelocs)
  3554. internal_f.f_flags |= F_RELFLG;
  3555. if (!haslinno)
  3556. internal_f.f_flags |= F_LNNO;
  3557. if (abfd->flags & EXEC_P)
  3558. internal_f.f_flags |= F_EXEC;
  3559. #ifdef COFF_IMAGE_WITH_PE
  3560. if (! hasdebug)
  3561. internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
  3562. if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
  3563. internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
  3564. #endif
  3565. #ifndef COFF_WITH_pex64
  3566. #ifdef COFF_WITH_PE
  3567. internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
  3568. #else
  3569. if (bfd_little_endian (abfd))
  3570. internal_f.f_flags |= F_AR32WR;
  3571. else
  3572. internal_f.f_flags |= F_AR32W;
  3573. #endif
  3574. #endif
  3575. #ifdef TI_TARGET_ID
  3576. /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
  3577. but it doesn't hurt to set it internally. */
  3578. internal_f.f_target_id = TI_TARGET_ID;
  3579. #endif
  3580. #ifdef TIC80_TARGET_ID
  3581. internal_f.f_target_id = TIC80_TARGET_ID;
  3582. #endif
  3583. /* FIXME, should do something about the other byte orders and
  3584. architectures. */
  3585. #ifdef RS6000COFF_C
  3586. if ((abfd->flags & DYNAMIC) != 0)
  3587. internal_f.f_flags |= F_SHROBJ;
  3588. if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
  3589. internal_f.f_flags |= F_DYNLOAD;
  3590. #endif
  3591. /* Set up architecture-dependent stuff. */
  3592. {
  3593. unsigned int magic = 0;
  3594. unsigned short flags = 0;
  3595. coff_set_flags (abfd, &magic, &flags);
  3596. internal_f.f_magic = magic;
  3597. internal_f.f_flags |= flags;
  3598. /* ...and the "opt"hdr... */
  3599. #ifdef TICOFF_AOUT_MAGIC
  3600. internal_a.magic = TICOFF_AOUT_MAGIC;
  3601. #define __A_MAGIC_SET__
  3602. #endif
  3603. #ifdef TIC80COFF
  3604. internal_a.magic = TIC80_ARCH_MAGIC;
  3605. #define __A_MAGIC_SET__
  3606. #endif /* TIC80 */
  3607. #ifdef I860
  3608. /* FIXME: What are the a.out magic numbers for the i860? */
  3609. internal_a.magic = 0;
  3610. #define __A_MAGIC_SET__
  3611. #endif /* I860 */
  3612. #ifdef I960
  3613. internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC);
  3614. #define __A_MAGIC_SET__
  3615. #endif /* I960 */
  3616. #if M88
  3617. #define __A_MAGIC_SET__
  3618. internal_a.magic = PAGEMAGICBCS;
  3619. #endif /* M88 */
  3620. #if APOLLO_M68
  3621. #define __A_MAGIC_SET__
  3622. internal_a.magic = APOLLO_COFF_VERSION_NUMBER;
  3623. #endif
  3624. #if defined(M68) || defined(WE32K) || defined(M68K)
  3625. #define __A_MAGIC_SET__
  3626. #if defined(LYNXOS)
  3627. internal_a.magic = LYNXCOFFMAGIC;
  3628. #else
  3629. #if defined(TARG_AUX)
  3630. internal_a.magic = (abfd->flags & D_PAGED ? PAGEMAGICPEXECPAGED :
  3631. abfd->flags & WP_TEXT ? PAGEMAGICPEXECSWAPPED :
  3632. PAGEMAGICEXECSWAPPED);
  3633. #else
  3634. #if defined (PAGEMAGICPEXECPAGED)
  3635. internal_a.magic = PAGEMAGICPEXECPAGED;
  3636. #endif
  3637. #endif /* TARG_AUX */
  3638. #endif /* LYNXOS */
  3639. #endif /* M68 || WE32K || M68K */
  3640. #if defined(ARM)
  3641. #define __A_MAGIC_SET__
  3642. internal_a.magic = ZMAGIC;
  3643. #endif
  3644. #if defined(PPC_PE)
  3645. #define __A_MAGIC_SET__
  3646. internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
  3647. #endif
  3648. #if defined MCORE_PE
  3649. #define __A_MAGIC_SET__
  3650. internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
  3651. #endif
  3652. #if defined(I386)
  3653. #define __A_MAGIC_SET__
  3654. #if defined LYNXOS
  3655. internal_a.magic = LYNXCOFFMAGIC;
  3656. #elif defined AMD64
  3657. internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
  3658. #else
  3659. internal_a.magic = ZMAGIC;
  3660. #endif
  3661. #endif /* I386 */
  3662. #if defined(IA64)
  3663. #define __A_MAGIC_SET__
  3664. internal_a.magic = PE32PMAGIC;
  3665. #endif /* IA64 */
  3666. #if defined(SPARC)
  3667. #define __A_MAGIC_SET__
  3668. #if defined(LYNXOS)
  3669. internal_a.magic = LYNXCOFFMAGIC;
  3670. #endif /* LYNXOS */
  3671. #endif /* SPARC */
  3672. #ifdef RS6000COFF_C
  3673. #define __A_MAGIC_SET__
  3674. internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
  3675. (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
  3676. RS6K_AOUTHDR_OMAGIC;
  3677. #endif
  3678. #if defined(SH) && defined(COFF_WITH_PE)
  3679. #define __A_MAGIC_SET__
  3680. internal_a.magic = SH_PE_MAGIC;
  3681. #endif
  3682. #if defined(MIPS) && defined(COFF_WITH_PE)
  3683. #define __A_MAGIC_SET__
  3684. internal_a.magic = MIPS_PE_MAGIC;
  3685. #endif
  3686. #ifndef __A_MAGIC_SET__
  3687. #include "Your aouthdr magic number is not being set!"
  3688. #else
  3689. #undef __A_MAGIC_SET__
  3690. #endif
  3691. }
  3692. /* FIXME: Does anybody ever set this to another value? */
  3693. internal_a.vstamp = 0;
  3694. /* Now should write relocs, strings, syms. */
  3695. obj_sym_filepos (abfd) = sym_base;
  3696. if (bfd_get_symcount (abfd) != 0)
  3697. {
  3698. int firstundef;
  3699. if (!coff_renumber_symbols (abfd, &firstundef))
  3700. return FALSE;
  3701. coff_mangle_symbols (abfd);
  3702. if (! coff_write_symbols (abfd))
  3703. return FALSE;
  3704. if (! coff_write_linenumbers (abfd))
  3705. return FALSE;
  3706. if (! coff_write_relocs (abfd, firstundef))
  3707. return FALSE;
  3708. }
  3709. #ifdef COFF_LONG_SECTION_NAMES
  3710. else if (long_section_names && ! obj_coff_strings_written (abfd))
  3711. {
  3712. /* If we have long section names we have to write out the string
  3713. table even if there are no symbols. */
  3714. if (! coff_write_symbols (abfd))
  3715. return FALSE;
  3716. }
  3717. #endif
  3718. #ifdef COFF_IMAGE_WITH_PE
  3719. #ifdef PPC_PE
  3720. else if ((abfd->flags & EXEC_P) != 0)
  3721. {
  3722. bfd_byte b;
  3723. /* PowerPC PE appears to require that all executable files be
  3724. rounded up to the page size. */
  3725. b = 0;
  3726. if (bfd_seek (abfd,
  3727. (file_ptr) BFD_ALIGN (sym_base, COFF_PAGE_SIZE) - 1,
  3728. SEEK_SET) != 0
  3729. || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
  3730. return FALSE;
  3731. }
  3732. #endif
  3733. #endif
  3734. /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
  3735. backend linker, and obj_raw_syment_count is not valid until after
  3736. coff_write_symbols is called. */
  3737. if (obj_raw_syment_count (abfd) != 0)
  3738. {
  3739. internal_f.f_symptr = sym_base;
  3740. #ifdef RS6000COFF_C
  3741. /* AIX appears to require that F_RELFLG not be set if there are
  3742. local symbols but no relocations. */
  3743. internal_f.f_flags &=~ F_RELFLG;
  3744. #endif
  3745. }
  3746. else
  3747. {
  3748. if (long_section_names)
  3749. internal_f.f_symptr = sym_base;
  3750. else
  3751. internal_f.f_symptr = 0;
  3752. internal_f.f_flags |= F_LSYMS;
  3753. }
  3754. if (text_sec)
  3755. {
  3756. internal_a.tsize = text_sec->size;
  3757. internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
  3758. }
  3759. if (data_sec)
  3760. {
  3761. internal_a.dsize = data_sec->size;
  3762. internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
  3763. }
  3764. if (bss_sec)
  3765. {
  3766. internal_a.bsize = bss_sec->size;
  3767. if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
  3768. internal_a.data_start = bss_sec->vma;
  3769. }
  3770. internal_a.entry = bfd_get_start_address (abfd);
  3771. internal_f.f_nsyms = obj_raw_syment_count (abfd);
  3772. #ifdef RS6000COFF_C
  3773. if (xcoff_data (abfd)->full_aouthdr)
  3774. {
  3775. bfd_vma toc;
  3776. asection *loader_sec;
  3777. internal_a.vstamp = 1;
  3778. internal_a.o_snentry = xcoff_data (abfd)->snentry;
  3779. if (internal_a.o_snentry == 0)
  3780. internal_a.entry = (bfd_vma) -1;
  3781. if (text_sec != NULL)
  3782. {
  3783. internal_a.o_sntext = text_sec->target_index;
  3784. internal_a.o_algntext = bfd_get_section_alignment (abfd, text_sec);
  3785. }
  3786. else
  3787. {
  3788. internal_a.o_sntext = 0;
  3789. internal_a.o_algntext = 0;
  3790. }
  3791. if (data_sec != NULL)
  3792. {
  3793. internal_a.o_sndata = data_sec->target_index;
  3794. internal_a.o_algndata = bfd_get_section_alignment (abfd, data_sec);
  3795. }
  3796. else
  3797. {
  3798. internal_a.o_sndata = 0;
  3799. internal_a.o_algndata = 0;
  3800. }
  3801. loader_sec = bfd_get_section_by_name (abfd, ".loader");
  3802. if (loader_sec != NULL)
  3803. internal_a.o_snloader = loader_sec->target_index;
  3804. else
  3805. internal_a.o_snloader = 0;
  3806. if (bss_sec != NULL)
  3807. internal_a.o_snbss = bss_sec->target_index;
  3808. else
  3809. internal_a.o_snbss = 0;
  3810. toc = xcoff_data (abfd)->toc;
  3811. internal_a.o_toc = toc;
  3812. internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
  3813. internal_a.o_modtype = xcoff_data (abfd)->modtype;
  3814. if (xcoff_data (abfd)->cputype != -1)
  3815. internal_a.o_cputype = xcoff_data (abfd)->cputype;
  3816. else
  3817. {
  3818. switch (bfd_get_arch (abfd))
  3819. {
  3820. case bfd_arch_rs6000:
  3821. internal_a.o_cputype = 4;
  3822. break;
  3823. case bfd_arch_powerpc:
  3824. if (bfd_get_mach (abfd) == bfd_mach_ppc)
  3825. internal_a.o_cputype = 3;
  3826. else
  3827. internal_a.o_cputype = 1;
  3828. break;
  3829. default:
  3830. abort ();
  3831. }
  3832. }
  3833. internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
  3834. internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
  3835. }
  3836. #endif
  3837. #ifdef COFF_WITH_PE
  3838. {
  3839. /* After object contents are finalized so we can compute a reasonable hash,
  3840. but before header is written so we can update it to point to debug directory. */
  3841. struct pe_tdata *pe = pe_data (abfd);
  3842. if (pe->build_id.after_write_object_contents != NULL)
  3843. (*pe->build_id.after_write_object_contents) (abfd);
  3844. }
  3845. #endif
  3846. /* Now write header. */
  3847. if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
  3848. return FALSE;
  3849. {
  3850. char * buff;
  3851. bfd_size_type amount = bfd_coff_filhsz (abfd);
  3852. buff = (char *) bfd_malloc (amount);
  3853. if (buff == NULL)
  3854. return FALSE;
  3855. bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
  3856. amount = bfd_bwrite (buff, amount, abfd);
  3857. free (buff);
  3858. if (amount != bfd_coff_filhsz (abfd))
  3859. return FALSE;
  3860. }
  3861. if (abfd->flags & EXEC_P)
  3862. {
  3863. /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
  3864. include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)). */
  3865. char * buff;
  3866. bfd_size_type amount = bfd_coff_aoutsz (abfd);
  3867. buff = (char *) bfd_malloc (amount);
  3868. if (buff == NULL)
  3869. return FALSE;
  3870. coff_swap_aouthdr_out (abfd, & internal_a, buff);
  3871. amount = bfd_bwrite (buff, amount, abfd);
  3872. free (buff);
  3873. if (amount != bfd_coff_aoutsz (abfd))
  3874. return FALSE;
  3875. #ifdef COFF_IMAGE_WITH_PE
  3876. if (! coff_apply_checksum (abfd))
  3877. return FALSE;
  3878. #endif
  3879. }
  3880. #ifdef RS6000COFF_C
  3881. else
  3882. {
  3883. AOUTHDR buff;
  3884. size_t size;
  3885. /* XCOFF seems to always write at least a small a.out header. */
  3886. coff_swap_aouthdr_out (abfd, & internal_a, & buff);
  3887. if (xcoff_data (abfd)->full_aouthdr)
  3888. size = bfd_coff_aoutsz (abfd);
  3889. else
  3890. size = SMALL_AOUTSZ;
  3891. if (bfd_bwrite (& buff, (bfd_size_type) size, abfd) != size)
  3892. return FALSE;
  3893. }
  3894. #endif
  3895. return TRUE;
  3896. }
  3897. static bfd_boolean
  3898. coff_set_section_contents (bfd * abfd,
  3899. sec_ptr section,
  3900. const void * location,
  3901. file_ptr offset,
  3902. bfd_size_type count)
  3903. {
  3904. if (! abfd->output_has_begun) /* Set by bfd.c handler. */
  3905. {
  3906. if (! coff_compute_section_file_positions (abfd))
  3907. return FALSE;
  3908. }
  3909. #if defined(_LIB) && !defined(TARG_AUX)
  3910. /* The physical address field of a .lib section is used to hold the
  3911. number of shared libraries in the section. This code counts the
  3912. number of sections being written, and increments the lma field
  3913. with the number.
  3914. I have found no documentation on the contents of this section.
  3915. Experimentation indicates that the section contains zero or more
  3916. records, each of which has the following structure:
  3917. - a (four byte) word holding the length of this record, in words,
  3918. - a word that always seems to be set to "2",
  3919. - the path to a shared library, null-terminated and then padded
  3920. to a whole word boundary.
  3921. bfd_assert calls have been added to alert if an attempt is made
  3922. to write a section which doesn't follow these assumptions. The
  3923. code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
  3924. <robertl@arnet.com> (Thanks!).
  3925. Gvran Uddeborg <gvran@uddeborg.pp.se>. */
  3926. if (strcmp (section->name, _LIB) == 0)
  3927. {
  3928. bfd_byte *rec, *recend;
  3929. rec = (bfd_byte *) location;
  3930. recend = rec + count;
  3931. while (rec < recend)
  3932. {
  3933. ++section->lma;
  3934. rec += bfd_get_32 (abfd, rec) * 4;
  3935. }
  3936. BFD_ASSERT (rec == recend);
  3937. }
  3938. #endif
  3939. /* Don't write out bss sections - one way to do this is to
  3940. see if the filepos has not been set. */
  3941. if (section->filepos == 0)
  3942. return TRUE;
  3943. if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
  3944. return FALSE;
  3945. if (count == 0)
  3946. return TRUE;
  3947. return bfd_bwrite (location, count, abfd) == count;
  3948. }
  3949. static void *
  3950. buy_and_read (bfd *abfd, file_ptr where, bfd_size_type size)
  3951. {
  3952. void * area = bfd_alloc (abfd, size);
  3953. if (!area)
  3954. return NULL;
  3955. if (bfd_seek (abfd, where, SEEK_SET) != 0
  3956. || bfd_bread (area, size, abfd) != size)
  3957. return NULL;
  3958. return area;
  3959. }
  3960. /*
  3961. SUBSUBSECTION
  3962. Reading linenumbers
  3963. Creating the linenumber table is done by reading in the entire
  3964. coff linenumber table, and creating another table for internal use.
  3965. A coff linenumber table is structured so that each function
  3966. is marked as having a line number of 0. Each line within the
  3967. function is an offset from the first line in the function. The
  3968. base of the line number information for the table is stored in
  3969. the symbol associated with the function.
  3970. Note: The PE format uses line number 0 for a flag indicating a
  3971. new source file.
  3972. The information is copied from the external to the internal
  3973. table, and each symbol which marks a function is marked by
  3974. pointing its...
  3975. How does this work ?
  3976. */
  3977. static int
  3978. coff_sort_func_alent (const void * arg1, const void * arg2)
  3979. {
  3980. const alent *al1 = *(const alent **) arg1;
  3981. const alent *al2 = *(const alent **) arg2;
  3982. const coff_symbol_type *s1 = (const coff_symbol_type *) (al1->u.sym);
  3983. const coff_symbol_type *s2 = (const coff_symbol_type *) (al2->u.sym);
  3984. if (s1 == NULL || s2 == NULL)
  3985. return 0;
  3986. if (s1->symbol.value < s2->symbol.value)
  3987. return -1;
  3988. else if (s1->symbol.value > s2->symbol.value)
  3989. return 1;
  3990. return 0;
  3991. }
  3992. static bfd_boolean
  3993. coff_slurp_line_table (bfd *abfd, asection *asect)
  3994. {
  3995. LINENO *native_lineno;
  3996. alent *lineno_cache;
  3997. bfd_size_type amt;
  3998. unsigned int counter;
  3999. alent *cache_ptr;
  4000. bfd_vma prev_offset = 0;
  4001. bfd_boolean ordered = TRUE;
  4002. unsigned int nbr_func;
  4003. LINENO *src;
  4004. bfd_boolean have_func;
  4005. bfd_boolean ret = TRUE;
  4006. BFD_ASSERT (asect->lineno == NULL);
  4007. amt = ((bfd_size_type) asect->lineno_count + 1) * sizeof (alent);
  4008. lineno_cache = (alent *) bfd_alloc (abfd, amt);
  4009. if (lineno_cache == NULL)
  4010. return FALSE;
  4011. amt = (bfd_size_type) bfd_coff_linesz (abfd) * asect->lineno_count;
  4012. native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos, amt);
  4013. if (native_lineno == NULL)
  4014. {
  4015. (*_bfd_error_handler)
  4016. (_("%B: warning: line number table read failed"), abfd);
  4017. bfd_release (abfd, lineno_cache);
  4018. return FALSE;
  4019. }
  4020. cache_ptr = lineno_cache;
  4021. asect->lineno = lineno_cache;
  4022. src = native_lineno;
  4023. nbr_func = 0;
  4024. have_func = FALSE;
  4025. for (counter = 0; counter < asect->lineno_count; counter++, src++)
  4026. {
  4027. struct internal_lineno dst;
  4028. bfd_coff_swap_lineno_in (abfd, src, &dst);
  4029. cache_ptr->line_number = dst.l_lnno;
  4030. /* Appease memory checkers that get all excited about
  4031. uninitialised memory when copying alents if u.offset is
  4032. larger than u.sym. (64-bit BFD on 32-bit host.) */
  4033. memset (&cache_ptr->u, 0, sizeof (cache_ptr->u));
  4034. if (cache_ptr->line_number == 0)
  4035. {
  4036. combined_entry_type * ent;
  4037. bfd_vma symndx;
  4038. coff_symbol_type *sym;
  4039. have_func = FALSE;
  4040. symndx = dst.l_addr.l_symndx;
  4041. if (symndx >= obj_raw_syment_count (abfd))
  4042. {
  4043. (*_bfd_error_handler)
  4044. (_("%B: warning: illegal symbol index 0x%lx in line number entry %d"),
  4045. abfd, (long) symndx, counter);
  4046. cache_ptr->line_number = -1;
  4047. ret = FALSE;
  4048. continue;
  4049. }
  4050. ent = obj_raw_syments (abfd) + symndx;
  4051. /* FIXME: We should not be casting between ints and
  4052. pointers like this. */
  4053. if (! ent->is_sym)
  4054. {
  4055. (*_bfd_error_handler)
  4056. (_("%B: warning: illegal symbol index 0x%lx in line number entry %d"),
  4057. abfd, (long) symndx, counter);
  4058. cache_ptr->line_number = -1;
  4059. ret = FALSE;
  4060. continue;
  4061. }
  4062. sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
  4063. /* PR 17512 file: 078-10659-0.004 */
  4064. if (sym < obj_symbols (abfd)
  4065. || sym >= obj_symbols (abfd) + bfd_get_symcount (abfd))
  4066. {
  4067. (*_bfd_error_handler)
  4068. (_("%B: warning: illegal symbol in line number entry %d"),
  4069. abfd, counter);
  4070. cache_ptr->line_number = -1;
  4071. ret = FALSE;
  4072. continue;
  4073. }
  4074. have_func = TRUE;
  4075. nbr_func++;
  4076. cache_ptr->u.sym = (asymbol *) sym;
  4077. if (sym->lineno != NULL)
  4078. (*_bfd_error_handler)
  4079. (_("%B: warning: duplicate line number information for `%s'"),
  4080. abfd, bfd_asymbol_name (&sym->symbol));
  4081. sym->lineno = cache_ptr;
  4082. if (sym->symbol.value < prev_offset)
  4083. ordered = FALSE;
  4084. prev_offset = sym->symbol.value;
  4085. }
  4086. else if (!have_func)
  4087. /* Drop line information that has no associated function.
  4088. PR 17521: file: 078-10659-0.004. */
  4089. continue;
  4090. else
  4091. cache_ptr->u.offset = (dst.l_addr.l_paddr
  4092. - bfd_section_vma (abfd, asect));
  4093. cache_ptr++;
  4094. }
  4095. asect->lineno_count = cache_ptr - lineno_cache;
  4096. memset (cache_ptr, 0, sizeof (*cache_ptr));
  4097. bfd_release (abfd, native_lineno);
  4098. /* On some systems (eg AIX5.3) the lineno table may not be sorted. */
  4099. if (!ordered)
  4100. {
  4101. /* Sort the table. */
  4102. alent **func_table;
  4103. alent *n_lineno_cache;
  4104. /* Create a table of functions. */
  4105. func_table = (alent **) bfd_alloc (abfd, nbr_func * sizeof (alent *));
  4106. if (func_table != NULL)
  4107. {
  4108. alent **p = func_table;
  4109. unsigned int i;
  4110. for (i = 0; i < asect->lineno_count; i++)
  4111. if (lineno_cache[i].line_number == 0)
  4112. *p++ = &lineno_cache[i];
  4113. BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
  4114. /* Sort by functions. */
  4115. qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
  4116. /* Create the new sorted table. */
  4117. amt = (bfd_size_type) asect->lineno_count * sizeof (alent);
  4118. n_lineno_cache = (alent *) bfd_alloc (abfd, amt);
  4119. if (n_lineno_cache != NULL)
  4120. {
  4121. alent *n_cache_ptr = n_lineno_cache;
  4122. for (i = 0; i < nbr_func; i++)
  4123. {
  4124. coff_symbol_type *sym;
  4125. alent *old_ptr = func_table[i];
  4126. /* Update the function entry. */
  4127. sym = (coff_symbol_type *) old_ptr->u.sym;
  4128. /* PR binutils/17512: Point the lineno to where
  4129. this entry will be after the memcpy below. */
  4130. sym->lineno = lineno_cache + (n_cache_ptr - n_lineno_cache);
  4131. /* Copy the function and line number entries. */
  4132. do
  4133. *n_cache_ptr++ = *old_ptr++;
  4134. while (old_ptr->line_number != 0);
  4135. }
  4136. BFD_ASSERT ((bfd_size_type) (n_cache_ptr - n_lineno_cache) == (amt / sizeof (alent)));
  4137. memcpy (lineno_cache, n_lineno_cache, amt);
  4138. }
  4139. else
  4140. ret = FALSE;
  4141. bfd_release (abfd, func_table);
  4142. }
  4143. else
  4144. ret = FALSE;
  4145. }
  4146. return ret;
  4147. }
  4148. /* Slurp in the symbol table, converting it to generic form. Note
  4149. that if coff_relocate_section is defined, the linker will read
  4150. symbols via coff_link_add_symbols, rather than via this routine. */
  4151. static bfd_boolean
  4152. coff_slurp_symbol_table (bfd * abfd)
  4153. {
  4154. combined_entry_type *native_symbols;
  4155. coff_symbol_type *cached_area;
  4156. unsigned int *table_ptr;
  4157. bfd_size_type amt;
  4158. unsigned int number_of_symbols = 0;
  4159. bfd_boolean ret = TRUE;
  4160. if (obj_symbols (abfd))
  4161. return TRUE;
  4162. /* Read in the symbol table. */
  4163. if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
  4164. return FALSE;
  4165. /* Allocate enough room for all the symbols in cached form. */
  4166. amt = obj_raw_syment_count (abfd);
  4167. amt *= sizeof (coff_symbol_type);
  4168. cached_area = (coff_symbol_type *) bfd_alloc (abfd, amt);
  4169. if (cached_area == NULL)
  4170. return FALSE;
  4171. amt = obj_raw_syment_count (abfd);
  4172. amt *= sizeof (unsigned int);
  4173. table_ptr = (unsigned int *) bfd_zalloc (abfd, amt);
  4174. if (table_ptr == NULL)
  4175. return FALSE;
  4176. else
  4177. {
  4178. coff_symbol_type *dst = cached_area;
  4179. unsigned int last_native_index = obj_raw_syment_count (abfd);
  4180. unsigned int this_index = 0;
  4181. while (this_index < last_native_index)
  4182. {
  4183. combined_entry_type *src = native_symbols + this_index;
  4184. table_ptr[this_index] = number_of_symbols;
  4185. dst->symbol.the_bfd = abfd;
  4186. BFD_ASSERT (src->is_sym);
  4187. dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
  4188. /* We use the native name field to point to the cached field. */
  4189. src->u.syment._n._n_n._n_zeroes = (bfd_hostptr_t) dst;
  4190. dst->symbol.section = coff_section_from_bfd_index (abfd,
  4191. src->u.syment.n_scnum);
  4192. dst->symbol.flags = 0;
  4193. /* PR 17512: file: 079-7098-0.001:0.1. */
  4194. dst->symbol.value = 0;
  4195. dst->done_lineno = FALSE;
  4196. switch (src->u.syment.n_sclass)
  4197. {
  4198. #ifdef I960
  4199. case C_LEAFEXT:
  4200. /* Fall through to next case. */
  4201. #endif
  4202. case C_EXT:
  4203. case C_WEAKEXT:
  4204. #if defined ARM
  4205. case C_THUMBEXT:
  4206. case C_THUMBEXTFUNC:
  4207. #endif
  4208. #ifdef RS6000COFF_C
  4209. case C_HIDEXT:
  4210. #endif
  4211. #ifdef C_SYSTEM
  4212. case C_SYSTEM: /* System Wide variable. */
  4213. #endif
  4214. #ifdef COFF_WITH_PE
  4215. /* In PE, 0x68 (104) denotes a section symbol. */
  4216. case C_SECTION:
  4217. /* In PE, 0x69 (105) denotes a weak external symbol. */
  4218. case C_NT_WEAK:
  4219. #endif
  4220. switch (coff_classify_symbol (abfd, &src->u.syment))
  4221. {
  4222. case COFF_SYMBOL_GLOBAL:
  4223. dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
  4224. #if defined COFF_WITH_PE
  4225. /* PE sets the symbol to a value relative to the
  4226. start of the section. */
  4227. dst->symbol.value = src->u.syment.n_value;
  4228. #else
  4229. dst->symbol.value = (src->u.syment.n_value
  4230. - dst->symbol.section->vma);
  4231. #endif
  4232. if (ISFCN ((src->u.syment.n_type)))
  4233. /* A function ext does not go at the end of a
  4234. file. */
  4235. dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
  4236. break;
  4237. case COFF_SYMBOL_COMMON:
  4238. dst->symbol.section = bfd_com_section_ptr;
  4239. dst->symbol.value = src->u.syment.n_value;
  4240. break;
  4241. case COFF_SYMBOL_UNDEFINED:
  4242. dst->symbol.section = bfd_und_section_ptr;
  4243. dst->symbol.value = 0;
  4244. break;
  4245. case COFF_SYMBOL_PE_SECTION:
  4246. dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
  4247. dst->symbol.value = 0;
  4248. break;
  4249. case COFF_SYMBOL_LOCAL:
  4250. dst->symbol.flags = BSF_LOCAL;
  4251. #if defined COFF_WITH_PE
  4252. /* PE sets the symbol to a value relative to the
  4253. start of the section. */
  4254. dst->symbol.value = src->u.syment.n_value;
  4255. #else
  4256. dst->symbol.value = (src->u.syment.n_value
  4257. - dst->symbol.section->vma);
  4258. #endif
  4259. if (ISFCN ((src->u.syment.n_type)))
  4260. dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
  4261. break;
  4262. }
  4263. #ifdef RS6000COFF_C
  4264. /* A symbol with a csect entry should not go at the end. */
  4265. if (src->u.syment.n_numaux > 0)
  4266. dst->symbol.flags |= BSF_NOT_AT_END;
  4267. #endif
  4268. #ifdef COFF_WITH_PE
  4269. if (src->u.syment.n_sclass == C_NT_WEAK)
  4270. dst->symbol.flags |= BSF_WEAK;
  4271. if (src->u.syment.n_sclass == C_SECTION
  4272. && src->u.syment.n_scnum > 0)
  4273. dst->symbol.flags = BSF_LOCAL;
  4274. #endif
  4275. if (src->u.syment.n_sclass == C_WEAKEXT)
  4276. dst->symbol.flags |= BSF_WEAK;
  4277. break;
  4278. case C_STAT: /* Static. */
  4279. #ifdef I960
  4280. case C_LEAFSTAT: /* Static leaf procedure. */
  4281. #endif
  4282. #if defined ARM
  4283. case C_THUMBSTAT: /* Thumb static. */
  4284. case C_THUMBLABEL: /* Thumb label. */
  4285. case C_THUMBSTATFUNC:/* Thumb static function. */
  4286. #endif
  4287. #ifdef RS6000COFF_C
  4288. case C_DWARF: /* A label in a dwarf section. */
  4289. case C_INFO: /* A label in a comment section. */
  4290. #endif
  4291. case C_LABEL: /* Label. */
  4292. if (src->u.syment.n_scnum == N_DEBUG)
  4293. dst->symbol.flags = BSF_DEBUGGING;
  4294. else
  4295. dst->symbol.flags = BSF_LOCAL;
  4296. /* Base the value as an index from the base of the
  4297. section, if there is one. */
  4298. if (dst->symbol.section)
  4299. {
  4300. #if defined COFF_WITH_PE
  4301. /* PE sets the symbol to a value relative to the
  4302. start of the section. */
  4303. dst->symbol.value = src->u.syment.n_value;
  4304. #else
  4305. dst->symbol.value = (src->u.syment.n_value
  4306. - dst->symbol.section->vma);
  4307. #endif
  4308. }
  4309. else
  4310. dst->symbol.value = src->u.syment.n_value;
  4311. break;
  4312. case C_MOS: /* Member of structure. */
  4313. case C_EOS: /* End of structure. */
  4314. case C_REGPARM: /* Register parameter. */
  4315. case C_REG: /* register variable. */
  4316. /* C_AUTOARG conflicts with TI COFF C_UEXT. */
  4317. #if !defined (TIC80COFF) && !defined (TICOFF)
  4318. #ifdef C_AUTOARG
  4319. case C_AUTOARG: /* 960-specific storage class. */
  4320. #endif
  4321. #endif
  4322. case C_TPDEF: /* Type definition. */
  4323. case C_ARG:
  4324. case C_AUTO: /* Automatic variable. */
  4325. case C_FIELD: /* Bit field. */
  4326. case C_ENTAG: /* Enumeration tag. */
  4327. case C_MOE: /* Member of enumeration. */
  4328. case C_MOU: /* Member of union. */
  4329. case C_UNTAG: /* Union tag. */
  4330. dst->symbol.flags = BSF_DEBUGGING;
  4331. dst->symbol.value = (src->u.syment.n_value);
  4332. break;
  4333. case C_FILE: /* File name. */
  4334. case C_STRTAG: /* Structure tag. */
  4335. #ifdef RS6000COFF_C
  4336. case C_GSYM:
  4337. case C_LSYM:
  4338. case C_PSYM:
  4339. case C_RSYM:
  4340. case C_RPSYM:
  4341. case C_STSYM:
  4342. case C_TCSYM:
  4343. case C_BCOMM:
  4344. case C_ECOML:
  4345. case C_ECOMM:
  4346. case C_DECL:
  4347. case C_ENTRY:
  4348. case C_FUN:
  4349. case C_ESTAT:
  4350. #endif
  4351. dst->symbol.flags = BSF_DEBUGGING;
  4352. dst->symbol.value = (src->u.syment.n_value);
  4353. break;
  4354. #ifdef RS6000COFF_C
  4355. case C_BINCL: /* Beginning of include file. */
  4356. case C_EINCL: /* Ending of include file. */
  4357. /* The value is actually a pointer into the line numbers
  4358. of the file. We locate the line number entry, and
  4359. set the section to the section which contains it, and
  4360. the value to the index in that section. */
  4361. {
  4362. asection *sec;
  4363. dst->symbol.flags = BSF_DEBUGGING;
  4364. for (sec = abfd->sections; sec != NULL; sec = sec->next)
  4365. if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
  4366. && ((file_ptr) (sec->line_filepos
  4367. + sec->lineno_count * bfd_coff_linesz (abfd))
  4368. > (file_ptr) src->u.syment.n_value))
  4369. break;
  4370. if (sec == NULL)
  4371. dst->symbol.value = 0;
  4372. else
  4373. {
  4374. dst->symbol.section = sec;
  4375. dst->symbol.value = ((src->u.syment.n_value
  4376. - sec->line_filepos)
  4377. / bfd_coff_linesz (abfd));
  4378. src->fix_line = 1;
  4379. }
  4380. }
  4381. break;
  4382. case C_BSTAT:
  4383. dst->symbol.flags = BSF_DEBUGGING;
  4384. /* The value is actually a symbol index. Save a pointer
  4385. to the symbol instead of the index. FIXME: This
  4386. should use a union. */
  4387. src->u.syment.n_value =
  4388. (long) (intptr_t) (native_symbols + src->u.syment.n_value);
  4389. dst->symbol.value = src->u.syment.n_value;
  4390. src->fix_value = 1;
  4391. break;
  4392. #endif
  4393. case C_BLOCK: /* ".bb" or ".eb". */
  4394. case C_FCN: /* ".bf" or ".ef" (or PE ".lf"). */
  4395. case C_EFCN: /* Physical end of function. */
  4396. #if defined COFF_WITH_PE
  4397. /* PE sets the symbol to a value relative to the start
  4398. of the section. */
  4399. dst->symbol.value = src->u.syment.n_value;
  4400. if (strcmp (dst->symbol.name, ".bf") != 0)
  4401. {
  4402. /* PE uses funny values for .ef and .lf; don't
  4403. relocate them. */
  4404. dst->symbol.flags = BSF_DEBUGGING;
  4405. }
  4406. else
  4407. dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
  4408. #else
  4409. /* Base the value as an index from the base of the
  4410. section. */
  4411. dst->symbol.flags = BSF_LOCAL;
  4412. dst->symbol.value = (src->u.syment.n_value
  4413. - dst->symbol.section->vma);
  4414. #endif
  4415. break;
  4416. case C_STATLAB: /* Static load time label. */
  4417. dst->symbol.value = src->u.syment.n_value;
  4418. dst->symbol.flags = BSF_GLOBAL;
  4419. break;
  4420. case C_NULL:
  4421. /* PE DLLs sometimes have zeroed out symbols for some
  4422. reason. Just ignore them without a warning. */
  4423. if (src->u.syment.n_type == 0
  4424. && src->u.syment.n_value == 0
  4425. && src->u.syment.n_scnum == 0)
  4426. break;
  4427. #ifdef RS6000COFF_C
  4428. /* XCOFF specific: deleted entry. */
  4429. if (src->u.syment.n_value == C_NULL_VALUE)
  4430. break;
  4431. #endif
  4432. /* Fall through. */
  4433. case C_EXTDEF: /* External definition. */
  4434. case C_ULABEL: /* Undefined label. */
  4435. case C_USTATIC: /* Undefined static. */
  4436. #ifndef COFF_WITH_PE
  4437. /* C_LINE in regular coff is 0x68. NT has taken over this storage
  4438. class to represent a section symbol. */
  4439. case C_LINE: /* line # reformatted as symbol table entry. */
  4440. /* NT uses 0x67 for a weak symbol, not C_ALIAS. */
  4441. case C_ALIAS: /* Duplicate tag. */
  4442. #endif
  4443. /* New storage classes for TI COFF. */
  4444. #if defined(TIC80COFF) || defined(TICOFF)
  4445. case C_UEXT: /* Tentative external definition. */
  4446. #endif
  4447. default:
  4448. (*_bfd_error_handler)
  4449. (_("%B: Unrecognized storage class %d for %s symbol `%s'"),
  4450. abfd, src->u.syment.n_sclass,
  4451. dst->symbol.section->name, dst->symbol.name);
  4452. ret = FALSE;
  4453. case C_EXTLAB: /* External load time label. */
  4454. case C_HIDDEN: /* Ext symbol in dmert public lib. */
  4455. dst->symbol.flags = BSF_DEBUGGING;
  4456. dst->symbol.value = (src->u.syment.n_value);
  4457. break;
  4458. }
  4459. dst->native = src;
  4460. dst->symbol.udata.i = 0;
  4461. dst->lineno = NULL;
  4462. this_index += (src->u.syment.n_numaux) + 1;
  4463. dst++;
  4464. number_of_symbols++;
  4465. }
  4466. }
  4467. obj_symbols (abfd) = cached_area;
  4468. obj_raw_syments (abfd) = native_symbols;
  4469. bfd_get_symcount (abfd) = number_of_symbols;
  4470. obj_convert (abfd) = table_ptr;
  4471. /* Slurp the line tables for each section too. */
  4472. {
  4473. asection *p;
  4474. p = abfd->sections;
  4475. while (p)
  4476. {
  4477. if (! coff_slurp_line_table (abfd, p))
  4478. return FALSE;
  4479. p = p->next;
  4480. }
  4481. }
  4482. return ret;
  4483. }
  4484. /* Classify a COFF symbol. A couple of targets have globally visible
  4485. symbols which are not class C_EXT, and this handles those. It also
  4486. recognizes some special PE cases. */
  4487. static enum coff_symbol_classification
  4488. coff_classify_symbol (bfd *abfd,
  4489. struct internal_syment *syment)
  4490. {
  4491. /* FIXME: This partially duplicates the switch in
  4492. coff_slurp_symbol_table. */
  4493. switch (syment->n_sclass)
  4494. {
  4495. case C_EXT:
  4496. case C_WEAKEXT:
  4497. #ifdef I960
  4498. case C_LEAFEXT:
  4499. #endif
  4500. #ifdef ARM
  4501. case C_THUMBEXT:
  4502. case C_THUMBEXTFUNC:
  4503. #endif
  4504. #ifdef C_SYSTEM
  4505. case C_SYSTEM:
  4506. #endif
  4507. #ifdef COFF_WITH_PE
  4508. case C_NT_WEAK:
  4509. #endif
  4510. if (syment->n_scnum == 0)
  4511. {
  4512. if (syment->n_value == 0)
  4513. return COFF_SYMBOL_UNDEFINED;
  4514. else
  4515. return COFF_SYMBOL_COMMON;
  4516. }
  4517. return COFF_SYMBOL_GLOBAL;
  4518. default:
  4519. break;
  4520. }
  4521. #ifdef COFF_WITH_PE
  4522. if (syment->n_sclass == C_STAT)
  4523. {
  4524. if (syment->n_scnum == 0)
  4525. /* The Microsoft compiler sometimes generates these if a
  4526. small static function is inlined every time it is used.
  4527. The function is discarded, but the symbol table entry
  4528. remains. */
  4529. return COFF_SYMBOL_LOCAL;
  4530. #ifdef STRICT_PE_FORMAT
  4531. /* This is correct for Microsoft generated objects, but it
  4532. breaks gas generated objects. */
  4533. if (syment->n_value == 0)
  4534. {
  4535. asection *sec;
  4536. char * name;
  4537. char buf[SYMNMLEN + 1];
  4538. name = _bfd_coff_internal_syment_name (abfd, syment, buf)
  4539. sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
  4540. if (sec != NULL && name != NULL
  4541. && (strcmp (bfd_get_section_name (abfd, sec), name) == 0))
  4542. return COFF_SYMBOL_PE_SECTION;
  4543. }
  4544. #endif
  4545. return COFF_SYMBOL_LOCAL;
  4546. }
  4547. if (syment->n_sclass == C_SECTION)
  4548. {
  4549. /* In some cases in a DLL generated by the Microsoft linker, the
  4550. n_value field will contain garbage. FIXME: This should
  4551. probably be handled by the swapping function instead. */
  4552. syment->n_value = 0;
  4553. if (syment->n_scnum == 0)
  4554. return COFF_SYMBOL_UNDEFINED;
  4555. return COFF_SYMBOL_PE_SECTION;
  4556. }
  4557. #endif /* COFF_WITH_PE */
  4558. /* If it is not a global symbol, we presume it is a local symbol. */
  4559. if (syment->n_scnum == 0)
  4560. {
  4561. char buf[SYMNMLEN + 1];
  4562. (*_bfd_error_handler)
  4563. (_("warning: %B: local symbol `%s' has no section"),
  4564. abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
  4565. }
  4566. return COFF_SYMBOL_LOCAL;
  4567. }
  4568. /*
  4569. SUBSUBSECTION
  4570. Reading relocations
  4571. Coff relocations are easily transformed into the internal BFD form
  4572. (@code{arelent}).
  4573. Reading a coff relocation table is done in the following stages:
  4574. o Read the entire coff relocation table into memory.
  4575. o Process each relocation in turn; first swap it from the
  4576. external to the internal form.
  4577. o Turn the symbol referenced in the relocation's symbol index
  4578. into a pointer into the canonical symbol table.
  4579. This table is the same as the one returned by a call to
  4580. @code{bfd_canonicalize_symtab}. The back end will call that
  4581. routine and save the result if a canonicalization hasn't been done.
  4582. o The reloc index is turned into a pointer to a howto
  4583. structure, in a back end specific way. For instance, the 386
  4584. and 960 use the @code{r_type} to directly produce an index
  4585. into a howto table vector; the 88k subtracts a number from the
  4586. @code{r_type} field and creates an addend field.
  4587. */
  4588. #ifndef CALC_ADDEND
  4589. #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
  4590. { \
  4591. coff_symbol_type *coffsym = NULL; \
  4592. \
  4593. if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
  4594. coffsym = (obj_symbols (abfd) \
  4595. + (cache_ptr->sym_ptr_ptr - symbols)); \
  4596. else if (ptr) \
  4597. coffsym = coff_symbol_from (ptr); \
  4598. if (coffsym != NULL \
  4599. && coffsym->native->is_sym \
  4600. && coffsym->native->u.syment.n_scnum == 0) \
  4601. cache_ptr->addend = 0; \
  4602. else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
  4603. && ptr->section != NULL) \
  4604. cache_ptr->addend = - (ptr->section->vma + ptr->value); \
  4605. else \
  4606. cache_ptr->addend = 0; \
  4607. }
  4608. #endif
  4609. static bfd_boolean
  4610. coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
  4611. {
  4612. RELOC *native_relocs;
  4613. arelent *reloc_cache;
  4614. arelent *cache_ptr;
  4615. unsigned int idx;
  4616. bfd_size_type amt;
  4617. if (asect->relocation)
  4618. return TRUE;
  4619. if (asect->reloc_count == 0)
  4620. return TRUE;
  4621. if (asect->flags & SEC_CONSTRUCTOR)
  4622. return TRUE;
  4623. if (!coff_slurp_symbol_table (abfd))
  4624. return FALSE;
  4625. amt = (bfd_size_type) bfd_coff_relsz (abfd) * asect->reloc_count;
  4626. native_relocs = (RELOC *) buy_and_read (abfd, asect->rel_filepos, amt);
  4627. amt = (bfd_size_type) asect->reloc_count * sizeof (arelent);
  4628. reloc_cache = (arelent *) bfd_alloc (abfd, amt);
  4629. if (reloc_cache == NULL || native_relocs == NULL)
  4630. return FALSE;
  4631. for (idx = 0; idx < asect->reloc_count; idx++)
  4632. {
  4633. struct internal_reloc dst;
  4634. struct external_reloc *src;
  4635. #ifndef RELOC_PROCESSING
  4636. asymbol *ptr;
  4637. #endif
  4638. cache_ptr = reloc_cache + idx;
  4639. src = native_relocs + idx;
  4640. dst.r_offset = 0;
  4641. coff_swap_reloc_in (abfd, src, &dst);
  4642. #ifdef RELOC_PROCESSING
  4643. RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
  4644. #else
  4645. cache_ptr->address = dst.r_vaddr;
  4646. if (dst.r_symndx != -1)
  4647. {
  4648. if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
  4649. {
  4650. (*_bfd_error_handler)
  4651. (_("%B: warning: illegal symbol index %ld in relocs"),
  4652. abfd, (long) dst.r_symndx);
  4653. cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
  4654. ptr = NULL;
  4655. }
  4656. else
  4657. {
  4658. cache_ptr->sym_ptr_ptr = (symbols
  4659. + obj_convert (abfd)[dst.r_symndx]);
  4660. ptr = *(cache_ptr->sym_ptr_ptr);
  4661. }
  4662. }
  4663. else
  4664. {
  4665. cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
  4666. ptr = NULL;
  4667. }
  4668. /* The symbols definitions that we have read in have been
  4669. relocated as if their sections started at 0. But the offsets
  4670. refering to the symbols in the raw data have not been
  4671. modified, so we have to have a negative addend to compensate.
  4672. Note that symbols which used to be common must be left alone. */
  4673. /* Calculate any reloc addend by looking at the symbol. */
  4674. CALC_ADDEND (abfd, ptr, dst, cache_ptr);
  4675. (void) ptr;
  4676. cache_ptr->address -= asect->vma;
  4677. /* !! cache_ptr->section = NULL;*/
  4678. /* Fill in the cache_ptr->howto field from dst.r_type. */
  4679. RTYPE2HOWTO (cache_ptr, &dst);
  4680. #endif /* RELOC_PROCESSING */
  4681. if (cache_ptr->howto == NULL)
  4682. {
  4683. (*_bfd_error_handler)
  4684. (_("%B: illegal relocation type %d at address 0x%lx"),
  4685. abfd, dst.r_type, (long) dst.r_vaddr);
  4686. bfd_set_error (bfd_error_bad_value);
  4687. return FALSE;
  4688. }
  4689. }
  4690. asect->relocation = reloc_cache;
  4691. return TRUE;
  4692. }
  4693. #ifndef coff_rtype_to_howto
  4694. #ifdef RTYPE2HOWTO
  4695. /* Get the howto structure for a reloc. This is only used if the file
  4696. including this one defines coff_relocate_section to be
  4697. _bfd_coff_generic_relocate_section, so it is OK if it does not
  4698. always work. It is the responsibility of the including file to
  4699. make sure it is reasonable if it is needed. */
  4700. static reloc_howto_type *
  4701. coff_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
  4702. asection *sec ATTRIBUTE_UNUSED,
  4703. struct internal_reloc *rel ATTRIBUTE_UNUSED,
  4704. struct coff_link_hash_entry *h ATTRIBUTE_UNUSED,
  4705. struct internal_syment *sym ATTRIBUTE_UNUSED,
  4706. bfd_vma *addendp ATTRIBUTE_UNUSED)
  4707. {
  4708. arelent genrel;
  4709. genrel.howto = NULL;
  4710. RTYPE2HOWTO (&genrel, rel);
  4711. return genrel.howto;
  4712. }
  4713. #else /* ! defined (RTYPE2HOWTO) */
  4714. #define coff_rtype_to_howto NULL
  4715. #endif /* ! defined (RTYPE2HOWTO) */
  4716. #endif /* ! defined (coff_rtype_to_howto) */
  4717. /* This is stupid. This function should be a boolean predicate. */
  4718. static long
  4719. coff_canonicalize_reloc (bfd * abfd,
  4720. sec_ptr section,
  4721. arelent ** relptr,
  4722. asymbol ** symbols)
  4723. {
  4724. arelent *tblptr = section->relocation;
  4725. unsigned int count = 0;
  4726. if (section->flags & SEC_CONSTRUCTOR)
  4727. {
  4728. /* This section has relocs made up by us, they are not in the
  4729. file, so take them out of their chain and place them into
  4730. the data area provided. */
  4731. arelent_chain *chain = section->constructor_chain;
  4732. for (count = 0; count < section->reloc_count; count++)
  4733. {
  4734. *relptr++ = &chain->relent;
  4735. chain = chain->next;
  4736. }
  4737. }
  4738. else
  4739. {
  4740. if (! coff_slurp_reloc_table (abfd, section, symbols))
  4741. return -1;
  4742. tblptr = section->relocation;
  4743. for (; count++ < section->reloc_count;)
  4744. *relptr++ = tblptr++;
  4745. }
  4746. *relptr = 0;
  4747. return section->reloc_count;
  4748. }
  4749. #ifndef coff_reloc16_estimate
  4750. #define coff_reloc16_estimate dummy_reloc16_estimate
  4751. static int
  4752. dummy_reloc16_estimate (bfd *abfd ATTRIBUTE_UNUSED,
  4753. asection *input_section ATTRIBUTE_UNUSED,
  4754. arelent *reloc ATTRIBUTE_UNUSED,
  4755. unsigned int shrink ATTRIBUTE_UNUSED,
  4756. struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
  4757. {
  4758. abort ();
  4759. return 0;
  4760. }
  4761. #endif
  4762. #ifndef coff_reloc16_extra_cases
  4763. #define coff_reloc16_extra_cases dummy_reloc16_extra_cases
  4764. /* This works even if abort is not declared in any header file. */
  4765. static void
  4766. dummy_reloc16_extra_cases (bfd *abfd ATTRIBUTE_UNUSED,
  4767. struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
  4768. struct bfd_link_order *link_order ATTRIBUTE_UNUSED,
  4769. arelent *reloc ATTRIBUTE_UNUSED,
  4770. bfd_byte *data ATTRIBUTE_UNUSED,
  4771. unsigned int *src_ptr ATTRIBUTE_UNUSED,
  4772. unsigned int *dst_ptr ATTRIBUTE_UNUSED)
  4773. {
  4774. abort ();
  4775. }
  4776. #endif
  4777. /* If coff_relocate_section is defined, we can use the optimized COFF
  4778. backend linker. Otherwise we must continue to use the old linker. */
  4779. #ifdef coff_relocate_section
  4780. #ifndef coff_bfd_link_hash_table_create
  4781. #define coff_bfd_link_hash_table_create _bfd_coff_link_hash_table_create
  4782. #endif
  4783. #ifndef coff_bfd_link_add_symbols
  4784. #define coff_bfd_link_add_symbols _bfd_coff_link_add_symbols
  4785. #endif
  4786. #ifndef coff_bfd_final_link
  4787. #define coff_bfd_final_link _bfd_coff_final_link
  4788. #endif
  4789. #else /* ! defined (coff_relocate_section) */
  4790. #define coff_relocate_section NULL
  4791. #ifndef coff_bfd_link_hash_table_create
  4792. #define coff_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
  4793. #endif
  4794. #ifndef coff_bfd_link_add_symbols
  4795. #define coff_bfd_link_add_symbols _bfd_generic_link_add_symbols
  4796. #endif
  4797. #define coff_bfd_final_link _bfd_generic_final_link
  4798. #endif /* ! defined (coff_relocate_section) */
  4799. #define coff_bfd_link_just_syms _bfd_generic_link_just_syms
  4800. #define coff_bfd_copy_link_hash_symbol_type \
  4801. _bfd_generic_copy_link_hash_symbol_type
  4802. #define coff_bfd_link_split_section _bfd_generic_link_split_section
  4803. #ifndef coff_start_final_link
  4804. #define coff_start_final_link NULL
  4805. #endif
  4806. #ifndef coff_adjust_symndx
  4807. #define coff_adjust_symndx NULL
  4808. #endif
  4809. #ifndef coff_link_add_one_symbol
  4810. #define coff_link_add_one_symbol _bfd_generic_link_add_one_symbol
  4811. #endif
  4812. #ifndef coff_link_output_has_begun
  4813. static bfd_boolean
  4814. coff_link_output_has_begun (bfd * abfd,
  4815. struct coff_final_link_info * info ATTRIBUTE_UNUSED)
  4816. {
  4817. return abfd->output_has_begun;
  4818. }
  4819. #endif
  4820. #ifndef coff_final_link_postscript
  4821. static bfd_boolean
  4822. coff_final_link_postscript (bfd * abfd ATTRIBUTE_UNUSED,
  4823. struct coff_final_link_info * pfinfo ATTRIBUTE_UNUSED)
  4824. {
  4825. return TRUE;
  4826. }
  4827. #endif
  4828. #ifndef coff_SWAP_aux_in
  4829. #define coff_SWAP_aux_in coff_swap_aux_in
  4830. #endif
  4831. #ifndef coff_SWAP_sym_in
  4832. #define coff_SWAP_sym_in coff_swap_sym_in
  4833. #endif
  4834. #ifndef coff_SWAP_lineno_in
  4835. #define coff_SWAP_lineno_in coff_swap_lineno_in
  4836. #endif
  4837. #ifndef coff_SWAP_aux_out
  4838. #define coff_SWAP_aux_out coff_swap_aux_out
  4839. #endif
  4840. #ifndef coff_SWAP_sym_out
  4841. #define coff_SWAP_sym_out coff_swap_sym_out
  4842. #endif
  4843. #ifndef coff_SWAP_lineno_out
  4844. #define coff_SWAP_lineno_out coff_swap_lineno_out
  4845. #endif
  4846. #ifndef coff_SWAP_reloc_out
  4847. #define coff_SWAP_reloc_out coff_swap_reloc_out
  4848. #endif
  4849. #ifndef coff_SWAP_filehdr_out
  4850. #define coff_SWAP_filehdr_out coff_swap_filehdr_out
  4851. #endif
  4852. #ifndef coff_SWAP_aouthdr_out
  4853. #define coff_SWAP_aouthdr_out coff_swap_aouthdr_out
  4854. #endif
  4855. #ifndef coff_SWAP_scnhdr_out
  4856. #define coff_SWAP_scnhdr_out coff_swap_scnhdr_out
  4857. #endif
  4858. #ifndef coff_SWAP_reloc_in
  4859. #define coff_SWAP_reloc_in coff_swap_reloc_in
  4860. #endif
  4861. #ifndef coff_SWAP_filehdr_in
  4862. #define coff_SWAP_filehdr_in coff_swap_filehdr_in
  4863. #endif
  4864. #ifndef coff_SWAP_aouthdr_in
  4865. #define coff_SWAP_aouthdr_in coff_swap_aouthdr_in
  4866. #endif
  4867. #ifndef coff_SWAP_scnhdr_in
  4868. #define coff_SWAP_scnhdr_in coff_swap_scnhdr_in
  4869. #endif
  4870. static bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED =
  4871. {
  4872. coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
  4873. coff_SWAP_aux_out, coff_SWAP_sym_out,
  4874. coff_SWAP_lineno_out, coff_SWAP_reloc_out,
  4875. coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
  4876. coff_SWAP_scnhdr_out,
  4877. FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
  4878. #ifdef COFF_LONG_FILENAMES
  4879. TRUE,
  4880. #else
  4881. FALSE,
  4882. #endif
  4883. COFF_DEFAULT_LONG_SECTION_NAMES,
  4884. COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
  4885. #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
  4886. TRUE,
  4887. #else
  4888. FALSE,
  4889. #endif
  4890. #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
  4891. 4,
  4892. #else
  4893. 2,
  4894. #endif
  4895. 32768,
  4896. coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
  4897. coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
  4898. coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
  4899. coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
  4900. coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
  4901. coff_classify_symbol, coff_compute_section_file_positions,
  4902. coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
  4903. coff_adjust_symndx, coff_link_add_one_symbol,
  4904. coff_link_output_has_begun, coff_final_link_postscript,
  4905. bfd_pe_print_pdata
  4906. };
  4907. #ifdef TICOFF
  4908. /* COFF0 differs in file/section header size and relocation entry size. */
  4909. static bfd_coff_backend_data ticoff0_swap_table =
  4910. {
  4911. coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
  4912. coff_SWAP_aux_out, coff_SWAP_sym_out,
  4913. coff_SWAP_lineno_out, coff_SWAP_reloc_out,
  4914. coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
  4915. coff_SWAP_scnhdr_out,
  4916. FILHSZ_V0, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ_V0, LINESZ, FILNMLEN,
  4917. #ifdef COFF_LONG_FILENAMES
  4918. TRUE,
  4919. #else
  4920. FALSE,
  4921. #endif
  4922. COFF_DEFAULT_LONG_SECTION_NAMES,
  4923. COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
  4924. #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
  4925. TRUE,
  4926. #else
  4927. FALSE,
  4928. #endif
  4929. #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
  4930. 4,
  4931. #else
  4932. 2,
  4933. #endif
  4934. 32768,
  4935. coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
  4936. coff_SWAP_reloc_in, ticoff0_bad_format_hook, coff_set_arch_mach_hook,
  4937. coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
  4938. coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
  4939. coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
  4940. coff_classify_symbol, coff_compute_section_file_positions,
  4941. coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
  4942. coff_adjust_symndx, coff_link_add_one_symbol,
  4943. coff_link_output_has_begun, coff_final_link_postscript,
  4944. bfd_pe_print_pdata
  4945. };
  4946. #endif
  4947. #ifdef TICOFF
  4948. /* COFF1 differs in section header size. */
  4949. static bfd_coff_backend_data ticoff1_swap_table =
  4950. {
  4951. coff_SWAP_aux_in, coff_SWAP_sym_in, coff_SWAP_lineno_in,
  4952. coff_SWAP_aux_out, coff_SWAP_sym_out,
  4953. coff_SWAP_lineno_out, coff_SWAP_reloc_out,
  4954. coff_SWAP_filehdr_out, coff_SWAP_aouthdr_out,
  4955. coff_SWAP_scnhdr_out,
  4956. FILHSZ, AOUTSZ, SCNHSZ_V01, SYMESZ, AUXESZ, RELSZ, LINESZ, FILNMLEN,
  4957. #ifdef COFF_LONG_FILENAMES
  4958. TRUE,
  4959. #else
  4960. FALSE,
  4961. #endif
  4962. COFF_DEFAULT_LONG_SECTION_NAMES,
  4963. COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
  4964. #ifdef COFF_FORCE_SYMBOLS_IN_STRINGS
  4965. TRUE,
  4966. #else
  4967. FALSE,
  4968. #endif
  4969. #ifdef COFF_DEBUG_STRING_WIDE_PREFIX
  4970. 4,
  4971. #else
  4972. 2,
  4973. #endif
  4974. 32768,
  4975. coff_SWAP_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
  4976. coff_SWAP_reloc_in, ticoff1_bad_format_hook, coff_set_arch_mach_hook,
  4977. coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
  4978. coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
  4979. coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
  4980. coff_classify_symbol, coff_compute_section_file_positions,
  4981. coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
  4982. coff_adjust_symndx, coff_link_add_one_symbol,
  4983. coff_link_output_has_begun, coff_final_link_postscript,
  4984. bfd_pe_print_pdata /* huh */
  4985. };
  4986. #endif
  4987. #ifdef COFF_WITH_PE_BIGOBJ
  4988. /* The UID for bigobj files. */
  4989. static const char header_bigobj_classid[16] =
  4990. {
  4991. 0xC7, 0xA1, 0xBA, 0xD1,
  4992. 0xEE, 0xBA,
  4993. 0xa9, 0x4b,
  4994. 0xAF, 0x20,
  4995. 0xFA, 0xF6, 0x6A, 0xA4, 0xDC, 0xB8
  4996. };
  4997. /* Swap routines. */
  4998. static void
  4999. coff_bigobj_swap_filehdr_in (bfd * abfd, void * src, void * dst)
  5000. {
  5001. struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_src =
  5002. (struct external_ANON_OBJECT_HEADER_BIGOBJ *) src;
  5003. struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
  5004. filehdr_dst->f_magic = H_GET_16 (abfd, filehdr_src->Machine);
  5005. filehdr_dst->f_nscns = H_GET_32 (abfd, filehdr_src->NumberOfSections);
  5006. filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->TimeDateStamp);
  5007. filehdr_dst->f_symptr =
  5008. GET_FILEHDR_SYMPTR (abfd, filehdr_src->PointerToSymbolTable);
  5009. filehdr_dst->f_nsyms = H_GET_32 (abfd, filehdr_src->NumberOfSymbols);
  5010. filehdr_dst->f_opthdr = 0;
  5011. filehdr_dst->f_flags = 0;
  5012. /* Check other magic numbers. */
  5013. if (H_GET_16 (abfd, filehdr_src->Sig1) != IMAGE_FILE_MACHINE_UNKNOWN
  5014. || H_GET_16 (abfd, filehdr_src->Sig2) != 0xffff
  5015. || H_GET_16 (abfd, filehdr_src->Version) != 2
  5016. || memcmp (filehdr_src->ClassID, header_bigobj_classid, 16) != 0)
  5017. filehdr_dst->f_opthdr = 0xffff;
  5018. /* Note that CLR metadata are ignored. */
  5019. }
  5020. static unsigned int
  5021. coff_bigobj_swap_filehdr_out (bfd *abfd, void * in, void * out)
  5022. {
  5023. struct internal_filehdr *filehdr_in = (struct internal_filehdr *) in;
  5024. struct external_ANON_OBJECT_HEADER_BIGOBJ *filehdr_out =
  5025. (struct external_ANON_OBJECT_HEADER_BIGOBJ *) out;
  5026. memset (filehdr_out, 0, sizeof (*filehdr_out));
  5027. H_PUT_16 (abfd, IMAGE_FILE_MACHINE_UNKNOWN, filehdr_out->Sig1);
  5028. H_PUT_16 (abfd, 0xffff, filehdr_out->Sig2);
  5029. H_PUT_16 (abfd, 2, filehdr_out->Version);
  5030. memcpy (filehdr_out->ClassID, header_bigobj_classid, 16);
  5031. H_PUT_16 (abfd, filehdr_in->f_magic, filehdr_out->Machine);
  5032. H_PUT_32 (abfd, filehdr_in->f_nscns, filehdr_out->NumberOfSections);
  5033. H_PUT_32 (abfd, filehdr_in->f_timdat, filehdr_out->TimeDateStamp);
  5034. PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,
  5035. filehdr_out->PointerToSymbolTable);
  5036. H_PUT_32 (abfd, filehdr_in->f_nsyms, filehdr_out->NumberOfSymbols);
  5037. return bfd_coff_filhsz (abfd);
  5038. }
  5039. static void
  5040. coff_bigobj_swap_sym_in (bfd * abfd, void * ext1, void * in1)
  5041. {
  5042. SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) ext1;
  5043. struct internal_syment *in = (struct internal_syment *) in1;
  5044. if (ext->e.e_name[0] == 0)
  5045. {
  5046. in->_n._n_n._n_zeroes = 0;
  5047. in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
  5048. }
  5049. else
  5050. {
  5051. #if SYMNMLEN != E_SYMNMLEN
  5052. #error we need to cope with truncating or extending SYMNMLEN
  5053. #else
  5054. memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
  5055. #endif
  5056. }
  5057. in->n_value = H_GET_32 (abfd, ext->e_value);
  5058. in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
  5059. in->n_type = H_GET_16 (abfd, ext->e_type);
  5060. in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
  5061. in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
  5062. }
  5063. static unsigned int
  5064. coff_bigobj_swap_sym_out (bfd * abfd, void * inp, void * extp)
  5065. {
  5066. struct internal_syment *in = (struct internal_syment *) inp;
  5067. SYMENT_BIGOBJ *ext = (SYMENT_BIGOBJ *) extp;
  5068. if (in->_n._n_name[0] == 0)
  5069. {
  5070. H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
  5071. H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
  5072. }
  5073. else
  5074. {
  5075. #if SYMNMLEN != E_SYMNMLEN
  5076. #error we need to cope with truncating or extending SYMNMLEN
  5077. #else
  5078. memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
  5079. #endif
  5080. }
  5081. H_PUT_32 (abfd, in->n_value, ext->e_value);
  5082. H_PUT_32 (abfd, in->n_scnum, ext->e_scnum);
  5083. H_PUT_16 (abfd, in->n_type, ext->e_type);
  5084. H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
  5085. H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
  5086. return SYMESZ_BIGOBJ;
  5087. }
  5088. static void
  5089. coff_bigobj_swap_aux_in (bfd *abfd,
  5090. void * ext1,
  5091. int type,
  5092. int in_class,
  5093. int indx,
  5094. int numaux,
  5095. void * in1)
  5096. {
  5097. AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) ext1;
  5098. union internal_auxent *in = (union internal_auxent *) in1;
  5099. switch (in_class)
  5100. {
  5101. case C_FILE:
  5102. if (numaux > 1)
  5103. {
  5104. if (indx == 0)
  5105. memcpy (in->x_file.x_fname, ext->File.Name,
  5106. numaux * sizeof (AUXENT_BIGOBJ));
  5107. }
  5108. else
  5109. memcpy (in->x_file.x_fname, ext->File.Name, sizeof (ext->File.Name));
  5110. break;
  5111. case C_STAT:
  5112. case C_LEAFSTAT:
  5113. case C_HIDDEN:
  5114. if (type == T_NULL)
  5115. {
  5116. in->x_scn.x_scnlen = H_GET_32 (abfd, ext->Section.Length);
  5117. in->x_scn.x_nreloc =
  5118. H_GET_16 (abfd, ext->Section.NumberOfRelocations);
  5119. in->x_scn.x_nlinno =
  5120. H_GET_16 (abfd, ext->Section.NumberOfLinenumbers);
  5121. in->x_scn.x_checksum = H_GET_32 (abfd, ext->Section.Checksum);
  5122. in->x_scn.x_associated = H_GET_16 (abfd, ext->Section.Number)
  5123. | (H_GET_16 (abfd, ext->Section.HighNumber) << 16);
  5124. in->x_scn.x_comdat = H_GET_8 (abfd, ext->Section.Selection);
  5125. return;
  5126. }
  5127. break;
  5128. default:
  5129. in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->Sym.WeakDefaultSymIndex);
  5130. /* Characteristics is ignored. */
  5131. break;
  5132. }
  5133. }
  5134. static unsigned int
  5135. coff_bigobj_swap_aux_out (bfd * abfd,
  5136. void * inp,
  5137. int type,
  5138. int in_class,
  5139. int indx ATTRIBUTE_UNUSED,
  5140. int numaux ATTRIBUTE_UNUSED,
  5141. void * extp)
  5142. {
  5143. union internal_auxent * in = (union internal_auxent *) inp;
  5144. AUXENT_BIGOBJ *ext = (AUXENT_BIGOBJ *) extp;
  5145. memset (ext, 0, AUXESZ);
  5146. switch (in_class)
  5147. {
  5148. case C_FILE:
  5149. memcpy (ext->File.Name, in->x_file.x_fname, sizeof (ext->File.Name));
  5150. return AUXESZ;
  5151. case C_STAT:
  5152. case C_LEAFSTAT:
  5153. case C_HIDDEN:
  5154. if (type == T_NULL)
  5155. {
  5156. H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->Section.Length);
  5157. H_PUT_16 (abfd, in->x_scn.x_nreloc,
  5158. ext->Section.NumberOfRelocations);
  5159. H_PUT_16 (abfd, in->x_scn.x_nlinno,
  5160. ext->Section.NumberOfLinenumbers);
  5161. H_PUT_32 (abfd, in->x_scn.x_checksum, ext->Section.Checksum);
  5162. H_PUT_16 (abfd, in->x_scn.x_associated & 0xffff,
  5163. ext->Section.Number);
  5164. H_PUT_16 (abfd, (in->x_scn.x_associated >> 16),
  5165. ext->Section.HighNumber);
  5166. H_PUT_8 (abfd, in->x_scn.x_comdat, ext->Section.Selection);
  5167. return AUXESZ;
  5168. }
  5169. break;
  5170. }
  5171. H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->Sym.WeakDefaultSymIndex);
  5172. H_PUT_32 (abfd, 1, ext->Sym.WeakSearchType);
  5173. return AUXESZ;
  5174. }
  5175. static bfd_coff_backend_data bigobj_swap_table =
  5176. {
  5177. coff_bigobj_swap_aux_in, coff_bigobj_swap_sym_in, coff_SWAP_lineno_in,
  5178. coff_bigobj_swap_aux_out, coff_bigobj_swap_sym_out,
  5179. coff_SWAP_lineno_out, coff_SWAP_reloc_out,
  5180. coff_bigobj_swap_filehdr_out, coff_SWAP_aouthdr_out,
  5181. coff_SWAP_scnhdr_out,
  5182. FILHSZ_BIGOBJ, AOUTSZ, SCNHSZ, SYMESZ_BIGOBJ, AUXESZ_BIGOBJ,
  5183. RELSZ, LINESZ, FILNMLEN_BIGOBJ,
  5184. TRUE,
  5185. COFF_DEFAULT_LONG_SECTION_NAMES,
  5186. COFF_DEFAULT_SECTION_ALIGNMENT_POWER,
  5187. FALSE,
  5188. 2,
  5189. 1U << 31,
  5190. coff_bigobj_swap_filehdr_in, coff_SWAP_aouthdr_in, coff_SWAP_scnhdr_in,
  5191. coff_SWAP_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook,
  5192. coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook,
  5193. coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook,
  5194. coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate,
  5195. coff_classify_symbol, coff_compute_section_file_positions,
  5196. coff_start_final_link, coff_relocate_section, coff_rtype_to_howto,
  5197. coff_adjust_symndx, coff_link_add_one_symbol,
  5198. coff_link_output_has_begun, coff_final_link_postscript,
  5199. bfd_pe_print_pdata /* huh */
  5200. };
  5201. #endif /* COFF_WITH_PE_BIGOBJ */
  5202. #ifndef coff_close_and_cleanup
  5203. #define coff_close_and_cleanup _bfd_generic_close_and_cleanup
  5204. #endif
  5205. #ifndef coff_bfd_free_cached_info
  5206. #define coff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
  5207. #endif
  5208. #ifndef coff_get_section_contents
  5209. #define coff_get_section_contents _bfd_generic_get_section_contents
  5210. #endif
  5211. #ifndef coff_bfd_copy_private_symbol_data
  5212. #define coff_bfd_copy_private_symbol_data _bfd_generic_bfd_copy_private_symbol_data
  5213. #endif
  5214. #ifndef coff_bfd_copy_private_header_data
  5215. #define coff_bfd_copy_private_header_data _bfd_generic_bfd_copy_private_header_data
  5216. #endif
  5217. #ifndef coff_bfd_copy_private_section_data
  5218. #define coff_bfd_copy_private_section_data _bfd_generic_bfd_copy_private_section_data
  5219. #endif
  5220. #ifndef coff_bfd_copy_private_bfd_data
  5221. #define coff_bfd_copy_private_bfd_data _bfd_generic_bfd_copy_private_bfd_data
  5222. #endif
  5223. #ifndef coff_bfd_merge_private_bfd_data
  5224. #define coff_bfd_merge_private_bfd_data _bfd_generic_bfd_merge_private_bfd_data
  5225. #endif
  5226. #ifndef coff_bfd_set_private_flags
  5227. #define coff_bfd_set_private_flags _bfd_generic_bfd_set_private_flags
  5228. #endif
  5229. #ifndef coff_bfd_print_private_bfd_data
  5230. #define coff_bfd_print_private_bfd_data _bfd_generic_bfd_print_private_bfd_data
  5231. #endif
  5232. #ifndef coff_bfd_is_local_label_name
  5233. #define coff_bfd_is_local_label_name _bfd_coff_is_local_label_name
  5234. #endif
  5235. #ifndef coff_bfd_is_target_special_symbol
  5236. #define coff_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
  5237. #endif
  5238. #ifndef coff_read_minisymbols
  5239. #define coff_read_minisymbols _bfd_generic_read_minisymbols
  5240. #endif
  5241. #ifndef coff_minisymbol_to_symbol
  5242. #define coff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
  5243. #endif
  5244. /* The reloc lookup routine must be supplied by each individual COFF
  5245. backend. */
  5246. #ifndef coff_bfd_reloc_type_lookup
  5247. #define coff_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
  5248. #endif
  5249. #ifndef coff_bfd_reloc_name_lookup
  5250. #define coff_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
  5251. #endif
  5252. #ifndef coff_bfd_get_relocated_section_contents
  5253. #define coff_bfd_get_relocated_section_contents \
  5254. bfd_generic_get_relocated_section_contents
  5255. #endif
  5256. #ifndef coff_bfd_relax_section
  5257. #define coff_bfd_relax_section bfd_generic_relax_section
  5258. #endif
  5259. #ifndef coff_bfd_gc_sections
  5260. #define coff_bfd_gc_sections bfd_coff_gc_sections
  5261. #endif
  5262. #ifndef coff_bfd_lookup_section_flags
  5263. #define coff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
  5264. #endif
  5265. #ifndef coff_bfd_merge_sections
  5266. #define coff_bfd_merge_sections bfd_generic_merge_sections
  5267. #endif
  5268. #ifndef coff_bfd_is_group_section
  5269. #define coff_bfd_is_group_section bfd_generic_is_group_section
  5270. #endif
  5271. #ifndef coff_bfd_discard_group
  5272. #define coff_bfd_discard_group bfd_generic_discard_group
  5273. #endif
  5274. #ifndef coff_section_already_linked
  5275. #define coff_section_already_linked \
  5276. _bfd_coff_section_already_linked
  5277. #endif
  5278. #ifndef coff_bfd_define_common_symbol
  5279. #define coff_bfd_define_common_symbol bfd_generic_define_common_symbol
  5280. #endif
  5281. #define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
  5282. const bfd_target VAR = \
  5283. { \
  5284. NAME , \
  5285. bfd_target_coff_flavour, \
  5286. BFD_ENDIAN_BIG, /* Data byte order is big. */ \
  5287. BFD_ENDIAN_BIG, /* Header byte order is big. */ \
  5288. /* object flags */ \
  5289. (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
  5290. HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
  5291. /* section flags */ \
  5292. (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
  5293. UNDER, /* Leading symbol underscore. */ \
  5294. '/', /* AR_pad_char. */ \
  5295. 15, /* AR_max_namelen. */ \
  5296. 0, /* match priority. */ \
  5297. \
  5298. /* Data conversion functions. */ \
  5299. bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
  5300. bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
  5301. bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
  5302. \
  5303. /* Header conversion functions. */ \
  5304. bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
  5305. bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
  5306. bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
  5307. \
  5308. /* bfd_check_format. */ \
  5309. { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, \
  5310. _bfd_dummy_target }, \
  5311. /* bfd_set_format. */ \
  5312. { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \
  5313. /* bfd_write_contents. */ \
  5314. { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, \
  5315. bfd_false }, \
  5316. \
  5317. BFD_JUMP_TABLE_GENERIC (coff), \
  5318. BFD_JUMP_TABLE_COPY (coff), \
  5319. BFD_JUMP_TABLE_CORE (_bfd_nocore), \
  5320. BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
  5321. BFD_JUMP_TABLE_SYMBOLS (coff), \
  5322. BFD_JUMP_TABLE_RELOCS (coff), \
  5323. BFD_JUMP_TABLE_WRITE (coff), \
  5324. BFD_JUMP_TABLE_LINK (coff), \
  5325. BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
  5326. \
  5327. ALTERNATIVE, \
  5328. \
  5329. SWAP_TABLE \
  5330. };
  5331. #define CREATE_BIGHDR_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
  5332. const bfd_target VAR = \
  5333. { \
  5334. NAME , \
  5335. bfd_target_coff_flavour, \
  5336. BFD_ENDIAN_LITTLE, /* Data byte order is little. */ \
  5337. BFD_ENDIAN_BIG, /* Header byte order is big. */ \
  5338. /* object flags */ \
  5339. (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
  5340. HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
  5341. /* section flags */ \
  5342. (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
  5343. UNDER, /* Leading symbol underscore. */ \
  5344. '/', /* AR_pad_char. */ \
  5345. 15, /* AR_max_namelen. */ \
  5346. 0, /* match priority. */ \
  5347. \
  5348. /* Data conversion functions. */ \
  5349. bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
  5350. bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
  5351. bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
  5352. \
  5353. /* Header conversion functions. */ \
  5354. bfd_getb64, bfd_getb_signed_64, bfd_putb64, \
  5355. bfd_getb32, bfd_getb_signed_32, bfd_putb32, \
  5356. bfd_getb16, bfd_getb_signed_16, bfd_putb16, \
  5357. \
  5358. /* bfd_check_format. */ \
  5359. { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, \
  5360. _bfd_dummy_target }, \
  5361. /* bfd_set_format. */ \
  5362. { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \
  5363. /* bfd_write_contents. */ \
  5364. { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, \
  5365. bfd_false }, \
  5366. \
  5367. BFD_JUMP_TABLE_GENERIC (coff), \
  5368. BFD_JUMP_TABLE_COPY (coff), \
  5369. BFD_JUMP_TABLE_CORE (_bfd_nocore), \
  5370. BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
  5371. BFD_JUMP_TABLE_SYMBOLS (coff), \
  5372. BFD_JUMP_TABLE_RELOCS (coff), \
  5373. BFD_JUMP_TABLE_WRITE (coff), \
  5374. BFD_JUMP_TABLE_LINK (coff), \
  5375. BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
  5376. \
  5377. ALTERNATIVE, \
  5378. \
  5379. SWAP_TABLE \
  5380. };
  5381. #define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE) \
  5382. const bfd_target VAR = \
  5383. { \
  5384. NAME , \
  5385. bfd_target_coff_flavour, \
  5386. BFD_ENDIAN_LITTLE, /* Data byte order is little. */ \
  5387. BFD_ENDIAN_LITTLE, /* Header byte order is little. */ \
  5388. /* object flags */ \
  5389. (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | \
  5390. HAS_SYMS | HAS_LOCALS | WP_TEXT | EXTRA_O_FLAGS), \
  5391. /* section flags */ \
  5392. (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | EXTRA_S_FLAGS),\
  5393. UNDER, /* Leading symbol underscore. */ \
  5394. '/', /* AR_pad_char. */ \
  5395. 15, /* AR_max_namelen. */ \
  5396. 0, /* match priority. */ \
  5397. \
  5398. /* Data conversion functions. */ \
  5399. bfd_getl64, bfd_getl_signed_64, bfd_putl64, \
  5400. bfd_getl32, bfd_getl_signed_32, bfd_putl32, \
  5401. bfd_getl16, bfd_getl_signed_16, bfd_putl16, \
  5402. /* Header conversion functions. */ \
  5403. bfd_getl64, bfd_getl_signed_64, bfd_putl64, \
  5404. bfd_getl32, bfd_getl_signed_32, bfd_putl32, \
  5405. bfd_getl16, bfd_getl_signed_16, bfd_putl16, \
  5406. /* bfd_check_format. */ \
  5407. { _bfd_dummy_target, coff_object_p, bfd_generic_archive_p, \
  5408. _bfd_dummy_target }, \
  5409. /* bfd_set_format. */ \
  5410. { bfd_false, coff_mkobject, _bfd_generic_mkarchive, bfd_false }, \
  5411. /* bfd_write_contents. */ \
  5412. { bfd_false, coff_write_object_contents, _bfd_write_archive_contents, \
  5413. bfd_false }, \
  5414. \
  5415. BFD_JUMP_TABLE_GENERIC (coff), \
  5416. BFD_JUMP_TABLE_COPY (coff), \
  5417. BFD_JUMP_TABLE_CORE (_bfd_nocore), \
  5418. BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), \
  5419. BFD_JUMP_TABLE_SYMBOLS (coff), \
  5420. BFD_JUMP_TABLE_RELOCS (coff), \
  5421. BFD_JUMP_TABLE_WRITE (coff), \
  5422. BFD_JUMP_TABLE_LINK (coff), \
  5423. BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), \
  5424. \
  5425. ALTERNATIVE, \
  5426. \
  5427. SWAP_TABLE \
  5428. };