ecoff.c 146 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212
  1. /* ECOFF debugging support.
  2. Copyright (C) 1993-2022 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 indices 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 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. htab_t 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. (htab_t)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 htab_t 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. htab_t 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, int aent);
  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 = str_htab_create ();
  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. htab_t 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 *) str_hash_find (hash_tbl, str);
  1367. if (hash_ptr == (shash_t *) NULL)
  1368. {
  1369. if (vp->objects_last_page + len >= PAGE_USIZE)
  1370. {
  1371. vp->num_allocated =
  1372. ((vp->num_allocated + PAGE_USIZE - 1) / PAGE_USIZE) * PAGE_USIZE;
  1373. add_varray_page (vp);
  1374. }
  1375. hash_ptr = allocate_shash ();
  1376. hash_ptr->indx = vp->num_allocated;
  1377. hash_ptr->string = &vp->last->datum->byte[vp->objects_last_page];
  1378. vp->objects_last_page += len + 1;
  1379. vp->num_allocated += len + 1;
  1380. strcpy (hash_ptr->string, str);
  1381. if (str_hash_insert (hash_tbl, str, hash_ptr, 0) != NULL)
  1382. as_fatal (_("duplicate %s"), str);
  1383. }
  1384. if (ret_hash != (shash_t **) NULL)
  1385. *ret_hash = hash_ptr;
  1386. return hash_ptr->indx;
  1387. }
  1388. /* Add debugging information for a symbol. */
  1389. static localsym_t *
  1390. add_ecoff_symbol (const char *str, /* symbol name */
  1391. st_t type, /* symbol type */
  1392. sc_t storage, /* storage class */
  1393. symbolS *sym_value, /* associated symbol. */
  1394. bfd_vma addend, /* addend to sym_value. */
  1395. symint_t value, /* value of symbol */
  1396. symint_t indx /* index to local/aux. syms */)
  1397. {
  1398. localsym_t *psym;
  1399. scope_t *pscope;
  1400. thead_t *ptag_head;
  1401. tag_t *ptag;
  1402. tag_t *ptag_next;
  1403. varray_t *vp;
  1404. int scope_delta = 0;
  1405. shash_t *hash_ptr = (shash_t *) NULL;
  1406. if (cur_file_ptr == (efdr_t *) NULL)
  1407. as_fatal (_("no current file pointer"));
  1408. vp = &cur_file_ptr->symbols;
  1409. if (vp->objects_last_page == vp->objects_per_page)
  1410. add_varray_page (vp);
  1411. psym = &vp->last->datum->sym[vp->objects_last_page++];
  1412. if (str == (const char *) NULL && sym_value != (symbolS *) NULL)
  1413. psym->name = S_GET_NAME (sym_value);
  1414. else
  1415. psym->name = str;
  1416. psym->as_sym = sym_value;
  1417. if (sym_value != (symbolS *) NULL)
  1418. symbol_get_obj (sym_value)->ecoff_symbol = psym;
  1419. psym->addend = addend;
  1420. psym->file_ptr = cur_file_ptr;
  1421. psym->proc_ptr = cur_proc_ptr;
  1422. psym->begin_ptr = (localsym_t *) NULL;
  1423. psym->index_ptr = (aux_t *) NULL;
  1424. psym->forward_ref = (forward_t *) NULL;
  1425. psym->sym_index = -1;
  1426. memset (&psym->ecoff_sym, 0, sizeof (EXTR));
  1427. psym->ecoff_sym.asym.value = value;
  1428. psym->ecoff_sym.asym.st = (unsigned) type;
  1429. psym->ecoff_sym.asym.sc = (unsigned) storage;
  1430. psym->ecoff_sym.asym.index = indx;
  1431. /* If there is an associated symbol, we wait until the end of the
  1432. assembly before deciding where to put the name (it may be just an
  1433. external symbol). Otherwise, this is just a debugging symbol and
  1434. the name should go with the current file. */
  1435. if (sym_value == (symbolS *) NULL)
  1436. psym->ecoff_sym.asym.iss = ((str == (const char *) NULL)
  1437. ? 0
  1438. : add_string (&cur_file_ptr->strings,
  1439. cur_file_ptr->str_hash,
  1440. str,
  1441. &hash_ptr));
  1442. ++vp->num_allocated;
  1443. if (ECOFF_IS_STAB (&psym->ecoff_sym.asym))
  1444. return psym;
  1445. /* Save the symbol within the hash table if this is a static
  1446. item, and it has a name. */
  1447. if (hash_ptr != (shash_t *) NULL
  1448. && (type == st_Global || type == st_Static || type == st_Label
  1449. || type == st_Proc || type == st_StaticProc))
  1450. hash_ptr->sym_ptr = psym;
  1451. /* push or pop a scope if appropriate. */
  1452. switch (type)
  1453. {
  1454. default:
  1455. break;
  1456. case st_File: /* beginning of file */
  1457. case st_Proc: /* procedure */
  1458. case st_StaticProc: /* static procedure */
  1459. case st_Block: /* begin scope */
  1460. pscope = allocate_scope ();
  1461. pscope->prev = cur_file_ptr->cur_scope;
  1462. pscope->lsym = psym;
  1463. pscope->type = type;
  1464. cur_file_ptr->cur_scope = pscope;
  1465. if (type != st_File)
  1466. scope_delta = 1;
  1467. /* For every block type except file, struct, union, or
  1468. enumeration blocks, push a level on the tag stack. We omit
  1469. file types, so that tags can span file boundaries. */
  1470. if (type != st_File && storage != sc_Info)
  1471. {
  1472. ptag_head = allocate_thead ();
  1473. ptag_head->first_tag = 0;
  1474. ptag_head->prev = cur_tag_head;
  1475. cur_tag_head = ptag_head;
  1476. }
  1477. break;
  1478. case st_End:
  1479. pscope = cur_file_ptr->cur_scope;
  1480. if (pscope == (scope_t *) NULL)
  1481. as_fatal (_("too many st_End's"));
  1482. else
  1483. {
  1484. st_t begin_type = (st_t) pscope->lsym->ecoff_sym.asym.st;
  1485. psym->begin_ptr = pscope->lsym;
  1486. if (begin_type != st_File)
  1487. scope_delta = -1;
  1488. /* Except for file, structure, union, or enumeration end
  1489. blocks remove all tags created within this scope. */
  1490. if (begin_type != st_File && storage != sc_Info)
  1491. {
  1492. ptag_head = cur_tag_head;
  1493. cur_tag_head = ptag_head->prev;
  1494. for (ptag = ptag_head->first_tag;
  1495. ptag != (tag_t *) NULL;
  1496. ptag = ptag_next)
  1497. {
  1498. if (ptag->forward_ref != (forward_t *) NULL)
  1499. add_unknown_tag (ptag);
  1500. ptag_next = ptag->same_block;
  1501. ptag->hash_ptr->tag_ptr = ptag->same_name;
  1502. free_tag (ptag);
  1503. }
  1504. free_thead (ptag_head);
  1505. }
  1506. cur_file_ptr->cur_scope = pscope->prev;
  1507. /* block begin gets next sym #. This is set when we know
  1508. the symbol index value. */
  1509. /* Functions push two or more aux words as follows:
  1510. 1st word: index+1 of the end symbol (filled in later).
  1511. 2nd word: type of the function (plus any aux words needed).
  1512. Also, tie the external pointer back to the function begin symbol. */
  1513. if (begin_type != st_File && begin_type != st_Block)
  1514. {
  1515. symint_t ty;
  1516. varray_t *svp = &cur_file_ptr->aux_syms;
  1517. pscope->lsym->ecoff_sym.asym.index = add_aux_sym_symint (0);
  1518. pscope->lsym->index_ptr =
  1519. &svp->last->datum->aux[svp->objects_last_page - 1];
  1520. ty = add_aux_sym_tir (&last_func_type_info,
  1521. hash_no,
  1522. &cur_file_ptr->thash_head[0]);
  1523. (void) ty;
  1524. /* This seems to be unnecessary. I'm not even sure what it is
  1525. * intended to do. It's from mips-tfile.
  1526. * if (last_func_sym_value != (symbolS *) NULL)
  1527. * {
  1528. * last_func_sym_value->ifd = cur_file_ptr->file_index;
  1529. * last_func_sym_value->index = ty;
  1530. * }
  1531. */
  1532. }
  1533. free_scope (pscope);
  1534. }
  1535. }
  1536. cur_file_ptr->nested_scopes += scope_delta;
  1537. #ifdef ECOFF_DEBUG
  1538. if (debug && type != st_File
  1539. && (debug > 2 || type == st_Block || type == st_End
  1540. || type == st_Proc || type == st_StaticProc))
  1541. {
  1542. char *sc_str = sc_to_string (storage);
  1543. char *st_str = st_to_string (type);
  1544. int depth = cur_file_ptr->nested_scopes + (scope_delta < 0);
  1545. fprintf (stderr,
  1546. "\tlsym\tv= %10ld, depth= %2d, sc= %-12s",
  1547. value, depth, sc_str);
  1548. if (str_start && str_end_p1 - str_start > 0)
  1549. fprintf (stderr, " st= %-11s name= %.*s\n",
  1550. st_str, str_end_p1 - str_start, str_start);
  1551. else
  1552. {
  1553. unsigned long len = strlen (st_str);
  1554. fprintf (stderr, " st= %.*s\n", len - 1, st_str);
  1555. }
  1556. }
  1557. #endif
  1558. return psym;
  1559. }
  1560. /* Add an auxiliary symbol (passing a symint). This is actually used
  1561. for integral aux types, not just symints. */
  1562. static symint_t
  1563. add_aux_sym_symint (symint_t aux_word /* auxiliary information word */)
  1564. {
  1565. varray_t *vp;
  1566. aux_t *aux_ptr;
  1567. if (cur_file_ptr == (efdr_t *) NULL)
  1568. as_fatal (_("no current file pointer"));
  1569. vp = &cur_file_ptr->aux_syms;
  1570. if (vp->objects_last_page == vp->objects_per_page)
  1571. add_varray_page (vp);
  1572. aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
  1573. aux_ptr->type = aux_isym;
  1574. aux_ptr->data.isym = aux_word;
  1575. return vp->num_allocated++;
  1576. }
  1577. /* Add an auxiliary symbol (passing a file/symbol index combo). */
  1578. static symint_t
  1579. add_aux_sym_rndx (int file_index, symint_t sym_index)
  1580. {
  1581. varray_t *vp;
  1582. aux_t *aux_ptr;
  1583. if (cur_file_ptr == (efdr_t *) NULL)
  1584. as_fatal (_("no current file pointer"));
  1585. vp = &cur_file_ptr->aux_syms;
  1586. if (vp->objects_last_page == vp->objects_per_page)
  1587. add_varray_page (vp);
  1588. aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
  1589. aux_ptr->type = aux_rndx;
  1590. aux_ptr->data.rndx.rfd = file_index;
  1591. aux_ptr->data.rndx.index = sym_index;
  1592. return vp->num_allocated++;
  1593. }
  1594. /* Add an auxiliary symbol (passing the basic type and possibly
  1595. type qualifiers). */
  1596. static symint_t
  1597. add_aux_sym_tir (type_info_t *t, /* current type information */
  1598. hash_state_t state, /* whether to hash type or not */
  1599. thash_t **hash_tbl /* pointer to hash table to use */)
  1600. {
  1601. varray_t *vp;
  1602. aux_t *aux_ptr;
  1603. static AUXU init_aux;
  1604. symint_t ret;
  1605. int i;
  1606. AUXU aux;
  1607. if (cur_file_ptr == (efdr_t *) NULL)
  1608. as_fatal (_("no current file pointer"));
  1609. vp = &cur_file_ptr->aux_syms;
  1610. aux = init_aux;
  1611. aux.ti.bt = (int) t->basic_type;
  1612. aux.ti.continued = 0;
  1613. aux.ti.fBitfield = t->bitfield;
  1614. aux.ti.tq0 = (int) t->type_qualifiers[0];
  1615. aux.ti.tq1 = (int) t->type_qualifiers[1];
  1616. aux.ti.tq2 = (int) t->type_qualifiers[2];
  1617. aux.ti.tq3 = (int) t->type_qualifiers[3];
  1618. aux.ti.tq4 = (int) t->type_qualifiers[4];
  1619. aux.ti.tq5 = (int) t->type_qualifiers[5];
  1620. /* For anything that adds additional information, we must not hash,
  1621. so check here, and reset our state. */
  1622. if (state != hash_no
  1623. && (t->type_qualifiers[0] == tq_Array
  1624. || t->type_qualifiers[1] == tq_Array
  1625. || t->type_qualifiers[2] == tq_Array
  1626. || t->type_qualifiers[3] == tq_Array
  1627. || t->type_qualifiers[4] == tq_Array
  1628. || t->type_qualifiers[5] == tq_Array
  1629. || t->basic_type == bt_Struct
  1630. || t->basic_type == bt_Union
  1631. || t->basic_type == bt_Enum
  1632. || t->bitfield
  1633. || t->num_dims > 0))
  1634. state = hash_no;
  1635. /* See if we can hash this type, and save some space, but some types
  1636. can't be hashed (because they contain arrays or continuations),
  1637. and others can be put into the hash list, but cannot use existing
  1638. types because other aux entries precede this one. */
  1639. if (state != hash_no)
  1640. {
  1641. thash_t *hash_ptr;
  1642. symint_t hi;
  1643. hi = aux.isym & ((1 << HASHBITS) - 1);
  1644. hi %= THASH_SIZE;
  1645. for (hash_ptr = hash_tbl[hi];
  1646. hash_ptr != (thash_t *)0;
  1647. hash_ptr = hash_ptr->next)
  1648. {
  1649. if (aux.isym == hash_ptr->type.isym)
  1650. break;
  1651. }
  1652. if (hash_ptr != (thash_t *) NULL && state == hash_yes)
  1653. return hash_ptr->indx;
  1654. if (hash_ptr == (thash_t *) NULL)
  1655. {
  1656. hash_ptr = allocate_thash ();
  1657. hash_ptr->next = hash_tbl[hi];
  1658. hash_ptr->type = aux;
  1659. hash_ptr->indx = vp->num_allocated;
  1660. hash_tbl[hi] = hash_ptr;
  1661. }
  1662. }
  1663. /* Everything is set up, add the aux symbol. */
  1664. if (vp->objects_last_page == vp->objects_per_page)
  1665. add_varray_page (vp);
  1666. aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
  1667. aux_ptr->type = aux_tir;
  1668. aux_ptr->data = aux;
  1669. ret = vp->num_allocated++;
  1670. /* Add bitfield length if it exists.
  1671. NOTE: Mips documentation claims bitfield goes at the end of the
  1672. AUX record, but the DECstation compiler emits it here.
  1673. (This would only make a difference for enum bitfields.)
  1674. Also note: We use the last size given since gcc may emit 2
  1675. for an enum bitfield. */
  1676. if (t->bitfield)
  1677. (void) add_aux_sym_symint ((symint_t) t->sizes[t->num_sizes - 1]);
  1678. /* Add tag information if needed. Structure, union, and enum
  1679. references add 2 aux symbols: a [file index, symbol index]
  1680. pointer to the structure type, and the current file index. */
  1681. if (t->basic_type == bt_Struct
  1682. || t->basic_type == bt_Union
  1683. || t->basic_type == bt_Enum)
  1684. {
  1685. symint_t file_index = t->tag_ptr->ifd;
  1686. localsym_t *sym = t->tag_ptr->sym;
  1687. forward_t *forward_ref = allocate_forward ();
  1688. if (sym != (localsym_t *) NULL)
  1689. {
  1690. forward_ref->next = sym->forward_ref;
  1691. sym->forward_ref = forward_ref;
  1692. }
  1693. else
  1694. {
  1695. forward_ref->next = t->tag_ptr->forward_ref;
  1696. t->tag_ptr->forward_ref = forward_ref;
  1697. }
  1698. (void) add_aux_sym_rndx (ST_RFDESCAPE, indexNil);
  1699. forward_ref->index_ptr
  1700. = &vp->last->datum->aux[vp->objects_last_page - 1];
  1701. (void) add_aux_sym_symint (file_index);
  1702. forward_ref->ifd_ptr
  1703. = &vp->last->datum->aux[vp->objects_last_page - 1];
  1704. }
  1705. /* Add information about array bounds if they exist. */
  1706. for (i = 0; i < t->num_dims; i++)
  1707. {
  1708. (void) add_aux_sym_rndx (ST_RFDESCAPE,
  1709. cur_file_ptr->int_type);
  1710. (void) add_aux_sym_symint (cur_file_ptr->file_index); /* file index*/
  1711. (void) add_aux_sym_symint ((symint_t) 0); /* low bound */
  1712. (void) add_aux_sym_symint (t->dimensions[i] - 1); /* high bound*/
  1713. (void) add_aux_sym_symint ((t->dimensions[i] == 0) /* stride */
  1714. ? 0
  1715. : (t->sizes[i] * 8) / t->dimensions[i]);
  1716. };
  1717. /* NOTE: Mips documentation claims that the bitfield width goes here.
  1718. But it needs to be emitted earlier. */
  1719. return ret;
  1720. }
  1721. /* Add a tag to the tag table (unless it already exists). */
  1722. static tag_t *
  1723. get_tag (const char *tag, /* tag name */
  1724. localsym_t *sym, /* tag start block */
  1725. bt_t basic_type /* bt_Struct, bt_Union, or bt_Enum */)
  1726. {
  1727. shash_t *hash_ptr;
  1728. tag_t *tag_ptr;
  1729. if (cur_file_ptr == (efdr_t *) NULL)
  1730. as_fatal (_("no current file pointer"));
  1731. hash_ptr = (shash_t *) str_hash_find (tag_hash, tag);
  1732. if (hash_ptr != (shash_t *) NULL
  1733. && hash_ptr->tag_ptr != (tag_t *) NULL)
  1734. {
  1735. tag_ptr = hash_ptr->tag_ptr;
  1736. if (sym != (localsym_t *) NULL)
  1737. {
  1738. tag_ptr->basic_type = basic_type;
  1739. tag_ptr->ifd = cur_file_ptr->file_index;
  1740. tag_ptr->sym = sym;
  1741. }
  1742. return tag_ptr;
  1743. }
  1744. if (hash_ptr == (shash_t *) NULL)
  1745. {
  1746. char *perm;
  1747. perm = xstrdup (tag);
  1748. hash_ptr = allocate_shash ();
  1749. str_hash_insert (tag_hash, perm, hash_ptr, 0);
  1750. hash_ptr->string = perm;
  1751. }
  1752. tag_ptr = allocate_tag ();
  1753. tag_ptr->forward_ref = (forward_t *) NULL;
  1754. tag_ptr->hash_ptr = hash_ptr;
  1755. tag_ptr->same_name = hash_ptr->tag_ptr;
  1756. tag_ptr->basic_type = basic_type;
  1757. tag_ptr->sym = sym;
  1758. tag_ptr->ifd = ((sym == (localsym_t *) NULL)
  1759. ? (symint_t) -1
  1760. : cur_file_ptr->file_index);
  1761. tag_ptr->same_block = cur_tag_head->first_tag;
  1762. cur_tag_head->first_tag = tag_ptr;
  1763. hash_ptr->tag_ptr = tag_ptr;
  1764. return tag_ptr;
  1765. }
  1766. /* Add an unknown {struct, union, enum} tag. */
  1767. static void
  1768. add_unknown_tag (tag_t *ptag /* pointer to tag information */)
  1769. {
  1770. shash_t *hash_ptr = ptag->hash_ptr;
  1771. char *name = hash_ptr->string;
  1772. localsym_t *sym;
  1773. forward_t **pf;
  1774. #ifdef ECOFF_DEBUG
  1775. if (debug > 1)
  1776. {
  1777. char *agg_type = "{unknown aggregate type}";
  1778. switch (ptag->basic_type)
  1779. {
  1780. case bt_Struct: agg_type = "struct"; break;
  1781. case bt_Union: agg_type = "union"; break;
  1782. case bt_Enum: agg_type = "enum"; break;
  1783. default: break;
  1784. }
  1785. fprintf (stderr, "unknown %s %.*s found\n", agg_type,
  1786. hash_ptr->len, name_start);
  1787. }
  1788. #endif
  1789. sym = add_ecoff_symbol (name,
  1790. st_Block,
  1791. sc_Info,
  1792. (symbolS *) NULL,
  1793. (bfd_vma) 0,
  1794. (symint_t) 0,
  1795. (symint_t) 0);
  1796. (void) add_ecoff_symbol (name,
  1797. st_End,
  1798. sc_Info,
  1799. (symbolS *) NULL,
  1800. (bfd_vma) 0,
  1801. (symint_t) 0,
  1802. (symint_t) 0);
  1803. for (pf = &sym->forward_ref; *pf != (forward_t *) NULL; pf = &(*pf)->next)
  1804. ;
  1805. *pf = ptag->forward_ref;
  1806. }
  1807. /* Add a procedure to the current file's list of procedures, and record
  1808. this is the current procedure. If AENT, then only set the requested
  1809. symbol's function type. */
  1810. static void
  1811. add_procedure (char *func /* func name */, int aent)
  1812. {
  1813. varray_t *vp;
  1814. proc_t *new_proc_ptr;
  1815. symbolS *sym;
  1816. #ifdef ECOFF_DEBUG
  1817. if (debug)
  1818. fputc ('\n', stderr);
  1819. #endif
  1820. /* Set the BSF_FUNCTION flag for the symbol. */
  1821. sym = symbol_find_or_make (func);
  1822. symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
  1823. if (aent)
  1824. return;
  1825. if (cur_file_ptr == (efdr_t *) NULL)
  1826. as_fatal (_("no current file pointer"));
  1827. vp = &cur_file_ptr->procs;
  1828. if (vp->objects_last_page == vp->objects_per_page)
  1829. add_varray_page (vp);
  1830. cur_proc_ptr = new_proc_ptr = &vp->last->datum->proc[vp->objects_last_page++];
  1831. if (first_proc_ptr == (proc_t *) NULL)
  1832. first_proc_ptr = new_proc_ptr;
  1833. vp->num_allocated++;
  1834. new_proc_ptr->pdr.isym = -1;
  1835. new_proc_ptr->pdr.iline = -1;
  1836. new_proc_ptr->pdr.lnLow = -1;
  1837. new_proc_ptr->pdr.lnHigh = -1;
  1838. /* Push the start of the function. */
  1839. new_proc_ptr->sym = add_ecoff_symbol ((const char *) NULL, st_Proc, sc_Text,
  1840. sym, (bfd_vma) 0, (symint_t) 0,
  1841. (symint_t) 0);
  1842. ++proc_cnt;
  1843. /* Fill in the linenos preceding the .ent, if any. */
  1844. if (noproc_lineno != (lineno_list_t *) NULL)
  1845. {
  1846. lineno_list_t *l;
  1847. for (l = noproc_lineno; l != (lineno_list_t *) NULL; l = l->next)
  1848. l->proc = new_proc_ptr;
  1849. *last_lineno_ptr = noproc_lineno;
  1850. while (*last_lineno_ptr != NULL)
  1851. {
  1852. last_lineno = *last_lineno_ptr;
  1853. last_lineno_ptr = &last_lineno->next;
  1854. }
  1855. noproc_lineno = (lineno_list_t *) NULL;
  1856. }
  1857. }
  1858. symbolS *
  1859. ecoff_get_cur_proc_sym (void)
  1860. {
  1861. return (cur_proc_ptr ? cur_proc_ptr->sym->as_sym : NULL);
  1862. }
  1863. /* Add a new filename, and set up all of the file relative
  1864. virtual arrays (strings, symbols, aux syms, etc.). Record
  1865. where the current file structure lives. */
  1866. static void
  1867. add_file (const char *file_name, int indx ATTRIBUTE_UNUSED, int fake)
  1868. {
  1869. int first_ch;
  1870. efdr_t *fil_ptr;
  1871. #ifdef ECOFF_DEBUG
  1872. if (debug)
  1873. fprintf (stderr, "\tfile\t%.*s\n", len, file_start);
  1874. #endif
  1875. /* If the file name is NULL, then no .file symbol appeared, and we
  1876. want to use the actual file name. */
  1877. if (file_name == (const char *) NULL)
  1878. {
  1879. if (first_file != (efdr_t *) NULL)
  1880. as_fatal (_("fake .file after real one"));
  1881. file_name = as_where ((unsigned int *) NULL);
  1882. /* Automatically generate ECOFF debugging information, since I
  1883. think that's what other ECOFF assemblers do. We don't do
  1884. this if we see a .file directive with a string, since that
  1885. implies that some sort of debugging information is being
  1886. provided. */
  1887. if (! symbol_table_frozen && debug_type == DEBUG_UNSPECIFIED)
  1888. debug_type = DEBUG_ECOFF;
  1889. }
  1890. else if (debug_type == DEBUG_UNSPECIFIED)
  1891. debug_type = DEBUG_NONE;
  1892. #ifndef NO_LISTING
  1893. if (listing)
  1894. listing_source_file (file_name);
  1895. #endif
  1896. current_stabs_filename = file_name;
  1897. /* If we're creating stabs, then we don't actually make a new FDR.
  1898. Instead, we just create a stabs symbol. */
  1899. if (stabs_seen)
  1900. {
  1901. (void) add_ecoff_symbol (file_name, st_Nil, sc_Nil,
  1902. symbol_new (FAKE_LABEL_NAME, now_seg,
  1903. frag_now, frag_now_fix ()),
  1904. (bfd_vma) 0, 0, ECOFF_MARK_STAB (N_SOL));
  1905. return;
  1906. }
  1907. first_ch = *file_name;
  1908. /* FIXME: We can't safely merge files which have line number
  1909. information (fMerge will be zero in this case). Otherwise, we
  1910. get incorrect line number debugging info. See for instance
  1911. ecoff_build_lineno, which will end up setting all file->fdr.*
  1912. fields multiple times, resulting in incorrect debug info. In
  1913. order to make this work right, all line number and symbol info
  1914. for the same source file has to be adjacent in the object file,
  1915. so that a single file descriptor can be used to point to them.
  1916. This would require maintaining file specific lists of line
  1917. numbers and symbols for each file, so that they can be merged
  1918. together (or output together) when two .file pseudo-ops are
  1919. merged into one file descriptor. */
  1920. /* See if the file has already been created. */
  1921. for (fil_ptr = first_file;
  1922. fil_ptr != (efdr_t *) NULL;
  1923. fil_ptr = fil_ptr->next_file)
  1924. {
  1925. if (first_ch == fil_ptr->name[0]
  1926. && filename_cmp (file_name, fil_ptr->name) == 0
  1927. && fil_ptr->fdr.fMerge)
  1928. {
  1929. cur_file_ptr = fil_ptr;
  1930. if (! fake)
  1931. cur_file_ptr->fake = 0;
  1932. break;
  1933. }
  1934. }
  1935. /* If this is a new file, create it. */
  1936. if (fil_ptr == (efdr_t *) NULL)
  1937. {
  1938. if (file_desc.objects_last_page == file_desc.objects_per_page)
  1939. add_varray_page (&file_desc);
  1940. fil_ptr = cur_file_ptr =
  1941. &file_desc.last->datum->file[file_desc.objects_last_page++];
  1942. *fil_ptr = init_file;
  1943. fil_ptr->file_index = current_file_idx++;
  1944. ++file_desc.num_allocated;
  1945. fil_ptr->fake = fake;
  1946. /* Allocate the string hash table. */
  1947. fil_ptr->str_hash = str_htab_create ();
  1948. /* Make sure 0 byte in string table is null */
  1949. add_string (&fil_ptr->strings,
  1950. fil_ptr->str_hash,
  1951. "",
  1952. (shash_t **)0);
  1953. if (strlen (file_name) > PAGE_USIZE - 2)
  1954. as_fatal (_("filename goes over one page boundary"));
  1955. /* Push the start of the filename. We assume that the filename
  1956. will be stored at string offset 1. */
  1957. (void) add_ecoff_symbol (file_name, st_File, sc_Text,
  1958. (symbolS *) NULL, (bfd_vma) 0,
  1959. (symint_t) 0, (symint_t) 0);
  1960. fil_ptr->fdr.rss = 1;
  1961. fil_ptr->name = &fil_ptr->strings.last->datum->byte[1];
  1962. /* Update the linked list of file descriptors. */
  1963. *last_file_ptr = fil_ptr;
  1964. last_file_ptr = &fil_ptr->next_file;
  1965. /* Add void & int types to the file (void should be first to catch
  1966. errant 0's within the index fields). */
  1967. fil_ptr->void_type = add_aux_sym_tir (&void_type_info,
  1968. hash_yes,
  1969. &cur_file_ptr->thash_head[0]);
  1970. fil_ptr->int_type = add_aux_sym_tir (&int_type_info,
  1971. hash_yes,
  1972. &cur_file_ptr->thash_head[0]);
  1973. }
  1974. }
  1975. /* This function is called when the assembler notices a preprocessor
  1976. directive switching to a new file. This will not happen in
  1977. compiler output, only in hand coded assembler. */
  1978. void
  1979. ecoff_new_file (const char *name, int appfile ATTRIBUTE_UNUSED)
  1980. {
  1981. if (cur_file_ptr != NULL && filename_cmp (cur_file_ptr->name, name) == 0)
  1982. return;
  1983. add_file (name, 0, 0);
  1984. /* This is a hand coded assembler file, so automatically turn on
  1985. debugging information. */
  1986. if (debug_type == DEBUG_UNSPECIFIED)
  1987. debug_type = DEBUG_ECOFF;
  1988. }
  1989. #ifdef ECOFF_DEBUG
  1990. /* Convert storage class to string. */
  1991. static char *
  1992. sc_to_string (storage_class)
  1993. sc_t storage_class;
  1994. {
  1995. switch (storage_class)
  1996. {
  1997. case sc_Nil: return "Nil,";
  1998. case sc_Text: return "Text,";
  1999. case sc_Data: return "Data,";
  2000. case sc_Bss: return "Bss,";
  2001. case sc_Register: return "Register,";
  2002. case sc_Abs: return "Abs,";
  2003. case sc_Undefined: return "Undefined,";
  2004. case sc_CdbLocal: return "CdbLocal,";
  2005. case sc_Bits: return "Bits,";
  2006. case sc_CdbSystem: return "CdbSystem,";
  2007. case sc_RegImage: return "RegImage,";
  2008. case sc_Info: return "Info,";
  2009. case sc_UserStruct: return "UserStruct,";
  2010. case sc_SData: return "SData,";
  2011. case sc_SBss: return "SBss,";
  2012. case sc_RData: return "RData,";
  2013. case sc_Var: return "Var,";
  2014. case sc_Common: return "Common,";
  2015. case sc_SCommon: return "SCommon,";
  2016. case sc_VarRegister: return "VarRegister,";
  2017. case sc_Variant: return "Variant,";
  2018. case sc_SUndefined: return "SUndefined,";
  2019. case sc_Init: return "Init,";
  2020. case sc_Max: return "Max,";
  2021. }
  2022. return "???,";
  2023. }
  2024. #endif /* DEBUG */
  2025. #ifdef ECOFF_DEBUG
  2026. /* Convert symbol type to string. */
  2027. static char *
  2028. st_to_string (symbol_type)
  2029. st_t symbol_type;
  2030. {
  2031. switch (symbol_type)
  2032. {
  2033. case st_Nil: return "Nil,";
  2034. case st_Global: return "Global,";
  2035. case st_Static: return "Static,";
  2036. case st_Param: return "Param,";
  2037. case st_Local: return "Local,";
  2038. case st_Label: return "Label,";
  2039. case st_Proc: return "Proc,";
  2040. case st_Block: return "Block,";
  2041. case st_End: return "End,";
  2042. case st_Member: return "Member,";
  2043. case st_Typedef: return "Typedef,";
  2044. case st_File: return "File,";
  2045. case st_RegReloc: return "RegReloc,";
  2046. case st_Forward: return "Forward,";
  2047. case st_StaticProc: return "StaticProc,";
  2048. case st_Constant: return "Constant,";
  2049. case st_Str: return "String,";
  2050. case st_Number: return "Number,";
  2051. case st_Expr: return "Expr,";
  2052. case st_Type: return "Type,";
  2053. case st_Max: return "Max,";
  2054. }
  2055. return "???,";
  2056. }
  2057. #endif /* DEBUG */
  2058. /* Parse .begin directives which have a label as the first argument
  2059. which gives the location of the start of the block. */
  2060. void
  2061. ecoff_directive_begin (int ignore ATTRIBUTE_UNUSED)
  2062. {
  2063. char *name;
  2064. char name_end;
  2065. if (cur_file_ptr == (efdr_t *) NULL)
  2066. {
  2067. as_warn (_(".begin directive without a preceding .file directive"));
  2068. demand_empty_rest_of_line ();
  2069. return;
  2070. }
  2071. if (cur_proc_ptr == (proc_t *) NULL)
  2072. {
  2073. as_warn (_(".begin directive without a preceding .ent directive"));
  2074. demand_empty_rest_of_line ();
  2075. return;
  2076. }
  2077. name_end = get_symbol_name (&name);
  2078. (void) add_ecoff_symbol ((const char *) NULL, st_Block, sc_Text,
  2079. symbol_find_or_make (name),
  2080. (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
  2081. (void) restore_line_pointer (name_end);
  2082. /* The line number follows, but we don't use it. */
  2083. (void) get_absolute_expression ();
  2084. demand_empty_rest_of_line ();
  2085. }
  2086. /* Parse .bend directives which have a label as the first argument
  2087. which gives the location of the end of the block. */
  2088. void
  2089. ecoff_directive_bend (int ignore ATTRIBUTE_UNUSED)
  2090. {
  2091. char *name;
  2092. char name_end;
  2093. symbolS *endsym;
  2094. if (cur_file_ptr == (efdr_t *) NULL)
  2095. {
  2096. as_warn (_(".bend directive without a preceding .file directive"));
  2097. demand_empty_rest_of_line ();
  2098. return;
  2099. }
  2100. if (cur_proc_ptr == (proc_t *) NULL)
  2101. {
  2102. as_warn (_(".bend directive without a preceding .ent directive"));
  2103. demand_empty_rest_of_line ();
  2104. return;
  2105. }
  2106. name_end = get_symbol_name (&name);
  2107. /* The value is the distance between the .bend directive and the
  2108. corresponding symbol. We fill in the offset when we write out
  2109. the symbol. */
  2110. endsym = symbol_find (name);
  2111. if (endsym == (symbolS *) NULL)
  2112. as_warn (_(".bend directive names unknown symbol"));
  2113. else
  2114. (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text, endsym,
  2115. (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
  2116. restore_line_pointer (name_end);
  2117. /* The line number follows, but we don't use it. */
  2118. (void) get_absolute_expression ();
  2119. demand_empty_rest_of_line ();
  2120. }
  2121. /* COFF debugging information is provided as a series of directives
  2122. (.def, .scl, etc.). We build up information as we read the
  2123. directives in the following static variables, and file it away when
  2124. we reach the .endef directive. */
  2125. static char *coff_sym_name;
  2126. static type_info_t coff_type;
  2127. static sc_t coff_storage_class;
  2128. static st_t coff_symbol_typ;
  2129. static int coff_is_function;
  2130. static char *coff_tag;
  2131. static valueT coff_value;
  2132. static symbolS *coff_sym_value;
  2133. static bfd_vma coff_sym_addend;
  2134. static int coff_inside_enumeration;
  2135. /* Handle a .def directive: start defining a symbol. */
  2136. void
  2137. ecoff_directive_def (int ignore ATTRIBUTE_UNUSED)
  2138. {
  2139. char *name;
  2140. char name_end;
  2141. ecoff_debugging_seen = 1;
  2142. SKIP_WHITESPACE ();
  2143. name_end = get_symbol_name (&name);
  2144. if (coff_sym_name != (char *) NULL)
  2145. as_warn (_(".def pseudo-op used inside of .def/.endef; ignored"));
  2146. else if (*name == '\0')
  2147. as_warn (_("empty symbol name in .def; ignored"));
  2148. else
  2149. {
  2150. free (coff_sym_name);
  2151. free (coff_tag);
  2152. coff_sym_name = xstrdup (name);
  2153. coff_type = type_info_init;
  2154. coff_storage_class = sc_Nil;
  2155. coff_symbol_typ = st_Nil;
  2156. coff_is_function = 0;
  2157. coff_tag = (char *) NULL;
  2158. coff_value = 0;
  2159. coff_sym_value = (symbolS *) NULL;
  2160. coff_sym_addend = 0;
  2161. }
  2162. restore_line_pointer (name_end);
  2163. demand_empty_rest_of_line ();
  2164. }
  2165. /* Handle a .dim directive, used to give dimensions for an array. The
  2166. arguments are comma separated numbers. mips-tfile assumes that
  2167. there will not be more than 6 dimensions, and gdb won't read any
  2168. more than that anyhow, so I will also make that assumption. */
  2169. void
  2170. ecoff_directive_dim (int ignore ATTRIBUTE_UNUSED)
  2171. {
  2172. int dimens[N_TQ];
  2173. int i;
  2174. if (coff_sym_name == (char *) NULL)
  2175. {
  2176. as_warn (_(".dim pseudo-op used outside of .def/.endef; ignored"));
  2177. demand_empty_rest_of_line ();
  2178. return;
  2179. }
  2180. for (i = 0; i < N_TQ; i++)
  2181. {
  2182. SKIP_WHITESPACE ();
  2183. dimens[i] = get_absolute_expression ();
  2184. if (*input_line_pointer == ',')
  2185. ++input_line_pointer;
  2186. else
  2187. {
  2188. if (*input_line_pointer != '\n'
  2189. && *input_line_pointer != ';')
  2190. as_warn (_("badly formed .dim directive"));
  2191. break;
  2192. }
  2193. }
  2194. if (i == N_TQ)
  2195. --i;
  2196. /* The dimensions are stored away in reverse order. */
  2197. for (; i >= 0; i--)
  2198. {
  2199. if (coff_type.num_dims >= N_TQ)
  2200. {
  2201. as_warn (_("too many .dim entries"));
  2202. break;
  2203. }
  2204. coff_type.dimensions[coff_type.num_dims] = dimens[i];
  2205. ++coff_type.num_dims;
  2206. }
  2207. demand_empty_rest_of_line ();
  2208. }
  2209. /* Handle a .scl directive, which sets the COFF storage class of the
  2210. symbol. */
  2211. void
  2212. ecoff_directive_scl (int ignore ATTRIBUTE_UNUSED)
  2213. {
  2214. long val;
  2215. if (coff_sym_name == (char *) NULL)
  2216. {
  2217. as_warn (_(".scl pseudo-op used outside of .def/.endef; ignored"));
  2218. demand_empty_rest_of_line ();
  2219. return;
  2220. }
  2221. val = get_absolute_expression ();
  2222. coff_symbol_typ = map_coff_sym_type[val];
  2223. coff_storage_class = map_coff_storage[val];
  2224. demand_empty_rest_of_line ();
  2225. }
  2226. /* Handle a .size directive. For some reason mips-tfile.c thinks that
  2227. .size can have multiple arguments. We humor it, although gcc will
  2228. never generate more than one argument. */
  2229. void
  2230. ecoff_directive_size (int ignore ATTRIBUTE_UNUSED)
  2231. {
  2232. int sizes[N_TQ];
  2233. int i;
  2234. if (coff_sym_name == (char *) NULL)
  2235. {
  2236. as_warn (_(".size pseudo-op used outside of .def/.endef; ignored"));
  2237. demand_empty_rest_of_line ();
  2238. return;
  2239. }
  2240. for (i = 0; i < N_TQ; i++)
  2241. {
  2242. SKIP_WHITESPACE ();
  2243. sizes[i] = get_absolute_expression ();
  2244. if (*input_line_pointer == ',')
  2245. ++input_line_pointer;
  2246. else
  2247. {
  2248. if (*input_line_pointer != '\n'
  2249. && *input_line_pointer != ';')
  2250. as_warn (_("badly formed .size directive"));
  2251. break;
  2252. }
  2253. }
  2254. if (i == N_TQ)
  2255. --i;
  2256. /* The sizes are stored away in reverse order. */
  2257. for (; i >= 0; i--)
  2258. {
  2259. if (coff_type.num_sizes >= N_TQ)
  2260. {
  2261. as_warn (_("too many .size entries"));
  2262. break;
  2263. }
  2264. coff_type.sizes[coff_type.num_sizes] = sizes[i];
  2265. ++coff_type.num_sizes;
  2266. }
  2267. demand_empty_rest_of_line ();
  2268. }
  2269. /* Handle the .type directive, which gives the COFF type of the
  2270. symbol. */
  2271. void
  2272. ecoff_directive_type (int ignore ATTRIBUTE_UNUSED)
  2273. {
  2274. long val;
  2275. tq_t *tq_ptr;
  2276. tq_t *tq_shft;
  2277. if (coff_sym_name == (char *) NULL)
  2278. {
  2279. as_warn (_(".type pseudo-op used outside of .def/.endef; ignored"));
  2280. demand_empty_rest_of_line ();
  2281. return;
  2282. }
  2283. val = get_absolute_expression ();
  2284. coff_type.orig_type = BTYPE (val);
  2285. coff_type.basic_type = map_coff_types[coff_type.orig_type];
  2286. tq_ptr = &coff_type.type_qualifiers[N_TQ];
  2287. while (val & ~N_BTMASK)
  2288. {
  2289. if (tq_ptr == &coff_type.type_qualifiers[0])
  2290. {
  2291. /* FIXME: We could handle this by setting the continued bit.
  2292. There would still be a limit: the .type argument can not
  2293. be infinite. */
  2294. as_warn (_("the type of %s is too complex; it will be simplified"),
  2295. coff_sym_name);
  2296. break;
  2297. }
  2298. if (ISPTR (val))
  2299. *--tq_ptr = tq_Ptr;
  2300. else if (ISFCN (val))
  2301. *--tq_ptr = tq_Proc;
  2302. else if (ISARY (val))
  2303. *--tq_ptr = tq_Array;
  2304. else
  2305. as_fatal (_("Unrecognized .type argument"));
  2306. val = DECREF (val);
  2307. }
  2308. tq_shft = &coff_type.type_qualifiers[0];
  2309. while (tq_ptr != &coff_type.type_qualifiers[N_TQ])
  2310. *tq_shft++ = *tq_ptr++;
  2311. if (tq_shft != &coff_type.type_qualifiers[0] && tq_shft[-1] == tq_Proc)
  2312. {
  2313. /* If this is a function, ignore it, so that we don't get two
  2314. entries (one from the .ent, and one for the .def that
  2315. precedes it). Save the type information so that the end
  2316. block can properly add it after the begin block index. For
  2317. MIPS knows what reason, we must strip off the function type
  2318. at this point. */
  2319. coff_is_function = 1;
  2320. tq_shft[-1] = tq_Nil;
  2321. }
  2322. while (tq_shft != &coff_type.type_qualifiers[N_TQ])
  2323. *tq_shft++ = tq_Nil;
  2324. demand_empty_rest_of_line ();
  2325. }
  2326. /* Handle the .tag directive, which gives the name of a structure,
  2327. union or enum. */
  2328. void
  2329. ecoff_directive_tag (int ignore ATTRIBUTE_UNUSED)
  2330. {
  2331. char *name;
  2332. char name_end;
  2333. if (coff_sym_name == (char *) NULL)
  2334. {
  2335. as_warn (_(".tag pseudo-op used outside of .def/.endef; ignored"));
  2336. demand_empty_rest_of_line ();
  2337. return;
  2338. }
  2339. name_end = get_symbol_name (&name);
  2340. coff_tag = xstrdup (name);
  2341. (void) restore_line_pointer (name_end);
  2342. demand_empty_rest_of_line ();
  2343. }
  2344. /* Handle the .val directive, which gives the value of the symbol. It
  2345. may be the name of a static or global symbol. */
  2346. void
  2347. ecoff_directive_val (int ignore ATTRIBUTE_UNUSED)
  2348. {
  2349. expressionS exp;
  2350. if (coff_sym_name == (char *) NULL)
  2351. {
  2352. as_warn (_(".val pseudo-op used outside of .def/.endef; ignored"));
  2353. demand_empty_rest_of_line ();
  2354. return;
  2355. }
  2356. expression (&exp);
  2357. if (exp.X_op != O_constant && exp.X_op != O_symbol)
  2358. {
  2359. as_bad (_(".val expression is too complex"));
  2360. demand_empty_rest_of_line ();
  2361. return;
  2362. }
  2363. if (exp.X_op == O_constant)
  2364. coff_value = exp.X_add_number;
  2365. else
  2366. {
  2367. coff_sym_value = exp.X_add_symbol;
  2368. coff_sym_addend = exp.X_add_number;
  2369. }
  2370. demand_empty_rest_of_line ();
  2371. }
  2372. /* Handle the .endef directive, which terminates processing of COFF
  2373. debugging information for a symbol. */
  2374. void
  2375. ecoff_directive_endef (int ignore ATTRIBUTE_UNUSED)
  2376. {
  2377. char *name;
  2378. symint_t indx;
  2379. localsym_t *sym;
  2380. demand_empty_rest_of_line ();
  2381. if (coff_sym_name == (char *) NULL)
  2382. {
  2383. as_warn (_(".endef pseudo-op used before .def; ignored"));
  2384. return;
  2385. }
  2386. name = coff_sym_name;
  2387. coff_sym_name = (char *) NULL;
  2388. /* If the symbol is a static or external, we have already gotten the
  2389. appropriate type and class, so make sure we don't override those
  2390. values. This is needed because there are some type and classes
  2391. that are not in COFF, such as short data, etc. */
  2392. if (coff_sym_value != (symbolS *) NULL)
  2393. {
  2394. coff_symbol_typ = st_Nil;
  2395. coff_storage_class = sc_Nil;
  2396. }
  2397. coff_type.extra_sizes = coff_tag != (char *) NULL;
  2398. if (coff_type.num_dims > 0)
  2399. {
  2400. int diff = coff_type.num_dims - coff_type.num_sizes;
  2401. int i = coff_type.num_dims - 1;
  2402. int j;
  2403. if (coff_type.num_sizes != 1 || diff < 0)
  2404. {
  2405. as_warn (_("bad COFF debugging information"));
  2406. return;
  2407. }
  2408. /* If this is an array, make sure the same number of dimensions
  2409. and sizes were passed, creating extra sizes for multiply
  2410. dimensioned arrays if not passed. */
  2411. coff_type.extra_sizes = 0;
  2412. if (diff)
  2413. {
  2414. j = (sizeof (coff_type.sizes) / sizeof (coff_type.sizes[0])) - 1;
  2415. while (j >= 0)
  2416. {
  2417. coff_type.sizes[j] = (((j - diff) >= 0)
  2418. ? coff_type.sizes[j - diff]
  2419. : 0);
  2420. j--;
  2421. }
  2422. coff_type.num_sizes = i + 1;
  2423. for (i--; i >= 0; i--)
  2424. coff_type.sizes[i] = (coff_type.dimensions[i + 1] == 0
  2425. ? 0
  2426. : (coff_type.sizes[i + 1]
  2427. / coff_type.dimensions[i + 1]));
  2428. }
  2429. }
  2430. else if (coff_symbol_typ == st_Member
  2431. && coff_type.num_sizes - coff_type.extra_sizes == 1)
  2432. {
  2433. /* Is this a bitfield? This is indicated by a structure member
  2434. having a size field that isn't an array. */
  2435. coff_type.bitfield = 1;
  2436. }
  2437. /* Except for enumeration members & begin/ending of scopes, put the
  2438. type word in the aux. symbol table. */
  2439. if (coff_symbol_typ == st_Block || coff_symbol_typ == st_End)
  2440. indx = 0;
  2441. else if (coff_inside_enumeration)
  2442. indx = cur_file_ptr->void_type;
  2443. else
  2444. {
  2445. if (coff_type.basic_type == bt_Struct
  2446. || coff_type.basic_type == bt_Union
  2447. || coff_type.basic_type == bt_Enum)
  2448. {
  2449. if (coff_tag == (char *) NULL)
  2450. {
  2451. as_warn (_("no tag specified for %s"), name);
  2452. return;
  2453. }
  2454. coff_type.tag_ptr = get_tag (coff_tag, (localsym_t *) NULL,
  2455. coff_type.basic_type);
  2456. }
  2457. if (coff_is_function)
  2458. {
  2459. last_func_type_info = coff_type;
  2460. last_func_sym_value = coff_sym_value;
  2461. return;
  2462. }
  2463. indx = add_aux_sym_tir (&coff_type,
  2464. hash_yes,
  2465. &cur_file_ptr->thash_head[0]);
  2466. }
  2467. /* Do any last minute adjustments that are necessary. */
  2468. switch (coff_symbol_typ)
  2469. {
  2470. default:
  2471. break;
  2472. /* For the beginning of structs, unions, and enumerations, the
  2473. size info needs to be passed in the value field. */
  2474. case st_Block:
  2475. if (coff_type.num_sizes - coff_type.num_dims - coff_type.extra_sizes
  2476. != 1)
  2477. {
  2478. as_warn (_("bad COFF debugging information"));
  2479. return;
  2480. }
  2481. else
  2482. coff_value = coff_type.sizes[0];
  2483. coff_inside_enumeration = (coff_type.orig_type == T_ENUM);
  2484. break;
  2485. /* For the end of structs, unions, and enumerations, omit the
  2486. name which is always ".eos". This needs to be done last, so
  2487. that any error reporting above gives the correct name. */
  2488. case st_End:
  2489. free (name);
  2490. name = (char *) NULL;
  2491. coff_value = 0;
  2492. coff_inside_enumeration = 0;
  2493. break;
  2494. /* Members of structures and unions that aren't bitfields, need
  2495. to adjust the value from a byte offset to a bit offset.
  2496. Members of enumerations do not have the value adjusted, and
  2497. can be distinguished by indx == indexNil. For enumerations,
  2498. update the maximum enumeration value. */
  2499. case st_Member:
  2500. if (! coff_type.bitfield && ! coff_inside_enumeration)
  2501. coff_value *= 8;
  2502. break;
  2503. }
  2504. /* Add the symbol. */
  2505. sym = add_ecoff_symbol (name,
  2506. coff_symbol_typ,
  2507. coff_storage_class,
  2508. coff_sym_value,
  2509. coff_sym_addend,
  2510. (symint_t) coff_value,
  2511. indx);
  2512. /* deal with struct, union, and enum tags. */
  2513. if (coff_symbol_typ == st_Block)
  2514. {
  2515. /* Create or update the tag information. */
  2516. tag_t *tag_ptr = get_tag (name,
  2517. sym,
  2518. coff_type.basic_type);
  2519. forward_t **pf;
  2520. /* Remember any forward references. */
  2521. for (pf = &sym->forward_ref;
  2522. *pf != (forward_t *) NULL;
  2523. pf = &(*pf)->next)
  2524. ;
  2525. *pf = tag_ptr->forward_ref;
  2526. tag_ptr->forward_ref = (forward_t *) NULL;
  2527. }
  2528. }
  2529. /* Parse .end directives. */
  2530. void
  2531. ecoff_directive_end (int ignore ATTRIBUTE_UNUSED)
  2532. {
  2533. char *name;
  2534. char name_end;
  2535. symbolS *ent;
  2536. if (cur_file_ptr == (efdr_t *) NULL)
  2537. {
  2538. as_warn (_(".end directive without a preceding .file directive"));
  2539. demand_empty_rest_of_line ();
  2540. return;
  2541. }
  2542. if (cur_proc_ptr == (proc_t *) NULL)
  2543. {
  2544. as_warn (_(".end directive without a preceding .ent directive"));
  2545. demand_empty_rest_of_line ();
  2546. return;
  2547. }
  2548. name_end = get_symbol_name (&name);
  2549. if (name == input_line_pointer)
  2550. {
  2551. as_warn (_(".end directive has no name"));
  2552. (void) restore_line_pointer (name_end);
  2553. demand_empty_rest_of_line ();
  2554. return;
  2555. }
  2556. /* The value is the distance between the .end directive and the
  2557. corresponding symbol. We create a fake symbol to hold the
  2558. current location, and put in the offset when we write out the
  2559. symbol. */
  2560. ent = symbol_find (name);
  2561. if (ent == (symbolS *) NULL)
  2562. as_warn (_(".end directive names unknown symbol"));
  2563. else
  2564. (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text,
  2565. symbol_new (FAKE_LABEL_NAME, now_seg,
  2566. frag_now, frag_now_fix ()),
  2567. (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
  2568. #ifdef md_flush_pending_output
  2569. md_flush_pending_output ();
  2570. #endif
  2571. cur_proc_ptr = (proc_t *) NULL;
  2572. (void) restore_line_pointer (name_end);
  2573. demand_empty_rest_of_line ();
  2574. }
  2575. /* Parse .ent directives. */
  2576. void
  2577. ecoff_directive_ent (int aent)
  2578. {
  2579. char *name;
  2580. char name_end;
  2581. if (cur_file_ptr == (efdr_t *) NULL)
  2582. add_file ((const char *) NULL, 0, 1);
  2583. if (!aent && cur_proc_ptr != (proc_t *) NULL)
  2584. {
  2585. as_warn (_("second .ent directive found before .end directive"));
  2586. demand_empty_rest_of_line ();
  2587. return;
  2588. }
  2589. name_end = get_symbol_name (&name);
  2590. if (name == input_line_pointer)
  2591. {
  2592. as_warn (_("%s directive has no name"), aent ? ".aent" : ".ent");
  2593. (void) restore_line_pointer (name_end);
  2594. demand_empty_rest_of_line ();
  2595. return;
  2596. }
  2597. add_procedure (name, aent);
  2598. (void) restore_line_pointer (name_end);
  2599. /* The .ent directive is sometimes followed by a number. I'm not
  2600. really sure what the number means. I don't see any way to store
  2601. the information in the PDR. The Irix 4 assembler seems to ignore
  2602. the information. */
  2603. SKIP_WHITESPACE ();
  2604. if (*input_line_pointer == ',')
  2605. {
  2606. ++input_line_pointer;
  2607. SKIP_WHITESPACE ();
  2608. }
  2609. if (ISDIGIT (*input_line_pointer)
  2610. || *input_line_pointer == '-')
  2611. (void) get_absolute_expression ();
  2612. demand_empty_rest_of_line ();
  2613. }
  2614. /* Parse .extern directives. */
  2615. void
  2616. ecoff_directive_extern (int ignore ATTRIBUTE_UNUSED)
  2617. {
  2618. char *name;
  2619. int c;
  2620. symbolS *symbolp;
  2621. valueT size;
  2622. c = get_symbol_name (&name);
  2623. symbolp = symbol_find_or_make (name);
  2624. (void) restore_line_pointer (c);
  2625. S_SET_EXTERNAL (symbolp);
  2626. if (*input_line_pointer == ',')
  2627. ++input_line_pointer;
  2628. size = get_absolute_expression ();
  2629. symbol_get_obj (symbolp)->ecoff_extern_size = size;
  2630. }
  2631. /* Parse .file directives. */
  2632. void
  2633. ecoff_directive_file (int ignore ATTRIBUTE_UNUSED)
  2634. {
  2635. int indx;
  2636. char *name;
  2637. int len;
  2638. if (cur_proc_ptr != (proc_t *) NULL)
  2639. {
  2640. as_warn (_("no way to handle .file within .ent/.end section"));
  2641. demand_empty_rest_of_line ();
  2642. return;
  2643. }
  2644. indx = (int) get_absolute_expression ();
  2645. /* FIXME: we don't have to save the name here. */
  2646. name = demand_copy_C_string (&len);
  2647. add_file (name, indx - 1, 0);
  2648. demand_empty_rest_of_line ();
  2649. }
  2650. /* Parse .fmask directives. */
  2651. void
  2652. ecoff_directive_fmask (int ignore ATTRIBUTE_UNUSED)
  2653. {
  2654. long val;
  2655. if (cur_proc_ptr == (proc_t *) NULL)
  2656. {
  2657. as_warn (_(".fmask outside of .ent"));
  2658. demand_empty_rest_of_line ();
  2659. return;
  2660. }
  2661. if (get_absolute_expression_and_terminator (&val) != ',')
  2662. {
  2663. as_warn (_("bad .fmask directive"));
  2664. --input_line_pointer;
  2665. demand_empty_rest_of_line ();
  2666. return;
  2667. }
  2668. cur_proc_ptr->pdr.fregmask = val;
  2669. cur_proc_ptr->pdr.fregoffset = get_absolute_expression ();
  2670. demand_empty_rest_of_line ();
  2671. }
  2672. /* Parse .frame directives. */
  2673. void
  2674. ecoff_directive_frame (int ignore ATTRIBUTE_UNUSED)
  2675. {
  2676. long val;
  2677. if (cur_proc_ptr == (proc_t *) NULL)
  2678. {
  2679. as_warn (_(".frame outside of .ent"));
  2680. demand_empty_rest_of_line ();
  2681. return;
  2682. }
  2683. cur_proc_ptr->pdr.framereg = tc_get_register (1);
  2684. SKIP_WHITESPACE ();
  2685. if (*input_line_pointer++ != ','
  2686. || get_absolute_expression_and_terminator (&val) != ',')
  2687. {
  2688. as_warn (_("bad .frame directive"));
  2689. --input_line_pointer;
  2690. demand_empty_rest_of_line ();
  2691. return;
  2692. }
  2693. cur_proc_ptr->pdr.frameoffset = val;
  2694. cur_proc_ptr->pdr.pcreg = tc_get_register (0);
  2695. /* Alpha-OSF1 adds "the offset of saved $a0 from $sp", according to
  2696. Sandro. I don't yet know where this value should be stored, if
  2697. anywhere. Don't call demand_empty_rest_of_line (). */
  2698. s_ignore (42);
  2699. }
  2700. /* Parse .mask directives. */
  2701. void
  2702. ecoff_directive_mask (int ignore ATTRIBUTE_UNUSED)
  2703. {
  2704. long val;
  2705. if (cur_proc_ptr == (proc_t *) NULL)
  2706. {
  2707. as_warn (_(".mask outside of .ent"));
  2708. demand_empty_rest_of_line ();
  2709. return;
  2710. }
  2711. if (get_absolute_expression_and_terminator (&val) != ',')
  2712. {
  2713. as_warn (_("bad .mask directive"));
  2714. --input_line_pointer;
  2715. demand_empty_rest_of_line ();
  2716. return;
  2717. }
  2718. cur_proc_ptr->pdr.regmask = val;
  2719. cur_proc_ptr->pdr.regoffset = get_absolute_expression ();
  2720. demand_empty_rest_of_line ();
  2721. }
  2722. /* Parse .loc directives. */
  2723. void
  2724. ecoff_directive_loc (int ignore ATTRIBUTE_UNUSED)
  2725. {
  2726. lineno_list_t *list;
  2727. symint_t lineno;
  2728. if (cur_file_ptr == (efdr_t *) NULL)
  2729. {
  2730. as_warn (_(".loc before .file"));
  2731. demand_empty_rest_of_line ();
  2732. return;
  2733. }
  2734. if (now_seg != text_section)
  2735. {
  2736. as_warn (_(".loc outside of .text"));
  2737. demand_empty_rest_of_line ();
  2738. return;
  2739. }
  2740. /* Skip the file number. */
  2741. SKIP_WHITESPACE ();
  2742. get_absolute_expression ();
  2743. SKIP_WHITESPACE ();
  2744. lineno = get_absolute_expression ();
  2745. #ifndef NO_LISTING
  2746. if (listing)
  2747. listing_source_line (lineno);
  2748. #endif
  2749. /* If we're building stabs, then output a special label rather than
  2750. ECOFF line number info. */
  2751. if (stabs_seen)
  2752. {
  2753. (void) add_ecoff_symbol ((char *) NULL, st_Label, sc_Text,
  2754. symbol_new (FAKE_LABEL_NAME, now_seg,
  2755. frag_now, frag_now_fix ()),
  2756. (bfd_vma) 0, 0, lineno);
  2757. return;
  2758. }
  2759. list = allocate_lineno_list ();
  2760. list->next = (lineno_list_t *) NULL;
  2761. list->file = cur_file_ptr;
  2762. list->proc = cur_proc_ptr;
  2763. list->frag = frag_now;
  2764. list->paddr = frag_now_fix ();
  2765. list->lineno = lineno;
  2766. /* We don't want to merge files which have line numbers. */
  2767. cur_file_ptr->fdr.fMerge = 0;
  2768. /* A .loc directive will sometimes appear before a .ent directive,
  2769. which means that cur_proc_ptr will be NULL here. Arrange to
  2770. patch this up. */
  2771. if (cur_proc_ptr == (proc_t *) NULL)
  2772. {
  2773. lineno_list_t **pl;
  2774. pl = &noproc_lineno;
  2775. while (*pl != (lineno_list_t *) NULL)
  2776. pl = &(*pl)->next;
  2777. *pl = list;
  2778. }
  2779. else
  2780. {
  2781. last_lineno = list;
  2782. *last_lineno_ptr = list;
  2783. last_lineno_ptr = &list->next;
  2784. }
  2785. }
  2786. /* The MIPS assembler sometimes inserts nop instructions in the
  2787. instruction stream. When this happens, we must patch up the .loc
  2788. information so that it points to the instruction after the nop. */
  2789. void
  2790. ecoff_fix_loc (fragS *old_frag, unsigned long old_frag_offset)
  2791. {
  2792. if (last_lineno != NULL
  2793. && last_lineno->frag == old_frag
  2794. && last_lineno->paddr == old_frag_offset)
  2795. {
  2796. last_lineno->frag = frag_now;
  2797. last_lineno->paddr = frag_now_fix ();
  2798. }
  2799. }
  2800. /* Make sure the @stabs symbol is emitted. */
  2801. static void
  2802. mark_stabs (int ignore ATTRIBUTE_UNUSED)
  2803. {
  2804. if (! stabs_seen)
  2805. {
  2806. /* Add a dummy @stabs symbol. */
  2807. stabs_seen = 1;
  2808. (void) add_ecoff_symbol (stabs_symbol, st_Nil, sc_Info,
  2809. (symbolS *) NULL,
  2810. (bfd_vma) 0, (symint_t) -1,
  2811. ECOFF_MARK_STAB (0));
  2812. }
  2813. }
  2814. /* Parse .weakext directives. */
  2815. #ifndef TC_MIPS
  2816. /* For TC_MIPS use the version in tc-mips.c. */
  2817. void
  2818. ecoff_directive_weakext (int ignore ATTRIBUTE_UNUSED)
  2819. {
  2820. char *name;
  2821. int c;
  2822. symbolS *symbolP;
  2823. expressionS exp;
  2824. c = get_symbol_name (&name);
  2825. symbolP = symbol_find_or_make (name);
  2826. (void) restore_line_pointer (c);
  2827. SKIP_WHITESPACE ();
  2828. if (*input_line_pointer == ',')
  2829. {
  2830. if (S_IS_DEFINED (symbolP))
  2831. {
  2832. as_bad (_("symbol `%s' is already defined"),
  2833. S_GET_NAME (symbolP));
  2834. ignore_rest_of_line ();
  2835. return;
  2836. }
  2837. ++input_line_pointer;
  2838. SKIP_WHITESPACE ();
  2839. if (! is_end_of_line[(unsigned char) *input_line_pointer])
  2840. {
  2841. expression (&exp);
  2842. if (exp.X_op != O_symbol)
  2843. {
  2844. as_bad (_("bad .weakext directive"));
  2845. ignore_rest_of_line ();
  2846. return;
  2847. }
  2848. symbol_set_value_expression (symbolP, &exp);
  2849. }
  2850. }
  2851. S_SET_WEAK (symbolP);
  2852. demand_empty_rest_of_line ();
  2853. }
  2854. #endif /* not TC_MIPS */
  2855. /* Handle .stabs directives. The actual parsing routine is done by a
  2856. generic routine. This routine is called via OBJ_PROCESS_STAB.
  2857. When this is called, input_line_pointer will be pointing at the
  2858. value field of the stab.
  2859. .stabs directives have five fields:
  2860. "string" a string, encoding the type information.
  2861. code a numeric code, defined in <stab.h>
  2862. 0 a zero
  2863. desc a zero or line number
  2864. value a numeric value or an address.
  2865. If the value is relocatable, we transform this into:
  2866. iss points as an index into string space
  2867. value value from lookup of the name
  2868. st st from lookup of the name
  2869. sc sc from lookup of the name
  2870. index code|CODE_MASK
  2871. If the value is not relocatable, we transform this into:
  2872. iss points as an index into string space
  2873. value value
  2874. st st_Nil
  2875. sc sc_Nil
  2876. index code|CODE_MASK
  2877. .stabn directives have four fields (string is null):
  2878. code a numeric code, defined in <stab.h>
  2879. 0 a zero
  2880. desc a zero or a line number
  2881. value a numeric value or an address. */
  2882. void
  2883. ecoff_stab (segT sec ATTRIBUTE_UNUSED,
  2884. int what,
  2885. const char *string,
  2886. int type,
  2887. int other,
  2888. int desc)
  2889. {
  2890. efdr_t *save_file_ptr = cur_file_ptr;
  2891. symbolS *sym;
  2892. symint_t value;
  2893. bfd_vma addend;
  2894. st_t st;
  2895. sc_t sc;
  2896. symint_t indx;
  2897. localsym_t *hold = NULL;
  2898. ecoff_debugging_seen = 1;
  2899. /* We don't handle .stabd. */
  2900. if (what != 's' && what != 'n')
  2901. {
  2902. as_bad (_(".stab%c is not supported"), what);
  2903. return;
  2904. }
  2905. /* A .stabn uses a null name, not an empty string. */
  2906. if (what == 'n')
  2907. string = NULL;
  2908. /* We ignore the other field. */
  2909. if (other != 0)
  2910. as_warn (_(".stab%c: ignoring non-zero other field"), what);
  2911. /* Make sure we have a current file. */
  2912. if (cur_file_ptr == (efdr_t *) NULL)
  2913. {
  2914. add_file ((const char *) NULL, 0, 1);
  2915. save_file_ptr = cur_file_ptr;
  2916. }
  2917. /* For stabs in ECOFF, the first symbol must be @stabs. This is a
  2918. signal to gdb. */
  2919. if (stabs_seen == 0)
  2920. mark_stabs (0);
  2921. /* Line number stabs are handled differently, since they have two
  2922. values, the line number and the address of the label. We use the
  2923. index field (aka desc) to hold the line number, and the value
  2924. field to hold the address. The symbol type is st_Label, which
  2925. should be different from the other stabs, so that gdb can
  2926. recognize it. */
  2927. if (type == N_SLINE)
  2928. {
  2929. SYMR dummy_symr;
  2930. char *name;
  2931. char name_end;
  2932. #ifndef NO_LISTING
  2933. if (listing)
  2934. listing_source_line ((unsigned int) desc);
  2935. #endif
  2936. dummy_symr.index = desc;
  2937. if (dummy_symr.index != desc)
  2938. {
  2939. as_warn (_("line number (%d) for .stab%c directive cannot fit in index field (20 bits)"),
  2940. desc, what);
  2941. return;
  2942. }
  2943. name_end = get_symbol_name (&name);
  2944. sym = symbol_find_or_make (name);
  2945. (void) restore_line_pointer (name_end);
  2946. value = 0;
  2947. addend = 0;
  2948. st = st_Label;
  2949. sc = sc_Text;
  2950. indx = desc;
  2951. }
  2952. else
  2953. {
  2954. #ifndef NO_LISTING
  2955. if (listing && (type == N_SO || type == N_SOL))
  2956. listing_source_file (string);
  2957. #endif
  2958. if (ISDIGIT (*input_line_pointer)
  2959. || *input_line_pointer == '-'
  2960. || *input_line_pointer == '+')
  2961. {
  2962. st = st_Nil;
  2963. sc = sc_Nil;
  2964. sym = (symbolS *) NULL;
  2965. value = get_absolute_expression ();
  2966. addend = 0;
  2967. }
  2968. else if (! is_name_beginner ((unsigned char) *input_line_pointer))
  2969. {
  2970. as_warn (_("illegal .stab%c directive, bad character"), what);
  2971. return;
  2972. }
  2973. else
  2974. {
  2975. expressionS exp;
  2976. sc = sc_Nil;
  2977. st = st_Nil;
  2978. expression (&exp);
  2979. if (exp.X_op == O_constant)
  2980. {
  2981. sym = NULL;
  2982. value = exp.X_add_number;
  2983. addend = 0;
  2984. }
  2985. else if (exp.X_op == O_symbol)
  2986. {
  2987. sym = exp.X_add_symbol;
  2988. value = 0;
  2989. addend = exp.X_add_number;
  2990. }
  2991. else
  2992. {
  2993. sym = make_expr_symbol (&exp);
  2994. value = 0;
  2995. addend = 0;
  2996. }
  2997. }
  2998. indx = ECOFF_MARK_STAB (type);
  2999. }
  3000. /* Don't store the stabs symbol we are creating as the type of the
  3001. ECOFF symbol. We want to compute the type of the ECOFF symbol
  3002. independently. */
  3003. if (sym != (symbolS *) NULL)
  3004. hold = symbol_get_obj (sym)->ecoff_symbol;
  3005. (void) add_ecoff_symbol (string, st, sc, sym, addend, value, indx);
  3006. if (sym != (symbolS *) NULL)
  3007. symbol_get_obj (sym)->ecoff_symbol = hold;
  3008. /* Restore normal file type. */
  3009. cur_file_ptr = save_file_ptr;
  3010. }
  3011. static asection ecoff_scom_section;
  3012. static const asymbol ecoff_scom_symbol =
  3013. GLOBAL_SYM_INIT (SCOMMON, &ecoff_scom_section);
  3014. static asection ecoff_scom_section =
  3015. BFD_FAKE_SECTION (ecoff_scom_section, &ecoff_scom_symbol,
  3016. SCOMMON, 0, SEC_IS_COMMON | SEC_SMALL_DATA);
  3017. /* Frob an ECOFF symbol. Small common symbols go into a special
  3018. .scommon section rather than bfd_com_section. */
  3019. void
  3020. ecoff_frob_symbol (symbolS *sym)
  3021. {
  3022. if (S_IS_COMMON (sym)
  3023. && S_GET_VALUE (sym) > 0
  3024. && S_GET_VALUE (sym) <= bfd_get_gp_size (stdoutput))
  3025. {
  3026. S_SET_SEGMENT (sym, &ecoff_scom_section);
  3027. }
  3028. /* Double check weak symbols. */
  3029. if (S_IS_WEAK (sym))
  3030. {
  3031. if (S_IS_COMMON (sym))
  3032. as_bad (_("symbol `%s' can not be both weak and common"),
  3033. S_GET_NAME (sym));
  3034. }
  3035. }
  3036. /* Add bytes to the symbolic information buffer. */
  3037. static char *
  3038. ecoff_add_bytes (char **buf,
  3039. char **bufend,
  3040. char *bufptr,
  3041. unsigned long need)
  3042. {
  3043. unsigned long at;
  3044. unsigned long want;
  3045. at = bufptr - *buf;
  3046. need -= *bufend - bufptr;
  3047. if (need < PAGE_SIZE)
  3048. need = PAGE_SIZE;
  3049. want = (*bufend - *buf) + need;
  3050. *buf = XRESIZEVEC (char, *buf, want);
  3051. *bufend = *buf + want;
  3052. return *buf + at;
  3053. }
  3054. /* Adjust the symbolic information buffer to the alignment required
  3055. for the ECOFF target debugging information. */
  3056. static unsigned long
  3057. ecoff_padding_adjust (const struct ecoff_debug_swap *backend,
  3058. char **buf,
  3059. char **bufend,
  3060. unsigned long offset,
  3061. char **bufptrptr)
  3062. {
  3063. bfd_size_type align;
  3064. align = backend->debug_align;
  3065. if ((offset & (align - 1)) != 0)
  3066. {
  3067. unsigned long add;
  3068. add = align - (offset & (align - 1));
  3069. if ((unsigned long) (*bufend - (*buf + offset)) < add)
  3070. (void) ecoff_add_bytes (buf, bufend, *buf + offset, add);
  3071. memset (*buf + offset, 0, add);
  3072. offset += add;
  3073. if (bufptrptr != (char **) NULL)
  3074. *bufptrptr = *buf + offset;
  3075. }
  3076. return offset;
  3077. }
  3078. /* Build the line number information. */
  3079. static unsigned long
  3080. ecoff_build_lineno (const struct ecoff_debug_swap *backend,
  3081. char **buf,
  3082. char **bufend,
  3083. unsigned long offset,
  3084. long *linecntptr)
  3085. {
  3086. char *bufptr;
  3087. lineno_list_t *l;
  3088. lineno_list_t *last;
  3089. efdr_t *file;
  3090. proc_t *proc;
  3091. unsigned long c;
  3092. long iline;
  3093. long totcount;
  3094. lineno_list_t first;
  3095. lineno_list_t *local_first_lineno = first_lineno;
  3096. if (linecntptr != (long *) NULL)
  3097. *linecntptr = 0;
  3098. bufptr = *buf + offset;
  3099. file = (efdr_t *) NULL;
  3100. proc = (proc_t *) NULL;
  3101. last = (lineno_list_t *) NULL;
  3102. c = offset;
  3103. iline = 0;
  3104. totcount = 0;
  3105. /* FIXME? Now that MIPS embedded-PIC is gone, it may be safe to
  3106. remove this code. */
  3107. /* For some reason the address of the first procedure is ignored
  3108. when reading line numbers. This doesn't matter if the address of
  3109. the first procedure is 0, but when gcc is generating MIPS
  3110. embedded PIC code, it will put strings in the .text section
  3111. before the first procedure. We cope by inserting a dummy line if
  3112. the address of the first procedure is not 0. Hopefully this
  3113. won't screw things up too badly.
  3114. Don't do this for ECOFF assembly source line numbers. They work
  3115. without this extra attention. */
  3116. if (debug_type != DEBUG_ECOFF
  3117. && first_proc_ptr != (proc_t *) NULL
  3118. && local_first_lineno != (lineno_list_t *) NULL
  3119. && ((S_GET_VALUE (first_proc_ptr->sym->as_sym)
  3120. + bfd_section_vma (S_GET_SEGMENT (first_proc_ptr->sym->as_sym)))
  3121. != 0))
  3122. {
  3123. first.file = local_first_lineno->file;
  3124. first.proc = local_first_lineno->proc;
  3125. first.frag = &zero_address_frag;
  3126. first.paddr = 0;
  3127. first.lineno = 0;
  3128. first.next = local_first_lineno;
  3129. local_first_lineno = &first;
  3130. }
  3131. for (l = local_first_lineno; l != (lineno_list_t *) NULL; l = l->next)
  3132. {
  3133. long count;
  3134. long delta;
  3135. /* Get the offset to the memory address of the next line number
  3136. (in words). Do this first, so that we can skip ahead to the
  3137. next useful line number entry. */
  3138. if (l->next == (lineno_list_t *) NULL)
  3139. {
  3140. /* We want a count of zero, but it will be decremented
  3141. before it is used. */
  3142. count = 1;
  3143. }
  3144. else if (l->next->frag->fr_address + l->next->paddr
  3145. > l->frag->fr_address + l->paddr)
  3146. {
  3147. count = ((l->next->frag->fr_address + l->next->paddr
  3148. - (l->frag->fr_address + l->paddr))
  3149. >> 2);
  3150. }
  3151. else
  3152. {
  3153. /* Don't change last, so we still get the right delta. */
  3154. continue;
  3155. }
  3156. if (l->file != file || l->proc != proc)
  3157. {
  3158. if (l->proc != proc && proc != (proc_t *) NULL)
  3159. proc->pdr.lnHigh = last->lineno;
  3160. if (l->file != file && file != (efdr_t *) NULL)
  3161. {
  3162. file->fdr.cbLine = c - file->fdr.cbLineOffset;
  3163. file->fdr.cline = totcount + count;
  3164. if (linecntptr != (long *) NULL)
  3165. *linecntptr += totcount + count;
  3166. totcount = 0;
  3167. }
  3168. if (l->file != file)
  3169. {
  3170. efdr_t *last_file = file;
  3171. file = l->file;
  3172. if (last_file != (efdr_t *) NULL)
  3173. file->fdr.ilineBase
  3174. = last_file->fdr.ilineBase + last_file->fdr.cline;
  3175. else
  3176. file->fdr.ilineBase = 0;
  3177. file->fdr.cbLineOffset = c;
  3178. }
  3179. if (l->proc != proc)
  3180. {
  3181. proc = l->proc;
  3182. if (proc != (proc_t *) NULL)
  3183. {
  3184. proc->pdr.lnLow = l->lineno;
  3185. proc->pdr.cbLineOffset = c - file->fdr.cbLineOffset;
  3186. proc->pdr.iline = totcount;
  3187. }
  3188. }
  3189. last = (lineno_list_t *) NULL;
  3190. }
  3191. totcount += count;
  3192. /* Get the offset to this line number. */
  3193. if (last == (lineno_list_t *) NULL)
  3194. delta = 0;
  3195. else
  3196. delta = l->lineno - last->lineno;
  3197. /* Put in the offset to this line number. */
  3198. while (delta != 0)
  3199. {
  3200. int setcount;
  3201. /* 1 is added to each count read. */
  3202. --count;
  3203. /* We can only adjust the word count by up to 15 words at a
  3204. time. */
  3205. if (count <= 0x0f)
  3206. {
  3207. setcount = count;
  3208. count = 0;
  3209. }
  3210. else
  3211. {
  3212. setcount = 0x0f;
  3213. count -= 0x0f;
  3214. }
  3215. if (delta >= -7 && delta <= 7)
  3216. {
  3217. if (bufptr >= *bufend)
  3218. bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
  3219. *bufptr++ = setcount + (delta << 4);
  3220. delta = 0;
  3221. ++c;
  3222. }
  3223. else
  3224. {
  3225. int set;
  3226. if (*bufend - bufptr < 3)
  3227. bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 3);
  3228. *bufptr++ = setcount + (8 << 4);
  3229. if (delta < -0x8000)
  3230. {
  3231. set = -0x8000;
  3232. delta += 0x8000;
  3233. }
  3234. else if (delta > 0x7fff)
  3235. {
  3236. set = 0x7fff;
  3237. delta -= 0x7fff;
  3238. }
  3239. else
  3240. {
  3241. set = delta;
  3242. delta = 0;
  3243. }
  3244. *bufptr++ = set >> 8;
  3245. *bufptr++ = set & 0xffff;
  3246. c += 3;
  3247. }
  3248. }
  3249. /* Finish adjusting the count. */
  3250. while (count > 0)
  3251. {
  3252. if (bufptr >= *bufend)
  3253. bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
  3254. /* 1 is added to each count read. */
  3255. --count;
  3256. if (count > 0x0f)
  3257. {
  3258. *bufptr++ = 0x0f;
  3259. count -= 0x0f;
  3260. }
  3261. else
  3262. {
  3263. *bufptr++ = count;
  3264. count = 0;
  3265. }
  3266. ++c;
  3267. }
  3268. ++iline;
  3269. last = l;
  3270. }
  3271. if (proc != (proc_t *) NULL)
  3272. proc->pdr.lnHigh = last->lineno;
  3273. if (file != (efdr_t *) NULL)
  3274. {
  3275. file->fdr.cbLine = c - file->fdr.cbLineOffset;
  3276. file->fdr.cline = totcount;
  3277. }
  3278. if (linecntptr != (long *) NULL)
  3279. *linecntptr += totcount;
  3280. c = ecoff_padding_adjust (backend, buf, bufend, c, &bufptr);
  3281. return c;
  3282. }
  3283. /* Build and swap out the symbols. */
  3284. static unsigned long
  3285. ecoff_build_symbols (const struct ecoff_debug_swap *backend,
  3286. char **buf,
  3287. char **bufend,
  3288. unsigned long offset)
  3289. {
  3290. const bfd_size_type external_sym_size = backend->external_sym_size;
  3291. void (* const swap_sym_out) (bfd *, const SYMR *, void *)
  3292. = backend->swap_sym_out;
  3293. char *sym_out;
  3294. long isym;
  3295. vlinks_t *file_link;
  3296. sym_out = *buf + offset;
  3297. isym = 0;
  3298. /* The symbols are stored by file. */
  3299. for (file_link = file_desc.first;
  3300. file_link != (vlinks_t *) NULL;
  3301. file_link = file_link->next)
  3302. {
  3303. int ifilesym;
  3304. int fil_cnt;
  3305. efdr_t *fil_ptr;
  3306. efdr_t *fil_end;
  3307. if (file_link->next == (vlinks_t *) NULL)
  3308. fil_cnt = file_desc.objects_last_page;
  3309. else
  3310. fil_cnt = file_desc.objects_per_page;
  3311. fil_ptr = file_link->datum->file;
  3312. fil_end = fil_ptr + fil_cnt;
  3313. for (; fil_ptr < fil_end; fil_ptr++)
  3314. {
  3315. vlinks_t *sym_link;
  3316. fil_ptr->fdr.isymBase = isym;
  3317. ifilesym = isym;
  3318. for (sym_link = fil_ptr->symbols.first;
  3319. sym_link != (vlinks_t *) NULL;
  3320. sym_link = sym_link->next)
  3321. {
  3322. int sym_cnt;
  3323. localsym_t *sym_ptr;
  3324. localsym_t *sym_end;
  3325. if (sym_link->next == (vlinks_t *) NULL)
  3326. sym_cnt = fil_ptr->symbols.objects_last_page;
  3327. else
  3328. sym_cnt = fil_ptr->symbols.objects_per_page;
  3329. sym_ptr = sym_link->datum->sym;
  3330. sym_end = sym_ptr + sym_cnt;
  3331. for (; sym_ptr < sym_end; sym_ptr++)
  3332. {
  3333. int local;
  3334. symbolS *as_sym;
  3335. forward_t *f;
  3336. know (sym_ptr->file_ptr == fil_ptr);
  3337. /* If there is no associated gas symbol, then this
  3338. is a pure debugging symbol. We have already
  3339. added the name (if any) to fil_ptr->strings.
  3340. Otherwise we must decide whether this is an
  3341. external or a local symbol (actually, it may be
  3342. both if the local provides additional debugging
  3343. information for the external). */
  3344. local = 1;
  3345. as_sym = sym_ptr->as_sym;
  3346. if (as_sym != (symbolS *) NULL)
  3347. {
  3348. symint_t indx;
  3349. /* The value of a block start symbol is the
  3350. offset from the start of the procedure. For
  3351. other symbols we just use the gas value (but
  3352. we must offset it by the vma of the section,
  3353. just as BFD does, because BFD will not see
  3354. this value). */
  3355. if (sym_ptr->ecoff_sym.asym.st == (int) st_Block
  3356. && sym_ptr->ecoff_sym.asym.sc == (int) sc_Text)
  3357. {
  3358. symbolS *begin_sym;
  3359. know (sym_ptr->proc_ptr != (proc_t *) NULL);
  3360. begin_sym = sym_ptr->proc_ptr->sym->as_sym;
  3361. if (S_GET_SEGMENT (as_sym)
  3362. != S_GET_SEGMENT (begin_sym))
  3363. as_warn (_(".begin/.bend in different segments"));
  3364. sym_ptr->ecoff_sym.asym.value =
  3365. S_GET_VALUE (as_sym) - S_GET_VALUE (begin_sym);
  3366. }
  3367. else
  3368. sym_ptr->ecoff_sym.asym.value =
  3369. (S_GET_VALUE (as_sym)
  3370. + bfd_section_vma (S_GET_SEGMENT (as_sym))
  3371. + sym_ptr->addend);
  3372. sym_ptr->ecoff_sym.weakext = S_IS_WEAK (as_sym);
  3373. /* Set st_Proc to st_StaticProc for local
  3374. functions. */
  3375. if (sym_ptr->ecoff_sym.asym.st == st_Proc
  3376. && S_IS_DEFINED (as_sym)
  3377. && ! S_IS_EXTERNAL (as_sym)
  3378. && ! S_IS_WEAK (as_sym))
  3379. sym_ptr->ecoff_sym.asym.st = st_StaticProc;
  3380. /* Get the type and storage class based on where
  3381. the symbol actually wound up. Traditionally,
  3382. N_LBRAC and N_RBRAC are *not* relocated. */
  3383. indx = sym_ptr->ecoff_sym.asym.index;
  3384. if (sym_ptr->ecoff_sym.asym.st == st_Nil
  3385. && sym_ptr->ecoff_sym.asym.sc == sc_Nil
  3386. && (! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym)
  3387. || ((ECOFF_UNMARK_STAB (indx) != N_LBRAC)
  3388. && (ECOFF_UNMARK_STAB (indx) != N_RBRAC))))
  3389. {
  3390. segT seg;
  3391. const char *segname;
  3392. st_t st;
  3393. sc_t sc;
  3394. seg = S_GET_SEGMENT (as_sym);
  3395. segname = segment_name (seg);
  3396. if (! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym)
  3397. && (S_IS_EXTERNAL (as_sym)
  3398. || S_IS_WEAK (as_sym)
  3399. || ! S_IS_DEFINED (as_sym)))
  3400. {
  3401. if ((symbol_get_bfdsym (as_sym)->flags
  3402. & BSF_FUNCTION) != 0)
  3403. st = st_Proc;
  3404. else
  3405. st = st_Global;
  3406. }
  3407. else if (seg == text_section)
  3408. st = st_Label;
  3409. else
  3410. st = st_Static;
  3411. if (! S_IS_DEFINED (as_sym))
  3412. {
  3413. valueT s;
  3414. s = symbol_get_obj (as_sym)->ecoff_extern_size;
  3415. if (s == 0
  3416. || s > bfd_get_gp_size (stdoutput))
  3417. sc = sc_Undefined;
  3418. else
  3419. {
  3420. sc = sc_SUndefined;
  3421. sym_ptr->ecoff_sym.asym.value = s;
  3422. }
  3423. #ifdef S_SET_SIZE
  3424. S_SET_SIZE (as_sym, s);
  3425. #endif
  3426. }
  3427. else if (S_IS_COMMON (as_sym))
  3428. {
  3429. if (S_GET_VALUE (as_sym) > 0
  3430. && (S_GET_VALUE (as_sym)
  3431. <= bfd_get_gp_size (stdoutput)))
  3432. sc = sc_SCommon;
  3433. else
  3434. sc = sc_Common;
  3435. }
  3436. else if (seg == text_section)
  3437. sc = sc_Text;
  3438. else if (seg == data_section)
  3439. sc = sc_Data;
  3440. else if (strcmp (segname, ".rdata") == 0
  3441. || strcmp (segname, ".rodata") == 0)
  3442. sc = sc_RData;
  3443. else if (strcmp (segname, ".sdata") == 0)
  3444. sc = sc_SData;
  3445. else if (seg == bss_section)
  3446. sc = sc_Bss;
  3447. else if (strcmp (segname, ".sbss") == 0)
  3448. sc = sc_SBss;
  3449. else if (seg == bfd_abs_section_ptr)
  3450. sc = sc_Abs;
  3451. else
  3452. {
  3453. /* This must be a user named section.
  3454. This is not possible in ECOFF, but it
  3455. is in ELF. */
  3456. sc = sc_Data;
  3457. }
  3458. sym_ptr->ecoff_sym.asym.st = (int) st;
  3459. sym_ptr->ecoff_sym.asym.sc = (int) sc;
  3460. }
  3461. /* This is just an external symbol if it is
  3462. outside a procedure and it has a type.
  3463. FIXME: g++ will generate symbols which have
  3464. different names in the debugging information
  3465. than the actual symbol. Should we handle
  3466. them here? */
  3467. if ((S_IS_EXTERNAL (as_sym)
  3468. || S_IS_WEAK (as_sym)
  3469. || ! S_IS_DEFINED (as_sym))
  3470. && sym_ptr->proc_ptr == (proc_t *) NULL
  3471. && sym_ptr->ecoff_sym.asym.st != (int) st_Nil
  3472. && ! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym))
  3473. local = 0;
  3474. /* This is just an external symbol if it is a
  3475. common symbol. */
  3476. if (S_IS_COMMON (as_sym))
  3477. local = 0;
  3478. /* If an st_end symbol has an associated gas
  3479. symbol, then it is a local label created for
  3480. a .bend or .end directive. Stabs line
  3481. numbers will have FAKE_LABEL_CHAR in the names. */
  3482. if (local
  3483. && sym_ptr->ecoff_sym.asym.st != st_End
  3484. && strchr (sym_ptr->name, FAKE_LABEL_CHAR) == 0)
  3485. sym_ptr->ecoff_sym.asym.iss =
  3486. add_string (&fil_ptr->strings,
  3487. fil_ptr->str_hash,
  3488. sym_ptr->name,
  3489. (shash_t **) NULL);
  3490. }
  3491. /* We now know the index of this symbol; fill in
  3492. locations that have been waiting for that
  3493. information. */
  3494. if (sym_ptr->begin_ptr != (localsym_t *) NULL)
  3495. {
  3496. localsym_t *begin_ptr;
  3497. st_t begin_type;
  3498. know (local);
  3499. begin_ptr = sym_ptr->begin_ptr;
  3500. know (begin_ptr->sym_index != -1);
  3501. sym_ptr->ecoff_sym.asym.index = begin_ptr->sym_index;
  3502. if (sym_ptr->ecoff_sym.asym.sc != (int) sc_Info)
  3503. sym_ptr->ecoff_sym.asym.iss =
  3504. begin_ptr->ecoff_sym.asym.iss;
  3505. begin_type = (st_t) begin_ptr->ecoff_sym.asym.st;
  3506. if (begin_type == st_File
  3507. || begin_type == st_Block)
  3508. {
  3509. begin_ptr->ecoff_sym.asym.index =
  3510. isym - ifilesym + 1;
  3511. (*swap_sym_out) (stdoutput,
  3512. &begin_ptr->ecoff_sym.asym,
  3513. (*buf
  3514. + offset
  3515. + (begin_ptr->sym_index
  3516. * external_sym_size)));
  3517. }
  3518. else
  3519. {
  3520. know (begin_ptr->index_ptr != (aux_t *) NULL);
  3521. begin_ptr->index_ptr->data.isym =
  3522. isym - ifilesym + 1;
  3523. }
  3524. /* The value of the symbol marking the end of a
  3525. procedure is the size of the procedure. The
  3526. value of the symbol marking the end of a
  3527. block is the offset from the start of the
  3528. procedure to the block. */
  3529. if (begin_type == st_Proc
  3530. || begin_type == st_StaticProc)
  3531. {
  3532. know (as_sym != (symbolS *) NULL);
  3533. know (begin_ptr->as_sym != (symbolS *) NULL);
  3534. if (S_GET_SEGMENT (as_sym)
  3535. != S_GET_SEGMENT (begin_ptr->as_sym))
  3536. as_warn (_(".begin/.bend in different segments"));
  3537. sym_ptr->ecoff_sym.asym.value =
  3538. (S_GET_VALUE (as_sym)
  3539. - S_GET_VALUE (begin_ptr->as_sym));
  3540. /* If the size is odd, this is probably a
  3541. mips16 function; force it to be even. */
  3542. if ((sym_ptr->ecoff_sym.asym.value & 1) != 0)
  3543. ++sym_ptr->ecoff_sym.asym.value;
  3544. #ifdef S_SET_SIZE
  3545. S_SET_SIZE (begin_ptr->as_sym,
  3546. sym_ptr->ecoff_sym.asym.value);
  3547. #endif
  3548. }
  3549. else if (begin_type == st_Block
  3550. && sym_ptr->ecoff_sym.asym.sc != (int) sc_Info)
  3551. {
  3552. symbolS *begin_sym;
  3553. know (as_sym != (symbolS *) NULL);
  3554. know (sym_ptr->proc_ptr != (proc_t *) NULL);
  3555. begin_sym = sym_ptr->proc_ptr->sym->as_sym;
  3556. if (S_GET_SEGMENT (as_sym)
  3557. != S_GET_SEGMENT (begin_sym))
  3558. as_warn (_(".begin/.bend in different segments"));
  3559. sym_ptr->ecoff_sym.asym.value =
  3560. S_GET_VALUE (as_sym) - S_GET_VALUE (begin_sym);
  3561. }
  3562. }
  3563. for (f = sym_ptr->forward_ref;
  3564. f != (forward_t *) NULL;
  3565. f = f->next)
  3566. {
  3567. know (local);
  3568. f->ifd_ptr->data.isym = fil_ptr->file_index;
  3569. f->index_ptr->data.rndx.index = isym - ifilesym;
  3570. }
  3571. if (local)
  3572. {
  3573. if ((bfd_size_type)(*bufend - sym_out) < external_sym_size)
  3574. sym_out = ecoff_add_bytes (buf, bufend,
  3575. sym_out,
  3576. external_sym_size);
  3577. (*swap_sym_out) (stdoutput, &sym_ptr->ecoff_sym.asym,
  3578. sym_out);
  3579. sym_out += external_sym_size;
  3580. sym_ptr->sym_index = isym;
  3581. if (sym_ptr->proc_ptr != (proc_t *) NULL
  3582. && sym_ptr->proc_ptr->sym == sym_ptr)
  3583. sym_ptr->proc_ptr->pdr.isym = isym - ifilesym;
  3584. ++isym;
  3585. }
  3586. /* Record the local symbol index and file number in
  3587. case this is an external symbol. Note that this
  3588. destroys the asym.index field. */
  3589. if (as_sym != (symbolS *) NULL
  3590. && symbol_get_obj (as_sym)->ecoff_symbol == sym_ptr)
  3591. {
  3592. if ((sym_ptr->ecoff_sym.asym.st == st_Proc
  3593. || sym_ptr->ecoff_sym.asym.st == st_StaticProc)
  3594. && local)
  3595. sym_ptr->ecoff_sym.asym.index = isym - ifilesym - 1;
  3596. sym_ptr->ecoff_sym.ifd = fil_ptr->file_index;
  3597. /* Don't try to merge an FDR which has an
  3598. external symbol attached to it. */
  3599. if (S_IS_EXTERNAL (as_sym) || S_IS_WEAK (as_sym))
  3600. fil_ptr->fdr.fMerge = 0;
  3601. }
  3602. }
  3603. }
  3604. fil_ptr->fdr.csym = isym - fil_ptr->fdr.isymBase;
  3605. }
  3606. }
  3607. return offset + isym * external_sym_size;
  3608. }
  3609. /* Swap out the procedure information. */
  3610. static unsigned long
  3611. ecoff_build_procs (const struct ecoff_debug_swap *backend,
  3612. char **buf,
  3613. char **bufend,
  3614. unsigned long offset)
  3615. {
  3616. const bfd_size_type external_pdr_size = backend->external_pdr_size;
  3617. void (* const swap_pdr_out) (bfd *, const PDR *, void *)
  3618. = backend->swap_pdr_out;
  3619. char *pdr_out;
  3620. long iproc;
  3621. vlinks_t *file_link;
  3622. pdr_out = *buf + offset;
  3623. iproc = 0;
  3624. /* The procedures are stored by file. */
  3625. for (file_link = file_desc.first;
  3626. file_link != (vlinks_t *) NULL;
  3627. file_link = file_link->next)
  3628. {
  3629. int fil_cnt;
  3630. efdr_t *fil_ptr;
  3631. efdr_t *fil_end;
  3632. if (file_link->next == (vlinks_t *) NULL)
  3633. fil_cnt = file_desc.objects_last_page;
  3634. else
  3635. fil_cnt = file_desc.objects_per_page;
  3636. fil_ptr = file_link->datum->file;
  3637. fil_end = fil_ptr + fil_cnt;
  3638. for (; fil_ptr < fil_end; fil_ptr++)
  3639. {
  3640. vlinks_t *proc_link;
  3641. int first;
  3642. fil_ptr->fdr.ipdFirst = iproc;
  3643. first = 1;
  3644. for (proc_link = fil_ptr->procs.first;
  3645. proc_link != (vlinks_t *) NULL;
  3646. proc_link = proc_link->next)
  3647. {
  3648. int prc_cnt;
  3649. proc_t *proc_ptr;
  3650. proc_t *proc_end;
  3651. if (proc_link->next == (vlinks_t *) NULL)
  3652. prc_cnt = fil_ptr->procs.objects_last_page;
  3653. else
  3654. prc_cnt = fil_ptr->procs.objects_per_page;
  3655. proc_ptr = proc_link->datum->proc;
  3656. proc_end = proc_ptr + prc_cnt;
  3657. for (; proc_ptr < proc_end; proc_ptr++)
  3658. {
  3659. symbolS *adr_sym;
  3660. unsigned long adr;
  3661. adr_sym = proc_ptr->sym->as_sym;
  3662. adr = (S_GET_VALUE (adr_sym)
  3663. + bfd_section_vma (S_GET_SEGMENT (adr_sym)));
  3664. if (first)
  3665. {
  3666. /* This code used to force the adr of the very
  3667. first fdr to be 0. However, the native tools
  3668. don't do that, and I can't remember why it
  3669. used to work that way, so I took it out. */
  3670. fil_ptr->fdr.adr = adr;
  3671. first = 0;
  3672. }
  3673. proc_ptr->pdr.adr = adr - fil_ptr->fdr.adr;
  3674. if ((bfd_size_type)(*bufend - pdr_out) < external_pdr_size)
  3675. pdr_out = ecoff_add_bytes (buf, bufend,
  3676. pdr_out,
  3677. external_pdr_size);
  3678. (*swap_pdr_out) (stdoutput, &proc_ptr->pdr, pdr_out);
  3679. pdr_out += external_pdr_size;
  3680. ++iproc;
  3681. }
  3682. }
  3683. fil_ptr->fdr.cpd = iproc - fil_ptr->fdr.ipdFirst;
  3684. }
  3685. }
  3686. return offset + iproc * external_pdr_size;
  3687. }
  3688. /* Swap out the aux information. */
  3689. static unsigned long
  3690. ecoff_build_aux (const struct ecoff_debug_swap *backend,
  3691. char **buf,
  3692. char **bufend,
  3693. unsigned long offset)
  3694. {
  3695. int bigendian;
  3696. union aux_ext *aux_out;
  3697. long iaux;
  3698. vlinks_t *file_link;
  3699. bigendian = bfd_big_endian (stdoutput);
  3700. aux_out = (union aux_ext *) (*buf + offset);
  3701. iaux = 0;
  3702. /* The aux entries are stored by file. */
  3703. for (file_link = file_desc.first;
  3704. file_link != (vlinks_t *) NULL;
  3705. file_link = file_link->next)
  3706. {
  3707. int fil_cnt;
  3708. efdr_t *fil_ptr;
  3709. efdr_t *fil_end;
  3710. if (file_link->next == (vlinks_t *) NULL)
  3711. fil_cnt = file_desc.objects_last_page;
  3712. else
  3713. fil_cnt = file_desc.objects_per_page;
  3714. fil_ptr = file_link->datum->file;
  3715. fil_end = fil_ptr + fil_cnt;
  3716. for (; fil_ptr < fil_end; fil_ptr++)
  3717. {
  3718. vlinks_t *aux_link;
  3719. fil_ptr->fdr.fBigendian = bigendian;
  3720. fil_ptr->fdr.iauxBase = iaux;
  3721. for (aux_link = fil_ptr->aux_syms.first;
  3722. aux_link != (vlinks_t *) NULL;
  3723. aux_link = aux_link->next)
  3724. {
  3725. int aux_cnt;
  3726. aux_t *aux_ptr;
  3727. aux_t *aux_end;
  3728. if (aux_link->next == (vlinks_t *) NULL)
  3729. aux_cnt = fil_ptr->aux_syms.objects_last_page;
  3730. else
  3731. aux_cnt = fil_ptr->aux_syms.objects_per_page;
  3732. aux_ptr = aux_link->datum->aux;
  3733. aux_end = aux_ptr + aux_cnt;
  3734. for (; aux_ptr < aux_end; aux_ptr++)
  3735. {
  3736. if ((unsigned long) (*bufend - (char *) aux_out)
  3737. < sizeof (union aux_ext))
  3738. aux_out = ((union aux_ext *)
  3739. ecoff_add_bytes (buf, bufend,
  3740. (char *) aux_out,
  3741. sizeof (union aux_ext)));
  3742. switch (aux_ptr->type)
  3743. {
  3744. case aux_tir:
  3745. (*backend->swap_tir_out) (bigendian,
  3746. &aux_ptr->data.ti,
  3747. &aux_out->a_ti);
  3748. break;
  3749. case aux_rndx:
  3750. (*backend->swap_rndx_out) (bigendian,
  3751. &aux_ptr->data.rndx,
  3752. &aux_out->a_rndx);
  3753. break;
  3754. case aux_dnLow:
  3755. AUX_PUT_DNLOW (bigendian, aux_ptr->data.dnLow,
  3756. aux_out);
  3757. break;
  3758. case aux_dnHigh:
  3759. AUX_PUT_DNHIGH (bigendian, aux_ptr->data.dnHigh,
  3760. aux_out);
  3761. break;
  3762. case aux_isym:
  3763. AUX_PUT_ISYM (bigendian, aux_ptr->data.isym,
  3764. aux_out);
  3765. break;
  3766. case aux_iss:
  3767. AUX_PUT_ISS (bigendian, aux_ptr->data.iss,
  3768. aux_out);
  3769. break;
  3770. case aux_width:
  3771. AUX_PUT_WIDTH (bigendian, aux_ptr->data.width,
  3772. aux_out);
  3773. break;
  3774. case aux_count:
  3775. AUX_PUT_COUNT (bigendian, aux_ptr->data.count,
  3776. aux_out);
  3777. break;
  3778. }
  3779. ++aux_out;
  3780. ++iaux;
  3781. }
  3782. }
  3783. fil_ptr->fdr.caux = iaux - fil_ptr->fdr.iauxBase;
  3784. }
  3785. }
  3786. return ecoff_padding_adjust (backend, buf, bufend,
  3787. offset + iaux * sizeof (union aux_ext),
  3788. (char **) NULL);
  3789. }
  3790. /* Copy out the strings from a varray_t. This returns the number of
  3791. bytes copied, rather than the new offset. */
  3792. static unsigned long
  3793. ecoff_build_strings (char **buf,
  3794. char **bufend,
  3795. unsigned long offset,
  3796. varray_t *vp)
  3797. {
  3798. unsigned long istr;
  3799. char *str_out;
  3800. vlinks_t *str_link;
  3801. str_out = *buf + offset;
  3802. istr = 0;
  3803. for (str_link = vp->first;
  3804. str_link != (vlinks_t *) NULL;
  3805. str_link = str_link->next)
  3806. {
  3807. unsigned long str_cnt;
  3808. if (str_link->next == (vlinks_t *) NULL)
  3809. str_cnt = vp->objects_last_page;
  3810. else
  3811. str_cnt = vp->objects_per_page;
  3812. if ((unsigned long)(*bufend - str_out) < str_cnt)
  3813. str_out = ecoff_add_bytes (buf, bufend, str_out, str_cnt);
  3814. memcpy (str_out, str_link->datum->byte, str_cnt);
  3815. str_out += str_cnt;
  3816. istr += str_cnt;
  3817. }
  3818. return istr;
  3819. }
  3820. /* Dump out the local strings. */
  3821. static unsigned long
  3822. ecoff_build_ss (const struct ecoff_debug_swap *backend,
  3823. char **buf,
  3824. char **bufend,
  3825. unsigned long offset)
  3826. {
  3827. long iss;
  3828. vlinks_t *file_link;
  3829. iss = 0;
  3830. for (file_link = file_desc.first;
  3831. file_link != (vlinks_t *) NULL;
  3832. file_link = file_link->next)
  3833. {
  3834. int fil_cnt;
  3835. efdr_t *fil_ptr;
  3836. efdr_t *fil_end;
  3837. if (file_link->next == (vlinks_t *) NULL)
  3838. fil_cnt = file_desc.objects_last_page;
  3839. else
  3840. fil_cnt = file_desc.objects_per_page;
  3841. fil_ptr = file_link->datum->file;
  3842. fil_end = fil_ptr + fil_cnt;
  3843. for (; fil_ptr < fil_end; fil_ptr++)
  3844. {
  3845. long ss_cnt;
  3846. fil_ptr->fdr.issBase = iss;
  3847. ss_cnt = ecoff_build_strings (buf, bufend, offset + iss,
  3848. &fil_ptr->strings);
  3849. fil_ptr->fdr.cbSs = ss_cnt;
  3850. iss += ss_cnt;
  3851. }
  3852. }
  3853. return ecoff_padding_adjust (backend, buf, bufend, offset + iss,
  3854. (char **) NULL);
  3855. }
  3856. /* Swap out the file descriptors. */
  3857. static unsigned long
  3858. ecoff_build_fdr (const struct ecoff_debug_swap *backend,
  3859. char **buf,
  3860. char **bufend,
  3861. unsigned long offset)
  3862. {
  3863. const bfd_size_type external_fdr_size = backend->external_fdr_size;
  3864. void (* const swap_fdr_out) (bfd *, const FDR *, void *)
  3865. = backend->swap_fdr_out;
  3866. long ifile;
  3867. char *fdr_out;
  3868. vlinks_t *file_link;
  3869. ifile = 0;
  3870. fdr_out = *buf + offset;
  3871. for (file_link = file_desc.first;
  3872. file_link != (vlinks_t *) NULL;
  3873. file_link = file_link->next)
  3874. {
  3875. int fil_cnt;
  3876. efdr_t *fil_ptr;
  3877. efdr_t *fil_end;
  3878. if (file_link->next == (vlinks_t *) NULL)
  3879. fil_cnt = file_desc.objects_last_page;
  3880. else
  3881. fil_cnt = file_desc.objects_per_page;
  3882. fil_ptr = file_link->datum->file;
  3883. fil_end = fil_ptr + fil_cnt;
  3884. for (; fil_ptr < fil_end; fil_ptr++)
  3885. {
  3886. if ((bfd_size_type)(*bufend - fdr_out) < external_fdr_size)
  3887. fdr_out = ecoff_add_bytes (buf, bufend, fdr_out,
  3888. external_fdr_size);
  3889. (*swap_fdr_out) (stdoutput, &fil_ptr->fdr, fdr_out);
  3890. fdr_out += external_fdr_size;
  3891. ++ifile;
  3892. }
  3893. }
  3894. return offset + ifile * external_fdr_size;
  3895. }
  3896. /* Set up the external symbols. These are supposed to be handled by
  3897. the backend. This routine just gets the right information and
  3898. calls a backend function to deal with it. */
  3899. static void
  3900. ecoff_setup_ext (void)
  3901. {
  3902. symbolS *sym;
  3903. for (sym = symbol_rootP; sym != (symbolS *) NULL; sym = symbol_next (sym))
  3904. {
  3905. if (symbol_get_obj (sym)->ecoff_symbol == NULL)
  3906. continue;
  3907. /* If this is a local symbol, then force the fields to zero. */
  3908. if (! S_IS_EXTERNAL (sym)
  3909. && ! S_IS_WEAK (sym)
  3910. && S_IS_DEFINED (sym))
  3911. {
  3912. struct localsym *lsym;
  3913. lsym = symbol_get_obj (sym)->ecoff_symbol;
  3914. lsym->ecoff_sym.asym.value = 0;
  3915. lsym->ecoff_sym.asym.st = (int) st_Nil;
  3916. lsym->ecoff_sym.asym.sc = (int) sc_Nil;
  3917. lsym->ecoff_sym.asym.index = indexNil;
  3918. }
  3919. obj_ecoff_set_ext (sym, &symbol_get_obj (sym)->ecoff_symbol->ecoff_sym);
  3920. }
  3921. }
  3922. /* Build the ECOFF debugging information. */
  3923. unsigned long
  3924. ecoff_build_debug (HDRR *hdr,
  3925. char **bufp,
  3926. const struct ecoff_debug_swap *backend)
  3927. {
  3928. const bfd_size_type external_pdr_size = backend->external_pdr_size;
  3929. tag_t *ptag;
  3930. tag_t *ptag_next;
  3931. efdr_t *fil_ptr;
  3932. int end_warning;
  3933. efdr_t *hold_file_ptr;
  3934. proc_t *hold_proc_ptr;
  3935. symbolS *sym;
  3936. char *buf;
  3937. char *bufend;
  3938. unsigned long offset;
  3939. /* Make sure we have a file. */
  3940. if (first_file == (efdr_t *) NULL)
  3941. add_file ((const char *) NULL, 0, 1);
  3942. /* Handle any top level tags. */
  3943. for (ptag = top_tag_head->first_tag;
  3944. ptag != (tag_t *) NULL;
  3945. ptag = ptag_next)
  3946. {
  3947. if (ptag->forward_ref != (forward_t *) NULL)
  3948. add_unknown_tag (ptag);
  3949. ptag_next = ptag->same_block;
  3950. ptag->hash_ptr->tag_ptr = ptag->same_name;
  3951. free_tag (ptag);
  3952. }
  3953. free_thead (top_tag_head);
  3954. /* Look through the symbols. Add debugging information for each
  3955. symbol that has not already received it. */
  3956. hold_file_ptr = cur_file_ptr;
  3957. hold_proc_ptr = cur_proc_ptr;
  3958. cur_proc_ptr = (proc_t *) NULL;
  3959. for (sym = symbol_rootP; sym != (symbolS *) NULL; sym = symbol_next (sym))
  3960. {
  3961. if (symbol_get_obj (sym)->ecoff_symbol != NULL
  3962. || symbol_get_obj (sym)->ecoff_file == (efdr_t *) NULL
  3963. || (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0)
  3964. continue;
  3965. cur_file_ptr = symbol_get_obj (sym)->ecoff_file;
  3966. add_ecoff_symbol ((const char *) NULL, st_Nil, sc_Nil, sym,
  3967. (bfd_vma) 0, S_GET_VALUE (sym), indexNil);
  3968. }
  3969. cur_proc_ptr = hold_proc_ptr;
  3970. cur_file_ptr = hold_file_ptr;
  3971. /* Output an ending symbol for all the files. We have to do this
  3972. here for the last file, so we may as well do it for all of the
  3973. files. */
  3974. end_warning = 0;
  3975. for (fil_ptr = first_file;
  3976. fil_ptr != (efdr_t *) NULL;
  3977. fil_ptr = fil_ptr->next_file)
  3978. {
  3979. cur_file_ptr = fil_ptr;
  3980. while (cur_file_ptr->cur_scope != (scope_t *) NULL
  3981. && cur_file_ptr->cur_scope->prev != (scope_t *) NULL)
  3982. {
  3983. cur_file_ptr->cur_scope = cur_file_ptr->cur_scope->prev;
  3984. if (! end_warning && ! cur_file_ptr->fake)
  3985. {
  3986. as_warn (_("missing .end or .bend at end of file"));
  3987. end_warning = 1;
  3988. }
  3989. }
  3990. if (cur_file_ptr->cur_scope != (scope_t *) NULL)
  3991. (void) add_ecoff_symbol ((const char *) NULL,
  3992. st_End, sc_Text,
  3993. (symbolS *) NULL,
  3994. (bfd_vma) 0,
  3995. (symint_t) 0,
  3996. (symint_t) 0);
  3997. }
  3998. /* Build the symbolic information. */
  3999. offset = 0;
  4000. buf = XNEWVEC (char, PAGE_SIZE);
  4001. bufend = buf + PAGE_SIZE;
  4002. /* Build the line number information. */
  4003. hdr->cbLineOffset = offset;
  4004. offset = ecoff_build_lineno (backend, &buf, &bufend, offset,
  4005. &hdr->ilineMax);
  4006. hdr->cbLine = offset - hdr->cbLineOffset;
  4007. /* We don't use dense numbers at all. */
  4008. hdr->idnMax = 0;
  4009. hdr->cbDnOffset = 0;
  4010. /* We can't build the PDR table until we have built the symbols,
  4011. because a PDR contains a symbol index. However, we set aside
  4012. space at this point. */
  4013. hdr->ipdMax = proc_cnt;
  4014. hdr->cbPdOffset = offset;
  4015. if ((bfd_size_type)(bufend - (buf + offset)) < proc_cnt * external_pdr_size)
  4016. (void) ecoff_add_bytes (&buf, &bufend, buf + offset,
  4017. proc_cnt * external_pdr_size);
  4018. offset += proc_cnt * external_pdr_size;
  4019. /* Build the local symbols. */
  4020. hdr->cbSymOffset = offset;
  4021. offset = ecoff_build_symbols (backend, &buf, &bufend, offset);
  4022. hdr->isymMax = (offset - hdr->cbSymOffset) / backend->external_sym_size;
  4023. /* Building the symbols initializes the symbol index in the PDR's.
  4024. Now we can swap out the PDR's. */
  4025. (void) ecoff_build_procs (backend, &buf, &bufend, hdr->cbPdOffset);
  4026. /* We don't use optimization symbols. */
  4027. hdr->ioptMax = 0;
  4028. hdr->cbOptOffset = 0;
  4029. /* Swap out the auxiliary type information. */
  4030. hdr->cbAuxOffset = offset;
  4031. offset = ecoff_build_aux (backend, &buf, &bufend, offset);
  4032. hdr->iauxMax = (offset - hdr->cbAuxOffset) / sizeof (union aux_ext);
  4033. /* Copy out the local strings. */
  4034. hdr->cbSsOffset = offset;
  4035. offset = ecoff_build_ss (backend, &buf, &bufend, offset);
  4036. hdr->issMax = offset - hdr->cbSsOffset;
  4037. /* We don't use relative file descriptors. */
  4038. hdr->crfd = 0;
  4039. hdr->cbRfdOffset = 0;
  4040. /* Swap out the file descriptors. */
  4041. hdr->cbFdOffset = offset;
  4042. offset = ecoff_build_fdr (backend, &buf, &bufend, offset);
  4043. hdr->ifdMax = (offset - hdr->cbFdOffset) / backend->external_fdr_size;
  4044. /* Set up the external symbols, which are handled by the BFD back
  4045. end. */
  4046. hdr->issExtMax = 0;
  4047. hdr->cbSsExtOffset = 0;
  4048. hdr->iextMax = 0;
  4049. hdr->cbExtOffset = 0;
  4050. ecoff_setup_ext ();
  4051. know ((offset & (backend->debug_align - 1)) == 0);
  4052. /* FIXME: This value should be determined from the .verstamp directive,
  4053. with reasonable defaults in config files. */
  4054. #ifdef TC_ALPHA
  4055. hdr->vstamp = 0x030b;
  4056. #else
  4057. hdr->vstamp = 0x020b;
  4058. #endif
  4059. *bufp = buf;
  4060. return offset;
  4061. }
  4062. /* Allocate a cluster of pages. */
  4063. #ifndef MALLOC_CHECK
  4064. static page_type *
  4065. allocate_cluster (unsigned long npages)
  4066. {
  4067. page_type *value = (page_type *) xmalloc (npages * PAGE_USIZE);
  4068. #ifdef ECOFF_DEBUG
  4069. if (debug > 3)
  4070. fprintf (stderr, "\talloc\tnpages = %d, value = 0x%.8x\n", npages, value);
  4071. #endif
  4072. memset (value, 0, npages * PAGE_USIZE);
  4073. return value;
  4074. }
  4075. static page_type *cluster_ptr = NULL;
  4076. static unsigned long pages_left = 0;
  4077. #endif /* MALLOC_CHECK */
  4078. /* Allocate one page (which is initialized to 0). */
  4079. static page_type *
  4080. allocate_page (void)
  4081. {
  4082. #ifndef MALLOC_CHECK
  4083. if (pages_left == 0)
  4084. {
  4085. pages_left = MAX_CLUSTER_PAGES;
  4086. cluster_ptr = allocate_cluster (pages_left);
  4087. }
  4088. pages_left--;
  4089. return cluster_ptr++;
  4090. #else /* MALLOC_CHECK */
  4091. page_type *ptr;
  4092. ptr = xmalloc (PAGE_USIZE);
  4093. memset (ptr, 0, PAGE_USIZE);
  4094. return ptr;
  4095. #endif /* MALLOC_CHECK */
  4096. }
  4097. /* Allocate scoping information. */
  4098. static scope_t *
  4099. allocate_scope (void)
  4100. {
  4101. scope_t *ptr;
  4102. static scope_t initial_scope;
  4103. #ifndef MALLOC_CHECK
  4104. ptr = alloc_counts[(int) alloc_type_scope].free_list.f_scope;
  4105. if (ptr != (scope_t *) NULL)
  4106. alloc_counts[(int) alloc_type_scope].free_list.f_scope = ptr->free;
  4107. else
  4108. {
  4109. int unallocated = alloc_counts[(int) alloc_type_scope].unallocated;
  4110. page_type *cur_page = alloc_counts[(int) alloc_type_scope].cur_page;
  4111. if (unallocated == 0)
  4112. {
  4113. unallocated = PAGE_SIZE / sizeof (scope_t);
  4114. alloc_counts[(int) alloc_type_scope].cur_page = cur_page = allocate_page ();
  4115. alloc_counts[(int) alloc_type_scope].total_pages++;
  4116. }
  4117. ptr = &cur_page->scope[--unallocated];
  4118. alloc_counts[(int) alloc_type_scope].unallocated = unallocated;
  4119. }
  4120. #else
  4121. ptr = XNEW (scope_t);
  4122. #endif
  4123. alloc_counts[(int) alloc_type_scope].total_alloc++;
  4124. *ptr = initial_scope;
  4125. return ptr;
  4126. }
  4127. /* Free scoping information. */
  4128. static void
  4129. free_scope (scope_t *ptr)
  4130. {
  4131. alloc_counts[(int) alloc_type_scope].total_free++;
  4132. #ifndef MALLOC_CHECK
  4133. ptr->free = alloc_counts[(int) alloc_type_scope].free_list.f_scope;
  4134. alloc_counts[(int) alloc_type_scope].free_list.f_scope = ptr;
  4135. #else
  4136. free ((void *) ptr);
  4137. #endif
  4138. }
  4139. /* Allocate links for pages in a virtual array. */
  4140. static vlinks_t *
  4141. allocate_vlinks (void)
  4142. {
  4143. vlinks_t *ptr;
  4144. static vlinks_t initial_vlinks;
  4145. #ifndef MALLOC_CHECK
  4146. int unallocated = alloc_counts[(int) alloc_type_vlinks].unallocated;
  4147. page_type *cur_page = alloc_counts[(int) alloc_type_vlinks].cur_page;
  4148. if (unallocated == 0)
  4149. {
  4150. unallocated = PAGE_SIZE / sizeof (vlinks_t);
  4151. alloc_counts[(int) alloc_type_vlinks].cur_page = cur_page = allocate_page ();
  4152. alloc_counts[(int) alloc_type_vlinks].total_pages++;
  4153. }
  4154. ptr = &cur_page->vlinks[--unallocated];
  4155. alloc_counts[(int) alloc_type_vlinks].unallocated = unallocated;
  4156. #else
  4157. ptr = XNEW (vlinks_t);
  4158. #endif
  4159. alloc_counts[(int) alloc_type_vlinks].total_alloc++;
  4160. *ptr = initial_vlinks;
  4161. return ptr;
  4162. }
  4163. /* Allocate string hash buckets. */
  4164. static shash_t *
  4165. allocate_shash (void)
  4166. {
  4167. shash_t *ptr;
  4168. static shash_t initial_shash;
  4169. #ifndef MALLOC_CHECK
  4170. int unallocated = alloc_counts[(int) alloc_type_shash].unallocated;
  4171. page_type *cur_page = alloc_counts[(int) alloc_type_shash].cur_page;
  4172. if (unallocated == 0)
  4173. {
  4174. unallocated = PAGE_SIZE / sizeof (shash_t);
  4175. alloc_counts[(int) alloc_type_shash].cur_page = cur_page = allocate_page ();
  4176. alloc_counts[(int) alloc_type_shash].total_pages++;
  4177. }
  4178. ptr = &cur_page->shash[--unallocated];
  4179. alloc_counts[(int) alloc_type_shash].unallocated = unallocated;
  4180. #else
  4181. ptr = XNEW (shash_t);
  4182. #endif
  4183. alloc_counts[(int) alloc_type_shash].total_alloc++;
  4184. *ptr = initial_shash;
  4185. return ptr;
  4186. }
  4187. /* Allocate type hash buckets. */
  4188. static thash_t *
  4189. allocate_thash (void)
  4190. {
  4191. thash_t *ptr;
  4192. static thash_t initial_thash;
  4193. #ifndef MALLOC_CHECK
  4194. int unallocated = alloc_counts[(int) alloc_type_thash].unallocated;
  4195. page_type *cur_page = alloc_counts[(int) alloc_type_thash].cur_page;
  4196. if (unallocated == 0)
  4197. {
  4198. unallocated = PAGE_SIZE / sizeof (thash_t);
  4199. alloc_counts[(int) alloc_type_thash].cur_page = cur_page = allocate_page ();
  4200. alloc_counts[(int) alloc_type_thash].total_pages++;
  4201. }
  4202. ptr = &cur_page->thash[--unallocated];
  4203. alloc_counts[(int) alloc_type_thash].unallocated = unallocated;
  4204. #else
  4205. ptr = XNEW (thash_t);
  4206. #endif
  4207. alloc_counts[(int) alloc_type_thash].total_alloc++;
  4208. *ptr = initial_thash;
  4209. return ptr;
  4210. }
  4211. /* Allocate structure, union, or enum tag information. */
  4212. static tag_t *
  4213. allocate_tag (void)
  4214. {
  4215. tag_t *ptr;
  4216. static tag_t initial_tag;
  4217. #ifndef MALLOC_CHECK
  4218. ptr = alloc_counts[(int) alloc_type_tag].free_list.f_tag;
  4219. if (ptr != (tag_t *) NULL)
  4220. alloc_counts[(int) alloc_type_tag].free_list.f_tag = ptr->free;
  4221. else
  4222. {
  4223. int unallocated = alloc_counts[(int) alloc_type_tag].unallocated;
  4224. page_type *cur_page = alloc_counts[(int) alloc_type_tag].cur_page;
  4225. if (unallocated == 0)
  4226. {
  4227. unallocated = PAGE_SIZE / sizeof (tag_t);
  4228. alloc_counts[(int) alloc_type_tag].cur_page = cur_page = allocate_page ();
  4229. alloc_counts[(int) alloc_type_tag].total_pages++;
  4230. }
  4231. ptr = &cur_page->tag[--unallocated];
  4232. alloc_counts[(int) alloc_type_tag].unallocated = unallocated;
  4233. }
  4234. #else
  4235. ptr = XNEW (tag_t);
  4236. #endif
  4237. alloc_counts[(int) alloc_type_tag].total_alloc++;
  4238. *ptr = initial_tag;
  4239. return ptr;
  4240. }
  4241. /* Free scoping information. */
  4242. static void
  4243. free_tag (tag_t *ptr)
  4244. {
  4245. alloc_counts[(int) alloc_type_tag].total_free++;
  4246. #ifndef MALLOC_CHECK
  4247. ptr->free = alloc_counts[(int) alloc_type_tag].free_list.f_tag;
  4248. alloc_counts[(int) alloc_type_tag].free_list.f_tag = ptr;
  4249. #else
  4250. free ((PTR_T) ptr);
  4251. #endif
  4252. }
  4253. /* Allocate forward reference to a yet unknown tag. */
  4254. static forward_t *
  4255. allocate_forward (void)
  4256. {
  4257. forward_t *ptr;
  4258. static forward_t initial_forward;
  4259. #ifndef MALLOC_CHECK
  4260. int unallocated = alloc_counts[(int) alloc_type_forward].unallocated;
  4261. page_type *cur_page = alloc_counts[(int) alloc_type_forward].cur_page;
  4262. if (unallocated == 0)
  4263. {
  4264. unallocated = PAGE_SIZE / sizeof (forward_t);
  4265. alloc_counts[(int) alloc_type_forward].cur_page = cur_page = allocate_page ();
  4266. alloc_counts[(int) alloc_type_forward].total_pages++;
  4267. }
  4268. ptr = &cur_page->forward[--unallocated];
  4269. alloc_counts[(int) alloc_type_forward].unallocated = unallocated;
  4270. #else
  4271. ptr = XNEW (forward_t);
  4272. #endif
  4273. alloc_counts[(int) alloc_type_forward].total_alloc++;
  4274. *ptr = initial_forward;
  4275. return ptr;
  4276. }
  4277. /* Allocate head of type hash list. */
  4278. static thead_t *
  4279. allocate_thead (void)
  4280. {
  4281. thead_t *ptr;
  4282. static thead_t initial_thead;
  4283. #ifndef MALLOC_CHECK
  4284. ptr = alloc_counts[(int) alloc_type_thead].free_list.f_thead;
  4285. if (ptr != (thead_t *) NULL)
  4286. alloc_counts[(int) alloc_type_thead].free_list.f_thead = ptr->free;
  4287. else
  4288. {
  4289. int unallocated = alloc_counts[(int) alloc_type_thead].unallocated;
  4290. page_type *cur_page = alloc_counts[(int) alloc_type_thead].cur_page;
  4291. if (unallocated == 0)
  4292. {
  4293. unallocated = PAGE_SIZE / sizeof (thead_t);
  4294. alloc_counts[(int) alloc_type_thead].cur_page = cur_page = allocate_page ();
  4295. alloc_counts[(int) alloc_type_thead].total_pages++;
  4296. }
  4297. ptr = &cur_page->thead[--unallocated];
  4298. alloc_counts[(int) alloc_type_thead].unallocated = unallocated;
  4299. }
  4300. #else
  4301. ptr = XNEW (thead_t);
  4302. #endif
  4303. alloc_counts[(int) alloc_type_thead].total_alloc++;
  4304. *ptr = initial_thead;
  4305. return ptr;
  4306. }
  4307. /* Free scoping information. */
  4308. static void
  4309. free_thead (thead_t *ptr)
  4310. {
  4311. alloc_counts[(int) alloc_type_thead].total_free++;
  4312. #ifndef MALLOC_CHECK
  4313. ptr->free = (thead_t *) alloc_counts[(int) alloc_type_thead].free_list.f_thead;
  4314. alloc_counts[(int) alloc_type_thead].free_list.f_thead = ptr;
  4315. #else
  4316. free ((PTR_T) ptr);
  4317. #endif
  4318. }
  4319. static lineno_list_t *
  4320. allocate_lineno_list (void)
  4321. {
  4322. lineno_list_t *ptr;
  4323. static lineno_list_t initial_lineno_list;
  4324. #ifndef MALLOC_CHECK
  4325. int unallocated = alloc_counts[(int) alloc_type_lineno].unallocated;
  4326. page_type *cur_page = alloc_counts[(int) alloc_type_lineno].cur_page;
  4327. if (unallocated == 0)
  4328. {
  4329. unallocated = PAGE_SIZE / sizeof (lineno_list_t);
  4330. alloc_counts[(int) alloc_type_lineno].cur_page = cur_page = allocate_page ();
  4331. alloc_counts[(int) alloc_type_lineno].total_pages++;
  4332. }
  4333. ptr = &cur_page->lineno[--unallocated];
  4334. alloc_counts[(int) alloc_type_lineno].unallocated = unallocated;
  4335. #else
  4336. ptr = XNEW (lineno_list_t);
  4337. #endif
  4338. alloc_counts[(int) alloc_type_lineno].total_alloc++;
  4339. *ptr = initial_lineno_list;
  4340. return ptr;
  4341. }
  4342. void
  4343. ecoff_set_gp_prolog_size (int sz)
  4344. {
  4345. if (cur_proc_ptr == 0)
  4346. return;
  4347. cur_proc_ptr->pdr.gp_prologue = sz;
  4348. if (cur_proc_ptr->pdr.gp_prologue != sz)
  4349. {
  4350. as_warn (_("GP prologue size exceeds field size, using 0 instead"));
  4351. cur_proc_ptr->pdr.gp_prologue = 0;
  4352. }
  4353. cur_proc_ptr->pdr.gp_used = 1;
  4354. }
  4355. int
  4356. ecoff_no_current_file (void)
  4357. {
  4358. return cur_file_ptr == (efdr_t *) NULL;
  4359. }
  4360. void
  4361. ecoff_generate_asm_lineno (void)
  4362. {
  4363. unsigned int lineno;
  4364. const char *filename;
  4365. lineno_list_t *list;
  4366. filename = as_where (&lineno);
  4367. if (current_stabs_filename == (char *) NULL
  4368. || filename_cmp (current_stabs_filename, filename))
  4369. add_file (filename, 0, 1);
  4370. list = allocate_lineno_list ();
  4371. list->next = (lineno_list_t *) NULL;
  4372. list->file = cur_file_ptr;
  4373. list->proc = cur_proc_ptr;
  4374. list->frag = frag_now;
  4375. list->paddr = frag_now_fix ();
  4376. list->lineno = lineno;
  4377. /* We don't want to merge files which have line numbers. */
  4378. cur_file_ptr->fdr.fMerge = 0;
  4379. /* A .loc directive will sometimes appear before a .ent directive,
  4380. which means that cur_proc_ptr will be NULL here. Arrange to
  4381. patch this up. */
  4382. if (cur_proc_ptr == (proc_t *) NULL)
  4383. {
  4384. lineno_list_t **pl;
  4385. pl = &noproc_lineno;
  4386. while (*pl != (lineno_list_t *) NULL)
  4387. pl = &(*pl)->next;
  4388. *pl = list;
  4389. }
  4390. else
  4391. {
  4392. last_lineno = list;
  4393. *last_lineno_ptr = list;
  4394. last_lineno_ptr = &list->next;
  4395. }
  4396. }
  4397. #else
  4398. void
  4399. ecoff_generate_asm_lineno (void)
  4400. {
  4401. }
  4402. #endif /* ECOFF_DEBUGGING */