ecoff.c 147 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233
  1. /* ECOFF debugging support.
  2. Copyright (C) 1993-2015 Free Software Foundation, Inc.
  3. Contributed by Cygnus Support.
  4. This file was put together by Ian Lance Taylor <ian@cygnus.com>. A
  5. good deal of it comes directly from mips-tfile.c, by Michael
  6. Meissner <meissner@osf.org>.
  7. This file is part of GAS.
  8. GAS is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 3, or (at your option)
  11. any later version.
  12. GAS is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with GAS; see the file COPYING. If not, write to the Free
  18. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  19. 02110-1301, USA. */
  20. #include "as.h"
  21. /* This file is compiled conditionally for those targets which use
  22. ECOFF debugging information (e.g., MIPS ELF, Alpha ECOFF). */
  23. #include "ecoff.h"
  24. #ifdef ECOFF_DEBUGGING
  25. #include "coff/internal.h"
  26. #include "coff/symconst.h"
  27. #include "aout/stab_gnu.h"
  28. #include "filenames.h"
  29. #include "safe-ctype.h"
  30. /* Why isn't this in coff/sym.h? */
  31. #define ST_RFDESCAPE 0xfff
  32. /* This file constructs the information used by the ECOFF debugging
  33. format. It just builds a large block of data.
  34. We support both ECOFF style debugging and stabs debugging (the
  35. stabs symbols are encapsulated in ECOFF symbols). This should let
  36. us handle anything the compiler might throw at us. */
  37. /* Here is a brief description of the MIPS ECOFF symbol table, by
  38. Michael Meissner. The MIPS symbol table has the following pieces:
  39. Symbolic Header
  40. |
  41. +-- Auxiliary Symbols
  42. |
  43. +-- Dense number table
  44. |
  45. +-- Optimizer Symbols
  46. |
  47. +-- External Strings
  48. |
  49. +-- External Symbols
  50. |
  51. +-- Relative file descriptors
  52. |
  53. +-- File table
  54. |
  55. +-- Procedure table
  56. |
  57. +-- Line number table
  58. |
  59. +-- Local Strings
  60. |
  61. +-- Local Symbols
  62. The symbolic header points to each of the other tables, and also
  63. contains the number of entries. It also contains a magic number
  64. and MIPS compiler version number, such as 2.0.
  65. The auxiliary table is a series of 32 bit integers, that are
  66. referenced as needed from the local symbol table. Unlike standard
  67. COFF, the aux. information does not follow the symbol that uses
  68. it, but rather is a separate table. In theory, this would allow
  69. the MIPS compilers to collapse duplicate aux. entries, but I've not
  70. noticed this happening with the 1.31 compiler suite. The different
  71. types of aux. entries are:
  72. 1) dnLow: Low bound on array dimension.
  73. 2) dnHigh: High bound on array dimension.
  74. 3) isym: Index to the local symbol which is the start of the
  75. function for the end of function first aux. entry.
  76. 4) width: Width of structures and bitfields.
  77. 5) count: Count of ranges for variant part.
  78. 6) rndx: A relative index into the symbol table. The relative
  79. index field has two parts: rfd which is a pointer into the
  80. relative file index table or ST_RFDESCAPE which says the next
  81. aux. entry is the file number, and index: which is the pointer
  82. into the local symbol within a given file table. This is for
  83. things like references to types defined in another file.
  84. 7) Type information: This is like the COFF type bits, except it
  85. is 32 bits instead of 16; they still have room to add new
  86. basic types; and they can handle more than 6 levels of array,
  87. pointer, function, etc. Each type information field contains
  88. the following structure members:
  89. a) fBitfield: a bit that says this is a bitfield, and the
  90. size in bits follows as the next aux. entry.
  91. b) continued: a bit that says the next aux. entry is a
  92. continuation of the current type information (in case
  93. there are more than 6 levels of array/ptr/function).
  94. c) bt: an integer containing the base type before adding
  95. array, pointer, function, etc. qualifiers. The
  96. current base types that I have documentation for are:
  97. btNil -- undefined
  98. btAdr -- address - integer same size as ptr
  99. btChar -- character
  100. btUChar -- unsigned character
  101. btShort -- short
  102. btUShort -- unsigned short
  103. btInt -- int
  104. btUInt -- unsigned int
  105. btLong -- long
  106. btULong -- unsigned long
  107. btFloat -- float (real)
  108. btDouble -- Double (real)
  109. btStruct -- Structure (Record)
  110. btUnion -- Union (variant)
  111. btEnum -- Enumerated
  112. btTypedef -- defined via a typedef isymRef
  113. btRange -- subrange of int
  114. btSet -- pascal sets
  115. btComplex -- fortran complex
  116. btDComplex -- fortran double complex
  117. btIndirect -- forward or unnamed typedef
  118. btFixedDec -- Fixed Decimal
  119. btFloatDec -- Float Decimal
  120. btString -- Varying Length Character String
  121. btBit -- Aligned Bit String
  122. btPicture -- Picture
  123. btVoid -- Void (MIPS cc revision >= 2.00)
  124. d) tq0 - tq5: type qualifier fields as needed. The
  125. current type qualifier fields I have documentation for
  126. are:
  127. tqNil -- no more qualifiers
  128. tqPtr -- pointer
  129. tqProc -- procedure
  130. tqArray -- array
  131. tqFar -- 8086 far pointers
  132. tqVol -- volatile
  133. The dense number table is used in the front ends, and disappears by
  134. the time the .o is created.
  135. With the 1.31 compiler suite, the optimization symbols don't seem
  136. to be used as far as I can tell.
  137. The linker is the first entity that creates the relative file
  138. descriptor table, and I believe it is used so that the individual
  139. file table pointers don't have to be rewritten when the objects are
  140. merged together into the program file.
  141. Unlike COFF, the basic symbol & string tables are split into
  142. external and local symbols/strings. The relocation information
  143. only goes off of the external symbol table, and the debug
  144. information only goes off of the internal symbol table. The
  145. external symbols can have links to an appropriate file index and
  146. symbol within the file to give it the appropriate type information.
  147. Because of this, the external symbols are actually larger than the
  148. internal symbols (to contain the link information), and contain the
  149. local symbol structure as a member, though this member is not the
  150. first member of the external symbol structure (!). I suspect this
  151. split is to make strip easier to deal with.
  152. Each file table has offsets for where the line numbers, local
  153. strings, local symbols, and procedure table starts from within the
  154. global tables, and the indexs are reset to 0 for each of those
  155. tables for the file.
  156. The procedure table contains the binary equivalents of the .ent
  157. (start of the function address), .frame (what register is the
  158. virtual frame pointer, constant offset from the register to obtain
  159. the VFP, and what register holds the return address), .mask/.fmask
  160. (bitmask of saved registers, and where the first register is stored
  161. relative to the VFP) assembler directives. It also contains the
  162. low and high bounds of the line numbers if debugging is turned on.
  163. The line number table is a compressed form of the normal COFF line
  164. table. Each line number entry is either 1 or 3 bytes long, and
  165. contains a signed delta from the previous line, and an unsigned
  166. count of the number of instructions this statement takes.
  167. The local symbol table contains the following fields:
  168. 1) iss: index to the local string table giving the name of the
  169. symbol.
  170. 2) value: value of the symbol (address, register number, etc.).
  171. 3) st: symbol type. The current symbol types are:
  172. stNil -- Nuthin' special
  173. stGlobal -- external symbol
  174. stStatic -- static
  175. stParam -- procedure argument
  176. stLocal -- local variable
  177. stLabel -- label
  178. stProc -- External Procedure
  179. stBlock -- beginning of block
  180. stEnd -- end (of anything)
  181. stMember -- member (of anything)
  182. stTypedef -- type definition
  183. stFile -- file name
  184. stRegReloc -- register relocation
  185. stForward -- forwarding address
  186. stStaticProc -- Static procedure
  187. stConstant -- const
  188. 4) sc: storage class. The current storage classes are:
  189. scText -- text symbol
  190. scData -- initialized data symbol
  191. scBss -- un-initialized data symbol
  192. scRegister -- value of symbol is register number
  193. scAbs -- value of symbol is absolute
  194. scUndefined -- who knows?
  195. scCdbLocal -- variable's value is IN se->va.??
  196. scBits -- this is a bit field
  197. scCdbSystem -- value is IN debugger's address space
  198. scRegImage -- register value saved on stack
  199. scInfo -- symbol contains debugger information
  200. scUserStruct -- addr in struct user for current process
  201. scSData -- load time only small data
  202. scSBss -- load time only small common
  203. scRData -- load time only read only data
  204. scVar -- Var parameter (fortranpascal)
  205. scCommon -- common variable
  206. scSCommon -- small common
  207. scVarRegister -- Var parameter in a register
  208. scVariant -- Variant record
  209. scSUndefined -- small undefined(external) data
  210. scInit -- .init section symbol
  211. 5) index: pointer to a local symbol or aux. entry.
  212. For the following program:
  213. #include <stdio.h>
  214. main(){
  215. printf("Hello World!\n");
  216. return 0;
  217. }
  218. Mips-tdump produces the following information:
  219. Global file header:
  220. magic number 0x162
  221. # sections 2
  222. timestamp 645311799, Wed Jun 13 17:16:39 1990
  223. symbolic header offset 284
  224. symbolic header size 96
  225. optional header 56
  226. flags 0x0
  227. Symbolic header, magic number = 0x7009, vstamp = 1.31:
  228. Info Offset Number Bytes
  229. ==== ====== ====== =====
  230. Line numbers 380 4 4 [13]
  231. Dense numbers 0 0 0
  232. Procedures Tables 384 1 52
  233. Local Symbols 436 16 192
  234. Optimization Symbols 0 0 0
  235. Auxiliary Symbols 628 39 156
  236. Local Strings 784 80 80
  237. External Strings 864 144 144
  238. File Tables 1008 2 144
  239. Relative Files 0 0 0
  240. External Symbols 1152 20 320
  241. File #0, "hello2.c"
  242. Name index = 1 Readin = No
  243. Merge = No Endian = LITTLE
  244. Debug level = G2 Language = C
  245. Adr = 0x00000000
  246. Info Start Number Size Offset
  247. ==== ===== ====== ==== ======
  248. Local strings 0 15 15 784
  249. Local symbols 0 6 72 436
  250. Line numbers 0 13 13 380
  251. Optimization symbols 0 0 0 0
  252. Procedures 0 1 52 384
  253. Auxiliary symbols 0 14 56 628
  254. Relative Files 0 0 0 0
  255. There are 6 local symbols, starting at 436
  256. Symbol# 0: "hello2.c"
  257. End+1 symbol = 6
  258. String index = 1
  259. Storage class = Text Index = 6
  260. Symbol type = File Value = 0
  261. Symbol# 1: "main"
  262. End+1 symbol = 5
  263. Type = int
  264. String index = 10
  265. Storage class = Text Index = 12
  266. Symbol type = Proc Value = 0
  267. Symbol# 2: ""
  268. End+1 symbol = 4
  269. String index = 0
  270. Storage class = Text Index = 4
  271. Symbol type = Block Value = 8
  272. Symbol# 3: ""
  273. First symbol = 2
  274. String index = 0
  275. Storage class = Text Index = 2
  276. Symbol type = End Value = 28
  277. Symbol# 4: "main"
  278. First symbol = 1
  279. String index = 10
  280. Storage class = Text Index = 1
  281. Symbol type = End Value = 52
  282. Symbol# 5: "hello2.c"
  283. First symbol = 0
  284. String index = 1
  285. Storage class = Text Index = 0
  286. Symbol type = End Value = 0
  287. There are 14 auxiliary table entries, starting at 628.
  288. * #0 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  289. * #1 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
  290. * #2 8, [ 8/ 0], [ 2 0:0 0:0:0:0:0:0]
  291. * #3 16, [ 16/ 0], [ 4 0:0 0:0:0:0:0:0]
  292. * #4 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
  293. * #5 32, [ 32/ 0], [ 8 0:0 0:0:0:0:0:0]
  294. * #6 40, [ 40/ 0], [10 0:0 0:0:0:0:0:0]
  295. * #7 44, [ 44/ 0], [11 0:0 0:0:0:0:0:0]
  296. * #8 12, [ 12/ 0], [ 3 0:0 0:0:0:0:0:0]
  297. * #9 20, [ 20/ 0], [ 5 0:0 0:0:0:0:0:0]
  298. * #10 28, [ 28/ 0], [ 7 0:0 0:0:0:0:0:0]
  299. * #11 36, [ 36/ 0], [ 9 0:0 0:0:0:0:0:0]
  300. #12 5, [ 5/ 0], [ 1 1:0 0:0:0:0:0:0]
  301. #13 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
  302. There are 1 procedure descriptor entries, starting at 0.
  303. Procedure descriptor 0:
  304. Name index = 10 Name = "main"
  305. .mask 0x80000000,-4 .fmask 0x00000000,0
  306. .frame $29,24,$31
  307. Opt. start = -1 Symbols start = 1
  308. First line # = 3 Last line # = 6
  309. Line Offset = 0 Address = 0x00000000
  310. There are 4 bytes holding line numbers, starting at 380.
  311. Line 3, delta 0, count 2
  312. Line 4, delta 1, count 3
  313. Line 5, delta 1, count 2
  314. Line 6, delta 1, count 6
  315. File #1, "/usr/include/stdio.h"
  316. Name index = 1 Readin = No
  317. Merge = Yes Endian = LITTLE
  318. Debug level = G2 Language = C
  319. Adr = 0x00000000
  320. Info Start Number Size Offset
  321. ==== ===== ====== ==== ======
  322. Local strings 15 65 65 799
  323. Local symbols 6 10 120 508
  324. Line numbers 0 0 0 380
  325. Optimization symbols 0 0 0 0
  326. Procedures 1 0 0 436
  327. Auxiliary symbols 14 25 100 684
  328. Relative Files 0 0 0 0
  329. There are 10 local symbols, starting at 442
  330. Symbol# 0: "/usr/include/stdio.h"
  331. End+1 symbol = 10
  332. String index = 1
  333. Storage class = Text Index = 10
  334. Symbol type = File Value = 0
  335. Symbol# 1: "_iobuf"
  336. End+1 symbol = 9
  337. String index = 22
  338. Storage class = Info Index = 9
  339. Symbol type = Block Value = 20
  340. Symbol# 2: "_cnt"
  341. Type = int
  342. String index = 29
  343. Storage class = Info Index = 4
  344. Symbol type = Member Value = 0
  345. Symbol# 3: "_ptr"
  346. Type = ptr to char
  347. String index = 34
  348. Storage class = Info Index = 15
  349. Symbol type = Member Value = 32
  350. Symbol# 4: "_base"
  351. Type = ptr to char
  352. String index = 39
  353. Storage class = Info Index = 16
  354. Symbol type = Member Value = 64
  355. Symbol# 5: "_bufsiz"
  356. Type = int
  357. String index = 45
  358. Storage class = Info Index = 4
  359. Symbol type = Member Value = 96
  360. Symbol# 6: "_flag"
  361. Type = short
  362. String index = 53
  363. Storage class = Info Index = 3
  364. Symbol type = Member Value = 128
  365. Symbol# 7: "_file"
  366. Type = char
  367. String index = 59
  368. Storage class = Info Index = 2
  369. Symbol type = Member Value = 144
  370. Symbol# 8: ""
  371. First symbol = 1
  372. String index = 0
  373. Storage class = Info Index = 1
  374. Symbol type = End Value = 0
  375. Symbol# 9: "/usr/include/stdio.h"
  376. First symbol = 0
  377. String index = 1
  378. Storage class = Text Index = 0
  379. Symbol type = End Value = 0
  380. There are 25 auxiliary table entries, starting at 642.
  381. * #14 -1, [4095/1048575], [63 1:1 f:f:f:f:f:f]
  382. #15 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0]
  383. #16 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0]
  384. * #17 196656, [ 48/ 48], [12 0:0 3:0:0:0:0:0]
  385. * #18 8191, [4095/ 1], [63 1:1 0:0:0:0:f:1]
  386. * #19 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0]
  387. * #20 20479, [4095/ 4], [63 1:1 0:0:0:0:f:4]
  388. * #21 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0]
  389. * #22 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  390. * #23 2, [ 2/ 0], [ 0 0:1 0:0:0:0:0:0]
  391. * #24 160, [ 160/ 0], [40 0:0 0:0:0:0:0:0]
  392. * #25 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  393. * #26 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  394. * #27 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  395. * #28 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  396. * #29 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  397. * #30 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  398. * #31 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  399. * #32 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  400. * #33 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  401. * #34 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  402. * #35 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  403. * #36 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  404. * #37 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  405. * #38 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
  406. There are 0 procedure descriptor entries, starting at 1.
  407. There are 20 external symbols, starting at 1152
  408. Symbol# 0: "_iob"
  409. Type = array [3 {160}] of struct _iobuf { ifd = 1, index = 1 }
  410. String index = 0 Ifd = 1
  411. Storage class = Nil Index = 17
  412. Symbol type = Global Value = 60
  413. Symbol# 1: "fopen"
  414. String index = 5 Ifd = 1
  415. Storage class = Nil Index = 1048575
  416. Symbol type = Proc Value = 0
  417. Symbol# 2: "fdopen"
  418. String index = 11 Ifd = 1
  419. Storage class = Nil Index = 1048575
  420. Symbol type = Proc Value = 0
  421. Symbol# 3: "freopen"
  422. String index = 18 Ifd = 1
  423. Storage class = Nil Index = 1048575
  424. Symbol type = Proc Value = 0
  425. Symbol# 4: "popen"
  426. String index = 26 Ifd = 1
  427. Storage class = Nil Index = 1048575
  428. Symbol type = Proc Value = 0
  429. Symbol# 5: "tmpfile"
  430. String index = 32 Ifd = 1
  431. Storage class = Nil Index = 1048575
  432. Symbol type = Proc Value = 0
  433. Symbol# 6: "ftell"
  434. String index = 40 Ifd = 1
  435. Storage class = Nil Index = 1048575
  436. Symbol type = Proc Value = 0
  437. Symbol# 7: "rewind"
  438. String index = 46 Ifd = 1
  439. Storage class = Nil Index = 1048575
  440. Symbol type = Proc Value = 0
  441. Symbol# 8: "setbuf"
  442. String index = 53 Ifd = 1
  443. Storage class = Nil Index = 1048575
  444. Symbol type = Proc Value = 0
  445. Symbol# 9: "setbuffer"
  446. String index = 60 Ifd = 1
  447. Storage class = Nil Index = 1048575
  448. Symbol type = Proc Value = 0
  449. Symbol# 10: "setlinebuf"
  450. String index = 70 Ifd = 1
  451. Storage class = Nil Index = 1048575
  452. Symbol type = Proc Value = 0
  453. Symbol# 11: "fgets"
  454. String index = 81 Ifd = 1
  455. Storage class = Nil Index = 1048575
  456. Symbol type = Proc Value = 0
  457. Symbol# 12: "gets"
  458. String index = 87 Ifd = 1
  459. Storage class = Nil Index = 1048575
  460. Symbol type = Proc Value = 0
  461. Symbol# 13: "ctermid"
  462. String index = 92 Ifd = 1
  463. Storage class = Nil Index = 1048575
  464. Symbol type = Proc Value = 0
  465. Symbol# 14: "cuserid"
  466. String index = 100 Ifd = 1
  467. Storage class = Nil Index = 1048575
  468. Symbol type = Proc Value = 0
  469. Symbol# 15: "tempnam"
  470. String index = 108 Ifd = 1
  471. Storage class = Nil Index = 1048575
  472. Symbol type = Proc Value = 0
  473. Symbol# 16: "tmpnam"
  474. String index = 116 Ifd = 1
  475. Storage class = Nil Index = 1048575
  476. Symbol type = Proc Value = 0
  477. Symbol# 17: "sprintf"
  478. String index = 123 Ifd = 1
  479. Storage class = Nil Index = 1048575
  480. Symbol type = Proc Value = 0
  481. Symbol# 18: "main"
  482. Type = int
  483. String index = 131 Ifd = 0
  484. Storage class = Text Index = 1
  485. Symbol type = Proc Value = 0
  486. Symbol# 19: "printf"
  487. String index = 136 Ifd = 0
  488. Storage class = Undefined Index = 1048575
  489. Symbol type = Proc Value = 0
  490. The following auxiliary table entries were unused:
  491. #0 0 0x00000000 void
  492. #2 8 0x00000008 char
  493. #3 16 0x00000010 short
  494. #4 24 0x00000018 int
  495. #5 32 0x00000020 long
  496. #6 40 0x00000028 float
  497. #7 44 0x0000002c double
  498. #8 12 0x0000000c unsigned char
  499. #9 20 0x00000014 unsigned short
  500. #10 28 0x0000001c unsigned int
  501. #11 36 0x00000024 unsigned long
  502. #14 0 0x00000000 void
  503. #15 24 0x00000018 int
  504. #19 32 0x00000020 long
  505. #20 40 0x00000028 float
  506. #21 44 0x0000002c double
  507. #22 12 0x0000000c unsigned char
  508. #23 20 0x00000014 unsigned short
  509. #24 28 0x0000001c unsigned int
  510. #25 36 0x00000024 unsigned long
  511. #26 48 0x00000030 struct no name { ifd = -1, index = 1048575 }
  512. */
  513. /* Redefinition of of storage classes as an enumeration for better
  514. debugging. */
  515. typedef enum sc {
  516. sc_Nil = scNil, /* no storage class */
  517. sc_Text = scText, /* text symbol */
  518. sc_Data = scData, /* initialized data symbol */
  519. sc_Bss = scBss, /* un-initialized data symbol */
  520. sc_Register = scRegister, /* value of symbol is register number */
  521. sc_Abs = scAbs, /* value of symbol is absolute */
  522. sc_Undefined = scUndefined, /* who knows? */
  523. sc_CdbLocal = scCdbLocal, /* variable's value is IN se->va.?? */
  524. sc_Bits = scBits, /* this is a bit field */
  525. sc_CdbSystem = scCdbSystem, /* value is IN CDB's address space */
  526. sc_RegImage = scRegImage, /* register value saved on stack */
  527. sc_Info = scInfo, /* symbol contains debugger information */
  528. sc_UserStruct = scUserStruct, /* addr in struct user for current process */
  529. sc_SData = scSData, /* load time only small data */
  530. sc_SBss = scSBss, /* load time only small common */
  531. sc_RData = scRData, /* load time only read only data */
  532. sc_Var = scVar, /* Var parameter (fortran,pascal) */
  533. sc_Common = scCommon, /* common variable */
  534. sc_SCommon = scSCommon, /* small common */
  535. sc_VarRegister = scVarRegister, /* Var parameter in a register */
  536. sc_Variant = scVariant, /* Variant record */
  537. sc_SUndefined = scSUndefined, /* small undefined(external) data */
  538. sc_Init = scInit, /* .init section symbol */
  539. sc_Max = scMax /* Max storage class+1 */
  540. } sc_t;
  541. /* Redefinition of symbol type. */
  542. typedef enum st {
  543. st_Nil = stNil, /* Nuthin' special */
  544. st_Global = stGlobal, /* external symbol */
  545. st_Static = stStatic, /* static */
  546. st_Param = stParam, /* procedure argument */
  547. st_Local = stLocal, /* local variable */
  548. st_Label = stLabel, /* label */
  549. st_Proc = stProc, /* " " Procedure */
  550. st_Block = stBlock, /* beginning of block */
  551. st_End = stEnd, /* end (of anything) */
  552. st_Member = stMember, /* member (of anything - struct/union/enum */
  553. st_Typedef = stTypedef, /* type definition */
  554. st_File = stFile, /* file name */
  555. st_RegReloc = stRegReloc, /* register relocation */
  556. st_Forward = stForward, /* forwarding address */
  557. st_StaticProc = stStaticProc, /* load time only static procs */
  558. st_Constant = stConstant, /* const */
  559. st_Str = stStr, /* string */
  560. st_Number = stNumber, /* pure number (ie. 4 NOR 2+2) */
  561. st_Expr = stExpr, /* 2+2 vs. 4 */
  562. st_Type = stType, /* post-coercion SER */
  563. st_Max = stMax /* max type+1 */
  564. } st_t;
  565. /* Redefinition of type qualifiers. */
  566. typedef enum tq {
  567. tq_Nil = tqNil, /* bt is what you see */
  568. tq_Ptr = tqPtr, /* pointer */
  569. tq_Proc = tqProc, /* procedure */
  570. tq_Array = tqArray, /* duh */
  571. tq_Far = tqFar, /* longer addressing - 8086/8 land */
  572. tq_Vol = tqVol, /* volatile */
  573. tq_Max = tqMax /* Max type qualifier+1 */
  574. } tq_t;
  575. /* Redefinition of basic types. */
  576. typedef enum bt {
  577. bt_Nil = btNil, /* undefined */
  578. bt_Adr = btAdr, /* address - integer same size as pointer */
  579. bt_Char = btChar, /* character */
  580. bt_UChar = btUChar, /* unsigned character */
  581. bt_Short = btShort, /* short */
  582. bt_UShort = btUShort, /* unsigned short */
  583. bt_Int = btInt, /* int */
  584. bt_UInt = btUInt, /* unsigned int */
  585. bt_Long = btLong, /* long */
  586. bt_ULong = btULong, /* unsigned long */
  587. bt_Float = btFloat, /* float (real) */
  588. bt_Double = btDouble, /* Double (real) */
  589. bt_Struct = btStruct, /* Structure (Record) */
  590. bt_Union = btUnion, /* Union (variant) */
  591. bt_Enum = btEnum, /* Enumerated */
  592. bt_Typedef = btTypedef, /* defined via a typedef, isymRef points */
  593. bt_Range = btRange, /* subrange of int */
  594. bt_Set = btSet, /* pascal sets */
  595. bt_Complex = btComplex, /* fortran complex */
  596. bt_DComplex = btDComplex, /* fortran double complex */
  597. bt_Indirect = btIndirect, /* forward or unnamed typedef */
  598. bt_FixedDec = btFixedDec, /* Fixed Decimal */
  599. bt_FloatDec = btFloatDec, /* Float Decimal */
  600. bt_String = btString, /* Varying Length Character String */
  601. bt_Bit = btBit, /* Aligned Bit String */
  602. bt_Picture = btPicture, /* Picture */
  603. bt_Void = btVoid, /* Void */
  604. bt_Max = btMax /* Max basic type+1 */
  605. } bt_t;
  606. #define N_TQ itqMax
  607. /* States for whether to hash type or not. */
  608. typedef enum hash_state {
  609. hash_no = 0, /* Don't hash type */
  610. hash_yes = 1, /* OK to hash type, or use previous hash */
  611. hash_record = 2 /* OK to record hash, but don't use prev. */
  612. } hash_state_t;
  613. /* Types of different sized allocation requests. */
  614. enum alloc_type {
  615. alloc_type_none, /* dummy value */
  616. alloc_type_scope, /* nested scopes linked list */
  617. alloc_type_vlinks, /* glue linking pages in varray */
  618. alloc_type_shash, /* string hash element */
  619. alloc_type_thash, /* type hash element */
  620. alloc_type_tag, /* struct/union/tag element */
  621. alloc_type_forward, /* element to hold unknown tag */
  622. alloc_type_thead, /* head of type hash list */
  623. alloc_type_varray, /* general varray allocation */
  624. alloc_type_lineno, /* line number list */
  625. alloc_type_last /* last+1 element for array bounds */
  626. };
  627. /* Types of auxiliary type information. */
  628. enum aux_type {
  629. aux_tir, /* TIR type information */
  630. aux_rndx, /* relative index into symbol table */
  631. aux_dnLow, /* low dimension */
  632. aux_dnHigh, /* high dimension */
  633. aux_isym, /* symbol table index (end of proc) */
  634. aux_iss, /* index into string space (not used) */
  635. aux_width, /* width for non-default sized struc fields */
  636. aux_count /* count of ranges for variant arm */
  637. };
  638. /* Structures to provide n-number of virtual arrays, each of which can
  639. grow linearly, and which are written in the object file as
  640. sequential pages. On systems with a BSD malloc, the
  641. MAX_CLUSTER_PAGES should be 1 less than a power of two, since
  642. malloc adds it's overhead, and rounds up to the next power of 2.
  643. Pages are linked together via a linked list.
  644. If PAGE_SIZE is > 4096, the string length in the shash_t structure
  645. can't be represented (assuming there are strings > 4096 bytes). */
  646. /* FIXME: Yes, there can be such strings while emitting C++ class debug
  647. info. Templates are the offender here, the test case in question
  648. having a mangled class name of
  649. t7rb_tree4Z4xkeyZt4pair2ZC4xkeyZt7xsocket1Z4UserZt9select1st2Zt4pair\
  650. 2ZC4xkeyZt7xsocket1Z4UserZ4xkeyZt4less1Z4xkey
  651. Repeat that a couple dozen times while listing the class members and
  652. you've got strings over 4k. Hack around this for now by increasing
  653. the page size. A proper solution would abandon this structure scheme
  654. certainly for very large strings, and possibly entirely. */
  655. #ifndef PAGE_SIZE
  656. #define PAGE_SIZE (8*1024) /* size of varray pages */
  657. #endif
  658. #define PAGE_USIZE ((unsigned long) PAGE_SIZE)
  659. #ifndef MAX_CLUSTER_PAGES /* # pages to get from system */
  660. #define MAX_CLUSTER_PAGES 63
  661. #endif
  662. /* Linked list connecting separate page allocations. */
  663. typedef struct vlinks {
  664. struct vlinks *prev; /* previous set of pages */
  665. struct vlinks *next; /* next set of pages */
  666. union page *datum; /* start of page */
  667. unsigned long start_index; /* starting index # of page */
  668. } vlinks_t;
  669. /* Virtual array header. */
  670. typedef struct varray {
  671. vlinks_t *first; /* first page link */
  672. vlinks_t *last; /* last page link */
  673. unsigned long num_allocated; /* # objects allocated */
  674. unsigned short object_size; /* size in bytes of each object */
  675. unsigned short objects_per_page; /* # objects that can fit on a page */
  676. unsigned short objects_last_page; /* # objects allocated on last page */
  677. } varray_t;
  678. #ifndef MALLOC_CHECK
  679. #define OBJECTS_PER_PAGE(type) (PAGE_SIZE / sizeof (type))
  680. #else
  681. #define OBJECTS_PER_PAGE(type) ((sizeof (type) > 1) ? 1 : PAGE_SIZE)
  682. #endif
  683. #define INIT_VARRAY(type) { /* macro to initialize a varray */ \
  684. (vlinks_t *)0, /* first */ \
  685. (vlinks_t *)0, /* last */ \
  686. 0, /* num_allocated */ \
  687. sizeof (type), /* object_size */ \
  688. OBJECTS_PER_PAGE (type), /* objects_per_page */ \
  689. OBJECTS_PER_PAGE (type), /* objects_last_page */ \
  690. }
  691. /* Master type for indexes within the symbol table. */
  692. typedef unsigned long symint_t;
  693. /* Linked list support for nested scopes (file, block, structure, etc.). */
  694. typedef struct scope {
  695. struct scope *prev; /* previous scope level */
  696. struct scope *free; /* free list pointer */
  697. struct localsym *lsym; /* pointer to local symbol node */
  698. st_t type; /* type of the node */
  699. } scope_t;
  700. /* For a local symbol we store a gas symbol as well as the debugging
  701. information we generate. The gas symbol will be NULL if this is
  702. only a debugging symbol. */
  703. typedef struct localsym {
  704. const char *name; /* symbol name */
  705. symbolS *as_sym; /* symbol as seen by gas */
  706. bfd_vma addend; /* addend to as_sym value */
  707. struct efdr *file_ptr; /* file pointer */
  708. struct ecoff_proc *proc_ptr; /* proc pointer */
  709. struct localsym *begin_ptr; /* symbol at start of block */
  710. struct ecoff_aux *index_ptr; /* index value to be filled in */
  711. struct forward *forward_ref; /* forward references to this symbol */
  712. long sym_index; /* final symbol index */
  713. EXTR ecoff_sym; /* ECOFF debugging symbol */
  714. } localsym_t;
  715. /* For aux information we keep the type and the data. */
  716. typedef struct ecoff_aux {
  717. enum aux_type type; /* aux type */
  718. AUXU data; /* aux data */
  719. } aux_t;
  720. /* For a procedure we store the gas symbol as well as the PDR
  721. debugging information. */
  722. typedef struct ecoff_proc {
  723. localsym_t *sym; /* associated symbol */
  724. PDR pdr; /* ECOFF debugging info */
  725. } proc_t;
  726. /* Number of proc_t structures allocated. */
  727. static unsigned long proc_cnt;
  728. /* Forward reference list for tags referenced, but not yet defined. */
  729. typedef struct forward {
  730. struct forward *next; /* next forward reference */
  731. struct forward *free; /* free list pointer */
  732. aux_t *ifd_ptr; /* pointer to store file index */
  733. aux_t *index_ptr; /* pointer to store symbol index */
  734. } forward_t;
  735. /* Linked list support for tags. The first tag in the list is always
  736. the current tag for that block. */
  737. typedef struct tag {
  738. struct tag *free; /* free list pointer */
  739. struct shash *hash_ptr; /* pointer to the hash table head */
  740. struct tag *same_name; /* tag with same name in outer scope */
  741. struct tag *same_block; /* next tag defined in the same block. */
  742. struct forward *forward_ref; /* list of forward references */
  743. bt_t basic_type; /* bt_Struct, bt_Union, or bt_Enum */
  744. symint_t ifd; /* file # tag defined in */
  745. localsym_t *sym; /* file's local symbols */
  746. } tag_t;
  747. /* Head of a block's linked list of tags. */
  748. typedef struct thead {
  749. struct thead *prev; /* previous block */
  750. struct thead *free; /* free list pointer */
  751. struct tag *first_tag; /* first tag in block defined */
  752. } thead_t;
  753. /* Union containing pointers to each the small structures which are freed up. */
  754. typedef union small_free {
  755. scope_t *f_scope; /* scope structure */
  756. thead_t *f_thead; /* tag head structure */
  757. tag_t *f_tag; /* tag element structure */
  758. forward_t *f_forward; /* forward tag reference */
  759. } small_free_t;
  760. /* String hash table entry. */
  761. typedef struct shash {
  762. char *string; /* string we are hashing */
  763. symint_t indx; /* index within string table */
  764. EXTR *esym_ptr; /* global symbol pointer */
  765. localsym_t *sym_ptr; /* local symbol pointer */
  766. localsym_t *end_ptr; /* symbol pointer to end block */
  767. tag_t *tag_ptr; /* tag pointer */
  768. proc_t *proc_ptr; /* procedure descriptor pointer */
  769. } shash_t;
  770. /* Type hash table support. The size of the hash table must fit
  771. within a page with the other extended file descriptor information.
  772. Because unique types which are hashed are fewer in number than
  773. strings, we use a smaller hash value. */
  774. #define HASHBITS 30
  775. #ifndef THASH_SIZE
  776. #define THASH_SIZE 113
  777. #endif
  778. typedef struct thash {
  779. struct thash *next; /* next hash value */
  780. AUXU type; /* type we are hashing */
  781. symint_t indx; /* index within string table */
  782. } thash_t;
  783. /* Extended file descriptor that contains all of the support necessary
  784. to add things to each file separately. */
  785. typedef struct efdr {
  786. FDR fdr; /* File header to be written out */
  787. FDR *orig_fdr; /* original file header */
  788. char *name; /* filename */
  789. int fake; /* whether this is faked .file */
  790. symint_t void_type; /* aux. pointer to 'void' type */
  791. symint_t int_type; /* aux. pointer to 'int' type */
  792. scope_t *cur_scope; /* current nested scopes */
  793. symint_t file_index; /* current file number */
  794. int nested_scopes; /* # nested scopes */
  795. varray_t strings; /* local strings */
  796. varray_t symbols; /* local symbols */
  797. varray_t procs; /* procedures */
  798. varray_t aux_syms; /* auxiliary symbols */
  799. struct efdr *next_file; /* next file descriptor */
  800. /* string/type hash tables */
  801. struct hash_control *str_hash; /* string hash table */
  802. thash_t *thash_head[THASH_SIZE];
  803. } efdr_t;
  804. /* Pre-initialized extended file structure. */
  805. static const efdr_t init_file = {
  806. { /* FDR structure */
  807. 0, /* adr: memory address of beginning of file */
  808. 0, /* rss: file name (of source, if known) */
  809. 0, /* issBase: file's string space */
  810. 0, /* cbSs: number of bytes in the ss */
  811. 0, /* isymBase: beginning of symbols */
  812. 0, /* csym: count file's of symbols */
  813. 0, /* ilineBase: file's line symbols */
  814. 0, /* cline: count of file's line symbols */
  815. 0, /* ioptBase: file's optimization entries */
  816. 0, /* copt: count of file's optimization entries */
  817. 0, /* ipdFirst: start of procedures for this file */
  818. 0, /* cpd: count of procedures for this file */
  819. 0, /* iauxBase: file's auxiliary entries */
  820. 0, /* caux: count of file's auxiliary entries */
  821. 0, /* rfdBase: index into the file indirect table */
  822. 0, /* crfd: count file indirect entries */
  823. langC, /* lang: language for this file */
  824. 1, /* fMerge: whether this file can be merged */
  825. 0, /* fReadin: true if read in (not just created) */
  826. TARGET_BYTES_BIG_ENDIAN, /* fBigendian: if 1, compiled on big endian machine */
  827. GLEVEL_2, /* glevel: level this file was compiled with */
  828. 0, /* reserved: reserved for future use */
  829. 0, /* cbLineOffset: byte offset from header for this file ln's */
  830. 0, /* cbLine: size of lines for this file */
  831. },
  832. (FDR *)0, /* orig_fdr: original file header pointer */
  833. (char *)0, /* name: pointer to filename */
  834. 0, /* fake: whether this is a faked .file */
  835. 0, /* void_type: ptr to aux node for void type */
  836. 0, /* int_type: ptr to aux node for int type */
  837. (scope_t *)0, /* cur_scope: current scope being processed */
  838. 0, /* file_index: current file # */
  839. 0, /* nested_scopes: # nested scopes */
  840. INIT_VARRAY (char), /* strings: local string varray */
  841. INIT_VARRAY (localsym_t), /* symbols: local symbols varray */
  842. INIT_VARRAY (proc_t), /* procs: procedure varray */
  843. INIT_VARRAY (aux_t), /* aux_syms: auxiliary symbols varray */
  844. (struct efdr *)0, /* next_file: next file structure */
  845. (struct hash_control *)0, /* str_hash: string hash table */
  846. { 0 }, /* thash_head: type hash table */
  847. };
  848. static efdr_t *first_file; /* first file descriptor */
  849. static efdr_t **last_file_ptr = &first_file; /* file descriptor tail */
  850. /* Line number information is kept in a list until the assembly is
  851. finished. */
  852. typedef struct lineno_list {
  853. struct lineno_list *next; /* next element in list */
  854. efdr_t *file; /* file this line is in */
  855. proc_t *proc; /* procedure this line is in */
  856. fragS *frag; /* fragment this line number is in */
  857. unsigned long paddr; /* offset within fragment */
  858. long lineno; /* actual line number */
  859. } lineno_list_t;
  860. static lineno_list_t *first_lineno;
  861. static lineno_list_t *last_lineno;
  862. static lineno_list_t **last_lineno_ptr = &first_lineno;
  863. /* Sometimes there will be some .loc statements before a .ent. We
  864. keep them in this list so that we can fill in the procedure pointer
  865. after we see the .ent. */
  866. static lineno_list_t *noproc_lineno;
  867. /* Union of various things that are held in pages. */
  868. typedef union page {
  869. char byte [ PAGE_SIZE ];
  870. unsigned char ubyte [ PAGE_SIZE ];
  871. efdr_t file [ PAGE_SIZE / sizeof (efdr_t) ];
  872. FDR ofile [ PAGE_SIZE / sizeof (FDR) ];
  873. proc_t proc [ PAGE_SIZE / sizeof (proc_t) ];
  874. localsym_t sym [ PAGE_SIZE / sizeof (localsym_t) ];
  875. aux_t aux [ PAGE_SIZE / sizeof (aux_t) ];
  876. DNR dense [ PAGE_SIZE / sizeof (DNR) ];
  877. scope_t scope [ PAGE_SIZE / sizeof (scope_t) ];
  878. vlinks_t vlinks [ PAGE_SIZE / sizeof (vlinks_t) ];
  879. shash_t shash [ PAGE_SIZE / sizeof (shash_t) ];
  880. thash_t thash [ PAGE_SIZE / sizeof (thash_t) ];
  881. tag_t tag [ PAGE_SIZE / sizeof (tag_t) ];
  882. forward_t forward [ PAGE_SIZE / sizeof (forward_t) ];
  883. thead_t thead [ PAGE_SIZE / sizeof (thead_t) ];
  884. lineno_list_t lineno [ PAGE_SIZE / sizeof (lineno_list_t) ];
  885. } page_type;
  886. /* Structure holding allocation information for small sized structures. */
  887. typedef struct alloc_info {
  888. char *alloc_name; /* name of this allocation type (must be first) */
  889. page_type *cur_page; /* current page being allocated from */
  890. small_free_t free_list; /* current free list if any */
  891. int unallocated; /* number of elements unallocated on page */
  892. int total_alloc; /* total number of allocations */
  893. int total_free; /* total number of frees */
  894. int total_pages; /* total number of pages allocated */
  895. } alloc_info_t;
  896. /* Type information collected together. */
  897. typedef struct type_info {
  898. bt_t basic_type; /* basic type */
  899. int orig_type; /* original COFF-based type */
  900. int num_tq; /* # type qualifiers */
  901. int num_dims; /* # dimensions */
  902. int num_sizes; /* # sizes */
  903. int extra_sizes; /* # extra sizes not tied with dims */
  904. tag_t * tag_ptr; /* tag pointer */
  905. int bitfield; /* symbol is a bitfield */
  906. tq_t type_qualifiers[N_TQ]; /* type qualifiers (ptr, func, array)*/
  907. symint_t dimensions [N_TQ]; /* dimensions for each array */
  908. symint_t sizes [N_TQ+2]; /* sizes of each array slice + size of
  909. struct/union/enum + bitfield size */
  910. } type_info_t;
  911. /* Pre-initialized type_info struct. */
  912. static const type_info_t type_info_init = {
  913. bt_Nil, /* basic type */
  914. T_NULL, /* original COFF-based type */
  915. 0, /* # type qualifiers */
  916. 0, /* # dimensions */
  917. 0, /* # sizes */
  918. 0, /* sizes not tied with dims */
  919. NULL, /* ptr to tag */
  920. 0, /* bitfield */
  921. { /* type qualifiers */
  922. tq_Nil,
  923. tq_Nil,
  924. tq_Nil,
  925. tq_Nil,
  926. tq_Nil,
  927. tq_Nil,
  928. },
  929. { /* dimensions */
  930. 0,
  931. 0,
  932. 0,
  933. 0,
  934. 0,
  935. 0
  936. },
  937. { /* sizes */
  938. 0,
  939. 0,
  940. 0,
  941. 0,
  942. 0,
  943. 0,
  944. 0,
  945. 0,
  946. },
  947. };
  948. /* Global hash table for the tags table and global table for file
  949. descriptors. */
  950. static varray_t file_desc = INIT_VARRAY (efdr_t);
  951. static struct hash_control *tag_hash;
  952. /* Static types for int and void. Also, remember the last function's
  953. type (which is set up when we encounter the declaration for the
  954. function, and used when the end block for the function is emitted. */
  955. static type_info_t int_type_info;
  956. static type_info_t void_type_info;
  957. static type_info_t last_func_type_info;
  958. static symbolS *last_func_sym_value;
  959. /* Convert COFF basic type to ECOFF basic type. The T_NULL type
  960. really should use bt_Void, but this causes the current ecoff GDB to
  961. issue unsupported type messages, and the Ultrix 4.00 dbx (aka MIPS
  962. 2.0) doesn't understand it, even though the compiler generates it.
  963. Maybe this will be fixed in 2.10 or 2.20 of the MIPS compiler
  964. suite, but for now go with what works.
  965. It would make sense for the .type and .scl directives to use the
  966. ECOFF numbers directly, rather than using the COFF numbers and
  967. mapping them. Unfortunately, this is historically what mips-tfile
  968. expects, and changing gcc now would be a considerable pain (the
  969. native compiler generates debugging information internally, rather
  970. than via the assembler, so it will never use .type or .scl). */
  971. static const bt_t map_coff_types[] = {
  972. bt_Nil, /* T_NULL */
  973. bt_Nil, /* T_ARG */
  974. bt_Char, /* T_CHAR */
  975. bt_Short, /* T_SHORT */
  976. bt_Int, /* T_INT */
  977. bt_Long, /* T_LONG */
  978. bt_Float, /* T_FLOAT */
  979. bt_Double, /* T_DOUBLE */
  980. bt_Struct, /* T_STRUCT */
  981. bt_Union, /* T_UNION */
  982. bt_Enum, /* T_ENUM */
  983. bt_Enum, /* T_MOE */
  984. bt_UChar, /* T_UCHAR */
  985. bt_UShort, /* T_USHORT */
  986. bt_UInt, /* T_UINT */
  987. bt_ULong /* T_ULONG */
  988. };
  989. /* Convert COFF storage class to ECOFF storage class. */
  990. static const sc_t map_coff_storage[] = {
  991. sc_Nil, /* 0: C_NULL */
  992. sc_Abs, /* 1: C_AUTO auto var */
  993. sc_Undefined, /* 2: C_EXT external */
  994. sc_Data, /* 3: C_STAT static */
  995. sc_Register, /* 4: C_REG register */
  996. sc_Undefined, /* 5: C_EXTDEF ??? */
  997. sc_Text, /* 6: C_LABEL label */
  998. sc_Text, /* 7: C_ULABEL user label */
  999. sc_Info, /* 8: C_MOS member of struct */
  1000. sc_Abs, /* 9: C_ARG argument */
  1001. sc_Info, /* 10: C_STRTAG struct tag */
  1002. sc_Info, /* 11: C_MOU member of union */
  1003. sc_Info, /* 12: C_UNTAG union tag */
  1004. sc_Info, /* 13: C_TPDEF typedef */
  1005. sc_Data, /* 14: C_USTATIC ??? */
  1006. sc_Info, /* 15: C_ENTAG enum tag */
  1007. sc_Info, /* 16: C_MOE member of enum */
  1008. sc_Register, /* 17: C_REGPARM register parameter */
  1009. sc_Bits, /* 18; C_FIELD bitfield */
  1010. sc_Nil, /* 19 */
  1011. sc_Nil, /* 20 */
  1012. sc_Nil, /* 21 */
  1013. sc_Nil, /* 22 */
  1014. sc_Nil, /* 23 */
  1015. sc_Nil, /* 24 */
  1016. sc_Nil, /* 25 */
  1017. sc_Nil, /* 26 */
  1018. sc_Nil, /* 27 */
  1019. sc_Nil, /* 28 */
  1020. sc_Nil, /* 29 */
  1021. sc_Nil, /* 30 */
  1022. sc_Nil, /* 31 */
  1023. sc_Nil, /* 32 */
  1024. sc_Nil, /* 33 */
  1025. sc_Nil, /* 34 */
  1026. sc_Nil, /* 35 */
  1027. sc_Nil, /* 36 */
  1028. sc_Nil, /* 37 */
  1029. sc_Nil, /* 38 */
  1030. sc_Nil, /* 39 */
  1031. sc_Nil, /* 40 */
  1032. sc_Nil, /* 41 */
  1033. sc_Nil, /* 42 */
  1034. sc_Nil, /* 43 */
  1035. sc_Nil, /* 44 */
  1036. sc_Nil, /* 45 */
  1037. sc_Nil, /* 46 */
  1038. sc_Nil, /* 47 */
  1039. sc_Nil, /* 48 */
  1040. sc_Nil, /* 49 */
  1041. sc_Nil, /* 50 */
  1042. sc_Nil, /* 51 */
  1043. sc_Nil, /* 52 */
  1044. sc_Nil, /* 53 */
  1045. sc_Nil, /* 54 */
  1046. sc_Nil, /* 55 */
  1047. sc_Nil, /* 56 */
  1048. sc_Nil, /* 57 */
  1049. sc_Nil, /* 58 */
  1050. sc_Nil, /* 59 */
  1051. sc_Nil, /* 60 */
  1052. sc_Nil, /* 61 */
  1053. sc_Nil, /* 62 */
  1054. sc_Nil, /* 63 */
  1055. sc_Nil, /* 64 */
  1056. sc_Nil, /* 65 */
  1057. sc_Nil, /* 66 */
  1058. sc_Nil, /* 67 */
  1059. sc_Nil, /* 68 */
  1060. sc_Nil, /* 69 */
  1061. sc_Nil, /* 70 */
  1062. sc_Nil, /* 71 */
  1063. sc_Nil, /* 72 */
  1064. sc_Nil, /* 73 */
  1065. sc_Nil, /* 74 */
  1066. sc_Nil, /* 75 */
  1067. sc_Nil, /* 76 */
  1068. sc_Nil, /* 77 */
  1069. sc_Nil, /* 78 */
  1070. sc_Nil, /* 79 */
  1071. sc_Nil, /* 80 */
  1072. sc_Nil, /* 81 */
  1073. sc_Nil, /* 82 */
  1074. sc_Nil, /* 83 */
  1075. sc_Nil, /* 84 */
  1076. sc_Nil, /* 85 */
  1077. sc_Nil, /* 86 */
  1078. sc_Nil, /* 87 */
  1079. sc_Nil, /* 88 */
  1080. sc_Nil, /* 89 */
  1081. sc_Nil, /* 90 */
  1082. sc_Nil, /* 91 */
  1083. sc_Nil, /* 92 */
  1084. sc_Nil, /* 93 */
  1085. sc_Nil, /* 94 */
  1086. sc_Nil, /* 95 */
  1087. sc_Nil, /* 96 */
  1088. sc_Nil, /* 97 */
  1089. sc_Nil, /* 98 */
  1090. sc_Nil, /* 99 */
  1091. sc_Text, /* 100: C_BLOCK block start/end */
  1092. sc_Text, /* 101: C_FCN function start/end */
  1093. sc_Info, /* 102: C_EOS end of struct/union/enum */
  1094. sc_Nil, /* 103: C_FILE file start */
  1095. sc_Nil, /* 104: C_LINE line number */
  1096. sc_Nil, /* 105: C_ALIAS combined type info */
  1097. sc_Nil, /* 106: C_HIDDEN ??? */
  1098. };
  1099. /* Convert COFF storage class to ECOFF symbol type. */
  1100. static const st_t map_coff_sym_type[] = {
  1101. st_Nil, /* 0: C_NULL */
  1102. st_Local, /* 1: C_AUTO auto var */
  1103. st_Global, /* 2: C_EXT external */
  1104. st_Static, /* 3: C_STAT static */
  1105. st_Local, /* 4: C_REG register */
  1106. st_Global, /* 5: C_EXTDEF ??? */
  1107. st_Label, /* 6: C_LABEL label */
  1108. st_Label, /* 7: C_ULABEL user label */
  1109. st_Member, /* 8: C_MOS member of struct */
  1110. st_Param, /* 9: C_ARG argument */
  1111. st_Block, /* 10: C_STRTAG struct tag */
  1112. st_Member, /* 11: C_MOU member of union */
  1113. st_Block, /* 12: C_UNTAG union tag */
  1114. st_Typedef, /* 13: C_TPDEF typedef */
  1115. st_Static, /* 14: C_USTATIC ??? */
  1116. st_Block, /* 15: C_ENTAG enum tag */
  1117. st_Member, /* 16: C_MOE member of enum */
  1118. st_Param, /* 17: C_REGPARM register parameter */
  1119. st_Member, /* 18; C_FIELD bitfield */
  1120. st_Nil, /* 19 */
  1121. st_Nil, /* 20 */
  1122. st_Nil, /* 21 */
  1123. st_Nil, /* 22 */
  1124. st_Nil, /* 23 */
  1125. st_Nil, /* 24 */
  1126. st_Nil, /* 25 */
  1127. st_Nil, /* 26 */
  1128. st_Nil, /* 27 */
  1129. st_Nil, /* 28 */
  1130. st_Nil, /* 29 */
  1131. st_Nil, /* 30 */
  1132. st_Nil, /* 31 */
  1133. st_Nil, /* 32 */
  1134. st_Nil, /* 33 */
  1135. st_Nil, /* 34 */
  1136. st_Nil, /* 35 */
  1137. st_Nil, /* 36 */
  1138. st_Nil, /* 37 */
  1139. st_Nil, /* 38 */
  1140. st_Nil, /* 39 */
  1141. st_Nil, /* 40 */
  1142. st_Nil, /* 41 */
  1143. st_Nil, /* 42 */
  1144. st_Nil, /* 43 */
  1145. st_Nil, /* 44 */
  1146. st_Nil, /* 45 */
  1147. st_Nil, /* 46 */
  1148. st_Nil, /* 47 */
  1149. st_Nil, /* 48 */
  1150. st_Nil, /* 49 */
  1151. st_Nil, /* 50 */
  1152. st_Nil, /* 51 */
  1153. st_Nil, /* 52 */
  1154. st_Nil, /* 53 */
  1155. st_Nil, /* 54 */
  1156. st_Nil, /* 55 */
  1157. st_Nil, /* 56 */
  1158. st_Nil, /* 57 */
  1159. st_Nil, /* 58 */
  1160. st_Nil, /* 59 */
  1161. st_Nil, /* 60 */
  1162. st_Nil, /* 61 */
  1163. st_Nil, /* 62 */
  1164. st_Nil, /* 63 */
  1165. st_Nil, /* 64 */
  1166. st_Nil, /* 65 */
  1167. st_Nil, /* 66 */
  1168. st_Nil, /* 67 */
  1169. st_Nil, /* 68 */
  1170. st_Nil, /* 69 */
  1171. st_Nil, /* 70 */
  1172. st_Nil, /* 71 */
  1173. st_Nil, /* 72 */
  1174. st_Nil, /* 73 */
  1175. st_Nil, /* 74 */
  1176. st_Nil, /* 75 */
  1177. st_Nil, /* 76 */
  1178. st_Nil, /* 77 */
  1179. st_Nil, /* 78 */
  1180. st_Nil, /* 79 */
  1181. st_Nil, /* 80 */
  1182. st_Nil, /* 81 */
  1183. st_Nil, /* 82 */
  1184. st_Nil, /* 83 */
  1185. st_Nil, /* 84 */
  1186. st_Nil, /* 85 */
  1187. st_Nil, /* 86 */
  1188. st_Nil, /* 87 */
  1189. st_Nil, /* 88 */
  1190. st_Nil, /* 89 */
  1191. st_Nil, /* 90 */
  1192. st_Nil, /* 91 */
  1193. st_Nil, /* 92 */
  1194. st_Nil, /* 93 */
  1195. st_Nil, /* 94 */
  1196. st_Nil, /* 95 */
  1197. st_Nil, /* 96 */
  1198. st_Nil, /* 97 */
  1199. st_Nil, /* 98 */
  1200. st_Nil, /* 99 */
  1201. st_Block, /* 100: C_BLOCK block start/end */
  1202. st_Proc, /* 101: C_FCN function start/end */
  1203. st_End, /* 102: C_EOS end of struct/union/enum */
  1204. st_File, /* 103: C_FILE file start */
  1205. st_Nil, /* 104: C_LINE line number */
  1206. st_Nil, /* 105: C_ALIAS combined type info */
  1207. st_Nil, /* 106: C_HIDDEN ??? */
  1208. };
  1209. /* Keep track of different sized allocation requests. */
  1210. static alloc_info_t alloc_counts[(int) alloc_type_last];
  1211. /* Record whether we have seen any debugging information. */
  1212. int ecoff_debugging_seen = 0;
  1213. /* Various statics. */
  1214. static efdr_t *cur_file_ptr = (efdr_t *) 0; /* current file desc. header */
  1215. static proc_t *cur_proc_ptr = (proc_t *) 0; /* current procedure header */
  1216. static proc_t *first_proc_ptr = (proc_t *) 0; /* first procedure header */
  1217. static thead_t *top_tag_head = (thead_t *) 0; /* top level tag head */
  1218. static thead_t *cur_tag_head = (thead_t *) 0; /* current tag head */
  1219. #ifdef ECOFF_DEBUG
  1220. static int debug = 0; /* trace functions */
  1221. #endif
  1222. static int stabs_seen = 0; /* != 0 if stabs have been seen */
  1223. static int current_file_idx;
  1224. static const char *current_stabs_filename;
  1225. /* Pseudo symbol to use when putting stabs into the symbol table. */
  1226. #ifndef STABS_SYMBOL
  1227. #define STABS_SYMBOL "@stabs"
  1228. #endif
  1229. static char stabs_symbol[] = STABS_SYMBOL;
  1230. /* Prototypes for functions defined in this file. */
  1231. static void add_varray_page (varray_t *vp);
  1232. static symint_t add_string (varray_t *vp,
  1233. struct hash_control *hash_tbl,
  1234. const char *str,
  1235. shash_t **ret_hash);
  1236. static localsym_t *add_ecoff_symbol (const char *str, st_t type,
  1237. sc_t storage, symbolS *sym,
  1238. bfd_vma addend, symint_t value,
  1239. symint_t indx);
  1240. static symint_t add_aux_sym_symint (symint_t aux_word);
  1241. static symint_t add_aux_sym_rndx (int file_index, symint_t sym_index);
  1242. static symint_t add_aux_sym_tir (type_info_t *t,
  1243. hash_state_t state,
  1244. thash_t **hash_tbl);
  1245. static tag_t *get_tag (const char *tag, localsym_t *sym, bt_t basic_type);
  1246. static void add_unknown_tag (tag_t *ptag);
  1247. static void add_procedure (char *func);
  1248. static void add_file (const char *file_name, int indx, int fake);
  1249. #ifdef ECOFF_DEBUG
  1250. static char *sc_to_string (sc_t storage_class);
  1251. static char *st_to_string (st_t symbol_type);
  1252. #endif
  1253. static void mark_stabs (int);
  1254. static char *ecoff_add_bytes (char **buf, char **bufend,
  1255. char *bufptr, unsigned long need);
  1256. static unsigned long ecoff_padding_adjust
  1257. (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1258. unsigned long offset, char **bufptrptr);
  1259. static unsigned long ecoff_build_lineno
  1260. (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1261. unsigned long offset, long *linecntptr);
  1262. static unsigned long ecoff_build_symbols
  1263. (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1264. unsigned long offset);
  1265. static unsigned long ecoff_build_procs
  1266. (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1267. unsigned long offset);
  1268. static unsigned long ecoff_build_aux
  1269. (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1270. unsigned long offset);
  1271. static unsigned long ecoff_build_strings (char **buf, char **bufend,
  1272. unsigned long offset,
  1273. varray_t *vp);
  1274. static unsigned long ecoff_build_ss
  1275. (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1276. unsigned long offset);
  1277. static unsigned long ecoff_build_fdr
  1278. (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
  1279. unsigned long offset);
  1280. static void ecoff_setup_ext (void);
  1281. static page_type *allocate_cluster (unsigned long npages);
  1282. static page_type *allocate_page (void);
  1283. static scope_t *allocate_scope (void);
  1284. static void free_scope (scope_t *ptr);
  1285. static vlinks_t *allocate_vlinks (void);
  1286. static shash_t *allocate_shash (void);
  1287. static thash_t *allocate_thash (void);
  1288. static tag_t *allocate_tag (void);
  1289. static void free_tag (tag_t *ptr);
  1290. static forward_t *allocate_forward (void);
  1291. static thead_t *allocate_thead (void);
  1292. static void free_thead (thead_t *ptr);
  1293. static lineno_list_t *allocate_lineno_list (void);
  1294. /* This function should be called when the assembler starts up. */
  1295. void
  1296. ecoff_read_begin_hook (void)
  1297. {
  1298. tag_hash = hash_new ();
  1299. top_tag_head = allocate_thead ();
  1300. top_tag_head->first_tag = (tag_t *) NULL;
  1301. top_tag_head->free = (thead_t *) NULL;
  1302. top_tag_head->prev = cur_tag_head;
  1303. cur_tag_head = top_tag_head;
  1304. }
  1305. /* This function should be called when a symbol is created. */
  1306. void
  1307. ecoff_symbol_new_hook (symbolS *symbolP)
  1308. {
  1309. OBJ_SYMFIELD_TYPE *obj;
  1310. /* Make sure that we have a file pointer, but only if we have seen a
  1311. file. If we haven't seen a file, then this is a probably special
  1312. symbol created by md_begin which may required special handling at
  1313. some point. Creating a dummy file with a dummy name is certainly
  1314. wrong. */
  1315. if (cur_file_ptr == (efdr_t *) NULL
  1316. && seen_at_least_1_file ())
  1317. add_file ((const char *) NULL, 0, 1);
  1318. obj = symbol_get_obj (symbolP);
  1319. obj->ecoff_file = cur_file_ptr;
  1320. obj->ecoff_symbol = NULL;
  1321. obj->ecoff_extern_size = 0;
  1322. }
  1323. void
  1324. ecoff_symbol_clone_hook (symbolS *newsymP, symbolS *orgsymP)
  1325. {
  1326. OBJ_SYMFIELD_TYPE *n, *o;
  1327. n = symbol_get_obj (newsymP);
  1328. o = symbol_get_obj (orgsymP);
  1329. memcpy (n, o, sizeof *n);
  1330. }
  1331. /* Add a page to a varray object. */
  1332. static void
  1333. add_varray_page (varray_t *vp /* varray to add page to */)
  1334. {
  1335. vlinks_t *new_links = allocate_vlinks ();
  1336. #ifdef MALLOC_CHECK
  1337. if (vp->object_size > 1)
  1338. new_links->datum = (page_type *) xcalloc (1, vp->object_size);
  1339. else
  1340. #endif
  1341. new_links->datum = allocate_page ();
  1342. alloc_counts[(int) alloc_type_varray].total_alloc++;
  1343. alloc_counts[(int) alloc_type_varray].total_pages++;
  1344. new_links->start_index = vp->num_allocated;
  1345. vp->objects_last_page = 0;
  1346. if (vp->first == (vlinks_t *) NULL) /* first allocation? */
  1347. vp->first = vp->last = new_links;
  1348. else
  1349. { /* 2nd or greater allocation */
  1350. new_links->prev = vp->last;
  1351. vp->last->next = new_links;
  1352. vp->last = new_links;
  1353. }
  1354. }
  1355. /* Add a string (and null pad) to one of the string tables. */
  1356. static symint_t
  1357. add_string (varray_t *vp, /* string obstack */
  1358. struct hash_control *hash_tbl, /* ptr to hash table */
  1359. const char *str, /* string */
  1360. shash_t **ret_hash /* return hash pointer */)
  1361. {
  1362. unsigned long len = strlen (str);
  1363. shash_t *hash_ptr;
  1364. if (len >= PAGE_USIZE)
  1365. as_fatal (_("string too big (%lu bytes)"), len);
  1366. hash_ptr = (shash_t *) hash_find (hash_tbl, str);
  1367. if (hash_ptr == (shash_t *) NULL)
  1368. {
  1369. const char *err;
  1370. if (vp->objects_last_page + len >= PAGE_USIZE)
  1371. {
  1372. vp->num_allocated =
  1373. ((vp->num_allocated + PAGE_USIZE - 1) / PAGE_USIZE) * PAGE_USIZE;
  1374. add_varray_page (vp);
  1375. }
  1376. hash_ptr = allocate_shash ();
  1377. hash_ptr->indx = vp->num_allocated;
  1378. hash_ptr->string = &vp->last->datum->byte[vp->objects_last_page];
  1379. vp->objects_last_page += len + 1;
  1380. vp->num_allocated += len + 1;
  1381. strcpy (hash_ptr->string, str);
  1382. err = hash_insert (hash_tbl, str, (char *) hash_ptr);
  1383. if (err)
  1384. as_fatal (_("inserting \"%s\" into string hash table: %s"),
  1385. str, err);
  1386. }
  1387. if (ret_hash != (shash_t **) NULL)
  1388. *ret_hash = hash_ptr;
  1389. return hash_ptr->indx;
  1390. }
  1391. /* Add debugging information for a symbol. */
  1392. static localsym_t *
  1393. add_ecoff_symbol (const char *str, /* symbol name */
  1394. st_t type, /* symbol type */
  1395. sc_t storage, /* storage class */
  1396. symbolS *sym_value, /* associated symbol. */
  1397. bfd_vma addend, /* addend to sym_value. */
  1398. symint_t value, /* value of symbol */
  1399. symint_t indx /* index to local/aux. syms */)
  1400. {
  1401. localsym_t *psym;
  1402. scope_t *pscope;
  1403. thead_t *ptag_head;
  1404. tag_t *ptag;
  1405. tag_t *ptag_next;
  1406. varray_t *vp;
  1407. int scope_delta = 0;
  1408. shash_t *hash_ptr = (shash_t *) NULL;
  1409. if (cur_file_ptr == (efdr_t *) NULL)
  1410. as_fatal (_("no current file pointer"));
  1411. vp = &cur_file_ptr->symbols;
  1412. if (vp->objects_last_page == vp->objects_per_page)
  1413. add_varray_page (vp);
  1414. psym = &vp->last->datum->sym[vp->objects_last_page++];
  1415. if (str == (const char *) NULL && sym_value != (symbolS *) NULL)
  1416. psym->name = S_GET_NAME (sym_value);
  1417. else
  1418. psym->name = str;
  1419. psym->as_sym = sym_value;
  1420. if (sym_value != (symbolS *) NULL)
  1421. symbol_get_obj (sym_value)->ecoff_symbol = psym;
  1422. psym->addend = addend;
  1423. psym->file_ptr = cur_file_ptr;
  1424. psym->proc_ptr = cur_proc_ptr;
  1425. psym->begin_ptr = (localsym_t *) NULL;
  1426. psym->index_ptr = (aux_t *) NULL;
  1427. psym->forward_ref = (forward_t *) NULL;
  1428. psym->sym_index = -1;
  1429. memset (&psym->ecoff_sym, 0, sizeof (EXTR));
  1430. psym->ecoff_sym.asym.value = value;
  1431. psym->ecoff_sym.asym.st = (unsigned) type;
  1432. psym->ecoff_sym.asym.sc = (unsigned) storage;
  1433. psym->ecoff_sym.asym.index = indx;
  1434. /* If there is an associated symbol, we wait until the end of the
  1435. assembly before deciding where to put the name (it may be just an
  1436. external symbol). Otherwise, this is just a debugging symbol and
  1437. the name should go with the current file. */
  1438. if (sym_value == (symbolS *) NULL)
  1439. psym->ecoff_sym.asym.iss = ((str == (const char *) NULL)
  1440. ? 0
  1441. : add_string (&cur_file_ptr->strings,
  1442. cur_file_ptr->str_hash,
  1443. str,
  1444. &hash_ptr));
  1445. ++vp->num_allocated;
  1446. if (ECOFF_IS_STAB (&psym->ecoff_sym.asym))
  1447. return psym;
  1448. /* Save the symbol within the hash table if this is a static
  1449. item, and it has a name. */
  1450. if (hash_ptr != (shash_t *) NULL
  1451. && (type == st_Global || type == st_Static || type == st_Label
  1452. || type == st_Proc || type == st_StaticProc))
  1453. hash_ptr->sym_ptr = psym;
  1454. /* push or pop a scope if appropriate. */
  1455. switch (type)
  1456. {
  1457. default:
  1458. break;
  1459. case st_File: /* beginning of file */
  1460. case st_Proc: /* procedure */
  1461. case st_StaticProc: /* static procedure */
  1462. case st_Block: /* begin scope */
  1463. pscope = allocate_scope ();
  1464. pscope->prev = cur_file_ptr->cur_scope;
  1465. pscope->lsym = psym;
  1466. pscope->type = type;
  1467. cur_file_ptr->cur_scope = pscope;
  1468. if (type != st_File)
  1469. scope_delta = 1;
  1470. /* For every block type except file, struct, union, or
  1471. enumeration blocks, push a level on the tag stack. We omit
  1472. file types, so that tags can span file boundaries. */
  1473. if (type != st_File && storage != sc_Info)
  1474. {
  1475. ptag_head = allocate_thead ();
  1476. ptag_head->first_tag = 0;
  1477. ptag_head->prev = cur_tag_head;
  1478. cur_tag_head = ptag_head;
  1479. }
  1480. break;
  1481. case st_End:
  1482. pscope = cur_file_ptr->cur_scope;
  1483. if (pscope == (scope_t *) NULL)
  1484. as_fatal (_("too many st_End's"));
  1485. else
  1486. {
  1487. st_t begin_type = (st_t) pscope->lsym->ecoff_sym.asym.st;
  1488. psym->begin_ptr = pscope->lsym;
  1489. if (begin_type != st_File)
  1490. scope_delta = -1;
  1491. /* Except for file, structure, union, or enumeration end
  1492. blocks remove all tags created within this scope. */
  1493. if (begin_type != st_File && storage != sc_Info)
  1494. {
  1495. ptag_head = cur_tag_head;
  1496. cur_tag_head = ptag_head->prev;
  1497. for (ptag = ptag_head->first_tag;
  1498. ptag != (tag_t *) NULL;
  1499. ptag = ptag_next)
  1500. {
  1501. if (ptag->forward_ref != (forward_t *) NULL)
  1502. add_unknown_tag (ptag);
  1503. ptag_next = ptag->same_block;
  1504. ptag->hash_ptr->tag_ptr = ptag->same_name;
  1505. free_tag (ptag);
  1506. }
  1507. free_thead (ptag_head);
  1508. }
  1509. cur_file_ptr->cur_scope = pscope->prev;
  1510. /* block begin gets next sym #. This is set when we know
  1511. the symbol index value. */
  1512. /* Functions push two or more aux words as follows:
  1513. 1st word: index+1 of the end symbol (filled in later).
  1514. 2nd word: type of the function (plus any aux words needed).
  1515. Also, tie the external pointer back to the function begin symbol. */
  1516. if (begin_type != st_File && begin_type != st_Block)
  1517. {
  1518. symint_t ty;
  1519. varray_t *svp = &cur_file_ptr->aux_syms;
  1520. pscope->lsym->ecoff_sym.asym.index = add_aux_sym_symint (0);
  1521. pscope->lsym->index_ptr =
  1522. &svp->last->datum->aux[svp->objects_last_page - 1];
  1523. ty = add_aux_sym_tir (&last_func_type_info,
  1524. hash_no,
  1525. &cur_file_ptr->thash_head[0]);
  1526. (void) ty;
  1527. /* This seems to be unnecessary. I'm not even sure what it is
  1528. * intended to do. It's from mips-tfile.
  1529. * if (last_func_sym_value != (symbolS *) NULL)
  1530. * {
  1531. * last_func_sym_value->ifd = cur_file_ptr->file_index;
  1532. * last_func_sym_value->index = ty;
  1533. * }
  1534. */
  1535. }
  1536. free_scope (pscope);
  1537. }
  1538. }
  1539. cur_file_ptr->nested_scopes += scope_delta;
  1540. #ifdef ECOFF_DEBUG
  1541. if (debug && type != st_File
  1542. && (debug > 2 || type == st_Block || type == st_End
  1543. || type == st_Proc || type == st_StaticProc))
  1544. {
  1545. char *sc_str = sc_to_string (storage);
  1546. char *st_str = st_to_string (type);
  1547. int depth = cur_file_ptr->nested_scopes + (scope_delta < 0);
  1548. fprintf (stderr,
  1549. "\tlsym\tv= %10ld, depth= %2d, sc= %-12s",
  1550. value, depth, sc_str);
  1551. if (str_start && str_end_p1 - str_start > 0)
  1552. fprintf (stderr, " st= %-11s name= %.*s\n",
  1553. st_str, str_end_p1 - str_start, str_start);
  1554. else
  1555. {
  1556. unsigned long len = strlen (st_str);
  1557. fprintf (stderr, " st= %.*s\n", len - 1, st_str);
  1558. }
  1559. }
  1560. #endif
  1561. return psym;
  1562. }
  1563. /* Add an auxiliary symbol (passing a symint). This is actually used
  1564. for integral aux types, not just symints. */
  1565. static symint_t
  1566. add_aux_sym_symint (symint_t aux_word /* auxiliary information word */)
  1567. {
  1568. varray_t *vp;
  1569. aux_t *aux_ptr;
  1570. if (cur_file_ptr == (efdr_t *) NULL)
  1571. as_fatal (_("no current file pointer"));
  1572. vp = &cur_file_ptr->aux_syms;
  1573. if (vp->objects_last_page == vp->objects_per_page)
  1574. add_varray_page (vp);
  1575. aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
  1576. aux_ptr->type = aux_isym;
  1577. aux_ptr->data.isym = aux_word;
  1578. return vp->num_allocated++;
  1579. }
  1580. /* Add an auxiliary symbol (passing a file/symbol index combo). */
  1581. static symint_t
  1582. add_aux_sym_rndx (int file_index, symint_t sym_index)
  1583. {
  1584. varray_t *vp;
  1585. aux_t *aux_ptr;
  1586. if (cur_file_ptr == (efdr_t *) NULL)
  1587. as_fatal (_("no current file pointer"));
  1588. vp = &cur_file_ptr->aux_syms;
  1589. if (vp->objects_last_page == vp->objects_per_page)
  1590. add_varray_page (vp);
  1591. aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
  1592. aux_ptr->type = aux_rndx;
  1593. aux_ptr->data.rndx.rfd = file_index;
  1594. aux_ptr->data.rndx.index = sym_index;
  1595. return vp->num_allocated++;
  1596. }
  1597. /* Add an auxiliary symbol (passing the basic type and possibly
  1598. type qualifiers). */
  1599. static symint_t
  1600. add_aux_sym_tir (type_info_t *t, /* current type information */
  1601. hash_state_t state, /* whether to hash type or not */
  1602. thash_t **hash_tbl /* pointer to hash table to use */)
  1603. {
  1604. varray_t *vp;
  1605. aux_t *aux_ptr;
  1606. static AUXU init_aux;
  1607. symint_t ret;
  1608. int i;
  1609. AUXU aux;
  1610. if (cur_file_ptr == (efdr_t *) NULL)
  1611. as_fatal (_("no current file pointer"));
  1612. vp = &cur_file_ptr->aux_syms;
  1613. aux = init_aux;
  1614. aux.ti.bt = (int) t->basic_type;
  1615. aux.ti.continued = 0;
  1616. aux.ti.fBitfield = t->bitfield;
  1617. aux.ti.tq0 = (int) t->type_qualifiers[0];
  1618. aux.ti.tq1 = (int) t->type_qualifiers[1];
  1619. aux.ti.tq2 = (int) t->type_qualifiers[2];
  1620. aux.ti.tq3 = (int) t->type_qualifiers[3];
  1621. aux.ti.tq4 = (int) t->type_qualifiers[4];
  1622. aux.ti.tq5 = (int) t->type_qualifiers[5];
  1623. /* For anything that adds additional information, we must not hash,
  1624. so check here, and reset our state. */
  1625. if (state != hash_no
  1626. && (t->type_qualifiers[0] == tq_Array
  1627. || t->type_qualifiers[1] == tq_Array
  1628. || t->type_qualifiers[2] == tq_Array
  1629. || t->type_qualifiers[3] == tq_Array
  1630. || t->type_qualifiers[4] == tq_Array
  1631. || t->type_qualifiers[5] == tq_Array
  1632. || t->basic_type == bt_Struct
  1633. || t->basic_type == bt_Union
  1634. || t->basic_type == bt_Enum
  1635. || t->bitfield
  1636. || t->num_dims > 0))
  1637. state = hash_no;
  1638. /* See if we can hash this type, and save some space, but some types
  1639. can't be hashed (because they contain arrays or continuations),
  1640. and others can be put into the hash list, but cannot use existing
  1641. types because other aux entries precede this one. */
  1642. if (state != hash_no)
  1643. {
  1644. thash_t *hash_ptr;
  1645. symint_t hi;
  1646. hi = aux.isym & ((1 << HASHBITS) - 1);
  1647. hi %= THASH_SIZE;
  1648. for (hash_ptr = hash_tbl[hi];
  1649. hash_ptr != (thash_t *)0;
  1650. hash_ptr = hash_ptr->next)
  1651. {
  1652. if (aux.isym == hash_ptr->type.isym)
  1653. break;
  1654. }
  1655. if (hash_ptr != (thash_t *) NULL && state == hash_yes)
  1656. return hash_ptr->indx;
  1657. if (hash_ptr == (thash_t *) NULL)
  1658. {
  1659. hash_ptr = allocate_thash ();
  1660. hash_ptr->next = hash_tbl[hi];
  1661. hash_ptr->type = aux;
  1662. hash_ptr->indx = vp->num_allocated;
  1663. hash_tbl[hi] = hash_ptr;
  1664. }
  1665. }
  1666. /* Everything is set up, add the aux symbol. */
  1667. if (vp->objects_last_page == vp->objects_per_page)
  1668. add_varray_page (vp);
  1669. aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
  1670. aux_ptr->type = aux_tir;
  1671. aux_ptr->data = aux;
  1672. ret = vp->num_allocated++;
  1673. /* Add bitfield length if it exists.
  1674. NOTE: Mips documentation claims bitfield goes at the end of the
  1675. AUX record, but the DECstation compiler emits it here.
  1676. (This would only make a difference for enum bitfields.)
  1677. Also note: We use the last size given since gcc may emit 2
  1678. for an enum bitfield. */
  1679. if (t->bitfield)
  1680. (void) add_aux_sym_symint ((symint_t) t->sizes[t->num_sizes - 1]);
  1681. /* Add tag information if needed. Structure, union, and enum
  1682. references add 2 aux symbols: a [file index, symbol index]
  1683. pointer to the structure type, and the current file index. */
  1684. if (t->basic_type == bt_Struct
  1685. || t->basic_type == bt_Union
  1686. || t->basic_type == bt_Enum)
  1687. {
  1688. symint_t file_index = t->tag_ptr->ifd;
  1689. localsym_t *sym = t->tag_ptr->sym;
  1690. forward_t *forward_ref = allocate_forward ();
  1691. if (sym != (localsym_t *) NULL)
  1692. {
  1693. forward_ref->next = sym->forward_ref;
  1694. sym->forward_ref = forward_ref;
  1695. }
  1696. else
  1697. {
  1698. forward_ref->next = t->tag_ptr->forward_ref;
  1699. t->tag_ptr->forward_ref = forward_ref;
  1700. }
  1701. (void) add_aux_sym_rndx (ST_RFDESCAPE, indexNil);
  1702. forward_ref->index_ptr
  1703. = &vp->last->datum->aux[vp->objects_last_page - 1];
  1704. (void) add_aux_sym_symint (file_index);
  1705. forward_ref->ifd_ptr
  1706. = &vp->last->datum->aux[vp->objects_last_page - 1];
  1707. }
  1708. /* Add information about array bounds if they exist. */
  1709. for (i = 0; i < t->num_dims; i++)
  1710. {
  1711. (void) add_aux_sym_rndx (ST_RFDESCAPE,
  1712. cur_file_ptr->int_type);
  1713. (void) add_aux_sym_symint (cur_file_ptr->file_index); /* file index*/
  1714. (void) add_aux_sym_symint ((symint_t) 0); /* low bound */
  1715. (void) add_aux_sym_symint (t->dimensions[i] - 1); /* high bound*/
  1716. (void) add_aux_sym_symint ((t->dimensions[i] == 0) /* stride */
  1717. ? 0
  1718. : (t->sizes[i] * 8) / t->dimensions[i]);
  1719. };
  1720. /* NOTE: Mips documentation claims that the bitfield width goes here.
  1721. But it needs to be emitted earlier. */
  1722. return ret;
  1723. }
  1724. /* Add a tag to the tag table (unless it already exists). */
  1725. static tag_t *
  1726. get_tag (const char *tag, /* tag name */
  1727. localsym_t *sym, /* tag start block */
  1728. bt_t basic_type /* bt_Struct, bt_Union, or bt_Enum */)
  1729. {
  1730. shash_t *hash_ptr;
  1731. const char *err;
  1732. tag_t *tag_ptr;
  1733. if (cur_file_ptr == (efdr_t *) NULL)
  1734. as_fatal (_("no current file pointer"));
  1735. hash_ptr = (shash_t *) hash_find (tag_hash, tag);
  1736. if (hash_ptr != (shash_t *) NULL
  1737. && hash_ptr->tag_ptr != (tag_t *) NULL)
  1738. {
  1739. tag_ptr = hash_ptr->tag_ptr;
  1740. if (sym != (localsym_t *) NULL)
  1741. {
  1742. tag_ptr->basic_type = basic_type;
  1743. tag_ptr->ifd = cur_file_ptr->file_index;
  1744. tag_ptr->sym = sym;
  1745. }
  1746. return tag_ptr;
  1747. }
  1748. if (hash_ptr == (shash_t *) NULL)
  1749. {
  1750. char *perm;
  1751. perm = xstrdup (tag);
  1752. hash_ptr = allocate_shash ();
  1753. err = hash_insert (tag_hash, perm, (char *) hash_ptr);
  1754. if (err)
  1755. as_fatal (_("inserting \"%s\" into tag hash table: %s"),
  1756. tag, err);
  1757. hash_ptr->string = perm;
  1758. }
  1759. tag_ptr = allocate_tag ();
  1760. tag_ptr->forward_ref = (forward_t *) NULL;
  1761. tag_ptr->hash_ptr = hash_ptr;
  1762. tag_ptr->same_name = hash_ptr->tag_ptr;
  1763. tag_ptr->basic_type = basic_type;
  1764. tag_ptr->sym = sym;
  1765. tag_ptr->ifd = ((sym == (localsym_t *) NULL)
  1766. ? (symint_t) -1
  1767. : cur_file_ptr->file_index);
  1768. tag_ptr->same_block = cur_tag_head->first_tag;
  1769. cur_tag_head->first_tag = tag_ptr;
  1770. hash_ptr->tag_ptr = tag_ptr;
  1771. return tag_ptr;
  1772. }
  1773. /* Add an unknown {struct, union, enum} tag. */
  1774. static void
  1775. add_unknown_tag (tag_t *ptag /* pointer to tag information */)
  1776. {
  1777. shash_t *hash_ptr = ptag->hash_ptr;
  1778. char *name = hash_ptr->string;
  1779. localsym_t *sym;
  1780. forward_t **pf;
  1781. #ifdef ECOFF_DEBUG
  1782. if (debug > 1)
  1783. {
  1784. char *agg_type = "{unknown aggregate type}";
  1785. switch (ptag->basic_type)
  1786. {
  1787. case bt_Struct: agg_type = "struct"; break;
  1788. case bt_Union: agg_type = "union"; break;
  1789. case bt_Enum: agg_type = "enum"; break;
  1790. default: break;
  1791. }
  1792. fprintf (stderr, "unknown %s %.*s found\n", agg_type,
  1793. hash_ptr->len, name_start);
  1794. }
  1795. #endif
  1796. sym = add_ecoff_symbol (name,
  1797. st_Block,
  1798. sc_Info,
  1799. (symbolS *) NULL,
  1800. (bfd_vma) 0,
  1801. (symint_t) 0,
  1802. (symint_t) 0);
  1803. (void) add_ecoff_symbol (name,
  1804. st_End,
  1805. sc_Info,
  1806. (symbolS *) NULL,
  1807. (bfd_vma) 0,
  1808. (symint_t) 0,
  1809. (symint_t) 0);
  1810. for (pf = &sym->forward_ref; *pf != (forward_t *) NULL; pf = &(*pf)->next)
  1811. ;
  1812. *pf = ptag->forward_ref;
  1813. }
  1814. /* Add a procedure to the current file's list of procedures, and record
  1815. this is the current procedure. */
  1816. static void
  1817. add_procedure (char *func /* func name */)
  1818. {
  1819. varray_t *vp;
  1820. proc_t *new_proc_ptr;
  1821. symbolS *sym;
  1822. #ifdef ECOFF_DEBUG
  1823. if (debug)
  1824. fputc ('\n', stderr);
  1825. #endif
  1826. if (cur_file_ptr == (efdr_t *) NULL)
  1827. as_fatal (_("no current file pointer"));
  1828. vp = &cur_file_ptr->procs;
  1829. if (vp->objects_last_page == vp->objects_per_page)
  1830. add_varray_page (vp);
  1831. cur_proc_ptr = new_proc_ptr = &vp->last->datum->proc[vp->objects_last_page++];
  1832. if (first_proc_ptr == (proc_t *) NULL)
  1833. first_proc_ptr = new_proc_ptr;
  1834. vp->num_allocated++;
  1835. new_proc_ptr->pdr.isym = -1;
  1836. new_proc_ptr->pdr.iline = -1;
  1837. new_proc_ptr->pdr.lnLow = -1;
  1838. new_proc_ptr->pdr.lnHigh = -1;
  1839. /* Set the BSF_FUNCTION flag for the symbol. */
  1840. sym = symbol_find_or_make (func);
  1841. symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
  1842. /* Push the start of the function. */
  1843. new_proc_ptr->sym = add_ecoff_symbol ((const char *) NULL, st_Proc, sc_Text,
  1844. sym, (bfd_vma) 0, (symint_t) 0,
  1845. (symint_t) 0);
  1846. ++proc_cnt;
  1847. /* Fill in the linenos preceding the .ent, if any. */
  1848. if (noproc_lineno != (lineno_list_t *) NULL)
  1849. {
  1850. lineno_list_t *l;
  1851. for (l = noproc_lineno; l != (lineno_list_t *) NULL; l = l->next)
  1852. l->proc = new_proc_ptr;
  1853. *last_lineno_ptr = noproc_lineno;
  1854. while (*last_lineno_ptr != NULL)
  1855. {
  1856. last_lineno = *last_lineno_ptr;
  1857. last_lineno_ptr = &last_lineno->next;
  1858. }
  1859. noproc_lineno = (lineno_list_t *) NULL;
  1860. }
  1861. }
  1862. symbolS *
  1863. ecoff_get_cur_proc_sym (void)
  1864. {
  1865. return (cur_proc_ptr ? cur_proc_ptr->sym->as_sym : NULL);
  1866. }
  1867. /* Add a new filename, and set up all of the file relative
  1868. virtual arrays (strings, symbols, aux syms, etc.). Record
  1869. where the current file structure lives. */
  1870. static void
  1871. add_file (const char *file_name, int indx ATTRIBUTE_UNUSED, int fake)
  1872. {
  1873. int first_ch;
  1874. efdr_t *fil_ptr;
  1875. #ifdef ECOFF_DEBUG
  1876. if (debug)
  1877. fprintf (stderr, "\tfile\t%.*s\n", len, file_start);
  1878. #endif
  1879. /* If the file name is NULL, then no .file symbol appeared, and we
  1880. want to use the actual file name. */
  1881. if (file_name == (const char *) NULL)
  1882. {
  1883. char *file;
  1884. if (first_file != (efdr_t *) NULL)
  1885. as_fatal (_("fake .file after real one"));
  1886. as_where (&file, (unsigned int *) NULL);
  1887. file_name = (const char *) file;
  1888. /* Automatically generate ECOFF debugging information, since I
  1889. think that's what other ECOFF assemblers do. We don't do
  1890. this if we see a .file directive with a string, since that
  1891. implies that some sort of debugging information is being
  1892. provided. */
  1893. if (! symbol_table_frozen && debug_type == DEBUG_UNSPECIFIED)
  1894. debug_type = DEBUG_ECOFF;
  1895. }
  1896. else if (debug_type == DEBUG_UNSPECIFIED)
  1897. debug_type = DEBUG_NONE;
  1898. #ifndef NO_LISTING
  1899. if (listing)
  1900. listing_source_file (file_name);
  1901. #endif
  1902. current_stabs_filename = file_name;
  1903. /* If we're creating stabs, then we don't actually make a new FDR.
  1904. Instead, we just create a stabs symbol. */
  1905. if (stabs_seen)
  1906. {
  1907. (void) add_ecoff_symbol (file_name, st_Nil, sc_Nil,
  1908. symbol_new ("L0\001", now_seg,
  1909. (valueT) frag_now_fix (),
  1910. frag_now),
  1911. (bfd_vma) 0, 0, ECOFF_MARK_STAB (N_SOL));
  1912. return;
  1913. }
  1914. first_ch = *file_name;
  1915. /* FIXME: We can't safely merge files which have line number
  1916. information (fMerge will be zero in this case). Otherwise, we
  1917. get incorrect line number debugging info. See for instance
  1918. ecoff_build_lineno, which will end up setting all file->fdr.*
  1919. fields multiple times, resulting in incorrect debug info. In
  1920. order to make this work right, all line number and symbol info
  1921. for the same source file has to be adjacent in the object file,
  1922. so that a single file descriptor can be used to point to them.
  1923. This would require maintaining file specific lists of line
  1924. numbers and symbols for each file, so that they can be merged
  1925. together (or output together) when two .file pseudo-ops are
  1926. merged into one file descriptor. */
  1927. /* See if the file has already been created. */
  1928. for (fil_ptr = first_file;
  1929. fil_ptr != (efdr_t *) NULL;
  1930. fil_ptr = fil_ptr->next_file)
  1931. {
  1932. if (first_ch == fil_ptr->name[0]
  1933. && filename_cmp (file_name, fil_ptr->name) == 0
  1934. && fil_ptr->fdr.fMerge)
  1935. {
  1936. cur_file_ptr = fil_ptr;
  1937. if (! fake)
  1938. cur_file_ptr->fake = 0;
  1939. break;
  1940. }
  1941. }
  1942. /* If this is a new file, create it. */
  1943. if (fil_ptr == (efdr_t *) NULL)
  1944. {
  1945. if (file_desc.objects_last_page == file_desc.objects_per_page)
  1946. add_varray_page (&file_desc);
  1947. fil_ptr = cur_file_ptr =
  1948. &file_desc.last->datum->file[file_desc.objects_last_page++];
  1949. *fil_ptr = init_file;
  1950. fil_ptr->file_index = current_file_idx++;
  1951. ++file_desc.num_allocated;
  1952. fil_ptr->fake = fake;
  1953. /* Allocate the string hash table. */
  1954. fil_ptr->str_hash = hash_new ();
  1955. /* Make sure 0 byte in string table is null */
  1956. add_string (&fil_ptr->strings,
  1957. fil_ptr->str_hash,
  1958. "",
  1959. (shash_t **)0);
  1960. if (strlen (file_name) > PAGE_USIZE - 2)
  1961. as_fatal (_("filename goes over one page boundary"));
  1962. /* Push the start of the filename. We assume that the filename
  1963. will be stored at string offset 1. */
  1964. (void) add_ecoff_symbol (file_name, st_File, sc_Text,
  1965. (symbolS *) NULL, (bfd_vma) 0,
  1966. (symint_t) 0, (symint_t) 0);
  1967. fil_ptr->fdr.rss = 1;
  1968. fil_ptr->name = &fil_ptr->strings.last->datum->byte[1];
  1969. /* Update the linked list of file descriptors. */
  1970. *last_file_ptr = fil_ptr;
  1971. last_file_ptr = &fil_ptr->next_file;
  1972. /* Add void & int types to the file (void should be first to catch
  1973. errant 0's within the index fields). */
  1974. fil_ptr->void_type = add_aux_sym_tir (&void_type_info,
  1975. hash_yes,
  1976. &cur_file_ptr->thash_head[0]);
  1977. fil_ptr->int_type = add_aux_sym_tir (&int_type_info,
  1978. hash_yes,
  1979. &cur_file_ptr->thash_head[0]);
  1980. }
  1981. }
  1982. /* This function is called when the assembler notices a preprocessor
  1983. directive switching to a new file. This will not happen in
  1984. compiler output, only in hand coded assembler. */
  1985. void
  1986. ecoff_new_file (const char *name, int appfile ATTRIBUTE_UNUSED)
  1987. {
  1988. if (cur_file_ptr != NULL && filename_cmp (cur_file_ptr->name, name) == 0)
  1989. return;
  1990. add_file (name, 0, 0);
  1991. /* This is a hand coded assembler file, so automatically turn on
  1992. debugging information. */
  1993. if (debug_type == DEBUG_UNSPECIFIED)
  1994. debug_type = DEBUG_ECOFF;
  1995. }
  1996. #ifdef ECOFF_DEBUG
  1997. /* Convert storage class to string. */
  1998. static char *
  1999. sc_to_string (storage_class)
  2000. sc_t storage_class;
  2001. {
  2002. switch (storage_class)
  2003. {
  2004. case sc_Nil: return "Nil,";
  2005. case sc_Text: return "Text,";
  2006. case sc_Data: return "Data,";
  2007. case sc_Bss: return "Bss,";
  2008. case sc_Register: return "Register,";
  2009. case sc_Abs: return "Abs,";
  2010. case sc_Undefined: return "Undefined,";
  2011. case sc_CdbLocal: return "CdbLocal,";
  2012. case sc_Bits: return "Bits,";
  2013. case sc_CdbSystem: return "CdbSystem,";
  2014. case sc_RegImage: return "RegImage,";
  2015. case sc_Info: return "Info,";
  2016. case sc_UserStruct: return "UserStruct,";
  2017. case sc_SData: return "SData,";
  2018. case sc_SBss: return "SBss,";
  2019. case sc_RData: return "RData,";
  2020. case sc_Var: return "Var,";
  2021. case sc_Common: return "Common,";
  2022. case sc_SCommon: return "SCommon,";
  2023. case sc_VarRegister: return "VarRegister,";
  2024. case sc_Variant: return "Variant,";
  2025. case sc_SUndefined: return "SUndefined,";
  2026. case sc_Init: return "Init,";
  2027. case sc_Max: return "Max,";
  2028. }
  2029. return "???,";
  2030. }
  2031. #endif /* DEBUG */
  2032. #ifdef ECOFF_DEBUG
  2033. /* Convert symbol type to string. */
  2034. static char *
  2035. st_to_string (symbol_type)
  2036. st_t symbol_type;
  2037. {
  2038. switch (symbol_type)
  2039. {
  2040. case st_Nil: return "Nil,";
  2041. case st_Global: return "Global,";
  2042. case st_Static: return "Static,";
  2043. case st_Param: return "Param,";
  2044. case st_Local: return "Local,";
  2045. case st_Label: return "Label,";
  2046. case st_Proc: return "Proc,";
  2047. case st_Block: return "Block,";
  2048. case st_End: return "End,";
  2049. case st_Member: return "Member,";
  2050. case st_Typedef: return "Typedef,";
  2051. case st_File: return "File,";
  2052. case st_RegReloc: return "RegReloc,";
  2053. case st_Forward: return "Forward,";
  2054. case st_StaticProc: return "StaticProc,";
  2055. case st_Constant: return "Constant,";
  2056. case st_Str: return "String,";
  2057. case st_Number: return "Number,";
  2058. case st_Expr: return "Expr,";
  2059. case st_Type: return "Type,";
  2060. case st_Max: return "Max,";
  2061. }
  2062. return "???,";
  2063. }
  2064. #endif /* DEBUG */
  2065. /* Parse .begin directives which have a label as the first argument
  2066. which gives the location of the start of the block. */
  2067. void
  2068. ecoff_directive_begin (int ignore ATTRIBUTE_UNUSED)
  2069. {
  2070. char *name;
  2071. char name_end;
  2072. if (cur_file_ptr == (efdr_t *) NULL)
  2073. {
  2074. as_warn (_(".begin directive without a preceding .file directive"));
  2075. demand_empty_rest_of_line ();
  2076. return;
  2077. }
  2078. if (cur_proc_ptr == (proc_t *) NULL)
  2079. {
  2080. as_warn (_(".begin directive without a preceding .ent directive"));
  2081. demand_empty_rest_of_line ();
  2082. return;
  2083. }
  2084. name_end = get_symbol_name (&name);
  2085. (void) add_ecoff_symbol ((const char *) NULL, st_Block, sc_Text,
  2086. symbol_find_or_make (name),
  2087. (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
  2088. (void) restore_line_pointer (name_end);
  2089. /* The line number follows, but we don't use it. */
  2090. (void) get_absolute_expression ();
  2091. demand_empty_rest_of_line ();
  2092. }
  2093. /* Parse .bend directives which have a label as the first argument
  2094. which gives the location of the end of the block. */
  2095. void
  2096. ecoff_directive_bend (int ignore ATTRIBUTE_UNUSED)
  2097. {
  2098. char *name;
  2099. char name_end;
  2100. symbolS *endsym;
  2101. if (cur_file_ptr == (efdr_t *) NULL)
  2102. {
  2103. as_warn (_(".bend directive without a preceding .file directive"));
  2104. demand_empty_rest_of_line ();
  2105. return;
  2106. }
  2107. if (cur_proc_ptr == (proc_t *) NULL)
  2108. {
  2109. as_warn (_(".bend directive without a preceding .ent directive"));
  2110. demand_empty_rest_of_line ();
  2111. return;
  2112. }
  2113. name_end = get_symbol_name (&name);
  2114. /* The value is the distance between the .bend directive and the
  2115. corresponding symbol. We fill in the offset when we write out
  2116. the symbol. */
  2117. endsym = symbol_find (name);
  2118. if (endsym == (symbolS *) NULL)
  2119. as_warn (_(".bend directive names unknown symbol"));
  2120. else
  2121. (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text, endsym,
  2122. (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
  2123. restore_line_pointer (name_end);
  2124. /* The line number follows, but we don't use it. */
  2125. (void) get_absolute_expression ();
  2126. demand_empty_rest_of_line ();
  2127. }
  2128. /* COFF debugging information is provided as a series of directives
  2129. (.def, .scl, etc.). We build up information as we read the
  2130. directives in the following static variables, and file it away when
  2131. we reach the .endef directive. */
  2132. static char *coff_sym_name;
  2133. static type_info_t coff_type;
  2134. static sc_t coff_storage_class;
  2135. static st_t coff_symbol_typ;
  2136. static int coff_is_function;
  2137. static char *coff_tag;
  2138. static valueT coff_value;
  2139. static symbolS *coff_sym_value;
  2140. static bfd_vma coff_sym_addend;
  2141. static int coff_inside_enumeration;
  2142. /* Handle a .def directive: start defining a symbol. */
  2143. void
  2144. ecoff_directive_def (int ignore ATTRIBUTE_UNUSED)
  2145. {
  2146. char *name;
  2147. char name_end;
  2148. ecoff_debugging_seen = 1;
  2149. SKIP_WHITESPACE ();
  2150. name_end = get_symbol_name (&name);
  2151. if (coff_sym_name != (char *) NULL)
  2152. as_warn (_(".def pseudo-op used inside of .def/.endef; ignored"));
  2153. else if (*name == '\0')
  2154. as_warn (_("empty symbol name in .def; ignored"));
  2155. else
  2156. {
  2157. if (coff_sym_name != (char *) NULL)
  2158. free (coff_sym_name);
  2159. if (coff_tag != (char *) NULL)
  2160. free (coff_tag);
  2161. coff_sym_name = xstrdup (name);
  2162. coff_type = type_info_init;
  2163. coff_storage_class = sc_Nil;
  2164. coff_symbol_typ = st_Nil;
  2165. coff_is_function = 0;
  2166. coff_tag = (char *) NULL;
  2167. coff_value = 0;
  2168. coff_sym_value = (symbolS *) NULL;
  2169. coff_sym_addend = 0;
  2170. }
  2171. restore_line_pointer (name_end);
  2172. demand_empty_rest_of_line ();
  2173. }
  2174. /* Handle a .dim directive, used to give dimensions for an array. The
  2175. arguments are comma separated numbers. mips-tfile assumes that
  2176. there will not be more than 6 dimensions, and gdb won't read any
  2177. more than that anyhow, so I will also make that assumption. */
  2178. void
  2179. ecoff_directive_dim (int ignore ATTRIBUTE_UNUSED)
  2180. {
  2181. int dimens[N_TQ];
  2182. int i;
  2183. if (coff_sym_name == (char *) NULL)
  2184. {
  2185. as_warn (_(".dim pseudo-op used outside of .def/.endef; ignored"));
  2186. demand_empty_rest_of_line ();
  2187. return;
  2188. }
  2189. for (i = 0; i < N_TQ; i++)
  2190. {
  2191. SKIP_WHITESPACE ();
  2192. dimens[i] = get_absolute_expression ();
  2193. if (*input_line_pointer == ',')
  2194. ++input_line_pointer;
  2195. else
  2196. {
  2197. if (*input_line_pointer != '\n'
  2198. && *input_line_pointer != ';')
  2199. as_warn (_("badly formed .dim directive"));
  2200. break;
  2201. }
  2202. }
  2203. if (i == N_TQ)
  2204. --i;
  2205. /* The dimensions are stored away in reverse order. */
  2206. for (; i >= 0; i--)
  2207. {
  2208. if (coff_type.num_dims >= N_TQ)
  2209. {
  2210. as_warn (_("too many .dim entries"));
  2211. break;
  2212. }
  2213. coff_type.dimensions[coff_type.num_dims] = dimens[i];
  2214. ++coff_type.num_dims;
  2215. }
  2216. demand_empty_rest_of_line ();
  2217. }
  2218. /* Handle a .scl directive, which sets the COFF storage class of the
  2219. symbol. */
  2220. void
  2221. ecoff_directive_scl (int ignore ATTRIBUTE_UNUSED)
  2222. {
  2223. long val;
  2224. if (coff_sym_name == (char *) NULL)
  2225. {
  2226. as_warn (_(".scl pseudo-op used outside of .def/.endef; ignored"));
  2227. demand_empty_rest_of_line ();
  2228. return;
  2229. }
  2230. val = get_absolute_expression ();
  2231. coff_symbol_typ = map_coff_sym_type[val];
  2232. coff_storage_class = map_coff_storage[val];
  2233. demand_empty_rest_of_line ();
  2234. }
  2235. /* Handle a .size directive. For some reason mips-tfile.c thinks that
  2236. .size can have multiple arguments. We humor it, although gcc will
  2237. never generate more than one argument. */
  2238. void
  2239. ecoff_directive_size (int ignore ATTRIBUTE_UNUSED)
  2240. {
  2241. int sizes[N_TQ];
  2242. int i;
  2243. if (coff_sym_name == (char *) NULL)
  2244. {
  2245. as_warn (_(".size pseudo-op used outside of .def/.endef; ignored"));
  2246. demand_empty_rest_of_line ();
  2247. return;
  2248. }
  2249. for (i = 0; i < N_TQ; i++)
  2250. {
  2251. SKIP_WHITESPACE ();
  2252. sizes[i] = get_absolute_expression ();
  2253. if (*input_line_pointer == ',')
  2254. ++input_line_pointer;
  2255. else
  2256. {
  2257. if (*input_line_pointer != '\n'
  2258. && *input_line_pointer != ';')
  2259. as_warn (_("badly formed .size directive"));
  2260. break;
  2261. }
  2262. }
  2263. if (i == N_TQ)
  2264. --i;
  2265. /* The sizes are stored away in reverse order. */
  2266. for (; i >= 0; i--)
  2267. {
  2268. if (coff_type.num_sizes >= N_TQ)
  2269. {
  2270. as_warn (_("too many .size entries"));
  2271. break;
  2272. }
  2273. coff_type.sizes[coff_type.num_sizes] = sizes[i];
  2274. ++coff_type.num_sizes;
  2275. }
  2276. demand_empty_rest_of_line ();
  2277. }
  2278. /* Handle the .type directive, which gives the COFF type of the
  2279. symbol. */
  2280. void
  2281. ecoff_directive_type (int ignore ATTRIBUTE_UNUSED)
  2282. {
  2283. long val;
  2284. tq_t *tq_ptr;
  2285. tq_t *tq_shft;
  2286. if (coff_sym_name == (char *) NULL)
  2287. {
  2288. as_warn (_(".type pseudo-op used outside of .def/.endef; ignored"));
  2289. demand_empty_rest_of_line ();
  2290. return;
  2291. }
  2292. val = get_absolute_expression ();
  2293. coff_type.orig_type = BTYPE (val);
  2294. coff_type.basic_type = map_coff_types[coff_type.orig_type];
  2295. tq_ptr = &coff_type.type_qualifiers[N_TQ];
  2296. while (val & ~N_BTMASK)
  2297. {
  2298. if (tq_ptr == &coff_type.type_qualifiers[0])
  2299. {
  2300. /* FIXME: We could handle this by setting the continued bit.
  2301. There would still be a limit: the .type argument can not
  2302. be infinite. */
  2303. as_warn (_("the type of %s is too complex; it will be simplified"),
  2304. coff_sym_name);
  2305. break;
  2306. }
  2307. if (ISPTR (val))
  2308. *--tq_ptr = tq_Ptr;
  2309. else if (ISFCN (val))
  2310. *--tq_ptr = tq_Proc;
  2311. else if (ISARY (val))
  2312. *--tq_ptr = tq_Array;
  2313. else
  2314. as_fatal (_("Unrecognized .type argument"));
  2315. val = DECREF (val);
  2316. }
  2317. tq_shft = &coff_type.type_qualifiers[0];
  2318. while (tq_ptr != &coff_type.type_qualifiers[N_TQ])
  2319. *tq_shft++ = *tq_ptr++;
  2320. if (tq_shft != &coff_type.type_qualifiers[0] && tq_shft[-1] == tq_Proc)
  2321. {
  2322. /* If this is a function, ignore it, so that we don't get two
  2323. entries (one from the .ent, and one for the .def that
  2324. precedes it). Save the type information so that the end
  2325. block can properly add it after the begin block index. For
  2326. MIPS knows what reason, we must strip off the function type
  2327. at this point. */
  2328. coff_is_function = 1;
  2329. tq_shft[-1] = tq_Nil;
  2330. }
  2331. while (tq_shft != &coff_type.type_qualifiers[N_TQ])
  2332. *tq_shft++ = tq_Nil;
  2333. demand_empty_rest_of_line ();
  2334. }
  2335. /* Handle the .tag directive, which gives the name of a structure,
  2336. union or enum. */
  2337. void
  2338. ecoff_directive_tag (int ignore ATTRIBUTE_UNUSED)
  2339. {
  2340. char *name;
  2341. char name_end;
  2342. if (coff_sym_name == (char *) NULL)
  2343. {
  2344. as_warn (_(".tag pseudo-op used outside of .def/.endef; ignored"));
  2345. demand_empty_rest_of_line ();
  2346. return;
  2347. }
  2348. name_end = get_symbol_name (&name);
  2349. coff_tag = xstrdup (name);
  2350. (void) restore_line_pointer (name_end);
  2351. demand_empty_rest_of_line ();
  2352. }
  2353. /* Handle the .val directive, which gives the value of the symbol. It
  2354. may be the name of a static or global symbol. */
  2355. void
  2356. ecoff_directive_val (int ignore ATTRIBUTE_UNUSED)
  2357. {
  2358. expressionS exp;
  2359. if (coff_sym_name == (char *) NULL)
  2360. {
  2361. as_warn (_(".val pseudo-op used outside of .def/.endef; ignored"));
  2362. demand_empty_rest_of_line ();
  2363. return;
  2364. }
  2365. expression (&exp);
  2366. if (exp.X_op != O_constant && exp.X_op != O_symbol)
  2367. {
  2368. as_bad (_(".val expression is too complex"));
  2369. demand_empty_rest_of_line ();
  2370. return;
  2371. }
  2372. if (exp.X_op == O_constant)
  2373. coff_value = exp.X_add_number;
  2374. else
  2375. {
  2376. coff_sym_value = exp.X_add_symbol;
  2377. coff_sym_addend = exp.X_add_number;
  2378. }
  2379. demand_empty_rest_of_line ();
  2380. }
  2381. /* Handle the .endef directive, which terminates processing of COFF
  2382. debugging information for a symbol. */
  2383. void
  2384. ecoff_directive_endef (int ignore ATTRIBUTE_UNUSED)
  2385. {
  2386. char *name;
  2387. symint_t indx;
  2388. localsym_t *sym;
  2389. demand_empty_rest_of_line ();
  2390. if (coff_sym_name == (char *) NULL)
  2391. {
  2392. as_warn (_(".endef pseudo-op used before .def; ignored"));
  2393. return;
  2394. }
  2395. name = coff_sym_name;
  2396. coff_sym_name = (char *) NULL;
  2397. /* If the symbol is a static or external, we have already gotten the
  2398. appropriate type and class, so make sure we don't override those
  2399. values. This is needed because there are some type and classes
  2400. that are not in COFF, such as short data, etc. */
  2401. if (coff_sym_value != (symbolS *) NULL)
  2402. {
  2403. coff_symbol_typ = st_Nil;
  2404. coff_storage_class = sc_Nil;
  2405. }
  2406. coff_type.extra_sizes = coff_tag != (char *) NULL;
  2407. if (coff_type.num_dims > 0)
  2408. {
  2409. int diff = coff_type.num_dims - coff_type.num_sizes;
  2410. int i = coff_type.num_dims - 1;
  2411. int j;
  2412. if (coff_type.num_sizes != 1 || diff < 0)
  2413. {
  2414. as_warn (_("bad COFF debugging information"));
  2415. return;
  2416. }
  2417. /* If this is an array, make sure the same number of dimensions
  2418. and sizes were passed, creating extra sizes for multiply
  2419. dimensioned arrays if not passed. */
  2420. coff_type.extra_sizes = 0;
  2421. if (diff)
  2422. {
  2423. j = (sizeof (coff_type.sizes) / sizeof (coff_type.sizes[0])) - 1;
  2424. while (j >= 0)
  2425. {
  2426. coff_type.sizes[j] = (((j - diff) >= 0)
  2427. ? coff_type.sizes[j - diff]
  2428. : 0);
  2429. j--;
  2430. }
  2431. coff_type.num_sizes = i + 1;
  2432. for (i--; i >= 0; i--)
  2433. coff_type.sizes[i] = (coff_type.dimensions[i + 1] == 0
  2434. ? 0
  2435. : (coff_type.sizes[i + 1]
  2436. / coff_type.dimensions[i + 1]));
  2437. }
  2438. }
  2439. else if (coff_symbol_typ == st_Member
  2440. && coff_type.num_sizes - coff_type.extra_sizes == 1)
  2441. {
  2442. /* Is this a bitfield? This is indicated by a structure member
  2443. having a size field that isn't an array. */
  2444. coff_type.bitfield = 1;
  2445. }
  2446. /* Except for enumeration members & begin/ending of scopes, put the
  2447. type word in the aux. symbol table. */
  2448. if (coff_symbol_typ == st_Block || coff_symbol_typ == st_End)
  2449. indx = 0;
  2450. else if (coff_inside_enumeration)
  2451. indx = cur_file_ptr->void_type;
  2452. else
  2453. {
  2454. if (coff_type.basic_type == bt_Struct
  2455. || coff_type.basic_type == bt_Union
  2456. || coff_type.basic_type == bt_Enum)
  2457. {
  2458. if (coff_tag == (char *) NULL)
  2459. {
  2460. as_warn (_("no tag specified for %s"), name);
  2461. return;
  2462. }
  2463. coff_type.tag_ptr = get_tag (coff_tag, (localsym_t *) NULL,
  2464. coff_type.basic_type);
  2465. }
  2466. if (coff_is_function)
  2467. {
  2468. last_func_type_info = coff_type;
  2469. last_func_sym_value = coff_sym_value;
  2470. return;
  2471. }
  2472. indx = add_aux_sym_tir (&coff_type,
  2473. hash_yes,
  2474. &cur_file_ptr->thash_head[0]);
  2475. }
  2476. /* Do any last minute adjustments that are necessary. */
  2477. switch (coff_symbol_typ)
  2478. {
  2479. default:
  2480. break;
  2481. /* For the beginning of structs, unions, and enumerations, the
  2482. size info needs to be passed in the value field. */
  2483. case st_Block:
  2484. if (coff_type.num_sizes - coff_type.num_dims - coff_type.extra_sizes
  2485. != 1)
  2486. {
  2487. as_warn (_("bad COFF debugging information"));
  2488. return;
  2489. }
  2490. else
  2491. coff_value = coff_type.sizes[0];
  2492. coff_inside_enumeration = (coff_type.orig_type == T_ENUM);
  2493. break;
  2494. /* For the end of structs, unions, and enumerations, omit the
  2495. name which is always ".eos". This needs to be done last, so
  2496. that any error reporting above gives the correct name. */
  2497. case st_End:
  2498. free (name);
  2499. name = (char *) NULL;
  2500. coff_value = 0;
  2501. coff_inside_enumeration = 0;
  2502. break;
  2503. /* Members of structures and unions that aren't bitfields, need
  2504. to adjust the value from a byte offset to a bit offset.
  2505. Members of enumerations do not have the value adjusted, and
  2506. can be distinguished by indx == indexNil. For enumerations,
  2507. update the maximum enumeration value. */
  2508. case st_Member:
  2509. if (! coff_type.bitfield && ! coff_inside_enumeration)
  2510. coff_value *= 8;
  2511. break;
  2512. }
  2513. /* Add the symbol. */
  2514. sym = add_ecoff_symbol (name,
  2515. coff_symbol_typ,
  2516. coff_storage_class,
  2517. coff_sym_value,
  2518. coff_sym_addend,
  2519. (symint_t) coff_value,
  2520. indx);
  2521. /* deal with struct, union, and enum tags. */
  2522. if (coff_symbol_typ == st_Block)
  2523. {
  2524. /* Create or update the tag information. */
  2525. tag_t *tag_ptr = get_tag (name,
  2526. sym,
  2527. coff_type.basic_type);
  2528. forward_t **pf;
  2529. /* Remember any forward references. */
  2530. for (pf = &sym->forward_ref;
  2531. *pf != (forward_t *) NULL;
  2532. pf = &(*pf)->next)
  2533. ;
  2534. *pf = tag_ptr->forward_ref;
  2535. tag_ptr->forward_ref = (forward_t *) NULL;
  2536. }
  2537. }
  2538. /* Parse .end directives. */
  2539. void
  2540. ecoff_directive_end (int ignore ATTRIBUTE_UNUSED)
  2541. {
  2542. char *name;
  2543. char name_end;
  2544. symbolS *ent;
  2545. if (cur_file_ptr == (efdr_t *) NULL)
  2546. {
  2547. as_warn (_(".end directive without a preceding .file directive"));
  2548. demand_empty_rest_of_line ();
  2549. return;
  2550. }
  2551. if (cur_proc_ptr == (proc_t *) NULL)
  2552. {
  2553. as_warn (_(".end directive without a preceding .ent directive"));
  2554. demand_empty_rest_of_line ();
  2555. return;
  2556. }
  2557. name_end = get_symbol_name (&name);
  2558. if (name == input_line_pointer)
  2559. {
  2560. as_warn (_(".end directive has no name"));
  2561. (void) restore_line_pointer (name_end);
  2562. demand_empty_rest_of_line ();
  2563. return;
  2564. }
  2565. /* The value is the distance between the .end directive and the
  2566. corresponding symbol. We create a fake symbol to hold the
  2567. current location, and put in the offset when we write out the
  2568. symbol. */
  2569. ent = symbol_find (name);
  2570. if (ent == (symbolS *) NULL)
  2571. as_warn (_(".end directive names unknown symbol"));
  2572. else
  2573. (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text,
  2574. symbol_new ("L0\001", now_seg,
  2575. (valueT) frag_now_fix (),
  2576. frag_now),
  2577. (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
  2578. cur_proc_ptr = (proc_t *) NULL;
  2579. (void) restore_line_pointer (name_end);
  2580. demand_empty_rest_of_line ();
  2581. }
  2582. /* Parse .ent directives. */
  2583. void
  2584. ecoff_directive_ent (int ignore ATTRIBUTE_UNUSED)
  2585. {
  2586. char *name;
  2587. char name_end;
  2588. if (cur_file_ptr == (efdr_t *) NULL)
  2589. add_file ((const char *) NULL, 0, 1);
  2590. if (cur_proc_ptr != (proc_t *) NULL)
  2591. {
  2592. as_warn (_("second .ent directive found before .end directive"));
  2593. demand_empty_rest_of_line ();
  2594. return;
  2595. }
  2596. name_end = get_symbol_name (&name);
  2597. if (name == input_line_pointer)
  2598. {
  2599. as_warn (_(".ent directive has no name"));
  2600. (void) restore_line_pointer (name_end);
  2601. demand_empty_rest_of_line ();
  2602. return;
  2603. }
  2604. add_procedure (name);
  2605. (void) restore_line_pointer (name_end);
  2606. /* The .ent directive is sometimes followed by a number. I'm not
  2607. really sure what the number means. I don't see any way to store
  2608. the information in the PDR. The Irix 4 assembler seems to ignore
  2609. the information. */
  2610. SKIP_WHITESPACE ();
  2611. if (*input_line_pointer == ',')
  2612. {
  2613. ++input_line_pointer;
  2614. SKIP_WHITESPACE ();
  2615. }
  2616. if (ISDIGIT (*input_line_pointer)
  2617. || *input_line_pointer == '-')
  2618. (void) get_absolute_expression ();
  2619. demand_empty_rest_of_line ();
  2620. }
  2621. /* Parse .extern directives. */
  2622. void
  2623. ecoff_directive_extern (int ignore ATTRIBUTE_UNUSED)
  2624. {
  2625. char *name;
  2626. int c;
  2627. symbolS *symbolp;
  2628. valueT size;
  2629. c = get_symbol_name (&name);
  2630. symbolp = symbol_find_or_make (name);
  2631. (void) restore_line_pointer (c);
  2632. S_SET_EXTERNAL (symbolp);
  2633. if (*input_line_pointer == ',')
  2634. ++input_line_pointer;
  2635. size = get_absolute_expression ();
  2636. symbol_get_obj (symbolp)->ecoff_extern_size = size;
  2637. }
  2638. /* Parse .file directives. */
  2639. void
  2640. ecoff_directive_file (int ignore ATTRIBUTE_UNUSED)
  2641. {
  2642. int indx;
  2643. char *name;
  2644. int len;
  2645. if (cur_proc_ptr != (proc_t *) NULL)
  2646. {
  2647. as_warn (_("no way to handle .file within .ent/.end section"));
  2648. demand_empty_rest_of_line ();
  2649. return;
  2650. }
  2651. indx = (int) get_absolute_expression ();
  2652. /* FIXME: we don't have to save the name here. */
  2653. name = demand_copy_C_string (&len);
  2654. add_file (name, indx - 1, 0);
  2655. demand_empty_rest_of_line ();
  2656. }
  2657. /* Parse .fmask directives. */
  2658. void
  2659. ecoff_directive_fmask (int ignore ATTRIBUTE_UNUSED)
  2660. {
  2661. long val;
  2662. if (cur_proc_ptr == (proc_t *) NULL)
  2663. {
  2664. as_warn (_(".fmask outside of .ent"));
  2665. demand_empty_rest_of_line ();
  2666. return;
  2667. }
  2668. if (get_absolute_expression_and_terminator (&val) != ',')
  2669. {
  2670. as_warn (_("bad .fmask directive"));
  2671. --input_line_pointer;
  2672. demand_empty_rest_of_line ();
  2673. return;
  2674. }
  2675. cur_proc_ptr->pdr.fregmask = val;
  2676. cur_proc_ptr->pdr.fregoffset = get_absolute_expression ();
  2677. demand_empty_rest_of_line ();
  2678. }
  2679. /* Parse .frame directives. */
  2680. void
  2681. ecoff_directive_frame (int ignore ATTRIBUTE_UNUSED)
  2682. {
  2683. long val;
  2684. if (cur_proc_ptr == (proc_t *) NULL)
  2685. {
  2686. as_warn (_(".frame outside of .ent"));
  2687. demand_empty_rest_of_line ();
  2688. return;
  2689. }
  2690. cur_proc_ptr->pdr.framereg = tc_get_register (1);
  2691. SKIP_WHITESPACE ();
  2692. if (*input_line_pointer++ != ','
  2693. || get_absolute_expression_and_terminator (&val) != ',')
  2694. {
  2695. as_warn (_("bad .frame directive"));
  2696. --input_line_pointer;
  2697. demand_empty_rest_of_line ();
  2698. return;
  2699. }
  2700. cur_proc_ptr->pdr.frameoffset = val;
  2701. cur_proc_ptr->pdr.pcreg = tc_get_register (0);
  2702. /* Alpha-OSF1 adds "the offset of saved $a0 from $sp", according to
  2703. Sandro. I don't yet know where this value should be stored, if
  2704. anywhere. Don't call demand_empty_rest_of_line (). */
  2705. s_ignore (42);
  2706. }
  2707. /* Parse .mask directives. */
  2708. void
  2709. ecoff_directive_mask (int ignore ATTRIBUTE_UNUSED)
  2710. {
  2711. long val;
  2712. if (cur_proc_ptr == (proc_t *) NULL)
  2713. {
  2714. as_warn (_(".mask outside of .ent"));
  2715. demand_empty_rest_of_line ();
  2716. return;
  2717. }
  2718. if (get_absolute_expression_and_terminator (&val) != ',')
  2719. {
  2720. as_warn (_("bad .mask directive"));
  2721. --input_line_pointer;
  2722. demand_empty_rest_of_line ();
  2723. return;
  2724. }
  2725. cur_proc_ptr->pdr.regmask = val;
  2726. cur_proc_ptr->pdr.regoffset = get_absolute_expression ();
  2727. demand_empty_rest_of_line ();
  2728. }
  2729. /* Parse .loc directives. */
  2730. void
  2731. ecoff_directive_loc (int ignore ATTRIBUTE_UNUSED)
  2732. {
  2733. lineno_list_t *list;
  2734. symint_t lineno;
  2735. if (cur_file_ptr == (efdr_t *) NULL)
  2736. {
  2737. as_warn (_(".loc before .file"));
  2738. demand_empty_rest_of_line ();
  2739. return;
  2740. }
  2741. if (now_seg != text_section)
  2742. {
  2743. as_warn (_(".loc outside of .text"));
  2744. demand_empty_rest_of_line ();
  2745. return;
  2746. }
  2747. /* Skip the file number. */
  2748. SKIP_WHITESPACE ();
  2749. get_absolute_expression ();
  2750. SKIP_WHITESPACE ();
  2751. lineno = get_absolute_expression ();
  2752. #ifndef NO_LISTING
  2753. if (listing)
  2754. listing_source_line (lineno);
  2755. #endif
  2756. /* If we're building stabs, then output a special label rather than
  2757. ECOFF line number info. */
  2758. if (stabs_seen)
  2759. {
  2760. (void) add_ecoff_symbol ((char *) NULL, st_Label, sc_Text,
  2761. symbol_new ("L0\001", now_seg,
  2762. (valueT) frag_now_fix (),
  2763. frag_now),
  2764. (bfd_vma) 0, 0, lineno);
  2765. return;
  2766. }
  2767. list = allocate_lineno_list ();
  2768. list->next = (lineno_list_t *) NULL;
  2769. list->file = cur_file_ptr;
  2770. list->proc = cur_proc_ptr;
  2771. list->frag = frag_now;
  2772. list->paddr = frag_now_fix ();
  2773. list->lineno = lineno;
  2774. /* We don't want to merge files which have line numbers. */
  2775. cur_file_ptr->fdr.fMerge = 0;
  2776. /* A .loc directive will sometimes appear before a .ent directive,
  2777. which means that cur_proc_ptr will be NULL here. Arrange to
  2778. patch this up. */
  2779. if (cur_proc_ptr == (proc_t *) NULL)
  2780. {
  2781. lineno_list_t **pl;
  2782. pl = &noproc_lineno;
  2783. while (*pl != (lineno_list_t *) NULL)
  2784. pl = &(*pl)->next;
  2785. *pl = list;
  2786. }
  2787. else
  2788. {
  2789. last_lineno = list;
  2790. *last_lineno_ptr = list;
  2791. last_lineno_ptr = &list->next;
  2792. }
  2793. }
  2794. /* The MIPS assembler sometimes inserts nop instructions in the
  2795. instruction stream. When this happens, we must patch up the .loc
  2796. information so that it points to the instruction after the nop. */
  2797. void
  2798. ecoff_fix_loc (fragS *old_frag, unsigned long old_frag_offset)
  2799. {
  2800. if (last_lineno != NULL
  2801. && last_lineno->frag == old_frag
  2802. && last_lineno->paddr == old_frag_offset)
  2803. {
  2804. last_lineno->frag = frag_now;
  2805. last_lineno->paddr = frag_now_fix ();
  2806. }
  2807. }
  2808. /* Make sure the @stabs symbol is emitted. */
  2809. static void
  2810. mark_stabs (int ignore ATTRIBUTE_UNUSED)
  2811. {
  2812. if (! stabs_seen)
  2813. {
  2814. /* Add a dummy @stabs dymbol. */
  2815. stabs_seen = 1;
  2816. (void) add_ecoff_symbol (stabs_symbol, st_Nil, sc_Info,
  2817. (symbolS *) NULL,
  2818. (bfd_vma) 0, (symint_t) -1,
  2819. ECOFF_MARK_STAB (0));
  2820. }
  2821. }
  2822. /* Parse .weakext directives. */
  2823. #ifndef TC_MIPS
  2824. /* For TC_MIPS use the version in tc-mips.c. */
  2825. void
  2826. ecoff_directive_weakext (int ignore ATTRIBUTE_UNUSED)
  2827. {
  2828. char *name;
  2829. int c;
  2830. symbolS *symbolP;
  2831. expressionS exp;
  2832. c = get_symbol_name (&name);
  2833. symbolP = symbol_find_or_make (name);
  2834. (void) restore_line_pointer (c);
  2835. SKIP_WHITESPACE ();
  2836. if (*input_line_pointer == ',')
  2837. {
  2838. if (S_IS_DEFINED (symbolP))
  2839. {
  2840. as_bad (_("symbol `%s' is already defined"),
  2841. S_GET_NAME (symbolP));
  2842. ignore_rest_of_line ();
  2843. return;
  2844. }
  2845. ++input_line_pointer;
  2846. SKIP_WHITESPACE ();
  2847. if (! is_end_of_line[(unsigned char) *input_line_pointer])
  2848. {
  2849. expression (&exp);
  2850. if (exp.X_op != O_symbol)
  2851. {
  2852. as_bad (_("bad .weakext directive"));
  2853. ignore_rest_of_line ();
  2854. return;
  2855. }
  2856. symbol_set_value_expression (symbolP, &exp);
  2857. }
  2858. }
  2859. S_SET_WEAK (symbolP);
  2860. demand_empty_rest_of_line ();
  2861. }
  2862. #endif /* not TC_MIPS */
  2863. /* Handle .stabs directives. The actual parsing routine is done by a
  2864. generic routine. This routine is called via OBJ_PROCESS_STAB.
  2865. When this is called, input_line_pointer will be pointing at the
  2866. value field of the stab.
  2867. .stabs directives have five fields:
  2868. "string" a string, encoding the type information.
  2869. code a numeric code, defined in <stab.h>
  2870. 0 a zero
  2871. desc a zero or line number
  2872. value a numeric value or an address.
  2873. If the value is relocatable, we transform this into:
  2874. iss points as an index into string space
  2875. value value from lookup of the name
  2876. st st from lookup of the name
  2877. sc sc from lookup of the name
  2878. index code|CODE_MASK
  2879. If the value is not relocatable, we transform this into:
  2880. iss points as an index into string space
  2881. value value
  2882. st st_Nil
  2883. sc sc_Nil
  2884. index code|CODE_MASK
  2885. .stabn directives have four fields (string is null):
  2886. code a numeric code, defined in <stab.h>
  2887. 0 a zero
  2888. desc a zero or a line number
  2889. value a numeric value or an address. */
  2890. void
  2891. ecoff_stab (segT sec ATTRIBUTE_UNUSED,
  2892. int what,
  2893. const char *string,
  2894. int type,
  2895. int other,
  2896. int desc)
  2897. {
  2898. efdr_t *save_file_ptr = cur_file_ptr;
  2899. symbolS *sym;
  2900. symint_t value;
  2901. bfd_vma addend;
  2902. st_t st;
  2903. sc_t sc;
  2904. symint_t indx;
  2905. localsym_t *hold = NULL;
  2906. ecoff_debugging_seen = 1;
  2907. /* We don't handle .stabd. */
  2908. if (what != 's' && what != 'n')
  2909. {
  2910. as_bad (_(".stab%c is not supported"), what);
  2911. return;
  2912. }
  2913. /* A .stabn uses a null name, not an empty string. */
  2914. if (what == 'n')
  2915. string = NULL;
  2916. /* We ignore the other field. */
  2917. if (other != 0)
  2918. as_warn (_(".stab%c: ignoring non-zero other field"), what);
  2919. /* Make sure we have a current file. */
  2920. if (cur_file_ptr == (efdr_t *) NULL)
  2921. {
  2922. add_file ((const char *) NULL, 0, 1);
  2923. save_file_ptr = cur_file_ptr;
  2924. }
  2925. /* For stabs in ECOFF, the first symbol must be @stabs. This is a
  2926. signal to gdb. */
  2927. if (stabs_seen == 0)
  2928. mark_stabs (0);
  2929. /* Line number stabs are handled differently, since they have two
  2930. values, the line number and the address of the label. We use the
  2931. index field (aka desc) to hold the line number, and the value
  2932. field to hold the address. The symbol type is st_Label, which
  2933. should be different from the other stabs, so that gdb can
  2934. recognize it. */
  2935. if (type == N_SLINE)
  2936. {
  2937. SYMR dummy_symr;
  2938. char *name;
  2939. char name_end;
  2940. #ifndef NO_LISTING
  2941. if (listing)
  2942. listing_source_line ((unsigned int) desc);
  2943. #endif
  2944. dummy_symr.index = desc;
  2945. if (dummy_symr.index != desc)
  2946. {
  2947. as_warn (_("line number (%d) for .stab%c directive cannot fit in index field (20 bits)"),
  2948. desc, what);
  2949. return;
  2950. }
  2951. name_end = get_symbol_name (&name);
  2952. sym = symbol_find_or_make (name);
  2953. (void) restore_line_pointer (name_end);
  2954. value = 0;
  2955. addend = 0;
  2956. st = st_Label;
  2957. sc = sc_Text;
  2958. indx = desc;
  2959. }
  2960. else
  2961. {
  2962. #ifndef NO_LISTING
  2963. if (listing && (type == N_SO || type == N_SOL))
  2964. listing_source_file (string);
  2965. #endif
  2966. if (ISDIGIT (*input_line_pointer)
  2967. || *input_line_pointer == '-'
  2968. || *input_line_pointer == '+')
  2969. {
  2970. st = st_Nil;
  2971. sc = sc_Nil;
  2972. sym = (symbolS *) NULL;
  2973. value = get_absolute_expression ();
  2974. addend = 0;
  2975. }
  2976. else if (! is_name_beginner ((unsigned char) *input_line_pointer))
  2977. {
  2978. as_warn (_("illegal .stab%c directive, bad character"), what);
  2979. return;
  2980. }
  2981. else
  2982. {
  2983. expressionS exp;
  2984. sc = sc_Nil;
  2985. st = st_Nil;
  2986. expression (&exp);
  2987. if (exp.X_op == O_constant)
  2988. {
  2989. sym = NULL;
  2990. value = exp.X_add_number;
  2991. addend = 0;
  2992. }
  2993. else if (exp.X_op == O_symbol)
  2994. {
  2995. sym = exp.X_add_symbol;
  2996. value = 0;
  2997. addend = exp.X_add_number;
  2998. }
  2999. else
  3000. {
  3001. sym = make_expr_symbol (&exp);
  3002. value = 0;
  3003. addend = 0;
  3004. }
  3005. }
  3006. indx = ECOFF_MARK_STAB (type);
  3007. }
  3008. /* Don't store the stabs symbol we are creating as the type of the
  3009. ECOFF symbol. We want to compute the type of the ECOFF symbol
  3010. independently. */
  3011. if (sym != (symbolS *) NULL)
  3012. hold = symbol_get_obj (sym)->ecoff_symbol;
  3013. (void) add_ecoff_symbol (string, st, sc, sym, addend, value, indx);
  3014. if (sym != (symbolS *) NULL)
  3015. symbol_get_obj (sym)->ecoff_symbol = hold;
  3016. /* Restore normal file type. */
  3017. cur_file_ptr = save_file_ptr;
  3018. }
  3019. /* Frob an ECOFF symbol. Small common symbols go into a special
  3020. .scommon section rather than bfd_com_section. */
  3021. void
  3022. ecoff_frob_symbol (symbolS *sym)
  3023. {
  3024. if (S_IS_COMMON (sym)
  3025. && S_GET_VALUE (sym) > 0
  3026. && S_GET_VALUE (sym) <= bfd_get_gp_size (stdoutput))
  3027. {
  3028. static asection scom_section;
  3029. static asymbol scom_symbol;
  3030. /* We must construct a fake section similar to bfd_com_section
  3031. but with the name .scommon. */
  3032. if (scom_section.name == NULL)
  3033. {
  3034. scom_section = *bfd_com_section_ptr;
  3035. scom_section.name = ".scommon";
  3036. scom_section.output_section = &scom_section;
  3037. scom_section.symbol = &scom_symbol;
  3038. scom_section.symbol_ptr_ptr = &scom_section.symbol;
  3039. scom_symbol = *bfd_com_section_ptr->symbol;
  3040. scom_symbol.name = ".scommon";
  3041. scom_symbol.section = &scom_section;
  3042. }
  3043. S_SET_SEGMENT (sym, &scom_section);
  3044. }
  3045. /* Double check weak symbols. */
  3046. if (S_IS_WEAK (sym))
  3047. {
  3048. if (S_IS_COMMON (sym))
  3049. as_bad (_("symbol `%s' can not be both weak and common"),
  3050. S_GET_NAME (sym));
  3051. }
  3052. }
  3053. /* Add bytes to the symbolic information buffer. */
  3054. static char *
  3055. ecoff_add_bytes (char **buf,
  3056. char **bufend,
  3057. char *bufptr,
  3058. unsigned long need)
  3059. {
  3060. unsigned long at;
  3061. unsigned long want;
  3062. at = bufptr - *buf;
  3063. need -= *bufend - bufptr;
  3064. if (need < PAGE_SIZE)
  3065. need = PAGE_SIZE;
  3066. want = (*bufend - *buf) + need;
  3067. *buf = (char *) xrealloc (*buf, want);
  3068. *bufend = *buf + want;
  3069. return *buf + at;
  3070. }
  3071. /* Adjust the symbolic information buffer to the alignment required
  3072. for the ECOFF target debugging information. */
  3073. static unsigned long
  3074. ecoff_padding_adjust (const struct ecoff_debug_swap *backend,
  3075. char **buf,
  3076. char **bufend,
  3077. unsigned long offset,
  3078. char **bufptrptr)
  3079. {
  3080. bfd_size_type align;
  3081. align = backend->debug_align;
  3082. if ((offset & (align - 1)) != 0)
  3083. {
  3084. unsigned long add;
  3085. add = align - (offset & (align - 1));
  3086. if ((unsigned long) (*bufend - (*buf + offset)) < add)
  3087. (void) ecoff_add_bytes (buf, bufend, *buf + offset, add);
  3088. memset (*buf + offset, 0, add);
  3089. offset += add;
  3090. if (bufptrptr != (char **) NULL)
  3091. *bufptrptr = *buf + offset;
  3092. }
  3093. return offset;
  3094. }
  3095. /* Build the line number information. */
  3096. static unsigned long
  3097. ecoff_build_lineno (const struct ecoff_debug_swap *backend,
  3098. char **buf,
  3099. char **bufend,
  3100. unsigned long offset,
  3101. long *linecntptr)
  3102. {
  3103. char *bufptr;
  3104. lineno_list_t *l;
  3105. lineno_list_t *last;
  3106. efdr_t *file;
  3107. proc_t *proc;
  3108. unsigned long c;
  3109. long iline;
  3110. long totcount;
  3111. lineno_list_t first;
  3112. lineno_list_t *local_first_lineno = first_lineno;
  3113. if (linecntptr != (long *) NULL)
  3114. *linecntptr = 0;
  3115. bufptr = *buf + offset;
  3116. file = (efdr_t *) NULL;
  3117. proc = (proc_t *) NULL;
  3118. last = (lineno_list_t *) NULL;
  3119. c = offset;
  3120. iline = 0;
  3121. totcount = 0;
  3122. /* FIXME? Now that MIPS embedded-PIC is gone, it may be safe to
  3123. remove this code. */
  3124. /* For some reason the address of the first procedure is ignored
  3125. when reading line numbers. This doesn't matter if the address of
  3126. the first procedure is 0, but when gcc is generating MIPS
  3127. embedded PIC code, it will put strings in the .text section
  3128. before the first procedure. We cope by inserting a dummy line if
  3129. the address of the first procedure is not 0. Hopefully this
  3130. won't screw things up too badly.
  3131. Don't do this for ECOFF assembly source line numbers. They work
  3132. without this extra attention. */
  3133. if (debug_type != DEBUG_ECOFF
  3134. && first_proc_ptr != (proc_t *) NULL
  3135. && local_first_lineno != (lineno_list_t *) NULL
  3136. && ((S_GET_VALUE (first_proc_ptr->sym->as_sym)
  3137. + bfd_get_section_vma (stdoutput,
  3138. S_GET_SEGMENT (first_proc_ptr->sym->as_sym)))
  3139. != 0))
  3140. {
  3141. first.file = local_first_lineno->file;
  3142. first.proc = local_first_lineno->proc;
  3143. first.frag = &zero_address_frag;
  3144. first.paddr = 0;
  3145. first.lineno = 0;
  3146. first.next = local_first_lineno;
  3147. local_first_lineno = &first;
  3148. }
  3149. for (l = local_first_lineno; l != (lineno_list_t *) NULL; l = l->next)
  3150. {
  3151. long count;
  3152. long delta;
  3153. /* Get the offset to the memory address of the next line number
  3154. (in words). Do this first, so that we can skip ahead to the
  3155. next useful line number entry. */
  3156. if (l->next == (lineno_list_t *) NULL)
  3157. {
  3158. /* We want a count of zero, but it will be decremented
  3159. before it is used. */
  3160. count = 1;
  3161. }
  3162. else if (l->next->frag->fr_address + l->next->paddr
  3163. > l->frag->fr_address + l->paddr)
  3164. {
  3165. count = ((l->next->frag->fr_address + l->next->paddr
  3166. - (l->frag->fr_address + l->paddr))
  3167. >> 2);
  3168. }
  3169. else
  3170. {
  3171. /* Don't change last, so we still get the right delta. */
  3172. continue;
  3173. }
  3174. if (l->file != file || l->proc != proc)
  3175. {
  3176. if (l->proc != proc && proc != (proc_t *) NULL)
  3177. proc->pdr.lnHigh = last->lineno;
  3178. if (l->file != file && file != (efdr_t *) NULL)
  3179. {
  3180. file->fdr.cbLine = c - file->fdr.cbLineOffset;
  3181. file->fdr.cline = totcount + count;
  3182. if (linecntptr != (long *) NULL)
  3183. *linecntptr += totcount + count;
  3184. totcount = 0;
  3185. }
  3186. if (l->file != file)
  3187. {
  3188. efdr_t *last_file = file;
  3189. file = l->file;
  3190. if (last_file != (efdr_t *) NULL)
  3191. file->fdr.ilineBase
  3192. = last_file->fdr.ilineBase + last_file->fdr.cline;
  3193. else
  3194. file->fdr.ilineBase = 0;
  3195. file->fdr.cbLineOffset = c;
  3196. }
  3197. if (l->proc != proc)
  3198. {
  3199. proc = l->proc;
  3200. if (proc != (proc_t *) NULL)
  3201. {
  3202. proc->pdr.lnLow = l->lineno;
  3203. proc->pdr.cbLineOffset = c - file->fdr.cbLineOffset;
  3204. proc->pdr.iline = totcount;
  3205. }
  3206. }
  3207. last = (lineno_list_t *) NULL;
  3208. }
  3209. totcount += count;
  3210. /* Get the offset to this line number. */
  3211. if (last == (lineno_list_t *) NULL)
  3212. delta = 0;
  3213. else
  3214. delta = l->lineno - last->lineno;
  3215. /* Put in the offset to this line number. */
  3216. while (delta != 0)
  3217. {
  3218. int setcount;
  3219. /* 1 is added to each count read. */
  3220. --count;
  3221. /* We can only adjust the word count by up to 15 words at a
  3222. time. */
  3223. if (count <= 0x0f)
  3224. {
  3225. setcount = count;
  3226. count = 0;
  3227. }
  3228. else
  3229. {
  3230. setcount = 0x0f;
  3231. count -= 0x0f;
  3232. }
  3233. if (delta >= -7 && delta <= 7)
  3234. {
  3235. if (bufptr >= *bufend)
  3236. bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
  3237. *bufptr++ = setcount + (delta << 4);
  3238. delta = 0;
  3239. ++c;
  3240. }
  3241. else
  3242. {
  3243. int set;
  3244. if (*bufend - bufptr < 3)
  3245. bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 3);
  3246. *bufptr++ = setcount + (8 << 4);
  3247. if (delta < -0x8000)
  3248. {
  3249. set = -0x8000;
  3250. delta += 0x8000;
  3251. }
  3252. else if (delta > 0x7fff)
  3253. {
  3254. set = 0x7fff;
  3255. delta -= 0x7fff;
  3256. }
  3257. else
  3258. {
  3259. set = delta;
  3260. delta = 0;
  3261. }
  3262. *bufptr++ = set >> 8;
  3263. *bufptr++ = set & 0xffff;
  3264. c += 3;
  3265. }
  3266. }
  3267. /* Finish adjusting the count. */
  3268. while (count > 0)
  3269. {
  3270. if (bufptr >= *bufend)
  3271. bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
  3272. /* 1 is added to each count read. */
  3273. --count;
  3274. if (count > 0x0f)
  3275. {
  3276. *bufptr++ = 0x0f;
  3277. count -= 0x0f;
  3278. }
  3279. else
  3280. {
  3281. *bufptr++ = count;
  3282. count = 0;
  3283. }
  3284. ++c;
  3285. }
  3286. ++iline;
  3287. last = l;
  3288. }
  3289. if (proc != (proc_t *) NULL)
  3290. proc->pdr.lnHigh = last->lineno;
  3291. if (file != (efdr_t *) NULL)
  3292. {
  3293. file->fdr.cbLine = c - file->fdr.cbLineOffset;
  3294. file->fdr.cline = totcount;
  3295. }
  3296. if (linecntptr != (long *) NULL)
  3297. *linecntptr += totcount;
  3298. c = ecoff_padding_adjust (backend, buf, bufend, c, &bufptr);
  3299. return c;
  3300. }
  3301. /* Build and swap out the symbols. */
  3302. static unsigned long
  3303. ecoff_build_symbols (const struct ecoff_debug_swap *backend,
  3304. char **buf,
  3305. char **bufend,
  3306. unsigned long offset)
  3307. {
  3308. const bfd_size_type external_sym_size = backend->external_sym_size;
  3309. void (* const swap_sym_out) (bfd *, const SYMR *, void *)
  3310. = backend->swap_sym_out;
  3311. char *sym_out;
  3312. long isym;
  3313. vlinks_t *file_link;
  3314. sym_out = *buf + offset;
  3315. isym = 0;
  3316. /* The symbols are stored by file. */
  3317. for (file_link = file_desc.first;
  3318. file_link != (vlinks_t *) NULL;
  3319. file_link = file_link->next)
  3320. {
  3321. int ifilesym;
  3322. int fil_cnt;
  3323. efdr_t *fil_ptr;
  3324. efdr_t *fil_end;
  3325. if (file_link->next == (vlinks_t *) NULL)
  3326. fil_cnt = file_desc.objects_last_page;
  3327. else
  3328. fil_cnt = file_desc.objects_per_page;
  3329. fil_ptr = file_link->datum->file;
  3330. fil_end = fil_ptr + fil_cnt;
  3331. for (; fil_ptr < fil_end; fil_ptr++)
  3332. {
  3333. vlinks_t *sym_link;
  3334. fil_ptr->fdr.isymBase = isym;
  3335. ifilesym = isym;
  3336. for (sym_link = fil_ptr->symbols.first;
  3337. sym_link != (vlinks_t *) NULL;
  3338. sym_link = sym_link->next)
  3339. {
  3340. int sym_cnt;
  3341. localsym_t *sym_ptr;
  3342. localsym_t *sym_end;
  3343. if (sym_link->next == (vlinks_t *) NULL)
  3344. sym_cnt = fil_ptr->symbols.objects_last_page;
  3345. else
  3346. sym_cnt = fil_ptr->symbols.objects_per_page;
  3347. sym_ptr = sym_link->datum->sym;
  3348. sym_end = sym_ptr + sym_cnt;
  3349. for (; sym_ptr < sym_end; sym_ptr++)
  3350. {
  3351. int local;
  3352. symbolS *as_sym;
  3353. forward_t *f;
  3354. know (sym_ptr->file_ptr == fil_ptr);
  3355. /* If there is no associated gas symbol, then this
  3356. is a pure debugging symbol. We have already
  3357. added the name (if any) to fil_ptr->strings.
  3358. Otherwise we must decide whether this is an
  3359. external or a local symbol (actually, it may be
  3360. both if the local provides additional debugging
  3361. information for the external). */
  3362. local = 1;
  3363. as_sym = sym_ptr->as_sym;
  3364. if (as_sym != (symbolS *) NULL)
  3365. {
  3366. symint_t indx;
  3367. /* The value of a block start symbol is the
  3368. offset from the start of the procedure. For
  3369. other symbols we just use the gas value (but
  3370. we must offset it by the vma of the section,
  3371. just as BFD does, because BFD will not see
  3372. this value). */
  3373. if (sym_ptr->ecoff_sym.asym.st == (int) st_Block
  3374. && sym_ptr->ecoff_sym.asym.sc == (int) sc_Text)
  3375. {
  3376. symbolS *begin_sym;
  3377. know (sym_ptr->proc_ptr != (proc_t *) NULL);
  3378. begin_sym = sym_ptr->proc_ptr->sym->as_sym;
  3379. if (S_GET_SEGMENT (as_sym)
  3380. != S_GET_SEGMENT (begin_sym))
  3381. as_warn (_(".begin/.bend in different segments"));
  3382. sym_ptr->ecoff_sym.asym.value =
  3383. S_GET_VALUE (as_sym) - S_GET_VALUE (begin_sym);
  3384. }
  3385. else
  3386. sym_ptr->ecoff_sym.asym.value =
  3387. (S_GET_VALUE (as_sym)
  3388. + bfd_get_section_vma (stdoutput,
  3389. S_GET_SEGMENT (as_sym))
  3390. + sym_ptr->addend);
  3391. sym_ptr->ecoff_sym.weakext = S_IS_WEAK (as_sym);
  3392. /* Set st_Proc to st_StaticProc for local
  3393. functions. */
  3394. if (sym_ptr->ecoff_sym.asym.st == st_Proc
  3395. && S_IS_DEFINED (as_sym)
  3396. && ! S_IS_EXTERNAL (as_sym)
  3397. && ! S_IS_WEAK (as_sym))
  3398. sym_ptr->ecoff_sym.asym.st = st_StaticProc;
  3399. /* Get the type and storage class based on where
  3400. the symbol actually wound up. Traditionally,
  3401. N_LBRAC and N_RBRAC are *not* relocated. */
  3402. indx = sym_ptr->ecoff_sym.asym.index;
  3403. if (sym_ptr->ecoff_sym.asym.st == st_Nil
  3404. && sym_ptr->ecoff_sym.asym.sc == sc_Nil
  3405. && (! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym)
  3406. || ((ECOFF_UNMARK_STAB (indx) != N_LBRAC)
  3407. && (ECOFF_UNMARK_STAB (indx) != N_RBRAC))))
  3408. {
  3409. segT seg;
  3410. const char *segname;
  3411. st_t st;
  3412. sc_t sc;
  3413. seg = S_GET_SEGMENT (as_sym);
  3414. segname = segment_name (seg);
  3415. if (! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym)
  3416. && (S_IS_EXTERNAL (as_sym)
  3417. || S_IS_WEAK (as_sym)
  3418. || ! S_IS_DEFINED (as_sym)))
  3419. {
  3420. if ((symbol_get_bfdsym (as_sym)->flags
  3421. & BSF_FUNCTION) != 0)
  3422. st = st_Proc;
  3423. else
  3424. st = st_Global;
  3425. }
  3426. else if (seg == text_section)
  3427. st = st_Label;
  3428. else
  3429. st = st_Static;
  3430. if (! S_IS_DEFINED (as_sym))
  3431. {
  3432. valueT s;
  3433. s = symbol_get_obj (as_sym)->ecoff_extern_size;
  3434. if (s == 0
  3435. || s > bfd_get_gp_size (stdoutput))
  3436. sc = sc_Undefined;
  3437. else
  3438. {
  3439. sc = sc_SUndefined;
  3440. sym_ptr->ecoff_sym.asym.value = s;
  3441. }
  3442. #ifdef S_SET_SIZE
  3443. S_SET_SIZE (as_sym, s);
  3444. #endif
  3445. }
  3446. else if (S_IS_COMMON (as_sym))
  3447. {
  3448. if (S_GET_VALUE (as_sym) > 0
  3449. && (S_GET_VALUE (as_sym)
  3450. <= bfd_get_gp_size (stdoutput)))
  3451. sc = sc_SCommon;
  3452. else
  3453. sc = sc_Common;
  3454. }
  3455. else if (seg == text_section)
  3456. sc = sc_Text;
  3457. else if (seg == data_section)
  3458. sc = sc_Data;
  3459. else if (strcmp (segname, ".rdata") == 0
  3460. || strcmp (segname, ".rodata") == 0)
  3461. sc = sc_RData;
  3462. else if (strcmp (segname, ".sdata") == 0)
  3463. sc = sc_SData;
  3464. else if (seg == bss_section)
  3465. sc = sc_Bss;
  3466. else if (strcmp (segname, ".sbss") == 0)
  3467. sc = sc_SBss;
  3468. else if (seg == bfd_abs_section_ptr)
  3469. sc = sc_Abs;
  3470. else
  3471. {
  3472. /* This must be a user named section.
  3473. This is not possible in ECOFF, but it
  3474. is in ELF. */
  3475. sc = sc_Data;
  3476. }
  3477. sym_ptr->ecoff_sym.asym.st = (int) st;
  3478. sym_ptr->ecoff_sym.asym.sc = (int) sc;
  3479. }
  3480. /* This is just an external symbol if it is
  3481. outside a procedure and it has a type.
  3482. FIXME: g++ will generate symbols which have
  3483. different names in the debugging information
  3484. than the actual symbol. Should we handle
  3485. them here? */
  3486. if ((S_IS_EXTERNAL (as_sym)
  3487. || S_IS_WEAK (as_sym)
  3488. || ! S_IS_DEFINED (as_sym))
  3489. && sym_ptr->proc_ptr == (proc_t *) NULL
  3490. && sym_ptr->ecoff_sym.asym.st != (int) st_Nil
  3491. && ! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym))
  3492. local = 0;
  3493. /* This is just an external symbol if it is a
  3494. common symbol. */
  3495. if (S_IS_COMMON (as_sym))
  3496. local = 0;
  3497. /* If an st_end symbol has an associated gas
  3498. symbol, then it is a local label created for
  3499. a .bend or .end directive. Stabs line
  3500. numbers will have \001 in the names. */
  3501. if (local
  3502. && sym_ptr->ecoff_sym.asym.st != st_End
  3503. && strchr (sym_ptr->name, '\001') == 0)
  3504. sym_ptr->ecoff_sym.asym.iss =
  3505. add_string (&fil_ptr->strings,
  3506. fil_ptr->str_hash,
  3507. sym_ptr->name,
  3508. (shash_t **) NULL);
  3509. }
  3510. /* We now know the index of this symbol; fill in
  3511. locations that have been waiting for that
  3512. information. */
  3513. if (sym_ptr->begin_ptr != (localsym_t *) NULL)
  3514. {
  3515. localsym_t *begin_ptr;
  3516. st_t begin_type;
  3517. know (local);
  3518. begin_ptr = sym_ptr->begin_ptr;
  3519. know (begin_ptr->sym_index != -1);
  3520. sym_ptr->ecoff_sym.asym.index = begin_ptr->sym_index;
  3521. if (sym_ptr->ecoff_sym.asym.sc != (int) sc_Info)
  3522. sym_ptr->ecoff_sym.asym.iss =
  3523. begin_ptr->ecoff_sym.asym.iss;
  3524. begin_type = (st_t) begin_ptr->ecoff_sym.asym.st;
  3525. if (begin_type == st_File
  3526. || begin_type == st_Block)
  3527. {
  3528. begin_ptr->ecoff_sym.asym.index =
  3529. isym - ifilesym + 1;
  3530. (*swap_sym_out) (stdoutput,
  3531. &begin_ptr->ecoff_sym.asym,
  3532. (*buf
  3533. + offset
  3534. + (begin_ptr->sym_index
  3535. * external_sym_size)));
  3536. }
  3537. else
  3538. {
  3539. know (begin_ptr->index_ptr != (aux_t *) NULL);
  3540. begin_ptr->index_ptr->data.isym =
  3541. isym - ifilesym + 1;
  3542. }
  3543. /* The value of the symbol marking the end of a
  3544. procedure is the size of the procedure. The
  3545. value of the symbol marking the end of a
  3546. block is the offset from the start of the
  3547. procedure to the block. */
  3548. if (begin_type == st_Proc
  3549. || begin_type == st_StaticProc)
  3550. {
  3551. know (as_sym != (symbolS *) NULL);
  3552. know (begin_ptr->as_sym != (symbolS *) NULL);
  3553. if (S_GET_SEGMENT (as_sym)
  3554. != S_GET_SEGMENT (begin_ptr->as_sym))
  3555. as_warn (_(".begin/.bend in different segments"));
  3556. sym_ptr->ecoff_sym.asym.value =
  3557. (S_GET_VALUE (as_sym)
  3558. - S_GET_VALUE (begin_ptr->as_sym));
  3559. /* If the size is odd, this is probably a
  3560. mips16 function; force it to be even. */
  3561. if ((sym_ptr->ecoff_sym.asym.value & 1) != 0)
  3562. ++sym_ptr->ecoff_sym.asym.value;
  3563. #ifdef S_SET_SIZE
  3564. S_SET_SIZE (begin_ptr->as_sym,
  3565. sym_ptr->ecoff_sym.asym.value);
  3566. #endif
  3567. }
  3568. else if (begin_type == st_Block
  3569. && sym_ptr->ecoff_sym.asym.sc != (int) sc_Info)
  3570. {
  3571. symbolS *begin_sym;
  3572. know (as_sym != (symbolS *) NULL);
  3573. know (sym_ptr->proc_ptr != (proc_t *) NULL);
  3574. begin_sym = sym_ptr->proc_ptr->sym->as_sym;
  3575. if (S_GET_SEGMENT (as_sym)
  3576. != S_GET_SEGMENT (begin_sym))
  3577. as_warn (_(".begin/.bend in different segments"));
  3578. sym_ptr->ecoff_sym.asym.value =
  3579. S_GET_VALUE (as_sym) - S_GET_VALUE (begin_sym);
  3580. }
  3581. }
  3582. for (f = sym_ptr->forward_ref;
  3583. f != (forward_t *) NULL;
  3584. f = f->next)
  3585. {
  3586. know (local);
  3587. f->ifd_ptr->data.isym = fil_ptr->file_index;
  3588. f->index_ptr->data.rndx.index = isym - ifilesym;
  3589. }
  3590. if (local)
  3591. {
  3592. if ((bfd_size_type)(*bufend - sym_out) < external_sym_size)
  3593. sym_out = ecoff_add_bytes (buf, bufend,
  3594. sym_out,
  3595. external_sym_size);
  3596. (*swap_sym_out) (stdoutput, &sym_ptr->ecoff_sym.asym,
  3597. sym_out);
  3598. sym_out += external_sym_size;
  3599. sym_ptr->sym_index = isym;
  3600. if (sym_ptr->proc_ptr != (proc_t *) NULL
  3601. && sym_ptr->proc_ptr->sym == sym_ptr)
  3602. sym_ptr->proc_ptr->pdr.isym = isym - ifilesym;
  3603. ++isym;
  3604. }
  3605. /* Record the local symbol index and file number in
  3606. case this is an external symbol. Note that this
  3607. destroys the asym.index field. */
  3608. if (as_sym != (symbolS *) NULL
  3609. && symbol_get_obj (as_sym)->ecoff_symbol == sym_ptr)
  3610. {
  3611. if ((sym_ptr->ecoff_sym.asym.st == st_Proc
  3612. || sym_ptr->ecoff_sym.asym.st == st_StaticProc)
  3613. && local)
  3614. sym_ptr->ecoff_sym.asym.index = isym - ifilesym - 1;
  3615. sym_ptr->ecoff_sym.ifd = fil_ptr->file_index;
  3616. /* Don't try to merge an FDR which has an
  3617. external symbol attached to it. */
  3618. if (S_IS_EXTERNAL (as_sym) || S_IS_WEAK (as_sym))
  3619. fil_ptr->fdr.fMerge = 0;
  3620. }
  3621. }
  3622. }
  3623. fil_ptr->fdr.csym = isym - fil_ptr->fdr.isymBase;
  3624. }
  3625. }
  3626. return offset + isym * external_sym_size;
  3627. }
  3628. /* Swap out the procedure information. */
  3629. static unsigned long
  3630. ecoff_build_procs (const struct ecoff_debug_swap *backend,
  3631. char **buf,
  3632. char **bufend,
  3633. unsigned long offset)
  3634. {
  3635. const bfd_size_type external_pdr_size = backend->external_pdr_size;
  3636. void (* const swap_pdr_out) (bfd *, const PDR *, void *)
  3637. = backend->swap_pdr_out;
  3638. char *pdr_out;
  3639. long iproc;
  3640. vlinks_t *file_link;
  3641. pdr_out = *buf + offset;
  3642. iproc = 0;
  3643. /* The procedures are stored by file. */
  3644. for (file_link = file_desc.first;
  3645. file_link != (vlinks_t *) NULL;
  3646. file_link = file_link->next)
  3647. {
  3648. int fil_cnt;
  3649. efdr_t *fil_ptr;
  3650. efdr_t *fil_end;
  3651. if (file_link->next == (vlinks_t *) NULL)
  3652. fil_cnt = file_desc.objects_last_page;
  3653. else
  3654. fil_cnt = file_desc.objects_per_page;
  3655. fil_ptr = file_link->datum->file;
  3656. fil_end = fil_ptr + fil_cnt;
  3657. for (; fil_ptr < fil_end; fil_ptr++)
  3658. {
  3659. vlinks_t *proc_link;
  3660. int first;
  3661. fil_ptr->fdr.ipdFirst = iproc;
  3662. first = 1;
  3663. for (proc_link = fil_ptr->procs.first;
  3664. proc_link != (vlinks_t *) NULL;
  3665. proc_link = proc_link->next)
  3666. {
  3667. int prc_cnt;
  3668. proc_t *proc_ptr;
  3669. proc_t *proc_end;
  3670. if (proc_link->next == (vlinks_t *) NULL)
  3671. prc_cnt = fil_ptr->procs.objects_last_page;
  3672. else
  3673. prc_cnt = fil_ptr->procs.objects_per_page;
  3674. proc_ptr = proc_link->datum->proc;
  3675. proc_end = proc_ptr + prc_cnt;
  3676. for (; proc_ptr < proc_end; proc_ptr++)
  3677. {
  3678. symbolS *adr_sym;
  3679. unsigned long adr;
  3680. adr_sym = proc_ptr->sym->as_sym;
  3681. adr = (S_GET_VALUE (adr_sym)
  3682. + bfd_get_section_vma (stdoutput,
  3683. S_GET_SEGMENT (adr_sym)));
  3684. if (first)
  3685. {
  3686. /* This code used to force the adr of the very
  3687. first fdr to be 0. However, the native tools
  3688. don't do that, and I can't remember why it
  3689. used to work that way, so I took it out. */
  3690. fil_ptr->fdr.adr = adr;
  3691. first = 0;
  3692. }
  3693. proc_ptr->pdr.adr = adr - fil_ptr->fdr.adr;
  3694. if ((bfd_size_type)(*bufend - pdr_out) < external_pdr_size)
  3695. pdr_out = ecoff_add_bytes (buf, bufend,
  3696. pdr_out,
  3697. external_pdr_size);
  3698. (*swap_pdr_out) (stdoutput, &proc_ptr->pdr, pdr_out);
  3699. pdr_out += external_pdr_size;
  3700. ++iproc;
  3701. }
  3702. }
  3703. fil_ptr->fdr.cpd = iproc - fil_ptr->fdr.ipdFirst;
  3704. }
  3705. }
  3706. return offset + iproc * external_pdr_size;
  3707. }
  3708. /* Swap out the aux information. */
  3709. static unsigned long
  3710. ecoff_build_aux (const struct ecoff_debug_swap *backend,
  3711. char **buf,
  3712. char **bufend,
  3713. unsigned long offset)
  3714. {
  3715. int bigendian;
  3716. union aux_ext *aux_out;
  3717. long iaux;
  3718. vlinks_t *file_link;
  3719. bigendian = bfd_big_endian (stdoutput);
  3720. aux_out = (union aux_ext *) (*buf + offset);
  3721. iaux = 0;
  3722. /* The aux entries are stored by file. */
  3723. for (file_link = file_desc.first;
  3724. file_link != (vlinks_t *) NULL;
  3725. file_link = file_link->next)
  3726. {
  3727. int fil_cnt;
  3728. efdr_t *fil_ptr;
  3729. efdr_t *fil_end;
  3730. if (file_link->next == (vlinks_t *) NULL)
  3731. fil_cnt = file_desc.objects_last_page;
  3732. else
  3733. fil_cnt = file_desc.objects_per_page;
  3734. fil_ptr = file_link->datum->file;
  3735. fil_end = fil_ptr + fil_cnt;
  3736. for (; fil_ptr < fil_end; fil_ptr++)
  3737. {
  3738. vlinks_t *aux_link;
  3739. fil_ptr->fdr.fBigendian = bigendian;
  3740. fil_ptr->fdr.iauxBase = iaux;
  3741. for (aux_link = fil_ptr->aux_syms.first;
  3742. aux_link != (vlinks_t *) NULL;
  3743. aux_link = aux_link->next)
  3744. {
  3745. int aux_cnt;
  3746. aux_t *aux_ptr;
  3747. aux_t *aux_end;
  3748. if (aux_link->next == (vlinks_t *) NULL)
  3749. aux_cnt = fil_ptr->aux_syms.objects_last_page;
  3750. else
  3751. aux_cnt = fil_ptr->aux_syms.objects_per_page;
  3752. aux_ptr = aux_link->datum->aux;
  3753. aux_end = aux_ptr + aux_cnt;
  3754. for (; aux_ptr < aux_end; aux_ptr++)
  3755. {
  3756. if ((unsigned long) (*bufend - (char *) aux_out)
  3757. < sizeof (union aux_ext))
  3758. aux_out = ((union aux_ext *)
  3759. ecoff_add_bytes (buf, bufend,
  3760. (char *) aux_out,
  3761. sizeof (union aux_ext)));
  3762. switch (aux_ptr->type)
  3763. {
  3764. case aux_tir:
  3765. (*backend->swap_tir_out) (bigendian,
  3766. &aux_ptr->data.ti,
  3767. &aux_out->a_ti);
  3768. break;
  3769. case aux_rndx:
  3770. (*backend->swap_rndx_out) (bigendian,
  3771. &aux_ptr->data.rndx,
  3772. &aux_out->a_rndx);
  3773. break;
  3774. case aux_dnLow:
  3775. AUX_PUT_DNLOW (bigendian, aux_ptr->data.dnLow,
  3776. aux_out);
  3777. break;
  3778. case aux_dnHigh:
  3779. AUX_PUT_DNHIGH (bigendian, aux_ptr->data.dnHigh,
  3780. aux_out);
  3781. break;
  3782. case aux_isym:
  3783. AUX_PUT_ISYM (bigendian, aux_ptr->data.isym,
  3784. aux_out);
  3785. break;
  3786. case aux_iss:
  3787. AUX_PUT_ISS (bigendian, aux_ptr->data.iss,
  3788. aux_out);
  3789. break;
  3790. case aux_width:
  3791. AUX_PUT_WIDTH (bigendian, aux_ptr->data.width,
  3792. aux_out);
  3793. break;
  3794. case aux_count:
  3795. AUX_PUT_COUNT (bigendian, aux_ptr->data.count,
  3796. aux_out);
  3797. break;
  3798. }
  3799. ++aux_out;
  3800. ++iaux;
  3801. }
  3802. }
  3803. fil_ptr->fdr.caux = iaux - fil_ptr->fdr.iauxBase;
  3804. }
  3805. }
  3806. return ecoff_padding_adjust (backend, buf, bufend,
  3807. offset + iaux * sizeof (union aux_ext),
  3808. (char **) NULL);
  3809. }
  3810. /* Copy out the strings from a varray_t. This returns the number of
  3811. bytes copied, rather than the new offset. */
  3812. static unsigned long
  3813. ecoff_build_strings (char **buf,
  3814. char **bufend,
  3815. unsigned long offset,
  3816. varray_t *vp)
  3817. {
  3818. unsigned long istr;
  3819. char *str_out;
  3820. vlinks_t *str_link;
  3821. str_out = *buf + offset;
  3822. istr = 0;
  3823. for (str_link = vp->first;
  3824. str_link != (vlinks_t *) NULL;
  3825. str_link = str_link->next)
  3826. {
  3827. unsigned long str_cnt;
  3828. if (str_link->next == (vlinks_t *) NULL)
  3829. str_cnt = vp->objects_last_page;
  3830. else
  3831. str_cnt = vp->objects_per_page;
  3832. if ((unsigned long)(*bufend - str_out) < str_cnt)
  3833. str_out = ecoff_add_bytes (buf, bufend, str_out, str_cnt);
  3834. memcpy (str_out, str_link->datum->byte, str_cnt);
  3835. str_out += str_cnt;
  3836. istr += str_cnt;
  3837. }
  3838. return istr;
  3839. }
  3840. /* Dump out the local strings. */
  3841. static unsigned long
  3842. ecoff_build_ss (const struct ecoff_debug_swap *backend,
  3843. char **buf,
  3844. char **bufend,
  3845. unsigned long offset)
  3846. {
  3847. long iss;
  3848. vlinks_t *file_link;
  3849. iss = 0;
  3850. for (file_link = file_desc.first;
  3851. file_link != (vlinks_t *) NULL;
  3852. file_link = file_link->next)
  3853. {
  3854. int fil_cnt;
  3855. efdr_t *fil_ptr;
  3856. efdr_t *fil_end;
  3857. if (file_link->next == (vlinks_t *) NULL)
  3858. fil_cnt = file_desc.objects_last_page;
  3859. else
  3860. fil_cnt = file_desc.objects_per_page;
  3861. fil_ptr = file_link->datum->file;
  3862. fil_end = fil_ptr + fil_cnt;
  3863. for (; fil_ptr < fil_end; fil_ptr++)
  3864. {
  3865. long ss_cnt;
  3866. fil_ptr->fdr.issBase = iss;
  3867. ss_cnt = ecoff_build_strings (buf, bufend, offset + iss,
  3868. &fil_ptr->strings);
  3869. fil_ptr->fdr.cbSs = ss_cnt;
  3870. iss += ss_cnt;
  3871. }
  3872. }
  3873. return ecoff_padding_adjust (backend, buf, bufend, offset + iss,
  3874. (char **) NULL);
  3875. }
  3876. /* Swap out the file descriptors. */
  3877. static unsigned long
  3878. ecoff_build_fdr (const struct ecoff_debug_swap *backend,
  3879. char **buf,
  3880. char **bufend,
  3881. unsigned long offset)
  3882. {
  3883. const bfd_size_type external_fdr_size = backend->external_fdr_size;
  3884. void (* const swap_fdr_out) (bfd *, const FDR *, void *)
  3885. = backend->swap_fdr_out;
  3886. long ifile;
  3887. char *fdr_out;
  3888. vlinks_t *file_link;
  3889. ifile = 0;
  3890. fdr_out = *buf + offset;
  3891. for (file_link = file_desc.first;
  3892. file_link != (vlinks_t *) NULL;
  3893. file_link = file_link->next)
  3894. {
  3895. int fil_cnt;
  3896. efdr_t *fil_ptr;
  3897. efdr_t *fil_end;
  3898. if (file_link->next == (vlinks_t *) NULL)
  3899. fil_cnt = file_desc.objects_last_page;
  3900. else
  3901. fil_cnt = file_desc.objects_per_page;
  3902. fil_ptr = file_link->datum->file;
  3903. fil_end = fil_ptr + fil_cnt;
  3904. for (; fil_ptr < fil_end; fil_ptr++)
  3905. {
  3906. if ((bfd_size_type)(*bufend - fdr_out) < external_fdr_size)
  3907. fdr_out = ecoff_add_bytes (buf, bufend, fdr_out,
  3908. external_fdr_size);
  3909. (*swap_fdr_out) (stdoutput, &fil_ptr->fdr, fdr_out);
  3910. fdr_out += external_fdr_size;
  3911. ++ifile;
  3912. }
  3913. }
  3914. return offset + ifile * external_fdr_size;
  3915. }
  3916. /* Set up the external symbols. These are supposed to be handled by
  3917. the backend. This routine just gets the right information and
  3918. calls a backend function to deal with it. */
  3919. static void
  3920. ecoff_setup_ext (void)
  3921. {
  3922. symbolS *sym;
  3923. for (sym = symbol_rootP; sym != (symbolS *) NULL; sym = symbol_next (sym))
  3924. {
  3925. if (symbol_get_obj (sym)->ecoff_symbol == NULL)
  3926. continue;
  3927. /* If this is a local symbol, then force the fields to zero. */
  3928. if (! S_IS_EXTERNAL (sym)
  3929. && ! S_IS_WEAK (sym)
  3930. && S_IS_DEFINED (sym))
  3931. {
  3932. struct localsym *lsym;
  3933. lsym = symbol_get_obj (sym)->ecoff_symbol;
  3934. lsym->ecoff_sym.asym.value = 0;
  3935. lsym->ecoff_sym.asym.st = (int) st_Nil;
  3936. lsym->ecoff_sym.asym.sc = (int) sc_Nil;
  3937. lsym->ecoff_sym.asym.index = indexNil;
  3938. }
  3939. obj_ecoff_set_ext (sym, &symbol_get_obj (sym)->ecoff_symbol->ecoff_sym);
  3940. }
  3941. }
  3942. /* Build the ECOFF debugging information. */
  3943. unsigned long
  3944. ecoff_build_debug (HDRR *hdr,
  3945. char **bufp,
  3946. const struct ecoff_debug_swap *backend)
  3947. {
  3948. const bfd_size_type external_pdr_size = backend->external_pdr_size;
  3949. tag_t *ptag;
  3950. tag_t *ptag_next;
  3951. efdr_t *fil_ptr;
  3952. int end_warning;
  3953. efdr_t *hold_file_ptr;
  3954. proc_t *hold_proc_ptr;
  3955. symbolS *sym;
  3956. char *buf;
  3957. char *bufend;
  3958. unsigned long offset;
  3959. /* Make sure we have a file. */
  3960. if (first_file == (efdr_t *) NULL)
  3961. add_file ((const char *) NULL, 0, 1);
  3962. /* Handle any top level tags. */
  3963. for (ptag = top_tag_head->first_tag;
  3964. ptag != (tag_t *) NULL;
  3965. ptag = ptag_next)
  3966. {
  3967. if (ptag->forward_ref != (forward_t *) NULL)
  3968. add_unknown_tag (ptag);
  3969. ptag_next = ptag->same_block;
  3970. ptag->hash_ptr->tag_ptr = ptag->same_name;
  3971. free_tag (ptag);
  3972. }
  3973. free_thead (top_tag_head);
  3974. /* Look through the symbols. Add debugging information for each
  3975. symbol that has not already received it. */
  3976. hold_file_ptr = cur_file_ptr;
  3977. hold_proc_ptr = cur_proc_ptr;
  3978. cur_proc_ptr = (proc_t *) NULL;
  3979. for (sym = symbol_rootP; sym != (symbolS *) NULL; sym = symbol_next (sym))
  3980. {
  3981. if (symbol_get_obj (sym)->ecoff_symbol != NULL
  3982. || symbol_get_obj (sym)->ecoff_file == (efdr_t *) NULL
  3983. || (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0)
  3984. continue;
  3985. cur_file_ptr = symbol_get_obj (sym)->ecoff_file;
  3986. add_ecoff_symbol ((const char *) NULL, st_Nil, sc_Nil, sym,
  3987. (bfd_vma) 0, S_GET_VALUE (sym), indexNil);
  3988. }
  3989. cur_proc_ptr = hold_proc_ptr;
  3990. cur_file_ptr = hold_file_ptr;
  3991. /* Output an ending symbol for all the files. We have to do this
  3992. here for the last file, so we may as well do it for all of the
  3993. files. */
  3994. end_warning = 0;
  3995. for (fil_ptr = first_file;
  3996. fil_ptr != (efdr_t *) NULL;
  3997. fil_ptr = fil_ptr->next_file)
  3998. {
  3999. cur_file_ptr = fil_ptr;
  4000. while (cur_file_ptr->cur_scope != (scope_t *) NULL
  4001. && cur_file_ptr->cur_scope->prev != (scope_t *) NULL)
  4002. {
  4003. cur_file_ptr->cur_scope = cur_file_ptr->cur_scope->prev;
  4004. if (! end_warning && ! cur_file_ptr->fake)
  4005. {
  4006. as_warn (_("missing .end or .bend at end of file"));
  4007. end_warning = 1;
  4008. }
  4009. }
  4010. if (cur_file_ptr->cur_scope != (scope_t *) NULL)
  4011. (void) add_ecoff_symbol ((const char *) NULL,
  4012. st_End, sc_Text,
  4013. (symbolS *) NULL,
  4014. (bfd_vma) 0,
  4015. (symint_t) 0,
  4016. (symint_t) 0);
  4017. }
  4018. /* Build the symbolic information. */
  4019. offset = 0;
  4020. buf = (char *) xmalloc (PAGE_SIZE);
  4021. bufend = buf + PAGE_SIZE;
  4022. /* Build the line number information. */
  4023. hdr->cbLineOffset = offset;
  4024. offset = ecoff_build_lineno (backend, &buf, &bufend, offset,
  4025. &hdr->ilineMax);
  4026. hdr->cbLine = offset - hdr->cbLineOffset;
  4027. /* We don't use dense numbers at all. */
  4028. hdr->idnMax = 0;
  4029. hdr->cbDnOffset = 0;
  4030. /* We can't build the PDR table until we have built the symbols,
  4031. because a PDR contains a symbol index. However, we set aside
  4032. space at this point. */
  4033. hdr->ipdMax = proc_cnt;
  4034. hdr->cbPdOffset = offset;
  4035. if ((bfd_size_type)(bufend - (buf + offset)) < proc_cnt * external_pdr_size)
  4036. (void) ecoff_add_bytes (&buf, &bufend, buf + offset,
  4037. proc_cnt * external_pdr_size);
  4038. offset += proc_cnt * external_pdr_size;
  4039. /* Build the local symbols. */
  4040. hdr->cbSymOffset = offset;
  4041. offset = ecoff_build_symbols (backend, &buf, &bufend, offset);
  4042. hdr->isymMax = (offset - hdr->cbSymOffset) / backend->external_sym_size;
  4043. /* Building the symbols initializes the symbol index in the PDR's.
  4044. Now we can swap out the PDR's. */
  4045. (void) ecoff_build_procs (backend, &buf, &bufend, hdr->cbPdOffset);
  4046. /* We don't use optimization symbols. */
  4047. hdr->ioptMax = 0;
  4048. hdr->cbOptOffset = 0;
  4049. /* Swap out the auxiliary type information. */
  4050. hdr->cbAuxOffset = offset;
  4051. offset = ecoff_build_aux (backend, &buf, &bufend, offset);
  4052. hdr->iauxMax = (offset - hdr->cbAuxOffset) / sizeof (union aux_ext);
  4053. /* Copy out the local strings. */
  4054. hdr->cbSsOffset = offset;
  4055. offset = ecoff_build_ss (backend, &buf, &bufend, offset);
  4056. hdr->issMax = offset - hdr->cbSsOffset;
  4057. /* We don't use relative file descriptors. */
  4058. hdr->crfd = 0;
  4059. hdr->cbRfdOffset = 0;
  4060. /* Swap out the file descriptors. */
  4061. hdr->cbFdOffset = offset;
  4062. offset = ecoff_build_fdr (backend, &buf, &bufend, offset);
  4063. hdr->ifdMax = (offset - hdr->cbFdOffset) / backend->external_fdr_size;
  4064. /* Set up the external symbols, which are handled by the BFD back
  4065. end. */
  4066. hdr->issExtMax = 0;
  4067. hdr->cbSsExtOffset = 0;
  4068. hdr->iextMax = 0;
  4069. hdr->cbExtOffset = 0;
  4070. ecoff_setup_ext ();
  4071. know ((offset & (backend->debug_align - 1)) == 0);
  4072. /* FIXME: This value should be determined from the .verstamp directive,
  4073. with reasonable defaults in config files. */
  4074. #ifdef TC_ALPHA
  4075. hdr->vstamp = 0x030b;
  4076. #else
  4077. hdr->vstamp = 0x020b;
  4078. #endif
  4079. *bufp = buf;
  4080. return offset;
  4081. }
  4082. /* Allocate a cluster of pages. */
  4083. #ifndef MALLOC_CHECK
  4084. static page_type *
  4085. allocate_cluster (unsigned long npages)
  4086. {
  4087. page_type *value = (page_type *) xmalloc (npages * PAGE_USIZE);
  4088. #ifdef ECOFF_DEBUG
  4089. if (debug > 3)
  4090. fprintf (stderr, "\talloc\tnpages = %d, value = 0x%.8x\n", npages, value);
  4091. #endif
  4092. memset (value, 0, npages * PAGE_USIZE);
  4093. return value;
  4094. }
  4095. static page_type *cluster_ptr = NULL;
  4096. static unsigned long pages_left = 0;
  4097. #endif /* MALLOC_CHECK */
  4098. /* Allocate one page (which is initialized to 0). */
  4099. static page_type *
  4100. allocate_page (void)
  4101. {
  4102. #ifndef MALLOC_CHECK
  4103. if (pages_left == 0)
  4104. {
  4105. pages_left = MAX_CLUSTER_PAGES;
  4106. cluster_ptr = allocate_cluster (pages_left);
  4107. }
  4108. pages_left--;
  4109. return cluster_ptr++;
  4110. #else /* MALLOC_CHECK */
  4111. page_type *ptr;
  4112. ptr = xmalloc (PAGE_USIZE);
  4113. memset (ptr, 0, PAGE_USIZE);
  4114. return ptr;
  4115. #endif /* MALLOC_CHECK */
  4116. }
  4117. /* Allocate scoping information. */
  4118. static scope_t *
  4119. allocate_scope (void)
  4120. {
  4121. scope_t *ptr;
  4122. static scope_t initial_scope;
  4123. #ifndef MALLOC_CHECK
  4124. ptr = alloc_counts[(int) alloc_type_scope].free_list.f_scope;
  4125. if (ptr != (scope_t *) NULL)
  4126. alloc_counts[(int) alloc_type_scope].free_list.f_scope = ptr->free;
  4127. else
  4128. {
  4129. int unallocated = alloc_counts[(int) alloc_type_scope].unallocated;
  4130. page_type *cur_page = alloc_counts[(int) alloc_type_scope].cur_page;
  4131. if (unallocated == 0)
  4132. {
  4133. unallocated = PAGE_SIZE / sizeof (scope_t);
  4134. alloc_counts[(int) alloc_type_scope].cur_page = cur_page = allocate_page ();
  4135. alloc_counts[(int) alloc_type_scope].total_pages++;
  4136. }
  4137. ptr = &cur_page->scope[--unallocated];
  4138. alloc_counts[(int) alloc_type_scope].unallocated = unallocated;
  4139. }
  4140. #else
  4141. ptr = (scope_t *) xmalloc (sizeof (scope_t));
  4142. #endif
  4143. alloc_counts[(int) alloc_type_scope].total_alloc++;
  4144. *ptr = initial_scope;
  4145. return ptr;
  4146. }
  4147. /* Free scoping information. */
  4148. static void
  4149. free_scope (scope_t *ptr)
  4150. {
  4151. alloc_counts[(int) alloc_type_scope].total_free++;
  4152. #ifndef MALLOC_CHECK
  4153. ptr->free = alloc_counts[(int) alloc_type_scope].free_list.f_scope;
  4154. alloc_counts[(int) alloc_type_scope].free_list.f_scope = ptr;
  4155. #else
  4156. free ((void *) ptr);
  4157. #endif
  4158. }
  4159. /* Allocate links for pages in a virtual array. */
  4160. static vlinks_t *
  4161. allocate_vlinks (void)
  4162. {
  4163. vlinks_t *ptr;
  4164. static vlinks_t initial_vlinks;
  4165. #ifndef MALLOC_CHECK
  4166. int unallocated = alloc_counts[(int) alloc_type_vlinks].unallocated;
  4167. page_type *cur_page = alloc_counts[(int) alloc_type_vlinks].cur_page;
  4168. if (unallocated == 0)
  4169. {
  4170. unallocated = PAGE_SIZE / sizeof (vlinks_t);
  4171. alloc_counts[(int) alloc_type_vlinks].cur_page = cur_page = allocate_page ();
  4172. alloc_counts[(int) alloc_type_vlinks].total_pages++;
  4173. }
  4174. ptr = &cur_page->vlinks[--unallocated];
  4175. alloc_counts[(int) alloc_type_vlinks].unallocated = unallocated;
  4176. #else
  4177. ptr = (vlinks_t *) xmalloc (sizeof (vlinks_t));
  4178. #endif
  4179. alloc_counts[(int) alloc_type_vlinks].total_alloc++;
  4180. *ptr = initial_vlinks;
  4181. return ptr;
  4182. }
  4183. /* Allocate string hash buckets. */
  4184. static shash_t *
  4185. allocate_shash (void)
  4186. {
  4187. shash_t *ptr;
  4188. static shash_t initial_shash;
  4189. #ifndef MALLOC_CHECK
  4190. int unallocated = alloc_counts[(int) alloc_type_shash].unallocated;
  4191. page_type *cur_page = alloc_counts[(int) alloc_type_shash].cur_page;
  4192. if (unallocated == 0)
  4193. {
  4194. unallocated = PAGE_SIZE / sizeof (shash_t);
  4195. alloc_counts[(int) alloc_type_shash].cur_page = cur_page = allocate_page ();
  4196. alloc_counts[(int) alloc_type_shash].total_pages++;
  4197. }
  4198. ptr = &cur_page->shash[--unallocated];
  4199. alloc_counts[(int) alloc_type_shash].unallocated = unallocated;
  4200. #else
  4201. ptr = (shash_t *) xmalloc (sizeof (shash_t));
  4202. #endif
  4203. alloc_counts[(int) alloc_type_shash].total_alloc++;
  4204. *ptr = initial_shash;
  4205. return ptr;
  4206. }
  4207. /* Allocate type hash buckets. */
  4208. static thash_t *
  4209. allocate_thash (void)
  4210. {
  4211. thash_t *ptr;
  4212. static thash_t initial_thash;
  4213. #ifndef MALLOC_CHECK
  4214. int unallocated = alloc_counts[(int) alloc_type_thash].unallocated;
  4215. page_type *cur_page = alloc_counts[(int) alloc_type_thash].cur_page;
  4216. if (unallocated == 0)
  4217. {
  4218. unallocated = PAGE_SIZE / sizeof (thash_t);
  4219. alloc_counts[(int) alloc_type_thash].cur_page = cur_page = allocate_page ();
  4220. alloc_counts[(int) alloc_type_thash].total_pages++;
  4221. }
  4222. ptr = &cur_page->thash[--unallocated];
  4223. alloc_counts[(int) alloc_type_thash].unallocated = unallocated;
  4224. #else
  4225. ptr = (thash_t *) xmalloc (sizeof (thash_t));
  4226. #endif
  4227. alloc_counts[(int) alloc_type_thash].total_alloc++;
  4228. *ptr = initial_thash;
  4229. return ptr;
  4230. }
  4231. /* Allocate structure, union, or enum tag information. */
  4232. static tag_t *
  4233. allocate_tag (void)
  4234. {
  4235. tag_t *ptr;
  4236. static tag_t initial_tag;
  4237. #ifndef MALLOC_CHECK
  4238. ptr = alloc_counts[(int) alloc_type_tag].free_list.f_tag;
  4239. if (ptr != (tag_t *) NULL)
  4240. alloc_counts[(int) alloc_type_tag].free_list.f_tag = ptr->free;
  4241. else
  4242. {
  4243. int unallocated = alloc_counts[(int) alloc_type_tag].unallocated;
  4244. page_type *cur_page = alloc_counts[(int) alloc_type_tag].cur_page;
  4245. if (unallocated == 0)
  4246. {
  4247. unallocated = PAGE_SIZE / sizeof (tag_t);
  4248. alloc_counts[(int) alloc_type_tag].cur_page = cur_page = allocate_page ();
  4249. alloc_counts[(int) alloc_type_tag].total_pages++;
  4250. }
  4251. ptr = &cur_page->tag[--unallocated];
  4252. alloc_counts[(int) alloc_type_tag].unallocated = unallocated;
  4253. }
  4254. #else
  4255. ptr = (tag_t *) xmalloc (sizeof (tag_t));
  4256. #endif
  4257. alloc_counts[(int) alloc_type_tag].total_alloc++;
  4258. *ptr = initial_tag;
  4259. return ptr;
  4260. }
  4261. /* Free scoping information. */
  4262. static void
  4263. free_tag (tag_t *ptr)
  4264. {
  4265. alloc_counts[(int) alloc_type_tag].total_free++;
  4266. #ifndef MALLOC_CHECK
  4267. ptr->free = alloc_counts[(int) alloc_type_tag].free_list.f_tag;
  4268. alloc_counts[(int) alloc_type_tag].free_list.f_tag = ptr;
  4269. #else
  4270. free ((PTR_T) ptr);
  4271. #endif
  4272. }
  4273. /* Allocate forward reference to a yet unknown tag. */
  4274. static forward_t *
  4275. allocate_forward (void)
  4276. {
  4277. forward_t *ptr;
  4278. static forward_t initial_forward;
  4279. #ifndef MALLOC_CHECK
  4280. int unallocated = alloc_counts[(int) alloc_type_forward].unallocated;
  4281. page_type *cur_page = alloc_counts[(int) alloc_type_forward].cur_page;
  4282. if (unallocated == 0)
  4283. {
  4284. unallocated = PAGE_SIZE / sizeof (forward_t);
  4285. alloc_counts[(int) alloc_type_forward].cur_page = cur_page = allocate_page ();
  4286. alloc_counts[(int) alloc_type_forward].total_pages++;
  4287. }
  4288. ptr = &cur_page->forward[--unallocated];
  4289. alloc_counts[(int) alloc_type_forward].unallocated = unallocated;
  4290. #else
  4291. ptr = (forward_t *) xmalloc (sizeof (forward_t));
  4292. #endif
  4293. alloc_counts[(int) alloc_type_forward].total_alloc++;
  4294. *ptr = initial_forward;
  4295. return ptr;
  4296. }
  4297. /* Allocate head of type hash list. */
  4298. static thead_t *
  4299. allocate_thead (void)
  4300. {
  4301. thead_t *ptr;
  4302. static thead_t initial_thead;
  4303. #ifndef MALLOC_CHECK
  4304. ptr = alloc_counts[(int) alloc_type_thead].free_list.f_thead;
  4305. if (ptr != (thead_t *) NULL)
  4306. alloc_counts[(int) alloc_type_thead].free_list.f_thead = ptr->free;
  4307. else
  4308. {
  4309. int unallocated = alloc_counts[(int) alloc_type_thead].unallocated;
  4310. page_type *cur_page = alloc_counts[(int) alloc_type_thead].cur_page;
  4311. if (unallocated == 0)
  4312. {
  4313. unallocated = PAGE_SIZE / sizeof (thead_t);
  4314. alloc_counts[(int) alloc_type_thead].cur_page = cur_page = allocate_page ();
  4315. alloc_counts[(int) alloc_type_thead].total_pages++;
  4316. }
  4317. ptr = &cur_page->thead[--unallocated];
  4318. alloc_counts[(int) alloc_type_thead].unallocated = unallocated;
  4319. }
  4320. #else
  4321. ptr = (thead_t *) xmalloc (sizeof (thead_t));
  4322. #endif
  4323. alloc_counts[(int) alloc_type_thead].total_alloc++;
  4324. *ptr = initial_thead;
  4325. return ptr;
  4326. }
  4327. /* Free scoping information. */
  4328. static void
  4329. free_thead (thead_t *ptr)
  4330. {
  4331. alloc_counts[(int) alloc_type_thead].total_free++;
  4332. #ifndef MALLOC_CHECK
  4333. ptr->free = (thead_t *) alloc_counts[(int) alloc_type_thead].free_list.f_thead;
  4334. alloc_counts[(int) alloc_type_thead].free_list.f_thead = ptr;
  4335. #else
  4336. free ((PTR_T) ptr);
  4337. #endif
  4338. }
  4339. static lineno_list_t *
  4340. allocate_lineno_list (void)
  4341. {
  4342. lineno_list_t *ptr;
  4343. static lineno_list_t initial_lineno_list;
  4344. #ifndef MALLOC_CHECK
  4345. int unallocated = alloc_counts[(int) alloc_type_lineno].unallocated;
  4346. page_type *cur_page = alloc_counts[(int) alloc_type_lineno].cur_page;
  4347. if (unallocated == 0)
  4348. {
  4349. unallocated = PAGE_SIZE / sizeof (lineno_list_t);
  4350. alloc_counts[(int) alloc_type_lineno].cur_page = cur_page = allocate_page ();
  4351. alloc_counts[(int) alloc_type_lineno].total_pages++;
  4352. }
  4353. ptr = &cur_page->lineno[--unallocated];
  4354. alloc_counts[(int) alloc_type_lineno].unallocated = unallocated;
  4355. #else
  4356. ptr = (lineno_list_t *) xmalloc (sizeof (lineno_list_t));
  4357. #endif
  4358. alloc_counts[(int) alloc_type_lineno].total_alloc++;
  4359. *ptr = initial_lineno_list;
  4360. return ptr;
  4361. }
  4362. void
  4363. ecoff_set_gp_prolog_size (int sz)
  4364. {
  4365. if (cur_proc_ptr == 0)
  4366. return;
  4367. cur_proc_ptr->pdr.gp_prologue = sz;
  4368. if (cur_proc_ptr->pdr.gp_prologue != sz)
  4369. {
  4370. as_warn (_("GP prologue size exceeds field size, using 0 instead"));
  4371. cur_proc_ptr->pdr.gp_prologue = 0;
  4372. }
  4373. cur_proc_ptr->pdr.gp_used = 1;
  4374. }
  4375. int
  4376. ecoff_no_current_file (void)
  4377. {
  4378. return cur_file_ptr == (efdr_t *) NULL;
  4379. }
  4380. void
  4381. ecoff_generate_asm_lineno (void)
  4382. {
  4383. unsigned int lineno;
  4384. char *filename;
  4385. lineno_list_t *list;
  4386. as_where (&filename, &lineno);
  4387. if (current_stabs_filename == (char *) NULL
  4388. || filename_cmp (current_stabs_filename, filename))
  4389. add_file (filename, 0, 1);
  4390. list = allocate_lineno_list ();
  4391. list->next = (lineno_list_t *) NULL;
  4392. list->file = cur_file_ptr;
  4393. list->proc = cur_proc_ptr;
  4394. list->frag = frag_now;
  4395. list->paddr = frag_now_fix ();
  4396. list->lineno = lineno;
  4397. /* We don't want to merge files which have line numbers. */
  4398. cur_file_ptr->fdr.fMerge = 0;
  4399. /* A .loc directive will sometimes appear before a .ent directive,
  4400. which means that cur_proc_ptr will be NULL here. Arrange to
  4401. patch this up. */
  4402. if (cur_proc_ptr == (proc_t *) NULL)
  4403. {
  4404. lineno_list_t **pl;
  4405. pl = &noproc_lineno;
  4406. while (*pl != (lineno_list_t *) NULL)
  4407. pl = &(*pl)->next;
  4408. *pl = list;
  4409. }
  4410. else
  4411. {
  4412. last_lineno = list;
  4413. *last_lineno_ptr = list;
  4414. last_lineno_ptr = &list->next;
  4415. }
  4416. }
  4417. #else
  4418. void
  4419. ecoff_generate_asm_lineno (void)
  4420. {
  4421. }
  4422. #endif /* ECOFF_DEBUGGING */