gcc.c 263 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463
  1. /* Compiler driver program that can handle many languages.
  2. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. /* This program is the user interface to the C compiler and possibly to
  16. other compilers. It is used because compilation is a complicated procedure
  17. which involves running several programs and passing temporary files between
  18. them, forwarding the users switches to those programs selectively,
  19. and deleting the temporary files at the end.
  20. CC recognizes how to compile each input file by suffixes in the file names.
  21. Once it knows which kind of compilation to perform, the procedure for
  22. compilation is specified by a string called a "spec". */
  23. #include "config.h"
  24. #include "system.h"
  25. #include "coretypes.h"
  26. #include "multilib.h" /* before tm.h */
  27. #include "tm.h"
  28. #include "xregex.h"
  29. #include "obstack.h"
  30. #include "intl.h"
  31. #include "prefix.h"
  32. #include "gcc.h"
  33. #include "diagnostic.h"
  34. #include "flags.h"
  35. #include "opts.h"
  36. #include "params.h"
  37. #include "vec.h"
  38. #include "filenames.h"
  39. /* By default there is no special suffix for target executables. */
  40. /* FIXME: when autoconf is fixed, remove the host check - dj */
  41. #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX)
  42. #define HAVE_TARGET_EXECUTABLE_SUFFIX
  43. #endif
  44. /* By default there is no special suffix for host executables. */
  45. #ifdef HOST_EXECUTABLE_SUFFIX
  46. #define HAVE_HOST_EXECUTABLE_SUFFIX
  47. #else
  48. #define HOST_EXECUTABLE_SUFFIX ""
  49. #endif
  50. /* By default, the suffix for target object files is ".o". */
  51. #ifdef TARGET_OBJECT_SUFFIX
  52. #define HAVE_TARGET_OBJECT_SUFFIX
  53. #else
  54. #define TARGET_OBJECT_SUFFIX ".o"
  55. #endif
  56. static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
  57. /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */
  58. #ifndef LIBRARY_PATH_ENV
  59. #define LIBRARY_PATH_ENV "LIBRARY_PATH"
  60. #endif
  61. /* If a stage of compilation returns an exit status >= 1,
  62. compilation of that file ceases. */
  63. #define MIN_FATAL_STATUS 1
  64. /* Flag set by cppspec.c to 1. */
  65. int is_cpp_driver;
  66. /* Flag set to nonzero if an @file argument has been supplied to gcc. */
  67. static bool at_file_supplied;
  68. /* Definition of string containing the arguments given to configure. */
  69. #include "configargs.h"
  70. /* Flag saying to print the command line options understood by gcc and its
  71. sub-processes. */
  72. static int print_help_list;
  73. /* Flag saying to print the version of gcc and its sub-processes. */
  74. static int print_version;
  75. /* Flag indicating whether we should ONLY print the command and
  76. arguments (like verbose_flag) without executing the command.
  77. Displayed arguments are quoted so that the generated command
  78. line is suitable for execution. This is intended for use in
  79. shell scripts to capture the driver-generated command line. */
  80. static int verbose_only_flag;
  81. /* Flag indicating how to print command line options of sub-processes. */
  82. static int print_subprocess_help;
  83. /* Linker suffix passed to -fuse-ld=... */
  84. static const char *use_ld;
  85. /* Whether we should report subprocess execution times to a file. */
  86. FILE *report_times_to_file = NULL;
  87. /* Nonzero means place this string before uses of /, so that include
  88. and library files can be found in an alternate location. */
  89. #ifdef TARGET_SYSTEM_ROOT
  90. static const char *target_system_root = TARGET_SYSTEM_ROOT;
  91. #else
  92. static const char *target_system_root = 0;
  93. #endif
  94. /* Nonzero means pass the updated target_system_root to the compiler. */
  95. static int target_system_root_changed;
  96. /* Nonzero means append this string to target_system_root. */
  97. static const char *target_sysroot_suffix = 0;
  98. /* Nonzero means append this string to target_system_root for headers. */
  99. static const char *target_sysroot_hdrs_suffix = 0;
  100. /* Nonzero means write "temp" files in source directory
  101. and use the source file's name in them, and don't delete them. */
  102. static enum save_temps {
  103. SAVE_TEMPS_NONE, /* no -save-temps */
  104. SAVE_TEMPS_CWD, /* -save-temps in current directory */
  105. SAVE_TEMPS_OBJ /* -save-temps in object directory */
  106. } save_temps_flag;
  107. /* Output file to use to get the object directory for -save-temps=obj */
  108. static char *save_temps_prefix = 0;
  109. static size_t save_temps_length = 0;
  110. /* The compiler version. */
  111. static const char *compiler_version;
  112. /* The target version. */
  113. static const char *const spec_version = DEFAULT_TARGET_VERSION;
  114. /* The target machine. */
  115. static const char *spec_machine = DEFAULT_TARGET_MACHINE;
  116. static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE;
  117. /* List of offload targets. */
  118. static char *offload_targets = NULL;
  119. /* Nonzero if cross-compiling.
  120. When -b is used, the value comes from the `specs' file. */
  121. #ifdef CROSS_DIRECTORY_STRUCTURE
  122. static const char *cross_compile = "1";
  123. #else
  124. static const char *cross_compile = "0";
  125. #endif
  126. /* Greatest exit code of sub-processes that has been encountered up to
  127. now. */
  128. static int greatest_status = 1;
  129. /* This is the obstack which we use to allocate many strings. */
  130. static struct obstack obstack;
  131. /* This is the obstack to build an environment variable to pass to
  132. collect2 that describes all of the relevant switches of what to
  133. pass the compiler in building the list of pointers to constructors
  134. and destructors. */
  135. static struct obstack collect_obstack;
  136. /* Forward declaration for prototypes. */
  137. struct path_prefix;
  138. struct prefix_list;
  139. static void init_spec (void);
  140. static void store_arg (const char *, int, int);
  141. static void insert_wrapper (const char *);
  142. static char *load_specs (const char *);
  143. static void read_specs (const char *, bool, bool);
  144. static void set_spec (const char *, const char *, bool);
  145. static struct compiler *lookup_compiler (const char *, size_t, const char *);
  146. static char *build_search_list (const struct path_prefix *, const char *,
  147. bool, bool);
  148. static void xputenv (const char *);
  149. static void putenv_from_prefixes (const struct path_prefix *, const char *,
  150. bool);
  151. static int access_check (const char *, int);
  152. static char *find_a_file (const struct path_prefix *, const char *, int, bool);
  153. static void add_prefix (struct path_prefix *, const char *, const char *,
  154. int, int, int);
  155. static void add_sysrooted_prefix (struct path_prefix *, const char *,
  156. const char *, int, int, int);
  157. static char *skip_whitespace (char *);
  158. static void delete_if_ordinary (const char *);
  159. static void delete_temp_files (void);
  160. static void delete_failure_queue (void);
  161. static void clear_failure_queue (void);
  162. static int check_live_switch (int, int);
  163. static const char *handle_braces (const char *);
  164. static inline bool input_suffix_matches (const char *, const char *);
  165. static inline bool switch_matches (const char *, const char *, int);
  166. static inline void mark_matching_switches (const char *, const char *, int);
  167. static inline void process_marked_switches (void);
  168. static const char *process_brace_body (const char *, const char *, const char *, int, int);
  169. static const struct spec_function *lookup_spec_function (const char *);
  170. static const char *eval_spec_function (const char *, const char *);
  171. static const char *handle_spec_function (const char *, bool *);
  172. static char *save_string (const char *, int);
  173. static void set_collect_gcc_options (void);
  174. static int do_spec_1 (const char *, int, const char *);
  175. static int do_spec_2 (const char *);
  176. static void do_option_spec (const char *, const char *);
  177. static void do_self_spec (const char *);
  178. static const char *find_file (const char *);
  179. static int is_directory (const char *, bool);
  180. static const char *validate_switches (const char *, bool);
  181. static void validate_all_switches (void);
  182. static inline void validate_switches_from_spec (const char *, bool);
  183. static void give_switch (int, int);
  184. static int used_arg (const char *, int);
  185. static int default_arg (const char *, int);
  186. static void set_multilib_dir (void);
  187. static void print_multilib_info (void);
  188. static void perror_with_name (const char *);
  189. static void display_help (void);
  190. static void add_preprocessor_option (const char *, int);
  191. static void add_assembler_option (const char *, int);
  192. static void add_linker_option (const char *, int);
  193. static void process_command (unsigned int, struct cl_decoded_option *);
  194. static int execute (void);
  195. static void alloc_args (void);
  196. static void clear_args (void);
  197. static void fatal_signal (int);
  198. #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
  199. static void init_gcc_specs (struct obstack *, const char *, const char *,
  200. const char *);
  201. #endif
  202. #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
  203. static const char *convert_filename (const char *, int, int);
  204. #endif
  205. static void try_generate_repro (const char **argv);
  206. static const char *getenv_spec_function (int, const char **);
  207. static const char *if_exists_spec_function (int, const char **);
  208. static const char *if_exists_else_spec_function (int, const char **);
  209. static const char *sanitize_spec_function (int, const char **);
  210. static const char *replace_outfile_spec_function (int, const char **);
  211. static const char *remove_outfile_spec_function (int, const char **);
  212. static const char *version_compare_spec_function (int, const char **);
  213. static const char *include_spec_function (int, const char **);
  214. static const char *find_file_spec_function (int, const char **);
  215. static const char *find_plugindir_spec_function (int, const char **);
  216. static const char *print_asm_header_spec_function (int, const char **);
  217. static const char *compare_debug_dump_opt_spec_function (int, const char **);
  218. static const char *compare_debug_self_opt_spec_function (int, const char **);
  219. static const char *compare_debug_auxbase_opt_spec_function (int, const char **);
  220. static const char *pass_through_libs_spec_func (int, const char **);
  221. static const char *replace_extension_spec_func (int, const char **);
  222. static char *convert_white_space (char *);
  223. /* The Specs Language
  224. Specs are strings containing lines, each of which (if not blank)
  225. is made up of a program name, and arguments separated by spaces.
  226. The program name must be exact and start from root, since no path
  227. is searched and it is unreliable to depend on the current working directory.
  228. Redirection of input or output is not supported; the subprograms must
  229. accept filenames saying what files to read and write.
  230. In addition, the specs can contain %-sequences to substitute variable text
  231. or for conditional text. Here is a table of all defined %-sequences.
  232. Note that spaces are not generated automatically around the results of
  233. expanding these sequences; therefore, you can concatenate them together
  234. or with constant text in a single argument.
  235. %% substitute one % into the program name or argument.
  236. %i substitute the name of the input file being processed.
  237. %b substitute the basename of the input file being processed.
  238. This is the substring up to (and not including) the last period
  239. and not including the directory unless -save-temps was specified
  240. to put temporaries in a different location.
  241. %B same as %b, but include the file suffix (text after the last period).
  242. %gSUFFIX
  243. substitute a file name that has suffix SUFFIX and is chosen
  244. once per compilation, and mark the argument a la %d. To reduce
  245. exposure to denial-of-service attacks, the file name is now
  246. chosen in a way that is hard to predict even when previously
  247. chosen file names are known. For example, `%g.s ... %g.o ... %g.s'
  248. might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches
  249. the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it
  250. had been pre-processed. Previously, %g was simply substituted
  251. with a file name chosen once per compilation, without regard
  252. to any appended suffix (which was therefore treated just like
  253. ordinary text), making such attacks more likely to succeed.
  254. %|SUFFIX
  255. like %g, but if -pipe is in effect, expands simply to "-".
  256. %mSUFFIX
  257. like %g, but if -pipe is in effect, expands to nothing. (We have both
  258. %| and %m to accommodate differences between system assemblers; see
  259. the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.)
  260. %uSUFFIX
  261. like %g, but generates a new temporary file name even if %uSUFFIX
  262. was already seen.
  263. %USUFFIX
  264. substitutes the last file name generated with %uSUFFIX, generating a
  265. new one if there is no such last file name. In the absence of any
  266. %uSUFFIX, this is just like %gSUFFIX, except they don't share
  267. the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s'
  268. would involve the generation of two distinct file names, one
  269. for each `%g.s' and another for each `%U.s'. Previously, %U was
  270. simply substituted with a file name chosen for the previous %u,
  271. without regard to any appended suffix.
  272. %jSUFFIX
  273. substitutes the name of the HOST_BIT_BUCKET, if any, and if it is
  274. writable, and if save-temps is off; otherwise, substitute the name
  275. of a temporary file, just like %u. This temporary file is not
  276. meant for communication between processes, but rather as a junk
  277. disposal mechanism.
  278. %.SUFFIX
  279. substitutes .SUFFIX for the suffixes of a matched switch's args when
  280. it is subsequently output with %*. SUFFIX is terminated by the next
  281. space or %.
  282. %d marks the argument containing or following the %d as a
  283. temporary file name, so that that file will be deleted if GCC exits
  284. successfully. Unlike %g, this contributes no text to the argument.
  285. %w marks the argument containing or following the %w as the
  286. "output file" of this compilation. This puts the argument
  287. into the sequence of arguments that %o will substitute later.
  288. %V indicates that this compilation produces no "output file".
  289. %W{...}
  290. like %{...} but mark last argument supplied within
  291. as a file to be deleted on failure.
  292. %o substitutes the names of all the output files, with spaces
  293. automatically placed around them. You should write spaces
  294. around the %o as well or the results are undefined.
  295. %o is for use in the specs for running the linker.
  296. Input files whose names have no recognized suffix are not compiled
  297. at all, but they are included among the output files, so they will
  298. be linked.
  299. %O substitutes the suffix for object files. Note that this is
  300. handled specially when it immediately follows %g, %u, or %U
  301. (with or without a suffix argument) because of the need for
  302. those to form complete file names. The handling is such that
  303. %O is treated exactly as if it had already been substituted,
  304. except that %g, %u, and %U do not currently support additional
  305. SUFFIX characters following %O as they would following, for
  306. example, `.o'.
  307. %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot
  308. (made from TARGET_SYSTEM_ROOT), -isystem (made from COMPILER_PATH
  309. and -B options) and -imultilib as necessary.
  310. %s current argument is the name of a library or startup file of some sort.
  311. Search for that file in a standard list of directories
  312. and substitute the full name found.
  313. %eSTR Print STR as an error message. STR is terminated by a newline.
  314. Use this when inconsistent options are detected.
  315. %nSTR Print STR as a notice. STR is terminated by a newline.
  316. %x{OPTION} Accumulate an option for %X.
  317. %X Output the accumulated linker options specified by compilations.
  318. %Y Output the accumulated assembler options specified by compilations.
  319. %Z Output the accumulated preprocessor options specified by compilations.
  320. %a process ASM_SPEC as a spec.
  321. This allows config.h to specify part of the spec for running as.
  322. %A process ASM_FINAL_SPEC as a spec. A capital A is actually
  323. used here. This can be used to run a post-processor after the
  324. assembler has done its job.
  325. %D Dump out a -L option for each directory in startfile_prefixes.
  326. If multilib_dir is set, extra entries are generated with it affixed.
  327. %l process LINK_SPEC as a spec.
  328. %L process LIB_SPEC as a spec.
  329. %M Output multilib_os_dir.
  330. %G process LIBGCC_SPEC as a spec.
  331. %R Output the concatenation of target_system_root and
  332. target_sysroot_suffix.
  333. %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
  334. %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
  335. %C process CPP_SPEC as a spec.
  336. %1 process CC1_SPEC as a spec.
  337. %2 process CC1PLUS_SPEC as a spec.
  338. %* substitute the variable part of a matched option. (See below.)
  339. Note that each comma in the substituted string is replaced by
  340. a single space. A space is appended after the last substition
  341. unless there is more text in current sequence.
  342. %<S remove all occurrences of -S from the command line.
  343. Note - this command is position dependent. % commands in the
  344. spec string before this one will see -S, % commands in the
  345. spec string after this one will not.
  346. %>S Similar to "%<S", but keep it in the GCC command line.
  347. %<S* remove all occurrences of all switches beginning with -S from the
  348. command line.
  349. %:function(args)
  350. Call the named function FUNCTION, passing it ARGS. ARGS is
  351. first processed as a nested spec string, then split into an
  352. argument vector in the usual fashion. The function returns
  353. a string which is processed as if it had appeared literally
  354. as part of the current spec.
  355. %{S} substitutes the -S switch, if that switch was given to GCC.
  356. If that switch was not specified, this substitutes nothing.
  357. Here S is a metasyntactic variable.
  358. %{S*} substitutes all the switches specified to GCC whose names start
  359. with -S. This is used for -o, -I, etc; switches that take
  360. arguments. GCC considers `-o foo' as being one switch whose
  361. name starts with `o'. %{o*} would substitute this text,
  362. including the space; thus, two arguments would be generated.
  363. %{S*&T*} likewise, but preserve order of S and T options (the order
  364. of S and T in the spec is not significant). Can be any number
  365. of ampersand-separated variables; for each the wild card is
  366. optional. Useful for CPP as %{D*&U*&A*}.
  367. %{S:X} substitutes X, if the -S switch was given to GCC.
  368. %{!S:X} substitutes X, if the -S switch was NOT given to GCC.
  369. %{S*:X} substitutes X if one or more switches whose names start
  370. with -S was given to GCC. Normally X is substituted only
  371. once, no matter how many such switches appeared. However,
  372. if %* appears somewhere in X, then X will be substituted
  373. once for each matching switch, with the %* replaced by the
  374. part of that switch that matched the '*'. A space will be
  375. appended after the last substition unless there is more
  376. text in current sequence.
  377. %{.S:X} substitutes X, if processing a file with suffix S.
  378. %{!.S:X} substitutes X, if NOT processing a file with suffix S.
  379. %{,S:X} substitutes X, if processing a file which will use spec S.
  380. %{!,S:X} substitutes X, if NOT processing a file which will use spec S.
  381. %{S|T:X} substitutes X if either -S or -T was given to GCC. This may be
  382. combined with '!', '.', ',', and '*' as above binding stronger
  383. than the OR.
  384. If %* appears in X, all of the alternatives must be starred, and
  385. only the first matching alternative is substituted.
  386. %{%:function(args):X}
  387. Call function named FUNCTION with args ARGS. If the function
  388. returns non-NULL, then X is substituted, if it returns
  389. NULL, it isn't substituted.
  390. %{S:X; if S was given to GCC, substitutes X;
  391. T:Y; else if T was given to GCC, substitutes Y;
  392. :D} else substitutes D. There can be as many clauses as you need.
  393. This may be combined with '.', '!', ',', '|', and '*' as above.
  394. %(Spec) processes a specification defined in a specs file as *Spec:
  395. The conditional text X in a %{S:X} or similar construct may contain
  396. other nested % constructs or spaces, or even newlines. They are
  397. processed as usual, as described above. Trailing white space in X is
  398. ignored. White space may also appear anywhere on the left side of the
  399. colon in these constructs, except between . or * and the corresponding
  400. word.
  401. The -O, -f, -g, -m, and -W switches are handled specifically in these
  402. constructs. If another value of -O or the negated form of a -f, -m, or
  403. -W switch is found later in the command line, the earlier switch
  404. value is ignored, except with {S*} where S is just one letter; this
  405. passes all matching options.
  406. The character | at the beginning of the predicate text is used to indicate
  407. that a command should be piped to the following command, but only if -pipe
  408. is specified.
  409. Note that it is built into GCC which switches take arguments and which
  410. do not. You might think it would be useful to generalize this to
  411. allow each compiler's spec to say which switches take arguments. But
  412. this cannot be done in a consistent fashion. GCC cannot even decide
  413. which input files have been specified without knowing which switches
  414. take arguments, and it must know which input files to compile in order
  415. to tell which compilers to run.
  416. GCC also knows implicitly that arguments starting in `-l' are to be
  417. treated as compiler output files, and passed to the linker in their
  418. proper position among the other output files. */
  419. /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */
  420. /* config.h can define ASM_SPEC to provide extra args to the assembler
  421. or extra switch-translations. */
  422. #ifndef ASM_SPEC
  423. #define ASM_SPEC ""
  424. #endif
  425. /* config.h can define ASM_FINAL_SPEC to run a post processor after
  426. the assembler has run. */
  427. #ifndef ASM_FINAL_SPEC
  428. #define ASM_FINAL_SPEC \
  429. "%{gsplit-dwarf: \n\
  430. objcopy --extract-dwo \
  431. %{c:%{o*:%*}%{!o*:%b%O}}%{!c:%U%O} \
  432. %{c:%{o*:%:replace-extension(%{o*:%*} .dwo)}%{!o*:%b.dwo}}%{!c:%b.dwo} \n\
  433. objcopy --strip-dwo \
  434. %{c:%{o*:%*}%{!o*:%b%O}}%{!c:%U%O} \
  435. }"
  436. #endif
  437. /* config.h can define CPP_SPEC to provide extra args to the C preprocessor
  438. or extra switch-translations. */
  439. #ifndef CPP_SPEC
  440. #define CPP_SPEC ""
  441. #endif
  442. /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus
  443. or extra switch-translations. */
  444. #ifndef CC1_SPEC
  445. #define CC1_SPEC ""
  446. #endif
  447. /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus
  448. or extra switch-translations. */
  449. #ifndef CC1PLUS_SPEC
  450. #define CC1PLUS_SPEC ""
  451. #endif
  452. /* config.h can define LINK_SPEC to provide extra args to the linker
  453. or extra switch-translations. */
  454. #ifndef LINK_SPEC
  455. #define LINK_SPEC ""
  456. #endif
  457. /* config.h can define LIB_SPEC to override the default libraries. */
  458. #ifndef LIB_SPEC
  459. #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"
  460. #endif
  461. /* When using -fsplit-stack we need to wrap pthread_create, in order
  462. to initialize the stack guard. We always use wrapping, rather than
  463. shared library ordering, and we keep the wrapper function in
  464. libgcc. This is not yet a real spec, though it could become one;
  465. it is currently just stuffed into LINK_SPEC. FIXME: This wrapping
  466. only works with GNU ld and gold. */
  467. #define STACK_SPLIT_SPEC " %{fsplit-stack: --wrap=pthread_create}"
  468. #ifndef LIBASAN_SPEC
  469. #define STATIC_LIBASAN_LIBS \
  470. " %{static-libasan:%:include(libsanitizer.spec)%(link_libasan)}"
  471. #ifdef LIBASAN_EARLY_SPEC
  472. #define LIBASAN_SPEC STATIC_LIBASAN_LIBS
  473. #elif defined(HAVE_LD_STATIC_DYNAMIC)
  474. #define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \
  475. "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \
  476. STATIC_LIBASAN_LIBS
  477. #else
  478. #define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS
  479. #endif
  480. #endif
  481. #ifndef LIBASAN_EARLY_SPEC
  482. #define LIBASAN_EARLY_SPEC ""
  483. #endif
  484. #ifndef LIBTSAN_SPEC
  485. #define STATIC_LIBTSAN_LIBS \
  486. " %{static-libtsan:%:include(libsanitizer.spec)%(link_libtsan)}"
  487. #ifdef LIBTSAN_EARLY_SPEC
  488. #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS
  489. #elif defined(HAVE_LD_STATIC_DYNAMIC)
  490. #define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \
  491. "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \
  492. STATIC_LIBTSAN_LIBS
  493. #else
  494. #define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS
  495. #endif
  496. #endif
  497. #ifndef LIBTSAN_EARLY_SPEC
  498. #define LIBTSAN_EARLY_SPEC ""
  499. #endif
  500. #ifndef LIBLSAN_SPEC
  501. #define STATIC_LIBLSAN_LIBS \
  502. " %{static-liblsan:%:include(libsanitizer.spec)%(link_liblsan)}"
  503. #ifdef LIBLSAN_EARLY_SPEC
  504. #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS
  505. #elif defined(HAVE_LD_STATIC_DYNAMIC)
  506. #define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \
  507. "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \
  508. STATIC_LIBLSAN_LIBS
  509. #else
  510. #define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS
  511. #endif
  512. #endif
  513. #ifndef LIBLSAN_EARLY_SPEC
  514. #define LIBLSAN_EARLY_SPEC ""
  515. #endif
  516. #ifndef LIBUBSAN_SPEC
  517. #define STATIC_LIBUBSAN_LIBS \
  518. " %{static-libubsan:%:include(libsanitizer.spec)%(link_libubsan)}"
  519. #ifdef HAVE_LD_STATIC_DYNAMIC
  520. #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \
  521. "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \
  522. STATIC_LIBUBSAN_LIBS
  523. #else
  524. #define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS
  525. #endif
  526. #endif
  527. /* Linker options for compressed debug sections. */
  528. #if HAVE_LD_COMPRESS_DEBUG == 0
  529. /* No linker support. */
  530. #define LINK_COMPRESS_DEBUG_SPEC \
  531. " %{gz*:%e-gz is not supported in this configuration} "
  532. #elif HAVE_LD_COMPRESS_DEBUG == 1
  533. /* GNU style on input, GNU ld options. Reject, not useful. */
  534. #define LINK_COMPRESS_DEBUG_SPEC \
  535. " %{gz*:%e-gz is not supported in this configuration} "
  536. #elif HAVE_LD_COMPRESS_DEBUG == 2
  537. /* GNU style, GNU gold options. */
  538. #define LINK_COMPRESS_DEBUG_SPEC \
  539. " %{gz|gz=zlib-gnu:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \
  540. " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \
  541. " %{gz=zlib:%e-gz=zlib is not supported in this configuration} "
  542. #elif HAVE_LD_COMPRESS_DEBUG == 3
  543. /* ELF gABI style. */
  544. #define LINK_COMPRESS_DEBUG_SPEC \
  545. " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \
  546. " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \
  547. " %{gz=zlib-gnu:" LD_COMPRESS_DEBUG_OPTION "=zlib-gnu} "
  548. #else
  549. #error Unknown value for HAVE_LD_COMPRESS_DEBUG.
  550. #endif
  551. /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is
  552. included. */
  553. #ifndef LIBGCC_SPEC
  554. #if defined(REAL_LIBGCC_SPEC)
  555. #define LIBGCC_SPEC REAL_LIBGCC_SPEC
  556. #elif defined(LINK_LIBGCC_SPECIAL_1)
  557. /* Have gcc do the search for libgcc.a. */
  558. #define LIBGCC_SPEC "libgcc.a%s"
  559. #else
  560. #define LIBGCC_SPEC "-lgcc"
  561. #endif
  562. #endif
  563. /* config.h can define STARTFILE_SPEC to override the default crt0 files. */
  564. #ifndef STARTFILE_SPEC
  565. #define STARTFILE_SPEC \
  566. "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"
  567. #endif
  568. /* config.h can define ENDFILE_SPEC to override the default crtn files. */
  569. #ifndef ENDFILE_SPEC
  570. #define ENDFILE_SPEC ""
  571. #endif
  572. #ifndef LINKER_NAME
  573. #define LINKER_NAME "collect2"
  574. #endif
  575. #ifdef HAVE_AS_DEBUG_PREFIX_MAP
  576. #define ASM_MAP " %{fdebug-prefix-map=*:--debug-prefix-map %*}"
  577. #else
  578. #define ASM_MAP ""
  579. #endif
  580. /* Assembler options for compressed debug sections. */
  581. #if HAVE_LD_COMPRESS_DEBUG < 2
  582. /* Reject if the linker cannot write compressed debug sections. */
  583. #define ASM_COMPRESS_DEBUG_SPEC \
  584. " %{gz*:%e-gz is not supported in this configuration} "
  585. #else /* HAVE_LD_COMPRESS_DEBUG >= 2 */
  586. #if HAVE_AS_COMPRESS_DEBUG == 0
  587. /* No assembler support. Ignore silently. */
  588. #define ASM_COMPRESS_DEBUG_SPEC \
  589. " %{gz*:} "
  590. #elif HAVE_AS_COMPRESS_DEBUG == 1
  591. /* GNU style, GNU as options. */
  592. #define ASM_COMPRESS_DEBUG_SPEC \
  593. " %{gz|gz=zlib-gnu:" AS_COMPRESS_DEBUG_OPTION "}" \
  594. " %{gz=none:" AS_NO_COMPRESS_DEBUG_OPTION "}" \
  595. " %{gz=zlib:%e-gz=zlib is not supported in this configuration} "
  596. #elif HAVE_AS_COMPRESS_DEBUG == 2
  597. /* ELF gABI style. */
  598. #define ASM_COMPRESS_DEBUG_SPEC \
  599. " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \
  600. " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \
  601. " %{gz=zlib-gnu:" AS_COMPRESS_DEBUG_OPTION "=zlib-gnu} "
  602. #else
  603. #error Unknown value for HAVE_AS_COMPRESS_DEBUG.
  604. #endif
  605. #endif /* HAVE_LD_COMPRESS_DEBUG >= 2 */
  606. /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g'
  607. to the assembler. */
  608. #ifndef ASM_DEBUG_SPEC
  609. # if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \
  610. && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
  611. # define ASM_DEBUG_SPEC \
  612. (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \
  613. ? "%{!g0:%{gdwarf*:--gdwarf2}%{!gdwarf*:%{g*:--gstabs}}}" ASM_MAP \
  614. : "%{!g0:%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}}" ASM_MAP)
  615. # else
  616. # if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)
  617. # define ASM_DEBUG_SPEC "%{g*:%{!g0:--gstabs}}" ASM_MAP
  618. # endif
  619. # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG)
  620. # define ASM_DEBUG_SPEC "%{g*:%{!g0:--gdwarf2}}" ASM_MAP
  621. # endif
  622. # endif
  623. #endif
  624. #ifndef ASM_DEBUG_SPEC
  625. # define ASM_DEBUG_SPEC ""
  626. #endif
  627. /* Here is the spec for running the linker, after compiling all files. */
  628. /* This is overridable by the target in case they need to specify the
  629. -lgcc and -lc order specially, yet not require them to override all
  630. of LINK_COMMAND_SPEC. */
  631. #ifndef LINK_GCC_C_SEQUENCE_SPEC
  632. #define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G"
  633. #endif
  634. #ifndef LINK_SSP_SPEC
  635. #ifdef TARGET_LIBC_PROVIDES_SSP
  636. #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
  637. "|fstack-protector-strong|fstack-protector-explicit:}"
  638. #else
  639. #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
  640. "|fstack-protector-strong|fstack-protector-explicit" \
  641. ":-lssp_nonshared -lssp}"
  642. #endif
  643. #endif
  644. #ifndef LINK_PIE_SPEC
  645. #ifdef HAVE_LD_PIE
  646. #define LINK_PIE_SPEC "%{pie:-pie} "
  647. #else
  648. #define LINK_PIE_SPEC "%{pie:} "
  649. #endif
  650. #endif
  651. #ifndef LINK_BUILDID_SPEC
  652. # if defined(HAVE_LD_BUILDID) && defined(ENABLE_LD_BUILDID)
  653. # define LINK_BUILDID_SPEC "%{!r:--build-id} "
  654. # endif
  655. #endif
  656. /* Conditional to test whether the LTO plugin is used or not.
  657. FIXME: For slim LTO we will need to enable plugin unconditionally. This
  658. still cause problems with PLUGIN_LD != LD and when plugin is built but
  659. not useable. For GCC 4.6 we don't support slim LTO and thus we can enable
  660. plugin only when LTO is enabled. We still honor explicit
  661. -fuse-linker-plugin if the linker used understands -plugin. */
  662. /* The linker has some plugin support. */
  663. #if HAVE_LTO_PLUGIN > 0
  664. /* The linker used has full plugin support, use LTO plugin by default. */
  665. #if HAVE_LTO_PLUGIN == 2
  666. #define PLUGIN_COND "!fno-use-linker-plugin:%{!fno-lto"
  667. #define PLUGIN_COND_CLOSE "}"
  668. #else
  669. /* The linker used has limited plugin support, use LTO plugin with explicit
  670. -fuse-linker-plugin. */
  671. #define PLUGIN_COND "fuse-linker-plugin"
  672. #define PLUGIN_COND_CLOSE ""
  673. #endif
  674. #define LINK_PLUGIN_SPEC \
  675. "%{"PLUGIN_COND": \
  676. -plugin %(linker_plugin_file) \
  677. -plugin-opt=%(lto_wrapper) \
  678. -plugin-opt=-fresolution=%u.res \
  679. %{!nostdlib:%{!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))}} \
  680. }"PLUGIN_COND_CLOSE
  681. #else
  682. /* The linker used doesn't support -plugin, reject -fuse-linker-plugin. */
  683. #define LINK_PLUGIN_SPEC "%{fuse-linker-plugin:\
  684. %e-fuse-linker-plugin is not supported in this configuration}"
  685. #endif
  686. /* Linker command line options for -fsanitize= early on the command line. */
  687. #ifndef SANITIZER_EARLY_SPEC
  688. #define SANITIZER_EARLY_SPEC "\
  689. %{!nostdlib:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \
  690. %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "} \
  691. %{%:sanitize(leak):" LIBLSAN_EARLY_SPEC "}}}"
  692. #endif
  693. /* Linker command line options for -fsanitize= late on the command line. */
  694. #ifndef SANITIZER_SPEC
  695. #define SANITIZER_SPEC "\
  696. %{!nostdlib:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_SPEC "\
  697. %{static:%ecannot specify -static with -fsanitize=address}}\
  698. %{%:sanitize(thread):" LIBTSAN_SPEC "\
  699. %{static:%ecannot specify -static with -fsanitize=thread}}\
  700. %{%:sanitize(undefined):" LIBUBSAN_SPEC "}\
  701. %{%:sanitize(leak):" LIBLSAN_SPEC "}}}"
  702. #endif
  703. /* This is the spec to use, once the code for creating the vtable
  704. verification runtime library, libvtv.so, has been created. Currently
  705. the vtable verification runtime functions are in libstdc++, so we use
  706. the spec just below this one. */
  707. #ifndef VTABLE_VERIFICATION_SPEC
  708. #define VTABLE_VERIFICATION_SPEC "\
  709. %{!nostdlib:%{fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}\
  710. %{fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}}"
  711. #endif
  712. #ifndef CHKP_SPEC
  713. #define CHKP_SPEC ""
  714. #endif
  715. /* -u* was put back because both BSD and SysV seem to support it. */
  716. /* %{static:} simply prevents an error message if the target machine
  717. doesn't handle -static. */
  718. /* We want %{T*} after %{L*} and %D so that it can be used to specify linker
  719. scripts which exist in user specified directories, or in standard
  720. directories. */
  721. /* We pass any -flto flags on to the linker, which is expected
  722. to understand them. In practice, this means it had better be collect2. */
  723. /* %{e*} includes -export-dynamic; see comment in common.opt. */
  724. #ifndef LINK_COMMAND_SPEC
  725. #define LINK_COMMAND_SPEC "\
  726. %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
  727. %(linker) " \
  728. LINK_PLUGIN_SPEC \
  729. "%{flto|flto=*:%<fcompare-debug*} \
  730. %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \
  731. "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
  732. "%X %{o*} %{e*} %{N} %{n} %{r}\
  733. %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}} " VTABLE_VERIFICATION_SPEC " \
  734. %{static:} %{L*} %(mfwrap) %(link_libgcc) " SANITIZER_EARLY_SPEC " %o\
  735. " CHKP_SPEC " \
  736. %{fopenacc|fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)}\
  737. %{fcilkplus:%:include(libcilkrts.spec)%(link_cilkrts)}\
  738. %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\
  739. %(mflib) " STACK_SPLIT_SPEC "\
  740. %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \
  741. %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\
  742. %{!nostdlib:%{!nostartfiles:%E}} %{T*} }}}}}}"
  743. #endif
  744. #ifndef LINK_LIBGCC_SPEC
  745. /* Generate -L options for startfile prefix list. */
  746. # define LINK_LIBGCC_SPEC "%D"
  747. #endif
  748. #ifndef STARTFILE_PREFIX_SPEC
  749. # define STARTFILE_PREFIX_SPEC ""
  750. #endif
  751. #ifndef SYSROOT_SPEC
  752. # define SYSROOT_SPEC "--sysroot=%R"
  753. #endif
  754. #ifndef SYSROOT_SUFFIX_SPEC
  755. # define SYSROOT_SUFFIX_SPEC ""
  756. #endif
  757. #ifndef SYSROOT_HEADERS_SUFFIX_SPEC
  758. # define SYSROOT_HEADERS_SUFFIX_SPEC ""
  759. #endif
  760. static const char *asm_debug = ASM_DEBUG_SPEC;
  761. static const char *cpp_spec = CPP_SPEC;
  762. static const char *cc1_spec = CC1_SPEC;
  763. static const char *cc1plus_spec = CC1PLUS_SPEC;
  764. static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC;
  765. static const char *link_ssp_spec = LINK_SSP_SPEC;
  766. static const char *asm_spec = ASM_SPEC;
  767. static const char *asm_final_spec = ASM_FINAL_SPEC;
  768. static const char *link_spec = LINK_SPEC;
  769. static const char *lib_spec = LIB_SPEC;
  770. static const char *link_gomp_spec = "";
  771. static const char *libgcc_spec = LIBGCC_SPEC;
  772. static const char *endfile_spec = ENDFILE_SPEC;
  773. static const char *startfile_spec = STARTFILE_SPEC;
  774. static const char *linker_name_spec = LINKER_NAME;
  775. static const char *linker_plugin_file_spec = "";
  776. static const char *lto_wrapper_spec = "";
  777. static const char *lto_gcc_spec = "";
  778. static const char *link_command_spec = LINK_COMMAND_SPEC;
  779. static const char *link_libgcc_spec = LINK_LIBGCC_SPEC;
  780. static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC;
  781. static const char *sysroot_spec = SYSROOT_SPEC;
  782. static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC;
  783. static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC;
  784. static const char *self_spec = "";
  785. /* Standard options to cpp, cc1, and as, to reduce duplication in specs.
  786. There should be no need to override these in target dependent files,
  787. but we need to copy them to the specs file so that newer versions
  788. of the GCC driver can correctly drive older tool chains with the
  789. appropriate -B options. */
  790. /* When cpplib handles traditional preprocessing, get rid of this, and
  791. call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so
  792. that we default the front end language better. */
  793. static const char *trad_capable_cpp =
  794. "cc1 -E %{traditional|traditional-cpp:-traditional-cpp}";
  795. /* We don't wrap .d files in %W{} since a missing .d file, and
  796. therefore no dependency entry, confuses make into thinking a .o
  797. file that happens to exist is up-to-date. */
  798. static const char *cpp_unique_options =
  799. "%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*&F*} %{P} %I\
  800. %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\
  801. %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\
  802. %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\
  803. %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\
  804. %{remap} %{g3|ggdb3|gstabs3|gcoff3|gxcoff3|gvms3:-dD}\
  805. %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\
  806. %{H} %C %{D*&U*&A*} %{i*} %Z %i\
  807. %{E|M|MM:%W{o*}}";
  808. /* This contains cpp options which are common with cc1_options and are passed
  809. only when preprocessing only to avoid duplication. We pass the cc1 spec
  810. options to the preprocessor so that it the cc1 spec may manipulate
  811. options used to set target flags. Those special target flags settings may
  812. in turn cause preprocessor symbols to be defined specially. */
  813. static const char *cpp_options =
  814. "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\
  815. %{f*} %{g*:%{!g0:%{g*} %{!fno-working-directory:-fworking-directory}}} %{O*}\
  816. %{undef} %{save-temps*:-fpch-preprocess}";
  817. /* This contains cpp options which are not passed when the preprocessor
  818. output will be used by another program. */
  819. static const char *cpp_debug_options = "%{d*}";
  820. /* NB: This is shared amongst all front-ends, except for Ada. */
  821. static const char *cc1_options =
  822. "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
  823. %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\
  824. %1 %{!Q:-quiet} %{!dumpbase:-dumpbase %B} %{d*} %{m*} %{aux-info*}\
  825. %{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} \
  826. %{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %b}} \
  827. %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\
  828. %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
  829. %{Qn:-fno-ident} %{Qy:} %{-help:--help}\
  830. %{-target-help:--target-help}\
  831. %{-version:--version}\
  832. %{-help=*:--help=%*}\
  833. %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
  834. %{fsyntax-only:-o %j} %{-param*}\
  835. %{coverage:-fprofile-arcs -ftest-coverage}";
  836. static const char *asm_options =
  837. "%{-target-help:%:print-asm-header()} "
  838. #if HAVE_GNU_AS
  839. /* If GNU AS is used, then convert -w (no warnings), -I, and -v
  840. to the assembler equivalents. */
  841. "%{v} %{w:-W} %{I*} "
  842. #endif
  843. ASM_COMPRESS_DEBUG_SPEC
  844. "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}";
  845. static const char *invoke_as =
  846. #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
  847. "%{!fwpa*:\
  848. %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\
  849. %{!S:-o %|.s |\n as %(asm_options) %|.s %A }\
  850. }";
  851. #else
  852. "%{!fwpa*:\
  853. %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\
  854. %{!S:-o %|.s |\n as %(asm_options) %m.s %A }\
  855. }";
  856. #endif
  857. /* Some compilers have limits on line lengths, and the multilib_select
  858. and/or multilib_matches strings can be very long, so we build them at
  859. run time. */
  860. static struct obstack multilib_obstack;
  861. static const char *multilib_select;
  862. static const char *multilib_matches;
  863. static const char *multilib_defaults;
  864. static const char *multilib_exclusions;
  865. static const char *multilib_reuse;
  866. /* Check whether a particular argument is a default argument. */
  867. #ifndef MULTILIB_DEFAULTS
  868. #define MULTILIB_DEFAULTS { "" }
  869. #endif
  870. static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS;
  871. #ifndef DRIVER_SELF_SPECS
  872. #define DRIVER_SELF_SPECS ""
  873. #endif
  874. /* Linking to libgomp implies pthreads. This is particularly important
  875. for targets that use different start files and suchlike. */
  876. #ifndef GOMP_SELF_SPECS
  877. #define GOMP_SELF_SPECS "%{fopenacc|fopenmp|ftree-parallelize-loops=*: " \
  878. "-pthread}"
  879. #endif
  880. /* Likewise for -fgnu-tm. */
  881. #ifndef GTM_SELF_SPECS
  882. #define GTM_SELF_SPECS "%{fgnu-tm: -pthread}"
  883. #endif
  884. /* Likewise for -fcilkplus. */
  885. #ifndef CILK_SELF_SPECS
  886. #define CILK_SELF_SPECS "%{fcilkplus: -pthread}"
  887. #endif
  888. static const char *const driver_self_specs[] = {
  889. "%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns",
  890. DRIVER_SELF_SPECS, CONFIGURE_SPECS, GOMP_SELF_SPECS, GTM_SELF_SPECS,
  891. CILK_SELF_SPECS
  892. };
  893. #ifndef OPTION_DEFAULT_SPECS
  894. #define OPTION_DEFAULT_SPECS { "", "" }
  895. #endif
  896. struct default_spec
  897. {
  898. const char *name;
  899. const char *spec;
  900. };
  901. static const struct default_spec
  902. option_default_specs[] = { OPTION_DEFAULT_SPECS };
  903. struct user_specs
  904. {
  905. struct user_specs *next;
  906. const char *filename;
  907. };
  908. static struct user_specs *user_specs_head, *user_specs_tail;
  909. /* Record the mapping from file suffixes for compilation specs. */
  910. struct compiler
  911. {
  912. const char *suffix; /* Use this compiler for input files
  913. whose names end in this suffix. */
  914. const char *spec; /* To use this compiler, run this spec. */
  915. const char *cpp_spec; /* If non-NULL, substitute this spec
  916. for `%C', rather than the usual
  917. cpp_spec. */
  918. const int combinable; /* If nonzero, compiler can deal with
  919. multiple source files at once (IMA). */
  920. const int needs_preprocessing; /* If nonzero, source files need to
  921. be run through a preprocessor. */
  922. };
  923. /* Pointer to a vector of `struct compiler' that gives the spec for
  924. compiling a file, based on its suffix.
  925. A file that does not end in any of these suffixes will be passed
  926. unchanged to the loader and nothing else will be done to it.
  927. An entry containing two 0s is used to terminate the vector.
  928. If multiple entries match a file, the last matching one is used. */
  929. static struct compiler *compilers;
  930. /* Number of entries in `compilers', not counting the null terminator. */
  931. static int n_compilers;
  932. /* The default list of file name suffixes and their compilation specs. */
  933. static const struct compiler default_compilers[] =
  934. {
  935. /* Add lists of suffixes of known languages here. If those languages
  936. were not present when we built the driver, we will hit these copies
  937. and be given a more meaningful error than "file not used since
  938. linking is not done". */
  939. {".m", "#Objective-C", 0, 0, 0}, {".mi", "#Objective-C", 0, 0, 0},
  940. {".mm", "#Objective-C++", 0, 0, 0}, {".M", "#Objective-C++", 0, 0, 0},
  941. {".mii", "#Objective-C++", 0, 0, 0},
  942. {".cc", "#C++", 0, 0, 0}, {".cxx", "#C++", 0, 0, 0},
  943. {".cpp", "#C++", 0, 0, 0}, {".cp", "#C++", 0, 0, 0},
  944. {".c++", "#C++", 0, 0, 0}, {".C", "#C++", 0, 0, 0},
  945. {".CPP", "#C++", 0, 0, 0}, {".ii", "#C++", 0, 0, 0},
  946. {".ads", "#Ada", 0, 0, 0}, {".adb", "#Ada", 0, 0, 0},
  947. {".f", "#Fortran", 0, 0, 0}, {".F", "#Fortran", 0, 0, 0},
  948. {".for", "#Fortran", 0, 0, 0}, {".FOR", "#Fortran", 0, 0, 0},
  949. {".ftn", "#Fortran", 0, 0, 0}, {".FTN", "#Fortran", 0, 0, 0},
  950. {".fpp", "#Fortran", 0, 0, 0}, {".FPP", "#Fortran", 0, 0, 0},
  951. {".f90", "#Fortran", 0, 0, 0}, {".F90", "#Fortran", 0, 0, 0},
  952. {".f95", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0},
  953. {".f03", "#Fortran", 0, 0, 0}, {".F03", "#Fortran", 0, 0, 0},
  954. {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0},
  955. {".r", "#Ratfor", 0, 0, 0},
  956. {".p", "#Pascal", 0, 0, 0}, {".pas", "#Pascal", 0, 0, 0},
  957. {".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0},
  958. {".zip", "#Java", 0, 0, 0}, {".jar", "#Java", 0, 0, 0},
  959. {".go", "#Go", 0, 1, 0},
  960. /* Next come the entries for C. */
  961. {".c", "@c", 0, 0, 1},
  962. {"@c",
  963. /* cc1 has an integrated ISO C preprocessor. We should invoke the
  964. external preprocessor if -save-temps is given. */
  965. "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
  966. %{!E:%{!M:%{!MM:\
  967. %{traditional:\
  968. %eGNU C no longer supports -traditional without -E}\
  969. %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
  970. %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
  971. cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
  972. %(cc1_options)}\
  973. %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
  974. cc1 %(cpp_unique_options) %(cc1_options)}}}\
  975. %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 1},
  976. {"-",
  977. "%{!E:%e-E or -x required when input is from standard input}\
  978. %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)", 0, 0, 0},
  979. {".h", "@c-header", 0, 0, 0},
  980. {"@c-header",
  981. /* cc1 has an integrated ISO C preprocessor. We should invoke the
  982. external preprocessor if -save-temps is given. */
  983. "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
  984. %{!E:%{!M:%{!MM:\
  985. %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \
  986. %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\
  987. cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \
  988. %(cc1_options)\
  989. %{!fdump-ada-spec*:-o %g.s %{!o*:--output-pch=%i.gch}\
  990. %W{o*:--output-pch=%*}}%V}\
  991. %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\
  992. cc1 %(cpp_unique_options) %(cc1_options)\
  993. %{!fdump-ada-spec*:-o %g.s %{!o*:--output-pch=%i.gch}\
  994. %W{o*:--output-pch=%*}}%V}}}}}}", 0, 0, 0},
  995. {".i", "@cpp-output", 0, 0, 0},
  996. {"@cpp-output",
  997. "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}", 0, 0, 0},
  998. {".s", "@assembler", 0, 0, 0},
  999. {"@assembler",
  1000. "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}", 0, 0, 0},
  1001. {".sx", "@assembler-with-cpp", 0, 0, 0},
  1002. {".S", "@assembler-with-cpp", 0, 0, 0},
  1003. {"@assembler-with-cpp",
  1004. #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT
  1005. "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
  1006. %{E|M|MM:%(cpp_debug_options)}\
  1007. %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
  1008. as %(asm_debug) %(asm_options) %|.s %A }}}}"
  1009. #else
  1010. "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\
  1011. %{E|M|MM:%(cpp_debug_options)}\
  1012. %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\
  1013. as %(asm_debug) %(asm_options) %m.s %A }}}}"
  1014. #endif
  1015. , 0, 0, 0},
  1016. #include "specs.h"
  1017. /* Mark end of table. */
  1018. {0, 0, 0, 0, 0}
  1019. };
  1020. /* Number of elements in default_compilers, not counting the terminator. */
  1021. static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1;
  1022. typedef char *char_p; /* For DEF_VEC_P. */
  1023. /* A vector of options to give to the linker.
  1024. These options are accumulated by %x,
  1025. and substituted into the linker command with %X. */
  1026. static vec<char_p> linker_options;
  1027. /* A vector of options to give to the assembler.
  1028. These options are accumulated by -Wa,
  1029. and substituted into the assembler command with %Y. */
  1030. static vec<char_p> assembler_options;
  1031. /* A vector of options to give to the preprocessor.
  1032. These options are accumulated by -Wp,
  1033. and substituted into the preprocessor command with %Z. */
  1034. static vec<char_p> preprocessor_options;
  1035. static char *
  1036. skip_whitespace (char *p)
  1037. {
  1038. while (1)
  1039. {
  1040. /* A fully-blank line is a delimiter in the SPEC file and shouldn't
  1041. be considered whitespace. */
  1042. if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n')
  1043. return p + 1;
  1044. else if (*p == '\n' || *p == ' ' || *p == '\t')
  1045. p++;
  1046. else if (*p == '#')
  1047. {
  1048. while (*p != '\n')
  1049. p++;
  1050. p++;
  1051. }
  1052. else
  1053. break;
  1054. }
  1055. return p;
  1056. }
  1057. /* Structures to keep track of prefixes to try when looking for files. */
  1058. struct prefix_list
  1059. {
  1060. const char *prefix; /* String to prepend to the path. */
  1061. struct prefix_list *next; /* Next in linked list. */
  1062. int require_machine_suffix; /* Don't use without machine_suffix. */
  1063. /* 2 means try both machine_suffix and just_machine_suffix. */
  1064. int priority; /* Sort key - priority within list. */
  1065. int os_multilib; /* 1 if OS multilib scheme should be used,
  1066. 0 for GCC multilib scheme. */
  1067. };
  1068. struct path_prefix
  1069. {
  1070. struct prefix_list *plist; /* List of prefixes to try */
  1071. int max_len; /* Max length of a prefix in PLIST */
  1072. const char *name; /* Name of this list (used in config stuff) */
  1073. };
  1074. /* List of prefixes to try when looking for executables. */
  1075. static struct path_prefix exec_prefixes = { 0, 0, "exec" };
  1076. /* List of prefixes to try when looking for startup (crt0) files. */
  1077. static struct path_prefix startfile_prefixes = { 0, 0, "startfile" };
  1078. /* List of prefixes to try when looking for include files. */
  1079. static struct path_prefix include_prefixes = { 0, 0, "include" };
  1080. /* Suffix to attach to directories searched for commands.
  1081. This looks like `MACHINE/VERSION/'. */
  1082. static const char *machine_suffix = 0;
  1083. /* Suffix to attach to directories searched for commands.
  1084. This is just `MACHINE/'. */
  1085. static const char *just_machine_suffix = 0;
  1086. /* Adjusted value of GCC_EXEC_PREFIX envvar. */
  1087. static const char *gcc_exec_prefix;
  1088. /* Adjusted value of standard_libexec_prefix. */
  1089. static const char *gcc_libexec_prefix;
  1090. /* Default prefixes to attach to command names. */
  1091. #ifndef STANDARD_STARTFILE_PREFIX_1
  1092. #define STANDARD_STARTFILE_PREFIX_1 "/lib/"
  1093. #endif
  1094. #ifndef STANDARD_STARTFILE_PREFIX_2
  1095. #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/"
  1096. #endif
  1097. #ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */
  1098. #undef MD_EXEC_PREFIX
  1099. #undef MD_STARTFILE_PREFIX
  1100. #undef MD_STARTFILE_PREFIX_1
  1101. #endif
  1102. /* If no prefixes defined, use the null string, which will disable them. */
  1103. #ifndef MD_EXEC_PREFIX
  1104. #define MD_EXEC_PREFIX ""
  1105. #endif
  1106. #ifndef MD_STARTFILE_PREFIX
  1107. #define MD_STARTFILE_PREFIX ""
  1108. #endif
  1109. #ifndef MD_STARTFILE_PREFIX_1
  1110. #define MD_STARTFILE_PREFIX_1 ""
  1111. #endif
  1112. /* These directories are locations set at configure-time based on the
  1113. --prefix option provided to configure. Their initializers are
  1114. defined in Makefile.in. These paths are not *directly* used when
  1115. gcc_exec_prefix is set because, in that case, we know where the
  1116. compiler has been installed, and use paths relative to that
  1117. location instead. */
  1118. static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX;
  1119. static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX;
  1120. static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX;
  1121. static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
  1122. /* For native compilers, these are well-known paths containing
  1123. components that may be provided by the system. For cross
  1124. compilers, these paths are not used. */
  1125. static const char *md_exec_prefix = MD_EXEC_PREFIX;
  1126. static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
  1127. static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
  1128. static const char *const standard_startfile_prefix_1
  1129. = STANDARD_STARTFILE_PREFIX_1;
  1130. static const char *const standard_startfile_prefix_2
  1131. = STANDARD_STARTFILE_PREFIX_2;
  1132. /* A relative path to be used in finding the location of tools
  1133. relative to the driver. */
  1134. static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
  1135. /* A prefix to be used when this is an accelerator compiler. */
  1136. static const char *const accel_dir_suffix = ACCEL_DIR_SUFFIX;
  1137. /* Subdirectory to use for locating libraries. Set by
  1138. set_multilib_dir based on the compilation options. */
  1139. static const char *multilib_dir;
  1140. /* Subdirectory to use for locating libraries in OS conventions. Set by
  1141. set_multilib_dir based on the compilation options. */
  1142. static const char *multilib_os_dir;
  1143. /* Subdirectory to use for locating libraries in multiarch conventions. Set by
  1144. set_multilib_dir based on the compilation options. */
  1145. static const char *multiarch_dir;
  1146. /* Structure to keep track of the specs that have been defined so far.
  1147. These are accessed using %(specname) in a compiler or link
  1148. spec. */
  1149. struct spec_list
  1150. {
  1151. /* The following 2 fields must be first */
  1152. /* to allow EXTRA_SPECS to be initialized */
  1153. const char *name; /* name of the spec. */
  1154. const char *ptr; /* available ptr if no static pointer */
  1155. /* The following fields are not initialized */
  1156. /* by EXTRA_SPECS */
  1157. const char **ptr_spec; /* pointer to the spec itself. */
  1158. struct spec_list *next; /* Next spec in linked list. */
  1159. int name_len; /* length of the name */
  1160. bool user_p; /* whether string come from file spec. */
  1161. bool alloc_p; /* whether string was allocated */
  1162. };
  1163. #define INIT_STATIC_SPEC(NAME,PTR) \
  1164. { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, false, false }
  1165. /* List of statically defined specs. */
  1166. static struct spec_list static_specs[] =
  1167. {
  1168. INIT_STATIC_SPEC ("asm", &asm_spec),
  1169. INIT_STATIC_SPEC ("asm_debug", &asm_debug),
  1170. INIT_STATIC_SPEC ("asm_final", &asm_final_spec),
  1171. INIT_STATIC_SPEC ("asm_options", &asm_options),
  1172. INIT_STATIC_SPEC ("invoke_as", &invoke_as),
  1173. INIT_STATIC_SPEC ("cpp", &cpp_spec),
  1174. INIT_STATIC_SPEC ("cpp_options", &cpp_options),
  1175. INIT_STATIC_SPEC ("cpp_debug_options", &cpp_debug_options),
  1176. INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options),
  1177. INIT_STATIC_SPEC ("trad_capable_cpp", &trad_capable_cpp),
  1178. INIT_STATIC_SPEC ("cc1", &cc1_spec),
  1179. INIT_STATIC_SPEC ("cc1_options", &cc1_options),
  1180. INIT_STATIC_SPEC ("cc1plus", &cc1plus_spec),
  1181. INIT_STATIC_SPEC ("link_gcc_c_sequence", &link_gcc_c_sequence_spec),
  1182. INIT_STATIC_SPEC ("link_ssp", &link_ssp_spec),
  1183. INIT_STATIC_SPEC ("endfile", &endfile_spec),
  1184. INIT_STATIC_SPEC ("link", &link_spec),
  1185. INIT_STATIC_SPEC ("lib", &lib_spec),
  1186. INIT_STATIC_SPEC ("link_gomp", &link_gomp_spec),
  1187. INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
  1188. INIT_STATIC_SPEC ("startfile", &startfile_spec),
  1189. INIT_STATIC_SPEC ("cross_compile", &cross_compile),
  1190. INIT_STATIC_SPEC ("version", &compiler_version),
  1191. INIT_STATIC_SPEC ("multilib", &multilib_select),
  1192. INIT_STATIC_SPEC ("multilib_defaults", &multilib_defaults),
  1193. INIT_STATIC_SPEC ("multilib_extra", &multilib_extra),
  1194. INIT_STATIC_SPEC ("multilib_matches", &multilib_matches),
  1195. INIT_STATIC_SPEC ("multilib_exclusions", &multilib_exclusions),
  1196. INIT_STATIC_SPEC ("multilib_options", &multilib_options),
  1197. INIT_STATIC_SPEC ("multilib_reuse", &multilib_reuse),
  1198. INIT_STATIC_SPEC ("linker", &linker_name_spec),
  1199. INIT_STATIC_SPEC ("linker_plugin_file", &linker_plugin_file_spec),
  1200. INIT_STATIC_SPEC ("lto_wrapper", &lto_wrapper_spec),
  1201. INIT_STATIC_SPEC ("lto_gcc", &lto_gcc_spec),
  1202. INIT_STATIC_SPEC ("link_libgcc", &link_libgcc_spec),
  1203. INIT_STATIC_SPEC ("md_exec_prefix", &md_exec_prefix),
  1204. INIT_STATIC_SPEC ("md_startfile_prefix", &md_startfile_prefix),
  1205. INIT_STATIC_SPEC ("md_startfile_prefix_1", &md_startfile_prefix_1),
  1206. INIT_STATIC_SPEC ("startfile_prefix_spec", &startfile_prefix_spec),
  1207. INIT_STATIC_SPEC ("sysroot_spec", &sysroot_spec),
  1208. INIT_STATIC_SPEC ("sysroot_suffix_spec", &sysroot_suffix_spec),
  1209. INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec", &sysroot_hdrs_suffix_spec),
  1210. INIT_STATIC_SPEC ("self_spec", &self_spec),
  1211. };
  1212. #ifdef EXTRA_SPECS /* additional specs needed */
  1213. /* Structure to keep track of just the first two args of a spec_list.
  1214. That is all that the EXTRA_SPECS macro gives us. */
  1215. struct spec_list_1
  1216. {
  1217. const char *const name;
  1218. const char *const ptr;
  1219. };
  1220. static const struct spec_list_1 extra_specs_1[] = { EXTRA_SPECS };
  1221. static struct spec_list *extra_specs = (struct spec_list *) 0;
  1222. #endif
  1223. /* List of dynamically allocates specs that have been defined so far. */
  1224. static struct spec_list *specs = (struct spec_list *) 0;
  1225. /* List of static spec functions. */
  1226. static const struct spec_function static_spec_functions[] =
  1227. {
  1228. { "getenv", getenv_spec_function },
  1229. { "if-exists", if_exists_spec_function },
  1230. { "if-exists-else", if_exists_else_spec_function },
  1231. { "sanitize", sanitize_spec_function },
  1232. { "replace-outfile", replace_outfile_spec_function },
  1233. { "remove-outfile", remove_outfile_spec_function },
  1234. { "version-compare", version_compare_spec_function },
  1235. { "include", include_spec_function },
  1236. { "find-file", find_file_spec_function },
  1237. { "find-plugindir", find_plugindir_spec_function },
  1238. { "print-asm-header", print_asm_header_spec_function },
  1239. { "compare-debug-dump-opt", compare_debug_dump_opt_spec_function },
  1240. { "compare-debug-self-opt", compare_debug_self_opt_spec_function },
  1241. { "compare-debug-auxbase-opt", compare_debug_auxbase_opt_spec_function },
  1242. { "pass-through-libs", pass_through_libs_spec_func },
  1243. { "replace-extension", replace_extension_spec_func },
  1244. #ifdef EXTRA_SPEC_FUNCTIONS
  1245. EXTRA_SPEC_FUNCTIONS
  1246. #endif
  1247. { 0, 0 }
  1248. };
  1249. static int processing_spec_function;
  1250. /* Add appropriate libgcc specs to OBSTACK, taking into account
  1251. various permutations of -shared-libgcc, -shared, and such. */
  1252. #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
  1253. #ifndef USE_LD_AS_NEEDED
  1254. #define USE_LD_AS_NEEDED 0
  1255. #endif
  1256. static void
  1257. init_gcc_specs (struct obstack *obstack, const char *shared_name,
  1258. const char *static_name, const char *eh_name)
  1259. {
  1260. char *buf;
  1261. buf = concat ("%{static|static-libgcc:", static_name, " ", eh_name, "}"
  1262. "%{!static:%{!static-libgcc:"
  1263. #if USE_LD_AS_NEEDED
  1264. "%{!shared-libgcc:",
  1265. static_name, " " LD_AS_NEEDED_OPTION " ",
  1266. shared_name, " " LD_NO_AS_NEEDED_OPTION
  1267. "}"
  1268. "%{shared-libgcc:",
  1269. shared_name, "%{!shared: ", static_name, "}"
  1270. "}"
  1271. #else
  1272. "%{!shared:"
  1273. "%{!shared-libgcc:", static_name, " ", eh_name, "}"
  1274. "%{shared-libgcc:", shared_name, " ", static_name, "}"
  1275. "}"
  1276. #ifdef LINK_EH_SPEC
  1277. "%{shared:"
  1278. "%{shared-libgcc:", shared_name, "}"
  1279. "%{!shared-libgcc:", static_name, "}"
  1280. "}"
  1281. #else
  1282. "%{shared:", shared_name, "}"
  1283. #endif
  1284. #endif
  1285. "}}", NULL);
  1286. obstack_grow (obstack, buf, strlen (buf));
  1287. free (buf);
  1288. }
  1289. #endif /* ENABLE_SHARED_LIBGCC */
  1290. /* Initialize the specs lookup routines. */
  1291. static void
  1292. init_spec (void)
  1293. {
  1294. struct spec_list *next = (struct spec_list *) 0;
  1295. struct spec_list *sl = (struct spec_list *) 0;
  1296. int i;
  1297. if (specs)
  1298. return; /* Already initialized. */
  1299. if (verbose_flag)
  1300. fnotice (stderr, "Using built-in specs.\n");
  1301. #ifdef EXTRA_SPECS
  1302. extra_specs = XCNEWVEC (struct spec_list, ARRAY_SIZE (extra_specs_1));
  1303. for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--)
  1304. {
  1305. sl = &extra_specs[i];
  1306. sl->name = extra_specs_1[i].name;
  1307. sl->ptr = extra_specs_1[i].ptr;
  1308. sl->next = next;
  1309. sl->name_len = strlen (sl->name);
  1310. sl->ptr_spec = &sl->ptr;
  1311. next = sl;
  1312. }
  1313. #endif
  1314. for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
  1315. {
  1316. sl = &static_specs[i];
  1317. sl->next = next;
  1318. next = sl;
  1319. }
  1320. #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)
  1321. /* ??? If neither -shared-libgcc nor --static-libgcc was
  1322. seen, then we should be making an educated guess. Some proposed
  1323. heuristics for ELF include:
  1324. (1) If "-Wl,--export-dynamic", then it's a fair bet that the
  1325. program will be doing dynamic loading, which will likely
  1326. need the shared libgcc.
  1327. (2) If "-ldl", then it's also a fair bet that we're doing
  1328. dynamic loading.
  1329. (3) For each ET_DYN we're linking against (either through -lfoo
  1330. or /some/path/foo.so), check to see whether it or one of
  1331. its dependencies depends on a shared libgcc.
  1332. (4) If "-shared"
  1333. If the runtime is fixed to look for program headers instead
  1334. of calling __register_frame_info at all, for each object,
  1335. use the shared libgcc if any EH symbol referenced.
  1336. If crtstuff is fixed to not invoke __register_frame_info
  1337. automatically, for each object, use the shared libgcc if
  1338. any non-empty unwind section found.
  1339. Doing any of this probably requires invoking an external program to
  1340. do the actual object file scanning. */
  1341. {
  1342. const char *p = libgcc_spec;
  1343. int in_sep = 1;
  1344. /* Transform the extant libgcc_spec into one that uses the shared libgcc
  1345. when given the proper command line arguments. */
  1346. while (*p)
  1347. {
  1348. if (in_sep && *p == '-' && strncmp (p, "-lgcc", 5) == 0)
  1349. {
  1350. init_gcc_specs (&obstack,
  1351. "-lgcc_s"
  1352. #ifdef USE_LIBUNWIND_EXCEPTIONS
  1353. " -lunwind"
  1354. #endif
  1355. ,
  1356. "-lgcc",
  1357. "-lgcc_eh"
  1358. #ifdef USE_LIBUNWIND_EXCEPTIONS
  1359. # ifdef HAVE_LD_STATIC_DYNAMIC
  1360. " %{!static:" LD_STATIC_OPTION "} -lunwind"
  1361. " %{!static:" LD_DYNAMIC_OPTION "}"
  1362. # else
  1363. " -lunwind"
  1364. # endif
  1365. #endif
  1366. );
  1367. p += 5;
  1368. in_sep = 0;
  1369. }
  1370. else if (in_sep && *p == 'l' && strncmp (p, "libgcc.a%s", 10) == 0)
  1371. {
  1372. /* Ug. We don't know shared library extensions. Hope that
  1373. systems that use this form don't do shared libraries. */
  1374. init_gcc_specs (&obstack,
  1375. "-lgcc_s",
  1376. "libgcc.a%s",
  1377. "libgcc_eh.a%s"
  1378. #ifdef USE_LIBUNWIND_EXCEPTIONS
  1379. " -lunwind"
  1380. #endif
  1381. );
  1382. p += 10;
  1383. in_sep = 0;
  1384. }
  1385. else
  1386. {
  1387. obstack_1grow (&obstack, *p);
  1388. in_sep = (*p == ' ');
  1389. p += 1;
  1390. }
  1391. }
  1392. obstack_1grow (&obstack, '\0');
  1393. libgcc_spec = XOBFINISH (&obstack, const char *);
  1394. }
  1395. #endif
  1396. #ifdef USE_AS_TRADITIONAL_FORMAT
  1397. /* Prepend "--traditional-format" to whatever asm_spec we had before. */
  1398. {
  1399. static const char tf[] = "--traditional-format ";
  1400. obstack_grow (&obstack, tf, sizeof (tf) - 1);
  1401. obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
  1402. asm_spec = XOBFINISH (&obstack, const char *);
  1403. }
  1404. #endif
  1405. #if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC || \
  1406. defined LINKER_HASH_STYLE
  1407. # ifdef LINK_BUILDID_SPEC
  1408. /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */
  1409. obstack_grow (&obstack, LINK_BUILDID_SPEC, sizeof (LINK_BUILDID_SPEC) - 1);
  1410. # endif
  1411. # ifdef LINK_EH_SPEC
  1412. /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */
  1413. obstack_grow (&obstack, LINK_EH_SPEC, sizeof (LINK_EH_SPEC) - 1);
  1414. # endif
  1415. # ifdef LINKER_HASH_STYLE
  1416. /* Prepend --hash-style=LINKER_HASH_STYLE to whatever link_spec we had
  1417. before. */
  1418. {
  1419. static const char hash_style[] = "--hash-style=";
  1420. obstack_grow (&obstack, hash_style, sizeof (hash_style) - 1);
  1421. obstack_grow (&obstack, LINKER_HASH_STYLE, sizeof (LINKER_HASH_STYLE) - 1);
  1422. obstack_1grow (&obstack, ' ');
  1423. }
  1424. # endif
  1425. obstack_grow0 (&obstack, link_spec, strlen (link_spec));
  1426. link_spec = XOBFINISH (&obstack, const char *);
  1427. #endif
  1428. specs = sl;
  1429. }
  1430. /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is
  1431. removed; If the spec starts with a + then SPEC is added to the end of the
  1432. current spec. */
  1433. static void
  1434. set_spec (const char *name, const char *spec, bool user_p)
  1435. {
  1436. struct spec_list *sl;
  1437. const char *old_spec;
  1438. int name_len = strlen (name);
  1439. int i;
  1440. /* If this is the first call, initialize the statically allocated specs. */
  1441. if (!specs)
  1442. {
  1443. struct spec_list *next = (struct spec_list *) 0;
  1444. for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--)
  1445. {
  1446. sl = &static_specs[i];
  1447. sl->next = next;
  1448. next = sl;
  1449. }
  1450. specs = sl;
  1451. }
  1452. /* See if the spec already exists. */
  1453. for (sl = specs; sl; sl = sl->next)
  1454. if (name_len == sl->name_len && !strcmp (sl->name, name))
  1455. break;
  1456. if (!sl)
  1457. {
  1458. /* Not found - make it. */
  1459. sl = XNEW (struct spec_list);
  1460. sl->name = xstrdup (name);
  1461. sl->name_len = name_len;
  1462. sl->ptr_spec = &sl->ptr;
  1463. sl->alloc_p = 0;
  1464. *(sl->ptr_spec) = "";
  1465. sl->next = specs;
  1466. specs = sl;
  1467. }
  1468. old_spec = *(sl->ptr_spec);
  1469. *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
  1470. ? concat (old_spec, spec + 1, NULL)
  1471. : xstrdup (spec));
  1472. #ifdef DEBUG_SPECS
  1473. if (verbose_flag)
  1474. fnotice (stderr, "Setting spec %s to '%s'\n\n", name, *(sl->ptr_spec));
  1475. #endif
  1476. /* Free the old spec. */
  1477. if (old_spec && sl->alloc_p)
  1478. free (CONST_CAST (char *, old_spec));
  1479. sl->user_p = user_p;
  1480. sl->alloc_p = true;
  1481. }
  1482. /* Accumulate a command (program name and args), and run it. */
  1483. typedef const char *const_char_p; /* For DEF_VEC_P. */
  1484. /* Vector of pointers to arguments in the current line of specifications. */
  1485. static vec<const_char_p> argbuf;
  1486. /* Were the options -c, -S or -E passed. */
  1487. static int have_c = 0;
  1488. /* Was the option -o passed. */
  1489. static int have_o = 0;
  1490. /* Pointer to output file name passed in with -o. */
  1491. static const char *output_file = 0;
  1492. /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated
  1493. temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for
  1494. it here. */
  1495. static struct temp_name {
  1496. const char *suffix; /* suffix associated with the code. */
  1497. int length; /* strlen (suffix). */
  1498. int unique; /* Indicates whether %g or %u/%U was used. */
  1499. const char *filename; /* associated filename. */
  1500. int filename_length; /* strlen (filename). */
  1501. struct temp_name *next;
  1502. } *temp_names;
  1503. /* Number of commands executed so far. */
  1504. static int execution_count;
  1505. /* Number of commands that exited with a signal. */
  1506. static int signal_count;
  1507. /* Allocate the argument vector. */
  1508. static void
  1509. alloc_args (void)
  1510. {
  1511. argbuf.create (10);
  1512. }
  1513. /* Clear out the vector of arguments (after a command is executed). */
  1514. static void
  1515. clear_args (void)
  1516. {
  1517. argbuf.truncate (0);
  1518. }
  1519. /* Add one argument to the vector at the end.
  1520. This is done when a space is seen or at the end of the line.
  1521. If DELETE_ALWAYS is nonzero, the arg is a filename
  1522. and the file should be deleted eventually.
  1523. If DELETE_FAILURE is nonzero, the arg is a filename
  1524. and the file should be deleted if this compilation fails. */
  1525. static void
  1526. store_arg (const char *arg, int delete_always, int delete_failure)
  1527. {
  1528. argbuf.safe_push (arg);
  1529. if (delete_always || delete_failure)
  1530. {
  1531. const char *p;
  1532. /* If the temporary file we should delete is specified as
  1533. part of a joined argument extract the filename. */
  1534. if (arg[0] == '-'
  1535. && (p = strrchr (arg, '=')))
  1536. arg = p + 1;
  1537. record_temp_file (arg, delete_always, delete_failure);
  1538. }
  1539. }
  1540. /* Load specs from a file name named FILENAME, replacing occurrences of
  1541. various different types of line-endings, \r\n, \n\r and just \r, with
  1542. a single \n. */
  1543. static char *
  1544. load_specs (const char *filename)
  1545. {
  1546. int desc;
  1547. int readlen;
  1548. struct stat statbuf;
  1549. char *buffer;
  1550. char *buffer_p;
  1551. char *specs;
  1552. char *specs_p;
  1553. if (verbose_flag)
  1554. fnotice (stderr, "Reading specs from %s\n", filename);
  1555. /* Open and stat the file. */
  1556. desc = open (filename, O_RDONLY, 0);
  1557. if (desc < 0)
  1558. pfatal_with_name (filename);
  1559. if (stat (filename, &statbuf) < 0)
  1560. pfatal_with_name (filename);
  1561. /* Read contents of file into BUFFER. */
  1562. buffer = XNEWVEC (char, statbuf.st_size + 1);
  1563. readlen = read (desc, buffer, (unsigned) statbuf.st_size);
  1564. if (readlen < 0)
  1565. pfatal_with_name (filename);
  1566. buffer[readlen] = 0;
  1567. close (desc);
  1568. specs = XNEWVEC (char, readlen + 1);
  1569. specs_p = specs;
  1570. for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++)
  1571. {
  1572. int skip = 0;
  1573. char c = *buffer_p;
  1574. if (c == '\r')
  1575. {
  1576. if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */
  1577. skip = 1;
  1578. else if (*(buffer_p + 1) == '\n') /* \r\n */
  1579. skip = 1;
  1580. else /* \r */
  1581. c = '\n';
  1582. }
  1583. if (! skip)
  1584. *specs_p++ = c;
  1585. }
  1586. *specs_p = '\0';
  1587. free (buffer);
  1588. return (specs);
  1589. }
  1590. /* Read compilation specs from a file named FILENAME,
  1591. replacing the default ones.
  1592. A suffix which starts with `*' is a definition for
  1593. one of the machine-specific sub-specs. The "suffix" should be
  1594. *asm, *cc1, *cpp, *link, *startfile, etc.
  1595. The corresponding spec is stored in asm_spec, etc.,
  1596. rather than in the `compilers' vector.
  1597. Anything invalid in the file is a fatal error. */
  1598. static void
  1599. read_specs (const char *filename, bool main_p, bool user_p)
  1600. {
  1601. char *buffer;
  1602. char *p;
  1603. buffer = load_specs (filename);
  1604. /* Scan BUFFER for specs, putting them in the vector. */
  1605. p = buffer;
  1606. while (1)
  1607. {
  1608. char *suffix;
  1609. char *spec;
  1610. char *in, *out, *p1, *p2, *p3;
  1611. /* Advance P in BUFFER to the next nonblank nocomment line. */
  1612. p = skip_whitespace (p);
  1613. if (*p == 0)
  1614. break;
  1615. /* Is this a special command that starts with '%'? */
  1616. /* Don't allow this for the main specs file, since it would
  1617. encourage people to overwrite it. */
  1618. if (*p == '%' && !main_p)
  1619. {
  1620. p1 = p;
  1621. while (*p && *p != '\n')
  1622. p++;
  1623. /* Skip '\n'. */
  1624. p++;
  1625. if (!strncmp (p1, "%include", sizeof ("%include") - 1)
  1626. && (p1[sizeof "%include" - 1] == ' '
  1627. || p1[sizeof "%include" - 1] == '\t'))
  1628. {
  1629. char *new_filename;
  1630. p1 += sizeof ("%include");
  1631. while (*p1 == ' ' || *p1 == '\t')
  1632. p1++;
  1633. if (*p1++ != '<' || p[-2] != '>')
  1634. fatal_error (input_location,
  1635. "specs %%include syntax malformed after "
  1636. "%ld characters",
  1637. (long) (p1 - buffer + 1));
  1638. p[-2] = '\0';
  1639. new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
  1640. read_specs (new_filename ? new_filename : p1, false, user_p);
  1641. continue;
  1642. }
  1643. else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1)
  1644. && (p1[sizeof "%include_noerr" - 1] == ' '
  1645. || p1[sizeof "%include_noerr" - 1] == '\t'))
  1646. {
  1647. char *new_filename;
  1648. p1 += sizeof "%include_noerr";
  1649. while (*p1 == ' ' || *p1 == '\t')
  1650. p1++;
  1651. if (*p1++ != '<' || p[-2] != '>')
  1652. fatal_error (input_location,
  1653. "specs %%include syntax malformed after "
  1654. "%ld characters",
  1655. (long) (p1 - buffer + 1));
  1656. p[-2] = '\0';
  1657. new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true);
  1658. if (new_filename)
  1659. read_specs (new_filename, false, user_p);
  1660. else if (verbose_flag)
  1661. fnotice (stderr, "could not find specs file %s\n", p1);
  1662. continue;
  1663. }
  1664. else if (!strncmp (p1, "%rename", sizeof "%rename" - 1)
  1665. && (p1[sizeof "%rename" - 1] == ' '
  1666. || p1[sizeof "%rename" - 1] == '\t'))
  1667. {
  1668. int name_len;
  1669. struct spec_list *sl;
  1670. struct spec_list *newsl;
  1671. /* Get original name. */
  1672. p1 += sizeof "%rename";
  1673. while (*p1 == ' ' || *p1 == '\t')
  1674. p1++;
  1675. if (! ISALPHA ((unsigned char) *p1))
  1676. fatal_error (input_location,
  1677. "specs %%rename syntax malformed after "
  1678. "%ld characters",
  1679. (long) (p1 - buffer));
  1680. p2 = p1;
  1681. while (*p2 && !ISSPACE ((unsigned char) *p2))
  1682. p2++;
  1683. if (*p2 != ' ' && *p2 != '\t')
  1684. fatal_error (input_location,
  1685. "specs %%rename syntax malformed after "
  1686. "%ld characters",
  1687. (long) (p2 - buffer));
  1688. name_len = p2 - p1;
  1689. *p2++ = '\0';
  1690. while (*p2 == ' ' || *p2 == '\t')
  1691. p2++;
  1692. if (! ISALPHA ((unsigned char) *p2))
  1693. fatal_error (input_location,
  1694. "specs %%rename syntax malformed after "
  1695. "%ld characters",
  1696. (long) (p2 - buffer));
  1697. /* Get new spec name. */
  1698. p3 = p2;
  1699. while (*p3 && !ISSPACE ((unsigned char) *p3))
  1700. p3++;
  1701. if (p3 != p - 1)
  1702. fatal_error (input_location,
  1703. "specs %%rename syntax malformed after "
  1704. "%ld characters",
  1705. (long) (p3 - buffer));
  1706. *p3 = '\0';
  1707. for (sl = specs; sl; sl = sl->next)
  1708. if (name_len == sl->name_len && !strcmp (sl->name, p1))
  1709. break;
  1710. if (!sl)
  1711. fatal_error (input_location,
  1712. "specs %s spec was not found to be renamed", p1);
  1713. if (strcmp (p1, p2) == 0)
  1714. continue;
  1715. for (newsl = specs; newsl; newsl = newsl->next)
  1716. if (strcmp (newsl->name, p2) == 0)
  1717. fatal_error (input_location,
  1718. "%s: attempt to rename spec %qs to "
  1719. "already defined spec %qs",
  1720. filename, p1, p2);
  1721. if (verbose_flag)
  1722. {
  1723. fnotice (stderr, "rename spec %s to %s\n", p1, p2);
  1724. #ifdef DEBUG_SPECS
  1725. fnotice (stderr, "spec is '%s'\n\n", *(sl->ptr_spec));
  1726. #endif
  1727. }
  1728. set_spec (p2, *(sl->ptr_spec), user_p);
  1729. if (sl->alloc_p)
  1730. free (CONST_CAST (char *, *(sl->ptr_spec)));
  1731. *(sl->ptr_spec) = "";
  1732. sl->alloc_p = 0;
  1733. continue;
  1734. }
  1735. else
  1736. fatal_error (input_location,
  1737. "specs unknown %% command after %ld characters",
  1738. (long) (p1 - buffer));
  1739. }
  1740. /* Find the colon that should end the suffix. */
  1741. p1 = p;
  1742. while (*p1 && *p1 != ':' && *p1 != '\n')
  1743. p1++;
  1744. /* The colon shouldn't be missing. */
  1745. if (*p1 != ':')
  1746. fatal_error (input_location,
  1747. "specs file malformed after %ld characters",
  1748. (long) (p1 - buffer));
  1749. /* Skip back over trailing whitespace. */
  1750. p2 = p1;
  1751. while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t'))
  1752. p2--;
  1753. /* Copy the suffix to a string. */
  1754. suffix = save_string (p, p2 - p);
  1755. /* Find the next line. */
  1756. p = skip_whitespace (p1 + 1);
  1757. if (p[1] == 0)
  1758. fatal_error (input_location,
  1759. "specs file malformed after %ld characters",
  1760. (long) (p - buffer));
  1761. p1 = p;
  1762. /* Find next blank line or end of string. */
  1763. while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0')))
  1764. p1++;
  1765. /* Specs end at the blank line and do not include the newline. */
  1766. spec = save_string (p, p1 - p);
  1767. p = p1;
  1768. /* Delete backslash-newline sequences from the spec. */
  1769. in = spec;
  1770. out = spec;
  1771. while (*in != 0)
  1772. {
  1773. if (in[0] == '\\' && in[1] == '\n')
  1774. in += 2;
  1775. else if (in[0] == '#')
  1776. while (*in && *in != '\n')
  1777. in++;
  1778. else
  1779. *out++ = *in++;
  1780. }
  1781. *out = 0;
  1782. if (suffix[0] == '*')
  1783. {
  1784. if (! strcmp (suffix, "*link_command"))
  1785. link_command_spec = spec;
  1786. else
  1787. set_spec (suffix + 1, spec, user_p);
  1788. }
  1789. else
  1790. {
  1791. /* Add this pair to the vector. */
  1792. compilers
  1793. = XRESIZEVEC (struct compiler, compilers, n_compilers + 2);
  1794. compilers[n_compilers].suffix = suffix;
  1795. compilers[n_compilers].spec = spec;
  1796. n_compilers++;
  1797. memset (&compilers[n_compilers], 0, sizeof compilers[n_compilers]);
  1798. }
  1799. if (*suffix == 0)
  1800. link_command_spec = spec;
  1801. }
  1802. if (link_command_spec == 0)
  1803. fatal_error (input_location, "spec file has no spec for linking");
  1804. }
  1805. /* Record the names of temporary files we tell compilers to write,
  1806. and delete them at the end of the run. */
  1807. /* This is the common prefix we use to make temp file names.
  1808. It is chosen once for each run of this program.
  1809. It is substituted into a spec by %g or %j.
  1810. Thus, all temp file names contain this prefix.
  1811. In practice, all temp file names start with this prefix.
  1812. This prefix comes from the envvar TMPDIR if it is defined;
  1813. otherwise, from the P_tmpdir macro if that is defined;
  1814. otherwise, in /usr/tmp or /tmp;
  1815. or finally the current directory if all else fails. */
  1816. static const char *temp_filename;
  1817. /* Length of the prefix. */
  1818. static int temp_filename_length;
  1819. /* Define the list of temporary files to delete. */
  1820. struct temp_file
  1821. {
  1822. const char *name;
  1823. struct temp_file *next;
  1824. };
  1825. /* Queue of files to delete on success or failure of compilation. */
  1826. static struct temp_file *always_delete_queue;
  1827. /* Queue of files to delete on failure of compilation. */
  1828. static struct temp_file *failure_delete_queue;
  1829. /* Record FILENAME as a file to be deleted automatically.
  1830. ALWAYS_DELETE nonzero means delete it if all compilation succeeds;
  1831. otherwise delete it in any case.
  1832. FAIL_DELETE nonzero means delete it if a compilation step fails;
  1833. otherwise delete it in any case. */
  1834. void
  1835. record_temp_file (const char *filename, int always_delete, int fail_delete)
  1836. {
  1837. char *const name = xstrdup (filename);
  1838. if (always_delete)
  1839. {
  1840. struct temp_file *temp;
  1841. for (temp = always_delete_queue; temp; temp = temp->next)
  1842. if (! filename_cmp (name, temp->name))
  1843. goto already1;
  1844. temp = XNEW (struct temp_file);
  1845. temp->next = always_delete_queue;
  1846. temp->name = name;
  1847. always_delete_queue = temp;
  1848. already1:;
  1849. }
  1850. if (fail_delete)
  1851. {
  1852. struct temp_file *temp;
  1853. for (temp = failure_delete_queue; temp; temp = temp->next)
  1854. if (! filename_cmp (name, temp->name))
  1855. {
  1856. free (name);
  1857. goto already2;
  1858. }
  1859. temp = XNEW (struct temp_file);
  1860. temp->next = failure_delete_queue;
  1861. temp->name = name;
  1862. failure_delete_queue = temp;
  1863. already2:;
  1864. }
  1865. }
  1866. /* Delete all the temporary files whose names we previously recorded. */
  1867. #ifndef DELETE_IF_ORDINARY
  1868. #define DELETE_IF_ORDINARY(NAME,ST,VERBOSE_FLAG) \
  1869. do \
  1870. { \
  1871. if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \
  1872. if (unlink (NAME) < 0) \
  1873. if (VERBOSE_FLAG) \
  1874. perror_with_name (NAME); \
  1875. } while (0)
  1876. #endif
  1877. static void
  1878. delete_if_ordinary (const char *name)
  1879. {
  1880. struct stat st;
  1881. #ifdef DEBUG
  1882. int i, c;
  1883. printf ("Delete %s? (y or n) ", name);
  1884. fflush (stdout);
  1885. i = getchar ();
  1886. if (i != '\n')
  1887. while ((c = getchar ()) != '\n' && c != EOF)
  1888. ;
  1889. if (i == 'y' || i == 'Y')
  1890. #endif /* DEBUG */
  1891. DELETE_IF_ORDINARY (name, st, verbose_flag);
  1892. }
  1893. static void
  1894. delete_temp_files (void)
  1895. {
  1896. struct temp_file *temp;
  1897. for (temp = always_delete_queue; temp; temp = temp->next)
  1898. delete_if_ordinary (temp->name);
  1899. always_delete_queue = 0;
  1900. }
  1901. /* Delete all the files to be deleted on error. */
  1902. static void
  1903. delete_failure_queue (void)
  1904. {
  1905. struct temp_file *temp;
  1906. for (temp = failure_delete_queue; temp; temp = temp->next)
  1907. delete_if_ordinary (temp->name);
  1908. }
  1909. static void
  1910. clear_failure_queue (void)
  1911. {
  1912. failure_delete_queue = 0;
  1913. }
  1914. /* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK
  1915. returns non-NULL.
  1916. If DO_MULTI is true iterate over the paths twice, first with multilib
  1917. suffix then without, otherwise iterate over the paths once without
  1918. adding a multilib suffix. When DO_MULTI is true, some attempt is made
  1919. to avoid visiting the same path twice, but we could do better. For
  1920. instance, /usr/lib/../lib is considered different from /usr/lib.
  1921. At least EXTRA_SPACE chars past the end of the path passed to
  1922. CALLBACK are available for use by the callback.
  1923. CALLBACK_INFO allows extra parameters to be passed to CALLBACK.
  1924. Returns the value returned by CALLBACK. */
  1925. static void *
  1926. for_each_path (const struct path_prefix *paths,
  1927. bool do_multi,
  1928. size_t extra_space,
  1929. void *(*callback) (char *, void *),
  1930. void *callback_info)
  1931. {
  1932. struct prefix_list *pl;
  1933. const char *multi_dir = NULL;
  1934. const char *multi_os_dir = NULL;
  1935. const char *multiarch_suffix = NULL;
  1936. const char *multi_suffix;
  1937. const char *just_multi_suffix;
  1938. char *path = NULL;
  1939. void *ret = NULL;
  1940. bool skip_multi_dir = false;
  1941. bool skip_multi_os_dir = false;
  1942. multi_suffix = machine_suffix;
  1943. just_multi_suffix = just_machine_suffix;
  1944. if (do_multi && multilib_dir && strcmp (multilib_dir, ".") != 0)
  1945. {
  1946. multi_dir = concat (multilib_dir, dir_separator_str, NULL);
  1947. multi_suffix = concat (multi_suffix, multi_dir, NULL);
  1948. just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL);
  1949. }
  1950. if (do_multi && multilib_os_dir && strcmp (multilib_os_dir, ".") != 0)
  1951. multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL);
  1952. if (multiarch_dir)
  1953. multiarch_suffix = concat (multiarch_dir, dir_separator_str, NULL);
  1954. while (1)
  1955. {
  1956. size_t multi_dir_len = 0;
  1957. size_t multi_os_dir_len = 0;
  1958. size_t multiarch_len = 0;
  1959. size_t suffix_len;
  1960. size_t just_suffix_len;
  1961. size_t len;
  1962. if (multi_dir)
  1963. multi_dir_len = strlen (multi_dir);
  1964. if (multi_os_dir)
  1965. multi_os_dir_len = strlen (multi_os_dir);
  1966. if (multiarch_suffix)
  1967. multiarch_len = strlen (multiarch_suffix);
  1968. suffix_len = strlen (multi_suffix);
  1969. just_suffix_len = strlen (just_multi_suffix);
  1970. if (path == NULL)
  1971. {
  1972. len = paths->max_len + extra_space + 1;
  1973. len += MAX (MAX (suffix_len, multi_os_dir_len), multiarch_len);
  1974. path = XNEWVEC (char, len);
  1975. }
  1976. for (pl = paths->plist; pl != 0; pl = pl->next)
  1977. {
  1978. len = strlen (pl->prefix);
  1979. memcpy (path, pl->prefix, len);
  1980. /* Look first in MACHINE/VERSION subdirectory. */
  1981. if (!skip_multi_dir)
  1982. {
  1983. memcpy (path + len, multi_suffix, suffix_len + 1);
  1984. ret = callback (path, callback_info);
  1985. if (ret)
  1986. break;
  1987. }
  1988. /* Some paths are tried with just the machine (ie. target)
  1989. subdir. This is used for finding as, ld, etc. */
  1990. if (!skip_multi_dir
  1991. && pl->require_machine_suffix == 2)
  1992. {
  1993. memcpy (path + len, just_multi_suffix, just_suffix_len + 1);
  1994. ret = callback (path, callback_info);
  1995. if (ret)
  1996. break;
  1997. }
  1998. /* Now try the multiarch path. */
  1999. if (!skip_multi_dir
  2000. && !pl->require_machine_suffix && multiarch_dir)
  2001. {
  2002. memcpy (path + len, multiarch_suffix, multiarch_len + 1);
  2003. ret = callback (path, callback_info);
  2004. if (ret)
  2005. break;
  2006. }
  2007. /* Now try the base path. */
  2008. if (!pl->require_machine_suffix
  2009. && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir))
  2010. {
  2011. const char *this_multi;
  2012. size_t this_multi_len;
  2013. if (pl->os_multilib)
  2014. {
  2015. this_multi = multi_os_dir;
  2016. this_multi_len = multi_os_dir_len;
  2017. }
  2018. else
  2019. {
  2020. this_multi = multi_dir;
  2021. this_multi_len = multi_dir_len;
  2022. }
  2023. if (this_multi_len)
  2024. memcpy (path + len, this_multi, this_multi_len + 1);
  2025. else
  2026. path[len] = '\0';
  2027. ret = callback (path, callback_info);
  2028. if (ret)
  2029. break;
  2030. }
  2031. }
  2032. if (pl)
  2033. break;
  2034. if (multi_dir == NULL && multi_os_dir == NULL)
  2035. break;
  2036. /* Run through the paths again, this time without multilibs.
  2037. Don't repeat any we have already seen. */
  2038. if (multi_dir)
  2039. {
  2040. free (CONST_CAST (char *, multi_dir));
  2041. multi_dir = NULL;
  2042. free (CONST_CAST (char *, multi_suffix));
  2043. multi_suffix = machine_suffix;
  2044. free (CONST_CAST (char *, just_multi_suffix));
  2045. just_multi_suffix = just_machine_suffix;
  2046. }
  2047. else
  2048. skip_multi_dir = true;
  2049. if (multi_os_dir)
  2050. {
  2051. free (CONST_CAST (char *, multi_os_dir));
  2052. multi_os_dir = NULL;
  2053. }
  2054. else
  2055. skip_multi_os_dir = true;
  2056. }
  2057. if (multi_dir)
  2058. {
  2059. free (CONST_CAST (char *, multi_dir));
  2060. free (CONST_CAST (char *, multi_suffix));
  2061. free (CONST_CAST (char *, just_multi_suffix));
  2062. }
  2063. if (multi_os_dir)
  2064. free (CONST_CAST (char *, multi_os_dir));
  2065. if (ret != path)
  2066. free (path);
  2067. return ret;
  2068. }
  2069. /* Callback for build_search_list. Adds path to obstack being built. */
  2070. struct add_to_obstack_info {
  2071. struct obstack *ob;
  2072. bool check_dir;
  2073. bool first_time;
  2074. };
  2075. static void *
  2076. add_to_obstack (char *path, void *data)
  2077. {
  2078. struct add_to_obstack_info *info = (struct add_to_obstack_info *) data;
  2079. if (info->check_dir && !is_directory (path, false))
  2080. return NULL;
  2081. if (!info->first_time)
  2082. obstack_1grow (info->ob, PATH_SEPARATOR);
  2083. obstack_grow (info->ob, path, strlen (path));
  2084. info->first_time = false;
  2085. return NULL;
  2086. }
  2087. /* Add or change the value of an environment variable, outputting the
  2088. change to standard error if in verbose mode. */
  2089. static void
  2090. xputenv (const char *string)
  2091. {
  2092. if (verbose_flag)
  2093. fnotice (stderr, "%s\n", string);
  2094. putenv (CONST_CAST (char *, string));
  2095. }
  2096. /* Build a list of search directories from PATHS.
  2097. PREFIX is a string to prepend to the list.
  2098. If CHECK_DIR_P is true we ensure the directory exists.
  2099. If DO_MULTI is true, multilib paths are output first, then
  2100. non-multilib paths.
  2101. This is used mostly by putenv_from_prefixes so we use `collect_obstack'.
  2102. It is also used by the --print-search-dirs flag. */
  2103. static char *
  2104. build_search_list (const struct path_prefix *paths, const char *prefix,
  2105. bool check_dir, bool do_multi)
  2106. {
  2107. struct add_to_obstack_info info;
  2108. info.ob = &collect_obstack;
  2109. info.check_dir = check_dir;
  2110. info.first_time = true;
  2111. obstack_grow (&collect_obstack, prefix, strlen (prefix));
  2112. obstack_1grow (&collect_obstack, '=');
  2113. for_each_path (paths, do_multi, 0, add_to_obstack, &info);
  2114. obstack_1grow (&collect_obstack, '\0');
  2115. return XOBFINISH (&collect_obstack, char *);
  2116. }
  2117. /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
  2118. for collect. */
  2119. static void
  2120. putenv_from_prefixes (const struct path_prefix *paths, const char *env_var,
  2121. bool do_multi)
  2122. {
  2123. xputenv (build_search_list (paths, env_var, true, do_multi));
  2124. }
  2125. /* Check whether NAME can be accessed in MODE. This is like access,
  2126. except that it never considers directories to be executable. */
  2127. static int
  2128. access_check (const char *name, int mode)
  2129. {
  2130. if (mode == X_OK)
  2131. {
  2132. struct stat st;
  2133. if (stat (name, &st) < 0
  2134. || S_ISDIR (st.st_mode))
  2135. return -1;
  2136. }
  2137. return access (name, mode);
  2138. }
  2139. /* Callback for find_a_file. Appends the file name to the directory
  2140. path. If the resulting file exists in the right mode, return the
  2141. full pathname to the file. */
  2142. struct file_at_path_info {
  2143. const char *name;
  2144. const char *suffix;
  2145. int name_len;
  2146. int suffix_len;
  2147. int mode;
  2148. };
  2149. static void *
  2150. file_at_path (char *path, void *data)
  2151. {
  2152. struct file_at_path_info *info = (struct file_at_path_info *) data;
  2153. size_t len = strlen (path);
  2154. memcpy (path + len, info->name, info->name_len);
  2155. len += info->name_len;
  2156. /* Some systems have a suffix for executable files.
  2157. So try appending that first. */
  2158. if (info->suffix_len)
  2159. {
  2160. memcpy (path + len, info->suffix, info->suffix_len + 1);
  2161. if (access_check (path, info->mode) == 0)
  2162. return path;
  2163. }
  2164. path[len] = '\0';
  2165. if (access_check (path, info->mode) == 0)
  2166. return path;
  2167. return NULL;
  2168. }
  2169. /* Search for NAME using the prefix list PREFIXES. MODE is passed to
  2170. access to check permissions. If DO_MULTI is true, search multilib
  2171. paths then non-multilib paths, otherwise do not search multilib paths.
  2172. Return 0 if not found, otherwise return its name, allocated with malloc. */
  2173. static char *
  2174. find_a_file (const struct path_prefix *pprefix, const char *name, int mode,
  2175. bool do_multi)
  2176. {
  2177. struct file_at_path_info info;
  2178. #ifdef DEFAULT_ASSEMBLER
  2179. if (! strcmp (name, "as") && access (DEFAULT_ASSEMBLER, mode) == 0)
  2180. return xstrdup (DEFAULT_ASSEMBLER);
  2181. #endif
  2182. #ifdef DEFAULT_LINKER
  2183. if (! strcmp (name, "ld") && access (DEFAULT_LINKER, mode) == 0)
  2184. return xstrdup (DEFAULT_LINKER);
  2185. #endif
  2186. /* Determine the filename to execute (special case for absolute paths). */
  2187. if (IS_ABSOLUTE_PATH (name))
  2188. {
  2189. if (access (name, mode) == 0)
  2190. return xstrdup (name);
  2191. return NULL;
  2192. }
  2193. info.name = name;
  2194. info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "";
  2195. info.name_len = strlen (info.name);
  2196. info.suffix_len = strlen (info.suffix);
  2197. info.mode = mode;
  2198. return (char*) for_each_path (pprefix, do_multi,
  2199. info.name_len + info.suffix_len,
  2200. file_at_path, &info);
  2201. }
  2202. /* Ranking of prefixes in the sort list. -B prefixes are put before
  2203. all others. */
  2204. enum path_prefix_priority
  2205. {
  2206. PREFIX_PRIORITY_B_OPT,
  2207. PREFIX_PRIORITY_LAST
  2208. };
  2209. /* Add an entry for PREFIX in PLIST. The PLIST is kept in ascending
  2210. order according to PRIORITY. Within each PRIORITY, new entries are
  2211. appended.
  2212. If WARN is nonzero, we will warn if no file is found
  2213. through this prefix. WARN should point to an int
  2214. which will be set to 1 if this entry is used.
  2215. COMPONENT is the value to be passed to update_path.
  2216. REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without
  2217. the complete value of machine_suffix.
  2218. 2 means try both machine_suffix and just_machine_suffix. */
  2219. static void
  2220. add_prefix (struct path_prefix *pprefix, const char *prefix,
  2221. const char *component, /* enum prefix_priority */ int priority,
  2222. int require_machine_suffix, int os_multilib)
  2223. {
  2224. struct prefix_list *pl, **prev;
  2225. int len;
  2226. for (prev = &pprefix->plist;
  2227. (*prev) != NULL && (*prev)->priority <= priority;
  2228. prev = &(*prev)->next)
  2229. ;
  2230. /* Keep track of the longest prefix. */
  2231. prefix = update_path (prefix, component);
  2232. len = strlen (prefix);
  2233. if (len > pprefix->max_len)
  2234. pprefix->max_len = len;
  2235. pl = XNEW (struct prefix_list);
  2236. pl->prefix = prefix;
  2237. pl->require_machine_suffix = require_machine_suffix;
  2238. pl->priority = priority;
  2239. pl->os_multilib = os_multilib;
  2240. /* Insert after PREV. */
  2241. pl->next = (*prev);
  2242. (*prev) = pl;
  2243. }
  2244. /* Same as add_prefix, but prepending target_system_root to prefix. */
  2245. /* The target_system_root prefix has been relocated by gcc_exec_prefix. */
  2246. static void
  2247. add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix,
  2248. const char *component,
  2249. /* enum prefix_priority */ int priority,
  2250. int require_machine_suffix, int os_multilib)
  2251. {
  2252. if (!IS_ABSOLUTE_PATH (prefix))
  2253. fatal_error (input_location, "system path %qs is not absolute", prefix);
  2254. if (target_system_root)
  2255. {
  2256. char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root);
  2257. size_t sysroot_len = strlen (target_system_root);
  2258. if (sysroot_len > 0
  2259. && target_system_root[sysroot_len - 1] == DIR_SEPARATOR)
  2260. sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
  2261. if (target_sysroot_suffix)
  2262. prefix = concat (sysroot_no_trailing_dir_separator,
  2263. target_sysroot_suffix, prefix, NULL);
  2264. else
  2265. prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
  2266. free (sysroot_no_trailing_dir_separator);
  2267. /* We have to override this because GCC's notion of sysroot
  2268. moves along with GCC. */
  2269. component = "GCC";
  2270. }
  2271. add_prefix (pprefix, prefix, component, priority,
  2272. require_machine_suffix, os_multilib);
  2273. }
  2274. /* Execute the command specified by the arguments on the current line of spec.
  2275. When using pipes, this includes several piped-together commands
  2276. with `|' between them.
  2277. Return 0 if successful, -1 if failed. */
  2278. static int
  2279. execute (void)
  2280. {
  2281. int i;
  2282. int n_commands; /* # of command. */
  2283. char *string;
  2284. struct pex_obj *pex;
  2285. struct command
  2286. {
  2287. const char *prog; /* program name. */
  2288. const char **argv; /* vector of args. */
  2289. };
  2290. const char *arg;
  2291. struct command *commands; /* each command buffer with above info. */
  2292. gcc_assert (!processing_spec_function);
  2293. if (wrapper_string)
  2294. {
  2295. string = find_a_file (&exec_prefixes,
  2296. argbuf[0], X_OK, false);
  2297. if (string)
  2298. argbuf[0] = string;
  2299. insert_wrapper (wrapper_string);
  2300. }
  2301. /* Count # of piped commands. */
  2302. for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)
  2303. if (strcmp (arg, "|") == 0)
  2304. n_commands++;
  2305. /* Get storage for each command. */
  2306. commands = (struct command *) alloca (n_commands * sizeof (struct command));
  2307. /* Split argbuf into its separate piped processes,
  2308. and record info about each one.
  2309. Also search for the programs that are to be run. */
  2310. argbuf.safe_push (0);
  2311. commands[0].prog = argbuf[0]; /* first command. */
  2312. commands[0].argv = argbuf.address ();
  2313. if (!wrapper_string)
  2314. {
  2315. string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false);
  2316. commands[0].argv[0] = (string) ? string : commands[0].argv[0];
  2317. }
  2318. for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)
  2319. if (arg && strcmp (arg, "|") == 0)
  2320. { /* each command. */
  2321. #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
  2322. fatal_error (input_location, "-pipe not supported");
  2323. #endif
  2324. argbuf[i] = 0; /* Termination of
  2325. command args. */
  2326. commands[n_commands].prog = argbuf[i + 1];
  2327. commands[n_commands].argv
  2328. = &(argbuf.address ())[i + 1];
  2329. string = find_a_file (&exec_prefixes, commands[n_commands].prog,
  2330. X_OK, false);
  2331. if (string)
  2332. commands[n_commands].argv[0] = string;
  2333. n_commands++;
  2334. }
  2335. /* If -v, print what we are about to do, and maybe query. */
  2336. if (verbose_flag)
  2337. {
  2338. /* For help listings, put a blank line between sub-processes. */
  2339. if (print_help_list)
  2340. fputc ('\n', stderr);
  2341. /* Print each piped command as a separate line. */
  2342. for (i = 0; i < n_commands; i++)
  2343. {
  2344. const char *const *j;
  2345. if (verbose_only_flag)
  2346. {
  2347. for (j = commands[i].argv; *j; j++)
  2348. {
  2349. const char *p;
  2350. for (p = *j; *p; ++p)
  2351. if (!ISALNUM ((unsigned char) *p)
  2352. && *p != '_' && *p != '/' && *p != '-' && *p != '.')
  2353. break;
  2354. if (*p || !*j)
  2355. {
  2356. fprintf (stderr, " \"");
  2357. for (p = *j; *p; ++p)
  2358. {
  2359. if (*p == '"' || *p == '\\' || *p == '$')
  2360. fputc ('\\', stderr);
  2361. fputc (*p, stderr);
  2362. }
  2363. fputc ('"', stderr);
  2364. }
  2365. /* If it's empty, print "". */
  2366. else if (!**j)
  2367. fprintf (stderr, " \"\"");
  2368. else
  2369. fprintf (stderr, " %s", *j);
  2370. }
  2371. }
  2372. else
  2373. for (j = commands[i].argv; *j; j++)
  2374. /* If it's empty, print "". */
  2375. if (!**j)
  2376. fprintf (stderr, " \"\"");
  2377. else
  2378. fprintf (stderr, " %s", *j);
  2379. /* Print a pipe symbol after all but the last command. */
  2380. if (i + 1 != n_commands)
  2381. fprintf (stderr, " |");
  2382. fprintf (stderr, "\n");
  2383. }
  2384. fflush (stderr);
  2385. if (verbose_only_flag != 0)
  2386. {
  2387. /* verbose_only_flag should act as if the spec was
  2388. executed, so increment execution_count before
  2389. returning. This prevents spurious warnings about
  2390. unused linker input files, etc. */
  2391. execution_count++;
  2392. return 0;
  2393. }
  2394. #ifdef DEBUG
  2395. fnotice (stderr, "\nGo ahead? (y or n) ");
  2396. fflush (stderr);
  2397. i = getchar ();
  2398. if (i != '\n')
  2399. while (getchar () != '\n')
  2400. ;
  2401. if (i != 'y' && i != 'Y')
  2402. return 0;
  2403. #endif /* DEBUG */
  2404. }
  2405. #ifdef ENABLE_VALGRIND_CHECKING
  2406. /* Run the each command through valgrind. To simplify prepending the
  2407. path to valgrind and the option "-q" (for quiet operation unless
  2408. something triggers), we allocate a separate argv array. */
  2409. for (i = 0; i < n_commands; i++)
  2410. {
  2411. const char **argv;
  2412. int argc;
  2413. int j;
  2414. for (argc = 0; commands[i].argv[argc] != NULL; argc++)
  2415. ;
  2416. argv = XALLOCAVEC (const char *, argc + 3);
  2417. argv[0] = VALGRIND_PATH;
  2418. argv[1] = "-q";
  2419. for (j = 2; j < argc + 2; j++)
  2420. argv[j] = commands[i].argv[j - 2];
  2421. argv[j] = NULL;
  2422. commands[i].argv = argv;
  2423. commands[i].prog = argv[0];
  2424. }
  2425. #endif
  2426. /* Run each piped subprocess. */
  2427. pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file)
  2428. ? PEX_RECORD_TIMES : 0),
  2429. progname, temp_filename);
  2430. if (pex == NULL)
  2431. fatal_error (input_location, "pex_init failed: %m");
  2432. for (i = 0; i < n_commands; i++)
  2433. {
  2434. const char *errmsg;
  2435. int err;
  2436. const char *string = commands[i].argv[0];
  2437. errmsg = pex_run (pex,
  2438. ((i + 1 == n_commands ? PEX_LAST : 0)
  2439. | (string == commands[i].prog ? PEX_SEARCH : 0)),
  2440. string, CONST_CAST (char **, commands[i].argv),
  2441. NULL, NULL, &err);
  2442. if (errmsg != NULL)
  2443. {
  2444. if (err == 0)
  2445. fatal_error (input_location, errmsg);
  2446. else
  2447. {
  2448. errno = err;
  2449. pfatal_with_name (errmsg);
  2450. }
  2451. }
  2452. if (i && string != commands[i].prog)
  2453. free (CONST_CAST (char *, string));
  2454. }
  2455. execution_count++;
  2456. /* Wait for all the subprocesses to finish. */
  2457. {
  2458. int *statuses;
  2459. struct pex_time *times = NULL;
  2460. int ret_code = 0;
  2461. statuses = (int *) alloca (n_commands * sizeof (int));
  2462. if (!pex_get_status (pex, n_commands, statuses))
  2463. fatal_error (input_location, "failed to get exit status: %m");
  2464. if (report_times || report_times_to_file)
  2465. {
  2466. times = (struct pex_time *) alloca (n_commands * sizeof (struct pex_time));
  2467. if (!pex_get_times (pex, n_commands, times))
  2468. fatal_error (input_location, "failed to get process times: %m");
  2469. }
  2470. pex_free (pex);
  2471. for (i = 0; i < n_commands; ++i)
  2472. {
  2473. int status = statuses[i];
  2474. if (WIFSIGNALED (status))
  2475. {
  2476. #ifdef SIGPIPE
  2477. /* SIGPIPE is a special case. It happens in -pipe mode
  2478. when the compiler dies before the preprocessor is done,
  2479. or the assembler dies before the compiler is done.
  2480. There's generally been an error already, and this is
  2481. just fallout. So don't generate another error unless
  2482. we would otherwise have succeeded. */
  2483. if (WTERMSIG (status) == SIGPIPE
  2484. && (signal_count || greatest_status >= MIN_FATAL_STATUS))
  2485. {
  2486. signal_count++;
  2487. ret_code = -1;
  2488. }
  2489. else
  2490. #endif
  2491. internal_error_no_backtrace ("%s (program %s)",
  2492. strsignal (WTERMSIG (status)),
  2493. commands[i].prog);
  2494. }
  2495. else if (WIFEXITED (status)
  2496. && WEXITSTATUS (status) >= MIN_FATAL_STATUS)
  2497. {
  2498. /* For ICEs in cc1, cc1obj, cc1plus see if it is
  2499. reproducible or not. */
  2500. const char *p;
  2501. if (flag_report_bug
  2502. && WEXITSTATUS (status) == ICE_EXIT_CODE
  2503. && i == 0
  2504. && (p = strrchr (commands[0].argv[0], DIR_SEPARATOR))
  2505. && ! strncmp (p + 1, "cc1", 3))
  2506. try_generate_repro (commands[0].argv);
  2507. if (WEXITSTATUS (status) > greatest_status)
  2508. greatest_status = WEXITSTATUS (status);
  2509. ret_code = -1;
  2510. }
  2511. if (report_times || report_times_to_file)
  2512. {
  2513. struct pex_time *pt = &times[i];
  2514. double ut, st;
  2515. ut = ((double) pt->user_seconds
  2516. + (double) pt->user_microseconds / 1.0e6);
  2517. st = ((double) pt->system_seconds
  2518. + (double) pt->system_microseconds / 1.0e6);
  2519. if (ut + st != 0)
  2520. {
  2521. if (report_times)
  2522. fnotice (stderr, "# %s %.2f %.2f\n",
  2523. commands[i].prog, ut, st);
  2524. if (report_times_to_file)
  2525. {
  2526. int c = 0;
  2527. const char *const *j;
  2528. fprintf (report_times_to_file, "%g %g", ut, st);
  2529. for (j = &commands[i].prog; *j; j = &commands[i].argv[++c])
  2530. {
  2531. const char *p;
  2532. for (p = *j; *p; ++p)
  2533. if (*p == '"' || *p == '\\' || *p == '$'
  2534. || ISSPACE (*p))
  2535. break;
  2536. if (*p)
  2537. {
  2538. fprintf (report_times_to_file, " \"");
  2539. for (p = *j; *p; ++p)
  2540. {
  2541. if (*p == '"' || *p == '\\' || *p == '$')
  2542. fputc ('\\', report_times_to_file);
  2543. fputc (*p, report_times_to_file);
  2544. }
  2545. fputc ('"', report_times_to_file);
  2546. }
  2547. else
  2548. fprintf (report_times_to_file, " %s", *j);
  2549. }
  2550. fputc ('\n', report_times_to_file);
  2551. }
  2552. }
  2553. }
  2554. }
  2555. if (commands[0].argv[0] != commands[0].prog)
  2556. free (CONST_CAST (char *, commands[0].argv[0]));
  2557. return ret_code;
  2558. }
  2559. }
  2560. /* Find all the switches given to us
  2561. and make a vector describing them.
  2562. The elements of the vector are strings, one per switch given.
  2563. If a switch uses following arguments, then the `part1' field
  2564. is the switch itself and the `args' field
  2565. is a null-terminated vector containing the following arguments.
  2566. Bits in the `live_cond' field are:
  2567. SWITCH_LIVE to indicate this switch is true in a conditional spec.
  2568. SWITCH_FALSE to indicate this switch is overridden by a later switch.
  2569. SWITCH_IGNORE to indicate this switch should be ignored (used in %<S).
  2570. SWITCH_IGNORE_PERMANENTLY to indicate this switch should be ignored
  2571. in all do_spec calls afterwards. Used for %<S from self specs.
  2572. The `validated' field is nonzero if any spec has looked at this switch;
  2573. if it remains zero at the end of the run, it must be meaningless. */
  2574. #define SWITCH_LIVE (1 << 0)
  2575. #define SWITCH_FALSE (1 << 1)
  2576. #define SWITCH_IGNORE (1 << 2)
  2577. #define SWITCH_IGNORE_PERMANENTLY (1 << 3)
  2578. #define SWITCH_KEEP_FOR_GCC (1 << 4)
  2579. struct switchstr
  2580. {
  2581. const char *part1;
  2582. const char **args;
  2583. unsigned int live_cond;
  2584. bool known;
  2585. bool validated;
  2586. bool ordering;
  2587. };
  2588. static struct switchstr *switches;
  2589. static int n_switches;
  2590. static int n_switches_alloc;
  2591. /* Set to zero if -fcompare-debug is disabled, positive if it's
  2592. enabled and we're running the first compilation, negative if it's
  2593. enabled and we're running the second compilation. For most of the
  2594. time, it's in the range -1..1, but it can be temporarily set to 2
  2595. or 3 to indicate that the -fcompare-debug flags didn't come from
  2596. the command-line, but rather from the GCC_COMPARE_DEBUG environment
  2597. variable, until a synthesized -fcompare-debug flag is added to the
  2598. command line. */
  2599. int compare_debug;
  2600. /* Set to nonzero if we've seen the -fcompare-debug-second flag. */
  2601. int compare_debug_second;
  2602. /* Set to the flags that should be passed to the second compilation in
  2603. a -fcompare-debug compilation. */
  2604. const char *compare_debug_opt;
  2605. static struct switchstr *switches_debug_check[2];
  2606. static int n_switches_debug_check[2];
  2607. static int n_switches_alloc_debug_check[2];
  2608. static char *debug_check_temp_file[2];
  2609. /* Language is one of three things:
  2610. 1) The name of a real programming language.
  2611. 2) NULL, indicating that no one has figured out
  2612. what it is yet.
  2613. 3) '*', indicating that the file should be passed
  2614. to the linker. */
  2615. struct infile
  2616. {
  2617. const char *name;
  2618. const char *language;
  2619. struct compiler *incompiler;
  2620. bool compiled;
  2621. bool preprocessed;
  2622. };
  2623. /* Also a vector of input files specified. */
  2624. static struct infile *infiles;
  2625. int n_infiles;
  2626. static int n_infiles_alloc;
  2627. /* True if multiple input files are being compiled to a single
  2628. assembly file. */
  2629. static bool combine_inputs;
  2630. /* This counts the number of libraries added by lang_specific_driver, so that
  2631. we can tell if there were any user supplied any files or libraries. */
  2632. static int added_libraries;
  2633. /* And a vector of corresponding output files is made up later. */
  2634. const char **outfiles;
  2635. #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
  2636. /* Convert NAME to a new name if it is the standard suffix. DO_EXE
  2637. is true if we should look for an executable suffix. DO_OBJ
  2638. is true if we should look for an object suffix. */
  2639. static const char *
  2640. convert_filename (const char *name, int do_exe ATTRIBUTE_UNUSED,
  2641. int do_obj ATTRIBUTE_UNUSED)
  2642. {
  2643. #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
  2644. int i;
  2645. #endif
  2646. int len;
  2647. if (name == NULL)
  2648. return NULL;
  2649. len = strlen (name);
  2650. #ifdef HAVE_TARGET_OBJECT_SUFFIX
  2651. /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */
  2652. if (do_obj && len > 2
  2653. && name[len - 2] == '.'
  2654. && name[len - 1] == 'o')
  2655. {
  2656. obstack_grow (&obstack, name, len - 2);
  2657. obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
  2658. name = XOBFINISH (&obstack, const char *);
  2659. }
  2660. #endif
  2661. #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX)
  2662. /* If there is no filetype, make it the executable suffix (which includes
  2663. the "."). But don't get confused if we have just "-o". */
  2664. if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || (len == 2 && name[0] == '-'))
  2665. return name;
  2666. for (i = len - 1; i >= 0; i--)
  2667. if (IS_DIR_SEPARATOR (name[i]))
  2668. break;
  2669. for (i++; i < len; i++)
  2670. if (name[i] == '.')
  2671. return name;
  2672. obstack_grow (&obstack, name, len);
  2673. obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
  2674. strlen (TARGET_EXECUTABLE_SUFFIX));
  2675. name = XOBFINISH (&obstack, const char *);
  2676. #endif
  2677. return name;
  2678. }
  2679. #endif
  2680. /* Display the command line switches accepted by gcc. */
  2681. static void
  2682. display_help (void)
  2683. {
  2684. printf (_("Usage: %s [options] file...\n"), progname);
  2685. fputs (_("Options:\n"), stdout);
  2686. fputs (_(" -pass-exit-codes Exit with highest error code from a phase\n"), stdout);
  2687. fputs (_(" --help Display this information\n"), stdout);
  2688. fputs (_(" --target-help Display target specific command line options\n"), stdout);
  2689. fputs (_(" --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]\n"), stdout);
  2690. fputs (_(" Display specific types of command line options\n"), stdout);
  2691. if (! verbose_flag)
  2692. fputs (_(" (Use '-v --help' to display command line options of sub-processes)\n"), stdout);
  2693. fputs (_(" --version Display compiler version information\n"), stdout);
  2694. fputs (_(" -dumpspecs Display all of the built in spec strings\n"), stdout);
  2695. fputs (_(" -dumpversion Display the version of the compiler\n"), stdout);
  2696. fputs (_(" -dumpmachine Display the compiler's target processor\n"), stdout);
  2697. fputs (_(" -print-search-dirs Display the directories in the compiler's search path\n"), stdout);
  2698. fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library\n"), stdout);
  2699. fputs (_(" -print-file-name=<lib> Display the full path to library <lib>\n"), stdout);
  2700. fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>\n"), stdout);
  2701. fputs (_("\
  2702. -print-multiarch Display the target's normalized GNU triplet, used as\n\
  2703. a component in the library path\n"), stdout);
  2704. fputs (_(" -print-multi-directory Display the root directory for versions of libgcc\n"), stdout);
  2705. fputs (_("\
  2706. -print-multi-lib Display the mapping between command line options and\n\
  2707. multiple library search directories\n"), stdout);
  2708. fputs (_(" -print-multi-os-directory Display the relative path to OS libraries\n"), stdout);
  2709. fputs (_(" -print-sysroot Display the target libraries directory\n"), stdout);
  2710. fputs (_(" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers\n"), stdout);
  2711. fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler\n"), stdout);
  2712. fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor\n"), stdout);
  2713. fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker\n"), stdout);
  2714. fputs (_(" -Xassembler <arg> Pass <arg> on to the assembler\n"), stdout);
  2715. fputs (_(" -Xpreprocessor <arg> Pass <arg> on to the preprocessor\n"), stdout);
  2716. fputs (_(" -Xlinker <arg> Pass <arg> on to the linker\n"), stdout);
  2717. fputs (_(" -save-temps Do not delete intermediate files\n"), stdout);
  2718. fputs (_(" -save-temps=<arg> Do not delete intermediate files\n"), stdout);
  2719. fputs (_("\
  2720. -no-canonical-prefixes Do not canonicalize paths when building relative\n\
  2721. prefixes to other gcc components\n"), stdout);
  2722. fputs (_(" -pipe Use pipes rather than intermediate files\n"), stdout);
  2723. fputs (_(" -time Time the execution of each subprocess\n"), stdout);
  2724. fputs (_(" -specs=<file> Override built-in specs with the contents of <file>\n"), stdout);
  2725. fputs (_(" -std=<standard> Assume that the input sources are for <standard>\n"), stdout);
  2726. fputs (_("\
  2727. --sysroot=<directory> Use <directory> as the root directory for headers\n\
  2728. and libraries\n"), stdout);
  2729. fputs (_(" -B <directory> Add <directory> to the compiler's search paths\n"), stdout);
  2730. fputs (_(" -v Display the programs invoked by the compiler\n"), stdout);
  2731. fputs (_(" -### Like -v but options quoted and commands not executed\n"), stdout);
  2732. fputs (_(" -E Preprocess only; do not compile, assemble or link\n"), stdout);
  2733. fputs (_(" -S Compile only; do not assemble or link\n"), stdout);
  2734. fputs (_(" -c Compile and assemble, but do not link\n"), stdout);
  2735. fputs (_(" -o <file> Place the output into <file>\n"), stdout);
  2736. fputs (_(" -pie Create a position independent executable\n"), stdout);
  2737. fputs (_(" -shared Create a shared library\n"), stdout);
  2738. fputs (_("\
  2739. -x <language> Specify the language of the following input files\n\
  2740. Permissible languages include: c c++ assembler none\n\
  2741. 'none' means revert to the default behavior of\n\
  2742. guessing the language based on the file's extension\n\
  2743. "), stdout);
  2744. printf (_("\
  2745. \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\
  2746. passed on to the various sub-processes invoked by %s. In order to pass\n\
  2747. other options on to these processes the -W<letter> options must be used.\n\
  2748. "), progname);
  2749. /* The rest of the options are displayed by invocations of the various
  2750. sub-processes. */
  2751. }
  2752. static void
  2753. add_preprocessor_option (const char *option, int len)
  2754. {
  2755. preprocessor_options.safe_push (save_string (option, len));
  2756. }
  2757. static void
  2758. add_assembler_option (const char *option, int len)
  2759. {
  2760. assembler_options.safe_push (save_string (option, len));
  2761. }
  2762. static void
  2763. add_linker_option (const char *option, int len)
  2764. {
  2765. linker_options.safe_push (save_string (option, len));
  2766. }
  2767. /* Allocate space for an input file in infiles. */
  2768. static void
  2769. alloc_infile (void)
  2770. {
  2771. if (n_infiles_alloc == 0)
  2772. {
  2773. n_infiles_alloc = 16;
  2774. infiles = XNEWVEC (struct infile, n_infiles_alloc);
  2775. }
  2776. else if (n_infiles_alloc == n_infiles)
  2777. {
  2778. n_infiles_alloc *= 2;
  2779. infiles = XRESIZEVEC (struct infile, infiles, n_infiles_alloc);
  2780. }
  2781. }
  2782. /* Store an input file with the given NAME and LANGUAGE in
  2783. infiles. */
  2784. static void
  2785. add_infile (const char *name, const char *language)
  2786. {
  2787. alloc_infile ();
  2788. infiles[n_infiles].name = name;
  2789. infiles[n_infiles++].language = language;
  2790. }
  2791. /* Allocate space for a switch in switches. */
  2792. static void
  2793. alloc_switch (void)
  2794. {
  2795. if (n_switches_alloc == 0)
  2796. {
  2797. n_switches_alloc = 16;
  2798. switches = XNEWVEC (struct switchstr, n_switches_alloc);
  2799. }
  2800. else if (n_switches_alloc == n_switches)
  2801. {
  2802. n_switches_alloc *= 2;
  2803. switches = XRESIZEVEC (struct switchstr, switches, n_switches_alloc);
  2804. }
  2805. }
  2806. /* Save an option OPT with N_ARGS arguments in array ARGS, marking it
  2807. as validated if VALIDATED and KNOWN if it is an internal switch. */
  2808. static void
  2809. save_switch (const char *opt, size_t n_args, const char *const *args,
  2810. bool validated, bool known)
  2811. {
  2812. alloc_switch ();
  2813. switches[n_switches].part1 = opt + 1;
  2814. if (n_args == 0)
  2815. switches[n_switches].args = 0;
  2816. else
  2817. {
  2818. switches[n_switches].args = XNEWVEC (const char *, n_args + 1);
  2819. memcpy (switches[n_switches].args, args, n_args * sizeof (const char *));
  2820. switches[n_switches].args[n_args] = NULL;
  2821. }
  2822. switches[n_switches].live_cond = 0;
  2823. switches[n_switches].validated = validated;
  2824. switches[n_switches].known = known;
  2825. switches[n_switches].ordering = 0;
  2826. n_switches++;
  2827. }
  2828. /* Handle an option DECODED that is unknown to the option-processing
  2829. machinery. */
  2830. static bool
  2831. driver_unknown_option_callback (const struct cl_decoded_option *decoded)
  2832. {
  2833. const char *opt = decoded->arg;
  2834. if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-'
  2835. && !(decoded->errors & CL_ERR_NEGATIVE))
  2836. {
  2837. /* Leave unknown -Wno-* options for the compiler proper, to be
  2838. diagnosed only if there are warnings. */
  2839. save_switch (decoded->canonical_option[0],
  2840. decoded->canonical_option_num_elements - 1,
  2841. &decoded->canonical_option[1], false, true);
  2842. return false;
  2843. }
  2844. if (decoded->opt_index == OPT_SPECIAL_unknown)
  2845. {
  2846. /* Give it a chance to define it a a spec file. */
  2847. save_switch (decoded->canonical_option[0],
  2848. decoded->canonical_option_num_elements - 1,
  2849. &decoded->canonical_option[1], false, false);
  2850. return false;
  2851. }
  2852. else
  2853. return true;
  2854. }
  2855. /* Handle an option DECODED that is not marked as CL_DRIVER.
  2856. LANG_MASK will always be CL_DRIVER. */
  2857. static void
  2858. driver_wrong_lang_callback (const struct cl_decoded_option *decoded,
  2859. unsigned int lang_mask ATTRIBUTE_UNUSED)
  2860. {
  2861. /* At this point, non-driver options are accepted (and expected to
  2862. be passed down by specs) unless marked to be rejected by the
  2863. driver. Options to be rejected by the driver but accepted by the
  2864. compilers proper are treated just like completely unknown
  2865. options. */
  2866. const struct cl_option *option = &cl_options[decoded->opt_index];
  2867. if (option->cl_reject_driver)
  2868. error ("unrecognized command line option %qs",
  2869. decoded->orig_option_with_args_text);
  2870. else
  2871. save_switch (decoded->canonical_option[0],
  2872. decoded->canonical_option_num_elements - 1,
  2873. &decoded->canonical_option[1], false, true);
  2874. }
  2875. static const char *spec_lang = 0;
  2876. static int last_language_n_infiles;
  2877. /* Parse -foffload option argument. */
  2878. static void
  2879. handle_foffload_option (const char *arg)
  2880. {
  2881. const char *c, *cur, *n, *next, *end;
  2882. char *target;
  2883. /* If option argument starts with '-' then no target is specified and we
  2884. do not need to parse it. */
  2885. if (arg[0] == '-')
  2886. return;
  2887. end = strchr (arg, '=');
  2888. if (end == NULL)
  2889. end = strchr (arg, '\0');
  2890. cur = arg;
  2891. while (cur < end)
  2892. {
  2893. next = strchr (cur, ',');
  2894. if (next == NULL)
  2895. next = end;
  2896. next = (next > end) ? end : next;
  2897. target = XNEWVEC (char, next - cur + 1);
  2898. memcpy (target, cur, next - cur);
  2899. target[next - cur] = '\0';
  2900. /* If 'disable' is passed to the option, stop parsing the option and clean
  2901. the list of offload targets. */
  2902. if (strcmp (target, "disable") == 0)
  2903. {
  2904. free (offload_targets);
  2905. offload_targets = xstrdup ("");
  2906. break;
  2907. }
  2908. /* Check that GCC is configured to support the offload target. */
  2909. c = OFFLOAD_TARGETS;
  2910. while (c)
  2911. {
  2912. n = strchr (c, ',');
  2913. if (n == NULL)
  2914. n = strchr (c, '\0');
  2915. if (next - cur == n - c && strncmp (target, c, n - c) == 0)
  2916. break;
  2917. c = *n ? n + 1 : NULL;
  2918. }
  2919. if (!c)
  2920. fatal_error (input_location,
  2921. "GCC is not configured to support %s as offload target",
  2922. target);
  2923. if (!offload_targets)
  2924. {
  2925. offload_targets = target;
  2926. target = NULL;
  2927. }
  2928. else
  2929. {
  2930. /* Check that the target hasn't already presented in the list. */
  2931. c = offload_targets;
  2932. do
  2933. {
  2934. n = strchr (c, ':');
  2935. if (n == NULL)
  2936. n = strchr (c, '\0');
  2937. if (next - cur == n - c && strncmp (c, target, n - c) == 0)
  2938. break;
  2939. c = n + 1;
  2940. }
  2941. while (*n);
  2942. /* If duplicate is not found, append the target to the list. */
  2943. if (c > n)
  2944. {
  2945. size_t offload_targets_len = strlen (offload_targets);
  2946. offload_targets
  2947. = XRESIZEVEC (char, offload_targets,
  2948. offload_targets_len + next - cur + 2);
  2949. if (offload_targets_len)
  2950. offload_targets[offload_targets_len++] = ':';
  2951. memcpy (offload_targets + offload_targets_len, target, next - cur);
  2952. }
  2953. }
  2954. cur = next + 1;
  2955. XDELETEVEC (target);
  2956. }
  2957. }
  2958. /* Handle a driver option; arguments and return value as for
  2959. handle_option. */
  2960. static bool
  2961. driver_handle_option (struct gcc_options *opts,
  2962. struct gcc_options *opts_set,
  2963. const struct cl_decoded_option *decoded,
  2964. unsigned int lang_mask ATTRIBUTE_UNUSED, int kind,
  2965. location_t loc,
  2966. const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED,
  2967. diagnostic_context *dc)
  2968. {
  2969. size_t opt_index = decoded->opt_index;
  2970. const char *arg = decoded->arg;
  2971. const char *compare_debug_replacement_opt;
  2972. int value = decoded->value;
  2973. bool validated = false;
  2974. bool do_save = true;
  2975. gcc_assert (opts == &global_options);
  2976. gcc_assert (opts_set == &global_options_set);
  2977. gcc_assert (kind == DK_UNSPECIFIED);
  2978. gcc_assert (loc == UNKNOWN_LOCATION);
  2979. gcc_assert (dc == global_dc);
  2980. switch (opt_index)
  2981. {
  2982. case OPT_dumpspecs:
  2983. {
  2984. struct spec_list *sl;
  2985. init_spec ();
  2986. for (sl = specs; sl; sl = sl->next)
  2987. printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
  2988. if (link_command_spec)
  2989. printf ("*link_command:\n%s\n\n", link_command_spec);
  2990. exit (0);
  2991. }
  2992. case OPT_dumpversion:
  2993. printf ("%s\n", spec_version);
  2994. exit (0);
  2995. case OPT_dumpmachine:
  2996. printf ("%s\n", spec_machine);
  2997. exit (0);
  2998. case OPT__version:
  2999. print_version = 1;
  3000. /* CPP driver cannot obtain switch from cc1_options. */
  3001. if (is_cpp_driver)
  3002. add_preprocessor_option ("--version", strlen ("--version"));
  3003. add_assembler_option ("--version", strlen ("--version"));
  3004. add_linker_option ("--version", strlen ("--version"));
  3005. break;
  3006. case OPT__help:
  3007. print_help_list = 1;
  3008. /* CPP driver cannot obtain switch from cc1_options. */
  3009. if (is_cpp_driver)
  3010. add_preprocessor_option ("--help", 6);
  3011. add_assembler_option ("--help", 6);
  3012. add_linker_option ("--help", 6);
  3013. break;
  3014. case OPT__help_:
  3015. print_subprocess_help = 2;
  3016. break;
  3017. case OPT__target_help:
  3018. print_subprocess_help = 1;
  3019. /* CPP driver cannot obtain switch from cc1_options. */
  3020. if (is_cpp_driver)
  3021. add_preprocessor_option ("--target-help", 13);
  3022. add_assembler_option ("--target-help", 13);
  3023. add_linker_option ("--target-help", 13);
  3024. break;
  3025. case OPT__no_sysroot_suffix:
  3026. case OPT_pass_exit_codes:
  3027. case OPT_print_search_dirs:
  3028. case OPT_print_file_name_:
  3029. case OPT_print_prog_name_:
  3030. case OPT_print_multi_lib:
  3031. case OPT_print_multi_directory:
  3032. case OPT_print_sysroot:
  3033. case OPT_print_multi_os_directory:
  3034. case OPT_print_multiarch:
  3035. case OPT_print_sysroot_headers_suffix:
  3036. case OPT_time:
  3037. case OPT_wrapper:
  3038. /* These options set the variables specified in common.opt
  3039. automatically, and do not need to be saved for spec
  3040. processing. */
  3041. do_save = false;
  3042. break;
  3043. case OPT_print_libgcc_file_name:
  3044. print_file_name = "libgcc.a";
  3045. do_save = false;
  3046. break;
  3047. case OPT_fuse_ld_bfd:
  3048. use_ld = ".bfd";
  3049. break;
  3050. case OPT_fuse_ld_gold:
  3051. use_ld = ".gold";
  3052. break;
  3053. case OPT_fcompare_debug_second:
  3054. compare_debug_second = 1;
  3055. break;
  3056. case OPT_fcompare_debug:
  3057. switch (value)
  3058. {
  3059. case 0:
  3060. compare_debug_replacement_opt = "-fcompare-debug=";
  3061. arg = "";
  3062. goto compare_debug_with_arg;
  3063. case 1:
  3064. compare_debug_replacement_opt = "-fcompare-debug=-gtoggle";
  3065. arg = "-gtoggle";
  3066. goto compare_debug_with_arg;
  3067. default:
  3068. gcc_unreachable ();
  3069. }
  3070. break;
  3071. case OPT_fcompare_debug_:
  3072. compare_debug_replacement_opt = decoded->canonical_option[0];
  3073. compare_debug_with_arg:
  3074. gcc_assert (decoded->canonical_option_num_elements == 1);
  3075. gcc_assert (arg != NULL);
  3076. if (*arg)
  3077. compare_debug = 1;
  3078. else
  3079. compare_debug = -1;
  3080. if (compare_debug < 0)
  3081. compare_debug_opt = NULL;
  3082. else
  3083. compare_debug_opt = arg;
  3084. save_switch (compare_debug_replacement_opt, 0, NULL, validated, true);
  3085. return true;
  3086. case OPT_fdiagnostics_color_:
  3087. diagnostic_color_init (dc, value);
  3088. break;
  3089. case OPT_Wa_:
  3090. {
  3091. int prev, j;
  3092. /* Pass the rest of this option to the assembler. */
  3093. /* Split the argument at commas. */
  3094. prev = 0;
  3095. for (j = 0; arg[j]; j++)
  3096. if (arg[j] == ',')
  3097. {
  3098. add_assembler_option (arg + prev, j - prev);
  3099. prev = j + 1;
  3100. }
  3101. /* Record the part after the last comma. */
  3102. add_assembler_option (arg + prev, j - prev);
  3103. }
  3104. do_save = false;
  3105. break;
  3106. case OPT_Wp_:
  3107. {
  3108. int prev, j;
  3109. /* Pass the rest of this option to the preprocessor. */
  3110. /* Split the argument at commas. */
  3111. prev = 0;
  3112. for (j = 0; arg[j]; j++)
  3113. if (arg[j] == ',')
  3114. {
  3115. add_preprocessor_option (arg + prev, j - prev);
  3116. prev = j + 1;
  3117. }
  3118. /* Record the part after the last comma. */
  3119. add_preprocessor_option (arg + prev, j - prev);
  3120. }
  3121. do_save = false;
  3122. break;
  3123. case OPT_Wl_:
  3124. {
  3125. int prev, j;
  3126. /* Split the argument at commas. */
  3127. prev = 0;
  3128. for (j = 0; arg[j]; j++)
  3129. if (arg[j] == ',')
  3130. {
  3131. add_infile (save_string (arg + prev, j - prev), "*");
  3132. prev = j + 1;
  3133. }
  3134. /* Record the part after the last comma. */
  3135. add_infile (arg + prev, "*");
  3136. }
  3137. do_save = false;
  3138. break;
  3139. case OPT_Xlinker:
  3140. add_infile (arg, "*");
  3141. do_save = false;
  3142. break;
  3143. case OPT_Xpreprocessor:
  3144. add_preprocessor_option (arg, strlen (arg));
  3145. do_save = false;
  3146. break;
  3147. case OPT_Xassembler:
  3148. add_assembler_option (arg, strlen (arg));
  3149. do_save = false;
  3150. break;
  3151. case OPT_l:
  3152. /* POSIX allows separation of -l and the lib arg; canonicalize
  3153. by concatenating -l with its arg */
  3154. add_infile (concat ("-l", arg, NULL), "*");
  3155. do_save = false;
  3156. break;
  3157. case OPT_L:
  3158. /* Similarly, canonicalize -L for linkers that may not accept
  3159. separate arguments. */
  3160. save_switch (concat ("-L", arg, NULL), 0, NULL, validated, true);
  3161. return true;
  3162. case OPT_F:
  3163. /* Likewise -F. */
  3164. save_switch (concat ("-F", arg, NULL), 0, NULL, validated, true);
  3165. return true;
  3166. case OPT_save_temps:
  3167. save_temps_flag = SAVE_TEMPS_CWD;
  3168. validated = true;
  3169. break;
  3170. case OPT_save_temps_:
  3171. if (strcmp (arg, "cwd") == 0)
  3172. save_temps_flag = SAVE_TEMPS_CWD;
  3173. else if (strcmp (arg, "obj") == 0
  3174. || strcmp (arg, "object") == 0)
  3175. save_temps_flag = SAVE_TEMPS_OBJ;
  3176. else
  3177. fatal_error (input_location, "%qs is an unknown -save-temps option",
  3178. decoded->orig_option_with_args_text);
  3179. break;
  3180. case OPT_no_canonical_prefixes:
  3181. /* Already handled as a special case, so ignored here. */
  3182. do_save = false;
  3183. break;
  3184. case OPT_pipe:
  3185. validated = true;
  3186. /* These options set the variables specified in common.opt
  3187. automatically, but do need to be saved for spec
  3188. processing. */
  3189. break;
  3190. case OPT_specs_:
  3191. {
  3192. struct user_specs *user = XNEW (struct user_specs);
  3193. user->next = (struct user_specs *) 0;
  3194. user->filename = arg;
  3195. if (user_specs_tail)
  3196. user_specs_tail->next = user;
  3197. else
  3198. user_specs_head = user;
  3199. user_specs_tail = user;
  3200. }
  3201. validated = true;
  3202. break;
  3203. case OPT__sysroot_:
  3204. target_system_root = arg;
  3205. target_system_root_changed = 1;
  3206. do_save = false;
  3207. break;
  3208. case OPT_time_:
  3209. if (report_times_to_file)
  3210. fclose (report_times_to_file);
  3211. report_times_to_file = fopen (arg, "a");
  3212. do_save = false;
  3213. break;
  3214. case OPT____:
  3215. /* "-###"
  3216. This is similar to -v except that there is no execution
  3217. of the commands and the echoed arguments are quoted. It
  3218. is intended for use in shell scripts to capture the
  3219. driver-generated command line. */
  3220. verbose_only_flag++;
  3221. verbose_flag = 1;
  3222. do_save = false;
  3223. break;
  3224. case OPT_B:
  3225. {
  3226. size_t len = strlen (arg);
  3227. /* Catch the case where the user has forgotten to append a
  3228. directory separator to the path. Note, they may be using
  3229. -B to add an executable name prefix, eg "i386-elf-", in
  3230. order to distinguish between multiple installations of
  3231. GCC in the same directory. Hence we must check to see
  3232. if appending a directory separator actually makes a
  3233. valid directory name. */
  3234. if (!IS_DIR_SEPARATOR (arg[len - 1])
  3235. && is_directory (arg, false))
  3236. {
  3237. char *tmp = XNEWVEC (char, len + 2);
  3238. strcpy (tmp, arg);
  3239. tmp[len] = DIR_SEPARATOR;
  3240. tmp[++len] = 0;
  3241. arg = tmp;
  3242. }
  3243. add_prefix (&exec_prefixes, arg, NULL,
  3244. PREFIX_PRIORITY_B_OPT, 0, 0);
  3245. add_prefix (&startfile_prefixes, arg, NULL,
  3246. PREFIX_PRIORITY_B_OPT, 0, 0);
  3247. add_prefix (&include_prefixes, arg, NULL,
  3248. PREFIX_PRIORITY_B_OPT, 0, 0);
  3249. }
  3250. validated = true;
  3251. break;
  3252. case OPT_x:
  3253. spec_lang = arg;
  3254. if (!strcmp (spec_lang, "none"))
  3255. /* Suppress the warning if -xnone comes after the last input
  3256. file, because alternate command interfaces like g++ might
  3257. find it useful to place -xnone after each input file. */
  3258. spec_lang = 0;
  3259. else
  3260. last_language_n_infiles = n_infiles;
  3261. do_save = false;
  3262. break;
  3263. case OPT_o:
  3264. have_o = 1;
  3265. #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX)
  3266. arg = convert_filename (arg, ! have_c, 0);
  3267. #endif
  3268. output_file = arg;
  3269. /* Save the output name in case -save-temps=obj was used. */
  3270. save_temps_prefix = xstrdup (arg);
  3271. /* On some systems, ld cannot handle "-o" without a space. So
  3272. split the option from its argument. */
  3273. save_switch ("-o", 1, &arg, validated, true);
  3274. return true;
  3275. case OPT_static_libgcc:
  3276. case OPT_shared_libgcc:
  3277. case OPT_static_libgfortran:
  3278. case OPT_static_libstdc__:
  3279. /* These are always valid, since gcc.c itself understands the
  3280. first two, gfortranspec.c understands -static-libgfortran and
  3281. g++spec.c understands -static-libstdc++ */
  3282. validated = true;
  3283. break;
  3284. case OPT_fwpa:
  3285. flag_wpa = "";
  3286. break;
  3287. case OPT_foffload_:
  3288. handle_foffload_option (arg);
  3289. break;
  3290. default:
  3291. /* Various driver options need no special processing at this
  3292. point, having been handled in a prescan above or being
  3293. handled by specs. */
  3294. break;
  3295. }
  3296. if (do_save)
  3297. save_switch (decoded->canonical_option[0],
  3298. decoded->canonical_option_num_elements - 1,
  3299. &decoded->canonical_option[1], validated, true);
  3300. return true;
  3301. }
  3302. /* Put the driver's standard set of option handlers in *HANDLERS. */
  3303. static void
  3304. set_option_handlers (struct cl_option_handlers *handlers)
  3305. {
  3306. handlers->unknown_option_callback = driver_unknown_option_callback;
  3307. handlers->wrong_lang_callback = driver_wrong_lang_callback;
  3308. handlers->num_handlers = 3;
  3309. handlers->handlers[0].handler = driver_handle_option;
  3310. handlers->handlers[0].mask = CL_DRIVER;
  3311. handlers->handlers[1].handler = common_handle_option;
  3312. handlers->handlers[1].mask = CL_COMMON;
  3313. handlers->handlers[2].handler = target_handle_option;
  3314. handlers->handlers[2].mask = CL_TARGET;
  3315. }
  3316. /* Create the vector `switches' and its contents.
  3317. Store its length in `n_switches'. */
  3318. static void
  3319. process_command (unsigned int decoded_options_count,
  3320. struct cl_decoded_option *decoded_options)
  3321. {
  3322. const char *temp;
  3323. char *temp1;
  3324. char *tooldir_prefix, *tooldir_prefix2;
  3325. char *(*get_relative_prefix) (const char *, const char *,
  3326. const char *) = NULL;
  3327. struct cl_option_handlers handlers;
  3328. unsigned int j;
  3329. gcc_exec_prefix = getenv ("GCC_EXEC_PREFIX");
  3330. n_switches = 0;
  3331. n_infiles = 0;
  3332. added_libraries = 0;
  3333. /* Figure compiler version from version string. */
  3334. compiler_version = temp1 = xstrdup (version_string);
  3335. for (; *temp1; ++temp1)
  3336. {
  3337. if (*temp1 == ' ')
  3338. {
  3339. *temp1 = '\0';
  3340. break;
  3341. }
  3342. }
  3343. /* Handle any -no-canonical-prefixes flag early, to assign the function
  3344. that builds relative prefixes. This function creates default search
  3345. paths that are needed later in normal option handling. */
  3346. for (j = 1; j < decoded_options_count; j++)
  3347. {
  3348. if (decoded_options[j].opt_index == OPT_no_canonical_prefixes)
  3349. {
  3350. get_relative_prefix = make_relative_prefix_ignore_links;
  3351. break;
  3352. }
  3353. }
  3354. if (! get_relative_prefix)
  3355. get_relative_prefix = make_relative_prefix;
  3356. /* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
  3357. see if we can create it from the pathname specified in
  3358. decoded_options[0].arg. */
  3359. gcc_libexec_prefix = standard_libexec_prefix;
  3360. #ifndef VMS
  3361. /* FIXME: make_relative_prefix doesn't yet work for VMS. */
  3362. if (!gcc_exec_prefix)
  3363. {
  3364. gcc_exec_prefix = get_relative_prefix (decoded_options[0].arg,
  3365. standard_bindir_prefix,
  3366. standard_exec_prefix);
  3367. gcc_libexec_prefix = get_relative_prefix (decoded_options[0].arg,
  3368. standard_bindir_prefix,
  3369. standard_libexec_prefix);
  3370. if (gcc_exec_prefix)
  3371. xputenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
  3372. }
  3373. else
  3374. {
  3375. /* make_relative_prefix requires a program name, but
  3376. GCC_EXEC_PREFIX is typically a directory name with a trailing
  3377. / (which is ignored by make_relative_prefix), so append a
  3378. program name. */
  3379. char *tmp_prefix = concat (gcc_exec_prefix, "gcc", NULL);
  3380. gcc_libexec_prefix = get_relative_prefix (tmp_prefix,
  3381. standard_exec_prefix,
  3382. standard_libexec_prefix);
  3383. /* The path is unrelocated, so fallback to the original setting. */
  3384. if (!gcc_libexec_prefix)
  3385. gcc_libexec_prefix = standard_libexec_prefix;
  3386. free (tmp_prefix);
  3387. }
  3388. #else
  3389. #endif
  3390. /* From this point onward, gcc_exec_prefix is non-null if the toolchain
  3391. is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX
  3392. or an automatically created GCC_EXEC_PREFIX from
  3393. decoded_options[0].arg. */
  3394. /* Do language-specific adjustment/addition of flags. */
  3395. lang_specific_driver (&decoded_options, &decoded_options_count,
  3396. &added_libraries);
  3397. if (gcc_exec_prefix)
  3398. {
  3399. int len = strlen (gcc_exec_prefix);
  3400. if (len > (int) sizeof ("/lib/gcc/") - 1
  3401. && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1])))
  3402. {
  3403. temp = gcc_exec_prefix + len - sizeof ("/lib/gcc/") + 1;
  3404. if (IS_DIR_SEPARATOR (*temp)
  3405. && filename_ncmp (temp + 1, "lib", 3) == 0
  3406. && IS_DIR_SEPARATOR (temp[4])
  3407. && filename_ncmp (temp + 5, "gcc", 3) == 0)
  3408. len -= sizeof ("/lib/gcc/") - 1;
  3409. }
  3410. set_std_prefix (gcc_exec_prefix, len);
  3411. add_prefix (&exec_prefixes, gcc_libexec_prefix, "GCC",
  3412. PREFIX_PRIORITY_LAST, 0, 0);
  3413. add_prefix (&startfile_prefixes, gcc_exec_prefix, "GCC",
  3414. PREFIX_PRIORITY_LAST, 0, 0);
  3415. }
  3416. /* COMPILER_PATH and LIBRARY_PATH have values
  3417. that are lists of directory names with colons. */
  3418. temp = getenv ("COMPILER_PATH");
  3419. if (temp)
  3420. {
  3421. const char *startp, *endp;
  3422. char *nstore = (char *) alloca (strlen (temp) + 3);
  3423. startp = endp = temp;
  3424. while (1)
  3425. {
  3426. if (*endp == PATH_SEPARATOR || *endp == 0)
  3427. {
  3428. strncpy (nstore, startp, endp - startp);
  3429. if (endp == startp)
  3430. strcpy (nstore, concat (".", dir_separator_str, NULL));
  3431. else if (!IS_DIR_SEPARATOR (endp[-1]))
  3432. {
  3433. nstore[endp - startp] = DIR_SEPARATOR;
  3434. nstore[endp - startp + 1] = 0;
  3435. }
  3436. else
  3437. nstore[endp - startp] = 0;
  3438. add_prefix (&exec_prefixes, nstore, 0,
  3439. PREFIX_PRIORITY_LAST, 0, 0);
  3440. add_prefix (&include_prefixes, nstore, 0,
  3441. PREFIX_PRIORITY_LAST, 0, 0);
  3442. if (*endp == 0)
  3443. break;
  3444. endp = startp = endp + 1;
  3445. }
  3446. else
  3447. endp++;
  3448. }
  3449. }
  3450. temp = getenv (LIBRARY_PATH_ENV);
  3451. if (temp && *cross_compile == '0')
  3452. {
  3453. const char *startp, *endp;
  3454. char *nstore = (char *) alloca (strlen (temp) + 3);
  3455. startp = endp = temp;
  3456. while (1)
  3457. {
  3458. if (*endp == PATH_SEPARATOR || *endp == 0)
  3459. {
  3460. strncpy (nstore, startp, endp - startp);
  3461. if (endp == startp)
  3462. strcpy (nstore, concat (".", dir_separator_str, NULL));
  3463. else if (!IS_DIR_SEPARATOR (endp[-1]))
  3464. {
  3465. nstore[endp - startp] = DIR_SEPARATOR;
  3466. nstore[endp - startp + 1] = 0;
  3467. }
  3468. else
  3469. nstore[endp - startp] = 0;
  3470. add_prefix (&startfile_prefixes, nstore, NULL,
  3471. PREFIX_PRIORITY_LAST, 0, 1);
  3472. if (*endp == 0)
  3473. break;
  3474. endp = startp = endp + 1;
  3475. }
  3476. else
  3477. endp++;
  3478. }
  3479. }
  3480. /* Use LPATH like LIBRARY_PATH (for the CMU build program). */
  3481. temp = getenv ("LPATH");
  3482. if (temp && *cross_compile == '0')
  3483. {
  3484. const char *startp, *endp;
  3485. char *nstore = (char *) alloca (strlen (temp) + 3);
  3486. startp = endp = temp;
  3487. while (1)
  3488. {
  3489. if (*endp == PATH_SEPARATOR || *endp == 0)
  3490. {
  3491. strncpy (nstore, startp, endp - startp);
  3492. if (endp == startp)
  3493. strcpy (nstore, concat (".", dir_separator_str, NULL));
  3494. else if (!IS_DIR_SEPARATOR (endp[-1]))
  3495. {
  3496. nstore[endp - startp] = DIR_SEPARATOR;
  3497. nstore[endp - startp + 1] = 0;
  3498. }
  3499. else
  3500. nstore[endp - startp] = 0;
  3501. add_prefix (&startfile_prefixes, nstore, NULL,
  3502. PREFIX_PRIORITY_LAST, 0, 1);
  3503. if (*endp == 0)
  3504. break;
  3505. endp = startp = endp + 1;
  3506. }
  3507. else
  3508. endp++;
  3509. }
  3510. }
  3511. /* Process the options and store input files and switches in their
  3512. vectors. */
  3513. last_language_n_infiles = -1;
  3514. set_option_handlers (&handlers);
  3515. for (j = 1; j < decoded_options_count; j++)
  3516. {
  3517. switch (decoded_options[j].opt_index)
  3518. {
  3519. case OPT_S:
  3520. case OPT_c:
  3521. case OPT_E:
  3522. have_c = 1;
  3523. break;
  3524. }
  3525. if (have_c)
  3526. break;
  3527. }
  3528. for (j = 1; j < decoded_options_count; j++)
  3529. {
  3530. if (decoded_options[j].opt_index == OPT_SPECIAL_input_file)
  3531. {
  3532. const char *arg = decoded_options[j].arg;
  3533. const char *p = strrchr (arg, '@');
  3534. char *fname;
  3535. long offset;
  3536. int consumed;
  3537. #ifdef HAVE_TARGET_OBJECT_SUFFIX
  3538. arg = convert_filename (arg, 0, access (arg, F_OK));
  3539. #endif
  3540. /* For LTO static archive support we handle input file
  3541. specifications that are composed of a filename and
  3542. an offset like FNAME@OFFSET. */
  3543. if (p
  3544. && p != arg
  3545. && sscanf (p, "@%li%n", &offset, &consumed) >= 1
  3546. && strlen (p) == (unsigned int)consumed)
  3547. {
  3548. fname = (char *)xmalloc (p - arg + 1);
  3549. memcpy (fname, arg, p - arg);
  3550. fname[p - arg] = '\0';
  3551. /* Only accept non-stdin and existing FNAME parts, otherwise
  3552. try with the full name. */
  3553. if (strcmp (fname, "-") == 0 || access (fname, F_OK) < 0)
  3554. {
  3555. free (fname);
  3556. fname = xstrdup (arg);
  3557. }
  3558. }
  3559. else
  3560. fname = xstrdup (arg);
  3561. if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0)
  3562. perror_with_name (fname);
  3563. else
  3564. add_infile (arg, spec_lang);
  3565. free (fname);
  3566. continue;
  3567. }
  3568. read_cmdline_option (&global_options, &global_options_set,
  3569. decoded_options + j, UNKNOWN_LOCATION,
  3570. CL_DRIVER, &handlers, global_dc);
  3571. }
  3572. if (output_file
  3573. && strcmp (output_file, "-") != 0
  3574. && strcmp (output_file, HOST_BIT_BUCKET) != 0)
  3575. {
  3576. int i;
  3577. for (i = 0; i < n_infiles; i++)
  3578. if ((!infiles[i].language || infiles[i].language[0] != '*')
  3579. && canonical_filename_eq (infiles[i].name, output_file))
  3580. fatal_error (input_location,
  3581. "input file %qs is the same as output file",
  3582. output_file);
  3583. }
  3584. /* If -save-temps=obj and -o name, create the prefix to use for %b.
  3585. Otherwise just make -save-temps=obj the same as -save-temps=cwd. */
  3586. if (save_temps_flag == SAVE_TEMPS_OBJ && save_temps_prefix != NULL)
  3587. {
  3588. save_temps_length = strlen (save_temps_prefix);
  3589. temp = strrchr (lbasename (save_temps_prefix), '.');
  3590. if (temp)
  3591. {
  3592. save_temps_length -= strlen (temp);
  3593. save_temps_prefix[save_temps_length] = '\0';
  3594. }
  3595. }
  3596. else if (save_temps_prefix != NULL)
  3597. {
  3598. free (save_temps_prefix);
  3599. save_temps_prefix = NULL;
  3600. }
  3601. if (save_temps_flag && use_pipes)
  3602. {
  3603. /* -save-temps overrides -pipe, so that temp files are produced */
  3604. if (save_temps_flag)
  3605. warning (0, "-pipe ignored because -save-temps specified");
  3606. use_pipes = 0;
  3607. }
  3608. if (!compare_debug)
  3609. {
  3610. const char *gcd = getenv ("GCC_COMPARE_DEBUG");
  3611. if (gcd && gcd[0] == '-')
  3612. {
  3613. compare_debug = 2;
  3614. compare_debug_opt = gcd;
  3615. }
  3616. else if (gcd && *gcd && strcmp (gcd, "0"))
  3617. {
  3618. compare_debug = 3;
  3619. compare_debug_opt = "-gtoggle";
  3620. }
  3621. }
  3622. else if (compare_debug < 0)
  3623. {
  3624. compare_debug = 0;
  3625. gcc_assert (!compare_debug_opt);
  3626. }
  3627. /* Set up the search paths. We add directories that we expect to
  3628. contain GNU Toolchain components before directories specified by
  3629. the machine description so that we will find GNU components (like
  3630. the GNU assembler) before those of the host system. */
  3631. /* If we don't know where the toolchain has been installed, use the
  3632. configured-in locations. */
  3633. if (!gcc_exec_prefix)
  3634. {
  3635. #ifndef OS2
  3636. add_prefix (&exec_prefixes, standard_libexec_prefix, "GCC",
  3637. PREFIX_PRIORITY_LAST, 1, 0);
  3638. add_prefix (&exec_prefixes, standard_libexec_prefix, "BINUTILS",
  3639. PREFIX_PRIORITY_LAST, 2, 0);
  3640. add_prefix (&exec_prefixes, standard_exec_prefix, "BINUTILS",
  3641. PREFIX_PRIORITY_LAST, 2, 0);
  3642. #endif
  3643. add_prefix (&startfile_prefixes, standard_exec_prefix, "BINUTILS",
  3644. PREFIX_PRIORITY_LAST, 1, 0);
  3645. }
  3646. gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix));
  3647. tooldir_prefix2 = concat (tooldir_base_prefix, spec_host_machine,
  3648. dir_separator_str, NULL);
  3649. /* Look for tools relative to the location from which the driver is
  3650. running, or, if that is not available, the configured prefix. */
  3651. tooldir_prefix
  3652. = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
  3653. spec_host_machine, dir_separator_str, spec_version,
  3654. accel_dir_suffix, dir_separator_str, tooldir_prefix2, NULL);
  3655. free (tooldir_prefix2);
  3656. add_prefix (&exec_prefixes,
  3657. concat (tooldir_prefix, "bin", dir_separator_str, NULL),
  3658. "BINUTILS", PREFIX_PRIORITY_LAST, 0, 0);
  3659. add_prefix (&startfile_prefixes,
  3660. concat (tooldir_prefix, "lib", dir_separator_str, NULL),
  3661. "BINUTILS", PREFIX_PRIORITY_LAST, 0, 1);
  3662. free (tooldir_prefix);
  3663. #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
  3664. /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
  3665. then consider it to relocate with the rest of the GCC installation
  3666. if GCC_EXEC_PREFIX is set.
  3667. ``make_relative_prefix'' is not compiled for VMS, so don't call it. */
  3668. if (target_system_root && !target_system_root_changed && gcc_exec_prefix)
  3669. {
  3670. char *tmp_prefix = get_relative_prefix (decoded_options[0].arg,
  3671. standard_bindir_prefix,
  3672. target_system_root);
  3673. if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0)
  3674. {
  3675. target_system_root = tmp_prefix;
  3676. target_system_root_changed = 1;
  3677. }
  3678. }
  3679. #endif
  3680. /* More prefixes are enabled in main, after we read the specs file
  3681. and determine whether this is cross-compilation or not. */
  3682. if (n_infiles == last_language_n_infiles && spec_lang != 0)
  3683. warning (0, "%<-x %s%> after last input file has no effect", spec_lang);
  3684. /* Synthesize -fcompare-debug flag from the GCC_COMPARE_DEBUG
  3685. environment variable. */
  3686. if (compare_debug == 2 || compare_debug == 3)
  3687. {
  3688. const char *opt = concat ("-fcompare-debug=", compare_debug_opt, NULL);
  3689. save_switch (opt, 0, NULL, false, true);
  3690. compare_debug = 1;
  3691. }
  3692. /* Ensure we only invoke each subprocess once. */
  3693. if (print_subprocess_help || print_help_list || print_version)
  3694. {
  3695. n_infiles = 0;
  3696. /* Create a dummy input file, so that we can pass
  3697. the help option on to the various sub-processes. */
  3698. add_infile ("help-dummy", "c");
  3699. }
  3700. alloc_switch ();
  3701. switches[n_switches].part1 = 0;
  3702. alloc_infile ();
  3703. infiles[n_infiles].name = 0;
  3704. }
  3705. /* Store switches not filtered out by %<S in spec in COLLECT_GCC_OPTIONS
  3706. and place that in the environment. */
  3707. static void
  3708. set_collect_gcc_options (void)
  3709. {
  3710. int i;
  3711. int first_time;
  3712. /* Build COLLECT_GCC_OPTIONS to have all of the options specified to
  3713. the compiler. */
  3714. obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=",
  3715. sizeof ("COLLECT_GCC_OPTIONS=") - 1);
  3716. first_time = TRUE;
  3717. for (i = 0; (int) i < n_switches; i++)
  3718. {
  3719. const char *const *args;
  3720. const char *p, *q;
  3721. if (!first_time)
  3722. obstack_grow (&collect_obstack, " ", 1);
  3723. first_time = FALSE;
  3724. /* Ignore elided switches. */
  3725. if ((switches[i].live_cond
  3726. & (SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC))
  3727. == SWITCH_IGNORE)
  3728. continue;
  3729. obstack_grow (&collect_obstack, "'-", 2);
  3730. q = switches[i].part1;
  3731. while ((p = strchr (q, '\'')))
  3732. {
  3733. obstack_grow (&collect_obstack, q, p - q);
  3734. obstack_grow (&collect_obstack, "'\\''", 4);
  3735. q = ++p;
  3736. }
  3737. obstack_grow (&collect_obstack, q, strlen (q));
  3738. obstack_grow (&collect_obstack, "'", 1);
  3739. for (args = switches[i].args; args && *args; args++)
  3740. {
  3741. obstack_grow (&collect_obstack, " '", 2);
  3742. q = *args;
  3743. while ((p = strchr (q, '\'')))
  3744. {
  3745. obstack_grow (&collect_obstack, q, p - q);
  3746. obstack_grow (&collect_obstack, "'\\''", 4);
  3747. q = ++p;
  3748. }
  3749. obstack_grow (&collect_obstack, q, strlen (q));
  3750. obstack_grow (&collect_obstack, "'", 1);
  3751. }
  3752. }
  3753. obstack_grow (&collect_obstack, "\0", 1);
  3754. xputenv (XOBFINISH (&collect_obstack, char *));
  3755. }
  3756. /* Process a spec string, accumulating and running commands. */
  3757. /* These variables describe the input file name.
  3758. input_file_number is the index on outfiles of this file,
  3759. so that the output file name can be stored for later use by %o.
  3760. input_basename is the start of the part of the input file
  3761. sans all directory names, and basename_length is the number
  3762. of characters starting there excluding the suffix .c or whatever. */
  3763. static const char *gcc_input_filename;
  3764. static int input_file_number;
  3765. size_t input_filename_length;
  3766. static int basename_length;
  3767. static int suffixed_basename_length;
  3768. static const char *input_basename;
  3769. static const char *input_suffix;
  3770. #ifndef HOST_LACKS_INODE_NUMBERS
  3771. static struct stat input_stat;
  3772. #endif
  3773. static int input_stat_set;
  3774. /* The compiler used to process the current input file. */
  3775. static struct compiler *input_file_compiler;
  3776. /* These are variables used within do_spec and do_spec_1. */
  3777. /* Nonzero if an arg has been started and not yet terminated
  3778. (with space, tab or newline). */
  3779. static int arg_going;
  3780. /* Nonzero means %d or %g has been seen; the next arg to be terminated
  3781. is a temporary file name. */
  3782. static int delete_this_arg;
  3783. /* Nonzero means %w has been seen; the next arg to be terminated
  3784. is the output file name of this compilation. */
  3785. static int this_is_output_file;
  3786. /* Nonzero means %s has been seen; the next arg to be terminated
  3787. is the name of a library file and we should try the standard
  3788. search dirs for it. */
  3789. static int this_is_library_file;
  3790. /* Nonzero means %T has been seen; the next arg to be terminated
  3791. is the name of a linker script and we should try all of the
  3792. standard search dirs for it. If it is found insert a --script
  3793. command line switch and then substitute the full path in place,
  3794. otherwise generate an error message. */
  3795. static int this_is_linker_script;
  3796. /* Nonzero means that the input of this command is coming from a pipe. */
  3797. static int input_from_pipe;
  3798. /* Nonnull means substitute this for any suffix when outputting a switches
  3799. arguments. */
  3800. static const char *suffix_subst;
  3801. /* If there is an argument being accumulated, terminate it and store it. */
  3802. static void
  3803. end_going_arg (void)
  3804. {
  3805. if (arg_going)
  3806. {
  3807. const char *string;
  3808. obstack_1grow (&obstack, 0);
  3809. string = XOBFINISH (&obstack, const char *);
  3810. if (this_is_library_file)
  3811. string = find_file (string);
  3812. if (this_is_linker_script)
  3813. {
  3814. char * full_script_path = find_a_file (&startfile_prefixes, string, R_OK, true);
  3815. if (full_script_path == NULL)
  3816. {
  3817. error ("unable to locate default linker script %qs in the library search paths", string);
  3818. /* Script was not found on search path. */
  3819. return;
  3820. }
  3821. store_arg ("--script", false, false);
  3822. string = full_script_path;
  3823. }
  3824. store_arg (string, delete_this_arg, this_is_output_file);
  3825. if (this_is_output_file)
  3826. outfiles[input_file_number] = string;
  3827. arg_going = 0;
  3828. }
  3829. }
  3830. /* Parse the WRAPPER string which is a comma separated list of the command line
  3831. and insert them into the beginning of argbuf. */
  3832. static void
  3833. insert_wrapper (const char *wrapper)
  3834. {
  3835. int n = 0;
  3836. int i;
  3837. char *buf = xstrdup (wrapper);
  3838. char *p = buf;
  3839. unsigned int old_length = argbuf.length ();
  3840. do
  3841. {
  3842. n++;
  3843. while (*p == ',')
  3844. p++;
  3845. }
  3846. while ((p = strchr (p, ',')) != NULL);
  3847. argbuf.safe_grow (old_length + n);
  3848. memmove (argbuf.address () + n,
  3849. argbuf.address (),
  3850. old_length * sizeof (const_char_p));
  3851. i = 0;
  3852. p = buf;
  3853. do
  3854. {
  3855. while (*p == ',')
  3856. {
  3857. *p = 0;
  3858. p++;
  3859. }
  3860. argbuf[i] = p;
  3861. i++;
  3862. }
  3863. while ((p = strchr (p, ',')) != NULL);
  3864. gcc_assert (i == n);
  3865. }
  3866. /* Process the spec SPEC and run the commands specified therein.
  3867. Returns 0 if the spec is successfully processed; -1 if failed. */
  3868. int
  3869. do_spec (const char *spec)
  3870. {
  3871. int value;
  3872. value = do_spec_2 (spec);
  3873. /* Force out any unfinished command.
  3874. If -pipe, this forces out the last command if it ended in `|'. */
  3875. if (value == 0)
  3876. {
  3877. if (argbuf.length () > 0
  3878. && !strcmp (argbuf.last (), "|"))
  3879. argbuf.pop ();
  3880. set_collect_gcc_options ();
  3881. if (argbuf.length () > 0)
  3882. value = execute ();
  3883. }
  3884. return value;
  3885. }
  3886. static int
  3887. do_spec_2 (const char *spec)
  3888. {
  3889. int result;
  3890. clear_args ();
  3891. arg_going = 0;
  3892. delete_this_arg = 0;
  3893. this_is_output_file = 0;
  3894. this_is_library_file = 0;
  3895. this_is_linker_script = 0;
  3896. input_from_pipe = 0;
  3897. suffix_subst = NULL;
  3898. result = do_spec_1 (spec, 0, NULL);
  3899. end_going_arg ();
  3900. return result;
  3901. }
  3902. /* Process the given spec string and add any new options to the end
  3903. of the switches/n_switches array. */
  3904. static void
  3905. do_option_spec (const char *name, const char *spec)
  3906. {
  3907. unsigned int i, value_count, value_len;
  3908. const char *p, *q, *value;
  3909. char *tmp_spec, *tmp_spec_p;
  3910. if (configure_default_options[0].name == NULL)
  3911. return;
  3912. for (i = 0; i < ARRAY_SIZE (configure_default_options); i++)
  3913. if (strcmp (configure_default_options[i].name, name) == 0)
  3914. break;
  3915. if (i == ARRAY_SIZE (configure_default_options))
  3916. return;
  3917. value = configure_default_options[i].value;
  3918. value_len = strlen (value);
  3919. /* Compute the size of the final spec. */
  3920. value_count = 0;
  3921. p = spec;
  3922. while ((p = strstr (p, "%(VALUE)")) != NULL)
  3923. {
  3924. p ++;
  3925. value_count ++;
  3926. }
  3927. /* Replace each %(VALUE) by the specified value. */
  3928. tmp_spec = (char *) alloca (strlen (spec) + 1
  3929. + value_count * (value_len - strlen ("%(VALUE)")));
  3930. tmp_spec_p = tmp_spec;
  3931. q = spec;
  3932. while ((p = strstr (q, "%(VALUE)")) != NULL)
  3933. {
  3934. memcpy (tmp_spec_p, q, p - q);
  3935. tmp_spec_p = tmp_spec_p + (p - q);
  3936. memcpy (tmp_spec_p, value, value_len);
  3937. tmp_spec_p += value_len;
  3938. q = p + strlen ("%(VALUE)");
  3939. }
  3940. strcpy (tmp_spec_p, q);
  3941. do_self_spec (tmp_spec);
  3942. }
  3943. /* Process the given spec string and add any new options to the end
  3944. of the switches/n_switches array. */
  3945. static void
  3946. do_self_spec (const char *spec)
  3947. {
  3948. int i;
  3949. do_spec_2 (spec);
  3950. do_spec_1 (" ", 0, NULL);
  3951. /* Mark %<S switches processed by do_self_spec to be ignored permanently.
  3952. do_self_specs adds the replacements to switches array, so it shouldn't
  3953. be processed afterwards. */
  3954. for (i = 0; i < n_switches; i++)
  3955. if ((switches[i].live_cond & SWITCH_IGNORE))
  3956. switches[i].live_cond |= SWITCH_IGNORE_PERMANENTLY;
  3957. if (argbuf.length () > 0)
  3958. {
  3959. const char **argbuf_copy;
  3960. struct cl_decoded_option *decoded_options;
  3961. struct cl_option_handlers handlers;
  3962. unsigned int decoded_options_count;
  3963. unsigned int j;
  3964. /* Create a copy of argbuf with a dummy argv[0] entry for
  3965. decode_cmdline_options_to_array. */
  3966. argbuf_copy = XNEWVEC (const char *,
  3967. argbuf.length () + 1);
  3968. argbuf_copy[0] = "";
  3969. memcpy (argbuf_copy + 1, argbuf.address (),
  3970. argbuf.length () * sizeof (const char *));
  3971. decode_cmdline_options_to_array (argbuf.length () + 1,
  3972. argbuf_copy,
  3973. CL_DRIVER, &decoded_options,
  3974. &decoded_options_count);
  3975. free (argbuf_copy);
  3976. set_option_handlers (&handlers);
  3977. for (j = 1; j < decoded_options_count; j++)
  3978. {
  3979. switch (decoded_options[j].opt_index)
  3980. {
  3981. case OPT_SPECIAL_input_file:
  3982. /* Specs should only generate options, not input
  3983. files. */
  3984. if (strcmp (decoded_options[j].arg, "-") != 0)
  3985. fatal_error (input_location,
  3986. "switch %qs does not start with %<-%>",
  3987. decoded_options[j].arg);
  3988. else
  3989. fatal_error (input_location,
  3990. "spec-generated switch is just %<-%>");
  3991. break;
  3992. case OPT_fcompare_debug_second:
  3993. case OPT_fcompare_debug:
  3994. case OPT_fcompare_debug_:
  3995. case OPT_o:
  3996. /* Avoid duplicate processing of some options from
  3997. compare-debug specs; just save them here. */
  3998. save_switch (decoded_options[j].canonical_option[0],
  3999. (decoded_options[j].canonical_option_num_elements
  4000. - 1),
  4001. &decoded_options[j].canonical_option[1], false, true);
  4002. break;
  4003. default:
  4004. read_cmdline_option (&global_options, &global_options_set,
  4005. decoded_options + j, UNKNOWN_LOCATION,
  4006. CL_DRIVER, &handlers, global_dc);
  4007. break;
  4008. }
  4009. }
  4010. free (decoded_options);
  4011. alloc_switch ();
  4012. switches[n_switches].part1 = 0;
  4013. }
  4014. }
  4015. /* Callback for processing %D and %I specs. */
  4016. struct spec_path_info {
  4017. const char *option;
  4018. const char *append;
  4019. size_t append_len;
  4020. bool omit_relative;
  4021. bool separate_options;
  4022. };
  4023. static void *
  4024. spec_path (char *path, void *data)
  4025. {
  4026. struct spec_path_info *info = (struct spec_path_info *) data;
  4027. size_t len = 0;
  4028. char save = 0;
  4029. if (info->omit_relative && !IS_ABSOLUTE_PATH (path))
  4030. return NULL;
  4031. if (info->append_len != 0)
  4032. {
  4033. len = strlen (path);
  4034. memcpy (path + len, info->append, info->append_len + 1);
  4035. }
  4036. if (!is_directory (path, true))
  4037. return NULL;
  4038. do_spec_1 (info->option, 1, NULL);
  4039. if (info->separate_options)
  4040. do_spec_1 (" ", 0, NULL);
  4041. if (info->append_len == 0)
  4042. {
  4043. len = strlen (path);
  4044. save = path[len - 1];
  4045. if (IS_DIR_SEPARATOR (path[len - 1]))
  4046. path[len - 1] = '\0';
  4047. }
  4048. do_spec_1 (path, 1, NULL);
  4049. do_spec_1 (" ", 0, NULL);
  4050. /* Must not damage the original path. */
  4051. if (info->append_len == 0)
  4052. path[len - 1] = save;
  4053. return NULL;
  4054. }
  4055. /* Create a temporary FILE with the contents of ARGV. Add @FILE to the
  4056. argument list. */
  4057. static void
  4058. create_at_file (char **argv)
  4059. {
  4060. char *temp_file = make_temp_file ("");
  4061. char *at_argument = concat ("@", temp_file, NULL);
  4062. FILE *f = fopen (temp_file, "w");
  4063. int status;
  4064. if (f == NULL)
  4065. fatal_error (input_location, "could not open temporary response file %s",
  4066. temp_file);
  4067. status = writeargv (argv, f);
  4068. if (status)
  4069. fatal_error (input_location,
  4070. "could not write to temporary response file %s",
  4071. temp_file);
  4072. status = fclose (f);
  4073. if (EOF == status)
  4074. fatal_error (input_location, "could not close temporary response file %s",
  4075. temp_file);
  4076. store_arg (at_argument, 0, 0);
  4077. record_temp_file (temp_file, !save_temps_flag, !save_temps_flag);
  4078. }
  4079. /* True if we should compile INFILE. */
  4080. static bool
  4081. compile_input_file_p (struct infile *infile)
  4082. {
  4083. if ((!infile->language) || (infile->language[0] != '*'))
  4084. if (infile->incompiler == input_file_compiler)
  4085. return true;
  4086. return false;
  4087. }
  4088. /* Process each member of VEC as a spec. */
  4089. static void
  4090. do_specs_vec (vec<char_p> vec)
  4091. {
  4092. unsigned ix;
  4093. char *opt;
  4094. FOR_EACH_VEC_ELT (vec, ix, opt)
  4095. {
  4096. do_spec_1 (opt, 1, NULL);
  4097. /* Make each accumulated option a separate argument. */
  4098. do_spec_1 (" ", 0, NULL);
  4099. }
  4100. }
  4101. /* Process the sub-spec SPEC as a portion of a larger spec.
  4102. This is like processing a whole spec except that we do
  4103. not initialize at the beginning and we do not supply a
  4104. newline by default at the end.
  4105. INSWITCH nonzero means don't process %-sequences in SPEC;
  4106. in this case, % is treated as an ordinary character.
  4107. This is used while substituting switches.
  4108. INSWITCH nonzero also causes SPC not to terminate an argument.
  4109. Value is zero unless a line was finished
  4110. and the command on that line reported an error. */
  4111. static int
  4112. do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
  4113. {
  4114. const char *p = spec;
  4115. int c;
  4116. int i;
  4117. int value;
  4118. /* If it's an empty string argument to a switch, keep it as is. */
  4119. if (inswitch && !*p)
  4120. arg_going = 1;
  4121. while ((c = *p++))
  4122. /* If substituting a switch, treat all chars like letters.
  4123. Otherwise, NL, SPC, TAB and % are special. */
  4124. switch (inswitch ? 'a' : c)
  4125. {
  4126. case '\n':
  4127. end_going_arg ();
  4128. if (argbuf.length () > 0
  4129. && !strcmp (argbuf.last (), "|"))
  4130. {
  4131. /* A `|' before the newline means use a pipe here,
  4132. but only if -pipe was specified.
  4133. Otherwise, execute now and don't pass the `|' as an arg. */
  4134. if (use_pipes)
  4135. {
  4136. input_from_pipe = 1;
  4137. break;
  4138. }
  4139. else
  4140. argbuf.pop ();
  4141. }
  4142. set_collect_gcc_options ();
  4143. if (argbuf.length () > 0)
  4144. {
  4145. value = execute ();
  4146. if (value)
  4147. return value;
  4148. }
  4149. /* Reinitialize for a new command, and for a new argument. */
  4150. clear_args ();
  4151. arg_going = 0;
  4152. delete_this_arg = 0;
  4153. this_is_output_file = 0;
  4154. this_is_library_file = 0;
  4155. this_is_linker_script = 0;
  4156. input_from_pipe = 0;
  4157. break;
  4158. case '|':
  4159. end_going_arg ();
  4160. /* Use pipe */
  4161. obstack_1grow (&obstack, c);
  4162. arg_going = 1;
  4163. break;
  4164. case '\t':
  4165. case ' ':
  4166. end_going_arg ();
  4167. /* Reinitialize for a new argument. */
  4168. delete_this_arg = 0;
  4169. this_is_output_file = 0;
  4170. this_is_library_file = 0;
  4171. this_is_linker_script = 0;
  4172. break;
  4173. case '%':
  4174. switch (c = *p++)
  4175. {
  4176. case 0:
  4177. fatal_error (input_location, "spec %qs invalid", spec);
  4178. case 'b':
  4179. if (save_temps_length)
  4180. obstack_grow (&obstack, save_temps_prefix, save_temps_length);
  4181. else
  4182. obstack_grow (&obstack, input_basename, basename_length);
  4183. if (compare_debug < 0)
  4184. obstack_grow (&obstack, ".gk", 3);
  4185. arg_going = 1;
  4186. break;
  4187. case 'B':
  4188. if (save_temps_length)
  4189. obstack_grow (&obstack, save_temps_prefix, save_temps_length);
  4190. else
  4191. obstack_grow (&obstack, input_basename, suffixed_basename_length);
  4192. if (compare_debug < 0)
  4193. obstack_grow (&obstack, ".gk", 3);
  4194. arg_going = 1;
  4195. break;
  4196. case 'd':
  4197. delete_this_arg = 2;
  4198. break;
  4199. /* Dump out the directories specified with LIBRARY_PATH,
  4200. followed by the absolute directories
  4201. that we search for startfiles. */
  4202. case 'D':
  4203. {
  4204. struct spec_path_info info;
  4205. info.option = "-L";
  4206. info.append_len = 0;
  4207. #ifdef RELATIVE_PREFIX_NOT_LINKDIR
  4208. /* Used on systems which record the specified -L dirs
  4209. and use them to search for dynamic linking.
  4210. Relative directories always come from -B,
  4211. and it is better not to use them for searching
  4212. at run time. In particular, stage1 loses. */
  4213. info.omit_relative = true;
  4214. #else
  4215. info.omit_relative = false;
  4216. #endif
  4217. info.separate_options = false;
  4218. for_each_path (&startfile_prefixes, true, 0, spec_path, &info);
  4219. }
  4220. break;
  4221. case 'e':
  4222. /* %efoo means report an error with `foo' as error message
  4223. and don't execute any more commands for this file. */
  4224. {
  4225. const char *q = p;
  4226. char *buf;
  4227. while (*p != 0 && *p != '\n')
  4228. p++;
  4229. buf = (char *) alloca (p - q + 1);
  4230. strncpy (buf, q, p - q);
  4231. buf[p - q] = 0;
  4232. error ("%s", _(buf));
  4233. return -1;
  4234. }
  4235. break;
  4236. case 'n':
  4237. /* %nfoo means report a notice with `foo' on stderr. */
  4238. {
  4239. const char *q = p;
  4240. char *buf;
  4241. while (*p != 0 && *p != '\n')
  4242. p++;
  4243. buf = (char *) alloca (p - q + 1);
  4244. strncpy (buf, q, p - q);
  4245. buf[p - q] = 0;
  4246. inform (0, "%s", _(buf));
  4247. if (*p)
  4248. p++;
  4249. }
  4250. break;
  4251. case 'j':
  4252. {
  4253. struct stat st;
  4254. /* If save_temps_flag is off, and the HOST_BIT_BUCKET is
  4255. defined, and it is not a directory, and it is
  4256. writable, use it. Otherwise, treat this like any
  4257. other temporary file. */
  4258. if ((!save_temps_flag)
  4259. && (stat (HOST_BIT_BUCKET, &st) == 0) && (!S_ISDIR (st.st_mode))
  4260. && (access (HOST_BIT_BUCKET, W_OK) == 0))
  4261. {
  4262. obstack_grow (&obstack, HOST_BIT_BUCKET,
  4263. strlen (HOST_BIT_BUCKET));
  4264. delete_this_arg = 0;
  4265. arg_going = 1;
  4266. break;
  4267. }
  4268. }
  4269. goto create_temp_file;
  4270. case '|':
  4271. if (use_pipes)
  4272. {
  4273. obstack_1grow (&obstack, '-');
  4274. delete_this_arg = 0;
  4275. arg_going = 1;
  4276. /* consume suffix */
  4277. while (*p == '.' || ISALNUM ((unsigned char) *p))
  4278. p++;
  4279. if (p[0] == '%' && p[1] == 'O')
  4280. p += 2;
  4281. break;
  4282. }
  4283. goto create_temp_file;
  4284. case 'm':
  4285. if (use_pipes)
  4286. {
  4287. /* consume suffix */
  4288. while (*p == '.' || ISALNUM ((unsigned char) *p))
  4289. p++;
  4290. if (p[0] == '%' && p[1] == 'O')
  4291. p += 2;
  4292. break;
  4293. }
  4294. goto create_temp_file;
  4295. case 'g':
  4296. case 'u':
  4297. case 'U':
  4298. create_temp_file:
  4299. {
  4300. struct temp_name *t;
  4301. int suffix_length;
  4302. const char *suffix = p;
  4303. char *saved_suffix = NULL;
  4304. while (*p == '.' || ISALNUM ((unsigned char) *p))
  4305. p++;
  4306. suffix_length = p - suffix;
  4307. if (p[0] == '%' && p[1] == 'O')
  4308. {
  4309. p += 2;
  4310. /* We don't support extra suffix characters after %O. */
  4311. if (*p == '.' || ISALNUM ((unsigned char) *p))
  4312. fatal_error (input_location,
  4313. "spec %qs has invalid %<%%0%c%>", spec, *p);
  4314. if (suffix_length == 0)
  4315. suffix = TARGET_OBJECT_SUFFIX;
  4316. else
  4317. {
  4318. saved_suffix
  4319. = XNEWVEC (char, suffix_length
  4320. + strlen (TARGET_OBJECT_SUFFIX) + 1);
  4321. strncpy (saved_suffix, suffix, suffix_length);
  4322. strcpy (saved_suffix + suffix_length,
  4323. TARGET_OBJECT_SUFFIX);
  4324. }
  4325. suffix_length += strlen (TARGET_OBJECT_SUFFIX);
  4326. }
  4327. if (compare_debug < 0)
  4328. {
  4329. suffix = concat (".gk", suffix, NULL);
  4330. suffix_length += 3;
  4331. }
  4332. /* If -save-temps=obj and -o were specified, use that for the
  4333. temp file. */
  4334. if (save_temps_length)
  4335. {
  4336. char *tmp;
  4337. temp_filename_length
  4338. = save_temps_length + suffix_length + 1;
  4339. tmp = (char *) alloca (temp_filename_length);
  4340. memcpy (tmp, save_temps_prefix, save_temps_length);
  4341. memcpy (tmp + save_temps_length, suffix, suffix_length);
  4342. tmp[save_temps_length + suffix_length] = '\0';
  4343. temp_filename = save_string (tmp, save_temps_length
  4344. + suffix_length);
  4345. obstack_grow (&obstack, temp_filename,
  4346. temp_filename_length);
  4347. arg_going = 1;
  4348. delete_this_arg = 0;
  4349. break;
  4350. }
  4351. /* If the gcc_input_filename has the same suffix specified
  4352. for the %g, %u, or %U, and -save-temps is specified,
  4353. we could end up using that file as an intermediate
  4354. thus clobbering the user's source file (.e.g.,
  4355. gcc -save-temps foo.s would clobber foo.s with the
  4356. output of cpp0). So check for this condition and
  4357. generate a temp file as the intermediate. */
  4358. if (save_temps_flag)
  4359. {
  4360. char *tmp;
  4361. temp_filename_length = basename_length + suffix_length + 1;
  4362. tmp = (char *) alloca (temp_filename_length);
  4363. memcpy (tmp, input_basename, basename_length);
  4364. memcpy (tmp + basename_length, suffix, suffix_length);
  4365. tmp[basename_length + suffix_length] = '\0';
  4366. temp_filename = tmp;
  4367. if (filename_cmp (temp_filename, gcc_input_filename) != 0)
  4368. {
  4369. #ifndef HOST_LACKS_INODE_NUMBERS
  4370. struct stat st_temp;
  4371. /* Note, set_input() resets input_stat_set to 0. */
  4372. if (input_stat_set == 0)
  4373. {
  4374. input_stat_set = stat (gcc_input_filename,
  4375. &input_stat);
  4376. if (input_stat_set >= 0)
  4377. input_stat_set = 1;
  4378. }
  4379. /* If we have the stat for the gcc_input_filename
  4380. and we can do the stat for the temp_filename
  4381. then the they could still refer to the same
  4382. file if st_dev/st_ino's are the same. */
  4383. if (input_stat_set != 1
  4384. || stat (temp_filename, &st_temp) < 0
  4385. || input_stat.st_dev != st_temp.st_dev
  4386. || input_stat.st_ino != st_temp.st_ino)
  4387. #else
  4388. /* Just compare canonical pathnames. */
  4389. char* input_realname = lrealpath (gcc_input_filename);
  4390. char* temp_realname = lrealpath (temp_filename);
  4391. bool files_differ = filename_cmp (input_realname, temp_realname);
  4392. free (input_realname);
  4393. free (temp_realname);
  4394. if (files_differ)
  4395. #endif
  4396. {
  4397. temp_filename = save_string (temp_filename,
  4398. temp_filename_length + 1);
  4399. obstack_grow (&obstack, temp_filename,
  4400. temp_filename_length);
  4401. arg_going = 1;
  4402. delete_this_arg = 0;
  4403. break;
  4404. }
  4405. }
  4406. }
  4407. /* See if we already have an association of %g/%u/%U and
  4408. suffix. */
  4409. for (t = temp_names; t; t = t->next)
  4410. if (t->length == suffix_length
  4411. && strncmp (t->suffix, suffix, suffix_length) == 0
  4412. && t->unique == (c == 'u' || c == 'U' || c == 'j'))
  4413. break;
  4414. /* Make a new association if needed. %u and %j
  4415. require one. */
  4416. if (t == 0 || c == 'u' || c == 'j')
  4417. {
  4418. if (t == 0)
  4419. {
  4420. t = XNEW (struct temp_name);
  4421. t->next = temp_names;
  4422. temp_names = t;
  4423. }
  4424. t->length = suffix_length;
  4425. if (saved_suffix)
  4426. {
  4427. t->suffix = saved_suffix;
  4428. saved_suffix = NULL;
  4429. }
  4430. else
  4431. t->suffix = save_string (suffix, suffix_length);
  4432. t->unique = (c == 'u' || c == 'U' || c == 'j');
  4433. temp_filename = make_temp_file (t->suffix);
  4434. temp_filename_length = strlen (temp_filename);
  4435. t->filename = temp_filename;
  4436. t->filename_length = temp_filename_length;
  4437. }
  4438. free (saved_suffix);
  4439. obstack_grow (&obstack, t->filename, t->filename_length);
  4440. delete_this_arg = 1;
  4441. }
  4442. arg_going = 1;
  4443. break;
  4444. case 'i':
  4445. if (combine_inputs)
  4446. {
  4447. if (at_file_supplied)
  4448. {
  4449. /* We are going to expand `%i' to `@FILE', where FILE
  4450. is a newly-created temporary filename. The filenames
  4451. that would usually be expanded in place of %o will be
  4452. written to the temporary file. */
  4453. char **argv;
  4454. int n_files = 0;
  4455. int j;
  4456. for (i = 0; i < n_infiles; i++)
  4457. if (compile_input_file_p (&infiles[i]))
  4458. n_files++;
  4459. argv = (char **) alloca (sizeof (char *) * (n_files + 1));
  4460. /* Copy the strings over. */
  4461. for (i = 0, j = 0; i < n_infiles; i++)
  4462. if (compile_input_file_p (&infiles[i]))
  4463. {
  4464. argv[j] = CONST_CAST (char *, infiles[i].name);
  4465. infiles[i].compiled = true;
  4466. j++;
  4467. }
  4468. argv[j] = NULL;
  4469. create_at_file (argv);
  4470. }
  4471. else
  4472. for (i = 0; (int) i < n_infiles; i++)
  4473. if (compile_input_file_p (&infiles[i]))
  4474. {
  4475. store_arg (infiles[i].name, 0, 0);
  4476. infiles[i].compiled = true;
  4477. }
  4478. }
  4479. else
  4480. {
  4481. obstack_grow (&obstack, gcc_input_filename,
  4482. input_filename_length);
  4483. arg_going = 1;
  4484. }
  4485. break;
  4486. case 'I':
  4487. {
  4488. struct spec_path_info info;
  4489. if (multilib_dir)
  4490. {
  4491. do_spec_1 ("-imultilib", 1, NULL);
  4492. /* Make this a separate argument. */
  4493. do_spec_1 (" ", 0, NULL);
  4494. do_spec_1 (multilib_dir, 1, NULL);
  4495. do_spec_1 (" ", 0, NULL);
  4496. }
  4497. if (multiarch_dir)
  4498. {
  4499. do_spec_1 ("-imultiarch", 1, NULL);
  4500. /* Make this a separate argument. */
  4501. do_spec_1 (" ", 0, NULL);
  4502. do_spec_1 (multiarch_dir, 1, NULL);
  4503. do_spec_1 (" ", 0, NULL);
  4504. }
  4505. if (gcc_exec_prefix)
  4506. {
  4507. do_spec_1 ("-iprefix", 1, NULL);
  4508. /* Make this a separate argument. */
  4509. do_spec_1 (" ", 0, NULL);
  4510. do_spec_1 (gcc_exec_prefix, 1, NULL);
  4511. do_spec_1 (" ", 0, NULL);
  4512. }
  4513. if (target_system_root_changed ||
  4514. (target_system_root && target_sysroot_hdrs_suffix))
  4515. {
  4516. do_spec_1 ("-isysroot", 1, NULL);
  4517. /* Make this a separate argument. */
  4518. do_spec_1 (" ", 0, NULL);
  4519. do_spec_1 (target_system_root, 1, NULL);
  4520. if (target_sysroot_hdrs_suffix)
  4521. do_spec_1 (target_sysroot_hdrs_suffix, 1, NULL);
  4522. do_spec_1 (" ", 0, NULL);
  4523. }
  4524. info.option = "-isystem";
  4525. info.append = "include";
  4526. info.append_len = strlen (info.append);
  4527. info.omit_relative = false;
  4528. info.separate_options = true;
  4529. for_each_path (&include_prefixes, false, info.append_len,
  4530. spec_path, &info);
  4531. info.append = "include-fixed";
  4532. if (*sysroot_hdrs_suffix_spec)
  4533. info.append = concat (info.append, dir_separator_str,
  4534. multilib_dir, NULL);
  4535. info.append_len = strlen (info.append);
  4536. for_each_path (&include_prefixes, false, info.append_len,
  4537. spec_path, &info);
  4538. }
  4539. break;
  4540. case 'o':
  4541. {
  4542. int max = n_infiles;
  4543. max += lang_specific_extra_outfiles;
  4544. if (HAVE_GNU_LD && at_file_supplied)
  4545. {
  4546. /* We are going to expand `%o' to `@FILE', where FILE
  4547. is a newly-created temporary filename. The filenames
  4548. that would usually be expanded in place of %o will be
  4549. written to the temporary file. */
  4550. char **argv;
  4551. int n_files, j;
  4552. /* Convert OUTFILES into a form suitable for writeargv. */
  4553. /* Determine how many are non-NULL. */
  4554. for (n_files = 0, i = 0; i < max; i++)
  4555. n_files += outfiles[i] != NULL;
  4556. argv = (char **) alloca (sizeof (char *) * (n_files + 1));
  4557. /* Copy the strings over. */
  4558. for (i = 0, j = 0; i < max; i++)
  4559. if (outfiles[i])
  4560. {
  4561. argv[j] = CONST_CAST (char *, outfiles[i]);
  4562. j++;
  4563. }
  4564. argv[j] = NULL;
  4565. create_at_file (argv);
  4566. }
  4567. else
  4568. for (i = 0; i < max; i++)
  4569. if (outfiles[i])
  4570. store_arg (outfiles[i], 0, 0);
  4571. break;
  4572. }
  4573. case 'O':
  4574. obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX));
  4575. arg_going = 1;
  4576. break;
  4577. case 's':
  4578. this_is_library_file = 1;
  4579. break;
  4580. case 'T':
  4581. this_is_linker_script = 1;
  4582. break;
  4583. case 'V':
  4584. outfiles[input_file_number] = NULL;
  4585. break;
  4586. case 'w':
  4587. this_is_output_file = 1;
  4588. break;
  4589. case 'W':
  4590. {
  4591. unsigned int cur_index = argbuf.length ();
  4592. /* Handle the {...} following the %W. */
  4593. if (*p != '{')
  4594. fatal_error (input_location,
  4595. "spec %qs has invalid %<%%W%c%>", spec, *p);
  4596. p = handle_braces (p + 1);
  4597. if (p == 0)
  4598. return -1;
  4599. end_going_arg ();
  4600. /* If any args were output, mark the last one for deletion
  4601. on failure. */
  4602. if (argbuf.length () != cur_index)
  4603. record_temp_file (argbuf.last (), 0, 1);
  4604. break;
  4605. }
  4606. /* %x{OPTION} records OPTION for %X to output. */
  4607. case 'x':
  4608. {
  4609. const char *p1 = p;
  4610. char *string;
  4611. char *opt;
  4612. unsigned ix;
  4613. /* Skip past the option value and make a copy. */
  4614. if (*p != '{')
  4615. fatal_error (input_location,
  4616. "spec %qs has invalid %<%%x%c%>", spec, *p);
  4617. while (*p++ != '}')
  4618. ;
  4619. string = save_string (p1 + 1, p - p1 - 2);
  4620. /* See if we already recorded this option. */
  4621. FOR_EACH_VEC_ELT (linker_options, ix, opt)
  4622. if (! strcmp (string, opt))
  4623. {
  4624. free (string);
  4625. return 0;
  4626. }
  4627. /* This option is new; add it. */
  4628. add_linker_option (string, strlen (string));
  4629. free (string);
  4630. }
  4631. break;
  4632. /* Dump out the options accumulated previously using %x. */
  4633. case 'X':
  4634. do_specs_vec (linker_options);
  4635. break;
  4636. /* Dump out the options accumulated previously using -Wa,. */
  4637. case 'Y':
  4638. do_specs_vec (assembler_options);
  4639. break;
  4640. /* Dump out the options accumulated previously using -Wp,. */
  4641. case 'Z':
  4642. do_specs_vec (preprocessor_options);
  4643. break;
  4644. /* Here are digits and numbers that just process
  4645. a certain constant string as a spec. */
  4646. case '1':
  4647. value = do_spec_1 (cc1_spec, 0, NULL);
  4648. if (value != 0)
  4649. return value;
  4650. break;
  4651. case '2':
  4652. value = do_spec_1 (cc1plus_spec, 0, NULL);
  4653. if (value != 0)
  4654. return value;
  4655. break;
  4656. case 'a':
  4657. value = do_spec_1 (asm_spec, 0, NULL);
  4658. if (value != 0)
  4659. return value;
  4660. break;
  4661. case 'A':
  4662. value = do_spec_1 (asm_final_spec, 0, NULL);
  4663. if (value != 0)
  4664. return value;
  4665. break;
  4666. case 'C':
  4667. {
  4668. const char *const spec
  4669. = (input_file_compiler->cpp_spec
  4670. ? input_file_compiler->cpp_spec
  4671. : cpp_spec);
  4672. value = do_spec_1 (spec, 0, NULL);
  4673. if (value != 0)
  4674. return value;
  4675. }
  4676. break;
  4677. case 'E':
  4678. value = do_spec_1 (endfile_spec, 0, NULL);
  4679. if (value != 0)
  4680. return value;
  4681. break;
  4682. case 'l':
  4683. value = do_spec_1 (link_spec, 0, NULL);
  4684. if (value != 0)
  4685. return value;
  4686. break;
  4687. case 'L':
  4688. value = do_spec_1 (lib_spec, 0, NULL);
  4689. if (value != 0)
  4690. return value;
  4691. break;
  4692. case 'M':
  4693. if (multilib_os_dir == NULL)
  4694. obstack_1grow (&obstack, '.');
  4695. else
  4696. obstack_grow (&obstack, multilib_os_dir,
  4697. strlen (multilib_os_dir));
  4698. break;
  4699. case 'G':
  4700. value = do_spec_1 (libgcc_spec, 0, NULL);
  4701. if (value != 0)
  4702. return value;
  4703. break;
  4704. case 'R':
  4705. /* We assume there is a directory
  4706. separator at the end of this string. */
  4707. if (target_system_root)
  4708. {
  4709. obstack_grow (&obstack, target_system_root,
  4710. strlen (target_system_root));
  4711. if (target_sysroot_suffix)
  4712. obstack_grow (&obstack, target_sysroot_suffix,
  4713. strlen (target_sysroot_suffix));
  4714. }
  4715. break;
  4716. case 'S':
  4717. value = do_spec_1 (startfile_spec, 0, NULL);
  4718. if (value != 0)
  4719. return value;
  4720. break;
  4721. /* Here we define characters other than letters and digits. */
  4722. case '{':
  4723. p = handle_braces (p);
  4724. if (p == 0)
  4725. return -1;
  4726. break;
  4727. case ':':
  4728. p = handle_spec_function (p, NULL);
  4729. if (p == 0)
  4730. return -1;
  4731. break;
  4732. case '%':
  4733. obstack_1grow (&obstack, '%');
  4734. break;
  4735. case '.':
  4736. {
  4737. unsigned len = 0;
  4738. while (p[len] && p[len] != ' ' && p[len] != '%')
  4739. len++;
  4740. suffix_subst = save_string (p - 1, len + 1);
  4741. p += len;
  4742. }
  4743. break;
  4744. /* Henceforth ignore the option(s) matching the pattern
  4745. after the %<. */
  4746. case '<':
  4747. case '>':
  4748. {
  4749. unsigned len = 0;
  4750. int have_wildcard = 0;
  4751. int i;
  4752. int switch_option;
  4753. if (c == '>')
  4754. switch_option = SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC;
  4755. else
  4756. switch_option = SWITCH_IGNORE;
  4757. while (p[len] && p[len] != ' ' && p[len] != '\t')
  4758. len++;
  4759. if (p[len-1] == '*')
  4760. have_wildcard = 1;
  4761. for (i = 0; i < n_switches; i++)
  4762. if (!strncmp (switches[i].part1, p, len - have_wildcard)
  4763. && (have_wildcard || switches[i].part1[len] == '\0'))
  4764. {
  4765. switches[i].live_cond |= switch_option;
  4766. /* User switch be validated from validate_all_switches.
  4767. when the definition is seen from the spec file.
  4768. If not defined anywhere, will be rejected. */
  4769. if (switches[i].known)
  4770. switches[i].validated = true;
  4771. }
  4772. p += len;
  4773. }
  4774. break;
  4775. case '*':
  4776. if (soft_matched_part)
  4777. {
  4778. if (soft_matched_part[0])
  4779. do_spec_1 (soft_matched_part, 1, NULL);
  4780. /* Only insert a space after the substitution if it is at the
  4781. end of the current sequence. So if:
  4782. "%{foo=*:bar%*}%{foo=*:one%*two}"
  4783. matches -foo=hello then it will produce:
  4784. barhello onehellotwo
  4785. */
  4786. if (*p == 0 || *p == '}')
  4787. do_spec_1 (" ", 0, NULL);
  4788. }
  4789. else
  4790. /* Catch the case where a spec string contains something like
  4791. '%{foo:%*}'. i.e. there is no * in the pattern on the left
  4792. hand side of the :. */
  4793. error ("spec failure: %<%%*%> has not been initialized by pattern match");
  4794. break;
  4795. /* Process a string found as the value of a spec given by name.
  4796. This feature allows individual machine descriptions
  4797. to add and use their own specs. */
  4798. case '(':
  4799. {
  4800. const char *name = p;
  4801. struct spec_list *sl;
  4802. int len;
  4803. /* The string after the S/P is the name of a spec that is to be
  4804. processed. */
  4805. while (*p && *p != ')')
  4806. p++;
  4807. /* See if it's in the list. */
  4808. for (len = p - name, sl = specs; sl; sl = sl->next)
  4809. if (sl->name_len == len && !strncmp (sl->name, name, len))
  4810. {
  4811. name = *(sl->ptr_spec);
  4812. #ifdef DEBUG_SPECS
  4813. fnotice (stderr, "Processing spec (%s), which is '%s'\n",
  4814. sl->name, name);
  4815. #endif
  4816. break;
  4817. }
  4818. if (sl)
  4819. {
  4820. value = do_spec_1 (name, 0, NULL);
  4821. if (value != 0)
  4822. return value;
  4823. }
  4824. /* Discard the closing paren. */
  4825. if (*p)
  4826. p++;
  4827. }
  4828. break;
  4829. default:
  4830. error ("spec failure: unrecognized spec option %qc", c);
  4831. break;
  4832. }
  4833. break;
  4834. case '\\':
  4835. /* Backslash: treat next character as ordinary. */
  4836. c = *p++;
  4837. /* Fall through. */
  4838. default:
  4839. /* Ordinary character: put it into the current argument. */
  4840. obstack_1grow (&obstack, c);
  4841. arg_going = 1;
  4842. }
  4843. /* End of string. If we are processing a spec function, we need to
  4844. end any pending argument. */
  4845. if (processing_spec_function)
  4846. end_going_arg ();
  4847. return 0;
  4848. }
  4849. /* Look up a spec function. */
  4850. static const struct spec_function *
  4851. lookup_spec_function (const char *name)
  4852. {
  4853. const struct spec_function *sf;
  4854. for (sf = static_spec_functions; sf->name != NULL; sf++)
  4855. if (strcmp (sf->name, name) == 0)
  4856. return sf;
  4857. return NULL;
  4858. }
  4859. /* Evaluate a spec function. */
  4860. static const char *
  4861. eval_spec_function (const char *func, const char *args)
  4862. {
  4863. const struct spec_function *sf;
  4864. const char *funcval;
  4865. /* Saved spec processing context. */
  4866. vec<const_char_p> save_argbuf;
  4867. int save_arg_going;
  4868. int save_delete_this_arg;
  4869. int save_this_is_output_file;
  4870. int save_this_is_library_file;
  4871. int save_input_from_pipe;
  4872. int save_this_is_linker_script;
  4873. const char *save_suffix_subst;
  4874. int save_growing_size;
  4875. void *save_growing_value = NULL;
  4876. sf = lookup_spec_function (func);
  4877. if (sf == NULL)
  4878. fatal_error (input_location, "unknown spec function %qs", func);
  4879. /* Push the spec processing context. */
  4880. save_argbuf = argbuf;
  4881. save_arg_going = arg_going;
  4882. save_delete_this_arg = delete_this_arg;
  4883. save_this_is_output_file = this_is_output_file;
  4884. save_this_is_library_file = this_is_library_file;
  4885. save_this_is_linker_script = this_is_linker_script;
  4886. save_input_from_pipe = input_from_pipe;
  4887. save_suffix_subst = suffix_subst;
  4888. /* If we have some object growing now, finalize it so the args and function
  4889. eval proceed from a cleared context. This is needed to prevent the first
  4890. constructed arg from mistakenly including the growing value. We'll push
  4891. this value back on the obstack once the function evaluation is done, to
  4892. restore a consistent processing context for our caller. This is fine as
  4893. the address of growing objects isn't guaranteed to remain stable until
  4894. they are finalized, and we expect this situation to be rare enough for
  4895. the extra copy not to be an issue. */
  4896. save_growing_size = obstack_object_size (&obstack);
  4897. if (save_growing_size > 0)
  4898. save_growing_value = obstack_finish (&obstack);
  4899. /* Create a new spec processing context, and build the function
  4900. arguments. */
  4901. alloc_args ();
  4902. if (do_spec_2 (args) < 0)
  4903. fatal_error (input_location, "error in args to spec function %qs", func);
  4904. /* argbuf_index is an index for the next argument to be inserted, and
  4905. so contains the count of the args already inserted. */
  4906. funcval = (*sf->func) (argbuf.length (),
  4907. argbuf.address ());
  4908. /* Pop the spec processing context. */
  4909. argbuf.release ();
  4910. argbuf = save_argbuf;
  4911. arg_going = save_arg_going;
  4912. delete_this_arg = save_delete_this_arg;
  4913. this_is_output_file = save_this_is_output_file;
  4914. this_is_library_file = save_this_is_library_file;
  4915. this_is_linker_script = save_this_is_linker_script;
  4916. input_from_pipe = save_input_from_pipe;
  4917. suffix_subst = save_suffix_subst;
  4918. if (save_growing_size > 0)
  4919. obstack_grow (&obstack, save_growing_value, save_growing_size);
  4920. return funcval;
  4921. }
  4922. /* Handle a spec function call of the form:
  4923. %:function(args)
  4924. ARGS is processed as a spec in a separate context and split into an
  4925. argument vector in the normal fashion. The function returns a string
  4926. containing a spec which we then process in the caller's context, or
  4927. NULL if no processing is required.
  4928. If RETVAL_NONNULL is not NULL, then store a bool whether function
  4929. returned non-NULL. */
  4930. static const char *
  4931. handle_spec_function (const char *p, bool *retval_nonnull)
  4932. {
  4933. char *func, *args;
  4934. const char *endp, *funcval;
  4935. int count;
  4936. processing_spec_function++;
  4937. /* Get the function name. */
  4938. for (endp = p; *endp != '\0'; endp++)
  4939. {
  4940. if (*endp == '(') /* ) */
  4941. break;
  4942. /* Only allow [A-Za-z0-9], -, and _ in function names. */
  4943. if (!ISALNUM (*endp) && !(*endp == '-' || *endp == '_'))
  4944. fatal_error (input_location, "malformed spec function name");
  4945. }
  4946. if (*endp != '(') /* ) */
  4947. fatal_error (input_location, "no arguments for spec function");
  4948. func = save_string (p, endp - p);
  4949. p = ++endp;
  4950. /* Get the arguments. */
  4951. for (count = 0; *endp != '\0'; endp++)
  4952. {
  4953. /* ( */
  4954. if (*endp == ')')
  4955. {
  4956. if (count == 0)
  4957. break;
  4958. count--;
  4959. }
  4960. else if (*endp == '(') /* ) */
  4961. count++;
  4962. }
  4963. /* ( */
  4964. if (*endp != ')')
  4965. fatal_error (input_location, "malformed spec function arguments");
  4966. args = save_string (p, endp - p);
  4967. p = ++endp;
  4968. /* p now points to just past the end of the spec function expression. */
  4969. funcval = eval_spec_function (func, args);
  4970. if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0)
  4971. p = NULL;
  4972. if (retval_nonnull)
  4973. *retval_nonnull = funcval != NULL;
  4974. free (func);
  4975. free (args);
  4976. processing_spec_function--;
  4977. return p;
  4978. }
  4979. /* Inline subroutine of handle_braces. Returns true if the current
  4980. input suffix matches the atom bracketed by ATOM and END_ATOM. */
  4981. static inline bool
  4982. input_suffix_matches (const char *atom, const char *end_atom)
  4983. {
  4984. return (input_suffix
  4985. && !strncmp (input_suffix, atom, end_atom - atom)
  4986. && input_suffix[end_atom - atom] == '\0');
  4987. }
  4988. /* Subroutine of handle_braces. Returns true if the current
  4989. input file's spec name matches the atom bracketed by ATOM and END_ATOM. */
  4990. static bool
  4991. input_spec_matches (const char *atom, const char *end_atom)
  4992. {
  4993. return (input_file_compiler
  4994. && input_file_compiler->suffix
  4995. && input_file_compiler->suffix[0] != '\0'
  4996. && !strncmp (input_file_compiler->suffix + 1, atom,
  4997. end_atom - atom)
  4998. && input_file_compiler->suffix[end_atom - atom + 1] == '\0');
  4999. }
  5000. /* Subroutine of handle_braces. Returns true if a switch
  5001. matching the atom bracketed by ATOM and END_ATOM appeared on the
  5002. command line. */
  5003. static bool
  5004. switch_matches (const char *atom, const char *end_atom, int starred)
  5005. {
  5006. int i;
  5007. int len = end_atom - atom;
  5008. int plen = starred ? len : -1;
  5009. for (i = 0; i < n_switches; i++)
  5010. if (!strncmp (switches[i].part1, atom, len)
  5011. && (starred || switches[i].part1[len] == '\0')
  5012. && check_live_switch (i, plen))
  5013. return true;
  5014. /* Check if a switch with separated form matching the atom.
  5015. We check -D and -U switches. */
  5016. else if (switches[i].args != 0)
  5017. {
  5018. if ((*switches[i].part1 == 'D' || *switches[i].part1 == 'U')
  5019. && *switches[i].part1 == atom[0])
  5020. {
  5021. if (!strncmp (switches[i].args[0], &atom[1], len - 1)
  5022. && (starred || (switches[i].part1[1] == '\0'
  5023. && switches[i].args[0][len - 1] == '\0'))
  5024. && check_live_switch (i, (starred ? 1 : -1)))
  5025. return true;
  5026. }
  5027. }
  5028. return false;
  5029. }
  5030. /* Inline subroutine of handle_braces. Mark all of the switches which
  5031. match ATOM (extends to END_ATOM; STARRED indicates whether there
  5032. was a star after the atom) for later processing. */
  5033. static inline void
  5034. mark_matching_switches (const char *atom, const char *end_atom, int starred)
  5035. {
  5036. int i;
  5037. int len = end_atom - atom;
  5038. int plen = starred ? len : -1;
  5039. for (i = 0; i < n_switches; i++)
  5040. if (!strncmp (switches[i].part1, atom, len)
  5041. && (starred || switches[i].part1[len] == '\0')
  5042. && check_live_switch (i, plen))
  5043. switches[i].ordering = 1;
  5044. }
  5045. /* Inline subroutine of handle_braces. Process all the currently
  5046. marked switches through give_switch, and clear the marks. */
  5047. static inline void
  5048. process_marked_switches (void)
  5049. {
  5050. int i;
  5051. for (i = 0; i < n_switches; i++)
  5052. if (switches[i].ordering == 1)
  5053. {
  5054. switches[i].ordering = 0;
  5055. give_switch (i, 0);
  5056. }
  5057. }
  5058. /* Handle a %{ ... } construct. P points just inside the leading {.
  5059. Returns a pointer one past the end of the brace block, or 0
  5060. if we call do_spec_1 and that returns -1. */
  5061. static const char *
  5062. handle_braces (const char *p)
  5063. {
  5064. const char *atom, *end_atom;
  5065. const char *d_atom = NULL, *d_end_atom = NULL;
  5066. const char *orig = p;
  5067. bool a_is_suffix;
  5068. bool a_is_spectype;
  5069. bool a_is_starred;
  5070. bool a_is_negated;
  5071. bool a_matched;
  5072. bool a_must_be_last = false;
  5073. bool ordered_set = false;
  5074. bool disjunct_set = false;
  5075. bool disj_matched = false;
  5076. bool disj_starred = true;
  5077. bool n_way_choice = false;
  5078. bool n_way_matched = false;
  5079. #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
  5080. do
  5081. {
  5082. if (a_must_be_last)
  5083. goto invalid;
  5084. /* Scan one "atom" (S in the description above of %{}, possibly
  5085. with '!', '.', '@', ',', or '*' modifiers). */
  5086. a_matched = false;
  5087. a_is_suffix = false;
  5088. a_is_starred = false;
  5089. a_is_negated = false;
  5090. a_is_spectype = false;
  5091. SKIP_WHITE ();
  5092. if (*p == '!')
  5093. p++, a_is_negated = true;
  5094. SKIP_WHITE ();
  5095. if (*p == '%' && p[1] == ':')
  5096. {
  5097. atom = NULL;
  5098. end_atom = NULL;
  5099. p = handle_spec_function (p + 2, &a_matched);
  5100. }
  5101. else
  5102. {
  5103. if (*p == '.')
  5104. p++, a_is_suffix = true;
  5105. else if (*p == ',')
  5106. p++, a_is_spectype = true;
  5107. atom = p;
  5108. while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '='
  5109. || *p == ',' || *p == '.' || *p == '@')
  5110. p++;
  5111. end_atom = p;
  5112. if (*p == '*')
  5113. p++, a_is_starred = 1;
  5114. }
  5115. SKIP_WHITE ();
  5116. switch (*p)
  5117. {
  5118. case '&': case '}':
  5119. /* Substitute the switch(es) indicated by the current atom. */
  5120. ordered_set = true;
  5121. if (disjunct_set || n_way_choice || a_is_negated || a_is_suffix
  5122. || a_is_spectype || atom == end_atom)
  5123. goto invalid;
  5124. mark_matching_switches (atom, end_atom, a_is_starred);
  5125. if (*p == '}')
  5126. process_marked_switches ();
  5127. break;
  5128. case '|': case ':':
  5129. /* Substitute some text if the current atom appears as a switch
  5130. or suffix. */
  5131. disjunct_set = true;
  5132. if (ordered_set)
  5133. goto invalid;
  5134. if (atom && atom == end_atom)
  5135. {
  5136. if (!n_way_choice || disj_matched || *p == '|'
  5137. || a_is_negated || a_is_suffix || a_is_spectype
  5138. || a_is_starred)
  5139. goto invalid;
  5140. /* An empty term may appear as the last choice of an
  5141. N-way choice set; it means "otherwise". */
  5142. a_must_be_last = true;
  5143. disj_matched = !n_way_matched;
  5144. disj_starred = false;
  5145. }
  5146. else
  5147. {
  5148. if ((a_is_suffix || a_is_spectype) && a_is_starred)
  5149. goto invalid;
  5150. if (!a_is_starred)
  5151. disj_starred = false;
  5152. /* Don't bother testing this atom if we already have a
  5153. match. */
  5154. if (!disj_matched && !n_way_matched)
  5155. {
  5156. if (atom == NULL)
  5157. /* a_matched is already set by handle_spec_function. */;
  5158. else if (a_is_suffix)
  5159. a_matched = input_suffix_matches (atom, end_atom);
  5160. else if (a_is_spectype)
  5161. a_matched = input_spec_matches (atom, end_atom);
  5162. else
  5163. a_matched = switch_matches (atom, end_atom, a_is_starred);
  5164. if (a_matched != a_is_negated)
  5165. {
  5166. disj_matched = true;
  5167. d_atom = atom;
  5168. d_end_atom = end_atom;
  5169. }
  5170. }
  5171. }
  5172. if (*p == ':')
  5173. {
  5174. /* Found the body, that is, the text to substitute if the
  5175. current disjunction matches. */
  5176. p = process_brace_body (p + 1, d_atom, d_end_atom, disj_starred,
  5177. disj_matched && !n_way_matched);
  5178. if (p == 0)
  5179. return 0;
  5180. /* If we have an N-way choice, reset state for the next
  5181. disjunction. */
  5182. if (*p == ';')
  5183. {
  5184. n_way_choice = true;
  5185. n_way_matched |= disj_matched;
  5186. disj_matched = false;
  5187. disj_starred = true;
  5188. d_atom = d_end_atom = NULL;
  5189. }
  5190. }
  5191. break;
  5192. default:
  5193. goto invalid;
  5194. }
  5195. }
  5196. while (*p++ != '}');
  5197. return p;
  5198. invalid:
  5199. fatal_error (input_location, "braced spec %qs is invalid at %qc", orig, *p);
  5200. #undef SKIP_WHITE
  5201. }
  5202. /* Subroutine of handle_braces. Scan and process a brace substitution body
  5203. (X in the description of %{} syntax). P points one past the colon;
  5204. ATOM and END_ATOM bracket the first atom which was found to be true
  5205. (present) in the current disjunction; STARRED indicates whether all
  5206. the atoms in the current disjunction were starred (for syntax validation);
  5207. MATCHED indicates whether the disjunction matched or not, and therefore
  5208. whether or not the body is to be processed through do_spec_1 or just
  5209. skipped. Returns a pointer to the closing } or ;, or 0 if do_spec_1
  5210. returns -1. */
  5211. static const char *
  5212. process_brace_body (const char *p, const char *atom, const char *end_atom,
  5213. int starred, int matched)
  5214. {
  5215. const char *body, *end_body;
  5216. unsigned int nesting_level;
  5217. bool have_subst = false;
  5218. /* Locate the closing } or ;, honoring nested braces.
  5219. Trim trailing whitespace. */
  5220. body = p;
  5221. nesting_level = 1;
  5222. for (;;)
  5223. {
  5224. if (*p == '{')
  5225. nesting_level++;
  5226. else if (*p == '}')
  5227. {
  5228. if (!--nesting_level)
  5229. break;
  5230. }
  5231. else if (*p == ';' && nesting_level == 1)
  5232. break;
  5233. else if (*p == '%' && p[1] == '*' && nesting_level == 1)
  5234. have_subst = true;
  5235. else if (*p == '\0')
  5236. goto invalid;
  5237. p++;
  5238. }
  5239. end_body = p;
  5240. while (end_body[-1] == ' ' || end_body[-1] == '\t')
  5241. end_body--;
  5242. if (have_subst && !starred)
  5243. goto invalid;
  5244. if (matched)
  5245. {
  5246. /* Copy the substitution body to permanent storage and execute it.
  5247. If have_subst is false, this is a simple matter of running the
  5248. body through do_spec_1... */
  5249. char *string = save_string (body, end_body - body);
  5250. if (!have_subst)
  5251. {
  5252. if (do_spec_1 (string, 0, NULL) < 0)
  5253. return 0;
  5254. }
  5255. else
  5256. {
  5257. /* ... but if have_subst is true, we have to process the
  5258. body once for each matching switch, with %* set to the
  5259. variant part of the switch. */
  5260. unsigned int hard_match_len = end_atom - atom;
  5261. int i;
  5262. for (i = 0; i < n_switches; i++)
  5263. if (!strncmp (switches[i].part1, atom, hard_match_len)
  5264. && check_live_switch (i, hard_match_len))
  5265. {
  5266. if (do_spec_1 (string, 0,
  5267. &switches[i].part1[hard_match_len]) < 0)
  5268. return 0;
  5269. /* Pass any arguments this switch has. */
  5270. give_switch (i, 1);
  5271. suffix_subst = NULL;
  5272. }
  5273. }
  5274. }
  5275. return p;
  5276. invalid:
  5277. fatal_error (input_location, "braced spec body %qs is invalid", body);
  5278. }
  5279. /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch
  5280. on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*}
  5281. spec, or -1 if either exact match or %* is used.
  5282. A -O switch is obsoleted by a later -O switch. A -f, -g, -m, or -W switch
  5283. whose value does not begin with "no-" is obsoleted by the same value
  5284. with the "no-", similarly for a switch with the "no-" prefix. */
  5285. static int
  5286. check_live_switch (int switchnum, int prefix_length)
  5287. {
  5288. const char *name = switches[switchnum].part1;
  5289. int i;
  5290. /* If we already processed this switch and determined if it was
  5291. live or not, return our past determination. */
  5292. if (switches[switchnum].live_cond != 0)
  5293. return ((switches[switchnum].live_cond & SWITCH_LIVE) != 0
  5294. && (switches[switchnum].live_cond & SWITCH_FALSE) == 0
  5295. && (switches[switchnum].live_cond & SWITCH_IGNORE_PERMANENTLY)
  5296. == 0);
  5297. /* In the common case of {<at-most-one-letter>*}, a negating
  5298. switch would always match, so ignore that case. We will just
  5299. send the conflicting switches to the compiler phase. */
  5300. if (prefix_length >= 0 && prefix_length <= 1)
  5301. return 1;
  5302. /* Now search for duplicate in a manner that depends on the name. */
  5303. switch (*name)
  5304. {
  5305. case 'O':
  5306. for (i = switchnum + 1; i < n_switches; i++)
  5307. if (switches[i].part1[0] == 'O')
  5308. {
  5309. switches[switchnum].validated = true;
  5310. switches[switchnum].live_cond = SWITCH_FALSE;
  5311. return 0;
  5312. }
  5313. break;
  5314. case 'W': case 'f': case 'm': case 'g':
  5315. if (! strncmp (name + 1, "no-", 3))
  5316. {
  5317. /* We have Xno-YYY, search for XYYY. */
  5318. for (i = switchnum + 1; i < n_switches; i++)
  5319. if (switches[i].part1[0] == name[0]
  5320. && ! strcmp (&switches[i].part1[1], &name[4]))
  5321. {
  5322. /* --specs are validated with the validate_switches mechanism. */
  5323. if (switches[switchnum].known)
  5324. switches[switchnum].validated = true;
  5325. switches[switchnum].live_cond = SWITCH_FALSE;
  5326. return 0;
  5327. }
  5328. }
  5329. else
  5330. {
  5331. /* We have XYYY, search for Xno-YYY. */
  5332. for (i = switchnum + 1; i < n_switches; i++)
  5333. if (switches[i].part1[0] == name[0]
  5334. && switches[i].part1[1] == 'n'
  5335. && switches[i].part1[2] == 'o'
  5336. && switches[i].part1[3] == '-'
  5337. && !strcmp (&switches[i].part1[4], &name[1]))
  5338. {
  5339. /* --specs are validated with the validate_switches mechanism. */
  5340. if (switches[switchnum].known)
  5341. switches[switchnum].validated = true;
  5342. switches[switchnum].live_cond = SWITCH_FALSE;
  5343. return 0;
  5344. }
  5345. }
  5346. break;
  5347. }
  5348. /* Otherwise the switch is live. */
  5349. switches[switchnum].live_cond |= SWITCH_LIVE;
  5350. return 1;
  5351. }
  5352. /* Pass a switch to the current accumulating command
  5353. in the same form that we received it.
  5354. SWITCHNUM identifies the switch; it is an index into
  5355. the vector of switches gcc received, which is `switches'.
  5356. This cannot fail since it never finishes a command line.
  5357. If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */
  5358. static void
  5359. give_switch (int switchnum, int omit_first_word)
  5360. {
  5361. if ((switches[switchnum].live_cond & SWITCH_IGNORE) != 0)
  5362. return;
  5363. if (!omit_first_word)
  5364. {
  5365. do_spec_1 ("-", 0, NULL);
  5366. do_spec_1 (switches[switchnum].part1, 1, NULL);
  5367. }
  5368. if (switches[switchnum].args != 0)
  5369. {
  5370. const char **p;
  5371. for (p = switches[switchnum].args; *p; p++)
  5372. {
  5373. const char *arg = *p;
  5374. do_spec_1 (" ", 0, NULL);
  5375. if (suffix_subst)
  5376. {
  5377. unsigned length = strlen (arg);
  5378. int dot = 0;
  5379. while (length-- && !IS_DIR_SEPARATOR (arg[length]))
  5380. if (arg[length] == '.')
  5381. {
  5382. (CONST_CAST (char *, arg))[length] = 0;
  5383. dot = 1;
  5384. break;
  5385. }
  5386. do_spec_1 (arg, 1, NULL);
  5387. if (dot)
  5388. (CONST_CAST (char *, arg))[length] = '.';
  5389. do_spec_1 (suffix_subst, 1, NULL);
  5390. }
  5391. else
  5392. do_spec_1 (arg, 1, NULL);
  5393. }
  5394. }
  5395. do_spec_1 (" ", 0, NULL);
  5396. switches[switchnum].validated = true;
  5397. }
  5398. /* Print GCC configuration (e.g. version, thread model, target,
  5399. configuration_arguments) to a given FILE. */
  5400. static void
  5401. print_configuration (FILE *file)
  5402. {
  5403. int n;
  5404. const char *thrmod;
  5405. fnotice (file, "Target: %s\n", spec_machine);
  5406. fnotice (file, "Configured with: %s\n", configuration_arguments);
  5407. #ifdef THREAD_MODEL_SPEC
  5408. /* We could have defined THREAD_MODEL_SPEC to "%*" by default,
  5409. but there's no point in doing all this processing just to get
  5410. thread_model back. */
  5411. obstack_init (&obstack);
  5412. do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model);
  5413. obstack_1grow (&obstack, '\0');
  5414. thrmod = XOBFINISH (&obstack, const char *);
  5415. #else
  5416. thrmod = thread_model;
  5417. #endif
  5418. fnotice (file, "Thread model: %s\n", thrmod);
  5419. /* compiler_version is truncated at the first space when initialized
  5420. from version string, so truncate version_string at the first space
  5421. before comparing. */
  5422. for (n = 0; version_string[n]; n++)
  5423. if (version_string[n] == ' ')
  5424. break;
  5425. if (! strncmp (version_string, compiler_version, n)
  5426. && compiler_version[n] == 0)
  5427. fnotice (file, "gcc version %s %s\n", version_string,
  5428. pkgversion_string);
  5429. else
  5430. fnotice (file, "gcc driver version %s %sexecuting gcc version %s\n",
  5431. version_string, pkgversion_string, compiler_version);
  5432. }
  5433. #define RETRY_ICE_ATTEMPTS 3
  5434. /* Returns true if FILE1 and FILE2 contain equivalent data, 0 otherwise. */
  5435. static bool
  5436. files_equal_p (char *file1, char *file2)
  5437. {
  5438. struct stat st1, st2;
  5439. off_t n, len;
  5440. int fd1, fd2;
  5441. const int bufsize = 8192;
  5442. char *buf = XNEWVEC (char, bufsize);
  5443. fd1 = open (file1, O_RDONLY);
  5444. fd2 = open (file2, O_RDONLY);
  5445. if (fd1 < 0 || fd2 < 0)
  5446. goto error;
  5447. if (fstat (fd1, &st1) < 0 || fstat (fd2, &st2) < 0)
  5448. goto error;
  5449. if (st1.st_size != st2.st_size)
  5450. goto error;
  5451. for (n = st1.st_size; n; n -= len)
  5452. {
  5453. len = n;
  5454. if ((int) len > bufsize / 2)
  5455. len = bufsize / 2;
  5456. if (read (fd1, buf, len) != (int) len
  5457. || read (fd2, buf + bufsize / 2, len) != (int) len)
  5458. {
  5459. goto error;
  5460. }
  5461. if (memcmp (buf, buf + bufsize / 2, len) != 0)
  5462. goto error;
  5463. }
  5464. free (buf);
  5465. close (fd1);
  5466. close (fd2);
  5467. return 1;
  5468. error:
  5469. free (buf);
  5470. close (fd1);
  5471. close (fd2);
  5472. return 0;
  5473. }
  5474. /* Check that compiler's output doesn't differ across runs.
  5475. TEMP_STDOUT_FILES and TEMP_STDERR_FILES are arrays of files, containing
  5476. stdout and stderr for each compiler run. Return true if all of
  5477. TEMP_STDOUT_FILES and TEMP_STDERR_FILES are equivalent. */
  5478. static bool
  5479. check_repro (char **temp_stdout_files, char **temp_stderr_files)
  5480. {
  5481. int i;
  5482. for (i = 0; i < RETRY_ICE_ATTEMPTS - 2; ++i)
  5483. {
  5484. if (!files_equal_p (temp_stdout_files[i], temp_stdout_files[i + 1])
  5485. || !files_equal_p (temp_stderr_files[i], temp_stderr_files[i + 1]))
  5486. {
  5487. fnotice (stderr, "The bug is not reproducible, so it is"
  5488. " likely a hardware or OS problem.\n");
  5489. break;
  5490. }
  5491. }
  5492. return i == RETRY_ICE_ATTEMPTS - 2;
  5493. }
  5494. enum attempt_status {
  5495. ATTEMPT_STATUS_FAIL_TO_RUN,
  5496. ATTEMPT_STATUS_SUCCESS,
  5497. ATTEMPT_STATUS_ICE
  5498. };
  5499. /* Run compiler with arguments NEW_ARGV to reproduce the ICE, storing stdout
  5500. to OUT_TEMP and stderr to ERR_TEMP. If APPEND is TRUE, append to OUT_TEMP
  5501. and ERR_TEMP instead of truncating. If EMIT_SYSTEM_INFO is TRUE, also write
  5502. GCC configuration into to ERR_TEMP. Return ATTEMPT_STATUS_FAIL_TO_RUN if
  5503. compiler failed to run, ATTEMPT_STATUS_ICE if compiled ICE-ed and
  5504. ATTEMPT_STATUS_SUCCESS otherwise. */
  5505. static enum attempt_status
  5506. run_attempt (const char **new_argv, const char *out_temp,
  5507. const char *err_temp, int emit_system_info, int append)
  5508. {
  5509. if (emit_system_info)
  5510. {
  5511. FILE *file_out = fopen (err_temp, "a");
  5512. print_configuration (file_out);
  5513. fputs ("\n", file_out);
  5514. fclose (file_out);
  5515. }
  5516. int exit_status;
  5517. const char *errmsg;
  5518. struct pex_obj *pex;
  5519. int err;
  5520. int pex_flags = PEX_USE_PIPES | PEX_LAST;
  5521. enum attempt_status status = ATTEMPT_STATUS_FAIL_TO_RUN;
  5522. if (append)
  5523. pex_flags |= PEX_STDOUT_APPEND | PEX_STDERR_APPEND;
  5524. pex = pex_init (PEX_USE_PIPES, new_argv[0], NULL);
  5525. if (!pex)
  5526. fatal_error (input_location, "pex_init failed: %m");
  5527. errmsg = pex_run (pex, pex_flags, new_argv[0],
  5528. CONST_CAST2 (char *const *, const char **, &new_argv[1]), out_temp,
  5529. err_temp, &err);
  5530. if (errmsg != NULL)
  5531. {
  5532. if (err == 0)
  5533. fatal_error (input_location, errmsg);
  5534. else
  5535. {
  5536. errno = err;
  5537. pfatal_with_name (errmsg);
  5538. }
  5539. }
  5540. if (!pex_get_status (pex, 1, &exit_status))
  5541. goto out;
  5542. switch (WEXITSTATUS (exit_status))
  5543. {
  5544. case ICE_EXIT_CODE:
  5545. status = ATTEMPT_STATUS_ICE;
  5546. break;
  5547. case SUCCESS_EXIT_CODE:
  5548. status = ATTEMPT_STATUS_SUCCESS;
  5549. break;
  5550. default:
  5551. ;
  5552. }
  5553. out:
  5554. pex_free (pex);
  5555. return status;
  5556. }
  5557. /* This routine reads lines from IN file, adds C++ style comments
  5558. at the begining of each line and writes result into OUT. */
  5559. static void
  5560. insert_comments (const char *file_in, const char *file_out)
  5561. {
  5562. FILE *in = fopen (file_in, "rb");
  5563. FILE *out = fopen (file_out, "wb");
  5564. char line[256];
  5565. bool add_comment = true;
  5566. while (fgets (line, sizeof (line), in))
  5567. {
  5568. if (add_comment)
  5569. fputs ("// ", out);
  5570. fputs (line, out);
  5571. add_comment = strchr (line, '\n') != NULL;
  5572. }
  5573. fclose (in);
  5574. fclose (out);
  5575. }
  5576. /* This routine adds preprocessed source code into the given ERR_FILE.
  5577. To do this, it adds "-E" to NEW_ARGV and execute RUN_ATTEMPT routine to
  5578. add information in report file. RUN_ATTEMPT should return
  5579. ATTEMPT_STATUS_SUCCESS, in other case we cannot generate the report. */
  5580. static void
  5581. do_report_bug (const char **new_argv, const int nargs,
  5582. char **out_file, char **err_file)
  5583. {
  5584. int i, status;
  5585. int fd = open (*out_file, O_RDWR | O_APPEND);
  5586. if (fd < 0)
  5587. return;
  5588. write (fd, "\n//", 3);
  5589. for (i = 0; i < nargs; i++)
  5590. {
  5591. write (fd, " ", 1);
  5592. write (fd, new_argv[i], strlen (new_argv[i]));
  5593. }
  5594. write (fd, "\n\n", 2);
  5595. close (fd);
  5596. new_argv[nargs] = "-E";
  5597. new_argv[nargs + 1] = NULL;
  5598. status = run_attempt (new_argv, *out_file, *err_file, 0, 1);
  5599. if (status == ATTEMPT_STATUS_SUCCESS)
  5600. {
  5601. fnotice (stderr, "Preprocessed source stored into %s file,"
  5602. " please attach this to your bugreport.\n", *out_file);
  5603. /* Make sure it is not deleted. */
  5604. free (*out_file);
  5605. *out_file = NULL;
  5606. }
  5607. }
  5608. /* Try to reproduce ICE. If bug is reproducible, generate report .err file
  5609. containing GCC configuration, backtrace, compiler's command line options
  5610. and preprocessed source code. */
  5611. static void
  5612. try_generate_repro (const char **argv)
  5613. {
  5614. int i, nargs, out_arg = -1, quiet = 0, attempt;
  5615. const char **new_argv;
  5616. char *temp_files[RETRY_ICE_ATTEMPTS * 2];
  5617. char **temp_stdout_files = &temp_files[0];
  5618. char **temp_stderr_files = &temp_files[RETRY_ICE_ATTEMPTS];
  5619. if (gcc_input_filename == NULL || ! strcmp (gcc_input_filename, "-"))
  5620. return;
  5621. for (nargs = 0; argv[nargs] != NULL; ++nargs)
  5622. /* Only retry compiler ICEs, not preprocessor ones. */
  5623. if (! strcmp (argv[nargs], "-E"))
  5624. return;
  5625. else if (argv[nargs][0] == '-' && argv[nargs][1] == 'o')
  5626. {
  5627. if (out_arg == -1)
  5628. out_arg = nargs;
  5629. else
  5630. return;
  5631. }
  5632. /* If the compiler is going to output any time information,
  5633. it might varry between invocations. */
  5634. else if (! strcmp (argv[nargs], "-quiet"))
  5635. quiet = 1;
  5636. else if (! strcmp (argv[nargs], "-ftime-report"))
  5637. return;
  5638. if (out_arg == -1 || !quiet)
  5639. return;
  5640. memset (temp_files, '\0', sizeof (temp_files));
  5641. new_argv = XALLOCAVEC (const char *, nargs + 4);
  5642. memcpy (new_argv, argv, (nargs + 1) * sizeof (const char *));
  5643. new_argv[nargs++] = "-frandom-seed=0";
  5644. new_argv[nargs++] = "-fdump-noaddr";
  5645. new_argv[nargs] = NULL;
  5646. if (new_argv[out_arg][2] == '\0')
  5647. new_argv[out_arg + 1] = "-";
  5648. else
  5649. new_argv[out_arg] = "-o-";
  5650. int status;
  5651. for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS; ++attempt)
  5652. {
  5653. int emit_system_info = 0;
  5654. int append = 0;
  5655. temp_stdout_files[attempt] = make_temp_file (".out");
  5656. temp_stderr_files[attempt] = make_temp_file (".err");
  5657. if (attempt == RETRY_ICE_ATTEMPTS - 1)
  5658. {
  5659. append = 1;
  5660. emit_system_info = 1;
  5661. }
  5662. status = run_attempt (new_argv, temp_stdout_files[attempt],
  5663. temp_stderr_files[attempt], emit_system_info,
  5664. append);
  5665. if (status != ATTEMPT_STATUS_ICE)
  5666. {
  5667. fnotice (stderr, "The bug is not reproducible, so it is"
  5668. " likely a hardware or OS problem.\n");
  5669. goto out;
  5670. }
  5671. }
  5672. if (!check_repro (temp_stdout_files, temp_stderr_files))
  5673. goto out;
  5674. {
  5675. /* Insert commented out backtrace into report file. */
  5676. char **stderr_commented = &temp_stdout_files[RETRY_ICE_ATTEMPTS - 1];
  5677. insert_comments (temp_stderr_files[RETRY_ICE_ATTEMPTS - 1],
  5678. *stderr_commented);
  5679. /* In final attempt we append compiler options and preprocesssed code to last
  5680. generated .out file with configuration and backtrace. */
  5681. char **output = &temp_stdout_files[RETRY_ICE_ATTEMPTS - 1];
  5682. do_report_bug (new_argv, nargs, stderr_commented, output);
  5683. }
  5684. out:
  5685. for (i = 0; i < RETRY_ICE_ATTEMPTS * 2; i++)
  5686. if (temp_files[i])
  5687. {
  5688. unlink (temp_stdout_files[i]);
  5689. free (temp_stdout_files[i]);
  5690. }
  5691. }
  5692. /* Search for a file named NAME trying various prefixes including the
  5693. user's -B prefix and some standard ones.
  5694. Return the absolute file name found. If nothing is found, return NAME. */
  5695. static const char *
  5696. find_file (const char *name)
  5697. {
  5698. char *newname = find_a_file (&startfile_prefixes, name, R_OK, true);
  5699. return newname ? newname : name;
  5700. }
  5701. /* Determine whether a directory exists. If LINKER, return 0 for
  5702. certain fixed names not needed by the linker. */
  5703. static int
  5704. is_directory (const char *path1, bool linker)
  5705. {
  5706. int len1;
  5707. char *path;
  5708. char *cp;
  5709. struct stat st;
  5710. /* Ensure the string ends with "/.". The resulting path will be a
  5711. directory even if the given path is a symbolic link. */
  5712. len1 = strlen (path1);
  5713. path = (char *) alloca (3 + len1);
  5714. memcpy (path, path1, len1);
  5715. cp = path + len1;
  5716. if (!IS_DIR_SEPARATOR (cp[-1]))
  5717. *cp++ = DIR_SEPARATOR;
  5718. *cp++ = '.';
  5719. *cp = '\0';
  5720. /* Exclude directories that the linker is known to search. */
  5721. if (linker
  5722. && IS_DIR_SEPARATOR (path[0])
  5723. && ((cp - path == 6
  5724. && filename_ncmp (path + 1, "lib", 3) == 0)
  5725. || (cp - path == 10
  5726. && filename_ncmp (path + 1, "usr", 3) == 0
  5727. && IS_DIR_SEPARATOR (path[4])
  5728. && filename_ncmp (path + 5, "lib", 3) == 0)))
  5729. return 0;
  5730. return (stat (path, &st) >= 0 && S_ISDIR (st.st_mode));
  5731. }
  5732. /* Set up the various global variables to indicate that we're processing
  5733. the input file named FILENAME. */
  5734. void
  5735. set_input (const char *filename)
  5736. {
  5737. const char *p;
  5738. gcc_input_filename = filename;
  5739. input_filename_length = strlen (gcc_input_filename);
  5740. input_basename = lbasename (gcc_input_filename);
  5741. /* Find a suffix starting with the last period,
  5742. and set basename_length to exclude that suffix. */
  5743. basename_length = strlen (input_basename);
  5744. suffixed_basename_length = basename_length;
  5745. p = input_basename + basename_length;
  5746. while (p != input_basename && *p != '.')
  5747. --p;
  5748. if (*p == '.' && p != input_basename)
  5749. {
  5750. basename_length = p - input_basename;
  5751. input_suffix = p + 1;
  5752. }
  5753. else
  5754. input_suffix = "";
  5755. /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then
  5756. we will need to do a stat on the gcc_input_filename. The
  5757. INPUT_STAT_SET signals that the stat is needed. */
  5758. input_stat_set = 0;
  5759. }
  5760. /* On fatal signals, delete all the temporary files. */
  5761. static void
  5762. fatal_signal (int signum)
  5763. {
  5764. signal (signum, SIG_DFL);
  5765. delete_failure_queue ();
  5766. delete_temp_files ();
  5767. /* Get the same signal again, this time not handled,
  5768. so its normal effect occurs. */
  5769. kill (getpid (), signum);
  5770. }
  5771. /* Compare the contents of the two files named CMPFILE[0] and
  5772. CMPFILE[1]. Return zero if they're identical, nonzero
  5773. otherwise. */
  5774. static int
  5775. compare_files (char *cmpfile[])
  5776. {
  5777. int ret = 0;
  5778. FILE *temp[2] = { NULL, NULL };
  5779. int i;
  5780. #if HAVE_MMAP_FILE
  5781. {
  5782. size_t length[2];
  5783. void *map[2] = { NULL, NULL };
  5784. for (i = 0; i < 2; i++)
  5785. {
  5786. struct stat st;
  5787. if (stat (cmpfile[i], &st) < 0 || !S_ISREG (st.st_mode))
  5788. {
  5789. error ("%s: could not determine length of compare-debug file %s",
  5790. gcc_input_filename, cmpfile[i]);
  5791. ret = 1;
  5792. break;
  5793. }
  5794. length[i] = st.st_size;
  5795. }
  5796. if (!ret && length[0] != length[1])
  5797. {
  5798. error ("%s: -fcompare-debug failure (length)", gcc_input_filename);
  5799. ret = 1;
  5800. }
  5801. if (!ret)
  5802. for (i = 0; i < 2; i++)
  5803. {
  5804. int fd = open (cmpfile[i], O_RDONLY);
  5805. if (fd < 0)
  5806. {
  5807. error ("%s: could not open compare-debug file %s",
  5808. gcc_input_filename, cmpfile[i]);
  5809. ret = 1;
  5810. break;
  5811. }
  5812. map[i] = mmap (NULL, length[i], PROT_READ, MAP_PRIVATE, fd, 0);
  5813. close (fd);
  5814. if (map[i] == (void *) MAP_FAILED)
  5815. {
  5816. ret = -1;
  5817. break;
  5818. }
  5819. }
  5820. if (!ret)
  5821. {
  5822. if (memcmp (map[0], map[1], length[0]) != 0)
  5823. {
  5824. error ("%s: -fcompare-debug failure", gcc_input_filename);
  5825. ret = 1;
  5826. }
  5827. }
  5828. for (i = 0; i < 2; i++)
  5829. if (map[i])
  5830. munmap ((caddr_t) map[i], length[i]);
  5831. if (ret >= 0)
  5832. return ret;
  5833. ret = 0;
  5834. }
  5835. #endif
  5836. for (i = 0; i < 2; i++)
  5837. {
  5838. temp[i] = fopen (cmpfile[i], "r");
  5839. if (!temp[i])
  5840. {
  5841. error ("%s: could not open compare-debug file %s",
  5842. gcc_input_filename, cmpfile[i]);
  5843. ret = 1;
  5844. break;
  5845. }
  5846. }
  5847. if (!ret && temp[0] && temp[1])
  5848. for (;;)
  5849. {
  5850. int c0, c1;
  5851. c0 = fgetc (temp[0]);
  5852. c1 = fgetc (temp[1]);
  5853. if (c0 != c1)
  5854. {
  5855. error ("%s: -fcompare-debug failure",
  5856. gcc_input_filename);
  5857. ret = 1;
  5858. break;
  5859. }
  5860. if (c0 == EOF)
  5861. break;
  5862. }
  5863. for (i = 1; i >= 0; i--)
  5864. {
  5865. if (temp[i])
  5866. fclose (temp[i]);
  5867. }
  5868. return ret;
  5869. }
  5870. /* driver::main is implemented as a series of driver:: method calls. */
  5871. int
  5872. driver::main (int argc, char **argv)
  5873. {
  5874. bool early_exit;
  5875. set_progname (argv[0]);
  5876. expand_at_files (&argc, &argv);
  5877. decode_argv (argc, const_cast <const char **> (argv));
  5878. global_initializations ();
  5879. build_multilib_strings ();
  5880. set_up_specs ();
  5881. putenv_COLLECT_GCC (argv[0]);
  5882. maybe_putenv_COLLECT_LTO_WRAPPER ();
  5883. maybe_putenv_OFFLOAD_TARGETS ();
  5884. handle_unrecognized_options ();
  5885. if (!maybe_print_and_exit ())
  5886. return 0;
  5887. early_exit = prepare_infiles ();
  5888. if (early_exit)
  5889. return get_exit_code ();
  5890. do_spec_on_infiles ();
  5891. maybe_run_linker (argv[0]);
  5892. final_actions ();
  5893. return get_exit_code ();
  5894. }
  5895. /* Locate the final component of argv[0] after any leading path, and set
  5896. the program name accordingly. */
  5897. void
  5898. driver::set_progname (const char *argv0) const
  5899. {
  5900. const char *p = argv0 + strlen (argv0);
  5901. while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
  5902. --p;
  5903. progname = p;
  5904. xmalloc_set_program_name (progname);
  5905. }
  5906. /* Expand any @ files within the command-line args,
  5907. setting at_file_supplied if any were expanded. */
  5908. void
  5909. driver::expand_at_files (int *argc, char ***argv) const
  5910. {
  5911. char **old_argv = *argv;
  5912. expandargv (argc, argv);
  5913. /* Determine if any expansions were made. */
  5914. if (*argv != old_argv)
  5915. at_file_supplied = true;
  5916. }
  5917. /* Decode the command-line arguments from argc/argv into the
  5918. decoded_options array. */
  5919. void
  5920. driver::decode_argv (int argc, const char **argv)
  5921. {
  5922. /* Register the language-independent parameters. */
  5923. global_init_params ();
  5924. finish_params ();
  5925. init_options_struct (&global_options, &global_options_set);
  5926. decode_cmdline_options_to_array (argc, argv,
  5927. CL_DRIVER,
  5928. &decoded_options, &decoded_options_count);
  5929. }
  5930. /* Perform various initializations and setup. */
  5931. void
  5932. driver::global_initializations ()
  5933. {
  5934. /* Unlock the stdio streams. */
  5935. unlock_std_streams ();
  5936. gcc_init_libintl ();
  5937. diagnostic_initialize (global_dc, 0);
  5938. diagnostic_color_init (global_dc);
  5939. #ifdef GCC_DRIVER_HOST_INITIALIZATION
  5940. /* Perform host dependent initialization when needed. */
  5941. GCC_DRIVER_HOST_INITIALIZATION;
  5942. #endif
  5943. if (atexit (delete_temp_files) != 0)
  5944. fatal_error (input_location, "atexit failed");
  5945. if (signal (SIGINT, SIG_IGN) != SIG_IGN)
  5946. signal (SIGINT, fatal_signal);
  5947. #ifdef SIGHUP
  5948. if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
  5949. signal (SIGHUP, fatal_signal);
  5950. #endif
  5951. if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
  5952. signal (SIGTERM, fatal_signal);
  5953. #ifdef SIGPIPE
  5954. if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
  5955. signal (SIGPIPE, fatal_signal);
  5956. #endif
  5957. #ifdef SIGCHLD
  5958. /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
  5959. receive the signal. A different setting is inheritable */
  5960. signal (SIGCHLD, SIG_DFL);
  5961. #endif
  5962. /* Parsing and gimplification sometimes need quite large stack.
  5963. Increase stack size limits if possible. */
  5964. stack_limit_increase (64 * 1024 * 1024);
  5965. /* Allocate the argument vector. */
  5966. alloc_args ();
  5967. obstack_init (&obstack);
  5968. }
  5969. /* Build multilib_select, et. al from the separate lines that make up each
  5970. multilib selection. */
  5971. void
  5972. driver::build_multilib_strings () const
  5973. {
  5974. {
  5975. const char *p;
  5976. const char *const *q = multilib_raw;
  5977. int need_space;
  5978. obstack_init (&multilib_obstack);
  5979. while ((p = *q++) != (char *) 0)
  5980. obstack_grow (&multilib_obstack, p, strlen (p));
  5981. obstack_1grow (&multilib_obstack, 0);
  5982. multilib_select = XOBFINISH (&multilib_obstack, const char *);
  5983. q = multilib_matches_raw;
  5984. while ((p = *q++) != (char *) 0)
  5985. obstack_grow (&multilib_obstack, p, strlen (p));
  5986. obstack_1grow (&multilib_obstack, 0);
  5987. multilib_matches = XOBFINISH (&multilib_obstack, const char *);
  5988. q = multilib_exclusions_raw;
  5989. while ((p = *q++) != (char *) 0)
  5990. obstack_grow (&multilib_obstack, p, strlen (p));
  5991. obstack_1grow (&multilib_obstack, 0);
  5992. multilib_exclusions = XOBFINISH (&multilib_obstack, const char *);
  5993. q = multilib_reuse_raw;
  5994. while ((p = *q++) != (char *) 0)
  5995. obstack_grow (&multilib_obstack, p, strlen (p));
  5996. obstack_1grow (&multilib_obstack, 0);
  5997. multilib_reuse = XOBFINISH (&multilib_obstack, const char *);
  5998. need_space = FALSE;
  5999. for (size_t i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++)
  6000. {
  6001. if (need_space)
  6002. obstack_1grow (&multilib_obstack, ' ');
  6003. obstack_grow (&multilib_obstack,
  6004. multilib_defaults_raw[i],
  6005. strlen (multilib_defaults_raw[i]));
  6006. need_space = TRUE;
  6007. }
  6008. obstack_1grow (&multilib_obstack, 0);
  6009. multilib_defaults = XOBFINISH (&multilib_obstack, const char *);
  6010. }
  6011. }
  6012. /* Set up the spec-handling machinery. */
  6013. void
  6014. driver::set_up_specs () const
  6015. {
  6016. const char *spec_machine_suffix;
  6017. char *specs_file;
  6018. size_t i;
  6019. #ifdef INIT_ENVIRONMENT
  6020. /* Set up any other necessary machine specific environment variables. */
  6021. xputenv (INIT_ENVIRONMENT);
  6022. #endif
  6023. /* Make a table of what switches there are (switches, n_switches).
  6024. Make a table of specified input files (infiles, n_infiles).
  6025. Decode switches that are handled locally. */
  6026. process_command (decoded_options_count, decoded_options);
  6027. /* Initialize the vector of specs to just the default.
  6028. This means one element containing 0s, as a terminator. */
  6029. compilers = XNEWVAR (struct compiler, sizeof default_compilers);
  6030. memcpy (compilers, default_compilers, sizeof default_compilers);
  6031. n_compilers = n_default_compilers;
  6032. /* Read specs from a file if there is one. */
  6033. machine_suffix = concat (spec_host_machine, dir_separator_str, spec_version,
  6034. accel_dir_suffix, dir_separator_str, NULL);
  6035. just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
  6036. specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
  6037. /* Read the specs file unless it is a default one. */
  6038. if (specs_file != 0 && strcmp (specs_file, "specs"))
  6039. read_specs (specs_file, true, false);
  6040. else
  6041. init_spec ();
  6042. #ifdef ACCEL_COMPILER
  6043. spec_machine_suffix = machine_suffix;
  6044. #else
  6045. spec_machine_suffix = just_machine_suffix;
  6046. #endif
  6047. /* We need to check standard_exec_prefix/spec_machine_suffix/specs
  6048. for any override of as, ld and libraries. */
  6049. specs_file = (char *) alloca (strlen (standard_exec_prefix)
  6050. + strlen (spec_machine_suffix) + sizeof ("specs"));
  6051. strcpy (specs_file, standard_exec_prefix);
  6052. strcat (specs_file, spec_machine_suffix);
  6053. strcat (specs_file, "specs");
  6054. if (access (specs_file, R_OK) == 0)
  6055. read_specs (specs_file, true, false);
  6056. /* Process any configure-time defaults specified for the command line
  6057. options, via OPTION_DEFAULT_SPECS. */
  6058. for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)
  6059. do_option_spec (option_default_specs[i].name,
  6060. option_default_specs[i].spec);
  6061. /* Process DRIVER_SELF_SPECS, adding any new options to the end
  6062. of the command line. */
  6063. for (i = 0; i < ARRAY_SIZE (driver_self_specs); i++)
  6064. do_self_spec (driver_self_specs[i]);
  6065. /* If not cross-compiling, look for executables in the standard
  6066. places. */
  6067. if (*cross_compile == '0')
  6068. {
  6069. if (*md_exec_prefix)
  6070. {
  6071. add_prefix (&exec_prefixes, md_exec_prefix, "GCC",
  6072. PREFIX_PRIORITY_LAST, 0, 0);
  6073. }
  6074. }
  6075. /* Process sysroot_suffix_spec. */
  6076. if (*sysroot_suffix_spec != 0
  6077. && !no_sysroot_suffix
  6078. && do_spec_2 (sysroot_suffix_spec) == 0)
  6079. {
  6080. if (argbuf.length () > 1)
  6081. error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC");
  6082. else if (argbuf.length () == 1)
  6083. target_sysroot_suffix = xstrdup (argbuf.last ());
  6084. }
  6085. #ifdef HAVE_LD_SYSROOT
  6086. /* Pass the --sysroot option to the linker, if it supports that. If
  6087. there is a sysroot_suffix_spec, it has already been processed by
  6088. this point, so target_system_root really is the system root we
  6089. should be using. */
  6090. if (target_system_root)
  6091. {
  6092. obstack_grow (&obstack, "%(sysroot_spec) ", strlen ("%(sysroot_spec) "));
  6093. obstack_grow0 (&obstack, link_spec, strlen (link_spec));
  6094. set_spec ("link", XOBFINISH (&obstack, const char *), false);
  6095. }
  6096. #endif
  6097. /* Process sysroot_hdrs_suffix_spec. */
  6098. if (*sysroot_hdrs_suffix_spec != 0
  6099. && !no_sysroot_suffix
  6100. && do_spec_2 (sysroot_hdrs_suffix_spec) == 0)
  6101. {
  6102. if (argbuf.length () > 1)
  6103. error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC");
  6104. else if (argbuf.length () == 1)
  6105. target_sysroot_hdrs_suffix = xstrdup (argbuf.last ());
  6106. }
  6107. /* Look for startfiles in the standard places. */
  6108. if (*startfile_prefix_spec != 0
  6109. && do_spec_2 (startfile_prefix_spec) == 0
  6110. && do_spec_1 (" ", 0, NULL) == 0)
  6111. {
  6112. const char *arg;
  6113. int ndx;
  6114. FOR_EACH_VEC_ELT (argbuf, ndx, arg)
  6115. add_sysrooted_prefix (&startfile_prefixes, arg, "BINUTILS",
  6116. PREFIX_PRIORITY_LAST, 0, 1);
  6117. }
  6118. /* We should eventually get rid of all these and stick to
  6119. startfile_prefix_spec exclusively. */
  6120. else if (*cross_compile == '0' || target_system_root)
  6121. {
  6122. if (*md_startfile_prefix)
  6123. add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix,
  6124. "GCC", PREFIX_PRIORITY_LAST, 0, 1);
  6125. if (*md_startfile_prefix_1)
  6126. add_sysrooted_prefix (&startfile_prefixes, md_startfile_prefix_1,
  6127. "GCC", PREFIX_PRIORITY_LAST, 0, 1);
  6128. /* If standard_startfile_prefix is relative, base it on
  6129. standard_exec_prefix. This lets us move the installed tree
  6130. as a unit. If GCC_EXEC_PREFIX is defined, base
  6131. standard_startfile_prefix on that as well.
  6132. If the prefix is relative, only search it for native compilers;
  6133. otherwise we will search a directory containing host libraries. */
  6134. if (IS_ABSOLUTE_PATH (standard_startfile_prefix))
  6135. add_sysrooted_prefix (&startfile_prefixes,
  6136. standard_startfile_prefix, "BINUTILS",
  6137. PREFIX_PRIORITY_LAST, 0, 1);
  6138. else if (*cross_compile == '0')
  6139. {
  6140. add_prefix (&startfile_prefixes,
  6141. concat (gcc_exec_prefix
  6142. ? gcc_exec_prefix : standard_exec_prefix,
  6143. machine_suffix,
  6144. standard_startfile_prefix, NULL),
  6145. NULL, PREFIX_PRIORITY_LAST, 0, 1);
  6146. }
  6147. /* Sysrooted prefixes are relocated because target_system_root is
  6148. also relocated by gcc_exec_prefix. */
  6149. if (*standard_startfile_prefix_1)
  6150. add_sysrooted_prefix (&startfile_prefixes,
  6151. standard_startfile_prefix_1, "BINUTILS",
  6152. PREFIX_PRIORITY_LAST, 0, 1);
  6153. if (*standard_startfile_prefix_2)
  6154. add_sysrooted_prefix (&startfile_prefixes,
  6155. standard_startfile_prefix_2, "BINUTILS",
  6156. PREFIX_PRIORITY_LAST, 0, 1);
  6157. }
  6158. /* Process any user specified specs in the order given on the command
  6159. line. */
  6160. for (struct user_specs *uptr = user_specs_head; uptr; uptr = uptr->next)
  6161. {
  6162. char *filename = find_a_file (&startfile_prefixes, uptr->filename,
  6163. R_OK, true);
  6164. read_specs (filename ? filename : uptr->filename, false, true);
  6165. }
  6166. /* Process any user self specs. */
  6167. {
  6168. struct spec_list *sl;
  6169. for (sl = specs; sl; sl = sl->next)
  6170. if (sl->name_len == sizeof "self_spec" - 1
  6171. && !strcmp (sl->name, "self_spec"))
  6172. do_self_spec (*sl->ptr_spec);
  6173. }
  6174. if (compare_debug)
  6175. {
  6176. enum save_temps save;
  6177. if (!compare_debug_second)
  6178. {
  6179. n_switches_debug_check[1] = n_switches;
  6180. n_switches_alloc_debug_check[1] = n_switches_alloc;
  6181. switches_debug_check[1] = XDUPVEC (struct switchstr, switches,
  6182. n_switches_alloc);
  6183. do_self_spec ("%:compare-debug-self-opt()");
  6184. n_switches_debug_check[0] = n_switches;
  6185. n_switches_alloc_debug_check[0] = n_switches_alloc;
  6186. switches_debug_check[0] = switches;
  6187. n_switches = n_switches_debug_check[1];
  6188. n_switches_alloc = n_switches_alloc_debug_check[1];
  6189. switches = switches_debug_check[1];
  6190. }
  6191. /* Avoid crash when computing %j in this early. */
  6192. save = save_temps_flag;
  6193. save_temps_flag = SAVE_TEMPS_NONE;
  6194. compare_debug = -compare_debug;
  6195. do_self_spec ("%:compare-debug-self-opt()");
  6196. save_temps_flag = save;
  6197. if (!compare_debug_second)
  6198. {
  6199. n_switches_debug_check[1] = n_switches;
  6200. n_switches_alloc_debug_check[1] = n_switches_alloc;
  6201. switches_debug_check[1] = switches;
  6202. compare_debug = -compare_debug;
  6203. n_switches = n_switches_debug_check[0];
  6204. n_switches_alloc = n_switches_debug_check[0];
  6205. switches = switches_debug_check[0];
  6206. }
  6207. }
  6208. /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */
  6209. if (gcc_exec_prefix)
  6210. gcc_exec_prefix = concat (gcc_exec_prefix, spec_host_machine,
  6211. dir_separator_str, spec_version,
  6212. accel_dir_suffix, dir_separator_str, NULL);
  6213. /* Now we have the specs.
  6214. Set the `valid' bits for switches that match anything in any spec. */
  6215. validate_all_switches ();
  6216. /* Now that we have the switches and the specs, set
  6217. the subdirectory based on the options. */
  6218. set_multilib_dir ();
  6219. }
  6220. /* Set up to remember the pathname of gcc and any options
  6221. needed for collect. We use argv[0] instead of progname because
  6222. we need the complete pathname. */
  6223. void
  6224. driver::putenv_COLLECT_GCC (const char *argv0) const
  6225. {
  6226. obstack_init (&collect_obstack);
  6227. obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1);
  6228. obstack_grow (&collect_obstack, argv0, strlen (argv0) + 1);
  6229. xputenv (XOBFINISH (&collect_obstack, char *));
  6230. }
  6231. /* Set up to remember the pathname of the lto wrapper. */
  6232. void
  6233. driver::maybe_putenv_COLLECT_LTO_WRAPPER () const
  6234. {
  6235. char *lto_wrapper_file;
  6236. if (have_c)
  6237. lto_wrapper_file = NULL;
  6238. else
  6239. lto_wrapper_file = find_a_file (&exec_prefixes, "lto-wrapper",
  6240. X_OK, false);
  6241. if (lto_wrapper_file)
  6242. {
  6243. lto_wrapper_file = convert_white_space (lto_wrapper_file);
  6244. lto_wrapper_spec = lto_wrapper_file;
  6245. obstack_init (&collect_obstack);
  6246. obstack_grow (&collect_obstack, "COLLECT_LTO_WRAPPER=",
  6247. sizeof ("COLLECT_LTO_WRAPPER=") - 1);
  6248. obstack_grow (&collect_obstack, lto_wrapper_spec,
  6249. strlen (lto_wrapper_spec) + 1);
  6250. xputenv (XOBFINISH (&collect_obstack, char *));
  6251. }
  6252. }
  6253. /* Set up to remember the names of offload targets. */
  6254. void
  6255. driver::maybe_putenv_OFFLOAD_TARGETS () const
  6256. {
  6257. const char *targets = offload_targets;
  6258. /* If no targets specified by -foffload, use all available targets. */
  6259. if (!targets)
  6260. targets = OFFLOAD_TARGETS;
  6261. if (strlen (targets) > 0)
  6262. {
  6263. obstack_grow (&collect_obstack, "OFFLOAD_TARGET_NAMES=",
  6264. sizeof ("OFFLOAD_TARGET_NAMES=") - 1);
  6265. obstack_grow (&collect_obstack, targets,
  6266. strlen (targets) + 1);
  6267. xputenv (XOBFINISH (&collect_obstack, char *));
  6268. }
  6269. free (offload_targets);
  6270. }
  6271. /* Reject switches that no pass was interested in. */
  6272. void
  6273. driver::handle_unrecognized_options () const
  6274. {
  6275. for (size_t i = 0; (int) i < n_switches; i++)
  6276. if (! switches[i].validated)
  6277. error ("unrecognized command line option %<-%s%>", switches[i].part1);
  6278. }
  6279. /* Handle the various -print-* options, returning 0 if the driver
  6280. should exit, or nonzero if the driver should continue. */
  6281. int
  6282. driver::maybe_print_and_exit () const
  6283. {
  6284. if (print_search_dirs)
  6285. {
  6286. printf (_("install: %s%s\n"),
  6287. gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
  6288. gcc_exec_prefix ? "" : machine_suffix);
  6289. printf (_("programs: %s\n"),
  6290. build_search_list (&exec_prefixes, "", false, false));
  6291. printf (_("libraries: %s\n"),
  6292. build_search_list (&startfile_prefixes, "", false, true));
  6293. return (0);
  6294. }
  6295. if (print_file_name)
  6296. {
  6297. printf ("%s\n", find_file (print_file_name));
  6298. return (0);
  6299. }
  6300. if (print_prog_name)
  6301. {
  6302. if (use_ld != NULL && ! strcmp (print_prog_name, "ld"))
  6303. {
  6304. /* Append USE_LD to to the default linker. */
  6305. #ifdef DEFAULT_LINKER
  6306. char *ld;
  6307. # ifdef HAVE_HOST_EXECUTABLE_SUFFIX
  6308. int len = (sizeof (DEFAULT_LINKER)
  6309. - sizeof (HOST_EXECUTABLE_SUFFIX));
  6310. ld = NULL;
  6311. if (len > 0)
  6312. {
  6313. char *default_linker = xstrdup (DEFAULT_LINKER);
  6314. /* Strip HOST_EXECUTABLE_SUFFIX if DEFAULT_LINKER contains
  6315. HOST_EXECUTABLE_SUFFIX. */
  6316. if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX))
  6317. {
  6318. default_linker[len] = '\0';
  6319. ld = concat (default_linker, use_ld,
  6320. HOST_EXECUTABLE_SUFFIX, NULL);
  6321. }
  6322. }
  6323. if (ld == NULL)
  6324. # endif
  6325. ld = concat (DEFAULT_LINKER, use_ld, NULL);
  6326. if (access (ld, X_OK) == 0)
  6327. {
  6328. printf ("%s\n", ld);
  6329. return (0);
  6330. }
  6331. #endif
  6332. print_prog_name = concat (print_prog_name, use_ld, NULL);
  6333. }
  6334. char *newname = find_a_file (&exec_prefixes, print_prog_name, X_OK, 0);
  6335. printf ("%s\n", (newname ? newname : print_prog_name));
  6336. return (0);
  6337. }
  6338. if (print_multi_lib)
  6339. {
  6340. print_multilib_info ();
  6341. return (0);
  6342. }
  6343. if (print_multi_directory)
  6344. {
  6345. if (multilib_dir == NULL)
  6346. printf (".\n");
  6347. else
  6348. printf ("%s\n", multilib_dir);
  6349. return (0);
  6350. }
  6351. if (print_multiarch)
  6352. {
  6353. if (multiarch_dir == NULL)
  6354. printf ("\n");
  6355. else
  6356. printf ("%s\n", multiarch_dir);
  6357. return (0);
  6358. }
  6359. if (print_sysroot)
  6360. {
  6361. if (target_system_root)
  6362. {
  6363. if (target_sysroot_suffix)
  6364. printf ("%s%s\n", target_system_root, target_sysroot_suffix);
  6365. else
  6366. printf ("%s\n", target_system_root);
  6367. }
  6368. return (0);
  6369. }
  6370. if (print_multi_os_directory)
  6371. {
  6372. if (multilib_os_dir == NULL)
  6373. printf (".\n");
  6374. else
  6375. printf ("%s\n", multilib_os_dir);
  6376. return (0);
  6377. }
  6378. if (print_sysroot_headers_suffix)
  6379. {
  6380. if (*sysroot_hdrs_suffix_spec)
  6381. {
  6382. printf("%s\n", (target_sysroot_hdrs_suffix
  6383. ? target_sysroot_hdrs_suffix
  6384. : ""));
  6385. return (0);
  6386. }
  6387. else
  6388. /* The error status indicates that only one set of fixed
  6389. headers should be built. */
  6390. fatal_error (input_location,
  6391. "not configured with sysroot headers suffix");
  6392. }
  6393. if (print_help_list)
  6394. {
  6395. display_help ();
  6396. if (! verbose_flag)
  6397. {
  6398. printf (_("\nFor bug reporting instructions, please see:\n"));
  6399. printf ("%s.\n", bug_report_url);
  6400. return (0);
  6401. }
  6402. /* We do not exit here. Instead we have created a fake input file
  6403. called 'help-dummy' which needs to be compiled, and we pass this
  6404. on the various sub-processes, along with the --help switch.
  6405. Ensure their output appears after ours. */
  6406. fputc ('\n', stdout);
  6407. fflush (stdout);
  6408. }
  6409. if (print_version)
  6410. {
  6411. printf (_("%s %s%s\n"), progname, pkgversion_string,
  6412. version_string);
  6413. printf ("Copyright %s 2015 Free Software Foundation, Inc.\n",
  6414. _("(C)"));
  6415. fputs (_("This is free software; see the source for copying conditions. There is NO\n\
  6416. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
  6417. stdout);
  6418. if (! verbose_flag)
  6419. return 0;
  6420. /* We do not exit here. We use the same mechanism of --help to print
  6421. the version of the sub-processes. */
  6422. fputc ('\n', stdout);
  6423. fflush (stdout);
  6424. }
  6425. if (verbose_flag)
  6426. {
  6427. print_configuration (stderr);
  6428. if (n_infiles == 0)
  6429. return (0);
  6430. }
  6431. return 1;
  6432. }
  6433. /* Figure out what to do with each input file.
  6434. Return true if we need to exit early from "main", false otherwise. */
  6435. bool
  6436. driver::prepare_infiles ()
  6437. {
  6438. size_t i;
  6439. int lang_n_infiles = 0;
  6440. if (n_infiles == added_libraries)
  6441. fatal_error (input_location, "no input files");
  6442. if (seen_error ())
  6443. /* Early exit needed from main. */
  6444. return true;
  6445. /* Make a place to record the compiler output file names
  6446. that correspond to the input files. */
  6447. i = n_infiles;
  6448. i += lang_specific_extra_outfiles;
  6449. outfiles = XCNEWVEC (const char *, i);
  6450. /* Record which files were specified explicitly as link input. */
  6451. explicit_link_files = XCNEWVEC (char, n_infiles);
  6452. combine_inputs = have_o || flag_wpa;
  6453. for (i = 0; (int) i < n_infiles; i++)
  6454. {
  6455. const char *name = infiles[i].name;
  6456. struct compiler *compiler = lookup_compiler (name,
  6457. strlen (name),
  6458. infiles[i].language);
  6459. if (compiler && !(compiler->combinable))
  6460. combine_inputs = false;
  6461. if (lang_n_infiles > 0 && compiler != input_file_compiler
  6462. && infiles[i].language && infiles[i].language[0] != '*')
  6463. infiles[i].incompiler = compiler;
  6464. else if (compiler)
  6465. {
  6466. lang_n_infiles++;
  6467. input_file_compiler = compiler;
  6468. infiles[i].incompiler = compiler;
  6469. }
  6470. else
  6471. {
  6472. /* Since there is no compiler for this input file, assume it is a
  6473. linker file. */
  6474. explicit_link_files[i] = 1;
  6475. infiles[i].incompiler = NULL;
  6476. }
  6477. infiles[i].compiled = false;
  6478. infiles[i].preprocessed = false;
  6479. }
  6480. if (!combine_inputs && have_c && have_o && lang_n_infiles > 1)
  6481. fatal_error (input_location,
  6482. "cannot specify -o with -c, -S or -E with multiple files");
  6483. /* No early exit needed from main; we can continue. */
  6484. return false;
  6485. }
  6486. /* Run the spec machinery on each input file. */
  6487. void
  6488. driver::do_spec_on_infiles () const
  6489. {
  6490. size_t i;
  6491. for (i = 0; (int) i < n_infiles; i++)
  6492. {
  6493. int this_file_error = 0;
  6494. /* Tell do_spec what to substitute for %i. */
  6495. input_file_number = i;
  6496. set_input (infiles[i].name);
  6497. if (infiles[i].compiled)
  6498. continue;
  6499. /* Use the same thing in %o, unless cp->spec says otherwise. */
  6500. outfiles[i] = gcc_input_filename;
  6501. /* Figure out which compiler from the file's suffix. */
  6502. input_file_compiler
  6503. = lookup_compiler (infiles[i].name, input_filename_length,
  6504. infiles[i].language);
  6505. if (input_file_compiler)
  6506. {
  6507. /* Ok, we found an applicable compiler. Run its spec. */
  6508. if (input_file_compiler->spec[0] == '#')
  6509. {
  6510. error ("%s: %s compiler not installed on this system",
  6511. gcc_input_filename, &input_file_compiler->spec[1]);
  6512. this_file_error = 1;
  6513. }
  6514. else
  6515. {
  6516. int value;
  6517. if (compare_debug)
  6518. {
  6519. free (debug_check_temp_file[0]);
  6520. debug_check_temp_file[0] = NULL;
  6521. free (debug_check_temp_file[1]);
  6522. debug_check_temp_file[1] = NULL;
  6523. }
  6524. value = do_spec (input_file_compiler->spec);
  6525. infiles[i].compiled = true;
  6526. if (value < 0)
  6527. this_file_error = 1;
  6528. else if (compare_debug && debug_check_temp_file[0])
  6529. {
  6530. if (verbose_flag)
  6531. inform (0, "recompiling with -fcompare-debug");
  6532. compare_debug = -compare_debug;
  6533. n_switches = n_switches_debug_check[1];
  6534. n_switches_alloc = n_switches_alloc_debug_check[1];
  6535. switches = switches_debug_check[1];
  6536. value = do_spec (input_file_compiler->spec);
  6537. compare_debug = -compare_debug;
  6538. n_switches = n_switches_debug_check[0];
  6539. n_switches_alloc = n_switches_alloc_debug_check[0];
  6540. switches = switches_debug_check[0];
  6541. if (value < 0)
  6542. {
  6543. error ("during -fcompare-debug recompilation");
  6544. this_file_error = 1;
  6545. }
  6546. gcc_assert (debug_check_temp_file[1]
  6547. && filename_cmp (debug_check_temp_file[0],
  6548. debug_check_temp_file[1]));
  6549. if (verbose_flag)
  6550. inform (0, "comparing final insns dumps");
  6551. if (compare_files (debug_check_temp_file))
  6552. this_file_error = 1;
  6553. }
  6554. if (compare_debug)
  6555. {
  6556. free (debug_check_temp_file[0]);
  6557. debug_check_temp_file[0] = NULL;
  6558. free (debug_check_temp_file[1]);
  6559. debug_check_temp_file[1] = NULL;
  6560. }
  6561. }
  6562. }
  6563. /* If this file's name does not contain a recognized suffix,
  6564. record it as explicit linker input. */
  6565. else
  6566. explicit_link_files[i] = 1;
  6567. /* Clear the delete-on-failure queue, deleting the files in it
  6568. if this compilation failed. */
  6569. if (this_file_error)
  6570. {
  6571. delete_failure_queue ();
  6572. errorcount++;
  6573. }
  6574. /* If this compilation succeeded, don't delete those files later. */
  6575. clear_failure_queue ();
  6576. }
  6577. /* Reset the input file name to the first compile/object file name, for use
  6578. with %b in LINK_SPEC. We use the first input file that we can find
  6579. a compiler to compile it instead of using infiles.language since for
  6580. languages other than C we use aliases that we then lookup later. */
  6581. if (n_infiles > 0)
  6582. {
  6583. int i;
  6584. for (i = 0; i < n_infiles ; i++)
  6585. if (infiles[i].incompiler
  6586. || (infiles[i].language && infiles[i].language[0] != '*'))
  6587. {
  6588. set_input (infiles[i].name);
  6589. break;
  6590. }
  6591. }
  6592. if (!seen_error ())
  6593. {
  6594. /* Make sure INPUT_FILE_NUMBER points to first available open
  6595. slot. */
  6596. input_file_number = n_infiles;
  6597. if (lang_specific_pre_link ())
  6598. errorcount++;
  6599. }
  6600. }
  6601. /* If we have to run the linker, do it now. */
  6602. void
  6603. driver::maybe_run_linker (const char *argv0) const
  6604. {
  6605. size_t i;
  6606. int linker_was_run = 0;
  6607. int num_linker_inputs;
  6608. /* Determine if there are any linker input files. */
  6609. num_linker_inputs = 0;
  6610. for (i = 0; (int) i < n_infiles; i++)
  6611. if (explicit_link_files[i] || outfiles[i] != NULL)
  6612. num_linker_inputs++;
  6613. /* Run ld to link all the compiler output files. */
  6614. if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2)
  6615. {
  6616. int tmp = execution_count;
  6617. if (! have_c)
  6618. {
  6619. #if HAVE_LTO_PLUGIN > 0
  6620. #if HAVE_LTO_PLUGIN == 2
  6621. const char *fno_use_linker_plugin = "fno-use-linker-plugin";
  6622. #else
  6623. const char *fuse_linker_plugin = "fuse-linker-plugin";
  6624. #endif
  6625. #endif
  6626. /* We'll use ld if we can't find collect2. */
  6627. if (! strcmp (linker_name_spec, "collect2"))
  6628. {
  6629. char *s = find_a_file (&exec_prefixes, "collect2", X_OK, false);
  6630. if (s == NULL)
  6631. linker_name_spec = "ld";
  6632. }
  6633. #if HAVE_LTO_PLUGIN > 0
  6634. #if HAVE_LTO_PLUGIN == 2
  6635. if (!switch_matches (fno_use_linker_plugin,
  6636. fno_use_linker_plugin
  6637. + strlen (fno_use_linker_plugin), 0))
  6638. #else
  6639. if (switch_matches (fuse_linker_plugin,
  6640. fuse_linker_plugin
  6641. + strlen (fuse_linker_plugin), 0))
  6642. #endif
  6643. {
  6644. char *temp_spec = find_a_file (&exec_prefixes,
  6645. LTOPLUGINSONAME, R_OK,
  6646. false);
  6647. if (!temp_spec)
  6648. fatal_error (input_location,
  6649. "-fuse-linker-plugin, but %s not found",
  6650. LTOPLUGINSONAME);
  6651. linker_plugin_file_spec = convert_white_space (temp_spec);
  6652. }
  6653. #endif
  6654. lto_gcc_spec = argv0;
  6655. }
  6656. /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables
  6657. for collect. */
  6658. putenv_from_prefixes (&exec_prefixes, "COMPILER_PATH", false);
  6659. putenv_from_prefixes (&startfile_prefixes, LIBRARY_PATH_ENV, true);
  6660. if (print_subprocess_help == 1)
  6661. {
  6662. printf (_("\nLinker options\n==============\n\n"));
  6663. printf (_("Use \"-Wl,OPTION\" to pass \"OPTION\""
  6664. " to the linker.\n\n"));
  6665. fflush (stdout);
  6666. }
  6667. int value = do_spec (link_command_spec);
  6668. if (value < 0)
  6669. errorcount = 1;
  6670. linker_was_run = (tmp != execution_count);
  6671. }
  6672. /* If options said don't run linker,
  6673. complain about input files to be given to the linker. */
  6674. if (! linker_was_run && !seen_error ())
  6675. for (i = 0; (int) i < n_infiles; i++)
  6676. if (explicit_link_files[i]
  6677. && !(infiles[i].language && infiles[i].language[0] == '*'))
  6678. warning (0, "%s: linker input file unused because linking not done",
  6679. outfiles[i]);
  6680. }
  6681. /* The end of "main". */
  6682. void
  6683. driver::final_actions () const
  6684. {
  6685. /* Delete some or all of the temporary files we made. */
  6686. if (seen_error ())
  6687. delete_failure_queue ();
  6688. delete_temp_files ();
  6689. if (print_help_list)
  6690. {
  6691. printf (("\nFor bug reporting instructions, please see:\n"));
  6692. printf ("%s\n", bug_report_url);
  6693. }
  6694. }
  6695. /* Determine what the exit code of the driver should be. */
  6696. int
  6697. driver::get_exit_code () const
  6698. {
  6699. return (signal_count != 0 ? 2
  6700. : seen_error () ? (pass_exit_codes ? greatest_status : 1)
  6701. : 0);
  6702. }
  6703. /* Find the proper compilation spec for the file name NAME,
  6704. whose length is LENGTH. LANGUAGE is the specified language,
  6705. or 0 if this file is to be passed to the linker. */
  6706. static struct compiler *
  6707. lookup_compiler (const char *name, size_t length, const char *language)
  6708. {
  6709. struct compiler *cp;
  6710. /* If this was specified by the user to be a linker input, indicate that. */
  6711. if (language != 0 && language[0] == '*')
  6712. return 0;
  6713. /* Otherwise, look for the language, if one is spec'd. */
  6714. if (language != 0)
  6715. {
  6716. for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
  6717. if (cp->suffix[0] == '@' && !strcmp (cp->suffix + 1, language))
  6718. return cp;
  6719. error ("language %s not recognized", language);
  6720. return 0;
  6721. }
  6722. /* Look for a suffix. */
  6723. for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
  6724. {
  6725. if (/* The suffix `-' matches only the file name `-'. */
  6726. (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
  6727. || (strlen (cp->suffix) < length
  6728. /* See if the suffix matches the end of NAME. */
  6729. && !strcmp (cp->suffix,
  6730. name + length - strlen (cp->suffix))
  6731. ))
  6732. break;
  6733. }
  6734. #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM)
  6735. /* Look again, but case-insensitively this time. */
  6736. if (cp < compilers)
  6737. for (cp = compilers + n_compilers - 1; cp >= compilers; cp--)
  6738. {
  6739. if (/* The suffix `-' matches only the file name `-'. */
  6740. (!strcmp (cp->suffix, "-") && !strcmp (name, "-"))
  6741. || (strlen (cp->suffix) < length
  6742. /* See if the suffix matches the end of NAME. */
  6743. && ((!strcmp (cp->suffix,
  6744. name + length - strlen (cp->suffix))
  6745. || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
  6746. && !strcasecmp (cp->suffix,
  6747. name + length - strlen (cp->suffix)))
  6748. ))
  6749. break;
  6750. }
  6751. #endif
  6752. if (cp >= compilers)
  6753. {
  6754. if (cp->spec[0] != '@')
  6755. /* A non-alias entry: return it. */
  6756. return cp;
  6757. /* An alias entry maps a suffix to a language.
  6758. Search for the language; pass 0 for NAME and LENGTH
  6759. to avoid infinite recursion if language not found. */
  6760. return lookup_compiler (NULL, 0, cp->spec + 1);
  6761. }
  6762. return 0;
  6763. }
  6764. static char *
  6765. save_string (const char *s, int len)
  6766. {
  6767. char *result = XNEWVEC (char, len + 1);
  6768. memcpy (result, s, len);
  6769. result[len] = 0;
  6770. return result;
  6771. }
  6772. void
  6773. pfatal_with_name (const char *name)
  6774. {
  6775. perror_with_name (name);
  6776. delete_temp_files ();
  6777. exit (1);
  6778. }
  6779. static void
  6780. perror_with_name (const char *name)
  6781. {
  6782. error ("%s: %m", name);
  6783. }
  6784. static inline void
  6785. validate_switches_from_spec (const char *spec, bool user)
  6786. {
  6787. const char *p = spec;
  6788. char c;
  6789. while ((c = *p++))
  6790. if (c == '%' && (*p == '{' || *p == '<' || (*p == 'W' && *++p == '{')))
  6791. /* We have a switch spec. */
  6792. p = validate_switches (p + 1, user);
  6793. }
  6794. static void
  6795. validate_all_switches (void)
  6796. {
  6797. struct compiler *comp;
  6798. struct spec_list *spec;
  6799. for (comp = compilers; comp->spec; comp++)
  6800. validate_switches_from_spec (comp->spec, false);
  6801. /* Look through the linked list of specs read from the specs file. */
  6802. for (spec = specs; spec; spec = spec->next)
  6803. validate_switches_from_spec (*spec->ptr_spec, spec->user_p);
  6804. validate_switches_from_spec (link_command_spec, false);
  6805. }
  6806. /* Look at the switch-name that comes after START
  6807. and mark as valid all supplied switches that match it. */
  6808. static const char *
  6809. validate_switches (const char *start, bool user_spec)
  6810. {
  6811. const char *p = start;
  6812. const char *atom;
  6813. size_t len;
  6814. int i;
  6815. bool suffix = false;
  6816. bool starred = false;
  6817. #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
  6818. next_member:
  6819. SKIP_WHITE ();
  6820. if (*p == '!')
  6821. p++;
  6822. SKIP_WHITE ();
  6823. if (*p == '.' || *p == ',')
  6824. suffix = true, p++;
  6825. atom = p;
  6826. while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '='
  6827. || *p == ',' || *p == '.' || *p == '@')
  6828. p++;
  6829. len = p - atom;
  6830. if (*p == '*')
  6831. starred = true, p++;
  6832. SKIP_WHITE ();
  6833. if (!suffix)
  6834. {
  6835. /* Mark all matching switches as valid. */
  6836. for (i = 0; i < n_switches; i++)
  6837. if (!strncmp (switches[i].part1, atom, len)
  6838. && (starred || switches[i].part1[len] == '\0')
  6839. && (switches[i].known || user_spec))
  6840. switches[i].validated = true;
  6841. }
  6842. if (*p) p++;
  6843. if (*p && (p[-1] == '|' || p[-1] == '&'))
  6844. goto next_member;
  6845. if (*p && p[-1] == ':')
  6846. {
  6847. while (*p && *p != ';' && *p != '}')
  6848. {
  6849. if (*p == '%')
  6850. {
  6851. p++;
  6852. if (*p == '{' || *p == '<')
  6853. p = validate_switches (p+1, user_spec);
  6854. else if (p[0] == 'W' && p[1] == '{')
  6855. p = validate_switches (p+2, user_spec);
  6856. }
  6857. else
  6858. p++;
  6859. }
  6860. if (*p) p++;
  6861. if (*p && p[-1] == ';')
  6862. goto next_member;
  6863. }
  6864. return p;
  6865. #undef SKIP_WHITE
  6866. }
  6867. struct mdswitchstr
  6868. {
  6869. const char *str;
  6870. int len;
  6871. };
  6872. static struct mdswitchstr *mdswitches;
  6873. static int n_mdswitches;
  6874. /* Check whether a particular argument was used. The first time we
  6875. canonicalize the switches to keep only the ones we care about. */
  6876. static int
  6877. used_arg (const char *p, int len)
  6878. {
  6879. struct mswitchstr
  6880. {
  6881. const char *str;
  6882. const char *replace;
  6883. int len;
  6884. int rep_len;
  6885. };
  6886. static struct mswitchstr *mswitches;
  6887. static int n_mswitches;
  6888. int i, j;
  6889. if (!mswitches)
  6890. {
  6891. struct mswitchstr *matches;
  6892. const char *q;
  6893. int cnt = 0;
  6894. /* Break multilib_matches into the component strings of string
  6895. and replacement string. */
  6896. for (q = multilib_matches; *q != '\0'; q++)
  6897. if (*q == ';')
  6898. cnt++;
  6899. matches
  6900. = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt);
  6901. i = 0;
  6902. q = multilib_matches;
  6903. while (*q != '\0')
  6904. {
  6905. matches[i].str = q;
  6906. while (*q != ' ')
  6907. {
  6908. if (*q == '\0')
  6909. {
  6910. invalid_matches:
  6911. fatal_error (input_location, "multilib spec %qs is invalid",
  6912. multilib_matches);
  6913. }
  6914. q++;
  6915. }
  6916. matches[i].len = q - matches[i].str;
  6917. matches[i].replace = ++q;
  6918. while (*q != ';' && *q != '\0')
  6919. {
  6920. if (*q == ' ')
  6921. goto invalid_matches;
  6922. q++;
  6923. }
  6924. matches[i].rep_len = q - matches[i].replace;
  6925. i++;
  6926. if (*q == ';')
  6927. q++;
  6928. }
  6929. /* Now build a list of the replacement string for switches that we care
  6930. about. Make sure we allocate at least one entry. This prevents
  6931. xmalloc from calling fatal, and prevents us from re-executing this
  6932. block of code. */
  6933. mswitches
  6934. = XNEWVEC (struct mswitchstr, n_mdswitches + (n_switches ? n_switches : 1));
  6935. for (i = 0; i < n_switches; i++)
  6936. if ((switches[i].live_cond & SWITCH_IGNORE) == 0)
  6937. {
  6938. int xlen = strlen (switches[i].part1);
  6939. for (j = 0; j < cnt; j++)
  6940. if (xlen == matches[j].len
  6941. && ! strncmp (switches[i].part1, matches[j].str, xlen))
  6942. {
  6943. mswitches[n_mswitches].str = matches[j].replace;
  6944. mswitches[n_mswitches].len = matches[j].rep_len;
  6945. mswitches[n_mswitches].replace = (char *) 0;
  6946. mswitches[n_mswitches].rep_len = 0;
  6947. n_mswitches++;
  6948. break;
  6949. }
  6950. }
  6951. /* Add MULTILIB_DEFAULTS switches too, as long as they were not present
  6952. on the command line nor any options mutually incompatible with
  6953. them. */
  6954. for (i = 0; i < n_mdswitches; i++)
  6955. {
  6956. const char *r;
  6957. for (q = multilib_options; *q != '\0'; *q && q++)
  6958. {
  6959. while (*q == ' ')
  6960. q++;
  6961. r = q;
  6962. while (strncmp (q, mdswitches[i].str, mdswitches[i].len) != 0
  6963. || strchr (" /", q[mdswitches[i].len]) == NULL)
  6964. {
  6965. while (*q != ' ' && *q != '/' && *q != '\0')
  6966. q++;
  6967. if (*q != '/')
  6968. break;
  6969. q++;
  6970. }
  6971. if (*q != ' ' && *q != '\0')
  6972. {
  6973. while (*r != ' ' && *r != '\0')
  6974. {
  6975. q = r;
  6976. while (*q != ' ' && *q != '/' && *q != '\0')
  6977. q++;
  6978. if (used_arg (r, q - r))
  6979. break;
  6980. if (*q != '/')
  6981. {
  6982. mswitches[n_mswitches].str = mdswitches[i].str;
  6983. mswitches[n_mswitches].len = mdswitches[i].len;
  6984. mswitches[n_mswitches].replace = (char *) 0;
  6985. mswitches[n_mswitches].rep_len = 0;
  6986. n_mswitches++;
  6987. break;
  6988. }
  6989. r = q + 1;
  6990. }
  6991. break;
  6992. }
  6993. }
  6994. }
  6995. }
  6996. for (i = 0; i < n_mswitches; i++)
  6997. if (len == mswitches[i].len && ! strncmp (p, mswitches[i].str, len))
  6998. return 1;
  6999. return 0;
  7000. }
  7001. static int
  7002. default_arg (const char *p, int len)
  7003. {
  7004. int i;
  7005. for (i = 0; i < n_mdswitches; i++)
  7006. if (len == mdswitches[i].len && ! strncmp (p, mdswitches[i].str, len))
  7007. return 1;
  7008. return 0;
  7009. }
  7010. /* Work out the subdirectory to use based on the options. The format of
  7011. multilib_select is a list of elements. Each element is a subdirectory
  7012. name followed by a list of options followed by a semicolon. The format
  7013. of multilib_exclusions is the same, but without the preceding
  7014. directory. First gcc will check the exclusions, if none of the options
  7015. beginning with an exclamation point are present, and all of the other
  7016. options are present, then we will ignore this completely. Passing
  7017. that, gcc will consider each multilib_select in turn using the same
  7018. rules for matching the options. If a match is found, that subdirectory
  7019. will be used.
  7020. A subdirectory name is optionally followed by a colon and the corresponding
  7021. multiarch name. */
  7022. static void
  7023. set_multilib_dir (void)
  7024. {
  7025. const char *p;
  7026. unsigned int this_path_len;
  7027. const char *this_path, *this_arg;
  7028. const char *start, *end;
  7029. int not_arg;
  7030. int ok, ndfltok, first;
  7031. n_mdswitches = 0;
  7032. start = multilib_defaults;
  7033. while (*start == ' ' || *start == '\t')
  7034. start++;
  7035. while (*start != '\0')
  7036. {
  7037. n_mdswitches++;
  7038. while (*start != ' ' && *start != '\t' && *start != '\0')
  7039. start++;
  7040. while (*start == ' ' || *start == '\t')
  7041. start++;
  7042. }
  7043. if (n_mdswitches)
  7044. {
  7045. int i = 0;
  7046. mdswitches = XNEWVEC (struct mdswitchstr, n_mdswitches);
  7047. for (start = multilib_defaults; *start != '\0'; start = end + 1)
  7048. {
  7049. while (*start == ' ' || *start == '\t')
  7050. start++;
  7051. if (*start == '\0')
  7052. break;
  7053. for (end = start + 1;
  7054. *end != ' ' && *end != '\t' && *end != '\0'; end++)
  7055. ;
  7056. obstack_grow (&multilib_obstack, start, end - start);
  7057. obstack_1grow (&multilib_obstack, 0);
  7058. mdswitches[i].str = XOBFINISH (&multilib_obstack, const char *);
  7059. mdswitches[i++].len = end - start;
  7060. if (*end == '\0')
  7061. break;
  7062. }
  7063. }
  7064. p = multilib_exclusions;
  7065. while (*p != '\0')
  7066. {
  7067. /* Ignore newlines. */
  7068. if (*p == '\n')
  7069. {
  7070. ++p;
  7071. continue;
  7072. }
  7073. /* Check the arguments. */
  7074. ok = 1;
  7075. while (*p != ';')
  7076. {
  7077. if (*p == '\0')
  7078. {
  7079. invalid_exclusions:
  7080. fatal_error (input_location, "multilib exclusions %qs is invalid",
  7081. multilib_exclusions);
  7082. }
  7083. if (! ok)
  7084. {
  7085. ++p;
  7086. continue;
  7087. }
  7088. this_arg = p;
  7089. while (*p != ' ' && *p != ';')
  7090. {
  7091. if (*p == '\0')
  7092. goto invalid_exclusions;
  7093. ++p;
  7094. }
  7095. if (*this_arg != '!')
  7096. not_arg = 0;
  7097. else
  7098. {
  7099. not_arg = 1;
  7100. ++this_arg;
  7101. }
  7102. ok = used_arg (this_arg, p - this_arg);
  7103. if (not_arg)
  7104. ok = ! ok;
  7105. if (*p == ' ')
  7106. ++p;
  7107. }
  7108. if (ok)
  7109. return;
  7110. ++p;
  7111. }
  7112. first = 1;
  7113. p = multilib_select;
  7114. /* Append multilib reuse rules if any. With those rules, we can reuse
  7115. one multilib for certain different options sets. */
  7116. if (strlen (multilib_reuse) > 0)
  7117. p = concat (p, multilib_reuse, NULL);
  7118. while (*p != '\0')
  7119. {
  7120. /* Ignore newlines. */
  7121. if (*p == '\n')
  7122. {
  7123. ++p;
  7124. continue;
  7125. }
  7126. /* Get the initial path. */
  7127. this_path = p;
  7128. while (*p != ' ')
  7129. {
  7130. if (*p == '\0')
  7131. {
  7132. invalid_select:
  7133. fatal_error (input_location, "multilib select %qs %qs is invalid",
  7134. multilib_select, multilib_reuse);
  7135. }
  7136. ++p;
  7137. }
  7138. this_path_len = p - this_path;
  7139. /* Check the arguments. */
  7140. ok = 1;
  7141. ndfltok = 1;
  7142. ++p;
  7143. while (*p != ';')
  7144. {
  7145. if (*p == '\0')
  7146. goto invalid_select;
  7147. if (! ok)
  7148. {
  7149. ++p;
  7150. continue;
  7151. }
  7152. this_arg = p;
  7153. while (*p != ' ' && *p != ';')
  7154. {
  7155. if (*p == '\0')
  7156. goto invalid_select;
  7157. ++p;
  7158. }
  7159. if (*this_arg != '!')
  7160. not_arg = 0;
  7161. else
  7162. {
  7163. not_arg = 1;
  7164. ++this_arg;
  7165. }
  7166. /* If this is a default argument, we can just ignore it.
  7167. This is true even if this_arg begins with '!'. Beginning
  7168. with '!' does not mean that this argument is necessarily
  7169. inappropriate for this library: it merely means that
  7170. there is a more specific library which uses this
  7171. argument. If this argument is a default, we need not
  7172. consider that more specific library. */
  7173. ok = used_arg (this_arg, p - this_arg);
  7174. if (not_arg)
  7175. ok = ! ok;
  7176. if (! ok)
  7177. ndfltok = 0;
  7178. if (default_arg (this_arg, p - this_arg))
  7179. ok = 1;
  7180. if (*p == ' ')
  7181. ++p;
  7182. }
  7183. if (ok && first)
  7184. {
  7185. if (this_path_len != 1
  7186. || this_path[0] != '.')
  7187. {
  7188. char *new_multilib_dir = XNEWVEC (char, this_path_len + 1);
  7189. char *q;
  7190. strncpy (new_multilib_dir, this_path, this_path_len);
  7191. new_multilib_dir[this_path_len] = '\0';
  7192. q = strchr (new_multilib_dir, ':');
  7193. if (q != NULL)
  7194. *q = '\0';
  7195. multilib_dir = new_multilib_dir;
  7196. }
  7197. first = 0;
  7198. }
  7199. if (ndfltok)
  7200. {
  7201. const char *q = this_path, *end = this_path + this_path_len;
  7202. while (q < end && *q != ':')
  7203. q++;
  7204. if (q < end)
  7205. {
  7206. const char *q2 = q + 1, *ml_end = end;
  7207. char *new_multilib_os_dir;
  7208. while (q2 < end && *q2 != ':')
  7209. q2++;
  7210. if (*q2 == ':')
  7211. ml_end = q2;
  7212. if (ml_end - q == 1)
  7213. multilib_os_dir = xstrdup (".");
  7214. else
  7215. {
  7216. new_multilib_os_dir = XNEWVEC (char, ml_end - q);
  7217. memcpy (new_multilib_os_dir, q + 1, ml_end - q - 1);
  7218. new_multilib_os_dir[ml_end - q - 1] = '\0';
  7219. multilib_os_dir = new_multilib_os_dir;
  7220. }
  7221. if (q2 < end && *q2 == ':')
  7222. {
  7223. char *new_multiarch_dir = XNEWVEC (char, end - q2);
  7224. memcpy (new_multiarch_dir, q2 + 1, end - q2 - 1);
  7225. new_multiarch_dir[end - q2 - 1] = '\0';
  7226. multiarch_dir = new_multiarch_dir;
  7227. }
  7228. break;
  7229. }
  7230. }
  7231. ++p;
  7232. }
  7233. if (multilib_dir == NULL && multilib_os_dir != NULL
  7234. && strcmp (multilib_os_dir, ".") == 0)
  7235. {
  7236. free (CONST_CAST (char *, multilib_os_dir));
  7237. multilib_os_dir = NULL;
  7238. }
  7239. else if (multilib_dir != NULL && multilib_os_dir == NULL)
  7240. multilib_os_dir = multilib_dir;
  7241. }
  7242. /* Print out the multiple library subdirectory selection
  7243. information. This prints out a series of lines. Each line looks
  7244. like SUBDIRECTORY;@OPTION@OPTION, with as many options as is
  7245. required. Only the desired options are printed out, the negative
  7246. matches. The options are print without a leading dash. There are
  7247. no spaces to make it easy to use the information in the shell.
  7248. Each subdirectory is printed only once. This assumes the ordering
  7249. generated by the genmultilib script. Also, we leave out ones that match
  7250. the exclusions. */
  7251. static void
  7252. print_multilib_info (void)
  7253. {
  7254. const char *p = multilib_select;
  7255. const char *last_path = 0, *this_path;
  7256. int skip;
  7257. unsigned int last_path_len = 0;
  7258. while (*p != '\0')
  7259. {
  7260. skip = 0;
  7261. /* Ignore newlines. */
  7262. if (*p == '\n')
  7263. {
  7264. ++p;
  7265. continue;
  7266. }
  7267. /* Get the initial path. */
  7268. this_path = p;
  7269. while (*p != ' ')
  7270. {
  7271. if (*p == '\0')
  7272. {
  7273. invalid_select:
  7274. fatal_error (input_location,
  7275. "multilib select %qs is invalid", multilib_select);
  7276. }
  7277. ++p;
  7278. }
  7279. /* When --disable-multilib was used but target defines
  7280. MULTILIB_OSDIRNAMES, entries starting with .: (and not starting
  7281. with .:: for multiarch configurations) are there just to find
  7282. multilib_os_dir, so skip them from output. */
  7283. if (this_path[0] == '.' && this_path[1] == ':' && this_path[2] != ':')
  7284. skip = 1;
  7285. /* Check for matches with the multilib_exclusions. We don't bother
  7286. with the '!' in either list. If any of the exclusion rules match
  7287. all of its options with the select rule, we skip it. */
  7288. {
  7289. const char *e = multilib_exclusions;
  7290. const char *this_arg;
  7291. while (*e != '\0')
  7292. {
  7293. int m = 1;
  7294. /* Ignore newlines. */
  7295. if (*e == '\n')
  7296. {
  7297. ++e;
  7298. continue;
  7299. }
  7300. /* Check the arguments. */
  7301. while (*e != ';')
  7302. {
  7303. const char *q;
  7304. int mp = 0;
  7305. if (*e == '\0')
  7306. {
  7307. invalid_exclusion:
  7308. fatal_error (input_location,
  7309. "multilib exclusion %qs is invalid",
  7310. multilib_exclusions);
  7311. }
  7312. if (! m)
  7313. {
  7314. ++e;
  7315. continue;
  7316. }
  7317. this_arg = e;
  7318. while (*e != ' ' && *e != ';')
  7319. {
  7320. if (*e == '\0')
  7321. goto invalid_exclusion;
  7322. ++e;
  7323. }
  7324. q = p + 1;
  7325. while (*q != ';')
  7326. {
  7327. const char *arg;
  7328. int len = e - this_arg;
  7329. if (*q == '\0')
  7330. goto invalid_select;
  7331. arg = q;
  7332. while (*q != ' ' && *q != ';')
  7333. {
  7334. if (*q == '\0')
  7335. goto invalid_select;
  7336. ++q;
  7337. }
  7338. if (! strncmp (arg, this_arg,
  7339. (len < q - arg) ? q - arg : len)
  7340. || default_arg (this_arg, e - this_arg))
  7341. {
  7342. mp = 1;
  7343. break;
  7344. }
  7345. if (*q == ' ')
  7346. ++q;
  7347. }
  7348. if (! mp)
  7349. m = 0;
  7350. if (*e == ' ')
  7351. ++e;
  7352. }
  7353. if (m)
  7354. {
  7355. skip = 1;
  7356. break;
  7357. }
  7358. if (*e != '\0')
  7359. ++e;
  7360. }
  7361. }
  7362. if (! skip)
  7363. {
  7364. /* If this is a duplicate, skip it. */
  7365. skip = (last_path != 0
  7366. && (unsigned int) (p - this_path) == last_path_len
  7367. && ! filename_ncmp (last_path, this_path, last_path_len));
  7368. last_path = this_path;
  7369. last_path_len = p - this_path;
  7370. }
  7371. /* If this directory requires any default arguments, we can skip
  7372. it. We will already have printed a directory identical to
  7373. this one which does not require that default argument. */
  7374. if (! skip)
  7375. {
  7376. const char *q;
  7377. q = p + 1;
  7378. while (*q != ';')
  7379. {
  7380. const char *arg;
  7381. if (*q == '\0')
  7382. goto invalid_select;
  7383. if (*q == '!')
  7384. arg = NULL;
  7385. else
  7386. arg = q;
  7387. while (*q != ' ' && *q != ';')
  7388. {
  7389. if (*q == '\0')
  7390. goto invalid_select;
  7391. ++q;
  7392. }
  7393. if (arg != NULL
  7394. && default_arg (arg, q - arg))
  7395. {
  7396. skip = 1;
  7397. break;
  7398. }
  7399. if (*q == ' ')
  7400. ++q;
  7401. }
  7402. }
  7403. if (! skip)
  7404. {
  7405. const char *p1;
  7406. for (p1 = last_path; p1 < p && *p1 != ':'; p1++)
  7407. putchar (*p1);
  7408. putchar (';');
  7409. }
  7410. ++p;
  7411. while (*p != ';')
  7412. {
  7413. int use_arg;
  7414. if (*p == '\0')
  7415. goto invalid_select;
  7416. if (skip)
  7417. {
  7418. ++p;
  7419. continue;
  7420. }
  7421. use_arg = *p != '!';
  7422. if (use_arg)
  7423. putchar ('@');
  7424. while (*p != ' ' && *p != ';')
  7425. {
  7426. if (*p == '\0')
  7427. goto invalid_select;
  7428. if (use_arg)
  7429. putchar (*p);
  7430. ++p;
  7431. }
  7432. if (*p == ' ')
  7433. ++p;
  7434. }
  7435. if (! skip)
  7436. {
  7437. /* If there are extra options, print them now. */
  7438. if (multilib_extra && *multilib_extra)
  7439. {
  7440. int print_at = TRUE;
  7441. const char *q;
  7442. for (q = multilib_extra; *q != '\0'; q++)
  7443. {
  7444. if (*q == ' ')
  7445. print_at = TRUE;
  7446. else
  7447. {
  7448. if (print_at)
  7449. putchar ('@');
  7450. putchar (*q);
  7451. print_at = FALSE;
  7452. }
  7453. }
  7454. }
  7455. putchar ('\n');
  7456. }
  7457. ++p;
  7458. }
  7459. }
  7460. /* getenv built-in spec function.
  7461. Returns the value of the environment variable given by its first
  7462. argument, concatenated with the second argument. If the
  7463. environment variable is not defined, a fatal error is issued. */
  7464. static const char *
  7465. getenv_spec_function (int argc, const char **argv)
  7466. {
  7467. char *value;
  7468. char *result;
  7469. char *ptr;
  7470. size_t len;
  7471. if (argc != 2)
  7472. return NULL;
  7473. value = getenv (argv[0]);
  7474. if (!value)
  7475. fatal_error (input_location,
  7476. "environment variable %qs not defined", argv[0]);
  7477. /* We have to escape every character of the environment variable so
  7478. they are not interpreted as active spec characters. A
  7479. particularly painful case is when we are reading a variable
  7480. holding a windows path complete with \ separators. */
  7481. len = strlen (value) * 2 + strlen (argv[1]) + 1;
  7482. result = XNEWVAR (char, len);
  7483. for (ptr = result; *value; ptr += 2)
  7484. {
  7485. ptr[0] = '\\';
  7486. ptr[1] = *value++;
  7487. }
  7488. strcpy (ptr, argv[1]);
  7489. return result;
  7490. }
  7491. /* if-exists built-in spec function.
  7492. Checks to see if the file specified by the absolute pathname in
  7493. ARGS exists. Returns that pathname if found.
  7494. The usual use for this function is to check for a library file
  7495. (whose name has been expanded with %s). */
  7496. static const char *
  7497. if_exists_spec_function (int argc, const char **argv)
  7498. {
  7499. /* Must have only one argument. */
  7500. if (argc == 1 && IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
  7501. return argv[0];
  7502. return NULL;
  7503. }
  7504. /* if-exists-else built-in spec function.
  7505. This is like if-exists, but takes an additional argument which
  7506. is returned if the first argument does not exist. */
  7507. static const char *
  7508. if_exists_else_spec_function (int argc, const char **argv)
  7509. {
  7510. /* Must have exactly two arguments. */
  7511. if (argc != 2)
  7512. return NULL;
  7513. if (IS_ABSOLUTE_PATH (argv[0]) && ! access (argv[0], R_OK))
  7514. return argv[0];
  7515. return argv[1];
  7516. }
  7517. /* sanitize built-in spec function.
  7518. This returns non-NULL, if sanitizing address, thread or
  7519. any of the undefined behavior sanitizers. */
  7520. static const char *
  7521. sanitize_spec_function (int argc, const char **argv)
  7522. {
  7523. if (argc != 1)
  7524. return NULL;
  7525. if (strcmp (argv[0], "address") == 0)
  7526. return (flag_sanitize & SANITIZE_USER_ADDRESS) ? "" : NULL;
  7527. if (strcmp (argv[0], "kernel-address") == 0)
  7528. return (flag_sanitize & SANITIZE_KERNEL_ADDRESS) ? "" : NULL;
  7529. if (strcmp (argv[0], "thread") == 0)
  7530. return (flag_sanitize & SANITIZE_THREAD) ? "" : NULL;
  7531. if (strcmp (argv[0], "undefined") == 0)
  7532. return ((flag_sanitize & (SANITIZE_UNDEFINED | SANITIZE_NONDEFAULT))
  7533. && !flag_sanitize_undefined_trap_on_error) ? "" : NULL;
  7534. if (strcmp (argv[0], "leak") == 0)
  7535. return ((flag_sanitize
  7536. & (SANITIZE_ADDRESS | SANITIZE_LEAK | SANITIZE_THREAD))
  7537. == SANITIZE_LEAK) ? "" : NULL;
  7538. return NULL;
  7539. }
  7540. /* replace-outfile built-in spec function.
  7541. This looks for the first argument in the outfiles array's name and
  7542. replaces it with the second argument. */
  7543. static const char *
  7544. replace_outfile_spec_function (int argc, const char **argv)
  7545. {
  7546. int i;
  7547. /* Must have exactly two arguments. */
  7548. if (argc != 2)
  7549. abort ();
  7550. for (i = 0; i < n_infiles; i++)
  7551. {
  7552. if (outfiles[i] && !filename_cmp (outfiles[i], argv[0]))
  7553. outfiles[i] = xstrdup (argv[1]);
  7554. }
  7555. return NULL;
  7556. }
  7557. /* remove-outfile built-in spec function.
  7558. *
  7559. * This looks for the first argument in the outfiles array's name and
  7560. * removes it. */
  7561. static const char *
  7562. remove_outfile_spec_function (int argc, const char **argv)
  7563. {
  7564. int i;
  7565. /* Must have exactly one argument. */
  7566. if (argc != 1)
  7567. abort ();
  7568. for (i = 0; i < n_infiles; i++)
  7569. {
  7570. if (outfiles[i] && !filename_cmp (outfiles[i], argv[0]))
  7571. outfiles[i] = NULL;
  7572. }
  7573. return NULL;
  7574. }
  7575. /* Given two version numbers, compares the two numbers.
  7576. A version number must match the regular expression
  7577. ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))*
  7578. */
  7579. static int
  7580. compare_version_strings (const char *v1, const char *v2)
  7581. {
  7582. int rresult;
  7583. regex_t r;
  7584. if (regcomp (&r, "^([1-9][0-9]*|0)(\\.([1-9][0-9]*|0))*$",
  7585. REG_EXTENDED | REG_NOSUB) != 0)
  7586. abort ();
  7587. rresult = regexec (&r, v1, 0, NULL, 0);
  7588. if (rresult == REG_NOMATCH)
  7589. fatal_error (input_location, "invalid version number %qs", v1);
  7590. else if (rresult != 0)
  7591. abort ();
  7592. rresult = regexec (&r, v2, 0, NULL, 0);
  7593. if (rresult == REG_NOMATCH)
  7594. fatal_error (input_location, "invalid version number %qs", v2);
  7595. else if (rresult != 0)
  7596. abort ();
  7597. return strverscmp (v1, v2);
  7598. }
  7599. /* version_compare built-in spec function.
  7600. This takes an argument of the following form:
  7601. <comparison-op> <arg1> [<arg2>] <switch> <result>
  7602. and produces "result" if the comparison evaluates to true,
  7603. and nothing if it doesn't.
  7604. The supported <comparison-op> values are:
  7605. >= true if switch is a later (or same) version than arg1
  7606. !> opposite of >=
  7607. < true if switch is an earlier version than arg1
  7608. !< opposite of <
  7609. >< true if switch is arg1 or later, and earlier than arg2
  7610. <> true if switch is earlier than arg1 or is arg2 or later
  7611. If the switch is not present, the condition is false unless
  7612. the first character of the <comparison-op> is '!'.
  7613. For example,
  7614. %:version-compare(>= 10.3 mmacosx-version-min= -lmx)
  7615. adds -lmx if -mmacosx-version-min=10.3.9 was passed. */
  7616. static const char *
  7617. version_compare_spec_function (int argc, const char **argv)
  7618. {
  7619. int comp1, comp2;
  7620. size_t switch_len;
  7621. const char *switch_value = NULL;
  7622. int nargs = 1, i;
  7623. bool result;
  7624. if (argc < 3)
  7625. fatal_error (input_location, "too few arguments to %%:version-compare");
  7626. if (argv[0][0] == '\0')
  7627. abort ();
  7628. if ((argv[0][1] == '<' || argv[0][1] == '>') && argv[0][0] != '!')
  7629. nargs = 2;
  7630. if (argc != nargs + 3)
  7631. fatal_error (input_location, "too many arguments to %%:version-compare");
  7632. switch_len = strlen (argv[nargs + 1]);
  7633. for (i = 0; i < n_switches; i++)
  7634. if (!strncmp (switches[i].part1, argv[nargs + 1], switch_len)
  7635. && check_live_switch (i, switch_len))
  7636. switch_value = switches[i].part1 + switch_len;
  7637. if (switch_value == NULL)
  7638. comp1 = comp2 = -1;
  7639. else
  7640. {
  7641. comp1 = compare_version_strings (switch_value, argv[1]);
  7642. if (nargs == 2)
  7643. comp2 = compare_version_strings (switch_value, argv[2]);
  7644. else
  7645. comp2 = -1; /* This value unused. */
  7646. }
  7647. switch (argv[0][0] << 8 | argv[0][1])
  7648. {
  7649. case '>' << 8 | '=':
  7650. result = comp1 >= 0;
  7651. break;
  7652. case '!' << 8 | '<':
  7653. result = comp1 >= 0 || switch_value == NULL;
  7654. break;
  7655. case '<' << 8:
  7656. result = comp1 < 0;
  7657. break;
  7658. case '!' << 8 | '>':
  7659. result = comp1 < 0 || switch_value == NULL;
  7660. break;
  7661. case '>' << 8 | '<':
  7662. result = comp1 >= 0 && comp2 < 0;
  7663. break;
  7664. case '<' << 8 | '>':
  7665. result = comp1 < 0 || comp2 >= 0;
  7666. break;
  7667. default:
  7668. fatal_error (input_location,
  7669. "unknown operator %qs in %%:version-compare", argv[0]);
  7670. }
  7671. if (! result)
  7672. return NULL;
  7673. return argv[nargs + 2];
  7674. }
  7675. /* %:include builtin spec function. This differs from %include in that it
  7676. can be nested inside a spec, and thus be conditionalized. It takes
  7677. one argument, the filename, and looks for it in the startfile path.
  7678. The result is always NULL, i.e. an empty expansion. */
  7679. static const char *
  7680. include_spec_function (int argc, const char **argv)
  7681. {
  7682. char *file;
  7683. if (argc != 1)
  7684. abort ();
  7685. file = find_a_file (&startfile_prefixes, argv[0], R_OK, true);
  7686. read_specs (file ? file : argv[0], false, false);
  7687. return NULL;
  7688. }
  7689. /* %:find-file spec function. This function replaces its argument by
  7690. the file found through find_file, that is the -print-file-name gcc
  7691. program option. */
  7692. static const char *
  7693. find_file_spec_function (int argc, const char **argv)
  7694. {
  7695. const char *file;
  7696. if (argc != 1)
  7697. abort ();
  7698. file = find_file (argv[0]);
  7699. return file;
  7700. }
  7701. /* %:find-plugindir spec function. This function replaces its argument
  7702. by the -iplugindir=<dir> option. `dir' is found through find_file, that
  7703. is the -print-file-name gcc program option. */
  7704. static const char *
  7705. find_plugindir_spec_function (int argc, const char **argv ATTRIBUTE_UNUSED)
  7706. {
  7707. const char *option;
  7708. if (argc != 0)
  7709. abort ();
  7710. option = concat ("-iplugindir=", find_file ("plugin"), NULL);
  7711. return option;
  7712. }
  7713. /* %:print-asm-header spec function. Print a banner to say that the
  7714. following output is from the assembler. */
  7715. static const char *
  7716. print_asm_header_spec_function (int arg ATTRIBUTE_UNUSED,
  7717. const char **argv ATTRIBUTE_UNUSED)
  7718. {
  7719. printf (_("Assembler options\n=================\n\n"));
  7720. printf (_("Use \"-Wa,OPTION\" to pass \"OPTION\" to the assembler.\n\n"));
  7721. fflush (stdout);
  7722. return NULL;
  7723. }
  7724. /* Get a random number for -frandom-seed */
  7725. static unsigned HOST_WIDE_INT
  7726. get_random_number (void)
  7727. {
  7728. unsigned HOST_WIDE_INT ret = 0;
  7729. int fd;
  7730. fd = open ("/dev/urandom", O_RDONLY);
  7731. if (fd >= 0)
  7732. {
  7733. read (fd, &ret, sizeof (HOST_WIDE_INT));
  7734. close (fd);
  7735. if (ret)
  7736. return ret;
  7737. }
  7738. /* Get some more or less random data. */
  7739. #ifdef HAVE_GETTIMEOFDAY
  7740. {
  7741. struct timeval tv;
  7742. gettimeofday (&tv, NULL);
  7743. ret = tv.tv_sec * 1000 + tv.tv_usec / 1000;
  7744. }
  7745. #else
  7746. {
  7747. time_t now = time (NULL);
  7748. if (now != (time_t)-1)
  7749. ret = (unsigned) now;
  7750. }
  7751. #endif
  7752. return ret ^ getpid ();
  7753. }
  7754. /* %:compare-debug-dump-opt spec function. Save the last argument,
  7755. expected to be the last -fdump-final-insns option, or generate a
  7756. temporary. */
  7757. static const char *
  7758. compare_debug_dump_opt_spec_function (int arg,
  7759. const char **argv ATTRIBUTE_UNUSED)
  7760. {
  7761. char *ret;
  7762. char *name;
  7763. int which;
  7764. static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
  7765. if (arg != 0)
  7766. fatal_error (input_location,
  7767. "too many arguments to %%:compare-debug-dump-opt");
  7768. do_spec_2 ("%{fdump-final-insns=*:%*}");
  7769. do_spec_1 (" ", 0, NULL);
  7770. if (argbuf.length () > 0
  7771. && strcmp (argv[argbuf.length () - 1], "."))
  7772. {
  7773. if (!compare_debug)
  7774. return NULL;
  7775. name = xstrdup (argv[argbuf.length () - 1]);
  7776. ret = NULL;
  7777. }
  7778. else
  7779. {
  7780. const char *ext = NULL;
  7781. if (argbuf.length () > 0)
  7782. {
  7783. do_spec_2 ("%{o*:%*}%{!o:%{!S:%b%O}%{S:%b.s}}");
  7784. ext = ".gkd";
  7785. }
  7786. else if (!compare_debug)
  7787. return NULL;
  7788. else
  7789. do_spec_2 ("%g.gkd");
  7790. do_spec_1 (" ", 0, NULL);
  7791. gcc_assert (argbuf.length () > 0);
  7792. name = concat (argbuf.last (), ext, NULL);
  7793. ret = concat ("-fdump-final-insns=", name, NULL);
  7794. }
  7795. which = compare_debug < 0;
  7796. debug_check_temp_file[which] = name;
  7797. if (!which)
  7798. {
  7799. unsigned HOST_WIDE_INT value = get_random_number ();
  7800. sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
  7801. }
  7802. if (*random_seed)
  7803. {
  7804. char *tmp = ret;
  7805. ret = concat ("%{!frandom-seed=*:-frandom-seed=", random_seed, "} ",
  7806. ret, NULL);
  7807. free (tmp);
  7808. }
  7809. if (which)
  7810. *random_seed = 0;
  7811. return ret;
  7812. }
  7813. static const char *debug_auxbase_opt;
  7814. /* %:compare-debug-self-opt spec function. Expands to the options
  7815. that are to be passed in the second compilation of
  7816. compare-debug. */
  7817. static const char *
  7818. compare_debug_self_opt_spec_function (int arg,
  7819. const char **argv ATTRIBUTE_UNUSED)
  7820. {
  7821. if (arg != 0)
  7822. fatal_error (input_location,
  7823. "too many arguments to %%:compare-debug-self-opt");
  7824. if (compare_debug >= 0)
  7825. return NULL;
  7826. do_spec_2 ("%{c|S:%{o*:%*}}");
  7827. do_spec_1 (" ", 0, NULL);
  7828. if (argbuf.length () > 0)
  7829. debug_auxbase_opt = concat ("-auxbase-strip ",
  7830. argbuf.last (),
  7831. NULL);
  7832. else
  7833. debug_auxbase_opt = NULL;
  7834. return concat ("\
  7835. %<o %<MD %<MMD %<MF* %<MG %<MP %<MQ* %<MT* \
  7836. %<fdump-final-insns=* -w -S -o %j \
  7837. %{!fcompare-debug-second:-fcompare-debug-second} \
  7838. ", compare_debug_opt, NULL);
  7839. }
  7840. /* %:compare-debug-auxbase-opt spec function. Expands to the auxbase
  7841. options that are to be passed in the second compilation of
  7842. compare-debug. It expects, as an argument, the basename of the
  7843. current input file name, with the .gk suffix appended to it. */
  7844. static const char *
  7845. compare_debug_auxbase_opt_spec_function (int arg,
  7846. const char **argv)
  7847. {
  7848. char *name;
  7849. int len;
  7850. if (arg == 0)
  7851. fatal_error (input_location,
  7852. "too few arguments to %%:compare-debug-auxbase-opt");
  7853. if (arg != 1)
  7854. fatal_error (input_location,
  7855. "too many arguments to %%:compare-debug-auxbase-opt");
  7856. if (compare_debug >= 0)
  7857. return NULL;
  7858. len = strlen (argv[0]);
  7859. if (len < 3 || strcmp (argv[0] + len - 3, ".gk") != 0)
  7860. fatal_error (input_location, "argument to %%:compare-debug-auxbase-opt "
  7861. "does not end in .gk");
  7862. if (debug_auxbase_opt)
  7863. return debug_auxbase_opt;
  7864. #define OPT "-auxbase "
  7865. len -= 3;
  7866. name = (char*) xmalloc (sizeof (OPT) + len);
  7867. memcpy (name, OPT, sizeof (OPT) - 1);
  7868. memcpy (name + sizeof (OPT) - 1, argv[0], len);
  7869. name[sizeof (OPT) - 1 + len] = '\0';
  7870. #undef OPT
  7871. return name;
  7872. }
  7873. /* %:pass-through-libs spec function. Finds all -l options and input
  7874. file names in the lib spec passed to it, and makes a list of them
  7875. prepended with the plugin option to cause them to be passed through
  7876. to the final link after all the new object files have been added. */
  7877. const char *
  7878. pass_through_libs_spec_func (int argc, const char **argv)
  7879. {
  7880. char *prepended = xstrdup (" ");
  7881. int n;
  7882. /* Shlemiel the painter's algorithm. Innately horrible, but at least
  7883. we know that there will never be more than a handful of strings to
  7884. concat, and it's only once per run, so it's not worth optimising. */
  7885. for (n = 0; n < argc; n++)
  7886. {
  7887. char *old = prepended;
  7888. /* Anything that isn't an option is a full path to an output
  7889. file; pass it through if it ends in '.a'. Among options,
  7890. pass only -l. */
  7891. if (argv[n][0] == '-' && argv[n][1] == 'l')
  7892. {
  7893. const char *lopt = argv[n] + 2;
  7894. /* Handle both joined and non-joined -l options. If for any
  7895. reason there's a trailing -l with no joined or following
  7896. arg just discard it. */
  7897. if (!*lopt && ++n >= argc)
  7898. break;
  7899. else if (!*lopt)
  7900. lopt = argv[n];
  7901. prepended = concat (prepended, "-plugin-opt=-pass-through=-l",
  7902. lopt, " ", NULL);
  7903. }
  7904. else if (!strcmp (".a", argv[n] + strlen (argv[n]) - 2))
  7905. {
  7906. prepended = concat (prepended, "-plugin-opt=-pass-through=",
  7907. argv[n], " ", NULL);
  7908. }
  7909. if (prepended != old)
  7910. free (old);
  7911. }
  7912. return prepended;
  7913. }
  7914. /* %:replace-extension spec function. Replaces the extension of the
  7915. first argument with the second argument. */
  7916. const char *
  7917. replace_extension_spec_func (int argc, const char **argv)
  7918. {
  7919. char *name;
  7920. char *p;
  7921. char *result;
  7922. int i;
  7923. if (argc != 2)
  7924. fatal_error (input_location, "too few arguments to %%:replace-extension");
  7925. name = xstrdup (argv[0]);
  7926. for (i = strlen (name) - 1; i >= 0; i--)
  7927. if (IS_DIR_SEPARATOR (name[i]))
  7928. break;
  7929. p = strrchr (name + i + 1, '.');
  7930. if (p != NULL)
  7931. *p = '\0';
  7932. result = concat (name, argv[1], NULL);
  7933. free (name);
  7934. return result;
  7935. }
  7936. /* Insert backslash before spaces in ORIG (usually a file path), to
  7937. avoid being broken by spec parser.
  7938. This function is needed as do_spec_1 treats white space (' ' and '\t')
  7939. as the end of an argument. But in case of -plugin /usr/gcc install/xxx.so,
  7940. the file name should be treated as a single argument rather than being
  7941. broken into multiple. Solution is to insert '\\' before the space in a
  7942. file name.
  7943. This function converts and only converts all occurrence of ' '
  7944. to '\\' + ' ' and '\t' to '\\' + '\t'. For example:
  7945. "a b" -> "a\\ b"
  7946. "a b" -> "a\\ \\ b"
  7947. "a\tb" -> "a\\\tb"
  7948. "a\\ b" -> "a\\\\ b"
  7949. orig: input null-terminating string that was allocated by xalloc. The
  7950. memory it points to might be freed in this function. Behavior undefined
  7951. if ORIG wasn't xalloced or was freed already at entry.
  7952. Return: ORIG if no conversion needed. Otherwise a newly allocated string
  7953. that was converted from ORIG. */
  7954. static char *
  7955. convert_white_space (char *orig)
  7956. {
  7957. int len, number_of_space = 0;
  7958. for (len = 0; orig[len]; len++)
  7959. if (orig[len] == ' ' || orig[len] == '\t') number_of_space++;
  7960. if (number_of_space)
  7961. {
  7962. char *new_spec = (char *) xmalloc (len + number_of_space + 1);
  7963. int j, k;
  7964. for (j = 0, k = 0; j <= len; j++, k++)
  7965. {
  7966. if (orig[j] == ' ' || orig[j] == '\t')
  7967. new_spec[k++] = '\\';
  7968. new_spec[k] = orig[j];
  7969. }
  7970. free (orig);
  7971. return new_spec;
  7972. }
  7973. else
  7974. return orig;
  7975. }
  7976. /* PR jit/64810.
  7977. Targets can provide configure-time default options in
  7978. OPTION_DEFAULT_SPECS. The jit needs to access these, but
  7979. they are expressed in the spec language.
  7980. Run just enough of the driver to be able to expand these
  7981. specs, and then call the callback CB on each
  7982. such option. The options strings are *without* a leading
  7983. '-' character e.g. ("march=x86-64"). Finally, clean up. */
  7984. void
  7985. driver_get_configure_time_options (void (*cb) (const char *option,
  7986. void *user_data),
  7987. void *user_data)
  7988. {
  7989. size_t i;
  7990. obstack_init (&obstack);
  7991. gcc_obstack_init (&opts_obstack);
  7992. n_switches = 0;
  7993. for (i = 0; i < ARRAY_SIZE (option_default_specs); i++)
  7994. do_option_spec (option_default_specs[i].name,
  7995. option_default_specs[i].spec);
  7996. for (i = 0; (int) i < n_switches; i++)
  7997. {
  7998. gcc_assert (switches[i].part1);
  7999. (*cb) (switches[i].part1, user_data);
  8000. }
  8001. obstack_free (&opts_obstack, NULL);
  8002. obstack_free (&obstack, NULL);
  8003. n_switches = 0;
  8004. }